@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":"model-tool-protocol.js","sourceRoot":"","sources":["../../src/core/model-tool-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,yBAAyB,EAAwC,MAAM,mBAAmB,CAAC;AAG9G,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAkB7C;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAIxC,EAA+B;IAC/B,IAAI,IAAI,CAAC,gBAAgB,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAC;IACjE,CAAC;IACD,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACpC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAC;IAC3D,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,CAAC,oBAAoB,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;IACxD,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,KAAK,eAAe,EAAE,CAAC;QAC3D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC9D,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC7C,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,2BAA2B,EAAE,CAAC;IACzE,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO;YACN,QAAQ,EAAE,SAAS;YACnB,UAAU,EAAE,0BAA0B;YACtC,aAAa,EAAE,WAAW,CAAC,aAAa;SACxC,CAAC;IACH,CAAC;IACD,IAAI,WAAW,CAAC,OAAO,KAAK,2BAA2B,IAAI,CAAC,yBAAyB,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5G,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,2BAA2B,EAAE,CAAC;IACzE,CAAC;IACD,OAAO;QACN,QAAQ,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE;QAC1C,UAAU,EAAE,kBAAkB;KAC9B,CAAC;AAAA,CACF","sourcesContent":["import { type Api, isTextToolProtocolVariant, type Model, type SimpleStreamOptions } from \"@caupulican/pi-ai\";\nimport type { ModelAdaptationProfile } from \"./models/adaptation-store.ts\";\n\nexport const MODEL_TOOL_PROTOCOL_VERSION = 1;\n\nexport type ModelToolProtocolReasonCode =\n\t| \"settings_disabled\"\n\t| \"settings_enabled\"\n\t| \"model_enabled\"\n\t| \"probe_calibrated\"\n\t| \"probe_calibration_missing\"\n\t| \"probe_calibration_failed\"\n\t| \"probe_calibration_invalid\"\n\t| \"native_default\";\n\nexport interface ModelToolProtocolResolution {\n\tprotocol: SimpleStreamOptions[\"textToolCallProtocol\"];\n\treasonCode: ModelToolProtocolReasonCode;\n\tvariantsTried?: readonly string[];\n}\n\n/**\n * Resolve the effective tool-call transport for any model and execution lane.\n *\n * Explicit settings win, followed by model metadata and then graded probe evidence. A probe-driven\n * text protocol is usable only with a current, recognized calibration; otherwise the model stays on\n * native calls for this turn. Callers use the reason code for diagnostics, but never reimplement the\n * precedence or silently substitute the default dialect.\n */\nexport function resolveModelToolProtocol(args: {\n\tmodel: Pick<Model<Api>, \"textToolCallProtocol\">;\n\tsettingsOverride?: boolean;\n\tadaptation: Pick<ModelAdaptationProfile, \"protocol\" | \"toolProbe\">;\n}): ModelToolProtocolResolution {\n\tif (args.settingsOverride === false) {\n\t\treturn { protocol: undefined, reasonCode: \"settings_disabled\" };\n\t}\n\tif (args.settingsOverride === true) {\n\t\treturn { protocol: true, reasonCode: \"settings_enabled\" };\n\t}\n\tif (args.model.textToolCallProtocol === true) {\n\t\treturn { protocol: true, reasonCode: \"model_enabled\" };\n\t}\n\tif (args.adaptation.toolProbe?.status !== \"text-protocol\") {\n\t\treturn { protocol: undefined, reasonCode: \"native_default\" };\n\t}\n\n\tconst calibration = args.adaptation.protocol;\n\tif (!calibration) {\n\t\treturn { protocol: undefined, reasonCode: \"probe_calibration_missing\" };\n\t}\n\tif (calibration.status === \"failed\") {\n\t\treturn {\n\t\t\tprotocol: undefined,\n\t\t\treasonCode: \"probe_calibration_failed\",\n\t\t\tvariantsTried: calibration.variantsTried,\n\t\t};\n\t}\n\tif (calibration.version !== MODEL_TOOL_PROTOCOL_VERSION || !isTextToolProtocolVariant(calibration.variant)) {\n\t\treturn { protocol: undefined, reasonCode: \"probe_calibration_invalid\" };\n\t}\n\treturn {\n\t\tprotocol: { variant: calibration.variant },\n\t\treasonCode: \"probe_calibrated\",\n\t};\n}\n"]}
1
+ {"version":3,"file":"model-tool-protocol.js","sourceRoot":"","sources":["../../src/core/model-tool-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,2BAA2B,EAAE,CAAC;IACzE,CAAC;IACD,OAAO;QACN,QAAQ,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE;QAC1C,UAAU,EAAE,kBAAkB;KAC9B,CAAC;AACH,CAAC","sourcesContent":["import { type Api, isTextToolProtocolVariant, type Model, type SimpleStreamOptions } from \"@caupulican/pi-ai\";\nimport type { ModelAdaptationProfile } from \"./models/adaptation-store.ts\";\n\nexport const MODEL_TOOL_PROTOCOL_VERSION = 1;\n\nexport type ModelToolProtocolReasonCode =\n\t| \"settings_disabled\"\n\t| \"settings_enabled\"\n\t| \"model_enabled\"\n\t| \"probe_calibrated\"\n\t| \"probe_calibration_missing\"\n\t| \"probe_calibration_failed\"\n\t| \"probe_calibration_invalid\"\n\t| \"native_default\";\n\nexport interface ModelToolProtocolResolution {\n\tprotocol: SimpleStreamOptions[\"textToolCallProtocol\"];\n\treasonCode: ModelToolProtocolReasonCode;\n\tvariantsTried?: readonly string[];\n}\n\n/**\n * Resolve the effective tool-call transport for any model and execution lane.\n *\n * Explicit settings win, followed by model metadata and then graded probe evidence. A probe-driven\n * text protocol is usable only with a current, recognized calibration; otherwise the model stays on\n * native calls for this turn. Callers use the reason code for diagnostics, but never reimplement the\n * precedence or silently substitute the default dialect.\n */\nexport function resolveModelToolProtocol(args: {\n\tmodel: Pick<Model<Api>, \"textToolCallProtocol\">;\n\tsettingsOverride?: boolean;\n\tadaptation: Pick<ModelAdaptationProfile, \"protocol\" | \"toolProbe\">;\n}): ModelToolProtocolResolution {\n\tif (args.settingsOverride === false) {\n\t\treturn { protocol: undefined, reasonCode: \"settings_disabled\" };\n\t}\n\tif (args.settingsOverride === true) {\n\t\treturn { protocol: true, reasonCode: \"settings_enabled\" };\n\t}\n\tif (args.model.textToolCallProtocol === true) {\n\t\treturn { protocol: true, reasonCode: \"model_enabled\" };\n\t}\n\tif (args.adaptation.toolProbe?.status !== \"text-protocol\") {\n\t\treturn { protocol: undefined, reasonCode: \"native_default\" };\n\t}\n\n\tconst calibration = args.adaptation.protocol;\n\tif (!calibration) {\n\t\treturn { protocol: undefined, reasonCode: \"probe_calibration_missing\" };\n\t}\n\tif (calibration.status === \"failed\") {\n\t\treturn {\n\t\t\tprotocol: undefined,\n\t\t\treasonCode: \"probe_calibration_failed\",\n\t\t\tvariantsTried: calibration.variantsTried,\n\t\t};\n\t}\n\tif (calibration.version !== MODEL_TOOL_PROTOCOL_VERSION || !isTextToolProtocolVariant(calibration.variant)) {\n\t\treturn { protocol: undefined, reasonCode: \"probe_calibration_invalid\" };\n\t}\n\treturn {\n\t\tprotocol: { variant: calibration.variant },\n\t\treasonCode: \"probe_calibrated\",\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"adaptation-store.d.ts","sourceRoot":"","sources":["../../../src/core/models/adaptation-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,eAAe,EAAqC,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAEpB,MAAM,mBAAmB,CAAC;AAM3B,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,wBAAwB,GACjC;IACA,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACpB,GACD;IACA,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,QAAQ,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEL,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,eAAe,GAAG,MAAM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I,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAWrG;IAED,sEAAsE;IACtE,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAKnD;IAED,6EAA6E;IAC7E,MAAM,IAAI,qBAAqB,EAAE,CAMhC;CACD","sourcesContent":["import { stateFile } from \"../agent-paths.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { isRecordObject } from \"../util/value-guards.ts\";\nimport { type HostFingerprint, HostStateStore, isHostFingerprint } from \"./host-state-store.ts\";\nimport {\n\thasUsableModelPerfSample,\n\tisModelPerfProfile,\n\ttype ModelPerfProfile,\n\ttype ModelPerfSample,\n\tupdateModelPerfProfile,\n} from \"./perf-profile.ts\";\n\nconst STORE_VERSION = 1;\nconst MAX_RULES_PER_MODEL = 5;\nconst RETIRE_AFTER_MS = 30 * 24 * 60 * 60 * 1000;\n\nexport interface ModelAdaptationRule {\n\tmode: string;\n\ttext: string;\n\taddedAt: string;\n\tlastFiredAt: string;\n}\n\nexport type ModelProtocolCalibration =\n\t| {\n\t\t\tversion: number;\n\t\t\tstatus?: \"calibrated\";\n\t\t\tvariant: string;\n\t\t\tcalibratedAt: string;\n\t }\n\t| {\n\t\t\tversion: number;\n\t\t\tstatus: \"failed\";\n\t\t\tattemptedAt: string;\n\t\t\tvariantsTried: string[];\n\t };\n\nexport type ModelToolProbeVerdict = \"native\" | \"text-protocol\" | \"none\";\nexport type NativeToolProbeGrade = \"task\" | \"echo-only\" | \"absent\";\n\nexport interface ModelToolProbe {\n\tversion: number;\n\tstatus: ModelToolProbeVerdict;\n\tprobedAt: string;\n\tvariant?: string;\n\tnativeGrade?: NativeToolProbeGrade;\n\tdiagnostic?: string;\n}\n\nexport interface ModelTeachStats {\n\ttaught: number;\n\trecurrenceBefore: number;\n\trecurrenceAfter: number;\n}\n\nexport interface ModelAdaptationProfile {\n\trules: ModelAdaptationRule[];\n\tprotocol?: ModelProtocolCalibration;\n\ttoolProbe?: ModelToolProbe;\n\tperf?: ModelPerfProfile;\n\tteachStats: Record<string, ModelTeachStats>;\n}\n\nexport interface StoredModelAdaptation {\n\tmodel: string;\n\tprofile: ModelAdaptationProfile;\n\tat: string;\n\thost: HostFingerprint;\n}\n\ninterface ProfileMutation {\n\tprofile: ModelAdaptationProfile;\n\tentry?: StoredModelAdaptation;\n\tapplied: boolean;\n}\n\nfunction emptyProfile(): ModelAdaptationProfile {\n\treturn { rules: [], teachStats: {} };\n}\n\nfunction normalizeProfile(profile: Partial<ModelAdaptationProfile> | undefined): ModelAdaptationProfile {\n\treturn {\n\t\trules: Array.isArray(profile?.rules) ? profile.rules.filter(isRule) : [],\n\t\t...(isProtocol(profile?.protocol) && { protocol: profile.protocol }),\n\t\t...(isToolProbe(profile?.toolProbe) && { toolProbe: profile.toolProbe }),\n\t\t...(isModelPerfProfile(profile?.perf) && { perf: profile.perf }),\n\t\tteachStats: isRecordObject(profile?.teachStats) ? filterTeachStats(profile.teachStats) : {},\n\t};\n}\n\nfunction isRule(value: unknown): value is ModelAdaptationRule {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.mode === \"string\" &&\n\t\ttypeof value.text === \"string\" &&\n\t\ttypeof value.addedAt === \"string\" &&\n\t\ttypeof value.lastFiredAt === \"string\"\n\t);\n}\n\nfunction isProtocol(value: unknown): value is ModelProtocolCalibration {\n\tif (!isRecordObject(value) || typeof value.version !== \"number\") return false;\n\tif (value.status === \"failed\") {\n\t\treturn (\n\t\t\ttypeof value.attemptedAt === \"string\" &&\n\t\t\tArray.isArray(value.variantsTried) &&\n\t\t\tvalue.variantsTried.every((variant) => typeof variant === \"string\")\n\t\t);\n\t}\n\treturn (\n\t\t(value.status === undefined || value.status === \"calibrated\") &&\n\t\ttypeof value.variant === \"string\" &&\n\t\ttypeof value.calibratedAt === \"string\"\n\t);\n}\n\nfunction isToolProbe(value: unknown): value is ModelToolProbe {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.version === \"number\" &&\n\t\t(value.status === \"native\" || value.status === \"text-protocol\" || value.status === \"none\") &&\n\t\ttypeof value.probedAt === \"string\" &&\n\t\t(value.variant === undefined || typeof value.variant === \"string\") &&\n\t\t(value.nativeGrade === undefined ||\n\t\t\tvalue.nativeGrade === \"task\" ||\n\t\t\tvalue.nativeGrade === \"echo-only\" ||\n\t\t\tvalue.nativeGrade === \"absent\") &&\n\t\t(value.diagnostic === undefined || typeof value.diagnostic === \"string\")\n\t);\n}\n\nfunction isTeachStats(value: unknown): value is ModelTeachStats {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.taught === \"number\" &&\n\t\ttypeof value.recurrenceBefore === \"number\" &&\n\t\ttypeof value.recurrenceAfter === \"number\"\n\t);\n}\n\nfunction filterTeachStats(value: Record<string, unknown>): Record<string, ModelTeachStats> {\n\treturn Object.fromEntries(\n\t\tObject.entries(value).filter((entry): entry is [string, ModelTeachStats] => isTeachStats(entry[1])),\n\t);\n}\n\nfunction ruleRecency(rule: ModelAdaptationRule): number {\n\tconst lastFired = Date.parse(rule.lastFiredAt);\n\tif (Number.isFinite(lastFired)) return lastFired;\n\tconst added = Date.parse(rule.addedAt);\n\treturn Number.isFinite(added) ? added : 0;\n}\n\n/**\n * Minimum post-rule recurrences before efficacy can retire a rule early — a single relapse is\n * noise, not proof the rule stopped working.\n */\nconst MIN_RECURRENCE_AFTER_FOR_EFFICACY = 2;\n\n/**\n * Efficacy-based early retirement. `agent-session.ts`'s `_handleModelAdaptationTelemetry` bumps\n * `recurrenceBefore` each time a failure mode recurs BEFORE a standing rule exists for it (the\n * baseline that earned the rule), then switches to bumping `recurrenceAfter` each time the SAME mode\n * recurs AFTER the rule fired. So a rule that is actually working keeps `recurrenceAfter` low relative\n * to its own pre-rule baseline; a rule that has caught up to (or exceeded) that baseline has\n * demonstrably stopped reducing recurrence and should retire before the time-based outer bound.\n */\nfunction isRuleEffective(stats: ModelTeachStats | undefined): boolean {\n\tif (!stats || stats.recurrenceAfter < MIN_RECURRENCE_AFTER_FOR_EFFICACY) return true; // not enough post-rule evidence yet\n\treturn stats.recurrenceAfter < stats.recurrenceBefore;\n}\n\n/**\n * Prune rules past the time-based outer bound (`RETIRE_AFTER_MS`, always enforced) OR past efficacy\n * (a rule that stopped reducing recurrence retires early; a rule that keeps helping persists until\n * the outer bound).\n */\nfunction pruneRetiredRules(\n\trules: readonly ModelAdaptationRule[],\n\tteachStats: Record<string, ModelTeachStats>,\n\tnow: Date,\n): ModelAdaptationRule[] {\n\tconst cutoff = now.getTime() - RETIRE_AFTER_MS;\n\treturn rules.filter((rule) => ruleRecency(rule) >= cutoff && isRuleEffective(teachStats[rule.mode]));\n}\n\nfunction enforceRuleCap(rules: readonly ModelAdaptationRule[]): ModelAdaptationRule[] {\n\tif (rules.length <= MAX_RULES_PER_MODEL) return [...rules];\n\treturn [...rules].sort((a, b) => ruleRecency(b) - ruleRecency(a)).slice(0, MAX_RULES_PER_MODEL);\n}\n\nfunction mergeRule(rules: readonly ModelAdaptationRule[], rule: ModelAdaptationRule): ModelAdaptationRule[] {\n\tconst withoutSameMode = rules.filter((existing) => existing.mode !== rule.mode);\n\treturn enforceRuleCap([...withoutSameMode, rule]);\n}\n\nfunction parseAdaptationHost(value: unknown, hostId: string): Record<string, StoredModelAdaptation> | undefined {\n\tif (!isRecordObject(value)) return undefined;\n\tconst profiles: Record<string, StoredModelAdaptation> = {};\n\tfor (const [model, candidate] of Object.entries(value)) {\n\t\tif (\n\t\t\t!isRecordObject(candidate) ||\n\t\t\tcandidate.model !== model ||\n\t\t\ttypeof candidate.at !== \"string\" ||\n\t\t\t!isHostFingerprint(candidate.host) ||\n\t\t\tcandidate.host.id !== hostId ||\n\t\t\t!isRecordObject(candidate.profile)\n\t\t)\n\t\t\tcontinue;\n\t\tprofiles[model] = {\n\t\t\tmodel,\n\t\t\tprofile: normalizeProfile(candidate.profile),\n\t\t\tat: candidate.at,\n\t\t\thost: candidate.host,\n\t\t};\n\t}\n\treturn profiles;\n}\n\nexport class ModelAdaptationStore {\n\tprivate readonly storage: HostStateStore<Record<string, StoredModelAdaptation>>;\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: parseAdaptationHost,\n\t\t});\n\t}\n\n\tstatic forAgentDir(\n\t\tagentDir: string,\n\t\toptions?: { fingerprint?: () => HostFingerprint; readOnly?: boolean },\n\t): ModelAdaptationStore {\n\t\treturn new ModelAdaptationStore(stateFile(agentDir, \"model-adaptation.json\"), options);\n\t}\n\n\t/**\n\t * Load-mutate-write under a single exclusive lock so two concurrent stores (e.g. two sessions\n\t * sharing an agentDir) can't both read the old file and clobber each other's write.\n\t */\n\tprivate store(model: string, profile: ModelAdaptationProfile, at: string): StoredModelAdaptation {\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(profiles, host) => {\n\t\t\t\tconst entry: StoredModelAdaptation = { model, profile: normalizeProfile(profile), at, host };\n\t\t\t\tprofiles[model] = entry;\n\t\t\t\treturn { result: entry, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Keep the complete profile read-modify-write transaction under the host-state lock. */\n\tprivate mutateProfile(\n\t\tmodel: string,\n\t\tnow: Date,\n\t\tmutate: (profile: ModelAdaptationProfile) => ModelAdaptationProfile | undefined,\n\t\tstoredAt = now.toISOString(),\n\t): ProfileMutation {\n\t\treturn this.storage.mutateCurrentHost<ProfileMutation>(\n\t\t\t() => ({}),\n\t\t\t(profiles, host) => {\n\t\t\t\tconst current = normalizeProfile(profiles[model]?.profile);\n\t\t\t\tconst activeRules = pruneRetiredRules(current.rules, current.teachStats, now);\n\t\t\t\tconst pruned = activeRules.length !== current.rules.length;\n\t\t\t\tconst active = pruned ? { ...current, rules: activeRules } : current;\n\t\t\t\tconst requested = mutate(active);\n\t\t\t\tconst applied = requested !== undefined;\n\t\t\t\tif (!applied && !pruned) {\n\t\t\t\t\treturn { result: { profile: active, applied: false }, changed: false };\n\t\t\t\t}\n\t\t\t\tconst profile = normalizeProfile(requested ?? active);\n\t\t\t\tconst entry: StoredModelAdaptation = { model, profile, at: storedAt, host };\n\t\t\t\tprofiles[model] = entry;\n\t\t\t\treturn { result: { profile, entry, applied }, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Persist the profile for a model on the CURRENT host. Best-effort, returns the entry. */\n\tsave(model: string, profile: ModelAdaptationProfile, at?: string): StoredModelAdaptation {\n\t\treturn this.store(model, profile, at ?? new Date().toISOString());\n\t}\n\n\t/** Profile for a model on the current host; prunes retired rules before returning. */\n\tget(model: string, now: Date = new Date()): ModelAdaptationProfile {\n\t\tconst entry = this.storage.getHost()?.[model];\n\t\tif (!entry) return emptyProfile();\n\t\tconst profile = normalizeProfile(entry.profile);\n\t\tconst prunedRules = pruneRetiredRules(profile.rules, profile.teachStats, now);\n\t\tif (prunedRules.length !== profile.rules.length) {\n\t\t\treturn this.mutateProfile(model, now, () => undefined).profile;\n\t\t}\n\t\treturn profile;\n\t}\n\n\t/** Add or replace one standing rule, enforcing the per-model cap. */\n\taddRule(\n\t\tmodel: string,\n\t\trule: { mode: string; text: string; addedAt?: string; lastFiredAt?: string },\n\t\tnow = new Date(),\n\t): StoredModelAdaptation {\n\t\tconst at = now.toISOString();\n\t\tconst nextRule: ModelAdaptationRule = {\n\t\t\tmode: rule.mode,\n\t\t\ttext: rule.text,\n\t\t\taddedAt: rule.addedAt ?? at,\n\t\t\tlastFiredAt: rule.lastFiredAt ?? at,\n\t\t};\n\t\tconst result = this.mutateProfile(model, now, (profile) => ({\n\t\t\t...profile,\n\t\t\trules: mergeRule(profile.rules, nextRule),\n\t\t}));\n\t\treturn result.entry!;\n\t}\n\n\tremoveRule(model: string, mode: string, at = new Date()): boolean {\n\t\treturn this.mutateProfile(model, at, (profile) => {\n\t\t\tconst rules = profile.rules.filter((rule) => rule.mode !== mode);\n\t\t\treturn rules.length === profile.rules.length ? undefined : { ...profile, rules };\n\t\t}).applied;\n\t}\n\n\t/** Update last-fired recency for an existing rule. No-op when absent. */\n\tmarkRuleFired(model: string, mode: string, at = new Date()): StoredModelAdaptation | undefined {\n\t\tconst result = this.mutateProfile(model, at, (profile) => {\n\t\t\tconst rules = profile.rules.map((rule) =>\n\t\t\t\trule.mode === mode ? { ...rule, lastFiredAt: at.toISOString() } : rule,\n\t\t\t);\n\t\t\treturn rules.every((rule, index) => rule === profile.rules[index]) ? undefined : { ...profile, rules };\n\t\t});\n\t\treturn result.applied ? result.entry : undefined;\n\t}\n\n\tsetProtocol(model: string, protocol: ModelProtocolCalibration, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? (protocol.status === \"failed\" ? protocol.attemptedAt : protocol.calibratedAt);\n\t\treturn this.mutateProfile(model, new Date(now), (profile) => ({ ...profile, protocol }), now).entry!;\n\t}\n\n\tsetToolProbe(model: string, toolProbe: ModelToolProbe, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? toolProbe.probedAt;\n\t\treturn this.mutateProfile(model, new Date(now), (profile) => ({ ...profile, toolProbe }), now).entry!;\n\t}\n\n\trecordPerfSample(model: string, sample: ModelPerfSample, at?: string): StoredModelAdaptation | undefined {\n\t\tif (!hasUsableModelPerfSample(sample)) return undefined;\n\t\tconst now = at ?? sample.at ?? new Date().toISOString();\n\t\tconst result = this.mutateProfile(\n\t\t\tmodel,\n\t\t\tnew Date(now),\n\t\t\t(profile) => {\n\t\t\t\tconst perf = updateModelPerfProfile(profile.perf, sample, now);\n\t\t\t\treturn perf ? { ...profile, perf } : undefined;\n\t\t\t},\n\t\t\tnow,\n\t\t);\n\t\treturn result.applied ? result.entry : undefined;\n\t}\n\n\tremoveProtocol(model: string, at = new Date()): boolean {\n\t\treturn this.mutateProfile(model, at, (profile) => {\n\t\t\tif (!profile.protocol) return undefined;\n\t\t\tconst { protocol: _protocol, ...rest } = profile;\n\t\t\treturn rest;\n\t\t}).applied;\n\t}\n\n\tsetTeachStats(model: string, mode: string, stats: ModelTeachStats, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? new Date().toISOString();\n\t\treturn this.mutateProfile(\n\t\t\tmodel,\n\t\t\tnew Date(now),\n\t\t\t(profile) => ({\n\t\t\t\t...profile,\n\t\t\t\tteachStats: { ...profile.teachStats, [mode]: stats },\n\t\t\t}),\n\t\t\tnow,\n\t\t).entry!;\n\t}\n\n\t/** Profiles for the current host (default) or an explicit host id. */\n\tgetForHost(hostId?: string): StoredModelAdaptation[] {\n\t\treturn Object.values(this.storage.getHost(hostId) ?? {}).map((entry) => ({\n\t\t\t...entry,\n\t\t\tprofile: normalizeProfile(entry.profile),\n\t\t}));\n\t}\n\n\t/** Every stored profile across all hosts (for cross-machine comparisons). */\n\tgetAll(): StoredModelAdaptation[] {\n\t\treturn this.storage\n\t\t\t.getAllHosts()\n\t\t\t.flatMap((models) =>\n\t\t\t\tObject.values(models).map((entry) => ({ ...entry, profile: normalizeProfile(entry.profile) })),\n\t\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"adaptation-store.d.ts","sourceRoot":"","sources":["../../../src/core/models/adaptation-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,eAAe,EAAqC,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAEpB,MAAM,mBAAmB,CAAC;AAM3B,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,wBAAwB,GACjC;IACA,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;IACt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MAAM,GAAG,qBAAqB,CAGzF;IAED,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAavG;IAED,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,OAAa,GAAG,OAAO,CAMtD;IAED,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAWrG;IAED,sEAAsE;IACtE,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAKnD;IAED,6EAA6E;IAC7E,MAAM,IAAI,qBAAqB,EAAE,CAMhC;CACD"}
@@ -123,7 +123,6 @@ function parseAdaptationHost(value, hostId) {
123
123
  return profiles;
124
124
  }
125
125
  export class ModelAdaptationStore {
126
- storage;
127
126
  constructor(filePath, options) {
128
127
  this.storage = new HostStateStore({
129
128
  filePath,
@@ -1 +1 @@
1
- {"version":3,"file":"adaptation-store.js","sourceRoot":"","sources":["../../../src/core/models/adaptation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAwB,cAAc,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAGlB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AA8DjD,SAAS,YAAY,GA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U,EAAE,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE;SACpD,CAAC,EACF,GAAG,CACH,CAAC,KAAM,CAAC;IAAA,CACT;IAED,sEAAsE;IACtE,UAAU,CAAC,MAAe,EAA2B;QACpD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACxE,GAAG,KAAK;YACR,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC;SACxC,CAAC,CAAC,CAAC;IAAA,CACJ;IAED,6EAA6E;IAC7E,MAAM,GAA4B;QACjC,OAAO,IAAI,CAAC,OAAO;aACjB,WAAW,EAAE;aACb,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CACnB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAC9F,CAAC;IAAA,CACH;CACD","sourcesContent":["import { stateFile } from \"../agent-paths.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { isRecordObject } from \"../util/value-guards.ts\";\nimport { type HostFingerprint, HostStateStore, isHostFingerprint } from \"./host-state-store.ts\";\nimport {\n\thasUsableModelPerfSample,\n\tisModelPerfProfile,\n\ttype ModelPerfProfile,\n\ttype ModelPerfSample,\n\tupdateModelPerfProfile,\n} from \"./perf-profile.ts\";\n\nconst STORE_VERSION = 1;\nconst MAX_RULES_PER_MODEL = 5;\nconst RETIRE_AFTER_MS = 30 * 24 * 60 * 60 * 1000;\n\nexport interface ModelAdaptationRule {\n\tmode: string;\n\ttext: string;\n\taddedAt: string;\n\tlastFiredAt: string;\n}\n\nexport type ModelProtocolCalibration =\n\t| {\n\t\t\tversion: number;\n\t\t\tstatus?: \"calibrated\";\n\t\t\tvariant: string;\n\t\t\tcalibratedAt: string;\n\t }\n\t| {\n\t\t\tversion: number;\n\t\t\tstatus: \"failed\";\n\t\t\tattemptedAt: string;\n\t\t\tvariantsTried: string[];\n\t };\n\nexport type ModelToolProbeVerdict = \"native\" | \"text-protocol\" | \"none\";\nexport type NativeToolProbeGrade = \"task\" | \"echo-only\" | \"absent\";\n\nexport interface ModelToolProbe {\n\tversion: number;\n\tstatus: ModelToolProbeVerdict;\n\tprobedAt: string;\n\tvariant?: string;\n\tnativeGrade?: NativeToolProbeGrade;\n\tdiagnostic?: string;\n}\n\nexport interface ModelTeachStats {\n\ttaught: number;\n\trecurrenceBefore: number;\n\trecurrenceAfter: number;\n}\n\nexport interface ModelAdaptationProfile {\n\trules: ModelAdaptationRule[];\n\tprotocol?: ModelProtocolCalibration;\n\ttoolProbe?: ModelToolProbe;\n\tperf?: ModelPerfProfile;\n\tteachStats: Record<string, ModelTeachStats>;\n}\n\nexport interface StoredModelAdaptation {\n\tmodel: string;\n\tprofile: ModelAdaptationProfile;\n\tat: string;\n\thost: HostFingerprint;\n}\n\ninterface ProfileMutation {\n\tprofile: ModelAdaptationProfile;\n\tentry?: StoredModelAdaptation;\n\tapplied: boolean;\n}\n\nfunction emptyProfile(): ModelAdaptationProfile {\n\treturn { rules: [], teachStats: {} };\n}\n\nfunction normalizeProfile(profile: Partial<ModelAdaptationProfile> | undefined): ModelAdaptationProfile {\n\treturn {\n\t\trules: Array.isArray(profile?.rules) ? profile.rules.filter(isRule) : [],\n\t\t...(isProtocol(profile?.protocol) && { protocol: profile.protocol }),\n\t\t...(isToolProbe(profile?.toolProbe) && { toolProbe: profile.toolProbe }),\n\t\t...(isModelPerfProfile(profile?.perf) && { perf: profile.perf }),\n\t\tteachStats: isRecordObject(profile?.teachStats) ? filterTeachStats(profile.teachStats) : {},\n\t};\n}\n\nfunction isRule(value: unknown): value is ModelAdaptationRule {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.mode === \"string\" &&\n\t\ttypeof value.text === \"string\" &&\n\t\ttypeof value.addedAt === \"string\" &&\n\t\ttypeof value.lastFiredAt === \"string\"\n\t);\n}\n\nfunction isProtocol(value: unknown): value is ModelProtocolCalibration {\n\tif (!isRecordObject(value) || typeof value.version !== \"number\") return false;\n\tif (value.status === \"failed\") {\n\t\treturn (\n\t\t\ttypeof value.attemptedAt === \"string\" &&\n\t\t\tArray.isArray(value.variantsTried) &&\n\t\t\tvalue.variantsTried.every((variant) => typeof variant === \"string\")\n\t\t);\n\t}\n\treturn (\n\t\t(value.status === undefined || value.status === \"calibrated\") &&\n\t\ttypeof value.variant === \"string\" &&\n\t\ttypeof value.calibratedAt === \"string\"\n\t);\n}\n\nfunction isToolProbe(value: unknown): value is ModelToolProbe {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.version === \"number\" &&\n\t\t(value.status === \"native\" || value.status === \"text-protocol\" || value.status === \"none\") &&\n\t\ttypeof value.probedAt === \"string\" &&\n\t\t(value.variant === undefined || typeof value.variant === \"string\") &&\n\t\t(value.nativeGrade === undefined ||\n\t\t\tvalue.nativeGrade === \"task\" ||\n\t\t\tvalue.nativeGrade === \"echo-only\" ||\n\t\t\tvalue.nativeGrade === \"absent\") &&\n\t\t(value.diagnostic === undefined || typeof value.diagnostic === \"string\")\n\t);\n}\n\nfunction isTeachStats(value: unknown): value is ModelTeachStats {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.taught === \"number\" &&\n\t\ttypeof value.recurrenceBefore === \"number\" &&\n\t\ttypeof value.recurrenceAfter === \"number\"\n\t);\n}\n\nfunction filterTeachStats(value: Record<string, unknown>): Record<string, ModelTeachStats> {\n\treturn Object.fromEntries(\n\t\tObject.entries(value).filter((entry): entry is [string, ModelTeachStats] => isTeachStats(entry[1])),\n\t);\n}\n\nfunction ruleRecency(rule: ModelAdaptationRule): number {\n\tconst lastFired = Date.parse(rule.lastFiredAt);\n\tif (Number.isFinite(lastFired)) return lastFired;\n\tconst added = Date.parse(rule.addedAt);\n\treturn Number.isFinite(added) ? added : 0;\n}\n\n/**\n * Minimum post-rule recurrences before efficacy can retire a rule early — a single relapse is\n * noise, not proof the rule stopped working.\n */\nconst MIN_RECURRENCE_AFTER_FOR_EFFICACY = 2;\n\n/**\n * Efficacy-based early retirement. `agent-session.ts`'s `_handleModelAdaptationTelemetry` bumps\n * `recurrenceBefore` each time a failure mode recurs BEFORE a standing rule exists for it (the\n * baseline that earned the rule), then switches to bumping `recurrenceAfter` each time the SAME mode\n * recurs AFTER the rule fired. So a rule that is actually working keeps `recurrenceAfter` low relative\n * to its own pre-rule baseline; a rule that has caught up to (or exceeded) that baseline has\n * demonstrably stopped reducing recurrence and should retire before the time-based outer bound.\n */\nfunction isRuleEffective(stats: ModelTeachStats | undefined): boolean {\n\tif (!stats || stats.recurrenceAfter < MIN_RECURRENCE_AFTER_FOR_EFFICACY) return true; // not enough post-rule evidence yet\n\treturn stats.recurrenceAfter < stats.recurrenceBefore;\n}\n\n/**\n * Prune rules past the time-based outer bound (`RETIRE_AFTER_MS`, always enforced) OR past efficacy\n * (a rule that stopped reducing recurrence retires early; a rule that keeps helping persists until\n * the outer bound).\n */\nfunction pruneRetiredRules(\n\trules: readonly ModelAdaptationRule[],\n\tteachStats: Record<string, ModelTeachStats>,\n\tnow: Date,\n): ModelAdaptationRule[] {\n\tconst cutoff = now.getTime() - RETIRE_AFTER_MS;\n\treturn rules.filter((rule) => ruleRecency(rule) >= cutoff && isRuleEffective(teachStats[rule.mode]));\n}\n\nfunction enforceRuleCap(rules: readonly ModelAdaptationRule[]): ModelAdaptationRule[] {\n\tif (rules.length <= MAX_RULES_PER_MODEL) return [...rules];\n\treturn [...rules].sort((a, b) => ruleRecency(b) - ruleRecency(a)).slice(0, MAX_RULES_PER_MODEL);\n}\n\nfunction mergeRule(rules: readonly ModelAdaptationRule[], rule: ModelAdaptationRule): ModelAdaptationRule[] {\n\tconst withoutSameMode = rules.filter((existing) => existing.mode !== rule.mode);\n\treturn enforceRuleCap([...withoutSameMode, rule]);\n}\n\nfunction parseAdaptationHost(value: unknown, hostId: string): Record<string, StoredModelAdaptation> | undefined {\n\tif (!isRecordObject(value)) return undefined;\n\tconst profiles: Record<string, StoredModelAdaptation> = {};\n\tfor (const [model, candidate] of Object.entries(value)) {\n\t\tif (\n\t\t\t!isRecordObject(candidate) ||\n\t\t\tcandidate.model !== model ||\n\t\t\ttypeof candidate.at !== \"string\" ||\n\t\t\t!isHostFingerprint(candidate.host) ||\n\t\t\tcandidate.host.id !== hostId ||\n\t\t\t!isRecordObject(candidate.profile)\n\t\t)\n\t\t\tcontinue;\n\t\tprofiles[model] = {\n\t\t\tmodel,\n\t\t\tprofile: normalizeProfile(candidate.profile),\n\t\t\tat: candidate.at,\n\t\t\thost: candidate.host,\n\t\t};\n\t}\n\treturn profiles;\n}\n\nexport class ModelAdaptationStore {\n\tprivate readonly storage: HostStateStore<Record<string, StoredModelAdaptation>>;\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: parseAdaptationHost,\n\t\t});\n\t}\n\n\tstatic forAgentDir(\n\t\tagentDir: string,\n\t\toptions?: { fingerprint?: () => HostFingerprint; readOnly?: boolean },\n\t): ModelAdaptationStore {\n\t\treturn new ModelAdaptationStore(stateFile(agentDir, \"model-adaptation.json\"), options);\n\t}\n\n\t/**\n\t * Load-mutate-write under a single exclusive lock so two concurrent stores (e.g. two sessions\n\t * sharing an agentDir) can't both read the old file and clobber each other's write.\n\t */\n\tprivate store(model: string, profile: ModelAdaptationProfile, at: string): StoredModelAdaptation {\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(profiles, host) => {\n\t\t\t\tconst entry: StoredModelAdaptation = { model, profile: normalizeProfile(profile), at, host };\n\t\t\t\tprofiles[model] = entry;\n\t\t\t\treturn { result: entry, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Keep the complete profile read-modify-write transaction under the host-state lock. */\n\tprivate mutateProfile(\n\t\tmodel: string,\n\t\tnow: Date,\n\t\tmutate: (profile: ModelAdaptationProfile) => ModelAdaptationProfile | undefined,\n\t\tstoredAt = now.toISOString(),\n\t): ProfileMutation {\n\t\treturn this.storage.mutateCurrentHost<ProfileMutation>(\n\t\t\t() => ({}),\n\t\t\t(profiles, host) => {\n\t\t\t\tconst current = normalizeProfile(profiles[model]?.profile);\n\t\t\t\tconst activeRules = pruneRetiredRules(current.rules, current.teachStats, now);\n\t\t\t\tconst pruned = activeRules.length !== current.rules.length;\n\t\t\t\tconst active = pruned ? { ...current, rules: activeRules } : current;\n\t\t\t\tconst requested = mutate(active);\n\t\t\t\tconst applied = requested !== undefined;\n\t\t\t\tif (!applied && !pruned) {\n\t\t\t\t\treturn { result: { profile: active, applied: false }, changed: false };\n\t\t\t\t}\n\t\t\t\tconst profile = normalizeProfile(requested ?? active);\n\t\t\t\tconst entry: StoredModelAdaptation = { model, profile, at: storedAt, host };\n\t\t\t\tprofiles[model] = entry;\n\t\t\t\treturn { result: { profile, entry, applied }, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Persist the profile for a model on the CURRENT host. Best-effort, returns the entry. */\n\tsave(model: string, profile: ModelAdaptationProfile, at?: string): StoredModelAdaptation {\n\t\treturn this.store(model, profile, at ?? new Date().toISOString());\n\t}\n\n\t/** Profile for a model on the current host; prunes retired rules before returning. */\n\tget(model: string, now: Date = new Date()): ModelAdaptationProfile {\n\t\tconst entry = this.storage.getHost()?.[model];\n\t\tif (!entry) return emptyProfile();\n\t\tconst profile = normalizeProfile(entry.profile);\n\t\tconst prunedRules = pruneRetiredRules(profile.rules, profile.teachStats, now);\n\t\tif (prunedRules.length !== profile.rules.length) {\n\t\t\treturn this.mutateProfile(model, now, () => undefined).profile;\n\t\t}\n\t\treturn profile;\n\t}\n\n\t/** Add or replace one standing rule, enforcing the per-model cap. */\n\taddRule(\n\t\tmodel: string,\n\t\trule: { mode: string; text: string; addedAt?: string; lastFiredAt?: string },\n\t\tnow = new Date(),\n\t): StoredModelAdaptation {\n\t\tconst at = now.toISOString();\n\t\tconst nextRule: ModelAdaptationRule = {\n\t\t\tmode: rule.mode,\n\t\t\ttext: rule.text,\n\t\t\taddedAt: rule.addedAt ?? at,\n\t\t\tlastFiredAt: rule.lastFiredAt ?? at,\n\t\t};\n\t\tconst result = this.mutateProfile(model, now, (profile) => ({\n\t\t\t...profile,\n\t\t\trules: mergeRule(profile.rules, nextRule),\n\t\t}));\n\t\treturn result.entry!;\n\t}\n\n\tremoveRule(model: string, mode: string, at = new Date()): boolean {\n\t\treturn this.mutateProfile(model, at, (profile) => {\n\t\t\tconst rules = profile.rules.filter((rule) => rule.mode !== mode);\n\t\t\treturn rules.length === profile.rules.length ? undefined : { ...profile, rules };\n\t\t}).applied;\n\t}\n\n\t/** Update last-fired recency for an existing rule. No-op when absent. */\n\tmarkRuleFired(model: string, mode: string, at = new Date()): StoredModelAdaptation | undefined {\n\t\tconst result = this.mutateProfile(model, at, (profile) => {\n\t\t\tconst rules = profile.rules.map((rule) =>\n\t\t\t\trule.mode === mode ? { ...rule, lastFiredAt: at.toISOString() } : rule,\n\t\t\t);\n\t\t\treturn rules.every((rule, index) => rule === profile.rules[index]) ? undefined : { ...profile, rules };\n\t\t});\n\t\treturn result.applied ? result.entry : undefined;\n\t}\n\n\tsetProtocol(model: string, protocol: ModelProtocolCalibration, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? (protocol.status === \"failed\" ? protocol.attemptedAt : protocol.calibratedAt);\n\t\treturn this.mutateProfile(model, new Date(now), (profile) => ({ ...profile, protocol }), now).entry!;\n\t}\n\n\tsetToolProbe(model: string, toolProbe: ModelToolProbe, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? toolProbe.probedAt;\n\t\treturn this.mutateProfile(model, new Date(now), (profile) => ({ ...profile, toolProbe }), now).entry!;\n\t}\n\n\trecordPerfSample(model: string, sample: ModelPerfSample, at?: string): StoredModelAdaptation | undefined {\n\t\tif (!hasUsableModelPerfSample(sample)) return undefined;\n\t\tconst now = at ?? sample.at ?? new Date().toISOString();\n\t\tconst result = this.mutateProfile(\n\t\t\tmodel,\n\t\t\tnew Date(now),\n\t\t\t(profile) => {\n\t\t\t\tconst perf = updateModelPerfProfile(profile.perf, sample, now);\n\t\t\t\treturn perf ? { ...profile, perf } : undefined;\n\t\t\t},\n\t\t\tnow,\n\t\t);\n\t\treturn result.applied ? result.entry : undefined;\n\t}\n\n\tremoveProtocol(model: string, at = new Date()): boolean {\n\t\treturn this.mutateProfile(model, at, (profile) => {\n\t\t\tif (!profile.protocol) return undefined;\n\t\t\tconst { protocol: _protocol, ...rest } = profile;\n\t\t\treturn rest;\n\t\t}).applied;\n\t}\n\n\tsetTeachStats(model: string, mode: string, stats: ModelTeachStats, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? new Date().toISOString();\n\t\treturn this.mutateProfile(\n\t\t\tmodel,\n\t\t\tnew Date(now),\n\t\t\t(profile) => ({\n\t\t\t\t...profile,\n\t\t\t\tteachStats: { ...profile.teachStats, [mode]: stats },\n\t\t\t}),\n\t\t\tnow,\n\t\t).entry!;\n\t}\n\n\t/** Profiles for the current host (default) or an explicit host id. */\n\tgetForHost(hostId?: string): StoredModelAdaptation[] {\n\t\treturn Object.values(this.storage.getHost(hostId) ?? {}).map((entry) => ({\n\t\t\t...entry,\n\t\t\tprofile: normalizeProfile(entry.profile),\n\t\t}));\n\t}\n\n\t/** Every stored profile across all hosts (for cross-machine comparisons). */\n\tgetAll(): StoredModelAdaptation[] {\n\t\treturn this.storage\n\t\t\t.getAllHosts()\n\t\t\t.flatMap((models) =>\n\t\t\t\tObject.values(models).map((entry) => ({ ...entry, profile: normalizeProfile(entry.profile) })),\n\t\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"adaptation-store.js","sourceRoot":"","sources":["../../../src/core/models/adaptation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAwB,cAAc,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAGlB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AA8DjD,SAAS,YAAY;IACpB,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAoD;IAC7E,OAAO;QACN,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;QACxE,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;QACpE,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;QACxE,GAAG,CAAC,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE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kerSession } from \"../session-role.ts\";\nimport { isRecordObject } from \"../util/value-guards.ts\";\nimport { type HostFingerprint, HostStateStore, isHostFingerprint } from \"./host-state-store.ts\";\nimport {\n\thasUsableModelPerfSample,\n\tisModelPerfProfile,\n\ttype ModelPerfProfile,\n\ttype ModelPerfSample,\n\tupdateModelPerfProfile,\n} from \"./perf-profile.ts\";\n\nconst STORE_VERSION = 1;\nconst MAX_RULES_PER_MODEL = 5;\nconst RETIRE_AFTER_MS = 30 * 24 * 60 * 60 * 1000;\n\nexport interface ModelAdaptationRule {\n\tmode: string;\n\ttext: string;\n\taddedAt: string;\n\tlastFiredAt: string;\n}\n\nexport type ModelProtocolCalibration =\n\t| {\n\t\t\tversion: number;\n\t\t\tstatus?: \"calibrated\";\n\t\t\tvariant: string;\n\t\t\tcalibratedAt: string;\n\t }\n\t| {\n\t\t\tversion: number;\n\t\t\tstatus: \"failed\";\n\t\t\tattemptedAt: string;\n\t\t\tvariantsTried: string[];\n\t };\n\nexport type ModelToolProbeVerdict = \"native\" | \"text-protocol\" | \"none\";\nexport type NativeToolProbeGrade = \"task\" | \"echo-only\" | \"absent\";\n\nexport interface ModelToolProbe {\n\tversion: number;\n\tstatus: ModelToolProbeVerdict;\n\tprobedAt: string;\n\tvariant?: string;\n\tnativeGrade?: NativeToolProbeGrade;\n\tdiagnostic?: string;\n}\n\nexport interface ModelTeachStats {\n\ttaught: number;\n\trecurrenceBefore: number;\n\trecurrenceAfter: number;\n}\n\nexport interface ModelAdaptationProfile {\n\trules: ModelAdaptationRule[];\n\tprotocol?: ModelProtocolCalibration;\n\ttoolProbe?: ModelToolProbe;\n\tperf?: ModelPerfProfile;\n\tteachStats: Record<string, ModelTeachStats>;\n}\n\nexport interface StoredModelAdaptation {\n\tmodel: string;\n\tprofile: ModelAdaptationProfile;\n\tat: string;\n\thost: HostFingerprint;\n}\n\ninterface ProfileMutation {\n\tprofile: ModelAdaptationProfile;\n\tentry?: StoredModelAdaptation;\n\tapplied: boolean;\n}\n\nfunction emptyProfile(): ModelAdaptationProfile {\n\treturn { rules: [], teachStats: {} };\n}\n\nfunction normalizeProfile(profile: Partial<ModelAdaptationProfile> | undefined): ModelAdaptationProfile {\n\treturn {\n\t\trules: Array.isArray(profile?.rules) ? profile.rules.filter(isRule) : [],\n\t\t...(isProtocol(profile?.protocol) && { protocol: profile.protocol }),\n\t\t...(isToolProbe(profile?.toolProbe) && { toolProbe: profile.toolProbe }),\n\t\t...(isModelPerfProfile(profile?.perf) && { perf: profile.perf }),\n\t\tteachStats: isRecordObject(profile?.teachStats) ? filterTeachStats(profile.teachStats) : {},\n\t};\n}\n\nfunction isRule(value: unknown): value is ModelAdaptationRule {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.mode === \"string\" &&\n\t\ttypeof value.text === \"string\" &&\n\t\ttypeof value.addedAt === \"string\" &&\n\t\ttypeof value.lastFiredAt === \"string\"\n\t);\n}\n\nfunction isProtocol(value: unknown): value is ModelProtocolCalibration {\n\tif (!isRecordObject(value) || typeof value.version !== \"number\") return false;\n\tif (value.status === \"failed\") {\n\t\treturn (\n\t\t\ttypeof value.attemptedAt === \"string\" &&\n\t\t\tArray.isArray(value.variantsTried) &&\n\t\t\tvalue.variantsTried.every((variant) => typeof variant === \"string\")\n\t\t);\n\t}\n\treturn (\n\t\t(value.status === undefined || value.status === \"calibrated\") &&\n\t\ttypeof value.variant === \"string\" &&\n\t\ttypeof value.calibratedAt === \"string\"\n\t);\n}\n\nfunction isToolProbe(value: unknown): value is ModelToolProbe {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.version === \"number\" &&\n\t\t(value.status === \"native\" || value.status === \"text-protocol\" || value.status === \"none\") &&\n\t\ttypeof value.probedAt === \"string\" &&\n\t\t(value.variant === undefined || typeof value.variant === \"string\") &&\n\t\t(value.nativeGrade === undefined ||\n\t\t\tvalue.nativeGrade === \"task\" ||\n\t\t\tvalue.nativeGrade === \"echo-only\" ||\n\t\t\tvalue.nativeGrade === \"absent\") &&\n\t\t(value.diagnostic === undefined || typeof value.diagnostic === \"string\")\n\t);\n}\n\nfunction isTeachStats(value: unknown): value is ModelTeachStats {\n\treturn (\n\t\tisRecordObject(value) &&\n\t\ttypeof value.taught === \"number\" &&\n\t\ttypeof value.recurrenceBefore === \"number\" &&\n\t\ttypeof value.recurrenceAfter === \"number\"\n\t);\n}\n\nfunction filterTeachStats(value: Record<string, unknown>): Record<string, ModelTeachStats> {\n\treturn Object.fromEntries(\n\t\tObject.entries(value).filter((entry): entry is [string, ModelTeachStats] => isTeachStats(entry[1])),\n\t);\n}\n\nfunction ruleRecency(rule: ModelAdaptationRule): number {\n\tconst lastFired = Date.parse(rule.lastFiredAt);\n\tif (Number.isFinite(lastFired)) return lastFired;\n\tconst added = Date.parse(rule.addedAt);\n\treturn Number.isFinite(added) ? added : 0;\n}\n\n/**\n * Minimum post-rule recurrences before efficacy can retire a rule early — a single relapse is\n * noise, not proof the rule stopped working.\n */\nconst MIN_RECURRENCE_AFTER_FOR_EFFICACY = 2;\n\n/**\n * Efficacy-based early retirement. `agent-session.ts`'s `_handleModelAdaptationTelemetry` bumps\n * `recurrenceBefore` each time a failure mode recurs BEFORE a standing rule exists for it (the\n * baseline that earned the rule), then switches to bumping `recurrenceAfter` each time the SAME mode\n * recurs AFTER the rule fired. So a rule that is actually working keeps `recurrenceAfter` low relative\n * to its own pre-rule baseline; a rule that has caught up to (or exceeded) that baseline has\n * demonstrably stopped reducing recurrence and should retire before the time-based outer bound.\n */\nfunction isRuleEffective(stats: ModelTeachStats | undefined): boolean {\n\tif (!stats || stats.recurrenceAfter < MIN_RECURRENCE_AFTER_FOR_EFFICACY) return true; // not enough post-rule evidence yet\n\treturn stats.recurrenceAfter < stats.recurrenceBefore;\n}\n\n/**\n * Prune rules past the time-based outer bound (`RETIRE_AFTER_MS`, always enforced) OR past efficacy\n * (a rule that stopped reducing recurrence retires early; a rule that keeps helping persists until\n * the outer bound).\n */\nfunction pruneRetiredRules(\n\trules: readonly ModelAdaptationRule[],\n\tteachStats: Record<string, ModelTeachStats>,\n\tnow: Date,\n): ModelAdaptationRule[] {\n\tconst cutoff = now.getTime() - RETIRE_AFTER_MS;\n\treturn rules.filter((rule) => ruleRecency(rule) >= cutoff && isRuleEffective(teachStats[rule.mode]));\n}\n\nfunction enforceRuleCap(rules: readonly ModelAdaptationRule[]): ModelAdaptationRule[] {\n\tif (rules.length <= MAX_RULES_PER_MODEL) return [...rules];\n\treturn [...rules].sort((a, b) => ruleRecency(b) - ruleRecency(a)).slice(0, MAX_RULES_PER_MODEL);\n}\n\nfunction mergeRule(rules: readonly ModelAdaptationRule[], rule: ModelAdaptationRule): ModelAdaptationRule[] {\n\tconst withoutSameMode = rules.filter((existing) => existing.mode !== rule.mode);\n\treturn enforceRuleCap([...withoutSameMode, rule]);\n}\n\nfunction parseAdaptationHost(value: unknown, hostId: string): Record<string, StoredModelAdaptation> | undefined {\n\tif (!isRecordObject(value)) return undefined;\n\tconst profiles: Record<string, StoredModelAdaptation> = {};\n\tfor (const [model, candidate] of Object.entries(value)) {\n\t\tif (\n\t\t\t!isRecordObject(candidate) ||\n\t\t\tcandidate.model !== model ||\n\t\t\ttypeof candidate.at !== \"string\" ||\n\t\t\t!isHostFingerprint(candidate.host) ||\n\t\t\tcandidate.host.id !== hostId ||\n\t\t\t!isRecordObject(candidate.profile)\n\t\t)\n\t\t\tcontinue;\n\t\tprofiles[model] = {\n\t\t\tmodel,\n\t\t\tprofile: normalizeProfile(candidate.profile),\n\t\t\tat: candidate.at,\n\t\t\thost: candidate.host,\n\t\t};\n\t}\n\treturn profiles;\n}\n\nexport class ModelAdaptationStore {\n\tprivate readonly storage: HostStateStore<Record<string, StoredModelAdaptation>>;\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: parseAdaptationHost,\n\t\t});\n\t}\n\n\tstatic forAgentDir(\n\t\tagentDir: string,\n\t\toptions?: { fingerprint?: () => HostFingerprint; readOnly?: boolean },\n\t): ModelAdaptationStore {\n\t\treturn new ModelAdaptationStore(stateFile(agentDir, \"model-adaptation.json\"), options);\n\t}\n\n\t/**\n\t * Load-mutate-write under a single exclusive lock so two concurrent stores (e.g. two sessions\n\t * sharing an agentDir) can't both read the old file and clobber each other's write.\n\t */\n\tprivate store(model: string, profile: ModelAdaptationProfile, at: string): StoredModelAdaptation {\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(profiles, host) => {\n\t\t\t\tconst entry: StoredModelAdaptation = { model, profile: normalizeProfile(profile), at, host };\n\t\t\t\tprofiles[model] = entry;\n\t\t\t\treturn { result: entry, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Keep the complete profile read-modify-write transaction under the host-state lock. */\n\tprivate mutateProfile(\n\t\tmodel: string,\n\t\tnow: Date,\n\t\tmutate: (profile: ModelAdaptationProfile) => ModelAdaptationProfile | undefined,\n\t\tstoredAt = now.toISOString(),\n\t): ProfileMutation {\n\t\treturn this.storage.mutateCurrentHost<ProfileMutation>(\n\t\t\t() => ({}),\n\t\t\t(profiles, host) => {\n\t\t\t\tconst current = normalizeProfile(profiles[model]?.profile);\n\t\t\t\tconst activeRules = pruneRetiredRules(current.rules, current.teachStats, now);\n\t\t\t\tconst pruned = activeRules.length !== current.rules.length;\n\t\t\t\tconst active = pruned ? { ...current, rules: activeRules } : current;\n\t\t\t\tconst requested = mutate(active);\n\t\t\t\tconst applied = requested !== undefined;\n\t\t\t\tif (!applied && !pruned) {\n\t\t\t\t\treturn { result: { profile: active, applied: false }, changed: false };\n\t\t\t\t}\n\t\t\t\tconst profile = normalizeProfile(requested ?? active);\n\t\t\t\tconst entry: StoredModelAdaptation = { model, profile, at: storedAt, host };\n\t\t\t\tprofiles[model] = entry;\n\t\t\t\treturn { result: { profile, entry, applied }, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Persist the profile for a model on the CURRENT host. Best-effort, returns the entry. */\n\tsave(model: string, profile: ModelAdaptationProfile, at?: string): StoredModelAdaptation {\n\t\treturn this.store(model, profile, at ?? new Date().toISOString());\n\t}\n\n\t/** Profile for a model on the current host; prunes retired rules before returning. */\n\tget(model: string, now: Date = new Date()): ModelAdaptationProfile {\n\t\tconst entry = this.storage.getHost()?.[model];\n\t\tif (!entry) return emptyProfile();\n\t\tconst profile = normalizeProfile(entry.profile);\n\t\tconst prunedRules = pruneRetiredRules(profile.rules, profile.teachStats, now);\n\t\tif (prunedRules.length !== profile.rules.length) {\n\t\t\treturn this.mutateProfile(model, now, () => undefined).profile;\n\t\t}\n\t\treturn profile;\n\t}\n\n\t/** Add or replace one standing rule, enforcing the per-model cap. */\n\taddRule(\n\t\tmodel: string,\n\t\trule: { mode: string; text: string; addedAt?: string; lastFiredAt?: string },\n\t\tnow = new Date(),\n\t): StoredModelAdaptation {\n\t\tconst at = now.toISOString();\n\t\tconst nextRule: ModelAdaptationRule = {\n\t\t\tmode: rule.mode,\n\t\t\ttext: rule.text,\n\t\t\taddedAt: rule.addedAt ?? at,\n\t\t\tlastFiredAt: rule.lastFiredAt ?? at,\n\t\t};\n\t\tconst result = this.mutateProfile(model, now, (profile) => ({\n\t\t\t...profile,\n\t\t\trules: mergeRule(profile.rules, nextRule),\n\t\t}));\n\t\treturn result.entry!;\n\t}\n\n\tremoveRule(model: string, mode: string, at = new Date()): boolean {\n\t\treturn this.mutateProfile(model, at, (profile) => {\n\t\t\tconst rules = profile.rules.filter((rule) => rule.mode !== mode);\n\t\t\treturn rules.length === profile.rules.length ? undefined : { ...profile, rules };\n\t\t}).applied;\n\t}\n\n\t/** Update last-fired recency for an existing rule. No-op when absent. */\n\tmarkRuleFired(model: string, mode: string, at = new Date()): StoredModelAdaptation | undefined {\n\t\tconst result = this.mutateProfile(model, at, (profile) => {\n\t\t\tconst rules = profile.rules.map((rule) =>\n\t\t\t\trule.mode === mode ? { ...rule, lastFiredAt: at.toISOString() } : rule,\n\t\t\t);\n\t\t\treturn rules.every((rule, index) => rule === profile.rules[index]) ? undefined : { ...profile, rules };\n\t\t});\n\t\treturn result.applied ? result.entry : undefined;\n\t}\n\n\tsetProtocol(model: string, protocol: ModelProtocolCalibration, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? (protocol.status === \"failed\" ? protocol.attemptedAt : protocol.calibratedAt);\n\t\treturn this.mutateProfile(model, new Date(now), (profile) => ({ ...profile, protocol }), now).entry!;\n\t}\n\n\tsetToolProbe(model: string, toolProbe: ModelToolProbe, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? toolProbe.probedAt;\n\t\treturn this.mutateProfile(model, new Date(now), (profile) => ({ ...profile, toolProbe }), now).entry!;\n\t}\n\n\trecordPerfSample(model: string, sample: ModelPerfSample, at?: string): StoredModelAdaptation | undefined {\n\t\tif (!hasUsableModelPerfSample(sample)) return undefined;\n\t\tconst now = at ?? sample.at ?? new Date().toISOString();\n\t\tconst result = this.mutateProfile(\n\t\t\tmodel,\n\t\t\tnew Date(now),\n\t\t\t(profile) => {\n\t\t\t\tconst perf = updateModelPerfProfile(profile.perf, sample, now);\n\t\t\t\treturn perf ? { ...profile, perf } : undefined;\n\t\t\t},\n\t\t\tnow,\n\t\t);\n\t\treturn result.applied ? result.entry : undefined;\n\t}\n\n\tremoveProtocol(model: string, at = new Date()): boolean {\n\t\treturn this.mutateProfile(model, at, (profile) => {\n\t\t\tif (!profile.protocol) return undefined;\n\t\t\tconst { protocol: _protocol, ...rest } = profile;\n\t\t\treturn rest;\n\t\t}).applied;\n\t}\n\n\tsetTeachStats(model: string, mode: string, stats: ModelTeachStats, at?: string): StoredModelAdaptation {\n\t\tconst now = at ?? new Date().toISOString();\n\t\treturn this.mutateProfile(\n\t\t\tmodel,\n\t\t\tnew Date(now),\n\t\t\t(profile) => ({\n\t\t\t\t...profile,\n\t\t\t\tteachStats: { ...profile.teachStats, [mode]: stats },\n\t\t\t}),\n\t\t\tnow,\n\t\t).entry!;\n\t}\n\n\t/** Profiles for the current host (default) or an explicit host id. */\n\tgetForHost(hostId?: string): StoredModelAdaptation[] {\n\t\treturn Object.values(this.storage.getHost(hostId) ?? {}).map((entry) => ({\n\t\t\t...entry,\n\t\t\tprofile: normalizeProfile(entry.profile),\n\t\t}));\n\t}\n\n\t/** Every stored profile across all hosts (for cross-machine comparisons). */\n\tgetAll(): StoredModelAdaptation[] {\n\t\treturn this.storage\n\t\t\t.getAllHosts()\n\t\t\t.flatMap((models) =>\n\t\t\t\tObject.values(models).map((entry) => ({ ...entry, profile: normalizeProfile(entry.profile) })),\n\t\t\t);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context-sizing.d.ts","sourceRoot":"","sources":["../../../src/core/models/context-sizing.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,wBAAwB;IACxC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC9C,IAAI,EAAE,wBAAwB,CAAC;IAC/B,KAAK,EAAE,sBAAsB,CAAC;IAC9B,OAAO,CAAC,EAAE,wBAAwB,CAAC;IACnC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B,GAAG,qBAAqB,GAAG,SAAS,CAoBpC;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE3F;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG5E","sourcesContent":["const CONTEXT_RUNGS = [4_096, 8_192, 16_384, 32_768] as const;\nconst DEFAULT_HEADROOM_FRACTION = 0.8;\nconst F16_BYTES = 2;\nconst Q8_BYTES = 1;\n\nexport interface ContextSizingModelInfo {\n\tmodelInfo: Record<string, unknown>;\n\tweightsBytes: number;\n}\n\nexport interface ContextSizingHostProfile {\n\ttotalMemBytes: number;\n\theadroomFraction?: number;\n}\n\nexport interface ContextSizingRuntimeCaps {\n\tsupportsKvQuantization?: boolean;\n}\n\nexport interface ContextSizingDecision {\n\tnumCtx: number;\n\tkvCacheType?: \"q8_0\";\n\tkvBytesPerToken: number;\n\tbudgetBytes: number;\n\testimatedBytes: number;\n}\n\nexport function deriveLocalContextSizing(args: {\n\thost: ContextSizingHostProfile;\n\tmodel: ContextSizingModelInfo;\n\truntime?: ContextSizingRuntimeCaps;\n\trungs?: readonly number[];\n}): ContextSizingDecision | undefined {\n\tconst kvShape = deriveKvShape(args.model.modelInfo);\n\tif (!kvShape) return undefined;\n\tconst headroomFraction = args.host.headroomFraction ?? DEFAULT_HEADROOM_FRACTION;\n\tconst budgetBytes = Math.floor(args.host.totalMemBytes * headroomFraction);\n\tconst availableKvBytes = budgetBytes - args.model.weightsBytes;\n\tif (availableKvBytes <= 0) return undefined;\n\tconst rungs = args.rungs ?? CONTEXT_RUNGS;\n\tconst f16Decision = chooseContextRung({ availableKvBytes, bytesPerElement: F16_BYTES, budgetBytes, kvShape, rungs });\n\tif (!args.runtime?.supportsKvQuantization) return f16Decision;\n\tconst q8Decision = chooseContextRung({\n\t\tavailableKvBytes,\n\t\tbytesPerElement: Q8_BYTES,\n\t\tbudgetBytes,\n\t\tkvCacheType: \"q8_0\",\n\t\tkvShape,\n\t\trungs,\n\t});\n\tif (q8Decision && (!f16Decision || q8Decision.numCtx > f16Decision.numCtx)) return q8Decision;\n\treturn f16Decision;\n}\n\nexport function renderOllamaContextModelfile(args: { from: string; numCtx: number }): string {\n\treturn `FROM ${args.from}\\nPARAMETER num_ctx ${args.numCtx}\\n`;\n}\n\nexport function sizedLocalModelRef(sourceRef: string, numCtx: number): string {\n\tconst safeSource = sourceRef.replace(/[^a-zA-Z0-9_.-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"local-model\";\n\treturn `pi-${safeSource}:ctx${numCtx}`;\n}\n\nfunction chooseContextRung(args: {\n\tavailableKvBytes: number;\n\tbytesPerElement: number;\n\tbudgetBytes: number;\n\tkvCacheType?: \"q8_0\";\n\tkvShape: { elementsPerToken: number };\n\trungs: readonly number[];\n}): ContextSizingDecision | undefined {\n\tconst kvBytesPerToken = args.kvShape.elementsPerToken * args.bytesPerElement;\n\tfor (const numCtx of [...args.rungs].sort((a, b) => b - a)) {\n\t\tconst estimatedBytes = kvBytesPerToken * numCtx;\n\t\tif (estimatedBytes <= args.availableKvBytes) {\n\t\t\treturn {\n\t\t\t\tnumCtx,\n\t\t\t\tkvCacheType: args.kvCacheType,\n\t\t\t\tkvBytesPerToken,\n\t\t\t\tbudgetBytes: args.budgetBytes,\n\t\t\t\testimatedBytes,\n\t\t\t};\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction deriveKvShape(modelInfo: Record<string, unknown>): { elementsPerToken: number } | undefined {\n\tconst layers = modelInfoNumber(modelInfo, \"block_count\");\n\tif (!layers) return undefined;\n\tconst headCountKv = modelInfoNumber(modelInfo, \"attention.head_count_kv\");\n\tconst keyLength = modelInfoNumber(modelInfo, \"attention.key_length\");\n\tconst valueLength = modelInfoNumber(modelInfo, \"attention.value_length\");\n\tif (headCountKv && keyLength && valueLength) {\n\t\treturn { elementsPerToken: layers * headCountKv * (keyLength + valueLength) };\n\t}\n\tconst embeddingLength = modelInfoNumber(modelInfo, \"embedding_length\");\n\treturn embeddingLength ? { elementsPerToken: layers * embeddingLength * 2 } : undefined;\n}\n\nfunction modelInfoNumber(record: Record<string, unknown>, suffix: string): number | undefined {\n\tconst architecture = typeof record[\"general.architecture\"] === \"string\" ? record[\"general.architecture\"].trim() : \"\";\n\tif (architecture) return positiveNumber(record[`${architecture}.${suffix}`]);\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tif (key.endsWith(`.${suffix}`)) {\n\t\t\tconst matched = positiveNumber(value);\n\t\t\tif (matched) return matched;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction positiveNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value > 0 ? value : undefined;\n}\n"]}
1
+ {"version":3,"file":"context-sizing.d.ts","sourceRoot":"","sources":["../../../src/core/models/context-sizing.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,wBAAwB;IACxC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC9C,IAAI,EAAE,wBAAwB,CAAC;IAC/B,KAAK,EAAE,sBAAsB,CAAC;IAC9B,OAAO,C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,CAAC,CAAC,CAAC;IAC7E,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,MAAM,EAAE,CAAC,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YACtC,IAAI,OAAO;gBAAE,OAAO,OAAO,CAAC;QAC7B,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAAA,CACjB;AAED,SAAS,cAAc,CAAC,KAAc,EAAsB;IAC3D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CAC5F","sourcesContent":["const CONTEXT_RUNGS = [4_096, 8_192, 16_384, 32_768] as const;\nconst DEFAULT_HEADROOM_FRACTION = 0.8;\nconst F16_BYTES = 2;\nconst Q8_BYTES = 1;\n\nexport interface ContextSizingModelInfo {\n\tmodelInfo: Record<string, unknown>;\n\tweightsBytes: number;\n}\n\nexport interface ContextSizingHostProfile {\n\ttotalMemBytes: number;\n\theadroomFraction?: number;\n}\n\nexport interface ContextSizingRuntimeCaps {\n\tsupportsKvQuantization?: boolean;\n}\n\nexport interface ContextSizingDecision {\n\tnumCtx: number;\n\tkvCacheType?: \"q8_0\";\n\tkvBytesPerToken: number;\n\tbudgetBytes: number;\n\testimatedBytes: number;\n}\n\nexport function deriveLocalContextSizing(args: {\n\thost: ContextSizingHostProfile;\n\tmodel: ContextSizingModelInfo;\n\truntime?: ContextSizingRuntimeCaps;\n\trungs?: readonly number[];\n}): ContextSizingDecision | undefined {\n\tconst kvShape = deriveKvShape(args.model.modelInfo);\n\tif (!kvShape) return undefined;\n\tconst headroomFraction = args.host.headroomFraction ?? DEFAULT_HEADROOM_FRACTION;\n\tconst budgetBytes = Math.floor(args.host.totalMemBytes * headroomFraction);\n\tconst availableKvBytes = budgetBytes - args.model.weightsBytes;\n\tif (availableKvBytes <= 0) return undefined;\n\tconst rungs = args.rungs ?? CONTEXT_RUNGS;\n\tconst f16Decision = chooseContextRung({ availableKvBytes, bytesPerElement: F16_BYTES, budgetBytes, kvShape, rungs });\n\tif (!args.runtime?.supportsKvQuantization) return f16Decision;\n\tconst q8Decision = chooseContextRung({\n\t\tavailableKvBytes,\n\t\tbytesPerElement: Q8_BYTES,\n\t\tbudgetBytes,\n\t\tkvCacheType: \"q8_0\",\n\t\tkvShape,\n\t\trungs,\n\t});\n\tif (q8Decision && (!f16Decision || q8Decision.numCtx > f16Decision.numCtx)) return q8Decision;\n\treturn f16Decision;\n}\n\nexport function renderOllamaContextModelfile(args: { from: string; numCtx: number }): string {\n\treturn `FROM ${args.from}\\nPARAMETER num_ctx ${args.numCtx}\\n`;\n}\n\nexport function sizedLocalModelRef(sourceRef: string, numCtx: number): string {\n\tconst safeSource = sourceRef.replace(/[^a-zA-Z0-9_.-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"local-model\";\n\treturn `pi-${safeSource}:ctx${numCtx}`;\n}\n\nfunction chooseContextRung(args: {\n\tavailableKvBytes: number;\n\tbytesPerElement: number;\n\tbudgetBytes: number;\n\tkvCacheType?: \"q8_0\";\n\tkvShape: { elementsPerToken: number };\n\trungs: readonly number[];\n}): ContextSizingDecision | undefined {\n\tconst kvBytesPerToken = args.kvShape.elementsPerToken * args.bytesPerElement;\n\tfor (const numCtx of [...args.rungs].sort((a, b) => b - a)) {\n\t\tconst estimatedBytes = kvBytesPerToken * numCtx;\n\t\tif (estimatedBytes <= args.availableKvBytes) {\n\t\t\treturn {\n\t\t\t\tnumCtx,\n\t\t\t\tkvCacheType: args.kvCacheType,\n\t\t\t\tkvBytesPerToken,\n\t\t\t\tbudgetBytes: args.budgetBytes,\n\t\t\t\testimatedBytes,\n\t\t\t};\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction deriveKvShape(modelInfo: Record<string, unknown>): { elementsPerToken: number } | undefined {\n\tconst layers = modelInfoNumber(modelInfo, \"block_count\");\n\tif (!layers) return undefined;\n\tconst headCountKv = modelInfoNumber(modelInfo, \"attention.head_count_kv\");\n\tconst keyLength = modelInfoNumber(modelInfo, \"attention.key_length\");\n\tconst valueLength = modelInfoNumber(modelInfo, \"attention.value_length\");\n\tif (headCountKv && keyLength && valueLength) {\n\t\treturn { elementsPerToken: layers * headCountKv * (keyLength + valueLength) };\n\t}\n\tconst embeddingLength = modelInfoNumber(modelInfo, \"embedding_length\");\n\treturn embeddingLength ? { elementsPerToken: layers * embeddingLength * 2 } : undefined;\n}\n\nfunction modelInfoNumber(record: Record<string, unknown>, suffix: string): number | undefined {\n\tconst architecture = typeof record[\"general.architecture\"] === \"string\" ? record[\"general.architecture\"].trim() : \"\";\n\tif (architecture) return positiveNumber(record[`${architecture}.${suffix}`]);\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tif (key.endsWith(`.${suffix}`)) {\n\t\t\tconst matched = positiveNumber(value);\n\t\t\tif (matched) return matched;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction positiveNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value > 0 ? value : undefined;\n}\n"]}
1
+ {"version":3,"file":"context-sizing.js","sourceRoot":"","sources":["../../../src/core/models/context-sizing.ts"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAC9D,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,QAAQ,GAAG,CAAC,CAAC;AAwBnB,MAAM,UAAU,wBAAwB,CAAC,IAKxC;IACA,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACpD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AkB,CAAC,CAAC;IACvE,OAAO,eAAe,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,MAAM,GAAG,eAAe,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACzF,CAAC;AAED,SAAS,eAAe,CAAC,MAA+B,EAAE,MAAc;IACvE,MAAM,YAAY,GAAG,OAAO,MAAM,CAAC,sBAAsB,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrH,IAAI,YAAY;QAAE,OAAO,cAAc,CAAC,MAAM,CAAC,GAAG,YAAY,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC;IAC7E,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,MAAM,EAAE,CAAC,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YACtC,IAAI,OAAO;gBAAE,OAAO,OAAO,CAAC;QAC7B,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7F,CAAC","sourcesContent":["const CONTEXT_RUNGS = [4_096, 8_192, 16_384, 32_768] as const;\nconst DEFAULT_HEADROOM_FRACTION = 0.8;\nconst F16_BYTES = 2;\nconst Q8_BYTES = 1;\n\nexport interface ContextSizingModelInfo {\n\tmodelInfo: Record<string, unknown>;\n\tweightsBytes: number;\n}\n\nexport interface ContextSizingHostProfile {\n\ttotalMemBytes: number;\n\theadroomFraction?: number;\n}\n\nexport interface ContextSizingRuntimeCaps {\n\tsupportsKvQuantization?: boolean;\n}\n\nexport interface ContextSizingDecision {\n\tnumCtx: number;\n\tkvCacheType?: \"q8_0\";\n\tkvBytesPerToken: number;\n\tbudgetBytes: number;\n\testimatedBytes: number;\n}\n\nexport function deriveLocalContextSizing(args: {\n\thost: ContextSizingHostProfile;\n\tmodel: ContextSizingModelInfo;\n\truntime?: ContextSizingRuntimeCaps;\n\trungs?: readonly number[];\n}): ContextSizingDecision | undefined {\n\tconst kvShape = deriveKvShape(args.model.modelInfo);\n\tif (!kvShape) return undefined;\n\tconst headroomFraction = args.host.headroomFraction ?? DEFAULT_HEADROOM_FRACTION;\n\tconst budgetBytes = Math.floor(args.host.totalMemBytes * headroomFraction);\n\tconst availableKvBytes = budgetBytes - args.model.weightsBytes;\n\tif (availableKvBytes <= 0) return undefined;\n\tconst rungs = args.rungs ?? CONTEXT_RUNGS;\n\tconst f16Decision = chooseContextRung({ availableKvBytes, bytesPerElement: F16_BYTES, budgetBytes, kvShape, rungs });\n\tif (!args.runtime?.supportsKvQuantization) return f16Decision;\n\tconst q8Decision = chooseContextRung({\n\t\tavailableKvBytes,\n\t\tbytesPerElement: Q8_BYTES,\n\t\tbudgetBytes,\n\t\tkvCacheType: \"q8_0\",\n\t\tkvShape,\n\t\trungs,\n\t});\n\tif (q8Decision && (!f16Decision || q8Decision.numCtx > f16Decision.numCtx)) return q8Decision;\n\treturn f16Decision;\n}\n\nexport function renderOllamaContextModelfile(args: { from: string; numCtx: number }): string {\n\treturn `FROM ${args.from}\\nPARAMETER num_ctx ${args.numCtx}\\n`;\n}\n\nexport function sizedLocalModelRef(sourceRef: string, numCtx: number): string {\n\tconst safeSource = sourceRef.replace(/[^a-zA-Z0-9_.-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"local-model\";\n\treturn `pi-${safeSource}:ctx${numCtx}`;\n}\n\nfunction chooseContextRung(args: {\n\tavailableKvBytes: number;\n\tbytesPerElement: number;\n\tbudgetBytes: number;\n\tkvCacheType?: \"q8_0\";\n\tkvShape: { elementsPerToken: number };\n\trungs: readonly number[];\n}): ContextSizingDecision | undefined {\n\tconst kvBytesPerToken = args.kvShape.elementsPerToken * args.bytesPerElement;\n\tfor (const numCtx of [...args.rungs].sort((a, b) => b - a)) {\n\t\tconst estimatedBytes = kvBytesPerToken * numCtx;\n\t\tif (estimatedBytes <= args.availableKvBytes) {\n\t\t\treturn {\n\t\t\t\tnumCtx,\n\t\t\t\tkvCacheType: args.kvCacheType,\n\t\t\t\tkvBytesPerToken,\n\t\t\t\tbudgetBytes: args.budgetBytes,\n\t\t\t\testimatedBytes,\n\t\t\t};\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction deriveKvShape(modelInfo: Record<string, unknown>): { elementsPerToken: number } | undefined {\n\tconst layers = modelInfoNumber(modelInfo, \"block_count\");\n\tif (!layers) return undefined;\n\tconst headCountKv = modelInfoNumber(modelInfo, \"attention.head_count_kv\");\n\tconst keyLength = modelInfoNumber(modelInfo, \"attention.key_length\");\n\tconst valueLength = modelInfoNumber(modelInfo, \"attention.value_length\");\n\tif (headCountKv && keyLength && valueLength) {\n\t\treturn { elementsPerToken: layers * headCountKv * (keyLength + valueLength) };\n\t}\n\tconst embeddingLength = modelInfoNumber(modelInfo, \"embedding_length\");\n\treturn embeddingLength ? { elementsPerToken: layers * embeddingLength * 2 } : undefined;\n}\n\nfunction modelInfoNumber(record: Record<string, unknown>, suffix: string): number | undefined {\n\tconst architecture = typeof record[\"general.architecture\"] === \"string\" ? record[\"general.architecture\"].trim() : \"\";\n\tif (architecture) return positiveNumber(record[`${architecture}.${suffix}`]);\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tif (key.endsWith(`.${suffix}`)) {\n\t\t\tconst matched = positiveNumber(value);\n\t\t\tif (matched) return matched;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction positiveNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value > 0 ? value : undefined;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"default-model-suggestions.d.ts","sourceRoot":"","sources":["../../../src/core/models/default-model-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6DAA6D,CAAC;AAE/F;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,eAAe;IAC/B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,oGAAoG;IACpG,WAAW,EAAE,OAAO,CAAC;IACrB,mGAAmG;IACnG,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,qFAAqF;IACrF,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,yBAAyB,EAAE,SAAS,eAAe,EA2G/D,CAAC;AAEF,gFAAgF;AAChF,wBAAgB,sBAAsB,CAAC,WAAW,GAAE,SAAS,eAAe,EAA8B,GAAG,MAAM,EAAE,CAcpH","sourcesContent":["import type { FitnessRole } from \"../../modes/interactive/components/fitness-role-selector.ts\";\n\n/**\n * Curated local-model suggestions: a starting roster validated during pi-adaptative's own\n * small-model research so a user does not have to know WHICH model fits WHICH role. Each entry is\n * an install ref (accepted by /models add) plus the role it was validated for and whether it can use\n * tools. Native tool-calling remains preferred when it works; text-protocol models are listed only\n * when their runtime is pi-managed and the fitness/probe path can calibrate that fallback.\n *\n * Honesty: these are SUGGESTIONS, not guarantees. Fitness is a property of the model AND the host\n * hardware, so no per-model score is baked in here — `/models add` auto-probes on the actual\n * machine, and the roster only encodes what role each model was SHAPED for. `assignRole` is the\n * /fitness role the suggestion maps to (undefined = no single-setting slot yet; use it as a\n * research/worker lane model).\n */\n\nexport interface ModelSuggestion {\n\t/** Display name in the suggestions list. */\n\tname: string;\n\t/** Ref accepted by /models add and the source normalizer. */\n\tpullRef: string;\n\t/** Role this model was validated/shaped for. */\n\trole: string;\n\t/** True if the model can use tools after host-local probing/calibration (required for executor). */\n\ttoolCalling: boolean;\n\t/** The /fitness assignment target this suggestion maps to, when there is a single-setting slot. */\n\tassignRole?: FitnessRole;\n\t/** One-line rationale from the validation work; never a fabricated numeric score. */\n\trationale: string;\n\t/** Optional caveat (quant selection, RAM needs). */\n\tnote?: string;\n}\n\nexport const DEFAULT_MODEL_SUGGESTIONS: readonly ModelSuggestion[] = [\n\t{\n\t\tname: \"qwen3:1.7b\",\n\t\tpullRef: \"qwen3:1.7b\",\n\t\trole: \"Toolkit executor / reflex muscle\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Validated as the executor: reliable native tool-calling and low latency, so direct toolkit commands run without retries.\",\n\t},\n\t{\n\t\tname: \"qwen3:0.6b\",\n\t\tpullRef: \"qwen3:0.6b\",\n\t\trole: \"Minimal executor (fastest)\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Fastest local option; on harder requests it can narrate without executing, so prefer it only when speed dominates and requests are simple.\",\n\t},\n\t{\n\t\tname: \"MiniCPM5-1B (full-base)\",\n\t\tpullRef: \"hf.co/openbmb/MiniCPM5-1B\",\n\t\trole: \"Full-base Transformers executor / tiny local muscle\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Full-base Hugging Face MiniCPM5-1B target: pi installs an isolated Transformers runtime and probes native tool-calling first, then calibrates the text protocol only if native tool calls do not work.\",\n\t\tnote: \"Not GGUF/quantized: weights and Python deps land under pi-owned runtime/cache directories, separate from Ollama and system Python.\",\n\t},\n\t{\n\t\tname: \"FastContext-1.0-4B\",\n\t\tpullRef: \"hf.co/KikoCis/FastContext-1.0-4B-longctx-imatrix-GGUF:fastcontext4b.Q4_K_M.imx.gguf\",\n\t\trole: \"Repository scout (context_scout)\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"scout\",\n\t\trationale:\n\t\t\t\"The model the context_scout lane is built around (Plan 9): 4B Qwen3, 256K context, trained for read-only repo exploration returning file:line citations. /fitness must pass the tool-calls + research lanes before assignment.\",\n\t\tnote: \"Q4 ≈ 2.5 GB; ~5-6 GB peak with 32-64K KV. Qwen3 template caveat: if tool calls fail the probe, use the Modelfile recipe in docs/scout.md.\",\n\t},\n\t{\n\t\tname: \"Ornith-1.0-9B\",\n\t\tpullRef: \"hf.co/deepreinforce-ai/Ornith-1.0-9B-GGUF:Q4_K_M\",\n\t\trole: \"Agentic-coding worker / router cheap tier\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"router-cheap\",\n\t\trationale:\n\t\t\t\"External candidate (not from pi's own validation research): MIT, Qwen 3.5 base, RL-trained for agentic coding with native tool-calling — the strongest local worker SHAPE in the roster. /fitness on your hardware is the validator.\",\n\t\tnote: \"Q4_K_M ≈ 5.6 GB weights, ~7-8 GB peak with KV — on a 10 GB box run it as the ONLY local model. Qwen 3.5 arch: confirm pi's pinned Ollama supports it and probe tool-calls with /fitness before assigning (template derives from the GGUF). Larger boxes: consider router-medium after a passed worker lane.\",\n\t},\n\t{\n\t\tname: \"Bonsai-4B (GGUF Q1_0)\",\n\t\tpullRef: \"hf.co/prism-ml/Bonsai-4B-gguf:Q1_0\",\n\t\trole: \"Context curator / reflex brain / lighter lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"Lighter Bonsai lane model for context curation and structured local analysis; the exact Q1_0 artifact keeps /models suggest one-step.\",\n\t\tnote: \"Recommended when Bonsai-8B is too heavy. Pi pulls this exact GGUF through managed Ollama, probes /fitness on the host, then offers the curator role.\",\n\t},\n\t{\n\t\tname: \"Bonsai-27B (1-bit + vision)\",\n\t\tpullRef: \"hf.co/prism-ml/Bonsai-27B-gguf:Q1_0\",\n\t\trole: \"Context curator / reflex brain / vision-capable lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"External 1-bit 27B, binary weights, 262K-class context, vision via mmproj; served by pi through prism-ml's llama.cpp build (stock llama.cpp/Ollama cannot serve these weights). /fitness on your hardware is the validator — never pre-claim tool-calling.\",\n\t\tnote: \"~3.8 GB weights + 629 MB vision projector + a one-time llama-server runtime download; CPU-served on GPU-less hosts. Pi installs the pinned prism llama.cpp runtime, downloads both files, starts llama-server, and registers the model in one step. Provider-recommended sampling is temp 0.7 / top-p 0.95 / top-k 20; models.json has no per-model default-sampling field yet, so pi cannot wire this — set it per-request/session if your workflow needs it.\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-1.7B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-1.7B-gguf\",\n\t\trole: \"Search scout (heavy-lifter)\",\n\t\ttoolCalling: false,\n\t\trationale:\n\t\t\t\"Ternary weights, very fast; strong at structured search plans. No tool-calling template — use it as a research/worker lane model, never an executor.\",\n\t\tnote: \"Pick a GGUF quant the runtime accepts (e.g. :Q8_0). The ternary Q2_0 build needs prism-ml's patched llama.cpp.\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-4B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-4B-gguf\",\n\t\trole: \"Context curator / reflex brain / lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"Validated as the 'brain': strict-JSON interpretation and faithful digests. Drives context curation and the toolkit reflex interpreter. Not a tool-caller.\",\n\t\tnote: \"Pick a GGUF quant the runtime accepts (e.g. :Q8_0).\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-8B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-8B-gguf\",\n\t\trole: \"Routing judge (larger machines)\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"judge\",\n\t\trationale:\n\t\t\t\"A judge candidate for machines with more headroom — too slow on ~16GB-class hardware in this research, kept for a bigger box.\",\n\t\tnote: \"Heavy: confirm tok/s with /fitness before committing. Ternary quant may need prism-ml's patched llama.cpp.\",\n\t},\n\t{\n\t\tname: \"needle (function-call tester, 26M)\",\n\t\tpullRef: \"hf.co/Cactus-Compute/needle\",\n\t\trole: \"Standalone function-call test bench (not a chat/lane model)\",\n\t\ttoolCalling: false,\n\t\trationale:\n\t\t\t\"NOT a pi chat model, executor, or lane model — needle is a 26M-parameter single-shot function-call SPECIALIST invoked one query at a time through its own `needle run` CLI, useful only as a standalone bench for probing tool-call behavior in isolation. No OpenAI-compatible endpoint, no chat lanes, no models.json registration, and no /fitness probe: use /models needle <query> [tools-json] to test it directly instead.\",\n\t\tnote: \"Upstream weights (needle.pkl) are pickle-only — arbitrary code execution on load by construction, not something pi's pinned-sha256 verification makes safe in the abstract, only tamper-evident.\",\n\t},\n];\n\n/** Bounded plain-text roster for `/models suggest` and the empty-store hint. */\nexport function formatModelSuggestions(suggestions: readonly ModelSuggestion[] = DEFAULT_MODEL_SUGGESTIONS): string[] {\n\tconst lines = [\n\t\t\"Suggested local models (validated roles from pi's own small-model research; probe on YOUR hardware with /fitness):\",\n\t];\n\tfor (const suggestion of suggestions) {\n\t\tlines.push(\n\t\t\t` - ${suggestion.name} → ${suggestion.role}${suggestion.toolCalling ? \"\" : \" [no tool-calling]\"}`,\n\t\t\t` /models add ${suggestion.pullRef}`,\n\t\t\t` ${suggestion.rationale}`,\n\t\t);\n\t\tif (suggestion.note) lines.push(` note: ${suggestion.note}`);\n\t}\n\tlines.push(\"Add one with /models add <ref> — pi pulls it, probes it, and offers a role in one step.\");\n\treturn lines;\n}\n"]}
1
+ {"version":3,"file":"default-model-suggestions.d.ts","sourceRoot":"","sources":["../../../src/core/models/default-model-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6DAA6D,CAAC;AAE/F;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,eAAe;IAC/B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,oGAAoG;IACpG,WAAW,EAAE,OAAO,CAAC;IACrB,mGAAmG;IACnG,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,qFAAqF;IACrF,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,yBAAyB,EAAE,SAAS,eAAe,EA2G/D,CAAC;AAEF,gFAAgF;AAChF,wBAAgB,sBAAsB,CAAC,WAAW,GAAE,SAAS,eAAe,EAA8B,GAAG,MAAM,EAAE,CAcpH"}
@@ -1 +1 @@
1
- {"version":3,"file":"default-model-suggestions.js","sourceRoot":"","sources":["../../../src/core/models/default-model-suggestions.ts"],"names":[],"mappings":"AAiCA,MAAM,CAAC,MAAM,yBAAyB,GAA+B;IACpE;QACC,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,YAAY;QACrB,IAAI,EAAE,kCAAkC;QACxC,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,UAAU;QACtB,SAAS,EACR,0HAA0H;KAC3H;IACD;QACC,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,YAAY;QACrB,IAAI,EAAE,4BAA4B;QAClC,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,UAAU;QACtB,SAAS,EACR,4IAA4I;KAC7I;IACD;QACC,IAAI,EAAE,yBAAyB;QAC/B,OAAO,EAAE,2BAA2B;QACpC,IAAI,EAAE,qDAAqD;QAC3D,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,UAAU;QACtB,SAAS,EACR,wMAAwM;QACzM,IAAI,EAAE,oIAAoI;KAC1I;IACD;QACC,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,qFAAqF;QAC9F,IAAI,EAAE,kCAAkC;QACxC,WAAW,EAAE,IAAI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AAoC;QAC1C,OAAO,EAAE,6BAA6B;QACtC,IAAI,EAAE,6DAA6D;QACnE,WAAW,EAAE,KAAK;QAClB,SAAS,EACR,qaAAma;QACpa,IAAI,EAAE,oMAAkM;KACxM;CACD,CAAC;AAEF,gFAAgF;AAChF,MAAM,UAAU,sBAAsB,CAAC,WAAW,GAA+B,yBAAyB,EAAY;IACrH,MAAM,KAAK,GAAG;QACb,oHAAoH;KACpH,CAAC;IACF,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACtC,KAAK,CAAC,IAAI,CACT,OAAO,UAAU,CAAC,IAAI,QAAM,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,oBAAoB,EAAE,EAClG,qBAAqB,UAAU,CAAC,OAAO,EAAE,EACzC,SAAS,UAAU,CAAC,SAAS,EAAE,CAC/B,CAAC;QACF,IAAI,UAAU,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,eAAe,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,2FAAyF,CAAC,CAAC;IACtG,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import type { FitnessRole } from \"../../modes/interactive/components/fitness-role-selector.ts\";\n\n/**\n * Curated local-model suggestions: a starting roster validated during pi-adaptative's own\n * small-model research so a user does not have to know WHICH model fits WHICH role. Each entry is\n * an install ref (accepted by /models add) plus the role it was validated for and whether it can use\n * tools. Native tool-calling remains preferred when it works; text-protocol models are listed only\n * when their runtime is pi-managed and the fitness/probe path can calibrate that fallback.\n *\n * Honesty: these are SUGGESTIONS, not guarantees. Fitness is a property of the model AND the host\n * hardware, so no per-model score is baked in here — `/models add` auto-probes on the actual\n * machine, and the roster only encodes what role each model was SHAPED for. `assignRole` is the\n * /fitness role the suggestion maps to (undefined = no single-setting slot yet; use it as a\n * research/worker lane model).\n */\n\nexport interface ModelSuggestion {\n\t/** Display name in the suggestions list. */\n\tname: string;\n\t/** Ref accepted by /models add and the source normalizer. */\n\tpullRef: string;\n\t/** Role this model was validated/shaped for. */\n\trole: string;\n\t/** True if the model can use tools after host-local probing/calibration (required for executor). */\n\ttoolCalling: boolean;\n\t/** The /fitness assignment target this suggestion maps to, when there is a single-setting slot. */\n\tassignRole?: FitnessRole;\n\t/** One-line rationale from the validation work; never a fabricated numeric score. */\n\trationale: string;\n\t/** Optional caveat (quant selection, RAM needs). */\n\tnote?: string;\n}\n\nexport const DEFAULT_MODEL_SUGGESTIONS: readonly ModelSuggestion[] = [\n\t{\n\t\tname: \"qwen3:1.7b\",\n\t\tpullRef: \"qwen3:1.7b\",\n\t\trole: \"Toolkit executor / reflex muscle\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Validated as the executor: reliable native tool-calling and low latency, so direct toolkit commands run without retries.\",\n\t},\n\t{\n\t\tname: \"qwen3:0.6b\",\n\t\tpullRef: \"qwen3:0.6b\",\n\t\trole: \"Minimal executor (fastest)\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Fastest local option; on harder requests it can narrate without executing, so prefer it only when speed dominates and requests are simple.\",\n\t},\n\t{\n\t\tname: \"MiniCPM5-1B (full-base)\",\n\t\tpullRef: \"hf.co/openbmb/MiniCPM5-1B\",\n\t\trole: \"Full-base Transformers executor / tiny local muscle\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Full-base Hugging Face MiniCPM5-1B target: pi installs an isolated Transformers runtime and probes native tool-calling first, then calibrates the text protocol only if native tool calls do not work.\",\n\t\tnote: \"Not GGUF/quantized: weights and Python deps land under pi-owned runtime/cache directories, separate from Ollama and system Python.\",\n\t},\n\t{\n\t\tname: \"FastContext-1.0-4B\",\n\t\tpullRef: \"hf.co/KikoCis/FastContext-1.0-4B-longctx-imatrix-GGUF:fastcontext4b.Q4_K_M.imx.gguf\",\n\t\trole: \"Repository scout (context_scout)\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"scout\",\n\t\trationale:\n\t\t\t\"The model the context_scout lane is built around (Plan 9): 4B Qwen3, 256K context, trained for read-only repo exploration returning file:line citations. /fitness must pass the tool-calls + research lanes before assignment.\",\n\t\tnote: \"Q4 ≈ 2.5 GB; ~5-6 GB peak with 32-64K KV. Qwen3 template caveat: if tool calls fail the probe, use the Modelfile recipe in docs/scout.md.\",\n\t},\n\t{\n\t\tname: \"Ornith-1.0-9B\",\n\t\tpullRef: \"hf.co/deepreinforce-ai/Ornith-1.0-9B-GGUF:Q4_K_M\",\n\t\trole: \"Agentic-coding worker / router cheap tier\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"router-cheap\",\n\t\trationale:\n\t\t\t\"External candidate (not from pi's own validation research): MIT, Qwen 3.5 base, RL-trained for agentic coding with native tool-calling — the strongest local worker SHAPE in the roster. /fitness on your hardware is the validator.\",\n\t\tnote: \"Q4_K_M ≈ 5.6 GB weights, ~7-8 GB peak with KV — on a 10 GB box run it as the ONLY local model. Qwen 3.5 arch: confirm pi's pinned Ollama supports it and probe tool-calls with /fitness before assigning (template derives from the GGUF). Larger boxes: consider router-medium after a passed worker lane.\",\n\t},\n\t{\n\t\tname: \"Bonsai-4B (GGUF Q1_0)\",\n\t\tpullRef: \"hf.co/prism-ml/Bonsai-4B-gguf:Q1_0\",\n\t\trole: \"Context curator / reflex brain / lighter lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"Lighter Bonsai lane model for context curation and structured local analysis; the exact Q1_0 artifact keeps /models suggest one-step.\",\n\t\tnote: \"Recommended when Bonsai-8B is too heavy. Pi pulls this exact GGUF through managed Ollama, probes /fitness on the host, then offers the curator role.\",\n\t},\n\t{\n\t\tname: \"Bonsai-27B (1-bit + vision)\",\n\t\tpullRef: \"hf.co/prism-ml/Bonsai-27B-gguf:Q1_0\",\n\t\trole: \"Context curator / reflex brain / vision-capable lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"External 1-bit 27B, binary weights, 262K-class context, vision via mmproj; served by pi through prism-ml's llama.cpp build (stock llama.cpp/Ollama cannot serve these weights). /fitness on your hardware is the validator — never pre-claim tool-calling.\",\n\t\tnote: \"~3.8 GB weights + 629 MB vision projector + a one-time llama-server runtime download; CPU-served on GPU-less hosts. Pi installs the pinned prism llama.cpp runtime, downloads both files, starts llama-server, and registers the model in one step. Provider-recommended sampling is temp 0.7 / top-p 0.95 / top-k 20; models.json has no per-model default-sampling field yet, so pi cannot wire this — set it per-request/session if your workflow needs it.\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-1.7B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-1.7B-gguf\",\n\t\trole: \"Search scout (heavy-lifter)\",\n\t\ttoolCalling: false,\n\t\trationale:\n\t\t\t\"Ternary weights, very fast; strong at structured search plans. No tool-calling template — use it as a research/worker lane model, never an executor.\",\n\t\tnote: \"Pick a GGUF quant the runtime accepts (e.g. :Q8_0). The ternary Q2_0 build needs prism-ml's patched llama.cpp.\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-4B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-4B-gguf\",\n\t\trole: \"Context curator / reflex brain / lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"Validated as the 'brain': strict-JSON interpretation and faithful digests. Drives context curation and the toolkit reflex interpreter. Not a tool-caller.\",\n\t\tnote: \"Pick a GGUF quant the runtime accepts (e.g. :Q8_0).\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-8B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-8B-gguf\",\n\t\trole: \"Routing judge (larger machines)\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"judge\",\n\t\trationale:\n\t\t\t\"A judge candidate for machines with more headroom — too slow on ~16GB-class hardware in this research, kept for a bigger box.\",\n\t\tnote: \"Heavy: confirm tok/s with /fitness before committing. Ternary quant may need prism-ml's patched llama.cpp.\",\n\t},\n\t{\n\t\tname: \"needle (function-call tester, 26M)\",\n\t\tpullRef: \"hf.co/Cactus-Compute/needle\",\n\t\trole: \"Standalone function-call test bench (not a chat/lane model)\",\n\t\ttoolCalling: false,\n\t\trationale:\n\t\t\t\"NOT a pi chat model, executor, or lane model — needle is a 26M-parameter single-shot function-call SPECIALIST invoked one query at a time through its own `needle run` CLI, useful only as a standalone bench for probing tool-call behavior in isolation. No OpenAI-compatible endpoint, no chat lanes, no models.json registration, and no /fitness probe: use /models needle <query> [tools-json] to test it directly instead.\",\n\t\tnote: \"Upstream weights (needle.pkl) are pickle-only — arbitrary code execution on load by construction, not something pi's pinned-sha256 verification makes safe in the abstract, only tamper-evident.\",\n\t},\n];\n\n/** Bounded plain-text roster for `/models suggest` and the empty-store hint. */\nexport function formatModelSuggestions(suggestions: readonly ModelSuggestion[] = DEFAULT_MODEL_SUGGESTIONS): string[] {\n\tconst lines = [\n\t\t\"Suggested local models (validated roles from pi's own small-model research; probe on YOUR hardware with /fitness):\",\n\t];\n\tfor (const suggestion of suggestions) {\n\t\tlines.push(\n\t\t\t` - ${suggestion.name} → ${suggestion.role}${suggestion.toolCalling ? \"\" : \" [no tool-calling]\"}`,\n\t\t\t` /models add ${suggestion.pullRef}`,\n\t\t\t` ${suggestion.rationale}`,\n\t\t);\n\t\tif (suggestion.note) lines.push(` note: ${suggestion.note}`);\n\t}\n\tlines.push(\"Add one with /models add <ref> — pi pulls it, probes it, and offers a role in one step.\");\n\treturn lines;\n}\n"]}
1
+ {"version":3,"file":"default-model-suggestions.js","sourceRoot":"","sources":["../../../src/core/models/default-model-suggestions.ts"],"names":[],"mappings":"AAiCA,MAAM,CAAC,MAAM,yBAAyB,GAA+B;IACpE;QACC,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,YA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IACnE,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,yFAAyF,CAAC,CAAC;IACtG,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import type { FitnessRole } from \"../../modes/interactive/components/fitness-role-selector.ts\";\n\n/**\n * Curated local-model suggestions: a starting roster validated during pi-adaptative's own\n * small-model research so a user does not have to know WHICH model fits WHICH role. Each entry is\n * an install ref (accepted by /models add) plus the role it was validated for and whether it can use\n * tools. Native tool-calling remains preferred when it works; text-protocol models are listed only\n * when their runtime is pi-managed and the fitness/probe path can calibrate that fallback.\n *\n * Honesty: these are SUGGESTIONS, not guarantees. Fitness is a property of the model AND the host\n * hardware, so no per-model score is baked in here — `/models add` auto-probes on the actual\n * machine, and the roster only encodes what role each model was SHAPED for. `assignRole` is the\n * /fitness role the suggestion maps to (undefined = no single-setting slot yet; use it as a\n * research/worker lane model).\n */\n\nexport interface ModelSuggestion {\n\t/** Display name in the suggestions list. */\n\tname: string;\n\t/** Ref accepted by /models add and the source normalizer. */\n\tpullRef: string;\n\t/** Role this model was validated/shaped for. */\n\trole: string;\n\t/** True if the model can use tools after host-local probing/calibration (required for executor). */\n\ttoolCalling: boolean;\n\t/** The /fitness assignment target this suggestion maps to, when there is a single-setting slot. */\n\tassignRole?: FitnessRole;\n\t/** One-line rationale from the validation work; never a fabricated numeric score. */\n\trationale: string;\n\t/** Optional caveat (quant selection, RAM needs). */\n\tnote?: string;\n}\n\nexport const DEFAULT_MODEL_SUGGESTIONS: readonly ModelSuggestion[] = [\n\t{\n\t\tname: \"qwen3:1.7b\",\n\t\tpullRef: \"qwen3:1.7b\",\n\t\trole: \"Toolkit executor / reflex muscle\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Validated as the executor: reliable native tool-calling and low latency, so direct toolkit commands run without retries.\",\n\t},\n\t{\n\t\tname: \"qwen3:0.6b\",\n\t\tpullRef: \"qwen3:0.6b\",\n\t\trole: \"Minimal executor (fastest)\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Fastest local option; on harder requests it can narrate without executing, so prefer it only when speed dominates and requests are simple.\",\n\t},\n\t{\n\t\tname: \"MiniCPM5-1B (full-base)\",\n\t\tpullRef: \"hf.co/openbmb/MiniCPM5-1B\",\n\t\trole: \"Full-base Transformers executor / tiny local muscle\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"executor\",\n\t\trationale:\n\t\t\t\"Full-base Hugging Face MiniCPM5-1B target: pi installs an isolated Transformers runtime and probes native tool-calling first, then calibrates the text protocol only if native tool calls do not work.\",\n\t\tnote: \"Not GGUF/quantized: weights and Python deps land under pi-owned runtime/cache directories, separate from Ollama and system Python.\",\n\t},\n\t{\n\t\tname: \"FastContext-1.0-4B\",\n\t\tpullRef: \"hf.co/KikoCis/FastContext-1.0-4B-longctx-imatrix-GGUF:fastcontext4b.Q4_K_M.imx.gguf\",\n\t\trole: \"Repository scout (context_scout)\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"scout\",\n\t\trationale:\n\t\t\t\"The model the context_scout lane is built around (Plan 9): 4B Qwen3, 256K context, trained for read-only repo exploration returning file:line citations. /fitness must pass the tool-calls + research lanes before assignment.\",\n\t\tnote: \"Q4 ≈ 2.5 GB; ~5-6 GB peak with 32-64K KV. Qwen3 template caveat: if tool calls fail the probe, use the Modelfile recipe in docs/scout.md.\",\n\t},\n\t{\n\t\tname: \"Ornith-1.0-9B\",\n\t\tpullRef: \"hf.co/deepreinforce-ai/Ornith-1.0-9B-GGUF:Q4_K_M\",\n\t\trole: \"Agentic-coding worker / router cheap tier\",\n\t\ttoolCalling: true,\n\t\tassignRole: \"router-cheap\",\n\t\trationale:\n\t\t\t\"External candidate (not from pi's own validation research): MIT, Qwen 3.5 base, RL-trained for agentic coding with native tool-calling — the strongest local worker SHAPE in the roster. /fitness on your hardware is the validator.\",\n\t\tnote: \"Q4_K_M ≈ 5.6 GB weights, ~7-8 GB peak with KV — on a 10 GB box run it as the ONLY local model. Qwen 3.5 arch: confirm pi's pinned Ollama supports it and probe tool-calls with /fitness before assigning (template derives from the GGUF). Larger boxes: consider router-medium after a passed worker lane.\",\n\t},\n\t{\n\t\tname: \"Bonsai-4B (GGUF Q1_0)\",\n\t\tpullRef: \"hf.co/prism-ml/Bonsai-4B-gguf:Q1_0\",\n\t\trole: \"Context curator / reflex brain / lighter lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"Lighter Bonsai lane model for context curation and structured local analysis; the exact Q1_0 artifact keeps /models suggest one-step.\",\n\t\tnote: \"Recommended when Bonsai-8B is too heavy. Pi pulls this exact GGUF through managed Ollama, probes /fitness on the host, then offers the curator role.\",\n\t},\n\t{\n\t\tname: \"Bonsai-27B (1-bit + vision)\",\n\t\tpullRef: \"hf.co/prism-ml/Bonsai-27B-gguf:Q1_0\",\n\t\trole: \"Context curator / reflex brain / vision-capable lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"External 1-bit 27B, binary weights, 262K-class context, vision via mmproj; served by pi through prism-ml's llama.cpp build (stock llama.cpp/Ollama cannot serve these weights). /fitness on your hardware is the validator — never pre-claim tool-calling.\",\n\t\tnote: \"~3.8 GB weights + 629 MB vision projector + a one-time llama-server runtime download; CPU-served on GPU-less hosts. Pi installs the pinned prism llama.cpp runtime, downloads both files, starts llama-server, and registers the model in one step. Provider-recommended sampling is temp 0.7 / top-p 0.95 / top-k 20; models.json has no per-model default-sampling field yet, so pi cannot wire this — set it per-request/session if your workflow needs it.\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-1.7B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-1.7B-gguf\",\n\t\trole: \"Search scout (heavy-lifter)\",\n\t\ttoolCalling: false,\n\t\trationale:\n\t\t\t\"Ternary weights, very fast; strong at structured search plans. No tool-calling template — use it as a research/worker lane model, never an executor.\",\n\t\tnote: \"Pick a GGUF quant the runtime accepts (e.g. :Q8_0). The ternary Q2_0 build needs prism-ml's patched llama.cpp.\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-4B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-4B-gguf\",\n\t\trole: \"Context curator / reflex brain / lane analyst\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"curator\",\n\t\trationale:\n\t\t\t\"Validated as the 'brain': strict-JSON interpretation and faithful digests. Drives context curation and the toolkit reflex interpreter. Not a tool-caller.\",\n\t\tnote: \"Pick a GGUF quant the runtime accepts (e.g. :Q8_0).\",\n\t},\n\t{\n\t\tname: \"Ternary-Bonsai-8B\",\n\t\tpullRef: \"hf.co/prism-ml/Ternary-Bonsai-8B-gguf\",\n\t\trole: \"Routing judge (larger machines)\",\n\t\ttoolCalling: false,\n\t\tassignRole: \"judge\",\n\t\trationale:\n\t\t\t\"A judge candidate for machines with more headroom — too slow on ~16GB-class hardware in this research, kept for a bigger box.\",\n\t\tnote: \"Heavy: confirm tok/s with /fitness before committing. Ternary quant may need prism-ml's patched llama.cpp.\",\n\t},\n\t{\n\t\tname: \"needle (function-call tester, 26M)\",\n\t\tpullRef: \"hf.co/Cactus-Compute/needle\",\n\t\trole: \"Standalone function-call test bench (not a chat/lane model)\",\n\t\ttoolCalling: false,\n\t\trationale:\n\t\t\t\"NOT a pi chat model, executor, or lane model — needle is a 26M-parameter single-shot function-call SPECIALIST invoked one query at a time through its own `needle run` CLI, useful only as a standalone bench for probing tool-call behavior in isolation. No OpenAI-compatible endpoint, no chat lanes, no models.json registration, and no /fitness probe: use /models needle <query> [tools-json] to test it directly instead.\",\n\t\tnote: \"Upstream weights (needle.pkl) are pickle-only — arbitrary code execution on load by construction, not something pi's pinned-sha256 verification makes safe in the abstract, only tamper-evident.\",\n\t},\n];\n\n/** Bounded plain-text roster for `/models suggest` and the empty-store hint. */\nexport function formatModelSuggestions(suggestions: readonly ModelSuggestion[] = DEFAULT_MODEL_SUGGESTIONS): string[] {\n\tconst lines = [\n\t\t\"Suggested local models (validated roles from pi's own small-model research; probe on YOUR hardware with /fitness):\",\n\t];\n\tfor (const suggestion of suggestions) {\n\t\tlines.push(\n\t\t\t` - ${suggestion.name} → ${suggestion.role}${suggestion.toolCalling ? \"\" : \" [no tool-calling]\"}`,\n\t\t\t` /models add ${suggestion.pullRef}`,\n\t\t\t` ${suggestion.rationale}`,\n\t\t);\n\t\tif (suggestion.note) lines.push(` note: ${suggestion.note}`);\n\t}\n\tlines.push(\"Add one with /models add <ref> — pi pulls it, probes it, and offers a role in one step.\");\n\treturn lines;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fitness-store.d.ts","sourceRoot":"","sources":["../../../src/core/models/fitness-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,EAAE,KAAK,eAAe,EAAqC,MAAM,uBAAuB,CAAC;AAEhG;;;;;;GAMG;AAEH,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,kBAAkB,CAAC;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,eAAe,CAAC;CACtB;AAyED,qBAAa,YAAY;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsD;IAE9E,YAAY,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,eAAe,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAQlG;IAED,MAAM,CAAC,WAAW,CACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,eAAe,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GACnE,YAAY,CAEd;IAED,iGAAiG;IACjG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAShF;IAED,yFAAyF;IACzF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAS1B;IAED,qEAAqE;IACrE,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAEjD;IAED,4EAA4E;IAC5E,MAAM,IAAI,mBAAmB,EAAE,CAE9B;CACD","sourcesContent":["import { stateFile } from \"../agent-paths.ts\";\nimport type { ModelFitnessReport } from \"../research/model-fitness.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport { type HostFingerprint, HostStateStore, isHostFingerprint } from \"./host-state-store.ts\";\n\n/**\n * Durable, HOST-KEYED storage for model fitness reports. Fitness is a property of a model ON a\n * host (tok/s and latency-driven failures do not travel between machines), so reports are keyed\n * by a hardware fingerprint: the same model can be \"the heavy lifter\" on one machine and\n * \"waiting for better hardware\" on another, and pi remembers both without confusing them —\n * including when settings/dotfiles are synced across machines.\n */\n\nexport interface StoredFitnessReport {\n\tmodel: string;\n\treport: ModelFitnessReport;\n\tat: string;\n\thost: HostFingerprint;\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isFinite(value);\n}\n\nfunction isLaneScore(value: unknown): boolean {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\tisFiniteNumber(value.succeeded) &&\n\t\tisFiniteNumber(value.total) &&\n\t\tArray.isArray(value.outcomes) &&\n\t\tvalue.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\tisFiniteNumber(value.meanMs) &&\n\t\t(value.tokensPerSecond === undefined || isFiniteNumber(value.tokensPerSecond))\n\t);\n}\n\nfunction isFitnessReport(value: unknown): value is ModelFitnessReport {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\tisFiniteNumber(value.trials) &&\n\t\t(value.tokensPerSecond === undefined || isFiniteNumber(value.tokensPerSecond)) &&\n\t\tisLaneScore(value.research) &&\n\t\tisLaneScore(value.worker) &&\n\t\tisLaneScore(value.search) &&\n\t\tisLaneScore(value.toolCall) &&\n\t\tisLaneScore(value.digest) &&\n\t\tisPlainRecord(value.judge) &&\n\t\tisFiniteNumber(value.judge.parsed) &&\n\t\tisFiniteNumber(value.judge.planningElevated) &&\n\t\tisFiniteNumber(value.judge.planningTotal) &&\n\t\tisFiniteNumber(value.judge.trivialCheap) &&\n\t\tisFiniteNumber(value.judge.trivialTotal) &&\n\t\tisFiniteNumber(value.judge.total) &&\n\t\tArray.isArray(value.judge.outcomes) &&\n\t\tvalue.judge.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\tisFiniteNumber(value.judge.meanMs) &&\n\t\t(value.judge.tokensPerSecond === undefined || isFiniteNumber(value.judge.tokensPerSecond)) &&\n\t\t(value.capacity === undefined ||\n\t\t\t(isPlainRecord(value.capacity) &&\n\t\t\t\tisFiniteNumber(value.capacity.registeredContextWindow) &&\n\t\t\t\tisFiniteNumber(value.capacity.servedContextWindow) &&\n\t\t\t\tArray.isArray(value.capacity.outcomes) &&\n\t\t\t\tvalue.capacity.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\t\t\tisFiniteNumber(value.capacity.meanMs))) &&\n\t\tisFiniteNumber(value.totalCostUsd)\n\t);\n}\n\nfunction parseFitnessHost(value: unknown, hostId: string): Record<string, StoredFitnessReport> | undefined {\n\tif (!isPlainRecord(value)) return undefined;\n\tconst reports: Record<string, StoredFitnessReport> = {};\n\tfor (const [model, candidate] of Object.entries(value)) {\n\t\tif (\n\t\t\t!isPlainRecord(candidate) ||\n\t\t\tcandidate.model !== model ||\n\t\t\ttypeof candidate.at !== \"string\" ||\n\t\t\t!isHostFingerprint(candidate.host) ||\n\t\t\tcandidate.host.id !== hostId ||\n\t\t\t!isFitnessReport(candidate.report)\n\t\t)\n\t\t\tcontinue;\n\t\treports[model] = {\n\t\t\tmodel,\n\t\t\treport: candidate.report,\n\t\t\tat: candidate.at,\n\t\t\thost: candidate.host,\n\t\t};\n\t}\n\treturn reports;\n}\n\nexport class FitnessStore {\n\tprivate readonly storage: HostStateStore<Record<string, StoredFitnessReport>>;\n\n\tconstructor(filePath: string, options?: { fingerprint?: () => HostFingerprint; readOnly?: boolean }) {\n\t\tthis.storage = new HostStateStore({\n\t\t\tfilePath,\n\t\t\tversion: 1,\n\t\t\tfingerprint: options?.fingerprint,\n\t\t\treadOnly: options?.readOnly ?? isWorkerSession(),\n\t\t\tparseHost: parseFitnessHost,\n\t\t});\n\t}\n\n\tstatic forAgentDir(\n\t\tagentDir: string,\n\t\toptions?: { fingerprint?: () => HostFingerprint; readOnly?: boolean },\n\t): FitnessStore {\n\t\treturn new FitnessStore(stateFile(agentDir, \"model-fitness.json\"), options);\n\t}\n\n\t/** Persist the latest report for a model on the CURRENT host. Best-effort, returns the entry. */\n\tsave(model: string, report: ModelFitnessReport, at?: string): StoredFitnessReport {\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(reports, host) => {\n\t\t\t\tconst entry: StoredFitnessReport = { model, report, at: at ?? new Date().toISOString(), host };\n\t\t\t\treports[model] = entry;\n\t\t\t\treturn { result: entry, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Drop a model's report for the CURRENT host (uninstall cleanup). No-op when absent. */\n\tremove(model: string): void {\n\t\tthis.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(reports) => {\n\t\t\t\tif (!reports[model]) return { result: undefined, changed: false };\n\t\t\t\tdelete reports[model];\n\t\t\t\treturn { result: undefined, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Reports for the current host (default) or an explicit host id. */\n\tgetForHost(hostId?: string): StoredFitnessReport[] {\n\t\treturn Object.values(this.storage.getHost(hostId) ?? {});\n\t}\n\n\t/** Every stored report across all hosts (for cross-machine comparisons). */\n\tgetAll(): StoredFitnessReport[] {\n\t\treturn this.storage.getAllHosts().flatMap((reports) => Object.values(reports));\n\t}\n}\n"]}
1
+ {"version":3,"file":"fitness-store.d.ts","sourceRoot":"","sources":["../../../src/core/models/fitness-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,EAAE,KAAK,eAAe,EAAqC,MAAM,uBAAuB,CAAC;AAEhG;;;;;;GAMG;AAEH,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,kBAAkB,CAAC;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,eAAe,CAAC;CACtB;AAyED,qBAAa,YAAY;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsD;IAE9E,YAAY,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,eAAe,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAQlG;IAED,MAAM,CAAC,WAAW,CACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,eAAe,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GACnE,YAAY,CAEd;IAED,iGAAiG;IACjG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAShF;IAED,yFAAyF;IACzF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAS1B;IAED,qEAAqE;IACrE,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAEjD;IAED,4EAA4E;IAC5E,MAAM,IAAI,mBAAmB,EAAE,CAE9B;CACD"}
@@ -65,7 +65,6 @@ function parseFitnessHost(value, hostId) {
65
65
  return reports;
66
66
  }
67
67
  export class FitnessStore {
68
- storage;
69
68
  constructor(filePath, options) {
70
69
  this.storage = new HostStateStore({
71
70
  filePath,
@@ -1 +1 @@
1
- {"version":3,"file":"fitness-store.js","sourceRoot":"","sources":["../../../src/core/models/fitness-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAwB,cAAc,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAiBhG,SAAS,cAAc,CAAC,KAAc,EAAmB;IACxD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAAA,CAC3D;AAED,SAAS,WAAW,CAAC,KAAc,EAAW;IAC7C,OAAO,CACN,aAAa,CAAC,KAAK,CAAC;QACpB,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC;QAC/B,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC7B,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC;QAC9D,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC;QAC5B,CAAC,KAAK,CAAC,eAAe,KAAK,SAAS,IAAI,cAAc,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAC9E,CAAC;AAAA,CACF;AAED,SAAS,eAAe,CAAC,KAAc,EAA+B;IACrE,OAAO,CACN,aAAa,CAAC,KAAK,CAAC;QACpB,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC;QAC5B,CAAC,KAAK,CAAC,eAAe,KAAK,SAAS,IAAI,cAAc,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAC9E,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC3B,WAAW,CA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AAI,EAAE,CAAC,CAAC;IAAA,CACzD;IAED,4EAA4E;IAC5E,MAAM,GAA0B;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAAA,CAC/E;CACD","sourcesContent":["import { stateFile } from \"../agent-paths.ts\";\nimport type { ModelFitnessReport } from \"../research/model-fitness.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport { type HostFingerprint, HostStateStore, isHostFingerprint } from \"./host-state-store.ts\";\n\n/**\n * Durable, HOST-KEYED storage for model fitness reports. Fitness is a property of a model ON a\n * host (tok/s and latency-driven failures do not travel between machines), so reports are keyed\n * by a hardware fingerprint: the same model can be \"the heavy lifter\" on one machine and\n * \"waiting for better hardware\" on another, and pi remembers both without confusing them —\n * including when settings/dotfiles are synced across machines.\n */\n\nexport interface StoredFitnessReport {\n\tmodel: string;\n\treport: ModelFitnessReport;\n\tat: string;\n\thost: HostFingerprint;\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isFinite(value);\n}\n\nfunction isLaneScore(value: unknown): boolean {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\tisFiniteNumber(value.succeeded) &&\n\t\tisFiniteNumber(value.total) &&\n\t\tArray.isArray(value.outcomes) &&\n\t\tvalue.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\tisFiniteNumber(value.meanMs) &&\n\t\t(value.tokensPerSecond === undefined || isFiniteNumber(value.tokensPerSecond))\n\t);\n}\n\nfunction isFitnessReport(value: unknown): value is ModelFitnessReport {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\tisFiniteNumber(value.trials) &&\n\t\t(value.tokensPerSecond === undefined || isFiniteNumber(value.tokensPerSecond)) &&\n\t\tisLaneScore(value.research) &&\n\t\tisLaneScore(value.worker) &&\n\t\tisLaneScore(value.search) &&\n\t\tisLaneScore(value.toolCall) &&\n\t\tisLaneScore(value.digest) &&\n\t\tisPlainRecord(value.judge) &&\n\t\tisFiniteNumber(value.judge.parsed) &&\n\t\tisFiniteNumber(value.judge.planningElevated) &&\n\t\tisFiniteNumber(value.judge.planningTotal) &&\n\t\tisFiniteNumber(value.judge.trivialCheap) &&\n\t\tisFiniteNumber(value.judge.trivialTotal) &&\n\t\tisFiniteNumber(value.judge.total) &&\n\t\tArray.isArray(value.judge.outcomes) &&\n\t\tvalue.judge.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\tisFiniteNumber(value.judge.meanMs) &&\n\t\t(value.judge.tokensPerSecond === undefined || isFiniteNumber(value.judge.tokensPerSecond)) &&\n\t\t(value.capacity === undefined ||\n\t\t\t(isPlainRecord(value.capacity) &&\n\t\t\t\tisFiniteNumber(value.capacity.registeredContextWindow) &&\n\t\t\t\tisFiniteNumber(value.capacity.servedContextWindow) &&\n\t\t\t\tArray.isArray(value.capacity.outcomes) &&\n\t\t\t\tvalue.capacity.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\t\t\tisFiniteNumber(value.capacity.meanMs))) &&\n\t\tisFiniteNumber(value.totalCostUsd)\n\t);\n}\n\nfunction parseFitnessHost(value: unknown, hostId: string): Record<string, StoredFitnessReport> | undefined {\n\tif (!isPlainRecord(value)) return undefined;\n\tconst reports: Record<string, StoredFitnessReport> = {};\n\tfor (const [model, candidate] of Object.entries(value)) {\n\t\tif (\n\t\t\t!isPlainRecord(candidate) ||\n\t\t\tcandidate.model !== model ||\n\t\t\ttypeof candidate.at !== \"string\" ||\n\t\t\t!isHostFingerprint(candidate.host) ||\n\t\t\tcandidate.host.id !== hostId ||\n\t\t\t!isFitnessReport(candidate.report)\n\t\t)\n\t\t\tcontinue;\n\t\treports[model] = {\n\t\t\tmodel,\n\t\t\treport: candidate.report,\n\t\t\tat: candidate.at,\n\t\t\thost: candidate.host,\n\t\t};\n\t}\n\treturn reports;\n}\n\nexport class FitnessStore {\n\tprivate readonly storage: HostStateStore<Record<string, StoredFitnessReport>>;\n\n\tconstructor(filePath: string, options?: { fingerprint?: () => HostFingerprint; readOnly?: boolean }) {\n\t\tthis.storage = new HostStateStore({\n\t\t\tfilePath,\n\t\t\tversion: 1,\n\t\t\tfingerprint: options?.fingerprint,\n\t\t\treadOnly: options?.readOnly ?? isWorkerSession(),\n\t\t\tparseHost: parseFitnessHost,\n\t\t});\n\t}\n\n\tstatic forAgentDir(\n\t\tagentDir: string,\n\t\toptions?: { fingerprint?: () => HostFingerprint; readOnly?: boolean },\n\t): FitnessStore {\n\t\treturn new FitnessStore(stateFile(agentDir, \"model-fitness.json\"), options);\n\t}\n\n\t/** Persist the latest report for a model on the CURRENT host. Best-effort, returns the entry. */\n\tsave(model: string, report: ModelFitnessReport, at?: string): StoredFitnessReport {\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(reports, host) => {\n\t\t\t\tconst entry: StoredFitnessReport = { model, report, at: at ?? new Date().toISOString(), host };\n\t\t\t\treports[model] = entry;\n\t\t\t\treturn { result: entry, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Drop a model's report for the CURRENT host (uninstall cleanup). No-op when absent. */\n\tremove(model: string): void {\n\t\tthis.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(reports) => {\n\t\t\t\tif (!reports[model]) return { result: undefined, changed: false };\n\t\t\t\tdelete reports[model];\n\t\t\t\treturn { result: undefined, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Reports for the current host (default) or an explicit host id. */\n\tgetForHost(hostId?: string): StoredFitnessReport[] {\n\t\treturn Object.values(this.storage.getHost(hostId) ?? {});\n\t}\n\n\t/** Every stored report across all hosts (for cross-machine comparisons). */\n\tgetAll(): StoredFitnessReport[] {\n\t\treturn this.storage.getAllHosts().flatMap((reports) => Object.values(reports));\n\t}\n}\n"]}
1
+ {"version":3,"file":"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E,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAChF,CAAC;CACD","sourcesContent":["import { stateFile } from \"../agent-paths.ts\";\nimport type { ModelFitnessReport } from \"../research/model-fitness.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport { type HostFingerprint, HostStateStore, isHostFingerprint } from \"./host-state-store.ts\";\n\n/**\n * Durable, HOST-KEYED storage for model fitness reports. Fitness is a property of a model ON a\n * host (tok/s and latency-driven failures do not travel between machines), so reports are keyed\n * by a hardware fingerprint: the same model can be \"the heavy lifter\" on one machine and\n * \"waiting for better hardware\" on another, and pi remembers both without confusing them —\n * including when settings/dotfiles are synced across machines.\n */\n\nexport interface StoredFitnessReport {\n\tmodel: string;\n\treport: ModelFitnessReport;\n\tat: string;\n\thost: HostFingerprint;\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isFinite(value);\n}\n\nfunction isLaneScore(value: unknown): boolean {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\tisFiniteNumber(value.succeeded) &&\n\t\tisFiniteNumber(value.total) &&\n\t\tArray.isArray(value.outcomes) &&\n\t\tvalue.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\tisFiniteNumber(value.meanMs) &&\n\t\t(value.tokensPerSecond === undefined || isFiniteNumber(value.tokensPerSecond))\n\t);\n}\n\nfunction isFitnessReport(value: unknown): value is ModelFitnessReport {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\tisFiniteNumber(value.trials) &&\n\t\t(value.tokensPerSecond === undefined || isFiniteNumber(value.tokensPerSecond)) &&\n\t\tisLaneScore(value.research) &&\n\t\tisLaneScore(value.worker) &&\n\t\tisLaneScore(value.search) &&\n\t\tisLaneScore(value.toolCall) &&\n\t\tisLaneScore(value.digest) &&\n\t\tisPlainRecord(value.judge) &&\n\t\tisFiniteNumber(value.judge.parsed) &&\n\t\tisFiniteNumber(value.judge.planningElevated) &&\n\t\tisFiniteNumber(value.judge.planningTotal) &&\n\t\tisFiniteNumber(value.judge.trivialCheap) &&\n\t\tisFiniteNumber(value.judge.trivialTotal) &&\n\t\tisFiniteNumber(value.judge.total) &&\n\t\tArray.isArray(value.judge.outcomes) &&\n\t\tvalue.judge.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\tisFiniteNumber(value.judge.meanMs) &&\n\t\t(value.judge.tokensPerSecond === undefined || isFiniteNumber(value.judge.tokensPerSecond)) &&\n\t\t(value.capacity === undefined ||\n\t\t\t(isPlainRecord(value.capacity) &&\n\t\t\t\tisFiniteNumber(value.capacity.registeredContextWindow) &&\n\t\t\t\tisFiniteNumber(value.capacity.servedContextWindow) &&\n\t\t\t\tArray.isArray(value.capacity.outcomes) &&\n\t\t\t\tvalue.capacity.outcomes.every((outcome) => typeof outcome === \"string\") &&\n\t\t\t\tisFiniteNumber(value.capacity.meanMs))) &&\n\t\tisFiniteNumber(value.totalCostUsd)\n\t);\n}\n\nfunction parseFitnessHost(value: unknown, hostId: string): Record<string, StoredFitnessReport> | undefined {\n\tif (!isPlainRecord(value)) return undefined;\n\tconst reports: Record<string, StoredFitnessReport> = {};\n\tfor (const [model, candidate] of Object.entries(value)) {\n\t\tif (\n\t\t\t!isPlainRecord(candidate) ||\n\t\t\tcandidate.model !== model ||\n\t\t\ttypeof candidate.at !== \"string\" ||\n\t\t\t!isHostFingerprint(candidate.host) ||\n\t\t\tcandidate.host.id !== hostId ||\n\t\t\t!isFitnessReport(candidate.report)\n\t\t)\n\t\t\tcontinue;\n\t\treports[model] = {\n\t\t\tmodel,\n\t\t\treport: candidate.report,\n\t\t\tat: candidate.at,\n\t\t\thost: candidate.host,\n\t\t};\n\t}\n\treturn reports;\n}\n\nexport class FitnessStore {\n\tprivate readonly storage: HostStateStore<Record<string, StoredFitnessReport>>;\n\n\tconstructor(filePath: string, options?: { fingerprint?: () => HostFingerprint; readOnly?: boolean }) {\n\t\tthis.storage = new HostStateStore({\n\t\t\tfilePath,\n\t\t\tversion: 1,\n\t\t\tfingerprint: options?.fingerprint,\n\t\t\treadOnly: options?.readOnly ?? isWorkerSession(),\n\t\t\tparseHost: parseFitnessHost,\n\t\t});\n\t}\n\n\tstatic forAgentDir(\n\t\tagentDir: string,\n\t\toptions?: { fingerprint?: () => HostFingerprint; readOnly?: boolean },\n\t): FitnessStore {\n\t\treturn new FitnessStore(stateFile(agentDir, \"model-fitness.json\"), options);\n\t}\n\n\t/** Persist the latest report for a model on the CURRENT host. Best-effort, returns the entry. */\n\tsave(model: string, report: ModelFitnessReport, at?: string): StoredFitnessReport {\n\t\treturn this.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(reports, host) => {\n\t\t\t\tconst entry: StoredFitnessReport = { model, report, at: at ?? new Date().toISOString(), host };\n\t\t\t\treports[model] = entry;\n\t\t\t\treturn { result: entry, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Drop a model's report for the CURRENT host (uninstall cleanup). No-op when absent. */\n\tremove(model: string): void {\n\t\tthis.storage.mutateCurrentHost(\n\t\t\t() => ({}),\n\t\t\t(reports) => {\n\t\t\t\tif (!reports[model]) return { result: undefined, changed: false };\n\t\t\t\tdelete reports[model];\n\t\t\t\treturn { result: undefined, changed: true };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Reports for the current host (default) or an explicit host id. */\n\tgetForHost(hostId?: string): StoredFitnessReport[] {\n\t\treturn Object.values(this.storage.getHost(hostId) ?? {});\n\t}\n\n\t/** Every stored report across all hosts (for cross-machine comparisons). */\n\tgetAll(): StoredFitnessReport[] {\n\t\treturn this.storage.getAllHosts().flatMap((reports) => Object.values(reports));\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"host-state-store.d.ts","sourceRoot":"","sources":["../../../src/core/models/host-state-store.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CA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AI;CAiBZ","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { cpus, totalmem } from \"node:os\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport interface HostFingerprint {\n\tid: string;\n\tcpu: string;\n\tcores: number;\n\ttotalMemGb: number;\n}\n\nexport function currentHostFingerprint(): HostFingerprint {\n\tconst cpuList = cpus();\n\tconst cpu = (cpuList[0]?.model ?? \"unknown-cpu\").trim();\n\tconst cores = Math.max(1, cpuList.length);\n\tconst totalMemGb = Math.round(totalmem() / 1024 ** 3);\n\tconst id = `${cpu\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 48)}-${cores}c-${totalMemGb}g`;\n\treturn { id, cpu, cores, totalMemGb };\n}\n\nexport function isHostFingerprint(value: unknown): value is HostFingerprint {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\ttypeof value.id === \"string\" &&\n\t\tvalue.id.length > 0 &&\n\t\ttypeof value.cpu === \"string\" &&\n\t\tNumber.isSafeInteger(value.cores) &&\n\t\tNumber(value.cores) > 0 &&\n\t\ttypeof value.totalMemGb === \"number\" &&\n\t\tNumber.isFinite(value.totalMemGb) &&\n\t\tvalue.totalMemGb >= 0\n\t);\n}\n\ninterface HostStateFile<THostData> {\n\tversion: number;\n\thosts: Record<string, THostData>;\n}\n\nexport interface HostStateMutation<TResult> {\n\tresult: TResult;\n\tchanged: boolean;\n}\n\nexport interface HostStateStoreOptions<THostData> {\n\tfilePath: string;\n\tversion: number;\n\tfingerprint?: () => HostFingerprint;\n\treadOnly?: boolean;\n\tparseHost(value: unknown, hostId: string): THostData | undefined;\n}\n\n/** Shared lock-safe, atomic substrate for versioned state partitioned by host fingerprint. */\nexport class HostStateStore<THostData> {\n\tprivate readonly filePath: string;\n\tprivate readonly version: number;\n\tprivate readonly fingerprint: () => HostFingerprint;\n\tprivate readonly readOnly: boolean;\n\tprivate readonly parseHost: (value: unknown, hostId: string) => THostData | undefined;\n\n\tconstructor(options: HostStateStoreOptions<THostData>) {\n\t\tthis.filePath = options.filePath;\n\t\tthis.version = options.version;\n\t\tthis.fingerprint = options.fingerprint ?? currentHostFingerprint;\n\t\tthis.readOnly = options.readOnly ?? false;\n\t\tthis.parseHost = options.parseHost;\n\t}\n\n\tprivate currentHost(): HostFingerprint {\n\t\treturn this.fingerprint();\n\t}\n\n\tgetHost(hostId = this.currentHost().id): THostData | undefined {\n\t\treturn this.load().hosts[hostId];\n\t}\n\n\tgetAllHosts(): THostData[] {\n\t\treturn Object.values(this.load().hosts);\n\t}\n\n\tmutateCurrentHost<TResult>(\n\t\tcreate: (host: HostFingerprint) => THostData,\n\t\tmutate: (data: THostData, host: HostFingerprint) => HostStateMutation<TResult>,\n\t): TResult {\n\t\tconst host = this.currentHost();\n\t\tconst execute = (): TResult => {\n\t\t\tconst file = this.load();\n\t\t\tconst data = file.hosts[host.id] ?? create(host);\n\t\t\tfile.hosts[host.id] = data;\n\t\t\tconst mutation = mutate(data, host);\n\t\t\tif (mutation.changed && !this.readOnly) {\n\t\t\t\twriteFileAtomicSync(this.filePath, `${JSON.stringify(file, null, \"\\t\")}\\n`);\n\t\t\t}\n\t\t\treturn mutation.result;\n\t\t};\n\t\treturn this.readOnly ? execute() : withFileLockSync(this.filePath, execute);\n\t}\n\n\tprivate load(): HostStateFile<THostData> {\n\t\tif (!existsSync(this.filePath)) return { version: this.version, hosts: {} };\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(readFileSync(this.filePath, \"utf-8\"));\n\t\t\tif (!isPlainRecord(parsed) || parsed.version !== this.version || !isPlainRecord(parsed.hosts)) {\n\t\t\t\treturn { version: this.version, hosts: {} };\n\t\t\t}\n\t\t\tconst hosts: Record<string, THostData> = {};\n\t\t\tfor (const [hostId, value] of Object.entries(parsed.hosts)) {\n\t\t\t\tconst host = this.parseHost(value, hostId);\n\t\t\t\tif (host !== undefined) hosts[hostId] = host;\n\t\t\t}\n\t\t\treturn { version: this.version, hosts };\n\t\t} catch {\n\t\t\treturn { version: this.version, hosts: {} };\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"host-state-store.d.ts","sourceRoot":"","sources":["../../../src/core/models/host-state-store.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,sBAAsB,IAAI,eAAe,CAWxD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAY1E;AAOD,MAAM,WAAW,iBAAiB,CAAC,OAAO;IACzC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB,CAAC,SAAS;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,eAAe,CAAC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;CACjE;AAED,8FAA8F;AAC9F,qBAAa,cAAc,CAAC,SAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwB;IACpD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4D;IAEtF,YAAY,OAAO,EAAE,qBAAqB,CAAC,SAAS,CAAC,EAMpD;IAED,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,MAAM,SAAwB,GAAG,SAAS,GAAG,SAAS,CAE7D;IAED,WAAW,IAAI,SAAS,EAAE,CAEzB;IAED,iBAAiB,CAAC,OAAO,EACxB,MAAM,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,SAAS,EAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,KAAK,iBAAiB,CAAC,OAAO,CAAC,GAC5E,OAAO,CAaT;IAED,OAAO,CAAC,IAAI;CAiBZ"}
@@ -27,11 +27,6 @@ export function isHostFingerprint(value) {
27
27
  }
28
28
  /** Shared lock-safe, atomic substrate for versioned state partitioned by host fingerprint. */
29
29
  export class HostStateStore {
30
- filePath;
31
- version;
32
- fingerprint;
33
- readOnly;
34
- parseHost;
35
30
  constructor(options) {
36
31
  this.filePath = options.filePath;
37
32
  this.version = options.version;
@@ -56,7 +51,7 @@ export class HostStateStore {
56
51
  file.hosts[host.id] = data;
57
52
  const mutation = mutate(data, host);
58
53
  if (mutation.changed && !this.readOnly) {
59
- writeFileAtomicSync(this.filePath, `${JSON.stringify(file, null, "\t")}\n`);
54
+ writeFileAtomicSync(this.filePath, `${JSON.stringify(file)}\n`);
60
55
  }
61
56
  return mutation.result;
62
57
  };
@@ -1 +1 @@
1
- {"version":3,"file":"host-state-store.js","sourceRoot":"","sources":["../../../src/core/models/host-state-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AASxD,MAAM,UAAU,sBAAsB,GAAoB;IACzD,MAAM,OAAO,GAAG,IAAI,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,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AC;YACR,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;QAC7C,CAAC;IAAA,CACD;CACD","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { cpus, totalmem } from \"node:os\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport interface HostFingerprint {\n\tid: string;\n\tcpu: string;\n\tcores: number;\n\ttotalMemGb: number;\n}\n\nexport function currentHostFingerprint(): HostFingerprint {\n\tconst cpuList = cpus();\n\tconst cpu = (cpuList[0]?.model ?? \"unknown-cpu\").trim();\n\tconst cores = Math.max(1, cpuList.length);\n\tconst totalMemGb = Math.round(totalmem() / 1024 ** 3);\n\tconst id = `${cpu\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 48)}-${cores}c-${totalMemGb}g`;\n\treturn { id, cpu, cores, totalMemGb };\n}\n\nexport function isHostFingerprint(value: unknown): value is HostFingerprint {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\ttypeof value.id === \"string\" &&\n\t\tvalue.id.length > 0 &&\n\t\ttypeof value.cpu === \"string\" &&\n\t\tNumber.isSafeInteger(value.cores) &&\n\t\tNumber(value.cores) > 0 &&\n\t\ttypeof value.totalMemGb === \"number\" &&\n\t\tNumber.isFinite(value.totalMemGb) &&\n\t\tvalue.totalMemGb >= 0\n\t);\n}\n\ninterface HostStateFile<THostData> {\n\tversion: number;\n\thosts: Record<string, THostData>;\n}\n\nexport interface HostStateMutation<TResult> {\n\tresult: TResult;\n\tchanged: boolean;\n}\n\nexport interface HostStateStoreOptions<THostData> {\n\tfilePath: string;\n\tversion: number;\n\tfingerprint?: () => HostFingerprint;\n\treadOnly?: boolean;\n\tparseHost(value: unknown, hostId: string): THostData | undefined;\n}\n\n/** Shared lock-safe, atomic substrate for versioned state partitioned by host fingerprint. */\nexport class HostStateStore<THostData> {\n\tprivate readonly filePath: string;\n\tprivate readonly version: number;\n\tprivate readonly fingerprint: () => HostFingerprint;\n\tprivate readonly readOnly: boolean;\n\tprivate readonly parseHost: (value: unknown, hostId: string) => THostData | undefined;\n\n\tconstructor(options: HostStateStoreOptions<THostData>) {\n\t\tthis.filePath = options.filePath;\n\t\tthis.version = options.version;\n\t\tthis.fingerprint = options.fingerprint ?? currentHostFingerprint;\n\t\tthis.readOnly = options.readOnly ?? false;\n\t\tthis.parseHost = options.parseHost;\n\t}\n\n\tprivate currentHost(): HostFingerprint {\n\t\treturn this.fingerprint();\n\t}\n\n\tgetHost(hostId = this.currentHost().id): THostData | undefined {\n\t\treturn this.load().hosts[hostId];\n\t}\n\n\tgetAllHosts(): THostData[] {\n\t\treturn Object.values(this.load().hosts);\n\t}\n\n\tmutateCurrentHost<TResult>(\n\t\tcreate: (host: HostFingerprint) => THostData,\n\t\tmutate: (data: THostData, host: HostFingerprint) => HostStateMutation<TResult>,\n\t): TResult {\n\t\tconst host = this.currentHost();\n\t\tconst execute = (): TResult => {\n\t\t\tconst file = this.load();\n\t\t\tconst data = file.hosts[host.id] ?? create(host);\n\t\t\tfile.hosts[host.id] = data;\n\t\t\tconst mutation = mutate(data, host);\n\t\t\tif (mutation.changed && !this.readOnly) {\n\t\t\t\twriteFileAtomicSync(this.filePath, `${JSON.stringify(file, null, \"\\t\")}\\n`);\n\t\t\t}\n\t\t\treturn mutation.result;\n\t\t};\n\t\treturn this.readOnly ? execute() : withFileLockSync(this.filePath, execute);\n\t}\n\n\tprivate load(): HostStateFile<THostData> {\n\t\tif (!existsSync(this.filePath)) return { version: this.version, hosts: {} };\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(readFileSync(this.filePath, \"utf-8\"));\n\t\t\tif (!isPlainRecord(parsed) || parsed.version !== this.version || !isPlainRecord(parsed.hosts)) {\n\t\t\t\treturn { version: this.version, hosts: {} };\n\t\t\t}\n\t\t\tconst hosts: Record<string, THostData> = {};\n\t\t\tfor (const [hostId, value] of Object.entries(parsed.hosts)) {\n\t\t\t\tconst host = this.parseHost(value, hostId);\n\t\t\t\tif (host !== undefined) hosts[hostId] = host;\n\t\t\t}\n\t\t\treturn { version: this.version, hosts };\n\t\t} catch {\n\t\t\treturn { version: this.version, hosts: {} };\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"host-state-store.js","sourceRoot":"","sources":["../../../src/core/models/host-state-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AASxD,MAAM,UAAU,sBAAsB;IACrC,MAAM,OAAO,GAAG,IAAI,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC;IACxD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC;IACtD,MAAM,EAAE,GAAG,GAAG,GAAG;SACf,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,KAAK,UAAU,GAAG,CAAC;IAC1C,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AACvC,CAAC;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E,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;YAC7C,CAAC;YACD,MAAM,KAAK,GAA8B,EAAE,CAAC;YAC5C,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAC3C,IAAI,IAAI,KAAK,SAAS;oBAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;YAC9C,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QACzC,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;QAC7C,CAAC;IACF,CAAC;CACD","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { cpus, totalmem } from \"node:os\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport interface HostFingerprint {\n\tid: string;\n\tcpu: string;\n\tcores: number;\n\ttotalMemGb: number;\n}\n\nexport function currentHostFingerprint(): HostFingerprint {\n\tconst cpuList = cpus();\n\tconst cpu = (cpuList[0]?.model ?? \"unknown-cpu\").trim();\n\tconst cores = Math.max(1, cpuList.length);\n\tconst totalMemGb = Math.round(totalmem() / 1024 ** 3);\n\tconst id = `${cpu\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 48)}-${cores}c-${totalMemGb}g`;\n\treturn { id, cpu, cores, totalMemGb };\n}\n\nexport function isHostFingerprint(value: unknown): value is HostFingerprint {\n\treturn (\n\t\tisPlainRecord(value) &&\n\t\ttypeof value.id === \"string\" &&\n\t\tvalue.id.length > 0 &&\n\t\ttypeof value.cpu === \"string\" &&\n\t\tNumber.isSafeInteger(value.cores) &&\n\t\tNumber(value.cores) > 0 &&\n\t\ttypeof value.totalMemGb === \"number\" &&\n\t\tNumber.isFinite(value.totalMemGb) &&\n\t\tvalue.totalMemGb >= 0\n\t);\n}\n\ninterface HostStateFile<THostData> {\n\tversion: number;\n\thosts: Record<string, THostData>;\n}\n\nexport interface HostStateMutation<TResult> {\n\tresult: TResult;\n\tchanged: boolean;\n}\n\nexport interface HostStateStoreOptions<THostData> {\n\tfilePath: string;\n\tversion: number;\n\tfingerprint?: () => HostFingerprint;\n\treadOnly?: boolean;\n\tparseHost(value: unknown, hostId: string): THostData | undefined;\n}\n\n/** Shared lock-safe, atomic substrate for versioned state partitioned by host fingerprint. */\nexport class HostStateStore<THostData> {\n\tprivate readonly filePath: string;\n\tprivate readonly version: number;\n\tprivate readonly fingerprint: () => HostFingerprint;\n\tprivate readonly readOnly: boolean;\n\tprivate readonly parseHost: (value: unknown, hostId: string) => THostData | undefined;\n\n\tconstructor(options: HostStateStoreOptions<THostData>) {\n\t\tthis.filePath = options.filePath;\n\t\tthis.version = options.version;\n\t\tthis.fingerprint = options.fingerprint ?? currentHostFingerprint;\n\t\tthis.readOnly = options.readOnly ?? false;\n\t\tthis.parseHost = options.parseHost;\n\t}\n\n\tprivate currentHost(): HostFingerprint {\n\t\treturn this.fingerprint();\n\t}\n\n\tgetHost(hostId = this.currentHost().id): THostData | undefined {\n\t\treturn this.load().hosts[hostId];\n\t}\n\n\tgetAllHosts(): THostData[] {\n\t\treturn Object.values(this.load().hosts);\n\t}\n\n\tmutateCurrentHost<TResult>(\n\t\tcreate: (host: HostFingerprint) => THostData,\n\t\tmutate: (data: THostData, host: HostFingerprint) => HostStateMutation<TResult>,\n\t): TResult {\n\t\tconst host = this.currentHost();\n\t\tconst execute = (): TResult => {\n\t\t\tconst file = this.load();\n\t\t\tconst data = file.hosts[host.id] ?? create(host);\n\t\t\tfile.hosts[host.id] = data;\n\t\t\tconst mutation = mutate(data, host);\n\t\t\tif (mutation.changed && !this.readOnly) {\n\t\t\t\twriteFileAtomicSync(this.filePath, `${JSON.stringify(file)}\\n`);\n\t\t\t}\n\t\t\treturn mutation.result;\n\t\t};\n\t\treturn this.readOnly ? execute() : withFileLockSync(this.filePath, execute);\n\t}\n\n\tprivate load(): HostStateFile<THostData> {\n\t\tif (!existsSync(this.filePath)) return { version: this.version, hosts: {} };\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(readFileSync(this.filePath, \"utf-8\"));\n\t\t\tif (!isPlainRecord(parsed) || parsed.version !== this.version || !isPlainRecord(parsed.hosts)) {\n\t\t\t\treturn { version: this.version, hosts: {} };\n\t\t\t}\n\t\t\tconst hosts: Record<string, THostData> = {};\n\t\t\tfor (const [hostId, value] of Object.entries(parsed.hosts)) {\n\t\t\t\tconst host = this.parseHost(value, hostId);\n\t\t\t\tif (host !== undefined) hosts[hostId] = host;\n\t\t\t}\n\t\t\treturn { version: this.version, hosts };\n\t\t} catch {\n\t\t\treturn { version: this.version, hosts: {} };\n\t\t}\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { type ChildProcess } from "node:child_process";
2
1
  import type { Readable } from "node:stream";
2
+ import { type ManagedRuntimeSpawn } from "./runtime-process.ts";
3
3
  /**
4
4
  * Managed runtime for prism-ml 1-bit GGUF models (Bonsai-27B first). The provider requires their
5
5
  * llama.cpp fork (Q1_0_g128 hybrid-attention kernels) — stock llama.cpp/Ollama cannot serve these
@@ -65,19 +65,13 @@ export type PrismServeResult = {
65
65
  ok: false;
66
66
  error: string;
67
67
  };
68
- type PrismSpawnOptions = {
69
- detached?: boolean;
70
- stdio?: "ignore";
71
- env?: NodeJS.ProcessEnv;
72
- };
73
- type PrismSpawnFn = (command: string, args: string[], options: PrismSpawnOptions) => Pick<ChildProcess, "pid" | "kill" | "unref" | "on">;
74
68
  type PrismExtractArchiveFn = (input: Readable, destDir: string, kind: PrismAssetKind) => Promise<{
75
69
  ok: boolean;
76
70
  error?: string;
77
71
  }>;
78
72
  export interface PrismLlamaCppDeps {
79
73
  fetchFn?: typeof fetch;
80
- spawnFn?: PrismSpawnFn;
74
+ spawnFn?: ManagedRuntimeSpawn;
81
75
  existsFn?: (path: string) => boolean;
82
76
  sleepFn?: (ms: number) => Promise<void>;
83
77
  /** Whether a named command exists on PATH (nvidia-smi, tar — for zip extraction on Windows). */
@@ -105,7 +99,7 @@ export declare class PrismLlamaCppRuntime {
105
99
  private readonly _hasNvidiaGpu;
106
100
  private readonly _platform;
107
101
  private readonly _arch;
108
- private readonly _extractArchiveOverride;
102
+ private readonly _extractArchiveFn;
109
103
  private readonly _healthPollAttempts;
110
104
  private readonly _healthPollIntervalMs;
111
105
  private _child;
@@ -135,20 +129,11 @@ export declare class PrismLlamaCppRuntime {
135
129
  ok: boolean;
136
130
  error?: string;
137
131
  }>;
132
+ private _installArchive;
138
133
  private _extractArchive;
139
134
  private _extractTarGz;
140
135
  private _extractZip;
141
136
  private _remoteContentLength;
142
- private _fileSizeBytes;
143
- private _cleanupPartial;
144
- /**
145
- * Wait until a write stream's underlying fd is actually closed. `pipeline()` destroys the
146
- * stream on error but its promise can settle before the fd close completes (Windows in
147
- * particular keeps the file handle open a tick longer) — unlinking before that races with the
148
- * OS and can leave the "partial" file behind or fail the delete outright. Resolves immediately
149
- * if the stream already reports `closed`.
150
- */
151
- private _waitForStreamClosed;
152
137
  /**
153
138
  * Stream a GGUF (or mmproj) file from Hugging Face into pi's owned models dir. Skips a re-download
154
139
  * when the local file already matches the remote size; verifies size when the response reports