@xopcai/xopc 0.0.217 → 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 (329) 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-D6trMTyZ.js → activity-store-slG02hSm.js} +1 -1
  4. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-CAQdFrcu.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-B9pZAyMB.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-BF0q7N24.js → archive-plugin-DKXa160O.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-D1qmjGDo.js → attachment-load-CzwA9g2y.js} +1 -1
  12. package/dist/gateway/static/root/assets/{automations-page-Ccu4yRFa.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-DooqxEZz.js → binary-plugins-DoQ_DnT7.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-Dqg9kvb9.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-CsIh8ySc.js → browser-workflow-inputs-D4roXE6r.js} +1 -1
  18. package/dist/gateway/static/root/assets/{browser-workflows-page-BXQFxT0p.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-BX9U0FRh.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-CUBTQ0Bz.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-XzPZhzVM.js → cron-expression-4DvCFs-v.js} +1 -1
  28. package/dist/gateway/static/root/assets/date-picker-B6FSjt4Z.js +1 -0
  29. package/dist/gateway/static/root/assets/dependency-picker-Za18eMp1.js +1 -0
  30. package/dist/gateway/static/root/assets/{desktop-pet-DZjW-7Tw.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-D7APnE3n.js → extension-debug-page-Cordpg4X.js} +1 -1
  35. package/dist/gateway/static/root/assets/{extension-page-BhV5hz70.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-BTH9HVUk.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-DAEk_tnd.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-HqcQrSed.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-BG6lShzn.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-vaz8ewe2.js → local-apps-page-Be79cyMG.js} +1 -1
  55. package/dist/gateway/static/root/assets/{locale-store-De8wYkd7.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-tqTGCHt0.js → management-settings-CRspx0oY.js} +1 -1
  58. package/dist/gateway/static/root/assets/{markdown-split-BGx8Aao0.js → markdown-split-G3PTpGw3.js} +1 -1
  59. package/dist/gateway/static/root/assets/{markdown-view-ybRARsPs.js → markdown-view-D4FPJZ91.js} +1 -1
  60. package/dist/gateway/static/root/assets/{media-plugins-xbM-SSP5.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-D9CCwyWK.js → notes-api-q7HjYO07.js} +1 -1
  63. package/dist/gateway/static/root/assets/{notes-page-CMNBbg6g.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-CZdzgPZW.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-DYmKEwiG.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-DQ12tLCL.js → runtime-tools-settings-panel-CXHQc53b.js} +2 -2
  74. package/dist/gateway/static/root/assets/{schema-form-DNCDIkqC.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-xgo41cfo.js → settings-loading-skeleton-H3ZH6a6l.js} +1 -1
  80. package/dist/gateway/static/root/assets/{settings-page-8astk_1U.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-BBZV4AGy.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-HmoDhJVh.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/tab-completion-input-D64VNmiA.js +1 -0
  89. package/dist/gateway/static/root/assets/tab-completion-input.utils-BP3NH_du.js +1 -0
  90. package/dist/gateway/static/root/assets/task-detail-page-BwOyrADL.js +1 -0
  91. package/dist/gateway/static/root/assets/{theme-store-STx6jo38.js → theme-store-Br4BtK4x.js} +1 -1
  92. package/dist/gateway/static/root/assets/typed-models-lib-q5-Vfqd8.js +1 -0
  93. package/dist/gateway/static/root/assets/{use-autosave-CqFVx92z.js → use-autosave-DRS3RwS9.js} +1 -1
  94. package/dist/gateway/static/root/assets/user-context-page-ClV2r3Cr.js +1 -0
  95. package/dist/gateway/static/root/assets/{voice-api-key-field-pYDiKKMo.js → voice-api-key-field-CGTE5156.js} +1 -1
  96. package/dist/gateway/static/root/assets/{work-discovery-overlay-LJLw9zf0.js → work-discovery-overlay-CW-HKD7h.js} +1 -1
  97. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-D0WhQ3kI.js → workflow-run-setup-panel-Dtr9fDC8.js} +2 -2
  98. package/dist/gateway/static/root/assets/workflows-page-CDOyNgZf.js +5 -0
  99. package/dist/gateway/static/root/index.html +20 -11
  100. package/dist/package.js +1 -1
  101. package/dist/packages/gateway-contract/src/new-session.js +99 -0
  102. package/dist/packages/gateway-contract/src/tasks.js +5 -0
  103. package/dist/packages/gateway-contract/src/user-message-display.js +55 -0
  104. package/dist/src/agent/agent-manager.js +3 -2
  105. package/dist/src/agent/background-review/prompts.d.ts +1 -1
  106. package/dist/src/agent/background-review/prompts.js +6 -3
  107. package/dist/src/agent/background-review/run-background-review.js +144 -16
  108. package/dist/src/agent/inbound/turn-dispatcher.d.ts +3 -1
  109. package/dist/src/agent/inbound/turn-dispatcher.js +2 -1
  110. package/dist/src/agent/memory/context/types.d.ts +1 -1
  111. package/dist/src/agent/memory/create-memory-manager.js +1 -1
  112. package/dist/src/agent/memory/manager.d.ts +2 -1
  113. package/dist/src/agent/memory/manager.js +2 -6
  114. package/dist/src/agent/memory/understanding/service.d.ts +1 -0
  115. package/dist/src/agent/memory/understanding/service.js +179 -36
  116. package/dist/src/agent/memory/understanding/types.d.ts +6 -0
  117. package/dist/src/agent/messaging/command-handler.d.ts +2 -0
  118. package/dist/src/agent/messaging/command-handler.js +3 -1
  119. package/dist/src/agent/service/direct-turn-helpers.d.ts +3 -0
  120. package/dist/src/agent/service/direct-turn-helpers.js +13 -3
  121. package/dist/src/agent/service/process-direct-streaming.d.ts +2 -1
  122. package/dist/src/agent/service/process-direct-streaming.js +12 -11
  123. package/dist/src/agent/session/session-config-service.d.ts +1 -0
  124. package/dist/src/agent/session/session-config-service.js +11 -0
  125. package/dist/src/agent/session/session-inspector.d.ts +1 -0
  126. package/dist/src/agent/session/session-inspector.js +1 -0
  127. package/dist/src/agent/source-context/budget.d.ts +3 -0
  128. package/dist/src/agent/source-context/budget.js +21 -0
  129. package/dist/src/agent/source-context/index.js +3 -3
  130. package/dist/src/agent/source-context/injector.d.ts +2 -2
  131. package/dist/src/agent/source-context/injector.js +19 -9
  132. package/dist/src/agent/source-context/types.d.ts +16 -0
  133. package/dist/src/agent/source-context/types.js +25 -1
  134. package/dist/src/agent/tool-manuals/xopc-use.d.ts +1 -1
  135. package/dist/src/agent/tool-manuals/xopc-use.js +19 -2
  136. package/dist/src/agent/tools/xopc-use-tool.js +62 -2
  137. package/dist/src/agent-runtime/index.js +1 -1
  138. package/dist/src/agent-runtime/runtime-profile.js +1 -1
  139. package/dist/src/browser/backend-from-config.d.ts +8 -0
  140. package/dist/src/browser/backend-from-config.js +16 -1
  141. package/dist/src/browser/providers/browser-ext-install.d.ts +3 -2
  142. package/dist/src/browser/providers/browser-ext-install.js +4 -2
  143. package/dist/src/chat-commands/builtins/review.js +11 -2
  144. package/dist/src/chat-commands/builtins/understanding.js +11 -4
  145. package/dist/src/chat-commands/types.d.ts +4 -0
  146. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  147. package/dist/src/cli/commands/extension-marketplace.js +1 -1
  148. package/dist/src/cli/commands/extension.js +1 -1
  149. package/dist/src/config/agent-profile.js +1 -1
  150. package/dist/src/config/models-json.d.ts +20 -20
  151. package/dist/src/connectors/connected-source-ingestion.js +21 -4
  152. package/dist/src/connectors/connected-source-normalizers.js +51 -4
  153. package/dist/src/connectors/connected-source-understanding.d.ts +20 -0
  154. package/dist/src/connectors/connected-source-understanding.js +180 -0
  155. package/dist/src/connectors/content-enrichment.d.ts +1 -0
  156. package/dist/src/connectors/content-enrichment.js +11 -7
  157. package/dist/src/connectors/learning-coordinator.js +112 -15
  158. package/dist/src/connectors/learning-recipes.js +2 -2
  159. package/dist/src/document-understanding/extract.d.ts +1 -1
  160. package/dist/src/document-understanding/extract.js +54 -1
  161. package/dist/src/extensions/update.js +1 -1
  162. package/dist/src/gateway/agents-admin.js +1 -1
  163. package/dist/src/gateway/chat-stream/mapper.js +18 -0
  164. package/dist/src/gateway/heartbeat/service.js +1 -1
  165. package/dist/src/gateway/hono/routes/agent-stream.js +12 -2
  166. package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
  167. package/dist/src/gateway/hono/routes/commands-skills.js +1 -0
  168. package/dist/src/gateway/hono/routes/session-input-handler.d.ts +46 -2
  169. package/dist/src/gateway/hono/routes/session-input-handler.js +23 -3
  170. package/dist/src/gateway/hono/routes/sessions.js +17 -20
  171. package/dist/src/gateway/hono/routes/tasks.js +25 -0
  172. package/dist/src/gateway/hono/routes/understanding-sources.d.ts +9 -0
  173. package/dist/src/gateway/hono/routes/understanding-sources.js +138 -24
  174. package/dist/src/gateway/hono/routes/you.js +71 -4
  175. package/dist/src/gateway/rate-limit/buckets.d.ts +1 -1
  176. package/dist/src/gateway/rate-limit/buckets.js +2 -2
  177. package/dist/src/gateway/service/agent-runner.d.ts +7 -2
  178. package/dist/src/gateway/service/agent-runner.js +21 -1
  179. package/dist/src/gateway/service/config-coordinator.js +1 -1
  180. package/dist/src/gateway/service/run-gateway-agent.d.ts +2 -0
  181. package/dist/src/gateway/service/run-gateway-agent.js +2 -1
  182. package/dist/src/gateway/service/session-input-coordinator.d.ts +8 -2
  183. package/dist/src/gateway/service/session-input-coordinator.js +62 -3
  184. package/dist/src/gateway/service/sessions-api.d.ts +1 -0
  185. package/dist/src/gateway/service.d.ts +3 -2
  186. package/dist/src/gateway/service.js +16 -6
  187. package/dist/src/gateway/user-turn-input.d.ts +2 -0
  188. package/dist/src/gateway/xopc-cloud-capability-setup.d.ts +3 -2
  189. package/dist/src/gateway/xopc-cloud-capability-setup.js +16 -3
  190. package/dist/src/heartbeat/index.js +1 -1
  191. package/dist/src/infra/update-runner.js +1 -1
  192. package/dist/src/knowledge/connected-understanding-pipeline.d.ts +1 -1
  193. package/dist/src/knowledge/connected-understanding-pipeline.js +4 -2
  194. package/dist/src/retrieval/queryProfile.d.ts +1 -0
  195. package/dist/src/retrieval/queryProfile.js +9 -1
  196. package/dist/src/session/client-history.d.ts +11 -0
  197. package/dist/src/session/client-history.js +24 -2
  198. package/dist/src/session/config-types.d.ts +1 -1
  199. package/dist/src/session/session-title.js +2 -3
  200. package/dist/src/session/store.js +1 -0
  201. package/dist/src/session/transcript-outline.js +5 -2
  202. package/dist/src/session/types.d.ts +1 -0
  203. package/dist/src/session/user-message-display.d.ts +4 -0
  204. package/dist/src/session/user-message-display.js +22 -0
  205. package/dist/src/storage/sqlite/context-extraction-repository.d.ts +57 -0
  206. package/dist/src/storage/sqlite/context-extraction-repository.js +119 -0
  207. package/dist/src/storage/sqlite/context-relation-repository.d.ts +50 -0
  208. package/dist/src/storage/sqlite/context-relation-repository.js +97 -0
  209. package/dist/src/storage/sqlite/index.d.ts +4 -2
  210. package/dist/src/storage/sqlite/index.js +5 -3
  211. package/dist/src/storage/sqlite/migrations/126_focus_context_governance.sql +72 -0
  212. package/dist/src/storage/sqlite/migrations/127_context_object_origin.sql +36 -0
  213. package/dist/src/storage/sqlite/migrations/128_context_extraction.sql +73 -0
  214. package/dist/src/storage/sqlite/migrations/129_focus_versions.sql +51 -0
  215. package/dist/src/storage/sqlite/migrations/130_context_evidence_provenance.sql +18 -0
  216. package/dist/src/storage/sqlite/migrations/131_session_input_contexts.sql +2 -0
  217. package/dist/src/storage/sqlite/migrations/132_transcript_source_context_metadata.sql +34 -0
  218. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  219. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  220. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  221. package/dist/src/storage/sqlite/schema.js +1 -1
  222. package/dist/src/storage/sqlite/session-input-repository.d.ts +8 -0
  223. package/dist/src/storage/sqlite/session-input-repository.js +19 -7
  224. package/dist/src/storage/sqlite/session-turn-replace-repository.d.ts +3 -0
  225. package/dist/src/storage/sqlite/session-turn-replace-repository.js +3 -2
  226. package/dist/src/storage/sqlite/transcript-repository.js +29 -3
  227. package/dist/src/storage/sqlite/user-context-repository.d.ts +4 -1
  228. package/dist/src/storage/sqlite/user-context-repository.js +65 -29
  229. package/dist/src/tasks/index.d.ts +1 -0
  230. package/dist/src/tasks/index.js +2 -1
  231. package/dist/src/tasks/task-deletion-service.d.ts +21 -0
  232. package/dist/src/tasks/task-deletion-service.js +35 -0
  233. package/dist/src/tasks/task-repository.js +22 -1
  234. package/dist/src/tui/backends/embedded-backend.js +5 -3
  235. package/dist/src/tui/backends/gateway-realtime-backend.js +5 -3
  236. package/dist/src/tui/chat-history.js +2 -1
  237. package/dist/src/tui/tui-agent-events.js +4 -2
  238. package/dist/src/tui/tui-commands.d.ts +1 -0
  239. package/dist/src/tui/tui-commands.js +8 -3
  240. package/dist/src/tui/tui-empty-session-cleanup.d.ts +0 -1
  241. package/dist/src/tui/tui-empty-session-cleanup.js +1 -11
  242. package/dist/src/tui/tui-new-session-preferences.d.ts +10 -0
  243. package/dist/src/tui/tui-new-session-preferences.js +32 -0
  244. package/dist/src/tui/tui-session-actions.d.ts +1 -0
  245. package/dist/src/tui/tui-session-actions.js +2 -1
  246. package/dist/src/tui/tui-settings.d.ts +2 -0
  247. package/dist/src/tui/tui-settings.js +4 -1
  248. package/dist/src/tui/tui-types.d.ts +1 -0
  249. package/dist/src/tui/tui.js +57 -4
  250. package/dist/src/tunnel/frpc-process.js +3 -0
  251. package/dist/src/tunnel/tunnel-service.d.ts +2 -0
  252. package/dist/src/tunnel/tunnel-service.js +40 -28
  253. package/dist/src/user-context/context-objects.d.ts +17 -0
  254. package/dist/src/user-context/context-objects.js +99 -0
  255. package/dist/src/user-context/domain.d.ts +13 -1
  256. package/dist/src/user-context/evaluation/harness.d.ts +13 -0
  257. package/dist/src/user-context/evaluation/harness.js +31 -0
  258. package/dist/src/user-context/extraction/registry.d.ts +26 -0
  259. package/dist/src/user-context/extraction/registry.js +113 -0
  260. package/dist/src/user-context/extraction/repair.d.ts +19 -0
  261. package/dist/src/user-context/extraction/repair.js +68 -0
  262. package/dist/src/user-context/planner.js +214 -57
  263. package/dist/src/user-context/retriever.js +69 -9
  264. package/dist/src/user-context/sources/catalog.js +9 -2
  265. package/dist/src/user-context/sources/index.js +2 -2
  266. package/dist/src/user-context/sources/local-source-contract.d.ts +1 -1
  267. package/dist/src/user-context/sources/local-source-contract.js +1 -0
  268. package/dist/src/user-context/sources/processing-policy.d.ts +2 -0
  269. package/dist/src/user-context/sources/processing-policy.js +7 -0
  270. package/dist/src/user-context/sources/repository.d.ts +23 -4
  271. package/dist/src/user-context/sources/repository.js +122 -12
  272. package/dist/src/user-context/sources/types.d.ts +10 -1
  273. package/dist/src/user-context/understanding-writing.d.ts +1 -0
  274. package/dist/src/user-context/understanding-writing.js +4 -0
  275. package/dist/src/user-context/understanding.js +1 -1
  276. package/dist/src/work-discovery/analyzer.d.ts +6 -0
  277. package/dist/src/work-discovery/analyzer.js +181 -57
  278. package/dist/src/work-discovery/index.js +1 -1
  279. package/dist/src/work-discovery/probe.js +20 -0
  280. package/dist/src/work-discovery/service.d.ts +9 -0
  281. package/dist/src/work-discovery/service.js +39 -11
  282. package/dist/src/work-discovery/source-repository.js +1 -1
  283. package/dist/src/work-discovery/types.d.ts +5 -0
  284. package/package.json +3 -3
  285. package/dist/gateway/static/root/assets/agents-C6q_vDzP.js +0 -68
  286. package/dist/gateway/static/root/assets/app-management-settings-panel-DRsTwFbF.js +0 -1
  287. package/dist/gateway/static/root/assets/appearance-settings-B99NaPTf.js +0 -1
  288. package/dist/gateway/static/root/assets/apps-page-Dx66anqa.js +0 -1
  289. package/dist/gateway/static/root/assets/automations-workspace-CHbA8d-P.js +0 -6
  290. package/dist/gateway/static/root/assets/browser-settings-page-CpRc-9Jy.js +0 -8
  291. package/dist/gateway/static/root/assets/capabilities-settings-panel-C89FGECN.js +0 -7
  292. package/dist/gateway/static/root/assets/capability-presets-settings-panel-XT6WEz9E.js +0 -3
  293. package/dist/gateway/static/root/assets/channels-settings-DhKk1oNT.js +0 -1
  294. package/dist/gateway/static/root/assets/channels-status-swr-CiwOOoVL.js +0 -1
  295. package/dist/gateway/static/root/assets/chat-terminal-dock-CTbkTsc2.js +0 -36
  296. package/dist/gateway/static/root/assets/connectors-page-BDn3HTzX.js +0 -2
  297. package/dist/gateway/static/root/assets/date-picker-BmZjs4Bq.js +0 -1
  298. package/dist/gateway/static/root/assets/dependency-picker-ndtb88_T.js +0 -1
  299. package/dist/gateway/static/root/assets/desktop-pet-settings-C7BLs783.js +0 -1
  300. package/dist/gateway/static/root/assets/directory-picker-path-field-BWiap88p.js +0 -1
  301. package/dist/gateway/static/root/assets/extension-settings-page-BhbcGuiJ.js +0 -1
  302. package/dist/gateway/static/root/assets/gateway-config-api-CUt9bIpL.js +0 -1
  303. package/dist/gateway/static/root/assets/gateway-settings-RafSECLG.js +0 -1
  304. package/dist/gateway/static/root/assets/heartbeat-settings-CwVPlPLB.js +0 -1
  305. package/dist/gateway/static/root/assets/home-page-CbdBcCwC.js +0 -1
  306. package/dist/gateway/static/root/assets/index-AbNnQyKk.css +0 -2
  307. package/dist/gateway/static/root/assets/index-CMLkr37Y.js +0 -108
  308. package/dist/gateway/static/root/assets/local-app-workbench-page-DdaPtQ5M.js +0 -2
  309. package/dist/gateway/static/root/assets/logs-page-CjxMHTQO.js +0 -2
  310. package/dist/gateway/static/root/assets/messages-VI9m1xJl.js +0 -3
  311. package/dist/gateway/static/root/assets/notes-workbench-V9C-8vSn.js +0 -4
  312. package/dist/gateway/static/root/assets/page-tabs-e99j9S9K.js +0 -1
  313. package/dist/gateway/static/root/assets/preview-open-alternatives-DW9MDOva.js +0 -1
  314. package/dist/gateway/static/root/assets/project-detail-page-DHmAUggu.js +0 -1
  315. package/dist/gateway/static/root/assets/projects-page-D0EiN69Y.js +0 -1
  316. package/dist/gateway/static/root/assets/remote-access-hub-BuAVFk2O.js +0 -1
  317. package/dist/gateway/static/root/assets/sessions-page-hzlTfgOl.js +0 -1
  318. package/dist/gateway/static/root/assets/settings-advanced-gate-BlCoA_9h.js +0 -1
  319. package/dist/gateway/static/root/assets/settings-form-section-z0JH53Fu.js +0 -1
  320. package/dist/gateway/static/root/assets/setup-status-panel-fZQfoJAk.js +0 -1
  321. package/dist/gateway/static/root/assets/shares-settings-B5dPMq3Y.js +0 -1
  322. package/dist/gateway/static/root/assets/skill-reload-api-i1PGf1V2.js +0 -1
  323. package/dist/gateway/static/root/assets/skills-page-BSN2VaqR.js +0 -2
  324. package/dist/gateway/static/root/assets/system-settings-panel-CSibO8vj.js +0 -1
  325. package/dist/gateway/static/root/assets/tab-completion-input-B-VsxKhC.js +0 -1
  326. package/dist/gateway/static/root/assets/task-detail-page-HCKZ11E8.js +0 -1
  327. package/dist/gateway/static/root/assets/typed-models-lib-zrYg51t3.js +0 -1
  328. package/dist/gateway/static/root/assets/user-context-page-CqG56cDS.js +0 -1
  329. package/dist/gateway/static/root/assets/workflows-page-DQAJzV5w.js +0 -5
@@ -0,0 +1,26 @@
1
+ import { type ContextExtractionRun } from '../../storage/sqlite/index.js';
2
+ import type { UnderstandingKind } from '../domain.js';
3
+ export type ExtractorId = 'explicit-command' | 'deterministic-signal' | 'transcript-synthesis' | 'connector-structural' | 'connector-semantic';
4
+ export type ExtractorDefinition = {
5
+ id: ExtractorId;
6
+ version: string;
7
+ inputKinds: Array<'conversation' | 'connector' | 'file' | 'task'>;
8
+ requiredProcessingPolicy: 'local_only' | 'remote_allowed';
9
+ authorityCeiling: 'user_explicit' | 'user_observed' | 'system_inferred' | 'external_untrusted';
10
+ candidateKinds: UnderstandingKind[];
11
+ maxAutomaticStatus: 'active' | 'candidate';
12
+ timeoutMs: number;
13
+ };
14
+ export declare function getExtractorDefinition(id: ExtractorId): ExtractorDefinition;
15
+ export declare function getRegisteredExtractorDefinition(id: string): ExtractorDefinition | undefined;
16
+ export declare function extractionInputHash(input: string): string;
17
+ export declare function claimRegisteredExtraction(input: {
18
+ extractorId: ExtractorId;
19
+ sourceRef: string;
20
+ contentForHash: string;
21
+ processingPolicy: 'local_only' | 'remote_allowed';
22
+ destination: ContextExtractionRun['destination'];
23
+ }): {
24
+ run: ContextExtractionRun;
25
+ shouldExecute: boolean;
26
+ };
@@ -0,0 +1,113 @@
1
+ import { claimContextExtractionRun, finishContextExtractionRun } from "../../storage/sqlite/context-extraction-repository.js";
2
+ import "../../storage/sqlite/index.js";
3
+ import { createHash } from "node:crypto";
4
+ //#region src/user-context/extraction/registry.ts
5
+ const UNDERSTANDING_KINDS = [
6
+ "preference",
7
+ "boundary",
8
+ "relationship",
9
+ "routine",
10
+ "current_state",
11
+ "long_term_goal",
12
+ "project_context",
13
+ "task_lesson",
14
+ "derived_insight"
15
+ ];
16
+ const DEFINITIONS = {
17
+ "explicit-command": {
18
+ id: "explicit-command",
19
+ version: "1",
20
+ inputKinds: ["conversation"],
21
+ requiredProcessingPolicy: "local_only",
22
+ authorityCeiling: "user_explicit",
23
+ candidateKinds: UNDERSTANDING_KINDS,
24
+ maxAutomaticStatus: "active",
25
+ timeoutMs: 500
26
+ },
27
+ "deterministic-signal": {
28
+ id: "deterministic-signal",
29
+ version: "1",
30
+ inputKinds: ["conversation", "task"],
31
+ requiredProcessingPolicy: "local_only",
32
+ authorityCeiling: "user_observed",
33
+ candidateKinds: UNDERSTANDING_KINDS,
34
+ maxAutomaticStatus: "candidate",
35
+ timeoutMs: 500
36
+ },
37
+ "transcript-synthesis": {
38
+ id: "transcript-synthesis",
39
+ version: "1",
40
+ inputKinds: ["conversation"],
41
+ requiredProcessingPolicy: "remote_allowed",
42
+ authorityCeiling: "system_inferred",
43
+ candidateKinds: UNDERSTANDING_KINDS,
44
+ maxAutomaticStatus: "candidate",
45
+ timeoutMs: 3e4
46
+ },
47
+ "connector-structural": {
48
+ id: "connector-structural",
49
+ version: "1",
50
+ inputKinds: ["connector"],
51
+ requiredProcessingPolicy: "local_only",
52
+ authorityCeiling: "external_untrusted",
53
+ candidateKinds: [
54
+ "project_context",
55
+ "current_state",
56
+ "routine"
57
+ ],
58
+ maxAutomaticStatus: "candidate",
59
+ timeoutMs: 1e4
60
+ },
61
+ "connector-semantic": {
62
+ id: "connector-semantic",
63
+ version: "1",
64
+ inputKinds: ["connector", "file"],
65
+ requiredProcessingPolicy: "remote_allowed",
66
+ authorityCeiling: "external_untrusted",
67
+ candidateKinds: [
68
+ "preference",
69
+ "routine",
70
+ "current_state",
71
+ "project_context"
72
+ ],
73
+ maxAutomaticStatus: "candidate",
74
+ timeoutMs: 3e4
75
+ }
76
+ };
77
+ function getExtractorDefinition(id) {
78
+ return DEFINITIONS[id];
79
+ }
80
+ function getRegisteredExtractorDefinition(id) {
81
+ return DEFINITIONS[id];
82
+ }
83
+ function extractionInputHash(input) {
84
+ return createHash("sha256").update(input).digest("hex");
85
+ }
86
+ function claimRegisteredExtraction(input) {
87
+ const definition = getExtractorDefinition(input.extractorId);
88
+ const claimed = claimContextExtractionRun({
89
+ sourceRef: input.sourceRef,
90
+ extractorId: definition.id,
91
+ extractorVersion: definition.version,
92
+ processingPolicy: input.processingPolicy,
93
+ destination: input.destination,
94
+ inputHash: extractionInputHash(input.contentForHash)
95
+ });
96
+ if (definition.requiredProcessingPolicy === "remote_allowed" && input.processingPolicy !== "remote_allowed") {
97
+ if (claimed.run.status === "running") finishContextExtractionRun({
98
+ runId: claimed.run.id,
99
+ status: "skipped",
100
+ errorCode: "processing_policy"
101
+ });
102
+ return {
103
+ run: {
104
+ ...claimed.run,
105
+ status: "skipped"
106
+ },
107
+ shouldExecute: false
108
+ };
109
+ }
110
+ return claimed;
111
+ }
112
+ //#endregion
113
+ export { claimRegisteredExtraction, extractionInputHash, getExtractorDefinition, getRegisteredExtractorDefinition };
@@ -0,0 +1,19 @@
1
+ export type ContextRepairFilter = {
2
+ runId?: string;
3
+ sourceRef?: string;
4
+ extractorId?: string;
5
+ extractorVersion?: string;
6
+ objectVersionId?: string;
7
+ };
8
+ export declare function repairExtractedContext(filter: ContextRepairFilter): {
9
+ runIds: string[];
10
+ repaired: Array<{
11
+ objectType: 'focus' | 'understanding';
12
+ objectId: string;
13
+ }>;
14
+ retained: Array<{
15
+ objectType: 'focus' | 'understanding';
16
+ objectId: string;
17
+ reason: string;
18
+ }>;
19
+ };
@@ -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,