@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,1760 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import type { Message } from "@earendil-works/pi-ai";
|
|
6
|
+
import { writeAtomicJson } from "../../shared/atomic-json.ts";
|
|
7
|
+
import { appendJsonl, getArtifactPaths } from "../../shared/artifacts.ts";
|
|
8
|
+
import { PI_CODING_AGENT_PACKAGE, getPiSpawnCommand, resolveInstalledPiPackageRoot } from "../shared/pi-spawn.ts";
|
|
9
|
+
import { captureSingleOutputSnapshot, finalizeSingleOutput, formatSavedOutputReference, resolveSingleOutput, type SingleOutputSnapshot } from "../shared/single-output.ts";
|
|
10
|
+
import {
|
|
11
|
+
type ActivityState,
|
|
12
|
+
type ArtifactConfig,
|
|
13
|
+
type ArtifactPaths,
|
|
14
|
+
type AsyncParallelGroupStatus,
|
|
15
|
+
type AsyncStatus,
|
|
16
|
+
type ModelAttempt,
|
|
17
|
+
type ResolvedControlConfig,
|
|
18
|
+
type SubagentRunMode,
|
|
19
|
+
type Usage,
|
|
20
|
+
DEFAULT_MAX_OUTPUT,
|
|
21
|
+
type MaxOutputConfig,
|
|
22
|
+
truncateOutput,
|
|
23
|
+
getSubagentDepthEnv,
|
|
24
|
+
} from "../../shared/types.ts";
|
|
25
|
+
import {
|
|
26
|
+
DEFAULT_CONTROL_CONFIG,
|
|
27
|
+
buildControlEvent,
|
|
28
|
+
deriveActivityState,
|
|
29
|
+
claimControlNotification,
|
|
30
|
+
formatControlIntercomMessage,
|
|
31
|
+
formatControlNoticeMessage,
|
|
32
|
+
} from "../shared/subagent-control.ts";
|
|
33
|
+
import {
|
|
34
|
+
type RunnerSubagentStep as SubagentStep,
|
|
35
|
+
type RunnerStep,
|
|
36
|
+
isParallelGroup,
|
|
37
|
+
flattenSteps,
|
|
38
|
+
mapConcurrent,
|
|
39
|
+
aggregateParallelOutputs,
|
|
40
|
+
MAX_PARALLEL_CONCURRENCY,
|
|
41
|
+
} from "../shared/parallel-utils.ts";
|
|
42
|
+
import { buildPiArgs, cleanupTempDir } from "../shared/pi-args.ts";
|
|
43
|
+
import { formatModelAttemptNote, isRetryableModelFailure } from "../shared/model-fallback.ts";
|
|
44
|
+
import { attachPostExitStdioGuard, trySignalChild } from "../../shared/post-exit-stdio-guard.ts";
|
|
45
|
+
import { detectSubagentError, extractTextFromContent, extractToolArgsPreview, getFinalOutput } from "../../shared/utils.ts";
|
|
46
|
+
import { evaluateCompletionMutationGuard } from "../shared/completion-guard.ts";
|
|
47
|
+
import {
|
|
48
|
+
createMutatingFailureState,
|
|
49
|
+
didMutatingToolFail,
|
|
50
|
+
isMutatingTool,
|
|
51
|
+
nextLongRunningTrigger,
|
|
52
|
+
recordMutatingFailure,
|
|
53
|
+
resetMutatingFailureState,
|
|
54
|
+
resolveCurrentPath,
|
|
55
|
+
shouldEscalateMutatingFailures,
|
|
56
|
+
summarizeRecentMutatingFailures,
|
|
57
|
+
} from "../shared/long-running-guard.ts";
|
|
58
|
+
import { parseSessionTokens } from "../../shared/session-tokens.ts";
|
|
59
|
+
import type { TokenUsage } from "../../shared/types.ts";
|
|
60
|
+
import {
|
|
61
|
+
cleanupWorktrees,
|
|
62
|
+
createWorktrees,
|
|
63
|
+
diffWorktrees,
|
|
64
|
+
findWorktreeTaskCwdConflict,
|
|
65
|
+
formatWorktreeDiffSummary,
|
|
66
|
+
formatWorktreeTaskCwdConflict,
|
|
67
|
+
type WorktreeSetup,
|
|
68
|
+
} from "../shared/worktree.ts";
|
|
69
|
+
import { resolveEffectiveThinking } from "../../shared/model-info.ts";
|
|
70
|
+
import { writeInitialProgressFile } from "../../shared/settings.ts";
|
|
71
|
+
|
|
72
|
+
interface SubagentRunConfig {
|
|
73
|
+
id: string;
|
|
74
|
+
steps: RunnerStep[];
|
|
75
|
+
resultPath: string;
|
|
76
|
+
cwd: string;
|
|
77
|
+
placeholder: string;
|
|
78
|
+
taskIndex?: number;
|
|
79
|
+
totalTasks?: number;
|
|
80
|
+
maxOutput?: MaxOutputConfig;
|
|
81
|
+
artifactsDir?: string;
|
|
82
|
+
artifactConfig?: Partial<ArtifactConfig>;
|
|
83
|
+
share?: boolean;
|
|
84
|
+
sessionDir?: string;
|
|
85
|
+
asyncDir: string;
|
|
86
|
+
sessionId?: string | null;
|
|
87
|
+
piPackageRoot?: string;
|
|
88
|
+
piArgv1?: string;
|
|
89
|
+
worktreeSetupHook?: string;
|
|
90
|
+
worktreeSetupHookTimeoutMs?: number;
|
|
91
|
+
controlConfig?: ResolvedControlConfig;
|
|
92
|
+
controlIntercomTarget?: string;
|
|
93
|
+
childIntercomTargets?: Array<string | undefined>;
|
|
94
|
+
resultMode?: SubagentRunMode;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface StepResult {
|
|
98
|
+
agent: string;
|
|
99
|
+
output: string;
|
|
100
|
+
error?: string;
|
|
101
|
+
success: boolean;
|
|
102
|
+
skipped?: boolean;
|
|
103
|
+
sessionFile?: string;
|
|
104
|
+
intercomTarget?: string;
|
|
105
|
+
model?: string;
|
|
106
|
+
attemptedModels?: string[];
|
|
107
|
+
modelAttempts?: ModelAttempt[];
|
|
108
|
+
artifactPaths?: ArtifactPaths;
|
|
109
|
+
truncated?: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const ASYNC_INTERRUPT_SIGNAL: NodeJS.Signals = process.platform === "win32" ? "SIGBREAK" : "SIGUSR2";
|
|
113
|
+
|
|
114
|
+
function findLatestSessionFile(sessionDir: string): string | null {
|
|
115
|
+
try {
|
|
116
|
+
const files = fs
|
|
117
|
+
.readdirSync(sessionDir)
|
|
118
|
+
.filter((f) => f.endsWith(".jsonl"))
|
|
119
|
+
.map((f) => path.join(sessionDir, f));
|
|
120
|
+
if (files.length === 0) return null;
|
|
121
|
+
files.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs);
|
|
122
|
+
return files[0] ?? null;
|
|
123
|
+
} catch {
|
|
124
|
+
// Session lookup is optional metadata.
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function emptyUsage(): Usage {
|
|
130
|
+
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function tokenUsageFromAttempts(attempts: ModelAttempt[] | undefined): TokenUsage | null {
|
|
134
|
+
if (!attempts || attempts.length === 0) return null;
|
|
135
|
+
let input = 0;
|
|
136
|
+
let output = 0;
|
|
137
|
+
for (const attempt of attempts) {
|
|
138
|
+
input += attempt.usage?.input ?? 0;
|
|
139
|
+
output += attempt.usage?.output ?? 0;
|
|
140
|
+
}
|
|
141
|
+
const total = input + output;
|
|
142
|
+
return total > 0 ? { input, output, total } : null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function appendRecentStepOutput(step: RunnerStatusStep, lines: string[]): void {
|
|
146
|
+
const nonEmpty = lines.filter((line) => line.trim());
|
|
147
|
+
if (nonEmpty.length === 0) return;
|
|
148
|
+
step.recentOutput ??= [];
|
|
149
|
+
step.recentOutput.push(...nonEmpty);
|
|
150
|
+
if (step.recentOutput.length > 50) {
|
|
151
|
+
step.recentOutput.splice(0, step.recentOutput.length - 50);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function resetStepLiveDetail(step: RunnerStatusStep): void {
|
|
156
|
+
step.currentTool = undefined;
|
|
157
|
+
step.currentToolArgs = undefined;
|
|
158
|
+
step.currentToolStartedAt = undefined;
|
|
159
|
+
step.currentPath = undefined;
|
|
160
|
+
step.recentTools = [];
|
|
161
|
+
step.recentOutput = [];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface ChildEventContext {
|
|
165
|
+
eventsPath: string;
|
|
166
|
+
runId: string;
|
|
167
|
+
stepIndex: number;
|
|
168
|
+
agent: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
interface ChildUsage {
|
|
172
|
+
input?: number;
|
|
173
|
+
inputTokens?: number;
|
|
174
|
+
output?: number;
|
|
175
|
+
outputTokens?: number;
|
|
176
|
+
cacheRead?: number;
|
|
177
|
+
cacheWrite?: number;
|
|
178
|
+
cost?: { total?: number };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
type ChildMessage = Message & {
|
|
182
|
+
model?: string;
|
|
183
|
+
errorMessage?: string;
|
|
184
|
+
usage?: ChildUsage;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
interface ChildEvent {
|
|
188
|
+
type?: string;
|
|
189
|
+
message?: ChildMessage;
|
|
190
|
+
toolName?: string;
|
|
191
|
+
args?: Record<string, unknown>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface RunPiStreamingResult {
|
|
195
|
+
stderr: string;
|
|
196
|
+
exitCode: number | null;
|
|
197
|
+
messages: Message[];
|
|
198
|
+
usage: Usage;
|
|
199
|
+
model?: string;
|
|
200
|
+
error?: string;
|
|
201
|
+
finalOutput: string;
|
|
202
|
+
interrupted?: boolean;
|
|
203
|
+
observedMutationAttempt?: boolean;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function runPiStreaming(
|
|
207
|
+
args: string[],
|
|
208
|
+
cwd: string,
|
|
209
|
+
outputFile: string,
|
|
210
|
+
env?: Record<string, string | undefined>,
|
|
211
|
+
piPackageRoot?: string,
|
|
212
|
+
piArgv1?: string,
|
|
213
|
+
maxSubagentDepth?: number,
|
|
214
|
+
childEventContext?: ChildEventContext,
|
|
215
|
+
registerInterrupt?: (interrupt: (() => void) | undefined) => void,
|
|
216
|
+
onChildEvent?: (event: ChildEvent) => void,
|
|
217
|
+
): Promise<RunPiStreamingResult> {
|
|
218
|
+
return new Promise((resolve) => {
|
|
219
|
+
const outputStream = fs.createWriteStream(outputFile, { flags: "w" });
|
|
220
|
+
const spawnEnv = { ...process.env, ...(env ?? {}), ...getSubagentDepthEnv(maxSubagentDepth) };
|
|
221
|
+
const spawnSpec = getPiSpawnCommand(args, {
|
|
222
|
+
...(piPackageRoot ? { piPackageRoot } : {}),
|
|
223
|
+
...(piArgv1 ? { argv1: piArgv1 } : {}),
|
|
224
|
+
});
|
|
225
|
+
const child = spawn(spawnSpec.command, spawnSpec.args, { cwd, stdio: ["ignore", "pipe", "pipe"], env: spawnEnv });
|
|
226
|
+
let stderr = "";
|
|
227
|
+
let stdoutBuf = "";
|
|
228
|
+
let stderrBuf = "";
|
|
229
|
+
const messages: Message[] = [];
|
|
230
|
+
const usage = emptyUsage();
|
|
231
|
+
let model: string | undefined;
|
|
232
|
+
let error: string | undefined;
|
|
233
|
+
let interrupted = false;
|
|
234
|
+
let observedMutationAttempt = false;
|
|
235
|
+
const rawStdoutLines: string[] = [];
|
|
236
|
+
|
|
237
|
+
const writeOutputLine = (line: string) => {
|
|
238
|
+
if (!line.trim()) return;
|
|
239
|
+
outputStream.write(`${line}\n`);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const writeOutputText = (text: string) => {
|
|
243
|
+
for (const line of text.split("\n")) {
|
|
244
|
+
writeOutputLine(line);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const appendChildEvent = (event: Record<string, unknown>) => {
|
|
249
|
+
if (!childEventContext) return;
|
|
250
|
+
appendJsonl(childEventContext.eventsPath, JSON.stringify({
|
|
251
|
+
...event,
|
|
252
|
+
subagentSource: "child",
|
|
253
|
+
subagentRunId: childEventContext.runId,
|
|
254
|
+
subagentStepIndex: childEventContext.stepIndex,
|
|
255
|
+
subagentAgent: childEventContext.agent,
|
|
256
|
+
observedAt: Date.now(),
|
|
257
|
+
}));
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const appendChildLine = (type: "subagent.child.stdout" | "subagent.child.stderr", line: string) => {
|
|
261
|
+
appendChildEvent({ type, line });
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const processStdoutLine = (line: string) => {
|
|
265
|
+
if (!line.trim()) return;
|
|
266
|
+
let event: ChildEvent;
|
|
267
|
+
try {
|
|
268
|
+
event = JSON.parse(line) as ChildEvent;
|
|
269
|
+
} catch {
|
|
270
|
+
rawStdoutLines.push(line);
|
|
271
|
+
writeOutputLine(line);
|
|
272
|
+
appendChildLine("subagent.child.stdout", line);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
appendChildEvent(event);
|
|
277
|
+
onChildEvent?.(event);
|
|
278
|
+
|
|
279
|
+
if (event.type === "tool_execution_start" && event.toolName) {
|
|
280
|
+
observedMutationAttempt = observedMutationAttempt || isMutatingTool(event.toolName, event.args);
|
|
281
|
+
const toolArgs = extractToolArgsPreview(event.args ?? {});
|
|
282
|
+
writeOutputLine(toolArgs ? `${event.toolName}: ${toolArgs}` : event.toolName);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if ((event.type === "message_end" || event.type === "tool_result_end") && event.message) {
|
|
287
|
+
messages.push(event.message);
|
|
288
|
+
const text = extractTextFromContent(event.message.content);
|
|
289
|
+
if (text) writeOutputText(text);
|
|
290
|
+
|
|
291
|
+
if (event.type !== "message_end" || event.message.role !== "assistant") return;
|
|
292
|
+
if (event.message.model) model = event.message.model;
|
|
293
|
+
if (event.message.errorMessage) error = event.message.errorMessage;
|
|
294
|
+
const eventUsage = event.message.usage;
|
|
295
|
+
if (eventUsage) {
|
|
296
|
+
usage.turns++;
|
|
297
|
+
usage.input += eventUsage.input ?? eventUsage.inputTokens ?? 0;
|
|
298
|
+
usage.output += eventUsage.output ?? eventUsage.outputTokens ?? 0;
|
|
299
|
+
usage.cacheRead += eventUsage.cacheRead ?? 0;
|
|
300
|
+
usage.cacheWrite += eventUsage.cacheWrite ?? 0;
|
|
301
|
+
usage.cost += eventUsage.cost?.total ?? 0;
|
|
302
|
+
}
|
|
303
|
+
const stopReason = (event.message as { stopReason?: string }).stopReason;
|
|
304
|
+
const hasToolCall = Array.isArray(event.message.content)
|
|
305
|
+
&& event.message.content.some((part) => (part as { type?: string }).type === "toolCall");
|
|
306
|
+
if (stopReason === "stop" && !hasToolCall) {
|
|
307
|
+
cleanTerminalAssistantStopReceived ||= !event.message.errorMessage;
|
|
308
|
+
startFinalDrain();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const processStderrText = (text: string) => {
|
|
314
|
+
stderr += text;
|
|
315
|
+
stderrBuf += text;
|
|
316
|
+
outputStream.write(text);
|
|
317
|
+
if (!childEventContext) return;
|
|
318
|
+
const lines = stderrBuf.split("\n");
|
|
319
|
+
stderrBuf = lines.pop() || "";
|
|
320
|
+
for (const line of lines) {
|
|
321
|
+
if (!line.trim()) continue;
|
|
322
|
+
appendChildLine("subagent.child.stderr", line);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// Guard both cases that can leave the parent waiting on `close` forever:
|
|
327
|
+
// a lingering stdio holder after `exit`, or a child that never exits.
|
|
328
|
+
const FINAL_STOP_GRACE_MS = 1000;
|
|
329
|
+
const HARD_KILL_MS = 3000;
|
|
330
|
+
let childExited = false;
|
|
331
|
+
let forcedTerminationSignal = false;
|
|
332
|
+
let cleanTerminalAssistantStopReceived = false;
|
|
333
|
+
let finalDrainTimer: NodeJS.Timeout | undefined;
|
|
334
|
+
let finalHardKillTimer: NodeJS.Timeout | undefined;
|
|
335
|
+
let settled = false;
|
|
336
|
+
const clearStdioGuard = attachPostExitStdioGuard(child, { idleMs: 2000, hardMs: 8000 });
|
|
337
|
+
child.stdout.on("data", (chunk: Buffer) => {
|
|
338
|
+
const text = chunk.toString();
|
|
339
|
+
stdoutBuf += text;
|
|
340
|
+
const lines = stdoutBuf.split("\n");
|
|
341
|
+
stdoutBuf = lines.pop() || "";
|
|
342
|
+
for (const line of lines) processStdoutLine(line);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
child.stderr.on("data", (chunk: Buffer) => {
|
|
346
|
+
processStderrText(chunk.toString());
|
|
347
|
+
});
|
|
348
|
+
registerInterrupt?.(() => {
|
|
349
|
+
if (settled) return;
|
|
350
|
+
interrupted = true;
|
|
351
|
+
if (!error) error = "Interrupted. Waiting for explicit next action.";
|
|
352
|
+
trySignalChild(child, "SIGINT");
|
|
353
|
+
setTimeout(() => {
|
|
354
|
+
if (!settled) trySignalChild(child, "SIGTERM");
|
|
355
|
+
}, 1000).unref?.();
|
|
356
|
+
});
|
|
357
|
+
const clearDrainTimers = () => {
|
|
358
|
+
if (finalDrainTimer) {
|
|
359
|
+
clearTimeout(finalDrainTimer);
|
|
360
|
+
finalDrainTimer = undefined;
|
|
361
|
+
}
|
|
362
|
+
if (finalHardKillTimer) {
|
|
363
|
+
clearTimeout(finalHardKillTimer);
|
|
364
|
+
finalHardKillTimer = undefined;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
function startFinalDrain(): void {
|
|
368
|
+
if (childExited || finalDrainTimer || settled) return;
|
|
369
|
+
finalDrainTimer = setTimeout(() => {
|
|
370
|
+
if (settled) return;
|
|
371
|
+
const termSent = trySignalChild(child, "SIGTERM");
|
|
372
|
+
if (!termSent) return;
|
|
373
|
+
forcedTerminationSignal = true;
|
|
374
|
+
if (!cleanTerminalAssistantStopReceived && !error) {
|
|
375
|
+
error = `Subagent process did not exit within ${FINAL_STOP_GRACE_MS}ms after its final message. Forcing termination.`;
|
|
376
|
+
}
|
|
377
|
+
finalHardKillTimer = setTimeout(() => {
|
|
378
|
+
if (settled) return;
|
|
379
|
+
forcedTerminationSignal = trySignalChild(child, "SIGKILL") || forcedTerminationSignal;
|
|
380
|
+
}, HARD_KILL_MS);
|
|
381
|
+
finalHardKillTimer.unref?.();
|
|
382
|
+
}, FINAL_STOP_GRACE_MS);
|
|
383
|
+
finalDrainTimer.unref?.();
|
|
384
|
+
}
|
|
385
|
+
child.on("exit", () => {
|
|
386
|
+
childExited = true;
|
|
387
|
+
clearDrainTimers();
|
|
388
|
+
});
|
|
389
|
+
child.on("close", (exitCode, signal) => {
|
|
390
|
+
settled = true;
|
|
391
|
+
registerInterrupt?.(undefined);
|
|
392
|
+
clearDrainTimers();
|
|
393
|
+
clearStdioGuard();
|
|
394
|
+
if (stdoutBuf.trim()) processStdoutLine(stdoutBuf);
|
|
395
|
+
if (stderrBuf.trim()) appendChildLine("subagent.child.stderr", stderrBuf);
|
|
396
|
+
outputStream.end();
|
|
397
|
+
const finalOutput = getFinalOutput(messages) || rawStdoutLines.join("\n").trim();
|
|
398
|
+
const forcedDrainAfterFinalSuccess = forcedTerminationSignal && cleanTerminalAssistantStopReceived && !error;
|
|
399
|
+
resolve({
|
|
400
|
+
stderr,
|
|
401
|
+
exitCode: interrupted || forcedDrainAfterFinalSuccess ? 0 : forcedTerminationSignal || signal ? (exitCode ?? 1) : exitCode,
|
|
402
|
+
messages,
|
|
403
|
+
usage,
|
|
404
|
+
model,
|
|
405
|
+
error: interrupted || forcedDrainAfterFinalSuccess ? undefined : error,
|
|
406
|
+
finalOutput,
|
|
407
|
+
interrupted,
|
|
408
|
+
observedMutationAttempt,
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
child.on("error", (spawnError) => {
|
|
413
|
+
settled = true;
|
|
414
|
+
registerInterrupt?.(undefined);
|
|
415
|
+
clearDrainTimers();
|
|
416
|
+
clearStdioGuard();
|
|
417
|
+
outputStream.end();
|
|
418
|
+
const finalOutput = getFinalOutput(messages) || rawStdoutLines.join("\n").trim();
|
|
419
|
+
const spawnErrorMessage = spawnError instanceof Error ? spawnError.message : String(spawnError);
|
|
420
|
+
resolve({ stderr, exitCode: 1, messages, usage, model, error: error ?? spawnErrorMessage, finalOutput, observedMutationAttempt });
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function resolvePiPackageRootFallback(): string {
|
|
426
|
+
const root = resolveInstalledPiPackageRoot();
|
|
427
|
+
if (root) return root;
|
|
428
|
+
throw new Error(`Could not resolve ${PI_CODING_AGENT_PACKAGE} package root`);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async function exportSessionHtml(sessionFile: string, outputDir: string, piPackageRoot?: string): Promise<string> {
|
|
432
|
+
const pkgRoot = piPackageRoot ?? resolvePiPackageRootFallback();
|
|
433
|
+
const exportModulePath = path.join(pkgRoot, "dist", "core", "export-html", "index.js");
|
|
434
|
+
const moduleUrl = pathToFileURL(exportModulePath).href;
|
|
435
|
+
const mod = await import(moduleUrl);
|
|
436
|
+
const exportFromFile = (mod as { exportFromFile?: (inputPath: string, options?: { outputPath?: string }) => string })
|
|
437
|
+
.exportFromFile;
|
|
438
|
+
if (typeof exportFromFile !== "function") {
|
|
439
|
+
throw new Error("exportFromFile not available");
|
|
440
|
+
}
|
|
441
|
+
const outputPath = path.join(outputDir, `${path.basename(sessionFile, ".jsonl")}.html`);
|
|
442
|
+
return exportFromFile(sessionFile, { outputPath });
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function createShareLink(htmlPath: string): { shareUrl: string; gistUrl: string } | { error: string } {
|
|
446
|
+
try {
|
|
447
|
+
const auth = spawnSync("gh", ["auth", "status"], { encoding: "utf-8" });
|
|
448
|
+
if (auth.status !== 0) {
|
|
449
|
+
return { error: "GitHub CLI is not logged in. Run 'gh auth login' first." };
|
|
450
|
+
}
|
|
451
|
+
} catch {
|
|
452
|
+
return { error: "GitHub CLI (gh) is not installed." };
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
try {
|
|
456
|
+
const result = spawnSync("gh", ["gist", "create", htmlPath], { encoding: "utf-8" });
|
|
457
|
+
if (result.status !== 0) {
|
|
458
|
+
const err = (result.stderr || "").trim() || "Failed to create gist.";
|
|
459
|
+
return { error: err };
|
|
460
|
+
}
|
|
461
|
+
const gistUrl = (result.stdout || "").trim();
|
|
462
|
+
const gistId = gistUrl.split("/").pop();
|
|
463
|
+
if (!gistId) return { error: "Failed to parse gist ID." };
|
|
464
|
+
const shareUrl = `https://shittycodingagent.ai/session/?${gistId}`;
|
|
465
|
+
return { shareUrl, gistUrl };
|
|
466
|
+
} catch (err) {
|
|
467
|
+
return { error: String(err) };
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function formatDuration(ms: number): string {
|
|
472
|
+
if (ms < 1000) return `${ms}ms`;
|
|
473
|
+
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;
|
|
474
|
+
const minutes = Math.floor(ms / 60000);
|
|
475
|
+
const seconds = Math.floor((ms % 60000) / 1000);
|
|
476
|
+
return `${minutes}m${seconds}s`;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function writeRunLog(
|
|
480
|
+
logPath: string,
|
|
481
|
+
input: {
|
|
482
|
+
id: string;
|
|
483
|
+
mode: SubagentRunMode;
|
|
484
|
+
cwd: string;
|
|
485
|
+
startedAt: number;
|
|
486
|
+
endedAt: number;
|
|
487
|
+
steps: Array<{
|
|
488
|
+
agent: string;
|
|
489
|
+
status: string;
|
|
490
|
+
durationMs?: number;
|
|
491
|
+
}>;
|
|
492
|
+
summary: string;
|
|
493
|
+
truncated: boolean;
|
|
494
|
+
artifactsDir?: string;
|
|
495
|
+
sessionFile?: string;
|
|
496
|
+
shareUrl?: string;
|
|
497
|
+
shareError?: string;
|
|
498
|
+
},
|
|
499
|
+
): void {
|
|
500
|
+
const lines: string[] = [];
|
|
501
|
+
lines.push(`# Subagent run ${input.id}`);
|
|
502
|
+
lines.push("");
|
|
503
|
+
lines.push(`- **Mode:** ${input.mode}`);
|
|
504
|
+
lines.push(`- **CWD:** ${input.cwd}`);
|
|
505
|
+
lines.push(`- **Started:** ${new Date(input.startedAt).toISOString()}`);
|
|
506
|
+
lines.push(`- **Ended:** ${new Date(input.endedAt).toISOString()}`);
|
|
507
|
+
lines.push(`- **Duration:** ${formatDuration(input.endedAt - input.startedAt)}`);
|
|
508
|
+
if (input.sessionFile) lines.push(`- **Session:** ${input.sessionFile}`);
|
|
509
|
+
if (input.shareUrl) lines.push(`- **Share:** ${input.shareUrl}`);
|
|
510
|
+
if (input.shareError) lines.push(`- **Share error:** ${input.shareError}`);
|
|
511
|
+
if (input.artifactsDir) lines.push(`- **Artifacts:** ${input.artifactsDir}`);
|
|
512
|
+
lines.push("");
|
|
513
|
+
lines.push("## Steps");
|
|
514
|
+
lines.push("| Step | Agent | Status | Duration |");
|
|
515
|
+
lines.push("| --- | --- | --- | --- |");
|
|
516
|
+
input.steps.forEach((step, i) => {
|
|
517
|
+
const duration = step.durationMs !== undefined ? formatDuration(step.durationMs) : "-";
|
|
518
|
+
lines.push(`| ${i + 1} | ${step.agent} | ${step.status} | ${duration} |`);
|
|
519
|
+
});
|
|
520
|
+
lines.push("");
|
|
521
|
+
lines.push("## Summary");
|
|
522
|
+
if (input.truncated) {
|
|
523
|
+
lines.push("_Output truncated_");
|
|
524
|
+
lines.push("");
|
|
525
|
+
}
|
|
526
|
+
lines.push(input.summary.trim() || "(no output)");
|
|
527
|
+
lines.push("");
|
|
528
|
+
fs.writeFileSync(logPath, lines.join("\n"), "utf-8");
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** Context for running a single step */
|
|
532
|
+
interface SingleStepContext {
|
|
533
|
+
previousOutput: string;
|
|
534
|
+
placeholder: string;
|
|
535
|
+
cwd: string;
|
|
536
|
+
sessionEnabled: boolean;
|
|
537
|
+
sessionDir?: string;
|
|
538
|
+
artifactsDir?: string;
|
|
539
|
+
artifactConfig?: Partial<ArtifactConfig>;
|
|
540
|
+
id: string;
|
|
541
|
+
flatIndex: number;
|
|
542
|
+
flatStepCount: number;
|
|
543
|
+
outputFile: string;
|
|
544
|
+
piPackageRoot?: string;
|
|
545
|
+
piArgv1?: string;
|
|
546
|
+
registerInterrupt?: (interrupt: (() => void) | undefined) => void;
|
|
547
|
+
childIntercomTarget?: string;
|
|
548
|
+
orchestratorIntercomTarget?: string;
|
|
549
|
+
onAttemptStart?: (attempt: { model?: string; thinking?: string }) => void;
|
|
550
|
+
onChildEvent?: (event: ChildEvent) => void;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/** Run a single pi agent step, returning output and metadata */
|
|
554
|
+
async function runSingleStep(
|
|
555
|
+
step: SubagentStep,
|
|
556
|
+
ctx: SingleStepContext,
|
|
557
|
+
): Promise<{
|
|
558
|
+
agent: string;
|
|
559
|
+
output: string;
|
|
560
|
+
exitCode: number | null;
|
|
561
|
+
error?: string;
|
|
562
|
+
model?: string;
|
|
563
|
+
attemptedModels?: string[];
|
|
564
|
+
modelAttempts?: ModelAttempt[];
|
|
565
|
+
artifactPaths?: ArtifactPaths;
|
|
566
|
+
interrupted?: boolean;
|
|
567
|
+
sessionFile?: string;
|
|
568
|
+
intercomTarget?: string;
|
|
569
|
+
completionGuardTriggered?: boolean;
|
|
570
|
+
}> {
|
|
571
|
+
const placeholderRegex = new RegExp(ctx.placeholder.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g");
|
|
572
|
+
const task = step.task.replace(placeholderRegex, () => ctx.previousOutput);
|
|
573
|
+
const sessionEnabled = Boolean(step.sessionFile) || ctx.sessionEnabled;
|
|
574
|
+
const sessionDir = step.sessionFile ? undefined : ctx.sessionDir;
|
|
575
|
+
|
|
576
|
+
let artifactPaths: ArtifactPaths | undefined;
|
|
577
|
+
if (ctx.artifactsDir && ctx.artifactConfig?.enabled !== false) {
|
|
578
|
+
const index = ctx.flatStepCount > 1 ? ctx.flatIndex : undefined;
|
|
579
|
+
artifactPaths = getArtifactPaths(ctx.artifactsDir, ctx.id, step.agent, index);
|
|
580
|
+
fs.mkdirSync(ctx.artifactsDir, { recursive: true });
|
|
581
|
+
if (ctx.artifactConfig?.includeInput !== false) {
|
|
582
|
+
fs.writeFileSync(artifactPaths.inputPath, `# Task for ${step.agent}\n\n${task}`, "utf-8");
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
const candidates = step.modelCandidates && step.modelCandidates.length > 0
|
|
587
|
+
? step.modelCandidates
|
|
588
|
+
: step.model
|
|
589
|
+
? [step.model]
|
|
590
|
+
: [undefined];
|
|
591
|
+
const attemptedModels: string[] = [];
|
|
592
|
+
const modelAttempts: ModelAttempt[] = [];
|
|
593
|
+
const attemptNotes: string[] = [];
|
|
594
|
+
const eventsPath = path.join(path.dirname(ctx.outputFile), "events.jsonl");
|
|
595
|
+
let finalResult: RunPiStreamingResult | undefined;
|
|
596
|
+
let finalOutputSnapshot: SingleOutputSnapshot | undefined;
|
|
597
|
+
let completionGuardTriggeredFinal = false;
|
|
598
|
+
|
|
599
|
+
for (let index = 0; index < candidates.length; index++) {
|
|
600
|
+
const candidate = candidates[index];
|
|
601
|
+
ctx.onAttemptStart?.({ model: candidate, thinking: resolveEffectiveThinking(candidate, step.thinking) });
|
|
602
|
+
const outputSnapshot = captureSingleOutputSnapshot(step.outputPath);
|
|
603
|
+
const { args, env, tempDir } = buildPiArgs({
|
|
604
|
+
baseArgs: ["--mode", "json", "-p"],
|
|
605
|
+
task,
|
|
606
|
+
sessionEnabled,
|
|
607
|
+
sessionDir,
|
|
608
|
+
sessionFile: step.sessionFile,
|
|
609
|
+
model: candidate,
|
|
610
|
+
inheritProjectContext: step.inheritProjectContext,
|
|
611
|
+
inheritSkills: step.inheritSkills,
|
|
612
|
+
tools: step.tools,
|
|
613
|
+
extensions: step.extensions,
|
|
614
|
+
systemPrompt: step.systemPrompt,
|
|
615
|
+
systemPromptMode: step.systemPromptMode,
|
|
616
|
+
mcpDirectTools: step.mcpDirectTools,
|
|
617
|
+
promptFileStem: step.agent,
|
|
618
|
+
intercomSessionName: ctx.childIntercomTarget,
|
|
619
|
+
orchestratorIntercomTarget: ctx.orchestratorIntercomTarget,
|
|
620
|
+
runId: ctx.id,
|
|
621
|
+
childAgentName: step.agent,
|
|
622
|
+
childIndex: ctx.flatIndex,
|
|
623
|
+
});
|
|
624
|
+
const run = await runPiStreaming(
|
|
625
|
+
args,
|
|
626
|
+
step.cwd ?? ctx.cwd,
|
|
627
|
+
ctx.outputFile,
|
|
628
|
+
env,
|
|
629
|
+
ctx.piPackageRoot,
|
|
630
|
+
ctx.piArgv1,
|
|
631
|
+
step.maxSubagentDepth,
|
|
632
|
+
{ eventsPath, runId: ctx.id, stepIndex: ctx.flatIndex, agent: step.agent },
|
|
633
|
+
ctx.registerInterrupt,
|
|
634
|
+
ctx.onChildEvent,
|
|
635
|
+
);
|
|
636
|
+
cleanupTempDir(tempDir);
|
|
637
|
+
|
|
638
|
+
const hiddenError = run.exitCode === 0 && !run.error ? detectSubagentError(run.messages) : null;
|
|
639
|
+
const completionGuard = run.exitCode === 0 && !run.error && !hiddenError?.hasError
|
|
640
|
+
? evaluateCompletionMutationGuard({
|
|
641
|
+
agent: step.agent,
|
|
642
|
+
task,
|
|
643
|
+
messages: run.messages,
|
|
644
|
+
})
|
|
645
|
+
: undefined;
|
|
646
|
+
const completionGuardTriggered = completionGuard?.triggered === true && !run.observedMutationAttempt;
|
|
647
|
+
const completionGuardError = completionGuardTriggered
|
|
648
|
+
? "Subagent completed without making edits for an implementation task.\nIt appears to have returned planning or scratchpad output instead of applying changes."
|
|
649
|
+
: undefined;
|
|
650
|
+
const effectiveExitCode = completionGuardTriggered
|
|
651
|
+
? 1
|
|
652
|
+
: hiddenError?.hasError
|
|
653
|
+
? (hiddenError.exitCode ?? 1)
|
|
654
|
+
: run.error && run.exitCode === 0
|
|
655
|
+
? 1
|
|
656
|
+
: run.exitCode;
|
|
657
|
+
const error = completionGuardError
|
|
658
|
+
?? (hiddenError?.hasError
|
|
659
|
+
? hiddenError.details
|
|
660
|
+
? `${hiddenError.errorType} failed (exit ${effectiveExitCode}): ${hiddenError.details}`
|
|
661
|
+
: `${hiddenError.errorType} failed with exit code ${effectiveExitCode}`
|
|
662
|
+
: run.error || (run.exitCode !== 0 && run.stderr.trim() ? run.stderr.trim() : undefined));
|
|
663
|
+
const attempt: ModelAttempt = {
|
|
664
|
+
model: candidate ?? run.model ?? step.model ?? "default",
|
|
665
|
+
success: effectiveExitCode === 0 && !error,
|
|
666
|
+
exitCode: effectiveExitCode,
|
|
667
|
+
error,
|
|
668
|
+
usage: run.usage,
|
|
669
|
+
};
|
|
670
|
+
modelAttempts.push(attempt);
|
|
671
|
+
if (candidate) attemptedModels.push(candidate);
|
|
672
|
+
completionGuardTriggeredFinal = completionGuardTriggered;
|
|
673
|
+
finalOutputSnapshot = outputSnapshot;
|
|
674
|
+
finalResult = { ...run, exitCode: effectiveExitCode, model: candidate ?? run.model, error };
|
|
675
|
+
if (attempt.success || completionGuardTriggered) break;
|
|
676
|
+
if (!isRetryableModelFailure(error) || index === candidates.length - 1) break;
|
|
677
|
+
attemptNotes.push(formatModelAttemptNote(attempt, candidates[index + 1]));
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const rawOutput = finalResult?.finalOutput ?? "";
|
|
681
|
+
const resolvedOutput = step.outputPath && finalResult?.exitCode === 0
|
|
682
|
+
? resolveSingleOutput(step.outputPath, rawOutput, finalOutputSnapshot)
|
|
683
|
+
: { fullOutput: rawOutput };
|
|
684
|
+
const output = resolvedOutput.fullOutput;
|
|
685
|
+
const outputReference = resolvedOutput.savedPath ? formatSavedOutputReference(resolvedOutput.savedPath, output) : undefined;
|
|
686
|
+
let outputForSummary = output;
|
|
687
|
+
if (attemptNotes.length > 0) {
|
|
688
|
+
outputForSummary = `${attemptNotes.join("\n")}\n\n${outputForSummary}`.trim();
|
|
689
|
+
}
|
|
690
|
+
const finalizedOutput = finalizeSingleOutput({
|
|
691
|
+
fullOutput: outputForSummary,
|
|
692
|
+
outputPath: step.outputPath,
|
|
693
|
+
outputMode: step.outputMode,
|
|
694
|
+
exitCode: finalResult?.exitCode ?? 1,
|
|
695
|
+
savedPath: resolvedOutput.savedPath,
|
|
696
|
+
outputReference,
|
|
697
|
+
saveError: resolvedOutput.saveError,
|
|
698
|
+
});
|
|
699
|
+
outputForSummary = finalizedOutput.displayOutput;
|
|
700
|
+
|
|
701
|
+
if (artifactPaths && ctx.artifactConfig?.enabled !== false) {
|
|
702
|
+
if (ctx.artifactConfig?.includeOutput !== false) {
|
|
703
|
+
fs.writeFileSync(artifactPaths.outputPath, output, "utf-8");
|
|
704
|
+
}
|
|
705
|
+
if (ctx.artifactConfig?.includeMetadata !== false) {
|
|
706
|
+
fs.writeFileSync(
|
|
707
|
+
artifactPaths.metadataPath,
|
|
708
|
+
JSON.stringify({
|
|
709
|
+
runId: ctx.id,
|
|
710
|
+
agent: step.agent,
|
|
711
|
+
task,
|
|
712
|
+
exitCode: finalResult?.exitCode,
|
|
713
|
+
model: finalResult?.model,
|
|
714
|
+
attemptedModels: attemptedModels.length > 0 ? attemptedModels : undefined,
|
|
715
|
+
modelAttempts,
|
|
716
|
+
skills: step.skills,
|
|
717
|
+
timestamp: Date.now(),
|
|
718
|
+
}, null, 2),
|
|
719
|
+
"utf-8",
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
return {
|
|
725
|
+
agent: step.agent,
|
|
726
|
+
output: outputForSummary,
|
|
727
|
+
exitCode: finalResult?.exitCode ?? 1,
|
|
728
|
+
error: finalResult?.error,
|
|
729
|
+
sessionFile: step.sessionFile,
|
|
730
|
+
intercomTarget: ctx.childIntercomTarget,
|
|
731
|
+
model: finalResult?.model,
|
|
732
|
+
attemptedModels: attemptedModels.length > 0 ? attemptedModels : undefined,
|
|
733
|
+
modelAttempts,
|
|
734
|
+
artifactPaths,
|
|
735
|
+
interrupted: finalResult?.interrupted,
|
|
736
|
+
completionGuardTriggered: completionGuardTriggeredFinal,
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
type RunnerStatusStep = NonNullable<AsyncStatus["steps"]>[number] & {
|
|
741
|
+
exitCode?: number | null;
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
type RunnerStatusPayload = Omit<AsyncStatus, "steps" | "parallelGroups" | "pid" | "cwd" | "currentStep" | "chainStepCount" | "lastUpdate"> & {
|
|
745
|
+
pid: number;
|
|
746
|
+
cwd: string;
|
|
747
|
+
currentStep: number;
|
|
748
|
+
chainStepCount: number;
|
|
749
|
+
parallelGroups: AsyncParallelGroupStatus[];
|
|
750
|
+
steps: RunnerStatusStep[];
|
|
751
|
+
lastUpdate: number;
|
|
752
|
+
artifactsDir?: string;
|
|
753
|
+
shareUrl?: string;
|
|
754
|
+
gistUrl?: string;
|
|
755
|
+
shareError?: string;
|
|
756
|
+
error?: string;
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
function markParallelGroupSetupFailure(input: {
|
|
760
|
+
statusPayload: RunnerStatusPayload;
|
|
761
|
+
results: StepResult[];
|
|
762
|
+
group: Extract<RunnerStep, { parallel: SubagentStep[] }>;
|
|
763
|
+
groupStartFlatIndex: number;
|
|
764
|
+
setupError: string;
|
|
765
|
+
failedAt: number;
|
|
766
|
+
statusPath: string;
|
|
767
|
+
eventsPath: string;
|
|
768
|
+
asyncDir: string;
|
|
769
|
+
runId: string;
|
|
770
|
+
stepIndex: number;
|
|
771
|
+
}): void {
|
|
772
|
+
for (let taskIndex = 0; taskIndex < input.group.parallel.length; taskIndex++) {
|
|
773
|
+
const flatTaskIndex = input.groupStartFlatIndex + taskIndex;
|
|
774
|
+
input.statusPayload.steps[flatTaskIndex].status = "failed";
|
|
775
|
+
input.statusPayload.steps[flatTaskIndex].startedAt = input.failedAt;
|
|
776
|
+
input.statusPayload.steps[flatTaskIndex].endedAt = input.failedAt;
|
|
777
|
+
input.statusPayload.steps[flatTaskIndex].durationMs = 0;
|
|
778
|
+
input.statusPayload.steps[flatTaskIndex].exitCode = 1;
|
|
779
|
+
input.results.push({ agent: input.group.parallel[taskIndex].agent, output: input.setupError, success: false, sessionFile: input.group.parallel[taskIndex].sessionFile });
|
|
780
|
+
}
|
|
781
|
+
input.statusPayload.currentStep = input.groupStartFlatIndex;
|
|
782
|
+
input.statusPayload.lastUpdate = input.failedAt;
|
|
783
|
+
input.statusPayload.outputFile = path.join(input.asyncDir, `output-${input.groupStartFlatIndex}.log`);
|
|
784
|
+
writeAtomicJson(input.statusPath, input.statusPayload);
|
|
785
|
+
appendJsonl(input.eventsPath, JSON.stringify({
|
|
786
|
+
type: "subagent.parallel.completed",
|
|
787
|
+
ts: input.failedAt,
|
|
788
|
+
runId: input.runId,
|
|
789
|
+
stepIndex: input.stepIndex,
|
|
790
|
+
success: false,
|
|
791
|
+
}));
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
function markParallelGroupRunning(input: {
|
|
795
|
+
statusPayload: RunnerStatusPayload;
|
|
796
|
+
group: Extract<RunnerStep, { parallel: SubagentStep[] }>;
|
|
797
|
+
groupStartFlatIndex: number;
|
|
798
|
+
groupStartTime: number;
|
|
799
|
+
statusPath: string;
|
|
800
|
+
eventsPath: string;
|
|
801
|
+
asyncDir: string;
|
|
802
|
+
runId: string;
|
|
803
|
+
stepIndex: number;
|
|
804
|
+
}): void {
|
|
805
|
+
for (let taskIndex = 0; taskIndex < input.group.parallel.length; taskIndex++) {
|
|
806
|
+
const flatTaskIndex = input.groupStartFlatIndex + taskIndex;
|
|
807
|
+
input.statusPayload.steps[flatTaskIndex].status = "pending";
|
|
808
|
+
input.statusPayload.steps[flatTaskIndex].startedAt = undefined;
|
|
809
|
+
input.statusPayload.steps[flatTaskIndex].endedAt = undefined;
|
|
810
|
+
input.statusPayload.steps[flatTaskIndex].durationMs = undefined;
|
|
811
|
+
input.statusPayload.steps[flatTaskIndex].lastActivityAt = undefined;
|
|
812
|
+
input.statusPayload.steps[flatTaskIndex].activityState = undefined;
|
|
813
|
+
input.statusPayload.steps[flatTaskIndex].error = undefined;
|
|
814
|
+
}
|
|
815
|
+
input.statusPayload.currentStep = input.groupStartFlatIndex;
|
|
816
|
+
input.statusPayload.activityState = undefined;
|
|
817
|
+
input.statusPayload.lastActivityAt = input.groupStartTime;
|
|
818
|
+
input.statusPayload.lastUpdate = input.groupStartTime;
|
|
819
|
+
input.statusPayload.outputFile = path.join(input.asyncDir, `output-${input.groupStartFlatIndex}.log`);
|
|
820
|
+
writeAtomicJson(input.statusPath, input.statusPayload);
|
|
821
|
+
appendJsonl(input.eventsPath, JSON.stringify({
|
|
822
|
+
type: "subagent.parallel.started",
|
|
823
|
+
ts: input.groupStartTime,
|
|
824
|
+
runId: input.runId,
|
|
825
|
+
stepIndex: input.stepIndex,
|
|
826
|
+
agents: input.group.parallel.map((task) => task.agent),
|
|
827
|
+
count: input.group.parallel.length,
|
|
828
|
+
}));
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function prepareParallelTaskRun(
|
|
832
|
+
task: SubagentStep,
|
|
833
|
+
cwd: string,
|
|
834
|
+
worktreeSetup: WorktreeSetup | undefined,
|
|
835
|
+
taskIndex: number,
|
|
836
|
+
): { taskForRun: SubagentStep; taskCwd: string } {
|
|
837
|
+
if (!worktreeSetup) return { taskForRun: task, taskCwd: cwd };
|
|
838
|
+
return {
|
|
839
|
+
taskForRun: { ...task, cwd: undefined },
|
|
840
|
+
taskCwd: worktreeSetup.worktrees[taskIndex]!.agentCwd,
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
function appendParallelWorktreeSummary(
|
|
845
|
+
previousOutput: string,
|
|
846
|
+
worktreeSetup: WorktreeSetup | undefined,
|
|
847
|
+
asyncDir: string,
|
|
848
|
+
stepIndex: number,
|
|
849
|
+
group: Extract<RunnerStep, { parallel: SubagentStep[] }>,
|
|
850
|
+
): string {
|
|
851
|
+
if (!worktreeSetup) return previousOutput;
|
|
852
|
+
const diffsDir = path.join(asyncDir, "worktree-diffs", `step-${stepIndex}`);
|
|
853
|
+
const diffs = diffWorktrees(worktreeSetup, group.parallel.map((task) => task.agent), diffsDir);
|
|
854
|
+
const diffSummary = formatWorktreeDiffSummary(diffs);
|
|
855
|
+
if (!diffSummary) return previousOutput;
|
|
856
|
+
return `${previousOutput}\n\n${diffSummary}`;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
function ensureParallelProgressFile(cwd: string, group: Extract<RunnerStep, { parallel: SubagentStep[] }>): void {
|
|
860
|
+
const progressPath = path.join(cwd, "progress.md");
|
|
861
|
+
if (!group.parallel.some((task) => task.task.includes(`Update progress at: ${progressPath}`))) return;
|
|
862
|
+
writeInitialProgressFile(cwd);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
async function runSubagent(config: SubagentRunConfig): Promise<void> {
|
|
866
|
+
const { id, steps, resultPath, cwd, placeholder, taskIndex, totalTasks, maxOutput, artifactsDir, artifactConfig } =
|
|
867
|
+
config;
|
|
868
|
+
let previousOutput = "";
|
|
869
|
+
const results: StepResult[] = [];
|
|
870
|
+
const overallStartTime = Date.now();
|
|
871
|
+
const shareEnabled = config.share === true;
|
|
872
|
+
const asyncDir = config.asyncDir;
|
|
873
|
+
const statusPath = path.join(asyncDir, "status.json");
|
|
874
|
+
const eventsPath = path.join(asyncDir, "events.jsonl");
|
|
875
|
+
const logPath = path.join(asyncDir, `subagent-log-${id}.md`);
|
|
876
|
+
const controlConfig = config.controlConfig ?? DEFAULT_CONTROL_CONFIG;
|
|
877
|
+
let activeChildInterrupt: (() => void) | undefined;
|
|
878
|
+
let interrupted = false;
|
|
879
|
+
let currentActivityState: ActivityState | undefined;
|
|
880
|
+
let activityTimer: NodeJS.Timeout | undefined;
|
|
881
|
+
let previousCumulativeTokens: TokenUsage = { input: 0, output: 0, total: 0 };
|
|
882
|
+
let latestSessionFile: string | undefined;
|
|
883
|
+
|
|
884
|
+
const parallelGroups: Array<{ start: number; count: number; stepIndex: number }> = [];
|
|
885
|
+
let flatStepCount = 0;
|
|
886
|
+
for (let stepIndex = 0; stepIndex < steps.length; stepIndex++) {
|
|
887
|
+
const step = steps[stepIndex]!;
|
|
888
|
+
if (isParallelGroup(step)) {
|
|
889
|
+
parallelGroups.push({ start: flatStepCount, count: step.parallel.length, stepIndex });
|
|
890
|
+
flatStepCount += step.parallel.length;
|
|
891
|
+
} else {
|
|
892
|
+
flatStepCount++;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
const flatSteps = flattenSteps(steps);
|
|
896
|
+
const sessionEnabled = Boolean(config.sessionDir)
|
|
897
|
+
|| shareEnabled
|
|
898
|
+
|| flatSteps.some((step) => Boolean(step.sessionFile));
|
|
899
|
+
const statusPayload: RunnerStatusPayload = {
|
|
900
|
+
runId: id,
|
|
901
|
+
...(config.sessionId ? { sessionId: config.sessionId } : {}),
|
|
902
|
+
mode: config.resultMode ?? (flatSteps.length > 1 ? "chain" : "single"),
|
|
903
|
+
state: "running",
|
|
904
|
+
lastActivityAt: overallStartTime,
|
|
905
|
+
startedAt: overallStartTime,
|
|
906
|
+
lastUpdate: overallStartTime,
|
|
907
|
+
pid: process.pid,
|
|
908
|
+
cwd,
|
|
909
|
+
currentStep: 0,
|
|
910
|
+
chainStepCount: steps.length,
|
|
911
|
+
parallelGroups,
|
|
912
|
+
steps: flatSteps.map((step) => ({
|
|
913
|
+
agent: step.agent,
|
|
914
|
+
status: "pending",
|
|
915
|
+
...(step.sessionFile ? { sessionFile: step.sessionFile } : {}),
|
|
916
|
+
skills: step.skills,
|
|
917
|
+
model: step.model,
|
|
918
|
+
thinking: step.thinking,
|
|
919
|
+
attemptedModels: step.modelCandidates && step.modelCandidates.length > 0 ? step.modelCandidates : step.model ? [step.model] : undefined,
|
|
920
|
+
recentTools: [],
|
|
921
|
+
recentOutput: [],
|
|
922
|
+
})),
|
|
923
|
+
artifactsDir,
|
|
924
|
+
sessionDir: config.sessionDir,
|
|
925
|
+
outputFile: path.join(asyncDir, "output-0.log"),
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
929
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
930
|
+
|
|
931
|
+
const stepOutputActivityAt = (index: number): number => {
|
|
932
|
+
const step = statusPayload.steps[index];
|
|
933
|
+
let lastActivityAt = step?.lastActivityAt ?? step?.startedAt ?? overallStartTime;
|
|
934
|
+
const outputPath = path.join(asyncDir, `output-${index}.log`);
|
|
935
|
+
try {
|
|
936
|
+
lastActivityAt = Math.max(lastActivityAt, fs.statSync(outputPath).mtimeMs);
|
|
937
|
+
} catch (error) {
|
|
938
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
|
|
939
|
+
console.error(`Failed to inspect async output file '${outputPath}':`, error);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
return lastActivityAt;
|
|
943
|
+
};
|
|
944
|
+
const emittedControlEventKeys = new Set<string>();
|
|
945
|
+
const activeLongRunningSteps = new Set<number>();
|
|
946
|
+
const mutatingFailureStates = flatSteps.map(() => createMutatingFailureState());
|
|
947
|
+
const pendingToolResults: Array<{ tool: string; path?: string; mutates: boolean; startedAt?: number } | undefined> = [];
|
|
948
|
+
const mutatingFailureWindowMs = 5 * 60_000;
|
|
949
|
+
const appendControlEvent = (event: ReturnType<typeof buildControlEvent>) => {
|
|
950
|
+
if (!controlConfig.enabled) return;
|
|
951
|
+
const childIntercomTarget = config.childIntercomTargets?.[event.index ?? statusPayload.currentStep];
|
|
952
|
+
const channels = event.type === "active_long_running"
|
|
953
|
+
? controlConfig.notifyChannels.filter((channel) => channel !== "intercom")
|
|
954
|
+
: controlConfig.notifyChannels;
|
|
955
|
+
if (channels.length === 0 || !claimControlNotification(controlConfig, event, emittedControlEventKeys, childIntercomTarget)) return;
|
|
956
|
+
appendJsonl(eventsPath, JSON.stringify({
|
|
957
|
+
type: "subagent.control",
|
|
958
|
+
event,
|
|
959
|
+
channels,
|
|
960
|
+
childIntercomTarget,
|
|
961
|
+
noticeText: formatControlNoticeMessage(event, childIntercomTarget),
|
|
962
|
+
...(config.controlIntercomTarget && channels.includes("intercom") ? {
|
|
963
|
+
intercom: {
|
|
964
|
+
to: config.controlIntercomTarget,
|
|
965
|
+
message: formatControlIntercomMessage(event, childIntercomTarget),
|
|
966
|
+
},
|
|
967
|
+
} : {}),
|
|
968
|
+
}));
|
|
969
|
+
};
|
|
970
|
+
const syncTopLevelCurrentTool = (): void => {
|
|
971
|
+
const activeStep = statusPayload.steps
|
|
972
|
+
.filter((step) => step.status === "running" && typeof step.currentTool === "string" && step.currentTool.length > 0)
|
|
973
|
+
.sort((left, right) => (right.currentToolStartedAt ?? 0) - (left.currentToolStartedAt ?? 0))[0];
|
|
974
|
+
statusPayload.currentTool = activeStep?.currentTool;
|
|
975
|
+
statusPayload.currentToolStartedAt = activeStep?.currentToolStartedAt;
|
|
976
|
+
statusPayload.currentPath = activeStep?.currentPath;
|
|
977
|
+
};
|
|
978
|
+
const maybeEmitActiveLongRunning = (flatIndex: number, now: number): boolean => {
|
|
979
|
+
if (!controlConfig.enabled || activeLongRunningSteps.has(flatIndex)) return false;
|
|
980
|
+
const step = statusPayload.steps[flatIndex];
|
|
981
|
+
if (!step || step.status !== "running" || step.activityState === "needs_attention") return false;
|
|
982
|
+
const reason = nextLongRunningTrigger(controlConfig, {
|
|
983
|
+
startedAt: step.startedAt ?? overallStartTime,
|
|
984
|
+
now,
|
|
985
|
+
turns: step.turnCount ?? 0,
|
|
986
|
+
tokens: step.tokens?.total ?? 0,
|
|
987
|
+
});
|
|
988
|
+
if (!reason) return false;
|
|
989
|
+
activeLongRunningSteps.add(flatIndex);
|
|
990
|
+
const previous = step.activityState;
|
|
991
|
+
step.activityState = "active_long_running";
|
|
992
|
+
statusPayload.activityState = statusPayload.activityState === "needs_attention" ? "needs_attention" : "active_long_running";
|
|
993
|
+
const event = buildControlEvent({
|
|
994
|
+
type: "active_long_running",
|
|
995
|
+
from: previous,
|
|
996
|
+
to: "active_long_running",
|
|
997
|
+
runId: id,
|
|
998
|
+
agent: step.agent,
|
|
999
|
+
index: flatIndex,
|
|
1000
|
+
ts: now,
|
|
1001
|
+
message: `${step.agent} is still active but long-running`,
|
|
1002
|
+
reason,
|
|
1003
|
+
turns: step.turnCount,
|
|
1004
|
+
tokens: step.tokens?.total,
|
|
1005
|
+
toolCount: step.toolCount,
|
|
1006
|
+
currentTool: step.currentTool,
|
|
1007
|
+
currentToolDurationMs: step.currentToolStartedAt ? Math.max(0, now - step.currentToolStartedAt) : undefined,
|
|
1008
|
+
currentPath: step.currentPath,
|
|
1009
|
+
elapsedMs: now - (step.startedAt ?? overallStartTime),
|
|
1010
|
+
});
|
|
1011
|
+
appendControlEvent(event);
|
|
1012
|
+
return true;
|
|
1013
|
+
};
|
|
1014
|
+
const updateStepModel = (flatIndex: number, model: string | undefined, thinking: string | undefined, now = Date.now()): void => {
|
|
1015
|
+
const step = statusPayload.steps[flatIndex];
|
|
1016
|
+
if (!step) return;
|
|
1017
|
+
step.model = model;
|
|
1018
|
+
step.thinking = thinking;
|
|
1019
|
+
statusPayload.lastUpdate = now;
|
|
1020
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1021
|
+
};
|
|
1022
|
+
const updateStepFromChildEvent = (flatIndex: number, event: ChildEvent): void => {
|
|
1023
|
+
const step = statusPayload.steps[flatIndex];
|
|
1024
|
+
if (!step) return;
|
|
1025
|
+
const now = Date.now();
|
|
1026
|
+
statusPayload.currentStep = flatIndex;
|
|
1027
|
+
if (event.type === "tool_execution_start" && event.toolName) {
|
|
1028
|
+
const mutates = isMutatingTool(event.toolName, event.args);
|
|
1029
|
+
const currentPath = resolveCurrentPath(event.toolName, event.args);
|
|
1030
|
+
step.toolCount = (step.toolCount ?? 0) + 1;
|
|
1031
|
+
step.currentTool = event.toolName;
|
|
1032
|
+
step.currentToolArgs = extractToolArgsPreview(event.args ?? {});
|
|
1033
|
+
step.currentToolStartedAt = now;
|
|
1034
|
+
step.currentPath = currentPath;
|
|
1035
|
+
pendingToolResults[flatIndex] = { tool: event.toolName, path: currentPath, mutates, startedAt: now };
|
|
1036
|
+
statusPayload.toolCount = (statusPayload.toolCount ?? 0) + 1;
|
|
1037
|
+
syncTopLevelCurrentTool();
|
|
1038
|
+
} else if (event.type === "tool_execution_end") {
|
|
1039
|
+
if (step.currentTool) {
|
|
1040
|
+
step.recentTools ??= [];
|
|
1041
|
+
step.recentTools.push({ tool: step.currentTool, args: step.currentToolArgs || "", endMs: now });
|
|
1042
|
+
}
|
|
1043
|
+
step.currentTool = undefined;
|
|
1044
|
+
step.currentToolArgs = undefined;
|
|
1045
|
+
step.currentToolStartedAt = undefined;
|
|
1046
|
+
step.currentPath = undefined;
|
|
1047
|
+
syncTopLevelCurrentTool();
|
|
1048
|
+
} else if (event.type === "tool_result_end" && event.message) {
|
|
1049
|
+
const toolSnapshot = pendingToolResults[flatIndex];
|
|
1050
|
+
pendingToolResults[flatIndex] = undefined;
|
|
1051
|
+
const resultText = extractTextFromContent(event.message.content);
|
|
1052
|
+
appendRecentStepOutput(step, resultText.split("\n").slice(-10));
|
|
1053
|
+
if (toolSnapshot?.mutates && didMutatingToolFail(resultText)) {
|
|
1054
|
+
const state = mutatingFailureStates[flatIndex]!;
|
|
1055
|
+
recordMutatingFailure(state, {
|
|
1056
|
+
tool: toolSnapshot.tool,
|
|
1057
|
+
path: toolSnapshot.path,
|
|
1058
|
+
error: resultText.split("\n").find((line) => line.trim())?.trim().slice(0, 180) ?? "mutating tool failed",
|
|
1059
|
+
ts: now,
|
|
1060
|
+
}, mutatingFailureWindowMs);
|
|
1061
|
+
if (controlConfig.enabled && shouldEscalateMutatingFailures(state, controlConfig.failedToolAttemptsBeforeAttention) && step.activityState !== "needs_attention") {
|
|
1062
|
+
const previous = step.activityState;
|
|
1063
|
+
step.activityState = "needs_attention";
|
|
1064
|
+
statusPayload.activityState = "needs_attention";
|
|
1065
|
+
appendControlEvent(buildControlEvent({
|
|
1066
|
+
type: "needs_attention",
|
|
1067
|
+
from: previous,
|
|
1068
|
+
to: "needs_attention",
|
|
1069
|
+
runId: id,
|
|
1070
|
+
agent: step.agent,
|
|
1071
|
+
index: flatIndex,
|
|
1072
|
+
ts: now,
|
|
1073
|
+
message: `${step.agent} needs attention after repeated mutating tool failures`,
|
|
1074
|
+
reason: "tool_failures",
|
|
1075
|
+
turns: step.turnCount,
|
|
1076
|
+
tokens: step.tokens?.total,
|
|
1077
|
+
toolCount: step.toolCount,
|
|
1078
|
+
currentTool: toolSnapshot.tool,
|
|
1079
|
+
currentToolDurationMs: toolSnapshot.startedAt ? Math.max(0, now - toolSnapshot.startedAt) : undefined,
|
|
1080
|
+
currentPath: toolSnapshot.path,
|
|
1081
|
+
recentFailureSummary: summarizeRecentMutatingFailures(state),
|
|
1082
|
+
}));
|
|
1083
|
+
}
|
|
1084
|
+
} else if (toolSnapshot?.mutates) {
|
|
1085
|
+
resetMutatingFailureState(mutatingFailureStates[flatIndex]!);
|
|
1086
|
+
}
|
|
1087
|
+
} else if (event.type === "message_end" && event.message?.role === "assistant") {
|
|
1088
|
+
appendRecentStepOutput(step, extractTextFromContent(event.message.content).split("\n").slice(-10));
|
|
1089
|
+
step.turnCount = (step.turnCount ?? 0) + 1;
|
|
1090
|
+
const usage = event.message.usage;
|
|
1091
|
+
if (usage) {
|
|
1092
|
+
const input = usage.input ?? usage.inputTokens ?? 0;
|
|
1093
|
+
const output = usage.output ?? usage.outputTokens ?? 0;
|
|
1094
|
+
const previousInput = step.tokens?.input ?? 0;
|
|
1095
|
+
const previousOutput = step.tokens?.output ?? 0;
|
|
1096
|
+
step.tokens = { input: previousInput + input, output: previousOutput + output, total: previousInput + previousOutput + input + output };
|
|
1097
|
+
const totalInput = statusPayload.totalTokens?.input ?? 0;
|
|
1098
|
+
const totalOutput = statusPayload.totalTokens?.output ?? 0;
|
|
1099
|
+
statusPayload.totalTokens = { input: totalInput + input, output: totalOutput + output, total: totalInput + totalOutput + input + output };
|
|
1100
|
+
}
|
|
1101
|
+
statusPayload.turnCount = Math.max(statusPayload.turnCount ?? 0, step.turnCount);
|
|
1102
|
+
}
|
|
1103
|
+
syncTopLevelCurrentTool();
|
|
1104
|
+
step.lastActivityAt = now;
|
|
1105
|
+
statusPayload.lastActivityAt = now;
|
|
1106
|
+
statusPayload.lastUpdate = now;
|
|
1107
|
+
maybeEmitActiveLongRunning(flatIndex, now);
|
|
1108
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1109
|
+
};
|
|
1110
|
+
const updateRunnerActivityState = (now: number): boolean => {
|
|
1111
|
+
if (!controlConfig.enabled) return false;
|
|
1112
|
+
let changed = false;
|
|
1113
|
+
let runLastActivityAt = statusPayload.lastActivityAt ?? overallStartTime;
|
|
1114
|
+
for (let index = 0; index < statusPayload.steps.length; index++) {
|
|
1115
|
+
const step = statusPayload.steps[index]!;
|
|
1116
|
+
if (step.status !== "running") continue;
|
|
1117
|
+
const lastActivityAt = stepOutputActivityAt(index);
|
|
1118
|
+
runLastActivityAt = Math.max(runLastActivityAt, lastActivityAt);
|
|
1119
|
+
if (step.lastActivityAt !== lastActivityAt) {
|
|
1120
|
+
step.lastActivityAt = lastActivityAt;
|
|
1121
|
+
changed = true;
|
|
1122
|
+
}
|
|
1123
|
+
const idleState = deriveActivityState({
|
|
1124
|
+
config: controlConfig,
|
|
1125
|
+
startedAt: step.startedAt ?? overallStartTime,
|
|
1126
|
+
lastActivityAt,
|
|
1127
|
+
now,
|
|
1128
|
+
});
|
|
1129
|
+
if (idleState === "needs_attention") {
|
|
1130
|
+
const previous = step.activityState;
|
|
1131
|
+
step.activityState = "needs_attention";
|
|
1132
|
+
if (previous !== "needs_attention") {
|
|
1133
|
+
appendControlEvent(buildControlEvent({
|
|
1134
|
+
from: previous,
|
|
1135
|
+
to: "needs_attention",
|
|
1136
|
+
runId: id,
|
|
1137
|
+
agent: step.agent,
|
|
1138
|
+
index,
|
|
1139
|
+
ts: now,
|
|
1140
|
+
lastActivityAt,
|
|
1141
|
+
}));
|
|
1142
|
+
changed = true;
|
|
1143
|
+
}
|
|
1144
|
+
} else if (maybeEmitActiveLongRunning(index, now)) {
|
|
1145
|
+
changed = true;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (statusPayload.lastActivityAt !== runLastActivityAt) {
|
|
1149
|
+
statusPayload.lastActivityAt = runLastActivityAt;
|
|
1150
|
+
changed = true;
|
|
1151
|
+
}
|
|
1152
|
+
const nextRunState = statusPayload.steps.some((step) => step.activityState === "needs_attention")
|
|
1153
|
+
? "needs_attention"
|
|
1154
|
+
: statusPayload.steps.some((step) => step.activityState === "active_long_running")
|
|
1155
|
+
? "active_long_running"
|
|
1156
|
+
: undefined;
|
|
1157
|
+
if (nextRunState !== currentActivityState) {
|
|
1158
|
+
currentActivityState = nextRunState;
|
|
1159
|
+
statusPayload.activityState = nextRunState;
|
|
1160
|
+
changed = true;
|
|
1161
|
+
}
|
|
1162
|
+
statusPayload.lastUpdate = now;
|
|
1163
|
+
if (changed) writeAtomicJson(statusPath, statusPayload);
|
|
1164
|
+
return changed;
|
|
1165
|
+
};
|
|
1166
|
+
if (controlConfig.enabled) {
|
|
1167
|
+
activityTimer = setInterval(() => {
|
|
1168
|
+
if (statusPayload.state !== "running") return;
|
|
1169
|
+
const now = Date.now();
|
|
1170
|
+
updateRunnerActivityState(now);
|
|
1171
|
+
}, 1000);
|
|
1172
|
+
activityTimer.unref?.();
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
const interruptRunner = () => {
|
|
1176
|
+
if (interrupted || statusPayload.state !== "running") return;
|
|
1177
|
+
interrupted = true;
|
|
1178
|
+
const now = Date.now();
|
|
1179
|
+
statusPayload.state = "paused";
|
|
1180
|
+
currentActivityState = undefined;
|
|
1181
|
+
statusPayload.activityState = undefined;
|
|
1182
|
+
statusPayload.lastUpdate = now;
|
|
1183
|
+
for (const step of statusPayload.steps) {
|
|
1184
|
+
if (step.status === "running") {
|
|
1185
|
+
step.status = "paused";
|
|
1186
|
+
step.activityState = undefined;
|
|
1187
|
+
step.endedAt = now;
|
|
1188
|
+
step.durationMs = step.startedAt ? now - step.startedAt : undefined;
|
|
1189
|
+
step.lastActivityAt = now;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1193
|
+
appendJsonl(eventsPath, JSON.stringify({
|
|
1194
|
+
type: "subagent.run.paused",
|
|
1195
|
+
ts: now,
|
|
1196
|
+
runId: id,
|
|
1197
|
+
}));
|
|
1198
|
+
activeChildInterrupt?.();
|
|
1199
|
+
};
|
|
1200
|
+
process.on(ASYNC_INTERRUPT_SIGNAL, interruptRunner);
|
|
1201
|
+
appendJsonl(
|
|
1202
|
+
eventsPath,
|
|
1203
|
+
JSON.stringify({
|
|
1204
|
+
type: "subagent.run.started",
|
|
1205
|
+
ts: overallStartTime,
|
|
1206
|
+
runId: id,
|
|
1207
|
+
mode: statusPayload.mode,
|
|
1208
|
+
cwd,
|
|
1209
|
+
pid: process.pid,
|
|
1210
|
+
}),
|
|
1211
|
+
);
|
|
1212
|
+
|
|
1213
|
+
let flatIndex = 0;
|
|
1214
|
+
|
|
1215
|
+
for (let stepIndex = 0; stepIndex < steps.length; stepIndex++) {
|
|
1216
|
+
if (interrupted) break;
|
|
1217
|
+
const step = steps[stepIndex];
|
|
1218
|
+
|
|
1219
|
+
if (isParallelGroup(step)) {
|
|
1220
|
+
const group = step;
|
|
1221
|
+
const concurrency = group.concurrency ?? MAX_PARALLEL_CONCURRENCY;
|
|
1222
|
+
const failFast = group.failFast ?? false;
|
|
1223
|
+
const groupStartFlatIndex = flatIndex;
|
|
1224
|
+
let aborted = false;
|
|
1225
|
+
let worktreeSetup: WorktreeSetup | undefined;
|
|
1226
|
+
if (group.worktree) {
|
|
1227
|
+
const worktreeTaskCwdConflict = findWorktreeTaskCwdConflict(group.parallel, cwd);
|
|
1228
|
+
if (worktreeTaskCwdConflict) {
|
|
1229
|
+
const failedAt = Date.now();
|
|
1230
|
+
markParallelGroupSetupFailure({
|
|
1231
|
+
statusPayload,
|
|
1232
|
+
results,
|
|
1233
|
+
group,
|
|
1234
|
+
groupStartFlatIndex,
|
|
1235
|
+
setupError: formatWorktreeTaskCwdConflict(worktreeTaskCwdConflict, cwd),
|
|
1236
|
+
failedAt,
|
|
1237
|
+
statusPath,
|
|
1238
|
+
eventsPath,
|
|
1239
|
+
asyncDir,
|
|
1240
|
+
runId: id,
|
|
1241
|
+
stepIndex,
|
|
1242
|
+
});
|
|
1243
|
+
flatIndex += group.parallel.length;
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1246
|
+
try {
|
|
1247
|
+
worktreeSetup = createWorktrees(cwd, `${id}-s${stepIndex}`, group.parallel.length, {
|
|
1248
|
+
agents: group.parallel.map((task) => task.agent),
|
|
1249
|
+
setupHook: config.worktreeSetupHook
|
|
1250
|
+
? { hookPath: config.worktreeSetupHook, timeoutMs: config.worktreeSetupHookTimeoutMs }
|
|
1251
|
+
: undefined,
|
|
1252
|
+
});
|
|
1253
|
+
} catch (error) {
|
|
1254
|
+
const setupError = error instanceof Error ? error.message : String(error);
|
|
1255
|
+
const failedAt = Date.now();
|
|
1256
|
+
markParallelGroupSetupFailure({
|
|
1257
|
+
statusPayload,
|
|
1258
|
+
results,
|
|
1259
|
+
group,
|
|
1260
|
+
groupStartFlatIndex,
|
|
1261
|
+
setupError,
|
|
1262
|
+
failedAt,
|
|
1263
|
+
statusPath,
|
|
1264
|
+
eventsPath,
|
|
1265
|
+
asyncDir,
|
|
1266
|
+
runId: id,
|
|
1267
|
+
stepIndex,
|
|
1268
|
+
});
|
|
1269
|
+
flatIndex += group.parallel.length;
|
|
1270
|
+
break;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
try {
|
|
1275
|
+
if (group.worktree) ensureParallelProgressFile(cwd, group);
|
|
1276
|
+
const groupStartTime = Date.now();
|
|
1277
|
+
markParallelGroupRunning({
|
|
1278
|
+
statusPayload,
|
|
1279
|
+
group,
|
|
1280
|
+
groupStartFlatIndex,
|
|
1281
|
+
groupStartTime,
|
|
1282
|
+
statusPath,
|
|
1283
|
+
eventsPath,
|
|
1284
|
+
asyncDir,
|
|
1285
|
+
runId: id,
|
|
1286
|
+
stepIndex,
|
|
1287
|
+
});
|
|
1288
|
+
const parallelResults = await mapConcurrent(
|
|
1289
|
+
group.parallel,
|
|
1290
|
+
concurrency,
|
|
1291
|
+
async (task, taskIdx) => {
|
|
1292
|
+
const fi = groupStartFlatIndex + taskIdx;
|
|
1293
|
+
if (aborted && failFast) {
|
|
1294
|
+
const skippedAt = Date.now();
|
|
1295
|
+
statusPayload.steps[fi].status = "failed";
|
|
1296
|
+
statusPayload.steps[fi].error = "Skipped due to fail-fast";
|
|
1297
|
+
statusPayload.steps[fi].startedAt = skippedAt;
|
|
1298
|
+
statusPayload.steps[fi].endedAt = skippedAt;
|
|
1299
|
+
statusPayload.steps[fi].durationMs = 0;
|
|
1300
|
+
statusPayload.steps[fi].exitCode = -1;
|
|
1301
|
+
statusPayload.steps[fi].activityState = undefined;
|
|
1302
|
+
statusPayload.lastUpdate = skippedAt;
|
|
1303
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1304
|
+
appendJsonl(eventsPath, JSON.stringify({
|
|
1305
|
+
type: "subagent.step.failed", ts: skippedAt, runId: id, stepIndex: fi, agent: task.agent, exitCode: -1, durationMs: 0,
|
|
1306
|
+
}));
|
|
1307
|
+
return { agent: task.agent, output: "(skipped — fail-fast)", exitCode: -1 as number | null, skipped: true };
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
const taskStartTime = Date.now();
|
|
1311
|
+
statusPayload.currentStep = fi;
|
|
1312
|
+
statusPayload.steps[fi].status = "running";
|
|
1313
|
+
statusPayload.steps[fi].error = undefined;
|
|
1314
|
+
statusPayload.steps[fi].activityState = undefined;
|
|
1315
|
+
resetStepLiveDetail(statusPayload.steps[fi]);
|
|
1316
|
+
statusPayload.steps[fi].startedAt = taskStartTime;
|
|
1317
|
+
statusPayload.steps[fi].endedAt = undefined;
|
|
1318
|
+
statusPayload.steps[fi].durationMs = undefined;
|
|
1319
|
+
statusPayload.steps[fi].lastActivityAt = taskStartTime;
|
|
1320
|
+
statusPayload.outputFile = path.join(asyncDir, `output-${fi}.log`);
|
|
1321
|
+
statusPayload.lastActivityAt = taskStartTime;
|
|
1322
|
+
statusPayload.lastUpdate = taskStartTime;
|
|
1323
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1324
|
+
|
|
1325
|
+
appendJsonl(eventsPath, JSON.stringify({
|
|
1326
|
+
type: "subagent.step.started", ts: taskStartTime, runId: id, stepIndex: fi, agent: task.agent,
|
|
1327
|
+
}));
|
|
1328
|
+
|
|
1329
|
+
const taskSessionDir = config.sessionDir
|
|
1330
|
+
? path.join(config.sessionDir, `parallel-${taskIdx}`)
|
|
1331
|
+
: undefined;
|
|
1332
|
+
const { taskForRun, taskCwd } = prepareParallelTaskRun(task, cwd, worktreeSetup, taskIdx);
|
|
1333
|
+
|
|
1334
|
+
const singleResult = await runSingleStep(taskForRun, {
|
|
1335
|
+
previousOutput, placeholder, cwd: taskCwd, sessionEnabled,
|
|
1336
|
+
sessionDir: taskSessionDir,
|
|
1337
|
+
artifactsDir, artifactConfig, id,
|
|
1338
|
+
flatIndex: fi, flatStepCount: flatSteps.length,
|
|
1339
|
+
outputFile: path.join(asyncDir, `output-${fi}.log`),
|
|
1340
|
+
piPackageRoot: config.piPackageRoot,
|
|
1341
|
+
piArgv1: config.piArgv1,
|
|
1342
|
+
childIntercomTarget: config.childIntercomTargets?.[fi],
|
|
1343
|
+
orchestratorIntercomTarget: config.controlIntercomTarget,
|
|
1344
|
+
registerInterrupt: (interrupt) => {
|
|
1345
|
+
activeChildInterrupt = interrupt;
|
|
1346
|
+
},
|
|
1347
|
+
onAttemptStart: (attempt) => updateStepModel(fi, attempt.model, attempt.thinking),
|
|
1348
|
+
onChildEvent: (event) => updateStepFromChildEvent(fi, event),
|
|
1349
|
+
});
|
|
1350
|
+
if (task.sessionFile) {
|
|
1351
|
+
latestSessionFile = task.sessionFile;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
const taskEndTime = Date.now();
|
|
1355
|
+
const taskDuration = taskEndTime - taskStartTime;
|
|
1356
|
+
|
|
1357
|
+
statusPayload.steps[fi].status = singleResult.exitCode === 0 ? "complete" : "failed";
|
|
1358
|
+
statusPayload.steps[fi].endedAt = taskEndTime;
|
|
1359
|
+
statusPayload.steps[fi].durationMs = taskDuration;
|
|
1360
|
+
statusPayload.steps[fi].exitCode = singleResult.exitCode;
|
|
1361
|
+
statusPayload.steps[fi].model = singleResult.model;
|
|
1362
|
+
statusPayload.steps[fi].thinking = resolveEffectiveThinking(singleResult.model, statusPayload.steps[fi].thinking);
|
|
1363
|
+
statusPayload.steps[fi].attemptedModels = singleResult.attemptedModels;
|
|
1364
|
+
statusPayload.steps[fi].modelAttempts = singleResult.modelAttempts;
|
|
1365
|
+
statusPayload.steps[fi].error = singleResult.error;
|
|
1366
|
+
statusPayload.lastUpdate = taskEndTime;
|
|
1367
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1368
|
+
|
|
1369
|
+
appendJsonl(eventsPath, JSON.stringify({
|
|
1370
|
+
type: singleResult.exitCode === 0 ? "subagent.step.completed" : "subagent.step.failed",
|
|
1371
|
+
ts: taskEndTime, runId: id, stepIndex: fi, agent: task.agent,
|
|
1372
|
+
exitCode: singleResult.exitCode, durationMs: taskDuration,
|
|
1373
|
+
}));
|
|
1374
|
+
if (singleResult.completionGuardTriggered) {
|
|
1375
|
+
const event = buildControlEvent({
|
|
1376
|
+
from: statusPayload.steps[fi].activityState,
|
|
1377
|
+
to: "needs_attention",
|
|
1378
|
+
runId: id,
|
|
1379
|
+
agent: task.agent,
|
|
1380
|
+
index: fi,
|
|
1381
|
+
ts: taskEndTime,
|
|
1382
|
+
message: `${task.agent} completed without making edits for an implementation task`,
|
|
1383
|
+
reason: "completion_guard",
|
|
1384
|
+
});
|
|
1385
|
+
appendControlEvent(event);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
if (singleResult.exitCode !== 0 && failFast) aborted = true;
|
|
1389
|
+
return { ...singleResult, skipped: false };
|
|
1390
|
+
},
|
|
1391
|
+
);
|
|
1392
|
+
|
|
1393
|
+
flatIndex += group.parallel.length;
|
|
1394
|
+
|
|
1395
|
+
for (let t = 0; t < group.parallel.length; t++) {
|
|
1396
|
+
const fi = groupStartFlatIndex + t;
|
|
1397
|
+
const sessionTokens = config.sessionDir
|
|
1398
|
+
? parseSessionTokens(path.join(config.sessionDir, `parallel-${t}`))
|
|
1399
|
+
: null;
|
|
1400
|
+
const taskTokens = sessionTokens ?? tokenUsageFromAttempts(parallelResults[t]?.modelAttempts);
|
|
1401
|
+
if (!taskTokens) continue;
|
|
1402
|
+
statusPayload.steps[fi].tokens = taskTokens;
|
|
1403
|
+
previousCumulativeTokens = {
|
|
1404
|
+
input: previousCumulativeTokens.input + taskTokens.input,
|
|
1405
|
+
output: previousCumulativeTokens.output + taskTokens.output,
|
|
1406
|
+
total: previousCumulativeTokens.total + taskTokens.total,
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
statusPayload.totalTokens = { ...previousCumulativeTokens };
|
|
1410
|
+
statusPayload.lastUpdate = Date.now();
|
|
1411
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1412
|
+
|
|
1413
|
+
for (const pr of parallelResults) {
|
|
1414
|
+
results.push({
|
|
1415
|
+
agent: pr.agent,
|
|
1416
|
+
output: pr.output,
|
|
1417
|
+
error: pr.error,
|
|
1418
|
+
success: pr.exitCode === 0,
|
|
1419
|
+
skipped: pr.skipped,
|
|
1420
|
+
sessionFile: pr.sessionFile,
|
|
1421
|
+
intercomTarget: pr.intercomTarget,
|
|
1422
|
+
model: pr.model,
|
|
1423
|
+
attemptedModels: pr.attemptedModels,
|
|
1424
|
+
modelAttempts: pr.modelAttempts,
|
|
1425
|
+
artifactPaths: pr.artifactPaths,
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
previousOutput = aggregateParallelOutputs(
|
|
1430
|
+
parallelResults.map((r) => ({
|
|
1431
|
+
agent: r.agent,
|
|
1432
|
+
output: r.output,
|
|
1433
|
+
exitCode: r.exitCode,
|
|
1434
|
+
error: r.error,
|
|
1435
|
+
model: r.model,
|
|
1436
|
+
attemptedModels: r.attemptedModels,
|
|
1437
|
+
})),
|
|
1438
|
+
);
|
|
1439
|
+
previousOutput = appendParallelWorktreeSummary(previousOutput, worktreeSetup, asyncDir, stepIndex, group);
|
|
1440
|
+
|
|
1441
|
+
appendJsonl(eventsPath, JSON.stringify({
|
|
1442
|
+
type: "subagent.parallel.completed",
|
|
1443
|
+
ts: Date.now(),
|
|
1444
|
+
runId: id,
|
|
1445
|
+
stepIndex,
|
|
1446
|
+
success: parallelResults.every((r) => r.exitCode === 0 || r.exitCode === -1),
|
|
1447
|
+
}));
|
|
1448
|
+
|
|
1449
|
+
if (parallelResults.some((r) => r.exitCode !== 0 && r.exitCode !== -1)) {
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
} finally {
|
|
1453
|
+
if (worktreeSetup) cleanupWorktrees(worktreeSetup);
|
|
1454
|
+
}
|
|
1455
|
+
} else {
|
|
1456
|
+
const seqStep = step as SubagentStep;
|
|
1457
|
+
const stepStartTime = Date.now();
|
|
1458
|
+
statusPayload.currentStep = flatIndex;
|
|
1459
|
+
statusPayload.steps[flatIndex].status = "running";
|
|
1460
|
+
statusPayload.steps[flatIndex].activityState = undefined;
|
|
1461
|
+
statusPayload.activityState = undefined;
|
|
1462
|
+
resetStepLiveDetail(statusPayload.steps[flatIndex]);
|
|
1463
|
+
statusPayload.steps[flatIndex].skills = seqStep.skills;
|
|
1464
|
+
statusPayload.steps[flatIndex].startedAt = stepStartTime;
|
|
1465
|
+
statusPayload.steps[flatIndex].lastActivityAt = stepStartTime;
|
|
1466
|
+
statusPayload.lastActivityAt = stepStartTime;
|
|
1467
|
+
statusPayload.lastUpdate = stepStartTime;
|
|
1468
|
+
statusPayload.outputFile = path.join(asyncDir, `output-${flatIndex}.log`);
|
|
1469
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1470
|
+
|
|
1471
|
+
appendJsonl(eventsPath, JSON.stringify({
|
|
1472
|
+
type: "subagent.step.started",
|
|
1473
|
+
ts: stepStartTime,
|
|
1474
|
+
runId: id,
|
|
1475
|
+
stepIndex: flatIndex,
|
|
1476
|
+
agent: seqStep.agent,
|
|
1477
|
+
}));
|
|
1478
|
+
|
|
1479
|
+
const singleResult = await runSingleStep(seqStep, {
|
|
1480
|
+
previousOutput, placeholder, cwd, sessionEnabled,
|
|
1481
|
+
sessionDir: config.sessionDir,
|
|
1482
|
+
artifactsDir, artifactConfig, id,
|
|
1483
|
+
flatIndex, flatStepCount: flatSteps.length,
|
|
1484
|
+
outputFile: path.join(asyncDir, `output-${flatIndex}.log`),
|
|
1485
|
+
piPackageRoot: config.piPackageRoot,
|
|
1486
|
+
piArgv1: config.piArgv1,
|
|
1487
|
+
childIntercomTarget: config.childIntercomTargets?.[flatIndex],
|
|
1488
|
+
orchestratorIntercomTarget: config.controlIntercomTarget,
|
|
1489
|
+
registerInterrupt: (interrupt) => {
|
|
1490
|
+
activeChildInterrupt = interrupt;
|
|
1491
|
+
},
|
|
1492
|
+
onAttemptStart: (attempt) => updateStepModel(flatIndex, attempt.model, attempt.thinking),
|
|
1493
|
+
onChildEvent: (event) => updateStepFromChildEvent(flatIndex, event),
|
|
1494
|
+
});
|
|
1495
|
+
if (seqStep.sessionFile) {
|
|
1496
|
+
latestSessionFile = seqStep.sessionFile;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
previousOutput = singleResult.output;
|
|
1500
|
+
results.push({
|
|
1501
|
+
agent: singleResult.agent,
|
|
1502
|
+
output: singleResult.output,
|
|
1503
|
+
error: singleResult.error,
|
|
1504
|
+
success: singleResult.exitCode === 0,
|
|
1505
|
+
sessionFile: singleResult.sessionFile,
|
|
1506
|
+
intercomTarget: singleResult.intercomTarget,
|
|
1507
|
+
model: singleResult.model,
|
|
1508
|
+
attemptedModels: singleResult.attemptedModels,
|
|
1509
|
+
modelAttempts: singleResult.modelAttempts,
|
|
1510
|
+
artifactPaths: singleResult.artifactPaths,
|
|
1511
|
+
});
|
|
1512
|
+
|
|
1513
|
+
const cumulativeTokens = config.sessionDir ? parseSessionTokens(config.sessionDir) : null;
|
|
1514
|
+
let stepTokens: TokenUsage | null = cumulativeTokens
|
|
1515
|
+
? {
|
|
1516
|
+
input: cumulativeTokens.input - previousCumulativeTokens.input,
|
|
1517
|
+
output: cumulativeTokens.output - previousCumulativeTokens.output,
|
|
1518
|
+
total: cumulativeTokens.total - previousCumulativeTokens.total,
|
|
1519
|
+
}
|
|
1520
|
+
: null;
|
|
1521
|
+
if (cumulativeTokens) {
|
|
1522
|
+
previousCumulativeTokens = cumulativeTokens;
|
|
1523
|
+
} else {
|
|
1524
|
+
stepTokens = tokenUsageFromAttempts(singleResult.modelAttempts);
|
|
1525
|
+
if (stepTokens) {
|
|
1526
|
+
previousCumulativeTokens = {
|
|
1527
|
+
input: previousCumulativeTokens.input + stepTokens.input,
|
|
1528
|
+
output: previousCumulativeTokens.output + stepTokens.output,
|
|
1529
|
+
total: previousCumulativeTokens.total + stepTokens.total,
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
const stepEndTime = Date.now();
|
|
1535
|
+
statusPayload.steps[flatIndex].status = singleResult.exitCode === 0 ? "complete" : "failed";
|
|
1536
|
+
statusPayload.steps[flatIndex].endedAt = stepEndTime;
|
|
1537
|
+
statusPayload.steps[flatIndex].durationMs = stepEndTime - stepStartTime;
|
|
1538
|
+
statusPayload.steps[flatIndex].exitCode = singleResult.exitCode;
|
|
1539
|
+
statusPayload.steps[flatIndex].model = singleResult.model;
|
|
1540
|
+
statusPayload.steps[flatIndex].thinking = resolveEffectiveThinking(singleResult.model, statusPayload.steps[flatIndex].thinking);
|
|
1541
|
+
statusPayload.steps[flatIndex].attemptedModels = singleResult.attemptedModels;
|
|
1542
|
+
statusPayload.steps[flatIndex].modelAttempts = singleResult.modelAttempts;
|
|
1543
|
+
statusPayload.steps[flatIndex].error = singleResult.error;
|
|
1544
|
+
if (stepTokens) {
|
|
1545
|
+
statusPayload.steps[flatIndex].tokens = stepTokens;
|
|
1546
|
+
statusPayload.totalTokens = { ...previousCumulativeTokens };
|
|
1547
|
+
}
|
|
1548
|
+
statusPayload.lastUpdate = stepEndTime;
|
|
1549
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1550
|
+
|
|
1551
|
+
appendJsonl(eventsPath, JSON.stringify({
|
|
1552
|
+
type: singleResult.exitCode === 0 ? "subagent.step.completed" : "subagent.step.failed",
|
|
1553
|
+
ts: stepEndTime,
|
|
1554
|
+
runId: id,
|
|
1555
|
+
stepIndex: flatIndex,
|
|
1556
|
+
agent: seqStep.agent,
|
|
1557
|
+
exitCode: singleResult.exitCode,
|
|
1558
|
+
durationMs: stepEndTime - stepStartTime,
|
|
1559
|
+
tokens: stepTokens,
|
|
1560
|
+
}));
|
|
1561
|
+
if (singleResult.completionGuardTriggered) {
|
|
1562
|
+
const event = buildControlEvent({
|
|
1563
|
+
from: statusPayload.steps[flatIndex].activityState,
|
|
1564
|
+
to: "needs_attention",
|
|
1565
|
+
runId: id,
|
|
1566
|
+
agent: seqStep.agent,
|
|
1567
|
+
index: flatIndex,
|
|
1568
|
+
ts: stepEndTime,
|
|
1569
|
+
message: `${seqStep.agent} completed without making edits for an implementation task`,
|
|
1570
|
+
reason: "completion_guard",
|
|
1571
|
+
});
|
|
1572
|
+
appendControlEvent(event);
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
flatIndex++;
|
|
1576
|
+
if (singleResult.exitCode !== 0) {
|
|
1577
|
+
break;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
let summary = results.map((r) => `${r.agent}:\n${r.output}`).join("\n\n");
|
|
1583
|
+
let truncated = false;
|
|
1584
|
+
|
|
1585
|
+
if (maxOutput) {
|
|
1586
|
+
const config = { ...DEFAULT_MAX_OUTPUT, ...maxOutput };
|
|
1587
|
+
const lastArtifactPath = results[results.length - 1]?.artifactPaths?.outputPath;
|
|
1588
|
+
const truncResult = truncateOutput(summary, config, lastArtifactPath);
|
|
1589
|
+
if (truncResult.truncated) {
|
|
1590
|
+
summary = truncResult.text;
|
|
1591
|
+
truncated = true;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
const resultMode = config.resultMode ?? statusPayload.mode;
|
|
1596
|
+
const agentName = flatSteps.length === 1
|
|
1597
|
+
? flatSteps[0].agent
|
|
1598
|
+
: resultMode === "parallel"
|
|
1599
|
+
? `parallel:${flatSteps.map((s) => s.agent).join("+")}`
|
|
1600
|
+
: `chain:${flatSteps.map((s) => s.agent).join("->")}`;
|
|
1601
|
+
let sessionFile: string | undefined;
|
|
1602
|
+
let shareUrl: string | undefined;
|
|
1603
|
+
let gistUrl: string | undefined;
|
|
1604
|
+
let shareError: string | undefined;
|
|
1605
|
+
|
|
1606
|
+
if (shareEnabled) {
|
|
1607
|
+
sessionFile = config.sessionDir
|
|
1608
|
+
? (findLatestSessionFile(config.sessionDir) ?? undefined)
|
|
1609
|
+
: undefined;
|
|
1610
|
+
if (!sessionFile && latestSessionFile) {
|
|
1611
|
+
sessionFile = latestSessionFile;
|
|
1612
|
+
}
|
|
1613
|
+
if (sessionFile) {
|
|
1614
|
+
try {
|
|
1615
|
+
const exportDir = config.sessionDir ?? path.dirname(sessionFile);
|
|
1616
|
+
const htmlPath = await exportSessionHtml(sessionFile, exportDir, config.piPackageRoot);
|
|
1617
|
+
const share = createShareLink(htmlPath);
|
|
1618
|
+
if ("error" in share) shareError = share.error;
|
|
1619
|
+
else {
|
|
1620
|
+
shareUrl = share.shareUrl;
|
|
1621
|
+
gistUrl = share.gistUrl;
|
|
1622
|
+
}
|
|
1623
|
+
} catch (err) {
|
|
1624
|
+
shareError = String(err);
|
|
1625
|
+
}
|
|
1626
|
+
} else {
|
|
1627
|
+
shareError = "Session file not found.";
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
if (activityTimer) {
|
|
1632
|
+
clearInterval(activityTimer);
|
|
1633
|
+
activityTimer = undefined;
|
|
1634
|
+
}
|
|
1635
|
+
const effectiveSessionFile = sessionFile ?? latestSessionFile;
|
|
1636
|
+
const runEndedAt = Date.now();
|
|
1637
|
+
statusPayload.state = interrupted ? "paused" : results.every((r) => r.success) ? "complete" : "failed";
|
|
1638
|
+
statusPayload.activityState = undefined;
|
|
1639
|
+
statusPayload.endedAt = runEndedAt;
|
|
1640
|
+
statusPayload.lastUpdate = runEndedAt;
|
|
1641
|
+
statusPayload.sessionFile = effectiveSessionFile;
|
|
1642
|
+
statusPayload.shareUrl = shareUrl;
|
|
1643
|
+
statusPayload.gistUrl = gistUrl;
|
|
1644
|
+
statusPayload.shareError = shareError;
|
|
1645
|
+
if (statusPayload.state === "failed") {
|
|
1646
|
+
const failedStep = statusPayload.steps.find((s) => s.status === "failed");
|
|
1647
|
+
if (failedStep?.agent) {
|
|
1648
|
+
statusPayload.error = `Step failed: ${failedStep.agent}`;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
writeAtomicJson(statusPath, statusPayload);
|
|
1652
|
+
appendJsonl(
|
|
1653
|
+
eventsPath,
|
|
1654
|
+
JSON.stringify({
|
|
1655
|
+
type: "subagent.run.completed",
|
|
1656
|
+
ts: runEndedAt,
|
|
1657
|
+
runId: id,
|
|
1658
|
+
status: statusPayload.state,
|
|
1659
|
+
durationMs: runEndedAt - overallStartTime,
|
|
1660
|
+
}),
|
|
1661
|
+
);
|
|
1662
|
+
writeRunLog(logPath, {
|
|
1663
|
+
id,
|
|
1664
|
+
mode: statusPayload.mode,
|
|
1665
|
+
cwd,
|
|
1666
|
+
startedAt: overallStartTime,
|
|
1667
|
+
endedAt: runEndedAt,
|
|
1668
|
+
steps: statusPayload.steps.map((step) => ({
|
|
1669
|
+
agent: step.agent,
|
|
1670
|
+
status: step.status,
|
|
1671
|
+
durationMs: step.durationMs,
|
|
1672
|
+
})),
|
|
1673
|
+
summary,
|
|
1674
|
+
truncated,
|
|
1675
|
+
artifactsDir,
|
|
1676
|
+
sessionFile: effectiveSessionFile,
|
|
1677
|
+
shareUrl,
|
|
1678
|
+
shareError,
|
|
1679
|
+
});
|
|
1680
|
+
|
|
1681
|
+
try {
|
|
1682
|
+
writeAtomicJson(resultPath, {
|
|
1683
|
+
id,
|
|
1684
|
+
agent: agentName,
|
|
1685
|
+
mode: resultMode,
|
|
1686
|
+
success: !interrupted && results.every((r) => r.success),
|
|
1687
|
+
state: interrupted ? "paused" : results.every((r) => r.success) ? "complete" : "failed",
|
|
1688
|
+
summary: interrupted ? "Paused after interrupt. Waiting for explicit next action." : summary,
|
|
1689
|
+
results: results.map((r) => ({
|
|
1690
|
+
agent: r.agent,
|
|
1691
|
+
output: r.output,
|
|
1692
|
+
error: r.error,
|
|
1693
|
+
success: r.success,
|
|
1694
|
+
skipped: r.skipped || undefined,
|
|
1695
|
+
sessionFile: r.sessionFile,
|
|
1696
|
+
intercomTarget: r.intercomTarget,
|
|
1697
|
+
model: r.model,
|
|
1698
|
+
attemptedModels: r.attemptedModels,
|
|
1699
|
+
modelAttempts: r.modelAttempts,
|
|
1700
|
+
artifactPaths: r.artifactPaths,
|
|
1701
|
+
truncated: r.truncated,
|
|
1702
|
+
})),
|
|
1703
|
+
exitCode: interrupted || results.every((r) => r.success) ? 0 : 1,
|
|
1704
|
+
timestamp: runEndedAt,
|
|
1705
|
+
durationMs: runEndedAt - overallStartTime,
|
|
1706
|
+
truncated,
|
|
1707
|
+
artifactsDir,
|
|
1708
|
+
cwd,
|
|
1709
|
+
asyncDir,
|
|
1710
|
+
sessionId: config.sessionId,
|
|
1711
|
+
sessionFile: effectiveSessionFile,
|
|
1712
|
+
intercomTarget: config.controlIntercomTarget,
|
|
1713
|
+
shareUrl,
|
|
1714
|
+
gistUrl,
|
|
1715
|
+
shareError,
|
|
1716
|
+
...(taskIndex !== undefined && { taskIndex }),
|
|
1717
|
+
...(totalTasks !== undefined && { totalTasks }),
|
|
1718
|
+
});
|
|
1719
|
+
} catch (err) {
|
|
1720
|
+
console.error(`Failed to write result file ${resultPath}:`, err);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
const configArg = process.argv[2];
|
|
1725
|
+
if (configArg) {
|
|
1726
|
+
try {
|
|
1727
|
+
const configJson = fs.readFileSync(configArg, "utf-8");
|
|
1728
|
+
const config = JSON.parse(configJson) as SubagentRunConfig;
|
|
1729
|
+
try {
|
|
1730
|
+
fs.unlinkSync(configArg);
|
|
1731
|
+
} catch {
|
|
1732
|
+
// Temp config cleanup is best effort.
|
|
1733
|
+
}
|
|
1734
|
+
runSubagent(config).catch((runErr) => {
|
|
1735
|
+
console.error("Subagent runner error:", runErr);
|
|
1736
|
+
process.exit(1);
|
|
1737
|
+
});
|
|
1738
|
+
} catch (err) {
|
|
1739
|
+
console.error("Subagent runner error:", err);
|
|
1740
|
+
process.exit(1);
|
|
1741
|
+
}
|
|
1742
|
+
} else {
|
|
1743
|
+
let input = "";
|
|
1744
|
+
process.stdin.setEncoding("utf-8");
|
|
1745
|
+
process.stdin.on("data", (chunk) => {
|
|
1746
|
+
input += chunk;
|
|
1747
|
+
});
|
|
1748
|
+
process.stdin.on("end", () => {
|
|
1749
|
+
try {
|
|
1750
|
+
const config = JSON.parse(input) as SubagentRunConfig;
|
|
1751
|
+
runSubagent(config).catch((runErr) => {
|
|
1752
|
+
console.error("Subagent runner error:", runErr);
|
|
1753
|
+
process.exit(1);
|
|
1754
|
+
});
|
|
1755
|
+
} catch (err) {
|
|
1756
|
+
console.error("Subagent runner error:", err);
|
|
1757
|
+
process.exit(1);
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
}
|