@caupulican/pi-adaptative 0.80.86 → 0.80.89

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 (353) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/core/agent-session.d.ts +412 -1
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +2053 -41
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/autonomy/approval-gate.d.ts +4 -0
  7. package/dist/core/autonomy/approval-gate.d.ts.map +1 -0
  8. package/dist/core/autonomy/approval-gate.js +27 -0
  9. package/dist/core/autonomy/approval-gate.js.map +1 -0
  10. package/dist/core/autonomy/bounded-completion.d.ts +27 -0
  11. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -0
  12. package/dist/core/autonomy/bounded-completion.js +44 -0
  13. package/dist/core/autonomy/bounded-completion.js.map +1 -0
  14. package/dist/core/autonomy/contracts.d.ts +129 -0
  15. package/dist/core/autonomy/contracts.d.ts.map +1 -0
  16. package/dist/core/autonomy/contracts.js +2 -0
  17. package/dist/core/autonomy/contracts.js.map +1 -0
  18. package/dist/core/autonomy/gates.d.ts +15 -0
  19. package/dist/core/autonomy/gates.d.ts.map +1 -0
  20. package/dist/core/autonomy/gates.js +205 -0
  21. package/dist/core/autonomy/gates.js.map +1 -0
  22. package/dist/core/autonomy/lane-tracker.d.ts +48 -0
  23. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -0
  24. package/dist/core/autonomy/lane-tracker.js +125 -0
  25. package/dist/core/autonomy/lane-tracker.js.map +1 -0
  26. package/dist/core/autonomy/path-scope.d.ts +9 -0
  27. package/dist/core/autonomy/path-scope.d.ts.map +1 -0
  28. package/dist/core/autonomy/path-scope.js +122 -0
  29. package/dist/core/autonomy/path-scope.js.map +1 -0
  30. package/dist/core/autonomy/risk-assessment.d.ts +3 -0
  31. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -0
  32. package/dist/core/autonomy/risk-assessment.js +122 -0
  33. package/dist/core/autonomy/risk-assessment.js.map +1 -0
  34. package/dist/core/autonomy/session-lane-record.d.ts +10 -0
  35. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -0
  36. package/dist/core/autonomy/session-lane-record.js +36 -0
  37. package/dist/core/autonomy/session-lane-record.js.map +1 -0
  38. package/dist/core/autonomy/status.d.ts +40 -0
  39. package/dist/core/autonomy/status.d.ts.map +1 -0
  40. package/dist/core/autonomy/status.js +107 -0
  41. package/dist/core/autonomy/status.js.map +1 -0
  42. package/dist/core/autonomy/subagent-prompt.d.ts +21 -0
  43. package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -0
  44. package/dist/core/autonomy/subagent-prompt.js +28 -0
  45. package/dist/core/autonomy/subagent-prompt.js.map +1 -0
  46. package/dist/core/autonomy/telemetry-events.d.ts +18 -0
  47. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -0
  48. package/dist/core/autonomy/telemetry-events.js +60 -0
  49. package/dist/core/autonomy/telemetry-events.js.map +1 -0
  50. package/dist/core/context/artifact-retrieval.d.ts +49 -0
  51. package/dist/core/context/artifact-retrieval.d.ts.map +1 -0
  52. package/dist/core/context/artifact-retrieval.js +49 -0
  53. package/dist/core/context/artifact-retrieval.js.map +1 -0
  54. package/dist/core/context/brain-curator.d.ts +88 -0
  55. package/dist/core/context/brain-curator.d.ts.map +1 -0
  56. package/dist/core/context/brain-curator.js +192 -0
  57. package/dist/core/context/brain-curator.js.map +1 -0
  58. package/dist/core/context/context-artifacts.d.ts +94 -0
  59. package/dist/core/context/context-artifacts.d.ts.map +1 -0
  60. package/dist/core/context/context-artifacts.js +307 -0
  61. package/dist/core/context/context-artifacts.js.map +1 -0
  62. package/dist/core/context/context-audit.d.ts +66 -0
  63. package/dist/core/context/context-audit.d.ts.map +1 -0
  64. package/dist/core/context/context-audit.js +173 -0
  65. package/dist/core/context/context-audit.js.map +1 -0
  66. package/dist/core/context/context-composition.d.ts +122 -0
  67. package/dist/core/context/context-composition.d.ts.map +1 -0
  68. package/dist/core/context/context-composition.js +163 -0
  69. package/dist/core/context/context-composition.js.map +1 -0
  70. package/dist/core/context/context-item.d.ts +117 -0
  71. package/dist/core/context/context-item.d.ts.map +1 -0
  72. package/dist/core/context/context-item.js +36 -0
  73. package/dist/core/context/context-item.js.map +1 -0
  74. package/dist/core/context/context-prompt-enforcement.d.ts +86 -0
  75. package/dist/core/context/context-prompt-enforcement.d.ts.map +1 -0
  76. package/dist/core/context/context-prompt-enforcement.js +168 -0
  77. package/dist/core/context/context-prompt-enforcement.js.map +1 -0
  78. package/dist/core/context/context-prompt-policy.d.ts +90 -0
  79. package/dist/core/context/context-prompt-policy.d.ts.map +1 -0
  80. package/dist/core/context/context-prompt-policy.js +73 -0
  81. package/dist/core/context/context-prompt-policy.js.map +1 -0
  82. package/dist/core/context/context-retention.d.ts +36 -0
  83. package/dist/core/context/context-retention.d.ts.map +1 -0
  84. package/dist/core/context/context-retention.js +108 -0
  85. package/dist/core/context/context-retention.js.map +1 -0
  86. package/dist/core/context/context-store.d.ts +37 -0
  87. package/dist/core/context/context-store.d.ts.map +1 -0
  88. package/dist/core/context/context-store.js +45 -0
  89. package/dist/core/context/context-store.js.map +1 -0
  90. package/dist/core/context/memory-diagnostics.d.ts +50 -0
  91. package/dist/core/context/memory-diagnostics.d.ts.map +1 -0
  92. package/dist/core/context/memory-diagnostics.js +43 -0
  93. package/dist/core/context/memory-diagnostics.js.map +1 -0
  94. package/dist/core/context/memory-index-store.d.ts +28 -0
  95. package/dist/core/context/memory-index-store.d.ts.map +1 -0
  96. package/dist/core/context/memory-index-store.js +38 -0
  97. package/dist/core/context/memory-index-store.js.map +1 -0
  98. package/dist/core/context/memory-prompt-block.d.ts +34 -0
  99. package/dist/core/context/memory-prompt-block.d.ts.map +1 -0
  100. package/dist/core/context/memory-prompt-block.js +58 -0
  101. package/dist/core/context/memory-prompt-block.js.map +1 -0
  102. package/dist/core/context/memory-provider-contract.d.ts +114 -0
  103. package/dist/core/context/memory-provider-contract.d.ts.map +1 -0
  104. package/dist/core/context/memory-provider-contract.js +121 -0
  105. package/dist/core/context/memory-provider-contract.js.map +1 -0
  106. package/dist/core/context/memory-retrieval.d.ts +27 -0
  107. package/dist/core/context/memory-retrieval.d.ts.map +1 -0
  108. package/dist/core/context/memory-retrieval.js +91 -0
  109. package/dist/core/context/memory-retrieval.js.map +1 -0
  110. package/dist/core/context/okf-memory-provider.d.ts +26 -0
  111. package/dist/core/context/okf-memory-provider.d.ts.map +1 -0
  112. package/dist/core/context/okf-memory-provider.js +154 -0
  113. package/dist/core/context/okf-memory-provider.js.map +1 -0
  114. package/dist/core/context/okf-memory.d.ts +42 -0
  115. package/dist/core/context/okf-memory.d.ts.map +1 -0
  116. package/dist/core/context/okf-memory.js +175 -0
  117. package/dist/core/context/okf-memory.js.map +1 -0
  118. package/dist/core/context/policy-engine.d.ts +66 -0
  119. package/dist/core/context/policy-engine.d.ts.map +1 -0
  120. package/dist/core/context/policy-engine.js +171 -0
  121. package/dist/core/context/policy-engine.js.map +1 -0
  122. package/dist/core/context/policy-types.d.ts +102 -0
  123. package/dist/core/context/policy-types.d.ts.map +1 -0
  124. package/dist/core/context/policy-types.js +7 -0
  125. package/dist/core/context/policy-types.js.map +1 -0
  126. package/dist/core/context/sqlite-runtime-index.d.ts +19 -0
  127. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -0
  128. package/dist/core/context/sqlite-runtime-index.js +344 -0
  129. package/dist/core/context/sqlite-runtime-index.js.map +1 -0
  130. package/dist/core/context/storage-authority.d.ts +20 -0
  131. package/dist/core/context/storage-authority.d.ts.map +1 -0
  132. package/dist/core/context/storage-authority.js +51 -0
  133. package/dist/core/context/storage-authority.js.map +1 -0
  134. package/dist/core/context/tool-output-packer.d.ts +75 -0
  135. package/dist/core/context/tool-output-packer.d.ts.map +1 -0
  136. package/dist/core/context/tool-output-packer.js +77 -0
  137. package/dist/core/context/tool-output-packer.js.map +1 -0
  138. package/dist/core/context-gc.d.ts +13 -0
  139. package/dist/core/context-gc.d.ts.map +1 -1
  140. package/dist/core/context-gc.js +6 -0
  141. package/dist/core/context-gc.js.map +1 -1
  142. package/dist/core/cost/session-usage.d.ts +20 -0
  143. package/dist/core/cost/session-usage.d.ts.map +1 -0
  144. package/dist/core/cost/session-usage.js +164 -0
  145. package/dist/core/cost/session-usage.js.map +1 -0
  146. package/dist/core/delegation/session-worker-result.d.ts +10 -0
  147. package/dist/core/delegation/session-worker-result.d.ts.map +1 -0
  148. package/dist/core/delegation/session-worker-result.js +36 -0
  149. package/dist/core/delegation/session-worker-result.js.map +1 -0
  150. package/dist/core/delegation/worker-result.d.ts +9 -0
  151. package/dist/core/delegation/worker-result.d.ts.map +1 -0
  152. package/dist/core/delegation/worker-result.js +152 -0
  153. package/dist/core/delegation/worker-result.js.map +1 -0
  154. package/dist/core/delegation/worker-runner.d.ts +58 -0
  155. package/dist/core/delegation/worker-runner.d.ts.map +1 -0
  156. package/dist/core/delegation/worker-runner.js +188 -0
  157. package/dist/core/delegation/worker-runner.js.map +1 -0
  158. package/dist/core/extensions/builtin.d.ts +5 -1
  159. package/dist/core/extensions/builtin.d.ts.map +1 -1
  160. package/dist/core/extensions/builtin.js +23 -1
  161. package/dist/core/extensions/builtin.js.map +1 -1
  162. package/dist/core/footer-data-provider.d.ts +5 -1
  163. package/dist/core/footer-data-provider.d.ts.map +1 -1
  164. package/dist/core/footer-data-provider.js +13 -0
  165. package/dist/core/footer-data-provider.js.map +1 -1
  166. package/dist/core/goals/goal-continuation-controller.d.ts +22 -0
  167. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -0
  168. package/dist/core/goals/goal-continuation-controller.js +88 -0
  169. package/dist/core/goals/goal-continuation-controller.js.map +1 -0
  170. package/dist/core/goals/goal-continuation-defaults.d.ts +10 -0
  171. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -0
  172. package/dist/core/goals/goal-continuation-defaults.js +10 -0
  173. package/dist/core/goals/goal-continuation-defaults.js.map +1 -0
  174. package/dist/core/goals/goal-continuation-prompt.d.ts +18 -0
  175. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -0
  176. package/dist/core/goals/goal-continuation-prompt.js +141 -0
  177. package/dist/core/goals/goal-continuation-prompt.js.map +1 -0
  178. package/dist/core/goals/goal-runtime-snapshot.d.ts +19 -0
  179. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -0
  180. package/dist/core/goals/goal-runtime-snapshot.js +23 -0
  181. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -0
  182. package/dist/core/goals/goal-state.d.ts +87 -0
  183. package/dist/core/goals/goal-state.d.ts.map +1 -0
  184. package/dist/core/goals/goal-state.js +259 -0
  185. package/dist/core/goals/goal-state.js.map +1 -0
  186. package/dist/core/goals/goal-tool-core.d.ts +66 -0
  187. package/dist/core/goals/goal-tool-core.d.ts.map +1 -0
  188. package/dist/core/goals/goal-tool-core.js +146 -0
  189. package/dist/core/goals/goal-tool-core.js.map +1 -0
  190. package/dist/core/goals/session-goal-state.d.ts +10 -0
  191. package/dist/core/goals/session-goal-state.d.ts.map +1 -0
  192. package/dist/core/goals/session-goal-state.js +35 -0
  193. package/dist/core/goals/session-goal-state.js.map +1 -0
  194. package/dist/core/learning/learning-audit.d.ts +45 -0
  195. package/dist/core/learning/learning-audit.d.ts.map +1 -0
  196. package/dist/core/learning/learning-audit.js +139 -0
  197. package/dist/core/learning/learning-audit.js.map +1 -0
  198. package/dist/core/learning/learning-gate.d.ts +29 -0
  199. package/dist/core/learning/learning-gate.d.ts.map +1 -0
  200. package/dist/core/learning/learning-gate.js +150 -0
  201. package/dist/core/learning/learning-gate.js.map +1 -0
  202. package/dist/core/learning/session-learning-decision.d.ts +10 -0
  203. package/dist/core/learning/session-learning-decision.d.ts.map +1 -0
  204. package/dist/core/learning/session-learning-decision.js +36 -0
  205. package/dist/core/learning/session-learning-decision.js.map +1 -0
  206. package/dist/core/model-capability.d.ts +41 -0
  207. package/dist/core/model-capability.d.ts.map +1 -0
  208. package/dist/core/model-capability.js +101 -0
  209. package/dist/core/model-capability.js.map +1 -0
  210. package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
  211. package/dist/core/model-router/config-diagnostics.js +1 -0
  212. package/dist/core/model-router/config-diagnostics.js.map +1 -1
  213. package/dist/core/model-router/intent-classifier.d.ts +2 -0
  214. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  215. package/dist/core/model-router/intent-classifier.js +154 -9
  216. package/dist/core/model-router/intent-classifier.js.map +1 -1
  217. package/dist/core/model-router/route-judge.d.ts +54 -0
  218. package/dist/core/model-router/route-judge.d.ts.map +1 -0
  219. package/dist/core/model-router/route-judge.js +128 -0
  220. package/dist/core/model-router/route-judge.js.map +1 -0
  221. package/dist/core/model-router/status.d.ts +4 -1
  222. package/dist/core/model-router/status.d.ts.map +1 -1
  223. package/dist/core/model-router/status.js +30 -6
  224. package/dist/core/model-router/status.js.map +1 -1
  225. package/dist/core/model-router/tool-escalation.d.ts +4 -6
  226. package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
  227. package/dist/core/model-router/tool-escalation.js +1 -1
  228. package/dist/core/model-router/tool-escalation.js.map +1 -1
  229. package/dist/core/models/fitness-store.d.ts +40 -0
  230. package/dist/core/models/fitness-store.d.ts.map +1 -0
  231. package/dist/core/models/fitness-store.js +61 -0
  232. package/dist/core/models/fitness-store.js.map +1 -0
  233. package/dist/core/profile-registry.d.ts.map +1 -1
  234. package/dist/core/profile-registry.js +1 -1
  235. package/dist/core/profile-registry.js.map +1 -1
  236. package/dist/core/prompt-templates.d.ts +2 -0
  237. package/dist/core/prompt-templates.d.ts.map +1 -1
  238. package/dist/core/prompt-templates.js +12 -4
  239. package/dist/core/prompt-templates.js.map +1 -1
  240. package/dist/core/research/automata-provider.d.ts +5 -0
  241. package/dist/core/research/automata-provider.d.ts.map +1 -0
  242. package/dist/core/research/automata-provider.js +15 -0
  243. package/dist/core/research/automata-provider.js.map +1 -0
  244. package/dist/core/research/evidence-bundle.d.ts +10 -0
  245. package/dist/core/research/evidence-bundle.d.ts.map +1 -0
  246. package/dist/core/research/evidence-bundle.js +116 -0
  247. package/dist/core/research/evidence-bundle.js.map +1 -0
  248. package/dist/core/research/model-fitness.d.ts +82 -0
  249. package/dist/core/research/model-fitness.d.ts.map +1 -0
  250. package/dist/core/research/model-fitness.js +308 -0
  251. package/dist/core/research/model-fitness.js.map +1 -0
  252. package/dist/core/research/research-gate.d.ts +11 -0
  253. package/dist/core/research/research-gate.d.ts.map +1 -0
  254. package/dist/core/research/research-gate.js +82 -0
  255. package/dist/core/research/research-gate.js.map +1 -0
  256. package/dist/core/research/research-runner.d.ts +59 -0
  257. package/dist/core/research/research-runner.d.ts.map +1 -0
  258. package/dist/core/research/research-runner.js +155 -0
  259. package/dist/core/research/research-runner.js.map +1 -0
  260. package/dist/core/research/session-evidence-bundle.d.ts +11 -0
  261. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -0
  262. package/dist/core/research/session-evidence-bundle.js +55 -0
  263. package/dist/core/research/session-evidence-bundle.js.map +1 -0
  264. package/dist/core/resource-loader.d.ts.map +1 -1
  265. package/dist/core/resource-loader.js +4 -0
  266. package/dist/core/resource-loader.js.map +1 -1
  267. package/dist/core/settings-manager.d.ts +160 -4
  268. package/dist/core/settings-manager.d.ts.map +1 -1
  269. package/dist/core/settings-manager.js +304 -9
  270. package/dist/core/settings-manager.js.map +1 -1
  271. package/dist/core/skills.d.ts +4 -0
  272. package/dist/core/skills.d.ts.map +1 -1
  273. package/dist/core/skills.js +18 -6
  274. package/dist/core/skills.js.map +1 -1
  275. package/dist/core/slash-commands.d.ts.map +1 -1
  276. package/dist/core/slash-commands.js +10 -1
  277. package/dist/core/slash-commands.js.map +1 -1
  278. package/dist/core/toolkit/script-registry.d.ts +34 -0
  279. package/dist/core/toolkit/script-registry.d.ts.map +1 -0
  280. package/dist/core/toolkit/script-registry.js +71 -0
  281. package/dist/core/toolkit/script-registry.js.map +1 -0
  282. package/dist/core/toolkit/script-runner.d.ts +28 -0
  283. package/dist/core/toolkit/script-runner.d.ts.map +1 -0
  284. package/dist/core/toolkit/script-runner.js +48 -0
  285. package/dist/core/toolkit/script-runner.js.map +1 -0
  286. package/dist/core/tools/artifact-retrieve.d.ts +23 -0
  287. package/dist/core/tools/artifact-retrieve.d.ts.map +1 -0
  288. package/dist/core/tools/artifact-retrieve.js +110 -0
  289. package/dist/core/tools/artifact-retrieve.js.map +1 -0
  290. package/dist/core/tools/delegate.d.ts +32 -0
  291. package/dist/core/tools/delegate.d.ts.map +1 -0
  292. package/dist/core/tools/delegate.js +60 -0
  293. package/dist/core/tools/delegate.js.map +1 -0
  294. package/dist/core/tools/fff-search-backend.d.ts +103 -0
  295. package/dist/core/tools/fff-search-backend.d.ts.map +1 -0
  296. package/dist/core/tools/fff-search-backend.js +151 -0
  297. package/dist/core/tools/fff-search-backend.js.map +1 -0
  298. package/dist/core/tools/find.d.ts +21 -1
  299. package/dist/core/tools/find.d.ts.map +1 -1
  300. package/dist/core/tools/find.js +183 -10
  301. package/dist/core/tools/find.js.map +1 -1
  302. package/dist/core/tools/goal.d.ts +35 -0
  303. package/dist/core/tools/goal.d.ts.map +1 -0
  304. package/dist/core/tools/goal.js +122 -0
  305. package/dist/core/tools/goal.js.map +1 -0
  306. package/dist/core/tools/grep.d.ts +21 -1
  307. package/dist/core/tools/grep.d.ts.map +1 -1
  308. package/dist/core/tools/grep.js +272 -27
  309. package/dist/core/tools/grep.js.map +1 -1
  310. package/dist/core/tools/index.d.ts +4 -1
  311. package/dist/core/tools/index.d.ts.map +1 -1
  312. package/dist/core/tools/index.js +9 -0
  313. package/dist/core/tools/index.js.map +1 -1
  314. package/dist/core/tools/model-fitness.d.ts +30 -0
  315. package/dist/core/tools/model-fitness.d.ts.map +1 -0
  316. package/dist/core/tools/model-fitness.js +38 -0
  317. package/dist/core/tools/model-fitness.js.map +1 -0
  318. package/dist/core/tools/run-toolkit-script.d.ts +24 -0
  319. package/dist/core/tools/run-toolkit-script.d.ts.map +1 -0
  320. package/dist/core/tools/run-toolkit-script.js +103 -0
  321. package/dist/core/tools/run-toolkit-script.js.map +1 -0
  322. package/dist/core/tools/search-router.d.ts +75 -0
  323. package/dist/core/tools/search-router.d.ts.map +1 -0
  324. package/dist/core/tools/search-router.js +85 -0
  325. package/dist/core/tools/search-router.js.map +1 -0
  326. package/dist/modes/interactive/components/fitness-role-selector.d.ts +13 -0
  327. package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -0
  328. package/dist/modes/interactive/components/fitness-role-selector.js +65 -0
  329. package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -0
  330. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  331. package/dist/modes/interactive/components/footer.js +18 -16
  332. package/dist/modes/interactive/components/footer.js.map +1 -1
  333. package/dist/modes/interactive/components/settings-selector.d.ts +16 -1
  334. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  335. package/dist/modes/interactive/components/settings-selector.js +555 -11
  336. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  337. package/dist/modes/interactive/interactive-mode.d.ts +9 -0
  338. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  339. package/dist/modes/interactive/interactive-mode.js +308 -39
  340. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  341. package/dist/utils/tools-manager.d.ts +2 -0
  342. package/dist/utils/tools-manager.d.ts.map +1 -1
  343. package/dist/utils/tools-manager.js +154 -2
  344. package/dist/utils/tools-manager.js.map +1 -1
  345. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  346. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  347. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  348. package/examples/extensions/sandbox/package-lock.json +2 -2
  349. package/examples/extensions/sandbox/package.json +1 -1
  350. package/examples/extensions/with-deps/package-lock.json +2 -2
  351. package/examples/extensions/with-deps/package.json +1 -1
  352. package/npm-shrinkwrap.json +368 -12
  353. package/package.json +5 -4
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createGoalState,\n\ttype GoalEvent,\n\ttype GoalEvidenceKind,\n\ttype GoalState,\n} from \"./goal-state.ts\";\n\n/**\n * Agent-facing goal ledger actions.\n *\n * This is the producer half of the goal continuation pipeline: the agent records\n * what it is trying to achieve and how far it has gotten, and those records become\n * the {@link GoalState} snapshots that the runtime continuation consumer reads.\n *\n * Each action maps onto either {@link createGoalState} or a single\n * {@link GoalEvent}, so the durable state model stays the single source of truth.\n */\nexport type GoalAction =\n\t| { action: \"start\"; goalId: string; userGoal: string }\n\t| { action: \"add_requirement\"; requirementId: string; text: string }\n\t| { action: \"satisfy_requirement\"; requirementId: string; evidenceIds?: readonly string[] }\n\t| { action: \"block_requirement\"; requirementId: string; reason: string }\n\t| { action: \"add_evidence\"; evidenceId: string; kind: GoalEvidenceKind; summary: string; uri?: string }\n\t| { action: \"progress\" }\n\t| { action: \"no_progress\" }\n\t| { action: \"complete\" }\n\t| { action: \"block_goal\"; reason: string }\n\t| { action: \"cancel\" };\n\nexport type GoalActionName = GoalAction[\"action\"];\n\nexport interface GoalActionSuccess {\n\tok: true;\n\tstate: GoalState;\n}\n\nexport interface GoalActionFailure {\n\tok: false;\n\terror: string;\n}\n\nexport type GoalActionResult = GoalActionSuccess | GoalActionFailure;\n\nfunction requirementExists(state: GoalState, requirementId: string): boolean {\n\treturn state.requirements.some((requirement) => requirement.id === requirementId);\n}\n\nfunction evidenceExists(state: GoalState, evidenceId: string): boolean {\n\treturn state.evidence.some((evidence) => evidence.id === evidenceId);\n}\n\n/**\n * Apply one agent-facing goal action to the current ledger state.\n *\n * Pure: takes the current state (or `undefined` when no goal exists yet) and the\n * action, and returns either the next state or a validation error. Performs no\n * I/O and never mutates its inputs.\n */\nexport function applyGoalAction(current: GoalState | undefined, action: GoalAction, now: string): GoalActionResult {\n\tif (action.action === \"start\") {\n\t\tconst goalId = action.goalId.trim();\n\t\tconst userGoal = action.userGoal.trim();\n\t\tif (!goalId) return { ok: false, error: \"start requires a non-empty goalId.\" };\n\t\tif (!userGoal) return { ok: false, error: \"start requires a non-empty userGoal.\" };\n\t\tif (current && current.status === \"active\" && current.goalId !== goalId) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror: `An active goal '${current.goalId}' already exists. Complete, block, or cancel it before starting '${goalId}'.`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true, state: createGoalState({ goalId, userGoal, now }) };\n\t}\n\n\tif (!current) {\n\t\treturn { ok: false, error: \"No active goal. Use action 'start' before recording goal updates.\" };\n\t}\n\n\tif (current.status !== \"active\") {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: `Goal '${current.goalId}' is ${current.status}; start a new goal before recording updates.`,\n\t\t};\n\t}\n\n\tconst event = toGoalEvent(current, action, now);\n\tif (!event.ok) return event;\n\treturn { ok: true, state: applyGoalEvent(current, event.event) };\n}\n\ntype ToGoalEventResult = { ok: true; event: GoalEvent } | GoalActionFailure;\n\nfunction toGoalEvent(state: GoalState, action: GoalAction, now: string): ToGoalEventResult {\n\tswitch (action.action) {\n\t\tcase \"add_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tconst text = action.text.trim();\n\t\t\tif (!id) return { ok: false, error: \"add_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!text) return { ok: false, error: \"add_requirement requires non-empty text.\" };\n\t\t\tif (requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Requirement '${id}' already exists.` };\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"add_requirement\", id, text, now } };\n\t\t}\n\t\tcase \"satisfy_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tif (!id) return { ok: false, error: \"satisfy_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\tconst evidenceIds = action.evidenceIds ?? [];\n\t\t\tfor (const evidenceId of evidenceIds) {\n\t\t\t\tif (!evidenceExists(state, evidenceId)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tok: false,\n\t\t\t\t\t\terror: `Unknown evidence '${evidenceId}'. Record it with action 'add_evidence' first.`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"satisfy_requirement\", id, evidenceIds: [...evidenceIds], now } };\n\t\t}\n\t\tcase \"block_requirement\": {\n\t\t\tconst id = action.requirementId.trim();\n\t\t\tconst reason = action.reason.trim();\n\t\t\tif (!id) return { ok: false, error: \"block_requirement requires a non-empty requirementId.\" };\n\t\t\tif (!reason) return { ok: false, error: \"block_requirement requires a non-empty reason.\" };\n\t\t\tif (!requirementExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Unknown requirement '${id}'.` };\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"block_requirement\", id, blockedReason: reason, now } };\n\t\t}\n\t\tcase \"add_evidence\": {\n\t\t\tconst id = action.evidenceId.trim();\n\t\t\tconst summary = action.summary.trim();\n\t\t\tif (!id) return { ok: false, error: \"add_evidence requires a non-empty evidenceId.\" };\n\t\t\tif (!summary) return { ok: false, error: \"add_evidence requires a non-empty summary.\" };\n\t\t\tif (evidenceExists(state, id)) {\n\t\t\t\treturn { ok: false, error: `Evidence '${id}' already exists.` };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tevent: { type: \"add_evidence\", id, kind: action.kind, summary, uri: action.uri?.trim() || undefined, now },\n\t\t\t};\n\t\t}\n\t\tcase \"progress\":\n\t\t\treturn { ok: true, event: { type: \"progress\", now } };\n\t\tcase \"no_progress\":\n\t\t\treturn { ok: true, event: { type: \"no_progress\", now } };\n\t\tcase \"complete\": {\n\t\t\tconst unsatisfied = state.requirements.filter((requirement) => requirement.status !== \"satisfied\");\n\t\t\tif (unsatisfied.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `Cannot complete goal: ${unsatisfied.length} requirement(s) not satisfied (${unsatisfied\n\t\t\t\t\t\t.map((requirement) => requirement.id)\n\t\t\t\t\t\t.join(\", \")}).`,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: true, event: { type: \"complete_goal\", now } };\n\t\t}\n\t\tcase \"block_goal\": {\n\t\t\tconst reason = action.reason.trim();\n\t\t\tif (!reason) return { ok: false, error: \"block_goal requires a non-empty reason.\" };\n\t\t\treturn { ok: true, event: { type: \"block_goal\", reason, now } };\n\t\t}\n\t\tcase \"cancel\":\n\t\t\treturn { ok: true, event: { type: \"cancel_goal\", now } };\n\t\tdefault:\n\t\t\treturn { ok: false, error: \"Unknown goal action.\" };\n\t}\n}\n\n/** Render a compact human-readable summary of the ledger after an action. */\nexport function summarizeGoalState(state: GoalState): string {\n\tconst open = state.requirements.filter((requirement) => requirement.status === \"open\").length;\n\tconst satisfied = state.requirements.filter((requirement) => requirement.status === \"satisfied\").length;\n\tconst blocked = state.requirements.filter((requirement) => requirement.status === \"blocked\").length;\n\tconst lines = [\n\t\t`Goal '${state.goalId}' (${state.status}): ${state.userGoal}`,\n\t\t`Requirements: ${state.requirements.length} total — ${open} open, ${satisfied} satisfied, ${blocked} blocked.`,\n\t\t`Evidence: ${state.evidence.length}. Stall turns: ${state.stallTurns}.`,\n\t];\n\tif (state.blockedReason) lines.push(`Blocked reason: ${state.blockedReason}`);\n\treturn lines.join(\"\\n\");\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { SessionEntry, SessionManager } from "../session-manager.ts";
2
+ import { type GoalState } from "./goal-state.ts";
3
+ export declare const GOAL_STATE_CUSTOM_TYPE = "goal_state";
4
+ export interface GoalStateSnapshotPayload {
5
+ version: 1;
6
+ state: GoalState;
7
+ }
8
+ export declare function appendGoalStateSnapshot(sessionManager: Pick<SessionManager, "appendCustomEntry">, state: GoalState): string;
9
+ export declare function getLatestGoalStateSnapshot(entries: readonly SessionEntry[]): GoalState | undefined;
10
+ //# sourceMappingURL=session-goal-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-goal-state.d.ts","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAA4B,KAAK,SAAS,EAAe,MAAM,iBAAiB,CAAC;AAExF,eAAO,MAAM,sBAAsB,eAAe,CAAC;AAEnD,MAAM,WAAW,wBAAwB;IACxC,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,KAAK,EAAE,SAAS,GACd,MAAM,CAMR;AAQD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,GAAG,SAAS,CAelG","sourcesContent":["import type { SessionEntry, SessionManager } from \"../session-manager.ts\";\nimport { cloneGoalStateForStorage, type GoalState, isGoalState } from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport interface GoalStateSnapshotPayload {\n\tversion: 1;\n\tstate: GoalState;\n}\n\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\tconst payload: GoalStateSnapshotPayload = {\n\t\tversion: 1,\n\t\tstate: cloneGoalStateForStorage(state),\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLatestGoalStateSnapshot(entries: readonly SessionEntry[]): GoalState | undefined {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type === \"custom\" && entry.customType === GOAL_STATE_CUSTOM_TYPE) {\n\t\t\tconst payload = entry.data;\n\t\t\tif (!isPlainRecord(payload)) continue;\n\t\t\tif (payload.version !== 1) continue;\n\t\t\tif (!(\"state\" in payload)) continue;\n\t\t\tconst state = payload.state;\n\t\t\tif (isGoalState(state)) {\n\t\t\t\treturn cloneGoalStateForStorage(state);\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { cloneGoalStateForStorage, isGoalState } from "./goal-state.js";
2
+ export const GOAL_STATE_CUSTOM_TYPE = "goal_state";
3
+ export function appendGoalStateSnapshot(sessionManager, state) {
4
+ const payload = {
5
+ version: 1,
6
+ state: cloneGoalStateForStorage(state),
7
+ };
8
+ return sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);
9
+ }
10
+ function isPlainRecord(value) {
11
+ if (!value || typeof value !== "object" || Array.isArray(value))
12
+ return false;
13
+ const prototype = Object.getPrototypeOf(value);
14
+ return prototype === Object.prototype || prototype === null;
15
+ }
16
+ export function getLatestGoalStateSnapshot(entries) {
17
+ for (let i = entries.length - 1; i >= 0; i--) {
18
+ const entry = entries[i];
19
+ if (entry.type === "custom" && entry.customType === GOAL_STATE_CUSTOM_TYPE) {
20
+ const payload = entry.data;
21
+ if (!isPlainRecord(payload))
22
+ continue;
23
+ if (payload.version !== 1)
24
+ continue;
25
+ if (!("state" in payload))
26
+ continue;
27
+ const state = payload.state;
28
+ if (isGoalState(state)) {
29
+ return cloneGoalStateForStorage(state);
30
+ }
31
+ }
32
+ }
33
+ return undefined;
34
+ }
35
+ //# sourceMappingURL=session-goal-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-goal-state.js","sourceRoot":"","sources":["../../../src/core/goals/session-goal-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAkB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAExF,MAAM,CAAC,MAAM,sBAAsB,GAAG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CAAC,CAAC;YACxC,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAAA,CACjB","sourcesContent":["import type { SessionEntry, SessionManager } from \"../session-manager.ts\";\nimport { cloneGoalStateForStorage, type GoalState, isGoalState } from \"./goal-state.ts\";\n\nexport const GOAL_STATE_CUSTOM_TYPE = \"goal_state\";\n\nexport interface GoalStateSnapshotPayload {\n\tversion: 1;\n\tstate: GoalState;\n}\n\nexport function appendGoalStateSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tstate: GoalState,\n): string {\n\tconst payload: GoalStateSnapshotPayload = {\n\t\tversion: 1,\n\t\tstate: cloneGoalStateForStorage(state),\n\t};\n\treturn sessionManager.appendCustomEntry(GOAL_STATE_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLatestGoalStateSnapshot(entries: readonly SessionEntry[]): GoalState | undefined {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type === \"custom\" && entry.customType === GOAL_STATE_CUSTOM_TYPE) {\n\t\t\tconst payload = entry.data;\n\t\t\tif (!isPlainRecord(payload)) continue;\n\t\t\tif (payload.version !== 1) continue;\n\t\t\tif (!(\"state\" in payload)) continue;\n\t\t\tconst state = payload.state;\n\t\t\tif (isGoalState(state)) {\n\t\t\t\treturn cloneGoalStateForStorage(state);\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n"]}
@@ -0,0 +1,45 @@
1
+ import type { LearningDecision } from "../autonomy/contracts.ts";
2
+ import type { SessionEntry, SessionManager } from "../session-manager.ts";
3
+ import type { DurableChangeLayer, DurableChangeProposal } from "./learning-gate.ts";
4
+ import type { ReflectionWrite } from "./reflection-engine.ts";
5
+ /**
6
+ * Audit + rollback metadata for durable learning changes. Every reflection-sourced write that the
7
+ * learning policy applies (or converts to a proposal) leaves one of these records in the session
8
+ * log, so `/autonomy diagnostics` can explain what changed, why, and how to undo it — and
9
+ * `rollbackLearningWrite` can execute the inverse operation.
10
+ */
11
+ export type LearningRollbackKind = "memory_remove" | "memory_restore" | "memory_add" | "archive_skill";
12
+ export interface LearningRollbackPlan {
13
+ kind: LearningRollbackKind;
14
+ /** Text currently present because of the change (to remove/replace), or the skill name to archive. */
15
+ target?: string;
16
+ /** Original text to restore (memory_restore/memory_add). */
17
+ previous?: string;
18
+ instructions: string;
19
+ }
20
+ export type LearningAuditAction = "apply" | "propose" | "rollback";
21
+ export interface LearningAuditRecord {
22
+ id: string;
23
+ proposalId: string;
24
+ layer: DurableChangeLayer;
25
+ action: LearningAuditAction;
26
+ summary: string;
27
+ reasonCode: string;
28
+ decision: LearningDecision;
29
+ rollback?: LearningRollbackPlan;
30
+ /** For action "rollback": the audit id of the applied change this record undoes. */
31
+ rollbackOf?: string;
32
+ createdAt: string;
33
+ }
34
+ export declare function proposalFromReflectionWrite(write: ReflectionWrite, proposalId: string): DurableChangeProposal;
35
+ export declare function rollbackPlanForReflectionWrite(write: ReflectionWrite): LearningRollbackPlan;
36
+ export declare function isLearningAuditRecord(value: unknown): value is LearningAuditRecord;
37
+ export declare function cloneLearningAuditRecordForStorage(record: LearningAuditRecord): LearningAuditRecord;
38
+ export declare const LEARNING_AUDIT_CUSTOM_TYPE = "learning_audit";
39
+ export interface LearningAuditSnapshotPayload {
40
+ version: 1;
41
+ record: LearningAuditRecord;
42
+ }
43
+ export declare function appendLearningAuditSnapshot(sessionManager: Pick<SessionManager, "appendCustomEntry">, record: LearningAuditRecord): string;
44
+ export declare function getLearningAuditSnapshots(entries: readonly SessionEntry[]): LearningAuditRecord[];
45
+ //# sourceMappingURL=learning-audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learning-audit.d.ts","sourceRoot":"","sources":["../../../src/core/learning/lear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AAO,GAAG,KAAK,IAAI,mBAAmB,CAYlF;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,CAMnG;AAED,eAAO,MAAM,0BAA0B,mBAAmB,CAAC;AAE3D,MAAM,WAAW,4BAA4B;IAC5C,OAAO,EAAE,CAAC,CAAC;IACX,MAAM,EAAE,mBAAmB,CAAC;CAC5B;AAED,wBAAgB,2BAA2B,CAC1C,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,MAAM,EAAE,mBAAmB,GACzB,MAAM,CAMR;AAQD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,mBAAmB,EAAE,CAmBjG","sourcesContent":["import type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport type { SessionEntry, SessionManager } from \"../session-manager.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\nexport type LearningAuditAction = \"apply\" | \"propose\" | \"rollback\";\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\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\", \"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 interface LearningAuditSnapshotPayload {\n\tversion: 1;\n\trecord: LearningAuditRecord;\n}\n\nexport function appendLearningAuditSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LearningAuditRecord,\n): string {\n\tconst payload: LearningAuditSnapshotPayload = {\n\t\tversion: 1,\n\t\trecord: cloneLearningAuditRecordForStorage(record),\n\t};\n\treturn sessionManager.appendCustomEntry(LEARNING_AUDIT_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLearningAuditSnapshots(entries: readonly SessionEntry[]): LearningAuditRecord[] {\n\tconst records: LearningAuditRecord[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== LEARNING_AUDIT_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"record\" in payload)) continue;\n\t\tconst record = payload.record;\n\t\tif (isLearningAuditRecord(record)) {\n\t\t\trecords.push(cloneLearningAuditRecordForStorage(record));\n\t\t}\n\t}\n\n\treturn records;\n}\n"]}
@@ -0,0 +1,139 @@
1
+ function describeWrite(write) {
2
+ switch (write.kind) {
3
+ case "memory_add":
4
+ return `Add ${write.section} memory: ${write.text}`;
5
+ case "memory_replace":
6
+ return `Replace memory "${write.target}" with "${write.text}"`;
7
+ case "memory_remove":
8
+ return `Remove memory: ${write.target}`;
9
+ case "promote_skill":
10
+ return `Promote skill "${write.name}": ${write.description}`;
11
+ }
12
+ }
13
+ export function proposalFromReflectionWrite(write, proposalId) {
14
+ return {
15
+ id: proposalId,
16
+ layer: write.kind === "promote_skill" ? "skill" : "memory",
17
+ summary: describeWrite(write),
18
+ rollbackPlan: rollbackPlanForReflectionWrite(write).instructions,
19
+ };
20
+ }
21
+ export function rollbackPlanForReflectionWrite(write) {
22
+ switch (write.kind) {
23
+ case "memory_add":
24
+ return {
25
+ kind: "memory_remove",
26
+ target: write.text,
27
+ instructions: `Remove the added ${write.section} memory text.`,
28
+ };
29
+ case "memory_replace":
30
+ return {
31
+ kind: "memory_restore",
32
+ target: write.text,
33
+ previous: write.target,
34
+ instructions: "Replace the new memory text with the original text it overwrote.",
35
+ };
36
+ case "memory_remove":
37
+ return {
38
+ kind: "memory_add",
39
+ previous: write.target,
40
+ instructions: "Re-add the removed text to the MEMORY file (it may originally have lived in USER).",
41
+ };
42
+ case "promote_skill":
43
+ return {
44
+ kind: "archive_skill",
45
+ target: write.name,
46
+ instructions: "Archive the promoted skill so it no longer loads.",
47
+ };
48
+ }
49
+ }
50
+ const AUDIT_ACTIONS = ["apply", "propose", "rollback"];
51
+ const ROLLBACK_KINDS = ["memory_remove", "memory_restore", "memory_add", "archive_skill"];
52
+ const LAYERS = ["memory", "skill", "prompt", "extension", "tool", "script", "settings", "source"];
53
+ function isOptionalString(value) {
54
+ return value === undefined || typeof value === "string";
55
+ }
56
+ function isLearningRollbackPlan(value) {
57
+ if (!value || typeof value !== "object" || Array.isArray(value))
58
+ return false;
59
+ const plan = value;
60
+ if (typeof plan.kind !== "string" || !ROLLBACK_KINDS.includes(plan.kind))
61
+ return false;
62
+ if (!isOptionalString(plan.target) || !isOptionalString(plan.previous))
63
+ return false;
64
+ return typeof plan.instructions === "string";
65
+ }
66
+ function isLearningDecisionShape(value) {
67
+ if (!value || typeof value !== "object" || Array.isArray(value))
68
+ return false;
69
+ const decision = value;
70
+ return ((decision.kind === "no-op" || decision.kind === "proposal" || decision.kind === "apply") &&
71
+ typeof decision.reasonCode === "string" &&
72
+ typeof decision.confidence === "number" &&
73
+ typeof decision.summary === "string" &&
74
+ typeof decision.requiresApproval === "boolean");
75
+ }
76
+ export function isLearningAuditRecord(value) {
77
+ if (!value || typeof value !== "object" || Array.isArray(value))
78
+ return false;
79
+ const record = value;
80
+ if (typeof record.id !== "string" || record.id.length === 0)
81
+ return false;
82
+ if (typeof record.proposalId !== "string")
83
+ return false;
84
+ if (typeof record.layer !== "string" || !LAYERS.includes(record.layer))
85
+ return false;
86
+ if (typeof record.action !== "string" || !AUDIT_ACTIONS.includes(record.action))
87
+ return false;
88
+ if (typeof record.summary !== "string" || typeof record.reasonCode !== "string")
89
+ return false;
90
+ if (!isLearningDecisionShape(record.decision))
91
+ return false;
92
+ if (record.rollback !== undefined && !isLearningRollbackPlan(record.rollback))
93
+ return false;
94
+ if (!isOptionalString(record.rollbackOf))
95
+ return false;
96
+ return typeof record.createdAt === "string";
97
+ }
98
+ export function cloneLearningAuditRecordForStorage(record) {
99
+ return {
100
+ ...record,
101
+ decision: { ...record.decision },
102
+ ...(record.rollback ? { rollback: { ...record.rollback } } : {}),
103
+ };
104
+ }
105
+ export const LEARNING_AUDIT_CUSTOM_TYPE = "learning_audit";
106
+ export function appendLearningAuditSnapshot(sessionManager, record) {
107
+ const payload = {
108
+ version: 1,
109
+ record: cloneLearningAuditRecordForStorage(record),
110
+ };
111
+ return sessionManager.appendCustomEntry(LEARNING_AUDIT_CUSTOM_TYPE, payload);
112
+ }
113
+ function isPlainRecord(value) {
114
+ if (!value || typeof value !== "object" || Array.isArray(value))
115
+ return false;
116
+ const prototype = Object.getPrototypeOf(value);
117
+ return prototype === Object.prototype || prototype === null;
118
+ }
119
+ export function getLearningAuditSnapshots(entries) {
120
+ const records = [];
121
+ for (const entry of entries) {
122
+ if (entry.type !== "custom" || entry.customType !== LEARNING_AUDIT_CUSTOM_TYPE) {
123
+ continue;
124
+ }
125
+ const payload = entry.data;
126
+ if (!isPlainRecord(payload))
127
+ continue;
128
+ if (payload.version !== 1)
129
+ continue;
130
+ if (!("record" in payload))
131
+ continue;
132
+ const record = payload.record;
133
+ if (isLearningAuditRecord(record)) {
134
+ records.push(cloneLearningAuditRecordForStorage(record));
135
+ }
136
+ }
137
+ return records;
138
+ }
139
+ //# sourceMappingURL=learning-audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learning-audit.js","sourceRoot":"","sources":["../../../src/core/learning/learning-audit.ts"],"names":[],"mappings":"AAuCA,SAAS,aAAa,CAAC,KAAsB,EAAU;IACtD,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;AAAA,CACD;AAED,MAAM,UAAU,2BAA2B,CAAC,KAAsB,EAAE,UAAkB,EAAyB;IAC9G,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,CAAC,CAAC,YAAY;KAChE,CAAC;AAAA,CACF;AAED,MAAM,UAAU,8BAA8B,CAAC,KAAsB,EAAwB;IAC5F,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,YAAY;Y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V,MAAM,EAAE,kCAAkC,CAAC,MAAM,CAAC;KAClD,CAAC;IACF,OAAO,cAAc,CAAC,iBAAiB,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;AAAA,CAC7E;AAED,SAAS,aAAa,CAAC,KAAc,EAAoC;IACxE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAAA,CAC5D;AAED,MAAM,UAAU,yBAAyB,CAAC,OAAgC,EAAyB;IAClG,MAAM,OAAO,GAA0B,EAAE,CAAC;IAE1C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,0BAA0B,EAAE,CAAC;YAChF,SAAS;QACV,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAAE,SAAS;QACtC,IAAI,OAAO,CAAC,OAAO,KAAK,CAAC;YAAE,SAAS;QACpC,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC;YAAE,SAAS;QACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport type { SessionEntry, SessionManager } from \"../session-manager.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\nexport type LearningAuditAction = \"apply\" | \"propose\" | \"rollback\";\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\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\", \"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 interface LearningAuditSnapshotPayload {\n\tversion: 1;\n\trecord: LearningAuditRecord;\n}\n\nexport function appendLearningAuditSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LearningAuditRecord,\n): string {\n\tconst payload: LearningAuditSnapshotPayload = {\n\t\tversion: 1,\n\t\trecord: cloneLearningAuditRecordForStorage(record),\n\t};\n\treturn sessionManager.appendCustomEntry(LEARNING_AUDIT_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLearningAuditSnapshots(entries: readonly SessionEntry[]): LearningAuditRecord[] {\n\tconst records: LearningAuditRecord[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== LEARNING_AUDIT_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"record\" in payload)) continue;\n\t\tconst record = payload.record;\n\t\tif (isLearningAuditRecord(record)) {\n\t\t\trecords.push(cloneLearningAuditRecordForStorage(record));\n\t\t}\n\t}\n\n\treturn records;\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import type { LearningDecision } from "../autonomy/contracts.ts";
2
+ export type DurableChangeLayer = "memory" | "skill" | "prompt" | "extension" | "tool" | "script" | "settings" | "source";
3
+ export interface DurableChangeProposal {
4
+ id: string;
5
+ layer: DurableChangeLayer;
6
+ summary: string;
7
+ evidenceIds?: readonly string[];
8
+ rollbackPlan?: string;
9
+ }
10
+ export interface LearningGateSettings {
11
+ enabled: boolean;
12
+ autoApplyEnabled: boolean;
13
+ confidenceThreshold: number;
14
+ minObservations: number;
15
+ allowedAutoApplyLayers: readonly DurableChangeLayer[];
16
+ requireRollbackPlan?: boolean;
17
+ requireEvidence?: boolean;
18
+ }
19
+ export declare function evaluateLearningDecision(args: {
20
+ proposal: DurableChangeProposal;
21
+ confidence: number;
22
+ observations: number;
23
+ contradictions: number;
24
+ settings: LearningGateSettings;
25
+ now?: string;
26
+ }): LearningDecision;
27
+ export declare function isLearningDecision(value: unknown): value is LearningDecision;
28
+ export declare function cloneLearningDecisionForStorage(decision: LearningDecision): LearningDecision;
29
+ //# sourceMappingURL=learning-gate.d.ts.map
@@ -0,0 +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;AAEjE,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;CAC1B;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,CA2GnB;AAQD,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\";\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}\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\tif (contradictions > 0) {\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\tconst hasEvidence = !!(proposal.evidenceIds && proposal.evidenceIds.length > 0);\n\t\treturn learningDecision({\n\t\t\tkind: hasEvidence ? \"proposal\" : \"no-op\",\n\t\t\treasonCode: \"below_confidence_threshold\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: hasEvidence,\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\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\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"]}
@@ -0,0 +1,150 @@
1
+ const MAX_DECISION_SUMMARY_LENGTH = 240;
2
+ function boundedDecisionSummary(summary) {
3
+ if (summary.length <= MAX_DECISION_SUMMARY_LENGTH)
4
+ return summary;
5
+ return `${summary.slice(0, MAX_DECISION_SUMMARY_LENGTH - 1)}…`;
6
+ }
7
+ function learningDecision(args) {
8
+ return {
9
+ kind: args.kind,
10
+ reasonCode: args.reasonCode,
11
+ confidence: args.confidence,
12
+ summary: boundedDecisionSummary(args.summary),
13
+ requiresApproval: args.requiresApproval,
14
+ createdAt: args.createdAt,
15
+ };
16
+ }
17
+ export function evaluateLearningDecision(args) {
18
+ const { proposal, confidence, observations, contradictions, settings, now } = args;
19
+ if (!settings.enabled) {
20
+ return learningDecision({
21
+ kind: "no-op",
22
+ reasonCode: "learning_disabled",
23
+ confidence,
24
+ summary: proposal.summary,
25
+ requiresApproval: false,
26
+ createdAt: now,
27
+ });
28
+ }
29
+ if (contradictions > 0) {
30
+ return learningDecision({
31
+ kind: "proposal",
32
+ reasonCode: "contradictions_present",
33
+ confidence,
34
+ summary: proposal.summary,
35
+ requiresApproval: true,
36
+ createdAt: now,
37
+ });
38
+ }
39
+ if (confidence < settings.confidenceThreshold) {
40
+ const hasEvidence = !!(proposal.evidenceIds && proposal.evidenceIds.length > 0);
41
+ return learningDecision({
42
+ kind: hasEvidence ? "proposal" : "no-op",
43
+ reasonCode: "below_confidence_threshold",
44
+ confidence,
45
+ summary: proposal.summary,
46
+ requiresApproval: hasEvidence,
47
+ createdAt: now,
48
+ });
49
+ }
50
+ if (observations < settings.minObservations) {
51
+ return learningDecision({
52
+ kind: "proposal",
53
+ reasonCode: "insufficient_observations",
54
+ confidence,
55
+ summary: proposal.summary,
56
+ requiresApproval: true,
57
+ createdAt: now,
58
+ });
59
+ }
60
+ if (settings.requireEvidence) {
61
+ const hasEvidence = !!(proposal.evidenceIds && proposal.evidenceIds.length > 0);
62
+ if (!hasEvidence) {
63
+ return learningDecision({
64
+ kind: "proposal",
65
+ reasonCode: "missing_evidence",
66
+ confidence,
67
+ summary: proposal.summary,
68
+ requiresApproval: true,
69
+ createdAt: now,
70
+ });
71
+ }
72
+ }
73
+ if (settings.requireRollbackPlan) {
74
+ const hasRollback = proposal.rollbackPlan !== undefined && proposal.rollbackPlan.trim().length > 0;
75
+ if (!hasRollback) {
76
+ return learningDecision({
77
+ kind: "proposal",
78
+ reasonCode: "missing_rollback_plan",
79
+ confidence,
80
+ summary: proposal.summary,
81
+ requiresApproval: true,
82
+ createdAt: now,
83
+ });
84
+ }
85
+ }
86
+ if (!settings.autoApplyEnabled) {
87
+ return learningDecision({
88
+ kind: "proposal",
89
+ reasonCode: "auto_apply_disabled",
90
+ confidence,
91
+ summary: proposal.summary,
92
+ requiresApproval: true,
93
+ createdAt: now,
94
+ });
95
+ }
96
+ const isAllowed = settings.allowedAutoApplyLayers.includes(proposal.layer);
97
+ if (!isAllowed) {
98
+ return learningDecision({
99
+ kind: "proposal",
100
+ reasonCode: "layer_not_allowed_for_auto_apply",
101
+ confidence,
102
+ summary: proposal.summary,
103
+ requiresApproval: true,
104
+ createdAt: now,
105
+ });
106
+ }
107
+ return learningDecision({
108
+ kind: "apply",
109
+ reasonCode: "eligible_auto_apply",
110
+ confidence,
111
+ summary: proposal.summary,
112
+ requiresApproval: false,
113
+ createdAt: now,
114
+ });
115
+ }
116
+ function isPlainRecord(value) {
117
+ if (!value || typeof value !== "object" || Array.isArray(value))
118
+ return false;
119
+ const prototype = Object.getPrototypeOf(value);
120
+ return prototype === Object.prototype || prototype === null;
121
+ }
122
+ export function isLearningDecision(value) {
123
+ if (!isPlainRecord(value))
124
+ return false;
125
+ if (typeof value.kind !== "string" || !["no-op", "proposal", "apply"].includes(value.kind)) {
126
+ return false;
127
+ }
128
+ if (typeof value.reasonCode !== "string")
129
+ return false;
130
+ if (typeof value.confidence !== "number" || !Number.isFinite(value.confidence))
131
+ return false;
132
+ if (typeof value.summary !== "string")
133
+ return false;
134
+ if (typeof value.requiresApproval !== "boolean")
135
+ return false;
136
+ if (value.createdAt !== undefined && typeof value.createdAt !== "string")
137
+ return false;
138
+ return true;
139
+ }
140
+ export function cloneLearningDecisionForStorage(decision) {
141
+ return {
142
+ kind: decision.kind,
143
+ reasonCode: decision.reasonCode,
144
+ confidence: decision.confidence,
145
+ summary: decision.summary,
146
+ requiresApproval: decision.requiresApproval,
147
+ createdAt: decision.createdAt,
148
+ };
149
+ }
150
+ //# sourceMappingURL=learning-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learning-gate.js","sourceRoot":"","sources":["../../../src/core/learning/learning-gate.ts"],"names":[],"mappings":"AA8BA,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC,SAAS,sBAAsB,CAAC,OAAe,EAAU;IACxD,IAAI,OAAO,CAAC,MAAM,IAAI,2BAA2B;QAAE,OAAO,OAAO,CAAC;IAClE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,2BAA2B,GAAG,CAAC,CAAC,KAAG,CAAC;AAAA,CAC/D;AAED,SAAS,gBAAgB,CAAC,IAOzB,EAAoB;IACpB,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;AAAA,CACF;AAED,MAAM,UAAU,wBAAwB,CAAC,IAOxC,EAAoB;IACpB,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/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,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\";\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}\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\tif (contradictions > 0) {\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\tconst hasEvidence = !!(proposal.evidenceIds && proposal.evidenceIds.length > 0);\n\t\treturn learningDecision({\n\t\t\tkind: hasEvidence ? \"proposal\" : \"no-op\",\n\t\t\treasonCode: \"below_confidence_threshold\",\n\t\t\tconfidence,\n\t\t\tsummary: proposal.summary,\n\t\t\trequiresApproval: hasEvidence,\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\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\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"]}
@@ -0,0 +1,10 @@
1
+ import type { LearningDecision } from "../autonomy/contracts.ts";
2
+ import type { SessionEntry, SessionManager } from "../session-manager.ts";
3
+ export declare const LEARNING_DECISION_CUSTOM_TYPE = "learning_decision";
4
+ export interface LearningDecisionSnapshotPayload {
5
+ version: 1;
6
+ decision: LearningDecision;
7
+ }
8
+ export declare function appendLearningDecisionSnapshot(sessionManager: Pick<SessionManager, "appendCustomEntry">, decision: LearningDecision): string;
9
+ export declare function getLearningDecisionSnapshots(entries: readonly SessionEntry[]): LearningDecision[];
10
+ //# sourceMappingURL=session-learning-decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-learning-decision.d.ts","sourceRoot":"","sources":["../../../src/core/learning/session-learning-decision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG1E,eAAO,MAAM,6BAA6B,sBAAsB,CAAC;AAEjE,MAAM,WAAW,+BAA+B;IAC/C,OAAO,EAAE,CAAC,CAAC;IACX,QAAQ,EAAE,gBAAgB,CAAC;CAC3B;AAED,wBAAgB,8BAA8B,CAC7C,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,QAAQ,EAAE,gBAAgB,GACxB,MAAM,CAMR;AAQD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,gBAAgB,EAAE,CAmBjG","sourcesContent":["import type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport type { SessionEntry, SessionManager } from \"../session-manager.ts\";\nimport { cloneLearningDecisionForStorage, isLearningDecision } from \"./learning-gate.ts\";\n\nexport const LEARNING_DECISION_CUSTOM_TYPE = \"learning_decision\";\n\nexport interface LearningDecisionSnapshotPayload {\n\tversion: 1;\n\tdecision: LearningDecision;\n}\n\nexport function appendLearningDecisionSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tdecision: LearningDecision,\n): string {\n\tconst payload: LearningDecisionSnapshotPayload = {\n\t\tversion: 1,\n\t\tdecision: cloneLearningDecisionForStorage(decision),\n\t};\n\treturn sessionManager.appendCustomEntry(LEARNING_DECISION_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLearningDecisionSnapshots(entries: readonly SessionEntry[]): LearningDecision[] {\n\tconst results: LearningDecision[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== LEARNING_DECISION_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"decision\" in payload)) continue;\n\t\tconst decision = payload.decision;\n\t\tif (isLearningDecision(decision)) {\n\t\t\tresults.push(cloneLearningDecisionForStorage(decision));\n\t\t}\n\t}\n\n\treturn results;\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import { cloneLearningDecisionForStorage, isLearningDecision } from "./learning-gate.js";
2
+ export const LEARNING_DECISION_CUSTOM_TYPE = "learning_decision";
3
+ export function appendLearningDecisionSnapshot(sessionManager, decision) {
4
+ const payload = {
5
+ version: 1,
6
+ decision: cloneLearningDecisionForStorage(decision),
7
+ };
8
+ return sessionManager.appendCustomEntry(LEARNING_DECISION_CUSTOM_TYPE, payload);
9
+ }
10
+ function isPlainRecord(value) {
11
+ if (!value || typeof value !== "object" || Array.isArray(value))
12
+ return false;
13
+ const prototype = Object.getPrototypeOf(value);
14
+ return prototype === Object.prototype || prototype === null;
15
+ }
16
+ export function getLearningDecisionSnapshots(entries) {
17
+ const results = [];
18
+ for (const entry of entries) {
19
+ if (entry.type !== "custom" || entry.customType !== LEARNING_DECISION_CUSTOM_TYPE) {
20
+ continue;
21
+ }
22
+ const payload = entry.data;
23
+ if (!isPlainRecord(payload))
24
+ continue;
25
+ if (payload.version !== 1)
26
+ continue;
27
+ if (!("decision" in payload))
28
+ continue;
29
+ const decision = payload.decision;
30
+ if (isLearningDecision(decision)) {
31
+ results.push(cloneLearningDecisionForStorage(decision));
32
+ }
33
+ }
34
+ return results;
35
+ }
36
+ //# sourceMappingURL=session-learning-decision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-learning-decision.js","sourceRoot":"","sources":["../../../src/core/learning/session-learning-decision.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAEzF,MAAM,CAAC,MAAM,6BAA6B,GAAG,mBAAmB,CAAC;AAOjE,MAAM,UAAU,8BAA8B,CAC7C,cAAyD,EACzD,QAA0B,EACjB;IACT,MAAM,OAAO,GAAoC;QAChD,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,+BAA+B,CAAC,QAAQ,CAAC;KACnD,CAAC;IACF,OAAO,cAAc,CAAC,iBAAiB,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;AAAA,CAChF;AAED,SAAS,aAAa,CAAC,KAAc,EAAoC;IACxE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAAA,CAC5D;AAED,MAAM,UAAU,4BAA4B,CAAC,OAAgC,EAAsB;IAClG,MAAM,OAAO,GAAuB,EAAE,CAAC;IAEvC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,6BAA6B,EAAE,CAAC;YACnF,SAAS;QACV,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAAE,SAAS;QACtC,IAAI,OAAO,CAAC,OAAO,KAAK,CAAC;YAAE,SAAS;QACpC,IAAI,CAAC,CAAC,UAAU,IAAI,OAAO,CAAC;YAAE,SAAS;QACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,IAAI,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClC,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import type { LearningDecision } from \"../autonomy/contracts.ts\";\nimport type { SessionEntry, SessionManager } from \"../session-manager.ts\";\nimport { cloneLearningDecisionForStorage, isLearningDecision } from \"./learning-gate.ts\";\n\nexport const LEARNING_DECISION_CUSTOM_TYPE = \"learning_decision\";\n\nexport interface LearningDecisionSnapshotPayload {\n\tversion: 1;\n\tdecision: LearningDecision;\n}\n\nexport function appendLearningDecisionSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tdecision: LearningDecision,\n): string {\n\tconst payload: LearningDecisionSnapshotPayload = {\n\t\tversion: 1,\n\t\tdecision: cloneLearningDecisionForStorage(decision),\n\t};\n\treturn sessionManager.appendCustomEntry(LEARNING_DECISION_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLearningDecisionSnapshots(entries: readonly SessionEntry[]): LearningDecision[] {\n\tconst results: LearningDecision[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== LEARNING_DECISION_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"decision\" in payload)) continue;\n\t\tconst decision = payload.decision;\n\t\tif (isLearningDecision(decision)) {\n\t\t\tresults.push(cloneLearningDecisionForStorage(decision));\n\t\t}\n\t}\n\n\treturn results;\n}\n"]}