@caupulican/pi-adaptative 0.81.40 → 0.81.41

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 (406) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +1 -0
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +1 -0
  6. package/dist/cli/args.d.ts +2 -0
  7. package/dist/cli/args.d.ts.map +1 -1
  8. package/dist/cli/args.js +22 -1
  9. package/dist/cli/args.js.map +1 -1
  10. package/dist/core/agent-paths.d.ts +6 -0
  11. package/dist/core/agent-paths.d.ts.map +1 -1
  12. package/dist/core/agent-paths.js +12 -0
  13. package/dist/core/agent-paths.js.map +1 -1
  14. package/dist/core/agent-session-contracts.d.ts +293 -0
  15. package/dist/core/agent-session-contracts.d.ts.map +1 -0
  16. package/dist/core/agent-session-contracts.js +26 -0
  17. package/dist/core/agent-session-contracts.js.map +1 -0
  18. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  19. package/dist/core/agent-session-runtime.js +3 -0
  20. package/dist/core/agent-session-runtime.js.map +1 -1
  21. package/dist/core/agent-session.d.ts +26 -405
  22. package/dist/core/agent-session.d.ts.map +1 -1
  23. package/dist/core/agent-session.js +86 -307
  24. package/dist/core/agent-session.js.map +1 -1
  25. package/dist/core/auth-storage.d.ts.map +1 -1
  26. package/dist/core/auth-storage.js +3 -1
  27. package/dist/core/auth-storage.js.map +1 -1
  28. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  29. package/dist/core/autonomy/lane-tool-surface.js +2 -1
  30. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  31. package/dist/core/background-lane-controller.d.ts +3 -1
  32. package/dist/core/background-lane-controller.d.ts.map +1 -1
  33. package/dist/core/background-lane-controller.js +1 -0
  34. package/dist/core/background-lane-controller.js.map +1 -1
  35. package/dist/core/bedrock-sso-login.d.ts +16 -0
  36. package/dist/core/bedrock-sso-login.d.ts.map +1 -0
  37. package/dist/core/bedrock-sso-login.js +98 -0
  38. package/dist/core/bedrock-sso-login.js.map +1 -0
  39. package/dist/core/compaction-controller.d.ts.map +1 -1
  40. package/dist/core/compaction-controller.js +1 -1
  41. package/dist/core/compaction-controller.js.map +1 -1
  42. package/dist/core/compaction-support.d.ts +3 -8
  43. package/dist/core/compaction-support.d.ts.map +1 -1
  44. package/dist/core/compaction-support.js +3 -3
  45. package/dist/core/compaction-support.js.map +1 -1
  46. package/dist/core/context-pipeline.d.ts +1 -1
  47. package/dist/core/context-pipeline.d.ts.map +1 -1
  48. package/dist/core/context-pipeline.js +7 -33
  49. package/dist/core/context-pipeline.js.map +1 -1
  50. package/dist/core/cost/cost-summary.d.ts.map +1 -1
  51. package/dist/core/cost/cost-summary.js +5 -3
  52. package/dist/core/cost/cost-summary.js.map +1 -1
  53. package/dist/core/cost/daily-usage.d.ts.map +1 -1
  54. package/dist/core/cost/daily-usage.js +4 -5
  55. package/dist/core/cost/daily-usage.js.map +1 -1
  56. package/dist/core/default-tool-surface.d.ts.map +1 -1
  57. package/dist/core/default-tool-surface.js +1 -0
  58. package/dist/core/default-tool-surface.js.map +1 -1
  59. package/dist/core/extension-import-authority.d.ts +6 -0
  60. package/dist/core/extension-import-authority.d.ts.map +1 -0
  61. package/dist/core/extension-import-authority.js +10 -0
  62. package/dist/core/extension-import-authority.js.map +1 -0
  63. package/dist/core/extensions/loader.d.ts.map +1 -1
  64. package/dist/core/extensions/loader.js +2 -3
  65. package/dist/core/extensions/loader.js.map +1 -1
  66. package/dist/core/extensions/runner.d.ts +3 -0
  67. package/dist/core/extensions/runner.d.ts.map +1 -1
  68. package/dist/core/extensions/runner.js +14 -5
  69. package/dist/core/extensions/runner.js.map +1 -1
  70. package/dist/core/extensions/stale-context.d.ts +2 -0
  71. package/dist/core/extensions/stale-context.d.ts.map +1 -0
  72. package/dist/core/extensions/stale-context.js +2 -0
  73. package/dist/core/extensions/stale-context.js.map +1 -0
  74. package/dist/core/extensions/types.d.ts +8 -0
  75. package/dist/core/extensions/types.d.ts.map +1 -1
  76. package/dist/core/extensions/types.js.map +1 -1
  77. package/dist/core/foreground-recovery-controller.d.ts +1 -0
  78. package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
  79. package/dist/core/foreground-recovery-controller.js +13 -13
  80. package/dist/core/foreground-recovery-controller.js.map +1 -1
  81. package/dist/core/goal-loop-controller.d.ts +14 -9
  82. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  83. package/dist/core/goal-loop-controller.js +47 -75
  84. package/dist/core/goal-loop-controller.js.map +1 -1
  85. package/dist/core/goals/compact-goal-context.d.ts +11 -0
  86. package/dist/core/goals/compact-goal-context.d.ts.map +1 -0
  87. package/dist/core/goals/compact-goal-context.js +59 -0
  88. package/dist/core/goals/compact-goal-context.js.map +1 -0
  89. package/dist/core/goals/goal-acceptance.d.ts.map +1 -1
  90. package/dist/core/goals/goal-acceptance.js +2 -0
  91. package/dist/core/goals/goal-acceptance.js.map +1 -1
  92. package/dist/core/goals/goal-auto-continue-controller.d.ts +2 -1
  93. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
  94. package/dist/core/goals/goal-auto-continue-controller.js +5 -8
  95. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
  96. package/dist/core/goals/goal-continuation-controller.d.ts +2 -2
  97. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  98. package/dist/core/goals/goal-continuation-controller.js +42 -11
  99. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  100. package/dist/core/goals/goal-continuation-defaults.d.ts +4 -29
  101. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  102. package/dist/core/goals/goal-continuation-defaults.js +4 -32
  103. package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
  104. package/dist/core/goals/goal-continuation-prompt.d.ts +8 -18
  105. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  106. package/dist/core/goals/goal-continuation-prompt.js +9 -179
  107. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  108. package/dist/core/goals/goal-lifecycle.d.ts +35 -12
  109. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
  110. package/dist/core/goals/goal-lifecycle.js +98 -13
  111. package/dist/core/goals/goal-lifecycle.js.map +1 -1
  112. package/dist/core/goals/goal-record.d.ts +17 -0
  113. package/dist/core/goals/goal-record.d.ts.map +1 -0
  114. package/dist/core/goals/goal-record.js +31 -0
  115. package/dist/core/goals/goal-record.js.map +1 -0
  116. package/dist/core/goals/goal-session-controller.d.ts +42 -0
  117. package/dist/core/goals/goal-session-controller.d.ts.map +1 -0
  118. package/dist/core/goals/goal-session-controller.js +128 -0
  119. package/dist/core/goals/goal-session-controller.js.map +1 -0
  120. package/dist/core/goals/goal-state.d.ts +45 -25
  121. package/dist/core/goals/goal-state.d.ts.map +1 -1
  122. package/dist/core/goals/goal-state.js +85 -15
  123. package/dist/core/goals/goal-state.js.map +1 -1
  124. package/dist/core/goals/goal-tool-core.d.ts +1 -4
  125. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  126. package/dist/core/goals/goal-tool-core.js +49 -34
  127. package/dist/core/goals/goal-tool-core.js.map +1 -1
  128. package/dist/core/goals/session-goal-state.d.ts +18 -8
  129. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  130. package/dist/core/goals/session-goal-state.js +134 -11
  131. package/dist/core/goals/session-goal-state.js.map +1 -1
  132. package/dist/core/human-input-controller.d.ts +47 -0
  133. package/dist/core/human-input-controller.d.ts.map +1 -0
  134. package/dist/core/human-input-controller.js +181 -0
  135. package/dist/core/human-input-controller.js.map +1 -0
  136. package/dist/core/local-runtime-controller.d.ts +1 -1
  137. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  138. package/dist/core/local-runtime-controller.js.map +1 -1
  139. package/dist/core/model-capability.d.ts +0 -19
  140. package/dist/core/model-capability.d.ts.map +1 -1
  141. package/dist/core/model-capability.js +0 -19
  142. package/dist/core/model-capability.js.map +1 -1
  143. package/dist/core/model-registry.d.ts +6 -1
  144. package/dist/core/model-registry.d.ts.map +1 -1
  145. package/dist/core/model-registry.js +13 -5
  146. package/dist/core/model-registry.js.map +1 -1
  147. package/dist/core/model-resolver.d.ts +16 -1
  148. package/dist/core/model-resolver.d.ts.map +1 -1
  149. package/dist/core/model-resolver.js +32 -16
  150. package/dist/core/model-resolver.js.map +1 -1
  151. package/dist/core/model-router-controller.d.ts +1 -1
  152. package/dist/core/model-router-controller.d.ts.map +1 -1
  153. package/dist/core/model-router-controller.js.map +1 -1
  154. package/dist/core/model-selection-controller.d.ts +1 -1
  155. package/dist/core/model-selection-controller.d.ts.map +1 -1
  156. package/dist/core/model-selection-controller.js.map +1 -1
  157. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  158. package/dist/core/orchestration/delegation-ledger.js +3 -0
  159. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  160. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
  161. package/dist/core/orchestration/work-state-projection.js +1 -1
  162. package/dist/core/orchestration/work-state-projection.js.map +1 -1
  163. package/dist/core/package-manager.d.ts.map +1 -1
  164. package/dist/core/package-manager.js +20 -3
  165. package/dist/core/package-manager.js.map +1 -1
  166. package/dist/core/profile-filter-controller.d.ts +8 -1
  167. package/dist/core/profile-filter-controller.d.ts.map +1 -1
  168. package/dist/core/profile-filter-controller.js +23 -5
  169. package/dist/core/profile-filter-controller.js.map +1 -1
  170. package/dist/core/prompt-templates.d.ts +1 -0
  171. package/dist/core/prompt-templates.d.ts.map +1 -1
  172. package/dist/core/prompt-templates.js +18 -29
  173. package/dist/core/prompt-templates.js.map +1 -1
  174. package/dist/core/reflection-controller.d.ts +1 -1
  175. package/dist/core/reflection-controller.d.ts.map +1 -1
  176. package/dist/core/reflection-controller.js +3 -1
  177. package/dist/core/reflection-controller.js.map +1 -1
  178. package/dist/core/request-auth.d.ts +7 -0
  179. package/dist/core/request-auth.d.ts.map +1 -0
  180. package/dist/core/request-auth.js +8 -0
  181. package/dist/core/request-auth.js.map +1 -0
  182. package/dist/core/resource-loader.d.ts.map +1 -1
  183. package/dist/core/resource-loader.js +16 -6
  184. package/dist/core/resource-loader.js.map +1 -1
  185. package/dist/core/risk-classifier.d.ts.map +1 -1
  186. package/dist/core/risk-classifier.js +8 -0
  187. package/dist/core/risk-classifier.js.map +1 -1
  188. package/dist/core/runtime-builder.d.ts +15 -3
  189. package/dist/core/runtime-builder.d.ts.map +1 -1
  190. package/dist/core/runtime-builder.js +132 -79
  191. package/dist/core/runtime-builder.js.map +1 -1
  192. package/dist/core/sdk.d.ts.map +1 -1
  193. package/dist/core/sdk.js +7 -1
  194. package/dist/core/sdk.js.map +1 -1
  195. package/dist/core/secrets/credential-exposure-guard.d.ts +9 -0
  196. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -0
  197. package/dist/core/secrets/credential-exposure-guard.js +241 -0
  198. package/dist/core/secrets/credential-exposure-guard.js.map +1 -0
  199. package/dist/core/secrets/secret-dotenv.d.ts +27 -0
  200. package/dist/core/secrets/secret-dotenv.d.ts.map +1 -0
  201. package/dist/core/secrets/secret-dotenv.js +183 -0
  202. package/dist/core/secrets/secret-dotenv.js.map +1 -0
  203. package/dist/core/secrets/secret-vault-format.d.ts +112 -0
  204. package/dist/core/secrets/secret-vault-format.d.ts.map +1 -0
  205. package/dist/core/secrets/secret-vault-format.js +397 -0
  206. package/dist/core/secrets/secret-vault-format.js.map +1 -0
  207. package/dist/core/secrets/secret-vault.d.ts +72 -0
  208. package/dist/core/secrets/secret-vault.d.ts.map +1 -0
  209. package/dist/core/secrets/secret-vault.js +671 -0
  210. package/dist/core/secrets/secret-vault.js.map +1 -0
  211. package/dist/core/session-analytics.d.ts +4 -23
  212. package/dist/core/session-analytics.d.ts.map +1 -1
  213. package/dist/core/session-analytics.js +39 -69
  214. package/dist/core/session-analytics.js.map +1 -1
  215. package/dist/core/session-role.d.ts +5 -0
  216. package/dist/core/session-role.d.ts.map +1 -1
  217. package/dist/core/session-role.js +14 -1
  218. package/dist/core/session-role.js.map +1 -1
  219. package/dist/core/session-tree-navigator.d.ts +4 -6
  220. package/dist/core/session-tree-navigator.d.ts.map +1 -1
  221. package/dist/core/session-tree-navigator.js +4 -1
  222. package/dist/core/session-tree-navigator.js.map +1 -1
  223. package/dist/core/settings-manager.d.ts +1 -1
  224. package/dist/core/settings-manager.d.ts.map +1 -1
  225. package/dist/core/settings-manager.js +1 -1
  226. package/dist/core/settings-manager.js.map +1 -1
  227. package/dist/core/slash-commands.d.ts.map +1 -1
  228. package/dist/core/slash-commands.js +2 -2
  229. package/dist/core/slash-commands.js.map +1 -1
  230. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  231. package/dist/core/tool-capability-policy.js +1 -0
  232. package/dist/core/tool-capability-policy.js.map +1 -1
  233. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  234. package/dist/core/tool-gate-controller.js +8 -2
  235. package/dist/core/tool-gate-controller.js.map +1 -1
  236. package/dist/core/tool-protocol-controller.d.ts +2 -4
  237. package/dist/core/tool-protocol-controller.d.ts.map +1 -1
  238. package/dist/core/tool-protocol-controller.js.map +1 -1
  239. package/dist/core/tool-recovery-stats.d.ts +21 -1
  240. package/dist/core/tool-recovery-stats.d.ts.map +1 -1
  241. package/dist/core/tool-recovery-stats.js.map +1 -1
  242. package/dist/core/tools/bash.d.ts +5 -0
  243. package/dist/core/tools/bash.d.ts.map +1 -1
  244. package/dist/core/tools/bash.js +59 -5
  245. package/dist/core/tools/bash.js.map +1 -1
  246. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  247. package/dist/core/tools/delegate-status.js +6 -7
  248. package/dist/core/tools/delegate-status.js.map +1 -1
  249. package/dist/core/tools/delegate.d.ts.map +1 -1
  250. package/dist/core/tools/delegate.js +6 -8
  251. package/dist/core/tools/delegate.js.map +1 -1
  252. package/dist/core/tools/git-filter.d.ts +1 -8
  253. package/dist/core/tools/git-filter.d.ts.map +1 -1
  254. package/dist/core/tools/git-filter.js +2 -63
  255. package/dist/core/tools/git-filter.js.map +1 -1
  256. package/dist/core/tools/goal.d.ts +5 -3
  257. package/dist/core/tools/goal.d.ts.map +1 -1
  258. package/dist/core/tools/goal.js +97 -19
  259. package/dist/core/tools/goal.js.map +1 -1
  260. package/dist/core/tools/index.d.ts +1 -0
  261. package/dist/core/tools/index.d.ts.map +1 -1
  262. package/dist/core/tools/index.js +1 -0
  263. package/dist/core/tools/index.js.map +1 -1
  264. package/dist/core/tools/orchestration-panel.d.ts +1 -4
  265. package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
  266. package/dist/core/tools/orchestration-panel.js +0 -44
  267. package/dist/core/tools/orchestration-panel.js.map +1 -1
  268. package/dist/core/tools/output-accumulator.d.ts +11 -0
  269. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  270. package/dist/core/tools/output-accumulator.js +36 -3
  271. package/dist/core/tools/output-accumulator.js.map +1 -1
  272. package/dist/core/tools/python.d.ts +2 -0
  273. package/dist/core/tools/python.d.ts.map +1 -1
  274. package/dist/core/tools/python.js +3 -1
  275. package/dist/core/tools/python.js.map +1 -1
  276. package/dist/core/tools/read.d.ts.map +1 -1
  277. package/dist/core/tools/read.js +1 -1
  278. package/dist/core/tools/read.js.map +1 -1
  279. package/dist/core/tools/search-command-guard.d.ts +14 -0
  280. package/dist/core/tools/search-command-guard.d.ts.map +1 -0
  281. package/dist/core/tools/search-command-guard.js +333 -0
  282. package/dist/core/tools/search-command-guard.js.map +1 -0
  283. package/dist/core/tools/secret-store.d.ts +38 -0
  284. package/dist/core/tools/secret-store.d.ts.map +1 -0
  285. package/dist/core/tools/secret-store.js +412 -0
  286. package/dist/core/tools/secret-store.js.map +1 -0
  287. package/dist/core/tools/shell-command-parser.d.ts +16 -0
  288. package/dist/core/tools/shell-command-parser.d.ts.map +1 -0
  289. package/dist/core/tools/shell-command-parser.js +113 -0
  290. package/dist/core/tools/shell-command-parser.js.map +1 -0
  291. package/dist/core/tools/task-steps.d.ts.map +1 -1
  292. package/dist/core/tools/task-steps.js +4 -7
  293. package/dist/core/tools/task-steps.js.map +1 -1
  294. package/dist/core/util/atomic-file.d.ts +6 -2
  295. package/dist/core/util/atomic-file.d.ts.map +1 -1
  296. package/dist/core/util/atomic-file.js +4 -4
  297. package/dist/core/util/atomic-file.js.map +1 -1
  298. package/dist/index.d.ts +3 -2
  299. package/dist/index.d.ts.map +1 -1
  300. package/dist/index.js +2 -1
  301. package/dist/index.js.map +1 -1
  302. package/dist/main.d.ts.map +1 -1
  303. package/dist/main.js +25 -11
  304. package/dist/main.js.map +1 -1
  305. package/dist/modes/interactive/auth-dialogs-controller.d.ts +4 -0
  306. package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
  307. package/dist/modes/interactive/auth-dialogs-controller.js +60 -1
  308. package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
  309. package/dist/modes/interactive/components/activity-lane.d.ts +55 -0
  310. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -0
  311. package/dist/modes/interactive/components/activity-lane.js +304 -0
  312. package/dist/modes/interactive/components/activity-lane.js.map +1 -0
  313. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  314. package/dist/modes/interactive/components/assistant-message.js +19 -10
  315. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  316. package/dist/modes/interactive/components/expandable-text.d.ts +12 -0
  317. package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -0
  318. package/dist/modes/interactive/components/expandable-text.js +17 -0
  319. package/dist/modes/interactive/components/expandable-text.js.map +1 -0
  320. package/dist/modes/interactive/components/extension-editor.d.ts +15 -1
  321. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  322. package/dist/modes/interactive/components/extension-editor.js +30 -21
  323. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  324. package/dist/modes/interactive/components/extension-input.d.ts +1 -0
  325. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  326. package/dist/modes/interactive/components/extension-input.js +6 -1
  327. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  328. package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
  329. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  330. package/dist/modes/interactive/components/scoped-models-selector.js +23 -14
  331. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  332. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  333. package/dist/modes/interactive/components/settings-selector.js +4 -4
  334. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  335. package/dist/modes/interactive/components/tool-execution.d.ts +19 -11
  336. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  337. package/dist/modes/interactive/components/tool-execution.js +53 -20
  338. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  339. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
  340. package/dist/modes/interactive/components/tool-group.js +3 -0
  341. package/dist/modes/interactive/components/tool-group.js.map +1 -1
  342. package/dist/modes/interactive/components/usage-action-selector.d.ts +16 -0
  343. package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -0
  344. package/dist/modes/interactive/components/usage-action-selector.js +46 -0
  345. package/dist/modes/interactive/components/usage-action-selector.js.map +1 -0
  346. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  347. package/dist/modes/interactive/extension-ui-host.js +1 -0
  348. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  349. package/dist/modes/interactive/external-editor.d.ts +15 -0
  350. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  351. package/dist/modes/interactive/external-editor.js +27 -19
  352. package/dist/modes/interactive/external-editor.js.map +1 -1
  353. package/dist/modes/interactive/history-reload-math.d.ts +6 -2
  354. package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
  355. package/dist/modes/interactive/history-reload-math.js +10 -5
  356. package/dist/modes/interactive/history-reload-math.js.map +1 -1
  357. package/dist/modes/interactive/interactive-event-controller.d.ts +74 -0
  358. package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -0
  359. package/dist/modes/interactive/interactive-event-controller.js +328 -0
  360. package/dist/modes/interactive/interactive-event-controller.js.map +1 -0
  361. package/dist/modes/interactive/interactive-mode.d.ts +20 -25
  362. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  363. package/dist/modes/interactive/interactive-mode.js +196 -608
  364. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  365. package/dist/modes/interactive/loaded-resources-view.d.ts +20 -0
  366. package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -0
  367. package/dist/modes/interactive/loaded-resources-view.js +147 -0
  368. package/dist/modes/interactive/loaded-resources-view.js.map +1 -0
  369. package/dist/modes/interactive/resource-display.d.ts.map +1 -1
  370. package/dist/modes/interactive/resource-display.js +8 -2
  371. package/dist/modes/interactive/resource-display.js.map +1 -1
  372. package/dist/modes/interactive/resource-shell-commands.d.ts +1 -5
  373. package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
  374. package/dist/modes/interactive/resource-shell-commands.js +0 -5
  375. package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
  376. package/dist/modes/interactive/session-flow-commands.d.ts +10 -6
  377. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  378. package/dist/modes/interactive/session-flow-commands.js +123 -70
  379. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  380. package/dist/modes/interactive/usage-commands.d.ts +34 -0
  381. package/dist/modes/interactive/usage-commands.d.ts.map +1 -0
  382. package/dist/modes/interactive/usage-commands.js +225 -0
  383. package/dist/modes/interactive/usage-commands.js.map +1 -0
  384. package/dist/utils/shell.d.ts.map +1 -1
  385. package/dist/utils/shell.js +5 -3
  386. package/dist/utils/shell.js.map +1 -1
  387. package/dist/utils/version-check.d.ts.map +1 -1
  388. package/dist/utils/version-check.js +3 -1
  389. package/dist/utils/version-check.js.map +1 -1
  390. package/docs/UI_POLISH_ORCHESTRATION.md +25 -31
  391. package/docs/UI_QUALITY_ORCHESTRATION.md +22 -24
  392. package/docs/providers.md +9 -1
  393. package/docs/ui-reference/README.md +6 -6
  394. package/docs/ui-reference/orchestration-after.txt +14 -7
  395. package/docs/ui-reference/orchestration-before.txt +12 -6
  396. package/docs/ui-reference/orchestration-reference.txt +15 -5
  397. package/docs/usage.md +9 -1
  398. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  399. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  400. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  401. package/examples/extensions/sandbox/package-lock.json +2 -2
  402. package/examples/extensions/sandbox/package.json +1 -1
  403. package/examples/extensions/with-deps/package-lock.json +2 -2
  404. package/examples/extensions/with-deps/package.json +1 -1
  405. package/npm-shrinkwrap.json +13 -13
  406. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import { createHash, randomUUID } from "node:crypto";
1
+ import { randomUUID } from "node:crypto";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { basename, dirname } from "node:path";
4
4
  import { compactToolResultDetailsForRetention, createCustomMessage, DEFAULT_STREAM_IDLE, withStreamIdleWatchdog, } from "@caupulican/pi-agent-core";
@@ -21,12 +21,11 @@ import { appendWorkerClaimSnapshot, getWorkerClaimSnapshots } from "./delegation
21
21
  import { FailureCorpusRecorder } from "./failure-corpus.js";
22
22
  import { ForegroundRecoveryController } from "./foreground-recovery-controller.js";
23
23
  import { GatewayRegistry } from "./gateways/channel-provider.js";
24
- import { GoalLoopController } from "./goal-loop-controller.js";
25
- import { buildGoalRuntimeSnapshot, } from "./goals/goal-runtime-snapshot.js";
26
- import { applyGoalEvent } from "./goals/goal-state.js";
27
- import { appendGoalStateSnapshot, getLatestGoalStateSnapshot } from "./goals/session-goal-state.js";
24
+ import { injectCompactGoalContext } from "./goals/compact-goal-context.js";
25
+ import { GoalSessionController } from "./goals/goal-session-controller.js";
28
26
  import { constrainStreamIdleToHttpTimeout } from "./http-dispatcher.js";
29
- import { beginHumanInputRequest, createHumanInputRequest, formatHumanInputAnswerText, getLatestHumanInputSnapshots, getResumableHumanInputSnapshot, getWorkerHumanInputsRequiringDelivery, HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE, resolveHumanInput, } from "./human-input.js";
27
+ import { getWorkerHumanInputsRequiringDelivery } from "./human-input.js";
28
+ import { HumanInputController } from "./human-input-controller.js";
30
29
  import { appendLearningDecisionSnapshot, getLearningDecisionSnapshots } from "./learning/session-learning-decision.js";
31
30
  import { isPromotedFrontmatter, SkillCurator } from "./learning/skill-curator.js";
32
31
  import { LocalRuntimeController } from "./local-runtime-controller.js";
@@ -93,63 +92,8 @@ function tagRawness(wrapped, innerIsRawStreamSimple) {
93
92
  Object.defineProperty(wrapped, RAW_STREAM_MARKER, { value: innerIsRawStreamSimple });
94
93
  return wrapped;
95
94
  }
96
- /**
97
- * Parse a skill block from message text.
98
- * Returns null if the text doesn't contain a skill block.
99
- */
100
- export function parseSkillBlock(text) {
101
- const match = text.match(/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/);
102
- if (!match)
103
- return null;
104
- return {
105
- name: match[1],
106
- location: match[2],
107
- content: match[3],
108
- userMessage: match[4]?.trim() || undefined,
109
- };
110
- }
111
- /** customType for spawned-usage roll-up entries (Cost Aggregation, Model A). */
112
- export const SPAWNED_USAGE_CUSTOM_TYPE = "spawned_usage";
113
- /**
114
- * customType for a persisted runaway-loop-backstop entry: the agent loop stopped a turn stuck
115
- * repeating one identical tool-call signature. This is the session-log/telemetry sink for
116
- * {@link Agent.onRunawayStop} — see `_installAgentToolHooks`.
117
- */
118
- export const RUNAWAY_STOP_CUSTOM_TYPE = "runaway_stop";
119
- /**
120
- * customType for a persisted tool-validation-escalation entry: the agent loop bounced the same
121
- * tool-call validation failure enough times to escalate. This is the session-log/telemetry sink for
122
- * {@link Agent.onToolValidationEscalation} — see `_installAgentToolHooks`.
123
- */
124
- export const TOOL_VALIDATION_ESCALATION_CUSTOM_TYPE = "tool_validation_escalation";
125
- /** Fallback {@link IsolatedCompletionOptions.laneKind} for callers that do not tag their lane. */
126
- export const DEFAULT_ISOLATED_LANE_KIND = "isolated";
127
- /**
128
- * Derive a STABLE synthetic cache-affinity key for an isolated completion lane. Isolated calls
129
- * deliberately never carry the real session id (see reflection-controller.ts's isolation invariants —
130
- * an isolated call must not entangle with the main session), which today also means every isolated
131
- * call looks like a brand-new, uncorrelated session to providers with session-affinity headers /
132
- * `prompt_cache_key` (anthropic.ts's `x-session-affinity`, openai-responses.ts /
133
- * openai-completions.ts's `prompt_cache_key`), defeating their cache routing.
134
- *
135
- * This key is deterministic per `(laneKind, model, systemPrompt)` — the SAME lane calling the SAME
136
- * model with the SAME (static) system prompt always gets the SAME key, so repeat calls route to the
137
- * same cache-warm backend — while remaining fully synthetic: it is a salted hash, namespaced with a
138
- * `lane:` prefix, and never derived from or equal to the real session id.
139
- */
140
- export function computeLaneAffinityKey(laneKind, model, systemPrompt) {
141
- const modelKey = model ? `${model.provider}/${model.id}` : "unknown-model";
142
- // NUL-separated fields: laneKind/modelKey are drawn from small caller-controlled vocabularies
143
- // that never contain a raw NUL, so this cannot field-collide the way a plain colon/space join could.
144
- const digest = createHash("sha256")
145
- .update(["pi-lane-affinity-v1", laneKind, modelKey, systemPrompt].join("\u0000"))
146
- .digest("hex")
147
- .slice(0, 32);
148
- return `lane:${laneKind}:${digest}`;
149
- }
150
- // ============================================================================
151
- // Constants
152
- // ============================================================================
95
+ export * from "./agent-session-contracts.js";
96
+ import { RUNAWAY_STOP_CUSTOM_TYPE, TOOL_VALIDATION_ESCALATION_CUSTOM_TYPE } from "./agent-session-contracts.js";
153
97
  // ============================================================================
154
98
  // AgentSession Class
155
99
  // ============================================================================
@@ -168,9 +112,6 @@ export class AgentSession {
168
112
  _queuedExtensionCommands = [];
169
113
  _pendingNextTurnMessages = [];
170
114
  _streamingPromptSubmissionTail = Promise.resolve();
171
- /** Serializes owner-input overlays so concurrent worker terminals cannot replace each other. */
172
- _humanInputTail = Promise.resolve();
173
- _activeHumanInputRequestIds = new Set();
174
115
  /**
175
116
  * The last tool set requested via setActiveToolsByName BEFORE model-capability filtering, so
176
117
  * switching from a small-window model back to a large one restores the full requested set.
@@ -207,6 +148,7 @@ export class AgentSession {
207
148
  * background-lane-controller.ts); owns the lane timers/guards, the last research-lane skip
208
149
  * reason, the live LaneTracker, and the in-flight research/worker abort controllers. */
209
150
  _backgroundLanes;
151
+ _humanInput;
210
152
  /** Plug-and-play memory subsystem (see memory-controller.ts); owns the OKF retrieval provider, the
211
153
  * latest retrieval/prompt-inclusion reports, the reload-safe MemoryManager, the recall
212
154
  * effectiveness tracker, and the extension-contributed pending providers. */
@@ -253,9 +195,8 @@ export class AgentSession {
253
195
  /** Native reflection engine + learning-apply/rollback path (see reflection-controller.ts); owns no
254
196
  * session state, applies durable writes through the bundled memory tool and the session log. */
255
197
  _reflection;
256
- /** Bounded goal auto-continuation loop (see goal-loop-controller.ts); reads goal state fresh
257
- * each pass and re-enters the session's own prompt path. */
258
- _goalContinuation;
198
+ /** Durable goal lifecycle, accounting, and raw continuation loop. */
199
+ _goals;
259
200
  _isChildSession;
260
201
  _baseToolsOverride;
261
202
  _sessionStartEvent;
@@ -401,6 +342,30 @@ export class AgentSession {
401
342
  getLearningAuditRecords: () => this.getLearningAuditRecords(),
402
343
  });
403
344
  this._modelRegistry = config.modelRegistry;
345
+ this._humanInput = new HumanInputController({
346
+ getSessionManager: () => this.sessionManager,
347
+ getUIContext: () => this._extensionUIContext,
348
+ getExtensionMode: () => this._extensionMode,
349
+ waitForIdle: () => this.agent.waitForIdle(),
350
+ isDisposed: () => this._disposed,
351
+ isStreaming: () => this.isStreaming,
352
+ getModel: () => this.model,
353
+ getArtifactStore: () => this._getToolArtifactStore(),
354
+ getImageStore: () => this._getSessionImageStore(),
355
+ runAgentPrompt: (messages) => this._runAgentPrompt(messages),
356
+ sendCustomMessage: (message, options) => this.sendCustomMessage(message, options),
357
+ emitWarning: (message) => this._emit({ type: "warning", message }),
358
+ });
359
+ this._goals = new GoalSessionController({
360
+ getSessionManager: () => this.sessionManager,
361
+ getModelProvider: () => this.model?.provider,
362
+ getLaneRecords: () => this._backgroundLanes.getLaneRecords(),
363
+ getTaskRuntimeSnapshot: () => this._backgroundLanes.getTaskRuntimeSnapshot(),
364
+ synchronizeGoalState: (state) => this._backgroundLanes.synchronizeGoalState(state),
365
+ scheduleGoalAutoContinueFromIdle: () => this._backgroundLanes.scheduleGoalAutoContinueFromIdle(),
366
+ prompt: (text, options) => this.prompt(text, options),
367
+ emitWarning: (message) => this._emit({ type: "warning", message }),
368
+ });
404
369
  this._backgroundLanes = new BackgroundLaneController({
405
370
  isDisposed: () => this._disposed,
406
371
  isChildSession: () => this._isChildSession,
@@ -422,17 +387,18 @@ export class AgentSession {
422
387
  emitAutonomyTelemetry: (event) => this._emitAutonomyTelemetry(event),
423
388
  getGoalStateSnapshot: () => this.getGoalStateSnapshot(),
424
389
  getGoalRuntimeSnapshot: (settings) => this.getGoalRuntimeSnapshot(settings),
390
+ markGoalToolUnavailable: () => this._goals.markToolUnavailable(),
425
391
  getEvidenceBundleSnapshot: () => this.getEvidenceBundleSnapshot(),
426
392
  saveEvidenceBundleSnapshot: (bundle) => this.saveEvidenceBundleSnapshot(bundle),
427
393
  saveWorkerClaimSnapshot: (claim, request) => this.saveWorkerClaimSnapshot(claim, request),
428
- queueWorkerHumanInput: (request) => this._queueWorkerHumanInput(request),
394
+ queueWorkerHumanInput: (request) => this._humanInput.queueWorkerInput(request),
429
395
  readMemoryForLane: (query) => this._memory.readMemoryForLane(query),
430
396
  addSpawnedUsage: (usage, opts) => this.addSpawnedUsage(usage, opts),
431
397
  runIsolatedCompletion: (opts) => this.runIsolatedCompletion(opts),
432
398
  // RAW loop, deliberately bypassing the public `continueGoalLoop` — that method now delegates
433
399
  // to this controller's own `continueGoalLoopExclusive` guard, so routing through it here would
434
400
  // recurse into the guard from inside itself instead of driving the actual continuation pass.
435
- continueGoalLoop: (options) => this._goalContinuation.continueGoalLoop(options),
401
+ continueGoalLoop: (options) => this._goals.continueLoop(options),
436
402
  collectWorkspaceSources: (args) => this._collectWorkspaceSources(args),
437
403
  });
438
404
  this._memory = new MemoryController({
@@ -569,11 +535,6 @@ export class AgentSession {
569
535
  addSpawnedUsage: (usage, opts) => this.addSpawnedUsage(usage, opts),
570
536
  saveLearningDecisionSnapshot: (decision) => this.saveLearningDecisionSnapshot(decision),
571
537
  });
572
- this._goalContinuation = new GoalLoopController({
573
- getGoalRuntimeSnapshot: (settings) => this.getGoalRuntimeSnapshot(settings),
574
- prompt: (text, options) => this.prompt(text, options),
575
- recordGoalContinuationPass: (pass) => this.recordGoalContinuationPass(pass),
576
- });
577
538
  this._extensionRunnerRef = config.extensionRunnerRef;
578
539
  this._initialActiveToolNames = config.orchestrationProfile
579
540
  ? [...config.orchestrationProfile.toolNames]
@@ -632,7 +593,8 @@ export class AgentSession {
632
593
  getExcludedToolNames: () => this._excludedToolNames,
633
594
  deriveToolProfileFilter: () => this._profileFilter.deriveToolProfileFilter(),
634
595
  isToolOrCommandAllowedByProfile: (name) => this._profileFilter.isToolOrCommandAllowedByProfile(name),
635
- filterExtensionsForRuntime: (extensions) => this._profileFilter.filterExtensionsForRuntime(extensions),
596
+ isExtensionPathAllowed: (path, authority, baseDir) => this._profileFilter.isExtensionPathAllowed(path, authority, baseDir),
597
+ filterExtensionsForRuntime: (extensions, explicitLiveExtensionPaths) => this._profileFilter.filterExtensionsForRuntime(extensions, explicitLiveExtensionPaths),
636
598
  setUnboundToolGrantWarnings: (warnings) => {
637
599
  this._unboundToolGrantWarnings = warnings;
638
600
  },
@@ -903,7 +865,7 @@ export class AgentSession {
903
865
  }
904
866
  throw new Error(result.error);
905
867
  }
906
- if (result.apiKey) {
868
+ if (this._modelRegistry.canUseResolvedRequestAuth(model, result)) {
907
869
  return { apiKey: result.apiKey, headers: result.headers };
908
870
  }
909
871
  const isOAuth = this._modelRegistry.isUsingOAuth(model);
@@ -983,7 +945,7 @@ export class AgentSession {
983
945
  // character caps are the only budget protection for this block -- load-bearing,
984
946
  // not merely defensive.
985
947
  const gcMessages = this._maybeAppendMemoryEvidenceBlock(enforcementResult.messages, memoryReport);
986
- return gcMessages;
948
+ return injectCompactGoalContext(gcMessages, this.getGoalStateSnapshot());
987
949
  };
988
950
  }
989
951
  /**
@@ -1542,7 +1504,7 @@ export class AgentSession {
1542
1504
  }
1543
1505
  }
1544
1506
  if (event.type === "agent_end" && !this._willRetryAfterAgentEnd(event)) {
1545
- this._schedulePendingWorkerHumanInputs();
1507
+ this._humanInput.schedulePendingWorkerInputs();
1546
1508
  }
1547
1509
  };
1548
1510
  _willRetryAfterAgentEnd(event) {
@@ -1770,7 +1732,7 @@ export class AgentSession {
1770
1732
  this.agent.afterToolCall = undefined;
1771
1733
  this.agent.transformContext = undefined;
1772
1734
  });
1773
- safely(() => this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload()."));
1735
+ safely(() => this._extensionRunner.invalidate());
1774
1736
  safely(() => this._disconnectFromAgent());
1775
1737
  this._eventListeners = [];
1776
1738
  // Best-effort memory cleanup (release locks/handles). Write-side onSessionEnd is wired on a
@@ -2001,186 +1963,13 @@ export class AgentSession {
2001
1963
  await this._drainQueuedExtensionCommands();
2002
1964
  }
2003
1965
  }
2004
- _queueWorkerHumanInput(request) {
2005
- const existing = getLatestHumanInputSnapshots(this.sessionManager).find((snapshot) => snapshot.request.workerRequestId === request.workerRequestId);
2006
- if (existing)
2007
- return;
2008
- const blockerText = request.blockers
2009
- .slice(0, 4)
2010
- .map((blocker) => blocker.slice(0, 500))
2011
- .join("; ");
2012
- const question = createHumanInputRequest({
2013
- source: "worker",
2014
- workerRequestId: request.workerRequestId,
2015
- questions: [
2016
- {
2017
- id: "worker_review",
2018
- header: "Worker review",
2019
- question: `${request.message.slice(0, 1_500)}${blockerText ? ` Blockers: ${blockerText}` : ""}`,
2020
- options: [
2021
- {
2022
- label: "Review now",
2023
- description: "Have the parent inspect the worker claim and evidence before reconciling it.",
2024
- },
2025
- {
2026
- label: "Keep blocked",
2027
- description: "Leave the worker result blocked and continue without accepting its output.",
2028
- },
2029
- ],
2030
- },
2031
- ],
2032
- acceptsImages: false,
2033
- });
2034
- beginHumanInputRequest(this.sessionManager, question);
2035
- if (!this.isStreaming)
2036
- this._scheduleWorkerHumanInput(question);
2037
- }
2038
- _schedulePendingWorkerHumanInputs() {
2039
- for (const snapshot of getWorkerHumanInputsRequiringDelivery(this.sessionManager)) {
2040
- this._scheduleWorkerHumanInput(snapshot);
2041
- }
2042
- }
2043
- _scheduleWorkerHumanInput(input) {
2044
- const snapshot = "status" in input ? input : { request: input, status: "pending", answers: [], updatedAt: input.createdAt };
2045
- const requestId = snapshot.request.requestId;
2046
- if (this._activeHumanInputRequestIds.has(requestId))
2047
- return;
2048
- this._activeHumanInputRequestIds.add(requestId);
2049
- this._humanInputTail = this._humanInputTail
2050
- .then(async () => {
2051
- await this._resolveWorkerHumanInput(snapshot);
2052
- })
2053
- .catch((error) => {
2054
- this._emit({
2055
- type: "warning",
2056
- message: `Worker owner-input request failed: ${error instanceof Error ? error.message : String(error)}`,
2057
- });
2058
- })
2059
- .finally(() => {
2060
- this._activeHumanInputRequestIds.delete(requestId);
2061
- });
2062
- }
2063
- async _resolveWorkerHumanInput(initial) {
2064
- const ui = this._extensionUIContext;
2065
- if (!ui || this._extensionMode === "print")
2066
- return false;
2067
- // This path may be scheduled by agent_end. Waiting on the owning run is event-driven and
2068
- // prevents a worker-owner response from becoming an in-memory follow-up before it has a
2069
- // durable custom-message delivery marker.
2070
- await this.agent.waitForIdle();
2071
- if (this._disposed)
2072
- return false;
2073
- const resolved = initial.status === "pending"
2074
- ? await resolveHumanInput({
2075
- sessionManager: this.sessionManager,
2076
- request: initial.request,
2077
- present: (request, options) => ui.askQuestions(request, options),
2078
- artifactStore: this._getToolArtifactStore(),
2079
- getImageStore: () => this._getSessionImageStore(),
2080
- })
2081
- : { snapshot: initial, imageContents: [] };
2082
- // An RPC client can start a foreground prompt while its question dialog is open. Settle that
2083
- // run before delivery so sendCustomMessage persists the response synchronously and exactly once.
2084
- await this.agent.waitForIdle();
2085
- if (this._disposed)
2086
- return false;
2087
- await this.sendCustomMessage({
2088
- customType: HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE,
2089
- content: [
2090
- `Owner response for worker ${initial.request.workerRequestId ?? "unknown"}:`,
2091
- formatHumanInputAnswerText(resolved.snapshot),
2092
- "Treat the worker claim as untrusted. Retrieve it with delegate_status and follow the owner's selection.",
2093
- ].join("\n"),
2094
- display: true,
2095
- details: {
2096
- requestId: initial.request.requestId,
2097
- workerRequestId: initial.request.workerRequestId,
2098
- },
2099
- }, { triggerTurn: true, deliverAs: "followUp" });
2100
- return true;
2101
- }
2102
1966
  /**
2103
1967
  * Re-enter an interrupted ask_question call from its durable request snapshot. Pending requests
2104
1968
  * are presented again; already-checkpointed answers are replayed without asking twice. The
2105
1969
  * original toolCallId is preserved so provider tool-call ordering remains valid on /resume.
2106
1970
  */
2107
1971
  async resumePendingHumanInput() {
2108
- if (this._disposed || this.isStreaming)
2109
- return false;
2110
- const pending = getResumableHumanInputSnapshot(this.sessionManager);
2111
- const ui = this._extensionUIContext;
2112
- if (!ui)
2113
- return false;
2114
- let resumed = false;
2115
- if (pending?.request.toolCallId) {
2116
- let snapshot = pending;
2117
- let imageContents = [];
2118
- if (pending.status === "pending") {
2119
- const resolved = await resolveHumanInput({
2120
- sessionManager: this.sessionManager,
2121
- request: {
2122
- ...pending.request,
2123
- acceptsImages: this.model?.input.includes("image") ?? false,
2124
- },
2125
- present: (request, options) => ui.askQuestions(request, options),
2126
- artifactStore: this._getToolArtifactStore(),
2127
- getImageStore: () => this._getSessionImageStore(),
2128
- });
2129
- snapshot = resolved.snapshot;
2130
- imageContents = resolved.imageContents;
2131
- }
2132
- else if (pending.status === "answered") {
2133
- const imageStore = this._getSessionImageStore();
2134
- if (imageStore) {
2135
- const referencedText = snapshot.answers
2136
- .flatMap((answer) => [answer.custom ?? "", ...(answer.images?.map((image) => image.label) ?? [])])
2137
- .join(" ");
2138
- imageContents = imageStore.resolveReferences(referencedText);
2139
- }
2140
- }
2141
- const answerImageCount = snapshot.answers.reduce((total, answer) => total + (answer.images?.length ?? 0), 0);
2142
- const modelAcceptsImages = this.model?.input.includes("image") ?? false;
2143
- const missingImageNotice = answerImageCount > imageContents.length
2144
- ? `\n\n[${answerImageCount - imageContents.length} attached image(s) could not be restored from durable storage.]`
2145
- : "";
2146
- const unsupportedImageNotice = imageContents.length > 0 && !modelAcceptsImages
2147
- ? "\n\n[Attached images were retained but not sent because the selected model does not accept image input.]"
2148
- : "";
2149
- const toolResult = {
2150
- role: "toolResult",
2151
- toolCallId: pending.request.toolCallId,
2152
- toolName: pending.request.toolName ?? "ask_question",
2153
- content: [
2154
- {
2155
- type: "text",
2156
- text: `${formatHumanInputAnswerText(snapshot)}${missingImageNotice}${unsupportedImageNotice}`,
2157
- },
2158
- ...(modelAcceptsImages ? imageContents : []),
2159
- ],
2160
- details: {
2161
- questions: snapshot.request.questions,
2162
- answers: snapshot.answers,
2163
- cancelled: snapshot.status === "cancelled",
2164
- ...(snapshot.reason ? { reason: snapshot.reason } : {}),
2165
- },
2166
- isError: false,
2167
- timestamp: Date.now(),
2168
- };
2169
- await this._runAgentPrompt(toolResult);
2170
- resumed = true;
2171
- }
2172
- for (const workerInput of getWorkerHumanInputsRequiringDelivery(this.sessionManager)) {
2173
- if (this._activeHumanInputRequestIds.has(workerInput.request.requestId))
2174
- continue;
2175
- this._activeHumanInputRequestIds.add(workerInput.request.requestId);
2176
- try {
2177
- resumed = (await this._resolveWorkerHumanInput(workerInput)) || resumed;
2178
- }
2179
- finally {
2180
- this._activeHumanInputRequestIds.delete(workerInput.request.requestId);
2181
- }
2182
- }
2183
- return resumed;
1972
+ return this._humanInput.resumePending();
2184
1973
  }
2185
1974
  /**
2186
1975
  * Shared {@link OllamaRuntime} for a given server, lazily created and cached by baseUrl so every
@@ -2274,6 +2063,7 @@ export class AgentSession {
2274
2063
  // selected/authenticated — can un-register it from _earlyDisplayedUserMessages instead of
2275
2064
  // leaking the reference forever.
2276
2065
  let userMessage;
2066
+ let promptMessage;
2277
2067
  let routingStarted = false;
2278
2068
  let pendingNextTurnCount = 0;
2279
2069
  // Effectiveness feedback: remember the recall page + the query so we can score, after the
@@ -2346,17 +2136,25 @@ export class AgentSession {
2346
2136
  // (seconds), not a regex; awaiting it first made the prompt appear to hang. The
2347
2137
  // authoritative message_start emitted later for this SAME object is suppressed in
2348
2138
  // _handleAgentEvent (see _earlyDisplayedUserMessages) so it is still shown exactly once.
2349
- const userContent = [{ type: "text", text: expandedText }];
2350
- if (currentImages) {
2351
- userContent.push(...currentImages);
2139
+ if (options?.internalContextType) {
2140
+ if (currentImages && currentImages.length > 0) {
2141
+ throw new Error("Internal context turns do not accept image attachments.");
2142
+ }
2143
+ promptMessage = createCustomMessage(options.internalContextType, expandedText, false, undefined, new Date().toISOString());
2144
+ }
2145
+ else {
2146
+ const userContent = [{ type: "text", text: expandedText }];
2147
+ if (currentImages)
2148
+ userContent.push(...currentImages);
2149
+ userMessage = {
2150
+ role: "user",
2151
+ content: userContent,
2152
+ timestamp: Date.now(),
2153
+ };
2154
+ promptMessage = userMessage;
2155
+ this._earlyDisplayedUserMessages.add(userMessage);
2156
+ this._emit({ type: "message_start", message: userMessage });
2352
2157
  }
2353
- userMessage = {
2354
- role: "user",
2355
- content: userContent,
2356
- timestamp: Date.now(),
2357
- };
2358
- this._earlyDisplayedUserMessages.add(userMessage);
2359
- this._emit({ type: "message_start", message: userMessage });
2360
2158
  // Bracket the routing/prep phase (judge, model/auth checks, compaction, ...) so the UI can
2361
2159
  // show general "working" feedback for it — otherwise the user stares at their own echoed
2362
2160
  // prompt with nothing happening for however long the judge takes. routing_end is emitted
@@ -2410,7 +2208,7 @@ export class AgentSession {
2410
2208
  // prefetch a relevant <memory_context> page from past sessions and prepend it as data ahead of
2411
2209
  // the user message. Best-effort and gated: trivial turns are skipped, and providers return ""
2412
2210
  // (no page) when nothing is relevant — so it stays net-negative and the GC packs stale pages.
2413
- if (this._memory.shouldAttemptRecall(expandedText)) {
2211
+ if (!options?.internalContextType && this._memory.shouldAttemptRecall(expandedText)) {
2414
2212
  try {
2415
2213
  const recall = await this._memory.prefetchRecall(expandedText);
2416
2214
  if (recall) {
@@ -2429,13 +2227,13 @@ export class AgentSession {
2429
2227
  }
2430
2228
  // Add user message (built earlier, before the router judge, so it could be painted
2431
2229
  // immediately — see the early message_start emit above).
2432
- messages.push(userMessage);
2230
+ messages.push(promptMessage);
2433
2231
  // Inject any pending "nextTurn" messages as context alongside the user message
2434
2232
  pendingNextTurnCount = this._pendingNextTurnMessages.length;
2435
2233
  for (const msg of this._pendingNextTurnMessages.slice(0, pendingNextTurnCount)) {
2436
2234
  messages.push(msg);
2437
2235
  }
2438
- const taskStepsState = this.getTaskStepsStateSnapshot();
2236
+ const taskStepsState = options?.internalContextType ? undefined : this.getTaskStepsStateSnapshot();
2439
2237
  const taskStepsContext = taskStepsState ? formatTaskStepsContext(taskStepsState) : undefined;
2440
2238
  if (taskStepsState && taskStepsContext) {
2441
2239
  messages.push(createCustomMessage("task_steps_context", taskStepsContext, false, { revision: taskStepsState.revision }, new Date().toISOString()));
@@ -3287,49 +3085,35 @@ export class AgentSession {
3287
3085
  *
3288
3086
  * @returns the id of the appended custom entry
3289
3087
  */
3290
- saveGoalStateSnapshot(state) {
3291
- const entryId = appendGoalStateSnapshot(this.sessionManager, state);
3292
- try {
3293
- this._backgroundLanes.synchronizeGoalState(state);
3294
- }
3295
- catch (error) {
3296
- this._emit({
3297
- type: "warning",
3298
- message: `Goal state persisted but durable worker reconciliation failed: ${error instanceof Error ? error.message : String(error)}`,
3299
- });
3300
- }
3301
- return entryId;
3088
+ saveGoalStateSnapshot(state, expected) {
3089
+ return this._goals.saveState(state, expected);
3090
+ }
3091
+ /** Persist a branch-scoped tombstone and stop goal-owned execution without resurrecting old state. */
3092
+ clearGoalStateSnapshot(state, now) {
3093
+ return this._goals.clearState(state, now);
3302
3094
  }
3303
3095
  /**
3304
3096
  * Retrieve the latest valid goal state snapshot from the session log.
3305
3097
  */
3306
3098
  getGoalStateSnapshot() {
3307
- return getLatestGoalStateSnapshot(this.sessionManager);
3099
+ return this._goals.getState();
3308
3100
  }
3309
3101
  /**
3310
- * Persist one submitted continuation pass's turn/wall-clock/spend contribution onto the active
3311
- * goal's durable cumulative budget (see `GoalState.continuationTurnsUsed` et al.). This is the
3102
+ * Persist one submitted continuation pass's exact turn/wall-clock/token/spend contribution onto the active
3103
+ * goal's durable cumulative accounting (see `GoalState.continuationTurnsUsed` et al.). This is the
3312
3104
  * "persistence dep" `GoalLoopController` calls once per pass actually submitted — it, not the
3313
- * loop controller, is where USD gets attributed: it reads the session's OWN cumulative model
3314
- * spend (`getCostSummary().ownCost` deliberately excludes worker/subagent spend, which is
3315
- * tracked and budgeted separately) and threads that single absolute reading into a
3316
- * `record_continuation_budget` event; the pure reducer in `goal-state.ts` derives the delta.
3105
+ * loop controller, is where usage gets attributed: it scans only assistant messages appended on
3106
+ * the active branch after the pass's captured cursor. Compaction cannot erase or reattribute that
3107
+ * append-only interval, and unrelated foreground turns outside the interval are excluded.
3317
3108
  * A no-op when no goal state exists (defensive — in practice this is only ever called right
3318
3109
  * after a pass the loop already confirmed was submitted against an active goal).
3319
3110
  */
3320
3111
  recordGoalContinuationPass(pass) {
3321
- const state = this.getGoalStateSnapshot();
3322
- if (!state)
3323
- return;
3324
- const sessionCostUsd = this.getCostSummary().ownCost;
3325
- const updated = applyGoalEvent(state, {
3326
- type: "record_continuation_budget",
3327
- turns: pass.turns,
3328
- wallClockMs: pass.wallClockMs,
3329
- sessionCostUsd,
3330
- now: new Date().toISOString(),
3331
- });
3332
- this.saveGoalStateSnapshot(updated);
3112
+ this._goals.recordContinuationPass(pass);
3113
+ }
3114
+ /** Restore runtime intent without mutating persisted goal lifecycle state. */
3115
+ restoreGoalRuntimeAfterResume() {
3116
+ this._goals.restoreAfterResume();
3333
3117
  }
3334
3118
  /** Save native task-step state to the active session log. */
3335
3119
  saveTaskStepsStateSnapshot(state) {
@@ -3394,12 +3178,7 @@ export class AgentSession {
3394
3178
  * same live lane state, since both reach this same method.
3395
3179
  */
3396
3180
  getGoalRuntimeSnapshot(settings) {
3397
- return buildGoalRuntimeSnapshot({
3398
- sessionManager: this.sessionManager,
3399
- settings,
3400
- laneRecords: this._backgroundLanes.getLaneRecords(),
3401
- taskRuntime: this._backgroundLanes.getTaskRuntimeSnapshot(),
3402
- });
3181
+ return this._goals.getRuntimeSnapshot(settings);
3403
3182
  }
3404
3183
  /**
3405
3184
  * Capability profile derived from the CURRENT session model's own metadata (context window),
@@ -3456,14 +3235,14 @@ export class AgentSession {
3456
3235
  return this._backgroundLanes.getStoredFitnessReports();
3457
3236
  }
3458
3237
  async continueGoalOnce(options) {
3459
- return this._goalContinuation.continueGoalOnce(options);
3238
+ return this._goals.continueOnce(options);
3460
3239
  }
3461
3240
  /**
3462
3241
  * Public entry point for BOTH idle autosteer and manual (`/goal start`, `/goal-continue`)
3463
3242
  * continuation. Delegates to {@link BackgroundLaneController.continueGoalLoopExclusive}, the
3464
3243
  * single-flight guard that prevents two goal loops from racing to submit prompts through the
3465
3244
  * same session (which throws "Agent is already processing" from the second submission). Do not
3466
- * call `this._goalContinuation.continueGoalLoop` directly from here — that bypasses the guard.
3245
+ * call `this._goals.continueLoop` directly from here — that bypasses the guard.
3467
3246
  */
3468
3247
  async continueGoalLoop(options) {
3469
3248
  return this._backgroundLanes.continueGoalLoopExclusive(options);