@caupulican/pi-adaptative 0.80.86 → 0.80.88

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 (337) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/dist/core/agent-session.d.ts +377 -1
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +1791 -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/context-artifacts.d.ts +94 -0
  55. package/dist/core/context/context-artifacts.d.ts.map +1 -0
  56. package/dist/core/context/context-artifacts.js +307 -0
  57. package/dist/core/context/context-artifacts.js.map +1 -0
  58. package/dist/core/context/context-audit.d.ts +66 -0
  59. package/dist/core/context/context-audit.d.ts.map +1 -0
  60. package/dist/core/context/context-audit.js +173 -0
  61. package/dist/core/context/context-audit.js.map +1 -0
  62. package/dist/core/context/context-item.d.ts +117 -0
  63. package/dist/core/context/context-item.d.ts.map +1 -0
  64. package/dist/core/context/context-item.js +36 -0
  65. package/dist/core/context/context-item.js.map +1 -0
  66. package/dist/core/context/context-prompt-enforcement.d.ts +73 -0
  67. package/dist/core/context/context-prompt-enforcement.d.ts.map +1 -0
  68. package/dist/core/context/context-prompt-enforcement.js +153 -0
  69. package/dist/core/context/context-prompt-enforcement.js.map +1 -0
  70. package/dist/core/context/context-prompt-policy.d.ts +90 -0
  71. package/dist/core/context/context-prompt-policy.d.ts.map +1 -0
  72. package/dist/core/context/context-prompt-policy.js +73 -0
  73. package/dist/core/context/context-prompt-policy.js.map +1 -0
  74. package/dist/core/context/context-retention.d.ts +36 -0
  75. package/dist/core/context/context-retention.d.ts.map +1 -0
  76. package/dist/core/context/context-retention.js +108 -0
  77. package/dist/core/context/context-retention.js.map +1 -0
  78. package/dist/core/context/context-store.d.ts +37 -0
  79. package/dist/core/context/context-store.d.ts.map +1 -0
  80. package/dist/core/context/context-store.js +45 -0
  81. package/dist/core/context/context-store.js.map +1 -0
  82. package/dist/core/context/memory-diagnostics.d.ts +50 -0
  83. package/dist/core/context/memory-diagnostics.d.ts.map +1 -0
  84. package/dist/core/context/memory-diagnostics.js +43 -0
  85. package/dist/core/context/memory-diagnostics.js.map +1 -0
  86. package/dist/core/context/memory-index-store.d.ts +28 -0
  87. package/dist/core/context/memory-index-store.d.ts.map +1 -0
  88. package/dist/core/context/memory-index-store.js +38 -0
  89. package/dist/core/context/memory-index-store.js.map +1 -0
  90. package/dist/core/context/memory-prompt-block.d.ts +34 -0
  91. package/dist/core/context/memory-prompt-block.d.ts.map +1 -0
  92. package/dist/core/context/memory-prompt-block.js +58 -0
  93. package/dist/core/context/memory-prompt-block.js.map +1 -0
  94. package/dist/core/context/memory-provider-contract.d.ts +114 -0
  95. package/dist/core/context/memory-provider-contract.d.ts.map +1 -0
  96. package/dist/core/context/memory-provider-contract.js +121 -0
  97. package/dist/core/context/memory-provider-contract.js.map +1 -0
  98. package/dist/core/context/memory-retrieval.d.ts +27 -0
  99. package/dist/core/context/memory-retrieval.d.ts.map +1 -0
  100. package/dist/core/context/memory-retrieval.js +91 -0
  101. package/dist/core/context/memory-retrieval.js.map +1 -0
  102. package/dist/core/context/okf-memory-provider.d.ts +26 -0
  103. package/dist/core/context/okf-memory-provider.d.ts.map +1 -0
  104. package/dist/core/context/okf-memory-provider.js +154 -0
  105. package/dist/core/context/okf-memory-provider.js.map +1 -0
  106. package/dist/core/context/okf-memory.d.ts +42 -0
  107. package/dist/core/context/okf-memory.d.ts.map +1 -0
  108. package/dist/core/context/okf-memory.js +175 -0
  109. package/dist/core/context/okf-memory.js.map +1 -0
  110. package/dist/core/context/policy-engine.d.ts +66 -0
  111. package/dist/core/context/policy-engine.d.ts.map +1 -0
  112. package/dist/core/context/policy-engine.js +171 -0
  113. package/dist/core/context/policy-engine.js.map +1 -0
  114. package/dist/core/context/policy-types.d.ts +102 -0
  115. package/dist/core/context/policy-types.d.ts.map +1 -0
  116. package/dist/core/context/policy-types.js +7 -0
  117. package/dist/core/context/policy-types.js.map +1 -0
  118. package/dist/core/context/sqlite-runtime-index.d.ts +19 -0
  119. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -0
  120. package/dist/core/context/sqlite-runtime-index.js +344 -0
  121. package/dist/core/context/sqlite-runtime-index.js.map +1 -0
  122. package/dist/core/context/storage-authority.d.ts +20 -0
  123. package/dist/core/context/storage-authority.d.ts.map +1 -0
  124. package/dist/core/context/storage-authority.js +51 -0
  125. package/dist/core/context/storage-authority.js.map +1 -0
  126. package/dist/core/context/tool-output-packer.d.ts +75 -0
  127. package/dist/core/context/tool-output-packer.d.ts.map +1 -0
  128. package/dist/core/context/tool-output-packer.js +77 -0
  129. package/dist/core/context/tool-output-packer.js.map +1 -0
  130. package/dist/core/cost/session-usage.d.ts +20 -0
  131. package/dist/core/cost/session-usage.d.ts.map +1 -0
  132. package/dist/core/cost/session-usage.js +164 -0
  133. package/dist/core/cost/session-usage.js.map +1 -0
  134. package/dist/core/delegation/session-worker-result.d.ts +10 -0
  135. package/dist/core/delegation/session-worker-result.d.ts.map +1 -0
  136. package/dist/core/delegation/session-worker-result.js +36 -0
  137. package/dist/core/delegation/session-worker-result.js.map +1 -0
  138. package/dist/core/delegation/worker-result.d.ts +9 -0
  139. package/dist/core/delegation/worker-result.d.ts.map +1 -0
  140. package/dist/core/delegation/worker-result.js +152 -0
  141. package/dist/core/delegation/worker-result.js.map +1 -0
  142. package/dist/core/delegation/worker-runner.d.ts +58 -0
  143. package/dist/core/delegation/worker-runner.d.ts.map +1 -0
  144. package/dist/core/delegation/worker-runner.js +188 -0
  145. package/dist/core/delegation/worker-runner.js.map +1 -0
  146. package/dist/core/extensions/builtin.d.ts +5 -1
  147. package/dist/core/extensions/builtin.d.ts.map +1 -1
  148. package/dist/core/extensions/builtin.js +23 -1
  149. package/dist/core/extensions/builtin.js.map +1 -1
  150. package/dist/core/footer-data-provider.d.ts +5 -1
  151. package/dist/core/footer-data-provider.d.ts.map +1 -1
  152. package/dist/core/footer-data-provider.js +13 -0
  153. package/dist/core/footer-data-provider.js.map +1 -1
  154. package/dist/core/goals/goal-continuation-controller.d.ts +22 -0
  155. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -0
  156. package/dist/core/goals/goal-continuation-controller.js +88 -0
  157. package/dist/core/goals/goal-continuation-controller.js.map +1 -0
  158. package/dist/core/goals/goal-continuation-defaults.d.ts +10 -0
  159. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -0
  160. package/dist/core/goals/goal-continuation-defaults.js +10 -0
  161. package/dist/core/goals/goal-continuation-defaults.js.map +1 -0
  162. package/dist/core/goals/goal-continuation-prompt.d.ts +18 -0
  163. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -0
  164. package/dist/core/goals/goal-continuation-prompt.js +141 -0
  165. package/dist/core/goals/goal-continuation-prompt.js.map +1 -0
  166. package/dist/core/goals/goal-runtime-snapshot.d.ts +19 -0
  167. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -0
  168. package/dist/core/goals/goal-runtime-snapshot.js +23 -0
  169. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -0
  170. package/dist/core/goals/goal-state.d.ts +87 -0
  171. package/dist/core/goals/goal-state.d.ts.map +1 -0
  172. package/dist/core/goals/goal-state.js +259 -0
  173. package/dist/core/goals/goal-state.js.map +1 -0
  174. package/dist/core/goals/goal-tool-core.d.ts +66 -0
  175. package/dist/core/goals/goal-tool-core.d.ts.map +1 -0
  176. package/dist/core/goals/goal-tool-core.js +146 -0
  177. package/dist/core/goals/goal-tool-core.js.map +1 -0
  178. package/dist/core/goals/session-goal-state.d.ts +10 -0
  179. package/dist/core/goals/session-goal-state.d.ts.map +1 -0
  180. package/dist/core/goals/session-goal-state.js +35 -0
  181. package/dist/core/goals/session-goal-state.js.map +1 -0
  182. package/dist/core/learning/learning-audit.d.ts +45 -0
  183. package/dist/core/learning/learning-audit.d.ts.map +1 -0
  184. package/dist/core/learning/learning-audit.js +139 -0
  185. package/dist/core/learning/learning-audit.js.map +1 -0
  186. package/dist/core/learning/learning-gate.d.ts +29 -0
  187. package/dist/core/learning/learning-gate.d.ts.map +1 -0
  188. package/dist/core/learning/learning-gate.js +150 -0
  189. package/dist/core/learning/learning-gate.js.map +1 -0
  190. package/dist/core/learning/session-learning-decision.d.ts +10 -0
  191. package/dist/core/learning/session-learning-decision.d.ts.map +1 -0
  192. package/dist/core/learning/session-learning-decision.js +36 -0
  193. package/dist/core/learning/session-learning-decision.js.map +1 -0
  194. package/dist/core/model-capability.d.ts +41 -0
  195. package/dist/core/model-capability.d.ts.map +1 -0
  196. package/dist/core/model-capability.js +101 -0
  197. package/dist/core/model-capability.js.map +1 -0
  198. package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
  199. package/dist/core/model-router/config-diagnostics.js +1 -0
  200. package/dist/core/model-router/config-diagnostics.js.map +1 -1
  201. package/dist/core/model-router/intent-classifier.d.ts +2 -0
  202. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  203. package/dist/core/model-router/intent-classifier.js +154 -9
  204. package/dist/core/model-router/intent-classifier.js.map +1 -1
  205. package/dist/core/model-router/route-judge.d.ts +54 -0
  206. package/dist/core/model-router/route-judge.d.ts.map +1 -0
  207. package/dist/core/model-router/route-judge.js +128 -0
  208. package/dist/core/model-router/route-judge.js.map +1 -0
  209. package/dist/core/model-router/status.d.ts +4 -1
  210. package/dist/core/model-router/status.d.ts.map +1 -1
  211. package/dist/core/model-router/status.js +30 -6
  212. package/dist/core/model-router/status.js.map +1 -1
  213. package/dist/core/model-router/tool-escalation.d.ts +4 -6
  214. package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
  215. package/dist/core/model-router/tool-escalation.js +1 -1
  216. package/dist/core/model-router/tool-escalation.js.map +1 -1
  217. package/dist/core/models/fitness-store.d.ts +40 -0
  218. package/dist/core/models/fitness-store.d.ts.map +1 -0
  219. package/dist/core/models/fitness-store.js +61 -0
  220. package/dist/core/models/fitness-store.js.map +1 -0
  221. package/dist/core/profile-registry.d.ts.map +1 -1
  222. package/dist/core/profile-registry.js +1 -1
  223. package/dist/core/profile-registry.js.map +1 -1
  224. package/dist/core/prompt-templates.d.ts +2 -0
  225. package/dist/core/prompt-templates.d.ts.map +1 -1
  226. package/dist/core/prompt-templates.js +12 -4
  227. package/dist/core/prompt-templates.js.map +1 -1
  228. package/dist/core/research/automata-provider.d.ts +5 -0
  229. package/dist/core/research/automata-provider.d.ts.map +1 -0
  230. package/dist/core/research/automata-provider.js +15 -0
  231. package/dist/core/research/automata-provider.js.map +1 -0
  232. package/dist/core/research/evidence-bundle.d.ts +10 -0
  233. package/dist/core/research/evidence-bundle.d.ts.map +1 -0
  234. package/dist/core/research/evidence-bundle.js +116 -0
  235. package/dist/core/research/evidence-bundle.js.map +1 -0
  236. package/dist/core/research/model-fitness.d.ts +79 -0
  237. package/dist/core/research/model-fitness.d.ts.map +1 -0
  238. package/dist/core/research/model-fitness.js +257 -0
  239. package/dist/core/research/model-fitness.js.map +1 -0
  240. package/dist/core/research/research-gate.d.ts +11 -0
  241. package/dist/core/research/research-gate.d.ts.map +1 -0
  242. package/dist/core/research/research-gate.js +82 -0
  243. package/dist/core/research/research-gate.js.map +1 -0
  244. package/dist/core/research/research-runner.d.ts +59 -0
  245. package/dist/core/research/research-runner.d.ts.map +1 -0
  246. package/dist/core/research/research-runner.js +155 -0
  247. package/dist/core/research/research-runner.js.map +1 -0
  248. package/dist/core/research/session-evidence-bundle.d.ts +11 -0
  249. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -0
  250. package/dist/core/research/session-evidence-bundle.js +55 -0
  251. package/dist/core/research/session-evidence-bundle.js.map +1 -0
  252. package/dist/core/resource-loader.d.ts.map +1 -1
  253. package/dist/core/resource-loader.js +4 -0
  254. package/dist/core/resource-loader.js.map +1 -1
  255. package/dist/core/settings-manager.d.ts +147 -4
  256. package/dist/core/settings-manager.d.ts.map +1 -1
  257. package/dist/core/settings-manager.js +285 -9
  258. package/dist/core/settings-manager.js.map +1 -1
  259. package/dist/core/skills.d.ts +4 -0
  260. package/dist/core/skills.d.ts.map +1 -1
  261. package/dist/core/skills.js +18 -6
  262. package/dist/core/skills.js.map +1 -1
  263. package/dist/core/slash-commands.d.ts.map +1 -1
  264. package/dist/core/slash-commands.js +4 -0
  265. package/dist/core/slash-commands.js.map +1 -1
  266. package/dist/core/toolkit/script-registry.d.ts +34 -0
  267. package/dist/core/toolkit/script-registry.d.ts.map +1 -0
  268. package/dist/core/toolkit/script-registry.js +71 -0
  269. package/dist/core/toolkit/script-registry.js.map +1 -0
  270. package/dist/core/toolkit/script-runner.d.ts +28 -0
  271. package/dist/core/toolkit/script-runner.d.ts.map +1 -0
  272. package/dist/core/toolkit/script-runner.js +48 -0
  273. package/dist/core/toolkit/script-runner.js.map +1 -0
  274. package/dist/core/tools/artifact-retrieve.d.ts +23 -0
  275. package/dist/core/tools/artifact-retrieve.d.ts.map +1 -0
  276. package/dist/core/tools/artifact-retrieve.js +110 -0
  277. package/dist/core/tools/artifact-retrieve.js.map +1 -0
  278. package/dist/core/tools/delegate.d.ts +32 -0
  279. package/dist/core/tools/delegate.d.ts.map +1 -0
  280. package/dist/core/tools/delegate.js +60 -0
  281. package/dist/core/tools/delegate.js.map +1 -0
  282. package/dist/core/tools/fff-search-backend.d.ts +103 -0
  283. package/dist/core/tools/fff-search-backend.d.ts.map +1 -0
  284. package/dist/core/tools/fff-search-backend.js +151 -0
  285. package/dist/core/tools/fff-search-backend.js.map +1 -0
  286. package/dist/core/tools/find.d.ts +21 -1
  287. package/dist/core/tools/find.d.ts.map +1 -1
  288. package/dist/core/tools/find.js +183 -10
  289. package/dist/core/tools/find.js.map +1 -1
  290. package/dist/core/tools/goal.d.ts +35 -0
  291. package/dist/core/tools/goal.d.ts.map +1 -0
  292. package/dist/core/tools/goal.js +122 -0
  293. package/dist/core/tools/goal.js.map +1 -0
  294. package/dist/core/tools/grep.d.ts +21 -1
  295. package/dist/core/tools/grep.d.ts.map +1 -1
  296. package/dist/core/tools/grep.js +272 -27
  297. package/dist/core/tools/grep.js.map +1 -1
  298. package/dist/core/tools/index.d.ts +4 -1
  299. package/dist/core/tools/index.d.ts.map +1 -1
  300. package/dist/core/tools/index.js +9 -0
  301. package/dist/core/tools/index.js.map +1 -1
  302. package/dist/core/tools/model-fitness.d.ts +30 -0
  303. package/dist/core/tools/model-fitness.d.ts.map +1 -0
  304. package/dist/core/tools/model-fitness.js +38 -0
  305. package/dist/core/tools/model-fitness.js.map +1 -0
  306. package/dist/core/tools/run-toolkit-script.d.ts +24 -0
  307. package/dist/core/tools/run-toolkit-script.d.ts.map +1 -0
  308. package/dist/core/tools/run-toolkit-script.js +103 -0
  309. package/dist/core/tools/run-toolkit-script.js.map +1 -0
  310. package/dist/core/tools/search-router.d.ts +75 -0
  311. package/dist/core/tools/search-router.d.ts.map +1 -0
  312. package/dist/core/tools/search-router.js +85 -0
  313. package/dist/core/tools/search-router.js.map +1 -0
  314. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  315. package/dist/modes/interactive/components/footer.js +18 -16
  316. package/dist/modes/interactive/components/footer.js.map +1 -1
  317. package/dist/modes/interactive/components/settings-selector.d.ts +13 -1
  318. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  319. package/dist/modes/interactive/components/settings-selector.js +471 -11
  320. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  321. package/dist/modes/interactive/interactive-mode.d.ts +4 -0
  322. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  323. package/dist/modes/interactive/interactive-mode.js +217 -39
  324. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  325. package/dist/utils/tools-manager.d.ts +2 -0
  326. package/dist/utils/tools-manager.d.ts.map +1 -1
  327. package/dist/utils/tools-manager.js +154 -2
  328. package/dist/utils/tools-manager.js.map +1 -1
  329. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  330. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  331. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  332. package/examples/extensions/sandbox/package-lock.json +2 -2
  333. package/examples/extensions/sandbox/package.json +1 -1
  334. package/examples/extensions/with-deps/package-lock.json +2 -2
  335. package/examples/extensions/with-deps/package.json +1 -1
  336. package/npm-shrinkwrap.json +368 -12
  337. package/package.json +5 -4
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Observe-first shadow/planning layer, one step closer to prompt construction than
3
+ * context-audit.ts (Phase 1). This module re-shapes an already-computed `ContextAuditReport`
4
+ * into a deterministic per-item policy plan, and can correlate that plan against the
5
+ * legacy context-gc's actual packed records. It never enforces anything: `appliedAction` is
6
+ * a literal `"keep_raw"` on every item -- the type itself makes it impossible for this
7
+ * module to report having changed prompt behavior. Nothing here mutates messages, the
8
+ * transcript, or artifact references; it only reads an already-computed report.
9
+ *
10
+ * Single source of truth for feature/flag construction remains context-audit.ts
11
+ * (`buildPolicyFeatures`/`buildHardConstraintFlags`): this module reuses the hard-constraint
12
+ * codes already computed there rather than reconstructing them, so there is exactly one
13
+ * place that decides how a tool_output item's PolicyFeatures/HardConstraintFlags are built.
14
+ */
15
+ /**
16
+ * Deterministic re-shaping of an audit report into the shadow policy plan shape. Pure: no
17
+ * I/O, no mutation, given the same audit report this always returns an equal result.
18
+ */
19
+ export function planPromptPolicy(auditReport) {
20
+ return {
21
+ turnIndex: auditReport.turnIndex,
22
+ items: auditReport.items.map((entry) => ({
23
+ itemId: entry.item.id,
24
+ kind: entry.item.kind,
25
+ retentionClass: entry.item.retentionClass,
26
+ source: entry.item.source,
27
+ toolCallId: entry.toolCallId,
28
+ messageIndex: entry.messageIndex,
29
+ primaryRefType: entry.item.primaryRef?.type,
30
+ hasAvailableRetrievalPath: entry.item.primaryRef?.type === "artifact",
31
+ allowedRetentionActions: entry.retention.allowedActions,
32
+ hardConstraints: {
33
+ keepRaw: entry.keepRawHardConstraints,
34
+ packToArtifact: entry.packToArtifactHardConstraints,
35
+ dropFromPrompt: entry.dropFromPromptHardConstraints,
36
+ summarize: entry.summarizeHardConstraints,
37
+ },
38
+ appliedAction: "keep_raw",
39
+ })),
40
+ };
41
+ }
42
+ /**
43
+ * Report-only correlation between the shadow plan and what the legacy context-gc pass
44
+ * actually did this turn. Does not influence context-gc in any way -- it runs after gc has
45
+ * already produced its report, purely to observe what each side did/would do.
46
+ *
47
+ * Deliberately does not derive an "agrees with legacy gc" boolean: legacy context-gc
48
+ * "packing" summarizes/stubs a tool result in place (provider-visible content shrinks in
49
+ * place), while the policy action `pack_to_artifact` means artifact-backed capture and
50
+ * out-of-band retrieval -- a different operation with different semantics, not a
51
+ * calibrated equivalent. Collapsing them into one "agreement" boolean would overclaim
52
+ * semantic agreement between the two and risk a later enforcement slice mistaking this
53
+ * observe-only diagnostic for a calibrated authority. The raw booleans below are reported
54
+ * as-is; comparing them is left to the reader.
55
+ */
56
+ export function correlateWithContextGc(shadowReport, gcReport) {
57
+ const packedByToolCallId = new Map();
58
+ for (const record of gcReport.records)
59
+ packedByToolCallId.set(record.toolCallId, record);
60
+ const entries = shadowReport.items.map((item) => {
61
+ const gcRecord = packedByToolCallId.get(item.toolCallId);
62
+ return {
63
+ itemId: item.itemId,
64
+ toolCallId: item.toolCallId,
65
+ actuallyPackedByLegacyGc: gcRecord !== undefined,
66
+ gcPackReason: gcRecord?.reason,
67
+ policyWouldAllowPack: item.hardConstraints.packToArtifact.length === 0,
68
+ policyWouldAllowDrop: item.hardConstraints.dropFromPrompt.length === 0,
69
+ };
70
+ });
71
+ return { turnIndex: shadowReport.turnIndex, entries };
72
+ }
73
+ //# sourceMappingURL=context-prompt-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-prompt-policy.js","sourceRoot":"","sources":["../../../src/core/context/context-prompt-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA8CH;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAA+B,EAA4B;IAC3F,OAAO;QACN,SAAS,EAAE,WAAW,CAAC,SAAS;QAChC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACxC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE;YACrB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI;YACrB,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc;YACzC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM;YACzB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI;YAC3C,yBAAyB,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,KAAK,UAAU;YACrE,uBAAuB,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc;YACvD,eAAe,EAAE;gBAChB,OAAO,EAAE,KAAK,CAAC,sBAAsB;gBACrC,cAAc,EAAE,KAAK,CAAC,6BAA6B;gBACnD,cAAc,EAAE,KAAK,CAAC,6BAA6B;gBACnD,SAAS,EAAE,KAAK,CAAC,wBAAwB;aACzC;YACD,aAAa,EAAE,UAAU;SACzB,CAAC,CAAC;KACH,CAAC;AAAA,CACF;AAmBD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CACrC,YAAsC,EACtC,QAAyB,EACS;IAClC,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAiC,CAAC;IACpE,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO;QAAE,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAEzF,MAAM,OAAO,GAAqC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAClF,MAAM,QAAQ,GAAG,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACzD,OAAO;YACN,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,wBAAwB,EAAE,QAAQ,KAAK,SAAS;YAChD,YAAY,EAAE,QAAQ,EAAE,MAAM;YAC9B,oBAAoB,EAAE,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC;YACtE,oBAAoB,EAAE,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC;SACtE,CAAC;IAAA,CACF,CAAC,CAAC;IAEH,OAAO,EAAE,SAAS,EAAE,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;AAAA,CACtD","sourcesContent":["/**\n * Observe-first shadow/planning layer, one step closer to prompt construction than\n * context-audit.ts (Phase 1). This module re-shapes an already-computed `ContextAuditReport`\n * into a deterministic per-item policy plan, and can correlate that plan against the\n * legacy context-gc's actual packed records. It never enforces anything: `appliedAction` is\n * a literal `\"keep_raw\"` on every item -- the type itself makes it impossible for this\n * module to report having changed prompt behavior. Nothing here mutates messages, the\n * transcript, or artifact references; it only reads an already-computed report.\n *\n * Single source of truth for feature/flag construction remains context-audit.ts\n * (`buildPolicyFeatures`/`buildHardConstraintFlags`): this module reuses the hard-constraint\n * codes already computed there rather than reconstructing them, so there is exactly one\n * place that decides how a tool_output item's PolicyFeatures/HardConstraintFlags are built.\n */\n\nimport type { ContextGcPackedRecord, ContextGcReport } from \"../context-gc.ts\";\nimport type { ContextAuditReport } from \"./context-audit.ts\";\nimport type { ContextEvidenceRef, ContextItemKind, ContextRetentionClass, ContextSource } from \"./context-item.ts\";\nimport type { RetentionAction } from \"./context-retention.ts\";\nimport type { PolicyHardConstraintCode } from \"./policy-types.ts\";\n\nexport interface PromptPolicyHardConstraints {\n\tkeepRaw: PolicyHardConstraintCode[];\n\tpackToArtifact: PolicyHardConstraintCode[];\n\tdropFromPrompt: PolicyHardConstraintCode[];\n\tsummarize: PolicyHardConstraintCode[];\n}\n\nexport interface PromptPolicyItemReport {\n\titemId: string;\n\tkind: ContextItemKind;\n\tretentionClass: ContextRetentionClass;\n\tsource: ContextSource;\n\ttoolCallId: string;\n\tmessageIndex: number;\n\tprimaryRefType: ContextEvidenceRef[\"type\"] | undefined;\n\t/**\n\t * True only for a resolved artifact ref, never for a transcript ref -- the same\n\t * fail-closed resolved-artifact-only rule context-audit.ts uses (a transcript ref is\n\t * provenance, not a live retrieval mechanism; see that module's doc comment).\n\t */\n\thasAvailableRetrievalPath: boolean;\n\t/** Coarse, store-free eligibility from context-retention.ts (treats any ref as retrievable). */\n\tallowedRetentionActions: RetentionAction[];\n\thardConstraints: PromptPolicyHardConstraints;\n\t/**\n\t * This shadow/planning pass never changes behavior: the applied action is always\n\t * \"keep_raw\", regardless of what the hard-constraint/retention analysis above would\n\t * otherwise allow. Typed as a literal so nothing here can ever report applying anything\n\t * else.\n\t */\n\tappliedAction: \"keep_raw\";\n}\n\nexport interface PromptPolicyShadowReport {\n\tturnIndex: number;\n\titems: PromptPolicyItemReport[];\n}\n\n/**\n * Deterministic re-shaping of an audit report into the shadow policy plan shape. Pure: no\n * I/O, no mutation, given the same audit report this always returns an equal result.\n */\nexport function planPromptPolicy(auditReport: ContextAuditReport): PromptPolicyShadowReport {\n\treturn {\n\t\tturnIndex: auditReport.turnIndex,\n\t\titems: auditReport.items.map((entry) => ({\n\t\t\titemId: entry.item.id,\n\t\t\tkind: entry.item.kind,\n\t\t\tretentionClass: entry.item.retentionClass,\n\t\t\tsource: entry.item.source,\n\t\t\ttoolCallId: entry.toolCallId,\n\t\t\tmessageIndex: entry.messageIndex,\n\t\t\tprimaryRefType: entry.item.primaryRef?.type,\n\t\t\thasAvailableRetrievalPath: entry.item.primaryRef?.type === \"artifact\",\n\t\t\tallowedRetentionActions: entry.retention.allowedActions,\n\t\t\thardConstraints: {\n\t\t\t\tkeepRaw: entry.keepRawHardConstraints,\n\t\t\t\tpackToArtifact: entry.packToArtifactHardConstraints,\n\t\t\t\tdropFromPrompt: entry.dropFromPromptHardConstraints,\n\t\t\t\tsummarize: entry.summarizeHardConstraints,\n\t\t\t},\n\t\t\tappliedAction: \"keep_raw\",\n\t\t})),\n\t};\n}\n\nexport interface PromptPolicyGcCorrelationEntry {\n\titemId: string;\n\ttoolCallId: string;\n\t/** True if the legacy context-gc pass actually packed this item's tool result this turn. */\n\tactuallyPackedByLegacyGc: boolean;\n\tgcPackReason?: ContextGcPackedRecord[\"reason\"];\n\t/** True if the shadow plan's pack_to_artifact hard constraints did not reject packing. */\n\tpolicyWouldAllowPack: boolean;\n\t/** True if the shadow plan's drop_from_prompt hard constraints did not reject dropping. */\n\tpolicyWouldAllowDrop: boolean;\n}\n\nexport interface PromptPolicyGcCorrelationReport {\n\tturnIndex: number;\n\tentries: PromptPolicyGcCorrelationEntry[];\n}\n\n/**\n * Report-only correlation between the shadow plan and what the legacy context-gc pass\n * actually did this turn. Does not influence context-gc in any way -- it runs after gc has\n * already produced its report, purely to observe what each side did/would do.\n *\n * Deliberately does not derive an \"agrees with legacy gc\" boolean: legacy context-gc\n * \"packing\" summarizes/stubs a tool result in place (provider-visible content shrinks in\n * place), while the policy action `pack_to_artifact` means artifact-backed capture and\n * out-of-band retrieval -- a different operation with different semantics, not a\n * calibrated equivalent. Collapsing them into one \"agreement\" boolean would overclaim\n * semantic agreement between the two and risk a later enforcement slice mistaking this\n * observe-only diagnostic for a calibrated authority. The raw booleans below are reported\n * as-is; comparing them is left to the reader.\n */\nexport function correlateWithContextGc(\n\tshadowReport: PromptPolicyShadowReport,\n\tgcReport: ContextGcReport,\n): PromptPolicyGcCorrelationReport {\n\tconst packedByToolCallId = new Map<string, ContextGcPackedRecord>();\n\tfor (const record of gcReport.records) packedByToolCallId.set(record.toolCallId, record);\n\n\tconst entries: PromptPolicyGcCorrelationEntry[] = shadowReport.items.map((item) => {\n\t\tconst gcRecord = packedByToolCallId.get(item.toolCallId);\n\t\treturn {\n\t\t\titemId: item.itemId,\n\t\t\ttoolCallId: item.toolCallId,\n\t\t\tactuallyPackedByLegacyGc: gcRecord !== undefined,\n\t\t\tgcPackReason: gcRecord?.reason,\n\t\t\tpolicyWouldAllowPack: item.hardConstraints.packToArtifact.length === 0,\n\t\t\tpolicyWouldAllowDrop: item.hardConstraints.dropFromPrompt.length === 0,\n\t\t};\n\t});\n\n\treturn { turnIndex: shadowReport.turnIndex, entries };\n}\n"]}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Pure retention-eligibility helpers for ContextItem.
3
+ *
4
+ * These functions only classify what a runtime policy is *allowed* to do with an item;
5
+ * they do not mutate, evict, or summarize anything themselves, and they never touch the
6
+ * transcript or artifact stores. Per contracts-and-retention.md, dropping from model
7
+ * context must never mean deleting from storage: these helpers only ever describe prompt
8
+ * inclusion, not deletion.
9
+ */
10
+ import { type ContextItem } from "./context-item.ts";
11
+ export type RetentionAction = "keep_raw" | "summarize" | "pack_to_artifact" | "drop_from_prompt";
12
+ export interface RetentionEligibility {
13
+ /** Actions a runtime policy may choose between for this item, most-preserving first. */
14
+ allowedActions: RetentionAction[];
15
+ /** True if the item's semantics must stay present verbatim; only "keep_raw" is allowed. */
16
+ hardRetained: boolean;
17
+ reasonCodes: string[];
18
+ }
19
+ /**
20
+ * True if `kind`/`retentionClass` combination must never be dropped or summarized away,
21
+ * regardless of budget pressure. Mirrors the "Hard retention rules" in
22
+ * contracts-and-retention.md: pinned items and the explicitly hard-retained kinds
23
+ * (user instructions, approvals, denials, safety constraints).
24
+ */
25
+ export declare function isHardRetained(item: ContextItem): boolean;
26
+ /**
27
+ * Determine which prompt-retention actions are permitted for an item. This is the pure
28
+ * policy helper referenced by implementation-phases.md Phase 1: it must never allow
29
+ * dropping pinned/open/latest-failure items, and it must never allow summarizing
30
+ * decision-bearing content that has no evidence/retrieval path.
31
+ */
32
+ export declare function evaluateRetentionEligibility(item: ContextItem): RetentionEligibility;
33
+ export declare function canDropFromPrompt(item: ContextItem): boolean;
34
+ export declare function canSummarize(item: ContextItem): boolean;
35
+ export declare function canPackToArtifact(item: ContextItem): boolean;
36
+ //# sourceMappingURL=context-retention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-retention.d.ts","sourceRoot":"","sources":["../../../src/core/context/context-retention.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,WAAW,EAA+B,MAAM,mBAAmB,CAAC;AAElF,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,WAAW,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAEjG,MAAM,WAAW,oBAAoB;IACpC,wFAAwF;IACxF,cAAc,EAAE,eAAe,EAAE,CAAC;IAClC,2FAA2F;IAC3F,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB;AAYD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,WAAW,GAAG,oBAAoB,CAiEpF;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAE5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAEvD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAE5D","sourcesContent":["/**\n * Pure retention-eligibility helpers for ContextItem.\n *\n * These functions only classify what a runtime policy is *allowed* to do with an item;\n * they do not mutate, evict, or summarize anything themselves, and they never touch the\n * transcript or artifact stores. Per contracts-and-retention.md, dropping from model\n * context must never mean deleting from storage: these helpers only ever describe prompt\n * inclusion, not deletion.\n */\n\nimport { type ContextItem, HARD_RETAINED_CONTEXT_KINDS } from \"./context-item.ts\";\n\nexport type RetentionAction = \"keep_raw\" | \"summarize\" | \"pack_to_artifact\" | \"drop_from_prompt\";\n\nexport interface RetentionEligibility {\n\t/** Actions a runtime policy may choose between for this item, most-preserving first. */\n\tallowedActions: RetentionAction[];\n\t/** True if the item's semantics must stay present verbatim; only \"keep_raw\" is allowed. */\n\thardRetained: boolean;\n\treasonCodes: string[];\n}\n\n/**\n * True if the item carries a ref at all. This is item-level and store-free by design: it\n * does not check whether an artifact ref is still resolvable in a live artifact store\n * (that check belongs to a store-aware layer, e.g. `HardConstraintFlags` in\n * policy-types.ts). Do not treat this as \"retrieval is available\" when wiring a real store.\n */\nfunction hasReferencedEvidence(item: ContextItem): boolean {\n\treturn item.primaryRef !== undefined || (item.evidenceRefs?.length ?? 0) > 0;\n}\n\n/**\n * True if `kind`/`retentionClass` combination must never be dropped or summarized away,\n * regardless of budget pressure. Mirrors the \"Hard retention rules\" in\n * contracts-and-retention.md: pinned items and the explicitly hard-retained kinds\n * (user instructions, approvals, denials, safety constraints).\n */\nexport function isHardRetained(item: ContextItem): boolean {\n\treturn item.retentionClass === \"pinned\" || HARD_RETAINED_CONTEXT_KINDS.has(item.kind);\n}\n\n/**\n * Determine which prompt-retention actions are permitted for an item. This is the pure\n * policy helper referenced by implementation-phases.md Phase 1: it must never allow\n * dropping pinned/open/latest-failure items, and it must never allow summarizing\n * decision-bearing content that has no evidence/retrieval path.\n */\nexport function evaluateRetentionEligibility(item: ContextItem): RetentionEligibility {\n\tif (isHardRetained(item)) {\n\t\treturn {\n\t\t\tallowedActions: [\"keep_raw\"],\n\t\t\thardRetained: true,\n\t\t\treasonCodes: [item.retentionClass === \"pinned\" ? \"pinned_hard_retained\" : \"hard_retained_kind\"],\n\t\t};\n\t}\n\n\tconst retrievable = hasReferencedEvidence(item);\n\n\tswitch (item.retentionClass) {\n\t\tcase \"active\":\n\t\t\t// Current working state (active goal, open requirement, plan, blocker):\n\t\t\t// must stay present while active. Summarizing requires evidence so the\n\t\t\t// summary does not silently lose decision-bearing facts.\n\t\t\treturn {\n\t\t\t\tallowedActions: retrievable ? [\"keep_raw\", \"summarize\"] : [\"keep_raw\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: retrievable ? [\"active_summarizable\"] : [\"active_no_retrieval_path\"],\n\t\t\t};\n\t\tcase \"decision_bearing\":\n\t\t\t// Evidence for a current decision (latest failing check, current diff, etc.):\n\t\t\t// keep while the decision is pending. Only summarizable with an evidence ref\n\t\t\t// so exact identifiers remain recoverable.\n\t\t\treturn {\n\t\t\t\tallowedActions: retrievable ? [\"keep_raw\", \"summarize\"] : [\"keep_raw\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: retrievable ? [\"decision_bearing_summarizable\"] : [\"decision_bearing_no_retrieval_path\"],\n\t\t\t};\n\t\tcase \"useful\":\n\t\t\t// Can be summarized or evicted if budget is tight AND retrieval is available.\n\t\t\t// With no retrieval/source ref, the conservative default is keep_raw only.\n\t\t\treturn {\n\t\t\t\tallowedActions: retrievable\n\t\t\t\t\t? [\"keep_raw\", \"summarize\", \"pack_to_artifact\", \"drop_from_prompt\"]\n\t\t\t\t\t: [\"keep_raw\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: retrievable ? [\"useful_retrievable\"] : [\"useful_no_retrieval_path\"],\n\t\t\t};\n\t\tcase \"ephemeral\":\n\t\t\t// Should not be resent raw after immediate use (broad search output, command\n\t\t\t// logs, old file reads). Packing/dropping requires a retrieval path per the\n\t\t\t// \"retrieval precedes aggressive eviction\" ground rule.\n\t\t\treturn {\n\t\t\t\tallowedActions: retrievable\n\t\t\t\t\t? [\"keep_raw\", \"pack_to_artifact\", \"drop_from_prompt\"]\n\t\t\t\t\t: [\"keep_raw\", \"pack_to_artifact\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: retrievable ? [\"ephemeral_retrievable\"] : [\"ephemeral_no_retrieval_path\"],\n\t\t\t};\n\t\tcase \"expired\":\n\t\t\t// Should not be included in prompt unless explicitly retrieved.\n\t\t\treturn {\n\t\t\t\tallowedActions: [\"drop_from_prompt\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: [\"expired\"],\n\t\t\t};\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\tallowedActions: [\"keep_raw\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: [\"unknown_retention_class\"],\n\t\t\t};\n\t}\n}\n\nexport function canDropFromPrompt(item: ContextItem): boolean {\n\treturn evaluateRetentionEligibility(item).allowedActions.includes(\"drop_from_prompt\");\n}\n\nexport function canSummarize(item: ContextItem): boolean {\n\treturn evaluateRetentionEligibility(item).allowedActions.includes(\"summarize\");\n}\n\nexport function canPackToArtifact(item: ContextItem): boolean {\n\treturn evaluateRetentionEligibility(item).allowedActions.includes(\"pack_to_artifact\");\n}\n"]}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Pure retention-eligibility helpers for ContextItem.
3
+ *
4
+ * These functions only classify what a runtime policy is *allowed* to do with an item;
5
+ * they do not mutate, evict, or summarize anything themselves, and they never touch the
6
+ * transcript or artifact stores. Per contracts-and-retention.md, dropping from model
7
+ * context must never mean deleting from storage: these helpers only ever describe prompt
8
+ * inclusion, not deletion.
9
+ */
10
+ import { HARD_RETAINED_CONTEXT_KINDS } from "./context-item.js";
11
+ /**
12
+ * True if the item carries a ref at all. This is item-level and store-free by design: it
13
+ * does not check whether an artifact ref is still resolvable in a live artifact store
14
+ * (that check belongs to a store-aware layer, e.g. `HardConstraintFlags` in
15
+ * policy-types.ts). Do not treat this as "retrieval is available" when wiring a real store.
16
+ */
17
+ function hasReferencedEvidence(item) {
18
+ return item.primaryRef !== undefined || (item.evidenceRefs?.length ?? 0) > 0;
19
+ }
20
+ /**
21
+ * True if `kind`/`retentionClass` combination must never be dropped or summarized away,
22
+ * regardless of budget pressure. Mirrors the "Hard retention rules" in
23
+ * contracts-and-retention.md: pinned items and the explicitly hard-retained kinds
24
+ * (user instructions, approvals, denials, safety constraints).
25
+ */
26
+ export function isHardRetained(item) {
27
+ return item.retentionClass === "pinned" || HARD_RETAINED_CONTEXT_KINDS.has(item.kind);
28
+ }
29
+ /**
30
+ * Determine which prompt-retention actions are permitted for an item. This is the pure
31
+ * policy helper referenced by implementation-phases.md Phase 1: it must never allow
32
+ * dropping pinned/open/latest-failure items, and it must never allow summarizing
33
+ * decision-bearing content that has no evidence/retrieval path.
34
+ */
35
+ export function evaluateRetentionEligibility(item) {
36
+ if (isHardRetained(item)) {
37
+ return {
38
+ allowedActions: ["keep_raw"],
39
+ hardRetained: true,
40
+ reasonCodes: [item.retentionClass === "pinned" ? "pinned_hard_retained" : "hard_retained_kind"],
41
+ };
42
+ }
43
+ const retrievable = hasReferencedEvidence(item);
44
+ switch (item.retentionClass) {
45
+ case "active":
46
+ // Current working state (active goal, open requirement, plan, blocker):
47
+ // must stay present while active. Summarizing requires evidence so the
48
+ // summary does not silently lose decision-bearing facts.
49
+ return {
50
+ allowedActions: retrievable ? ["keep_raw", "summarize"] : ["keep_raw"],
51
+ hardRetained: false,
52
+ reasonCodes: retrievable ? ["active_summarizable"] : ["active_no_retrieval_path"],
53
+ };
54
+ case "decision_bearing":
55
+ // Evidence for a current decision (latest failing check, current diff, etc.):
56
+ // keep while the decision is pending. Only summarizable with an evidence ref
57
+ // so exact identifiers remain recoverable.
58
+ return {
59
+ allowedActions: retrievable ? ["keep_raw", "summarize"] : ["keep_raw"],
60
+ hardRetained: false,
61
+ reasonCodes: retrievable ? ["decision_bearing_summarizable"] : ["decision_bearing_no_retrieval_path"],
62
+ };
63
+ case "useful":
64
+ // Can be summarized or evicted if budget is tight AND retrieval is available.
65
+ // With no retrieval/source ref, the conservative default is keep_raw only.
66
+ return {
67
+ allowedActions: retrievable
68
+ ? ["keep_raw", "summarize", "pack_to_artifact", "drop_from_prompt"]
69
+ : ["keep_raw"],
70
+ hardRetained: false,
71
+ reasonCodes: retrievable ? ["useful_retrievable"] : ["useful_no_retrieval_path"],
72
+ };
73
+ case "ephemeral":
74
+ // Should not be resent raw after immediate use (broad search output, command
75
+ // logs, old file reads). Packing/dropping requires a retrieval path per the
76
+ // "retrieval precedes aggressive eviction" ground rule.
77
+ return {
78
+ allowedActions: retrievable
79
+ ? ["keep_raw", "pack_to_artifact", "drop_from_prompt"]
80
+ : ["keep_raw", "pack_to_artifact"],
81
+ hardRetained: false,
82
+ reasonCodes: retrievable ? ["ephemeral_retrievable"] : ["ephemeral_no_retrieval_path"],
83
+ };
84
+ case "expired":
85
+ // Should not be included in prompt unless explicitly retrieved.
86
+ return {
87
+ allowedActions: ["drop_from_prompt"],
88
+ hardRetained: false,
89
+ reasonCodes: ["expired"],
90
+ };
91
+ default:
92
+ return {
93
+ allowedActions: ["keep_raw"],
94
+ hardRetained: false,
95
+ reasonCodes: ["unknown_retention_class"],
96
+ };
97
+ }
98
+ }
99
+ export function canDropFromPrompt(item) {
100
+ return evaluateRetentionEligibility(item).allowedActions.includes("drop_from_prompt");
101
+ }
102
+ export function canSummarize(item) {
103
+ return evaluateRetentionEligibility(item).allowedActions.includes("summarize");
104
+ }
105
+ export function canPackToArtifact(item) {
106
+ return evaluateRetentionEligibility(item).allowedActions.includes("pack_to_artifact");
107
+ }
108
+ //# sourceMappingURL=context-retention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-retention.js","sourceRoot":"","sources":["../../../src/core/context/context-retention.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAoB,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAYlF;;;;;GAKG;AACH,SAAS,qBAAqB,CAAC,IAAiB,EAAW;IAC1D,OAAO,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAAA,CAC7E;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAiB,EAAW;IAC1D,OAAO,IAAI,CAAC,cAAc,KAAK,QAAQ,IAAI,2BAA2B,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACtF;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAAC,IAAiB,EAAwB;IACrF,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO;YACN,cAAc,EAAE,CAAC,UAAU,CAAC;YAC5B,YAAY,EAAE,IAAI;YAClB,WAAW,EAAE,CAAC,IAAI,CAAC,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,oBAAoB,CAAC;SAC/F,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAEhD,QAAQ,IAAI,CAAC,cAAc,EAAE,CAAC;QAC7B,KAAK,QAAQ;YACZ,wEAAwE;YACxE,uEAAuE;YACvE,yDAAyD;YACzD,OAAO;gBACN,cAAc,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;gBACtE,YAAY,EAAE,KAAK;gBACnB,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B,CAAC;aACjF,CAAC;QACH,KAAK,kBAAkB;YACtB,8EAA8E;YAC9E,6EAA6E;YAC7E,2CAA2C;YAC3C,OAAO;gBACN,cAAc,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;gBACtE,YAAY,EAAE,KAAK;gBACnB,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,CAAC,CAAC,oCAAoC,CAAC;aACrG,CAAC;QACH,KAAK,QAAQ;YACZ,8EAA8E;YAC9E,2EAA2E;YAC3E,OAAO;gBACN,cAAc,EAAE,WAAW;oBAC1B,CAAC,CAAC,CAAC,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,kBAAkB,CAAC;oBACnE,CAAC,CAAC,CAAC,UAAU,CAAC;gBACf,YAAY,EAAE,KAAK;gBACnB,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B,CAAC;aAChF,CAAC;QACH,KAAK,WAAW;YACf,6EAA6E;YAC7E,4EAA4E;YAC5E,wDAAwD;YACxD,OAAO;gBACN,cAAc,EAAE,WAAW;oBAC1B,CAAC,CAAC,CAAC,UAAU,EAAE,kBAAkB,EAAE,kBAAkB,CAAC;oBACtD,CAAC,CAAC,CAAC,UAAU,EAAE,kBAAkB,CAAC;gBACnC,YAAY,EAAE,KAAK;gBACnB,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,6BAA6B,CAAC;aACtF,CAAC;QACH,KAAK,SAAS;YACb,gEAAgE;YAChE,OAAO;gBACN,cAAc,EAAE,CAAC,kBAAkB,CAAC;gBACpC,YAAY,EAAE,KAAK;gBACnB,WAAW,EAAE,CAAC,SAAS,CAAC;aACxB,CAAC;QACH;YACC,OAAO;gBACN,cAAc,EAAE,CAAC,UAAU,CAAC;gBAC5B,YAAY,EAAE,KAAK;gBACnB,WAAW,EAAE,CAAC,yBAAyB,CAAC;aACxC,CAAC;IACJ,CAAC;AAAA,CACD;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAiB,EAAW;IAC7D,OAAO,4BAA4B,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;AAAA,CACtF;AAED,MAAM,UAAU,YAAY,CAAC,IAAiB,EAAW;IACxD,OAAO,4BAA4B,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAAA,CAC/E;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAiB,EAAW;IAC7D,OAAO,4BAA4B,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;AAAA,CACtF","sourcesContent":["/**\n * Pure retention-eligibility helpers for ContextItem.\n *\n * These functions only classify what a runtime policy is *allowed* to do with an item;\n * they do not mutate, evict, or summarize anything themselves, and they never touch the\n * transcript or artifact stores. Per contracts-and-retention.md, dropping from model\n * context must never mean deleting from storage: these helpers only ever describe prompt\n * inclusion, not deletion.\n */\n\nimport { type ContextItem, HARD_RETAINED_CONTEXT_KINDS } from \"./context-item.ts\";\n\nexport type RetentionAction = \"keep_raw\" | \"summarize\" | \"pack_to_artifact\" | \"drop_from_prompt\";\n\nexport interface RetentionEligibility {\n\t/** Actions a runtime policy may choose between for this item, most-preserving first. */\n\tallowedActions: RetentionAction[];\n\t/** True if the item's semantics must stay present verbatim; only \"keep_raw\" is allowed. */\n\thardRetained: boolean;\n\treasonCodes: string[];\n}\n\n/**\n * True if the item carries a ref at all. This is item-level and store-free by design: it\n * does not check whether an artifact ref is still resolvable in a live artifact store\n * (that check belongs to a store-aware layer, e.g. `HardConstraintFlags` in\n * policy-types.ts). Do not treat this as \"retrieval is available\" when wiring a real store.\n */\nfunction hasReferencedEvidence(item: ContextItem): boolean {\n\treturn item.primaryRef !== undefined || (item.evidenceRefs?.length ?? 0) > 0;\n}\n\n/**\n * True if `kind`/`retentionClass` combination must never be dropped or summarized away,\n * regardless of budget pressure. Mirrors the \"Hard retention rules\" in\n * contracts-and-retention.md: pinned items and the explicitly hard-retained kinds\n * (user instructions, approvals, denials, safety constraints).\n */\nexport function isHardRetained(item: ContextItem): boolean {\n\treturn item.retentionClass === \"pinned\" || HARD_RETAINED_CONTEXT_KINDS.has(item.kind);\n}\n\n/**\n * Determine which prompt-retention actions are permitted for an item. This is the pure\n * policy helper referenced by implementation-phases.md Phase 1: it must never allow\n * dropping pinned/open/latest-failure items, and it must never allow summarizing\n * decision-bearing content that has no evidence/retrieval path.\n */\nexport function evaluateRetentionEligibility(item: ContextItem): RetentionEligibility {\n\tif (isHardRetained(item)) {\n\t\treturn {\n\t\t\tallowedActions: [\"keep_raw\"],\n\t\t\thardRetained: true,\n\t\t\treasonCodes: [item.retentionClass === \"pinned\" ? \"pinned_hard_retained\" : \"hard_retained_kind\"],\n\t\t};\n\t}\n\n\tconst retrievable = hasReferencedEvidence(item);\n\n\tswitch (item.retentionClass) {\n\t\tcase \"active\":\n\t\t\t// Current working state (active goal, open requirement, plan, blocker):\n\t\t\t// must stay present while active. Summarizing requires evidence so the\n\t\t\t// summary does not silently lose decision-bearing facts.\n\t\t\treturn {\n\t\t\t\tallowedActions: retrievable ? [\"keep_raw\", \"summarize\"] : [\"keep_raw\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: retrievable ? [\"active_summarizable\"] : [\"active_no_retrieval_path\"],\n\t\t\t};\n\t\tcase \"decision_bearing\":\n\t\t\t// Evidence for a current decision (latest failing check, current diff, etc.):\n\t\t\t// keep while the decision is pending. Only summarizable with an evidence ref\n\t\t\t// so exact identifiers remain recoverable.\n\t\t\treturn {\n\t\t\t\tallowedActions: retrievable ? [\"keep_raw\", \"summarize\"] : [\"keep_raw\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: retrievable ? [\"decision_bearing_summarizable\"] : [\"decision_bearing_no_retrieval_path\"],\n\t\t\t};\n\t\tcase \"useful\":\n\t\t\t// Can be summarized or evicted if budget is tight AND retrieval is available.\n\t\t\t// With no retrieval/source ref, the conservative default is keep_raw only.\n\t\t\treturn {\n\t\t\t\tallowedActions: retrievable\n\t\t\t\t\t? [\"keep_raw\", \"summarize\", \"pack_to_artifact\", \"drop_from_prompt\"]\n\t\t\t\t\t: [\"keep_raw\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: retrievable ? [\"useful_retrievable\"] : [\"useful_no_retrieval_path\"],\n\t\t\t};\n\t\tcase \"ephemeral\":\n\t\t\t// Should not be resent raw after immediate use (broad search output, command\n\t\t\t// logs, old file reads). Packing/dropping requires a retrieval path per the\n\t\t\t// \"retrieval precedes aggressive eviction\" ground rule.\n\t\t\treturn {\n\t\t\t\tallowedActions: retrievable\n\t\t\t\t\t? [\"keep_raw\", \"pack_to_artifact\", \"drop_from_prompt\"]\n\t\t\t\t\t: [\"keep_raw\", \"pack_to_artifact\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: retrievable ? [\"ephemeral_retrievable\"] : [\"ephemeral_no_retrieval_path\"],\n\t\t\t};\n\t\tcase \"expired\":\n\t\t\t// Should not be included in prompt unless explicitly retrieved.\n\t\t\treturn {\n\t\t\t\tallowedActions: [\"drop_from_prompt\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: [\"expired\"],\n\t\t\t};\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\tallowedActions: [\"keep_raw\"],\n\t\t\t\thardRetained: false,\n\t\t\t\treasonCodes: [\"unknown_retention_class\"],\n\t\t\t};\n\t}\n}\n\nexport function canDropFromPrompt(item: ContextItem): boolean {\n\treturn evaluateRetentionEligibility(item).allowedActions.includes(\"drop_from_prompt\");\n}\n\nexport function canSummarize(item: ContextItem): boolean {\n\treturn evaluateRetentionEligibility(item).allowedActions.includes(\"summarize\");\n}\n\nexport function canPackToArtifact(item: ContextItem): boolean {\n\treturn evaluateRetentionEligibility(item).allowedActions.includes(\"pack_to_artifact\");\n}\n"]}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Context store abstraction (Phase 2): the operational index for context item metadata,
3
+ * retention/policy decisions, and retrieval records. Per memory-architecture.md, this is
4
+ * an index/state/cache layer, not the sole audit source — transcript and artifacts remain
5
+ * canonical. An in-memory implementation is provided for tests; sqlite-runtime-index.ts
6
+ * provides an explicit SQLite implementation for callers that opt into it.
7
+ *
8
+ * Nothing here is wired into session persistence or prompt construction by default yet.
9
+ */
10
+ import type { ContextItem } from "./context-item.ts";
11
+ import type { PolicyDecision } from "./policy-types.ts";
12
+ export type RetrievalSliceKind = "metadata" | "preview" | "lines_around_error" | "file_range" | "search_sample" | "transcript_slice" | "full_artifact";
13
+ export interface RetrievalRecord {
14
+ id: string;
15
+ contextItemId: string;
16
+ requestedAtTurn: number;
17
+ sliceKind: RetrievalSliceKind;
18
+ resultSummary: string;
19
+ }
20
+ export interface PolicyDecisionRecord {
21
+ id: string;
22
+ contextItemId?: string;
23
+ decision: PolicyDecision;
24
+ recordedAtTurn: number;
25
+ }
26
+ export interface ContextStore {
27
+ upsertItem(item: ContextItem): void;
28
+ getItem(id: string): ContextItem | undefined;
29
+ listItems(): ContextItem[];
30
+ removeItem(id: string): void;
31
+ recordPolicyDecision(record: PolicyDecisionRecord): void;
32
+ listPolicyDecisions(contextItemId?: string): PolicyDecisionRecord[];
33
+ recordRetrieval(record: RetrievalRecord): void;
34
+ listRetrievals(contextItemId?: string): RetrievalRecord[];
35
+ }
36
+ export declare function createInMemoryContextStore(): ContextStore;
37
+ //# sourceMappingURL=context-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-store.d.ts","sourceRoot":"","sources":["../../../src/core/context/context-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAC3B,UAAU,GACV,SAAS,GACT,oBAAoB,GACpB,YAAY,GACZ,eAAe,GACf,kBAAkB,GAClB,eAAe,CAAC;AAEnB,MAAM,WAAW,eAAe;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC5B,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IAC7C,SAAS,IAAI,WAAW,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7B,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACzD,mBAAmB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,oBAAoB,EAAE,CAAC;IAEpE,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAC/C,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,eAAe,EAAE,CAAC;CAC1D;AAED,wBAAgB,0BAA0B,IAAI,YAAY,CA0CzD","sourcesContent":["/**\n * Context store abstraction (Phase 2): the operational index for context item metadata,\n * retention/policy decisions, and retrieval records. Per memory-architecture.md, this is\n * an index/state/cache layer, not the sole audit source — transcript and artifacts remain\n * canonical. An in-memory implementation is provided for tests; sqlite-runtime-index.ts\n * provides an explicit SQLite implementation for callers that opt into it.\n *\n * Nothing here is wired into session persistence or prompt construction by default yet.\n */\n\nimport type { ContextItem } from \"./context-item.ts\";\nimport type { PolicyDecision } from \"./policy-types.ts\";\n\nexport type RetrievalSliceKind =\n\t| \"metadata\"\n\t| \"preview\"\n\t| \"lines_around_error\"\n\t| \"file_range\"\n\t| \"search_sample\"\n\t| \"transcript_slice\"\n\t| \"full_artifact\";\n\nexport interface RetrievalRecord {\n\tid: string;\n\tcontextItemId: string;\n\trequestedAtTurn: number;\n\tsliceKind: RetrievalSliceKind;\n\tresultSummary: string;\n}\n\nexport interface PolicyDecisionRecord {\n\tid: string;\n\tcontextItemId?: string;\n\tdecision: PolicyDecision;\n\trecordedAtTurn: number;\n}\n\nexport interface ContextStore {\n\tupsertItem(item: ContextItem): void;\n\tgetItem(id: string): ContextItem | undefined;\n\tlistItems(): ContextItem[];\n\tremoveItem(id: string): void;\n\n\trecordPolicyDecision(record: PolicyDecisionRecord): void;\n\tlistPolicyDecisions(contextItemId?: string): PolicyDecisionRecord[];\n\n\trecordRetrieval(record: RetrievalRecord): void;\n\tlistRetrievals(contextItemId?: string): RetrievalRecord[];\n}\n\nexport function createInMemoryContextStore(): ContextStore {\n\tconst items = new Map<string, ContextItem>();\n\tconst policyDecisions: PolicyDecisionRecord[] = [];\n\tconst retrievals: RetrievalRecord[] = [];\n\n\treturn {\n\t\tupsertItem(item: ContextItem): void {\n\t\t\titems.set(item.id, item);\n\t\t},\n\n\t\tgetItem(id: string): ContextItem | undefined {\n\t\t\treturn items.get(id);\n\t\t},\n\n\t\tlistItems(): ContextItem[] {\n\t\t\treturn Array.from(items.values());\n\t\t},\n\n\t\tremoveItem(id: string): void {\n\t\t\titems.delete(id);\n\t\t},\n\n\t\trecordPolicyDecision(record: PolicyDecisionRecord): void {\n\t\t\tpolicyDecisions.push(record);\n\t\t},\n\n\t\tlistPolicyDecisions(contextItemId?: string): PolicyDecisionRecord[] {\n\t\t\treturn contextItemId === undefined\n\t\t\t\t? policyDecisions.slice()\n\t\t\t\t: policyDecisions.filter((record) => record.contextItemId === contextItemId);\n\t\t},\n\n\t\trecordRetrieval(record: RetrievalRecord): void {\n\t\t\tretrievals.push(record);\n\t\t},\n\n\t\tlistRetrievals(contextItemId?: string): RetrievalRecord[] {\n\t\t\treturn contextItemId === undefined\n\t\t\t\t? retrievals.slice()\n\t\t\t\t: retrievals.filter((record) => record.contextItemId === contextItemId);\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Context store abstraction (Phase 2): the operational index for context item metadata,
3
+ * retention/policy decisions, and retrieval records. Per memory-architecture.md, this is
4
+ * an index/state/cache layer, not the sole audit source — transcript and artifacts remain
5
+ * canonical. An in-memory implementation is provided for tests; sqlite-runtime-index.ts
6
+ * provides an explicit SQLite implementation for callers that opt into it.
7
+ *
8
+ * Nothing here is wired into session persistence or prompt construction by default yet.
9
+ */
10
+ export function createInMemoryContextStore() {
11
+ const items = new Map();
12
+ const policyDecisions = [];
13
+ const retrievals = [];
14
+ return {
15
+ upsertItem(item) {
16
+ items.set(item.id, item);
17
+ },
18
+ getItem(id) {
19
+ return items.get(id);
20
+ },
21
+ listItems() {
22
+ return Array.from(items.values());
23
+ },
24
+ removeItem(id) {
25
+ items.delete(id);
26
+ },
27
+ recordPolicyDecision(record) {
28
+ policyDecisions.push(record);
29
+ },
30
+ listPolicyDecisions(contextItemId) {
31
+ return contextItemId === undefined
32
+ ? policyDecisions.slice()
33
+ : policyDecisions.filter((record) => record.contextItemId === contextItemId);
34
+ },
35
+ recordRetrieval(record) {
36
+ retrievals.push(record);
37
+ },
38
+ listRetrievals(contextItemId) {
39
+ return contextItemId === undefined
40
+ ? retrievals.slice()
41
+ : retrievals.filter((record) => record.contextItemId === contextItemId);
42
+ },
43
+ };
44
+ }
45
+ //# sourceMappingURL=context-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-store.js","sourceRoot":"","sources":["../../../src/core/context/context-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0CH,MAAM,UAAU,0BAA0B,GAAiB;IAC1D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC7C,MAAM,eAAe,GAA2B,EAAE,CAAC;IACnD,MAAM,UAAU,GAAsB,EAAE,CAAC;IAEzC,OAAO;QACN,UAAU,CAAC,IAAiB,EAAQ;YACnC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAAA,CACzB;QAED,OAAO,CAAC,EAAU,EAA2B;YAC5C,OAAO,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAAA,CACrB;QAED,SAAS,GAAkB;YAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAAA,CAClC;QAED,UAAU,CAAC,EAAU,EAAQ;YAC5B,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAAA,CACjB;QAED,oBAAoB,CAAC,MAA4B,EAAQ;YACxD,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAAA,CAC7B;QAED,mBAAmB,CAAC,aAAsB,EAA0B;YACnE,OAAO,aAAa,KAAK,SAAS;gBACjC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE;gBACzB,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,KAAK,aAAa,CAAC,CAAC;QAAA,CAC9E;QAED,eAAe,CAAC,MAAuB,EAAQ;YAC9C,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAAA,CACxB;QAED,cAAc,CAAC,aAAsB,EAAqB;YACzD,OAAO,aAAa,KAAK,SAAS;gBACjC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE;gBACpB,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,KAAK,aAAa,CAAC,CAAC;QAAA,CACzE;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Context store abstraction (Phase 2): the operational index for context item metadata,\n * retention/policy decisions, and retrieval records. Per memory-architecture.md, this is\n * an index/state/cache layer, not the sole audit source — transcript and artifacts remain\n * canonical. An in-memory implementation is provided for tests; sqlite-runtime-index.ts\n * provides an explicit SQLite implementation for callers that opt into it.\n *\n * Nothing here is wired into session persistence or prompt construction by default yet.\n */\n\nimport type { ContextItem } from \"./context-item.ts\";\nimport type { PolicyDecision } from \"./policy-types.ts\";\n\nexport type RetrievalSliceKind =\n\t| \"metadata\"\n\t| \"preview\"\n\t| \"lines_around_error\"\n\t| \"file_range\"\n\t| \"search_sample\"\n\t| \"transcript_slice\"\n\t| \"full_artifact\";\n\nexport interface RetrievalRecord {\n\tid: string;\n\tcontextItemId: string;\n\trequestedAtTurn: number;\n\tsliceKind: RetrievalSliceKind;\n\tresultSummary: string;\n}\n\nexport interface PolicyDecisionRecord {\n\tid: string;\n\tcontextItemId?: string;\n\tdecision: PolicyDecision;\n\trecordedAtTurn: number;\n}\n\nexport interface ContextStore {\n\tupsertItem(item: ContextItem): void;\n\tgetItem(id: string): ContextItem | undefined;\n\tlistItems(): ContextItem[];\n\tremoveItem(id: string): void;\n\n\trecordPolicyDecision(record: PolicyDecisionRecord): void;\n\tlistPolicyDecisions(contextItemId?: string): PolicyDecisionRecord[];\n\n\trecordRetrieval(record: RetrievalRecord): void;\n\tlistRetrievals(contextItemId?: string): RetrievalRecord[];\n}\n\nexport function createInMemoryContextStore(): ContextStore {\n\tconst items = new Map<string, ContextItem>();\n\tconst policyDecisions: PolicyDecisionRecord[] = [];\n\tconst retrievals: RetrievalRecord[] = [];\n\n\treturn {\n\t\tupsertItem(item: ContextItem): void {\n\t\t\titems.set(item.id, item);\n\t\t},\n\n\t\tgetItem(id: string): ContextItem | undefined {\n\t\t\treturn items.get(id);\n\t\t},\n\n\t\tlistItems(): ContextItem[] {\n\t\t\treturn Array.from(items.values());\n\t\t},\n\n\t\tremoveItem(id: string): void {\n\t\t\titems.delete(id);\n\t\t},\n\n\t\trecordPolicyDecision(record: PolicyDecisionRecord): void {\n\t\t\tpolicyDecisions.push(record);\n\t\t},\n\n\t\tlistPolicyDecisions(contextItemId?: string): PolicyDecisionRecord[] {\n\t\t\treturn contextItemId === undefined\n\t\t\t\t? policyDecisions.slice()\n\t\t\t\t: policyDecisions.filter((record) => record.contextItemId === contextItemId);\n\t\t},\n\n\t\trecordRetrieval(record: RetrievalRecord): void {\n\t\t\tretrievals.push(record);\n\t\t},\n\n\t\tlistRetrievals(contextItemId?: string): RetrievalRecord[] {\n\t\t\treturn contextItemId === undefined\n\t\t\t\t? retrievals.slice()\n\t\t\t\t: retrievals.filter((record) => record.contextItemId === contextItemId);\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Safe, leak-free diagnostic projections of the memory-retrieval/prompt-inclusion state,
3
+ * for the context_audit tool (src/core/extensions/builtin.ts). Nothing here queries a
4
+ * provider or touches the OKF directory -- callers must pass in already-computed reports
5
+ * (AgentSession's existing no-arg, latest-stored-only getters).
6
+ *
7
+ * `sanitizeMemoryRetrievalReportForDiagnostics` is ALLOW-LIST based, not deny-list: it
8
+ * builds its output by explicitly copying only known-safe fields, never by spreading the
9
+ * source report and deleting unsafe ones. A spread-then-delete approach would silently
10
+ * re-expose any new content-bearing field added to `MemoryRetrievalReport` later; an
11
+ * allow-list cannot leak a field it was never told to copy.
12
+ */
13
+ import type { MemoryPolicyRejectionReason } from "./memory-provider-contract.ts";
14
+ import type { MemoryProviderRetrievalStatus, MemoryRetrievalReport } from "./memory-retrieval.ts";
15
+ export type MemoryPromptInclusionStatus = "disabled" | "include_disabled" | "no_results" | "empty_block" | "included" | "failed";
16
+ export interface MemoryPromptInclusionReport {
17
+ status: MemoryPromptInclusionStatus;
18
+ enabled: boolean;
19
+ includeInPrompt: boolean;
20
+ selectedItemCount: number;
21
+ includedCount: number;
22
+ omittedCount: number;
23
+ blockChars: number;
24
+ sourceLabel?: string;
25
+ }
26
+ export declare function defaultMemoryPromptInclusionReport(): MemoryPromptInclusionReport;
27
+ /** Safe per-provider projection: fixed enums and counts only, never `error` (may embed a filesystem path). */
28
+ export interface MemoryRetrievalProviderDiagnostics {
29
+ providerId: string;
30
+ status: MemoryProviderRetrievalStatus;
31
+ rejectionReasons: MemoryPolicyRejectionReason[];
32
+ resultCount: number;
33
+ }
34
+ export interface MemoryRetrievalDiagnostics {
35
+ enabled: boolean;
36
+ maxResults: number;
37
+ providerReports: MemoryRetrievalProviderDiagnostics[];
38
+ selectedItemCount: number;
39
+ }
40
+ /**
41
+ * Projects a live `MemoryRetrievalReport` down to only safe, bounded metadata. Drops
42
+ * `request.query`, every `results[]`/`contextItems[]` content field, and
43
+ * `providerReports[].error` entirely (never redacted -- redaction logic is itself a place
44
+ * a leak could slip back in).
45
+ */
46
+ export declare function sanitizeMemoryRetrievalReportForDiagnostics(report: MemoryRetrievalReport, settings: {
47
+ enabled: boolean;
48
+ maxResults: number;
49
+ }): MemoryRetrievalDiagnostics;
50
+ //# sourceMappingURL=memory-diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-diagnostics.d.ts","sourceRoot":"","sources":["../../../src/core/context/memory-diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAElG,MAAM,MAAM,2BAA2B,GACpC,UAAU,GACV,kBAAkB,GAClB,YAAY,GACZ,aAAa,GACb,UAAU,GACV,QAAQ,CAAC;AAEZ,MAAM,WAAW,2BAA2B;IAC3C,MAAM,EAAE,2BAA2B,CAAC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,kCAAkC,IAAI,2BAA2B,CAUhF;AAED,8GAA8G;AAC9G,MAAM,WAAW,kCAAkC;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,6BAA6B,CAAC;IACtC,gBAAgB,EAAE,2BAA2B,EAAE,CAAC;IAChD,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,0BAA0B;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,kCAAkC,EAAE,CAAC;IACtD,iBAAiB,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,2CAA2C,CAC1D,MAAM,EAAE,qBAAqB,EAC7B,QAAQ,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAChD,0BAA0B,CAY5B","sourcesContent":["/**\n * Safe, leak-free diagnostic projections of the memory-retrieval/prompt-inclusion state,\n * for the context_audit tool (src/core/extensions/builtin.ts). Nothing here queries a\n * provider or touches the OKF directory -- callers must pass in already-computed reports\n * (AgentSession's existing no-arg, latest-stored-only getters).\n *\n * `sanitizeMemoryRetrievalReportForDiagnostics` is ALLOW-LIST based, not deny-list: it\n * builds its output by explicitly copying only known-safe fields, never by spreading the\n * source report and deleting unsafe ones. A spread-then-delete approach would silently\n * re-expose any new content-bearing field added to `MemoryRetrievalReport` later; an\n * allow-list cannot leak a field it was never told to copy.\n */\n\nimport type { MemoryPolicyRejectionReason } from \"./memory-provider-contract.ts\";\nimport type { MemoryProviderRetrievalStatus, MemoryRetrievalReport } from \"./memory-retrieval.ts\";\n\nexport type MemoryPromptInclusionStatus =\n\t| \"disabled\"\n\t| \"include_disabled\"\n\t| \"no_results\"\n\t| \"empty_block\"\n\t| \"included\"\n\t| \"failed\";\n\nexport interface MemoryPromptInclusionReport {\n\tstatus: MemoryPromptInclusionStatus;\n\tenabled: boolean;\n\tincludeInPrompt: boolean;\n\tselectedItemCount: number;\n\tincludedCount: number;\n\tomittedCount: number;\n\tblockChars: number;\n\tsourceLabel?: string;\n}\n\nexport function defaultMemoryPromptInclusionReport(): MemoryPromptInclusionReport {\n\treturn {\n\t\tstatus: \"disabled\",\n\t\tenabled: false,\n\t\tincludeInPrompt: false,\n\t\tselectedItemCount: 0,\n\t\tincludedCount: 0,\n\t\tomittedCount: 0,\n\t\tblockChars: 0,\n\t};\n}\n\n/** Safe per-provider projection: fixed enums and counts only, never `error` (may embed a filesystem path). */\nexport interface MemoryRetrievalProviderDiagnostics {\n\tproviderId: string;\n\tstatus: MemoryProviderRetrievalStatus;\n\trejectionReasons: MemoryPolicyRejectionReason[];\n\tresultCount: number;\n}\n\nexport interface MemoryRetrievalDiagnostics {\n\tenabled: boolean;\n\tmaxResults: number;\n\tproviderReports: MemoryRetrievalProviderDiagnostics[];\n\tselectedItemCount: number;\n}\n\n/**\n * Projects a live `MemoryRetrievalReport` down to only safe, bounded metadata. Drops\n * `request.query`, every `results[]`/`contextItems[]` content field, and\n * `providerReports[].error` entirely (never redacted -- redaction logic is itself a place\n * a leak could slip back in).\n */\nexport function sanitizeMemoryRetrievalReportForDiagnostics(\n\treport: MemoryRetrievalReport,\n\tsettings: { enabled: boolean; maxResults: number },\n): MemoryRetrievalDiagnostics {\n\treturn {\n\t\tenabled: settings.enabled,\n\t\tmaxResults: settings.maxResults,\n\t\tproviderReports: report.providerReports.map((providerReport) => ({\n\t\t\tproviderId: providerReport.providerId,\n\t\t\tstatus: providerReport.status,\n\t\t\trejectionReasons: [...providerReport.rejectionReasons],\n\t\t\tresultCount: providerReport.resultCount,\n\t\t})),\n\t\tselectedItemCount: report.contextItems.length,\n\t};\n}\n"]}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Safe, leak-free diagnostic projections of the memory-retrieval/prompt-inclusion state,
3
+ * for the context_audit tool (src/core/extensions/builtin.ts). Nothing here queries a
4
+ * provider or touches the OKF directory -- callers must pass in already-computed reports
5
+ * (AgentSession's existing no-arg, latest-stored-only getters).
6
+ *
7
+ * `sanitizeMemoryRetrievalReportForDiagnostics` is ALLOW-LIST based, not deny-list: it
8
+ * builds its output by explicitly copying only known-safe fields, never by spreading the
9
+ * source report and deleting unsafe ones. A spread-then-delete approach would silently
10
+ * re-expose any new content-bearing field added to `MemoryRetrievalReport` later; an
11
+ * allow-list cannot leak a field it was never told to copy.
12
+ */
13
+ export function defaultMemoryPromptInclusionReport() {
14
+ return {
15
+ status: "disabled",
16
+ enabled: false,
17
+ includeInPrompt: false,
18
+ selectedItemCount: 0,
19
+ includedCount: 0,
20
+ omittedCount: 0,
21
+ blockChars: 0,
22
+ };
23
+ }
24
+ /**
25
+ * Projects a live `MemoryRetrievalReport` down to only safe, bounded metadata. Drops
26
+ * `request.query`, every `results[]`/`contextItems[]` content field, and
27
+ * `providerReports[].error` entirely (never redacted -- redaction logic is itself a place
28
+ * a leak could slip back in).
29
+ */
30
+ export function sanitizeMemoryRetrievalReportForDiagnostics(report, settings) {
31
+ return {
32
+ enabled: settings.enabled,
33
+ maxResults: settings.maxResults,
34
+ providerReports: report.providerReports.map((providerReport) => ({
35
+ providerId: providerReport.providerId,
36
+ status: providerReport.status,
37
+ rejectionReasons: [...providerReport.rejectionReasons],
38
+ resultCount: providerReport.resultCount,
39
+ })),
40
+ selectedItemCount: report.contextItems.length,
41
+ };
42
+ }
43
+ //# sourceMappingURL=memory-diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-diagnostics.js","sourceRoot":"","sources":["../../../src/core/context/memory-diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAwBH,MAAM,UAAU,kCAAkC,GAAgC;IACjF,OAAO;QACN,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,KAAK;QACd,eAAe,EAAE,KAAK;QACtB,iBAAiB,EAAE,CAAC;QACpB,aAAa,EAAE,CAAC;QAChB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;KACb,CAAC;AAAA,CACF;AAiBD;;;;;GAKG;AACH,MAAM,UAAU,2CAA2C,CAC1D,MAA6B,EAC7B,QAAkD,EACrB;IAC7B,OAAO;QACN,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,eAAe,EAAE,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;YAChE,UAAU,EAAE,cAAc,CAAC,UAAU;YACrC,MAAM,EAAE,cAAc,CAAC,MAAM;YAC7B,gBAAgB,EAAE,CAAC,GAAG,cAAc,CAAC,gBAAgB,CAAC;YACtD,WAAW,EAAE,cAAc,CAAC,WAAW;SACvC,CAAC,CAAC;QACH,iBAAiB,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM;KAC7C,CAAC;AAAA,CACF","sourcesContent":["/**\n * Safe, leak-free diagnostic projections of the memory-retrieval/prompt-inclusion state,\n * for the context_audit tool (src/core/extensions/builtin.ts). Nothing here queries a\n * provider or touches the OKF directory -- callers must pass in already-computed reports\n * (AgentSession's existing no-arg, latest-stored-only getters).\n *\n * `sanitizeMemoryRetrievalReportForDiagnostics` is ALLOW-LIST based, not deny-list: it\n * builds its output by explicitly copying only known-safe fields, never by spreading the\n * source report and deleting unsafe ones. A spread-then-delete approach would silently\n * re-expose any new content-bearing field added to `MemoryRetrievalReport` later; an\n * allow-list cannot leak a field it was never told to copy.\n */\n\nimport type { MemoryPolicyRejectionReason } from \"./memory-provider-contract.ts\";\nimport type { MemoryProviderRetrievalStatus, MemoryRetrievalReport } from \"./memory-retrieval.ts\";\n\nexport type MemoryPromptInclusionStatus =\n\t| \"disabled\"\n\t| \"include_disabled\"\n\t| \"no_results\"\n\t| \"empty_block\"\n\t| \"included\"\n\t| \"failed\";\n\nexport interface MemoryPromptInclusionReport {\n\tstatus: MemoryPromptInclusionStatus;\n\tenabled: boolean;\n\tincludeInPrompt: boolean;\n\tselectedItemCount: number;\n\tincludedCount: number;\n\tomittedCount: number;\n\tblockChars: number;\n\tsourceLabel?: string;\n}\n\nexport function defaultMemoryPromptInclusionReport(): MemoryPromptInclusionReport {\n\treturn {\n\t\tstatus: \"disabled\",\n\t\tenabled: false,\n\t\tincludeInPrompt: false,\n\t\tselectedItemCount: 0,\n\t\tincludedCount: 0,\n\t\tomittedCount: 0,\n\t\tblockChars: 0,\n\t};\n}\n\n/** Safe per-provider projection: fixed enums and counts only, never `error` (may embed a filesystem path). */\nexport interface MemoryRetrievalProviderDiagnostics {\n\tproviderId: string;\n\tstatus: MemoryProviderRetrievalStatus;\n\trejectionReasons: MemoryPolicyRejectionReason[];\n\tresultCount: number;\n}\n\nexport interface MemoryRetrievalDiagnostics {\n\tenabled: boolean;\n\tmaxResults: number;\n\tproviderReports: MemoryRetrievalProviderDiagnostics[];\n\tselectedItemCount: number;\n}\n\n/**\n * Projects a live `MemoryRetrievalReport` down to only safe, bounded metadata. Drops\n * `request.query`, every `results[]`/`contextItems[]` content field, and\n * `providerReports[].error` entirely (never redacted -- redaction logic is itself a place\n * a leak could slip back in).\n */\nexport function sanitizeMemoryRetrievalReportForDiagnostics(\n\treport: MemoryRetrievalReport,\n\tsettings: { enabled: boolean; maxResults: number },\n): MemoryRetrievalDiagnostics {\n\treturn {\n\t\tenabled: settings.enabled,\n\t\tmaxResults: settings.maxResults,\n\t\tproviderReports: report.providerReports.map((providerReport) => ({\n\t\t\tproviderId: providerReport.providerId,\n\t\t\tstatus: providerReport.status,\n\t\t\trejectionReasons: [...providerReport.rejectionReasons],\n\t\t\tresultCount: providerReport.resultCount,\n\t\t})),\n\t\tselectedItemCount: report.contextItems.length,\n\t};\n}\n"]}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Memory index store abstraction (Phase 2): the operational index over durable memory
3
+ * refs (Pi OKF and, later, external providers), so retrieval can rank/filter without
4
+ * re-querying every source on every turn. This is an index/cache layer per
5
+ * memory-architecture.md, not the durable memory itself; the OKF bundle (or a provider)
6
+ * remains canonical for the underlying content.
7
+ *
8
+ * This module does not hardcode Automata or any specific provider: `ContextMemoryRef`
9
+ * already carries an opaque `providerId`, and nothing here special-cases a provider name.
10
+ * No external provider queries or writes happen here — this is metadata indexing only.
11
+ */
12
+ import type { ContextMemoryRef, MemoryScope } from "./context-item.ts";
13
+ export interface MemoryIndexRecord {
14
+ ref: ContextMemoryRef;
15
+ title?: string;
16
+ summary: string;
17
+ indexedAtTurn: number;
18
+ stale: boolean;
19
+ }
20
+ export interface MemoryIndexStore {
21
+ upsert(record: MemoryIndexRecord): void;
22
+ get(providerId: string, itemId: string): MemoryIndexRecord | undefined;
23
+ list(scope?: MemoryScope): MemoryIndexRecord[];
24
+ markStale(providerId: string, itemId: string): void;
25
+ remove(providerId: string, itemId: string): void;
26
+ }
27
+ export declare function createInMemoryMemoryIndexStore(): MemoryIndexStore;
28
+ //# sourceMappingURL=memory-index-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-index-store.d.ts","sourceRoot":"","sources":["../../../src/core/context/memory-index-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEvE,MAAM,WAAW,iBAAiB;IACjC,GAAG,EAAE,gBAAgB,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAChC,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACxC,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAAC;IACvE,IAAI,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,iBAAiB,EAAE,CAAC;IAC/C,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACpD,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACjD;AAMD,wBAAgB,8BAA8B,IAAI,gBAAgB,CA0BjE","sourcesContent":["/**\n * Memory index store abstraction (Phase 2): the operational index over durable memory\n * refs (Pi OKF and, later, external providers), so retrieval can rank/filter without\n * re-querying every source on every turn. This is an index/cache layer per\n * memory-architecture.md, not the durable memory itself; the OKF bundle (or a provider)\n * remains canonical for the underlying content.\n *\n * This module does not hardcode Automata or any specific provider: `ContextMemoryRef`\n * already carries an opaque `providerId`, and nothing here special-cases a provider name.\n * No external provider queries or writes happen here — this is metadata indexing only.\n */\n\nimport type { ContextMemoryRef, MemoryScope } from \"./context-item.ts\";\n\nexport interface MemoryIndexRecord {\n\tref: ContextMemoryRef;\n\ttitle?: string;\n\tsummary: string;\n\tindexedAtTurn: number;\n\tstale: boolean;\n}\n\nexport interface MemoryIndexStore {\n\tupsert(record: MemoryIndexRecord): void;\n\tget(providerId: string, itemId: string): MemoryIndexRecord | undefined;\n\tlist(scope?: MemoryScope): MemoryIndexRecord[];\n\tmarkStale(providerId: string, itemId: string): void;\n\tremove(providerId: string, itemId: string): void;\n}\n\nfunction indexKey(providerId: string, itemId: string): string {\n\treturn `${providerId}\\0${itemId}`;\n}\n\nexport function createInMemoryMemoryIndexStore(): MemoryIndexStore {\n\tconst records = new Map<string, MemoryIndexRecord>();\n\n\treturn {\n\t\tupsert(record: MemoryIndexRecord): void {\n\t\t\trecords.set(indexKey(record.ref.providerId, record.ref.itemId), record);\n\t\t},\n\n\t\tget(providerId: string, itemId: string): MemoryIndexRecord | undefined {\n\t\t\treturn records.get(indexKey(providerId, itemId));\n\t\t},\n\n\t\tlist(scope?: MemoryScope): MemoryIndexRecord[] {\n\t\t\tconst all = Array.from(records.values());\n\t\t\treturn scope === undefined ? all : all.filter((record) => record.ref.scope === scope);\n\t\t},\n\n\t\tmarkStale(providerId: string, itemId: string): void {\n\t\t\tconst record = records.get(indexKey(providerId, itemId));\n\t\t\tif (record) record.stale = true;\n\t\t},\n\n\t\tremove(providerId: string, itemId: string): void {\n\t\t\trecords.delete(indexKey(providerId, itemId));\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Memory index store abstraction (Phase 2): the operational index over durable memory
3
+ * refs (Pi OKF and, later, external providers), so retrieval can rank/filter without
4
+ * re-querying every source on every turn. This is an index/cache layer per
5
+ * memory-architecture.md, not the durable memory itself; the OKF bundle (or a provider)
6
+ * remains canonical for the underlying content.
7
+ *
8
+ * This module does not hardcode Automata or any specific provider: `ContextMemoryRef`
9
+ * already carries an opaque `providerId`, and nothing here special-cases a provider name.
10
+ * No external provider queries or writes happen here — this is metadata indexing only.
11
+ */
12
+ function indexKey(providerId, itemId) {
13
+ return `${providerId}\0${itemId}`;
14
+ }
15
+ export function createInMemoryMemoryIndexStore() {
16
+ const records = new Map();
17
+ return {
18
+ upsert(record) {
19
+ records.set(indexKey(record.ref.providerId, record.ref.itemId), record);
20
+ },
21
+ get(providerId, itemId) {
22
+ return records.get(indexKey(providerId, itemId));
23
+ },
24
+ list(scope) {
25
+ const all = Array.from(records.values());
26
+ return scope === undefined ? all : all.filter((record) => record.ref.scope === scope);
27
+ },
28
+ markStale(providerId, itemId) {
29
+ const record = records.get(indexKey(providerId, itemId));
30
+ if (record)
31
+ record.stale = true;
32
+ },
33
+ remove(providerId, itemId) {
34
+ records.delete(indexKey(providerId, itemId));
35
+ },
36
+ };
37
+ }
38
+ //# sourceMappingURL=memory-index-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-index-store.js","sourceRoot":"","sources":["../../../src/core/context/memory-index-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoBH,SAAS,QAAQ,CAAC,UAAkB,EAAE,MAAc,EAAU;IAC7D,OAAO,GAAG,UAAU,KAAK,MAAM,EAAE,CAAC;AAAA,CAClC;AAED,MAAM,UAAU,8BAA8B,GAAqB;IAClE,MAAM,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAC;IAErD,OAAO;QACN,MAAM,CAAC,MAAyB,EAAQ;YACvC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;QAAA,CACxE;QAED,GAAG,CAAC,UAAkB,EAAE,MAAc,EAAiC;YACtE,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;QAAA,CACjD;QAED,IAAI,CAAC,KAAmB,EAAuB;YAC9C,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACzC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;QAAA,CACtF;QAED,SAAS,CAAC,UAAkB,EAAE,MAAc,EAAQ;YACnD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;YACzD,IAAI,MAAM;gBAAE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;QAAA,CAChC;QAED,MAAM,CAAC,UAAkB,EAAE,MAAc,EAAQ;YAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;QAAA,CAC7C;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Memory index store abstraction (Phase 2): the operational index over durable memory\n * refs (Pi OKF and, later, external providers), so retrieval can rank/filter without\n * re-querying every source on every turn. This is an index/cache layer per\n * memory-architecture.md, not the durable memory itself; the OKF bundle (or a provider)\n * remains canonical for the underlying content.\n *\n * This module does not hardcode Automata or any specific provider: `ContextMemoryRef`\n * already carries an opaque `providerId`, and nothing here special-cases a provider name.\n * No external provider queries or writes happen here — this is metadata indexing only.\n */\n\nimport type { ContextMemoryRef, MemoryScope } from \"./context-item.ts\";\n\nexport interface MemoryIndexRecord {\n\tref: ContextMemoryRef;\n\ttitle?: string;\n\tsummary: string;\n\tindexedAtTurn: number;\n\tstale: boolean;\n}\n\nexport interface MemoryIndexStore {\n\tupsert(record: MemoryIndexRecord): void;\n\tget(providerId: string, itemId: string): MemoryIndexRecord | undefined;\n\tlist(scope?: MemoryScope): MemoryIndexRecord[];\n\tmarkStale(providerId: string, itemId: string): void;\n\tremove(providerId: string, itemId: string): void;\n}\n\nfunction indexKey(providerId: string, itemId: string): string {\n\treturn `${providerId}\\0${itemId}`;\n}\n\nexport function createInMemoryMemoryIndexStore(): MemoryIndexStore {\n\tconst records = new Map<string, MemoryIndexRecord>();\n\n\treturn {\n\t\tupsert(record: MemoryIndexRecord): void {\n\t\t\trecords.set(indexKey(record.ref.providerId, record.ref.itemId), record);\n\t\t},\n\n\t\tget(providerId: string, itemId: string): MemoryIndexRecord | undefined {\n\t\t\treturn records.get(indexKey(providerId, itemId));\n\t\t},\n\n\t\tlist(scope?: MemoryScope): MemoryIndexRecord[] {\n\t\t\tconst all = Array.from(records.values());\n\t\t\treturn scope === undefined ? all : all.filter((record) => record.ref.scope === scope);\n\t\t},\n\n\t\tmarkStale(providerId: string, itemId: string): void {\n\t\t\tconst record = records.get(indexKey(providerId, itemId));\n\t\t\tif (record) record.stale = true;\n\t\t},\n\n\t\tremove(providerId: string, itemId: string): void {\n\t\t\trecords.delete(indexKey(providerId, itemId));\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Pure bounding/formatting for the local-memory prompt-inclusion pilot (see
3
+ * memory-retrieval.ts for the observe-only retrieval this consumes). This module only ever
4
+ * builds bounded, plain text; it does not know about messages, the transcript, the
5
+ * untrusted-content boundary, or AgentSession -- all of that wiring lives in
6
+ * agent-session.ts, which wraps this module's output with `wrapUntrustedText` before
7
+ * appending it to the provider-visible prompt.
8
+ *
9
+ * These caps are the ONLY budget protection for the injected block: it is appended AFTER
10
+ * context-gc and prompt-policy enforcement have already run, so nothing downstream trims
11
+ * it. Treat `MAX_CHARS_PER_ITEM`/`MAX_TOTAL_CHARS` as load-bearing, not merely defensive.
12
+ */
13
+ import type { ContextItem } from "./context-item.ts";
14
+ export declare const MEMORY_PROMPT_BLOCK_MAX_CHARS_PER_ITEM = 300;
15
+ export declare const MEMORY_PROMPT_BLOCK_MAX_TOTAL_CHARS = 2000;
16
+ export interface MemoryPromptBlockOptions {
17
+ maxCharsPerItem?: number;
18
+ maxTotalChars?: number;
19
+ }
20
+ export interface MemoryPromptBlockResult {
21
+ /** undefined when there is nothing to include (no items, or all summaries empty). */
22
+ text: string | undefined;
23
+ includedCount: number;
24
+ omittedCount: number;
25
+ }
26
+ /**
27
+ * Builds a numbered, per-item-truncated list of memory item summaries, bounded to a hard
28
+ * total character budget. Always includes at least the first non-empty item (truncated to
29
+ * `maxCharsPerItem`, which is expected to be well under `maxTotalChars`), even if that item
30
+ * alone would otherwise exceed the total budget -- callers should never see a report with
31
+ * results but an empty block.
32
+ */
33
+ export declare function buildMemoryPromptBlock(contextItems: readonly ContextItem[], options?: MemoryPromptBlockOptions): MemoryPromptBlockResult;
34
+ //# sourceMappingURL=memory-prompt-block.d.ts.map