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,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Change Tracker
|
|
3
|
+
*
|
|
4
|
+
* Tracks file changes for undo capability in agent sessions.
|
|
5
|
+
* Provides before/after content capture, diff generation, and undo functionality.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import Database from 'better-sqlite3';
|
|
10
|
+
* import { FileChangeTracker } from './file-change-tracker.js';
|
|
11
|
+
*
|
|
12
|
+
* const db = new Database('sessions.db');
|
|
13
|
+
* const tracker = new FileChangeTracker(db, 'session-123');
|
|
14
|
+
*
|
|
15
|
+
* // Record a file change
|
|
16
|
+
* const changeId = await tracker.recordChange({
|
|
17
|
+
* filePath: '/path/to/file.ts',
|
|
18
|
+
* operation: 'edit',
|
|
19
|
+
* contentBefore: 'old content',
|
|
20
|
+
* contentAfter: 'new content',
|
|
21
|
+
* turnNumber: 1,
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Undo the change
|
|
25
|
+
* const result = await tracker.undoChange(changeId);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import Database from 'better-sqlite3';
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for FileChangeTracker.
|
|
31
|
+
*/
|
|
32
|
+
export interface FileChangeTrackerConfig {
|
|
33
|
+
/** Whether tracking is enabled (default: true) */
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
/** Maximum bytes for full content storage (default: 50KB). Above this, store diff only. */
|
|
36
|
+
maxFullContentBytes?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Represents a file change record.
|
|
40
|
+
*/
|
|
41
|
+
export interface FileChange {
|
|
42
|
+
/** Unique change ID */
|
|
43
|
+
id: number;
|
|
44
|
+
/** Session this change belongs to */
|
|
45
|
+
sessionId: string;
|
|
46
|
+
/** Turn number when change occurred */
|
|
47
|
+
turnNumber: number;
|
|
48
|
+
/** Path to the changed file */
|
|
49
|
+
filePath: string;
|
|
50
|
+
/** Type of operation */
|
|
51
|
+
operation: 'create' | 'write' | 'edit' | 'delete';
|
|
52
|
+
/** Content before the change (null for creates) */
|
|
53
|
+
contentBefore: string | null;
|
|
54
|
+
/** Content after the change (null for deletes) */
|
|
55
|
+
contentAfter: string | null;
|
|
56
|
+
/** Unified diff (when using diff storage mode) */
|
|
57
|
+
diffUnified: string | null;
|
|
58
|
+
/** How content is stored */
|
|
59
|
+
storageMode: 'full' | 'diff';
|
|
60
|
+
/** Bytes before change */
|
|
61
|
+
bytesBefore: number;
|
|
62
|
+
/** Bytes after change */
|
|
63
|
+
bytesAfter: number;
|
|
64
|
+
/** Whether this change has been undone */
|
|
65
|
+
isUndone: boolean;
|
|
66
|
+
/** ID of the change that undid this one */
|
|
67
|
+
undoChangeId: number | null;
|
|
68
|
+
/** Tool call ID that made this change */
|
|
69
|
+
toolCallId: string | null;
|
|
70
|
+
/** ISO timestamp of when change was recorded */
|
|
71
|
+
createdAt: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Result of an undo operation.
|
|
75
|
+
*/
|
|
76
|
+
export interface UndoResult {
|
|
77
|
+
/** Whether the undo succeeded */
|
|
78
|
+
success: boolean;
|
|
79
|
+
/** Path to the affected file */
|
|
80
|
+
filePath: string;
|
|
81
|
+
/** Human-readable message */
|
|
82
|
+
message: string;
|
|
83
|
+
/** Change ID that was undone (if successful) */
|
|
84
|
+
changeId?: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Summary of changes in a session.
|
|
88
|
+
*/
|
|
89
|
+
export interface ChangeSummary {
|
|
90
|
+
/** Total number of changes */
|
|
91
|
+
totalChanges: number;
|
|
92
|
+
/** Number of active (non-undone) changes */
|
|
93
|
+
activeChanges: number;
|
|
94
|
+
/** Number of undone changes */
|
|
95
|
+
undoneChanges: number;
|
|
96
|
+
/** Files that were modified */
|
|
97
|
+
filesModified: string[];
|
|
98
|
+
/** Changes by operation type */
|
|
99
|
+
byOperation: {
|
|
100
|
+
create: number;
|
|
101
|
+
write: number;
|
|
102
|
+
edit: number;
|
|
103
|
+
delete: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Tracks file changes for undo capability.
|
|
108
|
+
*/
|
|
109
|
+
export declare class FileChangeTracker {
|
|
110
|
+
private db;
|
|
111
|
+
private sessionId;
|
|
112
|
+
private config;
|
|
113
|
+
private stmts;
|
|
114
|
+
constructor(db: Database.Database, sessionId: string, config?: FileChangeTrackerConfig);
|
|
115
|
+
/**
|
|
116
|
+
* Prepare SQL statements for reuse.
|
|
117
|
+
*/
|
|
118
|
+
private prepareStatements;
|
|
119
|
+
/**
|
|
120
|
+
* Record a file change.
|
|
121
|
+
*/
|
|
122
|
+
recordChange(params: {
|
|
123
|
+
filePath: string;
|
|
124
|
+
operation: 'create' | 'write' | 'edit' | 'delete';
|
|
125
|
+
contentBefore?: string;
|
|
126
|
+
contentAfter?: string;
|
|
127
|
+
turnNumber: number;
|
|
128
|
+
toolCallId?: string;
|
|
129
|
+
}): Promise<number>;
|
|
130
|
+
/**
|
|
131
|
+
* Undo a specific change by ID.
|
|
132
|
+
*/
|
|
133
|
+
undoChange(changeId: number): Promise<UndoResult>;
|
|
134
|
+
/**
|
|
135
|
+
* Undo the last change to a specific file.
|
|
136
|
+
*/
|
|
137
|
+
undoLastChange(filePath: string): Promise<UndoResult>;
|
|
138
|
+
/**
|
|
139
|
+
* Undo all changes in a turn.
|
|
140
|
+
*/
|
|
141
|
+
undoTurn(turnNumber: number): Promise<UndoResult[]>;
|
|
142
|
+
/**
|
|
143
|
+
* Get all changes for a file.
|
|
144
|
+
*/
|
|
145
|
+
getFileHistory(filePath: string): FileChange[];
|
|
146
|
+
/**
|
|
147
|
+
* Get all changes in session.
|
|
148
|
+
*/
|
|
149
|
+
getChanges(options?: {
|
|
150
|
+
filePath?: string;
|
|
151
|
+
}): FileChange[];
|
|
152
|
+
/**
|
|
153
|
+
* Get session change summary.
|
|
154
|
+
*/
|
|
155
|
+
getSessionChangeSummary(): ChangeSummary;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a FileChangeTracker instance.
|
|
159
|
+
*/
|
|
160
|
+
export declare function createFileChangeTracker(db: Database.Database, sessionId: string, config?: FileChangeTrackerConfig): FileChangeTracker;
|
|
161
|
+
//# sourceMappingURL=file-change-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-change-tracker.d.ts","sourceRoot":"","sources":["../../../src/integrations/file-change-tracker.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Change Tracker
|
|
3
|
+
*
|
|
4
|
+
* Tracks file changes for undo capability in agent sessions.
|
|
5
|
+
* Provides before/after content capture, diff generation, and undo functionality.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import Database from 'better-sqlite3';
|
|
10
|
+
* import { FileChangeTracker } from './file-change-tracker.js';
|
|
11
|
+
*
|
|
12
|
+
* const db = new Database('sessions.db');
|
|
13
|
+
* const tracker = new FileChangeTracker(db, 'session-123');
|
|
14
|
+
*
|
|
15
|
+
* // Record a file change
|
|
16
|
+
* const changeId = await tracker.recordChange({
|
|
17
|
+
* filePath: '/path/to/file.ts',
|
|
18
|
+
* operation: 'edit',
|
|
19
|
+
* contentBefore: 'old content',
|
|
20
|
+
* contentAfter: 'new content',
|
|
21
|
+
* turnNumber: 1,
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Undo the change
|
|
25
|
+
* const result = await tracker.undoChange(changeId);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { writeFile, unlink } from 'node:fs/promises';
|
|
29
|
+
import { existsSync } from 'node:fs';
|
|
30
|
+
// =============================================================================
|
|
31
|
+
// DIFF UTILITIES
|
|
32
|
+
// =============================================================================
|
|
33
|
+
/**
|
|
34
|
+
* Generate a simple unified diff between two strings.
|
|
35
|
+
* This is a basic implementation - for production, consider using a proper diff library.
|
|
36
|
+
*/
|
|
37
|
+
function generateUnifiedDiff(before, after, filePath) {
|
|
38
|
+
const beforeLines = before.split('\n');
|
|
39
|
+
const afterLines = after.split('\n');
|
|
40
|
+
const header = [
|
|
41
|
+
`--- a/${filePath}`,
|
|
42
|
+
`+++ b/${filePath}`,
|
|
43
|
+
];
|
|
44
|
+
// Simple line-by-line diff (not optimal but functional)
|
|
45
|
+
const hunks = [];
|
|
46
|
+
let i = 0;
|
|
47
|
+
let j = 0;
|
|
48
|
+
while (i < beforeLines.length || j < afterLines.length) {
|
|
49
|
+
// Find next difference
|
|
50
|
+
const startI = i;
|
|
51
|
+
const startJ = j;
|
|
52
|
+
// Skip matching lines
|
|
53
|
+
while (i < beforeLines.length && j < afterLines.length && beforeLines[i] === afterLines[j]) {
|
|
54
|
+
i++;
|
|
55
|
+
j++;
|
|
56
|
+
}
|
|
57
|
+
// If we've found a difference or reached the end
|
|
58
|
+
if (i < beforeLines.length || j < afterLines.length) {
|
|
59
|
+
// Determine the hunk boundaries
|
|
60
|
+
const contextBefore = Math.max(0, i - 3);
|
|
61
|
+
const hunkStart = contextBefore + 1;
|
|
62
|
+
// Find the extent of the difference
|
|
63
|
+
const diffStartI = i;
|
|
64
|
+
const diffStartJ = j;
|
|
65
|
+
// Advance through differing lines
|
|
66
|
+
while (i < beforeLines.length || j < afterLines.length) {
|
|
67
|
+
if (i < beforeLines.length && j < afterLines.length && beforeLines[i] === afterLines[j]) {
|
|
68
|
+
// Found a match - check if it's the end of the diff section
|
|
69
|
+
let matchCount = 0;
|
|
70
|
+
let tempI = i;
|
|
71
|
+
let tempJ = j;
|
|
72
|
+
while (tempI < beforeLines.length && tempJ < afterLines.length &&
|
|
73
|
+
beforeLines[tempI] === afterLines[tempJ] && matchCount < 3) {
|
|
74
|
+
matchCount++;
|
|
75
|
+
tempI++;
|
|
76
|
+
tempJ++;
|
|
77
|
+
}
|
|
78
|
+
if (matchCount >= 3) {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (i < beforeLines.length)
|
|
83
|
+
i++;
|
|
84
|
+
if (j < afterLines.length)
|
|
85
|
+
j++;
|
|
86
|
+
}
|
|
87
|
+
// Build the hunk
|
|
88
|
+
const hunkLines = [];
|
|
89
|
+
const beforeCount = i - contextBefore;
|
|
90
|
+
const afterCount = j - (startJ + (contextBefore - startI));
|
|
91
|
+
hunkLines.push(`@@ -${hunkStart},${beforeCount} +${hunkStart},${afterCount} @@`);
|
|
92
|
+
// Add context before
|
|
93
|
+
for (let k = contextBefore; k < diffStartI; k++) {
|
|
94
|
+
hunkLines.push(` ${beforeLines[k]}`);
|
|
95
|
+
}
|
|
96
|
+
// Add removed lines
|
|
97
|
+
for (let k = diffStartI; k < i; k++) {
|
|
98
|
+
if (k < beforeLines.length) {
|
|
99
|
+
hunkLines.push(`-${beforeLines[k]}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Add added lines
|
|
103
|
+
for (let k = diffStartJ; k < j; k++) {
|
|
104
|
+
if (k < afterLines.length) {
|
|
105
|
+
hunkLines.push(`+${afterLines[k]}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
hunks.push(hunkLines.join('\n'));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return [...header, ...hunks].join('\n');
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Apply a unified diff to restore original content.
|
|
115
|
+
* Returns the original content before the diff was applied.
|
|
116
|
+
*/
|
|
117
|
+
function applyReverseDiff(currentContent, diff) {
|
|
118
|
+
// Parse diff hunks
|
|
119
|
+
const lines = diff.split('\n');
|
|
120
|
+
const resultLines = currentContent.split('\n');
|
|
121
|
+
let lineIndex = 0;
|
|
122
|
+
let i = 0;
|
|
123
|
+
// Skip header lines
|
|
124
|
+
while (i < lines.length && !lines[i].startsWith('@@')) {
|
|
125
|
+
i++;
|
|
126
|
+
}
|
|
127
|
+
while (i < lines.length) {
|
|
128
|
+
const line = lines[i];
|
|
129
|
+
if (line.startsWith('@@')) {
|
|
130
|
+
// Parse hunk header: @@ -start,count +start,count @@
|
|
131
|
+
const match = line.match(/@@ -(\d+),?\d* \+(\d+),?\d* @@/);
|
|
132
|
+
if (match) {
|
|
133
|
+
lineIndex = parseInt(match[2], 10) - 1;
|
|
134
|
+
}
|
|
135
|
+
i++;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (line.startsWith('+')) {
|
|
139
|
+
// This was an addition - remove it to reverse
|
|
140
|
+
if (lineIndex < resultLines.length && resultLines[lineIndex] === line.slice(1)) {
|
|
141
|
+
resultLines.splice(lineIndex, 1);
|
|
142
|
+
}
|
|
143
|
+
i++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (line.startsWith('-')) {
|
|
147
|
+
// This was a removal - add it back to reverse
|
|
148
|
+
resultLines.splice(lineIndex, 0, line.slice(1));
|
|
149
|
+
lineIndex++;
|
|
150
|
+
i++;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (line.startsWith(' ')) {
|
|
154
|
+
// Context line
|
|
155
|
+
lineIndex++;
|
|
156
|
+
i++;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
i++;
|
|
160
|
+
}
|
|
161
|
+
return resultLines.join('\n');
|
|
162
|
+
}
|
|
163
|
+
// =============================================================================
|
|
164
|
+
// FILE CHANGE TRACKER
|
|
165
|
+
// =============================================================================
|
|
166
|
+
/**
|
|
167
|
+
* Tracks file changes for undo capability.
|
|
168
|
+
*/
|
|
169
|
+
export class FileChangeTracker {
|
|
170
|
+
db;
|
|
171
|
+
sessionId;
|
|
172
|
+
config;
|
|
173
|
+
stmts;
|
|
174
|
+
constructor(db, sessionId, config) {
|
|
175
|
+
this.db = db;
|
|
176
|
+
this.sessionId = sessionId;
|
|
177
|
+
this.config = {
|
|
178
|
+
enabled: config?.enabled ?? true,
|
|
179
|
+
maxFullContentBytes: config?.maxFullContentBytes ?? 50 * 1024, // 50KB
|
|
180
|
+
};
|
|
181
|
+
this.prepareStatements();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Prepare SQL statements for reuse.
|
|
185
|
+
*/
|
|
186
|
+
prepareStatements() {
|
|
187
|
+
this.stmts = {
|
|
188
|
+
insertChange: this.db.prepare(`
|
|
189
|
+
INSERT INTO file_changes (
|
|
190
|
+
session_id, entry_id, tool_call_id, turn_number, file_path,
|
|
191
|
+
operation, content_before, content_after, diff_unified,
|
|
192
|
+
storage_mode, bytes_before, bytes_after, is_undone,
|
|
193
|
+
undo_change_id, created_at
|
|
194
|
+
)
|
|
195
|
+
VALUES (
|
|
196
|
+
@sessionId, @entryId, @toolCallId, @turnNumber, @filePath,
|
|
197
|
+
@operation, @contentBefore, @contentAfter, @diffUnified,
|
|
198
|
+
@storageMode, @bytesBefore, @bytesAfter, @isUndone,
|
|
199
|
+
@undoChangeId, @createdAt
|
|
200
|
+
)
|
|
201
|
+
`),
|
|
202
|
+
getChange: this.db.prepare(`
|
|
203
|
+
SELECT
|
|
204
|
+
id, session_id as sessionId, turn_number as turnNumber,
|
|
205
|
+
file_path as filePath, operation, content_before as contentBefore,
|
|
206
|
+
content_after as contentAfter, diff_unified as diffUnified,
|
|
207
|
+
storage_mode as storageMode, bytes_before as bytesBefore,
|
|
208
|
+
bytes_after as bytesAfter, is_undone as isUndone,
|
|
209
|
+
undo_change_id as undoChangeId, tool_call_id as toolCallId,
|
|
210
|
+
created_at as createdAt
|
|
211
|
+
FROM file_changes
|
|
212
|
+
WHERE id = ? AND session_id = ?
|
|
213
|
+
`),
|
|
214
|
+
getChanges: this.db.prepare(`
|
|
215
|
+
SELECT
|
|
216
|
+
id, session_id as sessionId, turn_number as turnNumber,
|
|
217
|
+
file_path as filePath, operation, content_before as contentBefore,
|
|
218
|
+
content_after as contentAfter, diff_unified as diffUnified,
|
|
219
|
+
storage_mode as storageMode, bytes_before as bytesBefore,
|
|
220
|
+
bytes_after as bytesAfter, is_undone as isUndone,
|
|
221
|
+
undo_change_id as undoChangeId, tool_call_id as toolCallId,
|
|
222
|
+
created_at as createdAt
|
|
223
|
+
FROM file_changes
|
|
224
|
+
WHERE session_id = ?
|
|
225
|
+
ORDER BY id ASC
|
|
226
|
+
`),
|
|
227
|
+
getFileChanges: this.db.prepare(`
|
|
228
|
+
SELECT
|
|
229
|
+
id, session_id as sessionId, turn_number as turnNumber,
|
|
230
|
+
file_path as filePath, operation, content_before as contentBefore,
|
|
231
|
+
content_after as contentAfter, diff_unified as diffUnified,
|
|
232
|
+
storage_mode as storageMode, bytes_before as bytesBefore,
|
|
233
|
+
bytes_after as bytesAfter, is_undone as isUndone,
|
|
234
|
+
undo_change_id as undoChangeId, tool_call_id as toolCallId,
|
|
235
|
+
created_at as createdAt
|
|
236
|
+
FROM file_changes
|
|
237
|
+
WHERE session_id = ? AND file_path = ?
|
|
238
|
+
ORDER BY id ASC
|
|
239
|
+
`),
|
|
240
|
+
getLastFileChange: this.db.prepare(`
|
|
241
|
+
SELECT
|
|
242
|
+
id, session_id as sessionId, turn_number as turnNumber,
|
|
243
|
+
file_path as filePath, operation, content_before as contentBefore,
|
|
244
|
+
content_after as contentAfter, diff_unified as diffUnified,
|
|
245
|
+
storage_mode as storageMode, bytes_before as bytesBefore,
|
|
246
|
+
bytes_after as bytesAfter, is_undone as isUndone,
|
|
247
|
+
undo_change_id as undoChangeId, tool_call_id as toolCallId,
|
|
248
|
+
created_at as createdAt
|
|
249
|
+
FROM file_changes
|
|
250
|
+
WHERE session_id = ? AND file_path = ? AND is_undone = 0
|
|
251
|
+
ORDER BY id DESC
|
|
252
|
+
LIMIT 1
|
|
253
|
+
`),
|
|
254
|
+
getTurnChanges: this.db.prepare(`
|
|
255
|
+
SELECT
|
|
256
|
+
id, session_id as sessionId, turn_number as turnNumber,
|
|
257
|
+
file_path as filePath, operation, content_before as contentBefore,
|
|
258
|
+
content_after as contentAfter, diff_unified as diffUnified,
|
|
259
|
+
storage_mode as storageMode, bytes_before as bytesBefore,
|
|
260
|
+
bytes_after as bytesAfter, is_undone as isUndone,
|
|
261
|
+
undo_change_id as undoChangeId, tool_call_id as toolCallId,
|
|
262
|
+
created_at as createdAt
|
|
263
|
+
FROM file_changes
|
|
264
|
+
WHERE session_id = ? AND turn_number = ? AND is_undone = 0
|
|
265
|
+
ORDER BY id DESC
|
|
266
|
+
`),
|
|
267
|
+
markUndone: this.db.prepare(`
|
|
268
|
+
UPDATE file_changes
|
|
269
|
+
SET is_undone = 1, undo_change_id = ?
|
|
270
|
+
WHERE id = ? AND session_id = ?
|
|
271
|
+
`),
|
|
272
|
+
getSessionSummary: this.db.prepare(`
|
|
273
|
+
SELECT
|
|
274
|
+
COUNT(*) as totalChanges,
|
|
275
|
+
SUM(CASE WHEN is_undone = 0 THEN 1 ELSE 0 END) as activeChanges,
|
|
276
|
+
SUM(CASE WHEN is_undone = 1 THEN 1 ELSE 0 END) as undoneChanges,
|
|
277
|
+
SUM(CASE WHEN operation = 'create' AND is_undone = 0 THEN 1 ELSE 0 END) as createCount,
|
|
278
|
+
SUM(CASE WHEN operation = 'write' AND is_undone = 0 THEN 1 ELSE 0 END) as writeCount,
|
|
279
|
+
SUM(CASE WHEN operation = 'edit' AND is_undone = 0 THEN 1 ELSE 0 END) as editCount,
|
|
280
|
+
SUM(CASE WHEN operation = 'delete' AND is_undone = 0 THEN 1 ELSE 0 END) as deleteCount
|
|
281
|
+
FROM file_changes
|
|
282
|
+
WHERE session_id = ?
|
|
283
|
+
`),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Record a file change.
|
|
288
|
+
*/
|
|
289
|
+
async recordChange(params) {
|
|
290
|
+
if (!this.config.enabled) {
|
|
291
|
+
return -1;
|
|
292
|
+
}
|
|
293
|
+
const now = new Date().toISOString();
|
|
294
|
+
const contentBefore = params.contentBefore ?? null;
|
|
295
|
+
const contentAfter = params.contentAfter ?? null;
|
|
296
|
+
const bytesBefore = contentBefore ? Buffer.byteLength(contentBefore, 'utf-8') : 0;
|
|
297
|
+
const bytesAfter = contentAfter ? Buffer.byteLength(contentAfter, 'utf-8') : 0;
|
|
298
|
+
// Determine storage mode
|
|
299
|
+
let storageMode = 'full';
|
|
300
|
+
let diffUnified = null;
|
|
301
|
+
let storedBefore = contentBefore;
|
|
302
|
+
let storedAfter = contentAfter;
|
|
303
|
+
// Use diff mode for large files
|
|
304
|
+
const totalBytes = bytesBefore + bytesAfter;
|
|
305
|
+
if (totalBytes > this.config.maxFullContentBytes && contentBefore && contentAfter) {
|
|
306
|
+
storageMode = 'diff';
|
|
307
|
+
diffUnified = generateUnifiedDiff(contentBefore, contentAfter, params.filePath);
|
|
308
|
+
// In diff mode, we only store the after content (current state) and the diff
|
|
309
|
+
// to reconstruct the before content
|
|
310
|
+
storedBefore = null;
|
|
311
|
+
storedAfter = contentAfter;
|
|
312
|
+
}
|
|
313
|
+
const result = this.stmts.insertChange.run({
|
|
314
|
+
sessionId: this.sessionId,
|
|
315
|
+
entryId: null,
|
|
316
|
+
toolCallId: params.toolCallId ?? null,
|
|
317
|
+
turnNumber: params.turnNumber,
|
|
318
|
+
filePath: params.filePath,
|
|
319
|
+
operation: params.operation,
|
|
320
|
+
contentBefore: storedBefore,
|
|
321
|
+
contentAfter: storedAfter,
|
|
322
|
+
diffUnified,
|
|
323
|
+
storageMode,
|
|
324
|
+
bytesBefore,
|
|
325
|
+
bytesAfter,
|
|
326
|
+
isUndone: 0,
|
|
327
|
+
undoChangeId: null,
|
|
328
|
+
createdAt: now,
|
|
329
|
+
});
|
|
330
|
+
return result.lastInsertRowid;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Undo a specific change by ID.
|
|
334
|
+
*/
|
|
335
|
+
async undoChange(changeId) {
|
|
336
|
+
const row = this.stmts.getChange.get(changeId, this.sessionId);
|
|
337
|
+
if (!row) {
|
|
338
|
+
return {
|
|
339
|
+
success: false,
|
|
340
|
+
filePath: '',
|
|
341
|
+
message: `Change ${changeId} not found`,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
if (row.isUndone) {
|
|
345
|
+
return {
|
|
346
|
+
success: false,
|
|
347
|
+
filePath: row.filePath,
|
|
348
|
+
message: `Change ${changeId} has already been undone`,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
const filePath = row.filePath;
|
|
352
|
+
try {
|
|
353
|
+
// Determine what content to restore
|
|
354
|
+
let contentToRestore = null;
|
|
355
|
+
if (row.storageMode === 'full') {
|
|
356
|
+
contentToRestore = row.contentBefore;
|
|
357
|
+
}
|
|
358
|
+
else if (row.storageMode === 'diff' && row.diffUnified && row.contentAfter) {
|
|
359
|
+
// Reconstruct the before content from the diff
|
|
360
|
+
contentToRestore = applyReverseDiff(row.contentAfter, row.diffUnified);
|
|
361
|
+
}
|
|
362
|
+
// Perform the undo based on operation type
|
|
363
|
+
switch (row.operation) {
|
|
364
|
+
case 'create':
|
|
365
|
+
// Undo create = delete the file
|
|
366
|
+
if (existsSync(filePath)) {
|
|
367
|
+
await unlink(filePath);
|
|
368
|
+
}
|
|
369
|
+
break;
|
|
370
|
+
case 'write':
|
|
371
|
+
case 'edit':
|
|
372
|
+
// Undo write/edit = restore previous content
|
|
373
|
+
if (contentToRestore !== null) {
|
|
374
|
+
await writeFile(filePath, contentToRestore, 'utf-8');
|
|
375
|
+
}
|
|
376
|
+
else if (row.operation === 'write') {
|
|
377
|
+
// If no previous content for a write, delete the file
|
|
378
|
+
if (existsSync(filePath)) {
|
|
379
|
+
await unlink(filePath);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
break;
|
|
383
|
+
case 'delete':
|
|
384
|
+
// Undo delete = recreate the file with original content
|
|
385
|
+
if (contentToRestore !== null) {
|
|
386
|
+
await writeFile(filePath, contentToRestore, 'utf-8');
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
// Mark as undone (no undo change id since this isn't creating a new change record)
|
|
391
|
+
this.stmts.markUndone.run(null, changeId, this.sessionId);
|
|
392
|
+
return {
|
|
393
|
+
success: true,
|
|
394
|
+
filePath,
|
|
395
|
+
message: `Successfully undid ${row.operation} on ${filePath}`,
|
|
396
|
+
changeId,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
return {
|
|
401
|
+
success: false,
|
|
402
|
+
filePath,
|
|
403
|
+
message: `Failed to undo change: ${error instanceof Error ? error.message : String(error)}`,
|
|
404
|
+
changeId,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Undo the last change to a specific file.
|
|
410
|
+
*/
|
|
411
|
+
async undoLastChange(filePath) {
|
|
412
|
+
const row = this.stmts.getLastFileChange.get(this.sessionId, filePath);
|
|
413
|
+
if (!row) {
|
|
414
|
+
return {
|
|
415
|
+
success: false,
|
|
416
|
+
filePath,
|
|
417
|
+
message: `No undoable changes found for ${filePath}`,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
return this.undoChange(row.id);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Undo all changes in a turn.
|
|
424
|
+
*/
|
|
425
|
+
async undoTurn(turnNumber) {
|
|
426
|
+
const rows = this.stmts.getTurnChanges.all(this.sessionId, turnNumber);
|
|
427
|
+
const results = [];
|
|
428
|
+
// Undo in reverse order (last change first)
|
|
429
|
+
for (const row of rows) {
|
|
430
|
+
const result = await this.undoChange(row.id);
|
|
431
|
+
results.push(result);
|
|
432
|
+
}
|
|
433
|
+
return results;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Get all changes for a file.
|
|
437
|
+
*/
|
|
438
|
+
getFileHistory(filePath) {
|
|
439
|
+
const rows = this.stmts.getFileChanges.all(this.sessionId, filePath);
|
|
440
|
+
return rows.map(row => ({
|
|
441
|
+
id: row.id,
|
|
442
|
+
sessionId: row.sessionId,
|
|
443
|
+
turnNumber: row.turnNumber,
|
|
444
|
+
filePath: row.filePath,
|
|
445
|
+
operation: row.operation,
|
|
446
|
+
contentBefore: row.contentBefore,
|
|
447
|
+
contentAfter: row.contentAfter,
|
|
448
|
+
diffUnified: row.diffUnified,
|
|
449
|
+
storageMode: row.storageMode,
|
|
450
|
+
bytesBefore: row.bytesBefore,
|
|
451
|
+
bytesAfter: row.bytesAfter,
|
|
452
|
+
isUndone: row.isUndone === 1,
|
|
453
|
+
undoChangeId: row.undoChangeId,
|
|
454
|
+
toolCallId: row.toolCallId,
|
|
455
|
+
createdAt: row.createdAt,
|
|
456
|
+
}));
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get all changes in session.
|
|
460
|
+
*/
|
|
461
|
+
getChanges(options) {
|
|
462
|
+
if (options?.filePath) {
|
|
463
|
+
return this.getFileHistory(options.filePath);
|
|
464
|
+
}
|
|
465
|
+
const rows = this.stmts.getChanges.all(this.sessionId);
|
|
466
|
+
return rows.map(row => ({
|
|
467
|
+
id: row.id,
|
|
468
|
+
sessionId: row.sessionId,
|
|
469
|
+
turnNumber: row.turnNumber,
|
|
470
|
+
filePath: row.filePath,
|
|
471
|
+
operation: row.operation,
|
|
472
|
+
contentBefore: row.contentBefore,
|
|
473
|
+
contentAfter: row.contentAfter,
|
|
474
|
+
diffUnified: row.diffUnified,
|
|
475
|
+
storageMode: row.storageMode,
|
|
476
|
+
bytesBefore: row.bytesBefore,
|
|
477
|
+
bytesAfter: row.bytesAfter,
|
|
478
|
+
isUndone: row.isUndone === 1,
|
|
479
|
+
undoChangeId: row.undoChangeId,
|
|
480
|
+
toolCallId: row.toolCallId,
|
|
481
|
+
createdAt: row.createdAt,
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Get session change summary.
|
|
486
|
+
*/
|
|
487
|
+
getSessionChangeSummary() {
|
|
488
|
+
const row = this.stmts.getSessionSummary.get(this.sessionId);
|
|
489
|
+
// Get unique file paths from active changes
|
|
490
|
+
const changes = this.getChanges();
|
|
491
|
+
const activeFiles = new Set();
|
|
492
|
+
for (const change of changes) {
|
|
493
|
+
if (!change.isUndone) {
|
|
494
|
+
activeFiles.add(change.filePath);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
totalChanges: row.totalChanges || 0,
|
|
499
|
+
activeChanges: row.activeChanges || 0,
|
|
500
|
+
undoneChanges: row.undoneChanges || 0,
|
|
501
|
+
filesModified: Array.from(activeFiles),
|
|
502
|
+
byOperation: {
|
|
503
|
+
create: row.createCount || 0,
|
|
504
|
+
write: row.writeCount || 0,
|
|
505
|
+
edit: row.editCount || 0,
|
|
506
|
+
delete: row.deleteCount || 0,
|
|
507
|
+
},
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// =============================================================================
|
|
512
|
+
// FACTORY
|
|
513
|
+
// =============================================================================
|
|
514
|
+
/**
|
|
515
|
+
* Create a FileChangeTracker instance.
|
|
516
|
+
*/
|
|
517
|
+
export function createFileChangeTracker(db, sessionId, config) {
|
|
518
|
+
return new FileChangeTracker(db, sessionId, config);
|
|
519
|
+
}
|
|
520
|
+
//# sourceMappingURL=file-change-tracker.js.map
|