@caupulican/pi-adaptative 0.81.41 → 0.81.43

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 (1480) hide show
  1. package/CHANGELOG.md +53 -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 +57 -80
  18. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
  19. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
  20. package/dist/bundled-resources/runtimes/pi-shell-engine/escapes.py +70 -0
  21. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +135 -63
  22. package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
  23. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +108 -22
  24. package/dist/bundled-resources/runtimes/pi-shell-engine/paths.py +10 -0
  25. package/dist/bundled-resources/runtimes/pi-shell-engine/proc.py +12 -4
  26. package/dist/bundled-resources/runtimes/pi-shell-engine/shell_args.py +22 -0
  27. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +10 -2
  28. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +131 -259
  29. package/dist/bundled-resources/skills/authorized-web-security-audit/SKILL.md +187 -0
  30. package/dist/bundled-resources/skills/authorized-web-security-audit/references/assessment-contract.md +92 -0
  31. package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +134 -0
  32. package/dist/bundled-resources/skills/evidence-gated-tdd/SKILL.md +93 -0
  33. package/dist/bundled-resources/skills/evidence-gated-tdd/references/evidence-model.md +27 -0
  34. package/dist/bundled-resources/skills/evidence-gated-tdd/references/security-scanners.md +24 -0
  35. package/dist/bundled-resources/skills/harness-self-adaptation/SKILL.md +4 -2
  36. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/SKILL.md +217 -0
  37. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/defensive-exploit-catalogue.md +175 -0
  38. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/tool-boundary-checklist.md +87 -0
  39. package/dist/bundled-resources/skills/skill-architect/SKILL.md +2 -2
  40. package/dist/bundled-resources/skills/skill-creator/SKILL.md +188 -0
  41. package/dist/bundled-resources/skills/skill-creator/references/pi-skill-contract.md +73 -0
  42. package/dist/bundled-resources/skills/skill-creator/scripts/init-skill.mjs +142 -0
  43. package/dist/bundled-resources/skills/skill-creator/scripts/validate-skill.mjs +122 -0
  44. package/dist/cli/args.d.ts.map +1 -1
  45. package/dist/cli/args.js.map +1 -1
  46. package/dist/cli/config-selector.d.ts.map +1 -1
  47. package/dist/cli/config-selector.js.map +1 -1
  48. package/dist/cli/file-processor.d.ts.map +1 -1
  49. package/dist/cli/file-processor.js +8 -8
  50. package/dist/cli/file-processor.js.map +1 -1
  51. package/dist/cli/initial-message.d.ts +1 -1
  52. package/dist/cli/initial-message.d.ts.map +1 -1
  53. package/dist/cli/initial-message.js.map +1 -1
  54. package/dist/cli/list-models.d.ts.map +1 -1
  55. package/dist/cli/list-models.js.map +1 -1
  56. package/dist/cli/piped-stdin.d.ts +4 -0
  57. package/dist/cli/piped-stdin.d.ts.map +1 -0
  58. package/dist/cli/piped-stdin.js +13 -0
  59. package/dist/cli/piped-stdin.js.map +1 -0
  60. package/dist/cli/session-picker.d.ts.map +1 -1
  61. package/dist/cli/session-picker.js.map +1 -1
  62. package/dist/cli.d.ts.map +1 -1
  63. package/dist/cli.js.map +1 -1
  64. package/dist/config.d.ts.map +1 -1
  65. package/dist/config.js +9 -14
  66. package/dist/config.js.map +1 -1
  67. package/dist/core/agent-directory-layout.d.ts.map +1 -1
  68. package/dist/core/agent-directory-layout.js.map +1 -1
  69. package/dist/core/agent-paths.d.ts +32 -0
  70. package/dist/core/agent-paths.d.ts.map +1 -1
  71. package/dist/core/agent-paths.js +65 -0
  72. package/dist/core/agent-paths.js.map +1 -1
  73. package/dist/core/agent-session-contracts.d.ts +24 -10
  74. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  75. package/dist/core/agent-session-contracts.js +1 -12
  76. package/dist/core/agent-session-contracts.js.map +1 -1
  77. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  78. package/dist/core/agent-session-runtime.js +10 -25
  79. package/dist/core/agent-session-runtime.js.map +1 -1
  80. package/dist/core/agent-session-services.d.ts.map +1 -1
  81. package/dist/core/agent-session-services.js.map +1 -1
  82. package/dist/core/agent-session.d.ts +24 -1
  83. package/dist/core/agent-session.d.ts.map +1 -1
  84. package/dist/core/agent-session.js +214 -246
  85. package/dist/core/agent-session.js.map +1 -1
  86. package/dist/core/auth-guidance.d.ts.map +1 -1
  87. package/dist/core/auth-guidance.js.map +1 -1
  88. package/dist/core/auth-storage.d.ts +4 -1
  89. package/dist/core/auth-storage.d.ts.map +1 -1
  90. package/dist/core/auth-storage.js +13 -39
  91. package/dist/core/auth-storage.js.map +1 -1
  92. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  93. package/dist/core/autonomy/approval-gate.js.map +1 -1
  94. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  95. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  96. package/dist/core/autonomy/contracts.d.ts +2 -0
  97. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  98. package/dist/core/autonomy/contracts.js.map +1 -1
  99. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  100. package/dist/core/autonomy/envelope-enforcement.js +4 -9
  101. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  102. package/dist/core/autonomy/evidence-finding-projection.d.ts +11 -0
  103. package/dist/core/autonomy/evidence-finding-projection.d.ts.map +1 -0
  104. package/dist/core/autonomy/evidence-finding-projection.js +37 -0
  105. package/dist/core/autonomy/evidence-finding-projection.js.map +1 -0
  106. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  107. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  108. package/dist/core/autonomy/gates.d.ts.map +1 -1
  109. package/dist/core/autonomy/gates.js.map +1 -1
  110. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -1
  111. package/dist/core/autonomy/lane-private-paths.js.map +1 -1
  112. package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
  113. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  114. package/dist/core/autonomy/lane-tool-surface.js +17 -4
  115. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  116. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  117. package/dist/core/autonomy/lane-tracker.js +2 -3
  118. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  119. package/dist/core/autonomy/path-scope.d.ts +14 -0
  120. package/dist/core/autonomy/path-scope.d.ts.map +1 -1
  121. package/dist/core/autonomy/path-scope.js +37 -6
  122. package/dist/core/autonomy/path-scope.js.map +1 -1
  123. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  124. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  125. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  126. package/dist/core/autonomy/status.d.ts.map +1 -1
  127. package/dist/core/autonomy/status.js.map +1 -1
  128. package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
  129. package/dist/core/autonomy/subagent-prompt.js.map +1 -1
  130. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  131. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  132. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  133. package/dist/core/autonomy-telemetry.js +2 -4
  134. package/dist/core/autonomy-telemetry.js.map +1 -1
  135. package/dist/core/background-lane-controller.d.ts +27 -1
  136. package/dist/core/background-lane-controller.d.ts.map +1 -1
  137. package/dist/core/background-lane-controller.js +34 -16
  138. package/dist/core/background-lane-controller.js.map +1 -1
  139. package/dist/core/background-tool-task-controller.d.ts +88 -0
  140. package/dist/core/background-tool-task-controller.d.ts.map +1 -0
  141. package/dist/core/background-tool-task-controller.js +470 -0
  142. package/dist/core/background-tool-task-controller.js.map +1 -0
  143. package/dist/core/bash-execution-controller.d.ts +1 -0
  144. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  145. package/dist/core/bash-execution-controller.js +5 -4
  146. package/dist/core/bash-execution-controller.js.map +1 -1
  147. package/dist/core/bash-executor.d.ts.map +1 -1
  148. package/dist/core/bash-executor.js.map +1 -1
  149. package/dist/core/bedrock-sso-login.d.ts.map +1 -1
  150. package/dist/core/bedrock-sso-login.js.map +1 -1
  151. package/dist/core/billing-failover-controller.d.ts.map +1 -1
  152. package/dist/core/billing-failover-controller.js +3 -3
  153. package/dist/core/billing-failover-controller.js.map +1 -1
  154. package/dist/core/billing-failover.d.ts.map +1 -1
  155. package/dist/core/billing-failover.js.map +1 -1
  156. package/dist/core/capability-contract.d.ts.map +1 -1
  157. package/dist/core/catalog-manager.d.ts.map +1 -1
  158. package/dist/core/catalog-manager.js +0 -0
  159. package/dist/core/catalog-manager.js.map +1 -1
  160. package/dist/core/compaction-controller.d.ts +2 -0
  161. package/dist/core/compaction-controller.d.ts.map +1 -1
  162. package/dist/core/compaction-controller.js +21 -8
  163. package/dist/core/compaction-controller.js.map +1 -1
  164. package/dist/core/compaction-support.d.ts +8 -0
  165. package/dist/core/compaction-support.d.ts.map +1 -1
  166. package/dist/core/compaction-support.js +0 -2
  167. package/dist/core/compaction-support.js.map +1 -1
  168. package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
  169. package/dist/core/context/artifact-retrieval.js.map +1 -1
  170. package/dist/core/context/brain-curator.d.ts.map +1 -1
  171. package/dist/core/context/brain-curator.js +14 -33
  172. package/dist/core/context/brain-curator.js.map +1 -1
  173. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  174. package/dist/core/context/context-artifacts.js +16 -24
  175. package/dist/core/context/context-artifacts.js.map +1 -1
  176. package/dist/core/context/context-audit.d.ts.map +1 -1
  177. package/dist/core/context/context-audit.js +3 -17
  178. package/dist/core/context/context-audit.js.map +1 -1
  179. package/dist/core/context/context-composition.d.ts.map +1 -1
  180. package/dist/core/context/context-composition.js.map +1 -1
  181. package/dist/core/context/context-item.d.ts.map +1 -1
  182. package/dist/core/context/context-item.js.map +1 -1
  183. package/dist/core/context/context-prompt-enforcement.d.ts.map +1 -1
  184. package/dist/core/context/context-prompt-enforcement.js +3 -16
  185. package/dist/core/context/context-prompt-enforcement.js.map +1 -1
  186. package/dist/core/context/context-prompt-policy.d.ts.map +1 -1
  187. package/dist/core/context/context-prompt-policy.js.map +1 -1
  188. package/dist/core/context/context-retention.d.ts.map +1 -1
  189. package/dist/core/context/context-retention.js.map +1 -1
  190. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  191. package/dist/core/context/context-store-retention.js.map +1 -1
  192. package/dist/core/context/context-store.d.ts.map +1 -1
  193. package/dist/core/context/context-store.js.map +1 -1
  194. package/dist/core/context/context-tool-result.d.ts +4 -0
  195. package/dist/core/context/context-tool-result.d.ts.map +1 -0
  196. package/dist/core/context/context-tool-result.js +15 -0
  197. package/dist/core/context/context-tool-result.js.map +1 -0
  198. package/dist/core/context/current-work-memory.d.ts.map +1 -1
  199. package/dist/core/context/current-work-memory.js.map +1 -1
  200. package/dist/core/context/file-store-memory-provider.d.ts.map +1 -1
  201. package/dist/core/context/file-store-memory-provider.js +7 -28
  202. package/dist/core/context/file-store-memory-provider.js.map +1 -1
  203. package/dist/core/context/local-memory-search.d.ts +11 -0
  204. package/dist/core/context/local-memory-search.d.ts.map +1 -0
  205. package/dist/core/context/local-memory-search.js +37 -0
  206. package/dist/core/context/local-memory-search.js.map +1 -0
  207. package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
  208. package/dist/core/context/long-term-memory-trigger.js.map +1 -1
  209. package/dist/core/context/memory-diagnostics.d.ts.map +1 -1
  210. package/dist/core/context/memory-diagnostics.js.map +1 -1
  211. package/dist/core/context/memory-index-store.d.ts.map +1 -1
  212. package/dist/core/context/memory-index-store.js.map +1 -1
  213. package/dist/core/context/memory-prompt-block.d.ts.map +1 -1
  214. package/dist/core/context/memory-prompt-block.js.map +1 -1
  215. package/dist/core/context/memory-prompt-budget.d.ts.map +1 -1
  216. package/dist/core/context/memory-prompt-budget.js.map +1 -1
  217. package/dist/core/context/memory-provider-contract.d.ts.map +1 -1
  218. package/dist/core/context/memory-provider-contract.js.map +1 -1
  219. package/dist/core/context/memory-retrieval.d.ts.map +1 -1
  220. package/dist/core/context/memory-retrieval.js.map +1 -1
  221. package/dist/core/context/memory-tier-composer.d.ts.map +1 -1
  222. package/dist/core/context/memory-tier-composer.js.map +1 -1
  223. package/dist/core/context/message-text.d.ts +7 -0
  224. package/dist/core/context/message-text.d.ts.map +1 -0
  225. package/dist/core/context/message-text.js +68 -0
  226. package/dist/core/context/message-text.js.map +1 -0
  227. package/dist/core/context/okf-memory-provider.d.ts.map +1 -1
  228. package/dist/core/context/okf-memory-provider.js +4 -30
  229. package/dist/core/context/okf-memory-provider.js.map +1 -1
  230. package/dist/core/context/okf-memory.d.ts.map +1 -1
  231. package/dist/core/context/okf-memory.js.map +1 -1
  232. package/dist/core/context/policy-engine.d.ts.map +1 -1
  233. package/dist/core/context/policy-engine.js.map +1 -1
  234. package/dist/core/context/policy-types.d.ts.map +1 -1
  235. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  236. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  237. package/dist/core/context/storage-authority.d.ts.map +1 -1
  238. package/dist/core/context/tool-output-packer.d.ts.map +1 -1
  239. package/dist/core/context/tool-output-packer.js.map +1 -1
  240. package/dist/core/context-gc.d.ts.map +1 -1
  241. package/dist/core/context-gc.js +14 -21
  242. package/dist/core/context-gc.js.map +1 -1
  243. package/dist/core/context-pipeline.d.ts +1 -3
  244. package/dist/core/context-pipeline.d.ts.map +1 -1
  245. package/dist/core/context-pipeline.js +64 -145
  246. package/dist/core/context-pipeline.js.map +1 -1
  247. package/dist/core/cost/cost-summary.d.ts.map +1 -1
  248. package/dist/core/cost/cost-summary.js.map +1 -1
  249. package/dist/core/cost/daily-usage.d.ts.map +1 -1
  250. package/dist/core/cost/daily-usage.js.map +1 -1
  251. package/dist/core/cost/session-usage.d.ts.map +1 -1
  252. package/dist/core/cost/session-usage.js.map +1 -1
  253. package/dist/core/cost-guard.d.ts.map +1 -1
  254. package/dist/core/cost-guard.js.map +1 -1
  255. package/dist/core/default-tool-surface.d.ts.map +1 -1
  256. package/dist/core/default-tool-surface.js +1 -0
  257. package/dist/core/default-tool-surface.js.map +1 -1
  258. package/dist/core/defaults.d.ts.map +1 -1
  259. package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
  260. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  261. package/dist/core/delegation/managed-lane-controller.js +85 -46
  262. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  263. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
  264. package/dist/core/delegation/session-worker-claim.js +4 -3
  265. package/dist/core/delegation/session-worker-claim.js.map +1 -1
  266. package/dist/core/delegation/worker-action-journal.d.ts +73 -0
  267. package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
  268. package/dist/core/delegation/worker-action-journal.js +293 -0
  269. package/dist/core/delegation/worker-action-journal.js.map +1 -0
  270. package/dist/core/delegation/worker-actions.d.ts +36 -1
  271. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  272. package/dist/core/delegation/worker-actions.js +171 -46
  273. package/dist/core/delegation/worker-actions.js.map +1 -1
  274. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +76 -0
  275. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
  276. package/dist/core/delegation/worker-agent-control-coordinator.js +216 -0
  277. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
  278. package/dist/core/delegation/worker-agent-control.d.ts +66 -0
  279. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
  280. package/dist/core/delegation/worker-agent-control.js +160 -0
  281. package/dist/core/delegation/worker-agent-control.js.map +1 -0
  282. package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
  283. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
  284. package/dist/core/delegation/worker-attempt-executor.js +343 -0
  285. package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
  286. package/dist/core/delegation/worker-claim.d.ts +30 -0
  287. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  288. package/dist/core/delegation/worker-claim.js +205 -53
  289. package/dist/core/delegation/worker-claim.js.map +1 -1
  290. package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
  291. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
  292. package/dist/core/delegation/worker-conversation-store.js +440 -0
  293. package/dist/core/delegation/worker-conversation-store.js.map +1 -0
  294. package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
  295. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  296. package/dist/core/delegation/worker-delegation-controller.js +386 -260
  297. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  298. package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
  299. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  300. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  301. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
  302. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
  303. package/dist/core/delegation/worker-dispatch-scheduler.js +20 -11
  304. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
  305. package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
  306. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  307. package/dist/core/delegation/worker-execution-policy.js +5 -7
  308. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  309. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
  310. package/dist/core/delegation/worker-lane-projection.js.map +1 -1
  311. package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
  312. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  313. package/dist/core/delegation/worker-lifecycle.js +119 -2
  314. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  315. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
  316. package/dist/core/delegation/worker-notification-coordinator.js +4 -5
  317. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
  318. package/dist/core/delegation/worker-process-owner.d.ts +18 -0
  319. package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
  320. package/dist/core/delegation/worker-process-owner.js +54 -0
  321. package/dist/core/delegation/worker-process-owner.js.map +1 -0
  322. package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
  323. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  324. package/dist/core/delegation/worker-profile-resolver.js +9 -2
  325. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  326. package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
  327. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
  328. package/dist/core/delegation/worker-recovery-coordinator.js +180 -0
  329. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
  330. package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
  331. package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
  332. package/dist/core/delegation/worker-resource-catalog.js +116 -0
  333. package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
  334. package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
  335. package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
  336. package/dist/core/delegation/worker-resource-materializer.js +134 -0
  337. package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
  338. package/dist/core/delegation/worker-runner.d.ts +5 -5
  339. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  340. package/dist/core/delegation/worker-runner.js +193 -70
  341. package/dist/core/delegation/worker-runner.js.map +1 -1
  342. package/dist/core/delegation/worker-task-label.d.ts.map +1 -1
  343. package/dist/core/delegation/worker-task-label.js.map +1 -1
  344. package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
  345. package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
  346. package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
  347. package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
  348. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
  349. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
  350. package/dist/core/delegation/worker-write-reservation-coordinator.js +104 -0
  351. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
  352. package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
  353. package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
  354. package/dist/core/delegation/worker-write-reservation.js +346 -0
  355. package/dist/core/delegation/worker-write-reservation.js.map +1 -0
  356. package/dist/core/diagnostics.d.ts.map +1 -1
  357. package/dist/core/doctor.d.ts.map +1 -1
  358. package/dist/core/doctor.js.map +1 -1
  359. package/dist/core/event-bus.d.ts.map +1 -1
  360. package/dist/core/event-bus.js.map +1 -1
  361. package/dist/core/exec.d.ts.map +1 -1
  362. package/dist/core/exec.js +26 -7
  363. package/dist/core/exec.js.map +1 -1
  364. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  365. package/dist/core/export-html/ansi-to-html.js +21 -74
  366. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  367. package/dist/core/export-html/index.d.ts.map +1 -1
  368. package/dist/core/export-html/index.js +4 -0
  369. package/dist/core/export-html/index.js.map +1 -1
  370. package/dist/core/export-html/session-tree-foundations.d.mts +67 -0
  371. package/dist/core/export-html/session-tree-foundations.mjs +313 -0
  372. package/dist/core/export-html/template.css +14 -41
  373. package/dist/core/export-html/template.html +3 -1
  374. package/dist/core/export-html/template.js +26 -435
  375. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  376. package/dist/core/export-html/tool-renderer.js.map +1 -1
  377. package/dist/core/extension-import-authority.d.ts.map +1 -1
  378. package/dist/core/extension-import-authority.js.map +1 -1
  379. package/dist/core/extension-metadata.d.ts.map +1 -1
  380. package/dist/core/extension-metadata.js.map +1 -1
  381. package/dist/core/extensions/builtin.d.ts +17 -0
  382. package/dist/core/extensions/builtin.d.ts.map +1 -1
  383. package/dist/core/extensions/builtin.js +18 -54
  384. package/dist/core/extensions/builtin.js.map +1 -1
  385. package/dist/core/extensions/entry-resolution.d.ts +3 -0
  386. package/dist/core/extensions/entry-resolution.d.ts.map +1 -0
  387. package/dist/core/extensions/entry-resolution.js +17 -0
  388. package/dist/core/extensions/entry-resolution.js.map +1 -0
  389. package/dist/core/extensions/index.d.ts.map +1 -1
  390. package/dist/core/extensions/loader.d.ts.map +1 -1
  391. package/dist/core/extensions/loader.js +76 -21
  392. package/dist/core/extensions/loader.js.map +1 -1
  393. package/dist/core/extensions/runner.d.ts +2 -0
  394. package/dist/core/extensions/runner.d.ts.map +1 -1
  395. package/dist/core/extensions/runner.js +41 -112
  396. package/dist/core/extensions/runner.js.map +1 -1
  397. package/dist/core/extensions/stale-context.d.ts.map +1 -1
  398. package/dist/core/extensions/storage.d.ts.map +1 -1
  399. package/dist/core/extensions/storage.js.map +1 -1
  400. package/dist/core/extensions/types.d.ts.map +1 -1
  401. package/dist/core/extensions/types.js.map +1 -1
  402. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  403. package/dist/core/extensions/wrapper.js.map +1 -1
  404. package/dist/core/failure-corpus.d.ts.map +1 -1
  405. package/dist/core/failure-corpus.js +2 -5
  406. package/dist/core/failure-corpus.js.map +1 -1
  407. package/dist/core/footer-data-provider.d.ts.map +1 -1
  408. package/dist/core/footer-data-provider.js +27 -33
  409. package/dist/core/footer-data-provider.js.map +1 -1
  410. package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
  411. package/dist/core/foreground-recovery-controller.js +0 -4
  412. package/dist/core/foreground-recovery-controller.js.map +1 -1
  413. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  414. package/dist/core/gateways/channel-provider.js +7 -5
  415. package/dist/core/gateways/channel-provider.js.map +1 -1
  416. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  417. package/dist/core/goal-loop-controller.js +0 -1
  418. package/dist/core/goal-loop-controller.js.map +1 -1
  419. package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
  420. package/dist/core/goals/compact-goal-context.js +2 -4
  421. package/dist/core/goals/compact-goal-context.js.map +1 -1
  422. package/dist/core/goals/goal-acceptance.d.ts.map +1 -1
  423. package/dist/core/goals/goal-acceptance.js.map +1 -1
  424. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
  425. package/dist/core/goals/goal-auto-continue-controller.js +1 -3
  426. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
  427. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  428. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  429. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  430. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  431. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  432. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
  433. package/dist/core/goals/goal-lifecycle.js.map +1 -1
  434. package/dist/core/goals/goal-record.d.ts.map +1 -1
  435. package/dist/core/goals/goal-record.js.map +1 -1
  436. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  437. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  438. package/dist/core/goals/goal-session-controller.d.ts +15 -0
  439. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  440. package/dist/core/goals/goal-session-controller.js +27 -3
  441. package/dist/core/goals/goal-session-controller.js.map +1 -1
  442. package/dist/core/goals/goal-state.d.ts.map +1 -1
  443. package/dist/core/goals/goal-state.js +35 -51
  444. package/dist/core/goals/goal-state.js.map +1 -1
  445. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  446. package/dist/core/goals/goal-tool-core.js.map +1 -1
  447. package/dist/core/goals/natural-language-goal.d.ts +9 -0
  448. package/dist/core/goals/natural-language-goal.d.ts.map +1 -0
  449. package/dist/core/goals/natural-language-goal.js +23 -0
  450. package/dist/core/goals/natural-language-goal.js.map +1 -0
  451. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  452. package/dist/core/goals/session-goal-state.js.map +1 -1
  453. package/dist/core/http-dispatcher.d.ts.map +1 -1
  454. package/dist/core/http-dispatcher.js.map +1 -1
  455. package/dist/core/human-input-controller.d.ts.map +1 -1
  456. package/dist/core/human-input-controller.js +2 -3
  457. package/dist/core/human-input-controller.js.map +1 -1
  458. package/dist/core/human-input.d.ts.map +1 -1
  459. package/dist/core/human-input.js.map +1 -1
  460. package/dist/core/improvement-loop.d.ts.map +1 -1
  461. package/dist/core/improvement-loop.js +11 -11
  462. package/dist/core/improvement-loop.js.map +1 -1
  463. package/dist/core/index.d.ts.map +1 -1
  464. package/dist/core/install-telemetry.d.ts.map +1 -1
  465. package/dist/core/install-telemetry.js.map +1 -1
  466. package/dist/core/isolated-text-completion.d.ts +17 -0
  467. package/dist/core/isolated-text-completion.d.ts.map +1 -0
  468. package/dist/core/isolated-text-completion.js +15 -0
  469. package/dist/core/isolated-text-completion.js.map +1 -0
  470. package/dist/core/keybindings.d.ts +47 -2
  471. package/dist/core/keybindings.d.ts.map +1 -1
  472. package/dist/core/keybindings.js +12 -1
  473. package/dist/core/keybindings.js.map +1 -1
  474. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  475. package/dist/core/learning/learning-audit.js.map +1 -1
  476. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  477. package/dist/core/learning/learning-gate.js.map +1 -1
  478. package/dist/core/learning/observation-store.d.ts.map +1 -1
  479. package/dist/core/learning/observation-store.js +0 -2
  480. package/dist/core/learning/observation-store.js.map +1 -1
  481. package/dist/core/learning/reflection-engine.d.ts +1 -1
  482. package/dist/core/learning/reflection-engine.d.ts.map +1 -1
  483. package/dist/core/learning/reflection-engine.js +3 -0
  484. package/dist/core/learning/reflection-engine.js.map +1 -1
  485. package/dist/core/learning/reflection-turn-analysis.d.ts +20 -0
  486. package/dist/core/learning/reflection-turn-analysis.d.ts.map +1 -0
  487. package/dist/core/learning/reflection-turn-analysis.js +136 -0
  488. package/dist/core/learning/reflection-turn-analysis.js.map +1 -0
  489. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  490. package/dist/core/learning/session-learning-decision.js.map +1 -1
  491. package/dist/core/learning/skill-curator.d.ts.map +1 -1
  492. package/dist/core/learning/skill-curator.js +0 -3
  493. package/dist/core/learning/skill-curator.js.map +1 -1
  494. package/dist/core/local-runtime-controller.d.ts +39 -0
  495. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  496. package/dist/core/local-runtime-controller.js +41 -62
  497. package/dist/core/local-runtime-controller.js.map +1 -1
  498. package/dist/core/memory/effectiveness-tracker.d.ts.map +1 -1
  499. package/dist/core/memory/effectiveness-tracker.js +4 -2
  500. package/dist/core/memory/effectiveness-tracker.js.map +1 -1
  501. package/dist/core/memory/memory-manager.d.ts.map +1 -1
  502. package/dist/core/memory/memory-manager.js +7 -7
  503. package/dist/core/memory/memory-manager.js.map +1 -1
  504. package/dist/core/memory/memory-provider.d.ts.map +1 -1
  505. package/dist/core/memory/providers/file-store.d.ts +7 -0
  506. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  507. package/dist/core/memory/providers/file-store.js +48 -13
  508. package/dist/core/memory/providers/file-store.js.map +1 -1
  509. package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts +47 -0
  510. package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts.map +1 -0
  511. package/dist/core/memory/providers/transcript-recall-worker-protocol.js +50 -0
  512. package/dist/core/memory/providers/transcript-recall-worker-protocol.js.map +1 -0
  513. package/dist/core/memory/providers/transcript-recall-worker.d.ts +2 -0
  514. package/dist/core/memory/providers/transcript-recall-worker.d.ts.map +1 -0
  515. package/dist/core/memory/providers/transcript-recall-worker.js +143 -0
  516. package/dist/core/memory/providers/transcript-recall-worker.js.map +1 -0
  517. package/dist/core/memory/providers/transcript-recall.d.ts +24 -13
  518. package/dist/core/memory/providers/transcript-recall.d.ts.map +1 -1
  519. package/dist/core/memory/providers/transcript-recall.js +143 -141
  520. package/dist/core/memory/providers/transcript-recall.js.map +1 -1
  521. package/dist/core/memory/providers/user-memory-archive.d.ts +39 -0
  522. package/dist/core/memory/providers/user-memory-archive.d.ts.map +1 -0
  523. package/dist/core/memory/providers/user-memory-archive.js +258 -0
  524. package/dist/core/memory/providers/user-memory-archive.js.map +1 -0
  525. package/dist/core/memory/transcript-index.d.ts.map +1 -1
  526. package/dist/core/memory/transcript-index.js +1 -1
  527. package/dist/core/memory/transcript-index.js.map +1 -1
  528. package/dist/core/memory-controller.d.ts +9 -0
  529. package/dist/core/memory-controller.d.ts.map +1 -1
  530. package/dist/core/memory-controller.js +57 -16
  531. package/dist/core/memory-controller.js.map +1 -1
  532. package/dist/core/model-capability.d.ts.map +1 -1
  533. package/dist/core/model-capability.js.map +1 -1
  534. package/dist/core/model-output-json.d.ts +10 -0
  535. package/dist/core/model-output-json.d.ts.map +1 -0
  536. package/dist/core/model-output-json.js +43 -0
  537. package/dist/core/model-output-json.js.map +1 -0
  538. package/dist/core/model-registry.d.ts +8 -8
  539. package/dist/core/model-registry.d.ts.map +1 -1
  540. package/dist/core/model-registry.js +29 -52
  541. package/dist/core/model-registry.js.map +1 -1
  542. package/dist/core/model-resolver.d.ts.map +1 -1
  543. package/dist/core/model-resolver.js +1 -1
  544. package/dist/core/model-resolver.js.map +1 -1
  545. package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
  546. package/dist/core/model-router/config-diagnostics.js.map +1 -1
  547. package/dist/core/model-router/executor-route.d.ts.map +1 -1
  548. package/dist/core/model-router/executor-route.js.map +1 -1
  549. package/dist/core/model-router/fitness-gate.d.ts.map +1 -1
  550. package/dist/core/model-router/fitness-gate.js.map +1 -1
  551. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  552. package/dist/core/model-router/route-judge.d.ts.map +1 -1
  553. package/dist/core/model-router/route-judge.js +18 -36
  554. package/dist/core/model-router/route-judge.js.map +1 -1
  555. package/dist/core/model-router/session-buffer.d.ts.map +1 -1
  556. package/dist/core/model-router/session-buffer.js.map +1 -1
  557. package/dist/core/model-router/status.d.ts.map +1 -1
  558. package/dist/core/model-router/status.js.map +1 -1
  559. package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
  560. package/dist/core/model-router/tool-escalation.js.map +1 -1
  561. package/dist/core/model-router-controller.d.ts +1 -0
  562. package/dist/core/model-router-controller.d.ts.map +1 -1
  563. package/dist/core/model-router-controller.js +25 -56
  564. package/dist/core/model-router-controller.js.map +1 -1
  565. package/dist/core/model-selection-controller.d.ts +10 -0
  566. package/dist/core/model-selection-controller.d.ts.map +1 -1
  567. package/dist/core/model-selection-controller.js +0 -1
  568. package/dist/core/model-selection-controller.js.map +1 -1
  569. package/dist/core/model-tool-protocol.d.ts.map +1 -1
  570. package/dist/core/model-tool-protocol.js.map +1 -1
  571. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  572. package/dist/core/models/adaptation-store.js +0 -1
  573. package/dist/core/models/adaptation-store.js.map +1 -1
  574. package/dist/core/models/context-sizing.d.ts.map +1 -1
  575. package/dist/core/models/context-sizing.js.map +1 -1
  576. package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
  577. package/dist/core/models/default-model-suggestions.js.map +1 -1
  578. package/dist/core/models/fitness-store.d.ts.map +1 -1
  579. package/dist/core/models/fitness-store.js +0 -1
  580. package/dist/core/models/fitness-store.js.map +1 -1
  581. package/dist/core/models/host-state-store.d.ts.map +1 -1
  582. package/dist/core/models/host-state-store.js +1 -6
  583. package/dist/core/models/host-state-store.js.map +1 -1
  584. package/dist/core/models/llamacpp-runtime.d.ts +4 -19
  585. package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
  586. package/dist/core/models/llamacpp-runtime.js +32 -136
  587. package/dist/core/models/llamacpp-runtime.js.map +1 -1
  588. package/dist/core/models/local-registration.d.ts.map +1 -1
  589. package/dist/core/models/local-registration.js +82 -115
  590. package/dist/core/models/local-registration.js.map +1 -1
  591. package/dist/core/models/local-runtime.d.ts +12 -18
  592. package/dist/core/models/local-runtime.d.ts.map +1 -1
  593. package/dist/core/models/local-runtime.js +60 -204
  594. package/dist/core/models/local-runtime.js.map +1 -1
  595. package/dist/core/models/model-endpoint.d.ts +3 -0
  596. package/dist/core/models/model-endpoint.d.ts.map +1 -0
  597. package/dist/core/models/model-endpoint.js +11 -0
  598. package/dist/core/models/model-endpoint.js.map +1 -0
  599. package/dist/core/models/model-ref.d.ts.map +1 -1
  600. package/dist/core/models/model-ref.js.map +1 -1
  601. package/dist/core/models/needle-runtime.d.ts +7 -3
  602. package/dist/core/models/needle-runtime.d.ts.map +1 -1
  603. package/dist/core/models/needle-runtime.js +16 -92
  604. package/dist/core/models/needle-runtime.js.map +1 -1
  605. package/dist/core/models/perf-profile.d.ts +1 -1
  606. package/dist/core/models/perf-profile.d.ts.map +1 -1
  607. package/dist/core/models/perf-profile.js +6 -13
  608. package/dist/core/models/perf-profile.js.map +1 -1
  609. package/dist/core/models/prism-llamacpp-lifecycle.d.ts.map +1 -1
  610. package/dist/core/models/prism-llamacpp-lifecycle.js.map +1 -1
  611. package/dist/core/models/runtime-arbiter.d.ts.map +1 -1
  612. package/dist/core/models/runtime-arbiter.js +3 -15
  613. package/dist/core/models/runtime-arbiter.js.map +1 -1
  614. package/dist/core/models/runtime-process.d.ts +100 -0
  615. package/dist/core/models/runtime-process.d.ts.map +1 -0
  616. package/dist/core/models/runtime-process.js +183 -0
  617. package/dist/core/models/runtime-process.js.map +1 -0
  618. package/dist/core/orchestration/agent-resume.d.ts +2 -0
  619. package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
  620. package/dist/core/orchestration/agent-resume.js +7 -0
  621. package/dist/core/orchestration/agent-resume.js.map +1 -1
  622. package/dist/core/orchestration/attempt-usage.d.ts +28 -0
  623. package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
  624. package/dist/core/orchestration/attempt-usage.js +168 -0
  625. package/dist/core/orchestration/attempt-usage.js.map +1 -0
  626. package/dist/core/orchestration/capability-gateway.d.ts +19 -1
  627. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  628. package/dist/core/orchestration/capability-gateway.js +120 -34
  629. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  630. package/dist/core/orchestration/contracts.d.ts +35 -0
  631. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  632. package/dist/core/orchestration/contracts.js +17 -0
  633. package/dist/core/orchestration/contracts.js.map +1 -1
  634. package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
  635. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  636. package/dist/core/orchestration/delegation-ledger.js +78 -5
  637. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  638. package/dist/core/orchestration/event-store.d.ts +1 -0
  639. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  640. package/dist/core/orchestration/event-store.js +79 -52
  641. package/dist/core/orchestration/event-store.js.map +1 -1
  642. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  643. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  644. package/dist/core/orchestration/model-binding.d.ts.map +1 -1
  645. package/dist/core/orchestration/model-binding.js.map +1 -1
  646. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
  647. package/dist/core/orchestration/policy-compiler.js +0 -3
  648. package/dist/core/orchestration/policy-compiler.js.map +1 -1
  649. package/dist/core/orchestration/policy-gate.d.ts.map +1 -1
  650. package/dist/core/orchestration/policy-gate.js +0 -2
  651. package/dist/core/orchestration/policy-gate.js.map +1 -1
  652. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  653. package/dist/core/orchestration/profile-registry.js +82 -42
  654. package/dist/core/orchestration/profile-registry.js.map +1 -1
  655. package/dist/core/orchestration/profile-store.d.ts.map +1 -1
  656. package/dist/core/orchestration/profile-store.js +18 -7
  657. package/dist/core/orchestration/profile-store.js.map +1 -1
  658. package/dist/core/orchestration/risk-budget.d.ts +2 -0
  659. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  660. package/dist/core/orchestration/risk-budget.js +26 -0
  661. package/dist/core/orchestration/risk-budget.js.map +1 -1
  662. package/dist/core/orchestration/task-runtime.d.ts +14 -1
  663. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  664. package/dist/core/orchestration/task-runtime.js +153 -57
  665. package/dist/core/orchestration/task-runtime.js.map +1 -1
  666. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
  667. package/dist/core/orchestration/work-state-projection.js.map +1 -1
  668. package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
  669. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  670. package/dist/core/orchestration/worker-execution-contract.js +75 -23
  671. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  672. package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
  673. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
  674. package/dist/core/orchestration/worker-result-adapter.js +167 -14
  675. package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
  676. package/dist/core/output-guard.d.ts.map +1 -1
  677. package/dist/core/output-guard.js.map +1 -1
  678. package/dist/core/package-manager.d.ts +3 -0
  679. package/dist/core/package-manager.d.ts.map +1 -1
  680. package/dist/core/package-manager.js +88 -353
  681. package/dist/core/package-manager.js.map +1 -1
  682. package/dist/core/process-identity.d.ts.map +1 -1
  683. package/dist/core/process-identity.js.map +1 -1
  684. package/dist/core/process-liveness.d.ts +3 -0
  685. package/dist/core/process-liveness.d.ts.map +1 -0
  686. package/dist/core/process-liveness.js +17 -0
  687. package/dist/core/process-liveness.js.map +1 -0
  688. package/dist/core/process-matrix/codes.d.ts.map +1 -1
  689. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -1
  690. package/dist/core/process-matrix/resume-launcher.js.map +1 -1
  691. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  692. package/dist/core/process-matrix/runtime.js.map +1 -1
  693. package/dist/core/process-matrix/store.d.ts.map +1 -1
  694. package/dist/core/process-matrix/store.js.map +1 -1
  695. package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
  696. package/dist/core/process-matrix/supervisor.js.map +1 -1
  697. package/dist/core/profile-filter-controller.d.ts.map +1 -1
  698. package/dist/core/profile-filter-controller.js +7 -8
  699. package/dist/core/profile-filter-controller.js.map +1 -1
  700. package/dist/core/profile-registry.d.ts.map +1 -1
  701. package/dist/core/profile-registry.js +1 -2
  702. package/dist/core/profile-registry.js.map +1 -1
  703. package/dist/core/profile-resource-selection.d.ts.map +1 -1
  704. package/dist/core/profile-resource-selection.js +18 -59
  705. package/dist/core/profile-resource-selection.js.map +1 -1
  706. package/dist/core/prompt-markup.d.ts +3 -0
  707. package/dist/core/prompt-markup.d.ts.map +1 -0
  708. package/dist/core/prompt-markup.js +7 -0
  709. package/dist/core/prompt-markup.js.map +1 -0
  710. package/dist/core/prompt-templates.d.ts.map +1 -1
  711. package/dist/core/prompt-templates.js +13 -39
  712. package/dist/core/prompt-templates.js.map +1 -1
  713. package/dist/core/provider-display-names.d.ts.map +1 -1
  714. package/dist/core/python-runtime.d.ts.map +1 -1
  715. package/dist/core/python-runtime.js.map +1 -1
  716. package/dist/core/reflection-controller.d.ts +23 -2
  717. package/dist/core/reflection-controller.d.ts.map +1 -1
  718. package/dist/core/reflection-controller.js +233 -79
  719. package/dist/core/reflection-controller.js.map +1 -1
  720. package/dist/core/reload-blockers.d.ts +2 -1
  721. package/dist/core/reload-blockers.d.ts.map +1 -1
  722. package/dist/core/reload-blockers.js +4 -14
  723. package/dist/core/reload-blockers.js.map +1 -1
  724. package/dist/core/request-auth.d.ts.map +1 -1
  725. package/dist/core/request-auth.js.map +1 -1
  726. package/dist/core/research/automata-provider.d.ts.map +1 -1
  727. package/dist/core/research/automata-provider.js.map +1 -1
  728. package/dist/core/research/evidence-bundle.d.ts +20 -0
  729. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  730. package/dist/core/research/evidence-bundle.js +173 -69
  731. package/dist/core/research/evidence-bundle.js.map +1 -1
  732. package/dist/core/research/lane-model-resolver.d.ts.map +1 -1
  733. package/dist/core/research/lane-model-resolver.js +0 -1
  734. package/dist/core/research/lane-model-resolver.js.map +1 -1
  735. package/dist/core/research/model-fitness-controller.d.ts.map +1 -1
  736. package/dist/core/research/model-fitness-controller.js +17 -33
  737. package/dist/core/research/model-fitness-controller.js.map +1 -1
  738. package/dist/core/research/model-fitness.d.ts.map +1 -1
  739. package/dist/core/research/model-fitness.js +4 -25
  740. package/dist/core/research/model-fitness.js.map +1 -1
  741. package/dist/core/research/research-gate.d.ts.map +1 -1
  742. package/dist/core/research/research-gate.js.map +1 -1
  743. package/dist/core/research/research-lane-controller.d.ts.map +1 -1
  744. package/dist/core/research/research-lane-controller.js +5 -10
  745. package/dist/core/research/research-lane-controller.js.map +1 -1
  746. package/dist/core/research/research-runner.d.ts +2 -4
  747. package/dist/core/research/research-runner.d.ts.map +1 -1
  748. package/dist/core/research/research-runner.js +17 -48
  749. package/dist/core/research/research-runner.js.map +1 -1
  750. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  751. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  752. package/dist/core/research/workspace-collector.d.ts.map +1 -1
  753. package/dist/core/research/workspace-collector.js.map +1 -1
  754. package/dist/core/resolve-config-value.d.ts.map +1 -1
  755. package/dist/core/resolve-config-value.js.map +1 -1
  756. package/dist/core/resource-ignore.d.ts +6 -0
  757. package/dist/core/resource-ignore.d.ts.map +1 -0
  758. package/dist/core/resource-ignore.js +44 -0
  759. package/dist/core/resource-ignore.js.map +1 -0
  760. package/dist/core/resource-loader.d.ts +0 -1
  761. package/dist/core/resource-loader.d.ts.map +1 -1
  762. package/dist/core/resource-loader.js +52 -187
  763. package/dist/core/resource-loader.js.map +1 -1
  764. package/dist/core/resource-profile-blocks.d.ts +3 -1
  765. package/dist/core/resource-profile-blocks.d.ts.map +1 -1
  766. package/dist/core/resource-profile-blocks.js +8 -5
  767. package/dist/core/resource-profile-blocks.js.map +1 -1
  768. package/dist/core/resource-profile-equality.d.ts.map +1 -1
  769. package/dist/core/resource-profile-equality.js.map +1 -1
  770. package/dist/core/resource-traversal.d.ts +43 -0
  771. package/dist/core/resource-traversal.d.ts.map +1 -0
  772. package/dist/core/resource-traversal.js +84 -0
  773. package/dist/core/resource-traversal.js.map +1 -0
  774. package/dist/core/risk-classifier.d.ts.map +1 -1
  775. package/dist/core/risk-classifier.js.map +1 -1
  776. package/dist/core/runtime-builder.d.ts +11 -1
  777. package/dist/core/runtime-builder.d.ts.map +1 -1
  778. package/dist/core/runtime-builder.js +40 -51
  779. package/dist/core/runtime-builder.js.map +1 -1
  780. package/dist/core/scout-controller.d.ts.map +1 -1
  781. package/dist/core/scout-controller.js +0 -1
  782. package/dist/core/scout-controller.js.map +1 -1
  783. package/dist/core/sdk.d.ts.map +1 -1
  784. package/dist/core/sdk.js.map +1 -1
  785. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
  786. package/dist/core/secrets/credential-exposure-guard.js +70 -44
  787. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  788. package/dist/core/secrets/secret-dotenv.d.ts.map +1 -1
  789. package/dist/core/secrets/secret-dotenv.js +0 -1
  790. package/dist/core/secrets/secret-dotenv.js.map +1 -1
  791. package/dist/core/secrets/secret-vault-format.d.ts.map +1 -1
  792. package/dist/core/secrets/secret-vault-format.js +0 -1
  793. package/dist/core/secrets/secret-vault-format.js.map +1 -1
  794. package/dist/core/secrets/secret-vault.d.ts.map +1 -1
  795. package/dist/core/secrets/secret-vault.js +2 -10
  796. package/dist/core/secrets/secret-vault.js.map +1 -1
  797. package/dist/core/security/secret-text.d.ts.map +1 -1
  798. package/dist/core/security/secret-text.js.map +1 -1
  799. package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
  800. package/dist/core/security/untrusted-boundary.js.map +1 -1
  801. package/dist/core/session-analytics.d.ts.map +1 -1
  802. package/dist/core/session-analytics.js +18 -50
  803. package/dist/core/session-analytics.js.map +1 -1
  804. package/dist/core/session-artifact-bundle.d.ts +35 -0
  805. package/dist/core/session-artifact-bundle.d.ts.map +1 -0
  806. package/dist/core/session-artifact-bundle.js +61 -0
  807. package/dist/core/session-artifact-bundle.js.map +1 -0
  808. package/dist/core/session-cwd.d.ts.map +1 -1
  809. package/dist/core/session-cwd.js +0 -1
  810. package/dist/core/session-cwd.js.map +1 -1
  811. package/dist/core/session-entry-index.d.ts +8 -0
  812. package/dist/core/session-entry-index.d.ts.map +1 -0
  813. package/dist/core/session-entry-index.js +16 -0
  814. package/dist/core/session-entry-index.js.map +1 -0
  815. package/dist/core/session-image-store.d.ts.map +1 -1
  816. package/dist/core/session-image-store.js +0 -3
  817. package/dist/core/session-image-store.js.map +1 -1
  818. package/dist/core/session-jsonl-writer.d.ts +3 -0
  819. package/dist/core/session-jsonl-writer.d.ts.map +1 -0
  820. package/dist/core/session-jsonl-writer.js +38 -0
  821. package/dist/core/session-jsonl-writer.js.map +1 -0
  822. package/dist/core/session-manager-factory.d.ts.map +1 -1
  823. package/dist/core/session-manager-factory.js.map +1 -1
  824. package/dist/core/session-role.d.ts.map +1 -1
  825. package/dist/core/session-role.js.map +1 -1
  826. package/dist/core/session-snapshot.d.ts.map +1 -1
  827. package/dist/core/session-snapshot.js.map +1 -1
  828. package/dist/core/session-supervision-runtime.d.ts.map +1 -1
  829. package/dist/core/session-supervision-runtime.js +1 -4
  830. package/dist/core/session-supervision-runtime.js.map +1 -1
  831. package/dist/core/session-tree-navigator.d.ts.map +1 -1
  832. package/dist/core/session-tree-navigator.js +0 -1
  833. package/dist/core/session-tree-navigator.js.map +1 -1
  834. package/dist/core/settings-manager.d.ts +2 -1
  835. package/dist/core/settings-manager.d.ts.map +1 -1
  836. package/dist/core/settings-manager.js +64 -162
  837. package/dist/core/settings-manager.js.map +1 -1
  838. package/dist/core/skill-block.d.mts +8 -0
  839. package/dist/core/skill-block.mjs +52 -0
  840. package/dist/core/skill-discovery.d.ts +5 -0
  841. package/dist/core/skill-discovery.d.ts.map +1 -0
  842. package/dist/core/skill-discovery.js +34 -0
  843. package/dist/core/skill-discovery.js.map +1 -0
  844. package/dist/core/skills.d.ts.map +1 -1
  845. package/dist/core/skills.js +23 -159
  846. package/dist/core/skills.js.map +1 -1
  847. package/dist/core/slash-commands.d.ts.map +1 -1
  848. package/dist/core/source-info.d.ts.map +1 -1
  849. package/dist/core/source-info.js.map +1 -1
  850. package/dist/core/spawned-usage.d.ts +21 -0
  851. package/dist/core/spawned-usage.d.ts.map +1 -0
  852. package/dist/core/spawned-usage.js +29 -0
  853. package/dist/core/spawned-usage.js.map +1 -0
  854. package/dist/core/system-prompt-builder.d.ts +4 -0
  855. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  856. package/dist/core/system-prompt-builder.js +15 -8
  857. package/dist/core/system-prompt-builder.js.map +1 -1
  858. package/dist/core/system-prompt.d.ts.map +1 -1
  859. package/dist/core/system-prompt.js +52 -35
  860. package/dist/core/system-prompt.js.map +1 -1
  861. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  862. package/dist/core/tasks/session-task-state.js.map +1 -1
  863. package/dist/core/tasks/task-command.d.ts.map +1 -1
  864. package/dist/core/tasks/task-command.js.map +1 -1
  865. package/dist/core/tasks/task-contract-monitor.d.ts.map +1 -1
  866. package/dist/core/tasks/task-contract-monitor.js.map +1 -1
  867. package/dist/core/tasks/task-projection.d.ts.map +1 -1
  868. package/dist/core/tasks/task-projection.js.map +1 -1
  869. package/dist/core/tasks/task-state.d.ts.map +1 -1
  870. package/dist/core/tasks/task-state.js.map +1 -1
  871. package/dist/core/text-preview.d.ts +4 -0
  872. package/dist/core/text-preview.d.ts.map +1 -0
  873. package/dist/core/text-preview.js +33 -0
  874. package/dist/core/text-preview.js.map +1 -0
  875. package/dist/core/timings.d.ts.map +1 -1
  876. package/dist/core/timings.js.map +1 -1
  877. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  878. package/dist/core/tool-capability-policy.js.map +1 -1
  879. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  880. package/dist/core/tool-gate-controller.js +86 -87
  881. package/dist/core/tool-gate-controller.js.map +1 -1
  882. package/dist/core/tool-protocol-controller.d.ts +4 -1
  883. package/dist/core/tool-protocol-controller.d.ts.map +1 -1
  884. package/dist/core/tool-protocol-controller.js +19 -23
  885. package/dist/core/tool-protocol-controller.js.map +1 -1
  886. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  887. package/dist/core/tool-recovery-log-records.js.map +1 -1
  888. package/dist/core/tool-recovery-log-worker.d.ts.map +1 -1
  889. package/dist/core/tool-recovery-log-worker.js.map +1 -1
  890. package/dist/core/tool-recovery-logger.d.ts.map +1 -1
  891. package/dist/core/tool-recovery-logger.js +12 -24
  892. package/dist/core/tool-recovery-logger.js.map +1 -1
  893. package/dist/core/tool-recovery-stats.d.ts.map +1 -1
  894. package/dist/core/tool-recovery-stats.js +16 -22
  895. package/dist/core/tool-recovery-stats.js.map +1 -1
  896. package/dist/core/tool-repair-health.d.ts.map +1 -1
  897. package/dist/core/tool-repair-health.js.map +1 -1
  898. package/dist/core/tool-repair-settings.d.ts.map +1 -1
  899. package/dist/core/tool-repair-settings.js.map +1 -1
  900. package/dist/core/tool-selection/expected-utility.d.ts.map +1 -1
  901. package/dist/core/tool-selection/expected-utility.js.map +1 -1
  902. package/dist/core/tool-selection/promotion.d.ts.map +1 -1
  903. package/dist/core/tool-selection/promotion.js.map +1 -1
  904. package/dist/core/tool-selection/tool-performance-store.d.ts +2 -0
  905. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  906. package/dist/core/tool-selection/tool-performance-store.js +49 -7
  907. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  908. package/dist/core/tool-selection/tool-phase-timing.d.ts +19 -0
  909. package/dist/core/tool-selection/tool-phase-timing.d.ts.map +1 -0
  910. package/dist/core/tool-selection/tool-phase-timing.js +63 -0
  911. package/dist/core/tool-selection/tool-phase-timing.js.map +1 -0
  912. package/dist/core/tool-selection/tool-selection-controller.d.ts +2 -5
  913. package/dist/core/tool-selection/tool-selection-controller.d.ts.map +1 -1
  914. package/dist/core/tool-selection/tool-selection-controller.js +50 -30
  915. package/dist/core/tool-selection/tool-selection-controller.js.map +1 -1
  916. package/dist/core/toolkit/reflex-interpreter.d.ts +16 -0
  917. package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
  918. package/dist/core/toolkit/reflex-interpreter.js +21 -0
  919. package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
  920. package/dist/core/toolkit/script-registry.d.ts.map +1 -1
  921. package/dist/core/toolkit/script-registry.js.map +1 -1
  922. package/dist/core/toolkit/script-runner.d.ts.map +1 -1
  923. package/dist/core/toolkit/script-runner.js.map +1 -1
  924. package/dist/core/tools/artifact-retrieve.d.ts.map +1 -1
  925. package/dist/core/tools/artifact-retrieve.js.map +1 -1
  926. package/dist/core/tools/ask-question.d.ts +2 -3
  927. package/dist/core/tools/ask-question.d.ts.map +1 -1
  928. package/dist/core/tools/ask-question.js +14 -40
  929. package/dist/core/tools/ask-question.js.map +1 -1
  930. package/dist/core/tools/bash.d.ts +2 -0
  931. package/dist/core/tools/bash.d.ts.map +1 -1
  932. package/dist/core/tools/bash.js +83 -30
  933. package/dist/core/tools/bash.js.map +1 -1
  934. package/dist/core/tools/context-scout.d.ts.map +1 -1
  935. package/dist/core/tools/context-scout.js.map +1 -1
  936. package/dist/core/tools/delegate-status.d.ts +6 -1
  937. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  938. package/dist/core/tools/delegate-status.js +109 -25
  939. package/dist/core/tools/delegate-status.js.map +1 -1
  940. package/dist/core/tools/delegate.d.ts +9 -1
  941. package/dist/core/tools/delegate.d.ts.map +1 -1
  942. package/dist/core/tools/delegate.js +329 -67
  943. package/dist/core/tools/delegate.js.map +1 -1
  944. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  945. package/dist/core/tools/edit-diff.js.map +1 -1
  946. package/dist/core/tools/edit.d.ts.map +1 -1
  947. package/dist/core/tools/edit.js.map +1 -1
  948. package/dist/core/tools/extensionify.d.ts.map +1 -1
  949. package/dist/core/tools/extensionify.js.map +1 -1
  950. package/dist/core/tools/fff-search-backend.d.ts +19 -0
  951. package/dist/core/tools/fff-search-backend.d.ts.map +1 -1
  952. package/dist/core/tools/fff-search-backend.js +28 -2
  953. package/dist/core/tools/fff-search-backend.js.map +1 -1
  954. package/dist/core/tools/file-encoding-policy.d.ts.map +1 -1
  955. package/dist/core/tools/file-encoding-policy.js.map +1 -1
  956. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  957. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  958. package/dist/core/tools/find.d.ts +1 -1
  959. package/dist/core/tools/find.d.ts.map +1 -1
  960. package/dist/core/tools/find.js +44 -108
  961. package/dist/core/tools/find.js.map +1 -1
  962. package/dist/core/tools/git-filter.d.ts.map +1 -1
  963. package/dist/core/tools/git-filter.js.map +1 -1
  964. package/dist/core/tools/goal.d.ts.map +1 -1
  965. package/dist/core/tools/goal.js +7 -7
  966. package/dist/core/tools/goal.js.map +1 -1
  967. package/dist/core/tools/grep.d.ts +1 -1
  968. package/dist/core/tools/grep.d.ts.map +1 -1
  969. package/dist/core/tools/grep.js +42 -102
  970. package/dist/core/tools/grep.js.map +1 -1
  971. package/dist/core/tools/index.d.ts.map +1 -1
  972. package/dist/core/tools/index.js.map +1 -1
  973. package/dist/core/tools/ls.d.ts.map +1 -1
  974. package/dist/core/tools/ls.js +20 -36
  975. package/dist/core/tools/ls.js.map +1 -1
  976. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  977. package/dist/core/tools/model-fitness.js.map +1 -1
  978. package/dist/core/tools/orchestration-panel.d.ts +5 -0
  979. package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
  980. package/dist/core/tools/orchestration-panel.js +5 -5
  981. package/dist/core/tools/orchestration-panel.js.map +1 -1
  982. package/dist/core/tools/output-accumulator.d.ts +2 -0
  983. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  984. package/dist/core/tools/output-accumulator.js +24 -36
  985. package/dist/core/tools/output-accumulator.js.map +1 -1
  986. package/dist/core/tools/path-utils.d.ts.map +1 -1
  987. package/dist/core/tools/path-utils.js.map +1 -1
  988. package/dist/core/tools/persistent-process-coordinator.d.ts +31 -0
  989. package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -0
  990. package/dist/core/tools/persistent-process-coordinator.js +123 -0
  991. package/dist/core/tools/persistent-process-coordinator.js.map +1 -0
  992. package/dist/core/tools/python.d.ts.map +1 -1
  993. package/dist/core/tools/python.js.map +1 -1
  994. package/dist/core/tools/read.d.ts.map +1 -1
  995. package/dist/core/tools/read.js +14 -13
  996. package/dist/core/tools/read.js.map +1 -1
  997. package/dist/core/tools/render-utils.d.ts +29 -0
  998. package/dist/core/tools/render-utils.d.ts.map +1 -1
  999. package/dist/core/tools/render-utils.js +31 -1
  1000. package/dist/core/tools/render-utils.js.map +1 -1
  1001. package/dist/core/tools/run-process.d.ts +1 -1
  1002. package/dist/core/tools/run-process.d.ts.map +1 -1
  1003. package/dist/core/tools/run-process.js +69 -9
  1004. package/dist/core/tools/run-process.js.map +1 -1
  1005. package/dist/core/tools/run-toolkit-script.d.ts.map +1 -1
  1006. package/dist/core/tools/run-toolkit-script.js.map +1 -1
  1007. package/dist/core/tools/search-command-guard.d.ts +10 -0
  1008. package/dist/core/tools/search-command-guard.d.ts.map +1 -1
  1009. package/dist/core/tools/search-command-guard.js +118 -31
  1010. package/dist/core/tools/search-command-guard.js.map +1 -1
  1011. package/dist/core/tools/search-router.d.ts.map +1 -1
  1012. package/dist/core/tools/search-router.js.map +1 -1
  1013. package/dist/core/tools/search-tool-runtime.d.ts +19 -0
  1014. package/dist/core/tools/search-tool-runtime.d.ts.map +1 -0
  1015. package/dist/core/tools/search-tool-runtime.js +12 -0
  1016. package/dist/core/tools/search-tool-runtime.js.map +1 -0
  1017. package/dist/core/tools/secret-store.d.ts.map +1 -1
  1018. package/dist/core/tools/secret-store.js.map +1 -1
  1019. package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
  1020. package/dist/core/tools/shell-command-parser.js.map +1 -1
  1021. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  1022. package/dist/core/tools/shell-contract-router.js +16 -6
  1023. package/dist/core/tools/shell-contract-router.js.map +1 -1
  1024. package/dist/core/tools/shell-execution-session.d.ts +4 -0
  1025. package/dist/core/tools/shell-execution-session.d.ts.map +1 -0
  1026. package/dist/core/tools/shell-execution-session.js +11 -0
  1027. package/dist/core/tools/shell-execution-session.js.map +1 -0
  1028. package/dist/core/tools/shell-output-projection.d.ts +49 -0
  1029. package/dist/core/tools/shell-output-projection.d.ts.map +1 -0
  1030. package/dist/core/tools/shell-output-projection.js +381 -0
  1031. package/dist/core/tools/shell-output-projection.js.map +1 -0
  1032. package/dist/core/tools/shell-session.d.ts +2 -13
  1033. package/dist/core/tools/shell-session.d.ts.map +1 -1
  1034. package/dist/core/tools/shell-session.js +36 -136
  1035. package/dist/core/tools/shell-session.js.map +1 -1
  1036. package/dist/core/tools/skill-audit.d.ts.map +1 -1
  1037. package/dist/core/tools/skill-audit.js.map +1 -1
  1038. package/dist/core/tools/skillify.d.ts.map +1 -1
  1039. package/dist/core/tools/skillify.js.map +1 -1
  1040. package/dist/core/tools/task-steps.d.ts +8 -8
  1041. package/dist/core/tools/task-steps.d.ts.map +1 -1
  1042. package/dist/core/tools/task-steps.js +17 -18
  1043. package/dist/core/tools/task-steps.js.map +1 -1
  1044. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  1045. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  1046. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  1047. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  1048. package/dist/core/tools/tool-task.d.ts +23 -0
  1049. package/dist/core/tools/tool-task.d.ts.map +1 -0
  1050. package/dist/core/tools/tool-task.js +93 -0
  1051. package/dist/core/tools/tool-task.js.map +1 -0
  1052. package/dist/core/tools/windows-shell-engine.d.ts +17 -11
  1053. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  1054. package/dist/core/tools/windows-shell-engine.js +339 -117
  1055. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  1056. package/dist/core/tools/windows-shell-state.d.ts.map +1 -1
  1057. package/dist/core/tools/windows-shell-state.js.map +1 -1
  1058. package/dist/core/tools/worktree-sync.d.ts.map +1 -1
  1059. package/dist/core/tools/worktree-sync.js +8 -12
  1060. package/dist/core/tools/worktree-sync.js.map +1 -1
  1061. package/dist/core/tools/write.d.ts.map +1 -1
  1062. package/dist/core/tools/write.js +0 -1
  1063. package/dist/core/tools/write.js.map +1 -1
  1064. package/dist/core/trust-manager.d.ts.map +1 -1
  1065. package/dist/core/trust-manager.js +7 -40
  1066. package/dist/core/trust-manager.js.map +1 -1
  1067. package/dist/core/util/atomic-file.d.ts +19 -0
  1068. package/dist/core/util/atomic-file.d.ts.map +1 -1
  1069. package/dist/core/util/atomic-file.js +50 -15
  1070. package/dist/core/util/atomic-file.js.map +1 -1
  1071. package/dist/core/util/bounded-file.d.ts +15 -0
  1072. package/dist/core/util/bounded-file.d.ts.map +1 -0
  1073. package/dist/core/util/bounded-file.js +120 -0
  1074. package/dist/core/util/bounded-file.js.map +1 -0
  1075. package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
  1076. package/dist/core/util/bounded-jsonl.js +112 -9
  1077. package/dist/core/util/bounded-jsonl.js.map +1 -1
  1078. package/dist/core/util/bounded-value.d.ts +3 -0
  1079. package/dist/core/util/bounded-value.d.ts.map +1 -0
  1080. package/dist/core/util/bounded-value.js +12 -0
  1081. package/dist/core/util/bounded-value.js.map +1 -0
  1082. package/dist/core/util/json-size.d.ts +3 -0
  1083. package/dist/core/util/json-size.d.ts.map +1 -0
  1084. package/dist/core/util/json-size.js +95 -0
  1085. package/dist/core/util/json-size.js.map +1 -0
  1086. package/dist/core/util/minimatch-cache.d.ts.map +1 -1
  1087. package/dist/core/util/minimatch-cache.js.map +1 -1
  1088. package/dist/core/util/value-guards.d.ts +2 -0
  1089. package/dist/core/util/value-guards.d.ts.map +1 -1
  1090. package/dist/core/util/value-guards.js +5 -0
  1091. package/dist/core/util/value-guards.js.map +1 -1
  1092. package/dist/core/worktree-sync/codes.d.ts.map +1 -1
  1093. package/dist/core/worktree-sync/git-engine.d.ts.map +1 -1
  1094. package/dist/core/worktree-sync/git-engine.js +20 -36
  1095. package/dist/core/worktree-sync/git-engine.js.map +1 -1
  1096. package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -1
  1097. package/dist/core/worktree-sync/lane-gate.js +1 -4
  1098. package/dist/core/worktree-sync/lane-gate.js.map +1 -1
  1099. package/dist/core/worktree-sync/runtime.d.ts.map +1 -1
  1100. package/dist/core/worktree-sync/runtime.js.map +1 -1
  1101. package/dist/core/worktree-sync/store.d.ts.map +1 -1
  1102. package/dist/core/worktree-sync/store.js.map +1 -1
  1103. package/dist/core/worktree-sync/watcher.d.ts.map +1 -1
  1104. package/dist/core/worktree-sync/watcher.js.map +1 -1
  1105. package/dist/index.d.ts.map +1 -1
  1106. package/dist/index.js.map +1 -1
  1107. package/dist/main.d.ts.map +1 -1
  1108. package/dist/main.js +10 -32
  1109. package/dist/main.js.map +1 -1
  1110. package/dist/migrations.d.ts.map +1 -1
  1111. package/dist/migrations.js +6 -19
  1112. package/dist/migrations.js.map +1 -1
  1113. package/dist/modes/index.d.ts.map +1 -1
  1114. package/dist/modes/interactive/auth-dialogs-controller.d.ts +3 -0
  1115. package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
  1116. package/dist/modes/interactive/auth-dialogs-controller.js +96 -132
  1117. package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
  1118. package/dist/modes/interactive/auto-learn-controller.d.ts +1 -31
  1119. package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
  1120. package/dist/modes/interactive/auto-learn-controller.js +86 -307
  1121. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  1122. package/dist/modes/interactive/autocomplete-provider.d.ts.map +1 -1
  1123. package/dist/modes/interactive/autocomplete-provider.js.map +1 -1
  1124. package/dist/modes/interactive/autonomy-commands.d.ts.map +1 -1
  1125. package/dist/modes/interactive/autonomy-commands.js +2 -8
  1126. package/dist/modes/interactive/autonomy-commands.js.map +1 -1
  1127. package/dist/modes/interactive/clipboard-input.d.ts +5 -1
  1128. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  1129. package/dist/modes/interactive/clipboard-input.js +17 -0
  1130. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  1131. package/dist/modes/interactive/compaction-queue.d.ts.map +1 -1
  1132. package/dist/modes/interactive/compaction-queue.js +13 -18
  1133. package/dist/modes/interactive/compaction-queue.js.map +1 -1
  1134. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
  1135. package/dist/modes/interactive/components/activity-lane.js +6 -10
  1136. package/dist/modes/interactive/components/activity-lane.js.map +1 -1
  1137. package/dist/modes/interactive/components/armin.d.ts +1 -0
  1138. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  1139. package/dist/modes/interactive/components/armin.js +10 -21
  1140. package/dist/modes/interactive/components/armin.js.map +1 -1
  1141. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  1142. package/dist/modes/interactive/components/assistant-message.js +1 -6
  1143. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  1144. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  1145. package/dist/modes/interactive/components/bash-execution.js +4 -9
  1146. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  1147. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  1148. package/dist/modes/interactive/components/bordered-loader.js +0 -3
  1149. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  1150. package/dist/modes/interactive/components/branch-summary-message.d.ts +3 -8
  1151. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  1152. package/dist/modes/interactive/components/branch-summary-message.js +13 -35
  1153. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  1154. package/dist/modes/interactive/components/compaction-summary-message.d.ts +3 -8
  1155. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  1156. package/dist/modes/interactive/components/compaction-summary-message.js +14 -36
  1157. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  1158. package/dist/modes/interactive/components/config-selector.d.ts +1 -0
  1159. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  1160. package/dist/modes/interactive/components/config-selector.js +20 -43
  1161. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  1162. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  1163. package/dist/modes/interactive/components/countdown-timer.js +0 -5
  1164. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  1165. package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
  1166. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  1167. package/dist/modes/interactive/components/custom-editor.js +4 -8
  1168. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  1169. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  1170. package/dist/modes/interactive/components/custom-message.js +1 -6
  1171. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  1172. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  1173. package/dist/modes/interactive/components/daxnuts.js +6 -8
  1174. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  1175. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  1176. package/dist/modes/interactive/components/diff.js.map +1 -1
  1177. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  1178. package/dist/modes/interactive/components/dynamic-border.js +0 -1
  1179. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  1180. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  1181. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  1182. package/dist/modes/interactive/components/expandable-markdown-message.d.ts +21 -0
  1183. package/dist/modes/interactive/components/expandable-markdown-message.d.ts.map +1 -0
  1184. package/dist/modes/interactive/components/expandable-markdown-message.js +48 -0
  1185. package/dist/modes/interactive/components/expandable-markdown-message.js.map +1 -0
  1186. package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -1
  1187. package/dist/modes/interactive/components/expandable-text.js +0 -2
  1188. package/dist/modes/interactive/components/expandable-text.js.map +1 -1
  1189. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  1190. package/dist/modes/interactive/components/extension-editor.js +1 -9
  1191. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  1192. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  1193. package/dist/modes/interactive/components/extension-input.js +2 -8
  1194. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  1195. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  1196. package/dist/modes/interactive/components/extension-selector.js +5 -20
  1197. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  1198. package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
  1199. package/dist/modes/interactive/components/fitness-role-selector.js +0 -1
  1200. package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
  1201. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  1202. package/dist/modes/interactive/components/footer.js +1 -5
  1203. package/dist/modes/interactive/components/footer.js.map +1 -1
  1204. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  1205. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  1206. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  1207. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  1208. package/dist/modes/interactive/components/login-dialog.js +4 -10
  1209. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  1210. package/dist/modes/interactive/components/model-selector.d.ts +2 -2
  1211. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  1212. package/dist/modes/interactive/components/model-selector.js +21 -44
  1213. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  1214. package/dist/modes/interactive/components/model-suggestion-selector.d.ts.map +1 -1
  1215. package/dist/modes/interactive/components/model-suggestion-selector.js +0 -1
  1216. package/dist/modes/interactive/components/model-suggestion-selector.js.map +1 -1
  1217. package/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
  1218. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  1219. package/dist/modes/interactive/components/oauth-selector.js +16 -32
  1220. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  1221. package/dist/modes/interactive/components/profile-resource-editor.d.ts +3 -4
  1222. package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
  1223. package/dist/modes/interactive/components/profile-resource-editor.js +34 -93
  1224. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  1225. package/dist/modes/interactive/components/profile-selector.d.ts.map +1 -1
  1226. package/dist/modes/interactive/components/profile-selector.js +0 -1
  1227. package/dist/modes/interactive/components/profile-selector.js.map +1 -1
  1228. package/dist/modes/interactive/components/scoped-models-selector.d.ts +3 -4
  1229. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  1230. package/dist/modes/interactive/components/scoped-models-selector.js +34 -79
  1231. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  1232. package/dist/modes/interactive/components/selector-list.d.ts +63 -0
  1233. package/dist/modes/interactive/components/selector-list.d.ts.map +1 -0
  1234. package/dist/modes/interactive/components/selector-list.js +186 -0
  1235. package/dist/modes/interactive/components/selector-list.js.map +1 -0
  1236. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  1237. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  1238. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  1239. package/dist/modes/interactive/components/session-selector.js +61 -103
  1240. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  1241. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  1242. package/dist/modes/interactive/components/settings-selector.js +40 -138
  1243. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  1244. package/dist/modes/interactive/components/show-images-selector.d.ts +2 -4
  1245. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  1246. package/dist/modes/interactive/components/show-images-selector.js +9 -28
  1247. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  1248. package/dist/modes/interactive/components/skill-invocation-message.d.ts +3 -8
  1249. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  1250. package/dist/modes/interactive/components/skill-invocation-message.js +12 -40
  1251. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  1252. package/dist/modes/interactive/components/theme-selector.d.ts +2 -5
  1253. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  1254. package/dist/modes/interactive/components/theme-selector.js +11 -37
  1255. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  1256. package/dist/modes/interactive/components/thinking-selector.d.ts +2 -4
  1257. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  1258. package/dist/modes/interactive/components/thinking-selector.js +9 -31
  1259. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  1260. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  1261. package/dist/modes/interactive/components/tool-execution.js +9 -28
  1262. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  1263. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
  1264. package/dist/modes/interactive/components/tool-group.js +2 -3
  1265. package/dist/modes/interactive/components/tool-group.js.map +1 -1
  1266. package/dist/modes/interactive/components/tool-panel-registry.d.ts.map +1 -1
  1267. package/dist/modes/interactive/components/tool-panel-registry.js +5 -3
  1268. package/dist/modes/interactive/components/tool-panel-registry.js.map +1 -1
  1269. package/dist/modes/interactive/components/tool-title.d.ts.map +1 -1
  1270. package/dist/modes/interactive/components/tool-title.js +0 -4
  1271. package/dist/modes/interactive/components/tool-title.js.map +1 -1
  1272. package/dist/modes/interactive/components/transcript-pager.d.ts +26 -0
  1273. package/dist/modes/interactive/components/transcript-pager.d.ts.map +1 -0
  1274. package/dist/modes/interactive/components/transcript-pager.js +81 -0
  1275. package/dist/modes/interactive/components/transcript-pager.js.map +1 -0
  1276. package/dist/modes/interactive/components/tree-selector.d.ts +1 -12
  1277. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  1278. package/dist/modes/interactive/components/tree-selector.js +42 -402
  1279. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  1280. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  1281. package/dist/modes/interactive/components/trust-selector.js +4 -16
  1282. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  1283. package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -1
  1284. package/dist/modes/interactive/components/usage-action-selector.js +2 -10
  1285. package/dist/modes/interactive/components/usage-action-selector.js.map +1 -1
  1286. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  1287. package/dist/modes/interactive/components/user-message-selector.js +3 -6
  1288. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  1289. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  1290. package/dist/modes/interactive/components/user-message.js +0 -1
  1291. package/dist/modes/interactive/components/user-message.js.map +1 -1
  1292. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  1293. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  1294. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  1295. package/dist/modes/interactive/config-backup.js.map +1 -1
  1296. package/dist/modes/interactive/editor-overlay-host.d.ts.map +1 -1
  1297. package/dist/modes/interactive/editor-overlay-host.js +0 -3
  1298. package/dist/modes/interactive/editor-overlay-host.js.map +1 -1
  1299. package/dist/modes/interactive/extension-ui-host.d.ts +2 -0
  1300. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  1301. package/dist/modes/interactive/extension-ui-host.js +51 -72
  1302. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  1303. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  1304. package/dist/modes/interactive/external-editor.js +2 -15
  1305. package/dist/modes/interactive/external-editor.js.map +1 -1
  1306. package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
  1307. package/dist/modes/interactive/history-reload-math.js.map +1 -1
  1308. package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -1
  1309. package/dist/modes/interactive/interactive-event-controller.js +23 -16
  1310. package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
  1311. package/dist/modes/interactive/interactive-mode.d.ts +13 -4
  1312. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  1313. package/dist/modes/interactive/interactive-mode.js +123 -204
  1314. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  1315. package/dist/modes/interactive/interactive-selection-prompts.d.ts +20 -0
  1316. package/dist/modes/interactive/interactive-selection-prompts.d.ts.map +1 -0
  1317. package/dist/modes/interactive/interactive-selection-prompts.js +43 -0
  1318. package/dist/modes/interactive/interactive-selection-prompts.js.map +1 -0
  1319. package/dist/modes/interactive/key-handlers.d.ts +2 -1
  1320. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  1321. package/dist/modes/interactive/key-handlers.js +4 -2
  1322. package/dist/modes/interactive/key-handlers.js.map +1 -1
  1323. package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -1
  1324. package/dist/modes/interactive/loaded-resources-view.js.map +1 -1
  1325. package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
  1326. package/dist/modes/interactive/local-model-commands.js +4 -9
  1327. package/dist/modes/interactive/local-model-commands.js.map +1 -1
  1328. package/dist/modes/interactive/model-fitness-presentation.d.ts +21 -0
  1329. package/dist/modes/interactive/model-fitness-presentation.d.ts.map +1 -0
  1330. package/dist/modes/interactive/model-fitness-presentation.js +13 -0
  1331. package/dist/modes/interactive/model-fitness-presentation.js.map +1 -0
  1332. package/dist/modes/interactive/profile-menu-controller.d.ts +2 -0
  1333. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  1334. package/dist/modes/interactive/profile-menu-controller.js +79 -171
  1335. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  1336. package/dist/modes/interactive/report-commands.d.ts +2 -0
  1337. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  1338. package/dist/modes/interactive/report-commands.js +12 -6
  1339. package/dist/modes/interactive/report-commands.js.map +1 -1
  1340. package/dist/modes/interactive/resource-display.d.ts.map +1 -1
  1341. package/dist/modes/interactive/resource-display.js.map +1 -1
  1342. package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
  1343. package/dist/modes/interactive/resource-shell-commands.js +6 -23
  1344. package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
  1345. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  1346. package/dist/modes/interactive/session-flow-commands.js +21 -25
  1347. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  1348. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  1349. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  1350. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -1
  1351. package/dist/modes/interactive/session-replacement-errors.js.map +1 -1
  1352. package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
  1353. package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
  1354. package/dist/modes/interactive/signal-lifecycle.d.ts.map +1 -1
  1355. package/dist/modes/interactive/signal-lifecycle.js.map +1 -1
  1356. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  1357. package/dist/modes/interactive/startup-checks.js +12 -8
  1358. package/dist/modes/interactive/startup-checks.js.map +1 -1
  1359. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  1360. package/dist/modes/interactive/theme/theme.js +10 -76
  1361. package/dist/modes/interactive/theme/theme.js.map +1 -1
  1362. package/dist/modes/interactive/usage-commands.d.ts.map +1 -1
  1363. package/dist/modes/interactive/usage-commands.js.map +1 -1
  1364. package/dist/modes/print-mode.d.ts.map +1 -1
  1365. package/dist/modes/print-mode.js +5 -22
  1366. package/dist/modes/print-mode.js.map +1 -1
  1367. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  1368. package/dist/modes/rpc/jsonl.js +1 -1
  1369. package/dist/modes/rpc/jsonl.js.map +1 -1
  1370. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  1371. package/dist/modes/rpc/rpc-client.js +7 -8
  1372. package/dist/modes/rpc/rpc-client.js.map +1 -1
  1373. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  1374. package/dist/modes/rpc/rpc-mode.js +5 -20
  1375. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  1376. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  1377. package/dist/modes/rpc/rpc-types.js.map +1 -1
  1378. package/dist/modes/termination-signals.d.ts +4 -0
  1379. package/dist/modes/termination-signals.d.ts.map +1 -0
  1380. package/dist/modes/termination-signals.js +21 -0
  1381. package/dist/modes/termination-signals.js.map +1 -0
  1382. package/dist/package-manager-cli.d.ts.map +1 -1
  1383. package/dist/package-manager-cli.js.map +1 -1
  1384. package/dist/utils/ansi-colors.d.ts +5 -0
  1385. package/dist/utils/ansi-colors.d.ts.map +1 -0
  1386. package/dist/utils/ansi-colors.js +38 -0
  1387. package/dist/utils/ansi-colors.js.map +1 -0
  1388. package/dist/utils/ansi.d.ts.map +1 -1
  1389. package/dist/utils/ansi.js.map +1 -1
  1390. package/dist/utils/changelog.d.ts.map +1 -1
  1391. package/dist/utils/changelog.js.map +1 -1
  1392. package/dist/utils/child-process.d.ts.map +1 -1
  1393. package/dist/utils/child-process.js.map +1 -1
  1394. package/dist/utils/clipboard-image.d.ts.map +1 -1
  1395. package/dist/utils/clipboard-image.js.map +1 -1
  1396. package/dist/utils/clipboard-native.d.ts.map +1 -1
  1397. package/dist/utils/clipboard-native.js.map +1 -1
  1398. package/dist/utils/clipboard.d.ts.map +1 -1
  1399. package/dist/utils/clipboard.js.map +1 -1
  1400. package/dist/utils/deprecation.d.ts.map +1 -1
  1401. package/dist/utils/deprecation.js.map +1 -1
  1402. package/dist/utils/exif-orientation.d.ts.map +1 -1
  1403. package/dist/utils/exif-orientation.js.map +1 -1
  1404. package/dist/utils/external-editor-command.d.ts.map +1 -1
  1405. package/dist/utils/external-editor-command.js.map +1 -1
  1406. package/dist/utils/frontmatter.d.ts.map +1 -1
  1407. package/dist/utils/frontmatter.js.map +1 -1
  1408. package/dist/utils/fs-watch.d.ts.map +1 -1
  1409. package/dist/utils/fs-watch.js.map +1 -1
  1410. package/dist/utils/git.d.ts.map +1 -1
  1411. package/dist/utils/git.js +20 -28
  1412. package/dist/utils/git.js.map +1 -1
  1413. package/dist/utils/highlight-js-languages.d.ts.map +1 -1
  1414. package/dist/utils/html.d.ts.map +1 -1
  1415. package/dist/utils/html.js.map +1 -1
  1416. package/dist/utils/image-convert.d.ts.map +1 -1
  1417. package/dist/utils/image-convert.js.map +1 -1
  1418. package/dist/utils/image-resize-core.d.ts.map +1 -1
  1419. package/dist/utils/image-resize-core.js.map +1 -1
  1420. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  1421. package/dist/utils/image-resize-worker.js.map +1 -1
  1422. package/dist/utils/image-resize.d.ts.map +1 -1
  1423. package/dist/utils/image-resize.js.map +1 -1
  1424. package/dist/utils/json.d.ts.map +1 -1
  1425. package/dist/utils/json.js.map +1 -1
  1426. package/dist/utils/mime.d.ts.map +1 -1
  1427. package/dist/utils/mime.js.map +1 -1
  1428. package/dist/utils/open-browser.d.ts.map +1 -1
  1429. package/dist/utils/open-browser.js.map +1 -1
  1430. package/dist/utils/paths.d.ts.map +1 -1
  1431. package/dist/utils/paths.js.map +1 -1
  1432. package/dist/utils/photon.d.ts.map +1 -1
  1433. package/dist/utils/photon.js.map +1 -1
  1434. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  1435. package/dist/utils/pi-user-agent.js.map +1 -1
  1436. package/dist/utils/platform.d.ts.map +1 -1
  1437. package/dist/utils/platform.js.map +1 -1
  1438. package/dist/utils/process-memory.d.ts.map +1 -1
  1439. package/dist/utils/process-memory.js.map +1 -1
  1440. package/dist/utils/safe-write-stream.d.ts.map +1 -1
  1441. package/dist/utils/safe-write-stream.js.map +1 -1
  1442. package/dist/utils/shell.d.ts.map +1 -1
  1443. package/dist/utils/shell.js.map +1 -1
  1444. package/dist/utils/sleep.d.ts.map +1 -1
  1445. package/dist/utils/sleep.js +2 -15
  1446. package/dist/utils/sleep.js.map +1 -1
  1447. package/dist/utils/stdin-events.d.ts +8 -0
  1448. package/dist/utils/stdin-events.d.ts.map +1 -0
  1449. package/dist/utils/stdin-events.js +19 -0
  1450. package/dist/utils/stdin-events.js.map +1 -0
  1451. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  1452. package/dist/utils/syntax-highlight.js +20 -13
  1453. package/dist/utils/syntax-highlight.js.map +1 -1
  1454. package/dist/utils/tools-manager.d.ts.map +1 -1
  1455. package/dist/utils/tools-manager.js.map +1 -1
  1456. package/dist/utils/version-check.d.ts.map +1 -1
  1457. package/dist/utils/version-check.js.map +1 -1
  1458. package/dist/utils/windows-self-update.d.ts.map +1 -1
  1459. package/dist/utils/windows-self-update.js.map +1 -1
  1460. package/dist/utils/work-directory.d.ts.map +1 -1
  1461. package/dist/utils/work-directory.js.map +1 -1
  1462. package/docs/compaction.md +11 -3
  1463. package/docs/sessions.md +6 -0
  1464. package/docs/settings.md +1 -1
  1465. package/docs/tool-repair.md +3 -0
  1466. package/docs/windows.md +29 -2
  1467. package/docs/work-directory.md +9 -1
  1468. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  1469. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  1470. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  1471. package/examples/extensions/sandbox/package-lock.json +2 -2
  1472. package/examples/extensions/sandbox/package.json +1 -1
  1473. package/examples/extensions/with-deps/package-lock.json +2 -2
  1474. package/examples/extensions/with-deps/package.json +1 -1
  1475. package/npm-shrinkwrap.json +16 -16
  1476. package/package.json +10 -10
  1477. package/dist/utils/streaming-lines.d.ts +0 -20
  1478. package/dist/utils/streaming-lines.d.ts.map +0 -1
  1479. package/dist/utils/streaming-lines.js +0 -79
  1480. package/dist/utils/streaming-lines.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tool-selection-controller.js","sourceRoot":"","sources":["../../../src/core/tool-selection/tool-selection-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,qBAAqB,GAGrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAA0B,MAAM,gBAAgB,CAAC;AAwD/E,MAAM,cAAc,GAAwC;IAC3D,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,UAAU;IACV,SAAS;IACT,OAAO;CACP,CAAC;AAEF,MAAM,YAAY,GAAwD;IACz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,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,aAAa,GAClB,KAAK,CAAC,aAAa,KAAK,SAAS;YAChC,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,GAAG,GAAG,CAAC,QAAQ,KAAK,CAAC,WAAW,GAAG,CAAC;QACzE,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,QAAQ,MAAM,KAAK,CAAC,WAAW,eAAe,aAAa,EAAE,CAAC,CAAC;QACrF,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,MAAM,iBAAiB,GACtB,KAAK,CAAC,iBAAiB,KAAK,SAAS;gBACpC,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,iBAAiB,GAAG,GAAG,CAAC,QAAQ,KAAK,CAAC,eAAe,GAAG,CAAC;YACjF,KAAK,CAAC,IAAI,CAAC,6BAA6B,KAAK,CAAC,QAAQ,iCAA+B,iBAAiB,EAAE,CAAC,CAAC;QAC3G,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACxB;AAED,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import {\n\tdecideExpectedUtility,\n\ttype ExpectedUtilityCandidate,\n\ttype ToolSelectionDecision,\n} from \"./expected-utility.ts\";\nimport { evaluateToolPromotion, type ToolSelectionHint } from \"./promotion.ts\";\nimport type {\n\tToolExecutionObservation,\n\tToolPerformanceKey,\n\tToolPerformanceStore,\n\tToolSelectionIntentClass,\n\tToolSelectionObservation,\n} from \"./tool-performance-store.ts\";\n\nexport interface ToolSelectionTool {\n\tname: string;\n\tdescription?: string;\n\tparameters?: unknown;\n\tprofileAllowed?: boolean;\n\tcapabilityAllowed?: boolean;\n\tpathValidated?: boolean;\n\triskCost?: number;\n\tcontextCost?: number;\n}\n\nexport interface ToolSelectionControllerDeps {\n\tstore: ToolPerformanceStore;\n\tgetModelRef: () => string;\n\tgetActiveTools: () => readonly ToolSelectionTool[];\n\tisCandidateAllowed?: (toolName: string) => boolean;\n\t/**\n\t * Env-var source for the kill switches, injected for hermetic testing; defaults to\n\t * `process.env`. `PI_TOOL_SELECTION_OBSERVE=0` disables recording (the observe/stats layer,\n\t * default ON); `PI_TOOL_SELECTION_HINTS=0` disables surfacing the evidence-gated prompt hint\n\t * (default ON, but the hint itself only ever activates once evidence thresholds are met).\n\t */\n\tenv?: Record<string, string | undefined>;\n}\n\nexport interface ToolSelectionPendingObservation {\n\tid: string;\n\tkey: ToolPerformanceKey;\n\tfirstTool: boolean;\n\tstartedAt: number;\n\tinputTokenEstimate?: number;\n\tselection: Omit<ToolSelectionObservation, \"at\" | \"modelRef\" | \"intentClass\" | \"actualTool\" | \"succeeded\">;\n\t/** Was a promotion hint already active for this (model,intent) bucket before this call? */\n\thintActiveAtCallTime: boolean;\n}\n\n/** Report row for the observe/agreement/promotion loop — see {@link ToolSelectionController.getReport}. */\nexport interface ToolSelectionReportEntry {\n\tmodelRef: string;\n\tintentClass: ToolSelectionIntentClass;\n\tsampleCount: number;\n\tagreementRate?: number;\n\thintTool?: string;\n\thintSampleCount: number;\n\thintAgreementRate?: number;\n}\n\nconst INTENT_CLASSES: readonly ToolSelectionIntentClass[] = [\n\t\"read\",\n\t\"search\",\n\t\"execute\",\n\t\"write\",\n\t\"retrieve\",\n\t\"explain\",\n\t\"other\",\n];\n\nconst INTENT_WORDS: Record<ToolSelectionIntentClass, readonly string[]> = {\n\tread: [\"read\", \"cat\", \"ls\", \"list\", \"stat\", \"head\", \"tail\"],\n\tsearch: [\"search\", \"grep\", \"find\", \"glob\", \"ripgrep\", \"query\"],\n\texecute: [\"bash\", \"python\", \"powershell\", \"shell\", \"exec\", \"run\", \"process\", \"command\", \"script\"],\n\twrite: [\"write\", \"edit\", \"patch\", \"apply\", \"delete\", \"mkdir\", \"move\", \"rename\"],\n\tretrieve: [\"retrieve\", \"artifact\", \"recall\", \"memory\", \"fetch\", \"download\"],\n\texplain: [\"explain\", \"help\", \"describe\", \"inspect\", \"context\"],\n\tother: [],\n};\n\nfunction tokenize(value: string): string[] {\n\treturn value\n\t\t.toLowerCase()\n\t\t.split(/[^a-z0-9]+/u)\n\t\t.filter(Boolean);\n}\n\nfunction classifyToolIntent(tool: ToolSelectionTool): ToolSelectionIntentClass {\n\tconst tokens = tokenize(`${tool.name} ${tool.description ?? \"\"}`);\n\tlet best: ToolSelectionIntentClass = \"other\";\n\tlet bestScore = 0;\n\tfor (const intent of INTENT_CLASSES) {\n\t\tif (intent === \"other\") continue;\n\t\tconst score = INTENT_WORDS[intent].reduce((total, word) => total + (tokens.includes(word) ? 1 : 0), 0);\n\t\tif (score > bestScore) {\n\t\t\tbest = intent;\n\t\t\tbestScore = score;\n\t\t}\n\t}\n\treturn best;\n}\n\nfunction intentValue(intent: ToolSelectionIntentClass, toolIntent: ToolSelectionIntentClass): number {\n\tif (toolIntent === intent) return 0.85;\n\tif (intent === \"other\") return 0.35;\n\tif (toolIntent === \"other\") return 0.2;\n\treturn 0.12;\n}\n\nfunction noToolValue(intent: ToolSelectionIntentClass): number {\n\tswitch (intent) {\n\t\tcase \"explain\":\n\t\t\treturn 0.35;\n\t\tcase \"read\":\n\t\tcase \"search\":\n\t\tcase \"retrieve\":\n\t\t\treturn 0.12;\n\t\tcase \"write\":\n\t\tcase \"execute\":\n\t\t\treturn 0.05;\n\t\tdefault:\n\t\t\treturn 0.2;\n\t}\n}\n\nfunction estimateTokens(value: unknown): number | undefined {\n\ttry {\n\t\tconst serialized = typeof value === \"string\" ? value : JSON.stringify(value);\n\t\tif (!serialized) return undefined;\n\t\treturn Math.max(1, Math.ceil(serialized.length / 4));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction estimateContentTokens(content: readonly unknown[]): number | undefined {\n\tconst text = content\n\t\t.map((block) => {\n\t\t\tif (!block || typeof block !== \"object\") return \"\";\n\t\t\tconst candidate = block as { type?: unknown; text?: unknown };\n\t\t\treturn candidate.type === \"text\" && typeof candidate.text === \"string\" ? candidate.text : \"\";\n\t\t})\n\t\t.join(\"\\n\");\n\treturn estimateTokens(text);\n}\n\nfunction modelToolKey(modelRef: string, intentClass: ToolSelectionIntentClass, tool: string): ToolPerformanceKey {\n\treturn { modelRef, intentClass, tool };\n}\n\nfunction candidateFor(\n\tstore: ToolPerformanceStore,\n\tmodelRef: string,\n\tintentClass: ToolSelectionIntentClass,\n\ttool: ToolSelectionTool,\n\tactualTool: string,\n): ExpectedUtilityCandidate {\n\tconst key = modelToolKey(modelRef, intentClass, tool.name);\n\tconst stats = store.get(key);\n\treturn {\n\t\ttool: tool.name,\n\t\tvalue: intentValue(intentClass, classifyToolIntent(tool)),\n\t\talpha: stats.alpha,\n\t\tbeta: stats.beta,\n\t\tsampleCount: stats.sampleCount,\n\t\tlatencyMs: stats.latencyEwmaMs,\n\t\ttokenEstimate:\n\t\t\tstats.inputTokenEstimateEwma === undefined && stats.outputTokenEstimateEwma === undefined\n\t\t\t\t? undefined\n\t\t\t\t: (stats.inputTokenEstimateEwma ?? 0) + (stats.outputTokenEstimateEwma ?? 0),\n\t\triskCost: tool.riskCost,\n\t\tcontextCost: tool.contextCost,\n\t\tdeterministicMatch: tool.name === actualTool && tool.pathValidated !== false,\n\t\tautomaticEligible: tool.pathValidated !== false,\n\t};\n}\n\nexport class ToolSelectionController {\n\tprivate readonly deps: ToolSelectionControllerDeps;\n\tprivate readonly pending = new Map<string, ToolSelectionPendingObservation>();\n\tprivate firstToolInTurn = true;\n\t/** Kill switch: observe/stats recording, default ON. `PI_TOOL_SELECTION_OBSERVE=0` disables it. */\n\tprivate readonly observeEnabled: boolean;\n\n\tconstructor(deps: ToolSelectionControllerDeps) {\n\t\tthis.deps = deps;\n\t\tthis.observeEnabled = (deps.env ?? process.env).PI_TOOL_SELECTION_OBSERVE !== \"0\";\n\t}\n\n\tstartTurn(): void {\n\t\tthis.firstToolInTurn = true;\n\t}\n\n\tbegin(toolCallId: string, toolName: string, args: unknown): ToolSelectionPendingObservation {\n\t\tconst modelRef = this.deps.getModelRef();\n\t\tconst activeTools = this.deps\n\t\t\t.getActiveTools()\n\t\t\t.filter(\n\t\t\t\t(tool) =>\n\t\t\t\t\ttool.profileAllowed !== false &&\n\t\t\t\t\ttool.capabilityAllowed !== false &&\n\t\t\t\t\t(this.deps.isCandidateAllowed?.(tool.name) ?? true),\n\t\t\t);\n\t\tconst actualTool = activeTools.find((tool) => tool.name === toolName) ?? {\n\t\t\tname: toolName,\n\t\t\tpathValidated: true,\n\t\t};\n\t\tconst intentClass = classifyToolIntent(actualTool);\n\t\tconst candidates = activeTools.map((tool) =>\n\t\t\tcandidateFor(\n\t\t\t\tthis.deps.store,\n\t\t\t\tmodelRef,\n\t\t\t\tintentClass,\n\t\t\t\ttool.name === toolName ? tool : { ...tool, pathValidated: false },\n\t\t\t\ttoolName,\n\t\t\t),\n\t\t);\n\t\tif (!candidates.some((candidate) => candidate.tool === toolName)) {\n\t\t\tcandidates.push(candidateFor(this.deps.store, modelRef, intentClass, actualTool, toolName));\n\t\t}\n\t\tcandidates.push({\n\t\t\ttool: \"no_tool\",\n\t\t\tvalue: noToolValue(intentClass),\n\t\t\talpha: 1,\n\t\t\tbeta: 1,\n\t\t\tsampleCount: 0,\n\t\t\tsuccessProbability: 1,\n\t\t\tlatencyMs: 0,\n\t\t\ttokenEstimate: 0,\n\t\t\triskCost: 0,\n\t\t\tcontextCost: 0,\n\t\t});\n\t\tconst decision = decideExpectedUtility(candidates);\n\t\tconst firstTool = this.firstToolInTurn;\n\t\tconst selection = this.selectionSnapshot(decision, firstTool);\n\t\t// Evaluated BEFORE this call is recorded, so it reflects evidence up to (not including) this\n\t\t// observation — captured now because complete() (later, async) can no longer distinguish\n\t\t// \"before\" from \"after\" once the store has been written.\n\t\tconst hintActiveAtCallTime = this.observeEnabled\n\t\t\t? this.evaluatePromotion(modelRef, intentClass).tool !== undefined\n\t\t\t: false;\n\t\tconst pending: ToolSelectionPendingObservation = {\n\t\t\tid: toolCallId,\n\t\t\tkey: modelToolKey(modelRef, intentClass, toolName),\n\t\t\tfirstTool: this.firstToolInTurn,\n\t\t\tstartedAt: Date.now(),\n\t\t\tinputTokenEstimate: estimateTokens(args),\n\t\t\tselection,\n\t\t\thintActiveAtCallTime,\n\t\t};\n\t\tthis.firstToolInTurn = false;\n\t\tthis.pending.set(toolCallId, pending);\n\t\treturn pending;\n\t}\n\n\tcomplete(toolCallId: string, succeeded: boolean, content: readonly unknown[] = []): void {\n\t\tconst pending = this.pending.get(toolCallId);\n\t\tif (!pending) return;\n\t\tthis.pending.delete(toolCallId);\n\t\tif (!this.observeEnabled) return;\n\t\tconst execution: ToolExecutionObservation = {\n\t\t\tkey: pending.key,\n\t\t\tsuccess: succeeded,\n\t\t\tlatencyMs: Math.max(0, Date.now() - pending.startedAt),\n\t\t\tinputTokenEstimate: pending.inputTokenEstimate,\n\t\t\toutputTokenEstimate: estimateContentTokens(content),\n\t\t\tselection: pending.selection,\n\t\t\thintActiveAtCallTime: pending.hintActiveAtCallTime,\n\t\t};\n\t\tthis.deps.store.recordExecution(execution);\n\t}\n\n\trecordValidation(toolName: string, outcome: \"repaired\" | \"bounced\"): void {\n\t\tif (!this.observeEnabled) return;\n\t\tconst modelRef = this.deps.getModelRef();\n\t\tconst tool = this.deps.getActiveTools().find((candidate) => candidate.name === toolName) ?? { name: toolName };\n\t\tthis.deps.store.recordValidation(modelToolKey(modelRef, classifyToolIntent(tool), toolName), outcome);\n\t}\n\n\t/**\n\t * Evidence-gated promotion for one (model,intent) bucket — see promotion.ts. Pure read, no\n\t * mutation; used both to stamp `hintActiveAtCallTime` and to build the live hint list below.\n\t */\n\tprivate evaluatePromotion(modelRef: string, intentClass: ToolSelectionIntentClass) {\n\t\treturn evaluateToolPromotion(this.deps.store.getStatsForIntent(modelRef, intentClass));\n\t}\n\n\t/**\n\t * The currently active evidence-gated hints for the session's current model — one per\n\t * (intentClass) at most, only where accumulated evidence clears the promotion gate. Consumed by\n\t * `system-prompt-builder.ts` to render a compact, cache-stable prompt block. Empty when the\n\t * hint kill switch (`PI_TOOL_SELECTION_HINTS=0`) is set, observing is disabled, or no bucket has\n\t * cleared the gate yet.\n\t */\n\tgetActiveHints(modelRef: string = this.deps.getModelRef()): ToolSelectionHint[] {\n\t\tif ((this.deps.env ?? process.env).PI_TOOL_SELECTION_HINTS === \"0\") return [];\n\t\tif (!this.observeEnabled) return [];\n\t\tconst hints: ToolSelectionHint[] = [];\n\t\tfor (const intentClass of INTENT_CLASSES) {\n\t\t\tconst promotion = this.evaluatePromotion(modelRef, intentClass);\n\t\t\tif (!promotion.tool) continue;\n\t\t\thints.push({\n\t\t\t\tmodelRef,\n\t\t\t\tintentClass,\n\t\t\t\ttool: promotion.tool,\n\t\t\t\tsampleCount: promotion.sampleCount,\n\t\t\t\tmargin: promotion.margin,\n\t\t\t\tentropy: promotion.entropy,\n\t\t\t});\n\t\t}\n\t\treturn hints;\n\t}\n\n\t/**\n\t * Report surface for the observe/agreement/promotion loop: per (model,intent), the durable\n\t * agreement rate (did the raw ranking's top pick match what was actually called), plus the\n\t * currently active hint (if any) and its own efficacy (agreement rate while it has been active).\n\t * A read-only diagnostic — never used to gate behavior. Render with\n\t * {@link formatToolSelectionReport}.\n\t */\n\tgetReport(modelRef: string = this.deps.getModelRef()): ToolSelectionReportEntry[] {\n\t\tconst activeHints = new Map(this.getActiveHints(modelRef).map((hint) => [hint.intentClass, hint]));\n\t\treturn this.deps.store\n\t\t\t.getAllIntentAgreements(modelRef)\n\t\t\t.filter((agreement) => agreement.sampleCount > 0)\n\t\t\t.map((agreement) => ({\n\t\t\t\tmodelRef: agreement.modelRef,\n\t\t\t\tintentClass: agreement.intentClass,\n\t\t\t\tsampleCount: agreement.sampleCount,\n\t\t\t\tagreementRate: agreement.agreementCount / agreement.sampleCount,\n\t\t\t\thintTool: activeHints.get(agreement.intentClass)?.tool,\n\t\t\t\thintSampleCount: agreement.hintActiveSampleCount,\n\t\t\t\thintAgreementRate:\n\t\t\t\t\tagreement.hintActiveSampleCount > 0\n\t\t\t\t\t\t? agreement.hintActiveAgreementCount / agreement.hintActiveSampleCount\n\t\t\t\t\t\t: undefined,\n\t\t\t}));\n\t}\n\n\tprivate selectionSnapshot(\n\t\tdecision: ToolSelectionDecision,\n\t\tfirstTool: boolean,\n\t): ToolSelectionPendingObservation[\"selection\"] {\n\t\treturn {\n\t\t\tfirstTool,\n\t\t\tdisposition: decision.disposition,\n\t\t\trecommendation: decision.recommendation,\n\t\t\tshortlist: decision.shortlist,\n\t\t\tentropy: decision.entropy,\n\t\t\tmargin: decision.margin,\n\t\t\tranked: decision.ranked.map((candidate) => ({\n\t\t\t\ttool: candidate.tool,\n\t\t\t\tutility: candidate.utility,\n\t\t\t\tprobability: candidate.probability,\n\t\t\t})),\n\t\t};\n\t}\n}\n\n/** Renders {@link ToolSelectionController.getReport} rows into the /toolhealth-style diagnostic text. */\nexport function formatToolSelectionReport(entries: readonly ToolSelectionReportEntry[]): string {\n\tif (entries.length === 0) {\n\t\treturn \"Tool-selection loop: no observations recorded yet for this host.\";\n\t}\n\tconst sorted = [...entries].sort(\n\t\t(left, right) => left.modelRef.localeCompare(right.modelRef) || left.intentClass.localeCompare(right.intentClass),\n\t);\n\tconst lines = [\"Tool-selection loop (observe -> agreement -> evidence-gated hint)\"];\n\tfor (const entry of sorted) {\n\t\tconst agreementText =\n\t\t\tentry.agreementRate === undefined\n\t\t\t\t? \"n/a\"\n\t\t\t\t: `${Math.round(entry.agreementRate * 100)}% (n=${entry.sampleCount})`;\n\t\tlines.push(` ${entry.modelRef} / ${entry.intentClass}: agreement ${agreementText}`);\n\t\tif (entry.hintTool) {\n\t\t\tconst hintAgreementText =\n\t\t\t\tentry.hintAgreementRate === undefined\n\t\t\t\t\t? \"n/a\"\n\t\t\t\t\t: `${Math.round(entry.hintAgreementRate * 100)}% (n=${entry.hintSampleCount})`;\n\t\t\tlines.push(` hint active: prefer \\`${entry.hintTool}\\` — agreement while active ${hintAgreementText}`);\n\t\t}\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport { classifyToolIntent, estimateContentTokens, estimateTokens };\n"]}
1
+ {"version":3,"file":"tool-selection-controller.js","sourceRoot":"","sources":["../../../src/core/tool-selection/tool-selection-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACN,qBAAqB,GAGrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAA0B,MAAM,gBAAgB,CAAC;AAS/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAiD1D,MAAM,cAAc,GAAwC;IAC3D,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,UAAU;IACV,SAAS;IACT,OAAO;CACP,CAAC;AAEF,MAAM,YAAY,GAAwD;IACzE,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAC3D,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC;IAC9D,OAAO,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;IACjG,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;IAC/E,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC;IAC3E,OAAO,EAAE,CAAC,SAAS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CAAC,QAAQ,+BAA+B,iBAAiB,EAAE,CAAC,CAAC;QAC3G,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport {\n\tdecideExpectedUtility,\n\ttype ExpectedUtilityCandidate,\n\ttype ToolSelectionDecision,\n} from \"./expected-utility.ts\";\nimport { evaluateToolPromotion, type ToolSelectionHint } from \"./promotion.ts\";\nimport type {\n\tToolExecutionObservation,\n\tToolPerformanceKey,\n\tToolPerformanceStats,\n\tToolPerformanceStore,\n\tToolSelectionIntentClass,\n\tToolSelectionObservation,\n} from \"./tool-performance-store.ts\";\nimport { ToolPhaseTimings } from \"./tool-phase-timing.ts\";\n\nexport interface ToolSelectionTool {\n\tname: string;\n\tdescription?: string;\n\tparameters?: unknown;\n\tprofileAllowed?: boolean;\n\tcapabilityAllowed?: boolean;\n\tpathValidated?: boolean;\n\triskCost?: number;\n\tcontextCost?: number;\n}\n\nexport interface ToolSelectionControllerDeps {\n\tstore: ToolPerformanceStore;\n\tgetModelRef: () => string;\n\tgetActiveTools: () => readonly ToolSelectionTool[];\n\tisCandidateAllowed?: (toolName: string) => boolean;\n\t/**\n\t * Env-var source for the kill switches, injected for hermetic testing; defaults to\n\t * `process.env`. `PI_TOOL_SELECTION_OBSERVE=0` disables recording (the observe/stats layer,\n\t * default ON); `PI_TOOL_SELECTION_HINTS=0` disables surfacing the evidence-gated prompt hint\n\t * (default ON, but the hint itself only ever activates once evidence thresholds are met).\n\t */\n\tenv?: Record<string, string | undefined>;\n}\n\nexport interface ToolSelectionPendingObservation {\n\tid: string;\n\tkey: ToolPerformanceKey;\n\tfirstTool: boolean;\n\tstartedAt: number;\n\tinputTokenEstimate?: number;\n\tselection: Omit<ToolSelectionObservation, \"at\" | \"modelRef\" | \"intentClass\" | \"actualTool\" | \"succeeded\">;\n\t/** Was a promotion hint already active for this (model,intent) bucket before this call? */\n\thintActiveAtCallTime: boolean;\n}\n\n/** Report row for the observe/agreement/promotion loop — see {@link ToolSelectionController.getReport}. */\nexport interface ToolSelectionReportEntry {\n\tmodelRef: string;\n\tintentClass: ToolSelectionIntentClass;\n\tsampleCount: number;\n\tagreementRate?: number;\n\thintTool?: string;\n\thintSampleCount: number;\n\thintAgreementRate?: number;\n}\n\nconst INTENT_CLASSES: readonly ToolSelectionIntentClass[] = [\n\t\"read\",\n\t\"search\",\n\t\"execute\",\n\t\"write\",\n\t\"retrieve\",\n\t\"explain\",\n\t\"other\",\n];\n\nconst INTENT_WORDS: Record<ToolSelectionIntentClass, readonly string[]> = {\n\tread: [\"read\", \"cat\", \"ls\", \"list\", \"stat\", \"head\", \"tail\"],\n\tsearch: [\"search\", \"grep\", \"find\", \"glob\", \"ripgrep\", \"query\"],\n\texecute: [\"bash\", \"python\", \"powershell\", \"shell\", \"exec\", \"run\", \"process\", \"command\", \"script\"],\n\twrite: [\"write\", \"edit\", \"patch\", \"apply\", \"delete\", \"mkdir\", \"move\", \"rename\"],\n\tretrieve: [\"retrieve\", \"artifact\", \"recall\", \"memory\", \"fetch\", \"download\"],\n\texplain: [\"explain\", \"help\", \"describe\", \"inspect\", \"context\"],\n\tother: [],\n};\n\nfunction tokenize(value: string): string[] {\n\treturn value\n\t\t.toLowerCase()\n\t\t.split(/[^a-z0-9]+/u)\n\t\t.filter(Boolean);\n}\n\nfunction classifyToolIntent(tool: ToolSelectionTool): ToolSelectionIntentClass {\n\tconst tokens = tokenize(`${tool.name} ${tool.description ?? \"\"}`);\n\tlet best: ToolSelectionIntentClass = \"other\";\n\tlet bestScore = 0;\n\tfor (const intent of INTENT_CLASSES) {\n\t\tif (intent === \"other\") continue;\n\t\tconst score = INTENT_WORDS[intent].reduce((total, word) => total + (tokens.includes(word) ? 1 : 0), 0);\n\t\tif (score > bestScore) {\n\t\t\tbest = intent;\n\t\t\tbestScore = score;\n\t\t}\n\t}\n\treturn best;\n}\n\nfunction intentValue(intent: ToolSelectionIntentClass, toolIntent: ToolSelectionIntentClass): number {\n\tif (toolIntent === intent) return 0.85;\n\tif (intent === \"other\") return 0.35;\n\tif (toolIntent === \"other\") return 0.2;\n\treturn 0.12;\n}\n\nfunction noToolValue(intent: ToolSelectionIntentClass): number {\n\tswitch (intent) {\n\t\tcase \"explain\":\n\t\t\treturn 0.35;\n\t\tcase \"read\":\n\t\tcase \"search\":\n\t\tcase \"retrieve\":\n\t\t\treturn 0.12;\n\t\tcase \"write\":\n\t\tcase \"execute\":\n\t\t\treturn 0.05;\n\t\tdefault:\n\t\t\treturn 0.2;\n\t}\n}\n\nfunction estimateTokens(value: unknown): number | undefined {\n\ttry {\n\t\tconst serialized = typeof value === \"string\" ? value : JSON.stringify(value);\n\t\tif (!serialized) return undefined;\n\t\treturn Math.max(1, Math.ceil(serialized.length / 4));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction estimateContentTokens(content: readonly unknown[]): number | undefined {\n\tconst text = content\n\t\t.map((block) => {\n\t\t\tif (!block || typeof block !== \"object\") return \"\";\n\t\t\tconst candidate = block as { type?: unknown; text?: unknown };\n\t\t\treturn candidate.type === \"text\" && typeof candidate.text === \"string\" ? candidate.text : \"\";\n\t\t})\n\t\t.join(\"\\n\");\n\treturn estimateTokens(text);\n}\n\nfunction modelToolKey(modelRef: string, intentClass: ToolSelectionIntentClass, tool: string): ToolPerformanceKey {\n\treturn { modelRef, intentClass, tool };\n}\n\nfunction candidateFor(\n\tintentClass: ToolSelectionIntentClass,\n\ttool: ToolSelectionTool,\n\tactualTool: string,\n\tstats?: ToolPerformanceStats,\n): ExpectedUtilityCandidate {\n\treturn {\n\t\ttool: tool.name,\n\t\tvalue: intentValue(intentClass, classifyToolIntent(tool)),\n\t\talpha: stats?.alpha ?? 1,\n\t\tbeta: stats?.beta ?? 1,\n\t\tsampleCount: stats?.sampleCount ?? 0,\n\t\tlatencyMs: stats?.latencyEwmaMs,\n\t\ttokenEstimate:\n\t\t\tstats?.inputTokenEstimateEwma === undefined && stats?.outputTokenEstimateEwma === undefined\n\t\t\t\t? undefined\n\t\t\t\t: (stats.inputTokenEstimateEwma ?? 0) + (stats.outputTokenEstimateEwma ?? 0),\n\t\triskCost: tool.riskCost,\n\t\tcontextCost: tool.contextCost,\n\t\tdeterministicMatch: tool.name === actualTool && tool.pathValidated !== false,\n\t\tautomaticEligible: tool.pathValidated !== false,\n\t};\n}\n\nexport class ToolSelectionController {\n\tprivate readonly deps: ToolSelectionControllerDeps;\n\tprivate readonly pending = new Map<string, ToolSelectionPendingObservation>();\n\tprivate readonly timings = new ToolPhaseTimings();\n\tprivate firstToolInTurn = true;\n\t/** Kill switch: observe/stats recording, default ON. `PI_TOOL_SELECTION_OBSERVE=0` disables it. */\n\tprivate readonly observeEnabled: boolean;\n\n\tconstructor(deps: ToolSelectionControllerDeps) {\n\t\tthis.deps = deps;\n\t\tthis.observeEnabled = (deps.env ?? process.env).PI_TOOL_SELECTION_OBSERVE !== \"0\";\n\t}\n\n\tstartTurn(): void {\n\t\tthis.firstToolInTurn = true;\n\t}\n\n\tbegin(toolCallId: string, toolName: string, args: unknown): ToolSelectionPendingObservation {\n\t\tconst selectionStartedAt = performance.now();\n\t\tconst modelRef = this.deps.getModelRef();\n\t\tconst activeTools = this.deps\n\t\t\t.getActiveTools()\n\t\t\t.filter(\n\t\t\t\t(tool) =>\n\t\t\t\t\ttool.profileAllowed !== false &&\n\t\t\t\t\ttool.capabilityAllowed !== false &&\n\t\t\t\t\t(this.deps.isCandidateAllowed?.(tool.name) ?? true),\n\t\t\t);\n\t\tconst actualTool = activeTools.find((tool) => tool.name === toolName) ?? {\n\t\t\tname: toolName,\n\t\t\tpathValidated: true,\n\t\t};\n\t\tconst intentClass = classifyToolIntent(actualTool);\n\t\tconst intentStats = this.deps.store.getStatsForIntent(modelRef, intentClass);\n\t\tconst statsByTool = new Map(intentStats.map((stats) => [stats.tool, stats]));\n\t\tconst candidates = activeTools.map((tool) =>\n\t\t\tcandidateFor(\n\t\t\t\tintentClass,\n\t\t\t\ttool.name === toolName ? tool : { ...tool, pathValidated: false },\n\t\t\t\ttoolName,\n\t\t\t\tstatsByTool.get(tool.name),\n\t\t\t),\n\t\t);\n\t\tif (!candidates.some((candidate) => candidate.tool === toolName)) {\n\t\t\tcandidates.push(candidateFor(intentClass, actualTool, toolName, statsByTool.get(toolName)));\n\t\t}\n\t\tcandidates.push({\n\t\t\ttool: \"no_tool\",\n\t\t\tvalue: noToolValue(intentClass),\n\t\t\talpha: 1,\n\t\t\tbeta: 1,\n\t\t\tsampleCount: 0,\n\t\t\tsuccessProbability: 1,\n\t\t\tlatencyMs: 0,\n\t\t\ttokenEstimate: 0,\n\t\t\triskCost: 0,\n\t\t\tcontextCost: 0,\n\t\t});\n\t\tconst decision = decideExpectedUtility(candidates);\n\t\tconst firstTool = this.firstToolInTurn;\n\t\tconst selection = this.selectionSnapshot(decision, firstTool);\n\t\t// Evaluated BEFORE this call is recorded, so it reflects evidence up to (not including) this\n\t\t// observation — captured now because complete() (later, async) can no longer distinguish\n\t\t// \"before\" from \"after\" once the store has been written.\n\t\tconst hintActiveAtCallTime = this.observeEnabled ? evaluateToolPromotion(intentStats).tool !== undefined : false;\n\t\tconst selectionCompletedAt = performance.now();\n\t\tthis.timings.record(\"selection\", selectionCompletedAt - selectionStartedAt);\n\t\tconst pending: ToolSelectionPendingObservation = {\n\t\t\tid: toolCallId,\n\t\t\tkey: modelToolKey(modelRef, intentClass, toolName),\n\t\t\tfirstTool: this.firstToolInTurn,\n\t\t\tstartedAt: selectionCompletedAt,\n\t\t\tinputTokenEstimate: estimateTokens(args),\n\t\t\tselection,\n\t\t\thintActiveAtCallTime,\n\t\t};\n\t\tthis.firstToolInTurn = false;\n\t\tthis.pending.set(toolCallId, pending);\n\t\treturn pending;\n\t}\n\n\tcomplete(toolCallId: string, succeeded: boolean, content: readonly unknown[] = []): void {\n\t\tconst pending = this.pending.get(toolCallId);\n\t\tif (!pending) return;\n\t\tthis.pending.delete(toolCallId);\n\t\tconst completedAt = performance.now();\n\t\tconst latencyMs = Math.max(0, completedAt - pending.startedAt);\n\t\tthis.timings.record(\"execution\", latencyMs);\n\t\tif (!this.observeEnabled) return;\n\t\tconst execution: ToolExecutionObservation = {\n\t\t\tkey: pending.key,\n\t\t\tsuccess: succeeded,\n\t\t\tlatencyMs,\n\t\t\tinputTokenEstimate: pending.inputTokenEstimate,\n\t\t\toutputTokenEstimate: estimateContentTokens(content),\n\t\t\tselection: pending.selection,\n\t\t\thintActiveAtCallTime: pending.hintActiveAtCallTime,\n\t\t};\n\t\tconst writeStartedAt = performance.now();\n\t\ttry {\n\t\t\tthis.deps.store.recordExecution(execution);\n\t\t} finally {\n\t\t\tthis.timings.record(\"observation_write\", performance.now() - writeStartedAt);\n\t\t}\n\t}\n\n\trecordValidation(toolName: string, outcome: \"repaired\" | \"bounced\"): void {\n\t\tif (!this.observeEnabled) return;\n\t\tconst modelRef = this.deps.getModelRef();\n\t\tconst tool = this.deps.getActiveTools().find((candidate) => candidate.name === toolName) ?? { name: toolName };\n\t\tconst writeStartedAt = performance.now();\n\t\ttry {\n\t\t\tthis.deps.store.recordValidation(modelToolKey(modelRef, classifyToolIntent(tool), toolName), outcome);\n\t\t} finally {\n\t\t\tthis.timings.record(\"validation_write\", performance.now() - writeStartedAt);\n\t\t}\n\t}\n\n\t/**\n\t * The currently active evidence-gated hints for the session's current model — one per\n\t * (intentClass) at most, only where accumulated evidence clears the promotion gate. Consumed by\n\t * `system-prompt-builder.ts` to render a compact, cache-stable prompt block. Empty when the\n\t * hint kill switch (`PI_TOOL_SELECTION_HINTS=0`) is set, observing is disabled, or no bucket has\n\t * cleared the gate yet.\n\t */\n\tgetActiveHints(modelRef: string = this.deps.getModelRef()): ToolSelectionHint[] {\n\t\tif ((this.deps.env ?? process.env).PI_TOOL_SELECTION_HINTS === \"0\") return [];\n\t\tif (!this.observeEnabled) return [];\n\t\tconst snapshotStartedAt = performance.now();\n\t\tconst statsByIntent = new Map<ToolSelectionIntentClass, ToolPerformanceStats[]>();\n\t\tfor (const stats of this.deps.store.getStatsForModel(modelRef)) {\n\t\t\tconst entries = statsByIntent.get(stats.intentClass) ?? [];\n\t\t\tentries.push(stats);\n\t\t\tstatsByIntent.set(stats.intentClass, entries);\n\t\t}\n\t\tconst hints: ToolSelectionHint[] = [];\n\t\tfor (const intentClass of INTENT_CLASSES) {\n\t\t\tconst promotion = evaluateToolPromotion(statsByIntent.get(intentClass) ?? []);\n\t\t\tif (!promotion.tool) continue;\n\t\t\thints.push({\n\t\t\t\tmodelRef,\n\t\t\t\tintentClass,\n\t\t\t\ttool: promotion.tool,\n\t\t\t\tsampleCount: promotion.sampleCount,\n\t\t\t\tmargin: promotion.margin,\n\t\t\t\tentropy: promotion.entropy,\n\t\t\t});\n\t\t}\n\t\tthis.timings.record(\"hint_snapshot\", performance.now() - snapshotStartedAt);\n\t\treturn hints;\n\t}\n\n\tformatTimingReport(): string {\n\t\treturn this.timings.formatReport();\n\t}\n\n\t/**\n\t * Report surface for the observe/agreement/promotion loop: per (model,intent), the durable\n\t * agreement rate (did the raw ranking's top pick match what was actually called), plus the\n\t * currently active hint (if any) and its own efficacy (agreement rate while it has been active).\n\t * A read-only diagnostic — never used to gate behavior. Render with\n\t * {@link formatToolSelectionReport}.\n\t */\n\tgetReport(modelRef: string = this.deps.getModelRef()): ToolSelectionReportEntry[] {\n\t\tconst activeHints = new Map(this.getActiveHints(modelRef).map((hint) => [hint.intentClass, hint]));\n\t\treturn this.deps.store\n\t\t\t.getAllIntentAgreements(modelRef)\n\t\t\t.filter((agreement) => agreement.sampleCount > 0)\n\t\t\t.map((agreement) => ({\n\t\t\t\tmodelRef: agreement.modelRef,\n\t\t\t\tintentClass: agreement.intentClass,\n\t\t\t\tsampleCount: agreement.sampleCount,\n\t\t\t\tagreementRate: agreement.agreementCount / agreement.sampleCount,\n\t\t\t\thintTool: activeHints.get(agreement.intentClass)?.tool,\n\t\t\t\thintSampleCount: agreement.hintActiveSampleCount,\n\t\t\t\thintAgreementRate:\n\t\t\t\t\tagreement.hintActiveSampleCount > 0\n\t\t\t\t\t\t? agreement.hintActiveAgreementCount / agreement.hintActiveSampleCount\n\t\t\t\t\t\t: undefined,\n\t\t\t}));\n\t}\n\n\tprivate selectionSnapshot(\n\t\tdecision: ToolSelectionDecision,\n\t\tfirstTool: boolean,\n\t): ToolSelectionPendingObservation[\"selection\"] {\n\t\treturn {\n\t\t\tfirstTool,\n\t\t\tdisposition: decision.disposition,\n\t\t\trecommendation: decision.recommendation,\n\t\t\tshortlist: decision.shortlist,\n\t\t\tentropy: decision.entropy,\n\t\t\tmargin: decision.margin,\n\t\t\tranked: decision.ranked.map((candidate) => ({\n\t\t\t\ttool: candidate.tool,\n\t\t\t\tutility: candidate.utility,\n\t\t\t\tprobability: candidate.probability,\n\t\t\t})),\n\t\t};\n\t}\n}\n\n/** Renders {@link ToolSelectionController.getReport} rows into the /toolhealth-style diagnostic text. */\nexport function formatToolSelectionReport(entries: readonly ToolSelectionReportEntry[]): string {\n\tif (entries.length === 0) {\n\t\treturn \"Tool-selection loop: no observations recorded yet for this host.\";\n\t}\n\tconst sorted = [...entries].sort(\n\t\t(left, right) => left.modelRef.localeCompare(right.modelRef) || left.intentClass.localeCompare(right.intentClass),\n\t);\n\tconst lines = [\"Tool-selection loop (observe -> agreement -> evidence-gated hint)\"];\n\tfor (const entry of sorted) {\n\t\tconst agreementText =\n\t\t\tentry.agreementRate === undefined\n\t\t\t\t? \"n/a\"\n\t\t\t\t: `${Math.round(entry.agreementRate * 100)}% (n=${entry.sampleCount})`;\n\t\tlines.push(` ${entry.modelRef} / ${entry.intentClass}: agreement ${agreementText}`);\n\t\tif (entry.hintTool) {\n\t\t\tconst hintAgreementText =\n\t\t\t\tentry.hintAgreementRate === undefined\n\t\t\t\t\t? \"n/a\"\n\t\t\t\t\t: `${Math.round(entry.hintAgreementRate * 100)}% (n=${entry.hintSampleCount})`;\n\t\t\tlines.push(` hint active: prefer \\`${entry.hintTool}\\` — agreement while active ${hintAgreementText}`);\n\t\t}\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport { classifyToolIntent, estimateContentTokens, estimateTokens };\n"]}
@@ -1,3 +1,6 @@
1
+ import type { Api, Model } from "@caupulican/pi-ai";
2
+ import { type IsolatedCompletionRunner } from "../isolated-text-completion.ts";
3
+ import { type SpawnedUsageReporter } from "../spawned-usage.ts";
1
4
  import type { ToolkitScript } from "./script-registry.ts";
2
5
  /**
3
6
  * Reflex interpreter (the BRAIN half of the user-ratified brain->muscle pipeline, statistically
@@ -14,6 +17,19 @@ export interface ReflexPlan {
14
17
  confidence: number;
15
18
  }
16
19
  export declare const REFLEX_MIN_CONFIDENCE = 0.75;
20
+ export interface ReflexInterpreterCompletionOptions {
21
+ request: string;
22
+ scripts: readonly ToolkitScript[];
23
+ model: Model<Api>;
24
+ laneKind: string;
25
+ usageKind: string;
26
+ usageLabel: string;
27
+ sessionId: string;
28
+ completionRunner: IsolatedCompletionRunner;
29
+ usageReporter: SpawnedUsageReporter;
30
+ }
31
+ /** Execute the shared reflex interpreter call and account for it under the caller's lane identity. */
32
+ export declare function runReflexInterpreterCompletion(options: ReflexInterpreterCompletionOptions): Promise<ReflexPlan | undefined>;
17
33
  export declare function buildReflexUserPrompt(request: string, scripts: readonly ToolkitScript[]): string;
18
34
  export declare function parseReflexPlan(text: string): ReflexPlan | undefined;
19
35
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"reflex-interpreter.d.ts","sourceRoot":"","sources":["../../../src/core/toolkit/reflex-interpreter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;GAMG;AAEH,eAAO,MAAM,gCAAgC,QAMjC,CAAC;AAEb,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,CAKhG;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CA6BpE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,UAAU,GAAG,SAAS,EAC5B,OAAO,EAAE,SAAS,aAAa,EAAE,GAC/B;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,SAAS,CAKvD","sourcesContent":["import type { ToolkitScript } from \"./script-registry.ts\";\n\n/**\n * Reflex interpreter (the BRAIN half of the user-ratified brain->muscle pipeline, statistically\n * validated at 10/10 correct interpretations on the hard registry): a strict instruction\n * interpreter that maps a fuzzy user request onto the toolkit registry. It NEVER executes\n * anything — it only proposes `{script, args, danger, confidence}` for the deterministic\n * executor path, which still enforces every safety rule (danger confirmation included).\n */\n\nexport const REFLEX_INTERPRETER_SYSTEM_PROMPT = [\n\t\"You are a strict instruction interpreter for a script executor. You NEVER execute anything.\",\n\t\"Given a user request and the script registry, output STRICT JSON only:\",\n\t'{\"script\":\"<exact registry name>\",\"args\":[\"...\"],\"danger\":true|false,\"confidence\":<0..1>}',\n\t\"Pick the single best script. Extract arguments exactly as the script expects. Mark danger from the registry.\",\n\t'If no script fits, output {\"script\":\"none\",\"args\":[],\"danger\":false,\"confidence\":0}.',\n].join(\"\\n\");\n\nexport interface ReflexPlan {\n\tscript: string;\n\targs: string[];\n\tdanger: boolean;\n\tconfidence: number;\n}\n\nexport const REFLEX_MIN_CONFIDENCE = 0.75;\n\nexport function buildReflexUserPrompt(request: string, scripts: readonly ToolkitScript[]): string {\n\tconst registry = scripts\n\t\t.map((script) => `${script.name}: ${script.description}${script.danger ? \" [DANGEROUS]\" : \"\"}`)\n\t\t.join(\"\\n\");\n\treturn `Registry:\\n${registry}\\n\\nRequest: ${request.slice(0, 2000)}`;\n}\n\nexport function parseReflexPlan(text: string): ReflexPlan | undefined {\n\tconst trimmed = text.trim();\n\t// Strip a leading think block some local models emit even with thinking off.\n\tconst thinkEnd = trimmed.indexOf(\"</think>\");\n\tconst body = thinkEnd >= 0 ? trimmed.slice(thinkEnd + 8) : trimmed;\n\tconst start = body.indexOf(\"{\");\n\tconst end = body.lastIndexOf(\"}\");\n\tif (start < 0 || end <= start) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(body.slice(start, end + 1)) as {\n\t\t\tscript?: unknown;\n\t\t\targs?: unknown;\n\t\t\tdanger?: unknown;\n\t\t\tconfidence?: unknown;\n\t\t};\n\t\tif (typeof parsed.script !== \"string\" || parsed.script.length === 0) return undefined;\n\t\tconst confidence =\n\t\t\ttypeof parsed.confidence === \"number\" && Number.isFinite(parsed.confidence)\n\t\t\t\t? Math.max(0, Math.min(1, parsed.confidence))\n\t\t\t\t: 0;\n\t\treturn {\n\t\t\tscript: parsed.script,\n\t\t\targs: Array.isArray(parsed.args) ? parsed.args.filter((arg): arg is string => typeof arg === \"string\") : [],\n\t\t\tdanger: parsed.danger === true,\n\t\t\tconfidence,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Accept a plan only when it is confident AND names a real registry script (\"none\" and unknown\n * names are honest refusals). The DANGER flag is never trusted from the plan — the registry's\n * own flag governs confirmation, exactly as for a direct match.\n */\nexport function acceptReflexPlan(\n\tplan: ReflexPlan | undefined,\n\tscripts: readonly ToolkitScript[],\n): { script: ToolkitScript; args: string[] } | undefined {\n\tif (!plan || plan.confidence < REFLEX_MIN_CONFIDENCE) return undefined;\n\tconst script = scripts.find((entry) => entry.name === plan.script);\n\tif (!script) return undefined;\n\treturn { script, args: plan.args };\n}\n"]}
1
+ {"version":3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,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,UAAU,GAAG,SAAS,EAC5B,OAAO,EAAE,SAAS,aAAa,EAAE,GAC/B;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,SAAS,CAKvD"}
@@ -1,3 +1,5 @@
1
+ import { runIsolatedTextCompletion } from "../isolated-text-completion.js";
2
+ import { reportSpawnedUsage } from "../spawned-usage.js";
1
3
  /**
2
4
  * Reflex interpreter (the BRAIN half of the user-ratified brain->muscle pipeline, statistically
3
5
  * validated at 10/10 correct interpretations on the hard registry): a strict instruction
@@ -13,6 +15,25 @@ export const REFLEX_INTERPRETER_SYSTEM_PROMPT = [
13
15
  'If no script fits, output {"script":"none","args":[],"danger":false,"confidence":0}.',
14
16
  ].join("\n");
15
17
  export const REFLEX_MIN_CONFIDENCE = 0.75;
18
+ /** Execute the shared reflex interpreter call and account for it under the caller's lane identity. */
19
+ export async function runReflexInterpreterCompletion(options) {
20
+ const completion = await runIsolatedTextCompletion(options.completionRunner, {
21
+ systemPrompt: REFLEX_INTERPRETER_SYSTEM_PROMPT,
22
+ userPrompt: buildReflexUserPrompt(options.request, options.scripts),
23
+ model: options.model,
24
+ thinkingLevel: "off",
25
+ maxTokens: 256,
26
+ cacheRetention: "short",
27
+ laneKind: options.laneKind,
28
+ });
29
+ reportSpawnedUsage(options.usageReporter, completion.usage, {
30
+ kind: options.usageKind,
31
+ label: options.usageLabel,
32
+ sessionId: options.sessionId,
33
+ identity: options.request,
34
+ });
35
+ return parseReflexPlan(completion.text);
36
+ }
16
37
  export function buildReflexUserPrompt(request, scripts) {
17
38
  const registry = scripts
18
39
  .map((script) => `${script.name}: ${script.description}${script.danger ? " [DANGEROUS]" : ""}`)
@@ -1 +1 @@
1
- {"version":3,"file":"reflex-interpreter.js","sourceRoot":"","sources":["../../../src/core/toolkit/reflex-interpreter.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,MAAM,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C,IAAI,EAAE,CAAC;AAAA,CACnC","sourcesContent":["import type { ToolkitScript } from \"./script-registry.ts\";\n\n/**\n * Reflex interpreter (the BRAIN half of the user-ratified brain->muscle pipeline, statistically\n * validated at 10/10 correct interpretations on the hard registry): a strict instruction\n * interpreter that maps a fuzzy user request onto the toolkit registry. It NEVER executes\n * anything — it only proposes `{script, args, danger, confidence}` for the deterministic\n * executor path, which still enforces every safety rule (danger confirmation included).\n */\n\nexport const REFLEX_INTERPRETER_SYSTEM_PROMPT = [\n\t\"You are a strict instruction interpreter for a script executor. You NEVER execute anything.\",\n\t\"Given a user request and the script registry, output STRICT JSON only:\",\n\t'{\"script\":\"<exact registry name>\",\"args\":[\"...\"],\"danger\":true|false,\"confidence\":<0..1>}',\n\t\"Pick the single best script. Extract arguments exactly as the script expects. Mark danger from the registry.\",\n\t'If no script fits, output {\"script\":\"none\",\"args\":[],\"danger\":false,\"confidence\":0}.',\n].join(\"\\n\");\n\nexport interface ReflexPlan {\n\tscript: string;\n\targs: string[];\n\tdanger: boolean;\n\tconfidence: number;\n}\n\nexport const REFLEX_MIN_CONFIDENCE = 0.75;\n\nexport function buildReflexUserPrompt(request: string, scripts: readonly ToolkitScript[]): string {\n\tconst registry = scripts\n\t\t.map((script) => `${script.name}: ${script.description}${script.danger ? \" [DANGEROUS]\" : \"\"}`)\n\t\t.join(\"\\n\");\n\treturn `Registry:\\n${registry}\\n\\nRequest: ${request.slice(0, 2000)}`;\n}\n\nexport function parseReflexPlan(text: string): ReflexPlan | undefined {\n\tconst trimmed = text.trim();\n\t// Strip a leading think block some local models emit even with thinking off.\n\tconst thinkEnd = trimmed.indexOf(\"</think>\");\n\tconst body = thinkEnd >= 0 ? trimmed.slice(thinkEnd + 8) : trimmed;\n\tconst start = body.indexOf(\"{\");\n\tconst end = body.lastIndexOf(\"}\");\n\tif (start < 0 || end <= start) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(body.slice(start, end + 1)) as {\n\t\t\tscript?: unknown;\n\t\t\targs?: unknown;\n\t\t\tdanger?: unknown;\n\t\t\tconfidence?: unknown;\n\t\t};\n\t\tif (typeof parsed.script !== \"string\" || parsed.script.length === 0) return undefined;\n\t\tconst confidence =\n\t\t\ttypeof parsed.confidence === \"number\" && Number.isFinite(parsed.confidence)\n\t\t\t\t? Math.max(0, Math.min(1, parsed.confidence))\n\t\t\t\t: 0;\n\t\treturn {\n\t\t\tscript: parsed.script,\n\t\t\targs: Array.isArray(parsed.args) ? parsed.args.filter((arg): arg is string => typeof arg === \"string\") : [],\n\t\t\tdanger: parsed.danger === true,\n\t\t\tconfidence,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Accept a plan only when it is confident AND names a real registry script (\"none\" and unknown\n * names are honest refusals). The DANGER flag is never trusted from the plan — the registry's\n * own flag governs confirmation, exactly as for a direct match.\n */\nexport function acceptReflexPlan(\n\tplan: ReflexPlan | undefined,\n\tscripts: readonly ToolkitScript[],\n): { script: ToolkitScript; args: string[] } | undefined {\n\tif (!plan || plan.confidence < REFLEX_MIN_CONFIDENCE) return undefined;\n\tconst script = scripts.find((entry) => entry.name === plan.script);\n\tif (!script) return undefined;\n\treturn { script, args: plan.args };\n}\n"]}
1
+ {"version":3,"file":"reflex-interpreter.js","sourceRoot":"","sources":["../../../src/core/toolkit/reflex-interpreter.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAA6B,MAAM,qBAAqB,CAAC;AAGpF;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC/C,6FAA6F;IAC7F,wEAAwE;IACxE,2FAA2F;IAC3F,8GAA8G;IAC9G,sFAAsF;CACtF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AASb,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAc1C,sGAAsG;AACtG,MAAM,CAAC,KAAK,UAAU,8BAA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MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC/B,IAA4B,EAC5B,OAAiC;IAEjC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,GAAG,qBAAqB;QAAE,OAAO,SAAS,CAAC;IACvE,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC;IACnE,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;AACpC,CAAC","sourcesContent":["import type { Api, Model } from \"@caupulican/pi-ai\";\nimport { type IsolatedCompletionRunner, runIsolatedTextCompletion } from \"../isolated-text-completion.ts\";\nimport { reportSpawnedUsage, type SpawnedUsageReporter } from \"../spawned-usage.ts\";\nimport type { ToolkitScript } from \"./script-registry.ts\";\n\n/**\n * Reflex interpreter (the BRAIN half of the user-ratified brain->muscle pipeline, statistically\n * validated at 10/10 correct interpretations on the hard registry): a strict instruction\n * interpreter that maps a fuzzy user request onto the toolkit registry. It NEVER executes\n * anything — it only proposes `{script, args, danger, confidence}` for the deterministic\n * executor path, which still enforces every safety rule (danger confirmation included).\n */\n\nexport const REFLEX_INTERPRETER_SYSTEM_PROMPT = [\n\t\"You are a strict instruction interpreter for a script executor. You NEVER execute anything.\",\n\t\"Given a user request and the script registry, output STRICT JSON only:\",\n\t'{\"script\":\"<exact registry name>\",\"args\":[\"...\"],\"danger\":true|false,\"confidence\":<0..1>}',\n\t\"Pick the single best script. Extract arguments exactly as the script expects. Mark danger from the registry.\",\n\t'If no script fits, output {\"script\":\"none\",\"args\":[],\"danger\":false,\"confidence\":0}.',\n].join(\"\\n\");\n\nexport interface ReflexPlan {\n\tscript: string;\n\targs: string[];\n\tdanger: boolean;\n\tconfidence: number;\n}\n\nexport const REFLEX_MIN_CONFIDENCE = 0.75;\n\nexport interface ReflexInterpreterCompletionOptions {\n\trequest: string;\n\tscripts: readonly ToolkitScript[];\n\tmodel: Model<Api>;\n\tlaneKind: string;\n\tusageKind: string;\n\tusageLabel: string;\n\tsessionId: string;\n\tcompletionRunner: IsolatedCompletionRunner;\n\tusageReporter: SpawnedUsageReporter;\n}\n\n/** Execute the shared reflex interpreter call and account for it under the caller's lane identity. */\nexport async function runReflexInterpreterCompletion(\n\toptions: ReflexInterpreterCompletionOptions,\n): Promise<ReflexPlan | undefined> {\n\tconst completion = await runIsolatedTextCompletion(options.completionRunner, {\n\t\tsystemPrompt: REFLEX_INTERPRETER_SYSTEM_PROMPT,\n\t\tuserPrompt: buildReflexUserPrompt(options.request, options.scripts),\n\t\tmodel: options.model,\n\t\tthinkingLevel: \"off\",\n\t\tmaxTokens: 256,\n\t\tcacheRetention: \"short\",\n\t\tlaneKind: options.laneKind,\n\t});\n\treportSpawnedUsage(options.usageReporter, completion.usage, {\n\t\tkind: options.usageKind,\n\t\tlabel: options.usageLabel,\n\t\tsessionId: options.sessionId,\n\t\tidentity: options.request,\n\t});\n\treturn parseReflexPlan(completion.text);\n}\n\nexport function buildReflexUserPrompt(request: string, scripts: readonly ToolkitScript[]): string {\n\tconst registry = scripts\n\t\t.map((script) => `${script.name}: ${script.description}${script.danger ? \" [DANGEROUS]\" : \"\"}`)\n\t\t.join(\"\\n\");\n\treturn `Registry:\\n${registry}\\n\\nRequest: ${request.slice(0, 2000)}`;\n}\n\nexport function parseReflexPlan(text: string): ReflexPlan | undefined {\n\tconst trimmed = text.trim();\n\t// Strip a leading think block some local models emit even with thinking off.\n\tconst thinkEnd = trimmed.indexOf(\"</think>\");\n\tconst body = thinkEnd >= 0 ? trimmed.slice(thinkEnd + 8) : trimmed;\n\tconst start = body.indexOf(\"{\");\n\tconst end = body.lastIndexOf(\"}\");\n\tif (start < 0 || end <= start) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(body.slice(start, end + 1)) as {\n\t\t\tscript?: unknown;\n\t\t\targs?: unknown;\n\t\t\tdanger?: unknown;\n\t\t\tconfidence?: unknown;\n\t\t};\n\t\tif (typeof parsed.script !== \"string\" || parsed.script.length === 0) return undefined;\n\t\tconst confidence =\n\t\t\ttypeof parsed.confidence === \"number\" && Number.isFinite(parsed.confidence)\n\t\t\t\t? Math.max(0, Math.min(1, parsed.confidence))\n\t\t\t\t: 0;\n\t\treturn {\n\t\t\tscript: parsed.script,\n\t\t\targs: Array.isArray(parsed.args) ? parsed.args.filter((arg): arg is string => typeof arg === \"string\") : [],\n\t\t\tdanger: parsed.danger === true,\n\t\t\tconfidence,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Accept a plan only when it is confident AND names a real registry script (\"none\" and unknown\n * names are honest refusals). The DANGER flag is never trusted from the plan — the registry's\n * own flag governs confirmation, exactly as for a direct match.\n */\nexport function acceptReflexPlan(\n\tplan: ReflexPlan | undefined,\n\tscripts: readonly ToolkitScript[],\n): { script: ToolkitScript; args: string[] } | undefined {\n\tif (!plan || plan.confidence < REFLEX_MIN_CONFIDENCE) return undefined;\n\tconst script = scripts.find((entry) => entry.name === plan.script);\n\tif (!script) return undefined;\n\treturn { script, args: plan.args };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"script-registry.d.ts","sourceRoot":"","sources":["../../../src/core/toolkit/script-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,YAAY,GAAG,MAAM,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC7B,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,aAAa,CAAC;IACtB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,YAAY,GACrB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,aAAa,EAAE,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC;AAkC9C,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,YAAY,CAkCnG","sourcesContent":["/**\n * Toolkit script registry + the Level-0 conservative matcher.\n *\n * The registry is the user's blessed daily-ops toolkit: named scripts with fixed runners. The\n * matcher maps a natural-language request to a script WITHOUT guessing: exact name/alias hits\n * match directly; scored matches win only with a clear margin over the runner-up; anything else\n * is a shortlist (disambiguate) or none. Ambiguity never executes — \"prepare db\" must never\n * silently run update-db.\n */\n\nexport type ToolkitRunner = \"uv\" | \"powershell\" | \"bash\";\n\nexport interface ToolkitScript {\n\t/** Registry key, kebab-case (e.g. \"restore-db\"). */\n\tname: string;\n\tdescription: string;\n\t/** User-taught phrases that map directly to this script. */\n\taliases?: string[];\n\trunner: ToolkitRunner;\n\t/** Script path, relative to cwd or absolute. */\n\tpath: string;\n\t/** Dangerous scripts require explicit confirmation at every level. */\n\tdanger?: boolean;\n}\n\nexport type ToolkitMatch =\n\t| { kind: \"exact\"; script: ToolkitScript }\n\t| { kind: \"ambiguous\"; shortlist: ToolkitScript[] }\n\t| { kind: \"none\"; closest: ToolkitScript[] };\n\nfunction normalize(text: string): string {\n\treturn text\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \" \")\n\t\t.trim();\n}\n\nfunction tokens(text: string): string[] {\n\treturn normalize(text).split(\" \").filter(Boolean);\n}\n\nconst STOP_WORDS = new Set([\"the\", \"a\", \"an\", \"my\", \"run\", \"execute\", \"please\", \"now\", \"thing\", \"for\", \"me\", \"to\"]);\n\n/** Score a request against one script: shared meaningful tokens with name/alias/description. */\nfunction scoreScript(requestTokens: string[], script: ToolkitScript): number {\n\tconst nameTokens = new Set([...tokens(script.name), ...(script.aliases ?? []).flatMap((alias) => tokens(alias))]);\n\tconst descriptionTokens = new Set(tokens(script.description));\n\tlet score = 0;\n\t// Deduplicate: repeating a word (\"backup backup backup\") must not multiply the score past\n\t// MIN_SCORE/margin and turn an ambiguous request into a confident match.\n\tfor (const token of new Set(requestTokens)) {\n\t\tif (STOP_WORDS.has(token)) continue;\n\t\tif (nameTokens.has(token)) score += 3;\n\t\telse if (descriptionTokens.has(token)) score += 1;\n\t}\n\treturn score;\n}\n\n/** Margin rule: the winner must beat the runner-up by at least this factor AND absolute gap. */\nconst MARGIN_FACTOR = 1.5;\nconst MIN_SCORE = 3;\n\nexport function matchToolkitScript(request: string, scripts: readonly ToolkitScript[]): ToolkitMatch {\n\tconst normalizedRequest = normalize(request);\n\tif (normalizedRequest.length === 0 || scripts.length === 0) {\n\t\treturn { kind: \"none\", closest: [] };\n\t}\n\n\t// 1. Exact name or alias (normalized) matches directly.\n\tfor (const script of scripts) {\n\t\tif (normalize(script.name) === normalizedRequest) return { kind: \"exact\", script };\n\t\tfor (const alias of script.aliases ?? []) {\n\t\t\tif (normalize(alias) === normalizedRequest) return { kind: \"exact\", script };\n\t\t}\n\t}\n\n\t// 2. Scored matching with the margin rule.\n\tconst requestTokens = tokens(request);\n\tconst scored = scripts\n\t\t.map((script) => ({ script, score: scoreScript(requestTokens, script) }))\n\t\t.filter((entry) => entry.score > 0)\n\t\t.sort((a, b) => b.score - a.score);\n\n\tif (scored.length === 0) {\n\t\treturn { kind: \"none\", closest: scripts.slice(0, 3) };\n\t}\n\tconst [best, runnerUp] = scored;\n\tif (\n\t\tbest.score >= MIN_SCORE &&\n\t\t(runnerUp === undefined || (best.score >= runnerUp.score * MARGIN_FACTOR && best.score - runnerUp.score >= 2))\n\t) {\n\t\treturn { kind: \"exact\", script: best.script };\n\t}\n\n\t// No clear winner: shortlist for disambiguation — never guess.\n\treturn { kind: \"ambiguous\", shortlist: scored.slice(0, 4).map((entry) => entry.script) };\n}\n"]}
1
+ {"version":3,"file":"script-registry.d.ts","sourceRoot":"","sources":["../../../src/core/toolkit/script-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,YAAY,GAAG,MAAM,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC7B,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,aAAa,CAAC;IACtB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,YAAY,GACrB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,aAAa,EAAE,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC;AAkC9C,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,YAAY,CAkCnG"}
@@ -1 +1 @@
1
- {"version":3,"file":"script-registry.js","sourceRoot":"","sources":["../../../src/core/toolkit/script-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,SAAS,SAAS,CAAC,IAAY,EAAU;IACxC,OAAO,IAAI;SACT,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,IAAI,EA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,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IACvD,CAAC;IACD,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC;IAChC,IACC,IAAI,CAAC,KAAK,IAAI,SAAS;QACvB,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,GAAG,aAAa,IAAI,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAC7G,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC/C,CAAC;IAED,iEAA+D;IAC/D,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AAAA,CACzF","sourcesContent":["/**\n * Toolkit script registry + the Level-0 conservative matcher.\n *\n * The registry is the user's blessed daily-ops toolkit: named scripts with fixed runners. The\n * matcher maps a natural-language request to a script WITHOUT guessing: exact name/alias hits\n * match directly; scored matches win only with a clear margin over the runner-up; anything else\n * is a shortlist (disambiguate) or none. Ambiguity never executes — \"prepare db\" must never\n * silently run update-db.\n */\n\nexport type ToolkitRunner = \"uv\" | \"powershell\" | \"bash\";\n\nexport interface ToolkitScript {\n\t/** Registry key, kebab-case (e.g. \"restore-db\"). */\n\tname: string;\n\tdescription: string;\n\t/** User-taught phrases that map directly to this script. */\n\taliases?: string[];\n\trunner: ToolkitRunner;\n\t/** Script path, relative to cwd or absolute. */\n\tpath: string;\n\t/** Dangerous scripts require explicit confirmation at every level. */\n\tdanger?: boolean;\n}\n\nexport type ToolkitMatch =\n\t| { kind: \"exact\"; script: ToolkitScript }\n\t| { kind: \"ambiguous\"; shortlist: ToolkitScript[] }\n\t| { kind: \"none\"; closest: ToolkitScript[] };\n\nfunction normalize(text: string): string {\n\treturn text\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \" \")\n\t\t.trim();\n}\n\nfunction tokens(text: string): string[] {\n\treturn normalize(text).split(\" \").filter(Boolean);\n}\n\nconst STOP_WORDS = new Set([\"the\", \"a\", \"an\", \"my\", \"run\", \"execute\", \"please\", \"now\", \"thing\", \"for\", \"me\", \"to\"]);\n\n/** Score a request against one script: shared meaningful tokens with name/alias/description. */\nfunction scoreScript(requestTokens: string[], script: ToolkitScript): number {\n\tconst nameTokens = new Set([...tokens(script.name), ...(script.aliases ?? []).flatMap((alias) => tokens(alias))]);\n\tconst descriptionTokens = new Set(tokens(script.description));\n\tlet score = 0;\n\t// Deduplicate: repeating a word (\"backup backup backup\") must not multiply the score past\n\t// MIN_SCORE/margin and turn an ambiguous request into a confident match.\n\tfor (const token of new Set(requestTokens)) {\n\t\tif (STOP_WORDS.has(token)) continue;\n\t\tif (nameTokens.has(token)) score += 3;\n\t\telse if (descriptionTokens.has(token)) score += 1;\n\t}\n\treturn score;\n}\n\n/** Margin rule: the winner must beat the runner-up by at least this factor AND absolute gap. */\nconst MARGIN_FACTOR = 1.5;\nconst MIN_SCORE = 3;\n\nexport function matchToolkitScript(request: string, scripts: readonly ToolkitScript[]): ToolkitMatch {\n\tconst normalizedRequest = normalize(request);\n\tif (normalizedRequest.length === 0 || scripts.length === 0) {\n\t\treturn { kind: \"none\", closest: [] };\n\t}\n\n\t// 1. Exact name or alias (normalized) matches directly.\n\tfor (const script of scripts) {\n\t\tif (normalize(script.name) === normalizedRequest) return { kind: \"exact\", script };\n\t\tfor (const alias of script.aliases ?? []) {\n\t\t\tif (normalize(alias) === normalizedRequest) return { kind: \"exact\", script };\n\t\t}\n\t}\n\n\t// 2. Scored matching with the margin rule.\n\tconst requestTokens = tokens(request);\n\tconst scored = scripts\n\t\t.map((script) => ({ script, score: scoreScript(requestTokens, script) }))\n\t\t.filter((entry) => entry.score > 0)\n\t\t.sort((a, b) => b.score - a.score);\n\n\tif (scored.length === 0) {\n\t\treturn { kind: \"none\", closest: scripts.slice(0, 3) };\n\t}\n\tconst [best, runnerUp] = scored;\n\tif (\n\t\tbest.score >= MIN_SCORE &&\n\t\t(runnerUp === undefined || (best.score >= runnerUp.score * MARGIN_FACTOR && best.score - runnerUp.score >= 2))\n\t) {\n\t\treturn { kind: \"exact\", script: best.script };\n\t}\n\n\t// No clear winner: shortlist for disambiguation — never guess.\n\treturn { kind: \"ambiguous\", shortlist: scored.slice(0, 4).map((entry) => entry.script) };\n}\n"]}
1
+ {"version":3,"file":"script-registry.js","sourceRoot":"","sources":["../../../src/core/toolkit/script-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,SAAS,SAAS,CAAC,IAAY;IAC9B,OAAO,IAAI;SACT,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,IAAI,EAAE,CAAC;AACV,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC3B,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEpH,gGAAgG;AAChG,SAAS,WAAW,CAAC,aAAuB,EAAE,MAAqB;IAClE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,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AC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AAC1F,CAAC","sourcesContent":["/**\n * Toolkit script registry + the Level-0 conservative matcher.\n *\n * The registry is the user's blessed daily-ops toolkit: named scripts with fixed runners. The\n * matcher maps a natural-language request to a script WITHOUT guessing: exact name/alias hits\n * match directly; scored matches win only with a clear margin over the runner-up; anything else\n * is a shortlist (disambiguate) or none. Ambiguity never executes — \"prepare db\" must never\n * silently run update-db.\n */\n\nexport type ToolkitRunner = \"uv\" | \"powershell\" | \"bash\";\n\nexport interface ToolkitScript {\n\t/** Registry key, kebab-case (e.g. \"restore-db\"). */\n\tname: string;\n\tdescription: string;\n\t/** User-taught phrases that map directly to this script. */\n\taliases?: string[];\n\trunner: ToolkitRunner;\n\t/** Script path, relative to cwd or absolute. */\n\tpath: string;\n\t/** Dangerous scripts require explicit confirmation at every level. */\n\tdanger?: boolean;\n}\n\nexport type ToolkitMatch =\n\t| { kind: \"exact\"; script: ToolkitScript }\n\t| { kind: \"ambiguous\"; shortlist: ToolkitScript[] }\n\t| { kind: \"none\"; closest: ToolkitScript[] };\n\nfunction normalize(text: string): string {\n\treturn text\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \" \")\n\t\t.trim();\n}\n\nfunction tokens(text: string): string[] {\n\treturn normalize(text).split(\" \").filter(Boolean);\n}\n\nconst STOP_WORDS = new Set([\"the\", \"a\", \"an\", \"my\", \"run\", \"execute\", \"please\", \"now\", \"thing\", \"for\", \"me\", \"to\"]);\n\n/** Score a request against one script: shared meaningful tokens with name/alias/description. */\nfunction scoreScript(requestTokens: string[], script: ToolkitScript): number {\n\tconst nameTokens = new Set([...tokens(script.name), ...(script.aliases ?? []).flatMap((alias) => tokens(alias))]);\n\tconst descriptionTokens = new Set(tokens(script.description));\n\tlet score = 0;\n\t// Deduplicate: repeating a word (\"backup backup backup\") must not multiply the score past\n\t// MIN_SCORE/margin and turn an ambiguous request into a confident match.\n\tfor (const token of new Set(requestTokens)) {\n\t\tif (STOP_WORDS.has(token)) continue;\n\t\tif (nameTokens.has(token)) score += 3;\n\t\telse if (descriptionTokens.has(token)) score += 1;\n\t}\n\treturn score;\n}\n\n/** Margin rule: the winner must beat the runner-up by at least this factor AND absolute gap. */\nconst MARGIN_FACTOR = 1.5;\nconst MIN_SCORE = 3;\n\nexport function matchToolkitScript(request: string, scripts: readonly ToolkitScript[]): ToolkitMatch {\n\tconst normalizedRequest = normalize(request);\n\tif (normalizedRequest.length === 0 || scripts.length === 0) {\n\t\treturn { kind: \"none\", closest: [] };\n\t}\n\n\t// 1. Exact name or alias (normalized) matches directly.\n\tfor (const script of scripts) {\n\t\tif (normalize(script.name) === normalizedRequest) return { kind: \"exact\", script };\n\t\tfor (const alias of script.aliases ?? []) {\n\t\t\tif (normalize(alias) === normalizedRequest) return { kind: \"exact\", script };\n\t\t}\n\t}\n\n\t// 2. Scored matching with the margin rule.\n\tconst requestTokens = tokens(request);\n\tconst scored = scripts\n\t\t.map((script) => ({ script, score: scoreScript(requestTokens, script) }))\n\t\t.filter((entry) => entry.score > 0)\n\t\t.sort((a, b) => b.score - a.score);\n\n\tif (scored.length === 0) {\n\t\treturn { kind: \"none\", closest: scripts.slice(0, 3) };\n\t}\n\tconst [best, runnerUp] = scored;\n\tif (\n\t\tbest.score >= MIN_SCORE &&\n\t\t(runnerUp === undefined || (best.score >= runnerUp.score * MARGIN_FACTOR && best.score - runnerUp.score >= 2))\n\t) {\n\t\treturn { kind: \"exact\", script: best.script };\n\t}\n\n\t// No clear winner: shortlist for disambiguation — never guess.\n\treturn { kind: \"ambiguous\", shortlist: scored.slice(0, 4).map((entry) => entry.script) };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"script-runner.d.ts","sourceRoot":"","sources":["../../../src/core/toolkit/script-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;GAIG;AAEH,MAAM,WAAW,eAAe;IAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,cAAc,GAAG,CAC5B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,KACb,OAAO,CAAC,eAAe,CAAC,CAAC;AAE9B,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAYnH;AAKD,6FAA6F;AAC7F,eAAO,MAAM,mBAAmB,EAAE,cAyDjC,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAChD,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC1B,GAAG,OAAO,CAAC,eAAe,CAAC,CAI3B","sourcesContent":["import { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolkitScript } from \"./script-registry.ts\";\n\n/**\n * Toolkit script invocation: the harness owns execution. Fixed argv per runner (never a shell\n * string), captured exit/stdout/stderr ALWAYS — the structural error contract that makes\n * false-success impossible regardless of what the model narrates.\n */\n\nexport interface ScriptExecution {\n\texitCode: number | null;\n\tstdout: string;\n\tstderr: string;\n\tdurationMs: number;\n\ttimedOut: boolean;\n}\n\nexport type ScriptExecutor = (\n\tcommand: string,\n\targv: string[],\n\tcwd: string,\n\ttimeoutMs: number,\n) => Promise<ScriptExecution>;\n\nexport function buildScriptArgv(script: ToolkitScript, args: readonly string[]): { command: string; argv: string[] } {\n\tswitch (script.runner) {\n\t\tcase \"uv\":\n\t\t\treturn { command: \"uv\", argv: [\"run\", script.path, ...args] };\n\t\tcase \"powershell\":\n\t\t\treturn {\n\t\t\t\tcommand: \"powershell.exe\",\n\t\t\t\targv: [\"-NoProfile\", \"-ExecutionPolicy\", \"Bypass\", \"-File\", script.path, ...args],\n\t\t\t};\n\t\tcase \"bash\":\n\t\t\treturn { command: \"bash\", argv: [script.path, ...args] };\n\t}\n}\n\nconst MAX_OUTPUT_BYTES = 512 * 1024;\nconst SCRIPT_KILL_GRACE_MS = 2_000;\n\n/** Default executor: real process spawn, no shell interpolation, bounded output and time. */\nexport const spawnScriptExecutor: ScriptExecutor = async (command, argv, cwd, timeoutMs) => {\n\tconst started = Date.now();\n\tconst terminationController = new AbortController();\n\tconst stdoutChunks: Buffer[] = [];\n\tconst stderrChunks: Buffer[] = [];\n\tlet stdoutBytes = 0;\n\tlet stderrBytes = 0;\n\tlet outputExceeded = false;\n\tconst appendChunk = (chunks: Buffer[], chunk: Buffer, streamBytes: number): number => {\n\t\tconst remaining = Math.max(0, MAX_OUTPUT_BYTES - streamBytes);\n\t\tif (remaining > 0) chunks.push(chunk.subarray(0, remaining));\n\t\tconst nextBytes = streamBytes + chunk.length;\n\t\tif (nextBytes > MAX_OUTPUT_BYTES) {\n\t\t\toutputExceeded = true;\n\t\t\tterminationController.abort();\n\t\t}\n\t\treturn nextBytes;\n\t};\n\n\ttry {\n\t\tconst child = spawnProcess(command, argv, {\n\t\t\tcwd,\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => {\n\t\t\tstdoutBytes = appendChunk(stdoutChunks, chunk, stdoutBytes);\n\t\t});\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => {\n\t\t\tstderrBytes = appendChunk(stderrChunks, chunk, stderrBytes);\n\t\t});\n\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\tsignal: terminationController.signal,\n\t\t\ttimeoutMs,\n\t\t\tkillGraceMs: SCRIPT_KILL_GRACE_MS,\n\t\t});\n\t\tconst stdout = Buffer.concat(stdoutChunks).toString(\"utf8\");\n\t\tlet stderr = Buffer.concat(stderrChunks).toString(\"utf8\");\n\t\tif (outputExceeded) {\n\t\t\tstderr = `${stderr}${stderr ? \"\\n\" : \"\"}Command output exceeded maxBuffer (${MAX_OUTPUT_BYTES} bytes)`;\n\t\t}\n\t\treturn {\n\t\t\texitCode: outputExceeded ? null : terminal.code,\n\t\t\tstdout,\n\t\t\tstderr,\n\t\t\tdurationMs: Date.now() - started,\n\t\t\ttimedOut: terminal.reason === \"timeout\",\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\texitCode: null,\n\t\t\tstdout: Buffer.concat(stdoutChunks).toString(\"utf8\"),\n\t\t\tstderr: error instanceof Error ? error.message : String(error),\n\t\t\tdurationMs: Date.now() - started,\n\t\t\ttimedOut: false,\n\t\t};\n\t}\n};\n\nexport async function executeToolkitScript(args: {\n\tscript: ToolkitScript;\n\tscriptArgs: readonly string[];\n\tcwd: string;\n\ttimeoutMs?: number;\n\texecutor?: ScriptExecutor;\n}): Promise<ScriptExecution> {\n\tconst { command, argv } = buildScriptArgv(args.script, args.scriptArgs);\n\tconst executor = args.executor ?? spawnScriptExecutor;\n\treturn executor(command, argv, args.cwd, args.timeoutMs ?? 120_000);\n}\n"]}
1
+ {"version":3,"file":"script-runner.d.ts","sourceRoot":"","sources":["../../../src/core/toolkit/script-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;GAIG;AAEH,MAAM,WAAW,eAAe;IAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB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AC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI;YAC/C,MAAM;YACN,MAAM;YACN,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;YAChC,QAAQ,EAAE,QAAQ,CAAC,MAAM,KAAK,SAAS;SACvC,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO;YACN,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;YACpD,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC9D,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;YAChC,QAAQ,EAAE,KAAK;SACf,CAAC;IACH,CAAC;AAAA,CACD,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,IAM1C,EAA4B;IAC5B,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACxE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,mBAAmB,CAAC;IACtD,OAAO,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,CAAC;AAAA,CACpE","sourcesContent":["import { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolkitScript } from \"./script-registry.ts\";\n\n/**\n * Toolkit script invocation: the harness owns execution. Fixed argv per runner (never a shell\n * string), captured exit/stdout/stderr ALWAYS — the structural error contract that makes\n * false-success impossible regardless of what the model narrates.\n */\n\nexport interface ScriptExecution {\n\texitCode: number | null;\n\tstdout: string;\n\tstderr: string;\n\tdurationMs: number;\n\ttimedOut: boolean;\n}\n\nexport type ScriptExecutor = (\n\tcommand: string,\n\targv: string[],\n\tcwd: string,\n\ttimeoutMs: number,\n) => Promise<ScriptExecution>;\n\nexport function buildScriptArgv(script: ToolkitScript, args: readonly string[]): { command: string; argv: string[] } {\n\tswitch (script.runner) {\n\t\tcase \"uv\":\n\t\t\treturn { command: \"uv\", argv: [\"run\", script.path, ...args] };\n\t\tcase \"powershell\":\n\t\t\treturn {\n\t\t\t\tcommand: \"powershell.exe\",\n\t\t\t\targv: [\"-NoProfile\", \"-ExecutionPolicy\", \"Bypass\", \"-File\", script.path, ...args],\n\t\t\t};\n\t\tcase \"bash\":\n\t\t\treturn { command: \"bash\", argv: [script.path, ...args] };\n\t}\n}\n\nconst MAX_OUTPUT_BYTES = 512 * 1024;\nconst SCRIPT_KILL_GRACE_MS = 2_000;\n\n/** Default executor: real process spawn, no shell interpolation, bounded output and time. */\nexport const spawnScriptExecutor: ScriptExecutor = async (command, argv, cwd, timeoutMs) => {\n\tconst started = Date.now();\n\tconst terminationController = new AbortController();\n\tconst stdoutChunks: Buffer[] = [];\n\tconst stderrChunks: Buffer[] = [];\n\tlet stdoutBytes = 0;\n\tlet stderrBytes = 0;\n\tlet outputExceeded = false;\n\tconst appendChunk = (chunks: Buffer[], chunk: Buffer, streamBytes: number): number => {\n\t\tconst remaining = Math.max(0, MAX_OUTPUT_BYTES - streamBytes);\n\t\tif (remaining > 0) chunks.push(chunk.subarray(0, remaining));\n\t\tconst nextBytes = streamBytes + chunk.length;\n\t\tif (nextBytes > MAX_OUTPUT_BYTES) {\n\t\t\toutputExceeded = true;\n\t\t\tterminationController.abort();\n\t\t}\n\t\treturn nextBytes;\n\t};\n\n\ttry {\n\t\tconst child = spawnProcess(command, argv, {\n\t\t\tcwd,\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => {\n\t\t\tstdoutBytes = appendChunk(stdoutChunks, chunk, stdoutBytes);\n\t\t});\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => {\n\t\t\tstderrBytes = appendChunk(stderrChunks, chunk, stderrBytes);\n\t\t});\n\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\tsignal: terminationController.signal,\n\t\t\ttimeoutMs,\n\t\t\tkillGraceMs: SCRIPT_KILL_GRACE_MS,\n\t\t});\n\t\tconst stdout = Buffer.concat(stdoutChunks).toString(\"utf8\");\n\t\tlet stderr = Buffer.concat(stderrChunks).toString(\"utf8\");\n\t\tif (outputExceeded) {\n\t\t\tstderr = `${stderr}${stderr ? \"\\n\" : \"\"}Command output exceeded maxBuffer (${MAX_OUTPUT_BYTES} bytes)`;\n\t\t}\n\t\treturn {\n\t\t\texitCode: outputExceeded ? null : terminal.code,\n\t\t\tstdout,\n\t\t\tstderr,\n\t\t\tdurationMs: Date.now() - started,\n\t\t\ttimedOut: terminal.reason === \"timeout\",\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\texitCode: null,\n\t\t\tstdout: Buffer.concat(stdoutChunks).toString(\"utf8\"),\n\t\t\tstderr: error instanceof Error ? error.message : String(error),\n\t\t\tdurationMs: Date.now() - started,\n\t\t\ttimedOut: false,\n\t\t};\n\t}\n};\n\nexport async function executeToolkitScript(args: {\n\tscript: ToolkitScript;\n\tscriptArgs: readonly string[];\n\tcwd: string;\n\ttimeoutMs?: number;\n\texecutor?: ScriptExecutor;\n}): Promise<ScriptExecution> {\n\tconst { command, argv } = buildScriptArgv(args.script, args.scriptArgs);\n\tconst executor = args.executor ?? spawnScriptExecutor;\n\treturn executor(command, argv, args.cwd, args.timeoutMs ?? 120_000);\n}\n"]}
1
+ {"version":3,"file":"script-runner.js","sourceRoot":"","sources":["../../../src/core/toolkit/script-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAwBhG,MAAM,UAAU,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-process.ts\";\nimport type { ToolkitScript } from \"./script-registry.ts\";\n\n/**\n * Toolkit script invocation: the harness owns execution. Fixed argv per runner (never a shell\n * string), captured exit/stdout/stderr ALWAYS — the structural error contract that makes\n * false-success impossible regardless of what the model narrates.\n */\n\nexport interface ScriptExecution {\n\texitCode: number | null;\n\tstdout: string;\n\tstderr: string;\n\tdurationMs: number;\n\ttimedOut: boolean;\n}\n\nexport type ScriptExecutor = (\n\tcommand: string,\n\targv: string[],\n\tcwd: string,\n\ttimeoutMs: number,\n) => Promise<ScriptExecution>;\n\nexport function buildScriptArgv(script: ToolkitScript, args: readonly string[]): { command: string; argv: string[] } {\n\tswitch (script.runner) {\n\t\tcase \"uv\":\n\t\t\treturn { command: \"uv\", argv: [\"run\", script.path, ...args] };\n\t\tcase \"powershell\":\n\t\t\treturn {\n\t\t\t\tcommand: \"powershell.exe\",\n\t\t\t\targv: [\"-NoProfile\", \"-ExecutionPolicy\", \"Bypass\", \"-File\", script.path, ...args],\n\t\t\t};\n\t\tcase \"bash\":\n\t\t\treturn { command: \"bash\", argv: [script.path, ...args] };\n\t}\n}\n\nconst MAX_OUTPUT_BYTES = 512 * 1024;\nconst SCRIPT_KILL_GRACE_MS = 2_000;\n\n/** Default executor: real process spawn, no shell interpolation, bounded output and time. */\nexport const spawnScriptExecutor: ScriptExecutor = async (command, argv, cwd, timeoutMs) => {\n\tconst started = Date.now();\n\tconst terminationController = new AbortController();\n\tconst stdoutChunks: Buffer[] = [];\n\tconst stderrChunks: Buffer[] = [];\n\tlet stdoutBytes = 0;\n\tlet stderrBytes = 0;\n\tlet outputExceeded = false;\n\tconst appendChunk = (chunks: Buffer[], chunk: Buffer, streamBytes: number): number => {\n\t\tconst remaining = Math.max(0, MAX_OUTPUT_BYTES - streamBytes);\n\t\tif (remaining > 0) chunks.push(chunk.subarray(0, remaining));\n\t\tconst nextBytes = streamBytes + chunk.length;\n\t\tif (nextBytes > MAX_OUTPUT_BYTES) {\n\t\t\toutputExceeded = true;\n\t\t\tterminationController.abort();\n\t\t}\n\t\treturn nextBytes;\n\t};\n\n\ttry {\n\t\tconst child = spawnProcess(command, argv, {\n\t\t\tcwd,\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => {\n\t\t\tstdoutBytes = appendChunk(stdoutChunks, chunk, stdoutBytes);\n\t\t});\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => {\n\t\t\tstderrBytes = appendChunk(stderrChunks, chunk, stderrBytes);\n\t\t});\n\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\tsignal: terminationController.signal,\n\t\t\ttimeoutMs,\n\t\t\tkillGraceMs: SCRIPT_KILL_GRACE_MS,\n\t\t});\n\t\tconst stdout = Buffer.concat(stdoutChunks).toString(\"utf8\");\n\t\tlet stderr = Buffer.concat(stderrChunks).toString(\"utf8\");\n\t\tif (outputExceeded) {\n\t\t\tstderr = `${stderr}${stderr ? \"\\n\" : \"\"}Command output exceeded maxBuffer (${MAX_OUTPUT_BYTES} bytes)`;\n\t\t}\n\t\treturn {\n\t\t\texitCode: outputExceeded ? null : terminal.code,\n\t\t\tstdout,\n\t\t\tstderr,\n\t\t\tdurationMs: Date.now() - started,\n\t\t\ttimedOut: terminal.reason === \"timeout\",\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\texitCode: null,\n\t\t\tstdout: Buffer.concat(stdoutChunks).toString(\"utf8\"),\n\t\t\tstderr: error instanceof Error ? error.message : String(error),\n\t\t\tdurationMs: Date.now() - started,\n\t\t\ttimedOut: false,\n\t\t};\n\t}\n};\n\nexport async function executeToolkitScript(args: {\n\tscript: ToolkitScript;\n\tscriptArgs: readonly string[];\n\tcwd: string;\n\ttimeoutMs?: number;\n\texecutor?: ScriptExecutor;\n}): Promise<ScriptExecution> {\n\tconst { command, argv } = buildScriptArgv(args.script, args.scriptArgs);\n\tconst executor = args.executor ?? spawnScriptExecutor;\n\treturn executor(command, argv, args.cwd, args.timeoutMs ?? 120_000);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"artifact-retrieve.d.ts","sourceRoot":"","sources":["../../../src/core/tools/artifact-retrieve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EACN,KAAK,qBAAqB,EAG1B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM7D,QAAA,MAAM,sBAAsB;;;;EAc1B,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE9E,MAAM,WAAW,2BAA2B;IAC3C,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,qBAAqB,CAAC;CAC5B;AAED,MAAM,WAAW,2BAA2B;IAC3C,mGAAmG;IACnG,aAAa,CAAC,EAAE,aAAa,CAAC;CAC9B;AAkCD,wBAAgB,oCAAoC,CACnD,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,2BAA2B,GACnC,cAAc,CAAC,OAAO,sBAAsB,EAAE,2BAA2B,GAAG,SAAS,CAAC,CA2ExF;AAED,wBAAgB,0BAA0B,CACzC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,2BAA2B,GACnC,SAAS,CAAC,OAAO,sBAAsB,CAAC,CAE1C","sourcesContent":["import type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { formatSize } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport {\n\ttype ArtifactRetrievalMode,\n\tDEFAULT_RETRIEVAL_MAX_LINES,\n\tretrieveArtifactSlice,\n} from \"../context/artifact-retrieval.ts\";\nimport type { ArtifactStore } from \"../context/context-artifacts.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { invalidArgText, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst ARTIFACT_ID_PREFIX = \"tool-output:\";\n\nconst artifactRetrieveSchema = Type.Object({\n\tartifactId: Type.String({\n\t\tdescription:\n\t\t\t\"Artifact id from a 'Full output: artifact tool-output:<id>' reference in a prior tool result. The 'tool-output:' prefix is optional.\",\n\t}),\n\tmode: Type.Optional(\n\t\tType.Union([Type.Literal(\"metadata\"), Type.Literal(\"head\"), Type.Literal(\"tail\")], {\n\t\t\tdescription:\n\t\t\t\t\"'metadata' for tool/path/size info only (no content); 'head' (default) for the first lines; 'tail' for the last lines.\",\n\t\t}),\n\t),\n\tmaxLines: Type.Optional(\n\t\tType.Number({ description: `Maximum lines to return for head/tail (default: ${DEFAULT_RETRIEVAL_MAX_LINES})` }),\n\t),\n});\n\nexport type ArtifactRetrieveToolInput = Static<typeof artifactRetrieveSchema>;\n\nexport interface ArtifactRetrieveToolDetails {\n\tfound: boolean;\n\tmode: ArtifactRetrievalMode;\n}\n\nexport interface ArtifactRetrieveToolOptions {\n\t/** Session-scoped artifact store to resolve ids against. Omitted: the tool reports unavailable. */\n\tartifactStore?: ArtifactStore;\n}\n\nfunction normalizeArtifactId(input: string): string {\n\treturn input.startsWith(ARTIFACT_ID_PREFIX) ? input.slice(ARTIFACT_ID_PREFIX.length) : input;\n}\n\nfunction formatMetadataText(ref: {\n\tkind: string;\n\ttoolName?: string;\n\tcommand?: string;\n\tpath?: string;\n\tbyteLength: number;\n\tlineCount?: number;\n\treproducible: boolean;\n}): string {\n\tconst lines = [\n\t\t`kind: ${ref.kind}`,\n\t\tref.toolName ? `tool: ${ref.toolName}` : undefined,\n\t\tref.command ? `command: ${ref.command}` : undefined,\n\t\tref.path ? `path: ${ref.path}` : undefined,\n\t\t`size: ${formatSize(ref.byteLength)}`,\n\t\tref.lineCount !== undefined ? `lines: ${ref.lineCount}` : undefined,\n\t\t`reproducible: ${ref.reproducible}`,\n\t];\n\treturn lines.filter((line): line is string => line !== undefined).join(\"\\n\");\n}\n\nfunction formatCall(args: { artifactId: string; mode?: string } | undefined, theme: Theme): string {\n\tconst artifactId = str(args?.artifactId);\n\tconst mode = args?.mode ?? \"head\";\n\tconst idText = artifactId === null ? invalidArgText(theme) : theme.fg(\"accent\", artifactId);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"artifact_retrieve\"))} ${idText}${theme.fg(\"toolOutput\", ` (${mode})`)}`;\n}\n\nexport function createArtifactRetrieveToolDefinition(\n\t_cwd: string,\n\toptions?: ArtifactRetrieveToolOptions,\n): ToolDefinition<typeof artifactRetrieveSchema, ArtifactRetrieveToolDetails | undefined> {\n\tconst artifactStore = options?.artifactStore;\n\treturn {\n\t\tname: \"artifact_retrieve\",\n\t\tlabel: \"artifact_retrieve\",\n\t\tdescription:\n\t\t\t\"Retrieve a bounded slice of a packed tool-output artifact by id, from a 'Full output: artifact tool-output:<id>' reference in a prior tool result. Returns metadata, or a bounded head/tail slice -- never the full raw payload in one call.\",\n\t\tpromptSnippet: \"Retrieve a bounded slice of a packed tool-output artifact\",\n\t\tparameters: artifactRetrieveSchema,\n\t\ttoolGroup: \"explore\",\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ artifactId, mode, maxLines }: { artifactId: string; mode?: ArtifactRetrievalMode; maxLines?: number },\n\t\t) {\n\t\t\tconst effectiveMode = mode ?? \"head\";\n\t\t\tif (!artifactStore) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"No artifact store is configured for this session.\" }],\n\t\t\t\t\tdetails: { found: false, mode: effectiveMode },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst result = retrieveArtifactSlice(artifactStore, {\n\t\t\t\tartifactId: normalizeArtifactId(artifactId),\n\t\t\t\tmode,\n\t\t\t\tmaxLines,\n\t\t\t});\n\n\t\t\tif (!result.found) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Artifact not found: ${artifactId} (${result.missingReason}). It may have been cleaned up, or the id may be incorrect.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { found: false, mode: effectiveMode },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (result.mode === \"metadata\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatMetadataText(result.ref) }],\n\t\t\t\t\tdetails: { found: true, mode: \"metadata\" },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet text = result.slice;\n\t\t\tif (result.truncation.truncated) {\n\t\t\t\ttext += `\\n\\n[Showing ${result.mode} ${result.truncation.outputLines} of ${result.truncation.totalLines} lines. Full artifact: ${formatSize(result.ref.byteLength)}. Retrieve again with a different mode/maxLines for another slice.]`;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\tdetails: { found: true, mode: result.mode },\n\t\t\t};\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatCall(args, theme));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst content = result.content.find((part) => part.type === \"text\");\n\t\t\tconst body = content && \"text\" in content ? content.text : \"\";\n\t\t\tconst lines = body.split(\"\\n\");\n\t\t\tconst maxLines = options.expanded ? lines.length : 20;\n\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\tconst remaining = lines.length - maxLines;\n\t\t\tlet rendered = displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\");\n\t\t\tif (remaining > 0) rendered += `\\n${theme.fg(\"muted\", `... (${remaining} more lines)`)}`;\n\t\t\ttext.setText(rendered);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createArtifactRetrieveTool(\n\tcwd: string,\n\toptions?: ArtifactRetrieveToolOptions,\n): AgentTool<typeof artifactRetrieveSchema> {\n\treturn wrapToolDefinition(createArtifactRetrieveToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"artifact-retrieve.d.ts","sourceRoot":"","sources":["../../../src/core/tools/artifact-retrieve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EACN,KAAK,qBAAqB,EAG1B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM7D,QAAA,MAAM,sBAAsB;;;;EAc1B,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE9E,MAAM,WAAW,2BAA2B;IAC3C,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,qBAAqB,CAAC;CAC5B;AAED,MAAM,WAAW,2BAA2B;IAC3C,mGAAmG;IACnG,aAAa,CAAC,EAAE,aAAa,CAAC;CAC9B;AAkCD,wBAAgB,oCAAoC,CACnD,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,2BAA2B,GACnC,cAAc,CAAC,OAAO,sBAAsB,EAAE,2BAA2B,GAAG,SAAS,CAAC,CA2ExF;AAED,wBAAgB,0BAA0B,CACzC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,E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,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;YACpE,MAAM,IAAI,GAAG,OAAO,IAAI,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YACtD,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC9C,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC;YAC1C,IAAI,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnF,IAAI,SAAS,GAAG,CAAC;gBAAE,QAAQ,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,SAAS,cAAc,CAAC,EAAE,CAAC;YACzF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACvB,OAAO,IAAI,CAAC;QAAA,CACZ;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,0BAA0B,CACzC,GAAW,EACX,OAAqC,EACM;IAC3C,OAAO,kBAAkB,CAAC,oCAAoC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAC9E","sourcesContent":["import type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { formatSize } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport {\n\ttype ArtifactRetrievalMode,\n\tDEFAULT_RETRIEVAL_MAX_LINES,\n\tretrieveArtifactSlice,\n} from \"../context/artifact-retrieval.ts\";\nimport type { ArtifactStore } from \"../context/context-artifacts.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { invalidArgText, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst ARTIFACT_ID_PREFIX = \"tool-output:\";\n\nconst artifactRetrieveSchema = Type.Object({\n\tartifactId: Type.String({\n\t\tdescription:\n\t\t\t\"Artifact id from a 'Full output: artifact tool-output:<id>' reference in a prior tool result. The 'tool-output:' prefix is optional.\",\n\t}),\n\tmode: Type.Optional(\n\t\tType.Union([Type.Literal(\"metadata\"), Type.Literal(\"head\"), Type.Literal(\"tail\")], {\n\t\t\tdescription:\n\t\t\t\t\"'metadata' for tool/path/size info only (no content); 'head' (default) for the first lines; 'tail' for the last lines.\",\n\t\t}),\n\t),\n\tmaxLines: Type.Optional(\n\t\tType.Number({ description: `Maximum lines to return for head/tail (default: ${DEFAULT_RETRIEVAL_MAX_LINES})` }),\n\t),\n});\n\nexport type ArtifactRetrieveToolInput = Static<typeof artifactRetrieveSchema>;\n\nexport interface ArtifactRetrieveToolDetails {\n\tfound: boolean;\n\tmode: ArtifactRetrievalMode;\n}\n\nexport interface ArtifactRetrieveToolOptions {\n\t/** Session-scoped artifact store to resolve ids against. Omitted: the tool reports unavailable. */\n\tartifactStore?: ArtifactStore;\n}\n\nfunction normalizeArtifactId(input: string): string {\n\treturn input.startsWith(ARTIFACT_ID_PREFIX) ? input.slice(ARTIFACT_ID_PREFIX.length) : input;\n}\n\nfunction formatMetadataText(ref: {\n\tkind: string;\n\ttoolName?: string;\n\tcommand?: string;\n\tpath?: string;\n\tbyteLength: number;\n\tlineCount?: number;\n\treproducible: boolean;\n}): string {\n\tconst lines = [\n\t\t`kind: ${ref.kind}`,\n\t\tref.toolName ? `tool: ${ref.toolName}` : undefined,\n\t\tref.command ? `command: ${ref.command}` : undefined,\n\t\tref.path ? `path: ${ref.path}` : undefined,\n\t\t`size: ${formatSize(ref.byteLength)}`,\n\t\tref.lineCount !== undefined ? `lines: ${ref.lineCount}` : undefined,\n\t\t`reproducible: ${ref.reproducible}`,\n\t];\n\treturn lines.filter((line): line is string => line !== undefined).join(\"\\n\");\n}\n\nfunction formatCall(args: { artifactId: string; mode?: string } | undefined, theme: Theme): string {\n\tconst artifactId = str(args?.artifactId);\n\tconst mode = args?.mode ?? \"head\";\n\tconst idText = artifactId === null ? invalidArgText(theme) : theme.fg(\"accent\", artifactId);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"artifact_retrieve\"))} ${idText}${theme.fg(\"toolOutput\", ` (${mode})`)}`;\n}\n\nexport function createArtifactRetrieveToolDefinition(\n\t_cwd: string,\n\toptions?: ArtifactRetrieveToolOptions,\n): ToolDefinition<typeof artifactRetrieveSchema, ArtifactRetrieveToolDetails | undefined> {\n\tconst artifactStore = options?.artifactStore;\n\treturn {\n\t\tname: \"artifact_retrieve\",\n\t\tlabel: \"artifact_retrieve\",\n\t\tdescription:\n\t\t\t\"Retrieve a bounded slice of a packed tool-output artifact by id, from a 'Full output: artifact tool-output:<id>' reference in a prior tool result. Returns metadata, or a bounded head/tail slice -- never the full raw payload in one call.\",\n\t\tpromptSnippet: \"Retrieve a bounded slice of a packed tool-output artifact\",\n\t\tparameters: artifactRetrieveSchema,\n\t\ttoolGroup: \"explore\",\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ artifactId, mode, maxLines }: { artifactId: string; mode?: ArtifactRetrievalMode; maxLines?: number },\n\t\t) {\n\t\t\tconst effectiveMode = mode ?? \"head\";\n\t\t\tif (!artifactStore) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"No artifact store is configured for this session.\" }],\n\t\t\t\t\tdetails: { found: false, mode: effectiveMode },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst result = retrieveArtifactSlice(artifactStore, {\n\t\t\t\tartifactId: normalizeArtifactId(artifactId),\n\t\t\t\tmode,\n\t\t\t\tmaxLines,\n\t\t\t});\n\n\t\t\tif (!result.found) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Artifact not found: ${artifactId} (${result.missingReason}). It may have been cleaned up, or the id may be incorrect.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { found: false, mode: effectiveMode },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (result.mode === \"metadata\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatMetadataText(result.ref) }],\n\t\t\t\t\tdetails: { found: true, mode: \"metadata\" },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet text = result.slice;\n\t\t\tif (result.truncation.truncated) {\n\t\t\t\ttext += `\\n\\n[Showing ${result.mode} ${result.truncation.outputLines} of ${result.truncation.totalLines} lines. Full artifact: ${formatSize(result.ref.byteLength)}. Retrieve again with a different mode/maxLines for another slice.]`;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\tdetails: { found: true, mode: result.mode },\n\t\t\t};\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatCall(args, theme));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst content = result.content.find((part) => part.type === \"text\");\n\t\t\tconst body = content && \"text\" in content ? content.text : \"\";\n\t\t\tconst lines = body.split(\"\\n\");\n\t\t\tconst maxLines = options.expanded ? lines.length : 20;\n\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\tconst remaining = lines.length - maxLines;\n\t\t\tlet rendered = displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\");\n\t\t\tif (remaining > 0) rendered += `\\n${theme.fg(\"muted\", `... (${remaining} more lines)`)}`;\n\t\t\ttext.setText(rendered);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createArtifactRetrieveTool(\n\tcwd: string,\n\toptions?: ArtifactRetrieveToolOptions,\n): AgentTool<typeof artifactRetrieveSchema> {\n\treturn wrapToolDefinition(createArtifactRetrieveToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"artifact-retrieve.js","sourceRoot":"","sources":["../../../src/core/tools/artifact-retrieve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAEN,2BAA2B,EAC3B,qBAAqB,GACrB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAE1C,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,CAAC;IAC1C,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;QACvB,WAAW,EACV,sIAAsI;KACvI,CAAC;IACF,IAAI,EAAE,IAAI,CAAC,QAAQ,CAClB,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE;QAClF,WAAW,EACV,wHAAwH;KACzH,CAAC,CACF;IACD,QAAQ,EAAE,IAAI,CAAC,QAAQ,CACtB,IAAI,CAAC,MAAM,CAA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AC;AAC/E,CAAC","sourcesContent":["import type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { formatSize } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport {\n\ttype ArtifactRetrievalMode,\n\tDEFAULT_RETRIEVAL_MAX_LINES,\n\tretrieveArtifactSlice,\n} from \"../context/artifact-retrieval.ts\";\nimport type { ArtifactStore } from \"../context/context-artifacts.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { invalidArgText, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst ARTIFACT_ID_PREFIX = \"tool-output:\";\n\nconst artifactRetrieveSchema = Type.Object({\n\tartifactId: Type.String({\n\t\tdescription:\n\t\t\t\"Artifact id from a 'Full output: artifact tool-output:<id>' reference in a prior tool result. The 'tool-output:' prefix is optional.\",\n\t}),\n\tmode: Type.Optional(\n\t\tType.Union([Type.Literal(\"metadata\"), Type.Literal(\"head\"), Type.Literal(\"tail\")], {\n\t\t\tdescription:\n\t\t\t\t\"'metadata' for tool/path/size info only (no content); 'head' (default) for the first lines; 'tail' for the last lines.\",\n\t\t}),\n\t),\n\tmaxLines: Type.Optional(\n\t\tType.Number({ description: `Maximum lines to return for head/tail (default: ${DEFAULT_RETRIEVAL_MAX_LINES})` }),\n\t),\n});\n\nexport type ArtifactRetrieveToolInput = Static<typeof artifactRetrieveSchema>;\n\nexport interface ArtifactRetrieveToolDetails {\n\tfound: boolean;\n\tmode: ArtifactRetrievalMode;\n}\n\nexport interface ArtifactRetrieveToolOptions {\n\t/** Session-scoped artifact store to resolve ids against. Omitted: the tool reports unavailable. */\n\tartifactStore?: ArtifactStore;\n}\n\nfunction normalizeArtifactId(input: string): string {\n\treturn input.startsWith(ARTIFACT_ID_PREFIX) ? input.slice(ARTIFACT_ID_PREFIX.length) : input;\n}\n\nfunction formatMetadataText(ref: {\n\tkind: string;\n\ttoolName?: string;\n\tcommand?: string;\n\tpath?: string;\n\tbyteLength: number;\n\tlineCount?: number;\n\treproducible: boolean;\n}): string {\n\tconst lines = [\n\t\t`kind: ${ref.kind}`,\n\t\tref.toolName ? `tool: ${ref.toolName}` : undefined,\n\t\tref.command ? `command: ${ref.command}` : undefined,\n\t\tref.path ? `path: ${ref.path}` : undefined,\n\t\t`size: ${formatSize(ref.byteLength)}`,\n\t\tref.lineCount !== undefined ? `lines: ${ref.lineCount}` : undefined,\n\t\t`reproducible: ${ref.reproducible}`,\n\t];\n\treturn lines.filter((line): line is string => line !== undefined).join(\"\\n\");\n}\n\nfunction formatCall(args: { artifactId: string; mode?: string } | undefined, theme: Theme): string {\n\tconst artifactId = str(args?.artifactId);\n\tconst mode = args?.mode ?? \"head\";\n\tconst idText = artifactId === null ? invalidArgText(theme) : theme.fg(\"accent\", artifactId);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"artifact_retrieve\"))} ${idText}${theme.fg(\"toolOutput\", ` (${mode})`)}`;\n}\n\nexport function createArtifactRetrieveToolDefinition(\n\t_cwd: string,\n\toptions?: ArtifactRetrieveToolOptions,\n): ToolDefinition<typeof artifactRetrieveSchema, ArtifactRetrieveToolDetails | undefined> {\n\tconst artifactStore = options?.artifactStore;\n\treturn {\n\t\tname: \"artifact_retrieve\",\n\t\tlabel: \"artifact_retrieve\",\n\t\tdescription:\n\t\t\t\"Retrieve a bounded slice of a packed tool-output artifact by id, from a 'Full output: artifact tool-output:<id>' reference in a prior tool result. Returns metadata, or a bounded head/tail slice -- never the full raw payload in one call.\",\n\t\tpromptSnippet: \"Retrieve a bounded slice of a packed tool-output artifact\",\n\t\tparameters: artifactRetrieveSchema,\n\t\ttoolGroup: \"explore\",\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ artifactId, mode, maxLines }: { artifactId: string; mode?: ArtifactRetrievalMode; maxLines?: number },\n\t\t) {\n\t\t\tconst effectiveMode = mode ?? \"head\";\n\t\t\tif (!artifactStore) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"No artifact store is configured for this session.\" }],\n\t\t\t\t\tdetails: { found: false, mode: effectiveMode },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst result = retrieveArtifactSlice(artifactStore, {\n\t\t\t\tartifactId: normalizeArtifactId(artifactId),\n\t\t\t\tmode,\n\t\t\t\tmaxLines,\n\t\t\t});\n\n\t\t\tif (!result.found) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Artifact not found: ${artifactId} (${result.missingReason}). It may have been cleaned up, or the id may be incorrect.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { found: false, mode: effectiveMode },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (result.mode === \"metadata\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatMetadataText(result.ref) }],\n\t\t\t\t\tdetails: { found: true, mode: \"metadata\" },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet text = result.slice;\n\t\t\tif (result.truncation.truncated) {\n\t\t\t\ttext += `\\n\\n[Showing ${result.mode} ${result.truncation.outputLines} of ${result.truncation.totalLines} lines. Full artifact: ${formatSize(result.ref.byteLength)}. Retrieve again with a different mode/maxLines for another slice.]`;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\tdetails: { found: true, mode: result.mode },\n\t\t\t};\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatCall(args, theme));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst content = result.content.find((part) => part.type === \"text\");\n\t\t\tconst body = content && \"text\" in content ? content.text : \"\";\n\t\t\tconst lines = body.split(\"\\n\");\n\t\t\tconst maxLines = options.expanded ? lines.length : 20;\n\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\tconst remaining = lines.length - maxLines;\n\t\t\tlet rendered = displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\");\n\t\t\tif (remaining > 0) rendered += `\\n${theme.fg(\"muted\", `... (${remaining} more lines)`)}`;\n\t\t\ttext.setText(rendered);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createArtifactRetrieveTool(\n\tcwd: string,\n\toptions?: ArtifactRetrieveToolOptions,\n): AgentTool<typeof artifactRetrieveSchema> {\n\treturn wrapToolDefinition(createArtifactRetrieveToolDefinition(cwd, options));\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { SessionManager } from "@caupulican/pi-agent-core/node";
2
2
  import { type Component } from "@caupulican/pi-tui";
3
3
  import { type Static, Type } from "typebox";
4
- import type { ClipboardInputHost } from "../../modes/interactive/clipboard-input.ts";
4
+ import { type ClipboardInputHost } from "../../modes/interactive/clipboard-input.ts";
5
5
  import type { Theme } from "../../modes/interactive/theme/theme.ts";
6
6
  import type { ArtifactStore } from "../context/context-artifacts.ts";
7
7
  import { type HumanInputAnswer, type HumanInputAnswerImage, type HumanInputPresentationResult, type HumanInputQuestion, type HumanInputStopReason } from "../human-input.ts";
@@ -68,8 +68,7 @@ export declare class AskQuestionDialog implements Component {
68
68
  private readonly createAnswerEditor;
69
69
  private readonly selections;
70
70
  private readonly cursors;
71
- private pendingClipboardImages;
72
- private clipboardImageCounter;
71
+ private readonly clipboardQueue;
73
72
  private currentIndex;
74
73
  private input;
75
74
  private inputError;
@@ -1 +1 @@
1
- {"version":3,"file":"ask-question.d.ts","sourceRoot":"","sources":["../../../src/core/tools/ask-question.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE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AAY;IAUpB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAgE9B;IAED,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,cAAc;IAiFtB,OAAO,CAAC,YAAY;IA4BpB,OAAO,CAAC,UAAU;IAelB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAsB9B;IAED,UAAU,IAAI,IAAI,CAGjB;CACD;AA6DD,wBAAgB,+BAA+B,CAAC,OAAO,GAAE,sBAA2B;;;;;;;;;;;kGAsGnF","sourcesContent":["import type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\ttype Component,\n\tCURSOR_MARKER,\n\tInput,\n\ttype Keybinding,\n\ttruncateToWidth,\n\tvisibleWidth,\n\twrapTextWithAnsi,\n} from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport type { ClipboardInputHost, PendingClipboardImage } from \"../../modes/interactive/clipboard-input.ts\";\nimport { formatKeyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ArtifactStore } from \"../context/context-artifacts.ts\";\nimport { defineTool } from \"../extensions/types.ts\";\nimport {\n\tbeginHumanInputRequest,\n\tcreateHumanInputRequest,\n\tformatHumanInputAnswerText,\n\ttype HumanInputAnswer,\n\ttype HumanInputAnswerImage,\n\ttype HumanInputPresentationResult,\n\ttype HumanInputQuestion,\n\ttype HumanInputSnapshot,\n\ttype HumanInputStopReason,\n\tresolveHumanInput,\n} from \"../human-input.ts\";\nimport type { KeybindingsManager } from \"../keybindings.ts\";\nimport type { SessionImageStore } from \"../session-image-store.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n} from \"./orchestration-panel.ts\";\n\nconst optionSchema = Type.Object(\n\t{\n\t\tlabel: Type.String({ minLength: 1, maxLength: 120, description: \"Concise option label.\" }),\n\t\tdescription: Type.String({\n\t\t\tminLength: 1,\n\t\t\tmaxLength: 500,\n\t\t\tdescription: \"Concrete consequence or tradeoff of choosing this option.\",\n\t\t}),\n\t},\n\t{ additionalProperties: false },\n);\n\nconst questionSchema = Type.Object(\n\t{\n\t\tid: Type.String({ minLength: 1, maxLength: 80, description: \"Stable unique answer identifier.\" }),\n\t\theader: Type.String({\n\t\t\tminLength: 1,\n\t\t\tmaxLength: 32,\n\t\t\tdescription: \"Short topic label used in question navigation.\",\n\t\t}),\n\t\tquestion: Type.String({ minLength: 1, maxLength: 1_000, description: \"The specific user-facing question.\" }),\n\t\toptions: Type.Array(optionSchema, {\n\t\t\tminItems: 2,\n\t\t\tmaxItems: 4,\n\t\t\tdescription: \"Two to four genuine choices. Other and Skip are supplied by the harness.\",\n\t\t}),\n\t\tmultiSelect: Type.Optional(Type.Boolean({ description: \"Allow more than one listed option to be selected.\" })),\n\t},\n\t{ additionalProperties: false },\n);\n\nconst askQuestionSchema = Type.Object(\n\t{\n\t\tquestions: Type.Array(questionSchema, {\n\t\t\tminItems: 1,\n\t\t\tmaxItems: 4,\n\t\t\tdescription: \"One to four independent questions presented in one interaction.\",\n\t\t}),\n\t},\n\t{ additionalProperties: false },\n);\n\nconst ANSWER_PREVIEW_CHARS = 240;\nconst ANSWER_EDITOR_VIEWPORT_LINES = 8;\n\nexport type AskQuestionToolInput = Static<typeof askQuestionSchema>;\nexport type AskQuestion = HumanInputQuestion;\nexport type AskQuestionAnswer = HumanInputAnswer;\nexport type AskQuestionAnswerImage = HumanInputAnswerImage;\nexport type AskQuestionStopReason = HumanInputStopReason;\n\nexport interface AskQuestionToolDetails {\n\tquestions: readonly AskQuestion[];\n\tanswers: readonly AskQuestionAnswer[];\n\tcancelled: boolean;\n\treason?: AskQuestionStopReason;\n\terror?: string;\n}\n\nexport interface AskQuestionToolOptions {\n\tname?: string;\n\tlabel?: string;\n\t/** Production session sink. When present, requests and answers are checkpointed before continuation. */\n\tsessionManager?: Pick<SessionManager, \"appendCustomEntry\">;\n\tartifactStore?: ArtifactStore;\n\tgetImageStore?: () => Pick<SessionImageStore, \"retainContent\"> | undefined;\n}\n\nexport interface AskQuestionClipboardOptions {\n\tautoResizeImages: boolean;\n\tblockImages: boolean;\n\tblockImagesReason?: string;\n\timageStore?: Pick<SessionImageStore, \"write\">;\n}\n\nexport type PasteClipboardImage = (host: ClipboardInputHost) => Promise<void>;\n\nexport interface AskQuestionAnswerEditor extends Component {\n\tfocused: boolean;\n\tonSubmit?: (text: string) => void;\n\thandleInput(data: string): void;\n\tgetText(): string;\n\tsetText(text: string): void;\n\tinsertTextAtCursor(text: string): void;\n}\n\nexport type CreateAskQuestionAnswerEditor = () => AskQuestionAnswerEditor;\n\nclass SingleLineAnswerEditor implements AskQuestionAnswerEditor {\n\tprivate readonly input = new Input();\n\tonSubmit?: (text: string) => void;\n\n\tconstructor() {\n\t\tthis.input.onSubmit = (value) => this.onSubmit?.(value);\n\t}\n\n\tget focused(): boolean {\n\t\treturn this.input.focused;\n\t}\n\n\tset focused(value: boolean) {\n\t\tthis.input.focused = value;\n\t}\n\n\tgetText(): string {\n\t\treturn this.input.getValue();\n\t}\n\n\tsetText(text: string): void {\n\t\tthis.input.setValue(\"\");\n\t\tthis.insertTextAtCursor(text);\n\t}\n\n\tinsertTextAtCursor(text: string): void {\n\t\tthis.input.handleInput(`\\x1b[200~${text}\\x1b[201~`);\n\t}\n\n\thandleInput(data: string): void {\n\t\tthis.input.handleInput(data);\n\t}\n\n\trender(width: number): string[] {\n\t\treturn this.input.render(width);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.input.invalidate();\n\t}\n}\n\ninterface QuestionSelection {\n\toptionIndexes: Set<number>;\n\tcustom?: string;\n\tskipped: boolean;\n}\n\ntype AskQuestionDialogResult = HumanInputPresentationResult;\n\nfunction normalizedIdentity(value: string): string {\n\treturn value.trim().toLowerCase();\n}\n\nfunction validateQuestions(questions: readonly AskQuestion[]): string | undefined {\n\tif (questions.length < 1 || questions.length > 4) return \"Provide between one and four questions.\";\n\tconst ids = new Set<string>();\n\tconst prompts = new Set<string>();\n\tfor (const question of questions) {\n\t\tif (!question.id.trim() || !question.header.trim() || !question.question.trim()) {\n\t\t\treturn \"Question ids, headers, and prompts must not be blank.\";\n\t\t}\n\t\tconst id = normalizedIdentity(question.id);\n\t\tconst prompt = normalizedIdentity(question.question);\n\t\tif (ids.has(id)) return `Question id '${question.id}' is duplicated.`;\n\t\tif (prompts.has(prompt)) return `Question '${question.question}' is duplicated.`;\n\t\tids.add(id);\n\t\tprompts.add(prompt);\n\t\tif (question.options.length < 2 || question.options.length > 4) {\n\t\t\treturn `Question '${question.header}' requires between two and four options.`;\n\t\t}\n\t\tconst labels = new Set<string>();\n\t\tfor (const option of question.options) {\n\t\t\tconst label = normalizedIdentity(option.label);\n\t\t\tif (!label || !option.description.trim()) {\n\t\t\t\treturn `Question '${question.header}' has a blank option label or description.`;\n\t\t\t}\n\t\t\tif (label === \"other\" || label === \"skip\") {\n\t\t\t\treturn `Question '${question.header}' must not define the reserved '${option.label}' option.`;\n\t\t\t}\n\t\t\tif (labels.has(label)) return `Question '${question.header}' has duplicate option '${option.label}'.`;\n\t\t\tlabels.add(label);\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction displayKeys(keybindings: KeybindingsManager, keybinding: Keybinding, limit = 2): string {\n\treturn formatKeyText(keybindings.getKeys(keybinding).slice(0, limit).join(\"/\"), { capitalize: true });\n}\n\nfunction answerFor(\n\tquestion: AskQuestion,\n\tselection: QuestionSelection,\n\tattachments: readonly PendingClipboardImage[] = [],\n): AskQuestionAnswer {\n\tconst images = selection.custom\n\t\t? attachments\n\t\t\t\t.filter((attachment) => selection.custom?.includes(attachment.label))\n\t\t\t\t.map((attachment) => ({ label: attachment.label, mimeType: attachment.content.mimeType }))\n\t\t: [];\n\treturn {\n\t\tid: question.id,\n\t\theader: question.header,\n\t\tquestion: question.question,\n\t\tselected: [...selection.optionIndexes]\n\t\t\t.sort((left, right) => left - right)\n\t\t\t.map((index) => question.options[index]?.label)\n\t\t\t.filter((label): label is string => label !== undefined),\n\t\t...(selection.custom ? { custom: selection.custom } : {}),\n\t\t...(images.length > 0 ? { images } : {}),\n\t\tskipped: selection.skipped,\n\t};\n}\n\nfunction previewAnswer(value: string): string {\n\tif (value.length <= ANSWER_PREVIEW_CHARS) return value;\n\treturn `${value.slice(0, ANSWER_PREVIEW_CHARS)}… (${value.length} characters)`;\n}\n\nfunction isResolved(selection: QuestionSelection): boolean {\n\treturn selection.skipped || selection.optionIndexes.size > 0 || selection.custom !== undefined;\n}\n\n/** Native focused question interaction shared by every provider-facing ask_question call. */\nexport class AskQuestionDialog implements Component {\n\tprivate readonly questions: readonly AskQuestion[];\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly finish: (result: AskQuestionDialogResult) => void;\n\tprivate readonly clipboard: AskQuestionClipboardOptions;\n\tprivate readonly pasteClipboardImage: PasteClipboardImage;\n\tprivate readonly createAnswerEditor: CreateAskQuestionAnswerEditor;\n\tprivate readonly selections: QuestionSelection[];\n\tprivate readonly cursors: number[];\n\tprivate pendingClipboardImages: PendingClipboardImage[] = [];\n\tprivate clipboardImageCounter = 0;\n\tprivate currentIndex = 0;\n\tprivate input: AskQuestionAnswerEditor | undefined;\n\tprivate inputError: string | undefined;\n\tprivate inputStatus: string | undefined;\n\tprivate pasteInFlight = false;\n\tprivate submitAfterPaste = false;\n\tprivate cachedWidth: number | undefined;\n\tprivate cachedLines: string[] | undefined;\n\tprivate settled = false;\n\n\tconstructor(options: {\n\t\tquestions: readonly AskQuestion[];\n\t\ttheme: Theme;\n\t\tkeybindings: KeybindingsManager;\n\t\trequestRender: () => void;\n\t\tfinish: (result: AskQuestionDialogResult) => void;\n\t\tclipboard?: AskQuestionClipboardOptions;\n\t\tpasteClipboardImage?: PasteClipboardImage;\n\t\tcreateAnswerEditor?: CreateAskQuestionAnswerEditor;\n\t}) {\n\t\tthis.questions = options.questions;\n\t\tthis.theme = options.theme;\n\t\tthis.keybindings = options.keybindings;\n\t\tthis.requestRender = options.requestRender;\n\t\tthis.finish = options.finish;\n\t\tthis.clipboard = options.clipboard ?? { autoResizeImages: true, blockImages: false };\n\t\tthis.pasteClipboardImage =\n\t\t\toptions.pasteClipboardImage ??\n\t\t\t(async (host) => {\n\t\t\t\thost.showWarning(\"Clipboard paste is unavailable in this UI host.\");\n\t\t\t});\n\t\tthis.createAnswerEditor = options.createAnswerEditor ?? (() => new SingleLineAnswerEditor());\n\t\tthis.selections = options.questions.map(() => ({ optionIndexes: new Set(), skipped: false }));\n\t\tthis.cursors = options.questions.map(() => 0);\n\t}\n\n\tprivate refresh(): void {\n\t\tthis.invalidate();\n\t\tthis.requestRender();\n\t}\n\n\tprivate result(cancelled: boolean, reason?: AskQuestionStopReason): AskQuestionDialogResult {\n\t\tconst answers = this.questions.map((question, index) =>\n\t\t\tanswerFor(question, this.selections[index]!, this.pendingClipboardImages),\n\t\t);\n\t\tconst referencedLabels = new Set(answers.flatMap((answer) => answer.images?.map((image) => image.label) ?? []));\n\t\treturn {\n\t\t\tanswers,\n\t\t\tcancelled,\n\t\t\timageContents: cancelled\n\t\t\t\t? []\n\t\t\t\t: this.pendingClipboardImages\n\t\t\t\t\t\t.filter((attachment) => referencedLabels.has(attachment.label))\n\t\t\t\t\t\t.map((attachment) => attachment.content),\n\t\t\t...(reason ? { reason } : {}),\n\t\t};\n\t}\n\n\tprivate complete(result: AskQuestionDialogResult): void {\n\t\tif (this.settled) return;\n\t\tthis.settled = true;\n\t\tif (this.input) this.input.focused = false;\n\t\tthis.finish(result);\n\t}\n\n\tcancel(reason: Extract<AskQuestionStopReason, \"user_cancelled\" | \"interrupted\">): void {\n\t\tthis.complete(this.result(true, reason));\n\t}\n\n\tprivate move(delta: -1 | 1): void {\n\t\tconst lastIndex = this.questions.length;\n\t\tthis.currentIndex = Math.max(0, Math.min(lastIndex, this.currentIndex + delta));\n\t\tthis.refresh();\n\t}\n\n\tprivate advanceAfterSingleSelection(): void {\n\t\tif (this.questions.length === 1) {\n\t\t\tthis.complete(this.result(false));\n\t\t\treturn;\n\t\t}\n\t\tthis.currentIndex = Math.min(this.questions.length, this.currentIndex + 1);\n\t\tthis.refresh();\n\t}\n\n\tprivate beginCustomAnswer(): void {\n\t\tconst questionIndex = this.currentIndex;\n\t\tconst question = this.questions[questionIndex];\n\t\tconst selection = this.selections[questionIndex];\n\t\tif (!question || !selection) return;\n\t\tconst input = this.createAnswerEditor();\n\t\tthis.inputError = undefined;\n\t\tthis.inputStatus = undefined;\n\t\tinput.focused = true;\n\t\tif (selection.custom) input.setText(selection.custom);\n\t\tinput.onSubmit = (value) => {\n\t\t\tconst answer = value.trim();\n\t\t\tif (!answer) return;\n\t\t\tselection.custom = answer;\n\t\t\tselection.skipped = false;\n\t\t\tinput.focused = false;\n\t\t\tthis.input = undefined;\n\t\t\tif (question.multiSelect) this.refresh();\n\t\t\telse this.advanceAfterSingleSelection();\n\t\t};\n\t\tthis.input = input;\n\t\tthis.refresh();\n\t}\n\n\tprivate async pasteIntoCustomAnswer(): Promise<void> {\n\t\tconst input = this.input;\n\t\tif (!input || this.pasteInFlight) return;\n\t\tthis.pasteInFlight = true;\n\t\tthis.inputError = undefined;\n\t\tthis.inputStatus = \"Reading clipboard…\";\n\t\tthis.refresh();\n\t\tlet reported = false;\n\t\tconst self = this;\n\t\tconst host: ClipboardInputHost = {\n\t\t\tget pendingClipboardImages() {\n\t\t\t\treturn self.pendingClipboardImages;\n\t\t\t},\n\t\t\tset pendingClipboardImages(value) {\n\t\t\t\tself.pendingClipboardImages = value;\n\t\t\t},\n\t\t\tget clipboardImageCounter() {\n\t\t\t\treturn self.clipboardImageCounter;\n\t\t\t},\n\t\t\tset clipboardImageCounter(value) {\n\t\t\t\tself.clipboardImageCounter = value;\n\t\t\t},\n\t\t\teditor: {\n\t\t\t\thandleInput: (data) => input.handleInput(data),\n\t\t\t\tinsertTextAtCursor: (text) => input.insertTextAtCursor(text),\n\t\t\t},\n\t\t\tui: { requestRender: () => this.refresh() },\n\t\t\tautoResizeImages: this.clipboard.autoResizeImages,\n\t\t\tblockImages: this.clipboard.blockImages,\n\t\t\tblockImagesReason: this.clipboard.blockImagesReason,\n\t\t\timageStore: this.clipboard.imageStore,\n\t\t\tshowStatus: (message) => {\n\t\t\t\treported = true;\n\t\t\t\tthis.inputStatus = message;\n\t\t\t\tthis.inputError = undefined;\n\t\t\t},\n\t\t\tshowWarning: (message) => {\n\t\t\t\treported = true;\n\t\t\t\tthis.inputStatus = undefined;\n\t\t\t\tthis.inputError = message;\n\t\t\t\tthis.refresh();\n\t\t\t},\n\t\t};\n\t\ttry {\n\t\t\tawait this.pasteClipboardImage(host);\n\t\t} finally {\n\t\t\tthis.pasteInFlight = false;\n\t\t\tconst shouldSubmit = this.submitAfterPaste && this.input === input && !this.settled;\n\t\t\tthis.submitAfterPaste = false;\n\t\t\tif (!reported) this.inputStatus = undefined;\n\t\t\tif (shouldSubmit) input.onSubmit?.(input.getText());\n\t\t\tif (this.input === input && !this.settled) this.refresh();\n\t\t}\n\t}\n\n\tprivate selectCurrent(): void {\n\t\tconst question = this.questions[this.currentIndex];\n\t\tconst selection = this.selections[this.currentIndex];\n\t\tif (!question || !selection) return;\n\t\tconst cursor = this.cursors[this.currentIndex] ?? 0;\n\t\tif (cursor === question.options.length) {\n\t\t\tthis.beginCustomAnswer();\n\t\t\treturn;\n\t\t}\n\t\tif (cursor === question.options.length + 1) {\n\t\t\tselection.optionIndexes.clear();\n\t\t\tselection.custom = undefined;\n\t\t\tselection.skipped = true;\n\t\t\tthis.advanceAfterSingleSelection();\n\t\t\treturn;\n\t\t}\n\t\tselection.skipped = false;\n\t\tif (question.multiSelect) {\n\t\t\tif (selection.optionIndexes.has(cursor)) selection.optionIndexes.delete(cursor);\n\t\t\telse selection.optionIndexes.add(cursor);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tselection.optionIndexes.clear();\n\t\tselection.optionIndexes.add(cursor);\n\t\tselection.custom = undefined;\n\t\tthis.advanceAfterSingleSelection();\n\t}\n\n\tprivate submitReview(): void {\n\t\tconst unresolved = this.selections.findIndex((selection) => !isResolved(selection));\n\t\tif (unresolved >= 0) {\n\t\t\tthis.currentIndex = unresolved;\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.complete(this.result(false));\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.settled) return;\n\t\tif (this.input) {\n\t\t\tif (this.keybindings.matches(data, \"tui.select.cancel\")) {\n\t\t\t\tthis.submitAfterPaste = false;\n\t\t\t\tthis.input.focused = false;\n\t\t\t\tthis.input = undefined;\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (this.keybindings.matches(data, \"app.clipboard.pasteImage\")) {\n\t\t\t\tvoid this.pasteIntoCustomAnswer();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (this.pasteInFlight && this.keybindings.matches(data, \"tui.input.submit\")) {\n\t\t\t\tthis.submitAfterPaste = true;\n\t\t\t\tthis.inputStatus = \"Finishing clipboard paste…\";\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst input = this.input;\n\t\t\tthis.inputError = undefined;\n\t\t\tthis.inputStatus = undefined;\n\t\t\tinput.handleInput(data);\n\t\t\tif (this.input === input) this.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.cancel(\"user_cancelled\");\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"app.question.previous\")) {\n\t\t\tthis.move(-1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"app.question.next\")) {\n\t\t\tthis.move(1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.currentIndex === this.questions.length) {\n\t\t\tif (this.keybindings.matches(data, \"tui.select.confirm\")) this.submitReview();\n\t\t\treturn;\n\t\t}\n\t\tconst question = this.questions[this.currentIndex];\n\t\tif (!question) return;\n\t\tif (this.keybindings.matches(data, \"tui.select.up\")) {\n\t\t\tthis.cursors[this.currentIndex] = Math.max(0, (this.cursors[this.currentIndex] ?? 0) - 1);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.down\")) {\n\t\t\tthis.cursors[this.currentIndex] = Math.min(\n\t\t\t\tquestion.options.length + 1,\n\t\t\t\t(this.cursors[this.currentIndex] ?? 0) + 1,\n\t\t\t);\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tthis.keybindings.matches(data, \"tui.select.confirm\") ||\n\t\t\t(question.multiSelect && this.keybindings.matches(data, \"app.question.toggle\"))\n\t\t) {\n\t\t\tthis.selectCurrent();\n\t\t}\n\t}\n\n\tprivate addWrapped(lines: string[], text: string, width: number, indent = \"\"): void {\n\t\tconst contentWidth = Math.max(1, width - visibleWidth(indent));\n\t\tfor (const line of wrapTextWithAnsi(text, contentWidth)) {\n\t\t\tlines.push(truncateToWidth(`${indent}${line}`, width, \"\"));\n\t\t}\n\t}\n\n\tprivate renderProgress(lines: string[], width: number): void {\n\t\tif (this.questions.length === 1 && !this.questions[0]?.multiSelect) return;\n\t\tconst chips = this.questions.map((question, index) => {\n\t\t\tconst resolved = isResolved(this.selections[index]!);\n\t\t\tconst text = ` ${resolved ? \"●\" : \"○\"} ${question.header} `;\n\t\t\treturn index === this.currentIndex\n\t\t\t\t? this.theme.bg(\"selectedBg\", this.theme.fg(\"text\", text))\n\t\t\t\t: this.theme.fg(resolved ? \"success\" : \"muted\", text);\n\t\t});\n\t\tconst review = \" Review \";\n\t\tchips.push(\n\t\t\tthis.currentIndex === this.questions.length\n\t\t\t\t? this.theme.bg(\"selectedBg\", this.theme.fg(\"text\", review))\n\t\t\t\t: this.theme.fg(\"dim\", review),\n\t\t);\n\t\tlines.push(truncateToWidth(chips.join(\" \"), width, \"\"));\n\t\tlines.push(\"\");\n\t}\n\n\tprivate renderQuestion(lines: string[], width: number, question: AskQuestion): void {\n\t\tconst questionIndex = this.currentIndex;\n\t\tconst selection = this.selections[questionIndex]!;\n\t\tconst cursor = this.cursors[questionIndex] ?? 0;\n\t\tthis.addWrapped(lines, this.theme.bold(question.question), width);\n\t\tif (question.multiSelect) {\n\t\t\tlines.push(this.theme.fg(\"muted\", \"Choose one or more, then continue to review.\"));\n\t\t}\n\t\tlines.push(\"\");\n\n\t\tquestion.options.forEach((option, index) => {\n\t\t\tconst active = index === cursor;\n\t\t\tconst chosen = selection.optionIndexes.has(index);\n\t\t\tconst prefix = `${active ? \"›\" : \" \"} ${chosen ? \"●\" : \"○\"} `;\n\t\t\tconst label = `${prefix}${option.label}`;\n\t\t\tlines.push(\n\t\t\t\ttruncateToWidth(\n\t\t\t\t\tactive ? this.theme.bg(\"selectedBg\", this.theme.fg(\"text\", ` ${label} `)) : this.theme.fg(\"text\", label),\n\t\t\t\t\twidth,\n\t\t\t\t\t\"\",\n\t\t\t\t),\n\t\t\t);\n\t\t\tthis.addWrapped(lines, this.theme.fg(\"muted\", option.description), width, \" \");\n\t\t});\n\n\t\tconst otherIndex = question.options.length;\n\t\tconst otherActive = cursor === otherIndex;\n\t\tconst otherLabel = selection.custom ? `Other: ${previewAnswer(selection.custom)}` : \"Other\";\n\t\tconst otherText = `${otherActive ? \"›\" : \" \"} ${selection.custom ? \"●\" : \"+\"} ${otherLabel}`;\n\t\tlines.push(\n\t\t\ttruncateToWidth(\n\t\t\t\totherActive\n\t\t\t\t\t? this.theme.bg(\"selectedBg\", this.theme.fg(\"text\", ` ${otherText} `))\n\t\t\t\t\t: this.theme.fg(\"muted\", otherText),\n\t\t\t\twidth,\n\t\t\t\t\"\",\n\t\t\t),\n\t\t);\n\t\tconst skipActive = cursor === otherIndex + 1;\n\t\tconst skipText = `${skipActive ? \"›\" : \" \"} ${selection.skipped ? \"●\" : \"–\"} Skip`;\n\t\tlines.push(\n\t\t\ttruncateToWidth(\n\t\t\t\tskipActive\n\t\t\t\t\t? this.theme.bg(\"selectedBg\", this.theme.fg(\"text\", ` ${skipText} `))\n\t\t\t\t\t: this.theme.fg(\"dim\", skipText),\n\t\t\t\twidth,\n\t\t\t\t\"\",\n\t\t\t),\n\t\t);\n\n\t\tif (this.input) {\n\t\t\tlines.push(\"\");\n\t\t\tlines.push(this.theme.fg(\"muted\", \"Your answer\"));\n\t\t\tconst renderedInput = this.input.render(Math.max(4, width - 2));\n\t\t\tconst cursorLine = Math.max(\n\t\t\t\t0,\n\t\t\t\trenderedInput.findIndex((line) => line.includes(CURSOR_MARKER)),\n\t\t\t);\n\t\t\tconst viewportStart = Math.max(\n\t\t\t\t0,\n\t\t\t\tMath.min(\n\t\t\t\t\tcursorLine - Math.floor(ANSWER_EDITOR_VIEWPORT_LINES / 2),\n\t\t\t\t\trenderedInput.length - ANSWER_EDITOR_VIEWPORT_LINES,\n\t\t\t\t),\n\t\t\t);\n\t\t\tconst visibleInput = renderedInput.slice(viewportStart, viewportStart + ANSWER_EDITOR_VIEWPORT_LINES);\n\t\t\tif (viewportStart > 0) {\n\t\t\t\tlines.push(this.theme.fg(\"dim\", ` ↑ ${viewportStart} earlier line${viewportStart === 1 ? \"\" : \"s\"}`));\n\t\t\t}\n\t\t\tfor (const inputLine of visibleInput) {\n\t\t\t\tlines.push(truncateToWidth(` ${inputLine}`, width, \"\"));\n\t\t\t}\n\t\t\tconst remainingLines = renderedInput.length - viewportStart - visibleInput.length;\n\t\t\tif (remainingLines > 0) {\n\t\t\t\tlines.push(this.theme.fg(\"dim\", ` ↓ ${remainingLines} later line${remainingLines === 1 ? \"\" : \"s\"}`));\n\t\t\t}\n\t\t\tif (this.inputError) this.addWrapped(lines, this.theme.fg(\"warning\", this.inputError), width, \" \");\n\t\t\tif (this.inputStatus) this.addWrapped(lines, this.theme.fg(\"success\", this.inputStatus), width, \" \");\n\t\t}\n\t}\n\n\tprivate renderReview(lines: string[], width: number): void {\n\t\tlines.push(this.theme.bold(\"Review your answers\"));\n\t\tlines.push(\"\");\n\t\tlet unresolved = 0;\n\t\tthis.questions.forEach((question, index) => {\n\t\t\tconst answer = answerFor(question, this.selections[index]!);\n\t\t\tconst values = [...answer.selected, ...(answer.custom ? [previewAnswer(answer.custom)] : [])];\n\t\t\tconst value = answer.skipped ? \"Skipped\" : values.length > 0 ? values.join(\", \") : \"Unanswered\";\n\t\t\tif (!isResolved(this.selections[index]!)) unresolved++;\n\t\t\tthis.addWrapped(\n\t\t\t\tlines,\n\t\t\t\t`${this.theme.fg(\"muted\", `${question.header}:`)} ${this.theme.fg(value === \"Unanswered\" ? \"warning\" : \"text\", value)}`,\n\t\t\t\twidth,\n\t\t\t);\n\t\t});\n\t\tif (unresolved > 0) {\n\t\t\tlines.push(\"\");\n\t\t\tthis.addWrapped(\n\t\t\t\tlines,\n\t\t\t\tthis.theme.fg(\n\t\t\t\t\t\"warning\",\n\t\t\t\t\t`${unresolved} unanswered. Answer or explicitly skip each question before submitting.`,\n\t\t\t\t),\n\t\t\t\twidth,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate renderHelp(lines: string[], width: number): void {\n\t\tconst cancel = displayKeys(this.keybindings, \"tui.select.cancel\", 1);\n\t\tlet help: string;\n\t\tif (this.input) {\n\t\t\thelp = `${displayKeys(this.keybindings, \"tui.input.submit\", 1)} save · ${displayKeys(this.keybindings, \"tui.input.newLine\", 1)} newline · ${displayKeys(this.keybindings, \"app.clipboard.pasteImage\", 1)} paste · ${cancel} back`;\n\t\t} else if (this.currentIndex === this.questions.length) {\n\t\t\thelp = `${displayKeys(this.keybindings, \"tui.select.confirm\", 1)} submit · ${displayKeys(this.keybindings, \"app.question.previous\")} back · ${cancel} cancel`;\n\t\t} else if (this.questions[this.currentIndex]?.multiSelect) {\n\t\t\thelp = `${displayKeys(this.keybindings, \"tui.select.up\")}/${displayKeys(this.keybindings, \"tui.select.down\")} move · ${displayKeys(this.keybindings, \"app.question.toggle\", 1)}/${displayKeys(this.keybindings, \"tui.select.confirm\", 1)} toggle · ${displayKeys(this.keybindings, \"app.question.next\")} next · ${cancel} cancel`;\n\t\t} else {\n\t\t\thelp = `${displayKeys(this.keybindings, \"tui.select.up\")}/${displayKeys(this.keybindings, \"tui.select.down\")} move · ${displayKeys(this.keybindings, \"tui.select.confirm\", 1)} select · ${cancel} cancel`;\n\t\t}\n\t\tthis.addWrapped(lines, this.theme.fg(\"dim\", help), width);\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.cachedWidth === width && this.cachedLines) return this.cachedLines;\n\t\tconst safeWidth = Math.max(1, width);\n\t\tconst lines: string[] = [];\n\t\tconst header = this.currentIndex === this.questions.length ? \"review\" : this.questions[this.currentIndex]?.header;\n\t\tlines.push(\n\t\t\ttruncateToWidth(\n\t\t\t\t`${this.theme.fg(\"accent\", \"?\")} ${this.theme.bold(header ?? \"question\")} ${this.theme.fg(\"dim\", `${Math.min(this.currentIndex + 1, this.questions.length)}/${this.questions.length}`)}`,\n\t\t\t\tsafeWidth,\n\t\t\t\t\"\",\n\t\t\t),\n\t\t);\n\t\tlines.push(\"\");\n\t\tthis.renderProgress(lines, safeWidth);\n\t\tconst question = this.questions[this.currentIndex];\n\t\tif (question) this.renderQuestion(lines, safeWidth, question);\n\t\telse this.renderReview(lines, safeWidth);\n\t\tlines.push(\"\");\n\t\tthis.renderHelp(lines, safeWidth);\n\t\tthis.cachedWidth = width;\n\t\tthis.cachedLines = lines.map((line) => truncateToWidth(line, safeWidth, \"\"));\n\t\treturn this.cachedLines;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n}\n\nfunction questionPanelModel(details: AskQuestionToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn { label: \"question\", status: \"error\", emptyText: \"No structured answer was retained.\" };\n\t}\n\tif (details.reason === \"ui_unavailable\" || details.reason === \"invalid_questions\") {\n\t\treturn {\n\t\t\tlabel: \"question\",\n\t\t\taction: \"unavailable\",\n\t\t\tstatus: \"error\",\n\t\t\temptyText: details.error ?? \"User input is unavailable.\",\n\t\t};\n\t}\n\tconst rows = details.questions.map((question) => {\n\t\tconst answer = details.answers.find((candidate) => candidate.id === question.id);\n\t\tconst values = answer ? [...answer.selected, ...(answer.custom ? [previewAnswer(answer.custom)] : [])] : [];\n\t\tconst imageCount = answer?.images?.length ?? 0;\n\t\treturn {\n\t\t\tstatus: details.cancelled\n\t\t\t\t? (\"cancelled\" as const)\n\t\t\t\t: answer?.skipped\n\t\t\t\t\t? (\"cancelled\" as const)\n\t\t\t\t\t: (\"completed\" as const),\n\t\t\tlabel: question.header,\n\t\t\tmeta: details.cancelled\n\t\t\t\t? [details.reason === \"interrupted\" ? \"interrupted\" : \"cancelled\"]\n\t\t\t\t: answer?.skipped\n\t\t\t\t\t? [\"skipped\"]\n\t\t\t\t\t: [\n\t\t\t\t\t\t\tvalues.length > 1 ? `${values.length} selected` : undefined,\n\t\t\t\t\t\t\timageCount > 0 ? `${imageCount} image${imageCount === 1 ? \"\" : \"s\"}` : undefined,\n\t\t\t\t\t\t].filter((value): value is string => value !== undefined),\n\t\t\tdetails: values.length > 0 ? [`answer: ${values.join(\", \")}`] : undefined,\n\t\t};\n\t});\n\tconst skipped = details.answers.filter((answer) => answer.skipped).length;\n\treturn {\n\t\tlabel: \"question\",\n\t\taction: details.cancelled ? \"cancelled\" : \"answered\",\n\t\tstatus: details.cancelled ? \"warning\" : \"success\",\n\t\tsummary: details.cancelled\n\t\t\t? undefined\n\t\t\t: [`${details.answers.length - skipped} answered`, skipped ? `${skipped} skipped` : undefined].filter(\n\t\t\t\t\t(value): value is string => value !== undefined,\n\t\t\t\t),\n\t\trows,\n\t};\n}\n\nfunction stoppedResult(\n\tquestions: readonly AskQuestion[],\n\treason: AskQuestionStopReason,\n\terror?: string,\n): { content: Array<{ type: \"text\"; text: string }>; details: AskQuestionToolDetails } {\n\treturn {\n\t\tcontent: [{ type: \"text\", text: error ?? `ask_question stopped: ${reason}` }],\n\t\tdetails: { questions, answers: [], cancelled: true, reason, ...(error ? { error } : {}) },\n\t};\n}\n\nexport function createAskQuestionToolDefinition(options: AskQuestionToolOptions = {}) {\n\tconst name = options.name ?? \"ask_question\";\n\treturn defineTool<typeof askQuestionSchema, AskQuestionToolDetails>({\n\t\tname,\n\t\tlabel: options.label ?? \"Ask Question\",\n\t\tdescription:\n\t\t\t\"Ask the human owner one to four concise questions when a missing choice materially changes the work. The harness supplies Other and Skip choices, supports single- and multi-select answers, and returns a typed answer set.\",\n\t\tpromptSnippet: \"Ask the human owner for a consequential missing choice through the native interactive UI.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use this tool only when a missing owner choice materially changes the result, authority, risk, or acceptance criteria; otherwise proceed with a safe stated assumption.\",\n\t\t\t\"Batch independent questions into one call, with at most four questions and two to four genuine options each.\",\n\t\t\t\"Make every option label concise and describe its concrete consequence or tradeoff. Do not add Other, Skip, None, or filler options; the harness supplies Other and Skip.\",\n\t\t\t\"Set multiSelect only when choices are genuinely independent. Never use a question to delegate a decision already fixed by an owner-authored profile or policy.\",\n\t\t\t\"Respect skipped or cancelled input as owner intent. Do not immediately repeat the same question; proceed safely or report the unresolved boundary.\",\n\t\t],\n\t\tparameters: askQuestionSchema,\n\t\texecutionMode: \"sequential\",\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) {\n\t\t\t\treturn new OrchestrationPanelComponent(theme, {\n\t\t\t\t\tlabel: \"question\",\n\t\t\t\t\taction: \"waiting for you\",\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, questionPanelModel(result.details), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input, signal, _onUpdate, ctx) {\n\t\t\tconst validationError = validateQuestions(input.questions);\n\t\t\tif (validationError) return stoppedResult(input.questions, \"invalid_questions\", validationError);\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\treturn stoppedResult(input.questions, \"ui_unavailable\", \"ask_question requires interactive UI.\");\n\t\t\t}\n\t\t\tif (signal?.aborted) return stoppedResult(input.questions, \"interrupted\");\n\n\t\t\tconst request = createHumanInputRequest({\n\t\t\t\tsource: \"tool\",\n\t\t\t\ttoolCallId: _toolCallId,\n\t\t\t\ttoolName: name,\n\t\t\t\tquestions: input.questions,\n\t\t\t\tacceptsImages: ctx.model?.input.includes(\"image\") ?? false,\n\t\t\t});\n\t\t\tif (options.sessionManager) beginHumanInputRequest(options.sessionManager, request);\n\t\t\tconst resolved = options.sessionManager\n\t\t\t\t? await resolveHumanInput({\n\t\t\t\t\t\tsessionManager: options.sessionManager,\n\t\t\t\t\t\trequest,\n\t\t\t\t\t\tpresent: (presentation, dialogOptions) => ctx.ui.askQuestions(presentation, dialogOptions),\n\t\t\t\t\t\tartifactStore: options.artifactStore,\n\t\t\t\t\t\tgetImageStore: options.getImageStore,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t})\n\t\t\t\t: await (async (): Promise<{\n\t\t\t\t\t\tsnapshot: HumanInputSnapshot;\n\t\t\t\t\t\timageContents: AskQuestionDialogResult[\"imageContents\"];\n\t\t\t\t\t}> => {\n\t\t\t\t\t\tconst result = await ctx.ui.askQuestions(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\trequestId: request.requestId,\n\t\t\t\t\t\t\t\tquestions: request.questions,\n\t\t\t\t\t\t\t\tacceptsImages: request.acceptsImages,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tsnapshot: {\n\t\t\t\t\t\t\t\trequest,\n\t\t\t\t\t\t\t\tstatus: result.cancelled ? \"cancelled\" : \"answered\",\n\t\t\t\t\t\t\t\tanswers: result.answers,\n\t\t\t\t\t\t\t\t...(result.reason ? { reason: result.reason } : {}),\n\t\t\t\t\t\t\t\tupdatedAt: new Date().toISOString(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\timageContents: result.imageContents,\n\t\t\t\t\t\t};\n\t\t\t\t\t})();\n\n\t\t\tconst details: AskQuestionToolDetails = {\n\t\t\t\tquestions: input.questions,\n\t\t\t\tanswers: resolved.snapshot.answers,\n\t\t\t\tcancelled: resolved.snapshot.status === \"cancelled\",\n\t\t\t\t...(resolved.snapshot.reason ? { reason: resolved.snapshot.reason } : {}),\n\t\t\t};\n\t\t\tif (details.cancelled) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: formatHumanInputAnswerText(resolved.snapshot) }],\n\t\t\t\t\tdetails,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{ type: \"text\" as const, text: formatHumanInputAnswerText(resolved.snapshot) },\n\t\t\t\t\t...resolved.imageContents,\n\t\t\t\t],\n\t\t\t\tdetails,\n\t\t\t};\n\t\t},\n\t});\n}\n"]}
1
+ {"version":3,"file":"ask-question.d.ts","sourceRoot":"","sources":["../../../src/core/tools/ask-question.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACN,KAAK,SAAS,EAOd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAEN,KAAK,kBAAkB,EAGvB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EAIN,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,kBAAkB,EAEvB,KAAK,oBAA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