@cjhyy/code-shell-core 0.5.0-rc.1 → 0.6.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -10
- package/dist/agent/agent-definition-registry.d.ts +21 -3
- package/dist/agent/agent-definition-registry.js +49 -18
- package/dist/agent/agent-definition.d.ts +32 -0
- package/dist/agent/agent-definition.js +49 -4
- package/dist/arena/arena.js +11 -12
- package/dist/arena/context/context-tools.js +47 -6
- package/dist/arena/context/within-root.d.ts +7 -0
- package/dist/arena/context/within-root.js +15 -0
- package/dist/arena/iterate/phases/argue.js +8 -2
- package/dist/arena/iterate/phases/revise.js +1 -1
- package/dist/arena/iterate/phases/tournament.js +3 -3
- package/dist/arena/ledger.js +9 -1
- package/dist/arena/phases/adjudication.js +1 -4
- package/dist/arena/phases/build-consensus.js +1 -4
- package/dist/arena/phases/cross-review.js +2 -8
- package/dist/arena/phases/debate-rounds.js +1 -4
- package/dist/arena/phases/participant-research.js +1 -4
- package/dist/arena/phases/planning-detail-expansion.js +8 -10
- package/dist/arena/planner.js +0 -1
- package/dist/arena/providers/docs.d.ts +1 -0
- package/dist/arena/providers/docs.js +5 -2
- package/dist/arena/providers/repo.d.ts +1 -0
- package/dist/arena/providers/repo.js +5 -2
- package/dist/arena/strategies/utils.d.ts +1 -4
- package/dist/arena/strategies/utils.js +7 -51
- package/dist/arena/transitions.d.ts +7 -2
- package/dist/arena/transitions.js +9 -4
- package/dist/arena/types.d.ts +8 -2
- package/dist/automation/cron-expr.d.ts +41 -0
- package/dist/automation/cron-expr.js +169 -0
- package/dist/automation/index.d.ts +41 -0
- package/dist/automation/index.js +39 -0
- package/dist/automation/runner.d.ts +84 -0
- package/dist/automation/runner.js +92 -0
- package/dist/automation/scheduler.d.ts +194 -0
- package/dist/automation/scheduler.js +623 -0
- package/dist/automation/store.d.ts +39 -0
- package/dist/automation/store.js +122 -0
- package/dist/automation/write-policy.d.ts +34 -0
- package/dist/automation/write-policy.js +113 -0
- package/dist/automation/write-run.d.ts +51 -0
- package/dist/automation/write-run.js +38 -0
- package/dist/capability-control/disabled-lists.d.ts +25 -0
- package/dist/capability-control/disabled-lists.js +57 -0
- package/dist/capability-control/index.d.ts +5 -0
- package/dist/capability-control/index.js +3 -0
- package/dist/capability-control/overlay.d.ts +64 -0
- package/dist/capability-control/overlay.js +116 -0
- package/dist/capability-control/project.d.ts +65 -0
- package/dist/capability-control/project.js +147 -0
- package/dist/capability-control/service.d.ts +70 -0
- package/dist/capability-control/service.js +147 -0
- package/dist/capability-control/types.d.ts +62 -0
- package/dist/capability-control/types.js +17 -0
- package/dist/cc-orchestrator/agent-adapter.d.ts +50 -0
- package/dist/cc-orchestrator/agent-adapter.js +133 -0
- package/dist/cc-orchestrator/cc-capability.d.ts +19 -0
- package/dist/cc-orchestrator/cc-capability.js +53 -0
- package/dist/cc-orchestrator/codex-session-discovery.d.ts +24 -0
- package/dist/cc-orchestrator/codex-session-discovery.js +191 -0
- package/dist/cc-orchestrator/codex-session-history.d.ts +25 -0
- package/dist/cc-orchestrator/codex-session-history.js +187 -0
- package/dist/cc-orchestrator/external-agent-changes.d.ts +19 -0
- package/dist/cc-orchestrator/external-agent-changes.js +214 -0
- package/dist/cc-orchestrator/external-agent-driver.d.ts +18 -0
- package/dist/cc-orchestrator/external-agent-driver.js +69 -0
- package/dist/cc-orchestrator/index.d.ts +8 -0
- package/dist/cc-orchestrator/index.js +8 -0
- package/dist/cc-orchestrator/relevance-judge.d.ts +15 -0
- package/dist/cc-orchestrator/relevance-judge.js +29 -0
- package/dist/cc-orchestrator/session-discovery.d.ts +46 -0
- package/dist/cc-orchestrator/session-discovery.js +125 -0
- package/dist/cc-orchestrator/session-history.d.ts +19 -0
- package/dist/cc-orchestrator/session-history.js +67 -0
- package/dist/cli/agent-server-stdio.d.ts +26 -1
- package/dist/cli/agent-server-stdio.js +221 -28
- package/dist/cli/agent-server-tcp.d.ts +20 -0
- package/dist/cli/agent-server-tcp.js +134 -0
- package/dist/cli/graceful-shutdown.d.ts +27 -0
- package/dist/cli/graceful-shutdown.js +30 -0
- package/dist/context/compaction.d.ts +56 -0
- package/dist/context/compaction.js +209 -15
- package/dist/context/manager.d.ts +0 -20
- package/dist/context/manager.js +25 -41
- package/dist/cost-tracker.js +5 -61
- package/dist/credentials/cipher.d.ts +49 -0
- package/dist/credentials/cipher.js +45 -0
- package/dist/credentials/cookie-jar.d.ts +24 -0
- package/dist/credentials/cookie-jar.js +40 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/inject-credential-tool.d.ts +20 -0
- package/dist/credentials/inject-credential-tool.js +130 -0
- package/dist/credentials/store.d.ts +72 -0
- package/dist/credentials/store.js +184 -0
- package/dist/credentials/types.d.ts +56 -0
- package/dist/credentials/use-credential-tool.d.ts +29 -0
- package/dist/credentials/use-credential-tool.js +205 -0
- package/dist/credentials/use-gate.d.ts +56 -0
- package/dist/credentials/use-gate.js +52 -0
- package/dist/cron/cron-runtime.d.ts +2 -0
- package/dist/cron/cron-runtime.js +2 -0
- package/dist/cron/cron-store.d.ts +2 -0
- package/dist/cron/cron-store.js +2 -0
- package/dist/cron/scheduler.d.ts +5 -32
- package/dist/cron/scheduler.js +5 -113
- package/dist/data/model-metadata.d.ts +77 -0
- package/dist/data/model-metadata.js +56 -0
- package/dist/data/model-metadata.json +216 -0
- package/dist/data/openrouter-models.d.ts +18 -7
- package/dist/data/openrouter-models.js +35 -8
- package/dist/data/openrouter-sync.js +1 -1
- package/dist/engine/aux-key.d.ts +10 -0
- package/dist/engine/aux-key.js +11 -0
- package/dist/engine/dynamic-tool-defs.d.ts +19 -0
- package/dist/engine/dynamic-tool-defs.js +36 -0
- package/dist/engine/engine.d.ts +431 -108
- package/dist/engine/engine.js +1630 -279
- package/dist/engine/friendly-error.d.ts +18 -0
- package/dist/engine/friendly-error.js +63 -0
- package/dist/engine/goal.d.ts +187 -0
- package/dist/engine/goal.js +196 -0
- package/dist/engine/image-compression.d.ts +81 -0
- package/dist/engine/image-compression.js +186 -0
- package/dist/engine/image-policy.d.ts +165 -0
- package/dist/engine/image-policy.js +189 -0
- package/dist/engine/model-connections-pool.d.ts +17 -0
- package/dist/engine/model-connections-pool.js +66 -0
- package/dist/engine/model-facade.d.ts +10 -0
- package/dist/engine/model-facade.js +25 -0
- package/dist/engine/patch-orphaned-tools.js +3 -0
- package/dist/engine/reactive-threshold.d.ts +13 -0
- package/dist/engine/reactive-threshold.js +17 -0
- package/dist/engine/resolve-llm-config.d.ts +16 -0
- package/dist/engine/resolve-llm-config.js +44 -0
- package/dist/engine/runtime.js +9 -1
- package/dist/engine/sandbox-cache-key.d.ts +10 -0
- package/dist/engine/sandbox-cache-key.js +9 -0
- package/dist/engine/sandbox-config.d.ts +31 -0
- package/dist/engine/sandbox-config.js +38 -0
- package/dist/engine/session-title.d.ts +13 -0
- package/dist/engine/session-title.js +34 -0
- package/dist/engine/session-usage.d.ts +19 -0
- package/dist/engine/session-usage.js +25 -0
- package/dist/engine/steer-queue.d.ts +32 -0
- package/dist/engine/steer-queue.js +26 -0
- package/dist/engine/streaming-tool-queue.d.ts +12 -0
- package/dist/engine/streaming-tool-queue.js +50 -10
- package/dist/engine/turn-loop.d.ts +94 -9
- package/dist/engine/turn-loop.js +775 -342
- package/dist/engine/types.d.ts +175 -0
- package/dist/engine/types.js +13 -0
- package/dist/external-agents/config.d.ts +2 -0
- package/dist/external-agents/config.js +15 -0
- package/dist/external-agents/types.d.ts +31 -0
- package/dist/external-agents/types.js +1 -0
- package/dist/git/parse-log.d.ts +13 -0
- package/dist/git/parse-log.js +21 -0
- package/dist/git/utils.d.ts +8 -6
- package/dist/git/utils.js +62 -26
- package/dist/git/worktree.d.ts +48 -0
- package/dist/git/worktree.js +111 -20
- package/dist/hooks/events.d.ts +23 -1
- package/dist/hooks/goal-stop-hook.d.ts +58 -0
- package/dist/hooks/goal-stop-hook.js +279 -0
- package/dist/hooks/hook-output.d.ts +33 -0
- package/dist/hooks/hook-output.js +79 -0
- package/dist/hooks/registry.d.ts +15 -0
- package/dist/hooks/registry.js +57 -1
- package/dist/hooks/shell-runner.d.ts +2 -0
- package/dist/hooks/shell-runner.js +48 -18
- package/dist/index.d.ts +79 -11
- package/dist/index.js +89 -6
- package/dist/llm/capabilities/param-specs.d.ts +14 -0
- package/dist/llm/capabilities/param-specs.js +62 -0
- package/dist/llm/capabilities/reasoning-control.d.ts +24 -0
- package/dist/llm/capabilities/reasoning-control.js +38 -0
- package/dist/llm/capabilities/rules.js +37 -3
- package/dist/llm/capabilities/types.d.ts +32 -2
- package/dist/llm/clamp-max-tokens.d.ts +11 -0
- package/dist/llm/clamp-max-tokens.js +17 -0
- package/dist/llm/client-base.d.ts +69 -5
- package/dist/llm/client-base.js +185 -25
- package/dist/llm/client-factory.d.ts +3 -3
- package/dist/llm/client-factory.js +2 -2
- package/dist/llm/model-cache.js +4 -2
- package/dist/llm/model-pool.d.ts +29 -11
- package/dist/llm/model-pool.js +36 -20
- package/dist/llm/provider-auth.d.ts +41 -0
- package/dist/llm/provider-auth.js +76 -0
- package/dist/llm/provider-catalog.d.ts +6 -2
- package/dist/llm/providers/anthropic.d.ts +32 -2
- package/dist/llm/providers/anthropic.js +207 -18
- package/dist/llm/providers/openai.d.ts +47 -2
- package/dist/llm/providers/openai.js +478 -71
- package/dist/llm/reasoning-setting.d.ts +51 -0
- package/dist/llm/reasoning-setting.js +40 -0
- package/dist/llm/stop-reason.d.ts +13 -0
- package/dist/llm/stop-reason.js +21 -0
- package/dist/llm/stream-watchdog.js +5 -1
- package/dist/llm/strip-vision.d.ts +32 -0
- package/dist/llm/strip-vision.js +94 -0
- package/dist/llm/token-counter.js +9 -2
- package/dist/llm/types.d.ts +9 -6
- package/dist/logging/logger.js +18 -4
- package/dist/logging/sanitize-messages.d.ts +10 -0
- package/dist/logging/sanitize-messages.js +112 -0
- package/dist/lsp/client.js +28 -8
- package/dist/lsp/manager.d.ts +1 -1
- package/dist/lsp/manager.js +42 -11
- package/dist/lsp/root-path.d.ts +9 -0
- package/dist/lsp/root-path.js +12 -0
- package/dist/model-catalog/builtin.d.ts +12 -0
- package/dist/model-catalog/builtin.js +407 -0
- package/dist/model-catalog/gen-connections.d.ts +20 -0
- package/dist/model-catalog/gen-connections.js +28 -0
- package/dist/model-catalog/index.d.ts +41 -0
- package/dist/model-catalog/index.js +90 -0
- package/dist/model-catalog/params.d.ts +20 -0
- package/dist/model-catalog/params.js +45 -0
- package/dist/model-catalog/resolve.d.ts +48 -0
- package/dist/model-catalog/resolve.js +33 -0
- package/dist/model-catalog/save-entry.d.ts +32 -0
- package/dist/model-catalog/save-entry.js +104 -0
- package/dist/model-catalog/types.d.ts +561 -0
- package/dist/model-catalog/types.js +93 -0
- package/dist/model-catalog/upsert.d.ts +9 -0
- package/dist/model-catalog/upsert.js +8 -0
- package/dist/onboarding.d.ts +12 -82
- package/dist/onboarding.js +75 -333
- package/dist/plugins/gitOps.d.ts +53 -0
- package/dist/plugins/gitOps.js +130 -5
- package/dist/plugins/installer/checkUpdate.d.ts +16 -0
- package/dist/plugins/installer/checkUpdate.js +32 -0
- package/dist/plugins/installer/codex/convertAgents.d.ts +7 -0
- package/dist/plugins/installer/codex/convertAgents.js +55 -0
- package/dist/plugins/installer/codex/convertCommands.d.ts +19 -0
- package/dist/plugins/installer/codex/convertCommands.js +46 -0
- package/dist/plugins/installer/codex/convertMcp.d.ts +11 -0
- package/dist/plugins/installer/codex/convertMcp.js +85 -0
- package/dist/plugins/installer/codex/convertSkills.d.ts +12 -0
- package/dist/plugins/installer/codex/convertSkills.js +33 -0
- package/dist/plugins/installer/detectFormat.d.ts +2 -0
- package/dist/plugins/installer/detectFormat.js +6 -0
- package/dist/plugins/installer/install.d.ts +7 -0
- package/dist/plugins/installer/install.js +123 -0
- package/dist/plugins/installer/installFromArchive.d.ts +43 -0
- package/dist/plugins/installer/installFromArchive.js +134 -0
- package/dist/plugins/installer/installFromSource.d.ts +13 -0
- package/dist/plugins/installer/installFromSource.js +51 -0
- package/dist/plugins/installer/list.d.ts +9 -0
- package/dist/plugins/installer/list.js +30 -0
- package/dist/plugins/installer/loadPluginAgents.d.ts +3 -0
- package/dist/plugins/installer/loadPluginAgents.js +27 -0
- package/dist/plugins/installer/loadPluginMcp.d.ts +14 -0
- package/dist/plugins/installer/loadPluginMcp.js +107 -0
- package/dist/plugins/installer/parseSource.d.ts +20 -0
- package/dist/plugins/installer/parseSource.js +74 -0
- package/dist/plugins/installer/paths.d.ts +5 -0
- package/dist/plugins/installer/paths.js +25 -0
- package/dist/plugins/installer/pruneDisabled.d.ts +24 -0
- package/dist/plugins/installer/pruneDisabled.js +73 -0
- package/dist/plugins/installer/types.d.ts +52 -0
- package/dist/plugins/installer/types.js +28 -0
- package/dist/plugins/installer/uninstall.d.ts +2 -0
- package/dist/plugins/installer/uninstall.js +18 -0
- package/dist/plugins/installer/unzip.d.ts +14 -0
- package/dist/plugins/installer/unzip.js +82 -0
- package/dist/plugins/installer/update.d.ts +28 -0
- package/dist/plugins/installer/update.js +97 -0
- package/dist/plugins/loadPluginHooks.d.ts +54 -1
- package/dist/plugins/loadPluginHooks.js +83 -1
- package/dist/plugins/marketplaceManager.d.ts +15 -1
- package/dist/plugins/marketplaceManager.js +58 -4
- package/dist/plugins/pluginCommandHook.js +34 -14
- package/dist/plugins/pluginContent.d.ts +30 -0
- package/dist/plugins/pluginContent.js +83 -0
- package/dist/plugins/pluginInstaller.d.ts +34 -0
- package/dist/plugins/pluginInstaller.js +168 -35
- package/dist/plugins/schemas.js +41 -6
- package/dist/plugins/types.d.ts +10 -0
- package/dist/preset/index.d.ts +7 -1
- package/dist/preset/index.js +112 -6
- package/dist/product/types.d.ts +1 -1
- package/dist/prompt/composer.d.ts +31 -0
- package/dist/prompt/composer.js +95 -25
- package/dist/prompt/instruction-scanner.js +5 -3
- package/dist/prompt/section-loader.js +1 -0
- package/dist/prompt/sections/base.md +1 -0
- package/dist/prompt/sections/browser.md +10 -0
- package/dist/prompt/sections/coding.md +4 -0
- package/dist/prompt/sections/orchestration.md +8 -0
- package/dist/protocol/chat-session-manager.d.ts +15 -2
- package/dist/protocol/chat-session-manager.js +46 -0
- package/dist/protocol/chat-session.d.ts +82 -0
- package/dist/protocol/chat-session.js +121 -1
- package/dist/protocol/client.d.ts +27 -0
- package/dist/protocol/client.js +38 -0
- package/dist/protocol/redact.d.ts +50 -0
- package/dist/protocol/redact.js +71 -0
- package/dist/protocol/server.d.ts +153 -2
- package/dist/protocol/server.js +807 -39
- package/dist/protocol/tcp-transport.d.ts +45 -0
- package/dist/protocol/tcp-transport.js +74 -0
- package/dist/protocol/transport.js +3 -2
- package/dist/protocol/types.d.ts +69 -0
- package/dist/protocol/types.js +22 -0
- package/dist/quota/credentials.d.ts +3 -0
- package/dist/quota/credentials.js +80 -0
- package/dist/quota/index.d.ts +36 -0
- package/dist/quota/index.js +155 -0
- package/dist/quota/types.d.ts +48 -0
- package/dist/quota/types.js +13 -0
- package/dist/remote/bridge.d.ts +11 -2
- package/dist/remote/bridge.js +61 -33
- package/dist/review/review-prompt.d.ts +28 -0
- package/dist/review/review-prompt.js +81 -0
- package/dist/run/ArtifactTracker.js +5 -4
- package/dist/run/EngineRunner.d.ts +27 -1
- package/dist/run/EngineRunner.js +46 -8
- package/dist/run/FileRunStore.js +40 -11
- package/dist/run/RunApprovalBackend.js +25 -5
- package/dist/run/RunLock.d.ts +28 -2
- package/dist/run/RunLock.js +49 -7
- package/dist/run/RunManager.d.ts +12 -0
- package/dist/run/RunManager.js +86 -3
- package/dist/run/RunQueue.d.ts +1 -0
- package/dist/run/RunQueue.js +8 -2
- package/dist/run/factory.d.ts +8 -1
- package/dist/run/factory.js +1 -0
- package/dist/run/index.d.ts +2 -2
- package/dist/run/index.js +1 -1
- package/dist/run/redirect-target.d.ts +7 -0
- package/dist/run/redirect-target.js +13 -0
- package/dist/run/types.js +1 -1
- package/dist/runtime/background-shell.d.ts +139 -0
- package/dist/runtime/background-shell.js +495 -0
- package/dist/runtime/output-clean.d.ts +24 -0
- package/dist/runtime/output-clean.js +41 -0
- package/dist/runtime/ring-file.d.ts +64 -0
- package/dist/runtime/ring-file.js +174 -0
- package/dist/runtime/safe-spawn.js +15 -34
- package/dist/runtime/spawn-common.d.ts +148 -0
- package/dist/runtime/spawn-common.js +303 -0
- package/dist/runtime/truncate-output.d.ts +22 -0
- package/dist/runtime/truncate-output.js +49 -0
- package/dist/runtime/utf8-cut.d.ts +11 -0
- package/dist/runtime/utf8-cut.js +23 -0
- package/dist/services/auto-dream.d.ts +4 -0
- package/dist/services/auto-dream.js +26 -26
- package/dist/services/browser-open.d.ts +13 -0
- package/dist/services/browser-open.js +16 -0
- package/dist/services/diagnostics.d.ts +1 -2
- package/dist/services/diagnostics.js +12 -7
- package/dist/services/dream-consolidation.d.ts +57 -0
- package/dist/services/dream-consolidation.js +151 -0
- package/dist/services/extract-memories.d.ts +14 -1
- package/dist/services/extract-memories.js +45 -6
- package/dist/services/memory-orchestrator.d.ts +21 -0
- package/dist/services/memory-orchestrator.js +125 -32
- package/dist/services/notifier.d.ts +8 -0
- package/dist/services/notifier.js +39 -25
- package/dist/services/oauth.js +5 -7
- package/dist/services/session-memory-sort.d.ts +8 -0
- package/dist/services/session-memory-sort.js +9 -0
- package/dist/services/session-memory.js +30 -19
- package/dist/session/file-history.d.ts +124 -1
- package/dist/session/file-history.js +232 -9
- package/dist/session/memory.d.ts +116 -2
- package/dist/session/memory.js +250 -28
- package/dist/session/session-manager.d.ts +63 -1
- package/dist/session/session-manager.js +186 -5
- package/dist/session/simple-diff.d.ts +23 -0
- package/dist/session/simple-diff.js +84 -0
- package/dist/session/transcript.d.ts +25 -1
- package/dist/session/transcript.js +35 -2
- package/dist/session/undo-target.d.ts +67 -0
- package/dist/session/undo-target.js +144 -0
- package/dist/settings/disk-defaults.d.ts +42 -0
- package/dist/settings/disk-defaults.js +33 -0
- package/dist/settings/feature-flags.d.ts +64 -0
- package/dist/settings/feature-flags.js +61 -0
- package/dist/settings/manager.d.ts +101 -1
- package/dist/settings/manager.js +345 -15
- package/dist/settings/migrate-config.d.ts +45 -0
- package/dist/settings/migrate-config.js +125 -0
- package/dist/settings/personalization.d.ts +19 -0
- package/dist/settings/personalization.js +7 -0
- package/dist/settings/schema-export.d.ts +25 -0
- package/dist/settings/schema-export.js +38 -0
- package/dist/settings/schema.d.ts +1827 -396
- package/dist/settings/schema.js +361 -81
- package/dist/skills/scanner.d.ts +9 -0
- package/dist/skills/scanner.js +30 -2
- package/dist/stt/resolve-transcribe.d.ts +31 -0
- package/dist/stt/resolve-transcribe.js +108 -0
- package/dist/stt/transcribe.d.ts +51 -0
- package/dist/stt/transcribe.js +65 -0
- package/dist/tool-system/browser-bridge.d.ts +226 -0
- package/dist/tool-system/browser-bridge.js +163 -0
- package/dist/tool-system/builtin/add-marketplace.d.ts +12 -0
- package/dist/tool-system/builtin/add-marketplace.js +76 -0
- package/dist/tool-system/builtin/agent-heartbeat.d.ts +49 -0
- package/dist/tool-system/builtin/agent-heartbeat.js +89 -0
- package/dist/tool-system/builtin/agent-notifications.d.ts +12 -3
- package/dist/tool-system/builtin/agent-notifications.js +9 -3
- package/dist/tool-system/builtin/agent-output-file.d.ts +38 -0
- package/dist/tool-system/builtin/agent-output-file.js +72 -0
- package/dist/tool-system/builtin/agent-registry.d.ts +23 -0
- package/dist/tool-system/builtin/agent-registry.js +16 -4
- package/dist/tool-system/builtin/agent.d.ts +50 -11
- package/dist/tool-system/builtin/agent.js +576 -73
- package/dist/tool-system/builtin/apply-patch/applier.js +66 -8
- package/dist/tool-system/builtin/apply-patch/backup-targets.d.ts +10 -0
- package/dist/tool-system/builtin/apply-patch/backup-targets.js +30 -0
- package/dist/tool-system/builtin/apply-patch/index.js +7 -3
- package/dist/tool-system/builtin/arena.js +6 -7
- package/dist/tool-system/builtin/background-jobs.d.ts +76 -0
- package/dist/tool-system/builtin/background-jobs.js +124 -0
- package/dist/tool-system/builtin/background-shell-tools.d.ts +20 -0
- package/dist/tool-system/builtin/background-shell-tools.js +108 -0
- package/dist/tool-system/builtin/background-work.d.ts +67 -0
- package/dist/tool-system/builtin/background-work.js +86 -0
- package/dist/tool-system/builtin/bash-output-style.d.ts +32 -0
- package/dist/tool-system/builtin/bash-output-style.js +40 -0
- package/dist/tool-system/builtin/bash.d.ts +5 -2
- package/dist/tool-system/builtin/bash.js +98 -62
- package/dist/tool-system/builtin/browser-tools.d.ts +33 -0
- package/dist/tool-system/builtin/browser-tools.js +312 -0
- package/dist/tool-system/builtin/cancel-goal.d.ts +31 -0
- package/dist/tool-system/builtin/cancel-goal.js +64 -0
- package/dist/tool-system/builtin/check-quota.d.ts +15 -0
- package/dist/tool-system/builtin/check-quota.js +34 -0
- package/dist/tool-system/builtin/complete-goal.d.ts +25 -0
- package/dist/tool-system/builtin/complete-goal.js +45 -0
- package/dist/tool-system/builtin/config.js +7 -0
- package/dist/tool-system/builtin/cron.d.ts +7 -0
- package/dist/tool-system/builtin/cron.js +105 -9
- package/dist/tool-system/builtin/drive-claude-code.d.ts +30 -0
- package/dist/tool-system/builtin/drive-claude-code.js +157 -0
- package/dist/tool-system/builtin/edit-model-catalog.d.ts +3 -0
- package/dist/tool-system/builtin/edit-model-catalog.js +94 -0
- package/dist/tool-system/builtin/edit.d.ts +2 -1
- package/dist/tool-system/builtin/edit.js +21 -12
- package/dist/tool-system/builtin/eol.d.ts +29 -0
- package/dist/tool-system/builtin/eol.js +37 -0
- package/dist/tool-system/builtin/file-cache.d.ts +6 -0
- package/dist/tool-system/builtin/file-cache.js +8 -0
- package/dist/tool-system/builtin/generate-image.d.ts +60 -0
- package/dist/tool-system/builtin/generate-image.js +374 -0
- package/dist/tool-system/builtin/generate-video.d.ts +55 -0
- package/dist/tool-system/builtin/generate-video.js +361 -0
- package/dist/tool-system/builtin/grep.js +6 -2
- package/dist/tool-system/builtin/image-providers.d.ts +86 -0
- package/dist/tool-system/builtin/image-providers.js +190 -0
- package/dist/tool-system/builtin/image-uploader.d.ts +33 -0
- package/dist/tool-system/builtin/image-uploader.js +74 -0
- package/dist/tool-system/builtin/index.d.ts +24 -1
- package/dist/tool-system/builtin/index.js +310 -25
- package/dist/tool-system/builtin/mcp-tools.js +23 -3
- package/dist/tool-system/builtin/memory.js +45 -7
- package/dist/tool-system/builtin/notebook-edit.d.ts +2 -1
- package/dist/tool-system/builtin/notebook-edit.js +1 -1
- package/dist/tool-system/builtin/powershell.js +4 -1
- package/dist/tool-system/builtin/read.d.ts +2 -1
- package/dist/tool-system/builtin/read.js +11 -3
- package/dist/tool-system/builtin/repl.js +4 -1
- package/dist/tool-system/builtin/skill.js +9 -0
- package/dist/tool-system/builtin/sleep.js +12 -5
- package/dist/tool-system/builtin/task.js +4 -1
- package/dist/tool-system/builtin/tool-search.js +25 -7
- package/dist/tool-system/builtin/update-automation-memory.d.ts +24 -0
- package/dist/tool-system/builtin/update-automation-memory.js +60 -0
- package/dist/tool-system/builtin/video-providers.d.ts +154 -0
- package/dist/tool-system/builtin/video-providers.js +235 -0
- package/dist/tool-system/builtin/view-image.d.ts +18 -0
- package/dist/tool-system/builtin/view-image.js +96 -0
- package/dist/tool-system/builtin/web-fetch.js +12 -2
- package/dist/tool-system/builtin/web-search.d.ts +4 -1
- package/dist/tool-system/builtin/web-search.js +57 -10
- package/dist/tool-system/builtin/worktree.d.ts +2 -1
- package/dist/tool-system/builtin/worktree.js +31 -4
- package/dist/tool-system/builtin/write.d.ts +2 -1
- package/dist/tool-system/builtin/write.js +1 -1
- package/dist/tool-system/context.d.ts +166 -6
- package/dist/tool-system/executor.d.ts +3 -2
- package/dist/tool-system/executor.js +197 -119
- package/dist/tool-system/investigation-guard.d.ts +4 -1
- package/dist/tool-system/investigation-guard.js +20 -4
- package/dist/tool-system/mcp-manager.d.ts +78 -16
- package/dist/tool-system/mcp-manager.js +357 -28
- package/dist/tool-system/path-policy.d.ts +99 -0
- package/dist/tool-system/path-policy.js +578 -0
- package/dist/tool-system/permission.d.ts +36 -1
- package/dist/tool-system/permission.js +322 -117
- package/dist/tool-system/plan-mode-allowlist.d.ts +32 -0
- package/dist/tool-system/plan-mode-allowlist.js +65 -0
- package/dist/tool-system/registry.d.ts +1 -0
- package/dist/tool-system/registry.js +26 -1
- package/dist/tool-system/sandbox/index.d.ts +8 -0
- package/dist/tool-system/sandbox/index.js +7 -2
- package/dist/tool-system/validate-tool-metadata.d.ts +36 -0
- package/dist/tool-system/validate-tool-metadata.js +63 -0
- package/dist/tool-system/validation.d.ts +10 -0
- package/dist/tool-system/validation.js +16 -3
- package/dist/types.d.ts +301 -15
- package/dist/updater.js +20 -9
- package/dist/utils/envUtils.d.ts +0 -9
- package/dist/utils/envUtils.js +3 -28
- package/dist/utils/exec.d.ts +40 -0
- package/dist/utils/exec.js +144 -0
- package/dist/utils/format.js +4 -2
- package/dist/utils/json.d.ts +12 -0
- package/dist/utils/json.js +92 -0
- package/dist/utils/lockfile.js +9 -2
- package/dist/utils/theme.d.ts +7 -1
- package/dist/utils/theme.js +5 -3
- package/dist/utils/toolDisplay.js +0 -1
- package/package.json +14 -7
- package/dist/agent/coordinator.d.ts +0 -49
- package/dist/agent/coordinator.js +0 -77
- package/dist/settings/manager.test.js +0 -73
- package/dist/tool-system/builtin/remote-trigger.d.ts +0 -6
- package/dist/tool-system/builtin/remote-trigger.js +0 -54
- package/dist/tool-system/builtin/send-message.d.ts +0 -6
- package/dist/tool-system/builtin/send-message.js +0 -47
- /package/dist/{settings/manager.test.d.ts → credentials/types.js} +0 -0
|
@@ -10,6 +10,29 @@ function nextReqId() {
|
|
|
10
10
|
_reqSeq += 1;
|
|
11
11
|
return `r${_reqSeq.toString(36)}`;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Prompt-cache hit rate for one request, as CC computes it:
|
|
15
|
+
* cacheRead / (cacheRead + cacheCreation + uncachedInput)
|
|
16
|
+
* where uncachedInput = promptTokens − cacheRead − cacheCreation (promptTokens
|
|
17
|
+
* already includes the cached portion). Returns undefined when the provider
|
|
18
|
+
* reported no cache info at all, so `llm.request` only carries the field when
|
|
19
|
+
* it's meaningful. Makes hit-rate observable in logs — the prerequisite for
|
|
20
|
+
* any caching tuning (docs/todo/prompt-cache-optimization.md §四 step 1).
|
|
21
|
+
*/
|
|
22
|
+
export function cacheHitRate(usage) {
|
|
23
|
+
if (!usage)
|
|
24
|
+
return undefined;
|
|
25
|
+
const read = usage.cacheReadTokens ?? 0;
|
|
26
|
+
const creation = usage.cacheCreationTokens ?? 0;
|
|
27
|
+
if (read === 0 && creation === 0)
|
|
28
|
+
return undefined;
|
|
29
|
+
const prompt = usage.promptTokens ?? 0;
|
|
30
|
+
const uncached = Math.max(0, prompt - read - creation);
|
|
31
|
+
const denom = read + creation + uncached;
|
|
32
|
+
if (denom === 0)
|
|
33
|
+
return undefined;
|
|
34
|
+
return read / denom;
|
|
35
|
+
}
|
|
13
36
|
export class ModelFacade {
|
|
14
37
|
client;
|
|
15
38
|
transcript;
|
|
@@ -82,6 +105,7 @@ export class ModelFacade {
|
|
|
82
105
|
toolCalls: response.toolCalls.length,
|
|
83
106
|
textLen: response.text?.length ?? 0,
|
|
84
107
|
usage: response.usage,
|
|
108
|
+
cacheHitRate: cacheHitRate(response.usage),
|
|
85
109
|
});
|
|
86
110
|
recordLLMResponse(sid, {
|
|
87
111
|
text: response.text,
|
|
@@ -135,6 +159,7 @@ export class ModelFacade {
|
|
|
135
159
|
toolCalls: response.toolCalls.length,
|
|
136
160
|
textLen: response.text?.length ?? 0,
|
|
137
161
|
usage: response.usage,
|
|
162
|
+
cacheHitRate: cacheHitRate(response.usage),
|
|
138
163
|
});
|
|
139
164
|
recordLLMResponse(sid, {
|
|
140
165
|
text: response.text,
|
|
@@ -79,6 +79,9 @@ export function patchOrphanedToolUses(messages) {
|
|
|
79
79
|
type: "tool_result",
|
|
80
80
|
tool_use_id: id,
|
|
81
81
|
content: SYNTHETIC_ERROR_TEXT,
|
|
82
|
+
// Flag as an error so the Anthropic provider marks it is_error; otherwise
|
|
83
|
+
// the model reads the synthetic result as a successful tool output.
|
|
84
|
+
is_error: true,
|
|
82
85
|
}));
|
|
83
86
|
messages.splice(i + 1, 0, { role: "user", content: errorBlocks });
|
|
84
87
|
// Mark these ids answered so a later assistant message referencing
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactive-compaction probe gating.
|
|
3
|
+
*
|
|
4
|
+
* During streaming the turn loop accumulates an estimate of the response
|
|
5
|
+
* size and periodically asks the ContextManager whether we're nearing the
|
|
6
|
+
* context limit. The old gate (`tokens % 2000 === 0`) almost never matched a
|
|
7
|
+
* running `+= ceil(len/4)` accumulator, so the probe never fired. This fires
|
|
8
|
+
* once per 2000-token bucket crossed, tracked by `lastBucket`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function crossedReactiveThreshold(accumulatedTokens: number, lastBucket: number): {
|
|
11
|
+
crossed: boolean;
|
|
12
|
+
bucket: number;
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactive-compaction probe gating.
|
|
3
|
+
*
|
|
4
|
+
* During streaming the turn loop accumulates an estimate of the response
|
|
5
|
+
* size and periodically asks the ContextManager whether we're nearing the
|
|
6
|
+
* context limit. The old gate (`tokens % 2000 === 0`) almost never matched a
|
|
7
|
+
* running `+= ceil(len/4)` accumulator, so the probe never fired. This fires
|
|
8
|
+
* once per 2000-token bucket crossed, tracked by `lastBucket`.
|
|
9
|
+
*/
|
|
10
|
+
const REACTIVE_BUCKET = 2000;
|
|
11
|
+
export function crossedReactiveThreshold(accumulatedTokens, lastBucket) {
|
|
12
|
+
const bucket = Math.floor(accumulatedTokens / REACTIVE_BUCKET);
|
|
13
|
+
if (bucket >= 1 && bucket > lastBucket) {
|
|
14
|
+
return { crossed: true, bucket };
|
|
15
|
+
}
|
|
16
|
+
return { crossed: false, bucket: lastBucket };
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resolveLLMConfigForTag — 单一入口:settings + tag + 可选偏好实例 id → LLMConfig。
|
|
3
|
+
* 所有非-engine 的 seed 场景(agent-server bootstrap / automation / dream / TUI
|
|
4
|
+
* 命令)都调它,避免各自手搓 { provider: settings.model.provider, ... }。
|
|
5
|
+
*
|
|
6
|
+
* 复用 modelEntriesFromConnections + 临时 ModelPool.toLLMConfig,与 engine 内部
|
|
7
|
+
* 长生命周期 pool 共享同一批零件,不逻辑分叉。
|
|
8
|
+
*
|
|
9
|
+
* 选择优先级:preferredId(命中才用)→ defaults[tag] → 首个可用连接。
|
|
10
|
+
* 返回 null = 该 tag 下没有任何可用连接,调用方据此抛明确错误。
|
|
11
|
+
*
|
|
12
|
+
* 本次只处理 text;image/video 已有独立 resolver(resolveImageProvider 等)。
|
|
13
|
+
*/
|
|
14
|
+
import type { LLMConfig } from "../types.js";
|
|
15
|
+
import type { ValidatedSettings } from "../settings/schema.js";
|
|
16
|
+
export declare function resolveLLMConfigForTag(settings: ValidatedSettings, tag: "text", preferredInstanceId?: string): LLMConfig | null;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getMergedCatalog } from "../model-catalog/index.js";
|
|
2
|
+
import { modelEntriesFromConnections } from "./model-connections-pool.js";
|
|
3
|
+
import { ModelPool } from "../llm/model-pool.js";
|
|
4
|
+
export function resolveLLMConfigForTag(settings, tag, preferredInstanceId) {
|
|
5
|
+
const connections = settings.modelConnections;
|
|
6
|
+
if (!Array.isArray(connections) || connections.length === 0)
|
|
7
|
+
return null;
|
|
8
|
+
const credentials = settings.credentials;
|
|
9
|
+
const catalog = getMergedCatalog();
|
|
10
|
+
const entries = modelEntriesFromConnections(connections, (Array.isArray(credentials) ? credentials : []), catalog);
|
|
11
|
+
if (entries.length === 0)
|
|
12
|
+
return null;
|
|
13
|
+
// entry.key === connection.id(见 modelEntriesFromConnections)。
|
|
14
|
+
const defaultId = settings.defaults?.text;
|
|
15
|
+
const pick = (preferredInstanceId && entries.find((e) => e.key === preferredInstanceId)) ||
|
|
16
|
+
(defaultId && entries.find((e) => e.key === defaultId)) ||
|
|
17
|
+
entries[0];
|
|
18
|
+
if (!pick)
|
|
19
|
+
return null;
|
|
20
|
+
// 用户显式选了 default/preferred 但它解析不到(连接的 catalogId 被删 →
|
|
21
|
+
// modelEntriesFromConnections 静默过滤掉)→ 这里 find 落空、悄悄回退到 entries[0]
|
|
22
|
+
// 是「换了个模型还不告诉你」。不改回退行为(有可用连接就用),但出一条 warn 让
|
|
23
|
+
// 静默替换可见(否则用户以为还在用选的那个)。
|
|
24
|
+
const wanted = preferredInstanceId ?? defaultId;
|
|
25
|
+
if (wanted && pick.key !== wanted) {
|
|
26
|
+
console.warn(`[resolveLLMConfigForTag] 偏好/默认连接 "${wanted}" 解析不到(catalogId 可能已删)— 回退到 "${pick.key}"。`);
|
|
27
|
+
}
|
|
28
|
+
// The picked connection's catalog template needs a key but none resolved
|
|
29
|
+
// (credentialId missing/points at a deleted credential). Returning null here
|
|
30
|
+
// routes to the caller's existing clean "没有可用的文本模型连接 … 请在「连接」
|
|
31
|
+
// 页添加并填写凭证" message + exit, instead of silently building a config with
|
|
32
|
+
// apiKey:undefined that only fails later as a cryptic provider 401. In
|
|
33
|
+
// CONTRACT: this fn's null already means "no USABLE connection for this tag".
|
|
34
|
+
// resolveInstance's no-crash (apiKey:undefined) behavior is untouched — this
|
|
35
|
+
// gate is one layer up where usability is decided.
|
|
36
|
+
if (pick.needsKey !== false && !pick.apiKey) {
|
|
37
|
+
console.warn(`[resolveLLMConfigForTag] 连接 "${pick.key}" 需要密钥但未解析到凭证(credentialId 缺失或指向已删凭证)— 视为该 tag 无可用连接。`);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
// 临时 pool 复用 toLLMConfig 的全部映射逻辑(reasoning/headers/providerKind 等)。
|
|
41
|
+
const pool = new ModelPool([]);
|
|
42
|
+
pool.register(pick);
|
|
43
|
+
return pool.toLLMConfig(pick);
|
|
44
|
+
}
|
package/dist/engine/runtime.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveSandboxBackend, } from "../tool-system/sandbox/index.js";
|
|
2
|
+
import { sandboxCacheKey } from "./sandbox-cache-key.js";
|
|
2
3
|
/**
|
|
3
4
|
* Shared read-only resources used by all Engine instances in a worker.
|
|
4
5
|
* Mutable per-session state stays on Engine itself.
|
|
@@ -31,10 +32,17 @@ export class EngineRuntime {
|
|
|
31
32
|
* violate standard §S4 fail-closed rule.
|
|
32
33
|
*/
|
|
33
34
|
resolveSandbox(config, cwd) {
|
|
34
|
-
const key =
|
|
35
|
+
const key = sandboxCacheKey(config, cwd);
|
|
35
36
|
let cached = this.sandboxCache.get(key);
|
|
36
37
|
if (!cached) {
|
|
37
38
|
cached = resolveSandboxBackend(config, cwd);
|
|
39
|
+
// Don't cache a rejection: an explicit-mode probe that throws (e.g.
|
|
40
|
+
// `seatbelt` on a host without sandbox-exec) must be retryable after the
|
|
41
|
+
// user fixes the config, not sticky until process restart.
|
|
42
|
+
cached.catch(() => {
|
|
43
|
+
if (this.sandboxCache.get(key) === cached)
|
|
44
|
+
this.sandboxCache.delete(key);
|
|
45
|
+
});
|
|
38
46
|
this.sandboxCache.set(key, cached);
|
|
39
47
|
}
|
|
40
48
|
return cached;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sandboxCacheKey — cache key for a resolved sandbox backend. Includes every
|
|
3
|
+
* field that affects the backend (mode, network, writableRoots, deniedReads)
|
|
4
|
+
* plus cwd. The key was previously `${mode}:${cwd}`, which ignored network /
|
|
5
|
+
* roots / reads — so editing those in 设置页 hit the stale cached backend and
|
|
6
|
+
* didn't take effect until app restart. Stable JSON shape so equal configs map
|
|
7
|
+
* to equal keys.
|
|
8
|
+
*/
|
|
9
|
+
import type { SandboxConfig } from "../tool-system/sandbox/index.js";
|
|
10
|
+
export declare function sandboxCacheKey(config: SandboxConfig, cwd: string): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resolveSandboxConfig — pick the sandbox config for a run, reading the
|
|
3
|
+
* 设置页's settings.sandbox so a project-scoped sandbox setting actually takes
|
|
4
|
+
* effect. Priority: explicit config.sandbox → settings.sandbox.mode → per-run
|
|
5
|
+
* default (headless=auto, REPL/desktop=off).
|
|
6
|
+
*
|
|
7
|
+
* Background: the engine previously only honored config.sandbox, which the
|
|
8
|
+
* desktop host never passes — so a user enabling sandbox in 设置页 had no
|
|
9
|
+
* effect. This bridges settings → run config.
|
|
10
|
+
* See memory project_10_review_bug_list #9.
|
|
11
|
+
*/
|
|
12
|
+
import { type SandboxConfig, type SandboxMode } from "../tool-system/sandbox/index.js";
|
|
13
|
+
/** The shape of settings.sandbox (all fields optional). */
|
|
14
|
+
export interface SettingsSandbox {
|
|
15
|
+
mode?: SandboxMode;
|
|
16
|
+
network?: "allow" | "deny";
|
|
17
|
+
writableRoots?: string[];
|
|
18
|
+
deniedReads?: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Three-layer resolve. Priority:
|
|
22
|
+
* 1. config.sandbox — explicit host-passed.
|
|
23
|
+
* 2. project settings.sandbox (has mode) — overrides global.
|
|
24
|
+
* 3. global settings.sandbox (has mode) — what a project "follows".
|
|
25
|
+
* 4. per-run default: headless → auto, desktop/REPL → off.
|
|
26
|
+
*
|
|
27
|
+
* A layer without `mode` is "unset / 跟随上一层" — pass unmerged per-scope
|
|
28
|
+
* values so a project that wrote nothing genuinely follows global (a merged
|
|
29
|
+
* value would make every project look like it set global's mode).
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveSandboxConfig(configSandbox: SandboxConfig | undefined, projectSandbox: SettingsSandbox | undefined, globalSandbox: SettingsSandbox | undefined, headless: boolean): SandboxConfig;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resolveSandboxConfig — pick the sandbox config for a run, reading the
|
|
3
|
+
* 设置页's settings.sandbox so a project-scoped sandbox setting actually takes
|
|
4
|
+
* effect. Priority: explicit config.sandbox → settings.sandbox.mode → per-run
|
|
5
|
+
* default (headless=auto, REPL/desktop=off).
|
|
6
|
+
*
|
|
7
|
+
* Background: the engine previously only honored config.sandbox, which the
|
|
8
|
+
* desktop host never passes — so a user enabling sandbox in 设置页 had no
|
|
9
|
+
* effect. This bridges settings → run config.
|
|
10
|
+
* See memory project_10_review_bug_list #9.
|
|
11
|
+
*/
|
|
12
|
+
import { defaultSandboxConfig } from "../tool-system/sandbox/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Three-layer resolve. Priority:
|
|
15
|
+
* 1. config.sandbox — explicit host-passed.
|
|
16
|
+
* 2. project settings.sandbox (has mode) — overrides global.
|
|
17
|
+
* 3. global settings.sandbox (has mode) — what a project "follows".
|
|
18
|
+
* 4. per-run default: headless → auto, desktop/REPL → off.
|
|
19
|
+
*
|
|
20
|
+
* A layer without `mode` is "unset / 跟随上一层" — pass unmerged per-scope
|
|
21
|
+
* values so a project that wrote nothing genuinely follows global (a merged
|
|
22
|
+
* value would make every project look like it set global's mode).
|
|
23
|
+
*/
|
|
24
|
+
export function resolveSandboxConfig(configSandbox, projectSandbox, globalSandbox, headless) {
|
|
25
|
+
if (configSandbox)
|
|
26
|
+
return configSandbox;
|
|
27
|
+
const layer = projectSandbox?.mode ? projectSandbox : globalSandbox?.mode ? globalSandbox : undefined;
|
|
28
|
+
if (layer?.mode) {
|
|
29
|
+
const base = defaultSandboxConfig(layer.mode);
|
|
30
|
+
return {
|
|
31
|
+
mode: layer.mode,
|
|
32
|
+
network: layer.network ?? base.network,
|
|
33
|
+
writableRoots: layer.writableRoots ?? base.writableRoots,
|
|
34
|
+
deniedReads: layer.deniedReads ?? base.deniedReads,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return defaultSandboxConfig(headless ? "auto" : "off");
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session title generation — best-effort, one-line LLM title for the sidebar.
|
|
3
|
+
*
|
|
4
|
+
* Pure function (no Engine `this`) so it's trivially unit-testable. The Engine
|
|
5
|
+
* resolves the aux client and wiring; this only does the LLM call + cleanup.
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMClientBase } from "../llm/client-base.js";
|
|
8
|
+
/**
|
|
9
|
+
* Ask the aux client for a one-line title from the first user message + first
|
|
10
|
+
* assistant reply. Returns the cleaned title, or null on any failure / empty
|
|
11
|
+
* output (caller treats null as "keep existing title").
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildSessionTitle(client: LLMClientBase, firstUserText: string, firstAssistantText: string): Promise<string | null>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const SYSTEM_PROMPT = "You generate a very short title (≤6 words, no quotes, no trailing punctuation) " +
|
|
2
|
+
"summarizing a chat, in the same language as the user's message.";
|
|
3
|
+
/** Strip wrapping quotes/whitespace the model sometimes adds. */
|
|
4
|
+
function clean(raw) {
|
|
5
|
+
return raw
|
|
6
|
+
.trim()
|
|
7
|
+
.replace(/^["'“”‘’「『]+/, "")
|
|
8
|
+
.replace(/["'“”‘’」』]+$/, "")
|
|
9
|
+
.trim();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ask the aux client for a one-line title from the first user message + first
|
|
13
|
+
* assistant reply. Returns the cleaned title, or null on any failure / empty
|
|
14
|
+
* output (caller treats null as "keep existing title").
|
|
15
|
+
*/
|
|
16
|
+
export async function buildSessionTitle(client, firstUserText, firstAssistantText) {
|
|
17
|
+
try {
|
|
18
|
+
const prompt = `User: ${firstUserText.slice(0, 2000)}\n\n` +
|
|
19
|
+
`Assistant: ${firstAssistantText.slice(0, 2000)}\n\n` +
|
|
20
|
+
`Title:`;
|
|
21
|
+
const resp = await client.createMessage({
|
|
22
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
23
|
+
messages: [{ role: "user", content: prompt }],
|
|
24
|
+
tools: [],
|
|
25
|
+
maxTokens: 64,
|
|
26
|
+
reasoning: { mode: "off" },
|
|
27
|
+
});
|
|
28
|
+
const title = clean(resp.text ?? "");
|
|
29
|
+
return title.length > 0 ? title : null;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TokenUsage } from "../types.js";
|
|
2
|
+
import type { LLMUsageTracker } from "../llm/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Fold one run's cumulative usage onto a session baseline, producing the new
|
|
5
|
+
* session-cumulative TokenUsage.
|
|
6
|
+
*
|
|
7
|
+
* The LLM client is recreated per `engine.run()`, so its `getUsage()` totals
|
|
8
|
+
* count only the current run and start from zero each run. To get a true
|
|
9
|
+
* session cumulative we add the run's running total onto the baseline captured
|
|
10
|
+
* at run start (the value persisted from prior runs).
|
|
11
|
+
*
|
|
12
|
+
* Crucially this is `baseline + current`, NOT `baseline += current`: the
|
|
13
|
+
* turn-boundary heartbeat fires many times within one run, each reading the
|
|
14
|
+
* run's growing total. Recomputing `baseline + current` every time is
|
|
15
|
+
* idempotent — it never double-counts — whereas a `+=` would add the running
|
|
16
|
+
* total repeatedly. Feed the folded result back as the baseline only across
|
|
17
|
+
* run boundaries (new client, fresh run total).
|
|
18
|
+
*/
|
|
19
|
+
export declare function foldRunUsage(baseline: TokenUsage, runUsage: LLMUsageTracker): TokenUsage;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fold one run's cumulative usage onto a session baseline, producing the new
|
|
3
|
+
* session-cumulative TokenUsage.
|
|
4
|
+
*
|
|
5
|
+
* The LLM client is recreated per `engine.run()`, so its `getUsage()` totals
|
|
6
|
+
* count only the current run and start from zero each run. To get a true
|
|
7
|
+
* session cumulative we add the run's running total onto the baseline captured
|
|
8
|
+
* at run start (the value persisted from prior runs).
|
|
9
|
+
*
|
|
10
|
+
* Crucially this is `baseline + current`, NOT `baseline += current`: the
|
|
11
|
+
* turn-boundary heartbeat fires many times within one run, each reading the
|
|
12
|
+
* run's growing total. Recomputing `baseline + current` every time is
|
|
13
|
+
* idempotent — it never double-counts — whereas a `+=` would add the running
|
|
14
|
+
* total repeatedly. Feed the folded result back as the baseline only across
|
|
15
|
+
* run boundaries (new client, fresh run total).
|
|
16
|
+
*/
|
|
17
|
+
export function foldRunUsage(baseline, runUsage) {
|
|
18
|
+
return {
|
|
19
|
+
promptTokens: baseline.promptTokens + runUsage.totalPromptTokens,
|
|
20
|
+
completionTokens: baseline.completionTokens + runUsage.totalCompletionTokens,
|
|
21
|
+
totalTokens: baseline.totalTokens + runUsage.totalTokens,
|
|
22
|
+
cacheReadTokens: (baseline.cacheReadTokens ?? 0) + runUsage.totalCacheReadTokens,
|
|
23
|
+
cacheCreationTokens: (baseline.cacheCreationTokens ?? 0) + runUsage.totalCacheCreationTokens,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step-gap steering queue — pure helpers over a per-session list of pending
|
|
3
|
+
* user messages. Each entry carries a stable `id` so the host can (a) match the
|
|
4
|
+
* later `steer_injected` event back to the queued draft it showed in the UI and
|
|
5
|
+
* (b) revoke a still-pending entry via `unsteer` before the turn loop consumes
|
|
6
|
+
* it. Pure + side-effect-free so it unit-tests without the Engine/TurnLoop
|
|
7
|
+
* harness (same rationale as the renderer's queuedInput.ts).
|
|
8
|
+
*/
|
|
9
|
+
export interface SteerItem {
|
|
10
|
+
id: string;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
/** Append a steer entry. Blank text is dropped (returns the list unchanged). */
|
|
14
|
+
export declare function enqueueSteerItem(list: SteerItem[], id: string, text: string): SteerItem[];
|
|
15
|
+
/**
|
|
16
|
+
* Take everything currently queued and clear the list. Returns the drained
|
|
17
|
+
* entries (in order) and the now-empty remainder. The turn loop calls this at
|
|
18
|
+
* each step boundary.
|
|
19
|
+
*/
|
|
20
|
+
export declare function consumeSteerItems(list: SteerItem[]): {
|
|
21
|
+
drained: SteerItem[];
|
|
22
|
+
rest: SteerItem[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Remove a still-pending entry by id (the 撤回 path). Returns the new list and
|
|
26
|
+
* whether anything was removed — `false` means it was already consumed (the
|
|
27
|
+
* host can't take it back; it has already been spliced into the run).
|
|
28
|
+
*/
|
|
29
|
+
export declare function removeSteerItem(list: SteerItem[], id: string): {
|
|
30
|
+
list: SteerItem[];
|
|
31
|
+
removed: boolean;
|
|
32
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Append a steer entry. Blank text is dropped (returns the list unchanged). */
|
|
2
|
+
export function enqueueSteerItem(list, id, text) {
|
|
3
|
+
const t = text?.trim();
|
|
4
|
+
if (!id || !t)
|
|
5
|
+
return list;
|
|
6
|
+
return [...list, { id, text: t }];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Take everything currently queued and clear the list. Returns the drained
|
|
10
|
+
* entries (in order) and the now-empty remainder. The turn loop calls this at
|
|
11
|
+
* each step boundary.
|
|
12
|
+
*/
|
|
13
|
+
export function consumeSteerItems(list) {
|
|
14
|
+
if (list.length === 0)
|
|
15
|
+
return { drained: [], rest: [] };
|
|
16
|
+
return { drained: list, rest: [] };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Remove a still-pending entry by id (the 撤回 path). Returns the new list and
|
|
20
|
+
* whether anything was removed — `false` means it was already consumed (the
|
|
21
|
+
* host can't take it back; it has already been spliced into the run).
|
|
22
|
+
*/
|
|
23
|
+
export function removeSteerItem(list, id) {
|
|
24
|
+
const next = list.filter((item) => item.id !== id);
|
|
25
|
+
return { list: next, removed: next.length !== list.length };
|
|
26
|
+
}
|
|
@@ -17,6 +17,7 @@ export declare class StreamingToolQueue {
|
|
|
17
17
|
private readonly pending;
|
|
18
18
|
private readonly unsafeQueue;
|
|
19
19
|
private readonly callOrder;
|
|
20
|
+
private readonly toolNameById;
|
|
20
21
|
private draining;
|
|
21
22
|
constructor(executor: ToolExecutor);
|
|
22
23
|
/**
|
|
@@ -27,8 +28,19 @@ export declare class StreamingToolQueue {
|
|
|
27
28
|
/**
|
|
28
29
|
* Execute all remaining unsafe tools sequentially, then await all results.
|
|
29
30
|
* Returns results in original enqueue order.
|
|
31
|
+
*
|
|
32
|
+
* A tool's promise can REJECT — not just resolve to an error ToolResult —
|
|
33
|
+
* because permission.handleAsk (and pre_tool_use "ask") throw outside
|
|
34
|
+
* executeSingle's try/catch. We must never let one rejection (a) abort the
|
|
35
|
+
* drain and lose the other tools' results, or (b) leave a hole that surfaces
|
|
36
|
+
* as `undefined` downstream (toolResultToBlock would crash on it). So every
|
|
37
|
+
* await is funneled through toResult(), which converts a thrown value into a
|
|
38
|
+
* synthetic error ToolResult, and any id still missing at the end is filled
|
|
39
|
+
* with one too.
|
|
30
40
|
*/
|
|
31
41
|
drain(): Promise<ToolResult[]>;
|
|
42
|
+
/** Await a tool promise, converting a rejection into an error ToolResult. */
|
|
43
|
+
private toResult;
|
|
32
44
|
/** Number of tools currently enqueued or executing. */
|
|
33
45
|
get size(): number;
|
|
34
46
|
}
|
|
@@ -15,6 +15,7 @@ export class StreamingToolQueue {
|
|
|
15
15
|
pending = new Map();
|
|
16
16
|
unsafeQueue = [];
|
|
17
17
|
callOrder = [];
|
|
18
|
+
toolNameById = new Map();
|
|
18
19
|
draining = false;
|
|
19
20
|
constructor(executor) {
|
|
20
21
|
this.executor = executor;
|
|
@@ -25,9 +26,14 @@ export class StreamingToolQueue {
|
|
|
25
26
|
*/
|
|
26
27
|
enqueue(call) {
|
|
27
28
|
this.callOrder.push(call.id);
|
|
29
|
+
this.toolNameById.set(call.id, call.toolName);
|
|
28
30
|
if (this.executor.isConcurrencySafe(call.toolName)) {
|
|
29
|
-
// Start immediately
|
|
30
|
-
|
|
31
|
+
// Start immediately. Attach a no-op catch so a synchronous/early rejection
|
|
32
|
+
// doesn't surface as an unhandledRejection before drain() awaits it; the
|
|
33
|
+
// real handling (→ error ToolResult) happens in drain()/toResult().
|
|
34
|
+
const p = this.executor.executeSingle(call);
|
|
35
|
+
p.catch(() => { });
|
|
36
|
+
this.pending.set(call.id, p);
|
|
31
37
|
}
|
|
32
38
|
else {
|
|
33
39
|
this.unsafeQueue.push(call);
|
|
@@ -36,23 +42,57 @@ export class StreamingToolQueue {
|
|
|
36
42
|
/**
|
|
37
43
|
* Execute all remaining unsafe tools sequentially, then await all results.
|
|
38
44
|
* Returns results in original enqueue order.
|
|
45
|
+
*
|
|
46
|
+
* A tool's promise can REJECT — not just resolve to an error ToolResult —
|
|
47
|
+
* because permission.handleAsk (and pre_tool_use "ask") throw outside
|
|
48
|
+
* executeSingle's try/catch. We must never let one rejection (a) abort the
|
|
49
|
+
* drain and lose the other tools' results, or (b) leave a hole that surfaces
|
|
50
|
+
* as `undefined` downstream (toolResultToBlock would crash on it). So every
|
|
51
|
+
* await is funneled through toResult(), which converts a thrown value into a
|
|
52
|
+
* synthetic error ToolResult, and any id still missing at the end is filled
|
|
53
|
+
* with one too.
|
|
39
54
|
*/
|
|
40
55
|
async drain() {
|
|
41
56
|
if (this.draining)
|
|
42
57
|
throw new Error("StreamingToolQueue already draining");
|
|
43
58
|
this.draining = true;
|
|
44
|
-
|
|
59
|
+
const resultMap = new Map();
|
|
60
|
+
// Execute unsafe tools sequentially. A rejection here must not stop the
|
|
61
|
+
// remaining unsafe tools from running.
|
|
45
62
|
for (const call of this.unsafeQueue) {
|
|
46
|
-
|
|
47
|
-
|
|
63
|
+
const p = this.executor.executeSingle(call);
|
|
64
|
+
this.pending.set(call.id, p);
|
|
65
|
+
resultMap.set(call.id, await this.toResult(call.id, call.toolName, p));
|
|
48
66
|
}
|
|
49
|
-
// Await all results
|
|
50
|
-
const resultMap = new Map();
|
|
67
|
+
// Await all results (concurrency-safe tools started at enqueue time).
|
|
51
68
|
for (const [id, promise] of this.pending) {
|
|
52
|
-
resultMap.
|
|
69
|
+
if (resultMap.has(id))
|
|
70
|
+
continue; // already drained above
|
|
71
|
+
const toolName = this.toolNameById.get(id) ?? "unknown";
|
|
72
|
+
resultMap.set(id, await this.toResult(id, toolName, promise));
|
|
73
|
+
}
|
|
74
|
+
// Return in original order, with a synthetic error for any id that somehow
|
|
75
|
+
// never produced a result (defensive — should not happen now).
|
|
76
|
+
return this.callOrder.map((id) => resultMap.get(id) ?? {
|
|
77
|
+
id,
|
|
78
|
+
toolName: this.toolNameById.get(id) ?? "unknown",
|
|
79
|
+
error: "Tool execution produced no result.",
|
|
80
|
+
isError: true,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Await a tool promise, converting a rejection into an error ToolResult. */
|
|
84
|
+
async toResult(id, toolName, p) {
|
|
85
|
+
try {
|
|
86
|
+
return await p;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
return {
|
|
90
|
+
id,
|
|
91
|
+
toolName,
|
|
92
|
+
error: err instanceof Error ? err.message : String(err),
|
|
93
|
+
isError: true,
|
|
94
|
+
};
|
|
53
95
|
}
|
|
54
|
-
// Return in original order
|
|
55
|
-
return this.callOrder.map((id) => resultMap.get(id));
|
|
56
96
|
}
|
|
57
97
|
/** Number of tools currently enqueued or executing. */
|
|
58
98
|
get size() {
|