@caupulican/pi-adaptative 0.81.39 → 0.81.40

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 (667) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +2 -0
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +2 -0
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +3 -0
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
  13. package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
  14. package/dist/cli/args.d.ts +2 -0
  15. package/dist/cli/args.d.ts.map +1 -1
  16. package/dist/cli/args.js +9 -0
  17. package/dist/cli/args.js.map +1 -1
  18. package/dist/core/agent-directory-layout.d.ts +15 -0
  19. package/dist/core/agent-directory-layout.d.ts.map +1 -0
  20. package/dist/core/agent-directory-layout.js +72 -0
  21. package/dist/core/agent-directory-layout.js.map +1 -0
  22. package/dist/core/agent-paths.d.ts +19 -2
  23. package/dist/core/agent-paths.d.ts.map +1 -1
  24. package/dist/core/agent-paths.js +67 -4
  25. package/dist/core/agent-paths.js.map +1 -1
  26. package/dist/core/agent-session-runtime.d.ts +52 -8
  27. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  28. package/dist/core/agent-session-runtime.js +397 -79
  29. package/dist/core/agent-session-runtime.js.map +1 -1
  30. package/dist/core/agent-session-services.d.ts +1 -0
  31. package/dist/core/agent-session-services.d.ts.map +1 -1
  32. package/dist/core/agent-session-services.js +1 -0
  33. package/dist/core/agent-session-services.js.map +1 -1
  34. package/dist/core/agent-session.d.ts +71 -136
  35. package/dist/core/agent-session.d.ts.map +1 -1
  36. package/dist/core/agent-session.js +477 -1318
  37. package/dist/core/agent-session.js.map +1 -1
  38. package/dist/core/autonomy/approval-gate.d.ts +3 -2
  39. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  40. package/dist/core/autonomy/approval-gate.js +6 -28
  41. package/dist/core/autonomy/approval-gate.js.map +1 -1
  42. package/dist/core/autonomy/bounded-completion.d.ts +1 -1
  43. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  44. package/dist/core/autonomy/bounded-completion.js +1 -1
  45. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  46. package/dist/core/autonomy/contracts.d.ts +20 -12
  47. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  48. package/dist/core/autonomy/contracts.js.map +1 -1
  49. package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
  50. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  51. package/dist/core/autonomy/foreground-envelope.js +8 -25
  52. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  53. package/dist/core/autonomy/gates.d.ts.map +1 -1
  54. package/dist/core/autonomy/gates.js +8 -10
  55. package/dist/core/autonomy/gates.js.map +1 -1
  56. package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
  57. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
  58. package/dist/core/autonomy/lane-private-paths.js +16 -0
  59. package/dist/core/autonomy/lane-private-paths.js.map +1 -0
  60. package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
  61. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  62. package/dist/core/autonomy/lane-tool-surface.js +46 -8
  63. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  64. package/dist/core/autonomy/lane-tracker.d.ts +14 -0
  65. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  66. package/dist/core/autonomy/lane-tracker.js +38 -0
  67. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  68. package/dist/core/autonomy/risk-assessment.d.ts +1 -2
  69. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  70. package/dist/core/autonomy/risk-assessment.js +1 -123
  71. package/dist/core/autonomy/risk-assessment.js.map +1 -1
  72. package/dist/core/autonomy/session-lane-record.d.ts +4 -4
  73. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  74. package/dist/core/autonomy/session-lane-record.js +16 -29
  75. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  76. package/dist/core/autonomy/telemetry-events.d.ts +1 -1
  77. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  78. package/dist/core/autonomy/telemetry-events.js +1 -1
  79. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  80. package/dist/core/autonomy-telemetry.d.ts +7 -7
  81. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  82. package/dist/core/autonomy-telemetry.js +9 -9
  83. package/dist/core/autonomy-telemetry.js.map +1 -1
  84. package/dist/core/background-lane-controller.d.ts +54 -236
  85. package/dist/core/background-lane-controller.d.ts.map +1 -1
  86. package/dist/core/background-lane-controller.js +140 -1273
  87. package/dist/core/background-lane-controller.js.map +1 -1
  88. package/dist/core/capability-contract.d.ts +4 -0
  89. package/dist/core/capability-contract.d.ts.map +1 -0
  90. package/dist/core/capability-contract.js +28 -0
  91. package/dist/core/capability-contract.js.map +1 -0
  92. package/dist/core/compaction-controller.d.ts +90 -0
  93. package/dist/core/compaction-controller.d.ts.map +1 -0
  94. package/dist/core/compaction-controller.js +452 -0
  95. package/dist/core/compaction-controller.js.map +1 -0
  96. package/dist/core/compaction-support.d.ts +12 -11
  97. package/dist/core/compaction-support.d.ts.map +1 -1
  98. package/dist/core/compaction-support.js.map +1 -1
  99. package/dist/core/context/context-artifacts.d.ts +6 -2
  100. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  101. package/dist/core/context/context-artifacts.js +34 -2
  102. package/dist/core/context/context-artifacts.js.map +1 -1
  103. package/dist/core/context/context-store-retention.d.ts +8 -2
  104. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  105. package/dist/core/context/context-store-retention.js +158 -35
  106. package/dist/core/context/context-store-retention.js.map +1 -1
  107. package/dist/core/context/okf-memory.d.ts.map +1 -1
  108. package/dist/core/context/okf-memory.js +9 -11
  109. package/dist/core/context/okf-memory.js.map +1 -1
  110. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  111. package/dist/core/context/sqlite-runtime-index.js +6 -8
  112. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  113. package/dist/core/context-gc.d.ts +3 -0
  114. package/dist/core/context-gc.d.ts.map +1 -1
  115. package/dist/core/context-gc.js +10 -5
  116. package/dist/core/context-gc.js.map +1 -1
  117. package/dist/core/context-pipeline.d.ts.map +1 -1
  118. package/dist/core/context-pipeline.js +9 -4
  119. package/dist/core/context-pipeline.js.map +1 -1
  120. package/dist/core/default-tool-surface.d.ts.map +1 -1
  121. package/dist/core/default-tool-surface.js +1 -0
  122. package/dist/core/default-tool-surface.js.map +1 -1
  123. package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
  124. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
  125. package/dist/core/delegation/managed-lane-controller.js +217 -0
  126. package/dist/core/delegation/managed-lane-controller.js.map +1 -0
  127. package/dist/core/delegation/session-worker-claim.d.ts +44 -0
  128. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
  129. package/dist/core/delegation/session-worker-claim.js +98 -0
  130. package/dist/core/delegation/session-worker-claim.js.map +1 -0
  131. package/dist/core/delegation/worker-actions.d.ts +7 -5
  132. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  133. package/dist/core/delegation/worker-actions.js +20 -4
  134. package/dist/core/delegation/worker-actions.js.map +1 -1
  135. package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
  136. package/dist/core/delegation/worker-claim.d.ts.map +1 -0
  137. package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
  138. package/dist/core/delegation/worker-claim.js.map +1 -0
  139. package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
  140. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
  141. package/dist/core/delegation/worker-delegation-controller.js +861 -0
  142. package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
  143. package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
  144. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
  145. package/dist/core/delegation/worker-delegation-request.js +2 -0
  146. package/dist/core/delegation/worker-delegation-request.js.map +1 -0
  147. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
  148. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
  149. package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
  150. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
  151. package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
  152. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
  153. package/dist/core/delegation/worker-execution-policy.js +160 -0
  154. package/dist/core/delegation/worker-execution-policy.js.map +1 -0
  155. package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
  156. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
  157. package/dist/core/delegation/worker-lane-projection.js +100 -0
  158. package/dist/core/delegation/worker-lane-projection.js.map +1 -0
  159. package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
  160. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
  161. package/dist/core/delegation/worker-lifecycle.js +339 -0
  162. package/dist/core/delegation/worker-lifecycle.js.map +1 -0
  163. package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
  164. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
  165. package/dist/core/delegation/worker-notification-coordinator.js +90 -0
  166. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
  167. package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
  168. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
  169. package/dist/core/delegation/worker-profile-resolver.js +113 -0
  170. package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
  171. package/dist/core/delegation/worker-runner.d.ts +25 -14
  172. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  173. package/dist/core/delegation/worker-runner.js +122 -53
  174. package/dist/core/delegation/worker-runner.js.map +1 -1
  175. package/dist/core/delegation/worker-task-label.d.ts +3 -0
  176. package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
  177. package/dist/core/delegation/worker-task-label.js +11 -0
  178. package/dist/core/delegation/worker-task-label.js.map +1 -0
  179. package/dist/core/doctor.d.ts +8 -0
  180. package/dist/core/doctor.d.ts.map +1 -1
  181. package/dist/core/doctor.js +32 -1
  182. package/dist/core/doctor.js.map +1 -1
  183. package/dist/core/extensions/index.d.ts +1 -1
  184. package/dist/core/extensions/index.d.ts.map +1 -1
  185. package/dist/core/extensions/index.js.map +1 -1
  186. package/dist/core/extensions/loader.d.ts +5 -1
  187. package/dist/core/extensions/loader.d.ts.map +1 -1
  188. package/dist/core/extensions/loader.js +50 -15
  189. package/dist/core/extensions/loader.js.map +1 -1
  190. package/dist/core/extensions/runner.d.ts.map +1 -1
  191. package/dist/core/extensions/runner.js +6 -0
  192. package/dist/core/extensions/runner.js.map +1 -1
  193. package/dist/core/extensions/storage.d.ts +8 -0
  194. package/dist/core/extensions/storage.d.ts.map +1 -0
  195. package/dist/core/extensions/storage.js +28 -0
  196. package/dist/core/extensions/storage.js.map +1 -0
  197. package/dist/core/extensions/types.d.ts +70 -21
  198. package/dist/core/extensions/types.d.ts.map +1 -1
  199. package/dist/core/extensions/types.js.map +1 -1
  200. package/dist/core/failure-corpus.d.ts +1 -15
  201. package/dist/core/failure-corpus.d.ts.map +1 -1
  202. package/dist/core/failure-corpus.js +9 -37
  203. package/dist/core/failure-corpus.js.map +1 -1
  204. package/dist/core/foreground-recovery-controller.d.ts +52 -0
  205. package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
  206. package/dist/core/foreground-recovery-controller.js +111 -0
  207. package/dist/core/foreground-recovery-controller.js.map +1 -0
  208. package/dist/core/gateways/channel-provider.d.ts +3 -0
  209. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  210. package/dist/core/gateways/channel-provider.js +31 -6
  211. package/dist/core/gateways/channel-provider.js.map +1 -1
  212. package/dist/core/goals/goal-acceptance.d.ts +11 -0
  213. package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
  214. package/dist/core/goals/goal-acceptance.js +25 -0
  215. package/dist/core/goals/goal-acceptance.js.map +1 -0
  216. package/dist/core/goals/goal-auto-continue-controller.d.ts +27 -0
  217. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
  218. package/dist/core/goals/goal-auto-continue-controller.js +93 -0
  219. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
  220. package/dist/core/goals/goal-continuation-controller.d.ts +1 -1
  221. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  222. package/dist/core/goals/goal-continuation-controller.js +10 -0
  223. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  224. package/dist/core/goals/goal-continuation-prompt.d.ts +1 -1
  225. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  226. package/dist/core/goals/goal-continuation-prompt.js +6 -6
  227. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  228. package/dist/core/goals/goal-lifecycle.d.ts +20 -0
  229. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
  230. package/dist/core/goals/goal-lifecycle.js +17 -0
  231. package/dist/core/goals/goal-lifecycle.js.map +1 -0
  232. package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
  233. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  234. package/dist/core/goals/goal-runtime-snapshot.js +10 -8
  235. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  236. package/dist/core/goals/goal-state.d.ts +1 -0
  237. package/dist/core/goals/goal-state.d.ts.map +1 -1
  238. package/dist/core/goals/goal-state.js +7 -10
  239. package/dist/core/goals/goal-state.js.map +1 -1
  240. package/dist/core/goals/goal-tool-core.d.ts +8 -6
  241. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  242. package/dist/core/goals/goal-tool-core.js +11 -41
  243. package/dist/core/goals/goal-tool-core.js.map +1 -1
  244. package/dist/core/goals/session-goal-state.d.ts +2 -4
  245. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  246. package/dist/core/goals/session-goal-state.js +10 -33
  247. package/dist/core/goals/session-goal-state.js.map +1 -1
  248. package/dist/core/human-input.d.ts +100 -0
  249. package/dist/core/human-input.d.ts.map +1 -0
  250. package/dist/core/human-input.js +362 -0
  251. package/dist/core/human-input.js.map +1 -0
  252. package/dist/core/index.d.ts +9 -1
  253. package/dist/core/index.d.ts.map +1 -1
  254. package/dist/core/index.js +9 -1
  255. package/dist/core/index.js.map +1 -1
  256. package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
  257. package/dist/core/install-telemetry.d.ts.map +1 -0
  258. package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
  259. package/dist/core/install-telemetry.js.map +1 -0
  260. package/dist/core/keybindings.d.ts +17 -1
  261. package/dist/core/keybindings.d.ts.map +1 -1
  262. package/dist/core/keybindings.js +24 -6
  263. package/dist/core/keybindings.js.map +1 -1
  264. package/dist/core/learning/learning-audit.d.ts +2 -4
  265. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  266. package/dist/core/learning/learning-audit.js +9 -29
  267. package/dist/core/learning/learning-audit.js.map +1 -1
  268. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  269. package/dist/core/learning/learning-gate.js +1 -6
  270. package/dist/core/learning/learning-gate.js.map +1 -1
  271. package/dist/core/learning/session-learning-decision.d.ts +2 -4
  272. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  273. package/dist/core/learning/session-learning-decision.js +9 -29
  274. package/dist/core/learning/session-learning-decision.js.map +1 -1
  275. package/dist/core/memory-controller.d.ts.map +1 -1
  276. package/dist/core/memory-controller.js +4 -4
  277. package/dist/core/memory-controller.js.map +1 -1
  278. package/dist/core/model-capability.d.ts.map +1 -1
  279. package/dist/core/model-capability.js +1 -0
  280. package/dist/core/model-capability.js.map +1 -1
  281. package/dist/core/model-resolver.d.ts +1 -1
  282. package/dist/core/model-resolver.d.ts.map +1 -1
  283. package/dist/core/model-resolver.js +6 -9
  284. package/dist/core/model-resolver.js.map +1 -1
  285. package/dist/core/model-router/intent-classifier.d.ts +1 -4
  286. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  287. package/dist/core/model-router/intent-classifier.js +1 -156
  288. package/dist/core/model-router/intent-classifier.js.map +1 -1
  289. package/dist/core/model-router-controller.d.ts.map +1 -1
  290. package/dist/core/model-router-controller.js +2 -2
  291. package/dist/core/model-router-controller.js.map +1 -1
  292. package/dist/core/model-selection-controller.d.ts +4 -4
  293. package/dist/core/model-selection-controller.d.ts.map +1 -1
  294. package/dist/core/model-selection-controller.js.map +1 -1
  295. package/dist/core/model-tool-protocol.d.ts +23 -0
  296. package/dist/core/model-tool-protocol.d.ts.map +1 -0
  297. package/dist/core/model-tool-protocol.js +43 -0
  298. package/dist/core/model-tool-protocol.js.map +1 -0
  299. package/dist/core/models/adaptation-store.d.ts +4 -6
  300. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  301. package/dist/core/models/adaptation-store.js +95 -83
  302. package/dist/core/models/adaptation-store.js.map +1 -1
  303. package/dist/core/models/fitness-store.d.ts +2 -12
  304. package/dist/core/models/fitness-store.d.ts.map +1 -1
  305. package/dist/core/models/fitness-store.js +84 -57
  306. package/dist/core/models/fitness-store.js.map +1 -1
  307. package/dist/core/models/host-state-store.d.ts +34 -0
  308. package/dist/core/models/host-state-store.d.ts.map +1 -0
  309. package/dist/core/models/host-state-store.js +86 -0
  310. package/dist/core/models/host-state-store.js.map +1 -0
  311. package/dist/core/orchestration/agent-resume.d.ts +24 -0
  312. package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
  313. package/dist/core/orchestration/agent-resume.js +90 -0
  314. package/dist/core/orchestration/agent-resume.js.map +1 -0
  315. package/dist/core/orchestration/capability-gateway.d.ts +61 -0
  316. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
  317. package/dist/core/orchestration/capability-gateway.js +152 -0
  318. package/dist/core/orchestration/capability-gateway.js.map +1 -0
  319. package/dist/core/orchestration/contracts.d.ts +343 -0
  320. package/dist/core/orchestration/contracts.d.ts.map +1 -0
  321. package/dist/core/orchestration/contracts.js +135 -0
  322. package/dist/core/orchestration/contracts.js.map +1 -0
  323. package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
  324. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
  325. package/dist/core/orchestration/delegation-ledger.js +197 -0
  326. package/dist/core/orchestration/delegation-ledger.js.map +1 -0
  327. package/dist/core/orchestration/event-store.d.ts +83 -0
  328. package/dist/core/orchestration/event-store.d.ts.map +1 -0
  329. package/dist/core/orchestration/event-store.js +560 -0
  330. package/dist/core/orchestration/event-store.js.map +1 -0
  331. package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
  332. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
  333. package/dist/core/orchestration/lane-tool-manifests.js +37 -0
  334. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
  335. package/dist/core/orchestration/model-binding.d.ts +15 -0
  336. package/dist/core/orchestration/model-binding.d.ts.map +1 -0
  337. package/dist/core/orchestration/model-binding.js +29 -0
  338. package/dist/core/orchestration/model-binding.js.map +1 -0
  339. package/dist/core/orchestration/policy-compiler.d.ts +49 -0
  340. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
  341. package/dist/core/orchestration/policy-compiler.js +191 -0
  342. package/dist/core/orchestration/policy-compiler.js.map +1 -0
  343. package/dist/core/orchestration/policy-gate.d.ts +18 -0
  344. package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
  345. package/dist/core/orchestration/policy-gate.js +24 -0
  346. package/dist/core/orchestration/policy-gate.js.map +1 -0
  347. package/dist/core/orchestration/profile-registry.d.ts +51 -0
  348. package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
  349. package/dist/core/orchestration/profile-registry.js +393 -0
  350. package/dist/core/orchestration/profile-registry.js.map +1 -0
  351. package/dist/core/orchestration/profile-store.d.ts +31 -0
  352. package/dist/core/orchestration/profile-store.d.ts.map +1 -0
  353. package/dist/core/orchestration/profile-store.js +136 -0
  354. package/dist/core/orchestration/profile-store.js.map +1 -0
  355. package/dist/core/orchestration/risk-budget.d.ts +9 -0
  356. package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
  357. package/dist/core/orchestration/risk-budget.js +48 -0
  358. package/dist/core/orchestration/risk-budget.js.map +1 -0
  359. package/dist/core/orchestration/task-runtime.d.ts +168 -0
  360. package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
  361. package/dist/core/orchestration/task-runtime.js +1600 -0
  362. package/dist/core/orchestration/task-runtime.js.map +1 -0
  363. package/dist/core/orchestration/work-state-projection.d.ts +32 -0
  364. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
  365. package/dist/core/orchestration/work-state-projection.js +116 -0
  366. package/dist/core/orchestration/work-state-projection.js.map +1 -0
  367. package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
  368. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
  369. package/dist/core/orchestration/worker-execution-contract.js +179 -0
  370. package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
  371. package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
  372. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
  373. package/dist/core/orchestration/worker-result-adapter.js +109 -0
  374. package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
  375. package/dist/core/process-identity.d.ts +11 -0
  376. package/dist/core/process-identity.d.ts.map +1 -0
  377. package/dist/core/process-identity.js +26 -0
  378. package/dist/core/process-identity.js.map +1 -0
  379. package/dist/core/process-matrix/codes.d.ts +14 -3
  380. package/dist/core/process-matrix/codes.d.ts.map +1 -1
  381. package/dist/core/process-matrix/codes.js.map +1 -1
  382. package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
  383. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
  384. package/dist/core/process-matrix/resume-launcher.js +62 -0
  385. package/dist/core/process-matrix/resume-launcher.js.map +1 -0
  386. package/dist/core/process-matrix/runtime.d.ts +37 -22
  387. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  388. package/dist/core/process-matrix/runtime.js +399 -76
  389. package/dist/core/process-matrix/runtime.js.map +1 -1
  390. package/dist/core/process-matrix/store.d.ts +5 -2
  391. package/dist/core/process-matrix/store.d.ts.map +1 -1
  392. package/dist/core/process-matrix/store.js +123 -14
  393. package/dist/core/process-matrix/store.js.map +1 -1
  394. package/dist/core/process-matrix/supervisor.d.ts +10 -7
  395. package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
  396. package/dist/core/process-matrix/supervisor.js +45 -14
  397. package/dist/core/process-matrix/supervisor.js.map +1 -1
  398. package/dist/core/profile-registry.d.ts.map +1 -1
  399. package/dist/core/profile-registry.js +6 -8
  400. package/dist/core/profile-registry.js.map +1 -1
  401. package/dist/core/reflection-controller.d.ts +4 -4
  402. package/dist/core/reflection-controller.d.ts.map +1 -1
  403. package/dist/core/reflection-controller.js +2 -1
  404. package/dist/core/reflection-controller.js.map +1 -1
  405. package/dist/core/reload-blockers.d.ts.map +1 -1
  406. package/dist/core/reload-blockers.js +6 -8
  407. package/dist/core/reload-blockers.js.map +1 -1
  408. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  409. package/dist/core/research/evidence-bundle.js +1 -6
  410. package/dist/core/research/evidence-bundle.js.map +1 -1
  411. package/dist/core/research/lane-model-resolver.d.ts +33 -0
  412. package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
  413. package/dist/core/research/lane-model-resolver.js +65 -0
  414. package/dist/core/research/lane-model-resolver.js.map +1 -0
  415. package/dist/core/research/model-fitness-controller.d.ts +38 -0
  416. package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
  417. package/dist/core/research/model-fitness-controller.js +106 -0
  418. package/dist/core/research/model-fitness-controller.js.map +1 -0
  419. package/dist/core/research/model-fitness.d.ts +1 -1
  420. package/dist/core/research/model-fitness.d.ts.map +1 -1
  421. package/dist/core/research/model-fitness.js +4 -4
  422. package/dist/core/research/model-fitness.js.map +1 -1
  423. package/dist/core/research/research-gate.d.ts.map +1 -1
  424. package/dist/core/research/research-gate.js +7 -7
  425. package/dist/core/research/research-gate.js.map +1 -1
  426. package/dist/core/research/research-lane-controller.d.ts +62 -0
  427. package/dist/core/research/research-lane-controller.d.ts.map +1 -0
  428. package/dist/core/research/research-lane-controller.js +292 -0
  429. package/dist/core/research/research-lane-controller.js.map +1 -0
  430. package/dist/core/research/session-evidence-bundle.d.ts +2 -4
  431. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  432. package/dist/core/research/session-evidence-bundle.js +10 -46
  433. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  434. package/dist/core/resource-loader.d.ts.map +1 -1
  435. package/dist/core/resource-loader.js +7 -2
  436. package/dist/core/resource-loader.js.map +1 -1
  437. package/dist/core/risk-classifier.d.ts +6 -0
  438. package/dist/core/risk-classifier.d.ts.map +1 -0
  439. package/dist/core/risk-classifier.js +225 -0
  440. package/dist/core/risk-classifier.js.map +1 -0
  441. package/dist/core/runtime-builder.d.ts +26 -20
  442. package/dist/core/runtime-builder.d.ts.map +1 -1
  443. package/dist/core/runtime-builder.js +237 -178
  444. package/dist/core/runtime-builder.js.map +1 -1
  445. package/dist/core/sdk.d.ts +6 -3
  446. package/dist/core/sdk.d.ts.map +1 -1
  447. package/dist/core/sdk.js +61 -24
  448. package/dist/core/sdk.js.map +1 -1
  449. package/dist/core/session-analytics.d.ts.map +1 -1
  450. package/dist/core/session-analytics.js +28 -1
  451. package/dist/core/session-analytics.js.map +1 -1
  452. package/dist/core/session-image-store.d.ts +33 -0
  453. package/dist/core/session-image-store.d.ts.map +1 -0
  454. package/dist/core/session-image-store.js +283 -0
  455. package/dist/core/session-image-store.js.map +1 -0
  456. package/dist/core/session-role.d.ts +6 -4
  457. package/dist/core/session-role.d.ts.map +1 -1
  458. package/dist/core/session-role.js +10 -4
  459. package/dist/core/session-role.js.map +1 -1
  460. package/dist/core/session-snapshot.d.ts +34 -0
  461. package/dist/core/session-snapshot.d.ts.map +1 -0
  462. package/dist/core/session-snapshot.js +68 -0
  463. package/dist/core/session-snapshot.js.map +1 -0
  464. package/dist/core/session-supervision-runtime.d.ts +31 -0
  465. package/dist/core/session-supervision-runtime.d.ts.map +1 -0
  466. package/dist/core/session-supervision-runtime.js +97 -0
  467. package/dist/core/session-supervision-runtime.js.map +1 -0
  468. package/dist/core/settings-manager.d.ts +9 -4
  469. package/dist/core/settings-manager.d.ts.map +1 -1
  470. package/dist/core/settings-manager.js +80 -28
  471. package/dist/core/settings-manager.js.map +1 -1
  472. package/dist/core/tasks/session-task-state.d.ts +2 -4
  473. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  474. package/dist/core/tasks/session-task-state.js +10 -28
  475. package/dist/core/tasks/session-task-state.js.map +1 -1
  476. package/dist/core/tasks/task-projection.d.ts +20 -0
  477. package/dist/core/tasks/task-projection.d.ts.map +1 -0
  478. package/dist/core/tasks/task-projection.js +47 -0
  479. package/dist/core/tasks/task-projection.js.map +1 -0
  480. package/dist/core/tasks/task-state.d.ts +4 -0
  481. package/dist/core/tasks/task-state.d.ts.map +1 -1
  482. package/dist/core/tasks/task-state.js +28 -11
  483. package/dist/core/tasks/task-state.js.map +1 -1
  484. package/dist/core/tool-capability-policy.d.ts +13 -0
  485. package/dist/core/tool-capability-policy.d.ts.map +1 -0
  486. package/dist/core/tool-capability-policy.js +85 -0
  487. package/dist/core/tool-capability-policy.js.map +1 -0
  488. package/dist/core/tool-protocol-controller.d.ts +91 -0
  489. package/dist/core/tool-protocol-controller.d.ts.map +1 -0
  490. package/dist/core/tool-protocol-controller.js +512 -0
  491. package/dist/core/tool-protocol-controller.js.map +1 -0
  492. package/dist/core/tool-recovery-log-records.d.ts +2 -3
  493. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  494. package/dist/core/tool-recovery-log-records.js +9 -35
  495. package/dist/core/tool-recovery-log-records.js.map +1 -1
  496. package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
  497. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  498. package/dist/core/tool-selection/tool-performance-store.js +97 -138
  499. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  500. package/dist/core/tools/ask-question.d.ts +124 -0
  501. package/dist/core/tools/ask-question.d.ts.map +1 -0
  502. package/dist/core/tools/ask-question.js +693 -0
  503. package/dist/core/tools/ask-question.js.map +1 -0
  504. package/dist/core/tools/delegate-status.d.ts +31 -3
  505. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  506. package/dist/core/tools/delegate-status.js +149 -29
  507. package/dist/core/tools/delegate-status.js.map +1 -1
  508. package/dist/core/tools/delegate.d.ts +15 -13
  509. package/dist/core/tools/delegate.d.ts.map +1 -1
  510. package/dist/core/tools/delegate.js +108 -23
  511. package/dist/core/tools/delegate.js.map +1 -1
  512. package/dist/core/tools/extensionify.d.ts.map +1 -1
  513. package/dist/core/tools/extensionify.js +1 -0
  514. package/dist/core/tools/extensionify.js.map +1 -1
  515. package/dist/core/tools/goal.d.ts +5 -5
  516. package/dist/core/tools/goal.d.ts.map +1 -1
  517. package/dist/core/tools/goal.js +10 -10
  518. package/dist/core/tools/goal.js.map +1 -1
  519. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  520. package/dist/core/tools/model-fitness.js +2 -2
  521. package/dist/core/tools/model-fitness.js.map +1 -1
  522. package/dist/core/tools/orchestration-panel.d.ts +43 -0
  523. package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
  524. package/dist/core/tools/orchestration-panel.js +168 -0
  525. package/dist/core/tools/orchestration-panel.js.map +1 -0
  526. package/dist/core/tools/run-process.d.ts +26 -0
  527. package/dist/core/tools/run-process.d.ts.map +1 -0
  528. package/dist/core/tools/run-process.js +138 -0
  529. package/dist/core/tools/run-process.js.map +1 -0
  530. package/dist/core/tools/task-steps.d.ts +2 -0
  531. package/dist/core/tools/task-steps.d.ts.map +1 -1
  532. package/dist/core/tools/task-steps.js +102 -0
  533. package/dist/core/tools/task-steps.js.map +1 -1
  534. package/dist/core/tools/tmux-dispatch.d.ts +3 -5
  535. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  536. package/dist/core/tools/tmux-dispatch.js +4 -4
  537. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  538. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  539. package/dist/core/tools/windows-shell-engine.js +4 -6
  540. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  541. package/dist/core/util/bounded-jsonl.d.ts +10 -0
  542. package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
  543. package/dist/core/util/bounded-jsonl.js +75 -0
  544. package/dist/core/util/bounded-jsonl.js.map +1 -0
  545. package/dist/core/util/value-guards.d.ts +5 -0
  546. package/dist/core/util/value-guards.d.ts.map +1 -0
  547. package/dist/core/util/value-guards.js +12 -0
  548. package/dist/core/util/value-guards.js.map +1 -0
  549. package/dist/core/worktree-sync/store.d.ts +3 -3
  550. package/dist/core/worktree-sync/store.d.ts.map +1 -1
  551. package/dist/core/worktree-sync/store.js +10 -5
  552. package/dist/core/worktree-sync/store.js.map +1 -1
  553. package/dist/index.d.ts +13 -3
  554. package/dist/index.d.ts.map +1 -1
  555. package/dist/index.js +12 -2
  556. package/dist/index.js.map +1 -1
  557. package/dist/main.d.ts.map +1 -1
  558. package/dist/main.js +128 -44
  559. package/dist/main.js.map +1 -1
  560. package/dist/migrations.d.ts +4 -6
  561. package/dist/migrations.d.ts.map +1 -1
  562. package/dist/migrations.js +186 -28
  563. package/dist/migrations.js.map +1 -1
  564. package/dist/modes/interactive/clipboard-input.d.ts +7 -1
  565. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  566. package/dist/modes/interactive/clipboard-input.js +44 -6
  567. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  568. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  569. package/dist/modes/interactive/components/settings-selector.js +2 -2
  570. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  571. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  572. package/dist/modes/interactive/config-backup.js +5 -4
  573. package/dist/modes/interactive/config-backup.js.map +1 -1
  574. package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
  575. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  576. package/dist/modes/interactive/extension-ui-host.js +76 -15
  577. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  578. package/dist/modes/interactive/interactive-mode.d.ts +3 -0
  579. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  580. package/dist/modes/interactive/interactive-mode.js +63 -1
  581. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  582. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  583. package/dist/modes/interactive/key-handlers.js +1 -1
  584. package/dist/modes/interactive/key-handlers.js.map +1 -1
  585. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  586. package/dist/modes/interactive/profile-menu-controller.js +7 -7
  587. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  588. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  589. package/dist/modes/interactive/report-commands.js +21 -0
  590. package/dist/modes/interactive/report-commands.js.map +1 -1
  591. package/dist/modes/interactive/session-flow-commands.d.ts +17 -2
  592. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  593. package/dist/modes/interactive/session-flow-commands.js +50 -17
  594. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  595. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  596. package/dist/modes/interactive/session-io-commands.js +16 -6
  597. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  598. package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
  599. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
  600. package/dist/modes/interactive/session-replacement-errors.js +15 -0
  601. package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
  602. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  603. package/dist/modes/interactive/startup-checks.js +1 -1
  604. package/dist/modes/interactive/startup-checks.js.map +1 -1
  605. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  606. package/dist/modes/rpc/rpc-mode.js +82 -23
  607. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  608. package/dist/modes/rpc/rpc-types.d.ts +15 -0
  609. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  610. package/dist/modes/rpc/rpc-types.js +138 -1
  611. package/dist/modes/rpc/rpc-types.js.map +1 -1
  612. package/dist/utils/clipboard-image.d.ts.map +1 -1
  613. package/dist/utils/clipboard-image.js +2 -13
  614. package/dist/utils/clipboard-image.js.map +1 -1
  615. package/dist/utils/clipboard-native.d.ts +1 -0
  616. package/dist/utils/clipboard-native.d.ts.map +1 -1
  617. package/dist/utils/clipboard-native.js.map +1 -1
  618. package/dist/utils/clipboard.d.ts +1 -0
  619. package/dist/utils/clipboard.d.ts.map +1 -1
  620. package/dist/utils/clipboard.js +52 -1
  621. package/dist/utils/clipboard.js.map +1 -1
  622. package/dist/utils/platform.d.ts +3 -0
  623. package/dist/utils/platform.d.ts.map +1 -0
  624. package/dist/utils/platform.js +8 -0
  625. package/dist/utils/platform.js.map +1 -0
  626. package/dist/utils/work-directory.d.ts +11 -0
  627. package/dist/utils/work-directory.d.ts.map +1 -1
  628. package/dist/utils/work-directory.js +30 -9
  629. package/dist/utils/work-directory.js.map +1 -1
  630. package/docs/UI_POLISH_ORCHESTRATION.md +44 -0
  631. package/docs/UI_QUALITY_ORCHESTRATION.md +30 -0
  632. package/docs/docs.json +4 -0
  633. package/docs/extensions.md +62 -2
  634. package/docs/harness-architecture.md +156 -0
  635. package/docs/keybindings.md +11 -1
  636. package/docs/process-matrix.md +59 -26
  637. package/docs/rpc.md +45 -2
  638. package/docs/sessions.md +15 -0
  639. package/docs/settings.md +125 -11
  640. package/docs/task-steps.md +8 -0
  641. package/docs/telemetry.md +19 -0
  642. package/docs/tmux-agent-manager.md +10 -3
  643. package/docs/ui-reference/README.md +9 -0
  644. package/docs/ui-reference/orchestration-after.txt +7 -0
  645. package/docs/ui-reference/orchestration-before.txt +7 -0
  646. package/docs/ui-reference/orchestration-reference.txt +6 -0
  647. package/docs/usage.md +14 -2
  648. package/docs/work-directory.md +19 -8
  649. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  650. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  651. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  652. package/examples/extensions/question.ts +34 -245
  653. package/examples/extensions/questionnaire.ts +41 -407
  654. package/examples/extensions/sandbox/package-lock.json +2 -2
  655. package/examples/extensions/sandbox/package.json +1 -1
  656. package/examples/extensions/with-deps/package-lock.json +2 -2
  657. package/examples/extensions/with-deps/package.json +1 -1
  658. package/npm-shrinkwrap.json +12 -12
  659. package/package.json +4 -4
  660. package/dist/core/delegation/session-worker-result.d.ts +0 -46
  661. package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
  662. package/dist/core/delegation/session-worker-result.js +0 -113
  663. package/dist/core/delegation/session-worker-result.js.map +0 -1
  664. package/dist/core/delegation/worker-result.d.ts.map +0 -1
  665. package/dist/core/delegation/worker-result.js.map +0 -1
  666. package/dist/core/telemetry.d.ts.map +0 -1
  667. package/dist/core/telemetry.js.map +0 -1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C,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY;aACrC,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,WAAW,CAAC;aAC3D,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACvC,OAAO,mCAAmC,CAAC,KAAK,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,EAAE,CAAC;AAAA,CACV","sourcesContent":["import {\n\tapplyGoalEvent,\n\tcreateGoalState,\n\ttype GoalEvent,\n\ttype GoalEvidenceKind,\n\ttype GoalState,\n} from \"./goal-state.ts\";\n\n/**\n * Agent-facing goal ledger actions.\n *\n * This is the producer half of the goal continuation pipeline: the agent records\n * what it is trying to achieve and how far it has gotten, and those records become\n * the {@link GoalState} snapshots that the runtime continuation consumer reads.\n *\n * Each action maps onto either {@link createGoalState} or a single\n * {@link GoalEvent}, so the durable state model stays the single source of truth.\n */\nexport type GoalAction =\n\t| { action: \"start\"; goalId: string; userGoal: string }\n\t| { action: \"add_requirement\"; requirementId: string; text: string }\n\t| { action: \"satisfy_requirement\"; requirementId: string; evidenceIds?: readonly string[] }\n\t| { action: \"block_requirement\"; requirementId: string; reason: string }\n\t| { action: \"reopen_requirement\"; requirementId: string }\n\t| {\n\t\t\taction: \"dispatch_worker\";\n\t\t\trequirementId: string;\n\t\t\tinstructions: string;\n\t\t\t/**\n\t\t\t * LaneId returned by the tool layer's dispatch side effect (calling the real worker/tmux\n\t\t\t * dispatch). Computed by the tool layer -- which has session/runtime access -- and merged\n\t\t\t * onto the action before it reaches this pure reducer, exactly like `add_evidence`'s\n\t\t\t * `verified` field. Undefined when the dispatch side effect is unwired/stubbed.\n\t\t\t */\n\t\t\tlaneId?: string;\n\t }\n\t| {\n\t\t\taction: \"add_evidence\";\n\t\t\tevidenceId: string;\n\t\t\tkind: GoalEvidenceKind;\n\t\t\tsummary: string;\n\t\t\turi?: string;\n\t\t\t/**\n\t\t\t * Whether `uri` was checked against session records/the filesystem. Computed by the\n\t\t\t * tool layer (which has session/filesystem access); `applyGoalAction` stays pure and\n\t\t\t * only carries this value through into the recorded {@link GoalEvidenceRef}.\n\t\t\t */\n\t\t\tverified?: boolean;\n\t }\n\t| { action: \"progress\" }\n\t| { action: \"no_progress\" }\n\t| { action: \"complete\" }\n\t| { action: \"block_goal\"; reason: string }\n\t| { action: \"resume_goal\" }\n\t| { action: \"cancel\" };\n\nexport type GoalActionName = GoalAction[\"action\"];\n\nexport interface GoalActionSuccess {\n\tok: true;\n\tstate: GoalState;\n}\n\nexport interface GoalActionFailure {\n\tok: false;\n\terror: string;\n}\n\nexport type GoalActionResult = GoalActionSuccess | GoalActionFailure;\n\nexport interface ApplyGoalActionOptions {\n\t/**\n\t * Gate agent-facing 'complete' on at least one satisfied requirement being backed by\n\t * verified-ref evidence (kind 'tool'/'file' with `verified === true`) or kind 'user'\n\t * evidence. Defaults to `true` (on) when omitted — the conservative default. Manual\n\t * completion ({@link completeGoalManually}) is never subject to this gate.\n\t */\n\trequireVerifiedEvidenceForCompletion?: boolean;\n}\n\nfunction requirementExists(state: GoalState, requirementId: string): boolean {\n\treturn state.requirements.some((requirement) => requirement.id === requirementId);\n}\n\nfunction evidenceExists(state: GoalState, evidenceId: string): boolean {\n\treturn state.evidence.some((evidence) => evidence.id === evidenceId);\n}\n\nfunction isVerifiedOrUserEvidence(evidence: GoalState[\"evidence\"][number]): boolean {\n\treturn evidence.kind === \"user\" || evidence.verified === true;\n}\n\n/** Does at least one SATISFIED requirement cite evidence that is verified-ref or kind:'user'? */\nfunction hasEvidenceBackedSatisfaction(state: GoalState): boolean {\n\treturn state.requirements.some((requirement) => {\n\t\tif (requirement.status !== \"satisfied\") return false;\n\t\treturn requirement.evidenceIds.some((evidenceId) => {\n\t\t\tconst evidence = state.evidence.find((candidate) => candidate.id === evidenceId);\n\t\t\treturn evidence !== undefined && isVerifiedOrUserEvidence(evidence);\n\t\t});\n\t});\n}\n\n/**\n * Apply one agent-facing goal action to the current ledger state.\n *\n * Pure: takes the current state (or `undefined` when no goal exists yet) and the\n * action, and returns either the next state or a validation error. Performs no\n * I/O and never mutates its inputs.\n */\nexport function applyGoalAction(\n\tcurrent: GoalState | undefined,\n\taction: GoalAction,\n\tnow: string,\n\toptions?: ApplyGoalActionOptions,\n): GoalActionResult {\n\tif (action.action === \"start\") {\n\t\tconst goalId = action.goalId.trim();\n\t\tconst userGoal = action.userGoal.trim();\n\t\tif (!goalId) return { ok: false, error: \"start requires a non-empty goalId.\" };\n\t\tif (!userGoal) return { ok: false, error: \"start requires a non-empty userGoal.\" };\n\t\tif (current && current.status === \"active\" && current.goalId !== goalId) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror: `An active goal '${current.goalId}' already exists. Complete, block, or cancel it before starting '${goalId}'.`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true, state: createGoalState({ goalId, userGoal, now }) };\n\t}\n\n\tif (!current) {\n\t\treturn { ok: false, error: \"No active goal. Use action 'start' before recording goal updates.\" };\n\t}\n\n\tif (action.action === \"resume_goal\") {\n\t\tif (current.status !== \"blocked\") {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror: `Goal '${current.goalId}' is ${current.status}; only blocked goals can be resumed.`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true, state: applyGoalEvent(current, { type: \"resume_goal\", now }) };\n\t}\n\n\tif (current.status !== \"active\") {\n\t\tif (current.status === \"blocked\" && action.action === \"cancel\") {\n\t\t\treturn { ok: true, state: applyGoalEvent(current, { type: \"cancel_goal\", now }) };\n\t\t}\n\t\tconst recovery =\n\t\t\tcurrent.status === \"blocked\"\n\t\t\t\t? \"Resume it with action 'resume_goal', cancel it, or start a replacement goal.\"\n\t\t\t\t: \"Start a new goal before recording updates.\";\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: `Goal '${current.goalId}' is ${current.status}. ${recovery}`,\n\t\t};\n\t}\n\n\tconst event = toGoalEvent(current, action, now, options);\n\tif (!event.ok) return event;\n\treturn { ok: true, state: applyGoalEvent(current, event.event) };\n}\n\ntype ToGoalEventResult = { ok: true; event: GoalEvent } | GoalActionFailure;\n\nfunction toGoalEvent(\n\tstate: GoalState,\n\taction: GoalAction,\n\tnow: string,\n\toptions: ApplyGoalActionOptions | undefined,\n): ToGoalEventResult {\n\tswitch (action.action) {\n\t\tcase \"add_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tconst text = action.text.trim();\n\t\t\tif (!id) return { ok: false, error: \"add_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!text) return { ok: false, error: \"add_requirement requires non-empty text.\" };\n\t\t\tif (requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Requirement '${id}' already exists.` };\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"add_requirement\", id, text, now } };\n\t\t}\n\t\tcase \"satisfy_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tif (!id) return { ok: false, error: \"satisfy_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\tconst evidenceIds = action.evidenceIds ?? [];\n\t\t\tfor (const evidenceId of evidenceIds) {\n\t\t\t\tif (!evidenceExists(state, evidenceId)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tok: false,\n\t\t\t\t\t\terror: `Unknown evidence '${evidenceId}'. Record it with action 'add_evidence' first.`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"satisfy_requirement\", id, evidenceIds: [...evidenceIds], now } };\n\t\t}\n\t\tcase \"block_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tconst reason = action.reason.trim();\n\t\t\tif (!id) return { ok: false, error: \"block_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!reason) return { ok: false, error: \"block_requirement requires a non-empty reason.\" };\n\t\t\tif (!requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"block_requirement\", id, blockedReason: reason, now } };\n\t\t}\n\t\tcase \"reopen_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tif (!id) return { ok: false, error: \"reopen_requirement requires a non-empty requirementId.\" };\n\t\t\tconst requirement = state.requirements.find((candidate) => candidate.id === id);\n\t\t\tif (!requirement) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\tif (requirement.status !== \"blocked\") {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `Requirement '${id}' is ${requirement.status}; only blocked requirements can be reopened.`,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"reopen_requirement\", id, now } };\n\t\t}\n\t\tcase \"dispatch_worker\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tconst instructions = action.instructions.trim();\n\t\t\tif (!id) return { ok: false, error: \"dispatch_worker requires a non-empty requirementId.\" };\n\t\t\tif (!instructions) return { ok: false, error: \"dispatch_worker requires non-empty instructions.\" };\n\t\t\tif (!requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"dispatch_worker\", id, instructions, laneId: action.laneId, now } };\n\t\t}\n\t\tcase \"add_evidence\": {\n\t\t\tconst id = action.evidenceId.trim();\n\t\t\tconst summary = action.summary.trim();\n\t\t\tif (!id) return { ok: false, error: \"add_evidence requires a non-empty evidenceId.\" };\n\t\t\tif (!summary) return { ok: false, error: \"add_evidence requires a non-empty summary.\" };\n\t\t\tif (evidenceExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Evidence '${id}' already exists.` };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tevent: {\n\t\t\t\t\ttype: \"add_evidence\",\n\t\t\t\t\tid,\n\t\t\t\t\tkind: action.kind,\n\t\t\t\t\tsummary,\n\t\t\t\t\turi: action.uri?.trim() || undefined,\n\t\t\t\t\tverified: action.verified,\n\t\t\t\t\tnow,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase \"progress\":\n\t\t\treturn { ok: true, event: { type: \"progress\", now } };\n\t\tcase \"no_progress\":\n\t\t\treturn { ok: true, event: { type: \"no_progress\", now } };\n\t\tcase \"complete\": {\n\t\t\tconst unsatisfied = state.requirements.filter((requirement) => requirement.status !== \"satisfied\");\n\t\t\tif (unsatisfied.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `Cannot complete goal: ${unsatisfied.length} requirement(s) not satisfied (${unsatisfied\n\t\t\t\t\t\t.map((requirement) => requirement.id)\n\t\t\t\t\t\t.join(\", \")}).`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst requireVerifiedEvidence = options?.requireVerifiedEvidenceForCompletion ?? true;\n\t\t\tif (requireVerifiedEvidence && !hasEvidenceBackedSatisfaction(state)) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: \"Cannot complete goal: no satisfied requirement is backed by verified evidence (kind 'tool'/'file' with a validated ref) or kind 'user' evidence. Record such evidence with 'add_evidence' and cite it in 'satisfy_requirement'.\",\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"complete_goal\", now } };\n\t\t}\n\t\tcase \"block_goal\": {\n\t\t\tconst reason = action.reason.trim();\n\t\t\tif (!reason) return { ok: false, error: \"block_goal requires a non-empty reason.\" };\n\t\t\treturn { ok: true, event: { type: \"block_goal\", reason, now } };\n\t\t}\n\t\tcase \"resume_goal\":\n\t\t\treturn { ok: true, event: { type: \"resume_goal\", now } };\n\t\tcase \"cancel\":\n\t\t\treturn { ok: true, event: { type: \"cancel_goal\", now } };\n\t\tdefault:\n\t\t\treturn { ok: false, error: \"Unknown goal action.\" };\n\t}\n}\n\n/**\n * Complete a goal on explicit user authority, even when requirements remain open or\n * blocked. Agent-facing `complete` stays evidence-gated; this path is reserved for\n * direct user lifecycle controls.\n */\nexport function completeGoalManually(current: GoalState | undefined, now: string): GoalActionResult {\n\tif (!current) {\n\t\treturn { ok: false, error: \"No goal exists to complete.\" };\n\t}\n\tif (current.status === \"completed\") {\n\t\treturn { ok: false, error: `Goal '${current.goalId}' is already completed.` };\n\t}\n\tif (current.status === \"cancelled\") {\n\t\treturn { ok: false, error: `Goal '${current.goalId}' is cancelled; start or override with a new goal.` };\n\t}\n\treturn { ok: true, state: applyGoalEvent(current, { type: \"complete_goal_manually\", now }) };\n}\n\n/** Render a compact human-readable summary of the ledger after an action. */\nexport function summarizeGoalState(\n\tstate: GoalState,\n\toptions?: { action?: GoalAction; openTaskSteps?: readonly OpenTaskStepRef[] },\n): string {\n\tconst open = state.requirements.filter((requirement) => requirement.status === \"open\").length;\n\tconst satisfied = state.requirements.filter((requirement) => requirement.status === \"satisfied\").length;\n\tconst blocked = state.requirements.filter((requirement) => requirement.status === \"blocked\").length;\n\tconst lines = [\n\t\t`Goal '${state.goalId}' (${state.status}): ${state.userGoal}`,\n\t\t`Requirements: ${state.requirements.length} total — ${open} open, ${satisfied} satisfied, ${blocked} blocked.`,\n\t\t`Evidence: ${state.evidence.length}. Stall turns: ${state.stallTurns}.`,\n\t];\n\tif (state.blockedReason) lines.push(`Blocked reason: ${state.blockedReason}`);\n\tif (options?.action) {\n\t\tlines.push(...buildGoalTaskCrossVisibilityNudges(options.action, state, options.openTaskSteps));\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Read-only goal⇄task cross-visibility (bounded slice — no shared state machine).\n *\n * `goal-tool-core` never reads or mutates task state itself (it stays pure); callers that DO\n * have access to the branch-scoped open task steps (e.g. via `buildGoalRuntimeSnapshot`) may\n * pass them through here to surface a nudge in the tool response when an open task_steps step\n * appears to reference a requirement the agent just satisfied or completed. Task state is never\n * written from goal code — this only reads an already-resolved, caller-supplied summary.\n */\nexport interface OpenTaskStepRef {\n\tid: string;\n\tcontent: string;\n}\n\nfunction escapeRegExp(text: string): string {\n\treturn text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Cheap, conservative cross-reference: an open task step \"references\" a requirement when its\n * content contains the requirement id as a whole token (not a substring of a longer token), or\n * contains the requirement's full text verbatim (case-insensitive). Both conditions are chosen\n * to avoid noisy partial-word matches -- a short common id or a coincidental few-word overlap\n * does not qualify.\n */\nfunction taskStepReferencesRequirement(step: OpenTaskStepRef, requirement: { id: string; text: string }): boolean {\n\tconst idToken = requirement.id.trim();\n\tif (idToken.length >= 2) {\n\t\tconst idPattern = new RegExp(`(^|[^a-z0-9])${escapeRegExp(idToken.toLocaleLowerCase())}([^a-z0-9]|$)`, \"i\");\n\t\tif (idPattern.test(step.content)) return true;\n\t}\n\tconst text = requirement.text.trim();\n\tif (text.length >= 8 && step.content.toLocaleLowerCase().includes(text.toLocaleLowerCase())) return true;\n\treturn false;\n}\n\n/**\n * Nudge lines for open task steps that reference any of `requirementIds` (deduped per\n * requirement, one line naming every referencing step). Empty when there is nothing to say.\n */\nexport function findRequirementCrossReferenceNudges(\n\tstate: GoalState,\n\trequirementIds: readonly string[],\n\topenTaskSteps: readonly OpenTaskStepRef[],\n): string[] {\n\tif (openTaskSteps.length === 0 || requirementIds.length === 0) return [];\n\tconst nudges: string[] = [];\n\tfor (const requirementId of requirementIds) {\n\t\tconst requirement = state.requirements.find((candidate) => candidate.id === requirementId);\n\t\tif (!requirement) continue;\n\t\tconst referencing = openTaskSteps.filter((step) => taskStepReferencesRequirement(step, requirement));\n\t\tif (referencing.length === 0) continue;\n\t\tconst stepList = referencing.map((step) => step.id).join(\", \");\n\t\tnudges.push(\n\t\t\t`Note: open task step(s) ${stepList} appear to reference satisfied requirement '${requirement.id}' -- consider updating them via task_steps once covered.`,\n\t\t);\n\t}\n\treturn nudges;\n}\n\n/**\n * After 'satisfy_requirement' or 'complete', nudge lines for open task steps whose content\n * references a just-satisfied requirement. Returns `[]` for every other action, or when\n * `openTaskSteps` was not supplied (the default -- backward compatible, no behavior change for\n * callers that do not pass task-step context).\n */\nexport function buildGoalTaskCrossVisibilityNudges(\n\taction: GoalAction,\n\tstate: GoalState,\n\topenTaskSteps: readonly OpenTaskStepRef[] | undefined,\n): string[] {\n\tif (!openTaskSteps || openTaskSteps.length === 0) return [];\n\tif (action.action === \"satisfy_requirement\") {\n\t\treturn findRequirementCrossReferenceNudges(state, [action.requirementId.trim()], openTaskSteps);\n\t}\n\tif (action.action === \"complete\") {\n\t\tconst satisfiedIds = state.requirements\n\t\t\t.filter((requirement) => requirement.status === \"satisfied\")\n\t\t\t.map((requirement) => requirement.id);\n\t\treturn findRequirementCrossReferenceNudges(state, satisfiedIds, openTaskSteps);\n\t}\n\treturn [];\n}\n"]}
1
+ {"version":3,"file":"goal-tool-core.js","sourceRoot":"","sources":["../../../src/core/goals/goal-tool-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EACN,cAAc,EACd,eAAe,GAIf,MAAM,iBAAiB,CAAC;AA0EzB,SAAS,iBAAiB,CAAC,KAAgB,EAAE,aAAqB,EAAW;IAC5E,OAAO,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,aAAa,CAAC,CAAC;AAAA,CAClF;AAED,SAAS,cAAc,CAAC,KAAgB,EAAE,UAAkB,EAAW;IACtE,OAAO,KAAK,CAAC,QAAQ,CAAC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C,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,6BAA6B,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;QACrG,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACvC,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/D,MAAM,CAAC,IAAI,CACV,2BAA2B,QAAQ,+CAA+C,WAAW,CAAC,EAAE,0DAA0D,CAC1J,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACd;AAED;;;;;GAKG;AACH,MAAM,UAAU,kCAAkC,CACjD,MAAkB,EAClB,KAAgB,EAChB,aAAqD,EAC1C;IACX,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC5D,IAAI,MAAM,CAAC,MAAM,KAAK,qBAAqB,EAAE,CAAC;QAC7C,OAAO,mCAAmC,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY;aACrC,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,WAAW,CAAC;aAC3D,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACvC,OAAO,mCAAmC,CAAC,KAAK,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,EAAE,CAAC;AAAA,CACV","sourcesContent":["import { taskStepReferencesRequirement } from \"../tasks/task-projection.ts\";\nimport { getUnprovenGoalRequirementIds } from \"./goal-acceptance.ts\";\nimport {\n\tapplyGoalEvent,\n\tcreateGoalState,\n\ttype GoalEvent,\n\ttype GoalEvidenceKind,\n\ttype GoalState,\n} from \"./goal-state.ts\";\n\n/**\n * Agent-facing goal ledger actions.\n *\n * This is the producer half of the goal continuation pipeline: the agent records\n * what it is trying to achieve and how far it has gotten, and those records become\n * the {@link GoalState} snapshots that the runtime continuation consumer reads.\n *\n * Each action maps onto either {@link createGoalState} or a single\n * {@link GoalEvent}, so the durable state model stays the single source of truth.\n */\nexport type GoalAction =\n\t| { action: \"start\"; goalId: string; userGoal: string }\n\t| { action: \"add_requirement\"; requirementId: string; text: string }\n\t| { action: \"satisfy_requirement\"; requirementId: string; evidenceIds?: readonly string[] }\n\t| { action: \"block_requirement\"; requirementId: string; reason: string }\n\t| { action: \"reopen_requirement\"; requirementId: string }\n\t| {\n\t\t\taction: \"dispatch_worker\";\n\t\t\trequirementId: string;\n\t\t\tinstructions: string;\n\t\t\t/**\n\t\t\t * LaneId returned by the tool layer's dispatch side effect (calling the real worker/tmux\n\t\t\t * dispatch). Computed by the tool layer -- which has session/runtime access -- and merged\n\t\t\t * onto the action before it reaches this pure reducer, exactly like `add_evidence`'s\n\t\t\t * `verified` field. Undefined when the dispatch side effect is unwired/stubbed.\n\t\t\t */\n\t\t\tlaneId?: string;\n\t }\n\t| {\n\t\t\taction: \"add_evidence\";\n\t\t\tevidenceId: string;\n\t\t\tkind: GoalEvidenceKind;\n\t\t\tsummary: string;\n\t\t\turi?: string;\n\t\t\t/**\n\t\t\t * Whether `uri` was checked against session records/the filesystem. Computed by the\n\t\t\t * tool layer (which has session/filesystem access); `applyGoalAction` stays pure and\n\t\t\t * only carries this value through into the recorded {@link GoalEvidenceRef}.\n\t\t\t */\n\t\t\tverified?: boolean;\n\t }\n\t| { action: \"progress\" }\n\t| { action: \"no_progress\" }\n\t| { action: \"complete\" }\n\t| { action: \"block_goal\"; reason: string }\n\t| { action: \"resume_goal\" }\n\t| { action: \"cancel\" };\n\nexport type GoalActionName = GoalAction[\"action\"];\n\nexport interface GoalActionSuccess {\n\tok: true;\n\tstate: GoalState;\n}\n\nexport interface GoalActionFailure {\n\tok: false;\n\terror: string;\n}\n\nexport type GoalActionResult = GoalActionSuccess | GoalActionFailure;\n\nexport interface ApplyGoalActionOptions {\n\t/**\n\t * Gate agent-facing 'complete' on every satisfied requirement being backed by\n\t * verified-ref evidence (kind 'tool'/'file' with `verified === true`) or kind 'user'\n\t * evidence. Defaults to `true` (on) when omitted — the conservative default. Manual\n\t * completion ({@link completeGoalManually}) is never subject to this gate.\n\t */\n\trequireVerifiedEvidenceForCompletion?: boolean;\n}\n\nfunction requirementExists(state: GoalState, requirementId: string): boolean {\n\treturn state.requirements.some((requirement) => requirement.id === requirementId);\n}\n\nfunction evidenceExists(state: GoalState, evidenceId: string): boolean {\n\treturn state.evidence.some((evidence) => evidence.id === evidenceId);\n}\n\n/**\n * Apply one agent-facing goal action to the current ledger state.\n *\n * Pure: takes the current state (or `undefined` when no goal exists yet) and the\n * action, and returns either the next state or a validation error. Performs no\n * I/O and never mutates its inputs.\n */\nexport function applyGoalAction(\n\tcurrent: GoalState | undefined,\n\taction: GoalAction,\n\tnow: string,\n\toptions?: ApplyGoalActionOptions,\n): GoalActionResult {\n\tif (action.action === \"start\") {\n\t\tconst goalId = action.goalId.trim();\n\t\tconst userGoal = action.userGoal.trim();\n\t\tif (!goalId) return { ok: false, error: \"start requires a non-empty goalId.\" };\n\t\tif (!userGoal) return { ok: false, error: \"start requires a non-empty userGoal.\" };\n\t\tif (current && current.status === \"active\" && current.goalId !== goalId) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror: `An active goal '${current.goalId}' already exists. Complete, block, or cancel it before starting '${goalId}'.`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true, state: createGoalState({ goalId, userGoal, now }) };\n\t}\n\n\tif (!current) {\n\t\treturn { ok: false, error: \"No active goal. Use action 'start' before recording goal updates.\" };\n\t}\n\n\tif (action.action === \"resume_goal\") {\n\t\tif (current.status !== \"blocked\") {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror: `Goal '${current.goalId}' is ${current.status}; only blocked goals can be resumed.`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true, state: applyGoalEvent(current, { type: \"resume_goal\", now }) };\n\t}\n\n\tif (current.status !== \"active\") {\n\t\tif (current.status === \"blocked\" && action.action === \"cancel\") {\n\t\t\treturn { ok: true, state: applyGoalEvent(current, { type: \"cancel_goal\", now }) };\n\t\t}\n\t\tconst recovery =\n\t\t\tcurrent.status === \"blocked\"\n\t\t\t\t? \"Resume it with action 'resume_goal', cancel it, or start a replacement goal.\"\n\t\t\t\t: \"Start a new goal before recording updates.\";\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: `Goal '${current.goalId}' is ${current.status}. ${recovery}`,\n\t\t};\n\t}\n\n\tconst event = toGoalEvent(current, action, now, options);\n\tif (!event.ok) return event;\n\treturn { ok: true, state: applyGoalEvent(current, event.event) };\n}\n\ntype ToGoalEventResult = { ok: true; event: GoalEvent } | GoalActionFailure;\n\nfunction toGoalEvent(\n\tstate: GoalState,\n\taction: GoalAction,\n\tnow: string,\n\toptions: ApplyGoalActionOptions | undefined,\n): ToGoalEventResult {\n\tswitch (action.action) {\n\t\tcase \"add_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tconst text = action.text.trim();\n\t\t\tif (!id) return { ok: false, error: \"add_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!text) return { ok: false, error: \"add_requirement requires non-empty text.\" };\n\t\t\tif (requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Requirement '${id}' already exists.` };\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"add_requirement\", id, text, now } };\n\t\t}\n\t\tcase \"satisfy_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tif (!id) return { ok: false, error: \"satisfy_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\tconst evidenceIds = action.evidenceIds ?? [];\n\t\t\tfor (const evidenceId of evidenceIds) {\n\t\t\t\tif (!evidenceExists(state, evidenceId)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tok: false,\n\t\t\t\t\t\terror: `Unknown evidence '${evidenceId}'. Record it with action 'add_evidence' first.`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"satisfy_requirement\", id, evidenceIds: [...evidenceIds], now } };\n\t\t}\n\t\tcase \"block_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tconst reason = action.reason.trim();\n\t\t\tif (!id) return { ok: false, error: \"block_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!reason) return { ok: false, error: \"block_requirement requires a non-empty reason.\" };\n\t\t\tif (!requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"block_requirement\", id, blockedReason: reason, now } };\n\t\t}\n\t\tcase \"reopen_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tif (!id) return { ok: false, error: \"reopen_requirement requires a non-empty requirementId.\" };\n\t\t\tconst requirement = state.requirements.find((candidate) => candidate.id === id);\n\t\t\tif (!requirement) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\tif (requirement.status !== \"blocked\") {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `Requirement '${id}' is ${requirement.status}; only blocked requirements can be reopened.`,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"reopen_requirement\", id, now } };\n\t\t}\n\t\tcase \"dispatch_worker\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tconst instructions = action.instructions.trim();\n\t\t\tif (!id) return { ok: false, error: \"dispatch_worker requires a non-empty requirementId.\" };\n\t\t\tif (!instructions) return { ok: false, error: \"dispatch_worker requires non-empty instructions.\" };\n\t\t\tif (!requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"dispatch_worker\", id, instructions, laneId: action.laneId, now } };\n\t\t}\n\t\tcase \"add_evidence\": {\n\t\t\tconst id = action.evidenceId.trim();\n\t\t\tconst summary = action.summary.trim();\n\t\t\tif (!id) return { ok: false, error: \"add_evidence requires a non-empty evidenceId.\" };\n\t\t\tif (!summary) return { ok: false, error: \"add_evidence requires a non-empty summary.\" };\n\t\t\tif (evidenceExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Evidence '${id}' already exists.` };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tevent: {\n\t\t\t\t\ttype: \"add_evidence\",\n\t\t\t\t\tid,\n\t\t\t\t\tkind: action.kind,\n\t\t\t\t\tsummary,\n\t\t\t\t\turi: action.uri?.trim() || undefined,\n\t\t\t\t\tverified: action.verified,\n\t\t\t\t\tnow,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase \"progress\":\n\t\t\treturn { ok: true, event: { type: \"progress\", now } };\n\t\tcase \"no_progress\":\n\t\t\treturn { ok: true, event: { type: \"no_progress\", now } };\n\t\tcase \"complete\": {\n\t\t\tconst unsatisfied = state.requirements.filter((requirement) => requirement.status !== \"satisfied\");\n\t\t\tif (unsatisfied.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `Cannot complete goal: ${unsatisfied.length} requirement(s) not satisfied (${unsatisfied\n\t\t\t\t\t\t.map((requirement) => requirement.id)\n\t\t\t\t\t\t.join(\", \")}).`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst requireVerifiedEvidence = options?.requireVerifiedEvidenceForCompletion ?? true;\n\t\t\tconst unprovenRequirementIds = getUnprovenGoalRequirementIds(state);\n\t\t\tif (requireVerifiedEvidence && unprovenRequirementIds.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `Cannot complete goal: requirement(s) lack verified evidence (${unprovenRequirementIds.join(\", \")}). Record verified or user-confirmed evidence and cite it in satisfy_requirement.`,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tevent: { type: \"complete_goal\", acceptanceOverride: !requireVerifiedEvidence, now },\n\t\t\t};\n\t\t}\n\t\tcase \"block_goal\": {\n\t\t\tconst reason = action.reason.trim();\n\t\t\tif (!reason) return { ok: false, error: \"block_goal requires a non-empty reason.\" };\n\t\t\treturn { ok: true, event: { type: \"block_goal\", reason, now } };\n\t\t}\n\t\tcase \"resume_goal\":\n\t\t\treturn { ok: true, event: { type: \"resume_goal\", now } };\n\t\tcase \"cancel\":\n\t\t\treturn { ok: true, event: { type: \"cancel_goal\", now } };\n\t\tdefault:\n\t\t\treturn { ok: false, error: \"Unknown goal action.\" };\n\t}\n}\n\n/**\n * Complete a goal on explicit user authority, even when requirements remain open or\n * blocked. Agent-facing `complete` stays evidence-gated; this path is reserved for\n * direct user lifecycle controls.\n */\nexport function completeGoalManually(current: GoalState | undefined, now: string): GoalActionResult {\n\tif (!current) {\n\t\treturn { ok: false, error: \"No goal exists to complete.\" };\n\t}\n\tif (current.status === \"completed\") {\n\t\treturn { ok: false, error: `Goal '${current.goalId}' is already completed.` };\n\t}\n\tif (current.status === \"cancelled\") {\n\t\treturn { ok: false, error: `Goal '${current.goalId}' is cancelled; start or override with a new goal.` };\n\t}\n\treturn { ok: true, state: applyGoalEvent(current, { type: \"complete_goal_manually\", now }) };\n}\n\n/** Render a compact human-readable summary of the ledger after an action. */\nexport function summarizeGoalState(\n\tstate: GoalState,\n\toptions?: { action?: GoalAction; openTaskSteps?: readonly OpenTaskStepRef[] },\n): string {\n\tconst open = state.requirements.filter((requirement) => requirement.status === \"open\").length;\n\tconst satisfied = state.requirements.filter((requirement) => requirement.status === \"satisfied\").length;\n\tconst blocked = state.requirements.filter((requirement) => requirement.status === \"blocked\").length;\n\tconst lines = [\n\t\t`Goal '${state.goalId}' (${state.status}): ${state.userGoal}`,\n\t\t`Requirements: ${state.requirements.length} total — ${open} open, ${satisfied} satisfied, ${blocked} blocked.`,\n\t\t`Evidence: ${state.evidence.length}. Stall turns: ${state.stallTurns}.`,\n\t];\n\tif (state.blockedReason) lines.push(`Blocked reason: ${state.blockedReason}`);\n\tif (options?.action) {\n\t\tlines.push(...buildGoalTaskCrossVisibilityNudges(options.action, state, options.openTaskSteps));\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Read-only goal⇄task cross-visibility (bounded slice — no shared state machine).\n *\n * `goal-tool-core` never reads or mutates task state itself (it stays pure); callers that DO\n * have access to the branch-scoped open task steps (e.g. via `buildGoalRuntimeSnapshot`) may\n * pass them through here to surface a nudge in the tool response when an open task_steps step is\n * explicitly linked to, or conservatively appears to reference, a requirement the agent just\n * satisfied or completed. Task state is never written from goal code — this only reads an\n * already-resolved, caller-supplied summary.\n */\nexport interface OpenTaskStepRef {\n\tid: string;\n\tcontent: string;\n\trequirementIds?: readonly string[];\n}\n\n/**\n * Nudge lines for open task steps that reference any of `requirementIds` (deduped per\n * requirement, one line naming every referencing step). Empty when there is nothing to say.\n */\nexport function findRequirementCrossReferenceNudges(\n\tstate: GoalState,\n\trequirementIds: readonly string[],\n\topenTaskSteps: readonly OpenTaskStepRef[],\n): string[] {\n\tif (openTaskSteps.length === 0 || requirementIds.length === 0) return [];\n\tconst nudges: string[] = [];\n\tfor (const requirementId of requirementIds) {\n\t\tconst requirement = state.requirements.find((candidate) => candidate.id === requirementId);\n\t\tif (!requirement) continue;\n\t\tconst referencing = openTaskSteps.filter((step) => taskStepReferencesRequirement(step, requirement));\n\t\tif (referencing.length === 0) continue;\n\t\tconst stepList = referencing.map((step) => step.id).join(\", \");\n\t\tnudges.push(\n\t\t\t`Note: open task step(s) ${stepList} appear to reference satisfied requirement '${requirement.id}' -- consider updating them via task_steps once covered.`,\n\t\t);\n\t}\n\treturn nudges;\n}\n\n/**\n * After 'satisfy_requirement' or 'complete', nudge lines for linked open task steps. Returns `[]`\n * for every other action, or when\n * `openTaskSteps` was not supplied (the default -- backward compatible, no behavior change for\n * callers that do not pass task-step context).\n */\nexport function buildGoalTaskCrossVisibilityNudges(\n\taction: GoalAction,\n\tstate: GoalState,\n\topenTaskSteps: readonly OpenTaskStepRef[] | undefined,\n): string[] {\n\tif (!openTaskSteps || openTaskSteps.length === 0) return [];\n\tif (action.action === \"satisfy_requirement\") {\n\t\treturn findRequirementCrossReferenceNudges(state, [action.requirementId.trim()], openTaskSteps);\n\t}\n\tif (action.action === \"complete\") {\n\t\tconst satisfiedIds = state.requirements\n\t\t\t.filter((requirement) => requirement.status === \"satisfied\")\n\t\t\t.map((requirement) => requirement.id);\n\t\treturn findRequirementCrossReferenceNudges(state, satisfiedIds, openTaskSteps);\n\t}\n\treturn [];\n}\n"]}
@@ -1,10 +1,8 @@
1
1
  import type { SessionManager } from "@caupulican/pi-agent-core/node";
2
+ import { type SessionSnapshotPayload } from "../session-snapshot.ts";
2
3
  import { type GoalState } from "./goal-state.ts";
3
4
  export declare const GOAL_STATE_CUSTOM_TYPE = "goal_state";
4
- export interface GoalStateSnapshotPayload {
5
- version: 1;
6
- state: GoalState;
7
- }
5
+ export type GoalStateSnapshotPayload = SessionSnapshotPayload<"state", GoalState>;
8
6
  export declare function appendGoalStateSnapshot(sessionManager: Pick<SessionManager, "appendCustomEntry">, state: GoalState): string;
9
7
  /** Pure payload decode: validates + clones a goal-state snapshot payload. No SessionManager access,
10
8
  * so unit tests can exercise decoding directly against a constructed `data` value. */
@@ -1 +1 @@
1
- {"version":3,"file":"session-goal-state.d.ts","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAA4B,KAAK,SAAS,EAAe,MAAM,iBAAiB,CAAC;AAExF,eAAO,MAAM,sBAAsB,eAAe,CAAC;AAEnD,MAAM,WAAW,wBAAwB;IACxC,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,GACd,MAAM,CAMR;AAQD;sFACsF;AACtF,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAOnF;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACzC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,8BAA8B,CAAC,GAClE,SAAS,GAAG,SAAS,CAUvB","sourcesContent":["import type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { cloneGoalStateForStorage, type GoalState, isGoalState } from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport interface GoalStateSnapshotPayload {\n\tversion: 1;\n\tstate: GoalState;\n}\n\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\tconst payload: GoalStateSnapshotPayload = {\n\t\tversion: 1,\n\t\tstate: cloneGoalStateForStorage(state),\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\n/** Pure payload decode: validates + clones a goal-state snapshot payload. No SessionManager access,\n * so unit tests can exercise decoding directly against a constructed `data` value. */\nexport function decodeGoalStateSnapshotPayload(data: unknown): GoalState | undefined {\n\tif (!isPlainRecord(data)) return undefined;\n\tif (data.version !== 1) return undefined;\n\tif (!(\"state\" in data)) return undefined;\n\tconst state = data.state;\n\tif (isGoalState(state)) return cloneGoalStateForStorage(state);\n\treturn undefined;\n}\n\n/**\n * Most recent VALID goal-state snapshot on the active branch. Walks leaf→root ancestry via\n * `getLatestCustomEntryOnBranch`, skipping entries whose payload fails to decode and resuming\n * the search from that entry's parent, so an older valid snapshot still wins over a newer\n * malformed one (matches the pre-branch-scoping flat-list resolution semantics).\n */\nexport function getLatestGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"getLatestCustomEntryOnBranch\">,\n): GoalState | undefined {\n\tlet fromId: string | undefined;\n\tfor (;;) {\n\t\tconst entry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE, fromId);\n\t\tif (!entry) return undefined;\n\t\tconst decoded = decodeGoalStateSnapshotPayload(entry.data);\n\t\tif (decoded !== undefined) return decoded;\n\t\tif (entry.parentId === null) return undefined;\n\t\tfromId = entry.parentId;\n\t}\n}\n"]}
1
+ {"version":3,"file":"session-goal-state.d.ts","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAKN,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA4B,KAAK,SAAS,EAAe,MAAM,iBAAiB,CAAC;AAExF,eAAO,MAAM,sBAAsB,eAAe,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AASlF,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,GACd,MAAM,CAER;AAED;sFACsF;AACtF,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAEnF;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACzC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,8BAA8B,CAAC,GAClE,SAAS,GAAG,SAAS,CAEvB","sourcesContent":["import type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tdecodeSessionSnapshotPayload,\n\tgetLatestSessionSnapshotOnBranch,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { cloneGoalStateForStorage, type GoalState, isGoalState } from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport type GoalStateSnapshotPayload = SessionSnapshotPayload<\"state\", GoalState>;\n\nconst GOAL_STATE_SNAPSHOT_CODEC: SessionSnapshotCodec<GoalState, \"state\"> = {\n\tcustomType: GOAL_STATE_CUSTOM_TYPE,\n\tvalueKey: \"state\",\n\tisValue: isGoalState,\n\tclone: cloneGoalStateForStorage,\n};\n\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\treturn appendSessionSnapshot(sessionManager, GOAL_STATE_SNAPSHOT_CODEC, state);\n}\n\n/** Pure payload decode: validates + clones a goal-state snapshot payload. No SessionManager access,\n * so unit tests can exercise decoding directly against a constructed `data` value. */\nexport function decodeGoalStateSnapshotPayload(data: unknown): GoalState | undefined {\n\treturn decodeSessionSnapshotPayload(data, GOAL_STATE_SNAPSHOT_CODEC);\n}\n\n/**\n * Most recent VALID goal-state snapshot on the active branch. Walks leaf→root ancestry via\n * `getLatestCustomEntryOnBranch`, skipping entries whose payload fails to decode and resuming\n * the search from that entry's parent, so an older valid snapshot still wins over a newer\n * malformed one (matches the pre-branch-scoping flat-list resolution semantics).\n */\nexport function getLatestGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"getLatestCustomEntryOnBranch\">,\n): GoalState | undefined {\n\treturn getLatestSessionSnapshotOnBranch(sessionManager, GOAL_STATE_SNAPSHOT_CODEC);\n}\n"]}
@@ -1,31 +1,19 @@
1
+ import { appendSessionSnapshot, decodeSessionSnapshotPayload, getLatestSessionSnapshotOnBranch, } from "../session-snapshot.js";
1
2
  import { cloneGoalStateForStorage, isGoalState } from "./goal-state.js";
2
3
  export const GOAL_STATE_CUSTOM_TYPE = "goal_state";
4
+ const GOAL_STATE_SNAPSHOT_CODEC = {
5
+ customType: GOAL_STATE_CUSTOM_TYPE,
6
+ valueKey: "state",
7
+ isValue: isGoalState,
8
+ clone: cloneGoalStateForStorage,
9
+ };
3
10
  export function appendGoalStateSnapshot(sessionManager, state) {
4
- const payload = {
5
- version: 1,
6
- state: cloneGoalStateForStorage(state),
7
- };
8
- return sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);
9
- }
10
- function isPlainRecord(value) {
11
- if (!value || typeof value !== "object" || Array.isArray(value))
12
- return false;
13
- const prototype = Object.getPrototypeOf(value);
14
- return prototype === Object.prototype || prototype === null;
11
+ return appendSessionSnapshot(sessionManager, GOAL_STATE_SNAPSHOT_CODEC, state);
15
12
  }
16
13
  /** Pure payload decode: validates + clones a goal-state snapshot payload. No SessionManager access,
17
14
  * so unit tests can exercise decoding directly against a constructed `data` value. */
18
15
  export function decodeGoalStateSnapshotPayload(data) {
19
- if (!isPlainRecord(data))
20
- return undefined;
21
- if (data.version !== 1)
22
- return undefined;
23
- if (!("state" in data))
24
- return undefined;
25
- const state = data.state;
26
- if (isGoalState(state))
27
- return cloneGoalStateForStorage(state);
28
- return undefined;
16
+ return decodeSessionSnapshotPayload(data, GOAL_STATE_SNAPSHOT_CODEC);
29
17
  }
30
18
  /**
31
19
  * Most recent VALID goal-state snapshot on the active branch. Walks leaf→root ancestry via
@@ -34,17 +22,6 @@ export function decodeGoalStateSnapshotPayload(data) {
34
22
  * malformed one (matches the pre-branch-scoping flat-list resolution semantics).
35
23
  */
36
24
  export function getLatestGoalStateSnapshot(sessionManager) {
37
- let fromId;
38
- for (;;) {
39
- const entry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE, fromId);
40
- if (!entry)
41
- return undefined;
42
- const decoded = decodeGoalStateSnapshotPayload(entry.data);
43
- if (decoded !== undefined)
44
- return decoded;
45
- if (entry.parentId === null)
46
- return undefined;
47
- fromId = entry.parentId;
48
- }
25
+ return getLatestSessionSnapshotOnBranch(sessionManager, GOAL_STATE_SNAPSHOT_CODEC);
49
26
  }
50
27
  //# sourceMappingURL=session-goal-state.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-goal-state.js","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAkB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAExF,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAY,CAAC;AAOnD,MAAM,UAAU,uBAAuB,CACtC,cAAyD,EACzD,KAAgB,EACP;IACT,MAAM,OAAO,GAA6B;QACzC,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,wBAAwB,CAAC,KAAK,CAAC;KACtC,CAAC;IACF,OAAO,cAAc,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;AAAA,CACzE;AAED,SAAS,aAAa,CAAC,KAAc,EAAoC;IACxE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAAA,CAC5D;AAED;sFACsF;AACtF,MAAM,UAAU,8BAA8B,CAAC,IAAa,EAAyB;IACpF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IACzB,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAC/D,OAAO,SAAS,CAAC;AAAA,CACjB;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACzC,cAAoE,EAC5C;IACxB,IAAI,MAA0B,CAAC;IAC/B,SAAS,CAAC;QACT,MAAM,KAAK,GAAG,cAAc,CAAC,4BAA4B,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,MAAM,OAAO,GAAG,8BAA8B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3D,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC;QAC1C,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;YAAE,OAAO,SAAS,CAAC;QAC9C,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC;IACzB,CAAC;AAAA,CACD","sourcesContent":["import type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { cloneGoalStateForStorage, type GoalState, isGoalState } from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport interface GoalStateSnapshotPayload {\n\tversion: 1;\n\tstate: GoalState;\n}\n\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\tconst payload: GoalStateSnapshotPayload = {\n\t\tversion: 1,\n\t\tstate: cloneGoalStateForStorage(state),\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\n/** Pure payload decode: validates + clones a goal-state snapshot payload. No SessionManager access,\n * so unit tests can exercise decoding directly against a constructed `data` value. */\nexport function decodeGoalStateSnapshotPayload(data: unknown): GoalState | undefined {\n\tif (!isPlainRecord(data)) return undefined;\n\tif (data.version !== 1) return undefined;\n\tif (!(\"state\" in data)) return undefined;\n\tconst state = data.state;\n\tif (isGoalState(state)) return cloneGoalStateForStorage(state);\n\treturn undefined;\n}\n\n/**\n * Most recent VALID goal-state snapshot on the active branch. Walks leaf→root ancestry via\n * `getLatestCustomEntryOnBranch`, skipping entries whose payload fails to decode and resuming\n * the search from that entry's parent, so an older valid snapshot still wins over a newer\n * malformed one (matches the pre-branch-scoping flat-list resolution semantics).\n */\nexport function getLatestGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"getLatestCustomEntryOnBranch\">,\n): GoalState | undefined {\n\tlet fromId: string | undefined;\n\tfor (;;) {\n\t\tconst entry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE, fromId);\n\t\tif (!entry) return undefined;\n\t\tconst decoded = decodeGoalStateSnapshotPayload(entry.data);\n\t\tif (decoded !== undefined) return decoded;\n\t\tif (entry.parentId === null) return undefined;\n\t\tfromId = entry.parentId;\n\t}\n}\n"]}
1
+ {"version":3,"file":"session-goal-state.js","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qBAAqB,EACrB,4BAA4B,EAC5B,gCAAgC,GAGhC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAkB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAExF,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAY,CAAC;AAInD,MAAM,yBAAyB,GAA6C;IAC3E,UAAU,EAAE,sBAAsB;IAClC,QAAQ,EAAE,OAAO;IACjB,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,wBAAwB;CAC/B,CAAC;AAEF,MAAM,UAAU,uBAAuB,CACtC,cAAyD,EACzD,KAAgB,EACP;IACT,OAAO,qBAAqB,CAAC,cAAc,EAAE,yBAAyB,EAAE,KAAK,CAAC,CAAC;AAAA,CAC/E;AAED;sFACsF;AACtF,MAAM,UAAU,8BAA8B,CAAC,IAAa,EAAyB;IACpF,OAAO,4BAA4B,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;AAAA,CACrE;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACzC,cAAoE,EAC5C;IACxB,OAAO,gCAAgC,CAAC,cAAc,EAAE,yBAAyB,CAAC,CAAC;AAAA,CACnF","sourcesContent":["import type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tdecodeSessionSnapshotPayload,\n\tgetLatestSessionSnapshotOnBranch,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { cloneGoalStateForStorage, type GoalState, isGoalState } from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport type GoalStateSnapshotPayload = SessionSnapshotPayload<\"state\", GoalState>;\n\nconst GOAL_STATE_SNAPSHOT_CODEC: SessionSnapshotCodec<GoalState, \"state\"> = {\n\tcustomType: GOAL_STATE_CUSTOM_TYPE,\n\tvalueKey: \"state\",\n\tisValue: isGoalState,\n\tclone: cloneGoalStateForStorage,\n};\n\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\treturn appendSessionSnapshot(sessionManager, GOAL_STATE_SNAPSHOT_CODEC, state);\n}\n\n/** Pure payload decode: validates + clones a goal-state snapshot payload. No SessionManager access,\n * so unit tests can exercise decoding directly against a constructed `data` value. */\nexport function decodeGoalStateSnapshotPayload(data: unknown): GoalState | undefined {\n\treturn decodeSessionSnapshotPayload(data, GOAL_STATE_SNAPSHOT_CODEC);\n}\n\n/**\n * Most recent VALID goal-state snapshot on the active branch. Walks leaf→root ancestry via\n * `getLatestCustomEntryOnBranch`, skipping entries whose payload fails to decode and resuming\n * the search from that entry's parent, so an older valid snapshot still wins over a newer\n * malformed one (matches the pre-branch-scoping flat-list resolution semantics).\n */\nexport function getLatestGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"getLatestCustomEntryOnBranch\">,\n): GoalState | undefined {\n\treturn getLatestSessionSnapshotOnBranch(sessionManager, GOAL_STATE_SNAPSHOT_CODEC);\n}\n"]}
@@ -0,0 +1,100 @@
1
+ import type { SessionEntry, SessionManager } from "@caupulican/pi-agent-core/node";
2
+ import type { ImageContent } from "@caupulican/pi-ai";
3
+ import type { ArtifactStore } from "./context/context-artifacts.ts";
4
+ import type { ContextArtifactRef } from "./context/context-item.ts";
5
+ import type { SessionImageStore } from "./session-image-store.ts";
6
+ import { type SessionBranchEntrySource } from "./session-snapshot.ts";
7
+ export declare const HUMAN_INPUT_CUSTOM_TYPE = "human_input_request";
8
+ export declare const HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE = "worker-owner-response";
9
+ export declare const HUMAN_INPUT_INLINE_BYTES: number;
10
+ export interface HumanInputOption {
11
+ label: string;
12
+ description: string;
13
+ }
14
+ export interface HumanInputQuestion {
15
+ id: string;
16
+ header: string;
17
+ question: string;
18
+ options: readonly HumanInputOption[];
19
+ multiSelect?: boolean;
20
+ }
21
+ export interface HumanInputAnswerImage {
22
+ label: string;
23
+ mimeType: string;
24
+ }
25
+ export interface HumanInputAnswer {
26
+ id: string;
27
+ header: string;
28
+ question: string;
29
+ selected: readonly string[];
30
+ /** Inline answer, or a bounded preview when customArtifact is present. */
31
+ custom?: string;
32
+ /** Exact full answer retained out of prompt context when it exceeds the inline bound. */
33
+ customArtifact?: ContextArtifactRef;
34
+ images?: readonly HumanInputAnswerImage[];
35
+ skipped: boolean;
36
+ }
37
+ export type HumanInputStopReason = "user_cancelled" | "ui_unavailable" | "interrupted" | "invalid_questions";
38
+ export interface HumanInputPresentationRequest {
39
+ requestId: string;
40
+ questions: readonly HumanInputQuestion[];
41
+ acceptsImages: boolean;
42
+ }
43
+ export interface HumanInputPresentationResult {
44
+ answers: readonly HumanInputAnswer[];
45
+ cancelled: boolean;
46
+ reason?: HumanInputStopReason;
47
+ imageContents: readonly ImageContent[];
48
+ }
49
+ export type HumanInputSource = "tool" | "worker";
50
+ export interface HumanInputRequest {
51
+ requestId: string;
52
+ source: HumanInputSource;
53
+ toolCallId?: string;
54
+ toolName?: string;
55
+ workerRequestId?: string;
56
+ questions: readonly HumanInputQuestion[];
57
+ acceptsImages: boolean;
58
+ createdAt: string;
59
+ }
60
+ export type HumanInputStatus = "pending" | "answered" | "cancelled";
61
+ export interface HumanInputSnapshot {
62
+ request: HumanInputRequest;
63
+ status: HumanInputStatus;
64
+ answers: readonly HumanInputAnswer[];
65
+ reason?: HumanInputStopReason;
66
+ updatedAt: string;
67
+ }
68
+ export interface HumanInputRequestOptions {
69
+ source: HumanInputSource;
70
+ toolCallId?: string;
71
+ toolName?: string;
72
+ workerRequestId?: string;
73
+ questions: readonly HumanInputQuestion[];
74
+ acceptsImages: boolean;
75
+ now?: () => string;
76
+ }
77
+ export interface ResolveHumanInputOptions {
78
+ sessionManager: Pick<SessionManager, "appendCustomEntry">;
79
+ request: HumanInputRequest;
80
+ present: (request: HumanInputPresentationRequest, options?: {
81
+ signal?: AbortSignal;
82
+ }) => Promise<HumanInputPresentationResult>;
83
+ artifactStore?: ArtifactStore;
84
+ getImageStore?: () => Pick<SessionImageStore, "retainContent"> | undefined;
85
+ signal?: AbortSignal;
86
+ now?: () => string;
87
+ }
88
+ export declare function createHumanInputRequest(options: HumanInputRequestOptions): HumanInputRequest;
89
+ export declare function appendHumanInputSnapshot(sessionManager: Pick<SessionManager, "appendCustomEntry">, snapshot: HumanInputSnapshot): string;
90
+ export declare function beginHumanInputRequest(sessionManager: Pick<SessionManager, "appendCustomEntry">, request: HumanInputRequest): HumanInputSnapshot;
91
+ export declare function getHumanInputSnapshots(entries: readonly SessionEntry[]): HumanInputSnapshot[];
92
+ export declare function getLatestHumanInputSnapshots(source: SessionBranchEntrySource): HumanInputSnapshot[];
93
+ export declare function getWorkerHumanInputsRequiringDelivery(source: SessionBranchEntrySource): HumanInputSnapshot[];
94
+ export declare function getResumableHumanInputSnapshot(source: SessionBranchEntrySource): HumanInputSnapshot | undefined;
95
+ export declare function resolveHumanInput(options: ResolveHumanInputOptions): Promise<{
96
+ snapshot: HumanInputSnapshot;
97
+ imageContents: readonly ImageContent[];
98
+ }>;
99
+ export declare function formatHumanInputAnswerText(snapshot: HumanInputSnapshot): string;
100
+ //# sourceMappingURL=human-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"human-input.d.ts","sourceRoot":"","sources":["../../src/core/human-input.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAiC,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAGrG,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAC7D,eAAO,MAAM,uCAAuC,0BAA0B,CAAC;AAC/E,eAAO,MAAM,wBAAwB,QAAY,CAAC;AAGlD,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IAClC,EAAE,EAAE,M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C,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAY5F;AAED,wBAAgB,wBAAwB,CACvC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,QAAQ,EAAE,kBAAkB,GAC1B,MAAM,CAGR;AAED,wBAAgB,sBAAsB,CACrC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,OAAO,EAAE,iBAAiB,GACxB,kBAAkB,CASpB;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,kBAAkB,EAAE,CAQ7F;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,wBAAwB,GAAG,kBAAkB,EAAE,CAMnG;AAED,wBAAgB,qCAAqC,CAAC,MAAM,EAAE,wBAAwB,GAAG,kBAAkB,EAAE,CAoB5G;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,wBAAwB,GAAG,kBAAkB,GAAG,SAAS,CAuB/G;AAiCD,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC;IACnF,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;CACvC,CAAC,CA+BD;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAkB/E","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { ImageContent } from \"@caupulican/pi-ai\";\nimport type { ArtifactStore } from \"./context/context-artifacts.ts\";\nimport type { ContextArtifactRef } from \"./context/context-item.ts\";\nimport type { SessionImageStore } from \"./session-image-store.ts\";\nimport { getActiveSessionBranchEntries, type SessionBranchEntrySource } from \"./session-snapshot.ts\";\nimport { isPlainRecord } from \"./util/value-guards.ts\";\n\nexport const HUMAN_INPUT_CUSTOM_TYPE = \"human_input_request\";\nexport const HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE = \"worker-owner-response\";\nexport const HUMAN_INPUT_INLINE_BYTES = 16 * 1024;\nconst HUMAN_INPUT_PREVIEW_CHARS = 4_000;\n\nexport interface HumanInputOption {\n\tlabel: string;\n\tdescription: string;\n}\n\nexport interface HumanInputQuestion {\n\tid: string;\n\theader: string;\n\tquestion: string;\n\toptions: readonly HumanInputOption[];\n\tmultiSelect?: boolean;\n}\n\nexport interface HumanInputAnswerImage {\n\tlabel: string;\n\tmimeType: string;\n}\n\nexport interface HumanInputAnswer {\n\tid: string;\n\theader: string;\n\tquestion: string;\n\tselected: readonly string[];\n\t/** Inline answer, or a bounded preview when customArtifact is present. */\n\tcustom?: string;\n\t/** Exact full answer retained out of prompt context when it exceeds the inline bound. */\n\tcustomArtifact?: ContextArtifactRef;\n\timages?: readonly HumanInputAnswerImage[];\n\tskipped: boolean;\n}\n\nexport type HumanInputStopReason = \"user_cancelled\" | \"ui_unavailable\" | \"interrupted\" | \"invalid_questions\";\n\nexport interface HumanInputPresentationRequest {\n\trequestId: string;\n\tquestions: readonly HumanInputQuestion[];\n\tacceptsImages: boolean;\n}\n\nexport interface HumanInputPresentationResult {\n\tanswers: readonly HumanInputAnswer[];\n\tcancelled: boolean;\n\treason?: HumanInputStopReason;\n\timageContents: readonly ImageContent[];\n}\n\nexport type HumanInputSource = \"tool\" | \"worker\";\n\nexport interface HumanInputRequest {\n\trequestId: string;\n\tsource: HumanInputSource;\n\ttoolCallId?: string;\n\ttoolName?: string;\n\tworkerRequestId?: string;\n\tquestions: readonly HumanInputQuestion[];\n\tacceptsImages: boolean;\n\tcreatedAt: string;\n}\n\nexport type HumanInputStatus = \"pending\" | \"answered\" | \"cancelled\";\n\nexport interface HumanInputSnapshot {\n\trequest: HumanInputRequest;\n\tstatus: HumanInputStatus;\n\tanswers: readonly HumanInputAnswer[];\n\treason?: HumanInputStopReason;\n\tupdatedAt: string;\n}\n\ninterface HumanInputSnapshotPayload {\n\tversion: 1;\n\tsnapshot: HumanInputSnapshot;\n}\n\nexport interface HumanInputRequestOptions {\n\tsource: HumanInputSource;\n\ttoolCallId?: string;\n\ttoolName?: string;\n\tworkerRequestId?: string;\n\tquestions: readonly HumanInputQuestion[];\n\tacceptsImages: boolean;\n\tnow?: () => string;\n}\n\nexport interface ResolveHumanInputOptions {\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">;\n\trequest: HumanInputRequest;\n\tpresent: (\n\t\trequest: HumanInputPresentationRequest,\n\t\toptions?: { signal?: AbortSignal },\n\t) => Promise<HumanInputPresentationResult>;\n\tartifactStore?: ArtifactStore;\n\tgetImageStore?: () => Pick<SessionImageStore, \"retainContent\"> | undefined;\n\tsignal?: AbortSignal;\n\tnow?: () => string;\n}\n\nfunction cloneQuestion(question: HumanInputQuestion): HumanInputQuestion {\n\treturn {\n\t\t...question,\n\t\toptions: question.options.map((option) => ({ ...option })),\n\t};\n}\n\nfunction cloneAnswer(answer: HumanInputAnswer): HumanInputAnswer {\n\treturn {\n\t\t...answer,\n\t\tselected: [...answer.selected],\n\t\tcustomArtifact: answer.customArtifact ? { ...answer.customArtifact } : undefined,\n\t\timages: answer.images?.map((image) => ({ ...image })),\n\t};\n}\n\nfunction cloneRequest(request: HumanInputRequest): HumanInputRequest {\n\treturn {\n\t\t...request,\n\t\tquestions: request.questions.map(cloneQuestion),\n\t};\n}\n\nfunction cloneSnapshot(snapshot: HumanInputSnapshot): HumanInputSnapshot {\n\treturn {\n\t\t...snapshot,\n\t\trequest: cloneRequest(snapshot.request),\n\t\tanswers: snapshot.answers.map(cloneAnswer),\n\t};\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n\treturn Array.isArray(value) && value.every((entry) => typeof entry === \"string\");\n}\n\nfunction isQuestion(value: unknown): value is HumanInputQuestion {\n\tif (!isPlainRecord(value) || !Array.isArray(value.options)) return false;\n\treturn (\n\t\ttypeof value.id === \"string\" &&\n\t\ttypeof value.header === \"string\" &&\n\t\ttypeof value.question === \"string\" &&\n\t\t(value.multiSelect === undefined || typeof value.multiSelect === \"boolean\") &&\n\t\tvalue.options.every(\n\t\t\t(option) =>\n\t\t\t\tisPlainRecord(option) && typeof option.label === \"string\" && typeof option.description === \"string\",\n\t\t)\n\t);\n}\n\nfunction isArtifactRef(value: unknown): value is ContextArtifactRef {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\ttypeof value.id === \"string\" &&\n\t\ttypeof value.kind === \"string\" &&\n\t\ttypeof value.byteLength === \"number\" &&\n\t\ttypeof value.createdAtTurn === \"number\" &&\n\t\ttypeof value.reproducible === \"boolean\"\n\t);\n}\n\nfunction isAnswer(value: unknown): value is HumanInputAnswer {\n\tif (!isPlainRecord(value)) return false;\n\treturn (\n\t\ttypeof value.id === \"string\" &&\n\t\ttypeof value.header === \"string\" &&\n\t\ttypeof value.question === \"string\" &&\n\t\tisStringArray(value.selected) &&\n\t\t(value.custom === undefined || typeof value.custom === \"string\") &&\n\t\t(value.customArtifact === undefined || isArtifactRef(value.customArtifact)) &&\n\t\t(value.images === undefined ||\n\t\t\t(Array.isArray(value.images) &&\n\t\t\t\tvalue.images.every(\n\t\t\t\t\t(image) => isPlainRecord(image) && typeof image.label === \"string\" && typeof image.mimeType === \"string\",\n\t\t\t\t))) &&\n\t\ttypeof value.skipped === \"boolean\"\n\t);\n}\n\nfunction isImageContent(value: unknown): value is ImageContent {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\tvalue.type === \"image\" &&\n\t\ttypeof value.data === \"string\" &&\n\t\ttypeof value.mimeType === \"string\"\n\t);\n}\n\nfunction normalizePresentationResult(request: HumanInputRequest, value: unknown): HumanInputPresentationResult {\n\tif (!isPlainRecord(value) || typeof value.cancelled !== \"boolean\") {\n\t\tthrow new Error(\"Invalid human-input response: expected a typed presentation result\");\n\t}\n\tif (value.cancelled) {\n\t\tconst reason = value.reason;\n\t\tif (\n\t\t\treason !== undefined &&\n\t\t\treason !== \"user_cancelled\" &&\n\t\t\treason !== \"ui_unavailable\" &&\n\t\t\treason !== \"interrupted\" &&\n\t\t\treason !== \"invalid_questions\"\n\t\t) {\n\t\t\tthrow new Error(\"Invalid human-input response: unknown cancellation reason\");\n\t\t}\n\t\treturn {\n\t\t\tanswers: [],\n\t\t\tcancelled: true,\n\t\t\t...(reason ? { reason } : {}),\n\t\t\timageContents: [],\n\t\t};\n\t}\n\tif (!Array.isArray(value.answers) || !Array.isArray(value.imageContents)) {\n\t\tthrow new Error(\"Invalid human-input response: answers and imageContents must be arrays\");\n\t}\n\tconst answersById = new Map<string, HumanInputAnswer>();\n\tfor (const candidate of value.answers) {\n\t\tif (!isAnswer(candidate)) throw new Error(\"Invalid human-input response: malformed answer\");\n\t\tif (candidate.customArtifact !== undefined) {\n\t\t\tthrow new Error(\"Invalid human-input response: artifact references are harness-owned\");\n\t\t}\n\t\tif (answersById.has(candidate.id)) {\n\t\t\tthrow new Error(`Invalid human-input response: duplicate answer '${candidate.id}'`);\n\t\t}\n\t\tanswersById.set(candidate.id, candidate);\n\t}\n\tif (answersById.size !== request.questions.length) {\n\t\tthrow new Error(\"Invalid human-input response: every question must have exactly one answer\");\n\t}\n\n\tconst answers = request.questions.map((question) => {\n\t\tconst answer = answersById.get(question.id);\n\t\tif (!answer) throw new Error(`Invalid human-input response: missing answer '${question.id}'`);\n\t\tconst optionLabels = new Set(question.options.map((option) => option.label));\n\t\tif (new Set(answer.selected).size !== answer.selected.length) {\n\t\t\tthrow new Error(`Invalid human-input response: duplicate option for '${question.id}'`);\n\t\t}\n\t\tif (answer.selected.some((selection) => !optionLabels.has(selection))) {\n\t\t\tthrow new Error(`Invalid human-input response: unknown option for '${question.id}'`);\n\t\t}\n\t\tif (!question.multiSelect && answer.selected.length > 1) {\n\t\t\tthrow new Error(`Invalid human-input response: '${question.id}' is single-select`);\n\t\t}\n\t\tif (\n\t\t\tanswer.skipped &&\n\t\t\t(answer.selected.length > 0 || Boolean(answer.custom) || (answer.images?.length ?? 0) > 0)\n\t\t) {\n\t\t\tthrow new Error(`Invalid human-input response: skipped answer '${question.id}' contains a value`);\n\t\t}\n\t\treturn {\n\t\t\t...cloneAnswer(answer),\n\t\t\theader: question.header,\n\t\t\tquestion: question.question,\n\t\t};\n\t});\n\tif (!value.imageContents.every(isImageContent)) {\n\t\tthrow new Error(\"Invalid human-input response: malformed image content\");\n\t}\n\tconst answerImages = answers.flatMap((answer) => answer.images ?? []);\n\tif (answerImages.length !== value.imageContents.length) {\n\t\tthrow new Error(\"Invalid human-input response: image metadata does not match image content\");\n\t}\n\tif (!request.acceptsImages && value.imageContents.length > 0) {\n\t\tthrow new Error(\"Invalid human-input response: the selected model does not accept images\");\n\t}\n\tfor (let index = 0; index < answerImages.length; index++) {\n\t\tif (answerImages[index]?.mimeType !== value.imageContents[index]?.mimeType) {\n\t\t\tthrow new Error(\"Invalid human-input response: image MIME metadata does not match image content\");\n\t\t}\n\t}\n\treturn {\n\t\tanswers,\n\t\tcancelled: false,\n\t\timageContents: value.imageContents.map((image) => ({ ...image })),\n\t};\n}\n\nfunction persistPresentationImages(\n\tresult: HumanInputPresentationResult,\n\timageStore: Pick<SessionImageStore, \"retainContent\"> | undefined,\n): HumanInputPresentationResult {\n\tif (!imageStore || result.cancelled || result.imageContents.length === 0) return result;\n\tlet imageIndex = 0;\n\tconst durableContents: ImageContent[] = [];\n\tconst answers = result.answers.map((answer) => {\n\t\tlet custom = answer.custom;\n\t\tconst images = answer.images?.map((image) => {\n\t\t\tconst content = result.imageContents[imageIndex++];\n\t\t\tif (!content) throw new Error(\"Human-input image metadata exceeds supplied image content\");\n\t\t\tconst sequenceMatch = /^\\[Image #(\\d{1,6})\\]$/iu.exec(image.label);\n\t\t\tconst stored = imageStore.retainContent(content, sequenceMatch ? Number(sequenceMatch[1]) : undefined);\n\t\t\tconst durableLabel = `[Image #${stored.sequence}]`;\n\t\t\tif (custom?.includes(image.label)) custom = custom.split(image.label).join(durableLabel);\n\t\t\tdurableContents.push({\n\t\t\t\ttype: \"image\",\n\t\t\t\tdata: Buffer.from(stored.bytes).toString(\"base64\"),\n\t\t\t\tmimeType: stored.mimeType,\n\t\t\t});\n\t\t\treturn { label: durableLabel, mimeType: stored.mimeType };\n\t\t});\n\t\treturn {\n\t\t\t...cloneAnswer(answer),\n\t\t\t...(custom !== undefined ? { custom } : {}),\n\t\t\t...(images && images.length > 0 ? { images } : {}),\n\t\t};\n\t});\n\treturn { ...result, answers, imageContents: durableContents };\n}\n\nfunction isRequest(value: unknown): value is HumanInputRequest {\n\tif (!isPlainRecord(value) || !Array.isArray(value.questions)) return false;\n\treturn (\n\t\ttypeof value.requestId === \"string\" &&\n\t\t(value.source === \"tool\" || value.source === \"worker\") &&\n\t\t(value.toolCallId === undefined || typeof value.toolCallId === \"string\") &&\n\t\t(value.toolName === undefined || typeof value.toolName === \"string\") &&\n\t\t(value.workerRequestId === undefined || typeof value.workerRequestId === \"string\") &&\n\t\tvalue.questions.every(isQuestion) &&\n\t\ttypeof value.acceptsImages === \"boolean\" &&\n\t\ttypeof value.createdAt === \"string\"\n\t);\n}\n\nfunction decodeSnapshot(data: unknown): HumanInputSnapshot | undefined {\n\tif (!isPlainRecord(data) || data.version !== 1 || !isPlainRecord(data.snapshot)) return undefined;\n\tconst snapshot = data.snapshot;\n\tif (\n\t\t!isRequest(snapshot.request) ||\n\t\t(snapshot.status !== \"pending\" && snapshot.status !== \"answered\" && snapshot.status !== \"cancelled\") ||\n\t\t!Array.isArray(snapshot.answers) ||\n\t\t!snapshot.answers.every(isAnswer) ||\n\t\t(snapshot.reason !== undefined &&\n\t\t\tsnapshot.reason !== \"user_cancelled\" &&\n\t\t\tsnapshot.reason !== \"ui_unavailable\" &&\n\t\t\tsnapshot.reason !== \"interrupted\" &&\n\t\t\tsnapshot.reason !== \"invalid_questions\") ||\n\t\ttypeof snapshot.updatedAt !== \"string\"\n\t) {\n\t\treturn undefined;\n\t}\n\treturn cloneSnapshot(snapshot as unknown as HumanInputSnapshot);\n}\n\nexport function createHumanInputRequest(options: HumanInputRequestOptions): HumanInputRequest {\n\tconst now = options.now?.() ?? new Date().toISOString();\n\treturn {\n\t\trequestId: `human-input:${options.toolCallId ?? options.workerRequestId ?? randomUUID()}`,\n\t\tsource: options.source,\n\t\t...(options.toolCallId ? { toolCallId: options.toolCallId } : {}),\n\t\t...(options.toolName ? { toolName: options.toolName } : {}),\n\t\t...(options.workerRequestId ? { workerRequestId: options.workerRequestId } : {}),\n\t\tquestions: options.questions.map(cloneQuestion),\n\t\tacceptsImages: options.acceptsImages,\n\t\tcreatedAt: now,\n\t};\n}\n\nexport function appendHumanInputSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tsnapshot: HumanInputSnapshot,\n): string {\n\tconst payload: HumanInputSnapshotPayload = { version: 1, snapshot: cloneSnapshot(snapshot) };\n\treturn sessionManager.appendCustomEntry(HUMAN_INPUT_CUSTOM_TYPE, payload);\n}\n\nexport function beginHumanInputRequest(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trequest: HumanInputRequest,\n): HumanInputSnapshot {\n\tconst snapshot: HumanInputSnapshot = {\n\t\trequest: cloneRequest(request),\n\t\tstatus: \"pending\",\n\t\tanswers: [],\n\t\tupdatedAt: request.createdAt,\n\t};\n\tappendHumanInputSnapshot(sessionManager, snapshot);\n\treturn snapshot;\n}\n\nexport function getHumanInputSnapshots(entries: readonly SessionEntry[]): HumanInputSnapshot[] {\n\tconst snapshots: HumanInputSnapshot[] = [];\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== HUMAN_INPUT_CUSTOM_TYPE) continue;\n\t\tconst snapshot = decodeSnapshot(entry.data);\n\t\tif (snapshot) snapshots.push(snapshot);\n\t}\n\treturn snapshots;\n}\n\nexport function getLatestHumanInputSnapshots(source: SessionBranchEntrySource): HumanInputSnapshot[] {\n\tconst latest = new Map<string, HumanInputSnapshot>();\n\tfor (const snapshot of getHumanInputSnapshots(getActiveSessionBranchEntries(source))) {\n\t\tlatest.set(snapshot.request.requestId, snapshot);\n\t}\n\treturn [...latest.values()];\n}\n\nexport function getWorkerHumanInputsRequiringDelivery(source: SessionBranchEntrySource): HumanInputSnapshot[] {\n\tconst entries = getActiveSessionBranchEntries(source);\n\tconst deliveredRequestIds = new Set(\n\t\tentries.flatMap((entry) => {\n\t\t\tif (\n\t\t\t\tentry.type !== \"custom_message\" ||\n\t\t\t\tentry.customType !== HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE ||\n\t\t\t\t!isPlainRecord(entry.details) ||\n\t\t\t\ttypeof entry.details.requestId !== \"string\"\n\t\t\t) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn [entry.details.requestId];\n\t\t}),\n\t);\n\treturn getLatestHumanInputSnapshots(source)\n\t\t.filter(\n\t\t\t(snapshot) => snapshot.request.source === \"worker\" && !deliveredRequestIds.has(snapshot.request.requestId),\n\t\t)\n\t\t.sort((left, right) => left.updatedAt.localeCompare(right.updatedAt));\n}\n\nexport function getResumableHumanInputSnapshot(source: SessionBranchEntrySource): HumanInputSnapshot | undefined {\n\tconst entries = getActiveSessionBranchEntries(source);\n\tconst requestedToolCalls = new Set(\n\t\tentries.flatMap((entry) =>\n\t\t\tentry.type === \"message\" && entry.message.role === \"assistant\"\n\t\t\t\t? entry.message.content.flatMap((part) => (part.type === \"toolCall\" ? [part.id] : []))\n\t\t\t\t: [],\n\t\t),\n\t);\n\tconst answeredToolCalls = new Set(\n\t\tentries.flatMap((entry) =>\n\t\t\tentry.type === \"message\" && entry.message.role === \"toolResult\" ? [entry.message.toolCallId] : [],\n\t\t),\n\t);\n\treturn getLatestHumanInputSnapshots(source)\n\t\t.filter(\n\t\t\t(snapshot) =>\n\t\t\t\tsnapshot.request.source === \"tool\" &&\n\t\t\t\tsnapshot.request.toolCallId !== undefined &&\n\t\t\t\trequestedToolCalls.has(snapshot.request.toolCallId) &&\n\t\t\t\t!answeredToolCalls.has(snapshot.request.toolCallId),\n\t\t)\n\t\t.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt))[0];\n}\n\nfunction preview(value: string): string {\n\tif (value.length <= HUMAN_INPUT_PREVIEW_CHARS) return value;\n\treturn `${value.slice(0, HUMAN_INPUT_PREVIEW_CHARS)}…`;\n}\n\nfunction externalizeAnswer(\n\trequest: HumanInputRequest,\n\tanswer: HumanInputAnswer,\n\tartifactStore: ArtifactStore | undefined,\n): HumanInputAnswer {\n\tif (!answer.custom || Buffer.byteLength(answer.custom, \"utf8\") <= HUMAN_INPUT_INLINE_BYTES || !artifactStore) {\n\t\treturn cloneAnswer(answer);\n\t}\n\tconst record = artifactStore.write({\n\t\tkind: \"transcript_slice\",\n\t\tcontent: answer.custom,\n\t\ttoolName: request.toolName ?? \"human_input\",\n\t\tsessionEntryId: request.requestId,\n\t\tcreatedAtTurn: 0,\n\t\treproducible: false,\n\t});\n\tif (!artifactStore.addReference(record.ref.id, request.requestId)) {\n\t\tthrow new Error(`Failed to retain human-input artifact ${record.ref.id}`);\n\t}\n\treturn {\n\t\t...cloneAnswer(answer),\n\t\tcustom: preview(answer.custom),\n\t\tcustomArtifact: record.ref,\n\t};\n}\n\nexport async function resolveHumanInput(options: ResolveHumanInputOptions): Promise<{\n\tsnapshot: HumanInputSnapshot;\n\timageContents: readonly ImageContent[];\n}> {\n\tconst now = options.now ?? (() => new Date().toISOString());\n\tlet result: HumanInputPresentationResult;\n\tif (options.signal?.aborted) {\n\t\tresult = { answers: [], cancelled: true, reason: \"interrupted\", imageContents: [] };\n\t} else {\n\t\tresult = persistPresentationImages(\n\t\t\tnormalizePresentationResult(\n\t\t\t\toptions.request,\n\t\t\t\tawait options.present(\n\t\t\t\t\t{\n\t\t\t\t\t\trequestId: options.request.requestId,\n\t\t\t\t\t\tquestions: options.request.questions,\n\t\t\t\t\t\tacceptsImages: options.request.acceptsImages,\n\t\t\t\t\t},\n\t\t\t\t\t{ signal: options.signal },\n\t\t\t\t),\n\t\t\t),\n\t\t\toptions.getImageStore?.(),\n\t\t);\n\t}\n\tconst answers = result.answers.map((answer) => externalizeAnswer(options.request, answer, options.artifactStore));\n\tconst snapshot: HumanInputSnapshot = {\n\t\trequest: cloneRequest(options.request),\n\t\tstatus: result.cancelled ? \"cancelled\" : \"answered\",\n\t\tanswers,\n\t\t...(result.reason ? { reason: result.reason } : {}),\n\t\tupdatedAt: now(),\n\t};\n\tappendHumanInputSnapshot(options.sessionManager, snapshot);\n\treturn { snapshot, imageContents: result.cancelled ? [] : result.imageContents };\n}\n\nexport function formatHumanInputAnswerText(snapshot: HumanInputSnapshot): string {\n\tif (snapshot.status === \"cancelled\") {\n\t\treturn snapshot.reason === \"interrupted\"\n\t\t\t? \"User question was interrupted.\"\n\t\t\t: snapshot.reason === \"ui_unavailable\"\n\t\t\t\t? \"User input is unavailable in this host.\"\n\t\t\t\t: \"User cancelled the question without submitting answers.\";\n\t}\n\treturn snapshot.answers\n\t\t.map((answer) => {\n\t\t\tif (answer.skipped) return `${answer.header}: user skipped this question`;\n\t\t\tconst values = [...answer.selected, ...(answer.custom ? [answer.custom] : [])];\n\t\t\tconst artifact = answer.customArtifact\n\t\t\t\t? `\\nFull answer: artifact tool-output:${answer.customArtifact.id} (${answer.customArtifact.byteLength} bytes)`\n\t\t\t\t: \"\";\n\t\t\treturn `${answer.header}: ${values.length > 1 ? \"user selected\" : \"user answered\"}: ${values.join(\", \")}${artifact}`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n"]}