byterover-cli 0.4.1 → 1.0.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 +1 -9
- package/dist/commands/curate.d.ts +1 -3
- package/dist/commands/curate.js +14 -51
- package/dist/commands/main.d.ts +8 -0
- package/dist/commands/main.js +29 -8
- package/dist/commands/query.d.ts +1 -3
- package/dist/commands/query.js +8 -35
- package/dist/config/context-tree-domains.d.ts +5 -0
- package/dist/config/context-tree-domains.js +6 -1
- package/dist/config/environment.js +9 -9
- package/dist/constants.d.ts +14 -0
- package/dist/constants.js +18 -0
- package/dist/core/domain/cipher/agent/agent-info.d.ts +199 -0
- package/dist/core/domain/cipher/agent/agent-info.js +143 -0
- package/dist/core/domain/cipher/agent/agent-registry.d.ts +96 -0
- package/dist/core/domain/cipher/agent/agent-registry.js +254 -0
- package/dist/core/domain/cipher/agent/index.d.ts +4 -1
- package/dist/core/domain/cipher/agent/index.js +7 -1
- package/dist/core/domain/cipher/agent-events/types.d.ts +355 -2
- package/dist/core/domain/cipher/agent-events/types.js +11 -0
- package/dist/core/domain/cipher/errors/error-normalizer.d.ts +156 -0
- package/dist/core/domain/cipher/errors/error-normalizer.js +379 -0
- package/dist/core/domain/cipher/errors/file-system-error.d.ts +2 -1
- package/dist/core/domain/cipher/errors/file-system-error.js +3 -2
- package/dist/core/domain/cipher/errors/system-prompt-error-codes.d.ts +79 -0
- package/dist/core/domain/cipher/errors/system-prompt-error-codes.js +80 -0
- package/dist/core/domain/cipher/errors/system-prompt-error.d.ts +114 -0
- package/dist/core/domain/cipher/errors/system-prompt-error.js +144 -0
- package/dist/core/domain/cipher/file-system/types.d.ts +57 -0
- package/dist/core/domain/cipher/llm/error-codes.d.ts +51 -0
- package/dist/core/domain/cipher/llm/error-codes.js +51 -0
- package/dist/core/domain/cipher/llm/index.d.ts +9 -0
- package/dist/core/domain/cipher/llm/index.js +13 -0
- package/dist/core/domain/cipher/llm/registry.d.ts +113 -0
- package/dist/core/domain/cipher/llm/registry.js +244 -0
- package/dist/core/domain/cipher/llm/schemas.d.ts +155 -0
- package/dist/core/domain/cipher/llm/schemas.js +151 -0
- package/dist/core/domain/cipher/llm/types.d.ts +121 -0
- package/dist/core/domain/cipher/llm/types.js +60 -0
- package/dist/core/domain/cipher/storage/message-storage-types.d.ts +114 -5
- package/dist/core/domain/cipher/streaming/types.d.ts +119 -0
- package/dist/core/domain/cipher/streaming/types.js +16 -0
- package/dist/core/domain/cipher/system-prompt/types.d.ts +44 -0
- package/dist/core/domain/cipher/todos/types.d.ts +34 -0
- package/dist/core/domain/cipher/tools/constants.d.ts +5 -2
- package/dist/core/domain/cipher/tools/constants.js +5 -2
- package/dist/core/domain/cipher/tools/types.d.ts +31 -0
- package/dist/core/domain/errors/connection-error.d.ts +33 -0
- package/dist/core/domain/errors/connection-error.js +54 -0
- package/dist/core/domain/errors/core-process-error.d.ts +27 -0
- package/dist/core/domain/errors/core-process-error.js +43 -0
- package/dist/core/domain/errors/task-error.d.ts +64 -0
- package/dist/core/domain/errors/task-error.js +116 -0
- package/dist/core/domain/errors/transport-error.d.ts +72 -0
- package/dist/core/domain/errors/transport-error.js +114 -0
- package/dist/core/domain/instance/index.d.ts +1 -0
- package/dist/core/domain/instance/index.js +1 -0
- package/dist/core/domain/instance/types.d.ts +57 -0
- package/dist/core/domain/instance/types.js +72 -0
- package/dist/core/domain/knowledge/directory-manager.d.ts +16 -0
- package/dist/core/domain/knowledge/directory-manager.js +31 -0
- package/dist/core/domain/transport/index.d.ts +2 -0
- package/dist/core/domain/transport/index.js +2 -0
- package/dist/core/domain/transport/schemas.d.ts +1149 -0
- package/dist/core/domain/transport/schemas.js +554 -0
- package/dist/core/domain/transport/types.d.ts +67 -0
- package/dist/core/domain/transport/types.js +7 -0
- package/dist/core/interfaces/cipher/cipher-services.d.ts +15 -3
- package/dist/core/interfaces/cipher/i-chat-session.d.ts +47 -5
- package/dist/core/interfaces/cipher/i-cipher-agent.d.ts +39 -4
- package/dist/core/interfaces/cipher/i-content-generator.d.ts +3 -5
- package/dist/core/interfaces/cipher/i-file-system.d.ts +12 -1
- package/dist/core/interfaces/cipher/i-llm-service.d.ts +4 -5
- package/dist/core/interfaces/cipher/i-todo-storage.d.ts +24 -0
- package/dist/core/interfaces/cipher/i-todo-storage.js +1 -0
- package/dist/core/interfaces/cipher/i-tool-plugin.d.ts +90 -0
- package/dist/core/interfaces/cipher/i-tool-plugin.js +1 -0
- package/dist/core/interfaces/cipher/i-tool-provider.d.ts +3 -2
- package/dist/core/interfaces/cipher/i-tool-scheduler.d.ts +4 -0
- package/dist/core/interfaces/cipher/index.d.ts +35 -0
- package/dist/core/interfaces/cipher/index.js +11 -0
- package/dist/core/interfaces/cipher/message-factory.d.ts +155 -0
- package/dist/core/interfaces/cipher/message-factory.js +252 -0
- package/dist/core/interfaces/cipher/message-type-guards.d.ts +139 -0
- package/dist/core/interfaces/cipher/message-type-guards.js +173 -0
- package/dist/core/interfaces/cipher/message-types.d.ts +279 -5
- package/dist/core/interfaces/cipher/message-types.js +6 -0
- package/dist/core/interfaces/cipher/sanitization-types.d.ts +147 -0
- package/dist/core/interfaces/cipher/sanitization-types.js +46 -0
- package/dist/core/interfaces/executor/i-curate-executor.d.ts +34 -0
- package/dist/core/interfaces/executor/i-curate-executor.js +1 -0
- package/dist/core/interfaces/executor/i-query-executor.d.ts +32 -0
- package/dist/core/interfaces/executor/i-query-executor.js +1 -0
- package/dist/core/interfaces/executor/index.d.ts +2 -0
- package/dist/core/interfaces/executor/index.js +2 -0
- package/dist/core/interfaces/instance/i-instance-discovery.d.ts +45 -0
- package/dist/core/interfaces/instance/i-instance-discovery.js +1 -0
- package/dist/core/interfaces/instance/i-instance-manager.d.ts +58 -0
- package/dist/core/interfaces/instance/i-instance-manager.js +1 -0
- package/dist/core/interfaces/instance/index.d.ts +2 -0
- package/dist/core/interfaces/instance/index.js +2 -0
- package/dist/core/interfaces/noop-implementations.d.ts +53 -0
- package/dist/core/interfaces/noop-implementations.js +62 -0
- package/dist/core/interfaces/transport/i-transport-client.d.ts +97 -0
- package/dist/core/interfaces/transport/i-transport-client.js +1 -0
- package/dist/core/interfaces/transport/i-transport-server.d.ts +93 -0
- package/dist/core/interfaces/transport/i-transport-server.js +1 -0
- package/dist/core/interfaces/transport/index.d.ts +2 -0
- package/dist/core/interfaces/transport/index.js +2 -0
- package/dist/infra/cipher/agent/agent-error-codes.d.ts +16 -0
- package/dist/infra/cipher/agent/agent-error-codes.js +17 -0
- package/dist/infra/cipher/agent/agent-error.d.ts +54 -0
- package/dist/infra/cipher/agent/agent-error.js +79 -0
- package/dist/infra/cipher/agent/agent-schemas.d.ts +264 -0
- package/dist/infra/cipher/agent/agent-schemas.js +97 -0
- package/dist/infra/cipher/agent/agent-state-manager.d.ts +140 -0
- package/dist/infra/cipher/agent/agent-state-manager.js +275 -0
- package/dist/infra/cipher/agent/base-agent.d.ts +118 -0
- package/dist/infra/cipher/agent/base-agent.js +240 -0
- package/dist/infra/cipher/agent/cipher-agent.d.ts +165 -0
- package/dist/infra/cipher/agent/cipher-agent.js +546 -0
- package/dist/infra/cipher/agent/index.d.ts +22 -0
- package/dist/infra/cipher/agent/index.js +24 -0
- package/dist/infra/cipher/agent/service-initializer.d.ts +79 -0
- package/dist/infra/cipher/{agent-service-factory.js → agent/service-initializer.js} +117 -68
- package/dist/infra/cipher/agent/types.d.ts +35 -0
- package/dist/infra/cipher/agent/types.js +1 -0
- package/dist/infra/cipher/blob/blob-reference-resolver.d.ts +107 -0
- package/dist/infra/cipher/blob/blob-reference-resolver.js +228 -0
- package/dist/infra/cipher/blob/blob-reference-utils.d.ts +117 -0
- package/dist/infra/cipher/blob/blob-reference-utils.js +230 -0
- package/dist/infra/cipher/consumer/consumer-lock.js +1 -0
- package/dist/infra/cipher/consumer/consumer-service.js +1 -0
- package/dist/infra/cipher/consumer/execution-consumer.d.ts +6 -1
- package/dist/infra/cipher/consumer/execution-consumer.js +54 -16
- package/dist/infra/cipher/consumer/index.d.ts +1 -1
- package/dist/infra/cipher/consumer/index.js +2 -1
- package/dist/infra/cipher/consumer/queue-polling-service.js +1 -0
- package/dist/infra/cipher/file-system/binary-utils.d.ts +43 -0
- package/dist/infra/cipher/file-system/binary-utils.js +164 -0
- package/dist/infra/cipher/file-system/context-tree-file-system-factory.d.ts +9 -0
- package/dist/infra/cipher/file-system/context-tree-file-system-factory.js +24 -0
- package/dist/infra/cipher/file-system/file-system-service.d.ts +17 -1
- package/dist/infra/cipher/file-system/file-system-service.js +327 -36
- package/dist/infra/cipher/file-system/path-validator.d.ts +32 -0
- package/dist/infra/cipher/file-system/path-validator.js +111 -6
- package/dist/infra/cipher/interactive-loop.js +41 -33
- package/dist/infra/cipher/llm/capability-cache.d.ts +87 -0
- package/dist/infra/cipher/llm/capability-cache.js +125 -0
- package/dist/infra/cipher/llm/context/compaction/compaction-service.d.ts +32 -0
- package/dist/infra/cipher/llm/context/compaction/compaction-service.js +44 -3
- package/dist/infra/cipher/llm/context/compression/enhanced-compaction.d.ts +112 -0
- package/dist/infra/cipher/llm/context/compression/enhanced-compaction.js +175 -0
- package/dist/infra/cipher/llm/context/compression/filter-compacted.d.ts +83 -0
- package/dist/infra/cipher/llm/context/compression/filter-compacted.js +150 -0
- package/dist/infra/cipher/llm/context/compression/index.d.ts +5 -0
- package/dist/infra/cipher/llm/context/compression/index.js +6 -0
- package/dist/infra/cipher/llm/context/compression/reactive-overflow.d.ts +107 -0
- package/dist/infra/cipher/llm/context/compression/reactive-overflow.js +272 -0
- package/dist/infra/cipher/llm/context/context-manager.d.ts +47 -1
- package/dist/infra/cipher/llm/context/context-manager.js +129 -0
- package/dist/infra/cipher/llm/context/utils.js +17 -4
- package/dist/infra/cipher/llm/generators/byterover-content-generator.js +4 -2
- package/dist/infra/cipher/llm/internal-llm-service.d.ts +50 -17
- package/dist/infra/cipher/llm/internal-llm-service.js +273 -50
- package/dist/infra/cipher/llm/openrouter-llm-service.d.ts +6 -8
- package/dist/infra/cipher/llm/openrouter-llm-service.js +14 -16
- package/dist/infra/cipher/llm/retry/retry-policy.d.ts +1 -0
- package/dist/infra/cipher/llm/retry/retry-policy.js +11 -0
- package/dist/infra/cipher/llm/retry/retry-with-backoff.js +3 -2
- package/dist/infra/cipher/llm/sanitization/base64-utils.d.ts +102 -0
- package/dist/infra/cipher/llm/sanitization/base64-utils.js +182 -0
- package/dist/infra/cipher/llm/sanitization/index.d.ts +12 -0
- package/dist/infra/cipher/llm/sanitization/index.js +13 -0
- package/dist/infra/cipher/llm/sanitization/tool-sanitizer.d.ts +74 -0
- package/dist/infra/cipher/llm/sanitization/tool-sanitizer.js +398 -0
- package/dist/infra/cipher/llm/stream-processor.d.ts +158 -0
- package/dist/infra/cipher/llm/stream-processor.js +276 -0
- package/dist/infra/cipher/llm/tokenizers/claude-tokenizer.d.ts +13 -20
- package/dist/infra/cipher/llm/tokenizers/claude-tokenizer.js +17 -24
- package/dist/infra/cipher/llm/tokenizers/gemini-tokenizer.d.ts +12 -11
- package/dist/infra/cipher/llm/tokenizers/gemini-tokenizer.js +16 -15
- package/dist/infra/cipher/llm/tokenizers/openrouter-tokenizer.d.ts +15 -7
- package/dist/infra/cipher/llm/tokenizers/openrouter-tokenizer.js +22 -10
- package/dist/infra/cipher/llm/tool-output-processor.d.ts +51 -0
- package/dist/infra/cipher/llm/tool-output-processor.js +139 -0
- package/dist/infra/cipher/process/command-validator.d.ts +23 -0
- package/dist/infra/cipher/process/command-validator.js +75 -0
- package/dist/infra/cipher/process/path-utils.d.ts +66 -0
- package/dist/infra/cipher/process/path-utils.js +94 -0
- package/dist/infra/cipher/process/process-service.d.ts +32 -0
- package/dist/infra/cipher/process/process-service.js +98 -17
- package/dist/infra/cipher/session/chat-session.d.ts +56 -7
- package/dist/infra/cipher/session/chat-session.js +163 -13
- package/dist/infra/cipher/session/index.d.ts +1 -0
- package/dist/infra/cipher/session/index.js +2 -0
- package/dist/infra/cipher/session/message-queue.d.ts +65 -0
- package/dist/infra/cipher/session/message-queue.js +90 -0
- package/dist/infra/cipher/session/session-manager.d.ts +106 -5
- package/dist/infra/cipher/session/session-manager.js +254 -7
- package/dist/infra/cipher/session/session-status.d.ts +137 -0
- package/dist/infra/cipher/session/session-status.js +184 -0
- package/dist/infra/cipher/session/title-generator.d.ts +8 -0
- package/dist/infra/cipher/session/title-generator.js +31 -0
- package/dist/infra/cipher/storage/message-storage-service.d.ts +65 -2
- package/dist/infra/cipher/storage/message-storage-service.js +300 -54
- package/dist/infra/cipher/storage/tool-part-factory.d.ts +116 -0
- package/dist/infra/cipher/storage/tool-part-factory.js +197 -0
- package/dist/infra/cipher/system-prompt/contributor-schemas.d.ts +516 -0
- package/dist/infra/cipher/system-prompt/contributor-schemas.js +85 -0
- package/dist/infra/cipher/system-prompt/contributors/agent-prompt-contributor.d.ts +59 -0
- package/dist/infra/cipher/system-prompt/contributors/agent-prompt-contributor.js +131 -0
- package/dist/infra/cipher/system-prompt/contributors/companion-contributor.d.ts +54 -0
- package/dist/infra/cipher/system-prompt/contributors/companion-contributor.js +107 -0
- package/dist/infra/cipher/system-prompt/contributors/context-tree-structure-contributor.d.ts +68 -0
- package/dist/infra/cipher/system-prompt/contributors/context-tree-structure-contributor.js +179 -0
- package/dist/infra/cipher/system-prompt/contributors/datetime-contributor.d.ts +25 -0
- package/dist/infra/cipher/system-prompt/contributors/datetime-contributor.js +29 -0
- package/dist/infra/cipher/system-prompt/contributors/environment-contributor.d.ts +25 -0
- package/dist/infra/cipher/system-prompt/contributors/environment-contributor.js +54 -0
- package/dist/infra/cipher/system-prompt/contributors/file-contributor.d.ts +60 -0
- package/dist/infra/cipher/system-prompt/contributors/file-contributor.js +128 -0
- package/dist/infra/cipher/system-prompt/contributors/index.d.ts +13 -0
- package/dist/infra/cipher/system-prompt/contributors/index.js +8 -0
- package/dist/infra/cipher/system-prompt/contributors/memory-contributor.d.ts +40 -0
- package/dist/infra/cipher/system-prompt/contributors/memory-contributor.js +56 -0
- package/dist/infra/cipher/system-prompt/contributors/static-contributor.d.ts +26 -0
- package/dist/infra/cipher/system-prompt/contributors/static-contributor.js +31 -0
- package/dist/infra/cipher/system-prompt/environment-context-builder.d.ts +112 -0
- package/dist/infra/cipher/system-prompt/environment-context-builder.js +256 -0
- package/dist/infra/cipher/system-prompt/prompt-cache.d.ts +102 -0
- package/dist/infra/cipher/system-prompt/prompt-cache.js +156 -0
- package/dist/infra/cipher/system-prompt/schemas.d.ts +151 -0
- package/dist/infra/cipher/system-prompt/schemas.js +94 -0
- package/dist/infra/cipher/system-prompt/system-prompt-manager.d.ts +136 -0
- package/dist/infra/cipher/system-prompt/system-prompt-manager.js +307 -0
- package/dist/infra/cipher/todos/todo-storage-service.d.ts +26 -0
- package/dist/infra/cipher/todos/todo-storage-service.js +28 -0
- package/dist/infra/cipher/tools/core-tool-scheduler.js +5 -1
- package/dist/infra/cipher/tools/default-policy-rules.js +1 -1
- package/dist/infra/cipher/tools/implementations/bash-exec-tool.d.ts +1 -0
- package/dist/infra/cipher/tools/implementations/bash-exec-tool.js +27 -10
- package/dist/infra/cipher/tools/implementations/bash-output-tool.js +1 -5
- package/dist/infra/cipher/tools/implementations/batch-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/batch-tool.js +142 -0
- package/dist/infra/cipher/tools/implementations/curate-tool.js +195 -68
- package/dist/infra/cipher/tools/implementations/list-directory-tool.d.ts +12 -0
- package/dist/infra/cipher/tools/implementations/list-directory-tool.js +52 -0
- package/dist/infra/cipher/tools/implementations/read-file-tool.d.ts +8 -1
- package/dist/infra/cipher/tools/implementations/read-file-tool.js +17 -7
- package/dist/infra/cipher/tools/implementations/read-todos-tool.d.ts +11 -0
- package/dist/infra/cipher/tools/implementations/read-todos-tool.js +39 -0
- package/dist/infra/cipher/tools/implementations/{detect-domains-tool.d.ts → spec-analyze-tool.d.ts} +1 -1
- package/dist/infra/cipher/tools/implementations/{detect-domains-tool.js → spec-analyze-tool.js} +9 -7
- package/dist/infra/cipher/tools/implementations/task-tool.d.ts +34 -0
- package/dist/infra/cipher/tools/implementations/task-tool.js +207 -0
- package/dist/infra/cipher/tools/implementations/write-todos-tool.d.ts +4 -1
- package/dist/infra/cipher/tools/implementations/write-todos-tool.js +19 -63
- package/dist/infra/cipher/tools/index.d.ts +1 -1
- package/dist/infra/cipher/tools/index.js +1 -1
- package/dist/infra/cipher/tools/plugins/index.d.ts +3 -0
- package/dist/infra/cipher/tools/plugins/index.js +2 -0
- package/dist/infra/cipher/tools/plugins/logging-plugin.d.ts +28 -0
- package/dist/infra/cipher/tools/plugins/logging-plugin.js +66 -0
- package/dist/infra/cipher/tools/plugins/plugin-manager.d.ts +81 -0
- package/dist/infra/cipher/tools/plugins/plugin-manager.js +122 -0
- package/dist/infra/cipher/tools/streaming/index.d.ts +1 -0
- package/dist/infra/cipher/tools/streaming/index.js +1 -0
- package/dist/infra/cipher/tools/streaming/metadata-handler.d.ts +31 -0
- package/dist/infra/cipher/tools/streaming/metadata-handler.js +39 -0
- package/dist/infra/cipher/tools/tool-description-loader.d.ts +57 -0
- package/dist/infra/cipher/tools/tool-description-loader.js +108 -0
- package/dist/infra/cipher/tools/tool-manager.d.ts +38 -4
- package/dist/infra/cipher/tools/tool-manager.js +107 -11
- package/dist/infra/cipher/tools/tool-provider-getter.d.ts +6 -0
- package/dist/infra/cipher/tools/tool-provider-getter.js +1 -0
- package/dist/infra/cipher/tools/tool-provider.d.ts +32 -7
- package/dist/infra/cipher/tools/tool-provider.js +81 -25
- package/dist/infra/cipher/tools/tool-registry.d.ts +23 -0
- package/dist/infra/cipher/tools/tool-registry.js +58 -16
- package/dist/infra/context-tree/file-context-tree-snapshot-service.js +10 -4
- package/dist/infra/context-tree/file-context-tree-writer-service.d.ts +4 -3
- package/dist/infra/context-tree/file-context-tree-writer-service.js +6 -4
- package/dist/infra/context-tree/path-utils.d.ts +7 -0
- package/dist/infra/context-tree/path-utils.js +7 -0
- package/dist/infra/core/executors/curate-executor.d.ts +35 -0
- package/dist/infra/core/executors/curate-executor.js +123 -0
- package/dist/infra/core/executors/index.d.ts +2 -0
- package/dist/infra/core/executors/index.js +2 -0
- package/dist/infra/core/executors/query-executor.d.ts +23 -0
- package/dist/infra/core/executors/query-executor.js +51 -0
- package/dist/infra/core/task-processor.d.ts +81 -0
- package/dist/infra/core/task-processor.js +115 -0
- package/dist/infra/instance/file-instance-discovery.d.ts +31 -0
- package/dist/infra/instance/file-instance-discovery.js +84 -0
- package/dist/infra/instance/file-instance-manager.d.ts +46 -0
- package/dist/infra/instance/file-instance-manager.js +123 -0
- package/dist/infra/instance/index.d.ts +3 -0
- package/dist/infra/instance/index.js +3 -0
- package/dist/infra/instance/process-utils.d.ts +14 -0
- package/dist/infra/instance/process-utils.js +39 -0
- package/dist/infra/process/agent-worker.d.ts +20 -0
- package/dist/infra/process/agent-worker.js +602 -0
- package/dist/infra/process/index.d.ts +12 -0
- package/dist/infra/process/index.js +11 -0
- package/dist/infra/process/ipc-types.d.ts +55 -0
- package/dist/infra/process/ipc-types.js +12 -0
- package/dist/infra/process/process-manager.d.ts +154 -0
- package/dist/infra/process/process-manager.js +471 -0
- package/dist/infra/process/task-queue-manager.d.ts +123 -0
- package/dist/infra/process/task-queue-manager.js +226 -0
- package/dist/infra/process/transport-handlers.d.ts +124 -0
- package/dist/infra/process/transport-handlers.js +348 -0
- package/dist/infra/process/transport-worker.d.ts +20 -0
- package/dist/infra/process/transport-worker.js +168 -0
- package/dist/infra/repl/commands/curate-command.js +0 -5
- package/dist/infra/repl/commands/query-command.js +0 -3
- package/dist/infra/repl/repl-startup.d.ts +4 -0
- package/dist/infra/repl/repl-startup.js +8 -1
- package/dist/infra/repl/transport-client-helper.d.ts +9 -0
- package/dist/infra/repl/transport-client-helper.js +96 -0
- package/dist/infra/transport/index.d.ts +4 -0
- package/dist/infra/transport/index.js +4 -0
- package/dist/infra/transport/port-utils.d.ts +42 -0
- package/dist/infra/transport/port-utils.js +84 -0
- package/dist/infra/transport/socket-io-transport-client.d.ts +45 -0
- package/dist/infra/transport/socket-io-transport-client.js +270 -0
- package/dist/infra/transport/socket-io-transport-server.d.ts +35 -0
- package/dist/infra/transport/socket-io-transport-server.js +207 -0
- package/dist/infra/transport/transport-client-factory.d.ts +76 -0
- package/dist/infra/transport/transport-client-factory.js +168 -0
- package/dist/infra/transport/transport-factory.d.ts +33 -0
- package/dist/infra/transport/transport-factory.js +59 -0
- package/dist/infra/usecase/curate-use-case.d.ts +8 -55
- package/dist/infra/usecase/curate-use-case.js +71 -262
- package/dist/infra/usecase/init-use-case.js +3 -2
- package/dist/infra/usecase/query-use-case.d.ts +18 -45
- package/dist/infra/usecase/query-use-case.js +250 -326
- package/dist/infra/usecase/status-use-case.js +1 -1
- package/dist/resources/prompts/{curate-context-tree-curation.yml → curate.yml} +25 -22
- package/dist/resources/prompts/explore.yml +78 -0
- package/dist/resources/prompts/plan.yml +114 -0
- package/dist/resources/prompts/reflection.yml +1 -1
- package/dist/resources/prompts/system-prompt.yml +15 -8
- package/dist/resources/prompts/tool-outputs.yml +0 -5
- package/dist/resources/tools/bash_exec.txt +98 -0
- package/dist/resources/tools/bash_output.txt +40 -0
- package/dist/resources/tools/batch.txt +28 -0
- package/dist/resources/tools/create_knowledge_topic.txt +23 -0
- package/dist/resources/tools/curate.txt +22 -0
- package/dist/resources/tools/delete_memory.txt +1 -0
- package/dist/resources/tools/detect_domains.txt +11 -0
- package/dist/resources/tools/edit_file.txt +1 -0
- package/dist/resources/tools/edit_memory.txt +1 -0
- package/dist/resources/tools/glob_files.txt +20 -0
- package/dist/resources/tools/grep_content.txt +18 -0
- package/dist/resources/tools/kill_process.txt +16 -0
- package/dist/resources/tools/list_directory.txt +16 -0
- package/dist/resources/tools/list_memories.txt +1 -0
- package/dist/resources/tools/read_file.txt +31 -0
- package/dist/resources/tools/read_memory.txt +1 -0
- package/dist/resources/tools/read_todos.txt +17 -0
- package/dist/resources/tools/search_history.txt +1 -0
- package/dist/resources/tools/task.txt +23 -0
- package/dist/resources/tools/write_file.txt +1 -0
- package/dist/resources/tools/write_memory.txt +1 -0
- package/dist/resources/tools/write_todos.txt +29 -0
- package/dist/tui/app.js +9 -13
- package/dist/tui/components/command-details.d.ts +14 -0
- package/dist/tui/components/command-details.js +35 -0
- package/dist/tui/components/execution/execution-changes.d.ts +5 -0
- package/dist/tui/components/execution/execution-changes.js +19 -4
- package/dist/tui/components/execution/execution-content.d.ts +4 -2
- package/dist/tui/components/execution/execution-content.js +26 -13
- package/dist/tui/components/execution/execution-input.js +3 -3
- package/dist/tui/components/execution/execution-progress.d.ts +2 -2
- package/dist/tui/components/execution/execution-progress.js +8 -6
- package/dist/tui/components/execution/log-item.d.ts +3 -4
- package/dist/tui/components/execution/log-item.js +2 -5
- package/dist/tui/components/footer.js +9 -4
- package/dist/tui/components/header.d.ts +3 -3
- package/dist/tui/components/header.js +5 -3
- package/dist/tui/components/index.d.ts +1 -0
- package/dist/tui/components/index.js +1 -0
- package/dist/tui/components/onboarding/copyable-prompt.d.ts +5 -3
- package/dist/tui/components/onboarding/copyable-prompt.js +7 -8
- package/dist/tui/components/onboarding/onboarding-flow.js +35 -25
- package/dist/tui/components/scrollable-list.js +12 -10
- package/dist/tui/components/suggestions.js +39 -41
- package/dist/tui/components/tab-bar.d.ts +2 -1
- package/dist/tui/components/tab-bar.js +3 -4
- package/dist/tui/constants.d.ts +0 -5
- package/dist/tui/constants.js +0 -5
- package/dist/tui/contexts/auth-context.js +9 -2
- package/dist/tui/contexts/{use-commands.js → commands-context.js} +3 -3
- package/dist/tui/contexts/index.d.ts +6 -1
- package/dist/tui/contexts/index.js +6 -1
- package/dist/tui/contexts/onboarding-context.d.ts +1 -1
- package/dist/tui/contexts/onboarding-context.js +9 -9
- package/dist/tui/contexts/tasks-context.d.ts +84 -0
- package/dist/tui/contexts/tasks-context.js +218 -0
- package/dist/tui/contexts/transport-context.d.ts +29 -0
- package/dist/tui/contexts/transport-context.js +82 -0
- package/dist/tui/hooks/index.d.ts +10 -6
- package/dist/tui/hooks/index.js +7 -6
- package/dist/tui/hooks/use-activity-logs.d.ts +3 -11
- package/dist/tui/hooks/use-activity-logs.js +87 -34
- package/dist/tui/hooks/use-auth-polling.d.ts +24 -0
- package/dist/tui/hooks/use-auth-polling.js +104 -0
- package/dist/tui/hooks/use-slash-command-processor.js +0 -1
- package/dist/tui/hooks/use-slash-completion.js +1 -1
- package/dist/tui/hooks/use-tab-navigation.d.ts +2 -1
- package/dist/tui/hooks/use-tab-navigation.js +16 -7
- package/dist/tui/hooks/use-terminal-breakpoint.d.ts +21 -0
- package/dist/tui/hooks/use-terminal-breakpoint.js +38 -0
- package/dist/tui/hooks/use-ui-heights.d.ts +120 -0
- package/dist/tui/hooks/use-ui-heights.js +88 -0
- package/dist/tui/providers/app-providers.js +2 -6
- package/dist/tui/types/commands.d.ts +0 -26
- package/dist/tui/types/index.d.ts +1 -1
- package/dist/tui/types/ui.d.ts +9 -4
- package/dist/tui/utils/line.d.ts +11 -0
- package/dist/tui/utils/line.js +16 -0
- package/dist/tui/utils/log.d.ts +27 -0
- package/dist/tui/utils/log.js +114 -0
- package/dist/tui/views/command-view.d.ts +7 -0
- package/dist/tui/views/command-view.js +103 -80
- package/dist/tui/views/login-view.js +7 -4
- package/dist/tui/views/logs-view.d.ts +13 -0
- package/dist/tui/views/logs-view.js +27 -52
- package/dist/utils/connection-error-handler.d.ts +16 -0
- package/dist/utils/connection-error-handler.js +49 -0
- package/dist/utils/crash-log.d.ts +14 -0
- package/dist/utils/crash-log.js +19 -0
- package/dist/utils/file-helpers.d.ts +14 -0
- package/dist/utils/file-helpers.js +21 -0
- package/dist/utils/global-logs-path.d.ts +11 -0
- package/dist/utils/global-logs-path.js +37 -0
- package/dist/utils/process-logger.d.ts +53 -0
- package/dist/utils/process-logger.js +253 -0
- package/dist/utils/sandbox-detector.d.ts +31 -0
- package/dist/utils/sandbox-detector.js +122 -0
- package/oclif.manifest.json +10 -198
- package/package.json +5 -1
- package/dist/commands/cipher-agent/run.d.ts +0 -142
- package/dist/commands/cipher-agent/run.js +0 -555
- package/dist/commands/cipher-agent/set-prompt.d.ts +0 -16
- package/dist/commands/cipher-agent/set-prompt.js +0 -58
- package/dist/commands/cipher-agent/show-prompt.d.ts +0 -13
- package/dist/commands/cipher-agent/show-prompt.js +0 -53
- package/dist/commands/foo.d.ts +0 -14
- package/dist/commands/foo.js +0 -66
- package/dist/infra/cipher/agent-service-factory.d.ts +0 -93
- package/dist/infra/cipher/cipher-agent-state-manager.d.ts +0 -63
- package/dist/infra/cipher/cipher-agent-state-manager.js +0 -108
- package/dist/infra/cipher/cipher-agent.d.ts +0 -182
- package/dist/infra/cipher/cipher-agent.js +0 -317
- package/dist/infra/cipher/system-prompt/simple-prompt-factory.d.ts +0 -106
- package/dist/infra/cipher/system-prompt/simple-prompt-factory.js +0 -297
- package/dist/infra/cipher/tools/implementations/find-knowledge-topics-tool.d.ts +0 -7
- package/dist/infra/cipher/tools/implementations/find-knowledge-topics-tool.js +0 -424
- package/dist/resources/prompts/modes/autonomous.yml +0 -9
- package/dist/resources/prompts/query-context-tree-retrieval.yml +0 -48
- package/dist/tui/contexts/consumer.d.ts +0 -31
- package/dist/tui/contexts/consumer.js +0 -56
- package/dist/tui/hooks/use-consumer.d.ts +0 -12
- package/dist/tui/hooks/use-consumer.js +0 -50
- package/dist/tui/hooks/use-queue-polling.d.ts +0 -31
- package/dist/tui/hooks/use-queue-polling.js +0 -90
- /package/dist/tui/contexts/{use-commands.d.ts → commands-context.d.ts} +0 -0
- /package/dist/tui/contexts/{use-mode.d.ts → mode-context.d.ts} +0 -0
- /package/dist/tui/contexts/{use-mode.js → mode-context.js} +0 -0
- /package/dist/tui/contexts/{use-theme.d.ts → theme-context.d.ts} +0 -0
- /package/dist/tui/contexts/{use-theme.js → theme-context.js} +0 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaskQueueManager - Manages in-memory task queues with concurrency control.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Separate queues for different task types (curate, query)
|
|
6
|
+
* - Configurable concurrency limits per queue
|
|
7
|
+
* - Task deduplication (same taskId can't be queued twice)
|
|
8
|
+
* - Cancel tasks from queue before processing
|
|
9
|
+
* - FIFO processing order
|
|
10
|
+
*
|
|
11
|
+
* This class is extracted from agent-worker.ts to enable unit testing.
|
|
12
|
+
*/
|
|
13
|
+
import type { TaskExecute } from '../../core/domain/transport/schemas.js';
|
|
14
|
+
export type TaskType = 'curate' | 'query';
|
|
15
|
+
export interface QueueConfig {
|
|
16
|
+
/** Maximum concurrent tasks for this queue */
|
|
17
|
+
maxConcurrent: number;
|
|
18
|
+
}
|
|
19
|
+
export interface TaskQueueStats {
|
|
20
|
+
/** Number of tasks currently being processed */
|
|
21
|
+
active: number;
|
|
22
|
+
/** Maximum concurrent tasks allowed */
|
|
23
|
+
maxConcurrent: number;
|
|
24
|
+
/** Number of tasks waiting in queue */
|
|
25
|
+
queued: number;
|
|
26
|
+
}
|
|
27
|
+
export interface TaskQueueManagerConfig {
|
|
28
|
+
curate: QueueConfig;
|
|
29
|
+
/** Optional callback for executor errors (for logging/debugging) */
|
|
30
|
+
onExecutorError?: (taskId: string, error: unknown) => void;
|
|
31
|
+
query: QueueConfig;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Result of attempting to enqueue a task.
|
|
35
|
+
*/
|
|
36
|
+
export type EnqueueResult = {
|
|
37
|
+
position: number;
|
|
38
|
+
success: true;
|
|
39
|
+
} | {
|
|
40
|
+
reason: 'duplicate' | 'unknown_type';
|
|
41
|
+
success: false;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Result of attempting to cancel a task.
|
|
45
|
+
*/
|
|
46
|
+
export type CancelResult = {
|
|
47
|
+
reason: 'not_found';
|
|
48
|
+
success: false;
|
|
49
|
+
} | {
|
|
50
|
+
success: true;
|
|
51
|
+
taskType: TaskType;
|
|
52
|
+
wasQueued: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Callback for when a task should be executed.
|
|
56
|
+
*/
|
|
57
|
+
export type TaskExecutor = (task: TaskExecute) => Promise<void>;
|
|
58
|
+
export declare class TaskQueueManager {
|
|
59
|
+
private activeCurateTasks;
|
|
60
|
+
private activeQueryTasks;
|
|
61
|
+
private readonly config;
|
|
62
|
+
private readonly curateQueue;
|
|
63
|
+
/** Maps taskId → taskType for tracking (replaces Set for type awareness) */
|
|
64
|
+
private readonly knownTasks;
|
|
65
|
+
private readonly onExecutorError?;
|
|
66
|
+
private readonly queryQueue;
|
|
67
|
+
private taskExecutor;
|
|
68
|
+
constructor(config?: Partial<TaskQueueManagerConfig>);
|
|
69
|
+
/**
|
|
70
|
+
* Cancel a task by taskId.
|
|
71
|
+
* Removes from queue if waiting, or marks for cancellation if processing.
|
|
72
|
+
*/
|
|
73
|
+
cancel(taskId: string): CancelResult;
|
|
74
|
+
/**
|
|
75
|
+
* Clear all queues and reset state.
|
|
76
|
+
* Useful for testing or shutdown.
|
|
77
|
+
*/
|
|
78
|
+
clear(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Enqueue a task for processing.
|
|
81
|
+
* Returns success with queue position, or failure reason.
|
|
82
|
+
*/
|
|
83
|
+
enqueue(task: TaskExecute): EnqueueResult;
|
|
84
|
+
/**
|
|
85
|
+
* Get all queue statistics.
|
|
86
|
+
*/
|
|
87
|
+
getAllStats(): Record<TaskType, TaskQueueStats>;
|
|
88
|
+
/**
|
|
89
|
+
* Get statistics for a specific queue.
|
|
90
|
+
*/
|
|
91
|
+
getStats(type: TaskType): TaskQueueStats;
|
|
92
|
+
/**
|
|
93
|
+
* Check if a taskId is known (queued or processing).
|
|
94
|
+
*/
|
|
95
|
+
isKnown(taskId: string): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Mark a task as completed (removes from known map).
|
|
98
|
+
* Should be called by executor when task finishes.
|
|
99
|
+
* Guards against underflow from duplicate/invalid calls.
|
|
100
|
+
*/
|
|
101
|
+
markCompleted(taskId: string, type: TaskType): void;
|
|
102
|
+
/**
|
|
103
|
+
* Set the task executor callback.
|
|
104
|
+
* Called when a task is ready to be processed.
|
|
105
|
+
* Also triggers processing of any queued tasks (up to maxConcurrent).
|
|
106
|
+
*/
|
|
107
|
+
setExecutor(executor: TaskExecutor): void;
|
|
108
|
+
/**
|
|
109
|
+
* Process all possible tasks from a queue (up to maxConcurrent).
|
|
110
|
+
* Handles Infinity maxConcurrent safely by using queue length as bound.
|
|
111
|
+
*/
|
|
112
|
+
private drainQueue;
|
|
113
|
+
private executeTask;
|
|
114
|
+
/**
|
|
115
|
+
* Get queue state for a task type (DRY helper).
|
|
116
|
+
*/
|
|
117
|
+
private getQueueState;
|
|
118
|
+
/**
|
|
119
|
+
* Try to process the next task from a specific queue.
|
|
120
|
+
* Unified method replacing tryProcessNextCurate/tryProcessNextQuery.
|
|
121
|
+
*/
|
|
122
|
+
private tryProcessNext;
|
|
123
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaskQueueManager - Manages in-memory task queues with concurrency control.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Separate queues for different task types (curate, query)
|
|
6
|
+
* - Configurable concurrency limits per queue
|
|
7
|
+
* - Task deduplication (same taskId can't be queued twice)
|
|
8
|
+
* - Cancel tasks from queue before processing
|
|
9
|
+
* - FIFO processing order
|
|
10
|
+
*
|
|
11
|
+
* This class is extracted from agent-worker.ts to enable unit testing.
|
|
12
|
+
*/
|
|
13
|
+
export class TaskQueueManager {
|
|
14
|
+
activeCurateTasks = 0;
|
|
15
|
+
activeQueryTasks = 0;
|
|
16
|
+
config;
|
|
17
|
+
curateQueue = [];
|
|
18
|
+
/** Maps taskId → taskType for tracking (replaces Set for type awareness) */
|
|
19
|
+
knownTasks = new Map();
|
|
20
|
+
onExecutorError;
|
|
21
|
+
queryQueue = [];
|
|
22
|
+
taskExecutor;
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.config = {
|
|
25
|
+
curate: { maxConcurrent: config?.curate?.maxConcurrent ?? 2 },
|
|
26
|
+
// Query tasks are unlimited (Infinity) - lightweight and fast
|
|
27
|
+
query: { maxConcurrent: config?.query?.maxConcurrent ?? Infinity },
|
|
28
|
+
};
|
|
29
|
+
this.onExecutorError = config?.onExecutorError;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Cancel a task by taskId.
|
|
33
|
+
* Removes from queue if waiting, or marks for cancellation if processing.
|
|
34
|
+
*/
|
|
35
|
+
cancel(taskId) {
|
|
36
|
+
// Try to remove from curate queue
|
|
37
|
+
const curateIndex = this.curateQueue.findIndex((t) => t.taskId === taskId);
|
|
38
|
+
if (curateIndex !== -1) {
|
|
39
|
+
this.curateQueue.splice(curateIndex, 1);
|
|
40
|
+
this.knownTasks.delete(taskId);
|
|
41
|
+
return { success: true, taskType: 'curate', wasQueued: true };
|
|
42
|
+
}
|
|
43
|
+
// Try to remove from query queue
|
|
44
|
+
const queryIndex = this.queryQueue.findIndex((t) => t.taskId === taskId);
|
|
45
|
+
if (queryIndex !== -1) {
|
|
46
|
+
this.queryQueue.splice(queryIndex, 1);
|
|
47
|
+
this.knownTasks.delete(taskId);
|
|
48
|
+
return { success: true, taskType: 'query', wasQueued: true };
|
|
49
|
+
}
|
|
50
|
+
// Check if task is currently processing - now we know the real taskType!
|
|
51
|
+
const taskType = this.knownTasks.get(taskId);
|
|
52
|
+
if (taskType) {
|
|
53
|
+
// Task is processing - caller should handle cancellation via taskProcessor
|
|
54
|
+
return { success: true, taskType, wasQueued: false };
|
|
55
|
+
}
|
|
56
|
+
return { reason: 'not_found', success: false };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clear all queues and reset state.
|
|
60
|
+
* Useful for testing or shutdown.
|
|
61
|
+
*/
|
|
62
|
+
clear() {
|
|
63
|
+
this.curateQueue.length = 0;
|
|
64
|
+
this.queryQueue.length = 0;
|
|
65
|
+
this.activeCurateTasks = 0;
|
|
66
|
+
this.activeQueryTasks = 0;
|
|
67
|
+
this.knownTasks.clear();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Enqueue a task for processing.
|
|
71
|
+
* Returns success with queue position, or failure reason.
|
|
72
|
+
*/
|
|
73
|
+
enqueue(task) {
|
|
74
|
+
// Deduplication check
|
|
75
|
+
if (this.knownTasks.has(task.taskId)) {
|
|
76
|
+
return { reason: 'duplicate', success: false };
|
|
77
|
+
}
|
|
78
|
+
// Validate task type
|
|
79
|
+
if (task.type !== 'curate' && task.type !== 'query') {
|
|
80
|
+
return { reason: 'unknown_type', success: false };
|
|
81
|
+
}
|
|
82
|
+
// Register with type and enqueue
|
|
83
|
+
this.knownTasks.set(task.taskId, task.type);
|
|
84
|
+
if (task.type === 'curate') {
|
|
85
|
+
this.curateQueue.push(task);
|
|
86
|
+
this.tryProcessNext('curate');
|
|
87
|
+
return { position: this.curateQueue.length, success: true };
|
|
88
|
+
}
|
|
89
|
+
this.queryQueue.push(task);
|
|
90
|
+
this.tryProcessNext('query');
|
|
91
|
+
return { position: this.queryQueue.length, success: true };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get all queue statistics.
|
|
95
|
+
*/
|
|
96
|
+
getAllStats() {
|
|
97
|
+
return {
|
|
98
|
+
curate: this.getStats('curate'),
|
|
99
|
+
query: this.getStats('query'),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get statistics for a specific queue.
|
|
104
|
+
*/
|
|
105
|
+
getStats(type) {
|
|
106
|
+
if (type === 'curate') {
|
|
107
|
+
return {
|
|
108
|
+
active: this.activeCurateTasks,
|
|
109
|
+
maxConcurrent: this.config.curate.maxConcurrent,
|
|
110
|
+
queued: this.curateQueue.length,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
active: this.activeQueryTasks,
|
|
115
|
+
maxConcurrent: this.config.query.maxConcurrent,
|
|
116
|
+
queued: this.queryQueue.length,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if a taskId is known (queued or processing).
|
|
121
|
+
*/
|
|
122
|
+
isKnown(taskId) {
|
|
123
|
+
return this.knownTasks.has(taskId);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Mark a task as completed (removes from known map).
|
|
127
|
+
* Should be called by executor when task finishes.
|
|
128
|
+
* Guards against underflow from duplicate/invalid calls.
|
|
129
|
+
*/
|
|
130
|
+
markCompleted(taskId, type) {
|
|
131
|
+
// Guard: only decrement if task was actually known (prevents underflow)
|
|
132
|
+
if (!this.knownTasks.has(taskId)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.knownTasks.delete(taskId);
|
|
136
|
+
if (type === 'curate') {
|
|
137
|
+
if (this.activeCurateTasks > 0) {
|
|
138
|
+
this.activeCurateTasks--;
|
|
139
|
+
}
|
|
140
|
+
this.tryProcessNext('curate');
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
if (this.activeQueryTasks > 0) {
|
|
144
|
+
this.activeQueryTasks--;
|
|
145
|
+
}
|
|
146
|
+
this.tryProcessNext('query');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Set the task executor callback.
|
|
151
|
+
* Called when a task is ready to be processed.
|
|
152
|
+
* Also triggers processing of any queued tasks (up to maxConcurrent).
|
|
153
|
+
*/
|
|
154
|
+
setExecutor(executor) {
|
|
155
|
+
this.taskExecutor = executor;
|
|
156
|
+
// Process any tasks that were queued before executor was set
|
|
157
|
+
// Use queue length as upper bound to handle Infinity maxConcurrent safely
|
|
158
|
+
this.drainQueue('curate');
|
|
159
|
+
this.drainQueue('query');
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Process all possible tasks from a queue (up to maxConcurrent).
|
|
163
|
+
* Handles Infinity maxConcurrent safely by using queue length as bound.
|
|
164
|
+
*/
|
|
165
|
+
drainQueue(type) {
|
|
166
|
+
const state = this.getQueueState(type);
|
|
167
|
+
// Process up to queue length (safe for Infinity maxConcurrent)
|
|
168
|
+
const toProcess = Math.min(state.queue.length, state.config.maxConcurrent);
|
|
169
|
+
for (let i = 0; i < toProcess; i++) {
|
|
170
|
+
this.tryProcessNext(type);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// ============================================================================
|
|
174
|
+
// Private Methods
|
|
175
|
+
// ============================================================================
|
|
176
|
+
executeTask(task, type) {
|
|
177
|
+
this.taskExecutor(task)
|
|
178
|
+
.catch((error) => {
|
|
179
|
+
// Notify caller of executor error (for logging/debugging)
|
|
180
|
+
// Primary error handling is executor's responsibility
|
|
181
|
+
this.onExecutorError?.(task.taskId, error);
|
|
182
|
+
})
|
|
183
|
+
.finally(() => {
|
|
184
|
+
this.markCompleted(task.taskId, type);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get queue state for a task type (DRY helper).
|
|
189
|
+
*/
|
|
190
|
+
getQueueState(type) {
|
|
191
|
+
if (type === 'curate') {
|
|
192
|
+
return {
|
|
193
|
+
active: this.activeCurateTasks,
|
|
194
|
+
config: this.config.curate,
|
|
195
|
+
incrementActive: () => this.activeCurateTasks++,
|
|
196
|
+
queue: this.curateQueue,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
active: this.activeQueryTasks,
|
|
201
|
+
config: this.config.query,
|
|
202
|
+
incrementActive: () => this.activeQueryTasks++,
|
|
203
|
+
queue: this.queryQueue,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Try to process the next task from a specific queue.
|
|
208
|
+
* Unified method replacing tryProcessNextCurate/tryProcessNextQuery.
|
|
209
|
+
*/
|
|
210
|
+
tryProcessNext(type) {
|
|
211
|
+
// Don't process without executor - tasks stay in queue
|
|
212
|
+
if (!this.taskExecutor) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const state = this.getQueueState(type);
|
|
216
|
+
if (state.active >= state.config.maxConcurrent) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (state.queue.length === 0) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const task = state.queue.shift();
|
|
223
|
+
state.incrementActive();
|
|
224
|
+
this.executeTask(task, type);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport Handlers - Message routing in Transport Process.
|
|
3
|
+
*
|
|
4
|
+
* Architecture v0.5.0:
|
|
5
|
+
* - Routes messages between clients (TUI, external CLIs) and Agent
|
|
6
|
+
* - Agent is a special client that registers via 'agent:register'
|
|
7
|
+
* - Client UseCase generates taskId, Transport validates and routes
|
|
8
|
+
* - NO TaskProcessor, NO business logic (just routing)
|
|
9
|
+
*
|
|
10
|
+
* Event naming convention:
|
|
11
|
+
* - task:* events are Transport-generated (ack, created, started, completed, error)
|
|
12
|
+
* - llmservice:* events are forwarded from Agent with ORIGINAL names
|
|
13
|
+
*
|
|
14
|
+
* Message flows:
|
|
15
|
+
* 1. Client → Transport: task:create {taskId, type, content}
|
|
16
|
+
* Transport → Agent: task:execute {taskId, type, content, clientId}
|
|
17
|
+
* Transport → Client: task:ack {taskId}
|
|
18
|
+
* Transport → broadcast-room: task:created {taskId, type, content, files?}
|
|
19
|
+
*
|
|
20
|
+
* 2. Agent → Transport: llmservice:response {taskId, content}
|
|
21
|
+
* Transport → Client (direct): llmservice:response
|
|
22
|
+
* Transport → broadcast-room: llmservice:response (for TUI monitoring)
|
|
23
|
+
*
|
|
24
|
+
* 3. Agent → Transport: task:completed {taskId}
|
|
25
|
+
* Transport → Client (direct): task:completed
|
|
26
|
+
* Transport → broadcast-room: task:completed (for TUI monitoring)
|
|
27
|
+
*
|
|
28
|
+
* Special events:
|
|
29
|
+
* - agent:register: Agent identifies itself
|
|
30
|
+
* - agent:connected / agent:disconnected: Broadcast to all clients
|
|
31
|
+
* - broadcast-room: TUI joins this room to monitor all events
|
|
32
|
+
*/
|
|
33
|
+
import type { ITransportServer } from '../../core/interfaces/transport/i-transport-server.js';
|
|
34
|
+
/**
|
|
35
|
+
* TransportHandlers - Routes messages between clients and Agent.
|
|
36
|
+
*
|
|
37
|
+
* This class is the "brain" of the Transport Process.
|
|
38
|
+
* It knows which client is the Agent and routes messages accordingly.
|
|
39
|
+
*/
|
|
40
|
+
export declare class TransportHandlers {
|
|
41
|
+
/** The Agent's client ID (set when Agent registers) */
|
|
42
|
+
private agentClientId;
|
|
43
|
+
/** Track active tasks */
|
|
44
|
+
private tasks;
|
|
45
|
+
/** Transport server reference */
|
|
46
|
+
private readonly transport;
|
|
47
|
+
constructor(transport: ITransportServer);
|
|
48
|
+
/**
|
|
49
|
+
* Cleanup handlers.
|
|
50
|
+
*/
|
|
51
|
+
cleanup(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Setup all message handlers.
|
|
54
|
+
*/
|
|
55
|
+
setup(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Handle Agent registration.
|
|
58
|
+
* Agent connects as Socket.IO client and sends 'agent:register'.
|
|
59
|
+
*/
|
|
60
|
+
private handleAgentRegister;
|
|
61
|
+
/**
|
|
62
|
+
* Handle task:cancel request from client.
|
|
63
|
+
* Returns success:false if task not found or Agent not available.
|
|
64
|
+
* Emits task:cancelled terminal event when cancelled locally (no Agent).
|
|
65
|
+
*/
|
|
66
|
+
private handleTaskCancel;
|
|
67
|
+
/**
|
|
68
|
+
* Handle task:cancelled from Agent.
|
|
69
|
+
* Terminal event: task was cancelled before completion.
|
|
70
|
+
* Route to task owner + broadcast-room, then cleanup.
|
|
71
|
+
*/
|
|
72
|
+
private handleTaskCancelled;
|
|
73
|
+
/**
|
|
74
|
+
* Handle task:completed from Agent.
|
|
75
|
+
* Route directly to task owner + broadcast-room for monitoring.
|
|
76
|
+
*/
|
|
77
|
+
private handleTaskCompleted;
|
|
78
|
+
/**
|
|
79
|
+
* Handle task:create request from client.
|
|
80
|
+
* Validate taskId from client, add to tracking, forward to Agent.
|
|
81
|
+
*/
|
|
82
|
+
private handleTaskCreate;
|
|
83
|
+
/**
|
|
84
|
+
* Handle task:error from Agent.
|
|
85
|
+
* Route directly to task owner + broadcast-room for monitoring.
|
|
86
|
+
*/
|
|
87
|
+
private handleTaskError;
|
|
88
|
+
/**
|
|
89
|
+
* Handle task:started from Agent.
|
|
90
|
+
* Route directly to task owner + broadcast-room for monitoring.
|
|
91
|
+
*/
|
|
92
|
+
private handleTaskStarted;
|
|
93
|
+
private registerLlmEvent;
|
|
94
|
+
/**
|
|
95
|
+
* Generic handler for routing LLM events from Agent to clients.
|
|
96
|
+
* Routes directly to task owner + broadcast-room for monitoring.
|
|
97
|
+
*
|
|
98
|
+
* All llmservice:* events follow the same routing pattern:
|
|
99
|
+
* 1. Extract taskId from payload
|
|
100
|
+
* 2. Check if task is still active (not completed/cancelled/errored)
|
|
101
|
+
* 3. Send to task owner + broadcast-room if active
|
|
102
|
+
* 4. Drop silently if task already ended (prevents events-after-terminal)
|
|
103
|
+
*/
|
|
104
|
+
private routeLlmEvent;
|
|
105
|
+
/**
|
|
106
|
+
* Setup agent control handlers.
|
|
107
|
+
* These handle commands to control the Agent process (restart, etc.)
|
|
108
|
+
*/
|
|
109
|
+
private setupAgentControlHandlers;
|
|
110
|
+
/**
|
|
111
|
+
* Setup Agent-related handlers.
|
|
112
|
+
* These handle events FROM the Agent.
|
|
113
|
+
*/
|
|
114
|
+
private setupAgentHandlers;
|
|
115
|
+
/**
|
|
116
|
+
* Setup client-related handlers.
|
|
117
|
+
* These handle events FROM clients (TUI, external CLIs).
|
|
118
|
+
*/
|
|
119
|
+
private setupClientHandlers;
|
|
120
|
+
/**
|
|
121
|
+
* Setup connection event handlers.
|
|
122
|
+
*/
|
|
123
|
+
private setupConnectionHandlers;
|
|
124
|
+
}
|