@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,197 @@
|
|
|
1
|
+
import { logger } from "../../logging/logger.js";
|
|
2
|
+
// Stable empty reference so `getSnapshot(sid)` returns the same array
|
|
3
|
+
// identity across calls when the bucket is empty. React's
|
|
4
|
+
// useSyncExternalStore compares snapshots by identity to decide whether
|
|
5
|
+
// to re-render — a fresh `[]` each call would cause render loops.
|
|
6
|
+
const EMPTY = Object.freeze([]);
|
|
7
|
+
/**
|
|
8
|
+
* Runtime guard for sessionId. The static type is already `string` on
|
|
9
|
+
* the public surface, but a caller bypassing the type system via
|
|
10
|
+
* `as any` (or a stale JS-only consumer) could still smuggle in
|
|
11
|
+
* undefined / "". We refuse those, log once, and let the agent path
|
|
12
|
+
* continue — a buggy plugin shouldn't crash the engine.
|
|
13
|
+
*/
|
|
14
|
+
function isValidSessionId(sid) {
|
|
15
|
+
return typeof sid === "string" && sid.length > 0;
|
|
16
|
+
}
|
|
17
|
+
class NotificationQueue {
|
|
18
|
+
buckets = new Map();
|
|
19
|
+
listeners = new Set();
|
|
20
|
+
enqueue(item, sessionId) {
|
|
21
|
+
if (!isValidSessionId(sessionId)) {
|
|
22
|
+
logger.warn("notification_queue.invalid_session_id", {
|
|
23
|
+
agentId: item.agentId,
|
|
24
|
+
status: item.status,
|
|
25
|
+
sessionIdType: typeof sessionId,
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const next = [...(this.buckets.get(sessionId) ?? []), item];
|
|
30
|
+
this.buckets.set(sessionId, next);
|
|
31
|
+
this.notify();
|
|
32
|
+
// B2.2 — also publish to the protocol-facing bus. The bus is a
|
|
33
|
+
// separate listener set so existing TUI subscribers (which poll the
|
|
34
|
+
// queue via getSnapshot/drainAll) are unaffected. The server
|
|
35
|
+
// subscribes on construction and forwards each event to its client
|
|
36
|
+
// via the existing `agent/streamEvent` notification path.
|
|
37
|
+
agentNotificationBus.publish(sessionId, notificationItemToStreamEvent(item));
|
|
38
|
+
}
|
|
39
|
+
subscribe = (cb) => {
|
|
40
|
+
this.listeners.add(cb);
|
|
41
|
+
return () => {
|
|
42
|
+
this.listeners.delete(cb);
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
getSnapshot = (sessionId) => {
|
|
46
|
+
if (!isValidSessionId(sessionId))
|
|
47
|
+
return EMPTY;
|
|
48
|
+
return this.buckets.get(sessionId) ?? EMPTY;
|
|
49
|
+
};
|
|
50
|
+
/** Atomic: returns all items for a session and clears that bucket. */
|
|
51
|
+
drainAll(sessionId) {
|
|
52
|
+
if (!isValidSessionId(sessionId))
|
|
53
|
+
return [];
|
|
54
|
+
const items = this.buckets.get(sessionId);
|
|
55
|
+
if (!items || items.length === 0)
|
|
56
|
+
return [];
|
|
57
|
+
this.buckets.delete(sessionId);
|
|
58
|
+
this.notify();
|
|
59
|
+
return items;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Clear one bucket (sessionId given) or every bucket (no arg). Used by
|
|
63
|
+
* tests; production code drains per-session through `drainAll`.
|
|
64
|
+
*/
|
|
65
|
+
reset(sessionId) {
|
|
66
|
+
if (sessionId === undefined) {
|
|
67
|
+
if (this.buckets.size === 0)
|
|
68
|
+
return;
|
|
69
|
+
this.buckets.clear();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (!this.buckets.has(sessionId))
|
|
73
|
+
return;
|
|
74
|
+
this.buckets.delete(sessionId);
|
|
75
|
+
}
|
|
76
|
+
this.notify();
|
|
77
|
+
}
|
|
78
|
+
notify() {
|
|
79
|
+
for (const cb of this.listeners) {
|
|
80
|
+
try {
|
|
81
|
+
cb();
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// isolate per-listener errors
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export const notificationQueue = new NotificationQueue();
|
|
90
|
+
class AgentNotificationBus {
|
|
91
|
+
handlers = new Set();
|
|
92
|
+
publish(sessionId, event) {
|
|
93
|
+
if (!isValidSessionId(sessionId)) {
|
|
94
|
+
// Mirrors NotificationQueue.enqueue — refuse undefined / "" so the
|
|
95
|
+
// server-side subscriber never has to defend against it.
|
|
96
|
+
logger.warn("agent_notification_bus.invalid_session_id", {
|
|
97
|
+
agentId: event.agentId,
|
|
98
|
+
status: event.status,
|
|
99
|
+
sessionIdType: typeof sessionId,
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
for (const handler of this.handlers) {
|
|
104
|
+
try {
|
|
105
|
+
handler(sessionId, event);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// isolate per-listener errors
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
subscribe(handler) {
|
|
113
|
+
this.handlers.add(handler);
|
|
114
|
+
return () => {
|
|
115
|
+
this.handlers.delete(handler);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export const agentNotificationBus = new AgentNotificationBus();
|
|
120
|
+
/**
|
|
121
|
+
* Project a queue item to its protocol-event shape. The two types are
|
|
122
|
+
* field-compatible by design (see the comment on BackgroundAgentCompletedEvent
|
|
123
|
+
* in types.ts) so this is essentially an identity tag.
|
|
124
|
+
*/
|
|
125
|
+
export function notificationItemToStreamEvent(item) {
|
|
126
|
+
const event = {
|
|
127
|
+
type: "background_agent_completed",
|
|
128
|
+
agentId: item.agentId,
|
|
129
|
+
description: item.description,
|
|
130
|
+
status: item.status,
|
|
131
|
+
enqueuedAt: item.enqueuedAt,
|
|
132
|
+
};
|
|
133
|
+
if (item.name !== undefined)
|
|
134
|
+
event.name = item.name;
|
|
135
|
+
if (item.finalText !== undefined)
|
|
136
|
+
event.finalText = item.finalText;
|
|
137
|
+
if (item.error !== undefined)
|
|
138
|
+
event.error = item.error;
|
|
139
|
+
return event;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Escape XML-special characters. We only emit a fixed handful of tags, so
|
|
143
|
+
* we can hand-roll this rather than pulling in a full encoder. Attribute
|
|
144
|
+
* values get the quote escape too; element bodies don't need it.
|
|
145
|
+
*/
|
|
146
|
+
function escapeXmlText(s) {
|
|
147
|
+
return s
|
|
148
|
+
.replace(/&/g, "&")
|
|
149
|
+
.replace(/</g, "<")
|
|
150
|
+
.replace(/>/g, ">");
|
|
151
|
+
}
|
|
152
|
+
function escapeXmlAttr(s) {
|
|
153
|
+
return escapeXmlText(s).replace(/"/g, """);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Render a batch of completion notifications as the XML user-message
|
|
157
|
+
* body that the main agent's LLM will see. Format is stable — main
|
|
158
|
+
* agent prompts can rely on the `<background-agents-completed>` root
|
|
159
|
+
* tag as a signal that this turn is a system-injected notification,
|
|
160
|
+
* not a real user message.
|
|
161
|
+
*/
|
|
162
|
+
export function buildNotificationMessage(items) {
|
|
163
|
+
const agents = items
|
|
164
|
+
.map((item) => {
|
|
165
|
+
const nameAttr = item.name ? ` name="${escapeXmlAttr(item.name)}"` : "";
|
|
166
|
+
const opening = ` <agent id="${escapeXmlAttr(item.agentId)}"${nameAttr} status="${item.status}">`;
|
|
167
|
+
const desc = ` <description>${escapeXmlText(item.description)}</description>`;
|
|
168
|
+
const body = item.status === "completed"
|
|
169
|
+
? ` <result>\n${escapeXmlText(item.finalText ?? "")}\n </result>`
|
|
170
|
+
: ` <error>${escapeXmlText(item.error ?? "")}</error>`;
|
|
171
|
+
return [opening, desc, body, " </agent>"].join("\n");
|
|
172
|
+
})
|
|
173
|
+
.join("\n");
|
|
174
|
+
return [
|
|
175
|
+
"<background-agents-completed>",
|
|
176
|
+
agents,
|
|
177
|
+
"</background-agents-completed>",
|
|
178
|
+
"",
|
|
179
|
+
"Above are results from background agents that finished while you were idle. Address them appropriately — summarize for the user, continue work, or ignore if no longer relevant.",
|
|
180
|
+
].join("\n");
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* One-line-per-agent human summary for the chat feed. The full result
|
|
184
|
+
* body goes to the LLM via buildNotificationMessage; the user sees only
|
|
185
|
+
* this terse marker plus an optional inline error preview, and can
|
|
186
|
+
* switch to the sub-agent's dock view if they want details.
|
|
187
|
+
*/
|
|
188
|
+
export function buildNotificationSummary(items) {
|
|
189
|
+
const header = "📨 background agents completed";
|
|
190
|
+
const rows = items.map((item) => {
|
|
191
|
+
const badge = item.status === "completed" ? "✓" : "✗";
|
|
192
|
+
const namePart = item.name ? `${item.name} · ` : "";
|
|
193
|
+
const statusPart = item.status === "failed" ? ` · failed: ${item.error ?? "unknown"}` : "";
|
|
194
|
+
return ` └─ ${namePart}${item.description} · ${badge}${statusPart}`;
|
|
195
|
+
});
|
|
196
|
+
return [header, ...rows].join("\n");
|
|
197
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process async agent registry.
|
|
3
|
+
*
|
|
4
|
+
* When an Agent tool call uses run_in_background: true, the sub-agent
|
|
5
|
+
* runs detached from the current turn. We need somewhere to track
|
|
6
|
+
* agentId → status / result / cancel handle so the parent agent can
|
|
7
|
+
* later check on it (AgentStatus) or cancel it (AgentCancel).
|
|
8
|
+
*
|
|
9
|
+
* Lifetime: process-local. Crashing the process loses these — that's
|
|
10
|
+
* the same contract Claude Code's Agent.run_in_background gives, and
|
|
11
|
+
* the right boundary: long-running cross-process work belongs to
|
|
12
|
+
* RunManager, not here.
|
|
13
|
+
*/
|
|
14
|
+
export type AsyncAgentStatus = "running" | "completed" | "failed" | "cancelled";
|
|
15
|
+
/**
|
|
16
|
+
* Minimal structural shape for an entry in an agent's transcript. We avoid
|
|
17
|
+
* importing the UI's `ChatEntry` here to prevent a tool-system → ui import
|
|
18
|
+
* direction. Consumers (the UI dock) widen this type via `as ChatEntry[]`
|
|
19
|
+
* at their boundary.
|
|
20
|
+
*/
|
|
21
|
+
export interface AgentTranscriptEntry {
|
|
22
|
+
id: string;
|
|
23
|
+
type: string;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface AsyncAgentEntry {
|
|
27
|
+
agentId: string;
|
|
28
|
+
/** Short kind label shown in the dock (e.g. "Explore", "Plan"). */
|
|
29
|
+
name?: string;
|
|
30
|
+
description: string;
|
|
31
|
+
status: AsyncAgentStatus;
|
|
32
|
+
startedAt: number;
|
|
33
|
+
finishedAt?: number;
|
|
34
|
+
/** finishedAt + 30_000. Dock filters rows past this. */
|
|
35
|
+
finishedFadeAt?: number;
|
|
36
|
+
abort: () => void;
|
|
37
|
+
/** Stream events recorded by run_in_background agents for UI view-switching. */
|
|
38
|
+
transcript?: AgentTranscriptEntry[];
|
|
39
|
+
}
|
|
40
|
+
declare class AsyncAgentRegistry {
|
|
41
|
+
private agents;
|
|
42
|
+
private listeners;
|
|
43
|
+
private snapshot;
|
|
44
|
+
subscribe: (cb: () => void) => (() => void);
|
|
45
|
+
getSnapshot: () => AsyncAgentEntry[];
|
|
46
|
+
hasRunning: () => boolean;
|
|
47
|
+
private notify;
|
|
48
|
+
register(entry: AsyncAgentEntry): void;
|
|
49
|
+
appendToTranscript(agentId: string, entry: AgentTranscriptEntry): void;
|
|
50
|
+
/**
|
|
51
|
+
* Re-emit the registry change signal after callers mutate an agent's
|
|
52
|
+
* transcript array in place (patching or filtering entries). Required
|
|
53
|
+
* because `notify` rebuilds the snapshot and tells React subscribers to
|
|
54
|
+
* re-read.
|
|
55
|
+
*/
|
|
56
|
+
touchTranscript(agentId: string): void;
|
|
57
|
+
get(agentId: string): AsyncAgentEntry | undefined;
|
|
58
|
+
list(): AsyncAgentEntry[];
|
|
59
|
+
private markFinished;
|
|
60
|
+
markCompleted(agentId: string): void;
|
|
61
|
+
markFailed(agentId: string): void;
|
|
62
|
+
markCancelled(agentId: string): void;
|
|
63
|
+
cancel(agentId: string): boolean;
|
|
64
|
+
reset(): void;
|
|
65
|
+
}
|
|
66
|
+
export declare const asyncAgentRegistry: AsyncAgentRegistry;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process async agent registry.
|
|
3
|
+
*
|
|
4
|
+
* When an Agent tool call uses run_in_background: true, the sub-agent
|
|
5
|
+
* runs detached from the current turn. We need somewhere to track
|
|
6
|
+
* agentId → status / result / cancel handle so the parent agent can
|
|
7
|
+
* later check on it (AgentStatus) or cancel it (AgentCancel).
|
|
8
|
+
*
|
|
9
|
+
* Lifetime: process-local. Crashing the process loses these — that's
|
|
10
|
+
* the same contract Claude Code's Agent.run_in_background gives, and
|
|
11
|
+
* the right boundary: long-running cross-process work belongs to
|
|
12
|
+
* RunManager, not here.
|
|
13
|
+
*/
|
|
14
|
+
class AsyncAgentRegistry {
|
|
15
|
+
agents = new Map();
|
|
16
|
+
listeners = new Set();
|
|
17
|
+
snapshot = [];
|
|
18
|
+
// ── observer API (React useSyncExternalStore compatible) ──────────────
|
|
19
|
+
subscribe = (cb) => {
|
|
20
|
+
this.listeners.add(cb);
|
|
21
|
+
return () => {
|
|
22
|
+
this.listeners.delete(cb);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
getSnapshot = () => {
|
|
26
|
+
return this.snapshot;
|
|
27
|
+
};
|
|
28
|
+
hasRunning = () => {
|
|
29
|
+
return this.snapshot.some((e) => e.status === "running");
|
|
30
|
+
};
|
|
31
|
+
notify() {
|
|
32
|
+
this.snapshot = [...this.agents.values()];
|
|
33
|
+
for (const cb of this.listeners) {
|
|
34
|
+
try {
|
|
35
|
+
cb();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// isolate per-listener errors
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// ── mutators ──────────────────────────────────────────────────────────
|
|
43
|
+
register(entry) {
|
|
44
|
+
this.agents.set(entry.agentId, entry);
|
|
45
|
+
this.notify();
|
|
46
|
+
}
|
|
47
|
+
appendToTranscript(agentId, entry) {
|
|
48
|
+
const e = this.agents.get(agentId);
|
|
49
|
+
if (!e)
|
|
50
|
+
return;
|
|
51
|
+
if (!e.transcript)
|
|
52
|
+
e.transcript = [];
|
|
53
|
+
e.transcript.push(entry);
|
|
54
|
+
this.notify();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Re-emit the registry change signal after callers mutate an agent's
|
|
58
|
+
* transcript array in place (patching or filtering entries). Required
|
|
59
|
+
* because `notify` rebuilds the snapshot and tells React subscribers to
|
|
60
|
+
* re-read.
|
|
61
|
+
*/
|
|
62
|
+
touchTranscript(agentId) {
|
|
63
|
+
if (!this.agents.has(agentId))
|
|
64
|
+
return;
|
|
65
|
+
this.notify();
|
|
66
|
+
}
|
|
67
|
+
get(agentId) {
|
|
68
|
+
return this.agents.get(agentId);
|
|
69
|
+
}
|
|
70
|
+
list() {
|
|
71
|
+
return [...this.agents.values()];
|
|
72
|
+
}
|
|
73
|
+
markFinished(agentId, status) {
|
|
74
|
+
const e = this.agents.get(agentId);
|
|
75
|
+
if (!e)
|
|
76
|
+
return;
|
|
77
|
+
if (e.status !== "running")
|
|
78
|
+
return;
|
|
79
|
+
e.status = status;
|
|
80
|
+
e.finishedAt = Date.now();
|
|
81
|
+
e.finishedFadeAt = e.finishedAt + 30_000;
|
|
82
|
+
this.notify();
|
|
83
|
+
}
|
|
84
|
+
markCompleted(agentId) {
|
|
85
|
+
this.markFinished(agentId, "completed");
|
|
86
|
+
}
|
|
87
|
+
markFailed(agentId) {
|
|
88
|
+
this.markFinished(agentId, "failed");
|
|
89
|
+
}
|
|
90
|
+
markCancelled(agentId) {
|
|
91
|
+
this.markFinished(agentId, "cancelled");
|
|
92
|
+
}
|
|
93
|
+
cancel(agentId) {
|
|
94
|
+
const e = this.agents.get(agentId);
|
|
95
|
+
if (!e)
|
|
96
|
+
return false;
|
|
97
|
+
if (e.status !== "running")
|
|
98
|
+
return false;
|
|
99
|
+
try {
|
|
100
|
+
e.abort();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// ignore abort errors — we still mark cancelled
|
|
104
|
+
}
|
|
105
|
+
e.status = "cancelled";
|
|
106
|
+
e.finishedAt = Date.now();
|
|
107
|
+
e.finishedFadeAt = e.finishedAt + 30_000;
|
|
108
|
+
this.notify();
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
reset() {
|
|
112
|
+
for (const e of this.agents.values()) {
|
|
113
|
+
if (e.status === "running") {
|
|
114
|
+
try {
|
|
115
|
+
e.abort();
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// ignore
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
this.agents.clear();
|
|
123
|
+
this.notify();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export const asyncAgentRegistry = new AsyncAgentRegistry();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translate child Engine StreamEvents into ChatEntry-shaped objects so the
|
|
3
|
+
* AgentDock detail view (which reuses App.renderEntry) can show a sub-agent's
|
|
4
|
+
* conversation in the same visual language as the main feed.
|
|
5
|
+
*
|
|
6
|
+
* The transcript is the canonical record for one background sub-agent. State
|
|
7
|
+
* (current thinking entry, currently-streaming assistant_text, in-flight
|
|
8
|
+
* tool_start map) lives in a per-agent translator. Each translator instance
|
|
9
|
+
* appends ChatEntry-shaped objects via `append` and mutates them via `update`,
|
|
10
|
+
* mirroring how App.tsx's handleStreamEvent talks to chatStore but isolated to
|
|
11
|
+
* a single agent's transcript.
|
|
12
|
+
*
|
|
13
|
+
* The output shapes intentionally match `src/ui/store.ts#ChatEntryData` so the
|
|
14
|
+
* existing renderEntry switch picks them up without code changes.
|
|
15
|
+
*/
|
|
16
|
+
import type { StreamEvent } from "../../types.js";
|
|
17
|
+
/**
|
|
18
|
+
* Create a transcript translator scoped to one background sub-agent. Returned
|
|
19
|
+
* function is a StreamCallback drop-in: feed it the child Engine's events and
|
|
20
|
+
* it maintains the agent's transcript in `asyncAgentRegistry`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTranscriptTranslator(agentId: string): (event: StreamEvent) => void;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { asyncAgentRegistry, } from "./agent-registry.js";
|
|
2
|
+
let entryIdCounter = 0;
|
|
3
|
+
function nextId(agentId) {
|
|
4
|
+
return `bg-${agentId}-${++entryIdCounter}`;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create a transcript translator scoped to one background sub-agent. Returned
|
|
8
|
+
* function is a StreamCallback drop-in: feed it the child Engine's events and
|
|
9
|
+
* it maintains the agent's transcript in `asyncAgentRegistry`.
|
|
10
|
+
*/
|
|
11
|
+
export function createTranscriptTranslator(agentId) {
|
|
12
|
+
// Local state for THIS agent. Background sub-agents run independently so
|
|
13
|
+
// each gets its own translator; no cross-agent state.
|
|
14
|
+
let streamingAssistantId;
|
|
15
|
+
let thinkingId;
|
|
16
|
+
// toolCallId → tool_start entry id. Lets tool_use_args_delta find the right
|
|
17
|
+
// tool_start to patch.
|
|
18
|
+
const toolStartByCallId = new Map();
|
|
19
|
+
function patchEntry(entryId, patch) {
|
|
20
|
+
const a = asyncAgentRegistry.get(agentId);
|
|
21
|
+
if (!a?.transcript)
|
|
22
|
+
return;
|
|
23
|
+
const idx = a.transcript.findIndex((e) => e.id === entryId);
|
|
24
|
+
if (idx < 0)
|
|
25
|
+
return;
|
|
26
|
+
a.transcript[idx] = patch(a.transcript[idx]);
|
|
27
|
+
asyncAgentRegistry.touchTranscript(agentId);
|
|
28
|
+
}
|
|
29
|
+
function dropEntry(entryId) {
|
|
30
|
+
const a = asyncAgentRegistry.get(agentId);
|
|
31
|
+
if (!a?.transcript)
|
|
32
|
+
return;
|
|
33
|
+
a.transcript = a.transcript.filter((e) => e.id !== entryId);
|
|
34
|
+
asyncAgentRegistry.touchTranscript(agentId);
|
|
35
|
+
}
|
|
36
|
+
function append(data) {
|
|
37
|
+
const id = nextId(agentId);
|
|
38
|
+
asyncAgentRegistry.appendToTranscript(agentId, {
|
|
39
|
+
...data,
|
|
40
|
+
id,
|
|
41
|
+
});
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
44
|
+
return (event) => {
|
|
45
|
+
switch (event.type) {
|
|
46
|
+
// ── thinking ─────────────────────────────────────────────────
|
|
47
|
+
case "stream_request_start": {
|
|
48
|
+
if (thinkingId) {
|
|
49
|
+
dropEntry(thinkingId);
|
|
50
|
+
thinkingId = undefined;
|
|
51
|
+
}
|
|
52
|
+
thinkingId = append({ type: "thinking", agentId });
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case "thinking_delta": {
|
|
56
|
+
// Sub-agent thinking content is collapsed in the dock view — we
|
|
57
|
+
// don't replicate the verb spinner. Keep the empty thinking
|
|
58
|
+
// placeholder; renderEntry shows it as a spinner row.
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
// ── assistant text (streaming) ───────────────────────────────
|
|
62
|
+
case "text_delta": {
|
|
63
|
+
if (thinkingId) {
|
|
64
|
+
dropEntry(thinkingId);
|
|
65
|
+
thinkingId = undefined;
|
|
66
|
+
}
|
|
67
|
+
if (streamingAssistantId) {
|
|
68
|
+
patchEntry(streamingAssistantId, (e) => ({
|
|
69
|
+
...e,
|
|
70
|
+
text: String(e.text ?? "") + event.text,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
streamingAssistantId = append({
|
|
75
|
+
type: "assistant_text",
|
|
76
|
+
text: event.text,
|
|
77
|
+
streaming: true,
|
|
78
|
+
agentId,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
// ── tool call ────────────────────────────────────────────────
|
|
84
|
+
case "tool_use_start": {
|
|
85
|
+
if (streamingAssistantId) {
|
|
86
|
+
patchEntry(streamingAssistantId, (e) => ({ ...e, streaming: false }));
|
|
87
|
+
streamingAssistantId = undefined;
|
|
88
|
+
}
|
|
89
|
+
if (thinkingId) {
|
|
90
|
+
dropEntry(thinkingId);
|
|
91
|
+
thinkingId = undefined;
|
|
92
|
+
}
|
|
93
|
+
const tc = event.toolCall;
|
|
94
|
+
const startId = append({
|
|
95
|
+
type: "tool_start",
|
|
96
|
+
toolName: tc.toolName,
|
|
97
|
+
args: tc.args,
|
|
98
|
+
toolCallId: tc.id,
|
|
99
|
+
agentId,
|
|
100
|
+
});
|
|
101
|
+
if (tc.id)
|
|
102
|
+
toolStartByCallId.set(tc.id, startId);
|
|
103
|
+
append({ type: "tool_running", toolName: tc.toolName, agentId });
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case "tool_use_args_delta": {
|
|
107
|
+
const ev = event;
|
|
108
|
+
const startId = toolStartByCallId.get(ev.toolCallId);
|
|
109
|
+
if (!startId)
|
|
110
|
+
break;
|
|
111
|
+
patchEntry(startId, (e) => ({ ...e, args: ev.args }));
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "tool_result": {
|
|
115
|
+
const r = event.result;
|
|
116
|
+
const a = asyncAgentRegistry.get(agentId);
|
|
117
|
+
if (a?.transcript) {
|
|
118
|
+
a.transcript = a.transcript.filter((e) => !(e.type === "tool_running" && e.toolName === r.toolName));
|
|
119
|
+
asyncAgentRegistry.touchTranscript(agentId);
|
|
120
|
+
}
|
|
121
|
+
append({
|
|
122
|
+
type: "tool_result",
|
|
123
|
+
toolName: r.toolName,
|
|
124
|
+
result: r.result,
|
|
125
|
+
error: r.error,
|
|
126
|
+
agentId,
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
// ── lifecycle: finalize streaming on turn end ───────────────
|
|
131
|
+
case "turn_complete":
|
|
132
|
+
case "tombstone": {
|
|
133
|
+
if (streamingAssistantId) {
|
|
134
|
+
patchEntry(streamingAssistantId, (e) => ({ ...e, streaming: false }));
|
|
135
|
+
streamingAssistantId = undefined;
|
|
136
|
+
}
|
|
137
|
+
if (thinkingId) {
|
|
138
|
+
dropEntry(thinkingId);
|
|
139
|
+
thinkingId = undefined;
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
// ── errors surface as a card in the transcript ──────────────
|
|
144
|
+
case "error": {
|
|
145
|
+
if (thinkingId) {
|
|
146
|
+
dropEntry(thinkingId);
|
|
147
|
+
thinkingId = undefined;
|
|
148
|
+
}
|
|
149
|
+
append({
|
|
150
|
+
type: "error",
|
|
151
|
+
error: event.error,
|
|
152
|
+
agentId,
|
|
153
|
+
});
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
default:
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Agent tool — spawn a sub-agent to handle a task.
|
|
3
|
+
*
|
|
4
|
+
* Creates a new Engine instance with its own transcript,
|
|
5
|
+
* runs the task to completion, and returns the result text.
|
|
6
|
+
* Supports AbortSignal for cascading cancellation.
|
|
7
|
+
* Supports onStream for real-time output passthrough.
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolDefinition } from "../../types.js";
|
|
10
|
+
import type { ToolContext } from "../context.js";
|
|
11
|
+
export declare const agentToolDef: ToolDefinition;
|
|
12
|
+
export declare function agentTool(args: Record<string, unknown>, ctx?: ToolContext): Promise<string>;
|
|
13
|
+
export declare const agentStatusToolDef: ToolDefinition;
|
|
14
|
+
export declare function agentStatusTool(args: Record<string, unknown>): Promise<string>;
|
|
15
|
+
export declare const agentCancelToolDef: ToolDefinition;
|
|
16
|
+
export declare function agentCancelTool(args: Record<string, unknown>): Promise<string>;
|