@bastani/atomic 0.9.16-alpha.1 → 0.9.16-alpha.3

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.
Files changed (714) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/builtin/intercom/broker/spawn.ts +22 -2
  3. package/dist/builtin/intercom/index.bundle.mjs +61694 -0
  4. package/dist/builtin/intercom/package.json +3 -3
  5. package/dist/builtin/mcp/index.bundle.mjs +64901 -0
  6. package/dist/builtin/mcp/package.json +2 -2
  7. package/dist/builtin/subagents/CHANGELOG.md +13 -0
  8. package/dist/builtin/subagents/README.md +17 -105
  9. package/dist/builtin/subagents/package.json +2 -6
  10. package/dist/builtin/subagents/skills/subagent/SKILL.md +18 -88
  11. package/dist/builtin/subagents/src/extension/index.bundle.mjs +85671 -0
  12. package/dist/builtin/web-access/index.bundle.mjs +67413 -0
  13. package/dist/builtin/web-access/package.json +2 -2
  14. package/dist/builtin/workflows/CHANGELOG.md +6 -0
  15. package/dist/builtin/workflows/package.json +3 -3
  16. package/dist/builtin/workflows/skills/bro/LICENSE.txt +21 -0
  17. package/dist/builtin/workflows/skills/bro/SKILL.md +14 -0
  18. package/dist/builtin/workflows/skills/how/LICENSE.txt +21 -0
  19. package/dist/builtin/workflows/skills/how/SKILL.md +162 -0
  20. package/dist/builtin/workflows/skills/how/references/critic-prompt.md +59 -0
  21. package/dist/builtin/workflows/skills/how/references/critique-rubric.md +58 -0
  22. package/dist/builtin/workflows/skills/how/references/explainer-prompt.md +55 -0
  23. package/dist/builtin/workflows/skills/how/references/explorer-prompt.md +52 -0
  24. package/dist/builtin/workflows/skills/teach/LICENSE.txt +21 -0
  25. package/dist/builtin/workflows/skills/teach/SKILL.md +28 -0
  26. package/dist/builtin/workflows/skills/unslop/LICENSE.txt +21 -0
  27. package/dist/builtin/workflows/skills/unslop/SKILL.md +87 -0
  28. package/dist/builtin/workflows/skills/why/LICENSE.txt +21 -0
  29. package/dist/builtin/workflows/skills/why/SKILL.md +267 -0
  30. package/dist/builtin/workflows/skills/why/references/epistemics.md +144 -0
  31. package/dist/builtin/workflows/skills/why/references/investigator-prompt.md +103 -0
  32. package/dist/builtin/workflows/skills/why/references/source-playbook.md +17 -0
  33. package/dist/builtin/workflows/skills/why/references/sources/code-archaeology.md +88 -0
  34. package/dist/builtin/workflows/skills/why/references/sources/databricks.md +70 -0
  35. package/dist/builtin/workflows/skills/why/references/sources/datadog.md +99 -0
  36. package/dist/builtin/workflows/skills/why/references/sources/incident-postmortem.md +15 -0
  37. package/dist/builtin/workflows/skills/why/references/sources/linear.md +48 -0
  38. package/dist/builtin/workflows/skills/why/references/sources/notion.md +55 -0
  39. package/dist/builtin/workflows/skills/why/references/sources/sentry.md +100 -0
  40. package/dist/builtin/workflows/skills/why/references/sources/slack.md +54 -0
  41. package/dist/builtin/workflows/skills/why/references/synthesizer-prompt.md +135 -0
  42. package/dist/builtin/workflows/src/extension/index.bundle.mjs +76391 -96336
  43. package/dist/builtin/workflows/src/index.bundle.mjs +73244 -0
  44. package/dist/core/agent-session-auto-compaction.js +10 -10
  45. package/dist/core/agent-session-auto-compaction.js.map +1 -1
  46. package/dist/core/agent-session-events.d.ts.map +1 -1
  47. package/dist/core/agent-session-events.js +11 -13
  48. package/dist/core/agent-session-events.js.map +1 -1
  49. package/dist/core/agent-session-methods.d.ts +1 -1
  50. package/dist/core/agent-session-methods.d.ts.map +1 -1
  51. package/dist/core/agent-session-methods.js.map +1 -1
  52. package/dist/core/agent-session-models.d.ts.map +1 -1
  53. package/dist/core/agent-session-models.js +5 -7
  54. package/dist/core/agent-session-models.js.map +1 -1
  55. package/dist/core/agent-session-prompt.js +4 -4
  56. package/dist/core/agent-session-prompt.js.map +1 -1
  57. package/dist/core/agent-session-retry.d.ts +4 -4
  58. package/dist/core/agent-session-retry.d.ts.map +1 -1
  59. package/dist/core/agent-session-retry.js +8 -34
  60. package/dist/core/agent-session-retry.js.map +1 -1
  61. package/dist/core/agent-session-tool-hooks.js +4 -4
  62. package/dist/core/agent-session-tool-hooks.js.map +1 -1
  63. package/dist/core/atomic-guide-command.d.ts.map +1 -1
  64. package/dist/core/atomic-guide-command.js +3 -10
  65. package/dist/core/atomic-guide-command.js.map +1 -1
  66. package/dist/core/builtin-install-layout.d.ts +22 -0
  67. package/dist/core/builtin-install-layout.d.ts.map +1 -0
  68. package/dist/core/builtin-install-layout.js +23 -0
  69. package/dist/core/builtin-install-layout.js.map +1 -0
  70. package/dist/core/builtin-packages.d.ts.map +1 -1
  71. package/dist/core/builtin-packages.js +8 -32
  72. package/dist/core/builtin-packages.js.map +1 -1
  73. package/dist/core/slash-commands.d.ts.map +1 -1
  74. package/dist/core/slash-commands.js +0 -3
  75. package/dist/core/slash-commands.js.map +1 -1
  76. package/dist/core/system-prompt.d.ts.map +1 -1
  77. package/dist/core/system-prompt.js +0 -12
  78. package/dist/core/system-prompt.js.map +1 -1
  79. package/dist/modes/interactive-engine/remote-command-catalog.d.ts +1 -1
  80. package/dist/modes/interactive-engine/remote-command-catalog.js +1 -1
  81. package/dist/modes/interactive-engine/remote-command-catalog.js.map +1 -1
  82. package/docs/intercom.md +1 -1
  83. package/docs/settings.md +2 -2
  84. package/docs/subagents.md +6 -7
  85. package/docs/usage.md +0 -9
  86. package/npm-shrinkwrap.json +32 -32
  87. package/package.json +3 -3
  88. package/dist/builtin/intercom/closed-workflow-stage-message.ts +0 -66
  89. package/dist/builtin/intercom/config.ts +0 -121
  90. package/dist/builtin/intercom/contact-supervisor-tool.ts +0 -328
  91. package/dist/builtin/intercom/foreground-detach-handoff.ts +0 -164
  92. package/dist/builtin/intercom/group.ts +0 -85
  93. package/dist/builtin/intercom/inbound-idle-queue.ts +0 -82
  94. package/dist/builtin/intercom/inbound-message-admission.ts +0 -79
  95. package/dist/builtin/intercom/incoming-message-delivery.ts +0 -49
  96. package/dist/builtin/intercom/index-heavy.ts +0 -539
  97. package/dist/builtin/intercom/index.ts +0 -503
  98. package/dist/builtin/intercom/intercom-test-seams.ts +0 -6
  99. package/dist/builtin/intercom/intercom-tool.ts +0 -602
  100. package/dist/builtin/intercom/intercom-utils.ts +0 -427
  101. package/dist/builtin/intercom/late-stage-message-router.ts +0 -148
  102. package/dist/builtin/intercom/lazy-heavy-proxy.ts +0 -108
  103. package/dist/builtin/intercom/lazy-subagent-ack.ts +0 -25
  104. package/dist/builtin/intercom/lazy-tool-execution.ts +0 -39
  105. package/dist/builtin/intercom/lifecycle-lease.ts +0 -51
  106. package/dist/builtin/intercom/lifecycle.ts +0 -144
  107. package/dist/builtin/intercom/overlay.ts +0 -96
  108. package/dist/builtin/intercom/parent-ask-handoff.ts +0 -72
  109. package/dist/builtin/intercom/reconnect-backoff.ts +0 -6
  110. package/dist/builtin/intercom/reply-routing.ts +0 -17
  111. package/dist/builtin/intercom/reply-tracker.ts +0 -110
  112. package/dist/builtin/intercom/reply-waiter.ts +0 -115
  113. package/dist/builtin/intercom/result-renderers.ts +0 -77
  114. package/dist/builtin/intercom/runtime-group.ts +0 -13
  115. package/dist/builtin/intercom/session-target.ts +0 -54
  116. package/dist/builtin/intercom/source-ownership.ts +0 -31
  117. package/dist/builtin/intercom/stable-delivery-retry.ts +0 -32
  118. package/dist/builtin/intercom/subagent-relay.ts +0 -290
  119. package/dist/builtin/intercom/supervisor-authorization-registry.ts +0 -22
  120. package/dist/builtin/intercom/terminal-ordering-barrier.ts +0 -247
  121. package/dist/builtin/intercom/types.ts +0 -66
  122. package/dist/builtin/intercom/ui/compose.ts +0 -159
  123. package/dist/builtin/intercom/ui/inline-message.ts +0 -78
  124. package/dist/builtin/intercom/ui/session-list.ts +0 -195
  125. package/dist/builtin/intercom/workflow-reply-tracker.ts +0 -19
  126. package/dist/builtin/intercom/workflow-stage-admission.ts +0 -43
  127. package/dist/builtin/intercom/workflow-stage-delivery-failure.ts +0 -77
  128. package/dist/builtin/mcp/agent-dir.ts +0 -30
  129. package/dist/builtin/mcp/apps-cancellation.ts +0 -32
  130. package/dist/builtin/mcp/call-tool-result.ts +0 -9
  131. package/dist/builtin/mcp/caller-wait.ts +0 -50
  132. package/dist/builtin/mcp/cli.js +0 -191
  133. package/dist/builtin/mcp/command-registration.ts +0 -82
  134. package/dist/builtin/mcp/commands.ts +0 -424
  135. package/dist/builtin/mcp/config-write-utils.ts +0 -104
  136. package/dist/builtin/mcp/config.ts +0 -498
  137. package/dist/builtin/mcp/consent-manager.ts +0 -64
  138. package/dist/builtin/mcp/direct-tool-executor.ts +0 -280
  139. package/dist/builtin/mcp/direct-tools.ts +0 -216
  140. package/dist/builtin/mcp/errors.ts +0 -219
  141. package/dist/builtin/mcp/glimpse-ui.ts +0 -81
  142. package/dist/builtin/mcp/host-html-template.ts +0 -426
  143. package/dist/builtin/mcp/index.ts +0 -443
  144. package/dist/builtin/mcp/init.ts +0 -319
  145. package/dist/builtin/mcp/lifecycle.ts +0 -93
  146. package/dist/builtin/mcp/logger.ts +0 -169
  147. package/dist/builtin/mcp/mcp-auth-flow.ts +0 -372
  148. package/dist/builtin/mcp/mcp-auth.ts +0 -297
  149. package/dist/builtin/mcp/mcp-callback-server.ts +0 -306
  150. package/dist/builtin/mcp/mcp-oauth-provider.ts +0 -324
  151. package/dist/builtin/mcp/mcp-panel-renderer.ts +0 -243
  152. package/dist/builtin/mcp/mcp-panel-state.ts +0 -227
  153. package/dist/builtin/mcp/mcp-panel-types.ts +0 -86
  154. package/dist/builtin/mcp/mcp-panel.ts +0 -393
  155. package/dist/builtin/mcp/mcp-setup-panel.ts +0 -502
  156. package/dist/builtin/mcp/metadata-cache.ts +0 -201
  157. package/dist/builtin/mcp/metadata-hydration.ts +0 -52
  158. package/dist/builtin/mcp/npx-resolver.ts +0 -425
  159. package/dist/builtin/mcp/oauth-handler.ts +0 -60
  160. package/dist/builtin/mcp/onboarding-state.ts +0 -68
  161. package/dist/builtin/mcp/proxy-auth.ts +0 -61
  162. package/dist/builtin/mcp/proxy-call.ts +0 -447
  163. package/dist/builtin/mcp/proxy-connect.ts +0 -78
  164. package/dist/builtin/mcp/proxy-info-modes.ts +0 -409
  165. package/dist/builtin/mcp/proxy-modes.ts +0 -3
  166. package/dist/builtin/mcp/proxy-types.ts +0 -3
  167. package/dist/builtin/mcp/resource-tools.ts +0 -17
  168. package/dist/builtin/mcp/sampling-handler.ts +0 -273
  169. package/dist/builtin/mcp/server-manager.ts +0 -372
  170. package/dist/builtin/mcp/session-cleanup-barrier.ts +0 -43
  171. package/dist/builtin/mcp/startup-warmup.ts +0 -110
  172. package/dist/builtin/mcp/state-lease.ts +0 -12
  173. package/dist/builtin/mcp/state.ts +0 -41
  174. package/dist/builtin/mcp/tool-call-timeout.ts +0 -101
  175. package/dist/builtin/mcp/tool-metadata.ts +0 -152
  176. package/dist/builtin/mcp/tool-registrar.ts +0 -46
  177. package/dist/builtin/mcp/tool-result-renderer.ts +0 -66
  178. package/dist/builtin/mcp/types.ts +0 -445
  179. package/dist/builtin/mcp/ui-resource-handler.ts +0 -145
  180. package/dist/builtin/mcp/ui-server-http.ts +0 -81
  181. package/dist/builtin/mcp/ui-server.ts +0 -499
  182. package/dist/builtin/mcp/ui-session.ts +0 -378
  183. package/dist/builtin/mcp/ui-stream-types.ts +0 -89
  184. package/dist/builtin/mcp/utils.ts +0 -165
  185. package/dist/builtin/subagents/prompts/gather-context-and-clarify.md +0 -27
  186. package/dist/builtin/subagents/prompts/parallel-cleanup.md +0 -61
  187. package/dist/builtin/subagents/prompts/parallel-context-build.md +0 -43
  188. package/dist/builtin/subagents/prompts/parallel-handoff-plan.md +0 -47
  189. package/dist/builtin/subagents/prompts/parallel-research.md +0 -34
  190. package/dist/builtin/subagents/prompts/parallel-review.md +0 -47
  191. package/dist/builtin/subagents/prompts/review-loop.md +0 -39
  192. package/dist/builtin/subagents/src/agents/agent-discovery.ts +0 -116
  193. package/dist/builtin/subagents/src/agents/agent-loaders.ts +0 -216
  194. package/dist/builtin/subagents/src/agents/agent-management-helpers.ts +0 -221
  195. package/dist/builtin/subagents/src/agents/agent-management.ts +0 -315
  196. package/dist/builtin/subagents/src/agents/agent-overrides.ts +0 -450
  197. package/dist/builtin/subagents/src/agents/agent-paths.ts +0 -69
  198. package/dist/builtin/subagents/src/agents/agent-scope.ts +0 -6
  199. package/dist/builtin/subagents/src/agents/agent-selection.ts +0 -23
  200. package/dist/builtin/subagents/src/agents/agent-serializer.ts +0 -113
  201. package/dist/builtin/subagents/src/agents/agent-types.ts +0 -97
  202. package/dist/builtin/subagents/src/agents/agents.ts +0 -25
  203. package/dist/builtin/subagents/src/agents/frontmatter.ts +0 -74
  204. package/dist/builtin/subagents/src/agents/identity.ts +0 -37
  205. package/dist/builtin/subagents/src/agents/skills-paths.ts +0 -380
  206. package/dist/builtin/subagents/src/agents/skills.ts +0 -398
  207. package/dist/builtin/subagents/src/extension/api-lifecycle.ts +0 -64
  208. package/dist/builtin/subagents/src/extension/config.ts +0 -16
  209. package/dist/builtin/subagents/src/extension/control-notices.ts +0 -91
  210. package/dist/builtin/subagents/src/extension/doctor.ts +0 -188
  211. package/dist/builtin/subagents/src/extension/index.ts +0 -420
  212. package/dist/builtin/subagents/src/extension/notification-content.ts +0 -85
  213. package/dist/builtin/subagents/src/extension/prompt-guidance.ts +0 -11
  214. package/dist/builtin/subagents/src/extension/schemas.ts +0 -208
  215. package/dist/builtin/subagents/src/extension/startup-maintenance.ts +0 -133
  216. package/dist/builtin/subagents/src/extension/tool-description.ts +0 -19
  217. package/dist/builtin/subagents/src/extension/tool-rendering.ts +0 -53
  218. package/dist/builtin/subagents/src/intercom/intercom-bridge.ts +0 -429
  219. package/dist/builtin/subagents/src/intercom/result-intercom.ts +0 -246
  220. package/dist/builtin/subagents/src/intercom/supervisor-authorization.ts +0 -30
  221. package/dist/builtin/subagents/src/runs/foreground/completion-notification.ts +0 -42
  222. package/dist/builtin/subagents/src/runs/foreground/detached-cleanup-barrier.ts +0 -26
  223. package/dist/builtin/subagents/src/runs/foreground/execution-detach-reservations.ts +0 -58
  224. package/dist/builtin/subagents/src/runs/foreground/execution-detach-route.ts +0 -19
  225. package/dist/builtin/subagents/src/runs/foreground/execution-intercom-detach.ts +0 -51
  226. package/dist/builtin/subagents/src/runs/foreground/execution-parent-ask-handoff.ts +0 -78
  227. package/dist/builtin/subagents/src/runs/foreground/execution-run-sync.ts +0 -1
  228. package/dist/builtin/subagents/src/runs/foreground/execution-updates.ts +0 -26
  229. package/dist/builtin/subagents/src/runs/foreground/execution-utils.ts +0 -61
  230. package/dist/builtin/subagents/src/runs/foreground/execution.ts +0 -6
  231. package/dist/builtin/subagents/src/runs/foreground/inprocess-run-sync.ts +0 -512
  232. package/dist/builtin/subagents/src/runs/foreground/notify.ts +0 -355
  233. package/dist/builtin/subagents/src/runs/foreground/parent-ask-output.ts +0 -48
  234. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-burst-display.ts +0 -46
  235. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-burst.ts +0 -403
  236. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-context.ts +0 -223
  237. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-cwd.ts +0 -6
  238. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-input.ts +0 -139
  239. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-live-update.ts +0 -11
  240. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +0 -268
  241. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel.ts +0 -327
  242. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parent-ask-projection.ts +0 -11
  243. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-runtime.ts +0 -12
  244. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +0 -350
  245. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-status.ts +0 -246
  246. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-types.ts +0 -131
  247. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-worktree.ts +0 -102
  248. package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +0 -254
  249. package/dist/builtin/subagents/src/runs/inprocess/child-policy.ts +0 -27
  250. package/dist/builtin/subagents/src/runs/inprocess/control-registry.ts +0 -55
  251. package/dist/builtin/subagents/src/runs/inprocess/control-status.ts +0 -72
  252. package/dist/builtin/subagents/src/runs/inprocess/index.ts +0 -27
  253. package/dist/builtin/subagents/src/runs/inprocess/prompt-behavior.ts +0 -168
  254. package/dist/builtin/subagents/src/runs/inprocess/runner.ts +0 -1280
  255. package/dist/builtin/subagents/src/runs/inprocess/runtime-support/temp-cleanup.ts +0 -69
  256. package/dist/builtin/subagents/src/runs/inprocess.ts +0 -1
  257. package/dist/builtin/subagents/src/runs/shared/intercom-group.ts +0 -67
  258. package/dist/builtin/subagents/src/runs/shared/long-running-guard.ts +0 -182
  259. package/dist/builtin/subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -391
  260. package/dist/builtin/subagents/src/runs/shared/model-candidate-filter.ts +0 -56
  261. package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +0 -88
  262. package/dist/builtin/subagents/src/runs/shared/parallel-utils.ts +0 -70
  263. package/dist/builtin/subagents/src/runs/shared/progress-trend.ts +0 -69
  264. package/dist/builtin/subagents/src/runs/shared/run-history.ts +0 -64
  265. package/dist/builtin/subagents/src/runs/shared/single-output.ts +0 -169
  266. package/dist/builtin/subagents/src/runs/shared/subagent-control.ts +0 -234
  267. package/dist/builtin/subagents/src/runs/shared/worktree-post-create.ts +0 -111
  268. package/dist/builtin/subagents/src/runs/shared/worktree-root.ts +0 -67
  269. package/dist/builtin/subagents/src/runs/shared/worktree.ts +0 -552
  270. package/dist/builtin/subagents/src/shared/artifacts.ts +0 -240
  271. package/dist/builtin/subagents/src/shared/atomic-json.ts +0 -16
  272. package/dist/builtin/subagents/src/shared/event-jsonl-writer.ts +0 -330
  273. package/dist/builtin/subagents/src/shared/exclusive-file-publication.ts +0 -44
  274. package/dist/builtin/subagents/src/shared/fast-mode.ts +0 -87
  275. package/dist/builtin/subagents/src/shared/file-coalescer.ts +0 -40
  276. package/dist/builtin/subagents/src/shared/fork-context.ts +0 -79
  277. package/dist/builtin/subagents/src/shared/formatters.ts +0 -89
  278. package/dist/builtin/subagents/src/shared/jsonl-writer.ts +0 -83
  279. package/dist/builtin/subagents/src/shared/model-info.ts +0 -101
  280. package/dist/builtin/subagents/src/shared/model-resolution.ts +0 -78
  281. package/dist/builtin/subagents/src/shared/session-identity.ts +0 -10
  282. package/dist/builtin/subagents/src/shared/session-tokens.ts +0 -45
  283. package/dist/builtin/subagents/src/shared/settings.ts +0 -118
  284. package/dist/builtin/subagents/src/shared/status-format.ts +0 -50
  285. package/dist/builtin/subagents/src/shared/types-config.ts +0 -206
  286. package/dist/builtin/subagents/src/shared/types-depth.ts +0 -46
  287. package/dist/builtin/subagents/src/shared/types-foreground-state.ts +0 -48
  288. package/dist/builtin/subagents/src/shared/types-output.ts +0 -63
  289. package/dist/builtin/subagents/src/shared/types-results.ts +0 -259
  290. package/dist/builtin/subagents/src/shared/types-runtime.ts +0 -115
  291. package/dist/builtin/subagents/src/shared/types.ts +0 -13
  292. package/dist/builtin/subagents/src/shared/utils.ts +0 -342
  293. package/dist/builtin/subagents/src/slash/bridge-settlement.ts +0 -87
  294. package/dist/builtin/subagents/src/slash/prompt-template-bridge.ts +0 -455
  295. package/dist/builtin/subagents/src/slash/slash-bridge.ts +0 -194
  296. package/dist/builtin/subagents/src/slash/slash-commands.ts +0 -469
  297. package/dist/builtin/subagents/src/slash/slash-live-state.ts +0 -259
  298. package/dist/builtin/subagents/src/tui/render-event-formatting.ts +0 -7
  299. package/dist/builtin/subagents/src/tui/render-helpers.ts +0 -90
  300. package/dist/builtin/subagents/src/tui/render-layout.ts +0 -157
  301. package/dist/builtin/subagents/src/tui/render-progress.ts +0 -89
  302. package/dist/builtin/subagents/src/tui/render-result-animation.ts +0 -47
  303. package/dist/builtin/subagents/src/tui/render-result-compact.ts +0 -248
  304. package/dist/builtin/subagents/src/tui/render-result.ts +0 -438
  305. package/dist/builtin/subagents/src/tui/render-stable-output.ts +0 -50
  306. package/dist/builtin/subagents/src/tui/render-status-progress.ts +0 -168
  307. package/dist/builtin/subagents/src/tui/render.ts +0 -23
  308. package/dist/builtin/web-access/activity.ts +0 -101
  309. package/dist/builtin/web-access/chrome-cookies.ts +0 -323
  310. package/dist/builtin/web-access/code-search.ts +0 -107
  311. package/dist/builtin/web-access/config-paths.ts +0 -11
  312. package/dist/builtin/web-access/content-tools.ts +0 -354
  313. package/dist/builtin/web-access/curator-page-assets/script-1.ts +0 -400
  314. package/dist/builtin/web-access/curator-page-assets/script-2.ts +0 -400
  315. package/dist/builtin/web-access/curator-page-assets/script-3.ts +0 -400
  316. package/dist/builtin/web-access/curator-page-assets/script-4.ts +0 -400
  317. package/dist/builtin/web-access/curator-page-assets/script-5.ts +0 -398
  318. package/dist/builtin/web-access/curator-page-assets/styles-1.ts +0 -394
  319. package/dist/builtin/web-access/curator-page-assets/styles-2.ts +0 -394
  320. package/dist/builtin/web-access/curator-page-assets/styles-3.ts +0 -393
  321. package/dist/builtin/web-access/curator-page.ts +0 -196
  322. package/dist/builtin/web-access/curator-server-helpers.ts +0 -115
  323. package/dist/builtin/web-access/curator-server.ts +0 -494
  324. package/dist/builtin/web-access/exa-mcp.ts +0 -218
  325. package/dist/builtin/web-access/exa.ts +0 -317
  326. package/dist/builtin/web-access/extract-frames.ts +0 -229
  327. package/dist/builtin/web-access/extract.ts +0 -500
  328. package/dist/builtin/web-access/flat-string.ts +0 -37
  329. package/dist/builtin/web-access/gemini-api.ts +0 -111
  330. package/dist/builtin/web-access/gemini-search.ts +0 -363
  331. package/dist/builtin/web-access/gemini-url-context.ts +0 -126
  332. package/dist/builtin/web-access/gemini-web-config.ts +0 -53
  333. package/dist/builtin/web-access/gemini-web.ts +0 -397
  334. package/dist/builtin/web-access/github-api.ts +0 -198
  335. package/dist/builtin/web-access/github-config.ts +0 -156
  336. package/dist/builtin/web-access/github-extract.ts +0 -487
  337. package/dist/builtin/web-access/index-heavy.ts +0 -164
  338. package/dist/builtin/web-access/index.ts +0 -401
  339. package/dist/builtin/web-access/lifecycle-lease.ts +0 -38
  340. package/dist/builtin/web-access/pdf-extract.ts +0 -192
  341. package/dist/builtin/web-access/perplexity.ts +0 -194
  342. package/dist/builtin/web-access/result-renderers.ts +0 -366
  343. package/dist/builtin/web-access/rsc-extract.ts +0 -338
  344. package/dist/builtin/web-access/storage.ts +0 -72
  345. package/dist/builtin/web-access/subprocess.ts +0 -102
  346. package/dist/builtin/web-access/summary-review.ts +0 -287
  347. package/dist/builtin/web-access/utils.ts +0 -44
  348. package/dist/builtin/web-access/video-extract.ts +0 -375
  349. package/dist/builtin/web-access/web-search-activity.ts +0 -102
  350. package/dist/builtin/web-access/web-search-browser.ts +0 -124
  351. package/dist/builtin/web-access/web-search-command.ts +0 -242
  352. package/dist/builtin/web-access/web-search-config.ts +0 -157
  353. package/dist/builtin/web-access/web-search-curator.ts +0 -214
  354. package/dist/builtin/web-access/web-search-features.ts +0 -181
  355. package/dist/builtin/web-access/web-search-formatting.ts +0 -117
  356. package/dist/builtin/web-access/web-search-return.ts +0 -143
  357. package/dist/builtin/web-access/web-search-summary.ts +0 -177
  358. package/dist/builtin/web-access/web-search-tool.ts +0 -286
  359. package/dist/builtin/web-access/web-search-types.ts +0 -50
  360. package/dist/builtin/web-access/web-search-workflow.ts +0 -10
  361. package/dist/builtin/web-access/youtube-extract.ts +0 -309
  362. package/dist/builtin/workflows/src/authoring/keep-context.ts +0 -46
  363. package/dist/builtin/workflows/src/authoring/typebox-defaults.d.ts +0 -41
  364. package/dist/builtin/workflows/src/authoring/typebox-defaults.ts +0 -180
  365. package/dist/builtin/workflows/src/authoring/workflow.ts +0 -206
  366. package/dist/builtin/workflows/src/durable/backend.ts +0 -598
  367. package/dist/builtin/workflows/src/durable/boundary-lifecycle.ts +0 -172
  368. package/dist/builtin/workflows/src/durable/boundary-topology.ts +0 -475
  369. package/dist/builtin/workflows/src/durable/child-invocation.ts +0 -14
  370. package/dist/builtin/workflows/src/durable/child-primitive.ts +0 -124
  371. package/dist/builtin/workflows/src/durable/completed-catalog-stage-groups.ts +0 -385
  372. package/dist/builtin/workflows/src/durable/completed-catalog.ts +0 -685
  373. package/dist/builtin/workflows/src/durable/completed-inspection.ts +0 -157
  374. package/dist/builtin/workflows/src/durable/completed-subtree.ts +0 -50
  375. package/dist/builtin/workflows/src/durable/dbos-backend.ts +0 -580
  376. package/dist/builtin/workflows/src/durable/dbos-embedded-postgres-root.ts +0 -681
  377. package/dist/builtin/workflows/src/durable/dbos-embedded-postgres.ts +0 -717
  378. package/dist/builtin/workflows/src/durable/dbos-envelope.ts +0 -516
  379. package/dist/builtin/workflows/src/durable/dbos-lifecycle.ts +0 -208
  380. package/dist/builtin/workflows/src/durable/dbos-local-postgres.ts +0 -166
  381. package/dist/builtin/workflows/src/durable/dbos-metadata.ts +0 -196
  382. package/dist/builtin/workflows/src/durable/dbos-process-owner.ts +0 -87
  383. package/dist/builtin/workflows/src/durable/dbos-prompt-reservations.ts +0 -377
  384. package/dist/builtin/workflows/src/durable/dbos-registration-diagnostics.ts +0 -113
  385. package/dist/builtin/workflows/src/durable/dbos-sdk-handle.ts +0 -182
  386. package/dist/builtin/workflows/src/durable/dbos-status-transition.ts +0 -67
  387. package/dist/builtin/workflows/src/durable/dbos-tombstone.ts +0 -27
  388. package/dist/builtin/workflows/src/durable/durable-hash.ts +0 -18
  389. package/dist/builtin/workflows/src/durable/factory.ts +0 -93
  390. package/dist/builtin/workflows/src/durable/format-version.ts +0 -6
  391. package/dist/builtin/workflows/src/durable/index.ts +0 -82
  392. package/dist/builtin/workflows/src/durable/local-command.ts +0 -135
  393. package/dist/builtin/workflows/src/durable/prompt-reservation-state.ts +0 -184
  394. package/dist/builtin/workflows/src/durable/prompt-reservations.ts +0 -36
  395. package/dist/builtin/workflows/src/durable/resume-catalog.ts +0 -20
  396. package/dist/builtin/workflows/src/durable/resume-eligibility.ts +0 -106
  397. package/dist/builtin/workflows/src/durable/resume-runtime.ts +0 -344
  398. package/dist/builtin/workflows/src/durable/retention-policy.ts +0 -43
  399. package/dist/builtin/workflows/src/durable/run-timing.ts +0 -151
  400. package/dist/builtin/workflows/src/durable/scoped-backend.ts +0 -308
  401. package/dist/builtin/workflows/src/durable/stage-primitive.ts +0 -553
  402. package/dist/builtin/workflows/src/durable/stage-topology-validation.ts +0 -247
  403. package/dist/builtin/workflows/src/durable/stage-topology.ts +0 -53
  404. package/dist/builtin/workflows/src/durable/targeted-inspection.ts +0 -110
  405. package/dist/builtin/workflows/src/durable/tool-failure-checkpoint.ts +0 -54
  406. package/dist/builtin/workflows/src/durable/tool-outcome.ts +0 -130
  407. package/dist/builtin/workflows/src/durable/tool-primitive.ts +0 -861
  408. package/dist/builtin/workflows/src/durable/types.ts +0 -343
  409. package/dist/builtin/workflows/src/durable/ui-primitive.ts +0 -263
  410. package/dist/builtin/workflows/src/durable/workflow-child-result.ts +0 -63
  411. package/dist/builtin/workflows/src/durable/workflow-heartbeat-anchor.ts +0 -153
  412. package/dist/builtin/workflows/src/durable/workflow-status-transition.ts +0 -31
  413. package/dist/builtin/workflows/src/engine/graph-inference.ts +0 -100
  414. package/dist/builtin/workflows/src/engine/options.ts +0 -44
  415. package/dist/builtin/workflows/src/engine/primitives/chain.ts +0 -34
  416. package/dist/builtin/workflows/src/engine/primitives/exit.ts +0 -2
  417. package/dist/builtin/workflows/src/engine/primitives/parallel.ts +0 -74
  418. package/dist/builtin/workflows/src/engine/primitives/task.ts +0 -127
  419. package/dist/builtin/workflows/src/engine/primitives/ui.ts +0 -54
  420. package/dist/builtin/workflows/src/engine/primitives/workflow.ts +0 -219
  421. package/dist/builtin/workflows/src/engine/replay.ts +0 -8
  422. package/dist/builtin/workflows/src/engine/run-budget.ts +0 -308
  423. package/dist/builtin/workflows/src/engine/run-durable-admission.ts +0 -50
  424. package/dist/builtin/workflows/src/engine/run-durable-finalize.ts +0 -97
  425. package/dist/builtin/workflows/src/engine/run-durable-stage-session.ts +0 -65
  426. package/dist/builtin/workflows/src/engine/run-durable-topology.ts +0 -295
  427. package/dist/builtin/workflows/src/engine/run-returned-status.ts +0 -86
  428. package/dist/builtin/workflows/src/engine/run-terminal-event.ts +0 -39
  429. package/dist/builtin/workflows/src/engine/run-terminal-failure.ts +0 -53
  430. package/dist/builtin/workflows/src/engine/run-tool-admission-boundary.ts +0 -99
  431. package/dist/builtin/workflows/src/engine/run-tool-control-registry.ts +0 -187
  432. package/dist/builtin/workflows/src/engine/run-tool-execution-tracker.ts +0 -164
  433. package/dist/builtin/workflows/src/engine/run-tool-node-lifecycle.ts +0 -158
  434. package/dist/builtin/workflows/src/engine/run.ts +0 -841
  435. package/dist/builtin/workflows/src/engine/runtime.ts +0 -220
  436. package/dist/builtin/workflows/src/engine/workflow-activity.ts +0 -13
  437. package/dist/builtin/workflows/src/engine/workflow-tool-abort.ts +0 -92
  438. package/dist/builtin/workflows/src/extension/adopt-session-run-state.ts +0 -20
  439. package/dist/builtin/workflows/src/extension/atomic-stage-session.ts +0 -168
  440. package/dist/builtin/workflows/src/extension/background-ui-adapter.ts +0 -154
  441. package/dist/builtin/workflows/src/extension/companions.ts +0 -210
  442. package/dist/builtin/workflows/src/extension/completed-stage-intercom-ask.ts +0 -167
  443. package/dist/builtin/workflows/src/extension/config-file-loader.ts +0 -185
  444. package/dist/builtin/workflows/src/extension/config-loader.ts +0 -439
  445. package/dist/builtin/workflows/src/extension/discovery-loaders.ts +0 -112
  446. package/dist/builtin/workflows/src/extension/discovery.ts +0 -424
  447. package/dist/builtin/workflows/src/extension/dispatcher.ts +0 -273
  448. package/dist/builtin/workflows/src/extension/extension-factory.ts +0 -133
  449. package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +0 -174
  450. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +0 -596
  451. package/dist/builtin/workflows/src/extension/hil-answer-notifications.ts +0 -367
  452. package/dist/builtin/workflows/src/extension/index.ts +0 -42
  453. package/dist/builtin/workflows/src/extension/lifecycle-notification-delivery.ts +0 -83
  454. package/dist/builtin/workflows/src/extension/lifecycle-notifications.ts +0 -849
  455. package/dist/builtin/workflows/src/extension/mcp.ts +0 -121
  456. package/dist/builtin/workflows/src/extension/postmortem-deps.ts +0 -70
  457. package/dist/builtin/workflows/src/extension/public-types.ts +0 -234
  458. package/dist/builtin/workflows/src/extension/render-call.ts +0 -115
  459. package/dist/builtin/workflows/src/extension/render-component.ts +0 -12
  460. package/dist/builtin/workflows/src/extension/render-result.ts +0 -558
  461. package/dist/builtin/workflows/src/extension/renderers.ts +0 -89
  462. package/dist/builtin/workflows/src/extension/runtime-active-block-claim.ts +0 -78
  463. package/dist/builtin/workflows/src/extension/runtime-durable-resume.ts +0 -174
  464. package/dist/builtin/workflows/src/extension/runtime.ts +0 -439
  465. package/dist/builtin/workflows/src/extension/status-writer.ts +0 -182
  466. package/dist/builtin/workflows/src/extension/ui-surface.ts +0 -387
  467. package/dist/builtin/workflows/src/extension/wiring.ts +0 -490
  468. package/dist/builtin/workflows/src/extension/workflow-command-completions.ts +0 -129
  469. package/dist/builtin/workflows/src/extension/workflow-command-registration.ts +0 -296
  470. package/dist/builtin/workflows/src/extension/workflow-command-surfaces.ts +0 -114
  471. package/dist/builtin/workflows/src/extension/workflow-command-utils.ts +0 -175
  472. package/dist/builtin/workflows/src/extension/workflow-durable-resume-command.ts +0 -270
  473. package/dist/builtin/workflows/src/extension/workflow-heartbeat-delivery.ts +0 -241
  474. package/dist/builtin/workflows/src/extension/workflow-heartbeat-notice.ts +0 -115
  475. package/dist/builtin/workflows/src/extension/workflow-heartbeat-scheduler.ts +0 -962
  476. package/dist/builtin/workflows/src/extension/workflow-model-catalog.ts +0 -24
  477. package/dist/builtin/workflows/src/extension/workflow-module-loader.ts +0 -162
  478. package/dist/builtin/workflows/src/extension/workflow-policy.ts +0 -13
  479. package/dist/builtin/workflows/src/extension/workflow-ports.ts +0 -45
  480. package/dist/builtin/workflows/src/extension/workflow-prompts.ts +0 -73
  481. package/dist/builtin/workflows/src/extension/workflow-reload-coordinator.ts +0 -66
  482. package/dist/builtin/workflows/src/extension/workflow-reload-report.ts +0 -42
  483. package/dist/builtin/workflows/src/extension/workflow-request-abort.ts +0 -15
  484. package/dist/builtin/workflows/src/extension/workflow-resume-picker-rows.ts +0 -96
  485. package/dist/builtin/workflows/src/extension/workflow-resume-shadow.ts +0 -53
  486. package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +0 -562
  487. package/dist/builtin/workflows/src/extension/workflow-schema.ts +0 -192
  488. package/dist/builtin/workflows/src/extension/workflow-stage-results.ts +0 -252
  489. package/dist/builtin/workflows/src/extension/workflow-status-summary.ts +0 -276
  490. package/dist/builtin/workflows/src/extension/workflow-targets.ts +0 -210
  491. package/dist/builtin/workflows/src/extension/workflow-tool-content.ts +0 -265
  492. package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +0 -547
  493. package/dist/builtin/workflows/src/extension/workflow-tool-inspection.ts +0 -153
  494. package/dist/builtin/workflows/src/extension/workflow-tool-registration.ts +0 -145
  495. package/dist/builtin/workflows/src/extension/workflow-tool-send.ts +0 -488
  496. package/dist/builtin/workflows/src/extension/workflow-tool.ts +0 -188
  497. package/dist/builtin/workflows/src/index.ts +0 -8
  498. package/dist/builtin/workflows/src/intercom/intercom-bridge.ts +0 -90
  499. package/dist/builtin/workflows/src/intercom/intercom-routing.ts +0 -131
  500. package/dist/builtin/workflows/src/intercom/result-intercom.ts +0 -271
  501. package/dist/builtin/workflows/src/runs/background/cancellation-registry.ts +0 -135
  502. package/dist/builtin/workflows/src/runs/background/durable-resume-transition.ts +0 -63
  503. package/dist/builtin/workflows/src/runs/background/job-tracker.ts +0 -125
  504. package/dist/builtin/workflows/src/runs/background/quit-tool-node.ts +0 -71
  505. package/dist/builtin/workflows/src/runs/background/quit.ts +0 -417
  506. package/dist/builtin/workflows/src/runs/background/resume-acknowledgements.ts +0 -99
  507. package/dist/builtin/workflows/src/runs/background/run-inspect.ts +0 -126
  508. package/dist/builtin/workflows/src/runs/background/runner.ts +0 -185
  509. package/dist/builtin/workflows/src/runs/background/startup-admission.ts +0 -73
  510. package/dist/builtin/workflows/src/runs/background/status.ts +0 -511
  511. package/dist/builtin/workflows/src/runs/background/workflow-lifecycle-aggregate.ts +0 -43
  512. package/dist/builtin/workflows/src/runs/foreground/executor-abort.ts +0 -441
  513. package/dist/builtin/workflows/src/runs/foreground/executor-child-boundary.ts +0 -263
  514. package/dist/builtin/workflows/src/runs/foreground/executor-child-helpers.ts +0 -79
  515. package/dist/builtin/workflows/src/runs/foreground/executor-child-workflow.ts +0 -1
  516. package/dist/builtin/workflows/src/runs/foreground/executor-continuation.ts +0 -207
  517. package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +0 -321
  518. package/dist/builtin/workflows/src/runs/foreground/executor-exit-manager.ts +0 -224
  519. package/dist/builtin/workflows/src/runs/foreground/executor-hil.ts +0 -403
  520. package/dist/builtin/workflows/src/runs/foreground/executor-inputs.ts +0 -86
  521. package/dist/builtin/workflows/src/runs/foreground/executor-lifecycle.ts +0 -491
  522. package/dist/builtin/workflows/src/runs/foreground/executor-outputs.ts +0 -156
  523. package/dist/builtin/workflows/src/runs/foreground/executor-prompt-nodes.ts +0 -379
  524. package/dist/builtin/workflows/src/runs/foreground/executor-queued-user-message.ts +0 -75
  525. package/dist/builtin/workflows/src/runs/foreground/executor-run-finalizers.ts +0 -144
  526. package/dist/builtin/workflows/src/runs/foreground/executor-run.ts +0 -1
  527. package/dist/builtin/workflows/src/runs/foreground/executor-scheduler.ts +0 -206
  528. package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +0 -434
  529. package/dist/builtin/workflows/src/runs/foreground/executor-stage-context.ts +0 -153
  530. package/dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts +0 -225
  531. package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +0 -473
  532. package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +0 -156
  533. package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +0 -72
  534. package/dist/builtin/workflows/src/runs/foreground/executor-task-context.ts +0 -2
  535. package/dist/builtin/workflows/src/runs/foreground/executor-task-prompts.ts +0 -226
  536. package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +0 -186
  537. package/dist/builtin/workflows/src/runs/foreground/executor.ts +0 -25
  538. package/dist/builtin/workflows/src/runs/foreground/postmortem-stage-chat.ts +0 -245
  539. package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +0 -466
  540. package/dist/builtin/workflows/src/runs/foreground/stage-delivery-activity.ts +0 -86
  541. package/dist/builtin/workflows/src/runs/foreground/stage-queued-user-messages.ts +0 -95
  542. package/dist/builtin/workflows/src/runs/foreground/stage-runner-candidate.ts +0 -21
  543. package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +0 -330
  544. package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +0 -1472
  545. package/dist/builtin/workflows/src/runs/foreground/stage-runner-message-admission.ts +0 -196
  546. package/dist/builtin/workflows/src/runs/foreground/stage-runner-messages.ts +0 -177
  547. package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +0 -97
  548. package/dist/builtin/workflows/src/runs/foreground/stage-runner-output.ts +0 -278
  549. package/dist/builtin/workflows/src/runs/foreground/stage-runner-pause.ts +0 -206
  550. package/dist/builtin/workflows/src/runs/foreground/stage-runner-replacement.ts +0 -41
  551. package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +0 -134
  552. package/dist/builtin/workflows/src/runs/foreground/stage-runner-session-options.ts +0 -38
  553. package/dist/builtin/workflows/src/runs/foreground/stage-runner-session.ts +0 -66
  554. package/dist/builtin/workflows/src/runs/foreground/stage-runner-structured-output.ts +0 -120
  555. package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +0 -211
  556. package/dist/builtin/workflows/src/runs/foreground/stage-runner-unresolved-overflow.ts +0 -42
  557. package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +0 -22
  558. package/dist/builtin/workflows/src/runs/foreground/stage-session-heartbeat.ts +0 -88
  559. package/dist/builtin/workflows/src/runs/foreground/stage-tool-execution-buffer.ts +0 -49
  560. package/dist/builtin/workflows/src/runs/shared/concurrency.ts +0 -76
  561. package/dist/builtin/workflows/src/runs/shared/graph-inference.ts +0 -2
  562. package/dist/builtin/workflows/src/runs/shared/model-fallback-candidates.ts +0 -325
  563. package/dist/builtin/workflows/src/runs/shared/model-fallback-failures.ts +0 -19
  564. package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +0 -2
  565. package/dist/builtin/workflows/src/runs/shared/prompt-callsite.ts +0 -96
  566. package/dist/builtin/workflows/src/runs/shared/retry.ts +0 -44
  567. package/dist/builtin/workflows/src/runs/shared/validate-inputs.ts +0 -111
  568. package/dist/builtin/workflows/src/runs/shared/worktree-cache-lifecycle.ts +0 -23
  569. package/dist/builtin/workflows/src/runs/shared/worktree-cwd.ts +0 -116
  570. package/dist/builtin/workflows/src/runs/shared/worktree-diff.ts +0 -172
  571. package/dist/builtin/workflows/src/runs/shared/worktree-generation.ts +0 -57
  572. package/dist/builtin/workflows/src/runs/shared/worktree-git-runner.ts +0 -107
  573. package/dist/builtin/workflows/src/runs/shared/worktree-git.ts +0 -407
  574. package/dist/builtin/workflows/src/runs/shared/worktree-post-create.ts +0 -137
  575. package/dist/builtin/workflows/src/runs/shared/worktree-root.ts +0 -84
  576. package/dist/builtin/workflows/src/runs/shared/worktree-setup.ts +0 -372
  577. package/dist/builtin/workflows/src/runs/shared/worktree-types.ts +0 -102
  578. package/dist/builtin/workflows/src/runs/shared/worktree.ts +0 -21
  579. package/dist/builtin/workflows/src/sdk-surface.ts +0 -70
  580. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +0 -403
  581. package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +0 -489
  582. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +0 -327
  583. package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +0 -437
  584. package/dist/builtin/workflows/src/shared/budget-meter.ts +0 -34
  585. package/dist/builtin/workflows/src/shared/budget.d.ts +0 -67
  586. package/dist/builtin/workflows/src/shared/budget.ts +0 -127
  587. package/dist/builtin/workflows/src/shared/expanded-workflow-graph.ts +0 -434
  588. package/dist/builtin/workflows/src/shared/flat-string.ts +0 -33
  589. package/dist/builtin/workflows/src/shared/graph-store-snapshot.ts +0 -188
  590. package/dist/builtin/workflows/src/shared/intercom-group.ts +0 -58
  591. package/dist/builtin/workflows/src/shared/persistence-compaction-policy.ts +0 -72
  592. package/dist/builtin/workflows/src/shared/persistence-restore-helpers.ts +0 -613
  593. package/dist/builtin/workflows/src/shared/persistence-restore.ts +0 -306
  594. package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +0 -303
  595. package/dist/builtin/workflows/src/shared/prompt-answer.ts +0 -130
  596. package/dist/builtin/workflows/src/shared/prompt-callsite-context.ts +0 -13
  597. package/dist/builtin/workflows/src/shared/render-inputs-schema.ts +0 -161
  598. package/dist/builtin/workflows/src/shared/resume-continuation.ts +0 -2
  599. package/dist/builtin/workflows/src/shared/returned-run-status.ts +0 -164
  600. package/dist/builtin/workflows/src/shared/run-id.ts +0 -36
  601. package/dist/builtin/workflows/src/shared/run-indicator-status.ts +0 -75
  602. package/dist/builtin/workflows/src/shared/run-visibility.ts +0 -9
  603. package/dist/builtin/workflows/src/shared/schema-introspection.ts +0 -111
  604. package/dist/builtin/workflows/src/shared/serializable.ts +0 -118
  605. package/dist/builtin/workflows/src/shared/session-scoped-singleton.ts +0 -98
  606. package/dist/builtin/workflows/src/shared/session-transcript.ts +0 -79
  607. package/dist/builtin/workflows/src/shared/stage-prompt.ts +0 -338
  608. package/dist/builtin/workflows/src/shared/stage-ui-broker.ts +0 -340
  609. package/dist/builtin/workflows/src/shared/store-factory.ts +0 -26
  610. package/dist/builtin/workflows/src/shared/store-internal.ts +0 -252
  611. package/dist/builtin/workflows/src/shared/store-observation.ts +0 -10
  612. package/dist/builtin/workflows/src/shared/store-prompt-methods.ts +0 -215
  613. package/dist/builtin/workflows/src/shared/store-public-types.ts +0 -282
  614. package/dist/builtin/workflows/src/shared/store-run-methods.ts +0 -305
  615. package/dist/builtin/workflows/src/shared/store-stage-methods.ts +0 -331
  616. package/dist/builtin/workflows/src/shared/store-tool-node-methods.ts +0 -60
  617. package/dist/builtin/workflows/src/shared/store-types.ts +0 -439
  618. package/dist/builtin/workflows/src/shared/store.ts +0 -15
  619. package/dist/builtin/workflows/src/shared/timing.ts +0 -71
  620. package/dist/builtin/workflows/src/shared/tool-payload-bounds.ts +0 -576
  621. package/dist/builtin/workflows/src/shared/types.ts +0 -523
  622. package/dist/builtin/workflows/src/shared/workflow-artifact-env.ts +0 -21
  623. package/dist/builtin/workflows/src/shared/workflow-artifacts.ts +0 -259
  624. package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +0 -60
  625. package/dist/builtin/workflows/src/shared/workflow-authoring-types.ts +0 -111
  626. package/dist/builtin/workflows/src/shared/workflow-failures-classifier.ts +0 -292
  627. package/dist/builtin/workflows/src/shared/workflow-failures-contract.ts +0 -74
  628. package/dist/builtin/workflows/src/shared/workflow-failures-decisions.ts +0 -458
  629. package/dist/builtin/workflows/src/shared/workflow-failures-signals.ts +0 -303
  630. package/dist/builtin/workflows/src/shared/workflow-failures.ts +0 -13
  631. package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.d.ts +0 -21
  632. package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.ts +0 -25
  633. package/dist/builtin/workflows/src/shared/workflow-run-ownership.ts +0 -49
  634. package/dist/builtin/workflows/src/tui/chat-surface-message.ts +0 -319
  635. package/dist/builtin/workflows/src/tui/chat-surface.ts +0 -477
  636. package/dist/builtin/workflows/src/tui/color-utils.ts +0 -55
  637. package/dist/builtin/workflows/src/tui/connectors.ts +0 -84
  638. package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +0 -334
  639. package/dist/builtin/workflows/src/tui/edge.ts +0 -25
  640. package/dist/builtin/workflows/src/tui/graph-canvas.ts +0 -185
  641. package/dist/builtin/workflows/src/tui/graph-theme.ts +0 -292
  642. package/dist/builtin/workflows/src/tui/graph-view-constants.ts +0 -49
  643. package/dist/builtin/workflows/src/tui/graph-view-graph-render.ts +0 -157
  644. package/dist/builtin/workflows/src/tui/graph-view-input.ts +0 -427
  645. package/dist/builtin/workflows/src/tui/graph-view-layout.ts +0 -297
  646. package/dist/builtin/workflows/src/tui/graph-view-render-helpers.ts +0 -294
  647. package/dist/builtin/workflows/src/tui/graph-view-render.ts +0 -361
  648. package/dist/builtin/workflows/src/tui/graph-view-state.ts +0 -547
  649. package/dist/builtin/workflows/src/tui/graph-view-types.ts +0 -79
  650. package/dist/builtin/workflows/src/tui/graph-view.ts +0 -25
  651. package/dist/builtin/workflows/src/tui/header.ts +0 -210
  652. package/dist/builtin/workflows/src/tui/host-input-form.ts +0 -64
  653. package/dist/builtin/workflows/src/tui/inline-form-card.ts +0 -438
  654. package/dist/builtin/workflows/src/tui/inline-form-editor-text.ts +0 -120
  655. package/dist/builtin/workflows/src/tui/inline-form-editor.ts +0 -496
  656. package/dist/builtin/workflows/src/tui/inline-form-overlay.ts +0 -317
  657. package/dist/builtin/workflows/src/tui/inline-form-store.ts +0 -90
  658. package/dist/builtin/workflows/src/tui/inputs-overlay.ts +0 -185
  659. package/dist/builtin/workflows/src/tui/inputs-picker-editing.ts +0 -147
  660. package/dist/builtin/workflows/src/tui/inputs-picker-input.ts +0 -357
  661. package/dist/builtin/workflows/src/tui/inputs-picker-render.ts +0 -312
  662. package/dist/builtin/workflows/src/tui/inputs-picker-types.ts +0 -161
  663. package/dist/builtin/workflows/src/tui/inputs-picker.ts +0 -20
  664. package/dist/builtin/workflows/src/tui/keybindings-adapter.ts +0 -167
  665. package/dist/builtin/workflows/src/tui/layout.ts +0 -150
  666. package/dist/builtin/workflows/src/tui/mouse-input.ts +0 -61
  667. package/dist/builtin/workflows/src/tui/node-card.ts +0 -357
  668. package/dist/builtin/workflows/src/tui/overlay-adapter.ts +0 -449
  669. package/dist/builtin/workflows/src/tui/overlay-terminal-modes.ts +0 -39
  670. package/dist/builtin/workflows/src/tui/prompt-card-input.ts +0 -215
  671. package/dist/builtin/workflows/src/tui/prompt-card-render.ts +0 -584
  672. package/dist/builtin/workflows/src/tui/prompt-card-select.ts +0 -94
  673. package/dist/builtin/workflows/src/tui/prompt-card-state.ts +0 -61
  674. package/dist/builtin/workflows/src/tui/prompt-card-text.ts +0 -122
  675. package/dist/builtin/workflows/src/tui/prompt-card.ts +0 -12
  676. package/dist/builtin/workflows/src/tui/renderers.ts +0 -14
  677. package/dist/builtin/workflows/src/tui/run-detail.ts +0 -438
  678. package/dist/builtin/workflows/src/tui/run-identity-rows.ts +0 -97
  679. package/dist/builtin/workflows/src/tui/session-list.ts +0 -38
  680. package/dist/builtin/workflows/src/tui/session-overlays.ts +0 -161
  681. package/dist/builtin/workflows/src/tui/session-picker.ts +0 -482
  682. package/dist/builtin/workflows/src/tui/stage-chat-composer-drafts.ts +0 -19
  683. package/dist/builtin/workflows/src/tui/stage-chat-layout.ts +0 -81
  684. package/dist/builtin/workflows/src/tui/stage-chat-view-archive-history.ts +0 -462
  685. package/dist/builtin/workflows/src/tui/stage-chat-view-custom-ui.ts +0 -115
  686. package/dist/builtin/workflows/src/tui/stage-chat-view-delivery-activity.ts +0 -113
  687. package/dist/builtin/workflows/src/tui/stage-chat-view-footer-status.ts +0 -219
  688. package/dist/builtin/workflows/src/tui/stage-chat-view-input.ts +0 -216
  689. package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +0 -65
  690. package/dist/builtin/workflows/src/tui/stage-chat-view-pending-tools.ts +0 -7
  691. package/dist/builtin/workflows/src/tui/stage-chat-view-render-helpers.ts +0 -149
  692. package/dist/builtin/workflows/src/tui/stage-chat-view-render-settings.ts +0 -49
  693. package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +0 -575
  694. package/dist/builtin/workflows/src/tui/stage-chat-view-status.ts +0 -35
  695. package/dist/builtin/workflows/src/tui/stage-chat-view-transcript.ts +0 -226
  696. package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +0 -156
  697. package/dist/builtin/workflows/src/tui/stage-chat-view.ts +0 -309
  698. package/dist/builtin/workflows/src/tui/status-helpers.ts +0 -85
  699. package/dist/builtin/workflows/src/tui/status-list.ts +0 -447
  700. package/dist/builtin/workflows/src/tui/store-widget-installer.ts +0 -338
  701. package/dist/builtin/workflows/src/tui/submit-pane.ts +0 -148
  702. package/dist/builtin/workflows/src/tui/switcher.ts +0 -172
  703. package/dist/builtin/workflows/src/tui/text-helpers.ts +0 -208
  704. package/dist/builtin/workflows/src/tui/tool-detail.ts +0 -367
  705. package/dist/builtin/workflows/src/tui/widget.ts +0 -427
  706. package/dist/builtin/workflows/src/tui/workflow-attach-pane-handle.ts +0 -21
  707. package/dist/builtin/workflows/src/tui/workflow-attach-pane-types.ts +0 -77
  708. package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +0 -477
  709. package/dist/builtin/workflows/src/tui/workflow-list.ts +0 -189
  710. package/dist/builtin/workflows/src/tui/workflow-notice-card.ts +0 -167
  711. package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +0 -334
  712. package/dist/builtin/workflows/src/tui/workflow-status.ts +0 -12
  713. package/dist/builtin/workflows/src/workflows/identity.ts +0 -39
  714. package/dist/builtin/workflows/src/workflows/registry.ts +0 -115
@@ -1 +1 @@
1
- {"version":3,"file":"agent-session-retry.js","sourceRoot":"","sources":["../../src/core/agent-session-retry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE9F,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;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AED;;GAEG;AAEH,MAAM,UAAU,UAAU;IACzB,IAAI,CAAC,qBAAqB,EAAE,KAAK,EAAE,CAAC;IACpC,gEAAgE;IAChE,IAAI,CAAC,aAAa,EAAE,CAAC;AACtB,CAAC;AAED;;;GAGG;AAEH,MAAM,CAAC,KAAK,UAAU,YAAY;IACjC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QACzB,OAAO;IACR,CAAC;IAED,MAAM,IAAI,CAAC,aAAa,CAAC;IACzB,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;AAChC,CAAC;AAED,kDAAkD;AAElD,MAAM,UAAU,mBAAmB,CAAqB,OAAgB;IACvE,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,4EAA4E;AAC5E,iBAAiB;AACjB,4EAA4E;AAE5E;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,iBAAiB;IACjB,oBAAoB;IACpB,kBAAkB;IAClB,gBAAgB;IAChB,qBAAqB;IACrB,yBAAyB;IACzB,wBAAwB;IACxB,wBAAwB;IACxB,qBAAqB;IACrB,UAAU;IACV,YAAY;IACZ,mBAAmB;CACnB,CAAC","sourcesContent":["import type { Api, AssistantMessage, Model } from \"@bastani/pi-ai/compat\";\nimport { clampThinkingLevel, isContextOverflow, modelsAreEqual } from \"@bastani/pi-ai/compat\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { sleep } from \"../utils/sleep.ts\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { isCodexTokenInvalidationError } from \"./codex-errors.ts\";\nimport { DEFAULT_THINKING_LEVEL } from \"./defaults.ts\";\nimport { fallbackKey, resolveFallbackModel as resolveConfiguredFallbackModel } from \"./fallback-models.ts\";\nimport {\n\tisRetryableModelFailure,\n\tisRetryableSameModelFailure,\n\tisSafetyRefusalFailure,\n\tnormalizeModelFailureSignal,\n} from \"./model-fallback-failures.ts\";\nimport { nextRetryDecision } from \"./retry-policy.ts\";\n\nfunction modelLabel(model: Model<Api> | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"unknown model\";\n}\n\nfunction containsCodexTokenInvalidation(provider: string, value: unknown, seen = new Set<unknown>()): boolean {\n\tif (value === null || value === undefined || seen.has(value)) return false;\n\tif (typeof value === \"string\") return isCodexTokenInvalidationError(provider, value);\n\tif (typeof value !== \"object\") return false;\n\tseen.add(value);\n\tconst record = value as Record<string, unknown>;\n\tfor (const field of [record.errorMessage, record.message, record.statusText]) {\n\t\tif (typeof field === \"string\" && isCodexTokenInvalidationError(provider, field)) return true;\n\t}\n\tfor (const nested of [\n\t\trecord.error,\n\t\trecord.cause,\n\t\t...(Array.isArray(record.diagnostics) ? record.diagnostics : []),\n\t]) {\n\t\tif (containsCodexTokenInvalidation(provider, nested, seen)) return true;\n\t}\n\treturn false;\n}\n\nfunction resolveFallbackModel(\n\tthis: AgentSession,\n\tvalue: string,\n): { model: Model<Api>; thinkingLevel?: ThinkingLevel } | undefined {\n\treturn resolveConfiguredFallbackModel(\n\t\tvalue,\n\t\tthis._modelRuntime,\n\t\tthis.model?.provider ?? this.settingsManager.getDefaultProvider(),\n\t);\n}\n\n/** Whether an assistant error may advance the configured fallback chain. */\nexport function _isFallbackableError(this: AgentSession, message: AssistantMessage): boolean {\n\tif (message.stopReason !== \"error\") return false;\n\tconst contextWindow = this.model?.contextWindow ?? 0;\n\tif (isContextOverflow(message, contextWindow)) return false;\n\tconst provider = message.provider || this.model?.provider;\n\tif (provider && containsCodexTokenInvalidation(provider, message)) return true;\n\tconst signal = normalizeModelFailureSignal(message);\n\tif (signal.kind === \"cancelled\" || signal.kind === \"task_failure\") return false;\n\treturn isRetryableModelFailure(message);\n}\n\n/**\n * Whether the current model should be requested again.\n *\n * Fallback eligibility is broader than same-model retry eligibility. Auth and\n * request-incompatible failures should spend a fallback candidate, but cannot\n * be repaired by sending the same request again. Codex token invalidation is\n * also terminal for the current model while remaining fallbackable.\n */\nexport function _isRetryableError(this: AgentSession, message: AssistantMessage): boolean {\n\tif (message.stopReason !== \"error\") return false;\n\n\t// Context overflow is handled by compaction, not retry.\n\tconst contextWindow = this.model?.contextWindow ?? 0;\n\tif (isContextOverflow(message, contextWindow)) return false;\n\n\tconst provider = message.provider || this.model?.provider;\n\tif (provider && containsCodexTokenInvalidation(provider, message)) return false;\n\n\t// Safety/refusal errors remain bounded same-model retries, but do not spend\n\t// another provider candidate. The refusal grammar lives in the shared\n\t// classifier so this decision cannot drift from workflow fallback handling.\n\tif (isSafetyRefusalFailure(message)) return true;\n\treturn isRetryableSameModelFailure(message);\n}\n\n/**\n * Detect a degenerate empty completion: the provider ended the stream with no\n * usable content and zero output tokens. Seen with github-copilot Gemini models\n * that emit finish_reason \"stop\" (or a tool-use stop) with an empty content array\n * and 0 output tokens, leaving the turn dead instead of producing the next step.\n *\n * These are treated as retryable so the harness re-issues the request rather than\n * silently stopping mid-task. Guarded tightly (no text, no tool call, no thinking,\n * and output === 0) so legitimate non-empty turns are never matched.\n *\n * Intentionally provider-agnostic (not gated to Copilot Gemini): a degenerate\n * empty turn is a transient failure for any provider. It is bounded by\n * `maxRetries` and falls through to normal handling on exhaustion.\n */\n\nexport function _isEmptyCompletion(this: AgentSession, message: AssistantMessage): boolean {\n\t// Only \"completed\" stop reasons can be deceptively empty. Real errors are handled\n\t// by _isRetryableError; aborted/length turns are intentional outcomes.\n\tif (message.stopReason !== \"stop\" && message.stopReason !== \"toolUse\") return false;\n\n\tconst content = message.content;\n\tif (Array.isArray(content)) {\n\t\tconst hasContent = content.some((part) => {\n\t\t\tif (part.type === \"text\") return part.text.trim().length > 0;\n\t\t\tif (part.type === \"toolCall\") return true;\n\t\t\tif (part.type === \"thinking\") return part.redacted === true || part.thinking.trim().length > 0;\n\t\t\treturn true; // unknown part types count as content\n\t\t});\n\t\tif (hasContent) return false;\n\t}\n\n\t// A turn that produced output tokens but no surfaced content is not \"empty\"\n\t// (e.g. reasoning-only responses); leave those alone. Note: a provider that\n\t// fails to report `usage` (output defaults to 0) would make every\n\t// content-less turn match here; the dual requirement (empty content AND zero\n\t// output) keeps that false-positive risk low in practice.\n\treturn (message.usage?.output ?? 0) === 0;\n}\n\n/**\n * Detect a canned provider-side safety refusal that arrives as a *successful*\n * completion instead of an error. Seen with github-copilot GPT models under\n * heavy contexts: the endpoint intercepts the request and returns exactly\n * \"I'm sorry, but I cannot assist with that request.\" with zero usage and a\n * spurious stopReason of \"length\" (or \"stop\"), which the agent would otherwise\n * accept as the final answer and dead-end the turn (issue #1608).\n *\n * A text heuristic is unavoidable here: the OpenAI Responses API does signal\n * these interceptions structurally (`refusal` content parts plus\n * `incomplete_details.reason: \"content_filter\"`), but pi-ai's normalization\n * folds refusal parts into plain text blocks and collapses the `incomplete`\n * status to stopReason \"length\", discarding the reason — so no structured\n * refusal marker survives on the AssistantMessage. Providers whose safety\n * signals DO survive as structured errors (Anthropic refusal stops, OpenAI\n * `finish_reason: content_filter`) are matched in _isRetryableError instead.\n *\n * Guarded tightly so legitimate turns are never matched:\n * - only non-error completion stops (\"stop\" | \"length\" | \"toolUse\");\n * - content must be a single short canned refusal text — any tool call,\n * thinking block, or additional prose disqualifies the message;\n * - usage.output must be 0: a genuine model-authored refusal bills output\n * tokens, while the intercepted canned refusal reports zero usage.\n *\n * Treated as retryable so the harness re-requests the model call rather than\n * accepting the refusal; bounded by `maxRetries` like every other retry path.\n */\n\nconst CANNED_SAFETY_REFUSAL_PATTERN =\n\t/^(?:i['’]?m sorry[,.]?\\s+(?:but\\s+)?|sorry[,.]?\\s+(?:but\\s+)?)?i\\s+(?:cannot|can['’]?t|can\\s+not|am\\s+unable\\s+to|am\\s+not\\s+able\\s+to)\\s+(?:assist|help|comply|continue)(?:\\s+with)?(?:\\s+(?:that|this))?(?:\\s+(?:request|task))?\\.?$/i;\n\nconst CANNED_SAFETY_REFUSAL_MAX_LENGTH = 120;\n\nexport function _isSafetyRefusal(this: AgentSession, message: AssistantMessage): boolean {\n\t// Real errors are handled by _isRetryableError; aborts are user-initiated.\n\tif (message.stopReason !== \"stop\" && message.stopReason !== \"length\" && message.stopReason !== \"toolUse\") {\n\t\treturn false;\n\t}\n\n\tconst content = message.content;\n\tif (!Array.isArray(content) || content.length === 0) return false;\n\n\tlet text = \"\";\n\tfor (const part of content) {\n\t\tif (part.type === \"toolCall\") return false;\n\t\tif (part.type === \"thinking\" && (part.redacted === true || part.thinking.trim().length > 0)) return false;\n\t\tif (part.type === \"text\") text += part.text;\n\t}\n\ttext = text.trim();\n\tif (text.length === 0 || text.length > CANNED_SAFETY_REFUSAL_MAX_LENGTH) return false;\n\tif (!CANNED_SAFETY_REFUSAL_PATTERN.test(text)) return false;\n\n\t// Zero billed output distinguishes a provider interception from legitimate\n\t// model-authored refusal prose, which is never auto-retried.\n\treturn (message.usage?.output ?? 0) === 0;\n}\n\nfunction applyFallbackThinkingLevel(this: AgentSession, level: ThinkingLevel): boolean {\n\tconst previousLevel = this.agent.state.thinkingLevel ?? this.thinkingLevel;\n\tthis.agent.state.thinkingLevel = level;\n\tif (previousLevel === level) return false;\n\tthis.sessionManager.appendThinkingLevelChange(level);\n\tthis._emit({ type: \"thinking_level_changed\", level });\n\tvoid this._extensionRunner?.emit({\n\t\ttype: \"thinking_level_select\",\n\t\tlevel,\n\t\tpreviousLevel,\n\t});\n\treturn true;\n}\n\n/** Capture the user-selected model before the first fallback in a turn. */\nexport function _beginFallbackModelScope(this: AgentSession): void {\n\tconst currentModel = this.agent.state.model ?? this.model;\n\tif (this._fallbackOriginModel !== undefined || currentModel === undefined) return;\n\tthis._fallbackScopeGeneration = (this._fallbackScopeGeneration ?? 0) + 1;\n\tthis._fallbackOriginGeneration = this._fallbackScopeGeneration;\n\tthis._fallbackOriginModel = currentModel;\n\tthis._fallbackOriginThinkingLevel = this.agent.state.thinkingLevel ?? this.thinkingLevel;\n\tthis._fallbackRestoreError = undefined;\n}\n\nfunction clearFallbackModelScopeState(this: AgentSession): void {\n\tthis._fallbackOriginGeneration = undefined;\n\tthis._fallbackOriginModel = undefined;\n\tthis._fallbackOriginThinkingLevel = undefined;\n\tthis._fallbackRestoreError = undefined;\n\tthis._fallbackAttemptedKeys.clear();\n\tthis._fallbackBlockedModels.length = 0;\n}\n\nfunction finishFallbackModelScope(\n\tthis: AgentSession,\n\toptions: {\n\t\treadonly success: boolean;\n\t\treadonly from?: string;\n\t\treadonly to?: string;\n\t\treadonly finalError?: string;\n\t},\n): boolean {\n\tif (this._fallbackOriginModel === undefined || this._fallbackOriginGeneration === undefined) return false;\n\tthis._fallbackScopeGeneration = (this._fallbackScopeGeneration ?? 0) + 1;\n\tclearFallbackModelScopeState.call(this);\n\tthis._emit({\n\t\ttype: \"model_fallback_end\",\n\t\tsuccess: options.success,\n\t\t...(options.from === undefined ? {} : { from: options.from }),\n\t\t...(options.to === undefined ? {} : { to: options.to }),\n\t\t...(options.finalError === undefined ? {} : { finalError: options.finalError }),\n\t});\n\treturn true;\n}\n\n/** Cancel a pending fallback restore after an explicit model/effort choice. */\nexport function _clearFallbackModelScope(this: AgentSession): void {\n\tconst currentModel = this.agent.state.model ?? this.model;\n\tconst finalError = this._fallbackRestoreError;\n\tif (this._fallbackOriginModel !== undefined && this._fallbackOriginGeneration !== undefined) {\n\t\tfinishFallbackModelScope.call(this, {\n\t\t\tsuccess: finalError === undefined,\n\t\t\tfrom: modelLabel(currentModel),\n\t\t\t...(finalError === undefined ? {} : { finalError }),\n\t\t});\n\t\treturn;\n\t}\n\tthis._fallbackScopeGeneration = (this._fallbackScopeGeneration ?? 0) + 1;\n\tclearFallbackModelScopeState.call(this);\n}\n\n/** Restore the model that was active before this turn spent a fallback. */\nexport async function _restoreFallbackModel(this: AgentSession): Promise<boolean> {\n\tconst originModel = this._fallbackOriginModel;\n\tconst originGeneration = this._fallbackOriginGeneration;\n\tconst finalError = this._fallbackRestoreError;\n\tif (originModel === undefined || originGeneration === undefined) {\n\t\tclearFallbackModelScopeState.call(this);\n\t\treturn false;\n\t}\n\n\tconst previousModel = this.agent.state.model ?? this.model;\n\tconst previousThinkingLevel = this.agent.state.thinkingLevel ?? this.thinkingLevel;\n\tconst originThinkingLevel = clampThinkingLevel(\n\t\toriginModel,\n\t\tthis._fallbackOriginThinkingLevel ?? DEFAULT_THINKING_LEVEL,\n\t) as ThinkingLevel;\n\tconst modelChanged = !modelsAreEqual(previousModel, originModel);\n\tconst thinkingChanged = previousThinkingLevel !== originThinkingLevel;\n\tif (!modelChanged && !thinkingChanged) {\n\t\treturn finishFallbackModelScope.call(this, {\n\t\t\tsuccess: finalError === undefined,\n\t\t\tfrom: modelLabel(previousModel),\n\t\t\tto: modelLabel(originModel),\n\t\t\t...(finalError === undefined ? {} : { finalError }),\n\t\t});\n\t}\n\n\tconst stillOwnsRestore = (): boolean =>\n\t\tthis._fallbackOriginGeneration === originGeneration &&\n\t\tthis._fallbackOriginModel === originModel &&\n\t\tmodelsAreEqual(this.agent.state.model ?? this.model, originModel) &&\n\t\t(this.agent.state.thinkingLevel ?? this.thinkingLevel) === originThinkingLevel;\n\n\tthis.agent.state.model = originModel;\n\tif (modelChanged) this.sessionManager.appendModelChange(originModel.provider, originModel.id);\n\tapplyFallbackThinkingLevel.call(this, originThinkingLevel);\n\tthis._refreshBaseSystemPromptFromActiveTools();\n\tthis._emitModelChanged(originModel, previousModel, \"restore\");\n\tif (!stillOwnsRestore()) return false;\n\tawait this._emitModelSelect(originModel, previousModel, \"restore\");\n\tif (!stillOwnsRestore()) return false;\n\n\treturn finishFallbackModelScope.call(this, {\n\t\tsuccess: finalError === undefined,\n\t\tfrom: modelLabel(previousModel),\n\t\tto: modelLabel(originModel),\n\t\t...(finalError === undefined ? {} : { finalError }),\n\t});\n}\n\n/** Handle retryable errors with exponential backoff. */\nexport async function _trySwitchToFallbackModel(this: AgentSession, message: AssistantMessage): Promise<boolean> {\n\tconst currentModel = this.agent.state.model ?? this.model;\n\tif (this._fallbackModels.length === 0 || currentModel === undefined) return false;\n\n\t// A failure the chain may spend a candidate on, but that requesting the same\n\t// model again cannot repair — a rejected credential, an unavailable model, a\n\t// request this model cannot serve — condemns that model for the rest of the\n\t// turn. Reasoning level does not change any of those answers, so every\n\t// reasoning variant of it is blocked too. Transient rate-limit and transport\n\t// failures stay same-model retryable and keep their reasoning variants.\n\tif (isRetryableModelFailure(message) && !isRetryableSameModelFailure(message)) {\n\t\tif (!this._fallbackBlockedModels.some((blocked) => modelsAreEqual(blocked, currentModel))) {\n\t\t\tthis._fallbackBlockedModels.push(currentModel);\n\t\t}\n\t}\n\n\tconst currentThinkingLevel = this.agent.state.thinkingLevel ?? this.thinkingLevel;\n\tconst fromModel = currentModel;\n\tfor (const rawCandidate of this._fallbackModels) {\n\t\tconst candidate = resolveFallbackModel.call(this, rawCandidate);\n\t\tif (!candidate) continue;\n\t\tconst nextModel = candidate.model;\n\t\tconst nextLevel = clampThinkingLevel(\n\t\t\tnextModel,\n\t\t\tcandidate.thinkingLevel ??\n\t\t\t\tthis.settingsManager.getDefaultThinkingLevel() ??\n\t\t\t\tcurrentThinkingLevel ??\n\t\t\t\tDEFAULT_THINKING_LEVEL,\n\t\t) as ThinkingLevel;\n\t\tconst key = fallbackKey(nextModel, nextLevel);\n\t\tif (this._fallbackAttemptedKeys.has(key)) continue;\n\t\tif (modelsAreEqual(nextModel, fromModel) && nextLevel === currentThinkingLevel) continue;\n\t\t// Skipped before any lifecycle starts: a blocked variant emits no fallback\n\t\t// event and opens no scope.\n\t\tif (this._fallbackBlockedModels.some((blocked) => modelsAreEqual(blocked, nextModel))) continue;\n\n\t\t// Do not create a fallback lifecycle until a candidate can actually be\n\t\t// selected. An exhausted or unresolvable chain has no start to close.\n\t\t_beginFallbackModelScope.call(this);\n\t\tthis._fallbackAttemptedKeys.add(fallbackKey(currentModel, currentThinkingLevel));\n\t\tif (this._retryAttempt > 0) {\n\t\t\tthis._emit({\n\t\t\t\ttype: \"auto_retry_end\",\n\t\t\t\tsuccess: true,\n\t\t\t\tattempt: Math.max(0, this._retryAttempt - 1),\n\t\t\t});\n\t\t}\n\t\tthis._fallbackAttemptedKeys.add(key);\n\t\tthis._emit({\n\t\t\ttype: \"model_fallback_start\",\n\t\t\tfrom: modelLabel(fromModel),\n\t\t\tto: `${nextModel.provider}/${nextModel.id}`,\n\t\t\treason: message.errorMessage || \"Retryable model error\",\n\t\t\tattempt: this._fallbackAttemptedKeys.size - 1,\n\t\t});\n\n\t\tconst messages = this.agent.state.messages;\n\t\tif (messages.length > 0 && messages[messages.length - 1]?.role === \"assistant\") {\n\t\t\tthis.agent.state.messages = messages.slice(0, -1);\n\t\t}\n\t\tthis.agent.state.model = nextModel;\n\t\tthis.sessionManager.appendModelChange(nextModel.provider, nextModel.id);\n\t\tapplyFallbackThinkingLevel.call(this, nextLevel);\n\t\tthis._refreshBaseSystemPromptFromActiveTools();\n\t\tthis._emitModelChanged(nextModel, fromModel, \"fallback\");\n\t\tawait this._emitModelSelect(nextModel, fromModel, \"fallback\");\n\t\tthis._retryAttempt = 0;\n\n\t\tconst fallbackGeneration = this._fallbackOriginGeneration;\n\t\tsetTimeout(() => {\n\t\t\tvoid this.agent.continue().catch(async (error: unknown) => {\n\t\t\t\tconst finalError = error instanceof Error ? error.message : String(error);\n\t\t\t\tif (this._fallbackOriginGeneration === fallbackGeneration) {\n\t\t\t\t\tthis._fallbackRestoreError = finalError;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this._restoreFallbackModel();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tif (this._fallbackOriginGeneration === fallbackGeneration) {\n\t\t\t\t\t\t\tfinishFallbackModelScope.call(this, {\n\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\tfrom: modelLabel(this.agent.state.model ?? this.model),\n\t\t\t\t\t\t\t\tfinalError,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis._retryAttempt = 0;\n\t\t\t\tthis._resolveRetry();\n\t\t\t});\n\t\t}, 0);\n\t\treturn true;\n\t}\n\tif (this._fallbackOriginModel !== undefined) {\n\t\tthis._fallbackRestoreError = message.errorMessage || \"Model fallback exhausted\";\n\t}\n\treturn false;\n}\n\nexport async function _handleRetryableError(this: AgentSession, message: AssistantMessage): Promise<boolean> {\n\tconst settings = this.settingsManager.getRetrySettings();\n\tconst retryableError = this._isRetryableError?.(message) ?? true;\n\tconst fallbackableError = this._isFallbackableError?.(message) ?? retryableError;\n\tconst emptyCompletion = this._isEmptyCompletion?.(message) ?? false;\n\tconst safetyRefusal = this._isSafetyRefusal?.(message) ?? false;\n\tconst canRetrySameModel = retryableError || emptyCompletion || safetyRefusal;\n\t// Empty completions have historically been allowed to spend a fallback after\n\t// same-model retries. Provider safety refusals stay on the same model.\n\tconst canAdvanceToFallback = fallbackableError || emptyCompletion;\n\tif (!settings.enabled || !canRetrySameModel) {\n\t\tif (canAdvanceToFallback && (await this._trySwitchToFallbackModel(message))) return true;\n\t\tif (this._retryAttempt > 0) {\n\t\t\tthis._emit({\n\t\t\t\ttype: \"auto_retry_end\",\n\t\t\t\tsuccess: false,\n\t\t\t\tattempt: this._retryAttempt,\n\t\t\t\tfinalError: message.errorMessage,\n\t\t\t});\n\t\t}\n\t\tthis._retryAttempt = 0;\n\t\tthis._resolveRetry();\n\t\treturn false;\n\t}\n\n\t// Retry promise is created synchronously in _handleAgentEvent for agent_end.\n\t// Keep a defensive fallback here in case a future refactor bypasses that path.\n\tif (!this._retryPromise) {\n\t\tthis._retryPromise = new Promise((resolve) => {\n\t\t\tthis._retryResolve = resolve;\n\t\t});\n\t}\n\n\t// One shared policy decides the bounded same-model budget and its backoff, so\n\t// main chat and workflow stages cannot drift apart on the same settings. The\n\t// counter still advances on the exhausting attempt, so `_trySwitchToFallbackModel`\n\t// closes the retry lifecycle before the fallback lifecycle opens.\n\tconst decision = nextRetryDecision(settings, this._retryAttempt, canRetrySameModel);\n\tthis._retryAttempt += 1;\n\tif (decision === undefined) {\n\t\tif (canAdvanceToFallback && (await this._trySwitchToFallbackModel(message))) {\n\t\t\treturn true;\n\t\t}\n\t\t// Max retries exceeded, emit final failure and reset\n\t\tthis._emit({\n\t\t\ttype: \"auto_retry_end\",\n\t\t\tsuccess: false,\n\t\t\tattempt: this._retryAttempt - 1,\n\t\t\tfinalError: message.errorMessage,\n\t\t});\n\t\tthis._retryAttempt = 0;\n\t\tthis._resolveRetry(); // Resolve so waitForRetry() completes\n\t\treturn false;\n\t}\n\n\tconst delayMs = decision.delayMs;\n\n\tthis._emit({\n\t\ttype: \"auto_retry_start\",\n\t\tattempt: this._retryAttempt,\n\t\tmaxAttempts: settings.maxRetries,\n\t\tdelayMs,\n\t\terrorMessage: message.errorMessage || \"Unknown error\",\n\t});\n\n\t// Remove error message from agent state (keep in session for history)\n\tconst messages = this.agent.state.messages;\n\tif (messages.length > 0 && messages[messages.length - 1].role === \"assistant\") {\n\t\tthis.agent.state.messages = messages.slice(0, -1);\n\t}\n\n\t// Wait with exponential backoff (abortable)\n\tthis._retryAbortController = new AbortController();\n\ttry {\n\t\tawait sleep(delayMs, this._retryAbortController.signal);\n\t} catch {\n\t\t// Aborted during sleep - emit end event so UI can clean up\n\t\tconst attempt = this._retryAttempt;\n\t\tthis._retryAttempt = 0;\n\t\tthis._retryAbortController = undefined;\n\t\tthis._emit({\n\t\t\ttype: \"auto_retry_end\",\n\t\t\tsuccess: false,\n\t\t\tattempt,\n\t\t\tfinalError: \"Retry cancelled\",\n\t\t});\n\t\tthis._resolveRetry();\n\t\treturn false;\n\t}\n\tthis._retryAbortController = undefined;\n\n\t// Retry via continue() - use setTimeout to break out of event handler chain\n\tsetTimeout(() => {\n\t\tthis.agent.continue().catch(() => {\n\t\t\t// Retry failed - will be caught by next agent_end\n\t\t});\n\t}, 0);\n\n\treturn true;\n}\n\n/**\n * Cancel in-progress retry.\n */\n\nexport function abortRetry(this: AgentSession): void {\n\tthis._retryAbortController?.abort();\n\t// Note: _retryAttempt is reset in the catch block of _autoRetry\n\tthis._resolveRetry();\n}\n\n/**\n * Wait for any in-progress retry to complete.\n * Returns immediately if no retry is in progress.\n */\n\nexport async function waitForRetry(this: AgentSession): Promise<void> {\n\tif (!this._retryPromise) {\n\t\treturn;\n\t}\n\n\tawait this._retryPromise;\n\tawait this.agent.waitForIdle();\n}\n\n/** Whether auto-retry is currently in progress */\n\nexport function setAutoRetryEnabled(this: AgentSession, enabled: boolean): void {\n\tthis.settingsManager.setRetryEnabled(enabled);\n}\n\n// =========================================================================\n// Bash Execution\n// =========================================================================\n\n/**\n * Execute a bash command.\n * Adds result to agent context and session.\n * @param command The bash command to execute\n * @param onChunk Optional streaming callback for output\n * @param options.excludeFromContext If true, command output won't be sent to LLM (!! prefix)\n * @param options.operations Custom BashOperations for remote execution\n */\n\nexport const agentSessionRetryMethods = {\n\t_isRetryableError,\n\t_isFallbackableError,\n\t_isEmptyCompletion,\n\t_isSafetyRefusal,\n\t_handleRetryableError,\n\t_trySwitchToFallbackModel,\n\t_beginFallbackModelScope,\n\t_clearFallbackModelScope,\n\t_restoreFallbackModel,\n\tabortRetry,\n\twaitForRetry,\n\tsetAutoRetryEnabled,\n};\n"]}
1
+ {"version":3,"file":"agent-session-retry.js","sourceRoot":"","sources":["../../src/core/agent-session-retry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE9F,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,oBAAoB,IAAI,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAC3G,OAAO,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,8BAA8B,CAAC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C,eAAe,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,4EAA4E;AAC5E,iBAAiB;AACjB,4EAA4E;AAE5E;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,iBAAiB;IACjB,oBAAoB;IACpB,kBAAkB;IAClB,gBAAgB;IAChB,qBAAqB;IACrB,yBAAyB;IACzB,wBAAwB;IACxB,wBAAwB;IACxB,yBAAyB;IACzB,UAAU;IACV,YAAY;IACZ,mBAAmB;CACnB,CAAC","sourcesContent":["import type { Api, AssistantMessage, Model } from \"@bastani/pi-ai/compat\";\nimport { clampThinkingLevel, isContextOverflow, modelsAreEqual } from \"@bastani/pi-ai/compat\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { sleep } from \"../utils/sleep.ts\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { isCodexTokenInvalidationError } from \"./codex-errors.ts\";\nimport { DEFAULT_THINKING_LEVEL } from \"./defaults.ts\";\nimport { fallbackKey, resolveFallbackModel as resolveConfiguredFallbackModel } from \"./fallback-models.ts\";\nimport {\n\tisRetryableModelFailure,\n\tisRetryableSameModelFailure,\n\tisSafetyRefusalFailure,\n\tnormalizeModelFailureSignal,\n} from \"./model-fallback-failures.ts\";\nimport { nextRetryDecision } from \"./retry-policy.ts\";\n\nfunction modelLabel(model: Model<Api> | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"unknown model\";\n}\n\nfunction containsCodexTokenInvalidation(provider: string, value: unknown, seen = new Set<unknown>()): boolean {\n\tif (value === null || value === undefined || seen.has(value)) return false;\n\tif (typeof value === \"string\") return isCodexTokenInvalidationError(provider, value);\n\tif (typeof value !== \"object\") return false;\n\tseen.add(value);\n\tconst record = value as Record<string, unknown>;\n\tfor (const field of [record.errorMessage, record.message, record.statusText]) {\n\t\tif (typeof field === \"string\" && isCodexTokenInvalidationError(provider, field)) return true;\n\t}\n\tfor (const nested of [\n\t\trecord.error,\n\t\trecord.cause,\n\t\t...(Array.isArray(record.diagnostics) ? record.diagnostics : []),\n\t]) {\n\t\tif (containsCodexTokenInvalidation(provider, nested, seen)) return true;\n\t}\n\treturn false;\n}\n\nfunction resolveFallbackModel(\n\tthis: AgentSession,\n\tvalue: string,\n): { model: Model<Api>; thinkingLevel?: ThinkingLevel } | undefined {\n\treturn resolveConfiguredFallbackModel(\n\t\tvalue,\n\t\tthis._modelRuntime,\n\t\tthis.model?.provider ?? this.settingsManager.getDefaultProvider(),\n\t);\n}\n\n/** Whether an assistant error may advance the configured fallback chain. */\nexport function _isFallbackableError(this: AgentSession, message: AssistantMessage): boolean {\n\tif (message.stopReason !== \"error\") return false;\n\tconst contextWindow = this.model?.contextWindow ?? 0;\n\tif (isContextOverflow(message, contextWindow)) return false;\n\tconst provider = message.provider || this.model?.provider;\n\tif (provider && containsCodexTokenInvalidation(provider, message)) return true;\n\tconst signal = normalizeModelFailureSignal(message);\n\tif (signal.kind === \"cancelled\" || signal.kind === \"task_failure\") return false;\n\treturn isRetryableModelFailure(message);\n}\n\n/**\n * Whether the current model should be requested again.\n *\n * Fallback eligibility is broader than same-model retry eligibility. Auth and\n * request-incompatible failures should spend a fallback candidate, but cannot\n * be repaired by sending the same request again. Codex token invalidation is\n * also terminal for the current model while remaining fallbackable.\n */\nexport function _isRetryableError(this: AgentSession, message: AssistantMessage): boolean {\n\tif (message.stopReason !== \"error\") return false;\n\n\t// Context overflow is handled by compaction, not retry.\n\tconst contextWindow = this.model?.contextWindow ?? 0;\n\tif (isContextOverflow(message, contextWindow)) return false;\n\n\tconst provider = message.provider || this.model?.provider;\n\tif (provider && containsCodexTokenInvalidation(provider, message)) return false;\n\n\t// Safety/refusal errors remain bounded same-model retries, but do not spend\n\t// another provider candidate. The refusal grammar lives in the shared\n\t// classifier so this decision cannot drift from workflow fallback handling.\n\tif (isSafetyRefusalFailure(message)) return true;\n\treturn isRetryableSameModelFailure(message);\n}\n\n/**\n * Detect a degenerate empty completion: the provider ended the stream with no\n * usable content and zero output tokens. Seen with github-copilot Gemini models\n * that emit finish_reason \"stop\" (or a tool-use stop) with an empty content array\n * and 0 output tokens, leaving the turn dead instead of producing the next step.\n *\n * These are treated as retryable so the harness re-issues the request rather than\n * silently stopping mid-task. Guarded tightly (no text, no tool call, no thinking,\n * and output === 0) so legitimate non-empty turns are never matched.\n *\n * Intentionally provider-agnostic (not gated to Copilot Gemini): a degenerate\n * empty turn is a transient failure for any provider. It is bounded by\n * `maxRetries` and falls through to normal handling on exhaustion.\n */\n\nexport function _isEmptyCompletion(this: AgentSession, message: AssistantMessage): boolean {\n\t// Only \"completed\" stop reasons can be deceptively empty. Real errors are handled\n\t// by _isRetryableError; aborted/length turns are intentional outcomes.\n\tif (message.stopReason !== \"stop\" && message.stopReason !== \"toolUse\") return false;\n\n\tconst content = message.content;\n\tif (Array.isArray(content)) {\n\t\tconst hasContent = content.some((part) => {\n\t\t\tif (part.type === \"text\") return part.text.trim().length > 0;\n\t\t\tif (part.type === \"toolCall\") return true;\n\t\t\tif (part.type === \"thinking\") return part.redacted === true || part.thinking.trim().length > 0;\n\t\t\treturn true; // unknown part types count as content\n\t\t});\n\t\tif (hasContent) return false;\n\t}\n\n\t// A turn that produced output tokens but no surfaced content is not \"empty\"\n\t// (e.g. reasoning-only responses); leave those alone. Note: a provider that\n\t// fails to report `usage` (output defaults to 0) would make every\n\t// content-less turn match here; the dual requirement (empty content AND zero\n\t// output) keeps that false-positive risk low in practice.\n\treturn (message.usage?.output ?? 0) === 0;\n}\n\n/**\n * Detect a canned provider-side safety refusal that arrives as a *successful*\n * completion instead of an error. Seen with github-copilot GPT models under\n * heavy contexts: the endpoint intercepts the request and returns exactly\n * \"I'm sorry, but I cannot assist with that request.\" with zero usage and a\n * spurious stopReason of \"length\" (or \"stop\"), which the agent would otherwise\n * accept as the final answer and dead-end the turn (issue #1608).\n *\n * A text heuristic is unavoidable here: the OpenAI Responses API does signal\n * these interceptions structurally (`refusal` content parts plus\n * `incomplete_details.reason: \"content_filter\"`), but pi-ai's normalization\n * folds refusal parts into plain text blocks and collapses the `incomplete`\n * status to stopReason \"length\", discarding the reason — so no structured\n * refusal marker survives on the AssistantMessage. Providers whose safety\n * signals DO survive as structured errors (Anthropic refusal stops, OpenAI\n * `finish_reason: content_filter`) are matched in _isRetryableError instead.\n *\n * Guarded tightly so legitimate turns are never matched:\n * - only non-error completion stops (\"stop\" | \"length\" | \"toolUse\");\n * - content must be a single short canned refusal text — any tool call,\n * thinking block, or additional prose disqualifies the message;\n * - usage.output must be 0: a genuine model-authored refusal bills output\n * tokens, while the intercepted canned refusal reports zero usage.\n *\n * Treated as retryable so the harness re-requests the model call rather than\n * accepting the refusal; bounded by `maxRetries` like every other retry path.\n */\n\nconst CANNED_SAFETY_REFUSAL_PATTERN =\n\t/^(?:i['’]?m sorry[,.]?\\s+(?:but\\s+)?|sorry[,.]?\\s+(?:but\\s+)?)?i\\s+(?:cannot|can['’]?t|can\\s+not|am\\s+unable\\s+to|am\\s+not\\s+able\\s+to)\\s+(?:assist|help|comply|continue)(?:\\s+with)?(?:\\s+(?:that|this))?(?:\\s+(?:request|task))?\\.?$/i;\n\nconst CANNED_SAFETY_REFUSAL_MAX_LENGTH = 120;\n\nexport function _isSafetyRefusal(this: AgentSession, message: AssistantMessage): boolean {\n\t// Real errors are handled by _isRetryableError; aborts are user-initiated.\n\tif (message.stopReason !== \"stop\" && message.stopReason !== \"length\" && message.stopReason !== \"toolUse\") {\n\t\treturn false;\n\t}\n\n\tconst content = message.content;\n\tif (!Array.isArray(content) || content.length === 0) return false;\n\n\tlet text = \"\";\n\tfor (const part of content) {\n\t\tif (part.type === \"toolCall\") return false;\n\t\tif (part.type === \"thinking\" && (part.redacted === true || part.thinking.trim().length > 0)) return false;\n\t\tif (part.type === \"text\") text += part.text;\n\t}\n\ttext = text.trim();\n\tif (text.length === 0 || text.length > CANNED_SAFETY_REFUSAL_MAX_LENGTH) return false;\n\tif (!CANNED_SAFETY_REFUSAL_PATTERN.test(text)) return false;\n\n\t// Zero billed output distinguishes a provider interception from legitimate\n\t// model-authored refusal prose, which is never auto-retried.\n\treturn (message.usage?.output ?? 0) === 0;\n}\n\nfunction applyFallbackThinkingLevel(this: AgentSession, level: ThinkingLevel): boolean {\n\tconst previousLevel = this.agent.state.thinkingLevel ?? this.thinkingLevel;\n\tthis.agent.state.thinkingLevel = level;\n\tif (previousLevel === level) return false;\n\tthis.sessionManager.appendThinkingLevelChange(level);\n\tthis._emit({ type: \"thinking_level_changed\", level });\n\tvoid this._extensionRunner?.emit({\n\t\ttype: \"thinking_level_select\",\n\t\tlevel,\n\t\tpreviousLevel,\n\t});\n\treturn true;\n}\n\n/** Capture the user-selected model before the first fallback in a turn. */\nexport function _beginFallbackModelScope(this: AgentSession): void {\n\tconst currentModel = this.agent.state.model ?? this.model;\n\tif (this._fallbackOriginModel !== undefined || currentModel === undefined) return;\n\tthis._fallbackScopeGeneration = (this._fallbackScopeGeneration ?? 0) + 1;\n\tthis._fallbackOriginGeneration = this._fallbackScopeGeneration;\n\tthis._fallbackOriginModel = currentModel;\n\tthis._fallbackOriginThinkingLevel = this.agent.state.thinkingLevel ?? this.thinkingLevel;\n\tthis._fallbackRestoreError = undefined;\n}\n\nfunction clearFallbackModelScopeState(this: AgentSession): void {\n\tthis._fallbackOriginGeneration = undefined;\n\tthis._fallbackOriginModel = undefined;\n\tthis._fallbackOriginThinkingLevel = undefined;\n\tthis._fallbackRestoreError = undefined;\n\tthis._fallbackAttemptedKeys.clear();\n\tthis._fallbackBlockedModels.length = 0;\n}\n\nfunction finishFallbackModelScope(\n\tthis: AgentSession,\n\toptions: {\n\t\treadonly success: boolean;\n\t\treadonly from?: string;\n\t\treadonly to?: string;\n\t\treadonly finalError?: string;\n\t},\n): boolean {\n\tif (this._fallbackOriginModel === undefined || this._fallbackOriginGeneration === undefined) return false;\n\tthis._fallbackScopeGeneration = (this._fallbackScopeGeneration ?? 0) + 1;\n\tclearFallbackModelScopeState.call(this);\n\tthis._emit({\n\t\ttype: \"model_fallback_end\",\n\t\tsuccess: options.success,\n\t\t...(options.from === undefined ? {} : { from: options.from }),\n\t\t...(options.to === undefined ? {} : { to: options.to }),\n\t\t...(options.finalError === undefined ? {} : { finalError: options.finalError }),\n\t});\n\treturn true;\n}\n\n/** Finish an active fallback lifecycle before an explicit model choice. */\nexport function _clearFallbackModelScope(this: AgentSession): void {\n\tconst currentModel = this.agent.state.model ?? this.model;\n\tconst finalError = this._fallbackRestoreError;\n\tif (this._fallbackOriginModel !== undefined && this._fallbackOriginGeneration !== undefined) {\n\t\tfinishFallbackModelScope.call(this, {\n\t\t\tsuccess: finalError === undefined,\n\t\t\tfrom: modelLabel(currentModel),\n\t\t\t...(finalError === undefined ? {} : { finalError }),\n\t\t});\n\t\treturn;\n\t}\n\tthis._fallbackScopeGeneration = (this._fallbackScopeGeneration ?? 0) + 1;\n\tclearFallbackModelScopeState.call(this);\n}\n\n/** Finish an active fallback lifecycle without changing the selected fallback model. */\nexport async function _settleFallbackModelScope(this: AgentSession): Promise<boolean> {\n\tconst originModel = this._fallbackOriginModel;\n\tconst originGeneration = this._fallbackOriginGeneration;\n\tconst finalError = this._fallbackRestoreError;\n\tif (originModel === undefined || originGeneration === undefined) {\n\t\tclearFallbackModelScopeState.call(this);\n\t\treturn false;\n\t}\n\tif (this._fallbackOriginGeneration !== originGeneration || this._fallbackOriginModel !== originModel) return false;\n\n\tconst currentModel = this.agent.state.model ?? this.model;\n\treturn finishFallbackModelScope.call(this, {\n\t\tsuccess: finalError === undefined,\n\t\tfrom: modelLabel(currentModel),\n\t\t...(finalError === undefined ? {} : { finalError }),\n\t});\n}\n\n/** Handle retryable errors with exponential backoff. */\nexport async function _trySwitchToFallbackModel(this: AgentSession, message: AssistantMessage): Promise<boolean> {\n\tconst currentModel = this.agent.state.model ?? this.model;\n\tif (this._fallbackModels.length === 0 || currentModel === undefined) return false;\n\n\t// A failure the chain may spend a candidate on, but that requesting the same\n\t// model again cannot repair — a rejected credential, an unavailable model, a\n\t// request this model cannot serve — condemns that model for the rest of the\n\t// turn. Reasoning level does not change any of those answers, so every\n\t// reasoning variant of it is blocked too. Transient rate-limit and transport\n\t// failures stay same-model retryable and keep their reasoning variants.\n\tif (isRetryableModelFailure(message) && !isRetryableSameModelFailure(message)) {\n\t\tif (!this._fallbackBlockedModels.some((blocked) => modelsAreEqual(blocked, currentModel))) {\n\t\t\tthis._fallbackBlockedModels.push(currentModel);\n\t\t}\n\t}\n\n\tconst currentThinkingLevel = this.agent.state.thinkingLevel ?? this.thinkingLevel;\n\tconst fromModel = currentModel;\n\tfor (const rawCandidate of this._fallbackModels) {\n\t\tconst candidate = resolveFallbackModel.call(this, rawCandidate);\n\t\tif (!candidate) continue;\n\t\tconst nextModel = candidate.model;\n\t\tconst nextLevel = clampThinkingLevel(\n\t\t\tnextModel,\n\t\t\tcandidate.thinkingLevel ??\n\t\t\t\tthis.settingsManager.getDefaultThinkingLevel() ??\n\t\t\t\tcurrentThinkingLevel ??\n\t\t\t\tDEFAULT_THINKING_LEVEL,\n\t\t) as ThinkingLevel;\n\t\tconst key = fallbackKey(nextModel, nextLevel);\n\t\tif (this._fallbackAttemptedKeys.has(key)) continue;\n\t\tif (modelsAreEqual(nextModel, fromModel) && nextLevel === currentThinkingLevel) continue;\n\t\t// Skipped before any lifecycle starts: a blocked variant emits no fallback\n\t\t// event and opens no scope.\n\t\tif (this._fallbackBlockedModels.some((blocked) => modelsAreEqual(blocked, nextModel))) continue;\n\n\t\t// Do not create a fallback lifecycle until a candidate can actually be\n\t\t// selected. An exhausted or unresolvable chain has no start to close.\n\t\t_beginFallbackModelScope.call(this);\n\t\tthis._fallbackAttemptedKeys.add(fallbackKey(currentModel, currentThinkingLevel));\n\t\tif (this._retryAttempt > 0) {\n\t\t\tthis._emit({\n\t\t\t\ttype: \"auto_retry_end\",\n\t\t\t\tsuccess: true,\n\t\t\t\tattempt: Math.max(0, this._retryAttempt - 1),\n\t\t\t});\n\t\t}\n\t\tthis._fallbackAttemptedKeys.add(key);\n\t\tthis._emit({\n\t\t\ttype: \"model_fallback_start\",\n\t\t\tfrom: modelLabel(fromModel),\n\t\t\tto: `${nextModel.provider}/${nextModel.id}`,\n\t\t\treason: message.errorMessage || \"Retryable model error\",\n\t\t\tattempt: this._fallbackAttemptedKeys.size - 1,\n\t\t});\n\n\t\tconst messages = this.agent.state.messages;\n\t\tif (messages.length > 0 && messages[messages.length - 1]?.role === \"assistant\") {\n\t\t\tthis.agent.state.messages = messages.slice(0, -1);\n\t\t}\n\t\tthis.agent.state.model = nextModel;\n\t\tthis.sessionManager.appendModelChange(nextModel.provider, nextModel.id);\n\t\tapplyFallbackThinkingLevel.call(this, nextLevel);\n\t\tthis._refreshBaseSystemPromptFromActiveTools();\n\t\tthis._emitModelChanged(nextModel, fromModel, \"fallback\");\n\t\tawait this._emitModelSelect(nextModel, fromModel, \"fallback\");\n\t\tthis._retryAttempt = 0;\n\n\t\tconst fallbackGeneration = this._fallbackOriginGeneration;\n\t\tsetTimeout(() => {\n\t\t\tvoid this.agent.continue().catch(async (error: unknown) => {\n\t\t\t\tconst finalError = error instanceof Error ? error.message : String(error);\n\t\t\t\tif (this._fallbackOriginGeneration === fallbackGeneration) {\n\t\t\t\t\tthis._fallbackRestoreError = finalError;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this._settleFallbackModelScope();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tif (this._fallbackOriginGeneration === fallbackGeneration) {\n\t\t\t\t\t\t\tfinishFallbackModelScope.call(this, {\n\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\tfrom: modelLabel(this.agent.state.model ?? this.model),\n\t\t\t\t\t\t\t\tfinalError,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis._retryAttempt = 0;\n\t\t\t\tthis._resolveRetry();\n\t\t\t});\n\t\t}, 0);\n\t\treturn true;\n\t}\n\tif (this._fallbackOriginModel !== undefined) {\n\t\tthis._fallbackRestoreError = message.errorMessage || \"Model fallback exhausted\";\n\t}\n\treturn false;\n}\n\nexport async function _handleRetryableError(this: AgentSession, message: AssistantMessage): Promise<boolean> {\n\tconst settings = this.settingsManager.getRetrySettings();\n\tconst retryableError = this._isRetryableError?.(message) ?? true;\n\tconst fallbackableError = this._isFallbackableError?.(message) ?? retryableError;\n\tconst emptyCompletion = this._isEmptyCompletion?.(message) ?? false;\n\tconst safetyRefusal = this._isSafetyRefusal?.(message) ?? false;\n\tconst canRetrySameModel = retryableError || emptyCompletion || safetyRefusal;\n\t// Empty completions have historically been allowed to spend a fallback after\n\t// same-model retries. Provider safety refusals stay on the same model.\n\tconst canAdvanceToFallback = fallbackableError || emptyCompletion;\n\tif (!settings.enabled || !canRetrySameModel) {\n\t\tif (canAdvanceToFallback && (await this._trySwitchToFallbackModel(message))) return true;\n\t\tif (this._retryAttempt > 0) {\n\t\t\tthis._emit({\n\t\t\t\ttype: \"auto_retry_end\",\n\t\t\t\tsuccess: false,\n\t\t\t\tattempt: this._retryAttempt,\n\t\t\t\tfinalError: message.errorMessage,\n\t\t\t});\n\t\t}\n\t\tthis._retryAttempt = 0;\n\t\tthis._resolveRetry();\n\t\treturn false;\n\t}\n\n\t// Retry promise is created synchronously in _handleAgentEvent for agent_end.\n\t// Keep a defensive fallback here in case a future refactor bypasses that path.\n\tif (!this._retryPromise) {\n\t\tthis._retryPromise = new Promise((resolve) => {\n\t\t\tthis._retryResolve = resolve;\n\t\t});\n\t}\n\n\t// One shared policy decides the bounded same-model budget and its backoff, so\n\t// main chat and workflow stages cannot drift apart on the same settings. The\n\t// counter still advances on the exhausting attempt, so `_trySwitchToFallbackModel`\n\t// closes the retry lifecycle before the fallback lifecycle opens.\n\tconst decision = nextRetryDecision(settings, this._retryAttempt, canRetrySameModel);\n\tthis._retryAttempt += 1;\n\tif (decision === undefined) {\n\t\tif (canAdvanceToFallback && (await this._trySwitchToFallbackModel(message))) {\n\t\t\treturn true;\n\t\t}\n\t\t// Max retries exceeded, emit final failure and reset\n\t\tthis._emit({\n\t\t\ttype: \"auto_retry_end\",\n\t\t\tsuccess: false,\n\t\t\tattempt: this._retryAttempt - 1,\n\t\t\tfinalError: message.errorMessage,\n\t\t});\n\t\tthis._retryAttempt = 0;\n\t\tthis._resolveRetry(); // Resolve so waitForRetry() completes\n\t\treturn false;\n\t}\n\n\tconst delayMs = decision.delayMs;\n\n\tthis._emit({\n\t\ttype: \"auto_retry_start\",\n\t\tattempt: this._retryAttempt,\n\t\tmaxAttempts: settings.maxRetries,\n\t\tdelayMs,\n\t\terrorMessage: message.errorMessage || \"Unknown error\",\n\t});\n\n\t// Remove error message from agent state (keep in session for history)\n\tconst messages = this.agent.state.messages;\n\tif (messages.length > 0 && messages[messages.length - 1].role === \"assistant\") {\n\t\tthis.agent.state.messages = messages.slice(0, -1);\n\t}\n\n\t// Wait with exponential backoff (abortable)\n\tthis._retryAbortController = new AbortController();\n\ttry {\n\t\tawait sleep(delayMs, this._retryAbortController.signal);\n\t} catch {\n\t\t// Aborted during sleep - emit end event so UI can clean up\n\t\tconst attempt = this._retryAttempt;\n\t\tthis._retryAttempt = 0;\n\t\tthis._retryAbortController = undefined;\n\t\tthis._emit({\n\t\t\ttype: \"auto_retry_end\",\n\t\t\tsuccess: false,\n\t\t\tattempt,\n\t\t\tfinalError: \"Retry cancelled\",\n\t\t});\n\t\tthis._resolveRetry();\n\t\treturn false;\n\t}\n\tthis._retryAbortController = undefined;\n\n\t// Retry via continue() - use setTimeout to break out of event handler chain\n\tsetTimeout(() => {\n\t\tthis.agent.continue().catch(() => {\n\t\t\t// Retry failed - will be caught by next agent_end\n\t\t});\n\t}, 0);\n\n\treturn true;\n}\n\n/**\n * Cancel in-progress retry.\n */\n\nexport function abortRetry(this: AgentSession): void {\n\tthis._retryAbortController?.abort();\n\t// Note: _retryAttempt is reset in the catch block of _autoRetry\n\tthis._resolveRetry();\n}\n\n/**\n * Wait for any in-progress retry to complete.\n * Returns immediately if no retry is in progress.\n */\n\nexport async function waitForRetry(this: AgentSession): Promise<void> {\n\tif (!this._retryPromise) {\n\t\treturn;\n\t}\n\n\tawait this._retryPromise;\n\tawait this.agent.waitForIdle();\n}\n\n/** Whether auto-retry is currently in progress */\n\nexport function setAutoRetryEnabled(this: AgentSession, enabled: boolean): void {\n\tthis.settingsManager.setRetryEnabled(enabled);\n}\n\n// =========================================================================\n// Bash Execution\n// =========================================================================\n\n/**\n * Execute a bash command.\n * Adds result to agent context and session.\n * @param command The bash command to execute\n * @param onChunk Optional streaming callback for output\n * @param options.excludeFromContext If true, command output won't be sent to LLM (!! prefix)\n * @param options.operations Custom BashOperations for remote execution\n */\n\nexport const agentSessionRetryMethods = {\n\t_isRetryableError,\n\t_isFallbackableError,\n\t_isEmptyCompletion,\n\t_isSafetyRefusal,\n\t_handleRetryableError,\n\t_trySwitchToFallbackModel,\n\t_beginFallbackModelScope,\n\t_clearFallbackModelScope,\n\t_settleFallbackModelScope,\n\tabortRetry,\n\twaitForRetry,\n\tsetAutoRetryEnabled,\n};\n"]}
@@ -107,9 +107,9 @@ export function _installAgentNextTurnRefresh() {
107
107
  const messages = turn.toolResults.length > 0 && !terminatingBatch
108
108
  ? await this._preflightPostToolContext(previousContext.messages, signal)
109
109
  : previousContext.messages;
110
- // Restore before queued follow-up messages are polled, but keep the
111
- // fallback for deceptive completions that event processing must retry on
112
- // the same model (safety refusal, empty completion, or length truncation).
110
+ // Settle before queued follow-up messages are polled, but keep the fallback
111
+ // lifecycle open for deceptive completions that event processing must retry
112
+ // on the same model (safety refusal, empty completion, or length truncation).
113
113
  const preserveFallbackForFailure = turn.message.role === "assistant" &&
114
114
  !this.agent.hasQueuedMessages() &&
115
115
  (turn.message.stopReason === "length" ||
@@ -117,7 +117,7 @@ export function _installAgentNextTurnRefresh() {
117
117
  this._isSafetyRefusal?.(turn.message) === true);
118
118
  if (!preserveFallbackForFailure && (turn.toolResults.length === 0 || terminatingBatch)) {
119
119
  await this._agentEventQueue;
120
- await this._restoreFallbackModel();
120
+ await this._settleFallbackModelScope();
121
121
  }
122
122
  return {
123
123
  ...previousSnapshot,
@@ -1 +1 @@
1
- {"version":3,"file":"agent-session-tool-hooks.js","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,MAAM,UAAU,sBAAsB;IACrC,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,IAAI,CAAC,gBAAgB,CAAC;QAE5B,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC;gBACxC,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,QAAQ,CAAC,IAAI;gBACvB,UAAU,EAAE,QAAQ,CAAC,EAAE;gBACvB,KAAK,EAAE,IAA+B;aACtC,CAAC,CAAC;YACH,IAAI,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;gBAChD,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,MAAM,CAAC;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YAC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B,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC;YACxE,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC;QAE7B,oEAAoE;QACpE,yEAAyE;QACzE,2EAA2E;QAC3E,MAAM,0BAA0B,GAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW;YACjC,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE;YAC/B,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,QAAQ;gBACpC,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI;gBAChD,IAAI,CAAC,gBAAgB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,0BAA0B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,gBAAgB,CAAC,EAAE,CAAC;YACxF,MAAM,IAAI,CAAC,gBAAgB,CAAC;YAC5B,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACpC,CAAC;QAED,OAAO;YACN,GAAG,gBAAgB;YACnB,OAAO,EAAE;gBACR,GAAG,eAAe;gBAClB,QAAQ;gBACR,YAAY,EAAE,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,iBAAiB;gBAClE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE;aACrC;YACD,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK;YAC7B,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa;SAC7C,CAAC;IACH,CAAC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC3C,sBAAsB;IACtB,4BAA4B;CAC5B,CAAC","sourcesContent":["import type { PrepareNextTurnContext } from \"@earendil-works/pi-agent-core\";\nimport { normalizeToolResultImages } from \"../utils/tool-result-images.js\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { assertToolPairingInvariant } from \"./context-tool-pairing.js\";\nimport { redirectOversizedToolResult } from \"./tools/oversized-tool-result.js\";\n\nexport function _installAgentToolHooks(this: AgentSession): void {\n\tthis.agent.beforeToolCall = async ({ toolCall, args }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tif (!runner.hasHandlers(\"tool_call\")) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tawait this._agentEventQueue;\n\n\t\ttry {\n\t\t\tconst result = await runner.emitToolCall({\n\t\t\t\ttype: \"tool_call\",\n\t\t\t\ttoolName: toolCall.name,\n\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t});\n\t\t\tif (result?.block && result.terminate === true) {\n\t\t\t\tthis._terminatingToolCallIds.add(toolCall.id);\n\t\t\t} else {\n\t\t\t\tthis._terminatingToolCallIds.delete(toolCall.id);\n\t\t\t}\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tif (err instanceof Error) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tthrow new Error(`Extension failed, blocking execution: ${String(err)}`);\n\t\t}\n\t};\n\n\tthis.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tconst hookResult = runner.hasHandlers(\"tool_result\")\n\t\t\t? await runner.emitToolResult({\n\t\t\t\t\ttype: \"tool_result\",\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t\t\tcontent: result.content,\n\t\t\t\t\tdetails: result.details,\n\t\t\t\t\tisError,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\tconst hookContent = hookResult?.content ?? result.content;\n\t\t// Run after extension hooks so extension-injected images enter history at provider-safe sizes.\n\t\tconst normalizedContent = await normalizeToolResultImages(hookContent, {\n\t\t\tautoResizeImages: this.settingsManager.getImageAutoResize(),\n\t\t});\n\t\tconst resultReplacement =\n\t\t\thookResult || normalizedContent !== hookContent\n\t\t\t\t? {\n\t\t\t\t\t\tcontent: normalizedContent,\n\t\t\t\t\t\tdetails: hookResult?.details,\n\t\t\t\t\t\tisError: hookResult?.isError ?? isError,\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tconst finalResult = {\n\t\t\tcontent: normalizedContent,\n\t\t\t// Preserve original details when an extension hook rewrites only content;\n\t\t\t// the redirect check only replaces model-visible content blocks.\n\t\t\tdetails: hookResult?.details ?? result.details,\n\t\t};\n\t\tconst finalIsError = hookResult?.isError ?? isError;\n\t\tconst redirectReplacement = await redirectOversizedToolResult({\n\t\t\ttoolName: toolCall.name,\n\t\t\ttoolCallId: toolCall.id,\n\t\t\tresult: finalResult,\n\t\t\tisError: finalIsError,\n\t\t\tsessionId: this.sessionManager.getSessionId(),\n\t\t\tsessionDir: this.sessionManager.getSessionDir() || undefined,\n\t\t\tmaxResultSizeChars: this.getToolDefinition(toolCall.name)?.maxResultSizeChars,\n\t\t});\n\n\t\tif (result.terminate === true) this._terminatingToolCallIds.add(toolCall.id);\n\t\telse this._terminatingToolCallIds.delete(toolCall.id);\n\t\treturn redirectReplacement ?? resultReplacement;\n\t};\n}\n\n/**\n * Install a prepareNextTurnWithContext hook so that extension tool changes\n * (e.g. setActiveTools) and before_agent_start systemPrompt overrides are\n * applied to the next provider request within the same run.\n */\nexport function _installAgentNextTurnRefresh(this: AgentSession): void {\n\tconst previousPrepareNextTurnWithContext =\n\t\tthis.agent.prepareNextTurnWithContext ??\n\t\t(this.agent.prepareNextTurn\n\t\t\t? async (_turn: PrepareNextTurnContext, signal?: AbortSignal) => await this.agent.prepareNextTurn?.(signal)\n\t\t\t: undefined);\n\tconst previousTransformContext = this.agent.transformContext;\n\tthis.agent.transformContext = async (messages, signal) => {\n\t\tconst transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;\n\t\tconst guarded = this._finishPostToolCompactionPreflight(transformed);\n\t\t// Last checkpoint before provider conversion: a structurally invalid context\n\t\t// here becomes an unrecoverable provider 400, so surface it as an Atomic error.\n\t\tassertToolPairingInvariant(guarded);\n\t\treturn guarded;\n\t};\n\tthis.agent.prepareNextTurnWithContext = async (turn, signal) => {\n\t\tconst previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal);\n\t\tconst previousContext = previousSnapshot?.context ?? turn.context;\n\t\tconst toolCallIds = turn.message.content.filter((part) => part.type === \"toolCall\").map((part) => part.id);\n\t\tconst terminatingBatch =\n\t\t\ttoolCallIds.length > 0 && toolCallIds.every((id) => this._terminatingToolCallIds.has(id));\n\t\tfor (const id of toolCallIds) this._terminatingToolCallIds.delete(id);\n\t\tconst messages =\n\t\t\tturn.toolResults.length > 0 && !terminatingBatch\n\t\t\t\t? await this._preflightPostToolContext(previousContext.messages, signal)\n\t\t\t\t: previousContext.messages;\n\n\t\t// Restore before queued follow-up messages are polled, but keep the\n\t\t// fallback for deceptive completions that event processing must retry on\n\t\t// the same model (safety refusal, empty completion, or length truncation).\n\t\tconst preserveFallbackForFailure =\n\t\t\tturn.message.role === \"assistant\" &&\n\t\t\t!this.agent.hasQueuedMessages() &&\n\t\t\t(turn.message.stopReason === \"length\" ||\n\t\t\t\tthis._isEmptyCompletion?.(turn.message) === true ||\n\t\t\t\tthis._isSafetyRefusal?.(turn.message) === true);\n\t\tif (!preserveFallbackForFailure && (turn.toolResults.length === 0 || terminatingBatch)) {\n\t\t\tawait this._agentEventQueue;\n\t\t\tawait this._restoreFallbackModel();\n\t\t}\n\n\t\treturn {\n\t\t\t...previousSnapshot,\n\t\t\tcontext: {\n\t\t\t\t...previousContext,\n\t\t\t\tmessages,\n\t\t\t\tsystemPrompt: this._systemPromptOverride ?? this._baseSystemPrompt,\n\t\t\t\ttools: this.agent.state.tools.slice(),\n\t\t\t},\n\t\t\tmodel: this.agent.state.model,\n\t\t\tthinkingLevel: this.agent.state.thinkingLevel,\n\t\t};\n\t};\n}\n\nexport const agentSessionToolHooksMethods = {\n\t_installAgentToolHooks,\n\t_installAgentNextTurnRefresh,\n};\n"]}
1
+ {"version":3,"file":"agent-session-tool-hooks.js","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,MAAM,UAAU,sBAAsB;IACrC,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,IAAI,CAAC,gBAAgB,CAAC;QAE5B,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC;gBACxC,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,QAAQ,CAAC,IAAI;gBACvB,UAAU,EAAE,QAAQ,CAAC,EAAE;gBACvB,KAAK,EAAE,IAA+B;aACtC,CAAC,CAAC;YACH,IAAI,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;gBAChD,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,MAAM,CAAC;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,GAAG,YAA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C,QAAQ,EAAE,MAAM,CAAC;YACxE,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC;QAE7B,4EAA4E;QAC5E,4EAA4E;QAC5E,8EAA8E;QAC9E,MAAM,0BAA0B,GAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW;YACjC,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE;YAC/B,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,QAAQ;gBACpC,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI;gBAChD,IAAI,CAAC,gBAAgB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,0BAA0B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,gBAAgB,CAAC,EAAE,CAAC;YACxF,MAAM,IAAI,CAAC,gBAAgB,CAAC;YAC5B,MAAM,IAAI,CAAC,yBAAyB,EAAE,CAAC;QACxC,CAAC;QAED,OAAO;YACN,GAAG,gBAAgB;YACnB,OAAO,EAAE;gBACR,GAAG,eAAe;gBAClB,QAAQ;gBACR,YAAY,EAAE,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,iBAAiB;gBAClE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE;aACrC;YACD,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK;YAC7B,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa;SAC7C,CAAC;IACH,CAAC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC3C,sBAAsB;IACtB,4BAA4B;CAC5B,CAAC","sourcesContent":["import type { PrepareNextTurnContext } from \"@earendil-works/pi-agent-core\";\nimport { normalizeToolResultImages } from \"../utils/tool-result-images.js\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { assertToolPairingInvariant } from \"./context-tool-pairing.js\";\nimport { redirectOversizedToolResult } from \"./tools/oversized-tool-result.js\";\n\nexport function _installAgentToolHooks(this: AgentSession): void {\n\tthis.agent.beforeToolCall = async ({ toolCall, args }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tif (!runner.hasHandlers(\"tool_call\")) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tawait this._agentEventQueue;\n\n\t\ttry {\n\t\t\tconst result = await runner.emitToolCall({\n\t\t\t\ttype: \"tool_call\",\n\t\t\t\ttoolName: toolCall.name,\n\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t});\n\t\t\tif (result?.block && result.terminate === true) {\n\t\t\t\tthis._terminatingToolCallIds.add(toolCall.id);\n\t\t\t} else {\n\t\t\t\tthis._terminatingToolCallIds.delete(toolCall.id);\n\t\t\t}\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tif (err instanceof Error) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tthrow new Error(`Extension failed, blocking execution: ${String(err)}`);\n\t\t}\n\t};\n\n\tthis.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tconst hookResult = runner.hasHandlers(\"tool_result\")\n\t\t\t? await runner.emitToolResult({\n\t\t\t\t\ttype: \"tool_result\",\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t\t\tcontent: result.content,\n\t\t\t\t\tdetails: result.details,\n\t\t\t\t\tisError,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\tconst hookContent = hookResult?.content ?? result.content;\n\t\t// Run after extension hooks so extension-injected images enter history at provider-safe sizes.\n\t\tconst normalizedContent = await normalizeToolResultImages(hookContent, {\n\t\t\tautoResizeImages: this.settingsManager.getImageAutoResize(),\n\t\t});\n\t\tconst resultReplacement =\n\t\t\thookResult || normalizedContent !== hookContent\n\t\t\t\t? {\n\t\t\t\t\t\tcontent: normalizedContent,\n\t\t\t\t\t\tdetails: hookResult?.details,\n\t\t\t\t\t\tisError: hookResult?.isError ?? isError,\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tconst finalResult = {\n\t\t\tcontent: normalizedContent,\n\t\t\t// Preserve original details when an extension hook rewrites only content;\n\t\t\t// the redirect check only replaces model-visible content blocks.\n\t\t\tdetails: hookResult?.details ?? result.details,\n\t\t};\n\t\tconst finalIsError = hookResult?.isError ?? isError;\n\t\tconst redirectReplacement = await redirectOversizedToolResult({\n\t\t\ttoolName: toolCall.name,\n\t\t\ttoolCallId: toolCall.id,\n\t\t\tresult: finalResult,\n\t\t\tisError: finalIsError,\n\t\t\tsessionId: this.sessionManager.getSessionId(),\n\t\t\tsessionDir: this.sessionManager.getSessionDir() || undefined,\n\t\t\tmaxResultSizeChars: this.getToolDefinition(toolCall.name)?.maxResultSizeChars,\n\t\t});\n\n\t\tif (result.terminate === true) this._terminatingToolCallIds.add(toolCall.id);\n\t\telse this._terminatingToolCallIds.delete(toolCall.id);\n\t\treturn redirectReplacement ?? resultReplacement;\n\t};\n}\n\n/**\n * Install a prepareNextTurnWithContext hook so that extension tool changes\n * (e.g. setActiveTools) and before_agent_start systemPrompt overrides are\n * applied to the next provider request within the same run.\n */\nexport function _installAgentNextTurnRefresh(this: AgentSession): void {\n\tconst previousPrepareNextTurnWithContext =\n\t\tthis.agent.prepareNextTurnWithContext ??\n\t\t(this.agent.prepareNextTurn\n\t\t\t? async (_turn: PrepareNextTurnContext, signal?: AbortSignal) => await this.agent.prepareNextTurn?.(signal)\n\t\t\t: undefined);\n\tconst previousTransformContext = this.agent.transformContext;\n\tthis.agent.transformContext = async (messages, signal) => {\n\t\tconst transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;\n\t\tconst guarded = this._finishPostToolCompactionPreflight(transformed);\n\t\t// Last checkpoint before provider conversion: a structurally invalid context\n\t\t// here becomes an unrecoverable provider 400, so surface it as an Atomic error.\n\t\tassertToolPairingInvariant(guarded);\n\t\treturn guarded;\n\t};\n\tthis.agent.prepareNextTurnWithContext = async (turn, signal) => {\n\t\tconst previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal);\n\t\tconst previousContext = previousSnapshot?.context ?? turn.context;\n\t\tconst toolCallIds = turn.message.content.filter((part) => part.type === \"toolCall\").map((part) => part.id);\n\t\tconst terminatingBatch =\n\t\t\ttoolCallIds.length > 0 && toolCallIds.every((id) => this._terminatingToolCallIds.has(id));\n\t\tfor (const id of toolCallIds) this._terminatingToolCallIds.delete(id);\n\t\tconst messages =\n\t\t\tturn.toolResults.length > 0 && !terminatingBatch\n\t\t\t\t? await this._preflightPostToolContext(previousContext.messages, signal)\n\t\t\t\t: previousContext.messages;\n\n\t\t// Settle before queued follow-up messages are polled, but keep the fallback\n\t\t// lifecycle open for deceptive completions that event processing must retry\n\t\t// on the same model (safety refusal, empty completion, or length truncation).\n\t\tconst preserveFallbackForFailure =\n\t\t\tturn.message.role === \"assistant\" &&\n\t\t\t!this.agent.hasQueuedMessages() &&\n\t\t\t(turn.message.stopReason === \"length\" ||\n\t\t\t\tthis._isEmptyCompletion?.(turn.message) === true ||\n\t\t\t\tthis._isSafetyRefusal?.(turn.message) === true);\n\t\tif (!preserveFallbackForFailure && (turn.toolResults.length === 0 || terminatingBatch)) {\n\t\t\tawait this._agentEventQueue;\n\t\t\tawait this._settleFallbackModelScope();\n\t\t}\n\n\t\treturn {\n\t\t\t...previousSnapshot,\n\t\t\tcontext: {\n\t\t\t\t...previousContext,\n\t\t\t\tmessages,\n\t\t\t\tsystemPrompt: this._systemPromptOverride ?? this._baseSystemPrompt,\n\t\t\t\ttools: this.agent.state.tools.slice(),\n\t\t\t},\n\t\t\tmodel: this.agent.state.model,\n\t\t\tthinkingLevel: this.agent.state.thinkingLevel,\n\t\t};\n\t};\n}\n\nexport const agentSessionToolHooksMethods = {\n\t_installAgentToolHooks,\n\t_installAgentNextTurnRefresh,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"atomic-guide-command.d.ts","sourceRoot":"","sources":["../../src/core/atomic-guide-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAClD,eAAO,MAAM,gCAAgC,qCAAqC,CAAC;AA6NnF,QAAA,MAAM,cAAc;mBAEZ,UAAU;;oBAET,UAAU;0BACJ,oBAAoB;;;mBAI3B,WAAW;;oBAEV,WAAW;0BACL,iBAAiB;;;mBAIxB,SAAS;;oBAER,SAAS;0BACH,0BAA0B;;;mBAIjC,WAAW;;oBAEV,YAAY;0BACN,sBAAsB;;EASlC,CAAC;AAEJ,KAAK,kBAAkB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1D,KAAK,sBAAsB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,sBAAsB,CAAC;AAE9D,eAAO,MAAM,yBAAyB,EAAE,SAAS,qBAAqB,EAErE,CAAC;AAcF,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,qBAAqB,CAEvF;AA6BD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAKtE;AAED,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,EAAE,GAAG,IAAI,CAW3F;AAED,iBAAS,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CActD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAA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AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,qBAAqB,GAAG,eAAe,CAEvF"}
@@ -25,7 +25,7 @@ Atomic turns non-trivial work into executable, inspectable workflows. Default to
25
25
  | On-call / broken behavior | Use a focused workflow to reproduce, diagnose, repair, and validate; direct debugger/subagent calls remain useful as stages or for tiny deterministic diagnosis |
26
26
  | Research → spec → implementation | Use \`/skill:research-codebase\`, then \`/skill:create-spec\`, then a named or custom implementation workflow with explicit validation and review |
27
27
  | Testing / regression hardening | Use a workflow for test/fix loops so retries, evidence, and the passing stop condition are tracked |
28
- | Large repo discovery | Run \`/parallel codebase-locator "map the area" -> codebase-analyzer "trace the current flow" -> codebase-pattern-finder "find patterns"\`, or use repository-focused \`fan-out-and-synthesize\` branches plus a synthesis barrier |
28
+ | Large repo discovery | Use repository-focused \`fan-out-and-synthesize\` branches plus a synthesis barrier, or launch locator/analyzer/pattern-finder children with the \`subagent\` tool |
29
29
  | UI / product polish | Run \`/skill:impeccable\` for interface critique and refinement, or \`/workflow open-claude-design\` for one generated preview plus a live review session and export |
30
30
 
31
31
  ## Built-in workflows
@@ -52,7 +52,7 @@ Use \`/workflow list\` to see what is available and \`/workflow inputs <name>\`
52
52
  | \`create-spec\` | turn research into an implementation-ready plan | \`/skill:create-spec from research/docs/<date>-<topic>.md\` |
53
53
  | \`tdd\` | do test-first feature or bug work | \`/skill:tdd\` |
54
54
  | \`prompt-engineer\` | tighten a vague prompt before a long run | \`/skill:prompt-engineer Draft a sharper implementation prompt for ...\` |
55
- | \`subagent\` | learn delegation patterns and exact \`/run\` and \`/parallel\` usage | \`/skill:subagent\` |
55
+ | \`subagent\` | learn when and how to delegate with the \`subagent\` tool | \`/skill:subagent\` |
56
56
  | \`impeccable\` | critique or refine frontend and product UI | \`/skill:impeccable\` |
57
57
  | \`show-me\` | explain a topic visually with concise diagrams, code-shape sketches, or focused HTML artifacts (HumanLayer, MIT) | \`/skill:show-me\` |
58
58
 
@@ -67,9 +67,6 @@ Subagents are focused child Atomic sessions you can point at one job inside the
67
67
  | \`codebase-pattern-finder\` | find existing code to model after |
68
68
  | \`debugger\` | reproduce, diagnose, and fix broken behavior |
69
69
 
70
- How the direct commands map to repo work:
71
- - \`/run\` = one specialist on one job, for example \`/run codebase-locator "Map the webhook retry flow"\`
72
- - \`/parallel\` = several independent specialists at once, for example \`/parallel codebase-locator "map retry files" -> codebase-pattern-finder "find existing retry/backoff patterns" -> codebase-online-researcher "research current retry guidance"\`
73
70
 
74
71
  ─────────────────────────────────────────────────────────────────
75
72
 
@@ -115,11 +112,7 @@ Loop or stop-condition phrasing is a key workflow signal. Encode \`do X until Y\
115
112
 
116
113
  Use the workflow's deterministic evidence, verifier decision, remaining-work report, and bound-exhaustion state to decide whether to ship, repair, unblock, or clarify. Keep PR/MR creation, deployment, and publication as separately authorized post-approval actions.
117
114
 
118
- If you implemented directly instead of using a workflow, you can still run:
119
-
120
- \`/parallel-review current diff\`
121
-
122
- Atomic will synthesize reviewer feedback and ask before applying fixes.
115
+ If you implemented directly instead of using a workflow, launch a fresh-context cleanup pass with the \`subagent\` tool and apply only the synthesized fixes you accept.
123
116
 
124
117
  ─────────────────────────────────────────────────────────────────
125
118
 
@@ -1 +1 @@
1
- {"version":3,"file":"atomic-guide-command.js","sourceRoot":"","sources":["../../src/core/atomic-guide-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,QAAQ,CAAC;AAClD,MAAM,CAAC,MAAM,gCAAgC,GAAG,kCAAkC,CAAC;AAEnF,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDA0EmC,CAAC;AAErD,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;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E,CAAC;IACzC,MAAM,cAAc,GAAG,cAAc,CAAC,aAAa,CAAC;SAClD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;SAC5C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;SACX,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;SACpC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,sSAAsS,CAAC;IAC/S,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC,IAAI,aAAa,CAAC;IACxE,OAAO,mBAAmB,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,YAAY,yLAAyL,CAAC;AAC7Q,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAqB,EAAE,GAAW;IACvE,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,sBAAsB,EAAE,CAAC;IACrD,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,MAA6B;IACrE,OAAO,wBAAwB,CAAC,MAAM,CAAC,EAAE,IAAI,IAAI,MAAM,CAAC;AACzD,CAAC","sourcesContent":["import * as path from \"node:path\";\nimport type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport { getChangelogPath, parseChangelog } from \"../utils/changelog.ts\";\n\nexport const ATOMIC_GUIDE_COMMAND_NAME = \"atomic\";\nexport const ATOMIC_GUIDE_COMMAND_DESCRIPTION = \"Atomic onboarding and help guide\";\n\nconst OVERVIEW = `# Atomic overview\n\nAtomic turns non-trivial work into executable, inspectable workflows. Default to a workflow for implementation, build, debugging, bug fixes, migrations, features, scoped multi-file changes, and validated docs/code work, or whenever a request has dependencies, handoffs, uncertainty, review gates, measurable done criteria, or evidence requirements. Use direct chat for tiny deterministic low-risk answers or edits. Loop-shaped prompts such as \\`do X until Y\\`, \\`review/fix until passing\\`, or \\`run checks and fix until green\\` are especially strong workflow signals. Workflow-first is not builtin-only or monolithic: use named workflows, direct modes, author a custom TypeScript \\`workflow({...})\\` inline, or import reusable project/package and builtin definitions from \\`@bastani/workflows/builtin\\` and nest them with \\`ctx.workflow(...)\\`. Nested children may compose further children within \\`maxDepth\\`, enabling powerful research → implementation → verification → approval graphs from reusable parts. Start Atomic in a project with \\`atomic\\`, then talk to it normally. Use \\`@file\\` to attach files, \\`!command\\` to run shell output through the model, and \\`!!command\\` to run shell output without adding it to context.\n\n## Core session commands\n\n| Command | Use |\n|---|---|\n| \\`/login\\` | configure auth |\n| \\`/model\\` | switch model |\n| \\`/settings\\` | thinking level, theme, message delivery, transport |\n| \\`/new\\`, \\`/resume\\` | start or resume sessions |\n| \\`/tree\\`, \\`/fork\\`, \\`/clone\\` | branch or navigate session history |\n| \\`/compact\\` | delete safe older context verbatim |\n| \\`/hotkeys\\`, \\`/changelog\\` | local help and release notes |\n\n## Examples of using Atomic\n\n| Goal | How to use |\n|---|---|\n| On-call / broken behavior | Use a focused workflow to reproduce, diagnose, repair, and validate; direct debugger/subagent calls remain useful as stages or for tiny deterministic diagnosis |\n| Research → spec → implementation | Use \\`/skill:research-codebase\\`, then \\`/skill:create-spec\\`, then a named or custom implementation workflow with explicit validation and review |\n| Testing / regression hardening | Use a workflow for test/fix loops so retries, evidence, and the passing stop condition are tracked |\n| Large repo discovery | Run \\`/parallel codebase-locator \"map the area\" -> codebase-analyzer \"trace the current flow\" -> codebase-pattern-finder \"find patterns\"\\`, or use repository-focused \\`fan-out-and-synthesize\\` branches plus a synthesis barrier |\n| UI / product polish | Run \\`/skill:impeccable\\` for interface critique and refinement, or \\`/workflow open-claude-design\\` for one generated preview plus a live review session and export |\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`classify-and-act\\` | structured routing with a low-confidence human fallback | \\`/workflow classify-and-act prompt=\"Triage this request\"\\` |\n| \\`fan-out-and-synthesize\\` | independent slices or repository-focused research with artifact synthesis | \\`/workflow fan-out-and-synthesize prompt=\"Map payment retries by subsystem\"\\` |\n| \\`adversarial-verification\\` | fresh verification and bounded repair of a candidate | \\`/workflow adversarial-verification task=\"Verify the migration patch\"\\` |\n| \\`generate-and-filter\\` | generate many candidates and keep a distinct shortlist | \\`/workflow generate-and-filter prompt=\"Propose command names\"\\` |\n| \\`tournament\\` | compare whole solutions through balanced pairwise judging | \\`/workflow tournament prompt=\"Design the retry strategy\"\\` |\n| \\`loop-until-done\\` | iterate until explicit evidence passes or the bound is exhausted | \\`/workflow loop-until-done prompt=\"Repair failures until tests pass\"\\` |\n| \\`goal\\` | ledger-backed autonomous work with receipts and reviewer-gated completion | \\`/workflow goal objective=\"Update CLI docs and validate the docs build\"\\` |\n| \\`ralph\\` | research-first delegated implementation with bounded multi-model review | \\`/workflow ralph prompt=\"Implement specs/rate-limit.md\"\\` |\n| \\`open-claude-design\\` | UI and design-system generation with one live review session and export | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow list\\` to see what is available and \\`/workflow inputs <name>\\` to inspect inputs in your environment.\n\n## Top skills\n\n| Skill | When to use | How to run |\n|---|---|---|\n| \\`research-codebase\\` | write a grounded research artifact for one subsystem or question | \\`/skill:research-codebase how the rate limiter works in src/middleware/\\` |\n| \\`create-spec\\` | turn research into an implementation-ready plan | \\`/skill:create-spec from research/docs/<date>-<topic>.md\\` |\n| \\`tdd\\` | do test-first feature or bug work | \\`/skill:tdd\\` |\n| \\`prompt-engineer\\` | tighten a vague prompt before a long run | \\`/skill:prompt-engineer Draft a sharper implementation prompt for ...\\` |\n| \\`subagent\\` | learn delegation patterns and exact \\`/run\\` and \\`/parallel\\` usage | \\`/skill:subagent\\` |\n| \\`impeccable\\` | critique or refine frontend and product UI | \\`/skill:impeccable\\` |\n| \\`show-me\\` | explain a topic visually with concise diagrams, code-shape sketches, or focused HTML artifacts (HumanLayer, MIT) | \\`/skill:show-me\\` |\n\n## Subagents\n\nSubagents are focused child Atomic sessions you can point at one job inside the repo.\n\n| Built-in subagent | Use |\n|---|---|\n| \\`codebase-locator\\` | find relevant files, tests, entrypoints, and configs |\n| \\`codebase-analyzer\\` | explain current behavior with file:line refs |\n| \\`codebase-pattern-finder\\` | find existing code to model after |\n| \\`debugger\\` | reproduce, diagnose, and fix broken behavior |\n\nHow the direct commands map to repo work:\n- \\`/run\\` = one specialist on one job, for example \\`/run codebase-locator \"Map the webhook retry flow\"\\`\n- \\`/parallel\\` = several independent specialists at once, for example \\`/parallel codebase-locator \"map retry files\" -> codebase-pattern-finder \"find existing retry/backoff patterns\" -> codebase-online-researcher \"research current retry guidance\"\\`\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see the pieces used on a code task\n\\`/atomic workflows\\` — learn when to use workflows`;\n\nconst EXAMPLE = `# Practical example\n\nThis example shows a spec-driven development process whose clearly delegated autonomous implementation benefits from durable workflow execution. For interactive or conversation-led work, stay inline or use bounded subagents while the parent remains in control. Type the examples below into the Atomic TUI chat after starting \\`atomic\\` in your project.\n\n## 1. Research what exists\n\nUse \\`/skill:research-codebase\\` for a scoped area, subsystem, or directory:\n\n\\`/skill:research-codebase how the rate limiter works in src/middleware/\\`\n\nFor repository-wide research, use \\`fan-out-and-synthesize\\` with distinct subsystem partitions, artifact outputs, and a synthesis prompt that cites concrete paths:\n\n\\`/workflow fan-out-and-synthesize prompt=\"Partition payment retries by subsystem and synthesize cited end-to-end findings\"\\`\n\nIf the research prompt is vague, tighten it first with \\`/skill:prompt-engineer\\`:\n\n\\`/skill:prompt-engineer Draft a sharper repo-research prompt for understanding payment retries end to end, including retries, queues, and failure handling.\\`\n\n## 2. Create a spec when requirements are fuzzy\n\nSkip this if the implementation request is already precise.\n\n\\`/skill:create-spec from research/docs/<date>-<topic>.md\\`\n\n## 3. Implement with review built in\n\nDefault to a workflow for non-trivial implementation and review. Use direct chat only for tiny deterministic low-risk edits; use focused subagents inside workflow stages or for bounded specialist passes. Choose an installed workflow when it fits, or author a custom TypeScript workflow inline from the starter patterns when the task needs a richer graph.\n\nFor implementation with review built in, author a task-specific worker → fresh verifier → reducer loop. Give it literal acceptance criteria, deterministic checks, evidence-backed repair payloads, and a bounded stop condition:\n\n\\`Create and run a workflow that implements specs/<date>-<topic>.md, runs focused tests, sends the patch to fresh verifiers, and repairs findings until the documented behavior passes or the iteration bound is reached.\\`\n\nLoop or stop-condition phrasing is a key workflow signal. Encode \\`do X until Y\\`, \\`review/fix until passing\\`, or \\`run checks and fix until green\\` as explicit bounded workflow gates rather than informal retries.\n\n## 4. Decide and land\n\nUse the workflow's deterministic evidence, verifier decision, remaining-work report, and bound-exhaustion state to decide whether to ship, repair, unblock, or clarify. Keep PR/MR creation, deployment, and publication as separately authorized post-approval actions.\n\nIf you implemented directly instead of using a workflow, you can still run:\n\n\\`/parallel-review current diff\\`\n\nAtomic will synthesize reviewer feedback and ask before applying fixes.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic workflows\\` — learn when to use workflows\n\\`/atomic overview\\` — quick refresh`;\n\nconst WORKFLOWS = `# Workflows primer\n\nA workflow is a TypeScript-defined pipeline exported from \\`workflow({...})\\`. It can run tasks, chains, parallel fan-out, human-in-the-loop prompts, background status, and model fallback chains.\n\nDefault to workflows for non-trivial work and requests with inherent structure plus a verifiable objective. Implementation, debugging, migrations, multi-file changes, validation, review, evidence requirements, and explicit stop conditions are workflow-shaped; use direct chat only for tiny deterministic low-risk answers or edits.\n\nWorkflow-first is not builtin-only or monolithic. Atomic can author custom TypeScript \\`workflow({...})\\` definitions inline, and workflows can import reusable project/package definitions or builtins from \\`@bastani/workflows/builtin\\`, then nest them with \\`ctx.workflow(...)\\`. Imported children can nest further children within \\`maxDepth\\`, so compose proven research, implementation, design, verification, and approval workflows instead of copying their stages. Use the documented starter patterns for classify-and-act routing, dynamic fan-out and synthesis, adversarial verification, candidate selection, and bounded convergence. Atomic writes the parent definition, reloads it, and runs the composed graph.\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`classify-and-act\\` | structured routing | \\`/workflow classify-and-act prompt=\"Triage this request\"\\` |\n| \\`fan-out-and-synthesize\\` | independent slices or repository research | \\`/workflow fan-out-and-synthesize prompt=\"Map payment retries by subsystem\"\\` |\n| \\`adversarial-verification\\` | fresh verification and bounded repair | \\`/workflow adversarial-verification task=\"Verify the patch\"\\` |\n| \\`generate-and-filter\\` | candidate generation and shortlisting | \\`/workflow generate-and-filter prompt=\"Propose command names\"\\` |\n| \\`tournament\\` | balanced whole-solution comparison | \\`/workflow tournament prompt=\"Design the retry strategy\"\\` |\n| \\`loop-until-done\\` | bounded convergence on explicit evidence | \\`/workflow loop-until-done prompt=\"Repair failures until tests pass\"\\` |\n| \\`goal\\` | durable ledger, bounded orchestration, and reviewer-gated completion | \\`/workflow goal objective=\"Update CLI docs and validate the docs build\"\\` |\n| \\`ralph\\` | research-first delegated implementation and iterative review | \\`/workflow ralph prompt=\"Implement specs/rate-limit.md\"\\` |\n| \\`open-claude-design\\` | frontend and product design | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow inputs <name>\\` to inspect exact inputs. Goal and Ralph skip PR creation unless \\`create_pr=true\\` explicitly authorizes their post-approval final stage. Use \\`/skill:research-codebase\\` for one focused subsystem and repository-focused \\`fan-out-and-synthesize\\` for independent whole-repository slices.\n\nIf you are drafting research, reviewer, or synthesis prompts for a workflow, use \\`/skill:prompt-engineer\\` first. It is a good fit when a stage prompt feels vague, overloaded, or underspecified.\n\n## What good workflow authoring looks like\n\nA good workflow request is explicit about stage purpose, model choice, handoff, and the decision each step must return.\n\nFor workflow-owned side effects such as filesystem writes, network mutations, and external API actions, prefer \\`ctx.tool(name, args, fn)\\`: completed calls are durably cached, so resume returns the saved result without rerunning \\`fn\\`. Keep pure computation as ordinary TypeScript, and do not wrap agent-stage internals or every function call indiscriminately.\n\nExample: ask Atomic in chat with something like this:\n\n~~~text\nCreate a reusable workflow called review-changes.\n\nIt should accept one required text input called target for a diff, PR summary, or review target.\n\nRun two independent review stages in parallel with fresh context:\n- one reviewer focused on correctness, regressions, and missing tests using openai-codex/gpt-5.5 at xhigh thinking\n- one reviewer focused on edge cases, maintainability, and hidden risks using anthropic/claude-opus-4-8 at xhigh thinking\n\nThen add an aggregate stage that consolidates both reviews, deduplicates overlap, keeps only evidence-backed issues, and separates blockers from optional suggestions using openai/gpt-5.5 at high thinking.\n\nFinally add an adjudicate stage using anthropic/claude-sonnet-4 at high thinking that decides what to fix now, what to defer, and what to reject. Return a short action list with rationale.\n\nThe workflow should return structured output with consolidated_review and decision fields.\n~~~\n\nWhy this is good:\n- it names the workflow and required input\n- it specifies which stages are parallel vs sequential\n- each stage has one job\n- it defines the handoff and final outputs\n- it calls out model choice and thinking level where that matters\n\n## Run and inspect\n\n\\`/workflow list\\`\n\n\\`/workflow inputs fan-out-and-synthesize\\`\n\n\\`/workflow fan-out-and-synthesize prompt=\"Partition the settings flow by subsystem and synthesize cited findings\"\\`\n\n\\`/workflow inputs adversarial-verification\\`\n\n\\`/workflow adversarial-verification task=\"Verify the settings form validation patch\"\\`\n\n\\`/workflow status\\`\n\n\\`/workflow connect <run-id>\\`\n\n\\`/workflow interrupt <run-id>\\`\n\n\\`/workflow quit <run-id>\\`\n\n\\`/workflow resume <run-id>\\`\n\nWorkflows run as background tasks. Use F2 or \\`/workflow connect <run-id>\\` for the graph viewer. Human-in-the-loop prompts appear there, not as chat modals, and awaiting-input states do not wake the main chat agent. Completion and failure notices are steered back into the main chat; answers submitted in the workflow UI interrupt stale main-chat questions so the model does not ask again.\n\n## Author your own\n\nDescribe your workflow in plain chat — say what you want the workflow to accomplish, what inputs it should accept, what stages should run, and what final output or decision it should return. Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\`, ask clarifying questions when stage purpose, models, or handoffs are ambiguous, and run \\`/workflow reload\\` so you can launch it immediately.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see workflows in a normal task flow\n\\`/atomic overview\\` — quick refresh`;\n\nconst GUIDE_SECTIONS = [\n\t{\n\t\tname: \"overview\",\n\t\taliases: [],\n\t\tlabel: \"overview\",\n\t\tdescription: \"30-second overview\",\n\t\trender: () => OVERVIEW,\n\t},\n\t{\n\t\tname: \"workflows\",\n\t\taliases: [\"workflow\"],\n\t\tlabel: \"workflows\",\n\t\tdescription: \"Workflow primer\",\n\t\trender: () => WORKFLOWS,\n\t},\n\t{\n\t\tname: \"example\",\n\t\taliases: [\"examples\"],\n\t\tlabel: \"example\",\n\t\tdescription: \"Practical first workflow\",\n\t\trender: () => EXAMPLE,\n\t},\n\t{\n\t\tname: \"whats-new\",\n\t\taliases: [\"what's new\", \"whats new\", \"news\", \"updates\", \"changelog\"],\n\t\tlabel: \"what's new\",\n\t\tdescription: \"Recent release notes\",\n\t\trender: readLatestStableChangelog,\n\t},\n] as const satisfies readonly {\n\treadonly name: string;\n\treadonly aliases: readonly string[];\n\treadonly label: string;\n\treadonly description: string;\n\treadonly render: (cwd: string) => string;\n}[];\n\ntype AtomicGuideSection = (typeof GUIDE_SECTIONS)[number];\ntype AtomicGuideSectionName = AtomicGuideSection[\"name\"];\n\nexport type AtomicGuideHelpChoice = AtomicGuideSection[\"label\"];\n\nexport type AtomicGuideMode = \"help\" | AtomicGuideSectionName;\n\nexport const ATOMIC_GUIDE_HELP_CHOICES: readonly AtomicGuideHelpChoice[] = GUIDE_SECTIONS.map(\n\t(section) => section.label,\n);\n\nconst GUIDE_SECTIONS_BY_NAME = new Map<AtomicGuideSectionName, AtomicGuideSection>(\n\tGUIDE_SECTIONS.map((section) => [section.name, section]),\n);\nconst GUIDE_SECTIONS_BY_LABEL = new Map<string, AtomicGuideSection>(\n\tGUIDE_SECTIONS.map((section) => [section.label, section]),\n);\nconst GUIDE_SECTIONS_BY_INPUT = new Map<string, AtomicGuideSection>(\n\tGUIDE_SECTIONS.flatMap((section) =>\n\t\t[section.name, section.label, ...section.aliases].map((input) => [input, section] as const),\n\t),\n);\n\nexport function isAtomicGuideHelpChoice(choice: string): choice is AtomicGuideHelpChoice {\n\treturn GUIDE_SECTIONS_BY_LABEL.has(choice);\n}\n\nconst ATOMIC_GUIDE_TRAILING_PUNCTUATION = \"?!.,;:\";\n\nfunction stripTrailingAtomicGuidePunctuation(value: string): string {\n\tlet end = value.length;\n\twhile (end > 0 && ATOMIC_GUIDE_TRAILING_PUNCTUATION.includes(value.charAt(end - 1))) {\n\t\tend--;\n\t}\n\treturn value.slice(0, end);\n}\n\nfunction getGuideSectionForChoice(choice: string): AtomicGuideSection | undefined {\n\treturn GUIDE_SECTIONS_BY_LABEL.get(choice);\n}\n\nfunction getGuideSectionForMode(mode: AtomicGuideSectionName): AtomicGuideSection {\n\tconst section = GUIDE_SECTIONS_BY_NAME.get(mode);\n\tif (!section) throw new Error(`Unknown Atomic guide section: ${mode}`);\n\treturn section;\n}\n\nfunction getAtomicGuideHelpMenu(): string {\n\tconst sectionHelp = GUIDE_SECTIONS.map(\n\t\t(section) => `- \\`${section.label}\\` — run \\`/atomic ${section.label}\\``,\n\t).join(\"\\n\");\n\treturn `# Atomic\\n\\nSelect where to start:\\n\\n${sectionHelp}`;\n}\n\nexport function normalizeAtomicGuideMode(args: string): AtomicGuideMode {\n\tconst normalized = stripTrailingAtomicGuidePunctuation(args.trim().toLowerCase());\n\tif (!normalized) return \"help\";\n\n\treturn GUIDE_SECTIONS_BY_INPUT.get(normalized)?.name ?? \"help\";\n}\n\nexport function getAtomicGuideArgumentCompletions(prefix: string): AutocompleteItem[] | null {\n\tconst query = prefix.trim().toLowerCase();\n\tconst items = GUIDE_SECTIONS.map((section) => ({\n\t\tvalue: section.label,\n\t\tlabel: section.label,\n\t\tdescription: section.description,\n\t}));\n\tconst filtered = query\n\t\t? items.filter((item) => item.value.startsWith(query) || item.label.startsWith(query))\n\t\t: items;\n\treturn filtered.length > 0 ? filtered : null;\n}\n\nfunction readLatestStableChangelog(cwd: string): string {\n\tconst changelogPath = getChangelogPath();\n\tconst stableSections = parseChangelog(changelogPath)\n\t\t.filter((entry) => entry.prerelease === null)\n\t\t.slice(0, 3)\n\t\t.map((entry) => entry.content.trim())\n\t\t.filter(Boolean);\n\n\tif (stableSections.length === 0) {\n\t\treturn `# What's new\\n\\nNo stable release sections were found. Try \\`/changelog\\` for the interactive changelog viewer.\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n\t}\n\n\tconst relativePath = path.relative(cwd, changelogPath) || changelogPath;\n\treturn `# What's new\\n\\n${stableSections.join(\"\\n\\n\")}\\n\\nSource: \\`${relativePath}\\`\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n}\n\nexport function getAtomicGuideMessage(mode: AtomicGuideMode, cwd: string): string {\n\tif (mode === \"help\") return getAtomicGuideHelpMenu();\n\treturn getGuideSectionForMode(mode).render(cwd);\n}\n\nexport function atomicGuideModeForChoice(choice: AtomicGuideHelpChoice): AtomicGuideMode {\n\treturn getGuideSectionForChoice(choice)?.name ?? \"help\";\n}\n"]}
1
+ {"version":3,"file":"atomic-guide-command.js","sourceRoot":"","sources":["../../src/core/atomic-guide-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,QAAQ,CAAC;AAClD,MAAM,CAAC,MAAM,gCAAgC,GAAG,kCAAkC,CAAC;AAEnF,M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AAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC;AAED,SAAS,yBAAyB,CAAC,GAAW;IAC7C,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,MAAM,cAAc,GAAG,cAAc,CAAC,aAAa,CAAC;SAClD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;SAC5C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;SACX,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;SACpC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,sSAAsS,CAAC;IAC/S,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC,IAAI,aAAa,CAAC;IACxE,OAAO,mBAAmB,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,YAAY,yLAAyL,CAAC;AAC7Q,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAqB,EAAE,GAAW;IACvE,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,sBAAsB,EAAE,CAAC;IACrD,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,MAA6B;IACrE,OAAO,wBAAwB,CAAC,MAAM,CAAC,EAAE,IAAI,IAAI,MAAM,CAAC;AACzD,CAAC","sourcesContent":["import * as path from \"node:path\";\nimport type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport { getChangelogPath, parseChangelog } from \"../utils/changelog.ts\";\n\nexport const ATOMIC_GUIDE_COMMAND_NAME = \"atomic\";\nexport const ATOMIC_GUIDE_COMMAND_DESCRIPTION = \"Atomic onboarding and help guide\";\n\nconst OVERVIEW = `# Atomic overview\n\nAtomic turns non-trivial work into executable, inspectable workflows. Default to a workflow for implementation, build, debugging, bug fixes, migrations, features, scoped multi-file changes, and validated docs/code work, or whenever a request has dependencies, handoffs, uncertainty, review gates, measurable done criteria, or evidence requirements. Use direct chat for tiny deterministic low-risk answers or edits. Loop-shaped prompts such as \\`do X until Y\\`, \\`review/fix until passing\\`, or \\`run checks and fix until green\\` are especially strong workflow signals. Workflow-first is not builtin-only or monolithic: use named workflows, direct modes, author a custom TypeScript \\`workflow({...})\\` inline, or import reusable project/package and builtin definitions from \\`@bastani/workflows/builtin\\` and nest them with \\`ctx.workflow(...)\\`. Nested children may compose further children within \\`maxDepth\\`, enabling powerful research → implementation → verification → approval graphs from reusable parts. Start Atomic in a project with \\`atomic\\`, then talk to it normally. Use \\`@file\\` to attach files, \\`!command\\` to run shell output through the model, and \\`!!command\\` to run shell output without adding it to context.\n\n## Core session commands\n\n| Command | Use |\n|---|---|\n| \\`/login\\` | configure auth |\n| \\`/model\\` | switch model |\n| \\`/settings\\` | thinking level, theme, message delivery, transport |\n| \\`/new\\`, \\`/resume\\` | start or resume sessions |\n| \\`/tree\\`, \\`/fork\\`, \\`/clone\\` | branch or navigate session history |\n| \\`/compact\\` | delete safe older context verbatim |\n| \\`/hotkeys\\`, \\`/changelog\\` | local help and release notes |\n\n## Examples of using Atomic\n\n| Goal | How to use |\n|---|---|\n| On-call / broken behavior | Use a focused workflow to reproduce, diagnose, repair, and validate; direct debugger/subagent calls remain useful as stages or for tiny deterministic diagnosis |\n| Research → spec → implementation | Use \\`/skill:research-codebase\\`, then \\`/skill:create-spec\\`, then a named or custom implementation workflow with explicit validation and review |\n| Testing / regression hardening | Use a workflow for test/fix loops so retries, evidence, and the passing stop condition are tracked |\n| Large repo discovery | Use repository-focused \\`fan-out-and-synthesize\\` branches plus a synthesis barrier, or launch locator/analyzer/pattern-finder children with the \\`subagent\\` tool |\n| UI / product polish | Run \\`/skill:impeccable\\` for interface critique and refinement, or \\`/workflow open-claude-design\\` for one generated preview plus a live review session and export |\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`classify-and-act\\` | structured routing with a low-confidence human fallback | \\`/workflow classify-and-act prompt=\"Triage this request\"\\` |\n| \\`fan-out-and-synthesize\\` | independent slices or repository-focused research with artifact synthesis | \\`/workflow fan-out-and-synthesize prompt=\"Map payment retries by subsystem\"\\` |\n| \\`adversarial-verification\\` | fresh verification and bounded repair of a candidate | \\`/workflow adversarial-verification task=\"Verify the migration patch\"\\` |\n| \\`generate-and-filter\\` | generate many candidates and keep a distinct shortlist | \\`/workflow generate-and-filter prompt=\"Propose command names\"\\` |\n| \\`tournament\\` | compare whole solutions through balanced pairwise judging | \\`/workflow tournament prompt=\"Design the retry strategy\"\\` |\n| \\`loop-until-done\\` | iterate until explicit evidence passes or the bound is exhausted | \\`/workflow loop-until-done prompt=\"Repair failures until tests pass\"\\` |\n| \\`goal\\` | ledger-backed autonomous work with receipts and reviewer-gated completion | \\`/workflow goal objective=\"Update CLI docs and validate the docs build\"\\` |\n| \\`ralph\\` | research-first delegated implementation with bounded multi-model review | \\`/workflow ralph prompt=\"Implement specs/rate-limit.md\"\\` |\n| \\`open-claude-design\\` | UI and design-system generation with one live review session and export | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow list\\` to see what is available and \\`/workflow inputs <name>\\` to inspect inputs in your environment.\n\n## Top skills\n\n| Skill | When to use | How to run |\n|---|---|---|\n| \\`research-codebase\\` | write a grounded research artifact for one subsystem or question | \\`/skill:research-codebase how the rate limiter works in src/middleware/\\` |\n| \\`create-spec\\` | turn research into an implementation-ready plan | \\`/skill:create-spec from research/docs/<date>-<topic>.md\\` |\n| \\`tdd\\` | do test-first feature or bug work | \\`/skill:tdd\\` |\n| \\`prompt-engineer\\` | tighten a vague prompt before a long run | \\`/skill:prompt-engineer Draft a sharper implementation prompt for ...\\` |\n| \\`subagent\\` | learn when and how to delegate with the \\`subagent\\` tool | \\`/skill:subagent\\` |\n| \\`impeccable\\` | critique or refine frontend and product UI | \\`/skill:impeccable\\` |\n| \\`show-me\\` | explain a topic visually with concise diagrams, code-shape sketches, or focused HTML artifacts (HumanLayer, MIT) | \\`/skill:show-me\\` |\n\n## Subagents\n\nSubagents are focused child Atomic sessions you can point at one job inside the repo.\n\n| Built-in subagent | Use |\n|---|---|\n| \\`codebase-locator\\` | find relevant files, tests, entrypoints, and configs |\n| \\`codebase-analyzer\\` | explain current behavior with file:line refs |\n| \\`codebase-pattern-finder\\` | find existing code to model after |\n| \\`debugger\\` | reproduce, diagnose, and fix broken behavior |\n\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see the pieces used on a code task\n\\`/atomic workflows\\` — learn when to use workflows`;\n\nconst EXAMPLE = `# Practical example\n\nThis example shows a spec-driven development process whose clearly delegated autonomous implementation benefits from durable workflow execution. For interactive or conversation-led work, stay inline or use bounded subagents while the parent remains in control. Type the examples below into the Atomic TUI chat after starting \\`atomic\\` in your project.\n\n## 1. Research what exists\n\nUse \\`/skill:research-codebase\\` for a scoped area, subsystem, or directory:\n\n\\`/skill:research-codebase how the rate limiter works in src/middleware/\\`\n\nFor repository-wide research, use \\`fan-out-and-synthesize\\` with distinct subsystem partitions, artifact outputs, and a synthesis prompt that cites concrete paths:\n\n\\`/workflow fan-out-and-synthesize prompt=\"Partition payment retries by subsystem and synthesize cited end-to-end findings\"\\`\n\nIf the research prompt is vague, tighten it first with \\`/skill:prompt-engineer\\`:\n\n\\`/skill:prompt-engineer Draft a sharper repo-research prompt for understanding payment retries end to end, including retries, queues, and failure handling.\\`\n\n## 2. Create a spec when requirements are fuzzy\n\nSkip this if the implementation request is already precise.\n\n\\`/skill:create-spec from research/docs/<date>-<topic>.md\\`\n\n## 3. Implement with review built in\n\nDefault to a workflow for non-trivial implementation and review. Use direct chat only for tiny deterministic low-risk edits; use focused subagents inside workflow stages or for bounded specialist passes. Choose an installed workflow when it fits, or author a custom TypeScript workflow inline from the starter patterns when the task needs a richer graph.\n\nFor implementation with review built in, author a task-specific worker → fresh verifier → reducer loop. Give it literal acceptance criteria, deterministic checks, evidence-backed repair payloads, and a bounded stop condition:\n\n\\`Create and run a workflow that implements specs/<date>-<topic>.md, runs focused tests, sends the patch to fresh verifiers, and repairs findings until the documented behavior passes or the iteration bound is reached.\\`\n\nLoop or stop-condition phrasing is a key workflow signal. Encode \\`do X until Y\\`, \\`review/fix until passing\\`, or \\`run checks and fix until green\\` as explicit bounded workflow gates rather than informal retries.\n\n## 4. Decide and land\n\nUse the workflow's deterministic evidence, verifier decision, remaining-work report, and bound-exhaustion state to decide whether to ship, repair, unblock, or clarify. Keep PR/MR creation, deployment, and publication as separately authorized post-approval actions.\n\nIf you implemented directly instead of using a workflow, launch a fresh-context cleanup pass with the \\`subagent\\` tool and apply only the synthesized fixes you accept.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic workflows\\` — learn when to use workflows\n\\`/atomic overview\\` — quick refresh`;\n\nconst WORKFLOWS = `# Workflows primer\n\nA workflow is a TypeScript-defined pipeline exported from \\`workflow({...})\\`. It can run tasks, chains, parallel fan-out, human-in-the-loop prompts, background status, and model fallback chains.\n\nDefault to workflows for non-trivial work and requests with inherent structure plus a verifiable objective. Implementation, debugging, migrations, multi-file changes, validation, review, evidence requirements, and explicit stop conditions are workflow-shaped; use direct chat only for tiny deterministic low-risk answers or edits.\n\nWorkflow-first is not builtin-only or monolithic. Atomic can author custom TypeScript \\`workflow({...})\\` definitions inline, and workflows can import reusable project/package definitions or builtins from \\`@bastani/workflows/builtin\\`, then nest them with \\`ctx.workflow(...)\\`. Imported children can nest further children within \\`maxDepth\\`, so compose proven research, implementation, design, verification, and approval workflows instead of copying their stages. Use the documented starter patterns for classify-and-act routing, dynamic fan-out and synthesis, adversarial verification, candidate selection, and bounded convergence. Atomic writes the parent definition, reloads it, and runs the composed graph.\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`classify-and-act\\` | structured routing | \\`/workflow classify-and-act prompt=\"Triage this request\"\\` |\n| \\`fan-out-and-synthesize\\` | independent slices or repository research | \\`/workflow fan-out-and-synthesize prompt=\"Map payment retries by subsystem\"\\` |\n| \\`adversarial-verification\\` | fresh verification and bounded repair | \\`/workflow adversarial-verification task=\"Verify the patch\"\\` |\n| \\`generate-and-filter\\` | candidate generation and shortlisting | \\`/workflow generate-and-filter prompt=\"Propose command names\"\\` |\n| \\`tournament\\` | balanced whole-solution comparison | \\`/workflow tournament prompt=\"Design the retry strategy\"\\` |\n| \\`loop-until-done\\` | bounded convergence on explicit evidence | \\`/workflow loop-until-done prompt=\"Repair failures until tests pass\"\\` |\n| \\`goal\\` | durable ledger, bounded orchestration, and reviewer-gated completion | \\`/workflow goal objective=\"Update CLI docs and validate the docs build\"\\` |\n| \\`ralph\\` | research-first delegated implementation and iterative review | \\`/workflow ralph prompt=\"Implement specs/rate-limit.md\"\\` |\n| \\`open-claude-design\\` | frontend and product design | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow inputs <name>\\` to inspect exact inputs. Goal and Ralph skip PR creation unless \\`create_pr=true\\` explicitly authorizes their post-approval final stage. Use \\`/skill:research-codebase\\` for one focused subsystem and repository-focused \\`fan-out-and-synthesize\\` for independent whole-repository slices.\n\nIf you are drafting research, reviewer, or synthesis prompts for a workflow, use \\`/skill:prompt-engineer\\` first. It is a good fit when a stage prompt feels vague, overloaded, or underspecified.\n\n## What good workflow authoring looks like\n\nA good workflow request is explicit about stage purpose, model choice, handoff, and the decision each step must return.\n\nFor workflow-owned side effects such as filesystem writes, network mutations, and external API actions, prefer \\`ctx.tool(name, args, fn)\\`: completed calls are durably cached, so resume returns the saved result without rerunning \\`fn\\`. Keep pure computation as ordinary TypeScript, and do not wrap agent-stage internals or every function call indiscriminately.\n\nExample: ask Atomic in chat with something like this:\n\n~~~text\nCreate a reusable workflow called review-changes.\n\nIt should accept one required text input called target for a diff, PR summary, or review target.\n\nRun two independent review stages in parallel with fresh context:\n- one reviewer focused on correctness, regressions, and missing tests using openai-codex/gpt-5.5 at xhigh thinking\n- one reviewer focused on edge cases, maintainability, and hidden risks using anthropic/claude-opus-4-8 at xhigh thinking\n\nThen add an aggregate stage that consolidates both reviews, deduplicates overlap, keeps only evidence-backed issues, and separates blockers from optional suggestions using openai/gpt-5.5 at high thinking.\n\nFinally add an adjudicate stage using anthropic/claude-sonnet-4 at high thinking that decides what to fix now, what to defer, and what to reject. Return a short action list with rationale.\n\nThe workflow should return structured output with consolidated_review and decision fields.\n~~~\n\nWhy this is good:\n- it names the workflow and required input\n- it specifies which stages are parallel vs sequential\n- each stage has one job\n- it defines the handoff and final outputs\n- it calls out model choice and thinking level where that matters\n\n## Run and inspect\n\n\\`/workflow list\\`\n\n\\`/workflow inputs fan-out-and-synthesize\\`\n\n\\`/workflow fan-out-and-synthesize prompt=\"Partition the settings flow by subsystem and synthesize cited findings\"\\`\n\n\\`/workflow inputs adversarial-verification\\`\n\n\\`/workflow adversarial-verification task=\"Verify the settings form validation patch\"\\`\n\n\\`/workflow status\\`\n\n\\`/workflow connect <run-id>\\`\n\n\\`/workflow interrupt <run-id>\\`\n\n\\`/workflow quit <run-id>\\`\n\n\\`/workflow resume <run-id>\\`\n\nWorkflows run as background tasks. Use F2 or \\`/workflow connect <run-id>\\` for the graph viewer. Human-in-the-loop prompts appear there, not as chat modals, and awaiting-input states do not wake the main chat agent. Completion and failure notices are steered back into the main chat; answers submitted in the workflow UI interrupt stale main-chat questions so the model does not ask again.\n\n## Author your own\n\nDescribe your workflow in plain chat — say what you want the workflow to accomplish, what inputs it should accept, what stages should run, and what final output or decision it should return. Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\`, ask clarifying questions when stage purpose, models, or handoffs are ambiguous, and run \\`/workflow reload\\` so you can launch it immediately.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see workflows in a normal task flow\n\\`/atomic overview\\` — quick refresh`;\n\nconst GUIDE_SECTIONS = [\n\t{\n\t\tname: \"overview\",\n\t\taliases: [],\n\t\tlabel: \"overview\",\n\t\tdescription: \"30-second overview\",\n\t\trender: () => OVERVIEW,\n\t},\n\t{\n\t\tname: \"workflows\",\n\t\taliases: [\"workflow\"],\n\t\tlabel: \"workflows\",\n\t\tdescription: \"Workflow primer\",\n\t\trender: () => WORKFLOWS,\n\t},\n\t{\n\t\tname: \"example\",\n\t\taliases: [\"examples\"],\n\t\tlabel: \"example\",\n\t\tdescription: \"Practical first workflow\",\n\t\trender: () => EXAMPLE,\n\t},\n\t{\n\t\tname: \"whats-new\",\n\t\taliases: [\"what's new\", \"whats new\", \"news\", \"updates\", \"changelog\"],\n\t\tlabel: \"what's new\",\n\t\tdescription: \"Recent release notes\",\n\t\trender: readLatestStableChangelog,\n\t},\n] as const satisfies readonly {\n\treadonly name: string;\n\treadonly aliases: readonly string[];\n\treadonly label: string;\n\treadonly description: string;\n\treadonly render: (cwd: string) => string;\n}[];\n\ntype AtomicGuideSection = (typeof GUIDE_SECTIONS)[number];\ntype AtomicGuideSectionName = AtomicGuideSection[\"name\"];\n\nexport type AtomicGuideHelpChoice = AtomicGuideSection[\"label\"];\n\nexport type AtomicGuideMode = \"help\" | AtomicGuideSectionName;\n\nexport const ATOMIC_GUIDE_HELP_CHOICES: readonly AtomicGuideHelpChoice[] = GUIDE_SECTIONS.map(\n\t(section) => section.label,\n);\n\nconst GUIDE_SECTIONS_BY_NAME = new Map<AtomicGuideSectionName, AtomicGuideSection>(\n\tGUIDE_SECTIONS.map((section) => [section.name, section]),\n);\nconst GUIDE_SECTIONS_BY_LABEL = new Map<string, AtomicGuideSection>(\n\tGUIDE_SECTIONS.map((section) => [section.label, section]),\n);\nconst GUIDE_SECTIONS_BY_INPUT = new Map<string, AtomicGuideSection>(\n\tGUIDE_SECTIONS.flatMap((section) =>\n\t\t[section.name, section.label, ...section.aliases].map((input) => [input, section] as const),\n\t),\n);\n\nexport function isAtomicGuideHelpChoice(choice: string): choice is AtomicGuideHelpChoice {\n\treturn GUIDE_SECTIONS_BY_LABEL.has(choice);\n}\n\nconst ATOMIC_GUIDE_TRAILING_PUNCTUATION = \"?!.,;:\";\n\nfunction stripTrailingAtomicGuidePunctuation(value: string): string {\n\tlet end = value.length;\n\twhile (end > 0 && ATOMIC_GUIDE_TRAILING_PUNCTUATION.includes(value.charAt(end - 1))) {\n\t\tend--;\n\t}\n\treturn value.slice(0, end);\n}\n\nfunction getGuideSectionForChoice(choice: string): AtomicGuideSection | undefined {\n\treturn GUIDE_SECTIONS_BY_LABEL.get(choice);\n}\n\nfunction getGuideSectionForMode(mode: AtomicGuideSectionName): AtomicGuideSection {\n\tconst section = GUIDE_SECTIONS_BY_NAME.get(mode);\n\tif (!section) throw new Error(`Unknown Atomic guide section: ${mode}`);\n\treturn section;\n}\n\nfunction getAtomicGuideHelpMenu(): string {\n\tconst sectionHelp = GUIDE_SECTIONS.map(\n\t\t(section) => `- \\`${section.label}\\` — run \\`/atomic ${section.label}\\``,\n\t).join(\"\\n\");\n\treturn `# Atomic\\n\\nSelect where to start:\\n\\n${sectionHelp}`;\n}\n\nexport function normalizeAtomicGuideMode(args: string): AtomicGuideMode {\n\tconst normalized = stripTrailingAtomicGuidePunctuation(args.trim().toLowerCase());\n\tif (!normalized) return \"help\";\n\n\treturn GUIDE_SECTIONS_BY_INPUT.get(normalized)?.name ?? \"help\";\n}\n\nexport function getAtomicGuideArgumentCompletions(prefix: string): AutocompleteItem[] | null {\n\tconst query = prefix.trim().toLowerCase();\n\tconst items = GUIDE_SECTIONS.map((section) => ({\n\t\tvalue: section.label,\n\t\tlabel: section.label,\n\t\tdescription: section.description,\n\t}));\n\tconst filtered = query\n\t\t? items.filter((item) => item.value.startsWith(query) || item.label.startsWith(query))\n\t\t: items;\n\treturn filtered.length > 0 ? filtered : null;\n}\n\nfunction readLatestStableChangelog(cwd: string): string {\n\tconst changelogPath = getChangelogPath();\n\tconst stableSections = parseChangelog(changelogPath)\n\t\t.filter((entry) => entry.prerelease === null)\n\t\t.slice(0, 3)\n\t\t.map((entry) => entry.content.trim())\n\t\t.filter(Boolean);\n\n\tif (stableSections.length === 0) {\n\t\treturn `# What's new\\n\\nNo stable release sections were found. Try \\`/changelog\\` for the interactive changelog viewer.\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n\t}\n\n\tconst relativePath = path.relative(cwd, changelogPath) || changelogPath;\n\treturn `# What's new\\n\\n${stableSections.join(\"\\n\\n\")}\\n\\nSource: \\`${relativePath}\\`\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n}\n\nexport function getAtomicGuideMessage(mode: AtomicGuideMode, cwd: string): string {\n\tif (mode === \"help\") return getAtomicGuideHelpMenu();\n\treturn getGuideSectionForMode(mode).render(cwd);\n}\n\nexport function atomicGuideModeForChoice(choice: AtomicGuideHelpChoice): AtomicGuideMode {\n\treturn getGuideSectionForChoice(choice)?.name ?? \"help\";\n}\n"]}
@@ -0,0 +1,22 @@
1
+ export declare const BUILTIN_PACKAGE_DIR_NAMES: readonly ["workflows", "subagents", "mcp", "web-access", "intercom"];
2
+ export type BuiltinPackageDirName = (typeof BUILTIN_PACKAGE_DIR_NAMES)[number];
3
+ /** Source-checkout extension entries. Discovery still loads these in a git tree. */
4
+ export declare const SOURCE_EXTENSION_ENTRIES: {
5
+ readonly workflows: "src/extension/index.ts";
6
+ readonly subagents: "src/extension/index.ts";
7
+ readonly mcp: "index.ts";
8
+ readonly "web-access": "index.ts";
9
+ readonly intercom: "index.ts";
10
+ };
11
+ /** Installed/npm extension entries after copy-builtin-packages prebundles them. */
12
+ export declare const INSTALLED_EXTENSION_ENTRIES: {
13
+ readonly workflows: "src/extension/index.bundle.mjs";
14
+ readonly subagents: "src/extension/index.bundle.mjs";
15
+ readonly mcp: "index.bundle.mjs";
16
+ readonly "web-access": "index.bundle.mjs";
17
+ readonly intercom: "index.bundle.mjs";
18
+ };
19
+ export declare const WORKFLOWS_SDK_BUNDLE_ENTRY = "src/index.bundle.mjs";
20
+ export declare const INTERCOM_BROKER_BUNDLE_ENTRY = "broker/broker.bundle.mjs";
21
+ export declare function requiredEntriesForBuiltin(dirName: BuiltinPackageDirName): readonly string[];
22
+ //# sourceMappingURL=builtin-install-layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtin-install-layout.d.ts","sourceRoot":"","sources":["../../src/core/builtin-install-layout.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,YAAI,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,CAAU,CAAC;AAE9G,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/E,oFAAoF;AACpF,eAAO,MAAM,wBAAwB;wBACzB,wBAAwB;wBACxB,wBAAwB;kBAC9B,UAAU;2BACD,UAAU;uBACd,UAAU;CACqC,CAAC;AAE3D,mFAAmF;AACnF,eAAO,MAAM,2BAA2B;wBAC5B,gCAAgC;wBAChC,gCAAgC;kBACtC,kBAAkB;2BACT,kBAAkB;uBACtB,kBAAkB;CAC6B,CAAC;AAE3D,eAAO,MAAM,0BAA0B,yBAAyB,CAAC;AACjE,eAAO,MAAM,4BAA4B,6BAA6B,CAAC;AAEvE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS,MAAM,EAAE,CAE3F"}
@@ -0,0 +1,23 @@
1
+ export const BUILTIN_PACKAGE_DIR_NAMES = ["workflows", "subagents", "mcp", "web-access", "intercom"];
2
+ /** Source-checkout extension entries. Discovery still loads these in a git tree. */
3
+ export const SOURCE_EXTENSION_ENTRIES = {
4
+ workflows: "src/extension/index.ts",
5
+ subagents: "src/extension/index.ts",
6
+ mcp: "index.ts",
7
+ "web-access": "index.ts",
8
+ intercom: "index.ts",
9
+ };
10
+ /** Installed/npm extension entries after copy-builtin-packages prebundles them. */
11
+ export const INSTALLED_EXTENSION_ENTRIES = {
12
+ workflows: "src/extension/index.bundle.mjs",
13
+ subagents: "src/extension/index.bundle.mjs",
14
+ mcp: "index.bundle.mjs",
15
+ "web-access": "index.bundle.mjs",
16
+ intercom: "index.bundle.mjs",
17
+ };
18
+ export const WORKFLOWS_SDK_BUNDLE_ENTRY = "src/index.bundle.mjs";
19
+ export const INTERCOM_BROKER_BUNDLE_ENTRY = "broker/broker.bundle.mjs";
20
+ export function requiredEntriesForBuiltin(dirName) {
21
+ return [INSTALLED_EXTENSION_ENTRIES[dirName], SOURCE_EXTENSION_ENTRIES[dirName]];
22
+ }
23
+ //# sourceMappingURL=builtin-install-layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtin-install-layout.js","sourceRoot":"","sources":["../../src/core/builtin-install-layout.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,CAAU,CAAC;AAI9G,oFAAoF;AACpF,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,SAAS,EAAE,wBAAwB;IACnC,SAAS,EAAE,wBAAwB;IACnC,GAAG,EAAE,UAAU;IACf,YAAY,EAAE,UAAU;IACxB,QAAQ,EAAE,UAAU;CACqC,CAAC;AAE3D,mFAAmF;AACnF,MAAM,CAAC,MAAM,2BAA2B,GAAG;IAC1C,SAAS,EAAE,gCAAgC;IAC3C,SAAS,EAAE,gCAAgC;IAC3C,GAAG,EAAE,kBAAkB;IACvB,YAAY,EAAE,kBAAkB;IAChC,QAAQ,EAAE,kBAAkB;CAC6B,CAAC;AAE3D,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AACjE,MAAM,CAAC,MAAM,4BAA4B,GAAG,0BAA0B,CAAC;AAEvE,MAAM,UAAU,yBAAyB,CAAC,OAA8B;IACvE,OAAO,CAAC,2BAA2B,CAAC,OAAO,CAAC,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;AAClF,CAAC","sourcesContent":["export const BUILTIN_PACKAGE_DIR_NAMES = [\"workflows\", \"subagents\", \"mcp\", \"web-access\", \"intercom\"] as const;\n\nexport type BuiltinPackageDirName = (typeof BUILTIN_PACKAGE_DIR_NAMES)[number];\n\n/** Source-checkout extension entries. Discovery still loads these in a git tree. */\nexport const SOURCE_EXTENSION_ENTRIES = {\n\tworkflows: \"src/extension/index.ts\",\n\tsubagents: \"src/extension/index.ts\",\n\tmcp: \"index.ts\",\n\t\"web-access\": \"index.ts\",\n\tintercom: \"index.ts\",\n} as const satisfies Record<BuiltinPackageDirName, string>;\n\n/** Installed/npm extension entries after copy-builtin-packages prebundles them. */\nexport const INSTALLED_EXTENSION_ENTRIES = {\n\tworkflows: \"src/extension/index.bundle.mjs\",\n\tsubagents: \"src/extension/index.bundle.mjs\",\n\tmcp: \"index.bundle.mjs\",\n\t\"web-access\": \"index.bundle.mjs\",\n\tintercom: \"index.bundle.mjs\",\n} as const satisfies Record<BuiltinPackageDirName, string>;\n\nexport const WORKFLOWS_SDK_BUNDLE_ENTRY = \"src/index.bundle.mjs\";\nexport const INTERCOM_BROKER_BUNDLE_ENTRY = \"broker/broker.bundle.mjs\";\n\nexport function requiredEntriesForBuiltin(dirName: BuiltinPackageDirName): readonly string[] {\n\treturn [INSTALLED_EXTENSION_ENTRIES[dirName], SOURCE_EXTENSION_ENTRIES[dirName]];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"builtin-packages.d.ts","sourceRoot":"","sources":["../../src/core/builtin-packages.ts"],"names":[],"mappings":"AA+HA;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAUjD"}
1
+ {"version":3,"file":"builtin-packages.d.ts","sourceRoot":"","sources":["../../src/core/builtin-packages.ts"],"names":[],"mappings":"AAsGA;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAUjD"}
@@ -2,42 +2,18 @@ import { existsSync, readFileSync } from "node:fs";
2
2
  import { join, resolve } from "node:path";
3
3
  import { getPackageDir } from "../config.js";
4
4
  import { moduleDirFromMetaUrl } from "../utils/split-launcher.js";
5
+ import { requiredEntriesForBuiltin } from "./builtin-install-layout.js";
5
6
  const WORKSPACE_BUILTINS = [
6
- {
7
- packageName: "@bastani/workflows",
8
- workspaceDirName: "workflows",
9
- distDirName: "workflows",
10
- requiredEntry: join("src", "extension", "index.ts"),
11
- },
12
- {
13
- packageName: "@bastani/subagents",
14
- workspaceDirName: "subagents",
15
- distDirName: "subagents",
16
- requiredEntry: join("src", "extension", "index.ts"),
17
- },
18
- {
19
- packageName: "@bastani/mcp",
20
- workspaceDirName: "mcp",
21
- distDirName: "mcp",
22
- requiredEntry: "index.ts",
23
- },
24
- {
25
- packageName: "@bastani/web-access",
26
- workspaceDirName: "web-access",
27
- distDirName: "web-access",
28
- requiredEntry: "index.ts",
29
- },
30
- {
31
- packageName: "@bastani/intercom",
32
- workspaceDirName: "intercom",
33
- distDirName: "intercom",
34
- requiredEntry: "index.ts",
35
- },
7
+ { packageName: "@bastani/workflows", workspaceDirName: "workflows", distDirName: "workflows" },
8
+ { packageName: "@bastani/subagents", workspaceDirName: "subagents", distDirName: "subagents" },
9
+ { packageName: "@bastani/mcp", workspaceDirName: "mcp", distDirName: "mcp" },
10
+ { packageName: "@bastani/web-access", workspaceDirName: "web-access", distDirName: "web-access" },
11
+ { packageName: "@bastani/intercom", workspaceDirName: "intercom", distDirName: "intercom" },
36
12
  ];
37
13
  const BUILTIN_PACKAGES = WORKSPACE_BUILTINS.map((spec) => ({
38
14
  packageName: spec.packageName,
39
15
  distDirName: spec.distDirName,
40
- requiredEntry: spec.requiredEntry,
16
+ requiredEntries: requiredEntriesForBuiltin(spec.distDirName),
41
17
  sourceCandidates: ({ here, packageDir, isSourceCheckout }) => isSourceCheckout
42
18
  ? [join(packageDir, "..", spec.workspaceDirName), join(here, "..", "..", "..", spec.workspaceDirName)]
43
19
  : [],
@@ -52,7 +28,7 @@ function readPackageName(packageJsonPath) {
52
28
  }
53
29
  }
54
30
  function isPackageDir(dir, descriptor) {
55
- return (existsSync(join(dir, descriptor.requiredEntry)) &&
31
+ return (descriptor.requiredEntries.some((entry) => existsSync(join(dir, entry))) &&
56
32
  readPackageName(join(dir, "package.json")) === descriptor.packageName);
57
33
  }
58
34
  function firstExistingPackageDir(candidates, descriptor) {