byterover-cli 1.7.2 → 2.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 +65 -551
- package/bin/kill-daemon.js +78 -0
- package/bin/run.js +2 -2
- package/dist/agent/core/domain/blob/types.d.ts +8 -2
- package/dist/agent/core/domain/llm/index.d.ts +1 -1
- package/dist/agent/core/domain/llm/index.js +1 -1
- package/dist/agent/core/domain/llm/registry.js +353 -14
- package/dist/agent/core/domain/llm/schemas.d.ts +13 -13
- package/dist/agent/core/domain/llm/schemas.js +3 -3
- package/dist/agent/core/domain/llm/types.d.ts +15 -5
- package/dist/agent/core/domain/llm/types.js +8 -2
- package/dist/agent/core/domain/sandbox/types.d.ts +6 -0
- package/dist/agent/core/domain/session/session-metadata.d.ts +7 -2
- package/dist/agent/core/domain/session/session-metadata.js +14 -4
- package/dist/agent/core/domain/streaming/types.d.ts +2 -0
- package/dist/agent/core/domain/tools/constants.d.ts +0 -15
- package/dist/agent/core/domain/tools/constants.js +0 -15
- package/dist/agent/core/domain/tools/types.d.ts +2 -0
- package/dist/agent/core/interfaces/i-chat-session.d.ts +1 -1
- package/dist/agent/core/interfaces/i-cipher-agent.d.ts +68 -0
- package/dist/agent/core/interfaces/i-curate-service.d.ts +34 -7
- package/dist/agent/core/interfaces/i-history-storage.d.ts +8 -0
- package/dist/agent/core/interfaces/i-key-storage.d.ts +11 -0
- package/dist/agent/core/interfaces/i-llm-service.d.ts +1 -1
- package/dist/agent/core/interfaces/i-sandbox-service.d.ts +26 -0
- package/dist/agent/core/interfaces/i-session-persistence.d.ts +3 -36
- package/dist/agent/core/interfaces/i-session-persistence.js +1 -1
- package/dist/agent/infra/agent/agent-schemas.d.ts +26 -5
- package/dist/agent/infra/agent/agent-schemas.js +10 -3
- package/dist/agent/infra/agent/cipher-agent.d.ts +87 -2
- package/dist/agent/infra/agent/cipher-agent.js +191 -16
- package/dist/agent/infra/agent/interactive-loop.js +1 -5
- package/dist/agent/infra/agent/provider-update-config.d.ts +19 -0
- package/dist/agent/infra/agent/service-initializer.d.ts +27 -6
- package/dist/agent/infra/agent/service-initializer.js +46 -60
- package/dist/agent/infra/blob/blob-storage-factory.d.ts +1 -1
- package/dist/agent/infra/blob/blob-storage-factory.js +1 -1
- package/dist/agent/infra/blob/sqlite-blob-storage.js +8 -5
- package/dist/agent/infra/file-system/file-system-service.js +6 -3
- package/dist/agent/infra/http/internal-llm-http-service.d.ts +9 -5
- package/dist/agent/infra/http/internal-llm-http-service.js +12 -7
- package/dist/agent/infra/llm/agent-llm-service.d.ts +420 -0
- package/dist/agent/infra/llm/agent-llm-service.js +1291 -0
- package/dist/agent/infra/llm/context/compaction/compaction-service.d.ts +14 -12
- package/dist/agent/infra/llm/context/compaction/compaction-service.js +26 -9
- package/dist/agent/infra/llm/context/compression/reactive-overflow.js +12 -3
- package/dist/agent/infra/llm/context/context-manager.d.ts +44 -3
- package/dist/agent/infra/llm/context/context-manager.js +203 -98
- package/dist/agent/infra/llm/context/deferred-effects.d.ts +30 -0
- package/dist/agent/infra/llm/context/deferred-effects.js +40 -0
- package/dist/agent/infra/llm/formatters/gemini-formatter.d.ts +1 -1
- package/dist/agent/infra/llm/formatters/gemini-formatter.js +14 -10
- package/dist/agent/infra/llm/generators/ai-sdk-content-generator.d.ts +33 -0
- package/dist/agent/infra/llm/generators/ai-sdk-content-generator.js +166 -0
- package/dist/agent/infra/llm/generators/ai-sdk-message-converter.d.ts +20 -0
- package/dist/agent/infra/llm/generators/ai-sdk-message-converter.js +182 -0
- package/dist/agent/infra/llm/generators/index.d.ts +3 -3
- package/dist/agent/infra/llm/generators/index.js +3 -3
- package/dist/agent/infra/llm/generators/retryable-content-generator.d.ts +7 -0
- package/dist/agent/infra/llm/generators/retryable-content-generator.js +29 -5
- package/dist/agent/infra/llm/index.d.ts +1 -2
- package/dist/agent/infra/llm/index.js +2 -3
- package/dist/agent/infra/llm/model-capabilities.d.ts +1 -0
- package/dist/agent/infra/llm/model-capabilities.js +31 -0
- package/dist/agent/infra/llm/providers/anthropic.d.ts +7 -0
- package/dist/agent/infra/llm/providers/anthropic.js +27 -0
- package/dist/agent/infra/llm/providers/byterover.d.ts +9 -0
- package/dist/agent/infra/llm/providers/byterover.js +37 -0
- package/dist/agent/infra/llm/providers/cerebras.d.ts +7 -0
- package/dist/agent/infra/llm/providers/cerebras.js +31 -0
- package/dist/agent/infra/llm/providers/cohere.d.ts +7 -0
- package/dist/agent/infra/llm/providers/cohere.js +26 -0
- package/dist/agent/infra/llm/providers/deepinfra.d.ts +7 -0
- package/dist/agent/infra/llm/providers/deepinfra.js +26 -0
- package/dist/agent/infra/llm/providers/glm.d.ts +7 -0
- package/dist/agent/infra/llm/providers/glm.js +30 -0
- package/dist/agent/infra/llm/providers/google-vertex.d.ts +15 -0
- package/dist/agent/infra/llm/providers/google-vertex.js +36 -0
- package/dist/agent/infra/llm/providers/google.d.ts +7 -0
- package/dist/agent/infra/llm/providers/google.js +25 -0
- package/dist/agent/infra/llm/providers/groq.d.ts +7 -0
- package/dist/agent/infra/llm/providers/groq.js +26 -0
- package/dist/agent/infra/llm/providers/index.d.ts +24 -0
- package/dist/agent/infra/llm/providers/index.js +75 -0
- package/dist/agent/infra/llm/providers/minimax.d.ts +7 -0
- package/dist/agent/infra/llm/providers/minimax.js +30 -0
- package/dist/agent/infra/llm/providers/mistral.d.ts +7 -0
- package/dist/agent/infra/llm/providers/mistral.js +26 -0
- package/dist/agent/infra/llm/providers/moonshot.d.ts +7 -0
- package/dist/agent/infra/llm/providers/moonshot.js +30 -0
- package/dist/agent/infra/llm/providers/openai-compatible.d.ts +9 -0
- package/dist/agent/infra/llm/providers/openai-compatible.js +30 -0
- package/dist/agent/infra/llm/providers/openai.d.ts +7 -0
- package/dist/agent/infra/llm/providers/openai.js +26 -0
- package/dist/agent/infra/llm/providers/openrouter.d.ts +7 -0
- package/dist/agent/infra/llm/providers/openrouter.js +26 -0
- package/dist/agent/infra/llm/providers/perplexity.d.ts +7 -0
- package/dist/agent/infra/llm/providers/perplexity.js +26 -0
- package/dist/agent/infra/llm/providers/togetherai.d.ts +7 -0
- package/dist/agent/infra/llm/providers/togetherai.js +26 -0
- package/dist/agent/infra/llm/providers/types.d.ts +81 -0
- package/dist/agent/infra/llm/providers/types.js +7 -0
- package/dist/agent/infra/llm/providers/vercel.d.ts +7 -0
- package/dist/agent/infra/llm/providers/vercel.js +32 -0
- package/dist/agent/infra/llm/providers/xai.d.ts +7 -0
- package/dist/agent/infra/llm/providers/xai.js +26 -0
- package/dist/agent/infra/llm/retry/retry-policy.d.ts +13 -0
- package/dist/agent/infra/llm/retry/retry-policy.js +207 -0
- package/dist/agent/infra/llm/tokenizers/openrouter-tokenizer.js +1 -1
- package/dist/agent/infra/llm/tool-output-processor.d.ts +16 -4
- package/dist/agent/infra/llm/tool-output-processor.js +61 -16
- package/dist/agent/infra/sandbox/curate-result-collector.d.ts +30 -0
- package/dist/agent/infra/sandbox/curate-result-collector.js +39 -0
- package/dist/agent/infra/sandbox/curate-service.d.ts +4 -1
- package/dist/agent/infra/sandbox/curate-service.js +12 -3
- package/dist/agent/infra/sandbox/local-sandbox.d.ts +13 -0
- package/dist/agent/infra/sandbox/local-sandbox.js +41 -4
- package/dist/agent/infra/sandbox/sandbox-service.d.ts +40 -5
- package/dist/agent/infra/sandbox/sandbox-service.js +97 -14
- package/dist/agent/infra/sandbox/tools-sdk.d.ts +42 -4
- package/dist/agent/infra/sandbox/tools-sdk.js +29 -4
- package/dist/agent/infra/session/chat-session.d.ts +1 -1
- package/dist/agent/infra/session/chat-session.js +2 -2
- package/dist/agent/infra/session/session-event-forwarder.js +6 -3
- package/dist/agent/infra/session/session-manager.d.ts +12 -2
- package/dist/agent/infra/session/session-manager.js +25 -8
- package/dist/agent/infra/session/session-metadata-store.d.ts +17 -10
- package/dist/agent/infra/session/session-metadata-store.js +12 -87
- package/dist/agent/infra/storage/blob-history-storage.d.ts +5 -0
- package/dist/agent/infra/storage/blob-history-storage.js +15 -0
- package/dist/agent/infra/storage/dual-format-history-storage.d.ts +6 -0
- package/dist/agent/infra/storage/dual-format-history-storage.js +16 -0
- package/dist/agent/infra/storage/message-storage-service.js +134 -22
- package/dist/agent/infra/storage/sqlite-key-storage.d.ts +8 -0
- package/dist/agent/infra/storage/sqlite-key-storage.js +47 -13
- package/dist/agent/infra/system-prompt/contributors/context-tree-structure-contributor.js +3 -3
- package/dist/agent/infra/tools/implementations/code-exec-tool.js +43 -2
- package/dist/agent/infra/tools/implementations/curate-tool.d.ts +221 -22
- package/dist/agent/infra/tools/implementations/curate-tool.js +100 -23
- package/dist/agent/infra/tools/implementations/memory-path-matcher.d.ts +48 -0
- package/dist/agent/infra/tools/implementations/memory-path-matcher.js +217 -0
- package/dist/agent/infra/tools/implementations/memory-symbol-tree.d.ts +101 -0
- package/dist/agent/infra/tools/implementations/memory-symbol-tree.js +259 -0
- package/dist/agent/infra/tools/implementations/search-knowledge-service.d.ts +48 -6
- package/dist/agent/infra/tools/implementations/search-knowledge-service.js +394 -41
- package/dist/agent/infra/tools/implementations/search-knowledge-tool.d.ts +2 -1
- package/dist/agent/infra/tools/implementations/search-knowledge-tool.js +50 -6
- package/dist/agent/infra/tools/index.d.ts +0 -4
- package/dist/agent/infra/tools/index.js +0 -4
- package/dist/agent/infra/tools/tool-registry.js +2 -115
- package/dist/agent/infra/transport/transport-event-bridge.d.ts +42 -0
- package/dist/agent/infra/transport/transport-event-bridge.js +90 -0
- package/dist/agent/infra/validation/workspace-validator.d.ts +3 -3
- package/dist/agent/infra/validation/workspace-validator.js +3 -8
- package/dist/agent/resources/prompts/curate-detail-preservation.yml +101 -0
- package/dist/agent/resources/prompts/system-prompt.yml +404 -94
- package/dist/agent/resources/tools/code_exec.txt +97 -0
- package/dist/agent/resources/tools/curate.txt +25 -13
- package/dist/agent/resources/tools/detect_domains.txt +4 -3
- package/dist/oclif/commands/connectors/index.d.ts +12 -0
- package/dist/oclif/commands/connectors/index.js +53 -0
- package/dist/oclif/commands/connectors/install.d.ts +31 -0
- package/dist/oclif/commands/connectors/install.js +148 -0
- package/dist/oclif/commands/connectors/list.d.ts +5 -0
- package/dist/oclif/commands/connectors/list.js +8 -0
- package/dist/oclif/commands/curate/index.d.ts +25 -0
- package/dist/oclif/commands/curate/index.js +256 -0
- package/dist/oclif/commands/curate/view.d.ts +18 -0
- package/dist/oclif/commands/curate/view.js +104 -0
- package/dist/oclif/commands/debug.d.ts +35 -0
- package/dist/oclif/commands/debug.js +436 -0
- package/dist/oclif/commands/hub/index.d.ts +5 -0
- package/dist/oclif/commands/hub/index.js +7 -0
- package/dist/oclif/commands/hub/install.d.ts +23 -0
- package/dist/oclif/commands/hub/install.js +74 -0
- package/dist/oclif/commands/hub/list.d.ts +13 -0
- package/dist/oclif/commands/hub/list.js +65 -0
- package/dist/oclif/commands/hub/registry/add.d.ts +19 -0
- package/dist/oclif/commands/hub/registry/add.js +74 -0
- package/dist/oclif/commands/hub/registry/index.d.ts +5 -0
- package/dist/oclif/commands/hub/registry/index.js +7 -0
- package/dist/oclif/commands/hub/registry/list.d.ts +12 -0
- package/dist/oclif/commands/hub/registry/list.js +49 -0
- package/dist/oclif/commands/hub/registry/remove.d.ts +15 -0
- package/dist/oclif/commands/hub/registry/remove.js +46 -0
- package/dist/oclif/commands/login.d.ts +4 -0
- package/dist/oclif/commands/login.js +51 -31
- package/dist/oclif/commands/main.d.ts +3 -17
- package/dist/oclif/commands/main.js +15 -96
- package/dist/oclif/commands/mcp.js +24 -5
- package/dist/oclif/commands/model/index.d.ts +15 -0
- package/dist/oclif/commands/model/index.js +59 -0
- package/dist/oclif/commands/model/list.d.ts +17 -0
- package/dist/oclif/commands/model/list.js +89 -0
- package/dist/oclif/commands/model/switch.d.ts +21 -0
- package/dist/oclif/commands/model/switch.js +81 -0
- package/dist/oclif/commands/providers/connect.d.ts +28 -0
- package/dist/oclif/commands/providers/connect.js +141 -0
- package/dist/oclif/commands/providers/disconnect.d.ts +14 -0
- package/dist/oclif/commands/providers/disconnect.js +61 -0
- package/dist/oclif/commands/providers/index.d.ts +15 -0
- package/dist/oclif/commands/providers/index.js +59 -0
- package/dist/oclif/commands/providers/list.d.ts +12 -0
- package/dist/oclif/commands/providers/list.js +45 -0
- package/dist/oclif/commands/providers/switch.d.ts +17 -0
- package/dist/oclif/commands/providers/switch.js +61 -0
- package/dist/oclif/commands/pull.d.ts +1 -6
- package/dist/oclif/commands/pull.js +46 -49
- package/dist/oclif/commands/push.d.ts +1 -7
- package/dist/oclif/commands/push.js +66 -59
- package/dist/oclif/commands/query.d.ts +5 -7
- package/dist/oclif/commands/query.js +142 -43
- package/dist/oclif/commands/restart.d.ts +95 -0
- package/dist/oclif/commands/restart.js +333 -0
- package/dist/oclif/commands/space/list.d.ts +12 -0
- package/dist/oclif/commands/space/list.js +66 -0
- package/dist/oclif/commands/space/switch.d.ts +17 -0
- package/dist/oclif/commands/space/switch.js +87 -0
- package/dist/oclif/commands/status.d.ts +4 -9
- package/dist/oclif/commands/status.js +94 -49
- package/dist/oclif/hooks/prerun/validate-brv-config-version.d.ts +16 -11
- package/dist/oclif/hooks/prerun/validate-brv-config-version.js +67 -24
- package/dist/oclif/lib/daemon-client.d.ts +40 -0
- package/dist/oclif/lib/daemon-client.js +142 -0
- package/dist/oclif/lib/json-response.d.ts +9 -0
- package/dist/oclif/lib/json-response.js +10 -0
- package/dist/oclif/lib/task-client.d.ts +68 -0
- package/dist/oclif/lib/task-client.js +227 -0
- package/dist/server/config/environment.d.ts +1 -1
- package/dist/server/config/environment.js +2 -2
- package/dist/server/constants.d.ts +30 -1
- package/dist/server/constants.js +43 -2
- package/dist/server/core/domain/client/client-info.d.ts +82 -0
- package/dist/server/core/domain/client/client-info.js +87 -0
- package/dist/server/core/domain/entities/agent.d.ts +3 -6
- package/dist/server/core/domain/entities/agent.js +49 -54
- package/dist/server/core/domain/entities/brv-config.d.ts +31 -10
- package/dist/server/core/domain/entities/brv-config.js +68 -39
- package/dist/server/core/domain/entities/connector-type.d.ts +1 -11
- package/dist/server/core/domain/entities/connector-type.js +1 -10
- package/dist/server/core/domain/entities/context-tree-snapshot.d.ts +2 -11
- package/dist/server/core/domain/entities/curate-log-entry.d.ts +41 -0
- package/dist/server/core/domain/entities/curation-status.d.ts +28 -0
- package/dist/server/core/domain/entities/provider-config.d.ts +14 -1
- package/dist/server/core/domain/entities/provider-config.js +17 -6
- package/dist/server/core/domain/entities/provider-registry.d.ts +3 -1
- package/dist/server/core/domain/entities/provider-registry.js +230 -10
- package/dist/server/core/domain/errors/task-error.d.ts +17 -4
- package/dist/server/core/domain/errors/task-error.js +35 -10
- package/dist/server/core/domain/knowledge/markdown-writer.d.ts +71 -1
- package/dist/server/core/domain/knowledge/markdown-writer.js +403 -37
- package/dist/server/core/domain/knowledge/memory-scoring.d.ts +118 -0
- package/dist/server/core/domain/knowledge/memory-scoring.js +217 -0
- package/dist/server/core/domain/knowledge/relation-parser.d.ts +16 -0
- package/dist/server/core/domain/knowledge/relation-parser.js +21 -8
- package/dist/server/core/domain/project/project-info.d.ts +54 -0
- package/dist/server/core/domain/project/project-info.js +62 -0
- package/dist/server/core/domain/transport/schemas.d.ts +97 -19
- package/dist/server/core/domain/transport/schemas.js +40 -1
- package/dist/server/core/domain/transport/task-info.d.ts +21 -0
- package/dist/server/core/interfaces/agent/i-agent-pool.d.ts +88 -0
- package/dist/server/core/interfaces/client/i-client-manager.d.ts +117 -0
- package/dist/server/core/interfaces/context-tree/i-context-file-reader.d.ts +5 -1
- package/dist/server/core/interfaces/context-tree/i-context-tree-merger.d.ts +80 -0
- package/dist/server/core/interfaces/context-tree/i-context-tree-service.d.ts +5 -0
- package/dist/server/core/interfaces/context-tree/i-context-tree-snapshot-service.d.ts +15 -0
- package/dist/server/core/interfaces/daemon/i-agent-idle-timeout-policy.d.ts +39 -0
- package/dist/server/core/interfaces/daemon/i-daemon-resilience.d.ts +24 -0
- package/dist/server/core/interfaces/daemon/i-heartbeat-writer.d.ts +28 -0
- package/dist/server/core/interfaces/daemon/i-idle-timeout-policy.d.ts +34 -0
- package/dist/server/core/interfaces/daemon/i-shutdown-handler.d.ts +20 -0
- package/dist/server/core/interfaces/daemon/index.d.ts +4 -0
- package/dist/server/core/interfaces/daemon/index.js +2 -0
- package/dist/server/core/interfaces/executor/i-curate-executor.d.ts +2 -2
- package/dist/server/core/interfaces/executor/i-query-executor.d.ts +2 -2
- package/dist/server/core/interfaces/hub/i-hub-install-service.d.ts +45 -0
- package/dist/server/core/interfaces/hub/i-hub-keychain-store.d.ts +27 -0
- package/dist/server/core/interfaces/hub/i-hub-registry-config-store.d.ts +27 -0
- package/dist/server/core/interfaces/hub/i-hub-registry-service.d.ts +30 -0
- package/dist/server/core/interfaces/hub/i-hub-registry-service.js +1 -0
- package/dist/server/core/interfaces/i-provider-config-store.d.ts +3 -1
- package/dist/server/core/interfaces/i-provider-model-fetcher.d.ts +59 -0
- package/dist/server/core/interfaces/i-provider-model-fetcher.js +7 -0
- package/dist/server/core/interfaces/process/i-task-lifecycle-hook.d.ts +27 -0
- package/dist/server/core/interfaces/process/i-task-lifecycle-hook.js +1 -0
- package/dist/server/core/interfaces/project/i-project-registry.d.ts +46 -0
- package/dist/server/core/interfaces/project/i-project-registry.js +1 -0
- package/dist/server/core/interfaces/routing/i-project-router.d.ts +45 -0
- package/dist/server/core/interfaces/routing/i-project-router.js +1 -0
- package/dist/server/core/interfaces/routing/index.d.ts +1 -0
- package/dist/server/core/interfaces/routing/index.js +1 -0
- package/dist/server/core/interfaces/session/i-session-reader.d.ts +13 -0
- package/dist/server/core/interfaces/session/i-session-reader.js +1 -0
- package/dist/server/core/interfaces/state/i-auth-state-store.d.ts +68 -0
- package/dist/server/core/interfaces/state/i-auth-state-store.js +1 -0
- package/dist/server/core/interfaces/state/i-project-state-loader.d.ts +110 -0
- package/dist/server/core/interfaces/state/i-project-state-loader.js +1 -0
- package/dist/server/core/interfaces/storage/i-curate-log-store.d.ts +20 -0
- package/dist/server/core/interfaces/storage/i-curate-log-store.js +1 -0
- package/dist/server/core/interfaces/storage/i-global-config-store.d.ts +1 -15
- package/dist/server/core/interfaces/storage/i-mcp-config-writer.d.ts +5 -1
- package/dist/server/core/interfaces/storage/i-project-config-store.d.ts +6 -1
- package/dist/server/core/interfaces/transport/i-transport-server.d.ts +12 -2
- package/dist/server/core/interfaces/usecase/i-curate-log-use-case.d.ts +12 -0
- package/dist/server/core/interfaces/usecase/i-curate-log-use-case.js +1 -0
- package/dist/server/infra/client/client-manager.d.ts +51 -0
- package/dist/server/infra/client/client-manager.js +144 -0
- package/dist/server/infra/cogit/context-tree-to-push-context-mapper.js +2 -2
- package/dist/server/infra/config/auto-init.d.ts +14 -0
- package/dist/server/infra/config/auto-init.js +18 -0
- package/dist/server/infra/config/file-config-store.d.ts +1 -0
- package/dist/server/infra/config/file-config-store.js +15 -7
- package/dist/server/infra/connectors/mcp/json-mcp-config-writer.d.ts +1 -2
- package/dist/server/infra/connectors/mcp/json-mcp-config-writer.js +9 -8
- package/dist/server/infra/connectors/mcp/mcp-connector-config.d.ts +29 -6
- package/dist/server/infra/connectors/mcp/mcp-connector-config.js +28 -1
- package/dist/server/infra/connectors/mcp/mcp-connector.js +5 -5
- package/dist/server/infra/connectors/mcp/toml-mcp-config-writer.d.ts +1 -2
- package/dist/server/infra/connectors/rules/rules-connector-config.d.ts +8 -0
- package/dist/server/infra/connectors/rules/rules-connector-config.js +8 -0
- package/dist/server/infra/connectors/rules/rules-connector.js +34 -7
- package/dist/server/infra/connectors/shared/constants.d.ts +5 -0
- package/dist/server/infra/connectors/shared/constants.js +12 -0
- package/dist/server/infra/connectors/shared/rule-segment-patcher.d.ts +29 -0
- package/dist/server/infra/connectors/shared/rule-segment-patcher.js +208 -0
- package/dist/server/infra/connectors/skill/skill-connector-config.d.ts +79 -20
- package/dist/server/infra/connectors/skill/skill-connector-config.js +74 -10
- package/dist/server/infra/connectors/skill/skill-connector.d.ts +31 -4
- package/dist/server/infra/connectors/skill/skill-connector.js +136 -39
- package/dist/server/infra/context-tree/file-context-file-reader.js +6 -2
- package/dist/server/infra/context-tree/file-context-tree-merger.d.ts +51 -0
- package/dist/server/infra/context-tree/file-context-tree-merger.js +261 -0
- package/dist/server/infra/context-tree/file-context-tree-service.d.ts +1 -0
- package/dist/server/infra/context-tree/file-context-tree-service.js +6 -1
- package/dist/server/infra/context-tree/file-context-tree-snapshot-service.d.ts +2 -4
- package/dist/server/infra/context-tree/file-context-tree-snapshot-service.js +19 -9
- package/dist/server/infra/context-tree/hash-utils.d.ts +6 -0
- package/dist/server/infra/context-tree/hash-utils.js +9 -0
- package/dist/server/infra/daemon/agent-idle-timeout-policy.d.ts +36 -0
- package/dist/server/infra/daemon/agent-idle-timeout-policy.js +89 -0
- package/dist/server/infra/daemon/agent-logger.d.ts +10 -0
- package/dist/server/infra/daemon/agent-logger.js +22 -0
- package/dist/server/infra/daemon/agent-pool.d.ts +112 -0
- package/dist/server/infra/daemon/agent-pool.js +335 -0
- package/dist/server/infra/daemon/agent-process.d.ts +21 -0
- package/dist/server/infra/daemon/agent-process.js +610 -0
- package/dist/server/infra/daemon/brv-server.d.ts +23 -0
- package/dist/server/infra/daemon/brv-server.js +405 -0
- package/dist/server/infra/daemon/daemon-resilience.d.ts +34 -0
- package/dist/server/infra/daemon/daemon-resilience.js +100 -0
- package/dist/server/infra/daemon/heartbeat.d.ts +28 -0
- package/dist/server/infra/daemon/heartbeat.js +81 -0
- package/dist/server/infra/daemon/idle-timeout-policy.d.ts +38 -0
- package/dist/server/infra/daemon/idle-timeout-policy.js +91 -0
- package/dist/server/infra/daemon/index.d.ts +5 -0
- package/dist/server/infra/daemon/index.js +11 -0
- package/dist/server/infra/daemon/port-selector.d.ts +28 -0
- package/dist/server/infra/daemon/port-selector.js +45 -0
- package/dist/server/infra/daemon/project-task-queue.d.ts +54 -0
- package/dist/server/infra/daemon/project-task-queue.js +103 -0
- package/dist/server/infra/daemon/session-resolver.d.ts +26 -0
- package/dist/server/infra/daemon/session-resolver.js +88 -0
- package/dist/server/infra/daemon/shutdown-handler.d.ts +42 -0
- package/dist/server/infra/daemon/shutdown-handler.js +101 -0
- package/dist/server/infra/executor/curate-executor.d.ts +10 -2
- package/dist/server/infra/executor/curate-executor.js +88 -14
- package/dist/server/infra/executor/direct-search-responder.d.ts +48 -0
- package/dist/server/infra/executor/direct-search-responder.js +88 -0
- package/dist/server/infra/executor/folder-pack-executor.d.ts +13 -5
- package/dist/server/infra/executor/folder-pack-executor.js +780 -39
- package/dist/server/infra/executor/query-executor.d.ts +69 -6
- package/dist/server/infra/executor/query-executor.js +313 -22
- package/dist/server/infra/executor/query-result-cache.d.ts +87 -0
- package/dist/server/infra/executor/query-result-cache.js +127 -0
- package/dist/server/infra/executor/query-similarity.d.ts +28 -0
- package/dist/server/infra/executor/query-similarity.js +41 -0
- package/dist/server/infra/http/provider-model-fetcher-registry.d.ts +31 -0
- package/dist/server/infra/http/provider-model-fetcher-registry.js +121 -0
- package/dist/server/infra/http/provider-model-fetchers.d.ts +108 -0
- package/dist/server/infra/http/provider-model-fetchers.js +582 -0
- package/dist/server/infra/hub/composite-hub-registry-service.d.ts +17 -0
- package/dist/server/infra/hub/composite-hub-registry-service.js +54 -0
- package/dist/server/infra/hub/hub-auth-headers.d.ts +11 -0
- package/dist/server/infra/hub/hub-auth-headers.js +29 -0
- package/dist/server/infra/hub/hub-install-service.d.ts +22 -0
- package/dist/server/infra/hub/hub-install-service.js +99 -0
- package/dist/server/infra/hub/hub-keychain-store.d.ts +29 -0
- package/dist/server/infra/hub/hub-keychain-store.js +98 -0
- package/dist/server/infra/hub/hub-registry-config-store.d.ts +24 -0
- package/dist/server/infra/hub/hub-registry-config-store.js +92 -0
- package/dist/server/infra/hub/hub-registry-service.d.ts +33 -0
- package/dist/server/infra/hub/hub-registry-service.js +109 -0
- package/dist/server/infra/mcp/mcp-mode-detector.d.ts +21 -0
- package/dist/server/infra/mcp/mcp-mode-detector.js +25 -0
- package/dist/server/infra/mcp/mcp-server.d.ts +15 -9
- package/dist/server/infra/mcp/mcp-server.js +84 -98
- package/dist/server/infra/mcp/tools/brv-curate-tool.d.ts +5 -10
- package/dist/server/infra/mcp/tools/brv-curate-tool.js +47 -17
- package/dist/server/infra/mcp/tools/brv-query-tool.d.ts +4 -1
- package/dist/server/infra/mcp/tools/brv-query-tool.js +39 -12
- package/dist/server/infra/mcp/tools/index.d.ts +1 -0
- package/dist/server/infra/mcp/tools/index.js +1 -0
- package/dist/server/infra/mcp/tools/resolve-client-cwd.d.ts +17 -0
- package/dist/server/infra/mcp/tools/resolve-client-cwd.js +27 -0
- package/dist/server/infra/mcp/tools/task-result-waiter.js +6 -5
- package/dist/server/infra/process/broadcast-utils.d.ts +16 -0
- package/dist/server/infra/process/broadcast-utils.js +22 -0
- package/dist/server/infra/process/connection-coordinator.d.ts +85 -0
- package/dist/server/infra/process/connection-coordinator.js +333 -0
- package/dist/server/infra/process/curate-log-handler.d.ts +35 -0
- package/dist/server/infra/process/curate-log-handler.js +179 -0
- package/dist/server/infra/process/feature-handlers.d.ts +25 -0
- package/dist/server/infra/process/feature-handlers.js +165 -0
- package/dist/server/infra/process/index.d.ts +6 -7
- package/dist/server/infra/process/index.js +5 -6
- package/dist/server/infra/process/task-router.d.ts +139 -0
- package/dist/server/infra/process/task-router.js +503 -0
- package/dist/server/infra/process/transport-handlers.d.ts +55 -117
- package/dist/server/infra/process/transport-handlers.js +50 -437
- package/dist/server/infra/process/types.d.ts +5 -0
- package/dist/server/infra/process/types.js +1 -0
- package/dist/server/infra/project/project-registry.d.ts +37 -0
- package/dist/server/infra/project/project-registry.js +147 -0
- package/dist/server/infra/provider/env-provider-detector.d.ts +33 -0
- package/dist/server/infra/provider/env-provider-detector.js +52 -0
- package/dist/server/infra/provider/provider-config-resolver.d.ts +30 -0
- package/dist/server/infra/provider/provider-config-resolver.js +167 -0
- package/dist/server/infra/provider/vertex-ai-utils.d.ts +10 -0
- package/dist/server/infra/provider/vertex-ai-utils.js +28 -0
- package/dist/server/infra/routing/project-router.d.ts +35 -0
- package/dist/server/infra/routing/project-router.js +60 -0
- package/dist/server/infra/session/session-reader.d.ts +18 -0
- package/dist/server/infra/session/session-reader.js +17 -0
- package/dist/server/infra/state/auth-state-store.d.ts +55 -0
- package/dist/server/infra/state/auth-state-store.js +111 -0
- package/dist/server/infra/state/project-state-loader.d.ts +69 -0
- package/dist/server/infra/state/project-state-loader.js +154 -0
- package/dist/server/infra/storage/file-curate-log-store.d.ts +61 -0
- package/dist/server/infra/storage/file-curate-log-store.js +198 -0
- package/dist/server/infra/storage/file-global-config-store.d.ts +0 -2
- package/dist/server/infra/storage/file-global-config-store.js +0 -19
- package/dist/server/infra/storage/file-onboarding-preference-store.d.ts +1 -1
- package/dist/server/infra/storage/file-onboarding-preference-store.js +7 -8
- package/dist/server/infra/storage/file-provider-config-store.d.ts +3 -2
- package/dist/server/infra/storage/file-provider-config-store.js +3 -3
- package/dist/server/infra/storage/file-provider-keychain-store.d.ts +31 -0
- package/dist/server/infra/storage/file-provider-keychain-store.js +110 -0
- package/dist/server/infra/storage/file-token-store.d.ts +2 -5
- package/dist/server/infra/storage/file-token-store.js +2 -5
- package/dist/server/infra/storage/provider-keychain-store.d.ts +2 -33
- package/dist/server/infra/storage/provider-keychain-store.js +4 -71
- package/dist/server/infra/storage/token-store.d.ts +3 -8
- package/dist/server/infra/storage/token-store.js +4 -11
- package/dist/server/infra/transport/agent-instance-discovery.d.ts +20 -0
- package/dist/server/infra/transport/agent-instance-discovery.js +32 -0
- package/dist/server/infra/transport/handlers/agent-dto-mapper.d.ts +6 -0
- package/dist/server/infra/transport/handlers/agent-dto-mapper.js +16 -0
- package/dist/server/infra/transport/handlers/auth-handler.d.ts +60 -0
- package/dist/server/infra/transport/handlers/auth-handler.js +257 -0
- package/dist/server/infra/transport/handlers/config-handler.d.ts +13 -0
- package/dist/server/infra/transport/handlers/config-handler.js +22 -0
- package/dist/server/infra/transport/handlers/connectors-handler.d.ts +23 -0
- package/dist/server/infra/transport/handlers/connectors-handler.js +73 -0
- package/dist/server/infra/transport/handlers/handler-types.d.ts +23 -0
- package/dist/server/infra/transport/handlers/handler-types.js +21 -0
- package/dist/server/infra/transport/handlers/hub-handler.d.ts +34 -0
- package/dist/server/infra/transport/handlers/hub-handler.js +218 -0
- package/dist/server/infra/transport/handlers/index.d.ts +26 -0
- package/dist/server/infra/transport/handlers/index.js +13 -0
- package/dist/server/infra/transport/handlers/init-handler.d.ts +50 -0
- package/dist/server/infra/transport/handlers/init-handler.js +157 -0
- package/dist/server/infra/transport/handlers/model-handler.d.ts +22 -0
- package/dist/server/infra/transport/handlers/model-handler.js +107 -0
- package/dist/server/infra/transport/handlers/provider-handler.d.ts +25 -0
- package/dist/server/infra/transport/handlers/provider-handler.js +101 -0
- package/dist/server/infra/transport/handlers/pull-handler.d.ts +35 -0
- package/dist/server/infra/transport/handlers/pull-handler.js +87 -0
- package/dist/server/infra/transport/handlers/push-handler.d.ts +37 -0
- package/dist/server/infra/transport/handlers/push-handler.js +109 -0
- package/dist/server/infra/transport/handlers/reset-handler.d.ts +23 -0
- package/dist/server/infra/transport/handlers/reset-handler.js +33 -0
- package/dist/server/infra/transport/handlers/space-handler.d.ts +44 -0
- package/dist/server/infra/transport/handlers/space-handler.js +206 -0
- package/dist/server/infra/transport/handlers/status-handler.d.ts +29 -0
- package/dist/server/infra/transport/handlers/status-handler.js +99 -0
- package/dist/server/infra/transport/index.d.ts +1 -1
- package/dist/server/infra/transport/index.js +0 -1
- package/dist/server/infra/transport/port-utils.d.ts +0 -35
- package/dist/server/infra/transport/port-utils.js +0 -62
- package/dist/server/infra/transport/socket-io-transport-server.d.ts +6 -1
- package/dist/server/infra/transport/socket-io-transport-server.js +30 -10
- package/dist/server/infra/transport/transport-connector.d.ts +13 -0
- package/dist/server/infra/transport/transport-connector.js +18 -0
- package/dist/server/infra/usecase/curate-log-use-case.d.ts +32 -0
- package/dist/server/infra/usecase/curate-log-use-case.js +142 -0
- package/dist/server/templates/sections/brv-instructions.md +8 -0
- package/dist/server/templates/sections/command-reference.md +5 -2
- package/dist/server/templates/sections/workflow.md +2 -0
- package/dist/server/templates/skill/SKILL.md +138 -59
- package/dist/server/utils/config-xdg-sync.d.ts +13 -0
- package/dist/server/utils/config-xdg-sync.js +25 -0
- package/dist/server/utils/curate-result-parser.d.ts +121 -0
- package/dist/server/utils/curate-result-parser.js +120 -0
- package/dist/server/utils/file-validator.js +78 -1
- package/dist/server/utils/global-config-path.d.ts +1 -1
- package/dist/server/utils/global-config-path.js +5 -2
- package/dist/server/utils/global-data-path.d.ts +2 -2
- package/dist/server/utils/global-data-path.js +8 -3
- package/dist/server/utils/path-utils.d.ts +38 -0
- package/dist/server/utils/path-utils.js +92 -0
- package/dist/server/utils/process-logger.js +1 -1
- package/dist/server/utils/server-main-resolver.d.ts +9 -0
- package/dist/server/utils/server-main-resolver.js +17 -0
- package/dist/shared/transport/events/agent-events.d.ts +16 -0
- package/dist/shared/transport/events/agent-events.js +10 -0
- package/dist/shared/transport/events/auth-events.d.ts +45 -0
- package/dist/shared/transport/events/auth-events.js +11 -0
- package/dist/shared/transport/events/config-events.d.ts +18 -0
- package/dist/shared/transport/events/config-events.js +5 -0
- package/dist/shared/transport/events/connector-events.d.ts +35 -0
- package/dist/shared/transport/events/connector-events.js +6 -0
- package/dist/shared/transport/events/hub-events.d.ts +62 -0
- package/dist/shared/transport/events/hub-events.js +10 -0
- package/dist/shared/transport/events/index.d.ts +123 -0
- package/dist/shared/transport/events/index.js +73 -0
- package/dist/shared/transport/events/init-events.d.ts +41 -0
- package/dist/shared/transport/events/init-events.js +8 -0
- package/dist/shared/transport/events/llm-events.d.ts +13 -0
- package/dist/shared/transport/events/llm-events.js +13 -0
- package/dist/shared/transport/events/model-events.d.ts +30 -0
- package/dist/shared/transport/events/model-events.js +5 -0
- package/dist/shared/transport/events/onboarding-events.d.ts +18 -0
- package/dist/shared/transport/events/onboarding-events.js +5 -0
- package/dist/shared/transport/events/provider-events.d.ts +44 -0
- package/dist/shared/transport/events/provider-events.js +8 -0
- package/dist/shared/transport/events/pull-events.d.ts +26 -0
- package/dist/shared/transport/events/pull-events.js +5 -0
- package/dist/shared/transport/events/push-events.d.ts +27 -0
- package/dist/shared/transport/events/push-events.js +5 -0
- package/dist/shared/transport/events/reset-events.d.ts +6 -0
- package/dist/shared/transport/events/reset-events.js +3 -0
- package/dist/shared/transport/events/session-events.d.ts +3 -0
- package/dist/shared/transport/events/session-events.js +3 -0
- package/dist/shared/transport/events/space-events.d.ts +30 -0
- package/dist/shared/transport/events/space-events.js +4 -0
- package/dist/shared/transport/events/status-events.d.ts +7 -0
- package/dist/shared/transport/events/status-events.js +3 -0
- package/dist/shared/transport/events/task-events.d.ts +19 -0
- package/dist/shared/transport/events/task-events.js +9 -0
- package/dist/shared/transport/types/auth-scheme.d.ts +1 -0
- package/dist/shared/transport/types/auth-scheme.js +1 -0
- package/dist/shared/transport/types/dto.d.ts +112 -0
- package/dist/shared/transport/types/dto.js +6 -0
- package/dist/shared/transport/types/index.d.ts +1 -0
- package/dist/shared/transport/types/index.js +1 -0
- package/dist/shared/types/agent.d.ts +5 -0
- package/dist/shared/types/agent.js +27 -0
- package/dist/shared/types/connector-type.d.ts +18 -0
- package/dist/shared/types/connector-type.js +26 -0
- package/dist/shared/types/context-tree-changes.d.ts +11 -0
- package/dist/shared/types/context-tree-changes.js +1 -0
- package/dist/shared/types/index.d.ts +3 -0
- package/dist/shared/types/index.js +2 -0
- package/dist/tui/app/index.d.ts +9 -0
- package/dist/tui/app/index.js +4 -0
- package/dist/tui/app/layouts/main-layout.d.ts +14 -0
- package/dist/tui/app/layouts/main-layout.js +19 -0
- package/dist/tui/app/pages/config-provider-page.d.ts +8 -0
- package/dist/tui/app/pages/config-provider-page.js +19 -0
- package/dist/tui/app/pages/home-page.d.ts +8 -0
- package/dist/tui/app/pages/home-page.js +85 -0
- package/dist/tui/app/pages/login-page.d.ts +12 -0
- package/dist/tui/app/pages/login-page.js +87 -0
- package/dist/tui/app/pages/protected-routes.d.ts +8 -0
- package/dist/tui/app/pages/protected-routes.js +14 -0
- package/dist/tui/app/router.d.ts +11 -0
- package/dist/tui/app/router.js +21 -0
- package/dist/tui/components/command/command-output.d.ts +1 -1
- package/dist/tui/components/command/command-output.js +5 -7
- package/dist/tui/components/command/expanded-command-view.d.ts +1 -1
- package/dist/tui/components/command/expanded-command-view.js +5 -6
- package/dist/tui/components/command/live-streaming-output.d.ts +2 -4
- package/dist/tui/components/command/live-streaming-output.js +5 -19
- package/dist/tui/components/command-details.d.ts +1 -1
- package/dist/tui/components/command-details.js +3 -3
- package/dist/tui/components/command-input.js +84 -171
- package/dist/tui/components/command-item.d.ts +1 -1
- package/dist/tui/components/command-item.js +6 -7
- package/dist/tui/components/execution/execution-status.d.ts +1 -1
- package/dist/tui/components/execution/execution-tool.d.ts +1 -1
- package/dist/tui/components/execution/expanded-log-view.d.ts +1 -1
- package/dist/tui/components/execution/expanded-log-view.js +1 -1
- package/dist/tui/components/execution/log-item.d.ts +1 -1
- package/dist/tui/components/execution/log-item.js +1 -1
- package/dist/tui/components/footer.js +6 -4
- package/dist/tui/components/header.js +2 -2
- package/dist/tui/components/index.d.ts +0 -2
- package/dist/tui/components/index.js +0 -2
- package/dist/tui/components/init.d.ts +1 -1
- package/dist/tui/components/init.js +26 -32
- package/dist/tui/components/inline-prompts/inline-file-selector.d.ts +1 -1
- package/dist/tui/components/inline-prompts/inline-input.d.ts +6 -0
- package/dist/tui/components/inline-prompts/inline-input.js +53 -16
- package/dist/tui/components/inline-prompts/inline-search.d.ts +2 -2
- package/dist/tui/components/inline-prompts/inline-search.js +1 -1
- package/dist/tui/components/inline-prompts/inline-select.d.ts +1 -1
- package/dist/tui/components/inline-prompts/inline-select.js +1 -1
- package/dist/tui/components/message-item.d.ts +1 -1
- package/dist/tui/components/message-item.js +2 -2
- package/dist/tui/components/onboarding/welcome-box.d.ts +1 -8
- package/dist/tui/components/onboarding/welcome-box.js +11 -12
- package/dist/tui/components/onboarding-item.d.ts +1 -1
- package/dist/tui/components/selectable-list.d.ts +3 -1
- package/dist/tui/components/selectable-list.js +7 -15
- package/dist/tui/components/status-badge.js +1 -1
- package/dist/tui/components/suggestions.js +5 -18
- package/dist/tui/features/activity/hooks/index.d.ts +2 -0
- package/dist/tui/features/activity/hooks/index.js +2 -0
- package/dist/tui/features/activity/hooks/use-activity-logs.d.ts +18 -0
- package/dist/tui/features/activity/hooks/use-activity-logs.js +208 -0
- package/dist/tui/features/activity/hooks/use-feed-navigation.d.ts +24 -0
- package/dist/tui/features/activity/hooks/use-feed-navigation.js +43 -0
- package/dist/tui/features/activity/index.d.ts +1 -0
- package/dist/tui/features/activity/index.js +1 -0
- package/dist/tui/features/auth/api/get-auth-state.d.ts +16 -0
- package/dist/tui/features/auth/api/get-auth-state.js +21 -0
- package/dist/tui/features/auth/api/login.d.ts +3 -0
- package/dist/tui/features/auth/api/login.js +14 -0
- package/dist/tui/features/auth/api/logout.d.ts +8 -0
- package/dist/tui/features/auth/api/logout.js +24 -0
- package/dist/tui/features/auth/api/refresh-auth.d.ts +8 -0
- package/dist/tui/features/auth/api/refresh-auth.js +24 -0
- package/dist/tui/features/auth/components/auth-initializer.d.ts +10 -0
- package/dist/tui/features/auth/components/auth-initializer.js +82 -0
- package/dist/tui/features/auth/components/login-flow.d.ts +8 -0
- package/dist/tui/features/auth/components/login-flow.js +62 -0
- package/dist/tui/features/auth/components/logout-flow.d.ts +12 -0
- package/dist/tui/features/auth/components/logout-flow.js +81 -0
- package/dist/tui/features/auth/guards/auth-guard.d.ts +2 -0
- package/dist/tui/features/auth/guards/auth-guard.js +11 -0
- package/dist/tui/features/auth/stores/auth-store.d.ts +27 -0
- package/dist/tui/features/auth/stores/auth-store.js +29 -0
- package/dist/tui/features/commands/components/command-view.d.ts +17 -0
- package/dist/tui/features/commands/components/command-view.js +34 -0
- package/dist/tui/features/commands/definitions/connectors.d.ts +2 -0
- package/dist/tui/features/commands/definitions/connectors.js +9 -0
- package/dist/tui/features/commands/definitions/curate.d.ts +2 -0
- package/dist/tui/features/commands/definitions/curate.js +53 -0
- package/dist/tui/features/commands/definitions/hub-list.d.ts +2 -0
- package/dist/tui/features/commands/definitions/hub-list.js +9 -0
- package/dist/tui/features/commands/definitions/hub-registry-add.d.ts +2 -0
- package/dist/tui/features/commands/definitions/hub-registry-add.js +36 -0
- package/dist/tui/features/commands/definitions/hub-registry-list.d.ts +2 -0
- package/dist/tui/features/commands/definitions/hub-registry-list.js +9 -0
- package/dist/tui/features/commands/definitions/hub-registry-remove.d.ts +2 -0
- package/dist/tui/features/commands/definitions/hub-registry-remove.js +25 -0
- package/dist/tui/features/commands/definitions/hub-registry.d.ts +2 -0
- package/dist/tui/features/commands/definitions/hub-registry.js +8 -0
- package/dist/tui/features/commands/definitions/hub.d.ts +2 -0
- package/dist/tui/features/commands/definitions/hub.js +7 -0
- package/dist/tui/features/commands/definitions/index.d.ts +8 -0
- package/dist/tui/features/commands/definitions/index.js +45 -0
- package/dist/tui/features/commands/definitions/login.d.ts +2 -0
- package/dist/tui/features/commands/definitions/login.js +12 -0
- package/dist/tui/features/commands/definitions/logout.d.ts +2 -0
- package/dist/tui/features/commands/definitions/logout.js +26 -0
- package/dist/tui/features/commands/definitions/model.d.ts +2 -0
- package/dist/tui/features/commands/definitions/model.js +9 -0
- package/dist/tui/features/commands/definitions/new.d.ts +2 -0
- package/dist/tui/features/commands/definitions/new.js +27 -0
- package/dist/tui/features/commands/definitions/providers.d.ts +2 -0
- package/dist/tui/features/commands/definitions/providers.js +9 -0
- package/dist/tui/features/commands/definitions/pull.d.ts +2 -0
- package/dist/tui/features/commands/definitions/pull.js +23 -0
- package/dist/tui/features/commands/definitions/push.d.ts +2 -0
- package/dist/tui/features/commands/definitions/push.js +29 -0
- package/dist/tui/features/commands/definitions/query.d.ts +2 -0
- package/dist/tui/features/commands/definitions/query.js +36 -0
- package/dist/tui/features/commands/definitions/reset.d.ts +2 -0
- package/dist/tui/features/commands/definitions/reset.js +22 -0
- package/dist/tui/features/commands/definitions/space-list.d.ts +2 -0
- package/dist/tui/features/commands/definitions/space-list.js +22 -0
- package/dist/tui/features/commands/definitions/space-switch.d.ts +2 -0
- package/dist/tui/features/commands/definitions/space-switch.js +9 -0
- package/dist/tui/features/commands/definitions/space.d.ts +2 -0
- package/dist/tui/features/commands/definitions/space.js +7 -0
- package/dist/tui/features/commands/definitions/status.d.ts +2 -0
- package/dist/tui/features/commands/definitions/status.js +11 -0
- package/dist/tui/features/commands/hooks/use-commands-controller.d.ts +38 -0
- package/dist/tui/features/commands/hooks/use-commands-controller.js +43 -0
- package/dist/tui/features/commands/hooks/use-slash-command-processor.d.ts +16 -0
- package/dist/tui/features/commands/hooks/use-slash-command-processor.js +134 -0
- package/dist/tui/features/commands/hooks/use-slash-completion.d.ts +30 -0
- package/dist/tui/features/commands/hooks/use-slash-completion.js +256 -0
- package/dist/tui/features/commands/stores/commands-store.d.ts +32 -0
- package/dist/tui/features/commands/stores/commands-store.js +23 -0
- package/dist/tui/features/commands/utils/arg-parser.d.ts +102 -0
- package/dist/tui/features/connectors/api/get-agent-config-paths.d.ts +18 -0
- package/dist/tui/features/connectors/api/get-agent-config-paths.js +17 -0
- package/dist/tui/features/connectors/api/get-agents.d.ts +16 -0
- package/dist/tui/features/connectors/api/get-agents.js +19 -0
- package/dist/tui/features/connectors/api/get-connectors.d.ts +16 -0
- package/dist/tui/features/connectors/api/get-connectors.js +17 -0
- package/dist/tui/features/connectors/api/install-connector.d.ts +14 -0
- package/dist/tui/features/connectors/api/install-connector.js +27 -0
- package/dist/tui/features/connectors/components/agent-search-step.d.ts +9 -0
- package/dist/tui/features/connectors/components/agent-search-step.js +18 -0
- package/dist/tui/features/connectors/components/confirm-switch-step.d.ts +10 -0
- package/dist/tui/features/connectors/components/confirm-switch-step.js +13 -0
- package/dist/tui/features/connectors/components/connector-list-step.d.ts +11 -0
- package/dist/tui/features/connectors/components/connector-list-step.js +29 -0
- package/dist/tui/features/connectors/components/connector-type-step.d.ts +13 -0
- package/dist/tui/features/connectors/components/connector-type-step.js +23 -0
- package/dist/tui/features/connectors/components/connectors-flow.d.ts +17 -0
- package/dist/tui/features/connectors/components/connectors-flow.js +179 -0
- package/dist/tui/features/connectors/utils/get-connector-name.d.ts +3 -0
- package/dist/tui/features/connectors/utils/get-connector-name.js +33 -0
- package/dist/tui/features/curate/api/create-curate-task.d.ts +22 -0
- package/dist/tui/features/curate/api/create-curate-task.js +40 -0
- package/dist/tui/features/curate/components/curate-flow.d.ts +20 -0
- package/dist/tui/features/curate/components/curate-flow.js +41 -0
- package/dist/tui/features/hub/api/add-hub-registry.d.ts +15 -0
- package/dist/tui/features/hub/api/add-hub-registry.js +30 -0
- package/dist/tui/features/hub/api/get-hub-entries.d.ts +16 -0
- package/dist/tui/features/hub/api/get-hub-entries.js +17 -0
- package/dist/tui/features/hub/api/install-hub-entry.d.ts +14 -0
- package/dist/tui/features/hub/api/install-hub-entry.js +24 -0
- package/dist/tui/features/hub/api/list-hub-registries.d.ts +16 -0
- package/dist/tui/features/hub/api/list-hub-registries.js +17 -0
- package/dist/tui/features/hub/api/remove-hub-registry.d.ts +11 -0
- package/dist/tui/features/hub/api/remove-hub-registry.js +24 -0
- package/dist/tui/features/hub/components/hub-agent-step.d.ts +8 -0
- package/dist/tui/features/hub/components/hub-agent-step.js +14 -0
- package/dist/tui/features/hub/components/hub-detail-step.d.ts +10 -0
- package/dist/tui/features/hub/components/hub-detail-step.js +25 -0
- package/dist/tui/features/hub/components/hub-flow.d.ts +7 -0
- package/dist/tui/features/hub/components/hub-flow.js +90 -0
- package/dist/tui/features/hub/components/hub-list-step.d.ts +10 -0
- package/dist/tui/features/hub/components/hub-list-step.js +34 -0
- package/dist/tui/features/hub/components/hub-registry-add-view.d.ts +12 -0
- package/dist/tui/features/hub/components/hub-registry-add-view.js +36 -0
- package/dist/tui/features/hub/components/hub-registry-list-view.d.ts +7 -0
- package/dist/tui/features/hub/components/hub-registry-list-view.js +38 -0
- package/dist/tui/features/hub/components/hub-registry-remove-view.d.ts +8 -0
- package/dist/tui/features/hub/components/hub-registry-remove-view.js +17 -0
- package/dist/tui/features/model/api/get-models-by-providers.d.ts +20 -0
- package/dist/tui/features/model/api/get-models-by-providers.js +17 -0
- package/dist/tui/features/model/api/get-models.d.ts +20 -0
- package/dist/tui/features/model/api/get-models.js +17 -0
- package/dist/tui/features/model/api/set-active-model.d.ts +13 -0
- package/dist/tui/features/model/api/set-active-model.js +13 -0
- package/dist/tui/features/model/components/model-dialog.d.ts +67 -0
- package/dist/tui/features/model/components/model-dialog.js +96 -0
- package/dist/tui/features/model/components/model-flow.d.ts +17 -0
- package/dist/tui/features/model/components/model-flow.js +108 -0
- package/dist/tui/features/model/stores/model-store.d.ts +35 -0
- package/dist/tui/features/model/stores/model-store.js +26 -0
- package/dist/tui/features/onboarding/api/auto-setup-onboarding.d.ts +8 -0
- package/dist/tui/features/onboarding/api/auto-setup-onboarding.js +24 -0
- package/dist/tui/features/onboarding/api/complete-onboarding.d.ts +11 -0
- package/dist/tui/features/onboarding/api/complete-onboarding.js +24 -0
- package/dist/tui/features/onboarding/api/get-onboarding-state.d.ts +16 -0
- package/dist/tui/features/onboarding/api/get-onboarding-state.js +17 -0
- package/dist/tui/features/onboarding/hooks/use-app-view-mode.d.ts +27 -0
- package/dist/tui/features/onboarding/hooks/use-app-view-mode.js +36 -0
- package/dist/tui/features/onboarding/types.d.ts +7 -0
- package/dist/tui/features/onboarding/types.js +4 -0
- package/dist/tui/features/onboarding/utils.d.ts +28 -0
- package/dist/tui/features/onboarding/utils.js +76 -0
- package/dist/tui/features/provider/api/connect-provider.d.ts +13 -0
- package/dist/tui/features/provider/api/connect-provider.js +28 -0
- package/dist/tui/features/provider/api/disconnect-provider.d.ts +11 -0
- package/dist/tui/features/provider/api/disconnect-provider.js +26 -0
- package/dist/tui/features/provider/api/get-active-provider-config.d.ts +16 -0
- package/dist/tui/features/provider/api/get-active-provider-config.js +17 -0
- package/dist/tui/features/provider/api/get-providers.d.ts +16 -0
- package/dist/tui/features/provider/api/get-providers.js +17 -0
- package/dist/tui/features/provider/api/set-active-provider.d.ts +11 -0
- package/dist/tui/features/provider/api/set-active-provider.js +24 -0
- package/dist/tui/features/provider/api/validate-api-key.d.ts +12 -0
- package/dist/tui/features/provider/api/validate-api-key.js +13 -0
- package/dist/tui/features/provider/components/api-key-dialog.d.ts +41 -0
- package/dist/tui/features/provider/components/api-key-dialog.js +126 -0
- package/dist/tui/features/provider/components/base-url-dialog.d.ts +24 -0
- package/dist/tui/features/provider/components/base-url-dialog.js +77 -0
- package/dist/tui/features/provider/components/credential-path-dialog.d.ts +30 -0
- package/dist/tui/features/provider/components/credential-path-dialog.js +85 -0
- package/dist/tui/features/provider/components/model-select-step.d.ts +20 -0
- package/dist/tui/features/provider/components/model-select-step.js +73 -0
- package/dist/tui/features/provider/components/provider-dialog.d.ts +29 -0
- package/dist/tui/features/provider/components/provider-dialog.js +20 -0
- package/dist/tui/features/provider/components/provider-flow.d.ts +25 -0
- package/dist/tui/features/provider/components/provider-flow.js +277 -0
- package/dist/tui/features/provider/stores/provider-store.d.ts +28 -0
- package/dist/tui/features/provider/stores/provider-store.js +22 -0
- package/dist/tui/features/pull/api/execute-pull.d.ts +11 -0
- package/dist/tui/features/pull/api/execute-pull.js +13 -0
- package/dist/tui/features/pull/api/prepare-pull.d.ts +20 -0
- package/dist/tui/features/pull/api/prepare-pull.js +17 -0
- package/dist/tui/features/pull/components/pull-flow.d.ts +12 -0
- package/dist/tui/features/pull/components/pull-flow.js +70 -0
- package/dist/tui/features/push/api/execute-push.d.ts +11 -0
- package/dist/tui/features/push/api/execute-push.js +13 -0
- package/dist/tui/features/push/api/prepare-push.d.ts +20 -0
- package/dist/tui/features/push/api/prepare-push.js +17 -0
- package/dist/tui/features/push/components/push-flow.d.ts +13 -0
- package/dist/tui/features/push/components/push-flow.js +86 -0
- package/dist/tui/features/query/api/create-query-task.d.ts +17 -0
- package/dist/tui/features/query/api/create-query-task.js +27 -0
- package/dist/tui/features/query/components/query-flow.d.ts +18 -0
- package/dist/tui/features/query/components/query-flow.js +36 -0
- package/dist/tui/features/reset/api/execute-reset.d.ts +8 -0
- package/dist/tui/features/reset/api/execute-reset.js +13 -0
- package/dist/tui/features/reset/components/reset-flow.d.ts +12 -0
- package/dist/tui/features/reset/components/reset-flow.js +44 -0
- package/dist/tui/features/session/components/new-session-flow.d.ts +12 -0
- package/dist/tui/features/session/components/new-session-flow.js +28 -0
- package/dist/tui/features/space/api/get-spaces.d.ts +16 -0
- package/dist/tui/features/space/api/get-spaces.js +17 -0
- package/dist/tui/features/space/api/switch-space.d.ts +11 -0
- package/dist/tui/features/space/api/switch-space.js +24 -0
- package/dist/tui/features/space/components/space-list-view.d.ts +12 -0
- package/dist/tui/features/space/components/space-list-view.js +56 -0
- package/dist/tui/features/space/components/space-switch-flow.d.ts +13 -0
- package/dist/tui/features/space/components/space-switch-flow.js +97 -0
- package/dist/tui/features/status/api/get-status.d.ts +16 -0
- package/dist/tui/features/status/api/get-status.js +17 -0
- package/dist/tui/features/status/components/status-view.d.ts +12 -0
- package/dist/tui/features/status/components/status-view.js +26 -0
- package/dist/tui/features/status/utils/format-status.d.ts +5 -0
- package/dist/tui/features/status/utils/format-status.js +62 -0
- package/dist/tui/features/tasks/components/task-subscription-initializer.d.ts +5 -0
- package/dist/tui/features/tasks/components/task-subscription-initializer.js +9 -0
- package/dist/tui/features/tasks/hooks/use-task-subscriptions.d.ts +5 -0
- package/dist/tui/features/tasks/hooks/use-task-subscriptions.js +74 -0
- package/dist/tui/features/tasks/stores/tasks-store.d.ts +92 -0
- package/dist/tui/features/tasks/stores/tasks-store.js +262 -0
- package/dist/tui/features/transport/components/transport-initializer.d.ts +13 -0
- package/dist/tui/features/transport/components/transport-initializer.js +107 -0
- package/dist/tui/features/transport/hooks/use-transport.d.ts +19 -0
- package/dist/tui/features/transport/hooks/use-transport.js +16 -0
- package/dist/tui/hooks/index.d.ts +14 -13
- package/dist/tui/hooks/index.js +15 -9
- package/dist/tui/hooks/use-terminal-breakpoint.js +3 -2
- package/dist/tui/lib/api-client.d.ts +20 -0
- package/dist/tui/lib/api-client.js +29 -0
- package/dist/tui/lib/environment.d.ts +18 -0
- package/dist/tui/lib/environment.js +18 -0
- package/dist/tui/lib/react-query.d.ts +17 -0
- package/dist/tui/lib/react-query.js +17 -0
- package/dist/tui/lib/transport-logger.d.ts +13 -0
- package/dist/tui/lib/transport-logger.js +40 -0
- package/dist/tui/providers/app-providers.d.ts +1 -16
- package/dist/tui/providers/app-providers.js +26 -4
- package/dist/tui/repl-startup.d.ts +1 -12
- package/dist/tui/repl-startup.js +6 -24
- package/dist/tui/stores/mode-store.d.ts +25 -0
- package/dist/tui/stores/mode-store.js +49 -0
- package/dist/tui/stores/theme-store.d.ts +43 -0
- package/dist/tui/stores/theme-store.js +39 -0
- package/dist/tui/stores/transport-store.d.ts +40 -0
- package/dist/tui/stores/transport-store.js +40 -0
- package/dist/tui/types/commands.d.ts +23 -91
- package/dist/tui/types/commands.js +1 -13
- package/dist/tui/types/index.d.ts +3 -4
- package/dist/tui/types/index.js +0 -2
- package/dist/tui/types/messages.d.ts +8 -1
- package/dist/tui/types/ui.d.ts +0 -5
- package/dist/tui/utils/error-messages.d.ts +22 -0
- package/dist/tui/utils/error-messages.js +45 -0
- package/dist/tui/utils/index.d.ts +2 -0
- package/dist/tui/utils/index.js +2 -0
- package/dist/tui/utils/input.d.ts +14 -0
- package/dist/tui/utils/input.js +17 -0
- package/dist/tui/utils/log.d.ts +1 -1
- package/node_modules/@campfirein/brv-transport-client/README.md +79 -338
- package/node_modules/@campfirein/brv-transport-client/dist/constants.d.ts +18 -3
- package/node_modules/@campfirein/brv-transport-client/dist/constants.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/constants.js +25 -4
- package/node_modules/@campfirein/brv-transport-client/dist/constants.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/entities/instance-info.d.ts +4 -9
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/entities/instance-info.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/entities/instance-info.js +9 -24
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/entities/instance-info.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/errors/connection-error.d.ts +20 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/errors/connection-error.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/errors/connection-error.js +30 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/errors/connection-error.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/errors/transport-error.d.ts +3 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/errors/transport-error.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/errors/transport-error.js +4 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/errors/transport-error.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/events/event-names.d.ts +10 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/events/event-names.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/events/event-names.js +10 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/events/event-names.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/events/index.d.ts +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/events/index.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/events/index.js +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/events/index.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/types.d.ts +9 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/types.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/types.js +8 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/types.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/common.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/common.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/event-name-validator.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/event-name-validator.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/index.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/index.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/room-name-validator.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/room-name-validator.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/url-validator.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/domain/validators/url-validator.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-factory-config.d.ts +150 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-factory-config.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-factory-config.js +8 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-factory-config.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-factory.d.ts +9 -4
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-factory.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-factory.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-logger.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client-logger.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-client.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-connection-state.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-connection-state.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-event-dispatcher.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-event-dispatcher.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-force-reconnect-manager.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-force-reconnect-manager.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-discovery.d.ts +9 -22
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-discovery.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-discovery.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-manager.d.ts +46 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-manager.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-manager.js +2 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-manager.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-reconnection-strategy.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-reconnection-strategy.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-room-manager.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-room-manager.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-socket-provider.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-socket-provider.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-socket.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-socket.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-spawn-lock.d.ts +27 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-spawn-lock.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-spawn-lock.js +2 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-spawn-lock.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-wake-detector.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-wake-detector.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/index.d.ts +26 -16
- package/node_modules/@campfirein/brv-transport-client/dist/index.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/index.js +28 -18
- package/node_modules/@campfirein/brv-transport-client/dist/index.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/client-factory.d.ts +49 -167
- package/node_modules/@campfirein/brv-transport-client/dist/infra/client-factory.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/client-factory.js +161 -260
- package/node_modules/@campfirein/brv-transport-client/dist/infra/client-factory.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/connection-state-manager.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/connection-state-manager.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-connector.d.ts +46 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-connector.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-connector.js +47 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-connector.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-discovery-sync.d.ts +41 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-discovery-sync.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-discovery-sync.js +48 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-discovery-sync.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-health.d.ts +37 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-health.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-health.js +35 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-health.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-instance-discovery.d.ts +22 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-instance-discovery.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-instance-discovery.js +83 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-instance-discovery.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-reconnector.d.ts +60 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-reconnector.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-reconnector.js +101 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-reconnector.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-spawner.d.ts +33 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-spawner.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-spawner.js +161 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/daemon-spawner.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/event-dispatcher.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/event-dispatcher.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/find-project-root.d.ts +11 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/find-project-root.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/find-project-root.js +31 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/find-project-root.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/force-reconnect-manager.d.ts +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/force-reconnect-manager.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/force-reconnect-manager.js +4 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/force-reconnect-manager.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/global-data-path.d.ts +12 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/global-data-path.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/global-data-path.js +38 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/global-data-path.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/global-instance-manager.d.ts +37 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/global-instance-manager.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/global-instance-manager.js +100 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/global-instance-manager.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/heartbeat-utils.d.ts +12 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/heartbeat-utils.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/heartbeat-utils.js +29 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/heartbeat-utils.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/no-op-client-logger.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/no-op-client-logger.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/process-utils.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/process-utils.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/reconnection-strategy.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/reconnection-strategy.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/resolve-server-path.d.ts +12 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/resolve-server-path.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/resolve-server-path.js +52 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/resolve-server-path.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/room-manager.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/room-manager.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/index.d.ts +2 -2
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/index.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/index.js +4 -2
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/index.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/schemas.d.ts +65 -3
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/schemas.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/schemas.js +44 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/schemas.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/types.d.ts +11 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/types.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/schemas/types.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/socket-io-client.d.ts +32 -61
- package/node_modules/@campfirein/brv-transport-client/dist/infra/socket-io-client.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/socket-io-client.js +133 -37
- package/node_modules/@campfirein/brv-transport-client/dist/infra/socket-io-client.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/spawn-lock.d.ts +27 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/spawn-lock.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/spawn-lock.js +124 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/spawn-lock.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/utils/deep-freeze.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/utils/deep-freeze.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/wait-for-connected-client.d.ts +13 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/wait-for-connected-client.d.ts.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/wait-for-connected-client.js +33 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/wait-for-connected-client.js.map +1 -0
- package/node_modules/@campfirein/brv-transport-client/dist/infra/wake-detector.d.ts.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/wake-detector.js.map +1 -1
- package/node_modules/@campfirein/brv-transport-client/package.json +3 -12
- package/oclif.manifest.json +1224 -180
- package/package.json +47 -8
- package/dist/agent/infra/llm/generators/openrouter-content-generator.d.ts +0 -94
- package/dist/agent/infra/llm/generators/openrouter-content-generator.js +0 -280
- package/dist/agent/infra/llm/internal-llm-service.d.ts +0 -362
- package/dist/agent/infra/llm/internal-llm-service.js +0 -1039
- package/dist/agent/infra/llm/openrouter-llm-service.d.ts +0 -215
- package/dist/agent/infra/llm/openrouter-llm-service.js +0 -572
- package/dist/agent/infra/llm/stream-processor.d.ts +0 -178
- package/dist/agent/infra/llm/stream-processor.js +0 -350
- package/dist/agent/infra/llm/transformers/openrouter-stream-transformer.d.ts +0 -49
- package/dist/agent/infra/llm/transformers/openrouter-stream-transformer.js +0 -270
- package/dist/agent/infra/tools/implementations/bash-exec-tool.d.ts +0 -13
- package/dist/agent/infra/tools/implementations/bash-exec-tool.js +0 -110
- package/dist/agent/infra/tools/implementations/bash-output-tool.d.ts +0 -12
- package/dist/agent/infra/tools/implementations/bash-output-tool.js +0 -43
- package/dist/agent/infra/tools/implementations/batch-tool.d.ts +0 -12
- package/dist/agent/infra/tools/implementations/batch-tool.js +0 -142
- package/dist/agent/infra/tools/implementations/create-knowledge-topic-tool.d.ts +0 -11
- package/dist/agent/infra/tools/implementations/create-knowledge-topic-tool.js +0 -149
- package/dist/agent/infra/tools/implementations/delete-memory-tool.d.ts +0 -12
- package/dist/agent/infra/tools/implementations/delete-memory-tool.js +0 -37
- package/dist/agent/infra/tools/implementations/edit-file-tool.d.ts +0 -13
- package/dist/agent/infra/tools/implementations/edit-file-tool.js +0 -50
- package/dist/agent/infra/tools/implementations/edit-memory-tool.d.ts +0 -13
- package/dist/agent/infra/tools/implementations/edit-memory-tool.js +0 -53
- package/dist/agent/infra/tools/implementations/kill-process-tool.d.ts +0 -12
- package/dist/agent/infra/tools/implementations/kill-process-tool.js +0 -55
- package/dist/agent/infra/tools/implementations/list-memories-tool.d.ts +0 -12
- package/dist/agent/infra/tools/implementations/list-memories-tool.js +0 -63
- package/dist/agent/infra/tools/implementations/read-memory-tool.d.ts +0 -12
- package/dist/agent/infra/tools/implementations/read-memory-tool.js +0 -39
- package/dist/agent/infra/tools/implementations/read-todos-tool.d.ts +0 -11
- package/dist/agent/infra/tools/implementations/read-todos-tool.js +0 -39
- package/dist/agent/infra/tools/implementations/search-history-tool.d.ts +0 -10
- package/dist/agent/infra/tools/implementations/search-history-tool.js +0 -36
- package/dist/agent/infra/tools/implementations/spec-analyze-tool.d.ts +0 -7
- package/dist/agent/infra/tools/implementations/spec-analyze-tool.js +0 -78
- package/dist/agent/infra/tools/implementations/write-memory-tool.d.ts +0 -13
- package/dist/agent/infra/tools/implementations/write-memory-tool.js +0 -52
- package/dist/agent/infra/tools/implementations/write-todos-tool.d.ts +0 -13
- package/dist/agent/infra/tools/implementations/write-todos-tool.js +0 -121
- package/dist/oclif/commands/curate.d.ts +0 -21
- package/dist/oclif/commands/curate.js +0 -96
- package/dist/oclif/commands/init.d.ts +0 -18
- package/dist/oclif/commands/init.js +0 -129
- package/dist/server/core/domain/entities/context-tree-index.d.ts +0 -26
- package/dist/server/core/domain/entities/context-tree-index.js +0 -27
- package/dist/server/core/domain/entities/event.d.ts +0 -8
- package/dist/server/core/domain/entities/event.js +0 -25
- package/dist/server/core/domain/errors/ace-error.d.ts +0 -34
- package/dist/server/core/domain/errors/ace-error.js +0 -53
- package/dist/server/core/domain/errors/brv-config-version-error.d.ts +0 -16
- package/dist/server/core/domain/errors/brv-config-version-error.js +0 -21
- package/dist/server/core/domain/errors/core-process-error.d.ts +0 -27
- package/dist/server/core/domain/errors/core-process-error.js +0 -43
- package/dist/server/core/domain/instance/index.d.ts +0 -1
- package/dist/server/core/domain/instance/index.js +0 -1
- package/dist/server/core/domain/instance/types.d.ts +0 -57
- package/dist/server/core/domain/instance/types.js +0 -72
- package/dist/server/core/interfaces/instance/i-instance-discovery.d.ts +0 -45
- package/dist/server/core/interfaces/instance/i-instance-manager.d.ts +0 -58
- package/dist/server/core/interfaces/instance/index.d.ts +0 -2
- package/dist/server/core/interfaces/instance/index.js +0 -2
- package/dist/server/core/interfaces/noop-implementations.d.ts +0 -53
- package/dist/server/core/interfaces/noop-implementations.js +0 -62
- package/dist/server/core/interfaces/services/i-tracking-service.d.ts +0 -21
- package/dist/server/core/interfaces/usecase/i-connectors-use-case.d.ts +0 -3
- package/dist/server/core/interfaces/usecase/i-curate-use-case.d.ts +0 -14
- package/dist/server/core/interfaces/usecase/i-init-use-case.d.ts +0 -11
- package/dist/server/core/interfaces/usecase/i-login-use-case.d.ts +0 -6
- package/dist/server/core/interfaces/usecase/i-logout-use-case.d.ts +0 -5
- package/dist/server/core/interfaces/usecase/i-pull-use-case.d.ts +0 -7
- package/dist/server/core/interfaces/usecase/i-push-use-case.d.ts +0 -8
- package/dist/server/core/interfaces/usecase/i-query-use-case.d.ts +0 -11
- package/dist/server/core/interfaces/usecase/i-reset-use-case.d.ts +0 -6
- package/dist/server/core/interfaces/usecase/i-space-list-use-case.d.ts +0 -3
- package/dist/server/core/interfaces/usecase/i-space-switch-use-case.d.ts +0 -3
- package/dist/server/core/interfaces/usecase/i-status-use-case.d.ts +0 -6
- package/dist/server/infra/executor/task-processor.d.ts +0 -89
- package/dist/server/infra/executor/task-processor.js +0 -133
- package/dist/server/infra/instance/file-instance-discovery.d.ts +0 -31
- package/dist/server/infra/instance/file-instance-discovery.js +0 -84
- package/dist/server/infra/instance/file-instance-manager.d.ts +0 -46
- package/dist/server/infra/instance/file-instance-manager.js +0 -123
- package/dist/server/infra/instance/index.d.ts +0 -3
- package/dist/server/infra/instance/index.js +0 -3
- package/dist/server/infra/instance/process-utils.d.ts +0 -14
- package/dist/server/infra/instance/process-utils.js +0 -39
- package/dist/server/infra/process/agent-worker.d.ts +0 -20
- package/dist/server/infra/process/agent-worker.js +0 -1392
- package/dist/server/infra/process/inline-agent-executor.d.ts +0 -32
- package/dist/server/infra/process/inline-agent-executor.js +0 -267
- package/dist/server/infra/process/ipc-types.d.ts +0 -68
- package/dist/server/infra/process/ipc-types.js +0 -12
- package/dist/server/infra/process/parent-heartbeat.d.ts +0 -47
- package/dist/server/infra/process/parent-heartbeat.js +0 -118
- package/dist/server/infra/process/process-manager.d.ts +0 -242
- package/dist/server/infra/process/process-manager.js +0 -765
- package/dist/server/infra/process/task-queue-manager.d.ts +0 -125
- package/dist/server/infra/process/task-queue-manager.js +0 -185
- package/dist/server/infra/process/transport-worker.d.ts +0 -20
- package/dist/server/infra/process/transport-worker.js +0 -196
- package/dist/server/infra/storage/keychain-token-store.d.ts +0 -13
- package/dist/server/infra/storage/keychain-token-store.js +0 -42
- package/dist/server/infra/terminal/oclif-terminal.d.ts +0 -19
- package/dist/server/infra/terminal/oclif-terminal.js +0 -60
- package/dist/server/infra/terminal/repl-terminal.d.ts +0 -31
- package/dist/server/infra/terminal/repl-terminal.js +0 -116
- package/dist/server/infra/tracking/mixpanel-tracking-service.d.ts +0 -24
- package/dist/server/infra/tracking/mixpanel-tracking-service.js +0 -49
- package/dist/server/infra/transport/transport-factory.d.ts +0 -17
- package/dist/server/infra/transport/transport-factory.js +0 -31
- package/dist/server/infra/usecase/connectors-use-case.d.ts +0 -63
- package/dist/server/infra/usecase/connectors-use-case.js +0 -234
- package/dist/server/infra/usecase/curate-use-case.d.ts +0 -59
- package/dist/server/infra/usecase/curate-use-case.js +0 -269
- package/dist/server/infra/usecase/init-use-case.d.ts +0 -126
- package/dist/server/infra/usecase/init-use-case.js +0 -538
- package/dist/server/infra/usecase/login-use-case.d.ts +0 -30
- package/dist/server/infra/usecase/login-use-case.js +0 -127
- package/dist/server/infra/usecase/logout-use-case.d.ts +0 -19
- package/dist/server/infra/usecase/logout-use-case.js +0 -48
- package/dist/server/infra/usecase/pull-use-case.d.ts +0 -49
- package/dist/server/infra/usecase/pull-use-case.js +0 -147
- package/dist/server/infra/usecase/push-use-case.d.ts +0 -50
- package/dist/server/infra/usecase/push-use-case.js +0 -191
- package/dist/server/infra/usecase/query-use-case.d.ts +0 -73
- package/dist/server/infra/usecase/query-use-case.js +0 -410
- package/dist/server/infra/usecase/reset-use-case.d.ts +0 -21
- package/dist/server/infra/usecase/reset-use-case.js +0 -60
- package/dist/server/infra/usecase/space-list-use-case.d.ts +0 -27
- package/dist/server/infra/usecase/space-list-use-case.js +0 -64
- package/dist/server/infra/usecase/space-switch-use-case.d.ts +0 -26
- package/dist/server/infra/usecase/space-switch-use-case.js +0 -110
- package/dist/server/infra/usecase/status-use-case.d.ts +0 -75
- package/dist/server/infra/usecase/status-use-case.js +0 -268
- package/dist/server/templates/skill/TROUBLESHOOTING.md +0 -50
- package/dist/server/templates/skill/WORKFLOWS.md +0 -229
- package/dist/server/utils/environment-detector.d.ts +0 -20
- package/dist/server/utils/environment-detector.js +0 -92
- package/dist/tui/app.d.ts +0 -9
- package/dist/tui/app.js +0 -28
- package/dist/tui/commands/arg-parser.d.ts +0 -102
- package/dist/tui/commands/connectors-command.d.ts +0 -8
- package/dist/tui/commands/connectors-command.js +0 -49
- package/dist/tui/commands/curate-command.d.ts +0 -9
- package/dist/tui/commands/curate-command.js +0 -80
- package/dist/tui/commands/index.d.ts +0 -8
- package/dist/tui/commands/index.js +0 -45
- package/dist/tui/commands/init-command.d.ts +0 -7
- package/dist/tui/commands/init-command.js +0 -87
- package/dist/tui/commands/login-command.d.ts +0 -7
- package/dist/tui/commands/login-command.js +0 -50
- package/dist/tui/commands/logout-command.d.ts +0 -5
- package/dist/tui/commands/logout-command.js +0 -46
- package/dist/tui/commands/model-command.d.ts +0 -13
- package/dist/tui/commands/model-command.js +0 -212
- package/dist/tui/commands/new-command.d.ts +0 -14
- package/dist/tui/commands/new-command.js +0 -61
- package/dist/tui/commands/provider-command.d.ts +0 -13
- package/dist/tui/commands/provider-command.js +0 -181
- package/dist/tui/commands/pull-command.d.ts +0 -5
- package/dist/tui/commands/pull-command.js +0 -61
- package/dist/tui/commands/push-command.d.ts +0 -5
- package/dist/tui/commands/push-command.js +0 -66
- package/dist/tui/commands/query-command.d.ts +0 -5
- package/dist/tui/commands/query-command.js +0 -63
- package/dist/tui/commands/reset-command.d.ts +0 -5
- package/dist/tui/commands/reset-command.js +0 -61
- package/dist/tui/commands/space/index.d.ts +0 -5
- package/dist/tui/commands/space/index.js +0 -14
- package/dist/tui/commands/space/list-command.d.ts +0 -5
- package/dist/tui/commands/space/list-command.js +0 -70
- package/dist/tui/commands/space/switch-command.d.ts +0 -5
- package/dist/tui/commands/space/switch-command.js +0 -35
- package/dist/tui/commands/status-command.d.ts +0 -5
- package/dist/tui/commands/status-command.js +0 -39
- package/dist/tui/components/api-key-dialog.d.ts +0 -39
- package/dist/tui/components/api-key-dialog.js +0 -94
- package/dist/tui/components/message-list.d.ts +0 -16
- package/dist/tui/components/message-list.js +0 -120
- package/dist/tui/components/model-dialog.d.ts +0 -63
- package/dist/tui/components/model-dialog.js +0 -89
- package/dist/tui/components/provider-dialog.d.ts +0 -27
- package/dist/tui/components/provider-dialog.js +0 -31
- package/dist/tui/components/tab-bar.d.ts +0 -11
- package/dist/tui/components/tab-bar.js +0 -11
- package/dist/tui/constants.d.ts +0 -6
- package/dist/tui/constants.js +0 -8
- package/dist/tui/contexts/auth-context.d.ts +0 -33
- package/dist/tui/contexts/auth-context.js +0 -193
- package/dist/tui/contexts/commands-context.d.ts +0 -37
- package/dist/tui/contexts/commands-context.js +0 -65
- package/dist/tui/contexts/index.d.ts +0 -11
- package/dist/tui/contexts/index.js +0 -11
- package/dist/tui/contexts/mode-context.d.ts +0 -43
- package/dist/tui/contexts/mode-context.js +0 -70
- package/dist/tui/contexts/onboarding-context.d.ts +0 -49
- package/dist/tui/contexts/onboarding-context.js +0 -193
- package/dist/tui/contexts/services-context.d.ts +0 -32
- package/dist/tui/contexts/services-context.js +0 -27
- package/dist/tui/contexts/tasks-context.d.ts +0 -101
- package/dist/tui/contexts/tasks-context.js +0 -422
- package/dist/tui/contexts/theme-context.d.ts +0 -55
- package/dist/tui/contexts/theme-context.js +0 -62
- package/dist/tui/contexts/transport-context.d.ts +0 -29
- package/dist/tui/contexts/transport-context.js +0 -81
- package/dist/tui/hooks/use-activity-logs.d.ts +0 -18
- package/dist/tui/hooks/use-activity-logs.js +0 -207
- package/dist/tui/hooks/use-auth-polling.d.ts +0 -27
- package/dist/tui/hooks/use-auth-polling.js +0 -118
- package/dist/tui/hooks/use-onboarding-logs.d.ts +0 -17
- package/dist/tui/hooks/use-onboarding-logs.js +0 -26
- package/dist/tui/hooks/use-onboarding.d.ts +0 -7
- package/dist/tui/hooks/use-onboarding.js +0 -6
- package/dist/tui/hooks/use-slash-command-processor.d.ts +0 -16
- package/dist/tui/hooks/use-slash-command-processor.js +0 -132
- package/dist/tui/hooks/use-slash-completion.d.ts +0 -30
- package/dist/tui/hooks/use-slash-completion.js +0 -230
- package/dist/tui/index.d.ts +0 -1
- package/dist/tui/index.js +0 -1
- package/dist/tui/types.d.ts +0 -1
- package/dist/tui/types.js +0 -1
- package/dist/tui/utils/transport-client-helper.d.ts +0 -9
- package/dist/tui/utils/transport-client-helper.js +0 -99
- package/dist/tui/views/index.d.ts +0 -5
- package/dist/tui/views/index.js +0 -5
- package/dist/tui/views/init-view.d.ts +0 -15
- package/dist/tui/views/init-view.js +0 -41
- package/dist/tui/views/login-view.d.ts +0 -10
- package/dist/tui/views/login-view.js +0 -33
- package/dist/tui/views/main-view.d.ts +0 -12
- package/dist/tui/views/main-view.js +0 -20
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-reader.d.ts +0 -19
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-reader.d.ts.map +0 -1
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-reader.js +0 -2
- package/node_modules/@campfirein/brv-transport-client/dist/core/interfaces/i-instance-reader.js.map +0 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/file-instance-discovery.d.ts +0 -32
- package/node_modules/@campfirein/brv-transport-client/dist/infra/file-instance-discovery.d.ts.map +0 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/file-instance-discovery.js +0 -85
- package/node_modules/@campfirein/brv-transport-client/dist/infra/file-instance-discovery.js.map +0 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/file-instance-reader.d.ts +0 -16
- package/node_modules/@campfirein/brv-transport-client/dist/infra/file-instance-reader.d.ts.map +0 -1
- package/node_modules/@campfirein/brv-transport-client/dist/infra/file-instance-reader.js +0 -47
- package/node_modules/@campfirein/brv-transport-client/dist/infra/file-instance-reader.js.map +0 -1
- /package/dist/{server/core/interfaces/instance/i-instance-discovery.js → agent/infra/agent/provider-update-config.js} +0 -0
- /package/dist/server/core/{interfaces/instance/i-instance-manager.js → domain/entities/curate-log-entry.js} +0 -0
- /package/dist/server/core/{interfaces/services/i-tracking-service.js → domain/entities/curation-status.js} +0 -0
- /package/dist/server/core/{interfaces/usecase/i-connectors-use-case.js → domain/transport/task-info.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-curate-use-case.js → agent/i-agent-pool.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-init-use-case.js → client/i-client-manager.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-login-use-case.js → context-tree/i-context-tree-merger.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-logout-use-case.js → daemon/i-agent-idle-timeout-policy.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-pull-use-case.js → daemon/i-daemon-resilience.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-push-use-case.js → daemon/i-heartbeat-writer.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-query-use-case.js → daemon/i-idle-timeout-policy.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-reset-use-case.js → daemon/i-shutdown-handler.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-space-list-use-case.js → hub/i-hub-install-service.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-space-switch-use-case.js → hub/i-hub-keychain-store.js} +0 -0
- /package/dist/server/core/interfaces/{usecase/i-status-use-case.js → hub/i-hub-registry-config-store.js} +0 -0
- /package/dist/tui/{commands → features/commands/utils}/arg-parser.js +0 -0
|
@@ -1,1392 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Worker - Entry point for Agent Process.
|
|
3
|
-
*
|
|
4
|
-
* Architecture v0.5.0:
|
|
5
|
-
* - Connects to Transport as Socket.IO CLIENT
|
|
6
|
-
* - Contains TaskProcessor + UseCases + CipherAgent
|
|
7
|
-
* - Receives tasks via Socket.IO (task:execute)
|
|
8
|
-
* - Sends results back via Socket.IO (task:chunk, task:completed, etc.)
|
|
9
|
-
* - NO Socket.IO server (Transport is the only server)
|
|
10
|
-
*
|
|
11
|
-
* IPC messages:
|
|
12
|
-
* - Receives: 'ping', 'shutdown', 'health-check'
|
|
13
|
-
* - Sends: 'ready', 'pong', 'stopped', 'error', 'health-check-result'
|
|
14
|
-
*
|
|
15
|
-
* Socket.IO events (as client):
|
|
16
|
-
* - Sends: 'agent:register' (identify as Agent)
|
|
17
|
-
* - Receives: 'task:execute', 'task:cancel', 'shutdown'
|
|
18
|
-
* - Sends: 'task:started', 'task:chunk', 'task:completed', 'task:error', 'task:toolCall', 'task:toolResult'
|
|
19
|
-
*/
|
|
20
|
-
import { TransportClient } from '@campfirein/brv-transport-client';
|
|
21
|
-
import { randomUUID } from 'node:crypto';
|
|
22
|
-
import { CipherAgent } from '../../../agent/infra/agent/index.js';
|
|
23
|
-
import { FileSystemService } from '../../../agent/infra/file-system/file-system-service.js';
|
|
24
|
-
import { FolderPackService } from '../../../agent/infra/folder-pack/folder-pack-service.js';
|
|
25
|
-
import { getCurrentConfig } from '../../config/environment.js';
|
|
26
|
-
import { DEFAULT_LLM_MODEL, PROJECT } from '../../constants.js';
|
|
27
|
-
import { AgentNotInitializedError, NotAuthenticatedError, ProcessorNotInitError, serializeTaskError, } from '../../core/domain/errors/task-error.js';
|
|
28
|
-
import { agentLog } from '../../utils/process-logger.js';
|
|
29
|
-
import { ProjectConfigStore } from '../config/file-config-store.js';
|
|
30
|
-
import { CurateExecutor } from '../executor/curate-executor.js';
|
|
31
|
-
import { FolderPackExecutor } from '../executor/folder-pack-executor.js';
|
|
32
|
-
import { QueryExecutor } from '../executor/query-executor.js';
|
|
33
|
-
import { createTaskProcessor } from '../executor/task-processor.js';
|
|
34
|
-
import { FileProviderConfigStore } from '../storage/file-provider-config-store.js';
|
|
35
|
-
import { ProviderKeychainStore } from '../storage/provider-keychain-store.js';
|
|
36
|
-
import { createTokenStore } from '../storage/token-store.js';
|
|
37
|
-
import { createParentHeartbeat } from './parent-heartbeat.js';
|
|
38
|
-
import { TaskQueueManager } from './task-queue-manager.js';
|
|
39
|
-
// IPC types imported from ./ipc-types.ts
|
|
40
|
-
function sendToParent(message) {
|
|
41
|
-
process.send?.(message);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Log transport errors instead of silently swallowing them.
|
|
45
|
-
* Used for fire-and-forget transport calls where we don't want to crash
|
|
46
|
-
* but still want visibility into failures for debugging.
|
|
47
|
-
*/
|
|
48
|
-
function logTransportError(error) {
|
|
49
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
50
|
-
agentLog(`Transport error (non-fatal): ${message}`);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Send a critical transport event with retry logic.
|
|
54
|
-
* Uses exponential backoff for retries to handle transient network issues.
|
|
55
|
-
* Inspired by opencode's robust event forwarding pattern.
|
|
56
|
-
*
|
|
57
|
-
* Critical events include: task:completed, task:error, task:cancelled
|
|
58
|
-
* These should be retried because if they fail, TUI won't know the task ended.
|
|
59
|
-
*
|
|
60
|
-
* @param eventName - The event name to send
|
|
61
|
-
* @param data - The event payload
|
|
62
|
-
* @param maxRetries - Maximum number of retry attempts (default: 3)
|
|
63
|
-
*/
|
|
64
|
-
function sendCriticalEvent(eventName, data, maxRetries = 3) {
|
|
65
|
-
const BASE_DELAY_MS = 100;
|
|
66
|
-
const attemptSend = (attempt) => {
|
|
67
|
-
transportClient
|
|
68
|
-
?.requestWithAck(eventName, data)
|
|
69
|
-
.then(() => {
|
|
70
|
-
// Success - nothing more to do
|
|
71
|
-
})
|
|
72
|
-
.catch((error) => {
|
|
73
|
-
const isLastAttempt = attempt >= maxRetries;
|
|
74
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
75
|
-
if (isLastAttempt) {
|
|
76
|
-
agentLog(`Critical event ${eventName} failed after ${maxRetries + 1} attempts: ${message}`);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
// Retry with exponential backoff
|
|
80
|
-
const delay = BASE_DELAY_MS * 2 ** attempt;
|
|
81
|
-
agentLog(`Critical event ${eventName} failed (attempt ${attempt + 1}/${maxRetries + 1}), retrying in ${delay}ms: ${message}`);
|
|
82
|
-
setTimeout(() => attemptSend(attempt + 1), delay);
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
attemptSend(0);
|
|
86
|
-
}
|
|
87
|
-
// Task types imported from core/domain/transport/schemas.ts:
|
|
88
|
-
// - TaskExecute: Transport → Agent (task:execute event)
|
|
89
|
-
// - TaskCancel: Transport → Agent (task:cancel event)
|
|
90
|
-
// ============================================================================
|
|
91
|
-
// Agent Process
|
|
92
|
-
// ============================================================================
|
|
93
|
-
let transportClient;
|
|
94
|
-
let taskProcessor;
|
|
95
|
-
let cipherAgent;
|
|
96
|
-
/** ChatSession ID - created once when agent starts, used for all tasks */
|
|
97
|
-
let chatSessionId;
|
|
98
|
-
/** Whether the agent is fully initialized (has auth + config) */
|
|
99
|
-
let isAgentInitialized = false;
|
|
100
|
-
/** Initialization error if agent couldn't be initialized */
|
|
101
|
-
let initializationError;
|
|
102
|
-
/** Guard: prevent concurrent initialization attempts */
|
|
103
|
-
let isInitializing = false;
|
|
104
|
-
/** Guard: prevent double cleanup */
|
|
105
|
-
let isCleaningUp = false;
|
|
106
|
-
/** Parent heartbeat monitor - lazily initialized in runWorker() */
|
|
107
|
-
let parentHeartbeat;
|
|
108
|
-
// ============================================================================
|
|
109
|
-
// Credentials Polling (detects auth/config changes)
|
|
110
|
-
// ============================================================================
|
|
111
|
-
/**
|
|
112
|
-
* Credentials polling interval in milliseconds.
|
|
113
|
-
*
|
|
114
|
-
* 5 seconds balances:
|
|
115
|
-
* - Responsiveness: User expects agent to react within ~5s after login/logout/space switch
|
|
116
|
-
* - Efficiency: Polling every 5s has minimal CPU/IO overhead (reads 2 small files)
|
|
117
|
-
* - UX: Faster than explicit restart, acceptable latency for credential changes
|
|
118
|
-
*/
|
|
119
|
-
const CREDENTIALS_POLL_INTERVAL_MS = 5000;
|
|
120
|
-
/** Current cached credentials (set after successful init) */
|
|
121
|
-
let cachedCredentials;
|
|
122
|
-
/** Guard: prevent concurrent polling checks */
|
|
123
|
-
let isPolling = false;
|
|
124
|
-
/** Credentials polling running flag */
|
|
125
|
-
let credentialsPollingRunning = false;
|
|
126
|
-
/** Guard: prevent task enqueueing during reinit (fixes TOCTOU race condition) */
|
|
127
|
-
let isReinitializing = false;
|
|
128
|
-
/**
|
|
129
|
-
* Lazy-initialized stores for credentials polling.
|
|
130
|
-
* Avoids side effects at import time (file system access).
|
|
131
|
-
* Created once on first poll, then reused (avoid creating new instances every 5 seconds).
|
|
132
|
-
*/
|
|
133
|
-
let pollingTokenStore;
|
|
134
|
-
let pollingConfigStore;
|
|
135
|
-
function getPollingStores() {
|
|
136
|
-
pollingTokenStore ??= createTokenStore();
|
|
137
|
-
pollingConfigStore ??= new ProjectConfigStore();
|
|
138
|
-
return { pollingConfigStore, pollingTokenStore };
|
|
139
|
-
}
|
|
140
|
-
let eventForwarders = [];
|
|
141
|
-
// ============================================================================
|
|
142
|
-
// Task Queue Manager (replaces inline queue logic)
|
|
143
|
-
// ============================================================================
|
|
144
|
-
/**
|
|
145
|
-
* Task queue manager handles:
|
|
146
|
-
* - Unified queue for all task types (curate, query)
|
|
147
|
-
* - Sequential FIFO execution (max 1 concurrent)
|
|
148
|
-
* - Task deduplication (same taskId can't be queued twice)
|
|
149
|
-
* - Cancel tasks from queue before processing
|
|
150
|
-
*/
|
|
151
|
-
const taskQueueManager = new TaskQueueManager({
|
|
152
|
-
maxConcurrent: 1, // Sequential FIFO execution for all tasks
|
|
153
|
-
onExecutorError(taskId, error) {
|
|
154
|
-
agentLog(`Executor error for task ${taskId}: ${error}`);
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
/**
|
|
158
|
-
* Notify clients about dropped tasks and clear the queue.
|
|
159
|
-
* Extracted to avoid DRY violation across reinit, stop, and shutdown paths.
|
|
160
|
-
*/
|
|
161
|
-
function notifyQueuedTasksAboutDropAndClear(reason) {
|
|
162
|
-
const queuedTasks = taskQueueManager.getQueuedTasks();
|
|
163
|
-
if (queuedTasks.length > 0) {
|
|
164
|
-
const error = serializeTaskError(new AgentNotInitializedError(`Task dropped - ${reason}`));
|
|
165
|
-
if (transportClient) {
|
|
166
|
-
agentLog(`Notifying ${queuedTasks.length} queued task(s): ${reason}`);
|
|
167
|
-
for (const task of queuedTasks) {
|
|
168
|
-
transportClient.requestWithAck('task:error', { error, taskId: task.taskId }).catch(logTransportError);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
agentLog(`Cannot notify ${queuedTasks.length} queued task(s): no transport client`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
taskQueueManager.clear();
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Get Transport port from environment.
|
|
179
|
-
*/
|
|
180
|
-
function getTransportPort() {
|
|
181
|
-
const portStr = process.env.TRANSPORT_PORT;
|
|
182
|
-
if (!portStr) {
|
|
183
|
-
throw new Error('TRANSPORT_PORT environment variable not set');
|
|
184
|
-
}
|
|
185
|
-
const port = Number.parseInt(portStr, 10);
|
|
186
|
-
if (Number.isNaN(port)) {
|
|
187
|
-
throw new TypeError(`Invalid TRANSPORT_PORT: ${portStr}`);
|
|
188
|
-
}
|
|
189
|
-
return port;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Cleanup event forwarders from previous agent instance.
|
|
193
|
-
* Prevents memory leaks when agent is reinitialized.
|
|
194
|
-
*/
|
|
195
|
-
function cleanupAgentEventForwarding() {
|
|
196
|
-
if (eventForwarders.length === 0) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
// Get the old agent's event bus (if still available)
|
|
200
|
-
const eventBus = cipherAgent?.agentEventBus;
|
|
201
|
-
if (eventBus) {
|
|
202
|
-
for (const { event, handler } of eventForwarders) {
|
|
203
|
-
// Uses fallback signature: off(eventName: string, listener: (data?: unknown) => void)
|
|
204
|
-
eventBus.off(event, handler);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
// Clear the stored references
|
|
208
|
-
eventForwarders = [];
|
|
209
|
-
agentLog('Event forwarders cleaned up');
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Check if there is pending work that would be disrupted by reinit.
|
|
213
|
-
* Returns true if tasks are active (running) OR queued (waiting).
|
|
214
|
-
*/
|
|
215
|
-
function hasPendingWork() {
|
|
216
|
-
return taskQueueManager.hasActiveTasks() || taskQueueManager.getQueuedCount() > 0;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Wait for active tasks to complete with a timeout.
|
|
220
|
-
* Used before reinit to allow in-flight tasks to finish gracefully.
|
|
221
|
-
*/
|
|
222
|
-
async function waitForActiveTasksToComplete(timeoutMs) {
|
|
223
|
-
const start = Date.now();
|
|
224
|
-
const checkInterval = 100;
|
|
225
|
-
// Poll until no active tasks or timeout
|
|
226
|
-
const pollUntilDone = async () => {
|
|
227
|
-
while (taskQueueManager.hasActiveTasks()) {
|
|
228
|
-
if (Date.now() - start >= timeoutMs) {
|
|
229
|
-
agentLog('Timeout waiting for active tasks - proceeding with reinit');
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
// eslint-disable-next-line no-await-in-loop
|
|
233
|
-
await new Promise((resolve) => {
|
|
234
|
-
setTimeout(resolve, checkInterval);
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
agentLog('Task queue drained successfully');
|
|
238
|
-
};
|
|
239
|
-
await pollUntilDone();
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Setup event forwarding from CipherAgent to Transport.
|
|
243
|
-
* agent-worker subscribes directly to agentEventBus (owns the agent).
|
|
244
|
-
* Events are forwarded with currentTaskId.
|
|
245
|
-
*
|
|
246
|
-
* IMPORTANT: This function now stores handler references and cleans up
|
|
247
|
-
* old handlers on reinit to prevent memory leaks.
|
|
248
|
-
*/
|
|
249
|
-
function setupAgentEventForwarding(agent) {
|
|
250
|
-
// Clean up old forwarders first (prevents accumulation on reinit)
|
|
251
|
-
cleanupAgentEventForwarding();
|
|
252
|
-
const eventBus = agent.agentEventBus;
|
|
253
|
-
if (!eventBus) {
|
|
254
|
-
agentLog('No agentEventBus available for event forwarding');
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
// Helper to register and track event forwarder.
|
|
258
|
-
// Wraps typed handler to match event bus fallback signature.
|
|
259
|
-
const registerForwarder = (event, handler) => {
|
|
260
|
-
// Wrapper matches fallback: (data?: unknown) => void
|
|
261
|
-
// BOUNDARY CAST: Event bus delivers unknown data; handler expects T.
|
|
262
|
-
// Type guard not possible for generic T at runtime.
|
|
263
|
-
const wrappedHandler = (data) => {
|
|
264
|
-
handler(data);
|
|
265
|
-
};
|
|
266
|
-
// Uses fallback signature: on(eventName: string, listener: (data?: unknown) => void)
|
|
267
|
-
eventBus.on(event, wrappedHandler);
|
|
268
|
-
eventForwarders.push({ event, handler: wrappedHandler });
|
|
269
|
-
};
|
|
270
|
-
// Forward llmservice:thinking
|
|
271
|
-
registerForwarder('llmservice:thinking', (payload) => {
|
|
272
|
-
if (payload.taskId) {
|
|
273
|
-
transportClient
|
|
274
|
-
?.requestWithAck('llmservice:thinking', { sessionId: payload.sessionId, taskId: payload.taskId })
|
|
275
|
-
.catch(logTransportError);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
// Forward llmservice:chunk
|
|
279
|
-
registerForwarder('llmservice:chunk', (payload) => {
|
|
280
|
-
if (payload.taskId) {
|
|
281
|
-
transportClient
|
|
282
|
-
?.requestWithAck('llmservice:chunk', {
|
|
283
|
-
content: payload.content,
|
|
284
|
-
isComplete: payload.isComplete,
|
|
285
|
-
sessionId: payload.sessionId,
|
|
286
|
-
taskId: payload.taskId,
|
|
287
|
-
type: payload.type,
|
|
288
|
-
})
|
|
289
|
-
.catch(logTransportError);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
// Forward llmservice:response
|
|
293
|
-
registerForwarder('llmservice:response', (payload) => {
|
|
294
|
-
if (payload.taskId && payload.content) {
|
|
295
|
-
transportClient
|
|
296
|
-
?.requestWithAck('llmservice:response', {
|
|
297
|
-
content: payload.content,
|
|
298
|
-
model: payload.model,
|
|
299
|
-
partial: payload.partial,
|
|
300
|
-
provider: payload.provider,
|
|
301
|
-
reasoning: payload.reasoning,
|
|
302
|
-
sessionId: payload.sessionId,
|
|
303
|
-
taskId: payload.taskId,
|
|
304
|
-
tokenUsage: payload.tokenUsage,
|
|
305
|
-
})
|
|
306
|
-
.catch(logTransportError);
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
// Forward llmservice:toolCall
|
|
310
|
-
registerForwarder('llmservice:toolCall', (payload) => {
|
|
311
|
-
if (payload.taskId && payload.callId) {
|
|
312
|
-
transportClient
|
|
313
|
-
?.requestWithAck('llmservice:toolCall', {
|
|
314
|
-
args: payload.args,
|
|
315
|
-
callId: payload.callId,
|
|
316
|
-
sessionId: payload.sessionId,
|
|
317
|
-
taskId: payload.taskId,
|
|
318
|
-
toolName: payload.toolName,
|
|
319
|
-
})
|
|
320
|
-
.catch(logTransportError);
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
// Forward llmservice:toolResult
|
|
324
|
-
registerForwarder('llmservice:toolResult', (payload) => {
|
|
325
|
-
if (payload.taskId && payload.callId) {
|
|
326
|
-
transportClient
|
|
327
|
-
?.requestWithAck('llmservice:toolResult', {
|
|
328
|
-
callId: payload.callId,
|
|
329
|
-
error: payload.error,
|
|
330
|
-
errorType: payload.errorType,
|
|
331
|
-
metadata: payload.metadata,
|
|
332
|
-
result: payload.result,
|
|
333
|
-
sessionId: payload.sessionId,
|
|
334
|
-
success: payload.success,
|
|
335
|
-
taskId: payload.taskId,
|
|
336
|
-
toolName: payload.toolName,
|
|
337
|
-
})
|
|
338
|
-
.catch(logTransportError);
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
// Forward llmservice:error
|
|
342
|
-
registerForwarder('llmservice:error', (payload) => {
|
|
343
|
-
if (payload.taskId) {
|
|
344
|
-
transportClient
|
|
345
|
-
?.requestWithAck('llmservice:error', {
|
|
346
|
-
code: payload.code,
|
|
347
|
-
error: payload.error,
|
|
348
|
-
sessionId: payload.sessionId,
|
|
349
|
-
taskId: payload.taskId,
|
|
350
|
-
})
|
|
351
|
-
.catch(logTransportError);
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
// Forward llmservice:unsupportedInput
|
|
355
|
-
registerForwarder('llmservice:unsupportedInput', (payload) => {
|
|
356
|
-
if (payload.taskId) {
|
|
357
|
-
transportClient
|
|
358
|
-
?.requestWithAck('llmservice:unsupportedInput', {
|
|
359
|
-
reason: payload.reason,
|
|
360
|
-
sessionId: payload.sessionId,
|
|
361
|
-
taskId: payload.taskId,
|
|
362
|
-
})
|
|
363
|
-
.catch(logTransportError);
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
agentLog(`Event forwarding setup complete (${eventForwarders.length} forwarders registered)`);
|
|
367
|
-
}
|
|
368
|
-
/** Task execution timeout: 5 minutes */
|
|
369
|
-
const TASK_EXECUTION_TIMEOUT_MS = 5 * 60 * 1000;
|
|
370
|
-
/**
|
|
371
|
-
* Setup the task executor for TaskQueueManager.
|
|
372
|
-
* Fix #2: Now called unconditionally at startup (before tryInitializeAgent).
|
|
373
|
-
* Lazy init inside executor enables processing tasks even if initial init failed.
|
|
374
|
-
*/
|
|
375
|
-
function setupTaskExecutor() {
|
|
376
|
-
taskQueueManager.setExecutor(async (task) => {
|
|
377
|
-
const { taskId, type } = task;
|
|
378
|
-
const stats = taskQueueManager.getStats();
|
|
379
|
-
agentLog(`Processing task ${taskId} (${type}), ${stats.queued} queued, ${stats.active} active`);
|
|
380
|
-
// Fix #2: Lazy initialization - if agent not ready, try to initialize now
|
|
381
|
-
// This enables processing tasks that arrived while init was failing
|
|
382
|
-
if (!isAgentInitialized) {
|
|
383
|
-
agentLog(`Task ${taskId} - agent not initialized, attempting lazy init...`);
|
|
384
|
-
const initialized = await tryInitializeAgent();
|
|
385
|
-
if (!initialized) {
|
|
386
|
-
agentLog(`Task ${taskId} rejected - lazy initialization failed`);
|
|
387
|
-
const error = serializeTaskError(initializationError ?? new AgentNotInitializedError('Agent initialization failed'));
|
|
388
|
-
sendCriticalEvent('task:error', { error, taskId });
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
agentLog(`Task ${taskId} - lazy initialization successful, proceeding`);
|
|
392
|
-
}
|
|
393
|
-
// Pre-execution guard: Verify agent is still ready (catches race conditions)
|
|
394
|
-
// This catches the case where credentials polling stopped the agent
|
|
395
|
-
// between when lazy init succeeded and when execution starts.
|
|
396
|
-
if (!isAgentInitialized || !taskProcessor) {
|
|
397
|
-
agentLog(`Task ${taskId} rejected - agent stopped during queue wait`);
|
|
398
|
-
const error = serializeTaskError(new AgentNotInitializedError('Agent stopped during execution wait'));
|
|
399
|
-
sendCriticalEvent('task:error', { error, taskId });
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
// Track timeout state for error handling
|
|
403
|
-
let timedOut = false;
|
|
404
|
-
const timeoutId = setTimeout(() => {
|
|
405
|
-
timedOut = true;
|
|
406
|
-
agentLog(`Task ${taskId} timed out after 5 minutes - cancelling via CipherAgent`);
|
|
407
|
-
// Cancel via CipherAgent's existing cancel() method
|
|
408
|
-
// This aborts activeStreamControllers and session, causing generate() to throw
|
|
409
|
-
if (cipherAgent) {
|
|
410
|
-
cipherAgent.cancel().catch((error) => {
|
|
411
|
-
agentLog(`Error cancelling CipherAgent on timeout: ${error}`);
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
}, TASK_EXECUTION_TIMEOUT_MS);
|
|
415
|
-
try {
|
|
416
|
-
// Execute task - if timeout fires, cipherAgent.cancel() will cause this to throw
|
|
417
|
-
await handleTaskExecute(task);
|
|
418
|
-
}
|
|
419
|
-
catch (error) {
|
|
420
|
-
// Handle timeout-triggered cancellation
|
|
421
|
-
if (timedOut) {
|
|
422
|
-
agentLog(`Task ${taskId} cancelled due to timeout`);
|
|
423
|
-
const errorData = serializeTaskError(new Error('Task exceeded 5 minute timeout'));
|
|
424
|
-
sendCriticalEvent('task:error', { error: errorData, taskId });
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
// Handle other errors (not timeout)
|
|
428
|
-
agentLog(`Task execution failed: ${error}`);
|
|
429
|
-
const errorData = serializeTaskError(error);
|
|
430
|
-
sendCriticalEvent('task:error', { error: errorData, taskId });
|
|
431
|
-
}
|
|
432
|
-
finally {
|
|
433
|
-
// Always clear timeout to prevent memory leak
|
|
434
|
-
clearTimeout(timeoutId);
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
agentLog('Task executor setup complete');
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Timeout for CipherAgent initialization operations.
|
|
441
|
-
* This prevents isInitializing flag from getting stuck if agent.start() or createSession() hangs.
|
|
442
|
-
* ProcessManager has 30s timeout for startup, but runtime reinit needs its own protection.
|
|
443
|
-
*/
|
|
444
|
-
const AGENT_INIT_TIMEOUT_MS = 30_000;
|
|
445
|
-
/**
|
|
446
|
-
* Helper to wrap a promise with a timeout.
|
|
447
|
-
* Throws an error if the operation doesn't complete within the timeout.
|
|
448
|
-
*/
|
|
449
|
-
async function withTimeout(promise, timeoutMs, operation) {
|
|
450
|
-
let timeoutId;
|
|
451
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
452
|
-
timeoutId = setTimeout(() => {
|
|
453
|
-
reject(new Error(`${operation} timed out after ${timeoutMs}ms`));
|
|
454
|
-
}, timeoutMs);
|
|
455
|
-
});
|
|
456
|
-
try {
|
|
457
|
-
return await Promise.race([promise, timeoutPromise]);
|
|
458
|
-
}
|
|
459
|
-
finally {
|
|
460
|
-
if (timeoutId) {
|
|
461
|
-
clearTimeout(timeoutId);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Validate auth token for initialization.
|
|
467
|
-
* Returns the token if valid, undefined if invalid (also sets initializationError).
|
|
468
|
-
*/
|
|
469
|
-
function validateAuthToken(authToken) {
|
|
470
|
-
if (!authToken) {
|
|
471
|
-
initializationError = new NotAuthenticatedError();
|
|
472
|
-
agentLog('Cannot initialize - no auth token');
|
|
473
|
-
return undefined;
|
|
474
|
-
}
|
|
475
|
-
if (authToken.isExpired()) {
|
|
476
|
-
initializationError = new NotAuthenticatedError();
|
|
477
|
-
agentLog('Cannot initialize - token expired (please run /login to re-authenticate)');
|
|
478
|
-
return undefined;
|
|
479
|
-
}
|
|
480
|
-
return authToken;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Check if cleanup started during init and abort if so.
|
|
484
|
-
* Returns true if should abort (cleanup started), false otherwise.
|
|
485
|
-
*/
|
|
486
|
-
async function shouldAbortInitForCleanup(agent, phase) {
|
|
487
|
-
if (isCleaningUp) {
|
|
488
|
-
agentLog(`Cleanup started during ${phase}, aborting`);
|
|
489
|
-
await agent.stop();
|
|
490
|
-
return true;
|
|
491
|
-
}
|
|
492
|
-
return false;
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Stop a pending agent that was created but not yet assigned to cipherAgent.
|
|
496
|
-
* Used in catch block when timeout/error occurs during agent.start() or createSession().
|
|
497
|
-
*/
|
|
498
|
-
async function stopPendingAgent(agent) {
|
|
499
|
-
if (!agent)
|
|
500
|
-
return;
|
|
501
|
-
try {
|
|
502
|
-
await agent.stop();
|
|
503
|
-
}
|
|
504
|
-
catch (stopError) {
|
|
505
|
-
agentLog(`Error stopping pending agent: ${stopError}`);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Stop existing agent during force reinit.
|
|
510
|
-
*/
|
|
511
|
-
async function stopExistingAgentForReinit() {
|
|
512
|
-
if (!cipherAgent)
|
|
513
|
-
return;
|
|
514
|
-
agentLog('Reinitializing with new config...');
|
|
515
|
-
try {
|
|
516
|
-
await cipherAgent.stop();
|
|
517
|
-
}
|
|
518
|
-
catch (error) {
|
|
519
|
-
agentLog(`Error stopping previous agent: ${error}`);
|
|
520
|
-
}
|
|
521
|
-
cipherAgent = undefined;
|
|
522
|
-
taskProcessor = undefined;
|
|
523
|
-
isAgentInitialized = false;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Prepare for reinitialization by draining queue and stopping existing agent.
|
|
527
|
-
*
|
|
528
|
-
* NOTE: We do NOT cleanup transport event handlers here because they are meant
|
|
529
|
-
* to be long-lived for the entire worker process lifecycle. Only agent event
|
|
530
|
-
* forwarders (which are tied to the CipherAgent instance) are cleaned up via
|
|
531
|
-
* cleanupAgentEventForwarding() in stopExistingAgentForReinit().
|
|
532
|
-
*/
|
|
533
|
-
async function prepareForReinit() {
|
|
534
|
-
// Drain task queue before reinit to prevent tasks executing with stale processor
|
|
535
|
-
agentLog('Draining task queue before reinit...');
|
|
536
|
-
notifyQueuedTasksAboutDropAndClear('credential/config change');
|
|
537
|
-
// Wait for active tasks to complete (with timeout)
|
|
538
|
-
await waitForActiveTasksToComplete(10_000);
|
|
539
|
-
await stopExistingAgentForReinit();
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Load provider configuration and return API key and model if using external provider.
|
|
543
|
-
*/
|
|
544
|
-
async function loadProviderConfiguration() {
|
|
545
|
-
const providerConfigStore = new FileProviderConfigStore();
|
|
546
|
-
const providerKeychainStore = new ProviderKeychainStore();
|
|
547
|
-
const providerConfig = await providerConfigStore.read();
|
|
548
|
-
const activeProviderId = providerConfig.activeProvider;
|
|
549
|
-
// Get OpenRouter API key if using external provider
|
|
550
|
-
let openRouterApiKey;
|
|
551
|
-
let modelFromProvider;
|
|
552
|
-
if (activeProviderId !== 'byterover') {
|
|
553
|
-
openRouterApiKey = await providerKeychainStore.getApiKey(activeProviderId);
|
|
554
|
-
modelFromProvider = await providerConfigStore.getActiveModel(activeProviderId);
|
|
555
|
-
if (openRouterApiKey) {
|
|
556
|
-
agentLog(`Using external provider: ${activeProviderId}${modelFromProvider ? ` with model: ${modelFromProvider}` : ''}`);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
return { modelFromProvider, openRouterApiKey };
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Build agent configuration object from auth token and provider settings.
|
|
563
|
-
*/
|
|
564
|
-
function buildAgentConfig(authToken, modelFromProvider, openRouterApiKey) {
|
|
565
|
-
const envConfig = getCurrentConfig();
|
|
566
|
-
return {
|
|
567
|
-
accessToken: authToken.accessToken,
|
|
568
|
-
apiBaseUrl: envConfig.llmApiBaseUrl,
|
|
569
|
-
fileSystem: { workingDirectory: process.cwd() },
|
|
570
|
-
llm: {
|
|
571
|
-
maxIterations: 10,
|
|
572
|
-
maxTokens: 4096,
|
|
573
|
-
temperature: 0.7,
|
|
574
|
-
topK: 10,
|
|
575
|
-
topP: 0.95,
|
|
576
|
-
verbose: false,
|
|
577
|
-
},
|
|
578
|
-
model: modelFromProvider ?? DEFAULT_LLM_MODEL,
|
|
579
|
-
openRouterApiKey,
|
|
580
|
-
projectId: PROJECT,
|
|
581
|
-
sessionKey: authToken.sessionKey,
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Initialize agent instance by starting it and creating a session.
|
|
586
|
-
* Returns the initialized agent or undefined if cleanup was triggered.
|
|
587
|
-
*/
|
|
588
|
-
async function initializeAgentInstance(agent) {
|
|
589
|
-
// Wrap agent.start() with timeout to prevent isInitializing from getting stuck
|
|
590
|
-
await withTimeout(agent.start(), AGENT_INIT_TIMEOUT_MS, 'CipherAgent.start()');
|
|
591
|
-
agentLog('CipherAgent started');
|
|
592
|
-
// Check if cleanup started during agent.start() (fixes zombie agent race)
|
|
593
|
-
if (await shouldAbortInitForCleanup(agent, 'agent.start()')) {
|
|
594
|
-
return undefined;
|
|
595
|
-
}
|
|
596
|
-
// Create ChatSession (also with timeout to prevent hanging)
|
|
597
|
-
chatSessionId = `agent-session-${randomUUID()}`;
|
|
598
|
-
await withTimeout(agent.createSession(chatSessionId), AGENT_INIT_TIMEOUT_MS, 'CipherAgent.createSession()');
|
|
599
|
-
agentLog(`ChatSession created: ${chatSessionId}`);
|
|
600
|
-
// Check if cleanup started during createSession() (fixes zombie agent race)
|
|
601
|
-
if (await shouldAbortInitForCleanup(agent, 'createSession()')) {
|
|
602
|
-
return undefined;
|
|
603
|
-
}
|
|
604
|
-
return agent;
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Finalize agent initialization by setting up event forwarding, creating task processor,
|
|
608
|
-
* and updating cached credentials.
|
|
609
|
-
*/
|
|
610
|
-
function finalizeAgentInitialization(params) {
|
|
611
|
-
const { agent, authToken, brvConfig, curateExecutor, folderPackExecutor, queryExecutor } = params;
|
|
612
|
-
// Setup event forwarding
|
|
613
|
-
setupAgentEventForwarding(agent);
|
|
614
|
-
cipherAgent = agent;
|
|
615
|
-
// Create TaskProcessor
|
|
616
|
-
taskProcessor = createTaskProcessor({
|
|
617
|
-
curateExecutor,
|
|
618
|
-
folderPackExecutor,
|
|
619
|
-
queryExecutor,
|
|
620
|
-
});
|
|
621
|
-
taskProcessor.setAgent(cipherAgent);
|
|
622
|
-
// NOTE: setupTaskExecutor() is called once in startAgent() before tryInitializeAgent()
|
|
623
|
-
// No need to call again here - executor is already set and handles lazy init
|
|
624
|
-
// Mark as initialized
|
|
625
|
-
isAgentInitialized = true;
|
|
626
|
-
initializationError = undefined;
|
|
627
|
-
// Cache credentials for change detection polling
|
|
628
|
-
updateCachedCredentials(authToken.accessToken, authToken.sessionKey, brvConfig ? { spaceId: brvConfig.spaceId, teamId: brvConfig.teamId } : undefined);
|
|
629
|
-
if (brvConfig) {
|
|
630
|
-
agentLog(`Fully initialized with auth and config (team=${brvConfig.teamId}, space=${brvConfig.spaceId})`);
|
|
631
|
-
}
|
|
632
|
-
else {
|
|
633
|
-
agentLog('Initialized with auth only (no project config yet - will reinit when config available)');
|
|
634
|
-
}
|
|
635
|
-
// Broadcast status change to Transport (init success)
|
|
636
|
-
broadcastStatusChange();
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Try to initialize/reinitialize the CipherAgent.
|
|
640
|
-
* Called on startup and lazily when tasks arrive but agent is not initialized.
|
|
641
|
-
* This handles the case where user completes onboarding after agent starts.
|
|
642
|
-
*
|
|
643
|
-
* @param forceReinit - Force reinitialization even if already initialized (for config reload)
|
|
644
|
-
*/
|
|
645
|
-
async function tryInitializeAgent(forceReinit = false) {
|
|
646
|
-
// Guard: prevent initialization during cleanup or if already in progress
|
|
647
|
-
if (isCleaningUp || isInitializing) {
|
|
648
|
-
agentLog('Initialization blocked (cleanup or already in progress)');
|
|
649
|
-
// Clear isReinitializing if WE set it (forceReinit case)
|
|
650
|
-
// Without this, the flag would be stuck forever since we return before try block
|
|
651
|
-
// and thus finally block never runs. Next poll will re-detect and retry.
|
|
652
|
-
if (forceReinit) {
|
|
653
|
-
isReinitializing = false;
|
|
654
|
-
}
|
|
655
|
-
return false;
|
|
656
|
-
}
|
|
657
|
-
// Already initialized and not forcing reinit
|
|
658
|
-
if (!forceReinit && isAgentInitialized && cipherAgent && taskProcessor) {
|
|
659
|
-
return true;
|
|
660
|
-
}
|
|
661
|
-
isInitializing = true;
|
|
662
|
-
// Set isReinitializing flag for forceReinit to reject tasks during reinit
|
|
663
|
-
// Note: caller (pollCredentialsAndSync) may have already set this - that's OK, we'll clear in finally
|
|
664
|
-
if (forceReinit) {
|
|
665
|
-
isReinitializing = true;
|
|
666
|
-
}
|
|
667
|
-
// Declare outside try block so catch can cleanup on timeout/error
|
|
668
|
-
let pendingAgent;
|
|
669
|
-
try {
|
|
670
|
-
// If forcing reinit, drain queue and stop existing agent first
|
|
671
|
-
if (forceReinit) {
|
|
672
|
-
await prepareForReinit();
|
|
673
|
-
}
|
|
674
|
-
const tokenStore = createTokenStore();
|
|
675
|
-
const configStore = new ProjectConfigStore();
|
|
676
|
-
const rawToken = await tokenStore.load();
|
|
677
|
-
const brvConfig = await configStore.read();
|
|
678
|
-
// Validate auth token (sets initializationError if invalid)
|
|
679
|
-
const authToken = validateAuthToken(rawToken);
|
|
680
|
-
if (!authToken) {
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
|
-
// Create Executors
|
|
684
|
-
const curateExecutor = new CurateExecutor();
|
|
685
|
-
const queryExecutor = new QueryExecutor();
|
|
686
|
-
// Create FolderPackExecutor with required dependencies
|
|
687
|
-
const fileSystemService = new FileSystemService();
|
|
688
|
-
await fileSystemService.initialize();
|
|
689
|
-
const folderPackService = new FolderPackService(fileSystemService);
|
|
690
|
-
await folderPackService.initialize();
|
|
691
|
-
const folderPackExecutor = new FolderPackExecutor(folderPackService);
|
|
692
|
-
// Read provider configuration
|
|
693
|
-
const { modelFromProvider, openRouterApiKey } = await loadProviderConfiguration();
|
|
694
|
-
// Build agent configuration
|
|
695
|
-
const agentConfig = buildAgentConfig(authToken, modelFromProvider, openRouterApiKey);
|
|
696
|
-
// Initialize agent instance
|
|
697
|
-
pendingAgent = new CipherAgent(agentConfig, brvConfig ?? undefined);
|
|
698
|
-
const initializedAgent = await initializeAgentInstance(pendingAgent);
|
|
699
|
-
if (!initializedAgent) {
|
|
700
|
-
return false;
|
|
701
|
-
}
|
|
702
|
-
// Finalize initialization
|
|
703
|
-
finalizeAgentInitialization({
|
|
704
|
-
agent: initializedAgent,
|
|
705
|
-
authToken,
|
|
706
|
-
brvConfig,
|
|
707
|
-
curateExecutor,
|
|
708
|
-
folderPackExecutor,
|
|
709
|
-
queryExecutor,
|
|
710
|
-
});
|
|
711
|
-
pendingAgent = undefined; // Clear local ref - cipherAgent now owns it
|
|
712
|
-
return true;
|
|
713
|
-
}
|
|
714
|
-
catch (error) {
|
|
715
|
-
// Stop pendingAgent if it was created but not yet assigned to cipherAgent
|
|
716
|
-
// This handles timeout/error during agent.start() or createSession()
|
|
717
|
-
await stopPendingAgent(pendingAgent);
|
|
718
|
-
pendingAgent = undefined;
|
|
719
|
-
// Cleanup partial state before recording error
|
|
720
|
-
// This prevents stale refs from accumulating on repeated failures
|
|
721
|
-
await cleanupPartialInit();
|
|
722
|
-
// Catch errors and return false instead of throwing
|
|
723
|
-
// This allows lazy init to retry when tasks arrive
|
|
724
|
-
initializationError = error instanceof Error ? error : new Error(String(error));
|
|
725
|
-
agentLog(`Agent initialization failed: ${error}`);
|
|
726
|
-
// Broadcast status change to Transport (init failed)
|
|
727
|
-
broadcastStatusChange();
|
|
728
|
-
return false;
|
|
729
|
-
}
|
|
730
|
-
finally {
|
|
731
|
-
isInitializing = false;
|
|
732
|
-
// Clear isReinitializing flag (matches the set above for forceReinit)
|
|
733
|
-
if (forceReinit) {
|
|
734
|
-
isReinitializing = false;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Handle task:execute from Transport.
|
|
740
|
-
*/
|
|
741
|
-
async function handleTaskExecute(data) {
|
|
742
|
-
const { clientCwd, content, files, folderPath, taskId, type } = data;
|
|
743
|
-
agentLog(`Processing task: ${taskId} (type=${type})`);
|
|
744
|
-
// NOTE: Lazy initialization is handled in setupTaskExecutor() executor callback.
|
|
745
|
-
// By the time we reach here, agent is already initialized (executor does lazy init first).
|
|
746
|
-
if (!taskProcessor) {
|
|
747
|
-
agentLog('TaskProcessor not initialized');
|
|
748
|
-
const error = serializeTaskError(new ProcessorNotInitError());
|
|
749
|
-
sendCriticalEvent('task:error', { error, taskId });
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
// Notify task started - use sendCriticalEvent for reliability
|
|
753
|
-
sendCriticalEvent('task:started', { taskId });
|
|
754
|
-
try {
|
|
755
|
-
// Process task - events stream via agentEventBus subscription
|
|
756
|
-
// Response is forwarded via llmservice:response event (no manual send needed)
|
|
757
|
-
// Agent uses its default session (Single-Session pattern)
|
|
758
|
-
// File validation is handled by UseCase (business logic belongs there)
|
|
759
|
-
// Note: taskId is passed to UseCase → CipherAgent → ChatSession, which adds it to all events
|
|
760
|
-
const result = await taskProcessor.process({
|
|
761
|
-
clientCwd,
|
|
762
|
-
content,
|
|
763
|
-
files,
|
|
764
|
-
folderPath,
|
|
765
|
-
taskId,
|
|
766
|
-
type,
|
|
767
|
-
});
|
|
768
|
-
// Notify completion with result (required by TaskCompletedEventSchema)
|
|
769
|
-
// Use sendCriticalEvent for retry logic - TUI must know task ended
|
|
770
|
-
agentLog(`Task completed: ${taskId}`);
|
|
771
|
-
sendCriticalEvent('task:completed', { result, taskId });
|
|
772
|
-
}
|
|
773
|
-
catch (error) {
|
|
774
|
-
const errorData = serializeTaskError(error);
|
|
775
|
-
agentLog(`Task error: ${taskId} - [${errorData.name}] ${errorData.message}`);
|
|
776
|
-
// Use sendCriticalEvent for retry logic - TUI must know task ended
|
|
777
|
-
sendCriticalEvent('task:error', { error: errorData, taskId });
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* Handle task:cancel from Transport.
|
|
782
|
-
* Uses TaskQueueManager to remove from queue or signal cancellation.
|
|
783
|
-
*/
|
|
784
|
-
function handleTaskCancel(data) {
|
|
785
|
-
const { taskId } = data;
|
|
786
|
-
agentLog(`Cancelling task: ${taskId}`);
|
|
787
|
-
const result = taskQueueManager.cancel(taskId);
|
|
788
|
-
if (result.success) {
|
|
789
|
-
if (result.wasQueued) {
|
|
790
|
-
// Task was in queue, not yet processing - removed by queue manager
|
|
791
|
-
agentLog(`Task ${taskId} removed from ${result.taskType} queue (was waiting)`);
|
|
792
|
-
// Notify transport that task was cancelled - use retry for reliability
|
|
793
|
-
sendCriticalEvent('task:cancelled', { taskId });
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
// Task is currently processing - cancel via taskProcessor
|
|
797
|
-
agentLog(`Task ${taskId} is processing, forwarding cancel to taskProcessor`);
|
|
798
|
-
taskProcessor?.cancel(taskId);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
else {
|
|
802
|
-
agentLog(`Task ${taskId} not found in queue or processing`);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Start Agent Process.
|
|
807
|
-
*/
|
|
808
|
-
async function startAgent() {
|
|
809
|
-
const port = getTransportPort();
|
|
810
|
-
agentLog(`Connecting to Transport on port ${port}`);
|
|
811
|
-
// Create Transport client (low-level: worker connects to specific port, not via discovery)
|
|
812
|
-
transportClient = new TransportClient();
|
|
813
|
-
// Connect to Transport
|
|
814
|
-
await transportClient.connect(`http://localhost:${port}`);
|
|
815
|
-
agentLog('Connected to Transport');
|
|
816
|
-
// Register as Agent
|
|
817
|
-
await transportClient.requestWithAck('agent:register', {});
|
|
818
|
-
agentLog('Registered with Transport');
|
|
819
|
-
// Fix #1: Re-register on any reconnect (Socket.IO auto-reconnect OR force reconnect)
|
|
820
|
-
// When connection is restored, agent needs to re-register with Transport.
|
|
821
|
-
// Using onStateChange instead of 'connect' event to handle all reconnect types.
|
|
822
|
-
// Fix #4: Include status in register payload to prevent race condition window
|
|
823
|
-
let wasDisconnected = false;
|
|
824
|
-
transportClient.onStateChange(async (state) => {
|
|
825
|
-
agentLog(`Transport state changed: ${state}`);
|
|
826
|
-
if (state === 'disconnected' || state === 'reconnecting') {
|
|
827
|
-
wasDisconnected = true;
|
|
828
|
-
}
|
|
829
|
-
else if (state === 'connected' && wasDisconnected) {
|
|
830
|
-
agentLog('Transport reconnected - re-registering with Transport');
|
|
831
|
-
// Retry with exponential backoff (50ms, 100ms, 200ms, 400ms, 800ms)
|
|
832
|
-
// Socket.IO may fire 'connected' state before socket is fully ready
|
|
833
|
-
const retryDelays = [50, 100, 200, 400, 800];
|
|
834
|
-
for (let attempt = 0; attempt <= retryDelays.length; attempt++) {
|
|
835
|
-
try {
|
|
836
|
-
// Include status in register payload (Transport caches it atomically)
|
|
837
|
-
// eslint-disable-next-line no-await-in-loop -- Sequential retries with backoff required
|
|
838
|
-
await transportClient?.requestWithAck('agent:register', { status: getAgentStatus() });
|
|
839
|
-
// Only clear flag after successful registration
|
|
840
|
-
wasDisconnected = false;
|
|
841
|
-
agentLog('Re-registered with Transport after reconnect');
|
|
842
|
-
return; // Success - exit retry loop
|
|
843
|
-
}
|
|
844
|
-
catch (error) {
|
|
845
|
-
if (attempt < retryDelays.length) {
|
|
846
|
-
agentLog(`Re-register attempt ${attempt + 1} failed, retrying in ${retryDelays[attempt]}ms: ${error}`);
|
|
847
|
-
// eslint-disable-next-line no-await-in-loop -- Sequential retries with backoff required
|
|
848
|
-
await new Promise((resolve) => {
|
|
849
|
-
setTimeout(resolve, retryDelays[attempt]);
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
else {
|
|
853
|
-
// Keep wasDisconnected = true so next reconnect retries registration
|
|
854
|
-
agentLog(`Failed to re-register after ${attempt + 1} attempts: ${error}`);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
});
|
|
860
|
-
// Fix #2: Setup task executor BEFORE init - enables lazy init when tasks arrive
|
|
861
|
-
// This ensures tasks don't get stuck in queue if initial init fails
|
|
862
|
-
setupTaskExecutor();
|
|
863
|
-
// Try to initialize agent (may fail if no auth yet - that's OK)
|
|
864
|
-
// tryInitializeAgent() broadcasts status on both success and failure,
|
|
865
|
-
// so Transport will have cached status before any task can arrive.
|
|
866
|
-
// If init fails, lazy init will retry when tasks arrive (handled by executor).
|
|
867
|
-
const initialized = await tryInitializeAgent();
|
|
868
|
-
if (!initialized) {
|
|
869
|
-
agentLog('Initial setup incomplete - will retry when tasks arrive (lazy init)');
|
|
870
|
-
}
|
|
871
|
-
// Setup event handlers - TaskQueueManager handles queueing and deduplication
|
|
872
|
-
// These handlers are registered once and persist for the worker's lifetime
|
|
873
|
-
transportClient.on('task:execute', (data) => {
|
|
874
|
-
// Reject tasks during reinit to prevent TOCTOU race condition
|
|
875
|
-
if (isReinitializing) {
|
|
876
|
-
agentLog(`Task ${data.taskId} rejected - agent reinitializing`);
|
|
877
|
-
const error = serializeTaskError(new AgentNotInitializedError('Agent is reinitializing'));
|
|
878
|
-
sendCriticalEvent('task:error', { error, taskId: data.taskId });
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
const result = taskQueueManager.enqueue(data);
|
|
882
|
-
if (result.success) {
|
|
883
|
-
const stats = taskQueueManager.getStats();
|
|
884
|
-
agentLog(`Task ${data.taskId} (${data.type}) queued at position ${result.position}, ${stats.queued} in queue`);
|
|
885
|
-
}
|
|
886
|
-
else if (result.reason === 'duplicate') {
|
|
887
|
-
agentLog(`Task ${data.taskId} already known (duplicate), ignoring`);
|
|
888
|
-
}
|
|
889
|
-
else {
|
|
890
|
-
agentLog(`Task ${data.taskId} rejected: ${result.reason}`);
|
|
891
|
-
}
|
|
892
|
-
});
|
|
893
|
-
transportClient.on('task:cancel', handleTaskCancel);
|
|
894
|
-
// Handle shutdown from Transport
|
|
895
|
-
transportClient.on('shutdown', () => {
|
|
896
|
-
agentLog('Received shutdown from Transport');
|
|
897
|
-
stopAgent()
|
|
898
|
-
.then(() => {
|
|
899
|
-
sendToParent({ type: 'stopped' });
|
|
900
|
-
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
901
|
-
process.exit(0);
|
|
902
|
-
})
|
|
903
|
-
.catch((error) => {
|
|
904
|
-
agentLog(`Error during shutdown: ${error}`);
|
|
905
|
-
sendToParent({ type: 'stopped' });
|
|
906
|
-
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
907
|
-
process.exit(1);
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
// Handle agent:restart from Transport (triggered by client, e.g., after /init)
|
|
911
|
-
transportClient.on('agent:restart', async (data) => {
|
|
912
|
-
agentLog(`Agent restart requested: ${data.reason ?? 'no reason'}`);
|
|
913
|
-
// Guard: reject if initialization already in progress (prevents concurrent reinit race condition)
|
|
914
|
-
if (isInitializing || isReinitializing) {
|
|
915
|
-
agentLog('Agent restart rejected - initialization already in progress');
|
|
916
|
-
await transportClient?.requestWithAck('agent:restarted', {
|
|
917
|
-
error: 'Initialization already in progress',
|
|
918
|
-
success: false,
|
|
919
|
-
});
|
|
920
|
-
return;
|
|
921
|
-
}
|
|
922
|
-
// Reject restart if tasks are in progress or queued (prevents killing active tasks)
|
|
923
|
-
if (hasPendingWork()) {
|
|
924
|
-
agentLog('Agent restart rejected - tasks in progress or queued');
|
|
925
|
-
await transportClient?.requestWithAck('agent:restarted', {
|
|
926
|
-
error: 'Tasks in progress. Please wait for tasks to complete.',
|
|
927
|
-
success: false,
|
|
928
|
-
});
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
try {
|
|
932
|
-
// Reinitialize agent with fresh config
|
|
933
|
-
const success = await tryInitializeAgent(true); // forceReinit = true
|
|
934
|
-
if (success) {
|
|
935
|
-
agentLog('Agent reinitialized successfully');
|
|
936
|
-
// Notify Transport that restart completed
|
|
937
|
-
await transportClient?.requestWithAck('agent:restarted', { success: true });
|
|
938
|
-
}
|
|
939
|
-
else if (isCleaningUp) {
|
|
940
|
-
// Cleanup in progress - can't restart during shutdown
|
|
941
|
-
agentLog('Agent reinitialization rejected - cleanup in progress');
|
|
942
|
-
await transportClient?.requestWithAck('agent:restarted', {
|
|
943
|
-
error: 'Agent is shutting down',
|
|
944
|
-
success: false,
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
else {
|
|
948
|
-
// Actual failure - missing auth or config
|
|
949
|
-
// Note: isInitializing is guaranteed to be false here because tryInitializeAgent()
|
|
950
|
-
// always clears it in its finally block before returning
|
|
951
|
-
agentLog('Agent reinitialization failed - config incomplete');
|
|
952
|
-
await transportClient?.requestWithAck('agent:restarted', {
|
|
953
|
-
error: initializationError?.message ?? 'Config incomplete (no auth token or config)',
|
|
954
|
-
success: false,
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
catch (error) {
|
|
959
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
960
|
-
agentLog(`Agent reinitialization error: ${message}`);
|
|
961
|
-
await transportClient?.requestWithAck('agent:restarted', { error: message, success: false });
|
|
962
|
-
}
|
|
963
|
-
});
|
|
964
|
-
// Handle agent:newSession from Transport (triggered by /new command)
|
|
965
|
-
transportClient.on('agent:newSession', async (data) => {
|
|
966
|
-
agentLog(`New session requested: ${data.reason ?? 'no reason'}`);
|
|
967
|
-
try {
|
|
968
|
-
if (!cipherAgent) {
|
|
969
|
-
agentLog('Cannot create new session - agent not initialized');
|
|
970
|
-
await transportClient?.requestWithAck('agent:newSessionCreated', {
|
|
971
|
-
error: 'Agent not initialized',
|
|
972
|
-
success: false,
|
|
973
|
-
});
|
|
974
|
-
return;
|
|
975
|
-
}
|
|
976
|
-
// Generate new session ID
|
|
977
|
-
const newSessionId = `agent-session-${randomUUID()}`;
|
|
978
|
-
// Create new session
|
|
979
|
-
await cipherAgent.createSession(newSessionId);
|
|
980
|
-
// Switch the agent's default session to the new one
|
|
981
|
-
// This ensures execute()/generate()/stream() use the new session
|
|
982
|
-
cipherAgent.switchDefaultSession(newSessionId);
|
|
983
|
-
// Update the local session ID reference
|
|
984
|
-
chatSessionId = newSessionId;
|
|
985
|
-
agentLog(`New session created: ${newSessionId}`);
|
|
986
|
-
// Notify Transport that new session was created
|
|
987
|
-
await transportClient?.requestWithAck('agent:newSessionCreated', {
|
|
988
|
-
sessionId: newSessionId,
|
|
989
|
-
success: true,
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
catch (error) {
|
|
993
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
994
|
-
agentLog(`New session creation error: ${message}`);
|
|
995
|
-
await transportClient?.requestWithAck('agent:newSessionCreated', {
|
|
996
|
-
error: message,
|
|
997
|
-
success: false,
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
});
|
|
1001
|
-
agentLog('Ready to process tasks');
|
|
1002
|
-
}
|
|
1003
|
-
// ============================================================================
|
|
1004
|
-
// Credentials Polling Functions
|
|
1005
|
-
// ============================================================================
|
|
1006
|
-
/**
|
|
1007
|
-
* Stop CipherAgent only (does NOT exit process or disconnect transport).
|
|
1008
|
-
* Used when credentials are missing/invalid but we want to keep polling.
|
|
1009
|
-
*/
|
|
1010
|
-
async function stopCipherAgent() {
|
|
1011
|
-
// Cleanup event forwarders
|
|
1012
|
-
cleanupAgentEventForwarding();
|
|
1013
|
-
// Notify and clear task queue (can't process without agent)
|
|
1014
|
-
notifyQueuedTasksAboutDropAndClear('agent stopped');
|
|
1015
|
-
// Stop CipherAgent
|
|
1016
|
-
if (cipherAgent) {
|
|
1017
|
-
try {
|
|
1018
|
-
await cipherAgent.stop();
|
|
1019
|
-
}
|
|
1020
|
-
catch (error) {
|
|
1021
|
-
agentLog(`Error stopping CipherAgent: ${error}`);
|
|
1022
|
-
}
|
|
1023
|
-
cipherAgent = undefined;
|
|
1024
|
-
}
|
|
1025
|
-
taskProcessor = undefined;
|
|
1026
|
-
chatSessionId = undefined;
|
|
1027
|
-
isAgentInitialized = false;
|
|
1028
|
-
cachedCredentials = undefined;
|
|
1029
|
-
agentLog('CipherAgent stopped (credentials missing or invalid)');
|
|
1030
|
-
// Broadcast status change to Transport (cipher stopped)
|
|
1031
|
-
broadcastStatusChange();
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* Cleanup partial state after failed initialization.
|
|
1035
|
-
* Called when tryInitializeAgent() fails partway through.
|
|
1036
|
-
* Does NOT broadcast status (caller handles that).
|
|
1037
|
-
*/
|
|
1038
|
-
async function cleanupPartialInit() {
|
|
1039
|
-
agentLog('Cleaning up partial initialization state...');
|
|
1040
|
-
// Cleanup event forwarders (may have been partially set up)
|
|
1041
|
-
cleanupAgentEventForwarding();
|
|
1042
|
-
// Stop CipherAgent if it was partially started
|
|
1043
|
-
if (cipherAgent) {
|
|
1044
|
-
try {
|
|
1045
|
-
await cipherAgent.stop();
|
|
1046
|
-
}
|
|
1047
|
-
catch (error) {
|
|
1048
|
-
agentLog(`Error stopping partial CipherAgent: ${error}`);
|
|
1049
|
-
}
|
|
1050
|
-
cipherAgent = undefined;
|
|
1051
|
-
}
|
|
1052
|
-
// Clear partial state
|
|
1053
|
-
taskProcessor = undefined;
|
|
1054
|
-
chatSessionId = undefined;
|
|
1055
|
-
// Note: DON'T clear cachedCredentials here - keep old credentials for comparison
|
|
1056
|
-
// Note: DON'T set isAgentInitialized - it should already be false
|
|
1057
|
-
agentLog('Partial initialization state cleaned up');
|
|
1058
|
-
}
|
|
1059
|
-
/**
|
|
1060
|
-
* Update cached credentials after successful initialization.
|
|
1061
|
-
*/
|
|
1062
|
-
function updateCachedCredentials(accessToken, sessionKey, config) {
|
|
1063
|
-
cachedCredentials = {
|
|
1064
|
-
accessToken,
|
|
1065
|
-
sessionKey,
|
|
1066
|
-
spaceId: config?.spaceId,
|
|
1067
|
-
teamId: config?.teamId,
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
/**
|
|
1071
|
-
* Check if credentials have changed compared to cache.
|
|
1072
|
-
*/
|
|
1073
|
-
function credentialsChanged(currentToken, currentConfig) {
|
|
1074
|
-
// No cached credentials = first run or was stopped
|
|
1075
|
-
if (!cachedCredentials) {
|
|
1076
|
-
return currentToken ? 'changed' : 'missing';
|
|
1077
|
-
}
|
|
1078
|
-
// Token missing = credentials gone
|
|
1079
|
-
if (!currentToken) {
|
|
1080
|
-
return 'missing';
|
|
1081
|
-
}
|
|
1082
|
-
// Compare token
|
|
1083
|
-
if (currentToken.accessToken !== cachedCredentials.accessToken ||
|
|
1084
|
-
currentToken.sessionKey !== cachedCredentials.sessionKey) {
|
|
1085
|
-
return 'changed';
|
|
1086
|
-
}
|
|
1087
|
-
// Compare config (spaceId/teamId)
|
|
1088
|
-
const currentSpaceId = currentConfig?.spaceId;
|
|
1089
|
-
const currentTeamId = currentConfig?.teamId;
|
|
1090
|
-
if (currentSpaceId !== cachedCredentials.spaceId || currentTeamId !== cachedCredentials.teamId) {
|
|
1091
|
-
return 'changed';
|
|
1092
|
-
}
|
|
1093
|
-
return 'unchanged';
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Poll credentials and sync CipherAgent state.
|
|
1097
|
-
*
|
|
1098
|
-
* Called periodically to detect auth/config changes:
|
|
1099
|
-
* - If credentials MISSING → stop CipherAgent
|
|
1100
|
-
* - If credentials CHANGED → reinit CipherAgent
|
|
1101
|
-
* - If UNCHANGED → do nothing
|
|
1102
|
-
*/
|
|
1103
|
-
async function pollCredentialsAndSync() {
|
|
1104
|
-
// Guard: prevent concurrent polling
|
|
1105
|
-
if (isPolling) {
|
|
1106
|
-
return;
|
|
1107
|
-
}
|
|
1108
|
-
// Guard: don't poll during cleanup or initialization
|
|
1109
|
-
if (isCleaningUp || isInitializing) {
|
|
1110
|
-
return;
|
|
1111
|
-
}
|
|
1112
|
-
isPolling = true;
|
|
1113
|
-
try {
|
|
1114
|
-
// Use lazy-initialized cached stores (avoid creating new instances every poll)
|
|
1115
|
-
const stores = getPollingStores();
|
|
1116
|
-
const authToken = await stores.pollingTokenStore.load();
|
|
1117
|
-
const brvConfig = await stores.pollingConfigStore.read();
|
|
1118
|
-
// Detect change
|
|
1119
|
-
const tokenInfo = authToken ? { accessToken: authToken.accessToken, sessionKey: authToken.sessionKey } : undefined;
|
|
1120
|
-
const configInfo = brvConfig ? { spaceId: brvConfig.spaceId, teamId: brvConfig.teamId } : undefined;
|
|
1121
|
-
const changeStatus = credentialsChanged(tokenInfo, configInfo);
|
|
1122
|
-
switch (changeStatus) {
|
|
1123
|
-
case 'changed': {
|
|
1124
|
-
// Check RIGHT BEFORE reinit - after all awaits, to catch tasks added during awaits
|
|
1125
|
-
// Must check BOTH active (running) AND queued tasks to prevent race condition
|
|
1126
|
-
// where task is enqueued after this check but before stopCipherAgent() clears taskProcessor
|
|
1127
|
-
if (hasPendingWork() || isReinitializing) {
|
|
1128
|
-
agentLog('Credentials changed but tasks in progress, queued, or reinit in progress - deferring');
|
|
1129
|
-
return;
|
|
1130
|
-
}
|
|
1131
|
-
// Set flag IMMEDIATELY after check to close TOCTOU window
|
|
1132
|
-
// tryInitializeAgent will manage the flag from here (set on entry, clear in finally)
|
|
1133
|
-
isReinitializing = true;
|
|
1134
|
-
// Credentials changed - reinit CipherAgent
|
|
1135
|
-
agentLog('Credentials changed - reinitializing CipherAgent');
|
|
1136
|
-
const success = await tryInitializeAgent(true); // forceReinit
|
|
1137
|
-
if (success) {
|
|
1138
|
-
agentLog('CipherAgent reinitialized with new credentials');
|
|
1139
|
-
}
|
|
1140
|
-
else {
|
|
1141
|
-
agentLog('CipherAgent reinitialization failed');
|
|
1142
|
-
}
|
|
1143
|
-
break;
|
|
1144
|
-
}
|
|
1145
|
-
case 'missing': {
|
|
1146
|
-
// Credentials gone - stop CipherAgent if running
|
|
1147
|
-
if (isAgentInitialized) {
|
|
1148
|
-
if (hasPendingWork()) {
|
|
1149
|
-
agentLog('Credentials missing but tasks in progress - deferring stop');
|
|
1150
|
-
return;
|
|
1151
|
-
}
|
|
1152
|
-
agentLog('Credentials missing - stopping CipherAgent');
|
|
1153
|
-
await stopCipherAgent();
|
|
1154
|
-
}
|
|
1155
|
-
break;
|
|
1156
|
-
}
|
|
1157
|
-
case 'unchanged': {
|
|
1158
|
-
// No change - check if token expired (edge case)
|
|
1159
|
-
if (authToken?.isExpired() && isAgentInitialized) {
|
|
1160
|
-
if (hasPendingWork()) {
|
|
1161
|
-
agentLog('Token expired but tasks in progress - deferring stop');
|
|
1162
|
-
return;
|
|
1163
|
-
}
|
|
1164
|
-
agentLog('Token expired - stopping CipherAgent');
|
|
1165
|
-
await stopCipherAgent();
|
|
1166
|
-
}
|
|
1167
|
-
break;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
catch (error) {
|
|
1172
|
-
// Don't crash on poll errors - just log and continue
|
|
1173
|
-
agentLog(`Credentials poll error: ${error}`);
|
|
1174
|
-
}
|
|
1175
|
-
finally {
|
|
1176
|
-
isPolling = false;
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Start credentials polling.
|
|
1181
|
-
* Uses recursive setTimeout pattern (same as parent heartbeat).
|
|
1182
|
-
*/
|
|
1183
|
-
function startCredentialsPolling() {
|
|
1184
|
-
if (credentialsPollingRunning) {
|
|
1185
|
-
return;
|
|
1186
|
-
}
|
|
1187
|
-
credentialsPollingRunning = true;
|
|
1188
|
-
const poll = () => {
|
|
1189
|
-
if (!credentialsPollingRunning) {
|
|
1190
|
-
return;
|
|
1191
|
-
}
|
|
1192
|
-
pollCredentialsAndSync()
|
|
1193
|
-
.catch((error) => {
|
|
1194
|
-
agentLog(`Credentials poll failed: ${error}`);
|
|
1195
|
-
})
|
|
1196
|
-
.finally(() => {
|
|
1197
|
-
// Schedule next poll (only if still running)
|
|
1198
|
-
if (credentialsPollingRunning) {
|
|
1199
|
-
setTimeout(poll, CREDENTIALS_POLL_INTERVAL_MS);
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1202
|
-
};
|
|
1203
|
-
// Start first poll after delay
|
|
1204
|
-
setTimeout(poll, CREDENTIALS_POLL_INTERVAL_MS);
|
|
1205
|
-
agentLog('Credentials polling started');
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* Stop credentials polling.
|
|
1209
|
-
*/
|
|
1210
|
-
function stopCredentialsPolling() {
|
|
1211
|
-
credentialsPollingRunning = false;
|
|
1212
|
-
}
|
|
1213
|
-
// ============================================================================
|
|
1214
|
-
// Agent Status Reporting
|
|
1215
|
-
// ============================================================================
|
|
1216
|
-
/**
|
|
1217
|
-
* Get current agent status for health check.
|
|
1218
|
-
* Used by Transport to check if agent is ready before forwarding tasks.
|
|
1219
|
-
*/
|
|
1220
|
-
function getAgentStatus() {
|
|
1221
|
-
return {
|
|
1222
|
-
activeTasks: taskQueueManager.getActiveCount(),
|
|
1223
|
-
hasAuth: cachedCredentials !== undefined,
|
|
1224
|
-
// Check both spaceId and teamId for safety (both must be set after /init)
|
|
1225
|
-
hasConfig: cachedCredentials?.spaceId !== undefined && cachedCredentials?.teamId !== undefined,
|
|
1226
|
-
isInitialized: isAgentInitialized,
|
|
1227
|
-
lastError: initializationError?.message,
|
|
1228
|
-
queuedTasks: taskQueueManager.getQueuedCount(),
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* Broadcast status change to Transport.
|
|
1233
|
-
* Called when cipher state changes (init success/fail, stop, credentials change).
|
|
1234
|
-
* Transport will forward to all connected clients.
|
|
1235
|
-
*/
|
|
1236
|
-
function broadcastStatusChange() {
|
|
1237
|
-
const status = getAgentStatus();
|
|
1238
|
-
transportClient?.requestWithAck('agent:status:changed', status).catch(logTransportError);
|
|
1239
|
-
}
|
|
1240
|
-
/**
|
|
1241
|
-
* Stop Agent Process.
|
|
1242
|
-
*/
|
|
1243
|
-
async function stopAgent() {
|
|
1244
|
-
// Guard: prevent double cleanup
|
|
1245
|
-
if (isCleaningUp) {
|
|
1246
|
-
agentLog('Cleanup already in progress, skipping');
|
|
1247
|
-
return;
|
|
1248
|
-
}
|
|
1249
|
-
isCleaningUp = true;
|
|
1250
|
-
try {
|
|
1251
|
-
// Stop polling and heartbeat first
|
|
1252
|
-
stopCredentialsPolling();
|
|
1253
|
-
parentHeartbeat?.stop();
|
|
1254
|
-
// Notify and clear task queue
|
|
1255
|
-
notifyQueuedTasksAboutDropAndClear('agent shutting down');
|
|
1256
|
-
// Cleanup event forwarders before stopping agent
|
|
1257
|
-
cleanupAgentEventForwarding();
|
|
1258
|
-
// Stop CipherAgent first
|
|
1259
|
-
if (cipherAgent) {
|
|
1260
|
-
await cipherAgent.stop();
|
|
1261
|
-
cipherAgent = undefined;
|
|
1262
|
-
agentLog('CipherAgent stopped');
|
|
1263
|
-
}
|
|
1264
|
-
if (transportClient) {
|
|
1265
|
-
await transportClient.disconnect();
|
|
1266
|
-
transportClient = undefined;
|
|
1267
|
-
}
|
|
1268
|
-
taskProcessor = undefined;
|
|
1269
|
-
isAgentInitialized = false;
|
|
1270
|
-
agentLog('Stopped');
|
|
1271
|
-
}
|
|
1272
|
-
finally {
|
|
1273
|
-
isCleaningUp = false;
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
// ============================================================================
|
|
1277
|
-
// Worker Entry Point
|
|
1278
|
-
// ============================================================================
|
|
1279
|
-
async function runWorker() {
|
|
1280
|
-
try {
|
|
1281
|
-
await startAgent();
|
|
1282
|
-
sendToParent({ type: 'ready' });
|
|
1283
|
-
// Start parent heartbeat monitoring after ready
|
|
1284
|
-
// This ensures we self-terminate if parent dies (SIGKILL scenario)
|
|
1285
|
-
parentHeartbeat = createParentHeartbeat({
|
|
1286
|
-
cleanup: stopAgent,
|
|
1287
|
-
log: agentLog,
|
|
1288
|
-
});
|
|
1289
|
-
parentHeartbeat.start();
|
|
1290
|
-
// Start credentials polling to detect auth/config changes
|
|
1291
|
-
// This ensures CipherAgent stays in sync with user's login state
|
|
1292
|
-
startCredentialsPolling();
|
|
1293
|
-
}
|
|
1294
|
-
catch (error) {
|
|
1295
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1296
|
-
agentLog(`Failed to start: ${message}`);
|
|
1297
|
-
sendToParent({ error: message, type: 'error' });
|
|
1298
|
-
// Cleanup before exit to release any acquired resources
|
|
1299
|
-
await stopAgent().catch(() => { });
|
|
1300
|
-
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
1301
|
-
process.exit(1);
|
|
1302
|
-
}
|
|
1303
|
-
// IPC message handler
|
|
1304
|
-
process.on('message', async (msg) => {
|
|
1305
|
-
switch (msg.type) {
|
|
1306
|
-
case 'health-check': {
|
|
1307
|
-
// Fix #3: Health-check after sleep/wake - verify and repair connection
|
|
1308
|
-
agentLog('Received health-check from parent - verifying connection');
|
|
1309
|
-
// Guard: skip health check during initialization (would interfere with startup sequence)
|
|
1310
|
-
if (isInitializing) {
|
|
1311
|
-
agentLog('Health-check skipped - initialization in progress');
|
|
1312
|
-
sendToParent({ success: true, type: 'health-check-result' });
|
|
1313
|
-
break;
|
|
1314
|
-
}
|
|
1315
|
-
// Guard: transportClient must exist for health check
|
|
1316
|
-
if (!transportClient) {
|
|
1317
|
-
agentLog('Health-check failed - transportClient not initialized');
|
|
1318
|
-
sendToParent({ success: false, type: 'health-check-result' });
|
|
1319
|
-
break;
|
|
1320
|
-
}
|
|
1321
|
-
try {
|
|
1322
|
-
// Fix #5: Fail-fast - verify socket is responsive before expensive operation
|
|
1323
|
-
// After sleep, socket.connected may be true but TCP connection is dead
|
|
1324
|
-
const isAlive = await transportClient.isConnected(2000); // 2s timeout
|
|
1325
|
-
agentLog(`Health-check: isConnected=${isAlive}, state=${transportClient.getState()}`);
|
|
1326
|
-
if (!isAlive) {
|
|
1327
|
-
agentLog('Health-check failed - socket not responsive (connection stale)');
|
|
1328
|
-
sendToParent({ success: false, type: 'health-check-result' });
|
|
1329
|
-
break;
|
|
1330
|
-
}
|
|
1331
|
-
// Re-register with Transport to ensure connection is alive
|
|
1332
|
-
// Include status in register payload (Transport caches it atomically)
|
|
1333
|
-
await transportClient.requestWithAck('agent:register', { status: getAgentStatus() });
|
|
1334
|
-
agentLog('Health-check passed - connection verified');
|
|
1335
|
-
sendToParent({ success: true, type: 'health-check-result' });
|
|
1336
|
-
}
|
|
1337
|
-
catch (error) {
|
|
1338
|
-
agentLog(`Health-check failed - connection may be stale: ${error}`);
|
|
1339
|
-
sendToParent({ success: false, type: 'health-check-result' });
|
|
1340
|
-
// Socket.IO will attempt reconnection automatically
|
|
1341
|
-
}
|
|
1342
|
-
break;
|
|
1343
|
-
}
|
|
1344
|
-
case 'ping': {
|
|
1345
|
-
sendToParent({ type: 'pong' });
|
|
1346
|
-
break;
|
|
1347
|
-
}
|
|
1348
|
-
case 'shutdown': {
|
|
1349
|
-
await stopAgent();
|
|
1350
|
-
sendToParent({ type: 'stopped' });
|
|
1351
|
-
// eslint-disable-next-line n/no-process-exit
|
|
1352
|
-
process.exit(0);
|
|
1353
|
-
// Note: break unreachable due to process.exit() above
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
});
|
|
1357
|
-
// Signal handlers
|
|
1358
|
-
const cleanup = async () => {
|
|
1359
|
-
await stopAgent();
|
|
1360
|
-
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
1361
|
-
process.exit(0);
|
|
1362
|
-
};
|
|
1363
|
-
process.once('SIGTERM', cleanup);
|
|
1364
|
-
process.once('SIGINT', cleanup);
|
|
1365
|
-
process.once('disconnect', cleanup);
|
|
1366
|
-
// Global exception handlers - ensure cleanup on unexpected errors
|
|
1367
|
-
process.on('uncaughtException', async (error) => {
|
|
1368
|
-
agentLog(`Uncaught exception: ${error}`);
|
|
1369
|
-
await stopAgent().catch(() => { });
|
|
1370
|
-
// eslint-disable-next-line n/no-process-exit
|
|
1371
|
-
process.exit(1);
|
|
1372
|
-
});
|
|
1373
|
-
process.on('unhandledRejection', async (reason) => {
|
|
1374
|
-
agentLog(`Unhandled rejection: ${reason}`);
|
|
1375
|
-
await stopAgent().catch(() => { });
|
|
1376
|
-
// eslint-disable-next-line n/no-process-exit
|
|
1377
|
-
process.exit(1);
|
|
1378
|
-
});
|
|
1379
|
-
}
|
|
1380
|
-
// ============================================================================
|
|
1381
|
-
// Run
|
|
1382
|
-
// ============================================================================
|
|
1383
|
-
try {
|
|
1384
|
-
await runWorker();
|
|
1385
|
-
}
|
|
1386
|
-
catch (error) {
|
|
1387
|
-
agentLog(`Fatal error: ${error}`);
|
|
1388
|
-
// Cleanup before exit to release any acquired resources
|
|
1389
|
-
await stopAgent().catch(() => { });
|
|
1390
|
-
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
1391
|
-
process.exit(1);
|
|
1392
|
-
}
|