@caupulican/pi-adaptative 0.81.38 → 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 (881) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/README.md +2 -0
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/README.md +18 -1
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +133 -0
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -0
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +198 -0
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -0
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +311 -0
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +31 -2
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +823 -79
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  13. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +1043 -86
  14. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/__init__.py +43 -0
  15. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/fs.py +270 -0
  16. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/search.py +252 -0
  17. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/strings.py +399 -0
  18. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +575 -0
  19. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +52 -0
  20. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +49 -0
  21. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +734 -0
  22. package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +238 -0
  23. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +132 -0
  24. package/dist/bundled-resources/runtimes/pi-shell-engine/nodes.py +116 -0
  25. package/dist/bundled-resources/runtimes/pi-shell-engine/parser.py +287 -0
  26. package/dist/bundled-resources/runtimes/pi-shell-engine/proc.py +137 -0
  27. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +100 -0
  28. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +579 -0
  29. package/dist/bundled-resources/skills/tool-call-repair/SKILL.md +19 -9
  30. package/dist/bundled-resources/skills/tool-call-repair/references/failure-grammar.md +22 -5
  31. package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +7 -7
  32. package/dist/bundled-resources/skills/tool-call-repair/references/text-protocol-grammar.md +28 -7
  33. package/dist/cli/args.d.ts +5 -0
  34. package/dist/cli/args.d.ts.map +1 -1
  35. package/dist/cli/args.js +24 -0
  36. package/dist/cli/args.js.map +1 -1
  37. package/dist/core/agent-directory-layout.d.ts +15 -0
  38. package/dist/core/agent-directory-layout.d.ts.map +1 -0
  39. package/dist/core/agent-directory-layout.js +72 -0
  40. package/dist/core/agent-directory-layout.js.map +1 -0
  41. package/dist/core/agent-paths.d.ts +66 -0
  42. package/dist/core/agent-paths.d.ts.map +1 -0
  43. package/dist/core/agent-paths.js +170 -0
  44. package/dist/core/agent-paths.js.map +1 -0
  45. package/dist/core/agent-session-runtime.d.ts +52 -8
  46. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  47. package/dist/core/agent-session-runtime.js +397 -79
  48. package/dist/core/agent-session-runtime.js.map +1 -1
  49. package/dist/core/agent-session-services.d.ts +1 -0
  50. package/dist/core/agent-session-services.d.ts.map +1 -1
  51. package/dist/core/agent-session-services.js +4 -3
  52. package/dist/core/agent-session-services.js.map +1 -1
  53. package/dist/core/agent-session.d.ts +255 -103
  54. package/dist/core/agent-session.d.ts.map +1 -1
  55. package/dist/core/agent-session.js +754 -1173
  56. package/dist/core/agent-session.js.map +1 -1
  57. package/dist/core/autonomy/approval-gate.d.ts +3 -2
  58. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  59. package/dist/core/autonomy/approval-gate.js +6 -28
  60. package/dist/core/autonomy/approval-gate.js.map +1 -1
  61. package/dist/core/autonomy/bounded-completion.d.ts +1 -1
  62. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  63. package/dist/core/autonomy/bounded-completion.js +1 -1
  64. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  65. package/dist/core/autonomy/contracts.d.ts +26 -9
  66. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  67. package/dist/core/autonomy/contracts.js.map +1 -1
  68. package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
  69. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  70. package/dist/core/autonomy/foreground-envelope.js +8 -25
  71. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  72. package/dist/core/autonomy/gates.d.ts.map +1 -1
  73. package/dist/core/autonomy/gates.js +8 -10
  74. package/dist/core/autonomy/gates.js.map +1 -1
  75. package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
  76. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
  77. package/dist/core/autonomy/lane-private-paths.js +16 -0
  78. package/dist/core/autonomy/lane-private-paths.js.map +1 -0
  79. package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
  80. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  81. package/dist/core/autonomy/lane-tool-surface.js +46 -8
  82. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  83. package/dist/core/autonomy/lane-tracker.d.ts +24 -1
  84. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  85. package/dist/core/autonomy/lane-tracker.js +43 -1
  86. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  87. package/dist/core/autonomy/risk-assessment.d.ts +1 -2
  88. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  89. package/dist/core/autonomy/risk-assessment.js +1 -123
  90. package/dist/core/autonomy/risk-assessment.js.map +1 -1
  91. package/dist/core/autonomy/session-lane-record.d.ts +4 -4
  92. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  93. package/dist/core/autonomy/session-lane-record.js +16 -29
  94. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  95. package/dist/core/autonomy/telemetry-events.d.ts +1 -1
  96. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  97. package/dist/core/autonomy/telemetry-events.js +1 -1
  98. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  99. package/dist/core/autonomy-telemetry.d.ts +7 -7
  100. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  101. package/dist/core/autonomy-telemetry.js +9 -9
  102. package/dist/core/autonomy-telemetry.js.map +1 -1
  103. package/dist/core/background-lane-controller.d.ts +90 -156
  104. package/dist/core/background-lane-controller.d.ts.map +1 -1
  105. package/dist/core/background-lane-controller.js +192 -968
  106. package/dist/core/background-lane-controller.js.map +1 -1
  107. package/dist/core/bash-execution-controller.d.ts +4 -0
  108. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  109. package/dist/core/bash-execution-controller.js +7 -1
  110. package/dist/core/bash-execution-controller.js.map +1 -1
  111. package/dist/core/capability-contract.d.ts +4 -0
  112. package/dist/core/capability-contract.d.ts.map +1 -0
  113. package/dist/core/capability-contract.js +28 -0
  114. package/dist/core/capability-contract.js.map +1 -0
  115. package/dist/core/compaction-controller.d.ts +90 -0
  116. package/dist/core/compaction-controller.d.ts.map +1 -0
  117. package/dist/core/compaction-controller.js +452 -0
  118. package/dist/core/compaction-controller.js.map +1 -0
  119. package/dist/core/compaction-support.d.ts +24 -13
  120. package/dist/core/compaction-support.d.ts.map +1 -1
  121. package/dist/core/compaction-support.js +43 -7
  122. package/dist/core/compaction-support.js.map +1 -1
  123. package/dist/core/context/context-artifacts.d.ts +6 -2
  124. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  125. package/dist/core/context/context-artifacts.js +34 -2
  126. package/dist/core/context/context-artifacts.js.map +1 -1
  127. package/dist/core/context/context-audit.d.ts +33 -1
  128. package/dist/core/context/context-audit.d.ts.map +1 -1
  129. package/dist/core/context/context-audit.js +31 -5
  130. package/dist/core/context/context-audit.js.map +1 -1
  131. package/dist/core/context/context-store-retention.d.ts +8 -2
  132. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  133. package/dist/core/context/context-store-retention.js +158 -35
  134. package/dist/core/context/context-store-retention.js.map +1 -1
  135. package/dist/core/context/okf-memory.d.ts.map +1 -1
  136. package/dist/core/context/okf-memory.js +9 -11
  137. package/dist/core/context/okf-memory.js.map +1 -1
  138. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  139. package/dist/core/context/sqlite-runtime-index.js +6 -8
  140. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  141. package/dist/core/context-gc.d.ts +3 -0
  142. package/dist/core/context-gc.d.ts.map +1 -1
  143. package/dist/core/context-gc.js +26 -6
  144. package/dist/core/context-gc.js.map +1 -1
  145. package/dist/core/context-pipeline.d.ts +26 -4
  146. package/dist/core/context-pipeline.d.ts.map +1 -1
  147. package/dist/core/context-pipeline.js +146 -18
  148. package/dist/core/context-pipeline.js.map +1 -1
  149. package/dist/core/cost-guard.d.ts +19 -3
  150. package/dist/core/cost-guard.d.ts.map +1 -1
  151. package/dist/core/cost-guard.js +18 -3
  152. package/dist/core/cost-guard.js.map +1 -1
  153. package/dist/core/default-tool-surface.d.ts.map +1 -1
  154. package/dist/core/default-tool-surface.js +1 -0
  155. package/dist/core/default-tool-surface.js.map +1 -1
  156. package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
  157. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
  158. package/dist/core/delegation/managed-lane-controller.js +217 -0
  159. package/dist/core/delegation/managed-lane-controller.js.map +1 -0
  160. package/dist/core/delegation/session-worker-claim.d.ts +44 -0
  161. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
  162. package/dist/core/delegation/session-worker-claim.js +98 -0
  163. package/dist/core/delegation/session-worker-claim.js.map +1 -0
  164. package/dist/core/delegation/worker-actions.d.ts +7 -5
  165. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  166. package/dist/core/delegation/worker-actions.js +20 -4
  167. package/dist/core/delegation/worker-actions.js.map +1 -1
  168. package/dist/core/delegation/worker-claim.d.ts +56 -0
  169. package/dist/core/delegation/worker-claim.d.ts.map +1 -0
  170. package/dist/core/delegation/worker-claim.js +239 -0
  171. package/dist/core/delegation/worker-claim.js.map +1 -0
  172. package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
  173. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
  174. package/dist/core/delegation/worker-delegation-controller.js +861 -0
  175. package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
  176. package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
  177. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
  178. package/dist/core/delegation/worker-delegation-request.js +2 -0
  179. package/dist/core/delegation/worker-delegation-request.js.map +1 -0
  180. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
  181. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
  182. package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
  183. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
  184. package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
  185. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
  186. package/dist/core/delegation/worker-execution-policy.js +160 -0
  187. package/dist/core/delegation/worker-execution-policy.js.map +1 -0
  188. package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
  189. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
  190. package/dist/core/delegation/worker-lane-projection.js +100 -0
  191. package/dist/core/delegation/worker-lane-projection.js.map +1 -0
  192. package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
  193. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
  194. package/dist/core/delegation/worker-lifecycle.js +339 -0
  195. package/dist/core/delegation/worker-lifecycle.js.map +1 -0
  196. package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
  197. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
  198. package/dist/core/delegation/worker-notification-coordinator.js +90 -0
  199. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
  200. package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
  201. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
  202. package/dist/core/delegation/worker-profile-resolver.js +113 -0
  203. package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
  204. package/dist/core/delegation/worker-runner.d.ts +25 -14
  205. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  206. package/dist/core/delegation/worker-runner.js +122 -53
  207. package/dist/core/delegation/worker-runner.js.map +1 -1
  208. package/dist/core/delegation/worker-task-label.d.ts +3 -0
  209. package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
  210. package/dist/core/delegation/worker-task-label.js +11 -0
  211. package/dist/core/delegation/worker-task-label.js.map +1 -0
  212. package/dist/core/doctor.d.ts +8 -0
  213. package/dist/core/doctor.d.ts.map +1 -1
  214. package/dist/core/doctor.js +32 -1
  215. package/dist/core/doctor.js.map +1 -1
  216. package/dist/core/extensions/index.d.ts +1 -1
  217. package/dist/core/extensions/index.d.ts.map +1 -1
  218. package/dist/core/extensions/index.js.map +1 -1
  219. package/dist/core/extensions/loader.d.ts +5 -1
  220. package/dist/core/extensions/loader.d.ts.map +1 -1
  221. package/dist/core/extensions/loader.js +68 -13
  222. package/dist/core/extensions/loader.js.map +1 -1
  223. package/dist/core/extensions/runner.d.ts.map +1 -1
  224. package/dist/core/extensions/runner.js +7 -0
  225. package/dist/core/extensions/runner.js.map +1 -1
  226. package/dist/core/extensions/storage.d.ts +8 -0
  227. package/dist/core/extensions/storage.d.ts.map +1 -0
  228. package/dist/core/extensions/storage.js +28 -0
  229. package/dist/core/extensions/storage.js.map +1 -0
  230. package/dist/core/extensions/types.d.ts +101 -1
  231. package/dist/core/extensions/types.d.ts.map +1 -1
  232. package/dist/core/extensions/types.js.map +1 -1
  233. package/dist/core/failure-corpus.d.ts +1 -15
  234. package/dist/core/failure-corpus.d.ts.map +1 -1
  235. package/dist/core/failure-corpus.js +9 -37
  236. package/dist/core/failure-corpus.js.map +1 -1
  237. package/dist/core/foreground-recovery-controller.d.ts +52 -0
  238. package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
  239. package/dist/core/foreground-recovery-controller.js +111 -0
  240. package/dist/core/foreground-recovery-controller.js.map +1 -0
  241. package/dist/core/gateways/channel-provider.d.ts +3 -0
  242. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  243. package/dist/core/gateways/channel-provider.js +31 -6
  244. package/dist/core/gateways/channel-provider.js.map +1 -1
  245. package/dist/core/goal-loop-controller.d.ts +17 -1
  246. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  247. package/dist/core/goal-loop-controller.js +79 -11
  248. package/dist/core/goal-loop-controller.js.map +1 -1
  249. package/dist/core/goals/goal-acceptance.d.ts +11 -0
  250. package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
  251. package/dist/core/goals/goal-acceptance.js +25 -0
  252. package/dist/core/goals/goal-acceptance.js.map +1 -0
  253. package/dist/core/goals/goal-auto-continue-controller.d.ts +27 -0
  254. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
  255. package/dist/core/goals/goal-auto-continue-controller.js +93 -0
  256. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
  257. package/dist/core/goals/goal-continuation-controller.d.ts +48 -2
  258. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  259. package/dist/core/goals/goal-continuation-controller.js +87 -0
  260. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  261. package/dist/core/goals/goal-continuation-defaults.d.ts +39 -0
  262. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  263. package/dist/core/goals/goal-continuation-defaults.js +42 -0
  264. package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
  265. package/dist/core/goals/goal-continuation-prompt.d.ts +5 -1
  266. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  267. package/dist/core/goals/goal-continuation-prompt.js +56 -15
  268. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  269. package/dist/core/goals/goal-lifecycle.d.ts +20 -0
  270. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
  271. package/dist/core/goals/goal-lifecycle.js +17 -0
  272. package/dist/core/goals/goal-lifecycle.js.map +1 -0
  273. package/dist/core/goals/goal-runtime-snapshot.d.ts +105 -4
  274. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  275. package/dist/core/goals/goal-runtime-snapshot.js +91 -6
  276. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  277. package/dist/core/goals/goal-state.d.ts +90 -1
  278. package/dist/core/goals/goal-state.d.ts.map +1 -1
  279. package/dist/core/goals/goal-state.js +78 -15
  280. package/dist/core/goals/goal-state.js.map +1 -1
  281. package/dist/core/goals/goal-tool-core.d.ts +58 -2
  282. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  283. package/dist/core/goals/goal-tool-core.js +82 -6
  284. package/dist/core/goals/goal-tool-core.js.map +1 -1
  285. package/dist/core/goals/session-goal-state.d.ts +13 -6
  286. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  287. package/dist/core/goals/session-goal-state.js +20 -28
  288. package/dist/core/goals/session-goal-state.js.map +1 -1
  289. package/dist/core/human-input.d.ts +100 -0
  290. package/dist/core/human-input.d.ts.map +1 -0
  291. package/dist/core/human-input.js +362 -0
  292. package/dist/core/human-input.js.map +1 -0
  293. package/dist/core/index.d.ts +9 -1
  294. package/dist/core/index.d.ts.map +1 -1
  295. package/dist/core/index.js +9 -1
  296. package/dist/core/index.js.map +1 -1
  297. package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
  298. package/dist/core/install-telemetry.d.ts.map +1 -0
  299. package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
  300. package/dist/core/install-telemetry.js.map +1 -0
  301. package/dist/core/keybindings.d.ts +27 -1
  302. package/dist/core/keybindings.d.ts.map +1 -1
  303. package/dist/core/keybindings.js +34 -8
  304. package/dist/core/keybindings.js.map +1 -1
  305. package/dist/core/learning/learning-audit.d.ts +2 -4
  306. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  307. package/dist/core/learning/learning-audit.js +9 -29
  308. package/dist/core/learning/learning-audit.js.map +1 -1
  309. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  310. package/dist/core/learning/learning-gate.js +1 -6
  311. package/dist/core/learning/learning-gate.js.map +1 -1
  312. package/dist/core/learning/observation-store.d.ts +12 -3
  313. package/dist/core/learning/observation-store.d.ts.map +1 -1
  314. package/dist/core/learning/observation-store.js +30 -15
  315. package/dist/core/learning/observation-store.js.map +1 -1
  316. package/dist/core/learning/session-learning-decision.d.ts +2 -4
  317. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  318. package/dist/core/learning/session-learning-decision.js +9 -29
  319. package/dist/core/learning/session-learning-decision.js.map +1 -1
  320. package/dist/core/learning/skill-curator.d.ts +5 -1
  321. package/dist/core/learning/skill-curator.d.ts.map +1 -1
  322. package/dist/core/learning/skill-curator.js +21 -19
  323. package/dist/core/learning/skill-curator.js.map +1 -1
  324. package/dist/core/local-runtime-controller.d.ts +65 -3
  325. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  326. package/dist/core/local-runtime-controller.js +186 -26
  327. package/dist/core/local-runtime-controller.js.map +1 -1
  328. package/dist/core/memory/providers/file-store.d.ts +1 -1
  329. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  330. package/dist/core/memory/providers/file-store.js +6 -6
  331. package/dist/core/memory/providers/file-store.js.map +1 -1
  332. package/dist/core/memory-controller.d.ts.map +1 -1
  333. package/dist/core/memory-controller.js +4 -4
  334. package/dist/core/memory-controller.js.map +1 -1
  335. package/dist/core/model-capability.d.ts +34 -0
  336. package/dist/core/model-capability.d.ts.map +1 -1
  337. package/dist/core/model-capability.js +43 -1
  338. package/dist/core/model-capability.js.map +1 -1
  339. package/dist/core/model-resolver.d.ts +1 -1
  340. package/dist/core/model-resolver.d.ts.map +1 -1
  341. package/dist/core/model-resolver.js +6 -9
  342. package/dist/core/model-resolver.js.map +1 -1
  343. package/dist/core/model-router/intent-classifier.d.ts +1 -4
  344. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  345. package/dist/core/model-router/intent-classifier.js +1 -156
  346. package/dist/core/model-router/intent-classifier.js.map +1 -1
  347. package/dist/core/model-router/tool-escalation.d.ts +15 -0
  348. package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
  349. package/dist/core/model-router/tool-escalation.js +23 -1
  350. package/dist/core/model-router/tool-escalation.js.map +1 -1
  351. package/dist/core/model-router-controller.d.ts +34 -7
  352. package/dist/core/model-router-controller.d.ts.map +1 -1
  353. package/dist/core/model-router-controller.js +95 -16
  354. package/dist/core/model-router-controller.js.map +1 -1
  355. package/dist/core/model-selection-controller.d.ts +4 -4
  356. package/dist/core/model-selection-controller.d.ts.map +1 -1
  357. package/dist/core/model-selection-controller.js.map +1 -1
  358. package/dist/core/model-tool-protocol.d.ts +23 -0
  359. package/dist/core/model-tool-protocol.d.ts.map +1 -0
  360. package/dist/core/model-tool-protocol.js +43 -0
  361. package/dist/core/model-tool-protocol.js.map +1 -0
  362. package/dist/core/models/adaptation-store.d.ts +10 -5
  363. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  364. package/dist/core/models/adaptation-store.js +129 -81
  365. package/dist/core/models/adaptation-store.js.map +1 -1
  366. package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
  367. package/dist/core/models/default-model-suggestions.js +17 -0
  368. package/dist/core/models/default-model-suggestions.js.map +1 -1
  369. package/dist/core/models/fitness-store.d.ts +4 -11
  370. package/dist/core/models/fitness-store.d.ts.map +1 -1
  371. package/dist/core/models/fitness-store.js +87 -51
  372. package/dist/core/models/fitness-store.js.map +1 -1
  373. package/dist/core/models/host-state-store.d.ts +34 -0
  374. package/dist/core/models/host-state-store.d.ts.map +1 -0
  375. package/dist/core/models/host-state-store.js +86 -0
  376. package/dist/core/models/host-state-store.js.map +1 -0
  377. package/dist/core/models/llamacpp-runtime.d.ts +180 -0
  378. package/dist/core/models/llamacpp-runtime.d.ts.map +1 -0
  379. package/dist/core/models/llamacpp-runtime.js +475 -0
  380. package/dist/core/models/llamacpp-runtime.js.map +1 -0
  381. package/dist/core/models/local-registration.d.ts +40 -0
  382. package/dist/core/models/local-registration.d.ts.map +1 -1
  383. package/dist/core/models/local-registration.js +94 -5
  384. package/dist/core/models/local-registration.js.map +1 -1
  385. package/dist/core/models/local-runtime.d.ts.map +1 -1
  386. package/dist/core/models/local-runtime.js +6 -5
  387. package/dist/core/models/local-runtime.js.map +1 -1
  388. package/dist/core/models/model-ref.d.ts +7 -0
  389. package/dist/core/models/model-ref.d.ts.map +1 -1
  390. package/dist/core/models/model-ref.js +26 -0
  391. package/dist/core/models/model-ref.js.map +1 -1
  392. package/dist/core/models/needle-runtime.d.ts +257 -0
  393. package/dist/core/models/needle-runtime.d.ts.map +1 -0
  394. package/dist/core/models/needle-runtime.js +519 -0
  395. package/dist/core/models/needle-runtime.js.map +1 -0
  396. package/dist/core/models/prism-llamacpp-lifecycle.d.ts +89 -0
  397. package/dist/core/models/prism-llamacpp-lifecycle.d.ts.map +1 -0
  398. package/dist/core/models/prism-llamacpp-lifecycle.js +121 -0
  399. package/dist/core/models/prism-llamacpp-lifecycle.js.map +1 -0
  400. package/dist/core/orchestration/agent-resume.d.ts +24 -0
  401. package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
  402. package/dist/core/orchestration/agent-resume.js +90 -0
  403. package/dist/core/orchestration/agent-resume.js.map +1 -0
  404. package/dist/core/orchestration/capability-gateway.d.ts +61 -0
  405. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
  406. package/dist/core/orchestration/capability-gateway.js +152 -0
  407. package/dist/core/orchestration/capability-gateway.js.map +1 -0
  408. package/dist/core/orchestration/contracts.d.ts +343 -0
  409. package/dist/core/orchestration/contracts.d.ts.map +1 -0
  410. package/dist/core/orchestration/contracts.js +135 -0
  411. package/dist/core/orchestration/contracts.js.map +1 -0
  412. package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
  413. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
  414. package/dist/core/orchestration/delegation-ledger.js +197 -0
  415. package/dist/core/orchestration/delegation-ledger.js.map +1 -0
  416. package/dist/core/orchestration/event-store.d.ts +83 -0
  417. package/dist/core/orchestration/event-store.d.ts.map +1 -0
  418. package/dist/core/orchestration/event-store.js +560 -0
  419. package/dist/core/orchestration/event-store.js.map +1 -0
  420. package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
  421. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
  422. package/dist/core/orchestration/lane-tool-manifests.js +37 -0
  423. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
  424. package/dist/core/orchestration/model-binding.d.ts +15 -0
  425. package/dist/core/orchestration/model-binding.d.ts.map +1 -0
  426. package/dist/core/orchestration/model-binding.js +29 -0
  427. package/dist/core/orchestration/model-binding.js.map +1 -0
  428. package/dist/core/orchestration/policy-compiler.d.ts +49 -0
  429. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
  430. package/dist/core/orchestration/policy-compiler.js +191 -0
  431. package/dist/core/orchestration/policy-compiler.js.map +1 -0
  432. package/dist/core/orchestration/policy-gate.d.ts +18 -0
  433. package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
  434. package/dist/core/orchestration/policy-gate.js +24 -0
  435. package/dist/core/orchestration/policy-gate.js.map +1 -0
  436. package/dist/core/orchestration/profile-registry.d.ts +51 -0
  437. package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
  438. package/dist/core/orchestration/profile-registry.js +393 -0
  439. package/dist/core/orchestration/profile-registry.js.map +1 -0
  440. package/dist/core/orchestration/profile-store.d.ts +31 -0
  441. package/dist/core/orchestration/profile-store.d.ts.map +1 -0
  442. package/dist/core/orchestration/profile-store.js +136 -0
  443. package/dist/core/orchestration/profile-store.js.map +1 -0
  444. package/dist/core/orchestration/risk-budget.d.ts +9 -0
  445. package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
  446. package/dist/core/orchestration/risk-budget.js +48 -0
  447. package/dist/core/orchestration/risk-budget.js.map +1 -0
  448. package/dist/core/orchestration/task-runtime.d.ts +168 -0
  449. package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
  450. package/dist/core/orchestration/task-runtime.js +1600 -0
  451. package/dist/core/orchestration/task-runtime.js.map +1 -0
  452. package/dist/core/orchestration/work-state-projection.d.ts +32 -0
  453. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
  454. package/dist/core/orchestration/work-state-projection.js +116 -0
  455. package/dist/core/orchestration/work-state-projection.js.map +1 -0
  456. package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
  457. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
  458. package/dist/core/orchestration/worker-execution-contract.js +179 -0
  459. package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
  460. package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
  461. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
  462. package/dist/core/orchestration/worker-result-adapter.js +109 -0
  463. package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
  464. package/dist/core/package-manager.d.ts.map +1 -1
  465. package/dist/core/package-manager.js +11 -10
  466. package/dist/core/package-manager.js.map +1 -1
  467. package/dist/core/process-identity.d.ts +11 -0
  468. package/dist/core/process-identity.d.ts.map +1 -0
  469. package/dist/core/process-identity.js +26 -0
  470. package/dist/core/process-identity.js.map +1 -0
  471. package/dist/core/process-matrix/codes.d.ts +83 -0
  472. package/dist/core/process-matrix/codes.d.ts.map +1 -0
  473. package/dist/core/process-matrix/codes.js +15 -0
  474. package/dist/core/process-matrix/codes.js.map +1 -0
  475. package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
  476. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
  477. package/dist/core/process-matrix/resume-launcher.js +62 -0
  478. package/dist/core/process-matrix/resume-launcher.js.map +1 -0
  479. package/dist/core/process-matrix/runtime.d.ts +78 -0
  480. package/dist/core/process-matrix/runtime.d.ts.map +1 -0
  481. package/dist/core/process-matrix/runtime.js +633 -0
  482. package/dist/core/process-matrix/runtime.js.map +1 -0
  483. package/dist/core/process-matrix/store.d.ts +25 -0
  484. package/dist/core/process-matrix/store.d.ts.map +1 -0
  485. package/dist/core/process-matrix/store.js +189 -0
  486. package/dist/core/process-matrix/store.js.map +1 -0
  487. package/dist/core/process-matrix/supervisor.d.ts +75 -0
  488. package/dist/core/process-matrix/supervisor.d.ts.map +1 -0
  489. package/dist/core/process-matrix/supervisor.js +161 -0
  490. package/dist/core/process-matrix/supervisor.js.map +1 -0
  491. package/dist/core/profile-registry.d.ts +7 -0
  492. package/dist/core/profile-registry.d.ts.map +1 -1
  493. package/dist/core/profile-registry.js +25 -7
  494. package/dist/core/profile-registry.js.map +1 -1
  495. package/dist/core/python-runtime.d.ts.map +1 -1
  496. package/dist/core/python-runtime.js +3 -3
  497. package/dist/core/python-runtime.js.map +1 -1
  498. package/dist/core/reflection-controller.d.ts +33 -9
  499. package/dist/core/reflection-controller.d.ts.map +1 -1
  500. package/dist/core/reflection-controller.js +217 -127
  501. package/dist/core/reflection-controller.js.map +1 -1
  502. package/dist/core/reload-blockers.d.ts +36 -0
  503. package/dist/core/reload-blockers.d.ts.map +1 -1
  504. package/dist/core/reload-blockers.js +50 -8
  505. package/dist/core/reload-blockers.js.map +1 -1
  506. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  507. package/dist/core/research/evidence-bundle.js +1 -6
  508. package/dist/core/research/evidence-bundle.js.map +1 -1
  509. package/dist/core/research/lane-model-resolver.d.ts +33 -0
  510. package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
  511. package/dist/core/research/lane-model-resolver.js +65 -0
  512. package/dist/core/research/lane-model-resolver.js.map +1 -0
  513. package/dist/core/research/model-fitness-controller.d.ts +38 -0
  514. package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
  515. package/dist/core/research/model-fitness-controller.js +106 -0
  516. package/dist/core/research/model-fitness-controller.js.map +1 -0
  517. package/dist/core/research/model-fitness.d.ts +1 -1
  518. package/dist/core/research/model-fitness.d.ts.map +1 -1
  519. package/dist/core/research/model-fitness.js +4 -4
  520. package/dist/core/research/model-fitness.js.map +1 -1
  521. package/dist/core/research/research-gate.d.ts.map +1 -1
  522. package/dist/core/research/research-gate.js +7 -7
  523. package/dist/core/research/research-gate.js.map +1 -1
  524. package/dist/core/research/research-lane-controller.d.ts +62 -0
  525. package/dist/core/research/research-lane-controller.d.ts.map +1 -0
  526. package/dist/core/research/research-lane-controller.js +292 -0
  527. package/dist/core/research/research-lane-controller.js.map +1 -0
  528. package/dist/core/research/session-evidence-bundle.d.ts +2 -4
  529. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  530. package/dist/core/research/session-evidence-bundle.js +10 -46
  531. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  532. package/dist/core/resource-loader.d.ts.map +1 -1
  533. package/dist/core/resource-loader.js +15 -9
  534. package/dist/core/resource-loader.js.map +1 -1
  535. package/dist/core/risk-classifier.d.ts +6 -0
  536. package/dist/core/risk-classifier.d.ts.map +1 -0
  537. package/dist/core/risk-classifier.js +225 -0
  538. package/dist/core/risk-classifier.js.map +1 -0
  539. package/dist/core/runtime-builder.d.ts +76 -17
  540. package/dist/core/runtime-builder.d.ts.map +1 -1
  541. package/dist/core/runtime-builder.js +367 -124
  542. package/dist/core/runtime-builder.js.map +1 -1
  543. package/dist/core/scout-controller.d.ts +6 -0
  544. package/dist/core/scout-controller.d.ts.map +1 -1
  545. package/dist/core/scout-controller.js +66 -52
  546. package/dist/core/scout-controller.js.map +1 -1
  547. package/dist/core/sdk.d.ts +6 -3
  548. package/dist/core/sdk.d.ts.map +1 -1
  549. package/dist/core/sdk.js +64 -27
  550. package/dist/core/sdk.js.map +1 -1
  551. package/dist/core/session-analytics.d.ts.map +1 -1
  552. package/dist/core/session-analytics.js +28 -1
  553. package/dist/core/session-analytics.js.map +1 -1
  554. package/dist/core/session-image-store.d.ts +33 -0
  555. package/dist/core/session-image-store.d.ts.map +1 -0
  556. package/dist/core/session-image-store.js +283 -0
  557. package/dist/core/session-image-store.js.map +1 -0
  558. package/dist/core/session-role.d.ts +33 -0
  559. package/dist/core/session-role.d.ts.map +1 -0
  560. package/dist/core/session-role.js +58 -0
  561. package/dist/core/session-role.js.map +1 -0
  562. package/dist/core/session-snapshot.d.ts +34 -0
  563. package/dist/core/session-snapshot.d.ts.map +1 -0
  564. package/dist/core/session-snapshot.js +68 -0
  565. package/dist/core/session-snapshot.js.map +1 -0
  566. package/dist/core/session-supervision-runtime.d.ts +31 -0
  567. package/dist/core/session-supervision-runtime.d.ts.map +1 -0
  568. package/dist/core/session-supervision-runtime.js +97 -0
  569. package/dist/core/session-supervision-runtime.js.map +1 -0
  570. package/dist/core/settings-manager.d.ts +51 -7
  571. package/dist/core/settings-manager.d.ts.map +1 -1
  572. package/dist/core/settings-manager.js +168 -82
  573. package/dist/core/settings-manager.js.map +1 -1
  574. package/dist/core/system-prompt-builder.d.ts +12 -0
  575. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  576. package/dist/core/system-prompt-builder.js +6 -0
  577. package/dist/core/system-prompt-builder.js.map +1 -1
  578. package/dist/core/system-prompt.d.ts +14 -1
  579. package/dist/core/system-prompt.d.ts.map +1 -1
  580. package/dist/core/system-prompt.js +20 -3
  581. package/dist/core/system-prompt.js.map +1 -1
  582. package/dist/core/tasks/session-task-state.d.ts +13 -6
  583. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  584. package/dist/core/tasks/session-task-state.js +20 -22
  585. package/dist/core/tasks/session-task-state.js.map +1 -1
  586. package/dist/core/tasks/task-contract-monitor.d.ts +45 -0
  587. package/dist/core/tasks/task-contract-monitor.d.ts.map +1 -0
  588. package/dist/core/tasks/task-contract-monitor.js +56 -0
  589. package/dist/core/tasks/task-contract-monitor.js.map +1 -0
  590. package/dist/core/tasks/task-projection.d.ts +20 -0
  591. package/dist/core/tasks/task-projection.d.ts.map +1 -0
  592. package/dist/core/tasks/task-projection.js +47 -0
  593. package/dist/core/tasks/task-projection.js.map +1 -0
  594. package/dist/core/tasks/task-state.d.ts +12 -0
  595. package/dist/core/tasks/task-state.d.ts.map +1 -1
  596. package/dist/core/tasks/task-state.js +56 -12
  597. package/dist/core/tasks/task-state.js.map +1 -1
  598. package/dist/core/tool-capability-policy.d.ts +13 -0
  599. package/dist/core/tool-capability-policy.d.ts.map +1 -0
  600. package/dist/core/tool-capability-policy.js +85 -0
  601. package/dist/core/tool-capability-policy.js.map +1 -0
  602. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  603. package/dist/core/tool-gate-controller.js +5 -0
  604. package/dist/core/tool-gate-controller.js.map +1 -1
  605. package/dist/core/tool-protocol-controller.d.ts +91 -0
  606. package/dist/core/tool-protocol-controller.d.ts.map +1 -0
  607. package/dist/core/tool-protocol-controller.js +512 -0
  608. package/dist/core/tool-protocol-controller.js.map +1 -0
  609. package/dist/core/tool-recovery-log-records.d.ts +6 -0
  610. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  611. package/dist/core/tool-recovery-log-records.js +13 -31
  612. package/dist/core/tool-recovery-log-records.js.map +1 -1
  613. package/dist/core/tool-selection/promotion.d.ts +54 -0
  614. package/dist/core/tool-selection/promotion.d.ts.map +1 -0
  615. package/dist/core/tool-selection/promotion.js +81 -0
  616. package/dist/core/tool-selection/promotion.js.map +1 -0
  617. package/dist/core/tool-selection/tool-performance-store.d.ts +39 -6
  618. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  619. package/dist/core/tool-selection/tool-performance-store.js +153 -110
  620. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  621. package/dist/core/tool-selection/tool-selection-controller.d.ts +45 -0
  622. package/dist/core/tool-selection/tool-selection-controller.d.ts.map +1 -1
  623. package/dist/core/tool-selection/tool-selection-controller.js +96 -0
  624. package/dist/core/tool-selection/tool-selection-controller.js.map +1 -1
  625. package/dist/core/tools/ask-question.d.ts +124 -0
  626. package/dist/core/tools/ask-question.d.ts.map +1 -0
  627. package/dist/core/tools/ask-question.js +693 -0
  628. package/dist/core/tools/ask-question.js.map +1 -0
  629. package/dist/core/tools/bash.d.ts +18 -0
  630. package/dist/core/tools/bash.d.ts.map +1 -1
  631. package/dist/core/tools/bash.js +95 -16
  632. package/dist/core/tools/bash.js.map +1 -1
  633. package/dist/core/tools/delegate-status.d.ts +44 -2
  634. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  635. package/dist/core/tools/delegate-status.js +214 -19
  636. package/dist/core/tools/delegate-status.js.map +1 -1
  637. package/dist/core/tools/delegate.d.ts +15 -13
  638. package/dist/core/tools/delegate.d.ts.map +1 -1
  639. package/dist/core/tools/delegate.js +124 -22
  640. package/dist/core/tools/delegate.js.map +1 -1
  641. package/dist/core/tools/extensionify.d.ts.map +1 -1
  642. package/dist/core/tools/extensionify.js +1 -0
  643. package/dist/core/tools/extensionify.js.map +1 -1
  644. package/dist/core/tools/goal.d.ts +94 -3
  645. package/dist/core/tools/goal.d.ts.map +1 -1
  646. package/dist/core/tools/goal.js +165 -15
  647. package/dist/core/tools/goal.js.map +1 -1
  648. package/dist/core/tools/model-fitness.d.ts +7 -0
  649. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  650. package/dist/core/tools/model-fitness.js +4 -4
  651. package/dist/core/tools/model-fitness.js.map +1 -1
  652. package/dist/core/tools/orchestration-panel.d.ts +43 -0
  653. package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
  654. package/dist/core/tools/orchestration-panel.js +168 -0
  655. package/dist/core/tools/orchestration-panel.js.map +1 -0
  656. package/dist/core/tools/run-process.d.ts +26 -0
  657. package/dist/core/tools/run-process.d.ts.map +1 -0
  658. package/dist/core/tools/run-process.js +138 -0
  659. package/dist/core/tools/run-process.js.map +1 -0
  660. package/dist/core/tools/shell-contract-router.d.ts +6 -1
  661. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  662. package/dist/core/tools/shell-contract-router.js +23 -2
  663. package/dist/core/tools/shell-contract-router.js.map +1 -1
  664. package/dist/core/tools/shell-session.d.ts +89 -0
  665. package/dist/core/tools/shell-session.d.ts.map +1 -0
  666. package/dist/core/tools/shell-session.js +432 -0
  667. package/dist/core/tools/shell-session.js.map +1 -0
  668. package/dist/core/tools/task-steps.d.ts +6 -0
  669. package/dist/core/tools/task-steps.d.ts.map +1 -1
  670. package/dist/core/tools/task-steps.js +165 -8
  671. package/dist/core/tools/task-steps.js.map +1 -1
  672. package/dist/core/tools/tmux-dispatch.d.ts +84 -0
  673. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -0
  674. package/dist/core/tools/tmux-dispatch.js +91 -0
  675. package/dist/core/tools/tmux-dispatch.js.map +1 -0
  676. package/dist/core/tools/windows-shell-engine.d.ts +42 -0
  677. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -0
  678. package/dist/core/tools/windows-shell-engine.js +151 -0
  679. package/dist/core/tools/windows-shell-engine.js.map +1 -0
  680. package/dist/core/tools/windows-shell-state.d.ts +40 -0
  681. package/dist/core/tools/windows-shell-state.d.ts.map +1 -0
  682. package/dist/core/tools/windows-shell-state.js +59 -0
  683. package/dist/core/tools/windows-shell-state.js.map +1 -0
  684. package/dist/core/tools/worktree-sync.d.ts +24 -0
  685. package/dist/core/tools/worktree-sync.d.ts.map +1 -0
  686. package/dist/core/tools/worktree-sync.js +338 -0
  687. package/dist/core/tools/worktree-sync.js.map +1 -0
  688. package/dist/core/trust-manager.d.ts +4 -1
  689. package/dist/core/trust-manager.d.ts.map +1 -1
  690. package/dist/core/trust-manager.js +20 -2
  691. package/dist/core/trust-manager.js.map +1 -1
  692. package/dist/core/util/atomic-file.d.ts +55 -0
  693. package/dist/core/util/atomic-file.d.ts.map +1 -0
  694. package/dist/core/util/atomic-file.js +255 -0
  695. package/dist/core/util/atomic-file.js.map +1 -0
  696. package/dist/core/util/bounded-jsonl.d.ts +10 -0
  697. package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
  698. package/dist/core/util/bounded-jsonl.js +75 -0
  699. package/dist/core/util/bounded-jsonl.js.map +1 -0
  700. package/dist/core/util/minimatch-cache.d.ts +33 -0
  701. package/dist/core/util/minimatch-cache.d.ts.map +1 -0
  702. package/dist/core/util/minimatch-cache.js +0 -0
  703. package/dist/core/util/minimatch-cache.js.map +1 -0
  704. package/dist/core/util/value-guards.d.ts +5 -0
  705. package/dist/core/util/value-guards.d.ts.map +1 -0
  706. package/dist/core/util/value-guards.js +12 -0
  707. package/dist/core/util/value-guards.js.map +1 -0
  708. package/dist/core/worktree-sync/codes.d.ts +227 -0
  709. package/dist/core/worktree-sync/codes.d.ts.map +1 -0
  710. package/dist/core/worktree-sync/codes.js +14 -0
  711. package/dist/core/worktree-sync/codes.js.map +1 -0
  712. package/dist/core/worktree-sync/git-engine.d.ts +156 -0
  713. package/dist/core/worktree-sync/git-engine.d.ts.map +1 -0
  714. package/dist/core/worktree-sync/git-engine.js +1191 -0
  715. package/dist/core/worktree-sync/git-engine.js.map +1 -0
  716. package/dist/core/worktree-sync/lane-gate.d.ts +75 -0
  717. package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -0
  718. package/dist/core/worktree-sync/lane-gate.js +360 -0
  719. package/dist/core/worktree-sync/lane-gate.js.map +1 -0
  720. package/dist/core/worktree-sync/runtime.d.ts +47 -0
  721. package/dist/core/worktree-sync/runtime.d.ts.map +1 -0
  722. package/dist/core/worktree-sync/runtime.js +96 -0
  723. package/dist/core/worktree-sync/runtime.js.map +1 -0
  724. package/dist/core/worktree-sync/store.d.ts +69 -0
  725. package/dist/core/worktree-sync/store.d.ts.map +1 -0
  726. package/dist/core/worktree-sync/store.js +252 -0
  727. package/dist/core/worktree-sync/store.js.map +1 -0
  728. package/dist/core/worktree-sync/watcher.d.ts +29 -0
  729. package/dist/core/worktree-sync/watcher.d.ts.map +1 -0
  730. package/dist/core/worktree-sync/watcher.js +93 -0
  731. package/dist/core/worktree-sync/watcher.js.map +1 -0
  732. package/dist/index.d.ts +13 -3
  733. package/dist/index.d.ts.map +1 -1
  734. package/dist/index.js +12 -2
  735. package/dist/index.js.map +1 -1
  736. package/dist/main.d.ts.map +1 -1
  737. package/dist/main.js +179 -1
  738. package/dist/main.js.map +1 -1
  739. package/dist/migrations.d.ts +7 -0
  740. package/dist/migrations.d.ts.map +1 -1
  741. package/dist/migrations.js +197 -1
  742. package/dist/migrations.js.map +1 -1
  743. package/dist/modes/interactive/auto-learn-controller.d.ts +16 -1
  744. package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
  745. package/dist/modes/interactive/auto-learn-controller.js +50 -8
  746. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  747. package/dist/modes/interactive/clipboard-input.d.ts +7 -1
  748. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  749. package/dist/modes/interactive/clipboard-input.js +44 -6
  750. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  751. package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
  752. package/dist/modes/interactive/components/profile-resource-editor.js +23 -1
  753. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  754. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  755. package/dist/modes/interactive/components/settings-selector.js +2 -2
  756. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  757. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  758. package/dist/modes/interactive/config-backup.js +5 -4
  759. package/dist/modes/interactive/config-backup.js.map +1 -1
  760. package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
  761. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  762. package/dist/modes/interactive/extension-ui-host.js +76 -15
  763. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  764. package/dist/modes/interactive/interactive-mode.d.ts +4 -0
  765. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  766. package/dist/modes/interactive/interactive-mode.js +67 -1
  767. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  768. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  769. package/dist/modes/interactive/key-handlers.js +1 -1
  770. package/dist/modes/interactive/key-handlers.js.map +1 -1
  771. package/dist/modes/interactive/local-model-commands.d.ts +43 -0
  772. package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
  773. package/dist/modes/interactive/local-model-commands.js +290 -3
  774. package/dist/modes/interactive/local-model-commands.js.map +1 -1
  775. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  776. package/dist/modes/interactive/profile-menu-controller.js +7 -7
  777. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  778. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  779. package/dist/modes/interactive/report-commands.js +21 -0
  780. package/dist/modes/interactive/report-commands.js.map +1 -1
  781. package/dist/modes/interactive/session-flow-commands.d.ts +17 -2
  782. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  783. package/dist/modes/interactive/session-flow-commands.js +74 -21
  784. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  785. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  786. package/dist/modes/interactive/session-io-commands.js +16 -6
  787. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  788. package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
  789. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
  790. package/dist/modes/interactive/session-replacement-errors.js +15 -0
  791. package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
  792. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  793. package/dist/modes/interactive/startup-checks.js +1 -1
  794. package/dist/modes/interactive/startup-checks.js.map +1 -1
  795. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  796. package/dist/modes/rpc/rpc-mode.js +82 -23
  797. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  798. package/dist/modes/rpc/rpc-types.d.ts +15 -0
  799. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  800. package/dist/modes/rpc/rpc-types.js +138 -1
  801. package/dist/modes/rpc/rpc-types.js.map +1 -1
  802. package/dist/utils/clipboard-image.d.ts.map +1 -1
  803. package/dist/utils/clipboard-image.js +2 -13
  804. package/dist/utils/clipboard-image.js.map +1 -1
  805. package/dist/utils/clipboard-native.d.ts +1 -0
  806. package/dist/utils/clipboard-native.d.ts.map +1 -1
  807. package/dist/utils/clipboard-native.js.map +1 -1
  808. package/dist/utils/clipboard.d.ts +1 -0
  809. package/dist/utils/clipboard.d.ts.map +1 -1
  810. package/dist/utils/clipboard.js +52 -1
  811. package/dist/utils/clipboard.js.map +1 -1
  812. package/dist/utils/fs-watch.d.ts +11 -0
  813. package/dist/utils/fs-watch.d.ts.map +1 -1
  814. package/dist/utils/fs-watch.js +20 -2
  815. package/dist/utils/fs-watch.js.map +1 -1
  816. package/dist/utils/highlight-js-languages.d.ts +4 -0
  817. package/dist/utils/highlight-js-languages.d.ts.map +1 -0
  818. package/dist/utils/highlight-js-languages.js +573 -0
  819. package/dist/utils/highlight-js-languages.js.map +1 -0
  820. package/dist/utils/platform.d.ts +3 -0
  821. package/dist/utils/platform.d.ts.map +1 -0
  822. package/dist/utils/platform.js +8 -0
  823. package/dist/utils/platform.js.map +1 -0
  824. package/dist/utils/shell.d.ts +7 -1
  825. package/dist/utils/shell.d.ts.map +1 -1
  826. package/dist/utils/shell.js +21 -6
  827. package/dist/utils/shell.js.map +1 -1
  828. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  829. package/dist/utils/syntax-highlight.js +53 -5
  830. package/dist/utils/syntax-highlight.js.map +1 -1
  831. package/dist/utils/tools-manager.d.ts.map +1 -1
  832. package/dist/utils/tools-manager.js +112 -1
  833. package/dist/utils/tools-manager.js.map +1 -1
  834. package/dist/utils/work-directory.d.ts +11 -0
  835. package/dist/utils/work-directory.d.ts.map +1 -1
  836. package/dist/utils/work-directory.js +30 -9
  837. package/dist/utils/work-directory.js.map +1 -1
  838. package/docs/UI_POLISH_ORCHESTRATION.md +44 -0
  839. package/docs/UI_QUALITY_ORCHESTRATION.md +30 -0
  840. package/docs/docs.json +4 -0
  841. package/docs/extensions.md +62 -2
  842. package/docs/harness-architecture.md +156 -0
  843. package/docs/keybindings.md +11 -1
  844. package/docs/process-matrix.md +153 -0
  845. package/docs/rpc.md +45 -2
  846. package/docs/sessions.md +15 -0
  847. package/docs/settings.md +128 -11
  848. package/docs/task-steps.md +8 -0
  849. package/docs/telemetry.md +19 -0
  850. package/docs/tmux-agent-manager.md +92 -2
  851. package/docs/ui-reference/README.md +9 -0
  852. package/docs/ui-reference/orchestration-after.txt +7 -0
  853. package/docs/ui-reference/orchestration-before.txt +7 -0
  854. package/docs/ui-reference/orchestration-reference.txt +6 -0
  855. package/docs/usage.md +14 -2
  856. package/docs/windows.md +52 -3
  857. package/docs/work-directory.md +42 -2
  858. package/docs/worktree-sync.md +250 -0
  859. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  860. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  861. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  862. package/examples/extensions/question.ts +34 -245
  863. package/examples/extensions/questionnaire.ts +41 -407
  864. package/examples/extensions/sandbox/package-lock.json +2 -2
  865. package/examples/extensions/sandbox/package.json +1 -1
  866. package/examples/extensions/with-deps/package-lock.json +2 -2
  867. package/examples/extensions/with-deps/package.json +1 -1
  868. package/npm-shrinkwrap.json +12 -12
  869. package/package.json +10 -4
  870. package/dist/core/delegation/session-worker-result.d.ts +0 -16
  871. package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
  872. package/dist/core/delegation/session-worker-result.js +0 -53
  873. package/dist/core/delegation/session-worker-result.js.map +0 -1
  874. package/dist/core/delegation/worker-result.d.ts +0 -15
  875. package/dist/core/delegation/worker-result.d.ts.map +0 -1
  876. package/dist/core/delegation/worker-result.js +0 -161
  877. package/dist/core/delegation/worker-result.js.map +0 -1
  878. package/dist/core/telemetry.d.ts.map +0 -1
  879. package/dist/core/telemetry.js.map +0 -1
  880. package/docs/integration-sweep-builder-blueprint-2026-07-09.md +0 -365
  881. package/docs/integration-sweep-resume-2026-07-09.md +0 -407
@@ -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,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACrC,WAAW,CAAC,EAAE,OA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,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"]}
@@ -0,0 +1,362 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { getActiveSessionBranchEntries } from "./session-snapshot.js";
3
+ import { isPlainRecord } from "./util/value-guards.js";
4
+ export const HUMAN_INPUT_CUSTOM_TYPE = "human_input_request";
5
+ export const HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE = "worker-owner-response";
6
+ export const HUMAN_INPUT_INLINE_BYTES = 16 * 1024;
7
+ const HUMAN_INPUT_PREVIEW_CHARS = 4_000;
8
+ function cloneQuestion(question) {
9
+ return {
10
+ ...question,
11
+ options: question.options.map((option) => ({ ...option })),
12
+ };
13
+ }
14
+ function cloneAnswer(answer) {
15
+ return {
16
+ ...answer,
17
+ selected: [...answer.selected],
18
+ customArtifact: answer.customArtifact ? { ...answer.customArtifact } : undefined,
19
+ images: answer.images?.map((image) => ({ ...image })),
20
+ };
21
+ }
22
+ function cloneRequest(request) {
23
+ return {
24
+ ...request,
25
+ questions: request.questions.map(cloneQuestion),
26
+ };
27
+ }
28
+ function cloneSnapshot(snapshot) {
29
+ return {
30
+ ...snapshot,
31
+ request: cloneRequest(snapshot.request),
32
+ answers: snapshot.answers.map(cloneAnswer),
33
+ };
34
+ }
35
+ function isStringArray(value) {
36
+ return Array.isArray(value) && value.every((entry) => typeof entry === "string");
37
+ }
38
+ function isQuestion(value) {
39
+ if (!isPlainRecord(value) || !Array.isArray(value.options))
40
+ return false;
41
+ return (typeof value.id === "string" &&
42
+ typeof value.header === "string" &&
43
+ typeof value.question === "string" &&
44
+ (value.multiSelect === undefined || typeof value.multiSelect === "boolean") &&
45
+ value.options.every((option) => isPlainRecord(option) && typeof option.label === "string" && typeof option.description === "string"));
46
+ }
47
+ function isArtifactRef(value) {
48
+ return (isPlainRecord(value) &&
49
+ typeof value.id === "string" &&
50
+ typeof value.kind === "string" &&
51
+ typeof value.byteLength === "number" &&
52
+ typeof value.createdAtTurn === "number" &&
53
+ typeof value.reproducible === "boolean");
54
+ }
55
+ function isAnswer(value) {
56
+ if (!isPlainRecord(value))
57
+ return false;
58
+ return (typeof value.id === "string" &&
59
+ typeof value.header === "string" &&
60
+ typeof value.question === "string" &&
61
+ isStringArray(value.selected) &&
62
+ (value.custom === undefined || typeof value.custom === "string") &&
63
+ (value.customArtifact === undefined || isArtifactRef(value.customArtifact)) &&
64
+ (value.images === undefined ||
65
+ (Array.isArray(value.images) &&
66
+ value.images.every((image) => isPlainRecord(image) && typeof image.label === "string" && typeof image.mimeType === "string"))) &&
67
+ typeof value.skipped === "boolean");
68
+ }
69
+ function isImageContent(value) {
70
+ return (isPlainRecord(value) &&
71
+ value.type === "image" &&
72
+ typeof value.data === "string" &&
73
+ typeof value.mimeType === "string");
74
+ }
75
+ function normalizePresentationResult(request, value) {
76
+ if (!isPlainRecord(value) || typeof value.cancelled !== "boolean") {
77
+ throw new Error("Invalid human-input response: expected a typed presentation result");
78
+ }
79
+ if (value.cancelled) {
80
+ const reason = value.reason;
81
+ if (reason !== undefined &&
82
+ reason !== "user_cancelled" &&
83
+ reason !== "ui_unavailable" &&
84
+ reason !== "interrupted" &&
85
+ reason !== "invalid_questions") {
86
+ throw new Error("Invalid human-input response: unknown cancellation reason");
87
+ }
88
+ return {
89
+ answers: [],
90
+ cancelled: true,
91
+ ...(reason ? { reason } : {}),
92
+ imageContents: [],
93
+ };
94
+ }
95
+ if (!Array.isArray(value.answers) || !Array.isArray(value.imageContents)) {
96
+ throw new Error("Invalid human-input response: answers and imageContents must be arrays");
97
+ }
98
+ const answersById = new Map();
99
+ for (const candidate of value.answers) {
100
+ if (!isAnswer(candidate))
101
+ throw new Error("Invalid human-input response: malformed answer");
102
+ if (candidate.customArtifact !== undefined) {
103
+ throw new Error("Invalid human-input response: artifact references are harness-owned");
104
+ }
105
+ if (answersById.has(candidate.id)) {
106
+ throw new Error(`Invalid human-input response: duplicate answer '${candidate.id}'`);
107
+ }
108
+ answersById.set(candidate.id, candidate);
109
+ }
110
+ if (answersById.size !== request.questions.length) {
111
+ throw new Error("Invalid human-input response: every question must have exactly one answer");
112
+ }
113
+ const answers = request.questions.map((question) => {
114
+ const answer = answersById.get(question.id);
115
+ if (!answer)
116
+ throw new Error(`Invalid human-input response: missing answer '${question.id}'`);
117
+ const optionLabels = new Set(question.options.map((option) => option.label));
118
+ if (new Set(answer.selected).size !== answer.selected.length) {
119
+ throw new Error(`Invalid human-input response: duplicate option for '${question.id}'`);
120
+ }
121
+ if (answer.selected.some((selection) => !optionLabels.has(selection))) {
122
+ throw new Error(`Invalid human-input response: unknown option for '${question.id}'`);
123
+ }
124
+ if (!question.multiSelect && answer.selected.length > 1) {
125
+ throw new Error(`Invalid human-input response: '${question.id}' is single-select`);
126
+ }
127
+ if (answer.skipped &&
128
+ (answer.selected.length > 0 || Boolean(answer.custom) || (answer.images?.length ?? 0) > 0)) {
129
+ throw new Error(`Invalid human-input response: skipped answer '${question.id}' contains a value`);
130
+ }
131
+ return {
132
+ ...cloneAnswer(answer),
133
+ header: question.header,
134
+ question: question.question,
135
+ };
136
+ });
137
+ if (!value.imageContents.every(isImageContent)) {
138
+ throw new Error("Invalid human-input response: malformed image content");
139
+ }
140
+ const answerImages = answers.flatMap((answer) => answer.images ?? []);
141
+ if (answerImages.length !== value.imageContents.length) {
142
+ throw new Error("Invalid human-input response: image metadata does not match image content");
143
+ }
144
+ if (!request.acceptsImages && value.imageContents.length > 0) {
145
+ throw new Error("Invalid human-input response: the selected model does not accept images");
146
+ }
147
+ for (let index = 0; index < answerImages.length; index++) {
148
+ if (answerImages[index]?.mimeType !== value.imageContents[index]?.mimeType) {
149
+ throw new Error("Invalid human-input response: image MIME metadata does not match image content");
150
+ }
151
+ }
152
+ return {
153
+ answers,
154
+ cancelled: false,
155
+ imageContents: value.imageContents.map((image) => ({ ...image })),
156
+ };
157
+ }
158
+ function persistPresentationImages(result, imageStore) {
159
+ if (!imageStore || result.cancelled || result.imageContents.length === 0)
160
+ return result;
161
+ let imageIndex = 0;
162
+ const durableContents = [];
163
+ const answers = result.answers.map((answer) => {
164
+ let custom = answer.custom;
165
+ const images = answer.images?.map((image) => {
166
+ const content = result.imageContents[imageIndex++];
167
+ if (!content)
168
+ throw new Error("Human-input image metadata exceeds supplied image content");
169
+ const sequenceMatch = /^\[Image #(\d{1,6})\]$/iu.exec(image.label);
170
+ const stored = imageStore.retainContent(content, sequenceMatch ? Number(sequenceMatch[1]) : undefined);
171
+ const durableLabel = `[Image #${stored.sequence}]`;
172
+ if (custom?.includes(image.label))
173
+ custom = custom.split(image.label).join(durableLabel);
174
+ durableContents.push({
175
+ type: "image",
176
+ data: Buffer.from(stored.bytes).toString("base64"),
177
+ mimeType: stored.mimeType,
178
+ });
179
+ return { label: durableLabel, mimeType: stored.mimeType };
180
+ });
181
+ return {
182
+ ...cloneAnswer(answer),
183
+ ...(custom !== undefined ? { custom } : {}),
184
+ ...(images && images.length > 0 ? { images } : {}),
185
+ };
186
+ });
187
+ return { ...result, answers, imageContents: durableContents };
188
+ }
189
+ function isRequest(value) {
190
+ if (!isPlainRecord(value) || !Array.isArray(value.questions))
191
+ return false;
192
+ return (typeof value.requestId === "string" &&
193
+ (value.source === "tool" || value.source === "worker") &&
194
+ (value.toolCallId === undefined || typeof value.toolCallId === "string") &&
195
+ (value.toolName === undefined || typeof value.toolName === "string") &&
196
+ (value.workerRequestId === undefined || typeof value.workerRequestId === "string") &&
197
+ value.questions.every(isQuestion) &&
198
+ typeof value.acceptsImages === "boolean" &&
199
+ typeof value.createdAt === "string");
200
+ }
201
+ function decodeSnapshot(data) {
202
+ if (!isPlainRecord(data) || data.version !== 1 || !isPlainRecord(data.snapshot))
203
+ return undefined;
204
+ const snapshot = data.snapshot;
205
+ if (!isRequest(snapshot.request) ||
206
+ (snapshot.status !== "pending" && snapshot.status !== "answered" && snapshot.status !== "cancelled") ||
207
+ !Array.isArray(snapshot.answers) ||
208
+ !snapshot.answers.every(isAnswer) ||
209
+ (snapshot.reason !== undefined &&
210
+ snapshot.reason !== "user_cancelled" &&
211
+ snapshot.reason !== "ui_unavailable" &&
212
+ snapshot.reason !== "interrupted" &&
213
+ snapshot.reason !== "invalid_questions") ||
214
+ typeof snapshot.updatedAt !== "string") {
215
+ return undefined;
216
+ }
217
+ return cloneSnapshot(snapshot);
218
+ }
219
+ export function createHumanInputRequest(options) {
220
+ const now = options.now?.() ?? new Date().toISOString();
221
+ return {
222
+ requestId: `human-input:${options.toolCallId ?? options.workerRequestId ?? randomUUID()}`,
223
+ source: options.source,
224
+ ...(options.toolCallId ? { toolCallId: options.toolCallId } : {}),
225
+ ...(options.toolName ? { toolName: options.toolName } : {}),
226
+ ...(options.workerRequestId ? { workerRequestId: options.workerRequestId } : {}),
227
+ questions: options.questions.map(cloneQuestion),
228
+ acceptsImages: options.acceptsImages,
229
+ createdAt: now,
230
+ };
231
+ }
232
+ export function appendHumanInputSnapshot(sessionManager, snapshot) {
233
+ const payload = { version: 1, snapshot: cloneSnapshot(snapshot) };
234
+ return sessionManager.appendCustomEntry(HUMAN_INPUT_CUSTOM_TYPE, payload);
235
+ }
236
+ export function beginHumanInputRequest(sessionManager, request) {
237
+ const snapshot = {
238
+ request: cloneRequest(request),
239
+ status: "pending",
240
+ answers: [],
241
+ updatedAt: request.createdAt,
242
+ };
243
+ appendHumanInputSnapshot(sessionManager, snapshot);
244
+ return snapshot;
245
+ }
246
+ export function getHumanInputSnapshots(entries) {
247
+ const snapshots = [];
248
+ for (const entry of entries) {
249
+ if (entry.type !== "custom" || entry.customType !== HUMAN_INPUT_CUSTOM_TYPE)
250
+ continue;
251
+ const snapshot = decodeSnapshot(entry.data);
252
+ if (snapshot)
253
+ snapshots.push(snapshot);
254
+ }
255
+ return snapshots;
256
+ }
257
+ export function getLatestHumanInputSnapshots(source) {
258
+ const latest = new Map();
259
+ for (const snapshot of getHumanInputSnapshots(getActiveSessionBranchEntries(source))) {
260
+ latest.set(snapshot.request.requestId, snapshot);
261
+ }
262
+ return [...latest.values()];
263
+ }
264
+ export function getWorkerHumanInputsRequiringDelivery(source) {
265
+ const entries = getActiveSessionBranchEntries(source);
266
+ const deliveredRequestIds = new Set(entries.flatMap((entry) => {
267
+ if (entry.type !== "custom_message" ||
268
+ entry.customType !== HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE ||
269
+ !isPlainRecord(entry.details) ||
270
+ typeof entry.details.requestId !== "string") {
271
+ return [];
272
+ }
273
+ return [entry.details.requestId];
274
+ }));
275
+ return getLatestHumanInputSnapshots(source)
276
+ .filter((snapshot) => snapshot.request.source === "worker" && !deliveredRequestIds.has(snapshot.request.requestId))
277
+ .sort((left, right) => left.updatedAt.localeCompare(right.updatedAt));
278
+ }
279
+ export function getResumableHumanInputSnapshot(source) {
280
+ const entries = getActiveSessionBranchEntries(source);
281
+ const requestedToolCalls = new Set(entries.flatMap((entry) => entry.type === "message" && entry.message.role === "assistant"
282
+ ? entry.message.content.flatMap((part) => (part.type === "toolCall" ? [part.id] : []))
283
+ : []));
284
+ const answeredToolCalls = new Set(entries.flatMap((entry) => entry.type === "message" && entry.message.role === "toolResult" ? [entry.message.toolCallId] : []));
285
+ return getLatestHumanInputSnapshots(source)
286
+ .filter((snapshot) => snapshot.request.source === "tool" &&
287
+ snapshot.request.toolCallId !== undefined &&
288
+ requestedToolCalls.has(snapshot.request.toolCallId) &&
289
+ !answeredToolCalls.has(snapshot.request.toolCallId))
290
+ .sort((left, right) => right.updatedAt.localeCompare(left.updatedAt))[0];
291
+ }
292
+ function preview(value) {
293
+ if (value.length <= HUMAN_INPUT_PREVIEW_CHARS)
294
+ return value;
295
+ return `${value.slice(0, HUMAN_INPUT_PREVIEW_CHARS)}…`;
296
+ }
297
+ function externalizeAnswer(request, answer, artifactStore) {
298
+ if (!answer.custom || Buffer.byteLength(answer.custom, "utf8") <= HUMAN_INPUT_INLINE_BYTES || !artifactStore) {
299
+ return cloneAnswer(answer);
300
+ }
301
+ const record = artifactStore.write({
302
+ kind: "transcript_slice",
303
+ content: answer.custom,
304
+ toolName: request.toolName ?? "human_input",
305
+ sessionEntryId: request.requestId,
306
+ createdAtTurn: 0,
307
+ reproducible: false,
308
+ });
309
+ if (!artifactStore.addReference(record.ref.id, request.requestId)) {
310
+ throw new Error(`Failed to retain human-input artifact ${record.ref.id}`);
311
+ }
312
+ return {
313
+ ...cloneAnswer(answer),
314
+ custom: preview(answer.custom),
315
+ customArtifact: record.ref,
316
+ };
317
+ }
318
+ export async function resolveHumanInput(options) {
319
+ const now = options.now ?? (() => new Date().toISOString());
320
+ let result;
321
+ if (options.signal?.aborted) {
322
+ result = { answers: [], cancelled: true, reason: "interrupted", imageContents: [] };
323
+ }
324
+ else {
325
+ result = persistPresentationImages(normalizePresentationResult(options.request, await options.present({
326
+ requestId: options.request.requestId,
327
+ questions: options.request.questions,
328
+ acceptsImages: options.request.acceptsImages,
329
+ }, { signal: options.signal })), options.getImageStore?.());
330
+ }
331
+ const answers = result.answers.map((answer) => externalizeAnswer(options.request, answer, options.artifactStore));
332
+ const snapshot = {
333
+ request: cloneRequest(options.request),
334
+ status: result.cancelled ? "cancelled" : "answered",
335
+ answers,
336
+ ...(result.reason ? { reason: result.reason } : {}),
337
+ updatedAt: now(),
338
+ };
339
+ appendHumanInputSnapshot(options.sessionManager, snapshot);
340
+ return { snapshot, imageContents: result.cancelled ? [] : result.imageContents };
341
+ }
342
+ export function formatHumanInputAnswerText(snapshot) {
343
+ if (snapshot.status === "cancelled") {
344
+ return snapshot.reason === "interrupted"
345
+ ? "User question was interrupted."
346
+ : snapshot.reason === "ui_unavailable"
347
+ ? "User input is unavailable in this host."
348
+ : "User cancelled the question without submitting answers.";
349
+ }
350
+ return snapshot.answers
351
+ .map((answer) => {
352
+ if (answer.skipped)
353
+ return `${answer.header}: user skipped this question`;
354
+ const values = [...answer.selected, ...(answer.custom ? [answer.custom] : [])];
355
+ const artifact = answer.customArtifact
356
+ ? `\nFull answer: artifact tool-output:${answer.customArtifact.id} (${answer.customArtifact.byteLength} bytes)`
357
+ : "";
358
+ return `${answer.header}: ${values.length > 1 ? "user selected" : "user answered"}: ${values.join(", ")}${artifact}`;
359
+ })
360
+ .join("\n");
361
+ }
362
+ //# sourceMappingURL=human-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"human-input.js","sourceRoot":"","sources":["../../src/core/human-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EAAE,6BAA6B,EAAiC,MAAM,uBAAuB,CAAC;AACrG,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,MAAM,CAAC,MAAM,uBAAuB,GAAG,qBAAqB,CAAC;AAC7D,MAAM,CAAC,MAAM,uCAAuC,GAAG,uBAAuB,CAAC;AAC/E,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,CAAC;AAClD,MAAM,yBAAyB,GAAG,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AAE,KAAK,MAAM,CAAC,cAAc,CAAC,UAAU,SAAS;YAC/G,CAAC,CAAC,EAAE,CAAC;QACN,OAAO,GAAG,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE,CAAC;IAAA,CACrH,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACb","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"]}
@@ -3,10 +3,18 @@
3
3
  */
4
4
  export type { CompactionResult } from "@caupulican/pi-agent-core/node";
5
5
  export { AgentSession, type AgentSessionConfig, type AgentSessionEvent, type AgentSessionEventListener, type ModelCycleResult, type PromptOptions, type SessionStats, } from "./agent-session.ts";
6
- export { AgentSessionRuntime, type CreateAgentSessionRuntimeFactory, type CreateAgentSessionRuntimeResult, createAgentSessionRuntime, } from "./agent-session-runtime.ts";
6
+ export { AgentSessionRuntime, type AgentSessionRuntimeResource, type AgentSessionSwitchOptions, type CreateAgentSessionRuntimeFactory, type CreateAgentSessionRuntimeResult, createAgentSessionRuntime, SessionReplacementCallbackError, SessionReplacementRuntimeError, } from "./agent-session-runtime.ts";
7
7
  export { type AgentSessionRuntimeDiagnostic, type AgentSessionServices, type CreateAgentSessionFromServicesOptions, type CreateAgentSessionServicesOptions, createAgentSessionFromServices, createAgentSessionServices, } from "./agent-session-services.ts";
8
8
  export { type BashExecutorOptions, type BashResult, executeBashWithOperations } from "./bash-executor.ts";
9
9
  export { createEventBus, type EventBus, type EventBusController } from "./event-bus.ts";
10
10
  export { type AgentEndEvent, type AgentStartEvent, type AgentToolResult, type AgentToolUpdateCallback, type BeforeAgentStartEvent, type BeforeAgentStartEventResult, type BuildSystemPromptOptions, type ContextEvent, defineTool, discoverAndLoadExtensions, type ExecOptions, type ExecResult, type Extension, type ExtensionAPI, type ExtensionCommandContext, type ExtensionContext, type ExtensionError, type ExtensionEvent, type ExtensionFactory, type ExtensionFlag, type ExtensionHandler, ExtensionRunner, type ExtensionShortcut, type ExtensionUIContext, type LoadExtensionsResult, type MessageRenderer, type RegisteredCommand, type SessionBeforeCompactEvent, type SessionBeforeForkEvent, type SessionBeforeSwitchEvent, type SessionBeforeTreeEvent, type SessionCompactEvent, type SessionShutdownEvent, type SessionStartEvent, type SessionTreeEvent, type ToolCallEvent, type ToolCallEventResult, type ToolDefinition, type ToolRenderResultOptions, type ToolResultEvent, type TurnEndEvent, type TurnStartEvent, type WorkingIndicatorOptions, } from "./extensions/index.ts";
11
+ export * from "./orchestration/capability-gateway.ts";
12
+ export * from "./orchestration/contracts.ts";
13
+ export * from "./orchestration/event-store.ts";
14
+ export * from "./orchestration/model-binding.ts";
15
+ export * from "./orchestration/policy-compiler.ts";
16
+ export * from "./orchestration/profile-registry.ts";
17
+ export * from "./orchestration/profile-store.ts";
18
+ export * from "./orchestration/task-runtime.ts";
11
19
  export { createSyntheticSourceInfo } from "./source-info.ts";
12
20
  //# sourceMappingURL=index.d.ts.map