@bastani/atomic 0.8.13 → 0.8.14
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 +23 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/host-html-template.ts +1 -1
- package/dist/builtin/mcp/init.ts +15 -2
- package/dist/builtin/mcp/mcp-callback-server.ts +10 -9
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/mcp/ui-session.ts +9 -6
- package/dist/builtin/subagents/CHANGELOG.md +8 -1
- package/dist/builtin/subagents/README.md +39 -32
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +11 -11
- package/dist/builtin/subagents/src/agents/agent-management.ts +6 -1
- package/dist/builtin/subagents/src/agents/agent-serializer.ts +2 -0
- package/dist/builtin/subagents/src/agents/agents.ts +44 -19
- package/dist/builtin/subagents/src/extension/config.ts +16 -0
- package/dist/builtin/subagents/src/extension/fanout-child.ts +246 -0
- package/dist/builtin/subagents/src/extension/index.ts +466 -603
- package/dist/builtin/subagents/src/intercom/intercom-bridge.ts +6 -4
- package/dist/builtin/subagents/src/intercom/result-intercom.ts +109 -1
- package/dist/builtin/subagents/src/runs/background/async-execution.ts +124 -19
- package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +41 -6
- package/dist/builtin/subagents/src/runs/background/async-resume.ts +28 -15
- package/dist/builtin/subagents/src/runs/background/async-status.ts +60 -30
- package/dist/builtin/subagents/src/runs/background/result-watcher.ts +111 -54
- package/dist/builtin/subagents/src/runs/background/run-id-resolver.ts +83 -0
- package/dist/builtin/subagents/src/runs/background/run-status.ts +79 -3
- package/dist/builtin/subagents/src/runs/background/stale-run-reconciler.ts +46 -1
- package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +66 -14
- package/dist/builtin/subagents/src/runs/foreground/chain-execution.ts +10 -3
- package/dist/builtin/subagents/src/runs/foreground/execution.ts +14 -2
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +320 -23
- package/dist/builtin/subagents/src/runs/shared/completion-guard.ts +23 -1
- package/dist/builtin/subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +369 -0
- package/dist/builtin/subagents/src/runs/shared/nested-events.ts +935 -0
- package/dist/builtin/subagents/src/runs/shared/nested-path.ts +52 -0
- package/dist/builtin/subagents/src/runs/shared/nested-render.ts +115 -0
- package/dist/builtin/subagents/src/runs/shared/parallel-utils.ts +1 -0
- package/dist/builtin/subagents/src/runs/shared/pi-args.ts +82 -9
- package/dist/builtin/subagents/src/runs/shared/pi-spawn.ts +1 -1
- package/dist/builtin/subagents/src/runs/shared/single-output.ts +12 -2
- package/dist/builtin/subagents/src/runs/shared/subagent-prompt-runtime.ts +32 -10
- package/dist/builtin/subagents/src/runs/shared/worktree.ts +3 -2
- package/dist/builtin/subagents/src/shared/artifacts.ts +0 -1
- package/dist/builtin/subagents/src/shared/types.ts +96 -1
- package/dist/builtin/subagents/src/shared/utils.ts +10 -2
- package/dist/builtin/subagents/src/slash/slash-commands.ts +468 -625
- package/dist/builtin/subagents/src/tui/render.ts +1227 -2093
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +24 -0
- package/dist/builtin/workflows/README.md +28 -11
- package/dist/builtin/workflows/builtin/deep-research-codebase.ts +323 -40
- package/dist/builtin/workflows/builtin/ralph.ts +362 -176
- package/dist/builtin/workflows/package.json +2 -5
- package/dist/builtin/workflows/skills/research-codebase/SKILL.md +1 -1
- package/dist/builtin/workflows/skills/skill-creator/LICENSE.txt +202 -0
- package/dist/builtin/workflows/skills/skill-creator/SKILL.md +489 -0
- package/dist/builtin/workflows/skills/skill-creator/agents/analyzer.md +274 -0
- package/dist/builtin/workflows/skills/skill-creator/agents/comparator.md +202 -0
- package/dist/builtin/workflows/skills/skill-creator/agents/grader.md +223 -0
- package/dist/builtin/workflows/skills/skill-creator/assets/eval_review.html +146 -0
- package/dist/builtin/workflows/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/dist/builtin/workflows/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/dist/builtin/workflows/skills/skill-creator/references/schemas.md +430 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/__init__.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/generate_report.py +326 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/improve_description.py +247 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/package_skill.py +136 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/run_eval.py +310 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/run_loop.py +328 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/utils.py +47 -0
- package/dist/builtin/workflows/src/extension/index.ts +869 -93
- package/dist/builtin/workflows/src/extension/render-call.ts +34 -1
- package/dist/builtin/workflows/src/extension/render-result.ts +126 -21
- package/dist/builtin/workflows/src/extension/runtime.ts +91 -3
- package/dist/builtin/workflows/src/extension/wiring.ts +38 -12
- package/dist/builtin/workflows/src/extension/workflow-schema.ts +62 -5
- package/dist/builtin/workflows/src/runs/background/runner.ts +3 -3
- package/dist/builtin/workflows/src/runs/background/status.ts +42 -8
- package/dist/builtin/workflows/src/runs/foreground/executor.ts +410 -95
- package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +5 -2
- package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +8 -0
- package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +6 -4
- package/dist/builtin/workflows/src/runs/shared/worktree.ts +3 -2
- package/dist/builtin/workflows/src/shared/persistence-restore.ts +138 -5
- package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +30 -0
- package/dist/builtin/workflows/src/shared/render-inputs-schema.ts +78 -120
- package/dist/builtin/workflows/src/shared/stage-ui-broker.ts +193 -0
- package/dist/builtin/workflows/src/shared/store-types.ts +26 -1
- package/dist/builtin/workflows/src/shared/store.ts +145 -17
- package/dist/builtin/workflows/src/shared/timing.ts +6 -2
- package/dist/builtin/workflows/src/shared/workflow-failures.ts +375 -0
- package/dist/builtin/workflows/src/tui/chat-surface.ts +68 -17
- package/dist/builtin/workflows/src/tui/connectors.ts +2 -2
- package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +24 -26
- package/dist/builtin/workflows/src/tui/graph-canvas.ts +4 -8
- package/dist/builtin/workflows/src/tui/graph-view.ts +17 -14
- package/dist/builtin/workflows/src/tui/header.ts +38 -0
- package/dist/builtin/workflows/src/tui/inline-form-card.ts +161 -238
- package/dist/builtin/workflows/src/tui/inline-form-editor.ts +68 -73
- package/dist/builtin/workflows/src/tui/inline-form-overlay.ts +2 -3
- package/dist/builtin/workflows/src/tui/inline-form-store.ts +2 -1
- package/dist/builtin/workflows/src/tui/inputs-overlay.ts +1 -3
- package/dist/builtin/workflows/src/tui/inputs-picker.ts +286 -399
- package/dist/builtin/workflows/src/tui/keybindings-adapter.ts +11 -0
- package/dist/builtin/workflows/src/tui/node-card.ts +2 -1
- package/dist/builtin/workflows/src/tui/overlay-adapter.ts +9 -1
- package/dist/builtin/workflows/src/tui/prompt-card.ts +46 -19
- package/dist/builtin/workflows/src/tui/run-detail.ts +63 -80
- package/dist/builtin/workflows/src/tui/session-confirm.ts +9 -3
- package/dist/builtin/workflows/src/tui/session-picker.ts +19 -16
- package/dist/builtin/workflows/src/tui/stage-chat-layout.ts +88 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +368 -879
- package/dist/builtin/workflows/src/tui/status-helpers.ts +4 -0
- package/dist/builtin/workflows/src/tui/status-list.ts +67 -75
- package/dist/builtin/workflows/src/tui/store-widget-installer.ts +50 -12
- package/dist/builtin/workflows/src/tui/submit-pane.ts +164 -0
- package/dist/builtin/workflows/src/tui/switcher.ts +27 -4
- package/dist/builtin/workflows/src/tui/text-helpers.ts +98 -4
- package/dist/builtin/workflows/src/tui/widget.ts +90 -68
- package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +23 -2
- package/dist/builtin/workflows/src/tui/workflow-list.ts +44 -68
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +2 -3
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -10
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +2 -1
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +3 -2
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +6 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +16 -2
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/atomic-guide-command.d.ts.map +1 -1
- package/dist/core/atomic-guide-command.js +8 -9
- package/dist/core/atomic-guide-command.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -2
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +2 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +8 -6
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.js +6 -3
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +12 -29
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +5 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/package-manager.d.ts +8 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +145 -58
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +6 -20
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +38 -31
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +9 -4
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +32 -24
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +8 -15
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +8 -22
- package/dist/core/skills.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts +5 -4
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js +34 -11
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/contract.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/projections.js +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/projections.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.d.ts +1 -2
- package/dist/core/tools/ask-user-question/state/state-reducer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.js +26 -9
- package/dist/core/tools/ask-user-question/state/state-reducer.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/state.d.ts +4 -0
- package/dist/core/tools/ask-user-question/state/state.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/state.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts +1 -0
- package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/option-list-view.js +1 -0
- package/dist/core/tools/ask-user-question/view/components/option-list-view.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts +9 -6
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js +28 -7
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/props-adapter.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/props-adapter.js +4 -1
- package/dist/core/tools/ask-user-question/view/props-adapter.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +56 -53
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +3 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +8 -1
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +44 -81
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +27 -12
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +2 -3
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +3 -3
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +5 -5
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +2 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +11 -4
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/path-utils.d.ts +2 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js +39 -21
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +9 -8
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js +12 -2
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +20 -35
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +5 -6
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/chat-input-actions.d.ts +24 -0
- package/dist/modes/interactive/chat-input-actions.d.ts.map +1 -0
- package/dist/modes/interactive/chat-input-actions.js +179 -0
- package/dist/modes/interactive/chat-input-actions.js.map +1 -0
- package/dist/modes/interactive/components/chat-message-renderer.d.ts +1 -0
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js +14 -3
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +157 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host.js +1007 -0
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +1 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +14 -5
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +9 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +29 -4
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +18 -67
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/child-process.d.ts +1 -0
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +8 -0
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +3 -1
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js +14 -8
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts +30 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -0
- package/dist/utils/image-resize-core.js +124 -0
- package/dist/utils/image-resize-core.js.map +1 -0
- package/dist/utils/image-resize-worker.d.ts +2 -0
- package/dist/utils/image-resize-worker.d.ts.map +1 -0
- package/dist/utils/image-resize-worker.js +31 -0
- package/dist/utils/image-resize-worker.js.map +1 -0
- package/dist/utils/image-resize.d.ts +7 -27
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +75 -115
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/paths.d.ts +16 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +49 -7
- package/dist/utils/paths.js.map +1 -1
- package/docs/changelog.mdx +29 -0
- package/docs/compaction.md +1 -1
- package/docs/custom-provider.md +2 -2
- package/docs/development.md +1 -1
- package/docs/docs.json +98 -143
- package/docs/extensions.md +29 -16
- package/docs/favicon.svg +29 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/images/workflow-command.png +0 -0
- package/docs/images/workflow-graph.png +0 -0
- package/docs/images/workflow-input-picker.png +0 -0
- package/docs/images/workflow-list.png +0 -0
- package/docs/index.md +10 -1
- package/docs/logo.svg +59 -0
- package/docs/packages.md +3 -3
- package/docs/providers.md +1 -1
- package/docs/quickstart.md +98 -2
- package/docs/rpc.md +8 -8
- package/docs/sdk.md +23 -12
- package/docs/sessions.md +1 -1
- package/docs/skills.md +15 -1
- package/docs/termux.md +11 -1
- package/docs/themes.md +6 -6
- package/docs/tui.md +18 -18
- package/docs/usage.md +1 -1
- package/docs/workflows.md +172 -2
- package/examples/extensions/subagent/index.ts +2 -1
- package/package.json +6 -6
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/SKILL.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/element-attributes.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/playwright-tests.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/request-mocking.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/running-code.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/session-management.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/spec-driven-testing.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/storage-state.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/test-generation.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/tracing.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/playwright-cli/references/video-recording.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/tdd/SKILL.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/tdd/deep-modules.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/tdd/interface-design.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/tdd/mocking.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/tdd/refactoring.md +0 -0
- /package/dist/builtin/{workflows → subagents}/skills/tdd/tests.md +0 -0
|
@@ -15,82 +15,52 @@
|
|
|
15
15
|
import * as fs from "node:fs";
|
|
16
16
|
import * as os from "node:os";
|
|
17
17
|
import * as path from "node:path";
|
|
18
|
-
import { getAgentConfigPaths, getEnvValue } from "@bastani/atomic";
|
|
19
18
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type ToolDefinition,
|
|
24
|
-
} from "@bastani/atomic";
|
|
25
|
-
import {
|
|
26
|
-
Box,
|
|
27
|
-
Container,
|
|
28
|
-
Spacer,
|
|
29
|
-
Text,
|
|
30
|
-
truncateToWidth,
|
|
31
|
-
visibleWidth,
|
|
32
|
-
wrapTextWithAnsi,
|
|
33
|
-
type Component,
|
|
34
|
-
} from "@earendil-works/pi-tui";
|
|
19
|
+
import { APP_NAME, getEnvValue } from "@bastani/atomic";
|
|
20
|
+
import { type ExtensionAPI, type ExtensionContext, type ToolDefinition } from "@bastani/atomic";
|
|
21
|
+
import { Box, Container, Spacer, Text, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component } from "@earendil-works/pi-tui";
|
|
35
22
|
import { discoverAgents } from "../agents/agents.ts";
|
|
36
|
-
import {
|
|
37
|
-
cleanupAllArtifactDirs,
|
|
38
|
-
cleanupOldArtifacts,
|
|
39
|
-
getArtifactsDir,
|
|
40
|
-
} from "../shared/artifacts.ts";
|
|
23
|
+
import { cleanupAllArtifactDirs, cleanupOldArtifacts, getArtifactsDir } from "../shared/artifacts.ts";
|
|
41
24
|
import { resolveCurrentSessionId } from "../shared/session-identity.ts";
|
|
42
25
|
import { cleanupOldChainDirs } from "../shared/settings.ts";
|
|
43
|
-
import {
|
|
44
|
-
renderWidget,
|
|
45
|
-
renderSubagentResult,
|
|
46
|
-
stopResultAnimations,
|
|
47
|
-
stopWidgetAnimation,
|
|
48
|
-
syncResultAnimation,
|
|
49
|
-
} from "../tui/render.ts";
|
|
26
|
+
import { clearLegacyResultAnimationTimer, renderWidget, renderSubagentResult } from "../tui/render.ts";
|
|
50
27
|
import { SubagentParams } from "./schemas.ts";
|
|
51
|
-
import {
|
|
52
|
-
createSubagentExecutor,
|
|
53
|
-
type SubagentParamsLike,
|
|
54
|
-
} from "../runs/foreground/subagent-executor.ts";
|
|
28
|
+
import { createSubagentExecutor, type SubagentParamsLike } from "../runs/foreground/subagent-executor.ts";
|
|
55
29
|
import { createAsyncJobTracker } from "../runs/background/async-job-tracker.ts";
|
|
56
30
|
import { createResultWatcher } from "../runs/background/result-watcher.ts";
|
|
57
31
|
import { registerSlashCommands } from "../slash/slash-commands.ts";
|
|
58
32
|
import { registerPromptTemplateDelegationBridge } from "../slash/prompt-template-bridge.ts";
|
|
59
33
|
import { registerSlashSubagentBridge } from "../slash/slash-bridge.ts";
|
|
60
|
-
import {
|
|
61
|
-
clearSlashSnapshots,
|
|
62
|
-
getSlashRenderableSnapshot,
|
|
63
|
-
resolveSlashMessageDetails,
|
|
64
|
-
restoreSlashFinalSnapshots,
|
|
65
|
-
type SlashMessageDetails,
|
|
66
|
-
} from "../slash/slash-live-state.ts";
|
|
34
|
+
import { clearSlashSnapshots, getSlashRenderableSnapshot, resolveSlashMessageDetails, restoreSlashFinalSnapshots, type SlashMessageDetails } from "../slash/slash-live-state.ts";
|
|
67
35
|
import { inspectSubagentStatus } from "../runs/background/run-status.ts";
|
|
68
|
-
import registerSubagentNotify, {
|
|
69
|
-
|
|
70
|
-
} from "../runs/
|
|
71
|
-
import
|
|
36
|
+
import registerSubagentNotify, { type SubagentNotifyDetails } from "../runs/background/notify.ts";
|
|
37
|
+
import { cleanupOldNestedRuntimeDirs } from "../runs/shared/nested-events.ts";
|
|
38
|
+
import { SUBAGENT_CHILD_ENV, SUBAGENT_FANOUT_CHILD_ENV } from "../runs/shared/pi-args.ts";
|
|
39
|
+
import registerFanoutChildSubagentExtension from "./fanout-child.ts";
|
|
72
40
|
import { formatDuration, shortenPath } from "../shared/formatters.ts";
|
|
41
|
+
import { loadConfig } from "./config.ts";
|
|
73
42
|
import {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
WIDGET_KEY,
|
|
43
|
+
type Details,
|
|
44
|
+
type SubagentState,
|
|
45
|
+
ASYNC_DIR,
|
|
46
|
+
DEFAULT_ARTIFACT_CONFIG,
|
|
47
|
+
RESULTS_DIR,
|
|
48
|
+
SLASH_RESULT_TYPE,
|
|
49
|
+
SUBAGENT_ASYNC_COMPLETE_EVENT,
|
|
50
|
+
SUBAGENT_ASYNC_STARTED_EVENT,
|
|
51
|
+
SUBAGENT_CONTROL_EVENT,
|
|
52
|
+
WIDGET_KEY,
|
|
85
53
|
} from "../shared/types.ts";
|
|
86
54
|
import {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
55
|
+
clearPendingForegroundControlNotices,
|
|
56
|
+
formatSubagentControlNotice,
|
|
57
|
+
handleSubagentControlNotice,
|
|
58
|
+
SUBAGENT_CONTROL_MESSAGE_TYPE,
|
|
59
|
+
type SubagentControlMessageDetails,
|
|
92
60
|
} from "./control-notices.ts";
|
|
93
61
|
|
|
62
|
+
export { loadConfig } from "./config.ts";
|
|
63
|
+
|
|
94
64
|
/**
|
|
95
65
|
* Derive subagent session base directory from parent session file.
|
|
96
66
|
* If parent session is ~/.atomic/agent/sessions/abc123.jsonl,
|
|
@@ -99,38 +69,16 @@ import {
|
|
|
99
69
|
* Falls back to a unique temp directory if no parent session.
|
|
100
70
|
*/
|
|
101
71
|
function getSubagentSessionRoot(parentSessionFile: string | null): string {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function loadConfig(): ExtensionConfig {
|
|
111
|
-
for (const configPath of getAgentConfigPaths(
|
|
112
|
-
"extensions",
|
|
113
|
-
"subagent",
|
|
114
|
-
"config.json",
|
|
115
|
-
)) {
|
|
116
|
-
try {
|
|
117
|
-
if (fs.existsSync(configPath)) {
|
|
118
|
-
return JSON.parse(
|
|
119
|
-
fs.readFileSync(configPath, "utf-8"),
|
|
120
|
-
) as ExtensionConfig;
|
|
121
|
-
}
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error(
|
|
124
|
-
`Failed to load subagent config from '${configPath}':`,
|
|
125
|
-
error,
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return {};
|
|
72
|
+
if (parentSessionFile) {
|
|
73
|
+
const baseName = path.basename(parentSessionFile, ".jsonl");
|
|
74
|
+
const sessionsDir = path.dirname(parentSessionFile);
|
|
75
|
+
return path.join(sessionsDir, baseName);
|
|
76
|
+
}
|
|
77
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), `${APP_NAME}-subagent-session-`));
|
|
130
78
|
}
|
|
131
79
|
|
|
132
80
|
function expandTilde(p: string): string {
|
|
133
|
-
|
|
81
|
+
return p.startsWith("~/") ? path.join(os.homedir(), p.slice(2)) : p;
|
|
134
82
|
}
|
|
135
83
|
|
|
136
84
|
/**
|
|
@@ -141,380 +89,308 @@ function expandTilde(p: string): string {
|
|
|
141
89
|
* the directory completely inaccessible to the creating user.
|
|
142
90
|
*/
|
|
143
91
|
function ensureAccessibleDir(dirPath: string): void {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
92
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
93
|
+
try {
|
|
94
|
+
fs.accessSync(dirPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
95
|
+
} catch {
|
|
96
|
+
try {
|
|
97
|
+
fs.rmSync(dirPath, { recursive: true, force: true });
|
|
98
|
+
} catch {
|
|
99
|
+
// Best effort: retry mkdir/access even if cleanup fails.
|
|
100
|
+
}
|
|
101
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
102
|
+
fs.accessSync(dirPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
103
|
+
}
|
|
156
104
|
}
|
|
157
105
|
|
|
158
106
|
function isSlashResultRunning(result: { details?: Details }): boolean {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
(entry) => entry.progress?.status === "running",
|
|
163
|
-
) ||
|
|
164
|
-
false
|
|
165
|
-
);
|
|
107
|
+
return result.details?.progress?.some((entry) => entry.status === "running")
|
|
108
|
+
|| result.details?.results.some((entry) => entry.progress?.status === "running")
|
|
109
|
+
|| false;
|
|
166
110
|
}
|
|
167
111
|
|
|
168
112
|
function isSlashResultError(result: { details?: Details }): boolean {
|
|
169
|
-
|
|
170
|
-
result.details?.results.some(
|
|
171
|
-
(entry) => entry.exitCode !== 0 && entry.progress?.status !== "running",
|
|
172
|
-
) || false
|
|
173
|
-
);
|
|
113
|
+
return result.details?.results.some((entry) => entry.exitCode !== 0 && entry.progress?.status !== "running") || false;
|
|
174
114
|
}
|
|
175
115
|
|
|
176
116
|
function isStaleExtensionContextError(error: unknown): boolean {
|
|
177
|
-
|
|
178
|
-
error instanceof Error &&
|
|
179
|
-
error.message.includes("Extension context no longer active")
|
|
180
|
-
);
|
|
117
|
+
return error instanceof Error && error.message.includes("Extension context no longer active");
|
|
181
118
|
}
|
|
182
119
|
|
|
183
120
|
function rebuildSlashResultContainer(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
121
|
+
container: Container,
|
|
122
|
+
result: AgentToolResult<Details>,
|
|
123
|
+
options: { expanded: boolean },
|
|
124
|
+
theme: ExtensionContext["ui"]["theme"],
|
|
188
125
|
): void {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
: "toolSuccessBg";
|
|
196
|
-
const box = new Box(1, 1, (text: string) => theme.bg(boxTheme, text));
|
|
197
|
-
box.addChild(renderSubagentResult(result, options, theme));
|
|
198
|
-
container.addChild(box);
|
|
126
|
+
container.clear();
|
|
127
|
+
container.addChild(new Spacer(1));
|
|
128
|
+
const boxTheme = isSlashResultRunning(result) ? "toolPendingBg" : isSlashResultError(result) ? "toolErrorBg" : "toolSuccessBg";
|
|
129
|
+
const box = new Box(1, 1, (text: string) => theme.bg(boxTheme, text));
|
|
130
|
+
box.addChild(renderSubagentResult(result, options, theme));
|
|
131
|
+
container.addChild(box);
|
|
199
132
|
}
|
|
200
133
|
|
|
201
134
|
function createSlashResultComponent(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
requestRender: () => void,
|
|
135
|
+
details: SlashMessageDetails,
|
|
136
|
+
options: { expanded: boolean },
|
|
137
|
+
theme: ExtensionContext["ui"]["theme"],
|
|
206
138
|
): Container {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
rebuildSlashResultContainer(container, snapshot.result, options, theme);
|
|
219
|
-
}
|
|
220
|
-
return Container.prototype.render.call(container, width);
|
|
221
|
-
};
|
|
222
|
-
return container;
|
|
139
|
+
const container = new Container();
|
|
140
|
+
let lastVersion = -1;
|
|
141
|
+
container.render = (width: number): string[] => {
|
|
142
|
+
const snapshot = getSlashRenderableSnapshot(details);
|
|
143
|
+
if (snapshot.version !== lastVersion || isSlashResultRunning(snapshot.result)) {
|
|
144
|
+
lastVersion = snapshot.version;
|
|
145
|
+
rebuildSlashResultContainer(container, snapshot.result, options, theme);
|
|
146
|
+
}
|
|
147
|
+
return Container.prototype.render.call(container, width);
|
|
148
|
+
};
|
|
149
|
+
return container;
|
|
223
150
|
}
|
|
224
151
|
|
|
225
|
-
function parseSubagentNotifyContent(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return {
|
|
256
|
-
agent: match[2]!,
|
|
257
|
-
status: match[1] as SubagentNotifyDetails["status"],
|
|
258
|
-
...(match[3] ? { taskInfo: match[3] } : {}),
|
|
259
|
-
resultPreview,
|
|
260
|
-
...(sessionLabel && sessionValue ? { sessionLabel, sessionValue } : {}),
|
|
261
|
-
};
|
|
152
|
+
function parseSubagentNotifyContent(content: string): SubagentNotifyDetails | undefined {
|
|
153
|
+
const lines = content.split("\n");
|
|
154
|
+
const header = lines[0] ?? "";
|
|
155
|
+
const match = header.match(/^Background task (completed|failed|paused): \*\*(.+?)\*\*(?:\s+(\([^)]*\)))?$/);
|
|
156
|
+
if (!match) return undefined;
|
|
157
|
+
const body = lines.slice(2);
|
|
158
|
+
let sessionIndex = -1;
|
|
159
|
+
for (let i = body.length - 1; i >= 1; i--) {
|
|
160
|
+
if (body[i - 1]?.trim() === "" && /^(Session|Session file|Session share error):\s+/.test(body[i]!)) {
|
|
161
|
+
sessionIndex = i;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const sessionLine = sessionIndex >= 0 ? body[sessionIndex] : undefined;
|
|
166
|
+
const resultLines = sessionIndex >= 0 ? body.slice(0, sessionIndex) : body;
|
|
167
|
+
const resultPreview = resultLines.join("\n").trim() || "(no output)";
|
|
168
|
+
let sessionLabel: string | undefined;
|
|
169
|
+
let sessionValue: string | undefined;
|
|
170
|
+
if (sessionLine) {
|
|
171
|
+
const separator = sessionLine.indexOf(":");
|
|
172
|
+
sessionLabel = sessionLine.slice(0, separator).toLowerCase();
|
|
173
|
+
sessionValue = sessionLine.slice(separator + 1).trim();
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
agent: match[2]!,
|
|
177
|
+
status: match[1] as SubagentNotifyDetails["status"],
|
|
178
|
+
...(match[3] ? { taskInfo: match[3] } : {}),
|
|
179
|
+
resultPreview,
|
|
180
|
+
...(sessionLabel && sessionValue ? { sessionLabel, sessionValue } : {}),
|
|
181
|
+
};
|
|
262
182
|
}
|
|
263
183
|
|
|
264
184
|
class SubagentControlNoticeComponent implements Component {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
)) {
|
|
291
|
-
const text = truncateToWidth(line, bodyWidth, "");
|
|
292
|
-
const padding = Math.max(0, bodyWidth - visibleWidth(text));
|
|
293
|
-
lines.push(this.theme.fg("accent", `│${text}${" ".repeat(padding)}│`));
|
|
294
|
-
}
|
|
295
|
-
lines.push(this.theme.fg("accent", `╰${borderChar.repeat(bodyWidth)}╯`));
|
|
296
|
-
return lines;
|
|
297
|
-
}
|
|
185
|
+
constructor(
|
|
186
|
+
private readonly details: SubagentControlMessageDetails,
|
|
187
|
+
private readonly theme: ExtensionContext["ui"]["theme"],
|
|
188
|
+
) {}
|
|
189
|
+
|
|
190
|
+
invalidate(): void {}
|
|
191
|
+
|
|
192
|
+
render(width: number): string[] {
|
|
193
|
+
const eventLabel = this.details.event.type.replaceAll("_", " ");
|
|
194
|
+
if (width < 3) return [truncateToWidth(`Subagent ${eventLabel}`, width)];
|
|
195
|
+
const bodyWidth = Math.max(1, width - 2);
|
|
196
|
+
const borderChar = "─";
|
|
197
|
+
const header = ` ⚠ Subagent ${eventLabel}: ${this.details.event.agent} `;
|
|
198
|
+
const headerText = truncateToWidth(header, bodyWidth, "");
|
|
199
|
+
const headerPadding = Math.max(0, bodyWidth - visibleWidth(headerText));
|
|
200
|
+
const lines = [this.theme.fg("accent", `╭${headerText}${borderChar.repeat(headerPadding)}╮`)];
|
|
201
|
+
|
|
202
|
+
for (const line of wrapTextWithAnsi(formatSubagentControlNotice(this.details), bodyWidth)) {
|
|
203
|
+
const text = truncateToWidth(line, bodyWidth, "");
|
|
204
|
+
const padding = Math.max(0, bodyWidth - visibleWidth(text));
|
|
205
|
+
lines.push(this.theme.fg("accent", `│${text}${" ".repeat(padding)}│`));
|
|
206
|
+
}
|
|
207
|
+
lines.push(this.theme.fg("accent", `╰${borderChar.repeat(bodyWidth)}╯`));
|
|
208
|
+
return lines;
|
|
209
|
+
}
|
|
298
210
|
}
|
|
299
211
|
|
|
300
212
|
export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
requestId,
|
|
483
|
-
{
|
|
484
|
-
agent: request.agent,
|
|
485
|
-
task: request.task,
|
|
486
|
-
context: request.context,
|
|
487
|
-
cwd: request.cwd,
|
|
488
|
-
model: request.model,
|
|
489
|
-
async: false,
|
|
490
|
-
clarify: false,
|
|
491
|
-
},
|
|
492
|
-
signal,
|
|
493
|
-
onUpdate,
|
|
494
|
-
ctx,
|
|
495
|
-
);
|
|
496
|
-
},
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
function effectiveParallelTaskCount(
|
|
500
|
-
tasks: Array<{ count?: unknown }> | undefined,
|
|
501
|
-
): number {
|
|
502
|
-
if (!tasks || tasks.length === 0) return 0;
|
|
503
|
-
return tasks.reduce((total, task) => {
|
|
504
|
-
const count =
|
|
505
|
-
typeof task.count === "number" &&
|
|
506
|
-
Number.isInteger(task.count) &&
|
|
507
|
-
task.count >= 1
|
|
508
|
-
? task.count
|
|
509
|
-
: 1;
|
|
510
|
-
return total + count;
|
|
511
|
-
}, 0);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
const tool: ToolDefinition<typeof SubagentParams, Details> = {
|
|
515
|
-
name: "subagent",
|
|
516
|
-
label: "Subagent",
|
|
517
|
-
description: `Delegate to subagents or manage agent definitions.
|
|
213
|
+
if (getEnvValue(SUBAGENT_CHILD_ENV) === "1") {
|
|
214
|
+
if (getEnvValue(SUBAGENT_FANOUT_CHILD_ENV) === "1") registerFanoutChildSubagentExtension(pi);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const globalStore = globalThis as Record<string, unknown>;
|
|
218
|
+
const runtimeCleanupStoreKey = "__piSubagentRuntimeCleanup";
|
|
219
|
+
const previousRuntimeCleanup = globalStore[runtimeCleanupStoreKey];
|
|
220
|
+
if (typeof previousRuntimeCleanup === "function") {
|
|
221
|
+
try {
|
|
222
|
+
previousRuntimeCleanup();
|
|
223
|
+
} catch {
|
|
224
|
+
// Best effort cleanup for stale timers from an older reload.
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
ensureAccessibleDir(RESULTS_DIR);
|
|
229
|
+
ensureAccessibleDir(ASYNC_DIR);
|
|
230
|
+
cleanupOldChainDirs();
|
|
231
|
+
|
|
232
|
+
const config = loadConfig();
|
|
233
|
+
const asyncByDefault = config.asyncByDefault === true;
|
|
234
|
+
const tempArtifactsDir = getArtifactsDir(null);
|
|
235
|
+
cleanupAllArtifactDirs(DEFAULT_ARTIFACT_CONFIG.cleanupDays);
|
|
236
|
+
cleanupOldNestedRuntimeDirs(DEFAULT_ARTIFACT_CONFIG.cleanupDays);
|
|
237
|
+
|
|
238
|
+
const state: SubagentState = {
|
|
239
|
+
baseCwd: "",
|
|
240
|
+
currentSessionId: null,
|
|
241
|
+
asyncJobs: new Map(),
|
|
242
|
+
foregroundRuns: new Map(),
|
|
243
|
+
foregroundControls: new Map(),
|
|
244
|
+
lastForegroundControlId: null,
|
|
245
|
+
pendingForegroundControlNotices: new Map(),
|
|
246
|
+
cleanupTimers: new Map(),
|
|
247
|
+
lastUiContext: null,
|
|
248
|
+
poller: null,
|
|
249
|
+
completionSeen: new Map(),
|
|
250
|
+
watcher: null,
|
|
251
|
+
watcherRestartTimer: null,
|
|
252
|
+
resultFileCoalescer: {
|
|
253
|
+
schedule: () => false,
|
|
254
|
+
clear: () => {},
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const { startResultWatcher, primeExistingResults, stopResultWatcher } = createResultWatcher(
|
|
259
|
+
pi,
|
|
260
|
+
state,
|
|
261
|
+
RESULTS_DIR,
|
|
262
|
+
10 * 60 * 1000,
|
|
263
|
+
);
|
|
264
|
+
startResultWatcher();
|
|
265
|
+
primeExistingResults();
|
|
266
|
+
|
|
267
|
+
const runtimeCleanup = () => {
|
|
268
|
+
stopResultWatcher();
|
|
269
|
+
clearPendingForegroundControlNotices(state);
|
|
270
|
+
if (state.poller) {
|
|
271
|
+
clearInterval(state.poller);
|
|
272
|
+
state.poller = null;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
globalStore[runtimeCleanupStoreKey] = runtimeCleanup;
|
|
276
|
+
|
|
277
|
+
const { ensurePoller, handleStarted, handleComplete, resetJobs } = createAsyncJobTracker(pi, state, ASYNC_DIR);
|
|
278
|
+
const executor = createSubagentExecutor({
|
|
279
|
+
pi,
|
|
280
|
+
state,
|
|
281
|
+
config,
|
|
282
|
+
asyncByDefault,
|
|
283
|
+
tempArtifactsDir,
|
|
284
|
+
getSubagentSessionRoot,
|
|
285
|
+
expandTilde,
|
|
286
|
+
discoverAgents,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
pi.registerMessageRenderer<SlashMessageDetails>(SLASH_RESULT_TYPE, (message, options, theme) => {
|
|
290
|
+
const details = resolveSlashMessageDetails(message.details);
|
|
291
|
+
if (!details) return undefined;
|
|
292
|
+
return createSlashResultComponent(details, options, theme);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
pi.registerMessageRenderer<SubagentNotifyDetails>("subagent-notify", (message, options, theme) => {
|
|
296
|
+
const content = typeof message.content === "string" ? message.content : "";
|
|
297
|
+
const details = (message.details as SubagentNotifyDetails | undefined) ?? parseSubagentNotifyContent(content);
|
|
298
|
+
if (!details) return new Text(content, 0, 0);
|
|
299
|
+
const icon = details.status === "completed"
|
|
300
|
+
? theme.fg("success", "✓")
|
|
301
|
+
: details.status === "paused"
|
|
302
|
+
? theme.fg("warning", "■")
|
|
303
|
+
: theme.fg("error", "✗");
|
|
304
|
+
const parts: string[] = [];
|
|
305
|
+
if (details.taskInfo) parts.push(details.taskInfo);
|
|
306
|
+
if (details.durationMs !== undefined) parts.push(formatDuration(details.durationMs));
|
|
307
|
+
let text = `${icon} ${theme.bold(details.agent)} ${theme.fg("dim", details.status)}`;
|
|
308
|
+
if (parts.length > 0) text += ` ${theme.fg("dim", "·")} ${parts.map((part) => theme.fg("dim", part)).join(` ${theme.fg("dim", "·")} `)}`;
|
|
309
|
+
const trimmedPreview = details.resultPreview.trim();
|
|
310
|
+
const previewLines = options.expanded
|
|
311
|
+
? trimmedPreview.split("\n").filter((line) => line.trim())
|
|
312
|
+
: [trimmedPreview.split("\n", 1)[0] ?? ""].filter((line) => line.trim());
|
|
313
|
+
for (const line of previewLines.length > 0 ? previewLines : ["(no output)"]) {
|
|
314
|
+
text += `\n ${theme.fg("dim", `⎿ ${line}`)}`;
|
|
315
|
+
}
|
|
316
|
+
if (!options.expanded && trimmedPreview.includes("\n")) {
|
|
317
|
+
text += `\n ${theme.fg("dim", "ctrl+o full notification")}`;
|
|
318
|
+
}
|
|
319
|
+
if (details.sessionLabel && details.sessionValue) {
|
|
320
|
+
text += `\n ${theme.fg("muted", `${details.sessionLabel}: ${shortenPath(details.sessionValue)}`)}`;
|
|
321
|
+
}
|
|
322
|
+
return new Text(text, 0, 0);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
pi.registerMessageRenderer<SubagentControlMessageDetails>(SUBAGENT_CONTROL_MESSAGE_TYPE, (message, _options, theme) => {
|
|
326
|
+
const details = message.details as SubagentControlMessageDetails | undefined;
|
|
327
|
+
if (!details?.event) return undefined;
|
|
328
|
+
const content = typeof message.content === "string" ? message.content : undefined;
|
|
329
|
+
return new SubagentControlNoticeComponent({ ...details, noticeText: formatSubagentControlNotice(details, content) }, theme);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
const executeSubagentCollapsed = (id: string, params: SubagentParamsLike, signal: AbortSignal, onUpdate: ((result: AgentToolResult<Details>) => void) | undefined, ctx: ExtensionContext) => {
|
|
333
|
+
if (ctx.hasUI) ctx.ui.setToolsExpanded(false);
|
|
334
|
+
return executor.execute(id, params, signal, onUpdate, ctx);
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const slashBridge = registerSlashSubagentBridge({
|
|
338
|
+
events: pi.events,
|
|
339
|
+
getContext: () => state.lastUiContext,
|
|
340
|
+
execute: (id, params, signal, onUpdate, ctx) =>
|
|
341
|
+
executeSubagentCollapsed(id, params, signal, onUpdate, ctx),
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const promptTemplateBridge = registerPromptTemplateDelegationBridge({
|
|
345
|
+
events: pi.events,
|
|
346
|
+
getContext: () => state.lastUiContext,
|
|
347
|
+
execute: async (requestId, request, signal, ctx, onUpdate) => {
|
|
348
|
+
if (request.tasks && request.tasks.length > 0) {
|
|
349
|
+
return executeSubagentCollapsed(
|
|
350
|
+
requestId,
|
|
351
|
+
{
|
|
352
|
+
tasks: request.tasks,
|
|
353
|
+
context: request.context,
|
|
354
|
+
cwd: request.cwd,
|
|
355
|
+
worktree: request.worktree,
|
|
356
|
+
async: false,
|
|
357
|
+
clarify: false,
|
|
358
|
+
},
|
|
359
|
+
signal,
|
|
360
|
+
onUpdate,
|
|
361
|
+
ctx,
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
return executeSubagentCollapsed(
|
|
365
|
+
requestId,
|
|
366
|
+
{
|
|
367
|
+
agent: request.agent,
|
|
368
|
+
task: request.task,
|
|
369
|
+
context: request.context,
|
|
370
|
+
cwd: request.cwd,
|
|
371
|
+
model: request.model,
|
|
372
|
+
async: false,
|
|
373
|
+
clarify: false,
|
|
374
|
+
},
|
|
375
|
+
signal,
|
|
376
|
+
onUpdate,
|
|
377
|
+
ctx,
|
|
378
|
+
);
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
function effectiveParallelTaskCount(tasks: Array<{ count?: unknown }> | undefined): number {
|
|
383
|
+
if (!tasks || tasks.length === 0) return 0;
|
|
384
|
+
return tasks.reduce((total, task) => {
|
|
385
|
+
const count = typeof task.count === "number" && Number.isInteger(task.count) && task.count >= 1 ? task.count : 1;
|
|
386
|
+
return total + count;
|
|
387
|
+
}, 0);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const tool: ToolDefinition<typeof SubagentParams, Details> = {
|
|
391
|
+
name: "subagent",
|
|
392
|
+
label: "Subagent",
|
|
393
|
+
description: `Delegate to subagents or manage agent definitions.
|
|
518
394
|
|
|
519
395
|
EXECUTION (use exactly ONE mode):
|
|
520
396
|
• Before executing, use { action: "list" } to inspect configured agents/chains. Only execute agents listed as executable/non-disabled.
|
|
@@ -526,7 +402,7 @@ EXECUTION (use exactly ONE mode):
|
|
|
526
402
|
CHAIN TEMPLATE VARIABLES (use in task strings):
|
|
527
403
|
• {task} - The original task/request from the user
|
|
528
404
|
• {previous} - Text response from the previous step (empty for first step)
|
|
529
|
-
• {chain_dir} - Shared directory for chain files (e.g., <tmpdir
|
|
405
|
+
• {chain_dir} - Shared directory for chain files (e.g., <tmpdir>/${APP_NAME}-subagents-<scope>/chain-runs/abc123/)
|
|
530
406
|
|
|
531
407
|
Example: { chain: [{agent:"agent-a", task:"Analyze {task}"}, {agent:"agent-b", task:"Plan based on {previous}"}] }
|
|
532
408
|
|
|
@@ -545,169 +421,156 @@ CONTROL:
|
|
|
545
421
|
|
|
546
422
|
DIAGNOSTICS:
|
|
547
423
|
• { action: "doctor" } - read-only report for runtime paths, discovery, sessions, and intercom`,
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
stopWidgetAnimation();
|
|
701
|
-
stopResultAnimations();
|
|
702
|
-
if (globalStore[runtimeCleanupStoreKey] === runtimeCleanup) {
|
|
703
|
-
delete globalStore[runtimeCleanupStoreKey];
|
|
704
|
-
}
|
|
705
|
-
try {
|
|
706
|
-
if (state.lastUiContext?.hasUI) {
|
|
707
|
-
state.lastUiContext.ui.setWidget(WIDGET_KEY, undefined);
|
|
708
|
-
}
|
|
709
|
-
} catch (error) {
|
|
710
|
-
if (!isStaleExtensionContextError(error)) throw error;
|
|
711
|
-
}
|
|
712
|
-
});
|
|
424
|
+
parameters: SubagentParams,
|
|
425
|
+
|
|
426
|
+
execute(id, params, signal, onUpdate, ctx) {
|
|
427
|
+
return executeSubagentCollapsed(id, params, signal, onUpdate, ctx);
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
renderCall(args, theme) {
|
|
431
|
+
if (args.action) {
|
|
432
|
+
const target = args.agent || args.chainName || "";
|
|
433
|
+
return new Text(
|
|
434
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}${args.action}${target ? ` ${theme.fg("accent", target)}` : ""}`,
|
|
435
|
+
0, 0,
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
const isParallel = (args.tasks?.length ?? 0) > 0;
|
|
439
|
+
const parallelCount = effectiveParallelTaskCount(args.tasks as Array<{ count?: unknown }> | undefined);
|
|
440
|
+
const asyncLabel = args.async === true && args.clarify !== true && !isParallel ? theme.fg("warning", " [async]") : "";
|
|
441
|
+
if (args.chain?.length)
|
|
442
|
+
return new Text(
|
|
443
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}chain (${args.chain.length})${asyncLabel}`,
|
|
444
|
+
0,
|
|
445
|
+
0,
|
|
446
|
+
);
|
|
447
|
+
if (isParallel)
|
|
448
|
+
return new Text(
|
|
449
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}parallel (${parallelCount})`,
|
|
450
|
+
0,
|
|
451
|
+
0,
|
|
452
|
+
);
|
|
453
|
+
return new Text(
|
|
454
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}${theme.fg("accent", args.agent || "?")}${asyncLabel}`,
|
|
455
|
+
0,
|
|
456
|
+
0,
|
|
457
|
+
);
|
|
458
|
+
},
|
|
459
|
+
|
|
460
|
+
renderResult(result, options, theme, context) {
|
|
461
|
+
clearLegacyResultAnimationTimer(context);
|
|
462
|
+
return renderSubagentResult(result, options, theme);
|
|
463
|
+
},
|
|
464
|
+
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
pi.registerTool(tool);
|
|
468
|
+
registerSlashCommands(pi, state);
|
|
469
|
+
|
|
470
|
+
const eventUnsubscribeStoreKey = "__piSubagentEventUnsubscribes";
|
|
471
|
+
const controlNoticeSeenStoreKey = "__piSubagentVisibleControlNotices";
|
|
472
|
+
const previousEventUnsubscribes = globalStore[eventUnsubscribeStoreKey];
|
|
473
|
+
if (Array.isArray(previousEventUnsubscribes)) {
|
|
474
|
+
for (const unsubscribe of previousEventUnsubscribes) {
|
|
475
|
+
if (typeof unsubscribe !== "function") continue;
|
|
476
|
+
try {
|
|
477
|
+
unsubscribe();
|
|
478
|
+
} catch {
|
|
479
|
+
// Best effort cleanup for stale handlers from an older reload.
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
registerSubagentNotify(pi);
|
|
484
|
+
|
|
485
|
+
const existingVisibleControlNotices = globalStore[controlNoticeSeenStoreKey];
|
|
486
|
+
const visibleControlNotices = existingVisibleControlNotices instanceof Set ? existingVisibleControlNotices as Set<string> : new Set<string>();
|
|
487
|
+
globalStore[controlNoticeSeenStoreKey] = visibleControlNotices;
|
|
488
|
+
const controlEventHandler = (payload: unknown) => {
|
|
489
|
+
handleSubagentControlNotice({
|
|
490
|
+
pi,
|
|
491
|
+
state,
|
|
492
|
+
visibleControlNotices,
|
|
493
|
+
details: payload as SubagentControlMessageDetails,
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
const eventUnsubscribes = [
|
|
497
|
+
pi.events.on(SUBAGENT_ASYNC_STARTED_EVENT, handleStarted),
|
|
498
|
+
pi.events.on(SUBAGENT_ASYNC_COMPLETE_EVENT, handleComplete),
|
|
499
|
+
pi.events.on(SUBAGENT_CONTROL_EVENT, controlEventHandler),
|
|
500
|
+
];
|
|
501
|
+
globalStore[eventUnsubscribeStoreKey] = eventUnsubscribes;
|
|
502
|
+
|
|
503
|
+
pi.on("tool_result", (event, ctx) => {
|
|
504
|
+
if (event.toolName !== "subagent") return;
|
|
505
|
+
if (!ctx.hasUI) return;
|
|
506
|
+
state.lastUiContext = ctx;
|
|
507
|
+
if (state.asyncJobs.size > 0) {
|
|
508
|
+
renderWidget(ctx, Array.from(state.asyncJobs.values()));
|
|
509
|
+
ctx.ui.requestRender?.();
|
|
510
|
+
ensurePoller();
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
const cleanupSessionArtifacts = (ctx: ExtensionContext) => {
|
|
515
|
+
try {
|
|
516
|
+
const sessionFile = ctx.sessionManager.getSessionFile();
|
|
517
|
+
if (sessionFile) {
|
|
518
|
+
cleanupOldArtifacts(getArtifactsDir(sessionFile), DEFAULT_ARTIFACT_CONFIG.cleanupDays);
|
|
519
|
+
}
|
|
520
|
+
} catch {
|
|
521
|
+
// Cleanup failures should not block session lifecycle events.
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
const resetSessionState = (ctx: ExtensionContext) => {
|
|
526
|
+
state.baseCwd = ctx.cwd;
|
|
527
|
+
state.currentSessionId = resolveCurrentSessionId(ctx.sessionManager);
|
|
528
|
+
state.lastUiContext = ctx;
|
|
529
|
+
cleanupSessionArtifacts(ctx);
|
|
530
|
+
clearPendingForegroundControlNotices(state);
|
|
531
|
+
resetJobs(ctx);
|
|
532
|
+
restoreSlashFinalSnapshots(ctx.sessionManager.getEntries());
|
|
533
|
+
primeExistingResults();
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
pi.on("session_start", (_event, ctx) => {
|
|
537
|
+
resetSessionState(ctx);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
pi.on("session_shutdown", () => {
|
|
541
|
+
for (const unsubscribe of eventUnsubscribes) {
|
|
542
|
+
try {
|
|
543
|
+
unsubscribe();
|
|
544
|
+
} catch {
|
|
545
|
+
// Best effort cleanup during shutdown.
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (globalStore[eventUnsubscribeStoreKey] === eventUnsubscribes) {
|
|
549
|
+
delete globalStore[eventUnsubscribeStoreKey];
|
|
550
|
+
}
|
|
551
|
+
stopResultWatcher();
|
|
552
|
+
if (state.poller) clearInterval(state.poller);
|
|
553
|
+
state.poller = null;
|
|
554
|
+
clearPendingForegroundControlNotices(state);
|
|
555
|
+
for (const timer of state.cleanupTimers.values()) {
|
|
556
|
+
clearTimeout(timer);
|
|
557
|
+
}
|
|
558
|
+
state.cleanupTimers.clear();
|
|
559
|
+
state.asyncJobs.clear();
|
|
560
|
+
clearSlashSnapshots();
|
|
561
|
+
slashBridge.cancelAll();
|
|
562
|
+
slashBridge.dispose();
|
|
563
|
+
promptTemplateBridge.cancelAll();
|
|
564
|
+
promptTemplateBridge.dispose();
|
|
565
|
+
if (globalStore[runtimeCleanupStoreKey] === runtimeCleanup) {
|
|
566
|
+
delete globalStore[runtimeCleanupStoreKey];
|
|
567
|
+
}
|
|
568
|
+
try {
|
|
569
|
+
if (state.lastUiContext?.hasUI) {
|
|
570
|
+
state.lastUiContext.ui.setWidget(WIDGET_KEY, undefined);
|
|
571
|
+
}
|
|
572
|
+
} catch (error) {
|
|
573
|
+
if (!isStaleExtensionContextError(error)) throw error;
|
|
574
|
+
}
|
|
575
|
+
});
|
|
713
576
|
}
|