@xopcai/xopc 0.0.218 → 0.0.219

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 (326) 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-slG02hSm.js} +1 -1
  4. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-Dw9rF5o1.js → agent-avatar-dicebear-DZ6ETNIk.js} +1 -1
  5. package/dist/gateway/static/root/assets/agents-DxaIH0Ep.js +68 -0
  6. package/dist/gateway/static/root/assets/{api-_H0Bam-t.js → api-Tz57QxiN.js} +1 -1
  7. package/dist/gateway/static/root/assets/app-management-settings-panel-DdR1L4LR.js +1 -0
  8. package/dist/gateway/static/root/assets/appearance-settings-wYbwqmee.js +1 -0
  9. package/dist/gateway/static/root/assets/apps-page-CyWr6KyO.js +1 -0
  10. package/dist/gateway/static/root/assets/{archive-plugin-DZCOhXch.js → archive-plugin-DKXa160O.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-Bjb0FH2B.js → attachment-load-CzwA9g2y.js} +1 -1
  12. package/dist/gateway/static/root/assets/{automations-page-D4N3ZDhu.js → automations-page-DwAXyWAY.js} +1 -1
  13. package/dist/gateway/static/root/assets/automations-workspace-CL7ieYIt.js +6 -0
  14. package/dist/gateway/static/root/assets/{binary-plugins-uXPt0s47.js → binary-plugins-DoQ_DnT7.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-gukkIEro.js → block-editor-Bj_Uxxng.js} +47 -47
  16. package/dist/gateway/static/root/assets/browser-settings-page-BYa_FNC1.js +8 -0
  17. package/dist/gateway/static/root/assets/{browser-workflow-inputs-DAhdS-XZ.js → browser-workflow-inputs-D4roXE6r.js} +1 -1
  18. package/dist/gateway/static/root/assets/{browser-workflows-page-LKjYzXS_.js → browser-workflows-page-CleKTAKD.js} +2 -2
  19. package/dist/gateway/static/root/assets/capabilities-settings-panel-DYG37N0k.js +7 -0
  20. package/dist/gateway/static/root/assets/{capability-presets-api-BBUkH833.js → capability-presets-api-wtEN6Ss6.js} +1 -1
  21. package/dist/gateway/static/root/assets/capability-presets-settings-panel-C0Q4dFq-.js +3 -0
  22. package/dist/gateway/static/root/assets/{channel-recipient-api-E5mo8M3a.js → channel-recipient-api-DhuS2RJ3.js} +1 -1
  23. package/dist/gateway/static/root/assets/channels-settings-CpO6Xg0n.js +1 -0
  24. package/dist/gateway/static/root/assets/channels-status-swr-CXhPeiNj.js +1 -0
  25. package/dist/gateway/static/root/assets/chat-terminal-dock-ClQMDe2n.js +36 -0
  26. package/dist/gateway/static/root/assets/connectors-page-BvyiPdKU.js +2 -0
  27. package/dist/gateway/static/root/assets/{cron-expression-BGNuaqvI.js → cron-expression-4DvCFs-v.js} +1 -1
  28. package/dist/gateway/static/root/assets/{date-picker-k7mkklMU.js → date-picker-B6FSjt4Z.js} +1 -1
  29. package/dist/gateway/static/root/assets/dependency-picker-Za18eMp1.js +1 -0
  30. package/dist/gateway/static/root/assets/{desktop-pet-p9EZyGzV.js → desktop-pet-DUUf3yyJ.js} +1 -1
  31. package/dist/gateway/static/root/assets/desktop-pet-settings-Dwx3GfB8.js +1 -0
  32. package/dist/gateway/static/root/assets/directory-picker-path-field-C6dfTCsl.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-Cordpg4X.js} +1 -1
  35. package/dist/gateway/static/root/assets/{extension-page-CzEGCkOa.js → extension-page-Dw0dGyMl.js} +1 -1
  36. package/dist/gateway/static/root/assets/extension-settings-page-B2pUMaXm.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-DAZUOEQh.js +1 -0
  42. package/dist/gateway/static/root/assets/{gateway-config-swr-DNrttVr2.js → gateway-config-swr-BIqRg-zo.js} +1 -1
  43. package/dist/gateway/static/root/assets/gateway-settings-ik2f-pmV.js +1 -0
  44. package/dist/gateway/static/root/assets/{gateway-startup-retry-B1vD3vRb.js → gateway-startup-retry-BFjWYOCS.js} +1 -1
  45. package/dist/gateway/static/root/assets/heartbeat-settings-BE81XJ8F.js +1 -0
  46. package/dist/gateway/static/root/assets/home-page-BTWXJu_m.js +1 -0
  47. package/dist/gateway/static/root/assets/{image-generation-api-BTR0Wk_k.js → image-generation-api-HXAWlgm6.js} +1 -1
  48. package/dist/gateway/static/root/assets/index-B6gWYy08.js +108 -0
  49. package/dist/gateway/static/root/assets/index-CDkuz_YC.css +2 -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-ROqQ_Xlo.js} +1 -1
  53. package/dist/gateway/static/root/assets/local-app-workbench-page-Dcaf190G.js +2 -0
  54. package/dist/gateway/static/root/assets/{local-apps-page-CNppYVew.js → local-apps-page-Be79cyMG.js} +1 -1
  55. package/dist/gateway/static/root/assets/{locale-store-gf9Bg2gb.js → locale-store-DfK-Hofd.js} +1 -1
  56. package/dist/gateway/static/root/assets/logs-page-C2pjbXno.js +2 -0
  57. package/dist/gateway/static/root/assets/{management-settings-IYk9xLgt.js → management-settings-CRspx0oY.js} +1 -1
  58. package/dist/gateway/static/root/assets/{markdown-split-D8e6pRMH.js → markdown-split-G3PTpGw3.js} +1 -1
  59. package/dist/gateway/static/root/assets/{markdown-view-D0fiJjBQ.js → markdown-view-D4FPJZ91.js} +1 -1
  60. package/dist/gateway/static/root/assets/{media-plugins-CCq6TtEf.js → media-plugins-DT0P7j7u.js} +1 -1
  61. package/dist/gateway/static/root/assets/messages-B701TEZ5.js +3 -0
  62. package/dist/gateway/static/root/assets/{notes-api-BBtWnlUU.js → notes-api-q7HjYO07.js} +1 -1
  63. package/dist/gateway/static/root/assets/{notes-page-BKe1xa3U.js → notes-page-Cgl2h7AR.js} +1 -1
  64. package/dist/gateway/static/root/assets/notes-workbench-DFMQYyGJ.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-ComKLO4D.js} +1 -1
  68. package/dist/gateway/static/root/assets/project-detail-page-DUFmQscH.js +1 -0
  69. package/dist/gateway/static/root/assets/projects-page-CTWxt3dv.js +1 -0
  70. package/dist/gateway/static/root/assets/{registry-api-xj5gOva_.js → registry-api-BBoJ7khF.js} +1 -1
  71. package/dist/gateway/static/root/assets/remote-access-hub-qmG-3qjj.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-CXHQc53b.js} +2 -2
  74. package/dist/gateway/static/root/assets/{schema-form-DvGBa_7R.js → schema-form-3jTDF2lJ.js} +1 -1
  75. package/dist/gateway/static/root/assets/search-DA7gz22f.js +1 -0
  76. package/dist/gateway/static/root/assets/sessions-page-D_We4_MV.js +1 -0
  77. package/dist/gateway/static/root/assets/settings-advanced-gate-B_QhPgU0.js +1 -0
  78. package/dist/gateway/static/root/assets/settings-form-section-CUDozALU.js +1 -0
  79. package/dist/gateway/static/root/assets/{settings-loading-skeleton-sbef7GTm.js → settings-loading-skeleton-H3ZH6a6l.js} +1 -1
  80. package/dist/gateway/static/root/assets/{settings-page-BNGxxXZe.js → settings-page-tx29z21o.js} +1 -1
  81. package/dist/gateway/static/root/assets/setup-status-panel-VunfXpTX.js +1 -0
  82. package/dist/gateway/static/root/assets/{share-preview-page-C1523ij3.js → share-preview-page-MyThymEx.js} +1 -1
  83. package/dist/gateway/static/root/assets/shares-settings-DkZvY1cr.js +1 -0
  84. package/dist/gateway/static/root/assets/skill-reload-api-DVDOh1iY.js +1 -0
  85. package/dist/gateway/static/root/assets/skills-page-BOOyMnno.js +2 -0
  86. package/dist/gateway/static/root/assets/{skills-page.utils-Ditgz7Vo.js → skills-page.utils-Bl5Yv3Cx.js} +1 -1
  87. package/dist/gateway/static/root/assets/system-settings-panel-DwQ3O1ta.js +1 -0
  88. package/dist/gateway/static/root/assets/task-detail-page-BwOyrADL.js +1 -0
  89. package/dist/gateway/static/root/assets/{theme-store-DgSjes3O.js → theme-store-Br4BtK4x.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-DRS3RwS9.js} +1 -1
  92. package/dist/gateway/static/root/assets/user-context-page-ClV2r3Cr.js +1 -0
  93. package/dist/gateway/static/root/assets/{voice-api-key-field-hbzDfErG.js → voice-api-key-field-CGTE5156.js} +1 -1
  94. package/dist/gateway/static/root/assets/{work-discovery-overlay-DZVib-04.js → work-discovery-overlay-CW-HKD7h.js} +1 -1
  95. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-C2RKay1p.js → workflow-run-setup-panel-Dtr9fDC8.js} +2 -2
  96. package/dist/gateway/static/root/assets/workflows-page-CDOyNgZf.js +5 -0
  97. package/dist/gateway/static/root/index.html +20 -11
  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/extension-marketplace.js +1 -1
  155. package/dist/src/cli/commands/extension.js +1 -1
  156. package/dist/src/cli/commands/models.js +1 -1
  157. package/dist/src/config/index.js +4 -4
  158. package/dist/src/config/loader.js +1 -1
  159. package/dist/src/config/models-json.d.ts +20 -20
  160. package/dist/src/config/models-json.js +1 -1
  161. package/dist/src/connectors/connected-source-understanding.d.ts +1 -0
  162. package/dist/src/connectors/connected-source-understanding.js +82 -34
  163. package/dist/src/connectors/learning-coordinator.js +57 -11
  164. package/dist/src/extensions/lockfile.js +1 -1
  165. package/dist/src/extensions/update.js +1 -1
  166. package/dist/src/gateway/agents-admin.js +1 -1
  167. package/dist/src/gateway/chat-stream/mapper.js +18 -0
  168. package/dist/src/gateway/file-path-classifier.js +1 -1
  169. package/dist/src/gateway/hono/lib/config-payload.js +1 -1
  170. package/dist/src/gateway/hono/routes/agent-stream.js +12 -2
  171. package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
  172. package/dist/src/gateway/hono/routes/commands-skills.js +1 -0
  173. package/dist/src/gateway/hono/routes/models.js +1 -1
  174. package/dist/src/gateway/hono/routes/session-input-handler.d.ts +46 -2
  175. package/dist/src/gateway/hono/routes/session-input-handler.js +23 -3
  176. package/dist/src/gateway/hono/routes/sessions.js +17 -20
  177. package/dist/src/gateway/hono/routes/tasks.js +25 -0
  178. package/dist/src/gateway/hono/routes/understanding-sources.d.ts +9 -0
  179. package/dist/src/gateway/hono/routes/understanding-sources.js +127 -31
  180. package/dist/src/gateway/hono/routes/workflows.js +2 -2
  181. package/dist/src/gateway/hono/routes/you.js +71 -4
  182. package/dist/src/gateway/service/agent-runner.d.ts +7 -2
  183. package/dist/src/gateway/service/agent-runner.js +21 -1
  184. package/dist/src/gateway/service/config-coordinator.js +2 -2
  185. package/dist/src/gateway/service/run-gateway-agent.d.ts +2 -0
  186. package/dist/src/gateway/service/run-gateway-agent.js +2 -1
  187. package/dist/src/gateway/service/session-input-coordinator.d.ts +8 -2
  188. package/dist/src/gateway/service/session-input-coordinator.js +62 -3
  189. package/dist/src/gateway/service/sessions-api.d.ts +1 -0
  190. package/dist/src/gateway/service.d.ts +3 -2
  191. package/dist/src/gateway/service.js +25 -15
  192. package/dist/src/gateway/user-turn-input.d.ts +2 -0
  193. package/dist/src/gateway/xopc-cloud-capability-setup.d.ts +3 -2
  194. package/dist/src/gateway/xopc-cloud-capability-setup.js +16 -3
  195. package/dist/src/infra/update-runner.js +1 -1
  196. package/dist/src/knowledge/connected-understanding-pipeline.d.ts +1 -1
  197. package/dist/src/knowledge/connected-understanding-pipeline.js +4 -2
  198. package/dist/src/providers/auth-runtime/resolve-auth.js +1 -1
  199. package/dist/src/providers/index.js +2 -2
  200. package/dist/src/providers/model-registry.js +1 -1
  201. package/dist/src/providers/register-runtime-providers.js +1 -1
  202. package/dist/src/retrieval/queryProfile.d.ts +1 -0
  203. package/dist/src/retrieval/queryProfile.js +9 -1
  204. package/dist/src/session/client-history.d.ts +11 -0
  205. package/dist/src/session/client-history.js +24 -2
  206. package/dist/src/session/config-types.d.ts +1 -1
  207. package/dist/src/session/session-title.js +2 -3
  208. package/dist/src/session/store.js +1 -0
  209. package/dist/src/session/transcript-outline.js +5 -2
  210. package/dist/src/session/types.d.ts +1 -0
  211. package/dist/src/session/user-message-display.d.ts +4 -0
  212. package/dist/src/session/user-message-display.js +22 -0
  213. package/dist/src/storage/sqlite/context-extraction-repository.d.ts +57 -0
  214. package/dist/src/storage/sqlite/context-extraction-repository.js +119 -0
  215. package/dist/src/storage/sqlite/context-relation-repository.d.ts +50 -0
  216. package/dist/src/storage/sqlite/context-relation-repository.js +97 -0
  217. package/dist/src/storage/sqlite/index.d.ts +4 -2
  218. package/dist/src/storage/sqlite/index.js +5 -3
  219. package/dist/src/storage/sqlite/migrations/126_focus_context_governance.sql +72 -0
  220. package/dist/src/storage/sqlite/migrations/127_context_object_origin.sql +36 -0
  221. package/dist/src/storage/sqlite/migrations/128_context_extraction.sql +73 -0
  222. package/dist/src/storage/sqlite/migrations/129_focus_versions.sql +51 -0
  223. package/dist/src/storage/sqlite/migrations/130_context_evidence_provenance.sql +18 -0
  224. package/dist/src/storage/sqlite/migrations/131_session_input_contexts.sql +2 -0
  225. package/dist/src/storage/sqlite/migrations/132_transcript_source_context_metadata.sql +34 -0
  226. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  227. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  228. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  229. package/dist/src/storage/sqlite/schema.js +1 -1
  230. package/dist/src/storage/sqlite/session-input-repository.d.ts +8 -0
  231. package/dist/src/storage/sqlite/session-input-repository.js +19 -7
  232. package/dist/src/storage/sqlite/session-turn-replace-repository.d.ts +3 -0
  233. package/dist/src/storage/sqlite/session-turn-replace-repository.js +3 -2
  234. package/dist/src/storage/sqlite/transcript-repository.js +29 -3
  235. package/dist/src/storage/sqlite/user-context-repository.d.ts +4 -1
  236. package/dist/src/storage/sqlite/user-context-repository.js +65 -29
  237. package/dist/src/tasks/index.d.ts +1 -0
  238. package/dist/src/tasks/index.js +2 -1
  239. package/dist/src/tasks/task-deletion-service.d.ts +21 -0
  240. package/dist/src/tasks/task-deletion-service.js +35 -0
  241. package/dist/src/tasks/task-repository.js +22 -1
  242. package/dist/src/tui/backends/embedded-backend.js +5 -3
  243. package/dist/src/tui/backends/gateway-realtime-backend.js +5 -3
  244. package/dist/src/tui/chat-history.js +2 -1
  245. package/dist/src/tui/tui-agent-events.js +4 -2
  246. package/dist/src/tui/tui-commands.d.ts +1 -0
  247. package/dist/src/tui/tui-commands.js +8 -3
  248. package/dist/src/tui/tui-empty-session-cleanup.d.ts +0 -1
  249. package/dist/src/tui/tui-empty-session-cleanup.js +1 -11
  250. package/dist/src/tui/tui-new-session-preferences.d.ts +10 -0
  251. package/dist/src/tui/tui-new-session-preferences.js +32 -0
  252. package/dist/src/tui/tui-session-actions.d.ts +1 -0
  253. package/dist/src/tui/tui-session-actions.js +2 -1
  254. package/dist/src/tui/tui-settings.d.ts +2 -0
  255. package/dist/src/tui/tui-settings.js +4 -1
  256. package/dist/src/tui/tui-startup-resources.js +1 -1
  257. package/dist/src/tui/tui-types.d.ts +1 -0
  258. package/dist/src/tui/tui.js +58 -5
  259. package/dist/src/tunnel/frpc-process.js +3 -0
  260. package/dist/src/tunnel/tunnel-service.d.ts +2 -0
  261. package/dist/src/tunnel/tunnel-service.js +40 -28
  262. package/dist/src/user-context/context-objects.d.ts +17 -0
  263. package/dist/src/user-context/context-objects.js +99 -0
  264. package/dist/src/user-context/domain.d.ts +13 -1
  265. package/dist/src/user-context/evaluation/harness.d.ts +13 -0
  266. package/dist/src/user-context/evaluation/harness.js +31 -0
  267. package/dist/src/user-context/extraction/registry.d.ts +26 -0
  268. package/dist/src/user-context/extraction/registry.js +113 -0
  269. package/dist/src/user-context/extraction/repair.d.ts +19 -0
  270. package/dist/src/user-context/extraction/repair.js +68 -0
  271. package/dist/src/user-context/planner.js +214 -57
  272. package/dist/src/user-context/retriever.js +69 -9
  273. package/dist/src/user-context/sources/index.js +2 -2
  274. package/dist/src/user-context/sources/processing-policy.d.ts +2 -0
  275. package/dist/src/user-context/sources/processing-policy.js +7 -0
  276. package/dist/src/user-context/sources/repository.d.ts +23 -4
  277. package/dist/src/user-context/sources/repository.js +122 -12
  278. package/dist/src/user-context/sources/types.d.ts +10 -1
  279. package/dist/src/user-context/understanding.js +1 -1
  280. package/dist/src/work-discovery/service.js +21 -5
  281. package/dist/src/work-discovery/source-repository.js +1 -1
  282. package/dist/src/workflows/service/workflow-run-service.js +1 -1
  283. package/package.json +3 -3
  284. package/dist/gateway/static/root/assets/agents-Dj86bHkl.js +0 -68
  285. package/dist/gateway/static/root/assets/app-management-settings-panel-D-M6GN-8.js +0 -1
  286. package/dist/gateway/static/root/assets/appearance-settings-XDhmzdIc.js +0 -1
  287. package/dist/gateway/static/root/assets/apps-page-sfO835uz.js +0 -1
  288. package/dist/gateway/static/root/assets/automations-workspace-PptuZgoo.js +0 -6
  289. package/dist/gateway/static/root/assets/browser-settings-page-BoCmzMFV.js +0 -8
  290. package/dist/gateway/static/root/assets/capabilities-settings-panel-DhkJsU8Z.js +0 -7
  291. package/dist/gateway/static/root/assets/capability-presets-settings-panel-Dm7T61fE.js +0 -3
  292. package/dist/gateway/static/root/assets/channels-settings-dG6UFVqt.js +0 -1
  293. package/dist/gateway/static/root/assets/channels-status-swr-DgJxfNyK.js +0 -1
  294. package/dist/gateway/static/root/assets/chat-terminal-dock-CT5yoSMD.js +0 -36
  295. package/dist/gateway/static/root/assets/connectors-page-BC6Ft9SU.js +0 -2
  296. package/dist/gateway/static/root/assets/dependency-picker-DZVSgLXH.js +0 -1
  297. package/dist/gateway/static/root/assets/desktop-pet-settings-Bw4cCFzI.js +0 -1
  298. package/dist/gateway/static/root/assets/directory-picker-path-field-Cbst7IXR.js +0 -1
  299. package/dist/gateway/static/root/assets/extension-settings-page-C1PAKSy2.js +0 -1
  300. package/dist/gateway/static/root/assets/gateway-config-api-Bch9vO6t.js +0 -1
  301. package/dist/gateway/static/root/assets/gateway-settings-DkDxZFGG.js +0 -1
  302. package/dist/gateway/static/root/assets/heartbeat-settings-DXNMxy5b.js +0 -1
  303. package/dist/gateway/static/root/assets/home-page-CYcpVFNT.js +0 -1
  304. package/dist/gateway/static/root/assets/index-Dgb1R07E.css +0 -2
  305. package/dist/gateway/static/root/assets/index-DlOYwVFK.js +0 -108
  306. package/dist/gateway/static/root/assets/local-app-workbench-page-BFrgPwGE.js +0 -2
  307. package/dist/gateway/static/root/assets/logs-page-CPweLw3k.js +0 -2
  308. package/dist/gateway/static/root/assets/messages-B9WQcZ1V.js +0 -3
  309. package/dist/gateway/static/root/assets/notes-workbench-wieRAd1y.js +0 -4
  310. package/dist/gateway/static/root/assets/page-tabs-Bsluqyfb.js +0 -1
  311. package/dist/gateway/static/root/assets/preview-open-alternatives-BrpTWv44.js +0 -1
  312. package/dist/gateway/static/root/assets/project-detail-page-Cww6V7HJ.js +0 -1
  313. package/dist/gateway/static/root/assets/projects-page-D0LKhCCw.js +0 -1
  314. package/dist/gateway/static/root/assets/remote-access-hub-Sf4Pde6Z.js +0 -1
  315. package/dist/gateway/static/root/assets/sessions-page-S5gvgfu5.js +0 -1
  316. package/dist/gateway/static/root/assets/settings-advanced-gate-B3XvdEy8.js +0 -1
  317. package/dist/gateway/static/root/assets/settings-form-section-CiGFtdD8.js +0 -1
  318. package/dist/gateway/static/root/assets/setup-status-panel-CGU_Mxjr.js +0 -1
  319. package/dist/gateway/static/root/assets/shares-settings-k0UQ8WxO.js +0 -1
  320. package/dist/gateway/static/root/assets/skill-reload-api-DQ1GvL1w.js +0 -1
  321. package/dist/gateway/static/root/assets/skills-page-OuHd9GcN.js +0 -2
  322. package/dist/gateway/static/root/assets/system-settings-panel-CERqCsz2.js +0 -1
  323. package/dist/gateway/static/root/assets/task-detail-page-BnRNL2sn.js +0 -1
  324. package/dist/gateway/static/root/assets/typed-models-lib-abEJNkCO.js +0 -1
  325. package/dist/gateway/static/root/assets/user-context-page-Cnkaiky5.js +0 -1
  326. package/dist/gateway/static/root/assets/workflows-page-B_VlcKiK.js +0 -5
@@ -0,0 +1,68 @@
1
+ import { hasIndependentExtractionOutput, listContextExtractionOutputs, listContextExtractionRuns } from "../../storage/sqlite/context-extraction-repository.js";
2
+ import { getUnderstanding, setUnderstandingStatus } from "../../storage/sqlite/user-context-repository.js";
3
+ import "../../storage/sqlite/index.js";
4
+ import { listUserFocuses, updateUserFocus } from "../sources/repository.js";
5
+ //#region src/user-context/extraction/repair.ts
6
+ function repairExtractedContext(filter) {
7
+ const runs = listContextExtractionRuns({
8
+ ...filter.sourceRef ? { sourceRef: filter.sourceRef } : {},
9
+ ...filter.extractorId ? { extractorId: filter.extractorId } : {},
10
+ ...filter.extractorVersion ? { extractorVersion: filter.extractorVersion } : {},
11
+ limit: 500
12
+ }).filter((run) => !filter.runId || run.id === filter.runId);
13
+ const repaired = [];
14
+ const retained = [];
15
+ const seen = /* @__PURE__ */ new Set();
16
+ const targetRunIds = runs.map((run) => run.id);
17
+ for (const run of runs) for (const output of listContextExtractionOutputs(run.id)) {
18
+ if (output.objectType !== "focus" && output.objectType !== "understanding" || !output.objectId) continue;
19
+ if (filter.objectVersionId && output.versionId !== filter.objectVersionId) continue;
20
+ const key = `${output.objectType}:${output.objectId}`;
21
+ if (seen.has(key)) continue;
22
+ seen.add(key);
23
+ if (hasIndependentExtractionOutput(targetRunIds, output.objectType, output.objectId)) {
24
+ retained.push({
25
+ objectType: output.objectType,
26
+ objectId: output.objectId,
27
+ reason: "independent_extraction"
28
+ });
29
+ continue;
30
+ }
31
+ if (output.objectType === "understanding") {
32
+ const understanding = getUnderstanding(output.objectId);
33
+ if (!understanding) continue;
34
+ if (understanding.explicitness === "explicit") {
35
+ retained.push({
36
+ objectType: "understanding",
37
+ objectId: output.objectId,
38
+ reason: "user_explicit"
39
+ });
40
+ continue;
41
+ }
42
+ setUnderstandingStatus(output.objectId, "archived");
43
+ } else {
44
+ const focus = listUserFocuses().find((item) => item.id === output.objectId);
45
+ if (!focus) continue;
46
+ if (focus.explicitness === "explicit") {
47
+ retained.push({
48
+ objectType: "focus",
49
+ objectId: output.objectId,
50
+ reason: "user_explicit"
51
+ });
52
+ continue;
53
+ }
54
+ updateUserFocus(output.objectId, { status: "paused" });
55
+ }
56
+ repaired.push({
57
+ objectType: output.objectType,
58
+ objectId: output.objectId
59
+ });
60
+ }
61
+ return {
62
+ runIds: runs.map((run) => run.id),
63
+ repaired,
64
+ retained
65
+ };
66
+ }
67
+ //#endregion
68
+ export { repairExtractedContext };
@@ -1,14 +1,20 @@
1
- import { consumeContextConsent, ensureContextConsent, getUserProfile, listCollaborationRules, recordContextRun } from "../storage/sqlite/user-context-repository.js";
1
+ import { consumeContextConsent, ensureContextConsent, getUserProfile, listCollaborationRules, listUnderstandingEvidence, 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";
3
6
  import { readAgentMessageContent } from "../agent/memory/agent-message-access.js";
4
7
  import { buildUserContextBlock } from "../agent/memory/context-fence.js";
5
- import { listUserFocuses } from "./sources/repository.js";
8
+ import { getUnderstandingSourceGrant, getUnderstandingSourceRun, listUserFocuses } from "./sources/repository.js";
6
9
  import { matchesUserContextScope } from "./scope.js";
7
10
  import { UserUnderstandingRetriever } from "./retriever.js";
8
11
  import { randomUUID } from "node:crypto";
9
12
  //#region src/user-context/planner.ts
13
+ init_session_key();
10
14
  const DEFAULT_MAX_CONTEXT_CHARS = 6e3;
11
15
  const DEFAULT_MAX_RESULTS = 12;
16
+ const MAX_FOCUS_RESULTS = 3;
17
+ const MIN_RELEVANCE_SCORE = .25;
12
18
  function prependAgentContext(message, block) {
13
19
  if (!block) return message;
14
20
  const prefix = `${block}\n\n`;
@@ -44,29 +50,82 @@ function sectionFor(item) {
44
50
  ].includes(item.kind)) return "interaction";
45
51
  return "task";
46
52
  }
47
- function originFor(item) {
48
- if (item.explicitness === "explicit") return "told_by_user";
49
- if (item.explicitness === "observed") return "observed";
50
- return "inferred";
53
+ function sourceDescription(item) {
54
+ if (item.explicitness === "explicit") return {
55
+ origin: "told_by_user",
56
+ label: "You told xopc"
57
+ };
58
+ const connected = listUnderstandingEvidence(item.id).find((evidence) => evidence.sourceType === "connector");
59
+ if (connected) return {
60
+ origin: "connected_source",
61
+ label: connected.sourceInstanceId ?? "Connected source"
62
+ };
63
+ if (item.explicitness === "observed") return {
64
+ origin: "observed",
65
+ label: "Observed across prior work"
66
+ };
67
+ return {
68
+ origin: "inferred",
69
+ label: "An inference that may be wrong"
70
+ };
51
71
  }
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";
72
+ function focusSourceDescription(focus) {
73
+ if (focus.explicitness === "explicit") return {
74
+ origin: "told_by_user",
75
+ label: "You set this focus"
76
+ };
77
+ const sourceRun = focus.sourceRunId ? getUnderstandingSourceRun(focus.sourceRunId) : null;
78
+ const grant = sourceRun ? getUnderstandingSourceGrant(sourceRun.grantId) : null;
79
+ if (grant?.adapterId.startsWith("connector:")) return {
80
+ origin: "connected_source",
81
+ label: grant.displayName
82
+ };
83
+ if (focus.explicitness === "observed") return {
84
+ origin: "observed",
85
+ label: "Observed across prior work"
86
+ };
87
+ return {
88
+ origin: "inferred",
89
+ label: "Suggested from prior work"
90
+ };
56
91
  }
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";
92
+ function rejectionReason(item, input, now, timeHints) {
93
+ const historical = timeHints.includes("historical") && item.validTo !== void 0;
94
+ if (item.status === "needs_review" || item.status === "candidate" || item.status === "stale" && !historical) return "needs_review";
95
+ if (item.status === "rejected" || item.status === "archived" && !historical) return "disabled";
60
96
  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";
97
+ if (item.validFrom && item.validFrom > now && !timeHints.includes("future")) return "not_yet_valid";
98
+ if ((item.validTo && item.validTo < now || item.expiresAt && item.expiresAt < now) && !historical) return "expired";
63
99
  if (item.sensitivity === "secret" || item.sensitivity === "regulated") return "sensitive";
64
100
  if (item.conflictGroupId) return "conflict";
65
101
  }
66
102
  function ruleMatches(rule, input) {
67
103
  if (rule.status !== "active" || !matchesUserContextScope(rule.scope, input)) return false;
68
104
  const channel = typeof rule.conditions.channel === "string" ? rule.conditions.channel : void 0;
69
- return !channel || channel === input.channel;
105
+ const agentId = typeof rule.conditions.agentId === "string" ? rule.conditions.agentId : void 0;
106
+ return (!channel || channel === input.channel) && (!agentId || agentId === input.agentId);
107
+ }
108
+ function focusRejectionReason(focus, input, now) {
109
+ if (focus.status !== "active") return "disabled";
110
+ if (!matchesUserContextScope(focus.scope, input)) return "scope_mismatch";
111
+ if (focus.validFrom && focus.validFrom > now) return "not_yet_valid";
112
+ if (focus.validTo && focus.validTo < now) return "expired";
113
+ if (focus.sensitivity === "secret" || focus.sensitivity === "regulated") return "sensitive";
114
+ if (focus.disclosurePolicy === "ask_before_reference") return "requires_consent";
115
+ }
116
+ function focusScore(focus, query, scopeInput) {
117
+ const lexical = retrievalLexicalSimilarity(buildRetrievalQueryProfile(query, scopeInput).normalized, `${focus.title} ${focus.summary}`);
118
+ const scoped = focus.scope.type !== "global" && matchesUserContextScope(focus.scope, scopeInput);
119
+ return Math.min(1, lexical * .75 + focus.confidence * .15 + (scoped ? .25 : 0));
120
+ }
121
+ function renderContextBlock(params) {
122
+ const understandingItems = params.items.filter((item) => item.objectType === "understanding");
123
+ return [
124
+ params.profileLines.length ? `<user-profile>\n${params.profileLines.join("\n")}\n</user-profile>` : "",
125
+ params.focuses.length ? `<active-focuses>\n${params.focuses.map((focus) => `- ${focus.title}: ${focus.summary} (${focus.horizon})`).join("\n")}\n</active-focuses>` : "",
126
+ params.rules.length ? `<collaboration-contract>\n${params.rules.map((rule) => `- ${rule.statement}`).join("\n")}\n</collaboration-contract>` : "",
127
+ understandingItems.length ? buildUserContextBlock(understandingItems.map((item) => `- ${item.content}\n Evidence: ${params.understandingSources.get(item.recordId) ?? "Unknown source"}`).join("\n")) : ""
128
+ ].filter(Boolean).join("\n\n");
70
129
  }
71
130
  var UserContextPlanner = class {
72
131
  retriever = new UserUnderstandingRetriever();
@@ -91,12 +150,24 @@ var UserContextPlanner = class {
91
150
  workspaceId: params.workspaceId,
92
151
  ...params.projectId ? { projectId: params.projectId } : {}
93
152
  };
153
+ const queryProfile = buildRetrievalQueryProfile(query, scopeInput);
94
154
  const excluded = new Set(params.excludedRecordIds ?? []);
95
155
  const rejected = [];
96
156
  const consentRequests = [];
97
157
  const traceItems = [];
98
158
  const items = [];
159
+ const selectedFocuses = [];
160
+ const selectedRules = [];
161
+ const understandingSources = /* @__PURE__ */ new Map();
99
162
  let usedChars = 0;
163
+ const render = (overrides = {}) => renderContextBlock({
164
+ profileLines,
165
+ focuses: selectedFocuses,
166
+ rules: selectedRules,
167
+ items,
168
+ understandingSources,
169
+ ...overrides
170
+ });
100
171
  const profile = getUserProfile();
101
172
  const profileLines = [
102
173
  profile.callName ? `Preferred name: ${profile.callName}` : "",
@@ -108,28 +179,103 @@ var UserContextPlanner = class {
108
179
  ].filter(Boolean);
109
180
  if (profileLines.length) {
110
181
  const content = profileLines.join("\n");
182
+ const nextChars = render().length;
183
+ if (nextChars <= maxChars) {
184
+ traceItems.push({
185
+ objectType: "profile",
186
+ objectId: "profile",
187
+ decision: "selected",
188
+ reason: "User-provided profile",
189
+ content,
190
+ sourceLabel: "You provided this directly",
191
+ origin: "told_by_user",
192
+ rank: 0,
193
+ score: 1,
194
+ injectedChars: nextChars
195
+ });
196
+ usedChars = nextChars;
197
+ } else {
198
+ profileLines.length = 0;
199
+ traceItems.push({
200
+ objectType: "profile",
201
+ objectId: "profile",
202
+ decision: "budget_exceeded",
203
+ reason: "Context budget reached",
204
+ content,
205
+ sourceLabel: "You provided this directly",
206
+ origin: "told_by_user",
207
+ injectedChars: 0
208
+ });
209
+ }
210
+ }
211
+ const rankedFocuses = listUserFocuses(["active"]).map((focus) => ({
212
+ focus,
213
+ score: focusScore(focus, query, scopeInput)
214
+ })).sort((left, right) => right.score - left.score || right.focus.updatedAt - left.focus.updatedAt);
215
+ for (const { focus, score } of rankedFocuses) {
216
+ const source = focusSourceDescription(focus);
217
+ let reason = focusRejectionReason(focus, scopeInput, now);
218
+ if (!reason && score <= MIN_RELEVANCE_SCORE) reason = "low_score";
219
+ if (!reason && selectedFocuses.length >= MAX_FOCUS_RESULTS) reason = "budget";
220
+ if (!reason && items.length >= maxResults) reason = "budget";
221
+ const content = `${focus.title}: ${focus.summary} (${focus.horizon})`;
222
+ const nextChars = render({ focuses: [...selectedFocuses, focus] }).length;
223
+ if (!reason && nextChars > maxChars) reason = "budget";
224
+ if (reason) {
225
+ rejected.push({
226
+ recordId: focus.id,
227
+ reason
228
+ });
229
+ traceItems.push({
230
+ objectType: "focus",
231
+ objectId: focus.id,
232
+ versionId: focus.versionId,
233
+ 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",
234
+ reason,
235
+ content,
236
+ sourceLabel: source.label,
237
+ origin: source.origin,
238
+ score,
239
+ injectedChars: 0
240
+ });
241
+ continue;
242
+ }
243
+ const addedChars = nextChars - usedChars;
244
+ usedChars = nextChars;
245
+ selectedFocuses.push(focus);
246
+ items.push({
247
+ recordId: focus.id,
248
+ objectType: "focus",
249
+ versionId: focus.versionId,
250
+ content,
251
+ score,
252
+ section: "task",
253
+ citation: `user-focus://${focus.id}`,
254
+ origin: source.origin,
255
+ stability: focus.confidence
256
+ });
111
257
  traceItems.push({
112
- objectType: "profile",
113
- objectId: "profile",
258
+ objectType: "focus",
259
+ objectId: focus.id,
260
+ versionId: focus.versionId,
114
261
  decision: "selected",
115
- reason: "User-provided profile",
262
+ reason: "Relevant active focus",
116
263
  content,
117
- sourceLabel: "You provided this directly",
118
- rank: 0,
119
- score: 1,
120
- injectedChars: content.length
264
+ sourceLabel: source.label,
265
+ origin: source.origin,
266
+ rank: items.length,
267
+ score,
268
+ injectedChars: addedChars
121
269
  });
122
- usedChars += content.length;
123
270
  }
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
271
  const rules = listCollaborationRules().filter((rule) => ruleMatches(rule, {
127
272
  ...scopeInput,
128
- channel: params.channel
273
+ channel: params.channel,
274
+ agentId: parseSessionKey(params.sessionKey)?.agentId
129
275
  }));
130
- const selectedRules = [];
131
276
  for (const [index, rule] of rules.entries()) {
132
- if (usedChars + rule.statement.length > maxChars) {
277
+ const nextChars = render({ rules: [...selectedRules, rule] }).length;
278
+ if (nextChars > maxChars) {
133
279
  traceItems.push({
134
280
  objectType: "rule",
135
281
  objectId: rule.id,
@@ -138,11 +284,13 @@ var UserContextPlanner = class {
138
284
  reason: "Context budget reached",
139
285
  content: rule.statement,
140
286
  sourceLabel: "Your collaboration rule",
287
+ origin: "told_by_user",
141
288
  injectedChars: 0
142
289
  });
143
290
  continue;
144
291
  }
145
- usedChars += rule.statement.length;
292
+ const addedChars = nextChars - usedChars;
293
+ usedChars = nextChars;
146
294
  selectedRules.push(rule);
147
295
  traceItems.push({
148
296
  objectType: "rule",
@@ -152,9 +300,10 @@ var UserContextPlanner = class {
152
300
  reason: "Active collaboration rule",
153
301
  content: rule.statement,
154
302
  sourceLabel: "Your collaboration rule",
303
+ origin: "told_by_user",
155
304
  rank: index + 1,
156
305
  score: 1,
157
- injectedChars: rule.statement.length
306
+ injectedChars: addedChars
158
307
  });
159
308
  }
160
309
  const ranked = this.retriever.retrieve({
@@ -168,6 +317,7 @@ var UserContextPlanner = class {
168
317
  score: result.score
169
318
  }));
170
319
  for (const { item, score } of ranked) {
320
+ const source = sourceDescription(item);
171
321
  if (items.length >= maxResults) {
172
322
  rejected.push({
173
323
  recordId: item.id,
@@ -180,14 +330,15 @@ var UserContextPlanner = class {
180
330
  decision: "budget_exceeded",
181
331
  reason: "Maximum result count reached",
182
332
  content: item.statement,
183
- sourceLabel: sourceLabel(item),
333
+ sourceLabel: source.label,
334
+ origin: source.origin,
184
335
  score,
185
336
  injectedChars: 0
186
337
  });
187
338
  continue;
188
339
  }
189
- let reason = rejectionReason(item, scopeInput, now);
190
- if (!reason && score < .25) reason = "low_score";
340
+ let reason = rejectionReason(item, scopeInput, now, queryProfile.timeHints);
341
+ if (!reason && score <= MIN_RELEVANCE_SCORE) reason = "low_score";
191
342
  if (!reason && item.disclosurePolicy === "ask_before_reference") {
192
343
  const consentStatus = consumeContextConsent(item.id, params.sessionKey);
193
344
  if (consentStatus !== "granted") {
@@ -215,13 +366,30 @@ var UserContextPlanner = class {
215
366
  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
367
  reason,
217
368
  content: item.statement,
218
- sourceLabel: sourceLabel(item),
369
+ sourceLabel: source.label,
370
+ origin: source.origin,
219
371
  score,
220
372
  injectedChars: 0
221
373
  });
222
374
  continue;
223
375
  }
224
- if (usedChars + item.statement.length > maxChars) {
376
+ const plannedItem = {
377
+ recordId: item.id,
378
+ objectType: "understanding",
379
+ versionId: item.versionId,
380
+ content: item.statement,
381
+ score,
382
+ section: sectionFor(item),
383
+ citation: `user-context://${item.id}`,
384
+ origin: source.origin,
385
+ stability: item.confidence
386
+ };
387
+ const nextSources = new Map(understandingSources).set(item.id, source.label);
388
+ const nextChars = render({
389
+ items: [...items, plannedItem],
390
+ understandingSources: nextSources
391
+ }).length;
392
+ if (nextChars > maxChars) {
225
393
  rejected.push({
226
394
  recordId: item.id,
227
395
  reason: "budget"
@@ -233,24 +401,17 @@ var UserContextPlanner = class {
233
401
  decision: "budget_exceeded",
234
402
  reason: "Context budget reached",
235
403
  content: item.statement,
236
- sourceLabel: sourceLabel(item),
404
+ sourceLabel: source.label,
405
+ origin: source.origin,
237
406
  score,
238
407
  injectedChars: 0
239
408
  });
240
409
  continue;
241
410
  }
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
- });
411
+ const addedChars = nextChars - usedChars;
412
+ usedChars = nextChars;
413
+ understandingSources.set(item.id, source.label);
414
+ items.push(plannedItem);
254
415
  traceItems.push({
255
416
  objectType: "understanding",
256
417
  objectId: item.id,
@@ -258,18 +419,14 @@ var UserContextPlanner = class {
258
419
  decision: "selected",
259
420
  reason: "Relevant to this request",
260
421
  content: item.statement,
261
- sourceLabel: sourceLabel(item),
422
+ sourceLabel: source.label,
423
+ origin: source.origin,
262
424
  rank: items.length,
263
425
  score,
264
- injectedChars: item.statement.length
426
+ injectedChars: addedChars
265
427
  });
266
428
  }
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");
429
+ const block = render();
273
430
  recordContextRun({
274
431
  turnId: params.turnId,
275
432
  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 {};