@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
|
@@ -32,26 +32,85 @@
|
|
|
32
32
|
import { Engine } from "../engine/engine.js";
|
|
33
33
|
import { EngineRuntime } from "../engine/runtime.js";
|
|
34
34
|
import { ChatSessionManager } from "../protocol/chat-session-manager.js";
|
|
35
|
+
import { SessionManager } from "../session/session-manager.js";
|
|
36
|
+
import { validateSettings } from "../settings/schema.js";
|
|
35
37
|
import { AgentServer } from "../protocol/server.js";
|
|
36
38
|
import { StdioTransport } from "../protocol/transport.js";
|
|
37
|
-
import {
|
|
39
|
+
import { createNotification } from "../protocol/types.js";
|
|
40
|
+
import { setCronChangedSink } from "../tool-system/builtin/cron.js";
|
|
41
|
+
import { SettingsManager, noRepoDir } from "../settings/manager.js";
|
|
42
|
+
import { personalizationFrom } from "../settings/personalization.js";
|
|
38
43
|
import { MCPManager } from "../tool-system/mcp-manager.js";
|
|
44
|
+
import { mergePluginMcpServers } from "../plugins/installer/loadPluginMcp.js";
|
|
45
|
+
import { computeEffectiveDisabledLists } from "../capability-control/disabled-lists.js";
|
|
39
46
|
import { CostTracker } from "../cost-tracker.js";
|
|
47
|
+
import { installGracefulShutdown } from "./graceful-shutdown.js";
|
|
48
|
+
import { backgroundShellManager } from "../runtime/background-shell.js";
|
|
49
|
+
import { logger } from "../logging/logger.js";
|
|
50
|
+
import { cronScheduler } from "../automation/scheduler.js";
|
|
51
|
+
import { CronStore, defaultCronStorePath } from "../automation/store.js";
|
|
52
|
+
import { resolveLLMConfigForTag } from "../engine/resolve-llm-config.js";
|
|
53
|
+
/**
|
|
54
|
+
* Resolve per-session agent config: protocol slice overrides win, else fall
|
|
55
|
+
* back to disk settings.agent.*. Fixes the bug where settings.agent.* never
|
|
56
|
+
* reached session engines (slice arrived with only permissionMode+cwd).
|
|
57
|
+
*/
|
|
58
|
+
export function resolveSessionAgentConfig(slice, settings) {
|
|
59
|
+
return {
|
|
60
|
+
preset: slice.preset ?? settings.agent.preset,
|
|
61
|
+
customSystemPrompt: slice.customSystemPrompt ?? settings.agent.customSystemPrompt,
|
|
62
|
+
appendSystemPrompt: slice.appendSystemPrompt ?? settings.agent.appendSystemPrompt,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Resolve a session's effective cwd. A protocol slice with an explicit cwd
|
|
67
|
+
* points the session at that project; a slice WITHOUT a cwd is a no-repo
|
|
68
|
+
* "纯聊天" session (the renderer omits cwd when no project is selected) and must
|
|
69
|
+
* land in the no-repo sandbox (~/.code-shell/no-repo) — NOT the worker's boot
|
|
70
|
+
* cwd.
|
|
71
|
+
*
|
|
72
|
+
* Why not the boot cwd: this stdio worker is long-lived and reused across
|
|
73
|
+
* sessions/projects, so its boot cwd is whatever project first spawned it.
|
|
74
|
+
* Inheriting it for a no-repo chat would (a) silently run the chat against a
|
|
75
|
+
* stale, unrelated project's files and (b) defeat the no-repo skill/plugin
|
|
76
|
+
* whitelist inversion (which only fires when cwd === noRepoDir).
|
|
77
|
+
*/
|
|
78
|
+
export function resolveSessionCwd(slice) {
|
|
79
|
+
return slice.cwd ?? noRepoDir();
|
|
80
|
+
}
|
|
40
81
|
// ─── Read base config from environment / settings ─────────────────
|
|
41
82
|
const cwd = process.env.AGENT_CWD ?? process.cwd();
|
|
42
83
|
// Load settings once to derive llm config for the seed engine.
|
|
43
84
|
// Desktop is a host application: read the full disk hierarchy (incl. the
|
|
44
85
|
// user's ~/.code-shell). The SDK default 'project' would skip user config.
|
|
45
86
|
const settingsManager = new SettingsManager(cwd, "full");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
// Bootstrap load must NOT crash the worker on a schema-invalid (but JSON-valid)
|
|
88
|
+
// settings file: a hand-edited settings.json with e.g. `permissions.defaultMode:
|
|
89
|
+
// "ask"` or `env.FOO: 123` makes SettingsSchema.parse throw a ZodError at module
|
|
90
|
+
// top level, which the desktop/mobile host sees as "connection lost" / a
|
|
91
|
+
// nonzero-exit worker. Fall back to schema defaults and print a readable,
|
|
92
|
+
// truncated reason so the user can fix the file (freshSettings() applies the
|
|
93
|
+
// same best-effort contract per session once the worker is up).
|
|
94
|
+
let settings;
|
|
95
|
+
try {
|
|
96
|
+
settings = settingsManager.get();
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
const reason = (err instanceof Error ? err.message : String(err)).slice(0, 2000);
|
|
100
|
+
console.error(`[agent-server] settings.json 校验失败,已回退到默认配置(请修正后重启):\n${reason}`);
|
|
101
|
+
settings = validateSettings({});
|
|
102
|
+
}
|
|
103
|
+
// LLMConfig is pure model identity now — only the bare identity fields go here.
|
|
104
|
+
// temperature/imageDetail/timeout/retryMaxAttempts are ClientDefaults, derived
|
|
105
|
+
// inside Engine.populateModelPoolFromSettings (temperature is a ClientDefaults
|
|
106
|
+
// knob; imageDetail from settings.images.detail).
|
|
107
|
+
const seedLlm = resolveLLMConfigForTag(settings, "text", settings.defaults?.text);
|
|
108
|
+
if (!seedLlm) {
|
|
109
|
+
console.error(`[agent-server] 没有可用的文本模型连接(defaults.text=${settings.defaults?.text ?? "未设置"})。` +
|
|
110
|
+
`请在「连接」页添加并填写凭证。`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
const llmConfig = seedLlm;
|
|
55
114
|
// ─── Step 1: seed engine — populates model pool from settings ─────
|
|
56
115
|
const seedEngine = new Engine({
|
|
57
116
|
llm: llmConfig,
|
|
@@ -62,9 +121,12 @@ const seedEngine = new Engine({
|
|
|
62
121
|
// ─── Step 2: extract shared resources ────────────────────────────
|
|
63
122
|
const modelPool = seedEngine.getModelPool();
|
|
64
123
|
const toolRegistry = seedEngine.getToolRegistry();
|
|
65
|
-
// Capture the seed engine's resolved llmConfig
|
|
66
|
-
//
|
|
124
|
+
// Capture the seed engine's resolved llmConfig + clientDefaults
|
|
125
|
+
// (post-populateModelPoolFromSettings). Session engines inherit defaults so
|
|
126
|
+
// the temperature ClientDefault / images.detail apply uniformly without each
|
|
127
|
+
// factory call re-reading settings.
|
|
67
128
|
const resolvedLlmConfig = seedEngine.getConfig().llm;
|
|
129
|
+
const resolvedClientDefaults = seedEngine.getConfig().clientDefaults;
|
|
68
130
|
// Reuse the same SettingsManager instance for the runtime instead of constructing
|
|
69
131
|
// a fresh one — avoids duplication and keeps the pattern cleaner.
|
|
70
132
|
const sharedSettings = settingsManager;
|
|
@@ -90,32 +152,163 @@ const runtime = new EngineRuntime({
|
|
|
90
152
|
costTracker,
|
|
91
153
|
});
|
|
92
154
|
// ─── Step 4: ChatSessionManager ──────────────────────────────────
|
|
155
|
+
// Re-read settings from disk on each new session so edits the user makes in
|
|
156
|
+
// the settings UI take effect on the NEXT session without restarting the
|
|
157
|
+
// worker (the `settings` bootstrap snapshot above is read once at process
|
|
158
|
+
// start and would otherwise pin every session to the launch-time values).
|
|
159
|
+
// This is the "pull on session creation" tier — mirrors how Codex's new
|
|
160
|
+
// threads call load_with_overrides() per start. (Hot-reloading ALREADY-RUNNING
|
|
161
|
+
// sessions is a separate, heavier push mechanism, intentionally out of scope.)
|
|
162
|
+
// Best-effort: if a freshly-edited settings.json is malformed, fall back to the
|
|
163
|
+
// last-known-good bootstrap snapshot rather than failing to create a session.
|
|
164
|
+
function freshSettings() {
|
|
165
|
+
try {
|
|
166
|
+
return settingsManager.load();
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return settings;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
93
172
|
const chatManager = new ChatSessionManager({
|
|
94
173
|
runtime,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
174
|
+
// resolvedLlmConfig is the bootstrap-time snapshot. When the user
|
|
175
|
+
// hot-switches models via configure() the modelPool.activeKey moves
|
|
176
|
+
// ahead of it, so newly-created sessions must re-resolve from the pool
|
|
177
|
+
// each time the factory fires; fall back to the snapshot only when the
|
|
178
|
+
// pool can't resolve (no active key — shouldn't happen in practice).
|
|
179
|
+
engineFactory: (slice) => {
|
|
180
|
+
// Effective cwd for THIS session: explicit slice.cwd → that project; absent
|
|
181
|
+
// → the no-repo sandbox (NOT the worker's stale boot cwd). See
|
|
182
|
+
// resolveSessionCwd for the full rationale.
|
|
183
|
+
const sessionCwd = resolveSessionCwd(slice);
|
|
184
|
+
// Read settings for THIS session's cwd, not the worker's boot cwd. A single
|
|
185
|
+
// worker serves many projects; the boot-cwd `freshSettings()` snapshot pins
|
|
186
|
+
// every session to the first project's project-layer settings, so project
|
|
187
|
+
// `mcpServers` / `agent.*` / permissions from the boot project would leak
|
|
188
|
+
// into (and shadow) other projects' sessions. A per-session SettingsManager
|
|
189
|
+
// still reads the full hierarchy (user ~/.code-shell + THIS project's
|
|
190
|
+
// .code-shell), keeping user-global settings while picking up the correct
|
|
191
|
+
// project overlay. Falls back to the boot snapshot if this project's file is
|
|
192
|
+
// malformed (same best-effort contract as freshSettings()).
|
|
193
|
+
const sessionSettingsManager = new SettingsManager(sessionCwd, "full");
|
|
194
|
+
let live;
|
|
195
|
+
try {
|
|
196
|
+
live = sessionSettingsManager.load();
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
live = freshSettings();
|
|
200
|
+
}
|
|
201
|
+
// Fold project capabilityOverrides over the global disabledPlugins before
|
|
202
|
+
// the MCP merge — a plugin force-enabled in 能力总览 (project "on") must
|
|
203
|
+
// contribute its MCP servers even while globally disabled, and vice versa.
|
|
204
|
+
// Raw `live.disabledPlugins` alone ignored the project layer.
|
|
205
|
+
const { disabledPlugins } = computeEffectiveDisabledLists(sessionSettingsManager, sessionCwd);
|
|
206
|
+
return new Engine({
|
|
207
|
+
llm: runtime.modelPool.resolveLLMConfig() ?? resolvedLlmConfig,
|
|
208
|
+
// Inherit the seed engine's resolved clientDefaults so every session
|
|
209
|
+
// engine sees the user's temperature/imageDetail without each factory
|
|
210
|
+
// call re-running populateModelPoolFromSettings.
|
|
211
|
+
clientDefaults: resolvedClientDefaults,
|
|
212
|
+
// sessionCwd resolves slice.cwd → no-repo sandbox (never the stale boot
|
|
213
|
+
// cwd). The slice.cwd spread below is now redundant with this but kept
|
|
214
|
+
// for clarity / explicitness.
|
|
215
|
+
cwd: sessionCwd,
|
|
216
|
+
runtime,
|
|
217
|
+
// This stdio worker exists only to serve the desktop app, so every
|
|
218
|
+
// session it creates is a desktop-origin session.
|
|
219
|
+
origin: "desktop",
|
|
220
|
+
// Inherit full scope so spawned subagents read user config too.
|
|
221
|
+
settingsScope: "full",
|
|
222
|
+
// MCP servers from settings — the worker reads the full disk
|
|
223
|
+
// hierarchy at bootstrap (incl. ~/.code-shell). Without this the
|
|
224
|
+
// factory-built session Engine has config.mcpServers === undefined,
|
|
225
|
+
// so Engine.run()'s connectAll() guard never fires and no MCP server
|
|
226
|
+
// (stdio OR url) is ever connected. The shared runtime.mcpPool means
|
|
227
|
+
// the first session to connect populates connections for the worker.
|
|
228
|
+
// Plugin-provided MCP servers (mcp-servers.json in installed plugins)
|
|
229
|
+
// are merged in here so the model can actually call them.
|
|
230
|
+
mcpServers: mergePluginMcpServers(live.mcpServers ?? {}, disabledPlugins, live.mcpServerOverrides ?? {}),
|
|
231
|
+
// Per-session overrides from the protocol request; fall back to
|
|
232
|
+
// settings.agent.* so the user's 个性化 settings actually apply
|
|
233
|
+
// (previously slice arrived with only permissionMode+cwd, so these
|
|
234
|
+
// were always undefined — the 自定义指令 box never took effect).
|
|
235
|
+
// `live` is re-read from disk per session, so settings edits take effect
|
|
236
|
+
// on the next session without a worker restart.
|
|
237
|
+
permissionMode: slice.permissionMode,
|
|
238
|
+
// Workspace trust for this project (asserted by desktop main's
|
|
239
|
+
// trust-store, threaded via RunParams). When false, core strips the
|
|
240
|
+
// project's dangerous .code-shell settings (permissions/env/hooks/…).
|
|
241
|
+
projectTrusted: slice.projectTrusted,
|
|
242
|
+
...resolveSessionAgentConfig(slice, live),
|
|
243
|
+
// Personalization + instruction compat come from disk settings only
|
|
244
|
+
// (not per-request protocol overrides), so they read straight from
|
|
245
|
+
// `live` here rather than through the slice. Shared helper keeps the
|
|
246
|
+
// three fields wired identically across desktop / TUI / TCP.
|
|
247
|
+
...personalizationFrom(live.agent),
|
|
248
|
+
maxTurns: slice.maxTurns,
|
|
249
|
+
maxContextTokens: slice.maxContextTokens,
|
|
250
|
+
// cwd already set to sessionCwd above (slice.cwd → no-repo fallback).
|
|
251
|
+
});
|
|
252
|
+
},
|
|
110
253
|
maxSessions: 16,
|
|
111
254
|
idleTtlMs: 30 * 60 * 1000,
|
|
112
255
|
});
|
|
113
256
|
chatManager.startIdleSweeper();
|
|
257
|
+
// ─── Cron persistence ────────────────────────────────────────────
|
|
258
|
+
// The agent's CronCreate/Delete tools operate on the shared cronScheduler
|
|
259
|
+
// singleton. In the desktop host this worker is a SEPARATE process from the
|
|
260
|
+
// Electron main process that owns the live scheduler, so the only way a
|
|
261
|
+
// chat-created job reaches the automation UI is through the shared on-disk
|
|
262
|
+
// store (~/.code-shell/cron.json). Give this process's scheduler that store so
|
|
263
|
+
// CronCreate persists; loadJobs() so the agent can list/modify existing jobs.
|
|
264
|
+
// Execution is DISABLED here — this worker must not run scheduled jobs (the
|
|
265
|
+
// main process owns execution); persistence is its only cron role. Without
|
|
266
|
+
// this, loadJobs()/CronCreate would arm timers in this process too, double-
|
|
267
|
+
// running jobs and corrupting run stats.
|
|
268
|
+
cronScheduler.setStore(new CronStore(defaultCronStorePath()));
|
|
269
|
+
cronScheduler.setExecutionEnabled(false);
|
|
270
|
+
cronScheduler.loadJobs();
|
|
114
271
|
// ─── Step 5: AgentServer over stdio ──────────────────────────────
|
|
115
272
|
const stdioTransport = new StdioTransport(process.stdin, process.stdout);
|
|
116
|
-
|
|
273
|
+
// Cron jobs are persisted by this worker but only main arms/executes their
|
|
274
|
+
// timers (this worker keeps setExecutionEnabled(false) above). When an AI tool
|
|
275
|
+
// creates/deletes a cron job here, notify main over stdio so it reloads the
|
|
276
|
+
// store and (re)arms its scheduler — otherwise AI-created jobs never fire.
|
|
277
|
+
setCronChangedSink(() => {
|
|
278
|
+
stdioTransport.send(createNotification("agent/cronChanged", {}));
|
|
279
|
+
});
|
|
280
|
+
// Disk-only active-goal reader for agent/goalGet. In worker mode there is no
|
|
281
|
+
// legacyEngine, and reopening a session after restart doesn't create a live
|
|
282
|
+
// ChatSession (that only happens on a send), so chatManager.get() misses. This
|
|
283
|
+
// reads the same ~/.code-shell/sessions/<id>/state.json every Engine writes, so
|
|
284
|
+
// the goal block re-surfaces on load ("goal 还在但页面不显示" fix).
|
|
285
|
+
const goalDiskReader = new SessionManager();
|
|
286
|
+
const agentServer = new AgentServer({
|
|
117
287
|
chatManager,
|
|
118
288
|
transport: stdioTransport,
|
|
289
|
+
// Config hot-reload (layer 2) reads disk through the SAME closure the
|
|
290
|
+
// engineFactory uses for new sessions, so a reloaded running session and a
|
|
291
|
+
// newly-created session converge on identical disk config (no divergence).
|
|
292
|
+
settingsReader: freshSettings,
|
|
293
|
+
readActiveGoalFromDisk: (sessionId) => goalDiskReader.readActiveGoal(sessionId),
|
|
119
294
|
});
|
|
295
|
+
// Clean up on termination signals. Without this, SIGTERM (parent kill),
|
|
296
|
+
// SIGINT (Ctrl+C), or SIGHUP would drop the process without closing sessions,
|
|
297
|
+
// clearing the idle sweeper, or terminating child MCP/tool processes.
|
|
298
|
+
// AgentServer.close() → chatManager.closeAll() also reaps background shells.
|
|
299
|
+
installGracefulShutdown(agentServer);
|
|
300
|
+
// Reap orphaned background shells left by a previously-crashed worker
|
|
301
|
+
// (design §难点1): a worker crash detaches its `npm run dev` children, which
|
|
302
|
+
// keep holding ports. Scanning pidfiles on boot lists still-alive groups as
|
|
303
|
+
// `orphaned` (so ListShells/KillShell can clean them) and deletes stale ones.
|
|
304
|
+
try {
|
|
305
|
+
const orphans = backgroundShellManager.reapOrphansFromPidfiles();
|
|
306
|
+
if (orphans.length > 0) {
|
|
307
|
+
logger.info("bg_shell.orphans_found", { count: orphans.length });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
/* best-effort — never block worker startup on this */
|
|
312
|
+
}
|
|
120
313
|
// Keep the process alive — readline in StdioTransport holds the event loop.
|
|
121
314
|
// On parent close / stdin EOF the process will exit naturally.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-server-tcp — headless server entry point over TCP (Phase 6).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors agent-server-stdio.ts (same EngineRuntime + ChatSessionManager +
|
|
5
|
+
* AgentServer bootstrap), but listens on a TCP socket instead of stdio and
|
|
6
|
+
* also starts the in-process automation scheduler so a deployed server runs
|
|
7
|
+
* scheduled jobs 7x24 with no Electron/GUI.
|
|
8
|
+
*
|
|
9
|
+
* The automation module is the SAME zero-env-dependency module the desktop
|
|
10
|
+
* loads (startAutomation) — this is the "thin server host" the plan's D2
|
|
11
|
+
* describes: one module, two hosts.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* AGENT_TCP_PORT=4321 node dist/cli/agent-server-tcp.js
|
|
15
|
+
*
|
|
16
|
+
* v1 SECURITY: binds 127.0.0.1 by default and has NO authentication. Do not
|
|
17
|
+
* expose to a public interface without adding auth (token/TLS). Use SSH
|
|
18
|
+
* tunneling for remote access in v1.
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-server-tcp — headless server entry point over TCP (Phase 6).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors agent-server-stdio.ts (same EngineRuntime + ChatSessionManager +
|
|
5
|
+
* AgentServer bootstrap), but listens on a TCP socket instead of stdio and
|
|
6
|
+
* also starts the in-process automation scheduler so a deployed server runs
|
|
7
|
+
* scheduled jobs 7x24 with no Electron/GUI.
|
|
8
|
+
*
|
|
9
|
+
* The automation module is the SAME zero-env-dependency module the desktop
|
|
10
|
+
* loads (startAutomation) — this is the "thin server host" the plan's D2
|
|
11
|
+
* describes: one module, two hosts.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* AGENT_TCP_PORT=4321 node dist/cli/agent-server-tcp.js
|
|
15
|
+
*
|
|
16
|
+
* v1 SECURITY: binds 127.0.0.1 by default and has NO authentication. Do not
|
|
17
|
+
* expose to a public interface without adding auth (token/TLS). Use SSH
|
|
18
|
+
* tunneling for remote access in v1.
|
|
19
|
+
*/
|
|
20
|
+
import { Engine } from "../engine/engine.js";
|
|
21
|
+
import { EngineRuntime } from "../engine/runtime.js";
|
|
22
|
+
import { ChatSessionManager } from "../protocol/chat-session-manager.js";
|
|
23
|
+
import { AgentServer } from "../protocol/server.js";
|
|
24
|
+
import { listenTcp } from "../protocol/tcp-transport.js";
|
|
25
|
+
import { SettingsManager } from "../settings/manager.js";
|
|
26
|
+
import { computeEffectiveDisabledLists } from "../capability-control/disabled-lists.js";
|
|
27
|
+
import { personalizationFrom } from "../settings/personalization.js";
|
|
28
|
+
import { MCPManager } from "../tool-system/mcp-manager.js";
|
|
29
|
+
import { mergePluginMcpServers } from "../plugins/installer/loadPluginMcp.js";
|
|
30
|
+
import { CostTracker } from "../cost-tracker.js";
|
|
31
|
+
import { HeadlessApprovalBackend } from "../tool-system/permission.js";
|
|
32
|
+
import { createRunManager } from "../run/factory.js";
|
|
33
|
+
import { startAutomation } from "../automation/index.js";
|
|
34
|
+
import { CronStore, defaultCronStorePath } from "../automation/store.js";
|
|
35
|
+
import { resolveLLMConfigForTag } from "../engine/resolve-llm-config.js";
|
|
36
|
+
const cwd = process.env.AGENT_CWD ?? process.cwd();
|
|
37
|
+
const port = Number(process.env.AGENT_TCP_PORT ?? "4321");
|
|
38
|
+
const host = process.env.AGENT_TCP_HOST ?? "127.0.0.1";
|
|
39
|
+
const settingsManager = new SettingsManager(cwd, "full");
|
|
40
|
+
// Read once at startup and reuse for every session (see engineFactory below).
|
|
41
|
+
// This is intentional for the TCP host: it's a headless long-running server,
|
|
42
|
+
// so config changes — including `mcpServers` — take effect on restart, not
|
|
43
|
+
// mid-session. (The stdio host re-reads per session via freshSettings(); the
|
|
44
|
+
// difference is by design, not a bug. Assessment §4.8.)
|
|
45
|
+
const settings = settingsManager.get();
|
|
46
|
+
const seedLlm = resolveLLMConfigForTag(settings, "text", settings.defaults?.text);
|
|
47
|
+
if (!seedLlm) {
|
|
48
|
+
console.error(`[agent-server] 没有可用的文本模型连接(defaults.text=${settings.defaults?.text ?? "未设置"})。` +
|
|
49
|
+
`请在「连接」页添加并填写凭证。`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
const llmConfig = seedLlm;
|
|
53
|
+
// ── Shared runtime (same bootstrap as stdio) ─────────────────────
|
|
54
|
+
const seedEngine = new Engine({ llm: llmConfig, cwd, settingsScope: "full" });
|
|
55
|
+
const modelPool = seedEngine.getModelPool();
|
|
56
|
+
const toolRegistry = seedEngine.getToolRegistry();
|
|
57
|
+
const resolvedLlmConfig = seedEngine.getConfig().llm;
|
|
58
|
+
const resolvedClientDefaults = seedEngine.getConfig().clientDefaults;
|
|
59
|
+
const mcpPool = new MCPManager(toolRegistry);
|
|
60
|
+
const costTracker = new CostTracker();
|
|
61
|
+
const runtime = new EngineRuntime({
|
|
62
|
+
modelPool,
|
|
63
|
+
toolRegistry,
|
|
64
|
+
settings: settingsManager,
|
|
65
|
+
mcpPool,
|
|
66
|
+
costTracker,
|
|
67
|
+
});
|
|
68
|
+
const chatManager = new ChatSessionManager({
|
|
69
|
+
runtime,
|
|
70
|
+
engineFactory: (slice) => {
|
|
71
|
+
// Fold project capabilityOverrides over the global disabledPlugins for
|
|
72
|
+
// the MCP merge (能力总览 project "on" must override global off) — same
|
|
73
|
+
// contract as the stdio host's factory.
|
|
74
|
+
const sessionCwd = slice.cwd ?? cwd;
|
|
75
|
+
const { disabledPlugins } = computeEffectiveDisabledLists(new SettingsManager(sessionCwd, "full"), sessionCwd);
|
|
76
|
+
return new Engine({
|
|
77
|
+
llm: runtime.modelPool.resolveLLMConfig() ?? resolvedLlmConfig,
|
|
78
|
+
clientDefaults: resolvedClientDefaults,
|
|
79
|
+
cwd,
|
|
80
|
+
runtime,
|
|
81
|
+
settingsScope: "full",
|
|
82
|
+
mcpServers: mergePluginMcpServers(settings.mcpServers ?? {}, disabledPlugins, settings.mcpServerOverrides ?? {}),
|
|
83
|
+
permissionMode: slice.permissionMode,
|
|
84
|
+
preset: slice.preset,
|
|
85
|
+
customSystemPrompt: slice.customSystemPrompt,
|
|
86
|
+
appendSystemPrompt: slice.appendSystemPrompt,
|
|
87
|
+
// Personalization + instruction compat come from disk settings only
|
|
88
|
+
// (not per-request slice overrides) — same disk-only contract as the
|
|
89
|
+
// stdio host. Shared helper keeps the three fields wired identically.
|
|
90
|
+
...personalizationFrom(settings.agent),
|
|
91
|
+
maxTurns: slice.maxTurns,
|
|
92
|
+
maxContextTokens: slice.maxContextTokens,
|
|
93
|
+
...(slice.cwd ? { cwd: slice.cwd } : {}),
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
maxSessions: 16,
|
|
97
|
+
idleTtlMs: 30 * 60 * 1000,
|
|
98
|
+
});
|
|
99
|
+
chatManager.startIdleSweeper();
|
|
100
|
+
// ── Automation (same module the desktop loads) ──────────────────
|
|
101
|
+
// Read-only by default until write tiers are configured per job. Runs land in
|
|
102
|
+
// the RunStore so history is queryable.
|
|
103
|
+
const automationRunManager = createRunManager({
|
|
104
|
+
llm: resolvedLlmConfig,
|
|
105
|
+
cwd,
|
|
106
|
+
permissionMode: "default",
|
|
107
|
+
approvalBackend: new HeadlessApprovalBackend("approve-read-only"),
|
|
108
|
+
});
|
|
109
|
+
const automation = startAutomation({
|
|
110
|
+
store: new CronStore(defaultCronStorePath()),
|
|
111
|
+
runManager: automationRunManager,
|
|
112
|
+
});
|
|
113
|
+
// ── Serve over TCP ──────────────────────────────────────────────
|
|
114
|
+
// One AgentServer per accepted connection, all sharing the same chatManager.
|
|
115
|
+
const servers = new Set();
|
|
116
|
+
listenTcp({ port, host }, (transport) => {
|
|
117
|
+
const server = new AgentServer({ chatManager, transport });
|
|
118
|
+
servers.add(server);
|
|
119
|
+
})
|
|
120
|
+
.then((listener) => {
|
|
121
|
+
process.stderr.write(`[code-shell] automation server listening on ${host}:${listener.port}\n`);
|
|
122
|
+
const shutdown = () => {
|
|
123
|
+
automation.stop();
|
|
124
|
+
for (const s of servers)
|
|
125
|
+
s.close();
|
|
126
|
+
void listener.close().then(() => process.exit(0));
|
|
127
|
+
};
|
|
128
|
+
process.on("SIGTERM", shutdown);
|
|
129
|
+
process.on("SIGINT", shutdown);
|
|
130
|
+
})
|
|
131
|
+
.catch((err) => {
|
|
132
|
+
process.stderr.write(`[code-shell] failed to start automation server: ${String(err)}\n`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Minimal surface we need from a server to shut it down cleanly. */
|
|
2
|
+
interface Closable {
|
|
3
|
+
close(): void;
|
|
4
|
+
}
|
|
5
|
+
/** Minimal surface we need from `process` (injectable for tests). */
|
|
6
|
+
interface ProcLike {
|
|
7
|
+
on(event: string, listener: (...args: unknown[]) => void): unknown;
|
|
8
|
+
exit(code?: number): void;
|
|
9
|
+
}
|
|
10
|
+
export interface GracefulShutdownOptions {
|
|
11
|
+
/** Defaults to the real `process`. */
|
|
12
|
+
proc?: ProcLike;
|
|
13
|
+
/** Signals to handle. Defaults to SIGTERM, SIGINT, SIGHUP. */
|
|
14
|
+
signals?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Register signal handlers that cleanly shut down a long-lived server before
|
|
18
|
+
* the process exits. Without this, SIGTERM/SIGINT (Ctrl+C)/SIGHUP terminate
|
|
19
|
+
* the process immediately, leaking the idle sweeper interval, open sessions,
|
|
20
|
+
* pending approvals, and child processes (MCP servers, tools).
|
|
21
|
+
*
|
|
22
|
+
* Idempotent: the first signal runs close() exactly once; later signals (or a
|
|
23
|
+
* second handler firing) are ignored. A throwing close() is swallowed so the
|
|
24
|
+
* process still exits.
|
|
25
|
+
*/
|
|
26
|
+
export declare function installGracefulShutdown(server: Closable, options?: GracefulShutdownOptions): void;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register signal handlers that cleanly shut down a long-lived server before
|
|
3
|
+
* the process exits. Without this, SIGTERM/SIGINT (Ctrl+C)/SIGHUP terminate
|
|
4
|
+
* the process immediately, leaking the idle sweeper interval, open sessions,
|
|
5
|
+
* pending approvals, and child processes (MCP servers, tools).
|
|
6
|
+
*
|
|
7
|
+
* Idempotent: the first signal runs close() exactly once; later signals (or a
|
|
8
|
+
* second handler firing) are ignored. A throwing close() is swallowed so the
|
|
9
|
+
* process still exits.
|
|
10
|
+
*/
|
|
11
|
+
export function installGracefulShutdown(server, options = {}) {
|
|
12
|
+
const proc = options.proc ?? globalThis.process;
|
|
13
|
+
const signals = options.signals ?? ["SIGTERM", "SIGINT", "SIGHUP"];
|
|
14
|
+
let shuttingDown = false;
|
|
15
|
+
const shutdown = () => {
|
|
16
|
+
if (shuttingDown)
|
|
17
|
+
return;
|
|
18
|
+
shuttingDown = true;
|
|
19
|
+
try {
|
|
20
|
+
server.close();
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Best-effort cleanup — never block exit on a close() failure.
|
|
24
|
+
}
|
|
25
|
+
proc.exit(0);
|
|
26
|
+
};
|
|
27
|
+
for (const sig of signals) {
|
|
28
|
+
proc.on(sig, shutdown);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -16,6 +16,25 @@ import type { Message } from "../types.js";
|
|
|
16
16
|
* Uses per-block-type estimation with 33% overhead padding.
|
|
17
17
|
*/
|
|
18
18
|
export declare function estimateTokens(messages: Message[]): number;
|
|
19
|
+
/**
|
|
20
|
+
* Reconcile user-supplied compaction ratios into a safe ordering.
|
|
21
|
+
*
|
|
22
|
+
* The three tiers must satisfy `floor < compact < summarize` or the manager
|
|
23
|
+
* fires them in the wrong order (e.g. an emergency window-compact before the
|
|
24
|
+
* cheaper summary). Users edit these freely in settings.json, so we clamp
|
|
25
|
+
* rather than trust: summarize is pulled up to at least compact, floor is
|
|
26
|
+
* pushed down to at most compact. Absent fields are left undefined so the
|
|
27
|
+
* ContextManager keeps its own default for them.
|
|
28
|
+
*/
|
|
29
|
+
export declare function clampContextRatios(input: {
|
|
30
|
+
compactAtRatio?: number;
|
|
31
|
+
summarizeAtRatio?: number;
|
|
32
|
+
microcompactFloorRatio?: number;
|
|
33
|
+
}): {
|
|
34
|
+
compactAtRatio?: number;
|
|
35
|
+
summarizeAtRatio?: number;
|
|
36
|
+
microcompactFloorRatio?: number;
|
|
37
|
+
};
|
|
19
38
|
/**
|
|
20
39
|
* Expand a slice start-index backwards so that every tool_result in the
|
|
21
40
|
* kept range has its corresponding tool_use in the kept range too.
|
|
@@ -74,6 +93,43 @@ export interface MicrocompactOptions {
|
|
|
74
93
|
* forced into blind re-Reads (which then trip the Investigation guard).
|
|
75
94
|
*/
|
|
76
95
|
export declare function microcompact(messages: Message[], options?: MicrocompactOptions): Message[];
|
|
96
|
+
export interface DedupeFileReadsResult {
|
|
97
|
+
messages: Message[];
|
|
98
|
+
/** How many stale Read results were cleared. */
|
|
99
|
+
clearedCount: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Content-aware dedup: when the SAME file is Read more than once, every Read
|
|
103
|
+
* result except the most recent is stale — the file's current state is in the
|
|
104
|
+
* latest read. Clear the older ones (replace with a fingerprint pointing at
|
|
105
|
+
* the newer read) regardless of the recency window or pressure floor, because
|
|
106
|
+
* this is pure waste removal, not lossy compaction: the model never needs two
|
|
107
|
+
* copies of the same file.
|
|
108
|
+
*
|
|
109
|
+
* Distinct from microcompact (which is recency-gated and pressure-gated): a
|
|
110
|
+
* file Read 3 times in the last 3 turns keeps 3 full copies under microcompact
|
|
111
|
+
* but only the newest under this pass. Zero-cost and always safe to run, so the
|
|
112
|
+
* ContextManager calls it as an early tier.
|
|
113
|
+
*
|
|
114
|
+
* Only `Read` is deduped (its result is exactly the file content). Edit/Write
|
|
115
|
+
* results are diffs/confirmations, not full snapshots, so they're left alone.
|
|
116
|
+
*/
|
|
117
|
+
export declare function dedupeFileReads(messages: Message[]): DedupeFileReadsResult;
|
|
118
|
+
/**
|
|
119
|
+
* Observation masking for browser_observe(snapshot) results (the research's
|
|
120
|
+
* highest-leverage browser-token saving: a page snapshot is large and only the
|
|
121
|
+
* LATEST one matters for the next decision; older ones are stale element lists).
|
|
122
|
+
* Keep the most recent snapshot result verbatim; replace every earlier one with
|
|
123
|
+
* a one-line placeholder. Deterministic — no LLM summarization needed.
|
|
124
|
+
*
|
|
125
|
+
* Keyed on the snapshot OBSERVATION (browser_observe with mode snapshot) — read/
|
|
126
|
+
* extract observations and act results are left untouched. Renamed from
|
|
127
|
+
* maskOldBrowserSnapshots when the 9 browser_* tools collapsed into 3.
|
|
128
|
+
*/
|
|
129
|
+
export declare function maskOldObservations(messages: Message[]): {
|
|
130
|
+
messages: Message[];
|
|
131
|
+
maskedCount: number;
|
|
132
|
+
};
|
|
77
133
|
/**
|
|
78
134
|
* Apply aggregate per-message tool result budget.
|
|
79
135
|
* When total tool_result content in a single message exceeds maxTotalChars,
|