@cjhyy/code-shell-core 0.5.0-rc.2 → 0.6.0-rc.2
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 +3 -0
- package/dist/agent/agent-definition-registry.js +3 -1
- package/dist/agent/agent-definition.d.ts +15 -0
- package/dist/agent/agent-definition.js +27 -3
- package/dist/arena/context/context-tools.js +47 -4
- package/dist/arena/ledger.js +9 -1
- package/dist/arena/strategies/utils.d.ts +1 -4
- package/dist/arena/strategies/utils.js +7 -84
- package/dist/automation/cron-expr.d.ts +10 -0
- package/dist/automation/cron-expr.js +23 -5
- package/dist/automation/runner.d.ts +21 -4
- package/dist/automation/runner.js +48 -12
- package/dist/automation/scheduler.d.ts +38 -0
- package/dist/automation/scheduler.js +89 -12
- package/dist/automation/store.js +5 -2
- package/dist/capability-control/disabled-lists.d.ts +25 -0
- package/dist/capability-control/disabled-lists.js +57 -0
- package/dist/capability-control/overlay.d.ts +15 -0
- package/dist/capability-control/overlay.js +27 -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 +15 -1
- package/dist/cli/agent-server-stdio.js +115 -17
- package/dist/cli/agent-server-tcp.js +40 -26
- package/dist/context/compaction.d.ts +56 -0
- package/dist/context/compaction.js +186 -0
- package/dist/context/manager.js +25 -4
- 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/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/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 +267 -138
- package/dist/engine/engine.js +957 -191
- package/dist/engine/friendly-error.d.ts +18 -0
- package/dist/engine/friendly-error.js +63 -0
- package/dist/engine/goal.d.ts +145 -0
- package/dist/engine/goal.js +144 -0
- package/dist/engine/image-policy.d.ts +13 -0
- package/dist/engine/image-policy.js +24 -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/resolve-llm-config.d.ts +16 -0
- package/dist/engine/resolve-llm-config.js +44 -0
- package/dist/engine/runtime.js +2 -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-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 +67 -3
- package/dist/engine/turn-loop.js +292 -41
- 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/utils.js +11 -6
- package/dist/git/worktree.d.ts +48 -0
- package/dist/git/worktree.js +86 -10
- package/dist/hooks/goal-stop-hook.d.ts +28 -0
- package/dist/hooks/goal-stop-hook.js +186 -9
- package/dist/hooks/registry.d.ts +8 -0
- package/dist/hooks/registry.js +19 -0
- package/dist/hooks/shell-runner.js +10 -21
- package/dist/index.d.ts +49 -6
- package/dist/index.js +60 -4
- package/dist/llm/capabilities/param-specs.d.ts +14 -0
- package/dist/llm/capabilities/param-specs.js +62 -0
- package/dist/llm/capabilities/rules.js +4 -0
- package/dist/llm/capabilities/types.d.ts +10 -0
- package/dist/llm/client-base.d.ts +28 -1
- package/dist/llm/client-base.js +119 -13
- package/dist/llm/model-cache.js +4 -2
- package/dist/llm/model-pool.d.ts +14 -0
- package/dist/llm/model-pool.js +13 -0
- package/dist/llm/provider-auth.d.ts +41 -0
- package/dist/llm/provider-auth.js +76 -0
- package/dist/llm/provider-catalog.d.ts +4 -0
- package/dist/llm/providers/anthropic.js +64 -14
- package/dist/llm/providers/openai.d.ts +36 -0
- package/dist/llm/providers/openai.js +257 -51
- package/dist/llm/reasoning-setting.d.ts +3 -3
- package/dist/llm/reasoning-setting.js +9 -1
- package/dist/llm/stream-watchdog.js +5 -1
- package/dist/llm/token-counter.js +9 -2
- package/dist/llm/types.d.ts +4 -0
- package/dist/logging/sanitize-messages.js +22 -0
- package/dist/lsp/manager.d.ts +1 -1
- package/dist/lsp/manager.js +40 -10
- 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 +61 -326
- package/dist/plugins/gitOps.d.ts +19 -0
- package/dist/plugins/gitOps.js +73 -4
- package/dist/plugins/installer/checkUpdate.d.ts +16 -0
- package/dist/plugins/installer/checkUpdate.js +32 -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 +5 -2
- package/dist/plugins/installer/codex/convertMcp.js +45 -5
- package/dist/plugins/installer/install.js +25 -1
- package/dist/plugins/installer/installFromArchive.d.ts +43 -0
- package/dist/plugins/installer/installFromArchive.js +134 -0
- package/dist/plugins/installer/installFromSource.js +8 -2
- package/dist/plugins/installer/loadPluginAgents.js +6 -2
- package/dist/plugins/installer/loadPluginMcp.d.ts +9 -2
- package/dist/plugins/installer/loadPluginMcp.js +35 -2
- package/dist/plugins/installer/pruneDisabled.d.ts +24 -0
- package/dist/plugins/installer/pruneDisabled.js +73 -0
- package/dist/plugins/installer/types.d.ts +5 -2
- package/dist/plugins/installer/types.js +1 -0
- package/dist/plugins/installer/uninstall.js +4 -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 +14 -0
- package/dist/plugins/installer/update.js +53 -21
- package/dist/plugins/loadPluginHooks.d.ts +47 -1
- package/dist/plugins/loadPluginHooks.js +73 -1
- package/dist/plugins/marketplaceManager.d.ts +7 -0
- package/dist/plugins/marketplaceManager.js +20 -0
- package/dist/plugins/pluginCommandHook.js +4 -18
- package/dist/plugins/pluginContent.d.ts +30 -0
- package/dist/plugins/pluginContent.js +83 -0
- package/dist/plugins/pluginInstaller.d.ts +13 -0
- package/dist/plugins/pluginInstaller.js +42 -8
- package/dist/plugins/schemas.js +1 -0
- package/dist/plugins/types.d.ts +6 -0
- package/dist/preset/index.d.ts +7 -1
- package/dist/preset/index.js +96 -6
- package/dist/product/types.d.ts +1 -1
- package/dist/prompt/composer.d.ts +27 -0
- package/dist/prompt/composer.js +67 -21
- 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/protocol/chat-session-manager.d.ts +8 -2
- package/dist/protocol/chat-session-manager.js +36 -0
- package/dist/protocol/chat-session.d.ts +65 -0
- package/dist/protocol/chat-session.js +94 -2
- package/dist/protocol/client.d.ts +27 -0
- package/dist/protocol/client.js +38 -0
- package/dist/protocol/server.d.ts +112 -0
- package/dist/protocol/server.js +586 -16
- package/dist/protocol/transport.js +3 -2
- package/dist/protocol/types.d.ts +46 -0
- package/dist/protocol/types.js +16 -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/review/review-prompt.d.ts +28 -0
- package/dist/review/review-prompt.js +81 -0
- package/dist/run/FileRunStore.js +8 -3
- package/dist/run/RunApprovalBackend.js +25 -5
- package/dist/run/RunManager.d.ts +12 -0
- package/dist/run/RunManager.js +35 -0
- package/dist/run/factory.d.ts +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/diagnostics.d.ts +1 -2
- package/dist/services/diagnostics.js +12 -7
- 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 -50
- package/dist/services/session-memory.js +24 -12
- package/dist/session/file-history.d.ts +124 -1
- package/dist/session/file-history.js +222 -6
- package/dist/session/memory.d.ts +116 -2
- package/dist/session/memory.js +250 -28
- package/dist/session/session-manager.d.ts +40 -0
- package/dist/session/session-manager.js +113 -3
- 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 +9 -2
- package/dist/settings/disk-defaults.js +11 -2
- package/dist/settings/feature-flags.d.ts +64 -0
- package/dist/settings/feature-flags.js +61 -0
- package/dist/settings/manager.d.ts +68 -1
- package/dist/settings/manager.js +266 -29
- package/dist/settings/migrate-config.d.ts +45 -0
- package/dist/settings/migrate-config.js +125 -0
- package/dist/settings/schema-export.d.ts +25 -0
- package/dist/settings/schema-export.js +38 -0
- package/dist/settings/schema.d.ts +1186 -771
- package/dist/settings/schema.js +268 -97
- 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/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 +12 -0
- package/dist/tool-system/builtin/agent-registry.js +8 -0
- package/dist/tool-system/builtin/agent.d.ts +21 -1
- package/dist/tool-system/builtin/agent.js +489 -42
- 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 +0 -15
- 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/config.js +7 -0
- package/dist/tool-system/builtin/cron.d.ts +7 -0
- package/dist/tool-system/builtin/cron.js +55 -3
- 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.js +20 -16
- 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 +35 -0
- package/dist/tool-system/builtin/generate-image.js +278 -50
- 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/glob.js +0 -7
- package/dist/tool-system/builtin/grep.js +6 -8
- 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 +7 -1
- package/dist/tool-system/builtin/index.js +249 -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.js +0 -7
- package/dist/tool-system/builtin/powershell.js +4 -1
- package/dist/tool-system/builtin/read.js +10 -10
- 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 +3 -2
- package/dist/tool-system/builtin/tool-search.js +25 -7
- 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/web-fetch.js +12 -2
- package/dist/tool-system/builtin/web-search.js +21 -7
- 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.js +0 -6
- package/dist/tool-system/context.d.ts +154 -6
- package/dist/tool-system/executor.d.ts +3 -1
- package/dist/tool-system/executor.js +172 -88
- package/dist/tool-system/investigation-guard.js +1 -1
- package/dist/tool-system/mcp-manager.d.ts +42 -4
- package/dist/tool-system/mcp-manager.js +186 -20
- package/dist/tool-system/path-policy.d.ts +5 -0
- package/dist/tool-system/path-policy.js +307 -8
- package/dist/tool-system/permission.d.ts +36 -1
- package/dist/tool-system/permission.js +281 -69
- package/dist/tool-system/plan-mode-allowlist.d.ts +13 -2
- package/dist/tool-system/plan-mode-allowlist.js +24 -2
- package/dist/tool-system/registry.d.ts +1 -0
- package/dist/tool-system/registry.js +16 -2
- 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/types.d.ts +217 -6
- 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/json.d.ts +12 -0
- package/dist/utils/json.js +92 -0
- package/dist/utils/theme.d.ts +1 -1
- package/dist/utils/theme.js +1 -1
- package/dist/utils/toolDisplay.js +0 -1
- package/package.json +13 -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
|
@@ -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
|
@@ -61,11 +61,28 @@ export interface RunParams {
|
|
|
61
61
|
* When omitted, the engine keeps its configured default.
|
|
62
62
|
*/
|
|
63
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;
|
|
64
72
|
/**
|
|
65
73
|
* Per-run plan-mode flag. When true, the Engine enters plan mode for
|
|
66
74
|
* this run; when omitted, the engine keeps its configured default.
|
|
67
75
|
*/
|
|
68
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;
|
|
69
86
|
/**
|
|
70
87
|
* Goal mode for this run. When set, the engine runs loop-until-done:
|
|
71
88
|
* on each natural completion a GoalStopHook judges whether this goal is
|
|
@@ -103,6 +120,19 @@ export interface InjectParams {
|
|
|
103
120
|
sessionId: string;
|
|
104
121
|
content: string;
|
|
105
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
|
+
}
|
|
106
136
|
/** Update runtime configuration. */
|
|
107
137
|
export interface ConfigureParams {
|
|
108
138
|
/** When present, configure that specific chat session. Otherwise worker-global. */
|
|
@@ -229,8 +259,24 @@ export declare const Methods: {
|
|
|
229
259
|
readonly Query: "agent/query";
|
|
230
260
|
/** Inject context into transcript without triggering LLM. */
|
|
231
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";
|
|
232
266
|
/** Close (destroy) a session. */
|
|
233
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";
|
|
234
280
|
readonly StreamEvent: "agent/streamEvent";
|
|
235
281
|
readonly ApprovalRequest: "agent/approvalRequest";
|
|
236
282
|
readonly Status: "agent/status";
|
package/dist/protocol/types.js
CHANGED
|
@@ -35,8 +35,24 @@ export const Methods = {
|
|
|
35
35
|
Query: "agent/query",
|
|
36
36
|
/** Inject context into transcript without triggering LLM. */
|
|
37
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",
|
|
38
42
|
/** Close (destroy) a session. */
|
|
39
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",
|
|
40
56
|
// Server → Client (notifications, no id)
|
|
41
57
|
StreamEvent: "agent/streamEvent",
|
|
42
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 {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code-review prompt builder (TODO 7.3). Produces the instruction sent to the
|
|
3
|
+
* model for `/review`. Pure + testable — the TUI/desktop command gathers the
|
|
4
|
+
* diff or file contents and calls this; the model does the actual reasoning.
|
|
5
|
+
*
|
|
6
|
+
* Findings are structured: priority P0–P3, a confidence score, and a precise
|
|
7
|
+
* location, so the output is consistent and (optionally) machine-readable for
|
|
8
|
+
* CI/CD via `--json`.
|
|
9
|
+
*/
|
|
10
|
+
export type ReviewDimension = "security" | "performance" | "readability" | "correctness";
|
|
11
|
+
export declare const ALL_DIMENSIONS: ReviewDimension[];
|
|
12
|
+
export interface ReviewPromptOptions {
|
|
13
|
+
/** The unified diff (incremental) or full file contents to review. */
|
|
14
|
+
content: string;
|
|
15
|
+
/** Which dimensions to weigh. Defaults to all four. */
|
|
16
|
+
dimensions?: ReviewDimension[];
|
|
17
|
+
/** True when reviewing a diff (incremental); false when reviewing whole files. */
|
|
18
|
+
incremental?: boolean;
|
|
19
|
+
/** Emit a machine-readable JSON findings array (for CI/CD) instead of prose. */
|
|
20
|
+
json?: boolean;
|
|
21
|
+
/** Optional label for what's under review (e.g. a file path). */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** Truncate content to this many chars (default 12000). */
|
|
24
|
+
maxChars?: number;
|
|
25
|
+
}
|
|
26
|
+
/** Normalize a comma/space list of dimension names; invalid names dropped. */
|
|
27
|
+
export declare function parseDimensions(input: string | undefined): ReviewDimension[];
|
|
28
|
+
export declare function buildReviewPrompt(opts: ReviewPromptOptions): string;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code-review prompt builder (TODO 7.3). Produces the instruction sent to the
|
|
3
|
+
* model for `/review`. Pure + testable — the TUI/desktop command gathers the
|
|
4
|
+
* diff or file contents and calls this; the model does the actual reasoning.
|
|
5
|
+
*
|
|
6
|
+
* Findings are structured: priority P0–P3, a confidence score, and a precise
|
|
7
|
+
* location, so the output is consistent and (optionally) machine-readable for
|
|
8
|
+
* CI/CD via `--json`.
|
|
9
|
+
*/
|
|
10
|
+
export const ALL_DIMENSIONS = [
|
|
11
|
+
"correctness",
|
|
12
|
+
"security",
|
|
13
|
+
"performance",
|
|
14
|
+
"readability",
|
|
15
|
+
];
|
|
16
|
+
const DIMENSION_LABEL = {
|
|
17
|
+
security: "安全 (injection, authz, secret leakage, unsafe deserialization)",
|
|
18
|
+
performance: "性能 (N+1, needless allocation, blocking I/O, complexity)",
|
|
19
|
+
readability: "可读性 (naming, structure, dead code, comment accuracy)",
|
|
20
|
+
correctness: "正确性 (logic bugs, edge cases, error handling, races)",
|
|
21
|
+
};
|
|
22
|
+
/** Normalize a comma/space list of dimension names; invalid names dropped. */
|
|
23
|
+
export function parseDimensions(input) {
|
|
24
|
+
if (!input)
|
|
25
|
+
return ALL_DIMENSIONS;
|
|
26
|
+
const wanted = input
|
|
27
|
+
.split(/[\s,]+/)
|
|
28
|
+
.map((s) => s.trim().toLowerCase())
|
|
29
|
+
.filter(Boolean);
|
|
30
|
+
const picked = ALL_DIMENSIONS.filter((d) => wanted.includes(d));
|
|
31
|
+
return picked.length > 0 ? picked : ALL_DIMENSIONS;
|
|
32
|
+
}
|
|
33
|
+
const PRIORITY_GUIDE = "Priority: P0 = must fix before merge (data loss, security hole, crash); " +
|
|
34
|
+
"P1 = should fix (likely bug, real risk); " +
|
|
35
|
+
"P2 = nice to fix (smell, minor inefficiency); " +
|
|
36
|
+
"P3 = optional (style, nit).";
|
|
37
|
+
export function buildReviewPrompt(opts) {
|
|
38
|
+
const dims = opts.dimensions?.length ? opts.dimensions : ALL_DIMENSIONS;
|
|
39
|
+
const maxChars = opts.maxChars ?? 12_000;
|
|
40
|
+
const body = opts.content.length > maxChars
|
|
41
|
+
? opts.content.slice(0, maxChars) + "\n…(truncated)…"
|
|
42
|
+
: opts.content;
|
|
43
|
+
const fence = opts.incremental === false ? "" : "diff";
|
|
44
|
+
const what = opts.incremental === false ? "code" : "code changes (diff)";
|
|
45
|
+
const subject = opts.label ? ` for \`${opts.label}\`` : "";
|
|
46
|
+
const dimLines = dims.map((d) => ` - ${DIMENSION_LABEL[d]}`).join("\n");
|
|
47
|
+
if (opts.json) {
|
|
48
|
+
return [
|
|
49
|
+
`Review the following ${what}${subject} across these dimensions:`,
|
|
50
|
+
dimLines,
|
|
51
|
+
``,
|
|
52
|
+
PRIORITY_GUIDE,
|
|
53
|
+
``,
|
|
54
|
+
`Respond with ONLY a JSON object (no prose, no markdown fence) of the form:`,
|
|
55
|
+
`{"summary": string, "findings": [{"priority": "P0"|"P1"|"P2"|"P3", ` +
|
|
56
|
+
`"dimension": ${dims.map((d) => `"${d}"`).join("|")}, ` +
|
|
57
|
+
`"confidence": number /*0..1*/, "location": string /*file:line*/, ` +
|
|
58
|
+
`"title": string, "detail": string, "suggestion": string}]}`,
|
|
59
|
+
`Order findings by priority then confidence. Omit a finding rather than guess.`,
|
|
60
|
+
``,
|
|
61
|
+
"```" + fence,
|
|
62
|
+
body,
|
|
63
|
+
"```",
|
|
64
|
+
].join("\n");
|
|
65
|
+
}
|
|
66
|
+
return [
|
|
67
|
+
`Review the following ${what}${subject} across these dimensions:`,
|
|
68
|
+
dimLines,
|
|
69
|
+
``,
|
|
70
|
+
PRIORITY_GUIDE,
|
|
71
|
+
``,
|
|
72
|
+
`For each finding, give: **[P0-P3]** a short title, the location (file:line), ` +
|
|
73
|
+
`your confidence (low/med/high), what's wrong, and a concrete fix.`,
|
|
74
|
+
`Start with a one-line summary, then list findings ordered by priority. ` +
|
|
75
|
+
`If nothing warrants a finding, say so plainly. Don't pad with nits to look thorough.`,
|
|
76
|
+
``,
|
|
77
|
+
"```" + fence,
|
|
78
|
+
body,
|
|
79
|
+
"```",
|
|
80
|
+
].join("\n");
|
|
81
|
+
}
|
package/dist/run/FileRunStore.js
CHANGED
|
@@ -126,9 +126,14 @@ export class FileRunStore {
|
|
|
126
126
|
}
|
|
127
127
|
// Sort by createdAt descending (newest first)
|
|
128
128
|
snapshots.sort((a, b) => b.createdAt - a.createdAt);
|
|
129
|
-
// Pagination
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
// Pagination. Clamp to sane bounds before slicing: a negative offset would
|
|
130
|
+
// make Array.slice count "from the end" and silently return a surprise tail
|
|
131
|
+
// window; a negative limit would drop elements off the end. Both nonsensical
|
|
132
|
+
// for pagination — clamp offset≥0, treat a non-positive limit as an empty page.
|
|
133
|
+
const rawOffset = query?.offset ?? 0;
|
|
134
|
+
const rawLimit = query?.limit ?? 50;
|
|
135
|
+
const offset = Number.isFinite(rawOffset) && rawOffset > 0 ? Math.floor(rawOffset) : 0;
|
|
136
|
+
const limit = Number.isFinite(rawLimit) && rawLimit > 0 ? Math.floor(rawLimit) : 0;
|
|
132
137
|
return snapshots.slice(offset, offset + limit);
|
|
133
138
|
}
|
|
134
139
|
async delete(runId) {
|
|
@@ -24,8 +24,15 @@ export class RunApprovalBackend {
|
|
|
24
24
|
}
|
|
25
25
|
async requestApproval(request) {
|
|
26
26
|
if (!this.hooks) {
|
|
27
|
-
// No hooks wired —
|
|
28
|
-
|
|
27
|
+
// No hooks wired — fail CLOSED. This backend is the engine's approval
|
|
28
|
+
// path for an interactive run; if a host forgot to setHooks() there is
|
|
29
|
+
// no UI to ask, so auto-approving every tool (the old behavior) silently
|
|
30
|
+
// bypassed all approval. Denying is the safe default — a misconfigured
|
|
31
|
+
// run refuses tools instead of running `rm -rf /` unattended. (§5.6 #15)
|
|
32
|
+
return {
|
|
33
|
+
approved: false,
|
|
34
|
+
reason: "run approval backend has no lifecycle hooks wired (denied fail-closed)",
|
|
35
|
+
};
|
|
29
36
|
}
|
|
30
37
|
// Notify RunManager that approval is needed
|
|
31
38
|
const { approvalId } = await this.hooks.onApprovalNeeded(request);
|
|
@@ -64,12 +71,25 @@ export class RunApprovalBackend {
|
|
|
64
71
|
*/
|
|
65
72
|
export function createRunAskUserFn(hooks) {
|
|
66
73
|
let pending = null;
|
|
74
|
+
const supersedePending = () => {
|
|
75
|
+
// A run suspends on a single input at a time (RunManager resolves via one
|
|
76
|
+
// handle). If a second ask arrives while one is still pending, the old
|
|
77
|
+
// code overwrote the slot and the first promise hung forever. Reject the
|
|
78
|
+
// prior one so its awaiter unblocks instead of leaking. (§5.6 #15)
|
|
79
|
+
if (pending) {
|
|
80
|
+
pending.reject(new Error("superseded: a newer AskUser request replaced this one before it was answered"));
|
|
81
|
+
pending = null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
67
84
|
const askUserFn = async (question) => {
|
|
68
85
|
// Notify RunManager
|
|
69
86
|
await hooks.onInputNeeded(question);
|
|
70
|
-
// Suspend execution until user provides input
|
|
71
|
-
|
|
72
|
-
|
|
87
|
+
// Suspend execution until user provides input. The supersede check runs
|
|
88
|
+
// here — AFTER the await — so it sees a `pending` set by an earlier ask
|
|
89
|
+
// whose own await already resolved, rather than racing the assignment.
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
supersedePending();
|
|
92
|
+
pending = { resolve, reject, question };
|
|
73
93
|
});
|
|
74
94
|
};
|
|
75
95
|
const resolveInput = (answer) => {
|
package/dist/run/RunManager.d.ts
CHANGED
|
@@ -49,10 +49,22 @@ export declare class RunManager {
|
|
|
49
49
|
private readonly abortControllers;
|
|
50
50
|
/** Active execution handles — used to resolve pending approvals/input while Engine is suspended */
|
|
51
51
|
private readonly executionHandles;
|
|
52
|
+
/**
|
|
53
|
+
* Runs with a resume()/cancel() decision currently being applied. Guards the
|
|
54
|
+
* approval/input resume race: resume() and cancel() each have multiple await
|
|
55
|
+
* points, and the status check at the top of resume() reads a value that
|
|
56
|
+
* stays `waiting_*` until a later `await transition()` lands. Two concurrent
|
|
57
|
+
* resumes (double-click approve), or resume racing cancel, would both pass
|
|
58
|
+
* that check and both drive transitions / resolve the handle. The handle's
|
|
59
|
+
* resolve is idempotent, but the duplicate transitions and (worse) the
|
|
60
|
+
* mismatched-input re-queue path are not. We serialize per-run here.
|
|
61
|
+
*/
|
|
62
|
+
private readonly resolvingRuns;
|
|
52
63
|
constructor(config: RunManagerConfig);
|
|
53
64
|
submit(input: SubmitRunInput): Promise<RunSnapshot>;
|
|
54
65
|
start(runId: string): Promise<void>;
|
|
55
66
|
resume(runId: string, input?: ResumeRunInput): Promise<void>;
|
|
67
|
+
private resumeInner;
|
|
56
68
|
cancel(runId: string, reason?: string): Promise<void>;
|
|
57
69
|
get(runId: string): Promise<RunSnapshot | null>;
|
|
58
70
|
list(query?: ListRunsQuery): Promise<RunSnapshot[]>;
|