@caupulican/pi-adaptative 0.81.41 → 0.81.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1480) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/bun/cli.d.ts.map +1 -1
  3. package/dist/bun/cli.js.map +1 -1
  4. package/dist/bun/register-bedrock.d.ts.map +1 -1
  5. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  6. package/dist/bun/restore-sandbox-env.js.map +1 -1
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +52 -49
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +62 -57
  13. package/dist/bundled-resources/prompts/skillify.md +1 -1
  14. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/fs.py +16 -19
  15. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/search.py +12 -26
  16. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/strings.py +15 -121
  17. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +57 -80
  18. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
  19. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
  20. package/dist/bundled-resources/runtimes/pi-shell-engine/escapes.py +70 -0
  21. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +135 -63
  22. package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
  23. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +108 -22
  24. package/dist/bundled-resources/runtimes/pi-shell-engine/paths.py +10 -0
  25. package/dist/bundled-resources/runtimes/pi-shell-engine/proc.py +12 -4
  26. package/dist/bundled-resources/runtimes/pi-shell-engine/shell_args.py +22 -0
  27. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +10 -2
  28. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +131 -259
  29. package/dist/bundled-resources/skills/authorized-web-security-audit/SKILL.md +187 -0
  30. package/dist/bundled-resources/skills/authorized-web-security-audit/references/assessment-contract.md +92 -0
  31. package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +134 -0
  32. package/dist/bundled-resources/skills/evidence-gated-tdd/SKILL.md +93 -0
  33. package/dist/bundled-resources/skills/evidence-gated-tdd/references/evidence-model.md +27 -0
  34. package/dist/bundled-resources/skills/evidence-gated-tdd/references/security-scanners.md +24 -0
  35. package/dist/bundled-resources/skills/harness-self-adaptation/SKILL.md +4 -2
  36. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/SKILL.md +217 -0
  37. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/defensive-exploit-catalogue.md +175 -0
  38. package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/tool-boundary-checklist.md +87 -0
  39. package/dist/bundled-resources/skills/skill-architect/SKILL.md +2 -2
  40. package/dist/bundled-resources/skills/skill-creator/SKILL.md +188 -0
  41. package/dist/bundled-resources/skills/skill-creator/references/pi-skill-contract.md +73 -0
  42. package/dist/bundled-resources/skills/skill-creator/scripts/init-skill.mjs +142 -0
  43. package/dist/bundled-resources/skills/skill-creator/scripts/validate-skill.mjs +122 -0
  44. package/dist/cli/args.d.ts.map +1 -1
  45. package/dist/cli/args.js.map +1 -1
  46. package/dist/cli/config-selector.d.ts.map +1 -1
  47. package/dist/cli/config-selector.js.map +1 -1
  48. package/dist/cli/file-processor.d.ts.map +1 -1
  49. package/dist/cli/file-processor.js +8 -8
  50. package/dist/cli/file-processor.js.map +1 -1
  51. package/dist/cli/initial-message.d.ts +1 -1
  52. package/dist/cli/initial-message.d.ts.map +1 -1
  53. package/dist/cli/initial-message.js.map +1 -1
  54. package/dist/cli/list-models.d.ts.map +1 -1
  55. package/dist/cli/list-models.js.map +1 -1
  56. package/dist/cli/piped-stdin.d.ts +4 -0
  57. package/dist/cli/piped-stdin.d.ts.map +1 -0
  58. package/dist/cli/piped-stdin.js +13 -0
  59. package/dist/cli/piped-stdin.js.map +1 -0
  60. package/dist/cli/session-picker.d.ts.map +1 -1
  61. package/dist/cli/session-picker.js.map +1 -1
  62. package/dist/cli.d.ts.map +1 -1
  63. package/dist/cli.js.map +1 -1
  64. package/dist/config.d.ts.map +1 -1
  65. package/dist/config.js +9 -14
  66. package/dist/config.js.map +1 -1
  67. package/dist/core/agent-directory-layout.d.ts.map +1 -1
  68. package/dist/core/agent-directory-layout.js.map +1 -1
  69. package/dist/core/agent-paths.d.ts +32 -0
  70. package/dist/core/agent-paths.d.ts.map +1 -1
  71. package/dist/core/agent-paths.js +65 -0
  72. package/dist/core/agent-paths.js.map +1 -1
  73. package/dist/core/agent-session-contracts.d.ts +24 -10
  74. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  75. package/dist/core/agent-session-contracts.js +1 -12
  76. package/dist/core/agent-session-contracts.js.map +1 -1
  77. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  78. package/dist/core/agent-session-runtime.js +10 -25
  79. package/dist/core/agent-session-runtime.js.map +1 -1
  80. package/dist/core/agent-session-services.d.ts.map +1 -1
  81. package/dist/core/agent-session-services.js.map +1 -1
  82. package/dist/core/agent-session.d.ts +24 -1
  83. package/dist/core/agent-session.d.ts.map +1 -1
  84. package/dist/core/agent-session.js +214 -246
  85. package/dist/core/agent-session.js.map +1 -1
  86. package/dist/core/auth-guidance.d.ts.map +1 -1
  87. package/dist/core/auth-guidance.js.map +1 -1
  88. package/dist/core/auth-storage.d.ts +4 -1
  89. package/dist/core/auth-storage.d.ts.map +1 -1
  90. package/dist/core/auth-storage.js +13 -39
  91. package/dist/core/auth-storage.js.map +1 -1
  92. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  93. package/dist/core/autonomy/approval-gate.js.map +1 -1
  94. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  95. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  96. package/dist/core/autonomy/contracts.d.ts +2 -0
  97. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  98. package/dist/core/autonomy/contracts.js.map +1 -1
  99. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  100. package/dist/core/autonomy/envelope-enforcement.js +4 -9
  101. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  102. package/dist/core/autonomy/evidence-finding-projection.d.ts +11 -0
  103. package/dist/core/autonomy/evidence-finding-projection.d.ts.map +1 -0
  104. package/dist/core/autonomy/evidence-finding-projection.js +37 -0
  105. package/dist/core/autonomy/evidence-finding-projection.js.map +1 -0
  106. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  107. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  108. package/dist/core/autonomy/gates.d.ts.map +1 -1
  109. package/dist/core/autonomy/gates.js.map +1 -1
  110. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -1
  111. package/dist/core/autonomy/lane-private-paths.js.map +1 -1
  112. package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
  113. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  114. package/dist/core/autonomy/lane-tool-surface.js +17 -4
  115. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  116. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  117. package/dist/core/autonomy/lane-tracker.js +2 -3
  118. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  119. package/dist/core/autonomy/path-scope.d.ts +14 -0
  120. package/dist/core/autonomy/path-scope.d.ts.map +1 -1
  121. package/dist/core/autonomy/path-scope.js +37 -6
  122. package/dist/core/autonomy/path-scope.js.map +1 -1
  123. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  124. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  125. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  126. package/dist/core/autonomy/status.d.ts.map +1 -1
  127. package/dist/core/autonomy/status.js.map +1 -1
  128. package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
  129. package/dist/core/autonomy/subagent-prompt.js.map +1 -1
  130. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  131. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  132. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  133. package/dist/core/autonomy-telemetry.js +2 -4
  134. package/dist/core/autonomy-telemetry.js.map +1 -1
  135. package/dist/core/background-lane-controller.d.ts +27 -1
  136. package/dist/core/background-lane-controller.d.ts.map +1 -1
  137. package/dist/core/background-lane-controller.js +34 -16
  138. package/dist/core/background-lane-controller.js.map +1 -1
  139. package/dist/core/background-tool-task-controller.d.ts +88 -0
  140. package/dist/core/background-tool-task-controller.d.ts.map +1 -0
  141. package/dist/core/background-tool-task-controller.js +470 -0
  142. package/dist/core/background-tool-task-controller.js.map +1 -0
  143. package/dist/core/bash-execution-controller.d.ts +1 -0
  144. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  145. package/dist/core/bash-execution-controller.js +5 -4
  146. package/dist/core/bash-execution-controller.js.map +1 -1
  147. package/dist/core/bash-executor.d.ts.map +1 -1
  148. package/dist/core/bash-executor.js.map +1 -1
  149. package/dist/core/bedrock-sso-login.d.ts.map +1 -1
  150. package/dist/core/bedrock-sso-login.js.map +1 -1
  151. package/dist/core/billing-failover-controller.d.ts.map +1 -1
  152. package/dist/core/billing-failover-controller.js +3 -3
  153. package/dist/core/billing-failover-controller.js.map +1 -1
  154. package/dist/core/billing-failover.d.ts.map +1 -1
  155. package/dist/core/billing-failover.js.map +1 -1
  156. package/dist/core/capability-contract.d.ts.map +1 -1
  157. package/dist/core/catalog-manager.d.ts.map +1 -1
  158. package/dist/core/catalog-manager.js +0 -0
  159. package/dist/core/catalog-manager.js.map +1 -1
  160. package/dist/core/compaction-controller.d.ts +2 -0
  161. package/dist/core/compaction-controller.d.ts.map +1 -1
  162. package/dist/core/compaction-controller.js +21 -8
  163. package/dist/core/compaction-controller.js.map +1 -1
  164. package/dist/core/compaction-support.d.ts +8 -0
  165. package/dist/core/compaction-support.d.ts.map +1 -1
  166. package/dist/core/compaction-support.js +0 -2
  167. package/dist/core/compaction-support.js.map +1 -1
  168. package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
  169. package/dist/core/context/artifact-retrieval.js.map +1 -1
  170. package/dist/core/context/brain-curator.d.ts.map +1 -1
  171. package/dist/core/context/brain-curator.js +14 -33
  172. package/dist/core/context/brain-curator.js.map +1 -1
  173. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  174. package/dist/core/context/context-artifacts.js +16 -24
  175. package/dist/core/context/context-artifacts.js.map +1 -1
  176. package/dist/core/context/context-audit.d.ts.map +1 -1
  177. package/dist/core/context/context-audit.js +3 -17
  178. package/dist/core/context/context-audit.js.map +1 -1
  179. package/dist/core/context/context-composition.d.ts.map +1 -1
  180. package/dist/core/context/context-composition.js.map +1 -1
  181. package/dist/core/context/context-item.d.ts.map +1 -1
  182. package/dist/core/context/context-item.js.map +1 -1
  183. package/dist/core/context/context-prompt-enforcement.d.ts.map +1 -1
  184. package/dist/core/context/context-prompt-enforcement.js +3 -16
  185. package/dist/core/context/context-prompt-enforcement.js.map +1 -1
  186. package/dist/core/context/context-prompt-policy.d.ts.map +1 -1
  187. package/dist/core/context/context-prompt-policy.js.map +1 -1
  188. package/dist/core/context/context-retention.d.ts.map +1 -1
  189. package/dist/core/context/context-retention.js.map +1 -1
  190. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  191. package/dist/core/context/context-store-retention.js.map +1 -1
  192. package/dist/core/context/context-store.d.ts.map +1 -1
  193. package/dist/core/context/context-store.js.map +1 -1
  194. package/dist/core/context/context-tool-result.d.ts +4 -0
  195. package/dist/core/context/context-tool-result.d.ts.map +1 -0
  196. package/dist/core/context/context-tool-result.js +15 -0
  197. package/dist/core/context/context-tool-result.js.map +1 -0
  198. package/dist/core/context/current-work-memory.d.ts.map +1 -1
  199. package/dist/core/context/current-work-memory.js.map +1 -1
  200. package/dist/core/context/file-store-memory-provider.d.ts.map +1 -1
  201. package/dist/core/context/file-store-memory-provider.js +7 -28
  202. package/dist/core/context/file-store-memory-provider.js.map +1 -1
  203. package/dist/core/context/local-memory-search.d.ts +11 -0
  204. package/dist/core/context/local-memory-search.d.ts.map +1 -0
  205. package/dist/core/context/local-memory-search.js +37 -0
  206. package/dist/core/context/local-memory-search.js.map +1 -0
  207. package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
  208. package/dist/core/context/long-term-memory-trigger.js.map +1 -1
  209. package/dist/core/context/memory-diagnostics.d.ts.map +1 -1
  210. package/dist/core/context/memory-diagnostics.js.map +1 -1
  211. package/dist/core/context/memory-index-store.d.ts.map +1 -1
  212. package/dist/core/context/memory-index-store.js.map +1 -1
  213. package/dist/core/context/memory-prompt-block.d.ts.map +1 -1
  214. package/dist/core/context/memory-prompt-block.js.map +1 -1
  215. package/dist/core/context/memory-prompt-budget.d.ts.map +1 -1
  216. package/dist/core/context/memory-prompt-budget.js.map +1 -1
  217. package/dist/core/context/memory-provider-contract.d.ts.map +1 -1
  218. package/dist/core/context/memory-provider-contract.js.map +1 -1
  219. package/dist/core/context/memory-retrieval.d.ts.map +1 -1
  220. package/dist/core/context/memory-retrieval.js.map +1 -1
  221. package/dist/core/context/memory-tier-composer.d.ts.map +1 -1
  222. package/dist/core/context/memory-tier-composer.js.map +1 -1
  223. package/dist/core/context/message-text.d.ts +7 -0
  224. package/dist/core/context/message-text.d.ts.map +1 -0
  225. package/dist/core/context/message-text.js +68 -0
  226. package/dist/core/context/message-text.js.map +1 -0
  227. package/dist/core/context/okf-memory-provider.d.ts.map +1 -1
  228. package/dist/core/context/okf-memory-provider.js +4 -30
  229. package/dist/core/context/okf-memory-provider.js.map +1 -1
  230. package/dist/core/context/okf-memory.d.ts.map +1 -1
  231. package/dist/core/context/okf-memory.js.map +1 -1
  232. package/dist/core/context/policy-engine.d.ts.map +1 -1
  233. package/dist/core/context/policy-engine.js.map +1 -1
  234. package/dist/core/context/policy-types.d.ts.map +1 -1
  235. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  236. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  237. package/dist/core/context/storage-authority.d.ts.map +1 -1
  238. package/dist/core/context/tool-output-packer.d.ts.map +1 -1
  239. package/dist/core/context/tool-output-packer.js.map +1 -1
  240. package/dist/core/context-gc.d.ts.map +1 -1
  241. package/dist/core/context-gc.js +14 -21
  242. package/dist/core/context-gc.js.map +1 -1
  243. package/dist/core/context-pipeline.d.ts +1 -3
  244. package/dist/core/context-pipeline.d.ts.map +1 -1
  245. package/dist/core/context-pipeline.js +64 -145
  246. package/dist/core/context-pipeline.js.map +1 -1
  247. package/dist/core/cost/cost-summary.d.ts.map +1 -1
  248. package/dist/core/cost/cost-summary.js.map +1 -1
  249. package/dist/core/cost/daily-usage.d.ts.map +1 -1
  250. package/dist/core/cost/daily-usage.js.map +1 -1
  251. package/dist/core/cost/session-usage.d.ts.map +1 -1
  252. package/dist/core/cost/session-usage.js.map +1 -1
  253. package/dist/core/cost-guard.d.ts.map +1 -1
  254. package/dist/core/cost-guard.js.map +1 -1
  255. package/dist/core/default-tool-surface.d.ts.map +1 -1
  256. package/dist/core/default-tool-surface.js +1 -0
  257. package/dist/core/default-tool-surface.js.map +1 -1
  258. package/dist/core/defaults.d.ts.map +1 -1
  259. package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
  260. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  261. package/dist/core/delegation/managed-lane-controller.js +85 -46
  262. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  263. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
  264. package/dist/core/delegation/session-worker-claim.js +4 -3
  265. package/dist/core/delegation/session-worker-claim.js.map +1 -1
  266. package/dist/core/delegation/worker-action-journal.d.ts +73 -0
  267. package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
  268. package/dist/core/delegation/worker-action-journal.js +293 -0
  269. package/dist/core/delegation/worker-action-journal.js.map +1 -0
  270. package/dist/core/delegation/worker-actions.d.ts +36 -1
  271. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  272. package/dist/core/delegation/worker-actions.js +171 -46
  273. package/dist/core/delegation/worker-actions.js.map +1 -1
  274. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +76 -0
  275. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
  276. package/dist/core/delegation/worker-agent-control-coordinator.js +216 -0
  277. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
  278. package/dist/core/delegation/worker-agent-control.d.ts +66 -0
  279. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
  280. package/dist/core/delegation/worker-agent-control.js +160 -0
  281. package/dist/core/delegation/worker-agent-control.js.map +1 -0
  282. package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
  283. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
  284. package/dist/core/delegation/worker-attempt-executor.js +343 -0
  285. package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
  286. package/dist/core/delegation/worker-claim.d.ts +30 -0
  287. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  288. package/dist/core/delegation/worker-claim.js +205 -53
  289. package/dist/core/delegation/worker-claim.js.map +1 -1
  290. package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
  291. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
  292. package/dist/core/delegation/worker-conversation-store.js +440 -0
  293. package/dist/core/delegation/worker-conversation-store.js.map +1 -0
  294. package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
  295. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  296. package/dist/core/delegation/worker-delegation-controller.js +386 -260
  297. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  298. package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
  299. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  300. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  301. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
  302. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
  303. package/dist/core/delegation/worker-dispatch-scheduler.js +20 -11
  304. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
  305. package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
  306. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  307. package/dist/core/delegation/worker-execution-policy.js +5 -7
  308. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  309. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
  310. package/dist/core/delegation/worker-lane-projection.js.map +1 -1
  311. package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
  312. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  313. package/dist/core/delegation/worker-lifecycle.js +119 -2
  314. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  315. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
  316. package/dist/core/delegation/worker-notification-coordinator.js +4 -5
  317. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
  318. package/dist/core/delegation/worker-process-owner.d.ts +18 -0
  319. package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
  320. package/dist/core/delegation/worker-process-owner.js +54 -0
  321. package/dist/core/delegation/worker-process-owner.js.map +1 -0
  322. package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
  323. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  324. package/dist/core/delegation/worker-profile-resolver.js +9 -2
  325. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  326. package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
  327. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
  328. package/dist/core/delegation/worker-recovery-coordinator.js +180 -0
  329. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
  330. package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
  331. package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
  332. package/dist/core/delegation/worker-resource-catalog.js +116 -0
  333. package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
  334. package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
  335. package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
  336. package/dist/core/delegation/worker-resource-materializer.js +134 -0
  337. package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
  338. package/dist/core/delegation/worker-runner.d.ts +5 -5
  339. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  340. package/dist/core/delegation/worker-runner.js +193 -70
  341. package/dist/core/delegation/worker-runner.js.map +1 -1
  342. package/dist/core/delegation/worker-task-label.d.ts.map +1 -1
  343. package/dist/core/delegation/worker-task-label.js.map +1 -1
  344. package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
  345. package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
  346. package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
  347. package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
  348. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
  349. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
  350. package/dist/core/delegation/worker-write-reservation-coordinator.js +104 -0
  351. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
  352. package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
  353. package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
  354. package/dist/core/delegation/worker-write-reservation.js +346 -0
  355. package/dist/core/delegation/worker-write-reservation.js.map +1 -0
  356. package/dist/core/diagnostics.d.ts.map +1 -1
  357. package/dist/core/doctor.d.ts.map +1 -1
  358. package/dist/core/doctor.js.map +1 -1
  359. package/dist/core/event-bus.d.ts.map +1 -1
  360. package/dist/core/event-bus.js.map +1 -1
  361. package/dist/core/exec.d.ts.map +1 -1
  362. package/dist/core/exec.js +26 -7
  363. package/dist/core/exec.js.map +1 -1
  364. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  365. package/dist/core/export-html/ansi-to-html.js +21 -74
  366. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  367. package/dist/core/export-html/index.d.ts.map +1 -1
  368. package/dist/core/export-html/index.js +4 -0
  369. package/dist/core/export-html/index.js.map +1 -1
  370. package/dist/core/export-html/session-tree-foundations.d.mts +67 -0
  371. package/dist/core/export-html/session-tree-foundations.mjs +313 -0
  372. package/dist/core/export-html/template.css +14 -41
  373. package/dist/core/export-html/template.html +3 -1
  374. package/dist/core/export-html/template.js +26 -435
  375. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  376. package/dist/core/export-html/tool-renderer.js.map +1 -1
  377. package/dist/core/extension-import-authority.d.ts.map +1 -1
  378. package/dist/core/extension-import-authority.js.map +1 -1
  379. package/dist/core/extension-metadata.d.ts.map +1 -1
  380. package/dist/core/extension-metadata.js.map +1 -1
  381. package/dist/core/extensions/builtin.d.ts +17 -0
  382. package/dist/core/extensions/builtin.d.ts.map +1 -1
  383. package/dist/core/extensions/builtin.js +18 -54
  384. package/dist/core/extensions/builtin.js.map +1 -1
  385. package/dist/core/extensions/entry-resolution.d.ts +3 -0
  386. package/dist/core/extensions/entry-resolution.d.ts.map +1 -0
  387. package/dist/core/extensions/entry-resolution.js +17 -0
  388. package/dist/core/extensions/entry-resolution.js.map +1 -0
  389. package/dist/core/extensions/index.d.ts.map +1 -1
  390. package/dist/core/extensions/loader.d.ts.map +1 -1
  391. package/dist/core/extensions/loader.js +76 -21
  392. package/dist/core/extensions/loader.js.map +1 -1
  393. package/dist/core/extensions/runner.d.ts +2 -0
  394. package/dist/core/extensions/runner.d.ts.map +1 -1
  395. package/dist/core/extensions/runner.js +41 -112
  396. package/dist/core/extensions/runner.js.map +1 -1
  397. package/dist/core/extensions/stale-context.d.ts.map +1 -1
  398. package/dist/core/extensions/storage.d.ts.map +1 -1
  399. package/dist/core/extensions/storage.js.map +1 -1
  400. package/dist/core/extensions/types.d.ts.map +1 -1
  401. package/dist/core/extensions/types.js.map +1 -1
  402. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  403. package/dist/core/extensions/wrapper.js.map +1 -1
  404. package/dist/core/failure-corpus.d.ts.map +1 -1
  405. package/dist/core/failure-corpus.js +2 -5
  406. package/dist/core/failure-corpus.js.map +1 -1
  407. package/dist/core/footer-data-provider.d.ts.map +1 -1
  408. package/dist/core/footer-data-provider.js +27 -33
  409. package/dist/core/footer-data-provider.js.map +1 -1
  410. package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
  411. package/dist/core/foreground-recovery-controller.js +0 -4
  412. package/dist/core/foreground-recovery-controller.js.map +1 -1
  413. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  414. package/dist/core/gateways/channel-provider.js +7 -5
  415. package/dist/core/gateways/channel-provider.js.map +1 -1
  416. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  417. package/dist/core/goal-loop-controller.js +0 -1
  418. package/dist/core/goal-loop-controller.js.map +1 -1
  419. package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
  420. package/dist/core/goals/compact-goal-context.js +2 -4
  421. package/dist/core/goals/compact-goal-context.js.map +1 -1
  422. package/dist/core/goals/goal-acceptance.d.ts.map +1 -1
  423. package/dist/core/goals/goal-acceptance.js.map +1 -1
  424. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
  425. package/dist/core/goals/goal-auto-continue-controller.js +1 -3
  426. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
  427. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  428. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  429. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  430. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  431. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  432. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
  433. package/dist/core/goals/goal-lifecycle.js.map +1 -1
  434. package/dist/core/goals/goal-record.d.ts.map +1 -1
  435. package/dist/core/goals/goal-record.js.map +1 -1
  436. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  437. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  438. package/dist/core/goals/goal-session-controller.d.ts +15 -0
  439. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  440. package/dist/core/goals/goal-session-controller.js +27 -3
  441. package/dist/core/goals/goal-session-controller.js.map +1 -1
  442. package/dist/core/goals/goal-state.d.ts.map +1 -1
  443. package/dist/core/goals/goal-state.js +35 -51
  444. package/dist/core/goals/goal-state.js.map +1 -1
  445. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  446. package/dist/core/goals/goal-tool-core.js.map +1 -1
  447. package/dist/core/goals/natural-language-goal.d.ts +9 -0
  448. package/dist/core/goals/natural-language-goal.d.ts.map +1 -0
  449. package/dist/core/goals/natural-language-goal.js +23 -0
  450. package/dist/core/goals/natural-language-goal.js.map +1 -0
  451. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  452. package/dist/core/goals/session-goal-state.js.map +1 -1
  453. package/dist/core/http-dispatcher.d.ts.map +1 -1
  454. package/dist/core/http-dispatcher.js.map +1 -1
  455. package/dist/core/human-input-controller.d.ts.map +1 -1
  456. package/dist/core/human-input-controller.js +2 -3
  457. package/dist/core/human-input-controller.js.map +1 -1
  458. package/dist/core/human-input.d.ts.map +1 -1
  459. package/dist/core/human-input.js.map +1 -1
  460. package/dist/core/improvement-loop.d.ts.map +1 -1
  461. package/dist/core/improvement-loop.js +11 -11
  462. package/dist/core/improvement-loop.js.map +1 -1
  463. package/dist/core/index.d.ts.map +1 -1
  464. package/dist/core/install-telemetry.d.ts.map +1 -1
  465. package/dist/core/install-telemetry.js.map +1 -1
  466. package/dist/core/isolated-text-completion.d.ts +17 -0
  467. package/dist/core/isolated-text-completion.d.ts.map +1 -0
  468. package/dist/core/isolated-text-completion.js +15 -0
  469. package/dist/core/isolated-text-completion.js.map +1 -0
  470. package/dist/core/keybindings.d.ts +47 -2
  471. package/dist/core/keybindings.d.ts.map +1 -1
  472. package/dist/core/keybindings.js +12 -1
  473. package/dist/core/keybindings.js.map +1 -1
  474. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  475. package/dist/core/learning/learning-audit.js.map +1 -1
  476. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  477. package/dist/core/learning/learning-gate.js.map +1 -1
  478. package/dist/core/learning/observation-store.d.ts.map +1 -1
  479. package/dist/core/learning/observation-store.js +0 -2
  480. package/dist/core/learning/observation-store.js.map +1 -1
  481. package/dist/core/learning/reflection-engine.d.ts +1 -1
  482. package/dist/core/learning/reflection-engine.d.ts.map +1 -1
  483. package/dist/core/learning/reflection-engine.js +3 -0
  484. package/dist/core/learning/reflection-engine.js.map +1 -1
  485. package/dist/core/learning/reflection-turn-analysis.d.ts +20 -0
  486. package/dist/core/learning/reflection-turn-analysis.d.ts.map +1 -0
  487. package/dist/core/learning/reflection-turn-analysis.js +136 -0
  488. package/dist/core/learning/reflection-turn-analysis.js.map +1 -0
  489. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  490. package/dist/core/learning/session-learning-decision.js.map +1 -1
  491. package/dist/core/learning/skill-curator.d.ts.map +1 -1
  492. package/dist/core/learning/skill-curator.js +0 -3
  493. package/dist/core/learning/skill-curator.js.map +1 -1
  494. package/dist/core/local-runtime-controller.d.ts +39 -0
  495. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  496. package/dist/core/local-runtime-controller.js +41 -62
  497. package/dist/core/local-runtime-controller.js.map +1 -1
  498. package/dist/core/memory/effectiveness-tracker.d.ts.map +1 -1
  499. package/dist/core/memory/effectiveness-tracker.js +4 -2
  500. package/dist/core/memory/effectiveness-tracker.js.map +1 -1
  501. package/dist/core/memory/memory-manager.d.ts.map +1 -1
  502. package/dist/core/memory/memory-manager.js +7 -7
  503. package/dist/core/memory/memory-manager.js.map +1 -1
  504. package/dist/core/memory/memory-provider.d.ts.map +1 -1
  505. package/dist/core/memory/providers/file-store.d.ts +7 -0
  506. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  507. package/dist/core/memory/providers/file-store.js +48 -13
  508. package/dist/core/memory/providers/file-store.js.map +1 -1
  509. package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts +47 -0
  510. package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts.map +1 -0
  511. package/dist/core/memory/providers/transcript-recall-worker-protocol.js +50 -0
  512. package/dist/core/memory/providers/transcript-recall-worker-protocol.js.map +1 -0
  513. package/dist/core/memory/providers/transcript-recall-worker.d.ts +2 -0
  514. package/dist/core/memory/providers/transcript-recall-worker.d.ts.map +1 -0
  515. package/dist/core/memory/providers/transcript-recall-worker.js +143 -0
  516. package/dist/core/memory/providers/transcript-recall-worker.js.map +1 -0
  517. package/dist/core/memory/providers/transcript-recall.d.ts +24 -13
  518. package/dist/core/memory/providers/transcript-recall.d.ts.map +1 -1
  519. package/dist/core/memory/providers/transcript-recall.js +143 -141
  520. package/dist/core/memory/providers/transcript-recall.js.map +1 -1
  521. package/dist/core/memory/providers/user-memory-archive.d.ts +39 -0
  522. package/dist/core/memory/providers/user-memory-archive.d.ts.map +1 -0
  523. package/dist/core/memory/providers/user-memory-archive.js +258 -0
  524. package/dist/core/memory/providers/user-memory-archive.js.map +1 -0
  525. package/dist/core/memory/transcript-index.d.ts.map +1 -1
  526. package/dist/core/memory/transcript-index.js +1 -1
  527. package/dist/core/memory/transcript-index.js.map +1 -1
  528. package/dist/core/memory-controller.d.ts +9 -0
  529. package/dist/core/memory-controller.d.ts.map +1 -1
  530. package/dist/core/memory-controller.js +57 -16
  531. package/dist/core/memory-controller.js.map +1 -1
  532. package/dist/core/model-capability.d.ts.map +1 -1
  533. package/dist/core/model-capability.js.map +1 -1
  534. package/dist/core/model-output-json.d.ts +10 -0
  535. package/dist/core/model-output-json.d.ts.map +1 -0
  536. package/dist/core/model-output-json.js +43 -0
  537. package/dist/core/model-output-json.js.map +1 -0
  538. package/dist/core/model-registry.d.ts +8 -8
  539. package/dist/core/model-registry.d.ts.map +1 -1
  540. package/dist/core/model-registry.js +29 -52
  541. package/dist/core/model-registry.js.map +1 -1
  542. package/dist/core/model-resolver.d.ts.map +1 -1
  543. package/dist/core/model-resolver.js +1 -1
  544. package/dist/core/model-resolver.js.map +1 -1
  545. package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
  546. package/dist/core/model-router/config-diagnostics.js.map +1 -1
  547. package/dist/core/model-router/executor-route.d.ts.map +1 -1
  548. package/dist/core/model-router/executor-route.js.map +1 -1
  549. package/dist/core/model-router/fitness-gate.d.ts.map +1 -1
  550. package/dist/core/model-router/fitness-gate.js.map +1 -1
  551. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  552. package/dist/core/model-router/route-judge.d.ts.map +1 -1
  553. package/dist/core/model-router/route-judge.js +18 -36
  554. package/dist/core/model-router/route-judge.js.map +1 -1
  555. package/dist/core/model-router/session-buffer.d.ts.map +1 -1
  556. package/dist/core/model-router/session-buffer.js.map +1 -1
  557. package/dist/core/model-router/status.d.ts.map +1 -1
  558. package/dist/core/model-router/status.js.map +1 -1
  559. package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
  560. package/dist/core/model-router/tool-escalation.js.map +1 -1
  561. package/dist/core/model-router-controller.d.ts +1 -0
  562. package/dist/core/model-router-controller.d.ts.map +1 -1
  563. package/dist/core/model-router-controller.js +25 -56
  564. package/dist/core/model-router-controller.js.map +1 -1
  565. package/dist/core/model-selection-controller.d.ts +10 -0
  566. package/dist/core/model-selection-controller.d.ts.map +1 -1
  567. package/dist/core/model-selection-controller.js +0 -1
  568. package/dist/core/model-selection-controller.js.map +1 -1
  569. package/dist/core/model-tool-protocol.d.ts.map +1 -1
  570. package/dist/core/model-tool-protocol.js.map +1 -1
  571. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  572. package/dist/core/models/adaptation-store.js +0 -1
  573. package/dist/core/models/adaptation-store.js.map +1 -1
  574. package/dist/core/models/context-sizing.d.ts.map +1 -1
  575. package/dist/core/models/context-sizing.js.map +1 -1
  576. package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
  577. package/dist/core/models/default-model-suggestions.js.map +1 -1
  578. package/dist/core/models/fitness-store.d.ts.map +1 -1
  579. package/dist/core/models/fitness-store.js +0 -1
  580. package/dist/core/models/fitness-store.js.map +1 -1
  581. package/dist/core/models/host-state-store.d.ts.map +1 -1
  582. package/dist/core/models/host-state-store.js +1 -6
  583. package/dist/core/models/host-state-store.js.map +1 -1
  584. package/dist/core/models/llamacpp-runtime.d.ts +4 -19
  585. package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
  586. package/dist/core/models/llamacpp-runtime.js +32 -136
  587. package/dist/core/models/llamacpp-runtime.js.map +1 -1
  588. package/dist/core/models/local-registration.d.ts.map +1 -1
  589. package/dist/core/models/local-registration.js +82 -115
  590. package/dist/core/models/local-registration.js.map +1 -1
  591. package/dist/core/models/local-runtime.d.ts +12 -18
  592. package/dist/core/models/local-runtime.d.ts.map +1 -1
  593. package/dist/core/models/local-runtime.js +60 -204
  594. package/dist/core/models/local-runtime.js.map +1 -1
  595. package/dist/core/models/model-endpoint.d.ts +3 -0
  596. package/dist/core/models/model-endpoint.d.ts.map +1 -0
  597. package/dist/core/models/model-endpoint.js +11 -0
  598. package/dist/core/models/model-endpoint.js.map +1 -0
  599. package/dist/core/models/model-ref.d.ts.map +1 -1
  600. package/dist/core/models/model-ref.js.map +1 -1
  601. package/dist/core/models/needle-runtime.d.ts +7 -3
  602. package/dist/core/models/needle-runtime.d.ts.map +1 -1
  603. package/dist/core/models/needle-runtime.js +16 -92
  604. package/dist/core/models/needle-runtime.js.map +1 -1
  605. package/dist/core/models/perf-profile.d.ts +1 -1
  606. package/dist/core/models/perf-profile.d.ts.map +1 -1
  607. package/dist/core/models/perf-profile.js +6 -13
  608. package/dist/core/models/perf-profile.js.map +1 -1
  609. package/dist/core/models/prism-llamacpp-lifecycle.d.ts.map +1 -1
  610. package/dist/core/models/prism-llamacpp-lifecycle.js.map +1 -1
  611. package/dist/core/models/runtime-arbiter.d.ts.map +1 -1
  612. package/dist/core/models/runtime-arbiter.js +3 -15
  613. package/dist/core/models/runtime-arbiter.js.map +1 -1
  614. package/dist/core/models/runtime-process.d.ts +100 -0
  615. package/dist/core/models/runtime-process.d.ts.map +1 -0
  616. package/dist/core/models/runtime-process.js +183 -0
  617. package/dist/core/models/runtime-process.js.map +1 -0
  618. package/dist/core/orchestration/agent-resume.d.ts +2 -0
  619. package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
  620. package/dist/core/orchestration/agent-resume.js +7 -0
  621. package/dist/core/orchestration/agent-resume.js.map +1 -1
  622. package/dist/core/orchestration/attempt-usage.d.ts +28 -0
  623. package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
  624. package/dist/core/orchestration/attempt-usage.js +168 -0
  625. package/dist/core/orchestration/attempt-usage.js.map +1 -0
  626. package/dist/core/orchestration/capability-gateway.d.ts +19 -1
  627. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  628. package/dist/core/orchestration/capability-gateway.js +120 -34
  629. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  630. package/dist/core/orchestration/contracts.d.ts +35 -0
  631. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  632. package/dist/core/orchestration/contracts.js +17 -0
  633. package/dist/core/orchestration/contracts.js.map +1 -1
  634. package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
  635. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  636. package/dist/core/orchestration/delegation-ledger.js +78 -5
  637. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  638. package/dist/core/orchestration/event-store.d.ts +1 -0
  639. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  640. package/dist/core/orchestration/event-store.js +79 -52
  641. package/dist/core/orchestration/event-store.js.map +1 -1
  642. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  643. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  644. package/dist/core/orchestration/model-binding.d.ts.map +1 -1
  645. package/dist/core/orchestration/model-binding.js.map +1 -1
  646. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
  647. package/dist/core/orchestration/policy-compiler.js +0 -3
  648. package/dist/core/orchestration/policy-compiler.js.map +1 -1
  649. package/dist/core/orchestration/policy-gate.d.ts.map +1 -1
  650. package/dist/core/orchestration/policy-gate.js +0 -2
  651. package/dist/core/orchestration/policy-gate.js.map +1 -1
  652. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  653. package/dist/core/orchestration/profile-registry.js +82 -42
  654. package/dist/core/orchestration/profile-registry.js.map +1 -1
  655. package/dist/core/orchestration/profile-store.d.ts.map +1 -1
  656. package/dist/core/orchestration/profile-store.js +18 -7
  657. package/dist/core/orchestration/profile-store.js.map +1 -1
  658. package/dist/core/orchestration/risk-budget.d.ts +2 -0
  659. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  660. package/dist/core/orchestration/risk-budget.js +26 -0
  661. package/dist/core/orchestration/risk-budget.js.map +1 -1
  662. package/dist/core/orchestration/task-runtime.d.ts +14 -1
  663. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  664. package/dist/core/orchestration/task-runtime.js +153 -57
  665. package/dist/core/orchestration/task-runtime.js.map +1 -1
  666. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
  667. package/dist/core/orchestration/work-state-projection.js.map +1 -1
  668. package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
  669. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  670. package/dist/core/orchestration/worker-execution-contract.js +75 -23
  671. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  672. package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
  673. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
  674. package/dist/core/orchestration/worker-result-adapter.js +167 -14
  675. package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
  676. package/dist/core/output-guard.d.ts.map +1 -1
  677. package/dist/core/output-guard.js.map +1 -1
  678. package/dist/core/package-manager.d.ts +3 -0
  679. package/dist/core/package-manager.d.ts.map +1 -1
  680. package/dist/core/package-manager.js +88 -353
  681. package/dist/core/package-manager.js.map +1 -1
  682. package/dist/core/process-identity.d.ts.map +1 -1
  683. package/dist/core/process-identity.js.map +1 -1
  684. package/dist/core/process-liveness.d.ts +3 -0
  685. package/dist/core/process-liveness.d.ts.map +1 -0
  686. package/dist/core/process-liveness.js +17 -0
  687. package/dist/core/process-liveness.js.map +1 -0
  688. package/dist/core/process-matrix/codes.d.ts.map +1 -1
  689. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -1
  690. package/dist/core/process-matrix/resume-launcher.js.map +1 -1
  691. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  692. package/dist/core/process-matrix/runtime.js.map +1 -1
  693. package/dist/core/process-matrix/store.d.ts.map +1 -1
  694. package/dist/core/process-matrix/store.js.map +1 -1
  695. package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
  696. package/dist/core/process-matrix/supervisor.js.map +1 -1
  697. package/dist/core/profile-filter-controller.d.ts.map +1 -1
  698. package/dist/core/profile-filter-controller.js +7 -8
  699. package/dist/core/profile-filter-controller.js.map +1 -1
  700. package/dist/core/profile-registry.d.ts.map +1 -1
  701. package/dist/core/profile-registry.js +1 -2
  702. package/dist/core/profile-registry.js.map +1 -1
  703. package/dist/core/profile-resource-selection.d.ts.map +1 -1
  704. package/dist/core/profile-resource-selection.js +18 -59
  705. package/dist/core/profile-resource-selection.js.map +1 -1
  706. package/dist/core/prompt-markup.d.ts +3 -0
  707. package/dist/core/prompt-markup.d.ts.map +1 -0
  708. package/dist/core/prompt-markup.js +7 -0
  709. package/dist/core/prompt-markup.js.map +1 -0
  710. package/dist/core/prompt-templates.d.ts.map +1 -1
  711. package/dist/core/prompt-templates.js +13 -39
  712. package/dist/core/prompt-templates.js.map +1 -1
  713. package/dist/core/provider-display-names.d.ts.map +1 -1
  714. package/dist/core/python-runtime.d.ts.map +1 -1
  715. package/dist/core/python-runtime.js.map +1 -1
  716. package/dist/core/reflection-controller.d.ts +23 -2
  717. package/dist/core/reflection-controller.d.ts.map +1 -1
  718. package/dist/core/reflection-controller.js +233 -79
  719. package/dist/core/reflection-controller.js.map +1 -1
  720. package/dist/core/reload-blockers.d.ts +2 -1
  721. package/dist/core/reload-blockers.d.ts.map +1 -1
  722. package/dist/core/reload-blockers.js +4 -14
  723. package/dist/core/reload-blockers.js.map +1 -1
  724. package/dist/core/request-auth.d.ts.map +1 -1
  725. package/dist/core/request-auth.js.map +1 -1
  726. package/dist/core/research/automata-provider.d.ts.map +1 -1
  727. package/dist/core/research/automata-provider.js.map +1 -1
  728. package/dist/core/research/evidence-bundle.d.ts +20 -0
  729. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  730. package/dist/core/research/evidence-bundle.js +173 -69
  731. package/dist/core/research/evidence-bundle.js.map +1 -1
  732. package/dist/core/research/lane-model-resolver.d.ts.map +1 -1
  733. package/dist/core/research/lane-model-resolver.js +0 -1
  734. package/dist/core/research/lane-model-resolver.js.map +1 -1
  735. package/dist/core/research/model-fitness-controller.d.ts.map +1 -1
  736. package/dist/core/research/model-fitness-controller.js +17 -33
  737. package/dist/core/research/model-fitness-controller.js.map +1 -1
  738. package/dist/core/research/model-fitness.d.ts.map +1 -1
  739. package/dist/core/research/model-fitness.js +4 -25
  740. package/dist/core/research/model-fitness.js.map +1 -1
  741. package/dist/core/research/research-gate.d.ts.map +1 -1
  742. package/dist/core/research/research-gate.js.map +1 -1
  743. package/dist/core/research/research-lane-controller.d.ts.map +1 -1
  744. package/dist/core/research/research-lane-controller.js +5 -10
  745. package/dist/core/research/research-lane-controller.js.map +1 -1
  746. package/dist/core/research/research-runner.d.ts +2 -4
  747. package/dist/core/research/research-runner.d.ts.map +1 -1
  748. package/dist/core/research/research-runner.js +17 -48
  749. package/dist/core/research/research-runner.js.map +1 -1
  750. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  751. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  752. package/dist/core/research/workspace-collector.d.ts.map +1 -1
  753. package/dist/core/research/workspace-collector.js.map +1 -1
  754. package/dist/core/resolve-config-value.d.ts.map +1 -1
  755. package/dist/core/resolve-config-value.js.map +1 -1
  756. package/dist/core/resource-ignore.d.ts +6 -0
  757. package/dist/core/resource-ignore.d.ts.map +1 -0
  758. package/dist/core/resource-ignore.js +44 -0
  759. package/dist/core/resource-ignore.js.map +1 -0
  760. package/dist/core/resource-loader.d.ts +0 -1
  761. package/dist/core/resource-loader.d.ts.map +1 -1
  762. package/dist/core/resource-loader.js +52 -187
  763. package/dist/core/resource-loader.js.map +1 -1
  764. package/dist/core/resource-profile-blocks.d.ts +3 -1
  765. package/dist/core/resource-profile-blocks.d.ts.map +1 -1
  766. package/dist/core/resource-profile-blocks.js +8 -5
  767. package/dist/core/resource-profile-blocks.js.map +1 -1
  768. package/dist/core/resource-profile-equality.d.ts.map +1 -1
  769. package/dist/core/resource-profile-equality.js.map +1 -1
  770. package/dist/core/resource-traversal.d.ts +43 -0
  771. package/dist/core/resource-traversal.d.ts.map +1 -0
  772. package/dist/core/resource-traversal.js +84 -0
  773. package/dist/core/resource-traversal.js.map +1 -0
  774. package/dist/core/risk-classifier.d.ts.map +1 -1
  775. package/dist/core/risk-classifier.js.map +1 -1
  776. package/dist/core/runtime-builder.d.ts +11 -1
  777. package/dist/core/runtime-builder.d.ts.map +1 -1
  778. package/dist/core/runtime-builder.js +40 -51
  779. package/dist/core/runtime-builder.js.map +1 -1
  780. package/dist/core/scout-controller.d.ts.map +1 -1
  781. package/dist/core/scout-controller.js +0 -1
  782. package/dist/core/scout-controller.js.map +1 -1
  783. package/dist/core/sdk.d.ts.map +1 -1
  784. package/dist/core/sdk.js.map +1 -1
  785. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
  786. package/dist/core/secrets/credential-exposure-guard.js +70 -44
  787. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  788. package/dist/core/secrets/secret-dotenv.d.ts.map +1 -1
  789. package/dist/core/secrets/secret-dotenv.js +0 -1
  790. package/dist/core/secrets/secret-dotenv.js.map +1 -1
  791. package/dist/core/secrets/secret-vault-format.d.ts.map +1 -1
  792. package/dist/core/secrets/secret-vault-format.js +0 -1
  793. package/dist/core/secrets/secret-vault-format.js.map +1 -1
  794. package/dist/core/secrets/secret-vault.d.ts.map +1 -1
  795. package/dist/core/secrets/secret-vault.js +2 -10
  796. package/dist/core/secrets/secret-vault.js.map +1 -1
  797. package/dist/core/security/secret-text.d.ts.map +1 -1
  798. package/dist/core/security/secret-text.js.map +1 -1
  799. package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
  800. package/dist/core/security/untrusted-boundary.js.map +1 -1
  801. package/dist/core/session-analytics.d.ts.map +1 -1
  802. package/dist/core/session-analytics.js +18 -50
  803. package/dist/core/session-analytics.js.map +1 -1
  804. package/dist/core/session-artifact-bundle.d.ts +35 -0
  805. package/dist/core/session-artifact-bundle.d.ts.map +1 -0
  806. package/dist/core/session-artifact-bundle.js +61 -0
  807. package/dist/core/session-artifact-bundle.js.map +1 -0
  808. package/dist/core/session-cwd.d.ts.map +1 -1
  809. package/dist/core/session-cwd.js +0 -1
  810. package/dist/core/session-cwd.js.map +1 -1
  811. package/dist/core/session-entry-index.d.ts +8 -0
  812. package/dist/core/session-entry-index.d.ts.map +1 -0
  813. package/dist/core/session-entry-index.js +16 -0
  814. package/dist/core/session-entry-index.js.map +1 -0
  815. package/dist/core/session-image-store.d.ts.map +1 -1
  816. package/dist/core/session-image-store.js +0 -3
  817. package/dist/core/session-image-store.js.map +1 -1
  818. package/dist/core/session-jsonl-writer.d.ts +3 -0
  819. package/dist/core/session-jsonl-writer.d.ts.map +1 -0
  820. package/dist/core/session-jsonl-writer.js +38 -0
  821. package/dist/core/session-jsonl-writer.js.map +1 -0
  822. package/dist/core/session-manager-factory.d.ts.map +1 -1
  823. package/dist/core/session-manager-factory.js.map +1 -1
  824. package/dist/core/session-role.d.ts.map +1 -1
  825. package/dist/core/session-role.js.map +1 -1
  826. package/dist/core/session-snapshot.d.ts.map +1 -1
  827. package/dist/core/session-snapshot.js.map +1 -1
  828. package/dist/core/session-supervision-runtime.d.ts.map +1 -1
  829. package/dist/core/session-supervision-runtime.js +1 -4
  830. package/dist/core/session-supervision-runtime.js.map +1 -1
  831. package/dist/core/session-tree-navigator.d.ts.map +1 -1
  832. package/dist/core/session-tree-navigator.js +0 -1
  833. package/dist/core/session-tree-navigator.js.map +1 -1
  834. package/dist/core/settings-manager.d.ts +2 -1
  835. package/dist/core/settings-manager.d.ts.map +1 -1
  836. package/dist/core/settings-manager.js +64 -162
  837. package/dist/core/settings-manager.js.map +1 -1
  838. package/dist/core/skill-block.d.mts +8 -0
  839. package/dist/core/skill-block.mjs +52 -0
  840. package/dist/core/skill-discovery.d.ts +5 -0
  841. package/dist/core/skill-discovery.d.ts.map +1 -0
  842. package/dist/core/skill-discovery.js +34 -0
  843. package/dist/core/skill-discovery.js.map +1 -0
  844. package/dist/core/skills.d.ts.map +1 -1
  845. package/dist/core/skills.js +23 -159
  846. package/dist/core/skills.js.map +1 -1
  847. package/dist/core/slash-commands.d.ts.map +1 -1
  848. package/dist/core/source-info.d.ts.map +1 -1
  849. package/dist/core/source-info.js.map +1 -1
  850. package/dist/core/spawned-usage.d.ts +21 -0
  851. package/dist/core/spawned-usage.d.ts.map +1 -0
  852. package/dist/core/spawned-usage.js +29 -0
  853. package/dist/core/spawned-usage.js.map +1 -0
  854. package/dist/core/system-prompt-builder.d.ts +4 -0
  855. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  856. package/dist/core/system-prompt-builder.js +15 -8
  857. package/dist/core/system-prompt-builder.js.map +1 -1
  858. package/dist/core/system-prompt.d.ts.map +1 -1
  859. package/dist/core/system-prompt.js +52 -35
  860. package/dist/core/system-prompt.js.map +1 -1
  861. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  862. package/dist/core/tasks/session-task-state.js.map +1 -1
  863. package/dist/core/tasks/task-command.d.ts.map +1 -1
  864. package/dist/core/tasks/task-command.js.map +1 -1
  865. package/dist/core/tasks/task-contract-monitor.d.ts.map +1 -1
  866. package/dist/core/tasks/task-contract-monitor.js.map +1 -1
  867. package/dist/core/tasks/task-projection.d.ts.map +1 -1
  868. package/dist/core/tasks/task-projection.js.map +1 -1
  869. package/dist/core/tasks/task-state.d.ts.map +1 -1
  870. package/dist/core/tasks/task-state.js.map +1 -1
  871. package/dist/core/text-preview.d.ts +4 -0
  872. package/dist/core/text-preview.d.ts.map +1 -0
  873. package/dist/core/text-preview.js +33 -0
  874. package/dist/core/text-preview.js.map +1 -0
  875. package/dist/core/timings.d.ts.map +1 -1
  876. package/dist/core/timings.js.map +1 -1
  877. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  878. package/dist/core/tool-capability-policy.js.map +1 -1
  879. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  880. package/dist/core/tool-gate-controller.js +86 -87
  881. package/dist/core/tool-gate-controller.js.map +1 -1
  882. package/dist/core/tool-protocol-controller.d.ts +4 -1
  883. package/dist/core/tool-protocol-controller.d.ts.map +1 -1
  884. package/dist/core/tool-protocol-controller.js +19 -23
  885. package/dist/core/tool-protocol-controller.js.map +1 -1
  886. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  887. package/dist/core/tool-recovery-log-records.js.map +1 -1
  888. package/dist/core/tool-recovery-log-worker.d.ts.map +1 -1
  889. package/dist/core/tool-recovery-log-worker.js.map +1 -1
  890. package/dist/core/tool-recovery-logger.d.ts.map +1 -1
  891. package/dist/core/tool-recovery-logger.js +12 -24
  892. package/dist/core/tool-recovery-logger.js.map +1 -1
  893. package/dist/core/tool-recovery-stats.d.ts.map +1 -1
  894. package/dist/core/tool-recovery-stats.js +16 -22
  895. package/dist/core/tool-recovery-stats.js.map +1 -1
  896. package/dist/core/tool-repair-health.d.ts.map +1 -1
  897. package/dist/core/tool-repair-health.js.map +1 -1
  898. package/dist/core/tool-repair-settings.d.ts.map +1 -1
  899. package/dist/core/tool-repair-settings.js.map +1 -1
  900. package/dist/core/tool-selection/expected-utility.d.ts.map +1 -1
  901. package/dist/core/tool-selection/expected-utility.js.map +1 -1
  902. package/dist/core/tool-selection/promotion.d.ts.map +1 -1
  903. package/dist/core/tool-selection/promotion.js.map +1 -1
  904. package/dist/core/tool-selection/tool-performance-store.d.ts +2 -0
  905. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  906. package/dist/core/tool-selection/tool-performance-store.js +49 -7
  907. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  908. package/dist/core/tool-selection/tool-phase-timing.d.ts +19 -0
  909. package/dist/core/tool-selection/tool-phase-timing.d.ts.map +1 -0
  910. package/dist/core/tool-selection/tool-phase-timing.js +63 -0
  911. package/dist/core/tool-selection/tool-phase-timing.js.map +1 -0
  912. package/dist/core/tool-selection/tool-selection-controller.d.ts +2 -5
  913. package/dist/core/tool-selection/tool-selection-controller.d.ts.map +1 -1
  914. package/dist/core/tool-selection/tool-selection-controller.js +50 -30
  915. package/dist/core/tool-selection/tool-selection-controller.js.map +1 -1
  916. package/dist/core/toolkit/reflex-interpreter.d.ts +16 -0
  917. package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
  918. package/dist/core/toolkit/reflex-interpreter.js +21 -0
  919. package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
  920. package/dist/core/toolkit/script-registry.d.ts.map +1 -1
  921. package/dist/core/toolkit/script-registry.js.map +1 -1
  922. package/dist/core/toolkit/script-runner.d.ts.map +1 -1
  923. package/dist/core/toolkit/script-runner.js.map +1 -1
  924. package/dist/core/tools/artifact-retrieve.d.ts.map +1 -1
  925. package/dist/core/tools/artifact-retrieve.js.map +1 -1
  926. package/dist/core/tools/ask-question.d.ts +2 -3
  927. package/dist/core/tools/ask-question.d.ts.map +1 -1
  928. package/dist/core/tools/ask-question.js +14 -40
  929. package/dist/core/tools/ask-question.js.map +1 -1
  930. package/dist/core/tools/bash.d.ts +2 -0
  931. package/dist/core/tools/bash.d.ts.map +1 -1
  932. package/dist/core/tools/bash.js +83 -30
  933. package/dist/core/tools/bash.js.map +1 -1
  934. package/dist/core/tools/context-scout.d.ts.map +1 -1
  935. package/dist/core/tools/context-scout.js.map +1 -1
  936. package/dist/core/tools/delegate-status.d.ts +6 -1
  937. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  938. package/dist/core/tools/delegate-status.js +109 -25
  939. package/dist/core/tools/delegate-status.js.map +1 -1
  940. package/dist/core/tools/delegate.d.ts +9 -1
  941. package/dist/core/tools/delegate.d.ts.map +1 -1
  942. package/dist/core/tools/delegate.js +329 -67
  943. package/dist/core/tools/delegate.js.map +1 -1
  944. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  945. package/dist/core/tools/edit-diff.js.map +1 -1
  946. package/dist/core/tools/edit.d.ts.map +1 -1
  947. package/dist/core/tools/edit.js.map +1 -1
  948. package/dist/core/tools/extensionify.d.ts.map +1 -1
  949. package/dist/core/tools/extensionify.js.map +1 -1
  950. package/dist/core/tools/fff-search-backend.d.ts +19 -0
  951. package/dist/core/tools/fff-search-backend.d.ts.map +1 -1
  952. package/dist/core/tools/fff-search-backend.js +28 -2
  953. package/dist/core/tools/fff-search-backend.js.map +1 -1
  954. package/dist/core/tools/file-encoding-policy.d.ts.map +1 -1
  955. package/dist/core/tools/file-encoding-policy.js.map +1 -1
  956. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  957. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  958. package/dist/core/tools/find.d.ts +1 -1
  959. package/dist/core/tools/find.d.ts.map +1 -1
  960. package/dist/core/tools/find.js +44 -108
  961. package/dist/core/tools/find.js.map +1 -1
  962. package/dist/core/tools/git-filter.d.ts.map +1 -1
  963. package/dist/core/tools/git-filter.js.map +1 -1
  964. package/dist/core/tools/goal.d.ts.map +1 -1
  965. package/dist/core/tools/goal.js +7 -7
  966. package/dist/core/tools/goal.js.map +1 -1
  967. package/dist/core/tools/grep.d.ts +1 -1
  968. package/dist/core/tools/grep.d.ts.map +1 -1
  969. package/dist/core/tools/grep.js +42 -102
  970. package/dist/core/tools/grep.js.map +1 -1
  971. package/dist/core/tools/index.d.ts.map +1 -1
  972. package/dist/core/tools/index.js.map +1 -1
  973. package/dist/core/tools/ls.d.ts.map +1 -1
  974. package/dist/core/tools/ls.js +20 -36
  975. package/dist/core/tools/ls.js.map +1 -1
  976. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  977. package/dist/core/tools/model-fitness.js.map +1 -1
  978. package/dist/core/tools/orchestration-panel.d.ts +5 -0
  979. package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
  980. package/dist/core/tools/orchestration-panel.js +5 -5
  981. package/dist/core/tools/orchestration-panel.js.map +1 -1
  982. package/dist/core/tools/output-accumulator.d.ts +2 -0
  983. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  984. package/dist/core/tools/output-accumulator.js +24 -36
  985. package/dist/core/tools/output-accumulator.js.map +1 -1
  986. package/dist/core/tools/path-utils.d.ts.map +1 -1
  987. package/dist/core/tools/path-utils.js.map +1 -1
  988. package/dist/core/tools/persistent-process-coordinator.d.ts +31 -0
  989. package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -0
  990. package/dist/core/tools/persistent-process-coordinator.js +123 -0
  991. package/dist/core/tools/persistent-process-coordinator.js.map +1 -0
  992. package/dist/core/tools/python.d.ts.map +1 -1
  993. package/dist/core/tools/python.js.map +1 -1
  994. package/dist/core/tools/read.d.ts.map +1 -1
  995. package/dist/core/tools/read.js +14 -13
  996. package/dist/core/tools/read.js.map +1 -1
  997. package/dist/core/tools/render-utils.d.ts +29 -0
  998. package/dist/core/tools/render-utils.d.ts.map +1 -1
  999. package/dist/core/tools/render-utils.js +31 -1
  1000. package/dist/core/tools/render-utils.js.map +1 -1
  1001. package/dist/core/tools/run-process.d.ts +1 -1
  1002. package/dist/core/tools/run-process.d.ts.map +1 -1
  1003. package/dist/core/tools/run-process.js +69 -9
  1004. package/dist/core/tools/run-process.js.map +1 -1
  1005. package/dist/core/tools/run-toolkit-script.d.ts.map +1 -1
  1006. package/dist/core/tools/run-toolkit-script.js.map +1 -1
  1007. package/dist/core/tools/search-command-guard.d.ts +10 -0
  1008. package/dist/core/tools/search-command-guard.d.ts.map +1 -1
  1009. package/dist/core/tools/search-command-guard.js +118 -31
  1010. package/dist/core/tools/search-command-guard.js.map +1 -1
  1011. package/dist/core/tools/search-router.d.ts.map +1 -1
  1012. package/dist/core/tools/search-router.js.map +1 -1
  1013. package/dist/core/tools/search-tool-runtime.d.ts +19 -0
  1014. package/dist/core/tools/search-tool-runtime.d.ts.map +1 -0
  1015. package/dist/core/tools/search-tool-runtime.js +12 -0
  1016. package/dist/core/tools/search-tool-runtime.js.map +1 -0
  1017. package/dist/core/tools/secret-store.d.ts.map +1 -1
  1018. package/dist/core/tools/secret-store.js.map +1 -1
  1019. package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
  1020. package/dist/core/tools/shell-command-parser.js.map +1 -1
  1021. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  1022. package/dist/core/tools/shell-contract-router.js +16 -6
  1023. package/dist/core/tools/shell-contract-router.js.map +1 -1
  1024. package/dist/core/tools/shell-execution-session.d.ts +4 -0
  1025. package/dist/core/tools/shell-execution-session.d.ts.map +1 -0
  1026. package/dist/core/tools/shell-execution-session.js +11 -0
  1027. package/dist/core/tools/shell-execution-session.js.map +1 -0
  1028. package/dist/core/tools/shell-output-projection.d.ts +49 -0
  1029. package/dist/core/tools/shell-output-projection.d.ts.map +1 -0
  1030. package/dist/core/tools/shell-output-projection.js +381 -0
  1031. package/dist/core/tools/shell-output-projection.js.map +1 -0
  1032. package/dist/core/tools/shell-session.d.ts +2 -13
  1033. package/dist/core/tools/shell-session.d.ts.map +1 -1
  1034. package/dist/core/tools/shell-session.js +36 -136
  1035. package/dist/core/tools/shell-session.js.map +1 -1
  1036. package/dist/core/tools/skill-audit.d.ts.map +1 -1
  1037. package/dist/core/tools/skill-audit.js.map +1 -1
  1038. package/dist/core/tools/skillify.d.ts.map +1 -1
  1039. package/dist/core/tools/skillify.js.map +1 -1
  1040. package/dist/core/tools/task-steps.d.ts +8 -8
  1041. package/dist/core/tools/task-steps.d.ts.map +1 -1
  1042. package/dist/core/tools/task-steps.js +17 -18
  1043. package/dist/core/tools/task-steps.js.map +1 -1
  1044. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  1045. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  1046. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  1047. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  1048. package/dist/core/tools/tool-task.d.ts +23 -0
  1049. package/dist/core/tools/tool-task.d.ts.map +1 -0
  1050. package/dist/core/tools/tool-task.js +93 -0
  1051. package/dist/core/tools/tool-task.js.map +1 -0
  1052. package/dist/core/tools/windows-shell-engine.d.ts +17 -11
  1053. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  1054. package/dist/core/tools/windows-shell-engine.js +339 -117
  1055. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  1056. package/dist/core/tools/windows-shell-state.d.ts.map +1 -1
  1057. package/dist/core/tools/windows-shell-state.js.map +1 -1
  1058. package/dist/core/tools/worktree-sync.d.ts.map +1 -1
  1059. package/dist/core/tools/worktree-sync.js +8 -12
  1060. package/dist/core/tools/worktree-sync.js.map +1 -1
  1061. package/dist/core/tools/write.d.ts.map +1 -1
  1062. package/dist/core/tools/write.js +0 -1
  1063. package/dist/core/tools/write.js.map +1 -1
  1064. package/dist/core/trust-manager.d.ts.map +1 -1
  1065. package/dist/core/trust-manager.js +7 -40
  1066. package/dist/core/trust-manager.js.map +1 -1
  1067. package/dist/core/util/atomic-file.d.ts +19 -0
  1068. package/dist/core/util/atomic-file.d.ts.map +1 -1
  1069. package/dist/core/util/atomic-file.js +50 -15
  1070. package/dist/core/util/atomic-file.js.map +1 -1
  1071. package/dist/core/util/bounded-file.d.ts +15 -0
  1072. package/dist/core/util/bounded-file.d.ts.map +1 -0
  1073. package/dist/core/util/bounded-file.js +120 -0
  1074. package/dist/core/util/bounded-file.js.map +1 -0
  1075. package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
  1076. package/dist/core/util/bounded-jsonl.js +112 -9
  1077. package/dist/core/util/bounded-jsonl.js.map +1 -1
  1078. package/dist/core/util/bounded-value.d.ts +3 -0
  1079. package/dist/core/util/bounded-value.d.ts.map +1 -0
  1080. package/dist/core/util/bounded-value.js +12 -0
  1081. package/dist/core/util/bounded-value.js.map +1 -0
  1082. package/dist/core/util/json-size.d.ts +3 -0
  1083. package/dist/core/util/json-size.d.ts.map +1 -0
  1084. package/dist/core/util/json-size.js +95 -0
  1085. package/dist/core/util/json-size.js.map +1 -0
  1086. package/dist/core/util/minimatch-cache.d.ts.map +1 -1
  1087. package/dist/core/util/minimatch-cache.js.map +1 -1
  1088. package/dist/core/util/value-guards.d.ts +2 -0
  1089. package/dist/core/util/value-guards.d.ts.map +1 -1
  1090. package/dist/core/util/value-guards.js +5 -0
  1091. package/dist/core/util/value-guards.js.map +1 -1
  1092. package/dist/core/worktree-sync/codes.d.ts.map +1 -1
  1093. package/dist/core/worktree-sync/git-engine.d.ts.map +1 -1
  1094. package/dist/core/worktree-sync/git-engine.js +20 -36
  1095. package/dist/core/worktree-sync/git-engine.js.map +1 -1
  1096. package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -1
  1097. package/dist/core/worktree-sync/lane-gate.js +1 -4
  1098. package/dist/core/worktree-sync/lane-gate.js.map +1 -1
  1099. package/dist/core/worktree-sync/runtime.d.ts.map +1 -1
  1100. package/dist/core/worktree-sync/runtime.js.map +1 -1
  1101. package/dist/core/worktree-sync/store.d.ts.map +1 -1
  1102. package/dist/core/worktree-sync/store.js.map +1 -1
  1103. package/dist/core/worktree-sync/watcher.d.ts.map +1 -1
  1104. package/dist/core/worktree-sync/watcher.js.map +1 -1
  1105. package/dist/index.d.ts.map +1 -1
  1106. package/dist/index.js.map +1 -1
  1107. package/dist/main.d.ts.map +1 -1
  1108. package/dist/main.js +10 -32
  1109. package/dist/main.js.map +1 -1
  1110. package/dist/migrations.d.ts.map +1 -1
  1111. package/dist/migrations.js +6 -19
  1112. package/dist/migrations.js.map +1 -1
  1113. package/dist/modes/index.d.ts.map +1 -1
  1114. package/dist/modes/interactive/auth-dialogs-controller.d.ts +3 -0
  1115. package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
  1116. package/dist/modes/interactive/auth-dialogs-controller.js +96 -132
  1117. package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
  1118. package/dist/modes/interactive/auto-learn-controller.d.ts +1 -31
  1119. package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
  1120. package/dist/modes/interactive/auto-learn-controller.js +86 -307
  1121. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  1122. package/dist/modes/interactive/autocomplete-provider.d.ts.map +1 -1
  1123. package/dist/modes/interactive/autocomplete-provider.js.map +1 -1
  1124. package/dist/modes/interactive/autonomy-commands.d.ts.map +1 -1
  1125. package/dist/modes/interactive/autonomy-commands.js +2 -8
  1126. package/dist/modes/interactive/autonomy-commands.js.map +1 -1
  1127. package/dist/modes/interactive/clipboard-input.d.ts +5 -1
  1128. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  1129. package/dist/modes/interactive/clipboard-input.js +17 -0
  1130. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  1131. package/dist/modes/interactive/compaction-queue.d.ts.map +1 -1
  1132. package/dist/modes/interactive/compaction-queue.js +13 -18
  1133. package/dist/modes/interactive/compaction-queue.js.map +1 -1
  1134. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
  1135. package/dist/modes/interactive/components/activity-lane.js +6 -10
  1136. package/dist/modes/interactive/components/activity-lane.js.map +1 -1
  1137. package/dist/modes/interactive/components/armin.d.ts +1 -0
  1138. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  1139. package/dist/modes/interactive/components/armin.js +10 -21
  1140. package/dist/modes/interactive/components/armin.js.map +1 -1
  1141. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  1142. package/dist/modes/interactive/components/assistant-message.js +1 -6
  1143. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  1144. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  1145. package/dist/modes/interactive/components/bash-execution.js +4 -9
  1146. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  1147. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  1148. package/dist/modes/interactive/components/bordered-loader.js +0 -3
  1149. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  1150. package/dist/modes/interactive/components/branch-summary-message.d.ts +3 -8
  1151. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  1152. package/dist/modes/interactive/components/branch-summary-message.js +13 -35
  1153. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  1154. package/dist/modes/interactive/components/compaction-summary-message.d.ts +3 -8
  1155. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  1156. package/dist/modes/interactive/components/compaction-summary-message.js +14 -36
  1157. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  1158. package/dist/modes/interactive/components/config-selector.d.ts +1 -0
  1159. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  1160. package/dist/modes/interactive/components/config-selector.js +20 -43
  1161. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  1162. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  1163. package/dist/modes/interactive/components/countdown-timer.js +0 -5
  1164. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  1165. package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
  1166. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  1167. package/dist/modes/interactive/components/custom-editor.js +4 -8
  1168. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  1169. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  1170. package/dist/modes/interactive/components/custom-message.js +1 -6
  1171. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  1172. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  1173. package/dist/modes/interactive/components/daxnuts.js +6 -8
  1174. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  1175. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  1176. package/dist/modes/interactive/components/diff.js.map +1 -1
  1177. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  1178. package/dist/modes/interactive/components/dynamic-border.js +0 -1
  1179. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  1180. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  1181. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  1182. package/dist/modes/interactive/components/expandable-markdown-message.d.ts +21 -0
  1183. package/dist/modes/interactive/components/expandable-markdown-message.d.ts.map +1 -0
  1184. package/dist/modes/interactive/components/expandable-markdown-message.js +48 -0
  1185. package/dist/modes/interactive/components/expandable-markdown-message.js.map +1 -0
  1186. package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -1
  1187. package/dist/modes/interactive/components/expandable-text.js +0 -2
  1188. package/dist/modes/interactive/components/expandable-text.js.map +1 -1
  1189. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  1190. package/dist/modes/interactive/components/extension-editor.js +1 -9
  1191. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  1192. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  1193. package/dist/modes/interactive/components/extension-input.js +2 -8
  1194. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  1195. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  1196. package/dist/modes/interactive/components/extension-selector.js +5 -20
  1197. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  1198. package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
  1199. package/dist/modes/interactive/components/fitness-role-selector.js +0 -1
  1200. package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
  1201. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  1202. package/dist/modes/interactive/components/footer.js +1 -5
  1203. package/dist/modes/interactive/components/footer.js.map +1 -1
  1204. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  1205. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  1206. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  1207. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  1208. package/dist/modes/interactive/components/login-dialog.js +4 -10
  1209. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  1210. package/dist/modes/interactive/components/model-selector.d.ts +2 -2
  1211. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  1212. package/dist/modes/interactive/components/model-selector.js +21 -44
  1213. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  1214. package/dist/modes/interactive/components/model-suggestion-selector.d.ts.map +1 -1
  1215. package/dist/modes/interactive/components/model-suggestion-selector.js +0 -1
  1216. package/dist/modes/interactive/components/model-suggestion-selector.js.map +1 -1
  1217. package/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
  1218. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  1219. package/dist/modes/interactive/components/oauth-selector.js +16 -32
  1220. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  1221. package/dist/modes/interactive/components/profile-resource-editor.d.ts +3 -4
  1222. package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
  1223. package/dist/modes/interactive/components/profile-resource-editor.js +34 -93
  1224. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  1225. package/dist/modes/interactive/components/profile-selector.d.ts.map +1 -1
  1226. package/dist/modes/interactive/components/profile-selector.js +0 -1
  1227. package/dist/modes/interactive/components/profile-selector.js.map +1 -1
  1228. package/dist/modes/interactive/components/scoped-models-selector.d.ts +3 -4
  1229. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  1230. package/dist/modes/interactive/components/scoped-models-selector.js +34 -79
  1231. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  1232. package/dist/modes/interactive/components/selector-list.d.ts +63 -0
  1233. package/dist/modes/interactive/components/selector-list.d.ts.map +1 -0
  1234. package/dist/modes/interactive/components/selector-list.js +186 -0
  1235. package/dist/modes/interactive/components/selector-list.js.map +1 -0
  1236. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  1237. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  1238. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  1239. package/dist/modes/interactive/components/session-selector.js +61 -103
  1240. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  1241. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  1242. package/dist/modes/interactive/components/settings-selector.js +40 -138
  1243. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  1244. package/dist/modes/interactive/components/show-images-selector.d.ts +2 -4
  1245. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  1246. package/dist/modes/interactive/components/show-images-selector.js +9 -28
  1247. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  1248. package/dist/modes/interactive/components/skill-invocation-message.d.ts +3 -8
  1249. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  1250. package/dist/modes/interactive/components/skill-invocation-message.js +12 -40
  1251. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  1252. package/dist/modes/interactive/components/theme-selector.d.ts +2 -5
  1253. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  1254. package/dist/modes/interactive/components/theme-selector.js +11 -37
  1255. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  1256. package/dist/modes/interactive/components/thinking-selector.d.ts +2 -4
  1257. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  1258. package/dist/modes/interactive/components/thinking-selector.js +9 -31
  1259. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  1260. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  1261. package/dist/modes/interactive/components/tool-execution.js +9 -28
  1262. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  1263. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
  1264. package/dist/modes/interactive/components/tool-group.js +2 -3
  1265. package/dist/modes/interactive/components/tool-group.js.map +1 -1
  1266. package/dist/modes/interactive/components/tool-panel-registry.d.ts.map +1 -1
  1267. package/dist/modes/interactive/components/tool-panel-registry.js +5 -3
  1268. package/dist/modes/interactive/components/tool-panel-registry.js.map +1 -1
  1269. package/dist/modes/interactive/components/tool-title.d.ts.map +1 -1
  1270. package/dist/modes/interactive/components/tool-title.js +0 -4
  1271. package/dist/modes/interactive/components/tool-title.js.map +1 -1
  1272. package/dist/modes/interactive/components/transcript-pager.d.ts +26 -0
  1273. package/dist/modes/interactive/components/transcript-pager.d.ts.map +1 -0
  1274. package/dist/modes/interactive/components/transcript-pager.js +81 -0
  1275. package/dist/modes/interactive/components/transcript-pager.js.map +1 -0
  1276. package/dist/modes/interactive/components/tree-selector.d.ts +1 -12
  1277. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  1278. package/dist/modes/interactive/components/tree-selector.js +42 -402
  1279. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  1280. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  1281. package/dist/modes/interactive/components/trust-selector.js +4 -16
  1282. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  1283. package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -1
  1284. package/dist/modes/interactive/components/usage-action-selector.js +2 -10
  1285. package/dist/modes/interactive/components/usage-action-selector.js.map +1 -1
  1286. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  1287. package/dist/modes/interactive/components/user-message-selector.js +3 -6
  1288. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  1289. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  1290. package/dist/modes/interactive/components/user-message.js +0 -1
  1291. package/dist/modes/interactive/components/user-message.js.map +1 -1
  1292. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  1293. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  1294. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  1295. package/dist/modes/interactive/config-backup.js.map +1 -1
  1296. package/dist/modes/interactive/editor-overlay-host.d.ts.map +1 -1
  1297. package/dist/modes/interactive/editor-overlay-host.js +0 -3
  1298. package/dist/modes/interactive/editor-overlay-host.js.map +1 -1
  1299. package/dist/modes/interactive/extension-ui-host.d.ts +2 -0
  1300. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  1301. package/dist/modes/interactive/extension-ui-host.js +51 -72
  1302. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  1303. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  1304. package/dist/modes/interactive/external-editor.js +2 -15
  1305. package/dist/modes/interactive/external-editor.js.map +1 -1
  1306. package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
  1307. package/dist/modes/interactive/history-reload-math.js.map +1 -1
  1308. package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -1
  1309. package/dist/modes/interactive/interactive-event-controller.js +23 -16
  1310. package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
  1311. package/dist/modes/interactive/interactive-mode.d.ts +13 -4
  1312. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  1313. package/dist/modes/interactive/interactive-mode.js +123 -204
  1314. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  1315. package/dist/modes/interactive/interactive-selection-prompts.d.ts +20 -0
  1316. package/dist/modes/interactive/interactive-selection-prompts.d.ts.map +1 -0
  1317. package/dist/modes/interactive/interactive-selection-prompts.js +43 -0
  1318. package/dist/modes/interactive/interactive-selection-prompts.js.map +1 -0
  1319. package/dist/modes/interactive/key-handlers.d.ts +2 -1
  1320. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  1321. package/dist/modes/interactive/key-handlers.js +4 -2
  1322. package/dist/modes/interactive/key-handlers.js.map +1 -1
  1323. package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -1
  1324. package/dist/modes/interactive/loaded-resources-view.js.map +1 -1
  1325. package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
  1326. package/dist/modes/interactive/local-model-commands.js +4 -9
  1327. package/dist/modes/interactive/local-model-commands.js.map +1 -1
  1328. package/dist/modes/interactive/model-fitness-presentation.d.ts +21 -0
  1329. package/dist/modes/interactive/model-fitness-presentation.d.ts.map +1 -0
  1330. package/dist/modes/interactive/model-fitness-presentation.js +13 -0
  1331. package/dist/modes/interactive/model-fitness-presentation.js.map +1 -0
  1332. package/dist/modes/interactive/profile-menu-controller.d.ts +2 -0
  1333. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  1334. package/dist/modes/interactive/profile-menu-controller.js +79 -171
  1335. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  1336. package/dist/modes/interactive/report-commands.d.ts +2 -0
  1337. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  1338. package/dist/modes/interactive/report-commands.js +12 -6
  1339. package/dist/modes/interactive/report-commands.js.map +1 -1
  1340. package/dist/modes/interactive/resource-display.d.ts.map +1 -1
  1341. package/dist/modes/interactive/resource-display.js.map +1 -1
  1342. package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
  1343. package/dist/modes/interactive/resource-shell-commands.js +6 -23
  1344. package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
  1345. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  1346. package/dist/modes/interactive/session-flow-commands.js +21 -25
  1347. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  1348. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  1349. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  1350. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -1
  1351. package/dist/modes/interactive/session-replacement-errors.js.map +1 -1
  1352. package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
  1353. package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
  1354. package/dist/modes/interactive/signal-lifecycle.d.ts.map +1 -1
  1355. package/dist/modes/interactive/signal-lifecycle.js.map +1 -1
  1356. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  1357. package/dist/modes/interactive/startup-checks.js +12 -8
  1358. package/dist/modes/interactive/startup-checks.js.map +1 -1
  1359. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  1360. package/dist/modes/interactive/theme/theme.js +10 -76
  1361. package/dist/modes/interactive/theme/theme.js.map +1 -1
  1362. package/dist/modes/interactive/usage-commands.d.ts.map +1 -1
  1363. package/dist/modes/interactive/usage-commands.js.map +1 -1
  1364. package/dist/modes/print-mode.d.ts.map +1 -1
  1365. package/dist/modes/print-mode.js +5 -22
  1366. package/dist/modes/print-mode.js.map +1 -1
  1367. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  1368. package/dist/modes/rpc/jsonl.js +1 -1
  1369. package/dist/modes/rpc/jsonl.js.map +1 -1
  1370. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  1371. package/dist/modes/rpc/rpc-client.js +7 -8
  1372. package/dist/modes/rpc/rpc-client.js.map +1 -1
  1373. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  1374. package/dist/modes/rpc/rpc-mode.js +5 -20
  1375. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  1376. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  1377. package/dist/modes/rpc/rpc-types.js.map +1 -1
  1378. package/dist/modes/termination-signals.d.ts +4 -0
  1379. package/dist/modes/termination-signals.d.ts.map +1 -0
  1380. package/dist/modes/termination-signals.js +21 -0
  1381. package/dist/modes/termination-signals.js.map +1 -0
  1382. package/dist/package-manager-cli.d.ts.map +1 -1
  1383. package/dist/package-manager-cli.js.map +1 -1
  1384. package/dist/utils/ansi-colors.d.ts +5 -0
  1385. package/dist/utils/ansi-colors.d.ts.map +1 -0
  1386. package/dist/utils/ansi-colors.js +38 -0
  1387. package/dist/utils/ansi-colors.js.map +1 -0
  1388. package/dist/utils/ansi.d.ts.map +1 -1
  1389. package/dist/utils/ansi.js.map +1 -1
  1390. package/dist/utils/changelog.d.ts.map +1 -1
  1391. package/dist/utils/changelog.js.map +1 -1
  1392. package/dist/utils/child-process.d.ts.map +1 -1
  1393. package/dist/utils/child-process.js.map +1 -1
  1394. package/dist/utils/clipboard-image.d.ts.map +1 -1
  1395. package/dist/utils/clipboard-image.js.map +1 -1
  1396. package/dist/utils/clipboard-native.d.ts.map +1 -1
  1397. package/dist/utils/clipboard-native.js.map +1 -1
  1398. package/dist/utils/clipboard.d.ts.map +1 -1
  1399. package/dist/utils/clipboard.js.map +1 -1
  1400. package/dist/utils/deprecation.d.ts.map +1 -1
  1401. package/dist/utils/deprecation.js.map +1 -1
  1402. package/dist/utils/exif-orientation.d.ts.map +1 -1
  1403. package/dist/utils/exif-orientation.js.map +1 -1
  1404. package/dist/utils/external-editor-command.d.ts.map +1 -1
  1405. package/dist/utils/external-editor-command.js.map +1 -1
  1406. package/dist/utils/frontmatter.d.ts.map +1 -1
  1407. package/dist/utils/frontmatter.js.map +1 -1
  1408. package/dist/utils/fs-watch.d.ts.map +1 -1
  1409. package/dist/utils/fs-watch.js.map +1 -1
  1410. package/dist/utils/git.d.ts.map +1 -1
  1411. package/dist/utils/git.js +20 -28
  1412. package/dist/utils/git.js.map +1 -1
  1413. package/dist/utils/highlight-js-languages.d.ts.map +1 -1
  1414. package/dist/utils/html.d.ts.map +1 -1
  1415. package/dist/utils/html.js.map +1 -1
  1416. package/dist/utils/image-convert.d.ts.map +1 -1
  1417. package/dist/utils/image-convert.js.map +1 -1
  1418. package/dist/utils/image-resize-core.d.ts.map +1 -1
  1419. package/dist/utils/image-resize-core.js.map +1 -1
  1420. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  1421. package/dist/utils/image-resize-worker.js.map +1 -1
  1422. package/dist/utils/image-resize.d.ts.map +1 -1
  1423. package/dist/utils/image-resize.js.map +1 -1
  1424. package/dist/utils/json.d.ts.map +1 -1
  1425. package/dist/utils/json.js.map +1 -1
  1426. package/dist/utils/mime.d.ts.map +1 -1
  1427. package/dist/utils/mime.js.map +1 -1
  1428. package/dist/utils/open-browser.d.ts.map +1 -1
  1429. package/dist/utils/open-browser.js.map +1 -1
  1430. package/dist/utils/paths.d.ts.map +1 -1
  1431. package/dist/utils/paths.js.map +1 -1
  1432. package/dist/utils/photon.d.ts.map +1 -1
  1433. package/dist/utils/photon.js.map +1 -1
  1434. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  1435. package/dist/utils/pi-user-agent.js.map +1 -1
  1436. package/dist/utils/platform.d.ts.map +1 -1
  1437. package/dist/utils/platform.js.map +1 -1
  1438. package/dist/utils/process-memory.d.ts.map +1 -1
  1439. package/dist/utils/process-memory.js.map +1 -1
  1440. package/dist/utils/safe-write-stream.d.ts.map +1 -1
  1441. package/dist/utils/safe-write-stream.js.map +1 -1
  1442. package/dist/utils/shell.d.ts.map +1 -1
  1443. package/dist/utils/shell.js.map +1 -1
  1444. package/dist/utils/sleep.d.ts.map +1 -1
  1445. package/dist/utils/sleep.js +2 -15
  1446. package/dist/utils/sleep.js.map +1 -1
  1447. package/dist/utils/stdin-events.d.ts +8 -0
  1448. package/dist/utils/stdin-events.d.ts.map +1 -0
  1449. package/dist/utils/stdin-events.js +19 -0
  1450. package/dist/utils/stdin-events.js.map +1 -0
  1451. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  1452. package/dist/utils/syntax-highlight.js +20 -13
  1453. package/dist/utils/syntax-highlight.js.map +1 -1
  1454. package/dist/utils/tools-manager.d.ts.map +1 -1
  1455. package/dist/utils/tools-manager.js.map +1 -1
  1456. package/dist/utils/version-check.d.ts.map +1 -1
  1457. package/dist/utils/version-check.js.map +1 -1
  1458. package/dist/utils/windows-self-update.d.ts.map +1 -1
  1459. package/dist/utils/windows-self-update.js.map +1 -1
  1460. package/dist/utils/work-directory.d.ts.map +1 -1
  1461. package/dist/utils/work-directory.js.map +1 -1
  1462. package/docs/compaction.md +11 -3
  1463. package/docs/sessions.md +6 -0
  1464. package/docs/settings.md +1 -1
  1465. package/docs/tool-repair.md +3 -0
  1466. package/docs/windows.md +29 -2
  1467. package/docs/work-directory.md +9 -1
  1468. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  1469. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  1470. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  1471. package/examples/extensions/sandbox/package-lock.json +2 -2
  1472. package/examples/extensions/sandbox/package.json +1 -1
  1473. package/examples/extensions/with-deps/package-lock.json +2 -2
  1474. package/examples/extensions/with-deps/package.json +1 -1
  1475. package/npm-shrinkwrap.json +16 -16
  1476. package/package.json +10 -10
  1477. package/dist/utils/streaming-lines.d.ts +0 -20
  1478. package/dist/utils/streaming-lines.d.ts.map +0 -1
  1479. package/dist/utils/streaming-lines.js +0 -79
  1480. package/dist/utils/streaming-lines.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"keybindings.d.ts","sourceRoot":"","sources":["../../src/core/keybindings.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,UAAU,EAEf,KAAK,iBAAiB,EACtB,KAAK,KAAK,EAEV,kBAAkB,IAAI,qBAAqB,EAC3C,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,cAAc;IAC9B,eAAe,EAAE,IAAI,CAAC;IACtB,WAAW,EAAE,IAAI,CAAC;IAClB,UAAU,EAAE,IAAI,CAAC;IACjB,aAAa,EAAE,IAAI,CAAC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AAC,QAAQ,GAAE,MAAsB,GAAG,kBAAkB,CAIlE;IAED,MAAM,IAAI,IAAI,CAGb;IAED,kBAAkB,IAAI,iBAAiB,CAEtC;IAED,OAAO,CAAC,MAAM,CAAC,YAAY;CAK3B;AAED,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import {\n\ttype Keybinding,\n\ttype KeybindingDefinitions,\n\ttype KeybindingsConfig,\n\ttype KeyId,\n\tTUI_KEYBINDINGS,\n\tKeybindingsManager as TuiKeybindingsManager,\n} from \"@caupulican/pi-tui\";\nimport { existsSync, readFileSync } from \"fs\";\nimport { getAgentDir } from \"../config.ts\";\nimport { isWslEnvironment } from \"../utils/platform.ts\";\nimport { configFile } from \"./agent-paths.ts\";\nimport { isRecordObject } from \"./util/value-guards.ts\";\n\nexport interface AppKeybindings {\n\t\"app.interrupt\": true;\n\t\"app.clear\": true;\n\t\"app.exit\": true;\n\t\"app.suspend\": true;\n\t\"app.thinking.cycle\": true;\n\t\"app.model.cycleForward\": true;\n\t\"app.model.cycleBackward\": true;\n\t\"app.model.select\": true;\n\t\"app.tools.expand\": true;\n\t\"app.thinking.toggle\": true;\n\t\"app.session.toggleNamedFilter\": true;\n\t\"app.editor.external\": true;\n\t\"app.message.followUp\": true;\n\t\"app.message.dequeue\": true;\n\t\"app.clipboard.pasteImage\": true;\n\t\"app.question.next\": true;\n\t\"app.question.previous\": true;\n\t\"app.question.toggle\": true;\n\t\"app.session.new\": true;\n\t\"app.session.tree\": true;\n\t\"app.session.fork\": true;\n\t\"app.session.resume\": true;\n\t\"app.tree.foldOrUp\": true;\n\t\"app.tree.unfoldOrDown\": true;\n\t\"app.tree.editLabel\": true;\n\t\"app.tree.toggleLabelTimestamp\": true;\n\t\"app.session.togglePath\": true;\n\t\"app.session.toggleSort\": true;\n\t\"app.session.rename\": true;\n\t\"app.session.delete\": true;\n\t\"app.session.deleteNoninvasive\": true;\n\t\"app.models.save\": true;\n\t\"app.models.enableAll\": true;\n\t\"app.models.clearAll\": true;\n\t\"app.models.toggleProvider\": true;\n\t\"app.models.reorderUp\": true;\n\t\"app.models.reorderDown\": true;\n\t\"app.profiles.enableAll\": true;\n\t\"app.profiles.clearAll\": true;\n\t\"app.tree.filter.default\": true;\n\t\"app.tree.filter.noTools\": true;\n\t\"app.tree.filter.userOnly\": true;\n\t\"app.tree.filter.labeledOnly\": true;\n\t\"app.tree.filter.all\": true;\n\t\"app.tree.filter.cycleForward\": true;\n\t\"app.tree.filter.cycleBackward\": true;\n}\n\nexport type AppKeybinding = keyof AppKeybindings;\n\nexport function defaultImagePasteKeys(\n\tplatform: NodeJS.Platform = process.platform,\n\tenv: NodeJS.ProcessEnv = process.env,\n\tkernelRelease?: string,\n): KeyId | KeyId[] {\n\tif (platform === \"win32\") return \"alt+v\";\n\tif (isWslEnvironment(env, platform, kernelRelease)) return [\"alt+v\", \"ctrl+v\"];\n\treturn \"ctrl+v\";\n}\n\ndeclare module \"@caupulican/pi-tui\" {\n\tinterface Keybindings extends AppKeybindings {}\n}\n\nexport const KEYBINDINGS = {\n\t...TUI_KEYBINDINGS,\n\t\"app.interrupt\": { defaultKeys: \"escape\", description: \"Cancel or abort\" },\n\t\"app.clear\": { defaultKeys: \"ctrl+c\", description: \"Clear editor\" },\n\t\"app.exit\": { defaultKeys: \"ctrl+d\", description: \"Exit when editor is empty\" },\n\t\"app.suspend\": {\n\t\tdefaultKeys: process.platform === \"win32\" ? [] : \"ctrl+z\",\n\t\tdescription: \"Suspend to background\",\n\t},\n\t\"app.thinking.cycle\": {\n\t\tdefaultKeys: \"shift+tab\",\n\t\tdescription: \"Cycle thinking level\",\n\t},\n\t\"app.model.cycleForward\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Cycle to next model\",\n\t},\n\t\"app.model.cycleBackward\": {\n\t\tdefaultKeys: \"shift+ctrl+p\",\n\t\tdescription: \"Cycle to previous model\",\n\t},\n\t\"app.model.select\": { defaultKeys: \"ctrl+l\", description: \"Open model selector\" },\n\t\"app.tools.expand\": { defaultKeys: \"ctrl+o\", description: \"Toggle tool output\" },\n\t\"app.thinking.toggle\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Toggle thinking blocks\",\n\t},\n\t\"app.session.toggleNamedFilter\": {\n\t\tdefaultKeys: \"ctrl+n\",\n\t\tdescription: \"Toggle named session filter\",\n\t},\n\t\"app.editor.external\": {\n\t\tdefaultKeys: \"ctrl+g\",\n\t\tdescription: \"Open external editor\",\n\t},\n\t\"app.message.followUp\": {\n\t\tdefaultKeys: \"alt+enter\",\n\t\tdescription: \"Queue follow-up message\",\n\t},\n\t\"app.message.dequeue\": {\n\t\tdefaultKeys: \"alt+up\",\n\t\tdescription: \"Restore queued messages\",\n\t},\n\t\"app.clipboard.pasteImage\": {\n\t\tdefaultKeys: defaultImagePasteKeys(),\n\t\tdescription: \"Paste image from clipboard\",\n\t},\n\t\"app.question.next\": {\n\t\tdefaultKeys: [\"tab\", \"right\"],\n\t\tdescription: \"Next question or review\",\n\t},\n\t\"app.question.previous\": {\n\t\tdefaultKeys: [\"shift+tab\", \"left\"],\n\t\tdescription: \"Previous question\",\n\t},\n\t\"app.question.toggle\": {\n\t\tdefaultKeys: \"space\",\n\t\tdescription: \"Toggle a multi-select answer\",\n\t},\n\t\"app.session.new\": { defaultKeys: [], description: \"Start a new session\" },\n\t\"app.session.tree\": { defaultKeys: [], description: \"Open session tree\" },\n\t\"app.session.fork\": { defaultKeys: [], description: \"Fork current session\" },\n\t\"app.session.resume\": { defaultKeys: [], description: \"Resume a session\" },\n\t\"app.tree.foldOrUp\": {\n\t\tdefaultKeys: [\"ctrl+left\", \"alt+left\"],\n\t\tdescription: \"Fold tree branch or move up\",\n\t},\n\t\"app.tree.unfoldOrDown\": {\n\t\tdefaultKeys: [\"ctrl+right\", \"alt+right\"],\n\t\tdescription: \"Unfold tree branch or move down\",\n\t},\n\t\"app.tree.editLabel\": {\n\t\tdefaultKeys: \"shift+l\",\n\t\tdescription: \"Edit tree label\",\n\t},\n\t\"app.tree.toggleLabelTimestamp\": {\n\t\tdefaultKeys: \"shift+t\",\n\t\tdescription: \"Toggle tree label timestamps\",\n\t},\n\t\"app.session.togglePath\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Toggle session path display\",\n\t},\n\t\"app.session.toggleSort\": {\n\t\tdefaultKeys: \"ctrl+s\",\n\t\tdescription: \"Toggle session sort mode\",\n\t},\n\t\"app.session.rename\": {\n\t\tdefaultKeys: \"ctrl+r\",\n\t\tdescription: \"Rename session\",\n\t},\n\t\"app.session.delete\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Delete session\",\n\t},\n\t\"app.session.deleteNoninvasive\": {\n\t\tdefaultKeys: \"ctrl+backspace\",\n\t\tdescription: \"Delete session when query is empty\",\n\t},\n\t\"app.models.save\": {\n\t\tdefaultKeys: \"ctrl+s\",\n\t\tdescription: \"Save model selection\",\n\t},\n\t\"app.models.enableAll\": {\n\t\tdefaultKeys: \"ctrl+a\",\n\t\tdescription: \"Enable all models\",\n\t},\n\t\"app.models.clearAll\": {\n\t\tdefaultKeys: \"ctrl+x\",\n\t\tdescription: \"Clear all models\",\n\t},\n\t\"app.models.toggleProvider\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Toggle all models for provider\",\n\t},\n\t\"app.models.reorderUp\": {\n\t\tdefaultKeys: \"alt+up\",\n\t\tdescription: \"Move model up in order\",\n\t},\n\t\"app.models.reorderDown\": {\n\t\tdefaultKeys: \"alt+down\",\n\t\tdescription: \"Move model down in order\",\n\t},\n\t\"app.profiles.enableAll\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Enable all listed resources\",\n\t},\n\t\"app.profiles.clearAll\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Disable all listed resources\",\n\t},\n\t\"app.tree.filter.default\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Tree filter: default view\",\n\t},\n\t\"app.tree.filter.noTools\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Tree filter: hide tool results\",\n\t},\n\t\"app.tree.filter.userOnly\": {\n\t\tdefaultKeys: \"ctrl+u\",\n\t\tdescription: \"Tree filter: user messages only\",\n\t},\n\t\"app.tree.filter.labeledOnly\": {\n\t\tdefaultKeys: \"ctrl+l\",\n\t\tdescription: \"Tree filter: labeled entries only\",\n\t},\n\t\"app.tree.filter.all\": {\n\t\tdefaultKeys: \"ctrl+a\",\n\t\tdescription: \"Tree filter: show all entries\",\n\t},\n\t\"app.tree.filter.cycleForward\": {\n\t\tdefaultKeys: \"ctrl+o\",\n\t\tdescription: \"Tree filter: cycle forward\",\n\t},\n\t\"app.tree.filter.cycleBackward\": {\n\t\tdefaultKeys: \"shift+ctrl+o\",\n\t\tdescription: \"Tree filter: cycle backward\",\n\t},\n} as const satisfies KeybindingDefinitions;\n\nconst KEYBINDING_NAME_MIGRATIONS = {\n\tcursorUp: \"tui.editor.cursorUp\",\n\tcursorDown: \"tui.editor.cursorDown\",\n\tcursorLeft: \"tui.editor.cursorLeft\",\n\tcursorRight: \"tui.editor.cursorRight\",\n\tcursorWordLeft: \"tui.editor.cursorWordLeft\",\n\tcursorWordRight: \"tui.editor.cursorWordRight\",\n\tcursorLineStart: \"tui.editor.cursorLineStart\",\n\tcursorLineEnd: \"tui.editor.cursorLineEnd\",\n\tjumpForward: \"tui.editor.jumpForward\",\n\tjumpBackward: \"tui.editor.jumpBackward\",\n\tpageUp: \"tui.editor.pageUp\",\n\tpageDown: \"tui.editor.pageDown\",\n\tdeleteCharBackward: \"tui.editor.deleteCharBackward\",\n\tdeleteCharForward: \"tui.editor.deleteCharForward\",\n\tdeleteWordBackward: \"tui.editor.deleteWordBackward\",\n\tdeleteWordForward: \"tui.editor.deleteWordForward\",\n\tdeleteToLineStart: \"tui.editor.deleteToLineStart\",\n\tdeleteToLineEnd: \"tui.editor.deleteToLineEnd\",\n\tyank: \"tui.editor.yank\",\n\tyankPop: \"tui.editor.yankPop\",\n\tundo: \"tui.editor.undo\",\n\tnewLine: \"tui.input.newLine\",\n\tsubmit: \"tui.input.submit\",\n\ttab: \"tui.input.tab\",\n\tcopy: \"tui.input.copy\",\n\tselectUp: \"tui.select.up\",\n\tselectDown: \"tui.select.down\",\n\tselectPageUp: \"tui.select.pageUp\",\n\tselectPageDown: \"tui.select.pageDown\",\n\tselectConfirm: \"tui.select.confirm\",\n\tselectCancel: \"tui.select.cancel\",\n\tinterrupt: \"app.interrupt\",\n\tclear: \"app.clear\",\n\texit: \"app.exit\",\n\tsuspend: \"app.suspend\",\n\tcycleThinkingLevel: \"app.thinking.cycle\",\n\tcycleModelForward: \"app.model.cycleForward\",\n\tcycleModelBackward: \"app.model.cycleBackward\",\n\tselectModel: \"app.model.select\",\n\texpandTools: \"app.tools.expand\",\n\ttoggleThinking: \"app.thinking.toggle\",\n\ttoggleSessionNamedFilter: \"app.session.toggleNamedFilter\",\n\texternalEditor: \"app.editor.external\",\n\tfollowUp: \"app.message.followUp\",\n\tdequeue: \"app.message.dequeue\",\n\tpasteImage: \"app.clipboard.pasteImage\",\n\tnewSession: \"app.session.new\",\n\ttree: \"app.session.tree\",\n\tfork: \"app.session.fork\",\n\tresume: \"app.session.resume\",\n\ttreeFoldOrUp: \"app.tree.foldOrUp\",\n\ttreeUnfoldOrDown: \"app.tree.unfoldOrDown\",\n\ttreeEditLabel: \"app.tree.editLabel\",\n\ttreeToggleLabelTimestamp: \"app.tree.toggleLabelTimestamp\",\n\ttoggleSessionPath: \"app.session.togglePath\",\n\ttoggleSessionSort: \"app.session.toggleSort\",\n\trenameSession: \"app.session.rename\",\n\tdeleteSession: \"app.session.delete\",\n\tdeleteSessionNoninvasive: \"app.session.deleteNoninvasive\",\n} as const satisfies Record<string, Keybinding>;\n\nfunction isLegacyKeybindingName(key: string): key is keyof typeof KEYBINDING_NAME_MIGRATIONS {\n\treturn key in KEYBINDING_NAME_MIGRATIONS;\n}\n\nfunction toKeybindingsConfig(value: unknown): KeybindingsConfig {\n\tif (!isRecordObject(value)) return {};\n\n\tconst config: KeybindingsConfig = {};\n\tfor (const [key, binding] of Object.entries(value)) {\n\t\tif (typeof binding === \"string\") {\n\t\t\tconfig[key] = binding as KeyId;\n\t\t\tcontinue;\n\t\t}\n\t\tif (Array.isArray(binding) && binding.every((entry) => typeof entry === \"string\")) {\n\t\t\tconfig[key] = binding as KeyId[];\n\t\t}\n\t}\n\treturn config;\n}\n\nexport function migrateKeybindingsConfig(rawConfig: Record<string, unknown>): {\n\tconfig: Record<string, unknown>;\n\tmigrated: boolean;\n} {\n\tconst config: Record<string, unknown> = {};\n\tlet migrated = false;\n\n\tfor (const [key, value] of Object.entries(rawConfig)) {\n\t\tconst nextKey = isLegacyKeybindingName(key) ? KEYBINDING_NAME_MIGRATIONS[key] : key;\n\t\tif (nextKey !== key) {\n\t\t\tmigrated = true;\n\t\t}\n\t\tif (key !== nextKey && Object.hasOwn(rawConfig, nextKey)) {\n\t\t\tmigrated = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconfig[nextKey] = value;\n\t}\n\n\treturn { config: orderKeybindingsConfig(config), migrated };\n}\n\nfunction orderKeybindingsConfig(config: Record<string, unknown>): Record<string, unknown> {\n\tconst ordered: Record<string, unknown> = {};\n\tfor (const keybinding of Object.keys(KEYBINDINGS)) {\n\t\tif (Object.hasOwn(config, keybinding)) {\n\t\t\tordered[keybinding] = config[keybinding];\n\t\t}\n\t}\n\n\tconst extras = Object.keys(config)\n\t\t.filter((key) => !Object.hasOwn(ordered, key))\n\t\t.sort();\n\tfor (const key of extras) {\n\t\tordered[key] = config[key];\n\t}\n\n\treturn ordered;\n}\n\nfunction loadRawConfig(path: string): Record<string, unknown> | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(path, \"utf-8\")) as unknown;\n\t\treturn isRecordObject(parsed) ? parsed : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport class KeybindingsManager extends TuiKeybindingsManager {\n\tprivate configPath: string | undefined;\n\n\tconstructor(userBindings: KeybindingsConfig = {}, configPath?: string) {\n\t\tsuper(KEYBINDINGS, userBindings);\n\t\tthis.configPath = configPath;\n\t}\n\n\tstatic create(agentDir: string = getAgentDir()): KeybindingsManager {\n\t\tconst configPath = configFile(agentDir, \"keybindings.json\");\n\t\tconst userBindings = KeybindingsManager.loadFromFile(configPath);\n\t\treturn new KeybindingsManager(userBindings, configPath);\n\t}\n\n\treload(): void {\n\t\tif (!this.configPath) return;\n\t\tthis.setUserBindings(KeybindingsManager.loadFromFile(this.configPath));\n\t}\n\n\tgetEffectiveConfig(): KeybindingsConfig {\n\t\treturn this.getResolvedBindings();\n\t}\n\n\tprivate static loadFromFile(path: string): KeybindingsConfig {\n\t\tconst rawConfig = loadRawConfig(path);\n\t\tif (!rawConfig) return {};\n\t\treturn toKeybindingsConfig(migrateKeybindingsConfig(rawConfig).config);\n\t}\n}\n\nexport type { Keybinding, KeyId, KeybindingsConfig };\n"]}
1
+ {"version":3,"file":"keybindings.d.ts","sourceRoot":"","sources":["../../src/core/keybindings.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,UAAU,EAEf,KAAK,iBAAiB,EACtB,KAAK,KAAK,EAEV,kBAAkB,IAAI,qBAAqB,EAC3C,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,cAAc;IAC9B,eAAe,EAAE,IAAI,CAAC;IACtB,WAAW,EAAE,IAAI,CAAC;IAClB,UAAU,EAAE,IAAI,CAAC;IACjB,aAAa,EAAE,IAAI,CAAC;IACpB,oBAAoB,EAAE,IAAI,CAAC;IAC3B,wBAAwB,EAAE,IAAI,CAAC;IAC/B,yBAAyB,EAAE,IAAI,CAAC;IAChC,kBAAkB,EAAE,IAAI,CAAC;IACzB,kBAAkB,EAAE,IAAI,CAAC;IACzB,sBAAsB,EAAE,IAAI,CAAC;IAC7B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AAE,cAAc;iBAC3B,WAAW,EAAE,6BAA6B;;CAEF,CAAC;AAoF3C,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC7E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;CAClB,CAiBA;AA8BD,qBAAa,kBAAmB,SAAQ,qBAAqB;IAC5D,OAAO,CAAC,UAAU,CAAqB;IAEvC,YAAY,YAAY,GAAE,iBAAsB,EAAE,UAAU,CAAC,EAAE,MAAM,EAGpE;IAED,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAE,MAAsB,GAAG,kBAAkB,CAIlE;IAED,MAAM,IAAI,IAAI,CAGb;IAED,kBAAkB,IAAI,iBAAiB,CAEtC;IAED,OAAO,CAAC,MAAM,CAAC,YAAY;CAK3B;AAED,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC"}
@@ -34,6 +34,7 @@ export const KEYBINDINGS = {
34
34
  },
35
35
  "app.model.select": { defaultKeys: "ctrl+l", description: "Open model selector" },
36
36
  "app.tools.expand": { defaultKeys: "ctrl+o", description: "Toggle tool output" },
37
+ "app.tools.background": { defaultKeys: "ctrl+b", description: "Move active tool calls to background" },
37
38
  "app.thinking.toggle": {
38
39
  defaultKeys: "ctrl+t",
39
40
  description: "Toggle thinking blocks",
@@ -58,6 +59,17 @@ export const KEYBINDINGS = {
58
59
  defaultKeys: defaultImagePasteKeys(),
59
60
  description: "Paste image from clipboard",
60
61
  },
62
+ "app.transcript.open": {
63
+ defaultKeys: "shift+pageUp",
64
+ description: "Open transcript scrollback",
65
+ },
66
+ "app.transcript.scrollUp": { defaultKeys: "up", description: "Scroll transcript up" },
67
+ "app.transcript.scrollDown": { defaultKeys: "down", description: "Scroll transcript down" },
68
+ "app.transcript.pageUp": { defaultKeys: "pageUp", description: "Page transcript up" },
69
+ "app.transcript.pageDown": { defaultKeys: "pageDown", description: "Page transcript down" },
70
+ "app.transcript.top": { defaultKeys: "home", description: "Jump to transcript start" },
71
+ "app.transcript.bottom": { defaultKeys: "end", description: "Jump to transcript tail" },
72
+ "app.transcript.close": { defaultKeys: "escape", description: "Close transcript scrollback" },
61
73
  "app.question.next": {
62
74
  defaultKeys: ["tab", "right"],
63
75
  description: "Next question or review",
@@ -293,7 +305,6 @@ function loadRawConfig(path) {
293
305
  }
294
306
  }
295
307
  export class KeybindingsManager extends TuiKeybindingsManager {
296
- configPath;
297
308
  constructor(userBindings = {}, configPath) {
298
309
  super(KEYBINDINGS, userBindings);
299
310
  this.configPath = configPath;
@@ -1 +1 @@
1
- {"version":3,"file":"keybindings.js","sourceRoot":"","sources":["../../src/core/keybindings.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,eAAe,EACf,kBAAkB,IAAI,qBAAqB,GAC3C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAqDxD,MAAM,UAAU,qBAAqB,CACpC,QAAQ,GAAoB,OAAO,CAAC,QAAQ,EAC5C,GAAG,GAAsB,OAAO,CAAC,GAAG,EACpC,aAAsB,EACJ;IAClB,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,OAAO,CAAC;IACzC,IAAI,gBAAgB,CAAC,GAAG,EAAE,QAAQ,EAAE,aAAa,CAAC;QAAE,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC/E,OAAO,QAAQ,CAAC;AAAA,CAChB;AAMD,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,GAAG,eAAe;I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EAAE,CAAC;IAAA,CAClC;IAEO,MAAM,CAAC,YAAY,CAAC,IAAY,EAAqB;QAC5D,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS;YAAE,OAAO,EAAE,CAAC;QAC1B,OAAO,mBAAmB,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;IAAA,CACvE;CACD","sourcesContent":["import {\n\ttype Keybinding,\n\ttype KeybindingDefinitions,\n\ttype KeybindingsConfig,\n\ttype KeyId,\n\tTUI_KEYBINDINGS,\n\tKeybindingsManager as TuiKeybindingsManager,\n} from \"@caupulican/pi-tui\";\nimport { existsSync, readFileSync } from \"fs\";\nimport { getAgentDir } from \"../config.ts\";\nimport { isWslEnvironment } from \"../utils/platform.ts\";\nimport { configFile } from \"./agent-paths.ts\";\nimport { isRecordObject } from \"./util/value-guards.ts\";\n\nexport interface AppKeybindings {\n\t\"app.interrupt\": true;\n\t\"app.clear\": true;\n\t\"app.exit\": true;\n\t\"app.suspend\": true;\n\t\"app.thinking.cycle\": true;\n\t\"app.model.cycleForward\": true;\n\t\"app.model.cycleBackward\": true;\n\t\"app.model.select\": true;\n\t\"app.tools.expand\": true;\n\t\"app.thinking.toggle\": true;\n\t\"app.session.toggleNamedFilter\": true;\n\t\"app.editor.external\": true;\n\t\"app.message.followUp\": true;\n\t\"app.message.dequeue\": true;\n\t\"app.clipboard.pasteImage\": true;\n\t\"app.question.next\": true;\n\t\"app.question.previous\": true;\n\t\"app.question.toggle\": true;\n\t\"app.session.new\": true;\n\t\"app.session.tree\": true;\n\t\"app.session.fork\": true;\n\t\"app.session.resume\": true;\n\t\"app.tree.foldOrUp\": true;\n\t\"app.tree.unfoldOrDown\": true;\n\t\"app.tree.editLabel\": true;\n\t\"app.tree.toggleLabelTimestamp\": true;\n\t\"app.session.togglePath\": true;\n\t\"app.session.toggleSort\": true;\n\t\"app.session.rename\": true;\n\t\"app.session.delete\": true;\n\t\"app.session.deleteNoninvasive\": true;\n\t\"app.models.save\": true;\n\t\"app.models.enableAll\": true;\n\t\"app.models.clearAll\": true;\n\t\"app.models.toggleProvider\": true;\n\t\"app.models.reorderUp\": true;\n\t\"app.models.reorderDown\": true;\n\t\"app.profiles.enableAll\": true;\n\t\"app.profiles.clearAll\": true;\n\t\"app.tree.filter.default\": true;\n\t\"app.tree.filter.noTools\": true;\n\t\"app.tree.filter.userOnly\": true;\n\t\"app.tree.filter.labeledOnly\": true;\n\t\"app.tree.filter.all\": true;\n\t\"app.tree.filter.cycleForward\": true;\n\t\"app.tree.filter.cycleBackward\": true;\n}\n\nexport type AppKeybinding = keyof AppKeybindings;\n\nexport function defaultImagePasteKeys(\n\tplatform: NodeJS.Platform = process.platform,\n\tenv: NodeJS.ProcessEnv = process.env,\n\tkernelRelease?: string,\n): KeyId | KeyId[] {\n\tif (platform === \"win32\") return \"alt+v\";\n\tif (isWslEnvironment(env, platform, kernelRelease)) return [\"alt+v\", \"ctrl+v\"];\n\treturn \"ctrl+v\";\n}\n\ndeclare module \"@caupulican/pi-tui\" {\n\tinterface Keybindings extends AppKeybindings {}\n}\n\nexport const KEYBINDINGS = {\n\t...TUI_KEYBINDINGS,\n\t\"app.interrupt\": { defaultKeys: \"escape\", description: \"Cancel or abort\" },\n\t\"app.clear\": { defaultKeys: \"ctrl+c\", description: \"Clear editor\" },\n\t\"app.exit\": { defaultKeys: \"ctrl+d\", description: \"Exit when editor is empty\" },\n\t\"app.suspend\": {\n\t\tdefaultKeys: process.platform === \"win32\" ? [] : \"ctrl+z\",\n\t\tdescription: \"Suspend to background\",\n\t},\n\t\"app.thinking.cycle\": {\n\t\tdefaultKeys: \"shift+tab\",\n\t\tdescription: \"Cycle thinking level\",\n\t},\n\t\"app.model.cycleForward\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Cycle to next model\",\n\t},\n\t\"app.model.cycleBackward\": {\n\t\tdefaultKeys: \"shift+ctrl+p\",\n\t\tdescription: \"Cycle to previous model\",\n\t},\n\t\"app.model.select\": { defaultKeys: \"ctrl+l\", description: \"Open model selector\" },\n\t\"app.tools.expand\": { defaultKeys: \"ctrl+o\", description: \"Toggle tool output\" },\n\t\"app.thinking.toggle\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Toggle thinking blocks\",\n\t},\n\t\"app.session.toggleNamedFilter\": {\n\t\tdefaultKeys: \"ctrl+n\",\n\t\tdescription: \"Toggle named session filter\",\n\t},\n\t\"app.editor.external\": {\n\t\tdefaultKeys: \"ctrl+g\",\n\t\tdescription: \"Open external editor\",\n\t},\n\t\"app.message.followUp\": {\n\t\tdefaultKeys: \"alt+enter\",\n\t\tdescription: \"Queue follow-up message\",\n\t},\n\t\"app.message.dequeue\": {\n\t\tdefaultKeys: \"alt+up\",\n\t\tdescription: \"Restore queued messages\",\n\t},\n\t\"app.clipboard.pasteImage\": {\n\t\tdefaultKeys: defaultImagePasteKeys(),\n\t\tdescription: \"Paste image from clipboard\",\n\t},\n\t\"app.question.next\": {\n\t\tdefaultKeys: [\"tab\", \"right\"],\n\t\tdescription: \"Next question or review\",\n\t},\n\t\"app.question.previous\": {\n\t\tdefaultKeys: [\"shift+tab\", \"left\"],\n\t\tdescription: \"Previous question\",\n\t},\n\t\"app.question.toggle\": {\n\t\tdefaultKeys: \"space\",\n\t\tdescription: \"Toggle a multi-select answer\",\n\t},\n\t\"app.session.new\": { defaultKeys: [], description: \"Start a new session\" },\n\t\"app.session.tree\": { defaultKeys: [], description: \"Open session tree\" },\n\t\"app.session.fork\": { defaultKeys: [], description: \"Fork current session\" },\n\t\"app.session.resume\": { defaultKeys: [], description: \"Resume a session\" },\n\t\"app.tree.foldOrUp\": {\n\t\tdefaultKeys: [\"ctrl+left\", \"alt+left\"],\n\t\tdescription: \"Fold tree branch or move up\",\n\t},\n\t\"app.tree.unfoldOrDown\": {\n\t\tdefaultKeys: [\"ctrl+right\", \"alt+right\"],\n\t\tdescription: \"Unfold tree branch or move down\",\n\t},\n\t\"app.tree.editLabel\": {\n\t\tdefaultKeys: \"shift+l\",\n\t\tdescription: \"Edit tree label\",\n\t},\n\t\"app.tree.toggleLabelTimestamp\": {\n\t\tdefaultKeys: \"shift+t\",\n\t\tdescription: \"Toggle tree label timestamps\",\n\t},\n\t\"app.session.togglePath\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Toggle session path display\",\n\t},\n\t\"app.session.toggleSort\": {\n\t\tdefaultKeys: \"ctrl+s\",\n\t\tdescription: \"Toggle session sort mode\",\n\t},\n\t\"app.session.rename\": {\n\t\tdefaultKeys: \"ctrl+r\",\n\t\tdescription: \"Rename session\",\n\t},\n\t\"app.session.delete\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Delete session\",\n\t},\n\t\"app.session.deleteNoninvasive\": {\n\t\tdefaultKeys: \"ctrl+backspace\",\n\t\tdescription: \"Delete session when query is empty\",\n\t},\n\t\"app.models.save\": {\n\t\tdefaultKeys: \"ctrl+s\",\n\t\tdescription: \"Save model selection\",\n\t},\n\t\"app.models.enableAll\": {\n\t\tdefaultKeys: \"ctrl+a\",\n\t\tdescription: \"Enable all models\",\n\t},\n\t\"app.models.clearAll\": {\n\t\tdefaultKeys: \"ctrl+x\",\n\t\tdescription: \"Clear all models\",\n\t},\n\t\"app.models.toggleProvider\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Toggle all models for provider\",\n\t},\n\t\"app.models.reorderUp\": {\n\t\tdefaultKeys: \"alt+up\",\n\t\tdescription: \"Move model up in order\",\n\t},\n\t\"app.models.reorderDown\": {\n\t\tdefaultKeys: \"alt+down\",\n\t\tdescription: \"Move model down in order\",\n\t},\n\t\"app.profiles.enableAll\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Enable all listed resources\",\n\t},\n\t\"app.profiles.clearAll\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Disable all listed resources\",\n\t},\n\t\"app.tree.filter.default\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Tree filter: default view\",\n\t},\n\t\"app.tree.filter.noTools\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Tree filter: hide tool results\",\n\t},\n\t\"app.tree.filter.userOnly\": {\n\t\tdefaultKeys: \"ctrl+u\",\n\t\tdescription: \"Tree filter: user messages only\",\n\t},\n\t\"app.tree.filter.labeledOnly\": {\n\t\tdefaultKeys: \"ctrl+l\",\n\t\tdescription: \"Tree filter: labeled entries only\",\n\t},\n\t\"app.tree.filter.all\": {\n\t\tdefaultKeys: \"ctrl+a\",\n\t\tdescription: \"Tree filter: show all entries\",\n\t},\n\t\"app.tree.filter.cycleForward\": {\n\t\tdefaultKeys: \"ctrl+o\",\n\t\tdescription: \"Tree filter: cycle forward\",\n\t},\n\t\"app.tree.filter.cycleBackward\": {\n\t\tdefaultKeys: \"shift+ctrl+o\",\n\t\tdescription: \"Tree filter: cycle backward\",\n\t},\n} as const satisfies KeybindingDefinitions;\n\nconst KEYBINDING_NAME_MIGRATIONS = {\n\tcursorUp: \"tui.editor.cursorUp\",\n\tcursorDown: \"tui.editor.cursorDown\",\n\tcursorLeft: \"tui.editor.cursorLeft\",\n\tcursorRight: \"tui.editor.cursorRight\",\n\tcursorWordLeft: \"tui.editor.cursorWordLeft\",\n\tcursorWordRight: \"tui.editor.cursorWordRight\",\n\tcursorLineStart: \"tui.editor.cursorLineStart\",\n\tcursorLineEnd: \"tui.editor.cursorLineEnd\",\n\tjumpForward: \"tui.editor.jumpForward\",\n\tjumpBackward: \"tui.editor.jumpBackward\",\n\tpageUp: \"tui.editor.pageUp\",\n\tpageDown: \"tui.editor.pageDown\",\n\tdeleteCharBackward: \"tui.editor.deleteCharBackward\",\n\tdeleteCharForward: \"tui.editor.deleteCharForward\",\n\tdeleteWordBackward: \"tui.editor.deleteWordBackward\",\n\tdeleteWordForward: \"tui.editor.deleteWordForward\",\n\tdeleteToLineStart: \"tui.editor.deleteToLineStart\",\n\tdeleteToLineEnd: \"tui.editor.deleteToLineEnd\",\n\tyank: \"tui.editor.yank\",\n\tyankPop: \"tui.editor.yankPop\",\n\tundo: \"tui.editor.undo\",\n\tnewLine: \"tui.input.newLine\",\n\tsubmit: \"tui.input.submit\",\n\ttab: \"tui.input.tab\",\n\tcopy: \"tui.input.copy\",\n\tselectUp: \"tui.select.up\",\n\tselectDown: \"tui.select.down\",\n\tselectPageUp: \"tui.select.pageUp\",\n\tselectPageDown: \"tui.select.pageDown\",\n\tselectConfirm: \"tui.select.confirm\",\n\tselectCancel: \"tui.select.cancel\",\n\tinterrupt: \"app.interrupt\",\n\tclear: \"app.clear\",\n\texit: \"app.exit\",\n\tsuspend: \"app.suspend\",\n\tcycleThinkingLevel: \"app.thinking.cycle\",\n\tcycleModelForward: \"app.model.cycleForward\",\n\tcycleModelBackward: \"app.model.cycleBackward\",\n\tselectModel: \"app.model.select\",\n\texpandTools: \"app.tools.expand\",\n\ttoggleThinking: \"app.thinking.toggle\",\n\ttoggleSessionNamedFilter: \"app.session.toggleNamedFilter\",\n\texternalEditor: \"app.editor.external\",\n\tfollowUp: \"app.message.followUp\",\n\tdequeue: \"app.message.dequeue\",\n\tpasteImage: \"app.clipboard.pasteImage\",\n\tnewSession: \"app.session.new\",\n\ttree: \"app.session.tree\",\n\tfork: \"app.session.fork\",\n\tresume: \"app.session.resume\",\n\ttreeFoldOrUp: \"app.tree.foldOrUp\",\n\ttreeUnfoldOrDown: \"app.tree.unfoldOrDown\",\n\ttreeEditLabel: \"app.tree.editLabel\",\n\ttreeToggleLabelTimestamp: \"app.tree.toggleLabelTimestamp\",\n\ttoggleSessionPath: \"app.session.togglePath\",\n\ttoggleSessionSort: \"app.session.toggleSort\",\n\trenameSession: \"app.session.rename\",\n\tdeleteSession: \"app.session.delete\",\n\tdeleteSessionNoninvasive: \"app.session.deleteNoninvasive\",\n} as const satisfies Record<string, Keybinding>;\n\nfunction isLegacyKeybindingName(key: string): key is keyof typeof KEYBINDING_NAME_MIGRATIONS {\n\treturn key in KEYBINDING_NAME_MIGRATIONS;\n}\n\nfunction toKeybindingsConfig(value: unknown): KeybindingsConfig {\n\tif (!isRecordObject(value)) return {};\n\n\tconst config: KeybindingsConfig = {};\n\tfor (const [key, binding] of Object.entries(value)) {\n\t\tif (typeof binding === \"string\") {\n\t\t\tconfig[key] = binding as KeyId;\n\t\t\tcontinue;\n\t\t}\n\t\tif (Array.isArray(binding) && binding.every((entry) => typeof entry === \"string\")) {\n\t\t\tconfig[key] = binding as KeyId[];\n\t\t}\n\t}\n\treturn config;\n}\n\nexport function migrateKeybindingsConfig(rawConfig: Record<string, unknown>): {\n\tconfig: Record<string, unknown>;\n\tmigrated: boolean;\n} {\n\tconst config: Record<string, unknown> = {};\n\tlet migrated = false;\n\n\tfor (const [key, value] of Object.entries(rawConfig)) {\n\t\tconst nextKey = isLegacyKeybindingName(key) ? KEYBINDING_NAME_MIGRATIONS[key] : key;\n\t\tif (nextKey !== key) {\n\t\t\tmigrated = true;\n\t\t}\n\t\tif (key !== nextKey && Object.hasOwn(rawConfig, nextKey)) {\n\t\t\tmigrated = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconfig[nextKey] = value;\n\t}\n\n\treturn { config: orderKeybindingsConfig(config), migrated };\n}\n\nfunction orderKeybindingsConfig(config: Record<string, unknown>): Record<string, unknown> {\n\tconst ordered: Record<string, unknown> = {};\n\tfor (const keybinding of Object.keys(KEYBINDINGS)) {\n\t\tif (Object.hasOwn(config, keybinding)) {\n\t\t\tordered[keybinding] = config[keybinding];\n\t\t}\n\t}\n\n\tconst extras = Object.keys(config)\n\t\t.filter((key) => !Object.hasOwn(ordered, key))\n\t\t.sort();\n\tfor (const key of extras) {\n\t\tordered[key] = config[key];\n\t}\n\n\treturn ordered;\n}\n\nfunction loadRawConfig(path: string): Record<string, unknown> | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(path, \"utf-8\")) as unknown;\n\t\treturn isRecordObject(parsed) ? parsed : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport class KeybindingsManager extends TuiKeybindingsManager {\n\tprivate configPath: string | undefined;\n\n\tconstructor(userBindings: KeybindingsConfig = {}, configPath?: string) {\n\t\tsuper(KEYBINDINGS, userBindings);\n\t\tthis.configPath = configPath;\n\t}\n\n\tstatic create(agentDir: string = getAgentDir()): KeybindingsManager {\n\t\tconst configPath = configFile(agentDir, \"keybindings.json\");\n\t\tconst userBindings = KeybindingsManager.loadFromFile(configPath);\n\t\treturn new KeybindingsManager(userBindings, configPath);\n\t}\n\n\treload(): void {\n\t\tif (!this.configPath) return;\n\t\tthis.setUserBindings(KeybindingsManager.loadFromFile(this.configPath));\n\t}\n\n\tgetEffectiveConfig(): KeybindingsConfig {\n\t\treturn this.getResolvedBindings();\n\t}\n\n\tprivate static loadFromFile(path: string): KeybindingsConfig {\n\t\tconst rawConfig = loadRawConfig(path);\n\t\tif (!rawConfig) return {};\n\t\treturn toKeybindingsConfig(migrateKeybindingsConfig(rawConfig).config);\n\t}\n}\n\nexport type { Keybinding, KeyId, KeybindingsConfig };\n"]}
1
+ {"version":3,"file":"keybindings.js","sourceRoot":"","sources":["../../src/core/keybindings.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,eAAe,EACf,kBAAkB,IAAI,qBAAqB,GAC3C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AA8DxD,MAAM,UAAU,qBAAqB,CACpC,QAAQ,GAAoB,OAAO,CAAC,QAAQ,EAC5C,GAA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itions,\n\ttype KeybindingsConfig,\n\ttype KeyId,\n\tTUI_KEYBINDINGS,\n\tKeybindingsManager as TuiKeybindingsManager,\n} from \"@caupulican/pi-tui\";\nimport { existsSync, readFileSync } from \"fs\";\nimport { getAgentDir } from \"../config.ts\";\nimport { isWslEnvironment } from \"../utils/platform.ts\";\nimport { configFile } from \"./agent-paths.ts\";\nimport { isRecordObject } from \"./util/value-guards.ts\";\n\nexport interface AppKeybindings {\n\t\"app.interrupt\": true;\n\t\"app.clear\": true;\n\t\"app.exit\": true;\n\t\"app.suspend\": true;\n\t\"app.thinking.cycle\": true;\n\t\"app.model.cycleForward\": true;\n\t\"app.model.cycleBackward\": true;\n\t\"app.model.select\": true;\n\t\"app.tools.expand\": true;\n\t\"app.tools.background\": true;\n\t\"app.thinking.toggle\": true;\n\t\"app.session.toggleNamedFilter\": true;\n\t\"app.editor.external\": true;\n\t\"app.message.followUp\": true;\n\t\"app.message.dequeue\": true;\n\t\"app.clipboard.pasteImage\": true;\n\t\"app.transcript.open\": true;\n\t\"app.transcript.scrollUp\": true;\n\t\"app.transcript.scrollDown\": true;\n\t\"app.transcript.pageUp\": true;\n\t\"app.transcript.pageDown\": true;\n\t\"app.transcript.top\": true;\n\t\"app.transcript.bottom\": true;\n\t\"app.transcript.close\": true;\n\t\"app.question.next\": true;\n\t\"app.question.previous\": true;\n\t\"app.question.toggle\": true;\n\t\"app.session.new\": true;\n\t\"app.session.tree\": true;\n\t\"app.session.fork\": true;\n\t\"app.session.resume\": true;\n\t\"app.tree.foldOrUp\": true;\n\t\"app.tree.unfoldOrDown\": true;\n\t\"app.tree.editLabel\": true;\n\t\"app.tree.toggleLabelTimestamp\": true;\n\t\"app.session.togglePath\": true;\n\t\"app.session.toggleSort\": true;\n\t\"app.session.rename\": true;\n\t\"app.session.delete\": true;\n\t\"app.session.deleteNoninvasive\": true;\n\t\"app.models.save\": true;\n\t\"app.models.enableAll\": true;\n\t\"app.models.clearAll\": true;\n\t\"app.models.toggleProvider\": true;\n\t\"app.models.reorderUp\": true;\n\t\"app.models.reorderDown\": true;\n\t\"app.profiles.enableAll\": true;\n\t\"app.profiles.clearAll\": true;\n\t\"app.tree.filter.default\": true;\n\t\"app.tree.filter.noTools\": true;\n\t\"app.tree.filter.userOnly\": true;\n\t\"app.tree.filter.labeledOnly\": true;\n\t\"app.tree.filter.all\": true;\n\t\"app.tree.filter.cycleForward\": true;\n\t\"app.tree.filter.cycleBackward\": true;\n}\n\nexport type AppKeybinding = keyof AppKeybindings;\n\nexport function defaultImagePasteKeys(\n\tplatform: NodeJS.Platform = process.platform,\n\tenv: NodeJS.ProcessEnv = process.env,\n\tkernelRelease?: string,\n): KeyId | KeyId[] {\n\tif (platform === \"win32\") return \"alt+v\";\n\tif (isWslEnvironment(env, platform, kernelRelease)) return [\"alt+v\", \"ctrl+v\"];\n\treturn \"ctrl+v\";\n}\n\ndeclare module \"@caupulican/pi-tui\" {\n\tinterface Keybindings extends AppKeybindings {}\n}\n\nexport const KEYBINDINGS = {\n\t...TUI_KEYBINDINGS,\n\t\"app.interrupt\": { defaultKeys: \"escape\", description: \"Cancel or abort\" },\n\t\"app.clear\": { defaultKeys: \"ctrl+c\", description: \"Clear editor\" },\n\t\"app.exit\": { defaultKeys: \"ctrl+d\", description: \"Exit when editor is empty\" },\n\t\"app.suspend\": {\n\t\tdefaultKeys: process.platform === \"win32\" ? [] : \"ctrl+z\",\n\t\tdescription: \"Suspend to background\",\n\t},\n\t\"app.thinking.cycle\": {\n\t\tdefaultKeys: \"shift+tab\",\n\t\tdescription: \"Cycle thinking level\",\n\t},\n\t\"app.model.cycleForward\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Cycle to next model\",\n\t},\n\t\"app.model.cycleBackward\": {\n\t\tdefaultKeys: \"shift+ctrl+p\",\n\t\tdescription: \"Cycle to previous model\",\n\t},\n\t\"app.model.select\": { defaultKeys: \"ctrl+l\", description: \"Open model selector\" },\n\t\"app.tools.expand\": { defaultKeys: \"ctrl+o\", description: \"Toggle tool output\" },\n\t\"app.tools.background\": { defaultKeys: \"ctrl+b\", description: \"Move active tool calls to background\" },\n\t\"app.thinking.toggle\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Toggle thinking blocks\",\n\t},\n\t\"app.session.toggleNamedFilter\": {\n\t\tdefaultKeys: \"ctrl+n\",\n\t\tdescription: \"Toggle named session filter\",\n\t},\n\t\"app.editor.external\": {\n\t\tdefaultKeys: \"ctrl+g\",\n\t\tdescription: \"Open external editor\",\n\t},\n\t\"app.message.followUp\": {\n\t\tdefaultKeys: \"alt+enter\",\n\t\tdescription: \"Queue follow-up message\",\n\t},\n\t\"app.message.dequeue\": {\n\t\tdefaultKeys: \"alt+up\",\n\t\tdescription: \"Restore queued messages\",\n\t},\n\t\"app.clipboard.pasteImage\": {\n\t\tdefaultKeys: defaultImagePasteKeys(),\n\t\tdescription: \"Paste image from clipboard\",\n\t},\n\t\"app.transcript.open\": {\n\t\tdefaultKeys: \"shift+pageUp\",\n\t\tdescription: \"Open transcript scrollback\",\n\t},\n\t\"app.transcript.scrollUp\": { defaultKeys: \"up\", description: \"Scroll transcript up\" },\n\t\"app.transcript.scrollDown\": { defaultKeys: \"down\", description: \"Scroll transcript down\" },\n\t\"app.transcript.pageUp\": { defaultKeys: \"pageUp\", description: \"Page transcript up\" },\n\t\"app.transcript.pageDown\": { defaultKeys: \"pageDown\", description: \"Page transcript down\" },\n\t\"app.transcript.top\": { defaultKeys: \"home\", description: \"Jump to transcript start\" },\n\t\"app.transcript.bottom\": { defaultKeys: \"end\", description: \"Jump to transcript tail\" },\n\t\"app.transcript.close\": { defaultKeys: \"escape\", description: \"Close transcript scrollback\" },\n\t\"app.question.next\": {\n\t\tdefaultKeys: [\"tab\", \"right\"],\n\t\tdescription: \"Next question or review\",\n\t},\n\t\"app.question.previous\": {\n\t\tdefaultKeys: [\"shift+tab\", \"left\"],\n\t\tdescription: \"Previous question\",\n\t},\n\t\"app.question.toggle\": {\n\t\tdefaultKeys: \"space\",\n\t\tdescription: \"Toggle a multi-select answer\",\n\t},\n\t\"app.session.new\": { defaultKeys: [], description: \"Start a new session\" },\n\t\"app.session.tree\": { defaultKeys: [], description: \"Open session tree\" },\n\t\"app.session.fork\": { defaultKeys: [], description: \"Fork current session\" },\n\t\"app.session.resume\": { defaultKeys: [], description: \"Resume a session\" },\n\t\"app.tree.foldOrUp\": {\n\t\tdefaultKeys: [\"ctrl+left\", \"alt+left\"],\n\t\tdescription: \"Fold tree branch or move up\",\n\t},\n\t\"app.tree.unfoldOrDown\": {\n\t\tdefaultKeys: [\"ctrl+right\", \"alt+right\"],\n\t\tdescription: \"Unfold tree branch or move down\",\n\t},\n\t\"app.tree.editLabel\": {\n\t\tdefaultKeys: \"shift+l\",\n\t\tdescription: \"Edit tree label\",\n\t},\n\t\"app.tree.toggleLabelTimestamp\": {\n\t\tdefaultKeys: \"shift+t\",\n\t\tdescription: \"Toggle tree label timestamps\",\n\t},\n\t\"app.session.togglePath\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Toggle session path display\",\n\t},\n\t\"app.session.toggleSort\": {\n\t\tdefaultKeys: \"ctrl+s\",\n\t\tdescription: \"Toggle session sort mode\",\n\t},\n\t\"app.session.rename\": {\n\t\tdefaultKeys: \"ctrl+r\",\n\t\tdescription: \"Rename session\",\n\t},\n\t\"app.session.delete\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Delete session\",\n\t},\n\t\"app.session.deleteNoninvasive\": {\n\t\tdefaultKeys: \"ctrl+backspace\",\n\t\tdescription: \"Delete session when query is empty\",\n\t},\n\t\"app.models.save\": {\n\t\tdefaultKeys: \"ctrl+s\",\n\t\tdescription: \"Save model selection\",\n\t},\n\t\"app.models.enableAll\": {\n\t\tdefaultKeys: \"ctrl+a\",\n\t\tdescription: \"Enable all models\",\n\t},\n\t\"app.models.clearAll\": {\n\t\tdefaultKeys: \"ctrl+x\",\n\t\tdescription: \"Clear all models\",\n\t},\n\t\"app.models.toggleProvider\": {\n\t\tdefaultKeys: \"ctrl+p\",\n\t\tdescription: \"Toggle all models for provider\",\n\t},\n\t\"app.models.reorderUp\": {\n\t\tdefaultKeys: \"alt+up\",\n\t\tdescription: \"Move model up in order\",\n\t},\n\t\"app.models.reorderDown\": {\n\t\tdefaultKeys: \"alt+down\",\n\t\tdescription: \"Move model down in order\",\n\t},\n\t\"app.profiles.enableAll\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Enable all listed resources\",\n\t},\n\t\"app.profiles.clearAll\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Disable all listed resources\",\n\t},\n\t\"app.tree.filter.default\": {\n\t\tdefaultKeys: \"ctrl+d\",\n\t\tdescription: \"Tree filter: default view\",\n\t},\n\t\"app.tree.filter.noTools\": {\n\t\tdefaultKeys: \"ctrl+t\",\n\t\tdescription: \"Tree filter: hide tool results\",\n\t},\n\t\"app.tree.filter.userOnly\": {\n\t\tdefaultKeys: \"ctrl+u\",\n\t\tdescription: \"Tree filter: user messages only\",\n\t},\n\t\"app.tree.filter.labeledOnly\": {\n\t\tdefaultKeys: \"ctrl+l\",\n\t\tdescription: \"Tree filter: labeled entries only\",\n\t},\n\t\"app.tree.filter.all\": {\n\t\tdefaultKeys: \"ctrl+a\",\n\t\tdescription: \"Tree filter: show all entries\",\n\t},\n\t\"app.tree.filter.cycleForward\": {\n\t\tdefaultKeys: \"ctrl+o\",\n\t\tdescription: \"Tree filter: cycle forward\",\n\t},\n\t\"app.tree.filter.cycleBackward\": {\n\t\tdefaultKeys: \"shift+ctrl+o\",\n\t\tdescription: \"Tree filter: cycle backward\",\n\t},\n} as const satisfies KeybindingDefinitions;\n\nconst KEYBINDING_NAME_MIGRATIONS = {\n\tcursorUp: \"tui.editor.cursorUp\",\n\tcursorDown: \"tui.editor.cursorDown\",\n\tcursorLeft: \"tui.editor.cursorLeft\",\n\tcursorRight: \"tui.editor.cursorRight\",\n\tcursorWordLeft: \"tui.editor.cursorWordLeft\",\n\tcursorWordRight: \"tui.editor.cursorWordRight\",\n\tcursorLineStart: \"tui.editor.cursorLineStart\",\n\tcursorLineEnd: \"tui.editor.cursorLineEnd\",\n\tjumpForward: \"tui.editor.jumpForward\",\n\tjumpBackward: \"tui.editor.jumpBackward\",\n\tpageUp: \"tui.editor.pageUp\",\n\tpageDown: \"tui.editor.pageDown\",\n\tdeleteCharBackward: \"tui.editor.deleteCharBackward\",\n\tdeleteCharForward: \"tui.editor.deleteCharForward\",\n\tdeleteWordBackward: \"tui.editor.deleteWordBackward\",\n\tdeleteWordForward: \"tui.editor.deleteWordForward\",\n\tdeleteToLineStart: \"tui.editor.deleteToLineStart\",\n\tdeleteToLineEnd: \"tui.editor.deleteToLineEnd\",\n\tyank: \"tui.editor.yank\",\n\tyankPop: \"tui.editor.yankPop\",\n\tundo: \"tui.editor.undo\",\n\tnewLine: \"tui.input.newLine\",\n\tsubmit: \"tui.input.submit\",\n\ttab: \"tui.input.tab\",\n\tcopy: \"tui.input.copy\",\n\tselectUp: \"tui.select.up\",\n\tselectDown: \"tui.select.down\",\n\tselectPageUp: \"tui.select.pageUp\",\n\tselectPageDown: \"tui.select.pageDown\",\n\tselectConfirm: \"tui.select.confirm\",\n\tselectCancel: \"tui.select.cancel\",\n\tinterrupt: \"app.interrupt\",\n\tclear: \"app.clear\",\n\texit: \"app.exit\",\n\tsuspend: \"app.suspend\",\n\tcycleThinkingLevel: \"app.thinking.cycle\",\n\tcycleModelForward: \"app.model.cycleForward\",\n\tcycleModelBackward: \"app.model.cycleBackward\",\n\tselectModel: \"app.model.select\",\n\texpandTools: \"app.tools.expand\",\n\ttoggleThinking: \"app.thinking.toggle\",\n\ttoggleSessionNamedFilter: \"app.session.toggleNamedFilter\",\n\texternalEditor: \"app.editor.external\",\n\tfollowUp: \"app.message.followUp\",\n\tdequeue: \"app.message.dequeue\",\n\tpasteImage: \"app.clipboard.pasteImage\",\n\tnewSession: \"app.session.new\",\n\ttree: \"app.session.tree\",\n\tfork: \"app.session.fork\",\n\tresume: \"app.session.resume\",\n\ttreeFoldOrUp: \"app.tree.foldOrUp\",\n\ttreeUnfoldOrDown: \"app.tree.unfoldOrDown\",\n\ttreeEditLabel: \"app.tree.editLabel\",\n\ttreeToggleLabelTimestamp: \"app.tree.toggleLabelTimestamp\",\n\ttoggleSessionPath: \"app.session.togglePath\",\n\ttoggleSessionSort: \"app.session.toggleSort\",\n\trenameSession: \"app.session.rename\",\n\tdeleteSession: \"app.session.delete\",\n\tdeleteSessionNoninvasive: \"app.session.deleteNoninvasive\",\n} as const satisfies Record<string, Keybinding>;\n\nfunction isLegacyKeybindingName(key: string): key is keyof typeof KEYBINDING_NAME_MIGRATIONS {\n\treturn key in KEYBINDING_NAME_MIGRATIONS;\n}\n\nfunction toKeybindingsConfig(value: unknown): KeybindingsConfig {\n\tif (!isRecordObject(value)) return {};\n\n\tconst config: KeybindingsConfig = {};\n\tfor (const [key, binding] of Object.entries(value)) {\n\t\tif (typeof binding === \"string\") {\n\t\t\tconfig[key] = binding as KeyId;\n\t\t\tcontinue;\n\t\t}\n\t\tif (Array.isArray(binding) && binding.every((entry) => typeof entry === \"string\")) {\n\t\t\tconfig[key] = binding as KeyId[];\n\t\t}\n\t}\n\treturn config;\n}\n\nexport function migrateKeybindingsConfig(rawConfig: Record<string, unknown>): {\n\tconfig: Record<string, unknown>;\n\tmigrated: boolean;\n} {\n\tconst config: Record<string, unknown> = {};\n\tlet migrated = false;\n\n\tfor (const [key, value] of Object.entries(rawConfig)) {\n\t\tconst nextKey = isLegacyKeybindingName(key) ? KEYBINDING_NAME_MIGRATIONS[key] : key;\n\t\tif (nextKey !== key) {\n\t\t\tmigrated = true;\n\t\t}\n\t\tif (key !== nextKey && Object.hasOwn(rawConfig, nextKey)) {\n\t\t\tmigrated = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconfig[nextKey] = value;\n\t}\n\n\treturn { config: orderKeybindingsConfig(config), migrated };\n}\n\nfunction orderKeybindingsConfig(config: Record<string, unknown>): Record<string, unknown> {\n\tconst ordered: Record<string, unknown> = {};\n\tfor (const keybinding of Object.keys(KEYBINDINGS)) {\n\t\tif (Object.hasOwn(config, keybinding)) {\n\t\t\tordered[keybinding] = config[keybinding];\n\t\t}\n\t}\n\n\tconst extras = Object.keys(config)\n\t\t.filter((key) => !Object.hasOwn(ordered, key))\n\t\t.sort();\n\tfor (const key of extras) {\n\t\tordered[key] = config[key];\n\t}\n\n\treturn ordered;\n}\n\nfunction loadRawConfig(path: string): Record<string, unknown> | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(path, \"utf-8\")) as unknown;\n\t\treturn isRecordObject(parsed) ? parsed : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport class KeybindingsManager extends TuiKeybindingsManager {\n\tprivate configPath: string | undefined;\n\n\tconstructor(userBindings: KeybindingsConfig = {}, configPath?: string) {\n\t\tsuper(KEYBINDINGS, userBindings);\n\t\tthis.configPath = configPath;\n\t}\n\n\tstatic create(agentDir: string = getAgentDir()): KeybindingsManager {\n\t\tconst configPath = configFile(agentDir, \"keybindings.json\");\n\t\tconst userBindings = KeybindingsManager.loadFromFile(configPath);\n\t\treturn new KeybindingsManager(userBindings, configPath);\n\t}\n\n\treload(): void {\n\t\tif (!this.configPath) return;\n\t\tthis.setUserBindings(KeybindingsManager.loadFromFile(this.configPath));\n\t}\n\n\tgetEffectiveConfig(): KeybindingsConfig {\n\t\treturn this.getResolvedBindings();\n\t}\n\n\tprivate static loadFromFile(path: string): KeybindingsConfig {\n\t\tconst rawConfig = loadRawConfig(path);\n\t\tif (!rawConfig) return {};\n\t\treturn toKeybindingsConfig(migrateKeybindingsConfig(rawConfig).config);\n\t}\n}\n\nexport type { Keybinding, KeyId, KeybindingsConfig };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"learning-audit.d.ts","sourceRoot":"","sources":["../../../src/core/learning/learning-audit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AAqB,CAO7G;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAS/E;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,eAAe,GAAG,oBAAoB,CA4B3F;AA8BD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAYlF;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,CAMnG;AAED,eAAO,MAAM,0BAA0B,mBAAmB,CAAC;AAE3D,MAAM,MAAM,4BAA4B,GAAG,sBAAsB,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;AASjG,wBAAgB,2BAA2B,CAC1C,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,MAAM,EAAE,mBAAmB,GACzB,MAAM,CAER;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,mBAAmB,EAAE,CAEjG","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport {\n\tappendSessionSnapshot,\n\tgetSessionSnapshots,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport type { DurableChangeLayer, DurableChangeProposal } from \"./learning-gate.ts\";\nimport type { ReflectionWrite } from \"./reflection-engine.ts\";\n\n/**\n * Audit + rollback metadata for durable learning changes. Every reflection-sourced write that the\n * learning policy applies (or converts to a proposal) leaves one of these records in the session\n * log, so `/autonomy diagnostics` can explain what changed, why, and how to undo it — and\n * `rollbackLearningWrite` can execute the inverse operation.\n */\n\nexport type LearningRollbackKind = \"memory_remove\" | \"memory_restore\" | \"memory_add\" | \"archive_skill\";\n\nexport interface LearningRollbackPlan {\n\tkind: LearningRollbackKind;\n\t/** Text currently present because of the change (to remove/replace), or the skill name to archive. */\n\ttarget?: string;\n\t/** Original text to restore (memory_restore/memory_add). */\n\tprevious?: string;\n\tinstructions: string;\n}\n\n// \"apply_failed\" is distinct from \"apply\": the gate decided to apply, but the underlying write tool\n// (e.g. the memory tool) refused it (budget exceeded, drift, threat) without throwing. It must never\n// be treated as \"apply\" by a rollback-eligibility check — there is nothing durable to undo.\nexport type LearningAuditAction = \"apply\" | \"apply_failed\" | \"propose\" | \"rollback\";\n\n/** reasonCode for an \"apply_failed\" audit — distinct from the gate's own reasonCode (e.g.\n * \"eligible_auto_apply\") so the record is honest about WHERE it stopped: the gate approved the\n * write, but the write tool refused it after the fact. */\nexport const APPLY_WRITE_REFUSED_REASON_CODE = \"apply_write_refused\";\n\nexport interface LearningAuditRecord {\n\tid: string;\n\tproposalId: string;\n\tlayer: DurableChangeLayer;\n\taction: LearningAuditAction;\n\tsummary: string;\n\treasonCode: string;\n\tdecision: LearningDecision;\n\trollback?: LearningRollbackPlan;\n\t/** For action \"rollback\": the audit id of the applied change this record undoes. */\n\trollbackOf?: string;\n\tcreatedAt: string;\n}\n\nfunction describeWrite(write: ReflectionWrite): string {\n\tswitch (write.kind) {\n\t\tcase \"memory_add\":\n\t\t\treturn `Add ${write.section} memory: ${write.text}`;\n\t\tcase \"memory_replace\":\n\t\t\treturn `Replace memory \"${write.target}\" with \"${write.text}\"`;\n\t\tcase \"memory_remove\":\n\t\t\treturn `Remove memory: ${write.target}`;\n\t\tcase \"promote_skill\":\n\t\t\treturn `Promote skill \"${write.name}\": ${write.description}`;\n\t}\n}\n\nexport function proposalFromReflectionWrite(write: ReflectionWrite, proposalId: string): DurableChangeProposal {\n\treturn {\n\t\tid: proposalId,\n\t\tlayer: write.kind === \"promote_skill\" ? \"skill\" : \"memory\",\n\t\tsummary: describeWrite(write),\n\t\trollbackPlan: rollbackPlanForReflectionWrite(write).instructions,\n\t};\n}\n\n/**\n * Contradiction count a reflection write carries against existing durable knowledge. A\n * `memory_replace`/`memory_remove` is only emitted when the reflection engine CONFRONTS an existing\n * fact (it supersedes or deletes it) — that supersession is the gate's contradiction signal, so such\n * a write must route through approval rather than silently overwriting prior memory. A `memory_add`\n * or `promote_skill` is purely additive and contradicts nothing.\n */\nexport function contradictionsForReflectionWrite(write: ReflectionWrite): number {\n\tswitch (write.kind) {\n\t\tcase \"memory_replace\":\n\t\tcase \"memory_remove\":\n\t\t\treturn 1;\n\t\tcase \"memory_add\":\n\t\tcase \"promote_skill\":\n\t\t\treturn 0;\n\t}\n}\n\nexport function rollbackPlanForReflectionWrite(write: ReflectionWrite): LearningRollbackPlan {\n\tswitch (write.kind) {\n\t\tcase \"memory_add\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_remove\",\n\t\t\t\ttarget: write.text,\n\t\t\t\tinstructions: `Remove the added ${write.section} memory text.`,\n\t\t\t};\n\t\tcase \"memory_replace\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_restore\",\n\t\t\t\ttarget: write.text,\n\t\t\t\tprevious: write.target,\n\t\t\t\tinstructions: \"Replace the new memory text with the original text it overwrote.\",\n\t\t\t};\n\t\tcase \"memory_remove\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_add\",\n\t\t\t\tprevious: write.target,\n\t\t\t\tinstructions: \"Re-add the removed text to the MEMORY file (it may originally have lived in USER).\",\n\t\t\t};\n\t\tcase \"promote_skill\":\n\t\t\treturn {\n\t\t\t\tkind: \"archive_skill\",\n\t\t\t\ttarget: write.name,\n\t\t\t\tinstructions: \"Archive the promoted skill so it no longer loads.\",\n\t\t\t};\n\t}\n}\n\nconst AUDIT_ACTIONS: readonly string[] = [\"apply\", \"apply_failed\", \"propose\", \"rollback\"];\nconst ROLLBACK_KINDS: readonly string[] = [\"memory_remove\", \"memory_restore\", \"memory_add\", \"archive_skill\"];\nconst LAYERS: readonly string[] = [\"memory\", \"skill\", \"prompt\", \"extension\", \"tool\", \"script\", \"settings\", \"source\"];\n\nfunction isOptionalString(value: unknown): boolean {\n\treturn value === undefined || typeof value === \"string\";\n}\n\nfunction isLearningRollbackPlan(value: unknown): value is LearningRollbackPlan {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst plan = value as Record<string, unknown>;\n\tif (typeof plan.kind !== \"string\" || !ROLLBACK_KINDS.includes(plan.kind)) return false;\n\tif (!isOptionalString(plan.target) || !isOptionalString(plan.previous)) return false;\n\treturn typeof plan.instructions === \"string\";\n}\n\nfunction isLearningDecisionShape(value: unknown): value is LearningDecision {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst decision = value as Record<string, unknown>;\n\treturn (\n\t\t(decision.kind === \"no-op\" || decision.kind === \"proposal\" || decision.kind === \"apply\") &&\n\t\ttypeof decision.reasonCode === \"string\" &&\n\t\ttypeof decision.confidence === \"number\" &&\n\t\ttypeof decision.summary === \"string\" &&\n\t\ttypeof decision.requiresApproval === \"boolean\"\n\t);\n}\n\nexport function isLearningAuditRecord(value: unknown): value is LearningAuditRecord {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst record = value as Record<string, unknown>;\n\tif (typeof record.id !== \"string\" || record.id.length === 0) return false;\n\tif (typeof record.proposalId !== \"string\") return false;\n\tif (typeof record.layer !== \"string\" || !LAYERS.includes(record.layer)) return false;\n\tif (typeof record.action !== \"string\" || !AUDIT_ACTIONS.includes(record.action)) return false;\n\tif (typeof record.summary !== \"string\" || typeof record.reasonCode !== \"string\") return false;\n\tif (!isLearningDecisionShape(record.decision)) return false;\n\tif (record.rollback !== undefined && !isLearningRollbackPlan(record.rollback)) return false;\n\tif (!isOptionalString(record.rollbackOf)) return false;\n\treturn typeof record.createdAt === \"string\";\n}\n\nexport function cloneLearningAuditRecordForStorage(record: LearningAuditRecord): LearningAuditRecord {\n\treturn {\n\t\t...record,\n\t\tdecision: { ...record.decision },\n\t\t...(record.rollback ? { rollback: { ...record.rollback } } : {}),\n\t};\n}\n\nexport const LEARNING_AUDIT_CUSTOM_TYPE = \"learning_audit\";\n\nexport type LearningAuditSnapshotPayload = SessionSnapshotPayload<\"record\", LearningAuditRecord>;\n\nconst LEARNING_AUDIT_SNAPSHOT_CODEC: SessionSnapshotCodec<LearningAuditRecord, \"record\"> = {\n\tcustomType: LEARNING_AUDIT_CUSTOM_TYPE,\n\tvalueKey: \"record\",\n\tisValue: isLearningAuditRecord,\n\tclone: cloneLearningAuditRecordForStorage,\n};\n\nexport function appendLearningAuditSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LearningAuditRecord,\n): string {\n\treturn appendSessionSnapshot(sessionManager, LEARNING_AUDIT_SNAPSHOT_CODEC, record);\n}\n\nexport function getLearningAuditSnapshots(entries: readonly SessionEntry[]): LearningAuditRecord[] {\n\treturn getSessionSnapshots(entries, LEARNING_AUDIT_SNAPSHOT_CODEC);\n}\n"]}
1
+ {"version":3,"file":"learning-audit.d.ts","sourceRoot":"","sources":["../../../src/core/learning/learning-audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAIN,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;GAKG;AAEH,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,gBAAgB,GAAG,YAAY,GAAG,eAAe,CAAC;AAEvG,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,sGAAsG;IACtG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACrB;AAKD,MAAM,MAAM,mB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AA0B,GAAG,gBAAgB,CAAC;AAI3D,MAAM,6BAA6B,GAAwD;IAC1F,UAAU,EAAE,0BAA0B;IACtC,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,qBAAqB;IAC9B,KAAK,EAAE,kCAAkC;CACzC,CAAC;AAEF,MAAM,UAAU,2BAA2B,CAC1C,cAAyD,EACzD,MAA2B,EAClB;IACT,OAAO,qBAAqB,CAAC,cAAc,EAAE,6BAA6B,EAAE,MAAM,CAAC,CAAC;AAAA,CACpF;AAED,MAAM,UAAU,yBAAyB,CAAC,OAAgC,EAAyB;IAClG,OAAO,mBAAmB,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAAC;AAAA,CACnE","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport {\n\tappendSessionSnapshot,\n\tgetSessionSnapshots,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport type { DurableChangeLayer, DurableChangeProposal } from \"./learning-gate.ts\";\nimport type { ReflectionWrite } from \"./reflection-engine.ts\";\n\n/**\n * Audit + rollback metadata for durable learning changes. Every reflection-sourced write that the\n * learning policy applies (or converts to a proposal) leaves one of these records in the session\n * log, so `/autonomy diagnostics` can explain what changed, why, and how to undo it — and\n * `rollbackLearningWrite` can execute the inverse operation.\n */\n\nexport type LearningRollbackKind = \"memory_remove\" | \"memory_restore\" | \"memory_add\" | \"archive_skill\";\n\nexport interface LearningRollbackPlan {\n\tkind: LearningRollbackKind;\n\t/** Text currently present because of the change (to remove/replace), or the skill name to archive. */\n\ttarget?: string;\n\t/** Original text to restore (memory_restore/memory_add). */\n\tprevious?: string;\n\tinstructions: string;\n}\n\n// \"apply_failed\" is distinct from \"apply\": the gate decided to apply, but the underlying write tool\n// (e.g. the memory tool) refused it (budget exceeded, drift, threat) without throwing. It must never\n// be treated as \"apply\" by a rollback-eligibility check — there is nothing durable to undo.\nexport type LearningAuditAction = \"apply\" | \"apply_failed\" | \"propose\" | \"rollback\";\n\n/** reasonCode for an \"apply_failed\" audit — distinct from the gate's own reasonCode (e.g.\n * \"eligible_auto_apply\") so the record is honest about WHERE it stopped: the gate approved the\n * write, but the write tool refused it after the fact. */\nexport const APPLY_WRITE_REFUSED_REASON_CODE = \"apply_write_refused\";\n\nexport interface LearningAuditRecord {\n\tid: string;\n\tproposalId: string;\n\tlayer: DurableChangeLayer;\n\taction: LearningAuditAction;\n\tsummary: string;\n\treasonCode: string;\n\tdecision: LearningDecision;\n\trollback?: LearningRollbackPlan;\n\t/** For action \"rollback\": the audit id of the applied change this record undoes. */\n\trollbackOf?: string;\n\tcreatedAt: string;\n}\n\nfunction describeWrite(write: ReflectionWrite): string {\n\tswitch (write.kind) {\n\t\tcase \"memory_add\":\n\t\t\treturn `Add ${write.section} memory: ${write.text}`;\n\t\tcase \"memory_replace\":\n\t\t\treturn `Replace memory \"${write.target}\" with \"${write.text}\"`;\n\t\tcase \"memory_remove\":\n\t\t\treturn `Remove memory: ${write.target}`;\n\t\tcase \"promote_skill\":\n\t\t\treturn `Promote skill \"${write.name}\": ${write.description}`;\n\t}\n}\n\nexport function proposalFromReflectionWrite(write: ReflectionWrite, proposalId: string): DurableChangeProposal {\n\treturn {\n\t\tid: proposalId,\n\t\tlayer: write.kind === \"promote_skill\" ? \"skill\" : \"memory\",\n\t\tsummary: describeWrite(write),\n\t\trollbackPlan: rollbackPlanForReflectionWrite(write).instructions,\n\t};\n}\n\n/**\n * Contradiction count a reflection write carries against existing durable knowledge. A\n * `memory_replace`/`memory_remove` is only emitted when the reflection engine CONFRONTS an existing\n * fact (it supersedes or deletes it) — that supersession is the gate's contradiction signal, so such\n * a write must route through approval rather than silently overwriting prior memory. A `memory_add`\n * or `promote_skill` is purely additive and contradicts nothing.\n */\nexport function contradictionsForReflectionWrite(write: ReflectionWrite): number {\n\tswitch (write.kind) {\n\t\tcase \"memory_replace\":\n\t\tcase \"memory_remove\":\n\t\t\treturn 1;\n\t\tcase \"memory_add\":\n\t\tcase \"promote_skill\":\n\t\t\treturn 0;\n\t}\n}\n\nexport function rollbackPlanForReflectionWrite(write: ReflectionWrite): LearningRollbackPlan {\n\tswitch (write.kind) {\n\t\tcase \"memory_add\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_remove\",\n\t\t\t\ttarget: write.text,\n\t\t\t\tinstructions: `Remove the added ${write.section} memory text.`,\n\t\t\t};\n\t\tcase \"memory_replace\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_restore\",\n\t\t\t\ttarget: write.text,\n\t\t\t\tprevious: write.target,\n\t\t\t\tinstructions: \"Replace the new memory text with the original text it overwrote.\",\n\t\t\t};\n\t\tcase \"memory_remove\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_add\",\n\t\t\t\tprevious: write.target,\n\t\t\t\tinstructions: \"Re-add the removed text to the MEMORY file (it may originally have lived in USER).\",\n\t\t\t};\n\t\tcase \"promote_skill\":\n\t\t\treturn {\n\t\t\t\tkind: \"archive_skill\",\n\t\t\t\ttarget: write.name,\n\t\t\t\tinstructions: \"Archive the promoted skill so it no longer loads.\",\n\t\t\t};\n\t}\n}\n\nconst AUDIT_ACTIONS: readonly string[] = [\"apply\", \"apply_failed\", \"propose\", \"rollback\"];\nconst ROLLBACK_KINDS: readonly string[] = [\"memory_remove\", \"memory_restore\", \"memory_add\", \"archive_skill\"];\nconst LAYERS: readonly string[] = [\"memory\", \"skill\", \"prompt\", \"extension\", \"tool\", \"script\", \"settings\", \"source\"];\n\nfunction isOptionalString(value: unknown): boolean {\n\treturn value === undefined || typeof value === \"string\";\n}\n\nfunction isLearningRollbackPlan(value: unknown): value is LearningRollbackPlan {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst plan = value as Record<string, unknown>;\n\tif (typeof plan.kind !== \"string\" || !ROLLBACK_KINDS.includes(plan.kind)) return false;\n\tif (!isOptionalString(plan.target) || !isOptionalString(plan.previous)) return false;\n\treturn typeof plan.instructions === \"string\";\n}\n\nfunction isLearningDecisionShape(value: unknown): value is LearningDecision {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst decision = value as Record<string, unknown>;\n\treturn (\n\t\t(decision.kind === \"no-op\" || decision.kind === \"proposal\" || decision.kind === \"apply\") &&\n\t\ttypeof decision.reasonCode === \"string\" &&\n\t\ttypeof decision.confidence === \"number\" &&\n\t\ttypeof decision.summary === \"string\" &&\n\t\ttypeof decision.requiresApproval === \"boolean\"\n\t);\n}\n\nexport function isLearningAuditRecord(value: unknown): value is LearningAuditRecord {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst record = value as Record<string, unknown>;\n\tif (typeof record.id !== \"string\" || record.id.length === 0) return false;\n\tif (typeof record.proposalId !== \"string\") return false;\n\tif (typeof record.layer !== \"string\" || !LAYERS.includes(record.layer)) return false;\n\tif (typeof record.action !== \"string\" || !AUDIT_ACTIONS.includes(record.action)) return false;\n\tif (typeof record.summary !== \"string\" || typeof record.reasonCode !== \"string\") return false;\n\tif (!isLearningDecisionShape(record.decision)) return false;\n\tif (record.rollback !== undefined && !isLearningRollbackPlan(record.rollback)) return false;\n\tif (!isOptionalString(record.rollbackOf)) return false;\n\treturn typeof record.createdAt === \"string\";\n}\n\nexport function cloneLearningAuditRecordForStorage(record: LearningAuditRecord): LearningAuditRecord {\n\treturn {\n\t\t...record,\n\t\tdecision: { ...record.decision },\n\t\t...(record.rollback ? { rollback: { ...record.rollback } } : {}),\n\t};\n}\n\nexport const LEARNING_AUDIT_CUSTOM_TYPE = \"learning_audit\";\n\nexport type LearningAuditSnapshotPayload = SessionSnapshotPayload<\"record\", LearningAuditRecord>;\n\nconst LEARNING_AUDIT_SNAPSHOT_CODEC: SessionSnapshotCodec<LearningAuditRecord, \"record\"> = {\n\tcustomType: LEARNING_AUDIT_CUSTOM_TYPE,\n\tvalueKey: \"record\",\n\tisValue: isLearningAuditRecord,\n\tclone: cloneLearningAuditRecordForStorage,\n};\n\nexport function appendLearningAuditSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LearningAuditRecord,\n): string {\n\treturn appendSessionSnapshot(sessionManager, LEARNING_AUDIT_SNAPSHOT_CODEC, record);\n}\n\nexport function getLearningAuditSnapshots(entries: readonly SessionEntry[]): LearningAuditRecord[] {\n\treturn getSessionSnapshots(entries, LEARNING_AUDIT_SNAPSHOT_CODEC);\n}\n"]}
1
+ {"version":3,"file":"learning-audit.js","sourceRoot":"","sources":["../../../src/core/learning/learning-audit.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,qBAAqB,EACrB,mBAAmB,GAGnB,MAAM,wBAAwB,CAAC;AA2BhC;;0DAE0D;AAC1D,MAAM,CAAC,MAAM,+BAA+B,GAAG,qBAAqB,CAAC;AAgBrE,SAAS,aAAa,CAAC,KAAsB;IAC5C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,YAAY;YAChB,OAAO,OAAO,KAAK,CAAC,OAAO,YAAY,KAAK,CAAC,IAAI,EAAE,CAAC;QACrD,KAAK,gBAAgB;YACpB,OAAO,mBAAmB,KAAK,CAAC,MAAM,WAAW,KAAK,CAAC,IAAI,GAAG,CAAC;QAChE,KAAK,eAAe;YACnB,OAAO,kBAAkB,KAAK,CAAC,MAAM,EAAE,CAAC;QACzC,KAAK,eAAe;YACnB,OAAO,kBAAkB,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;IAC/D,CAAC;AACF,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,KAAsB,EAAE,UAAkB;IACrF,OAAO;QACN,EAAE,EAAE,UAAU;QACd,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ;QAC1D,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC;QAC7B,YAAY,EAAE,8BAA8B,CAAC,KAAK,C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EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE;QAChC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChE,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,gBAAgB,CAAC;AAI3D,MAAM,6BAA6B,GAAwD;IAC1F,UAAU,EAAE,0BAA0B;IACtC,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,qBAAqB;IAC9B,KAAK,EAAE,kCAAkC;CACzC,CAAC;AAEF,MAAM,UAAU,2BAA2B,CAC1C,cAAyD,EACzD,MAA2B;IAE3B,OAAO,qBAAqB,CAAC,cAAc,EAAE,6BAA6B,EAAE,MAAM,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,OAAgC;IACzE,OAAO,mBAAmB,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport {\n\tappendSessionSnapshot,\n\tgetSessionSnapshots,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport type { DurableChangeLayer, DurableChangeProposal } from \"./learning-gate.ts\";\nimport type { ReflectionWrite } from \"./reflection-engine.ts\";\n\n/**\n * Audit + rollback metadata for durable learning changes. Every reflection-sourced write that the\n * learning policy applies (or converts to a proposal) leaves one of these records in the session\n * log, so `/autonomy diagnostics` can explain what changed, why, and how to undo it — and\n * `rollbackLearningWrite` can execute the inverse operation.\n */\n\nexport type LearningRollbackKind = \"memory_remove\" | \"memory_restore\" | \"memory_add\" | \"archive_skill\";\n\nexport interface LearningRollbackPlan {\n\tkind: LearningRollbackKind;\n\t/** Text currently present because of the change (to remove/replace), or the skill name to archive. */\n\ttarget?: string;\n\t/** Original text to restore (memory_restore/memory_add). */\n\tprevious?: string;\n\tinstructions: string;\n}\n\n// \"apply_failed\" is distinct from \"apply\": the gate decided to apply, but the underlying write tool\n// (e.g. the memory tool) refused it (budget exceeded, drift, threat) without throwing. It must never\n// be treated as \"apply\" by a rollback-eligibility check — there is nothing durable to undo.\nexport type LearningAuditAction = \"apply\" | \"apply_failed\" | \"propose\" | \"rollback\";\n\n/** reasonCode for an \"apply_failed\" audit — distinct from the gate's own reasonCode (e.g.\n * \"eligible_auto_apply\") so the record is honest about WHERE it stopped: the gate approved the\n * write, but the write tool refused it after the fact. */\nexport const APPLY_WRITE_REFUSED_REASON_CODE = \"apply_write_refused\";\n\nexport interface LearningAuditRecord {\n\tid: string;\n\tproposalId: string;\n\tlayer: DurableChangeLayer;\n\taction: LearningAuditAction;\n\tsummary: string;\n\treasonCode: string;\n\tdecision: LearningDecision;\n\trollback?: LearningRollbackPlan;\n\t/** For action \"rollback\": the audit id of the applied change this record undoes. */\n\trollbackOf?: string;\n\tcreatedAt: string;\n}\n\nfunction describeWrite(write: ReflectionWrite): string {\n\tswitch (write.kind) {\n\t\tcase \"memory_add\":\n\t\t\treturn `Add ${write.section} memory: ${write.text}`;\n\t\tcase \"memory_replace\":\n\t\t\treturn `Replace memory \"${write.target}\" with \"${write.text}\"`;\n\t\tcase \"memory_remove\":\n\t\t\treturn `Remove memory: ${write.target}`;\n\t\tcase \"promote_skill\":\n\t\t\treturn `Promote skill \"${write.name}\": ${write.description}`;\n\t}\n}\n\nexport function proposalFromReflectionWrite(write: ReflectionWrite, proposalId: string): DurableChangeProposal {\n\treturn {\n\t\tid: proposalId,\n\t\tlayer: write.kind === \"promote_skill\" ? \"skill\" : \"memory\",\n\t\tsummary: describeWrite(write),\n\t\trollbackPlan: rollbackPlanForReflectionWrite(write).instructions,\n\t};\n}\n\n/**\n * Contradiction count a reflection write carries against existing durable knowledge. A\n * `memory_replace`/`memory_remove` is only emitted when the reflection engine CONFRONTS an existing\n * fact (it supersedes or deletes it) — that supersession is the gate's contradiction signal, so such\n * a write must route through approval rather than silently overwriting prior memory. A `memory_add`\n * or `promote_skill` is purely additive and contradicts nothing.\n */\nexport function contradictionsForReflectionWrite(write: ReflectionWrite): number {\n\tswitch (write.kind) {\n\t\tcase \"memory_replace\":\n\t\tcase \"memory_remove\":\n\t\t\treturn 1;\n\t\tcase \"memory_add\":\n\t\tcase \"promote_skill\":\n\t\t\treturn 0;\n\t}\n}\n\nexport function rollbackPlanForReflectionWrite(write: ReflectionWrite): LearningRollbackPlan {\n\tswitch (write.kind) {\n\t\tcase \"memory_add\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_remove\",\n\t\t\t\ttarget: write.text,\n\t\t\t\tinstructions: `Remove the added ${write.section} memory text.`,\n\t\t\t};\n\t\tcase \"memory_replace\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_restore\",\n\t\t\t\ttarget: write.text,\n\t\t\t\tprevious: write.target,\n\t\t\t\tinstructions: \"Replace the new memory text with the original text it overwrote.\",\n\t\t\t};\n\t\tcase \"memory_remove\":\n\t\t\treturn {\n\t\t\t\tkind: \"memory_add\",\n\t\t\t\tprevious: write.target,\n\t\t\t\tinstructions: \"Re-add the removed text to the MEMORY file (it may originally have lived in USER).\",\n\t\t\t};\n\t\tcase \"promote_skill\":\n\t\t\treturn {\n\t\t\t\tkind: \"archive_skill\",\n\t\t\t\ttarget: write.name,\n\t\t\t\tinstructions: \"Archive the promoted skill so it no longer loads.\",\n\t\t\t};\n\t}\n}\n\nconst AUDIT_ACTIONS: readonly string[] = [\"apply\", \"apply_failed\", \"propose\", \"rollback\"];\nconst ROLLBACK_KINDS: readonly string[] = [\"memory_remove\", \"memory_restore\", \"memory_add\", \"archive_skill\"];\nconst LAYERS: readonly string[] = [\"memory\", \"skill\", \"prompt\", \"extension\", \"tool\", \"script\", \"settings\", \"source\"];\n\nfunction isOptionalString(value: unknown): boolean {\n\treturn value === undefined || typeof value === \"string\";\n}\n\nfunction isLearningRollbackPlan(value: unknown): value is LearningRollbackPlan {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst plan = value as Record<string, unknown>;\n\tif (typeof plan.kind !== \"string\" || !ROLLBACK_KINDS.includes(plan.kind)) return false;\n\tif (!isOptionalString(plan.target) || !isOptionalString(plan.previous)) return false;\n\treturn typeof plan.instructions === \"string\";\n}\n\nfunction isLearningDecisionShape(value: unknown): value is LearningDecision {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst decision = value as Record<string, unknown>;\n\treturn (\n\t\t(decision.kind === \"no-op\" || decision.kind === \"proposal\" || decision.kind === \"apply\") &&\n\t\ttypeof decision.reasonCode === \"string\" &&\n\t\ttypeof decision.confidence === \"number\" &&\n\t\ttypeof decision.summary === \"string\" &&\n\t\ttypeof decision.requiresApproval === \"boolean\"\n\t);\n}\n\nexport function isLearningAuditRecord(value: unknown): value is LearningAuditRecord {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst record = value as Record<string, unknown>;\n\tif (typeof record.id !== \"string\" || record.id.length === 0) return false;\n\tif (typeof record.proposalId !== \"string\") return false;\n\tif (typeof record.layer !== \"string\" || !LAYERS.includes(record.layer)) return false;\n\tif (typeof record.action !== \"string\" || !AUDIT_ACTIONS.includes(record.action)) return false;\n\tif (typeof record.summary !== \"string\" || typeof record.reasonCode !== \"string\") return false;\n\tif (!isLearningDecisionShape(record.decision)) return false;\n\tif (record.rollback !== undefined && !isLearningRollbackPlan(record.rollback)) return false;\n\tif (!isOptionalString(record.rollbackOf)) return false;\n\treturn typeof record.createdAt === \"string\";\n}\n\nexport function cloneLearningAuditRecordForStorage(record: LearningAuditRecord): LearningAuditRecord {\n\treturn {\n\t\t...record,\n\t\tdecision: { ...record.decision },\n\t\t...(record.rollback ? { rollback: { ...record.rollback } } : {}),\n\t};\n}\n\nexport const LEARNING_AUDIT_CUSTOM_TYPE = \"learning_audit\";\n\nexport type LearningAuditSnapshotPayload = SessionSnapshotPayload<\"record\", LearningAuditRecord>;\n\nconst LEARNING_AUDIT_SNAPSHOT_CODEC: SessionSnapshotCodec<LearningAuditRecord, \"record\"> = {\n\tcustomType: LEARNING_AUDIT_CUSTOM_TYPE,\n\tvalueKey: \"record\",\n\tisValue: isLearningAuditRecord,\n\tclone: cloneLearningAuditRecordForStorage,\n};\n\nexport function appendLearningAuditSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LearningAuditRecord,\n): string {\n\treturn appendSessionSnapshot(sessionManager, LEARNING_AUDIT_SNAPSHOT_CODEC, record);\n}\n\nexport function getLearningAuditSnapshots(entries: readonly SessionEntry[]): LearningAuditRecord[] {\n\treturn getSessionSnapshots(entries, LEARNING_AUDIT_SNAPSHOT_CODEC);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"learning-gate.d.ts","sourceRoot":"","sources":["../../../src/core/learning/learning-gate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGjE,MAAM,MAAM,kBAAkB,GAC3B,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,WAAW,GACX,MAAM,GACN,QAAQ,GACR,UAAU,GACV,QAAQ,CAAC;AAEZ,MAAM,WAAW,qBAAqB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,kBAAkB,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,sBAAsB,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACtD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;2FACuF;IACvF,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACjC;AA2BD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC9C,QAAQ,EAAE,qBAAqB,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,gBAAgB,CAoHnB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAc5E;AAED,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,gBAAgB,GAAG,gBAAgB,CAS5F","sourcesContent":["import type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport type DurableChangeLayer =\n\t| \"memory\"\n\t| \"skill\"\n\t| \"prompt\"\n\t| \"extension\"\n\t| \"tool\"\n\t| \"script\"\n\t| \"settings\"\n\t| \"source\";\n\nexport interface DurableChangeProposal {\n\tid: string;\n\tlayer: DurableChangeLayer;\n\tsummary: string;\n\tevidenceIds?: readonly string[];\n\trollbackPlan?: string;\n}\n\nexport interface LearningGateSettings {\n\tenabled: boolean;\n\tautoApplyEnabled: boolean;\n\tconfidenceThreshold: number;\n\tminObservations: number;\n\tallowedAutoApplyLayers: readonly DurableChangeLayer[];\n\trequireRollbackPlan?: boolean;\n\trequireEvidence?: boolean;\n\t/** default: false — a memory_replace/memory_remove (supersedes/deletes an existing fact) stays an\n\t * approval-gated proposal even when otherwise eligible, unless explicitly opted in. */\n\tautoApplySupersessions?: boolean;\n}\n\nconst MAX_DECISION_SUMMARY_LENGTH = 240;\n\nfunction boundedDecisionSummary(summary: string): string {\n\tif (summary.length <= MAX_DECISION_SUMMARY_LENGTH) return summary;\n\treturn `${summary.slice(0, MAX_DECISION_SUMMARY_LENGTH - 1)}…`;\n}\n\nfunction learningDecision(args: {\n\tkind: LearningDecision[\"kind\"];\n\treasonCode: string;\n\tconfidence: number;\n\tsummary: string;\n\trequiresApproval: boolean;\n\tcreatedAt?: string;\n}): LearningDecision {\n\treturn {\n\t\tkind: args.kind,\n\t\treasonCode: args.reasonCode,\n\t\tconfidence: args.confidence,\n\t\tsummary: boundedDecisionSummary(args.summary),\n\t\trequiresApproval: args.requiresApproval,\n\t\tcreatedAt: args.createdAt,\n\t};\n}\n\nexport function evaluateLearningDecision(args: {\n\tproposal: DurableChangeProposal;\n\tconfidence: number;\n\tobservations: number;\n\tcontradictions: number;\n\tsettings: LearningGateSettings;\n\tnow?: string;\n}): LearningDecision {\n\tconst { proposal, confidence, observations, contradictions, settings, now } = args;\n\n\tif (!settings.enabled) {\n\t\treturn learningDecision({\n\t\t\tkind: \"no-op\",\n\t\t\treasonCode: \"learning_disabled\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: false,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\t// A replace/remove supersedes or deletes an existing fact — the reflection engine's\n\t// confront-before-write conflict signal — so by default it routes through approval rather than\n\t// silently overwriting prior memory. With `autoApplySupersessions` opted in, that signal no longer\n\t// short-circuits the decision outright: it FALLS THROUGH to the standard eligibility chain below,\n\t// so a supersession auto-applies only when everything else (threshold/observations/evidence/\n\t// rollback/autoApplyEnabled/layer) also passes.\n\tif (contradictions > 0 && !settings.autoApplySupersessions) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"contradictions_present\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (confidence < settings.confidenceThreshold) {\n\t\t// Below-threshold confidence degrades to an approval-gated proposal, never a silent no-op:\n\t\t// learning stays fail-closed (it can only auto-apply above the threshold) while remaining\n\t\t// VISIBLE and audited. A silent no-op here disabled learning entirely under stock settings\n\t\t// (reflectionSourceConfidence < confidenceThreshold, reflection writes carrying no evidenceIds).\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"below_confidence_threshold\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (observations < settings.minObservations) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"insufficient_observations\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (settings.requireEvidence) {\n\t\tconst hasEvidence = !!(proposal.evidenceIds && proposal.evidenceIds.length > 0);\n\t\tif (!hasEvidence) {\n\t\t\treturn learningDecision({\n\t\t\t\tkind: \"proposal\",\n\t\t\t\treasonCode: \"missing_evidence\",\n\t\t\t\tconfidence,\n\t\t\t\tsummary: proposal.summary,\n\t\t\t\trequiresApproval: true,\n\t\t\t\tcreatedAt: now,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (settings.requireRollbackPlan) {\n\t\tconst hasRollback = proposal.rollbackPlan !== undefined && proposal.rollbackPlan.trim().length > 0;\n\t\tif (!hasRollback) {\n\t\t\treturn learningDecision({\n\t\t\t\tkind: \"proposal\",\n\t\t\t\treasonCode: \"missing_rollback_plan\",\n\t\t\t\tconfidence,\n\t\t\t\tsummary: proposal.summary,\n\t\t\t\trequiresApproval: true,\n\t\t\t\tcreatedAt: now,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!settings.autoApplyEnabled) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"auto_apply_disabled\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tconst isAllowed = settings.allowedAutoApplyLayers.includes(proposal.layer);\n\tif (!isAllowed) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"layer_not_allowed_for_auto_apply\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\treturn learningDecision({\n\t\tkind: \"apply\",\n\t\treasonCode: \"eligible_auto_apply\",\n\t\tconfidence,\n\t\tsummary: proposal.summary,\n\t\trequiresApproval: false,\n\t\tcreatedAt: now,\n\t});\n}\n\nexport function isLearningDecision(value: unknown): value is LearningDecision {\n\tif (!isPlainRecord(value)) return false;\n\n\tif (typeof value.kind !== \"string\" || ![\"no-op\", \"proposal\", \"apply\"].includes(value.kind)) {\n\t\treturn false;\n\t}\n\n\tif (typeof value.reasonCode !== \"string\") return false;\n\tif (typeof value.confidence !== \"number\" || !Number.isFinite(value.confidence)) return false;\n\tif (typeof value.summary !== \"string\") return false;\n\tif (typeof value.requiresApproval !== \"boolean\") return false;\n\tif (value.createdAt !== undefined && typeof value.createdAt !== \"string\") return false;\n\n\treturn true;\n}\n\nexport function cloneLearningDecisionForStorage(decision: LearningDecision): LearningDecision {\n\treturn {\n\t\tkind: decision.kind,\n\t\treasonCode: decision.reasonCode,\n\t\tconfidence: decision.confidence,\n\t\tsummary: decision.summary,\n\t\trequiresApproval: decision.requiresApproval,\n\t\tcreatedAt: decision.createdAt,\n\t};\n}\n"]}
1
+ {"version":3,"file":"learning-gate.d.ts","sourceRoot":"","sources":["../../../src/core/learning/learning-gate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGjE,MAAM,MAAM,kBAAkB,GAC3B,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,WAAW,GACX,MAAM,GACN,QAAQ,GACR,UAAU,GACV,QAAQ,CAAC;AAEZ,M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AC,IAAI,CAAC,EAAE,CAAC;QAC5F,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACvD,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7F,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACpD,IAAI,OAAO,KAAK,CAAC,gBAAgB,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAEvF,OAAO,IAAI,CAAC;AAAA,CACZ;AAED,MAAM,UAAU,+BAA+B,CAAC,QAA0B,EAAoB;IAC7F,OAAO;QACN,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;QAC3C,SAAS,EAAE,QAAQ,CAAC,SAAS;KAC7B,CAAC;AAAA,CACF","sourcesContent":["import type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport type DurableChangeLayer =\n\t| \"memory\"\n\t| \"skill\"\n\t| \"prompt\"\n\t| \"extension\"\n\t| \"tool\"\n\t| \"script\"\n\t| \"settings\"\n\t| \"source\";\n\nexport interface DurableChangeProposal {\n\tid: string;\n\tlayer: DurableChangeLayer;\n\tsummary: string;\n\tevidenceIds?: readonly string[];\n\trollbackPlan?: string;\n}\n\nexport interface LearningGateSettings {\n\tenabled: boolean;\n\tautoApplyEnabled: boolean;\n\tconfidenceThreshold: number;\n\tminObservations: number;\n\tallowedAutoApplyLayers: readonly DurableChangeLayer[];\n\trequireRollbackPlan?: boolean;\n\trequireEvidence?: boolean;\n\t/** default: false — a memory_replace/memory_remove (supersedes/deletes an existing fact) stays an\n\t * approval-gated proposal even when otherwise eligible, unless explicitly opted in. */\n\tautoApplySupersessions?: boolean;\n}\n\nconst MAX_DECISION_SUMMARY_LENGTH = 240;\n\nfunction boundedDecisionSummary(summary: string): string {\n\tif (summary.length <= MAX_DECISION_SUMMARY_LENGTH) return summary;\n\treturn `${summary.slice(0, MAX_DECISION_SUMMARY_LENGTH - 1)}…`;\n}\n\nfunction learningDecision(args: {\n\tkind: LearningDecision[\"kind\"];\n\treasonCode: string;\n\tconfidence: number;\n\tsummary: string;\n\trequiresApproval: boolean;\n\tcreatedAt?: string;\n}): LearningDecision {\n\treturn {\n\t\tkind: args.kind,\n\t\treasonCode: args.reasonCode,\n\t\tconfidence: args.confidence,\n\t\tsummary: boundedDecisionSummary(args.summary),\n\t\trequiresApproval: args.requiresApproval,\n\t\tcreatedAt: args.createdAt,\n\t};\n}\n\nexport function evaluateLearningDecision(args: {\n\tproposal: DurableChangeProposal;\n\tconfidence: number;\n\tobservations: number;\n\tcontradictions: number;\n\tsettings: LearningGateSettings;\n\tnow?: string;\n}): LearningDecision {\n\tconst { proposal, confidence, observations, contradictions, settings, now } = args;\n\n\tif (!settings.enabled) {\n\t\treturn learningDecision({\n\t\t\tkind: \"no-op\",\n\t\t\treasonCode: \"learning_disabled\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: false,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\t// A replace/remove supersedes or deletes an existing fact — the reflection engine's\n\t// confront-before-write conflict signal — so by default it routes through approval rather than\n\t// silently overwriting prior memory. With `autoApplySupersessions` opted in, that signal no longer\n\t// short-circuits the decision outright: it FALLS THROUGH to the standard eligibility chain below,\n\t// so a supersession auto-applies only when everything else (threshold/observations/evidence/\n\t// rollback/autoApplyEnabled/layer) also passes.\n\tif (contradictions > 0 && !settings.autoApplySupersessions) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"contradictions_present\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (confidence < settings.confidenceThreshold) {\n\t\t// Below-threshold confidence degrades to an approval-gated proposal, never a silent no-op:\n\t\t// learning stays fail-closed (it can only auto-apply above the threshold) while remaining\n\t\t// VISIBLE and audited. A silent no-op here disabled learning entirely under stock settings\n\t\t// (reflectionSourceConfidence < confidenceThreshold, reflection writes carrying no evidenceIds).\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"below_confidence_threshold\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (observations < settings.minObservations) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"insufficient_observations\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (settings.requireEvidence) {\n\t\tconst hasEvidence = !!(proposal.evidenceIds && proposal.evidenceIds.length > 0);\n\t\tif (!hasEvidence) {\n\t\t\treturn learningDecision({\n\t\t\t\tkind: \"proposal\",\n\t\t\t\treasonCode: \"missing_evidence\",\n\t\t\t\tconfidence,\n\t\t\t\tsummary: proposal.summary,\n\t\t\t\trequiresApproval: true,\n\t\t\t\tcreatedAt: now,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (settings.requireRollbackPlan) {\n\t\tconst hasRollback = proposal.rollbackPlan !== undefined && proposal.rollbackPlan.trim().length > 0;\n\t\tif (!hasRollback) {\n\t\t\treturn learningDecision({\n\t\t\t\tkind: \"proposal\",\n\t\t\t\treasonCode: \"missing_rollback_plan\",\n\t\t\t\tconfidence,\n\t\t\t\tsummary: proposal.summary,\n\t\t\t\trequiresApproval: true,\n\t\t\t\tcreatedAt: now,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!settings.autoApplyEnabled) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"auto_apply_disabled\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tconst isAllowed = settings.allowedAutoApplyLayers.includes(proposal.layer);\n\tif (!isAllowed) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"layer_not_allowed_for_auto_apply\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\treturn learningDecision({\n\t\tkind: \"apply\",\n\t\treasonCode: \"eligible_auto_apply\",\n\t\tconfidence,\n\t\tsummary: proposal.summary,\n\t\trequiresApproval: false,\n\t\tcreatedAt: now,\n\t});\n}\n\nexport function isLearningDecision(value: unknown): value is LearningDecision {\n\tif (!isPlainRecord(value)) return false;\n\n\tif (typeof value.kind !== \"string\" || ![\"no-op\", \"proposal\", \"apply\"].includes(value.kind)) {\n\t\treturn false;\n\t}\n\n\tif (typeof value.reasonCode !== \"string\") return false;\n\tif (typeof value.confidence !== \"number\" || !Number.isFinite(value.confidence)) return false;\n\tif (typeof value.summary !== \"string\") return false;\n\tif (typeof value.requiresApproval !== \"boolean\") return false;\n\tif (value.createdAt !== undefined && typeof value.createdAt !== \"string\") return false;\n\n\treturn true;\n}\n\nexport function cloneLearningDecisionForStorage(decision: LearningDecision): LearningDecision {\n\treturn {\n\t\tkind: decision.kind,\n\t\treasonCode: decision.reasonCode,\n\t\tconfidence: decision.confidence,\n\t\tsummary: decision.summary,\n\t\trequiresApproval: decision.requiresApproval,\n\t\tcreatedAt: decision.createdAt,\n\t};\n}\n"]}
1
+ {"version":3,"file":"learning-gate.js","sourceRoot":"","sources":["../../../src/core/learning/learning-gate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAiCxD,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC,SAAS,sBAAsB,CAAC,OAAe;IAC9C,IAAI,OAAO,CAAC,MAAM,IAAI,2BAA2B;QAAE,OAAO,OAAO,CAAC;IAClE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,2BAA2B,GAAG,CAAC,CAAC,GAAG,CAAC;AAChE,CAAC;AAED,SAAS,gBAAgB,CAAC,IAOzB;IACA,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,OAAO,EAAE,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC;QAC7C,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,SAAS,EAAE,IAAI,CAAC,SAAS;KACzB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,IAOxC;IACA,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAEnF,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,gBAAgB,CAAC;YACvB,IAAI,EAAE,OAAO;YACb,UAAU,EAAE,mBAAmB;YAC/B,UAAU;YACV,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,gBAAgB,EAAE,KAAK;YACvB,SAAS,EAAE,GAAG;SACd,CAAC,CAAC;IACJ,CAAC;IAED,oFAAoF;IACpF,+FAA+F;IAC/F,mGAAmG;IACnG,kGAAkG;IAClG,6FAA6F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ecord } from \"../util/value-guards.ts\";\n\nexport type DurableChangeLayer =\n\t| \"memory\"\n\t| \"skill\"\n\t| \"prompt\"\n\t| \"extension\"\n\t| \"tool\"\n\t| \"script\"\n\t| \"settings\"\n\t| \"source\";\n\nexport interface DurableChangeProposal {\n\tid: string;\n\tlayer: DurableChangeLayer;\n\tsummary: string;\n\tevidenceIds?: readonly string[];\n\trollbackPlan?: string;\n}\n\nexport interface LearningGateSettings {\n\tenabled: boolean;\n\tautoApplyEnabled: boolean;\n\tconfidenceThreshold: number;\n\tminObservations: number;\n\tallowedAutoApplyLayers: readonly DurableChangeLayer[];\n\trequireRollbackPlan?: boolean;\n\trequireEvidence?: boolean;\n\t/** default: false — a memory_replace/memory_remove (supersedes/deletes an existing fact) stays an\n\t * approval-gated proposal even when otherwise eligible, unless explicitly opted in. */\n\tautoApplySupersessions?: boolean;\n}\n\nconst MAX_DECISION_SUMMARY_LENGTH = 240;\n\nfunction boundedDecisionSummary(summary: string): string {\n\tif (summary.length <= MAX_DECISION_SUMMARY_LENGTH) return summary;\n\treturn `${summary.slice(0, MAX_DECISION_SUMMARY_LENGTH - 1)}…`;\n}\n\nfunction learningDecision(args: {\n\tkind: LearningDecision[\"kind\"];\n\treasonCode: string;\n\tconfidence: number;\n\tsummary: string;\n\trequiresApproval: boolean;\n\tcreatedAt?: string;\n}): LearningDecision {\n\treturn {\n\t\tkind: args.kind,\n\t\treasonCode: args.reasonCode,\n\t\tconfidence: args.confidence,\n\t\tsummary: boundedDecisionSummary(args.summary),\n\t\trequiresApproval: args.requiresApproval,\n\t\tcreatedAt: args.createdAt,\n\t};\n}\n\nexport function evaluateLearningDecision(args: {\n\tproposal: DurableChangeProposal;\n\tconfidence: number;\n\tobservations: number;\n\tcontradictions: number;\n\tsettings: LearningGateSettings;\n\tnow?: string;\n}): LearningDecision {\n\tconst { proposal, confidence, observations, contradictions, settings, now } = args;\n\n\tif (!settings.enabled) {\n\t\treturn learningDecision({\n\t\t\tkind: \"no-op\",\n\t\t\treasonCode: \"learning_disabled\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: false,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\t// A replace/remove supersedes or deletes an existing fact — the reflection engine's\n\t// confront-before-write conflict signal — so by default it routes through approval rather than\n\t// silently overwriting prior memory. With `autoApplySupersessions` opted in, that signal no longer\n\t// short-circuits the decision outright: it FALLS THROUGH to the standard eligibility chain below,\n\t// so a supersession auto-applies only when everything else (threshold/observations/evidence/\n\t// rollback/autoApplyEnabled/layer) also passes.\n\tif (contradictions > 0 && !settings.autoApplySupersessions) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"contradictions_present\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (confidence < settings.confidenceThreshold) {\n\t\t// Below-threshold confidence degrades to an approval-gated proposal, never a silent no-op:\n\t\t// learning stays fail-closed (it can only auto-apply above the threshold) while remaining\n\t\t// VISIBLE and audited. A silent no-op here disabled learning entirely under stock settings\n\t\t// (reflectionSourceConfidence < confidenceThreshold, reflection writes carrying no evidenceIds).\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"below_confidence_threshold\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (observations < settings.minObservations) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"insufficient_observations\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tif (settings.requireEvidence) {\n\t\tconst hasEvidence = !!(proposal.evidenceIds && proposal.evidenceIds.length > 0);\n\t\tif (!hasEvidence) {\n\t\t\treturn learningDecision({\n\t\t\t\tkind: \"proposal\",\n\t\t\t\treasonCode: \"missing_evidence\",\n\t\t\t\tconfidence,\n\t\t\t\tsummary: proposal.summary,\n\t\t\t\trequiresApproval: true,\n\t\t\t\tcreatedAt: now,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (settings.requireRollbackPlan) {\n\t\tconst hasRollback = proposal.rollbackPlan !== undefined && proposal.rollbackPlan.trim().length > 0;\n\t\tif (!hasRollback) {\n\t\t\treturn learningDecision({\n\t\t\t\tkind: \"proposal\",\n\t\t\t\treasonCode: \"missing_rollback_plan\",\n\t\t\t\tconfidence,\n\t\t\t\tsummary: proposal.summary,\n\t\t\t\trequiresApproval: true,\n\t\t\t\tcreatedAt: now,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!settings.autoApplyEnabled) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"auto_apply_disabled\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\tconst isAllowed = settings.allowedAutoApplyLayers.includes(proposal.layer);\n\tif (!isAllowed) {\n\t\treturn learningDecision({\n\t\t\tkind: \"proposal\",\n\t\t\treasonCode: \"layer_not_allowed_for_auto_apply\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: true,\n\t\t\tcreatedAt: now,\n\t\t});\n\t}\n\n\treturn learningDecision({\n\t\tkind: \"apply\",\n\t\treasonCode: \"eligible_auto_apply\",\n\t\tconfidence,\n\t\tsummary: proposal.summary,\n\t\trequiresApproval: false,\n\t\tcreatedAt: now,\n\t});\n}\n\nexport function isLearningDecision(value: unknown): value is LearningDecision {\n\tif (!isPlainRecord(value)) return false;\n\n\tif (typeof value.kind !== \"string\" || ![\"no-op\", \"proposal\", \"apply\"].includes(value.kind)) {\n\t\treturn false;\n\t}\n\n\tif (typeof value.reasonCode !== \"string\") return false;\n\tif (typeof value.confidence !== \"number\" || !Number.isFinite(value.confidence)) return false;\n\tif (typeof value.summary !== \"string\") return false;\n\tif (typeof value.requiresApproval !== \"boolean\") return false;\n\tif (value.createdAt !== undefined && typeof value.createdAt !== \"string\") return false;\n\n\treturn true;\n}\n\nexport function cloneLearningDecisionForStorage(decision: LearningDecision): LearningDecision {\n\treturn {\n\t\tkind: decision.kind,\n\t\treasonCode: decision.reasonCode,\n\t\tconfidence: decision.confidence,\n\t\tsummary: decision.summary,\n\t\trequiresApproval: decision.requiresApproval,\n\t\tcreatedAt: decision.createdAt,\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"observation-store.d.ts","sourceRoot":"","sources":["../../../src/core/learning/observation-store.ts"],"names":[],"mappings":"AAkCA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGrE;AAED,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC,YAAY,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAG7D;IAED,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,gBAAgB,CAEvF;IAED,OAAO,CAAC,IAAI;IAoCZ,OAAO,CAAC,IAAI;IAIZ,6FAA6F;IAC7F,OAAO,CAAC,KAAK;IAab;;;;OAIG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgB1C;IAED,iEAAiE;IACjE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvB;CACD","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { stateFile } from \"../agent-paths.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\n\n/**\n * Durable, BOUNDED evidence-strength store for the learning gate. The gate auto-applies a\n * durable change only once it has been *observed* enough times; a single reflection pass sees a\n * lesson once, so without persistence every proposal would look brand-new and never accumulate the\n * repeated evidence the gate requires. This store counts how many times the SAME lesson (keyed by\n * its durable layer + normalized summary) has been proposed across passes and sessions.\n *\n * File layout mirrors {@link ../models/fitness-store.ts}: a versioned JSON object under\n * `<agentDir>/state/`, best-effort writes, and a corrupt/missing file recovers as a fresh store.\n */\n\n/** Cap per-key counts so a hot lesson can't grow unbounded (the gate only needs a small threshold). */\nconst MAX_COUNT = 100;\n/** Cap the number of tracked keys; least-recently-incremented keys are evicted past this bound. */\nconst MAX_KEYS = 500;\n\ninterface ObservationEntry {\n\tcount: number;\n\t/** ISO timestamp of the most recent increment; drives least-recently-incremented eviction. */\n\tlastAt: string;\n}\n\ninterface ObservationStoreFile {\n\tversion: 1;\n\t/** observationKey -> accumulated evidence for that lesson. */\n\tobservations: Record<string, ObservationEntry>;\n}\n\n/**\n * Stable evidence key for a durable-change proposal: sha256 of the layer plus its summary,\n * lowercased and whitespace-collapsed, truncated to 24 hex chars. Normalization means the same\n * lesson re-observed with reworded whitespace/casing accumulates onto one key instead of scattering.\n */\nexport function observationKey(layer: string, summary: string): string {\n\tconst normalized = summary.toLowerCase().replace(/\\s+/g, \" \").trim();\n\treturn createHash(\"sha256\").update(`${layer}\\n${normalized}`).digest(\"hex\").slice(0, 24);\n}\n\nexport class ObservationStore {\n\tprivate readonly filePath: string;\n\tprivate readonly readOnly: boolean;\n\n\tconstructor(filePath: string, options?: { readOnly?: boolean }) {\n\t\tthis.filePath = filePath;\n\t\tthis.readOnly = options?.readOnly ?? isWorkerSession();\n\t}\n\n\tstatic forAgentDir(agentDir: string, options?: { readOnly?: boolean }): ObservationStore {\n\t\treturn new ObservationStore(stateFile(agentDir, \"learning-observations.json\"), options);\n\t}\n\n\tprivate load(): ObservationStoreFile {\n\t\ttry {\n\t\t\tif (!existsSync(this.filePath)) return { version: 1, observations: {} };\n\t\t\tconst parsed = JSON.parse(readFileSync(this.filePath, \"utf-8\")) as ObservationStoreFile;\n\t\t\tif (\n\t\t\t\tparsed &&\n\t\t\t\tparsed.version === 1 &&\n\t\t\t\tparsed.observations &&\n\t\t\t\ttypeof parsed.observations === \"object\" &&\n\t\t\t\t!Array.isArray(parsed.observations)\n\t\t\t) {\n\t\t\t\t// Sanitize per-entry so a partially-mangled file still yields a usable store rather than\n\t\t\t\t// leaking NaN/undefined counts into the gate.\n\t\t\t\tconst clean: ObservationStoreFile = { version: 1, observations: {} };\n\t\t\t\tfor (const [key, value] of Object.entries(parsed.observations)) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tvalue &&\n\t\t\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t\t\ttypeof (value as ObservationEntry).count === \"number\" &&\n\t\t\t\t\t\tNumber.isFinite((value as ObservationEntry).count) &&\n\t\t\t\t\t\ttypeof (value as ObservationEntry).lastAt === \"string\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tclean.observations[key] = {\n\t\t\t\t\t\t\tcount: Math.min(Math.max(0, Math.floor((value as ObservationEntry).count)), MAX_COUNT),\n\t\t\t\t\t\t\tlastAt: (value as ObservationEntry).lastAt,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn clean;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Unreadable/corrupt store: start fresh in memory; the next increment rewrites the file.\n\t\t}\n\t\treturn { version: 1, observations: {} };\n\t}\n\n\tprivate save(file: ObservationStoreFile): void {\n\t\twriteFileAtomicSync(this.filePath, `${JSON.stringify(file, null, \"\\t\")}\\n`);\n\t}\n\n\t/** Evict least-recently-incremented keys until the store is back within {@link MAX_KEYS}. */\n\tprivate evict(file: ObservationStoreFile): void {\n\t\tconst keys = Object.keys(file.observations);\n\t\tif (keys.length <= MAX_KEYS) return;\n\t\tkeys.sort((a, b) => {\n\t\t\tconst la = file.observations[a]!.lastAt;\n\t\t\tconst lb = file.observations[b]!.lastAt;\n\t\t\treturn la < lb ? -1 : la > lb ? 1 : 0;\n\t\t});\n\t\tfor (const key of keys.slice(0, keys.length - MAX_KEYS)) {\n\t\t\tdelete file.observations[key];\n\t\t}\n\t}\n\n\t/**\n\t * Record one more observation of `key` and return the new (capped) count. Load-mutate-save runs\n\t * under a single exclusive lock so two concurrent increments (e.g. two reflection passes across\n\t * sessions sharing an agentDir) can't both read the old count and drop one increment.\n\t */\n\tincrement(key: string, at?: string): number {\n\t\tif (this.readOnly) {\n\t\t\t// Zero-footprint (worker session): no lock, no dir, no write -- just the pure-read\n\t\t\t// equivalent of what a real increment would have returned.\n\t\t\tconst file = this.load();\n\t\t\treturn Math.min((file.observations[key]?.count ?? 0) + 1, MAX_COUNT);\n\t\t}\n\t\tconst now = at ?? new Date().toISOString();\n\t\treturn withFileLockSync(this.filePath, () => {\n\t\t\tconst file = this.load();\n\t\t\tconst count = Math.min((file.observations[key]?.count ?? 0) + 1, MAX_COUNT);\n\t\t\tfile.observations[key] = { count, lastAt: now };\n\t\t\tthis.evict(file);\n\t\t\tthis.save(file);\n\t\t\treturn count;\n\t\t});\n\t}\n\n\t/** Current observation count for `key` (0 if never observed). */\n\tget(key: string): number {\n\t\treturn this.load().observations[key]?.count ?? 0;\n\t}\n}\n"]}
1
+ {"version":3,"file":"observation-store.d.ts","sourceRoot":"","sources":["../../../src/core/learning/observation-store.ts"],"names":[],"mappings":"AAkCA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGrE;AAED,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC,YAAY,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAG7D;IAED,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,gBAAgB,CAEvF;IAED,OAAO,CAAC,IAAI;IAoCZ,OAAO,CAAC,IAAI;IAIZ,6FAA6F;IAC7F,OAAO,CAAC,KAAK;IAab;;;;OAIG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgB1C;IAED,iEAAiE;IACjE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvB;CACD"}
@@ -27,8 +27,6 @@ export function observationKey(layer, summary) {
27
27
  return createHash("sha256").update(`${layer}\n${normalized}`).digest("hex").slice(0, 24);
28
28
  }
29
29
  export class ObservationStore {
30
- filePath;
31
- readOnly;
32
30
  constructor(filePath, options) {
33
31
  this.filePath = filePath;
34
32
  this.readOnly = options?.readOnly ?? isWorkerSession();
@@ -1 +1 @@
1
- {"version":3,"file":"observation-store.js","sourceRoot":"","sources":["../../../src/core/learning/observation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E;;;;;;;;;GASG;AAEH,uGAAuG;AACvG,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,mGAAmG;AACnG,MAAM,QAAQ,GAAG,GAAG,CAAC;AAcrB;;;;GAIG;AACH,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CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;YAC5E,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAChD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,OAAO,KAAK,CAAC;QAAA,CACb,CAAC,CAAC;IAAA,CACH;IAED,iEAAiE;IACjE,GAAG,CAAC,GAAW,EAAU;QACxB,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;IAAA,CACjD;CACD","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { stateFile } from \"../agent-paths.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\n\n/**\n * Durable, BOUNDED evidence-strength store for the learning gate. The gate auto-applies a\n * durable change only once it has been *observed* enough times; a single reflection pass sees a\n * lesson once, so without persistence every proposal would look brand-new and never accumulate the\n * repeated evidence the gate requires. This store counts how many times the SAME lesson (keyed by\n * its durable layer + normalized summary) has been proposed across passes and sessions.\n *\n * File layout mirrors {@link ../models/fitness-store.ts}: a versioned JSON object under\n * `<agentDir>/state/`, best-effort writes, and a corrupt/missing file recovers as a fresh store.\n */\n\n/** Cap per-key counts so a hot lesson can't grow unbounded (the gate only needs a small threshold). */\nconst MAX_COUNT = 100;\n/** Cap the number of tracked keys; least-recently-incremented keys are evicted past this bound. */\nconst MAX_KEYS = 500;\n\ninterface ObservationEntry {\n\tcount: number;\n\t/** ISO timestamp of the most recent increment; drives least-recently-incremented eviction. */\n\tlastAt: string;\n}\n\ninterface ObservationStoreFile {\n\tversion: 1;\n\t/** observationKey -> accumulated evidence for that lesson. */\n\tobservations: Record<string, ObservationEntry>;\n}\n\n/**\n * Stable evidence key for a durable-change proposal: sha256 of the layer plus its summary,\n * lowercased and whitespace-collapsed, truncated to 24 hex chars. Normalization means the same\n * lesson re-observed with reworded whitespace/casing accumulates onto one key instead of scattering.\n */\nexport function observationKey(layer: string, summary: string): string {\n\tconst normalized = summary.toLowerCase().replace(/\\s+/g, \" \").trim();\n\treturn createHash(\"sha256\").update(`${layer}\\n${normalized}`).digest(\"hex\").slice(0, 24);\n}\n\nexport class ObservationStore {\n\tprivate readonly filePath: string;\n\tprivate readonly readOnly: boolean;\n\n\tconstructor(filePath: string, options?: { readOnly?: boolean }) {\n\t\tthis.filePath = filePath;\n\t\tthis.readOnly = options?.readOnly ?? isWorkerSession();\n\t}\n\n\tstatic forAgentDir(agentDir: string, options?: { readOnly?: boolean }): ObservationStore {\n\t\treturn new ObservationStore(stateFile(agentDir, \"learning-observations.json\"), options);\n\t}\n\n\tprivate load(): ObservationStoreFile {\n\t\ttry {\n\t\t\tif (!existsSync(this.filePath)) return { version: 1, observations: {} };\n\t\t\tconst parsed = JSON.parse(readFileSync(this.filePath, \"utf-8\")) as ObservationStoreFile;\n\t\t\tif (\n\t\t\t\tparsed &&\n\t\t\t\tparsed.version === 1 &&\n\t\t\t\tparsed.observations &&\n\t\t\t\ttypeof parsed.observations === \"object\" &&\n\t\t\t\t!Array.isArray(parsed.observations)\n\t\t\t) {\n\t\t\t\t// Sanitize per-entry so a partially-mangled file still yields a usable store rather than\n\t\t\t\t// leaking NaN/undefined counts into the gate.\n\t\t\t\tconst clean: ObservationStoreFile = { version: 1, observations: {} };\n\t\t\t\tfor (const [key, value] of Object.entries(parsed.observations)) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tvalue &&\n\t\t\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t\t\ttypeof (value as ObservationEntry).count === \"number\" &&\n\t\t\t\t\t\tNumber.isFinite((value as ObservationEntry).count) &&\n\t\t\t\t\t\ttypeof (value as ObservationEntry).lastAt === \"string\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tclean.observations[key] = {\n\t\t\t\t\t\t\tcount: Math.min(Math.max(0, Math.floor((value as ObservationEntry).count)), MAX_COUNT),\n\t\t\t\t\t\t\tlastAt: (value as ObservationEntry).lastAt,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn clean;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Unreadable/corrupt store: start fresh in memory; the next increment rewrites the file.\n\t\t}\n\t\treturn { version: 1, observations: {} };\n\t}\n\n\tprivate save(file: ObservationStoreFile): void {\n\t\twriteFileAtomicSync(this.filePath, `${JSON.stringify(file, null, \"\\t\")}\\n`);\n\t}\n\n\t/** Evict least-recently-incremented keys until the store is back within {@link MAX_KEYS}. */\n\tprivate evict(file: ObservationStoreFile): void {\n\t\tconst keys = Object.keys(file.observations);\n\t\tif (keys.length <= MAX_KEYS) return;\n\t\tkeys.sort((a, b) => {\n\t\t\tconst la = file.observations[a]!.lastAt;\n\t\t\tconst lb = file.observations[b]!.lastAt;\n\t\t\treturn la < lb ? -1 : la > lb ? 1 : 0;\n\t\t});\n\t\tfor (const key of keys.slice(0, keys.length - MAX_KEYS)) {\n\t\t\tdelete file.observations[key];\n\t\t}\n\t}\n\n\t/**\n\t * Record one more observation of `key` and return the new (capped) count. Load-mutate-save runs\n\t * under a single exclusive lock so two concurrent increments (e.g. two reflection passes across\n\t * sessions sharing an agentDir) can't both read the old count and drop one increment.\n\t */\n\tincrement(key: string, at?: string): number {\n\t\tif (this.readOnly) {\n\t\t\t// Zero-footprint (worker session): no lock, no dir, no write -- just the pure-read\n\t\t\t// equivalent of what a real increment would have returned.\n\t\t\tconst file = this.load();\n\t\t\treturn Math.min((file.observations[key]?.count ?? 0) + 1, MAX_COUNT);\n\t\t}\n\t\tconst now = at ?? new Date().toISOString();\n\t\treturn withFileLockSync(this.filePath, () => {\n\t\t\tconst file = this.load();\n\t\t\tconst count = Math.min((file.observations[key]?.count ?? 0) + 1, MAX_COUNT);\n\t\t\tfile.observations[key] = { count, lastAt: now };\n\t\t\tthis.evict(file);\n\t\t\tthis.save(file);\n\t\t\treturn count;\n\t\t});\n\t}\n\n\t/** Current observation count for `key` (0 if never observed). */\n\tget(key: string): number {\n\t\treturn this.load().observations[key]?.count ?? 0;\n\t}\n}\n"]}
1
+ {"version":3,"file":"observation-store.js","sourceRoot":"","sources":["../../../src/core/learning/observation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E;;;;;;;;;GASG;AAEH,uGAAuG;AACvG,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,mGAAmG;AACnG,MAAM,QAAQ,GAAG,GAAG,CAAC;AAcrB;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,OAAe;IAC5D,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACrE,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,KAAK,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED,MAAM,OAAO,gBAAgB;IAI5B,YAAY,QAAgB,EAAE,OAAgC;QAC7D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,eAA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C;IACF,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,GAAW,EAAE,EAAW;QACjC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,mFAAmF;YACnF,2DAA2D;YAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;QACtE,CAAC;QACD,MAAM,GAAG,GAAG,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE;YAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;YAC5E,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAChD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,OAAO,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,iEAAiE;IACjE,GAAG,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;IAClD,CAAC;CACD","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { stateFile } from \"../agent-paths.ts\";\nimport { isWorkerSession } from \"../session-role.ts\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\n\n/**\n * Durable, BOUNDED evidence-strength store for the learning gate. The gate auto-applies a\n * durable change only once it has been *observed* enough times; a single reflection pass sees a\n * lesson once, so without persistence every proposal would look brand-new and never accumulate the\n * repeated evidence the gate requires. This store counts how many times the SAME lesson (keyed by\n * its durable layer + normalized summary) has been proposed across passes and sessions.\n *\n * File layout mirrors {@link ../models/fitness-store.ts}: a versioned JSON object under\n * `<agentDir>/state/`, best-effort writes, and a corrupt/missing file recovers as a fresh store.\n */\n\n/** Cap per-key counts so a hot lesson can't grow unbounded (the gate only needs a small threshold). */\nconst MAX_COUNT = 100;\n/** Cap the number of tracked keys; least-recently-incremented keys are evicted past this bound. */\nconst MAX_KEYS = 500;\n\ninterface ObservationEntry {\n\tcount: number;\n\t/** ISO timestamp of the most recent increment; drives least-recently-incremented eviction. */\n\tlastAt: string;\n}\n\ninterface ObservationStoreFile {\n\tversion: 1;\n\t/** observationKey -> accumulated evidence for that lesson. */\n\tobservations: Record<string, ObservationEntry>;\n}\n\n/**\n * Stable evidence key for a durable-change proposal: sha256 of the layer plus its summary,\n * lowercased and whitespace-collapsed, truncated to 24 hex chars. Normalization means the same\n * lesson re-observed with reworded whitespace/casing accumulates onto one key instead of scattering.\n */\nexport function observationKey(layer: string, summary: string): string {\n\tconst normalized = summary.toLowerCase().replace(/\\s+/g, \" \").trim();\n\treturn createHash(\"sha256\").update(`${layer}\\n${normalized}`).digest(\"hex\").slice(0, 24);\n}\n\nexport class ObservationStore {\n\tprivate readonly filePath: string;\n\tprivate readonly readOnly: boolean;\n\n\tconstructor(filePath: string, options?: { readOnly?: boolean }) {\n\t\tthis.filePath = filePath;\n\t\tthis.readOnly = options?.readOnly ?? isWorkerSession();\n\t}\n\n\tstatic forAgentDir(agentDir: string, options?: { readOnly?: boolean }): ObservationStore {\n\t\treturn new ObservationStore(stateFile(agentDir, \"learning-observations.json\"), options);\n\t}\n\n\tprivate load(): ObservationStoreFile {\n\t\ttry {\n\t\t\tif (!existsSync(this.filePath)) return { version: 1, observations: {} };\n\t\t\tconst parsed = JSON.parse(readFileSync(this.filePath, \"utf-8\")) as ObservationStoreFile;\n\t\t\tif (\n\t\t\t\tparsed &&\n\t\t\t\tparsed.version === 1 &&\n\t\t\t\tparsed.observations &&\n\t\t\t\ttypeof parsed.observations === \"object\" &&\n\t\t\t\t!Array.isArray(parsed.observations)\n\t\t\t) {\n\t\t\t\t// Sanitize per-entry so a partially-mangled file still yields a usable store rather than\n\t\t\t\t// leaking NaN/undefined counts into the gate.\n\t\t\t\tconst clean: ObservationStoreFile = { version: 1, observations: {} };\n\t\t\t\tfor (const [key, value] of Object.entries(parsed.observations)) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tvalue &&\n\t\t\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t\t\ttypeof (value as ObservationEntry).count === \"number\" &&\n\t\t\t\t\t\tNumber.isFinite((value as ObservationEntry).count) &&\n\t\t\t\t\t\ttypeof (value as ObservationEntry).lastAt === \"string\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tclean.observations[key] = {\n\t\t\t\t\t\t\tcount: Math.min(Math.max(0, Math.floor((value as ObservationEntry).count)), MAX_COUNT),\n\t\t\t\t\t\t\tlastAt: (value as ObservationEntry).lastAt,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn clean;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Unreadable/corrupt store: start fresh in memory; the next increment rewrites the file.\n\t\t}\n\t\treturn { version: 1, observations: {} };\n\t}\n\n\tprivate save(file: ObservationStoreFile): void {\n\t\twriteFileAtomicSync(this.filePath, `${JSON.stringify(file, null, \"\\t\")}\\n`);\n\t}\n\n\t/** Evict least-recently-incremented keys until the store is back within {@link MAX_KEYS}. */\n\tprivate evict(file: ObservationStoreFile): void {\n\t\tconst keys = Object.keys(file.observations);\n\t\tif (keys.length <= MAX_KEYS) return;\n\t\tkeys.sort((a, b) => {\n\t\t\tconst la = file.observations[a]!.lastAt;\n\t\t\tconst lb = file.observations[b]!.lastAt;\n\t\t\treturn la < lb ? -1 : la > lb ? 1 : 0;\n\t\t});\n\t\tfor (const key of keys.slice(0, keys.length - MAX_KEYS)) {\n\t\t\tdelete file.observations[key];\n\t\t}\n\t}\n\n\t/**\n\t * Record one more observation of `key` and return the new (capped) count. Load-mutate-save runs\n\t * under a single exclusive lock so two concurrent increments (e.g. two reflection passes across\n\t * sessions sharing an agentDir) can't both read the old count and drop one increment.\n\t */\n\tincrement(key: string, at?: string): number {\n\t\tif (this.readOnly) {\n\t\t\t// Zero-footprint (worker session): no lock, no dir, no write -- just the pure-read\n\t\t\t// equivalent of what a real increment would have returned.\n\t\t\tconst file = this.load();\n\t\t\treturn Math.min((file.observations[key]?.count ?? 0) + 1, MAX_COUNT);\n\t\t}\n\t\tconst now = at ?? new Date().toISOString();\n\t\treturn withFileLockSync(this.filePath, () => {\n\t\t\tconst file = this.load();\n\t\t\tconst count = Math.min((file.observations[key]?.count ?? 0) + 1, MAX_COUNT);\n\t\t\tfile.observations[key] = { count, lastAt: now };\n\t\t\tthis.evict(file);\n\t\t\tthis.save(file);\n\t\t\treturn count;\n\t\t});\n\t}\n\n\t/** Current observation count for `key` (0 if never observed). */\n\tget(key: string): number {\n\t\treturn this.load().observations[key]?.count ?? 0;\n\t}\n}\n"]}
@@ -5,7 +5,7 @@ export interface IsolatedCompletionResult {
5
5
  usage: Usage;
6
6
  stopReason: StopReason;
7
7
  }
8
- export type ReflectionTrigger = "complex" | "corrective" | "session-end" | "none";
8
+ export type ReflectionTrigger = "complex" | "corrective" | "durable" | "session-end" | "none";
9
9
  export interface DemandSignals {
10
10
  trigger: ReflectionTrigger;
11
11
  toolCallCount: number;
@@ -1 +1 @@
1
- {"version":3,"file":"reflection-engine.d.ts","sourceRoot":"","sources":["../../../src/core/learning/reflection-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAm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AA;CAAE,GAEzC;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,s4DAqBpC,CAAC;AAEF,qBAAa,gBAAgB;IAC5B;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAiF/D;CACD","sourcesContent":["import type { Usage } from \"@caupulican/pi-ai\";\n\nexport type StopReason = \"stop\" | \"toolUse\" | \"aborted\" | \"error\" | string;\n\nexport interface IsolatedCompletionResult {\n\ttext: string;\n\tusage: Usage;\n\tstopReason: StopReason;\n}\n\nexport type ReflectionTrigger = \"complex\" | \"corrective\" | \"session-end\" | \"none\";\n\nexport interface DemandSignals {\n\ttrigger: ReflectionTrigger;\n\ttoolCallCount: number;\n\thadCorrection: boolean;\n\tcontextHeadroomPct: number; // 0..100\n\tusefulLately: number; // 0..1 rolling score\n}\n\nexport interface DemandPlan {\n\tact: \"skip\" | \"reflect\";\n\treason: string;\n\ttokenBudget: number;\n}\n\n/**\n * Pure zero-I/O heuristic to decide whether the current turn justifies a reflection run\n * and determine the token budget under the cheap-tool net-negative doctrine.\n */\nexport function decideDemand(signals: DemandSignals): DemandPlan {\n\tif (signals.trigger === \"none\") {\n\t\treturn { act: \"skip\", reason: \"No trigger detected\", tokenBudget: 0 };\n\t}\n\tif (signals.contextHeadroomPct < 10) {\n\t\treturn { act: \"skip\", reason: \"Context headroom is critically low (< 10%)\", tokenBudget: 0 };\n\t}\n\n\t// Dynamic token budget based on headroom (keep reflection bounded between 500 and 1500 tokens)\n\tconst baseBudget = 1000;\n\tconst tokenBudget = Math.max(500, Math.min(1500, Math.round(baseBudget * (signals.contextHeadroomPct / 100))));\n\n\tif (signals.hadCorrection) {\n\t\treturn { act: \"reflect\", reason: \"Correction detected in the turn\", tokenBudget };\n\t}\n\tif (signals.trigger === \"session-end\") {\n\t\treturn { act: \"reflect\", reason: \"Session end reflection triggered\", tokenBudget };\n\t}\n\tif (signals.trigger === \"complex\") {\n\t\tif (signals.toolCallCount >= 3) {\n\t\t\treturn { act: \"reflect\", reason: `Complex turn with ${signals.toolCallCount} tool calls`, tokenBudget };\n\t\t}\n\t}\n\n\treturn { act: \"skip\", reason: \"Signals do not justify reflection overhead\", tokenBudget: 0 };\n}\n\nexport interface ReflectionInput {\n\trecentTurnText: string; // host serializes the just-finished turn\n\texistingMemory: string; // current MEMORY.md + USER.md snapshot\n\tplan: DemandPlan;\n\t// host-injected isolated completion function:\n\tcomplete: (systemPrompt: string, userPrompt: string) => Promise<IsolatedCompletionResult>;\n}\n\nexport type ReflectionWrite =\n\t| { kind: \"memory_add\"; section: \"MEMORY\" | \"USER\"; text: string }\n\t| { kind: \"memory_replace\"; target: string; text: string }\n\t| { kind: \"memory_remove\"; target: string }\n\t// R7 memory-to-behavior: promote a recurring procedural workflow into an executable skill.\n\t| { kind: \"promote_skill\"; name: string; description: string; body: string };\n\nexport interface ReflectionResult {\n\twrites: ReflectionWrite[];\n\tusage: Usage;\n\trationale: string;\n}\n\n/**\n * STATIC reflection system prompt (Hermes-parity #33). It is byte-identical across every reflection\n * pass — the variable parts (existing memory snapshot + the turn transcript) live in the USER prompt —\n * so the provider prompt-cache reuses this prefix instead of re-billing it each pass (cost guard).\n * Do NOT interpolate per-call data into this constant or caching breaks.\n */\nexport const REFLECTION_SYSTEM_PROMPT = `You are a reflection engine. Your job is to analyze the recent conversation turn, compare it against the agent's existing memory, and decide if any memory updates are needed.\n\nMemory guidelines:\n- \"MEMORY\" is for project facts, configuration, repeatable workflows, and coding findings.\n- \"USER\" is for user preferences, patterns, and style specifications.\n- Avoid duplicate facts. If the fact is already represented, do not add it.\n- CONFRONT existing memory: if the new turn contradicts or updates an existing fact, use \"memory_replace\" or \"memory_remove\" to supersede the old fact rather than blindly appending.\n- Keep memories short, factual, and direct. No fluff.\n- Do NOT capture transient/environment-specific noise: tool/network failures, one-off errors, or a single narrative event. Persist only durable facts and preferences.\n- PROMOTE to behavior: if the turn established a REPEATABLE, multi-step PROCEDURE/workflow (not a one-off fact) that should govern a future class of tasks, emit a \"promote_skill\" instead of (or in addition to) a memory fact. Only promote a genuinely reusable procedure — never a single fact, a one-off narrative, or environment-specific noise. Prefer a memory fact when unsure.\n\nYou must output your analysis and writes in the following JSON format inside a \\`\\`\\`json\\`\\`\\` code fence:\n{\n \"rationale\": \"Explanation of your reasoning\",\n \"writes\": [\n { \"kind\": \"memory_add\", \"section\": \"MEMORY\" | \"USER\", \"text\": \"New direct fact to append\" },\n { \"kind\": \"memory_replace\", \"target\": \"Exact text substring to replace\", \"text\": \"New replacement text\" },\n { \"kind\": \"memory_remove\", \"target\": \"Exact text substring to remove\" },\n { \"kind\": \"promote_skill\", \"name\": \"kebab-case-skill-name\", \"description\": \"one line of when to use it\", \"body\": \"Markdown: the step-by-step procedure\" }\n ]\n}\n`;\n\nexport class ReflectionEngine {\n\t/**\n\t * Build the reflection prompt, call the injected isolated complete(),\n\t * parse the response, confront existing memory, and return memory writes.\n\t * Zero direct I/O.\n\t */\n\tasync reflect(input: ReflectionInput): Promise<ReflectionResult> {\n\t\tconst systemPrompt = REFLECTION_SYSTEM_PROMPT;\n\n\t\t// Variable inputs go in the USER prompt so the system prefix above stays cache-stable (#33).\n\t\tconst userPrompt = `Existing Memory snapshot:\n${input.existingMemory}\n\nRecent turn transcript:\n${input.recentTurnText}\n\nAnalyze this turn against the existing memory and output your memory updates.`;\n\n\t\tlet usage: Usage | undefined;\n\t\ttry {\n\t\t\tconst compResult = await input.complete(systemPrompt, userPrompt);\n\t\t\tusage = compResult.usage;\n\t\t\tconst text = compResult.text;\n\n\t\t\tconst jsonMatch = text.match(/```json\\s*([\\s\\S]*?)\\s*```/) || text.match(/{[\\s\\S]*}/);\n\t\t\tif (!jsonMatch) {\n\t\t\t\treturn {\n\t\t\t\t\twrites: [],\n\t\t\t\t\tusage: compResult.usage,\n\t\t\t\t\trationale: `Failed to locate JSON response. Raw text:\\n${text}`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst parsed = JSON.parse(jsonMatch[1] || jsonMatch[0]);\n\t\t\tconst rationale = parsed.rationale || \"\";\n\t\t\tconst writes: ReflectionWrite[] = [];\n\n\t\t\tif (Array.isArray(parsed.writes)) {\n\t\t\t\tfor (const w of parsed.writes) {\n\t\t\t\t\tif (w && typeof w === \"object\") {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tw.kind === \"memory_add\" &&\n\t\t\t\t\t\t\t(w.section === \"MEMORY\" || w.section === \"USER\") &&\n\t\t\t\t\t\t\ttypeof w.text === \"string\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\twrites.push({ kind: \"memory_add\", section: w.section, text: w.text });\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tw.kind === \"memory_replace\" &&\n\t\t\t\t\t\t\ttypeof w.target === \"string\" &&\n\t\t\t\t\t\t\ttypeof w.text === \"string\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\twrites.push({ kind: \"memory_replace\", target: w.target, text: w.text });\n\t\t\t\t\t\t} else if (w.kind === \"memory_remove\" && typeof w.target === \"string\") {\n\t\t\t\t\t\t\twrites.push({ kind: \"memory_remove\", target: w.target });\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tw.kind === \"promote_skill\" &&\n\t\t\t\t\t\t\ttypeof w.name === \"string\" &&\n\t\t\t\t\t\t\ttypeof w.description === \"string\" &&\n\t\t\t\t\t\t\ttypeof w.body === \"string\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\twrites.push({ kind: \"promote_skill\", name: w.name, description: w.description, body: w.body });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\twrites,\n\t\t\t\tusage: compResult.usage,\n\t\t\t\trationale,\n\t\t\t};\n\t\t} catch (err) {\n\t\t\t// Zeroed/fallback usage representation\n\t\t\tconst emptyUsage: Usage = {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t};\n\t\t\treturn {\n\t\t\t\twrites: [],\n\t\t\t\tusage: usage ?? emptyUsage,\n\t\t\t\trationale: `Error during reflection: ${String(err)}`,\n\t\t\t};\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"reflection-engine.d.ts","sourceRoot":"","sources":["../../../src/core/learning/reflection-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAE3E,MAAM,WAAW,wBAAwB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;CACvB;AAED,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,CAAC;AAE9F,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IAC1B,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,UAAU,CA4B/D;AAED,MAAM,WAAW,eAAe;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,UAAU,CAAC;IAEjB,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,wBAAwB,CAAC,CAAC;CAC1F;AAED,MAAM,MAAM,eAAe,GACxB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,QAAQ,GAAG,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAEzC;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,s4DAqBpC,CAAC;AAEF,qBAAa,gBAAgB;IAC5B;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAiF/D;CACD"}
@@ -15,6 +15,9 @@ export function decideDemand(signals) {
15
15
  if (signals.hadCorrection) {
16
16
  return { act: "reflect", reason: "Correction detected in the turn", tokenBudget };
17
17
  }
18
+ if (signals.trigger === "durable") {
19
+ return { act: "reflect", reason: "Durable fact or preference detected in the turn", tokenBudget };
20
+ }
18
21
  if (signals.trigger === "session-end") {
19
22
  return { act: "reflect", reason: "Session end reflection triggered", tokenBudget };
20
23
  }