@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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TcpTransport — newline-delimited JSON over a TCP socket (Duplex stream).
|
|
3
|
+
*
|
|
4
|
+
* Phase 6 of the automation plan: lets the same AgentServer that runs over
|
|
5
|
+
* stdio (agent-server-stdio) also serve over a network socket, so a headless
|
|
6
|
+
* host can be reached by a remote/local client. The transport implements the
|
|
7
|
+
* 3-method Transport interface (send/onMessage/close); AgentServer is unchanged
|
|
8
|
+
* (§0 of docs/automation-plan-2026-05-31.md).
|
|
9
|
+
*
|
|
10
|
+
* Framing mirrors StdioTransport: one JSON value per line. The socket core is
|
|
11
|
+
* separated from listen/accept (`listenTcp`) so the framing is unit-testable
|
|
12
|
+
* against any Duplex without opening a real port.
|
|
13
|
+
*
|
|
14
|
+
* v1 security: intended for localhost / SSH-tunnel use only. There is NO
|
|
15
|
+
* authentication here — do not bind to a public interface without adding auth.
|
|
16
|
+
*/
|
|
17
|
+
import { type Server, type Socket } from "node:net";
|
|
18
|
+
import type { Duplex } from "node:stream";
|
|
19
|
+
import type { Transport } from "./transport.js";
|
|
20
|
+
import type { RpcMessage } from "./types.js";
|
|
21
|
+
/** Wrap a connected Duplex socket as a Transport (NDJSON framing). */
|
|
22
|
+
export declare class SocketTransport implements Transport {
|
|
23
|
+
private readonly socket;
|
|
24
|
+
private rl;
|
|
25
|
+
private handlers;
|
|
26
|
+
constructor(socket: Duplex);
|
|
27
|
+
send(message: RpcMessage): void;
|
|
28
|
+
onMessage(handler: (message: RpcMessage) => void): void;
|
|
29
|
+
close(): void;
|
|
30
|
+
}
|
|
31
|
+
export interface TcpListenResult {
|
|
32
|
+
server: Server;
|
|
33
|
+
/** The actual port bound (useful when 0 was requested). */
|
|
34
|
+
port: number;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Listen on host:port and invoke `onConnection` with a SocketTransport for each
|
|
39
|
+
* accepted client. Resolves once listening. Defaults to 127.0.0.1 — never bind
|
|
40
|
+
* 0.0.0.0 without auth (v1 has none).
|
|
41
|
+
*/
|
|
42
|
+
export declare function listenTcp(opts: {
|
|
43
|
+
port: number;
|
|
44
|
+
host?: string;
|
|
45
|
+
}, onConnection: (transport: SocketTransport, socket: Socket) => void): Promise<TcpListenResult>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TcpTransport — newline-delimited JSON over a TCP socket (Duplex stream).
|
|
3
|
+
*
|
|
4
|
+
* Phase 6 of the automation plan: lets the same AgentServer that runs over
|
|
5
|
+
* stdio (agent-server-stdio) also serve over a network socket, so a headless
|
|
6
|
+
* host can be reached by a remote/local client. The transport implements the
|
|
7
|
+
* 3-method Transport interface (send/onMessage/close); AgentServer is unchanged
|
|
8
|
+
* (§0 of docs/automation-plan-2026-05-31.md).
|
|
9
|
+
*
|
|
10
|
+
* Framing mirrors StdioTransport: one JSON value per line. The socket core is
|
|
11
|
+
* separated from listen/accept (`listenTcp`) so the framing is unit-testable
|
|
12
|
+
* against any Duplex without opening a real port.
|
|
13
|
+
*
|
|
14
|
+
* v1 security: intended for localhost / SSH-tunnel use only. There is NO
|
|
15
|
+
* authentication here — do not bind to a public interface without adding auth.
|
|
16
|
+
*/
|
|
17
|
+
import { createServer } from "node:net";
|
|
18
|
+
import { createInterface } from "node:readline";
|
|
19
|
+
/** Wrap a connected Duplex socket as a Transport (NDJSON framing). */
|
|
20
|
+
export class SocketTransport {
|
|
21
|
+
socket;
|
|
22
|
+
rl;
|
|
23
|
+
handlers = [];
|
|
24
|
+
constructor(socket) {
|
|
25
|
+
this.socket = socket;
|
|
26
|
+
this.rl = createInterface({ input: socket });
|
|
27
|
+
this.rl.on("line", (line) => {
|
|
28
|
+
if (!line.trim())
|
|
29
|
+
return;
|
|
30
|
+
try {
|
|
31
|
+
const msg = JSON.parse(line);
|
|
32
|
+
for (const handler of this.handlers)
|
|
33
|
+
handler(msg);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Skip malformed lines (same policy as StdioTransport).
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
send(message) {
|
|
41
|
+
this.socket.write(JSON.stringify(message) + "\n");
|
|
42
|
+
}
|
|
43
|
+
onMessage(handler) {
|
|
44
|
+
this.handlers.push(handler);
|
|
45
|
+
}
|
|
46
|
+
close() {
|
|
47
|
+
this.rl.close();
|
|
48
|
+
this.handlers = [];
|
|
49
|
+
this.socket.end();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Listen on host:port and invoke `onConnection` with a SocketTransport for each
|
|
54
|
+
* accepted client. Resolves once listening. Defaults to 127.0.0.1 — never bind
|
|
55
|
+
* 0.0.0.0 without auth (v1 has none).
|
|
56
|
+
*/
|
|
57
|
+
export function listenTcp(opts, onConnection) {
|
|
58
|
+
const host = opts.host ?? "127.0.0.1";
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const server = createServer((socket) => {
|
|
61
|
+
onConnection(new SocketTransport(socket), socket);
|
|
62
|
+
});
|
|
63
|
+
server.once("error", reject);
|
|
64
|
+
server.listen(opts.port, host, () => {
|
|
65
|
+
const addr = server.address();
|
|
66
|
+
const port = typeof addr === "object" && addr ? addr.port : opts.port;
|
|
67
|
+
resolve({
|
|
68
|
+
server,
|
|
69
|
+
port,
|
|
70
|
+
close: () => new Promise((res) => server.close(() => res())),
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -25,8 +25,9 @@ export function createInProcessTransport() {
|
|
|
25
25
|
emitterA.on("message", handler);
|
|
26
26
|
},
|
|
27
27
|
close() {
|
|
28
|
+
// Only tear down our own incoming channel; the other side listens on
|
|
29
|
+
// emitterB and must keep working if it hasn't closed yet.
|
|
28
30
|
emitterA.removeAllListeners();
|
|
29
|
-
emitterB.removeAllListeners();
|
|
30
31
|
},
|
|
31
32
|
};
|
|
32
33
|
const sideB = {
|
|
@@ -38,7 +39,7 @@ export function createInProcessTransport() {
|
|
|
38
39
|
emitterB.on("message", handler);
|
|
39
40
|
},
|
|
40
41
|
close() {
|
|
41
|
-
emitterA.
|
|
42
|
+
// Only tear down our own incoming channel; sideA listens on emitterA.
|
|
42
43
|
emitterB.removeAllListeners();
|
|
43
44
|
},
|
|
44
45
|
};
|
package/dist/protocol/types.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ export declare const ErrorCodes: {
|
|
|
40
40
|
readonly Overloaded: -32001;
|
|
41
41
|
readonly SessionNotFound: -32002;
|
|
42
42
|
readonly SessionClosed: -32004;
|
|
43
|
+
/**
|
|
44
|
+
* Run was cancelled by the user (ESC / Stop). Clients should treat
|
|
45
|
+
* this as a clean terminal state, not a real error: no banner, no
|
|
46
|
+
* red toast — just clear busy and stop streaming.
|
|
47
|
+
*/
|
|
48
|
+
readonly Cancelled: -32005;
|
|
43
49
|
};
|
|
44
50
|
/** Start an agent run with a user task. */
|
|
45
51
|
export interface RunParams {
|
|
@@ -55,11 +61,37 @@ export interface RunParams {
|
|
|
55
61
|
* When omitted, the engine keeps its configured default.
|
|
56
62
|
*/
|
|
57
63
|
permissionMode?: PermissionMode;
|
|
64
|
+
/**
|
|
65
|
+
* Workspace trust for this run's project (`cwd`), asserted by the host
|
|
66
|
+
* (desktop main from its trust-store) — never by the renderer. When false,
|
|
67
|
+
* the engine strips dangerous fields from the project's own .code-shell
|
|
68
|
+
* settings (permissions/env/hooks/mcpServers/localEnvironment). Omitted →
|
|
69
|
+
* trusted (preserves behavior for hosts that don't wire trust).
|
|
70
|
+
*/
|
|
71
|
+
projectTrusted?: boolean;
|
|
58
72
|
/**
|
|
59
73
|
* Per-run plan-mode flag. When true, the Engine enters plan mode for
|
|
60
74
|
* this run; when omitted, the engine keeps its configured default.
|
|
61
75
|
*/
|
|
62
76
|
planMode?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Require the target session to already exist on disk. When true and the
|
|
79
|
+
* session is absent, the run is rejected with `SessionNotFound` instead of
|
|
80
|
+
* silently creating a fresh empty session. Used by cron "continue this
|
|
81
|
+
* conversation" jobs: if the user deleted the target session, the job must
|
|
82
|
+
* fail loudly (so it can be auto-disabled) rather than run its prompt against
|
|
83
|
+
* a blank context. Omitted/false → the normal resume-or-create behavior.
|
|
84
|
+
*/
|
|
85
|
+
requireExisting?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Goal mode for this run. When set, the engine runs loop-until-done:
|
|
88
|
+
* on each natural completion a GoalStopHook judges whether this goal is
|
|
89
|
+
* met and re-prompts if not (bounded). Orthogonal to permissionMode.
|
|
90
|
+
*
|
|
91
|
+
* Accepts a bare objective string or a full GoalConfig (objective +
|
|
92
|
+
* optional token/time budgets). Normalized at the engine run boundary.
|
|
93
|
+
*/
|
|
94
|
+
goal?: string | import("../engine/goal.js").GoalConfig;
|
|
63
95
|
}
|
|
64
96
|
export interface RunResult {
|
|
65
97
|
text: string;
|
|
@@ -88,6 +120,19 @@ export interface InjectParams {
|
|
|
88
120
|
sessionId: string;
|
|
89
121
|
content: string;
|
|
90
122
|
}
|
|
123
|
+
/** Steer an in-flight run: queue a user message for the next turn-loop step. */
|
|
124
|
+
export interface SteerParams {
|
|
125
|
+
sessionId: string;
|
|
126
|
+
text: string;
|
|
127
|
+
/** Stable host-side id for this queued draft. Rides through to the
|
|
128
|
+
* steer_injected event and is the handle Unsteer uses to revoke it. */
|
|
129
|
+
id?: string;
|
|
130
|
+
}
|
|
131
|
+
/** Revoke a still-pending steer entry by id (before the loop consumes it). */
|
|
132
|
+
export interface UnsteerParams {
|
|
133
|
+
sessionId: string;
|
|
134
|
+
id: string;
|
|
135
|
+
}
|
|
91
136
|
/** Update runtime configuration. */
|
|
92
137
|
export interface ConfigureParams {
|
|
93
138
|
/** When present, configure that specific chat session. Otherwise worker-global. */
|
|
@@ -104,6 +149,14 @@ export interface ConfigureParams {
|
|
|
104
149
|
* running engine picks them up without a process restart.
|
|
105
150
|
*/
|
|
106
151
|
reloadModels?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Re-read disk settings and hot-push the disk-default config fields (preset /
|
|
154
|
+
* customSystemPrompt / appendSystemPrompt / personalization / mcpServers) +
|
|
155
|
+
* settings hooks onto ALREADY-RUNNING sessions ("config hot-reload layer 2").
|
|
156
|
+
* No sessionId → applies to every live session; with sessionId → that one.
|
|
157
|
+
* Applied at the next turn boundary; in-flight turns are not interrupted.
|
|
158
|
+
*/
|
|
159
|
+
reloadSettings?: boolean;
|
|
107
160
|
}
|
|
108
161
|
/** Query server state. */
|
|
109
162
|
export interface QueryParams {
|
|
@@ -206,8 +259,24 @@ export declare const Methods: {
|
|
|
206
259
|
readonly Query: "agent/query";
|
|
207
260
|
/** Inject context into transcript without triggering LLM. */
|
|
208
261
|
readonly Inject: "agent/inject";
|
|
262
|
+
/** Steer an in-flight run: queue a user message spliced at the next step (不打断). */
|
|
263
|
+
readonly Steer: "agent/steer";
|
|
264
|
+
/** Revoke a still-pending steer entry by id (撤回, before the loop consumes it). */
|
|
265
|
+
readonly Unsteer: "agent/unsteer";
|
|
209
266
|
/** Close (destroy) a session. */
|
|
210
267
|
readonly CloseSession: "agent/closeSession";
|
|
268
|
+
/** Extend a running goal's turn/budget ceilings mid-run (TODO 3.1). */
|
|
269
|
+
readonly GoalExtend: "agent/goalExtend";
|
|
270
|
+
/** Clear a session's persisted active goal (CC /goal clear). */
|
|
271
|
+
readonly GoalClear: "agent/goalClear";
|
|
272
|
+
/** Read a session's persisted active goal, to re-surface it on session load. */
|
|
273
|
+
readonly GoalGet: "agent/goalGet";
|
|
274
|
+
/** Query/control a session's background shells for the UI panel (TODO 3.2). */
|
|
275
|
+
readonly BackgroundShells: "agent/backgroundShells";
|
|
276
|
+
/** Unified listing of a session's background work (shells + sub-agents + jobs)
|
|
277
|
+
* for the desktop background panel. Output/kill of a shell still goes through
|
|
278
|
+
* BackgroundShells by shellId; this is list-only across all three kinds. */
|
|
279
|
+
readonly BackgroundWork: "agent/backgroundWork";
|
|
211
280
|
readonly StreamEvent: "agent/streamEvent";
|
|
212
281
|
readonly ApprovalRequest: "agent/approvalRequest";
|
|
213
282
|
readonly Status: "agent/status";
|
package/dist/protocol/types.js
CHANGED
|
@@ -18,6 +18,12 @@ export const ErrorCodes = {
|
|
|
18
18
|
Overloaded: -32001,
|
|
19
19
|
SessionNotFound: -32002,
|
|
20
20
|
SessionClosed: -32004,
|
|
21
|
+
/**
|
|
22
|
+
* Run was cancelled by the user (ESC / Stop). Clients should treat
|
|
23
|
+
* this as a clean terminal state, not a real error: no banner, no
|
|
24
|
+
* red toast — just clear busy and stop streaming.
|
|
25
|
+
*/
|
|
26
|
+
Cancelled: -32005,
|
|
21
27
|
};
|
|
22
28
|
// ─── Method Names ───────────────────────────────────────────────────
|
|
23
29
|
export const Methods = {
|
|
@@ -29,8 +35,24 @@ export const Methods = {
|
|
|
29
35
|
Query: "agent/query",
|
|
30
36
|
/** Inject context into transcript without triggering LLM. */
|
|
31
37
|
Inject: "agent/inject",
|
|
38
|
+
/** Steer an in-flight run: queue a user message spliced at the next step (不打断). */
|
|
39
|
+
Steer: "agent/steer",
|
|
40
|
+
/** Revoke a still-pending steer entry by id (撤回, before the loop consumes it). */
|
|
41
|
+
Unsteer: "agent/unsteer",
|
|
32
42
|
/** Close (destroy) a session. */
|
|
33
43
|
CloseSession: "agent/closeSession",
|
|
44
|
+
/** Extend a running goal's turn/budget ceilings mid-run (TODO 3.1). */
|
|
45
|
+
GoalExtend: "agent/goalExtend",
|
|
46
|
+
/** Clear a session's persisted active goal (CC /goal clear). */
|
|
47
|
+
GoalClear: "agent/goalClear",
|
|
48
|
+
/** Read a session's persisted active goal, to re-surface it on session load. */
|
|
49
|
+
GoalGet: "agent/goalGet",
|
|
50
|
+
/** Query/control a session's background shells for the UI panel (TODO 3.2). */
|
|
51
|
+
BackgroundShells: "agent/backgroundShells",
|
|
52
|
+
/** Unified listing of a session's background work (shells + sub-agents + jobs)
|
|
53
|
+
* for the desktop background panel. Output/kill of a shell still goes through
|
|
54
|
+
* BackgroundShells by shellId; this is list-only across all three kinds. */
|
|
55
|
+
BackgroundWork: "agent/backgroundWork",
|
|
34
56
|
// Server → Client (notifications, no id)
|
|
35
57
|
StreamEvent: "agent/streamEvent",
|
|
36
58
|
ApprovalRequest: "agent/approvalRequest",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default resolver for the tokens `quota/` needs.
|
|
3
|
+
*
|
|
4
|
+
* This is the ONE platform-specific file in the module — it reads a vendor's
|
|
5
|
+
* Keychain entry / auth.json. A host that stores secrets differently (or a
|
|
6
|
+
* future plugin) can bypass this and build QuotaCredentials itself; core logic
|
|
7
|
+
* in index.ts only depends on the QuotaCredentials shape.
|
|
8
|
+
*
|
|
9
|
+
* All reads are best-effort: a missing token yields `undefined`, never a throw,
|
|
10
|
+
* so a machine without Codex or without Keychain access degrades to "quota
|
|
11
|
+
* unavailable for that provider" instead of failing the whole call.
|
|
12
|
+
*/
|
|
13
|
+
import { execFile } from "node:child_process";
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
function userHome() {
|
|
18
|
+
return process.env.HOME || process.env.USERPROFILE || homedir();
|
|
19
|
+
}
|
|
20
|
+
/** Read the Codex OAuth token + account id from ~/.codex/auth.json. */
|
|
21
|
+
async function readCodexCreds() {
|
|
22
|
+
try {
|
|
23
|
+
const raw = await readFile(join(userHome(), ".codex", "auth.json"), "utf8");
|
|
24
|
+
const j = JSON.parse(raw);
|
|
25
|
+
const tokens = (j.tokens ?? {});
|
|
26
|
+
const token = typeof tokens.access_token === "string" ? tokens.access_token : undefined;
|
|
27
|
+
const acct = typeof tokens.account_id === "string" ? tokens.account_id : undefined;
|
|
28
|
+
return { codexAccessToken: token, codexAccountId: acct };
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Read the Claude Code OAuth access token.
|
|
36
|
+
* macOS: Keychain generic-password "Claude Code-credentials".
|
|
37
|
+
* Other platforms: fall back to a plaintext ~/.claude/.credentials.json if present.
|
|
38
|
+
*/
|
|
39
|
+
async function readClaudeCreds() {
|
|
40
|
+
// macOS Keychain first.
|
|
41
|
+
if (process.platform === "darwin") {
|
|
42
|
+
const raw = await runSecurity();
|
|
43
|
+
const token = parseClaudeToken(raw);
|
|
44
|
+
if (token)
|
|
45
|
+
return { claudeAccessToken: token };
|
|
46
|
+
}
|
|
47
|
+
// Cross-platform fallback: some installs keep a plaintext credentials file.
|
|
48
|
+
try {
|
|
49
|
+
const raw = await readFile(join(userHome(), ".claude", ".credentials.json"), "utf8");
|
|
50
|
+
const token = parseClaudeToken(raw);
|
|
51
|
+
if (token)
|
|
52
|
+
return { claudeAccessToken: token };
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
/* not present */
|
|
56
|
+
}
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
function parseClaudeToken(raw) {
|
|
60
|
+
if (!raw)
|
|
61
|
+
return undefined;
|
|
62
|
+
try {
|
|
63
|
+
const j = JSON.parse(raw);
|
|
64
|
+
const oauth = (j.claudeAiOauth ?? {});
|
|
65
|
+
return typeof oauth.accessToken === "string" ? oauth.accessToken : undefined;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function runSecurity() {
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
execFile("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 4000 }, (err, stdout) => resolve(err ? null : stdout.toString().trim()));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** Resolve all tokens from their standard local locations. Never throws. */
|
|
77
|
+
export async function resolveQuotaCredentials() {
|
|
78
|
+
const [codex, claude] = await Promise.all([readCodexCreds(), readClaudeCreds()]);
|
|
79
|
+
return { ...codex, ...claude };
|
|
80
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query remaining quota for the external coding-agent CLIs.
|
|
3
|
+
*
|
|
4
|
+
* Both lookups are verified against the real backends (2026-07-01):
|
|
5
|
+
* - Codex: GET https://chatgpt.com/backend-api/wham/usage → JSON
|
|
6
|
+
* rate_limit.{primary_window,secondary_window}.{used_percent,reset_at}.
|
|
7
|
+
* Zero cost (no message sent).
|
|
8
|
+
* - Claude: POST /v1/messages (max_tokens:1) → response headers
|
|
9
|
+
* anthropic-ratelimit-unified-{5h,7d}-{utilization,reset}.
|
|
10
|
+
* Costs ~1 output token (Claude exposes quota only via response
|
|
11
|
+
* headers — there is no standalone usage endpoint).
|
|
12
|
+
*
|
|
13
|
+
* The `fetch` and credentials are injected so this is unit-testable offline and
|
|
14
|
+
* so the host owns secret resolution (see types.ts boundary note).
|
|
15
|
+
*/
|
|
16
|
+
import type { ProviderQuota, QuotaCredentials, QuotaResult } from "./types.js";
|
|
17
|
+
type FetchLike = typeof fetch;
|
|
18
|
+
export interface CheckQuotaOptions {
|
|
19
|
+
creds: QuotaCredentials;
|
|
20
|
+
/** Restrict to specific providers; defaults to both. */
|
|
21
|
+
providers?: ("claude" | "codex")[];
|
|
22
|
+
/** Injected for tests; defaults to global fetch. */
|
|
23
|
+
fetchImpl?: FetchLike;
|
|
24
|
+
/** Caller's abort signal (user Stop); composed with an internal timeout. */
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
}
|
|
28
|
+
/** Codex: GET the usage endpoint and map its JSON to ProviderQuota. */
|
|
29
|
+
export declare function queryCodexQuota(creds: QuotaCredentials, fetchImpl: FetchLike, signal: AbortSignal): Promise<ProviderQuota>;
|
|
30
|
+
/** Claude: POST a 1-token probe and read the unified rate-limit headers. */
|
|
31
|
+
export declare function queryClaudeQuota(creds: QuotaCredentials, fetchImpl: FetchLike, signal: AbortSignal): Promise<ProviderQuota>;
|
|
32
|
+
/** Query both providers (or the subset requested), concurrently. */
|
|
33
|
+
export declare function checkQuota(opts: CheckQuotaOptions): Promise<QuotaResult>;
|
|
34
|
+
/** Render a QuotaResult as a compact human/agent-readable summary. */
|
|
35
|
+
export declare function formatQuota(result: QuotaResult, nowSec: number): string;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const CODEX_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
|
|
2
|
+
const CLAUDE_MESSAGES_URL = "https://api.anthropic.com/v1/messages";
|
|
3
|
+
/** Cheapest always-available model for the 1-token probe. */
|
|
4
|
+
const CLAUDE_PROBE_MODEL = "claude-haiku-4-5-20251001";
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 8000;
|
|
6
|
+
/** Compose the caller signal with a timeout so a hung backend can't block. */
|
|
7
|
+
function withTimeout(signal, timeoutMs) {
|
|
8
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
9
|
+
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
10
|
+
}
|
|
11
|
+
function num(v) {
|
|
12
|
+
const n = typeof v === "string" ? parseFloat(v) : typeof v === "number" ? v : NaN;
|
|
13
|
+
return Number.isFinite(n) ? n : null;
|
|
14
|
+
}
|
|
15
|
+
/** Codex: GET the usage endpoint and map its JSON to ProviderQuota. */
|
|
16
|
+
export async function queryCodexQuota(creds, fetchImpl, signal) {
|
|
17
|
+
if (!creds.codexAccessToken) {
|
|
18
|
+
return { provider: "codex", error: "no Codex token (是否已 codex login?)" };
|
|
19
|
+
}
|
|
20
|
+
let resp;
|
|
21
|
+
try {
|
|
22
|
+
resp = await fetchImpl(CODEX_USAGE_URL, {
|
|
23
|
+
method: "GET",
|
|
24
|
+
headers: {
|
|
25
|
+
authorization: `Bearer ${creds.codexAccessToken}`,
|
|
26
|
+
...(creds.codexAccountId ? { "chatgpt-account-id": creds.codexAccountId } : {}),
|
|
27
|
+
originator: "codex_cli_rs",
|
|
28
|
+
"user-agent": "codex_cli_rs",
|
|
29
|
+
},
|
|
30
|
+
signal,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
return { provider: "codex", error: `请求失败: ${err.message}` };
|
|
35
|
+
}
|
|
36
|
+
if (!resp.ok) {
|
|
37
|
+
return { provider: "codex", error: `HTTP ${resp.status}${resp.status === 401 ? " (token 可能已过期)" : ""}` };
|
|
38
|
+
}
|
|
39
|
+
let body;
|
|
40
|
+
try {
|
|
41
|
+
body = (await resp.json());
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return { provider: "codex", error: "响应非 JSON" };
|
|
45
|
+
}
|
|
46
|
+
const rl = (body.rate_limit ?? {});
|
|
47
|
+
const windows = [];
|
|
48
|
+
const map = [
|
|
49
|
+
["primary_window", "5h"],
|
|
50
|
+
["secondary_window", "7d"],
|
|
51
|
+
];
|
|
52
|
+
for (const [key, kind] of map) {
|
|
53
|
+
const w = rl[key];
|
|
54
|
+
if (!w)
|
|
55
|
+
continue;
|
|
56
|
+
const usedPercent = num(w.used_percent);
|
|
57
|
+
if (usedPercent == null)
|
|
58
|
+
continue;
|
|
59
|
+
windows.push({ kind, usedPercent, resetsAt: num(w.reset_at) });
|
|
60
|
+
}
|
|
61
|
+
if (windows.length === 0)
|
|
62
|
+
return { provider: "codex", error: "响应无 rate_limit 窗口" };
|
|
63
|
+
return {
|
|
64
|
+
provider: "codex",
|
|
65
|
+
windows,
|
|
66
|
+
planType: typeof body.plan_type === "string" ? body.plan_type : null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Claude: POST a 1-token probe and read the unified rate-limit headers. */
|
|
70
|
+
export async function queryClaudeQuota(creds, fetchImpl, signal) {
|
|
71
|
+
if (!creds.claudeAccessToken) {
|
|
72
|
+
return { provider: "claude", error: "no Claude Code token (是否已登录 Claude Code?)" };
|
|
73
|
+
}
|
|
74
|
+
let resp;
|
|
75
|
+
try {
|
|
76
|
+
resp = await fetchImpl(CLAUDE_MESSAGES_URL, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: {
|
|
79
|
+
authorization: `Bearer ${creds.claudeAccessToken}`,
|
|
80
|
+
"anthropic-version": "2023-06-01",
|
|
81
|
+
"anthropic-beta": "oauth-2025-04-20",
|
|
82
|
+
"content-type": "application/json",
|
|
83
|
+
},
|
|
84
|
+
body: JSON.stringify({
|
|
85
|
+
model: CLAUDE_PROBE_MODEL,
|
|
86
|
+
max_tokens: 1,
|
|
87
|
+
messages: [{ role: "user", content: "hi" }],
|
|
88
|
+
}),
|
|
89
|
+
signal,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
return { provider: "claude", error: `请求失败: ${err.message}` };
|
|
94
|
+
}
|
|
95
|
+
if (!resp.ok) {
|
|
96
|
+
return { provider: "claude", error: `HTTP ${resp.status}${resp.status === 401 ? " (token 可能已过期)" : ""}` };
|
|
97
|
+
}
|
|
98
|
+
const h = resp.headers;
|
|
99
|
+
const windows = [];
|
|
100
|
+
const map = [
|
|
101
|
+
["anthropic-ratelimit-unified-5h-utilization", "anthropic-ratelimit-unified-5h-reset", "5h"],
|
|
102
|
+
["anthropic-ratelimit-unified-7d-utilization", "anthropic-ratelimit-unified-7d-reset", "7d"],
|
|
103
|
+
];
|
|
104
|
+
for (const [utilKey, resetKey, kind] of map) {
|
|
105
|
+
const util = num(h.get(utilKey)); // 0–1
|
|
106
|
+
if (util == null)
|
|
107
|
+
continue;
|
|
108
|
+
windows.push({ kind, usedPercent: util * 100, resetsAt: num(h.get(resetKey)) });
|
|
109
|
+
}
|
|
110
|
+
if (windows.length === 0)
|
|
111
|
+
return { provider: "claude", error: "响应头无 rate-limit 字段" };
|
|
112
|
+
return { provider: "claude", windows };
|
|
113
|
+
}
|
|
114
|
+
/** Query both providers (or the subset requested), concurrently. */
|
|
115
|
+
export async function checkQuota(opts) {
|
|
116
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
117
|
+
const providers = opts.providers ?? ["claude", "codex"];
|
|
118
|
+
const signal = withTimeout(opts.signal, opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
119
|
+
const result = {};
|
|
120
|
+
await Promise.all(providers.map(async (p) => {
|
|
121
|
+
if (p === "codex")
|
|
122
|
+
result.codex = await queryCodexQuota(opts.creds, fetchImpl, signal);
|
|
123
|
+
else
|
|
124
|
+
result.claude = await queryClaudeQuota(opts.creds, fetchImpl, signal);
|
|
125
|
+
}));
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/** Render a QuotaResult as a compact human/agent-readable summary. */
|
|
129
|
+
export function formatQuota(result, nowSec) {
|
|
130
|
+
const lines = [];
|
|
131
|
+
for (const pq of [result.claude, result.codex]) {
|
|
132
|
+
if (!pq)
|
|
133
|
+
continue;
|
|
134
|
+
const name = pq.provider === "claude" ? "Claude Code" : "Codex";
|
|
135
|
+
if (pq.error || !pq.windows) {
|
|
136
|
+
lines.push(`${name}: 查询失败 — ${pq.error ?? "unknown"}`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const plan = pq.planType ? ` [${pq.planType}]` : "";
|
|
140
|
+
const parts = pq.windows.map((w) => {
|
|
141
|
+
const reset = w.resetsAt != null ? ` (重置 ${formatReset(w.resetsAt - nowSec)})` : "";
|
|
142
|
+
return `${w.kind} 用了 ${w.usedPercent.toFixed(0)}%${reset}`;
|
|
143
|
+
});
|
|
144
|
+
lines.push(`${name}${plan}: ${parts.join(",")}`);
|
|
145
|
+
}
|
|
146
|
+
return lines.length ? lines.join("\n") : "(无可用额度信息)";
|
|
147
|
+
}
|
|
148
|
+
/** "2h13m" / "45m" / "已重置" from a seconds delta. */
|
|
149
|
+
function formatReset(deltaSec) {
|
|
150
|
+
if (deltaSec <= 0)
|
|
151
|
+
return "已重置";
|
|
152
|
+
const h = Math.floor(deltaSec / 3600);
|
|
153
|
+
const m = Math.floor((deltaSec % 3600) / 60);
|
|
154
|
+
return h > 0 ? `${h}h${m}m 后` : `${m}m 后`;
|
|
155
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quota (rate-limit / usage) types for external coding-agent CLIs.
|
|
3
|
+
*
|
|
4
|
+
* DESIGN / BOUNDARY NOTE (see project_core_minimal_harness_business_layer):
|
|
5
|
+
* "how to read Claude Code / Codex remaining quota" is provider-specific
|
|
6
|
+
* BUSINESS policy, not core harness mechanism — it pokes a vendor's Keychain
|
|
7
|
+
* entry, an undocumented usage endpoint, and private response headers. It lives
|
|
8
|
+
* in this self-contained `quota/` module (one interface out: `checkQuota`) on
|
|
9
|
+
* purpose, so it can be lifted wholesale into a plugin later without untangling
|
|
10
|
+
* it from the rest of core. Nothing outside this module should know about
|
|
11
|
+
* Keychain / wham endpoints / `anthropic-ratelimit-*` header names.
|
|
12
|
+
*/
|
|
13
|
+
/** A single rolling limit window (e.g. the 5-hour or 7-day window). */
|
|
14
|
+
export interface QuotaWindow {
|
|
15
|
+
/** Which window this is. */
|
|
16
|
+
kind: "5h" | "7d";
|
|
17
|
+
/** Percent of the window's limit already used, 0–100. */
|
|
18
|
+
usedPercent: number;
|
|
19
|
+
/** Unix epoch seconds when this window resets, or null if unknown. */
|
|
20
|
+
resetsAt: number | null;
|
|
21
|
+
}
|
|
22
|
+
/** Quota for one provider (claude | codex). */
|
|
23
|
+
export interface ProviderQuota {
|
|
24
|
+
provider: "claude" | "codex";
|
|
25
|
+
/** Present when the lookup succeeded. */
|
|
26
|
+
windows?: QuotaWindow[];
|
|
27
|
+
/** Subscription tier, when the source exposes it (e.g. "team", "pro"). */
|
|
28
|
+
planType?: string | null;
|
|
29
|
+
/** Human-readable failure reason when the lookup did not succeed. */
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface QuotaResult {
|
|
33
|
+
claude?: ProviderQuota;
|
|
34
|
+
codex?: ProviderQuota;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A credential the host supplies so this module can talk to a vendor backend.
|
|
38
|
+
* Core never reads the Keychain / auth.json itself — the host (desktop main /
|
|
39
|
+
* server) resolves the secret and hands it in. This is the seam that makes the
|
|
40
|
+
* whole module portable to a plugin.
|
|
41
|
+
*/
|
|
42
|
+
export interface QuotaCredentials {
|
|
43
|
+
/** Claude Code OAuth access token (from Keychain "Claude Code-credentials"). */
|
|
44
|
+
claudeAccessToken?: string;
|
|
45
|
+
/** Codex OAuth access token + account id (from ~/.codex/auth.json). */
|
|
46
|
+
codexAccessToken?: string;
|
|
47
|
+
codexAccountId?: string;
|
|
48
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quota (rate-limit / usage) types for external coding-agent CLIs.
|
|
3
|
+
*
|
|
4
|
+
* DESIGN / BOUNDARY NOTE (see project_core_minimal_harness_business_layer):
|
|
5
|
+
* "how to read Claude Code / Codex remaining quota" is provider-specific
|
|
6
|
+
* BUSINESS policy, not core harness mechanism — it pokes a vendor's Keychain
|
|
7
|
+
* entry, an undocumented usage endpoint, and private response headers. It lives
|
|
8
|
+
* in this self-contained `quota/` module (one interface out: `checkQuota`) on
|
|
9
|
+
* purpose, so it can be lifted wholesale into a plugin later without untangling
|
|
10
|
+
* it from the rest of core. Nothing outside this module should know about
|
|
11
|
+
* Keychain / wham endpoints / `anthropic-ratelimit-*` header names.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
package/dist/remote/bridge.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Architecture:
|
|
5
5
|
* Local terminal ←→ SSH ←→ Remote code-shell (NDJSON stdio mode)
|
|
6
6
|
*/
|
|
7
|
+
import { type ChildProcess } from "node:child_process";
|
|
7
8
|
export interface BridgeConfig {
|
|
8
9
|
host: string;
|
|
9
10
|
user?: string;
|
|
@@ -11,11 +12,20 @@ export interface BridgeConfig {
|
|
|
11
12
|
identityFile?: string;
|
|
12
13
|
remoteCommand?: string;
|
|
13
14
|
}
|
|
15
|
+
/** A spawn function (injectable for tests). Defaults to child_process.spawn. */
|
|
16
|
+
export type SpawnFn = (command: string, args: string[]) => ChildProcess;
|
|
17
|
+
/**
|
|
18
|
+
* Build the ssh argv. Each value is a discrete element — spawn runs ssh
|
|
19
|
+
* without a shell, so identityFile/port/host are never shell-interpreted
|
|
20
|
+
* (there is no local command-injection surface here).
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildSSHArgs(config: BridgeConfig): string[];
|
|
14
23
|
export declare class RemoteBridge {
|
|
15
24
|
private readonly config;
|
|
16
25
|
private ssh;
|
|
17
26
|
private connected;
|
|
18
|
-
|
|
27
|
+
private readonly spawnFn;
|
|
28
|
+
constructor(config: BridgeConfig, spawnFn?: SpawnFn);
|
|
19
29
|
/**
|
|
20
30
|
* Connect to the remote host via SSH and start code-shell in NDJSON mode.
|
|
21
31
|
*/
|
|
@@ -33,5 +43,4 @@ export declare class RemoteBridge {
|
|
|
33
43
|
*/
|
|
34
44
|
disconnect(): void;
|
|
35
45
|
get isConnected(): boolean;
|
|
36
|
-
private buildSSHArgs;
|
|
37
46
|
}
|