@cjhyy/code-shell-core 0.5.0-rc.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/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/agent/coordinator.d.ts +49 -0
- package/dist/agent/coordinator.js +77 -0
- package/dist/arena/arena.d.ts +43 -0
- package/dist/arena/arena.js +334 -0
- package/dist/arena/context/context-tools.d.ts +16 -0
- package/dist/arena/context/context-tools.js +231 -0
- package/dist/arena/detect-mode.d.ts +20 -0
- package/dist/arena/detect-mode.js +78 -0
- package/dist/arena/digest-builder.d.ts +25 -0
- package/dist/arena/digest-builder.js +120 -0
- package/dist/arena/index.d.ts +29 -0
- package/dist/arena/index.js +29 -0
- package/dist/arena/iterate/convergence.d.ts +25 -0
- package/dist/arena/iterate/convergence.js +103 -0
- package/dist/arena/iterate/formats/index.d.ts +22 -0
- package/dist/arena/iterate/formats/index.js +283 -0
- package/dist/arena/iterate/index.d.ts +11 -0
- package/dist/arena/iterate/index.js +9 -0
- package/dist/arena/iterate/iterative-arena.d.ts +23 -0
- package/dist/arena/iterate/iterative-arena.js +237 -0
- package/dist/arena/iterate/parse.d.ts +42 -0
- package/dist/arena/iterate/parse.js +123 -0
- package/dist/arena/iterate/phases/argue.d.ts +22 -0
- package/dist/arena/iterate/phases/argue.js +159 -0
- package/dist/arena/iterate/phases/revise.d.ts +16 -0
- package/dist/arena/iterate/phases/revise.js +62 -0
- package/dist/arena/iterate/phases/tournament.d.ts +34 -0
- package/dist/arena/iterate/phases/tournament.js +113 -0
- package/dist/arena/iterate/tools/web-tools.d.ts +13 -0
- package/dist/arena/iterate/tools/web-tools.js +54 -0
- package/dist/arena/iterate/types.d.ts +152 -0
- package/dist/arena/iterate/types.js +8 -0
- package/dist/arena/ledger.d.ts +47 -0
- package/dist/arena/ledger.js +151 -0
- package/dist/arena/lenses/architecture.d.ts +5 -0
- package/dist/arena/lenses/architecture.js +22 -0
- package/dist/arena/lenses/engineering.d.ts +5 -0
- package/dist/arena/lenses/engineering.js +22 -0
- package/dist/arena/lenses/general.d.ts +5 -0
- package/dist/arena/lenses/general.js +20 -0
- package/dist/arena/lenses/index.d.ts +16 -0
- package/dist/arena/lenses/index.js +47 -0
- package/dist/arena/lenses/product.d.ts +5 -0
- package/dist/arena/lenses/product.js +22 -0
- package/dist/arena/model-presets.d.ts +23 -0
- package/dist/arena/model-presets.js +44 -0
- package/dist/arena/phases/adjudication.d.ts +24 -0
- package/dist/arena/phases/adjudication.js +144 -0
- package/dist/arena/phases/build-consensus.d.ts +29 -0
- package/dist/arena/phases/build-consensus.js +86 -0
- package/dist/arena/phases/claim-registry.d.ts +26 -0
- package/dist/arena/phases/claim-registry.js +60 -0
- package/dist/arena/phases/cross-review.d.ts +45 -0
- package/dist/arena/phases/cross-review.js +224 -0
- package/dist/arena/phases/debate-rounds.d.ts +27 -0
- package/dist/arena/phases/debate-rounds.js +162 -0
- package/dist/arena/phases/participant-research.d.ts +38 -0
- package/dist/arena/phases/participant-research.js +317 -0
- package/dist/arena/phases/planning-detail-expansion.d.ts +38 -0
- package/dist/arena/phases/planning-detail-expansion.js +121 -0
- package/dist/arena/planner.d.ts +27 -0
- package/dist/arena/planner.js +312 -0
- package/dist/arena/providers/docs.d.ts +6 -0
- package/dist/arena/providers/docs.js +108 -0
- package/dist/arena/providers/git.d.ts +8 -0
- package/dist/arena/providers/git.js +174 -0
- package/dist/arena/providers/index.d.ts +32 -0
- package/dist/arena/providers/index.js +132 -0
- package/dist/arena/providers/none.d.ts +7 -0
- package/dist/arena/providers/none.js +11 -0
- package/dist/arena/providers/repo.d.ts +6 -0
- package/dist/arena/providers/repo.js +255 -0
- package/dist/arena/render/session.d.ts +17 -0
- package/dist/arena/render/session.js +190 -0
- package/dist/arena/render/terminal.d.ts +34 -0
- package/dist/arena/render/terminal.js +286 -0
- package/dist/arena/strategies/discussion.d.ts +25 -0
- package/dist/arena/strategies/discussion.js +143 -0
- package/dist/arena/strategies/index.d.ts +15 -0
- package/dist/arena/strategies/index.js +28 -0
- package/dist/arena/strategies/language-wrapper.d.ts +17 -0
- package/dist/arena/strategies/language-wrapper.js +102 -0
- package/dist/arena/strategies/lens-wrapper.d.ts +16 -0
- package/dist/arena/strategies/lens-wrapper.js +236 -0
- package/dist/arena/strategies/planning.d.ts +30 -0
- package/dist/arena/strategies/planning.js +225 -0
- package/dist/arena/strategies/review.d.ts +26 -0
- package/dist/arena/strategies/review.js +168 -0
- package/dist/arena/strategies/utils.d.ts +39 -0
- package/dist/arena/strategies/utils.js +647 -0
- package/dist/arena/tools/selector.d.ts +17 -0
- package/dist/arena/tools/selector.js +61 -0
- package/dist/arena/transitions.d.ts +48 -0
- package/dist/arena/transitions.js +92 -0
- package/dist/arena/types.d.ts +508 -0
- package/dist/arena/types.js +27 -0
- package/dist/cli/agent-server-stdio.d.ts +32 -0
- package/dist/cli/agent-server-stdio.js +116 -0
- package/dist/colorizer.d.ts +23 -0
- package/dist/colorizer.js +12 -0
- package/dist/context/compaction.d.ts +116 -0
- package/dist/context/compaction.js +534 -0
- package/dist/context/manager.d.ts +145 -0
- package/dist/context/manager.js +423 -0
- package/dist/context/token-counter.d.ts +27 -0
- package/dist/context/token-counter.js +91 -0
- package/dist/context/tool-result-storage.d.ts +96 -0
- package/dist/context/tool-result-storage.js +296 -0
- package/dist/cost-tracker.d.ts +64 -0
- package/dist/cost-tracker.js +314 -0
- package/dist/cron/scheduler.d.ts +34 -0
- package/dist/cron/scheduler.js +115 -0
- package/dist/data/deepseek-models.json +46 -0
- package/dist/data/gemini-models.json +67 -0
- package/dist/data/openai-models.json +175 -0
- package/dist/data/openrouter-models.d.ts +35 -0
- package/dist/data/openrouter-models.js +36 -0
- package/dist/data/openrouter-models.json +4626 -0
- package/dist/data/openrouter-sync.d.ts +16 -0
- package/dist/data/openrouter-sync.js +53 -0
- package/dist/data/static-catalogs.d.ts +25 -0
- package/dist/data/static-catalogs.js +26 -0
- package/dist/data/zai-models.json +56 -0
- package/dist/engine/cost-store.d.ts +22 -0
- package/dist/engine/cost-store.js +15 -0
- package/dist/engine/engine.d.ts +295 -0
- package/dist/engine/engine.js +1467 -0
- package/dist/engine/model-facade.d.ts +24 -0
- package/dist/engine/model-facade.js +194 -0
- package/dist/engine/parse-task.d.ts +59 -0
- package/dist/engine/parse-task.js +135 -0
- package/dist/engine/patch-orphaned-tools.d.ts +52 -0
- package/dist/engine/patch-orphaned-tools.js +95 -0
- package/dist/engine/query.d.ts +50 -0
- package/dist/engine/query.js +107 -0
- package/dist/engine/runtime.d.ts +50 -0
- package/dist/engine/runtime.js +59 -0
- package/dist/engine/streaming-tool-queue.d.ts +34 -0
- package/dist/engine/streaming-tool-queue.js +61 -0
- package/dist/engine/token-budget.d.ts +22 -0
- package/dist/engine/token-budget.js +40 -0
- package/dist/engine/tool-summary.d.ts +13 -0
- package/dist/engine/tool-summary.js +35 -0
- package/dist/engine/turn-loop.d.ts +122 -0
- package/dist/engine/turn-loop.js +602 -0
- package/dist/engine/turn-state.d.ts +20 -0
- package/dist/engine/turn-state.js +17 -0
- package/dist/exceptions.d.ts +61 -0
- package/dist/exceptions.js +116 -0
- package/dist/git/utils.d.ts +35 -0
- package/dist/git/utils.js +98 -0
- package/dist/git/worktree.d.ts +36 -0
- package/dist/git/worktree.js +139 -0
- package/dist/hooks/events.d.ts +114 -0
- package/dist/hooks/events.js +4 -0
- package/dist/hooks/inject.d.ts +19 -0
- package/dist/hooks/inject.js +29 -0
- package/dist/hooks/registry.d.ts +15 -0
- package/dist/hooks/registry.js +84 -0
- package/dist/hooks/shell-runner.d.ts +45 -0
- package/dist/hooks/shell-runner.js +173 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +145 -0
- package/dist/llm/api-key-sanitize.d.ts +22 -0
- package/dist/llm/api-key-sanitize.js +81 -0
- package/dist/llm/capabilities/index.d.ts +20 -0
- package/dist/llm/capabilities/index.js +39 -0
- package/dist/llm/capabilities/rules.d.ts +26 -0
- package/dist/llm/capabilities/rules.js +215 -0
- package/dist/llm/capabilities/types.d.ts +114 -0
- package/dist/llm/capabilities/types.js +24 -0
- package/dist/llm/client-base.d.ts +29 -0
- package/dist/llm/client-base.js +137 -0
- package/dist/llm/client-factory.d.ts +10 -0
- package/dist/llm/client-factory.js +29 -0
- package/dist/llm/model-cache.d.ts +21 -0
- package/dist/llm/model-cache.js +46 -0
- package/dist/llm/model-fetcher.d.ts +29 -0
- package/dist/llm/model-fetcher.js +282 -0
- package/dist/llm/model-pool.d.ts +95 -0
- package/dist/llm/model-pool.js +246 -0
- package/dist/llm/provider-catalog.d.ts +32 -0
- package/dist/llm/provider-catalog.js +50 -0
- package/dist/llm/provider-kinds.d.ts +21 -0
- package/dist/llm/provider-kinds.js +132 -0
- package/dist/llm/providers/anthropic.d.ts +19 -0
- package/dist/llm/providers/anthropic.js +267 -0
- package/dist/llm/providers/openai.d.ts +64 -0
- package/dist/llm/providers/openai.js +606 -0
- package/dist/llm/retry.d.ts +12 -0
- package/dist/llm/retry.js +17 -0
- package/dist/llm/stream-watchdog.d.ts +42 -0
- package/dist/llm/stream-watchdog.js +70 -0
- package/dist/llm/token-counter.d.ts +17 -0
- package/dist/llm/token-counter.js +36 -0
- package/dist/llm/types.d.ts +37 -0
- package/dist/llm/types.js +4 -0
- package/dist/logging/logger.d.ts +109 -0
- package/dist/logging/logger.js +390 -0
- package/dist/logging/sanitize-messages.d.ts +42 -0
- package/dist/logging/sanitize-messages.js +150 -0
- package/dist/logging/session-recorder.d.ts +90 -0
- package/dist/logging/session-recorder.js +304 -0
- package/dist/lsp/client.d.ts +41 -0
- package/dist/lsp/client.js +166 -0
- package/dist/lsp/manager.d.ts +40 -0
- package/dist/lsp/manager.js +124 -0
- package/dist/lsp/servers.d.ts +16 -0
- package/dist/lsp/servers.js +60 -0
- package/dist/migrate-models.d.ts +45 -0
- package/dist/migrate-models.js +179 -0
- package/dist/onboarding.d.ts +189 -0
- package/dist/onboarding.js +625 -0
- package/dist/plugins/gitOps.d.ts +32 -0
- package/dist/plugins/gitOps.js +62 -0
- package/dist/plugins/installedPlugins.d.ts +15 -0
- package/dist/plugins/installedPlugins.js +56 -0
- package/dist/plugins/knownMarketplaces.d.ts +10 -0
- package/dist/plugins/knownMarketplaces.js +46 -0
- package/dist/plugins/loadPluginHooks.d.ts +52 -0
- package/dist/plugins/loadPluginHooks.js +162 -0
- package/dist/plugins/marketplaceManager.d.ts +49 -0
- package/dist/plugins/marketplaceManager.js +142 -0
- package/dist/plugins/parseMarketplaceInput.d.ts +16 -0
- package/dist/plugins/parseMarketplaceInput.js +73 -0
- package/dist/plugins/pluginCommandHook.d.ts +54 -0
- package/dist/plugins/pluginCommandHook.js +180 -0
- package/dist/plugins/pluginCommandsLoader.d.ts +25 -0
- package/dist/plugins/pluginCommandsLoader.js +114 -0
- package/dist/plugins/pluginInstaller.d.ts +36 -0
- package/dist/plugins/pluginInstaller.js +228 -0
- package/dist/plugins/schemas.d.ts +9 -0
- package/dist/plugins/schemas.js +136 -0
- package/dist/plugins/types.d.ts +75 -0
- package/dist/plugins/types.js +7 -0
- package/dist/plugins/varRewrite.d.ts +42 -0
- package/dist/plugins/varRewrite.js +129 -0
- package/dist/preset/index.d.ts +60 -0
- package/dist/preset/index.js +159 -0
- package/dist/product/define.d.ts +60 -0
- package/dist/product/define.js +123 -0
- package/dist/product/index.d.ts +5 -0
- package/dist/product/index.js +4 -0
- package/dist/product/types.d.ts +111 -0
- package/dist/product/types.js +21 -0
- package/dist/prompt/composer.d.ts +49 -0
- package/dist/prompt/composer.js +168 -0
- package/dist/prompt/instruction-scanner.d.ts +54 -0
- package/dist/prompt/instruction-scanner.js +187 -0
- package/dist/prompt/section-cache.d.ts +15 -0
- package/dist/prompt/section-cache.js +31 -0
- package/dist/prompt/section-loader.d.ts +26 -0
- package/dist/prompt/section-loader.js +53 -0
- package/dist/prompt/sections/base.md +35 -0
- package/dist/prompt/sections/coding.md +31 -0
- package/dist/prompt/sections/orchestration.md +16 -0
- package/dist/prompt/sections/tone.md +9 -0
- package/dist/protocol/chat-session-manager.d.ts +33 -0
- package/dist/protocol/chat-session-manager.js +65 -0
- package/dist/protocol/chat-session.d.ts +49 -0
- package/dist/protocol/chat-session.js +86 -0
- package/dist/protocol/client.d.ts +104 -0
- package/dist/protocol/client.js +260 -0
- package/dist/protocol/factories.d.ts +93 -0
- package/dist/protocol/factories.js +64 -0
- package/dist/protocol/helpers.d.ts +42 -0
- package/dist/protocol/helpers.js +55 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +4 -0
- package/dist/protocol/server.d.ts +80 -0
- package/dist/protocol/server.js +855 -0
- package/dist/protocol/transport.d.ts +37 -0
- package/dist/protocol/transport.js +85 -0
- package/dist/protocol/types.d.ts +221 -0
- package/dist/protocol/types.js +61 -0
- package/dist/remote/bridge.d.ts +37 -0
- package/dist/remote/bridge.js +103 -0
- package/dist/run/ArtifactTracker.d.ts +38 -0
- package/dist/run/ArtifactTracker.js +132 -0
- package/dist/run/CheckpointWriter.d.ts +53 -0
- package/dist/run/CheckpointWriter.js +135 -0
- package/dist/run/EngineRunner.d.ts +72 -0
- package/dist/run/EngineRunner.js +119 -0
- package/dist/run/Evaluator.d.ts +56 -0
- package/dist/run/Evaluator.js +62 -0
- package/dist/run/FileRunStore.d.ts +39 -0
- package/dist/run/FileRunStore.js +176 -0
- package/dist/run/Heartbeat.d.ts +54 -0
- package/dist/run/Heartbeat.js +123 -0
- package/dist/run/RunApprovalBackend.d.ts +53 -0
- package/dist/run/RunApprovalBackend.js +85 -0
- package/dist/run/RunLock.d.ts +40 -0
- package/dist/run/RunLock.js +98 -0
- package/dist/run/RunManager.d.ts +82 -0
- package/dist/run/RunManager.js +587 -0
- package/dist/run/RunQueue.d.ts +27 -0
- package/dist/run/RunQueue.js +73 -0
- package/dist/run/RunStore.d.ts +25 -0
- package/dist/run/RunStore.js +9 -0
- package/dist/run/factory.d.ts +63 -0
- package/dist/run/factory.js +51 -0
- package/dist/run/index.d.ts +17 -0
- package/dist/run/index.js +23 -0
- package/dist/run/types.d.ts +136 -0
- package/dist/run/types.js +28 -0
- package/dist/runtime/safe-spawn.d.ts +118 -0
- package/dist/runtime/safe-spawn.js +268 -0
- package/dist/services/analytics.d.ts +29 -0
- package/dist/services/analytics.js +84 -0
- package/dist/services/auto-dream.d.ts +49 -0
- package/dist/services/auto-dream.js +124 -0
- package/dist/services/diagnostics.d.ts +41 -0
- package/dist/services/diagnostics.js +99 -0
- package/dist/services/extract-memories.d.ts +31 -0
- package/dist/services/extract-memories.js +71 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/index.js +17 -0
- package/dist/services/memory-orchestrator.d.ts +60 -0
- package/dist/services/memory-orchestrator.js +133 -0
- package/dist/services/notifier.d.ts +25 -0
- package/dist/services/notifier.js +69 -0
- package/dist/services/oauth.d.ts +27 -0
- package/dist/services/oauth.js +153 -0
- package/dist/services/session-memory.d.ts +37 -0
- package/dist/services/session-memory.js +81 -0
- package/dist/session/file-history.d.ts +41 -0
- package/dist/session/file-history.js +115 -0
- package/dist/session/memory.d.ts +104 -0
- package/dist/session/memory.js +310 -0
- package/dist/session/session-manager.d.ts +41 -0
- package/dist/session/session-manager.js +261 -0
- package/dist/session/transcript.d.ts +39 -0
- package/dist/session/transcript.js +186 -0
- package/dist/settings/manager.d.ts +36 -0
- package/dist/settings/manager.js +187 -0
- package/dist/settings/schema.d.ts +1219 -0
- package/dist/settings/schema.js +246 -0
- package/dist/skills/frontmatter.d.ts +13 -0
- package/dist/skills/frontmatter.js +70 -0
- package/dist/skills/index.d.ts +7 -0
- package/dist/skills/index.js +6 -0
- package/dist/skills/scanner.d.ts +31 -0
- package/dist/skills/scanner.js +171 -0
- package/dist/state.d.ts +160 -0
- package/dist/state.js +267 -0
- package/dist/tool-system/builtin/agent-notifications.d.ts +84 -0
- package/dist/tool-system/builtin/agent-notifications.js +197 -0
- package/dist/tool-system/builtin/agent-registry.d.ts +67 -0
- package/dist/tool-system/builtin/agent-registry.js +126 -0
- package/dist/tool-system/builtin/agent-transcript-translator.d.ts +22 -0
- package/dist/tool-system/builtin/agent-transcript-translator.js +160 -0
- package/dist/tool-system/builtin/agent.d.ts +16 -0
- package/dist/tool-system/builtin/agent.js +364 -0
- package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
- package/dist/tool-system/builtin/apply-patch/applier.js +250 -0
- package/dist/tool-system/builtin/apply-patch/index.d.ts +20 -0
- package/dist/tool-system/builtin/apply-patch/index.js +101 -0
- package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
- package/dist/tool-system/builtin/apply-patch/parser.js +212 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.js +123 -0
- package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
- package/dist/tool-system/builtin/apply-patch/types.js +13 -0
- package/dist/tool-system/builtin/arena.d.ts +31 -0
- package/dist/tool-system/builtin/arena.js +416 -0
- package/dist/tool-system/builtin/ask-user.d.ts +20 -0
- package/dist/tool-system/builtin/ask-user.js +99 -0
- package/dist/tool-system/builtin/bash.d.ts +21 -0
- package/dist/tool-system/builtin/bash.js +149 -0
- package/dist/tool-system/builtin/brief.d.ts +6 -0
- package/dist/tool-system/builtin/brief.js +41 -0
- package/dist/tool-system/builtin/config.d.ts +6 -0
- package/dist/tool-system/builtin/config.js +67 -0
- package/dist/tool-system/builtin/cron.d.ts +10 -0
- package/dist/tool-system/builtin/cron.js +61 -0
- package/dist/tool-system/builtin/edit.d.ts +6 -0
- package/dist/tool-system/builtin/edit.js +100 -0
- package/dist/tool-system/builtin/file-cache.d.ts +11 -0
- package/dist/tool-system/builtin/file-cache.js +39 -0
- package/dist/tool-system/builtin/glob.d.ts +7 -0
- package/dist/tool-system/builtin/glob.js +76 -0
- package/dist/tool-system/builtin/grep.d.ts +7 -0
- package/dist/tool-system/builtin/grep.js +150 -0
- package/dist/tool-system/builtin/index.d.ts +20 -0
- package/dist/tool-system/builtin/index.js +449 -0
- package/dist/tool-system/builtin/lsp.d.ts +6 -0
- package/dist/tool-system/builtin/lsp.js +141 -0
- package/dist/tool-system/builtin/mcp-tools.d.ts +10 -0
- package/dist/tool-system/builtin/mcp-tools.js +102 -0
- package/dist/tool-system/builtin/memory.d.ts +26 -0
- package/dist/tool-system/builtin/memory.js +226 -0
- package/dist/tool-system/builtin/notebook-edit.d.ts +6 -0
- package/dist/tool-system/builtin/notebook-edit.js +124 -0
- package/dist/tool-system/builtin/plan.d.ts +15 -0
- package/dist/tool-system/builtin/plan.js +55 -0
- package/dist/tool-system/builtin/powershell.d.ts +11 -0
- package/dist/tool-system/builtin/powershell.js +64 -0
- package/dist/tool-system/builtin/read.d.ts +6 -0
- package/dist/tool-system/builtin/read.js +70 -0
- package/dist/tool-system/builtin/remote-trigger.d.ts +6 -0
- package/dist/tool-system/builtin/remote-trigger.js +54 -0
- package/dist/tool-system/builtin/repl.d.ts +11 -0
- package/dist/tool-system/builtin/repl.js +82 -0
- package/dist/tool-system/builtin/send-message.d.ts +6 -0
- package/dist/tool-system/builtin/send-message.js +47 -0
- package/dist/tool-system/builtin/skill-prompt.d.ts +20 -0
- package/dist/tool-system/builtin/skill-prompt.js +52 -0
- package/dist/tool-system/builtin/skill.d.ts +9 -0
- package/dist/tool-system/builtin/skill.js +55 -0
- package/dist/tool-system/builtin/sleep.d.ts +6 -0
- package/dist/tool-system/builtin/sleep.js +33 -0
- package/dist/tool-system/builtin/task.d.ts +48 -0
- package/dist/tool-system/builtin/task.js +139 -0
- package/dist/tool-system/builtin/tool-search.d.ts +11 -0
- package/dist/tool-system/builtin/tool-search.js +90 -0
- package/dist/tool-system/builtin/web-fetch.d.ts +10 -0
- package/dist/tool-system/builtin/web-fetch.js +328 -0
- package/dist/tool-system/builtin/web-search.d.ts +25 -0
- package/dist/tool-system/builtin/web-search.js +174 -0
- package/dist/tool-system/builtin/worktree.d.ts +10 -0
- package/dist/tool-system/builtin/worktree.js +95 -0
- package/dist/tool-system/builtin/write.d.ts +6 -0
- package/dist/tool-system/builtin/write.js +36 -0
- package/dist/tool-system/context.d.ts +165 -0
- package/dist/tool-system/context.js +18 -0
- package/dist/tool-system/executor.d.ts +49 -0
- package/dist/tool-system/executor.js +495 -0
- package/dist/tool-system/investigation-guard.d.ts +46 -0
- package/dist/tool-system/investigation-guard.js +155 -0
- package/dist/tool-system/mcp-manager.d.ts +67 -0
- package/dist/tool-system/mcp-manager.js +249 -0
- package/dist/tool-system/permission.d.ts +111 -0
- package/dist/tool-system/permission.js +774 -0
- package/dist/tool-system/registry.d.ts +32 -0
- package/dist/tool-system/registry.js +131 -0
- package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
- package/dist/tool-system/sandbox/bwrap.js +63 -0
- package/dist/tool-system/sandbox/index.d.ts +78 -0
- package/dist/tool-system/sandbox/index.js +222 -0
- package/dist/tool-system/sandbox/off.d.ts +2 -0
- package/dist/tool-system/sandbox/off.js +8 -0
- package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
- package/dist/tool-system/sandbox/seatbelt.js +109 -0
- package/dist/tool-system/task-guard.d.ts +29 -0
- package/dist/tool-system/task-guard.js +70 -0
- package/dist/tool-system/validation.d.ts +5 -0
- package/dist/tool-system/validation.js +39 -0
- package/dist/types.d.ts +376 -0
- package/dist/types.js +4 -0
- package/dist/updater.d.ts +65 -0
- package/dist/updater.js +405 -0
- package/dist/utils/debug.d.ts +41 -0
- package/dist/utils/debug.js +110 -0
- package/dist/utils/earlyInput.d.ts +43 -0
- package/dist/utils/earlyInput.js +166 -0
- package/dist/utils/env.d.ts +24 -0
- package/dist/utils/env.js +104 -0
- package/dist/utils/envUtils.d.ts +51 -0
- package/dist/utils/envUtils.js +135 -0
- package/dist/utils/execFileNoThrow.d.ts +39 -0
- package/dist/utils/execFileNoThrow.js +74 -0
- package/dist/utils/format.d.ts +44 -0
- package/dist/utils/format.js +236 -0
- package/dist/utils/intl.d.ts +22 -0
- package/dist/utils/intl.js +83 -0
- package/dist/utils/lockfile.d.ts +15 -0
- package/dist/utils/lockfile.js +30 -0
- package/dist/utils/memoize.d.ts +19 -0
- package/dist/utils/memoize.js +14 -0
- package/dist/utils/semver.d.ts +6 -0
- package/dist/utils/semver.js +13 -0
- package/dist/utils/sliceAnsi.d.ts +12 -0
- package/dist/utils/sliceAnsi.js +62 -0
- package/dist/utils/systemTheme.d.ts +40 -0
- package/dist/utils/systemTheme.js +108 -0
- package/dist/utils/task-sanitizer.d.ts +6 -0
- package/dist/utils/task-sanitizer.js +24 -0
- package/dist/utils/theme.d.ts +93 -0
- package/dist/utils/theme.js +544 -0
- package/dist/utils/toolDisplay.d.ts +31 -0
- package/dist/utils/toolDisplay.js +188 -0
- package/package.json +72 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport layer — abstracts how messages travel between client and server.
|
|
3
|
+
*
|
|
4
|
+
* Two implementations:
|
|
5
|
+
* - InProcessTransport: direct function calls (same process, zero overhead)
|
|
6
|
+
* - StdioTransport: newline-delimited JSON over stdin/stdout (cross-process,
|
|
7
|
+
* e.g. agent daemon spawned as child)
|
|
8
|
+
*/
|
|
9
|
+
import type { RpcMessage } from "./types.js";
|
|
10
|
+
import type { Readable, Writable } from "node:stream";
|
|
11
|
+
export interface Transport {
|
|
12
|
+
/** Send a message to the other side. */
|
|
13
|
+
send(message: RpcMessage): void;
|
|
14
|
+
/** Register a handler for incoming messages. */
|
|
15
|
+
onMessage(handler: (message: RpcMessage) => void): void;
|
|
16
|
+
/** Clean up resources. */
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a pair of linked transports for same-process use.
|
|
21
|
+
* Messages sent on one side are received on the other instantly.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createInProcessTransport(): [Transport, Transport];
|
|
24
|
+
/**
|
|
25
|
+
* Transport over stdio streams (newline-delimited JSON).
|
|
26
|
+
* Used for cross-process communication.
|
|
27
|
+
*/
|
|
28
|
+
export declare class StdioTransport implements Transport {
|
|
29
|
+
private readonly input;
|
|
30
|
+
private readonly output;
|
|
31
|
+
private rl;
|
|
32
|
+
private handlers;
|
|
33
|
+
constructor(input: Readable, output: Writable);
|
|
34
|
+
send(message: RpcMessage): void;
|
|
35
|
+
onMessage(handler: (message: RpcMessage) => void): void;
|
|
36
|
+
close(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport layer — abstracts how messages travel between client and server.
|
|
3
|
+
*
|
|
4
|
+
* Two implementations:
|
|
5
|
+
* - InProcessTransport: direct function calls (same process, zero overhead)
|
|
6
|
+
* - StdioTransport: newline-delimited JSON over stdin/stdout (cross-process,
|
|
7
|
+
* e.g. agent daemon spawned as child)
|
|
8
|
+
*/
|
|
9
|
+
import { EventEmitter } from "node:events";
|
|
10
|
+
import { createInterface } from "node:readline";
|
|
11
|
+
// ─── In-Process Transport ───────────────────────────────────────────
|
|
12
|
+
/**
|
|
13
|
+
* Creates a pair of linked transports for same-process use.
|
|
14
|
+
* Messages sent on one side are received on the other instantly.
|
|
15
|
+
*/
|
|
16
|
+
export function createInProcessTransport() {
|
|
17
|
+
const emitterA = new EventEmitter();
|
|
18
|
+
const emitterB = new EventEmitter();
|
|
19
|
+
const sideA = {
|
|
20
|
+
send(msg) {
|
|
21
|
+
// A sends → B receives
|
|
22
|
+
emitterB.emit("message", msg);
|
|
23
|
+
},
|
|
24
|
+
onMessage(handler) {
|
|
25
|
+
emitterA.on("message", handler);
|
|
26
|
+
},
|
|
27
|
+
close() {
|
|
28
|
+
emitterA.removeAllListeners();
|
|
29
|
+
emitterB.removeAllListeners();
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
const sideB = {
|
|
33
|
+
send(msg) {
|
|
34
|
+
// B sends → A receives
|
|
35
|
+
emitterA.emit("message", msg);
|
|
36
|
+
},
|
|
37
|
+
onMessage(handler) {
|
|
38
|
+
emitterB.on("message", handler);
|
|
39
|
+
},
|
|
40
|
+
close() {
|
|
41
|
+
emitterA.removeAllListeners();
|
|
42
|
+
emitterB.removeAllListeners();
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
return [sideA, sideB];
|
|
46
|
+
}
|
|
47
|
+
// ─── Stdio Transport ────────────────────────────────────────────────
|
|
48
|
+
/**
|
|
49
|
+
* Transport over stdio streams (newline-delimited JSON).
|
|
50
|
+
* Used for cross-process communication.
|
|
51
|
+
*/
|
|
52
|
+
export class StdioTransport {
|
|
53
|
+
input;
|
|
54
|
+
output;
|
|
55
|
+
rl;
|
|
56
|
+
handlers = [];
|
|
57
|
+
constructor(input, output) {
|
|
58
|
+
this.input = input;
|
|
59
|
+
this.output = output;
|
|
60
|
+
this.rl = createInterface({ input: this.input });
|
|
61
|
+
this.rl.on("line", (line) => {
|
|
62
|
+
if (!line.trim())
|
|
63
|
+
return;
|
|
64
|
+
try {
|
|
65
|
+
const msg = JSON.parse(line);
|
|
66
|
+
for (const handler of this.handlers) {
|
|
67
|
+
handler(msg);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Skip malformed lines
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
send(message) {
|
|
76
|
+
this.output.write(JSON.stringify(message) + "\n");
|
|
77
|
+
}
|
|
78
|
+
onMessage(handler) {
|
|
79
|
+
this.handlers.push(handler);
|
|
80
|
+
}
|
|
81
|
+
close() {
|
|
82
|
+
this.rl.close();
|
|
83
|
+
this.handlers = [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent protocol — JSON-RPC-style messages for client-server communication.
|
|
3
|
+
*
|
|
4
|
+
* The protocol separates the agent engine (server) from the UI (client).
|
|
5
|
+
* Communication is bidirectional:
|
|
6
|
+
* Client → Server: requests (run, approve, cancel, configure, query)
|
|
7
|
+
* Server → Client: notifications (stream events, approval requests)
|
|
8
|
+
* Server → Client: responses (results of requests)
|
|
9
|
+
*/
|
|
10
|
+
import type { StreamEvent, TokenUsage, TerminalReason, ApprovalRequest, ApprovalResult, PermissionMode } from "../types.js";
|
|
11
|
+
export interface RpcRequest {
|
|
12
|
+
jsonrpc: "2.0";
|
|
13
|
+
id: string | number;
|
|
14
|
+
method: string;
|
|
15
|
+
params?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface RpcResponse {
|
|
18
|
+
jsonrpc: "2.0";
|
|
19
|
+
id: string | number;
|
|
20
|
+
result?: unknown;
|
|
21
|
+
error?: RpcError;
|
|
22
|
+
}
|
|
23
|
+
export interface RpcNotification {
|
|
24
|
+
jsonrpc: "2.0";
|
|
25
|
+
method: string;
|
|
26
|
+
params?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
export interface RpcError {
|
|
29
|
+
code: number;
|
|
30
|
+
message: string;
|
|
31
|
+
data?: unknown;
|
|
32
|
+
}
|
|
33
|
+
export type RpcMessage = RpcRequest | RpcResponse | RpcNotification;
|
|
34
|
+
export declare const ErrorCodes: {
|
|
35
|
+
readonly ParseError: -32700;
|
|
36
|
+
readonly InvalidRequest: -32600;
|
|
37
|
+
readonly MethodNotFound: -32601;
|
|
38
|
+
readonly InvalidParams: -32602;
|
|
39
|
+
readonly InternalError: -32603;
|
|
40
|
+
readonly Overloaded: -32001;
|
|
41
|
+
readonly SessionNotFound: -32002;
|
|
42
|
+
readonly SessionClosed: -32004;
|
|
43
|
+
};
|
|
44
|
+
/** Start an agent run with a user task. */
|
|
45
|
+
export interface RunParams {
|
|
46
|
+
sessionId: string;
|
|
47
|
+
task: string;
|
|
48
|
+
/**
|
|
49
|
+
* Working directory for this run. When omitted, the Engine uses its
|
|
50
|
+
* configured cwd.
|
|
51
|
+
*/
|
|
52
|
+
cwd?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Per-run permission mode supplied by desktop/composer UIs.
|
|
55
|
+
* When omitted, the engine keeps its configured default.
|
|
56
|
+
*/
|
|
57
|
+
permissionMode?: PermissionMode;
|
|
58
|
+
/**
|
|
59
|
+
* Per-run plan-mode flag. When true, the Engine enters plan mode for
|
|
60
|
+
* this run; when omitted, the engine keeps its configured default.
|
|
61
|
+
*/
|
|
62
|
+
planMode?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface RunResult {
|
|
65
|
+
text: string;
|
|
66
|
+
reason: TerminalReason;
|
|
67
|
+
sessionId: string;
|
|
68
|
+
turnCount: number;
|
|
69
|
+
usage: TokenUsage;
|
|
70
|
+
}
|
|
71
|
+
/** Respond to an approval request from the server. */
|
|
72
|
+
export interface ApproveParams {
|
|
73
|
+
sessionId: string;
|
|
74
|
+
requestId: string;
|
|
75
|
+
decision: ApprovalResult;
|
|
76
|
+
}
|
|
77
|
+
/** Cancel a running agent turn. */
|
|
78
|
+
export interface CancelParams {
|
|
79
|
+
sessionId: string;
|
|
80
|
+
reason?: string;
|
|
81
|
+
}
|
|
82
|
+
/** Close (destroy) a session. */
|
|
83
|
+
export interface CloseSessionParams {
|
|
84
|
+
sessionId: string;
|
|
85
|
+
}
|
|
86
|
+
/** Inject context into a session transcript. */
|
|
87
|
+
export interface InjectParams {
|
|
88
|
+
sessionId: string;
|
|
89
|
+
content: string;
|
|
90
|
+
}
|
|
91
|
+
/** Update runtime configuration. */
|
|
92
|
+
export interface ConfigureParams {
|
|
93
|
+
/** When present, configure that specific chat session. Otherwise worker-global. */
|
|
94
|
+
sessionId?: string;
|
|
95
|
+
permissionMode?: PermissionMode;
|
|
96
|
+
planMode?: boolean;
|
|
97
|
+
bypassPermissions?: boolean;
|
|
98
|
+
effort?: string;
|
|
99
|
+
/** Switch active model by pool key (e.g. "sonnet", "haiku", "gpt"). */
|
|
100
|
+
model?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Re-read settings (providers[]/models[]) into the engine's ModelPool before
|
|
103
|
+
* any model switch. Set after onboarding/login persists new entries so the
|
|
104
|
+
* running engine picks them up without a process restart.
|
|
105
|
+
*/
|
|
106
|
+
reloadModels?: boolean;
|
|
107
|
+
}
|
|
108
|
+
/** Query server state. */
|
|
109
|
+
export interface QueryParams {
|
|
110
|
+
type: "sessions" | "tools" | "config" | "session_detail" | "compact" | "config_set" | "config_get" | "permission_set" | "models" | "providers" | "arena_status" | "provider_add" | "provider_refresh" | "provider_delete" | "model_add" | "model_delete";
|
|
111
|
+
sessionId?: string;
|
|
112
|
+
/** Used by config_set / permission_set: dotted key path or mode field */
|
|
113
|
+
key?: string;
|
|
114
|
+
/** Used by config_set / permission_set: new value */
|
|
115
|
+
value?: unknown;
|
|
116
|
+
/** Used by provider_add: full ProviderConfig payload */
|
|
117
|
+
provider?: unknown;
|
|
118
|
+
/** Used by model_add: the new model entry */
|
|
119
|
+
model?: unknown;
|
|
120
|
+
}
|
|
121
|
+
export interface QueryResult {
|
|
122
|
+
type: string;
|
|
123
|
+
data: unknown;
|
|
124
|
+
}
|
|
125
|
+
/** List / get session info. */
|
|
126
|
+
export interface SessionListResult {
|
|
127
|
+
sessions: Array<{
|
|
128
|
+
sessionId: string;
|
|
129
|
+
cwd: string;
|
|
130
|
+
startedAt: number;
|
|
131
|
+
model: string;
|
|
132
|
+
status: string;
|
|
133
|
+
turnCount: number;
|
|
134
|
+
}>;
|
|
135
|
+
}
|
|
136
|
+
export interface ToolListResult {
|
|
137
|
+
tools: Array<{
|
|
138
|
+
name: string;
|
|
139
|
+
description: string;
|
|
140
|
+
}>;
|
|
141
|
+
}
|
|
142
|
+
/** Shape of a model-pool entry returned by query("models"). */
|
|
143
|
+
export interface ProtocolModelEntry {
|
|
144
|
+
key: string;
|
|
145
|
+
label: string;
|
|
146
|
+
model: string;
|
|
147
|
+
/**
|
|
148
|
+
* Protocol the LLM client speaks ("openai" or "anthropic"). DeepSeek,
|
|
149
|
+
* Mistral, etc. all use "openai" since they're OpenAI-compatible.
|
|
150
|
+
* NOT the brand/vendor — that's providerKey below.
|
|
151
|
+
*/
|
|
152
|
+
protocol: string;
|
|
153
|
+
/**
|
|
154
|
+
* Pool entry's reference into settings.providers[]. Used by ModelManager
|
|
155
|
+
* to derive each provider's modelCount client-side ("how many models
|
|
156
|
+
* point at me"). Optional because auto-populated entries (autoPopulatePool)
|
|
157
|
+
* don't go through the wizard and have no providers[] row.
|
|
158
|
+
*/
|
|
159
|
+
providerKey?: string;
|
|
160
|
+
active: boolean;
|
|
161
|
+
/** Max output tokens (0 or undefined = unknown). */
|
|
162
|
+
maxOutputTokens?: number;
|
|
163
|
+
/** Max context window size (0 or undefined = unknown). */
|
|
164
|
+
maxContextTokens?: number;
|
|
165
|
+
}
|
|
166
|
+
export interface ProtocolProviderEntry {
|
|
167
|
+
key: string;
|
|
168
|
+
label: string;
|
|
169
|
+
kind: string;
|
|
170
|
+
modelCount: number;
|
|
171
|
+
cachedModels?: number;
|
|
172
|
+
cachedAt?: string;
|
|
173
|
+
}
|
|
174
|
+
export interface ConfigResult {
|
|
175
|
+
permissionMode: PermissionMode;
|
|
176
|
+
planMode: boolean;
|
|
177
|
+
preset?: string;
|
|
178
|
+
model: string;
|
|
179
|
+
cwd: string;
|
|
180
|
+
maxContextTokens?: number;
|
|
181
|
+
}
|
|
182
|
+
/** Stream event forwarded from the engine (legacy, no sessionId). */
|
|
183
|
+
export interface StreamEventNotification {
|
|
184
|
+
event: StreamEvent;
|
|
185
|
+
}
|
|
186
|
+
/** Multi-session stream event envelope — carries the originating sessionId. */
|
|
187
|
+
export interface AgentStreamEventNotification {
|
|
188
|
+
sessionId: string;
|
|
189
|
+
event: StreamEvent;
|
|
190
|
+
}
|
|
191
|
+
/** Server requests approval from the client (UI). */
|
|
192
|
+
export interface ApprovalRequestNotification {
|
|
193
|
+
requestId: string;
|
|
194
|
+
request: ApprovalRequest;
|
|
195
|
+
}
|
|
196
|
+
/** Server status changed. */
|
|
197
|
+
export interface StatusNotification {
|
|
198
|
+
status: "ready" | "running" | "error" | "shutdown";
|
|
199
|
+
message?: string;
|
|
200
|
+
}
|
|
201
|
+
export declare const Methods: {
|
|
202
|
+
readonly Run: "agent/run";
|
|
203
|
+
readonly Approve: "agent/approve";
|
|
204
|
+
readonly Cancel: "agent/cancel";
|
|
205
|
+
readonly Configure: "agent/configure";
|
|
206
|
+
readonly Query: "agent/query";
|
|
207
|
+
/** Inject context into transcript without triggering LLM. */
|
|
208
|
+
readonly Inject: "agent/inject";
|
|
209
|
+
/** Close (destroy) a session. */
|
|
210
|
+
readonly CloseSession: "agent/closeSession";
|
|
211
|
+
readonly StreamEvent: "agent/streamEvent";
|
|
212
|
+
readonly ApprovalRequest: "agent/approvalRequest";
|
|
213
|
+
readonly Status: "agent/status";
|
|
214
|
+
};
|
|
215
|
+
export declare function createRequest(method: string, params?: Record<string, unknown>): RpcRequest;
|
|
216
|
+
export declare function createResponse(id: string | number, result: unknown): RpcResponse;
|
|
217
|
+
export declare function createErrorResponse(id: string | number, code: number, message: string, data?: unknown): RpcResponse;
|
|
218
|
+
export declare function createNotification(method: string, params?: Record<string, unknown>): RpcNotification;
|
|
219
|
+
export declare function isRequest(msg: RpcMessage): msg is RpcRequest;
|
|
220
|
+
export declare function isResponse(msg: RpcMessage): msg is RpcResponse;
|
|
221
|
+
export declare function isNotification(msg: RpcMessage): msg is RpcNotification;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent protocol — JSON-RPC-style messages for client-server communication.
|
|
3
|
+
*
|
|
4
|
+
* The protocol separates the agent engine (server) from the UI (client).
|
|
5
|
+
* Communication is bidirectional:
|
|
6
|
+
* Client → Server: requests (run, approve, cancel, configure, query)
|
|
7
|
+
* Server → Client: notifications (stream events, approval requests)
|
|
8
|
+
* Server → Client: responses (results of requests)
|
|
9
|
+
*/
|
|
10
|
+
// ─── Error Codes ────────────────────────────────────────────────────
|
|
11
|
+
export const ErrorCodes = {
|
|
12
|
+
ParseError: -32700,
|
|
13
|
+
InvalidRequest: -32600,
|
|
14
|
+
MethodNotFound: -32601,
|
|
15
|
+
InvalidParams: -32602,
|
|
16
|
+
InternalError: -32603,
|
|
17
|
+
// Custom codes
|
|
18
|
+
Overloaded: -32001,
|
|
19
|
+
SessionNotFound: -32002,
|
|
20
|
+
SessionClosed: -32004,
|
|
21
|
+
};
|
|
22
|
+
// ─── Method Names ───────────────────────────────────────────────────
|
|
23
|
+
export const Methods = {
|
|
24
|
+
// Client → Server
|
|
25
|
+
Run: "agent/run",
|
|
26
|
+
Approve: "agent/approve",
|
|
27
|
+
Cancel: "agent/cancel",
|
|
28
|
+
Configure: "agent/configure",
|
|
29
|
+
Query: "agent/query",
|
|
30
|
+
/** Inject context into transcript without triggering LLM. */
|
|
31
|
+
Inject: "agent/inject",
|
|
32
|
+
/** Close (destroy) a session. */
|
|
33
|
+
CloseSession: "agent/closeSession",
|
|
34
|
+
// Server → Client (notifications, no id)
|
|
35
|
+
StreamEvent: "agent/streamEvent",
|
|
36
|
+
ApprovalRequest: "agent/approvalRequest",
|
|
37
|
+
Status: "agent/status",
|
|
38
|
+
};
|
|
39
|
+
// ─── Helpers ────────────────────────────────────────────────────────
|
|
40
|
+
let _nextId = 1;
|
|
41
|
+
export function createRequest(method, params) {
|
|
42
|
+
return { jsonrpc: "2.0", id: _nextId++, method, params };
|
|
43
|
+
}
|
|
44
|
+
export function createResponse(id, result) {
|
|
45
|
+
return { jsonrpc: "2.0", id, result };
|
|
46
|
+
}
|
|
47
|
+
export function createErrorResponse(id, code, message, data) {
|
|
48
|
+
return { jsonrpc: "2.0", id, error: { code, message, data } };
|
|
49
|
+
}
|
|
50
|
+
export function createNotification(method, params) {
|
|
51
|
+
return { jsonrpc: "2.0", method, params };
|
|
52
|
+
}
|
|
53
|
+
export function isRequest(msg) {
|
|
54
|
+
return "method" in msg && "id" in msg;
|
|
55
|
+
}
|
|
56
|
+
export function isResponse(msg) {
|
|
57
|
+
return "id" in msg && !("method" in msg);
|
|
58
|
+
}
|
|
59
|
+
export function isNotification(msg) {
|
|
60
|
+
return "method" in msg && !("id" in msg);
|
|
61
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote bridge — NDJSON over SSH for remote code-shell sessions.
|
|
3
|
+
*
|
|
4
|
+
* Architecture:
|
|
5
|
+
* Local terminal ←→ SSH ←→ Remote code-shell (NDJSON stdio mode)
|
|
6
|
+
*/
|
|
7
|
+
export interface BridgeConfig {
|
|
8
|
+
host: string;
|
|
9
|
+
user?: string;
|
|
10
|
+
port?: number;
|
|
11
|
+
identityFile?: string;
|
|
12
|
+
remoteCommand?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class RemoteBridge {
|
|
15
|
+
private readonly config;
|
|
16
|
+
private ssh;
|
|
17
|
+
private connected;
|
|
18
|
+
constructor(config: BridgeConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Connect to the remote host via SSH and start code-shell in NDJSON mode.
|
|
21
|
+
*/
|
|
22
|
+
connect(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Send a message to the remote code-shell.
|
|
25
|
+
*/
|
|
26
|
+
send(message: Record<string, unknown>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Async iterator for messages from the remote code-shell.
|
|
29
|
+
*/
|
|
30
|
+
messages(): AsyncGenerator<Record<string, unknown>>;
|
|
31
|
+
/**
|
|
32
|
+
* Disconnect from the remote host.
|
|
33
|
+
*/
|
|
34
|
+
disconnect(): void;
|
|
35
|
+
get isConnected(): boolean;
|
|
36
|
+
private buildSSHArgs;
|
|
37
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote bridge — NDJSON over SSH for remote code-shell sessions.
|
|
3
|
+
*
|
|
4
|
+
* Architecture:
|
|
5
|
+
* Local terminal ←→ SSH ←→ Remote code-shell (NDJSON stdio mode)
|
|
6
|
+
*/
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
import { createInterface } from "node:readline";
|
|
9
|
+
export class RemoteBridge {
|
|
10
|
+
config;
|
|
11
|
+
ssh;
|
|
12
|
+
connected = false;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Connect to the remote host via SSH and start code-shell in NDJSON mode.
|
|
18
|
+
*/
|
|
19
|
+
async connect() {
|
|
20
|
+
const sshArgs = this.buildSSHArgs();
|
|
21
|
+
const remoteCmd = this.config.remoteCommand ?? "code-shell run --output stream-json";
|
|
22
|
+
this.ssh = spawn("ssh", [...sshArgs, remoteCmd], {
|
|
23
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
24
|
+
});
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const timer = setTimeout(() => {
|
|
27
|
+
reject(new Error("SSH connection timed out"));
|
|
28
|
+
this.disconnect();
|
|
29
|
+
}, 30000);
|
|
30
|
+
this.ssh.stdout?.once("data", () => {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
this.connected = true;
|
|
33
|
+
resolve();
|
|
34
|
+
});
|
|
35
|
+
this.ssh.on("error", (err) => {
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
reject(err);
|
|
38
|
+
});
|
|
39
|
+
this.ssh.on("exit", (code) => {
|
|
40
|
+
this.connected = false;
|
|
41
|
+
if (!this.connected) {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
reject(new Error(`SSH exited with code ${code}`));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Send a message to the remote code-shell.
|
|
50
|
+
*/
|
|
51
|
+
send(message) {
|
|
52
|
+
if (!this.connected || !this.ssh?.stdin) {
|
|
53
|
+
throw new Error("Not connected");
|
|
54
|
+
}
|
|
55
|
+
this.ssh.stdin.write(JSON.stringify(message) + "\n");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Async iterator for messages from the remote code-shell.
|
|
59
|
+
*/
|
|
60
|
+
async *messages() {
|
|
61
|
+
if (!this.ssh?.stdout)
|
|
62
|
+
return;
|
|
63
|
+
const rl = createInterface({ input: this.ssh.stdout, crlfDelay: Infinity });
|
|
64
|
+
for await (const line of rl) {
|
|
65
|
+
const trimmed = line.trim();
|
|
66
|
+
if (!trimmed)
|
|
67
|
+
continue;
|
|
68
|
+
try {
|
|
69
|
+
yield JSON.parse(trimmed);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Skip malformed
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Disconnect from the remote host.
|
|
78
|
+
*/
|
|
79
|
+
disconnect() {
|
|
80
|
+
this.connected = false;
|
|
81
|
+
if (this.ssh) {
|
|
82
|
+
this.ssh.kill();
|
|
83
|
+
this.ssh = undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
get isConnected() {
|
|
87
|
+
return this.connected;
|
|
88
|
+
}
|
|
89
|
+
buildSSHArgs() {
|
|
90
|
+
const args = ["-T"]; // No pseudo-terminal
|
|
91
|
+
if (this.config.port)
|
|
92
|
+
args.push("-p", String(this.config.port));
|
|
93
|
+
if (this.config.identityFile)
|
|
94
|
+
args.push("-i", this.config.identityFile);
|
|
95
|
+
if (this.config.user) {
|
|
96
|
+
args.push(`${this.config.user}@${this.config.host}`);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
args.push(this.config.host);
|
|
100
|
+
}
|
|
101
|
+
return args;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArtifactTracker — records meaningful artifact refs during run execution.
|
|
3
|
+
*
|
|
4
|
+
* Listens to StreamEvents and identifies:
|
|
5
|
+
* - Files written or edited (Write / Edit tool results)
|
|
6
|
+
* - Files created by Bash commands (mkdir, touch, cp, git commit, etc.)
|
|
7
|
+
* - Structured outputs (e.g., generated configs, test results)
|
|
8
|
+
*
|
|
9
|
+
* Design constraint (§14):
|
|
10
|
+
* - Only record artifacts valuable for recovery, display, evaluation, or audit
|
|
11
|
+
* - Do NOT record every Read or every tool output
|
|
12
|
+
* - Judgment: file writes are artifacts, reads are not
|
|
13
|
+
*/
|
|
14
|
+
import type { StreamEvent } from "../types.js";
|
|
15
|
+
import type { RunStore } from "./RunStore.js";
|
|
16
|
+
export interface ArtifactTrackerConfig {
|
|
17
|
+
runId: string;
|
|
18
|
+
store: RunStore;
|
|
19
|
+
}
|
|
20
|
+
export declare class ArtifactTracker {
|
|
21
|
+
private readonly config;
|
|
22
|
+
private readonly pendingCalls;
|
|
23
|
+
private readonly recordedPaths;
|
|
24
|
+
constructor(config: ArtifactTrackerConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Feed a StreamEvent to the tracker.
|
|
27
|
+
*/
|
|
28
|
+
onStreamEvent(event: StreamEvent): Promise<void>;
|
|
29
|
+
/** Get all recorded artifact paths. */
|
|
30
|
+
getRecordedPaths(): string[];
|
|
31
|
+
private processToolResult;
|
|
32
|
+
private recordFileArtifact;
|
|
33
|
+
/**
|
|
34
|
+
* Extract artifact refs from Bash commands.
|
|
35
|
+
* Only track commands that clearly produce files.
|
|
36
|
+
*/
|
|
37
|
+
private extractBashArtifacts;
|
|
38
|
+
}
|