byterover-cli 0.2.1 → 0.3.1
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 +63 -3
- package/dist/commands/init.js +285 -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,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response Validation Layer
|
|
3
|
+
*
|
|
4
|
+
* Validates LLM responses before processing to catch malformed content.
|
|
5
|
+
* Pure validation only - retry logic is handled by RetryableContentGenerator.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when response validation fails
|
|
9
|
+
*/
|
|
10
|
+
export class ResponseValidationError extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Original response that failed validation (for debugging)
|
|
13
|
+
*/
|
|
14
|
+
originalResponse;
|
|
15
|
+
/**
|
|
16
|
+
* Type of validation failure
|
|
17
|
+
*/
|
|
18
|
+
validationType;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new ResponseValidationError
|
|
21
|
+
*
|
|
22
|
+
* @param message - Human-readable error message
|
|
23
|
+
* @param validationType - Type of validation failure
|
|
24
|
+
* @param originalResponse - Original response object (optional)
|
|
25
|
+
*/
|
|
26
|
+
constructor(message, validationType, originalResponse) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = 'ResponseValidationError';
|
|
29
|
+
this.validationType = validationType;
|
|
30
|
+
this.originalResponse = originalResponse;
|
|
31
|
+
// Maintain proper stack trace
|
|
32
|
+
if (Error.captureStackTrace) {
|
|
33
|
+
Error.captureStackTrace(this, ResponseValidationError);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Convert error to JSON for serialization
|
|
38
|
+
*/
|
|
39
|
+
toJSON() {
|
|
40
|
+
return {
|
|
41
|
+
message: this.message,
|
|
42
|
+
name: this.name,
|
|
43
|
+
validationType: this.validationType,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Response validator with validation rules and helper methods.
|
|
49
|
+
*
|
|
50
|
+
* Pure validation only - no retry logic.
|
|
51
|
+
* Retry behavior is handled by RetryableContentGenerator decorator.
|
|
52
|
+
*/
|
|
53
|
+
export const ResponseValidator = {
|
|
54
|
+
/**
|
|
55
|
+
* Validate individual message structure
|
|
56
|
+
*
|
|
57
|
+
* Checks that message has:
|
|
58
|
+
* 1. Valid role (assistant)
|
|
59
|
+
* 2. Either content or tool calls
|
|
60
|
+
* 3. Well-formed tool calls (if present)
|
|
61
|
+
*
|
|
62
|
+
* @param message - Internal message to validate
|
|
63
|
+
* @throws ResponseValidationError if validation fails
|
|
64
|
+
*/
|
|
65
|
+
validateMessage(message) {
|
|
66
|
+
// Validate role
|
|
67
|
+
if (!message.role) {
|
|
68
|
+
throw new ResponseValidationError('Message missing role', 'INVALID_ROLE', message);
|
|
69
|
+
}
|
|
70
|
+
if (message.role !== 'assistant') {
|
|
71
|
+
throw new ResponseValidationError(`Invalid role for LLM response: ${message.role} (expected 'assistant')`, 'INVALID_ROLE', message);
|
|
72
|
+
}
|
|
73
|
+
// Validate has content or tool calls
|
|
74
|
+
const hasContent = message.content && ((typeof message.content === 'string' && message.content.length > 0) ||
|
|
75
|
+
(Array.isArray(message.content) && message.content.length > 0));
|
|
76
|
+
const hasToolCalls = message.toolCalls && message.toolCalls.length > 0;
|
|
77
|
+
if (!hasContent && !hasToolCalls) {
|
|
78
|
+
throw new ResponseValidationError('Message has neither content nor tool calls', 'NO_CONTENT', message);
|
|
79
|
+
}
|
|
80
|
+
// Validate tool calls if present
|
|
81
|
+
if (hasToolCalls && message.toolCalls) {
|
|
82
|
+
for (const toolCall of message.toolCalls) {
|
|
83
|
+
if (!toolCall.id) {
|
|
84
|
+
throw new ResponseValidationError('Tool call missing id', 'MALFORMED_TOOL_CALL', toolCall);
|
|
85
|
+
}
|
|
86
|
+
if (!toolCall.function?.name) {
|
|
87
|
+
throw new ResponseValidationError('Tool call missing function name', 'MALFORMED_TOOL_CALL', toolCall);
|
|
88
|
+
}
|
|
89
|
+
// Validate arguments is valid JSON string
|
|
90
|
+
if (toolCall.function.arguments) {
|
|
91
|
+
try {
|
|
92
|
+
JSON.parse(toolCall.function.arguments);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new ResponseValidationError(`Tool call has invalid JSON arguments: ${toolCall.function.arguments}`, 'MALFORMED_TOOL_CALL', toolCall);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* Validate parsed message array
|
|
103
|
+
*
|
|
104
|
+
* Checks that:
|
|
105
|
+
* 1. Array is not empty
|
|
106
|
+
* 2. Has at least one message
|
|
107
|
+
*
|
|
108
|
+
* @param messages - Parsed messages from formatter
|
|
109
|
+
* @throws ResponseValidationError if validation fails
|
|
110
|
+
*/
|
|
111
|
+
validateMessageArray(messages) {
|
|
112
|
+
// Check has messages
|
|
113
|
+
if (!Array.isArray(messages) || messages.length === 0) {
|
|
114
|
+
throw new ResponseValidationError('Response contains no messages', 'NO_MESSAGES', messages);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* Validate raw response from LLM provider
|
|
119
|
+
*
|
|
120
|
+
* Checks that response is:
|
|
121
|
+
* 1. Not null/undefined
|
|
122
|
+
* 2. An object
|
|
123
|
+
*
|
|
124
|
+
* @param response - Raw response from provider
|
|
125
|
+
* @throws ResponseValidationError if validation fails
|
|
126
|
+
*/
|
|
127
|
+
validateRawResponse(response) {
|
|
128
|
+
// Check response exists
|
|
129
|
+
if (response === null || response === undefined) {
|
|
130
|
+
throw new ResponseValidationError('Response is null or undefined', 'EMPTY_RESPONSE', response);
|
|
131
|
+
}
|
|
132
|
+
// Check response is an object
|
|
133
|
+
if (typeof response !== 'object') {
|
|
134
|
+
throw new ResponseValidationError(`Response is not an object: ${typeof response}`, 'EMPTY_RESPONSE', response);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
/**
|
|
138
|
+
* Validate complete response after parsing
|
|
139
|
+
*
|
|
140
|
+
* Runs all validation checks on raw response, message array, and last message.
|
|
141
|
+
*
|
|
142
|
+
* @param response - Raw response from provider
|
|
143
|
+
* @param messages - Parsed messages from formatter
|
|
144
|
+
* @returns Last message if all validations pass
|
|
145
|
+
* @throws ResponseValidationError if any validation fails
|
|
146
|
+
*/
|
|
147
|
+
validateResponse(response, messages) {
|
|
148
|
+
// Validate raw response
|
|
149
|
+
this.validateRawResponse(response);
|
|
150
|
+
// Validate message array
|
|
151
|
+
this.validateMessageArray(messages);
|
|
152
|
+
// Get and validate last message
|
|
153
|
+
const lastMessage = messages.at(-1);
|
|
154
|
+
this.validateMessage(lastMessage);
|
|
155
|
+
return lastMessage;
|
|
156
|
+
},
|
|
157
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry exports.
|
|
3
|
+
*
|
|
4
|
+
* This module provides retry utilities for LLM operations:
|
|
5
|
+
* - RetryPolicy: Configuration interface and presets
|
|
6
|
+
* - withRetry: Generic retry utility with backoff
|
|
7
|
+
* - RetryableContentGenerator: Decorator for IContentGenerator
|
|
8
|
+
*/
|
|
9
|
+
export { AGGRESSIVE_RETRY_POLICY, calculateRetryDelay, createRetryPolicy, DEFAULT_RETRY_POLICY, isRetryableError, MINIMAL_RETRY_POLICY, NO_RETRY_POLICY, type RetryPolicy, } from './retry-policy.js';
|
|
10
|
+
export { makeRetryable, type RetryContext, type RetryOptions, type RetryResult, withRetry, withRetryResult, } from './retry-with-backoff.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry exports.
|
|
3
|
+
*
|
|
4
|
+
* This module provides retry utilities for LLM operations:
|
|
5
|
+
* - RetryPolicy: Configuration interface and presets
|
|
6
|
+
* - withRetry: Generic retry utility with backoff
|
|
7
|
+
* - RetryableContentGenerator: Decorator for IContentGenerator
|
|
8
|
+
*/
|
|
9
|
+
export { AGGRESSIVE_RETRY_POLICY, calculateRetryDelay, createRetryPolicy, DEFAULT_RETRY_POLICY, isRetryableError, MINIMAL_RETRY_POLICY, NO_RETRY_POLICY, } from './retry-policy.js';
|
|
10
|
+
export { makeRetryable, withRetry, withRetryResult, } from './retry-with-backoff.js';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry Policy Configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines retry behavior for LLM operations with exponential backoff.
|
|
5
|
+
* Based on patterns from gemini-cli for consistent retry handling.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for retry behavior.
|
|
9
|
+
*/
|
|
10
|
+
export interface RetryPolicy {
|
|
11
|
+
/** Multiplier for exponential backoff (e.g., 2 = double delay each time) */
|
|
12
|
+
backoffMultiplier: number;
|
|
13
|
+
/** Base delay in milliseconds before first retry */
|
|
14
|
+
baseDelayMs: number;
|
|
15
|
+
/** Jitter factor (0-1) to randomize delays and prevent thundering herd */
|
|
16
|
+
jitterFactor: number;
|
|
17
|
+
/** Maximum delay in milliseconds between retries */
|
|
18
|
+
maxDelayMs: number;
|
|
19
|
+
/** Maximum number of retry attempts (0 = no retries) */
|
|
20
|
+
maxRetries: number;
|
|
21
|
+
/** Error types/messages that should trigger a retry */
|
|
22
|
+
retryableErrors: string[];
|
|
23
|
+
/** HTTP status codes that should trigger a retry */
|
|
24
|
+
retryableStatusCodes: number[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Default retry policy with sensible defaults.
|
|
28
|
+
*
|
|
29
|
+
* - 3 retry attempts
|
|
30
|
+
* - Starting at 1 second, max 30 seconds
|
|
31
|
+
* - 2x exponential backoff
|
|
32
|
+
* - 25% jitter
|
|
33
|
+
* - Retries on common transient errors (429, 500, 502, 503, 504)
|
|
34
|
+
*/
|
|
35
|
+
export declare const DEFAULT_RETRY_POLICY: RetryPolicy;
|
|
36
|
+
/**
|
|
37
|
+
* Aggressive retry policy for critical operations.
|
|
38
|
+
*
|
|
39
|
+
* More retries with longer delays for operations that must succeed.
|
|
40
|
+
*/
|
|
41
|
+
export declare const AGGRESSIVE_RETRY_POLICY: RetryPolicy;
|
|
42
|
+
/**
|
|
43
|
+
* Minimal retry policy for fast-fail scenarios.
|
|
44
|
+
*
|
|
45
|
+
* Single retry with short delay when quick feedback is preferred.
|
|
46
|
+
*/
|
|
47
|
+
export declare const MINIMAL_RETRY_POLICY: RetryPolicy;
|
|
48
|
+
/**
|
|
49
|
+
* No retry policy - fail immediately on any error.
|
|
50
|
+
*/
|
|
51
|
+
export declare const NO_RETRY_POLICY: RetryPolicy;
|
|
52
|
+
/**
|
|
53
|
+
* Create a custom retry policy by merging with defaults.
|
|
54
|
+
*
|
|
55
|
+
* @param overrides - Partial policy to override defaults
|
|
56
|
+
* @returns Complete retry policy
|
|
57
|
+
*/
|
|
58
|
+
export declare function createRetryPolicy(overrides: Partial<RetryPolicy>): RetryPolicy;
|
|
59
|
+
/**
|
|
60
|
+
* Check if an error should be retried based on the policy.
|
|
61
|
+
*
|
|
62
|
+
* @param error - The error to check
|
|
63
|
+
* @param policy - The retry policy to use
|
|
64
|
+
* @returns True if the error is retryable
|
|
65
|
+
*/
|
|
66
|
+
export declare function isRetryableError(error: unknown, policy: RetryPolicy): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Calculate delay for a specific retry attempt with exponential backoff and jitter.
|
|
69
|
+
*
|
|
70
|
+
* @param attempt - Current retry attempt (1-based)
|
|
71
|
+
* @param policy - The retry policy to use
|
|
72
|
+
* @returns Delay in milliseconds
|
|
73
|
+
*/
|
|
74
|
+
export declare function calculateRetryDelay(attempt: number, policy: RetryPolicy): number;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry Policy Configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines retry behavior for LLM operations with exponential backoff.
|
|
5
|
+
* Based on patterns from gemini-cli for consistent retry handling.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Default retry policy with sensible defaults.
|
|
9
|
+
*
|
|
10
|
+
* - 3 retry attempts
|
|
11
|
+
* - Starting at 1 second, max 30 seconds
|
|
12
|
+
* - 2x exponential backoff
|
|
13
|
+
* - 25% jitter
|
|
14
|
+
* - Retries on common transient errors (429, 500, 502, 503, 504)
|
|
15
|
+
*/
|
|
16
|
+
export const DEFAULT_RETRY_POLICY = {
|
|
17
|
+
backoffMultiplier: 2,
|
|
18
|
+
baseDelayMs: 1000,
|
|
19
|
+
jitterFactor: 0.25,
|
|
20
|
+
maxDelayMs: 30_000,
|
|
21
|
+
maxRetries: 3,
|
|
22
|
+
retryableErrors: [
|
|
23
|
+
'ECONNRESET',
|
|
24
|
+
'ETIMEDOUT',
|
|
25
|
+
'ECONNREFUSED',
|
|
26
|
+
'ENOTFOUND',
|
|
27
|
+
'rate_limit',
|
|
28
|
+
'overloaded',
|
|
29
|
+
'capacity',
|
|
30
|
+
'timeout',
|
|
31
|
+
'temporarily unavailable',
|
|
32
|
+
],
|
|
33
|
+
retryableStatusCodes: [429, 500, 502, 503, 504],
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Aggressive retry policy for critical operations.
|
|
37
|
+
*
|
|
38
|
+
* More retries with longer delays for operations that must succeed.
|
|
39
|
+
*/
|
|
40
|
+
export const AGGRESSIVE_RETRY_POLICY = {
|
|
41
|
+
backoffMultiplier: 2,
|
|
42
|
+
baseDelayMs: 2000,
|
|
43
|
+
jitterFactor: 0.3,
|
|
44
|
+
maxDelayMs: 60_000,
|
|
45
|
+
maxRetries: 5,
|
|
46
|
+
retryableErrors: [
|
|
47
|
+
'ECONNRESET',
|
|
48
|
+
'ETIMEDOUT',
|
|
49
|
+
'ECONNREFUSED',
|
|
50
|
+
'ENOTFOUND',
|
|
51
|
+
'rate_limit',
|
|
52
|
+
'overloaded',
|
|
53
|
+
'capacity',
|
|
54
|
+
'timeout',
|
|
55
|
+
'temporarily unavailable',
|
|
56
|
+
],
|
|
57
|
+
retryableStatusCodes: [429, 500, 502, 503, 504],
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Minimal retry policy for fast-fail scenarios.
|
|
61
|
+
*
|
|
62
|
+
* Single retry with short delay when quick feedback is preferred.
|
|
63
|
+
*/
|
|
64
|
+
export const MINIMAL_RETRY_POLICY = {
|
|
65
|
+
backoffMultiplier: 2,
|
|
66
|
+
baseDelayMs: 500,
|
|
67
|
+
jitterFactor: 0.1,
|
|
68
|
+
maxDelayMs: 2000,
|
|
69
|
+
maxRetries: 1,
|
|
70
|
+
retryableErrors: ['rate_limit', 'overloaded'],
|
|
71
|
+
retryableStatusCodes: [429, 503],
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* No retry policy - fail immediately on any error.
|
|
75
|
+
*/
|
|
76
|
+
export const NO_RETRY_POLICY = {
|
|
77
|
+
backoffMultiplier: 1,
|
|
78
|
+
baseDelayMs: 0,
|
|
79
|
+
jitterFactor: 0,
|
|
80
|
+
maxDelayMs: 0,
|
|
81
|
+
maxRetries: 0,
|
|
82
|
+
retryableErrors: [],
|
|
83
|
+
retryableStatusCodes: [],
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Create a custom retry policy by merging with defaults.
|
|
87
|
+
*
|
|
88
|
+
* @param overrides - Partial policy to override defaults
|
|
89
|
+
* @returns Complete retry policy
|
|
90
|
+
*/
|
|
91
|
+
export function createRetryPolicy(overrides) {
|
|
92
|
+
return {
|
|
93
|
+
...DEFAULT_RETRY_POLICY,
|
|
94
|
+
...overrides,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if an error should be retried based on the policy.
|
|
99
|
+
*
|
|
100
|
+
* @param error - The error to check
|
|
101
|
+
* @param policy - The retry policy to use
|
|
102
|
+
* @returns True if the error is retryable
|
|
103
|
+
*/
|
|
104
|
+
export function isRetryableError(error, policy) {
|
|
105
|
+
// Check if we have any retry configuration
|
|
106
|
+
if (policy.maxRetries === 0) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
// Handle HTTP-like errors with status codes
|
|
110
|
+
if (error && typeof error === 'object') {
|
|
111
|
+
const errorObj = error;
|
|
112
|
+
// Check status code
|
|
113
|
+
const status = errorObj.status ?? errorObj.statusCode ?? errorObj.code;
|
|
114
|
+
if (typeof status === 'number' && policy.retryableStatusCodes.includes(status)) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
// Check for gRPC status codes (common transient errors)
|
|
118
|
+
const grpcCode = errorObj.code;
|
|
119
|
+
// gRPC codes: 14 = UNAVAILABLE, 8 = RESOURCE_EXHAUSTED, 4 = DEADLINE_EXCEEDED
|
|
120
|
+
if (typeof grpcCode === 'number' && [4, 8, 14].includes(grpcCode)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Check error message against retryable patterns
|
|
125
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
126
|
+
const lowerMessage = errorMessage.toLowerCase();
|
|
127
|
+
return policy.retryableErrors.some((pattern) => lowerMessage.includes(pattern.toLowerCase()));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Calculate delay for a specific retry attempt with exponential backoff and jitter.
|
|
131
|
+
*
|
|
132
|
+
* @param attempt - Current retry attempt (1-based)
|
|
133
|
+
* @param policy - The retry policy to use
|
|
134
|
+
* @returns Delay in milliseconds
|
|
135
|
+
*/
|
|
136
|
+
export function calculateRetryDelay(attempt, policy) {
|
|
137
|
+
// Calculate base exponential delay
|
|
138
|
+
const exponentialDelay = policy.baseDelayMs * policy.backoffMultiplier ** (attempt - 1);
|
|
139
|
+
// Cap at max delay
|
|
140
|
+
const cappedDelay = Math.min(exponentialDelay, policy.maxDelayMs);
|
|
141
|
+
// Apply jitter (randomize within jitter factor range)
|
|
142
|
+
const jitterRange = cappedDelay * policy.jitterFactor;
|
|
143
|
+
const jitter = Math.random() * jitterRange * 2 - jitterRange;
|
|
144
|
+
// Ensure delay is at least 0
|
|
145
|
+
return Math.max(0, Math.round(cappedDelay + jitter));
|
|
146
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry with Backoff Utility.
|
|
3
|
+
*
|
|
4
|
+
* Provides a generic retry mechanism with exponential backoff for async operations.
|
|
5
|
+
* Used by RetryableContentGenerator and can be used for other retry scenarios.
|
|
6
|
+
*/
|
|
7
|
+
import { type RetryPolicy } from './retry-policy.js';
|
|
8
|
+
/**
|
|
9
|
+
* Context provided to retry callbacks.
|
|
10
|
+
*/
|
|
11
|
+
export interface RetryContext {
|
|
12
|
+
/** Current attempt number (1-based) */
|
|
13
|
+
attempt: number;
|
|
14
|
+
/** Delay before next retry in milliseconds */
|
|
15
|
+
delayMs: number;
|
|
16
|
+
/** The error that triggered the retry */
|
|
17
|
+
error: unknown;
|
|
18
|
+
/** Maximum number of attempts */
|
|
19
|
+
maxAttempts: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for the retry operation.
|
|
23
|
+
*/
|
|
24
|
+
export interface RetryOptions {
|
|
25
|
+
/** Custom function to determine if an error is retryable */
|
|
26
|
+
isRetryable?: (error: unknown) => boolean;
|
|
27
|
+
/** Callback invoked when all retries are exhausted */
|
|
28
|
+
onExhausted?: (context: RetryContext) => void;
|
|
29
|
+
/** Callback invoked before each retry attempt */
|
|
30
|
+
onRetry?: (context: RetryContext) => void;
|
|
31
|
+
/** Retry policy configuration */
|
|
32
|
+
policy?: RetryPolicy;
|
|
33
|
+
/** Abort signal to cancel retries */
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Result of a retry operation.
|
|
38
|
+
*/
|
|
39
|
+
export interface RetryResult<T> {
|
|
40
|
+
/** Number of attempts made */
|
|
41
|
+
attempts: number;
|
|
42
|
+
/** The final error if failed */
|
|
43
|
+
error?: unknown;
|
|
44
|
+
/** The result if successful */
|
|
45
|
+
result?: T;
|
|
46
|
+
/** Whether the operation succeeded */
|
|
47
|
+
success: boolean;
|
|
48
|
+
/** Total time spent in milliseconds */
|
|
49
|
+
totalTimeMs: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Execute an async operation with retry and exponential backoff.
|
|
53
|
+
*
|
|
54
|
+
* @param operation - The async operation to execute
|
|
55
|
+
* @param options - Retry options
|
|
56
|
+
* @returns Promise resolving to the operation result or throwing after all retries exhausted
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const result = await withRetry(
|
|
61
|
+
* () => fetchData(),
|
|
62
|
+
* {
|
|
63
|
+
* policy: DEFAULT_RETRY_POLICY,
|
|
64
|
+
* onRetry: ({ attempt, delayMs }) => {
|
|
65
|
+
* console.log(`Retry ${attempt}, waiting ${delayMs}ms`)
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* )
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function withRetry<T>(operation: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Execute an async operation with retry and return a detailed result.
|
|
74
|
+
*
|
|
75
|
+
* Unlike `withRetry`, this function never throws and always returns a result object.
|
|
76
|
+
*
|
|
77
|
+
* @param operation - The async operation to execute
|
|
78
|
+
* @param options - Retry options
|
|
79
|
+
* @returns Promise resolving to a RetryResult object
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const { success, result, error, attempts } = await withRetryResult(
|
|
84
|
+
* () => fetchData(),
|
|
85
|
+
* { policy: DEFAULT_RETRY_POLICY }
|
|
86
|
+
* )
|
|
87
|
+
*
|
|
88
|
+
* if (success) {
|
|
89
|
+
* console.log('Data:', result)
|
|
90
|
+
* } else {
|
|
91
|
+
* console.error('Failed after', attempts, 'attempts:', error)
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function withRetryResult<T>(operation: () => Promise<T>, options?: RetryOptions): Promise<RetryResult<T>>;
|
|
96
|
+
/**
|
|
97
|
+
* Create a retryable version of an async function.
|
|
98
|
+
*
|
|
99
|
+
* @param fn - The async function to wrap
|
|
100
|
+
* @param options - Retry options
|
|
101
|
+
* @returns A new function that will retry on failure
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const retryableFetch = makeRetryable(
|
|
106
|
+
* (url: string) => fetch(url).then(r => r.json()),
|
|
107
|
+
* { policy: DEFAULT_RETRY_POLICY }
|
|
108
|
+
* )
|
|
109
|
+
*
|
|
110
|
+
* const data = await retryableFetch('https://api.example.com/data')
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function makeRetryable<TArgs extends unknown[], TResult>(fn: (...args: TArgs) => Promise<TResult>, options?: RetryOptions): (...args: TArgs) => Promise<TResult>;
|