@caupulican/pi-adaptative 0.81.42 → 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 (1406) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/bun/cli.d.ts.map +1 -1
  3. package/dist/bun/cli.js.map +1 -1
  4. package/dist/bun/register-bedrock.d.ts.map +1 -1
  5. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  6. package/dist/bun/restore-sandbox-env.js.map +1 -1
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +52 -49
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +62 -57
  13. package/dist/bundled-resources/prompts/skillify.md +1 -1
  14. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/fs.py +16 -19
  15. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/search.py +12 -26
  16. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/strings.py +15 -121
  17. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +52 -79
  18. package/dist/bundled-resources/runtimes/pi-shell-engine/escapes.py +70 -0
  19. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +110 -61
  20. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +106 -23
  21. package/dist/bundled-resources/runtimes/pi-shell-engine/paths.py +10 -0
  22. package/dist/bundled-resources/runtimes/pi-shell-engine/proc.py +12 -4
  23. package/dist/bundled-resources/runtimes/pi-shell-engine/shell_args.py +22 -0
  24. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +9 -2
  25. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +129 -259
  26. package/dist/bundled-resources/skills/authorized-web-security-audit/SKILL.md +187 -0
  27. package/dist/bundled-resources/skills/authorized-web-security-audit/references/assessment-contract.md +92 -0
  28. package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +134 -0
  29. package/dist/bundled-resources/skills/evidence-gated-tdd/SKILL.md +93 -0
  30. package/dist/bundled-resources/skills/evidence-gated-tdd/references/evidence-model.md +27 -0
  31. package/dist/bundled-resources/skills/evidence-gated-tdd/references/security-scanners.md +24 -0
  32. package/dist/bundled-resources/skills/harness-self-adaptation/SKILL.md +4 -2
  33. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/SKILL.md +217 -0
  34. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/defensive-exploit-catalogue.md +175 -0
  35. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/tool-boundary-checklist.md +87 -0
  36. package/dist/bundled-resources/skills/skill-architect/SKILL.md +2 -2
  37. package/dist/bundled-resources/skills/skill-creator/SKILL.md +188 -0
  38. package/dist/bundled-resources/skills/skill-creator/references/pi-skill-contract.md +73 -0
  39. package/dist/bundled-resources/skills/skill-creator/scripts/init-skill.mjs +142 -0
  40. package/dist/bundled-resources/skills/skill-creator/scripts/validate-skill.mjs +122 -0
  41. package/dist/cli/args.d.ts.map +1 -1
  42. package/dist/cli/args.js.map +1 -1
  43. package/dist/cli/config-selector.d.ts.map +1 -1
  44. package/dist/cli/config-selector.js.map +1 -1
  45. package/dist/cli/file-processor.d.ts.map +1 -1
  46. package/dist/cli/file-processor.js +8 -8
  47. package/dist/cli/file-processor.js.map +1 -1
  48. package/dist/cli/initial-message.d.ts +1 -1
  49. package/dist/cli/initial-message.d.ts.map +1 -1
  50. package/dist/cli/initial-message.js.map +1 -1
  51. package/dist/cli/list-models.d.ts.map +1 -1
  52. package/dist/cli/list-models.js.map +1 -1
  53. package/dist/cli/piped-stdin.d.ts +4 -0
  54. package/dist/cli/piped-stdin.d.ts.map +1 -0
  55. package/dist/cli/piped-stdin.js +13 -0
  56. package/dist/cli/piped-stdin.js.map +1 -0
  57. package/dist/cli/session-picker.d.ts.map +1 -1
  58. package/dist/cli/session-picker.js.map +1 -1
  59. package/dist/cli.d.ts.map +1 -1
  60. package/dist/cli.js.map +1 -1
  61. package/dist/config.d.ts.map +1 -1
  62. package/dist/config.js +9 -14
  63. package/dist/config.js.map +1 -1
  64. package/dist/core/agent-directory-layout.d.ts.map +1 -1
  65. package/dist/core/agent-directory-layout.js.map +1 -1
  66. package/dist/core/agent-paths.d.ts.map +1 -1
  67. package/dist/core/agent-paths.js.map +1 -1
  68. package/dist/core/agent-session-contracts.d.ts +5 -9
  69. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  70. package/dist/core/agent-session-contracts.js +1 -12
  71. package/dist/core/agent-session-contracts.js.map +1 -1
  72. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  73. package/dist/core/agent-session-runtime.js +10 -25
  74. package/dist/core/agent-session-runtime.js.map +1 -1
  75. package/dist/core/agent-session-services.d.ts.map +1 -1
  76. package/dist/core/agent-session-services.js.map +1 -1
  77. package/dist/core/agent-session.d.ts +24 -1
  78. package/dist/core/agent-session.d.ts.map +1 -1
  79. package/dist/core/agent-session.js +210 -237
  80. package/dist/core/agent-session.js.map +1 -1
  81. package/dist/core/auth-guidance.d.ts.map +1 -1
  82. package/dist/core/auth-guidance.js.map +1 -1
  83. package/dist/core/auth-storage.d.ts +4 -1
  84. package/dist/core/auth-storage.d.ts.map +1 -1
  85. package/dist/core/auth-storage.js +13 -39
  86. package/dist/core/auth-storage.js.map +1 -1
  87. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  88. package/dist/core/autonomy/approval-gate.js.map +1 -1
  89. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  90. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  91. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  92. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  93. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  94. package/dist/core/autonomy/evidence-finding-projection.d.ts +11 -0
  95. package/dist/core/autonomy/evidence-finding-projection.d.ts.map +1 -0
  96. package/dist/core/autonomy/evidence-finding-projection.js +37 -0
  97. package/dist/core/autonomy/evidence-finding-projection.js.map +1 -0
  98. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  99. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  100. package/dist/core/autonomy/gates.d.ts.map +1 -1
  101. package/dist/core/autonomy/gates.js.map +1 -1
  102. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -1
  103. package/dist/core/autonomy/lane-private-paths.js.map +1 -1
  104. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  105. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  106. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  107. package/dist/core/autonomy/lane-tracker.js +2 -3
  108. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  109. package/dist/core/autonomy/path-scope.d.ts.map +1 -1
  110. package/dist/core/autonomy/path-scope.js.map +1 -1
  111. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  112. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  113. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  114. package/dist/core/autonomy/status.d.ts.map +1 -1
  115. package/dist/core/autonomy/status.js.map +1 -1
  116. package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
  117. package/dist/core/autonomy/subagent-prompt.js.map +1 -1
  118. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  119. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  120. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  121. package/dist/core/autonomy-telemetry.js +2 -4
  122. package/dist/core/autonomy-telemetry.js.map +1 -1
  123. package/dist/core/background-lane-controller.d.ts.map +1 -1
  124. package/dist/core/background-lane-controller.js +2 -15
  125. package/dist/core/background-lane-controller.js.map +1 -1
  126. package/dist/core/background-tool-task-controller.d.ts +88 -0
  127. package/dist/core/background-tool-task-controller.d.ts.map +1 -0
  128. package/dist/core/background-tool-task-controller.js +470 -0
  129. package/dist/core/background-tool-task-controller.js.map +1 -0
  130. package/dist/core/bash-execution-controller.d.ts +1 -0
  131. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  132. package/dist/core/bash-execution-controller.js +5 -4
  133. package/dist/core/bash-execution-controller.js.map +1 -1
  134. package/dist/core/bash-executor.d.ts.map +1 -1
  135. package/dist/core/bash-executor.js.map +1 -1
  136. package/dist/core/bedrock-sso-login.d.ts.map +1 -1
  137. package/dist/core/bedrock-sso-login.js.map +1 -1
  138. package/dist/core/billing-failover-controller.d.ts.map +1 -1
  139. package/dist/core/billing-failover-controller.js +3 -3
  140. package/dist/core/billing-failover-controller.js.map +1 -1
  141. package/dist/core/billing-failover.d.ts.map +1 -1
  142. package/dist/core/billing-failover.js.map +1 -1
  143. package/dist/core/capability-contract.d.ts.map +1 -1
  144. package/dist/core/catalog-manager.d.ts.map +1 -1
  145. package/dist/core/catalog-manager.js +0 -0
  146. package/dist/core/catalog-manager.js.map +1 -1
  147. package/dist/core/compaction-controller.d.ts +2 -0
  148. package/dist/core/compaction-controller.d.ts.map +1 -1
  149. package/dist/core/compaction-controller.js +21 -8
  150. package/dist/core/compaction-controller.js.map +1 -1
  151. package/dist/core/compaction-support.d.ts +8 -0
  152. package/dist/core/compaction-support.d.ts.map +1 -1
  153. package/dist/core/compaction-support.js +0 -2
  154. package/dist/core/compaction-support.js.map +1 -1
  155. package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
  156. package/dist/core/context/artifact-retrieval.js.map +1 -1
  157. package/dist/core/context/brain-curator.d.ts.map +1 -1
  158. package/dist/core/context/brain-curator.js +14 -33
  159. package/dist/core/context/brain-curator.js.map +1 -1
  160. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  161. package/dist/core/context/context-artifacts.js +16 -24
  162. package/dist/core/context/context-artifacts.js.map +1 -1
  163. package/dist/core/context/context-audit.d.ts.map +1 -1
  164. package/dist/core/context/context-audit.js +3 -17
  165. package/dist/core/context/context-audit.js.map +1 -1
  166. package/dist/core/context/context-composition.d.ts.map +1 -1
  167. package/dist/core/context/context-composition.js.map +1 -1
  168. package/dist/core/context/context-item.d.ts.map +1 -1
  169. package/dist/core/context/context-item.js.map +1 -1
  170. package/dist/core/context/context-prompt-enforcement.d.ts.map +1 -1
  171. package/dist/core/context/context-prompt-enforcement.js +3 -16
  172. package/dist/core/context/context-prompt-enforcement.js.map +1 -1
  173. package/dist/core/context/context-prompt-policy.d.ts.map +1 -1
  174. package/dist/core/context/context-prompt-policy.js.map +1 -1
  175. package/dist/core/context/context-retention.d.ts.map +1 -1
  176. package/dist/core/context/context-retention.js.map +1 -1
  177. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  178. package/dist/core/context/context-store-retention.js.map +1 -1
  179. package/dist/core/context/context-store.d.ts.map +1 -1
  180. package/dist/core/context/context-store.js.map +1 -1
  181. package/dist/core/context/context-tool-result.d.ts +4 -0
  182. package/dist/core/context/context-tool-result.d.ts.map +1 -0
  183. package/dist/core/context/context-tool-result.js +15 -0
  184. package/dist/core/context/context-tool-result.js.map +1 -0
  185. package/dist/core/context/current-work-memory.d.ts.map +1 -1
  186. package/dist/core/context/current-work-memory.js.map +1 -1
  187. package/dist/core/context/file-store-memory-provider.d.ts.map +1 -1
  188. package/dist/core/context/file-store-memory-provider.js +7 -28
  189. package/dist/core/context/file-store-memory-provider.js.map +1 -1
  190. package/dist/core/context/local-memory-search.d.ts +11 -0
  191. package/dist/core/context/local-memory-search.d.ts.map +1 -0
  192. package/dist/core/context/local-memory-search.js +37 -0
  193. package/dist/core/context/local-memory-search.js.map +1 -0
  194. package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
  195. package/dist/core/context/long-term-memory-trigger.js.map +1 -1
  196. package/dist/core/context/memory-diagnostics.d.ts.map +1 -1
  197. package/dist/core/context/memory-diagnostics.js.map +1 -1
  198. package/dist/core/context/memory-index-store.d.ts.map +1 -1
  199. package/dist/core/context/memory-index-store.js.map +1 -1
  200. package/dist/core/context/memory-prompt-block.d.ts.map +1 -1
  201. package/dist/core/context/memory-prompt-block.js.map +1 -1
  202. package/dist/core/context/memory-prompt-budget.d.ts.map +1 -1
  203. package/dist/core/context/memory-prompt-budget.js.map +1 -1
  204. package/dist/core/context/memory-provider-contract.d.ts.map +1 -1
  205. package/dist/core/context/memory-provider-contract.js.map +1 -1
  206. package/dist/core/context/memory-retrieval.d.ts.map +1 -1
  207. package/dist/core/context/memory-retrieval.js.map +1 -1
  208. package/dist/core/context/memory-tier-composer.d.ts.map +1 -1
  209. package/dist/core/context/memory-tier-composer.js.map +1 -1
  210. package/dist/core/context/message-text.d.ts +7 -0
  211. package/dist/core/context/message-text.d.ts.map +1 -0
  212. package/dist/core/context/message-text.js +68 -0
  213. package/dist/core/context/message-text.js.map +1 -0
  214. package/dist/core/context/okf-memory-provider.d.ts.map +1 -1
  215. package/dist/core/context/okf-memory-provider.js +4 -30
  216. package/dist/core/context/okf-memory-provider.js.map +1 -1
  217. package/dist/core/context/okf-memory.d.ts.map +1 -1
  218. package/dist/core/context/okf-memory.js.map +1 -1
  219. package/dist/core/context/policy-engine.d.ts.map +1 -1
  220. package/dist/core/context/policy-engine.js.map +1 -1
  221. package/dist/core/context/policy-types.d.ts.map +1 -1
  222. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  223. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  224. package/dist/core/context/storage-authority.d.ts.map +1 -1
  225. package/dist/core/context/tool-output-packer.d.ts.map +1 -1
  226. package/dist/core/context/tool-output-packer.js.map +1 -1
  227. package/dist/core/context-gc.d.ts.map +1 -1
  228. package/dist/core/context-gc.js +14 -21
  229. package/dist/core/context-gc.js.map +1 -1
  230. package/dist/core/context-pipeline.d.ts +1 -3
  231. package/dist/core/context-pipeline.d.ts.map +1 -1
  232. package/dist/core/context-pipeline.js +64 -145
  233. package/dist/core/context-pipeline.js.map +1 -1
  234. package/dist/core/cost/cost-summary.d.ts.map +1 -1
  235. package/dist/core/cost/cost-summary.js.map +1 -1
  236. package/dist/core/cost/daily-usage.d.ts.map +1 -1
  237. package/dist/core/cost/daily-usage.js.map +1 -1
  238. package/dist/core/cost/session-usage.d.ts.map +1 -1
  239. package/dist/core/cost/session-usage.js.map +1 -1
  240. package/dist/core/cost-guard.d.ts.map +1 -1
  241. package/dist/core/cost-guard.js.map +1 -1
  242. package/dist/core/default-tool-surface.d.ts.map +1 -1
  243. package/dist/core/default-tool-surface.js +1 -0
  244. package/dist/core/default-tool-surface.js.map +1 -1
  245. package/dist/core/defaults.d.ts.map +1 -1
  246. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  247. package/dist/core/delegation/managed-lane-controller.js +2 -6
  248. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  249. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
  250. package/dist/core/delegation/session-worker-claim.js.map +1 -1
  251. package/dist/core/delegation/worker-action-journal.d.ts.map +1 -1
  252. package/dist/core/delegation/worker-action-journal.js +0 -4
  253. package/dist/core/delegation/worker-action-journal.js.map +1 -1
  254. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  255. package/dist/core/delegation/worker-actions.js.map +1 -1
  256. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +1 -0
  257. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
  258. package/dist/core/delegation/worker-agent-control-coordinator.js +13 -15
  259. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  260. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
  261. package/dist/core/delegation/worker-agent-control.js +1 -4
  262. package/dist/core/delegation/worker-agent-control.js.map +1 -1
  263. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  264. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  265. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  266. package/dist/core/delegation/worker-claim.js.map +1 -1
  267. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
  268. package/dist/core/delegation/worker-conversation-store.js +0 -2
  269. package/dist/core/delegation/worker-conversation-store.js.map +1 -1
  270. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  271. package/dist/core/delegation/worker-delegation-controller.js +5 -14
  272. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  273. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  274. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
  275. package/dist/core/delegation/worker-dispatch-scheduler.js +5 -6
  276. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
  277. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  278. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  279. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
  280. package/dist/core/delegation/worker-lane-projection.js.map +1 -1
  281. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  282. package/dist/core/delegation/worker-lifecycle.js +0 -3
  283. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  284. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
  285. package/dist/core/delegation/worker-notification-coordinator.js +4 -5
  286. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
  287. package/dist/core/delegation/worker-process-owner.d.ts.map +1 -1
  288. package/dist/core/delegation/worker-process-owner.js.map +1 -1
  289. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  290. package/dist/core/delegation/worker-profile-resolver.js +1 -2
  291. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  292. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
  293. package/dist/core/delegation/worker-recovery-coordinator.js +3 -4
  294. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
  295. package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -1
  296. package/dist/core/delegation/worker-resource-catalog.js.map +1 -1
  297. package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -1
  298. package/dist/core/delegation/worker-resource-materializer.js +1 -4
  299. package/dist/core/delegation/worker-resource-materializer.js.map +1 -1
  300. package/dist/core/delegation/worker-runner.d.ts +2 -4
  301. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  302. package/dist/core/delegation/worker-runner.js +6 -18
  303. package/dist/core/delegation/worker-runner.js.map +1 -1
  304. package/dist/core/delegation/worker-task-label.d.ts.map +1 -1
  305. package/dist/core/delegation/worker-task-label.js.map +1 -1
  306. package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -1
  307. package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -1
  308. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
  309. package/dist/core/delegation/worker-write-reservation-coordinator.js +1 -4
  310. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
  311. package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -1
  312. package/dist/core/delegation/worker-write-reservation.js +0 -2
  313. package/dist/core/delegation/worker-write-reservation.js.map +1 -1
  314. package/dist/core/diagnostics.d.ts.map +1 -1
  315. package/dist/core/doctor.d.ts.map +1 -1
  316. package/dist/core/doctor.js.map +1 -1
  317. package/dist/core/event-bus.d.ts.map +1 -1
  318. package/dist/core/event-bus.js.map +1 -1
  319. package/dist/core/exec.d.ts.map +1 -1
  320. package/dist/core/exec.js +26 -7
  321. package/dist/core/exec.js.map +1 -1
  322. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  323. package/dist/core/export-html/ansi-to-html.js +21 -74
  324. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  325. package/dist/core/export-html/index.d.ts.map +1 -1
  326. package/dist/core/export-html/index.js +4 -0
  327. package/dist/core/export-html/index.js.map +1 -1
  328. package/dist/core/export-html/session-tree-foundations.d.mts +67 -0
  329. package/dist/core/export-html/session-tree-foundations.mjs +313 -0
  330. package/dist/core/export-html/template.css +14 -41
  331. package/dist/core/export-html/template.html +3 -1
  332. package/dist/core/export-html/template.js +26 -435
  333. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  334. package/dist/core/export-html/tool-renderer.js.map +1 -1
  335. package/dist/core/extension-import-authority.d.ts.map +1 -1
  336. package/dist/core/extension-import-authority.js.map +1 -1
  337. package/dist/core/extension-metadata.d.ts.map +1 -1
  338. package/dist/core/extension-metadata.js.map +1 -1
  339. package/dist/core/extensions/builtin.d.ts +17 -0
  340. package/dist/core/extensions/builtin.d.ts.map +1 -1
  341. package/dist/core/extensions/builtin.js +18 -54
  342. package/dist/core/extensions/builtin.js.map +1 -1
  343. package/dist/core/extensions/entry-resolution.d.ts +3 -0
  344. package/dist/core/extensions/entry-resolution.d.ts.map +1 -0
  345. package/dist/core/extensions/entry-resolution.js +17 -0
  346. package/dist/core/extensions/entry-resolution.js.map +1 -0
  347. package/dist/core/extensions/index.d.ts.map +1 -1
  348. package/dist/core/extensions/loader.d.ts.map +1 -1
  349. package/dist/core/extensions/loader.js +76 -21
  350. package/dist/core/extensions/loader.js.map +1 -1
  351. package/dist/core/extensions/runner.d.ts +2 -0
  352. package/dist/core/extensions/runner.d.ts.map +1 -1
  353. package/dist/core/extensions/runner.js +41 -112
  354. package/dist/core/extensions/runner.js.map +1 -1
  355. package/dist/core/extensions/stale-context.d.ts.map +1 -1
  356. package/dist/core/extensions/storage.d.ts.map +1 -1
  357. package/dist/core/extensions/storage.js.map +1 -1
  358. package/dist/core/extensions/types.d.ts.map +1 -1
  359. package/dist/core/extensions/types.js.map +1 -1
  360. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  361. package/dist/core/extensions/wrapper.js.map +1 -1
  362. package/dist/core/failure-corpus.d.ts.map +1 -1
  363. package/dist/core/failure-corpus.js +2 -5
  364. package/dist/core/failure-corpus.js.map +1 -1
  365. package/dist/core/footer-data-provider.d.ts.map +1 -1
  366. package/dist/core/footer-data-provider.js +27 -33
  367. package/dist/core/footer-data-provider.js.map +1 -1
  368. package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
  369. package/dist/core/foreground-recovery-controller.js +0 -4
  370. package/dist/core/foreground-recovery-controller.js.map +1 -1
  371. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  372. package/dist/core/gateways/channel-provider.js +7 -5
  373. package/dist/core/gateways/channel-provider.js.map +1 -1
  374. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  375. package/dist/core/goal-loop-controller.js +0 -1
  376. package/dist/core/goal-loop-controller.js.map +1 -1
  377. package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
  378. package/dist/core/goals/compact-goal-context.js +2 -4
  379. package/dist/core/goals/compact-goal-context.js.map +1 -1
  380. package/dist/core/goals/goal-acceptance.d.ts.map +1 -1
  381. package/dist/core/goals/goal-acceptance.js.map +1 -1
  382. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
  383. package/dist/core/goals/goal-auto-continue-controller.js +1 -3
  384. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
  385. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  386. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  387. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  388. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  389. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  390. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
  391. package/dist/core/goals/goal-lifecycle.js.map +1 -1
  392. package/dist/core/goals/goal-record.d.ts.map +1 -1
  393. package/dist/core/goals/goal-record.js.map +1 -1
  394. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  395. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  396. package/dist/core/goals/goal-session-controller.d.ts +15 -0
  397. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  398. package/dist/core/goals/goal-session-controller.js +27 -3
  399. package/dist/core/goals/goal-session-controller.js.map +1 -1
  400. package/dist/core/goals/goal-state.d.ts.map +1 -1
  401. package/dist/core/goals/goal-state.js +35 -51
  402. package/dist/core/goals/goal-state.js.map +1 -1
  403. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  404. package/dist/core/goals/goal-tool-core.js.map +1 -1
  405. package/dist/core/goals/natural-language-goal.d.ts +9 -0
  406. package/dist/core/goals/natural-language-goal.d.ts.map +1 -0
  407. package/dist/core/goals/natural-language-goal.js +23 -0
  408. package/dist/core/goals/natural-language-goal.js.map +1 -0
  409. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  410. package/dist/core/goals/session-goal-state.js.map +1 -1
  411. package/dist/core/http-dispatcher.d.ts.map +1 -1
  412. package/dist/core/http-dispatcher.js.map +1 -1
  413. package/dist/core/human-input-controller.d.ts.map +1 -1
  414. package/dist/core/human-input-controller.js +2 -3
  415. package/dist/core/human-input-controller.js.map +1 -1
  416. package/dist/core/human-input.d.ts.map +1 -1
  417. package/dist/core/human-input.js.map +1 -1
  418. package/dist/core/improvement-loop.d.ts.map +1 -1
  419. package/dist/core/improvement-loop.js +11 -11
  420. package/dist/core/improvement-loop.js.map +1 -1
  421. package/dist/core/index.d.ts.map +1 -1
  422. package/dist/core/install-telemetry.d.ts.map +1 -1
  423. package/dist/core/install-telemetry.js.map +1 -1
  424. package/dist/core/isolated-text-completion.d.ts +17 -0
  425. package/dist/core/isolated-text-completion.d.ts.map +1 -0
  426. package/dist/core/isolated-text-completion.js +15 -0
  427. package/dist/core/isolated-text-completion.js.map +1 -0
  428. package/dist/core/keybindings.d.ts +47 -2
  429. package/dist/core/keybindings.d.ts.map +1 -1
  430. package/dist/core/keybindings.js +12 -1
  431. package/dist/core/keybindings.js.map +1 -1
  432. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  433. package/dist/core/learning/learning-audit.js.map +1 -1
  434. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  435. package/dist/core/learning/learning-gate.js.map +1 -1
  436. package/dist/core/learning/observation-store.d.ts.map +1 -1
  437. package/dist/core/learning/observation-store.js +0 -2
  438. package/dist/core/learning/observation-store.js.map +1 -1
  439. package/dist/core/learning/reflection-engine.d.ts +1 -1
  440. package/dist/core/learning/reflection-engine.d.ts.map +1 -1
  441. package/dist/core/learning/reflection-engine.js +3 -0
  442. package/dist/core/learning/reflection-engine.js.map +1 -1
  443. package/dist/core/learning/reflection-turn-analysis.d.ts +20 -0
  444. package/dist/core/learning/reflection-turn-analysis.d.ts.map +1 -0
  445. package/dist/core/learning/reflection-turn-analysis.js +136 -0
  446. package/dist/core/learning/reflection-turn-analysis.js.map +1 -0
  447. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  448. package/dist/core/learning/session-learning-decision.js.map +1 -1
  449. package/dist/core/learning/skill-curator.d.ts.map +1 -1
  450. package/dist/core/learning/skill-curator.js +0 -3
  451. package/dist/core/learning/skill-curator.js.map +1 -1
  452. package/dist/core/local-runtime-controller.d.ts +39 -0
  453. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  454. package/dist/core/local-runtime-controller.js +41 -62
  455. package/dist/core/local-runtime-controller.js.map +1 -1
  456. package/dist/core/memory/effectiveness-tracker.d.ts.map +1 -1
  457. package/dist/core/memory/effectiveness-tracker.js +4 -2
  458. package/dist/core/memory/effectiveness-tracker.js.map +1 -1
  459. package/dist/core/memory/memory-manager.d.ts.map +1 -1
  460. package/dist/core/memory/memory-manager.js +7 -7
  461. package/dist/core/memory/memory-manager.js.map +1 -1
  462. package/dist/core/memory/memory-provider.d.ts.map +1 -1
  463. package/dist/core/memory/providers/file-store.d.ts +7 -0
  464. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  465. package/dist/core/memory/providers/file-store.js +48 -13
  466. package/dist/core/memory/providers/file-store.js.map +1 -1
  467. package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts +47 -0
  468. package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts.map +1 -0
  469. package/dist/core/memory/providers/transcript-recall-worker-protocol.js +50 -0
  470. package/dist/core/memory/providers/transcript-recall-worker-protocol.js.map +1 -0
  471. package/dist/core/memory/providers/transcript-recall-worker.d.ts +2 -0
  472. package/dist/core/memory/providers/transcript-recall-worker.d.ts.map +1 -0
  473. package/dist/core/memory/providers/transcript-recall-worker.js +143 -0
  474. package/dist/core/memory/providers/transcript-recall-worker.js.map +1 -0
  475. package/dist/core/memory/providers/transcript-recall.d.ts +24 -13
  476. package/dist/core/memory/providers/transcript-recall.d.ts.map +1 -1
  477. package/dist/core/memory/providers/transcript-recall.js +143 -141
  478. package/dist/core/memory/providers/transcript-recall.js.map +1 -1
  479. package/dist/core/memory/providers/user-memory-archive.d.ts +39 -0
  480. package/dist/core/memory/providers/user-memory-archive.d.ts.map +1 -0
  481. package/dist/core/memory/providers/user-memory-archive.js +258 -0
  482. package/dist/core/memory/providers/user-memory-archive.js.map +1 -0
  483. package/dist/core/memory/transcript-index.d.ts.map +1 -1
  484. package/dist/core/memory/transcript-index.js +1 -1
  485. package/dist/core/memory/transcript-index.js.map +1 -1
  486. package/dist/core/memory-controller.d.ts +9 -0
  487. package/dist/core/memory-controller.d.ts.map +1 -1
  488. package/dist/core/memory-controller.js +57 -16
  489. package/dist/core/memory-controller.js.map +1 -1
  490. package/dist/core/model-capability.d.ts.map +1 -1
  491. package/dist/core/model-capability.js.map +1 -1
  492. package/dist/core/model-output-json.d.ts +10 -0
  493. package/dist/core/model-output-json.d.ts.map +1 -0
  494. package/dist/core/model-output-json.js +43 -0
  495. package/dist/core/model-output-json.js.map +1 -0
  496. package/dist/core/model-registry.d.ts +8 -8
  497. package/dist/core/model-registry.d.ts.map +1 -1
  498. package/dist/core/model-registry.js +29 -52
  499. package/dist/core/model-registry.js.map +1 -1
  500. package/dist/core/model-resolver.d.ts.map +1 -1
  501. package/dist/core/model-resolver.js +1 -1
  502. package/dist/core/model-resolver.js.map +1 -1
  503. package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
  504. package/dist/core/model-router/config-diagnostics.js.map +1 -1
  505. package/dist/core/model-router/executor-route.d.ts.map +1 -1
  506. package/dist/core/model-router/executor-route.js.map +1 -1
  507. package/dist/core/model-router/fitness-gate.d.ts.map +1 -1
  508. package/dist/core/model-router/fitness-gate.js.map +1 -1
  509. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  510. package/dist/core/model-router/route-judge.d.ts.map +1 -1
  511. package/dist/core/model-router/route-judge.js +18 -36
  512. package/dist/core/model-router/route-judge.js.map +1 -1
  513. package/dist/core/model-router/session-buffer.d.ts.map +1 -1
  514. package/dist/core/model-router/session-buffer.js.map +1 -1
  515. package/dist/core/model-router/status.d.ts.map +1 -1
  516. package/dist/core/model-router/status.js.map +1 -1
  517. package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
  518. package/dist/core/model-router/tool-escalation.js.map +1 -1
  519. package/dist/core/model-router-controller.d.ts +1 -0
  520. package/dist/core/model-router-controller.d.ts.map +1 -1
  521. package/dist/core/model-router-controller.js +25 -56
  522. package/dist/core/model-router-controller.js.map +1 -1
  523. package/dist/core/model-selection-controller.d.ts +10 -0
  524. package/dist/core/model-selection-controller.d.ts.map +1 -1
  525. package/dist/core/model-selection-controller.js +0 -1
  526. package/dist/core/model-selection-controller.js.map +1 -1
  527. package/dist/core/model-tool-protocol.d.ts.map +1 -1
  528. package/dist/core/model-tool-protocol.js.map +1 -1
  529. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  530. package/dist/core/models/adaptation-store.js +0 -1
  531. package/dist/core/models/adaptation-store.js.map +1 -1
  532. package/dist/core/models/context-sizing.d.ts.map +1 -1
  533. package/dist/core/models/context-sizing.js.map +1 -1
  534. package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
  535. package/dist/core/models/default-model-suggestions.js.map +1 -1
  536. package/dist/core/models/fitness-store.d.ts.map +1 -1
  537. package/dist/core/models/fitness-store.js +0 -1
  538. package/dist/core/models/fitness-store.js.map +1 -1
  539. package/dist/core/models/host-state-store.d.ts.map +1 -1
  540. package/dist/core/models/host-state-store.js +1 -6
  541. package/dist/core/models/host-state-store.js.map +1 -1
  542. package/dist/core/models/llamacpp-runtime.d.ts +4 -19
  543. package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
  544. package/dist/core/models/llamacpp-runtime.js +32 -136
  545. package/dist/core/models/llamacpp-runtime.js.map +1 -1
  546. package/dist/core/models/local-registration.d.ts.map +1 -1
  547. package/dist/core/models/local-registration.js +82 -115
  548. package/dist/core/models/local-registration.js.map +1 -1
  549. package/dist/core/models/local-runtime.d.ts +12 -18
  550. package/dist/core/models/local-runtime.d.ts.map +1 -1
  551. package/dist/core/models/local-runtime.js +60 -204
  552. package/dist/core/models/local-runtime.js.map +1 -1
  553. package/dist/core/models/model-endpoint.d.ts.map +1 -1
  554. package/dist/core/models/model-endpoint.js.map +1 -1
  555. package/dist/core/models/model-ref.d.ts.map +1 -1
  556. package/dist/core/models/model-ref.js.map +1 -1
  557. package/dist/core/models/needle-runtime.d.ts +7 -3
  558. package/dist/core/models/needle-runtime.d.ts.map +1 -1
  559. package/dist/core/models/needle-runtime.js +16 -92
  560. package/dist/core/models/needle-runtime.js.map +1 -1
  561. package/dist/core/models/perf-profile.d.ts +1 -1
  562. package/dist/core/models/perf-profile.d.ts.map +1 -1
  563. package/dist/core/models/perf-profile.js +6 -13
  564. package/dist/core/models/perf-profile.js.map +1 -1
  565. package/dist/core/models/prism-llamacpp-lifecycle.d.ts.map +1 -1
  566. package/dist/core/models/prism-llamacpp-lifecycle.js.map +1 -1
  567. package/dist/core/models/runtime-arbiter.d.ts.map +1 -1
  568. package/dist/core/models/runtime-arbiter.js +3 -15
  569. package/dist/core/models/runtime-arbiter.js.map +1 -1
  570. package/dist/core/models/runtime-process.d.ts +100 -0
  571. package/dist/core/models/runtime-process.d.ts.map +1 -0
  572. package/dist/core/models/runtime-process.js +183 -0
  573. package/dist/core/models/runtime-process.js.map +1 -0
  574. package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
  575. package/dist/core/orchestration/agent-resume.js.map +1 -1
  576. package/dist/core/orchestration/attempt-usage.d.ts.map +1 -1
  577. package/dist/core/orchestration/attempt-usage.js.map +1 -1
  578. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  579. package/dist/core/orchestration/capability-gateway.js +0 -14
  580. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  581. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  582. package/dist/core/orchestration/contracts.js.map +1 -1
  583. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  584. package/dist/core/orchestration/delegation-ledger.js +0 -2
  585. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  586. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  587. package/dist/core/orchestration/event-store.js +1 -14
  588. package/dist/core/orchestration/event-store.js.map +1 -1
  589. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  590. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  591. package/dist/core/orchestration/model-binding.d.ts.map +1 -1
  592. package/dist/core/orchestration/model-binding.js.map +1 -1
  593. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
  594. package/dist/core/orchestration/policy-compiler.js +0 -3
  595. package/dist/core/orchestration/policy-compiler.js.map +1 -1
  596. package/dist/core/orchestration/policy-gate.d.ts.map +1 -1
  597. package/dist/core/orchestration/policy-gate.js +0 -2
  598. package/dist/core/orchestration/policy-gate.js.map +1 -1
  599. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  600. package/dist/core/orchestration/profile-registry.js +1 -1
  601. package/dist/core/orchestration/profile-registry.js.map +1 -1
  602. package/dist/core/orchestration/profile-store.d.ts.map +1 -1
  603. package/dist/core/orchestration/profile-store.js +0 -3
  604. package/dist/core/orchestration/profile-store.js.map +1 -1
  605. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  606. package/dist/core/orchestration/risk-budget.js.map +1 -1
  607. package/dist/core/orchestration/task-runtime.d.ts +1 -0
  608. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  609. package/dist/core/orchestration/task-runtime.js +27 -42
  610. package/dist/core/orchestration/task-runtime.js.map +1 -1
  611. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
  612. package/dist/core/orchestration/work-state-projection.js.map +1 -1
  613. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  614. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  615. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
  616. package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
  617. package/dist/core/output-guard.d.ts.map +1 -1
  618. package/dist/core/output-guard.js.map +1 -1
  619. package/dist/core/package-manager.d.ts +3 -0
  620. package/dist/core/package-manager.d.ts.map +1 -1
  621. package/dist/core/package-manager.js +88 -353
  622. package/dist/core/package-manager.js.map +1 -1
  623. package/dist/core/process-identity.d.ts.map +1 -1
  624. package/dist/core/process-identity.js.map +1 -1
  625. package/dist/core/process-liveness.d.ts +3 -0
  626. package/dist/core/process-liveness.d.ts.map +1 -0
  627. package/dist/core/process-liveness.js +17 -0
  628. package/dist/core/process-liveness.js.map +1 -0
  629. package/dist/core/process-matrix/codes.d.ts.map +1 -1
  630. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -1
  631. package/dist/core/process-matrix/resume-launcher.js.map +1 -1
  632. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  633. package/dist/core/process-matrix/runtime.js.map +1 -1
  634. package/dist/core/process-matrix/store.d.ts.map +1 -1
  635. package/dist/core/process-matrix/store.js.map +1 -1
  636. package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
  637. package/dist/core/process-matrix/supervisor.js.map +1 -1
  638. package/dist/core/profile-filter-controller.d.ts.map +1 -1
  639. package/dist/core/profile-filter-controller.js +7 -8
  640. package/dist/core/profile-filter-controller.js.map +1 -1
  641. package/dist/core/profile-registry.d.ts.map +1 -1
  642. package/dist/core/profile-registry.js +1 -2
  643. package/dist/core/profile-registry.js.map +1 -1
  644. package/dist/core/profile-resource-selection.d.ts.map +1 -1
  645. package/dist/core/profile-resource-selection.js +18 -59
  646. package/dist/core/profile-resource-selection.js.map +1 -1
  647. package/dist/core/prompt-markup.d.ts +3 -0
  648. package/dist/core/prompt-markup.d.ts.map +1 -0
  649. package/dist/core/prompt-markup.js +7 -0
  650. package/dist/core/prompt-markup.js.map +1 -0
  651. package/dist/core/prompt-templates.d.ts.map +1 -1
  652. package/dist/core/prompt-templates.js +13 -39
  653. package/dist/core/prompt-templates.js.map +1 -1
  654. package/dist/core/provider-display-names.d.ts.map +1 -1
  655. package/dist/core/python-runtime.d.ts.map +1 -1
  656. package/dist/core/python-runtime.js.map +1 -1
  657. package/dist/core/reflection-controller.d.ts +22 -1
  658. package/dist/core/reflection-controller.d.ts.map +1 -1
  659. package/dist/core/reflection-controller.js +143 -25
  660. package/dist/core/reflection-controller.js.map +1 -1
  661. package/dist/core/reload-blockers.d.ts +2 -1
  662. package/dist/core/reload-blockers.d.ts.map +1 -1
  663. package/dist/core/reload-blockers.js +4 -14
  664. package/dist/core/reload-blockers.js.map +1 -1
  665. package/dist/core/request-auth.d.ts.map +1 -1
  666. package/dist/core/request-auth.js.map +1 -1
  667. package/dist/core/research/automata-provider.d.ts.map +1 -1
  668. package/dist/core/research/automata-provider.js.map +1 -1
  669. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  670. package/dist/core/research/evidence-bundle.js.map +1 -1
  671. package/dist/core/research/lane-model-resolver.d.ts.map +1 -1
  672. package/dist/core/research/lane-model-resolver.js +0 -1
  673. package/dist/core/research/lane-model-resolver.js.map +1 -1
  674. package/dist/core/research/model-fitness-controller.d.ts.map +1 -1
  675. package/dist/core/research/model-fitness-controller.js +17 -33
  676. package/dist/core/research/model-fitness-controller.js.map +1 -1
  677. package/dist/core/research/model-fitness.d.ts.map +1 -1
  678. package/dist/core/research/model-fitness.js +4 -25
  679. package/dist/core/research/model-fitness.js.map +1 -1
  680. package/dist/core/research/research-gate.d.ts.map +1 -1
  681. package/dist/core/research/research-gate.js.map +1 -1
  682. package/dist/core/research/research-lane-controller.d.ts.map +1 -1
  683. package/dist/core/research/research-lane-controller.js +5 -10
  684. package/dist/core/research/research-lane-controller.js.map +1 -1
  685. package/dist/core/research/research-runner.d.ts +2 -4
  686. package/dist/core/research/research-runner.d.ts.map +1 -1
  687. package/dist/core/research/research-runner.js +17 -48
  688. package/dist/core/research/research-runner.js.map +1 -1
  689. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  690. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  691. package/dist/core/research/workspace-collector.d.ts.map +1 -1
  692. package/dist/core/research/workspace-collector.js.map +1 -1
  693. package/dist/core/resolve-config-value.d.ts.map +1 -1
  694. package/dist/core/resolve-config-value.js.map +1 -1
  695. package/dist/core/resource-ignore.d.ts +6 -0
  696. package/dist/core/resource-ignore.d.ts.map +1 -0
  697. package/dist/core/resource-ignore.js +44 -0
  698. package/dist/core/resource-ignore.js.map +1 -0
  699. package/dist/core/resource-loader.d.ts +0 -1
  700. package/dist/core/resource-loader.d.ts.map +1 -1
  701. package/dist/core/resource-loader.js +52 -187
  702. package/dist/core/resource-loader.js.map +1 -1
  703. package/dist/core/resource-profile-blocks.d.ts +3 -1
  704. package/dist/core/resource-profile-blocks.d.ts.map +1 -1
  705. package/dist/core/resource-profile-blocks.js +8 -5
  706. package/dist/core/resource-profile-blocks.js.map +1 -1
  707. package/dist/core/resource-profile-equality.d.ts.map +1 -1
  708. package/dist/core/resource-profile-equality.js.map +1 -1
  709. package/dist/core/resource-traversal.d.ts +43 -0
  710. package/dist/core/resource-traversal.d.ts.map +1 -0
  711. package/dist/core/resource-traversal.js +84 -0
  712. package/dist/core/resource-traversal.js.map +1 -0
  713. package/dist/core/risk-classifier.d.ts.map +1 -1
  714. package/dist/core/risk-classifier.js.map +1 -1
  715. package/dist/core/runtime-builder.d.ts +4 -1
  716. package/dist/core/runtime-builder.d.ts.map +1 -1
  717. package/dist/core/runtime-builder.js +25 -50
  718. package/dist/core/runtime-builder.js.map +1 -1
  719. package/dist/core/scout-controller.d.ts.map +1 -1
  720. package/dist/core/scout-controller.js +0 -1
  721. package/dist/core/scout-controller.js.map +1 -1
  722. package/dist/core/sdk.d.ts.map +1 -1
  723. package/dist/core/sdk.js.map +1 -1
  724. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
  725. package/dist/core/secrets/credential-exposure-guard.js +70 -44
  726. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  727. package/dist/core/secrets/secret-dotenv.d.ts.map +1 -1
  728. package/dist/core/secrets/secret-dotenv.js +0 -1
  729. package/dist/core/secrets/secret-dotenv.js.map +1 -1
  730. package/dist/core/secrets/secret-vault-format.d.ts.map +1 -1
  731. package/dist/core/secrets/secret-vault-format.js +0 -1
  732. package/dist/core/secrets/secret-vault-format.js.map +1 -1
  733. package/dist/core/secrets/secret-vault.d.ts.map +1 -1
  734. package/dist/core/secrets/secret-vault.js +2 -10
  735. package/dist/core/secrets/secret-vault.js.map +1 -1
  736. package/dist/core/security/secret-text.d.ts.map +1 -1
  737. package/dist/core/security/secret-text.js.map +1 -1
  738. package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
  739. package/dist/core/security/untrusted-boundary.js.map +1 -1
  740. package/dist/core/session-analytics.d.ts.map +1 -1
  741. package/dist/core/session-analytics.js +18 -50
  742. package/dist/core/session-analytics.js.map +1 -1
  743. package/dist/core/session-artifact-bundle.d.ts.map +1 -1
  744. package/dist/core/session-artifact-bundle.js.map +1 -1
  745. package/dist/core/session-cwd.d.ts.map +1 -1
  746. package/dist/core/session-cwd.js +0 -1
  747. package/dist/core/session-cwd.js.map +1 -1
  748. package/dist/core/session-entry-index.d.ts +8 -0
  749. package/dist/core/session-entry-index.d.ts.map +1 -0
  750. package/dist/core/session-entry-index.js +16 -0
  751. package/dist/core/session-entry-index.js.map +1 -0
  752. package/dist/core/session-image-store.d.ts.map +1 -1
  753. package/dist/core/session-image-store.js +0 -3
  754. package/dist/core/session-image-store.js.map +1 -1
  755. package/dist/core/session-jsonl-writer.d.ts +3 -0
  756. package/dist/core/session-jsonl-writer.d.ts.map +1 -0
  757. package/dist/core/session-jsonl-writer.js +38 -0
  758. package/dist/core/session-jsonl-writer.js.map +1 -0
  759. package/dist/core/session-manager-factory.d.ts.map +1 -1
  760. package/dist/core/session-manager-factory.js.map +1 -1
  761. package/dist/core/session-role.d.ts.map +1 -1
  762. package/dist/core/session-role.js.map +1 -1
  763. package/dist/core/session-snapshot.d.ts.map +1 -1
  764. package/dist/core/session-snapshot.js.map +1 -1
  765. package/dist/core/session-supervision-runtime.d.ts.map +1 -1
  766. package/dist/core/session-supervision-runtime.js +1 -4
  767. package/dist/core/session-supervision-runtime.js.map +1 -1
  768. package/dist/core/session-tree-navigator.d.ts.map +1 -1
  769. package/dist/core/session-tree-navigator.js +0 -1
  770. package/dist/core/session-tree-navigator.js.map +1 -1
  771. package/dist/core/settings-manager.d.ts +2 -1
  772. package/dist/core/settings-manager.d.ts.map +1 -1
  773. package/dist/core/settings-manager.js +64 -162
  774. package/dist/core/settings-manager.js.map +1 -1
  775. package/dist/core/skill-block.d.mts +8 -0
  776. package/dist/core/skill-block.mjs +52 -0
  777. package/dist/core/skill-discovery.d.ts +5 -0
  778. package/dist/core/skill-discovery.d.ts.map +1 -0
  779. package/dist/core/skill-discovery.js +34 -0
  780. package/dist/core/skill-discovery.js.map +1 -0
  781. package/dist/core/skills.d.ts.map +1 -1
  782. package/dist/core/skills.js +23 -159
  783. package/dist/core/skills.js.map +1 -1
  784. package/dist/core/slash-commands.d.ts.map +1 -1
  785. package/dist/core/source-info.d.ts.map +1 -1
  786. package/dist/core/source-info.js.map +1 -1
  787. package/dist/core/spawned-usage.d.ts +21 -0
  788. package/dist/core/spawned-usage.d.ts.map +1 -0
  789. package/dist/core/spawned-usage.js +29 -0
  790. package/dist/core/spawned-usage.js.map +1 -0
  791. package/dist/core/system-prompt-builder.d.ts +4 -0
  792. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  793. package/dist/core/system-prompt-builder.js +15 -8
  794. package/dist/core/system-prompt-builder.js.map +1 -1
  795. package/dist/core/system-prompt.d.ts.map +1 -1
  796. package/dist/core/system-prompt.js +52 -35
  797. package/dist/core/system-prompt.js.map +1 -1
  798. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  799. package/dist/core/tasks/session-task-state.js.map +1 -1
  800. package/dist/core/tasks/task-command.d.ts.map +1 -1
  801. package/dist/core/tasks/task-command.js.map +1 -1
  802. package/dist/core/tasks/task-contract-monitor.d.ts.map +1 -1
  803. package/dist/core/tasks/task-contract-monitor.js.map +1 -1
  804. package/dist/core/tasks/task-projection.d.ts.map +1 -1
  805. package/dist/core/tasks/task-projection.js.map +1 -1
  806. package/dist/core/tasks/task-state.d.ts.map +1 -1
  807. package/dist/core/tasks/task-state.js.map +1 -1
  808. package/dist/core/text-preview.d.ts +4 -0
  809. package/dist/core/text-preview.d.ts.map +1 -0
  810. package/dist/core/text-preview.js +33 -0
  811. package/dist/core/text-preview.js.map +1 -0
  812. package/dist/core/timings.d.ts.map +1 -1
  813. package/dist/core/timings.js.map +1 -1
  814. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  815. package/dist/core/tool-capability-policy.js.map +1 -1
  816. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  817. package/dist/core/tool-gate-controller.js +86 -87
  818. package/dist/core/tool-gate-controller.js.map +1 -1
  819. package/dist/core/tool-protocol-controller.d.ts +4 -1
  820. package/dist/core/tool-protocol-controller.d.ts.map +1 -1
  821. package/dist/core/tool-protocol-controller.js +19 -23
  822. package/dist/core/tool-protocol-controller.js.map +1 -1
  823. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  824. package/dist/core/tool-recovery-log-records.js.map +1 -1
  825. package/dist/core/tool-recovery-log-worker.d.ts.map +1 -1
  826. package/dist/core/tool-recovery-log-worker.js.map +1 -1
  827. package/dist/core/tool-recovery-logger.d.ts.map +1 -1
  828. package/dist/core/tool-recovery-logger.js +12 -24
  829. package/dist/core/tool-recovery-logger.js.map +1 -1
  830. package/dist/core/tool-recovery-stats.d.ts.map +1 -1
  831. package/dist/core/tool-recovery-stats.js +16 -22
  832. package/dist/core/tool-recovery-stats.js.map +1 -1
  833. package/dist/core/tool-repair-health.d.ts.map +1 -1
  834. package/dist/core/tool-repair-health.js.map +1 -1
  835. package/dist/core/tool-repair-settings.d.ts.map +1 -1
  836. package/dist/core/tool-repair-settings.js.map +1 -1
  837. package/dist/core/tool-selection/expected-utility.d.ts.map +1 -1
  838. package/dist/core/tool-selection/expected-utility.js.map +1 -1
  839. package/dist/core/tool-selection/promotion.d.ts.map +1 -1
  840. package/dist/core/tool-selection/promotion.js.map +1 -1
  841. package/dist/core/tool-selection/tool-performance-store.d.ts +2 -0
  842. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  843. package/dist/core/tool-selection/tool-performance-store.js +49 -7
  844. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  845. package/dist/core/tool-selection/tool-phase-timing.d.ts +19 -0
  846. package/dist/core/tool-selection/tool-phase-timing.d.ts.map +1 -0
  847. package/dist/core/tool-selection/tool-phase-timing.js +63 -0
  848. package/dist/core/tool-selection/tool-phase-timing.js.map +1 -0
  849. package/dist/core/tool-selection/tool-selection-controller.d.ts +2 -5
  850. package/dist/core/tool-selection/tool-selection-controller.d.ts.map +1 -1
  851. package/dist/core/tool-selection/tool-selection-controller.js +50 -30
  852. package/dist/core/tool-selection/tool-selection-controller.js.map +1 -1
  853. package/dist/core/toolkit/reflex-interpreter.d.ts +16 -0
  854. package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
  855. package/dist/core/toolkit/reflex-interpreter.js +21 -0
  856. package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
  857. package/dist/core/toolkit/script-registry.d.ts.map +1 -1
  858. package/dist/core/toolkit/script-registry.js.map +1 -1
  859. package/dist/core/toolkit/script-runner.d.ts.map +1 -1
  860. package/dist/core/toolkit/script-runner.js.map +1 -1
  861. package/dist/core/tools/artifact-retrieve.d.ts.map +1 -1
  862. package/dist/core/tools/artifact-retrieve.js.map +1 -1
  863. package/dist/core/tools/ask-question.d.ts +2 -3
  864. package/dist/core/tools/ask-question.d.ts.map +1 -1
  865. package/dist/core/tools/ask-question.js +14 -40
  866. package/dist/core/tools/ask-question.js.map +1 -1
  867. package/dist/core/tools/bash.d.ts +2 -0
  868. package/dist/core/tools/bash.d.ts.map +1 -1
  869. package/dist/core/tools/bash.js +83 -30
  870. package/dist/core/tools/bash.js.map +1 -1
  871. package/dist/core/tools/context-scout.d.ts.map +1 -1
  872. package/dist/core/tools/context-scout.js.map +1 -1
  873. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  874. package/dist/core/tools/delegate-status.js +9 -7
  875. package/dist/core/tools/delegate-status.js.map +1 -1
  876. package/dist/core/tools/delegate.d.ts.map +1 -1
  877. package/dist/core/tools/delegate.js +6 -6
  878. package/dist/core/tools/delegate.js.map +1 -1
  879. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  880. package/dist/core/tools/edit-diff.js.map +1 -1
  881. package/dist/core/tools/edit.d.ts.map +1 -1
  882. package/dist/core/tools/edit.js.map +1 -1
  883. package/dist/core/tools/extensionify.d.ts.map +1 -1
  884. package/dist/core/tools/extensionify.js.map +1 -1
  885. package/dist/core/tools/fff-search-backend.d.ts +19 -0
  886. package/dist/core/tools/fff-search-backend.d.ts.map +1 -1
  887. package/dist/core/tools/fff-search-backend.js +28 -2
  888. package/dist/core/tools/fff-search-backend.js.map +1 -1
  889. package/dist/core/tools/file-encoding-policy.d.ts.map +1 -1
  890. package/dist/core/tools/file-encoding-policy.js.map +1 -1
  891. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  892. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  893. package/dist/core/tools/find.d.ts +1 -1
  894. package/dist/core/tools/find.d.ts.map +1 -1
  895. package/dist/core/tools/find.js +44 -108
  896. package/dist/core/tools/find.js.map +1 -1
  897. package/dist/core/tools/git-filter.d.ts.map +1 -1
  898. package/dist/core/tools/git-filter.js.map +1 -1
  899. package/dist/core/tools/goal.d.ts.map +1 -1
  900. package/dist/core/tools/goal.js +7 -7
  901. package/dist/core/tools/goal.js.map +1 -1
  902. package/dist/core/tools/grep.d.ts +1 -1
  903. package/dist/core/tools/grep.d.ts.map +1 -1
  904. package/dist/core/tools/grep.js +42 -102
  905. package/dist/core/tools/grep.js.map +1 -1
  906. package/dist/core/tools/index.d.ts.map +1 -1
  907. package/dist/core/tools/index.js.map +1 -1
  908. package/dist/core/tools/ls.d.ts.map +1 -1
  909. package/dist/core/tools/ls.js +20 -36
  910. package/dist/core/tools/ls.js.map +1 -1
  911. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  912. package/dist/core/tools/model-fitness.js.map +1 -1
  913. package/dist/core/tools/orchestration-panel.d.ts +5 -0
  914. package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
  915. package/dist/core/tools/orchestration-panel.js +5 -5
  916. package/dist/core/tools/orchestration-panel.js.map +1 -1
  917. package/dist/core/tools/output-accumulator.d.ts +2 -0
  918. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  919. package/dist/core/tools/output-accumulator.js +24 -36
  920. package/dist/core/tools/output-accumulator.js.map +1 -1
  921. package/dist/core/tools/path-utils.d.ts.map +1 -1
  922. package/dist/core/tools/path-utils.js.map +1 -1
  923. package/dist/core/tools/persistent-process-coordinator.d.ts +31 -0
  924. package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -0
  925. package/dist/core/tools/persistent-process-coordinator.js +123 -0
  926. package/dist/core/tools/persistent-process-coordinator.js.map +1 -0
  927. package/dist/core/tools/python.d.ts.map +1 -1
  928. package/dist/core/tools/python.js.map +1 -1
  929. package/dist/core/tools/read.d.ts.map +1 -1
  930. package/dist/core/tools/read.js +14 -13
  931. package/dist/core/tools/read.js.map +1 -1
  932. package/dist/core/tools/render-utils.d.ts +29 -0
  933. package/dist/core/tools/render-utils.d.ts.map +1 -1
  934. package/dist/core/tools/render-utils.js +31 -1
  935. package/dist/core/tools/render-utils.js.map +1 -1
  936. package/dist/core/tools/run-process.d.ts.map +1 -1
  937. package/dist/core/tools/run-process.js.map +1 -1
  938. package/dist/core/tools/run-toolkit-script.d.ts.map +1 -1
  939. package/dist/core/tools/run-toolkit-script.js.map +1 -1
  940. package/dist/core/tools/search-command-guard.d.ts +10 -0
  941. package/dist/core/tools/search-command-guard.d.ts.map +1 -1
  942. package/dist/core/tools/search-command-guard.js +118 -31
  943. package/dist/core/tools/search-command-guard.js.map +1 -1
  944. package/dist/core/tools/search-router.d.ts.map +1 -1
  945. package/dist/core/tools/search-router.js.map +1 -1
  946. package/dist/core/tools/search-tool-runtime.d.ts +19 -0
  947. package/dist/core/tools/search-tool-runtime.d.ts.map +1 -0
  948. package/dist/core/tools/search-tool-runtime.js +12 -0
  949. package/dist/core/tools/search-tool-runtime.js.map +1 -0
  950. package/dist/core/tools/secret-store.d.ts.map +1 -1
  951. package/dist/core/tools/secret-store.js.map +1 -1
  952. package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
  953. package/dist/core/tools/shell-command-parser.js.map +1 -1
  954. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  955. package/dist/core/tools/shell-contract-router.js +4 -1
  956. package/dist/core/tools/shell-contract-router.js.map +1 -1
  957. package/dist/core/tools/shell-execution-session.d.ts +4 -0
  958. package/dist/core/tools/shell-execution-session.d.ts.map +1 -0
  959. package/dist/core/tools/shell-execution-session.js +11 -0
  960. package/dist/core/tools/shell-execution-session.js.map +1 -0
  961. package/dist/core/tools/shell-output-projection.d.ts +49 -0
  962. package/dist/core/tools/shell-output-projection.d.ts.map +1 -0
  963. package/dist/core/tools/shell-output-projection.js +381 -0
  964. package/dist/core/tools/shell-output-projection.js.map +1 -0
  965. package/dist/core/tools/shell-session.d.ts +2 -13
  966. package/dist/core/tools/shell-session.d.ts.map +1 -1
  967. package/dist/core/tools/shell-session.js +36 -136
  968. package/dist/core/tools/shell-session.js.map +1 -1
  969. package/dist/core/tools/skill-audit.d.ts.map +1 -1
  970. package/dist/core/tools/skill-audit.js.map +1 -1
  971. package/dist/core/tools/skillify.d.ts.map +1 -1
  972. package/dist/core/tools/skillify.js.map +1 -1
  973. package/dist/core/tools/task-steps.d.ts +8 -8
  974. package/dist/core/tools/task-steps.d.ts.map +1 -1
  975. package/dist/core/tools/task-steps.js +17 -18
  976. package/dist/core/tools/task-steps.js.map +1 -1
  977. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  978. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  979. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  980. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  981. package/dist/core/tools/tool-task.d.ts +23 -0
  982. package/dist/core/tools/tool-task.d.ts.map +1 -0
  983. package/dist/core/tools/tool-task.js +93 -0
  984. package/dist/core/tools/tool-task.js.map +1 -0
  985. package/dist/core/tools/windows-shell-engine.d.ts +17 -11
  986. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  987. package/dist/core/tools/windows-shell-engine.js +339 -117
  988. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  989. package/dist/core/tools/windows-shell-state.d.ts.map +1 -1
  990. package/dist/core/tools/windows-shell-state.js.map +1 -1
  991. package/dist/core/tools/worktree-sync.d.ts.map +1 -1
  992. package/dist/core/tools/worktree-sync.js +8 -12
  993. package/dist/core/tools/worktree-sync.js.map +1 -1
  994. package/dist/core/tools/write.d.ts.map +1 -1
  995. package/dist/core/tools/write.js +0 -1
  996. package/dist/core/tools/write.js.map +1 -1
  997. package/dist/core/trust-manager.d.ts.map +1 -1
  998. package/dist/core/trust-manager.js +7 -40
  999. package/dist/core/trust-manager.js.map +1 -1
  1000. package/dist/core/util/atomic-file.d.ts +19 -0
  1001. package/dist/core/util/atomic-file.d.ts.map +1 -1
  1002. package/dist/core/util/atomic-file.js +50 -15
  1003. package/dist/core/util/atomic-file.js.map +1 -1
  1004. package/dist/core/util/bounded-file.d.ts.map +1 -1
  1005. package/dist/core/util/bounded-file.js.map +1 -1
  1006. package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
  1007. package/dist/core/util/bounded-jsonl.js +2 -9
  1008. package/dist/core/util/bounded-jsonl.js.map +1 -1
  1009. package/dist/core/util/bounded-value.d.ts.map +1 -1
  1010. package/dist/core/util/bounded-value.js.map +1 -1
  1011. package/dist/core/util/json-size.d.ts +3 -0
  1012. package/dist/core/util/json-size.d.ts.map +1 -0
  1013. package/dist/core/util/json-size.js +95 -0
  1014. package/dist/core/util/json-size.js.map +1 -0
  1015. package/dist/core/util/minimatch-cache.d.ts.map +1 -1
  1016. package/dist/core/util/minimatch-cache.js.map +1 -1
  1017. package/dist/core/util/value-guards.d.ts.map +1 -1
  1018. package/dist/core/util/value-guards.js.map +1 -1
  1019. package/dist/core/worktree-sync/codes.d.ts.map +1 -1
  1020. package/dist/core/worktree-sync/git-engine.d.ts.map +1 -1
  1021. package/dist/core/worktree-sync/git-engine.js +20 -36
  1022. package/dist/core/worktree-sync/git-engine.js.map +1 -1
  1023. package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -1
  1024. package/dist/core/worktree-sync/lane-gate.js +1 -4
  1025. package/dist/core/worktree-sync/lane-gate.js.map +1 -1
  1026. package/dist/core/worktree-sync/runtime.d.ts.map +1 -1
  1027. package/dist/core/worktree-sync/runtime.js.map +1 -1
  1028. package/dist/core/worktree-sync/store.d.ts.map +1 -1
  1029. package/dist/core/worktree-sync/store.js.map +1 -1
  1030. package/dist/core/worktree-sync/watcher.d.ts.map +1 -1
  1031. package/dist/core/worktree-sync/watcher.js.map +1 -1
  1032. package/dist/index.d.ts.map +1 -1
  1033. package/dist/index.js.map +1 -1
  1034. package/dist/main.d.ts.map +1 -1
  1035. package/dist/main.js +10 -32
  1036. package/dist/main.js.map +1 -1
  1037. package/dist/migrations.d.ts.map +1 -1
  1038. package/dist/migrations.js +6 -19
  1039. package/dist/migrations.js.map +1 -1
  1040. package/dist/modes/index.d.ts.map +1 -1
  1041. package/dist/modes/interactive/auth-dialogs-controller.d.ts +3 -0
  1042. package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
  1043. package/dist/modes/interactive/auth-dialogs-controller.js +96 -132
  1044. package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
  1045. package/dist/modes/interactive/auto-learn-controller.d.ts +1 -31
  1046. package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
  1047. package/dist/modes/interactive/auto-learn-controller.js +86 -307
  1048. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  1049. package/dist/modes/interactive/autocomplete-provider.d.ts.map +1 -1
  1050. package/dist/modes/interactive/autocomplete-provider.js.map +1 -1
  1051. package/dist/modes/interactive/autonomy-commands.d.ts.map +1 -1
  1052. package/dist/modes/interactive/autonomy-commands.js +2 -8
  1053. package/dist/modes/interactive/autonomy-commands.js.map +1 -1
  1054. package/dist/modes/interactive/clipboard-input.d.ts +5 -1
  1055. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  1056. package/dist/modes/interactive/clipboard-input.js +17 -0
  1057. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  1058. package/dist/modes/interactive/compaction-queue.d.ts.map +1 -1
  1059. package/dist/modes/interactive/compaction-queue.js +13 -18
  1060. package/dist/modes/interactive/compaction-queue.js.map +1 -1
  1061. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
  1062. package/dist/modes/interactive/components/activity-lane.js +6 -10
  1063. package/dist/modes/interactive/components/activity-lane.js.map +1 -1
  1064. package/dist/modes/interactive/components/armin.d.ts +1 -0
  1065. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  1066. package/dist/modes/interactive/components/armin.js +10 -21
  1067. package/dist/modes/interactive/components/armin.js.map +1 -1
  1068. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  1069. package/dist/modes/interactive/components/assistant-message.js +1 -6
  1070. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  1071. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  1072. package/dist/modes/interactive/components/bash-execution.js +4 -9
  1073. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  1074. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  1075. package/dist/modes/interactive/components/bordered-loader.js +0 -3
  1076. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  1077. package/dist/modes/interactive/components/branch-summary-message.d.ts +3 -8
  1078. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  1079. package/dist/modes/interactive/components/branch-summary-message.js +13 -35
  1080. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  1081. package/dist/modes/interactive/components/compaction-summary-message.d.ts +3 -8
  1082. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  1083. package/dist/modes/interactive/components/compaction-summary-message.js +14 -36
  1084. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  1085. package/dist/modes/interactive/components/config-selector.d.ts +1 -0
  1086. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  1087. package/dist/modes/interactive/components/config-selector.js +20 -43
  1088. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  1089. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  1090. package/dist/modes/interactive/components/countdown-timer.js +0 -5
  1091. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  1092. package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
  1093. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  1094. package/dist/modes/interactive/components/custom-editor.js +4 -8
  1095. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  1096. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  1097. package/dist/modes/interactive/components/custom-message.js +1 -6
  1098. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  1099. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  1100. package/dist/modes/interactive/components/daxnuts.js +6 -8
  1101. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  1102. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  1103. package/dist/modes/interactive/components/diff.js.map +1 -1
  1104. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  1105. package/dist/modes/interactive/components/dynamic-border.js +0 -1
  1106. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  1107. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  1108. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  1109. package/dist/modes/interactive/components/expandable-markdown-message.d.ts +21 -0
  1110. package/dist/modes/interactive/components/expandable-markdown-message.d.ts.map +1 -0
  1111. package/dist/modes/interactive/components/expandable-markdown-message.js +48 -0
  1112. package/dist/modes/interactive/components/expandable-markdown-message.js.map +1 -0
  1113. package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -1
  1114. package/dist/modes/interactive/components/expandable-text.js +0 -2
  1115. package/dist/modes/interactive/components/expandable-text.js.map +1 -1
  1116. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  1117. package/dist/modes/interactive/components/extension-editor.js +1 -9
  1118. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  1119. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  1120. package/dist/modes/interactive/components/extension-input.js +2 -8
  1121. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  1122. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  1123. package/dist/modes/interactive/components/extension-selector.js +5 -20
  1124. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  1125. package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
  1126. package/dist/modes/interactive/components/fitness-role-selector.js +0 -1
  1127. package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
  1128. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  1129. package/dist/modes/interactive/components/footer.js +1 -5
  1130. package/dist/modes/interactive/components/footer.js.map +1 -1
  1131. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  1132. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  1133. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  1134. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  1135. package/dist/modes/interactive/components/login-dialog.js +4 -10
  1136. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  1137. package/dist/modes/interactive/components/model-selector.d.ts +2 -2
  1138. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  1139. package/dist/modes/interactive/components/model-selector.js +21 -44
  1140. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  1141. package/dist/modes/interactive/components/model-suggestion-selector.d.ts.map +1 -1
  1142. package/dist/modes/interactive/components/model-suggestion-selector.js +0 -1
  1143. package/dist/modes/interactive/components/model-suggestion-selector.js.map +1 -1
  1144. package/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
  1145. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  1146. package/dist/modes/interactive/components/oauth-selector.js +16 -32
  1147. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  1148. package/dist/modes/interactive/components/profile-resource-editor.d.ts +3 -4
  1149. package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
  1150. package/dist/modes/interactive/components/profile-resource-editor.js +34 -93
  1151. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  1152. package/dist/modes/interactive/components/profile-selector.d.ts.map +1 -1
  1153. package/dist/modes/interactive/components/profile-selector.js +0 -1
  1154. package/dist/modes/interactive/components/profile-selector.js.map +1 -1
  1155. package/dist/modes/interactive/components/scoped-models-selector.d.ts +3 -4
  1156. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  1157. package/dist/modes/interactive/components/scoped-models-selector.js +34 -79
  1158. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  1159. package/dist/modes/interactive/components/selector-list.d.ts +63 -0
  1160. package/dist/modes/interactive/components/selector-list.d.ts.map +1 -0
  1161. package/dist/modes/interactive/components/selector-list.js +186 -0
  1162. package/dist/modes/interactive/components/selector-list.js.map +1 -0
  1163. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  1164. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  1165. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  1166. package/dist/modes/interactive/components/session-selector.js +34 -59
  1167. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  1168. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  1169. package/dist/modes/interactive/components/settings-selector.js +40 -138
  1170. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  1171. package/dist/modes/interactive/components/show-images-selector.d.ts +2 -4
  1172. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  1173. package/dist/modes/interactive/components/show-images-selector.js +9 -28
  1174. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  1175. package/dist/modes/interactive/components/skill-invocation-message.d.ts +3 -8
  1176. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  1177. package/dist/modes/interactive/components/skill-invocation-message.js +12 -40
  1178. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  1179. package/dist/modes/interactive/components/theme-selector.d.ts +2 -5
  1180. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  1181. package/dist/modes/interactive/components/theme-selector.js +11 -37
  1182. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  1183. package/dist/modes/interactive/components/thinking-selector.d.ts +2 -4
  1184. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  1185. package/dist/modes/interactive/components/thinking-selector.js +9 -31
  1186. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  1187. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  1188. package/dist/modes/interactive/components/tool-execution.js +9 -28
  1189. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  1190. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
  1191. package/dist/modes/interactive/components/tool-group.js +2 -3
  1192. package/dist/modes/interactive/components/tool-group.js.map +1 -1
  1193. package/dist/modes/interactive/components/tool-panel-registry.d.ts.map +1 -1
  1194. package/dist/modes/interactive/components/tool-panel-registry.js +5 -3
  1195. package/dist/modes/interactive/components/tool-panel-registry.js.map +1 -1
  1196. package/dist/modes/interactive/components/tool-title.d.ts.map +1 -1
  1197. package/dist/modes/interactive/components/tool-title.js +0 -4
  1198. package/dist/modes/interactive/components/tool-title.js.map +1 -1
  1199. package/dist/modes/interactive/components/transcript-pager.d.ts +26 -0
  1200. package/dist/modes/interactive/components/transcript-pager.d.ts.map +1 -0
  1201. package/dist/modes/interactive/components/transcript-pager.js +81 -0
  1202. package/dist/modes/interactive/components/transcript-pager.js.map +1 -0
  1203. package/dist/modes/interactive/components/tree-selector.d.ts +1 -12
  1204. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  1205. package/dist/modes/interactive/components/tree-selector.js +42 -402
  1206. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  1207. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  1208. package/dist/modes/interactive/components/trust-selector.js +4 -16
  1209. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  1210. package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -1
  1211. package/dist/modes/interactive/components/usage-action-selector.js +2 -10
  1212. package/dist/modes/interactive/components/usage-action-selector.js.map +1 -1
  1213. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  1214. package/dist/modes/interactive/components/user-message-selector.js +3 -6
  1215. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  1216. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  1217. package/dist/modes/interactive/components/user-message.js +0 -1
  1218. package/dist/modes/interactive/components/user-message.js.map +1 -1
  1219. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  1220. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  1221. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  1222. package/dist/modes/interactive/config-backup.js.map +1 -1
  1223. package/dist/modes/interactive/editor-overlay-host.d.ts.map +1 -1
  1224. package/dist/modes/interactive/editor-overlay-host.js +0 -3
  1225. package/dist/modes/interactive/editor-overlay-host.js.map +1 -1
  1226. package/dist/modes/interactive/extension-ui-host.d.ts +2 -0
  1227. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  1228. package/dist/modes/interactive/extension-ui-host.js +51 -72
  1229. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  1230. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  1231. package/dist/modes/interactive/external-editor.js +2 -15
  1232. package/dist/modes/interactive/external-editor.js.map +1 -1
  1233. package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
  1234. package/dist/modes/interactive/history-reload-math.js.map +1 -1
  1235. package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -1
  1236. package/dist/modes/interactive/interactive-event-controller.js +23 -16
  1237. package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
  1238. package/dist/modes/interactive/interactive-mode.d.ts +13 -4
  1239. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  1240. package/dist/modes/interactive/interactive-mode.js +123 -204
  1241. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  1242. package/dist/modes/interactive/interactive-selection-prompts.d.ts +20 -0
  1243. package/dist/modes/interactive/interactive-selection-prompts.d.ts.map +1 -0
  1244. package/dist/modes/interactive/interactive-selection-prompts.js +43 -0
  1245. package/dist/modes/interactive/interactive-selection-prompts.js.map +1 -0
  1246. package/dist/modes/interactive/key-handlers.d.ts +2 -1
  1247. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  1248. package/dist/modes/interactive/key-handlers.js +4 -2
  1249. package/dist/modes/interactive/key-handlers.js.map +1 -1
  1250. package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -1
  1251. package/dist/modes/interactive/loaded-resources-view.js.map +1 -1
  1252. package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
  1253. package/dist/modes/interactive/local-model-commands.js +4 -9
  1254. package/dist/modes/interactive/local-model-commands.js.map +1 -1
  1255. package/dist/modes/interactive/model-fitness-presentation.d.ts +21 -0
  1256. package/dist/modes/interactive/model-fitness-presentation.d.ts.map +1 -0
  1257. package/dist/modes/interactive/model-fitness-presentation.js +13 -0
  1258. package/dist/modes/interactive/model-fitness-presentation.js.map +1 -0
  1259. package/dist/modes/interactive/profile-menu-controller.d.ts +2 -0
  1260. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  1261. package/dist/modes/interactive/profile-menu-controller.js +79 -171
  1262. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  1263. package/dist/modes/interactive/report-commands.d.ts +2 -0
  1264. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  1265. package/dist/modes/interactive/report-commands.js +12 -6
  1266. package/dist/modes/interactive/report-commands.js.map +1 -1
  1267. package/dist/modes/interactive/resource-display.d.ts.map +1 -1
  1268. package/dist/modes/interactive/resource-display.js.map +1 -1
  1269. package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
  1270. package/dist/modes/interactive/resource-shell-commands.js +6 -23
  1271. package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
  1272. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  1273. package/dist/modes/interactive/session-flow-commands.js +21 -25
  1274. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  1275. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  1276. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  1277. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -1
  1278. package/dist/modes/interactive/session-replacement-errors.js.map +1 -1
  1279. package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
  1280. package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
  1281. package/dist/modes/interactive/signal-lifecycle.d.ts.map +1 -1
  1282. package/dist/modes/interactive/signal-lifecycle.js.map +1 -1
  1283. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  1284. package/dist/modes/interactive/startup-checks.js +12 -8
  1285. package/dist/modes/interactive/startup-checks.js.map +1 -1
  1286. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  1287. package/dist/modes/interactive/theme/theme.js +10 -76
  1288. package/dist/modes/interactive/theme/theme.js.map +1 -1
  1289. package/dist/modes/interactive/usage-commands.d.ts.map +1 -1
  1290. package/dist/modes/interactive/usage-commands.js.map +1 -1
  1291. package/dist/modes/print-mode.d.ts.map +1 -1
  1292. package/dist/modes/print-mode.js +5 -22
  1293. package/dist/modes/print-mode.js.map +1 -1
  1294. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  1295. package/dist/modes/rpc/jsonl.js +1 -1
  1296. package/dist/modes/rpc/jsonl.js.map +1 -1
  1297. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  1298. package/dist/modes/rpc/rpc-client.js +7 -8
  1299. package/dist/modes/rpc/rpc-client.js.map +1 -1
  1300. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  1301. package/dist/modes/rpc/rpc-mode.js +5 -20
  1302. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  1303. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  1304. package/dist/modes/rpc/rpc-types.js.map +1 -1
  1305. package/dist/modes/termination-signals.d.ts +4 -0
  1306. package/dist/modes/termination-signals.d.ts.map +1 -0
  1307. package/dist/modes/termination-signals.js +21 -0
  1308. package/dist/modes/termination-signals.js.map +1 -0
  1309. package/dist/package-manager-cli.d.ts.map +1 -1
  1310. package/dist/package-manager-cli.js.map +1 -1
  1311. package/dist/utils/ansi-colors.d.ts +5 -0
  1312. package/dist/utils/ansi-colors.d.ts.map +1 -0
  1313. package/dist/utils/ansi-colors.js +38 -0
  1314. package/dist/utils/ansi-colors.js.map +1 -0
  1315. package/dist/utils/ansi.d.ts.map +1 -1
  1316. package/dist/utils/ansi.js.map +1 -1
  1317. package/dist/utils/changelog.d.ts.map +1 -1
  1318. package/dist/utils/changelog.js.map +1 -1
  1319. package/dist/utils/child-process.d.ts.map +1 -1
  1320. package/dist/utils/child-process.js.map +1 -1
  1321. package/dist/utils/clipboard-image.d.ts.map +1 -1
  1322. package/dist/utils/clipboard-image.js.map +1 -1
  1323. package/dist/utils/clipboard-native.d.ts.map +1 -1
  1324. package/dist/utils/clipboard-native.js.map +1 -1
  1325. package/dist/utils/clipboard.d.ts.map +1 -1
  1326. package/dist/utils/clipboard.js.map +1 -1
  1327. package/dist/utils/deprecation.d.ts.map +1 -1
  1328. package/dist/utils/deprecation.js.map +1 -1
  1329. package/dist/utils/exif-orientation.d.ts.map +1 -1
  1330. package/dist/utils/exif-orientation.js.map +1 -1
  1331. package/dist/utils/external-editor-command.d.ts.map +1 -1
  1332. package/dist/utils/external-editor-command.js.map +1 -1
  1333. package/dist/utils/frontmatter.d.ts.map +1 -1
  1334. package/dist/utils/frontmatter.js.map +1 -1
  1335. package/dist/utils/fs-watch.d.ts.map +1 -1
  1336. package/dist/utils/fs-watch.js.map +1 -1
  1337. package/dist/utils/git.d.ts.map +1 -1
  1338. package/dist/utils/git.js +20 -28
  1339. package/dist/utils/git.js.map +1 -1
  1340. package/dist/utils/highlight-js-languages.d.ts.map +1 -1
  1341. package/dist/utils/html.d.ts.map +1 -1
  1342. package/dist/utils/html.js.map +1 -1
  1343. package/dist/utils/image-convert.d.ts.map +1 -1
  1344. package/dist/utils/image-convert.js.map +1 -1
  1345. package/dist/utils/image-resize-core.d.ts.map +1 -1
  1346. package/dist/utils/image-resize-core.js.map +1 -1
  1347. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  1348. package/dist/utils/image-resize-worker.js.map +1 -1
  1349. package/dist/utils/image-resize.d.ts.map +1 -1
  1350. package/dist/utils/image-resize.js.map +1 -1
  1351. package/dist/utils/json.d.ts.map +1 -1
  1352. package/dist/utils/json.js.map +1 -1
  1353. package/dist/utils/mime.d.ts.map +1 -1
  1354. package/dist/utils/mime.js.map +1 -1
  1355. package/dist/utils/open-browser.d.ts.map +1 -1
  1356. package/dist/utils/open-browser.js.map +1 -1
  1357. package/dist/utils/paths.d.ts.map +1 -1
  1358. package/dist/utils/paths.js.map +1 -1
  1359. package/dist/utils/photon.d.ts.map +1 -1
  1360. package/dist/utils/photon.js.map +1 -1
  1361. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  1362. package/dist/utils/pi-user-agent.js.map +1 -1
  1363. package/dist/utils/platform.d.ts.map +1 -1
  1364. package/dist/utils/platform.js.map +1 -1
  1365. package/dist/utils/process-memory.d.ts.map +1 -1
  1366. package/dist/utils/process-memory.js.map +1 -1
  1367. package/dist/utils/safe-write-stream.d.ts.map +1 -1
  1368. package/dist/utils/safe-write-stream.js.map +1 -1
  1369. package/dist/utils/shell.d.ts.map +1 -1
  1370. package/dist/utils/shell.js.map +1 -1
  1371. package/dist/utils/sleep.d.ts.map +1 -1
  1372. package/dist/utils/sleep.js +2 -15
  1373. package/dist/utils/sleep.js.map +1 -1
  1374. package/dist/utils/stdin-events.d.ts +8 -0
  1375. package/dist/utils/stdin-events.d.ts.map +1 -0
  1376. package/dist/utils/stdin-events.js +19 -0
  1377. package/dist/utils/stdin-events.js.map +1 -0
  1378. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  1379. package/dist/utils/syntax-highlight.js +20 -13
  1380. package/dist/utils/syntax-highlight.js.map +1 -1
  1381. package/dist/utils/tools-manager.d.ts.map +1 -1
  1382. package/dist/utils/tools-manager.js.map +1 -1
  1383. package/dist/utils/version-check.d.ts.map +1 -1
  1384. package/dist/utils/version-check.js.map +1 -1
  1385. package/dist/utils/windows-self-update.d.ts.map +1 -1
  1386. package/dist/utils/windows-self-update.js.map +1 -1
  1387. package/dist/utils/work-directory.d.ts.map +1 -1
  1388. package/dist/utils/work-directory.js.map +1 -1
  1389. package/docs/compaction.md +11 -3
  1390. package/docs/sessions.md +6 -0
  1391. package/docs/settings.md +1 -1
  1392. package/docs/windows.md +26 -1
  1393. package/docs/work-directory.md +9 -1
  1394. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  1395. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  1396. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  1397. package/examples/extensions/sandbox/package-lock.json +2 -2
  1398. package/examples/extensions/sandbox/package.json +1 -1
  1399. package/examples/extensions/with-deps/package-lock.json +2 -2
  1400. package/examples/extensions/with-deps/package.json +1 -1
  1401. package/npm-shrinkwrap.json +16 -16
  1402. package/package.json +10 -10
  1403. package/dist/utils/streaming-lines.d.ts +0 -20
  1404. package/dist/utils/streaming-lines.d.ts.map +0 -1
  1405. package/dist/utils/streaming-lines.js +0 -79
  1406. package/dist/utils/streaming-lines.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tool-performance-store.js","sourceRoot":"","sources":["../../../src/core/tool-selection/tool-performance-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAwB,cAAc,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAC1C,MAAM,UAAU,GAAG,IAAI,CAAC;AAsGxB,SAAS,OAAO,CAAC,GAAuB,EAAU;IACjD,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,WAAW,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;AAAA,CAC1D;AAED,SAAS,kBAAkB,CAAC,QAAgB,EA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AC;SACvG,CAAC;IAAA,CACF;IAED,eAAe,CAAC,QAAiB,EAA8B;QAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACpC,OAAO,CAAC,IAAI,EAAE,YAAY,IAAI,EAAE,CAAC;aAC/B,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,QAAQ,KAAK,SAAS,IAAI,WAAW,CAAC,QAAQ,KAAK,QAAQ,CAAC;aACpF,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YACtB,GAAG,WAAW;YACd,SAAS,EAAE,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC;YACrC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;SACjE,CAAC,CAAC,CAAC;IAAA,CACL;CACD","sourcesContent":["import { stateFile } from \"../agent-paths.ts\";\nimport { type HostFingerprint, HostStateStore, isHostFingerprint } from \"../models/host-state-store.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { isRecordObject } from \"../util/value-guards.ts\";\n\nconst STORE_VERSION = 1;\nconst MAX_STATS_PER_HOST = 500;\nconst MAX_OBSERVATIONS_PER_HOST = 1_000;\nconst MAX_INTENT_AGREEMENT_PER_HOST = 500;\nconst EWMA_ALPHA = 0.25;\n\nexport type ToolSelectionIntentClass = \"read\" | \"search\" | \"execute\" | \"write\" | \"retrieve\" | \"explain\" | \"other\";\n\nexport interface ToolPerformanceKey {\n\tmodelRef: string;\n\tintentClass: ToolSelectionIntentClass;\n\ttool: string;\n}\n\nexport interface ToolPerformanceStats extends ToolPerformanceKey {\n\talpha: number;\n\tbeta: number;\n\tsampleCount: number;\n\tlatencyEwmaMs?: number;\n\tlatencyDeviationEwmaMs?: number;\n\tinputTokenEstimateEwma?: number;\n\toutputTokenEstimateEwma?: number;\n\trepairCount: number;\n\tbounceCount: number;\n\tfailureCount: number;\n\tlastUsedAt: string;\n}\n\nexport interface ToolSelectionObservation {\n\tat: string;\n\tmodelRef: string;\n\tintentClass: ToolSelectionIntentClass;\n\tactualTool: string;\n\tfirstTool: boolean;\n\tsucceeded: boolean;\n\tdisposition: \"recommend\" | \"shortlist\" | \"abstain\";\n\trecommendation?: string;\n\tshortlist: string[];\n\tentropy: number;\n\tmargin: number;\n\t/** Redacted ranking: names and numeric scores only, never prompts, arguments, paths, or output. */\n\tranked: Array<{ tool: string; utility: number; probability: number }>;\n\tlatencyMs?: number;\n\tinputTokenEstimate?: number;\n\toutputTokenEstimate?: number;\n}\n\nexport interface ToolSelectionMetrics {\n\tfirstToolAttempts: number;\n\tfirstToolSuccesses: number;\n\twrongToolOrFailureCount: number;\n\trecommendationCount: number;\n\trecommendationMatchedCount: number;\n\tshortlistCount: number;\n\tabstentionCount: number;\n\taverageLatencyMs?: number;\n\taverageInputTokenEstimate?: number;\n\taverageOutputTokenEstimate?: number;\n}\n\n/**\n * Durable, per-(model,intent) aggregate of the observe-mode loop: does the raw expected-utility\n * ranking's top pick (`ToolSelectionObservation.ranked[0]`) match what the model actually called\n * (`ToolSelectionObservation.actualTool`)? Tracked separately from the capped, rolling\n * `observations` log so evidence for a given (model,intent) pair survives that log's trimming.\n * `hintActive*` fields are the SAME agreement measure, but restricted to calls made while an\n * evidence-gated promotion hint (see promotion.ts) was active for this bucket — the hint's own\n * efficacy trace: it never gates activation directly (that is always\n * recomputed live from `ToolPerformanceStats`), but it is the durable evidence a report can show\n * for \"is the hint still earning its keep\".\n */\nexport interface ToolSelectionIntentAgreement {\n\tmodelRef: string;\n\tintentClass: ToolSelectionIntentClass;\n\tsampleCount: number;\n\tagreementCount: number;\n\thintActiveSampleCount: number;\n\thintActiveAgreementCount: number;\n\tlastUpdatedAt: string;\n}\n\ninterface HostToolPerformanceData {\n\thost: HostFingerprint;\n\tstats: Record<string, ToolPerformanceStats>;\n\tobservations: ToolSelectionObservation[];\n\tintentAgreement: Record<string, ToolSelectionIntentAgreement>;\n}\n\nexport interface ToolExecutionObservation {\n\tkey: ToolPerformanceKey;\n\tsuccess: boolean;\n\tlatencyMs: number;\n\tinputTokenEstimate?: number;\n\toutputTokenEstimate?: number;\n\tselection: Omit<ToolSelectionObservation, \"at\" | \"modelRef\" | \"intentClass\" | \"actualTool\" | \"succeeded\">;\n\tat?: string;\n\t/**\n\t * Whether an evidence-gated promotion hint (promotion.ts) was already active for this\n\t * (model,intent) bucket BEFORE this call was recorded — captured by the controller at\n\t * `begin()` time, so it reflects evidence up to but not including this observation. Used only\n\t * to bucket the durable agreement stats (`ToolSelectionIntentAgreement.hintActive*`); never\n\t * changes what gets recorded, only how it is split for the efficacy report.\n\t */\n\thintActiveAtCallTime?: boolean;\n}\n\nfunction statKey(key: ToolPerformanceKey): string {\n\treturn `${key.modelRef}\\0${key.intentClass}\\0${key.tool}`;\n}\n\nfunction intentAgreementKey(modelRef: string, intentClass: ToolSelectionIntentClass): string {\n\treturn `${modelRef}\\0${intentClass}`;\n}\n\nfunction isIntentClass(value: unknown): value is ToolSelectionIntentClass {\n\treturn (\n\t\tvalue === \"read\" ||\n\t\tvalue === \"search\" ||\n\t\tvalue === \"execute\" ||\n\t\tvalue === \"write\" ||\n\t\tvalue === \"retrieve\" ||\n\t\tvalue === \"explain\" ||\n\t\tvalue === \"other\"\n\t);\n}\n\nfunction isStats(value: unknown): value is ToolPerformanceStats {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.modelRef === \"string\" &&\n\t\tisIntentClass(value.intentClass) &&\n\t\ttypeof value.tool === \"string\" &&\n\t\ttypeof value.alpha === \"number\" &&\n\t\ttypeof value.beta === \"number\" &&\n\t\ttypeof value.sampleCount === \"number\" &&\n\t\ttypeof value.repairCount === \"number\" &&\n\t\ttypeof value.bounceCount === \"number\" &&\n\t\ttypeof value.failureCount === \"number\" &&\n\t\ttypeof value.lastUsedAt === \"string\"\n\t);\n}\n\nfunction isObservation(value: unknown): value is ToolSelectionObservation {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.at === \"string\" &&\n\t\ttypeof value.modelRef === \"string\" &&\n\t\tisIntentClass(value.intentClass) &&\n\t\ttypeof value.actualTool === \"string\" &&\n\t\ttypeof value.firstTool === \"boolean\" &&\n\t\ttypeof value.succeeded === \"boolean\" &&\n\t\t(value.disposition === \"recommend\" || value.disposition === \"shortlist\" || value.disposition === \"abstain\") &&\n\t\tArray.isArray(value.shortlist) &&\n\t\tvalue.shortlist.every((tool) => typeof tool === \"string\") &&\n\t\ttypeof value.entropy === \"number\" &&\n\t\ttypeof value.margin === \"number\" &&\n\t\tArray.isArray(value.ranked) &&\n\t\tvalue.ranked.every(\n\t\t\t(entry) =>\n\t\t\t\tisRecordObject(entry) &&\n\t\t\t\ttypeof entry.tool === \"string\" &&\n\t\t\t\ttypeof entry.utility === \"number\" &&\n\t\t\t\ttypeof entry.probability === \"number\",\n\t\t) &&\n\t\t(value.latencyMs === undefined || typeof value.latencyMs === \"number\") &&\n\t\t(value.inputTokenEstimate === undefined || typeof value.inputTokenEstimate === \"number\") &&\n\t\t(value.outputTokenEstimate === undefined || typeof value.outputTokenEstimate === \"number\")\n\t);\n}\n\nfunction isIntentAgreement(value: unknown): value is ToolSelectionIntentAgreement {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.modelRef === \"string\" &&\n\t\tisIntentClass(value.intentClass) &&\n\t\ttypeof value.sampleCount === \"number\" &&\n\t\ttypeof value.agreementCount === \"number\" &&\n\t\ttypeof value.hintActiveSampleCount === \"number\" &&\n\t\ttypeof value.hintActiveAgreementCount === \"number\" &&\n\t\ttypeof value.lastUpdatedAt === \"string\"\n\t);\n}\n\nfunction emptyStats(key: ToolPerformanceKey, at: string): ToolPerformanceStats {\n\treturn {\n\t\t...key,\n\t\talpha: 1,\n\t\tbeta: 1,\n\t\tsampleCount: 0,\n\t\trepairCount: 0,\n\t\tbounceCount: 0,\n\t\tfailureCount: 0,\n\t\tlastUsedAt: at,\n\t};\n}\n\nfunction emptyIntentAgreement(\n\tmodelRef: string,\n\tintentClass: ToolSelectionIntentClass,\n\tat: string,\n): ToolSelectionIntentAgreement {\n\treturn {\n\t\tmodelRef,\n\t\tintentClass,\n\t\tsampleCount: 0,\n\t\tagreementCount: 0,\n\t\thintActiveSampleCount: 0,\n\t\thintActiveAgreementCount: 0,\n\t\tlastUpdatedAt: at,\n\t};\n}\n\nfunction finiteNonNegative(value: number | undefined): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value >= 0 ? value : undefined;\n}\n\nfunction updateEwma(previous: number | undefined, next: number | undefined): number | undefined {\n\tif (next === undefined) return previous;\n\treturn previous === undefined ? next : previous + EWMA_ALPHA * (next - previous);\n}\n\nfunction updateDeviation(\n\tpreviousValue: number | undefined,\n\tpreviousDeviation: number | undefined,\n\tnext: number | undefined,\n): number | undefined {\n\tif (next === undefined) return previousDeviation;\n\tconst deviation = previousValue === undefined ? 0 : Math.abs(next - previousValue);\n\treturn updateEwma(previousDeviation, deviation);\n}\n\nfunction parseHost(value: unknown, hostId: string): HostToolPerformanceData | undefined {\n\tif (\n\t\t!isRecordObject(value) ||\n\t\t!isHostFingerprint(value.host) ||\n\t\tvalue.host.id !== hostId ||\n\t\t!isRecordObject(value.stats) ||\n\t\t!Array.isArray(value.observations)\n\t)\n\t\treturn undefined;\n\tconst host = value.host;\n\t// intentAgreement is a purely additive field (older store files predate it) — tolerate absence\n\t// rather than bumping STORE_VERSION, same as any other backward-compatible default-empty field.\n\tconst intentAgreementRaw = isRecordObject(value.intentAgreement) ? value.intentAgreement : {};\n\treturn {\n\t\thost,\n\t\tstats: Object.fromEntries(\n\t\t\tObject.entries(value.stats).filter((entry): entry is [string, ToolPerformanceStats] => isStats(entry[1])),\n\t\t),\n\t\tobservations: value.observations.filter(isObservation),\n\t\tintentAgreement: Object.fromEntries(\n\t\t\tObject.entries(intentAgreementRaw).filter((entry): entry is [string, ToolSelectionIntentAgreement] =>\n\t\t\t\tisIntentAgreement(entry[1]),\n\t\t\t),\n\t\t),\n\t};\n}\n\nfunction trimStats(stats: Record<string, ToolPerformanceStats>): Record<string, ToolPerformanceStats> {\n\tconst entries = Object.entries(stats);\n\tif (entries.length <= MAX_STATS_PER_HOST) return stats;\n\treturn Object.fromEntries(\n\t\tentries\n\t\t\t.sort(([, left], [, right]) => Date.parse(right.lastUsedAt) - Date.parse(left.lastUsedAt))\n\t\t\t.slice(0, MAX_STATS_PER_HOST),\n\t);\n}\n\nfunction trimIntentAgreement(\n\trecords: Record<string, ToolSelectionIntentAgreement>,\n): Record<string, ToolSelectionIntentAgreement> {\n\tconst entries = Object.entries(records);\n\tif (entries.length <= MAX_INTENT_AGREEMENT_PER_HOST) return records;\n\treturn Object.fromEntries(\n\t\tentries\n\t\t\t.sort(([, left], [, right]) => Date.parse(right.lastUpdatedAt) - Date.parse(left.lastUpdatedAt))\n\t\t\t.slice(0, MAX_INTENT_AGREEMENT_PER_HOST),\n\t);\n}\n\nexport class ToolPerformanceStore {\n\tprivate readonly storage: HostStateStore<HostToolPerformanceData>;\n\n\tconstructor(filePath: string, options: { fingerprint?: () => HostFingerprint; readOnly?: boolean } = {}) {\n\t\tthis.storage = new HostStateStore({\n\t\t\tfilePath,\n\t\t\tversion: STORE_VERSION,\n\t\t\tfingerprint: options.fingerprint,\n\t\t\treadOnly: options.readOnly ?? isWorkerSession(),\n\t\t\tparseHost,\n\t\t});\n\t}\n\n\tstatic forAgentDir(\n\t\tagentDir: string,\n\t\toptions: { fingerprint?: () => HostFingerprint; readOnly?: boolean } = {},\n\t): ToolPerformanceStore {\n\t\treturn new ToolPerformanceStore(stateFile(agentDir, \"tool-performance.json\"), options);\n\t}\n\n\tprivate createHostData(host: HostFingerprint): HostToolPerformanceData {\n\t\treturn { host, stats: {}, observations: [], intentAgreement: {} };\n\t}\n\n\tget(key: ToolPerformanceKey): ToolPerformanceStats {\n\t\tconst host = this.storage.getHost();\n\t\tconst stats = host?.stats[statKey(key)];\n\t\treturn stats ? { ...stats } : emptyStats(key, new Date(0).toISOString());\n\t}\n\n\t/** Every per-tool track record recorded for a (model,intent) bucket — the promotion.ts input. */\n\tgetStatsForIntent(modelRef: string, intentClass: ToolSelectionIntentClass): ToolPerformanceStats[] {\n\t\tconst host = this.storage.getHost();\n\t\tif (!host) return [];\n\t\treturn Object.values(host.stats)\n\t\t\t.filter((stats) => stats.modelRef === modelRef && stats.intentClass === intentClass)\n\t\t\t.map((stats) => ({ ...stats }));\n\t}\n\n\t/** Durable observe-mode agreement for one (model,intent) bucket (see {@link ToolSelectionIntentAgreement}). */\n\tgetIntentAgreement(modelRef: string, intentClass: ToolSelectionIntentClass): ToolSelectionIntentAgreement {\n\t\tconst host = this.storage.getHost();\n\t\tconst record = host?.intentAgreement[intentAgreementKey(modelRef, intentClass)];\n\t\treturn record ? { ...record } : emptyIntentAgreement(modelRef, intentClass, new Date(0).toISOString());\n\t}\n\n\t/** All recorded (model,intent) agreement buckets, optionally scoped to one model — report input. */\n\tgetAllIntentAgreements(modelRef?: string): ToolSelectionIntentAgreement[] {\n\t\tconst host = this.storage.getHost();\n\t\treturn Object.values(host?.intentAgreement ?? {})\n\t\t\t.filter((record) => modelRef === undefined || record.modelRef === modelRef)\n\t\t\t.map((record) => ({ ...record }));\n\t}\n\n\trecordValidation(\n\t\tkey: ToolPerformanceKey,\n\t\toutcome: \"repaired\" | \"bounced\",\n\t\tat = new Date().toISOString(),\n\t): ToolPerformanceStats {\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t(host) => this.createHostData(host),\n\t\t\t(host) => {\n\t\t\t\tconst storageKey = statKey(key);\n\t\t\t\tconst current = host.stats[storageKey] ?? emptyStats(key, at);\n\t\t\t\tconst next: ToolPerformanceStats = {\n\t\t\t\t\t...current,\n\t\t\t\t\trepairCount: current.repairCount + (outcome === \"repaired\" ? 1 : 0),\n\t\t\t\t\tbounceCount: current.bounceCount + (outcome === \"bounced\" ? 1 : 0),\n\t\t\t\t\tlastUsedAt: at,\n\t\t\t\t};\n\t\t\t\thost.stats[storageKey] = next;\n\t\t\t\thost.stats = trimStats(host.stats);\n\t\t\t\treturn { result: { ...next }, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\trecordExecution(observation: ToolExecutionObservation): ToolPerformanceStats {\n\t\tconst at = observation.at ?? new Date().toISOString();\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t(host) => this.createHostData(host),\n\t\t\t(host) => {\n\t\t\t\tconst storageKey = statKey(observation.key);\n\t\t\t\tconst current = host.stats[storageKey] ?? emptyStats(observation.key, at);\n\t\t\t\tconst latencyMs = finiteNonNegative(observation.latencyMs);\n\t\t\t\tconst inputTokenEstimate = finiteNonNegative(observation.inputTokenEstimate);\n\t\t\t\tconst outputTokenEstimate = finiteNonNegative(observation.outputTokenEstimate);\n\t\t\t\tconst next: ToolPerformanceStats = {\n\t\t\t\t\t...current,\n\t\t\t\t\talpha: current.alpha + (observation.success ? 1 : 0),\n\t\t\t\t\tbeta: current.beta + (observation.success ? 0 : 1),\n\t\t\t\t\tsampleCount: current.sampleCount + 1,\n\t\t\t\t\tlatencyEwmaMs: updateEwma(current.latencyEwmaMs, latencyMs),\n\t\t\t\t\tlatencyDeviationEwmaMs: updateDeviation(\n\t\t\t\t\t\tcurrent.latencyEwmaMs,\n\t\t\t\t\t\tcurrent.latencyDeviationEwmaMs,\n\t\t\t\t\t\tlatencyMs,\n\t\t\t\t\t),\n\t\t\t\t\tinputTokenEstimateEwma: updateEwma(current.inputTokenEstimateEwma, inputTokenEstimate),\n\t\t\t\t\toutputTokenEstimateEwma: updateEwma(current.outputTokenEstimateEwma, outputTokenEstimate),\n\t\t\t\t\tfailureCount: current.failureCount + (observation.success ? 0 : 1),\n\t\t\t\t\tlastUsedAt: at,\n\t\t\t\t};\n\t\t\t\thost.stats[storageKey] = next;\n\t\t\t\thost.stats = trimStats(host.stats);\n\t\t\t\thost.observations.push({\n\t\t\t\t\t...observation.selection,\n\t\t\t\t\tat,\n\t\t\t\t\tmodelRef: observation.key.modelRef,\n\t\t\t\t\tintentClass: observation.key.intentClass,\n\t\t\t\t\tactualTool: observation.key.tool,\n\t\t\t\t\tsucceeded: observation.success,\n\t\t\t\t\tranked: observation.selection.ranked.slice(0, 6),\n\t\t\t\t\tshortlist: observation.selection.shortlist.slice(0, 3),\n\t\t\t\t\tlatencyMs,\n\t\t\t\t\tinputTokenEstimate,\n\t\t\t\t\toutputTokenEstimate,\n\t\t\t\t});\n\t\t\t\tif (host.observations.length > MAX_OBSERVATIONS_PER_HOST) {\n\t\t\t\t\thost.observations = host.observations.slice(-MAX_OBSERVATIONS_PER_HOST);\n\t\t\t\t}\n\n\t\t\t\t// Observe-mode agreement: did the RAW ranking's top pick (before any actual-tool-only\n\t\t\t\t// eligibility gating) match what the model actually called? Recorded durably per\n\t\t\t\t// (model,intent), separate from the capped `observations` log above, so it survives trimming.\n\t\t\t\tconst predictedBest = observation.selection.ranked[0]?.tool;\n\t\t\t\tconst agreed = predictedBest !== undefined && predictedBest === observation.key.tool;\n\t\t\t\tconst agreementKey = intentAgreementKey(observation.key.modelRef, observation.key.intentClass);\n\t\t\t\tconst currentAgreement =\n\t\t\t\t\thost.intentAgreement[agreementKey] ??\n\t\t\t\t\temptyIntentAgreement(observation.key.modelRef, observation.key.intentClass, at);\n\t\t\t\thost.intentAgreement[agreementKey] = {\n\t\t\t\t\t...currentAgreement,\n\t\t\t\t\tsampleCount: currentAgreement.sampleCount + 1,\n\t\t\t\t\tagreementCount: currentAgreement.agreementCount + (agreed ? 1 : 0),\n\t\t\t\t\thintActiveSampleCount:\n\t\t\t\t\t\tcurrentAgreement.hintActiveSampleCount + (observation.hintActiveAtCallTime ? 1 : 0),\n\t\t\t\t\thintActiveAgreementCount:\n\t\t\t\t\t\tcurrentAgreement.hintActiveAgreementCount + (observation.hintActiveAtCallTime && agreed ? 1 : 0),\n\t\t\t\t\tlastUpdatedAt: at,\n\t\t\t\t};\n\t\t\t\thost.intentAgreement = trimIntentAgreement(host.intentAgreement);\n\n\t\t\t\treturn { result: { ...next }, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\tgetMetrics(modelRef?: string): ToolSelectionMetrics {\n\t\tconst host = this.storage.getHost();\n\t\tconst observations = (host?.observations ?? []).filter(\n\t\t\t(observation) => modelRef === undefined || observation.modelRef === modelRef,\n\t\t);\n\t\tconst firstTools = observations.filter((observation) => observation.firstTool);\n\t\tconst recommended = observations.filter((observation) => observation.disposition === \"recommend\");\n\t\tconst average = (values: Array<number | undefined>): number | undefined => {\n\t\t\tconst present = values.filter((value): value is number => value !== undefined);\n\t\t\treturn present.length > 0 ? present.reduce((sum, value) => sum + value, 0) / present.length : undefined;\n\t\t};\n\t\treturn {\n\t\t\tfirstToolAttempts: firstTools.length,\n\t\t\tfirstToolSuccesses: firstTools.filter((observation) => observation.succeeded).length,\n\t\t\twrongToolOrFailureCount: observations.filter(\n\t\t\t\t(observation) =>\n\t\t\t\t\t!observation.succeeded ||\n\t\t\t\t\t(observation.disposition === \"recommend\" && observation.recommendation !== observation.actualTool),\n\t\t\t).length,\n\t\t\trecommendationCount: recommended.length,\n\t\t\trecommendationMatchedCount: recommended.filter(\n\t\t\t\t(observation) => observation.recommendation === observation.actualTool,\n\t\t\t).length,\n\t\t\tshortlistCount: observations.filter((observation) => observation.disposition === \"shortlist\").length,\n\t\t\tabstentionCount: observations.filter((observation) => observation.disposition === \"abstain\").length,\n\t\t\taverageLatencyMs: average(observations.map((observation) => observation.latencyMs)),\n\t\t\taverageInputTokenEstimate: average(observations.map((observation) => observation.inputTokenEstimate)),\n\t\t\taverageOutputTokenEstimate: average(observations.map((observation) => observation.outputTokenEstimate)),\n\t\t};\n\t}\n\n\tgetObservations(modelRef?: string): ToolSelectionObservation[] {\n\t\tconst host = this.storage.getHost();\n\t\treturn (host?.observations ?? [])\n\t\t\t.filter((observation) => modelRef === undefined || observation.modelRef === modelRef)\n\t\t\t.map((observation) => ({\n\t\t\t\t...observation,\n\t\t\t\tshortlist: [...observation.shortlist],\n\t\t\t\tranked: observation.ranked.map((candidate) => ({ ...candidate })),\n\t\t\t}));\n\t}\n}\n"]}
1
+ {"version":3,"file":"tool-performance-store.js","sourceRoot":"","sources":["../../../src/core/tool-selection/tool-performance-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAwB,cAAc,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,8BAA8B,GAAG,GAAG,GAAG,IAAI,CAAC;AAClD,MAAM,iCAAiC,GAAG,GAAG,GAAG,IAAI,CAAC;AACrD,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAC1C,MAAM,UAAU,GAAG,IAAI,CAAC;AAuGxB,SAAS,OAAO,CAAC,GAAuB;IACvC,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,WAAW,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;AAC3D,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAgB,EAAE,WAAqC;IAClF,OAAO,GAAG,QAAQ,KAAK,WAAW,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACpC,OAAO,CACN,KAAK,KAAK,MAAM;QAChB,KAAK,KAAK,QAAQ;QAClB,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,OAAO;QACjB,KAAK,KAAK,UAAU;QACpB,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,OAAO,CACjB,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC9B,OAAO,CACN,cAAc,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CAAC,MAAM;YACnG,gBAAgB,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;YACnF,yBAAyB,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;YACrG,0BAA0B,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;SACvG,CAAC;IACH,CAAC;IAED,eAAe,CAAC,QAAiB;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACpC,OAAO,CAAC,IAAI,EAAE,YAAY,IAAI,EAAE,CAAC;aAC/B,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,QAAQ,KAAK,SAAS,IAAI,WAAW,CAAC,QAAQ,KAAK,QAAQ,CAAC;aACpF,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YACtB,GAAG,WAAW;YACd,SAAS,EAAE,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC;YACrC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;SACjE,CAAC,CAAC,CAAC;IACN,CAAC;CACD","sourcesContent":["import { stateFile } from \"../agent-paths.ts\";\nimport { type HostFingerprint, HostStateStore, isHostFingerprint } from \"../models/host-state-store.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { isRecordObject } from \"../util/value-guards.ts\";\n\nconst STORE_VERSION = 1;\nconst MAX_STATS_PER_HOST = 500;\nconst MAX_OBSERVATIONS_PER_HOST = 1_000;\nconst MAX_OBSERVATION_BYTES_PER_HOST = 256 * 1024;\nconst TARGET_OBSERVATION_BYTES_PER_HOST = 192 * 1024;\nconst MAX_INTENT_AGREEMENT_PER_HOST = 500;\nconst EWMA_ALPHA = 0.25;\n\nexport type ToolSelectionIntentClass = \"read\" | \"search\" | \"execute\" | \"write\" | \"retrieve\" | \"explain\" | \"other\";\n\nexport interface ToolPerformanceKey {\n\tmodelRef: string;\n\tintentClass: ToolSelectionIntentClass;\n\ttool: string;\n}\n\nexport interface ToolPerformanceStats extends ToolPerformanceKey {\n\talpha: number;\n\tbeta: number;\n\tsampleCount: number;\n\tlatencyEwmaMs?: number;\n\tlatencyDeviationEwmaMs?: number;\n\tinputTokenEstimateEwma?: number;\n\toutputTokenEstimateEwma?: number;\n\trepairCount: number;\n\tbounceCount: number;\n\tfailureCount: number;\n\tlastUsedAt: string;\n}\n\nexport interface ToolSelectionObservation {\n\tat: string;\n\tmodelRef: string;\n\tintentClass: ToolSelectionIntentClass;\n\tactualTool: string;\n\tfirstTool: boolean;\n\tsucceeded: boolean;\n\tdisposition: \"recommend\" | \"shortlist\" | \"abstain\";\n\trecommendation?: string;\n\tshortlist: string[];\n\tentropy: number;\n\tmargin: number;\n\t/** Redacted ranking: names and numeric scores only, never prompts, arguments, paths, or output. */\n\tranked: Array<{ tool: string; utility: number; probability: number }>;\n\tlatencyMs?: number;\n\tinputTokenEstimate?: number;\n\toutputTokenEstimate?: number;\n}\n\nexport interface ToolSelectionMetrics {\n\tfirstToolAttempts: number;\n\tfirstToolSuccesses: number;\n\twrongToolOrFailureCount: number;\n\trecommendationCount: number;\n\trecommendationMatchedCount: number;\n\tshortlistCount: number;\n\tabstentionCount: number;\n\taverageLatencyMs?: number;\n\taverageInputTokenEstimate?: number;\n\taverageOutputTokenEstimate?: number;\n}\n\n/**\n * Durable, per-(model,intent) aggregate of the observe-mode loop: does the raw expected-utility\n * ranking's top pick (`ToolSelectionObservation.ranked[0]`) match what the model actually called\n * (`ToolSelectionObservation.actualTool`)? Tracked separately from the capped, rolling\n * `observations` log so evidence for a given (model,intent) pair survives that log's trimming.\n * `hintActive*` fields are the SAME agreement measure, but restricted to calls made while an\n * evidence-gated promotion hint (see promotion.ts) was active for this bucket — the hint's own\n * efficacy trace: it never gates activation directly (that is always\n * recomputed live from `ToolPerformanceStats`), but it is the durable evidence a report can show\n * for \"is the hint still earning its keep\".\n */\nexport interface ToolSelectionIntentAgreement {\n\tmodelRef: string;\n\tintentClass: ToolSelectionIntentClass;\n\tsampleCount: number;\n\tagreementCount: number;\n\thintActiveSampleCount: number;\n\thintActiveAgreementCount: number;\n\tlastUpdatedAt: string;\n}\n\ninterface HostToolPerformanceData {\n\thost: HostFingerprint;\n\tstats: Record<string, ToolPerformanceStats>;\n\tobservations: ToolSelectionObservation[];\n\tobservationBytes: number;\n\tintentAgreement: Record<string, ToolSelectionIntentAgreement>;\n}\n\nexport interface ToolExecutionObservation {\n\tkey: ToolPerformanceKey;\n\tsuccess: boolean;\n\tlatencyMs: number;\n\tinputTokenEstimate?: number;\n\toutputTokenEstimate?: number;\n\tselection: Omit<ToolSelectionObservation, \"at\" | \"modelRef\" | \"intentClass\" | \"actualTool\" | \"succeeded\">;\n\tat?: string;\n\t/**\n\t * Whether an evidence-gated promotion hint (promotion.ts) was already active for this\n\t * (model,intent) bucket BEFORE this call was recorded — captured by the controller at\n\t * `begin()` time, so it reflects evidence up to but not including this observation. Used only\n\t * to bucket the durable agreement stats (`ToolSelectionIntentAgreement.hintActive*`); never\n\t * changes what gets recorded, only how it is split for the efficacy report.\n\t */\n\thintActiveAtCallTime?: boolean;\n}\n\nfunction statKey(key: ToolPerformanceKey): string {\n\treturn `${key.modelRef}\\0${key.intentClass}\\0${key.tool}`;\n}\n\nfunction intentAgreementKey(modelRef: string, intentClass: ToolSelectionIntentClass): string {\n\treturn `${modelRef}\\0${intentClass}`;\n}\n\nfunction isIntentClass(value: unknown): value is ToolSelectionIntentClass {\n\treturn (\n\t\tvalue === \"read\" ||\n\t\tvalue === \"search\" ||\n\t\tvalue === \"execute\" ||\n\t\tvalue === \"write\" ||\n\t\tvalue === \"retrieve\" ||\n\t\tvalue === \"explain\" ||\n\t\tvalue === \"other\"\n\t);\n}\n\nfunction isStats(value: unknown): value is ToolPerformanceStats {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.modelRef === \"string\" &&\n\t\tisIntentClass(value.intentClass) &&\n\t\ttypeof value.tool === \"string\" &&\n\t\ttypeof value.alpha === \"number\" &&\n\t\ttypeof value.beta === \"number\" &&\n\t\ttypeof value.sampleCount === \"number\" &&\n\t\ttypeof value.repairCount === \"number\" &&\n\t\ttypeof value.bounceCount === \"number\" &&\n\t\ttypeof value.failureCount === \"number\" &&\n\t\ttypeof value.lastUsedAt === \"string\"\n\t);\n}\n\nfunction isObservation(value: unknown): value is ToolSelectionObservation {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.at === \"string\" &&\n\t\ttypeof value.modelRef === \"string\" &&\n\t\tisIntentClass(value.intentClass) &&\n\t\ttypeof value.actualTool === \"string\" &&\n\t\ttypeof value.firstTool === \"boolean\" &&\n\t\ttypeof value.succeeded === \"boolean\" &&\n\t\t(value.disposition === \"recommend\" || value.disposition === \"shortlist\" || value.disposition === \"abstain\") &&\n\t\tArray.isArray(value.shortlist) &&\n\t\tvalue.shortlist.every((tool) => typeof tool === \"string\") &&\n\t\ttypeof value.entropy === \"number\" &&\n\t\ttypeof value.margin === \"number\" &&\n\t\tArray.isArray(value.ranked) &&\n\t\tvalue.ranked.every(\n\t\t\t(entry) =>\n\t\t\t\tisRecordObject(entry) &&\n\t\t\t\ttypeof entry.tool === \"string\" &&\n\t\t\t\ttypeof entry.utility === \"number\" &&\n\t\t\t\ttypeof entry.probability === \"number\",\n\t\t) &&\n\t\t(value.latencyMs === undefined || typeof value.latencyMs === \"number\") &&\n\t\t(value.inputTokenEstimate === undefined || typeof value.inputTokenEstimate === \"number\") &&\n\t\t(value.outputTokenEstimate === undefined || typeof value.outputTokenEstimate === \"number\")\n\t);\n}\n\nfunction isIntentAgreement(value: unknown): value is ToolSelectionIntentAgreement {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.modelRef === \"string\" &&\n\t\tisIntentClass(value.intentClass) &&\n\t\ttypeof value.sampleCount === \"number\" &&\n\t\ttypeof value.agreementCount === \"number\" &&\n\t\ttypeof value.hintActiveSampleCount === \"number\" &&\n\t\ttypeof value.hintActiveAgreementCount === \"number\" &&\n\t\ttypeof value.lastUpdatedAt === \"string\"\n\t);\n}\n\nfunction emptyStats(key: ToolPerformanceKey, at: string): ToolPerformanceStats {\n\treturn {\n\t\t...key,\n\t\talpha: 1,\n\t\tbeta: 1,\n\t\tsampleCount: 0,\n\t\trepairCount: 0,\n\t\tbounceCount: 0,\n\t\tfailureCount: 0,\n\t\tlastUsedAt: at,\n\t};\n}\n\nfunction emptyIntentAgreement(\n\tmodelRef: string,\n\tintentClass: ToolSelectionIntentClass,\n\tat: string,\n): ToolSelectionIntentAgreement {\n\treturn {\n\t\tmodelRef,\n\t\tintentClass,\n\t\tsampleCount: 0,\n\t\tagreementCount: 0,\n\t\thintActiveSampleCount: 0,\n\t\thintActiveAgreementCount: 0,\n\t\tlastUpdatedAt: at,\n\t};\n}\n\nfunction finiteNonNegative(value: number | undefined): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value >= 0 ? value : undefined;\n}\n\nfunction updateEwma(previous: number | undefined, next: number | undefined): number | undefined {\n\tif (next === undefined) return previous;\n\treturn previous === undefined ? next : previous + EWMA_ALPHA * (next - previous);\n}\n\nfunction updateDeviation(\n\tpreviousValue: number | undefined,\n\tpreviousDeviation: number | undefined,\n\tnext: number | undefined,\n): number | undefined {\n\tif (next === undefined) return previousDeviation;\n\tconst deviation = previousValue === undefined ? 0 : Math.abs(next - previousValue);\n\treturn updateEwma(previousDeviation, deviation);\n}\n\nfunction encodedObservationBytes(observation: ToolSelectionObservation): number {\n\treturn Buffer.byteLength(JSON.stringify(observation), \"utf8\");\n}\n\nfunction trimObservations(observations: ToolSelectionObservation[]): {\n\tobservations: ToolSelectionObservation[];\n\tbytes: number;\n} {\n\tlet bytes = 2;\n\tfor (const observation of observations) {\n\t\tbytes += encodedObservationBytes(observation) + (bytes > 2 ? 1 : 0);\n\t}\n\tif (observations.length <= MAX_OBSERVATIONS_PER_HOST && bytes <= MAX_OBSERVATION_BYTES_PER_HOST) {\n\t\treturn { observations, bytes };\n\t}\n\n\tconst retained: ToolSelectionObservation[] = [];\n\tbytes = 2;\n\tfor (let index = observations.length - 1; index >= 0 && retained.length < MAX_OBSERVATIONS_PER_HOST; index -= 1) {\n\t\tconst observation = observations[index]!;\n\t\tconst addition = encodedObservationBytes(observation) + (retained.length > 0 ? 1 : 0);\n\t\tif (bytes + addition > TARGET_OBSERVATION_BYTES_PER_HOST) break;\n\t\tretained.push(observation);\n\t\tbytes += addition;\n\t}\n\tretained.reverse();\n\treturn { observations: retained, bytes };\n}\n\nfunction parseHost(value: unknown, hostId: string): HostToolPerformanceData | undefined {\n\tif (\n\t\t!isRecordObject(value) ||\n\t\t!isHostFingerprint(value.host) ||\n\t\tvalue.host.id !== hostId ||\n\t\t!isRecordObject(value.stats) ||\n\t\t!Array.isArray(value.observations)\n\t)\n\t\treturn undefined;\n\tconst host = value.host;\n\tconst observations = trimObservations(value.observations.filter(isObservation));\n\t// intentAgreement is a purely additive field (older store files predate it) — tolerate absence\n\t// rather than bumping STORE_VERSION, same as any other backward-compatible default-empty field.\n\tconst intentAgreementRaw = isRecordObject(value.intentAgreement) ? value.intentAgreement : {};\n\treturn {\n\t\thost,\n\t\tstats: Object.fromEntries(\n\t\t\tObject.entries(value.stats).filter((entry): entry is [string, ToolPerformanceStats] => isStats(entry[1])),\n\t\t),\n\t\tobservations: observations.observations,\n\t\tobservationBytes: observations.bytes,\n\t\tintentAgreement: Object.fromEntries(\n\t\t\tObject.entries(intentAgreementRaw).filter((entry): entry is [string, ToolSelectionIntentAgreement] =>\n\t\t\t\tisIntentAgreement(entry[1]),\n\t\t\t),\n\t\t),\n\t};\n}\n\nfunction trimStats(stats: Record<string, ToolPerformanceStats>): Record<string, ToolPerformanceStats> {\n\tconst entries = Object.entries(stats);\n\tif (entries.length <= MAX_STATS_PER_HOST) return stats;\n\treturn Object.fromEntries(\n\t\tentries\n\t\t\t.sort(([, left], [, right]) => Date.parse(right.lastUsedAt) - Date.parse(left.lastUsedAt))\n\t\t\t.slice(0, MAX_STATS_PER_HOST),\n\t);\n}\n\nfunction trimIntentAgreement(\n\trecords: Record<string, ToolSelectionIntentAgreement>,\n): Record<string, ToolSelectionIntentAgreement> {\n\tconst entries = Object.entries(records);\n\tif (entries.length <= MAX_INTENT_AGREEMENT_PER_HOST) return records;\n\treturn Object.fromEntries(\n\t\tentries\n\t\t\t.sort(([, left], [, right]) => Date.parse(right.lastUpdatedAt) - Date.parse(left.lastUpdatedAt))\n\t\t\t.slice(0, MAX_INTENT_AGREEMENT_PER_HOST),\n\t);\n}\n\nexport class ToolPerformanceStore {\n\tprivate readonly storage: HostStateStore<HostToolPerformanceData>;\n\n\tconstructor(filePath: string, options: { fingerprint?: () => HostFingerprint; readOnly?: boolean } = {}) {\n\t\tthis.storage = new HostStateStore({\n\t\t\tfilePath,\n\t\t\tversion: STORE_VERSION,\n\t\t\tfingerprint: options.fingerprint,\n\t\t\treadOnly: options.readOnly ?? isWorkerSession(),\n\t\t\tparseHost,\n\t\t});\n\t}\n\n\tstatic forAgentDir(\n\t\tagentDir: string,\n\t\toptions: { fingerprint?: () => HostFingerprint; readOnly?: boolean } = {},\n\t): ToolPerformanceStore {\n\t\treturn new ToolPerformanceStore(stateFile(agentDir, \"tool-performance.json\"), options);\n\t}\n\n\tprivate createHostData(host: HostFingerprint): HostToolPerformanceData {\n\t\treturn { host, stats: {}, observations: [], observationBytes: 2, intentAgreement: {} };\n\t}\n\n\tget(key: ToolPerformanceKey): ToolPerformanceStats {\n\t\tconst host = this.storage.getHost();\n\t\tconst stats = host?.stats[statKey(key)];\n\t\treturn stats ? { ...stats } : emptyStats(key, new Date(0).toISOString());\n\t}\n\n\t/** One fresh durable snapshot of every per-tool track record for a model. */\n\tgetStatsForModel(modelRef: string): ToolPerformanceStats[] {\n\t\tconst host = this.storage.getHost();\n\t\tif (!host) return [];\n\t\treturn Object.values(host.stats)\n\t\t\t.filter((stats) => stats.modelRef === modelRef)\n\t\t\t.map((stats) => ({ ...stats }));\n\t}\n\n\t/** Every per-tool track record recorded for a (model,intent) bucket — the promotion.ts input. */\n\tgetStatsForIntent(modelRef: string, intentClass: ToolSelectionIntentClass): ToolPerformanceStats[] {\n\t\tconst host = this.storage.getHost();\n\t\tif (!host) return [];\n\t\treturn Object.values(host.stats)\n\t\t\t.filter((stats) => stats.modelRef === modelRef && stats.intentClass === intentClass)\n\t\t\t.map((stats) => ({ ...stats }));\n\t}\n\n\t/** Durable observe-mode agreement for one (model,intent) bucket (see {@link ToolSelectionIntentAgreement}). */\n\tgetIntentAgreement(modelRef: string, intentClass: ToolSelectionIntentClass): ToolSelectionIntentAgreement {\n\t\tconst host = this.storage.getHost();\n\t\tconst record = host?.intentAgreement[intentAgreementKey(modelRef, intentClass)];\n\t\treturn record ? { ...record } : emptyIntentAgreement(modelRef, intentClass, new Date(0).toISOString());\n\t}\n\n\t/** All recorded (model,intent) agreement buckets, optionally scoped to one model — report input. */\n\tgetAllIntentAgreements(modelRef?: string): ToolSelectionIntentAgreement[] {\n\t\tconst host = this.storage.getHost();\n\t\treturn Object.values(host?.intentAgreement ?? {})\n\t\t\t.filter((record) => modelRef === undefined || record.modelRef === modelRef)\n\t\t\t.map((record) => ({ ...record }));\n\t}\n\n\trecordValidation(\n\t\tkey: ToolPerformanceKey,\n\t\toutcome: \"repaired\" | \"bounced\",\n\t\tat = new Date().toISOString(),\n\t): ToolPerformanceStats {\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t(host) => this.createHostData(host),\n\t\t\t(host) => {\n\t\t\t\tconst storageKey = statKey(key);\n\t\t\t\tconst current = host.stats[storageKey] ?? emptyStats(key, at);\n\t\t\t\tconst next: ToolPerformanceStats = {\n\t\t\t\t\t...current,\n\t\t\t\t\trepairCount: current.repairCount + (outcome === \"repaired\" ? 1 : 0),\n\t\t\t\t\tbounceCount: current.bounceCount + (outcome === \"bounced\" ? 1 : 0),\n\t\t\t\t\tlastUsedAt: at,\n\t\t\t\t};\n\t\t\t\thost.stats[storageKey] = next;\n\t\t\t\thost.stats = trimStats(host.stats);\n\t\t\t\treturn { result: { ...next }, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\trecordExecution(observation: ToolExecutionObservation): ToolPerformanceStats {\n\t\tconst at = observation.at ?? new Date().toISOString();\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t(host) => this.createHostData(host),\n\t\t\t(host) => {\n\t\t\t\tconst storageKey = statKey(observation.key);\n\t\t\t\tconst current = host.stats[storageKey] ?? emptyStats(observation.key, at);\n\t\t\t\tconst latencyMs = finiteNonNegative(observation.latencyMs);\n\t\t\t\tconst inputTokenEstimate = finiteNonNegative(observation.inputTokenEstimate);\n\t\t\t\tconst outputTokenEstimate = finiteNonNegative(observation.outputTokenEstimate);\n\t\t\t\tconst next: ToolPerformanceStats = {\n\t\t\t\t\t...current,\n\t\t\t\t\talpha: current.alpha + (observation.success ? 1 : 0),\n\t\t\t\t\tbeta: current.beta + (observation.success ? 0 : 1),\n\t\t\t\t\tsampleCount: current.sampleCount + 1,\n\t\t\t\t\tlatencyEwmaMs: updateEwma(current.latencyEwmaMs, latencyMs),\n\t\t\t\t\tlatencyDeviationEwmaMs: updateDeviation(\n\t\t\t\t\t\tcurrent.latencyEwmaMs,\n\t\t\t\t\t\tcurrent.latencyDeviationEwmaMs,\n\t\t\t\t\t\tlatencyMs,\n\t\t\t\t\t),\n\t\t\t\t\tinputTokenEstimateEwma: updateEwma(current.inputTokenEstimateEwma, inputTokenEstimate),\n\t\t\t\t\toutputTokenEstimateEwma: updateEwma(current.outputTokenEstimateEwma, outputTokenEstimate),\n\t\t\t\t\tfailureCount: current.failureCount + (observation.success ? 0 : 1),\n\t\t\t\t\tlastUsedAt: at,\n\t\t\t\t};\n\t\t\t\thost.stats[storageKey] = next;\n\t\t\t\thost.stats = trimStats(host.stats);\n\t\t\t\tconst selectionObservation: ToolSelectionObservation = {\n\t\t\t\t\t...observation.selection,\n\t\t\t\t\tat,\n\t\t\t\t\tmodelRef: observation.key.modelRef,\n\t\t\t\t\tintentClass: observation.key.intentClass,\n\t\t\t\t\tactualTool: observation.key.tool,\n\t\t\t\t\tsucceeded: observation.success,\n\t\t\t\t\tranked: observation.selection.ranked.slice(0, 6),\n\t\t\t\t\tshortlist: observation.selection.shortlist.slice(0, 3),\n\t\t\t\t\tlatencyMs,\n\t\t\t\t\tinputTokenEstimate,\n\t\t\t\t\toutputTokenEstimate,\n\t\t\t\t};\n\t\t\t\thost.observations.push(selectionObservation);\n\t\t\t\thost.observationBytes +=\n\t\t\t\t\tencodedObservationBytes(selectionObservation) + (host.observations.length > 1 ? 1 : 0);\n\t\t\t\tif (\n\t\t\t\t\thost.observations.length > MAX_OBSERVATIONS_PER_HOST ||\n\t\t\t\t\thost.observationBytes > MAX_OBSERVATION_BYTES_PER_HOST\n\t\t\t\t) {\n\t\t\t\t\tconst trimmed = trimObservations(host.observations);\n\t\t\t\t\thost.observations = trimmed.observations;\n\t\t\t\t\thost.observationBytes = trimmed.bytes;\n\t\t\t\t}\n\n\t\t\t\t// Observe-mode agreement: did the RAW ranking's top pick (before any actual-tool-only\n\t\t\t\t// eligibility gating) match what the model actually called? Recorded durably per\n\t\t\t\t// (model,intent), separate from the capped `observations` log above, so it survives trimming.\n\t\t\t\tconst predictedBest = observation.selection.ranked[0]?.tool;\n\t\t\t\tconst agreed = predictedBest !== undefined && predictedBest === observation.key.tool;\n\t\t\t\tconst agreementKey = intentAgreementKey(observation.key.modelRef, observation.key.intentClass);\n\t\t\t\tconst currentAgreement =\n\t\t\t\t\thost.intentAgreement[agreementKey] ??\n\t\t\t\t\temptyIntentAgreement(observation.key.modelRef, observation.key.intentClass, at);\n\t\t\t\thost.intentAgreement[agreementKey] = {\n\t\t\t\t\t...currentAgreement,\n\t\t\t\t\tsampleCount: currentAgreement.sampleCount + 1,\n\t\t\t\t\tagreementCount: currentAgreement.agreementCount + (agreed ? 1 : 0),\n\t\t\t\t\thintActiveSampleCount:\n\t\t\t\t\t\tcurrentAgreement.hintActiveSampleCount + (observation.hintActiveAtCallTime ? 1 : 0),\n\t\t\t\t\thintActiveAgreementCount:\n\t\t\t\t\t\tcurrentAgreement.hintActiveAgreementCount + (observation.hintActiveAtCallTime && agreed ? 1 : 0),\n\t\t\t\t\tlastUpdatedAt: at,\n\t\t\t\t};\n\t\t\t\thost.intentAgreement = trimIntentAgreement(host.intentAgreement);\n\n\t\t\t\treturn { result: { ...next }, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\tgetMetrics(modelRef?: string): ToolSelectionMetrics {\n\t\tconst host = this.storage.getHost();\n\t\tconst observations = (host?.observations ?? []).filter(\n\t\t\t(observation) => modelRef === undefined || observation.modelRef === modelRef,\n\t\t);\n\t\tconst firstTools = observations.filter((observation) => observation.firstTool);\n\t\tconst recommended = observations.filter((observation) => observation.disposition === \"recommend\");\n\t\tconst average = (values: Array<number | undefined>): number | undefined => {\n\t\t\tconst present = values.filter((value): value is number => value !== undefined);\n\t\t\treturn present.length > 0 ? present.reduce((sum, value) => sum + value, 0) / present.length : undefined;\n\t\t};\n\t\treturn {\n\t\t\tfirstToolAttempts: firstTools.length,\n\t\t\tfirstToolSuccesses: firstTools.filter((observation) => observation.succeeded).length,\n\t\t\twrongToolOrFailureCount: observations.filter(\n\t\t\t\t(observation) =>\n\t\t\t\t\t!observation.succeeded ||\n\t\t\t\t\t(observation.disposition === \"recommend\" && observation.recommendation !== observation.actualTool),\n\t\t\t).length,\n\t\t\trecommendationCount: recommended.length,\n\t\t\trecommendationMatchedCount: recommended.filter(\n\t\t\t\t(observation) => observation.recommendation === observation.actualTool,\n\t\t\t).length,\n\t\t\tshortlistCount: observations.filter((observation) => observation.disposition === \"shortlist\").length,\n\t\t\tabstentionCount: observations.filter((observation) => observation.disposition === \"abstain\").length,\n\t\t\taverageLatencyMs: average(observations.map((observation) => observation.latencyMs)),\n\t\t\taverageInputTokenEstimate: average(observations.map((observation) => observation.inputTokenEstimate)),\n\t\t\taverageOutputTokenEstimate: average(observations.map((observation) => observation.outputTokenEstimate)),\n\t\t};\n\t}\n\n\tgetObservations(modelRef?: string): ToolSelectionObservation[] {\n\t\tconst host = this.storage.getHost();\n\t\treturn (host?.observations ?? [])\n\t\t\t.filter((observation) => modelRef === undefined || observation.modelRef === modelRef)\n\t\t\t.map((observation) => ({\n\t\t\t\t...observation,\n\t\t\t\tshortlist: [...observation.shortlist],\n\t\t\t\tranked: observation.ranked.map((candidate) => ({ ...candidate })),\n\t\t\t}));\n\t}\n}\n"]}
@@ -0,0 +1,19 @@
1
+ export type ToolPhase = "selection" | "execution" | "observation_write" | "validation_write" | "hint_snapshot";
2
+ export interface ToolPhaseTimingStats {
3
+ phase: ToolPhase;
4
+ count: number;
5
+ recentCount: number;
6
+ p50Ms: number;
7
+ p95Ms: number;
8
+ maxMs: number;
9
+ }
10
+ /** Passive, allocation-free-on-record timing samples for the tool-call path. */
11
+ export declare class ToolPhaseTimings {
12
+ private readonly capacity;
13
+ private readonly samples;
14
+ constructor(capacity?: number);
15
+ record(phase: ToolPhase, durationMs: number): void;
16
+ getStats(): ToolPhaseTimingStats[];
17
+ formatReport(): string;
18
+ }
19
+ //# sourceMappingURL=tool-phase-timing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-phase-timing.d.ts","sourceRoot":"","sources":["../../../src/core/tool-selection/tool-phase-timing.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,eAAe,CAAC;AAE/G,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACd;AA+BD,gFAAgF;AAChF,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAE9D,YAAY,QAAQ,SAAiC,EAKpD;IAED,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAOjD;IAED,QAAQ,IAAI,oBAAoB,EAAE,CAgBjC;IAED,YAAY,IAAI,MAAM,CAUrB;CACD"}
@@ -0,0 +1,63 @@
1
+ const PHASES = [
2
+ "selection",
3
+ "execution",
4
+ "observation_write",
5
+ "validation_write",
6
+ "hint_snapshot",
7
+ ];
8
+ const PHASE_LABELS = {
9
+ selection: "selection",
10
+ execution: "execution and result hooks",
11
+ observation_write: "observation evidence write",
12
+ validation_write: "validation evidence write",
13
+ hint_snapshot: "hint snapshot",
14
+ };
15
+ const DEFAULT_RECENT_SAMPLE_CAPACITY = 128;
16
+ function percentile(sorted, fraction) {
17
+ return sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * fraction))] ?? 0;
18
+ }
19
+ /** Passive, allocation-free-on-record timing samples for the tool-call path. */
20
+ export class ToolPhaseTimings {
21
+ constructor(capacity = DEFAULT_RECENT_SAMPLE_CAPACITY) {
22
+ this.capacity = Math.max(1, Math.trunc(capacity));
23
+ this.samples = Object.fromEntries(PHASES.map((phase) => [phase, { values: new Float64Array(this.capacity), next: 0, size: 0, count: 0 }]));
24
+ }
25
+ record(phase, durationMs) {
26
+ if (!Number.isFinite(durationMs) || durationMs < 0)
27
+ return;
28
+ const samples = this.samples[phase];
29
+ samples.values[samples.next] = durationMs;
30
+ samples.next = (samples.next + 1) % this.capacity;
31
+ samples.size = Math.min(this.capacity, samples.size + 1);
32
+ samples.count += 1;
33
+ }
34
+ getStats() {
35
+ const stats = [];
36
+ for (const phase of PHASES) {
37
+ const samples = this.samples[phase];
38
+ if (samples.size === 0)
39
+ continue;
40
+ const recent = Array.from(samples.values.subarray(0, samples.size)).sort((left, right) => left - right);
41
+ stats.push({
42
+ phase,
43
+ count: samples.count,
44
+ recentCount: samples.size,
45
+ p50Ms: percentile(recent, 0.5),
46
+ p95Ms: percentile(recent, 0.95),
47
+ maxMs: recent[recent.length - 1] ?? 0,
48
+ });
49
+ }
50
+ return stats;
51
+ }
52
+ formatReport() {
53
+ const stats = this.getStats();
54
+ if (stats.length === 0)
55
+ return "Tool phase timings: no samples recorded yet.";
56
+ const lines = [`Tool phase timings (most recent ${this.capacity} samples per phase)`];
57
+ for (const entry of stats) {
58
+ lines.push(` ${PHASE_LABELS[entry.phase]}: n=${entry.count} p50=${entry.p50Ms.toFixed(2)}ms p95=${entry.p95Ms.toFixed(2)}ms max=${entry.maxMs.toFixed(2)}ms`);
59
+ }
60
+ return lines.join("\n");
61
+ }
62
+ }
63
+ //# sourceMappingURL=tool-phase-timing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-phase-timing.js","sourceRoot":"","sources":["../../../src/core/tool-selection/tool-phase-timing.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,GAAyB;IACpC,WAAW;IACX,WAAW;IACX,mBAAmB;IACnB,kBAAkB;IAClB,eAAe;CACf,CAAC;AAEF,MAAM,YAAY,GAA8B;IAC/C,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,4BAA4B;IACvC,iBAAiB,EAAE,4BAA4B;IAC/C,gBAAgB,EAAE,2BAA2B;IAC7C,aAAa,EAAE,eAAe;CAC9B,CAAC;AAEF,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAE3C,SAAS,UAAU,CAAC,MAAyB,EAAE,QAAgB;IAC9D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,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C,CAAC,IAAI,CAClJ,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;CACD","sourcesContent":["export type ToolPhase = \"selection\" | \"execution\" | \"observation_write\" | \"validation_write\" | \"hint_snapshot\";\n\nexport interface ToolPhaseTimingStats {\n\tphase: ToolPhase;\n\tcount: number;\n\trecentCount: number;\n\tp50Ms: number;\n\tp95Ms: number;\n\tmaxMs: number;\n}\n\ninterface ToolPhaseSamples {\n\tvalues: Float64Array;\n\tnext: number;\n\tsize: number;\n\tcount: number;\n}\n\nconst PHASES: readonly ToolPhase[] = [\n\t\"selection\",\n\t\"execution\",\n\t\"observation_write\",\n\t\"validation_write\",\n\t\"hint_snapshot\",\n];\n\nconst PHASE_LABELS: Record<ToolPhase, string> = {\n\tselection: \"selection\",\n\texecution: \"execution and result hooks\",\n\tobservation_write: \"observation evidence write\",\n\tvalidation_write: \"validation evidence write\",\n\thint_snapshot: \"hint snapshot\",\n};\n\nconst DEFAULT_RECENT_SAMPLE_CAPACITY = 128;\n\nfunction percentile(sorted: readonly number[], fraction: number): number {\n\treturn sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * fraction))] ?? 0;\n}\n\n/** Passive, allocation-free-on-record timing samples for the tool-call path. */\nexport class ToolPhaseTimings {\n\tprivate readonly capacity: number;\n\tprivate readonly samples: Record<ToolPhase, ToolPhaseSamples>;\n\n\tconstructor(capacity = DEFAULT_RECENT_SAMPLE_CAPACITY) {\n\t\tthis.capacity = Math.max(1, Math.trunc(capacity));\n\t\tthis.samples = Object.fromEntries(\n\t\t\tPHASES.map((phase) => [phase, { values: new Float64Array(this.capacity), next: 0, size: 0, count: 0 }]),\n\t\t) as Record<ToolPhase, ToolPhaseSamples>;\n\t}\n\n\trecord(phase: ToolPhase, durationMs: number): void {\n\t\tif (!Number.isFinite(durationMs) || durationMs < 0) return;\n\t\tconst samples = this.samples[phase];\n\t\tsamples.values[samples.next] = durationMs;\n\t\tsamples.next = (samples.next + 1) % this.capacity;\n\t\tsamples.size = Math.min(this.capacity, samples.size + 1);\n\t\tsamples.count += 1;\n\t}\n\n\tgetStats(): ToolPhaseTimingStats[] {\n\t\tconst stats: ToolPhaseTimingStats[] = [];\n\t\tfor (const phase of PHASES) {\n\t\t\tconst samples = this.samples[phase];\n\t\t\tif (samples.size === 0) continue;\n\t\t\tconst recent = Array.from(samples.values.subarray(0, samples.size)).sort((left, right) => left - right);\n\t\t\tstats.push({\n\t\t\t\tphase,\n\t\t\t\tcount: samples.count,\n\t\t\t\trecentCount: samples.size,\n\t\t\t\tp50Ms: percentile(recent, 0.5),\n\t\t\t\tp95Ms: percentile(recent, 0.95),\n\t\t\t\tmaxMs: recent[recent.length - 1] ?? 0,\n\t\t\t});\n\t\t}\n\t\treturn stats;\n\t}\n\n\tformatReport(): string {\n\t\tconst stats = this.getStats();\n\t\tif (stats.length === 0) return \"Tool phase timings: no samples recorded yet.\";\n\t\tconst lines = [`Tool phase timings (most recent ${this.capacity} samples per phase)`];\n\t\tfor (const entry of stats) {\n\t\t\tlines.push(\n\t\t\t\t` ${PHASE_LABELS[entry.phase]}: n=${entry.count} p50=${entry.p50Ms.toFixed(2)}ms p95=${entry.p95Ms.toFixed(2)}ms max=${entry.maxMs.toFixed(2)}ms`,\n\t\t\t);\n\t\t}\n\t\treturn lines.join(\"\\n\");\n\t}\n}\n"]}
@@ -49,6 +49,7 @@ declare function estimateContentTokens(content: readonly unknown[]): number | un
49
49
  export declare class ToolSelectionController {
50
50
  private readonly deps;
51
51
  private readonly pending;
52
+ private readonly timings;
52
53
  private firstToolInTurn;
53
54
  /** Kill switch: observe/stats recording, default ON. `PI_TOOL_SELECTION_OBSERVE=0` disables it. */
54
55
  private readonly observeEnabled;
@@ -57,11 +58,6 @@ export declare class ToolSelectionController {
57
58
  begin(toolCallId: string, toolName: string, args: unknown): ToolSelectionPendingObservation;
58
59
  complete(toolCallId: string, succeeded: boolean, content?: readonly unknown[]): void;
59
60
  recordValidation(toolName: string, outcome: "repaired" | "bounced"): void;
60
- /**
61
- * Evidence-gated promotion for one (model,intent) bucket — see promotion.ts. Pure read, no
62
- * mutation; used both to stamp `hintActiveAtCallTime` and to build the live hint list below.
63
- */
64
- private evaluatePromotion;
65
61
  /**
66
62
  * The currently active evidence-gated hints for the session's current model — one per
67
63
  * (intentClass) at most, only where accumulated evidence clears the promotion gate. Consumed by
@@ -70,6 +66,7 @@ export declare class ToolSelectionController {
70
66
  * cleared the gate yet.
71
67
  */
72
68
  getActiveHints(modelRef?: string): ToolSelectionHint[];
69
+ formatTimingReport(): string;
73
70
  /**
74
71
  * Report surface for the observe/agreement/promotion loop: per (model,intent), the durable
75
72
  * agreement rate (did the raw ranking's top pick match what was actually called), plus the
@@ -1 +1 @@
1
- {"version":3,"file":"tool-selection-controller.d.ts","sourceRoot":"","sources":["../../../src/core/tool-selection/tool-selection-controller.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,KAAK,EAEX,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,2BAA2B;IAC3C,KAAK,EAAE,oBAAoB,CAAC;IAC5B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,SAAS,iBAAiB,EAAE,CAAC;IACnD,kBAAkB,CAAC,EAA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AAY,IAAI,EAAE,2BAA2B,EAG5C;IAED,SAAS,IAAI,IAAI,CAEhB;IAED,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,+BAA+B,CA4D1F;IAED,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAE,SAAS,OAAO,EAAO,GAAG,IAAI,CAevF;IAED,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,IAAI,CAKxE;IAED;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;;;;;OAMG;IACH,cAAc,CAAC,QAAQ,GAAE,MAAgC,GAAG,iBAAiB,EAAE,CAiB9E;IAED;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,GAAE,MAAgC,GAAG,wBAAwB,EAAE,CAiBhF;IAED,OAAO,CAAC,iBAAiB;CAkBzB;AAED,yGAAyG;AACzG,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,SAAS,wBAAwB,EAAE,GAAG,MAAM,CAuB9F;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.d.ts","sourceRoot":"","sources":["../../../src/core/tool-selection/tool-selection-controller.ts"],"names":[],"mappings":"AAMA,OAAO,EAAyB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,KAAK,EAEX,kBAAkB,EAElB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,MAAM,6BAA6B,CAAC;AAGrC,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,2BAA2B;IAC3C,KAAK,EAAE,oBAAoB,CAAC;IAC5B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,SAAS,iBAAiB,EAAE,CAAC;IACnD,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,+BAA+B;IAC/C,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,kBAAkB,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,IAAI,CAAC,wBA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M,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,IAAI,CAUxE;IAED;;;;;;OAMG;IACH,cAAc,CAAC,QAAQ,GAAE,MAAgC,GAAG,iBAAiB,EAAE,CAyB9E;IAED,kBAAkB,IAAI,MAAM,CAE3B;IAED;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,GAAE,MAAgC,GAAG,wBAAwB,EAAE,CAiBhF;IAED,OAAO,CAAC,iBAAiB;CAkBzB;AAED,yGAAyG;AACzG,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,SAAS,wBAAwB,EAAE,GAAG,MAAM,CAuB9F;AAED,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,cAAc,EAAE,CAAC"}
@@ -1,5 +1,7 @@
1
+ import { performance } from "node:perf_hooks";
1
2
  import { decideExpectedUtility, } from "./expected-utility.js";
2
3
  import { evaluateToolPromotion } from "./promotion.js";
4
+ import { ToolPhaseTimings } from "./tool-phase-timing.js";
3
5
  const INTENT_CLASSES = [
4
6
  "read",
5
7
  "search",
@@ -88,17 +90,15 @@ function estimateContentTokens(content) {
88
90
  function modelToolKey(modelRef, intentClass, tool) {
89
91
  return { modelRef, intentClass, tool };
90
92
  }
91
- function candidateFor(store, modelRef, intentClass, tool, actualTool) {
92
- const key = modelToolKey(modelRef, intentClass, tool.name);
93
- const stats = store.get(key);
93
+ function candidateFor(intentClass, tool, actualTool, stats) {
94
94
  return {
95
95
  tool: tool.name,
96
96
  value: intentValue(intentClass, classifyToolIntent(tool)),
97
- alpha: stats.alpha,
98
- beta: stats.beta,
99
- sampleCount: stats.sampleCount,
100
- latencyMs: stats.latencyEwmaMs,
101
- tokenEstimate: stats.inputTokenEstimateEwma === undefined && stats.outputTokenEstimateEwma === undefined
97
+ alpha: stats?.alpha ?? 1,
98
+ beta: stats?.beta ?? 1,
99
+ sampleCount: stats?.sampleCount ?? 0,
100
+ latencyMs: stats?.latencyEwmaMs,
101
+ tokenEstimate: stats?.inputTokenEstimateEwma === undefined && stats?.outputTokenEstimateEwma === undefined
102
102
  ? undefined
103
103
  : (stats.inputTokenEstimateEwma ?? 0) + (stats.outputTokenEstimateEwma ?? 0),
104
104
  riskCost: tool.riskCost,
@@ -108,12 +108,10 @@ function candidateFor(store, modelRef, intentClass, tool, actualTool) {
108
108
  };
109
109
  }
110
110
  export class ToolSelectionController {
111
- deps;
112
- pending = new Map();
113
- firstToolInTurn = true;
114
- /** Kill switch: observe/stats recording, default ON. `PI_TOOL_SELECTION_OBSERVE=0` disables it. */
115
- observeEnabled;
116
111
  constructor(deps) {
112
+ this.pending = new Map();
113
+ this.timings = new ToolPhaseTimings();
114
+ this.firstToolInTurn = true;
117
115
  this.deps = deps;
118
116
  this.observeEnabled = (deps.env ?? process.env).PI_TOOL_SELECTION_OBSERVE !== "0";
119
117
  }
@@ -121,6 +119,7 @@ export class ToolSelectionController {
121
119
  this.firstToolInTurn = true;
122
120
  }
123
121
  begin(toolCallId, toolName, args) {
122
+ const selectionStartedAt = performance.now();
124
123
  const modelRef = this.deps.getModelRef();
125
124
  const activeTools = this.deps
126
125
  .getActiveTools()
@@ -132,9 +131,11 @@ export class ToolSelectionController {
132
131
  pathValidated: true,
133
132
  };
134
133
  const intentClass = classifyToolIntent(actualTool);
135
- const candidates = activeTools.map((tool) => candidateFor(this.deps.store, modelRef, intentClass, tool.name === toolName ? tool : { ...tool, pathValidated: false }, toolName));
134
+ const intentStats = this.deps.store.getStatsForIntent(modelRef, intentClass);
135
+ const statsByTool = new Map(intentStats.map((stats) => [stats.tool, stats]));
136
+ const candidates = activeTools.map((tool) => candidateFor(intentClass, tool.name === toolName ? tool : { ...tool, pathValidated: false }, toolName, statsByTool.get(tool.name)));
136
137
  if (!candidates.some((candidate) => candidate.tool === toolName)) {
137
- candidates.push(candidateFor(this.deps.store, modelRef, intentClass, actualTool, toolName));
138
+ candidates.push(candidateFor(intentClass, actualTool, toolName, statsByTool.get(toolName)));
138
139
  }
139
140
  candidates.push({
140
141
  tool: "no_tool",
@@ -154,14 +155,14 @@ export class ToolSelectionController {
154
155
  // Evaluated BEFORE this call is recorded, so it reflects evidence up to (not including) this
155
156
  // observation — captured now because complete() (later, async) can no longer distinguish
156
157
  // "before" from "after" once the store has been written.
157
- const hintActiveAtCallTime = this.observeEnabled
158
- ? this.evaluatePromotion(modelRef, intentClass).tool !== undefined
159
- : false;
158
+ const hintActiveAtCallTime = this.observeEnabled ? evaluateToolPromotion(intentStats).tool !== undefined : false;
159
+ const selectionCompletedAt = performance.now();
160
+ this.timings.record("selection", selectionCompletedAt - selectionStartedAt);
160
161
  const pending = {
161
162
  id: toolCallId,
162
163
  key: modelToolKey(modelRef, intentClass, toolName),
163
164
  firstTool: this.firstToolInTurn,
164
- startedAt: Date.now(),
165
+ startedAt: selectionCompletedAt,
165
166
  inputTokenEstimate: estimateTokens(args),
166
167
  selection,
167
168
  hintActiveAtCallTime,
@@ -175,32 +176,40 @@ export class ToolSelectionController {
175
176
  if (!pending)
176
177
  return;
177
178
  this.pending.delete(toolCallId);
179
+ const completedAt = performance.now();
180
+ const latencyMs = Math.max(0, completedAt - pending.startedAt);
181
+ this.timings.record("execution", latencyMs);
178
182
  if (!this.observeEnabled)
179
183
  return;
180
184
  const execution = {
181
185
  key: pending.key,
182
186
  success: succeeded,
183
- latencyMs: Math.max(0, Date.now() - pending.startedAt),
187
+ latencyMs,
184
188
  inputTokenEstimate: pending.inputTokenEstimate,
185
189
  outputTokenEstimate: estimateContentTokens(content),
186
190
  selection: pending.selection,
187
191
  hintActiveAtCallTime: pending.hintActiveAtCallTime,
188
192
  };
189
- this.deps.store.recordExecution(execution);
193
+ const writeStartedAt = performance.now();
194
+ try {
195
+ this.deps.store.recordExecution(execution);
196
+ }
197
+ finally {
198
+ this.timings.record("observation_write", performance.now() - writeStartedAt);
199
+ }
190
200
  }
191
201
  recordValidation(toolName, outcome) {
192
202
  if (!this.observeEnabled)
193
203
  return;
194
204
  const modelRef = this.deps.getModelRef();
195
205
  const tool = this.deps.getActiveTools().find((candidate) => candidate.name === toolName) ?? { name: toolName };
196
- this.deps.store.recordValidation(modelToolKey(modelRef, classifyToolIntent(tool), toolName), outcome);
197
- }
198
- /**
199
- * Evidence-gated promotion for one (model,intent) bucket — see promotion.ts. Pure read, no
200
- * mutation; used both to stamp `hintActiveAtCallTime` and to build the live hint list below.
201
- */
202
- evaluatePromotion(modelRef, intentClass) {
203
- return evaluateToolPromotion(this.deps.store.getStatsForIntent(modelRef, intentClass));
206
+ const writeStartedAt = performance.now();
207
+ try {
208
+ this.deps.store.recordValidation(modelToolKey(modelRef, classifyToolIntent(tool), toolName), outcome);
209
+ }
210
+ finally {
211
+ this.timings.record("validation_write", performance.now() - writeStartedAt);
212
+ }
204
213
  }
205
214
  /**
206
215
  * The currently active evidence-gated hints for the session's current model — one per
@@ -214,9 +223,16 @@ export class ToolSelectionController {
214
223
  return [];
215
224
  if (!this.observeEnabled)
216
225
  return [];
226
+ const snapshotStartedAt = performance.now();
227
+ const statsByIntent = new Map();
228
+ for (const stats of this.deps.store.getStatsForModel(modelRef)) {
229
+ const entries = statsByIntent.get(stats.intentClass) ?? [];
230
+ entries.push(stats);
231
+ statsByIntent.set(stats.intentClass, entries);
232
+ }
217
233
  const hints = [];
218
234
  for (const intentClass of INTENT_CLASSES) {
219
- const promotion = this.evaluatePromotion(modelRef, intentClass);
235
+ const promotion = evaluateToolPromotion(statsByIntent.get(intentClass) ?? []);
220
236
  if (!promotion.tool)
221
237
  continue;
222
238
  hints.push({
@@ -228,8 +244,12 @@ export class ToolSelectionController {
228
244
  entropy: promotion.entropy,
229
245
  });
230
246
  }
247
+ this.timings.record("hint_snapshot", performance.now() - snapshotStartedAt);
231
248
  return hints;
232
249
  }
250
+ formatTimingReport() {
251
+ return this.timings.formatReport();
252
+ }
233
253
  /**
234
254
  * Report surface for the observe/agreement/promotion loop: per (model,intent), the durable
235
255
  * agreement rate (did the raw ranking's top pick match what was actually called), plus the