byterover-cli 0.2.1 → 0.3.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/README.md +56 -56
- package/bin/dev.js +1 -1
- package/dist/commands/cipher-agent/run.d.ts +111 -0
- package/dist/commands/cipher-agent/run.js +493 -0
- package/dist/commands/cipher-agent/set-prompt.d.ts +14 -0
- package/dist/commands/cipher-agent/set-prompt.js +53 -0
- package/dist/commands/cipher-agent/show-prompt.d.ts +11 -0
- package/dist/commands/cipher-agent/show-prompt.js +48 -0
- package/dist/commands/clear.d.ts +6 -0
- package/dist/commands/clear.js +36 -15
- package/dist/commands/curate.d.ts +74 -0
- package/dist/commands/curate.js +396 -0
- package/dist/commands/foo.d.ts +12 -0
- package/dist/commands/foo.js +61 -0
- package/dist/commands/gen-rules.d.ts +3 -0
- package/dist/commands/gen-rules.js +39 -20
- package/dist/commands/init.d.ts +48 -3
- package/dist/commands/init.js +242 -70
- package/dist/commands/login.js +9 -4
- package/dist/commands/pull.d.ts +33 -0
- package/dist/commands/pull.js +115 -0
- package/dist/commands/push.d.ts +13 -13
- package/dist/commands/push.js +81 -101
- package/dist/commands/query.d.ts +63 -0
- package/dist/commands/query.js +349 -0
- package/dist/commands/space/list.d.ts +5 -2
- package/dist/commands/space/list.js +60 -56
- package/dist/commands/space/switch.d.ts +16 -0
- package/dist/commands/space/switch.js +102 -53
- package/dist/commands/status.d.ts +5 -2
- package/dist/commands/status.js +43 -33
- package/dist/commands/watch.d.ts +23 -0
- package/dist/commands/watch.js +171 -0
- package/dist/config/auth.config.js +14 -2
- package/dist/config/context-tree-domains.d.ts +12 -0
- package/dist/config/context-tree-domains.js +29 -0
- package/dist/config/environment.d.ts +6 -0
- package/dist/config/environment.js +9 -2
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +6 -0
- package/dist/core/domain/cipher/agent/agent-state-machine.d.ts +128 -0
- package/dist/core/domain/cipher/agent/agent-state-machine.js +183 -0
- package/dist/core/domain/cipher/agent/agent-state.d.ts +77 -0
- package/dist/core/domain/cipher/agent/agent-state.js +59 -0
- package/dist/core/domain/cipher/agent/index.d.ts +7 -0
- package/dist/core/domain/cipher/agent/index.js +7 -0
- package/dist/core/domain/cipher/agent-events/index.d.ts +8 -0
- package/dist/core/domain/cipher/agent-events/index.js +7 -0
- package/dist/core/domain/cipher/agent-events/types.d.ts +419 -0
- package/dist/core/domain/cipher/agent-events/types.js +42 -0
- package/dist/core/domain/cipher/blob/types.d.ts +108 -0
- package/dist/core/domain/cipher/errors/blob-error.d.ts +36 -0
- package/dist/core/domain/cipher/errors/blob-error.js +68 -0
- package/dist/core/domain/cipher/errors/file-system-error.d.ts +211 -0
- package/dist/core/domain/cipher/errors/file-system-error.js +291 -0
- package/dist/core/domain/cipher/errors/llm-error.d.ts +120 -0
- package/dist/core/domain/cipher/errors/llm-error.js +161 -0
- package/dist/core/domain/cipher/errors/memory-error.d.ts +35 -0
- package/dist/core/domain/cipher/errors/memory-error.js +62 -0
- package/dist/core/domain/cipher/errors/process-error-code.d.ts +97 -0
- package/dist/core/domain/cipher/errors/process-error-code.js +98 -0
- package/dist/core/domain/cipher/errors/process-error.d.ts +135 -0
- package/dist/core/domain/cipher/errors/process-error.js +173 -0
- package/dist/core/domain/cipher/errors/session-error.d.ts +56 -0
- package/dist/core/domain/cipher/errors/session-error.js +74 -0
- package/dist/core/domain/cipher/errors/tool-error.d.ts +57 -0
- package/dist/core/domain/cipher/errors/tool-error.js +81 -0
- package/dist/core/domain/cipher/file-system/types.d.ts +203 -0
- package/dist/core/domain/cipher/memory/types.d.ts +102 -0
- package/dist/core/domain/cipher/memory/types.js +4 -0
- package/dist/core/domain/cipher/parsed-interaction.d.ts +47 -0
- package/dist/core/domain/cipher/parsed-interaction.js +25 -0
- package/dist/core/domain/cipher/process/types.d.ts +286 -0
- package/dist/core/domain/cipher/session/types.d.ts +54 -0
- package/dist/core/domain/cipher/storage/history-types.d.ts +38 -0
- package/dist/core/domain/cipher/system-prompt/types.d.ts +131 -0
- package/dist/core/domain/cipher/todos/index.d.ts +4 -0
- package/dist/core/domain/cipher/todos/index.js +4 -0
- package/dist/core/domain/cipher/todos/types.d.ts +57 -0
- package/dist/core/domain/cipher/todos/types.js +5 -0
- package/dist/core/domain/cipher/tools/constants.d.ts +28 -0
- package/dist/core/domain/cipher/tools/constants.js +24 -0
- package/dist/core/domain/cipher/tools/tool-error.d.ts +183 -0
- package/dist/core/domain/cipher/tools/tool-error.js +246 -0
- package/dist/core/domain/cipher/tools/types.d.ts +145 -0
- package/dist/core/domain/entities/brv-config.d.ts +42 -6
- package/dist/core/domain/entities/brv-config.js +115 -17
- package/dist/core/domain/entities/cogit-push-context.d.ts +38 -0
- package/dist/core/domain/entities/cogit-push-context.js +91 -0
- package/dist/core/domain/entities/cogit-push-response.d.ts +20 -0
- package/dist/core/domain/entities/cogit-push-response.js +31 -0
- package/dist/core/domain/entities/cogit-snapshot-author.d.ts +24 -0
- package/dist/core/domain/entities/cogit-snapshot-author.js +39 -0
- package/dist/core/domain/entities/cogit-snapshot-file.d.ts +34 -0
- package/dist/core/domain/entities/cogit-snapshot-file.js +59 -0
- package/dist/core/domain/entities/cogit-snapshot.d.ts +31 -0
- package/dist/core/domain/entities/cogit-snapshot.js +58 -0
- package/dist/core/domain/entities/context-tree-index.d.ts +26 -0
- package/dist/core/domain/entities/context-tree-index.js +27 -0
- package/dist/core/domain/entities/context-tree-snapshot.d.ts +56 -0
- package/dist/core/domain/entities/context-tree-snapshot.js +83 -0
- package/dist/core/domain/entities/event.d.ts +1 -1
- package/dist/core/domain/entities/event.js +3 -1
- package/dist/core/domain/entities/parser.d.ts +567 -0
- package/dist/core/domain/entities/parser.js +10 -0
- package/dist/core/domain/entities/playbook.d.ts +2 -23
- package/dist/core/domain/entities/playbook.js +2 -70
- package/dist/core/domain/errors/brv-config-version-error.d.ts +16 -0
- package/dist/core/domain/errors/brv-config-version-error.js +21 -0
- package/dist/core/domain/knowledge/directory-manager.d.ts +80 -0
- package/dist/core/domain/knowledge/directory-manager.js +145 -0
- package/dist/core/domain/knowledge/markdown-writer.d.ts +18 -0
- package/dist/core/domain/knowledge/markdown-writer.js +18 -0
- package/dist/core/domain/knowledge/relation-parser.d.ts +90 -0
- package/dist/core/domain/knowledge/relation-parser.js +131 -0
- package/dist/core/interfaces/cipher/cipher-services.d.ts +71 -0
- package/dist/core/interfaces/cipher/cipher-services.js +1 -0
- package/dist/core/interfaces/cipher/i-blob-storage.d.ts +78 -0
- package/dist/core/interfaces/cipher/i-blob-storage.js +1 -0
- package/dist/core/interfaces/cipher/i-chat-session.d.ts +62 -0
- package/dist/core/interfaces/cipher/i-chat-session.js +1 -0
- package/dist/core/interfaces/cipher/i-cipher-agent.d.ts +88 -0
- package/dist/core/interfaces/cipher/i-cipher-agent.js +1 -0
- package/dist/core/interfaces/cipher/i-coding-agent-log-parser.d.ts +20 -0
- package/dist/core/interfaces/cipher/i-coding-agent-log-parser.js +1 -0
- package/dist/core/interfaces/cipher/i-coding-agent-log-watcher.d.ts +31 -0
- package/dist/core/interfaces/cipher/i-coding-agent-log-watcher.js +1 -0
- package/dist/core/interfaces/cipher/i-content-generator.d.ts +120 -0
- package/dist/core/interfaces/cipher/i-content-generator.js +12 -0
- package/dist/core/interfaces/cipher/i-event-emitter.d.ts +76 -0
- package/dist/core/interfaces/cipher/i-event-emitter.js +1 -0
- package/dist/core/interfaces/cipher/i-file-system.d.ts +68 -0
- package/dist/core/interfaces/cipher/i-file-system.js +1 -0
- package/dist/core/interfaces/cipher/i-history-storage.d.ts +53 -0
- package/dist/core/interfaces/cipher/i-history-storage.js +1 -0
- package/dist/core/interfaces/cipher/i-llm-provider.d.ts +14 -0
- package/dist/core/interfaces/cipher/i-llm-provider.js +1 -0
- package/dist/core/interfaces/cipher/i-llm-service.d.ts +62 -0
- package/dist/core/interfaces/cipher/i-llm-service.js +1 -0
- package/dist/core/interfaces/cipher/i-logger.d.ts +78 -0
- package/dist/core/interfaces/cipher/i-logger.js +28 -0
- package/dist/core/interfaces/cipher/i-message-formatter.d.ts +44 -0
- package/dist/core/interfaces/cipher/i-message-formatter.js +1 -0
- package/dist/core/interfaces/cipher/i-policy-engine.d.ts +102 -0
- package/dist/core/interfaces/cipher/i-policy-engine.js +9 -0
- package/dist/core/interfaces/cipher/i-process-service.d.ts +65 -0
- package/dist/core/interfaces/cipher/i-process-service.js +1 -0
- package/dist/core/interfaces/cipher/i-system-prompt-contributor.d.ts +25 -0
- package/dist/core/interfaces/cipher/i-system-prompt-contributor.js +1 -0
- package/dist/core/interfaces/cipher/i-tokenizer.d.ts +15 -0
- package/dist/core/interfaces/cipher/i-tokenizer.js +1 -0
- package/dist/core/interfaces/cipher/i-tool-provider.d.ts +64 -0
- package/dist/core/interfaces/cipher/i-tool-provider.js +1 -0
- package/dist/core/interfaces/cipher/i-tool-scheduler.d.ts +103 -0
- package/dist/core/interfaces/cipher/i-tool-scheduler.js +11 -0
- package/dist/core/interfaces/cipher/llm-types.d.ts +46 -0
- package/dist/core/interfaces/cipher/llm-types.js +5 -0
- package/dist/core/interfaces/cipher/message-types.d.ts +118 -0
- package/dist/core/interfaces/cipher/message-types.js +5 -0
- package/dist/core/interfaces/cipher/tokenizer-types.d.ts +11 -0
- package/dist/core/interfaces/cipher/tokenizer-types.js +14 -0
- package/dist/core/interfaces/i-cogit-pull-service.d.ts +24 -0
- package/dist/core/interfaces/i-cogit-pull-service.js +1 -0
- package/dist/core/interfaces/i-cogit-push-service.d.ts +27 -0
- package/dist/core/interfaces/i-cogit-push-service.js +1 -0
- package/dist/core/interfaces/i-context-file-reader.d.ts +32 -0
- package/dist/core/interfaces/i-context-file-reader.js +1 -0
- package/dist/core/interfaces/i-context-tree-service.d.ts +21 -0
- package/dist/core/interfaces/i-context-tree-service.js +1 -0
- package/dist/core/interfaces/i-context-tree-snapshot-service.d.ts +36 -0
- package/dist/core/interfaces/i-context-tree-snapshot-service.js +1 -0
- package/dist/core/interfaces/i-context-tree-writer-service.d.ts +32 -0
- package/dist/core/interfaces/i-context-tree-writer-service.js +1 -0
- package/dist/core/interfaces/i-file-watcher-service.d.ts +41 -0
- package/dist/core/interfaces/i-file-watcher-service.js +1 -0
- package/dist/core/interfaces/parser/i-clean-parser-service.d.ts +18 -0
- package/dist/core/interfaces/parser/i-clean-parser-service.js +1 -0
- package/dist/core/interfaces/parser/i-raw-parser-service.d.ts +17 -0
- package/dist/core/interfaces/parser/i-raw-parser-service.js +1 -0
- package/dist/core/interfaces/parser/i-session-normalizer.d.ts +56 -0
- package/dist/core/interfaces/parser/i-session-normalizer.js +1 -0
- package/dist/hooks/command_not_found/handle-invalid-commands.d.ts +7 -0
- package/dist/hooks/command_not_found/handle-invalid-commands.js +32 -0
- package/dist/hooks/error/clean-errors.d.ts +7 -0
- package/dist/hooks/error/clean-errors.js +50 -0
- package/dist/hooks/init/welcome.js +72 -1
- package/dist/hooks/prerun/validate-brv-config-version.d.ts +28 -0
- package/dist/hooks/prerun/validate-brv-config-version.js +43 -0
- package/dist/infra/cipher/agent-service-factory.d.ts +86 -0
- package/dist/infra/cipher/agent-service-factory.js +212 -0
- package/dist/infra/cipher/blob/blob-storage-factory.d.ts +13 -0
- package/dist/infra/cipher/blob/blob-storage-factory.js +14 -0
- package/dist/infra/cipher/blob/index.d.ts +10 -0
- package/dist/infra/cipher/blob/index.js +12 -0
- package/dist/infra/cipher/blob/migrations.d.ts +63 -0
- package/dist/infra/cipher/blob/migrations.js +148 -0
- package/dist/infra/cipher/blob/sqlite-blob-storage.d.ts +82 -0
- package/dist/infra/cipher/blob/sqlite-blob-storage.js +307 -0
- package/dist/infra/cipher/cipher-agent-state-manager.d.ts +63 -0
- package/dist/infra/cipher/cipher-agent-state-manager.js +108 -0
- package/dist/infra/cipher/cipher-agent.d.ts +182 -0
- package/dist/infra/cipher/cipher-agent.js +317 -0
- package/dist/infra/cipher/command-parser.d.ts +23 -0
- package/dist/infra/cipher/command-parser.js +85 -0
- package/dist/infra/cipher/display/todo-display.d.ts +23 -0
- package/dist/infra/cipher/display/todo-display.js +129 -0
- package/dist/infra/cipher/events/event-emitter.d.ts +137 -0
- package/dist/infra/cipher/events/event-emitter.js +158 -0
- package/dist/infra/cipher/exit-codes.d.ts +44 -0
- package/dist/infra/cipher/exit-codes.js +58 -0
- package/dist/infra/cipher/file-system/file-system-service.d.ts +105 -0
- package/dist/infra/cipher/file-system/file-system-service.js +641 -0
- package/dist/infra/cipher/file-system/gitignore-filter.d.ts +77 -0
- package/dist/infra/cipher/file-system/gitignore-filter.js +120 -0
- package/dist/infra/cipher/file-system/glob-utils.d.ts +60 -0
- package/dist/infra/cipher/file-system/glob-utils.js +120 -0
- package/dist/infra/cipher/file-system/path-validator.d.ts +69 -0
- package/dist/infra/cipher/file-system/path-validator.js +184 -0
- package/dist/infra/cipher/grpc/internal-llm-grpc-service.d.ts +149 -0
- package/dist/infra/cipher/grpc/internal-llm-grpc-service.js +364 -0
- package/dist/infra/cipher/grpc/internal-llm-grpc.proto +94 -0
- package/dist/infra/cipher/interactive-commands.d.ts +16 -0
- package/dist/infra/cipher/interactive-commands.js +198 -0
- package/dist/infra/cipher/interactive-loop.d.ts +24 -0
- package/dist/infra/cipher/interactive-loop.js +352 -0
- package/dist/infra/cipher/llm/context/async-mutex.d.ts +59 -0
- package/dist/infra/cipher/llm/context/async-mutex.js +92 -0
- package/dist/infra/cipher/llm/context/compression/index.d.ts +6 -0
- package/dist/infra/cipher/llm/context/compression/index.js +5 -0
- package/dist/infra/cipher/llm/context/compression/middle-removal.d.ts +40 -0
- package/dist/infra/cipher/llm/context/compression/middle-removal.js +76 -0
- package/dist/infra/cipher/llm/context/compression/oldest-removal.d.ts +38 -0
- package/dist/infra/cipher/llm/context/compression/oldest-removal.js +53 -0
- package/dist/infra/cipher/llm/context/compression/types.d.ts +36 -0
- package/dist/infra/cipher/llm/context/compression/types.js +1 -0
- package/dist/infra/cipher/llm/context/context-manager.d.ts +234 -0
- package/dist/infra/cipher/llm/context/context-manager.js +419 -0
- package/dist/infra/cipher/llm/context/index.d.ts +2 -0
- package/dist/infra/cipher/llm/context/index.js +2 -0
- package/dist/infra/cipher/llm/context/loop-detector.d.ts +125 -0
- package/dist/infra/cipher/llm/context/loop-detector.js +194 -0
- package/dist/infra/cipher/llm/context/utils.d.ts +17 -0
- package/dist/infra/cipher/llm/context/utils.js +89 -0
- package/dist/infra/cipher/llm/formatters/claude-formatter.d.ts +54 -0
- package/dist/infra/cipher/llm/formatters/claude-formatter.js +182 -0
- package/dist/infra/cipher/llm/formatters/gemini-formatter.d.ts +69 -0
- package/dist/infra/cipher/llm/formatters/gemini-formatter.js +253 -0
- package/dist/infra/cipher/llm/formatters/openrouter-formatter.d.ts +47 -0
- package/dist/infra/cipher/llm/formatters/openrouter-formatter.js +238 -0
- package/dist/infra/cipher/llm/generators/byterover-content-generator.d.ts +92 -0
- package/dist/infra/cipher/llm/generators/byterover-content-generator.js +211 -0
- package/dist/infra/cipher/llm/generators/index.d.ts +13 -0
- package/dist/infra/cipher/llm/generators/index.js +13 -0
- package/dist/infra/cipher/llm/generators/logging-content-generator.d.ts +104 -0
- package/dist/infra/cipher/llm/generators/logging-content-generator.js +182 -0
- package/dist/infra/cipher/llm/generators/openrouter-content-generator.d.ts +93 -0
- package/dist/infra/cipher/llm/generators/openrouter-content-generator.js +254 -0
- package/dist/infra/cipher/llm/generators/retryable-content-generator.d.ts +90 -0
- package/dist/infra/cipher/llm/generators/retryable-content-generator.js +157 -0
- package/dist/infra/cipher/llm/index.d.ts +9 -0
- package/dist/infra/cipher/llm/index.js +13 -0
- package/dist/infra/cipher/llm/internal-llm-service.d.ts +308 -0
- package/dist/infra/cipher/llm/internal-llm-service.js +724 -0
- package/dist/infra/cipher/llm/openrouter-llm-service.d.ts +183 -0
- package/dist/infra/cipher/llm/openrouter-llm-service.js +386 -0
- package/dist/infra/cipher/llm/response-validator.d.ts +89 -0
- package/dist/infra/cipher/llm/response-validator.js +157 -0
- package/dist/infra/cipher/llm/retry/index.d.ts +10 -0
- package/dist/infra/cipher/llm/retry/index.js +10 -0
- package/dist/infra/cipher/llm/retry/retry-policy.d.ts +74 -0
- package/dist/infra/cipher/llm/retry/retry-policy.js +146 -0
- package/dist/infra/cipher/llm/retry/retry-with-backoff.d.ts +113 -0
- package/dist/infra/cipher/llm/retry/retry-with-backoff.js +247 -0
- package/dist/infra/cipher/llm/thought-parser.d.ts +145 -0
- package/dist/infra/cipher/llm/thought-parser.js +190 -0
- package/dist/infra/cipher/llm/tokenizers/claude-tokenizer.d.ts +47 -0
- package/dist/infra/cipher/llm/tokenizers/claude-tokenizer.js +55 -0
- package/dist/infra/cipher/llm/tokenizers/default-tokenizer.d.ts +31 -0
- package/dist/infra/cipher/llm/tokenizers/default-tokenizer.js +38 -0
- package/dist/infra/cipher/llm/tokenizers/gemini-tokenizer.d.ts +37 -0
- package/dist/infra/cipher/llm/tokenizers/gemini-tokenizer.js +45 -0
- package/dist/infra/cipher/llm/tokenizers/openrouter-tokenizer.d.ts +29 -0
- package/dist/infra/cipher/llm/tokenizers/openrouter-tokenizer.js +37 -0
- package/dist/infra/cipher/llm/tool-output-processor.d.ts +117 -0
- package/dist/infra/cipher/llm/tool-output-processor.js +153 -0
- package/dist/infra/cipher/logger/console-logger.d.ts +42 -0
- package/dist/infra/cipher/logger/console-logger.js +63 -0
- package/dist/infra/cipher/logger/event-based-logger.d.ts +54 -0
- package/dist/infra/cipher/logger/event-based-logger.js +92 -0
- package/dist/infra/cipher/memory/index.d.ts +6 -0
- package/dist/infra/cipher/memory/index.js +7 -0
- package/dist/infra/cipher/memory/memory-manager.d.ts +136 -0
- package/dist/infra/cipher/memory/memory-manager.js +523 -0
- package/dist/infra/cipher/parsers/coding-agent-log-parser.d.ts +24 -0
- package/dist/infra/cipher/parsers/coding-agent-log-parser.js +51 -0
- package/dist/infra/cipher/process/command-validator.d.ts +59 -0
- package/dist/infra/cipher/process/command-validator.js +266 -0
- package/dist/infra/cipher/process/index.d.ts +8 -0
- package/dist/infra/cipher/process/index.js +8 -0
- package/dist/infra/cipher/process/process-service.d.ts +95 -0
- package/dist/infra/cipher/process/process-service.js +439 -0
- package/dist/infra/cipher/session/chat-session.d.ts +80 -0
- package/dist/infra/cipher/session/chat-session.js +165 -0
- package/dist/infra/cipher/session/index.d.ts +6 -0
- package/dist/infra/cipher/session/index.js +5 -0
- package/dist/infra/cipher/session/session-event-forwarder.d.ts +37 -0
- package/dist/infra/cipher/session/session-event-forwarder.js +83 -0
- package/dist/infra/cipher/session/session-manager.d.ts +109 -0
- package/dist/infra/cipher/session/session-manager.js +172 -0
- package/dist/infra/cipher/storage/blob-history-storage.d.ts +76 -0
- package/dist/infra/cipher/storage/blob-history-storage.js +178 -0
- package/dist/infra/cipher/system-prompt/simple-prompt-factory.d.ts +105 -0
- package/dist/infra/cipher/system-prompt/simple-prompt-factory.js +290 -0
- package/dist/infra/cipher/tools/core-tool-scheduler.d.ts +99 -0
- package/dist/infra/cipher/tools/core-tool-scheduler.js +161 -0
- package/dist/infra/cipher/tools/default-policy-rules.d.ts +26 -0
- package/dist/infra/cipher/tools/default-policy-rules.js +125 -0
- package/dist/infra/cipher/tools/implementations/bash-exec-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/bash-exec-tool.js +93 -0
- package/dist/infra/cipher/tools/implementations/bash-output-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/bash-output-tool.js +47 -0
- package/dist/infra/cipher/tools/implementations/create-knowledge-topic-tool.d.ts +11 -0
- package/dist/infra/cipher/tools/implementations/create-knowledge-topic-tool.js +142 -0
- package/dist/infra/cipher/tools/implementations/delete-memory-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/delete-memory-tool.js +37 -0
- package/dist/infra/cipher/tools/implementations/detect-domains-tool.d.ts +7 -0
- package/dist/infra/cipher/tools/implementations/detect-domains-tool.js +73 -0
- package/dist/infra/cipher/tools/implementations/edit-file-tool.d.ts +13 -0
- package/dist/infra/cipher/tools/implementations/edit-file-tool.js +50 -0
- package/dist/infra/cipher/tools/implementations/edit-memory-tool.d.ts +13 -0
- package/dist/infra/cipher/tools/implementations/edit-memory-tool.js +53 -0
- package/dist/infra/cipher/tools/implementations/find-knowledge-topics-tool.d.ts +7 -0
- package/dist/infra/cipher/tools/implementations/find-knowledge-topics-tool.js +421 -0
- package/dist/infra/cipher/tools/implementations/glob-files-tool.d.ts +18 -0
- package/dist/infra/cipher/tools/implementations/glob-files-tool.js +70 -0
- package/dist/infra/cipher/tools/implementations/grep-content-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/grep-content-tool.js +77 -0
- package/dist/infra/cipher/tools/implementations/kill-process-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/kill-process-tool.js +55 -0
- package/dist/infra/cipher/tools/implementations/list-memories-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/list-memories-tool.js +63 -0
- package/dist/infra/cipher/tools/implementations/read-file-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/read-file-tool.js +54 -0
- package/dist/infra/cipher/tools/implementations/read-memory-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/read-memory-tool.js +39 -0
- package/dist/infra/cipher/tools/implementations/search-history-tool.d.ts +10 -0
- package/dist/infra/cipher/tools/implementations/search-history-tool.js +36 -0
- package/dist/infra/cipher/tools/implementations/write-file-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/write-file-tool.js +52 -0
- package/dist/infra/cipher/tools/implementations/write-memory-tool.d.ts +13 -0
- package/dist/infra/cipher/tools/implementations/write-memory-tool.js +52 -0
- package/dist/infra/cipher/tools/implementations/write-todos-tool.d.ts +10 -0
- package/dist/infra/cipher/tools/implementations/write-todos-tool.js +165 -0
- package/dist/infra/cipher/tools/index.d.ts +18 -0
- package/dist/infra/cipher/tools/index.js +19 -0
- package/dist/infra/cipher/tools/policy-engine.d.ts +80 -0
- package/dist/infra/cipher/tools/policy-engine.js +110 -0
- package/dist/infra/cipher/tools/tool-invocation-queue.d.ts +191 -0
- package/dist/infra/cipher/tools/tool-invocation-queue.js +254 -0
- package/dist/infra/cipher/tools/tool-invocation.d.ts +216 -0
- package/dist/infra/cipher/tools/tool-invocation.js +294 -0
- package/dist/infra/cipher/tools/tool-manager.d.ts +135 -0
- package/dist/infra/cipher/tools/tool-manager.js +209 -0
- package/dist/infra/cipher/tools/tool-markers.d.ts +48 -0
- package/dist/infra/cipher/tools/tool-markers.js +49 -0
- package/dist/infra/cipher/tools/tool-provider.d.ts +77 -0
- package/dist/infra/cipher/tools/tool-provider.js +196 -0
- package/dist/infra/cipher/tools/tool-registry.d.ts +52 -0
- package/dist/infra/cipher/tools/tool-registry.js +144 -0
- package/dist/infra/cipher/tools/utils/schema-converter.d.ts +10 -0
- package/dist/infra/cipher/tools/utils/schema-converter.js +29 -0
- package/dist/infra/cipher/validation/workspace-validator.d.ts +19 -0
- package/dist/infra/cipher/validation/workspace-validator.js +37 -0
- package/dist/infra/cipher/watcher/coding-agent-log-watcher.d.ts +14 -0
- package/dist/infra/cipher/watcher/coding-agent-log-watcher.js +55 -0
- package/dist/infra/cogit/context-tree-to-push-context-mapper.d.ts +21 -0
- package/dist/infra/cogit/context-tree-to-push-context-mapper.js +32 -0
- package/dist/infra/cogit/http-cogit-pull-service.d.ts +15 -0
- package/dist/infra/cogit/http-cogit-pull-service.js +30 -0
- package/dist/infra/cogit/http-cogit-push-service.d.ts +17 -0
- package/dist/infra/cogit/http-cogit-push-service.js +104 -0
- package/dist/infra/config/file-config-store.js +9 -3
- package/dist/infra/context-tree/file-context-file-reader.d.ts +14 -0
- package/dist/infra/context-tree/file-context-file-reader.js +46 -0
- package/dist/infra/context-tree/file-context-tree-service.d.ts +14 -0
- package/dist/infra/context-tree/file-context-tree-service.js +46 -0
- package/dist/infra/context-tree/file-context-tree-snapshot-service.d.ts +34 -0
- package/dist/infra/context-tree/file-context-tree-snapshot-service.js +117 -0
- package/dist/infra/context-tree/file-context-tree-writer-service.d.ts +22 -0
- package/dist/infra/context-tree/file-context-tree-writer-service.js +61 -0
- package/dist/infra/memory/http-memory-retrieval-service.js +2 -1
- package/dist/infra/memory/http-memory-storage-service.js +4 -3
- package/dist/infra/parsers/clean/clean-claude-service.d.ts +111 -0
- package/dist/infra/parsers/clean/clean-claude-service.js +271 -0
- package/dist/infra/parsers/clean/clean-codex-service.d.ts +231 -0
- package/dist/infra/parsers/clean/clean-codex-service.js +534 -0
- package/dist/infra/parsers/clean/clean-copilot-service.d.ts +255 -0
- package/dist/infra/parsers/clean/clean-copilot-service.js +729 -0
- package/dist/infra/parsers/clean/clean-cursor-service.d.ts +161 -0
- package/dist/infra/parsers/clean/clean-cursor-service.js +432 -0
- package/dist/infra/parsers/clean/clean-parser-service-factory.d.ts +54 -0
- package/dist/infra/parsers/clean/clean-parser-service-factory.js +80 -0
- package/dist/infra/parsers/clean/shared.d.ts +84 -0
- package/dist/infra/parsers/clean/shared.js +273 -0
- package/dist/infra/parsers/raw/raw-claude-service.d.ts +195 -0
- package/dist/infra/parsers/raw/raw-claude-service.js +548 -0
- package/dist/infra/parsers/raw/raw-codex-service.d.ts +313 -0
- package/dist/infra/parsers/raw/raw-codex-service.js +782 -0
- package/dist/infra/parsers/raw/raw-copilot-service.d.ts +196 -0
- package/dist/infra/parsers/raw/raw-copilot-service.js +558 -0
- package/dist/infra/parsers/raw/raw-cursor-service.d.ts +316 -0
- package/dist/infra/parsers/raw/raw-cursor-service.js +818 -0
- package/dist/infra/parsers/raw/raw-parser-service-factory.d.ts +54 -0
- package/dist/infra/parsers/raw/raw-parser-service-factory.js +81 -0
- package/dist/infra/space/http-space-service.js +2 -1
- package/dist/infra/team/http-team-service.js +2 -1
- package/dist/infra/user/http-user-service.js +2 -1
- package/dist/infra/watcher/file-watcher-service.d.ts +10 -0
- package/dist/infra/watcher/file-watcher-service.js +81 -0
- package/dist/infra/workspace/workspace-detector-service.d.ts +60 -0
- package/dist/infra/workspace/workspace-detector-service.js +165 -0
- package/dist/resources/prompts/curate-context-tree-curation.yml +48 -0
- package/dist/resources/prompts/modes/autonomous.yml +9 -0
- package/dist/resources/prompts/query-context-tree-retrieval.yml +49 -0
- package/dist/resources/prompts/reflection.yml +27 -0
- package/dist/resources/prompts/system-prompt.yml +82 -0
- package/dist/resources/prompts/tool-outputs.yml +30 -0
- package/dist/templates/README.md +6 -7
- package/dist/templates/sections/command-reference.md +40 -111
- package/dist/templates/sections/workflow.md +3 -30
- package/dist/utils/emoji-helpers.d.ts +38 -0
- package/dist/utils/emoji-helpers.js +42 -0
- package/dist/utils/error-handler.d.ts +51 -0
- package/dist/utils/error-handler.js +169 -0
- package/dist/utils/error-helpers.d.ts +30 -0
- package/dist/utils/error-helpers.js +47 -0
- package/dist/utils/file-helpers.d.ts +15 -0
- package/dist/utils/file-helpers.js +44 -0
- package/dist/utils/oclif-error-helpers.d.ts +40 -0
- package/dist/utils/oclif-error-helpers.js +46 -0
- package/dist/utils/tool-display-formatter.d.ts +53 -0
- package/dist/utils/tool-display-formatter.js +257 -0
- package/oclif.manifest.json +381 -141
- package/package.json +27 -6
- package/dist/commands/add.d.ts +0 -49
- package/dist/commands/add.js +0 -192
- package/dist/commands/complete.d.ts +0 -108
- package/dist/commands/complete.js +0 -340
- package/dist/commands/retrieve.d.ts +0 -26
- package/dist/commands/retrieve.js +0 -101
- package/dist/core/domain/entities/curator-output.d.ts +0 -14
- package/dist/core/domain/entities/curator-output.js +0 -23
- package/dist/core/domain/entities/delta-batch.d.ts +0 -30
- package/dist/core/domain/entities/delta-batch.js +0 -52
- package/dist/core/domain/entities/delta-operation.d.ts +0 -31
- package/dist/core/domain/entities/delta-operation.js +0 -50
- package/dist/core/domain/entities/executor-output.d.ts +0 -27
- package/dist/core/domain/entities/executor-output.js +0 -33
- package/dist/core/domain/entities/reflector-output.d.ts +0 -38
- package/dist/core/domain/entities/reflector-output.js +0 -44
- package/dist/core/interfaces/i-ace-prompt-builder.d.ts +0 -48
- package/dist/core/interfaces/i-bullet-content-store.d.ts +0 -36
- package/dist/core/interfaces/i-delta-store.d.ts +0 -15
- package/dist/core/interfaces/i-executor-output-store.d.ts +0 -14
- package/dist/core/interfaces/i-playbook-service.d.ts +0 -69
- package/dist/core/interfaces/i-playbook-store.d.ts +0 -38
- package/dist/core/interfaces/i-reflection-store.d.ts +0 -21
- package/dist/infra/ace/ace-file-utils.d.ts +0 -46
- package/dist/infra/ace/ace-file-utils.js +0 -83
- package/dist/infra/ace/ace-prompt-templates.d.ts +0 -13
- package/dist/infra/ace/ace-prompt-templates.js +0 -177
- package/dist/infra/ace/file-bullet-content-store.d.ts +0 -27
- package/dist/infra/ace/file-bullet-content-store.js +0 -89
- package/dist/infra/ace/file-delta-store.d.ts +0 -9
- package/dist/infra/ace/file-delta-store.js +0 -26
- package/dist/infra/ace/file-executor-output-store.d.ts +0 -9
- package/dist/infra/ace/file-executor-output-store.js +0 -26
- package/dist/infra/ace/file-playbook-store.d.ts +0 -29
- package/dist/infra/ace/file-playbook-store.js +0 -107
- package/dist/infra/ace/file-reflection-store.d.ts +0 -10
- package/dist/infra/ace/file-reflection-store.js +0 -55
- package/dist/infra/playbook/file-playbook-service.d.ts +0 -42
- package/dist/infra/playbook/file-playbook-service.js +0 -132
- /package/dist/core/{interfaces/i-ace-prompt-builder.js → domain/cipher/blob/types.js} +0 -0
- /package/dist/core/{interfaces/i-bullet-content-store.js → domain/cipher/file-system/types.js} +0 -0
- /package/dist/core/{interfaces/i-delta-store.js → domain/cipher/process/types.js} +0 -0
- /package/dist/core/{interfaces/i-executor-output-store.js → domain/cipher/session/types.js} +0 -0
- /package/dist/core/{interfaces/i-playbook-service.js → domain/cipher/storage/history-types.js} +0 -0
- /package/dist/core/{interfaces/i-playbook-store.js → domain/cipher/system-prompt/types.js} +0 -0
- /package/dist/core/{interfaces/i-reflection-store.js → domain/cipher/tools/types.js} +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { BlobLogger } from '../../../core/domain/cipher/blob/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Migration definition type
|
|
5
|
+
*/
|
|
6
|
+
export type Migration = {
|
|
7
|
+
/**
|
|
8
|
+
* Description of what this migration does
|
|
9
|
+
*/
|
|
10
|
+
description: string;
|
|
11
|
+
/**
|
|
12
|
+
* Optional backward migration (downgrade)
|
|
13
|
+
* Only needed for critical rollback scenarios
|
|
14
|
+
* @param db - SQLite database instance
|
|
15
|
+
*/
|
|
16
|
+
down?(db: Database.Database): void;
|
|
17
|
+
/**
|
|
18
|
+
* Forward migration (upgrade)
|
|
19
|
+
* @param db - SQLite database instance
|
|
20
|
+
*/
|
|
21
|
+
up(db: Database.Database): void;
|
|
22
|
+
/**
|
|
23
|
+
* Migration version number (must be sequential)
|
|
24
|
+
*/
|
|
25
|
+
version: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* SQLite Blob Storage Migrations
|
|
29
|
+
*
|
|
30
|
+
* IMPORTANT RULES:
|
|
31
|
+
* 1. NEVER modify existing migrations - always add new ones
|
|
32
|
+
* 2. Version numbers must be sequential (1, 2, 3, ...)
|
|
33
|
+
* 3. Always use IF NOT EXISTS for safety
|
|
34
|
+
* 4. Test migrations thoroughly before releasing
|
|
35
|
+
* 5. Consider adding 'down' for complex changes
|
|
36
|
+
*/
|
|
37
|
+
export declare const MIGRATIONS: Migration[];
|
|
38
|
+
/**
|
|
39
|
+
* Get the current schema version from the database
|
|
40
|
+
*/
|
|
41
|
+
export declare function getCurrentVersion(db: Database.Database): number;
|
|
42
|
+
/**
|
|
43
|
+
* Set the schema version in the database
|
|
44
|
+
*/
|
|
45
|
+
export declare function setVersion(db: Database.Database, version: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Run all pending migrations
|
|
48
|
+
*
|
|
49
|
+
* @param db - SQLite database instance
|
|
50
|
+
* @param logger - Optional logger for migration output (defaults to console)
|
|
51
|
+
* @returns Number of migrations applied
|
|
52
|
+
* @throws Error if migration fails
|
|
53
|
+
*/
|
|
54
|
+
export declare function runMigrations(db: Database.Database, logger?: BlobLogger): number;
|
|
55
|
+
/**
|
|
56
|
+
* Rollback to a specific version (use with extreme caution!)
|
|
57
|
+
*
|
|
58
|
+
* @param db - SQLite database instance
|
|
59
|
+
* @param targetVersion - Version to rollback to
|
|
60
|
+
* @param logger - Optional logger for rollback output (defaults to console)
|
|
61
|
+
* @throws Error if rollback fails or migrations don't have 'down' methods
|
|
62
|
+
*/
|
|
63
|
+
export declare function rollbackToVersion(db: Database.Database, targetVersion: number, logger?: BlobLogger): void;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default logger that uses console (fallback when no logger provided)
|
|
3
|
+
*/
|
|
4
|
+
const defaultLogger = {
|
|
5
|
+
error: (message) => console.error(message),
|
|
6
|
+
info: (message) => console.log(message),
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* SQLite Blob Storage Migrations
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT RULES:
|
|
12
|
+
* 1. NEVER modify existing migrations - always add new ones
|
|
13
|
+
* 2. Version numbers must be sequential (1, 2, 3, ...)
|
|
14
|
+
* 3. Always use IF NOT EXISTS for safety
|
|
15
|
+
* 4. Test migrations thoroughly before releasing
|
|
16
|
+
* 5. Consider adding 'down' for complex changes
|
|
17
|
+
*/
|
|
18
|
+
export const MIGRATIONS = [
|
|
19
|
+
{
|
|
20
|
+
description: 'Initial schema: blobs table with comprehensive indexes',
|
|
21
|
+
down(db) {
|
|
22
|
+
// Rollback: drop all indexes and table
|
|
23
|
+
db.exec(`DROP INDEX IF EXISTS idx_blobs_size_created`);
|
|
24
|
+
db.exec(`DROP INDEX IF EXISTS idx_blobs_type_updated`);
|
|
25
|
+
db.exec(`DROP INDEX IF EXISTS idx_blobs_created_at`);
|
|
26
|
+
db.exec(`DROP INDEX IF EXISTS idx_blobs_updated_at`);
|
|
27
|
+
db.exec(`DROP INDEX IF EXISTS idx_blobs_size`);
|
|
28
|
+
db.exec(`DROP INDEX IF EXISTS idx_blobs_original_name`);
|
|
29
|
+
db.exec(`DROP INDEX IF EXISTS idx_blobs_content_type`);
|
|
30
|
+
db.exec(`DROP TABLE IF EXISTS blobs`);
|
|
31
|
+
},
|
|
32
|
+
up(db) {
|
|
33
|
+
// Create main table
|
|
34
|
+
db.exec(`
|
|
35
|
+
CREATE TABLE IF NOT EXISTS blobs (
|
|
36
|
+
key TEXT PRIMARY KEY,
|
|
37
|
+
content BLOB NOT NULL,
|
|
38
|
+
content_type TEXT,
|
|
39
|
+
original_name TEXT,
|
|
40
|
+
size INTEGER NOT NULL,
|
|
41
|
+
tags TEXT,
|
|
42
|
+
created_at INTEGER NOT NULL,
|
|
43
|
+
updated_at INTEGER NOT NULL
|
|
44
|
+
)
|
|
45
|
+
`);
|
|
46
|
+
// Single-column indexes
|
|
47
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_blobs_content_type ON blobs(content_type)`);
|
|
48
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_blobs_original_name ON blobs(original_name)`);
|
|
49
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_blobs_size ON blobs(size)`);
|
|
50
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_blobs_updated_at ON blobs(updated_at DESC)`);
|
|
51
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_blobs_created_at ON blobs(created_at DESC)`);
|
|
52
|
+
// Composite indexes
|
|
53
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_blobs_type_updated ON blobs(content_type, updated_at DESC)`);
|
|
54
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_blobs_size_created ON blobs(size, created_at DESC)`);
|
|
55
|
+
},
|
|
56
|
+
version: 1,
|
|
57
|
+
},
|
|
58
|
+
// Example future migration (commented out):
|
|
59
|
+
// {
|
|
60
|
+
// version: 2,
|
|
61
|
+
// description: 'Add checksum column for data integrity verification',
|
|
62
|
+
// up(db) {
|
|
63
|
+
// db.exec(`ALTER TABLE blobs ADD COLUMN checksum TEXT`);
|
|
64
|
+
// db.exec(`CREATE INDEX IF NOT EXISTS idx_blobs_checksum ON blobs(checksum)`);
|
|
65
|
+
// },
|
|
66
|
+
// down(db) {
|
|
67
|
+
// // Note: SQLite doesn't support DROP COLUMN easily
|
|
68
|
+
// // Would need to recreate table without the column
|
|
69
|
+
// db.exec(`DROP INDEX IF EXISTS idx_blobs_checksum`);
|
|
70
|
+
// },
|
|
71
|
+
// },
|
|
72
|
+
];
|
|
73
|
+
/**
|
|
74
|
+
* Get the current schema version from the database
|
|
75
|
+
*/
|
|
76
|
+
export function getCurrentVersion(db) {
|
|
77
|
+
const result = db.pragma('user_version', { simple: true });
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Set the schema version in the database
|
|
82
|
+
*/
|
|
83
|
+
export function setVersion(db, version) {
|
|
84
|
+
db.pragma(`user_version = ${version}`);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Run all pending migrations
|
|
88
|
+
*
|
|
89
|
+
* @param db - SQLite database instance
|
|
90
|
+
* @param logger - Optional logger for migration output (defaults to console)
|
|
91
|
+
* @returns Number of migrations applied
|
|
92
|
+
* @throws Error if migration fails
|
|
93
|
+
*/
|
|
94
|
+
export function runMigrations(db, logger = defaultLogger) {
|
|
95
|
+
const currentVersion = getCurrentVersion(db);
|
|
96
|
+
const pendingMigrations = MIGRATIONS.filter((m) => m.version > currentVersion);
|
|
97
|
+
if (pendingMigrations.length === 0) {
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
let appliedCount = 0;
|
|
101
|
+
// Use transaction for atomic migrations
|
|
102
|
+
const runMigrationsInTransaction = db.transaction(() => {
|
|
103
|
+
for (const migration of pendingMigrations) {
|
|
104
|
+
try {
|
|
105
|
+
// Run the migration (no verbose logging during execution)
|
|
106
|
+
migration.up(db);
|
|
107
|
+
// Update version
|
|
108
|
+
setVersion(db, migration.version);
|
|
109
|
+
appliedCount++;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
const errorMsg = `Database migration failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
113
|
+
logger.error(errorMsg);
|
|
114
|
+
throw new Error(errorMsg);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
// Execute all migrations atomically
|
|
119
|
+
runMigrationsInTransaction();
|
|
120
|
+
return appliedCount;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Rollback to a specific version (use with extreme caution!)
|
|
124
|
+
*
|
|
125
|
+
* @param db - SQLite database instance
|
|
126
|
+
* @param targetVersion - Version to rollback to
|
|
127
|
+
* @param logger - Optional logger for rollback output (defaults to console)
|
|
128
|
+
* @throws Error if rollback fails or migrations don't have 'down' methods
|
|
129
|
+
*/
|
|
130
|
+
export function rollbackToVersion(db, targetVersion, logger = defaultLogger) {
|
|
131
|
+
const currentVersion = getCurrentVersion(db);
|
|
132
|
+
if (targetVersion >= currentVersion) {
|
|
133
|
+
throw new Error(`Cannot rollback: target version ${targetVersion} is not older than current ${currentVersion}`);
|
|
134
|
+
}
|
|
135
|
+
const migrationsToRollback = MIGRATIONS.filter((m) => m.version > targetVersion && m.version <= currentVersion).reverse(); // Rollback in reverse order
|
|
136
|
+
const rollbackInTransaction = db.transaction(() => {
|
|
137
|
+
for (const migration of migrationsToRollback) {
|
|
138
|
+
if (!migration.down) {
|
|
139
|
+
throw new Error(`Migration v${migration.version} does not support rollback (no 'down' method)`);
|
|
140
|
+
}
|
|
141
|
+
logger.info(`[Migration] Rolling back v${migration.version}: ${migration.description}`);
|
|
142
|
+
migration.down(db);
|
|
143
|
+
}
|
|
144
|
+
setVersion(db, targetVersion);
|
|
145
|
+
});
|
|
146
|
+
rollbackInTransaction();
|
|
147
|
+
logger.info(`[Migration] Rolled back to v${targetVersion}`);
|
|
148
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { BlobMetadata, BlobStats, BlobStorageConfig, StoredBlob } from '../../../core/domain/cipher/blob/types.js';
|
|
2
|
+
import type { IBlobStorage } from '../../../core/interfaces/cipher/i-blob-storage.js';
|
|
3
|
+
/**
|
|
4
|
+
* SQLite-based blob storage implementation
|
|
5
|
+
*
|
|
6
|
+
* Stores all blobs in a single SQLite database file:
|
|
7
|
+
* - .brv/storage.db
|
|
8
|
+
*
|
|
9
|
+
* Schema:
|
|
10
|
+
* - blobs: key, content, content_type, original_name, size, tags, created_at, updated_at
|
|
11
|
+
*
|
|
12
|
+
* Benefits over file-based storage:
|
|
13
|
+
* - O(1) lookup for exists/retrieve
|
|
14
|
+
* - Fast listing and filtering
|
|
15
|
+
* - ACID transactions for data integrity
|
|
16
|
+
* - Single file for easy backup/migration
|
|
17
|
+
*/
|
|
18
|
+
export declare class SqliteBlobStorage implements IBlobStorage {
|
|
19
|
+
private db;
|
|
20
|
+
private readonly dbPath;
|
|
21
|
+
private initialized;
|
|
22
|
+
private readonly inMemory;
|
|
23
|
+
private readonly logger;
|
|
24
|
+
private readonly maxBlobSize;
|
|
25
|
+
private readonly maxTotalSize;
|
|
26
|
+
private readonly storageDir;
|
|
27
|
+
constructor(config?: Partial<BlobStorageConfig>);
|
|
28
|
+
/**
|
|
29
|
+
* Clear all blobs from storage
|
|
30
|
+
* WARNING: This is a destructive operation
|
|
31
|
+
*/
|
|
32
|
+
clear(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Close the database connection
|
|
35
|
+
*/
|
|
36
|
+
close(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Delete a blob by its key
|
|
39
|
+
*/
|
|
40
|
+
delete(key: string): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a blob exists
|
|
43
|
+
*/
|
|
44
|
+
exists(key: string): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Get metadata for a blob without retrieving its content
|
|
47
|
+
*/
|
|
48
|
+
getMetadata(key: string): Promise<BlobMetadata | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Get storage statistics
|
|
51
|
+
*/
|
|
52
|
+
getStats(): Promise<BlobStats>;
|
|
53
|
+
/**
|
|
54
|
+
* Initialize storage by creating the database and running migrations
|
|
55
|
+
*/
|
|
56
|
+
initialize(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* List all blob keys, optionally filtered by prefix
|
|
59
|
+
*/
|
|
60
|
+
list(prefix?: string): Promise<string[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Retrieve a blob by its key
|
|
63
|
+
*/
|
|
64
|
+
retrieve(key: string): Promise<StoredBlob | undefined>;
|
|
65
|
+
/**
|
|
66
|
+
* Store a blob with optional metadata
|
|
67
|
+
*/
|
|
68
|
+
store(key: string, content: Buffer | string, metadata?: Partial<BlobMetadata>): Promise<StoredBlob>;
|
|
69
|
+
/**
|
|
70
|
+
* Ensure storage has been initialized
|
|
71
|
+
*/
|
|
72
|
+
private ensureInitialized;
|
|
73
|
+
/**
|
|
74
|
+
* Convert database row to BlobMetadata
|
|
75
|
+
*/
|
|
76
|
+
private rowToMetadata;
|
|
77
|
+
/**
|
|
78
|
+
* Validate blob key
|
|
79
|
+
* Keys must be alphanumeric with hyphens and underscores only
|
|
80
|
+
*/
|
|
81
|
+
private validateKey;
|
|
82
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { BlobError } from '../../../core/domain/cipher/errors/blob-error.js';
|
|
5
|
+
/**
|
|
6
|
+
* SQLite-based blob storage implementation
|
|
7
|
+
*
|
|
8
|
+
* Stores all blobs in a single SQLite database file:
|
|
9
|
+
* - .brv/storage.db
|
|
10
|
+
*
|
|
11
|
+
* Schema:
|
|
12
|
+
* - blobs: key, content, content_type, original_name, size, tags, created_at, updated_at
|
|
13
|
+
*
|
|
14
|
+
* Benefits over file-based storage:
|
|
15
|
+
* - O(1) lookup for exists/retrieve
|
|
16
|
+
* - Fast listing and filtering
|
|
17
|
+
* - ACID transactions for data integrity
|
|
18
|
+
* - Single file for easy backup/migration
|
|
19
|
+
*/
|
|
20
|
+
export class SqliteBlobStorage {
|
|
21
|
+
db = null;
|
|
22
|
+
dbPath;
|
|
23
|
+
initialized = false;
|
|
24
|
+
inMemory;
|
|
25
|
+
logger;
|
|
26
|
+
maxBlobSize;
|
|
27
|
+
maxTotalSize;
|
|
28
|
+
storageDir;
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.inMemory = config?.inMemory ?? false;
|
|
31
|
+
this.storageDir = config?.storageDir || join(process.cwd(), '.brv');
|
|
32
|
+
this.dbPath = this.inMemory ? ':memory:' : join(this.storageDir, 'storage.db');
|
|
33
|
+
this.maxBlobSize = config?.maxBlobSize ?? 100 * 1024 * 1024; // 100MB default
|
|
34
|
+
this.maxTotalSize = config?.maxTotalSize ?? 1024 * 1024 * 1024; // 1GB default
|
|
35
|
+
this.logger = config?.logger ?? {
|
|
36
|
+
error: (message) => console.error(message),
|
|
37
|
+
info: (message) => console.log(message),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Clear all blobs from storage
|
|
42
|
+
* WARNING: This is a destructive operation
|
|
43
|
+
*/
|
|
44
|
+
async clear() {
|
|
45
|
+
this.ensureInitialized();
|
|
46
|
+
try {
|
|
47
|
+
this.db.exec('DELETE FROM blobs');
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw BlobError.deleteError(`Failed to clear storage: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Close the database connection
|
|
55
|
+
*/
|
|
56
|
+
close() {
|
|
57
|
+
if (this.db) {
|
|
58
|
+
this.db.close();
|
|
59
|
+
this.db = null;
|
|
60
|
+
this.initialized = false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Delete a blob by its key
|
|
65
|
+
*/
|
|
66
|
+
async delete(key) {
|
|
67
|
+
this.ensureInitialized();
|
|
68
|
+
this.validateKey(key);
|
|
69
|
+
try {
|
|
70
|
+
const stmt = this.db.prepare('DELETE FROM blobs WHERE key = ?');
|
|
71
|
+
const result = stmt.run(key);
|
|
72
|
+
if (result.changes === 0) {
|
|
73
|
+
throw BlobError.notFound(key);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof BlobError) {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
throw BlobError.deleteError(`Failed to delete blob ${key}: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if a blob exists
|
|
85
|
+
*/
|
|
86
|
+
async exists(key) {
|
|
87
|
+
this.ensureInitialized();
|
|
88
|
+
this.validateKey(key);
|
|
89
|
+
const stmt = this.db.prepare('SELECT 1 FROM blobs WHERE key = ?');
|
|
90
|
+
const row = stmt.get(key);
|
|
91
|
+
return row !== undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get metadata for a blob without retrieving its content
|
|
95
|
+
*/
|
|
96
|
+
async getMetadata(key) {
|
|
97
|
+
this.ensureInitialized();
|
|
98
|
+
this.validateKey(key);
|
|
99
|
+
try {
|
|
100
|
+
const stmt = this.db.prepare(`
|
|
101
|
+
SELECT content_type, original_name, size, tags, created_at, updated_at
|
|
102
|
+
FROM blobs WHERE key = ?
|
|
103
|
+
`);
|
|
104
|
+
const row = stmt.get(key);
|
|
105
|
+
if (!row) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
return this.rowToMetadata(row);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw BlobError.retrievalError(`Failed to read metadata for blob ${key}: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get storage statistics
|
|
116
|
+
*/
|
|
117
|
+
async getStats() {
|
|
118
|
+
this.ensureInitialized();
|
|
119
|
+
try {
|
|
120
|
+
const stmt = this.db.prepare(`
|
|
121
|
+
SELECT COUNT(*) as count, COALESCE(SUM(size), 0) as total_size
|
|
122
|
+
FROM blobs
|
|
123
|
+
`);
|
|
124
|
+
const row = stmt.get();
|
|
125
|
+
return {
|
|
126
|
+
lastUpdated: Date.now(),
|
|
127
|
+
totalBlobs: row.count,
|
|
128
|
+
totalSize: row.total_size,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw BlobError.retrievalError(`Failed to get storage stats: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Initialize storage by creating the database and running migrations
|
|
137
|
+
*/
|
|
138
|
+
async initialize() {
|
|
139
|
+
if (this.initialized) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
// Ensure storage directory exists (skip for in-memory)
|
|
144
|
+
if (!this.inMemory) {
|
|
145
|
+
await fs.mkdir(this.storageDir, { recursive: true });
|
|
146
|
+
}
|
|
147
|
+
// Open/create database (':memory:' for in-memory mode)
|
|
148
|
+
this.db = new Database(this.dbPath);
|
|
149
|
+
// Enable WAL mode for better concurrent performance
|
|
150
|
+
this.db.pragma('journal_mode = WAL');
|
|
151
|
+
// Run migrations to ensure schema is up-to-date
|
|
152
|
+
const { runMigrations } = await import('./migrations.js');
|
|
153
|
+
const appliedCount = runMigrations(this.db, this.logger);
|
|
154
|
+
if (appliedCount > 0) {
|
|
155
|
+
this.logger.info(`💾 Initializing storage...`);
|
|
156
|
+
}
|
|
157
|
+
this.initialized = true;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
throw BlobError.initializationError(`Failed to initialize SQLite storage: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* List all blob keys, optionally filtered by prefix
|
|
165
|
+
*/
|
|
166
|
+
async list(prefix) {
|
|
167
|
+
this.ensureInitialized();
|
|
168
|
+
try {
|
|
169
|
+
let stmt;
|
|
170
|
+
let rows;
|
|
171
|
+
if (prefix) {
|
|
172
|
+
stmt = this.db.prepare('SELECT key FROM blobs WHERE key LIKE ? ORDER BY key');
|
|
173
|
+
rows = stmt.all(`${prefix}%`);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
stmt = this.db.prepare('SELECT key FROM blobs ORDER BY key');
|
|
177
|
+
rows = stmt.all();
|
|
178
|
+
}
|
|
179
|
+
return rows.map((row) => row.key);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
throw BlobError.retrievalError(`Failed to list blobs: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Retrieve a blob by its key
|
|
187
|
+
*/
|
|
188
|
+
async retrieve(key) {
|
|
189
|
+
this.ensureInitialized();
|
|
190
|
+
this.validateKey(key);
|
|
191
|
+
try {
|
|
192
|
+
const stmt = this.db.prepare('SELECT * FROM blobs WHERE key = ?');
|
|
193
|
+
const row = stmt.get(key);
|
|
194
|
+
if (!row) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
content: row.content,
|
|
199
|
+
key: row.key,
|
|
200
|
+
metadata: this.rowToMetadata(row),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
throw BlobError.retrievalError(`Failed to retrieve blob ${key}: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Store a blob with optional metadata
|
|
209
|
+
*/
|
|
210
|
+
async store(key, content, metadata) {
|
|
211
|
+
this.ensureInitialized();
|
|
212
|
+
this.validateKey(key);
|
|
213
|
+
// Convert content to Buffer
|
|
214
|
+
const buffer = Buffer.isBuffer(content) ? content : Buffer.from(content);
|
|
215
|
+
// Check individual blob size
|
|
216
|
+
if (buffer.length > this.maxBlobSize) {
|
|
217
|
+
throw BlobError.tooLarge(buffer.length, this.maxBlobSize);
|
|
218
|
+
}
|
|
219
|
+
// Check total storage size
|
|
220
|
+
const stats = await this.getStats();
|
|
221
|
+
const existingBlob = await this.retrieve(key);
|
|
222
|
+
const existingSize = existingBlob?.metadata.size ?? 0;
|
|
223
|
+
const newTotalSize = stats.totalSize - existingSize + buffer.length;
|
|
224
|
+
if (newTotalSize > this.maxTotalSize) {
|
|
225
|
+
throw BlobError.totalSizeExceeded(stats.totalSize - existingSize, buffer.length, this.maxTotalSize);
|
|
226
|
+
}
|
|
227
|
+
const now = Date.now();
|
|
228
|
+
const fullMetadata = {
|
|
229
|
+
createdAt: existingBlob?.metadata.createdAt ?? now,
|
|
230
|
+
size: buffer.length,
|
|
231
|
+
updatedAt: now,
|
|
232
|
+
...metadata,
|
|
233
|
+
};
|
|
234
|
+
try {
|
|
235
|
+
const stmt = this.db.prepare(`
|
|
236
|
+
INSERT INTO blobs (key, content, content_type, original_name, size, tags, created_at, updated_at)
|
|
237
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
238
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
239
|
+
content = excluded.content,
|
|
240
|
+
content_type = excluded.content_type,
|
|
241
|
+
original_name = excluded.original_name,
|
|
242
|
+
size = excluded.size,
|
|
243
|
+
tags = excluded.tags,
|
|
244
|
+
updated_at = excluded.updated_at
|
|
245
|
+
`);
|
|
246
|
+
stmt.run(key, buffer, fullMetadata.contentType ?? null, fullMetadata.originalName ?? null, buffer.length, fullMetadata.tags ? JSON.stringify(fullMetadata.tags) : null, fullMetadata.createdAt, fullMetadata.updatedAt);
|
|
247
|
+
return {
|
|
248
|
+
content: buffer,
|
|
249
|
+
key,
|
|
250
|
+
metadata: fullMetadata,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
throw BlobError.storageError(`Failed to store blob ${key}: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Ensure storage has been initialized
|
|
259
|
+
*/
|
|
260
|
+
ensureInitialized() {
|
|
261
|
+
if (!this.initialized || !this.db) {
|
|
262
|
+
throw BlobError.notInitialized();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Convert database row to BlobMetadata
|
|
267
|
+
*/
|
|
268
|
+
rowToMetadata(row) {
|
|
269
|
+
const metadata = {
|
|
270
|
+
createdAt: row.created_at,
|
|
271
|
+
size: row.size,
|
|
272
|
+
updatedAt: row.updated_at,
|
|
273
|
+
};
|
|
274
|
+
if (row.content_type) {
|
|
275
|
+
metadata.contentType = row.content_type;
|
|
276
|
+
}
|
|
277
|
+
if (row.original_name) {
|
|
278
|
+
metadata.originalName = row.original_name;
|
|
279
|
+
}
|
|
280
|
+
if (row.tags) {
|
|
281
|
+
try {
|
|
282
|
+
metadata.tags = JSON.parse(row.tags);
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
// Ignore invalid JSON
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return metadata;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Validate blob key
|
|
292
|
+
* Keys must be alphanumeric with hyphens and underscores only
|
|
293
|
+
*/
|
|
294
|
+
validateKey(key) {
|
|
295
|
+
if (!key || typeof key !== 'string') {
|
|
296
|
+
throw BlobError.invalidKey(String(key), 'Key must be a non-empty string');
|
|
297
|
+
}
|
|
298
|
+
if (key.length === 0) {
|
|
299
|
+
throw BlobError.invalidKey(key, 'Key cannot be empty');
|
|
300
|
+
}
|
|
301
|
+
// Allow alphanumeric, hyphens, and underscores only
|
|
302
|
+
const validKeyRegex = /^[a-zA-Z0-9_-]+$/;
|
|
303
|
+
if (!validKeyRegex.test(key)) {
|
|
304
|
+
throw BlobError.invalidKey(key, 'Key must contain only alphanumeric characters, hyphens, and underscores');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { TerminationReason } from '../../core/domain/cipher/agent/agent-state.js';
|
|
2
|
+
import type { AgentExecutionState, AgentState } from '../../core/interfaces/cipher/i-cipher-agent.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manages the runtime state of the CipherAgent.
|
|
5
|
+
*
|
|
6
|
+
* Enhanced to track execution state, termination reasons, timing,
|
|
7
|
+
* and tool metrics following gemini-cli patterns. Maintains backward
|
|
8
|
+
* compatibility with legacy fields (executionHistory).
|
|
9
|
+
*/
|
|
10
|
+
export declare class CipherAgentStateManager {
|
|
11
|
+
private currentIteration;
|
|
12
|
+
private durationMs?;
|
|
13
|
+
private endTime?;
|
|
14
|
+
private executionHistory;
|
|
15
|
+
private executionState;
|
|
16
|
+
private startTime?;
|
|
17
|
+
private terminationReason?;
|
|
18
|
+
private toolCallsExecuted;
|
|
19
|
+
/**
|
|
20
|
+
* Add an execution record to history (legacy method).
|
|
21
|
+
* @param record - Execution record to add
|
|
22
|
+
*/
|
|
23
|
+
addExecutionRecord(record: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Mark execution as complete with reason.
|
|
26
|
+
* @param reason - Why execution terminated
|
|
27
|
+
*/
|
|
28
|
+
complete(reason: TerminationReason): void;
|
|
29
|
+
/**
|
|
30
|
+
* Mark execution as errored.
|
|
31
|
+
* @param reason - Error termination reason
|
|
32
|
+
*/
|
|
33
|
+
fail(reason: TerminationReason): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the current state.
|
|
36
|
+
* @returns Current agent state with all enhanced fields
|
|
37
|
+
*/
|
|
38
|
+
getState(): AgentState;
|
|
39
|
+
/**
|
|
40
|
+
* Increment the iteration counter.
|
|
41
|
+
* @returns The new iteration count
|
|
42
|
+
*/
|
|
43
|
+
incrementIteration(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Increment the tool calls counter.
|
|
46
|
+
* @returns The new tool calls count
|
|
47
|
+
*/
|
|
48
|
+
incrementToolCalls(): number;
|
|
49
|
+
/**
|
|
50
|
+
* Reset the state to initial values.
|
|
51
|
+
*/
|
|
52
|
+
reset(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Set the current execution state.
|
|
55
|
+
* @param state - New execution state
|
|
56
|
+
*/
|
|
57
|
+
setExecutionState(state: AgentExecutionState): void;
|
|
58
|
+
/**
|
|
59
|
+
* Start execution tracking.
|
|
60
|
+
* Sets startTime and transitions to executing state.
|
|
61
|
+
*/
|
|
62
|
+
startExecution(): void;
|
|
63
|
+
}
|