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,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncMutex - Simple asynchronous mutex for thread safety in parallel execution.
|
|
3
|
+
*
|
|
4
|
+
* Provides mutual exclusion for async operations, ensuring that only one
|
|
5
|
+
* operation can execute the critical section at a time. Uses a FIFO queue
|
|
6
|
+
* to ensure fairness among waiting operations.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const mutex = new AsyncMutex()
|
|
11
|
+
*
|
|
12
|
+
* // Option 1: Manual acquire/release
|
|
13
|
+
* await mutex.acquire()
|
|
14
|
+
* try {
|
|
15
|
+
* // Critical section
|
|
16
|
+
* } finally {
|
|
17
|
+
* mutex.release()
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Option 2: Using withLock (recommended)
|
|
21
|
+
* await mutex.withLock(async () => {
|
|
22
|
+
* // Critical section - automatically released
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class AsyncMutex {
|
|
27
|
+
locked = false;
|
|
28
|
+
queue = [];
|
|
29
|
+
/**
|
|
30
|
+
* Acquire the mutex lock.
|
|
31
|
+
* If the mutex is already locked, the caller will wait in a FIFO queue.
|
|
32
|
+
*
|
|
33
|
+
* @returns Promise that resolves when the lock is acquired
|
|
34
|
+
*/
|
|
35
|
+
async acquire() {
|
|
36
|
+
if (!this.locked) {
|
|
37
|
+
this.locked = true;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
this.queue.push(resolve);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the number of operations waiting for the lock.
|
|
46
|
+
*/
|
|
47
|
+
getQueueLength() {
|
|
48
|
+
return this.queue.length;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if the mutex is currently locked.
|
|
52
|
+
*/
|
|
53
|
+
isLocked() {
|
|
54
|
+
return this.locked;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Release the mutex lock.
|
|
58
|
+
* If there are waiting operations, the next one in the queue will be granted the lock.
|
|
59
|
+
*
|
|
60
|
+
* @throws Error if the mutex is not currently locked
|
|
61
|
+
*/
|
|
62
|
+
release() {
|
|
63
|
+
if (!this.locked) {
|
|
64
|
+
throw new Error('AsyncMutex: Cannot release a mutex that is not locked');
|
|
65
|
+
}
|
|
66
|
+
const next = this.queue.shift();
|
|
67
|
+
if (next) {
|
|
68
|
+
// Pass lock to next waiter (mutex stays locked)
|
|
69
|
+
next();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// No waiters, unlock
|
|
73
|
+
this.locked = false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Execute a function with the mutex lock held.
|
|
78
|
+
* The lock is automatically released when the function completes or throws.
|
|
79
|
+
*
|
|
80
|
+
* @param fn - Async function to execute with the lock held
|
|
81
|
+
* @returns The result of the function
|
|
82
|
+
*/
|
|
83
|
+
async withLock(fn) {
|
|
84
|
+
await this.acquire();
|
|
85
|
+
try {
|
|
86
|
+
return await fn();
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
this.release();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ITokenizer } from '../../../../../core/interfaces/cipher/i-tokenizer.js';
|
|
2
|
+
import type { InternalMessage } from '../../../../../core/interfaces/cipher/message-types.js';
|
|
3
|
+
import type { ICompressionStrategy } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for MiddleRemovalStrategy
|
|
6
|
+
*/
|
|
7
|
+
export interface MiddleRemovalOptions {
|
|
8
|
+
/** Number of messages to preserve at the end (default: 5) */
|
|
9
|
+
preserveEnd?: number;
|
|
10
|
+
/** Number of messages to preserve at the start (default: 4) */
|
|
11
|
+
preserveStart?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Middle Removal compression strategy.
|
|
15
|
+
*
|
|
16
|
+
* Preserves messages at the beginning (early context/setup) and end (recent conversation),
|
|
17
|
+
* removing messages from the middle section when compression is needed.
|
|
18
|
+
*
|
|
19
|
+
* This strategy is ideal for maintaining both:
|
|
20
|
+
* - Historical context (system instructions, initial setup)
|
|
21
|
+
* - Recent conversation flow (latest user/assistant exchanges)
|
|
22
|
+
*
|
|
23
|
+
* Algorithm:
|
|
24
|
+
* 1. Check if compression is needed
|
|
25
|
+
* 2. Identify the "middle" section (between preserved start and end)
|
|
26
|
+
* 3. Remove oldest messages from middle until token limit is met
|
|
27
|
+
* 4. Return compressed history with start and end intact
|
|
28
|
+
*
|
|
29
|
+
* Example with preserveStart=2, preserveEnd=2:
|
|
30
|
+
* Messages: [1, 2, 3, 4, 5, 6, 7, 8]
|
|
31
|
+
* Preserved: [1, 2] + [...] + [7, 8]
|
|
32
|
+
* Removable: [3, 4, 5, 6] (removed oldest-first if needed)
|
|
33
|
+
*/
|
|
34
|
+
export declare class MiddleRemovalStrategy implements ICompressionStrategy {
|
|
35
|
+
private readonly preserveEnd;
|
|
36
|
+
private readonly preserveStart;
|
|
37
|
+
constructor(options?: MiddleRemovalOptions);
|
|
38
|
+
compress(history: InternalMessage[], maxHistoryTokens: number, tokenizer: ITokenizer): Promise<InternalMessage[]>;
|
|
39
|
+
getName(): string;
|
|
40
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { countMessagesTokens } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Middle Removal compression strategy.
|
|
4
|
+
*
|
|
5
|
+
* Preserves messages at the beginning (early context/setup) and end (recent conversation),
|
|
6
|
+
* removing messages from the middle section when compression is needed.
|
|
7
|
+
*
|
|
8
|
+
* This strategy is ideal for maintaining both:
|
|
9
|
+
* - Historical context (system instructions, initial setup)
|
|
10
|
+
* - Recent conversation flow (latest user/assistant exchanges)
|
|
11
|
+
*
|
|
12
|
+
* Algorithm:
|
|
13
|
+
* 1. Check if compression is needed
|
|
14
|
+
* 2. Identify the "middle" section (between preserved start and end)
|
|
15
|
+
* 3. Remove oldest messages from middle until token limit is met
|
|
16
|
+
* 4. Return compressed history with start and end intact
|
|
17
|
+
*
|
|
18
|
+
* Example with preserveStart=2, preserveEnd=2:
|
|
19
|
+
* Messages: [1, 2, 3, 4, 5, 6, 7, 8]
|
|
20
|
+
* Preserved: [1, 2] + [...] + [7, 8]
|
|
21
|
+
* Removable: [3, 4, 5, 6] (removed oldest-first if needed)
|
|
22
|
+
*/
|
|
23
|
+
export class MiddleRemovalStrategy {
|
|
24
|
+
preserveEnd;
|
|
25
|
+
preserveStart;
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
this.preserveEnd = options.preserveEnd ?? 5;
|
|
28
|
+
this.preserveStart = options.preserveStart ?? 4;
|
|
29
|
+
// Debug logging removed for cleaner user experience
|
|
30
|
+
}
|
|
31
|
+
async compress(history, maxHistoryTokens, tokenizer) {
|
|
32
|
+
// Calculate initial token count
|
|
33
|
+
const initialTokenCount = countMessagesTokens(history, tokenizer);
|
|
34
|
+
// No compression needed - return unchanged
|
|
35
|
+
if (initialTokenCount <= maxHistoryTokens) {
|
|
36
|
+
// Debug logging removed for cleaner user experience
|
|
37
|
+
return history;
|
|
38
|
+
}
|
|
39
|
+
const totalMessages = history.length;
|
|
40
|
+
const removableIndices = [];
|
|
41
|
+
// Identify middle section that can be removed
|
|
42
|
+
// We need at least (preserveStart + preserveEnd) messages to apply this strategy
|
|
43
|
+
if (totalMessages > this.preserveStart + this.preserveEnd) {
|
|
44
|
+
for (let i = this.preserveStart; i < totalMessages - this.preserveEnd; i++) {
|
|
45
|
+
removableIndices.push(i);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// Not enough messages to apply strategy
|
|
50
|
+
console.warn(`MiddleRemovalStrategy: Cannot apply - only ${totalMessages} messages (need at least ${this.preserveStart + this.preserveEnd})`);
|
|
51
|
+
return history;
|
|
52
|
+
}
|
|
53
|
+
// Remove oldest messages from middle section until token limit is met
|
|
54
|
+
const removedIndices = new Set();
|
|
55
|
+
let currentTokenCount = initialTokenCount;
|
|
56
|
+
while (currentTokenCount > maxHistoryTokens && removableIndices.length > 0) {
|
|
57
|
+
// Remove oldest message from middle (shift from start of removableIndices)
|
|
58
|
+
const indexToRemove = removableIndices.shift();
|
|
59
|
+
if (indexToRemove === undefined) {
|
|
60
|
+
// This should never happen since we check length > 0, but be safe
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
removedIndices.add(indexToRemove);
|
|
64
|
+
// Recalculate tokens with current removals
|
|
65
|
+
const remaining = history.filter((_, i) => !removedIndices.has(i));
|
|
66
|
+
currentTokenCount = countMessagesTokens(remaining, tokenizer);
|
|
67
|
+
}
|
|
68
|
+
// Build final compressed history
|
|
69
|
+
const compressed = history.filter((_, i) => !removedIndices.has(i));
|
|
70
|
+
// Debug logging removed for cleaner user experience
|
|
71
|
+
return compressed;
|
|
72
|
+
}
|
|
73
|
+
getName() {
|
|
74
|
+
return 'MiddleRemoval';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ITokenizer } from '../../../../../core/interfaces/cipher/i-tokenizer.js';
|
|
2
|
+
import type { InternalMessage } from '../../../../../core/interfaces/cipher/message-types.js';
|
|
3
|
+
import type { ICompressionStrategy } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for OldestRemovalStrategy
|
|
6
|
+
*/
|
|
7
|
+
export interface OldestRemovalOptions {
|
|
8
|
+
/** Minimum number of recent messages to keep (default: 4) */
|
|
9
|
+
minMessagesToKeep?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Oldest Removal compression strategy.
|
|
13
|
+
*
|
|
14
|
+
* Simple FIFO (First-In-First-Out) strategy that removes the oldest messages first,
|
|
15
|
+
* preserving only recent conversation history.
|
|
16
|
+
*
|
|
17
|
+
* This strategy is ideal as a fallback after more sophisticated strategies have been
|
|
18
|
+
* applied. It ensures the most recent context is always preserved while older messages
|
|
19
|
+
* are removed to meet token limits.
|
|
20
|
+
*
|
|
21
|
+
* Algorithm:
|
|
22
|
+
* 1. Check if compression is needed
|
|
23
|
+
* 2. Remove oldest message (from start of array)
|
|
24
|
+
* 3. Recalculate token count
|
|
25
|
+
* 4. Repeat until token limit is met or minimum messages reached
|
|
26
|
+
* 5. Warn if still over limit (cannot compress further)
|
|
27
|
+
*
|
|
28
|
+
* Example with minMessagesToKeep=3:
|
|
29
|
+
* Messages: [1, 2, 3, 4, 5, 6, 7, 8]
|
|
30
|
+
* Remove: 1, then 2, then 3, then 4, then 5 (oldest-first)
|
|
31
|
+
* Result: [6, 7, 8] (stops at minimum 3 messages)
|
|
32
|
+
*/
|
|
33
|
+
export declare class OldestRemovalStrategy implements ICompressionStrategy {
|
|
34
|
+
private readonly minMessagesToKeep;
|
|
35
|
+
constructor(options?: OldestRemovalOptions);
|
|
36
|
+
compress(history: InternalMessage[], maxHistoryTokens: number, tokenizer: ITokenizer): Promise<InternalMessage[]>;
|
|
37
|
+
getName(): string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { countMessagesTokens } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Oldest Removal compression strategy.
|
|
4
|
+
*
|
|
5
|
+
* Simple FIFO (First-In-First-Out) strategy that removes the oldest messages first,
|
|
6
|
+
* preserving only recent conversation history.
|
|
7
|
+
*
|
|
8
|
+
* This strategy is ideal as a fallback after more sophisticated strategies have been
|
|
9
|
+
* applied. It ensures the most recent context is always preserved while older messages
|
|
10
|
+
* are removed to meet token limits.
|
|
11
|
+
*
|
|
12
|
+
* Algorithm:
|
|
13
|
+
* 1. Check if compression is needed
|
|
14
|
+
* 2. Remove oldest message (from start of array)
|
|
15
|
+
* 3. Recalculate token count
|
|
16
|
+
* 4. Repeat until token limit is met or minimum messages reached
|
|
17
|
+
* 5. Warn if still over limit (cannot compress further)
|
|
18
|
+
*
|
|
19
|
+
* Example with minMessagesToKeep=3:
|
|
20
|
+
* Messages: [1, 2, 3, 4, 5, 6, 7, 8]
|
|
21
|
+
* Remove: 1, then 2, then 3, then 4, then 5 (oldest-first)
|
|
22
|
+
* Result: [6, 7, 8] (stops at minimum 3 messages)
|
|
23
|
+
*/
|
|
24
|
+
export class OldestRemovalStrategy {
|
|
25
|
+
minMessagesToKeep;
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
this.minMessagesToKeep = options.minMessagesToKeep ?? 4;
|
|
28
|
+
// Debug logging removed for cleaner user experience
|
|
29
|
+
}
|
|
30
|
+
async compress(history, maxHistoryTokens, tokenizer) {
|
|
31
|
+
// Work with a copy to avoid mutating input
|
|
32
|
+
const currentHistory = [...history];
|
|
33
|
+
let currentTokenCount = countMessagesTokens(currentHistory, tokenizer);
|
|
34
|
+
// Remove oldest messages until token limit met or minimum reached
|
|
35
|
+
while (currentHistory.length > this.minMessagesToKeep &&
|
|
36
|
+
currentTokenCount > maxHistoryTokens) {
|
|
37
|
+
// Remove oldest message (from start)
|
|
38
|
+
currentHistory.shift();
|
|
39
|
+
// Recalculate token count
|
|
40
|
+
currentTokenCount = countMessagesTokens(currentHistory, tokenizer);
|
|
41
|
+
}
|
|
42
|
+
// Warn if still over limit after reaching minimum
|
|
43
|
+
if (currentTokenCount > maxHistoryTokens) {
|
|
44
|
+
// Keep warning as it's important
|
|
45
|
+
console.warn(`OldestRemovalStrategy: Cannot compress further - at minimum ${this.minMessagesToKeep} messages (${currentTokenCount} tokens > ${maxHistoryTokens} limit)`);
|
|
46
|
+
}
|
|
47
|
+
// Debug logging removed for cleaner user experience
|
|
48
|
+
return currentHistory;
|
|
49
|
+
}
|
|
50
|
+
getName() {
|
|
51
|
+
return 'OldestRemoval';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ITokenizer } from '../../../../../core/interfaces/cipher/i-tokenizer.js';
|
|
2
|
+
import type { InternalMessage } from '../../../../../core/interfaces/cipher/message-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for compression strategies
|
|
5
|
+
*/
|
|
6
|
+
export interface CompressionStrategyOptions {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Interface for context compression strategies.
|
|
11
|
+
* Strategies remove messages from history to fit within token limits.
|
|
12
|
+
*
|
|
13
|
+
* Compression strategies are applied sequentially by the ContextManager
|
|
14
|
+
* until the token limit is satisfied. Each strategy can implement different
|
|
15
|
+
* algorithms for deciding which messages to remove.
|
|
16
|
+
*
|
|
17
|
+
* Common strategies:
|
|
18
|
+
* - MiddleRemoval: Preserves early context and recent messages, removes from middle
|
|
19
|
+
* - OldestRemoval: Simple FIFO, keeps only recent messages
|
|
20
|
+
*/
|
|
21
|
+
export interface ICompressionStrategy {
|
|
22
|
+
/**
|
|
23
|
+
* Compress message history to fit within token limit
|
|
24
|
+
*
|
|
25
|
+
* @param history - Full message history to compress
|
|
26
|
+
* @param maxHistoryTokens - Maximum tokens allowed for history (excluding system prompt)
|
|
27
|
+
* @param tokenizer - Tokenizer for counting tokens
|
|
28
|
+
* @returns Compressed message history
|
|
29
|
+
*/
|
|
30
|
+
compress(history: InternalMessage[], maxHistoryTokens: number, tokenizer: ITokenizer): Promise<InternalMessage[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Human-readable name of the strategy
|
|
33
|
+
* Used for logging and debugging
|
|
34
|
+
*/
|
|
35
|
+
getName(): string;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { IHistoryStorage } from '../../../../core/interfaces/cipher/i-history-storage.js';
|
|
2
|
+
import type { ILogger } from '../../../../core/interfaces/cipher/i-logger.js';
|
|
3
|
+
import type { IMessageFormatter } from '../../../../core/interfaces/cipher/i-message-formatter.js';
|
|
4
|
+
import type { ITokenizer } from '../../../../core/interfaces/cipher/i-tokenizer.js';
|
|
5
|
+
import type { InternalMessage } from '../../../../core/interfaces/cipher/message-types.js';
|
|
6
|
+
import type { ICompressionStrategy } from './compression/types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Image data for messages
|
|
9
|
+
*/
|
|
10
|
+
export interface ImageData {
|
|
11
|
+
data: ArrayBuffer | Buffer | string | Uint8Array | URL;
|
|
12
|
+
mimeType?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* File data for messages
|
|
16
|
+
*/
|
|
17
|
+
export interface FileData {
|
|
18
|
+
data: ArrayBuffer | Buffer | string | Uint8Array | URL;
|
|
19
|
+
filename?: string;
|
|
20
|
+
mimeType: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Result of message formatting with compression
|
|
24
|
+
*/
|
|
25
|
+
export interface FormattedMessagesResult<T> {
|
|
26
|
+
formattedMessages: T[];
|
|
27
|
+
/** Number of messages filtered out as invalid */
|
|
28
|
+
messagesFiltered: number;
|
|
29
|
+
systemPrompt?: string;
|
|
30
|
+
tokensUsed: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reason why a message was considered invalid for API inclusion.
|
|
34
|
+
*/
|
|
35
|
+
export type MessageInvalidReason = 'empty_content' | 'incomplete_tool_call' | 'system_noise';
|
|
36
|
+
/**
|
|
37
|
+
* Result of message validation check.
|
|
38
|
+
*/
|
|
39
|
+
export interface MessageValidation {
|
|
40
|
+
/** Whether the message is valid for API inclusion */
|
|
41
|
+
isValid: boolean;
|
|
42
|
+
/** Reason if invalid */
|
|
43
|
+
reason?: MessageInvalidReason;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Configuration options for ContextManager
|
|
47
|
+
*/
|
|
48
|
+
export interface ContextManagerOptions<T> {
|
|
49
|
+
compressionStrategies?: ICompressionStrategy[];
|
|
50
|
+
formatter: IMessageFormatter<T>;
|
|
51
|
+
historyStorage?: IHistoryStorage;
|
|
52
|
+
logger?: ILogger;
|
|
53
|
+
maxInputTokens: number;
|
|
54
|
+
sessionId: string;
|
|
55
|
+
tokenizer: ITokenizer;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Context Manager for managing conversation history.
|
|
59
|
+
*
|
|
60
|
+
* Responsibilities:
|
|
61
|
+
* - Store and manage internal message history
|
|
62
|
+
* - Format messages for specific LLM providers
|
|
63
|
+
* - Handle message compression (future)
|
|
64
|
+
* - Count tokens for context management
|
|
65
|
+
*
|
|
66
|
+
* Generic type T represents the provider-specific message format
|
|
67
|
+
* (e.g., GeminiContent for Gemini, MessageParam for Anthropic)
|
|
68
|
+
*/
|
|
69
|
+
export declare class ContextManager<T> {
|
|
70
|
+
private readonly compressionStrategies;
|
|
71
|
+
private readonly formatter;
|
|
72
|
+
private readonly historyStorage?;
|
|
73
|
+
private isInitialized;
|
|
74
|
+
private readonly logger;
|
|
75
|
+
private readonly maxInputTokens;
|
|
76
|
+
private messages;
|
|
77
|
+
/**
|
|
78
|
+
* Mutex for thread-safe operations on messages array.
|
|
79
|
+
* Used during parallel tool execution to prevent race conditions.
|
|
80
|
+
*/
|
|
81
|
+
private readonly mutex;
|
|
82
|
+
private readonly sessionId;
|
|
83
|
+
private readonly tokenizer;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new context manager
|
|
86
|
+
*
|
|
87
|
+
* @param options - Configuration options
|
|
88
|
+
* @param options.sessionId - Unique session identifier
|
|
89
|
+
* @param options.formatter - Message formatter for provider-specific format
|
|
90
|
+
* @param options.tokenizer - Token counter for the model
|
|
91
|
+
* @param options.maxInputTokens - Maximum input tokens allowed
|
|
92
|
+
* @param options.historyStorage - Optional history storage for persistence
|
|
93
|
+
* @param options.compressionStrategies - Optional compression strategies (defaults to MiddleRemoval + OldestRemoval)
|
|
94
|
+
*/
|
|
95
|
+
constructor(options: ContextManagerOptions<T>);
|
|
96
|
+
/**
|
|
97
|
+
* Add an assistant message to the conversation.
|
|
98
|
+
*
|
|
99
|
+
* @param content - Message content (text or null if only tool calls)
|
|
100
|
+
* @param toolCalls - Optional tool calls made by the assistant
|
|
101
|
+
*/
|
|
102
|
+
addAssistantMessage(content: null | string, toolCalls?: InternalMessage['toolCalls']): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Add a system message to the conversation.
|
|
105
|
+
*
|
|
106
|
+
* @param content - System message content
|
|
107
|
+
*/
|
|
108
|
+
addSystemMessage(content: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Add a tool result message to the conversation.
|
|
111
|
+
* Thread-safe: Uses mutex to protect shared state during parallel tool execution.
|
|
112
|
+
*
|
|
113
|
+
* @param toolCallId - ID of the tool call this result responds to
|
|
114
|
+
* @param toolName - Name of the tool that was executed
|
|
115
|
+
* @param result - Result from tool execution
|
|
116
|
+
* @param _metadata - Additional metadata (success status, error type, execution metadata)
|
|
117
|
+
* @param _metadata.success - Whether the tool execution succeeded
|
|
118
|
+
* @param _metadata.errorType - Classified error type (if failed)
|
|
119
|
+
* @param _metadata.metadata - Execution metadata (duration, tokens, etc.)
|
|
120
|
+
* @returns The content that was added
|
|
121
|
+
*/
|
|
122
|
+
addToolResult(toolCallId: string, toolName: string, result: unknown, _metadata: {
|
|
123
|
+
errorType?: string;
|
|
124
|
+
metadata?: Record<string, unknown>;
|
|
125
|
+
success: boolean;
|
|
126
|
+
}): Promise<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Add a user message to the conversation.
|
|
129
|
+
*
|
|
130
|
+
* @param content - User message text
|
|
131
|
+
* @param _imageData - Optional image data (not yet implemented)
|
|
132
|
+
* @param _fileData - Optional file data (not yet implemented)
|
|
133
|
+
*/
|
|
134
|
+
addUserMessage(content: string, _imageData?: ImageData, _fileData?: FileData): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Clear all messages from the conversation history.
|
|
137
|
+
* Also clears persisted history if storage is enabled.
|
|
138
|
+
*/
|
|
139
|
+
clearHistory(): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Get comprehensive messages (all messages, for persistence/debugging).
|
|
142
|
+
* This includes all messages including invalid ones.
|
|
143
|
+
*
|
|
144
|
+
* @returns All messages in the conversation history
|
|
145
|
+
*/
|
|
146
|
+
getComprehensiveMessages(): InternalMessage[];
|
|
147
|
+
/**
|
|
148
|
+
* Get curated messages (valid messages only, for API calls).
|
|
149
|
+
* Filters out invalid messages that would waste tokens or confuse the LLM.
|
|
150
|
+
*
|
|
151
|
+
* @returns Only valid messages suitable for API calls
|
|
152
|
+
*/
|
|
153
|
+
getCuratedMessages(): InternalMessage[];
|
|
154
|
+
/**
|
|
155
|
+
* Get formatted messages with compression applied.
|
|
156
|
+
* Uses curated (valid-only) messages for better LLM context quality.
|
|
157
|
+
*
|
|
158
|
+
* @param systemPrompt - Optional system prompt (for token accounting)
|
|
159
|
+
* @returns Formatted messages, system prompt, token count, and filter stats
|
|
160
|
+
*/
|
|
161
|
+
getFormattedMessagesWithCompression(systemPrompt?: string): Promise<FormattedMessagesResult<T>>;
|
|
162
|
+
/**
|
|
163
|
+
* Get the maximum input tokens allowed.
|
|
164
|
+
*/
|
|
165
|
+
getMaxInputTokens(): number;
|
|
166
|
+
/**
|
|
167
|
+
* Get all messages in the conversation.
|
|
168
|
+
*/
|
|
169
|
+
getMessages(): InternalMessage[];
|
|
170
|
+
/**
|
|
171
|
+
* Get the session ID.
|
|
172
|
+
*/
|
|
173
|
+
getSessionId(): string;
|
|
174
|
+
/**
|
|
175
|
+
* Initialize the context manager by loading persisted history.
|
|
176
|
+
* Should be called after construction to restore previous conversation.
|
|
177
|
+
*
|
|
178
|
+
* @returns True if history was loaded, false otherwise
|
|
179
|
+
*/
|
|
180
|
+
initialize(): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Compress conversation history if needed to fit within token limits.
|
|
183
|
+
*
|
|
184
|
+
* This method applies compression strategies sequentially until the history
|
|
185
|
+
* fits within the available token budget (maxInputTokens - systemPromptTokens).
|
|
186
|
+
*
|
|
187
|
+
* @param systemPromptTokens - Tokens used by system prompt (reserved, not compressible)
|
|
188
|
+
* @param messagesToCompress - Messages to compress (defaults to all messages)
|
|
189
|
+
* @returns Compressed message history
|
|
190
|
+
*/
|
|
191
|
+
private compressHistoryIfNeeded;
|
|
192
|
+
/**
|
|
193
|
+
* Count tokens in formatted messages.
|
|
194
|
+
*
|
|
195
|
+
* @param _formattedMessages - Messages in provider-specific format
|
|
196
|
+
* @returns Token count
|
|
197
|
+
*/
|
|
198
|
+
private countTokens;
|
|
199
|
+
/**
|
|
200
|
+
* Check if a system message is noise (empty or whitespace only).
|
|
201
|
+
*
|
|
202
|
+
* @param message - Message to check
|
|
203
|
+
* @returns True if the message is noise
|
|
204
|
+
*/
|
|
205
|
+
private isSystemNoise;
|
|
206
|
+
/**
|
|
207
|
+
* Persist current conversation history to storage.
|
|
208
|
+
* This is called automatically after each message is added.
|
|
209
|
+
*
|
|
210
|
+
* @returns Promise that resolves when history is persisted
|
|
211
|
+
*/
|
|
212
|
+
private persistHistory;
|
|
213
|
+
/**
|
|
214
|
+
* Sanitize tool result for storage.
|
|
215
|
+
* Handles large outputs, binary data, circular references, etc.
|
|
216
|
+
*
|
|
217
|
+
* @param result - Raw tool result
|
|
218
|
+
* @returns Sanitized string representation
|
|
219
|
+
*/
|
|
220
|
+
private sanitizeToolResult;
|
|
221
|
+
/**
|
|
222
|
+
* Validate a message for API inclusion.
|
|
223
|
+
* Filters out invalid messages that would waste tokens or confuse the LLM.
|
|
224
|
+
*
|
|
225
|
+
* Rules:
|
|
226
|
+
* 1. Empty content (non-tool messages without content or tool calls)
|
|
227
|
+
* 2. Tool result without corresponding tool call ID
|
|
228
|
+
* 3. System messages with only noise (empty or whitespace)
|
|
229
|
+
*
|
|
230
|
+
* @param message - Message to validate
|
|
231
|
+
* @returns Validation result indicating if message is valid for API
|
|
232
|
+
*/
|
|
233
|
+
private validateMessage;
|
|
234
|
+
}
|