@xopcai/xopc 0.0.248 → 0.0.250
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.
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-etpmyV7S.js → activity-store-DfBjTSo9.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BmKxSM1k.js → agent-avatar-dicebear-BN6FJXkJ.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-C7rZH1A2.js +1 -0
- package/dist/gateway/static/root/assets/agents-CgGaoo4z.js +1 -0
- package/dist/gateway/static/root/assets/{api-B0-hLuZ1.js → api-zxpcJfgj.js} +1 -1
- package/dist/gateway/static/root/assets/app-management-settings-panel-D2gMshuS.js +1 -0
- package/dist/gateway/static/root/assets/appearance-settings-wMu0jSKx.js +1 -0
- package/dist/gateway/static/root/assets/apps-page-KF1Gnv36.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-BnMSgZvR.js → archive-plugin-u6EE3JV8.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-CejsQMev.js → attachment-load-DbJurnv-.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-RC8EyoAf.js → automations-page-Ew_e5HDn.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-Ch-ldu35.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-DGjppLSG.js → binary-plugins-DtDFNfPM.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-CWdP4bUc.js → block-editor-CnAwmabq.js} +44 -44
- package/dist/gateway/static/root/assets/browser-settings-page-DtVhsHJW.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-BQ1Ilw_o.js → browser-workflow-inputs-BX1-uM9L.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CJh4NyxT.js → browser-workflows-page-CcbUOWDF.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel--sXeylhe.js +7 -0
- package/dist/gateway/static/root/assets/channels-settings-AXSBDujZ.js +1 -0
- package/dist/gateway/static/root/assets/{channels-status-swr-Ohhee4vm.js → channels-status-swr-CX-yWwLD.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-BOtoKTK3.js → chat-terminal-dock-CryTDNdD.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-HBHUWohz.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-DTj1V3Sw.js → cron-expression-ji5aWrjG.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-Yr6OCvGL.js → date-picker-Dro_w3eX.js} +1 -1
- package/dist/gateway/static/root/assets/dependency-picker-Ce19KKnX.js +1 -0
- package/dist/gateway/static/root/assets/{desktop-pet-DbGzggPF.js → desktop-pet-DsSi-3uZ.js} +1 -1
- package/dist/gateway/static/root/assets/desktop-pet-settings-8WQ4woJy.js +1 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-DgTtk4KC.js → extension-debug-page-CgvEBfLZ.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DtQeiP6f.js → extension-page-DkznBbMj.js} +1 -1
- package/dist/gateway/static/root/assets/extension-settings-page-BOjhchK2.js +1 -0
- package/dist/gateway/static/root/assets/files-BArWTfr7.js +1 -0
- package/dist/gateway/static/root/assets/gateway-config-api-OEruhhX3.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-swr-DXuXtU1w.js → gateway-config-swr-CMNbl0FZ.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-BgH3A0LO.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CzBzglzQ.js → gateway-startup-retry-CR7Xg8As.js} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-C97naDkO.js +1 -0
- package/dist/gateway/static/root/assets/home-page-BBKKme4G.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-TIgsn04n.js → image-generation-api-C5mn73ca.js} +1 -1
- package/dist/gateway/static/root/assets/index-BcaF-dgQ.js +72 -0
- package/dist/gateway/static/root/assets/index-DAryGvZ7.css +2 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-wsWuoa8p.js → keyboard-shortcuts-settings-BYhfzsqe.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-DNncc2tn.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-CXrbrGo8.js → local-apps-page-vBlknU7C.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-BJFLQY8O.js → locale-store-CF4erhjB.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-CizZInrT.js +2 -0
- package/dist/gateway/static/root/assets/{management-settings-BdJZFR7U.js → management-settings-Dnx6mSNe.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-NK3ACVG2.js → markdown-split-DtBtcHWi.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-DTF9v1gg.js → markdown-view-CQvzsE24.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-F0jcUxyl.js → media-plugins-DrMYeHe7.js} +1 -1
- package/dist/gateway/static/root/assets/messages-Cf5hpZE6.js +3 -0
- package/dist/gateway/static/root/assets/mobile-pairing-wizard-AKgGy3Kx.js +1 -0
- package/dist/gateway/static/root/assets/note-detail-panel-Bw3jD9Jf.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-Dpqq7Z-J.js +8 -0
- package/dist/gateway/static/root/assets/page-tabs-CX9T71by.js +1 -0
- package/dist/gateway/static/root/assets/preview-open-alternatives-DvEHoimN.js +1 -0
- package/dist/gateway/static/root/assets/{product-open-page-CxGGlWA8.js → product-open-page-COcr_NUJ.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-BuT6MCTs.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-DXWMxOjf.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-CIsNlSBi.js → registry-api-BsRBlji7.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-7rBCUWzZ.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-YkjhiQfA.js → runtime-tools-settings-panel-CQ13P-mS.js} +2 -2
- package/dist/gateway/static/root/assets/{schema-form-oFGf3G3s.js → schema-form-BUVyTpZj.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-gmEOYNb4.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-DYYoJcl7.js +1 -0
- package/dist/gateway/static/root/assets/settings-form-section-DVY-8_B9.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-C7VWs0IT.js → settings-page-CdiVYyTl.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BhenBnUj.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-t5oz18rh.js → share-preview-page-C88YLKm4.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-Dq7xIj0_.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-MDI9Lz6z.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-DLir1nM0.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page.utils-DEDTYs2W.js → skills-page.utils-BMZAfS3G.js} +1 -1
- package/dist/gateway/static/root/assets/system-settings-panel-BM8ivYan.js +1 -0
- package/dist/gateway/static/root/assets/task-detail-page-P0_RldWv.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-O597U8q_.js → theme-store-BOgkc_9D.js} +1 -1
- package/dist/gateway/static/root/assets/tunnel-api-DemxChjo.js +1 -0
- package/dist/gateway/static/root/assets/{use-autosave-B5eUJ6Zq.js → use-autosave-CV3Ui5hu.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-CxfnoRVn.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-CMKSwz4C.js → voice-api-key-field-CUoCi4Sq.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-q7B6fOFB.js → voice-config-api-C-ryeIxj.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-overlay-BhDlkCMB.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DZmvLZjb.js → workflow-run-setup-panel-D8CcPc_C.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-Bxn2Dc16.js +5 -0
- package/dist/gateway/static/root/index.html +11 -27
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/user-message-display.js +18 -0
- package/dist/src/agent/agent-instance-gateway.d.ts +3 -3
- package/dist/src/agent/agent-manager.d.ts +13 -13
- package/dist/src/agent/agent-manager.js +76 -42
- package/dist/src/agent/background-review/coordinator.d.ts +2 -4
- package/dist/src/agent/background-review/coordinator.js +5 -30
- package/dist/src/agent/background-review/prompts.d.ts +4 -2
- package/dist/src/agent/background-review/prompts.js +33 -19
- package/dist/src/agent/background-review/run-background-review.d.ts +6 -7
- package/dist/src/agent/background-review/run-background-review.js +47 -41
- package/dist/src/agent/background-review/settings.d.ts +0 -1
- package/dist/src/agent/background-review/settings.js +6 -7
- package/dist/src/agent/context/audit.d.ts +38 -0
- package/dist/src/agent/context/audit.js +123 -0
- package/dist/src/agent/context/coordinator.d.ts +31 -0
- package/dist/src/agent/context/coordinator.js +73 -0
- package/dist/src/agent/context/execution-context.d.ts +13 -0
- package/dist/src/agent/context/execution-context.js +211 -0
- package/dist/src/agent/context/execution-context.types.d.ts +50 -0
- package/dist/src/agent/context/execution-scope.d.ts +5 -1
- package/dist/src/agent/context/execution-scope.js +6 -2
- package/dist/src/agent/context/prepend.d.ts +2 -0
- package/dist/src/agent/context/prepend.js +28 -0
- package/dist/src/agent/context/project-context.d.ts +6 -3
- package/dist/src/agent/context/project-context.js +28 -23
- package/dist/src/agent/embedded/index.js +1 -1
- package/dist/src/agent/embedded/run-for-session.js +1 -0
- package/dist/src/agent/embedded/run-turn.js +22 -2
- package/dist/src/agent/embedded/types.d.ts +1 -25
- package/dist/src/agent/external-tools/composio-provider.js +87 -92
- package/dist/src/agent/external-tools/gateway-tools.d.ts +4 -1
- package/dist/src/agent/external-tools/gateway-tools.js +153 -41
- package/dist/src/agent/external-tools/index.d.ts +1 -0
- package/dist/src/agent/external-tools/index.js +2 -1
- package/dist/src/agent/external-tools/memory-provider.d.ts +1 -0
- package/dist/src/agent/external-tools/memory-provider.js +1 -0
- package/dist/src/agent/external-tools/search-error.d.ts +12 -0
- package/dist/src/agent/external-tools/search-error.js +29 -0
- package/dist/src/agent/external-tools/service.d.ts +4 -0
- package/dist/src/agent/external-tools/service.js +22 -2
- package/dist/src/agent/inbound/attachment-pipeline.js +5 -1
- package/dist/src/agent/memory/compaction-policy.js +1 -1
- package/dist/src/agent/memory/compaction-promotion.d.ts +1 -0
- package/dist/src/agent/memory/compaction-promotion.js +52 -79
- package/dist/src/agent/memory/create-memory-manager.js +1 -3
- package/dist/src/agent/memory/index.d.ts +1 -6
- package/dist/src/agent/memory/index.js +3 -6
- package/dist/src/agent/memory/manager.d.ts +0 -16
- package/dist/src/agent/memory/manager.js +11 -40
- package/dist/src/agent/memory/memory-config.d.ts +0 -5
- package/dist/src/agent/memory/memory-config.js +2 -9
- package/dist/src/agent/memory/runtime.d.ts +2 -2
- package/dist/src/agent/memory/runtime.js +9 -19
- package/dist/src/agent/memory/types.d.ts +1 -1
- package/dist/src/agent/orchestration/agent-orchestrator.js +13 -21
- package/dist/src/agent/orchestration/context-overflow.js +1 -0
- package/dist/src/agent/prompt/sections/memory-skills.js +25 -36
- package/dist/src/agent/prompt/sections/tooling.js +10 -4
- package/dist/src/agent/prompt/service-prompt-builder.js +4 -3
- package/dist/src/agent/service/direct-turn-helpers.d.ts +2 -2
- package/dist/src/agent/service/direct-turn-helpers.js +8 -25
- package/dist/src/agent/service/process-direct-streaming.js +8 -7
- package/dist/src/agent/service.js +4 -3
- package/dist/src/agent/tasks/task-judge-service.js +1 -1
- package/dist/src/agent/tools/clarify-tool.d.ts +1 -0
- package/dist/src/agent/tools/delegate-tool.js +5 -2
- package/dist/src/agent/tools/factory.d.ts +1 -0
- package/dist/src/agent/tools/factory.js +68 -21
- package/dist/src/agent/tools/index.d.ts +3 -2
- package/dist/src/agent/tools/index.js +4 -3
- package/dist/src/agent/tools/knowledge-memory-tool.d.ts +15 -0
- package/dist/src/agent/tools/knowledge-memory-tool.js +184 -0
- package/dist/src/agent/tools/{dreaming-tool.d.ts → memory-maintenance-tool.d.ts} +2 -2
- package/dist/src/agent/tools/memory-maintenance-tool.js +31 -0
- package/dist/src/agent/tools/session-search-tool.d.ts +1 -0
- package/dist/src/agent/tools/session-search-tool.js +7 -0
- package/dist/src/agent/tools/user-context-tool.d.ts +10 -0
- package/dist/src/agent/tools/user-context-tool.js +98 -0
- package/dist/src/agent/tools/xopc-use-tool.js +2 -2
- package/dist/src/automations/service/automation-service.d.ts +2 -1
- package/dist/src/automations/service/automation-service.js +6 -2
- package/dist/src/chat-commands/builtins/understanding.js +24 -6
- package/dist/src/cli/commands/connectors.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/config/schema.d.ts +68 -75
- package/dist/src/config/schema.js +29 -18
- package/dist/src/config/web-patch.d.ts +1 -1
- package/dist/src/connectors/auth-provider-registry.js +1 -1
- package/dist/src/connectors/composio-managed-client.js +6 -2
- package/dist/src/connectors/connected-source-ingestion.js +1 -1
- package/dist/src/connectors/connected-source-understanding.d.ts +1 -3
- package/dist/src/connectors/connected-source-understanding.js +86 -99
- package/dist/src/connectors/connection-candidates.d.ts +11 -0
- package/dist/src/connectors/connection-candidates.js +58 -0
- package/dist/src/connectors/connection-capabilities.d.ts +4 -0
- package/dist/src/connectors/connection-capabilities.js +37 -0
- package/dist/src/connectors/connection-recovery-service.d.ts +43 -0
- package/dist/src/connectors/connection-recovery-service.js +420 -0
- package/dist/src/connectors/health.js +1 -1
- package/dist/src/connectors/learning-coordinator.d.ts +0 -2
- package/dist/src/connectors/learning-coordinator.js +6 -7
- package/dist/src/connectors/principal.d.ts +5 -0
- package/dist/src/connectors/principal.js +18 -0
- package/dist/src/files/file-service.js +4 -1
- package/dist/src/gateway/agent-builtin-tools.d.ts +28 -10
- package/dist/src/gateway/agent-builtin-tools.js +30 -9
- package/dist/src/gateway/chat-stream/mapper.js +1 -28
- package/dist/src/gateway/chat-stream/protocol.d.ts +2 -24
- package/dist/src/gateway/clarify-bridge.d.ts +4 -0
- package/dist/src/gateway/clarify-bridge.js +9 -4
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +52 -30
- package/dist/src/gateway/hono/lib/config-payload.js +4 -4
- package/dist/src/gateway/hono/middleware/auth.js +1 -2
- package/dist/src/gateway/hono/routes/capabilities.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.d.ts +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +72 -28
- package/dist/src/gateway/hono/routes/connection-waits.d.ts +3 -0
- package/dist/src/gateway/hono/routes/connection-waits.js +58 -0
- package/dist/src/gateway/hono/routes/connectors.js +24 -18
- package/dist/src/gateway/hono/routes/context-sources.d.ts +4 -0
- package/dist/src/gateway/hono/routes/context-sources.js +159 -0
- package/dist/src/gateway/hono/routes/files.js +23 -2
- package/dist/src/gateway/hono/routes/index.js +4 -2
- package/dist/src/gateway/hono/routes/lazy-bundles.js +9 -4
- package/dist/src/gateway/hono/routes/mcp.js +1 -1
- package/dist/src/gateway/hono/routes/notes.js +22 -7
- package/dist/src/gateway/hono/routes/projects.js +36 -44
- package/dist/src/gateway/hono/routes/session-input-handler.d.ts +15 -1
- package/dist/src/gateway/hono/routes/side-chats.js +13 -2
- package/dist/src/gateway/hono/routes/tasks.js +3 -3
- package/dist/src/gateway/hono/routes/user-model.d.ts +3 -0
- package/dist/src/gateway/hono/routes/user-model.js +480 -0
- package/dist/src/gateway/memory-maintenance-automation-reconciler.d.ts +11 -0
- package/dist/src/gateway/memory-maintenance-automation-reconciler.js +72 -0
- package/dist/src/gateway/security/gateway-scopes.js +2 -0
- package/dist/src/gateway/service/agent-runner.d.ts +9 -1
- package/dist/src/gateway/service/agent-runner.js +25 -1
- package/dist/src/gateway/service/config-coordinator.d.ts +2 -2
- package/dist/src/gateway/service/config-coordinator.js +4 -4
- package/dist/src/gateway/service/run-gateway-agent.d.ts +1 -0
- package/dist/src/gateway/service/run-gateway-agent.js +18 -14
- package/dist/src/gateway/service/session-input-coordinator.d.ts +3 -0
- package/dist/src/gateway/service/session-input-coordinator.js +12 -2
- package/dist/src/gateway/service.d.ts +3 -1
- package/dist/src/gateway/service.js +52 -17
- package/dist/src/gateway/side-chat/manager.d.ts +16 -3
- package/dist/src/gateway/side-chat/manager.js +117 -28
- package/dist/src/gateway/side-chat/run-service.d.ts +2 -0
- package/dist/src/gateway/side-chat/run-service.js +28 -5
- package/dist/src/gateway/side-chat/types.d.ts +9 -1
- package/dist/src/heartbeat/index.js +1 -1
- package/dist/src/knowledge/connected-knowledge-pipeline.d.ts +0 -2
- package/dist/src/knowledge/connected-knowledge-pipeline.js +46 -217
- package/dist/src/knowledge-memory/domain.d.ts +36 -0
- package/dist/src/knowledge-memory/index.d.ts +2 -0
- package/dist/src/knowledge-memory/index.js +2 -0
- package/dist/src/knowledge-memory/repository.d.ts +48 -0
- package/dist/src/knowledge-memory/repository.js +168 -0
- package/dist/src/memory-maintenance/index.d.ts +2 -0
- package/dist/src/memory-maintenance/index.js +3 -0
- package/dist/src/memory-maintenance/schedule.d.ts +13 -0
- package/dist/src/memory-maintenance/schedule.js +51 -0
- package/dist/src/memory-maintenance/service.d.ts +28 -0
- package/dist/src/memory-maintenance/service.js +216 -0
- package/dist/src/notes/service.d.ts +1 -0
- package/dist/src/notes/service.js +7 -1
- package/dist/src/notes/types.d.ts +16 -0
- package/dist/src/notifications/planner.js +7 -3
- package/dist/src/proactive/actions/service.d.ts +0 -1
- package/dist/src/proactive/actions/service.js +1 -10
- package/dist/src/proactive/execution/context.d.ts +8 -10
- package/dist/src/proactive/execution/context.js +93 -42
- package/dist/src/proactive/execution/insight.d.ts +4 -1
- package/dist/src/proactive/execution/insight.js +5 -2
- package/dist/src/proactive/execution/repository.d.ts +1 -0
- package/dist/src/proactive/execution/repository.js +9 -1
- package/dist/src/proactive/execution/types.d.ts +0 -1
- package/dist/src/proactive/execution/worker.js +7 -5
- package/dist/src/proactive/inbox/repository.js +8 -2
- package/dist/src/proactive/inbox/service.js +2 -2
- package/dist/src/proactive/inbox/types.d.ts +1 -0
- package/dist/src/proactive/inbox/worker.d.ts +1 -0
- package/dist/src/proactive/inbox/worker.js +7 -0
- package/dist/src/proactive/index.d.ts +2 -1
- package/dist/src/proactive/index.js +3 -2
- package/dist/src/proactive/maintenance.d.ts +4 -0
- package/dist/src/proactive/maintenance.js +21 -0
- package/dist/src/proactive/scenarios/repository.d.ts +1 -1
- package/dist/src/proactive/scenarios/repository.js +10 -3
- package/dist/src/proactive/scenarios/types.d.ts +7 -0
- package/dist/src/proactive/service.d.ts +7 -0
- package/dist/src/proactive/service.js +17 -1
- package/dist/src/projects/index.d.ts +1 -1
- package/dist/src/projects/index.js +2 -2
- package/dist/src/projects/knowledge-bind.d.ts +1 -0
- package/dist/src/projects/knowledge-bind.js +15 -0
- package/dist/src/projects/project-loop.d.ts +3 -3
- package/dist/src/projects/project-loop.js +4 -4
- package/dist/src/projects/project-service.d.ts +2 -1
- package/dist/src/projects/project-service.js +3 -2
- package/dist/src/projects/project-store.js +2 -1
- package/dist/src/realtime/runtime.js +1 -0
- package/dist/src/runtime-tools/manager.js +1 -1
- package/dist/src/session/index.js +1 -1
- package/dist/src/session/store.js +5 -2
- package/dist/src/storage/sqlite/collaboration-rule-repository.d.ts +19 -0
- package/dist/src/storage/sqlite/collaboration-rule-repository.js +54 -0
- package/dist/src/storage/sqlite/config-repository.js +1 -1
- package/dist/src/storage/sqlite/connection-wait-repository.d.ts +30 -0
- package/dist/src/storage/sqlite/connection-wait-repository.js +338 -0
- package/dist/src/storage/sqlite/connector-account-repository.js +1 -1
- package/dist/src/storage/sqlite/context-evidence-repository.d.ts +24 -0
- package/dist/src/storage/sqlite/context-evidence-repository.js +52 -0
- package/dist/src/storage/sqlite/index.d.ts +3 -5
- package/dist/src/storage/sqlite/index.js +6 -8
- package/dist/src/storage/sqlite/knowledge-repository.d.ts +0 -19
- package/dist/src/storage/sqlite/knowledge-repository.js +1 -90
- package/dist/src/storage/sqlite/migrations/148_user_model_foundation.sql +554 -0
- package/dist/src/storage/sqlite/migrations/149_separate_source_index_from_memory.sql +18 -0
- package/dist/src/storage/sqlite/migrations/150_session_connection_waits.sql +47 -0
- package/dist/src/storage/sqlite/migrations/151_proactive_scope_cleanup.sql +6 -0
- package/dist/src/storage/sqlite/migrations/152_proactive_scenario_contract.sql +140 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/notes-repository.d.ts +2 -1
- package/dist/src/storage/sqlite/notes-repository.js +37 -3
- package/dist/src/storage/sqlite/row-mappers.js +2 -2
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/session-input-repository.d.ts +14 -2
- package/dist/src/storage/sqlite/session-input-repository.js +17 -14
- package/dist/src/storage/sqlite/session-instance-repository.d.ts +2 -0
- package/dist/src/storage/sqlite/session-instance-repository.js +6 -0
- package/dist/src/storage/sqlite/session-repository.d.ts +1 -1
- package/dist/src/storage/sqlite/session-repository.js +7 -6
- package/dist/src/storage/sqlite/transcript-repository.js +3 -2
- package/dist/src/tasks/home-query-service.js +35 -13
- package/dist/src/tasks/index.js +2 -2
- package/dist/src/tasks/project-monitoring-service.d.ts +2 -0
- package/dist/src/tasks/project-monitoring-service.js +4 -1
- package/dist/src/tasks/project-operating-view-service.js +1 -1
- package/dist/src/tasks/task-application-service.js +6 -1
- package/dist/src/tasks/task-context-assembler.js +1 -1
- package/dist/src/tasks/task-context-repository.d.ts +0 -1
- package/dist/src/tasks/task-context-repository.js +1 -1
- package/dist/src/tasks/task-deletion-service.js +1 -1
- package/dist/src/tasks/task-handoff-service.js +1 -1
- package/dist/src/tasks/task-read-model-projector.js +1 -1
- package/dist/src/tasks/task-run-coordinator.js +1 -1
- package/dist/src/tasks/task-run-dispatcher.js +1 -1
- package/dist/src/tasks/task-run-repository.js +1 -0
- package/dist/src/tasks/task-signal-service.js +1 -1
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/tui/tool-summary.js +2 -1
- package/dist/src/tui/tui-startup-resources.js +1 -1
- package/dist/src/user-context/access-policy.d.ts +11 -0
- package/dist/src/user-context/access-policy.js +26 -0
- package/dist/src/user-context/changes.d.ts +1 -1
- package/dist/src/user-context/config.d.ts +135 -153
- package/dist/src/user-context/config.js +94 -99
- package/dist/src/user-context/relationship-continuity.d.ts +2 -2
- package/dist/src/user-context/relationship-continuity.js +34 -24
- package/dist/src/user-context/sources/activity-clustering.d.ts +9 -3
- package/dist/src/user-context/sources/index.js +2 -2
- package/dist/src/user-context/sources/repository.d.ts +1 -21
- package/dist/src/user-context/sources/repository.js +1 -183
- package/dist/src/user-context/sources/types.d.ts +0 -23
- package/dist/src/user-model/capture/executor.d.ts +50 -0
- package/dist/src/user-model/capture/executor.js +230 -0
- package/dist/src/user-model/capture/index.d.ts +2 -0
- package/dist/src/user-model/capture/index.js +3 -0
- package/dist/src/user-model/capture/semantic.d.ts +39 -0
- package/dist/src/user-model/capture/semantic.js +263 -0
- package/dist/src/user-model/domain.d.ts +93 -0
- package/dist/src/user-model/domain.js +33 -0
- package/dist/src/user-model/goals.d.ts +62 -0
- package/dist/src/user-model/goals.js +91 -0
- package/dist/src/user-model/importance.d.ts +11 -0
- package/dist/src/user-model/importance.js +17 -0
- package/dist/src/user-model/index.d.ts +5 -0
- package/dist/src/user-model/index.js +6 -0
- package/dist/src/user-model/repository.d.ts +23 -0
- package/dist/src/user-model/repository.js +268 -0
- package/dist/src/user-model/temporal.d.ts +10 -0
- package/dist/src/user-model/temporal.js +44 -0
- package/dist/src/voice/realtime/memory-context.d.ts +7 -2
- package/dist/src/voice/realtime/memory-context.js +39 -51
- package/dist/src/work-discovery/service.d.ts +3 -14
- package/dist/src/work-discovery/service.js +138 -99
- package/dist/src/work-discovery/types.d.ts +3 -3
- package/dist/src/workflows/service/workflow-run-service.js +1 -1
- package/dist/src/workflows/service/workflow-session-bridge.js +12 -20
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-CUXApfcE.js +0 -1
- package/dist/gateway/static/root/assets/agents-DNq_GKuc.js +0 -1
- package/dist/gateway/static/root/assets/app-management-settings-panel-qfwAgyhQ.js +0 -1
- package/dist/gateway/static/root/assets/appearance-settings-DqQVUpCC.js +0 -1
- package/dist/gateway/static/root/assets/apps-page-dwIqYmXk.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-SkdcSZ0i.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-CKCa6TvG.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DSp--zIZ.js +0 -7
- package/dist/gateway/static/root/assets/channels-settings-CMd2dDrI.js +0 -1
- package/dist/gateway/static/root/assets/cloud-C4-yfnnk.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-udWs5Kdm.js +0 -2
- package/dist/gateway/static/root/assets/dependency-picker-DpN3XZg9.js +0 -1
- package/dist/gateway/static/root/assets/desktop-pet-settings-DinCToZh.js +0 -1
- package/dist/gateway/static/root/assets/ellipsis-0k4rZLoy.js +0 -1
- package/dist/gateway/static/root/assets/extension-settings-page-DcguCgsH.js +0 -1
- package/dist/gateway/static/root/assets/eye-CABVeTq0.js +0 -1
- package/dist/gateway/static/root/assets/eye-off-DEAzt3g1.js +0 -1
- package/dist/gateway/static/root/assets/files-D6vf3S30.js +0 -1
- package/dist/gateway/static/root/assets/folder-open-CyzJ19I9.js +0 -1
- package/dist/gateway/static/root/assets/form-field-width-DJw_jULe.js +0 -1
- package/dist/gateway/static/root/assets/gateway-config-api-Br7lSf6H.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-CdPoDMuj.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-DHk1hawP.js +0 -1
- package/dist/gateway/static/root/assets/home-page-YGipe_W6.js +0 -1
- package/dist/gateway/static/root/assets/index-D5TQQpeb.js +0 -71
- package/dist/gateway/static/root/assets/index-DReBaaTX.css +0 -2
- package/dist/gateway/static/root/assets/interaction-BmQogeqz.js +0 -1
- package/dist/gateway/static/root/assets/is-masked-secret-DOkL5b_X.js +0 -1
- package/dist/gateway/static/root/assets/link-2-D_ZKYUW7.js +0 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-CpyvYyrb.js +0 -2
- package/dist/gateway/static/root/assets/local-context-graph-BjUf7fQ9.js +0 -1
- package/dist/gateway/static/root/assets/logs-page-CXKy6E_l.js +0 -2
- package/dist/gateway/static/root/assets/message-square-plus-XP0tGdlV.js +0 -1
- package/dist/gateway/static/root/assets/messages-CHNYp8EQ.js +0 -3
- package/dist/gateway/static/root/assets/minimize-2-DtOGrlpo.js +0 -1
- package/dist/gateway/static/root/assets/mobile-pairing-wizard-3NKCniSp.js +0 -1
- package/dist/gateway/static/root/assets/models-hub-cache-nCfkBN8M.js +0 -1
- package/dist/gateway/static/root/assets/notes-page-DuqLahi6.js +0 -1
- package/dist/gateway/static/root/assets/notes-workbench-C7j9EdQk.js +0 -5
- package/dist/gateway/static/root/assets/oauth-api-8lP_qJpq.js +0 -1
- package/dist/gateway/static/root/assets/oauth-authorization-window-Cdolr2wE.js +0 -1
- package/dist/gateway/static/root/assets/page-tabs-BaEQMYm_.js +0 -1
- package/dist/gateway/static/root/assets/pencil-DmIY3Oa-.js +0 -1
- package/dist/gateway/static/root/assets/preview-open-alternatives-CsNVTKC0.js +0 -1
- package/dist/gateway/static/root/assets/project-detail-page-CfebYVX0.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-48GvzSVa.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-64xj_s2m.js +0 -1
- package/dist/gateway/static/root/assets/rotate-cw-LIg3Am9S.js +0 -1
- package/dist/gateway/static/root/assets/search-DA7gz22f.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-CcwcdRN8.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BaN84CyW.js +0 -1
- package/dist/gateway/static/root/assets/settings-form-section-DjWzRk4z.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-DVVOCNbr.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-DUYbYLi7.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-BGyD0gB9.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-CjF8DTsN.js +0 -2
- package/dist/gateway/static/root/assets/system-settings-panel-BSYuRgFI.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-YZYSTJH7.js +0 -1
- package/dist/gateway/static/root/assets/tunnel-api-FKUi9wDL.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-BCyiduKd.js +0 -2
- package/dist/gateway/static/root/assets/work-discovery-overlay-jhT2EzeH.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-DQC0TpMa.js +0 -5
- package/dist/src/agent/memory/builtin-provider.d.ts +0 -37
- package/dist/src/agent/memory/builtin-provider.js +0 -225
- package/dist/src/agent/memory/context/types.d.ts +0 -40
- package/dist/src/agent/memory/understanding/quality.d.ts +0 -8
- package/dist/src/agent/memory/understanding/quality.js +0 -18
- package/dist/src/agent/memory/understanding/service.d.ts +0 -19
- package/dist/src/agent/memory/understanding/service.js +0 -209
- package/dist/src/agent/memory/understanding/types.d.ts +0 -34
- package/dist/src/agent/memory/user-context-coordinator.d.ts +0 -23
- package/dist/src/agent/memory/user-context-coordinator.js +0 -113
- package/dist/src/agent/tools/dreaming-tool.js +0 -37
- package/dist/src/agent/tools/memory-tool.d.ts +0 -9
- package/dist/src/agent/tools/memory-tool.js +0 -119
- package/dist/src/gateway/dreaming-automation-reconciler.d.ts +0 -11
- package/dist/src/gateway/dreaming-automation-reconciler.js +0 -63
- package/dist/src/gateway/hono/routes/understanding-sources.d.ts +0 -21
- package/dist/src/gateway/hono/routes/understanding-sources.js +0 -387
- package/dist/src/gateway/hono/routes/you.d.ts +0 -3
- package/dist/src/gateway/hono/routes/you.js +0 -457
- package/dist/src/projects/memory-bind.d.ts +0 -1
- package/dist/src/projects/memory-bind.js +0 -14
- package/dist/src/storage/sqlite/context-consolidation-repository.d.ts +0 -37
- package/dist/src/storage/sqlite/context-consolidation-repository.js +0 -64
- package/dist/src/storage/sqlite/memory-records-repository.d.ts +0 -217
- package/dist/src/storage/sqlite/memory-records-repository.js +0 -715
- package/dist/src/storage/sqlite/remote-context-repository.d.ts +0 -3
- package/dist/src/storage/sqlite/remote-context-repository.js +0 -40
- package/dist/src/storage/sqlite/understanding-focus-exclusions.d.ts +0 -2
- package/dist/src/storage/sqlite/understanding-focus-exclusions.js +0 -24
- package/dist/src/storage/sqlite/user-context-quality-repository.d.ts +0 -49
- package/dist/src/storage/sqlite/user-context-quality-repository.js +0 -118
- package/dist/src/storage/sqlite/user-context-repository.d.ts +0 -85
- package/dist/src/storage/sqlite/user-context-repository.js +0 -535
- package/dist/src/user-context/automatic-context.d.ts +0 -17
- package/dist/src/user-context/automatic-context.js +0 -85
- package/dist/src/user-context/consolidation.d.ts +0 -27
- package/dist/src/user-context/consolidation.js +0 -187
- package/dist/src/user-context/context-objects.d.ts +0 -17
- package/dist/src/user-context/context-objects.js +0 -99
- package/dist/src/user-context/evaluation/harness.d.ts +0 -13
- package/dist/src/user-context/evaluation/harness.js +0 -31
- package/dist/src/user-context/extraction/executor.d.ts +0 -22
- package/dist/src/user-context/extraction/executor.js +0 -142
- package/dist/src/user-context/extraction/repair.d.ts +0 -19
- package/dist/src/user-context/extraction/repair.js +0 -71
- package/dist/src/user-context/extraction/semantic.d.ts +0 -18
- package/dist/src/user-context/extraction/semantic.js +0 -148
- package/dist/src/user-context/focus-lifecycle.d.ts +0 -2
- package/dist/src/user-context/focus-lifecycle.js +0 -26
- package/dist/src/user-context/manual-understanding.d.ts +0 -12
- package/dist/src/user-context/manual-understanding.js +0 -37
- package/dist/src/user-context/planner.d.ts +0 -17
- package/dist/src/user-context/planner.js +0 -465
- package/dist/src/user-context/relationships/indexer.d.ts +0 -13
- package/dist/src/user-context/relationships/indexer.js +0 -185
- package/dist/src/user-context/relationships/service.d.ts +0 -22
- package/dist/src/user-context/relationships/service.js +0 -50
- package/dist/src/user-context/retriever.d.ts +0 -15
- package/dist/src/user-context/retriever.js +0 -124
- package/dist/src/user-context/scope.d.ts +0 -7
- package/dist/src/user-context/scope.js +0 -9
- package/dist/src/user-context/selection-policy.d.ts +0 -20
- package/dist/src/user-context/selection-policy.js +0 -33
- package/dist/src/user-context/understanding.d.ts +0 -15
- package/dist/src/user-context/understanding.js +0 -24
- package/dist/src/user-context/understandingQuality.d.ts +0 -5
- package/dist/src/user-context/understandingQuality.js +0 -48
- /package/dist/src/agent/{memory/context/types.js → context/execution-context.types.js} +0 -0
- /package/dist/src/{agent/memory/understanding/types.js → knowledge-memory/domain.js} +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/user-model/domain.ts
|
|
2
|
+
const USER_MODEL_PRINCIPAL_ID = "local-owner";
|
|
3
|
+
function validateScope(scope) {
|
|
4
|
+
const id = scope.id?.trim();
|
|
5
|
+
if (scope.type === "global") {
|
|
6
|
+
if (id) throw new Error("Global user-model scope must not have an id.");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (!id) throw new Error(`${scope.type} user-model scope requires an id.`);
|
|
10
|
+
}
|
|
11
|
+
function validateCandidate(candidate) {
|
|
12
|
+
validateScope(candidate.scope);
|
|
13
|
+
if (!candidate.subject.id.trim()) throw new Error("Assertion subject id is required.");
|
|
14
|
+
if (!candidate.predicate.trim()) throw new Error("Assertion predicate is required.");
|
|
15
|
+
if (!candidate.normalizedValue.trim()) throw new Error("Assertion normalized value is required.");
|
|
16
|
+
if (!candidate.statement.trim()) throw new Error("Assertion statement is required.");
|
|
17
|
+
if (!Number.isFinite(candidate.observedAt)) throw new Error("Assertion observedAt must be finite.");
|
|
18
|
+
for (const [field, value] of [
|
|
19
|
+
["validFrom", candidate.validFrom],
|
|
20
|
+
["validTo", candidate.validTo],
|
|
21
|
+
["reviewAt", candidate.reviewAt]
|
|
22
|
+
]) if (value !== void 0 && !Number.isFinite(value)) throw new Error(`${field} must be finite.`);
|
|
23
|
+
for (const [field, value] of [
|
|
24
|
+
["confidence", candidate.confidence],
|
|
25
|
+
["inferredImportance", candidate.inferredImportance],
|
|
26
|
+
["actionability", candidate.actionability],
|
|
27
|
+
["declaredImportance", candidate.declaredImportance],
|
|
28
|
+
["evidenceConfidence", candidate.evidenceConfidence]
|
|
29
|
+
]) if (value !== void 0 && (!Number.isFinite(value) || value < 0 || value > 1)) throw new Error(`${field} must be between 0 and 1.`);
|
|
30
|
+
if (candidate.validFrom !== void 0 && candidate.validTo !== void 0 && candidate.validTo < candidate.validFrom) throw new Error("Assertion validTo must be greater than or equal to validFrom.");
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { USER_MODEL_PRINCIPAL_ID, validateCandidate, validateScope };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type AssertionAuthority, type UserModelScope } from './domain.js';
|
|
2
|
+
export type UserGoalStatus = 'proposed' | 'active' | 'paused' | 'achieved' | 'abandoned';
|
|
3
|
+
export interface UserGoal {
|
|
4
|
+
id: string;
|
|
5
|
+
principalId: string;
|
|
6
|
+
status: UserGoalStatus;
|
|
7
|
+
scope: UserModelScope;
|
|
8
|
+
title: string;
|
|
9
|
+
desiredOutcome: string;
|
|
10
|
+
declaredImportance?: number;
|
|
11
|
+
confidence: number;
|
|
12
|
+
authority: AssertionAuthority;
|
|
13
|
+
targetAt?: number;
|
|
14
|
+
validFrom?: number;
|
|
15
|
+
validTo?: number;
|
|
16
|
+
reviewAt?: number;
|
|
17
|
+
createdAt: number;
|
|
18
|
+
updatedAt: number;
|
|
19
|
+
}
|
|
20
|
+
export interface UserPriorityWindow {
|
|
21
|
+
id: string;
|
|
22
|
+
principalId: string;
|
|
23
|
+
targetType: 'goal' | 'project' | 'task' | 'assertion' | 'topic';
|
|
24
|
+
targetId: string;
|
|
25
|
+
rank: 'primary' | 'secondary' | 'background';
|
|
26
|
+
declaredImportance?: number;
|
|
27
|
+
urgency: number;
|
|
28
|
+
scope: UserModelScope;
|
|
29
|
+
validFrom: number;
|
|
30
|
+
validTo: number;
|
|
31
|
+
reviewAt: number;
|
|
32
|
+
status: 'active' | 'paused' | 'completed' | 'expired';
|
|
33
|
+
createdAt: number;
|
|
34
|
+
updatedAt: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function listUserGoals(principalId?: string): UserGoal[];
|
|
37
|
+
export declare function createUserGoal(input: {
|
|
38
|
+
title: string;
|
|
39
|
+
desiredOutcome: string;
|
|
40
|
+
scope: UserModelScope;
|
|
41
|
+
declaredImportance?: number;
|
|
42
|
+
targetAt?: number;
|
|
43
|
+
status?: Extract<UserGoalStatus, 'proposed' | 'active'>;
|
|
44
|
+
authority?: AssertionAuthority;
|
|
45
|
+
confidence?: number;
|
|
46
|
+
createdBy?: 'user' | 'runtime';
|
|
47
|
+
now?: number;
|
|
48
|
+
}): UserGoal;
|
|
49
|
+
export declare function setUserGoalStatus(id: string, status: UserGoalStatus, now?: number): UserGoal | undefined;
|
|
50
|
+
export declare function listPriorityWindows(principalId?: string): UserPriorityWindow[];
|
|
51
|
+
export declare function createPriorityWindow(input: {
|
|
52
|
+
targetType: UserPriorityWindow['targetType'];
|
|
53
|
+
targetId: string;
|
|
54
|
+
rank: UserPriorityWindow['rank'];
|
|
55
|
+
urgency: number;
|
|
56
|
+
scope: UserModelScope;
|
|
57
|
+
validFrom: number;
|
|
58
|
+
validTo: number;
|
|
59
|
+
reviewAt?: number;
|
|
60
|
+
declaredImportance?: number;
|
|
61
|
+
now?: number;
|
|
62
|
+
}): UserPriorityWindow;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { getSqliteDatabase, runSqliteWriteTransaction } from "../storage/sqlite/transaction.js";
|
|
2
|
+
import { USER_MODEL_PRINCIPAL_ID, validateScope } from "./domain.js";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
//#region src/user-model/goals.ts
|
|
5
|
+
function optionalNumber(value) {
|
|
6
|
+
return value === null ? void 0 : value;
|
|
7
|
+
}
|
|
8
|
+
function listUserGoals(principalId = USER_MODEL_PRINCIPAL_ID) {
|
|
9
|
+
return getSqliteDatabase().prepare(`SELECT g.*, r.title, r.desired_outcome
|
|
10
|
+
FROM user_goals g JOIN user_goal_revisions r ON r.revision_id = g.current_revision_id
|
|
11
|
+
WHERE g.principal_id = ? ORDER BY g.updated_at DESC`).all(principalId).map((row) => ({
|
|
12
|
+
id: row.goal_id,
|
|
13
|
+
principalId: row.principal_id,
|
|
14
|
+
status: row.status,
|
|
15
|
+
scope: {
|
|
16
|
+
type: row.scope_type,
|
|
17
|
+
...row.scope_id ? { id: row.scope_id } : {}
|
|
18
|
+
},
|
|
19
|
+
title: row.title,
|
|
20
|
+
desiredOutcome: row.desired_outcome,
|
|
21
|
+
...optionalNumber(row.declared_importance) === void 0 ? {} : { declaredImportance: row.declared_importance },
|
|
22
|
+
confidence: row.confidence,
|
|
23
|
+
authority: row.authority,
|
|
24
|
+
...optionalNumber(row.target_at) === void 0 ? {} : { targetAt: row.target_at },
|
|
25
|
+
...optionalNumber(row.valid_from) === void 0 ? {} : { validFrom: row.valid_from },
|
|
26
|
+
...optionalNumber(row.valid_to) === void 0 ? {} : { validTo: row.valid_to },
|
|
27
|
+
...optionalNumber(row.review_at) === void 0 ? {} : { reviewAt: row.review_at },
|
|
28
|
+
createdAt: row.created_at,
|
|
29
|
+
updatedAt: row.updated_at
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
function createUserGoal(input) {
|
|
33
|
+
validateScope(input.scope);
|
|
34
|
+
if (!input.title.trim() || !input.desiredOutcome.trim()) throw new Error("Goal title and desired outcome are required.");
|
|
35
|
+
if (input.declaredImportance !== void 0 && (input.declaredImportance < 0 || input.declaredImportance > 1)) throw new Error("Goal declared importance must be between 0 and 1.");
|
|
36
|
+
const now = input.now ?? Date.now();
|
|
37
|
+
const confidence = input.confidence ?? 1;
|
|
38
|
+
if (confidence < 0 || confidence > 1) throw new Error("Goal confidence must be between 0 and 1.");
|
|
39
|
+
const goalId = randomUUID();
|
|
40
|
+
const revisionId = randomUUID();
|
|
41
|
+
runSqliteWriteTransaction((db) => {
|
|
42
|
+
db.prepare(`INSERT INTO user_goals (
|
|
43
|
+
goal_id, principal_id, status, scope_type, scope_id, declared_importance,
|
|
44
|
+
confidence, authority, target_at, current_revision_id, created_at, updated_at
|
|
45
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(goalId, USER_MODEL_PRINCIPAL_ID, input.status ?? "active", input.scope.type, input.scope.id ?? null, input.declaredImportance ?? null, confidence, input.authority ?? "user_explicit", input.targetAt ?? null, revisionId, now, now);
|
|
46
|
+
db.prepare(`INSERT INTO user_goal_revisions (
|
|
47
|
+
revision_id, goal_id, title, desired_outcome, created_by, change_reason, created_at
|
|
48
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(revisionId, goalId, input.title.trim(), input.desiredOutcome.trim(), input.createdBy ?? "user", input.createdBy === "runtime" ? "Goal extracted from user evidence." : "Goal created by user.", now);
|
|
49
|
+
});
|
|
50
|
+
return listUserGoals().find((goal) => goal.id === goalId);
|
|
51
|
+
}
|
|
52
|
+
function setUserGoalStatus(id, status, now = Date.now()) {
|
|
53
|
+
return getSqliteDatabase().prepare(`UPDATE user_goals SET status = ?, updated_at = ? WHERE goal_id = ?`).run(status, now, id).changes ? listUserGoals().find((goal) => goal.id === id) : void 0;
|
|
54
|
+
}
|
|
55
|
+
function listPriorityWindows(principalId = USER_MODEL_PRINCIPAL_ID) {
|
|
56
|
+
return getSqliteDatabase().prepare(`SELECT * FROM user_priority_windows
|
|
57
|
+
WHERE principal_id = ? ORDER BY valid_from DESC`).all(principalId).map((row) => ({
|
|
58
|
+
id: row.priority_id,
|
|
59
|
+
principalId: row.principal_id,
|
|
60
|
+
targetType: row.target_type,
|
|
61
|
+
targetId: row.target_id,
|
|
62
|
+
rank: row.rank,
|
|
63
|
+
...row.declared_importance === null ? {} : { declaredImportance: row.declared_importance },
|
|
64
|
+
urgency: row.urgency,
|
|
65
|
+
scope: {
|
|
66
|
+
type: row.scope_type,
|
|
67
|
+
...row.scope_id ? { id: row.scope_id } : {}
|
|
68
|
+
},
|
|
69
|
+
validFrom: row.valid_from,
|
|
70
|
+
validTo: row.valid_to,
|
|
71
|
+
reviewAt: row.review_at,
|
|
72
|
+
status: row.status,
|
|
73
|
+
createdAt: row.created_at,
|
|
74
|
+
updatedAt: row.updated_at
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
function createPriorityWindow(input) {
|
|
78
|
+
validateScope(input.scope);
|
|
79
|
+
if (!input.targetId.trim()) throw new Error("Priority target id is required.");
|
|
80
|
+
if (input.validTo < input.validFrom) throw new Error("Priority validTo must be after validFrom.");
|
|
81
|
+
for (const value of [input.urgency, input.declaredImportance]) if (value !== void 0 && (value < 0 || value > 1)) throw new Error("Priority scores must be between 0 and 1.");
|
|
82
|
+
const now = input.now ?? Date.now();
|
|
83
|
+
const id = randomUUID();
|
|
84
|
+
getSqliteDatabase().prepare(`INSERT INTO user_priority_windows (
|
|
85
|
+
priority_id, principal_id, target_type, target_id, rank, declared_importance,
|
|
86
|
+
urgency, scope_type, scope_id, valid_from, valid_to, review_at, status, created_at, updated_at
|
|
87
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, ?)`).run(id, USER_MODEL_PRINCIPAL_ID, input.targetType, input.targetId.trim(), input.rank, input.declaredImportance ?? null, input.urgency, input.scope.type, input.scope.id ?? null, input.validFrom, input.validTo, input.reviewAt ?? input.validTo, now, now);
|
|
88
|
+
return listPriorityWindows().find((item) => item.id === id);
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { createPriorityWindow, createUserGoal, listPriorityWindows, listUserGoals, setUserGoalStatus };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AssertionConsequence } from './domain.js';
|
|
2
|
+
export interface ExecutionValueInput {
|
|
3
|
+
declaredImportance?: number;
|
|
4
|
+
inferredImportance: number;
|
|
5
|
+
consequence: AssertionConsequence;
|
|
6
|
+
actionability: number;
|
|
7
|
+
taskRelevance: number;
|
|
8
|
+
urgency: number;
|
|
9
|
+
}
|
|
10
|
+
/** Ranks eligible context. Confidence is deliberately absent: it is an admission signal. */
|
|
11
|
+
export declare function calculateExecutionValue(input: ExecutionValueInput): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/user-model/importance.ts
|
|
2
|
+
const CONSEQUENCE_SCORE = {
|
|
3
|
+
low: .15,
|
|
4
|
+
medium: .45,
|
|
5
|
+
high: .75,
|
|
6
|
+
critical: 1
|
|
7
|
+
};
|
|
8
|
+
function clamp(value) {
|
|
9
|
+
return Math.min(1, Math.max(0, value));
|
|
10
|
+
}
|
|
11
|
+
/** Ranks eligible context. Confidence is deliberately absent: it is an admission signal. */
|
|
12
|
+
function calculateExecutionValue(input) {
|
|
13
|
+
const importance = input.declaredImportance ?? input.inferredImportance;
|
|
14
|
+
return clamp(.28 * clamp(input.taskRelevance) + .22 * clamp(importance) + .2 * CONSEQUENCE_SCORE[input.consequence] + .18 * clamp(input.actionability) + .12 * clamp(input.urgency));
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { calculateExecutionValue };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { USER_MODEL_PRINCIPAL_ID, validateCandidate, validateScope } from "./domain.js";
|
|
2
|
+
import { calculateExecutionValue } from "./importance.js";
|
|
3
|
+
import { createPriorityWindow, createUserGoal, listPriorityWindows, listUserGoals, setUserGoalStatus } from "./goals.js";
|
|
4
|
+
import { defaultReviewAt, isAssertionValidAt, requiresBoundedValidity, resolveCurrentAssertion } from "./temporal.js";
|
|
5
|
+
import { getActiveAssertionByPredicate, getActiveAssertionForSlot, getAssertionSlot, getUserAssertion, getUserTimezone, linkAssertionEvidence, listSlotAssertions, listUserAssertions, reconcileAssertion, setAssertionStatus } from "./repository.js";
|
|
6
|
+
export { USER_MODEL_PRINCIPAL_ID, calculateExecutionValue, createPriorityWindow, createUserGoal, defaultReviewAt, getActiveAssertionByPredicate, getActiveAssertionForSlot, getAssertionSlot, getUserAssertion, getUserTimezone, isAssertionValidAt, linkAssertionEvidence, listPriorityWindows, listSlotAssertions, listUserAssertions, listUserGoals, reconcileAssertion, requiresBoundedValidity, resolveCurrentAssertion, setAssertionStatus, setUserGoalStatus, validateCandidate, validateScope };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AssertionCandidate, type AssertionSlot, type AssertionStatus, type ReconciliationResult, type UserAssertion } from './domain.js';
|
|
2
|
+
export declare function reconcileAssertion(candidate: AssertionCandidate, now?: number): ReconciliationResult;
|
|
3
|
+
export declare function getUserAssertion(id: string): UserAssertion | undefined;
|
|
4
|
+
export declare function getAssertionSlot(id: string): AssertionSlot | undefined;
|
|
5
|
+
export declare function listSlotAssertions(slotId: string): UserAssertion[];
|
|
6
|
+
export declare function listUserAssertions(input?: {
|
|
7
|
+
principalId?: string;
|
|
8
|
+
statuses?: AssertionStatus[];
|
|
9
|
+
limit?: number;
|
|
10
|
+
}): UserAssertion[];
|
|
11
|
+
export declare function getActiveAssertionByPredicate(predicate: string): UserAssertion | undefined;
|
|
12
|
+
export declare function getActiveAssertionForSlot(input: {
|
|
13
|
+
subject: AssertionSlot['subject'];
|
|
14
|
+
predicate: string;
|
|
15
|
+
scope: AssertionSlot['scope'];
|
|
16
|
+
}): UserAssertion | undefined;
|
|
17
|
+
export declare function getUserTimezone(): string | undefined;
|
|
18
|
+
export declare function linkAssertionEvidence(assertionId: string, evidenceId: string, relation: 'supports' | 'contradicts' | 'supersedes', confidence: number, now?: number): void;
|
|
19
|
+
export declare function setAssertionStatus(assertionId: string, status: AssertionStatus, input: {
|
|
20
|
+
actor: 'user' | 'runtime' | 'maintenance' | 'migration';
|
|
21
|
+
reason: string;
|
|
22
|
+
now?: number;
|
|
23
|
+
}): UserAssertion;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { getSqliteDatabase, runSqliteWriteTransaction } from "../storage/sqlite/transaction.js";
|
|
2
|
+
import { USER_MODEL_PRINCIPAL_ID, validateCandidate, validateScope } from "./domain.js";
|
|
3
|
+
import { defaultReviewAt, requiresBoundedValidity } from "./temporal.js";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
//#region src/user-model/repository.ts
|
|
6
|
+
function slotFromRow(row) {
|
|
7
|
+
return {
|
|
8
|
+
id: row.slot_id,
|
|
9
|
+
principalId: row.principal_id,
|
|
10
|
+
subject: {
|
|
11
|
+
type: row.subject_type,
|
|
12
|
+
id: row.subject_id
|
|
13
|
+
},
|
|
14
|
+
predicate: row.predicate,
|
|
15
|
+
cardinality: row.cardinality,
|
|
16
|
+
scope: {
|
|
17
|
+
type: row.scope_type,
|
|
18
|
+
...row.scope_id ? { id: row.scope_id } : {}
|
|
19
|
+
},
|
|
20
|
+
createdAt: row.created_at
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function assertionFromRow(row) {
|
|
24
|
+
return {
|
|
25
|
+
id: row.assertion_id,
|
|
26
|
+
slotId: row.slot_id,
|
|
27
|
+
kind: row.kind,
|
|
28
|
+
value: JSON.parse(row.value_json),
|
|
29
|
+
normalizedValue: row.normalized_value,
|
|
30
|
+
statement: row.statement,
|
|
31
|
+
authority: row.authority,
|
|
32
|
+
status: row.status,
|
|
33
|
+
confidence: row.confidence,
|
|
34
|
+
...row.declared_importance === null ? {} : { declaredImportance: row.declared_importance },
|
|
35
|
+
inferredImportance: row.inferred_importance,
|
|
36
|
+
consequence: row.consequence,
|
|
37
|
+
actionability: row.actionability,
|
|
38
|
+
volatility: row.volatility,
|
|
39
|
+
sensitivity: row.sensitivity,
|
|
40
|
+
disclosurePolicy: row.disclosure_policy,
|
|
41
|
+
applicability: JSON.parse(row.applicability_json),
|
|
42
|
+
...row.valid_from === null ? {} : { validFrom: row.valid_from },
|
|
43
|
+
...row.valid_to === null ? {} : { validTo: row.valid_to },
|
|
44
|
+
observedAt: row.observed_at,
|
|
45
|
+
recordedAt: row.recorded_at,
|
|
46
|
+
...row.review_at === null ? {} : { reviewAt: row.review_at },
|
|
47
|
+
...row.supersedes_assertion_id === null ? {} : { supersedesAssertionId: row.supersedes_assertion_id },
|
|
48
|
+
createdBy: row.created_by,
|
|
49
|
+
createdAt: row.created_at
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function findOrCreateSlot(db, candidate, now) {
|
|
53
|
+
const principalId = candidate.principalId ?? "local-owner";
|
|
54
|
+
const scopeId = candidate.scope.id?.trim() ?? null;
|
|
55
|
+
const existing = db.prepare(`SELECT * FROM user_assertion_slots
|
|
56
|
+
WHERE principal_id = ? AND subject_type = ? AND subject_id = ? AND predicate = ?
|
|
57
|
+
AND scope_type = ? AND COALESCE(scope_id, '') = COALESCE(?, '')`).get(principalId, candidate.subject.type, candidate.subject.id.trim(), candidate.predicate.trim(), candidate.scope.type, scopeId);
|
|
58
|
+
if (existing) {
|
|
59
|
+
if (existing.cardinality !== candidate.cardinality) throw new Error(`Assertion slot cardinality mismatch for ${candidate.predicate}.`);
|
|
60
|
+
return slotFromRow(existing);
|
|
61
|
+
}
|
|
62
|
+
const id = randomUUID();
|
|
63
|
+
db.prepare(`INSERT INTO user_assertion_slots (
|
|
64
|
+
slot_id, principal_id, subject_type, subject_id, predicate, cardinality,
|
|
65
|
+
scope_type, scope_id, created_at
|
|
66
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, principalId, candidate.subject.type, candidate.subject.id.trim(), candidate.predicate.trim(), candidate.cardinality, candidate.scope.type, scopeId, now);
|
|
67
|
+
return slotFromRow(db.prepare("SELECT * FROM user_assertion_slots WHERE slot_id = ?").get(id));
|
|
68
|
+
}
|
|
69
|
+
function intervalsOverlap(left, candidate) {
|
|
70
|
+
const leftStart = left.validFrom ?? Number.NEGATIVE_INFINITY;
|
|
71
|
+
const leftEnd = left.validTo ?? Number.POSITIVE_INFINITY;
|
|
72
|
+
const rightStart = candidate.validFrom ?? Number.NEGATIVE_INFINITY;
|
|
73
|
+
return leftStart <= (candidate.validTo ?? Number.POSITIVE_INFINITY) && rightStart <= leftEnd;
|
|
74
|
+
}
|
|
75
|
+
function listReconcilableAssertions(db, slotId) {
|
|
76
|
+
return db.prepare(`SELECT * FROM user_assertions WHERE slot_id = ?
|
|
77
|
+
AND status NOT IN ('rejected', 'archived') ORDER BY recorded_at DESC`).all(slotId).map(assertionFromRow);
|
|
78
|
+
}
|
|
79
|
+
function sortByAuthorityAndRecorded(assertions) {
|
|
80
|
+
return assertions.sort((left, right) => authorityRank(right.authority) - authorityRank(left.authority) || right.recordedAt - left.recordedAt);
|
|
81
|
+
}
|
|
82
|
+
function initialStatus(candidate) {
|
|
83
|
+
if (requiresBoundedValidity(candidate.kind, candidate.volatility) && candidate.validTo === void 0) return "needs_review";
|
|
84
|
+
return candidate.authority === "user_explicit" ? "active" : "candidate";
|
|
85
|
+
}
|
|
86
|
+
function insertAssertion(db, slotId, candidate, status, now, supersedesAssertionId) {
|
|
87
|
+
const id = randomUUID();
|
|
88
|
+
const reviewAt = candidate.reviewAt ?? defaultReviewAt(candidate.volatility, candidate.observedAt) ?? null;
|
|
89
|
+
db.prepare(`INSERT INTO user_assertions (
|
|
90
|
+
assertion_id, slot_id, kind, value_json, normalized_value, statement, authority, status,
|
|
91
|
+
confidence, declared_importance, inferred_importance, consequence, actionability,
|
|
92
|
+
volatility, sensitivity, disclosure_policy, applicability_json, valid_from, valid_to,
|
|
93
|
+
observed_at, recorded_at, review_at, supersedes_assertion_id, created_by, created_at
|
|
94
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, slotId, candidate.kind, JSON.stringify(candidate.value), candidate.normalizedValue.trim(), candidate.statement.trim(), candidate.authority, status, candidate.confidence, candidate.declaredImportance ?? null, candidate.inferredImportance, candidate.consequence, candidate.actionability, candidate.volatility, candidate.sensitivity, candidate.disclosurePolicy, JSON.stringify(candidate.applicability ?? {}), candidate.validFrom ?? null, candidate.validTo ?? null, candidate.observedAt, now, reviewAt, supersedesAssertionId ?? null, candidate.createdBy, now);
|
|
95
|
+
db.prepare(`INSERT INTO user_assertions_fts(statement, assertion_id, slot_id) VALUES (?, ?, ?)`).run(candidate.statement.trim(), id, slotId);
|
|
96
|
+
recordStatusEvent(db, id, null, status, candidate.createdBy === "connector" ? "runtime" : candidate.createdBy, "Assertion admitted.", now);
|
|
97
|
+
if (candidate.evidenceId) db.prepare(`INSERT INTO user_assertion_evidence (
|
|
98
|
+
assertion_id, evidence_id, relation, confidence, created_at
|
|
99
|
+
) VALUES (?, ?, 'supports', ?, ?)
|
|
100
|
+
ON CONFLICT(assertion_id, evidence_id, relation) DO UPDATE SET confidence = excluded.confidence`).run(id, candidate.evidenceId, candidate.evidenceConfidence ?? candidate.confidence, now);
|
|
101
|
+
return assertionFromRow(db.prepare("SELECT * FROM user_assertions WHERE assertion_id = ?").get(id));
|
|
102
|
+
}
|
|
103
|
+
function recordStatusEvent(db, assertionId, fromStatus, toStatus, actor, reason, now) {
|
|
104
|
+
db.prepare(`INSERT INTO user_assertion_status_events (
|
|
105
|
+
event_id, assertion_id, from_status, to_status, actor_type, reason, created_at
|
|
106
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(randomUUID(), assertionId, fromStatus, toStatus, actor, reason, now);
|
|
107
|
+
}
|
|
108
|
+
function attachEvidence(db, assertionId, candidate, now) {
|
|
109
|
+
if (!candidate.evidenceId) return;
|
|
110
|
+
db.prepare(`INSERT INTO user_assertion_evidence (
|
|
111
|
+
assertion_id, evidence_id, relation, confidence, created_at
|
|
112
|
+
) VALUES (?, ?, 'supports', ?, ?)
|
|
113
|
+
ON CONFLICT(assertion_id, evidence_id, relation) DO UPDATE SET confidence = excluded.confidence`).run(assertionId, candidate.evidenceId, candidate.evidenceConfidence ?? candidate.confidence, now);
|
|
114
|
+
}
|
|
115
|
+
function closeValidity(db, assertion, boundary, now) {
|
|
116
|
+
if (assertion.validFrom !== void 0 && boundary <= assertion.validFrom) {
|
|
117
|
+
updateStatus(db, assertion, "archived", "Superseded before its validity began.", now);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const end = boundary - 1;
|
|
121
|
+
db.prepare(`UPDATE user_assertions SET valid_to = ?
|
|
122
|
+
WHERE assertion_id = ? AND (valid_to IS NULL OR valid_to >= ?)`).run(end, assertion.id, boundary);
|
|
123
|
+
}
|
|
124
|
+
function updateStatus(db, assertion, status, reason, now) {
|
|
125
|
+
if (assertion.status === status) return;
|
|
126
|
+
db.prepare("UPDATE user_assertions SET status = ? WHERE assertion_id = ?").run(status, assertion.id);
|
|
127
|
+
recordStatusEvent(db, assertion.id, assertion.status, status, "runtime", reason, now);
|
|
128
|
+
}
|
|
129
|
+
function authorityRank(authority) {
|
|
130
|
+
return {
|
|
131
|
+
external_untrusted: 0,
|
|
132
|
+
system_inferred: 1,
|
|
133
|
+
user_observed: 2,
|
|
134
|
+
user_explicit: 3
|
|
135
|
+
}[authority];
|
|
136
|
+
}
|
|
137
|
+
function reconcileAssertion(candidate, now = Date.now()) {
|
|
138
|
+
validateCandidate(candidate);
|
|
139
|
+
return runSqliteWriteTransaction((db) => {
|
|
140
|
+
const slot = findOrCreateSlot(db, candidate, now);
|
|
141
|
+
const existing = listReconcilableAssertions(db, slot.id);
|
|
142
|
+
if (candidate.correctionOfAssertionId) {
|
|
143
|
+
if (candidate.authority !== "user_explicit") throw new Error("Only an explicit user assertion can correct an existing assertion.");
|
|
144
|
+
const target = existing.find((item) => item.id === candidate.correctionOfAssertionId);
|
|
145
|
+
if (!target) throw new Error("Correction target does not belong to the resolved assertion slot.");
|
|
146
|
+
if (target.normalizedValue === candidate.normalizedValue.trim()) {
|
|
147
|
+
attachEvidence(db, target.id, candidate, now);
|
|
148
|
+
return {
|
|
149
|
+
action: "deduplicated",
|
|
150
|
+
assertion: target
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const assertion = insertAssertion(db, slot.id, candidate, "active", now, target.id);
|
|
154
|
+
closeValidity(db, target, candidate.validFrom ?? candidate.observedAt, now);
|
|
155
|
+
return {
|
|
156
|
+
action: "superseded",
|
|
157
|
+
assertion,
|
|
158
|
+
previousAssertion: getUserAssertion(target.id)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const overlapping = sortByAuthorityAndRecorded(existing.filter((item) => intervalsOverlap(item, candidate)));
|
|
162
|
+
const duplicate = overlapping.find((item) => item.normalizedValue === candidate.normalizedValue.trim());
|
|
163
|
+
if (duplicate) {
|
|
164
|
+
attachEvidence(db, duplicate.id, candidate, now);
|
|
165
|
+
return {
|
|
166
|
+
action: "deduplicated",
|
|
167
|
+
assertion: duplicate
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const status = initialStatus(candidate);
|
|
171
|
+
if (slot.cardinality === "multiple" || !overlapping.length) return {
|
|
172
|
+
action: "created",
|
|
173
|
+
assertion: insertAssertion(db, slot.id, candidate, status, now)
|
|
174
|
+
};
|
|
175
|
+
const current = overlapping[0];
|
|
176
|
+
if (candidate.authority === "user_explicit" && authorityRank(candidate.authority) > authorityRank(current.authority)) {
|
|
177
|
+
const assertion = insertAssertion(db, slot.id, candidate, status, now, current.id);
|
|
178
|
+
closeValidity(db, current, candidate.validFrom ?? candidate.observedAt, now);
|
|
179
|
+
return {
|
|
180
|
+
action: "superseded",
|
|
181
|
+
assertion,
|
|
182
|
+
previousAssertion: getUserAssertion(current.id)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const assertion = insertAssertion(db, slot.id, candidate, candidate.authority === "user_explicit" ? "needs_review" : "conflicted", now);
|
|
186
|
+
if (current.authority !== "user_explicit" && candidate.authority !== "user_explicit") updateStatus(db, current, "conflicted", "Overlapping assertion has a different value.", now);
|
|
187
|
+
return {
|
|
188
|
+
action: "conflicted",
|
|
189
|
+
assertion,
|
|
190
|
+
previousAssertion: getUserAssertion(current.id)
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function getUserAssertion(id) {
|
|
195
|
+
const row = getSqliteDatabase().prepare("SELECT * FROM user_assertions WHERE assertion_id = ?").get(id);
|
|
196
|
+
return row ? assertionFromRow(row) : void 0;
|
|
197
|
+
}
|
|
198
|
+
function getAssertionSlot(id) {
|
|
199
|
+
const row = getSqliteDatabase().prepare("SELECT * FROM user_assertion_slots WHERE slot_id = ?").get(id);
|
|
200
|
+
return row ? slotFromRow(row) : void 0;
|
|
201
|
+
}
|
|
202
|
+
function listSlotAssertions(slotId) {
|
|
203
|
+
return getSqliteDatabase().prepare(`SELECT * FROM user_assertions
|
|
204
|
+
WHERE slot_id = ? ORDER BY recorded_at DESC`).all(slotId).map(assertionFromRow);
|
|
205
|
+
}
|
|
206
|
+
function listUserAssertions(input = {}) {
|
|
207
|
+
const principalId = input.principalId ?? "local-owner";
|
|
208
|
+
const statuses = input.statuses ?? [
|
|
209
|
+
"active",
|
|
210
|
+
"candidate",
|
|
211
|
+
"needs_review",
|
|
212
|
+
"conflicted"
|
|
213
|
+
];
|
|
214
|
+
if (!statuses.length) return [];
|
|
215
|
+
const placeholders = statuses.map(() => "?").join(", ");
|
|
216
|
+
const limit = Math.max(1, Math.min(2e3, input.limit ?? 200));
|
|
217
|
+
return getSqliteDatabase().prepare(`SELECT a.* FROM user_assertions a
|
|
218
|
+
JOIN user_assertion_slots s ON s.slot_id = a.slot_id
|
|
219
|
+
WHERE s.principal_id = ? AND a.status IN (${placeholders})
|
|
220
|
+
ORDER BY a.recorded_at DESC LIMIT ?`).all(principalId, ...statuses, limit).map(assertionFromRow);
|
|
221
|
+
}
|
|
222
|
+
function getActiveAssertionByPredicate(predicate) {
|
|
223
|
+
const row = getSqliteDatabase().prepare(`SELECT a.* FROM user_assertions a
|
|
224
|
+
JOIN user_assertion_slots s ON s.slot_id = a.slot_id
|
|
225
|
+
WHERE s.principal_id = ? AND s.predicate = ? AND a.status = 'active'
|
|
226
|
+
AND (a.valid_from IS NULL OR a.valid_from <= ?)
|
|
227
|
+
AND (a.valid_to IS NULL OR a.valid_to >= ?)
|
|
228
|
+
ORDER BY CASE a.authority WHEN 'user_explicit' THEN 0 WHEN 'user_observed' THEN 1
|
|
229
|
+
WHEN 'system_inferred' THEN 2 ELSE 3 END, a.recorded_at DESC LIMIT 1`).get(USER_MODEL_PRINCIPAL_ID, predicate, Date.now(), Date.now());
|
|
230
|
+
return row ? assertionFromRow(row) : void 0;
|
|
231
|
+
}
|
|
232
|
+
function getActiveAssertionForSlot(input) {
|
|
233
|
+
validateScope(input.scope);
|
|
234
|
+
const row = getSqliteDatabase().prepare(`SELECT a.* FROM user_assertions a
|
|
235
|
+
JOIN user_assertion_slots s ON s.slot_id = a.slot_id
|
|
236
|
+
WHERE s.principal_id = ? AND s.subject_type = ? AND s.subject_id = ?
|
|
237
|
+
AND s.predicate = ? AND s.scope_type = ?
|
|
238
|
+
AND COALESCE(s.scope_id, '') = COALESCE(?, '') AND a.status = 'active'
|
|
239
|
+
AND (a.valid_from IS NULL OR a.valid_from <= ?)
|
|
240
|
+
AND (a.valid_to IS NULL OR a.valid_to >= ?)
|
|
241
|
+
ORDER BY CASE a.authority WHEN 'user_explicit' THEN 0 WHEN 'user_observed' THEN 1
|
|
242
|
+
WHEN 'system_inferred' THEN 2 ELSE 3 END, a.recorded_at DESC LIMIT 1`).get(USER_MODEL_PRINCIPAL_ID, input.subject.type, input.subject.id.trim(), input.predicate.trim(), input.scope.type, input.scope.id?.trim() ?? null, Date.now(), Date.now());
|
|
243
|
+
return row ? assertionFromRow(row) : void 0;
|
|
244
|
+
}
|
|
245
|
+
function getUserTimezone() {
|
|
246
|
+
const value = getActiveAssertionByPredicate("preference.timezone")?.value;
|
|
247
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
248
|
+
}
|
|
249
|
+
function linkAssertionEvidence(assertionId, evidenceId, relation, confidence, now = Date.now()) {
|
|
250
|
+
if (!Number.isFinite(confidence) || confidence < 0 || confidence > 1) throw new Error("Evidence confidence must be between 0 and 1.");
|
|
251
|
+
getSqliteDatabase().prepare(`INSERT INTO user_assertion_evidence (
|
|
252
|
+
assertion_id, evidence_id, relation, confidence, created_at
|
|
253
|
+
) VALUES (?, ?, ?, ?, ?)
|
|
254
|
+
ON CONFLICT(assertion_id, evidence_id, relation) DO UPDATE SET confidence = excluded.confidence`).run(assertionId, evidenceId, relation, confidence, now);
|
|
255
|
+
}
|
|
256
|
+
function setAssertionStatus(assertionId, status, input) {
|
|
257
|
+
const current = getUserAssertion(assertionId);
|
|
258
|
+
if (!current) throw new Error(`User assertion not found: ${assertionId}`);
|
|
259
|
+
if (current.status === status) return current;
|
|
260
|
+
const now = input.now ?? Date.now();
|
|
261
|
+
runSqliteWriteTransaction((db) => {
|
|
262
|
+
db.prepare("UPDATE user_assertions SET status = ? WHERE assertion_id = ?").run(status, assertionId);
|
|
263
|
+
recordStatusEvent(db, assertionId, current.status, status, input.actor, input.reason, now);
|
|
264
|
+
});
|
|
265
|
+
return getUserAssertion(assertionId);
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export { getActiveAssertionByPredicate, getActiveAssertionForSlot, getAssertionSlot, getUserAssertion, getUserTimezone, linkAssertionEvidence, listSlotAssertions, listUserAssertions, reconcileAssertion, setAssertionStatus };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AssertionKind, AssertionVolatility, UserAssertion } from './domain.js';
|
|
2
|
+
export declare function defaultReviewAt(volatility: AssertionVolatility, observedAt: number): number | undefined;
|
|
3
|
+
export declare function requiresBoundedValidity(kind: AssertionKind, volatility: AssertionVolatility): boolean;
|
|
4
|
+
export declare function isAssertionValidAt(assertion: UserAssertion, asOf: number): boolean;
|
|
5
|
+
export interface CurrentAssertionResolution {
|
|
6
|
+
assertion?: UserAssertion;
|
|
7
|
+
conflict: boolean;
|
|
8
|
+
contenders: UserAssertion[];
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveCurrentAssertion(assertions: UserAssertion[], asOf?: number): CurrentAssertionResolution;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/user-model/temporal.ts
|
|
2
|
+
const REVIEW_INTERVAL_MS = {
|
|
3
|
+
stable: void 0,
|
|
4
|
+
slow: 4320 * 60 * 60 * 1e3,
|
|
5
|
+
dynamic: 720 * 60 * 60 * 1e3,
|
|
6
|
+
event: 10080 * 60 * 1e3
|
|
7
|
+
};
|
|
8
|
+
function defaultReviewAt(volatility, observedAt) {
|
|
9
|
+
const interval = REVIEW_INTERVAL_MS[volatility];
|
|
10
|
+
return interval === void 0 ? void 0 : observedAt + interval;
|
|
11
|
+
}
|
|
12
|
+
function requiresBoundedValidity(kind, volatility) {
|
|
13
|
+
return kind === "current_state" || volatility === "event";
|
|
14
|
+
}
|
|
15
|
+
function isAssertionValidAt(assertion, asOf) {
|
|
16
|
+
return assertion.status === "active" && (assertion.validFrom === void 0 || assertion.validFrom <= asOf) && (assertion.validTo === void 0 || assertion.validTo >= asOf);
|
|
17
|
+
}
|
|
18
|
+
const AUTHORITY_RANK = {
|
|
19
|
+
external_untrusted: 0,
|
|
20
|
+
system_inferred: 1,
|
|
21
|
+
user_observed: 2,
|
|
22
|
+
user_explicit: 3
|
|
23
|
+
};
|
|
24
|
+
function resolveCurrentAssertion(assertions, asOf = Date.now()) {
|
|
25
|
+
const contenders = assertions.filter((item) => isAssertionValidAt(item, asOf));
|
|
26
|
+
if (!contenders.length) return {
|
|
27
|
+
conflict: false,
|
|
28
|
+
contenders: []
|
|
29
|
+
};
|
|
30
|
+
contenders.sort((left, right) => AUTHORITY_RANK[right.authority] - AUTHORITY_RANK[left.authority] || right.recordedAt - left.recordedAt);
|
|
31
|
+
const best = contenders[0];
|
|
32
|
+
if (contenders.filter((item) => AUTHORITY_RANK[item.authority] === AUTHORITY_RANK[best.authority] && item.normalizedValue !== best.normalizedValue).length) return {
|
|
33
|
+
assertion: void 0,
|
|
34
|
+
conflict: true,
|
|
35
|
+
contenders
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
assertion: best,
|
|
39
|
+
conflict: false,
|
|
40
|
+
contenders
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { defaultReviewAt, isAssertionValidAt, requiresBoundedValidity, resolveCurrentAssertion };
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { AgentMessage } from '@earendil-works/pi-agent-core';
|
|
2
2
|
import type { Config } from '../../config/schema.js';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export interface VoiceMemorySnapshot {
|
|
4
|
+
block: string;
|
|
5
|
+
references: Array<{
|
|
6
|
+
kind: 'assertion' | 'knowledge';
|
|
7
|
+
id: string;
|
|
8
|
+
updatedAt: number;
|
|
9
|
+
}>;
|
|
5
10
|
isCurrent: () => boolean;
|
|
6
11
|
subscribe: (invalidate: () => void) => () => void;
|
|
7
12
|
}
|