@remnic/core 9.4.2 → 9.6.0

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 (379) hide show
  1. package/dist/access-admin-ops-surface.d.ts +6 -6
  2. package/dist/access-admin-ops-surface.js +28 -28
  3. package/dist/access-boundary.d.ts +27 -8
  4. package/dist/access-boundary.js +33 -29
  5. package/dist/access-cli.js +83 -81
  6. package/dist/access-cli.js.map +1 -1
  7. package/dist/access-http.d.ts +52 -6
  8. package/dist/access-http.js +40 -38
  9. package/dist/access-identity-continuity-surface.d.ts +5 -5
  10. package/dist/access-identity-continuity-surface.js +28 -28
  11. package/dist/access-lcm-surface.d.ts +6 -6
  12. package/dist/access-lcm-surface.js +28 -28
  13. package/dist/access-mcp.d.ts +16 -6
  14. package/dist/access-mcp.js +37 -35
  15. package/dist/access-observe-write-surface.d.ts +6 -6
  16. package/dist/access-observe-write-surface.js +28 -28
  17. package/dist/access-operations-batch.js +33 -32
  18. package/dist/access-operations.d.ts +9 -9
  19. package/dist/access-operations.js +35 -34
  20. package/dist/access-recall-surface.d.ts +6 -6
  21. package/dist/access-recall-surface.js +28 -28
  22. package/dist/access-schema.d.ts +4 -4
  23. package/dist/access-schema.js +4 -4
  24. package/dist/{access-service-m-2VO_Ig.d.ts → access-service-CXJaql3A.d.ts} +4 -4
  25. package/dist/access-service.d.ts +6 -6
  26. package/dist/access-service.js +28 -28
  27. package/dist/access-surface-catalog.d.ts +6 -6
  28. package/dist/access-surface-catalog.js +1 -0
  29. package/dist/access-surface-catalog.js.map +1 -1
  30. package/dist/access-token-capabilities.d.ts +174 -0
  31. package/dist/access-token-capabilities.js +33 -0
  32. package/dist/action-confidence.d.ts +1 -1
  33. package/dist/active-memory-bridge.d.ts +1 -1
  34. package/dist/active-recall.d.ts +1 -1
  35. package/dist/active-recall.js +2 -2
  36. package/dist/adapters/index.js +4 -4
  37. package/dist/adapters/registry.js +2 -2
  38. package/dist/{auto-sync-HMHQHUAG.js → auto-sync-4A5YBWYO.js} +4 -4
  39. package/dist/behavior-learner.d.ts +1 -1
  40. package/dist/behavior-signals.d.ts +1 -1
  41. package/dist/bootstrap.d.ts +5 -5
  42. package/dist/briefing.d.ts +2 -2
  43. package/dist/briefing.js +9 -9
  44. package/dist/buffer-surprise-report.d.ts +1 -1
  45. package/dist/buffer.d.ts +2 -2
  46. package/dist/calibration.d.ts +1 -1
  47. package/dist/capabilities.d.ts +1 -1
  48. package/dist/{capsule-crypto-CZJSLEFG.js → capsule-crypto-RAARDY3M.js} +2 -2
  49. package/dist/capsule-crypto-RAARDY3M.js.map +1 -0
  50. package/dist/{catalog-BxWokdC2.d.ts → catalog-C9cu67Ig.d.ts} +1 -1
  51. package/dist/causal-behavior.d.ts +1 -1
  52. package/dist/causal-behavior.js +5 -5
  53. package/dist/causal-chain.js +3 -3
  54. package/dist/causal-consolidation.d.ts +1 -1
  55. package/dist/causal-consolidation.js +13 -13
  56. package/dist/causal-retrieval.js +3 -3
  57. package/dist/causal-trajectory-graph.d.ts +1 -1
  58. package/dist/causal-trajectory.js +1 -1
  59. package/dist/{chunk-6ZIETXZ2.js → chunk-23JFRB73.js} +2 -2
  60. package/dist/{chunk-IC6QX5TC.js → chunk-3XIY7MDQ.js} +6 -6
  61. package/dist/{chunk-FZGGZAAU.js → chunk-4GNEDXDI.js} +146 -2
  62. package/dist/chunk-4GNEDXDI.js.map +1 -0
  63. package/dist/{chunk-LOR6ZM5R.js → chunk-4LV23CHK.js} +2 -2
  64. package/dist/{chunk-E2SPGGUI.js → chunk-4OKLXWDZ.js} +13 -6
  65. package/dist/chunk-4OKLXWDZ.js.map +1 -0
  66. package/dist/{chunk-AER6MT24.js → chunk-6SXVCD7W.js} +2 -2
  67. package/dist/{chunk-OHDJ34CC.js → chunk-72WG5QKN.js} +2 -2
  68. package/dist/{chunk-CZAZX7JP.js → chunk-7MW3CVLD.js} +4 -4
  69. package/dist/{chunk-CXLNZXG5.js → chunk-7XGSIUP5.js} +1 -1
  70. package/dist/{chunk-CZAA5N5S.js → chunk-AYZJID4S.js} +2 -2
  71. package/dist/{chunk-M7XQSUBB.js → chunk-B3ABVQ36.js} +116 -9
  72. package/dist/chunk-B3ABVQ36.js.map +1 -0
  73. package/dist/{chunk-6BISDEN6.js → chunk-BEM4D2QG.js} +14 -14
  74. package/dist/{chunk-ZPOROUTX.js → chunk-CYWA2CXR.js} +5 -5
  75. package/dist/{chunk-M5QKGHCR.js → chunk-CYWCKFCL.js} +5 -5
  76. package/dist/chunk-D7FOKIY5.js +173 -0
  77. package/dist/chunk-D7FOKIY5.js.map +1 -0
  78. package/dist/{chunk-4BFRBP45.js → chunk-DEG5ULFJ.js} +2 -2
  79. package/dist/{chunk-JLR3JSTL.js → chunk-DS7MM2ES.js} +3 -3
  80. package/dist/{chunk-2BFLDH5F.js → chunk-EEIROWEG.js} +2 -2
  81. package/dist/{chunk-5QZDMSSN.js → chunk-FKCRGLRD.js} +237 -82
  82. package/dist/{chunk-5QZDMSSN.js.map → chunk-FKCRGLRD.js.map} +1 -1
  83. package/dist/{chunk-X4A62ET7.js → chunk-H2DXDQCQ.js} +17 -17
  84. package/dist/{chunk-27FLVMDC.js → chunk-HLN7RROI.js} +7 -7
  85. package/dist/chunk-IC2TCZJ2.js +54 -0
  86. package/dist/chunk-IC2TCZJ2.js.map +1 -0
  87. package/dist/{chunk-2U2A5HF4.js → chunk-J3XHPFEU.js} +6 -6
  88. package/dist/{chunk-AKUCU7CI.js → chunk-JI5AVXYO.js} +5 -5
  89. package/dist/{chunk-KCJ5H6XQ.js → chunk-JSNVWNGX.js} +2 -2
  90. package/dist/{chunk-7Z2DZNWN.js → chunk-KL4UAXUY.js} +43 -2
  91. package/dist/{chunk-7Z2DZNWN.js.map → chunk-KL4UAXUY.js.map} +1 -1
  92. package/dist/{chunk-FLVL4L3L.js → chunk-KTULX4YO.js} +4 -4
  93. package/dist/{chunk-ILFJ7AVS.js → chunk-LADFWYHY.js} +35 -21
  94. package/dist/chunk-LADFWYHY.js.map +1 -0
  95. package/dist/{chunk-437S3G37.js → chunk-LNQUAJNC.js} +1 -1
  96. package/dist/{chunk-EPGWWCZF.js → chunk-LR5DZ56F.js} +6 -6
  97. package/dist/{chunk-YDSWRD33.js → chunk-N3JDIRBW.js} +4 -4
  98. package/dist/{chunk-OUMTBFSQ.js → chunk-NKCPUHCI.js} +5 -5
  99. package/dist/{chunk-7QWMTOIF.js → chunk-P454KXD6.js} +112 -34
  100. package/dist/chunk-P454KXD6.js.map +1 -0
  101. package/dist/{chunk-DR6PEJU3.js → chunk-PCLIWBGD.js} +44 -59
  102. package/dist/chunk-PCLIWBGD.js.map +1 -0
  103. package/dist/{chunk-BGTAL46Y.js → chunk-PNLFN2PZ.js} +2 -2
  104. package/dist/{chunk-P6SYWE4G.js → chunk-PVUJ6WVV.js} +10 -10
  105. package/dist/{chunk-YPEMNNNY.js → chunk-RGK27ELN.js} +6 -6
  106. package/dist/{chunk-2QSZNTDO.js → chunk-RKNJBZ55.js} +4 -4
  107. package/dist/{chunk-66FLU5BT.js → chunk-SIRPLF54.js} +6 -6
  108. package/dist/{chunk-M7GGMGMZ.js → chunk-SVOHGUMI.js} +1202 -126
  109. package/dist/chunk-SVOHGUMI.js.map +1 -0
  110. package/dist/{chunk-HRCACVHL.js → chunk-TLUDFPZL.js} +2 -2
  111. package/dist/{chunk-2FOD2YY3.js → chunk-UFUKHGZD.js} +236 -103
  112. package/dist/chunk-UFUKHGZD.js.map +1 -0
  113. package/dist/{chunk-2MR3MFQB.js → chunk-UPSAT4PY.js} +2 -2
  114. package/dist/{chunk-4P4626RY.js → chunk-UTRJFDP2.js} +4 -4
  115. package/dist/{chunk-CGS7UKWM.js → chunk-VCW74PNH.js} +2 -2
  116. package/dist/{chunk-5GPPACXK.js → chunk-VSMRDBFT.js} +2 -1
  117. package/dist/{chunk-NG7YBCJO.js → chunk-XCL57M6Q.js} +4 -4
  118. package/dist/{chunk-CLX5VDNY.js → chunk-Y4RKAQZ7.js} +4 -4
  119. package/dist/{chunk-DGYCWCQ7.js → chunk-Y7UNNAZD.js} +2 -2
  120. package/dist/{chunk-EZ25VE3G.js → chunk-YNDLCWXS.js} +4 -4
  121. package/dist/{chunk-XN3TUUX2.js → chunk-YQB32INI.js} +2 -2
  122. package/dist/{cli-EiBBOt3r.d.ts → cli-CqdPA6z9.d.ts} +3 -3
  123. package/dist/cli.d.ts +7 -7
  124. package/dist/cli.js +61 -59
  125. package/dist/compounding/engine.d.ts +2 -2
  126. package/dist/compounding/engine.js +9 -9
  127. package/dist/compounding/preference-consolidator.d.ts +1 -1
  128. package/dist/compression-optimizer.d.ts +1 -1
  129. package/dist/config.d.ts +1 -1
  130. package/dist/config.js +2 -2
  131. package/dist/connectors/codex-materialize-runner.d.ts +1 -1
  132. package/dist/connectors/codex-materialize-runner.js +9 -9
  133. package/dist/connectors/codex-materialize.d.ts +1 -1
  134. package/dist/connectors/index.d.ts +1 -1
  135. package/dist/connectors/index.js +13 -11
  136. package/dist/consolidation-provenance-check.d.ts +2 -2
  137. package/dist/consolidation-undo.d.ts +2 -2
  138. package/dist/contradiction/index.d.ts +2 -2
  139. package/dist/contradiction/index.js +4 -4
  140. package/dist/conversation-index/backend.d.ts +1 -1
  141. package/dist/conversation-index/backend.js +2 -2
  142. package/dist/conversation-index/chunker.d.ts +1 -1
  143. package/dist/conversation-index/faiss-adapter.d.ts +1 -1
  144. package/dist/conversation-index/indexer.d.ts +1 -1
  145. package/dist/conversation-index/search.d.ts +1 -1
  146. package/dist/dashboard-runtime.js +2 -2
  147. package/dist/day-summary.d.ts +1 -1
  148. package/dist/delinearize.d.ts +1 -1
  149. package/dist/direct-answer-wiring.d.ts +1 -1
  150. package/dist/direct-answer.d.ts +1 -1
  151. package/dist/embedding-fallback.d.ts +1 -1
  152. package/dist/enrichment/index.d.ts +1 -1
  153. package/dist/entity-retrieval.d.ts +2 -2
  154. package/dist/entity-retrieval.js +9 -9
  155. package/dist/entity-schema.d.ts +1 -1
  156. package/dist/explicit-capture.d.ts +5 -5
  157. package/dist/extraction-faithfulness.d.ts +1 -1
  158. package/dist/extraction-judge-telemetry.d.ts +1 -1
  159. package/dist/extraction-judge-training.d.ts +1 -1
  160. package/dist/extraction-judge.d.ts +1 -1
  161. package/dist/extraction.d.ts +1 -1
  162. package/dist/fallback-llm.d.ts +1 -1
  163. package/dist/{first-start-migration-DY6YCRC2.js → first-start-migration-VBJQL6OI.js} +5 -5
  164. package/dist/graph-dashboard-diff.d.ts +1 -1
  165. package/dist/graph-dashboard-key.d.ts +1 -1
  166. package/dist/graph-dashboard-parser.d.ts +1 -1
  167. package/dist/graph-edge-reinforcement.d.ts +1 -1
  168. package/dist/graph-snapshot.d.ts +1 -1
  169. package/dist/graph.d.ts +1 -1
  170. package/dist/identity-continuity.d.ts +1 -1
  171. package/dist/importance.d.ts +1 -1
  172. package/dist/index.d.ts +271 -17
  173. package/dist/index.js +163 -99
  174. package/dist/intent.d.ts +1 -1
  175. package/dist/lcm/engine.d.ts +1 -1
  176. package/dist/lcm/engine.js +2 -2
  177. package/dist/lcm/index.d.ts +1 -1
  178. package/dist/lcm/index.js +2 -2
  179. package/dist/lcm/tools.d.ts +1 -1
  180. package/dist/lifecycle.d.ts +1 -1
  181. package/dist/live-connectors-runner.d.ts +1 -1
  182. package/dist/local-llm.d.ts +1 -1
  183. package/dist/local-model-endpoint.d.ts +1 -1
  184. package/dist/maintenance/memory-governance.d.ts +1 -1
  185. package/dist/maintenance/memory-governance.js +10 -10
  186. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +9 -9
  187. package/dist/maintenance/rebuild-memory-projection.js +11 -11
  188. package/dist/mcp-memory-inspector-app.d.ts +6 -6
  189. package/dist/mcp-read-only-tools.d.ts +16 -0
  190. package/dist/mcp-read-only-tools.js +8 -0
  191. package/dist/mcp-read-only-tools.js.map +1 -0
  192. package/dist/memory-action-policy.d.ts +1 -1
  193. package/dist/memory-cache.d.ts +1 -1
  194. package/dist/memory-lifecycle-ledger-utils.d.ts +1 -1
  195. package/dist/memory-projection-store.d.ts +1 -1
  196. package/dist/memory-provenance.d.ts +1 -1
  197. package/dist/memory-worth-outcomes.d.ts +2 -2
  198. package/dist/models-json.d.ts +1 -1
  199. package/dist/namespaces/migrate.d.ts +3 -3
  200. package/dist/namespaces/migrate.js +19 -19
  201. package/dist/namespaces/principal.d.ts +1 -1
  202. package/dist/namespaces/search.d.ts +1 -1
  203. package/dist/namespaces/search.js +10 -10
  204. package/dist/namespaces/storage.d.ts +3 -3
  205. package/dist/namespaces/storage.js +9 -9
  206. package/dist/native-knowledge.d.ts +1 -1
  207. package/dist/operator-toolkit.d.ts +2 -2
  208. package/dist/operator-toolkit.js +25 -25
  209. package/dist/orchestration/compression-guideline-coordinator.d.ts +2 -2
  210. package/dist/orchestration/maintenance.d.ts +2 -2
  211. package/dist/orchestration/maintenance.js +11 -11
  212. package/dist/{orchestrator-B2Y28Z9t.d.ts → orchestrator-CWFrT8AF.d.ts} +91 -60
  213. package/dist/orchestrator.d.ts +5 -5
  214. package/dist/orchestrator.js +85 -83
  215. package/dist/patterns-cli.d.ts +1 -1
  216. package/dist/policy-runtime.d.ts +1 -1
  217. package/dist/provenance.d.ts +1 -1
  218. package/dist/{qmd-Db9mOkzB.d.ts → qmd--fnPMK60.d.ts} +1 -1
  219. package/dist/qmd-preflight.d.ts +2 -2
  220. package/dist/qmd-recall-cache.d.ts +1 -1
  221. package/dist/qmd.d.ts +2 -2
  222. package/dist/recall-disclosure-escalation.d.ts +1 -1
  223. package/dist/recall-explain-renderer.d.ts +1 -1
  224. package/dist/recall-planner-llm.d.ts +1 -1
  225. package/dist/recall-state.d.ts +1 -1
  226. package/dist/recall-tag-filter.d.ts +1 -1
  227. package/dist/recall-timings.d.ts +1 -1
  228. package/dist/recall-xray-cli.d.ts +1 -1
  229. package/dist/recall-xray-renderer.d.ts +1 -1
  230. package/dist/recall-xray.d.ts +1 -1
  231. package/dist/resolve-auth-token.d.ts +1 -1
  232. package/dist/resume-bundles.js +4 -4
  233. package/dist/retrieval-agents.d.ts +2 -2
  234. package/dist/retrieval-tiers.d.ts +1 -1
  235. package/dist/routing/engine.d.ts +1 -1
  236. package/dist/routing/store.d.ts +1 -1
  237. package/dist/schemas.d.ts +22 -22
  238. package/dist/search/document-scanner.js +2 -2
  239. package/dist/search/embed-helper.d.ts +1 -1
  240. package/dist/search/factory.d.ts +1 -1
  241. package/dist/search/factory.js +9 -9
  242. package/dist/search/index.d.ts +1 -1
  243. package/dist/search/index.js +13 -13
  244. package/dist/search/lancedb-backend.d.ts +1 -1
  245. package/dist/search/lancedb-backend.js +3 -3
  246. package/dist/search/meilisearch-backend.d.ts +1 -1
  247. package/dist/search/meilisearch-backend.js +3 -3
  248. package/dist/search/noop-backend.d.ts +1 -1
  249. package/dist/search/orama-backend.d.ts +1 -1
  250. package/dist/search/orama-backend.js +3 -3
  251. package/dist/search/port.d.ts +1 -1
  252. package/dist/search/remote-backend.d.ts +1 -1
  253. package/dist/{semantic-consolidation-BDVIbLRw.d.ts → semantic-consolidation-O5lMZ4LG.d.ts} +1 -1
  254. package/dist/semantic-consolidation.d.ts +2 -2
  255. package/dist/semantic-consolidation.js +11 -11
  256. package/dist/semantic-rule-promotion.js +9 -9
  257. package/dist/semantic-rule-verifier.d.ts +1 -1
  258. package/dist/semantic-rule-verifier.js +10 -10
  259. package/dist/session-observer-bands.d.ts +1 -1
  260. package/dist/session-observer-state.d.ts +1 -1
  261. package/dist/shared-context/manager.d.ts +1 -1
  262. package/dist/signal.d.ts +1 -1
  263. package/dist/storage-C1maCNbc.d.ts +1591 -0
  264. package/dist/storage.d.ts +5 -1239
  265. package/dist/storage.js +8 -8
  266. package/dist/summarizer.d.ts +1 -1
  267. package/dist/summary-snapshot.d.ts +1 -1
  268. package/dist/temporal-supersession.d.ts +2 -2
  269. package/dist/temporal-validity.d.ts +1 -1
  270. package/dist/threading.d.ts +1 -1
  271. package/dist/tier-migration.d.ts +2 -2
  272. package/dist/tier-routing.d.ts +1 -1
  273. package/dist/{tier-stats-TG6GUZ6N.js → tier-stats-5XF4UBRQ.js} +4 -4
  274. package/dist/tokens.d.ts +17 -2
  275. package/dist/tokens.js +3 -1
  276. package/dist/topics.d.ts +1 -1
  277. package/dist/transcript.d.ts +1 -1
  278. package/dist/transfer/backup.js +2 -2
  279. package/dist/transfer/capsule-export.js +3 -3
  280. package/dist/transfer/capsule-import.js +3 -3
  281. package/dist/transfer/types.d.ts +12 -12
  282. package/dist/trust-score-stage.d.ts +1 -1
  283. package/dist/trust-score.d.ts +1 -1
  284. package/dist/{types-ljkd82rn.d.ts → types-CGgcNWCG.d.ts} +31 -1
  285. package/dist/types.d.ts +1 -1
  286. package/dist/utility-runtime.d.ts +1 -1
  287. package/dist/verified-recall.js +10 -10
  288. package/package.json +2 -2
  289. package/src/access-boundary.test.ts +62 -0
  290. package/src/access-boundary.ts +165 -126
  291. package/src/access-http.test.ts +781 -0
  292. package/src/access-http.ts +334 -108
  293. package/src/access-mcp.test.ts +264 -0
  294. package/src/access-mcp.ts +45 -70
  295. package/src/access-operations-batch.ts +35 -12
  296. package/src/access-surface-catalog.test.ts +22 -14
  297. package/src/access-surface-catalog.ts +6 -3
  298. package/src/access-token-capabilities.test.ts +844 -0
  299. package/src/access-token-capabilities.ts +391 -0
  300. package/src/chat/chat-mcp.test.ts +232 -0
  301. package/src/chat/chat-session.ts +34 -0
  302. package/src/cli-wearables-fuse.test.ts +197 -0
  303. package/src/cli.ts +25 -0
  304. package/src/index.ts +14 -0
  305. package/src/mcp-read-only-tools.ts +61 -0
  306. package/src/storage.ts +16 -0
  307. package/src/tokens.ts +32 -3
  308. package/src/wearables/cli.test.ts +102 -0
  309. package/src/wearables/cli.ts +65 -0
  310. package/src/wearables/config.test.ts +32 -0
  311. package/src/wearables/config.ts +52 -0
  312. package/src/wearables/day-store.test.ts +246 -0
  313. package/src/wearables/day-store.ts +272 -3
  314. package/src/wearables/fusion/cluster.ts +230 -0
  315. package/src/wearables/fusion/fuse.ts +218 -0
  316. package/src/wearables/fusion/fusion.test.ts +2575 -0
  317. package/src/wearables/fusion/index.ts +50 -0
  318. package/src/wearables/fusion/reconcile.ts +831 -0
  319. package/src/wearables/fusion/reconstruct.ts +251 -0
  320. package/src/wearables/fusion/store.ts +480 -0
  321. package/src/wearables/fusion/types.ts +228 -0
  322. package/src/wearables/index.ts +41 -0
  323. package/src/wearables/service.test.ts +1030 -2
  324. package/src/wearables/service.ts +258 -16
  325. package/src/wearables/speakers.test.ts +128 -0
  326. package/src/wearables/speakers.ts +58 -4
  327. package/src/wearables/storage-io.test.ts +146 -0
  328. package/src/wearables/types.ts +31 -0
  329. package/dist/chunk-2FOD2YY3.js.map +0 -1
  330. package/dist/chunk-7QWMTOIF.js.map +0 -1
  331. package/dist/chunk-DR6PEJU3.js.map +0 -1
  332. package/dist/chunk-E2SPGGUI.js.map +0 -1
  333. package/dist/chunk-FZGGZAAU.js.map +0 -1
  334. package/dist/chunk-ILFJ7AVS.js.map +0 -1
  335. package/dist/chunk-M7GGMGMZ.js.map +0 -1
  336. package/dist/chunk-M7XQSUBB.js.map +0 -1
  337. /package/dist/{capsule-crypto-CZJSLEFG.js.map → access-token-capabilities.js.map} +0 -0
  338. /package/dist/{auto-sync-HMHQHUAG.js.map → auto-sync-4A5YBWYO.js.map} +0 -0
  339. /package/dist/{chunk-6ZIETXZ2.js.map → chunk-23JFRB73.js.map} +0 -0
  340. /package/dist/{chunk-IC6QX5TC.js.map → chunk-3XIY7MDQ.js.map} +0 -0
  341. /package/dist/{chunk-LOR6ZM5R.js.map → chunk-4LV23CHK.js.map} +0 -0
  342. /package/dist/{chunk-AER6MT24.js.map → chunk-6SXVCD7W.js.map} +0 -0
  343. /package/dist/{chunk-OHDJ34CC.js.map → chunk-72WG5QKN.js.map} +0 -0
  344. /package/dist/{chunk-CZAZX7JP.js.map → chunk-7MW3CVLD.js.map} +0 -0
  345. /package/dist/{chunk-CXLNZXG5.js.map → chunk-7XGSIUP5.js.map} +0 -0
  346. /package/dist/{chunk-CZAA5N5S.js.map → chunk-AYZJID4S.js.map} +0 -0
  347. /package/dist/{chunk-6BISDEN6.js.map → chunk-BEM4D2QG.js.map} +0 -0
  348. /package/dist/{chunk-ZPOROUTX.js.map → chunk-CYWA2CXR.js.map} +0 -0
  349. /package/dist/{chunk-M5QKGHCR.js.map → chunk-CYWCKFCL.js.map} +0 -0
  350. /package/dist/{chunk-4BFRBP45.js.map → chunk-DEG5ULFJ.js.map} +0 -0
  351. /package/dist/{chunk-JLR3JSTL.js.map → chunk-DS7MM2ES.js.map} +0 -0
  352. /package/dist/{chunk-2BFLDH5F.js.map → chunk-EEIROWEG.js.map} +0 -0
  353. /package/dist/{chunk-X4A62ET7.js.map → chunk-H2DXDQCQ.js.map} +0 -0
  354. /package/dist/{chunk-27FLVMDC.js.map → chunk-HLN7RROI.js.map} +0 -0
  355. /package/dist/{chunk-2U2A5HF4.js.map → chunk-J3XHPFEU.js.map} +0 -0
  356. /package/dist/{chunk-AKUCU7CI.js.map → chunk-JI5AVXYO.js.map} +0 -0
  357. /package/dist/{chunk-KCJ5H6XQ.js.map → chunk-JSNVWNGX.js.map} +0 -0
  358. /package/dist/{chunk-FLVL4L3L.js.map → chunk-KTULX4YO.js.map} +0 -0
  359. /package/dist/{chunk-437S3G37.js.map → chunk-LNQUAJNC.js.map} +0 -0
  360. /package/dist/{chunk-EPGWWCZF.js.map → chunk-LR5DZ56F.js.map} +0 -0
  361. /package/dist/{chunk-YDSWRD33.js.map → chunk-N3JDIRBW.js.map} +0 -0
  362. /package/dist/{chunk-OUMTBFSQ.js.map → chunk-NKCPUHCI.js.map} +0 -0
  363. /package/dist/{chunk-BGTAL46Y.js.map → chunk-PNLFN2PZ.js.map} +0 -0
  364. /package/dist/{chunk-P6SYWE4G.js.map → chunk-PVUJ6WVV.js.map} +0 -0
  365. /package/dist/{chunk-YPEMNNNY.js.map → chunk-RGK27ELN.js.map} +0 -0
  366. /package/dist/{chunk-2QSZNTDO.js.map → chunk-RKNJBZ55.js.map} +0 -0
  367. /package/dist/{chunk-66FLU5BT.js.map → chunk-SIRPLF54.js.map} +0 -0
  368. /package/dist/{chunk-HRCACVHL.js.map → chunk-TLUDFPZL.js.map} +0 -0
  369. /package/dist/{chunk-2MR3MFQB.js.map → chunk-UPSAT4PY.js.map} +0 -0
  370. /package/dist/{chunk-4P4626RY.js.map → chunk-UTRJFDP2.js.map} +0 -0
  371. /package/dist/{chunk-CGS7UKWM.js.map → chunk-VCW74PNH.js.map} +0 -0
  372. /package/dist/{chunk-5GPPACXK.js.map → chunk-VSMRDBFT.js.map} +0 -0
  373. /package/dist/{chunk-NG7YBCJO.js.map → chunk-XCL57M6Q.js.map} +0 -0
  374. /package/dist/{chunk-CLX5VDNY.js.map → chunk-Y4RKAQZ7.js.map} +0 -0
  375. /package/dist/{chunk-DGYCWCQ7.js.map → chunk-Y7UNNAZD.js.map} +0 -0
  376. /package/dist/{chunk-EZ25VE3G.js.map → chunk-YNDLCWXS.js.map} +0 -0
  377. /package/dist/{chunk-XN3TUUX2.js.map → chunk-YQB32INI.js.map} +0 -0
  378. /package/dist/{first-start-migration-DY6YCRC2.js.map → first-start-migration-VBJQL6OI.js.map} +0 -0
  379. /package/dist/{tier-stats-TG6GUZ6N.js.map → tier-stats-5XF4UBRQ.js.map} +0 -0
@@ -3,26 +3,42 @@ import {
3
3
  } from "./chunk-V7IZKJI3.js";
4
4
  import {
5
5
  AdapterRegistry
6
- } from "./chunk-2QSZNTDO.js";
6
+ } from "./chunk-RKNJBZ55.js";
7
7
  import {
8
8
  EngramMcpServer,
9
9
  MCP_SUPPORTED_PROTOCOL_VERSIONS,
10
10
  cleanupExpiredChatSessions,
11
+ enforceChatSessionNamespace,
11
12
  loadChatSession,
12
13
  processChatMessage,
13
14
  sessionBelongsToPrincipal,
14
15
  subscribeChatTranscript
15
- } from "./chunk-DR6PEJU3.js";
16
+ } from "./chunk-PCLIWBGD.js";
16
17
  import {
17
18
  validateRequest
18
- } from "./chunk-2MR3MFQB.js";
19
+ } from "./chunk-UPSAT4PY.js";
20
+ import {
21
+ executeResolution,
22
+ isValidResolutionVerb
23
+ } from "./chunk-KQDNAXOM.js";
24
+ import {
25
+ isDefaultReviewNamespace,
26
+ listPairs,
27
+ readPair
28
+ } from "./chunk-35NN3ZFA.js";
19
29
  import {
20
30
  getOperation
21
- } from "./chunk-FZGGZAAU.js";
31
+ } from "./chunk-4GNEDXDI.js";
32
+ import {
33
+ assertOperationAllowed,
34
+ enforceNamespaceAllowList,
35
+ isCapabilityRestricted,
36
+ tokenCapabilityStore
37
+ } from "./chunk-D7FOKIY5.js";
22
38
  import {
23
39
  CorrectionContractError,
24
40
  EngramAccessInputError
25
- } from "./chunk-X4A62ET7.js";
41
+ } from "./chunk-H2DXDQCQ.js";
26
42
  import {
27
43
  isTrustZoneName
28
44
  } from "./chunk-JGSKJHF7.js";
@@ -635,7 +651,30 @@ var EngramAccessHttpServer = class {
635
651
  * is intentionally NOT used as a fallback for REST requests — omitting namespace
636
652
  * should default to the server's global namespace, not silently scope to an adapter. */
637
653
  resolveNamespace(_req, bodyNamespace) {
638
- return bodyNamespace || void 0;
654
+ const namespace = bodyNamespace || void 0;
655
+ enforceNamespaceAllowList(
656
+ tokenCapabilityStore.getStore(),
657
+ namespace,
658
+ this.service.configRef?.defaultNamespace
659
+ );
660
+ return namespace;
661
+ }
662
+ /**
663
+ * Resolve + enforce the `namespace` field carried in a POST request body,
664
+ * returning a shallow-copied envelope with the gated namespace stamped on.
665
+ * Used by the coding/correction POST routes that pass `body` straight to
666
+ * `op.run`: the body `namespace` is a user-controlled field that MUST flow
667
+ * through the same effective-namespace allow-list gate as the query-param
668
+ * routes, otherwise a scoped bearer can scope its call to another tenant
669
+ * by setting `body.namespace` (issue #1850 finding 2). Throws 403 for a
670
+ * scoped token whose allow-list does not cover the effective namespace.
671
+ */
672
+ gatedBodyNamespace(req, body) {
673
+ const namespace = this.resolveNamespace(
674
+ req,
675
+ typeof body.namespace === "string" ? body.namespace : void 0
676
+ );
677
+ return { ...body, namespace };
639
678
  }
640
679
  /**
641
680
  * Resolve the recall disclosure depth from the request (issue #677 PR
@@ -681,7 +720,7 @@ var EngramAccessHttpServer = class {
681
720
  }
682
721
  }
683
722
  if (this.externalRequestHandler) {
684
- const authorized = this.isAuthorized(req, pathname);
723
+ const authorized = this.isAuthorized(req, pathname) && !isCapabilityRestricted(this.resolveTokenCapabilities(req, pathname));
685
724
  if (await this.externalRequestHandler(req, res, { authorized })) {
686
725
  return;
687
726
  }
@@ -696,6 +735,12 @@ var EngramAccessHttpServer = class {
696
735
  res.end(body);
697
736
  return;
698
737
  }
738
+ const caps = this.resolveTokenCapabilities(req, pathname);
739
+ await tokenCapabilityStore.run(caps, async () => {
740
+ await this.dispatchAuthorizedRequest(req, res, parsed, pathname, correlationId, abortSignal);
741
+ });
742
+ }
743
+ async dispatchAuthorizedRequest(req, res, parsed, pathname, correlationId, abortSignal) {
699
744
  if (pathname === "/mcp" && (req.method === "GET" || req.method === "DELETE")) {
700
745
  const body = JSON.stringify({ error: "method_not_allowed", code: "method_not_allowed" });
701
746
  res.writeHead(405, {
@@ -715,6 +760,7 @@ var EngramAccessHttpServer = class {
715
760
  return;
716
761
  }
717
762
  if (req.method === "GET" && pathname === "/engram/v1/adapters") {
763
+ this.enforceTokenOp("adapters_status");
718
764
  const identity = this.resolveAdapterIdentity(req);
719
765
  this.respondJson(res, 200, {
720
766
  adaptersEnabled: this.adapterRegistry !== null,
@@ -724,6 +770,7 @@ var EngramAccessHttpServer = class {
724
770
  return;
725
771
  }
726
772
  if (req.method === "GET" && (pathname === "/engram/v1/admin/dashboard" || pathname === "/remnic/v1/admin/dashboard")) {
773
+ this.requireOperatorToken();
727
774
  if (!this.adminControls) {
728
775
  this.respondJson(res, 404, { error: "admin_controls_unavailable", code: "admin_controls_unavailable" });
729
776
  return;
@@ -732,6 +779,7 @@ var EngramAccessHttpServer = class {
732
779
  return;
733
780
  }
734
781
  if (req.method === "PATCH" && (pathname === "/engram/v1/admin/config" || pathname === "/remnic/v1/admin/config")) {
782
+ this.requireOperatorToken();
735
783
  if (!this.adminControls?.update) {
736
784
  this.respondJson(res, 404, { error: "admin_controls_unavailable", code: "admin_controls_unavailable" });
737
785
  return;
@@ -748,7 +796,7 @@ var EngramAccessHttpServer = class {
748
796
  return;
749
797
  }
750
798
  if (req.method === "POST" && pathname === "/engram/v1/recall") {
751
- void getOperation("recall");
799
+ this.enforceTokenOp("recall");
752
800
  const body = await this.readValidatedBody(req, "recall");
753
801
  const codingContext = "codingContext" in body ? body.codingContext : void 0;
754
802
  const disclosure = this.resolveRecallDisclosure(body.disclosure, parsed);
@@ -817,7 +865,7 @@ var EngramAccessHttpServer = class {
817
865
  return;
818
866
  }
819
867
  if (req.method === "POST" && pathname === "/engram/v1/coding-context") {
820
- void getOperation("set_coding_context");
868
+ this.enforceTokenOp("set_coding_context");
821
869
  const body = await this.readValidatedBody(req, "setCodingContext");
822
870
  const codingContext = body.codingContext !== void 0 ? body.codingContext : typeof body.projectTag === "string" ? codingContextFromProjectTag(body.projectTag) : (() => {
823
871
  throw new EngramAccessInputError("codingContext or projectTag is required");
@@ -830,7 +878,7 @@ var EngramAccessHttpServer = class {
830
878
  return;
831
879
  }
832
880
  if (req.method === "POST" && (pathname === "/engram/v1/capsules/export" || pathname === "/remnic/v1/capsules/export")) {
833
- void getOperation("capsule_export");
881
+ this.enforceTokenOp("capsule_export");
834
882
  const body = await this.readValidatedBody(req, "capsuleExport");
835
883
  this.ensureWriteRateLimitAvailable();
836
884
  const result = await this.service.capsuleExport({
@@ -848,7 +896,7 @@ var EngramAccessHttpServer = class {
848
896
  return;
849
897
  }
850
898
  if (req.method === "POST" && (pathname === "/engram/v1/capsules/import" || pathname === "/remnic/v1/capsules/import")) {
851
- void getOperation("capsule_import");
899
+ this.enforceTokenOp("capsule_import");
852
900
  const body = await this.readValidatedBody(req, "capsuleImport");
853
901
  this.ensureWriteRateLimitAvailable();
854
902
  const result = await this.service.capsuleImport({
@@ -863,7 +911,7 @@ var EngramAccessHttpServer = class {
863
911
  return;
864
912
  }
865
913
  if (req.method === "GET" && (pathname === "/engram/v1/offline-sync/snapshot" || pathname === "/remnic/v1/offline-sync/snapshot")) {
866
- void getOperation("offline_sync_snapshot");
914
+ this.enforceTokenOp("offline_sync_snapshot");
867
915
  const includeTranscriptsRaw = parsed.searchParams.get("include_transcripts");
868
916
  const includeContentRaw = parsed.searchParams.get("content");
869
917
  if (includeTranscriptsRaw !== null && includeTranscriptsRaw !== "true" && includeTranscriptsRaw !== "false") {
@@ -890,7 +938,7 @@ var EngramAccessHttpServer = class {
890
938
  return;
891
939
  }
892
940
  if (req.method === "GET" && (pathname === "/engram/v1/offline-sync/snapshot-stream" || pathname === "/remnic/v1/offline-sync/snapshot-stream")) {
893
- void getOperation("offline_sync_snapshot_stream");
941
+ this.enforceTokenOp("offline_sync_snapshot_stream");
894
942
  const includeTranscriptsRaw = parsed.searchParams.get("include_transcripts");
895
943
  const includeContentRaw = parsed.searchParams.get("content");
896
944
  if (includeTranscriptsRaw !== null && includeTranscriptsRaw !== "true" && includeTranscriptsRaw !== "false") {
@@ -916,7 +964,7 @@ var EngramAccessHttpServer = class {
916
964
  return;
917
965
  }
918
966
  if (req.method === "POST" && (pathname === "/engram/v1/offline-sync/snapshot" || pathname === "/remnic/v1/offline-sync/snapshot")) {
919
- void getOperation("offline_sync_snapshot");
967
+ this.enforceTokenOp("offline_sync_snapshot");
920
968
  const body = await this.readValidatedBody(
921
969
  req,
922
970
  "offlineSyncSnapshot",
@@ -935,7 +983,7 @@ var EngramAccessHttpServer = class {
935
983
  return;
936
984
  }
937
985
  if (req.method === "POST" && (pathname === "/engram/v1/offline-sync/files" || pathname === "/remnic/v1/offline-sync/files")) {
938
- void getOperation("offline_sync_files");
986
+ this.enforceTokenOp("offline_sync_files");
939
987
  const body = await this.readValidatedBody(req, "offlineSyncFiles");
940
988
  const result = await this.service.offlineSyncFiles({
941
989
  namespace: this.resolveNamespace(req, body.namespace),
@@ -947,7 +995,7 @@ var EngramAccessHttpServer = class {
947
995
  return;
948
996
  }
949
997
  if (req.method === "POST" && (pathname === "/engram/v1/offline-sync/file-content" || pathname === "/remnic/v1/offline-sync/file-content")) {
950
- void getOperation("offline_sync_file_content");
998
+ this.enforceTokenOp("offline_sync_file_content");
951
999
  const body = await this.readValidatedBody(req, "offlineSyncFileContent");
952
1000
  const result = await this.service.offlineSyncFileContent({
953
1001
  namespace: this.resolveNamespace(req, body.namespace),
@@ -969,7 +1017,7 @@ var EngramAccessHttpServer = class {
969
1017
  return;
970
1018
  }
971
1019
  if (req.method === "POST" && (pathname === "/engram/v1/offline-sync/apply-file-content" || pathname === "/remnic/v1/offline-sync/apply-file-content")) {
972
- void getOperation("offline_sync_apply_file_content");
1020
+ this.enforceTokenOp("offline_sync_apply_file_content");
973
1021
  const namespaceParam = parsed.searchParams.get("namespace");
974
1022
  const bytes = this.readRequiredIntegerHeader(req, "x-remnic-file-bytes");
975
1023
  const offset = this.readOptionalIntegerHeader(req, "x-remnic-chunk-offset") ?? 0;
@@ -998,7 +1046,7 @@ var EngramAccessHttpServer = class {
998
1046
  return;
999
1047
  }
1000
1048
  if (req.method === "POST" && (pathname === "/engram/v1/offline-sync/apply" || pathname === "/remnic/v1/offline-sync/apply")) {
1001
- void getOperation("offline_sync_apply");
1049
+ this.enforceTokenOp("offline_sync_apply");
1002
1050
  const body = await this.readValidatedBody(req, "offlineSyncApply", OFFLINE_SYNC_APPLY_MAX_BODY_BYTES);
1003
1051
  const result = await this.service.offlineSyncApply({
1004
1052
  namespace: this.resolveNamespace(req, body.namespace),
@@ -1010,7 +1058,7 @@ var EngramAccessHttpServer = class {
1010
1058
  return;
1011
1059
  }
1012
1060
  if (req.method === "POST" && pathname === "/engram/v1/recall/explain") {
1013
- void getOperation("recall_explain");
1061
+ this.enforceTokenOp("recall_explain");
1014
1062
  const body = await this.readValidatedBody(req, "recallExplain");
1015
1063
  const response = await this.service.recallExplain({
1016
1064
  sessionKey: body.sessionKey,
@@ -1021,13 +1069,13 @@ var EngramAccessHttpServer = class {
1021
1069
  return;
1022
1070
  }
1023
1071
  if (req.method === "POST" && (pathname === "/engram/v1/action-confidence" || pathname === "/remnic/v1/action-confidence")) {
1024
- void getOperation("action_confidence");
1072
+ this.enforceTokenOp("action_confidence");
1025
1073
  const body = await this.readValidatedBody(req, "actionConfidence");
1026
1074
  this.respondJson(res, 200, await this.service.actionConfidence(body));
1027
1075
  return;
1028
1076
  }
1029
1077
  if (req.method === "GET" && pathname === "/engram/v1/recall/tier-explain") {
1030
- void getOperation("recall_tier_explain");
1078
+ this.enforceTokenOp("recall_tier_explain");
1031
1079
  const sessionParam = parsed.searchParams.get("session");
1032
1080
  const sessionKey = sessionParam && sessionParam.length > 0 ? sessionParam : void 0;
1033
1081
  const namespaceParam = parsed.searchParams.get("namespace");
@@ -1044,7 +1092,7 @@ var EngramAccessHttpServer = class {
1044
1092
  return;
1045
1093
  }
1046
1094
  if (req.method === "GET" && pathname === "/engram/v1/recall/xray") {
1047
- void getOperation("recall_xray");
1095
+ this.enforceTokenOp("recall_xray");
1048
1096
  const queryParam = parsed.searchParams.get("q");
1049
1097
  if (!queryParam || queryParam.trim().length === 0) {
1050
1098
  this.respondJson(res, 400, {
@@ -1113,12 +1161,12 @@ var EngramAccessHttpServer = class {
1113
1161
  return;
1114
1162
  }
1115
1163
  if (req.method === "GET" && (pathname === "/engram/v1/wearables/status" || pathname === "/remnic/v1/wearables/status")) {
1116
- void getOperation("wearables_status");
1164
+ this.enforceTokenOp("wearables_status");
1117
1165
  this.respondJson(res, 200, await this.service.wearablesStatus());
1118
1166
  return;
1119
1167
  }
1120
1168
  if (req.method === "POST" && (pathname === "/engram/v1/wearables/sync" || pathname === "/remnic/v1/wearables/sync")) {
1121
- void getOperation("wearables_sync");
1169
+ this.enforceTokenOp("wearables_sync");
1122
1170
  const body = await this.readJsonBody(req);
1123
1171
  const source = optionalQueryString(body.source, "source");
1124
1172
  const date = optionalQueryString(body.date, "date");
@@ -1151,7 +1199,7 @@ var EngramAccessHttpServer = class {
1151
1199
  return;
1152
1200
  }
1153
1201
  if (req.method === "GET" && (pathname === "/engram/v1/wearables/transcript" || pathname === "/remnic/v1/wearables/transcript")) {
1154
- void getOperation("transcript_day");
1202
+ this.enforceTokenOp("transcript_day");
1155
1203
  const date = parsed.searchParams.get("date");
1156
1204
  if (!date || date.trim().length === 0) {
1157
1205
  throw new EngramAccessInputError(
@@ -1172,7 +1220,7 @@ var EngramAccessHttpServer = class {
1172
1220
  return;
1173
1221
  }
1174
1222
  if (req.method === "GET" && (pathname === "/engram/v1/wearables/transcripts/search" || pathname === "/remnic/v1/wearables/transcripts/search")) {
1175
- void getOperation("transcript_search");
1223
+ this.enforceTokenOp("transcript_search");
1176
1224
  const queryParam = parsed.searchParams.get("q");
1177
1225
  if (!queryParam || queryParam.trim().length === 0) {
1178
1226
  throw new EngramAccessInputError(
@@ -1195,7 +1243,7 @@ var EngramAccessHttpServer = class {
1195
1243
  return;
1196
1244
  }
1197
1245
  if (req.method === "GET" && (pathname === "/engram/v1/wearables/memories" || pathname === "/remnic/v1/wearables/memories")) {
1198
- void getOperation("transcript_memories");
1246
+ this.enforceTokenOp("transcript_memories");
1199
1247
  try {
1200
1248
  const memories = await this.service.wearablesTranscriptMemories({
1201
1249
  source: nonEmptyQueryParam(parsed.searchParams.get("source")),
@@ -1210,7 +1258,7 @@ var EngramAccessHttpServer = class {
1210
1258
  return;
1211
1259
  }
1212
1260
  if (req.method === "POST" && pathname === "/engram/v1/observe") {
1213
- void getOperation("observe");
1261
+ this.enforceTokenOp("observe");
1214
1262
  const body = await this.readValidatedBody(req, "observe");
1215
1263
  const response = await this.service.observe(
1216
1264
  {
@@ -1247,7 +1295,7 @@ var EngramAccessHttpServer = class {
1247
1295
  return;
1248
1296
  }
1249
1297
  if (req.method === "POST" && pathname === "/engram/v1/lcm/search") {
1250
- void getOperation("lcm_search");
1298
+ this.enforceTokenOp("lcm_search");
1251
1299
  const body = await this.readValidatedBody(req, "lcmSearch");
1252
1300
  const response = await this.service.lcmSearch({
1253
1301
  query: body.query,
@@ -1261,7 +1309,7 @@ var EngramAccessHttpServer = class {
1261
1309
  return;
1262
1310
  }
1263
1311
  if (req.method === "POST" && (pathname === "/engram/v1/lcm/compaction/flush" || pathname === "/remnic/v1/lcm/compaction/flush")) {
1264
- void getOperation("lcm_compaction_flush");
1312
+ this.enforceTokenOp("lcm_compaction_flush");
1265
1313
  const body = await this.readValidatedBody(req, "lcmCompactionFlush");
1266
1314
  this.ensureWriteRateLimitAvailable();
1267
1315
  const response = await this.service.lcmCompactionFlush({
@@ -1274,7 +1322,7 @@ var EngramAccessHttpServer = class {
1274
1322
  return;
1275
1323
  }
1276
1324
  if (req.method === "POST" && (pathname === "/engram/v1/lcm/compaction/record" || pathname === "/remnic/v1/lcm/compaction/record")) {
1277
- void getOperation("lcm_compaction_record");
1325
+ this.enforceTokenOp("lcm_compaction_record");
1278
1326
  const body = await this.readValidatedBody(req, "lcmCompactionRecord");
1279
1327
  this.ensureWriteRateLimitAvailable();
1280
1328
  const response = await this.service.lcmCompactionRecord({
@@ -1289,7 +1337,7 @@ var EngramAccessHttpServer = class {
1289
1337
  return;
1290
1338
  }
1291
1339
  if (req.method === "GET" && pathname === "/engram/v1/lcm/status") {
1292
- void getOperation("lcm_status");
1340
+ this.enforceTokenOp("lcm_status");
1293
1341
  this.respondJson(res, 200, await this.service.lcmStatus());
1294
1342
  return;
1295
1343
  }
@@ -1325,7 +1373,7 @@ var EngramAccessHttpServer = class {
1325
1373
  if (!op) {
1326
1374
  throw new EngramAccessInputError("access-boundary: operation not registered: coding_decision");
1327
1375
  }
1328
- const output = await op.run(body, {
1376
+ const output = await op.run(this.gatedBodyNamespace(req, body), {
1329
1377
  service: this.service,
1330
1378
  authenticatedPrincipal: this.resolveRequestPrincipal(req)
1331
1379
  });
@@ -1345,7 +1393,7 @@ var EngramAccessHttpServer = class {
1345
1393
  if (!op) {
1346
1394
  throw new EngramAccessInputError("access-boundary: operation not registered: coding_architecture");
1347
1395
  }
1348
- const output = await op.run(body, {
1396
+ const output = await op.run(this.gatedBodyNamespace(req, body), {
1349
1397
  service: this.service,
1350
1398
  authenticatedPrincipal: this.resolveRequestPrincipal(req)
1351
1399
  });
@@ -1361,7 +1409,7 @@ var EngramAccessHttpServer = class {
1361
1409
  if (!op) {
1362
1410
  throw new EngramAccessInputError("access-boundary: operation not registered: coding_delta");
1363
1411
  }
1364
- const output = await op.run(body, {
1412
+ const output = await op.run(this.gatedBodyNamespace(req, body), {
1365
1413
  service: this.service,
1366
1414
  authenticatedPrincipal: this.resolveRequestPrincipal(req)
1367
1415
  });
@@ -1375,7 +1423,7 @@ var EngramAccessHttpServer = class {
1375
1423
  if (!op) {
1376
1424
  throw new EngramAccessInputError("access-boundary: operation not registered: memory_correct_plan");
1377
1425
  }
1378
- const output = await op.run(body, {
1426
+ const output = await op.run(this.gatedBodyNamespace(req, body), {
1379
1427
  service: this.service,
1380
1428
  authenticatedPrincipal: this.resolveRequestPrincipal(req)
1381
1429
  });
@@ -1390,7 +1438,7 @@ var EngramAccessHttpServer = class {
1390
1438
  if (!op) {
1391
1439
  throw new EngramAccessInputError("access-boundary: operation not registered: memory_correct_apply");
1392
1440
  }
1393
- const output = await op.run(body, {
1441
+ const output = await op.run(this.gatedBodyNamespace(req, body), {
1394
1442
  service: this.service,
1395
1443
  authenticatedPrincipal: this.resolveRequestPrincipal(req)
1396
1444
  });
@@ -1402,12 +1450,12 @@ var EngramAccessHttpServer = class {
1402
1450
  const op = getOperation("correction_pending");
1403
1451
  if (op) {
1404
1452
  const output = await op.run(
1405
- { namespace: parsed.searchParams.get("namespace") ?? void 0, sessionKey: parsed.searchParams.get("sessionKey") ?? void 0 },
1453
+ { namespace: this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0), sessionKey: parsed.searchParams.get("sessionKey") ?? void 0 },
1406
1454
  { service: this.service, authenticatedPrincipal: this.resolveRequestPrincipal(req) }
1407
1455
  );
1408
1456
  this.respondJson(res, 200, output.result);
1409
1457
  } else {
1410
- const namespace = parsed.searchParams.get("namespace") ?? void 0;
1458
+ const namespace = this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0);
1411
1459
  const sessionKey = parsed.searchParams.get("sessionKey") ?? void 0;
1412
1460
  const plans = await this.service.correctionListPending({
1413
1461
  ...namespace ? { namespace } : {},
@@ -1419,7 +1467,7 @@ var EngramAccessHttpServer = class {
1419
1467
  return;
1420
1468
  }
1421
1469
  if (req.method === "POST" && pathname === "/engram/v1/suggestions") {
1422
- void getOperation("suggestion_submit");
1470
+ this.enforceTokenOp("suggestion_submit");
1423
1471
  const body = await this.readValidatedBody(req, "suggestionSubmit");
1424
1472
  const request = {
1425
1473
  schemaVersion: body.schemaVersion,
@@ -1448,7 +1496,7 @@ var EngramAccessHttpServer = class {
1448
1496
  return;
1449
1497
  }
1450
1498
  if (req.method === "GET" && pathname === "/engram/v1/memories") {
1451
- void getOperation("memory_list");
1499
+ this.enforceTokenOp("memory_list");
1452
1500
  const limit = parseStrictIntegerQuery(parsed.searchParams.get("limit"), "limit", 50, 1);
1453
1501
  const offset = parseStrictIntegerQuery(parsed.searchParams.get("offset"), "offset", 0, 0);
1454
1502
  const sort = parseMemorySort(parsed.searchParams.get("sort"));
@@ -1456,7 +1504,7 @@ var EngramAccessHttpServer = class {
1456
1504
  query: parsed.searchParams.get("q") ?? void 0,
1457
1505
  status: parsed.searchParams.get("status") ?? void 0,
1458
1506
  category: parsed.searchParams.get("category") ?? void 0,
1459
- namespace: parsed.searchParams.get("namespace") ?? void 0,
1507
+ namespace: this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0),
1460
1508
  authenticatedPrincipal: this.resolveRequestPrincipal(req),
1461
1509
  sort,
1462
1510
  limit,
@@ -1482,7 +1530,7 @@ var EngramAccessHttpServer = class {
1482
1530
  const memoryMatch = pathname.match(/^\/engram\/v1\/memories\/([^/]+)$/);
1483
1531
  if (req.method === "GET" && memoryMatch) {
1484
1532
  const memoryId = decodeURIComponent(memoryMatch[1] ?? "");
1485
- const namespace = parsed.searchParams.get("namespace") ?? void 0;
1533
+ const namespace = this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0);
1486
1534
  const sessionKey = this.resolveRequestIdentity(req).sessionKey ?? parsed.searchParams.get("session") ?? parsed.searchParams.get("sessionKey") ?? void 0;
1487
1535
  const op = getOperation("memory_get");
1488
1536
  if (!op) {
@@ -1497,21 +1545,21 @@ var EngramAccessHttpServer = class {
1497
1545
  return;
1498
1546
  }
1499
1547
  const timelineMatch = pathname.match(/^\/engram\/v1\/memories\/([^/]+)\/timeline$/);
1500
- void getOperation("memory_timeline");
1501
1548
  if (req.method === "GET" && timelineMatch) {
1549
+ this.enforceTokenOp("memory_timeline");
1502
1550
  const memoryId = decodeURIComponent(timelineMatch[1] ?? "");
1503
- const namespace = parsed.searchParams.get("namespace") ?? void 0;
1551
+ const namespace = this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0);
1504
1552
  const limit = parseStrictIntegerQuery(parsed.searchParams.get("limit"), "limit", 200, 1);
1505
1553
  const response = await this.service.memoryTimeline(memoryId, namespace, limit, this.resolveRequestPrincipal(req));
1506
1554
  this.respondJson(res, response.found ? 200 : 404, response);
1507
1555
  return;
1508
1556
  }
1509
1557
  if (req.method === "GET" && pathname === "/engram/v1/entities") {
1510
- void getOperation("entity_list");
1558
+ this.enforceTokenOp("entity_list");
1511
1559
  const limit = parseStrictIntegerQuery(parsed.searchParams.get("limit"), "limit", 50, 1);
1512
1560
  const offset = parseStrictIntegerQuery(parsed.searchParams.get("offset"), "offset", 0, 0);
1513
1561
  const response = await this.service.entityList({
1514
- namespace: parsed.searchParams.get("namespace") ?? void 0,
1562
+ namespace: this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0),
1515
1563
  query: parsed.searchParams.get("q") ?? void 0,
1516
1564
  limit,
1517
1565
  offset
@@ -1520,45 +1568,47 @@ var EngramAccessHttpServer = class {
1520
1568
  return;
1521
1569
  }
1522
1570
  const entityMatch = pathname.match(/^\/engram\/v1\/entities\/([^/]+)$/);
1523
- void getOperation("entity_get");
1524
1571
  if (req.method === "GET" && entityMatch) {
1572
+ this.enforceTokenOp("entity_get");
1525
1573
  const entityName = decodeURIComponent(entityMatch[1] ?? "");
1526
- const namespace = parsed.searchParams.get("namespace") ?? void 0;
1574
+ const namespace = this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0);
1527
1575
  const response = await this.service.entityGet(entityName, namespace);
1528
1576
  this.respondJson(res, response.found ? 200 : 404, response);
1529
1577
  return;
1530
1578
  }
1531
1579
  if (req.method === "GET" && pathname === "/engram/v1/review-queue") {
1532
- void getOperation("review_queue_list");
1580
+ this.enforceTokenOp("review_queue_list");
1533
1581
  const response = await this.service.reviewQueue(
1534
1582
  parsed.searchParams.get("runId") ?? void 0,
1535
- parsed.searchParams.get("namespace") ?? void 0,
1583
+ this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0),
1536
1584
  this.resolveRequestPrincipal(req)
1537
1585
  );
1538
1586
  this.respondJson(res, 200, response);
1539
1587
  return;
1540
1588
  }
1541
1589
  if (req.method === "GET" && pathname === "/engram/v1/maintenance") {
1542
- void getOperation("maintenance_status");
1543
- this.respondJson(res, 200, await this.service.maintenance(parsed.searchParams.get("namespace") ?? void 0, this.resolveRequestPrincipal(req)));
1590
+ this.enforceTokenOp("maintenance_status");
1591
+ const namespace = this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0);
1592
+ this.respondJson(res, 200, await this.service.maintenance(namespace, this.resolveRequestPrincipal(req)));
1544
1593
  return;
1545
1594
  }
1546
1595
  if (req.method === "GET" && pathname === "/engram/v1/quality") {
1547
- void getOperation("quality_status");
1548
- this.respondJson(res, 200, await this.service.quality(parsed.searchParams.get("namespace") ?? void 0, this.resolveRequestPrincipal(req)));
1596
+ this.enforceTokenOp("quality_status");
1597
+ const namespace = this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0);
1598
+ this.respondJson(res, 200, await this.service.quality(namespace, this.resolveRequestPrincipal(req)));
1549
1599
  return;
1550
1600
  }
1551
1601
  if (req.method === "GET" && pathname === "/engram/v1/trust-zones/status") {
1552
- void getOperation("trust_zones_status");
1602
+ this.enforceTokenOp("trust_zones_status");
1553
1603
  this.respondJson(
1554
1604
  res,
1555
1605
  200,
1556
- await this.service.trustZoneStatus(parsed.searchParams.get("namespace") ?? void 0, this.resolveRequestPrincipal(req))
1606
+ await this.service.trustZoneStatus(this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0), this.resolveRequestPrincipal(req))
1557
1607
  );
1558
1608
  return;
1559
1609
  }
1560
1610
  if (req.method === "GET" && pathname === "/engram/v1/procedural/stats") {
1561
- void getOperation("procedural_stats");
1611
+ this.enforceTokenOp("procedural_stats");
1562
1612
  const namespaceParam = parsed.searchParams.get("namespace");
1563
1613
  this.respondJson(
1564
1614
  res,
@@ -1576,7 +1626,7 @@ var EngramAccessHttpServer = class {
1576
1626
  return;
1577
1627
  }
1578
1628
  if (req.method === "GET" && pathname === "/engram/v1/trust-zones/records") {
1579
- void getOperation("trust_zones_records");
1629
+ this.enforceTokenOp("trust_zones_records");
1580
1630
  const limit = parseStrictIntegerQuery(parsed.searchParams.get("limit"), "limit", 25, 1);
1581
1631
  const offset = parseStrictIntegerQuery(parsed.searchParams.get("offset"), "offset", 0, 0);
1582
1632
  const response = await this.service.trustZoneBrowse({
@@ -1584,7 +1634,7 @@ var EngramAccessHttpServer = class {
1584
1634
  zone: parseTrustZoneFilter(parsed.searchParams.get("zone")),
1585
1635
  kind: parseTrustZoneKindFilter(parsed.searchParams.get("kind")),
1586
1636
  sourceClass: parseTrustZoneSourceClassFilter(parsed.searchParams.get("sourceClass")),
1587
- namespace: parsed.searchParams.get("namespace") ?? void 0,
1637
+ namespace: this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0),
1588
1638
  limit,
1589
1639
  offset
1590
1640
  }, this.resolveRequestPrincipal(req));
@@ -1592,7 +1642,7 @@ var EngramAccessHttpServer = class {
1592
1642
  return;
1593
1643
  }
1594
1644
  if (req.method === "POST" && pathname === "/engram/v1/review-disposition") {
1595
- void getOperation("review_disposition");
1645
+ this.enforceTokenOp("review_disposition");
1596
1646
  const body = await this.readValidatedBody(req, "reviewDisposition");
1597
1647
  this.ensureWriteRateLimitAvailable();
1598
1648
  const response = await this.service.reviewDisposition({
@@ -1609,7 +1659,7 @@ var EngramAccessHttpServer = class {
1609
1659
  return;
1610
1660
  }
1611
1661
  if (req.method === "POST" && pathname === "/engram/v1/trust-zones/promote") {
1612
- void getOperation("trust_zones_promote");
1662
+ this.enforceTokenOp("trust_zones_promote");
1613
1663
  const body = await this.readValidatedBody(req, "trustZonePromote");
1614
1664
  const dryRun = body.dryRun === true;
1615
1665
  if (!dryRun) {
@@ -1632,7 +1682,7 @@ var EngramAccessHttpServer = class {
1632
1682
  return;
1633
1683
  }
1634
1684
  if (req.method === "POST" && pathname === "/engram/v1/trust-zones/demo-seed") {
1635
- void getOperation("trust_zones_demo_seed");
1685
+ this.enforceTokenOp("trust_zones_demo_seed");
1636
1686
  const body = await this.readValidatedBody(req, "trustZoneDemoSeed");
1637
1687
  const dryRun = body.dryRun === true;
1638
1688
  if (!dryRun) {
@@ -1652,7 +1702,7 @@ var EngramAccessHttpServer = class {
1652
1702
  return;
1653
1703
  }
1654
1704
  if (req.method === "POST" && pathname === "/v1/citations/observed") {
1655
- void getOperation("citations_observed");
1705
+ this.enforceTokenOp("citations_observed");
1656
1706
  const body = await this.readJsonBody(req);
1657
1707
  if (!body || typeof body !== "object" || Array.isArray(body)) {
1658
1708
  throw new HttpError(400, "request body must be a JSON object", "invalid_body");
@@ -1712,19 +1762,15 @@ var EngramAccessHttpServer = class {
1712
1762
  return;
1713
1763
  }
1714
1764
  if (req.method === "GET" && pathname === "/engram/v1/review/contradictions") {
1715
- void getOperation("review_list");
1765
+ this.enforceTokenOp("review_list");
1716
1766
  const VALID_FILTERS = /* @__PURE__ */ new Set(["all", "unresolved", "contradicts", "independent", "duplicates", "needs-user"]);
1717
1767
  const rawFilter = parsed.searchParams.get("filter") ?? "unresolved";
1718
1768
  if (!VALID_FILTERS.has(rawFilter)) {
1719
1769
  this.respondJson(res, 400, { error: `Invalid filter '${rawFilter}'. Valid: ${[...VALID_FILTERS].join(", ")}` });
1720
1770
  return;
1721
1771
  }
1722
- const namespace = parsed.searchParams.get("namespace") ?? void 0;
1772
+ const namespace = this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0);
1723
1773
  const limit = parseStrictIntegerQuery(parsed.searchParams.get("limit"), "limit", 50, 1);
1724
- const {
1725
- isDefaultReviewNamespace,
1726
- listPairs
1727
- } = await import("./contradiction-review-QKJH5DKD.js");
1728
1774
  const principal = this.resolveRequestPrincipal(req);
1729
1775
  const resolved = await this.service.getReadableStorageForNamespace(namespace, principal);
1730
1776
  const reviewNamespace = this.service.configRef.namespacesEnabled ? resolved.namespace : void 0;
@@ -1741,14 +1787,18 @@ var EngramAccessHttpServer = class {
1741
1787
  return;
1742
1788
  }
1743
1789
  if (req.method === "GET" && pathname.startsWith("/engram/v1/review/contradictions/")) {
1744
- void getOperation("contradiction_detail");
1790
+ this.enforceTokenOp("contradiction_detail");
1745
1791
  const pairId = pathname.split("/").pop() ?? "";
1746
- const { readPair } = await import("./contradiction-review-QKJH5DKD.js");
1747
1792
  const pair = readPair(this.service.memoryDir, pairId);
1748
1793
  if (!pair) {
1749
1794
  this.respondJson(res, 404, { error: "pair_not_found" });
1750
1795
  return;
1751
1796
  }
1797
+ enforceNamespaceAllowList(
1798
+ tokenCapabilityStore.getStore(),
1799
+ pair.namespace,
1800
+ this.service.configRef?.defaultNamespace
1801
+ );
1752
1802
  try {
1753
1803
  await this.service.getReadableStorageForNamespace(pair.namespace, this.resolveRequestPrincipal(req));
1754
1804
  } catch {
@@ -1759,7 +1809,7 @@ var EngramAccessHttpServer = class {
1759
1809
  return;
1760
1810
  }
1761
1811
  if (req.method === "POST" && pathname === "/engram/v1/review/resolve") {
1762
- void getOperation("review_resolve");
1812
+ this.enforceTokenOp("review_resolve");
1763
1813
  const body = await this.readJsonBody(req);
1764
1814
  const pairId = typeof body.pairId === "string" ? body.pairId : "";
1765
1815
  const verb = typeof body.verb === "string" ? body.verb : "";
@@ -1767,11 +1817,18 @@ var EngramAccessHttpServer = class {
1767
1817
  this.respondJson(res, 400, { error: "pairId and verb are required" });
1768
1818
  return;
1769
1819
  }
1770
- const { isValidResolutionVerb, executeResolution } = await import("./resolution-VH4NGENZ.js");
1771
1820
  if (!isValidResolutionVerb(verb)) {
1772
1821
  this.respondJson(res, 400, { error: `Invalid verb: ${verb}. Must be one of: keep-a, keep-b, merge, both-valid, needs-more-context` });
1773
1822
  return;
1774
1823
  }
1824
+ const targetPair = readPair(this.service.memoryDir, pairId);
1825
+ if (targetPair) {
1826
+ enforceNamespaceAllowList(
1827
+ tokenCapabilityStore.getStore(),
1828
+ targetPair.namespace,
1829
+ this.service.configRef?.defaultNamespace
1830
+ );
1831
+ }
1775
1832
  const principal = this.resolveRequestPrincipal(req);
1776
1833
  const result = await executeResolution(this.service.memoryDir, this.service.storageRef, pairId, verb, {
1777
1834
  mergedMemoryId: typeof body.mergedMemoryId === "string" ? body.mergedMemoryId : void 0,
@@ -1791,7 +1848,7 @@ var EngramAccessHttpServer = class {
1791
1848
  return;
1792
1849
  }
1793
1850
  if (req.method === "GET" && pathname === "/engram/v1/graph/snapshot") {
1794
- void getOperation("graph_snapshot");
1851
+ this.enforceTokenOp("graph_snapshot");
1795
1852
  const limitRaw = parsed.searchParams.get("limit");
1796
1853
  let limit;
1797
1854
  if (limitRaw !== null && limitRaw.length > 0) {
@@ -1865,7 +1922,7 @@ var EngramAccessHttpServer = class {
1865
1922
  return;
1866
1923
  }
1867
1924
  if (req.method === "POST" && pathname === "/engram/v1/contradiction-scan") {
1868
- void getOperation("contradiction_scan_run");
1925
+ this.enforceTokenOp("contradiction_scan_run");
1869
1926
  const body = await this.readJsonBody(req);
1870
1927
  const { runContradictionScan } = await import("./contradiction-scan-SSKCAMLX.js");
1871
1928
  const principal = this.resolveRequestPrincipal(req);
@@ -1877,19 +1934,29 @@ var EngramAccessHttpServer = class {
1877
1934
  storageForNamespace: (namespace) => this.service.getWritableStorageForNamespace(namespace, principal),
1878
1935
  localLlm: this.service.localLlmRef,
1879
1936
  fallbackLlm: this.service.fallbackLlmRef,
1880
- namespace: typeof body.namespace === "string" ? body.namespace : void 0
1937
+ namespace: this.resolveNamespace(req, typeof body.namespace === "string" ? body.namespace : void 0)
1881
1938
  });
1882
1939
  this.respondJson(res, 200, result);
1883
1940
  return;
1884
1941
  }
1885
1942
  if (req.method === "GET" && pathname === "/engram/v1/graph/events") {
1886
- void getOperation("graph_events");
1943
+ this.enforceTokenOp("graph_events");
1887
1944
  await this.handleGraphEventsSSE(req, res);
1888
1945
  return;
1889
1946
  }
1890
1947
  if (req.method === "POST" && pathname === "/engram/v1/chat/message") {
1891
- void getOperation("chat_message");
1948
+ this.enforceTokenOp("chat_message");
1892
1949
  const body = await this.readJsonBody(req);
1950
+ const resumeChatSessionId = typeof body.chatSessionId === "string" ? body.chatSessionId : void 0;
1951
+ if (resumeChatSessionId) {
1952
+ await enforceChatSessionNamespace(this.service, resumeChatSessionId);
1953
+ } else {
1954
+ enforceNamespaceAllowList(
1955
+ tokenCapabilityStore.getStore(),
1956
+ void 0,
1957
+ this.service.configRef?.defaultNamespace
1958
+ );
1959
+ }
1893
1960
  await handleChatMessage(
1894
1961
  req,
1895
1962
  res,
@@ -1901,7 +1968,8 @@ var EngramAccessHttpServer = class {
1901
1968
  }
1902
1969
  const chatEventsMatch = /^\/engram\/v1\/chat\/events\/([^/]+)$/.exec(pathname);
1903
1970
  if (req.method === "GET" && chatEventsMatch) {
1904
- void getOperation("chat_events");
1971
+ this.enforceTokenOp("chat_events");
1972
+ await enforceChatSessionNamespace(this.service, chatEventsMatch[1] ?? "");
1905
1973
  await handleChatEventsSSE(
1906
1974
  req,
1907
1975
  res,
@@ -1927,21 +1995,21 @@ var EngramAccessHttpServer = class {
1927
1995
  return;
1928
1996
  }
1929
1997
  if (req.method === "GET" && pathname === "/engram/v1/console/state") {
1930
- void getOperation("console_state");
1931
- const namespace = parsed.searchParams.get("namespace") ?? void 0;
1998
+ this.enforceTokenOp("console_state");
1999
+ const namespace = this.resolveNamespace(req, parsed.searchParams.get("namespace") ?? void 0);
1932
2000
  const snapshot = await this.service.consoleState(namespace, this.resolveRequestPrincipal(req));
1933
2001
  this.respondJson(res, 200, snapshot);
1934
2002
  return;
1935
2003
  }
1936
2004
  if (req.method === "GET" && pathname === "/engram/v1/peers") {
1937
- void getOperation("peer_list");
2005
+ this.enforceTokenOp("peer_list");
1938
2006
  const result = await this.service.peerList();
1939
2007
  this.respondJson(res, 200, result);
1940
2008
  return;
1941
2009
  }
1942
2010
  const peerProfileMatch = /^\/engram\/v1\/peers\/([^/]+)\/profile$/.exec(pathname);
1943
2011
  if (peerProfileMatch) {
1944
- void getOperation("peer_profile_get");
2012
+ this.enforceTokenOp("peer_profile_get");
1945
2013
  if (req.method !== "GET") {
1946
2014
  this.respondJson(res, 405, { error: "method_not_allowed", code: "method_not_allowed" });
1947
2015
  return;
@@ -1959,7 +2027,7 @@ var EngramAccessHttpServer = class {
1959
2027
  if (peerIdMatch) {
1960
2028
  const peerId = decodePeerIdSegment(peerIdMatch[1] ?? "");
1961
2029
  if (req.method === "GET") {
1962
- void getOperation("peer_get");
2030
+ this.enforceTokenOp("peer_get");
1963
2031
  const result = await this.service.peerGet(peerId);
1964
2032
  if (!result.found) {
1965
2033
  this.respondJson(res, 404, { error: "peer_not_found", code: "peer_not_found" });
@@ -1969,7 +2037,7 @@ var EngramAccessHttpServer = class {
1969
2037
  return;
1970
2038
  }
1971
2039
  if (req.method === "PUT") {
1972
- void getOperation("peer_set");
2040
+ this.enforceTokenOp("peer_set");
1973
2041
  const body = await this.readJsonBody(req);
1974
2042
  if ("kind" in body && body.kind !== void 0 && typeof body.kind !== "string") {
1975
2043
  throw new EngramAccessInputError("kind must be a string when provided");
@@ -1990,7 +2058,7 @@ var EngramAccessHttpServer = class {
1990
2058
  return;
1991
2059
  }
1992
2060
  if (req.method === "DELETE") {
1993
- void getOperation("peer_delete");
2061
+ this.enforceTokenOp("peer_delete");
1994
2062
  const forgetParam = parsed.searchParams.get("forget");
1995
2063
  if (forgetParam === "true") {
1996
2064
  const body = await this.readJsonBody(req);
@@ -2015,7 +2083,7 @@ var EngramAccessHttpServer = class {
2015
2083
  return;
2016
2084
  }
2017
2085
  if (req.method === "GET" && pathname === "/engram/v1/dreams/status") {
2018
- void getOperation("dreams_status");
2086
+ this.enforceTokenOp("dreams_status");
2019
2087
  const { normalizeDreamsStatusWindowHours } = await import("./dreams-ledger-6UODQOX6.js");
2020
2088
  const windowHoursRaw = parsed.searchParams.get("windowHours");
2021
2089
  let windowHours;
@@ -2028,7 +2096,7 @@ var EngramAccessHttpServer = class {
2028
2096
  return;
2029
2097
  }
2030
2098
  const namespaceParam = parsed.searchParams.get("namespace");
2031
- const namespace = namespaceParam && namespaceParam.length > 0 ? namespaceParam : void 0;
2099
+ const namespace = this.resolveNamespace(req, namespaceParam && namespaceParam.length > 0 ? namespaceParam : void 0);
2032
2100
  const result = await this.service.dreamsStatus({
2033
2101
  windowHours,
2034
2102
  namespace,
@@ -2038,7 +2106,7 @@ var EngramAccessHttpServer = class {
2038
2106
  return;
2039
2107
  }
2040
2108
  if (req.method === "POST" && pathname === "/engram/v1/dreams/run") {
2041
- void getOperation("dreams_run");
2109
+ this.enforceTokenOp("dreams_run");
2042
2110
  const body = await this.readJsonBody(req);
2043
2111
  const VALID_PHASES = ["lightSleep", "rem", "deepSleep"];
2044
2112
  const phase = typeof body.phase === "string" ? body.phase : void 0;
@@ -2061,7 +2129,7 @@ var EngramAccessHttpServer = class {
2061
2129
  return;
2062
2130
  }
2063
2131
  const dryRun = body.dryRun === true;
2064
- const namespace = typeof body.namespace === "string" ? body.namespace : void 0;
2132
+ const namespace = this.resolveNamespace(req, typeof body.namespace === "string" ? body.namespace : void 0);
2065
2133
  if (!dryRun) {
2066
2134
  this.ensureWriteRateLimitAvailable();
2067
2135
  }
@@ -2082,6 +2150,7 @@ var EngramAccessHttpServer = class {
2082
2150
  this.respondJson(res, 405, { error: "method_not_allowed", code: "method_not_allowed" });
2083
2151
  return;
2084
2152
  }
2153
+ this.requireOperatorToken();
2085
2154
  const principal = this.resolveRequestPrincipal(req);
2086
2155
  let sessionKey;
2087
2156
  let namespaceOverride;
@@ -2110,6 +2179,7 @@ var EngramAccessHttpServer = class {
2110
2179
  this.respondJson(res, 405, { error: "method_not_allowed", code: "method_not_allowed" });
2111
2180
  return;
2112
2181
  }
2182
+ this.requireOperatorToken();
2113
2183
  const kind = parsed.searchParams.get("kind");
2114
2184
  const principal = parsed.searchParams.get("principal");
2115
2185
  const projectId = parsed.searchParams.get("projectId");
@@ -2128,6 +2198,7 @@ var EngramAccessHttpServer = class {
2128
2198
  this.respondJson(res, 405, { error: "method_not_allowed", code: "method_not_allowed" });
2129
2199
  return;
2130
2200
  }
2201
+ this.requireOperatorToken();
2131
2202
  const report = await this.service.adminMaintenanceHealth();
2132
2203
  this.respondJson(res, 200, report);
2133
2204
  return;
@@ -2137,6 +2208,7 @@ var EngramAccessHttpServer = class {
2137
2208
  this.respondJson(res, 405, { error: "method_not_allowed", code: "method_not_allowed" });
2138
2209
  return;
2139
2210
  }
2211
+ this.requireOperatorToken();
2140
2212
  const report = await this.service.adminTranscriptAudit();
2141
2213
  this.respondJson(res, 200, report);
2142
2214
  return;
@@ -2146,6 +2218,7 @@ var EngramAccessHttpServer = class {
2146
2218
  this.respondJson(res, 405, { error: "method_not_allowed", code: "method_not_allowed" });
2147
2219
  return;
2148
2220
  }
2221
+ this.requireOperatorToken();
2149
2222
  const body = await this.readJsonBody(req);
2150
2223
  if (typeof body.sourceMemoryId !== "string" || body.sourceMemoryId.trim().length === 0) {
2151
2224
  this.respondJson(res, 400, {
@@ -2253,7 +2326,7 @@ var EngramAccessHttpServer = class {
2253
2326
  async handleGraphEventsSSE(req, res) {
2254
2327
  const parsed = new URL(req.url ?? "/", `http://${hostToUrlAuthority(this.host)}`);
2255
2328
  const namespaceParam = parsed.searchParams.get("namespace");
2256
- const namespace = namespaceParam && namespaceParam.length > 0 ? namespaceParam : void 0;
2329
+ const namespace = this.resolveNamespace(req, namespaceParam && namespaceParam.length > 0 ? namespaceParam : void 0);
2257
2330
  const principal = this.resolveRequestPrincipal(req);
2258
2331
  const memoryDir = await this.service.getMemoryDirForNamespace(namespace, principal);
2259
2332
  res.writeHead(200, {
@@ -2360,6 +2433,14 @@ var EngramAccessHttpServer = class {
2360
2433
  })();
2361
2434
  const mcpCorrelationId = correlationIdStore.getStore() ?? randomUUID();
2362
2435
  const requestIdentity = this.resolveRequestIdentity(req);
2436
+ if (request.method === "tools/call" && this.mcpServer.toolAcceptsNamespace(toolName)) {
2437
+ const mcpExplicitNamespace = toolArgs !== null && typeof toolArgs === "object" && !Array.isArray(toolArgs) && typeof toolArgs.namespace === "string" && toolArgs.namespace.length > 0 ? toolArgs.namespace : void 0;
2438
+ enforceNamespaceAllowList(
2439
+ tokenCapabilityStore.getStore(),
2440
+ mcpExplicitNamespace ?? requestIdentity.namespace,
2441
+ this.service.configRef?.defaultNamespace
2442
+ );
2443
+ }
2363
2444
  const response = await this.mcpServer.handleRequest(request, {
2364
2445
  principalOverride: requestIdentity.principal,
2365
2446
  namespaceOverride: requestIdentity.namespace,
@@ -2643,8 +2724,18 @@ var EngramAccessHttpServer = class {
2643
2724
  return "Bearer";
2644
2725
  }
2645
2726
  isAuthorized(req, pathname) {
2727
+ return this.resolveAuthorizedEntry(req, pathname) !== null;
2728
+ }
2729
+ /**
2730
+ * Resolve the presenting token's entry for an authorized request, or null.
2731
+ * Captures the matched entry — including its capabilities record — so the
2732
+ * op/namespace capability enforcement (issue #1837) uses the SAME entry
2733
+ * that validated. Static operator tokens (`authToken`/`authTokens`) and
2734
+ * the string-token getter carry no capabilities ⇒ unrestricted.
2735
+ */
2736
+ resolveAuthorizedEntry(req, pathname) {
2646
2737
  if (!this.authToken && this.authTokens.length === 0 && !this.authTokensGetter && !this.authTokenEntriesGetter) {
2647
- return false;
2738
+ return null;
2648
2739
  }
2649
2740
  const raw = req.headers.authorization;
2650
2741
  let candidate = null;
@@ -2667,27 +2758,69 @@ var EngramAccessHttpServer = class {
2667
2758
  } catch {
2668
2759
  }
2669
2760
  }
2670
- if (!candidate) return false;
2761
+ if (!candidate) return null;
2671
2762
  const token = candidate;
2672
- if (this.authToken && this.timingSafeStringEqual(token, this.authToken)) return true;
2763
+ if (this.authToken && this.timingSafeStringEqual(token, this.authToken)) {
2764
+ return { token };
2765
+ }
2673
2766
  for (const valid of this.authTokens) {
2674
- if (this.timingSafeStringEqual(token, valid)) return true;
2767
+ if (this.timingSafeStringEqual(token, valid)) return { token: valid };
2675
2768
  }
2676
2769
  if (this.authTokenEntriesGetter) {
2677
2770
  for (const entry of this.authTokenEntriesGetter()) {
2678
2771
  if (!this.timingSafeStringEqual(token, entry.token)) continue;
2679
- if (!this.tokenPathPolicy) return true;
2680
- if (typeof entry.connector !== "string" || entry.connector.length === 0) return false;
2681
- return this.tokenPathPolicy(entry.connector, pathname);
2772
+ const matched = { token: entry.token, connector: entry.connector, capabilities: entry.capabilities };
2773
+ if (!this.tokenPathPolicy) return matched;
2774
+ if (typeof entry.connector !== "string" || entry.connector.length === 0) return null;
2775
+ return this.tokenPathPolicy(entry.connector, pathname) ? matched : null;
2682
2776
  }
2683
- return false;
2777
+ return null;
2684
2778
  }
2685
2779
  if (this.authTokensGetter) {
2686
2780
  for (const valid of this.authTokensGetter()) {
2687
- if (this.timingSafeStringEqual(token, valid)) return true;
2781
+ if (this.timingSafeStringEqual(token, valid)) return { token: valid };
2688
2782
  }
2689
2783
  }
2690
- return false;
2784
+ return null;
2785
+ }
2786
+ /** Cache for per-request capability resolution (avoids re-resolving). */
2787
+ capabilityCache = /* @__PURE__ */ new WeakMap();
2788
+ /**
2789
+ * Resolve the presenting token's capabilities for this request, or
2790
+ * undefined when the token is unrestricted (legacy / static operator /
2791
+ * explicit-unrestricted record). Cached per-request. `null` sentinel
2792
+ * distinguishes "resolved as unrestricted" from "not yet resolved".
2793
+ */
2794
+ resolveTokenCapabilities(req, pathname) {
2795
+ if (this.capabilityCache.has(req)) {
2796
+ return this.capabilityCache.get(req) ?? void 0;
2797
+ }
2798
+ const caps = this.resolveAuthorizedEntry(req, pathname)?.capabilities;
2799
+ this.capabilityCache.set(req, caps ?? null);
2800
+ return caps;
2801
+ }
2802
+ /**
2803
+ * Enforce the presenting token's ops allow-list for an HTTP route that
2804
+ * dispatches directly to the service (not through the boundary). Reads the
2805
+ * per-request capability context set in `handle`; unrestricted tokens
2806
+ * pass. Throws {@link EngramAccessForbiddenError} (→ 403) when a scoped
2807
+ * token calls a non-permitted op (issue #1837).
2808
+ */
2809
+ enforceTokenOp(op) {
2810
+ void getOperation(op);
2811
+ assertOperationAllowed(tokenCapabilityStore.getStore(), op);
2812
+ }
2813
+ /**
2814
+ * Operator/admin routes are unrestricted-only surfaces: a scoped
2815
+ * (least-privileged) token must NOT reach them (issue #1837). Legacy and
2816
+ * explicit-unrestricted tokens pass. Throws EngramAccessForbiddenError (→403).
2817
+ */
2818
+ requireOperatorToken() {
2819
+ if (isCapabilityRestricted(tokenCapabilityStore.getStore())) {
2820
+ throw new EngramAccessForbiddenError(
2821
+ "token is scoped and may not access operator/admin routes"
2822
+ );
2823
+ }
2691
2824
  }
2692
2825
  timingSafeStringEqual(a, b) {
2693
2826
  const left = this.encodeSecret(a);
@@ -2765,4 +2898,4 @@ function positiveIntQueryParam(value, label) {
2765
2898
  export {
2766
2899
  EngramAccessHttpServer
2767
2900
  };
2768
- //# sourceMappingURL=chunk-2FOD2YY3.js.map
2901
+ //# sourceMappingURL=chunk-UFUKHGZD.js.map