@xopcai/xopc 0.0.224 → 0.0.227

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 (232) hide show
  1. package/dist/browser-ext/manifest.json +1 -1
  2. package/dist/extensions/demo-memory/src/index.js +10 -1
  3. package/dist/extensions/feishu/src/outbound/media-load.js +1 -1
  4. package/dist/extensions/telegram/xopc.extension.json +1 -1
  5. package/dist/gateway/static/root/assets/{activity-store--GBciH10.js → activity-store-BevwE16n.js} +1 -1
  6. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-K7V4XXt7.js → agent-avatar-dicebear-BggVQrEZ.js} +1 -1
  7. package/dist/gateway/static/root/assets/agents-TJpjRHnr.js +68 -0
  8. package/dist/gateway/static/root/assets/{api-HoIz_ija.js → api-Bx_BpIt8.js} +1 -1
  9. package/dist/gateway/static/root/assets/{app-management-settings-panel-xQCmkAHh.js → app-management-settings-panel-BtKP9n2r.js} +1 -1
  10. package/dist/gateway/static/root/assets/{appearance-settings-BRoeA4kU.js → appearance-settings-BoH2NAUX.js} +1 -1
  11. package/dist/gateway/static/root/assets/apps-page-CZ4Da51l.js +1 -0
  12. package/dist/gateway/static/root/assets/{archive-plugin-CteCVsBP.js → archive-plugin-DnceUyxm.js} +1 -1
  13. package/dist/gateway/static/root/assets/{attachment-load-D7xNA2jB.js → attachment-load-Bh8_9gkr.js} +1 -1
  14. package/dist/gateway/static/root/assets/{automations-page-BD1vK7r5.js → automations-page-ZKeAAVxD.js} +1 -1
  15. package/dist/gateway/static/root/assets/automations-workspace-2Y00PvJU.js +6 -0
  16. package/dist/gateway/static/root/assets/{binary-plugins-C3DaJa0W.js → binary-plugins-Cy9er6w-.js} +1 -1
  17. package/dist/gateway/static/root/assets/{block-editor-lTkcHTve.js → block-editor-Cc0wWvNX.js} +3 -3
  18. package/dist/gateway/static/root/assets/browser-settings-page-CbJD27_j.js +8 -0
  19. package/dist/gateway/static/root/assets/{browser-workflow-inputs-1UZ0vnIy.js → browser-workflow-inputs-BS7rpLLl.js} +1 -1
  20. package/dist/gateway/static/root/assets/{browser-workflows-page-BHuJOF4M.js → browser-workflows-page-BdBVUZXm.js} +2 -2
  21. package/dist/gateway/static/root/assets/capabilities-settings-panel-Dv8y6OuP.js +7 -0
  22. package/dist/gateway/static/root/assets/{capability-presets-api-yNqTIuyd.js → capability-presets-api-D1Lqz0Tt.js} +1 -1
  23. package/dist/gateway/static/root/assets/capability-presets-settings-panel-TZmjzWzt.js +3 -0
  24. package/dist/gateway/static/root/assets/{channel-recipient-api-krezGsKc.js → channel-recipient-api-CGuEl-l2.js} +1 -1
  25. package/dist/gateway/static/root/assets/{channels-settings-B4AtvQHk.js → channels-settings-g-68dutA.js} +1 -1
  26. package/dist/gateway/static/root/assets/channels-status-swr-D7KsAeWh.js +1 -0
  27. package/dist/gateway/static/root/assets/{chat-terminal-dock-BRrL2iHA.js → chat-terminal-dock-CdX_7aQh.js} +1 -1
  28. package/dist/gateway/static/root/assets/connectors-page-DXA0rAvQ.js +2 -0
  29. package/dist/gateway/static/root/assets/{cron-expression-Bl-2DzBQ.js → cron-expression-BnSQc4Ek.js} +1 -1
  30. package/dist/gateway/static/root/assets/{date-picker-CxTl6Wlz.js → date-picker-BbuG7zQ_.js} +1 -1
  31. package/dist/gateway/static/root/assets/{dependency-picker-DSl0mOPa.js → dependency-picker-snZeqOmG.js} +1 -1
  32. package/dist/gateway/static/root/assets/{desktop-pet-DTeCmCdb.js → desktop-pet-DJQ8JoR1.js} +1 -1
  33. package/dist/gateway/static/root/assets/{desktop-pet-settings-BNebxg0V.js → desktop-pet-settings-B9txsRtv.js} +1 -1
  34. package/dist/gateway/static/root/assets/{directory-picker-path-field-Dn9XpmXY.js → directory-picker-path-field-D7WKWkNB.js} +1 -1
  35. package/dist/gateway/static/root/assets/{extension-debug-page-D-J-eOTb.js → extension-debug-page-D_7cOCj2.js} +1 -1
  36. package/dist/gateway/static/root/assets/{extension-page-CpST24nU.js → extension-page-Bwu47iUb.js} +1 -1
  37. package/dist/gateway/static/root/assets/{extension-settings-page-4nQXFnFq.js → extension-settings-page-Dwg4dSZM.js} +1 -1
  38. package/dist/gateway/static/root/assets/{gateway-config-api-BHWHduDi.js → gateway-config-api-jURUSte_.js} +1 -1
  39. package/dist/gateway/static/root/assets/{gateway-config-swr-yUxMMVjK.js → gateway-config-swr-6SQXF1yR.js} +1 -1
  40. package/dist/gateway/static/root/assets/{gateway-settings-BimMKmkM.js → gateway-settings-UklJOMLX.js} +1 -1
  41. package/dist/gateway/static/root/assets/{gateway-startup-retry-9mrsL84j.js → gateway-startup-retry-DqWaxyvZ.js} +1 -1
  42. package/dist/gateway/static/root/assets/heartbeat-settings-Djs_nduD.js +1 -0
  43. package/dist/gateway/static/root/assets/{home-page-DSM6aPHF.js → home-page-i6bXCHdo.js} +1 -1
  44. package/dist/gateway/static/root/assets/{image-generation-api-CgFAGDi8.js → image-generation-api-Bxmt6LEr.js} +1 -1
  45. package/dist/gateway/static/root/assets/index-BBBE89vm.css +2 -0
  46. package/dist/gateway/static/root/assets/index-BsD5wygl.js +74 -0
  47. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-6Ar5rfX4.js → keyboard-shortcuts-settings-ByVsCH3d.js} +1 -1
  48. package/dist/gateway/static/root/assets/{local-app-workbench-page-tzM0wTL8.js → local-app-workbench-page-BCKEDMlP.js} +2 -2
  49. package/dist/gateway/static/root/assets/{local-apps-page-B5n-x544.js → local-apps-page-D19R-xsz.js} +1 -1
  50. package/dist/gateway/static/root/assets/{locale-store-CPylQjH9.js → locale-store-Ci1Qi0Q-.js} +1 -1
  51. package/dist/gateway/static/root/assets/{logs-page-CgoQlera.js → logs-page-Cy9YQK7j.js} +2 -2
  52. package/dist/gateway/static/root/assets/{management-settings-CXBLyU-0.js → management-settings-G0y7zmfY.js} +1 -1
  53. package/dist/gateway/static/root/assets/{markdown-split-CtmQemJi.js → markdown-split-B69d2HWt.js} +1 -1
  54. package/dist/gateway/static/root/assets/{markdown-view-CUsob4Pz.js → markdown-view-CBM-v2ph.js} +1 -1
  55. package/dist/gateway/static/root/assets/{media-plugins-Dsd-IEOW.js → media-plugins-6TWEQgN_.js} +1 -1
  56. package/dist/gateway/static/root/assets/messages-CtOJwGW3.js +3 -0
  57. package/dist/gateway/static/root/assets/{notes-api-CfKZYrBC.js → notes-api-DLsnnZCS.js} +1 -1
  58. package/dist/gateway/static/root/assets/{notes-page-BKbOTE2n.js → notes-page-CkRJJKDm.js} +1 -1
  59. package/dist/gateway/static/root/assets/notes-workbench-B10T3hGX.js +4 -0
  60. package/dist/gateway/static/root/assets/{product-open-page-DqB9bsDB.js → product-open-page-HxArIvoN.js} +1 -1
  61. package/dist/gateway/static/root/assets/project-detail-page-DsqRlgsy.js +1 -0
  62. package/dist/gateway/static/root/assets/{projects-page-PeXUdGdO.js → projects-page-Bu2PN8OK.js} +1 -1
  63. package/dist/gateway/static/root/assets/{registry-api-B_5D8epF.js → registry-api-lEar5FOV.js} +1 -1
  64. package/dist/gateway/static/root/assets/remote-access-hub-CXACdJ2f.js +1 -0
  65. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-DBTH_t0O.js → runtime-tools-settings-panel-Bf03UNGD.js} +2 -2
  66. package/dist/gateway/static/root/assets/{schema-form-CqMKAwV0.js → schema-form-CIXMBgx5.js} +1 -1
  67. package/dist/gateway/static/root/assets/sessions-page-CS2knWDT.js +1 -0
  68. package/dist/gateway/static/root/assets/settings-advanced-gate-ByFGk0q_.js +1 -0
  69. package/dist/gateway/static/root/assets/{settings-form-section-dPriuuYq.js → settings-form-section-DgdB26mE.js} +1 -1
  70. package/dist/gateway/static/root/assets/{settings-loading-skeleton-B-Mbm8Va.js → settings-loading-skeleton-efk5W6lG.js} +1 -1
  71. package/dist/gateway/static/root/assets/{settings-page-Dyj3w-Ml.js → settings-page-BHVf4gEP.js} +1 -1
  72. package/dist/gateway/static/root/assets/{setup-status-panel-C4FxY5J3.js → setup-status-panel-WK0dGNMv.js} +1 -1
  73. package/dist/gateway/static/root/assets/{share-preview-page-emEdx7YL.js → share-preview-page-Cod-w2qm.js} +1 -1
  74. package/dist/gateway/static/root/assets/shares-settings-CUqQ31gt.js +1 -0
  75. package/dist/gateway/static/root/assets/skill-reload-api-DweAPjI8.js +1 -0
  76. package/dist/gateway/static/root/assets/{skills-page-BNtYnrRT.js → skills-page-DwCcipqK.js} +1 -1
  77. package/dist/gateway/static/root/assets/{skills-page.utils-DjnbNFs5.js → skills-page.utils-3WSbtl3S.js} +1 -1
  78. package/dist/gateway/static/root/assets/{system-settings-panel-DDStf-jZ.js → system-settings-panel-C5VxqC_s.js} +1 -1
  79. package/dist/gateway/static/root/assets/task-detail-page-DEj-BFMP.js +1 -0
  80. package/dist/gateway/static/root/assets/{theme-store-BN-32Fz5.js → theme-store-Dd89g_ki.js} +1 -1
  81. package/dist/gateway/static/root/assets/{use-autosave-C2mKZ-ua.js → use-autosave-CeV8VJh2.js} +1 -1
  82. package/dist/gateway/static/root/assets/user-context-page-f7yh7aD5.js +1 -0
  83. package/dist/gateway/static/root/assets/{voice-api-key-field-D7OHeQby.js → voice-api-key-field-EmJ-8aZu.js} +1 -1
  84. package/dist/gateway/static/root/assets/{work-discovery-overlay-CIiXie7F.js → work-discovery-overlay-zsk6E3Mi.js} +1 -1
  85. package/dist/gateway/static/root/assets/workflow-run-setup-panel-CBAYvm3G.js +3 -0
  86. package/dist/gateway/static/root/assets/workflows-page-BN0JmHrG.js +5 -0
  87. package/dist/gateway/static/root/index.html +11 -11
  88. package/dist/package.js +1 -1
  89. package/dist/src/agent/agent-manager.d.ts +3 -1
  90. package/dist/src/agent/agent-manager.js +22 -5
  91. package/dist/src/agent/embedded/run-turn.js +2 -0
  92. package/dist/src/agent/mcp/bundle-mcp-config.d.ts +9 -1
  93. package/dist/src/agent/mcp/bundle-mcp-config.js +11 -15
  94. package/dist/src/agent/mcp/embedded-mcp.d.ts +1 -1
  95. package/dist/src/agent/mcp/index.d.ts +1 -0
  96. package/dist/src/agent/mcp/index.js +7 -1
  97. package/dist/src/agent/mcp/mcp-http.d.ts +4 -0
  98. package/dist/src/agent/mcp/mcp-http.js +25 -1
  99. package/dist/src/agent/mcp/mcp-transport-config.d.ts +4 -0
  100. package/dist/src/agent/mcp/mcp-transport-config.js +1 -0
  101. package/dist/src/agent/mcp/mcp-transport.d.ts +7 -1
  102. package/dist/src/agent/mcp/mcp-transport.js +38 -11
  103. package/dist/src/agent/mcp/oauth/index.d.ts +6 -0
  104. package/dist/src/agent/mcp/oauth/index.js +6 -0
  105. package/dist/src/agent/mcp/oauth/mcp-oauth-errors.d.ts +5 -0
  106. package/dist/src/agent/mcp/oauth/mcp-oauth-errors.js +14 -0
  107. package/dist/src/agent/mcp/oauth/mcp-oauth-manager.d.ts +25 -0
  108. package/dist/src/agent/mcp/oauth/mcp-oauth-manager.js +219 -0
  109. package/dist/src/agent/mcp/oauth/mcp-oauth-provider.d.ts +33 -0
  110. package/dist/src/agent/mcp/oauth/mcp-oauth-provider.js +103 -0
  111. package/dist/src/agent/mcp/oauth/mcp-oauth-session.d.ts +29 -0
  112. package/dist/src/agent/mcp/oauth/mcp-oauth-session.js +169 -0
  113. package/dist/src/agent/mcp/oauth/mcp-oauth-store.d.ts +9 -0
  114. package/dist/src/agent/mcp/oauth/mcp-oauth-store.js +79 -0
  115. package/dist/src/agent/mcp/oauth/mcp-oauth-types.d.ts +22 -0
  116. package/dist/src/agent/mcp/oauth/mcp-oauth-types.js +1 -0
  117. package/dist/src/agent/memory/builtin-provider.js +23 -4
  118. package/dist/src/agent/memory/compaction-promotion.d.ts +18 -0
  119. package/dist/src/agent/memory/compaction-promotion.js +211 -0
  120. package/dist/src/agent/memory/context/types.d.ts +5 -0
  121. package/dist/src/agent/memory/manager.d.ts +3 -0
  122. package/dist/src/agent/memory/manager.js +12 -2
  123. package/dist/src/agent/memory/trusted-recall.d.ts +7 -0
  124. package/dist/src/agent/memory/trusted-recall.js +53 -0
  125. package/dist/src/agent/memory/turn-provenance.d.ts +14 -0
  126. package/dist/src/agent/memory/turn-provenance.js +60 -0
  127. package/dist/src/agent/memory/types.d.ts +18 -3
  128. package/dist/src/agent/memory/understanding/service.js +1 -0
  129. package/dist/src/agent/memory/understanding/types.d.ts +1 -0
  130. package/dist/src/agent/memory/user-context-coordinator.js +57 -6
  131. package/dist/src/agent/service.d.ts +2 -0
  132. package/dist/src/agent/service.js +6 -0
  133. package/dist/src/agent/skills/index.d.ts +22 -2
  134. package/dist/src/agent/skills/index.js +74 -32
  135. package/dist/src/agent/skills/marketplace/adapters/store/store-api-client.d.ts +2 -0
  136. package/dist/src/agent/skills/skill-sources.d.ts +0 -1
  137. package/dist/src/agent/skills/skill-sources.js +1 -11
  138. package/dist/src/agent/tools/memory-tool.js +5 -1
  139. package/dist/src/capabilities/store-connector.js +99 -10
  140. package/dist/src/cli/commands/channels.js +1 -1
  141. package/dist/src/cli/commands/connectors.js +1 -1
  142. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  143. package/dist/src/cli/commands/extension-marketplace.js +1 -1
  144. package/dist/src/cli/commands/models.js +1 -1
  145. package/dist/src/cli/commands/onboard.js +1 -1
  146. package/dist/src/config/config-mutation.d.ts +14 -0
  147. package/dist/src/config/config-mutation.js +33 -0
  148. package/dist/src/config/index.js +3 -3
  149. package/dist/src/config/paths.d.ts +2 -0
  150. package/dist/src/config/paths.js +5 -1
  151. package/dist/src/config/schema.d.ts +17 -0
  152. package/dist/src/config/schema.js +26 -2
  153. package/dist/src/connectors/auth-provider-registry.d.ts +1 -1
  154. package/dist/src/connectors/auth-provider-registry.js +23 -2
  155. package/dist/src/connectors/connected-source-understanding.js +1 -1
  156. package/dist/src/connectors/install.js +3 -3
  157. package/dist/src/connectors/instances.d.ts +2 -1
  158. package/dist/src/connectors/instances.js +15 -5
  159. package/dist/src/connectors/materialize.d.ts +1 -0
  160. package/dist/src/connectors/materialize.js +9 -1
  161. package/dist/src/connectors/runtime-adapter-registry.js +1 -0
  162. package/dist/src/connectors/types.d.ts +4 -1
  163. package/dist/src/extensions/connector-dependencies.d.ts +10 -0
  164. package/dist/src/extensions/connector-dependencies.js +65 -0
  165. package/dist/src/extensions/install.js +27 -0
  166. package/dist/src/extensions/normalize-manifest.js +1 -0
  167. package/dist/src/extensions/sdk/index.js +1 -1
  168. package/dist/src/extensions/types/manifest.d.ts +2 -0
  169. package/dist/src/gateway/hono/routes/capabilities.js +8 -8
  170. package/dist/src/gateway/hono/routes/connectors.js +104 -70
  171. package/dist/src/gateway/hono/routes/mcp.js +77 -5
  172. package/dist/src/gateway/hono/routes/project-skills.js +30 -2
  173. package/dist/src/gateway/hono/routes/you.js +52 -0
  174. package/dist/src/gateway/service.js +8 -8
  175. package/dist/src/knowledge/connected-knowledge-pipeline.js +26 -4
  176. package/dist/src/knowledge/connected-understanding-pipeline.js +12 -3
  177. package/dist/src/knowledge/index.d.ts +0 -1
  178. package/dist/src/knowledge/index.js +1 -2
  179. package/dist/src/projects/project-skill-service.d.ts +28 -6
  180. package/dist/src/projects/project-skill-service.js +76 -29
  181. package/dist/src/session/store.js +27 -0
  182. package/dist/src/storage/sqlite/index.d.ts +1 -0
  183. package/dist/src/storage/sqlite/index.js +2 -1
  184. package/dist/src/storage/sqlite/memory-records-repository.d.ts +9 -1
  185. package/dist/src/storage/sqlite/memory-records-repository.js +40 -6
  186. package/dist/src/storage/sqlite/migrations/134_memory_provenance.sql +18 -0
  187. package/dist/src/storage/sqlite/migrations/135_user_people.sql +59 -0
  188. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  189. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  190. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  191. package/dist/src/storage/sqlite/schema.js +1 -1
  192. package/dist/src/storage/sqlite/user-people-repository.d.ts +32 -0
  193. package/dist/src/storage/sqlite/user-people-repository.js +246 -0
  194. package/dist/src/tui/backends/embedded-backend.js +1 -1
  195. package/dist/src/user-context/planner.js +8 -3
  196. package/dist/src/user-context/relationships/indexer.d.ts +13 -0
  197. package/dist/src/user-context/relationships/indexer.js +185 -0
  198. package/dist/src/user-context/relationships/service.d.ts +22 -0
  199. package/dist/src/user-context/relationships/service.js +50 -0
  200. package/dist/src/user-context/relationships/types.d.ts +55 -0
  201. package/dist/src/user-context/relationships/types.js +10 -0
  202. package/dist/src/user-context/sources/repository.d.ts +1 -1
  203. package/dist/src/user-context/sources/repository.js +8 -2
  204. package/dist/src/work-discovery/service.js +1 -1
  205. package/package.json +2 -2
  206. package/dist/gateway/static/root/assets/agents-BsxTpXyq.js +0 -68
  207. package/dist/gateway/static/root/assets/apps-page-BXgpBA8w.js +0 -1
  208. package/dist/gateway/static/root/assets/automations-workspace-wrgf-z7D.js +0 -6
  209. package/dist/gateway/static/root/assets/browser-settings-page-zhzNkeVG.js +0 -8
  210. package/dist/gateway/static/root/assets/capabilities-settings-panel-DuCmg2Ej.js +0 -7
  211. package/dist/gateway/static/root/assets/capability-presets-settings-panel-DjiP3mQQ.js +0 -3
  212. package/dist/gateway/static/root/assets/channels-status-swr-DMxB7slL.js +0 -1
  213. package/dist/gateway/static/root/assets/connectors-page-fmda2NEP.js +0 -2
  214. package/dist/gateway/static/root/assets/heartbeat-settings-MUJ3mEC9.js +0 -1
  215. package/dist/gateway/static/root/assets/index-B3zYJBhK.js +0 -74
  216. package/dist/gateway/static/root/assets/index-D3_xSYKd.css +0 -2
  217. package/dist/gateway/static/root/assets/messages-B82nsi9k.js +0 -3
  218. package/dist/gateway/static/root/assets/notes-workbench-BScELo01.js +0 -4
  219. package/dist/gateway/static/root/assets/project-detail-page-DUoyty8X.js +0 -1
  220. package/dist/gateway/static/root/assets/remote-access-hub-sHho-uXP.js +0 -1
  221. package/dist/gateway/static/root/assets/sessions-page-DyvNgaP9.js +0 -1
  222. package/dist/gateway/static/root/assets/settings-advanced-gate-CnYf1R7z.js +0 -1
  223. package/dist/gateway/static/root/assets/shares-settings-BQBVq-sN.js +0 -1
  224. package/dist/gateway/static/root/assets/skill-reload-api-BFoEpQ4I.js +0 -1
  225. package/dist/gateway/static/root/assets/task-detail-page-ZVwr8KbS.js +0 -1
  226. package/dist/gateway/static/root/assets/user-context-page-CHjIinCW.js +0 -1
  227. package/dist/gateway/static/root/assets/workflow-run-setup-panel-9_dAGW3_.js +0 -3
  228. package/dist/gateway/static/root/assets/workflows-page-DXpYJxao.js +0 -5
  229. package/dist/src/extensions/bundle-mcp.d.ts +0 -18
  230. package/dist/src/extensions/bundle-mcp.js +0 -69
  231. package/dist/src/knowledge/people-graph.d.ts +0 -25
  232. package/dist/src/knowledge/people-graph.js +0 -92
@@ -4,6 +4,7 @@ import { init_logger } from "../utils/logger.js";
4
4
  import { requireXopcDatabase } from "../storage/sqlite/connection.js";
5
5
  import { buildSessionContextForLlm, buildSessionDisplayMessages, isRuntimeOnlyTranscriptMessage, isTranscriptCompactionEntry, mergeLlmMessagesPreservingContextRows, transcriptRowsFromJsonArray } from "./session-context-for-llm.js";
6
6
  import "./types.js";
7
+ import { init_agent_session_key, resolveAgentIdFromSessionKey } from "../routing/agent-session-key.js";
7
8
  import { estimateTokensFromMessages } from "../storage/sqlite/row-mappers.js";
8
9
  import { deleteSessionRecord, ensureSessionRecord, findSessionKeyBySessionId, getGlobalSessionStats, getSessionMetadata, listSessionMetadata, listSessionsByAgent, patchSessionMetadata, resetSessionRecord } from "../storage/sqlite/session-repository.js";
9
10
  import { appendCompactionBoundaryIfUnchanged, appendTranscriptEntry, listCompactionBoundaries, loadCompactionSourceSnapshot, loadLlmMessagesForSession, loadTranscriptHistoryRowsForSession, loadTranscriptRowsForSession, paginateTranscriptMessages, replaceTranscriptRows, restoreBeforeCompactionBoundary, searchSessionTranscript } from "../storage/sqlite/transcript-repository.js";
@@ -12,12 +13,14 @@ import { resolveEffectiveAgentProfileForSession } from "../config/agent-profile.
12
13
  import { readPostCompactionContext } from "../agent/reply/post-compaction-context.js";
13
14
  import { SessionCompactor } from "../agent/memory/compaction.js";
14
15
  import { resolveCompactionPolicy } from "../agent/memory/compaction-policy.js";
16
+ import { promoteCompactionLedger } from "../agent/memory/compaction-promotion.js";
15
17
  import { SlidingWindow } from "../agent/memory/window.js";
16
18
  import { isAppendOnlyLlmTranscriptMessage } from "./transcript-stats.js";
17
19
  import { transcriptRowsToClientHistory } from "./client-history.js";
18
20
  import { computeTranscriptUserRoundDeleteRange } from "./user-round-delete.js";
19
21
  //#region src/session/store.ts
20
22
  init_paths_state();
23
+ init_agent_session_key();
21
24
  init_logger();
22
25
  const log = createLogger("SessionStore");
23
26
  const INDEX_VERSION = "1.0";
@@ -455,6 +458,30 @@ var SessionStore = class {
455
458
  tokensBefore: result.tokensBefore,
456
459
  tokensAfter: result.tokensAfter
457
460
  })) throw new Error(`Session changed while compaction was running: ${key}`);
461
+ try {
462
+ const metadata = getSessionMetadata(key);
463
+ const promoted = promoteCompactionLedger({
464
+ sessionKey: key,
465
+ sessionId: expectedSnapshot.sessionId,
466
+ sourceAgentId: resolveAgentIdFromSessionKey(key),
467
+ workspaceId: this.resolveWorkspaceCwd(key),
468
+ projectId: metadata?.projectId,
469
+ handover: result.handover,
470
+ audit: result.audit,
471
+ sourceEntries: expectedSnapshot.entries
472
+ });
473
+ log.info({
474
+ sessionKey: key,
475
+ episodicCount: promoted.episodicRecordIds.length,
476
+ durableCount: promoted.durableRecordIds.length,
477
+ rejectedCount: promoted.rejectedRecordIds.length
478
+ }, "Compaction ledger memory promotion completed");
479
+ } catch (err) {
480
+ log.warn({
481
+ err,
482
+ sessionKey: key
483
+ }, "Compaction ledger memory promotion failed");
484
+ }
458
485
  log.info({
459
486
  key,
460
487
  tokensBefore: result.tokensBefore,
@@ -10,6 +10,7 @@ export { closeTemporalAssertions, createTemporalAssertion, linkContextObjects, l
10
10
  export { finishContextConsolidationRun, getContextConsolidationRun, listContextConsolidationDecisions, listContextConsolidationRuns, recordContextConsolidationDecision, startContextConsolidationRun, type ContextConsolidationDecision, type ContextConsolidationRun, } from './context-consolidation-repository.js';
11
11
  export { summarizeUnderstandingFeedback, summarizeUserUnderstandingQuality, type UnderstandingFeedbackSummary, type UserUnderstandingQualityMetrics, } from './user-context-quality-repository.js';
12
12
  export { createCollaborationRule, createContextEvidence, createUnderstanding, closeUnderstandingValidity, consumeContextConsent, deleteCollaborationRule, deleteUnderstanding, decideContextConsent, ensureContextConsent, getCollaborationRule, getTurnPersonalization, getUnderstanding, getUserProfile, hasContextConsent, isUnderstandingSuppressed, listCollaborationRules, listUnderstandingEvidence, listUnderstandings, linkUnderstandingEvidence, recordContextFeedback, recordContextRun, rejectUnderstanding, reviseCollaborationRule, reviseUnderstanding, searchActiveUnderstandings, setCollaborationRuleStatus, setUnderstandingStatus, updateUserProfile, type CreateUnderstandingInput, } from './user-context-repository.js';
13
+ export { getUserPerson, getUserPeopleIndexState, listUserPeople, mergeUserPeople, replaceUserPeopleIndex, summarizeUserPeople, updateUserPerson, } from './user-people-repository.js';
13
14
  export { cancelQueuedSessionInput, claimNextSessionInput, findSessionInput, finishSessionInputRun, getSessionInputState, getSessionInputById, insertSessionInput, mutateQueuedSessionInput, recoverSessionInputState, setSessionInputStatus, type SessionInput, type SessionInputDelivery, type SessionInputState, type SessionInputStatus, } from './session-input-repository.js';
14
15
  export { replaceLatestSessionTurnAndQueueInput, validateLatestSessionTurnTarget, type ReplaceLatestSessionTurnInput, type ReplaceLatestSessionTurnResult, } from './session-turn-replace-repository.js';
15
16
  export { acknowledgeHomeAttention, isHomeAttentionAcknowledged, type HomeAttentionSubjectKind, } from './home-attention-repository.js';
@@ -11,6 +11,7 @@ import { closeTemporalAssertions, createTemporalAssertion, linkContextObjects, l
11
11
  import { finishContextConsolidationRun, getContextConsolidationRun, listContextConsolidationDecisions, listContextConsolidationRuns, recordContextConsolidationDecision, startContextConsolidationRun } from "./context-consolidation-repository.js";
12
12
  import { summarizeUnderstandingFeedback, summarizeUserUnderstandingQuality } from "./user-context-quality-repository.js";
13
13
  import { closeUnderstandingValidity, consumeContextConsent, createCollaborationRule, createContextEvidence, createUnderstanding, decideContextConsent, deleteCollaborationRule, deleteUnderstanding, ensureContextConsent, getCollaborationRule, getTurnPersonalization, getUnderstanding, getUserProfile, hasContextConsent, isUnderstandingSuppressed, linkUnderstandingEvidence, listCollaborationRules, listUnderstandingEvidence, listUnderstandings, recordContextFeedback, recordContextRun, rejectUnderstanding, reviseCollaborationRule, reviseUnderstanding, searchActiveUnderstandings, setCollaborationRuleStatus, setUnderstandingStatus, updateUserProfile } from "./user-context-repository.js";
14
+ import { getUserPeopleIndexState, getUserPerson, listUserPeople, mergeUserPeople, replaceUserPeopleIndex, summarizeUserPeople, updateUserPerson } from "./user-people-repository.js";
14
15
  import { cancelQueuedSessionInput, claimNextSessionInput, findSessionInput, finishSessionInputRun, getSessionInputById, getSessionInputState, insertSessionInput, mutateQueuedSessionInput, recoverSessionInputState, setSessionInputStatus } from "./session-input-repository.js";
15
16
  import { buildDefaultSessionMetadata } from "./session-metadata.js";
16
17
  import { buildGlobalSessionStats, classifyStoredRow, estimateTokensFromMessages, extractFtsContent, metadataToSessionInsert, sessionConfigRowToConfig, sessionRowToMetadata, transcriptEntryRowToStoredRow } from "./row-mappers.js";
@@ -35,4 +36,4 @@ import { appendConnectorExecutionAudit, claimConnectorWebhookDelivery, completeC
35
36
  import { getConnectorAccount, listConnectorAccounts, reconcileConnectorAccount, refreshConnectorAccountCurrent } from "./connector-account-repository.js";
36
37
  import { getConnectorSyncPolicy, getConnectorSyncPolicyForConnection, listConnectorSyncPolicies, upsertConnectorSyncPolicy } from "./connector-sync-policy-repository.js";
37
38
  import { getUserTrustPolicy, setUserTrustPolicy } from "./user-trust-repository.js";
38
- export { COMPOSER_INPUT_HISTORY_LIMIT, DatabaseSchemaMigrationGapError, DatabaseSchemaTooNewError, SCHEMA_META_SCHEMA_VERSION_KEY, XOPC_DB_BASELINE_SCHEMA_VERSION, XOPC_DB_FILENAME, XOPC_DB_SCHEMA_VERSION, acknowledgeHomeAttention, appendCompactionBoundaryIfUnchanged, appendComposerInputHistory, appendConnectorExecutionAudit, appendMemorySignal, appendMemoryTraceEvent, appendTranscriptEntry, applyPendingMigrations, attachMemoryEvidence, bindEndpointPrincipal, buildDefaultSessionMetadata, buildGlobalSessionStats, buildRelationshipPrompt, cancelQueuedSessionInput, claimConnectorWebhookDelivery, claimContextExtractionRun, claimKnowledgeSourceItems, claimNextConnectorLearningJob, claimNextSessionInput, classifyStoredRow, clearComposerInputHistory, closeTemporalAssertions, closeUnderstandingValidity, closeXopcDatabase, completeConnectorWebhookDelivery, completeKnowledgeSourceItemSynthesis, consumeConnectorApproval, consumeContextConsent, countKnowledgeSourceItems, countMemoryRecordsBySourceInstanceId, createCollaborationRule, createConnectorApproval, createContextEvidence, createEndpointPrincipal, createObjectLinkRecord, createTemporalAssertion, createUnderstanding, decideConnectorApproval, decideContextConsent, deleteCollaborationRule, deleteConnectorConnection, deleteConnectorInstallation, deleteKnowledgeSourceItems, deleteMemoryEvidenceForRecord, deleteMemoryRecord, deleteMemoryRecordsBySourceInstanceId, deleteNoteAgentContextRecord, deleteNoteRecord, deleteObjectLinkRecord, deleteSessionConfig, deleteSessionRecord, deleteUnderstanding, discoverSqlMigrations, enqueueConnectorLearningJob, ensureContextConsent, ensureSessionRecord, ensureXopcDatabaseSchema, estimateTokensFromMessages, extractFtsContent, findSessionInput, findSessionKeyBySessionId, finishContextConsolidationRun, finishContextExtractionRun, finishEndpointToolInvocationAudit, finishKnowledgeSyncRun, finishSessionInputRun, getActivityEventRecord, getCachedConnectorCatalogEntry, getCollaborationRule, getConnectorAccount, getConnectorApproval, getConnectorConnection, getConnectorInstallation, getConnectorSyncPolicy, getConnectorSyncPolicyForConnection, getContextConsolidationRun, getContextExtractionRun, getCurrentSessionId, getEndpointPrincipal, getGlobalSessionStats, getInteractionState, getKnowledgeConsumerWatermark, getKnowledgeSourceCursor, getKnowledgeSourceItem, getMemoryProviderState, getMemoryRecord, getMemoryTurnFeedback, getNoteAgentContextRecord, getNoteRecord, getRelationshipSettings, getSessionConfig, getSessionInputById, getSessionInputState, getSessionMetadata, getSessionPersistedLevels, getSessionTaskPlan, getSqliteDatabase, getTurnPersonalization, getUnderstanding, getUserProfile, getUserTrustPolicy, getXopcDatabase, hasContextConsent, hasIndependentExtractionOutput, hasSessionConfig, hasUnresolvedMemoryConflict, incrementSessionStatsOnAppend, insertSessionInput, inspectSchemaMigrationStatus, isHomeAttentionAcknowledged, isProactiveSupportAllowed, isUnderstandingSuppressed, isXopcDatabaseOpen, linkContextObjects, linkUnderstandingEvidence, listActivityRecords, listCachedConnectorCatalogEntries, listCollaborationRules, listCompactionBoundaries, listComposerInputHistory, listConnectorAccounts, listConnectorActionMetadata, listConnectorApprovals, listConnectorConnections, listConnectorExecutionAudit, listConnectorInstallations, listConnectorLearningJobs, listConnectorSyncPolicies, listContextConsolidationDecisions, listContextConsolidationRuns, listContextExtractionOutputs, listContextExtractionRuns, listContextObjectRelations, listEndpointPrincipals, listEndpointToolInvocationAudits, listKnowledgeSourceChanges, listKnowledgeSourceItems, listKnowledgeSyncRuns, listMemoryEvidence, listMemoryRecords, listMemorySignals, listMemoryTraceEvents, listNoteRecords, listObjectActivityRecords, listObjectLinkRecords, listProjectActivityRecords, listRegisteredMigrationTargets, listSessionMetadata, listSessionsByAgent, listTemporalAssertions, listUnderstandingEvidence, listUnderstandings, loadCompactionSourceSnapshot, loadLlmMessagesForSession, loadTranscriptHistoryRowsForSession, loadTranscriptRows, loadTranscriptRowsForSession, markMemoryRecordsConflicted, metadataToSessionInsert, mutateQueuedSessionInput, openXopcDatabase, paginateTranscriptMessages, patchSessionMetadata, pruneBoundedKnowledgeSourceItems, readSchemaVersion, readSchemaVersionForTest, reconcileConnectorAccount, recordActivityEvent, recordContextConsolidationDecision, recordContextFeedback, recordContextRun, recoverSessionInputState, recoverStaleConnectorLearningJobs, refreshConnectorAccountCurrent, rejectUnderstanding, releaseConnectorWebhookDelivery, replaceConnectorCatalogEntries, replaceLatestSessionTurnAndQueueInput, replaceTranscriptRows, requireXopcDatabase, resetSessionRecord, resetXopcDatabaseSingletonForTest, resolveMigrationsDir, resolveSessionAgentId, resolveXopcDatabasePath, restoreBeforeCompactionBoundary, reviseCollaborationRule, reviseUnderstanding, revokeEndpointPrincipal, runSqliteWriteTransaction, searchActiveUnderstandings, searchMemoryRecords, searchSessionTranscript, sessionConfigRowToConfig, sessionRowToMetadata, setCollaborationRuleStatus, setConnectorLearningPaused, setInteractionState, setKnowledgeConsumerWatermark, setKnowledgeSourceCursor, setKnowledgeSourceItemSynthesisStatus, setMemoryProviderState, setMemoryRecordStatus, setMemoryTurnFeedback, setSessionConfig, setSessionInputStatus, setSessionTaskPlan, setUnderstandingStatus, setUserTrustPolicy, startContextConsolidationRun, startEndpointToolInvocationAudit, startKnowledgeSyncRun, summarizeMemoryRecallFeedback, summarizeUnderstandingFeedback, summarizeUserUnderstandingQuality, touchEndpointPrincipal, transcriptEntryRowToStoredRow, updateConnectorLearningJob, updateInteractionStateFromMessage, updateRelationshipSettings, updateSessionConfig, updateSessionStats, updateUserProfile, upsertConnectorActionMetadata, upsertConnectorCatalogEntry, upsertConnectorConnection, upsertConnectorInstallation, upsertConnectorSyncPolicy, upsertKnowledgeSourceItems, upsertMemoryRecord, upsertNoteAgentContextRecord, upsertNoteRecord, validateLatestSessionTurnTarget };
39
+ export { COMPOSER_INPUT_HISTORY_LIMIT, DatabaseSchemaMigrationGapError, DatabaseSchemaTooNewError, SCHEMA_META_SCHEMA_VERSION_KEY, XOPC_DB_BASELINE_SCHEMA_VERSION, XOPC_DB_FILENAME, XOPC_DB_SCHEMA_VERSION, acknowledgeHomeAttention, appendCompactionBoundaryIfUnchanged, appendComposerInputHistory, appendConnectorExecutionAudit, appendMemorySignal, appendMemoryTraceEvent, appendTranscriptEntry, applyPendingMigrations, attachMemoryEvidence, bindEndpointPrincipal, buildDefaultSessionMetadata, buildGlobalSessionStats, buildRelationshipPrompt, cancelQueuedSessionInput, claimConnectorWebhookDelivery, claimContextExtractionRun, claimKnowledgeSourceItems, claimNextConnectorLearningJob, claimNextSessionInput, classifyStoredRow, clearComposerInputHistory, closeTemporalAssertions, closeUnderstandingValidity, closeXopcDatabase, completeConnectorWebhookDelivery, completeKnowledgeSourceItemSynthesis, consumeConnectorApproval, consumeContextConsent, countKnowledgeSourceItems, countMemoryRecordsBySourceInstanceId, createCollaborationRule, createConnectorApproval, createContextEvidence, createEndpointPrincipal, createObjectLinkRecord, createTemporalAssertion, createUnderstanding, decideConnectorApproval, decideContextConsent, deleteCollaborationRule, deleteConnectorConnection, deleteConnectorInstallation, deleteKnowledgeSourceItems, deleteMemoryEvidenceForRecord, deleteMemoryRecord, deleteMemoryRecordsBySourceInstanceId, deleteNoteAgentContextRecord, deleteNoteRecord, deleteObjectLinkRecord, deleteSessionConfig, deleteSessionRecord, deleteUnderstanding, discoverSqlMigrations, enqueueConnectorLearningJob, ensureContextConsent, ensureSessionRecord, ensureXopcDatabaseSchema, estimateTokensFromMessages, extractFtsContent, findSessionInput, findSessionKeyBySessionId, finishContextConsolidationRun, finishContextExtractionRun, finishEndpointToolInvocationAudit, finishKnowledgeSyncRun, finishSessionInputRun, getActivityEventRecord, getCachedConnectorCatalogEntry, getCollaborationRule, getConnectorAccount, getConnectorApproval, getConnectorConnection, getConnectorInstallation, getConnectorSyncPolicy, getConnectorSyncPolicyForConnection, getContextConsolidationRun, getContextExtractionRun, getCurrentSessionId, getEndpointPrincipal, getGlobalSessionStats, getInteractionState, getKnowledgeConsumerWatermark, getKnowledgeSourceCursor, getKnowledgeSourceItem, getMemoryProviderState, getMemoryRecord, getMemoryTurnFeedback, getNoteAgentContextRecord, getNoteRecord, getRelationshipSettings, getSessionConfig, getSessionInputById, getSessionInputState, getSessionMetadata, getSessionPersistedLevels, getSessionTaskPlan, getSqliteDatabase, getTurnPersonalization, getUnderstanding, getUserPeopleIndexState, getUserPerson, getUserProfile, getUserTrustPolicy, getXopcDatabase, hasContextConsent, hasIndependentExtractionOutput, hasSessionConfig, hasUnresolvedMemoryConflict, incrementSessionStatsOnAppend, insertSessionInput, inspectSchemaMigrationStatus, isHomeAttentionAcknowledged, isProactiveSupportAllowed, isUnderstandingSuppressed, isXopcDatabaseOpen, linkContextObjects, linkUnderstandingEvidence, listActivityRecords, listCachedConnectorCatalogEntries, listCollaborationRules, listCompactionBoundaries, listComposerInputHistory, listConnectorAccounts, listConnectorActionMetadata, listConnectorApprovals, listConnectorConnections, listConnectorExecutionAudit, listConnectorInstallations, listConnectorLearningJobs, listConnectorSyncPolicies, listContextConsolidationDecisions, listContextConsolidationRuns, listContextExtractionOutputs, listContextExtractionRuns, listContextObjectRelations, listEndpointPrincipals, listEndpointToolInvocationAudits, listKnowledgeSourceChanges, listKnowledgeSourceItems, listKnowledgeSyncRuns, listMemoryEvidence, listMemoryRecords, listMemorySignals, listMemoryTraceEvents, listNoteRecords, listObjectActivityRecords, listObjectLinkRecords, listProjectActivityRecords, listRegisteredMigrationTargets, listSessionMetadata, listSessionsByAgent, listTemporalAssertions, listUnderstandingEvidence, listUnderstandings, listUserPeople, loadCompactionSourceSnapshot, loadLlmMessagesForSession, loadTranscriptHistoryRowsForSession, loadTranscriptRows, loadTranscriptRowsForSession, markMemoryRecordsConflicted, mergeUserPeople, metadataToSessionInsert, mutateQueuedSessionInput, openXopcDatabase, paginateTranscriptMessages, patchSessionMetadata, pruneBoundedKnowledgeSourceItems, readSchemaVersion, readSchemaVersionForTest, reconcileConnectorAccount, recordActivityEvent, recordContextConsolidationDecision, recordContextFeedback, recordContextRun, recoverSessionInputState, recoverStaleConnectorLearningJobs, refreshConnectorAccountCurrent, rejectUnderstanding, releaseConnectorWebhookDelivery, replaceConnectorCatalogEntries, replaceLatestSessionTurnAndQueueInput, replaceTranscriptRows, replaceUserPeopleIndex, requireXopcDatabase, resetSessionRecord, resetXopcDatabaseSingletonForTest, resolveMigrationsDir, resolveSessionAgentId, resolveXopcDatabasePath, restoreBeforeCompactionBoundary, reviseCollaborationRule, reviseUnderstanding, revokeEndpointPrincipal, runSqliteWriteTransaction, searchActiveUnderstandings, searchMemoryRecords, searchSessionTranscript, sessionConfigRowToConfig, sessionRowToMetadata, setCollaborationRuleStatus, setConnectorLearningPaused, setInteractionState, setKnowledgeConsumerWatermark, setKnowledgeSourceCursor, setKnowledgeSourceItemSynthesisStatus, setMemoryProviderState, setMemoryRecordStatus, setMemoryTurnFeedback, setSessionConfig, setSessionInputStatus, setSessionTaskPlan, setUnderstandingStatus, setUserTrustPolicy, startContextConsolidationRun, startEndpointToolInvocationAudit, startKnowledgeSyncRun, summarizeMemoryRecallFeedback, summarizeUnderstandingFeedback, summarizeUserPeople, summarizeUserUnderstandingQuality, touchEndpointPrincipal, transcriptEntryRowToStoredRow, updateConnectorLearningJob, updateInteractionStateFromMessage, updateRelationshipSettings, updateSessionConfig, updateSessionStats, updateUserPerson, updateUserProfile, upsertConnectorActionMetadata, upsertConnectorCatalogEntry, upsertConnectorConnection, upsertConnectorInstallation, upsertConnectorSyncPolicy, upsertKnowledgeSourceItems, upsertMemoryRecord, upsertNoteAgentContextRecord, upsertNoteRecord, validateLatestSessionTurnTarget };
@@ -1,4 +1,4 @@
1
- import type { MemoryDisclosurePolicy, MemoryDurability, MemoryExplicitness, MemoryKind, MemoryRecord, MemorySensitivity, MemorySearchResult, MemorySignal, MemoryStatus } from '../../agent/memory/types.js';
1
+ import type { MemoryDisclosurePolicy, MemoryDurability, MemoryExplicitness, MemoryKind, MemoryOriginClass, MemoryRecord, MemorySessionKind, MemorySensitivity, MemorySearchResult, MemorySignal, MemoryStatus } from '../../agent/memory/types.js';
2
2
  export interface UpsertMemoryRecordInput {
3
3
  id?: string;
4
4
  providerId: string;
@@ -26,6 +26,13 @@ export interface UpsertMemoryRecordInput {
26
26
  expiresAt?: string;
27
27
  supersedesRecordId?: string;
28
28
  conflictGroupId?: string;
29
+ originClass?: MemoryOriginClass;
30
+ sessionKind?: MemorySessionKind;
31
+ observedAt?: string;
32
+ sourceSessionId?: string;
33
+ sourceTurnId?: string;
34
+ supersedesKey?: string;
35
+ derivedFromRecalledContext?: boolean;
29
36
  nowMs?: number;
30
37
  }
31
38
  export interface ListMemoryRecordsOptions {
@@ -73,6 +80,7 @@ export interface SearchMemoryRecordsOptions {
73
80
  statuses?: MemoryStatus[];
74
81
  maxResults?: number;
75
82
  minScore?: number;
83
+ trustedOnly?: boolean;
76
84
  }
77
85
  export interface AppendMemorySignalInput {
78
86
  signal: MemorySignal;
@@ -86,7 +86,16 @@ function rowToRecord(row, evidence = []) {
86
86
  ...row.session_key ? { sessionKey: row.session_key } : {},
87
87
  ...row.project_id ? { projectId: row.project_id } : {}
88
88
  },
89
- provenance: { sourceAgentId: row.source_agent_id },
89
+ provenance: {
90
+ sourceAgentId: row.source_agent_id,
91
+ originClass: row.origin_class,
92
+ sessionKind: row.session_kind,
93
+ observedAt: new Date(row.observed_at).toISOString(),
94
+ ...row.source_session_id ? { sourceSessionId: row.source_session_id } : {},
95
+ ...row.source_turn_id ? { sourceTurnId: row.source_turn_id } : {},
96
+ ...row.supersedes_key ? { supersedesKey: row.supersedes_key } : {},
97
+ derivedFromRecalledContext: row.derived_from_recalled_context === 1
98
+ },
90
99
  content: row.content,
91
100
  source: parseSource(row.source_json),
92
101
  ...row.confidence != null ? { confidence: row.confidence } : {},
@@ -131,6 +140,9 @@ function upsertMemoryRecord(input) {
131
140
  const validTo = parseOptionalTimestamp(input.validTo);
132
141
  const reviewAfter = parseOptionalTimestamp(input.reviewAfter);
133
142
  const expiresAt = parseOptionalTimestamp(input.expiresAt);
143
+ const observedAt = parseOptionalTimestamp(input.observedAt) ?? now;
144
+ const originClass = input.originClass ?? "untrusted";
145
+ const sessionKind = input.sessionKind ?? "unknown";
134
146
  const source = {
135
147
  ...input.source ?? {},
136
148
  provider: input.source?.provider ?? input.providerId
@@ -141,8 +153,10 @@ function upsertMemoryRecord(input) {
141
153
  content, source_json, confidence, tags_json, status, sensitivity,
142
154
  canonical_key, explicitness, durability, importance,
143
155
  disclosure_policy, valid_from, valid_to, review_after, expires_at,
144
- supersedes_record_id, conflict_group_id, created_at, updated_at
145
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
156
+ supersedes_record_id, conflict_group_id,
157
+ origin_class, session_kind, observed_at, source_session_id, source_turn_id,
158
+ supersedes_key, derived_from_recalled_context, created_at, updated_at
159
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
146
160
  ON CONFLICT(record_id) DO UPDATE SET
147
161
  provider_id = excluded.provider_id,
148
162
  kind = excluded.kind,
@@ -168,7 +182,14 @@ function upsertMemoryRecord(input) {
168
182
  expires_at = excluded.expires_at,
169
183
  supersedes_record_id = excluded.supersedes_record_id,
170
184
  conflict_group_id = excluded.conflict_group_id,
171
- updated_at = excluded.updated_at`).run(id, input.providerId, input.kind, input.userId ?? "local-owner", input.sourceAgentId, input.workspaceId ?? null, input.sessionKey ?? null, input.projectId ?? null, input.content, JSON.stringify(source), input.confidence ?? null, JSON.stringify(input.tags ?? []), status, sensitivity, input.canonicalKey ?? null, explicitness, durability, importance, disclosurePolicy, validFrom, validTo, reviewAfter, expiresAt, input.supersedesRecordId ?? null, input.conflictGroupId ?? null, now, now);
185
+ origin_class = excluded.origin_class,
186
+ session_kind = excluded.session_kind,
187
+ observed_at = excluded.observed_at,
188
+ source_session_id = excluded.source_session_id,
189
+ source_turn_id = excluded.source_turn_id,
190
+ supersedes_key = excluded.supersedes_key,
191
+ derived_from_recalled_context = excluded.derived_from_recalled_context,
192
+ updated_at = excluded.updated_at`).run(id, input.providerId, input.kind, input.userId ?? "local-owner", input.sourceAgentId, input.workspaceId ?? null, input.sessionKey ?? null, input.projectId ?? null, input.content, JSON.stringify(source), input.confidence ?? null, JSON.stringify(input.tags ?? []), status, sensitivity, input.canonicalKey ?? null, explicitness, durability, importance, disclosurePolicy, validFrom, validTo, reviewAfter, expiresAt, input.supersedesRecordId ?? null, input.conflictGroupId ?? null, originClass, sessionKind, observedAt, input.sourceSessionId ?? null, input.sourceTurnId ?? null, input.supersedesKey ?? null, input.derivedFromRecalledContext ? 1 : 0, now, now);
172
193
  upsertMemoryRecordFts(db, {
173
194
  ...input,
174
195
  id
@@ -204,7 +225,16 @@ function upsertMemoryRecord(input) {
204
225
  ...input.sessionKey ? { sessionKey: input.sessionKey } : {},
205
226
  ...input.projectId ? { projectId: input.projectId } : {}
206
227
  },
207
- provenance: { sourceAgentId: input.sourceAgentId },
228
+ provenance: {
229
+ sourceAgentId: input.sourceAgentId,
230
+ originClass,
231
+ sessionKind,
232
+ observedAt: new Date(observedAt).toISOString(),
233
+ ...input.sourceSessionId ? { sourceSessionId: input.sourceSessionId } : {},
234
+ ...input.sourceTurnId ? { sourceTurnId: input.sourceTurnId } : {},
235
+ ...input.supersedesKey ? { supersedesKey: input.supersedesKey } : {},
236
+ derivedFromRecalledContext: input.derivedFromRecalledContext ?? false
237
+ },
208
238
  content: input.content,
209
239
  source,
210
240
  ...input.confidence != null ? { confidence: input.confidence } : {},
@@ -339,6 +369,10 @@ function searchMemoryRecords(options) {
339
369
  filters.push(`f.kind IN (${options.kinds.map(() => "?").join(", ")})`);
340
370
  params.push(...options.kinds);
341
371
  }
372
+ if (options.trustedOnly) {
373
+ filters.push(`r.origin_class IN ('owner', 'agent')`);
374
+ filters.push("r.derived_from_recalled_context = 0");
375
+ }
342
376
  const statuses = options.statuses && options.statuses.length > 0 ? options.statuses : ["active"];
343
377
  filters.push(`r.status IN (${statuses.map(() => "?").join(", ")})`);
344
378
  params.push(...statuses);
@@ -366,7 +400,7 @@ function searchMemoryRecords(options) {
366
400
  visibleToWorkspaceId: options.visibleToWorkspaceId,
367
401
  unscopedWorkspaceOnly: options.unscopedWorkspaceOnly,
368
402
  limit: 500
369
- }).filter((record) => statuses.includes(record.status ?? "active") && (!options.kinds?.length || options.kinds.includes(record.kind)));
403
+ }).filter((record) => statuses.includes(record.status ?? "active") && (!options.kinds?.length || options.kinds.includes(record.kind))).filter((record) => !options.trustedOnly || (record.provenance.originClass === "owner" || record.provenance.originClass === "agent") && !record.provenance.derivedFromRecalledContext);
370
404
  const candidateById = new Map(candidateRecords.map((record) => [record.id, record]));
371
405
  const missingRows = rows.filter((row) => !candidateById.has(row.record_id));
372
406
  const missingEvidence = listMemoryEvidenceForRecords(missingRows.map((row) => row.record_id));
@@ -0,0 +1,18 @@
1
+ ALTER TABLE memory_records ADD COLUMN origin_class TEXT NOT NULL DEFAULT 'untrusted'
2
+ CHECK (origin_class IN ('owner', 'agent', 'untrusted', 'system'));
3
+ ALTER TABLE memory_records ADD COLUMN session_kind TEXT NOT NULL DEFAULT 'unknown'
4
+ CHECK (session_kind IN ('interactive', 'group', 'automation', 'workflow', 'subagent', 'background', 'unknown'));
5
+ ALTER TABLE memory_records ADD COLUMN observed_at INTEGER NOT NULL DEFAULT 0;
6
+ ALTER TABLE memory_records ADD COLUMN source_session_id TEXT;
7
+ ALTER TABLE memory_records ADD COLUMN source_turn_id TEXT;
8
+ ALTER TABLE memory_records ADD COLUMN supersedes_key TEXT;
9
+ ALTER TABLE memory_records ADD COLUMN derived_from_recalled_context INTEGER NOT NULL DEFAULT 0
10
+ CHECK (derived_from_recalled_context IN (0, 1));
11
+
12
+ UPDATE memory_records
13
+ SET observed_at = CASE WHEN observed_at = 0 THEN created_at ELSE observed_at END;
14
+
15
+ CREATE INDEX idx_memory_records_trusted_scope_updated
16
+ ON memory_records(origin_class, derived_from_recalled_context, status, workspace_id, updated_at DESC);
17
+ CREATE INDEX idx_memory_records_source_turn
18
+ ON memory_records(source_session_id, source_turn_id);
@@ -0,0 +1,59 @@
1
+ CREATE TABLE user_people (
2
+ person_id TEXT PRIMARY KEY,
3
+ principal_id TEXT NOT NULL,
4
+ display_name TEXT NOT NULL,
5
+ user_display_name TEXT,
6
+ inferred_kind TEXT NOT NULL CHECK (inferred_kind IN ('person', 'bot', 'service', 'group', 'unknown')),
7
+ user_kind TEXT CHECK (user_kind IS NULL OR user_kind IN ('person', 'bot', 'service', 'group', 'unknown')),
8
+ hidden INTEGER NOT NULL DEFAULT 0 CHECK (hidden IN (0, 1)),
9
+ merged_into_person_id TEXT REFERENCES user_people(person_id) ON DELETE SET NULL,
10
+ confidence REAL NOT NULL CHECK (confidence >= 0 AND confidence <= 1),
11
+ first_observed_at INTEGER NOT NULL,
12
+ last_observed_at INTEGER NOT NULL,
13
+ created_at INTEGER NOT NULL,
14
+ updated_at INTEGER NOT NULL
15
+ );
16
+
17
+ CREATE INDEX idx_user_people_principal_kind
18
+ ON user_people(principal_id, inferred_kind, last_observed_at DESC);
19
+ CREATE INDEX idx_user_people_merge_target
20
+ ON user_people(merged_into_person_id);
21
+
22
+ CREATE TABLE user_person_handles (
23
+ handle_id TEXT PRIMARY KEY,
24
+ person_id TEXT NOT NULL REFERENCES user_people(person_id) ON DELETE CASCADE,
25
+ handle_type TEXT NOT NULL CHECK (handle_type IN ('email', 'provider_user', 'username', 'display_name')),
26
+ normalized_value TEXT NOT NULL,
27
+ display_value TEXT NOT NULL,
28
+ source_instance_id TEXT NOT NULL,
29
+ verification TEXT NOT NULL CHECK (verification IN ('observed', 'inferred', 'user_confirmed')),
30
+ first_observed_at INTEGER NOT NULL,
31
+ last_observed_at INTEGER NOT NULL,
32
+ created_at INTEGER NOT NULL,
33
+ updated_at INTEGER NOT NULL,
34
+ UNIQUE(handle_type, normalized_value, source_instance_id)
35
+ );
36
+
37
+ CREATE INDEX idx_user_person_handles_person ON user_person_handles(person_id);
38
+ CREATE INDEX idx_user_person_handles_lookup ON user_person_handles(handle_type, normalized_value);
39
+
40
+ CREATE TABLE user_person_source_stats (
41
+ person_id TEXT NOT NULL REFERENCES user_people(person_id) ON DELETE CASCADE,
42
+ source_instance_id TEXT NOT NULL,
43
+ interaction_count INTEGER NOT NULL CHECK (interaction_count >= 0),
44
+ first_observed_at INTEGER NOT NULL,
45
+ last_observed_at INTEGER NOT NULL,
46
+ last_source_item_id TEXT,
47
+ updated_at INTEGER NOT NULL,
48
+ PRIMARY KEY(person_id, source_instance_id)
49
+ );
50
+
51
+ CREATE INDEX idx_user_person_source_stats_source
52
+ ON user_person_source_stats(source_instance_id, last_observed_at DESC);
53
+
54
+ CREATE TABLE user_people_index_state (
55
+ principal_id TEXT PRIMARY KEY,
56
+ source_change_sequence INTEGER NOT NULL,
57
+ source_grants_updated_at INTEGER NOT NULL,
58
+ rebuilt_at INTEGER NOT NULL
59
+ );
@@ -3,7 +3,7 @@ import type { ApplyMigrationsOptions } from './types.js';
3
3
  /** Baseline schema version applied from schema.sql on first open. */
4
4
  export declare const XOPC_DB_BASELINE_SCHEMA_VERSION = 11;
5
5
  /** Latest schema version this release supports (increment when adding migrations). */
6
- export declare const XOPC_DB_SCHEMA_VERSION = 133;
6
+ export declare const XOPC_DB_SCHEMA_VERSION = 135;
7
7
  export declare function resolveMigrationsDir(override?: string): string;
8
8
  /**
9
9
  * Apply sequential SQL migrations from (currentVersion + 1) through targetVersion.
@@ -12,7 +12,7 @@ const log = createLogger("Sqlite:Migrations");
12
12
  /** Baseline schema version applied from schema.sql on first open. */
13
13
  const XOPC_DB_BASELINE_SCHEMA_VERSION = 11;
14
14
  /** Latest schema version this release supports (increment when adding migrations). */
15
- const XOPC_DB_SCHEMA_VERSION = 133;
15
+ const XOPC_DB_SCHEMA_VERSION = 135;
16
16
  const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
17
17
  function backupBeforeTaskCutover(db, databasePath) {
18
18
  db.exec("PRAGMA wal_checkpoint(FULL)");
@@ -57,7 +57,7 @@ function applySingleMigration(db, migration) {
57
57
  * Each step runs in its own transaction and updates schema_meta on success.
58
58
  */
59
59
  function applyPendingMigrations(db, options = {}) {
60
- const targetVersion = options.targetVersion ?? 133;
60
+ const targetVersion = options.targetVersion ?? 135;
61
61
  let currentVersion = readSchemaVersion(db);
62
62
  if (currentVersion > targetVersion) throw new DatabaseSchemaTooNewError(currentVersion, targetVersion);
63
63
  if (currentVersion >= targetVersion) return currentVersion;
@@ -94,7 +94,7 @@ function applyPendingMigrations(db, options = {}) {
94
94
  }
95
95
  /** Inspect schema version without mutating the database. */
96
96
  function inspectSchemaMigrationStatus(db, options = {}) {
97
- const appVersion = options.targetVersion ?? 133;
97
+ const appVersion = options.targetVersion ?? 135;
98
98
  const dbVersion = readSchemaVersion(db);
99
99
  if (dbVersion > appVersion) return {
100
100
  dbVersion,
@@ -19,7 +19,7 @@ const log = createLogger('Sqlite:Migrations');
19
19
  export const XOPC_DB_BASELINE_SCHEMA_VERSION = 11;
20
20
 
21
21
  /** Latest schema version this release supports (increment when adding migrations). */
22
- export const XOPC_DB_SCHEMA_VERSION = 133;
22
+ export const XOPC_DB_SCHEMA_VERSION = 135;
23
23
 
24
24
  const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
25
25
 
@@ -32,7 +32,7 @@ function ensureXopcDatabaseSchema(db, options = {}) {
32
32
  currentVersion = 11;
33
33
  }
34
34
  applyPendingMigrations(db, {
35
- targetVersion: 133,
35
+ targetVersion: 135,
36
36
  databasePath: options.databasePath
37
37
  });
38
38
  }
@@ -0,0 +1,32 @@
1
+ import type { UserPerson, UserPersonIndexEntry, UserPersonKind, UserRelationshipSummary } from '../../user-context/relationships/types.js';
2
+ export declare function replaceUserPeopleIndex(entries: UserPersonIndexEntry[], revision: {
3
+ sourceChangeSequence: number;
4
+ sourceGrantsUpdatedAt: number;
5
+ }, principalId?: string, nowMs?: number): void;
6
+ export declare function getUserPeopleIndexState(principalId?: string): {
7
+ sourceChangeSequence: number;
8
+ sourceGrantsUpdatedAt: number;
9
+ rebuiltAt: number;
10
+ } | null;
11
+ export declare function listUserPeople(options?: {
12
+ query?: string;
13
+ kind?: UserPersonKind;
14
+ sourceInstanceId?: string;
15
+ includeHidden?: boolean;
16
+ hiddenOnly?: boolean;
17
+ offset?: number;
18
+ limit?: number;
19
+ principalId?: string;
20
+ }): {
21
+ items: UserPerson[];
22
+ total: number;
23
+ nextOffset?: number;
24
+ };
25
+ export declare function getUserPerson(personId: string, principalId?: string): UserPerson | null;
26
+ export declare function updateUserPerson(personId: string, patch: {
27
+ displayName?: string | null;
28
+ kind?: UserPersonKind | null;
29
+ hidden?: boolean;
30
+ }, principalId?: string): UserPerson | null;
31
+ export declare function summarizeUserPeople(principalId?: string): UserRelationshipSummary;
32
+ export declare function mergeUserPeople(sourcePersonId: string, targetPersonId: string, principalId?: string): UserPerson | null;