@calliopelabs/cli 0.8.20 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/agent-config-loader.d.ts +60 -0
- package/dist/agents/agent-config-loader.d.ts.map +1 -0
- package/dist/agents/agent-config-loader.js +402 -0
- package/dist/agents/agent-config-loader.js.map +1 -0
- package/dist/agents/agent-config-presets.d.ts +10 -0
- package/dist/agents/agent-config-presets.d.ts.map +1 -0
- package/dist/agents/agent-config-presets.js +940 -0
- package/dist/agents/agent-config-presets.js.map +1 -0
- package/dist/agents/agent-config-types.d.ts +145 -0
- package/dist/agents/agent-config-types.d.ts.map +1 -0
- package/dist/agents/agent-config-types.js +12 -0
- package/dist/agents/agent-config-types.js.map +1 -0
- package/dist/{agterm → agents}/agent-detection.d.ts +1 -1
- package/dist/{agterm → agents}/agent-detection.d.ts.map +1 -1
- package/dist/{agterm → agents}/agent-detection.js +21 -5
- package/dist/agents/agent-detection.js.map +1 -0
- package/dist/agents/aggregator.d.ts +19 -0
- package/dist/agents/aggregator.d.ts.map +1 -0
- package/dist/agents/aggregator.js +141 -0
- package/dist/agents/aggregator.js.map +1 -0
- package/dist/{agterm → agents}/cli-backend.d.ts +1 -1
- package/dist/{agterm → agents}/cli-backend.d.ts.map +1 -1
- package/dist/{agterm → agents}/cli-backend.js +90 -12
- package/dist/agents/cli-backend.js.map +1 -0
- package/dist/agents/council-types.d.ts +113 -0
- package/dist/agents/council-types.d.ts.map +1 -0
- package/dist/agents/council-types.js +81 -0
- package/dist/agents/council-types.js.map +1 -0
- package/dist/agents/council.d.ts +107 -0
- package/dist/agents/council.d.ts.map +1 -0
- package/dist/agents/council.js +586 -0
- package/dist/agents/council.js.map +1 -0
- package/dist/agents/decomposer.d.ts +33 -0
- package/dist/agents/decomposer.d.ts.map +1 -0
- package/dist/agents/decomposer.js +138 -0
- package/dist/agents/decomposer.js.map +1 -0
- package/dist/agents/dynamic-tools.d.ts +52 -0
- package/dist/agents/dynamic-tools.d.ts.map +1 -0
- package/dist/agents/dynamic-tools.js +395 -0
- package/dist/agents/dynamic-tools.js.map +1 -0
- package/dist/agents/index.d.ts +29 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +29 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/installer.d.ts +39 -0
- package/dist/agents/installer.d.ts.map +1 -0
- package/dist/agents/installer.js +205 -0
- package/dist/agents/installer.js.map +1 -0
- package/dist/{agterm → agents}/orchestrator.d.ts +7 -2
- package/dist/agents/orchestrator.d.ts.map +1 -0
- package/dist/{agterm → agents}/orchestrator.js +22 -2
- package/dist/agents/orchestrator.js.map +1 -0
- package/dist/agents/sdk-backend.d.ts +63 -0
- package/dist/agents/sdk-backend.d.ts.map +1 -0
- package/dist/agents/sdk-backend.js +489 -0
- package/dist/agents/sdk-backend.js.map +1 -0
- package/dist/agents/swarm-types.d.ts +83 -0
- package/dist/agents/swarm-types.d.ts.map +1 -0
- package/dist/agents/swarm-types.js +20 -0
- package/dist/agents/swarm-types.js.map +1 -0
- package/dist/agents/swarm.d.ts +74 -0
- package/dist/agents/swarm.d.ts.map +1 -0
- package/dist/agents/swarm.js +307 -0
- package/dist/agents/swarm.js.map +1 -0
- package/dist/{agterm → agents}/tools.d.ts +7 -5
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +776 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/{agterm → agents}/types.d.ts +14 -2
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/{agterm → agents}/types.js +2 -2
- package/dist/agents/types.js.map +1 -0
- package/dist/api-server.d.ts +26 -0
- package/dist/api-server.d.ts.map +1 -0
- package/dist/api-server.js +230 -0
- package/dist/api-server.js.map +1 -0
- package/dist/auto-checkpoint.d.ts +35 -0
- package/dist/auto-checkpoint.d.ts.map +1 -0
- package/dist/auto-checkpoint.js +143 -0
- package/dist/auto-checkpoint.js.map +1 -0
- package/dist/auto-compressor.d.ts +44 -0
- package/dist/auto-compressor.d.ts.map +1 -0
- package/dist/auto-compressor.js +145 -0
- package/dist/auto-compressor.js.map +1 -0
- package/dist/background-jobs.d.ts +45 -0
- package/dist/background-jobs.d.ts.map +1 -0
- package/dist/background-jobs.js +122 -0
- package/dist/background-jobs.js.map +1 -0
- package/dist/bin.d.ts +6 -2
- package/dist/bin.d.ts.map +1 -1
- package/dist/bin.js +127 -24
- package/dist/bin.js.map +1 -1
- package/dist/checkpoint.d.ts +49 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +219 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/circuit-breaker/breaker.d.ts +80 -0
- package/dist/circuit-breaker/breaker.d.ts.map +1 -0
- package/dist/circuit-breaker/breaker.js +408 -0
- package/dist/circuit-breaker/breaker.js.map +1 -0
- package/dist/circuit-breaker/defaults.d.ts +8 -0
- package/dist/circuit-breaker/defaults.d.ts.map +1 -0
- package/dist/circuit-breaker/defaults.js +35 -0
- package/dist/circuit-breaker/defaults.js.map +1 -0
- package/dist/circuit-breaker/index.d.ts +9 -0
- package/dist/circuit-breaker/index.d.ts.map +1 -0
- package/dist/circuit-breaker/index.js +8 -0
- package/dist/circuit-breaker/index.js.map +1 -0
- package/dist/circuit-breaker/types.d.ts +77 -0
- package/dist/circuit-breaker/types.d.ts.map +1 -0
- package/dist/circuit-breaker/types.js +8 -0
- package/dist/circuit-breaker/types.js.map +1 -0
- package/dist/circuit-breaker.d.ts +8 -0
- package/dist/circuit-breaker.d.ts.map +1 -0
- package/dist/circuit-breaker.js +7 -0
- package/dist/circuit-breaker.js.map +1 -0
- package/dist/cli/agent.d.ts +9 -0
- package/dist/cli/agent.d.ts.map +1 -0
- package/dist/cli/agent.js +262 -0
- package/dist/cli/agent.js.map +1 -0
- package/dist/cli/commands.d.ts +12 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/{cli.js → cli/commands.js} +285 -422
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +222 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/types.d.ts +30 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +20 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/companions.d.ts +54 -0
- package/dist/companions.d.ts.map +1 -0
- package/dist/companions.js +440 -0
- package/dist/companions.js.map +1 -0
- package/dist/config.d.ts +23 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +95 -22
- package/dist/config.js.map +1 -1
- package/dist/diff.d.ts +27 -0
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +415 -10
- package/dist/diff.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +20 -11
- package/dist/errors.js.map +1 -1
- package/dist/git-status.d.ts +23 -0
- package/dist/git-status.d.ts.map +1 -0
- package/dist/git-status.js +92 -0
- package/dist/git-status.js.map +1 -0
- package/dist/headless.d.ts +25 -0
- package/dist/headless.d.ts.map +1 -0
- package/dist/headless.js +182 -0
- package/dist/headless.js.map +1 -0
- package/dist/hud/api.d.ts +35 -0
- package/dist/hud/api.d.ts.map +1 -0
- package/dist/hud/api.js +448 -0
- package/dist/hud/api.js.map +1 -0
- package/dist/hud/palettes.d.ts +9 -0
- package/dist/hud/palettes.d.ts.map +1 -0
- package/dist/hud/palettes.js +280 -0
- package/dist/hud/palettes.js.map +1 -0
- package/dist/hud/skins.d.ts +12 -0
- package/dist/hud/skins.d.ts.map +1 -0
- package/dist/hud/skins.js +365 -0
- package/dist/hud/skins.js.map +1 -0
- package/dist/hud/theme-packs/api.d.ts +51 -0
- package/dist/hud/theme-packs/api.d.ts.map +1 -0
- package/dist/hud/theme-packs/api.js +145 -0
- package/dist/hud/theme-packs/api.js.map +1 -0
- package/dist/hud/theme-packs/index.d.ts +18 -0
- package/dist/hud/theme-packs/index.d.ts.map +1 -0
- package/dist/hud/theme-packs/index.js +38 -0
- package/dist/hud/theme-packs/index.js.map +1 -0
- package/dist/hud/theme-packs/types.d.ts +29 -0
- package/dist/hud/theme-packs/types.d.ts.map +1 -0
- package/dist/hud/theme-packs/types.js +9 -0
- package/dist/hud/theme-packs/types.js.map +1 -0
- package/dist/hud/types.d.ts +182 -0
- package/dist/hud/types.d.ts.map +1 -0
- package/dist/hud/types.js +7 -0
- package/dist/hud/types.js.map +1 -0
- package/dist/idle-eviction.d.ts +34 -0
- package/dist/idle-eviction.d.ts.map +1 -0
- package/dist/idle-eviction.js +78 -0
- package/dist/idle-eviction.js.map +1 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/iteration-ledger.d.ts +105 -0
- package/dist/iteration-ledger.d.ts.map +1 -0
- package/dist/iteration-ledger.js +237 -0
- package/dist/iteration-ledger.js.map +1 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +1 -27
- package/dist/markdown.js.map +1 -1
- package/dist/mcp.d.ts +35 -0
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +291 -7
- package/dist/mcp.js.map +1 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +12 -2
- package/dist/memory.js.map +1 -1
- package/dist/model-detection.d.ts +5 -0
- package/dist/model-detection.d.ts.map +1 -1
- package/dist/model-detection.js +278 -10
- package/dist/model-detection.js.map +1 -1
- package/dist/model-router.d.ts.map +1 -1
- package/dist/model-router.js +33 -11
- package/dist/model-router.js.map +1 -1
- package/dist/plugins.d.ts +8 -0
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +97 -6
- package/dist/plugins.js.map +1 -1
- package/dist/providers/anthropic.d.ts +10 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +221 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/bedrock.d.ts +17 -0
- package/dist/providers/bedrock.d.ts.map +1 -0
- package/dist/providers/bedrock.js +574 -0
- package/dist/providers/bedrock.js.map +1 -0
- package/dist/providers/compat.d.ts +13 -0
- package/dist/providers/compat.d.ts.map +1 -0
- package/dist/providers/compat.js +202 -0
- package/dist/providers/compat.js.map +1 -0
- package/dist/providers/google.d.ts +10 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +203 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/index.d.ts +23 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +145 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/ollama.d.ts +17 -0
- package/dist/providers/ollama.d.ts.map +1 -0
- package/dist/providers/ollama.js +289 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai.d.ts +121 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +485 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +63 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +164 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/sandbox-native.d.ts +59 -0
- package/dist/sandbox-native.d.ts.map +1 -0
- package/dist/sandbox-native.js +292 -0
- package/dist/sandbox-native.js.map +1 -0
- package/dist/sandbox.d.ts +2 -2
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +59 -13
- package/dist/sandbox.js.map +1 -1
- package/dist/scope.d.ts +3 -1
- package/dist/scope.d.ts.map +1 -1
- package/dist/scope.js +13 -1
- package/dist/scope.js.map +1 -1
- package/dist/session-timeout.d.ts +31 -0
- package/dist/session-timeout.d.ts.map +1 -0
- package/dist/session-timeout.js +100 -0
- package/dist/session-timeout.js.map +1 -0
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +29 -17
- package/dist/setup.js.map +1 -1
- package/dist/smart-router.d.ts +73 -0
- package/dist/smart-router.d.ts.map +1 -0
- package/dist/smart-router.js +332 -0
- package/dist/smart-router.js.map +1 -0
- package/dist/storage.d.ts +19 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +164 -1
- package/dist/storage.js.map +1 -1
- package/dist/streaming.d.ts +4 -0
- package/dist/streaming.d.ts.map +1 -1
- package/dist/streaming.js +12 -0
- package/dist/streaming.js.map +1 -1
- package/dist/styles.d.ts +32 -0
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +91 -0
- package/dist/styles.js.map +1 -1
- package/dist/summarization.d.ts +1 -1
- package/dist/summarization.js +4 -4
- package/dist/summarization.js.map +1 -1
- package/dist/terminal-image.d.ts +115 -0
- package/dist/terminal-image.d.ts.map +1 -0
- package/dist/terminal-image.js +766 -0
- package/dist/terminal-image.js.map +1 -0
- package/dist/terminal-recording.d.ts +55 -0
- package/dist/terminal-recording.d.ts.map +1 -0
- package/dist/terminal-recording.js +182 -0
- package/dist/terminal-recording.js.map +1 -0
- package/dist/themes.d.ts +19 -35
- package/dist/themes.d.ts.map +1 -1
- package/dist/themes.js +101 -210
- package/dist/themes.js.map +1 -1
- package/dist/tmux.d.ts +35 -0
- package/dist/tmux.d.ts.map +1 -0
- package/dist/tmux.js +106 -0
- package/dist/tmux.js.map +1 -0
- package/dist/tools.d.ts +3 -3
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +587 -45
- package/dist/tools.js.map +1 -1
- package/dist/trust.d.ts +53 -0
- package/dist/trust.d.ts.map +1 -0
- package/dist/trust.js +154 -0
- package/dist/trust.js.map +1 -0
- package/dist/types.d.ts +7 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +70 -32
- package/dist/types.js.map +1 -1
- package/dist/ui/agent.d.ts +61 -0
- package/dist/ui/agent.d.ts.map +1 -0
- package/dist/ui/agent.js +768 -0
- package/dist/ui/agent.js.map +1 -0
- package/dist/ui/chat-input.d.ts +32 -0
- package/dist/ui/chat-input.d.ts.map +1 -0
- package/dist/ui/chat-input.js +355 -0
- package/dist/ui/chat-input.js.map +1 -0
- package/dist/ui/commands.d.ts +92 -0
- package/dist/ui/commands.d.ts.map +1 -0
- package/dist/ui/commands.js +3006 -0
- package/dist/ui/commands.js.map +1 -0
- package/dist/ui/completions.d.ts +22 -0
- package/dist/ui/completions.d.ts.map +1 -0
- package/dist/ui/completions.js +215 -0
- package/dist/ui/completions.js.map +1 -0
- package/dist/ui/components.d.ts +38 -0
- package/dist/ui/components.d.ts.map +1 -0
- package/dist/ui/components.js +422 -0
- package/dist/ui/components.js.map +1 -0
- package/dist/ui/context.d.ts +12 -0
- package/dist/ui/context.d.ts.map +1 -0
- package/dist/ui/context.js +102 -0
- package/dist/ui/context.js.map +1 -0
- package/dist/ui/error-boundary.d.ts +33 -0
- package/dist/ui/error-boundary.d.ts.map +1 -0
- package/dist/ui/error-boundary.js +94 -0
- package/dist/ui/error-boundary.js.map +1 -0
- package/dist/ui/frame.d.ts +13 -0
- package/dist/ui/frame.d.ts.map +1 -0
- package/dist/ui/frame.js +89 -0
- package/dist/ui/frame.js.map +1 -0
- package/dist/ui/index.d.ts +12 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +928 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/messages.d.ts +19 -0
- package/dist/ui/messages.d.ts.map +1 -0
- package/dist/ui/messages.js +181 -0
- package/dist/ui/messages.js.map +1 -0
- package/dist/ui/modals.d.ts +52 -0
- package/dist/ui/modals.d.ts.map +1 -0
- package/dist/ui/modals.js +204 -0
- package/dist/ui/modals.js.map +1 -0
- package/dist/ui/pack-picker.d.ts +12 -0
- package/dist/ui/pack-picker.d.ts.map +1 -0
- package/dist/ui/pack-picker.js +101 -0
- package/dist/ui/pack-picker.js.map +1 -0
- package/dist/ui/status-bar.d.ts +20 -0
- package/dist/ui/status-bar.d.ts.map +1 -0
- package/dist/ui/status-bar.js +41 -0
- package/dist/ui/status-bar.js.map +1 -0
- package/dist/ui/theme-picker.d.ts +24 -0
- package/dist/ui/theme-picker.d.ts.map +1 -0
- package/dist/ui/theme-picker.js +190 -0
- package/dist/ui/theme-picker.js.map +1 -0
- package/dist/ui/types.d.ts +62 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/types.js +7 -0
- package/dist/ui/types.js.map +1 -0
- package/dist/version-check.d.ts.map +1 -1
- package/dist/version-check.js +1 -9
- package/dist/version-check.js.map +1 -1
- package/package.json +8 -3
- package/dist/agterm/agent-detection.js.map +0 -1
- package/dist/agterm/cli-backend.js.map +0 -1
- package/dist/agterm/index.d.ts +0 -12
- package/dist/agterm/index.d.ts.map +0 -1
- package/dist/agterm/index.js +0 -15
- package/dist/agterm/index.js.map +0 -1
- package/dist/agterm/orchestrator.d.ts.map +0 -1
- package/dist/agterm/orchestrator.js.map +0 -1
- package/dist/agterm/tools.d.ts.map +0 -1
- package/dist/agterm/tools.js +0 -278
- package/dist/agterm/tools.js.map +0 -1
- package/dist/agterm/types.d.ts.map +0 -1
- package/dist/agterm/types.js.map +0 -1
- package/dist/cli.d.ts +0 -14
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/providers.d.ts +0 -51
- package/dist/providers.d.ts.map +0 -1
- package/dist/providers.js +0 -1146
- package/dist/providers.js.map +0 -1
- package/dist/ui-cli.d.ts +0 -17
- package/dist/ui-cli.d.ts.map +0 -1
- package/dist/ui-cli.js +0 -3730
- package/dist/ui-cli.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calliope CLI - Checkpoint/Restore Module (#20)
|
|
3
|
+
*
|
|
4
|
+
* Saves file content before overwrites so users can restore previous versions.
|
|
5
|
+
* Checkpoints are stored as individual JSON files in ~/.calliope-cli/checkpoints/
|
|
6
|
+
* organized by session date.
|
|
7
|
+
*/
|
|
8
|
+
export interface Checkpoint {
|
|
9
|
+
filePath: string;
|
|
10
|
+
content: string;
|
|
11
|
+
timestamp: string;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CheckpointSummary {
|
|
15
|
+
file: string;
|
|
16
|
+
filePath: string;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
sessionId?: string;
|
|
19
|
+
size: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the checkpoint directory path (~/.calliope-cli/checkpoints/).
|
|
23
|
+
*/
|
|
24
|
+
export declare function getCheckpointDir(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Create a checkpoint for a file before it gets overwritten.
|
|
27
|
+
* If content is provided, uses that; otherwise reads current content from disk.
|
|
28
|
+
* Returns the checkpoint filename on success, or undefined if the file doesn't exist
|
|
29
|
+
* and no content was provided.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createCheckpoint(filePath: string, content?: string, sessionId?: string): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Restore a file from its most recent checkpoint (or a specific index).
|
|
34
|
+
* Index 0 = most recent, 1 = second most recent, etc.
|
|
35
|
+
* Returns the restored content, or undefined if no checkpoint found.
|
|
36
|
+
*/
|
|
37
|
+
export declare function restoreCheckpoint(filePath: string, index?: number): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* List available checkpoints, optionally filtered by file path.
|
|
40
|
+
* Returns summaries sorted newest-first.
|
|
41
|
+
*/
|
|
42
|
+
export declare function listCheckpoints(filePath?: string): CheckpointSummary[];
|
|
43
|
+
/**
|
|
44
|
+
* Clean up old checkpoints. If olderThanDays is provided, removes checkpoints
|
|
45
|
+
* older than that many days. If omitted, removes all checkpoints.
|
|
46
|
+
* Returns the number of checkpoints removed.
|
|
47
|
+
*/
|
|
48
|
+
export declare function clearCheckpoints(olderThanDays?: number): number;
|
|
49
|
+
//# sourceMappingURL=checkpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../src/checkpoint.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAMD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAMzC;AA0BD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA2C3G;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,GAAG,SAAS,CAiBzF;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAsCtE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAiC/D"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calliope CLI - Checkpoint/Restore Module (#20)
|
|
3
|
+
*
|
|
4
|
+
* Saves file content before overwrites so users can restore previous versions.
|
|
5
|
+
* Checkpoints are stored as individual JSON files in ~/.calliope-cli/checkpoints/
|
|
6
|
+
* organized by session date.
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import * as os from 'os';
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Directory Management
|
|
13
|
+
// ============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Returns the checkpoint directory path (~/.calliope-cli/checkpoints/).
|
|
16
|
+
*/
|
|
17
|
+
export function getCheckpointDir() {
|
|
18
|
+
const dir = path.join(os.homedir(), '.calliope-cli', 'checkpoints');
|
|
19
|
+
if (!fs.existsSync(dir)) {
|
|
20
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
return dir;
|
|
23
|
+
}
|
|
24
|
+
let checkpointCounter = 0;
|
|
25
|
+
/** Auto-cleanup: remove checkpoints older than this many days */
|
|
26
|
+
const AUTO_CLEANUP_DAYS = 7;
|
|
27
|
+
/** Minimum interval between auto-cleanup runs (1 hour in ms) */
|
|
28
|
+
const AUTO_CLEANUP_INTERVAL = 60 * 60 * 1000;
|
|
29
|
+
/** Timestamp of last auto-cleanup run */
|
|
30
|
+
let lastAutoCleanup = 0;
|
|
31
|
+
/**
|
|
32
|
+
* Generate a unique checkpoint filename from a timestamp.
|
|
33
|
+
*/
|
|
34
|
+
function makeFilename(timestamp) {
|
|
35
|
+
// Replace colons and dots for filesystem safety + add counter to avoid same-millisecond collisions
|
|
36
|
+
const counter = String(checkpointCounter++).padStart(4, '0');
|
|
37
|
+
return `checkpoint-${timestamp.replace(/[:\.]/g, '-')}-${counter}.json`;
|
|
38
|
+
}
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// Core API
|
|
41
|
+
// ============================================================================
|
|
42
|
+
/**
|
|
43
|
+
* Create a checkpoint for a file before it gets overwritten.
|
|
44
|
+
* If content is provided, uses that; otherwise reads current content from disk.
|
|
45
|
+
* Returns the checkpoint filename on success, or undefined if the file doesn't exist
|
|
46
|
+
* and no content was provided.
|
|
47
|
+
*/
|
|
48
|
+
export function createCheckpoint(filePath, content, sessionId) {
|
|
49
|
+
// Auto-cleanup old checkpoints periodically (at most once per hour)
|
|
50
|
+
const now = Date.now();
|
|
51
|
+
if (now - lastAutoCleanup > AUTO_CLEANUP_INTERVAL) {
|
|
52
|
+
lastAutoCleanup = now;
|
|
53
|
+
try {
|
|
54
|
+
clearCheckpoints(AUTO_CLEANUP_DAYS);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Don't let cleanup errors block checkpoint creation
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const absPath = path.resolve(filePath);
|
|
61
|
+
// Determine content to save
|
|
62
|
+
let fileContent;
|
|
63
|
+
if (content !== undefined) {
|
|
64
|
+
fileContent = content;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
try {
|
|
68
|
+
if (!fs.existsSync(absPath)) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
fileContent = fs.readFileSync(absPath, 'utf-8');
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const timestamp = new Date().toISOString();
|
|
78
|
+
const checkpoint = {
|
|
79
|
+
filePath: absPath,
|
|
80
|
+
content: fileContent,
|
|
81
|
+
timestamp,
|
|
82
|
+
...(sessionId ? { sessionId } : {}),
|
|
83
|
+
};
|
|
84
|
+
const dir = getCheckpointDir();
|
|
85
|
+
const filename = makeFilename(timestamp);
|
|
86
|
+
const fullPath = path.join(dir, filename);
|
|
87
|
+
fs.writeFileSync(fullPath, JSON.stringify(checkpoint, null, 2));
|
|
88
|
+
return filename;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Restore a file from its most recent checkpoint (or a specific index).
|
|
92
|
+
* Index 0 = most recent, 1 = second most recent, etc.
|
|
93
|
+
* Returns the restored content, or undefined if no checkpoint found.
|
|
94
|
+
*/
|
|
95
|
+
export function restoreCheckpoint(filePath, index = 0) {
|
|
96
|
+
const absPath = path.resolve(filePath);
|
|
97
|
+
const checkpoints = getCheckpointsForFile(absPath);
|
|
98
|
+
if (index < 0 || index >= checkpoints.length) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
const checkpoint = checkpoints[index];
|
|
102
|
+
// Write the content back to the original file
|
|
103
|
+
const dir = path.dirname(absPath);
|
|
104
|
+
if (!fs.existsSync(dir)) {
|
|
105
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
106
|
+
}
|
|
107
|
+
fs.writeFileSync(absPath, checkpoint.content);
|
|
108
|
+
return checkpoint.content;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* List available checkpoints, optionally filtered by file path.
|
|
112
|
+
* Returns summaries sorted newest-first.
|
|
113
|
+
*/
|
|
114
|
+
export function listCheckpoints(filePath) {
|
|
115
|
+
const dir = getCheckpointDir();
|
|
116
|
+
let files;
|
|
117
|
+
try {
|
|
118
|
+
files = fs.readdirSync(dir).filter(f => f.startsWith('checkpoint-') && f.endsWith('.json'));
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
const summaries = [];
|
|
124
|
+
for (const file of files) {
|
|
125
|
+
try {
|
|
126
|
+
const raw = fs.readFileSync(path.join(dir, file), 'utf-8');
|
|
127
|
+
const cp = JSON.parse(raw);
|
|
128
|
+
// Filter by file path if specified
|
|
129
|
+
if (filePath) {
|
|
130
|
+
const absFilter = path.resolve(filePath);
|
|
131
|
+
if (cp.filePath !== absFilter)
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
summaries.push({
|
|
135
|
+
file,
|
|
136
|
+
filePath: cp.filePath,
|
|
137
|
+
timestamp: cp.timestamp,
|
|
138
|
+
sessionId: cp.sessionId,
|
|
139
|
+
size: cp.content.length,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// Skip corrupted checkpoint files
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Sort newest first
|
|
147
|
+
summaries.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
|
|
148
|
+
return summaries;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Clean up old checkpoints. If olderThanDays is provided, removes checkpoints
|
|
152
|
+
* older than that many days. If omitted, removes all checkpoints.
|
|
153
|
+
* Returns the number of checkpoints removed.
|
|
154
|
+
*/
|
|
155
|
+
export function clearCheckpoints(olderThanDays) {
|
|
156
|
+
const dir = getCheckpointDir();
|
|
157
|
+
let files;
|
|
158
|
+
try {
|
|
159
|
+
files = fs.readdirSync(dir).filter(f => f.startsWith('checkpoint-') && f.endsWith('.json'));
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
const cutoff = olderThanDays !== undefined
|
|
165
|
+
? new Date(Date.now() - olderThanDays * 24 * 60 * 60 * 1000)
|
|
166
|
+
: null;
|
|
167
|
+
let removed = 0;
|
|
168
|
+
for (const file of files) {
|
|
169
|
+
const fullPath = path.join(dir, file);
|
|
170
|
+
try {
|
|
171
|
+
if (cutoff) {
|
|
172
|
+
const raw = fs.readFileSync(fullPath, 'utf-8');
|
|
173
|
+
const cp = JSON.parse(raw);
|
|
174
|
+
const cpDate = new Date(cp.timestamp);
|
|
175
|
+
if (cpDate >= cutoff)
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
fs.unlinkSync(fullPath);
|
|
179
|
+
removed++;
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// Skip files that can't be read/deleted
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return removed;
|
|
186
|
+
}
|
|
187
|
+
// ============================================================================
|
|
188
|
+
// Internal Helpers
|
|
189
|
+
// ============================================================================
|
|
190
|
+
/**
|
|
191
|
+
* Get all checkpoints for a specific file path, sorted newest-first.
|
|
192
|
+
*/
|
|
193
|
+
function getCheckpointsForFile(absPath) {
|
|
194
|
+
const dir = getCheckpointDir();
|
|
195
|
+
let files;
|
|
196
|
+
try {
|
|
197
|
+
files = fs.readdirSync(dir).filter(f => f.startsWith('checkpoint-') && f.endsWith('.json'));
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
const checkpoints = [];
|
|
203
|
+
for (const file of files) {
|
|
204
|
+
try {
|
|
205
|
+
const raw = fs.readFileSync(path.join(dir, file), 'utf-8');
|
|
206
|
+
const cp = JSON.parse(raw);
|
|
207
|
+
if (cp.filePath === absPath) {
|
|
208
|
+
checkpoints.push(cp);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// Skip corrupted files
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Sort newest first
|
|
216
|
+
checkpoints.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
|
|
217
|
+
return checkpoints;
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=checkpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../src/checkpoint.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAqBzB,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC;IACpE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B,iEAAiE;AACjE,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,gEAAgE;AAChE,MAAM,qBAAqB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7C,yCAAyC;AACzC,IAAI,e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,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Circuit Breaker
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic circuit breaker that monitors agent loop iterations
|
|
5
|
+
* and trips on bad behavior patterns. State machine: closed → open → half-open.
|
|
6
|
+
*
|
|
7
|
+
* When tripped (open), the agent loop should pause and notify the user.
|
|
8
|
+
* User can resume (half-open) which runs at reduced thresholds (50%).
|
|
9
|
+
*/
|
|
10
|
+
import type { BreakerType, BreakerStatus, BreakerCheckResult, CircuitBreakerConfig, IterationData } from './types.js';
|
|
11
|
+
export declare class CircuitBreaker {
|
|
12
|
+
private config;
|
|
13
|
+
private states;
|
|
14
|
+
private tripCounts;
|
|
15
|
+
private lastTripped;
|
|
16
|
+
private lastEvents;
|
|
17
|
+
private consecutiveErrors;
|
|
18
|
+
private totalTokens;
|
|
19
|
+
private totalCost;
|
|
20
|
+
private idleCount;
|
|
21
|
+
private costWindow;
|
|
22
|
+
private toolCallHistory;
|
|
23
|
+
private startTime;
|
|
24
|
+
private lastIterationStart;
|
|
25
|
+
constructor(config?: Partial<CircuitBreakerConfig>);
|
|
26
|
+
/**
|
|
27
|
+
* Check all breakers against iteration data. Returns the first trip found.
|
|
28
|
+
*/
|
|
29
|
+
check(data: IterationData): BreakerCheckResult;
|
|
30
|
+
/**
|
|
31
|
+
* Resume a tripped breaker (moves to half-open state with 50% thresholds).
|
|
32
|
+
*/
|
|
33
|
+
resume(type?: BreakerType): void;
|
|
34
|
+
/**
|
|
35
|
+
* Reset a specific breaker or all breakers to closed.
|
|
36
|
+
*/
|
|
37
|
+
reset(type?: BreakerType): void;
|
|
38
|
+
/**
|
|
39
|
+
* Update thresholds for a specific breaker at runtime.
|
|
40
|
+
*/
|
|
41
|
+
adjust(type: BreakerType, thresholds: Record<string, unknown>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get status of all breakers.
|
|
44
|
+
*/
|
|
45
|
+
getStatus(): BreakerStatus[];
|
|
46
|
+
/**
|
|
47
|
+
* Get overall health: 'ok' | 'warning' | 'tripped'
|
|
48
|
+
*/
|
|
49
|
+
getHealth(): 'ok' | 'warning' | 'tripped';
|
|
50
|
+
/**
|
|
51
|
+
* Check if any breaker is currently tripped (open state).
|
|
52
|
+
*/
|
|
53
|
+
isTripped(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Get the current config.
|
|
56
|
+
*/
|
|
57
|
+
getConfig(): CircuitBreakerConfig;
|
|
58
|
+
/**
|
|
59
|
+
* Get tracking stats for display.
|
|
60
|
+
*/
|
|
61
|
+
getTrackingStats(): {
|
|
62
|
+
consecutiveErrors: number;
|
|
63
|
+
totalTokens: number;
|
|
64
|
+
totalCost: number;
|
|
65
|
+
idleCount: number;
|
|
66
|
+
recentToolCalls: number;
|
|
67
|
+
};
|
|
68
|
+
private updateTracking;
|
|
69
|
+
private resetTrackingForBreaker;
|
|
70
|
+
private resetAllTracking;
|
|
71
|
+
private trip;
|
|
72
|
+
private getThresholdMultiplier;
|
|
73
|
+
private checkRepeatedFailure;
|
|
74
|
+
private checkCostRunaway;
|
|
75
|
+
private checkInfiniteLoop;
|
|
76
|
+
private checkTokenBurn;
|
|
77
|
+
private checkStall;
|
|
78
|
+
private checkWallClock;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breaker.d.ts","sourceRoot":"","sources":["../../src/circuit-breaker/breaker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,WAAW,EAEX,aAAa,EAEb,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACd,MAAM,YAAY,CAAC;AAmBpB,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAuB;IAGrC,OAAO,CAAC,MAAM,CAA6C;IAC3D,OAAO,CAAC,UAAU,CAAuC;IACzD,OAAO,CAAC,WAAW,CAAq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