attocode 0.1.0
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/CHANGELOG.md +48 -0
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/src/adapters.d.ts +83 -0
- package/dist/src/adapters.d.ts.map +1 -0
- package/dist/src/adapters.js +221 -0
- package/dist/src/adapters.js.map +1 -0
- package/dist/src/agent-tools/index.d.ts +7 -0
- package/dist/src/agent-tools/index.d.ts.map +1 -0
- package/dist/src/agent-tools/index.js +8 -0
- package/dist/src/agent-tools/index.js.map +1 -0
- package/dist/src/agent-tools/lsp-file-tools.d.ts +33 -0
- package/dist/src/agent-tools/lsp-file-tools.d.ts.map +1 -0
- package/dist/src/agent-tools/lsp-file-tools.js +200 -0
- package/dist/src/agent-tools/lsp-file-tools.js.map +1 -0
- package/dist/src/agent.d.ts +667 -0
- package/dist/src/agent.d.ts.map +1 -0
- package/dist/src/agent.js +2824 -0
- package/dist/src/agent.js.map +1 -0
- package/dist/src/cli.d.ts +36 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +176 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/handler.d.ts +22 -0
- package/dist/src/commands/handler.d.ts.map +1 -0
- package/dist/src/commands/handler.js +1320 -0
- package/dist/src/commands/handler.js.map +1 -0
- package/dist/src/commands/init.d.ts +7 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +153 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/types.d.ts +70 -0
- package/dist/src/commands/types.d.ts.map +1 -0
- package/dist/src/commands/types.js +8 -0
- package/dist/src/commands/types.js.map +1 -0
- package/dist/src/config.d.ts +22 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +25 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/core/index.d.ts +32 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +35 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/process-handlers.d.ts +43 -0
- package/dist/src/core/process-handlers.d.ts.map +1 -0
- package/dist/src/core/process-handlers.js +117 -0
- package/dist/src/core/process-handlers.js.map +1 -0
- package/dist/src/core/protocol/bridge.d.ts +117 -0
- package/dist/src/core/protocol/bridge.d.ts.map +1 -0
- package/dist/src/core/protocol/bridge.js +149 -0
- package/dist/src/core/protocol/bridge.js.map +1 -0
- package/dist/src/core/protocol/index.d.ts +8 -0
- package/dist/src/core/protocol/index.d.ts.map +1 -0
- package/dist/src/core/protocol/index.js +8 -0
- package/dist/src/core/protocol/index.js.map +1 -0
- package/dist/src/core/protocol/types.d.ts +539 -0
- package/dist/src/core/protocol/types.d.ts.map +1 -0
- package/dist/src/core/protocol/types.js +149 -0
- package/dist/src/core/protocol/types.js.map +1 -0
- package/dist/src/core/queues/atomic-counter.d.ts +36 -0
- package/dist/src/core/queues/atomic-counter.d.ts.map +1 -0
- package/dist/src/core/queues/atomic-counter.js +46 -0
- package/dist/src/core/queues/atomic-counter.js.map +1 -0
- package/dist/src/core/queues/event-queue.d.ts +126 -0
- package/dist/src/core/queues/event-queue.d.ts.map +1 -0
- package/dist/src/core/queues/event-queue.js +208 -0
- package/dist/src/core/queues/event-queue.js.map +1 -0
- package/dist/src/core/queues/index.d.ts +12 -0
- package/dist/src/core/queues/index.d.ts.map +1 -0
- package/dist/src/core/queues/index.js +15 -0
- package/dist/src/core/queues/index.js.map +1 -0
- package/dist/src/core/queues/submission-queue.d.ts +116 -0
- package/dist/src/core/queues/submission-queue.d.ts.map +1 -0
- package/dist/src/core/queues/submission-queue.js +236 -0
- package/dist/src/core/queues/submission-queue.js.map +1 -0
- package/dist/src/costs/index.d.ts +22 -0
- package/dist/src/costs/index.d.ts.map +1 -0
- package/dist/src/costs/index.js +22 -0
- package/dist/src/costs/index.js.map +1 -0
- package/dist/src/costs/model-registry.d.ts +80 -0
- package/dist/src/costs/model-registry.d.ts.map +1 -0
- package/dist/src/costs/model-registry.js +237 -0
- package/dist/src/costs/model-registry.js.map +1 -0
- package/dist/src/costs/types.d.ts +50 -0
- package/dist/src/costs/types.d.ts.map +1 -0
- package/dist/src/costs/types.js +2 -0
- package/dist/src/costs/types.js.map +1 -0
- package/dist/src/defaults.d.ts +114 -0
- package/dist/src/defaults.d.ts.map +1 -0
- package/dist/src/defaults.js +457 -0
- package/dist/src/defaults.js.map +1 -0
- package/dist/src/first-run.d.ts +35 -0
- package/dist/src/first-run.d.ts.map +1 -0
- package/dist/src/first-run.js +94 -0
- package/dist/src/first-run.js.map +1 -0
- package/dist/src/hello.d.ts +2 -0
- package/dist/src/hello.d.ts.map +1 -0
- package/dist/src/hello.js +4 -0
- package/dist/src/hello.js.map +1 -0
- package/dist/src/integrations/agent-registry.d.ts +160 -0
- package/dist/src/integrations/agent-registry.d.ts.map +1 -0
- package/dist/src/integrations/agent-registry.js +446 -0
- package/dist/src/integrations/agent-registry.js.map +1 -0
- package/dist/src/integrations/auto-compaction.d.ts +177 -0
- package/dist/src/integrations/auto-compaction.d.ts.map +1 -0
- package/dist/src/integrations/auto-compaction.js +428 -0
- package/dist/src/integrations/auto-compaction.js.map +1 -0
- package/dist/src/integrations/cancellation.d.ts +162 -0
- package/dist/src/integrations/cancellation.d.ts.map +1 -0
- package/dist/src/integrations/cancellation.js +339 -0
- package/dist/src/integrations/cancellation.js.map +1 -0
- package/dist/src/integrations/codebase-context.d.ts +319 -0
- package/dist/src/integrations/codebase-context.d.ts.map +1 -0
- package/dist/src/integrations/codebase-context.js +816 -0
- package/dist/src/integrations/codebase-context.js.map +1 -0
- package/dist/src/integrations/compaction.d.ts +192 -0
- package/dist/src/integrations/compaction.d.ts.map +1 -0
- package/dist/src/integrations/compaction.js +376 -0
- package/dist/src/integrations/compaction.js.map +1 -0
- package/dist/src/integrations/context-engineering.d.ts +246 -0
- package/dist/src/integrations/context-engineering.d.ts.map +1 -0
- package/dist/src/integrations/context-engineering.js +394 -0
- package/dist/src/integrations/context-engineering.js.map +1 -0
- package/dist/src/integrations/diff-utils.d.ts +105 -0
- package/dist/src/integrations/diff-utils.d.ts.map +1 -0
- package/dist/src/integrations/diff-utils.js +497 -0
- package/dist/src/integrations/diff-utils.js.map +1 -0
- package/dist/src/integrations/economics.d.ts +192 -0
- package/dist/src/integrations/economics.d.ts.map +1 -0
- package/dist/src/integrations/economics.js +431 -0
- package/dist/src/integrations/economics.js.map +1 -0
- package/dist/src/integrations/execution-policy.d.ts +189 -0
- package/dist/src/integrations/execution-policy.d.ts.map +1 -0
- package/dist/src/integrations/execution-policy.js +352 -0
- package/dist/src/integrations/execution-policy.js.map +1 -0
- package/dist/src/integrations/file-change-tracker.d.ts +161 -0
- package/dist/src/integrations/file-change-tracker.d.ts.map +1 -0
- package/dist/src/integrations/file-change-tracker.js +520 -0
- package/dist/src/integrations/file-change-tracker.js.map +1 -0
- package/dist/src/integrations/hierarchical-config.d.ts +212 -0
- package/dist/src/integrations/hierarchical-config.d.ts.map +1 -0
- package/dist/src/integrations/hierarchical-config.js +484 -0
- package/dist/src/integrations/hierarchical-config.js.map +1 -0
- package/dist/src/integrations/hooks.d.ts +114 -0
- package/dist/src/integrations/hooks.d.ts.map +1 -0
- package/dist/src/integrations/hooks.js +326 -0
- package/dist/src/integrations/hooks.js.map +1 -0
- package/dist/src/integrations/ignore.d.ts +143 -0
- package/dist/src/integrations/ignore.d.ts.map +1 -0
- package/dist/src/integrations/ignore.js +417 -0
- package/dist/src/integrations/ignore.js.map +1 -0
- package/dist/src/integrations/image-renderer.d.ts +119 -0
- package/dist/src/integrations/image-renderer.d.ts.map +1 -0
- package/dist/src/integrations/image-renderer.js +306 -0
- package/dist/src/integrations/image-renderer.js.map +1 -0
- package/dist/src/integrations/index.d.ts +42 -0
- package/dist/src/integrations/index.d.ts.map +1 -0
- package/dist/src/integrations/index.js +73 -0
- package/dist/src/integrations/index.js.map +1 -0
- package/dist/src/integrations/lsp.d.ts +196 -0
- package/dist/src/integrations/lsp.d.ts.map +1 -0
- package/dist/src/integrations/lsp.js +582 -0
- package/dist/src/integrations/lsp.js.map +1 -0
- package/dist/src/integrations/mcp-client.d.ts +270 -0
- package/dist/src/integrations/mcp-client.d.ts.map +1 -0
- package/dist/src/integrations/mcp-client.js +698 -0
- package/dist/src/integrations/mcp-client.js.map +1 -0
- package/dist/src/integrations/mcp-tool-search.d.ts +77 -0
- package/dist/src/integrations/mcp-tool-search.d.ts.map +1 -0
- package/dist/src/integrations/mcp-tool-search.js +220 -0
- package/dist/src/integrations/mcp-tool-search.js.map +1 -0
- package/dist/src/integrations/memory.d.ts +108 -0
- package/dist/src/integrations/memory.d.ts.map +1 -0
- package/dist/src/integrations/memory.js +288 -0
- package/dist/src/integrations/memory.js.map +1 -0
- package/dist/src/integrations/multi-agent.d.ts +150 -0
- package/dist/src/integrations/multi-agent.d.ts.map +1 -0
- package/dist/src/integrations/multi-agent.js +306 -0
- package/dist/src/integrations/multi-agent.js.map +1 -0
- package/dist/src/integrations/observability.d.ts +162 -0
- package/dist/src/integrations/observability.d.ts.map +1 -0
- package/dist/src/integrations/observability.js +406 -0
- package/dist/src/integrations/observability.js.map +1 -0
- package/dist/src/integrations/openrouter-pricing.d.ts +42 -0
- package/dist/src/integrations/openrouter-pricing.d.ts.map +1 -0
- package/dist/src/integrations/openrouter-pricing.js +124 -0
- package/dist/src/integrations/openrouter-pricing.js.map +1 -0
- package/dist/src/integrations/pending-plan.d.ts +171 -0
- package/dist/src/integrations/pending-plan.d.ts.map +1 -0
- package/dist/src/integrations/pending-plan.js +244 -0
- package/dist/src/integrations/pending-plan.js.map +1 -0
- package/dist/src/integrations/persistence.d.ts +48 -0
- package/dist/src/integrations/persistence.d.ts.map +1 -0
- package/dist/src/integrations/persistence.js +196 -0
- package/dist/src/integrations/persistence.js.map +1 -0
- package/dist/src/integrations/planning.d.ts +96 -0
- package/dist/src/integrations/planning.d.ts.map +1 -0
- package/dist/src/integrations/planning.js +338 -0
- package/dist/src/integrations/planning.js.map +1 -0
- package/dist/src/integrations/pty-shell.d.ts +169 -0
- package/dist/src/integrations/pty-shell.d.ts.map +1 -0
- package/dist/src/integrations/pty-shell.js +367 -0
- package/dist/src/integrations/pty-shell.js.map +1 -0
- package/dist/src/integrations/react.d.ts +139 -0
- package/dist/src/integrations/react.d.ts.map +1 -0
- package/dist/src/integrations/react.js +273 -0
- package/dist/src/integrations/react.js.map +1 -0
- package/dist/src/integrations/resources.d.ts +177 -0
- package/dist/src/integrations/resources.d.ts.map +1 -0
- package/dist/src/integrations/resources.js +311 -0
- package/dist/src/integrations/resources.js.map +1 -0
- package/dist/src/integrations/result-synthesizer.d.ts +389 -0
- package/dist/src/integrations/result-synthesizer.d.ts.map +1 -0
- package/dist/src/integrations/result-synthesizer.js +951 -0
- package/dist/src/integrations/result-synthesizer.js.map +1 -0
- package/dist/src/integrations/routing.d.ts +117 -0
- package/dist/src/integrations/routing.d.ts.map +1 -0
- package/dist/src/integrations/routing.js +347 -0
- package/dist/src/integrations/routing.js.map +1 -0
- package/dist/src/integrations/rules.d.ts +131 -0
- package/dist/src/integrations/rules.d.ts.map +1 -0
- package/dist/src/integrations/rules.js +284 -0
- package/dist/src/integrations/rules.js.map +1 -0
- package/dist/src/integrations/safety.d.ts +142 -0
- package/dist/src/integrations/safety.d.ts.map +1 -0
- package/dist/src/integrations/safety.js +342 -0
- package/dist/src/integrations/safety.js.map +1 -0
- package/dist/src/integrations/sandbox/basic.d.ts +74 -0
- package/dist/src/integrations/sandbox/basic.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/basic.js +310 -0
- package/dist/src/integrations/sandbox/basic.js.map +1 -0
- package/dist/src/integrations/sandbox/docker.d.ts +94 -0
- package/dist/src/integrations/sandbox/docker.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/docker.js +293 -0
- package/dist/src/integrations/sandbox/docker.js.map +1 -0
- package/dist/src/integrations/sandbox/index.d.ts +182 -0
- package/dist/src/integrations/sandbox/index.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/index.js +382 -0
- package/dist/src/integrations/sandbox/index.js.map +1 -0
- package/dist/src/integrations/sandbox/landlock.d.ts +59 -0
- package/dist/src/integrations/sandbox/landlock.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/landlock.js +326 -0
- package/dist/src/integrations/sandbox/landlock.js.map +1 -0
- package/dist/src/integrations/sandbox/seatbelt.d.ts +68 -0
- package/dist/src/integrations/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/seatbelt.js +298 -0
- package/dist/src/integrations/sandbox/seatbelt.js.map +1 -0
- package/dist/src/integrations/semantic-cache.d.ts +178 -0
- package/dist/src/integrations/semantic-cache.d.ts.map +1 -0
- package/dist/src/integrations/semantic-cache.js +372 -0
- package/dist/src/integrations/semantic-cache.js.map +1 -0
- package/dist/src/integrations/session-store.d.ts +183 -0
- package/dist/src/integrations/session-store.d.ts.map +1 -0
- package/dist/src/integrations/session-store.js +345 -0
- package/dist/src/integrations/session-store.js.map +1 -0
- package/dist/src/integrations/shared-blackboard.d.ts +403 -0
- package/dist/src/integrations/shared-blackboard.d.ts.map +1 -0
- package/dist/src/integrations/shared-blackboard.js +710 -0
- package/dist/src/integrations/shared-blackboard.js.map +1 -0
- package/dist/src/integrations/skills.d.ts +171 -0
- package/dist/src/integrations/skills.d.ts.map +1 -0
- package/dist/src/integrations/skills.js +403 -0
- package/dist/src/integrations/skills.js.map +1 -0
- package/dist/src/integrations/smart-decomposer.d.ts +322 -0
- package/dist/src/integrations/smart-decomposer.d.ts.map +1 -0
- package/dist/src/integrations/smart-decomposer.js +856 -0
- package/dist/src/integrations/smart-decomposer.js.map +1 -0
- package/dist/src/integrations/sourcegraph.d.ts +169 -0
- package/dist/src/integrations/sourcegraph.d.ts.map +1 -0
- package/dist/src/integrations/sourcegraph.js +379 -0
- package/dist/src/integrations/sourcegraph.js.map +1 -0
- package/dist/src/integrations/sqlite-store.d.ts +518 -0
- package/dist/src/integrations/sqlite-store.d.ts.map +1 -0
- package/dist/src/integrations/sqlite-store.js +1423 -0
- package/dist/src/integrations/sqlite-store.js.map +1 -0
- package/dist/src/integrations/streaming.d.ts +102 -0
- package/dist/src/integrations/streaming.d.ts.map +1 -0
- package/dist/src/integrations/streaming.js +362 -0
- package/dist/src/integrations/streaming.js.map +1 -0
- package/dist/src/integrations/thread-manager.d.ts +199 -0
- package/dist/src/integrations/thread-manager.d.ts.map +1 -0
- package/dist/src/integrations/thread-manager.js +357 -0
- package/dist/src/integrations/thread-manager.js.map +1 -0
- package/dist/src/main.d.ts +26 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +170 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/modes/index.d.ts +10 -0
- package/dist/src/modes/index.d.ts.map +1 -0
- package/dist/src/modes/index.js +10 -0
- package/dist/src/modes/index.js.map +1 -0
- package/dist/src/modes/repl.d.ts +19 -0
- package/dist/src/modes/repl.d.ts.map +1 -0
- package/dist/src/modes/repl.js +393 -0
- package/dist/src/modes/repl.js.map +1 -0
- package/dist/src/modes/tui.d.ts +29 -0
- package/dist/src/modes/tui.d.ts.map +1 -0
- package/dist/src/modes/tui.js +272 -0
- package/dist/src/modes/tui.js.map +1 -0
- package/dist/src/modes.d.ts +179 -0
- package/dist/src/modes.d.ts.map +1 -0
- package/dist/src/modes.js +385 -0
- package/dist/src/modes.js.map +1 -0
- package/dist/src/observability/tracer.d.ts +111 -0
- package/dist/src/observability/tracer.d.ts.map +1 -0
- package/dist/src/observability/tracer.js +300 -0
- package/dist/src/observability/tracer.js.map +1 -0
- package/dist/src/observability/types.d.ts +271 -0
- package/dist/src/observability/types.d.ts.map +1 -0
- package/dist/src/observability/types.js +24 -0
- package/dist/src/observability/types.js.map +1 -0
- package/dist/src/paths.d.ts +101 -0
- package/dist/src/paths.d.ts.map +1 -0
- package/dist/src/paths.js +148 -0
- package/dist/src/paths.js.map +1 -0
- package/dist/src/persistence/index.d.ts +38 -0
- package/dist/src/persistence/index.d.ts.map +1 -0
- package/dist/src/persistence/index.js +48 -0
- package/dist/src/persistence/index.js.map +1 -0
- package/dist/src/persistence/migrator.d.ts +135 -0
- package/dist/src/persistence/migrator.d.ts.map +1 -0
- package/dist/src/persistence/migrator.js +303 -0
- package/dist/src/persistence/migrator.js.map +1 -0
- package/dist/src/persistence/schema.d.ts +101 -0
- package/dist/src/persistence/schema.d.ts.map +1 -0
- package/dist/src/persistence/schema.js +395 -0
- package/dist/src/persistence/schema.js.map +1 -0
- package/dist/src/providers/adapters/anthropic.d.ts +20 -0
- package/dist/src/providers/adapters/anthropic.d.ts.map +1 -0
- package/dist/src/providers/adapters/anthropic.js +124 -0
- package/dist/src/providers/adapters/anthropic.js.map +1 -0
- package/dist/src/providers/adapters/mock.d.ts +25 -0
- package/dist/src/providers/adapters/mock.d.ts.map +1 -0
- package/dist/src/providers/adapters/mock.js +133 -0
- package/dist/src/providers/adapters/mock.js.map +1 -0
- package/dist/src/providers/adapters/openai.d.ts +21 -0
- package/dist/src/providers/adapters/openai.d.ts.map +1 -0
- package/dist/src/providers/adapters/openai.js +126 -0
- package/dist/src/providers/adapters/openai.js.map +1 -0
- package/dist/src/providers/adapters/openrouter.d.ts +49 -0
- package/dist/src/providers/adapters/openrouter.d.ts.map +1 -0
- package/dist/src/providers/adapters/openrouter.js +363 -0
- package/dist/src/providers/adapters/openrouter.js.map +1 -0
- package/dist/src/providers/provider.d.ts +54 -0
- package/dist/src/providers/provider.d.ts.map +1 -0
- package/dist/src/providers/provider.js +111 -0
- package/dist/src/providers/provider.js.map +1 -0
- package/dist/src/providers/resilient-fetch.d.ts +99 -0
- package/dist/src/providers/resilient-fetch.d.ts.map +1 -0
- package/dist/src/providers/resilient-fetch.js +208 -0
- package/dist/src/providers/resilient-fetch.js.map +1 -0
- package/dist/src/providers/types.d.ts +227 -0
- package/dist/src/providers/types.d.ts.map +1 -0
- package/dist/src/providers/types.js +24 -0
- package/dist/src/providers/types.js.map +1 -0
- package/dist/src/session-picker.d.ts +28 -0
- package/dist/src/session-picker.d.ts.map +1 -0
- package/dist/src/session-picker.js +256 -0
- package/dist/src/session-picker.js.map +1 -0
- package/dist/src/test-sqlite.d.ts +2 -0
- package/dist/src/test-sqlite.d.ts.map +1 -0
- package/dist/src/test-sqlite.js +114 -0
- package/dist/src/test-sqlite.js.map +1 -0
- package/dist/src/tools/agent.d.ts +44 -0
- package/dist/src/tools/agent.d.ts.map +1 -0
- package/dist/src/tools/agent.js +110 -0
- package/dist/src/tools/agent.js.map +1 -0
- package/dist/src/tools/bash.d.ts +52 -0
- package/dist/src/tools/bash.d.ts.map +1 -0
- package/dist/src/tools/bash.js +141 -0
- package/dist/src/tools/bash.js.map +1 -0
- package/dist/src/tools/file.d.ts +47 -0
- package/dist/src/tools/file.d.ts.map +1 -0
- package/dist/src/tools/file.js +263 -0
- package/dist/src/tools/file.js.map +1 -0
- package/dist/src/tools/permission.d.ts +43 -0
- package/dist/src/tools/permission.d.ts.map +1 -0
- package/dist/src/tools/permission.js +216 -0
- package/dist/src/tools/permission.js.map +1 -0
- package/dist/src/tools/registry.d.ts +63 -0
- package/dist/src/tools/registry.d.ts.map +1 -0
- package/dist/src/tools/registry.js +250 -0
- package/dist/src/tools/registry.js.map +1 -0
- package/dist/src/tools/standard.d.ts +57 -0
- package/dist/src/tools/standard.d.ts.map +1 -0
- package/dist/src/tools/standard.js +113 -0
- package/dist/src/tools/standard.js.map +1 -0
- package/dist/src/tools/types.d.ts +146 -0
- package/dist/src/tools/types.d.ts.map +1 -0
- package/dist/src/tools/types.js +28 -0
- package/dist/src/tools/types.js.map +1 -0
- package/dist/src/tools/undo.d.ts +71 -0
- package/dist/src/tools/undo.d.ts.map +1 -0
- package/dist/src/tools/undo.js +123 -0
- package/dist/src/tools/undo.js.map +1 -0
- package/dist/src/tracing/cache-boundary-tracker.d.ts +189 -0
- package/dist/src/tracing/cache-boundary-tracker.d.ts.map +1 -0
- package/dist/src/tracing/cache-boundary-tracker.js +411 -0
- package/dist/src/tracing/cache-boundary-tracker.js.map +1 -0
- package/dist/src/tracing/trace-collector.d.ts +274 -0
- package/dist/src/tracing/trace-collector.d.ts.map +1 -0
- package/dist/src/tracing/trace-collector.js +727 -0
- package/dist/src/tracing/trace-collector.js.map +1 -0
- package/dist/src/tracing/types.d.ts +657 -0
- package/dist/src/tracing/types.d.ts.map +1 -0
- package/dist/src/tracing/types.js +39 -0
- package/dist/src/tracing/types.js.map +1 -0
- package/dist/src/tricks/failure-evidence.d.ts +268 -0
- package/dist/src/tricks/failure-evidence.d.ts.map +1 -0
- package/dist/src/tricks/failure-evidence.js +544 -0
- package/dist/src/tricks/failure-evidence.js.map +1 -0
- package/dist/src/tricks/json-utils.d.ts +77 -0
- package/dist/src/tricks/json-utils.d.ts.map +1 -0
- package/dist/src/tricks/json-utils.js +247 -0
- package/dist/src/tricks/json-utils.js.map +1 -0
- package/dist/src/tricks/kv-cache-context.d.ts +227 -0
- package/dist/src/tricks/kv-cache-context.d.ts.map +1 -0
- package/dist/src/tricks/kv-cache-context.js +377 -0
- package/dist/src/tricks/kv-cache-context.js.map +1 -0
- package/dist/src/tricks/recitation.d.ts +208 -0
- package/dist/src/tricks/recitation.d.ts.map +1 -0
- package/dist/src/tricks/recitation.js +374 -0
- package/dist/src/tricks/recitation.js.map +1 -0
- package/dist/src/tricks/reversible-compaction.d.ts +251 -0
- package/dist/src/tricks/reversible-compaction.d.ts.map +1 -0
- package/dist/src/tricks/reversible-compaction.js +555 -0
- package/dist/src/tricks/reversible-compaction.js.map +1 -0
- package/dist/src/tricks/serialization-diversity.d.ts +197 -0
- package/dist/src/tricks/serialization-diversity.d.ts.map +1 -0
- package/dist/src/tricks/serialization-diversity.js +460 -0
- package/dist/src/tricks/serialization-diversity.js.map +1 -0
- package/dist/src/tui/app.d.ts +42 -0
- package/dist/src/tui/app.d.ts.map +1 -0
- package/dist/src/tui/app.js +1076 -0
- package/dist/src/tui/app.js.map +1 -0
- package/dist/src/tui/components/ApprovalDialog.d.ts +28 -0
- package/dist/src/tui/components/ApprovalDialog.d.ts.map +1 -0
- package/dist/src/tui/components/ApprovalDialog.js +59 -0
- package/dist/src/tui/components/ApprovalDialog.js.map +1 -0
- package/dist/src/tui/components/InputArea.d.ts +35 -0
- package/dist/src/tui/components/InputArea.d.ts.map +1 -0
- package/dist/src/tui/components/InputArea.js +144 -0
- package/dist/src/tui/components/InputArea.js.map +1 -0
- package/dist/src/tui/components/MessageItem.d.ts +28 -0
- package/dist/src/tui/components/MessageItem.d.ts.map +1 -0
- package/dist/src/tui/components/MessageItem.js +27 -0
- package/dist/src/tui/components/MessageItem.js.map +1 -0
- package/dist/src/tui/components/ScrollableBox.d.ts +41 -0
- package/dist/src/tui/components/ScrollableBox.d.ts.map +1 -0
- package/dist/src/tui/components/ScrollableBox.js +101 -0
- package/dist/src/tui/components/ScrollableBox.js.map +1 -0
- package/dist/src/tui/components/ToolCallItem.d.ts +33 -0
- package/dist/src/tui/components/ToolCallItem.d.ts.map +1 -0
- package/dist/src/tui/components/ToolCallItem.js +91 -0
- package/dist/src/tui/components/ToolCallItem.js.map +1 -0
- package/dist/src/tui/components/index.d.ts +13 -0
- package/dist/src/tui/components/index.d.ts.map +1 -0
- package/dist/src/tui/components/index.js +15 -0
- package/dist/src/tui/components/index.js.map +1 -0
- package/dist/src/tui/event-display.d.ts +19 -0
- package/dist/src/tui/event-display.d.ts.map +1 -0
- package/dist/src/tui/event-display.js +178 -0
- package/dist/src/tui/event-display.js.map +1 -0
- package/dist/src/tui/index.d.ts +105 -0
- package/dist/src/tui/index.d.ts.map +1 -0
- package/dist/src/tui/index.js +214 -0
- package/dist/src/tui/index.js.map +1 -0
- package/dist/src/tui/input/CommandPalette.d.ts +55 -0
- package/dist/src/tui/input/CommandPalette.d.ts.map +1 -0
- package/dist/src/tui/input/CommandPalette.js +135 -0
- package/dist/src/tui/input/CommandPalette.js.map +1 -0
- package/dist/src/tui/input/index.d.ts +7 -0
- package/dist/src/tui/input/index.d.ts.map +1 -0
- package/dist/src/tui/input/index.js +7 -0
- package/dist/src/tui/input/index.js.map +1 -0
- package/dist/src/tui/theme/index.d.ts +45 -0
- package/dist/src/tui/theme/index.d.ts.map +1 -0
- package/dist/src/tui/theme/index.js +215 -0
- package/dist/src/tui/theme/index.js.map +1 -0
- package/dist/src/tui/types.d.ts +214 -0
- package/dist/src/tui/types.d.ts.map +1 -0
- package/dist/src/tui/types.js +27 -0
- package/dist/src/tui/types.js.map +1 -0
- package/dist/src/types.d.ts +905 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +9 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Cache Integration
|
|
3
|
+
*
|
|
4
|
+
* Caches LLM responses based on semantic similarity of queries.
|
|
5
|
+
* Returns cached response if a query is similar enough to a previous one.
|
|
6
|
+
* Adapted from tricks/semantic-cache.ts.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const cache = createSemanticCacheManager({ threshold: 0.95 });
|
|
10
|
+
* const hit = await cache.get("What is X?");
|
|
11
|
+
* if (hit) return hit.response;
|
|
12
|
+
* // else call LLM and cache result
|
|
13
|
+
* await cache.set("What is X?", response);
|
|
14
|
+
*/
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// EMBEDDING UTILITIES
|
|
17
|
+
// =============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Simple word-based embedding (for demo purposes).
|
|
20
|
+
* Production should use real embedding model (OpenAI, Sentence Transformers, etc.)
|
|
21
|
+
*/
|
|
22
|
+
async function simpleEmbed(text) {
|
|
23
|
+
// Normalize text
|
|
24
|
+
const normalized = text.toLowerCase().replace(/[^\w\s]/g, '');
|
|
25
|
+
const words = normalized.split(/\s+/);
|
|
26
|
+
// Create a simple bag-of-words style embedding
|
|
27
|
+
// Use a fixed vocabulary size with hashing
|
|
28
|
+
const vocabSize = 256;
|
|
29
|
+
const embedding = new Array(vocabSize).fill(0);
|
|
30
|
+
for (const word of words) {
|
|
31
|
+
const hash = simpleHash(word) % vocabSize;
|
|
32
|
+
embedding[hash] += 1;
|
|
33
|
+
}
|
|
34
|
+
// Normalize
|
|
35
|
+
const magnitude = Math.sqrt(embedding.reduce((sum, val) => sum + val * val, 0));
|
|
36
|
+
if (magnitude > 0) {
|
|
37
|
+
for (let i = 0; i < embedding.length; i++) {
|
|
38
|
+
embedding[i] /= magnitude;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return embedding;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Simple hash function.
|
|
45
|
+
*/
|
|
46
|
+
function simpleHash(str) {
|
|
47
|
+
let hash = 0;
|
|
48
|
+
for (let i = 0; i < str.length; i++) {
|
|
49
|
+
const char = str.charCodeAt(i);
|
|
50
|
+
hash = (hash << 5) - hash + char;
|
|
51
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
52
|
+
}
|
|
53
|
+
return Math.abs(hash);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Cosine similarity between two vectors.
|
|
57
|
+
*/
|
|
58
|
+
export function cosineSimilarity(a, b) {
|
|
59
|
+
if (a.length !== b.length) {
|
|
60
|
+
throw new Error('Vectors must have same length');
|
|
61
|
+
}
|
|
62
|
+
let dotProduct = 0;
|
|
63
|
+
let magnitudeA = 0;
|
|
64
|
+
let magnitudeB = 0;
|
|
65
|
+
for (let i = 0; i < a.length; i++) {
|
|
66
|
+
dotProduct += a[i] * b[i];
|
|
67
|
+
magnitudeA += a[i] * a[i];
|
|
68
|
+
magnitudeB += b[i] * b[i];
|
|
69
|
+
}
|
|
70
|
+
magnitudeA = Math.sqrt(magnitudeA);
|
|
71
|
+
magnitudeB = Math.sqrt(magnitudeB);
|
|
72
|
+
if (magnitudeA === 0 || magnitudeB === 0) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
return dotProduct / (magnitudeA * magnitudeB);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generate unique ID.
|
|
79
|
+
*/
|
|
80
|
+
function generateId() {
|
|
81
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
82
|
+
}
|
|
83
|
+
// =============================================================================
|
|
84
|
+
// SEMANTIC CACHE MANAGER
|
|
85
|
+
// =============================================================================
|
|
86
|
+
/**
|
|
87
|
+
* Manages semantic caching of LLM responses.
|
|
88
|
+
*/
|
|
89
|
+
export class SemanticCacheManager {
|
|
90
|
+
entries = new Map();
|
|
91
|
+
config;
|
|
92
|
+
eventListeners = new Set();
|
|
93
|
+
totalQueries = 0;
|
|
94
|
+
totalHits = 0;
|
|
95
|
+
constructor(config = {}) {
|
|
96
|
+
this.config = {
|
|
97
|
+
enabled: config.enabled ?? true,
|
|
98
|
+
threshold: config.threshold ?? 0.95,
|
|
99
|
+
maxSize: config.maxSize ?? 1000,
|
|
100
|
+
ttl: config.ttl ?? 0, // No expiry by default
|
|
101
|
+
embedFunction: config.embedFunction ?? simpleEmbed,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get cached response for a query.
|
|
106
|
+
*/
|
|
107
|
+
async get(query, threshold) {
|
|
108
|
+
if (!this.config.enabled)
|
|
109
|
+
return null;
|
|
110
|
+
this.totalQueries++;
|
|
111
|
+
const effectiveThreshold = threshold ?? this.config.threshold;
|
|
112
|
+
const queryEmbedding = await this.config.embedFunction(query);
|
|
113
|
+
// Clean expired entries
|
|
114
|
+
this.cleanExpired();
|
|
115
|
+
let bestMatch = null;
|
|
116
|
+
let bestSimilarity = 0;
|
|
117
|
+
for (const entry of this.entries.values()) {
|
|
118
|
+
if (!entry.embedding)
|
|
119
|
+
continue;
|
|
120
|
+
const similarity = cosineSimilarity(queryEmbedding, entry.embedding);
|
|
121
|
+
if (similarity >= effectiveThreshold && similarity > bestSimilarity) {
|
|
122
|
+
bestSimilarity = similarity;
|
|
123
|
+
bestMatch = { entry, similarity };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (bestMatch) {
|
|
127
|
+
// Update hit count
|
|
128
|
+
bestMatch.entry.hitCount++;
|
|
129
|
+
this.totalHits++;
|
|
130
|
+
this.emit({ type: 'cache.hit', query, similarity: bestMatch.similarity, entryId: bestMatch.entry.id });
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
this.emit({ type: 'cache.miss', query });
|
|
134
|
+
}
|
|
135
|
+
return bestMatch;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Store a query/response pair.
|
|
139
|
+
*/
|
|
140
|
+
async set(query, response, metadata) {
|
|
141
|
+
if (!this.config.enabled)
|
|
142
|
+
return '';
|
|
143
|
+
// Enforce max size with LRU eviction
|
|
144
|
+
if (this.entries.size >= this.config.maxSize) {
|
|
145
|
+
this.evictLRU();
|
|
146
|
+
}
|
|
147
|
+
const embedding = await this.config.embedFunction(query);
|
|
148
|
+
const now = new Date();
|
|
149
|
+
const entry = {
|
|
150
|
+
id: generateId(),
|
|
151
|
+
query,
|
|
152
|
+
response,
|
|
153
|
+
embedding,
|
|
154
|
+
createdAt: now,
|
|
155
|
+
expiresAt: this.config.ttl ? new Date(now.getTime() + this.config.ttl) : undefined,
|
|
156
|
+
hitCount: 0,
|
|
157
|
+
metadata,
|
|
158
|
+
};
|
|
159
|
+
this.entries.set(entry.id, entry);
|
|
160
|
+
this.emit({ type: 'cache.set', query, entryId: entry.id });
|
|
161
|
+
return entry.id;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Check if a similar query exists (without incrementing hit count).
|
|
165
|
+
*/
|
|
166
|
+
async has(query, threshold) {
|
|
167
|
+
if (!this.config.enabled)
|
|
168
|
+
return false;
|
|
169
|
+
const effectiveThreshold = threshold ?? this.config.threshold;
|
|
170
|
+
const queryEmbedding = await this.config.embedFunction(query);
|
|
171
|
+
for (const entry of this.entries.values()) {
|
|
172
|
+
if (!entry.embedding)
|
|
173
|
+
continue;
|
|
174
|
+
const similarity = cosineSimilarity(queryEmbedding, entry.embedding);
|
|
175
|
+
if (similarity >= effectiveThreshold) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Delete an entry by ID.
|
|
183
|
+
*/
|
|
184
|
+
delete(id) {
|
|
185
|
+
return this.entries.delete(id);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Clear all entries.
|
|
189
|
+
*/
|
|
190
|
+
clear() {
|
|
191
|
+
this.entries.clear();
|
|
192
|
+
this.emit({ type: 'cache.cleared' });
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get cache statistics.
|
|
196
|
+
*/
|
|
197
|
+
getStats() {
|
|
198
|
+
let totalHitCount = 0;
|
|
199
|
+
for (const entry of this.entries.values()) {
|
|
200
|
+
totalHitCount += entry.hitCount;
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
size: this.entries.size,
|
|
204
|
+
totalHits: this.totalHits,
|
|
205
|
+
avgHits: this.entries.size > 0 ? totalHitCount / this.entries.size : 0,
|
|
206
|
+
hitRate: this.totalQueries > 0 ? this.totalHits / this.totalQueries : 0,
|
|
207
|
+
totalQueries: this.totalQueries,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Find similar entries (for debugging/inspection).
|
|
212
|
+
*/
|
|
213
|
+
async findSimilar(query, limit = 5) {
|
|
214
|
+
if (!this.config.enabled)
|
|
215
|
+
return [];
|
|
216
|
+
const queryEmbedding = await this.config.embedFunction(query);
|
|
217
|
+
const results = [];
|
|
218
|
+
for (const entry of this.entries.values()) {
|
|
219
|
+
if (!entry.embedding)
|
|
220
|
+
continue;
|
|
221
|
+
const similarity = cosineSimilarity(queryEmbedding, entry.embedding);
|
|
222
|
+
results.push({ entry, similarity });
|
|
223
|
+
}
|
|
224
|
+
return results.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Get all entries (for debugging).
|
|
228
|
+
*/
|
|
229
|
+
getAllEntries() {
|
|
230
|
+
return Array.from(this.entries.values());
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Update configuration.
|
|
234
|
+
*/
|
|
235
|
+
setConfig(updates) {
|
|
236
|
+
if (updates.enabled !== undefined)
|
|
237
|
+
this.config.enabled = updates.enabled;
|
|
238
|
+
if (updates.threshold !== undefined)
|
|
239
|
+
this.config.threshold = updates.threshold;
|
|
240
|
+
if (updates.maxSize !== undefined)
|
|
241
|
+
this.config.maxSize = updates.maxSize;
|
|
242
|
+
if (updates.ttl !== undefined)
|
|
243
|
+
this.config.ttl = updates.ttl;
|
|
244
|
+
if (updates.embedFunction)
|
|
245
|
+
this.config.embedFunction = updates.embedFunction;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get current configuration.
|
|
249
|
+
*/
|
|
250
|
+
getConfig() {
|
|
251
|
+
return {
|
|
252
|
+
enabled: this.config.enabled,
|
|
253
|
+
threshold: this.config.threshold,
|
|
254
|
+
maxSize: this.config.maxSize,
|
|
255
|
+
ttl: this.config.ttl,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Subscribe to cache events.
|
|
260
|
+
*/
|
|
261
|
+
subscribe(listener) {
|
|
262
|
+
this.eventListeners.add(listener);
|
|
263
|
+
return () => this.eventListeners.delete(listener);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Cleanup resources.
|
|
267
|
+
*/
|
|
268
|
+
cleanup() {
|
|
269
|
+
this.entries.clear();
|
|
270
|
+
this.eventListeners.clear();
|
|
271
|
+
this.totalQueries = 0;
|
|
272
|
+
this.totalHits = 0;
|
|
273
|
+
}
|
|
274
|
+
// Internal methods
|
|
275
|
+
/**
|
|
276
|
+
* Clean expired entries.
|
|
277
|
+
*/
|
|
278
|
+
cleanExpired() {
|
|
279
|
+
if (!this.config.ttl)
|
|
280
|
+
return;
|
|
281
|
+
const now = new Date();
|
|
282
|
+
for (const [id, entry] of this.entries) {
|
|
283
|
+
if (entry.expiresAt && entry.expiresAt < now) {
|
|
284
|
+
this.entries.delete(id);
|
|
285
|
+
this.emit({ type: 'cache.evict', entryId: id, reason: 'ttl' });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Evict least recently used entry.
|
|
291
|
+
*/
|
|
292
|
+
evictLRU() {
|
|
293
|
+
let oldest = null;
|
|
294
|
+
let oldestId = null;
|
|
295
|
+
for (const [id, entry] of this.entries) {
|
|
296
|
+
if (!oldest || entry.createdAt < oldest.createdAt) {
|
|
297
|
+
oldest = entry;
|
|
298
|
+
oldestId = id;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (oldestId) {
|
|
302
|
+
this.entries.delete(oldestId);
|
|
303
|
+
this.emit({ type: 'cache.evict', entryId: oldestId, reason: 'size' });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Emit a cache event.
|
|
308
|
+
*/
|
|
309
|
+
emit(event) {
|
|
310
|
+
for (const listener of this.eventListeners) {
|
|
311
|
+
try {
|
|
312
|
+
listener(event);
|
|
313
|
+
}
|
|
314
|
+
catch {
|
|
315
|
+
// Ignore listener errors
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// =============================================================================
|
|
321
|
+
// FACTORY FUNCTIONS
|
|
322
|
+
// =============================================================================
|
|
323
|
+
/**
|
|
324
|
+
* Create a semantic cache manager.
|
|
325
|
+
*/
|
|
326
|
+
export function createSemanticCacheManager(config) {
|
|
327
|
+
return new SemanticCacheManager(config);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Create a strict cache (higher similarity threshold).
|
|
331
|
+
*/
|
|
332
|
+
export function createStrictCache() {
|
|
333
|
+
return new SemanticCacheManager({
|
|
334
|
+
enabled: true,
|
|
335
|
+
threshold: 0.98,
|
|
336
|
+
maxSize: 500,
|
|
337
|
+
ttl: 3600000, // 1 hour
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Create a lenient cache (lower similarity threshold).
|
|
342
|
+
*/
|
|
343
|
+
export function createLenientCache() {
|
|
344
|
+
return new SemanticCacheManager({
|
|
345
|
+
enabled: true,
|
|
346
|
+
threshold: 0.85,
|
|
347
|
+
maxSize: 2000,
|
|
348
|
+
ttl: 0, // No expiry
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
// =============================================================================
|
|
352
|
+
// WRAPPER UTILITY
|
|
353
|
+
// =============================================================================
|
|
354
|
+
/**
|
|
355
|
+
* Create a cached wrapper around an LLM call function.
|
|
356
|
+
*/
|
|
357
|
+
export function withSemanticCache(fn, cache) {
|
|
358
|
+
return (async (...args) => {
|
|
359
|
+
const query = args.join('\n');
|
|
360
|
+
// Check cache
|
|
361
|
+
const hit = await cache.get(query);
|
|
362
|
+
if (hit) {
|
|
363
|
+
return hit.entry.response;
|
|
364
|
+
}
|
|
365
|
+
// Call function
|
|
366
|
+
const response = await fn(...args);
|
|
367
|
+
// Cache result
|
|
368
|
+
await cache.set(query, response);
|
|
369
|
+
return response;
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=semantic-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-cache.js","sourceRoot":"","sources":["../../../src/integrations/semantic-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAwEH,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF;;;GAGG;AACH,KAAK,UAAU,WAAW,CAAC,IAAY;IACrC,iBAAiB;IACjB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC9D,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,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9B,cAAc;QACd,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,GAAG,EAAE,CAAC;YACR,OAAO,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC5B,CAAC;QAED,gBAAgB;QAChB,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAEnC,eAAe;QACf,MAAM,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAM,CAAC;AACV,CAAC"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lesson 25: Session Persistence
|
|
3
|
+
*
|
|
4
|
+
* Saves and loads conversation sessions to/from disk.
|
|
5
|
+
* Uses JSONL format for append-only, crash-safe storage.
|
|
6
|
+
*/
|
|
7
|
+
import type { Message, ToolCall } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Session metadata stored in index.
|
|
10
|
+
*/
|
|
11
|
+
export interface SessionMetadata {
|
|
12
|
+
id: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
lastActiveAt: string;
|
|
16
|
+
messageCount: number;
|
|
17
|
+
tokenCount: number;
|
|
18
|
+
summary?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Entry types that can be stored in a session.
|
|
22
|
+
*/
|
|
23
|
+
export type SessionEntryType = 'message' | 'tool_call' | 'tool_result' | 'checkpoint' | 'compaction' | 'metadata';
|
|
24
|
+
/**
|
|
25
|
+
* A single entry in the session log.
|
|
26
|
+
*/
|
|
27
|
+
export interface SessionEntry {
|
|
28
|
+
timestamp: string;
|
|
29
|
+
type: SessionEntryType;
|
|
30
|
+
data: unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Session store configuration.
|
|
34
|
+
*/
|
|
35
|
+
export interface SessionStoreConfig {
|
|
36
|
+
/** Base directory for sessions (default: .agent/sessions) */
|
|
37
|
+
baseDir?: string;
|
|
38
|
+
/** Auto-save on each entry (default: true) */
|
|
39
|
+
autoSave?: boolean;
|
|
40
|
+
/** Max sessions to keep (default: 50) */
|
|
41
|
+
maxSessions?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Session store events.
|
|
45
|
+
*/
|
|
46
|
+
export type SessionEvent = {
|
|
47
|
+
type: 'session.created';
|
|
48
|
+
sessionId: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'session.loaded';
|
|
51
|
+
sessionId: string;
|
|
52
|
+
entryCount: number;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'session.saved';
|
|
55
|
+
sessionId: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'session.deleted';
|
|
58
|
+
sessionId: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'entry.appended';
|
|
61
|
+
sessionId: string;
|
|
62
|
+
entryType: SessionEntryType;
|
|
63
|
+
};
|
|
64
|
+
export type SessionEventListener = (event: SessionEvent) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Manages session persistence.
|
|
67
|
+
*/
|
|
68
|
+
export declare class SessionStore {
|
|
69
|
+
private config;
|
|
70
|
+
private currentSessionId;
|
|
71
|
+
private index;
|
|
72
|
+
private listeners;
|
|
73
|
+
private writeQueue;
|
|
74
|
+
constructor(config?: SessionStoreConfig);
|
|
75
|
+
/**
|
|
76
|
+
* Initialize the session store.
|
|
77
|
+
*/
|
|
78
|
+
initialize(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Load the session index.
|
|
81
|
+
*/
|
|
82
|
+
private loadIndex;
|
|
83
|
+
/**
|
|
84
|
+
* Save the session index.
|
|
85
|
+
*/
|
|
86
|
+
private saveIndex;
|
|
87
|
+
/**
|
|
88
|
+
* Create a new session.
|
|
89
|
+
*/
|
|
90
|
+
createSession(name?: string): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Get the current session ID.
|
|
93
|
+
*/
|
|
94
|
+
getCurrentSessionId(): string | null;
|
|
95
|
+
/**
|
|
96
|
+
* Set the current session ID.
|
|
97
|
+
*/
|
|
98
|
+
setCurrentSessionId(sessionId: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Append an entry to the current session.
|
|
101
|
+
*/
|
|
102
|
+
appendEntry(entry: Omit<SessionEntry, 'timestamp'>): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Append a message to the current session.
|
|
105
|
+
*/
|
|
106
|
+
appendMessage(message: Message): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Append a tool call to the current session.
|
|
109
|
+
*/
|
|
110
|
+
appendToolCall(toolCall: ToolCall): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Append a tool result to the current session.
|
|
113
|
+
*/
|
|
114
|
+
appendToolResult(callId: string, result: unknown): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Append a compaction summary.
|
|
117
|
+
*/
|
|
118
|
+
appendCompaction(summary: string, compactedCount: number): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Append a checkpoint for session restoration.
|
|
121
|
+
* Checkpoints store the full conversation state at a point in time.
|
|
122
|
+
*/
|
|
123
|
+
appendCheckpoint(checkpoint: {
|
|
124
|
+
id: string;
|
|
125
|
+
label?: string;
|
|
126
|
+
messages: Message[];
|
|
127
|
+
iteration: number;
|
|
128
|
+
metrics?: unknown;
|
|
129
|
+
}): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Load a session by ID.
|
|
132
|
+
*/
|
|
133
|
+
loadSession(sessionId: string): Promise<SessionEntry[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Reconstruct messages from session entries.
|
|
136
|
+
*/
|
|
137
|
+
loadSessionMessages(sessionId: string): Promise<Message[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Delete a session.
|
|
140
|
+
*/
|
|
141
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* List all sessions.
|
|
144
|
+
*/
|
|
145
|
+
listSessions(): SessionMetadata[];
|
|
146
|
+
/**
|
|
147
|
+
* Get the most recent session.
|
|
148
|
+
*/
|
|
149
|
+
getRecentSession(): SessionMetadata | null;
|
|
150
|
+
/**
|
|
151
|
+
* Get session metadata by ID.
|
|
152
|
+
*/
|
|
153
|
+
getSessionMetadata(sessionId: string): SessionMetadata | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Update session metadata.
|
|
156
|
+
*/
|
|
157
|
+
updateSessionMetadata(sessionId: string, updates: Partial<Pick<SessionMetadata, 'name' | 'summary' | 'tokenCount'>>): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Prune old sessions if over limit.
|
|
160
|
+
*/
|
|
161
|
+
private pruneOldSessions;
|
|
162
|
+
/**
|
|
163
|
+
* Subscribe to events.
|
|
164
|
+
*/
|
|
165
|
+
on(listener: SessionEventListener): () => void;
|
|
166
|
+
/**
|
|
167
|
+
* Emit an event.
|
|
168
|
+
*/
|
|
169
|
+
private emit;
|
|
170
|
+
/**
|
|
171
|
+
* Cleanup - save index on exit.
|
|
172
|
+
*/
|
|
173
|
+
cleanup(): Promise<void>;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Create and initialize a session store.
|
|
177
|
+
*/
|
|
178
|
+
export declare function createSessionStore(config?: SessionStoreConfig): Promise<SessionStore>;
|
|
179
|
+
/**
|
|
180
|
+
* Format session metadata for display.
|
|
181
|
+
*/
|
|
182
|
+
export declare function formatSessionList(sessions: SessionMetadata[]): string;
|
|
183
|
+
//# sourceMappingURL=session-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../../src/integrations/session-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,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