@kenkaiiii/gg-engine 0.0.0-stage → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/NOTICE +43 -0
- package/README.md +53 -2
- package/assets/skills/bulletproof/SKILL.md +132 -0
- package/assets/skills/bulletproof/references/agent-surface.md +113 -0
- package/assets/skills/bulletproof/references/attack-classes.md +226 -0
- package/assets/skills/bulletproof/references/audit-protocol.md +232 -0
- package/assets/skills/bulletproof/references/platform-playbooks.md +196 -0
- package/assets/skills/bulletproof/references/provenance.md +146 -0
- package/assets/skills/bulletproof/references/secure-defaults.md +137 -0
- package/assets/skills/bulletproof/references/supply-chain.md +84 -0
- package/assets/skills/bulletproof/references/threat-landscape.md +66 -0
- package/assets/skills/bulletproof/references/verification.md +74 -0
- package/assets/skills/compliance-guard/SKILL.md +115 -0
- package/assets/skills/compliance-guard/references/artifacts.md +199 -0
- package/assets/skills/compliance-guard/references/eu-uk.md +162 -0
- package/assets/skills/compliance-guard/references/exposure-triage.md +177 -0
- package/assets/skills/compliance-guard/references/full-review.md +155 -0
- package/assets/skills/compliance-guard/references/lawsuit-vectors.md +153 -0
- package/assets/skills/compliance-guard/references/provenance.md +135 -0
- package/assets/skills/compliance-guard/references/sector-gates.md +187 -0
- package/assets/skills/compliance-guard/references/security-baseline.md +117 -0
- package/assets/skills/compliance-guard/references/trigger-map.md +177 -0
- package/assets/skills/compliance-guard/references/us.md +194 -0
- package/assets/skills/durable/SKILL.md +114 -0
- package/assets/skills/durable/references/agent-db-safety.md +76 -0
- package/assets/skills/durable/references/backups-and-runtime.md +93 -0
- package/assets/skills/durable/references/migrations-and-schema.md +87 -0
- package/assets/skills/gg-guide/SKILL.md +43 -0
- package/assets/skills/gg-guide/references/chat-motion-goals.md +217 -0
- package/assets/skills/gg-guide/references/checklist-and-safety.md +177 -0
- package/assets/skills/gg-guide/references/code-mode.md +272 -0
- package/assets/skills/gg-guide/references/getting-started.md +295 -0
- package/assets/skills/gg-guide/references/ken-and-autopilot.md +172 -0
- package/assets/skills/gg-guide/references/mcp-and-skills.md +204 -0
- package/assets/skills/gg-guide/references/models-and-sign-in.md +200 -0
- package/assets/skills/gg-guide/references/sessions-and-history.md +213 -0
- package/assets/skills/gg-guide/references/settings.md +193 -0
- package/assets/skills/gg-guide/references/troubleshooting-and-data.md +186 -0
- package/assets/skills/lean/SKILL.md +117 -0
- package/assets/skills/lean/references/memory-and-processes.md +99 -0
- package/assets/skills/lean/references/playbooks.md +134 -0
- package/dist/app-error.d.ts +22 -0
- package/dist/app-error.js +41 -0
- package/dist/app-error.js.map +1 -0
- package/dist/config.d.ts +90 -0
- package/dist/config.js +240 -0
- package/dist/config.js.map +1 -0
- package/dist/core/acceptance-checks.d.ts +48 -0
- package/dist/core/acceptance-checks.js +151 -0
- package/dist/core/acceptance-checks.js.map +1 -0
- package/dist/core/action-threats.d.ts +68 -0
- package/dist/core/action-threats.js +894 -0
- package/dist/core/action-threats.js.map +1 -0
- package/dist/core/agent-notifications.d.ts +79 -0
- package/dist/core/agent-notifications.js +125 -0
- package/dist/core/agent-notifications.js.map +1 -0
- package/dist/core/agent-session/helpers.d.ts +26 -0
- package/dist/core/agent-session/helpers.js +47 -0
- package/dist/core/agent-session/helpers.js.map +1 -0
- package/dist/core/agent-session/mcp-tools.d.ts +87 -0
- package/dist/core/agent-session/mcp-tools.js +227 -0
- package/dist/core/agent-session/mcp-tools.js.map +1 -0
- package/dist/core/agent-session/run-loop-monitor.d.ts +63 -0
- package/dist/core/agent-session/run-loop-monitor.js +164 -0
- package/dist/core/agent-session/run-loop-monitor.js.map +1 -0
- package/dist/core/agent-session/transcript-markers.d.ts +57 -0
- package/dist/core/agent-session/transcript-markers.js +166 -0
- package/dist/core/agent-session/transcript-markers.js.map +1 -0
- package/dist/core/agent-session/verification-tracker.d.ts +71 -0
- package/dist/core/agent-session/verification-tracker.js +295 -0
- package/dist/core/agent-session/verification-tracker.js.map +1 -0
- package/dist/core/agent-session.d.ts +1401 -0
- package/dist/core/agent-session.js +5160 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/agents.d.ts +63 -0
- package/dist/core/agents.js +160 -0
- package/dist/core/agents.js.map +1 -0
- package/dist/core/ask-user.d.ts +163 -0
- package/dist/core/ask-user.js +178 -0
- package/dist/core/ask-user.js.map +1 -0
- package/dist/core/auto-update.d.ts +32 -0
- package/dist/core/auto-update.js +218 -0
- package/dist/core/auto-update.js.map +1 -0
- package/dist/core/autopilot-cycle.d.ts +127 -0
- package/dist/core/autopilot-cycle.js +182 -0
- package/dist/core/autopilot-cycle.js.map +1 -0
- package/dist/core/autopilot-gate.d.ts +106 -0
- package/dist/core/autopilot-gate.js +192 -0
- package/dist/core/autopilot-gate.js.map +1 -0
- package/dist/core/autopilot-verdict.d.ts +55 -0
- package/dist/core/autopilot-verdict.js +226 -0
- package/dist/core/autopilot-verdict.js.map +1 -0
- package/dist/core/blocked-packages-file.d.ts +33 -0
- package/dist/core/blocked-packages-file.js +274 -0
- package/dist/core/blocked-packages-file.js.map +1 -0
- package/dist/core/bundled-agents.d.ts +2 -0
- package/dist/core/bundled-agents.js +253 -0
- package/dist/core/bundled-agents.js.map +1 -0
- package/dist/core/cache-diagnostics.d.ts +72 -0
- package/dist/core/cache-diagnostics.js +200 -0
- package/dist/core/cache-diagnostics.js.map +1 -0
- package/dist/core/cache-expiry.d.ts +89 -0
- package/dist/core/cache-expiry.js +117 -0
- package/dist/core/cache-expiry.js.map +1 -0
- package/dist/core/checklist-detection.d.ts +8 -0
- package/dist/core/checklist-detection.js +238 -0
- package/dist/core/checklist-detection.js.map +1 -0
- package/dist/core/checklist-git.d.ts +19 -0
- package/dist/core/checklist-git.js +54 -0
- package/dist/core/checklist-git.js.map +1 -0
- package/dist/core/checklist-items.d.ts +182 -0
- package/dist/core/checklist-items.js +228 -0
- package/dist/core/checklist-items.js.map +1 -0
- package/dist/core/checklist-prompt.d.ts +14 -0
- package/dist/core/checklist-prompt.js +64 -0
- package/dist/core/checklist-prompt.js.map +1 -0
- package/dist/core/checklist-snapshot.d.ts +7 -0
- package/dist/core/checklist-snapshot.js +46 -0
- package/dist/core/checklist-snapshot.js.map +1 -0
- package/dist/core/checklist-store.d.ts +45 -0
- package/dist/core/checklist-store.js +281 -0
- package/dist/core/checklist-store.js.map +1 -0
- package/dist/core/checkout-record.d.ts +22 -0
- package/dist/core/checkout-record.js +68 -0
- package/dist/core/checkout-record.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +109 -0
- package/dist/core/checkpoint-store.js +260 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/claude-code/complete.d.ts +35 -0
- package/dist/core/claude-code/complete.js +125 -0
- package/dist/core/claude-code/complete.js.map +1 -0
- package/dist/core/claude-code/events.d.ts +67 -0
- package/dist/core/claude-code/events.js +460 -0
- package/dist/core/claude-code/events.js.map +1 -0
- package/dist/core/claude-code/live-session.d.ts +94 -0
- package/dist/core/claude-code/live-session.js +525 -0
- package/dist/core/claude-code/live-session.js.map +1 -0
- package/dist/core/claude-code/loop.d.ts +9 -0
- package/dist/core/claude-code/loop.js +15 -0
- package/dist/core/claude-code/loop.js.map +1 -0
- package/dist/core/claude-code/session-sync.d.ts +28 -0
- package/dist/core/claude-code/session-sync.js +53 -0
- package/dist/core/claude-code/session-sync.js.map +1 -0
- package/dist/core/claude-code/tool-bridge.d.ts +49 -0
- package/dist/core/claude-code/tool-bridge.js +352 -0
- package/dist/core/claude-code/tool-bridge.js.map +1 -0
- package/dist/core/claude-code/transcripts.d.ts +39 -0
- package/dist/core/claude-code/transcripts.js +195 -0
- package/dist/core/claude-code/transcripts.js.map +1 -0
- package/dist/core/code-retrieval-chunkers.d.ts +26 -0
- package/dist/core/code-retrieval-chunkers.js +264 -0
- package/dist/core/code-retrieval-chunkers.js.map +1 -0
- package/dist/core/code-retrieval.d.ts +18 -0
- package/dist/core/code-retrieval.js +124 -0
- package/dist/core/code-retrieval.js.map +1 -0
- package/dist/core/codex-request-shape.d.ts +7 -0
- package/dist/core/codex-request-shape.js +19 -0
- package/dist/core/codex-request-shape.js.map +1 -0
- package/dist/core/compaction/active-context.d.ts +16 -0
- package/dist/core/compaction/active-context.js +20 -0
- package/dist/core/compaction/active-context.js.map +1 -0
- package/dist/core/compaction/compactor.d.ts +281 -0
- package/dist/core/compaction/compactor.js +1451 -0
- package/dist/core/compaction/compactor.js.map +1 -0
- package/dist/core/compaction/plan-step-policy.d.ts +46 -0
- package/dist/core/compaction/plan-step-policy.js +57 -0
- package/dist/core/compaction/plan-step-policy.js.map +1 -0
- package/dist/core/compaction/policy.d.ts +36 -0
- package/dist/core/compaction/policy.js +144 -0
- package/dist/core/compaction/policy.js.map +1 -0
- package/dist/core/compaction/query-aware-selector.d.ts +32 -0
- package/dist/core/compaction/query-aware-selector.js +202 -0
- package/dist/core/compaction/query-aware-selector.js.map +1 -0
- package/dist/core/compaction/token-estimator.d.ts +36 -0
- package/dist/core/compaction/token-estimator.js +180 -0
- package/dist/core/compaction/token-estimator.js.map +1 -0
- package/dist/core/compaction/tool-result-pruner.d.ts +90 -0
- package/dist/core/compaction/tool-result-pruner.js +238 -0
- package/dist/core/compaction/tool-result-pruner.js.map +1 -0
- package/dist/core/completion-review.d.ts +24 -0
- package/dist/core/completion-review.js +2 -0
- package/dist/core/completion-review.js.map +1 -0
- package/dist/core/context-files.d.ts +8 -0
- package/dist/core/context-files.js +46 -0
- package/dist/core/context-files.js.map +1 -0
- package/dist/core/context-limits.d.ts +40 -0
- package/dist/core/context-limits.js +43 -0
- package/dist/core/context-limits.js.map +1 -0
- package/dist/core/custom-commands.d.ts +18 -0
- package/dist/core/custom-commands.js +57 -0
- package/dist/core/custom-commands.js.map +1 -0
- package/dist/core/destructive-git-guard.d.ts +113 -0
- package/dist/core/destructive-git-guard.js +874 -0
- package/dist/core/destructive-git-guard.js.map +1 -0
- package/dist/core/display-items.d.ts +8 -0
- package/dist/core/display-items.js +2 -0
- package/dist/core/display-items.js.map +1 -0
- package/dist/core/encode-cwd.d.ts +41 -0
- package/dist/core/encode-cwd.js +53 -0
- package/dist/core/encode-cwd.js.map +1 -0
- package/dist/core/env-delta.d.ts +34 -0
- package/dist/core/env-delta.js +84 -0
- package/dist/core/env-delta.js.map +1 -0
- package/dist/core/event-bus.d.ts +178 -0
- package/dist/core/event-bus.js +171 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +7 -0
- package/dist/core/extensions/loader.js +68 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/plugin-bundles.d.ts +13 -0
- package/dist/core/extensions/plugin-bundles.js +45 -0
- package/dist/core/extensions/plugin-bundles.js.map +1 -0
- package/dist/core/extensions/types.d.ts +18 -0
- package/dist/core/extensions/types.js +2 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/foreign-session-import.d.ts +119 -0
- package/dist/core/foreign-session-import.js +598 -0
- package/dist/core/foreign-session-import.js.map +1 -0
- package/dist/core/foreign-transcript-blocks.d.ts +50 -0
- package/dist/core/foreign-transcript-blocks.js +151 -0
- package/dist/core/foreign-transcript-blocks.js.map +1 -0
- package/dist/core/frontmatter.d.ts +22 -0
- package/dist/core/frontmatter.js +90 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/goal-run-marker.d.ts +32 -0
- package/dist/core/goal-run-marker.js +178 -0
- package/dist/core/goal-run-marker.js.map +1 -0
- package/dist/core/goal-summary.d.ts +15 -0
- package/dist/core/goal-summary.js +110 -0
- package/dist/core/goal-summary.js.map +1 -0
- package/dist/core/goals-store.d.ts +208 -0
- package/dist/core/goals-store.js +577 -0
- package/dist/core/goals-store.js.map +1 -0
- package/dist/core/hashline.d.ts +51 -0
- package/dist/core/hashline.js +76 -0
- package/dist/core/hashline.js.map +1 -0
- package/dist/core/idle-wake.d.ts +62 -0
- package/dist/core/idle-wake.js +103 -0
- package/dist/core/idle-wake.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/injection-detect.d.ts +39 -0
- package/dist/core/injection-detect.js +241 -0
- package/dist/core/injection-detect.js.map +1 -0
- package/dist/core/installed-threats.d.ts +23 -0
- package/dist/core/installed-threats.js +71 -0
- package/dist/core/installed-threats.js.map +1 -0
- package/dist/core/internal-diagnostics.d.ts +159 -0
- package/dist/core/internal-diagnostics.js +495 -0
- package/dist/core/internal-diagnostics.js.map +1 -0
- package/dist/core/keep-awake.d.ts +88 -0
- package/dist/core/keep-awake.js +251 -0
- package/dist/core/keep-awake.js.map +1 -0
- package/dist/core/ken-ask-answer.d.ts +24 -0
- package/dist/core/ken-ask-answer.js +96 -0
- package/dist/core/ken-ask-answer.js.map +1 -0
- package/dist/core/ken-context.d.ts +119 -0
- package/dist/core/ken-context.js +447 -0
- package/dist/core/ken-context.js.map +1 -0
- package/dist/core/ken-model.d.ts +45 -0
- package/dist/core/ken-model.js +26 -0
- package/dist/core/ken-model.js.map +1 -0
- package/dist/core/ken-prompt.d.ts +21 -0
- package/dist/core/ken-prompt.js +370 -0
- package/dist/core/ken-prompt.js.map +1 -0
- package/dist/core/language-detector.d.ts +41 -0
- package/dist/core/language-detector.js +293 -0
- package/dist/core/language-detector.js.map +1 -0
- package/dist/core/live-preview.d.ts +26 -0
- package/dist/core/live-preview.js +80 -0
- package/dist/core/live-preview.js.map +1 -0
- package/dist/core/local-endpoint-store.d.ts +53 -0
- package/dist/core/local-endpoint-store.js +221 -0
- package/dist/core/local-endpoint-store.js.map +1 -0
- package/dist/core/logger.d.ts +21 -0
- package/dist/core/logger.js +94 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/loop-breaker.d.ts +89 -0
- package/dist/core/loop-breaker.js +204 -0
- package/dist/core/loop-breaker.js.map +1 -0
- package/dist/core/lsp/client.d.ts +206 -0
- package/dist/core/lsp/client.js +685 -0
- package/dist/core/lsp/client.js.map +1 -0
- package/dist/core/lsp/edit-telemetry.d.ts +26 -0
- package/dist/core/lsp/edit-telemetry.js +52 -0
- package/dist/core/lsp/edit-telemetry.js.map +1 -0
- package/dist/core/lsp/format.d.ts +11 -0
- package/dist/core/lsp/format.js +30 -0
- package/dist/core/lsp/format.js.map +1 -0
- package/dist/core/lsp/jsonrpc.d.ts +68 -0
- package/dist/core/lsp/jsonrpc.js +153 -0
- package/dist/core/lsp/jsonrpc.js.map +1 -0
- package/dist/core/lsp/manager.d.ts +188 -0
- package/dist/core/lsp/manager.js +576 -0
- package/dist/core/lsp/manager.js.map +1 -0
- package/dist/core/lsp/pool.d.ts +114 -0
- package/dist/core/lsp/pool.js +259 -0
- package/dist/core/lsp/pool.js.map +1 -0
- package/dist/core/lsp/project-root.d.ts +9 -0
- package/dist/core/lsp/project-root.js +75 -0
- package/dist/core/lsp/project-root.js.map +1 -0
- package/dist/core/lsp/reference-project.d.ts +6 -0
- package/dist/core/lsp/reference-project.js +110 -0
- package/dist/core/lsp/reference-project.js.map +1 -0
- package/dist/core/lsp/servers.d.ts +44 -0
- package/dist/core/lsp/servers.js +289 -0
- package/dist/core/lsp/servers.js.map +1 -0
- package/dist/core/lsp/test-support.d.ts +17 -0
- package/dist/core/lsp/test-support.js +27 -0
- package/dist/core/lsp/test-support.js.map +1 -0
- package/dist/core/mcp/catalog-cache.d.ts +64 -0
- package/dist/core/mcp/catalog-cache.js +166 -0
- package/dist/core/mcp/catalog-cache.js.map +1 -0
- package/dist/core/mcp/client.d.ts +317 -0
- package/dist/core/mcp/client.js +1168 -0
- package/dist/core/mcp/client.js.map +1 -0
- package/dist/core/mcp/content.d.ts +23 -0
- package/dist/core/mcp/content.js +194 -0
- package/dist/core/mcp/content.js.map +1 -0
- package/dist/core/mcp/defaults.d.ts +26 -0
- package/dist/core/mcp/defaults.js +81 -0
- package/dist/core/mcp/defaults.js.map +1 -0
- package/dist/core/mcp/deferred-catalog.d.ts +53 -0
- package/dist/core/mcp/deferred-catalog.js +117 -0
- package/dist/core/mcp/deferred-catalog.js.map +1 -0
- package/dist/core/mcp/elicitation-bridge.d.ts +40 -0
- package/dist/core/mcp/elicitation-bridge.js +36 -0
- package/dist/core/mcp/elicitation-bridge.js.map +1 -0
- package/dist/core/mcp/index.d.ts +16 -0
- package/dist/core/mcp/index.js +10 -0
- package/dist/core/mcp/index.js.map +1 -0
- package/dist/core/mcp/loopback.d.ts +26 -0
- package/dist/core/mcp/loopback.js +66 -0
- package/dist/core/mcp/loopback.js.map +1 -0
- package/dist/core/mcp/oauth-provider.d.ts +55 -0
- package/dist/core/mcp/oauth-provider.js +106 -0
- package/dist/core/mcp/oauth-provider.js.map +1 -0
- package/dist/core/mcp/oauth-store.d.ts +44 -0
- package/dist/core/mcp/oauth-store.js +76 -0
- package/dist/core/mcp/oauth-store.js.map +1 -0
- package/dist/core/mcp/parse-add-command.d.ts +50 -0
- package/dist/core/mcp/parse-add-command.js +391 -0
- package/dist/core/mcp/parse-add-command.js.map +1 -0
- package/dist/core/mcp/resolve-stdio.d.ts +77 -0
- package/dist/core/mcp/resolve-stdio.js +359 -0
- package/dist/core/mcp/resolve-stdio.js.map +1 -0
- package/dist/core/mcp/shared-pool.d.ts +157 -0
- package/dist/core/mcp/shared-pool.js +236 -0
- package/dist/core/mcp/shared-pool.js.map +1 -0
- package/dist/core/mcp/store.d.ts +100 -0
- package/dist/core/mcp/store.js +202 -0
- package/dist/core/mcp/store.js.map +1 -0
- package/dist/core/mcp/tool-guard.d.ts +58 -0
- package/dist/core/mcp/tool-guard.js +215 -0
- package/dist/core/mcp/tool-guard.js.map +1 -0
- package/dist/core/mcp/types.d.ts +57 -0
- package/dist/core/mcp/types.js +2 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/message-images.d.ts +11 -0
- package/dist/core/message-images.js +52 -0
- package/dist/core/message-images.js.map +1 -0
- package/dist/core/model-unavailable.d.ts +14 -0
- package/dist/core/model-unavailable.js +23 -0
- package/dist/core/model-unavailable.js.map +1 -0
- package/dist/core/network-guard.d.ts +28 -0
- package/dist/core/network-guard.js +251 -0
- package/dist/core/network-guard.js.map +1 -0
- package/dist/core/node-debugger.d.ts +148 -0
- package/dist/core/node-debugger.js +642 -0
- package/dist/core/node-debugger.js.map +1 -0
- package/dist/core/opencode-catalog-store.d.ts +20 -0
- package/dist/core/opencode-catalog-store.js +82 -0
- package/dist/core/opencode-catalog-store.js.map +1 -0
- package/dist/core/openrouter-catalog-store.d.ts +24 -0
- package/dist/core/openrouter-catalog-store.js +140 -0
- package/dist/core/openrouter-catalog-store.js.map +1 -0
- package/dist/core/package-cooldown.d.ts +69 -0
- package/dist/core/package-cooldown.js +297 -0
- package/dist/core/package-cooldown.js.map +1 -0
- package/dist/core/package-threats.d.ts +92 -0
- package/dist/core/package-threats.js +1339 -0
- package/dist/core/package-threats.js.map +1 -0
- package/dist/core/parked-requests.d.ts +43 -0
- package/dist/core/parked-requests.js +34 -0
- package/dist/core/parked-requests.js.map +1 -0
- package/dist/core/persistent-shell.d.ts +81 -0
- package/dist/core/persistent-shell.js +452 -0
- package/dist/core/persistent-shell.js.map +1 -0
- package/dist/core/plan-delta.d.ts +23 -0
- package/dist/core/plan-delta.js +36 -0
- package/dist/core/plan-delta.js.map +1 -0
- package/dist/core/plan-handoff.d.ts +38 -0
- package/dist/core/plan-handoff.js +21 -0
- package/dist/core/plan-handoff.js.map +1 -0
- package/dist/core/plan-submission-gate.d.ts +28 -0
- package/dist/core/plan-submission-gate.js +27 -0
- package/dist/core/plan-submission-gate.js.map +1 -0
- package/dist/core/platform-clis.d.ts +15 -0
- package/dist/core/platform-clis.js +299 -0
- package/dist/core/platform-clis.js.map +1 -0
- package/dist/core/process-gate.d.ts +61 -0
- package/dist/core/process-gate.js +103 -0
- package/dist/core/process-gate.js.map +1 -0
- package/dist/core/process-manager.d.ts +242 -0
- package/dist/core/process-manager.js +902 -0
- package/dist/core/process-manager.js.map +1 -0
- package/dist/core/progress/engine.d.ts +22 -0
- package/dist/core/progress/engine.js +131 -0
- package/dist/core/progress/engine.js.map +1 -0
- package/dist/core/progress/git-xp.d.ts +15 -0
- package/dist/core/progress/git-xp.js +100 -0
- package/dist/core/progress/git-xp.js.map +1 -0
- package/dist/core/progress/ranks.d.ts +31 -0
- package/dist/core/progress/ranks.js +310 -0
- package/dist/core/progress/ranks.js.map +1 -0
- package/dist/core/progress/rebuild.d.ts +8 -0
- package/dist/core/progress/rebuild.js +125 -0
- package/dist/core/progress/rebuild.js.map +1 -0
- package/dist/core/progress/store.d.ts +34 -0
- package/dist/core/progress/store.js +200 -0
- package/dist/core/progress/store.js.map +1 -0
- package/dist/core/progress/types.d.ts +56 -0
- package/dist/core/progress/types.js +2 -0
- package/dist/core/progress/types.js.map +1 -0
- package/dist/core/project-discovery.d.ts +64 -0
- package/dist/core/project-discovery.js +908 -0
- package/dist/core/project-discovery.js.map +1 -0
- package/dist/core/project-files.d.ts +15 -0
- package/dist/core/project-files.js +37 -0
- package/dist/core/project-files.js.map +1 -0
- package/dist/core/project-health-scan.d.ts +109 -0
- package/dist/core/project-health-scan.js +673 -0
- package/dist/core/project-health-scan.js.map +1 -0
- package/dist/core/project-health-score.d.ts +41 -0
- package/dist/core/project-health-score.js +257 -0
- package/dist/core/project-health-score.js.map +1 -0
- package/dist/core/prompt-command-expansion.d.ts +13 -0
- package/dist/core/prompt-command-expansion.js +48 -0
- package/dist/core/prompt-command-expansion.js.map +1 -0
- package/dist/core/prompt-commands.d.ts +13 -0
- package/dist/core/prompt-commands.js +370 -0
- package/dist/core/prompt-commands.js.map +1 -0
- package/dist/core/pull-requests.d.ts +18 -0
- package/dist/core/pull-requests.js +95 -0
- package/dist/core/pull-requests.js.map +1 -0
- package/dist/core/radio-players.d.ts +28 -0
- package/dist/core/radio-players.js +132 -0
- package/dist/core/radio-players.js.map +1 -0
- package/dist/core/radio.d.ts +42 -0
- package/dist/core/radio.js +499 -0
- package/dist/core/radio.js.map +1 -0
- package/dist/core/regrounding.d.ts +37 -0
- package/dist/core/regrounding.js +89 -0
- package/dist/core/regrounding.js.map +1 -0
- package/dist/core/resolve-start.d.ts +28 -0
- package/dist/core/resolve-start.js +35 -0
- package/dist/core/resolve-start.js.map +1 -0
- package/dist/core/run-claim.d.ts +36 -0
- package/dist/core/run-claim.js +46 -0
- package/dist/core/run-claim.js.map +1 -0
- package/dist/core/run-lifecycle.d.ts +58 -0
- package/dist/core/run-lifecycle.js +104 -0
- package/dist/core/run-lifecycle.js.map +1 -0
- package/dist/core/run-status.d.ts +17 -0
- package/dist/core/run-status.js +28 -0
- package/dist/core/run-status.js.map +1 -0
- package/dist/core/runtime-mode.d.ts +21 -0
- package/dist/core/runtime-mode.js +43 -0
- package/dist/core/runtime-mode.js.map +1 -0
- package/dist/core/sandbox-domains.d.ts +13 -0
- package/dist/core/sandbox-domains.js +76 -0
- package/dist/core/sandbox-domains.js.map +1 -0
- package/dist/core/sandbox-feedback.d.ts +21 -0
- package/dist/core/sandbox-feedback.js +69 -0
- package/dist/core/sandbox-feedback.js.map +1 -0
- package/dist/core/sandbox.d.ts +106 -0
- package/dist/core/sandbox.js +383 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/semantic-loop-check.d.ts +58 -0
- package/dist/core/semantic-loop-check.js +103 -0
- package/dist/core/semantic-loop-check.js.map +1 -0
- package/dist/core/session-compaction.d.ts +23 -0
- package/dist/core/session-compaction.js +54 -0
- package/dist/core/session-compaction.js.map +1 -0
- package/dist/core/session-export.d.ts +97 -0
- package/dist/core/session-export.js +368 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-history.d.ts +160 -0
- package/dist/core/session-history.js +467 -0
- package/dist/core/session-history.js.map +1 -0
- package/dist/core/session-manager.d.ts +512 -0
- package/dist/core/session-manager.js +1370 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/session-preview.d.ts +12 -0
- package/dist/core/session-preview.js +58 -0
- package/dist/core/session-preview.js.map +1 -0
- package/dist/core/session-storage.d.ts +78 -0
- package/dist/core/session-storage.js +659 -0
- package/dist/core/session-storage.js.map +1 -0
- package/dist/core/session-summary-index.d.ts +51 -0
- package/dist/core/session-summary-index.js +192 -0
- package/dist/core/session-summary-index.js.map +1 -0
- package/dist/core/settings-manager.d.ts +113 -0
- package/dist/core/settings-manager.js +281 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/shared-checkout-guard.d.ts +78 -0
- package/dist/core/shared-checkout-guard.js +219 -0
- package/dist/core/shared-checkout-guard.js.map +1 -0
- package/dist/core/shell-path.d.ts +13 -0
- package/dist/core/shell-path.js +175 -0
- package/dist/core/shell-path.js.map +1 -0
- package/dist/core/shell-threats-popular-packages.d.ts +11 -0
- package/dist/core/shell-threats-popular-packages.js +675 -0
- package/dist/core/shell-threats-popular-packages.js.map +1 -0
- package/dist/core/shell-threats.d.ts +21 -0
- package/dist/core/shell-threats.js +235 -0
- package/dist/core/shell-threats.js.map +1 -0
- package/dist/core/shell.d.ts +54 -0
- package/dist/core/shell.js +99 -0
- package/dist/core/shell.js.map +1 -0
- package/dist/core/shutdown.d.ts +70 -0
- package/dist/core/shutdown.js +144 -0
- package/dist/core/shutdown.js.map +1 -0
- package/dist/core/skill-scan.d.ts +112 -0
- package/dist/core/skill-scan.js +781 -0
- package/dist/core/skill-scan.js.map +1 -0
- package/dist/core/skills.d.ts +80 -0
- package/dist/core/skills.js +270 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +58 -0
- package/dist/core/slash-commands.js +242 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/steering.d.ts +47 -0
- package/dist/core/steering.js +65 -0
- package/dist/core/steering.js.map +1 -0
- package/dist/core/steroids.d.ts +66 -0
- package/dist/core/steroids.js +243 -0
- package/dist/core/steroids.js.map +1 -0
- package/dist/core/stream-diag-level.d.ts +3 -0
- package/dist/core/stream-diag-level.js +24 -0
- package/dist/core/stream-diag-level.js.map +1 -0
- package/dist/core/stream-rules.d.ts +30 -0
- package/dist/core/stream-rules.js +151 -0
- package/dist/core/stream-rules.js.map +1 -0
- package/dist/core/subagent-manager.d.ts +242 -0
- package/dist/core/subagent-manager.js +1075 -0
- package/dist/core/subagent-manager.js.map +1 -0
- package/dist/core/subagent-policy.d.ts +9 -0
- package/dist/core/subagent-policy.js +41 -0
- package/dist/core/subagent-policy.js.map +1 -0
- package/dist/core/subagent-receipt.d.ts +54 -0
- package/dist/core/subagent-receipt.js +274 -0
- package/dist/core/subagent-receipt.js.map +1 -0
- package/dist/core/subagent-store.d.ts +41 -0
- package/dist/core/subagent-store.js +284 -0
- package/dist/core/subagent-store.js.map +1 -0
- package/dist/core/subagent-turn-record.d.ts +18 -0
- package/dist/core/subagent-turn-record.js +82 -0
- package/dist/core/subagent-turn-record.js.map +1 -0
- package/dist/core/tasks-store.d.ts +31 -0
- package/dist/core/tasks-store.js +97 -0
- package/dist/core/tasks-store.js.map +1 -0
- package/dist/core/telegram-config.d.ts +20 -0
- package/dist/core/telegram-config.js +52 -0
- package/dist/core/telegram-config.js.map +1 -0
- package/dist/core/telegram.d.ts +114 -0
- package/dist/core/telegram.js +275 -0
- package/dist/core/telegram.js.map +1 -0
- package/dist/core/temp-paths.d.ts +5 -0
- package/dist/core/temp-paths.js +50 -0
- package/dist/core/temp-paths.js.map +1 -0
- package/dist/core/test-impact.d.ts +73 -0
- package/dist/core/test-impact.js +467 -0
- package/dist/core/test-impact.js.map +1 -0
- package/dist/core/threat-feed.d.ts +65 -0
- package/dist/core/threat-feed.js +334 -0
- package/dist/core/threat-feed.js.map +1 -0
- package/dist/core/trophies/catalog-more.d.ts +2 -0
- package/dist/core/trophies/catalog-more.js +837 -0
- package/dist/core/trophies/catalog-more.js.map +1 -0
- package/dist/core/trophies/catalog.d.ts +4 -0
- package/dist/core/trophies/catalog.js +649 -0
- package/dist/core/trophies/catalog.js.map +1 -0
- package/dist/core/trophies/engine.d.ts +70 -0
- package/dist/core/trophies/engine.js +347 -0
- package/dist/core/trophies/engine.js.map +1 -0
- package/dist/core/trophies/store.d.ts +17 -0
- package/dist/core/trophies/store.js +113 -0
- package/dist/core/trophies/store.js.map +1 -0
- package/dist/core/trophies/types.d.ts +87 -0
- package/dist/core/trophies/types.js +74 -0
- package/dist/core/trophies/types.js.map +1 -0
- package/dist/core/ui-adoption.d.ts +32 -0
- package/dist/core/ui-adoption.js +302 -0
- package/dist/core/ui-adoption.js.map +1 -0
- package/dist/core/ui-compatibility.d.ts +10 -0
- package/dist/core/ui-compatibility.js +51 -0
- package/dist/core/ui-compatibility.js.map +1 -0
- package/dist/core/ui-registry.d.ts +101 -0
- package/dist/core/ui-registry.js +292 -0
- package/dist/core/ui-registry.js.map +1 -0
- package/dist/core/user-shell-context.d.ts +8 -0
- package/dist/core/user-shell-context.js +12 -0
- package/dist/core/user-shell-context.js.map +1 -0
- package/dist/core/verification-evidence.d.ts +49 -0
- package/dist/core/verification-evidence.js +816 -0
- package/dist/core/verification-evidence.js.map +1 -0
- package/dist/core/verification-gate.d.ts +77 -0
- package/dist/core/verification-gate.js +504 -0
- package/dist/core/verification-gate.js.map +1 -0
- package/dist/core/verification-snapshot.d.ts +7 -0
- package/dist/core/verification-snapshot.js +109 -0
- package/dist/core/verification-snapshot.js.map +1 -0
- package/dist/core/verify-commands.d.ts +34 -0
- package/dist/core/verify-commands.js +203 -0
- package/dist/core/verify-commands.js.map +1 -0
- package/dist/core/voice-transcriber.d.ts +32 -0
- package/dist/core/voice-transcriber.js +114 -0
- package/dist/core/voice-transcriber.js.map +1 -0
- package/dist/core/workspace-guard.d.ts +56 -0
- package/dist/core/workspace-guard.js +334 -0
- package/dist/core/workspace-guard.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +44 -0
- package/dist/session.js +105 -0
- package/dist/session.js.map +1 -0
- package/dist/system-prompt.d.ts +104 -0
- package/dist/system-prompt.js +480 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/test-support/fake-home.d.ts +19 -0
- package/dist/test-support/fake-home.js +37 -0
- package/dist/test-support/fake-home.js.map +1 -0
- package/dist/test-support/keep-alive.d.ts +14 -0
- package/dist/test-support/keep-alive.js +17 -0
- package/dist/test-support/keep-alive.js.map +1 -0
- package/dist/test-support/slow-git.d.ts +1 -0
- package/dist/test-support/slow-git.js +21 -0
- package/dist/test-support/slow-git.js.map +1 -0
- package/dist/test-support/system-tools.d.ts +6 -0
- package/dist/test-support/system-tools.js +36 -0
- package/dist/test-support/system-tools.js.map +1 -0
- package/dist/tools/ask-user.d.ts +34 -0
- package/dist/tools/ask-user.js +99 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/background-watch-lint.d.ts +18 -0
- package/dist/tools/background-watch-lint.js +102 -0
- package/dist/tools/background-watch-lint.js.map +1 -0
- package/dist/tools/bash-read-evidence.d.ts +23 -0
- package/dist/tools/bash-read-evidence.js +180 -0
- package/dist/tools/bash-read-evidence.js.map +1 -0
- package/dist/tools/bash.d.ts +64 -0
- package/dist/tools/bash.js +552 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/browser-api.d.ts +27 -0
- package/dist/tools/browser-api.js +449 -0
- package/dist/tools/browser-api.js.map +1 -0
- package/dist/tools/browser-sandbox.d.ts +16 -0
- package/dist/tools/browser-sandbox.js +158 -0
- package/dist/tools/browser-sandbox.js.map +1 -0
- package/dist/tools/browser-session.d.ts +84 -0
- package/dist/tools/browser-session.js +304 -0
- package/dist/tools/browser-session.js.map +1 -0
- package/dist/tools/browser-snapshot.d.ts +19 -0
- package/dist/tools/browser-snapshot.js +109 -0
- package/dist/tools/browser-snapshot.js.map +1 -0
- package/dist/tools/browser.d.ts +11 -0
- package/dist/tools/browser.js +106 -0
- package/dist/tools/browser.js.map +1 -0
- package/dist/tools/checklist.d.ts +49 -0
- package/dist/tools/checklist.js +154 -0
- package/dist/tools/checklist.js.map +1 -0
- package/dist/tools/compress.d.ts +56 -0
- package/dist/tools/compress.js +226 -0
- package/dist/tools/compress.js.map +1 -0
- package/dist/tools/debug.d.ts +54 -0
- package/dist/tools/debug.js +230 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/document-text.d.ts +6 -0
- package/dist/tools/document-text.js +154 -0
- package/dist/tools/document-text.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +123 -0
- package/dist/tools/edit-diff.js +476 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit-targets.d.ts +10 -0
- package/dist/tools/edit-targets.js +31 -0
- package/dist/tools/edit-targets.js.map +1 -0
- package/dist/tools/edit.d.ts +38 -0
- package/dist/tools/edit.js +695 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/enter-plan.d.ts +7 -0
- package/dist/tools/enter-plan.js +20 -0
- package/dist/tools/enter-plan.js.map +1 -0
- package/dist/tools/exit-plan.d.ts +7 -0
- package/dist/tools/exit-plan.js +51 -0
- package/dist/tools/exit-plan.js.map +1 -0
- package/dist/tools/find.d.ts +17 -0
- package/dist/tools/find.js +100 -0
- package/dist/tools/find.js.map +1 -0
- package/dist/tools/generate-image.d.ts +83 -0
- package/dist/tools/generate-image.js +625 -0
- package/dist/tools/generate-image.js.map +1 -0
- package/dist/tools/grep-scan.d.ts +96 -0
- package/dist/tools/grep-scan.js +283 -0
- package/dist/tools/grep-scan.js.map +1 -0
- package/dist/tools/grep.d.ts +48 -0
- package/dist/tools/grep.js +1013 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/html-extract.d.ts +57 -0
- package/dist/tools/html-extract.js +130 -0
- package/dist/tools/html-extract.js.map +1 -0
- package/dist/tools/index.d.ts +198 -0
- package/dist/tools/index.js +216 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/live-preview.d.ts +23 -0
- package/dist/tools/live-preview.js +41 -0
- package/dist/tools/live-preview.js.map +1 -0
- package/dist/tools/ls.d.ts +9 -0
- package/dist/tools/ls.js +59 -0
- package/dist/tools/ls.js.map +1 -0
- package/dist/tools/operations.d.ts +86 -0
- package/dist/tools/operations.js +117 -0
- package/dist/tools/operations.js.map +1 -0
- package/dist/tools/overflow.d.ts +17 -0
- package/dist/tools/overflow.js +68 -0
- package/dist/tools/overflow.js.map +1 -0
- package/dist/tools/path-utils.d.ts +30 -0
- package/dist/tools/path-utils.js +74 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/pdf-extract.d.ts +17 -0
- package/dist/tools/pdf-extract.js +43 -0
- package/dist/tools/pdf-extract.js.map +1 -0
- package/dist/tools/prompt-hints.d.ts +46 -0
- package/dist/tools/prompt-hints.js +171 -0
- package/dist/tools/prompt-hints.js.map +1 -0
- package/dist/tools/read-only-bash.d.ts +31 -0
- package/dist/tools/read-only-bash.js +338 -0
- package/dist/tools/read-only-bash.js.map +1 -0
- package/dist/tools/read-tracker.d.ts +43 -0
- package/dist/tools/read-tracker.js +120 -0
- package/dist/tools/read-tracker.js.map +1 -0
- package/dist/tools/read.d.ts +18 -0
- package/dist/tools/read.js +316 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/redaction-guard.d.ts +10 -0
- package/dist/tools/redaction-guard.js +55 -0
- package/dist/tools/redaction-guard.js.map +1 -0
- package/dist/tools/routine-output.d.ts +39 -0
- package/dist/tools/routine-output.js +281 -0
- package/dist/tools/routine-output.js.map +1 -0
- package/dist/tools/safe-env.d.ts +1 -0
- package/dist/tools/safe-env.js +79 -0
- package/dist/tools/safe-env.js.map +1 -0
- package/dist/tools/session-stats.d.ts +26 -0
- package/dist/tools/session-stats.js +51 -0
- package/dist/tools/session-stats.js.map +1 -0
- package/dist/tools/side-web-search.d.ts +34 -0
- package/dist/tools/side-web-search.js +146 -0
- package/dist/tools/side-web-search.js.map +1 -0
- package/dist/tools/skill.d.ts +12 -0
- package/dist/tools/skill.js +94 -0
- package/dist/tools/skill.js.map +1 -0
- package/dist/tools/source-path.d.ts +8 -0
- package/dist/tools/source-path.js +135 -0
- package/dist/tools/source-path.js.map +1 -0
- package/dist/tools/steroids.d.ts +44 -0
- package/dist/tools/steroids.js +356 -0
- package/dist/tools/steroids.js.map +1 -0
- package/dist/tools/subagent-control.d.ts +5 -0
- package/dist/tools/subagent-control.js +211 -0
- package/dist/tools/subagent-control.js.map +1 -0
- package/dist/tools/subagent-shared.d.ts +115 -0
- package/dist/tools/subagent-shared.js +182 -0
- package/dist/tools/subagent-shared.js.map +1 -0
- package/dist/tools/subagent.d.ts +39 -0
- package/dist/tools/subagent.js +412 -0
- package/dist/tools/subagent.js.map +1 -0
- package/dist/tools/task-output.d.ts +10 -0
- package/dist/tools/task-output.js +74 -0
- package/dist/tools/task-output.js.map +1 -0
- package/dist/tools/task-send.d.ts +11 -0
- package/dist/tools/task-send.js +36 -0
- package/dist/tools/task-send.js.map +1 -0
- package/dist/tools/task-stop.d.ts +8 -0
- package/dist/tools/task-stop.js +15 -0
- package/dist/tools/task-stop.js.map +1 -0
- package/dist/tools/tasks.d.ts +15 -0
- package/dist/tools/tasks.js +94 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/tool-search.d.ts +26 -0
- package/dist/tools/tool-search.js +81 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/tool-tiers.d.ts +65 -0
- package/dist/tools/tool-tiers.js +121 -0
- package/dist/tools/tool-tiers.js.map +1 -0
- package/dist/tools/truncate.d.ts +39 -0
- package/dist/tools/truncate.js +242 -0
- package/dist/tools/truncate.js.map +1 -0
- package/dist/tools/ui-adopt.d.ts +16 -0
- package/dist/tools/ui-adopt.js +66 -0
- package/dist/tools/ui-adopt.js.map +1 -0
- package/dist/tools/ui-registry.d.ts +15 -0
- package/dist/tools/ui-registry.js +39 -0
- package/dist/tools/ui-registry.js.map +1 -0
- package/dist/tools/verification-review.d.ts +2 -0
- package/dist/tools/verification-review.js +41 -0
- package/dist/tools/verification-review.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +52 -0
- package/dist/tools/web-fetch.js +986 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.js +926 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/write.d.ts +16 -0
- package/dist/tools/write.js +196 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/commit-message.d.ts +25 -0
- package/dist/utils/commit-message.js +72 -0
- package/dist/utils/commit-message.js.map +1 -0
- package/dist/utils/git.d.ts +102 -0
- package/dist/utils/git.js +325 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/github-ci.d.ts +9 -0
- package/dist/utils/github-ci.js +138 -0
- package/dist/utils/github-ci.js.map +1 -0
- package/dist/utils/github.d.ts +19 -0
- package/dist/utils/github.js +67 -0
- package/dist/utils/github.js.map +1 -0
- package/dist/utils/image.d.ts +166 -0
- package/dist/utils/image.js +673 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/open-browser.d.ts +13 -0
- package/dist/utils/open-browser.js +31 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/dist/utils/plan-steps.d.ts +90 -0
- package/dist/utils/plan-steps.js +209 -0
- package/dist/utils/plan-steps.js.map +1 -0
- package/dist/utils/process.d.ts +48 -0
- package/dist/utils/process.js +175 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/prompt-enhancer.d.ts +34 -0
- package/dist/utils/prompt-enhancer.js +178 -0
- package/dist/utils/prompt-enhancer.js.map +1 -0
- package/dist/utils/text.d.ts +61 -0
- package/dist/utils/text.js +68 -0
- package/dist/utils/text.js.map +1 -0
- package/package.json +87 -3
|
@@ -0,0 +1,1075 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
4
|
+
import { statSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { getAppPaths, withoutPaidTier, log } from "@kenkaiiii/gg-core";
|
|
7
|
+
import { mcpServersForAgent } from "./agents.js";
|
|
8
|
+
import { SUBAGENT_RECORD_RETENTION_DAYS, SubAgentStore, } from "./subagent-store.js";
|
|
9
|
+
import { SessionManager } from "./session-manager.js";
|
|
10
|
+
import { withContextFiles } from "./context-files.js";
|
|
11
|
+
import { PullRequestRecorder } from "./pull-requests.js";
|
|
12
|
+
import { clearTurnRecord, readTurnRecord, } from "./subagent-turn-record.js";
|
|
13
|
+
import { boundSubAgentOutput, childSubAgentEnv, currentSubAgentDepth, resolveSubAgentCliEntry, selectSubAgent, subAgentCacheKey, subAgentThinkingLevel, SUB_AGENT_MAX_STDERR_CHARS, SUB_AGENT_TIMEOUT_MS, } from "../tools/subagent-shared.js";
|
|
14
|
+
/** Children that may be starting or running at once. */
|
|
15
|
+
export const ACTIVE_LIMIT = 8;
|
|
16
|
+
/**
|
|
17
|
+
* Default per-model cap for a manager that is itself running inside a child
|
|
18
|
+
* (depth >= 1). The top level keeps the full ACTIVE_LIMIT so a goal run with
|
|
19
|
+
* 4-6 workers is untouched, but without a nested default every child could
|
|
20
|
+
* fan out 8 more — 8 × 8 × 8 processes at blocking depth 3, each with a
|
|
21
|
+
* 50-turn budget. An explicit `subagentMaxPerModel` setting still wins.
|
|
22
|
+
*/
|
|
23
|
+
export const NESTED_DEFAULT_MAX_PER_MODEL = 2;
|
|
24
|
+
const RETAINED_WORKER_LIMIT = 8;
|
|
25
|
+
const SNAPSHOT_LIMIT = 20;
|
|
26
|
+
/**
|
|
27
|
+
* Chars of child output `wait_agent` returns — in total, and per agent.
|
|
28
|
+
*
|
|
29
|
+
* Whatever comes back is pasted into the PARENT's context: the old 100k cap
|
|
30
|
+
* could hand a single wait ~25k tokens of transcript. The full output always
|
|
31
|
+
* remains readable at each child's `child_session_path`.
|
|
32
|
+
*/
|
|
33
|
+
const WAIT_OUTPUT_LIMIT = 60_000;
|
|
34
|
+
const WAIT_OUTPUT_PER_AGENT_LIMIT = 30_000;
|
|
35
|
+
/**
|
|
36
|
+
* Wait budgets, aligned with the child's own `SUB_AGENT_TIMEOUT_MS` (10 min).
|
|
37
|
+
* The previous 30s default and 5-min ceiling meant a parent waiting on a
|
|
38
|
+
* legitimately long child gave up ~20x early and finalized on a half-answer.
|
|
39
|
+
*/
|
|
40
|
+
export const DEFAULT_WAIT_MS = 120_000;
|
|
41
|
+
export const MAX_WAIT_MS = SUB_AGENT_TIMEOUT_MS;
|
|
42
|
+
const DEFAULT_IDLE_MS = 10 * 60_000;
|
|
43
|
+
function activity(name, args) {
|
|
44
|
+
const value = Object.values(args).find((candidate) => typeof candidate === "string");
|
|
45
|
+
return value ? `${name}: ${String(value).slice(0, 60)}` : name;
|
|
46
|
+
}
|
|
47
|
+
/** Chars of a child's result kept in its completion notification. */
|
|
48
|
+
const NOTIFICATION_DIGEST_CHARS = 160;
|
|
49
|
+
/**
|
|
50
|
+
* One-line gist of a child's result for a push notification. The full output
|
|
51
|
+
* stays behind `wait_agent`; this only has to tell the parent whether the
|
|
52
|
+
* result is worth collecting now.
|
|
53
|
+
*/
|
|
54
|
+
function summarizeForNotification(text) {
|
|
55
|
+
const collapsed = text.replace(/\s+/g, " ").trim();
|
|
56
|
+
if (!collapsed)
|
|
57
|
+
return "";
|
|
58
|
+
return collapsed.length <= NOTIFICATION_DIGEST_CHARS
|
|
59
|
+
? collapsed
|
|
60
|
+
: `${collapsed.slice(0, NOTIFICATION_DIGEST_CHARS - 1)}\u2026`;
|
|
61
|
+
}
|
|
62
|
+
/** Shared pre-finalization hook used by both AgentSession and the Ink host. */
|
|
63
|
+
export function buildSubAgentCompletionFollowUp(manager) {
|
|
64
|
+
const message = manager?.completionGateMessage();
|
|
65
|
+
return message
|
|
66
|
+
? [
|
|
67
|
+
{
|
|
68
|
+
role: "user",
|
|
69
|
+
content: message,
|
|
70
|
+
provenance: { source: "runtime", kind: "completion_gate", visibility: "hidden" },
|
|
71
|
+
},
|
|
72
|
+
]
|
|
73
|
+
: null;
|
|
74
|
+
}
|
|
75
|
+
export class SubAgentManager {
|
|
76
|
+
options;
|
|
77
|
+
workers = new Map();
|
|
78
|
+
snapshots = new Map();
|
|
79
|
+
pullRequests = new Map();
|
|
80
|
+
listeners = new Set();
|
|
81
|
+
shuttingDown = false;
|
|
82
|
+
shutdownPromise;
|
|
83
|
+
/** Background retention started by `hydrate`; never rejects. */
|
|
84
|
+
retention = Promise.resolve();
|
|
85
|
+
store;
|
|
86
|
+
sessionRootDir;
|
|
87
|
+
parentSessionId;
|
|
88
|
+
persistQueue = Promise.resolve();
|
|
89
|
+
/** Bounded watcher for turn records of children orphaned mid-turn. */
|
|
90
|
+
adoptionWatcher;
|
|
91
|
+
adoptionDeadline = 0;
|
|
92
|
+
persistPending = false;
|
|
93
|
+
persistScheduled = false;
|
|
94
|
+
/** Agent definitions `spawn` resolves names against — the delegation roster. */
|
|
95
|
+
/** The agent a child is when its spawn names none (see SubAgentManagerOptions.defaultAgent). */
|
|
96
|
+
get defaultAgent() {
|
|
97
|
+
return this.options.defaultAgent;
|
|
98
|
+
}
|
|
99
|
+
get agents() {
|
|
100
|
+
return this.options.agents;
|
|
101
|
+
}
|
|
102
|
+
constructor(options) {
|
|
103
|
+
this.options = options;
|
|
104
|
+
const paths = getAppPaths();
|
|
105
|
+
this.store = options.store ?? new SubAgentStore(paths.subagentsDir);
|
|
106
|
+
this.sessionRootDir = options.sessionRootDir ?? paths.subagentSessionsDir;
|
|
107
|
+
}
|
|
108
|
+
/** Restore bounded history; dead in-flight workers become honestly interrupted. */
|
|
109
|
+
async hydrate(parentSessionId) {
|
|
110
|
+
if (this.workers.size > 0) {
|
|
111
|
+
await this.shutdownAll();
|
|
112
|
+
this.workers.clear();
|
|
113
|
+
this.shuttingDown = false;
|
|
114
|
+
this.shutdownPromise = undefined;
|
|
115
|
+
}
|
|
116
|
+
await this.waitForPersistence();
|
|
117
|
+
this.parentSessionId = parentSessionId;
|
|
118
|
+
this.snapshots.clear();
|
|
119
|
+
const records = await this.store.load(this.options.cwd, parentSessionId);
|
|
120
|
+
// Snapshots that were mid-turn at parent death. Their detached child may
|
|
121
|
+
// still be finishing (stdin-close → orphan mode → durable turn record),
|
|
122
|
+
// so adoption is checked now AND watched for a bounded window.
|
|
123
|
+
const adoptable = [];
|
|
124
|
+
for (const persisted of records) {
|
|
125
|
+
const wasActive = persisted.state === "starting" || persisted.state === "running";
|
|
126
|
+
const snapshot = {
|
|
127
|
+
...persisted,
|
|
128
|
+
...(wasActive
|
|
129
|
+
? {
|
|
130
|
+
state: "interrupted",
|
|
131
|
+
error: "Interrupted by process restart",
|
|
132
|
+
updated_at: Date.now(),
|
|
133
|
+
recovered: true,
|
|
134
|
+
}
|
|
135
|
+
: { recovered: true }),
|
|
136
|
+
};
|
|
137
|
+
if (wasActive && snapshot.child_session_path) {
|
|
138
|
+
adoptable.push({ snapshot, lastObservedAt: persisted.updated_at });
|
|
139
|
+
}
|
|
140
|
+
this.snapshots.set(snapshot.agent_id, snapshot);
|
|
141
|
+
this.options.onState?.(snapshot);
|
|
142
|
+
for (const listener of this.listeners)
|
|
143
|
+
listener(snapshot);
|
|
144
|
+
}
|
|
145
|
+
this.queuePersist();
|
|
146
|
+
await this.waitForPersistence();
|
|
147
|
+
await this.settleAdoptableTurns(adoptable);
|
|
148
|
+
// Retention is housekeeping, not restore: it walks every child session on
|
|
149
|
+
// disk, so it runs after hydrate returns instead of holding up readiness
|
|
150
|
+
// (hydrate is awaited by session initialize, i.e. every window open).
|
|
151
|
+
// Old records go first, so the child transcripts only they referenced are
|
|
152
|
+
// free to age out with the rest.
|
|
153
|
+
this.retention = this.store
|
|
154
|
+
.pruneDaily(SUBAGENT_RECORD_RETENTION_DAYS)
|
|
155
|
+
.then(() => this.store.listChildSessionPaths())
|
|
156
|
+
.then((referencedChildSessions) => new SessionManager(this.sessionRootDir).pruneOldSessions({
|
|
157
|
+
maxAgeDays: 30,
|
|
158
|
+
keepPaths: referencedChildSessions,
|
|
159
|
+
}))
|
|
160
|
+
.then(() => undefined, (error) => {
|
|
161
|
+
log("WARN", "subagent", "Failed to prune old subagent sessions", {
|
|
162
|
+
error: error instanceof Error ? error.message : String(error),
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/** Resolves once the retention pass the last `hydrate` started has finished. */
|
|
167
|
+
async waitForRetention() {
|
|
168
|
+
await this.retention;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Adopt durable turn records for snapshots that were mid-turn at restart.
|
|
172
|
+
* A record newer than the parent's last observation of that child is the
|
|
173
|
+
* child's own terminal verdict — it outranks the pessimistic "interrupted".
|
|
174
|
+
* Still-running orphans get a bounded watcher: the record usually lands
|
|
175
|
+
* within one turn timeout, and adoption then notifies the parent's next
|
|
176
|
+
* turn like any other completion.
|
|
177
|
+
*/
|
|
178
|
+
async settleAdoptableTurns(adoptable) {
|
|
179
|
+
clearInterval(this.adoptionWatcher);
|
|
180
|
+
if (adoptable.length === 0)
|
|
181
|
+
return;
|
|
182
|
+
const pending = new Map(adoptable.map((entry) => [entry.snapshot.agent_id, entry]));
|
|
183
|
+
const settle = async () => {
|
|
184
|
+
for (const [agentId, entry] of pending) {
|
|
185
|
+
// Skip anything re-spawned or already terminal via another path.
|
|
186
|
+
const current = this.snapshots.get(agentId);
|
|
187
|
+
if (!current || current.state !== "interrupted" || this.workers.has(agentId)) {
|
|
188
|
+
pending.delete(agentId);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const record = await readTurnRecord(current.child_session_path);
|
|
192
|
+
if (!record || record.completed_at <= entry.lastObservedAt)
|
|
193
|
+
continue;
|
|
194
|
+
pending.delete(agentId);
|
|
195
|
+
this.adoptTurnRecord(current, record);
|
|
196
|
+
}
|
|
197
|
+
if (pending.size === 0 || Date.now() > this.adoptionDeadline) {
|
|
198
|
+
clearInterval(this.adoptionWatcher);
|
|
199
|
+
this.adoptionWatcher = undefined;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
this.adoptionDeadline = Date.now() + SUB_AGENT_TIMEOUT_MS + 60_000;
|
|
203
|
+
await settle();
|
|
204
|
+
if (pending.size > 0) {
|
|
205
|
+
this.adoptionWatcher = setInterval(() => void settle(), this.options.adoptionPollMs ?? 5_000);
|
|
206
|
+
this.adoptionWatcher.unref?.();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** Fold a durable turn record into the snapshot and announce the adoption. */
|
|
210
|
+
adoptTurnRecord(snapshot, record) {
|
|
211
|
+
const adopted = {
|
|
212
|
+
...snapshot,
|
|
213
|
+
state: record.status === "completed" ? "completed" : record.status,
|
|
214
|
+
output: record.output,
|
|
215
|
+
receipt: record.receipt,
|
|
216
|
+
error: record.status === "completed"
|
|
217
|
+
? undefined
|
|
218
|
+
: (record.error ?? "Turn ended during a parent restart"),
|
|
219
|
+
model: record.model ?? snapshot.model,
|
|
220
|
+
turn_count: record.turn_count,
|
|
221
|
+
token_usage: {
|
|
222
|
+
...snapshot.token_usage,
|
|
223
|
+
input: record.token_usage.input,
|
|
224
|
+
output: record.token_usage.output,
|
|
225
|
+
},
|
|
226
|
+
updated_at: Date.now(),
|
|
227
|
+
recovered: true,
|
|
228
|
+
};
|
|
229
|
+
this.snapshots.set(adopted.agent_id, adopted);
|
|
230
|
+
this.options.onState?.(adopted);
|
|
231
|
+
for (const listener of this.listeners)
|
|
232
|
+
listener(adopted);
|
|
233
|
+
this.queuePersist();
|
|
234
|
+
// One record is adopted once; clearing prevents a re-hydrate double-adoption
|
|
235
|
+
// racing a persist that has not landed yet.
|
|
236
|
+
void clearTurnRecord(adopted.child_session_path);
|
|
237
|
+
log("INFO", "subagent", "Adopted child turn record after restart", {
|
|
238
|
+
agent_id: adopted.agent_id,
|
|
239
|
+
status: record.status,
|
|
240
|
+
});
|
|
241
|
+
this.options.notifications?.enqueue("subagent", adopted.agent_id, `Child agent "${adopted.task_name}" (${adopted.agent_id}) finished during a parent ` +
|
|
242
|
+
`restart and its result was recovered (${record.status}). ` +
|
|
243
|
+
`Collect the full output with wait_agent agent_ids ["${adopted.agent_id}"].`, { terminal: true, urgent: true });
|
|
244
|
+
}
|
|
245
|
+
/** Rebind durable child history after parent compaction creates a continuation. */
|
|
246
|
+
async rebindParentSession(parentSessionId) {
|
|
247
|
+
await this.waitForPersistence();
|
|
248
|
+
this.parentSessionId = parentSessionId;
|
|
249
|
+
this.queuePersist();
|
|
250
|
+
await this.persistQueue;
|
|
251
|
+
}
|
|
252
|
+
/** A genuinely new parent starts with no unrelated child history. */
|
|
253
|
+
async resetParentSession(parentSessionId) {
|
|
254
|
+
await this.shutdownAll();
|
|
255
|
+
await this.waitForPersistence();
|
|
256
|
+
this.shuttingDown = false;
|
|
257
|
+
this.shutdownPromise = undefined;
|
|
258
|
+
this.workers.clear();
|
|
259
|
+
this.snapshots.clear();
|
|
260
|
+
this.parentSessionId = parentSessionId;
|
|
261
|
+
this.queuePersist();
|
|
262
|
+
await this.persistQueue;
|
|
263
|
+
}
|
|
264
|
+
async waitForPersistence() {
|
|
265
|
+
await this.persistQueue;
|
|
266
|
+
}
|
|
267
|
+
/** Explicit per-spawn overrides. Used by harness-owned children (the
|
|
268
|
+
* independent Ideal reviewer): a read-only tool list and/or a forced model —
|
|
269
|
+
* bypassing agent-definition routing entirely — and a shorter turn time
|
|
270
|
+
* limit, after which the child answers from what it has gathered. */
|
|
271
|
+
async spawn(taskName, task, agentName, overrides) {
|
|
272
|
+
this.assertAvailable();
|
|
273
|
+
agentName ??= this.options.defaultAgent;
|
|
274
|
+
const childCwd = this.resolveChildCwd(overrides?.cwd);
|
|
275
|
+
if (!taskName.trim())
|
|
276
|
+
throw new Error("task_name is required");
|
|
277
|
+
if ([...this.workers.values()].some((worker) => worker.task_name === taskName)) {
|
|
278
|
+
throw new Error(`An agent named "${taskName}" already exists`);
|
|
279
|
+
}
|
|
280
|
+
if (this.activeCount() >= ACTIVE_LIMIT)
|
|
281
|
+
throw new Error(`At most ${ACTIVE_LIMIT} agents may run at once`);
|
|
282
|
+
this.reapExcessIdle();
|
|
283
|
+
const pick = this.options.getChildModel?.();
|
|
284
|
+
const parentProvider = this.options.getProvider();
|
|
285
|
+
const provider = pick?.provider ?? parentProvider;
|
|
286
|
+
const parentModel = this.options.getModel();
|
|
287
|
+
const parentThinkingLevel = this.options.getThinkingLevel?.();
|
|
288
|
+
const base = selectSubAgent(this.options.agents, agentName, provider, pick?.model ?? parentModel, parentThinkingLevel);
|
|
289
|
+
// Same rule as selectSubAgent: a harness override can't put a worker on a paid tier.
|
|
290
|
+
const model = withoutPaidTier(overrides?.model ?? base.model);
|
|
291
|
+
const selection = {
|
|
292
|
+
agentDef: base.agentDef,
|
|
293
|
+
provider: base.provider,
|
|
294
|
+
parentModel: base.parentModel,
|
|
295
|
+
model,
|
|
296
|
+
// Resolve against the actual child model, including harness overrides.
|
|
297
|
+
thinkingLevel: subAgentThinkingLevel(provider, model, parentThinkingLevel),
|
|
298
|
+
tools: overrides?.tools ?? base.agentDef?.tools ?? [],
|
|
299
|
+
};
|
|
300
|
+
if (agentName && !selection.agentDef) {
|
|
301
|
+
// Name the real roster: an unqualified "unknown agent" gives the model
|
|
302
|
+
// nothing to correct against, so it re-guesses the same wrong name.
|
|
303
|
+
const available = this.options.agents.map((a) => a.name).join(", ") || "none";
|
|
304
|
+
throw new Error(`Unknown agent: "${agentName}". Available agents: ${available}`);
|
|
305
|
+
}
|
|
306
|
+
this.assertModelCapacity(selection.model);
|
|
307
|
+
const now = Date.now();
|
|
308
|
+
const agentId = this.createId();
|
|
309
|
+
const child = this.spawnWorkerProcess(childCwd);
|
|
310
|
+
const record = {
|
|
311
|
+
agent_id: agentId,
|
|
312
|
+
task_name: taskName,
|
|
313
|
+
state: "starting",
|
|
314
|
+
started_at: now,
|
|
315
|
+
updated_at: now,
|
|
316
|
+
elapsed_ms: 0,
|
|
317
|
+
turn_count: 0,
|
|
318
|
+
tool_use_count: 0,
|
|
319
|
+
token_usage: { input: 0, output: 0 },
|
|
320
|
+
agent_name: selection.agentDef?.name,
|
|
321
|
+
provider,
|
|
322
|
+
model: selection.model,
|
|
323
|
+
...(childCwd !== this.options.cwd ? { cwd: childCwd } : {}),
|
|
324
|
+
collected: false,
|
|
325
|
+
process: child,
|
|
326
|
+
requests: new Map(),
|
|
327
|
+
requestSequence: 0,
|
|
328
|
+
stderr: "",
|
|
329
|
+
taskOutput: "",
|
|
330
|
+
turnResolvers: new Set(),
|
|
331
|
+
};
|
|
332
|
+
this.workers.set(agentId, record);
|
|
333
|
+
this.publish(record);
|
|
334
|
+
this.attach(record);
|
|
335
|
+
await this.waitForPersistence();
|
|
336
|
+
try {
|
|
337
|
+
const initialized = await this.request(record, "initialize", {
|
|
338
|
+
options: {
|
|
339
|
+
provider,
|
|
340
|
+
model: selection.model,
|
|
341
|
+
// The parent's model is only a fallback on the parent's provider.
|
|
342
|
+
fallbackModel: selection.model === parentModel || provider !== parentProvider
|
|
343
|
+
? undefined
|
|
344
|
+
: parentModel,
|
|
345
|
+
cwd: childCwd,
|
|
346
|
+
additionalRoots: this.sharedRoots(childCwd),
|
|
347
|
+
baseUrl: this.options.getBaseUrl?.(),
|
|
348
|
+
// Composed, not replaced — the child keeps its Tools section, project
|
|
349
|
+
// context and Environment facts alongside its agent body.
|
|
350
|
+
agentPrompt: selection.agentDef?.systemPrompt,
|
|
351
|
+
agentContext: selection.agentDef?.context,
|
|
352
|
+
thinkingLevel: selection.thinkingLevel,
|
|
353
|
+
parentThinkingLevel,
|
|
354
|
+
allowedTools: selection.tools.length ? [...selection.tools] : undefined,
|
|
355
|
+
// Without this, an allow-listed child connects NO MCP servers — even
|
|
356
|
+
// when its `tools:` frontmatter names `mcp__<server>__<tool>`.
|
|
357
|
+
allowedMcpServers: selection.tools.length
|
|
358
|
+
? mcpServersForAgent([...selection.tools])
|
|
359
|
+
: undefined,
|
|
360
|
+
promptCacheKey: subAgentCacheKey(this.options.getCacheKey?.(), selection.model, selection.agentDef?.name ?? "default", agentId),
|
|
361
|
+
sessionRootDir: this.sessionRootDir,
|
|
362
|
+
turnTimeoutMs: overrides?.turnTimeoutMs,
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
record.child_session_id =
|
|
366
|
+
typeof initialized.child_session_id === "string" ? initialized.child_session_id : undefined;
|
|
367
|
+
if (typeof initialized.model === "string")
|
|
368
|
+
record.model = initialized.model;
|
|
369
|
+
record.child_session_path =
|
|
370
|
+
typeof initialized.child_session_path === "string"
|
|
371
|
+
? this.assertChildSessionPath(initialized.child_session_path)
|
|
372
|
+
: undefined;
|
|
373
|
+
this.publish(record);
|
|
374
|
+
await this.waitForPersistence();
|
|
375
|
+
const brief = await withContextFiles(task, overrides?.contextFiles ?? [], childCwd);
|
|
376
|
+
await this.request(record, "start", { task: brief, checks: overrides?.checks ?? [] });
|
|
377
|
+
record.state = "running";
|
|
378
|
+
record.updated_at = Date.now();
|
|
379
|
+
this.publish(record);
|
|
380
|
+
await this.waitForPersistence();
|
|
381
|
+
return this.snapshot(record);
|
|
382
|
+
}
|
|
383
|
+
catch (error) {
|
|
384
|
+
this.fail(record, error);
|
|
385
|
+
await this.waitForPersistence();
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
async sendMessage(agentId, message) {
|
|
390
|
+
const worker = this.requireWorker(agentId);
|
|
391
|
+
if (worker.state !== "running")
|
|
392
|
+
throw new Error(`Agent ${agentId} is not running`);
|
|
393
|
+
const result = await this.request(worker, "queue_message", { message });
|
|
394
|
+
return Number(result.queued ?? 0);
|
|
395
|
+
}
|
|
396
|
+
async followup(agentId, task, checks = []) {
|
|
397
|
+
this.assertAvailable();
|
|
398
|
+
let worker = this.workers.get(agentId);
|
|
399
|
+
if (!worker) {
|
|
400
|
+
const recovered = this.snapshots.get(agentId);
|
|
401
|
+
if (!recovered)
|
|
402
|
+
throw new Error(`Unknown agent: ${agentId}`);
|
|
403
|
+
worker = await this.respawnRecovered(recovered);
|
|
404
|
+
}
|
|
405
|
+
if (worker.state === "running" || worker.state === "starting") {
|
|
406
|
+
throw new Error(`Agent ${agentId} already has an active turn`);
|
|
407
|
+
}
|
|
408
|
+
if (this.activeCount() >= ACTIVE_LIMIT)
|
|
409
|
+
throw new Error(`At most ${ACTIVE_LIMIT} agents may run at once`);
|
|
410
|
+
if (worker.model)
|
|
411
|
+
this.assertModelCapacity(worker.model);
|
|
412
|
+
clearTimeout(worker.idleTimer);
|
|
413
|
+
worker.taskOutput = "";
|
|
414
|
+
worker.output = undefined;
|
|
415
|
+
worker.receipt = undefined;
|
|
416
|
+
worker.acceptance = undefined;
|
|
417
|
+
worker.error = undefined;
|
|
418
|
+
worker.collected = false;
|
|
419
|
+
// Roots are fixed at initialize, so a folder attached since (a goal's new
|
|
420
|
+
// context) would stay out of reach of this worker's write tool. Send the
|
|
421
|
+
// current ones; the worker adds any it doesn't have yet.
|
|
422
|
+
await this.request(worker, "followup", {
|
|
423
|
+
task,
|
|
424
|
+
checks,
|
|
425
|
+
additionalRoots: this.sharedRoots(worker.cwd ?? this.options.cwd),
|
|
426
|
+
});
|
|
427
|
+
worker.state = "running";
|
|
428
|
+
worker.updated_at = Date.now();
|
|
429
|
+
this.publish(worker);
|
|
430
|
+
await this.waitForPersistence();
|
|
431
|
+
return this.snapshot(worker);
|
|
432
|
+
}
|
|
433
|
+
async interrupt(agentId, collectResult = true) {
|
|
434
|
+
const worker = this.requireWorker(agentId);
|
|
435
|
+
if (worker.state !== "running")
|
|
436
|
+
throw new Error(`Agent ${agentId} is not running`);
|
|
437
|
+
const changed = this.waitForChange(agentId);
|
|
438
|
+
await this.request(worker, "interrupt");
|
|
439
|
+
await changed;
|
|
440
|
+
if (collectResult)
|
|
441
|
+
this.markCollected(agentId);
|
|
442
|
+
await this.waitForPersistence();
|
|
443
|
+
return this.snapshot(worker);
|
|
444
|
+
}
|
|
445
|
+
subscribe(listener) {
|
|
446
|
+
this.listeners.add(listener);
|
|
447
|
+
return () => this.listeners.delete(listener);
|
|
448
|
+
}
|
|
449
|
+
list() {
|
|
450
|
+
return [...this.snapshots.values()]
|
|
451
|
+
.map((snapshot) => ({ ...snapshot, elapsed_ms: this.elapsed(snapshot) }))
|
|
452
|
+
.sort((a, b) => a.started_at - b.started_at);
|
|
453
|
+
}
|
|
454
|
+
async wait(agentIds, condition = "any", timeoutMs = DEFAULT_WAIT_MS) {
|
|
455
|
+
const ids = agentIds?.length
|
|
456
|
+
? agentIds
|
|
457
|
+
: [...this.workers.values()]
|
|
458
|
+
.filter((worker) => this.isActive(worker))
|
|
459
|
+
.map((worker) => worker.agent_id);
|
|
460
|
+
if (ids.length === 0)
|
|
461
|
+
return { timed_out: false, agents: [] };
|
|
462
|
+
for (const id of ids)
|
|
463
|
+
if (!this.snapshots.has(id))
|
|
464
|
+
throw new Error(`Unknown agent: ${id}`);
|
|
465
|
+
const boundedTimeout = Math.min(Math.max(timeoutMs, 0), MAX_WAIT_MS);
|
|
466
|
+
const terminal = () => ids.filter((id) => this.isTerminal(this.snapshots.get(id)?.state));
|
|
467
|
+
const ready = () => condition === "all" ? terminal().length === ids.length : terminal().length > 0;
|
|
468
|
+
const deadline = Date.now() + boundedTimeout;
|
|
469
|
+
let timedOut = false;
|
|
470
|
+
while (!ready()) {
|
|
471
|
+
const remaining = deadline - Date.now();
|
|
472
|
+
if (remaining <= 0) {
|
|
473
|
+
timedOut = true;
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
const pendingIds = ids.filter((id) => !this.isTerminal(this.snapshots.get(id)?.state));
|
|
477
|
+
const changed = await Promise.race([
|
|
478
|
+
Promise.race(pendingIds.map((id) => this.waitForChange(id))).then(() => true),
|
|
479
|
+
new Promise((resolve) => setTimeout(() => resolve(false), remaining)),
|
|
480
|
+
]);
|
|
481
|
+
if (!changed && !ready())
|
|
482
|
+
timedOut = true;
|
|
483
|
+
if (!changed)
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
for (const id of ids) {
|
|
487
|
+
if (this.isTerminal(this.snapshots.get(id)?.state))
|
|
488
|
+
this.markCollected(id);
|
|
489
|
+
}
|
|
490
|
+
await this.waitForPersistence();
|
|
491
|
+
let chars = 0;
|
|
492
|
+
const agents = ids.map((id) => {
|
|
493
|
+
const snapshot = { ...this.snapshots.get(id) };
|
|
494
|
+
if (snapshot.output) {
|
|
495
|
+
// Head, not tail: a child's report leads with its answer. Bounded per
|
|
496
|
+
// agent as well as in total so one verbose child cannot consume the
|
|
497
|
+
// whole budget and starve the others of any output at all.
|
|
498
|
+
const budget = Math.min(WAIT_OUTPUT_PER_AGENT_LIMIT, Math.max(0, WAIT_OUTPUT_LIMIT - chars));
|
|
499
|
+
if (snapshot.output.length > budget) {
|
|
500
|
+
const path = snapshot.child_session_path;
|
|
501
|
+
snapshot.output =
|
|
502
|
+
snapshot.output.slice(0, budget) +
|
|
503
|
+
`\n\n[output truncated at ${budget} chars${path ? `; full transcript: ${path}` : ""}]`;
|
|
504
|
+
}
|
|
505
|
+
chars += Math.min(budget, snapshot.output.length);
|
|
506
|
+
}
|
|
507
|
+
return snapshot;
|
|
508
|
+
});
|
|
509
|
+
return { timed_out: timedOut, agents };
|
|
510
|
+
}
|
|
511
|
+
completionGate() {
|
|
512
|
+
const snapshots = this.list();
|
|
513
|
+
const active = snapshots.filter((snapshot) => this.isActive(snapshot));
|
|
514
|
+
const uncollected = snapshots.filter((snapshot) => this.isTerminal(snapshot.state) && snapshot.collected !== true);
|
|
515
|
+
return { active, uncollected, unresolved: active.length + uncollected.length };
|
|
516
|
+
}
|
|
517
|
+
completionGateMessage() {
|
|
518
|
+
const gate = this.completionGate();
|
|
519
|
+
if (gate.unresolved === 0)
|
|
520
|
+
return undefined;
|
|
521
|
+
const activeIds = gate.active.map((snapshot) => snapshot.agent_id).sort();
|
|
522
|
+
const uncollectedIds = gate.uncollected.map((snapshot) => snapshot.agent_id).sort();
|
|
523
|
+
const unresolvedIds = [...new Set([...activeIds, ...uncollectedIds])];
|
|
524
|
+
return [
|
|
525
|
+
"Child-agent completion gate: the parent cannot finish with unresolved child work.",
|
|
526
|
+
`Unresolved agent IDs: ${unresolvedIds.join(", ")}.`,
|
|
527
|
+
activeIds.length > 0
|
|
528
|
+
? `Active agent IDs: ${activeIds.join(", ")}. Wait for them with wait_agent, or interrupt them before collecting their terminal result.`
|
|
529
|
+
: "All children are terminal, but their results have not been collected.",
|
|
530
|
+
`Call wait_agent with agent_ids [${unresolvedIds.map((id) => `"${id}"`).join(", ")}] and condition "all" before finishing.`,
|
|
531
|
+
].join("\n");
|
|
532
|
+
}
|
|
533
|
+
async interruptAll() {
|
|
534
|
+
await Promise.allSettled([...this.workers.values()]
|
|
535
|
+
.filter((worker) => this.isActive(worker))
|
|
536
|
+
.map((worker) => worker.state === "starting" ? this.close(worker) : this.interrupt(worker.agent_id, false)));
|
|
537
|
+
}
|
|
538
|
+
async shutdownAll() {
|
|
539
|
+
clearInterval(this.adoptionWatcher);
|
|
540
|
+
this.adoptionWatcher = undefined;
|
|
541
|
+
if (!this.shutdownPromise) {
|
|
542
|
+
this.shuttingDown = true;
|
|
543
|
+
this.shutdownPromise = Promise.allSettled([...this.workers.values()].map((worker) => this.close(worker, false, true))).then(() => undefined);
|
|
544
|
+
}
|
|
545
|
+
await this.shutdownPromise;
|
|
546
|
+
// Let a running retention pass finish so teardown (and test temp-dir
|
|
547
|
+
// removal) never races its file deletions.
|
|
548
|
+
await this.retention;
|
|
549
|
+
}
|
|
550
|
+
/** Synchronous process-exit fallback: terminate detached process groups immediately. */
|
|
551
|
+
shutdownAllNow() {
|
|
552
|
+
this.shuttingDown = true;
|
|
553
|
+
clearInterval(this.adoptionWatcher);
|
|
554
|
+
this.adoptionWatcher = undefined;
|
|
555
|
+
for (const worker of this.workers.values())
|
|
556
|
+
this.kill(worker);
|
|
557
|
+
}
|
|
558
|
+
markCollected(agentId) {
|
|
559
|
+
// The parent has the output now; a still-queued "is completed … collect it
|
|
560
|
+
// with wait_agent" notice would only repeat it on the next turn.
|
|
561
|
+
this.options.notifications?.clear("subagent", agentId);
|
|
562
|
+
const worker = this.workers.get(agentId);
|
|
563
|
+
if (worker) {
|
|
564
|
+
worker.collected = true;
|
|
565
|
+
worker.updated_at = Date.now();
|
|
566
|
+
this.publish(worker);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const snapshot = this.snapshots.get(agentId);
|
|
570
|
+
if (!snapshot)
|
|
571
|
+
return;
|
|
572
|
+
const collected = { ...snapshot, collected: true, updated_at: Date.now() };
|
|
573
|
+
this.snapshots.set(agentId, collected);
|
|
574
|
+
this.options.onState?.(collected);
|
|
575
|
+
for (const listener of this.listeners)
|
|
576
|
+
listener(collected);
|
|
577
|
+
this.queuePersist();
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* The folder a new child works in: the parent's cwd by default, otherwise a
|
|
581
|
+
* folder already in the parent's workspace. Never wider than the parent.
|
|
582
|
+
*/
|
|
583
|
+
resolveChildCwd(requested) {
|
|
584
|
+
if (!requested)
|
|
585
|
+
return this.options.cwd;
|
|
586
|
+
if (!path.isAbsolute(requested)) {
|
|
587
|
+
throw new Error(`cwd must be an absolute path: ${requested}`);
|
|
588
|
+
}
|
|
589
|
+
const target = path.resolve(requested);
|
|
590
|
+
const roots = [this.options.cwd, ...(this.options.getWorkspaceRoots?.() ?? [])].map((root) => path.resolve(root));
|
|
591
|
+
const inside = roots.some((root) => {
|
|
592
|
+
const relative = path.relative(root, target);
|
|
593
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
594
|
+
});
|
|
595
|
+
if (!inside) {
|
|
596
|
+
throw new Error(`cwd is outside this session's workspace: ${target}. Use one of: ${roots.join(", ")}`);
|
|
597
|
+
}
|
|
598
|
+
// A missing folder would only surface as an opaque spawn ENOENT.
|
|
599
|
+
let isDirectory;
|
|
600
|
+
try {
|
|
601
|
+
isDirectory = statSync(target).isDirectory();
|
|
602
|
+
}
|
|
603
|
+
catch {
|
|
604
|
+
isDirectory = false;
|
|
605
|
+
}
|
|
606
|
+
if (!isDirectory)
|
|
607
|
+
throw new Error(`cwd is not an existing folder: ${target}`);
|
|
608
|
+
return target;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* The parent's extra roots a child also gets (see shareWorkspaceRoots),
|
|
612
|
+
* less the folder it works in and any root that folder already covers.
|
|
613
|
+
* Undefined when the parent doesn't share them.
|
|
614
|
+
*/
|
|
615
|
+
sharedRoots(childCwd) {
|
|
616
|
+
if (!this.options.shareWorkspaceRoots)
|
|
617
|
+
return undefined;
|
|
618
|
+
const roots = (this.options.getWorkspaceRoots?.() ?? [])
|
|
619
|
+
.map((root) => path.resolve(root))
|
|
620
|
+
.filter((root) => {
|
|
621
|
+
const relative = path.relative(childCwd, root);
|
|
622
|
+
return relative.startsWith("..") || path.isAbsolute(relative);
|
|
623
|
+
});
|
|
624
|
+
return roots.length > 0 ? roots : undefined;
|
|
625
|
+
}
|
|
626
|
+
spawnWorkerProcess(cwd) {
|
|
627
|
+
return spawn(process.execPath, [this.options.workerEntry ?? resolveSubAgentCliEntry(), "--subagent-worker"], {
|
|
628
|
+
cwd,
|
|
629
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
630
|
+
env: childSubAgentEnv(),
|
|
631
|
+
detached: process.platform !== "win32",
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
async respawnRecovered(snapshot) {
|
|
635
|
+
if (!snapshot.child_session_path) {
|
|
636
|
+
throw new Error(`Agent ${snapshot.agent_id} was reaped and has no recoverable child session`);
|
|
637
|
+
}
|
|
638
|
+
const agentDef = snapshot.agent_name
|
|
639
|
+
? this.options.agents.find((candidate) => candidate.name === snapshot.agent_name)
|
|
640
|
+
: undefined;
|
|
641
|
+
const provider = snapshot.provider ?? this.options.getProvider();
|
|
642
|
+
const model = snapshot.model ?? this.options.getModel();
|
|
643
|
+
const parentModel = this.options.getModel();
|
|
644
|
+
const parentThinkingLevel = this.options.getThinkingLevel?.();
|
|
645
|
+
this.assertModelCapacity(model);
|
|
646
|
+
const childSessionPath = this.assertChildSessionPath(snapshot.child_session_path);
|
|
647
|
+
// Wake it where it was working; re-checked, since the workspace may have
|
|
648
|
+
// changed since it was started.
|
|
649
|
+
const childCwd = this.resolveChildCwd(snapshot.cwd);
|
|
650
|
+
const child = this.spawnWorkerProcess(childCwd);
|
|
651
|
+
const worker = {
|
|
652
|
+
...snapshot,
|
|
653
|
+
state: "starting",
|
|
654
|
+
updated_at: Date.now(),
|
|
655
|
+
current_activity: undefined,
|
|
656
|
+
output: undefined,
|
|
657
|
+
receipt: undefined,
|
|
658
|
+
error: undefined,
|
|
659
|
+
collected: false,
|
|
660
|
+
recovered: false,
|
|
661
|
+
process: child,
|
|
662
|
+
requests: new Map(),
|
|
663
|
+
requestSequence: 0,
|
|
664
|
+
stderr: "",
|
|
665
|
+
taskOutput: "",
|
|
666
|
+
turnResolvers: new Set(),
|
|
667
|
+
};
|
|
668
|
+
this.workers.set(worker.agent_id, worker);
|
|
669
|
+
this.publish(worker);
|
|
670
|
+
this.attach(worker);
|
|
671
|
+
await this.waitForPersistence();
|
|
672
|
+
try {
|
|
673
|
+
const initialized = await this.request(worker, "initialize", {
|
|
674
|
+
options: {
|
|
675
|
+
provider,
|
|
676
|
+
model,
|
|
677
|
+
fallbackModel: model === parentModel ? undefined : parentModel,
|
|
678
|
+
cwd: childCwd,
|
|
679
|
+
additionalRoots: this.sharedRoots(childCwd),
|
|
680
|
+
baseUrl: this.options.getBaseUrl?.(),
|
|
681
|
+
agentPrompt: agentDef?.systemPrompt,
|
|
682
|
+
agentContext: agentDef?.context,
|
|
683
|
+
thinkingLevel: subAgentThinkingLevel(provider, model, parentThinkingLevel),
|
|
684
|
+
parentThinkingLevel,
|
|
685
|
+
allowedTools: agentDef?.tools.length ? agentDef.tools : undefined,
|
|
686
|
+
allowedMcpServers: agentDef?.tools.length
|
|
687
|
+
? mcpServersForAgent(agentDef.tools)
|
|
688
|
+
: undefined,
|
|
689
|
+
promptCacheKey: subAgentCacheKey(this.options.getCacheKey?.(), model, agentDef?.name ?? "default", worker.agent_id),
|
|
690
|
+
sessionRootDir: this.sessionRootDir,
|
|
691
|
+
childSessionPath,
|
|
692
|
+
},
|
|
693
|
+
});
|
|
694
|
+
if (typeof initialized.child_session_id === "string") {
|
|
695
|
+
worker.child_session_id = initialized.child_session_id;
|
|
696
|
+
}
|
|
697
|
+
if (typeof initialized.child_session_path === "string") {
|
|
698
|
+
worker.child_session_path = this.assertChildSessionPath(initialized.child_session_path);
|
|
699
|
+
}
|
|
700
|
+
if (typeof initialized.model === "string")
|
|
701
|
+
worker.model = initialized.model;
|
|
702
|
+
worker.state = snapshot.state;
|
|
703
|
+
worker.updated_at = Date.now();
|
|
704
|
+
this.publish(worker);
|
|
705
|
+
await this.waitForPersistence();
|
|
706
|
+
return worker;
|
|
707
|
+
}
|
|
708
|
+
catch (error) {
|
|
709
|
+
this.fail(worker, error);
|
|
710
|
+
await this.waitForPersistence();
|
|
711
|
+
throw error;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
attach(worker) {
|
|
715
|
+
const lines = createInterface({ input: worker.process.stdout });
|
|
716
|
+
lines.on("line", (line) => {
|
|
717
|
+
let frame;
|
|
718
|
+
try {
|
|
719
|
+
frame = JSON.parse(line);
|
|
720
|
+
}
|
|
721
|
+
catch {
|
|
722
|
+
this.fail(worker, new Error("Subagent worker emitted malformed protocol data"));
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
this.handleFrame(worker, frame);
|
|
726
|
+
});
|
|
727
|
+
worker.process.stderr?.on("data", (chunk) => {
|
|
728
|
+
worker.stderr = (worker.stderr + chunk.toString()).slice(-SUB_AGENT_MAX_STDERR_CHARS);
|
|
729
|
+
});
|
|
730
|
+
// A worker can exit between the writable check and stdin.write(). Consume
|
|
731
|
+
// the pipe error here so EPIPE becomes worker failure instead of an
|
|
732
|
+
// uncaught process-level exception (seen on faster CI runners).
|
|
733
|
+
worker.process.stdin?.on("error", (error) => this.fail(worker, error));
|
|
734
|
+
worker.process.once("error", (error) => this.fail(worker, error));
|
|
735
|
+
worker.process.once("exit", (code) => {
|
|
736
|
+
if (!this.isTerminal(worker.state) && worker.state !== "closed") {
|
|
737
|
+
this.fail(worker, new Error(worker.stderr.trim() || `Subagent worker exited (${code})`), false);
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
handleFrame(worker, frame) {
|
|
742
|
+
if (frame.type === "ack") {
|
|
743
|
+
const pending = worker.requests.get(String(frame.request_id));
|
|
744
|
+
if (!pending)
|
|
745
|
+
return;
|
|
746
|
+
worker.requests.delete(String(frame.request_id));
|
|
747
|
+
if (frame.ok)
|
|
748
|
+
pending.resolve(frame);
|
|
749
|
+
else
|
|
750
|
+
pending.reject(new Error(String(frame.error ?? "Worker request failed")));
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (frame.type === "event") {
|
|
754
|
+
const event = String(frame.event);
|
|
755
|
+
const payload = (frame.payload ?? {});
|
|
756
|
+
// text_delta / thinking_delta fire per token but change no snapshot
|
|
757
|
+
// field (taskOutput is worker-local; the snapshot only carries the final
|
|
758
|
+
// `output`). Publishing them broadcast an unchanged snapshot per token,
|
|
759
|
+
// per agent — pure SSE + re-render churn downstream. Accumulate and move
|
|
760
|
+
// on; real state changes publish below.
|
|
761
|
+
if (event === "text_delta" || event === "thinking_delta") {
|
|
762
|
+
if (event === "text_delta")
|
|
763
|
+
worker.taskOutput += String(payload.text ?? "");
|
|
764
|
+
worker.updated_at = Date.now();
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (event === "tool_call_start" || event === "tool_call_end") {
|
|
768
|
+
let recorder = this.pullRequests.get(worker.agent_id);
|
|
769
|
+
if (!recorder) {
|
|
770
|
+
recorder = new PullRequestRecorder();
|
|
771
|
+
this.pullRequests.set(worker.agent_id, recorder);
|
|
772
|
+
}
|
|
773
|
+
if (event === "tool_call_start")
|
|
774
|
+
recorder.start(payload.toolCallId, payload.name, payload.args);
|
|
775
|
+
else if (recorder.end(payload.toolCallId, payload.result, payload.isError)) {
|
|
776
|
+
worker.pull_requests = recorder.list();
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (event === "tool_call_start") {
|
|
780
|
+
worker.tool_use_count++;
|
|
781
|
+
worker.current_activity = activity(String(payload.name ?? "tool"), (payload.args ?? {}));
|
|
782
|
+
}
|
|
783
|
+
if (event === "turn_end") {
|
|
784
|
+
worker.turn_count++;
|
|
785
|
+
const usage = payload.usage;
|
|
786
|
+
worker.token_usage.input += usage?.inputTokens ?? 0;
|
|
787
|
+
worker.token_usage.output += usage?.outputTokens ?? 0;
|
|
788
|
+
worker.token_usage.cacheRead =
|
|
789
|
+
(worker.token_usage.cacheRead ?? 0) + (usage?.cacheRead ?? 0);
|
|
790
|
+
worker.token_usage.cacheWrite =
|
|
791
|
+
(worker.token_usage.cacheWrite ?? 0) + (usage?.cacheWrite ?? 0);
|
|
792
|
+
}
|
|
793
|
+
worker.updated_at = Date.now();
|
|
794
|
+
const durableProgress = event === "tool_call_start" || event === "turn_end";
|
|
795
|
+
this.publish(worker, durableProgress);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
if (frame.type === "turn_complete") {
|
|
799
|
+
worker.state =
|
|
800
|
+
frame.status === "completed"
|
|
801
|
+
? "completed"
|
|
802
|
+
: frame.status === "interrupted"
|
|
803
|
+
? "interrupted"
|
|
804
|
+
: "failed";
|
|
805
|
+
worker.output = boundSubAgentOutput(String(frame.output ?? worker.taskOutput));
|
|
806
|
+
worker.receipt = typeof frame.receipt === "string" ? frame.receipt : undefined;
|
|
807
|
+
worker.acceptance = typeof frame.acceptance === "string" ? frame.acceptance : undefined;
|
|
808
|
+
worker.error = frame.error ? String(frame.error) : undefined;
|
|
809
|
+
if (typeof frame.model === "string")
|
|
810
|
+
worker.model = frame.model;
|
|
811
|
+
worker.current_activity = undefined;
|
|
812
|
+
worker.updated_at = Date.now();
|
|
813
|
+
this.publish(worker);
|
|
814
|
+
this.notifyTerminal(worker);
|
|
815
|
+
for (const resolve of worker.turnResolvers)
|
|
816
|
+
resolve();
|
|
817
|
+
worker.turnResolvers.clear();
|
|
818
|
+
this.scheduleIdleReap(worker);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Announce a finished child into the parent's next turn. Carries the id, the
|
|
823
|
+
* state and a short digest — NOT the output, which stays behind `wait_agent`
|
|
824
|
+
* so a chatty child cannot dump its transcript into the parent's context.
|
|
825
|
+
*/
|
|
826
|
+
notifyTerminal(worker) {
|
|
827
|
+
const queue = this.options.notifications;
|
|
828
|
+
if (!queue)
|
|
829
|
+
return;
|
|
830
|
+
const digest = summarizeForNotification(worker.error ?? worker.output ?? "");
|
|
831
|
+
queue.enqueue("subagent", worker.agent_id, `Child agent "${worker.task_name}" (${worker.agent_id}) is ${worker.state} after ` +
|
|
832
|
+
`${worker.turn_count} turn(s)${digest ? `: ${digest}` : ""}. ` +
|
|
833
|
+
`${worker.acceptance ? `Acceptance checks: ${worker.acceptance}. ` : ""}` +
|
|
834
|
+
`Collect its full output with wait_agent agent_ids ["${worker.agent_id}"].`, { terminal: true, urgent: true });
|
|
835
|
+
}
|
|
836
|
+
request(worker, command, payload = {}) {
|
|
837
|
+
const stdin = worker.process.stdin;
|
|
838
|
+
if (!stdin?.writable)
|
|
839
|
+
return Promise.reject(new Error("Subagent worker is closed"));
|
|
840
|
+
const requestId = `${worker.agent_id}-${++worker.requestSequence}`;
|
|
841
|
+
return new Promise((resolve, reject) => {
|
|
842
|
+
worker.requests.set(requestId, { resolve, reject });
|
|
843
|
+
stdin.write(`${JSON.stringify({ request_id: requestId, command, ...payload })}\n`);
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
waitForChange(agentId) {
|
|
847
|
+
const worker = this.workers.get(agentId);
|
|
848
|
+
if (!worker || this.isTerminal(worker.state))
|
|
849
|
+
return Promise.resolve();
|
|
850
|
+
return new Promise((resolve) => {
|
|
851
|
+
worker.turnResolvers.add(resolve);
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
publish(worker, persist = true) {
|
|
855
|
+
const snapshot = this.snapshot(worker);
|
|
856
|
+
this.snapshots.delete(worker.agent_id);
|
|
857
|
+
this.snapshots.set(worker.agent_id, snapshot);
|
|
858
|
+
for (const id of this.snapshots.keys()) {
|
|
859
|
+
if (this.snapshots.size <= SNAPSHOT_LIMIT)
|
|
860
|
+
break;
|
|
861
|
+
this.snapshots.delete(id);
|
|
862
|
+
}
|
|
863
|
+
this.options.onState?.(snapshot);
|
|
864
|
+
for (const listener of this.listeners)
|
|
865
|
+
listener(snapshot);
|
|
866
|
+
if (persist)
|
|
867
|
+
this.queuePersist();
|
|
868
|
+
}
|
|
869
|
+
snapshot(worker) {
|
|
870
|
+
return {
|
|
871
|
+
agent_id: worker.agent_id,
|
|
872
|
+
task_name: worker.task_name,
|
|
873
|
+
state: worker.state,
|
|
874
|
+
started_at: worker.started_at,
|
|
875
|
+
updated_at: worker.updated_at,
|
|
876
|
+
elapsed_ms: this.elapsed(worker),
|
|
877
|
+
current_activity: worker.current_activity,
|
|
878
|
+
turn_count: worker.turn_count,
|
|
879
|
+
tool_use_count: worker.tool_use_count,
|
|
880
|
+
token_usage: { ...worker.token_usage },
|
|
881
|
+
output: worker.output,
|
|
882
|
+
receipt: worker.receipt,
|
|
883
|
+
...(worker.acceptance !== undefined && { acceptance: worker.acceptance }),
|
|
884
|
+
...(worker.pull_requests !== undefined && { pull_requests: [...worker.pull_requests] }),
|
|
885
|
+
error: worker.error,
|
|
886
|
+
agent_name: worker.agent_name,
|
|
887
|
+
provider: worker.provider,
|
|
888
|
+
model: worker.model,
|
|
889
|
+
child_session_id: worker.child_session_id,
|
|
890
|
+
child_session_path: worker.child_session_path,
|
|
891
|
+
...(worker.cwd !== undefined && { cwd: worker.cwd }),
|
|
892
|
+
collected: worker.collected,
|
|
893
|
+
recovered: worker.recovered,
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
queuePersist() {
|
|
897
|
+
if (!this.parentSessionId)
|
|
898
|
+
return;
|
|
899
|
+
this.persistPending = true;
|
|
900
|
+
if (this.persistScheduled)
|
|
901
|
+
return;
|
|
902
|
+
this.persistScheduled = true;
|
|
903
|
+
this.persistQueue = this.persistQueue
|
|
904
|
+
.catch(() => { })
|
|
905
|
+
.then(async () => {
|
|
906
|
+
while (this.persistPending) {
|
|
907
|
+
this.persistPending = false;
|
|
908
|
+
const parentSessionId = this.parentSessionId;
|
|
909
|
+
if (!parentSessionId)
|
|
910
|
+
continue;
|
|
911
|
+
const records = [...this.snapshots.values()].map((snapshot) => ({
|
|
912
|
+
...snapshot,
|
|
913
|
+
token_usage: { ...snapshot.token_usage },
|
|
914
|
+
}));
|
|
915
|
+
await this.store.save(this.options.cwd, parentSessionId, records);
|
|
916
|
+
}
|
|
917
|
+
})
|
|
918
|
+
.catch((error) => {
|
|
919
|
+
this.persistPending = false;
|
|
920
|
+
log("WARN", "subagent", "Failed to persist subagent state", {
|
|
921
|
+
error: error instanceof Error ? error.message : String(error),
|
|
922
|
+
});
|
|
923
|
+
})
|
|
924
|
+
.finally(() => {
|
|
925
|
+
this.persistScheduled = false;
|
|
926
|
+
if (this.persistPending)
|
|
927
|
+
this.queuePersist();
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
elapsed(snapshot) {
|
|
931
|
+
return ((this.isTerminal(snapshot.state) ? snapshot.updated_at : Date.now()) - snapshot.started_at);
|
|
932
|
+
}
|
|
933
|
+
activeCount() {
|
|
934
|
+
return [...this.workers.values()].filter((worker) => this.isActive(worker)).length;
|
|
935
|
+
}
|
|
936
|
+
/** Enforce the optional per-model cap against the resolved child model. */
|
|
937
|
+
assertModelCapacity(model) {
|
|
938
|
+
const depth = this.options.subAgentDepth ?? currentSubAgentDepth();
|
|
939
|
+
const cap = this.options.getMaxPerModel?.() ?? (depth >= 1 ? NESTED_DEFAULT_MAX_PER_MODEL : undefined);
|
|
940
|
+
if (cap === undefined)
|
|
941
|
+
return;
|
|
942
|
+
const activeOnModel = [...this.workers.values()].filter((worker) => this.isActive(worker) && worker.model === model).length;
|
|
943
|
+
if (activeOnModel >= cap) {
|
|
944
|
+
throw new Error(`At most ${cap} agents may run at once on model ${model} (subagentMaxPerModel) — ` +
|
|
945
|
+
`wait for one to finish or choose a different agent`);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
isActive(worker) {
|
|
949
|
+
return worker.state === "starting" || worker.state === "running";
|
|
950
|
+
}
|
|
951
|
+
isTerminal(state) {
|
|
952
|
+
return (state === "completed" ||
|
|
953
|
+
state === "failed" ||
|
|
954
|
+
state === "interrupted" ||
|
|
955
|
+
state === "closed" ||
|
|
956
|
+
state === "reaped");
|
|
957
|
+
}
|
|
958
|
+
requireWorker(agentId) {
|
|
959
|
+
const worker = this.workers.get(agentId);
|
|
960
|
+
if (!worker)
|
|
961
|
+
throw new Error(`Unknown or reaped agent: ${agentId}`);
|
|
962
|
+
return worker;
|
|
963
|
+
}
|
|
964
|
+
assertAvailable() {
|
|
965
|
+
if (this.shuttingDown)
|
|
966
|
+
throw new Error("Subagent manager is shutting down");
|
|
967
|
+
}
|
|
968
|
+
assertChildSessionPath(candidate) {
|
|
969
|
+
const root = path.resolve(this.sessionRootDir);
|
|
970
|
+
const resolved = path.resolve(candidate);
|
|
971
|
+
if (!resolved.startsWith(`${root}${path.sep}`) || path.extname(resolved) !== ".jsonl") {
|
|
972
|
+
throw new Error("Recovered child session path is outside the subagent session root");
|
|
973
|
+
}
|
|
974
|
+
return resolved;
|
|
975
|
+
}
|
|
976
|
+
createId() {
|
|
977
|
+
let id;
|
|
978
|
+
do
|
|
979
|
+
id = randomUUID().replaceAll("-", "").slice(0, 8);
|
|
980
|
+
while (this.snapshots.has(id));
|
|
981
|
+
return id;
|
|
982
|
+
}
|
|
983
|
+
scheduleIdleReap(worker) {
|
|
984
|
+
clearTimeout(worker.idleTimer);
|
|
985
|
+
worker.idleTimer = setTimeout(() => void this.close(worker), this.options.idleTimeoutMs ?? DEFAULT_IDLE_MS);
|
|
986
|
+
worker.idleTimer.unref?.();
|
|
987
|
+
this.reapExcessIdle();
|
|
988
|
+
}
|
|
989
|
+
reapExcessIdle() {
|
|
990
|
+
const idle = [...this.workers.values()]
|
|
991
|
+
.filter((worker) => this.isTerminal(worker.state))
|
|
992
|
+
.sort((a, b) => a.updated_at - b.updated_at);
|
|
993
|
+
for (const worker of idle.slice(0, Math.max(0, idle.length - RETAINED_WORKER_LIMIT))) {
|
|
994
|
+
void this.close(worker, true);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
fail(worker, error, kill = true) {
|
|
998
|
+
if (this.isTerminal(worker.state))
|
|
999
|
+
return;
|
|
1000
|
+
worker.state = "failed";
|
|
1001
|
+
worker.error = error instanceof Error ? error.message : String(error);
|
|
1002
|
+
worker.output = boundSubAgentOutput(worker.taskOutput);
|
|
1003
|
+
worker.updated_at = Date.now();
|
|
1004
|
+
for (const pending of worker.requests.values())
|
|
1005
|
+
pending.reject(new Error(worker.error));
|
|
1006
|
+
worker.requests.clear();
|
|
1007
|
+
this.publish(worker);
|
|
1008
|
+
for (const resolve of worker.turnResolvers)
|
|
1009
|
+
resolve();
|
|
1010
|
+
worker.turnResolvers.clear();
|
|
1011
|
+
if (kill)
|
|
1012
|
+
this.kill(worker);
|
|
1013
|
+
}
|
|
1014
|
+
async close(worker, reaped = false, preserveTerminal = false) {
|
|
1015
|
+
clearTimeout(worker.idleTimer);
|
|
1016
|
+
if (worker.process.stdin?.writable) {
|
|
1017
|
+
await Promise.race([
|
|
1018
|
+
this.request(worker, "shutdown").catch(() => undefined),
|
|
1019
|
+
new Promise((resolve) => setTimeout(resolve, 500)),
|
|
1020
|
+
]);
|
|
1021
|
+
}
|
|
1022
|
+
this.kill(worker);
|
|
1023
|
+
const closedError = new Error("Subagent worker closed");
|
|
1024
|
+
for (const pending of worker.requests.values())
|
|
1025
|
+
pending.reject(closedError);
|
|
1026
|
+
worker.requests.clear();
|
|
1027
|
+
for (const resolve of worker.turnResolvers)
|
|
1028
|
+
resolve();
|
|
1029
|
+
worker.turnResolvers.clear();
|
|
1030
|
+
if (reaped)
|
|
1031
|
+
worker.state = "reaped";
|
|
1032
|
+
else if (!preserveTerminal || !this.isTerminal(worker.state))
|
|
1033
|
+
worker.state = "closed";
|
|
1034
|
+
worker.updated_at = Date.now();
|
|
1035
|
+
this.publish(worker);
|
|
1036
|
+
this.workers.delete(worker.agent_id);
|
|
1037
|
+
this.pullRequests.delete(worker.agent_id);
|
|
1038
|
+
}
|
|
1039
|
+
kill(worker) {
|
|
1040
|
+
if (worker.process.exitCode !== null || worker.process.killed)
|
|
1041
|
+
return;
|
|
1042
|
+
try {
|
|
1043
|
+
if (process.platform === "win32" && worker.process.pid) {
|
|
1044
|
+
spawn("taskkill", ["/pid", String(worker.process.pid), "/T", "/F"], { stdio: "ignore" });
|
|
1045
|
+
}
|
|
1046
|
+
else if (worker.process.pid) {
|
|
1047
|
+
process.kill(-worker.process.pid, "SIGTERM");
|
|
1048
|
+
}
|
|
1049
|
+
else
|
|
1050
|
+
worker.process.kill("SIGTERM");
|
|
1051
|
+
}
|
|
1052
|
+
catch {
|
|
1053
|
+
worker.process.kill("SIGTERM");
|
|
1054
|
+
}
|
|
1055
|
+
const timer = setTimeout(() => {
|
|
1056
|
+
if (worker.process.exitCode !== null)
|
|
1057
|
+
return;
|
|
1058
|
+
try {
|
|
1059
|
+
if (process.platform === "win32" && worker.process.pid) {
|
|
1060
|
+
spawn("taskkill", ["/pid", String(worker.process.pid), "/T", "/F"], { stdio: "ignore" });
|
|
1061
|
+
}
|
|
1062
|
+
else if (worker.process.pid) {
|
|
1063
|
+
process.kill(-worker.process.pid, "SIGKILL");
|
|
1064
|
+
}
|
|
1065
|
+
else
|
|
1066
|
+
worker.process.kill("SIGKILL");
|
|
1067
|
+
}
|
|
1068
|
+
catch {
|
|
1069
|
+
worker.process.kill("SIGKILL");
|
|
1070
|
+
}
|
|
1071
|
+
}, 3_000);
|
|
1072
|
+
timer.unref?.();
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
//# sourceMappingURL=subagent-manager.js.map
|