@xopcai/xopc 0.0.218 → 0.0.220

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 (342) hide show
  1. package/dist/browser-ext/manifest.json +1 -1
  2. package/dist/extensions/telegram/xopc.extension.json +1 -1
  3. package/dist/gateway/static/root/assets/{activity-store-DF2dYXG1.js → activity-store-DeKZ36Jy.js} +1 -1
  4. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-Dw9rF5o1.js → agent-avatar-dicebear-D0hZfdkn.js} +1 -1
  5. package/dist/gateway/static/root/assets/agents-Bu0NfWuh.js +68 -0
  6. package/dist/gateway/static/root/assets/{api-_H0Bam-t.js → api-yLnYUedB.js} +1 -1
  7. package/dist/gateway/static/root/assets/app-management-settings-panel-C2kZNEHz.js +1 -0
  8. package/dist/gateway/static/root/assets/appearance-settings-DQ7H35sN.js +1 -0
  9. package/dist/gateway/static/root/assets/apps-page-Tty2xaUG.js +1 -0
  10. package/dist/gateway/static/root/assets/{archive-plugin-DZCOhXch.js → archive-plugin-CBArbTPH.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-Bjb0FH2B.js → attachment-load-oc6DRj4G.js} +1 -1
  12. package/dist/gateway/static/root/assets/{automations-page-D4N3ZDhu.js → automations-page-CHPEUpz8.js} +1 -1
  13. package/dist/gateway/static/root/assets/automations-workspace-9uYkHmdI.js +6 -0
  14. package/dist/gateway/static/root/assets/{binary-plugins-uXPt0s47.js → binary-plugins-BRBd0X7_.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-gukkIEro.js → block-editor-ZgM-Z4Qv.js} +47 -47
  16. package/dist/gateway/static/root/assets/browser-settings-page-BT3mEm00.js +8 -0
  17. package/dist/gateway/static/root/assets/{browser-workflow-inputs-DAhdS-XZ.js → browser-workflow-inputs-DxD74a4c.js} +1 -1
  18. package/dist/gateway/static/root/assets/{browser-workflows-page-LKjYzXS_.js → browser-workflows-page-Dpc7NqZf.js} +2 -2
  19. package/dist/gateway/static/root/assets/capabilities-settings-panel-DHlfRj4M.js +7 -0
  20. package/dist/gateway/static/root/assets/{capability-presets-api-BBUkH833.js → capability-presets-api-B9ID97j6.js} +1 -1
  21. package/dist/gateway/static/root/assets/capability-presets-settings-panel-D2FkREUX.js +3 -0
  22. package/dist/gateway/static/root/assets/{channel-recipient-api-E5mo8M3a.js → channel-recipient-api-DCNn6MWL.js} +1 -1
  23. package/dist/gateway/static/root/assets/channels-settings-D4YcKMtf.js +1 -0
  24. package/dist/gateway/static/root/assets/channels-status-swr-B8XWrzKM.js +1 -0
  25. package/dist/gateway/static/root/assets/chat-terminal-dock-MvNpjcUs.js +36 -0
  26. package/dist/gateway/static/root/assets/connectors-page-Bd6K9bDk.js +2 -0
  27. package/dist/gateway/static/root/assets/{cron-expression-BGNuaqvI.js → cron-expression-BSXX9uY0.js} +1 -1
  28. package/dist/gateway/static/root/assets/{date-picker-k7mkklMU.js → date-picker-CiHNkkIS.js} +1 -1
  29. package/dist/gateway/static/root/assets/dependency-picker-DQyh2ZXE.js +1 -0
  30. package/dist/gateway/static/root/assets/{desktop-pet-p9EZyGzV.js → desktop-pet-DnAHU-zA.js} +1 -1
  31. package/dist/gateway/static/root/assets/desktop-pet-settings-DUdhIBBB.js +1 -0
  32. package/dist/gateway/static/root/assets/directory-picker-path-field-B3gFQt8x.js +1 -0
  33. package/dist/gateway/static/root/assets/ellipsis-0k4rZLoy.js +1 -0
  34. package/dist/gateway/static/root/assets/{extension-debug-page-Cd4BMKm_.js → extension-debug-page-Lq-gRApw.js} +1 -1
  35. package/dist/gateway/static/root/assets/{extension-page-CzEGCkOa.js → extension-page-D0ROxJmY.js} +1 -1
  36. package/dist/gateway/static/root/assets/extension-settings-page-B2tS6mFy.js +1 -0
  37. package/dist/gateway/static/root/assets/eye-CABVeTq0.js +1 -0
  38. package/dist/gateway/static/root/assets/eye-off-DEAzt3g1.js +1 -0
  39. package/dist/gateway/static/root/assets/file-code-corner-byQA1VfD.js +1 -0
  40. package/dist/gateway/static/root/assets/form-field-width-DJw_jULe.js +1 -0
  41. package/dist/gateway/static/root/assets/gateway-config-api-DJqWfVi6.js +1 -0
  42. package/dist/gateway/static/root/assets/{gateway-config-swr-DNrttVr2.js → gateway-config-swr-CnwF9Vso.js} +1 -1
  43. package/dist/gateway/static/root/assets/gateway-settings-B3thenPX.js +1 -0
  44. package/dist/gateway/static/root/assets/{gateway-startup-retry-B1vD3vRb.js → gateway-startup-retry-DdJJZR8M.js} +1 -1
  45. package/dist/gateway/static/root/assets/heartbeat-settings-C_g-ZGSE.js +1 -0
  46. package/dist/gateway/static/root/assets/home-page-Cgwx66kc.js +1 -0
  47. package/dist/gateway/static/root/assets/{image-generation-api-BTR0Wk_k.js → image-generation-api-Dtt9M5qz.js} +1 -1
  48. package/dist/gateway/static/root/assets/index-Cf0qTkBK.css +2 -0
  49. package/dist/gateway/static/root/assets/index-V9g9-SWT.js +108 -0
  50. package/dist/gateway/static/root/assets/interaction-BmQogeqz.js +1 -0
  51. package/dist/gateway/static/root/assets/is-masked-secret-DOkL5b_X.js +1 -0
  52. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-CYlS4RGA.js → keyboard-shortcuts-settings-cJqkmQdP.js} +1 -1
  53. package/dist/gateway/static/root/assets/local-app-workbench-page-CmjLMdly.js +2 -0
  54. package/dist/gateway/static/root/assets/{local-apps-page-CNppYVew.js → local-apps-page-BiuP2pkl.js} +1 -1
  55. package/dist/gateway/static/root/assets/{locale-store-gf9Bg2gb.js → locale-store-D3Q2yEAb.js} +1 -1
  56. package/dist/gateway/static/root/assets/logs-page-BTlxGPho.js +2 -0
  57. package/dist/gateway/static/root/assets/{management-settings-IYk9xLgt.js → management-settings-Z1gJUwP_.js} +1 -1
  58. package/dist/gateway/static/root/assets/{markdown-split-D8e6pRMH.js → markdown-split-DuOmpGgE.js} +1 -1
  59. package/dist/gateway/static/root/assets/{markdown-view-D0fiJjBQ.js → markdown-view-WYArkdrc.js} +1 -1
  60. package/dist/gateway/static/root/assets/{media-plugins-CCq6TtEf.js → media-plugins-DKPh3Mud.js} +1 -1
  61. package/dist/gateway/static/root/assets/messages-BQHpB4VI.js +3 -0
  62. package/dist/gateway/static/root/assets/{notes-api-BBtWnlUU.js → notes-api-DMEon7Zv.js} +1 -1
  63. package/dist/gateway/static/root/assets/{notes-page-BKe1xa3U.js → notes-page-BG4gV8WG.js} +1 -1
  64. package/dist/gateway/static/root/assets/notes-workbench-D3LMBO2X.js +4 -0
  65. package/dist/gateway/static/root/assets/page-tabs-BaEQMYm_.js +1 -0
  66. package/dist/gateway/static/root/assets/preview-open-alternatives-CsNVTKC0.js +1 -0
  67. package/dist/gateway/static/root/assets/{product-open-page-DXe5iWI6.js → product-open-page-BjJf4QOB.js} +1 -1
  68. package/dist/gateway/static/root/assets/project-detail-page-C59tYJG-.js +1 -0
  69. package/dist/gateway/static/root/assets/projects-page-Di7W-Fg8.js +1 -0
  70. package/dist/gateway/static/root/assets/{registry-api-xj5gOva_.js → registry-api-DRyvynb5.js} +1 -1
  71. package/dist/gateway/static/root/assets/remote-access-hub-BYOKveWT.js +1 -0
  72. package/dist/gateway/static/root/assets/rotate-cw-LIg3Am9S.js +1 -0
  73. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-BJTvmBCA.js → runtime-tools-settings-panel-DC6t_-db.js} +2 -2
  74. package/dist/gateway/static/root/assets/{schema-form-DvGBa_7R.js → schema-form-DSTWtpjp.js} +1 -1
  75. package/dist/gateway/static/root/assets/search-DA7gz22f.js +1 -0
  76. package/dist/gateway/static/root/assets/sessions-page-CJMNQsxK.js +1 -0
  77. package/dist/gateway/static/root/assets/settings-advanced-gate-FJxZw08y.js +1 -0
  78. package/dist/gateway/static/root/assets/settings-form-section-ZzEMNLYS.js +1 -0
  79. package/dist/gateway/static/root/assets/{settings-loading-skeleton-sbef7GTm.js → settings-loading-skeleton-D7-bkbcW.js} +1 -1
  80. package/dist/gateway/static/root/assets/{settings-page-BNGxxXZe.js → settings-page-PaTpLbmi.js} +1 -1
  81. package/dist/gateway/static/root/assets/setup-status-panel-Bnpim6NY.js +1 -0
  82. package/dist/gateway/static/root/assets/{share-preview-page-C1523ij3.js → share-preview-page-Cxcw0ksa.js} +1 -1
  83. package/dist/gateway/static/root/assets/shares-settings-DBqmV7ZY.js +1 -0
  84. package/dist/gateway/static/root/assets/skill-reload-api-UgLQaWoz.js +1 -0
  85. package/dist/gateway/static/root/assets/skills-page-Dby4iAYe.js +2 -0
  86. package/dist/gateway/static/root/assets/{skills-page.utils-Ditgz7Vo.js → skills-page.utils-nlzJ5Y1V.js} +1 -1
  87. package/dist/gateway/static/root/assets/system-settings-panel-vOsgnzDl.js +1 -0
  88. package/dist/gateway/static/root/assets/task-detail-page-CRy8Wl5g.js +1 -0
  89. package/dist/gateway/static/root/assets/{theme-store-DgSjes3O.js → theme-store-CvnEHGyP.js} +1 -1
  90. package/dist/gateway/static/root/assets/typed-models-lib-q5-Vfqd8.js +1 -0
  91. package/dist/gateway/static/root/assets/{use-autosave-Bp_qFZkl.js → use-autosave-BTNZHulv.js} +1 -1
  92. package/dist/gateway/static/root/assets/user-context-page-BT8F4mh5.js +1 -0
  93. package/dist/gateway/static/root/assets/{voice-api-key-field-hbzDfErG.js → voice-api-key-field-DDJ2-3Tx.js} +1 -1
  94. package/dist/gateway/static/root/assets/{work-discovery-overlay-DZVib-04.js → work-discovery-overlay-DV_qiKSD.js} +1 -1
  95. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-C2RKay1p.js → workflow-run-setup-panel--AcvRw1w.js} +2 -2
  96. package/dist/gateway/static/root/assets/workflows-page-CwvskVvU.js +5 -0
  97. package/dist/gateway/static/root/index.html +21 -12
  98. package/dist/package.js +1 -1
  99. package/dist/packages/gateway-contract/src/new-session.js +99 -0
  100. package/dist/packages/gateway-contract/src/tasks.js +5 -0
  101. package/dist/packages/gateway-contract/src/user-message-display.js +55 -0
  102. package/dist/src/agent/agent-manager.js +5 -4
  103. package/dist/src/agent/background-review/prompts.d.ts +1 -1
  104. package/dist/src/agent/background-review/prompts.js +2 -2
  105. package/dist/src/agent/background-review/run-background-review.js +144 -16
  106. package/dist/src/agent/embedded/model-runtime.js +1 -1
  107. package/dist/src/agent/embedded/run-for-session.js +1 -1
  108. package/dist/src/agent/image/tool-model-config.js +1 -1
  109. package/dist/src/agent/inbound/turn-dispatcher.d.ts +3 -1
  110. package/dist/src/agent/inbound/turn-dispatcher.js +2 -1
  111. package/dist/src/agent/ipc/inbox.js +1 -1
  112. package/dist/src/agent/memory/context/types.d.ts +1 -1
  113. package/dist/src/agent/memory/manager.d.ts +2 -1
  114. package/dist/src/agent/memory/manager.js +2 -6
  115. package/dist/src/agent/memory/understanding/service.d.ts +1 -0
  116. package/dist/src/agent/memory/understanding/service.js +179 -36
  117. package/dist/src/agent/memory/understanding/types.d.ts +6 -0
  118. package/dist/src/agent/messaging/command-handler.d.ts +2 -0
  119. package/dist/src/agent/messaging/command-handler.js +3 -1
  120. package/dist/src/agent/service/direct-turn-helpers.d.ts +3 -0
  121. package/dist/src/agent/service/direct-turn-helpers.js +13 -3
  122. package/dist/src/agent/service/process-direct-streaming.d.ts +2 -1
  123. package/dist/src/agent/service/process-direct-streaming.js +12 -11
  124. package/dist/src/agent/service.js +2 -2
  125. package/dist/src/agent/session/session-config-service.d.ts +1 -0
  126. package/dist/src/agent/session/session-config-service.js +11 -0
  127. package/dist/src/agent/session/session-inspector.d.ts +1 -0
  128. package/dist/src/agent/session/session-inspector.js +2 -1
  129. package/dist/src/agent/skills/hub-lock.js +1 -1
  130. package/dist/src/agent/source-context/budget.d.ts +3 -0
  131. package/dist/src/agent/source-context/budget.js +21 -0
  132. package/dist/src/agent/source-context/index.js +3 -3
  133. package/dist/src/agent/source-context/injector.d.ts +2 -2
  134. package/dist/src/agent/source-context/injector.js +19 -9
  135. package/dist/src/agent/source-context/types.d.ts +16 -0
  136. package/dist/src/agent/source-context/types.js +25 -1
  137. package/dist/src/agent/tasks/task-judge-service.js +3 -3
  138. package/dist/src/agent/tool-manuals/xopc-use.d.ts +1 -1
  139. package/dist/src/agent/tool-manuals/xopc-use.js +19 -2
  140. package/dist/src/agent/tools/xopc-use-tool.js +62 -2
  141. package/dist/src/ai-assist/text-assist.js +1 -1
  142. package/dist/src/auth/credentials.js +2 -2
  143. package/dist/src/auth/profiles/store.js +1 -1
  144. package/dist/src/auth/sync-provider-auth.js +2 -2
  145. package/dist/src/browser/backend-from-config.d.ts +8 -0
  146. package/dist/src/browser/backend-from-config.js +16 -1
  147. package/dist/src/browser/providers/browser-ext-install.d.ts +3 -2
  148. package/dist/src/browser/providers/browser-ext-install.js +5 -3
  149. package/dist/src/chat-commands/builtins/review.js +11 -2
  150. package/dist/src/chat-commands/builtins/understanding.js +11 -4
  151. package/dist/src/chat-commands/types.d.ts +4 -0
  152. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  153. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
  154. package/dist/src/cli/commands/models.js +1 -1
  155. package/dist/src/config/index.js +4 -4
  156. package/dist/src/config/loader.js +1 -1
  157. package/dist/src/config/models-json.d.ts +20 -20
  158. package/dist/src/config/models-json.js +1 -1
  159. package/dist/src/connectors/connected-source-understanding.d.ts +1 -0
  160. package/dist/src/connectors/connected-source-understanding.js +87 -38
  161. package/dist/src/connectors/learning-coordinator.js +68 -13
  162. package/dist/src/extensions/lockfile.js +1 -1
  163. package/dist/src/gateway/agents-admin.js +1 -1
  164. package/dist/src/gateway/chat-stream/mapper.js +18 -0
  165. package/dist/src/gateway/file-path-classifier.js +1 -1
  166. package/dist/src/gateway/hono/lib/config-payload.js +1 -1
  167. package/dist/src/gateway/hono/routes/agent-stream.js +12 -2
  168. package/dist/src/gateway/hono/routes/commands-skills.js +1 -0
  169. package/dist/src/gateway/hono/routes/models.js +1 -1
  170. package/dist/src/gateway/hono/routes/session-input-handler.d.ts +46 -2
  171. package/dist/src/gateway/hono/routes/session-input-handler.js +23 -3
  172. package/dist/src/gateway/hono/routes/sessions.js +17 -20
  173. package/dist/src/gateway/hono/routes/tasks.js +25 -0
  174. package/dist/src/gateway/hono/routes/understanding-sources.d.ts +18 -0
  175. package/dist/src/gateway/hono/routes/understanding-sources.js +165 -36
  176. package/dist/src/gateway/hono/routes/work-discovery.js +13 -3
  177. package/dist/src/gateway/hono/routes/workflows.js +2 -2
  178. package/dist/src/gateway/hono/routes/you.js +71 -4
  179. package/dist/src/gateway/service/agent-runner.d.ts +11 -2
  180. package/dist/src/gateway/service/agent-runner.js +27 -1
  181. package/dist/src/gateway/service/config-coordinator.js +1 -1
  182. package/dist/src/gateway/service/run-gateway-agent.d.ts +2 -0
  183. package/dist/src/gateway/service/run-gateway-agent.js +15 -9
  184. package/dist/src/gateway/service/session-input-coordinator.d.ts +8 -2
  185. package/dist/src/gateway/service/session-input-coordinator.js +62 -3
  186. package/dist/src/gateway/service/sessions-api.d.ts +10 -0
  187. package/dist/src/gateway/service/sessions-api.js +3 -0
  188. package/dist/src/gateway/service.d.ts +3 -2
  189. package/dist/src/gateway/service.js +27 -16
  190. package/dist/src/gateway/user-turn-input.d.ts +2 -0
  191. package/dist/src/gateway/xopc-cloud-capability-setup.d.ts +3 -2
  192. package/dist/src/gateway/xopc-cloud-capability-setup.js +16 -3
  193. package/dist/src/knowledge/connected-knowledge-pipeline.d.ts +6 -0
  194. package/dist/src/knowledge/connected-knowledge-pipeline.js +35 -4
  195. package/dist/src/knowledge/connected-understanding-pipeline.d.ts +1 -1
  196. package/dist/src/knowledge/connected-understanding-pipeline.js +4 -2
  197. package/dist/src/providers/auth-runtime/resolve-auth.js +1 -1
  198. package/dist/src/providers/index.js +2 -2
  199. package/dist/src/providers/model-registry.js +1 -1
  200. package/dist/src/providers/register-runtime-providers.js +1 -1
  201. package/dist/src/retrieval/queryProfile.d.ts +3 -0
  202. package/dist/src/retrieval/queryProfile.js +20 -2
  203. package/dist/src/session/client-history.d.ts +11 -0
  204. package/dist/src/session/client-history.js +24 -2
  205. package/dist/src/session/config-types.d.ts +1 -1
  206. package/dist/src/session/session-title.js +2 -3
  207. package/dist/src/session/store.js +1 -0
  208. package/dist/src/session/transcript-outline.js +5 -2
  209. package/dist/src/session/types.d.ts +1 -0
  210. package/dist/src/session/user-message-display.d.ts +4 -0
  211. package/dist/src/session/user-message-display.js +22 -0
  212. package/dist/src/storage/sqlite/context-extraction-repository.d.ts +57 -0
  213. package/dist/src/storage/sqlite/context-extraction-repository.js +119 -0
  214. package/dist/src/storage/sqlite/context-relation-repository.d.ts +50 -0
  215. package/dist/src/storage/sqlite/context-relation-repository.js +97 -0
  216. package/dist/src/storage/sqlite/index.d.ts +6 -4
  217. package/dist/src/storage/sqlite/index.js +7 -5
  218. package/dist/src/storage/sqlite/knowledge-repository.d.ts +5 -1
  219. package/dist/src/storage/sqlite/knowledge-repository.js +16 -1
  220. package/dist/src/storage/sqlite/memory-records-repository.d.ts +2 -0
  221. package/dist/src/storage/sqlite/memory-records-repository.js +21 -1
  222. package/dist/src/storage/sqlite/migrations/126_focus_context_governance.sql +72 -0
  223. package/dist/src/storage/sqlite/migrations/127_context_object_origin.sql +36 -0
  224. package/dist/src/storage/sqlite/migrations/128_context_extraction.sql +73 -0
  225. package/dist/src/storage/sqlite/migrations/129_focus_versions.sql +51 -0
  226. package/dist/src/storage/sqlite/migrations/130_context_evidence_provenance.sql +18 -0
  227. package/dist/src/storage/sqlite/migrations/131_session_input_contexts.sql +2 -0
  228. package/dist/src/storage/sqlite/migrations/132_transcript_source_context_metadata.sql +34 -0
  229. package/dist/src/storage/sqlite/migrations/133_archive_legacy_work_discovery_profile_facts.sql +11 -0
  230. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  231. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  232. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  233. package/dist/src/storage/sqlite/schema.js +1 -1
  234. package/dist/src/storage/sqlite/session-input-repository.d.ts +8 -0
  235. package/dist/src/storage/sqlite/session-input-repository.js +19 -7
  236. package/dist/src/storage/sqlite/session-repository.js +2 -2
  237. package/dist/src/storage/sqlite/session-turn-replace-repository.d.ts +3 -0
  238. package/dist/src/storage/sqlite/session-turn-replace-repository.js +3 -2
  239. package/dist/src/storage/sqlite/transcript-repository.js +29 -3
  240. package/dist/src/storage/sqlite/user-context-repository.d.ts +4 -1
  241. package/dist/src/storage/sqlite/user-context-repository.js +65 -29
  242. package/dist/src/tasks/home-query-service.d.ts +14 -0
  243. package/dist/src/tasks/home-query-service.js +19 -2
  244. package/dist/src/tasks/index.d.ts +1 -0
  245. package/dist/src/tasks/index.js +2 -1
  246. package/dist/src/tasks/task-deletion-service.d.ts +21 -0
  247. package/dist/src/tasks/task-deletion-service.js +35 -0
  248. package/dist/src/tasks/task-repository.js +22 -1
  249. package/dist/src/tui/backends/embedded-backend.js +5 -3
  250. package/dist/src/tui/backends/gateway-realtime-backend.js +5 -3
  251. package/dist/src/tui/chat-history.js +2 -1
  252. package/dist/src/tui/tui-agent-events.js +4 -2
  253. package/dist/src/tui/tui-commands.d.ts +1 -0
  254. package/dist/src/tui/tui-commands.js +8 -3
  255. package/dist/src/tui/tui-empty-session-cleanup.d.ts +0 -1
  256. package/dist/src/tui/tui-empty-session-cleanup.js +1 -11
  257. package/dist/src/tui/tui-new-session-preferences.d.ts +10 -0
  258. package/dist/src/tui/tui-new-session-preferences.js +32 -0
  259. package/dist/src/tui/tui-session-actions.d.ts +1 -0
  260. package/dist/src/tui/tui-session-actions.js +2 -1
  261. package/dist/src/tui/tui-settings.d.ts +2 -0
  262. package/dist/src/tui/tui-settings.js +4 -1
  263. package/dist/src/tui/tui-startup-resources.js +1 -1
  264. package/dist/src/tui/tui-types.d.ts +1 -0
  265. package/dist/src/tui/tui.js +58 -5
  266. package/dist/src/tunnel/frpc-process.js +3 -0
  267. package/dist/src/tunnel/tunnel-service.d.ts +2 -0
  268. package/dist/src/tunnel/tunnel-service.js +40 -28
  269. package/dist/src/user-context/consolidation.d.ts +1 -0
  270. package/dist/src/user-context/consolidation.js +62 -2
  271. package/dist/src/user-context/context-objects.d.ts +17 -0
  272. package/dist/src/user-context/context-objects.js +99 -0
  273. package/dist/src/user-context/domain.d.ts +13 -1
  274. package/dist/src/user-context/evaluation/harness.d.ts +13 -0
  275. package/dist/src/user-context/evaluation/harness.js +31 -0
  276. package/dist/src/user-context/extraction/registry.d.ts +26 -0
  277. package/dist/src/user-context/extraction/registry.js +113 -0
  278. package/dist/src/user-context/extraction/repair.d.ts +19 -0
  279. package/dist/src/user-context/extraction/repair.js +68 -0
  280. package/dist/src/user-context/focus-lifecycle.d.ts +2 -0
  281. package/dist/src/user-context/focus-lifecycle.js +26 -0
  282. package/dist/src/user-context/planner.js +252 -62
  283. package/dist/src/user-context/retriever.js +69 -9
  284. package/dist/src/user-context/sources/index.js +2 -2
  285. package/dist/src/user-context/sources/processing-policy.d.ts +2 -0
  286. package/dist/src/user-context/sources/processing-policy.js +7 -0
  287. package/dist/src/user-context/sources/repository.d.ts +23 -4
  288. package/dist/src/user-context/sources/repository.js +122 -12
  289. package/dist/src/user-context/sources/types.d.ts +10 -1
  290. package/dist/src/user-context/understanding.js +1 -1
  291. package/dist/src/work-discovery/analyzer.js +6 -4
  292. package/dist/src/work-discovery/index.js +2 -2
  293. package/dist/src/work-discovery/service.d.ts +12 -3
  294. package/dist/src/work-discovery/service.js +183 -86
  295. package/dist/src/work-discovery/source-repository.d.ts +1 -0
  296. package/dist/src/work-discovery/source-repository.js +10 -4
  297. package/dist/src/work-discovery/types.d.ts +2 -1
  298. package/dist/src/workflows/service/workflow-run-service.js +1 -1
  299. package/package.json +3 -3
  300. package/dist/gateway/static/root/assets/agents-Dj86bHkl.js +0 -68
  301. package/dist/gateway/static/root/assets/app-management-settings-panel-D-M6GN-8.js +0 -1
  302. package/dist/gateway/static/root/assets/appearance-settings-XDhmzdIc.js +0 -1
  303. package/dist/gateway/static/root/assets/apps-page-sfO835uz.js +0 -1
  304. package/dist/gateway/static/root/assets/automations-workspace-PptuZgoo.js +0 -6
  305. package/dist/gateway/static/root/assets/browser-settings-page-BoCmzMFV.js +0 -8
  306. package/dist/gateway/static/root/assets/capabilities-settings-panel-DhkJsU8Z.js +0 -7
  307. package/dist/gateway/static/root/assets/capability-presets-settings-panel-Dm7T61fE.js +0 -3
  308. package/dist/gateway/static/root/assets/channels-settings-dG6UFVqt.js +0 -1
  309. package/dist/gateway/static/root/assets/channels-status-swr-DgJxfNyK.js +0 -1
  310. package/dist/gateway/static/root/assets/chat-terminal-dock-CT5yoSMD.js +0 -36
  311. package/dist/gateway/static/root/assets/connectors-page-BC6Ft9SU.js +0 -2
  312. package/dist/gateway/static/root/assets/dependency-picker-DZVSgLXH.js +0 -1
  313. package/dist/gateway/static/root/assets/desktop-pet-settings-Bw4cCFzI.js +0 -1
  314. package/dist/gateway/static/root/assets/directory-picker-path-field-Cbst7IXR.js +0 -1
  315. package/dist/gateway/static/root/assets/extension-settings-page-C1PAKSy2.js +0 -1
  316. package/dist/gateway/static/root/assets/gateway-config-api-Bch9vO6t.js +0 -1
  317. package/dist/gateway/static/root/assets/gateway-settings-DkDxZFGG.js +0 -1
  318. package/dist/gateway/static/root/assets/heartbeat-settings-DXNMxy5b.js +0 -1
  319. package/dist/gateway/static/root/assets/home-page-CYcpVFNT.js +0 -1
  320. package/dist/gateway/static/root/assets/index-Dgb1R07E.css +0 -2
  321. package/dist/gateway/static/root/assets/index-DlOYwVFK.js +0 -108
  322. package/dist/gateway/static/root/assets/local-app-workbench-page-BFrgPwGE.js +0 -2
  323. package/dist/gateway/static/root/assets/logs-page-CPweLw3k.js +0 -2
  324. package/dist/gateway/static/root/assets/messages-B9WQcZ1V.js +0 -3
  325. package/dist/gateway/static/root/assets/notes-workbench-wieRAd1y.js +0 -4
  326. package/dist/gateway/static/root/assets/page-tabs-Bsluqyfb.js +0 -1
  327. package/dist/gateway/static/root/assets/preview-open-alternatives-BrpTWv44.js +0 -1
  328. package/dist/gateway/static/root/assets/project-detail-page-Cww6V7HJ.js +0 -1
  329. package/dist/gateway/static/root/assets/projects-page-D0LKhCCw.js +0 -1
  330. package/dist/gateway/static/root/assets/remote-access-hub-Sf4Pde6Z.js +0 -1
  331. package/dist/gateway/static/root/assets/sessions-page-S5gvgfu5.js +0 -1
  332. package/dist/gateway/static/root/assets/settings-advanced-gate-B3XvdEy8.js +0 -1
  333. package/dist/gateway/static/root/assets/settings-form-section-CiGFtdD8.js +0 -1
  334. package/dist/gateway/static/root/assets/setup-status-panel-CGU_Mxjr.js +0 -1
  335. package/dist/gateway/static/root/assets/shares-settings-k0UQ8WxO.js +0 -1
  336. package/dist/gateway/static/root/assets/skill-reload-api-DQ1GvL1w.js +0 -1
  337. package/dist/gateway/static/root/assets/skills-page-OuHd9GcN.js +0 -2
  338. package/dist/gateway/static/root/assets/system-settings-panel-CERqCsz2.js +0 -1
  339. package/dist/gateway/static/root/assets/task-detail-page-BnRNL2sn.js +0 -1
  340. package/dist/gateway/static/root/assets/typed-models-lib-abEJNkCO.js +0 -1
  341. package/dist/gateway/static/root/assets/user-context-page-Cnkaiky5.js +0 -1
  342. package/dist/gateway/static/root/assets/workflows-page-B_VlcKiK.js +0 -5
@@ -1,14 +1,34 @@
1
- import { consumeContextConsent, ensureContextConsent, getUserProfile, listCollaborationRules, recordContextRun } from "../storage/sqlite/user-context-repository.js";
1
+ import { consumeContextConsent, ensureContextConsent, getUserProfile, listCollaborationRules, listUnderstandingEvidence, listUnderstandings, recordContextRun } from "../storage/sqlite/user-context-repository.js";
2
+ import { retrievalLexicalSimilarity } from "../retrieval/textFeatures.js";
3
+ import { buildRetrievalQueryProfile } from "../retrieval/queryProfile.js";
2
4
  import "../storage/sqlite/index.js";
5
+ import { init_session_key, parseSessionKey } from "../routing/session-key.js";
6
+ import { ProjectStore } from "../projects/project-store.js";
3
7
  import { readAgentMessageContent } from "../agent/memory/agent-message-access.js";
4
8
  import { buildUserContextBlock } from "../agent/memory/context-fence.js";
5
- import { listUserFocuses } from "./sources/repository.js";
9
+ import { getUnderstandingSourceGrant, getUnderstandingSourceRun, listUserFocuses } from "./sources/repository.js";
6
10
  import { matchesUserContextScope } from "./scope.js";
7
11
  import { UserUnderstandingRetriever } from "./retriever.js";
8
12
  import { randomUUID } from "node:crypto";
9
13
  //#region src/user-context/planner.ts
14
+ init_session_key();
10
15
  const DEFAULT_MAX_CONTEXT_CHARS = 6e3;
11
16
  const DEFAULT_MAX_RESULTS = 12;
17
+ const SELF_REVIEW_MAX_CONTEXT_CHARS = 16e3;
18
+ const SELF_REVIEW_MAX_RESULTS = 50;
19
+ const MAX_FOCUS_RESULTS = 3;
20
+ const MIN_RELEVANCE_SCORE = .25;
21
+ function selfReviewScore(item) {
22
+ const authority = item.explicitness === "explicit" ? .2 : item.explicitness === "observed" ? .1 : 0;
23
+ const durable = item.durability === "durable" ? .1 : item.durability === "recurring" ? .05 : 0;
24
+ return Math.min(1, item.confidence * .7 + authority + durable);
25
+ }
26
+ function scopeLabel(scope, projects) {
27
+ if (scope.type === "global") return "Global";
28
+ if (scope.type === "project") return `Project: ${scope.id ? projects.get(scope.id)?.name ?? scope.id : "unknown"}`;
29
+ if (scope.type === "workspace") return `Workspace: ${scope.id ?? "unknown"}`;
30
+ return "This conversation";
31
+ }
12
32
  function prependAgentContext(message, block) {
13
33
  if (!block) return message;
14
34
  const prefix = `${block}\n\n`;
@@ -44,29 +64,89 @@ function sectionFor(item) {
44
64
  ].includes(item.kind)) return "interaction";
45
65
  return "task";
46
66
  }
47
- function originFor(item) {
48
- if (item.explicitness === "explicit") return "told_by_user";
49
- if (item.explicitness === "observed") return "observed";
50
- return "inferred";
67
+ function sourceDescription(item) {
68
+ if (item.explicitness === "explicit") return {
69
+ origin: "told_by_user",
70
+ label: "You told xopc"
71
+ };
72
+ const connected = listUnderstandingEvidence(item.id).find((evidence) => evidence.sourceType === "connector");
73
+ if (connected) return {
74
+ origin: "connected_source",
75
+ label: connected.sourceInstanceId ?? "Connected source"
76
+ };
77
+ if (item.explicitness === "observed") return {
78
+ origin: "observed",
79
+ label: "Observed across prior work"
80
+ };
81
+ return {
82
+ origin: "inferred",
83
+ label: "An inference that may be wrong"
84
+ };
51
85
  }
52
- function sourceLabel(item) {
53
- if (item.explicitness === "explicit") return "You told xopc";
54
- if (item.explicitness === "observed") return "Observed across prior work";
55
- return "An inference that may be wrong";
86
+ function focusSourceDescription(focus) {
87
+ if (focus.explicitness === "explicit") return {
88
+ origin: "told_by_user",
89
+ label: "You set this focus"
90
+ };
91
+ const sourceRun = focus.sourceRunId ? getUnderstandingSourceRun(focus.sourceRunId) : null;
92
+ const grant = sourceRun ? getUnderstandingSourceGrant(sourceRun.grantId) : null;
93
+ if (grant?.adapterId.startsWith("connector:")) return {
94
+ origin: "connected_source",
95
+ label: grant.displayName
96
+ };
97
+ if (focus.explicitness === "observed") return {
98
+ origin: "observed",
99
+ label: "Observed across prior work"
100
+ };
101
+ return {
102
+ origin: "inferred",
103
+ label: "Suggested from prior work"
104
+ };
56
105
  }
57
- function rejectionReason(item, input, now) {
58
- if (item.status === "needs_review" || item.status === "stale" || item.status === "candidate") return "needs_review";
59
- if (item.status === "archived" || item.status === "rejected") return "disabled";
106
+ function rejectionReason(item, input, now, timeHints) {
107
+ const historical = timeHints.includes("historical") && item.validTo !== void 0;
108
+ if (item.status === "needs_review" || item.status === "candidate" || item.status === "stale" && !historical) return "needs_review";
109
+ if (item.status === "rejected" || item.status === "archived" && !historical) return "disabled";
60
110
  if (!matchesUserContextScope(item.scope, input)) return "scope_mismatch";
61
- if (item.validFrom && item.validFrom > now) return "not_yet_valid";
62
- if (item.validTo && item.validTo < now || item.expiresAt && item.expiresAt < now) return "expired";
111
+ if (item.validFrom && item.validFrom > now && !timeHints.includes("future")) return "not_yet_valid";
112
+ if ((item.validTo && item.validTo < now || item.expiresAt && item.expiresAt < now) && !historical) return "expired";
63
113
  if (item.sensitivity === "secret" || item.sensitivity === "regulated") return "sensitive";
64
114
  if (item.conflictGroupId) return "conflict";
65
115
  }
66
116
  function ruleMatches(rule, input) {
67
117
  if (rule.status !== "active" || !matchesUserContextScope(rule.scope, input)) return false;
68
118
  const channel = typeof rule.conditions.channel === "string" ? rule.conditions.channel : void 0;
69
- return !channel || channel === input.channel;
119
+ const agentId = typeof rule.conditions.agentId === "string" ? rule.conditions.agentId : void 0;
120
+ return (!channel || channel === input.channel) && (!agentId || agentId === input.agentId);
121
+ }
122
+ function focusRejectionReason(focus, input, now) {
123
+ if (focus.status !== "active") return "disabled";
124
+ if (!matchesUserContextScope(focus.scope, input)) return "scope_mismatch";
125
+ if (focus.validFrom && focus.validFrom > now) return "not_yet_valid";
126
+ if (focus.validTo && focus.validTo < now) return "expired";
127
+ if (focus.sensitivity === "secret" || focus.sensitivity === "regulated") return "sensitive";
128
+ if (focus.disclosurePolicy === "ask_before_reference") return "requires_consent";
129
+ }
130
+ function focusScore(focus, query, scopeInput) {
131
+ const lexical = retrievalLexicalSimilarity(buildRetrievalQueryProfile(query, scopeInput).normalized, `${focus.title} ${focus.summary}`);
132
+ const scoped = focus.scope.type !== "global" && matchesUserContextScope(focus.scope, scopeInput);
133
+ return Math.min(1, lexical * .75 + focus.confidence * .15 + (scoped ? .25 : 0));
134
+ }
135
+ function renderContextBlock(params) {
136
+ const understandingItems = params.items.filter((item) => item.objectType === "understanding");
137
+ return [
138
+ params.selfReview ? [
139
+ "<user-context-review>",
140
+ "The user explicitly asked what xopc understands about them. This is a review of active, non-sensitive structured understanding across scopes.",
141
+ "Scope labels describe where each item applies. Do not present project facts as global personality traits.",
142
+ "An empty memory_search result does not mean structured user understanding is empty.",
143
+ "</user-context-review>"
144
+ ].join("\n") : "",
145
+ params.profileLines.length ? `<user-profile>\n${params.profileLines.join("\n")}\n</user-profile>` : "",
146
+ params.focuses.length ? `<active-focuses>\n${params.focuses.map((focus) => `- ${params.selfReview ? `[${scopeLabel(focus.scope, params.projects)}] ` : ""}${focus.title}: ${focus.summary} (${focus.horizon})`).join("\n")}\n</active-focuses>` : "",
147
+ params.rules.length ? `<collaboration-contract>\n${params.rules.map((rule) => `- ${rule.statement}`).join("\n")}\n</collaboration-contract>` : "",
148
+ understandingItems.length ? buildUserContextBlock(understandingItems.map((item) => `- ${item.content}\n Evidence: ${params.understandingSources.get(item.recordId) ?? "Unknown source"}`).join("\n")) : ""
149
+ ].filter(Boolean).join("\n\n");
70
150
  }
71
151
  var UserContextPlanner = class {
72
152
  retriever = new UserUnderstandingRetriever();
@@ -84,19 +164,37 @@ var UserContextPlanner = class {
84
164
  };
85
165
  const started = Date.now();
86
166
  const now = Date.now();
87
- const maxResults = params.allocation?.maxResults ?? DEFAULT_MAX_RESULTS;
88
- const maxChars = params.allocation?.maxChars ?? DEFAULT_MAX_CONTEXT_CHARS;
167
+ const requestedMaxResults = params.allocation?.maxResults;
168
+ const requestedMaxChars = params.allocation?.maxChars;
89
169
  const scopeInput = {
90
170
  sessionKey: params.sessionKey,
91
171
  workspaceId: params.workspaceId,
92
172
  ...params.projectId ? { projectId: params.projectId } : {}
93
173
  };
174
+ const queryProfile = buildRetrievalQueryProfile(query, scopeInput);
175
+ const selfReview = queryProfile.selfReview;
176
+ const maxResults = requestedMaxResults ?? (selfReview ? SELF_REVIEW_MAX_RESULTS : DEFAULT_MAX_RESULTS);
177
+ const maxChars = requestedMaxChars ?? (selfReview ? SELF_REVIEW_MAX_CONTEXT_CHARS : DEFAULT_MAX_CONTEXT_CHARS);
178
+ const projects = new ProjectStore();
94
179
  const excluded = new Set(params.excludedRecordIds ?? []);
95
180
  const rejected = [];
96
181
  const consentRequests = [];
97
182
  const traceItems = [];
98
183
  const items = [];
184
+ const selectedFocuses = [];
185
+ const selectedRules = [];
186
+ const understandingSources = /* @__PURE__ */ new Map();
99
187
  let usedChars = 0;
188
+ const render = (overrides = {}) => renderContextBlock({
189
+ profileLines,
190
+ focuses: selectedFocuses,
191
+ rules: selectedRules,
192
+ items,
193
+ understandingSources,
194
+ selfReview,
195
+ projects,
196
+ ...overrides
197
+ });
100
198
  const profile = getUserProfile();
101
199
  const profileLines = [
102
200
  profile.callName ? `Preferred name: ${profile.callName}` : "",
@@ -108,28 +206,105 @@ var UserContextPlanner = class {
108
206
  ].filter(Boolean);
109
207
  if (profileLines.length) {
110
208
  const content = profileLines.join("\n");
209
+ const nextChars = render().length;
210
+ if (nextChars <= maxChars) {
211
+ traceItems.push({
212
+ objectType: "profile",
213
+ objectId: "profile",
214
+ decision: "selected",
215
+ reason: "User-provided profile",
216
+ content,
217
+ sourceLabel: "You provided this directly",
218
+ origin: "told_by_user",
219
+ rank: 0,
220
+ score: 1,
221
+ injectedChars: nextChars
222
+ });
223
+ usedChars = nextChars;
224
+ } else {
225
+ profileLines.length = 0;
226
+ traceItems.push({
227
+ objectType: "profile",
228
+ objectId: "profile",
229
+ decision: "budget_exceeded",
230
+ reason: "Context budget reached",
231
+ content,
232
+ sourceLabel: "You provided this directly",
233
+ origin: "told_by_user",
234
+ injectedChars: 0
235
+ });
236
+ }
237
+ }
238
+ const rankedFocuses = listUserFocuses(["active"]).map((focus) => ({
239
+ focus,
240
+ score: focusScore(focus, query, scopeInput)
241
+ })).sort((left, right) => selfReview ? right.focus.confidence - left.focus.confidence || right.focus.updatedAt - left.focus.updatedAt : right.score - left.score || right.focus.updatedAt - left.focus.updatedAt);
242
+ for (const { focus, score } of rankedFocuses) {
243
+ const source = focusSourceDescription(focus);
244
+ let reason = focusRejectionReason(focus, scopeInput, now);
245
+ if (selfReview && reason === "scope_mismatch") reason = void 0;
246
+ if (!reason && !selfReview && score <= MIN_RELEVANCE_SCORE) reason = "low_score";
247
+ if (!reason && selectedFocuses.length >= (selfReview ? maxResults : MAX_FOCUS_RESULTS)) reason = "budget";
248
+ if (!reason && items.length >= maxResults) reason = "budget";
249
+ const focusScope = scopeLabel(focus.scope, projects);
250
+ const content = `${selfReview ? `[${focusScope}] ` : ""}${focus.title}: ${focus.summary} (${focus.horizon})`;
251
+ const nextChars = render({ focuses: [...selectedFocuses, focus] }).length;
252
+ if (!reason && nextChars > maxChars) reason = "budget";
253
+ if (reason) {
254
+ rejected.push({
255
+ recordId: focus.id,
256
+ reason
257
+ });
258
+ traceItems.push({
259
+ objectType: "focus",
260
+ objectId: focus.id,
261
+ versionId: focus.versionId,
262
+ decision: reason === "budget" ? "budget_exceeded" : reason === "requires_consent" ? "needs_consent" : reason === "scope_mismatch" ? "scope_mismatch" : reason === "expired" ? "expired" : reason === "sensitive" ? "sensitive" : reason === "disabled" ? "disabled" : "irrelevant",
263
+ reason,
264
+ content,
265
+ sourceLabel: source.label,
266
+ origin: source.origin,
267
+ score,
268
+ injectedChars: 0
269
+ });
270
+ continue;
271
+ }
272
+ const addedChars = nextChars - usedChars;
273
+ usedChars = nextChars;
274
+ selectedFocuses.push(focus);
275
+ items.push({
276
+ recordId: focus.id,
277
+ objectType: "focus",
278
+ versionId: focus.versionId,
279
+ content,
280
+ score,
281
+ section: "task",
282
+ citation: `user-focus://${focus.id}`,
283
+ origin: source.origin,
284
+ stability: focus.confidence
285
+ });
111
286
  traceItems.push({
112
- objectType: "profile",
113
- objectId: "profile",
287
+ objectType: "focus",
288
+ objectId: focus.id,
289
+ versionId: focus.versionId,
114
290
  decision: "selected",
115
- reason: "User-provided profile",
291
+ reason: "Relevant active focus",
116
292
  content,
117
- sourceLabel: "You provided this directly",
118
- rank: 0,
119
- score: 1,
120
- injectedChars: content.length
293
+ sourceLabel: source.label,
294
+ origin: source.origin,
295
+ rank: items.length,
296
+ score,
297
+ injectedChars: addedChars
121
298
  });
122
- usedChars += content.length;
123
299
  }
124
- const activeFocusLines = listUserFocuses(["active"]).slice(0, 5).map((focus) => `- ${focus.title}: ${focus.summary} (${focus.horizon})`);
125
- if (activeFocusLines.length) usedChars += activeFocusLines.join("\n").length;
126
300
  const rules = listCollaborationRules().filter((rule) => ruleMatches(rule, {
127
301
  ...scopeInput,
128
- channel: params.channel
302
+ channel: params.channel,
303
+ agentId: parseSessionKey(params.sessionKey)?.agentId
129
304
  }));
130
- const selectedRules = [];
131
305
  for (const [index, rule] of rules.entries()) {
132
- if (usedChars + rule.statement.length > maxChars) {
306
+ const nextChars = render({ rules: [...selectedRules, rule] }).length;
307
+ if (nextChars > maxChars) {
133
308
  traceItems.push({
134
309
  objectType: "rule",
135
310
  objectId: rule.id,
@@ -138,11 +313,13 @@ var UserContextPlanner = class {
138
313
  reason: "Context budget reached",
139
314
  content: rule.statement,
140
315
  sourceLabel: "Your collaboration rule",
316
+ origin: "told_by_user",
141
317
  injectedChars: 0
142
318
  });
143
319
  continue;
144
320
  }
145
- usedChars += rule.statement.length;
321
+ const addedChars = nextChars - usedChars;
322
+ usedChars = nextChars;
146
323
  selectedRules.push(rule);
147
324
  traceItems.push({
148
325
  objectType: "rule",
@@ -152,22 +329,27 @@ var UserContextPlanner = class {
152
329
  reason: "Active collaboration rule",
153
330
  content: rule.statement,
154
331
  sourceLabel: "Your collaboration rule",
332
+ origin: "told_by_user",
155
333
  rank: index + 1,
156
334
  score: 1,
157
- injectedChars: rule.statement.length
335
+ injectedChars: addedChars
158
336
  });
159
337
  }
160
- const ranked = this.retriever.retrieve({
338
+ const ranked = (selfReview ? listUnderstandings(["active"]).map((item) => ({
339
+ item,
340
+ score: selfReviewScore(item)
341
+ })).sort((left, right) => right.score - left.score || right.item.updatedAt - left.item.updatedAt) : this.retriever.retrieve({
161
342
  query,
162
343
  sessionKey: params.sessionKey,
163
344
  workspaceId: params.workspaceId,
164
345
  ...params.projectId ? { projectId: params.projectId } : {},
165
346
  maxCandidates: Math.max(maxResults * 5, 50)
166
- }).filter((result) => !excluded.has(result.understanding.id)).map((result) => ({
347
+ }).map((result) => ({
167
348
  item: result.understanding,
168
349
  score: result.score
169
- }));
350
+ }))).filter(({ item }) => !excluded.has(item.id));
170
351
  for (const { item, score } of ranked) {
352
+ const source = sourceDescription(item);
171
353
  if (items.length >= maxResults) {
172
354
  rejected.push({
173
355
  recordId: item.id,
@@ -180,14 +362,16 @@ var UserContextPlanner = class {
180
362
  decision: "budget_exceeded",
181
363
  reason: "Maximum result count reached",
182
364
  content: item.statement,
183
- sourceLabel: sourceLabel(item),
365
+ sourceLabel: source.label,
366
+ origin: source.origin,
184
367
  score,
185
368
  injectedChars: 0
186
369
  });
187
370
  continue;
188
371
  }
189
- let reason = rejectionReason(item, scopeInput, now);
190
- if (!reason && score < .25) reason = "low_score";
372
+ let reason = rejectionReason(item, scopeInput, now, queryProfile.timeHints);
373
+ if (selfReview && reason === "scope_mismatch") reason = void 0;
374
+ if (!reason && !selfReview && score <= MIN_RELEVANCE_SCORE) reason = "low_score";
191
375
  if (!reason && item.disclosurePolicy === "ask_before_reference") {
192
376
  const consentStatus = consumeContextConsent(item.id, params.sessionKey);
193
377
  if (consentStatus !== "granted") {
@@ -215,13 +399,30 @@ var UserContextPlanner = class {
215
399
  decision: reason === "budget" ? "budget_exceeded" : reason === "requires_consent" ? "needs_consent" : reason === "conflict" ? "conflicted" : reason === "expired" ? "expired" : reason === "sensitive" ? "sensitive" : reason === "scope_mismatch" ? "scope_mismatch" : reason === "disabled" ? "disabled" : "irrelevant",
216
400
  reason,
217
401
  content: item.statement,
218
- sourceLabel: sourceLabel(item),
402
+ sourceLabel: source.label,
403
+ origin: source.origin,
219
404
  score,
220
405
  injectedChars: 0
221
406
  });
222
407
  continue;
223
408
  }
224
- if (usedChars + item.statement.length > maxChars) {
409
+ const plannedItem = {
410
+ recordId: item.id,
411
+ objectType: "understanding",
412
+ versionId: item.versionId,
413
+ content: selfReview ? `[${scopeLabel(item.scope, projects)}] ${item.statement}` : item.statement,
414
+ score,
415
+ section: sectionFor(item),
416
+ citation: `user-context://${item.id}`,
417
+ origin: source.origin,
418
+ stability: item.confidence
419
+ };
420
+ const nextSources = new Map(understandingSources).set(item.id, source.label);
421
+ const nextChars = render({
422
+ items: [...items, plannedItem],
423
+ understandingSources: nextSources
424
+ }).length;
425
+ if (nextChars > maxChars) {
225
426
  rejected.push({
226
427
  recordId: item.id,
227
428
  reason: "budget"
@@ -233,24 +434,17 @@ var UserContextPlanner = class {
233
434
  decision: "budget_exceeded",
234
435
  reason: "Context budget reached",
235
436
  content: item.statement,
236
- sourceLabel: sourceLabel(item),
437
+ sourceLabel: source.label,
438
+ origin: source.origin,
237
439
  score,
238
440
  injectedChars: 0
239
441
  });
240
442
  continue;
241
443
  }
242
- usedChars += item.statement.length;
243
- items.push({
244
- recordId: item.id,
245
- objectType: "understanding",
246
- versionId: item.versionId,
247
- content: item.statement,
248
- score,
249
- section: sectionFor(item),
250
- citation: `user-context://${item.id}`,
251
- origin: originFor(item),
252
- stability: item.confidence
253
- });
444
+ const addedChars = nextChars - usedChars;
445
+ usedChars = nextChars;
446
+ understandingSources.set(item.id, source.label);
447
+ items.push(plannedItem);
254
448
  traceItems.push({
255
449
  objectType: "understanding",
256
450
  objectId: item.id,
@@ -258,18 +452,14 @@ var UserContextPlanner = class {
258
452
  decision: "selected",
259
453
  reason: "Relevant to this request",
260
454
  content: item.statement,
261
- sourceLabel: sourceLabel(item),
455
+ sourceLabel: source.label,
456
+ origin: source.origin,
262
457
  rank: items.length,
263
458
  score,
264
- injectedChars: item.statement.length
459
+ injectedChars: addedChars
265
460
  });
266
461
  }
267
- const block = [
268
- profileLines.length ? `<user-profile>\n${profileLines.join("\n")}\n</user-profile>` : "",
269
- activeFocusLines.length ? `<active-focuses>\n${activeFocusLines.join("\n")}\n</active-focuses>` : "",
270
- selectedRules.length ? `<collaboration-contract>\n${selectedRules.map((rule) => `- ${rule.statement}`).join("\n")}\n</collaboration-contract>` : "",
271
- items.length ? buildUserContextBlock(items.map((item) => `- ${item.content}\n Evidence: ${traceItems.find((trace) => trace.objectId === item.recordId)?.sourceLabel}`).join("\n")) : ""
272
- ].filter(Boolean).join("\n\n");
462
+ const block = render();
273
463
  recordContextRun({
274
464
  turnId: params.turnId,
275
465
  sessionKey: params.sessionKey,
@@ -1,5 +1,5 @@
1
1
  import { summarizeUnderstandingFeedback } from "../storage/sqlite/user-context-quality-repository.js";
2
- import { listUnderstandings, searchActiveUnderstandings } from "../storage/sqlite/user-context-repository.js";
2
+ import { listUnderstandingEvidence, listUnderstandings, searchActiveUnderstandings } from "../storage/sqlite/user-context-repository.js";
3
3
  import { normalizeRetrievalText, retrievalLexicalSimilarity } from "../retrieval/textFeatures.js";
4
4
  import { buildRetrievalQueryProfile } from "../retrieval/queryProfile.js";
5
5
  import "../storage/sqlite/index.js";
@@ -12,9 +12,62 @@ function authorityBonus(item) {
12
12
  }
13
13
  function baseline(item) {
14
14
  if (item.kind === "boundary" && item.explicitness === "explicit") return .8;
15
- if (item.kind === "preference" && item.explicitness === "explicit") return .35;
15
+ if (item.kind === "preference" && item.explicitness === "explicit") return .12;
16
16
  return 0;
17
17
  }
18
+ function temporalAdjustment(item, hints, now) {
19
+ if (!hints.length) return 0;
20
+ let score = 0;
21
+ if (hints.includes("historical")) score += item.validTo !== void 0 || item.status === "archived" || item.status === "stale" ? .14 : -.6;
22
+ if (hints.includes("current")) {
23
+ if (item.kind === "current_state" || item.validFrom !== void 0 || item.validTo !== void 0) {
24
+ const validNow = (item.validFrom === void 0 || item.validFrom <= now) && (item.validTo === void 0 || item.validTo > now);
25
+ score += validNow ? .08 : -.15;
26
+ if (item.kind === "current_state") score += .06;
27
+ }
28
+ }
29
+ if (hints.includes("recent")) score += now - item.updatedAt <= 2160 * 60 * 6e4 ? .08 : -.04;
30
+ if (hints.includes("future")) {
31
+ if ((item.validFrom ?? 0) > now || item.kind === "long_term_goal") score += .1;
32
+ }
33
+ return score;
34
+ }
35
+ function sourceBucket(item) {
36
+ if (item.explicitness === "explicit") return "user";
37
+ const evidence = listUnderstandingEvidence(item.id)[0];
38
+ if (!evidence) return `unknown:${item.id}`;
39
+ if (evidence.sourceInstanceId) return `${evidence.sourceType}:${evidence.sourceInstanceId}`;
40
+ return `${evidence.sourceType}:${evidence.sourceRef.split(":entry:")[0]}`;
41
+ }
42
+ function diversify(results, limit) {
43
+ const remaining = [...results];
44
+ const selected = [];
45
+ const sourceCounts = /* @__PURE__ */ new Map();
46
+ const sourceBuckets = new Map(results.map((result) => [result.understanding.id, sourceBucket(result.understanding)]));
47
+ while (remaining.length && selected.length < limit) {
48
+ let bestIndex = 0;
49
+ let bestScore = Number.NEGATIVE_INFINITY;
50
+ for (const [index, candidate] of remaining.entries()) {
51
+ const redundancy = selected.reduce((maximum, chosen) => Math.max(maximum, retrievalLexicalSimilarity(candidate.understanding.statement, chosen.understanding.statement)), 0);
52
+ const bucket = sourceBuckets.get(candidate.understanding.id);
53
+ const sourcePenalty = candidate.understanding.explicitness === "explicit" ? 0 : (sourceCounts.get(bucket) ?? 0) * .04;
54
+ const adjusted = candidate.score - redundancy * .18 - sourcePenalty;
55
+ if (adjusted > bestScore) {
56
+ bestScore = adjusted;
57
+ bestIndex = index;
58
+ }
59
+ }
60
+ const candidate = remaining.splice(bestIndex, 1)[0];
61
+ const bucket = sourceBuckets.get(candidate.understanding.id);
62
+ sourceCounts.set(bucket, (sourceCounts.get(bucket) ?? 0) + 1);
63
+ selected.push({
64
+ ...candidate,
65
+ score: Math.max(0, bestScore),
66
+ reasons: bestScore < candidate.score ? [...candidate.reasons, "diversified"] : candidate.reasons
67
+ });
68
+ }
69
+ return selected;
70
+ }
18
71
  function feedbackAdjustment(summary) {
19
72
  if (!summary || summary.total < 3) return 0;
20
73
  const helpfulRate = (summary.helpful + 1) / (summary.total + 2);
@@ -30,35 +83,42 @@ var UserUnderstandingRetriever = class {
30
83
  });
31
84
  if (!profile.normalized) return [];
32
85
  const maxCandidates = Math.max(1, Math.min(200, Math.floor(params.maxCandidates)));
33
- const fts = searchActiveUnderstandings(profile.normalized, Math.max(50, maxCandidates));
86
+ const fts = searchActiveUnderstandings(profile.expanded, Math.max(50, maxCandidates));
34
87
  const ftsScores = new Map(fts.map((result) => [result.understanding.id, result.score]));
35
88
  const recentLimit = Math.max(200, Math.min(500, maxCandidates * 5));
36
- const recent = listUnderstandings(["active"]).slice(0, recentLimit);
89
+ const recent = listUnderstandings([...profile.timeHints.includes("historical") ? [
90
+ "active",
91
+ "archived",
92
+ "stale"
93
+ ] : ["active"]]).slice(0, recentLimit);
37
94
  const candidates = /* @__PURE__ */ new Map();
38
95
  for (const result of fts) candidates.set(result.understanding.id, result.understanding);
39
96
  for (const item of recent) candidates.set(item.id, item);
40
97
  const feedback = new Map(summarizeUnderstandingFeedback([...candidates.keys()]).map((summary) => [summary.understandingId, summary]));
41
- return [...candidates.values()].map((item) => {
42
- const lexical = retrievalLexicalSimilarity(profile.normalized, item.statement);
98
+ const now = Date.now();
99
+ return diversify([...candidates.values()].map((item) => {
100
+ const lexical = Math.max(retrievalLexicalSimilarity(profile.normalized, item.statement), retrievalLexicalSimilarity(profile.expanded, item.statement));
43
101
  const ftsScore = ftsScores.get(item.id) ?? 0;
44
102
  const textScore = Math.max(lexical, ftsScore);
45
103
  const kindMatched = profile.intentKinds.includes(item.kind);
46
104
  const normalizedStatement = normalizeRetrievalText(item.statement);
47
105
  const identifierMatched = profile.identifiers.some((identifier) => normalizedStatement.includes(identifier));
48
106
  const feedbackScore = feedbackAdjustment(feedback.get(item.id));
107
+ const kindAdjustment = profile.intentKinds.length > 0 && !kindMatched && profile.timeHints.length === 0 ? -.35 : 0;
49
108
  return {
50
109
  understanding: item,
51
- score: Math.min(1, Math.max(0, Math.max(baseline(item), textScore * .7 + lexical * .1 + item.confidence * .1 + authorityBonus(item) + (kindMatched ? .08 : 0) + (identifierMatched ? .12 : 0) + (matchesUserContextScope(item.scope, params) && item.scope.type !== "global" ? .05 : 0)) + feedbackScore)),
110
+ score: Math.min(1, Math.max(0, Math.max(baseline(item), textScore * .7 + lexical * .1 + item.confidence * .1 + authorityBonus(item) + (kindMatched ? .08 : 0) + kindAdjustment + (identifierMatched ? .12 : 0) + temporalAdjustment(item, profile.timeHints, now) + (matchesUserContextScope(item.scope, params) && item.scope.type !== "global" ? .05 : 0)) + feedbackScore)),
52
111
  reasons: [
53
112
  ftsScore > 0 ? "fts" : "",
54
113
  lexical > 0 ? "lexical" : "",
55
114
  identifierMatched ? "identifier" : "",
56
115
  kindMatched ? "kind" : "",
57
116
  item.explicitness === "explicit" ? "explicit" : "",
58
- feedbackScore !== 0 ? "feedback" : ""
117
+ feedbackScore !== 0 ? "feedback" : "",
118
+ temporalAdjustment(item, profile.timeHints, now) !== 0 ? "temporal" : ""
59
119
  ].filter(Boolean)
60
120
  };
61
- }).sort((left, right) => Number(matchesUserContextScope(right.understanding.scope, params)) - Number(matchesUserContextScope(left.understanding.scope, params)) || right.score - left.score || right.understanding.updatedAt - left.understanding.updatedAt).slice(0, maxCandidates);
121
+ }).sort((left, right) => Number(matchesUserContextScope(right.understanding.scope, params)) - Number(matchesUserContextScope(left.understanding.scope, params)) || right.score - left.score || right.understanding.updatedAt - left.understanding.updatedAt), maxCandidates);
62
122
  }
63
123
  };
64
124
  //#endregion
@@ -1,4 +1,4 @@
1
- import { createUnderstandingSourceRun, deleteUserFocus, getUnderstandingSourceGrant, getUnderstandingSourceRun, listUnderstandingSourceGrants, listUnderstandingSourceRuns, listUserFocuses, revokeUnderstandingSourceGrant, setUserFocusStatus, updateUnderstandingSourceGrantCheckpoint, updateUnderstandingSourceRun, upsertUnderstandingSourceGrant, upsertUserFocus } from "./repository.js";
1
+ import { createUnderstandingSourceRun, deleteUserFocus, getUnderstandingSourceGrant, getUnderstandingSourceRun, listUnderstandingSourceGrants, listUnderstandingSourceRuns, listUserFocusEvidence, listUserFocuses, revokeUnderstandingSourceGrant, updateUnderstandingSourceGrantCheckpoint, updateUnderstandingSourceGrantPolicies, updateUnderstandingSourceRun, updateUserFocus, upsertUnderstandingSourceGrant, upsertUserFocus } from "./repository.js";
2
2
  import { clusterUnderstandingSignals, tokenizeUnderstandingSignal } from "./signal-clustering.js";
3
3
  import { listUnderstandingSourceDefinitions } from "./catalog.js";
4
- export { clusterUnderstandingSignals, createUnderstandingSourceRun, deleteUserFocus, getUnderstandingSourceGrant, getUnderstandingSourceRun, listUnderstandingSourceDefinitions, listUnderstandingSourceGrants, listUnderstandingSourceRuns, listUserFocuses, revokeUnderstandingSourceGrant, setUserFocusStatus, tokenizeUnderstandingSignal, updateUnderstandingSourceGrantCheckpoint, updateUnderstandingSourceRun, upsertUnderstandingSourceGrant, upsertUserFocus };
4
+ export { clusterUnderstandingSignals, createUnderstandingSourceRun, deleteUserFocus, getUnderstandingSourceGrant, getUnderstandingSourceRun, listUnderstandingSourceDefinitions, listUnderstandingSourceGrants, listUnderstandingSourceRuns, listUserFocusEvidence, listUserFocuses, revokeUnderstandingSourceGrant, tokenizeUnderstandingSignal, updateUnderstandingSourceGrantCheckpoint, updateUnderstandingSourceGrantPolicies, updateUnderstandingSourceRun, updateUserFocus, upsertUnderstandingSourceGrant, upsertUserFocus };
@@ -0,0 +1,2 @@
1
+ import type { UnderstandingSourceProcessingPolicy } from './types.js';
2
+ export declare function allowsRemoteSourceProcessing(policies: Iterable<UnderstandingSourceProcessingPolicy>): boolean;
@@ -0,0 +1,7 @@
1
+ //#region src/user-context/sources/processing-policy.ts
2
+ function allowsRemoteSourceProcessing(policies) {
3
+ for (const policy of policies) if (policy !== "remote_allowed") return false;
4
+ return true;
5
+ }
6
+ //#endregion
7
+ export { allowsRemoteSourceProcessing };
@@ -1,4 +1,18 @@
1
+ import { type ContextEvidence, type UserContextScope } from '../domain.js';
1
2
  import type { UnderstandingSourceGrant, UnderstandingSourceRun, UserFocus } from './types.js';
3
+ type UserFocusInput = Omit<UserFocus, 'id' | 'versionId' | 'principalId' | 'scope' | 'explicitness' | 'sensitivity' | 'disclosurePolicy' | 'validFrom' | 'validTo' | 'reviewAt' | 'createdAt' | 'updatedAt'> & {
4
+ principalId?: string;
5
+ scope?: UserContextScope;
6
+ explicitness?: UserFocus['explicitness'];
7
+ sensitivity?: UserFocus['sensitivity'];
8
+ disclosurePolicy?: UserFocus['disclosurePolicy'];
9
+ validFrom?: number;
10
+ validTo?: number;
11
+ reviewAt?: number;
12
+ changeReason?: string;
13
+ nowMs?: number;
14
+ };
15
+ export declare function listUserFocusEvidence(focusId: string): ContextEvidence[];
2
16
  export declare function listUnderstandingSourceGrants(options?: {
3
17
  includeRevoked?: boolean;
4
18
  }): UnderstandingSourceGrant[];
@@ -13,6 +27,12 @@ export declare function updateUnderstandingSourceGrantCheckpoint(id: string, inp
13
27
  lastCollectedAt?: number;
14
28
  nowMs?: number;
15
29
  }): UnderstandingSourceGrant | null;
30
+ export declare function updateUnderstandingSourceGrantPolicies(id: string, patch: {
31
+ accessMode?: UnderstandingSourceGrant['accessMode'];
32
+ retentionPolicy?: UnderstandingSourceGrant['retentionPolicy'];
33
+ processingPolicy?: UnderstandingSourceGrant['processingPolicy'];
34
+ nowMs?: number;
35
+ }): UnderstandingSourceGrant | null;
16
36
  export declare function revokeUnderstandingSourceGrant(id: string, nowMs?: number): UnderstandingSourceGrant | null;
17
37
  export declare function createUnderstandingSourceRun(input: {
18
38
  grantId: string;
@@ -33,9 +53,8 @@ export declare function updateUnderstandingSourceRun(id: string, patch: {
33
53
  completed?: boolean;
34
54
  nowMs?: number;
35
55
  }): UnderstandingSourceRun | null;
36
- export declare function upsertUserFocus(input: Omit<UserFocus, 'id' | 'createdAt' | 'updatedAt'> & {
37
- nowMs?: number;
38
- }): UserFocus;
56
+ export declare function upsertUserFocus(input: UserFocusInput): UserFocus;
39
57
  export declare function listUserFocuses(statuses?: UserFocus['status'][]): UserFocus[];
40
- export declare function setUserFocusStatus(id: string, status: UserFocus['status'], nowMs?: number): UserFocus | null;
58
+ export declare function updateUserFocus(id: string, patch: Partial<Pick<UserFocus, 'title' | 'summary' | 'status'>>, nowMs?: number): UserFocus | null;
41
59
  export declare function deleteUserFocus(id: string): boolean;
60
+ export {};