@caupulican/pi-adaptative 0.81.42 → 0.84.1

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 (1414) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/bun/cli.d.ts.map +1 -1
  3. package/dist/bun/cli.js.map +1 -1
  4. package/dist/bun/register-bedrock.d.ts.map +1 -1
  5. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  6. package/dist/bun/restore-sandbox-env.js.map +1 -1
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +52 -49
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +62 -57
  13. package/dist/bundled-resources/prompts/skillify.md +1 -1
  14. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/fs.py +16 -19
  15. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/search.py +12 -26
  16. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/strings.py +15 -121
  17. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +52 -79
  18. package/dist/bundled-resources/runtimes/pi-shell-engine/escapes.py +70 -0
  19. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +110 -61
  20. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +106 -23
  21. package/dist/bundled-resources/runtimes/pi-shell-engine/paths.py +10 -0
  22. package/dist/bundled-resources/runtimes/pi-shell-engine/proc.py +12 -4
  23. package/dist/bundled-resources/runtimes/pi-shell-engine/shell_args.py +22 -0
  24. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +9 -2
  25. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +129 -259
  26. package/dist/bundled-resources/skills/authorized-web-security-audit/SKILL.md +187 -0
  27. package/dist/bundled-resources/skills/authorized-web-security-audit/references/assessment-contract.md +92 -0
  28. package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +134 -0
  29. package/dist/bundled-resources/skills/evidence-gated-tdd/SKILL.md +93 -0
  30. package/dist/bundled-resources/skills/evidence-gated-tdd/references/evidence-model.md +27 -0
  31. package/dist/bundled-resources/skills/evidence-gated-tdd/references/security-scanners.md +24 -0
  32. package/dist/bundled-resources/skills/harness-self-adaptation/SKILL.md +4 -2
  33. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/SKILL.md +217 -0
  34. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/defensive-exploit-catalogue.md +175 -0
  35. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/tool-boundary-checklist.md +87 -0
  36. package/dist/bundled-resources/skills/skill-architect/SKILL.md +2 -2
  37. package/dist/bundled-resources/skills/skill-creator/SKILL.md +188 -0
  38. package/dist/bundled-resources/skills/skill-creator/references/pi-skill-contract.md +73 -0
  39. package/dist/bundled-resources/skills/skill-creator/scripts/init-skill.mjs +142 -0
  40. package/dist/bundled-resources/skills/skill-creator/scripts/validate-skill.mjs +122 -0
  41. package/dist/cli/args.d.ts.map +1 -1
  42. package/dist/cli/args.js.map +1 -1
  43. package/dist/cli/config-selector.d.ts.map +1 -1
  44. package/dist/cli/config-selector.js.map +1 -1
  45. package/dist/cli/file-processor.d.ts.map +1 -1
  46. package/dist/cli/file-processor.js +8 -8
  47. package/dist/cli/file-processor.js.map +1 -1
  48. package/dist/cli/initial-message.d.ts +1 -1
  49. package/dist/cli/initial-message.d.ts.map +1 -1
  50. package/dist/cli/initial-message.js.map +1 -1
  51. package/dist/cli/list-models.d.ts.map +1 -1
  52. package/dist/cli/list-models.js.map +1 -1
  53. package/dist/cli/piped-stdin.d.ts +4 -0
  54. package/dist/cli/piped-stdin.d.ts.map +1 -0
  55. package/dist/cli/piped-stdin.js +13 -0
  56. package/dist/cli/piped-stdin.js.map +1 -0
  57. package/dist/cli/session-picker.d.ts.map +1 -1
  58. package/dist/cli/session-picker.js.map +1 -1
  59. package/dist/cli.d.ts.map +1 -1
  60. package/dist/cli.js.map +1 -1
  61. package/dist/config.d.ts +1 -1
  62. package/dist/config.d.ts.map +1 -1
  63. package/dist/config.js +10 -15
  64. package/dist/config.js.map +1 -1
  65. package/dist/core/agent-directory-layout.d.ts.map +1 -1
  66. package/dist/core/agent-directory-layout.js.map +1 -1
  67. package/dist/core/agent-paths.d.ts +1 -1
  68. package/dist/core/agent-paths.d.ts.map +1 -1
  69. package/dist/core/agent-paths.js +1 -1
  70. package/dist/core/agent-paths.js.map +1 -1
  71. package/dist/core/agent-session-contracts.d.ts +5 -9
  72. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  73. package/dist/core/agent-session-contracts.js +1 -12
  74. package/dist/core/agent-session-contracts.js.map +1 -1
  75. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  76. package/dist/core/agent-session-runtime.js +10 -25
  77. package/dist/core/agent-session-runtime.js.map +1 -1
  78. package/dist/core/agent-session-services.d.ts.map +1 -1
  79. package/dist/core/agent-session-services.js.map +1 -1
  80. package/dist/core/agent-session.d.ts +24 -1
  81. package/dist/core/agent-session.d.ts.map +1 -1
  82. package/dist/core/agent-session.js +210 -237
  83. package/dist/core/agent-session.js.map +1 -1
  84. package/dist/core/auth-guidance.d.ts.map +1 -1
  85. package/dist/core/auth-guidance.js.map +1 -1
  86. package/dist/core/auth-storage.d.ts +4 -1
  87. package/dist/core/auth-storage.d.ts.map +1 -1
  88. package/dist/core/auth-storage.js +13 -39
  89. package/dist/core/auth-storage.js.map +1 -1
  90. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  91. package/dist/core/autonomy/approval-gate.js.map +1 -1
  92. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  93. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  94. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  95. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  96. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  97. package/dist/core/autonomy/evidence-finding-projection.d.ts +11 -0
  98. package/dist/core/autonomy/evidence-finding-projection.d.ts.map +1 -0
  99. package/dist/core/autonomy/evidence-finding-projection.js +37 -0
  100. package/dist/core/autonomy/evidence-finding-projection.js.map +1 -0
  101. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  102. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  103. package/dist/core/autonomy/gates.d.ts.map +1 -1
  104. package/dist/core/autonomy/gates.js.map +1 -1
  105. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -1
  106. package/dist/core/autonomy/lane-private-paths.js.map +1 -1
  107. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  108. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  109. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  110. package/dist/core/autonomy/lane-tracker.js +2 -3
  111. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  112. package/dist/core/autonomy/path-scope.d.ts.map +1 -1
  113. package/dist/core/autonomy/path-scope.js.map +1 -1
  114. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  115. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  116. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  117. package/dist/core/autonomy/status.d.ts.map +1 -1
  118. package/dist/core/autonomy/status.js.map +1 -1
  119. package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
  120. package/dist/core/autonomy/subagent-prompt.js.map +1 -1
  121. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  122. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  123. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  124. package/dist/core/autonomy-telemetry.js +2 -4
  125. package/dist/core/autonomy-telemetry.js.map +1 -1
  126. package/dist/core/background-lane-controller.d.ts.map +1 -1
  127. package/dist/core/background-lane-controller.js +2 -15
  128. package/dist/core/background-lane-controller.js.map +1 -1
  129. package/dist/core/background-tool-task-controller.d.ts +88 -0
  130. package/dist/core/background-tool-task-controller.d.ts.map +1 -0
  131. package/dist/core/background-tool-task-controller.js +470 -0
  132. package/dist/core/background-tool-task-controller.js.map +1 -0
  133. package/dist/core/bash-execution-controller.d.ts +1 -0
  134. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  135. package/dist/core/bash-execution-controller.js +5 -4
  136. package/dist/core/bash-execution-controller.js.map +1 -1
  137. package/dist/core/bash-executor.d.ts.map +1 -1
  138. package/dist/core/bash-executor.js.map +1 -1
  139. package/dist/core/bedrock-sso-login.d.ts.map +1 -1
  140. package/dist/core/bedrock-sso-login.js.map +1 -1
  141. package/dist/core/billing-failover-controller.d.ts.map +1 -1
  142. package/dist/core/billing-failover-controller.js +3 -3
  143. package/dist/core/billing-failover-controller.js.map +1 -1
  144. package/dist/core/billing-failover.d.ts.map +1 -1
  145. package/dist/core/billing-failover.js.map +1 -1
  146. package/dist/core/capability-contract.d.ts.map +1 -1
  147. package/dist/core/catalog-manager.d.ts.map +1 -1
  148. package/dist/core/catalog-manager.js +0 -0
  149. package/dist/core/catalog-manager.js.map +1 -1
  150. package/dist/core/compaction-controller.d.ts +2 -0
  151. package/dist/core/compaction-controller.d.ts.map +1 -1
  152. package/dist/core/compaction-controller.js +21 -8
  153. package/dist/core/compaction-controller.js.map +1 -1
  154. package/dist/core/compaction-support.d.ts +8 -0
  155. package/dist/core/compaction-support.d.ts.map +1 -1
  156. package/dist/core/compaction-support.js +0 -2
  157. package/dist/core/compaction-support.js.map +1 -1
  158. package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
  159. package/dist/core/context/artifact-retrieval.js.map +1 -1
  160. package/dist/core/context/brain-curator.d.ts.map +1 -1
  161. package/dist/core/context/brain-curator.js +14 -33
  162. package/dist/core/context/brain-curator.js.map +1 -1
  163. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  164. package/dist/core/context/context-artifacts.js +16 -24
  165. package/dist/core/context/context-artifacts.js.map +1 -1
  166. package/dist/core/context/context-audit.d.ts.map +1 -1
  167. package/dist/core/context/context-audit.js +3 -17
  168. package/dist/core/context/context-audit.js.map +1 -1
  169. package/dist/core/context/context-composition.d.ts.map +1 -1
  170. package/dist/core/context/context-composition.js.map +1 -1
  171. package/dist/core/context/context-item.d.ts.map +1 -1
  172. package/dist/core/context/context-item.js.map +1 -1
  173. package/dist/core/context/context-prompt-enforcement.d.ts.map +1 -1
  174. package/dist/core/context/context-prompt-enforcement.js +3 -16
  175. package/dist/core/context/context-prompt-enforcement.js.map +1 -1
  176. package/dist/core/context/context-prompt-policy.d.ts.map +1 -1
  177. package/dist/core/context/context-prompt-policy.js.map +1 -1
  178. package/dist/core/context/context-retention.d.ts.map +1 -1
  179. package/dist/core/context/context-retention.js.map +1 -1
  180. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  181. package/dist/core/context/context-store-retention.js.map +1 -1
  182. package/dist/core/context/context-store.d.ts.map +1 -1
  183. package/dist/core/context/context-store.js.map +1 -1
  184. package/dist/core/context/context-tool-result.d.ts +4 -0
  185. package/dist/core/context/context-tool-result.d.ts.map +1 -0
  186. package/dist/core/context/context-tool-result.js +15 -0
  187. package/dist/core/context/context-tool-result.js.map +1 -0
  188. package/dist/core/context/current-work-memory.d.ts.map +1 -1
  189. package/dist/core/context/current-work-memory.js.map +1 -1
  190. package/dist/core/context/file-store-memory-provider.d.ts.map +1 -1
  191. package/dist/core/context/file-store-memory-provider.js +7 -28
  192. package/dist/core/context/file-store-memory-provider.js.map +1 -1
  193. package/dist/core/context/local-memory-search.d.ts +11 -0
  194. package/dist/core/context/local-memory-search.d.ts.map +1 -0
  195. package/dist/core/context/local-memory-search.js +37 -0
  196. package/dist/core/context/local-memory-search.js.map +1 -0
  197. package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
  198. package/dist/core/context/long-term-memory-trigger.js.map +1 -1
  199. package/dist/core/context/memory-diagnostics.d.ts.map +1 -1
  200. package/dist/core/context/memory-diagnostics.js.map +1 -1
  201. package/dist/core/context/memory-index-store.d.ts.map +1 -1
  202. package/dist/core/context/memory-index-store.js.map +1 -1
  203. package/dist/core/context/memory-prompt-block.d.ts.map +1 -1
  204. package/dist/core/context/memory-prompt-block.js.map +1 -1
  205. package/dist/core/context/memory-prompt-budget.d.ts.map +1 -1
  206. package/dist/core/context/memory-prompt-budget.js.map +1 -1
  207. package/dist/core/context/memory-provider-contract.d.ts.map +1 -1
  208. package/dist/core/context/memory-provider-contract.js.map +1 -1
  209. package/dist/core/context/memory-retrieval.d.ts.map +1 -1
  210. package/dist/core/context/memory-retrieval.js.map +1 -1
  211. package/dist/core/context/memory-tier-composer.d.ts.map +1 -1
  212. package/dist/core/context/memory-tier-composer.js.map +1 -1
  213. package/dist/core/context/message-text.d.ts +7 -0
  214. package/dist/core/context/message-text.d.ts.map +1 -0
  215. package/dist/core/context/message-text.js +68 -0
  216. package/dist/core/context/message-text.js.map +1 -0
  217. package/dist/core/context/okf-memory-provider.d.ts.map +1 -1
  218. package/dist/core/context/okf-memory-provider.js +4 -30
  219. package/dist/core/context/okf-memory-provider.js.map +1 -1
  220. package/dist/core/context/okf-memory.d.ts.map +1 -1
  221. package/dist/core/context/okf-memory.js.map +1 -1
  222. package/dist/core/context/policy-engine.d.ts.map +1 -1
  223. package/dist/core/context/policy-engine.js.map +1 -1
  224. package/dist/core/context/policy-types.d.ts.map +1 -1
  225. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  226. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  227. package/dist/core/context/storage-authority.d.ts.map +1 -1
  228. package/dist/core/context/tool-output-packer.d.ts.map +1 -1
  229. package/dist/core/context/tool-output-packer.js.map +1 -1
  230. package/dist/core/context-gc.d.ts.map +1 -1
  231. package/dist/core/context-gc.js +14 -21
  232. package/dist/core/context-gc.js.map +1 -1
  233. package/dist/core/context-pipeline.d.ts +1 -3
  234. package/dist/core/context-pipeline.d.ts.map +1 -1
  235. package/dist/core/context-pipeline.js +64 -145
  236. package/dist/core/context-pipeline.js.map +1 -1
  237. package/dist/core/cost/cost-summary.d.ts.map +1 -1
  238. package/dist/core/cost/cost-summary.js.map +1 -1
  239. package/dist/core/cost/daily-usage.d.ts.map +1 -1
  240. package/dist/core/cost/daily-usage.js.map +1 -1
  241. package/dist/core/cost/session-usage.d.ts.map +1 -1
  242. package/dist/core/cost/session-usage.js.map +1 -1
  243. package/dist/core/cost-guard.d.ts.map +1 -1
  244. package/dist/core/cost-guard.js.map +1 -1
  245. package/dist/core/default-tool-surface.d.ts.map +1 -1
  246. package/dist/core/default-tool-surface.js +1 -0
  247. package/dist/core/default-tool-surface.js.map +1 -1
  248. package/dist/core/defaults.d.ts.map +1 -1
  249. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  250. package/dist/core/delegation/managed-lane-controller.js +2 -6
  251. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  252. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
  253. package/dist/core/delegation/session-worker-claim.js.map +1 -1
  254. package/dist/core/delegation/worker-action-journal.d.ts.map +1 -1
  255. package/dist/core/delegation/worker-action-journal.js +0 -4
  256. package/dist/core/delegation/worker-action-journal.js.map +1 -1
  257. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  258. package/dist/core/delegation/worker-actions.js.map +1 -1
  259. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +1 -0
  260. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
  261. package/dist/core/delegation/worker-agent-control-coordinator.js +13 -15
  262. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  263. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
  264. package/dist/core/delegation/worker-agent-control.js +1 -4
  265. package/dist/core/delegation/worker-agent-control.js.map +1 -1
  266. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  267. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  268. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  269. package/dist/core/delegation/worker-claim.js.map +1 -1
  270. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
  271. package/dist/core/delegation/worker-conversation-store.js +0 -2
  272. package/dist/core/delegation/worker-conversation-store.js.map +1 -1
  273. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  274. package/dist/core/delegation/worker-delegation-controller.js +5 -14
  275. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  276. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  277. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
  278. package/dist/core/delegation/worker-dispatch-scheduler.js +5 -6
  279. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
  280. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  281. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  282. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
  283. package/dist/core/delegation/worker-lane-projection.js.map +1 -1
  284. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  285. package/dist/core/delegation/worker-lifecycle.js +0 -3
  286. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  287. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
  288. package/dist/core/delegation/worker-notification-coordinator.js +4 -5
  289. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
  290. package/dist/core/delegation/worker-process-owner.d.ts.map +1 -1
  291. package/dist/core/delegation/worker-process-owner.js.map +1 -1
  292. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  293. package/dist/core/delegation/worker-profile-resolver.js +1 -2
  294. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  295. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
  296. package/dist/core/delegation/worker-recovery-coordinator.js +3 -4
  297. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
  298. package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -1
  299. package/dist/core/delegation/worker-resource-catalog.js.map +1 -1
  300. package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -1
  301. package/dist/core/delegation/worker-resource-materializer.js +1 -4
  302. package/dist/core/delegation/worker-resource-materializer.js.map +1 -1
  303. package/dist/core/delegation/worker-runner.d.ts +2 -4
  304. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  305. package/dist/core/delegation/worker-runner.js +6 -18
  306. package/dist/core/delegation/worker-runner.js.map +1 -1
  307. package/dist/core/delegation/worker-task-label.d.ts.map +1 -1
  308. package/dist/core/delegation/worker-task-label.js.map +1 -1
  309. package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -1
  310. package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -1
  311. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
  312. package/dist/core/delegation/worker-write-reservation-coordinator.js +1 -4
  313. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
  314. package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -1
  315. package/dist/core/delegation/worker-write-reservation.js +0 -2
  316. package/dist/core/delegation/worker-write-reservation.js.map +1 -1
  317. package/dist/core/diagnostics.d.ts.map +1 -1
  318. package/dist/core/doctor.d.ts +5 -5
  319. package/dist/core/doctor.d.ts.map +1 -1
  320. package/dist/core/doctor.js +16 -20
  321. package/dist/core/doctor.js.map +1 -1
  322. package/dist/core/event-bus.d.ts.map +1 -1
  323. package/dist/core/event-bus.js.map +1 -1
  324. package/dist/core/exec.d.ts.map +1 -1
  325. package/dist/core/exec.js +26 -7
  326. package/dist/core/exec.js.map +1 -1
  327. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  328. package/dist/core/export-html/ansi-to-html.js +21 -74
  329. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  330. package/dist/core/export-html/index.d.ts.map +1 -1
  331. package/dist/core/export-html/index.js +4 -0
  332. package/dist/core/export-html/index.js.map +1 -1
  333. package/dist/core/export-html/session-tree-foundations.d.mts +67 -0
  334. package/dist/core/export-html/session-tree-foundations.mjs +313 -0
  335. package/dist/core/export-html/template.css +14 -41
  336. package/dist/core/export-html/template.html +3 -1
  337. package/dist/core/export-html/template.js +26 -435
  338. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  339. package/dist/core/export-html/tool-renderer.js.map +1 -1
  340. package/dist/core/extension-import-authority.d.ts.map +1 -1
  341. package/dist/core/extension-import-authority.js.map +1 -1
  342. package/dist/core/extension-metadata.d.ts.map +1 -1
  343. package/dist/core/extension-metadata.js.map +1 -1
  344. package/dist/core/extensions/builtin.d.ts +17 -0
  345. package/dist/core/extensions/builtin.d.ts.map +1 -1
  346. package/dist/core/extensions/builtin.js +18 -54
  347. package/dist/core/extensions/builtin.js.map +1 -1
  348. package/dist/core/extensions/entry-resolution.d.ts +3 -0
  349. package/dist/core/extensions/entry-resolution.d.ts.map +1 -0
  350. package/dist/core/extensions/entry-resolution.js +17 -0
  351. package/dist/core/extensions/entry-resolution.js.map +1 -0
  352. package/dist/core/extensions/index.d.ts.map +1 -1
  353. package/dist/core/extensions/loader.d.ts.map +1 -1
  354. package/dist/core/extensions/loader.js +76 -21
  355. package/dist/core/extensions/loader.js.map +1 -1
  356. package/dist/core/extensions/runner.d.ts +2 -0
  357. package/dist/core/extensions/runner.d.ts.map +1 -1
  358. package/dist/core/extensions/runner.js +41 -112
  359. package/dist/core/extensions/runner.js.map +1 -1
  360. package/dist/core/extensions/stale-context.d.ts.map +1 -1
  361. package/dist/core/extensions/storage.d.ts.map +1 -1
  362. package/dist/core/extensions/storage.js.map +1 -1
  363. package/dist/core/extensions/types.d.ts.map +1 -1
  364. package/dist/core/extensions/types.js.map +1 -1
  365. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  366. package/dist/core/extensions/wrapper.js.map +1 -1
  367. package/dist/core/failure-corpus.d.ts.map +1 -1
  368. package/dist/core/failure-corpus.js +2 -5
  369. package/dist/core/failure-corpus.js.map +1 -1
  370. package/dist/core/footer-data-provider.d.ts.map +1 -1
  371. package/dist/core/footer-data-provider.js +27 -33
  372. package/dist/core/footer-data-provider.js.map +1 -1
  373. package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
  374. package/dist/core/foreground-recovery-controller.js +0 -4
  375. package/dist/core/foreground-recovery-controller.js.map +1 -1
  376. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  377. package/dist/core/gateways/channel-provider.js +7 -5
  378. package/dist/core/gateways/channel-provider.js.map +1 -1
  379. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  380. package/dist/core/goal-loop-controller.js +0 -1
  381. package/dist/core/goal-loop-controller.js.map +1 -1
  382. package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
  383. package/dist/core/goals/compact-goal-context.js +2 -4
  384. package/dist/core/goals/compact-goal-context.js.map +1 -1
  385. package/dist/core/goals/goal-acceptance.d.ts.map +1 -1
  386. package/dist/core/goals/goal-acceptance.js.map +1 -1
  387. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
  388. package/dist/core/goals/goal-auto-continue-controller.js +1 -3
  389. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
  390. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  391. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  392. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  393. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  394. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  395. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
  396. package/dist/core/goals/goal-lifecycle.js.map +1 -1
  397. package/dist/core/goals/goal-record.d.ts.map +1 -1
  398. package/dist/core/goals/goal-record.js.map +1 -1
  399. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  400. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  401. package/dist/core/goals/goal-session-controller.d.ts +15 -0
  402. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  403. package/dist/core/goals/goal-session-controller.js +27 -3
  404. package/dist/core/goals/goal-session-controller.js.map +1 -1
  405. package/dist/core/goals/goal-state.d.ts.map +1 -1
  406. package/dist/core/goals/goal-state.js +35 -51
  407. package/dist/core/goals/goal-state.js.map +1 -1
  408. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  409. package/dist/core/goals/goal-tool-core.js.map +1 -1
  410. package/dist/core/goals/natural-language-goal.d.ts +9 -0
  411. package/dist/core/goals/natural-language-goal.d.ts.map +1 -0
  412. package/dist/core/goals/natural-language-goal.js +23 -0
  413. package/dist/core/goals/natural-language-goal.js.map +1 -0
  414. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  415. package/dist/core/goals/session-goal-state.js.map +1 -1
  416. package/dist/core/http-dispatcher.d.ts.map +1 -1
  417. package/dist/core/http-dispatcher.js.map +1 -1
  418. package/dist/core/human-input-controller.d.ts.map +1 -1
  419. package/dist/core/human-input-controller.js +2 -3
  420. package/dist/core/human-input-controller.js.map +1 -1
  421. package/dist/core/human-input.d.ts.map +1 -1
  422. package/dist/core/human-input.js.map +1 -1
  423. package/dist/core/improvement-loop.d.ts.map +1 -1
  424. package/dist/core/improvement-loop.js +11 -11
  425. package/dist/core/improvement-loop.js.map +1 -1
  426. package/dist/core/index.d.ts.map +1 -1
  427. package/dist/core/install-telemetry.d.ts.map +1 -1
  428. package/dist/core/install-telemetry.js.map +1 -1
  429. package/dist/core/isolated-text-completion.d.ts +17 -0
  430. package/dist/core/isolated-text-completion.d.ts.map +1 -0
  431. package/dist/core/isolated-text-completion.js +15 -0
  432. package/dist/core/isolated-text-completion.js.map +1 -0
  433. package/dist/core/keybindings.d.ts +47 -2
  434. package/dist/core/keybindings.d.ts.map +1 -1
  435. package/dist/core/keybindings.js +12 -1
  436. package/dist/core/keybindings.js.map +1 -1
  437. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  438. package/dist/core/learning/learning-audit.js.map +1 -1
  439. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  440. package/dist/core/learning/learning-gate.js.map +1 -1
  441. package/dist/core/learning/observation-store.d.ts.map +1 -1
  442. package/dist/core/learning/observation-store.js +0 -2
  443. package/dist/core/learning/observation-store.js.map +1 -1
  444. package/dist/core/learning/reflection-engine.d.ts +1 -1
  445. package/dist/core/learning/reflection-engine.d.ts.map +1 -1
  446. package/dist/core/learning/reflection-engine.js +3 -0
  447. package/dist/core/learning/reflection-engine.js.map +1 -1
  448. package/dist/core/learning/reflection-turn-analysis.d.ts +20 -0
  449. package/dist/core/learning/reflection-turn-analysis.d.ts.map +1 -0
  450. package/dist/core/learning/reflection-turn-analysis.js +136 -0
  451. package/dist/core/learning/reflection-turn-analysis.js.map +1 -0
  452. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  453. package/dist/core/learning/session-learning-decision.js.map +1 -1
  454. package/dist/core/learning/skill-curator.d.ts.map +1 -1
  455. package/dist/core/learning/skill-curator.js +0 -3
  456. package/dist/core/learning/skill-curator.js.map +1 -1
  457. package/dist/core/local-runtime-controller.d.ts +39 -0
  458. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  459. package/dist/core/local-runtime-controller.js +41 -62
  460. package/dist/core/local-runtime-controller.js.map +1 -1
  461. package/dist/core/memory/effectiveness-tracker.d.ts.map +1 -1
  462. package/dist/core/memory/effectiveness-tracker.js +4 -2
  463. package/dist/core/memory/effectiveness-tracker.js.map +1 -1
  464. package/dist/core/memory/memory-manager.d.ts.map +1 -1
  465. package/dist/core/memory/memory-manager.js +7 -7
  466. package/dist/core/memory/memory-manager.js.map +1 -1
  467. package/dist/core/memory/memory-provider.d.ts.map +1 -1
  468. package/dist/core/memory/providers/file-store.d.ts +7 -0
  469. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  470. package/dist/core/memory/providers/file-store.js +48 -13
  471. package/dist/core/memory/providers/file-store.js.map +1 -1
  472. package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts +47 -0
  473. package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts.map +1 -0
  474. package/dist/core/memory/providers/transcript-recall-worker-protocol.js +50 -0
  475. package/dist/core/memory/providers/transcript-recall-worker-protocol.js.map +1 -0
  476. package/dist/core/memory/providers/transcript-recall-worker.d.ts +2 -0
  477. package/dist/core/memory/providers/transcript-recall-worker.d.ts.map +1 -0
  478. package/dist/core/memory/providers/transcript-recall-worker.js +143 -0
  479. package/dist/core/memory/providers/transcript-recall-worker.js.map +1 -0
  480. package/dist/core/memory/providers/transcript-recall.d.ts +24 -13
  481. package/dist/core/memory/providers/transcript-recall.d.ts.map +1 -1
  482. package/dist/core/memory/providers/transcript-recall.js +143 -141
  483. package/dist/core/memory/providers/transcript-recall.js.map +1 -1
  484. package/dist/core/memory/providers/user-memory-archive.d.ts +39 -0
  485. package/dist/core/memory/providers/user-memory-archive.d.ts.map +1 -0
  486. package/dist/core/memory/providers/user-memory-archive.js +258 -0
  487. package/dist/core/memory/providers/user-memory-archive.js.map +1 -0
  488. package/dist/core/memory/transcript-index.d.ts.map +1 -1
  489. package/dist/core/memory/transcript-index.js +1 -1
  490. package/dist/core/memory/transcript-index.js.map +1 -1
  491. package/dist/core/memory-controller.d.ts +9 -0
  492. package/dist/core/memory-controller.d.ts.map +1 -1
  493. package/dist/core/memory-controller.js +57 -16
  494. package/dist/core/memory-controller.js.map +1 -1
  495. package/dist/core/model-capability.d.ts.map +1 -1
  496. package/dist/core/model-capability.js.map +1 -1
  497. package/dist/core/model-output-json.d.ts +10 -0
  498. package/dist/core/model-output-json.d.ts.map +1 -0
  499. package/dist/core/model-output-json.js +43 -0
  500. package/dist/core/model-output-json.js.map +1 -0
  501. package/dist/core/model-registry.d.ts +8 -8
  502. package/dist/core/model-registry.d.ts.map +1 -1
  503. package/dist/core/model-registry.js +29 -52
  504. package/dist/core/model-registry.js.map +1 -1
  505. package/dist/core/model-resolver.d.ts.map +1 -1
  506. package/dist/core/model-resolver.js +1 -1
  507. package/dist/core/model-resolver.js.map +1 -1
  508. package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
  509. package/dist/core/model-router/config-diagnostics.js.map +1 -1
  510. package/dist/core/model-router/executor-route.d.ts.map +1 -1
  511. package/dist/core/model-router/executor-route.js.map +1 -1
  512. package/dist/core/model-router/fitness-gate.d.ts.map +1 -1
  513. package/dist/core/model-router/fitness-gate.js.map +1 -1
  514. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  515. package/dist/core/model-router/route-judge.d.ts.map +1 -1
  516. package/dist/core/model-router/route-judge.js +18 -36
  517. package/dist/core/model-router/route-judge.js.map +1 -1
  518. package/dist/core/model-router/session-buffer.d.ts.map +1 -1
  519. package/dist/core/model-router/session-buffer.js.map +1 -1
  520. package/dist/core/model-router/status.d.ts.map +1 -1
  521. package/dist/core/model-router/status.js.map +1 -1
  522. package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
  523. package/dist/core/model-router/tool-escalation.js.map +1 -1
  524. package/dist/core/model-router-controller.d.ts +1 -0
  525. package/dist/core/model-router-controller.d.ts.map +1 -1
  526. package/dist/core/model-router-controller.js +25 -56
  527. package/dist/core/model-router-controller.js.map +1 -1
  528. package/dist/core/model-selection-controller.d.ts +10 -0
  529. package/dist/core/model-selection-controller.d.ts.map +1 -1
  530. package/dist/core/model-selection-controller.js +0 -1
  531. package/dist/core/model-selection-controller.js.map +1 -1
  532. package/dist/core/model-tool-protocol.d.ts.map +1 -1
  533. package/dist/core/model-tool-protocol.js.map +1 -1
  534. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  535. package/dist/core/models/adaptation-store.js +0 -1
  536. package/dist/core/models/adaptation-store.js.map +1 -1
  537. package/dist/core/models/context-sizing.d.ts.map +1 -1
  538. package/dist/core/models/context-sizing.js.map +1 -1
  539. package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
  540. package/dist/core/models/default-model-suggestions.js.map +1 -1
  541. package/dist/core/models/fitness-store.d.ts.map +1 -1
  542. package/dist/core/models/fitness-store.js +0 -1
  543. package/dist/core/models/fitness-store.js.map +1 -1
  544. package/dist/core/models/host-state-store.d.ts.map +1 -1
  545. package/dist/core/models/host-state-store.js +1 -6
  546. package/dist/core/models/host-state-store.js.map +1 -1
  547. package/dist/core/models/llamacpp-runtime.d.ts +4 -19
  548. package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
  549. package/dist/core/models/llamacpp-runtime.js +32 -136
  550. package/dist/core/models/llamacpp-runtime.js.map +1 -1
  551. package/dist/core/models/local-registration.d.ts.map +1 -1
  552. package/dist/core/models/local-registration.js +82 -115
  553. package/dist/core/models/local-registration.js.map +1 -1
  554. package/dist/core/models/local-runtime.d.ts +12 -18
  555. package/dist/core/models/local-runtime.d.ts.map +1 -1
  556. package/dist/core/models/local-runtime.js +60 -204
  557. package/dist/core/models/local-runtime.js.map +1 -1
  558. package/dist/core/models/model-endpoint.d.ts.map +1 -1
  559. package/dist/core/models/model-endpoint.js.map +1 -1
  560. package/dist/core/models/model-ref.d.ts.map +1 -1
  561. package/dist/core/models/model-ref.js.map +1 -1
  562. package/dist/core/models/needle-runtime.d.ts +7 -3
  563. package/dist/core/models/needle-runtime.d.ts.map +1 -1
  564. package/dist/core/models/needle-runtime.js +16 -92
  565. package/dist/core/models/needle-runtime.js.map +1 -1
  566. package/dist/core/models/perf-profile.d.ts +1 -1
  567. package/dist/core/models/perf-profile.d.ts.map +1 -1
  568. package/dist/core/models/perf-profile.js +6 -13
  569. package/dist/core/models/perf-profile.js.map +1 -1
  570. package/dist/core/models/prism-llamacpp-lifecycle.d.ts.map +1 -1
  571. package/dist/core/models/prism-llamacpp-lifecycle.js.map +1 -1
  572. package/dist/core/models/runtime-arbiter.d.ts.map +1 -1
  573. package/dist/core/models/runtime-arbiter.js +3 -15
  574. package/dist/core/models/runtime-arbiter.js.map +1 -1
  575. package/dist/core/models/runtime-process.d.ts +100 -0
  576. package/dist/core/models/runtime-process.d.ts.map +1 -0
  577. package/dist/core/models/runtime-process.js +183 -0
  578. package/dist/core/models/runtime-process.js.map +1 -0
  579. package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
  580. package/dist/core/orchestration/agent-resume.js.map +1 -1
  581. package/dist/core/orchestration/attempt-usage.d.ts.map +1 -1
  582. package/dist/core/orchestration/attempt-usage.js.map +1 -1
  583. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  584. package/dist/core/orchestration/capability-gateway.js +0 -14
  585. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  586. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  587. package/dist/core/orchestration/contracts.js.map +1 -1
  588. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  589. package/dist/core/orchestration/delegation-ledger.js +0 -2
  590. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  591. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  592. package/dist/core/orchestration/event-store.js +1 -14
  593. package/dist/core/orchestration/event-store.js.map +1 -1
  594. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  595. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  596. package/dist/core/orchestration/model-binding.d.ts.map +1 -1
  597. package/dist/core/orchestration/model-binding.js.map +1 -1
  598. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
  599. package/dist/core/orchestration/policy-compiler.js +0 -3
  600. package/dist/core/orchestration/policy-compiler.js.map +1 -1
  601. package/dist/core/orchestration/policy-gate.d.ts.map +1 -1
  602. package/dist/core/orchestration/policy-gate.js +0 -2
  603. package/dist/core/orchestration/policy-gate.js.map +1 -1
  604. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  605. package/dist/core/orchestration/profile-registry.js +1 -1
  606. package/dist/core/orchestration/profile-registry.js.map +1 -1
  607. package/dist/core/orchestration/profile-store.d.ts.map +1 -1
  608. package/dist/core/orchestration/profile-store.js +0 -3
  609. package/dist/core/orchestration/profile-store.js.map +1 -1
  610. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  611. package/dist/core/orchestration/risk-budget.js.map +1 -1
  612. package/dist/core/orchestration/task-runtime.d.ts +1 -0
  613. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  614. package/dist/core/orchestration/task-runtime.js +27 -42
  615. package/dist/core/orchestration/task-runtime.js.map +1 -1
  616. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
  617. package/dist/core/orchestration/work-state-projection.js.map +1 -1
  618. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  619. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  620. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
  621. package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
  622. package/dist/core/output-guard.d.ts.map +1 -1
  623. package/dist/core/output-guard.js.map +1 -1
  624. package/dist/core/package-manager.d.ts +3 -0
  625. package/dist/core/package-manager.d.ts.map +1 -1
  626. package/dist/core/package-manager.js +88 -353
  627. package/dist/core/package-manager.js.map +1 -1
  628. package/dist/core/process-identity.d.ts.map +1 -1
  629. package/dist/core/process-identity.js.map +1 -1
  630. package/dist/core/process-liveness.d.ts +3 -0
  631. package/dist/core/process-liveness.d.ts.map +1 -0
  632. package/dist/core/process-liveness.js +17 -0
  633. package/dist/core/process-liveness.js.map +1 -0
  634. package/dist/core/process-matrix/codes.d.ts.map +1 -1
  635. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -1
  636. package/dist/core/process-matrix/resume-launcher.js.map +1 -1
  637. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  638. package/dist/core/process-matrix/runtime.js.map +1 -1
  639. package/dist/core/process-matrix/store.d.ts.map +1 -1
  640. package/dist/core/process-matrix/store.js.map +1 -1
  641. package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
  642. package/dist/core/process-matrix/supervisor.js.map +1 -1
  643. package/dist/core/profile-filter-controller.d.ts.map +1 -1
  644. package/dist/core/profile-filter-controller.js +7 -8
  645. package/dist/core/profile-filter-controller.js.map +1 -1
  646. package/dist/core/profile-registry.d.ts.map +1 -1
  647. package/dist/core/profile-registry.js +1 -2
  648. package/dist/core/profile-registry.js.map +1 -1
  649. package/dist/core/profile-resource-selection.d.ts.map +1 -1
  650. package/dist/core/profile-resource-selection.js +18 -59
  651. package/dist/core/profile-resource-selection.js.map +1 -1
  652. package/dist/core/prompt-markup.d.ts +3 -0
  653. package/dist/core/prompt-markup.d.ts.map +1 -0
  654. package/dist/core/prompt-markup.js +7 -0
  655. package/dist/core/prompt-markup.js.map +1 -0
  656. package/dist/core/prompt-templates.d.ts.map +1 -1
  657. package/dist/core/prompt-templates.js +13 -39
  658. package/dist/core/prompt-templates.js.map +1 -1
  659. package/dist/core/provider-display-names.d.ts.map +1 -1
  660. package/dist/core/python-runtime.d.ts.map +1 -1
  661. package/dist/core/python-runtime.js.map +1 -1
  662. package/dist/core/reflection-controller.d.ts +22 -1
  663. package/dist/core/reflection-controller.d.ts.map +1 -1
  664. package/dist/core/reflection-controller.js +143 -25
  665. package/dist/core/reflection-controller.js.map +1 -1
  666. package/dist/core/reload-blockers.d.ts +2 -1
  667. package/dist/core/reload-blockers.d.ts.map +1 -1
  668. package/dist/core/reload-blockers.js +4 -14
  669. package/dist/core/reload-blockers.js.map +1 -1
  670. package/dist/core/request-auth.d.ts.map +1 -1
  671. package/dist/core/request-auth.js.map +1 -1
  672. package/dist/core/research/automata-provider.d.ts.map +1 -1
  673. package/dist/core/research/automata-provider.js.map +1 -1
  674. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  675. package/dist/core/research/evidence-bundle.js.map +1 -1
  676. package/dist/core/research/lane-model-resolver.d.ts.map +1 -1
  677. package/dist/core/research/lane-model-resolver.js +0 -1
  678. package/dist/core/research/lane-model-resolver.js.map +1 -1
  679. package/dist/core/research/model-fitness-controller.d.ts.map +1 -1
  680. package/dist/core/research/model-fitness-controller.js +17 -33
  681. package/dist/core/research/model-fitness-controller.js.map +1 -1
  682. package/dist/core/research/model-fitness.d.ts.map +1 -1
  683. package/dist/core/research/model-fitness.js +4 -25
  684. package/dist/core/research/model-fitness.js.map +1 -1
  685. package/dist/core/research/research-gate.d.ts.map +1 -1
  686. package/dist/core/research/research-gate.js.map +1 -1
  687. package/dist/core/research/research-lane-controller.d.ts.map +1 -1
  688. package/dist/core/research/research-lane-controller.js +5 -10
  689. package/dist/core/research/research-lane-controller.js.map +1 -1
  690. package/dist/core/research/research-runner.d.ts +2 -4
  691. package/dist/core/research/research-runner.d.ts.map +1 -1
  692. package/dist/core/research/research-runner.js +17 -48
  693. package/dist/core/research/research-runner.js.map +1 -1
  694. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  695. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  696. package/dist/core/research/workspace-collector.d.ts.map +1 -1
  697. package/dist/core/research/workspace-collector.js.map +1 -1
  698. package/dist/core/resolve-config-value.d.ts.map +1 -1
  699. package/dist/core/resolve-config-value.js.map +1 -1
  700. package/dist/core/resource-ignore.d.ts +6 -0
  701. package/dist/core/resource-ignore.d.ts.map +1 -0
  702. package/dist/core/resource-ignore.js +44 -0
  703. package/dist/core/resource-ignore.js.map +1 -0
  704. package/dist/core/resource-loader.d.ts +0 -1
  705. package/dist/core/resource-loader.d.ts.map +1 -1
  706. package/dist/core/resource-loader.js +52 -187
  707. package/dist/core/resource-loader.js.map +1 -1
  708. package/dist/core/resource-profile-blocks.d.ts +3 -1
  709. package/dist/core/resource-profile-blocks.d.ts.map +1 -1
  710. package/dist/core/resource-profile-blocks.js +8 -5
  711. package/dist/core/resource-profile-blocks.js.map +1 -1
  712. package/dist/core/resource-profile-equality.d.ts.map +1 -1
  713. package/dist/core/resource-profile-equality.js.map +1 -1
  714. package/dist/core/resource-traversal.d.ts +43 -0
  715. package/dist/core/resource-traversal.d.ts.map +1 -0
  716. package/dist/core/resource-traversal.js +84 -0
  717. package/dist/core/resource-traversal.js.map +1 -0
  718. package/dist/core/risk-classifier.d.ts.map +1 -1
  719. package/dist/core/risk-classifier.js.map +1 -1
  720. package/dist/core/runtime-builder.d.ts +4 -1
  721. package/dist/core/runtime-builder.d.ts.map +1 -1
  722. package/dist/core/runtime-builder.js +25 -50
  723. package/dist/core/runtime-builder.js.map +1 -1
  724. package/dist/core/scout-controller.d.ts.map +1 -1
  725. package/dist/core/scout-controller.js +0 -1
  726. package/dist/core/scout-controller.js.map +1 -1
  727. package/dist/core/sdk.d.ts.map +1 -1
  728. package/dist/core/sdk.js.map +1 -1
  729. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
  730. package/dist/core/secrets/credential-exposure-guard.js +101 -43
  731. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  732. package/dist/core/secrets/secret-dotenv.d.ts.map +1 -1
  733. package/dist/core/secrets/secret-dotenv.js +0 -1
  734. package/dist/core/secrets/secret-dotenv.js.map +1 -1
  735. package/dist/core/secrets/secret-vault-format.d.ts.map +1 -1
  736. package/dist/core/secrets/secret-vault-format.js +0 -1
  737. package/dist/core/secrets/secret-vault-format.js.map +1 -1
  738. package/dist/core/secrets/secret-vault.d.ts.map +1 -1
  739. package/dist/core/secrets/secret-vault.js +2 -10
  740. package/dist/core/secrets/secret-vault.js.map +1 -1
  741. package/dist/core/security/secret-text.d.ts.map +1 -1
  742. package/dist/core/security/secret-text.js.map +1 -1
  743. package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
  744. package/dist/core/security/untrusted-boundary.js.map +1 -1
  745. package/dist/core/session-analytics.d.ts.map +1 -1
  746. package/dist/core/session-analytics.js +18 -50
  747. package/dist/core/session-analytics.js.map +1 -1
  748. package/dist/core/session-artifact-bundle.d.ts.map +1 -1
  749. package/dist/core/session-artifact-bundle.js.map +1 -1
  750. package/dist/core/session-cwd.d.ts.map +1 -1
  751. package/dist/core/session-cwd.js +0 -1
  752. package/dist/core/session-cwd.js.map +1 -1
  753. package/dist/core/session-entry-index.d.ts +8 -0
  754. package/dist/core/session-entry-index.d.ts.map +1 -0
  755. package/dist/core/session-entry-index.js +16 -0
  756. package/dist/core/session-entry-index.js.map +1 -0
  757. package/dist/core/session-image-store.d.ts.map +1 -1
  758. package/dist/core/session-image-store.js +0 -3
  759. package/dist/core/session-image-store.js.map +1 -1
  760. package/dist/core/session-jsonl-writer.d.ts +3 -0
  761. package/dist/core/session-jsonl-writer.d.ts.map +1 -0
  762. package/dist/core/session-jsonl-writer.js +38 -0
  763. package/dist/core/session-jsonl-writer.js.map +1 -0
  764. package/dist/core/session-manager-factory.d.ts.map +1 -1
  765. package/dist/core/session-manager-factory.js.map +1 -1
  766. package/dist/core/session-role.d.ts.map +1 -1
  767. package/dist/core/session-role.js.map +1 -1
  768. package/dist/core/session-snapshot.d.ts.map +1 -1
  769. package/dist/core/session-snapshot.js.map +1 -1
  770. package/dist/core/session-supervision-runtime.d.ts.map +1 -1
  771. package/dist/core/session-supervision-runtime.js +1 -4
  772. package/dist/core/session-supervision-runtime.js.map +1 -1
  773. package/dist/core/session-tree-navigator.d.ts.map +1 -1
  774. package/dist/core/session-tree-navigator.js +0 -1
  775. package/dist/core/session-tree-navigator.js.map +1 -1
  776. package/dist/core/settings-manager.d.ts +2 -1
  777. package/dist/core/settings-manager.d.ts.map +1 -1
  778. package/dist/core/settings-manager.js +64 -162
  779. package/dist/core/settings-manager.js.map +1 -1
  780. package/dist/core/skill-block.d.mts +8 -0
  781. package/dist/core/skill-block.mjs +52 -0
  782. package/dist/core/skill-discovery.d.ts +5 -0
  783. package/dist/core/skill-discovery.d.ts.map +1 -0
  784. package/dist/core/skill-discovery.js +34 -0
  785. package/dist/core/skill-discovery.js.map +1 -0
  786. package/dist/core/skills.d.ts.map +1 -1
  787. package/dist/core/skills.js +23 -159
  788. package/dist/core/skills.js.map +1 -1
  789. package/dist/core/slash-commands.d.ts.map +1 -1
  790. package/dist/core/source-info.d.ts.map +1 -1
  791. package/dist/core/source-info.js.map +1 -1
  792. package/dist/core/spawned-usage.d.ts +21 -0
  793. package/dist/core/spawned-usage.d.ts.map +1 -0
  794. package/dist/core/spawned-usage.js +29 -0
  795. package/dist/core/spawned-usage.js.map +1 -0
  796. package/dist/core/system-prompt-builder.d.ts +4 -0
  797. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  798. package/dist/core/system-prompt-builder.js +15 -8
  799. package/dist/core/system-prompt-builder.js.map +1 -1
  800. package/dist/core/system-prompt.d.ts.map +1 -1
  801. package/dist/core/system-prompt.js +53 -35
  802. package/dist/core/system-prompt.js.map +1 -1
  803. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  804. package/dist/core/tasks/session-task-state.js.map +1 -1
  805. package/dist/core/tasks/task-command.d.ts.map +1 -1
  806. package/dist/core/tasks/task-command.js.map +1 -1
  807. package/dist/core/tasks/task-contract-monitor.d.ts.map +1 -1
  808. package/dist/core/tasks/task-contract-monitor.js.map +1 -1
  809. package/dist/core/tasks/task-projection.d.ts.map +1 -1
  810. package/dist/core/tasks/task-projection.js.map +1 -1
  811. package/dist/core/tasks/task-state.d.ts.map +1 -1
  812. package/dist/core/tasks/task-state.js.map +1 -1
  813. package/dist/core/text-preview.d.ts +4 -0
  814. package/dist/core/text-preview.d.ts.map +1 -0
  815. package/dist/core/text-preview.js +33 -0
  816. package/dist/core/text-preview.js.map +1 -0
  817. package/dist/core/timings.d.ts.map +1 -1
  818. package/dist/core/timings.js.map +1 -1
  819. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  820. package/dist/core/tool-capability-policy.js.map +1 -1
  821. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  822. package/dist/core/tool-gate-controller.js +86 -87
  823. package/dist/core/tool-gate-controller.js.map +1 -1
  824. package/dist/core/tool-protocol-controller.d.ts +4 -1
  825. package/dist/core/tool-protocol-controller.d.ts.map +1 -1
  826. package/dist/core/tool-protocol-controller.js +19 -23
  827. package/dist/core/tool-protocol-controller.js.map +1 -1
  828. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  829. package/dist/core/tool-recovery-log-records.js.map +1 -1
  830. package/dist/core/tool-recovery-log-worker.d.ts.map +1 -1
  831. package/dist/core/tool-recovery-log-worker.js.map +1 -1
  832. package/dist/core/tool-recovery-logger.d.ts.map +1 -1
  833. package/dist/core/tool-recovery-logger.js +12 -24
  834. package/dist/core/tool-recovery-logger.js.map +1 -1
  835. package/dist/core/tool-recovery-stats.d.ts.map +1 -1
  836. package/dist/core/tool-recovery-stats.js +16 -22
  837. package/dist/core/tool-recovery-stats.js.map +1 -1
  838. package/dist/core/tool-repair-health.d.ts.map +1 -1
  839. package/dist/core/tool-repair-health.js.map +1 -1
  840. package/dist/core/tool-repair-settings.d.ts.map +1 -1
  841. package/dist/core/tool-repair-settings.js.map +1 -1
  842. package/dist/core/tool-selection/expected-utility.d.ts.map +1 -1
  843. package/dist/core/tool-selection/expected-utility.js.map +1 -1
  844. package/dist/core/tool-selection/promotion.d.ts.map +1 -1
  845. package/dist/core/tool-selection/promotion.js.map +1 -1
  846. package/dist/core/tool-selection/tool-performance-store.d.ts +2 -0
  847. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  848. package/dist/core/tool-selection/tool-performance-store.js +49 -7
  849. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  850. package/dist/core/tool-selection/tool-phase-timing.d.ts +19 -0
  851. package/dist/core/tool-selection/tool-phase-timing.d.ts.map +1 -0
  852. package/dist/core/tool-selection/tool-phase-timing.js +63 -0
  853. package/dist/core/tool-selection/tool-phase-timing.js.map +1 -0
  854. package/dist/core/tool-selection/tool-selection-controller.d.ts +2 -5
  855. package/dist/core/tool-selection/tool-selection-controller.d.ts.map +1 -1
  856. package/dist/core/tool-selection/tool-selection-controller.js +50 -30
  857. package/dist/core/tool-selection/tool-selection-controller.js.map +1 -1
  858. package/dist/core/toolkit/reflex-interpreter.d.ts +16 -0
  859. package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
  860. package/dist/core/toolkit/reflex-interpreter.js +21 -0
  861. package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
  862. package/dist/core/toolkit/script-registry.d.ts.map +1 -1
  863. package/dist/core/toolkit/script-registry.js.map +1 -1
  864. package/dist/core/toolkit/script-runner.d.ts.map +1 -1
  865. package/dist/core/toolkit/script-runner.js.map +1 -1
  866. package/dist/core/tools/artifact-retrieve.d.ts.map +1 -1
  867. package/dist/core/tools/artifact-retrieve.js.map +1 -1
  868. package/dist/core/tools/ask-question.d.ts +2 -3
  869. package/dist/core/tools/ask-question.d.ts.map +1 -1
  870. package/dist/core/tools/ask-question.js +14 -40
  871. package/dist/core/tools/ask-question.js.map +1 -1
  872. package/dist/core/tools/bash.d.ts +2 -0
  873. package/dist/core/tools/bash.d.ts.map +1 -1
  874. package/dist/core/tools/bash.js +83 -30
  875. package/dist/core/tools/bash.js.map +1 -1
  876. package/dist/core/tools/context-scout.d.ts.map +1 -1
  877. package/dist/core/tools/context-scout.js.map +1 -1
  878. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  879. package/dist/core/tools/delegate-status.js +9 -7
  880. package/dist/core/tools/delegate-status.js.map +1 -1
  881. package/dist/core/tools/delegate.d.ts.map +1 -1
  882. package/dist/core/tools/delegate.js +6 -6
  883. package/dist/core/tools/delegate.js.map +1 -1
  884. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  885. package/dist/core/tools/edit-diff.js.map +1 -1
  886. package/dist/core/tools/edit.d.ts.map +1 -1
  887. package/dist/core/tools/edit.js.map +1 -1
  888. package/dist/core/tools/extensionify.d.ts.map +1 -1
  889. package/dist/core/tools/extensionify.js.map +1 -1
  890. package/dist/core/tools/fff-search-backend.d.ts +19 -0
  891. package/dist/core/tools/fff-search-backend.d.ts.map +1 -1
  892. package/dist/core/tools/fff-search-backend.js +28 -2
  893. package/dist/core/tools/fff-search-backend.js.map +1 -1
  894. package/dist/core/tools/file-encoding-policy.d.ts.map +1 -1
  895. package/dist/core/tools/file-encoding-policy.js.map +1 -1
  896. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  897. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  898. package/dist/core/tools/find.d.ts +1 -1
  899. package/dist/core/tools/find.d.ts.map +1 -1
  900. package/dist/core/tools/find.js +44 -108
  901. package/dist/core/tools/find.js.map +1 -1
  902. package/dist/core/tools/git-filter.d.ts.map +1 -1
  903. package/dist/core/tools/git-filter.js.map +1 -1
  904. package/dist/core/tools/goal.d.ts.map +1 -1
  905. package/dist/core/tools/goal.js +7 -7
  906. package/dist/core/tools/goal.js.map +1 -1
  907. package/dist/core/tools/grep.d.ts +1 -1
  908. package/dist/core/tools/grep.d.ts.map +1 -1
  909. package/dist/core/tools/grep.js +42 -102
  910. package/dist/core/tools/grep.js.map +1 -1
  911. package/dist/core/tools/index.d.ts.map +1 -1
  912. package/dist/core/tools/index.js.map +1 -1
  913. package/dist/core/tools/ls.d.ts.map +1 -1
  914. package/dist/core/tools/ls.js +20 -36
  915. package/dist/core/tools/ls.js.map +1 -1
  916. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  917. package/dist/core/tools/model-fitness.js.map +1 -1
  918. package/dist/core/tools/orchestration-panel.d.ts +5 -0
  919. package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
  920. package/dist/core/tools/orchestration-panel.js +5 -5
  921. package/dist/core/tools/orchestration-panel.js.map +1 -1
  922. package/dist/core/tools/output-accumulator.d.ts +2 -0
  923. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  924. package/dist/core/tools/output-accumulator.js +24 -36
  925. package/dist/core/tools/output-accumulator.js.map +1 -1
  926. package/dist/core/tools/path-utils.d.ts.map +1 -1
  927. package/dist/core/tools/path-utils.js.map +1 -1
  928. package/dist/core/tools/persistent-process-coordinator.d.ts +31 -0
  929. package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -0
  930. package/dist/core/tools/persistent-process-coordinator.js +123 -0
  931. package/dist/core/tools/persistent-process-coordinator.js.map +1 -0
  932. package/dist/core/tools/python.d.ts.map +1 -1
  933. package/dist/core/tools/python.js.map +1 -1
  934. package/dist/core/tools/read.d.ts.map +1 -1
  935. package/dist/core/tools/read.js +14 -13
  936. package/dist/core/tools/read.js.map +1 -1
  937. package/dist/core/tools/render-utils.d.ts +29 -0
  938. package/dist/core/tools/render-utils.d.ts.map +1 -1
  939. package/dist/core/tools/render-utils.js +31 -1
  940. package/dist/core/tools/render-utils.js.map +1 -1
  941. package/dist/core/tools/run-process.d.ts.map +1 -1
  942. package/dist/core/tools/run-process.js.map +1 -1
  943. package/dist/core/tools/run-toolkit-script.d.ts.map +1 -1
  944. package/dist/core/tools/run-toolkit-script.js.map +1 -1
  945. package/dist/core/tools/search-command-guard.d.ts +10 -0
  946. package/dist/core/tools/search-command-guard.d.ts.map +1 -1
  947. package/dist/core/tools/search-command-guard.js +118 -31
  948. package/dist/core/tools/search-command-guard.js.map +1 -1
  949. package/dist/core/tools/search-router.d.ts.map +1 -1
  950. package/dist/core/tools/search-router.js.map +1 -1
  951. package/dist/core/tools/search-tool-runtime.d.ts +19 -0
  952. package/dist/core/tools/search-tool-runtime.d.ts.map +1 -0
  953. package/dist/core/tools/search-tool-runtime.js +12 -0
  954. package/dist/core/tools/search-tool-runtime.js.map +1 -0
  955. package/dist/core/tools/secret-store.d.ts.map +1 -1
  956. package/dist/core/tools/secret-store.js.map +1 -1
  957. package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
  958. package/dist/core/tools/shell-command-parser.js.map +1 -1
  959. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  960. package/dist/core/tools/shell-contract-router.js +4 -1
  961. package/dist/core/tools/shell-contract-router.js.map +1 -1
  962. package/dist/core/tools/shell-execution-session.d.ts +4 -0
  963. package/dist/core/tools/shell-execution-session.d.ts.map +1 -0
  964. package/dist/core/tools/shell-execution-session.js +11 -0
  965. package/dist/core/tools/shell-execution-session.js.map +1 -0
  966. package/dist/core/tools/shell-output-projection.d.ts +49 -0
  967. package/dist/core/tools/shell-output-projection.d.ts.map +1 -0
  968. package/dist/core/tools/shell-output-projection.js +381 -0
  969. package/dist/core/tools/shell-output-projection.js.map +1 -0
  970. package/dist/core/tools/shell-session.d.ts +2 -13
  971. package/dist/core/tools/shell-session.d.ts.map +1 -1
  972. package/dist/core/tools/shell-session.js +36 -136
  973. package/dist/core/tools/shell-session.js.map +1 -1
  974. package/dist/core/tools/skill-audit.d.ts.map +1 -1
  975. package/dist/core/tools/skill-audit.js.map +1 -1
  976. package/dist/core/tools/skillify.d.ts.map +1 -1
  977. package/dist/core/tools/skillify.js.map +1 -1
  978. package/dist/core/tools/task-steps.d.ts +8 -8
  979. package/dist/core/tools/task-steps.d.ts.map +1 -1
  980. package/dist/core/tools/task-steps.js +17 -18
  981. package/dist/core/tools/task-steps.js.map +1 -1
  982. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  983. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  984. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  985. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  986. package/dist/core/tools/tool-task.d.ts +23 -0
  987. package/dist/core/tools/tool-task.d.ts.map +1 -0
  988. package/dist/core/tools/tool-task.js +93 -0
  989. package/dist/core/tools/tool-task.js.map +1 -0
  990. package/dist/core/tools/windows-shell-engine.d.ts +17 -11
  991. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  992. package/dist/core/tools/windows-shell-engine.js +339 -117
  993. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  994. package/dist/core/tools/windows-shell-state.d.ts.map +1 -1
  995. package/dist/core/tools/windows-shell-state.js.map +1 -1
  996. package/dist/core/tools/worktree-sync.d.ts.map +1 -1
  997. package/dist/core/tools/worktree-sync.js +8 -12
  998. package/dist/core/tools/worktree-sync.js.map +1 -1
  999. package/dist/core/tools/write.d.ts.map +1 -1
  1000. package/dist/core/tools/write.js +0 -1
  1001. package/dist/core/tools/write.js.map +1 -1
  1002. package/dist/core/trust-manager.d.ts.map +1 -1
  1003. package/dist/core/trust-manager.js +7 -40
  1004. package/dist/core/trust-manager.js.map +1 -1
  1005. package/dist/core/util/atomic-file.d.ts +19 -0
  1006. package/dist/core/util/atomic-file.d.ts.map +1 -1
  1007. package/dist/core/util/atomic-file.js +50 -15
  1008. package/dist/core/util/atomic-file.js.map +1 -1
  1009. package/dist/core/util/bounded-file.d.ts.map +1 -1
  1010. package/dist/core/util/bounded-file.js.map +1 -1
  1011. package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
  1012. package/dist/core/util/bounded-jsonl.js +2 -9
  1013. package/dist/core/util/bounded-jsonl.js.map +1 -1
  1014. package/dist/core/util/bounded-value.d.ts.map +1 -1
  1015. package/dist/core/util/bounded-value.js.map +1 -1
  1016. package/dist/core/util/json-size.d.ts +3 -0
  1017. package/dist/core/util/json-size.d.ts.map +1 -0
  1018. package/dist/core/util/json-size.js +95 -0
  1019. package/dist/core/util/json-size.js.map +1 -0
  1020. package/dist/core/util/minimatch-cache.d.ts.map +1 -1
  1021. package/dist/core/util/minimatch-cache.js.map +1 -1
  1022. package/dist/core/util/value-guards.d.ts.map +1 -1
  1023. package/dist/core/util/value-guards.js.map +1 -1
  1024. package/dist/core/worktree-sync/codes.d.ts.map +1 -1
  1025. package/dist/core/worktree-sync/git-engine.d.ts.map +1 -1
  1026. package/dist/core/worktree-sync/git-engine.js +20 -36
  1027. package/dist/core/worktree-sync/git-engine.js.map +1 -1
  1028. package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -1
  1029. package/dist/core/worktree-sync/lane-gate.js +1 -4
  1030. package/dist/core/worktree-sync/lane-gate.js.map +1 -1
  1031. package/dist/core/worktree-sync/runtime.d.ts.map +1 -1
  1032. package/dist/core/worktree-sync/runtime.js.map +1 -1
  1033. package/dist/core/worktree-sync/store.d.ts.map +1 -1
  1034. package/dist/core/worktree-sync/store.js.map +1 -1
  1035. package/dist/core/worktree-sync/watcher.d.ts.map +1 -1
  1036. package/dist/core/worktree-sync/watcher.js.map +1 -1
  1037. package/dist/index.d.ts.map +1 -1
  1038. package/dist/index.js.map +1 -1
  1039. package/dist/main.d.ts.map +1 -1
  1040. package/dist/main.js +10 -32
  1041. package/dist/main.js.map +1 -1
  1042. package/dist/migrations.d.ts.map +1 -1
  1043. package/dist/migrations.js +6 -19
  1044. package/dist/migrations.js.map +1 -1
  1045. package/dist/modes/index.d.ts.map +1 -1
  1046. package/dist/modes/interactive/auth-dialogs-controller.d.ts +3 -0
  1047. package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
  1048. package/dist/modes/interactive/auth-dialogs-controller.js +96 -132
  1049. package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
  1050. package/dist/modes/interactive/auto-learn-controller.d.ts +1 -31
  1051. package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
  1052. package/dist/modes/interactive/auto-learn-controller.js +86 -307
  1053. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  1054. package/dist/modes/interactive/autocomplete-provider.d.ts.map +1 -1
  1055. package/dist/modes/interactive/autocomplete-provider.js.map +1 -1
  1056. package/dist/modes/interactive/autonomy-commands.d.ts.map +1 -1
  1057. package/dist/modes/interactive/autonomy-commands.js +2 -8
  1058. package/dist/modes/interactive/autonomy-commands.js.map +1 -1
  1059. package/dist/modes/interactive/clipboard-input.d.ts +5 -1
  1060. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  1061. package/dist/modes/interactive/clipboard-input.js +17 -0
  1062. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  1063. package/dist/modes/interactive/compaction-queue.d.ts.map +1 -1
  1064. package/dist/modes/interactive/compaction-queue.js +13 -18
  1065. package/dist/modes/interactive/compaction-queue.js.map +1 -1
  1066. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
  1067. package/dist/modes/interactive/components/activity-lane.js +6 -10
  1068. package/dist/modes/interactive/components/activity-lane.js.map +1 -1
  1069. package/dist/modes/interactive/components/armin.d.ts +1 -0
  1070. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  1071. package/dist/modes/interactive/components/armin.js +10 -21
  1072. package/dist/modes/interactive/components/armin.js.map +1 -1
  1073. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  1074. package/dist/modes/interactive/components/assistant-message.js +1 -6
  1075. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  1076. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  1077. package/dist/modes/interactive/components/bash-execution.js +4 -9
  1078. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  1079. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  1080. package/dist/modes/interactive/components/bordered-loader.js +0 -3
  1081. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  1082. package/dist/modes/interactive/components/branch-summary-message.d.ts +3 -8
  1083. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  1084. package/dist/modes/interactive/components/branch-summary-message.js +13 -35
  1085. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  1086. package/dist/modes/interactive/components/compaction-summary-message.d.ts +3 -8
  1087. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  1088. package/dist/modes/interactive/components/compaction-summary-message.js +14 -36
  1089. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  1090. package/dist/modes/interactive/components/config-selector.d.ts +1 -0
  1091. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  1092. package/dist/modes/interactive/components/config-selector.js +20 -43
  1093. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  1094. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  1095. package/dist/modes/interactive/components/countdown-timer.js +0 -5
  1096. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  1097. package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
  1098. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  1099. package/dist/modes/interactive/components/custom-editor.js +4 -8
  1100. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  1101. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  1102. package/dist/modes/interactive/components/custom-message.js +1 -6
  1103. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  1104. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  1105. package/dist/modes/interactive/components/daxnuts.js +6 -8
  1106. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  1107. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  1108. package/dist/modes/interactive/components/diff.js.map +1 -1
  1109. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  1110. package/dist/modes/interactive/components/dynamic-border.js +0 -1
  1111. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  1112. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  1113. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  1114. package/dist/modes/interactive/components/expandable-markdown-message.d.ts +21 -0
  1115. package/dist/modes/interactive/components/expandable-markdown-message.d.ts.map +1 -0
  1116. package/dist/modes/interactive/components/expandable-markdown-message.js +48 -0
  1117. package/dist/modes/interactive/components/expandable-markdown-message.js.map +1 -0
  1118. package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -1
  1119. package/dist/modes/interactive/components/expandable-text.js +0 -2
  1120. package/dist/modes/interactive/components/expandable-text.js.map +1 -1
  1121. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  1122. package/dist/modes/interactive/components/extension-editor.js +1 -9
  1123. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  1124. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  1125. package/dist/modes/interactive/components/extension-input.js +2 -8
  1126. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  1127. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  1128. package/dist/modes/interactive/components/extension-selector.js +5 -20
  1129. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  1130. package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
  1131. package/dist/modes/interactive/components/fitness-role-selector.js +0 -1
  1132. package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
  1133. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  1134. package/dist/modes/interactive/components/footer.js +1 -5
  1135. package/dist/modes/interactive/components/footer.js.map +1 -1
  1136. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  1137. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  1138. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  1139. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  1140. package/dist/modes/interactive/components/login-dialog.js +4 -10
  1141. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  1142. package/dist/modes/interactive/components/model-selector.d.ts +2 -2
  1143. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  1144. package/dist/modes/interactive/components/model-selector.js +21 -44
  1145. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  1146. package/dist/modes/interactive/components/model-suggestion-selector.d.ts.map +1 -1
  1147. package/dist/modes/interactive/components/model-suggestion-selector.js +0 -1
  1148. package/dist/modes/interactive/components/model-suggestion-selector.js.map +1 -1
  1149. package/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
  1150. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  1151. package/dist/modes/interactive/components/oauth-selector.js +16 -32
  1152. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  1153. package/dist/modes/interactive/components/profile-resource-editor.d.ts +3 -4
  1154. package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
  1155. package/dist/modes/interactive/components/profile-resource-editor.js +34 -93
  1156. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  1157. package/dist/modes/interactive/components/profile-selector.d.ts.map +1 -1
  1158. package/dist/modes/interactive/components/profile-selector.js +0 -1
  1159. package/dist/modes/interactive/components/profile-selector.js.map +1 -1
  1160. package/dist/modes/interactive/components/scoped-models-selector.d.ts +3 -4
  1161. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  1162. package/dist/modes/interactive/components/scoped-models-selector.js +34 -79
  1163. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  1164. package/dist/modes/interactive/components/selector-list.d.ts +63 -0
  1165. package/dist/modes/interactive/components/selector-list.d.ts.map +1 -0
  1166. package/dist/modes/interactive/components/selector-list.js +186 -0
  1167. package/dist/modes/interactive/components/selector-list.js.map +1 -0
  1168. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  1169. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  1170. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  1171. package/dist/modes/interactive/components/session-selector.js +34 -59
  1172. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  1173. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  1174. package/dist/modes/interactive/components/settings-selector.js +40 -138
  1175. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  1176. package/dist/modes/interactive/components/show-images-selector.d.ts +2 -4
  1177. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  1178. package/dist/modes/interactive/components/show-images-selector.js +9 -28
  1179. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  1180. package/dist/modes/interactive/components/skill-invocation-message.d.ts +3 -8
  1181. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  1182. package/dist/modes/interactive/components/skill-invocation-message.js +12 -40
  1183. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  1184. package/dist/modes/interactive/components/theme-selector.d.ts +2 -5
  1185. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  1186. package/dist/modes/interactive/components/theme-selector.js +11 -37
  1187. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  1188. package/dist/modes/interactive/components/thinking-selector.d.ts +2 -4
  1189. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  1190. package/dist/modes/interactive/components/thinking-selector.js +9 -31
  1191. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  1192. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  1193. package/dist/modes/interactive/components/tool-execution.js +9 -28
  1194. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  1195. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
  1196. package/dist/modes/interactive/components/tool-group.js +2 -3
  1197. package/dist/modes/interactive/components/tool-group.js.map +1 -1
  1198. package/dist/modes/interactive/components/tool-panel-registry.d.ts.map +1 -1
  1199. package/dist/modes/interactive/components/tool-panel-registry.js +5 -3
  1200. package/dist/modes/interactive/components/tool-panel-registry.js.map +1 -1
  1201. package/dist/modes/interactive/components/tool-title.d.ts.map +1 -1
  1202. package/dist/modes/interactive/components/tool-title.js +0 -4
  1203. package/dist/modes/interactive/components/tool-title.js.map +1 -1
  1204. package/dist/modes/interactive/components/transcript-pager.d.ts +26 -0
  1205. package/dist/modes/interactive/components/transcript-pager.d.ts.map +1 -0
  1206. package/dist/modes/interactive/components/transcript-pager.js +81 -0
  1207. package/dist/modes/interactive/components/transcript-pager.js.map +1 -0
  1208. package/dist/modes/interactive/components/tree-selector.d.ts +1 -12
  1209. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  1210. package/dist/modes/interactive/components/tree-selector.js +42 -402
  1211. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  1212. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  1213. package/dist/modes/interactive/components/trust-selector.js +4 -16
  1214. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  1215. package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -1
  1216. package/dist/modes/interactive/components/usage-action-selector.js +2 -10
  1217. package/dist/modes/interactive/components/usage-action-selector.js.map +1 -1
  1218. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  1219. package/dist/modes/interactive/components/user-message-selector.js +3 -6
  1220. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  1221. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  1222. package/dist/modes/interactive/components/user-message.js +0 -1
  1223. package/dist/modes/interactive/components/user-message.js.map +1 -1
  1224. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  1225. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  1226. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  1227. package/dist/modes/interactive/config-backup.js.map +1 -1
  1228. package/dist/modes/interactive/editor-overlay-host.d.ts.map +1 -1
  1229. package/dist/modes/interactive/editor-overlay-host.js +0 -3
  1230. package/dist/modes/interactive/editor-overlay-host.js.map +1 -1
  1231. package/dist/modes/interactive/extension-ui-host.d.ts +2 -0
  1232. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  1233. package/dist/modes/interactive/extension-ui-host.js +51 -72
  1234. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  1235. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  1236. package/dist/modes/interactive/external-editor.js +2 -15
  1237. package/dist/modes/interactive/external-editor.js.map +1 -1
  1238. package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
  1239. package/dist/modes/interactive/history-reload-math.js.map +1 -1
  1240. package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -1
  1241. package/dist/modes/interactive/interactive-event-controller.js +23 -16
  1242. package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
  1243. package/dist/modes/interactive/interactive-mode.d.ts +13 -4
  1244. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  1245. package/dist/modes/interactive/interactive-mode.js +126 -207
  1246. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  1247. package/dist/modes/interactive/interactive-selection-prompts.d.ts +20 -0
  1248. package/dist/modes/interactive/interactive-selection-prompts.d.ts.map +1 -0
  1249. package/dist/modes/interactive/interactive-selection-prompts.js +43 -0
  1250. package/dist/modes/interactive/interactive-selection-prompts.js.map +1 -0
  1251. package/dist/modes/interactive/key-handlers.d.ts +2 -1
  1252. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  1253. package/dist/modes/interactive/key-handlers.js +4 -2
  1254. package/dist/modes/interactive/key-handlers.js.map +1 -1
  1255. package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -1
  1256. package/dist/modes/interactive/loaded-resources-view.js.map +1 -1
  1257. package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
  1258. package/dist/modes/interactive/local-model-commands.js +4 -9
  1259. package/dist/modes/interactive/local-model-commands.js.map +1 -1
  1260. package/dist/modes/interactive/model-fitness-presentation.d.ts +21 -0
  1261. package/dist/modes/interactive/model-fitness-presentation.d.ts.map +1 -0
  1262. package/dist/modes/interactive/model-fitness-presentation.js +13 -0
  1263. package/dist/modes/interactive/model-fitness-presentation.js.map +1 -0
  1264. package/dist/modes/interactive/profile-menu-controller.d.ts +2 -0
  1265. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  1266. package/dist/modes/interactive/profile-menu-controller.js +79 -171
  1267. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  1268. package/dist/modes/interactive/report-commands.d.ts +2 -0
  1269. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  1270. package/dist/modes/interactive/report-commands.js +12 -6
  1271. package/dist/modes/interactive/report-commands.js.map +1 -1
  1272. package/dist/modes/interactive/resource-display.d.ts.map +1 -1
  1273. package/dist/modes/interactive/resource-display.js.map +1 -1
  1274. package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
  1275. package/dist/modes/interactive/resource-shell-commands.js +6 -23
  1276. package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
  1277. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  1278. package/dist/modes/interactive/session-flow-commands.js +21 -25
  1279. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  1280. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  1281. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  1282. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -1
  1283. package/dist/modes/interactive/session-replacement-errors.js.map +1 -1
  1284. package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
  1285. package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
  1286. package/dist/modes/interactive/signal-lifecycle.d.ts.map +1 -1
  1287. package/dist/modes/interactive/signal-lifecycle.js.map +1 -1
  1288. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  1289. package/dist/modes/interactive/startup-checks.js +12 -8
  1290. package/dist/modes/interactive/startup-checks.js.map +1 -1
  1291. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  1292. package/dist/modes/interactive/theme/theme.js +10 -76
  1293. package/dist/modes/interactive/theme/theme.js.map +1 -1
  1294. package/dist/modes/interactive/usage-commands.d.ts.map +1 -1
  1295. package/dist/modes/interactive/usage-commands.js.map +1 -1
  1296. package/dist/modes/print-mode.d.ts.map +1 -1
  1297. package/dist/modes/print-mode.js +5 -22
  1298. package/dist/modes/print-mode.js.map +1 -1
  1299. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  1300. package/dist/modes/rpc/jsonl.js +1 -1
  1301. package/dist/modes/rpc/jsonl.js.map +1 -1
  1302. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  1303. package/dist/modes/rpc/rpc-client.js +7 -8
  1304. package/dist/modes/rpc/rpc-client.js.map +1 -1
  1305. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  1306. package/dist/modes/rpc/rpc-mode.js +5 -20
  1307. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  1308. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  1309. package/dist/modes/rpc/rpc-types.js.map +1 -1
  1310. package/dist/modes/termination-signals.d.ts +4 -0
  1311. package/dist/modes/termination-signals.d.ts.map +1 -0
  1312. package/dist/modes/termination-signals.js +21 -0
  1313. package/dist/modes/termination-signals.js.map +1 -0
  1314. package/dist/package-manager-cli.d.ts.map +1 -1
  1315. package/dist/package-manager-cli.js.map +1 -1
  1316. package/dist/utils/ansi-colors.d.ts +5 -0
  1317. package/dist/utils/ansi-colors.d.ts.map +1 -0
  1318. package/dist/utils/ansi-colors.js +38 -0
  1319. package/dist/utils/ansi-colors.js.map +1 -0
  1320. package/dist/utils/ansi.d.ts.map +1 -1
  1321. package/dist/utils/ansi.js.map +1 -1
  1322. package/dist/utils/changelog.d.ts.map +1 -1
  1323. package/dist/utils/changelog.js.map +1 -1
  1324. package/dist/utils/child-process.d.ts.map +1 -1
  1325. package/dist/utils/child-process.js.map +1 -1
  1326. package/dist/utils/clipboard-image.d.ts.map +1 -1
  1327. package/dist/utils/clipboard-image.js.map +1 -1
  1328. package/dist/utils/clipboard-native.d.ts.map +1 -1
  1329. package/dist/utils/clipboard-native.js.map +1 -1
  1330. package/dist/utils/clipboard.d.ts.map +1 -1
  1331. package/dist/utils/clipboard.js.map +1 -1
  1332. package/dist/utils/deprecation.d.ts.map +1 -1
  1333. package/dist/utils/deprecation.js.map +1 -1
  1334. package/dist/utils/exif-orientation.d.ts.map +1 -1
  1335. package/dist/utils/exif-orientation.js.map +1 -1
  1336. package/dist/utils/external-editor-command.d.ts.map +1 -1
  1337. package/dist/utils/external-editor-command.js.map +1 -1
  1338. package/dist/utils/frontmatter.d.ts.map +1 -1
  1339. package/dist/utils/frontmatter.js.map +1 -1
  1340. package/dist/utils/fs-watch.d.ts.map +1 -1
  1341. package/dist/utils/fs-watch.js.map +1 -1
  1342. package/dist/utils/git.d.ts.map +1 -1
  1343. package/dist/utils/git.js +20 -28
  1344. package/dist/utils/git.js.map +1 -1
  1345. package/dist/utils/highlight-js-languages.d.ts.map +1 -1
  1346. package/dist/utils/html.d.ts.map +1 -1
  1347. package/dist/utils/html.js.map +1 -1
  1348. package/dist/utils/image-convert.d.ts.map +1 -1
  1349. package/dist/utils/image-convert.js.map +1 -1
  1350. package/dist/utils/image-resize-core.d.ts.map +1 -1
  1351. package/dist/utils/image-resize-core.js.map +1 -1
  1352. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  1353. package/dist/utils/image-resize-worker.js.map +1 -1
  1354. package/dist/utils/image-resize.d.ts.map +1 -1
  1355. package/dist/utils/image-resize.js.map +1 -1
  1356. package/dist/utils/json.d.ts.map +1 -1
  1357. package/dist/utils/json.js.map +1 -1
  1358. package/dist/utils/mime.d.ts.map +1 -1
  1359. package/dist/utils/mime.js.map +1 -1
  1360. package/dist/utils/open-browser.d.ts.map +1 -1
  1361. package/dist/utils/open-browser.js.map +1 -1
  1362. package/dist/utils/paths.d.ts.map +1 -1
  1363. package/dist/utils/paths.js.map +1 -1
  1364. package/dist/utils/photon.d.ts.map +1 -1
  1365. package/dist/utils/photon.js.map +1 -1
  1366. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  1367. package/dist/utils/pi-user-agent.js.map +1 -1
  1368. package/dist/utils/platform.d.ts.map +1 -1
  1369. package/dist/utils/platform.js.map +1 -1
  1370. package/dist/utils/process-memory.d.ts.map +1 -1
  1371. package/dist/utils/process-memory.js.map +1 -1
  1372. package/dist/utils/safe-write-stream.d.ts.map +1 -1
  1373. package/dist/utils/safe-write-stream.js.map +1 -1
  1374. package/dist/utils/shell.d.ts.map +1 -1
  1375. package/dist/utils/shell.js.map +1 -1
  1376. package/dist/utils/sleep.d.ts.map +1 -1
  1377. package/dist/utils/sleep.js +2 -15
  1378. package/dist/utils/sleep.js.map +1 -1
  1379. package/dist/utils/stdin-events.d.ts +8 -0
  1380. package/dist/utils/stdin-events.d.ts.map +1 -0
  1381. package/dist/utils/stdin-events.js +19 -0
  1382. package/dist/utils/stdin-events.js.map +1 -0
  1383. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  1384. package/dist/utils/syntax-highlight.js +20 -13
  1385. package/dist/utils/syntax-highlight.js.map +1 -1
  1386. package/dist/utils/tools-manager.d.ts +6 -1
  1387. package/dist/utils/tools-manager.d.ts.map +1 -1
  1388. package/dist/utils/tools-manager.js +59 -2
  1389. package/dist/utils/tools-manager.js.map +1 -1
  1390. package/dist/utils/version-check.d.ts.map +1 -1
  1391. package/dist/utils/version-check.js.map +1 -1
  1392. package/dist/utils/windows-self-update.d.ts.map +1 -1
  1393. package/dist/utils/windows-self-update.js.map +1 -1
  1394. package/dist/utils/work-directory.d.ts.map +1 -1
  1395. package/dist/utils/work-directory.js.map +1 -1
  1396. package/docs/compaction.md +11 -3
  1397. package/docs/development.md +1 -1
  1398. package/docs/sessions.md +6 -0
  1399. package/docs/settings.md +1 -1
  1400. package/docs/windows.md +28 -3
  1401. package/docs/work-directory.md +10 -2
  1402. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  1403. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  1404. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  1405. package/examples/extensions/sandbox/package-lock.json +2 -2
  1406. package/examples/extensions/sandbox/package.json +1 -1
  1407. package/examples/extensions/with-deps/package-lock.json +2 -2
  1408. package/examples/extensions/with-deps/package.json +1 -1
  1409. package/npm-shrinkwrap.json +27 -27
  1410. package/package.json +11 -11
  1411. package/dist/utils/streaming-lines.d.ts +0 -20
  1412. package/dist/utils/streaming-lines.d.ts.map +0 -1
  1413. package/dist/utils/streaming-lines.js +0 -79
  1414. package/dist/utils/streaming-lines.js.map +0 -1
@@ -0,0 +1,9 @@
1
+ export interface ExplicitChatGoal {
2
+ objective: string;
3
+ }
4
+ /**
5
+ * Recognize only explicit persistence language. Ordinary multi-step work and discussion ABOUT goal
6
+ * mechanics deliberately return undefined; those must not silently expand into autonomous work.
7
+ */
8
+ export declare function parseExplicitChatGoal(text: string): ExplicitChatGoal | undefined;
9
+ //# sourceMappingURL=natural-language-goal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"natural-language-goal.d.ts","sourceRoot":"","sources":["../../../src/core/goals/natural-language-goal.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;CAClB;AAWD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAOhF"}
@@ -0,0 +1,23 @@
1
+ import { MAX_GOAL_OBJECTIVE_LENGTH } from "./goal-state.js";
2
+ const EXPLICIT_GOAL_PATTERNS = [
3
+ /^\s*set\s+(?:this\s+as\s+)?a\s+(?:persistent\s+)?goal\s*(?::|to\s+)\s*(.+)$/is,
4
+ /^\s*my\s+persistent\s+goal\s+is\s+to\s+(.+)$/is,
5
+ /^\s*(?:the|our)\s+(?:persistent\s+)?goal\s+is\s+to\s+(.+)$/is,
6
+ /^\s*treat\s+this\s+as\s+my\s+(?:persistent\s+)?goal\s*:\s*(.+)$/is,
7
+ /^\s*i\s+want\s+this\s+as\s+(?:my\s+)?(?:persistent\s+)?goal\s*:\s*(.+)$/is,
8
+ /^\s*keep\s+working\s+until\s+this\s+is\s+(?:complete|done)\s*:\s*(.+)$/is,
9
+ ];
10
+ /**
11
+ * Recognize only explicit persistence language. Ordinary multi-step work and discussion ABOUT goal
12
+ * mechanics deliberately return undefined; those must not silently expand into autonomous work.
13
+ */
14
+ export function parseExplicitChatGoal(text) {
15
+ for (const pattern of EXPLICIT_GOAL_PATTERNS) {
16
+ const objective = pattern.exec(text)?.[1]?.trim();
17
+ if (!objective || objective.length > MAX_GOAL_OBJECTIVE_LENGTH)
18
+ continue;
19
+ return { objective };
20
+ }
21
+ return undefined;
22
+ }
23
+ //# sourceMappingURL=natural-language-goal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"natural-language-goal.js","sourceRoot":"","sources":["../../../src/core/goals/natural-language-goal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAM5D,MAAM,sBAAsB,GAAG;IAC9B,+EAA+E;IAC/E,gDAAgD;IAChD,8DAA8D;IAC9D,mEAAmE;IACnE,2EAA2E;IAC3E,0EAA0E;CACjE,CAAC;AAEX;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IACjD,KAAK,MAAM,OAAO,IAAI,sBAAsB,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QAClD,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,yBAAyB;YAAE,SAAS;QACzE,OAAO,EAAE,SAAS,EAAE,CAAC;IACtB,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { MAX_GOAL_OBJECTIVE_LENGTH } from \"./goal-state.ts\";\n\nexport interface ExplicitChatGoal {\n\tobjective: string;\n}\n\nconst EXPLICIT_GOAL_PATTERNS = [\n\t/^\\s*set\\s+(?:this\\s+as\\s+)?a\\s+(?:persistent\\s+)?goal\\s*(?::|to\\s+)\\s*(.+)$/is,\n\t/^\\s*my\\s+persistent\\s+goal\\s+is\\s+to\\s+(.+)$/is,\n\t/^\\s*(?:the|our)\\s+(?:persistent\\s+)?goal\\s+is\\s+to\\s+(.+)$/is,\n\t/^\\s*treat\\s+this\\s+as\\s+my\\s+(?:persistent\\s+)?goal\\s*:\\s*(.+)$/is,\n\t/^\\s*i\\s+want\\s+this\\s+as\\s+(?:my\\s+)?(?:persistent\\s+)?goal\\s*:\\s*(.+)$/is,\n\t/^\\s*keep\\s+working\\s+until\\s+this\\s+is\\s+(?:complete|done)\\s*:\\s*(.+)$/is,\n] as const;\n\n/**\n * Recognize only explicit persistence language. Ordinary multi-step work and discussion ABOUT goal\n * mechanics deliberately return undefined; those must not silently expand into autonomous work.\n */\nexport function parseExplicitChatGoal(text: string): ExplicitChatGoal | undefined {\n\tfor (const pattern of EXPLICIT_GOAL_PATTERNS) {\n\t\tconst objective = pattern.exec(text)?.[1]?.trim();\n\t\tif (!objective || objective.length > MAX_GOAL_OBJECTIVE_LENGTH) continue;\n\t\treturn { objective };\n\t}\n\treturn undefined;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"session-goal-state.d.ts","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAIN,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAKN,KAAK,SAAS,EAId,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,sBAAsB,eAAe,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AA+ElF;;;;GAIG;AACH,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,EAChB,QAAQ,CAAC,EAAE,SAAS,GAClB,MAAM,CAqBR;AAED,wBAAgB,yBAAyB,CACxC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,GACf,MAAM,CASR;AAED,0EAA0E;AAC1E,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAEnF;AAED,UAAU,eAAe;IACxB,4BAA4B,EAAE,cAAc,CAAC,8BAA8B,CAAC,CAAC;CAC7E;AAmBD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,eAAe,GAAG,SAAS,GAAG,SAAS,CAoCjG;AAED,uDAAuD;AACvD,wBAAgB,6BAA6B,CAC5C,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,GACd,MAAM,CAER","sourcesContent":["import type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tdecodeSessionSnapshotPayload,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport {\n\tapplyGoalEvent,\n\tcloneGoalEventForStorage,\n\tcloneGoalStateForStorage,\n\ttype GoalEvent,\n\ttype GoalState,\n\tisGoalEvent,\n\tisGoalState,\n\tMAX_GOAL_EVENT_HISTORY,\n} from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport type GoalStateSnapshotPayload = SessionSnapshotPayload<\"state\", GoalState>;\n\nconst GOAL_STATE_SNAPSHOT_CODEC: SessionSnapshotCodec<GoalState, \"state\"> = {\n\tcustomType: GOAL_STATE_CUSTOM_TYPE,\n\tvalueKey: \"state\",\n\tisValue: isGoalState,\n\tclone: cloneGoalStateForStorage,\n};\n\ninterface GoalEventBatchPayload {\n\tversion: 2;\n\tkind: \"events\";\n\tgoalId: string;\n\tbaseRevision: number;\n\tevents: readonly GoalEvent[];\n}\n\ninterface GoalCheckpointPayload {\n\tversion: 2;\n\tkind: \"checkpoint\";\n\tstate: GoalState;\n}\n\ninterface GoalClearedPayload {\n\tversion: 2;\n\tkind: \"cleared\";\n\tgoalId: string;\n\tbaseRevision: number;\n\tclearedAt: string;\n}\n\ntype GoalJournalPayload = GoalEventBatchPayload | GoalCheckpointPayload | GoalClearedPayload;\n\nfunction isNonNegativeInteger(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction decodeGoalJournalPayload(data: unknown): GoalJournalPayload | undefined {\n\tif (!isPlainRecord(data) || data.version !== 2 || typeof data.kind !== \"string\") return undefined;\n\tif (data.kind === \"checkpoint\") {\n\t\tif (!isGoalState(data.state)) return undefined;\n\t\treturn { version: 2, kind: \"checkpoint\", state: cloneGoalStateForStorage(data.state) };\n\t}\n\tif (data.kind === \"cleared\") {\n\t\tif (\n\t\t\ttypeof data.goalId !== \"string\" ||\n\t\t\t!isNonNegativeInteger(data.baseRevision) ||\n\t\t\ttypeof data.clearedAt !== \"string\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tversion: 2,\n\t\t\tkind: \"cleared\",\n\t\t\tgoalId: data.goalId,\n\t\t\tbaseRevision: data.baseRevision,\n\t\t\tclearedAt: data.clearedAt,\n\t\t};\n\t}\n\tif (data.kind !== \"events\") return undefined;\n\tif (\n\t\ttypeof data.goalId !== \"string\" ||\n\t\t!isNonNegativeInteger(data.baseRevision) ||\n\t\t!Array.isArray(data.events) ||\n\t\tdata.events.length === 0 ||\n\t\tdata.events.length > MAX_GOAL_EVENT_HISTORY ||\n\t\t!data.events.every(isGoalEvent)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tversion: 2,\n\t\tkind: \"events\",\n\t\tgoalId: data.goalId,\n\t\tbaseRevision: data.baseRevision,\n\t\tevents: data.events.map(cloneGoalEventForStorage),\n\t};\n}\n\n/**\n * Persist one state transition. Canonical reducer transitions are journaled as a bounded event\n * batch; starts, replacements, and non-canonical imports use one checkpoint. This removes the old\n * recursive full-state-on-every-mutation growth while keeping compound owner transitions atomic.\n */\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n\tprevious?: GoalState,\n): string {\n\tconst revision = state.revision ?? 0;\n\tconst previousRevision = previous?.revision ?? 0;\n\tconst eventCount = previous && previous.goalId === state.goalId ? revision - previousRevision : 0;\n\tif (previous && eventCount > 0 && eventCount <= state.events.length && eventCount <= MAX_GOAL_EVENT_HISTORY) {\n\t\tconst payload: GoalEventBatchPayload = {\n\t\t\tversion: 2,\n\t\t\tkind: \"events\",\n\t\t\tgoalId: state.goalId,\n\t\t\tbaseRevision: previousRevision,\n\t\t\tevents: state.events.slice(-eventCount).map(cloneGoalEventForStorage),\n\t\t};\n\t\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n\t}\n\n\tconst payload: GoalCheckpointPayload = {\n\t\tversion: 2,\n\t\tkind: \"checkpoint\",\n\t\tstate: cloneGoalStateForStorage(state),\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\nexport function appendGoalClearedSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n\tclearedAt: string,\n): string {\n\tconst payload: GoalClearedPayload = {\n\t\tversion: 2,\n\t\tkind: \"cleared\",\n\t\tgoalId: state.goalId,\n\t\tbaseRevision: state.revision ?? 0,\n\t\tclearedAt,\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\n/** Legacy payload decode retained for imports and focused codec tests. */\nexport function decodeGoalStateSnapshotPayload(data: unknown): GoalState | undefined {\n\treturn decodeSessionSnapshotPayload(data, GOAL_STATE_SNAPSHOT_CODEC);\n}\n\ninterface GoalStateSource {\n\tgetLatestCustomEntryOnBranch: SessionManager[\"getLatestCustomEntryOnBranch\"];\n}\n\ninterface GoalStateCacheEntry {\n\tlatestEntryId: string | null;\n\tstate: GoalState | undefined;\n}\n\nconst goalStateCache = new WeakMap<GoalStateSource, GoalStateCacheEntry>();\n\nfunction cacheGoalState(\n\tsessionManager: GoalStateSource,\n\tlatestEntryId: string | null,\n\tstate: GoalState | undefined,\n): GoalState | undefined {\n\tconst stored = state ? cloneGoalStateForStorage(state) : undefined;\n\tgoalStateCache.set(sessionManager, { latestEntryId, state: stored });\n\treturn stored ? cloneGoalStateForStorage(stored) : undefined;\n}\n\n/**\n * Reconstruct the latest goal from one checkpoint plus linear event batches. Any malformed newest\n * goal journal fails closed instead of skipping backward to an older active state and resurrecting\n * work after corruption.\n */\nexport function getLatestGoalStateSnapshot(sessionManager: GoalStateSource): GoalState | undefined {\n\tconst latestEntry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE);\n\tconst latestEntryId = latestEntry?.id ?? null;\n\tconst cached = goalStateCache.get(sessionManager);\n\tif (cached?.latestEntryId === latestEntryId) {\n\t\treturn cached.state ? cloneGoalStateForStorage(cached.state) : undefined;\n\t}\n\tif (!latestEntry) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\n\tconst batches: GoalEventBatchPayload[] = [];\n\tlet entry = latestEntry;\n\tfor (;;) {\n\t\tconst legacy = decodeGoalStateSnapshotPayload(entry.data);\n\t\tconst journal = legacy ? undefined : decodeGoalJournalPayload(entry.data);\n\t\tif (!legacy && !journal) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tif (journal?.kind === \"cleared\") return cacheGoalState(sessionManager, latestEntryId, undefined);\n\n\t\tconst checkpoint = legacy ?? (journal?.kind === \"checkpoint\" ? journal.state : undefined);\n\t\tif (checkpoint) {\n\t\t\tlet state = checkpoint;\n\t\t\tfor (const batch of batches.reverse()) {\n\t\t\t\tif (batch.goalId !== state.goalId || batch.baseRevision !== (state.revision ?? 0)) {\n\t\t\t\t\treturn cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\t\t\t}\n\t\t\t\tfor (const event of batch.events) state = applyGoalEvent(state, event);\n\t\t\t}\n\t\t\treturn cacheGoalState(sessionManager, latestEntryId, state);\n\t\t}\n\n\t\tif (journal?.kind !== \"events\") return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tbatches.push(journal);\n\t\tif (entry.parentId === null) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tconst previousEntry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE, entry.parentId);\n\t\tif (!previousEntry) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tentry = previousEntry;\n\t}\n}\n\n/** Explicit legacy writer for migration tests only. */\nexport function appendLegacyGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\treturn appendSessionSnapshot(sessionManager, GOAL_STATE_SNAPSHOT_CODEC, state);\n}\n"]}
1
+ {"version":3,"file":"session-goal-state.d.ts","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAIN,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAKN,KAAK,SAAS,EAId,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,sBAAsB,eAAe,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AA+ElF;;;;GAIG;AACH,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,EAChB,QAAQ,CAAC,EAAE,SAAS,GAClB,MAAM,CAqBR;AAED,wBAAgB,yBAAyB,CACxC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,GACf,MAAM,CASR;AAED,0EAA0E;AAC1E,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAEnF;AAED,UAAU,eAAe;IACxB,4BAA4B,EAAE,cAAc,CAAC,8BAA8B,CAAC,CAAC;CAC7E;AAmBD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,eAAe,GAAG,SAAS,GAAG,SAAS,CAoCjG;AAED,uDAAuD;AACvD,wBAAgB,6BAA6B,CAC5C,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,GACd,MAAM,CAER"}
@@ -1 +1 @@
1
- {"version":3,"file":"session-goal-state.js","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qBAAqB,EACrB,4BAA4B,GAG5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,O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AC;AAAA,CACD;AAED,uDAAuD;AACvD,MAAM,UAAU,6BAA6B,CAC5C,cAAyD,EACzD,KAAgB,EACP;IACT,OAAO,qBAAqB,CAAC,cAAc,EAAE,yBAAyB,EAAE,KAAK,CAAC,CAAC;AAAA,CAC/E","sourcesContent":["import type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tdecodeSessionSnapshotPayload,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport {\n\tapplyGoalEvent,\n\tcloneGoalEventForStorage,\n\tcloneGoalStateForStorage,\n\ttype GoalEvent,\n\ttype GoalState,\n\tisGoalEvent,\n\tisGoalState,\n\tMAX_GOAL_EVENT_HISTORY,\n} from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport type GoalStateSnapshotPayload = SessionSnapshotPayload<\"state\", GoalState>;\n\nconst GOAL_STATE_SNAPSHOT_CODEC: SessionSnapshotCodec<GoalState, \"state\"> = {\n\tcustomType: GOAL_STATE_CUSTOM_TYPE,\n\tvalueKey: \"state\",\n\tisValue: isGoalState,\n\tclone: cloneGoalStateForStorage,\n};\n\ninterface GoalEventBatchPayload {\n\tversion: 2;\n\tkind: \"events\";\n\tgoalId: string;\n\tbaseRevision: number;\n\tevents: readonly GoalEvent[];\n}\n\ninterface GoalCheckpointPayload {\n\tversion: 2;\n\tkind: \"checkpoint\";\n\tstate: GoalState;\n}\n\ninterface GoalClearedPayload {\n\tversion: 2;\n\tkind: \"cleared\";\n\tgoalId: string;\n\tbaseRevision: number;\n\tclearedAt: string;\n}\n\ntype GoalJournalPayload = GoalEventBatchPayload | GoalCheckpointPayload | GoalClearedPayload;\n\nfunction isNonNegativeInteger(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction decodeGoalJournalPayload(data: unknown): GoalJournalPayload | undefined {\n\tif (!isPlainRecord(data) || data.version !== 2 || typeof data.kind !== \"string\") return undefined;\n\tif (data.kind === \"checkpoint\") {\n\t\tif (!isGoalState(data.state)) return undefined;\n\t\treturn { version: 2, kind: \"checkpoint\", state: cloneGoalStateForStorage(data.state) };\n\t}\n\tif (data.kind === \"cleared\") {\n\t\tif (\n\t\t\ttypeof data.goalId !== \"string\" ||\n\t\t\t!isNonNegativeInteger(data.baseRevision) ||\n\t\t\ttypeof data.clearedAt !== \"string\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tversion: 2,\n\t\t\tkind: \"cleared\",\n\t\t\tgoalId: data.goalId,\n\t\t\tbaseRevision: data.baseRevision,\n\t\t\tclearedAt: data.clearedAt,\n\t\t};\n\t}\n\tif (data.kind !== \"events\") return undefined;\n\tif (\n\t\ttypeof data.goalId !== \"string\" ||\n\t\t!isNonNegativeInteger(data.baseRevision) ||\n\t\t!Array.isArray(data.events) ||\n\t\tdata.events.length === 0 ||\n\t\tdata.events.length > MAX_GOAL_EVENT_HISTORY ||\n\t\t!data.events.every(isGoalEvent)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tversion: 2,\n\t\tkind: \"events\",\n\t\tgoalId: data.goalId,\n\t\tbaseRevision: data.baseRevision,\n\t\tevents: data.events.map(cloneGoalEventForStorage),\n\t};\n}\n\n/**\n * Persist one state transition. Canonical reducer transitions are journaled as a bounded event\n * batch; starts, replacements, and non-canonical imports use one checkpoint. This removes the old\n * recursive full-state-on-every-mutation growth while keeping compound owner transitions atomic.\n */\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n\tprevious?: GoalState,\n): string {\n\tconst revision = state.revision ?? 0;\n\tconst previousRevision = previous?.revision ?? 0;\n\tconst eventCount = previous && previous.goalId === state.goalId ? revision - previousRevision : 0;\n\tif (previous && eventCount > 0 && eventCount <= state.events.length && eventCount <= MAX_GOAL_EVENT_HISTORY) {\n\t\tconst payload: GoalEventBatchPayload = {\n\t\t\tversion: 2,\n\t\t\tkind: \"events\",\n\t\t\tgoalId: state.goalId,\n\t\t\tbaseRevision: previousRevision,\n\t\t\tevents: state.events.slice(-eventCount).map(cloneGoalEventForStorage),\n\t\t};\n\t\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n\t}\n\n\tconst payload: GoalCheckpointPayload = {\n\t\tversion: 2,\n\t\tkind: \"checkpoint\",\n\t\tstate: cloneGoalStateForStorage(state),\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\nexport function appendGoalClearedSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n\tclearedAt: string,\n): string {\n\tconst payload: GoalClearedPayload = {\n\t\tversion: 2,\n\t\tkind: \"cleared\",\n\t\tgoalId: state.goalId,\n\t\tbaseRevision: state.revision ?? 0,\n\t\tclearedAt,\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\n/** Legacy payload decode retained for imports and focused codec tests. */\nexport function decodeGoalStateSnapshotPayload(data: unknown): GoalState | undefined {\n\treturn decodeSessionSnapshotPayload(data, GOAL_STATE_SNAPSHOT_CODEC);\n}\n\ninterface GoalStateSource {\n\tgetLatestCustomEntryOnBranch: SessionManager[\"getLatestCustomEntryOnBranch\"];\n}\n\ninterface GoalStateCacheEntry {\n\tlatestEntryId: string | null;\n\tstate: GoalState | undefined;\n}\n\nconst goalStateCache = new WeakMap<GoalStateSource, GoalStateCacheEntry>();\n\nfunction cacheGoalState(\n\tsessionManager: GoalStateSource,\n\tlatestEntryId: string | null,\n\tstate: GoalState | undefined,\n): GoalState | undefined {\n\tconst stored = state ? cloneGoalStateForStorage(state) : undefined;\n\tgoalStateCache.set(sessionManager, { latestEntryId, state: stored });\n\treturn stored ? cloneGoalStateForStorage(stored) : undefined;\n}\n\n/**\n * Reconstruct the latest goal from one checkpoint plus linear event batches. Any malformed newest\n * goal journal fails closed instead of skipping backward to an older active state and resurrecting\n * work after corruption.\n */\nexport function getLatestGoalStateSnapshot(sessionManager: GoalStateSource): GoalState | undefined {\n\tconst latestEntry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE);\n\tconst latestEntryId = latestEntry?.id ?? null;\n\tconst cached = goalStateCache.get(sessionManager);\n\tif (cached?.latestEntryId === latestEntryId) {\n\t\treturn cached.state ? cloneGoalStateForStorage(cached.state) : undefined;\n\t}\n\tif (!latestEntry) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\n\tconst batches: GoalEventBatchPayload[] = [];\n\tlet entry = latestEntry;\n\tfor (;;) {\n\t\tconst legacy = decodeGoalStateSnapshotPayload(entry.data);\n\t\tconst journal = legacy ? undefined : decodeGoalJournalPayload(entry.data);\n\t\tif (!legacy && !journal) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tif (journal?.kind === \"cleared\") return cacheGoalState(sessionManager, latestEntryId, undefined);\n\n\t\tconst checkpoint = legacy ?? (journal?.kind === \"checkpoint\" ? journal.state : undefined);\n\t\tif (checkpoint) {\n\t\t\tlet state = checkpoint;\n\t\t\tfor (const batch of batches.reverse()) {\n\t\t\t\tif (batch.goalId !== state.goalId || batch.baseRevision !== (state.revision ?? 0)) {\n\t\t\t\t\treturn cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\t\t\t}\n\t\t\t\tfor (const event of batch.events) state = applyGoalEvent(state, event);\n\t\t\t}\n\t\t\treturn cacheGoalState(sessionManager, latestEntryId, state);\n\t\t}\n\n\t\tif (journal?.kind !== \"events\") return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tbatches.push(journal);\n\t\tif (entry.parentId === null) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tconst previousEntry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE, entry.parentId);\n\t\tif (!previousEntry) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tentry = previousEntry;\n\t}\n}\n\n/** Explicit legacy writer for migration tests only. */\nexport function appendLegacyGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\treturn appendSessionSnapshot(sessionManager, GOAL_STATE_SNAPSHOT_CODEC, state);\n}\n"]}
1
+ {"version":3,"file":"session-goal-state.js","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qBAAqB,EACrB,4BAA4B,GAG5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EACN,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EAGxB,WAAW,EACX,WAAW,EACX,sBAAsB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAY,CAAC;AAInD,MAAM,yBAAyB,GAA6C;IAC3E,UAAU,EAAE,sBAAsB;IAClC,QAAQ,EAAE,OAAO;IACjB,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,wBAAwB;CAC/B,CAAC;AA0BF,SAAS,oBAAoB,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,wBAAwB,CAAC,IAAa;IAC9C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAClG,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CA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AC,cAAc,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QAChG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;YAAE,OAAO,cAAc,CAAC,cAAc,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QAC7F,MAAM,aAAa,GAAG,cAAc,CAAC,4BAA4B,CAAC,sBAAsB,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC1G,IAAI,CAAC,aAAa;YAAE,OAAO,cAAc,CAAC,cAAc,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QACpF,KAAK,GAAG,aAAa,CAAC;IACvB,CAAC;AACF,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,6BAA6B,CAC5C,cAAyD,EACzD,KAAgB;IAEhB,OAAO,qBAAqB,CAAC,cAAc,EAAE,yBAAyB,EAAE,KAAK,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tdecodeSessionSnapshotPayload,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport {\n\tapplyGoalEvent,\n\tcloneGoalEventForStorage,\n\tcloneGoalStateForStorage,\n\ttype GoalEvent,\n\ttype GoalState,\n\tisGoalEvent,\n\tisGoalState,\n\tMAX_GOAL_EVENT_HISTORY,\n} from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport type GoalStateSnapshotPayload = SessionSnapshotPayload<\"state\", GoalState>;\n\nconst GOAL_STATE_SNAPSHOT_CODEC: SessionSnapshotCodec<GoalState, \"state\"> = {\n\tcustomType: GOAL_STATE_CUSTOM_TYPE,\n\tvalueKey: \"state\",\n\tisValue: isGoalState,\n\tclone: cloneGoalStateForStorage,\n};\n\ninterface GoalEventBatchPayload {\n\tversion: 2;\n\tkind: \"events\";\n\tgoalId: string;\n\tbaseRevision: number;\n\tevents: readonly GoalEvent[];\n}\n\ninterface GoalCheckpointPayload {\n\tversion: 2;\n\tkind: \"checkpoint\";\n\tstate: GoalState;\n}\n\ninterface GoalClearedPayload {\n\tversion: 2;\n\tkind: \"cleared\";\n\tgoalId: string;\n\tbaseRevision: number;\n\tclearedAt: string;\n}\n\ntype GoalJournalPayload = GoalEventBatchPayload | GoalCheckpointPayload | GoalClearedPayload;\n\nfunction isNonNegativeInteger(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction decodeGoalJournalPayload(data: unknown): GoalJournalPayload | undefined {\n\tif (!isPlainRecord(data) || data.version !== 2 || typeof data.kind !== \"string\") return undefined;\n\tif (data.kind === \"checkpoint\") {\n\t\tif (!isGoalState(data.state)) return undefined;\n\t\treturn { version: 2, kind: \"checkpoint\", state: cloneGoalStateForStorage(data.state) };\n\t}\n\tif (data.kind === \"cleared\") {\n\t\tif (\n\t\t\ttypeof data.goalId !== \"string\" ||\n\t\t\t!isNonNegativeInteger(data.baseRevision) ||\n\t\t\ttypeof data.clearedAt !== \"string\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tversion: 2,\n\t\t\tkind: \"cleared\",\n\t\t\tgoalId: data.goalId,\n\t\t\tbaseRevision: data.baseRevision,\n\t\t\tclearedAt: data.clearedAt,\n\t\t};\n\t}\n\tif (data.kind !== \"events\") return undefined;\n\tif (\n\t\ttypeof data.goalId !== \"string\" ||\n\t\t!isNonNegativeInteger(data.baseRevision) ||\n\t\t!Array.isArray(data.events) ||\n\t\tdata.events.length === 0 ||\n\t\tdata.events.length > MAX_GOAL_EVENT_HISTORY ||\n\t\t!data.events.every(isGoalEvent)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tversion: 2,\n\t\tkind: \"events\",\n\t\tgoalId: data.goalId,\n\t\tbaseRevision: data.baseRevision,\n\t\tevents: data.events.map(cloneGoalEventForStorage),\n\t};\n}\n\n/**\n * Persist one state transition. Canonical reducer transitions are journaled as a bounded event\n * batch; starts, replacements, and non-canonical imports use one checkpoint. This removes the old\n * recursive full-state-on-every-mutation growth while keeping compound owner transitions atomic.\n */\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n\tprevious?: GoalState,\n): string {\n\tconst revision = state.revision ?? 0;\n\tconst previousRevision = previous?.revision ?? 0;\n\tconst eventCount = previous && previous.goalId === state.goalId ? revision - previousRevision : 0;\n\tif (previous && eventCount > 0 && eventCount <= state.events.length && eventCount <= MAX_GOAL_EVENT_HISTORY) {\n\t\tconst payload: GoalEventBatchPayload = {\n\t\t\tversion: 2,\n\t\t\tkind: \"events\",\n\t\t\tgoalId: state.goalId,\n\t\t\tbaseRevision: previousRevision,\n\t\t\tevents: state.events.slice(-eventCount).map(cloneGoalEventForStorage),\n\t\t};\n\t\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n\t}\n\n\tconst payload: GoalCheckpointPayload = {\n\t\tversion: 2,\n\t\tkind: \"checkpoint\",\n\t\tstate: cloneGoalStateForStorage(state),\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\nexport function appendGoalClearedSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n\tclearedAt: string,\n): string {\n\tconst payload: GoalClearedPayload = {\n\t\tversion: 2,\n\t\tkind: \"cleared\",\n\t\tgoalId: state.goalId,\n\t\tbaseRevision: state.revision ?? 0,\n\t\tclearedAt,\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\n/** Legacy payload decode retained for imports and focused codec tests. */\nexport function decodeGoalStateSnapshotPayload(data: unknown): GoalState | undefined {\n\treturn decodeSessionSnapshotPayload(data, GOAL_STATE_SNAPSHOT_CODEC);\n}\n\ninterface GoalStateSource {\n\tgetLatestCustomEntryOnBranch: SessionManager[\"getLatestCustomEntryOnBranch\"];\n}\n\ninterface GoalStateCacheEntry {\n\tlatestEntryId: string | null;\n\tstate: GoalState | undefined;\n}\n\nconst goalStateCache = new WeakMap<GoalStateSource, GoalStateCacheEntry>();\n\nfunction cacheGoalState(\n\tsessionManager: GoalStateSource,\n\tlatestEntryId: string | null,\n\tstate: GoalState | undefined,\n): GoalState | undefined {\n\tconst stored = state ? cloneGoalStateForStorage(state) : undefined;\n\tgoalStateCache.set(sessionManager, { latestEntryId, state: stored });\n\treturn stored ? cloneGoalStateForStorage(stored) : undefined;\n}\n\n/**\n * Reconstruct the latest goal from one checkpoint plus linear event batches. Any malformed newest\n * goal journal fails closed instead of skipping backward to an older active state and resurrecting\n * work after corruption.\n */\nexport function getLatestGoalStateSnapshot(sessionManager: GoalStateSource): GoalState | undefined {\n\tconst latestEntry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE);\n\tconst latestEntryId = latestEntry?.id ?? null;\n\tconst cached = goalStateCache.get(sessionManager);\n\tif (cached?.latestEntryId === latestEntryId) {\n\t\treturn cached.state ? cloneGoalStateForStorage(cached.state) : undefined;\n\t}\n\tif (!latestEntry) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\n\tconst batches: GoalEventBatchPayload[] = [];\n\tlet entry = latestEntry;\n\tfor (;;) {\n\t\tconst legacy = decodeGoalStateSnapshotPayload(entry.data);\n\t\tconst journal = legacy ? undefined : decodeGoalJournalPayload(entry.data);\n\t\tif (!legacy && !journal) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tif (journal?.kind === \"cleared\") return cacheGoalState(sessionManager, latestEntryId, undefined);\n\n\t\tconst checkpoint = legacy ?? (journal?.kind === \"checkpoint\" ? journal.state : undefined);\n\t\tif (checkpoint) {\n\t\t\tlet state = checkpoint;\n\t\t\tfor (const batch of batches.reverse()) {\n\t\t\t\tif (batch.goalId !== state.goalId || batch.baseRevision !== (state.revision ?? 0)) {\n\t\t\t\t\treturn cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\t\t\t}\n\t\t\t\tfor (const event of batch.events) state = applyGoalEvent(state, event);\n\t\t\t}\n\t\t\treturn cacheGoalState(sessionManager, latestEntryId, state);\n\t\t}\n\n\t\tif (journal?.kind !== \"events\") return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tbatches.push(journal);\n\t\tif (entry.parentId === null) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tconst previousEntry = sessionManager.getLatestCustomEntryOnBranch(GOAL_STATE_CUSTOM_TYPE, entry.parentId);\n\t\tif (!previousEntry) return cacheGoalState(sessionManager, latestEntryId, undefined);\n\t\tentry = previousEntry;\n\t}\n}\n\n/** Explicit legacy writer for migration tests only. */\nexport function appendLegacyGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\treturn appendSessionSnapshot(sessionManager, GOAL_STATE_SNAPSHOT_CODEC, state);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"http-dispatcher.d.ts","sourceRoot":"","sources":["../../src/core/http-dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAOxF,eAAO,MAAM,4BAA4B,SAAU,CAAC;AAKpD,MAAM,WAAW,2BAA2B;IAC3C,OAAO,EAAE,iBAAiB,CAAC;IAC3B,wFAAwF;IACxF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;EAO5B,CAAC;AAEX,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAgBzE;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAMjE;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC/C,OAAO,EAAE,iBAAiB,EAC1B,iBAAiB,EAAE,MAAM,GACvB,2BAA2B,CAiC7B;AAED,wBAAgB,uBAAuB,CAAC,SAAS,GAAE,MAAqC,GAAG,IAAI,CAgB9F","sourcesContent":["import { DEFAULT_STREAM_IDLE, type StreamIdleOptions } from \"@caupulican/pi-agent-core\";\nimport * as undici from \"undici\";\n\n// The default stays strictly greater than the stall watchdog's quiet bound (600s — see\n// pi-agent-core DEFAULT_STREAM_IDLE): 660s = quiet bound + 60s margin. Shorter explicit\n// values remain supported because constrainStreamIdleToHttpTimeout clamps every watchdog\n// phase and its adaptive ceiling below the nonzero undici timeout.\nexport const DEFAULT_HTTP_IDLE_TIMEOUT_MS = 660_000;\n\nconst MAX_HTTP_WATCHDOG_MARGIN_MS = 60_000;\nconst HTTP_WATCHDOG_MARGIN_RATIO = 0.1;\n\nexport interface HttpBoundedStreamIdlePolicy {\n\toptions: StreamIdleOptions;\n\t/** Undefined when the HTTP idle timeout is disabled and imposes no adaptive ceiling. */\n\tadaptiveCeilingMs?: number;\n}\n\nexport const HTTP_IDLE_TIMEOUT_CHOICES = [\n\t{ label: \"30 sec\", timeoutMs: 30_000 },\n\t{ label: \"1 min\", timeoutMs: 60_000 },\n\t{ label: \"2 min\", timeoutMs: 120_000 },\n\t{ label: \"5 min\", timeoutMs: 300_000 },\n\t{ label: \"11 min\", timeoutMs: 660_000 },\n\t{ label: \"disabled\", timeoutMs: 0 },\n] as const;\n\nexport function parseHttpIdleTimeoutMs(value: unknown): number | undefined {\n\tif (typeof value === \"string\") {\n\t\tconst trimmed = value.trim();\n\t\tif (trimmed.toLowerCase() === \"disabled\") {\n\t\t\treturn 0;\n\t\t}\n\t\tif (trimmed.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn parseHttpIdleTimeoutMs(Number(trimmed));\n\t}\n\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) {\n\t\treturn undefined;\n\t}\n\treturn Math.floor(value);\n}\n\nexport function formatHttpIdleTimeoutMs(timeoutMs: number): string {\n\tconst choice = HTTP_IDLE_TIMEOUT_CHOICES.find((item) => item.timeoutMs === timeoutMs);\n\tif (choice) {\n\t\treturn choice.label;\n\t}\n\treturn `${timeoutMs / 1000} sec`;\n}\n\n/**\n * Keep the phase-aware watchdog authoritative over undici's coarser headers/body idle timeout.\n * A nonzero HTTP timeout constrains every watchdog phase and adaptive expansion to a value with\n * a 10% margin (capped at 60s). Disabling the HTTP timeout leaves watchdog policy untouched.\n */\nexport function constrainStreamIdleToHttpTimeout(\n\toptions: StreamIdleOptions,\n\thttpIdleTimeoutMs: number,\n): HttpBoundedStreamIdlePolicy {\n\t// Settings intentionally expose an undefined field for each unset user override. A\n\t// spread can carry those values over the defaults before this boundary, so restore\n\t// the kernel defaults here instead of allowing Math.min(undefined, ...) to produce\n\t// a zero-delay NaN watchdog timer.\n\tconst resolvedOptions: StreamIdleOptions = {\n\t\t...options,\n\t\tconnectMs: options.connectMs ?? DEFAULT_STREAM_IDLE.connectMs,\n\t\tactiveIdleMs: options.activeIdleMs ?? DEFAULT_STREAM_IDLE.activeIdleMs,\n\t\tquietIdleMs: options.quietIdleMs ?? DEFAULT_STREAM_IDLE.quietIdleMs,\n\t};\n\tconst normalizedTimeoutMs = parseHttpIdleTimeoutMs(httpIdleTimeoutMs);\n\tif (normalizedTimeoutMs === undefined) {\n\t\tthrow new Error(`Invalid HTTP idle timeout: ${String(httpIdleTimeoutMs)}`);\n\t}\n\tif (normalizedTimeoutMs === 0) {\n\t\treturn { options: resolvedOptions };\n\t}\n\n\tconst marginMs = Math.min(\n\t\tMAX_HTTP_WATCHDOG_MARGIN_MS,\n\t\tMath.max(1, Math.floor(normalizedTimeoutMs * HTTP_WATCHDOG_MARGIN_RATIO)),\n\t);\n\tconst adaptiveCeilingMs = Math.max(0, normalizedTimeoutMs - marginMs);\n\treturn {\n\t\toptions: {\n\t\t\t...resolvedOptions,\n\t\t\tconnectMs: Math.min(resolvedOptions.connectMs, adaptiveCeilingMs),\n\t\t\tactiveIdleMs: Math.min(resolvedOptions.activeIdleMs, adaptiveCeilingMs),\n\t\t\tquietIdleMs: Math.min(resolvedOptions.quietIdleMs, adaptiveCeilingMs),\n\t\t},\n\t\tadaptiveCeilingMs,\n\t};\n}\n\nexport function configureHttpDispatcher(timeoutMs: number = DEFAULT_HTTP_IDLE_TIMEOUT_MS): void {\n\tconst normalizedTimeoutMs = parseHttpIdleTimeoutMs(timeoutMs);\n\tif (normalizedTimeoutMs === undefined) {\n\t\tthrow new Error(`Invalid HTTP idle timeout: ${String(timeoutMs)}`);\n\t}\n\tundici.setGlobalDispatcher(\n\t\tnew undici.EnvHttpProxyAgent({\n\t\t\tallowH2: false,\n\t\t\tbodyTimeout: normalizedTimeoutMs,\n\t\t\theadersTimeout: normalizedTimeoutMs,\n\t\t}),\n\t);\n\t// Keep fetch and the dispatcher on the same undici implementation. Node 26.0's\n\t// bundled fetch can otherwise consume compressed responses through npm undici's\n\t// dispatcher without decompressing them, causing response.json() failures.\n\tundici.install?.();\n}\n"]}
1
+ {"version":3,"file":"http-dispatcher.d.ts","sourceRoot":"","sources":["../../src/core/http-dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAOxF,eAAO,MAAM,4BAA4B,SAAU,CAAC;AAKpD,MAAM,WAAW,2BAA2B;IAC3C,OAAO,EAAE,iBAAiB,CAAC;IAC3B,wFAAwF;IACxF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,yBAAyB;aACnC,KAAK,EAAE,QAAQ;aAAE,SAAS,EAAE,KAAM;;aAClC,KAAK,EAAE,OAAO;aAAE,SAAS,EAAE,KAAM;;aACjC,KAAK,EAAE,OAAO;aAAE,SAAS,EAAE,MAAO;;aAClC,KAAK,EAAE,OAAO;aAAE,SAAS,EAAE,MAAO;;aAClC,KAAK,EAAE,QAAQ;aAAE,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mBAAmB,CACzB,IAAI,MAAM,CAAC,iBAAiB,CAAC;QAC5B,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,mBAAmB;QAChC,cAAc,EAAE,mBAAmB;KACnC,CAAC,CACF,CAAC;IACF,+EAA+E;IAC/E,gFAAgF;IAChF,2EAA2E;IAC3E,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;AAAA,CACnB","sourcesContent":["import { DEFAULT_STREAM_IDLE, type StreamIdleOptions } from \"@caupulican/pi-agent-core\";\nimport * as undici from \"undici\";\n\n// The default stays strictly greater than the stall watchdog's quiet bound (600s — see\n// pi-agent-core DEFAULT_STREAM_IDLE): 660s = quiet bound + 60s margin. Shorter explicit\n// values remain supported because constrainStreamIdleToHttpTimeout clamps every watchdog\n// phase and its adaptive ceiling below the nonzero undici timeout.\nexport const DEFAULT_HTTP_IDLE_TIMEOUT_MS = 660_000;\n\nconst MAX_HTTP_WATCHDOG_MARGIN_MS = 60_000;\nconst HTTP_WATCHDOG_MARGIN_RATIO = 0.1;\n\nexport interface HttpBoundedStreamIdlePolicy {\n\toptions: StreamIdleOptions;\n\t/** Undefined when the HTTP idle timeout is disabled and imposes no adaptive ceiling. */\n\tadaptiveCeilingMs?: number;\n}\n\nexport const HTTP_IDLE_TIMEOUT_CHOICES = [\n\t{ label: \"30 sec\", timeoutMs: 30_000 },\n\t{ label: \"1 min\", timeoutMs: 60_000 },\n\t{ label: \"2 min\", timeoutMs: 120_000 },\n\t{ label: \"5 min\", timeoutMs: 300_000 },\n\t{ label: \"11 min\", timeoutMs: 660_000 },\n\t{ label: \"disabled\", timeoutMs: 0 },\n] as const;\n\nexport function parseHttpIdleTimeoutMs(value: unknown): number | undefined {\n\tif (typeof value === \"string\") {\n\t\tconst trimmed = value.trim();\n\t\tif (trimmed.toLowerCase() === \"disabled\") {\n\t\t\treturn 0;\n\t\t}\n\t\tif (trimmed.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn parseHttpIdleTimeoutMs(Number(trimmed));\n\t}\n\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) {\n\t\treturn undefined;\n\t}\n\treturn Math.floor(value);\n}\n\nexport function formatHttpIdleTimeoutMs(timeoutMs: number): string {\n\tconst choice = HTTP_IDLE_TIMEOUT_CHOICES.find((item) => item.timeoutMs === timeoutMs);\n\tif (choice) {\n\t\treturn choice.label;\n\t}\n\treturn `${timeoutMs / 1000} sec`;\n}\n\n/**\n * Keep the phase-aware watchdog authoritative over undici's coarser headers/body idle timeout.\n * A nonzero HTTP timeout constrains every watchdog phase and adaptive expansion to a value with\n * a 10% margin (capped at 60s). Disabling the HTTP timeout leaves watchdog policy untouched.\n */\nexport function constrainStreamIdleToHttpTimeout(\n\toptions: StreamIdleOptions,\n\thttpIdleTimeoutMs: number,\n): HttpBoundedStreamIdlePolicy {\n\t// Settings intentionally expose an undefined field for each unset user override. A\n\t// spread can carry those values over the defaults before this boundary, so restore\n\t// the kernel defaults here instead of allowing Math.min(undefined, ...) to produce\n\t// a zero-delay NaN watchdog timer.\n\tconst resolvedOptions: StreamIdleOptions = {\n\t\t...options,\n\t\tconnectMs: options.connectMs ?? DEFAULT_STREAM_IDLE.connectMs,\n\t\tactiveIdleMs: options.activeIdleMs ?? DEFAULT_STREAM_IDLE.activeIdleMs,\n\t\tquietIdleMs: options.quietIdleMs ?? DEFAULT_STREAM_IDLE.quietIdleMs,\n\t};\n\tconst normalizedTimeoutMs = parseHttpIdleTimeoutMs(httpIdleTimeoutMs);\n\tif (normalizedTimeoutMs === undefined) {\n\t\tthrow new Error(`Invalid HTTP idle timeout: ${String(httpIdleTimeoutMs)}`);\n\t}\n\tif (normalizedTimeoutMs === 0) {\n\t\treturn { options: resolvedOptions };\n\t}\n\n\tconst marginMs = Math.min(\n\t\tMAX_HTTP_WATCHDOG_MARGIN_MS,\n\t\tMath.max(1, Math.floor(normalizedTimeoutMs * HTTP_WATCHDOG_MARGIN_RATIO)),\n\t);\n\tconst adaptiveCeilingMs = Math.max(0, normalizedTimeoutMs - marginMs);\n\treturn {\n\t\toptions: {\n\t\t\t...resolvedOptions,\n\t\t\tconnectMs: Math.min(resolvedOptions.connectMs, adaptiveCeilingMs),\n\t\t\tactiveIdleMs: Math.min(resolvedOptions.activeIdleMs, adaptiveCeilingMs),\n\t\t\tquietIdleMs: Math.min(resolvedOptions.quietIdleMs, adaptiveCeilingMs),\n\t\t},\n\t\tadaptiveCeilingMs,\n\t};\n}\n\nexport function configureHttpDispatcher(timeoutMs: number = DEFAULT_HTTP_IDLE_TIMEOUT_MS): void {\n\tconst normalizedTimeoutMs = parseHttpIdleTimeoutMs(timeoutMs);\n\tif (normalizedTimeoutMs === undefined) {\n\t\tthrow new Error(`Invalid HTTP idle timeout: ${String(timeoutMs)}`);\n\t}\n\tundici.setGlobalDispatcher(\n\t\tnew undici.EnvHttpProxyAgent({\n\t\t\tallowH2: false,\n\t\t\tbodyTimeout: normalizedTimeoutMs,\n\t\t\theadersTimeout: normalizedTimeoutMs,\n\t\t}),\n\t);\n\t// Keep fetch and the dispatcher on the same undici implementation. Node 26.0's\n\t// bundled fetch can otherwise consume compressed responses through npm undici's\n\t// dispatcher without decompressing them, causing response.json() failures.\n\tundici.install?.();\n}\n"]}
1
+ {"version":3,"file":"http-dispatcher.js","sourceRoot":"","sources":["../../src/core/http-dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAA0B,MAAM,2BAA2B,CAAC;AACxF,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,uFAAuF;AACvF,wFAAwF;AACxF,yFAAyF;AACzF,mEAAmE;AACnE,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAEpD,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAC3C,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAQvC,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACxC,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE;IACtC,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AC;SACrE;QACD,iBAAiB;KACjB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,SAAS,GAAW,4BAA4B;IACvF,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAC9D,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,MAAM,CAAC,mBAAmB,CACzB,IAAI,MAAM,CAAC,iBAAiB,CAAC;QAC5B,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,mBAAmB;QAChC,cAAc,EAAE,mBAAmB;KACnC,CAAC,CACF,CAAC;IACF,+EAA+E;IAC/E,gFAAgF;IAChF,2EAA2E;IAC3E,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import { DEFAULT_STREAM_IDLE, type StreamIdleOptions } from \"@caupulican/pi-agent-core\";\nimport * as undici from \"undici\";\n\n// The default stays strictly greater than the stall watchdog's quiet bound (600s — see\n// pi-agent-core DEFAULT_STREAM_IDLE): 660s = quiet bound + 60s margin. Shorter explicit\n// values remain supported because constrainStreamIdleToHttpTimeout clamps every watchdog\n// phase and its adaptive ceiling below the nonzero undici timeout.\nexport const DEFAULT_HTTP_IDLE_TIMEOUT_MS = 660_000;\n\nconst MAX_HTTP_WATCHDOG_MARGIN_MS = 60_000;\nconst HTTP_WATCHDOG_MARGIN_RATIO = 0.1;\n\nexport interface HttpBoundedStreamIdlePolicy {\n\toptions: StreamIdleOptions;\n\t/** Undefined when the HTTP idle timeout is disabled and imposes no adaptive ceiling. */\n\tadaptiveCeilingMs?: number;\n}\n\nexport const HTTP_IDLE_TIMEOUT_CHOICES = [\n\t{ label: \"30 sec\", timeoutMs: 30_000 },\n\t{ label: \"1 min\", timeoutMs: 60_000 },\n\t{ label: \"2 min\", timeoutMs: 120_000 },\n\t{ label: \"5 min\", timeoutMs: 300_000 },\n\t{ label: \"11 min\", timeoutMs: 660_000 },\n\t{ label: \"disabled\", timeoutMs: 0 },\n] as const;\n\nexport function parseHttpIdleTimeoutMs(value: unknown): number | undefined {\n\tif (typeof value === \"string\") {\n\t\tconst trimmed = value.trim();\n\t\tif (trimmed.toLowerCase() === \"disabled\") {\n\t\t\treturn 0;\n\t\t}\n\t\tif (trimmed.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn parseHttpIdleTimeoutMs(Number(trimmed));\n\t}\n\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) {\n\t\treturn undefined;\n\t}\n\treturn Math.floor(value);\n}\n\nexport function formatHttpIdleTimeoutMs(timeoutMs: number): string {\n\tconst choice = HTTP_IDLE_TIMEOUT_CHOICES.find((item) => item.timeoutMs === timeoutMs);\n\tif (choice) {\n\t\treturn choice.label;\n\t}\n\treturn `${timeoutMs / 1000} sec`;\n}\n\n/**\n * Keep the phase-aware watchdog authoritative over undici's coarser headers/body idle timeout.\n * A nonzero HTTP timeout constrains every watchdog phase and adaptive expansion to a value with\n * a 10% margin (capped at 60s). Disabling the HTTP timeout leaves watchdog policy untouched.\n */\nexport function constrainStreamIdleToHttpTimeout(\n\toptions: StreamIdleOptions,\n\thttpIdleTimeoutMs: number,\n): HttpBoundedStreamIdlePolicy {\n\t// Settings intentionally expose an undefined field for each unset user override. A\n\t// spread can carry those values over the defaults before this boundary, so restore\n\t// the kernel defaults here instead of allowing Math.min(undefined, ...) to produce\n\t// a zero-delay NaN watchdog timer.\n\tconst resolvedOptions: StreamIdleOptions = {\n\t\t...options,\n\t\tconnectMs: options.connectMs ?? DEFAULT_STREAM_IDLE.connectMs,\n\t\tactiveIdleMs: options.activeIdleMs ?? DEFAULT_STREAM_IDLE.activeIdleMs,\n\t\tquietIdleMs: options.quietIdleMs ?? DEFAULT_STREAM_IDLE.quietIdleMs,\n\t};\n\tconst normalizedTimeoutMs = parseHttpIdleTimeoutMs(httpIdleTimeoutMs);\n\tif (normalizedTimeoutMs === undefined) {\n\t\tthrow new Error(`Invalid HTTP idle timeout: ${String(httpIdleTimeoutMs)}`);\n\t}\n\tif (normalizedTimeoutMs === 0) {\n\t\treturn { options: resolvedOptions };\n\t}\n\n\tconst marginMs = Math.min(\n\t\tMAX_HTTP_WATCHDOG_MARGIN_MS,\n\t\tMath.max(1, Math.floor(normalizedTimeoutMs * HTTP_WATCHDOG_MARGIN_RATIO)),\n\t);\n\tconst adaptiveCeilingMs = Math.max(0, normalizedTimeoutMs - marginMs);\n\treturn {\n\t\toptions: {\n\t\t\t...resolvedOptions,\n\t\t\tconnectMs: Math.min(resolvedOptions.connectMs, adaptiveCeilingMs),\n\t\t\tactiveIdleMs: Math.min(resolvedOptions.activeIdleMs, adaptiveCeilingMs),\n\t\t\tquietIdleMs: Math.min(resolvedOptions.quietIdleMs, adaptiveCeilingMs),\n\t\t},\n\t\tadaptiveCeilingMs,\n\t};\n}\n\nexport function configureHttpDispatcher(timeoutMs: number = DEFAULT_HTTP_IDLE_TIMEOUT_MS): void {\n\tconst normalizedTimeoutMs = parseHttpIdleTimeoutMs(timeoutMs);\n\tif (normalizedTimeoutMs === undefined) {\n\t\tthrow new Error(`Invalid HTTP idle timeout: ${String(timeoutMs)}`);\n\t}\n\tundici.setGlobalDispatcher(\n\t\tnew undici.EnvHttpProxyAgent({\n\t\t\tallowH2: false,\n\t\t\tbodyTimeout: normalizedTimeoutMs,\n\t\t\theadersTimeout: normalizedTimeoutMs,\n\t\t}),\n\t);\n\t// Keep fetch and the dispatcher on the same undici implementation. Node 26.0's\n\t// bundled fetch can otherwise consume compressed responses through npm undici's\n\t// dispatcher without decompressing them, causing response.json() failures.\n\tundici.install?.();\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"human-input-controller.d.ts","sourceRoot":"","sources":["../../src/core/human-input-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAA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,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,qFAAqF;AACrF,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2B;IAChD,OAAO,CAAC,IAAI,CAAoC;IAChD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IAEtD,YAAY,IAAI,EAAE,wBAAwB,EAEzC;IAED,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAkCvD;IAED,2BAA2B,IAAI,IAAI,CAIlC;IAEK,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CA8EtC;IAED,OAAO,CAAC,mBAAmB;YAoBb,kBAAkB;CAmChC","sourcesContent":["import type { AgentMessage } from \"@caupulican/pi-agent-core\";\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { Api, ImageContent, Model, ToolResultMessage } from \"@caupulican/pi-ai\";\nimport type { ArtifactStore } from \"./context/context-artifacts.ts\";\nimport type { ExtensionContext, ExtensionUIContext } from \"./extensions/index.ts\";\nimport {\n\tbeginHumanInputRequest,\n\tcreateHumanInputRequest,\n\tformatHumanInputAnswerText,\n\tgetLatestHumanInputSnapshots,\n\tgetResumableHumanInputSnapshot,\n\tgetWorkerHumanInputsRequiringDelivery,\n\tHUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE,\n\ttype HumanInputRequest,\n\ttype HumanInputSnapshot,\n\tresolveHumanInput,\n} from \"./human-input.ts\";\nimport type { SessionImageStore } from \"./session-image-store.ts\";\n\nexport interface WorkerHumanInputRequest {\n\tworkerRequestId: string;\n\tmessage: string;\n\tblockers: readonly string[];\n}\n\ninterface HumanInputControllerDeps {\n\tgetSessionManager(): SessionManager;\n\tgetUIContext(): ExtensionUIContext | undefined;\n\tgetExtensionMode(): ExtensionContext[\"mode\"];\n\twaitForIdle(): Promise<void>;\n\tisDisposed(): boolean;\n\tisStreaming(): boolean;\n\tgetModel(): Model<Api> | undefined;\n\tgetArtifactStore(): ArtifactStore;\n\tgetImageStore(): SessionImageStore | undefined;\n\trunAgentPrompt(messages: AgentMessage | AgentMessage[]): Promise<void>;\n\tsendCustomMessage(\n\t\tmessage: { customType: string; content: string; display: boolean; details?: unknown },\n\t\toptions: { triggerTurn: boolean; deliverAs: \"followUp\" },\n\t): Promise<void>;\n\temitWarning(message: string): void;\n}\n\n/** Owns durable question replay and serialized worker-to-owner question delivery. */\nexport class HumanInputController {\n\tprivate readonly deps: HumanInputControllerDeps;\n\tprivate tail: Promise<void> = Promise.resolve();\n\tprivate readonly activeRequestIds = new Set<string>();\n\n\tconstructor(deps: HumanInputControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tqueueWorkerInput(request: WorkerHumanInputRequest): void {\n\t\tconst sessionManager = this.deps.getSessionManager();\n\t\tconst existing = getLatestHumanInputSnapshots(sessionManager).find(\n\t\t\t(snapshot) => snapshot.request.workerRequestId === request.workerRequestId,\n\t\t);\n\t\tif (existing) return;\n\t\tconst blockerText = request.blockers\n\t\t\t.slice(0, 4)\n\t\t\t.map((blocker) => blocker.slice(0, 500))\n\t\t\t.join(\"; \");\n\t\tconst question = createHumanInputRequest({\n\t\t\tsource: \"worker\",\n\t\t\tworkerRequestId: request.workerRequestId,\n\t\t\tquestions: [\n\t\t\t\t{\n\t\t\t\t\tid: \"worker_review\",\n\t\t\t\t\theader: \"Worker review\",\n\t\t\t\t\tquestion: `${request.message.slice(0, 1_500)}${blockerText ? ` Blockers: ${blockerText}` : \"\"}`,\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: \"Review now\",\n\t\t\t\t\t\t\tdescription: \"Have the parent inspect the worker claim and evidence before reconciling it.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: \"Keep blocked\",\n\t\t\t\t\t\t\tdescription: \"Leave the worker result blocked and continue without accepting its output.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t\tacceptsImages: false,\n\t\t});\n\t\tbeginHumanInputRequest(sessionManager, question);\n\t\tif (!this.deps.isStreaming()) this.scheduleWorkerInput(question);\n\t}\n\n\tschedulePendingWorkerInputs(): void {\n\t\tfor (const snapshot of getWorkerHumanInputsRequiringDelivery(this.deps.getSessionManager())) {\n\t\t\tthis.scheduleWorkerInput(snapshot);\n\t\t}\n\t}\n\n\tasync resumePending(): Promise<boolean> {\n\t\tif (this.deps.isDisposed() || this.deps.isStreaming()) return false;\n\t\tconst sessionManager = this.deps.getSessionManager();\n\t\tconst pending = getResumableHumanInputSnapshot(sessionManager);\n\t\tconst ui = this.deps.getUIContext();\n\t\tif (!ui) return false;\n\t\tlet resumed = false;\n\n\t\tif (pending?.request.toolCallId) {\n\t\t\tlet snapshot = pending;\n\t\t\tlet imageContents: readonly ImageContent[] = [];\n\t\t\tif (pending.status === \"pending\") {\n\t\t\t\tconst resolved = await resolveHumanInput({\n\t\t\t\t\tsessionManager,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\t...pending.request,\n\t\t\t\t\t\tacceptsImages: this.deps.getModel()?.input.includes(\"image\") ?? false,\n\t\t\t\t\t},\n\t\t\t\t\tpresent: (request, options) => ui.askQuestions(request, options),\n\t\t\t\t\tartifactStore: this.deps.getArtifactStore(),\n\t\t\t\t\tgetImageStore: () => this.deps.getImageStore(),\n\t\t\t\t});\n\t\t\t\tsnapshot = resolved.snapshot;\n\t\t\t\timageContents = resolved.imageContents;\n\t\t\t} else if (pending.status === \"answered\") {\n\t\t\t\tconst imageStore = this.deps.getImageStore();\n\t\t\t\tif (imageStore) {\n\t\t\t\t\tconst referencedText = snapshot.answers\n\t\t\t\t\t\t.flatMap((answer) => [answer.custom ?? \"\", ...(answer.images?.map((image) => image.label) ?? [])])\n\t\t\t\t\t\t.join(\" \");\n\t\t\t\t\timageContents = imageStore.resolveReferences(referencedText);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst answerImageCount = snapshot.answers.reduce((total, answer) => total + (answer.images?.length ?? 0), 0);\n\t\t\tconst modelAcceptsImages = this.deps.getModel()?.input.includes(\"image\") ?? false;\n\t\t\tconst missingImageNotice =\n\t\t\t\tanswerImageCount > imageContents.length\n\t\t\t\t\t? `\\n\\n[${answerImageCount - imageContents.length} attached image(s) could not be restored from durable storage.]`\n\t\t\t\t\t: \"\";\n\t\t\tconst unsupportedImageNotice =\n\t\t\t\timageContents.length > 0 && !modelAcceptsImages\n\t\t\t\t\t? \"\\n\\n[Attached images were retained but not sent because the selected model does not accept image input.]\"\n\t\t\t\t\t: \"\";\n\t\t\tconst toolResult: ToolResultMessage = {\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: pending.request.toolCallId,\n\t\t\t\ttoolName: pending.request.toolName ?? \"ask_question\",\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `${formatHumanInputAnswerText(snapshot)}${missingImageNotice}${unsupportedImageNotice}`,\n\t\t\t\t\t},\n\t\t\t\t\t...(modelAcceptsImages ? imageContents : []),\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tquestions: snapshot.request.questions,\n\t\t\t\t\tanswers: snapshot.answers,\n\t\t\t\t\tcancelled: snapshot.status === \"cancelled\",\n\t\t\t\t\t...(snapshot.reason ? { reason: snapshot.reason } : {}),\n\t\t\t\t},\n\t\t\t\tisError: false,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t};\n\t\t\tawait this.deps.runAgentPrompt(toolResult);\n\t\t\tresumed = true;\n\t\t}\n\n\t\tfor (const workerInput of getWorkerHumanInputsRequiringDelivery(sessionManager)) {\n\t\t\tif (this.activeRequestIds.has(workerInput.request.requestId)) continue;\n\t\t\tthis.activeRequestIds.add(workerInput.request.requestId);\n\t\t\ttry {\n\t\t\t\tresumed = (await this.resolveWorkerInput(workerInput)) || resumed;\n\t\t\t} finally {\n\t\t\t\tthis.activeRequestIds.delete(workerInput.request.requestId);\n\t\t\t}\n\t\t}\n\t\treturn resumed;\n\t}\n\n\tprivate scheduleWorkerInput(input: HumanInputRequest | HumanInputSnapshot): void {\n\t\tconst snapshot: HumanInputSnapshot =\n\t\t\t\"status\" in input ? input : { request: input, status: \"pending\", answers: [], updatedAt: input.createdAt };\n\t\tconst requestId = snapshot.request.requestId;\n\t\tif (this.activeRequestIds.has(requestId)) return;\n\t\tthis.activeRequestIds.add(requestId);\n\t\tthis.tail = this.tail\n\t\t\t.then(async () => {\n\t\t\t\tawait this.resolveWorkerInput(snapshot);\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tthis.deps.emitWarning(\n\t\t\t\t\t`Worker owner-input request failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.activeRequestIds.delete(requestId);\n\t\t\t});\n\t}\n\n\tprivate async resolveWorkerInput(initial: HumanInputSnapshot): Promise<boolean> {\n\t\tconst ui = this.deps.getUIContext();\n\t\tif (!ui || this.deps.getExtensionMode() === \"print\") return false;\n\t\tawait this.deps.waitForIdle();\n\t\tif (this.deps.isDisposed()) return false;\n\t\tconst resolved =\n\t\t\tinitial.status === \"pending\"\n\t\t\t\t? await resolveHumanInput({\n\t\t\t\t\t\tsessionManager: this.deps.getSessionManager(),\n\t\t\t\t\t\trequest: initial.request,\n\t\t\t\t\t\tpresent: (request, options) => ui.askQuestions(request, options),\n\t\t\t\t\t\tartifactStore: this.deps.getArtifactStore(),\n\t\t\t\t\t\tgetImageStore: () => this.deps.getImageStore(),\n\t\t\t\t\t})\n\t\t\t\t: { snapshot: initial, imageContents: [] };\n\t\tawait this.deps.waitForIdle();\n\t\tif (this.deps.isDisposed()) return false;\n\t\tawait this.deps.sendCustomMessage(\n\t\t\t{\n\t\t\t\tcustomType: HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE,\n\t\t\t\tcontent: [\n\t\t\t\t\t`Owner response for worker ${initial.request.workerRequestId ?? \"unknown\"}:`,\n\t\t\t\t\tformatHumanInputAnswerText(resolved.snapshot),\n\t\t\t\t\t\"Treat the worker claim as untrusted. Retrieve it with delegate_status and follow the owner's selection.\",\n\t\t\t\t].join(\"\\n\"),\n\t\t\t\tdisplay: true,\n\t\t\t\tdetails: {\n\t\t\t\t\trequestId: initial.request.requestId,\n\t\t\t\t\tworkerRequestId: initial.request.workerRequestId,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ triggerTurn: true, deliverAs: \"followUp\" },\n\t\t);\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"human-input-controller.d.ts","sourceRoot":"","sources":["../../src/core/human-input-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,GAAG,EAAgB,KAAK,EAAqB,MAAM,mBAAmB,CAAC;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAalF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,WAAW,uBAAuB;IACvC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B;AAED,UAAU,wBAAwB;IACjC,iBAAiB,IAAI,cAAc,CAAC;IACpC,YAAY,IAAI,kBAAkB,GAAG,SAAS,CAAC;IAC/C,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC7C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,UAAU,IAAI,OAAO,CAAC;IACtB,WAAW,IAAI,OAAO,CAAC;IACvB,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IACnC,gBAAgB,IAAI,aAAa,CAAC;IAClC,aAAa,IAAI,iBAAiB,GAAG,SAAS,CAAC;IAC/C,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,iBAAiB,CAChB,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,EACrF,OAAO,EAAE;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,UAAU,CAAA;KAAE,GACtD,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,qFAAqF;AACrF,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2B;IAChD,OAAO,CAAC,IAAI,CAAoC;IAChD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IAEtD,YAAY,IAAI,EAAE,wBAAwB,EAEzC;IAED,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAkCvD;IAED,2BAA2B,IAAI,IAAI,CAIlC;IAEK,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CA8EtC;IAED,OAAO,CAAC,mBAAmB;YAoBb,kBAAkB;CAmChC"}
@@ -1,10 +1,9 @@
1
1
  import { beginHumanInputRequest, createHumanInputRequest, formatHumanInputAnswerText, getLatestHumanInputSnapshots, getResumableHumanInputSnapshot, getWorkerHumanInputsRequiringDelivery, HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE, resolveHumanInput, } from "./human-input.js";
2
2
  /** Owns durable question replay and serialized worker-to-owner question delivery. */
3
3
  export class HumanInputController {
4
- deps;
5
- tail = Promise.resolve();
6
- activeRequestIds = new Set();
7
4
  constructor(deps) {
5
+ this.tail = Promise.resolve();
6
+ this.activeRequestIds = new Set();
8
7
  this.deps = deps;
9
8
  }
10
9
  queueWorkerInput(request) {
@@ -1 +1 @@
1
- {"version":3,"file":"human-input-controller.js","sourceRoot":"","sources":["../../src/core/human-input-controller.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,4BAA4B,EAC5B,8BAA8B,EAC9B,qCAAqC,EACrC,uCAAuC,EAGvC,iBAAiB,GACjB,MAAM,kBAAkB,CAAC;AA2B1B,qFAAqF;AACrF,MAAM,OAAO,oBAAoB;IACf,IAAI,CAA2B;IACxC,IAAI,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC/B,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAEtD,YAAY,IAA8B,EAAE;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;IAED,gBAAgB,CAAC,OAAgC,EAAQ;QACxD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,4BAA4B,CAAC,cAAc,CAAC,CAAC,IAAI,CACjE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,CAAC,eAAe,CAC1E,CAAC;QACF,IAAI,QAAQ;YAAE,OAAO;QACrB,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ;aAClC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aACX,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;aACvC,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,MAAM,QAAQ,GAAG,uBAAuB,CAAC;YACxC,MAAM,EAAE,QAAQ;YAChB,eAAe,EAAE,OAA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AE,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC;gBAChE,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAC3C,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;aAC9C,CAAC;YACH,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;QAC7C,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAAE,OAAO,KAAK,CAAC;QACzC,MAAM,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAChC;YACC,UAAU,EAAE,uCAAuC;YACnD,OAAO,EAAE;gBACR,6BAA6B,OAAO,CAAC,OAAO,CAAC,eAAe,IAAI,SAAS,GAAG;gBAC5E,0BAA0B,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAC7C,yGAAyG;aACzG,CAAC,IAAI,CAAC,IAAI,CAAC;YACZ,OAAO,EAAE,IAAI;YACb,OAAO,EAAE;gBACR,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS;gBACpC,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,eAAe;aAChD;SACD,EACD,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAC5C,CAAC;QACF,OAAO,IAAI,CAAC;IAAA,CACZ;CACD","sourcesContent":["import type { AgentMessage } from \"@caupulican/pi-agent-core\";\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { Api, ImageContent, Model, ToolResultMessage } from \"@caupulican/pi-ai\";\nimport type { ArtifactStore } from \"./context/context-artifacts.ts\";\nimport type { ExtensionContext, ExtensionUIContext } from \"./extensions/index.ts\";\nimport {\n\tbeginHumanInputRequest,\n\tcreateHumanInputRequest,\n\tformatHumanInputAnswerText,\n\tgetLatestHumanInputSnapshots,\n\tgetResumableHumanInputSnapshot,\n\tgetWorkerHumanInputsRequiringDelivery,\n\tHUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE,\n\ttype HumanInputRequest,\n\ttype HumanInputSnapshot,\n\tresolveHumanInput,\n} from \"./human-input.ts\";\nimport type { SessionImageStore } from \"./session-image-store.ts\";\n\nexport interface WorkerHumanInputRequest {\n\tworkerRequestId: string;\n\tmessage: string;\n\tblockers: readonly string[];\n}\n\ninterface HumanInputControllerDeps {\n\tgetSessionManager(): SessionManager;\n\tgetUIContext(): ExtensionUIContext | undefined;\n\tgetExtensionMode(): ExtensionContext[\"mode\"];\n\twaitForIdle(): Promise<void>;\n\tisDisposed(): boolean;\n\tisStreaming(): boolean;\n\tgetModel(): Model<Api> | undefined;\n\tgetArtifactStore(): ArtifactStore;\n\tgetImageStore(): SessionImageStore | undefined;\n\trunAgentPrompt(messages: AgentMessage | AgentMessage[]): Promise<void>;\n\tsendCustomMessage(\n\t\tmessage: { customType: string; content: string; display: boolean; details?: unknown },\n\t\toptions: { triggerTurn: boolean; deliverAs: \"followUp\" },\n\t): Promise<void>;\n\temitWarning(message: string): void;\n}\n\n/** Owns durable question replay and serialized worker-to-owner question delivery. */\nexport class HumanInputController {\n\tprivate readonly deps: HumanInputControllerDeps;\n\tprivate tail: Promise<void> = Promise.resolve();\n\tprivate readonly activeRequestIds = new Set<string>();\n\n\tconstructor(deps: HumanInputControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tqueueWorkerInput(request: WorkerHumanInputRequest): void {\n\t\tconst sessionManager = this.deps.getSessionManager();\n\t\tconst existing = getLatestHumanInputSnapshots(sessionManager).find(\n\t\t\t(snapshot) => snapshot.request.workerRequestId === request.workerRequestId,\n\t\t);\n\t\tif (existing) return;\n\t\tconst blockerText = request.blockers\n\t\t\t.slice(0, 4)\n\t\t\t.map((blocker) => blocker.slice(0, 500))\n\t\t\t.join(\"; \");\n\t\tconst question = createHumanInputRequest({\n\t\t\tsource: \"worker\",\n\t\t\tworkerRequestId: request.workerRequestId,\n\t\t\tquestions: [\n\t\t\t\t{\n\t\t\t\t\tid: \"worker_review\",\n\t\t\t\t\theader: \"Worker review\",\n\t\t\t\t\tquestion: `${request.message.slice(0, 1_500)}${blockerText ? ` Blockers: ${blockerText}` : \"\"}`,\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: \"Review now\",\n\t\t\t\t\t\t\tdescription: \"Have the parent inspect the worker claim and evidence before reconciling it.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: \"Keep blocked\",\n\t\t\t\t\t\t\tdescription: \"Leave the worker result blocked and continue without accepting its output.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t\tacceptsImages: false,\n\t\t});\n\t\tbeginHumanInputRequest(sessionManager, question);\n\t\tif (!this.deps.isStreaming()) this.scheduleWorkerInput(question);\n\t}\n\n\tschedulePendingWorkerInputs(): void {\n\t\tfor (const snapshot of getWorkerHumanInputsRequiringDelivery(this.deps.getSessionManager())) {\n\t\t\tthis.scheduleWorkerInput(snapshot);\n\t\t}\n\t}\n\n\tasync resumePending(): Promise<boolean> {\n\t\tif (this.deps.isDisposed() || this.deps.isStreaming()) return false;\n\t\tconst sessionManager = this.deps.getSessionManager();\n\t\tconst pending = getResumableHumanInputSnapshot(sessionManager);\n\t\tconst ui = this.deps.getUIContext();\n\t\tif (!ui) return false;\n\t\tlet resumed = false;\n\n\t\tif (pending?.request.toolCallId) {\n\t\t\tlet snapshot = pending;\n\t\t\tlet imageContents: readonly ImageContent[] = [];\n\t\t\tif (pending.status === \"pending\") {\n\t\t\t\tconst resolved = await resolveHumanInput({\n\t\t\t\t\tsessionManager,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\t...pending.request,\n\t\t\t\t\t\tacceptsImages: this.deps.getModel()?.input.includes(\"image\") ?? false,\n\t\t\t\t\t},\n\t\t\t\t\tpresent: (request, options) => ui.askQuestions(request, options),\n\t\t\t\t\tartifactStore: this.deps.getArtifactStore(),\n\t\t\t\t\tgetImageStore: () => this.deps.getImageStore(),\n\t\t\t\t});\n\t\t\t\tsnapshot = resolved.snapshot;\n\t\t\t\timageContents = resolved.imageContents;\n\t\t\t} else if (pending.status === \"answered\") {\n\t\t\t\tconst imageStore = this.deps.getImageStore();\n\t\t\t\tif (imageStore) {\n\t\t\t\t\tconst referencedText = snapshot.answers\n\t\t\t\t\t\t.flatMap((answer) => [answer.custom ?? \"\", ...(answer.images?.map((image) => image.label) ?? [])])\n\t\t\t\t\t\t.join(\" \");\n\t\t\t\t\timageContents = imageStore.resolveReferences(referencedText);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst answerImageCount = snapshot.answers.reduce((total, answer) => total + (answer.images?.length ?? 0), 0);\n\t\t\tconst modelAcceptsImages = this.deps.getModel()?.input.includes(\"image\") ?? false;\n\t\t\tconst missingImageNotice =\n\t\t\t\tanswerImageCount > imageContents.length\n\t\t\t\t\t? `\\n\\n[${answerImageCount - imageContents.length} attached image(s) could not be restored from durable storage.]`\n\t\t\t\t\t: \"\";\n\t\t\tconst unsupportedImageNotice =\n\t\t\t\timageContents.length > 0 && !modelAcceptsImages\n\t\t\t\t\t? \"\\n\\n[Attached images were retained but not sent because the selected model does not accept image input.]\"\n\t\t\t\t\t: \"\";\n\t\t\tconst toolResult: ToolResultMessage = {\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: pending.request.toolCallId,\n\t\t\t\ttoolName: pending.request.toolName ?? \"ask_question\",\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `${formatHumanInputAnswerText(snapshot)}${missingImageNotice}${unsupportedImageNotice}`,\n\t\t\t\t\t},\n\t\t\t\t\t...(modelAcceptsImages ? imageContents : []),\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tquestions: snapshot.request.questions,\n\t\t\t\t\tanswers: snapshot.answers,\n\t\t\t\t\tcancelled: snapshot.status === \"cancelled\",\n\t\t\t\t\t...(snapshot.reason ? { reason: snapshot.reason } : {}),\n\t\t\t\t},\n\t\t\t\tisError: false,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t};\n\t\t\tawait this.deps.runAgentPrompt(toolResult);\n\t\t\tresumed = true;\n\t\t}\n\n\t\tfor (const workerInput of getWorkerHumanInputsRequiringDelivery(sessionManager)) {\n\t\t\tif (this.activeRequestIds.has(workerInput.request.requestId)) continue;\n\t\t\tthis.activeRequestIds.add(workerInput.request.requestId);\n\t\t\ttry {\n\t\t\t\tresumed = (await this.resolveWorkerInput(workerInput)) || resumed;\n\t\t\t} finally {\n\t\t\t\tthis.activeRequestIds.delete(workerInput.request.requestId);\n\t\t\t}\n\t\t}\n\t\treturn resumed;\n\t}\n\n\tprivate scheduleWorkerInput(input: HumanInputRequest | HumanInputSnapshot): void {\n\t\tconst snapshot: HumanInputSnapshot =\n\t\t\t\"status\" in input ? input : { request: input, status: \"pending\", answers: [], updatedAt: input.createdAt };\n\t\tconst requestId = snapshot.request.requestId;\n\t\tif (this.activeRequestIds.has(requestId)) return;\n\t\tthis.activeRequestIds.add(requestId);\n\t\tthis.tail = this.tail\n\t\t\t.then(async () => {\n\t\t\t\tawait this.resolveWorkerInput(snapshot);\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tthis.deps.emitWarning(\n\t\t\t\t\t`Worker owner-input request failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.activeRequestIds.delete(requestId);\n\t\t\t});\n\t}\n\n\tprivate async resolveWorkerInput(initial: HumanInputSnapshot): Promise<boolean> {\n\t\tconst ui = this.deps.getUIContext();\n\t\tif (!ui || this.deps.getExtensionMode() === \"print\") return false;\n\t\tawait this.deps.waitForIdle();\n\t\tif (this.deps.isDisposed()) return false;\n\t\tconst resolved =\n\t\t\tinitial.status === \"pending\"\n\t\t\t\t? await resolveHumanInput({\n\t\t\t\t\t\tsessionManager: this.deps.getSessionManager(),\n\t\t\t\t\t\trequest: initial.request,\n\t\t\t\t\t\tpresent: (request, options) => ui.askQuestions(request, options),\n\t\t\t\t\t\tartifactStore: this.deps.getArtifactStore(),\n\t\t\t\t\t\tgetImageStore: () => this.deps.getImageStore(),\n\t\t\t\t\t})\n\t\t\t\t: { snapshot: initial, imageContents: [] };\n\t\tawait this.deps.waitForIdle();\n\t\tif (this.deps.isDisposed()) return false;\n\t\tawait this.deps.sendCustomMessage(\n\t\t\t{\n\t\t\t\tcustomType: HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE,\n\t\t\t\tcontent: [\n\t\t\t\t\t`Owner response for worker ${initial.request.workerRequestId ?? \"unknown\"}:`,\n\t\t\t\t\tformatHumanInputAnswerText(resolved.snapshot),\n\t\t\t\t\t\"Treat the worker claim as untrusted. Retrieve it with delegate_status and follow the owner's selection.\",\n\t\t\t\t].join(\"\\n\"),\n\t\t\t\tdisplay: true,\n\t\t\t\tdetails: {\n\t\t\t\t\trequestId: initial.request.requestId,\n\t\t\t\t\tworkerRequestId: initial.request.workerRequestId,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ triggerTurn: true, deliverAs: \"followUp\" },\n\t\t);\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"human-input-controller.js","sourceRoot":"","sources":["../../src/core/human-input-controller.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,4BAA4B,EAC5B,8BAA8B,EAC9B,qCAAqC,EACrC,uCAAuC,EAGvC,iBAAiB,GACjB,MAAM,kBAAkB,CAAC;AA2B1B,qFAAqF;AACrF,MAAM,OAAO,oBAAoB;IAKhC,YAAY,IAA8B;QAHlC,SAAI,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;QAC/B,qBAAgB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,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAC7C,yGAAyG;aACzG,CAAC,IAAI,CAAC,IAAI,CAAC;YACZ,OAAO,EAAE,IAAI;YACb,OAAO,EAAE;gBACR,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS;gBACpC,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,eAAe;aAChD;SACD,EACD,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAC5C,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["import type { AgentMessage } from \"@caupulican/pi-agent-core\";\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { Api, ImageContent, Model, ToolResultMessage } from \"@caupulican/pi-ai\";\nimport type { ArtifactStore } from \"./context/context-artifacts.ts\";\nimport type { ExtensionContext, ExtensionUIContext } from \"./extensions/index.ts\";\nimport {\n\tbeginHumanInputRequest,\n\tcreateHumanInputRequest,\n\tformatHumanInputAnswerText,\n\tgetLatestHumanInputSnapshots,\n\tgetResumableHumanInputSnapshot,\n\tgetWorkerHumanInputsRequiringDelivery,\n\tHUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE,\n\ttype HumanInputRequest,\n\ttype HumanInputSnapshot,\n\tresolveHumanInput,\n} from \"./human-input.ts\";\nimport type { SessionImageStore } from \"./session-image-store.ts\";\n\nexport interface WorkerHumanInputRequest {\n\tworkerRequestId: string;\n\tmessage: string;\n\tblockers: readonly string[];\n}\n\ninterface HumanInputControllerDeps {\n\tgetSessionManager(): SessionManager;\n\tgetUIContext(): ExtensionUIContext | undefined;\n\tgetExtensionMode(): ExtensionContext[\"mode\"];\n\twaitForIdle(): Promise<void>;\n\tisDisposed(): boolean;\n\tisStreaming(): boolean;\n\tgetModel(): Model<Api> | undefined;\n\tgetArtifactStore(): ArtifactStore;\n\tgetImageStore(): SessionImageStore | undefined;\n\trunAgentPrompt(messages: AgentMessage | AgentMessage[]): Promise<void>;\n\tsendCustomMessage(\n\t\tmessage: { customType: string; content: string; display: boolean; details?: unknown },\n\t\toptions: { triggerTurn: boolean; deliverAs: \"followUp\" },\n\t): Promise<void>;\n\temitWarning(message: string): void;\n}\n\n/** Owns durable question replay and serialized worker-to-owner question delivery. */\nexport class HumanInputController {\n\tprivate readonly deps: HumanInputControllerDeps;\n\tprivate tail: Promise<void> = Promise.resolve();\n\tprivate readonly activeRequestIds = new Set<string>();\n\n\tconstructor(deps: HumanInputControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tqueueWorkerInput(request: WorkerHumanInputRequest): void {\n\t\tconst sessionManager = this.deps.getSessionManager();\n\t\tconst existing = getLatestHumanInputSnapshots(sessionManager).find(\n\t\t\t(snapshot) => snapshot.request.workerRequestId === request.workerRequestId,\n\t\t);\n\t\tif (existing) return;\n\t\tconst blockerText = request.blockers\n\t\t\t.slice(0, 4)\n\t\t\t.map((blocker) => blocker.slice(0, 500))\n\t\t\t.join(\"; \");\n\t\tconst question = createHumanInputRequest({\n\t\t\tsource: \"worker\",\n\t\t\tworkerRequestId: request.workerRequestId,\n\t\t\tquestions: [\n\t\t\t\t{\n\t\t\t\t\tid: \"worker_review\",\n\t\t\t\t\theader: \"Worker review\",\n\t\t\t\t\tquestion: `${request.message.slice(0, 1_500)}${blockerText ? ` Blockers: ${blockerText}` : \"\"}`,\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: \"Review now\",\n\t\t\t\t\t\t\tdescription: \"Have the parent inspect the worker claim and evidence before reconciling it.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: \"Keep blocked\",\n\t\t\t\t\t\t\tdescription: \"Leave the worker result blocked and continue without accepting its output.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t\tacceptsImages: false,\n\t\t});\n\t\tbeginHumanInputRequest(sessionManager, question);\n\t\tif (!this.deps.isStreaming()) this.scheduleWorkerInput(question);\n\t}\n\n\tschedulePendingWorkerInputs(): void {\n\t\tfor (const snapshot of getWorkerHumanInputsRequiringDelivery(this.deps.getSessionManager())) {\n\t\t\tthis.scheduleWorkerInput(snapshot);\n\t\t}\n\t}\n\n\tasync resumePending(): Promise<boolean> {\n\t\tif (this.deps.isDisposed() || this.deps.isStreaming()) return false;\n\t\tconst sessionManager = this.deps.getSessionManager();\n\t\tconst pending = getResumableHumanInputSnapshot(sessionManager);\n\t\tconst ui = this.deps.getUIContext();\n\t\tif (!ui) return false;\n\t\tlet resumed = false;\n\n\t\tif (pending?.request.toolCallId) {\n\t\t\tlet snapshot = pending;\n\t\t\tlet imageContents: readonly ImageContent[] = [];\n\t\t\tif (pending.status === \"pending\") {\n\t\t\t\tconst resolved = await resolveHumanInput({\n\t\t\t\t\tsessionManager,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\t...pending.request,\n\t\t\t\t\t\tacceptsImages: this.deps.getModel()?.input.includes(\"image\") ?? false,\n\t\t\t\t\t},\n\t\t\t\t\tpresent: (request, options) => ui.askQuestions(request, options),\n\t\t\t\t\tartifactStore: this.deps.getArtifactStore(),\n\t\t\t\t\tgetImageStore: () => this.deps.getImageStore(),\n\t\t\t\t});\n\t\t\t\tsnapshot = resolved.snapshot;\n\t\t\t\timageContents = resolved.imageContents;\n\t\t\t} else if (pending.status === \"answered\") {\n\t\t\t\tconst imageStore = this.deps.getImageStore();\n\t\t\t\tif (imageStore) {\n\t\t\t\t\tconst referencedText = snapshot.answers\n\t\t\t\t\t\t.flatMap((answer) => [answer.custom ?? \"\", ...(answer.images?.map((image) => image.label) ?? [])])\n\t\t\t\t\t\t.join(\" \");\n\t\t\t\t\timageContents = imageStore.resolveReferences(referencedText);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst answerImageCount = snapshot.answers.reduce((total, answer) => total + (answer.images?.length ?? 0), 0);\n\t\t\tconst modelAcceptsImages = this.deps.getModel()?.input.includes(\"image\") ?? false;\n\t\t\tconst missingImageNotice =\n\t\t\t\tanswerImageCount > imageContents.length\n\t\t\t\t\t? `\\n\\n[${answerImageCount - imageContents.length} attached image(s) could not be restored from durable storage.]`\n\t\t\t\t\t: \"\";\n\t\t\tconst unsupportedImageNotice =\n\t\t\t\timageContents.length > 0 && !modelAcceptsImages\n\t\t\t\t\t? \"\\n\\n[Attached images were retained but not sent because the selected model does not accept image input.]\"\n\t\t\t\t\t: \"\";\n\t\t\tconst toolResult: ToolResultMessage = {\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: pending.request.toolCallId,\n\t\t\t\ttoolName: pending.request.toolName ?? \"ask_question\",\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `${formatHumanInputAnswerText(snapshot)}${missingImageNotice}${unsupportedImageNotice}`,\n\t\t\t\t\t},\n\t\t\t\t\t...(modelAcceptsImages ? imageContents : []),\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tquestions: snapshot.request.questions,\n\t\t\t\t\tanswers: snapshot.answers,\n\t\t\t\t\tcancelled: snapshot.status === \"cancelled\",\n\t\t\t\t\t...(snapshot.reason ? { reason: snapshot.reason } : {}),\n\t\t\t\t},\n\t\t\t\tisError: false,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t};\n\t\t\tawait this.deps.runAgentPrompt(toolResult);\n\t\t\tresumed = true;\n\t\t}\n\n\t\tfor (const workerInput of getWorkerHumanInputsRequiringDelivery(sessionManager)) {\n\t\t\tif (this.activeRequestIds.has(workerInput.request.requestId)) continue;\n\t\t\tthis.activeRequestIds.add(workerInput.request.requestId);\n\t\t\ttry {\n\t\t\t\tresumed = (await this.resolveWorkerInput(workerInput)) || resumed;\n\t\t\t} finally {\n\t\t\t\tthis.activeRequestIds.delete(workerInput.request.requestId);\n\t\t\t}\n\t\t}\n\t\treturn resumed;\n\t}\n\n\tprivate scheduleWorkerInput(input: HumanInputRequest | HumanInputSnapshot): void {\n\t\tconst snapshot: HumanInputSnapshot =\n\t\t\t\"status\" in input ? input : { request: input, status: \"pending\", answers: [], updatedAt: input.createdAt };\n\t\tconst requestId = snapshot.request.requestId;\n\t\tif (this.activeRequestIds.has(requestId)) return;\n\t\tthis.activeRequestIds.add(requestId);\n\t\tthis.tail = this.tail\n\t\t\t.then(async () => {\n\t\t\t\tawait this.resolveWorkerInput(snapshot);\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tthis.deps.emitWarning(\n\t\t\t\t\t`Worker owner-input request failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.activeRequestIds.delete(requestId);\n\t\t\t});\n\t}\n\n\tprivate async resolveWorkerInput(initial: HumanInputSnapshot): Promise<boolean> {\n\t\tconst ui = this.deps.getUIContext();\n\t\tif (!ui || this.deps.getExtensionMode() === \"print\") return false;\n\t\tawait this.deps.waitForIdle();\n\t\tif (this.deps.isDisposed()) return false;\n\t\tconst resolved =\n\t\t\tinitial.status === \"pending\"\n\t\t\t\t? await resolveHumanInput({\n\t\t\t\t\t\tsessionManager: this.deps.getSessionManager(),\n\t\t\t\t\t\trequest: initial.request,\n\t\t\t\t\t\tpresent: (request, options) => ui.askQuestions(request, options),\n\t\t\t\t\t\tartifactStore: this.deps.getArtifactStore(),\n\t\t\t\t\t\tgetImageStore: () => this.deps.getImageStore(),\n\t\t\t\t\t})\n\t\t\t\t: { snapshot: initial, imageContents: [] };\n\t\tawait this.deps.waitForIdle();\n\t\tif (this.deps.isDisposed()) return false;\n\t\tawait this.deps.sendCustomMessage(\n\t\t\t{\n\t\t\t\tcustomType: HUMAN_INPUT_WORKER_RESPONSE_CUSTOM_TYPE,\n\t\t\t\tcontent: [\n\t\t\t\t\t`Owner response for worker ${initial.request.workerRequestId ?? \"unknown\"}:`,\n\t\t\t\t\tformatHumanInputAnswerText(resolved.snapshot),\n\t\t\t\t\t\"Treat the worker claim as untrusted. Retrieve it with delegate_status and follow the owner's selection.\",\n\t\t\t\t].join(\"\\n\"),\n\t\t\t\tdisplay: true,\n\t\t\t\tdetails: {\n\t\t\t\t\trequestId: initial.request.requestId,\n\t\t\t\t\tworkerRequestId: initial.request.workerRequestId,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ triggerTurn: true, deliverAs: \"followUp\" },\n\t\t);\n\t\treturn true;\n\t}\n}\n"]}
@@ -1 +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,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CACjB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,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"]}
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,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CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/E,MAAM,QAAQ,GAAG,MAAM,CAAC,cAAc;YACrC,CAAC,CAAC,uCAAuC,MAAM,CAAC,cAAc,CAAC,EAAE,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"]}
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,KAAK,CAAC;AAmGxC,SAAS,aAAa,CAAC,QAA4B;IAClD,OAAO;QACN,GAAG,QAAQ;QACX,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;KAC1D,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,MAAwB;IAC5C,OAAO;QACN,GAAG,MAAM;QACT,QAAQ,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC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0B,CAAC,QAA4B;IACtE,IAAI,QAAQ,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,MAAM,KAAK,aAAa;YACvC,CAAC,CAAC,gCAAgC;YAClC,CAAC,CAAC,QAAQ,CAAC,MAAM,KAAK,gBAAgB;gBACrC,CAAC,CAAC,yCAAyC;gBAC3C,CAAC,CAAC,yDAAyD,CAAC;IAC/D,CAAC;IACD,OAAO,QAAQ,CAAC,OAAO;SACrB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,GAAG,MAAM,CAAC,MAAM,8BAA8B,CAAC;QAC1E,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/E,MAAM,QAAQ,GAAG,MAAM,CAAC,cAAc;YACrC,CAAC,CAAC,uCAAuC,MAAM,CAAC,cAAc,CAAC,EAAE,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;IACtH,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","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"]}