@bastani/atomic 0.7.17-1 → 0.8.0-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/CHANGELOG.md +4183 -0
- package/README.md +655 -0
- package/dist/builtin/intercom/CHANGELOG.md +195 -0
- package/dist/builtin/intercom/LICENSE +21 -0
- package/dist/builtin/intercom/README.md +484 -0
- package/dist/builtin/intercom/broker/broker.ts +346 -0
- package/dist/builtin/intercom/broker/client.ts +535 -0
- package/dist/builtin/intercom/broker/framing.ts +57 -0
- package/dist/builtin/intercom/broker/paths.ts +21 -0
- package/dist/builtin/intercom/broker/spawn.ts +308 -0
- package/dist/builtin/intercom/config.ts +109 -0
- package/dist/builtin/intercom/index.ts +1780 -0
- package/dist/builtin/intercom/package.json +59 -0
- package/dist/builtin/intercom/reply-tracker.ts +102 -0
- package/dist/builtin/intercom/skills/intercom/SKILL.md +513 -0
- package/dist/builtin/intercom/types.ts +46 -0
- package/dist/builtin/intercom/ui/compose.ts +139 -0
- package/dist/builtin/intercom/ui/inline-message.ts +76 -0
- package/dist/builtin/intercom/ui/session-list.ts +162 -0
- package/dist/builtin/mcp/CHANGELOG.md +346 -0
- package/dist/builtin/mcp/LICENSE +21 -0
- package/dist/builtin/mcp/OAUTH.md +324 -0
- package/dist/builtin/mcp/README.md +373 -0
- package/dist/builtin/mcp/agent-dir.ts +21 -0
- package/dist/builtin/mcp/app-bridge.bundle.js +67 -0
- package/dist/builtin/mcp/cli.js +186 -0
- package/dist/builtin/mcp/commands.ts +420 -0
- package/dist/builtin/mcp/config.ts +667 -0
- package/dist/builtin/mcp/consent-manager.ts +64 -0
- package/dist/builtin/mcp/direct-tools.ts +427 -0
- package/dist/builtin/mcp/errors.ts +219 -0
- package/dist/builtin/mcp/glimpse-ui.ts +80 -0
- package/dist/builtin/mcp/host-html-template.ts +427 -0
- package/dist/builtin/mcp/index.ts +334 -0
- package/dist/builtin/mcp/init.ts +336 -0
- package/dist/builtin/mcp/lifecycle.ts +93 -0
- package/dist/builtin/mcp/logger.ts +169 -0
- package/dist/builtin/mcp/mcp-auth-flow.ts +362 -0
- package/dist/builtin/mcp/mcp-auth.ts +297 -0
- package/dist/builtin/mcp/mcp-callback-server.ts +284 -0
- package/dist/builtin/mcp/mcp-oauth-provider.ts +302 -0
- package/dist/builtin/mcp/mcp-panel.ts +826 -0
- package/dist/builtin/mcp/mcp-setup-panel.ts +577 -0
- package/dist/builtin/mcp/metadata-cache.ts +201 -0
- package/dist/builtin/mcp/npx-resolver.ts +424 -0
- package/dist/builtin/mcp/oauth-handler.ts +60 -0
- package/dist/builtin/mcp/onboarding-state.ts +68 -0
- package/dist/builtin/mcp/package.json +61 -0
- package/dist/builtin/mcp/proxy-modes.ts +803 -0
- package/dist/builtin/mcp/resource-tools.ts +17 -0
- package/dist/builtin/mcp/sampling-handler.ts +268 -0
- package/dist/builtin/mcp/server-manager.ts +375 -0
- package/dist/builtin/mcp/state.ts +41 -0
- package/dist/builtin/mcp/tool-metadata.ts +152 -0
- package/dist/builtin/mcp/tool-registrar.ts +46 -0
- package/dist/builtin/mcp/tool-result-renderer.ts +65 -0
- package/dist/builtin/mcp/types.ts +441 -0
- package/dist/builtin/mcp/ui-resource-handler.ts +145 -0
- package/dist/builtin/mcp/ui-server.ts +623 -0
- package/dist/builtin/mcp/ui-session.ts +384 -0
- package/dist/builtin/mcp/ui-stream-types.ts +89 -0
- package/dist/builtin/mcp/utils.ts +129 -0
- package/dist/builtin/subagents/CHANGELOG.md +1019 -0
- package/dist/builtin/subagents/README.md +991 -0
- package/dist/builtin/subagents/agents/code-simplifier.md +84 -0
- package/dist/builtin/subagents/agents/codebase-analyzer.md +158 -0
- package/dist/builtin/subagents/agents/codebase-locator.md +113 -0
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +317 -0
- package/dist/builtin/subagents/agents/codebase-pattern-finder.md +236 -0
- package/dist/builtin/subagents/agents/codebase-research-analyzer.md +181 -0
- package/dist/builtin/subagents/agents/codebase-research-locator.md +146 -0
- package/dist/builtin/subagents/agents/debugger.md +92 -0
- package/dist/builtin/subagents/package.json +67 -0
- package/dist/builtin/subagents/prompts/gather-context-and-clarify.md +20 -0
- package/dist/builtin/subagents/prompts/parallel-cleanup.md +60 -0
- package/dist/builtin/subagents/prompts/parallel-context-build.md +55 -0
- package/dist/builtin/subagents/prompts/parallel-handoff-plan.md +77 -0
- package/dist/builtin/subagents/prompts/parallel-research.md +58 -0
- package/dist/builtin/subagents/prompts/parallel-review.md +52 -0
- package/dist/builtin/subagents/prompts/review-loop.md +48 -0
- package/dist/builtin/subagents/skills/subagent/SKILL.md +734 -0
- package/dist/builtin/subagents/src/agents/agent-management.ts +644 -0
- package/dist/builtin/subagents/src/agents/agent-scope.ts +6 -0
- package/dist/builtin/subagents/src/agents/agent-selection.ts +23 -0
- package/dist/builtin/subagents/src/agents/agent-serializer.ts +84 -0
- package/dist/builtin/subagents/src/agents/agents.ts +809 -0
- package/dist/builtin/subagents/src/agents/chain-serializer.ts +137 -0
- package/dist/builtin/subagents/src/agents/frontmatter.ts +29 -0
- package/dist/builtin/subagents/src/agents/identity.ts +30 -0
- package/dist/builtin/subagents/src/agents/skills.ts +630 -0
- package/dist/builtin/subagents/src/extension/control-notices.ts +92 -0
- package/dist/builtin/subagents/src/extension/doctor.ts +199 -0
- package/dist/builtin/subagents/src/extension/index.ts +586 -0
- package/dist/builtin/subagents/src/extension/schemas.ts +168 -0
- package/dist/builtin/subagents/src/intercom/intercom-bridge.ts +378 -0
- package/dist/builtin/subagents/src/intercom/result-intercom.ts +269 -0
- package/dist/builtin/subagents/src/runs/background/async-execution.ts +612 -0
- package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +267 -0
- package/dist/builtin/subagents/src/runs/background/async-resume.ts +332 -0
- package/dist/builtin/subagents/src/runs/background/async-status.ts +295 -0
- package/dist/builtin/subagents/src/runs/background/completion-dedupe.ts +63 -0
- package/dist/builtin/subagents/src/runs/background/notify.ts +108 -0
- package/dist/builtin/subagents/src/runs/background/parallel-groups.ts +45 -0
- package/dist/builtin/subagents/src/runs/background/result-watcher.ts +250 -0
- package/dist/builtin/subagents/src/runs/background/run-status.ts +193 -0
- package/dist/builtin/subagents/src/runs/background/stale-run-reconciler.ts +291 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +1760 -0
- package/dist/builtin/subagents/src/runs/background/top-level-async.ts +13 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify.ts +1333 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution.ts +932 -0
- package/dist/builtin/subagents/src/runs/foreground/execution.ts +902 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +2231 -0
- package/dist/builtin/subagents/src/runs/shared/completion-guard.ts +125 -0
- package/dist/builtin/subagents/src/runs/shared/long-running-guard.ts +175 -0
- package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +103 -0
- package/dist/builtin/subagents/src/runs/shared/parallel-utils.ts +108 -0
- package/dist/builtin/subagents/src/runs/shared/pi-args.ts +163 -0
- package/dist/builtin/subagents/src/runs/shared/pi-spawn.ts +115 -0
- package/dist/builtin/subagents/src/runs/shared/run-history.ts +56 -0
- package/dist/builtin/subagents/src/runs/shared/single-output.ts +154 -0
- package/dist/builtin/subagents/src/runs/shared/subagent-control.ts +226 -0
- package/dist/builtin/subagents/src/runs/shared/subagent-prompt-runtime.ts +152 -0
- package/dist/builtin/subagents/src/runs/shared/worktree.ts +577 -0
- package/dist/builtin/subagents/src/shared/artifacts.ts +99 -0
- package/dist/builtin/subagents/src/shared/atomic-json.ts +16 -0
- package/dist/builtin/subagents/src/shared/file-coalescer.ts +40 -0
- package/dist/builtin/subagents/src/shared/fork-context.ts +76 -0
- package/dist/builtin/subagents/src/shared/formatters.ts +133 -0
- package/dist/builtin/subagents/src/shared/jsonl-writer.ts +81 -0
- package/dist/builtin/subagents/src/shared/model-info.ts +78 -0
- package/dist/builtin/subagents/src/shared/post-exit-stdio-guard.ts +85 -0
- package/dist/builtin/subagents/src/shared/session-identity.ts +10 -0
- package/dist/builtin/subagents/src/shared/session-tokens.ts +44 -0
- package/dist/builtin/subagents/src/shared/settings.ts +397 -0
- package/dist/builtin/subagents/src/shared/status-format.ts +49 -0
- package/dist/builtin/subagents/src/shared/types.ts +732 -0
- package/dist/builtin/subagents/src/shared/utils.ts +440 -0
- package/dist/builtin/subagents/src/slash/prompt-template-bridge.ts +397 -0
- package/dist/builtin/subagents/src/slash/slash-bridge.ts +174 -0
- package/dist/builtin/subagents/src/slash/slash-commands.ts +528 -0
- package/dist/builtin/subagents/src/slash/slash-live-state.ts +292 -0
- package/dist/builtin/subagents/src/tui/render-helpers.ts +80 -0
- package/dist/builtin/subagents/src/tui/render.ts +1257 -0
- package/dist/builtin/web-access/CHANGELOG.md +387 -0
- package/dist/builtin/web-access/LICENSE +21 -0
- package/dist/builtin/web-access/README.md +346 -0
- package/dist/builtin/web-access/activity.ts +101 -0
- package/dist/builtin/web-access/chrome-cookies.ts +322 -0
- package/dist/builtin/web-access/code-search.ts +107 -0
- package/dist/builtin/web-access/curator-page.ts +3359 -0
- package/dist/builtin/web-access/curator-server.ts +605 -0
- package/dist/builtin/web-access/exa.ts +521 -0
- package/dist/builtin/web-access/extract.ts +701 -0
- package/dist/builtin/web-access/gemini-api.ts +113 -0
- package/dist/builtin/web-access/gemini-search.ts +362 -0
- package/dist/builtin/web-access/gemini-url-context.ts +126 -0
- package/dist/builtin/web-access/gemini-web-config.ts +54 -0
- package/dist/builtin/web-access/gemini-web.ts +396 -0
- package/dist/builtin/web-access/github-api.ts +196 -0
- package/dist/builtin/web-access/github-extract.ts +635 -0
- package/dist/builtin/web-access/index.ts +2347 -0
- package/dist/builtin/web-access/package.json +54 -0
- package/dist/builtin/web-access/pdf-extract.ts +192 -0
- package/dist/builtin/web-access/perplexity.ts +196 -0
- package/dist/builtin/web-access/rsc-extract.ts +338 -0
- package/dist/builtin/web-access/storage.ts +72 -0
- package/dist/builtin/web-access/summary-review.ts +276 -0
- package/dist/builtin/web-access/utils.ts +44 -0
- package/dist/builtin/web-access/video-extract.ts +379 -0
- package/dist/builtin/web-access/youtube-extract.ts +311 -0
- package/dist/builtin/workflows/CHANGELOG.md +20 -0
- package/dist/builtin/workflows/README.md +323 -0
- package/dist/builtin/workflows/builtin/deep-research-codebase.ts +567 -0
- package/dist/builtin/workflows/builtin/index.ts +10 -0
- package/dist/builtin/workflows/builtin/open-claude-design.ts +985 -0
- package/dist/builtin/workflows/builtin/ralph.ts +613 -0
- package/dist/builtin/workflows/package.json +89 -0
- package/dist/builtin/workflows/skills/create-spec/SKILL.md +247 -0
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +173 -0
- package/dist/builtin/workflows/skills/impeccable/reference/adapt.md +190 -0
- package/dist/builtin/workflows/skills/impeccable/reference/animate.md +175 -0
- package/dist/builtin/workflows/skills/impeccable/reference/audit.md +133 -0
- package/dist/builtin/workflows/skills/impeccable/reference/bolder.md +113 -0
- package/dist/builtin/workflows/skills/impeccable/reference/brand.md +118 -0
- package/dist/builtin/workflows/skills/impeccable/reference/clarify.md +174 -0
- package/dist/builtin/workflows/skills/impeccable/reference/codex.md +105 -0
- package/dist/builtin/workflows/skills/impeccable/reference/cognitive-load.md +106 -0
- package/dist/builtin/workflows/skills/impeccable/reference/color-and-contrast.md +105 -0
- package/dist/builtin/workflows/skills/impeccable/reference/colorize.md +154 -0
- package/dist/builtin/workflows/skills/impeccable/reference/craft.md +123 -0
- package/dist/builtin/workflows/skills/impeccable/reference/critique.md +261 -0
- package/dist/builtin/workflows/skills/impeccable/reference/delight.md +302 -0
- package/dist/builtin/workflows/skills/impeccable/reference/distill.md +111 -0
- package/dist/builtin/workflows/skills/impeccable/reference/document.md +427 -0
- package/dist/builtin/workflows/skills/impeccable/reference/extract.md +69 -0
- package/dist/builtin/workflows/skills/impeccable/reference/harden.md +347 -0
- package/dist/builtin/workflows/skills/impeccable/reference/heuristics-scoring.md +234 -0
- package/dist/builtin/workflows/skills/impeccable/reference/interaction-design.md +195 -0
- package/dist/builtin/workflows/skills/impeccable/reference/layout.md +141 -0
- package/dist/builtin/workflows/skills/impeccable/reference/live.md +622 -0
- package/dist/builtin/workflows/skills/impeccable/reference/motion-design.md +109 -0
- package/dist/builtin/workflows/skills/impeccable/reference/onboard.md +234 -0
- package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +258 -0
- package/dist/builtin/workflows/skills/impeccable/reference/overdrive.md +130 -0
- package/dist/builtin/workflows/skills/impeccable/reference/personas.md +179 -0
- package/dist/builtin/workflows/skills/impeccable/reference/polish.md +242 -0
- package/dist/builtin/workflows/skills/impeccable/reference/product.md +62 -0
- package/dist/builtin/workflows/skills/impeccable/reference/quieter.md +99 -0
- package/dist/builtin/workflows/skills/impeccable/reference/responsive-design.md +114 -0
- package/dist/builtin/workflows/skills/impeccable/reference/shape.md +165 -0
- package/dist/builtin/workflows/skills/impeccable/reference/spatial-design.md +100 -0
- package/dist/builtin/workflows/skills/impeccable/reference/teach.md +156 -0
- package/dist/builtin/workflows/skills/impeccable/reference/typeset.md +124 -0
- package/dist/builtin/workflows/skills/impeccable/reference/typography.md +159 -0
- package/dist/builtin/workflows/skills/impeccable/reference/ux-writing.md +107 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/cleanup-deprecated.mjs +284 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/command-metadata.json +94 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/critique-storage.mjs +226 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/design-parser.mjs +820 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detect-csp.mjs +198 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable-paths.mjs +110 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/is-generated.mjs +69 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +646 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-session.js +123 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +4865 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-complete.mjs +75 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-completion.mjs +18 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-inject.mjs +446 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-poll.mjs +200 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-resume.mjs +48 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +847 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-session-store.mjs +254 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-status.mjs +47 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +632 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live.mjs +247 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/load-context.mjs +141 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/modern-screenshot.umd.js +14 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/pin.mjs +214 -0
- package/dist/builtin/workflows/skills/playwright-cli/SKILL.md +392 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/element-attributes.md +23 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/request-mocking.md +87 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/running-code.md +241 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/session-management.md +225 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/spec-driven-testing.md +305 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/storage-state.md +275 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/test-generation.md +134 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/tracing.md +139 -0
- package/dist/builtin/workflows/skills/playwright-cli/references/video-recording.md +143 -0
- package/dist/builtin/workflows/skills/prompt-engineer/SKILL.md +263 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/advanced_patterns.md +271 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/core_prompting.md +137 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/quality_improvement.md +193 -0
- package/dist/builtin/workflows/skills/research-codebase/SKILL.md +226 -0
- package/dist/builtin/workflows/skills/tdd/SKILL.md +109 -0
- package/dist/builtin/workflows/skills/tdd/deep-modules.md +33 -0
- package/dist/builtin/workflows/skills/tdd/interface-design.md +31 -0
- package/dist/builtin/workflows/skills/tdd/mocking.md +59 -0
- package/dist/builtin/workflows/skills/tdd/refactoring.md +10 -0
- package/dist/builtin/workflows/skills/tdd/tests.md +61 -0
- package/dist/builtin/workflows/skills/workflow/SKILL.md +255 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/advanced-evaluation.md +404 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/bdi-mental-states.md +313 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-compression.md +274 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-degradation.md +208 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-fundamentals.md +203 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-optimization.md +197 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/evaluation.md +253 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/filesystem-context.md +289 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/hosted-agents.md +262 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/memory-systems.md +221 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/multi-agent-patterns.md +259 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/project-development.md +293 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/tool-design.md +273 -0
- package/dist/builtin/workflows/skills/workflow/references/context-engineering.md +23 -0
- package/dist/builtin/workflows/skills/workflow/references/design-checklist.md +79 -0
- package/dist/builtin/workflows/skills/workflow/references/running-workflows.md +107 -0
- package/dist/builtin/workflows/skills/workflow/references/sdk-authoring.md +140 -0
- package/dist/builtin/workflows/src/extension/background-ui-adapter.ts +168 -0
- package/dist/builtin/workflows/src/extension/companions.ts +210 -0
- package/dist/builtin/workflows/src/extension/config-loader.ts +493 -0
- package/dist/builtin/workflows/src/extension/discovery.ts +501 -0
- package/dist/builtin/workflows/src/extension/dispatcher.ts +173 -0
- package/dist/builtin/workflows/src/extension/index.ts +2143 -0
- package/dist/builtin/workflows/src/extension/mcp.ts +110 -0
- package/dist/builtin/workflows/src/extension/render-call.ts +39 -0
- package/dist/builtin/workflows/src/extension/render-result.ts +214 -0
- package/dist/builtin/workflows/src/extension/renderers.ts +87 -0
- package/dist/builtin/workflows/src/extension/runtime.ts +360 -0
- package/dist/builtin/workflows/src/extension/status-writer.ts +167 -0
- package/dist/builtin/workflows/src/extension/wiring.ts +555 -0
- package/dist/builtin/workflows/src/extension/workflow-schema.ts +102 -0
- package/dist/builtin/workflows/src/index.ts +25 -0
- package/dist/builtin/workflows/src/intercom/intercom-bridge.ts +93 -0
- package/dist/builtin/workflows/src/intercom/intercom-routing.ts +125 -0
- package/dist/builtin/workflows/src/intercom/result-intercom.ts +240 -0
- package/dist/builtin/workflows/src/runs/background/cancellation-registry.ts +113 -0
- package/dist/builtin/workflows/src/runs/background/job-tracker.ts +81 -0
- package/dist/builtin/workflows/src/runs/background/runner.ts +152 -0
- package/dist/builtin/workflows/src/runs/background/status.ts +354 -0
- package/dist/builtin/workflows/src/runs/foreground/executor.ts +1522 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +233 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +712 -0
- package/dist/builtin/workflows/src/runs/shared/concurrency.ts +76 -0
- package/dist/builtin/workflows/src/runs/shared/graph-inference.ts +69 -0
- package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +293 -0
- package/dist/builtin/workflows/src/runs/shared/validate-inputs.ts +83 -0
- package/dist/builtin/workflows/src/runs/shared/workflow-runner.ts +170 -0
- package/dist/builtin/workflows/src/runs/shared/worktree.ts +577 -0
- package/dist/builtin/workflows/src/shared/persistence-compaction-policy.ts +72 -0
- package/dist/builtin/workflows/src/shared/persistence-restore.ts +257 -0
- package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +145 -0
- package/dist/builtin/workflows/src/shared/render-inputs-schema.ts +196 -0
- package/dist/builtin/workflows/src/shared/store-types.ts +160 -0
- package/dist/builtin/workflows/src/shared/store.ts +579 -0
- package/dist/builtin/workflows/src/shared/types.ts +566 -0
- package/dist/builtin/workflows/src/tui/chat-surface-message.ts +224 -0
- package/dist/builtin/workflows/src/tui/chat-surface.ts +511 -0
- package/dist/builtin/workflows/src/tui/color-utils.ts +64 -0
- package/dist/builtin/workflows/src/tui/connectors.ts +88 -0
- package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +307 -0
- package/dist/builtin/workflows/src/tui/edge.ts +24 -0
- package/dist/builtin/workflows/src/tui/graph-canvas.ts +108 -0
- package/dist/builtin/workflows/src/tui/graph-theme.ts +283 -0
- package/dist/builtin/workflows/src/tui/graph-view.ts +1217 -0
- package/dist/builtin/workflows/src/tui/header.ts +172 -0
- package/dist/builtin/workflows/src/tui/inline-form-card.ts +421 -0
- package/dist/builtin/workflows/src/tui/inline-form-editor.ts +638 -0
- package/dist/builtin/workflows/src/tui/inline-form-overlay.ts +326 -0
- package/dist/builtin/workflows/src/tui/inline-form-store.ts +78 -0
- package/dist/builtin/workflows/src/tui/inputs-overlay.ts +163 -0
- package/dist/builtin/workflows/src/tui/inputs-picker.ts +888 -0
- package/dist/builtin/workflows/src/tui/keybindings-adapter.ts +154 -0
- package/dist/builtin/workflows/src/tui/layout.ts +153 -0
- package/dist/builtin/workflows/src/tui/node-card.ts +274 -0
- package/dist/builtin/workflows/src/tui/overlay-adapter.ts +277 -0
- package/dist/builtin/workflows/src/tui/prompt-card.ts +501 -0
- package/dist/builtin/workflows/src/tui/renderers.ts +15 -0
- package/dist/builtin/workflows/src/tui/run-detail.ts +339 -0
- package/dist/builtin/workflows/src/tui/session-confirm.ts +202 -0
- package/dist/builtin/workflows/src/tui/session-list.ts +32 -0
- package/dist/builtin/workflows/src/tui/session-overlays.ts +239 -0
- package/dist/builtin/workflows/src/tui/session-picker.ts +399 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +1873 -0
- package/dist/builtin/workflows/src/tui/status-helpers.ts +73 -0
- package/dist/builtin/workflows/src/tui/status-list.ts +361 -0
- package/dist/builtin/workflows/src/tui/store-widget-installer.ts +206 -0
- package/dist/builtin/workflows/src/tui/switcher.ts +121 -0
- package/dist/builtin/workflows/src/tui/text-helpers.ts +31 -0
- package/dist/builtin/workflows/src/tui/toast.ts +106 -0
- package/dist/builtin/workflows/src/tui/widget.ts +348 -0
- package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +285 -0
- package/dist/builtin/workflows/src/tui/workflow-list.ts +224 -0
- package/dist/builtin/workflows/src/workflows/define-workflow.ts +150 -0
- package/dist/builtin/workflows/src/workflows/identity.ts +39 -0
- package/dist/builtin/workflows/src/workflows/registry.ts +113 -0
- package/dist/bun/cli.d.ts +3 -0
- package/dist/bun/cli.d.ts.map +1 -0
- package/dist/bun/cli.js +9 -0
- package/dist/bun/cli.js.map +1 -0
- package/dist/bun/register-bedrock.d.ts +2 -0
- package/dist/bun/register-bedrock.d.ts.map +1 -0
- package/dist/bun/register-bedrock.js +4 -0
- package/dist/bun/register-bedrock.js.map +1 -0
- package/dist/bun/restore-sandbox-env.d.ts +13 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +32 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -0
- package/dist/cli/args.d.ts +53 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +341 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config-selector.d.ts +14 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +31 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/file-processor.d.ts +15 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +83 -0
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/initial-message.d.ts +18 -0
- package/dist/cli/initial-message.d.ts.map +1 -0
- package/dist/cli/initial-message.js +22 -0
- package/dist/cli/initial-message.js.map +1 -0
- package/dist/cli/list-models.d.ts +9 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +98 -0
- package/dist/cli/list-models.js.map +1 -0
- package/dist/cli/session-picker.d.ts +9 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +35 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +20 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +102 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +411 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts +117 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -0
- package/dist/core/agent-session-runtime.js +292 -0
- package/dist/core/agent-session-runtime.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.d.ts.map +1 -0
- package/dist/core/agent-session-services.js +117 -0
- package/dist/core/agent-session-services.js.map +1 -0
- package/dist/core/agent-session.d.ts +595 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +2518 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-guidance.d.ts +5 -0
- package/dist/core/auth-guidance.d.ts.map +1 -0
- package/dist/core/auth-guidance.js +21 -0
- package/dist/core/auth-guidance.js.map +1 -0
- package/dist/core/auth-storage.d.ts +141 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +437 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +32 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +111 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/builtin-packages.d.ts +14 -0
- package/dist/core/builtin-packages.d.ts.map +1 -0
- package/dist/core/builtin-packages.js +113 -0
- package/dist/core/builtin-packages.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +88 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +243 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +121 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +615 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +38 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +153 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/defaults.d.ts +3 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +2 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/diagnostics.d.ts +15 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +2 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/event-bus.d.ts +9 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +25 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/exec.d.ts +29 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +75 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +249 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +37 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +224 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +1066 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1834 -0
- package/dist/core/export-html/tool-renderer.d.ts +34 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +108 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/extensions/index.d.ts +12 -0
- package/dist/core/extensions/index.d.ts.map +1 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/index.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +24 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +501 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +159 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +817 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1173 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +45 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts +20 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +22 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +52 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +309 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +353 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +294 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/messages.d.ts +77 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +123 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-registry.d.ts +150 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +726 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +110 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +493 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/output-guard.d.ts +6 -0
- package/dist/core/output-guard.d.ts.map +1 -0
- package/dist/core/output-guard.js +59 -0
- package/dist/core/output-guard.js.map +1 -0
- package/dist/core/package-manager.d.ts +198 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +1970 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +52 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +250 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/provider-display-names.d.ts +2 -0
- package/dist/core/provider-display-names.d.ts.map +1 -0
- package/dist/core/provider-display-names.js +33 -0
- package/dist/core/provider-display-names.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +23 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +126 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +196 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +698 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/sdk.d.ts +107 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +291 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/session-cwd.d.ts +19 -0
- package/dist/core/session-cwd.d.ts.map +1 -0
- package/dist/core/session-cwd.js +37 -0
- package/dist/core/session-cwd.js.map +1 -0
- package/dist/core/session-manager.d.ts +333 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1118 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-manager.d.ts +261 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +773 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +60 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +404 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +14 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +25 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/source-info.d.ts +18 -0
- package/dist/core/source-info.d.ts.map +1 -0
- package/dist/core/source-info.js +19 -0
- package/dist/core/source-info.js.map +1 -0
- package/dist/core/system-prompt.d.ts +28 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +120 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/telemetry.d.ts +3 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +10 -0
- package/dist/core/telemetry.js.map +1 -0
- package/dist/core/timings.d.ts +8 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +32 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts +10 -0
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/ask-user-question.js +82 -0
- package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -0
- package/dist/core/tools/ask-user-question/config.d.ts +11 -0
- package/dist/core/tools/ask-user-question/config.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/config.js +34 -0
- package/dist/core/tools/ask-user-question/config.js.map +1 -0
- package/dist/core/tools/ask-user-question/index.d.ts +19 -0
- package/dist/core/tools/ask-user-question/index.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/index.js +19 -0
- package/dist/core/tools/ask-user-question/index.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts +36 -0
- package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/build-questionnaire.js +213 -0
- package/dist/core/tools/ask-user-question/state/build-questionnaire.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/key-router.d.ts +53 -0
- package/dist/core/tools/ask-user-question/state/key-router.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/key-router.js +240 -0
- package/dist/core/tools/ask-user-question/state/key-router.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts +61 -0
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js +147 -0
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/row-intent.d.ts +91 -0
- package/dist/core/tools/ask-user-question/state/row-intent.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/row-intent.js +91 -0
- package/dist/core/tools/ask-user-question/state/row-intent.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts +21 -0
- package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/contract.js +2 -0
- package/dist/core/tools/ask-user-question/state/selectors/contract.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts +44 -0
- package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/derivations.js +76 -0
- package/dist/core/tools/ask-user-question/state/selectors/derivations.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/focus.d.ts +15 -0
- package/dist/core/tools/ask-user-question/state/selectors/focus.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/focus.js +18 -0
- package/dist/core/tools/ask-user-question/state/selectors/focus.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts +16 -0
- package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/projections.js +71 -0
- package/dist/core/tools/ask-user-question/state/selectors/projections.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/state-reducer.d.ts +44 -0
- package/dist/core/tools/ask-user-question/state/state-reducer.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/state-reducer.js +239 -0
- package/dist/core/tools/ask-user-question/state/state-reducer.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/state.d.ts +42 -0
- package/dist/core/tools/ask-user-question/state/state.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/state.js +2 -0
- package/dist/core/tools/ask-user-question/state/state.js.map +1 -0
- package/dist/core/tools/ask-user-question/tool/format-answer.d.ts +30 -0
- package/dist/core/tools/ask-user-question/tool/format-answer.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/tool/format-answer.js +39 -0
- package/dist/core/tools/ask-user-question/tool/format-answer.js.map +1 -0
- package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts +29 -0
- package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/tool/response-envelope.js +46 -0
- package/dist/core/tools/ask-user-question/tool/response-envelope.js.map +1 -0
- package/dist/core/tools/ask-user-question/tool/types.d.ts +113 -0
- package/dist/core/tools/ask-user-question/tool/types.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/tool/types.js +81 -0
- package/dist/core/tools/ask-user-question/tool/types.js.map +1 -0
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts +21 -0
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.js +49 -0
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/body-residual-spacer.d.ts +18 -0
- package/dist/core/tools/ask-user-question/view/body-residual-spacer.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/body-residual-spacer.js +21 -0
- package/dist/core/tools/ask-user-question/view/body-residual-spacer.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/component-binding.d.ts +23 -0
- package/dist/core/tools/ask-user-question/view/component-binding.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/component-binding.js +16 -0
- package/dist/core/tools/ask-user-question/view/component-binding.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/chat-row-view.d.ts +40 -0
- package/dist/core/tools/ask-user-question/view/components/chat-row-view.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/chat-row-view.js +31 -0
- package/dist/core/tools/ask-user-question/view/components/chat-row-view.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts +35 -0
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js +91 -0
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts +43 -0
- package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/option-list-view.js +37 -0
- package/dist/core/tools/ask-user-question/view/components/option-list-view.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts +36 -0
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.js +66 -0
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +46 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js +69 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-box-renderer.d.ts +39 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-box-renderer.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-box-renderer.js +76 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-box-renderer.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts +116 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.js +173 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts +66 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js +124 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts +37 -0
- package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/submit-picker.js +44 -0
- package/dist/core/tools/ask-user-question/view/components/submit-picker.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts +32 -0
- package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/tab-bar.js +33 -0
- package/dist/core/tools/ask-user-question/view/components/tab-bar.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts +122 -0
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js +161 -0
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts +66 -0
- package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/dialog-builder.js +85 -0
- package/dist/core/tools/ask-user-question/view/dialog-builder.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/props-adapter.d.ts +58 -0
- package/dist/core/tools/ask-user-question/view/props-adapter.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/props-adapter.js +67 -0
- package/dist/core/tools/ask-user-question/view/props-adapter.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/stateful-view.d.ts +24 -0
- package/dist/core/tools/ask-user-question/view/stateful-view.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/stateful-view.js +2 -0
- package/dist/core/tools/ask-user-question/view/stateful-view.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/tab-components.d.ts +15 -0
- package/dist/core/tools/ask-user-question/view/tab-components.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/tab-components.js +2 -0
- package/dist/core/tools/ask-user-question/view/tab-components.js.map +1 -0
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts +71 -0
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.js +129 -0
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.js.map +1 -0
- package/dist/core/tools/bash.d.ts +68 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +338 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +85 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +338 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +49 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +324 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts +6 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-queue.js +37 -0
- package/dist/core/tools/file-mutation-queue.js.map +1 -0
- package/dist/core/tools/find.d.ts +35 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +298 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +37 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +304 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +42 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +139 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +37 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +169 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +50 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +172 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +8 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +81 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/read.d.ts +35 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +289 -0
- package/dist/core/tools/read.js.map +1 -0
- package/dist/core/tools/render-utils.d.ts +21 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -0
- package/dist/core/tools/render-utils.js +49 -0
- package/dist/core/tools/render-utils.js.map +1 -0
- package/dist/core/tools/todos.d.ts +35 -0
- package/dist/core/tools/todos.d.ts.map +1 -0
- package/dist/core/tools/todos.js +906 -0
- package/dist/core/tools/todos.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.js +34 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +70 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +205 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/write.d.ts +26 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +212 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +13 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +586 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +33 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +281 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/index.d.ts +9 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +8 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/interactive/assets/clankolas.png +3 -0
- package/dist/modes/interactive/components/armin.d.ts +34 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/modes/interactive/components/armin.js +329 -0
- package/dist/modes/interactive/components/armin.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +20 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +116 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +34 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +170 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +51 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +42 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +43 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +71 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +496 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +28 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +29 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +113 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +20 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +74 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +23 -0
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
- package/dist/modes/interactive/components/daxnuts.js +138 -0
- package/dist/modes/interactive/components/daxnuts.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +151 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +20 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +20 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +106 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +23 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +55 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +26 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +75 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +27 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +199 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +32 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +33 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +36 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +46 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +158 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +47 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-selector.js +266 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +31 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +156 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +42 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +286 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +155 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +96 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +836 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +67 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +371 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +38 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +45 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +48 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +50 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +63 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +280 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +89 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +1079 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +111 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +10 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +28 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +33 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +369 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +4709 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -0
- package/dist/modes/interactive/theme/catppuccin-frappe.json +90 -0
- package/dist/modes/interactive/theme/catppuccin-latte.json +90 -0
- package/dist/modes/interactive/theme/catppuccin-macchiato.json +90 -0
- package/dist/modes/interactive/theme/catppuccin-mocha.json +90 -0
- package/dist/modes/interactive/theme/dark.json +85 -0
- package/dist/modes/interactive/theme/light.json +84 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +81 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +970 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/interactive/whimsical-messages.d.ts +5 -0
- package/dist/modes/interactive/whimsical-messages.d.ts.map +1 -0
- package/dist/modes/interactive/whimsical-messages.js +464 -0
- package/dist/modes/interactive/whimsical-messages.js.map +1 -0
- package/dist/modes/print-mode.d.ts +28 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +131 -0
- package/dist/modes/print-mode.js.map +1 -0
- package/dist/modes/rpc/jsonl.d.ts +17 -0
- package/dist/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/modes/rpc/jsonl.js +49 -0
- package/dist/modes/rpc/jsonl.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +224 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +409 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +601 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +419 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +8 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/package-manager-cli.d.ts +4 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +460 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/dist/utils/ansi.d.ts +2 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +52 -0
- package/dist/utils/ansi.js.map +1 -0
- package/dist/utils/changelog.d.ts +21 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +87 -0
- package/dist/utils/changelog.js.map +1 -0
- package/dist/utils/child-process.d.ts +12 -0
- package/dist/utils/child-process.d.ts.map +1 -0
- package/dist/utils/child-process.js +86 -0
- package/dist/utils/child-process.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +245 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard-native.d.ts +8 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -0
- package/dist/utils/clipboard-native.js +14 -0
- package/dist/utils/clipboard-native.js.map +1 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +117 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/exif-orientation.d.ts +5 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -0
- package/dist/utils/exif-orientation.js +158 -0
- package/dist/utils/exif-orientation.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +26 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/fs-watch.d.ts +5 -0
- package/dist/utils/fs-watch.d.ts.map +1 -0
- package/dist/utils/fs-watch.js +25 -0
- package/dist/utils/fs-watch.js.map +1 -0
- package/dist/utils/git.d.ts +26 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +163 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/html.d.ts +7 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +40 -0
- package/dist/utils/html.js.map +1 -0
- package/dist/utils/image-convert.d.ts +9 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +39 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-resize.d.ts +36 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +137 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/dist/utils/mime.d.ts +3 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +69 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/paths.d.ts +16 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +50 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/photon.d.ts +21 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +121 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +5 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/shell.d.ts +30 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +190 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +5 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +17 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/syntax-highlight.d.ts +12 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +118 -0
- package/dist/utils/syntax-highlight.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +325 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/dist/utils/version-check.d.ts +14 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +76 -0
- package/dist/utils/version-check.js.map +1 -0
- package/docs/compaction.md +394 -0
- package/docs/custom-provider.md +646 -0
- package/docs/development.md +71 -0
- package/docs/docs.json +148 -0
- package/docs/extensions.md +2596 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +3 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +70 -0
- package/docs/json.md +82 -0
- package/docs/keybindings.md +197 -0
- package/docs/models.md +474 -0
- package/docs/packages.md +223 -0
- package/docs/prompt-templates.md +88 -0
- package/docs/providers.md +243 -0
- package/docs/quickstart.md +142 -0
- package/docs/rpc.md +1407 -0
- package/docs/sdk.md +1129 -0
- package/docs/session-format.md +412 -0
- package/docs/sessions.md +137 -0
- package/docs/settings.md +279 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +232 -0
- package/docs/terminal-setup.md +106 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +299 -0
- package/docs/tmux.md +61 -0
- package/docs/tui.md +918 -0
- package/docs/usage.md +277 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +208 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +150 -0
- package/examples/extensions/built-in-tool-renderer.ts +249 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +127 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +79 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/handoff.ts +191 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +426 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +55 -0
- package/examples/extensions/overlay-qa-tests.ts +1348 -0
- package/examples/extensions/overlay-test.ts +150 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +65 -0
- package/examples/extensions/plan-mode/index.ts +340 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +430 -0
- package/examples/extensions/prompt-customizer.ts +97 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +122 -0
- package/examples/extensions/question.ts +264 -0
- package/examples/extensions/questionnaire.ts +427 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +321 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +172 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +126 -0
- package/examples/extensions/subagent/index.ts +987 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +206 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1008 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +297 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +141 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +123 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/rpc-extension-ui.ts +632 -0
- package/examples/sdk/01-minimal.ts +26 -0
- package/examples/sdk/02-custom-model.ts +53 -0
- package/examples/sdk/03-custom-prompt.ts +75 -0
- package/examples/sdk/04-skills.ts +55 -0
- package/examples/sdk/05-tools.ts +48 -0
- package/examples/sdk/06-extensions.ts +99 -0
- package/examples/sdk/07-context-files.ts +47 -0
- package/examples/sdk/08-prompt-templates.ts +51 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +52 -0
- package/examples/sdk/10-settings.ts +53 -0
- package/examples/sdk/11-sessions.ts +52 -0
- package/examples/sdk/12-full-control.ts +77 -0
- package/examples/sdk/13-session-runtime.ts +67 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +94 -19
- package/bin/atomic +0 -82
- /package/{LICENSE → dist/builtin/workflows/LICENSE} +0 -0
|
@@ -0,0 +1,2231 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
5
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { type AgentConfig, type AgentScope } from "../../agents/agents.ts";
|
|
7
|
+
import { getArtifactsDir } from "../../shared/artifacts.ts";
|
|
8
|
+
import { ChainClarifyComponent, type ChainClarifyResult } from "./chain-clarify.ts";
|
|
9
|
+
import { toModelInfo, type ModelInfo } from "../../shared/model-info.ts";
|
|
10
|
+
import { executeChain } from "./chain-execution.ts";
|
|
11
|
+
import { resolveExecutionAgentScope } from "../../agents/agent-scope.ts";
|
|
12
|
+
import { handleManagementAction } from "../../agents/agent-management.ts";
|
|
13
|
+
import { buildDoctorReport } from "../../extension/doctor.ts";
|
|
14
|
+
import { clearPendingForegroundControlNotices } from "../../extension/control-notices.ts";
|
|
15
|
+
import { runSync } from "./execution.ts";
|
|
16
|
+
import { resolveModelCandidate } from "../shared/model-fallback.ts";
|
|
17
|
+
import { aggregateParallelOutputs } from "../shared/parallel-utils.ts";
|
|
18
|
+
import { recordRun } from "../shared/run-history.ts";
|
|
19
|
+
import {
|
|
20
|
+
buildChainInstructions,
|
|
21
|
+
writeInitialProgressFile,
|
|
22
|
+
getStepAgents,
|
|
23
|
+
isParallelStep,
|
|
24
|
+
resolveStepBehavior,
|
|
25
|
+
suppressProgressForReadOnlyTask,
|
|
26
|
+
taskDisallowsFileUpdates,
|
|
27
|
+
type ChainStep,
|
|
28
|
+
type ResolvedStepBehavior,
|
|
29
|
+
type SequentialStep,
|
|
30
|
+
type StepOverrides,
|
|
31
|
+
} from "../../shared/settings.ts";
|
|
32
|
+
import { discoverAvailableSkills, normalizeSkillInput } from "../../agents/skills.ts";
|
|
33
|
+
import { executeAsyncChain, executeAsyncSingle, formatAsyncStartedMessage, isAsyncAvailable } from "../background/async-execution.ts";
|
|
34
|
+
import { createForkContextResolver } from "../../shared/fork-context.ts";
|
|
35
|
+
import { resolveCurrentSessionId } from "../../shared/session-identity.ts";
|
|
36
|
+
import { applyIntercomBridgeToAgent, INTERCOM_BRIDGE_MARKER, resolveIntercomBridge, resolveIntercomSessionTarget, resolveSubagentIntercomTarget, type IntercomBridgeState } from "../../intercom/intercom-bridge.ts";
|
|
37
|
+
import { formatControlIntercomMessage, formatControlNoticeMessage, resolveControlConfig, shouldNotifyControlEvent } from "../shared/subagent-control.ts";
|
|
38
|
+
import { finalizeSingleOutput, injectSingleOutputInstruction, resolveSingleOutputPath, validateFileOnlyOutputMode } from "../shared/single-output.ts";
|
|
39
|
+
import { compactForegroundDetails, getSingleResultOutput, mapConcurrent, readStatus, resolveChildCwd } from "../../shared/utils.ts";
|
|
40
|
+
import {
|
|
41
|
+
buildSubagentResultIntercomPayload,
|
|
42
|
+
deliverSubagentIntercomMessageEvent,
|
|
43
|
+
deliverSubagentResultIntercomEvent,
|
|
44
|
+
formatSubagentResultReceipt,
|
|
45
|
+
resolveSubagentResultStatus,
|
|
46
|
+
stripDetailsOutputsForIntercomReceipt,
|
|
47
|
+
} from "../../intercom/result-intercom.ts";
|
|
48
|
+
import { buildRevivedAsyncTask, resolveAsyncResumeTarget } from "../background/async-resume.ts";
|
|
49
|
+
import { inspectSubagentStatus } from "../background/run-status.ts";
|
|
50
|
+
import { applyForceTopLevelAsyncOverride } from "../background/top-level-async.ts";
|
|
51
|
+
import {
|
|
52
|
+
cleanupWorktrees,
|
|
53
|
+
createWorktrees,
|
|
54
|
+
diffWorktrees,
|
|
55
|
+
findWorktreeTaskCwdConflict,
|
|
56
|
+
formatWorktreeDiffSummary,
|
|
57
|
+
formatWorktreeTaskCwdConflict,
|
|
58
|
+
type WorktreeSetup,
|
|
59
|
+
} from "../shared/worktree.ts";
|
|
60
|
+
import {
|
|
61
|
+
type AgentProgress,
|
|
62
|
+
type ArtifactConfig,
|
|
63
|
+
type ArtifactPaths,
|
|
64
|
+
type ControlConfig,
|
|
65
|
+
type ControlEvent,
|
|
66
|
+
type Details,
|
|
67
|
+
type ExtensionConfig,
|
|
68
|
+
type IntercomEventBus,
|
|
69
|
+
type MaxOutputConfig,
|
|
70
|
+
type ResolvedControlConfig,
|
|
71
|
+
type SingleResult,
|
|
72
|
+
type SubagentRunMode,
|
|
73
|
+
type SubagentState,
|
|
74
|
+
DEFAULT_ARTIFACT_CONFIG,
|
|
75
|
+
SUBAGENT_ACTIONS,
|
|
76
|
+
SUBAGENT_CONTROL_EVENT,
|
|
77
|
+
SUBAGENT_CONTROL_INTERCOM_EVENT,
|
|
78
|
+
checkSubagentDepth,
|
|
79
|
+
resolveTopLevelParallelConcurrency,
|
|
80
|
+
resolveTopLevelParallelMaxTasks,
|
|
81
|
+
resolveChildMaxSubagentDepth,
|
|
82
|
+
resolveCurrentMaxSubagentDepth,
|
|
83
|
+
wrapForkTask,
|
|
84
|
+
} from "../../shared/types.ts";
|
|
85
|
+
|
|
86
|
+
const ASYNC_INTERRUPT_SIGNAL: NodeJS.Signals = process.platform === "win32" ? "SIGBREAK" : "SIGUSR2";
|
|
87
|
+
|
|
88
|
+
interface TaskParam {
|
|
89
|
+
agent: string;
|
|
90
|
+
task: string;
|
|
91
|
+
cwd?: string;
|
|
92
|
+
count?: number;
|
|
93
|
+
output?: string | boolean;
|
|
94
|
+
outputMode?: "inline" | "file-only";
|
|
95
|
+
reads?: string[] | boolean;
|
|
96
|
+
progress?: boolean;
|
|
97
|
+
model?: string;
|
|
98
|
+
skill?: string | string[] | boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface SubagentParamsLike {
|
|
102
|
+
action?: string;
|
|
103
|
+
id?: string;
|
|
104
|
+
runId?: string;
|
|
105
|
+
dir?: string;
|
|
106
|
+
index?: number;
|
|
107
|
+
agent?: string;
|
|
108
|
+
task?: string;
|
|
109
|
+
message?: string;
|
|
110
|
+
chain?: ChainStep[];
|
|
111
|
+
tasks?: TaskParam[];
|
|
112
|
+
concurrency?: number;
|
|
113
|
+
worktree?: boolean;
|
|
114
|
+
context?: "fresh" | "fork";
|
|
115
|
+
async?: boolean;
|
|
116
|
+
clarify?: boolean;
|
|
117
|
+
share?: boolean;
|
|
118
|
+
control?: ControlConfig;
|
|
119
|
+
sessionDir?: string;
|
|
120
|
+
cwd?: string;
|
|
121
|
+
maxOutput?: MaxOutputConfig;
|
|
122
|
+
artifacts?: boolean;
|
|
123
|
+
includeProgress?: boolean;
|
|
124
|
+
model?: string;
|
|
125
|
+
skill?: string | string[] | boolean;
|
|
126
|
+
output?: string | boolean;
|
|
127
|
+
outputMode?: "inline" | "file-only";
|
|
128
|
+
agentScope?: unknown;
|
|
129
|
+
chainDir?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface ExecutorDeps {
|
|
133
|
+
pi: ExtensionAPI;
|
|
134
|
+
state: SubagentState;
|
|
135
|
+
config: ExtensionConfig;
|
|
136
|
+
asyncByDefault: boolean;
|
|
137
|
+
tempArtifactsDir: string;
|
|
138
|
+
getSubagentSessionRoot: (parentSessionFile: string | null) => string;
|
|
139
|
+
expandTilde: (p: string) => string;
|
|
140
|
+
discoverAgents: (cwd: string, scope: AgentScope) => { agents: AgentConfig[] };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface ExecutionContextData {
|
|
144
|
+
params: SubagentParamsLike;
|
|
145
|
+
effectiveCwd: string;
|
|
146
|
+
ctx: ExtensionContext;
|
|
147
|
+
signal: AbortSignal;
|
|
148
|
+
onUpdate?: (r: AgentToolResult<Details>) => void;
|
|
149
|
+
agents: AgentConfig[];
|
|
150
|
+
runId: string;
|
|
151
|
+
shareEnabled: boolean;
|
|
152
|
+
sessionRoot: string;
|
|
153
|
+
sessionDirForIndex: (idx?: number) => string;
|
|
154
|
+
sessionFileForIndex: (idx?: number) => string | undefined;
|
|
155
|
+
artifactConfig: ArtifactConfig;
|
|
156
|
+
artifactsDir: string;
|
|
157
|
+
backgroundRequestedWhileClarifying: boolean;
|
|
158
|
+
effectiveAsync: boolean;
|
|
159
|
+
controlConfig: ResolvedControlConfig;
|
|
160
|
+
intercomBridge: IntercomBridgeState;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function resolveRequestedCwd(runtimeCwd: string, requestedCwd: string | undefined): string {
|
|
164
|
+
return requestedCwd ? path.resolve(runtimeCwd, requestedCwd) : runtimeCwd;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function getForegroundControl(state: SubagentState, runId: string | undefined) {
|
|
168
|
+
if (runId) return state.foregroundControls.get(runId);
|
|
169
|
+
if (state.lastForegroundControlId) {
|
|
170
|
+
const latest = state.foregroundControls.get(state.lastForegroundControlId);
|
|
171
|
+
if (latest) return latest;
|
|
172
|
+
}
|
|
173
|
+
let newest: (SubagentState["foregroundControls"] extends Map<string, infer T> ? T : never) | undefined;
|
|
174
|
+
for (const control of state.foregroundControls.values()) {
|
|
175
|
+
if (!newest || control.updatedAt > newest.updatedAt) newest = control;
|
|
176
|
+
}
|
|
177
|
+
return newest;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function formatForegroundActivity(control: SubagentState["foregroundControls"] extends Map<string, infer T> ? T : never): string | undefined {
|
|
181
|
+
const facts: string[] = [];
|
|
182
|
+
if (control.currentTool && control.currentToolStartedAt) facts.push(`tool ${control.currentTool} for ${Math.floor(Math.max(0, Date.now() - control.currentToolStartedAt) / 1000)}s`);
|
|
183
|
+
else if (control.currentTool) facts.push(`tool ${control.currentTool}`);
|
|
184
|
+
if (control.currentPath) facts.push(`path ${control.currentPath}`);
|
|
185
|
+
if (control.turnCount !== undefined) facts.push(`${control.turnCount} turns`);
|
|
186
|
+
if (control.tokens !== undefined) facts.push(`${control.tokens} tokens`);
|
|
187
|
+
if (control.toolCount !== undefined) facts.push(`${control.toolCount} tools`);
|
|
188
|
+
if (!control.lastActivityAt) {
|
|
189
|
+
if (control.currentActivityState === "needs_attention") return ["needs attention", ...facts].join(" | ");
|
|
190
|
+
if (control.currentActivityState === "active_long_running") return ["active but long-running", ...facts].join(" | ");
|
|
191
|
+
return facts.length ? facts.join(" | ") : undefined;
|
|
192
|
+
}
|
|
193
|
+
const seconds = Math.floor(Math.max(0, Date.now() - control.lastActivityAt) / 1000);
|
|
194
|
+
if (control.currentActivityState === "needs_attention") return [`no activity for ${seconds}s`, ...facts].join(" | ");
|
|
195
|
+
if (control.currentActivityState === "active_long_running") return [`active but long-running; last activity ${seconds}s ago`, ...facts].join(" | ");
|
|
196
|
+
return [`active ${seconds}s ago`, ...facts].join(" | ");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function foregroundStatusResult(control: SubagentState["foregroundControls"] extends Map<string, infer T> ? T : never): AgentToolResult<Details> {
|
|
200
|
+
const activity = formatForegroundActivity(control);
|
|
201
|
+
const lines = [
|
|
202
|
+
`Run: ${control.runId}`,
|
|
203
|
+
"State: running",
|
|
204
|
+
`Mode: ${control.mode}`,
|
|
205
|
+
control.currentAgent ? `Current: ${control.currentAgent}${control.currentIndex !== undefined ? ` step ${control.currentIndex + 1}` : ""}` : undefined,
|
|
206
|
+
activity ? `Activity: ${activity}` : undefined,
|
|
207
|
+
].filter((line): line is string => Boolean(line));
|
|
208
|
+
return { content: [{ type: "text", text: lines.join("\n") }], details: { mode: "management", results: [] } };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function rememberForegroundRun(state: SubagentState, input: { runId: string; mode: "single" | "parallel" | "chain"; cwd: string; results: SingleResult[] }): void {
|
|
212
|
+
state.foregroundRuns ??= new Map();
|
|
213
|
+
state.foregroundRuns.set(input.runId, {
|
|
214
|
+
runId: input.runId,
|
|
215
|
+
mode: input.mode,
|
|
216
|
+
cwd: input.cwd,
|
|
217
|
+
updatedAt: Date.now(),
|
|
218
|
+
children: input.results.map((result, index) => ({
|
|
219
|
+
agent: result.agent,
|
|
220
|
+
index,
|
|
221
|
+
status: resolveSubagentResultStatus({ exitCode: result.exitCode, interrupted: result.interrupted, detached: result.detached }),
|
|
222
|
+
...(result.sessionFile ? { sessionFile: result.sessionFile } : {}),
|
|
223
|
+
})),
|
|
224
|
+
});
|
|
225
|
+
while (state.foregroundRuns.size > 50) {
|
|
226
|
+
const oldest = [...state.foregroundRuns.values()].sort((left, right) => left.updatedAt - right.updatedAt)[0];
|
|
227
|
+
if (!oldest) break;
|
|
228
|
+
state.foregroundRuns.delete(oldest.runId);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function resolveForegroundResumeTarget(params: SubagentParamsLike, state: SubagentState): { runId: string; mode: "single" | "parallel" | "chain"; state: "complete"; agent: string; index: number; intercomTarget: string; cwd: string; sessionFile: string } | undefined {
|
|
233
|
+
const requested = (params.id ?? params.runId)?.trim();
|
|
234
|
+
if (!requested || !state.foregroundRuns?.size) return undefined;
|
|
235
|
+
const direct = state.foregroundRuns.get(requested);
|
|
236
|
+
const matches = direct ? [direct] : [...state.foregroundRuns.values()].filter((run) => run.runId.startsWith(requested));
|
|
237
|
+
if (matches.length === 0) return undefined;
|
|
238
|
+
if (matches.length > 1) throw new Error(`Ambiguous foreground run id prefix '${requested}' matched: ${matches.map((run) => run.runId).join(", ")}. Provide a longer id.`);
|
|
239
|
+
const run = matches[0]!;
|
|
240
|
+
if (run.children.length > 1 && params.index === undefined) throw new Error(`Foreground run '${run.runId}' has ${run.children.length} children. Provide index to choose one.`);
|
|
241
|
+
const index = params.index ?? 0;
|
|
242
|
+
if (!Number.isInteger(index)) throw new Error(`Foreground run '${run.runId}' index must be an integer.`);
|
|
243
|
+
if (index < 0 || index >= run.children.length) throw new Error(`Foreground run '${run.runId}' has ${run.children.length} children. Index ${index} is out of range.`);
|
|
244
|
+
const child = run.children[index]!;
|
|
245
|
+
if (child.status === "detached") throw new Error(`Foreground run '${run.runId}' child ${index} is detached for intercom coordination and cannot be revived safely from the remembered foreground state. Reply to the supervisor request first; after the child exits, start a fresh follow-up if needed.`);
|
|
246
|
+
if (!child.sessionFile) throw new Error(`Foreground run '${run.runId}' child ${index} does not have a persisted session file to resume from.`);
|
|
247
|
+
if (path.extname(child.sessionFile) !== ".jsonl") throw new Error(`Foreground run '${run.runId}' child ${index} session file must be a .jsonl file: ${child.sessionFile}`);
|
|
248
|
+
const sessionFile = path.resolve(child.sessionFile);
|
|
249
|
+
if (!fs.existsSync(sessionFile)) throw new Error(`Foreground run '${run.runId}' child ${index} session file does not exist: ${child.sessionFile}`);
|
|
250
|
+
return { runId: run.runId, mode: run.mode, state: "complete", agent: child.agent, index, intercomTarget: resolveSubagentIntercomTarget(run.runId, child.agent, index), cwd: run.cwd, sessionFile };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
type AsyncResumeSourceTarget = ReturnType<typeof resolveAsyncResumeTarget> & { source: "async" };
|
|
254
|
+
type ForegroundResumeSourceTarget = NonNullable<ReturnType<typeof resolveForegroundResumeTarget>> & { kind: "revive"; source: "foreground" };
|
|
255
|
+
type ResumeSourceTarget = AsyncResumeSourceTarget | ForegroundResumeSourceTarget;
|
|
256
|
+
|
|
257
|
+
function isAsyncRunNotFound(error: unknown): boolean {
|
|
258
|
+
return error instanceof Error && error.message.startsWith("Async run not found.");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function isResumeAmbiguity(error: unknown): boolean {
|
|
262
|
+
return error instanceof Error && /Ambiguous .*run id prefix/.test(error.message);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function resumeTargetExact(target: { runId: string } | undefined, requested: string): boolean {
|
|
266
|
+
return target?.runId === requested;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function escapeRegExp(value: string): string {
|
|
270
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function isExactResumeError(error: unknown, source: "async" | "foreground", requested: string): boolean {
|
|
274
|
+
if (!(error instanceof Error) || !requested) return false;
|
|
275
|
+
return new RegExp(`\\b${source} run '${escapeRegExp(requested)}'`, "i").test(error.message);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function resolveResumeTarget(params: SubagentParamsLike, state: SubagentState): ResumeSourceTarget {
|
|
279
|
+
const requested = (params.id ?? params.runId)?.trim() ?? "";
|
|
280
|
+
let foregroundTarget: ForegroundResumeSourceTarget | undefined;
|
|
281
|
+
let foregroundError: unknown;
|
|
282
|
+
let asyncTarget: AsyncResumeSourceTarget | undefined;
|
|
283
|
+
let asyncError: unknown;
|
|
284
|
+
|
|
285
|
+
try {
|
|
286
|
+
const target = resolveForegroundResumeTarget(params, state);
|
|
287
|
+
if (target) foregroundTarget = { kind: "revive", source: "foreground", ...target };
|
|
288
|
+
} catch (error) {
|
|
289
|
+
foregroundError = error;
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
asyncTarget = { source: "async", ...resolveAsyncResumeTarget(params) };
|
|
293
|
+
} catch (error) {
|
|
294
|
+
asyncError = error;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (foregroundTarget && asyncTarget) {
|
|
298
|
+
const foregroundExact = resumeTargetExact(foregroundTarget, requested);
|
|
299
|
+
const asyncExact = resumeTargetExact(asyncTarget, requested);
|
|
300
|
+
if (foregroundExact && !asyncExact) return foregroundTarget;
|
|
301
|
+
if (asyncExact && !foregroundExact) return asyncTarget;
|
|
302
|
+
throw new Error(`Resume id '${requested}' is ambiguous between foreground run '${foregroundTarget.runId}' and async run '${asyncTarget.runId}'. Provide a full run id.`);
|
|
303
|
+
}
|
|
304
|
+
if (foregroundTarget) {
|
|
305
|
+
if (isExactResumeError(asyncError, "async", requested)) throw asyncError;
|
|
306
|
+
if (isResumeAmbiguity(asyncError) && !resumeTargetExact(foregroundTarget, requested)) throw asyncError;
|
|
307
|
+
return foregroundTarget;
|
|
308
|
+
}
|
|
309
|
+
if (asyncTarget) {
|
|
310
|
+
if (isExactResumeError(foregroundError, "foreground", requested)) throw foregroundError;
|
|
311
|
+
if (isResumeAmbiguity(foregroundError) && !resumeTargetExact(asyncTarget, requested)) throw foregroundError;
|
|
312
|
+
return asyncTarget;
|
|
313
|
+
}
|
|
314
|
+
if (foregroundError && !isAsyncRunNotFound(asyncError)) throw foregroundError;
|
|
315
|
+
if (foregroundError) throw foregroundError;
|
|
316
|
+
if (asyncError) throw asyncError;
|
|
317
|
+
throw new Error("Run not found. Provide id or runId.");
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function getAsyncInterruptTarget(state: SubagentState, runId: string | undefined): { asyncId: string; asyncDir: string } | undefined {
|
|
321
|
+
if (runId) {
|
|
322
|
+
const direct = state.asyncJobs.get(runId);
|
|
323
|
+
if (direct) return { asyncId: direct.asyncId, asyncDir: direct.asyncDir };
|
|
324
|
+
}
|
|
325
|
+
let newest: { asyncId: string; asyncDir: string; updatedAt: number } | undefined;
|
|
326
|
+
for (const job of state.asyncJobs.values()) {
|
|
327
|
+
if (job.status !== "running") continue;
|
|
328
|
+
if (!newest || (job.updatedAt ?? 0) > newest.updatedAt) {
|
|
329
|
+
newest = { asyncId: job.asyncId, asyncDir: job.asyncDir, updatedAt: job.updatedAt ?? 0 };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return newest ? { asyncId: newest.asyncId, asyncDir: newest.asyncDir } : undefined;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function emitControlNotification(input: {
|
|
336
|
+
pi: ExtensionAPI;
|
|
337
|
+
controlConfig: ResolvedControlConfig;
|
|
338
|
+
intercomBridge: IntercomBridgeState;
|
|
339
|
+
event: ControlEvent;
|
|
340
|
+
}): void {
|
|
341
|
+
if (!shouldNotifyControlEvent(input.controlConfig, input.event)) return;
|
|
342
|
+
const childIntercomTarget = input.intercomBridge.active
|
|
343
|
+
? resolveSubagentIntercomTarget(input.event.runId, input.event.agent, input.event.index)
|
|
344
|
+
: undefined;
|
|
345
|
+
const payload = {
|
|
346
|
+
event: input.event,
|
|
347
|
+
source: "foreground" as const,
|
|
348
|
+
childIntercomTarget,
|
|
349
|
+
noticeText: formatControlNoticeMessage(input.event, childIntercomTarget),
|
|
350
|
+
};
|
|
351
|
+
if (input.controlConfig.notifyChannels.includes("event")) {
|
|
352
|
+
input.pi.events.emit(SUBAGENT_CONTROL_EVENT, payload);
|
|
353
|
+
}
|
|
354
|
+
if (input.event.type !== "active_long_running" && input.controlConfig.notifyChannels.includes("intercom") && input.intercomBridge.active && input.intercomBridge.orchestratorTarget) {
|
|
355
|
+
input.pi.events.emit(SUBAGENT_CONTROL_INTERCOM_EVENT, {
|
|
356
|
+
...payload,
|
|
357
|
+
to: input.intercomBridge.orchestratorTarget,
|
|
358
|
+
message: formatControlIntercomMessage(input.event, childIntercomTarget),
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function interruptAsyncRun(state: SubagentState, runId: string | undefined): AgentToolResult<Details> | null {
|
|
364
|
+
const target = getAsyncInterruptTarget(state, runId);
|
|
365
|
+
if (!target) return null;
|
|
366
|
+
const status = readStatus(target.asyncDir);
|
|
367
|
+
if (!status || status.state !== "running" || typeof status.pid !== "number") {
|
|
368
|
+
return {
|
|
369
|
+
content: [{ type: "text", text: `No running async run with an interrupt-capable pid was found for '${runId ?? "current"}'.` }],
|
|
370
|
+
isError: true,
|
|
371
|
+
details: { mode: "management", results: [] },
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
process.kill(status.pid, ASYNC_INTERRUPT_SIGNAL);
|
|
376
|
+
const tracked = state.asyncJobs.get(target.asyncId);
|
|
377
|
+
if (tracked) {
|
|
378
|
+
tracked.activityState = undefined;
|
|
379
|
+
tracked.updatedAt = Date.now();
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
content: [{ type: "text", text: `Interrupt requested for async run ${target.asyncId}.` }],
|
|
383
|
+
details: { mode: "management", results: [] },
|
|
384
|
+
};
|
|
385
|
+
} catch (error) {
|
|
386
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
387
|
+
return {
|
|
388
|
+
content: [{ type: "text", text: `Failed to interrupt async run ${target.asyncId}: ${message}` }],
|
|
389
|
+
isError: true,
|
|
390
|
+
details: { mode: "management", results: [] },
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async function resumeAsyncRun(input: {
|
|
396
|
+
params: SubagentParamsLike;
|
|
397
|
+
requestCwd: string;
|
|
398
|
+
ctx: ExtensionContext;
|
|
399
|
+
deps: ExecutorDeps;
|
|
400
|
+
}): Promise<AgentToolResult<Details>> {
|
|
401
|
+
const followUp = (input.params.message ?? input.params.task ?? "").trim();
|
|
402
|
+
if (!followUp) {
|
|
403
|
+
return {
|
|
404
|
+
content: [{ type: "text", text: "action='resume' requires message." }],
|
|
405
|
+
isError: true,
|
|
406
|
+
details: { mode: "management", results: [] },
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
let target: ResumeSourceTarget;
|
|
411
|
+
try {
|
|
412
|
+
target = resolveResumeTarget(input.params, input.deps.state);
|
|
413
|
+
} catch (error) {
|
|
414
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
415
|
+
return { content: [{ type: "text", text: message }], isError: true, details: { mode: "management", results: [] } };
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (target.kind === "live") {
|
|
419
|
+
const delivered = await deliverSubagentIntercomMessageEvent(
|
|
420
|
+
input.deps.pi.events,
|
|
421
|
+
target.intercomTarget,
|
|
422
|
+
`Follow-up for async run ${target.runId} (${target.agent}):\n\n${followUp}`,
|
|
423
|
+
500,
|
|
424
|
+
{ source: "async-resume", runId: target.runId, agent: target.agent, index: target.index },
|
|
425
|
+
);
|
|
426
|
+
if (delivered) {
|
|
427
|
+
return {
|
|
428
|
+
content: [{ type: "text", text: [`Delivered follow-up to live async child.`, `Run: ${target.runId}`, `Intercom target: ${target.intercomTarget}`].join("\n") }],
|
|
429
|
+
details: { mode: "management", results: [] },
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
return {
|
|
433
|
+
content: [{ type: "text", text: [`Async child appears live but its intercom target is not registered.`, `Run: ${target.runId}`, `Intercom target: ${target.intercomTarget}`, `Wait for completion, then retry action='resume'.`].join("\n") }],
|
|
434
|
+
isError: true,
|
|
435
|
+
details: { mode: "management", results: [] },
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const { blocked, depth, maxDepth } = checkSubagentDepth(input.deps.config.maxSubagentDepth);
|
|
440
|
+
if (blocked) {
|
|
441
|
+
return {
|
|
442
|
+
content: [{ type: "text", text: `Nested subagent resume blocked (depth=${depth}, max=${maxDepth}). Complete the follow-up directly instead.` }],
|
|
443
|
+
isError: true,
|
|
444
|
+
details: { mode: "management", results: [] },
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const parentSessionFile = input.ctx.sessionManager.getSessionFile() ?? null;
|
|
449
|
+
input.deps.state.currentSessionId = resolveCurrentSessionId(input.ctx.sessionManager);
|
|
450
|
+
const effectiveCwd = target.cwd ?? input.requestCwd;
|
|
451
|
+
const scope: AgentScope = resolveExecutionAgentScope(input.params.agentScope);
|
|
452
|
+
const discoveredAgents = input.deps.discoverAgents(effectiveCwd, scope).agents;
|
|
453
|
+
const sessionName = resolveIntercomSessionTarget(input.deps.pi.getSessionName(), input.ctx.sessionManager.getSessionId());
|
|
454
|
+
const intercomBridge = resolveIntercomBridge({
|
|
455
|
+
config: input.deps.config.intercomBridge,
|
|
456
|
+
context: input.params.context,
|
|
457
|
+
orchestratorTarget: sessionName,
|
|
458
|
+
cwd: effectiveCwd,
|
|
459
|
+
});
|
|
460
|
+
const agents = intercomBridge.active
|
|
461
|
+
? discoveredAgents.map((agent) => applyIntercomBridgeToAgent(agent, intercomBridge))
|
|
462
|
+
: discoveredAgents;
|
|
463
|
+
const agentConfig = agents.find((agent) => agent.name === target.agent);
|
|
464
|
+
if (!agentConfig) {
|
|
465
|
+
return {
|
|
466
|
+
content: [{ type: "text", text: `Unknown agent for resume: ${target.agent}` }],
|
|
467
|
+
isError: true,
|
|
468
|
+
details: { mode: "management", results: [] },
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const runId = randomUUID().slice(0, 8);
|
|
473
|
+
const artifactConfig: ArtifactConfig = { ...DEFAULT_ARTIFACT_CONFIG, enabled: input.params.artifacts !== false };
|
|
474
|
+
const availableModels = input.ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
475
|
+
const result = executeAsyncSingle(runId, {
|
|
476
|
+
agent: target.agent,
|
|
477
|
+
task: buildRevivedAsyncTask(target, followUp),
|
|
478
|
+
agentConfig,
|
|
479
|
+
ctx: {
|
|
480
|
+
pi: input.deps.pi,
|
|
481
|
+
cwd: input.requestCwd,
|
|
482
|
+
currentSessionId: input.deps.state.currentSessionId,
|
|
483
|
+
currentModelProvider: input.ctx.model?.provider,
|
|
484
|
+
},
|
|
485
|
+
cwd: effectiveCwd,
|
|
486
|
+
maxOutput: input.params.maxOutput,
|
|
487
|
+
artifactsDir: input.deps.tempArtifactsDir,
|
|
488
|
+
artifactConfig,
|
|
489
|
+
shareEnabled: input.params.share === true,
|
|
490
|
+
sessionRoot: input.deps.getSubagentSessionRoot(parentSessionFile),
|
|
491
|
+
sessionFile: target.sessionFile,
|
|
492
|
+
maxSubagentDepth: resolveCurrentMaxSubagentDepth(input.deps.config.maxSubagentDepth),
|
|
493
|
+
worktreeSetupHook: input.deps.config.worktreeSetupHook,
|
|
494
|
+
worktreeSetupHookTimeoutMs: input.deps.config.worktreeSetupHookTimeoutMs,
|
|
495
|
+
controlConfig: resolveControlConfig(input.deps.config.control, input.params.control),
|
|
496
|
+
controlIntercomTarget: intercomBridge.active ? intercomBridge.orchestratorTarget : undefined,
|
|
497
|
+
childIntercomTarget: intercomBridge.active ? (agent, index) => resolveSubagentIntercomTarget(runId, agent, index) : undefined,
|
|
498
|
+
availableModels,
|
|
499
|
+
});
|
|
500
|
+
if (result.isError) return result;
|
|
501
|
+
|
|
502
|
+
const revivedId = result.details.asyncId ?? runId;
|
|
503
|
+
const revivedTarget = intercomBridge.active ? resolveSubagentIntercomTarget(revivedId, target.agent, 0) : undefined;
|
|
504
|
+
const sourceLabel = target.source === "foreground" ? "foreground" : "async";
|
|
505
|
+
const lines = [
|
|
506
|
+
`Revived ${sourceLabel} subagent from ${target.runId}.`,
|
|
507
|
+
`Revived run: ${revivedId}`,
|
|
508
|
+
`Agent: ${target.agent}`,
|
|
509
|
+
`Session: ${target.sessionFile}`,
|
|
510
|
+
result.details.asyncDir ? `Async dir: ${result.details.asyncDir}` : undefined,
|
|
511
|
+
revivedTarget ? `Intercom target: ${revivedTarget} (if registered)` : undefined,
|
|
512
|
+
`Status if needed: subagent({ action: "status", id: "${revivedId}" })`,
|
|
513
|
+
].filter((line): line is string => Boolean(line));
|
|
514
|
+
return { content: [{ type: "text", text: formatAsyncStartedMessage(lines.join("\n")) }], details: result.details };
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function resultSummaryForIntercom(result: SingleResult): string {
|
|
518
|
+
const output = getSingleResultOutput(result);
|
|
519
|
+
if (result.exitCode !== 0 && result.error) {
|
|
520
|
+
return output ? `${result.error}\n\nOutput:\n${output}` : result.error;
|
|
521
|
+
}
|
|
522
|
+
return output || result.error || "(no output)";
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function createForegroundControlNotifier(data: Pick<ExecutionContextData, "controlConfig" | "intercomBridge">, deps: Pick<ExecutorDeps, "pi">): (event: ControlEvent) => void {
|
|
526
|
+
return (event) => emitControlNotification({
|
|
527
|
+
pi: deps.pi,
|
|
528
|
+
controlConfig: data.controlConfig,
|
|
529
|
+
intercomBridge: data.intercomBridge,
|
|
530
|
+
event,
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
async function emitForegroundResultIntercom(input: {
|
|
535
|
+
pi: ExtensionAPI;
|
|
536
|
+
intercomBridge: IntercomBridgeState;
|
|
537
|
+
runId: string;
|
|
538
|
+
mode: SubagentRunMode;
|
|
539
|
+
results: SingleResult[];
|
|
540
|
+
chainSteps?: number;
|
|
541
|
+
}): Promise<ReturnType<typeof buildSubagentResultIntercomPayload> | null> {
|
|
542
|
+
if (!input.intercomBridge.active || !input.intercomBridge.orchestratorTarget) return null;
|
|
543
|
+
const children = input.results.flatMap((result, index) => result.detached ? [] : [{
|
|
544
|
+
agent: result.agent,
|
|
545
|
+
status: resolveSubagentResultStatus({
|
|
546
|
+
exitCode: result.exitCode,
|
|
547
|
+
interrupted: result.interrupted,
|
|
548
|
+
detached: result.detached,
|
|
549
|
+
}),
|
|
550
|
+
summary: resultSummaryForIntercom(result),
|
|
551
|
+
index,
|
|
552
|
+
artifactPath: result.artifactPaths?.outputPath,
|
|
553
|
+
sessionPath: result.sessionFile,
|
|
554
|
+
intercomTarget: resolveSubagentIntercomTarget(input.runId, result.agent, index),
|
|
555
|
+
}]);
|
|
556
|
+
if (children.length === 0) return null;
|
|
557
|
+
const payload = buildSubagentResultIntercomPayload({
|
|
558
|
+
to: input.intercomBridge.orchestratorTarget,
|
|
559
|
+
runId: input.runId,
|
|
560
|
+
mode: input.mode,
|
|
561
|
+
source: "foreground",
|
|
562
|
+
children,
|
|
563
|
+
...(typeof input.chainSteps === "number" ? { chainSteps: input.chainSteps } : {}),
|
|
564
|
+
});
|
|
565
|
+
const delivered = await deliverSubagentResultIntercomEvent(input.pi.events, payload);
|
|
566
|
+
if (!delivered) return null;
|
|
567
|
+
return payload;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
async function maybeBuildForegroundIntercomReceipt(input: {
|
|
571
|
+
pi: ExtensionAPI;
|
|
572
|
+
intercomBridge: IntercomBridgeState;
|
|
573
|
+
runId: string;
|
|
574
|
+
mode: SubagentRunMode;
|
|
575
|
+
details: Details;
|
|
576
|
+
}): Promise<{ text: string; details: Details } | null> {
|
|
577
|
+
const payload = await emitForegroundResultIntercom({
|
|
578
|
+
pi: input.pi,
|
|
579
|
+
intercomBridge: input.intercomBridge,
|
|
580
|
+
runId: input.runId,
|
|
581
|
+
mode: input.mode,
|
|
582
|
+
results: input.details.results,
|
|
583
|
+
...(typeof input.details.totalSteps === "number" ? { chainSteps: input.details.totalSteps } : {}),
|
|
584
|
+
});
|
|
585
|
+
if (!payload) return null;
|
|
586
|
+
return {
|
|
587
|
+
text: formatSubagentResultReceipt({ mode: input.mode, runId: input.runId, payload }),
|
|
588
|
+
details: stripDetailsOutputsForIntercomReceipt(input.details),
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function validateExecutionInput(
|
|
593
|
+
params: SubagentParamsLike,
|
|
594
|
+
agents: AgentConfig[],
|
|
595
|
+
hasChain: boolean,
|
|
596
|
+
hasTasks: boolean,
|
|
597
|
+
hasSingle: boolean,
|
|
598
|
+
allowClarifyTaskPrompt: boolean,
|
|
599
|
+
): AgentToolResult<Details> | null {
|
|
600
|
+
if (Number(hasChain) + Number(hasTasks) + Number(hasSingle) !== 1) {
|
|
601
|
+
return {
|
|
602
|
+
content: [
|
|
603
|
+
{
|
|
604
|
+
type: "text",
|
|
605
|
+
text: `Provide exactly one mode. Agents: ${agents.map((a) => a.name).join(", ") || "none"}`,
|
|
606
|
+
},
|
|
607
|
+
],
|
|
608
|
+
isError: true,
|
|
609
|
+
details: { mode: "single" as const, results: [] },
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (hasSingle && params.agent && !agents.find((agent) => agent.name === params.agent)) {
|
|
614
|
+
return {
|
|
615
|
+
content: [{ type: "text", text: `Unknown agent: ${params.agent}` }],
|
|
616
|
+
isError: true,
|
|
617
|
+
details: { mode: "single" as const, results: [] },
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (hasTasks && params.tasks) {
|
|
622
|
+
for (let i = 0; i < params.tasks.length; i++) {
|
|
623
|
+
const task = params.tasks[i]!;
|
|
624
|
+
if (!agents.find((agent) => agent.name === task.agent)) {
|
|
625
|
+
return {
|
|
626
|
+
content: [{ type: "text", text: `Unknown agent: ${task.agent} (task ${i + 1})` }],
|
|
627
|
+
isError: true,
|
|
628
|
+
details: { mode: "parallel" as const, results: [] },
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (hasChain && params.chain) {
|
|
635
|
+
if (params.chain.length === 0) {
|
|
636
|
+
return {
|
|
637
|
+
content: [{ type: "text", text: "Chain must have at least one step" }],
|
|
638
|
+
isError: true,
|
|
639
|
+
details: { mode: "chain" as const, results: [] },
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
const firstStep = params.chain[0] as ChainStep;
|
|
643
|
+
if (isParallelStep(firstStep)) {
|
|
644
|
+
const missingTaskIndex = firstStep.parallel.findIndex((t) => !t.task);
|
|
645
|
+
if (missingTaskIndex !== -1) {
|
|
646
|
+
return {
|
|
647
|
+
content: [{ type: "text", text: `First parallel step: task ${missingTaskIndex + 1} must have a task (no previous output to reference)` }],
|
|
648
|
+
isError: true,
|
|
649
|
+
details: { mode: "chain" as const, results: [] },
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
} else if (!(firstStep as SequentialStep).task && !params.task && !allowClarifyTaskPrompt) {
|
|
653
|
+
return {
|
|
654
|
+
content: [{ type: "text", text: "First step in chain must have a task" }],
|
|
655
|
+
isError: true,
|
|
656
|
+
details: { mode: "chain" as const, results: [] },
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
for (let i = 0; i < params.chain.length; i++) {
|
|
660
|
+
const step = params.chain[i] as ChainStep;
|
|
661
|
+
const stepAgents = getStepAgents(step);
|
|
662
|
+
for (const agentName of stepAgents) {
|
|
663
|
+
if (!agents.find((a) => a.name === agentName)) {
|
|
664
|
+
return {
|
|
665
|
+
content: [{ type: "text", text: `Unknown agent: ${agentName} (step ${i + 1})` }],
|
|
666
|
+
isError: true,
|
|
667
|
+
details: { mode: "chain" as const, results: [] },
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (isParallelStep(step) && step.parallel.length === 0) {
|
|
672
|
+
return {
|
|
673
|
+
content: [{ type: "text", text: `Parallel step ${i + 1} must have at least one task` }],
|
|
674
|
+
isError: true,
|
|
675
|
+
details: { mode: "chain" as const, results: [] },
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function getRequestedModeLabel(params: SubagentParamsLike): Details["mode"] {
|
|
685
|
+
if ((params.chain?.length ?? 0) > 0) return "chain";
|
|
686
|
+
if ((params.tasks?.length ?? 0) > 0) return "parallel";
|
|
687
|
+
if (params.agent) return "single";
|
|
688
|
+
return "single";
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function applyAgentDefaultContext(params: SubagentParamsLike, agents: AgentConfig[]): SubagentParamsLike {
|
|
692
|
+
if (params.context !== undefined) return params;
|
|
693
|
+
const byName = new Map(agents.map((agent) => [agent.name, agent]));
|
|
694
|
+
const names: string[] = [];
|
|
695
|
+
if (params.agent) names.push(params.agent);
|
|
696
|
+
for (const task of params.tasks ?? []) names.push(task.agent);
|
|
697
|
+
for (const step of params.chain ?? []) names.push(...getStepAgents(step));
|
|
698
|
+
return names.some((name) => byName.get(name)?.defaultContext === "fork")
|
|
699
|
+
? { ...params, context: "fork" }
|
|
700
|
+
: params;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function buildRequestedModeError(params: SubagentParamsLike, message: string): AgentToolResult<Details> {
|
|
704
|
+
return withForkContext(
|
|
705
|
+
{
|
|
706
|
+
content: [{ type: "text", text: message }],
|
|
707
|
+
isError: true,
|
|
708
|
+
details: { mode: getRequestedModeLabel(params), results: [] },
|
|
709
|
+
},
|
|
710
|
+
params.context,
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function expandTopLevelTaskCounts(tasks: TaskParam[]): { tasks?: TaskParam[]; error?: string } {
|
|
715
|
+
const expanded: TaskParam[] = [];
|
|
716
|
+
for (let taskIndex = 0; taskIndex < tasks.length; taskIndex++) {
|
|
717
|
+
const task = tasks[taskIndex]!;
|
|
718
|
+
const rawCount = (task as TaskParam & { count?: unknown }).count;
|
|
719
|
+
if (rawCount !== undefined && (typeof rawCount !== "number" || !Number.isInteger(rawCount) || rawCount < 1)) {
|
|
720
|
+
return { error: `tasks[${taskIndex}].count must be an integer >= 1` };
|
|
721
|
+
}
|
|
722
|
+
const { count, ...concreteTask } = task;
|
|
723
|
+
for (let repeat = 0; repeat < (rawCount ?? 1); repeat++) {
|
|
724
|
+
expanded.push({ ...concreteTask });
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return { tasks: expanded };
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function expandChainParallelCounts(chain: ChainStep[]): { chain?: ChainStep[]; error?: string } {
|
|
731
|
+
const expandedChain: ChainStep[] = [];
|
|
732
|
+
for (let stepIndex = 0; stepIndex < chain.length; stepIndex++) {
|
|
733
|
+
const step = chain[stepIndex]!;
|
|
734
|
+
if (!isParallelStep(step)) {
|
|
735
|
+
expandedChain.push(step);
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
const expandedParallel = [];
|
|
739
|
+
for (let taskIndex = 0; taskIndex < step.parallel.length; taskIndex++) {
|
|
740
|
+
const task = step.parallel[taskIndex]!;
|
|
741
|
+
const rawCount = (task as typeof task & { count?: unknown }).count;
|
|
742
|
+
if (rawCount !== undefined && (typeof rawCount !== "number" || !Number.isInteger(rawCount) || rawCount < 1)) {
|
|
743
|
+
return { error: `chain[${stepIndex}].parallel[${taskIndex}].count must be an integer >= 1` };
|
|
744
|
+
}
|
|
745
|
+
const { count, ...concreteTask } = task;
|
|
746
|
+
for (let repeat = 0; repeat < (rawCount ?? 1); repeat++) {
|
|
747
|
+
expandedParallel.push({ ...concreteTask });
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
expandedChain.push({ ...step, parallel: expandedParallel });
|
|
751
|
+
}
|
|
752
|
+
return { chain: expandedChain };
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function normalizeRepeatedParallelCounts(params: SubagentParamsLike): { params?: SubagentParamsLike; error?: AgentToolResult<Details> } {
|
|
756
|
+
if (params.tasks) {
|
|
757
|
+
const expandedTasks = expandTopLevelTaskCounts(params.tasks);
|
|
758
|
+
if (expandedTasks.error) {
|
|
759
|
+
return { error: buildRequestedModeError(params, expandedTasks.error) };
|
|
760
|
+
}
|
|
761
|
+
return { params: { ...params, tasks: expandedTasks.tasks } };
|
|
762
|
+
}
|
|
763
|
+
if (params.chain) {
|
|
764
|
+
const expandedChain = expandChainParallelCounts(params.chain);
|
|
765
|
+
if (expandedChain.error) {
|
|
766
|
+
return { error: buildRequestedModeError(params, expandedChain.error) };
|
|
767
|
+
}
|
|
768
|
+
return { params: { ...params, chain: expandedChain.chain } };
|
|
769
|
+
}
|
|
770
|
+
return { params };
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function withForkContext(
|
|
774
|
+
result: AgentToolResult<Details>,
|
|
775
|
+
context: SubagentParamsLike["context"],
|
|
776
|
+
): AgentToolResult<Details> {
|
|
777
|
+
if (context !== "fork" || !result.details) return result;
|
|
778
|
+
return {
|
|
779
|
+
...result,
|
|
780
|
+
details: {
|
|
781
|
+
...result.details,
|
|
782
|
+
context: "fork",
|
|
783
|
+
},
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function toExecutionErrorResult(params: SubagentParamsLike, error: unknown): AgentToolResult<Details> {
|
|
788
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
789
|
+
return withForkContext(
|
|
790
|
+
{
|
|
791
|
+
content: [{ type: "text", text: message }],
|
|
792
|
+
isError: true,
|
|
793
|
+
details: { mode: getRequestedModeLabel(params), results: [] },
|
|
794
|
+
},
|
|
795
|
+
params.context,
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function collectChainSessionFiles(
|
|
800
|
+
chain: ChainStep[],
|
|
801
|
+
sessionFileForIndex: (idx?: number) => string | undefined,
|
|
802
|
+
): (string | undefined)[] {
|
|
803
|
+
const sessionFiles: (string | undefined)[] = [];
|
|
804
|
+
let flatIndex = 0;
|
|
805
|
+
for (const step of chain) {
|
|
806
|
+
if (isParallelStep(step)) {
|
|
807
|
+
for (let i = 0; i < step.parallel.length; i++) {
|
|
808
|
+
sessionFiles.push(sessionFileForIndex(flatIndex));
|
|
809
|
+
flatIndex++;
|
|
810
|
+
}
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
813
|
+
sessionFiles.push(sessionFileForIndex(flatIndex));
|
|
814
|
+
flatIndex++;
|
|
815
|
+
}
|
|
816
|
+
return sessionFiles;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function wrapChainTasksForFork(chain: ChainStep[], context: SubagentParamsLike["context"]): ChainStep[] {
|
|
820
|
+
if (context !== "fork") return chain;
|
|
821
|
+
return chain.map((step, stepIndex) => {
|
|
822
|
+
if (isParallelStep(step)) {
|
|
823
|
+
return {
|
|
824
|
+
...step,
|
|
825
|
+
parallel: step.parallel.map((task) => ({
|
|
826
|
+
...task,
|
|
827
|
+
task: wrapForkTask(task.task ?? "{previous}"),
|
|
828
|
+
})),
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
const sequential = step as SequentialStep;
|
|
832
|
+
return {
|
|
833
|
+
...sequential,
|
|
834
|
+
task: wrapForkTask(sequential.task ?? (stepIndex === 0 ? "{task}" : "{previous}")),
|
|
835
|
+
};
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
function runAsyncPath(data: ExecutionContextData, deps: ExecutorDeps): AgentToolResult<Details> | null {
|
|
840
|
+
const {
|
|
841
|
+
params,
|
|
842
|
+
effectiveCwd,
|
|
843
|
+
agents,
|
|
844
|
+
ctx,
|
|
845
|
+
shareEnabled,
|
|
846
|
+
sessionRoot,
|
|
847
|
+
sessionFileForIndex,
|
|
848
|
+
artifactConfig,
|
|
849
|
+
artifactsDir,
|
|
850
|
+
effectiveAsync,
|
|
851
|
+
controlConfig,
|
|
852
|
+
intercomBridge,
|
|
853
|
+
} = data;
|
|
854
|
+
const hasChain = (params.chain?.length ?? 0) > 0;
|
|
855
|
+
const hasTasks = (params.tasks?.length ?? 0) > 0;
|
|
856
|
+
const hasSingle = !hasChain && !hasTasks && Boolean(params.agent);
|
|
857
|
+
if (!effectiveAsync) return null;
|
|
858
|
+
|
|
859
|
+
if (hasChain && params.chain) {
|
|
860
|
+
const chainWorktreeTaskCwdError = buildChainWorktreeTaskCwdError(params.chain as ChainStep[], effectiveCwd);
|
|
861
|
+
if (chainWorktreeTaskCwdError) {
|
|
862
|
+
return {
|
|
863
|
+
content: [{ type: "text", text: chainWorktreeTaskCwdError }],
|
|
864
|
+
isError: true,
|
|
865
|
+
details: { mode: "chain" as const, results: [] },
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
if (hasTasks && params.tasks) {
|
|
871
|
+
const maxParallelTasks = resolveTopLevelParallelMaxTasks(deps.config.parallel?.maxTasks);
|
|
872
|
+
if (params.tasks.length > maxParallelTasks) {
|
|
873
|
+
return buildParallelModeError(`Max ${maxParallelTasks} tasks`);
|
|
874
|
+
}
|
|
875
|
+
if (params.worktree) {
|
|
876
|
+
const worktreeTaskCwdError = buildParallelWorktreeTaskCwdError(params.tasks, effectiveCwd);
|
|
877
|
+
if (worktreeTaskCwdError) return buildParallelModeError(worktreeTaskCwdError);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (!isAsyncAvailable()) {
|
|
882
|
+
return {
|
|
883
|
+
content: [{ type: "text", text: "Async mode requires upstream jiti for TypeScript execution but it could not be found. Ensure the pi-subagents package dependencies are installed." }],
|
|
884
|
+
isError: true,
|
|
885
|
+
details: { mode: "single" as const, results: [] },
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
const id = randomUUID();
|
|
889
|
+
const asyncCtx = {
|
|
890
|
+
pi: deps.pi,
|
|
891
|
+
cwd: ctx.cwd,
|
|
892
|
+
currentSessionId: deps.state.currentSessionId!,
|
|
893
|
+
currentModelProvider: ctx.model?.provider,
|
|
894
|
+
};
|
|
895
|
+
const availableModels: ModelInfo[] = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
896
|
+
const currentMaxSubagentDepth = resolveCurrentMaxSubagentDepth(deps.config.maxSubagentDepth);
|
|
897
|
+
const currentProvider = ctx.model?.provider;
|
|
898
|
+
const controlIntercomTarget = intercomBridge.active ? intercomBridge.orchestratorTarget : undefined;
|
|
899
|
+
const childIntercomTarget = intercomBridge.active ? (agent: string, index: number) => resolveSubagentIntercomTarget(id, agent, index) : undefined;
|
|
900
|
+
|
|
901
|
+
if (hasTasks && params.tasks) {
|
|
902
|
+
const agentConfigs = params.tasks.map((task) => agents.find((agent) => agent.name === task.agent));
|
|
903
|
+
const modelOverrides = params.tasks.map((task, index) =>
|
|
904
|
+
resolveModelCandidate(task.model ?? agentConfigs[index]?.model, availableModels, currentProvider),
|
|
905
|
+
);
|
|
906
|
+
const skillOverrides = params.tasks.map((task) => normalizeSkillInput(task.skill));
|
|
907
|
+
const parallelTasks = params.tasks.map((task, index) => ({
|
|
908
|
+
agent: task.agent,
|
|
909
|
+
task: params.context === "fork" ? wrapForkTask(task.task) : task.task,
|
|
910
|
+
cwd: task.cwd,
|
|
911
|
+
...(modelOverrides[index] ? { model: modelOverrides[index] } : {}),
|
|
912
|
+
...(skillOverrides[index] !== undefined ? { skill: skillOverrides[index] } : {}),
|
|
913
|
+
...(task.output === true ? (agentConfigs[index]?.output ? { output: agentConfigs[index]!.output } : {}) : task.output !== undefined ? { output: task.output } : {}),
|
|
914
|
+
...(task.outputMode !== undefined ? { outputMode: task.outputMode } : {}),
|
|
915
|
+
...(task.reads !== undefined && task.reads !== true ? { reads: task.reads } : {}),
|
|
916
|
+
...(task.progress !== undefined ? { progress: task.progress } : {}),
|
|
917
|
+
}));
|
|
918
|
+
return executeAsyncChain(id, {
|
|
919
|
+
chain: [{
|
|
920
|
+
parallel: parallelTasks,
|
|
921
|
+
concurrency: resolveTopLevelParallelConcurrency(params.concurrency, deps.config.parallel?.concurrency),
|
|
922
|
+
worktree: params.worktree,
|
|
923
|
+
}],
|
|
924
|
+
resultMode: "parallel",
|
|
925
|
+
agents,
|
|
926
|
+
ctx: asyncCtx,
|
|
927
|
+
availableModels,
|
|
928
|
+
cwd: effectiveCwd,
|
|
929
|
+
maxOutput: params.maxOutput,
|
|
930
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
931
|
+
artifactConfig,
|
|
932
|
+
shareEnabled,
|
|
933
|
+
sessionRoot,
|
|
934
|
+
chainSkills: [],
|
|
935
|
+
sessionFilesByFlatIndex: params.tasks.map((_, index) => sessionFileForIndex(index)),
|
|
936
|
+
maxSubagentDepth: currentMaxSubagentDepth,
|
|
937
|
+
worktreeSetupHook: deps.config.worktreeSetupHook,
|
|
938
|
+
worktreeSetupHookTimeoutMs: deps.config.worktreeSetupHookTimeoutMs,
|
|
939
|
+
controlConfig,
|
|
940
|
+
controlIntercomTarget,
|
|
941
|
+
childIntercomTarget,
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
if (hasChain && params.chain) {
|
|
946
|
+
const normalized = normalizeSkillInput(params.skill);
|
|
947
|
+
const chainSkills = normalized === false ? [] : (normalized ?? []);
|
|
948
|
+
const chain = wrapChainTasksForFork(params.chain as ChainStep[], params.context);
|
|
949
|
+
return executeAsyncChain(id, {
|
|
950
|
+
chain,
|
|
951
|
+
task: params.task,
|
|
952
|
+
agents,
|
|
953
|
+
ctx: asyncCtx,
|
|
954
|
+
availableModels,
|
|
955
|
+
cwd: effectiveCwd,
|
|
956
|
+
maxOutput: params.maxOutput,
|
|
957
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
958
|
+
artifactConfig,
|
|
959
|
+
shareEnabled,
|
|
960
|
+
sessionRoot,
|
|
961
|
+
chainSkills,
|
|
962
|
+
sessionFilesByFlatIndex: collectChainSessionFiles(chain, sessionFileForIndex),
|
|
963
|
+
maxSubagentDepth: currentMaxSubagentDepth,
|
|
964
|
+
worktreeSetupHook: deps.config.worktreeSetupHook,
|
|
965
|
+
worktreeSetupHookTimeoutMs: deps.config.worktreeSetupHookTimeoutMs,
|
|
966
|
+
controlConfig,
|
|
967
|
+
controlIntercomTarget,
|
|
968
|
+
childIntercomTarget,
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
if (hasSingle) {
|
|
973
|
+
const a = agents.find((x) => x.name === params.agent);
|
|
974
|
+
if (!a) {
|
|
975
|
+
return {
|
|
976
|
+
content: [{ type: "text", text: `Unknown agent: ${params.agent}` }],
|
|
977
|
+
isError: true,
|
|
978
|
+
details: { mode: "single" as const, results: [] },
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
const rawOutput = params.output !== undefined ? params.output : a.output;
|
|
982
|
+
const effectiveOutput: string | false | undefined = rawOutput === true ? a.output : (rawOutput as string | false | undefined);
|
|
983
|
+
const effectiveOutputMode = params.outputMode ?? "inline";
|
|
984
|
+
const normalizedSkills = normalizeSkillInput(params.skill);
|
|
985
|
+
const skills = normalizedSkills === false ? [] : normalizedSkills;
|
|
986
|
+
const maxSubagentDepth = resolveChildMaxSubagentDepth(currentMaxSubagentDepth, a.maxSubagentDepth);
|
|
987
|
+
const modelOverride = resolveModelCandidate((params.model as string | undefined) ?? a.model, availableModels, currentProvider);
|
|
988
|
+
return executeAsyncSingle(id, {
|
|
989
|
+
agent: params.agent!,
|
|
990
|
+
task: params.context === "fork" ? wrapForkTask(params.task ?? "") : (params.task ?? ""),
|
|
991
|
+
agentConfig: a,
|
|
992
|
+
ctx: asyncCtx,
|
|
993
|
+
availableModels,
|
|
994
|
+
cwd: effectiveCwd,
|
|
995
|
+
maxOutput: params.maxOutput,
|
|
996
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
997
|
+
artifactConfig,
|
|
998
|
+
shareEnabled,
|
|
999
|
+
sessionRoot,
|
|
1000
|
+
sessionFile: sessionFileForIndex(0),
|
|
1001
|
+
skills,
|
|
1002
|
+
output: effectiveOutput,
|
|
1003
|
+
outputMode: effectiveOutputMode,
|
|
1004
|
+
modelOverride,
|
|
1005
|
+
maxSubagentDepth,
|
|
1006
|
+
worktreeSetupHook: deps.config.worktreeSetupHook,
|
|
1007
|
+
worktreeSetupHookTimeoutMs: deps.config.worktreeSetupHookTimeoutMs,
|
|
1008
|
+
controlConfig,
|
|
1009
|
+
controlIntercomTarget,
|
|
1010
|
+
childIntercomTarget: childIntercomTarget ? (agent, index) => childIntercomTarget(agent, index) : undefined,
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
return null;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
async function runChainPath(data: ExecutionContextData, deps: ExecutorDeps): Promise<AgentToolResult<Details>> {
|
|
1018
|
+
const {
|
|
1019
|
+
params,
|
|
1020
|
+
effectiveCwd,
|
|
1021
|
+
agents,
|
|
1022
|
+
ctx,
|
|
1023
|
+
signal,
|
|
1024
|
+
runId,
|
|
1025
|
+
shareEnabled,
|
|
1026
|
+
sessionDirForIndex,
|
|
1027
|
+
sessionFileForIndex,
|
|
1028
|
+
artifactsDir,
|
|
1029
|
+
artifactConfig,
|
|
1030
|
+
onUpdate,
|
|
1031
|
+
sessionRoot,
|
|
1032
|
+
controlConfig,
|
|
1033
|
+
} = data;
|
|
1034
|
+
const onControlEvent = createForegroundControlNotifier(data, deps);
|
|
1035
|
+
const childIntercomTarget = data.intercomBridge.active ? resolveSubagentIntercomTarget : undefined;
|
|
1036
|
+
const foregroundControl = deps.state.foregroundControls.get(runId);
|
|
1037
|
+
const normalized = normalizeSkillInput(params.skill);
|
|
1038
|
+
const chainSkills = normalized === false ? [] : (normalized ?? []);
|
|
1039
|
+
const chain = wrapChainTasksForFork(params.chain as ChainStep[], params.context);
|
|
1040
|
+
const currentMaxSubagentDepth = resolveCurrentMaxSubagentDepth(deps.config.maxSubagentDepth);
|
|
1041
|
+
const chainResult = await executeChain({
|
|
1042
|
+
chain,
|
|
1043
|
+
task: params.task,
|
|
1044
|
+
agents,
|
|
1045
|
+
ctx,
|
|
1046
|
+
intercomEvents: deps.pi.events,
|
|
1047
|
+
signal,
|
|
1048
|
+
runId,
|
|
1049
|
+
cwd: effectiveCwd,
|
|
1050
|
+
shareEnabled,
|
|
1051
|
+
sessionDirForIndex,
|
|
1052
|
+
sessionFileForIndex,
|
|
1053
|
+
artifactsDir,
|
|
1054
|
+
artifactConfig,
|
|
1055
|
+
includeProgress: params.includeProgress,
|
|
1056
|
+
clarify: params.clarify,
|
|
1057
|
+
onUpdate,
|
|
1058
|
+
onControlEvent,
|
|
1059
|
+
controlConfig,
|
|
1060
|
+
childIntercomTarget: childIntercomTarget ? (agent, index) => childIntercomTarget(runId, agent, index) : undefined,
|
|
1061
|
+
orchestratorIntercomTarget: data.intercomBridge.active ? data.intercomBridge.orchestratorTarget : undefined,
|
|
1062
|
+
foregroundControl,
|
|
1063
|
+
chainSkills,
|
|
1064
|
+
chainDir: params.chainDir,
|
|
1065
|
+
maxSubagentDepth: currentMaxSubagentDepth,
|
|
1066
|
+
worktreeSetupHook: deps.config.worktreeSetupHook,
|
|
1067
|
+
worktreeSetupHookTimeoutMs: deps.config.worktreeSetupHookTimeoutMs,
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
if (chainResult.requestedAsync) {
|
|
1071
|
+
if (!isAsyncAvailable()) {
|
|
1072
|
+
return {
|
|
1073
|
+
content: [{ type: "text", text: "Background mode requires upstream jiti for TypeScript execution but it could not be found. Ensure the pi-subagents package dependencies are installed." }],
|
|
1074
|
+
isError: true,
|
|
1075
|
+
details: { mode: "chain" as const, results: [] },
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
const id = randomUUID();
|
|
1079
|
+
const asyncCtx = {
|
|
1080
|
+
pi: deps.pi,
|
|
1081
|
+
cwd: ctx.cwd,
|
|
1082
|
+
currentSessionId: deps.state.currentSessionId!,
|
|
1083
|
+
currentModelProvider: ctx.model?.provider,
|
|
1084
|
+
};
|
|
1085
|
+
const asyncChain = wrapChainTasksForFork(chainResult.requestedAsync.chain, params.context);
|
|
1086
|
+
return executeAsyncChain(id, {
|
|
1087
|
+
chain: asyncChain,
|
|
1088
|
+
task: params.task,
|
|
1089
|
+
agents,
|
|
1090
|
+
ctx: asyncCtx,
|
|
1091
|
+
availableModels: ctx.modelRegistry.getAvailable().map(toModelInfo),
|
|
1092
|
+
cwd: effectiveCwd,
|
|
1093
|
+
maxOutput: params.maxOutput,
|
|
1094
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
1095
|
+
artifactConfig,
|
|
1096
|
+
shareEnabled,
|
|
1097
|
+
sessionRoot,
|
|
1098
|
+
chainSkills: chainResult.requestedAsync.chainSkills,
|
|
1099
|
+
sessionFilesByFlatIndex: collectChainSessionFiles(asyncChain, sessionFileForIndex),
|
|
1100
|
+
maxSubagentDepth: currentMaxSubagentDepth,
|
|
1101
|
+
worktreeSetupHook: deps.config.worktreeSetupHook,
|
|
1102
|
+
worktreeSetupHookTimeoutMs: deps.config.worktreeSetupHookTimeoutMs,
|
|
1103
|
+
controlConfig,
|
|
1104
|
+
controlIntercomTarget: data.intercomBridge.active ? data.intercomBridge.orchestratorTarget : undefined,
|
|
1105
|
+
childIntercomTarget: data.intercomBridge.active ? (agent, index) => resolveSubagentIntercomTarget(id, agent, index) : undefined,
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
const chainDetails = chainResult.details ? compactForegroundDetails({ ...chainResult.details, runId }) : undefined;
|
|
1110
|
+
if (chainDetails) rememberForegroundRun(deps.state, { runId, mode: "chain", cwd: effectiveCwd, results: chainDetails.results });
|
|
1111
|
+
const intercomReceipt = chainDetails && !chainDetails.results.some((result) => result.interrupted || result.detached)
|
|
1112
|
+
? await maybeBuildForegroundIntercomReceipt({
|
|
1113
|
+
pi: deps.pi,
|
|
1114
|
+
intercomBridge: data.intercomBridge,
|
|
1115
|
+
runId,
|
|
1116
|
+
mode: "chain",
|
|
1117
|
+
details: chainDetails,
|
|
1118
|
+
})
|
|
1119
|
+
: null;
|
|
1120
|
+
if (intercomReceipt) {
|
|
1121
|
+
return {
|
|
1122
|
+
...chainResult,
|
|
1123
|
+
content: [{ type: "text", text: intercomReceipt.text }],
|
|
1124
|
+
details: intercomReceipt.details,
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
return chainDetails ? { ...chainResult, details: chainDetails } : chainResult;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
interface ForegroundParallelRunInput {
|
|
1132
|
+
tasks: TaskParam[];
|
|
1133
|
+
taskTexts: string[];
|
|
1134
|
+
agents: AgentConfig[];
|
|
1135
|
+
ctx: ExtensionContext;
|
|
1136
|
+
intercomEvents: IntercomEventBus;
|
|
1137
|
+
signal: AbortSignal;
|
|
1138
|
+
runId: string;
|
|
1139
|
+
sessionDirForIndex: (idx?: number) => string | undefined;
|
|
1140
|
+
sessionFileForIndex: (idx?: number) => string | undefined;
|
|
1141
|
+
shareEnabled: boolean;
|
|
1142
|
+
artifactConfig: ArtifactConfig;
|
|
1143
|
+
artifactsDir: string;
|
|
1144
|
+
maxOutput?: MaxOutputConfig;
|
|
1145
|
+
paramsCwd: string;
|
|
1146
|
+
maxSubagentDepths: number[];
|
|
1147
|
+
availableModels: ModelInfo[];
|
|
1148
|
+
modelOverrides: (string | undefined)[];
|
|
1149
|
+
behaviors: Array<ReturnType<typeof resolveStepBehavior>>;
|
|
1150
|
+
firstProgressIndex: number;
|
|
1151
|
+
controlConfig: ResolvedControlConfig;
|
|
1152
|
+
onControlEvent?: (event: ControlEvent) => void;
|
|
1153
|
+
childIntercomTarget?: (agent: string, index: number) => string | undefined;
|
|
1154
|
+
orchestratorIntercomTarget?: string;
|
|
1155
|
+
foregroundControl?: SubagentState["foregroundControls"] extends Map<string, infer T> ? T : never;
|
|
1156
|
+
concurrencyLimit: number;
|
|
1157
|
+
liveResults: (SingleResult | undefined)[];
|
|
1158
|
+
liveProgress: (AgentProgress | undefined)[];
|
|
1159
|
+
onUpdate?: (r: AgentToolResult<Details>) => void;
|
|
1160
|
+
worktreeSetup?: WorktreeSetup;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
function buildParallelModeError(message: string): AgentToolResult<Details> {
|
|
1164
|
+
return {
|
|
1165
|
+
content: [{ type: "text", text: message }],
|
|
1166
|
+
isError: true,
|
|
1167
|
+
details: { mode: "parallel" as const, results: [] },
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
function createParallelWorktreeSetup(
|
|
1172
|
+
enabled: boolean | undefined,
|
|
1173
|
+
cwd: string,
|
|
1174
|
+
runId: string,
|
|
1175
|
+
tasks: TaskParam[],
|
|
1176
|
+
setupHook: ExtensionConfig["worktreeSetupHook"],
|
|
1177
|
+
setupHookTimeoutMs: ExtensionConfig["worktreeSetupHookTimeoutMs"],
|
|
1178
|
+
): { setup?: WorktreeSetup; errorResult?: AgentToolResult<Details> } {
|
|
1179
|
+
if (!enabled) return {};
|
|
1180
|
+
try {
|
|
1181
|
+
return {
|
|
1182
|
+
setup: createWorktrees(cwd, runId, tasks.length, {
|
|
1183
|
+
agents: tasks.map((task) => task.agent),
|
|
1184
|
+
setupHook: setupHook
|
|
1185
|
+
? { hookPath: setupHook, timeoutMs: setupHookTimeoutMs }
|
|
1186
|
+
: undefined,
|
|
1187
|
+
}),
|
|
1188
|
+
};
|
|
1189
|
+
} catch (error) {
|
|
1190
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1191
|
+
return { errorResult: buildParallelModeError(message) };
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
function buildParallelWorktreeTaskCwdError(
|
|
1196
|
+
tasks: ReadonlyArray<{ agent: string; cwd?: string }>,
|
|
1197
|
+
sharedCwd: string,
|
|
1198
|
+
): string | undefined {
|
|
1199
|
+
const conflict = findWorktreeTaskCwdConflict(tasks, sharedCwd);
|
|
1200
|
+
if (!conflict) return undefined;
|
|
1201
|
+
return formatWorktreeTaskCwdConflict(conflict, sharedCwd);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
function buildChainWorktreeTaskCwdError(chain: ChainStep[], sharedCwd: string): string | undefined {
|
|
1205
|
+
for (let stepIndex = 0; stepIndex < chain.length; stepIndex++) {
|
|
1206
|
+
const step = chain[stepIndex]!;
|
|
1207
|
+
if (!isParallelStep(step) || !step.worktree) continue;
|
|
1208
|
+
const stepCwd = resolveChildCwd(sharedCwd, step.cwd);
|
|
1209
|
+
const conflict = findWorktreeTaskCwdConflict(step.parallel, stepCwd);
|
|
1210
|
+
if (!conflict) continue;
|
|
1211
|
+
const detail = formatWorktreeTaskCwdConflict(conflict, stepCwd);
|
|
1212
|
+
return `parallel chain step ${stepIndex + 1}: ${detail}`;
|
|
1213
|
+
}
|
|
1214
|
+
return undefined;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
function resolveParallelTaskCwd(
|
|
1218
|
+
task: TaskParam,
|
|
1219
|
+
paramsCwd: string,
|
|
1220
|
+
worktreeSetup: WorktreeSetup | undefined,
|
|
1221
|
+
index: number,
|
|
1222
|
+
): string {
|
|
1223
|
+
if (worktreeSetup) return worktreeSetup.worktrees[index]!.agentCwd;
|
|
1224
|
+
return resolveChildCwd(paramsCwd, task.cwd);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
function buildParallelWorktreeSuffix(
|
|
1228
|
+
worktreeSetup: WorktreeSetup | undefined,
|
|
1229
|
+
artifactsDir: string,
|
|
1230
|
+
tasks: TaskParam[],
|
|
1231
|
+
): string {
|
|
1232
|
+
if (!worktreeSetup) return "";
|
|
1233
|
+
const diffsDir = path.join(artifactsDir, "worktree-diffs");
|
|
1234
|
+
const diffs = diffWorktrees(worktreeSetup, tasks.map((task) => task.agent), diffsDir);
|
|
1235
|
+
return formatWorktreeDiffSummary(diffs);
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
function findDuplicateParallelOutputPath(input: {
|
|
1239
|
+
tasks: TaskParam[];
|
|
1240
|
+
behaviors: ResolvedStepBehavior[];
|
|
1241
|
+
paramsCwd: string;
|
|
1242
|
+
ctxCwd: string;
|
|
1243
|
+
worktreeSetup?: WorktreeSetup;
|
|
1244
|
+
}): string | undefined {
|
|
1245
|
+
const seen = new Map<string, { index: number; agent: string }>();
|
|
1246
|
+
for (let index = 0; index < input.tasks.length; index++) {
|
|
1247
|
+
const behavior = input.behaviors[index];
|
|
1248
|
+
if (!behavior?.output) continue;
|
|
1249
|
+
const task = input.tasks[index]!;
|
|
1250
|
+
const taskCwd = resolveParallelTaskCwd(task, input.paramsCwd, input.worktreeSetup, index);
|
|
1251
|
+
const outputPath = resolveSingleOutputPath(behavior.output, input.ctxCwd, taskCwd);
|
|
1252
|
+
if (!outputPath) continue;
|
|
1253
|
+
const previous = seen.get(outputPath);
|
|
1254
|
+
if (previous) {
|
|
1255
|
+
return `Parallel tasks ${previous.index + 1} (${previous.agent}) and ${index + 1} (${task.agent}) resolve output to the same path: ${outputPath}. Use distinct output paths.`;
|
|
1256
|
+
}
|
|
1257
|
+
seen.set(outputPath, { index, agent: task.agent });
|
|
1258
|
+
}
|
|
1259
|
+
return undefined;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
async function runForegroundParallelTasks(input: ForegroundParallelRunInput): Promise<SingleResult[]> {
|
|
1263
|
+
return mapConcurrent(input.tasks, input.concurrencyLimit, async (task, index) => {
|
|
1264
|
+
const behavior = input.behaviors[index];
|
|
1265
|
+
const effectiveSkills = behavior?.skills;
|
|
1266
|
+
const taskCwd = resolveParallelTaskCwd(task, input.paramsCwd, input.worktreeSetup, index);
|
|
1267
|
+
const readInstructions = behavior
|
|
1268
|
+
? buildChainInstructions({ ...behavior, output: false, progress: false }, taskCwd, false)
|
|
1269
|
+
: { prefix: "", suffix: "" };
|
|
1270
|
+
const progressInstructions = behavior
|
|
1271
|
+
? buildChainInstructions({ ...behavior, output: false, reads: false }, input.paramsCwd, index === input.firstProgressIndex)
|
|
1272
|
+
: { prefix: "", suffix: "" };
|
|
1273
|
+
const outputPath = resolveSingleOutputPath(behavior?.output, input.ctx.cwd, taskCwd);
|
|
1274
|
+
const taskText = injectSingleOutputInstruction(
|
|
1275
|
+
`${readInstructions.prefix}${input.taskTexts[index]!}${progressInstructions.suffix}`,
|
|
1276
|
+
outputPath,
|
|
1277
|
+
);
|
|
1278
|
+
const interruptController = new AbortController();
|
|
1279
|
+
if (input.foregroundControl) {
|
|
1280
|
+
input.foregroundControl.currentAgent = task.agent;
|
|
1281
|
+
input.foregroundControl.currentIndex = index;
|
|
1282
|
+
input.foregroundControl.currentActivityState = undefined;
|
|
1283
|
+
input.foregroundControl.updatedAt = Date.now();
|
|
1284
|
+
input.foregroundControl.interrupt = () => {
|
|
1285
|
+
if (interruptController.signal.aborted) return false;
|
|
1286
|
+
interruptController.abort();
|
|
1287
|
+
input.foregroundControl!.currentActivityState = undefined;
|
|
1288
|
+
input.foregroundControl!.updatedAt = Date.now();
|
|
1289
|
+
return true;
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
const agentConfig = input.agents.find((agent) => agent.name === task.agent);
|
|
1293
|
+
return runSync(input.ctx.cwd, input.agents, task.agent, taskText, {
|
|
1294
|
+
cwd: taskCwd,
|
|
1295
|
+
signal: input.signal,
|
|
1296
|
+
interruptSignal: interruptController.signal,
|
|
1297
|
+
allowIntercomDetach: agentConfig?.systemPrompt?.includes(INTERCOM_BRIDGE_MARKER) === true,
|
|
1298
|
+
intercomEvents: input.intercomEvents,
|
|
1299
|
+
runId: input.runId,
|
|
1300
|
+
index,
|
|
1301
|
+
sessionDir: input.sessionDirForIndex(index),
|
|
1302
|
+
sessionFile: input.sessionFileForIndex(index),
|
|
1303
|
+
share: input.shareEnabled,
|
|
1304
|
+
artifactsDir: input.artifactConfig.enabled ? input.artifactsDir : undefined,
|
|
1305
|
+
artifactConfig: input.artifactConfig,
|
|
1306
|
+
maxOutput: input.maxOutput,
|
|
1307
|
+
outputPath,
|
|
1308
|
+
outputMode: behavior?.outputMode,
|
|
1309
|
+
maxSubagentDepth: input.maxSubagentDepths[index],
|
|
1310
|
+
controlConfig: input.controlConfig,
|
|
1311
|
+
onControlEvent: input.onControlEvent,
|
|
1312
|
+
intercomSessionName: input.childIntercomTarget?.(task.agent, index),
|
|
1313
|
+
orchestratorIntercomTarget: input.orchestratorIntercomTarget,
|
|
1314
|
+
modelOverride: input.modelOverrides[index],
|
|
1315
|
+
availableModels: input.availableModels,
|
|
1316
|
+
preferredModelProvider: input.ctx.model?.provider,
|
|
1317
|
+
skills: effectiveSkills === false ? [] : effectiveSkills,
|
|
1318
|
+
onUpdate: input.onUpdate
|
|
1319
|
+
? (progressUpdate) => {
|
|
1320
|
+
const stepResults = progressUpdate.details?.results || [];
|
|
1321
|
+
const stepProgress = progressUpdate.details?.progress || [];
|
|
1322
|
+
if (input.foregroundControl && stepProgress.length > 0) {
|
|
1323
|
+
const current = stepProgress[0];
|
|
1324
|
+
input.foregroundControl.currentAgent = task.agent;
|
|
1325
|
+
input.foregroundControl.currentIndex = index;
|
|
1326
|
+
input.foregroundControl.currentActivityState = current?.activityState;
|
|
1327
|
+
input.foregroundControl.lastActivityAt = current?.lastActivityAt;
|
|
1328
|
+
input.foregroundControl.currentTool = current?.currentTool;
|
|
1329
|
+
input.foregroundControl.currentToolStartedAt = current?.currentToolStartedAt;
|
|
1330
|
+
input.foregroundControl.currentPath = current?.currentPath;
|
|
1331
|
+
input.foregroundControl.turnCount = current?.turnCount;
|
|
1332
|
+
input.foregroundControl.tokens = current?.tokens;
|
|
1333
|
+
input.foregroundControl.toolCount = current?.toolCount;
|
|
1334
|
+
input.foregroundControl.updatedAt = Date.now();
|
|
1335
|
+
}
|
|
1336
|
+
if (stepResults.length > 0) input.liveResults[index] = stepResults[0];
|
|
1337
|
+
if (stepProgress.length > 0) input.liveProgress[index] = stepProgress[0];
|
|
1338
|
+
const mergedResults = input.liveResults.filter((result): result is SingleResult => result !== undefined);
|
|
1339
|
+
const mergedProgress = input.liveProgress.filter((progress): progress is AgentProgress => progress !== undefined);
|
|
1340
|
+
input.onUpdate?.({
|
|
1341
|
+
content: progressUpdate.content,
|
|
1342
|
+
details: {
|
|
1343
|
+
mode: "parallel",
|
|
1344
|
+
results: mergedResults,
|
|
1345
|
+
progress: mergedProgress,
|
|
1346
|
+
controlEvents: progressUpdate.details?.controlEvents,
|
|
1347
|
+
totalSteps: input.tasks.length,
|
|
1348
|
+
},
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
: undefined,
|
|
1352
|
+
}).finally(() => {
|
|
1353
|
+
if (input.foregroundControl?.currentIndex === index) {
|
|
1354
|
+
input.foregroundControl.interrupt = undefined;
|
|
1355
|
+
input.foregroundControl.updatedAt = Date.now();
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
async function runParallelPath(data: ExecutionContextData, deps: ExecutorDeps): Promise<AgentToolResult<Details>> {
|
|
1362
|
+
const {
|
|
1363
|
+
params,
|
|
1364
|
+
effectiveCwd,
|
|
1365
|
+
agents,
|
|
1366
|
+
ctx,
|
|
1367
|
+
signal,
|
|
1368
|
+
runId,
|
|
1369
|
+
sessionDirForIndex,
|
|
1370
|
+
sessionFileForIndex,
|
|
1371
|
+
shareEnabled,
|
|
1372
|
+
artifactConfig,
|
|
1373
|
+
artifactsDir,
|
|
1374
|
+
backgroundRequestedWhileClarifying,
|
|
1375
|
+
onUpdate,
|
|
1376
|
+
sessionRoot,
|
|
1377
|
+
controlConfig,
|
|
1378
|
+
} = data;
|
|
1379
|
+
const onControlEvent = createForegroundControlNotifier(data, deps);
|
|
1380
|
+
const childIntercomTarget = data.intercomBridge.active ? resolveSubagentIntercomTarget : undefined;
|
|
1381
|
+
const allProgress: AgentProgress[] = [];
|
|
1382
|
+
const allArtifactPaths: ArtifactPaths[] = [];
|
|
1383
|
+
const tasks = params.tasks!;
|
|
1384
|
+
const maxParallelTasks = resolveTopLevelParallelMaxTasks(deps.config.parallel?.maxTasks);
|
|
1385
|
+
const parallelConcurrency = resolveTopLevelParallelConcurrency(params.concurrency, deps.config.parallel?.concurrency);
|
|
1386
|
+
|
|
1387
|
+
if (tasks.length > maxParallelTasks)
|
|
1388
|
+
return {
|
|
1389
|
+
content: [{ type: "text", text: `Max ${maxParallelTasks} tasks` }],
|
|
1390
|
+
isError: true,
|
|
1391
|
+
details: { mode: "parallel" as const, results: [] },
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
const agentConfigs: AgentConfig[] = [];
|
|
1395
|
+
for (const t of tasks) {
|
|
1396
|
+
const config = agents.find((a) => a.name === t.agent);
|
|
1397
|
+
if (!config) {
|
|
1398
|
+
return {
|
|
1399
|
+
content: [{ type: "text", text: `Unknown agent: ${t.agent}` }],
|
|
1400
|
+
isError: true,
|
|
1401
|
+
details: { mode: "parallel" as const, results: [] },
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
agentConfigs.push(config);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
const currentMaxSubagentDepth = resolveCurrentMaxSubagentDepth(deps.config.maxSubagentDepth);
|
|
1408
|
+
const maxSubagentDepths = agentConfigs.map((config) =>
|
|
1409
|
+
resolveChildMaxSubagentDepth(currentMaxSubagentDepth, config.maxSubagentDepth),
|
|
1410
|
+
);
|
|
1411
|
+
|
|
1412
|
+
if (params.worktree) {
|
|
1413
|
+
const worktreeTaskCwdError = buildParallelWorktreeTaskCwdError(tasks, effectiveCwd);
|
|
1414
|
+
if (worktreeTaskCwdError) return buildParallelModeError(worktreeTaskCwdError);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
const currentProvider = ctx.model?.provider;
|
|
1418
|
+
const availableModels: ModelInfo[] = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
1419
|
+
let taskTexts = tasks.map((t) => t.task);
|
|
1420
|
+
const skillOverrides: (string[] | false | undefined)[] = tasks.map((t) =>
|
|
1421
|
+
normalizeSkillInput(t.skill),
|
|
1422
|
+
);
|
|
1423
|
+
const behaviorOverrides: StepOverrides[] = tasks.map((task, index) => ({
|
|
1424
|
+
...(task.output !== undefined ? { output: task.output === true ? agentConfigs[index]?.output ?? false : task.output } : {}),
|
|
1425
|
+
...(task.outputMode !== undefined ? { outputMode: task.outputMode } : {}),
|
|
1426
|
+
...(task.reads !== undefined && task.reads !== true ? { reads: task.reads } : {}),
|
|
1427
|
+
...(task.progress !== undefined ? { progress: task.progress } : {}),
|
|
1428
|
+
...(skillOverrides[index] !== undefined ? { skills: skillOverrides[index] } : {}),
|
|
1429
|
+
...(task.model ? { model: task.model } : {}),
|
|
1430
|
+
}));
|
|
1431
|
+
const modelOverrides: (string | undefined)[] = tasks.map((_, i) =>
|
|
1432
|
+
resolveModelCandidate(behaviorOverrides[i]?.model ?? agentConfigs[i]?.model, availableModels, currentProvider),
|
|
1433
|
+
);
|
|
1434
|
+
|
|
1435
|
+
if (params.clarify === true && ctx.hasUI) {
|
|
1436
|
+
const behaviors = agentConfigs.map((c, i) =>
|
|
1437
|
+
resolveStepBehavior(c, behaviorOverrides[i]!),
|
|
1438
|
+
);
|
|
1439
|
+
const availableSkills = discoverAvailableSkills(effectiveCwd);
|
|
1440
|
+
|
|
1441
|
+
const result = await ctx.ui.custom<ChainClarifyResult>(
|
|
1442
|
+
(tui, theme, _kb, done) =>
|
|
1443
|
+
new ChainClarifyComponent(
|
|
1444
|
+
tui, theme,
|
|
1445
|
+
agentConfigs,
|
|
1446
|
+
taskTexts,
|
|
1447
|
+
"",
|
|
1448
|
+
undefined,
|
|
1449
|
+
behaviors,
|
|
1450
|
+
availableModels,
|
|
1451
|
+
currentProvider,
|
|
1452
|
+
availableSkills,
|
|
1453
|
+
done,
|
|
1454
|
+
"parallel",
|
|
1455
|
+
),
|
|
1456
|
+
{ overlay: true, overlayOptions: { anchor: "center", width: 84, maxHeight: "80%" } },
|
|
1457
|
+
);
|
|
1458
|
+
|
|
1459
|
+
if (!result || !result.confirmed) {
|
|
1460
|
+
return { content: [{ type: "text", text: "Cancelled" }], details: { mode: "parallel", results: [] } };
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
taskTexts = result.templates;
|
|
1464
|
+
for (let i = 0; i < result.behaviorOverrides.length; i++) {
|
|
1465
|
+
const override = result.behaviorOverrides[i];
|
|
1466
|
+
if (override?.model) {
|
|
1467
|
+
modelOverrides[i] = override.model;
|
|
1468
|
+
behaviorOverrides[i]!.model = override.model;
|
|
1469
|
+
}
|
|
1470
|
+
if (override?.output !== undefined) behaviorOverrides[i]!.output = override.output;
|
|
1471
|
+
if (override?.reads !== undefined) behaviorOverrides[i]!.reads = override.reads;
|
|
1472
|
+
if (override?.progress !== undefined) behaviorOverrides[i]!.progress = override.progress;
|
|
1473
|
+
if (override?.skills !== undefined) {
|
|
1474
|
+
skillOverrides[i] = override.skills;
|
|
1475
|
+
behaviorOverrides[i]!.skills = override.skills;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
if (result.runInBackground) {
|
|
1480
|
+
if (!isAsyncAvailable()) {
|
|
1481
|
+
return {
|
|
1482
|
+
content: [{ type: "text", text: "Background mode requires upstream jiti for TypeScript execution but it could not be found. Ensure the pi-subagents package dependencies are installed." }],
|
|
1483
|
+
isError: true,
|
|
1484
|
+
details: { mode: "parallel" as const, results: [] },
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
const id = randomUUID();
|
|
1488
|
+
const asyncCtx = {
|
|
1489
|
+
pi: deps.pi,
|
|
1490
|
+
cwd: ctx.cwd,
|
|
1491
|
+
currentSessionId: deps.state.currentSessionId!,
|
|
1492
|
+
currentModelProvider: ctx.model?.provider,
|
|
1493
|
+
};
|
|
1494
|
+
const parallelTasks = tasks.map((t, i) => {
|
|
1495
|
+
const taskText = params.context === "fork" ? wrapForkTask(taskTexts[i]!) : taskTexts[i]!;
|
|
1496
|
+
const progress = taskDisallowsFileUpdates(taskText) ? false : behaviorOverrides[i]?.progress;
|
|
1497
|
+
return {
|
|
1498
|
+
agent: t.agent,
|
|
1499
|
+
task: taskText,
|
|
1500
|
+
cwd: t.cwd,
|
|
1501
|
+
...(modelOverrides[i] ? { model: modelOverrides[i] } : {}),
|
|
1502
|
+
...(skillOverrides[i] !== undefined ? { skill: skillOverrides[i] } : {}),
|
|
1503
|
+
...(behaviorOverrides[i]?.output !== undefined ? { output: behaviorOverrides[i]!.output } : {}),
|
|
1504
|
+
...(behaviorOverrides[i]?.outputMode !== undefined ? { outputMode: behaviorOverrides[i]!.outputMode } : {}),
|
|
1505
|
+
...(behaviorOverrides[i]?.reads !== undefined ? { reads: behaviorOverrides[i]!.reads } : {}),
|
|
1506
|
+
...(progress !== undefined ? { progress } : {}),
|
|
1507
|
+
};
|
|
1508
|
+
});
|
|
1509
|
+
return executeAsyncChain(id, {
|
|
1510
|
+
chain: [{ parallel: parallelTasks, concurrency: parallelConcurrency, worktree: params.worktree }],
|
|
1511
|
+
resultMode: "parallel",
|
|
1512
|
+
agents,
|
|
1513
|
+
ctx: asyncCtx,
|
|
1514
|
+
availableModels,
|
|
1515
|
+
cwd: effectiveCwd,
|
|
1516
|
+
maxOutput: params.maxOutput,
|
|
1517
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
1518
|
+
artifactConfig,
|
|
1519
|
+
shareEnabled,
|
|
1520
|
+
sessionRoot,
|
|
1521
|
+
chainSkills: [],
|
|
1522
|
+
sessionFilesByFlatIndex: tasks.map((_, index) => sessionFileForIndex(index)),
|
|
1523
|
+
maxSubagentDepth: currentMaxSubagentDepth,
|
|
1524
|
+
worktreeSetupHook: deps.config.worktreeSetupHook,
|
|
1525
|
+
worktreeSetupHookTimeoutMs: deps.config.worktreeSetupHookTimeoutMs,
|
|
1526
|
+
controlConfig,
|
|
1527
|
+
controlIntercomTarget: data.intercomBridge.active ? data.intercomBridge.orchestratorTarget : undefined,
|
|
1528
|
+
childIntercomTarget: data.intercomBridge.active ? (agent, index) => resolveSubagentIntercomTarget(id, agent, index) : undefined,
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
const behaviors = agentConfigs.map((config, index) => suppressProgressForReadOnlyTask(resolveStepBehavior(config, behaviorOverrides[index]!), taskTexts[index]));
|
|
1534
|
+
const firstProgressIndex = behaviors.findIndex((behavior) => behavior.progress);
|
|
1535
|
+
const liveResults: (SingleResult | undefined)[] = new Array(tasks.length).fill(undefined);
|
|
1536
|
+
const liveProgress: (AgentProgress | undefined)[] = new Array(tasks.length).fill(undefined);
|
|
1537
|
+
const foregroundControl = deps.state.foregroundControls.get(runId);
|
|
1538
|
+
const { setup: worktreeSetup, errorResult } = createParallelWorktreeSetup(
|
|
1539
|
+
params.worktree,
|
|
1540
|
+
effectiveCwd,
|
|
1541
|
+
runId,
|
|
1542
|
+
tasks,
|
|
1543
|
+
deps.config.worktreeSetupHook,
|
|
1544
|
+
deps.config.worktreeSetupHookTimeoutMs,
|
|
1545
|
+
);
|
|
1546
|
+
if (errorResult) return errorResult;
|
|
1547
|
+
|
|
1548
|
+
try {
|
|
1549
|
+
const duplicateOutputError = findDuplicateParallelOutputPath({
|
|
1550
|
+
tasks,
|
|
1551
|
+
behaviors,
|
|
1552
|
+
paramsCwd: effectiveCwd,
|
|
1553
|
+
ctxCwd: ctx.cwd,
|
|
1554
|
+
worktreeSetup,
|
|
1555
|
+
});
|
|
1556
|
+
if (duplicateOutputError) return buildParallelModeError(duplicateOutputError);
|
|
1557
|
+
for (let index = 0; index < tasks.length; index++) {
|
|
1558
|
+
const taskCwd = resolveParallelTaskCwd(tasks[index]!, effectiveCwd, worktreeSetup, index);
|
|
1559
|
+
const outputPath = resolveSingleOutputPath(behaviors[index]?.output, ctx.cwd, taskCwd);
|
|
1560
|
+
const validationError = validateFileOnlyOutputMode(behaviors[index]?.outputMode, outputPath, `Parallel task ${index + 1} (${tasks[index]!.agent})`);
|
|
1561
|
+
if (validationError) return buildParallelModeError(validationError);
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
const parallelProgressPrecreated = firstProgressIndex !== -1;
|
|
1565
|
+
if (parallelProgressPrecreated) writeInitialProgressFile(effectiveCwd);
|
|
1566
|
+
|
|
1567
|
+
if (params.context === "fork") {
|
|
1568
|
+
for (let i = 0; i < taskTexts.length; i++) {
|
|
1569
|
+
taskTexts[i] = wrapForkTask(taskTexts[i]!);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
const results = await runForegroundParallelTasks({
|
|
1574
|
+
tasks,
|
|
1575
|
+
taskTexts,
|
|
1576
|
+
agents,
|
|
1577
|
+
ctx,
|
|
1578
|
+
intercomEvents: deps.pi.events,
|
|
1579
|
+
signal,
|
|
1580
|
+
runId,
|
|
1581
|
+
sessionDirForIndex,
|
|
1582
|
+
sessionFileForIndex,
|
|
1583
|
+
shareEnabled,
|
|
1584
|
+
artifactConfig,
|
|
1585
|
+
artifactsDir,
|
|
1586
|
+
maxOutput: params.maxOutput,
|
|
1587
|
+
paramsCwd: effectiveCwd,
|
|
1588
|
+
availableModels,
|
|
1589
|
+
modelOverrides,
|
|
1590
|
+
behaviors,
|
|
1591
|
+
firstProgressIndex: parallelProgressPrecreated ? -1 : firstProgressIndex,
|
|
1592
|
+
controlConfig,
|
|
1593
|
+
onControlEvent,
|
|
1594
|
+
childIntercomTarget: childIntercomTarget ? (agent, index) => childIntercomTarget(runId, agent, index) : undefined,
|
|
1595
|
+
orchestratorIntercomTarget: data.intercomBridge.active ? data.intercomBridge.orchestratorTarget : undefined,
|
|
1596
|
+
foregroundControl,
|
|
1597
|
+
concurrencyLimit: parallelConcurrency,
|
|
1598
|
+
maxSubagentDepths,
|
|
1599
|
+
liveResults,
|
|
1600
|
+
liveProgress,
|
|
1601
|
+
onUpdate,
|
|
1602
|
+
worktreeSetup,
|
|
1603
|
+
});
|
|
1604
|
+
for (let i = 0; i < results.length; i++) {
|
|
1605
|
+
const run = results[i]!;
|
|
1606
|
+
recordRun(run.agent, taskTexts[i]!, run.exitCode, run.progressSummary?.durationMs ?? 0);
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
for (const result of results) {
|
|
1610
|
+
if (result.progress) allProgress.push(result.progress);
|
|
1611
|
+
if (result.artifactPaths) allArtifactPaths.push(result.artifactPaths);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
const interrupted = results.find((result) => result.interrupted);
|
|
1615
|
+
const details = compactForegroundDetails({
|
|
1616
|
+
mode: "parallel",
|
|
1617
|
+
runId,
|
|
1618
|
+
results,
|
|
1619
|
+
progress: params.includeProgress ? allProgress : undefined,
|
|
1620
|
+
artifacts: allArtifactPaths.length ? { dir: artifactsDir, files: allArtifactPaths } : undefined,
|
|
1621
|
+
});
|
|
1622
|
+
rememberForegroundRun(deps.state, { runId, mode: "parallel", cwd: effectiveCwd, results: details.results });
|
|
1623
|
+
if (interrupted) {
|
|
1624
|
+
return {
|
|
1625
|
+
content: [{ type: "text", text: `Parallel run paused after interrupt (${interrupted.agent}). Waiting for explicit next action.` }],
|
|
1626
|
+
details,
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
const detachedIndex = results.findIndex((result) => result.detached);
|
|
1630
|
+
const detached = detachedIndex >= 0 ? results[detachedIndex] : undefined;
|
|
1631
|
+
if (detached) {
|
|
1632
|
+
return {
|
|
1633
|
+
content: [{ type: "text", text: `Parallel run detached for intercom coordination (${detached.agent}). Reply to the supervisor request first. After the child exits, start a fresh follow-up if needed.` }],
|
|
1634
|
+
details,
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
const intercomReceipt = await maybeBuildForegroundIntercomReceipt({
|
|
1639
|
+
pi: deps.pi,
|
|
1640
|
+
intercomBridge: data.intercomBridge,
|
|
1641
|
+
runId,
|
|
1642
|
+
mode: "parallel",
|
|
1643
|
+
details,
|
|
1644
|
+
});
|
|
1645
|
+
if (intercomReceipt) {
|
|
1646
|
+
return {
|
|
1647
|
+
content: [{ type: "text", text: intercomReceipt.text }],
|
|
1648
|
+
details: intercomReceipt.details,
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
const worktreeSuffix = buildParallelWorktreeSuffix(worktreeSetup, artifactsDir, tasks);
|
|
1653
|
+
const ok = results.filter((result) => result.exitCode === 0).length;
|
|
1654
|
+
const downgradeNote = backgroundRequestedWhileClarifying ? " (background requested, but clarify kept this run foreground)" : "";
|
|
1655
|
+
const aggregatedOutput = aggregateParallelOutputs(
|
|
1656
|
+
results.map((result) => ({
|
|
1657
|
+
agent: result.agent,
|
|
1658
|
+
output: result.truncation?.text || getSingleResultOutput(result),
|
|
1659
|
+
exitCode: result.exitCode,
|
|
1660
|
+
error: result.error,
|
|
1661
|
+
})),
|
|
1662
|
+
(i, agent) => `=== Task ${i + 1}: ${agent} ===`,
|
|
1663
|
+
);
|
|
1664
|
+
|
|
1665
|
+
const summary = `${ok}/${results.length} succeeded${downgradeNote}`;
|
|
1666
|
+
const fullContent = worktreeSuffix
|
|
1667
|
+
? `${summary}\n\n${aggregatedOutput}\n\n${worktreeSuffix}`
|
|
1668
|
+
: `${summary}\n\n${aggregatedOutput}`;
|
|
1669
|
+
|
|
1670
|
+
return {
|
|
1671
|
+
content: [{ type: "text", text: fullContent }],
|
|
1672
|
+
details,
|
|
1673
|
+
};
|
|
1674
|
+
} finally {
|
|
1675
|
+
if (worktreeSetup) cleanupWorktrees(worktreeSetup);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
async function runSinglePath(data: ExecutionContextData, deps: ExecutorDeps): Promise<AgentToolResult<Details>> {
|
|
1680
|
+
const {
|
|
1681
|
+
params,
|
|
1682
|
+
effectiveCwd,
|
|
1683
|
+
agents,
|
|
1684
|
+
ctx,
|
|
1685
|
+
signal,
|
|
1686
|
+
runId,
|
|
1687
|
+
sessionDirForIndex,
|
|
1688
|
+
sessionFileForIndex,
|
|
1689
|
+
shareEnabled,
|
|
1690
|
+
artifactConfig,
|
|
1691
|
+
artifactsDir,
|
|
1692
|
+
onUpdate,
|
|
1693
|
+
sessionRoot,
|
|
1694
|
+
controlConfig,
|
|
1695
|
+
} = data;
|
|
1696
|
+
const onControlEvent = createForegroundControlNotifier(data, deps);
|
|
1697
|
+
const childIntercomTarget = data.intercomBridge.active ? resolveSubagentIntercomTarget(runId, params.agent!, 0) : undefined;
|
|
1698
|
+
const allProgress: AgentProgress[] = [];
|
|
1699
|
+
const allArtifactPaths: ArtifactPaths[] = [];
|
|
1700
|
+
const agentConfig = agents.find((a) => a.name === params.agent);
|
|
1701
|
+
if (!agentConfig) {
|
|
1702
|
+
return {
|
|
1703
|
+
content: [{ type: "text", text: `Unknown agent: ${params.agent}` }],
|
|
1704
|
+
isError: true,
|
|
1705
|
+
details: { mode: "single", results: [] },
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
const currentProvider = ctx.model?.provider;
|
|
1710
|
+
const availableModels: ModelInfo[] = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
1711
|
+
let task = params.task ?? "";
|
|
1712
|
+
let modelOverride: string | undefined = resolveModelCandidate(
|
|
1713
|
+
(params.model as string | undefined) ?? agentConfig.model,
|
|
1714
|
+
availableModels,
|
|
1715
|
+
currentProvider,
|
|
1716
|
+
);
|
|
1717
|
+
let skillOverride: string[] | false | undefined = normalizeSkillInput(params.skill);
|
|
1718
|
+
const rawOutput = params.output !== undefined ? params.output : agentConfig.output;
|
|
1719
|
+
let effectiveOutput: string | false | undefined = rawOutput === true ? agentConfig.output : (rawOutput as string | false | undefined);
|
|
1720
|
+
const effectiveOutputMode = params.outputMode ?? "inline";
|
|
1721
|
+
const currentMaxSubagentDepth = resolveCurrentMaxSubagentDepth(deps.config.maxSubagentDepth);
|
|
1722
|
+
const maxSubagentDepth = resolveChildMaxSubagentDepth(currentMaxSubagentDepth, agentConfig.maxSubagentDepth);
|
|
1723
|
+
|
|
1724
|
+
if (params.clarify === true && ctx.hasUI) {
|
|
1725
|
+
const behavior = resolveStepBehavior(agentConfig, { output: effectiveOutput, skills: skillOverride });
|
|
1726
|
+
const availableSkills = discoverAvailableSkills(effectiveCwd);
|
|
1727
|
+
|
|
1728
|
+
const result = await ctx.ui.custom<ChainClarifyResult>(
|
|
1729
|
+
(tui, theme, _kb, done) =>
|
|
1730
|
+
new ChainClarifyComponent(
|
|
1731
|
+
tui, theme,
|
|
1732
|
+
[agentConfig],
|
|
1733
|
+
[task],
|
|
1734
|
+
task,
|
|
1735
|
+
undefined,
|
|
1736
|
+
[behavior],
|
|
1737
|
+
availableModels,
|
|
1738
|
+
currentProvider,
|
|
1739
|
+
availableSkills,
|
|
1740
|
+
done,
|
|
1741
|
+
"single",
|
|
1742
|
+
),
|
|
1743
|
+
{ overlay: true, overlayOptions: { anchor: "center", width: 84, maxHeight: "80%" } },
|
|
1744
|
+
);
|
|
1745
|
+
|
|
1746
|
+
if (!result || !result.confirmed) {
|
|
1747
|
+
return { content: [{ type: "text", text: "Cancelled" }], details: { mode: "single", results: [] } };
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
task = result.templates[0]!;
|
|
1751
|
+
const override = result.behaviorOverrides[0];
|
|
1752
|
+
if (override?.model) modelOverride = override.model;
|
|
1753
|
+
if (override?.output !== undefined) effectiveOutput = override.output;
|
|
1754
|
+
if (override?.skills !== undefined) skillOverride = override.skills;
|
|
1755
|
+
|
|
1756
|
+
if (result.runInBackground) {
|
|
1757
|
+
if (!isAsyncAvailable()) {
|
|
1758
|
+
return {
|
|
1759
|
+
content: [{ type: "text", text: "Background mode requires upstream jiti for TypeScript execution but it could not be found. Ensure the pi-subagents package dependencies are installed." }],
|
|
1760
|
+
isError: true,
|
|
1761
|
+
details: { mode: "single" as const, results: [] },
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
const id = randomUUID();
|
|
1765
|
+
const asyncCtx = {
|
|
1766
|
+
pi: deps.pi,
|
|
1767
|
+
cwd: ctx.cwd,
|
|
1768
|
+
currentSessionId: deps.state.currentSessionId!,
|
|
1769
|
+
currentModelProvider: ctx.model?.provider,
|
|
1770
|
+
};
|
|
1771
|
+
return executeAsyncSingle(id, {
|
|
1772
|
+
agent: params.agent!,
|
|
1773
|
+
task: params.context === "fork" ? wrapForkTask(task) : task,
|
|
1774
|
+
agentConfig,
|
|
1775
|
+
ctx: asyncCtx,
|
|
1776
|
+
availableModels,
|
|
1777
|
+
cwd: effectiveCwd,
|
|
1778
|
+
maxOutput: params.maxOutput,
|
|
1779
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
1780
|
+
artifactConfig,
|
|
1781
|
+
shareEnabled,
|
|
1782
|
+
sessionRoot,
|
|
1783
|
+
sessionFile: sessionFileForIndex(0),
|
|
1784
|
+
skills: skillOverride === false ? [] : skillOverride,
|
|
1785
|
+
output: effectiveOutput,
|
|
1786
|
+
outputMode: effectiveOutputMode,
|
|
1787
|
+
modelOverride,
|
|
1788
|
+
maxSubagentDepth,
|
|
1789
|
+
worktreeSetupHook: deps.config.worktreeSetupHook,
|
|
1790
|
+
worktreeSetupHookTimeoutMs: deps.config.worktreeSetupHookTimeoutMs,
|
|
1791
|
+
controlConfig,
|
|
1792
|
+
controlIntercomTarget: data.intercomBridge.active ? data.intercomBridge.orchestratorTarget : undefined,
|
|
1793
|
+
childIntercomTarget: data.intercomBridge.active ? (agent, index) => resolveSubagentIntercomTarget(id, agent, index) : undefined,
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
if (params.context === "fork") {
|
|
1799
|
+
task = wrapForkTask(task);
|
|
1800
|
+
}
|
|
1801
|
+
const cleanTask = task;
|
|
1802
|
+
const outputPath = resolveSingleOutputPath(effectiveOutput, ctx.cwd, effectiveCwd);
|
|
1803
|
+
const validationError = validateFileOnlyOutputMode(effectiveOutputMode, outputPath, `Single run (${params.agent})`);
|
|
1804
|
+
if (validationError) {
|
|
1805
|
+
return { content: [{ type: "text", text: validationError }], isError: true, details: { mode: "single", results: [] } };
|
|
1806
|
+
}
|
|
1807
|
+
task = injectSingleOutputInstruction(task, outputPath);
|
|
1808
|
+
|
|
1809
|
+
let effectiveSkills: string[] | undefined;
|
|
1810
|
+
if (skillOverride === false) {
|
|
1811
|
+
effectiveSkills = [];
|
|
1812
|
+
} else {
|
|
1813
|
+
effectiveSkills = skillOverride;
|
|
1814
|
+
}
|
|
1815
|
+
const interruptController = new AbortController();
|
|
1816
|
+
const foregroundControl = deps.state.foregroundControls.get(runId);
|
|
1817
|
+
if (foregroundControl) {
|
|
1818
|
+
foregroundControl.currentAgent = params.agent;
|
|
1819
|
+
foregroundControl.currentIndex = 0;
|
|
1820
|
+
foregroundControl.currentActivityState = undefined;
|
|
1821
|
+
foregroundControl.updatedAt = Date.now();
|
|
1822
|
+
foregroundControl.interrupt = () => {
|
|
1823
|
+
if (interruptController.signal.aborted) return false;
|
|
1824
|
+
interruptController.abort();
|
|
1825
|
+
foregroundControl.currentActivityState = undefined;
|
|
1826
|
+
foregroundControl.updatedAt = Date.now();
|
|
1827
|
+
return true;
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
const forwardSingleUpdate = onUpdate
|
|
1832
|
+
? (update: AgentToolResult<Details>) => {
|
|
1833
|
+
if (foregroundControl) {
|
|
1834
|
+
const firstProgress = update.details?.progress?.[0];
|
|
1835
|
+
foregroundControl.currentAgent = params.agent;
|
|
1836
|
+
foregroundControl.currentIndex = firstProgress?.index ?? 0;
|
|
1837
|
+
foregroundControl.currentActivityState = firstProgress?.activityState;
|
|
1838
|
+
foregroundControl.lastActivityAt = firstProgress?.lastActivityAt;
|
|
1839
|
+
foregroundControl.currentTool = firstProgress?.currentTool;
|
|
1840
|
+
foregroundControl.currentToolStartedAt = firstProgress?.currentToolStartedAt;
|
|
1841
|
+
foregroundControl.currentPath = firstProgress?.currentPath;
|
|
1842
|
+
foregroundControl.turnCount = firstProgress?.turnCount;
|
|
1843
|
+
foregroundControl.tokens = firstProgress?.tokens;
|
|
1844
|
+
foregroundControl.toolCount = firstProgress?.toolCount;
|
|
1845
|
+
foregroundControl.updatedAt = Date.now();
|
|
1846
|
+
}
|
|
1847
|
+
onUpdate(update);
|
|
1848
|
+
}
|
|
1849
|
+
: undefined;
|
|
1850
|
+
|
|
1851
|
+
const r = await runSync(ctx.cwd, agents, params.agent!, task, {
|
|
1852
|
+
cwd: effectiveCwd,
|
|
1853
|
+
signal,
|
|
1854
|
+
interruptSignal: interruptController.signal,
|
|
1855
|
+
allowIntercomDetach: agentConfig.systemPrompt?.includes(INTERCOM_BRIDGE_MARKER) === true,
|
|
1856
|
+
intercomEvents: deps.pi.events,
|
|
1857
|
+
runId,
|
|
1858
|
+
sessionDir: sessionDirForIndex(0),
|
|
1859
|
+
sessionFile: sessionFileForIndex(0),
|
|
1860
|
+
share: shareEnabled,
|
|
1861
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
1862
|
+
artifactConfig,
|
|
1863
|
+
maxOutput: params.maxOutput,
|
|
1864
|
+
outputPath,
|
|
1865
|
+
outputMode: effectiveOutputMode,
|
|
1866
|
+
maxSubagentDepth,
|
|
1867
|
+
onUpdate: forwardSingleUpdate,
|
|
1868
|
+
controlConfig,
|
|
1869
|
+
onControlEvent,
|
|
1870
|
+
intercomSessionName: childIntercomTarget,
|
|
1871
|
+
orchestratorIntercomTarget: data.intercomBridge.active ? data.intercomBridge.orchestratorTarget : undefined,
|
|
1872
|
+
index: 0,
|
|
1873
|
+
modelOverride,
|
|
1874
|
+
availableModels,
|
|
1875
|
+
preferredModelProvider: currentProvider,
|
|
1876
|
+
skills: effectiveSkills,
|
|
1877
|
+
});
|
|
1878
|
+
if (foregroundControl?.currentIndex === 0) {
|
|
1879
|
+
foregroundControl.interrupt = undefined;
|
|
1880
|
+
foregroundControl.currentActivityState = r.progress?.activityState;
|
|
1881
|
+
foregroundControl.lastActivityAt = r.progress?.lastActivityAt;
|
|
1882
|
+
foregroundControl.currentTool = r.progress?.currentTool;
|
|
1883
|
+
foregroundControl.currentToolStartedAt = r.progress?.currentToolStartedAt;
|
|
1884
|
+
foregroundControl.currentPath = r.progress?.currentPath;
|
|
1885
|
+
foregroundControl.turnCount = r.progress?.turnCount;
|
|
1886
|
+
foregroundControl.tokens = r.progress?.tokens;
|
|
1887
|
+
foregroundControl.toolCount = r.progress?.toolCount;
|
|
1888
|
+
foregroundControl.updatedAt = Date.now();
|
|
1889
|
+
}
|
|
1890
|
+
recordRun(params.agent!, cleanTask, r.exitCode, r.progressSummary?.durationMs ?? 0);
|
|
1891
|
+
|
|
1892
|
+
if (r.progress) allProgress.push(r.progress);
|
|
1893
|
+
if (r.artifactPaths) allArtifactPaths.push(r.artifactPaths);
|
|
1894
|
+
|
|
1895
|
+
const fullOutput = getSingleResultOutput(r);
|
|
1896
|
+
const finalizedOutput = finalizeSingleOutput({
|
|
1897
|
+
fullOutput,
|
|
1898
|
+
truncatedOutput: r.truncation?.text,
|
|
1899
|
+
outputPath,
|
|
1900
|
+
outputMode: r.outputMode,
|
|
1901
|
+
exitCode: r.exitCode,
|
|
1902
|
+
savedPath: r.savedOutputPath,
|
|
1903
|
+
outputReference: r.outputReference,
|
|
1904
|
+
saveError: r.outputSaveError,
|
|
1905
|
+
});
|
|
1906
|
+
const details = compactForegroundDetails({
|
|
1907
|
+
mode: "single",
|
|
1908
|
+
runId,
|
|
1909
|
+
results: [r],
|
|
1910
|
+
progress: params.includeProgress ? allProgress : undefined,
|
|
1911
|
+
artifacts: allArtifactPaths.length ? { dir: artifactsDir, files: allArtifactPaths } : undefined,
|
|
1912
|
+
truncation: r.truncation,
|
|
1913
|
+
});
|
|
1914
|
+
rememberForegroundRun(deps.state, { runId, mode: "single", cwd: effectiveCwd, results: details.results });
|
|
1915
|
+
|
|
1916
|
+
if (!r.detached && !r.interrupted) {
|
|
1917
|
+
const intercomReceipt = await maybeBuildForegroundIntercomReceipt({
|
|
1918
|
+
pi: deps.pi,
|
|
1919
|
+
intercomBridge: data.intercomBridge,
|
|
1920
|
+
runId,
|
|
1921
|
+
mode: "single",
|
|
1922
|
+
details,
|
|
1923
|
+
});
|
|
1924
|
+
if (intercomReceipt) {
|
|
1925
|
+
return {
|
|
1926
|
+
content: [{ type: "text", text: intercomReceipt.text }],
|
|
1927
|
+
details: intercomReceipt.details,
|
|
1928
|
+
...(r.exitCode !== 0 ? { isError: true } : {}),
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
if (r.detached) {
|
|
1934
|
+
return {
|
|
1935
|
+
content: [{ type: "text", text: `Detached for intercom coordination: ${params.agent}. Reply to the supervisor request first. After the child exits, start a fresh follow-up if needed.` }],
|
|
1936
|
+
details,
|
|
1937
|
+
};
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
if (r.interrupted) {
|
|
1941
|
+
return {
|
|
1942
|
+
content: [{ type: "text", text: `Run paused after interrupt (${params.agent}). Waiting for explicit next action.` }],
|
|
1943
|
+
details,
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
if (r.exitCode !== 0)
|
|
1948
|
+
return {
|
|
1949
|
+
content: [{ type: "text", text: r.error || "Failed" }],
|
|
1950
|
+
details,
|
|
1951
|
+
isError: true,
|
|
1952
|
+
};
|
|
1953
|
+
return {
|
|
1954
|
+
content: [{ type: "text", text: finalizedOutput.displayOutput || "(no output)" }],
|
|
1955
|
+
details,
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
export function createSubagentExecutor(deps: ExecutorDeps): {
|
|
1960
|
+
execute: (
|
|
1961
|
+
id: string,
|
|
1962
|
+
params: SubagentParamsLike,
|
|
1963
|
+
signal: AbortSignal,
|
|
1964
|
+
onUpdate: ((r: AgentToolResult<Details>) => void) | undefined,
|
|
1965
|
+
ctx: ExtensionContext,
|
|
1966
|
+
) => Promise<AgentToolResult<Details>>;
|
|
1967
|
+
} {
|
|
1968
|
+
const execute = async (
|
|
1969
|
+
_id: string,
|
|
1970
|
+
params: SubagentParamsLike,
|
|
1971
|
+
signal: AbortSignal,
|
|
1972
|
+
onUpdate: ((r: AgentToolResult<Details>) => void) | undefined,
|
|
1973
|
+
ctx: ExtensionContext,
|
|
1974
|
+
): Promise<AgentToolResult<Details>> => {
|
|
1975
|
+
deps.state.baseCwd = ctx.cwd;
|
|
1976
|
+
deps.state.foregroundRuns ??= new Map();
|
|
1977
|
+
deps.state.foregroundControls ??= new Map();
|
|
1978
|
+
deps.state.lastForegroundControlId ??= null;
|
|
1979
|
+
const requestCwd = resolveRequestedCwd(ctx.cwd, params.cwd);
|
|
1980
|
+
const paramsWithResolvedCwd = params.cwd === undefined ? params : { ...params, cwd: requestCwd };
|
|
1981
|
+
if (params.action) {
|
|
1982
|
+
if (params.action === "doctor") {
|
|
1983
|
+
let currentSessionFile: string | null = null;
|
|
1984
|
+
let currentSessionId = deps.state.currentSessionId;
|
|
1985
|
+
let sessionError: string | undefined;
|
|
1986
|
+
try {
|
|
1987
|
+
currentSessionFile = ctx.sessionManager.getSessionFile() ?? null;
|
|
1988
|
+
currentSessionId = ctx.sessionManager.getSessionId();
|
|
1989
|
+
} catch (error) {
|
|
1990
|
+
sessionError = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
1991
|
+
}
|
|
1992
|
+
let orchestratorTarget: string | undefined;
|
|
1993
|
+
try {
|
|
1994
|
+
orchestratorTarget = resolveIntercomSessionTarget(deps.pi.getSessionName(), ctx.sessionManager.getSessionId());
|
|
1995
|
+
} catch {}
|
|
1996
|
+
return {
|
|
1997
|
+
content: [{
|
|
1998
|
+
type: "text",
|
|
1999
|
+
text: buildDoctorReport({
|
|
2000
|
+
cwd: requestCwd,
|
|
2001
|
+
config: deps.config,
|
|
2002
|
+
state: deps.state,
|
|
2003
|
+
context: paramsWithResolvedCwd.context,
|
|
2004
|
+
requestedSessionDir: paramsWithResolvedCwd.sessionDir,
|
|
2005
|
+
currentSessionFile,
|
|
2006
|
+
currentSessionId,
|
|
2007
|
+
orchestratorTarget,
|
|
2008
|
+
sessionError,
|
|
2009
|
+
expandTilde: deps.expandTilde,
|
|
2010
|
+
}),
|
|
2011
|
+
}],
|
|
2012
|
+
details: { mode: "management", results: [] },
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
if (params.action === "status") {
|
|
2016
|
+
const foreground = getForegroundControl(deps.state, paramsWithResolvedCwd.id ?? paramsWithResolvedCwd.runId);
|
|
2017
|
+
if (foreground) return foregroundStatusResult(foreground);
|
|
2018
|
+
return inspectSubagentStatus(paramsWithResolvedCwd);
|
|
2019
|
+
}
|
|
2020
|
+
if (params.action === "resume") {
|
|
2021
|
+
return resumeAsyncRun({ params: paramsWithResolvedCwd, requestCwd, ctx, deps });
|
|
2022
|
+
}
|
|
2023
|
+
if (params.action === "interrupt") {
|
|
2024
|
+
const targetRunId = paramsWithResolvedCwd.runId ?? paramsWithResolvedCwd.id;
|
|
2025
|
+
const foreground = getForegroundControl(deps.state, targetRunId);
|
|
2026
|
+
if (foreground?.interrupt) {
|
|
2027
|
+
const interrupted = foreground.interrupt();
|
|
2028
|
+
if (interrupted) {
|
|
2029
|
+
foreground.updatedAt = Date.now();
|
|
2030
|
+
foreground.currentActivityState = undefined;
|
|
2031
|
+
return {
|
|
2032
|
+
content: [{ type: "text", text: `Interrupt requested for foreground run ${foreground.runId}.` }],
|
|
2033
|
+
details: { mode: "management", results: [] },
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
return {
|
|
2037
|
+
content: [{ type: "text", text: `Foreground run ${foreground.runId} has no active child step to interrupt.` }],
|
|
2038
|
+
isError: true,
|
|
2039
|
+
details: { mode: "management", results: [] },
|
|
2040
|
+
};
|
|
2041
|
+
}
|
|
2042
|
+
const asyncInterruptResult = interruptAsyncRun(deps.state, targetRunId);
|
|
2043
|
+
if (asyncInterruptResult) return asyncInterruptResult;
|
|
2044
|
+
return {
|
|
2045
|
+
content: [{ type: "text", text: "No interrupt-capable run found in this session." }],
|
|
2046
|
+
isError: true,
|
|
2047
|
+
details: { mode: "management", results: [] },
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
if (!(SUBAGENT_ACTIONS as readonly string[]).includes(params.action)) {
|
|
2051
|
+
return {
|
|
2052
|
+
content: [{ type: "text", text: `Unknown action: ${params.action}. Valid: ${SUBAGENT_ACTIONS.join(", ")}` }],
|
|
2053
|
+
isError: true,
|
|
2054
|
+
details: { mode: "management" as const, results: [] },
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
return handleManagementAction(params.action, paramsWithResolvedCwd, { ...ctx, cwd: requestCwd });
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
const { blocked, depth, maxDepth } = checkSubagentDepth(deps.config.maxSubagentDepth);
|
|
2061
|
+
if (blocked) {
|
|
2062
|
+
return {
|
|
2063
|
+
content: [
|
|
2064
|
+
{
|
|
2065
|
+
type: "text",
|
|
2066
|
+
text:
|
|
2067
|
+
`Nested subagent call blocked (depth=${depth}, max=${maxDepth}). ` +
|
|
2068
|
+
"You are running at the maximum subagent nesting depth. " +
|
|
2069
|
+
"Complete your current task directly without delegating to further subagents.",
|
|
2070
|
+
},
|
|
2071
|
+
],
|
|
2072
|
+
isError: true,
|
|
2073
|
+
details: { mode: "single" as const, results: [] },
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
const normalized = normalizeRepeatedParallelCounts(paramsWithResolvedCwd);
|
|
2078
|
+
if (normalized.error) return normalized.error;
|
|
2079
|
+
const normalizedParams = normalized.params!;
|
|
2080
|
+
|
|
2081
|
+
let effectiveParams = applyForceTopLevelAsyncOverride(
|
|
2082
|
+
normalizedParams,
|
|
2083
|
+
depth,
|
|
2084
|
+
deps.config.forceTopLevelAsync === true,
|
|
2085
|
+
);
|
|
2086
|
+
|
|
2087
|
+
const scope: AgentScope = resolveExecutionAgentScope(effectiveParams.agentScope);
|
|
2088
|
+
const effectiveCwd = effectiveParams.cwd ?? ctx.cwd;
|
|
2089
|
+
const parentSessionFile = ctx.sessionManager.getSessionFile() ?? null;
|
|
2090
|
+
deps.state.currentSessionId = resolveCurrentSessionId(ctx.sessionManager);
|
|
2091
|
+
const discoveredAgents = deps.discoverAgents(effectiveCwd, scope).agents;
|
|
2092
|
+
effectiveParams = applyAgentDefaultContext(effectiveParams, discoveredAgents);
|
|
2093
|
+
const sessionName = resolveIntercomSessionTarget(deps.pi.getSessionName(), ctx.sessionManager.getSessionId());
|
|
2094
|
+
const intercomBridge = resolveIntercomBridge({
|
|
2095
|
+
config: deps.config.intercomBridge,
|
|
2096
|
+
context: effectiveParams.context,
|
|
2097
|
+
orchestratorTarget: sessionName,
|
|
2098
|
+
cwd: effectiveCwd,
|
|
2099
|
+
});
|
|
2100
|
+
const agents = intercomBridge.active
|
|
2101
|
+
? discoveredAgents.map((agent) => applyIntercomBridgeToAgent(agent, intercomBridge))
|
|
2102
|
+
: discoveredAgents;
|
|
2103
|
+
const runId = randomUUID().slice(0, 8);
|
|
2104
|
+
const shareEnabled = effectiveParams.share === true;
|
|
2105
|
+
const hasChain = (effectiveParams.chain?.length ?? 0) > 0;
|
|
2106
|
+
const hasTasks = (effectiveParams.tasks?.length ?? 0) > 0;
|
|
2107
|
+
const hasSingle = !hasChain && !hasTasks && Boolean(effectiveParams.agent);
|
|
2108
|
+
const allowClarifyTaskPrompt = hasChain
|
|
2109
|
+
&& effectiveParams.clarify === true
|
|
2110
|
+
&& ctx.hasUI
|
|
2111
|
+
&& !(effectiveParams.chain?.some(isParallelStep) ?? false);
|
|
2112
|
+
|
|
2113
|
+
const validationError = validateExecutionInput(
|
|
2114
|
+
effectiveParams,
|
|
2115
|
+
agents,
|
|
2116
|
+
hasChain,
|
|
2117
|
+
hasTasks,
|
|
2118
|
+
hasSingle,
|
|
2119
|
+
allowClarifyTaskPrompt,
|
|
2120
|
+
);
|
|
2121
|
+
if (validationError) return validationError;
|
|
2122
|
+
|
|
2123
|
+
let sessionFileForIndex: (idx?: number) => string | undefined = () => undefined;
|
|
2124
|
+
try {
|
|
2125
|
+
sessionFileForIndex = createForkContextResolver(ctx.sessionManager, effectiveParams.context).sessionFileForIndex;
|
|
2126
|
+
} catch (error) {
|
|
2127
|
+
return toExecutionErrorResult(effectiveParams, error);
|
|
2128
|
+
}
|
|
2129
|
+
const requestedAsync = effectiveParams.async ?? deps.asyncByDefault;
|
|
2130
|
+
const backgroundRequestedWhileClarifying = (hasChain || hasTasks) && requestedAsync && effectiveParams.clarify === true;
|
|
2131
|
+
const effectiveAsync = requestedAsync && effectiveParams.clarify !== true;
|
|
2132
|
+
const controlConfig = resolveControlConfig(deps.config.control, effectiveParams.control);
|
|
2133
|
+
|
|
2134
|
+
const artifactConfig: ArtifactConfig = {
|
|
2135
|
+
...DEFAULT_ARTIFACT_CONFIG,
|
|
2136
|
+
enabled: effectiveParams.artifacts !== false,
|
|
2137
|
+
};
|
|
2138
|
+
const artifactsDir = effectiveAsync ? deps.tempArtifactsDir : getArtifactsDir(parentSessionFile);
|
|
2139
|
+
|
|
2140
|
+
let sessionRoot: string;
|
|
2141
|
+
if (effectiveParams.sessionDir) {
|
|
2142
|
+
sessionRoot = path.resolve(deps.expandTilde(effectiveParams.sessionDir));
|
|
2143
|
+
} else {
|
|
2144
|
+
const baseSessionRoot = deps.config.defaultSessionDir
|
|
2145
|
+
? path.resolve(deps.expandTilde(deps.config.defaultSessionDir))
|
|
2146
|
+
: deps.getSubagentSessionRoot(parentSessionFile);
|
|
2147
|
+
sessionRoot = path.join(baseSessionRoot, runId);
|
|
2148
|
+
}
|
|
2149
|
+
try {
|
|
2150
|
+
fs.mkdirSync(sessionRoot, { recursive: true });
|
|
2151
|
+
} catch (error) {
|
|
2152
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2153
|
+
return toExecutionErrorResult(
|
|
2154
|
+
effectiveParams,
|
|
2155
|
+
new Error(`Failed to create session directory '${sessionRoot}': ${message}`),
|
|
2156
|
+
);
|
|
2157
|
+
}
|
|
2158
|
+
const sessionDirForIndex = (idx?: number) =>
|
|
2159
|
+
path.join(sessionRoot, `run-${idx ?? 0}`);
|
|
2160
|
+
const childSessionFileForIndex = (idx?: number) =>
|
|
2161
|
+
sessionFileForIndex(idx) ?? path.join(sessionDirForIndex(idx), "session.jsonl");
|
|
2162
|
+
|
|
2163
|
+
const onUpdateWithContext = onUpdate
|
|
2164
|
+
? (r: AgentToolResult<Details>) => onUpdate(withForkContext(r, effectiveParams.context))
|
|
2165
|
+
: undefined;
|
|
2166
|
+
|
|
2167
|
+
const execData: ExecutionContextData = {
|
|
2168
|
+
params: effectiveParams,
|
|
2169
|
+
effectiveCwd,
|
|
2170
|
+
ctx,
|
|
2171
|
+
signal,
|
|
2172
|
+
onUpdate: onUpdateWithContext,
|
|
2173
|
+
agents,
|
|
2174
|
+
runId,
|
|
2175
|
+
shareEnabled,
|
|
2176
|
+
sessionRoot,
|
|
2177
|
+
sessionDirForIndex,
|
|
2178
|
+
sessionFileForIndex: childSessionFileForIndex,
|
|
2179
|
+
artifactConfig,
|
|
2180
|
+
artifactsDir,
|
|
2181
|
+
backgroundRequestedWhileClarifying,
|
|
2182
|
+
effectiveAsync,
|
|
2183
|
+
controlConfig,
|
|
2184
|
+
intercomBridge,
|
|
2185
|
+
};
|
|
2186
|
+
|
|
2187
|
+
const foregroundMode: "single" | "parallel" | "chain" = hasChain ? "chain" : hasTasks ? "parallel" : "single";
|
|
2188
|
+
const foregroundControl = effectiveAsync
|
|
2189
|
+
? undefined
|
|
2190
|
+
: {
|
|
2191
|
+
runId,
|
|
2192
|
+
mode: foregroundMode,
|
|
2193
|
+
startedAt: Date.now(),
|
|
2194
|
+
updatedAt: Date.now(),
|
|
2195
|
+
currentAgent: undefined,
|
|
2196
|
+
currentIndex: undefined,
|
|
2197
|
+
currentActivityState: undefined,
|
|
2198
|
+
interrupt: undefined,
|
|
2199
|
+
};
|
|
2200
|
+
if (foregroundControl) {
|
|
2201
|
+
deps.state.foregroundControls.set(runId, foregroundControl);
|
|
2202
|
+
deps.state.lastForegroundControlId = runId;
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
try {
|
|
2206
|
+
const asyncResult = runAsyncPath(execData, deps);
|
|
2207
|
+
if (asyncResult) return withForkContext(asyncResult, effectiveParams.context);
|
|
2208
|
+
if (hasChain && effectiveParams.chain) return withForkContext(await runChainPath(execData, deps), effectiveParams.context);
|
|
2209
|
+
if (hasTasks && effectiveParams.tasks) return withForkContext(await runParallelPath(execData, deps), effectiveParams.context);
|
|
2210
|
+
if (hasSingle) return withForkContext(await runSinglePath(execData, deps), effectiveParams.context);
|
|
2211
|
+
} catch (error) {
|
|
2212
|
+
return toExecutionErrorResult(effectiveParams, error);
|
|
2213
|
+
} finally {
|
|
2214
|
+
if (foregroundControl) {
|
|
2215
|
+
clearPendingForegroundControlNotices(deps.state, runId);
|
|
2216
|
+
deps.state.foregroundControls.delete(runId);
|
|
2217
|
+
if (deps.state.lastForegroundControlId === runId) {
|
|
2218
|
+
deps.state.lastForegroundControlId = null;
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
return withForkContext({
|
|
2224
|
+
content: [{ type: "text", text: "Invalid params" }],
|
|
2225
|
+
isError: true,
|
|
2226
|
+
details: { mode: "single" as const, results: [] },
|
|
2227
|
+
}, effectiveParams.context);
|
|
2228
|
+
};
|
|
2229
|
+
|
|
2230
|
+
return { execute };
|
|
2231
|
+
}
|