@xopcai/xopc 0.0.188 → 0.0.190
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/README.md +1 -4
- package/README.zh-CN.md +0 -3
- 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--QoUGhiS.js → activity-store-DstnJCS5.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-B0yweLNQ.js → agent-avatar-dicebear-9vAbkroX.js} +1 -1
- package/dist/gateway/static/root/assets/agents-D1t4SfMQ.js +68 -0
- package/dist/gateway/static/root/assets/{api-5laWqfiE.js → api-BTL9kayv.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-BXJ8Jiv_.js → app-management-settings-panel-DkFeIdBf.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DG9n9D1M.js → appearance-settings-Bxs8Fpaj.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-Cgrgu5OW.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-Ceh5qrZf.js → archive-plugin-Ch2RmLCC.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-jFW7uYf7.js → attachment-load-BhMQM_Ky.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-CtJxstKh.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-XDlkI1r4.js → binary-plugins-D6CqlymH.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-kyKc2IhE.js → block-editor-ClL6HEg9.js} +56 -56
- package/dist/gateway/static/root/assets/browser-settings-page-DW99iDmD.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-BJa5Iz_v.js → browser-workflow-inputs-BYy48VhN.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CTQQOsn5.js → browser-workflows-page-zgLibuMH.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-CHUrT9EB.js +7 -0
- package/dist/gateway/static/root/assets/capability-presets-api-BB8t4Ja7.js +1 -0
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-Cycrv0YV.js +1 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-BgIkWq01.js → channel-recipient-api-BThDGiO3.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-V96gPUAU.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-Cz7SAAkm.js +1 -0
- package/dist/gateway/static/root/assets/connectors-api-DS9ED-EL.js +1 -0
- package/dist/gateway/static/root/assets/connectors-page-BhlyQoQI.js +2 -0
- package/dist/gateway/static/root/assets/cron-expression-CkgsvhtW.js +2 -0
- package/dist/gateway/static/root/assets/{desktop-pet-CSwd00CV.js → desktop-pet-Cv8rGhYW.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-CuNQvHGu.js → desktop-pet-settings-CIeJdwfV.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-ct0n5Rje.js → directory-picker-path-field-D8jXEiAY.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-BeRBuMUU.js → extension-debug-page-CCZ9u6TZ.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DbK-Cwao.js → extension-page-CV36ILRG.js} +1 -1
- package/dist/gateway/static/root/assets/extension-settings-page-IyQrSILY.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-CC7EvEFp.js → gateway-config-api-D4_r5iJM.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-CYlntpBH.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-B2DmdlwO.js → gateway-startup-retry-EO9mKvzE.js} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-D4SyWob8.js +1 -0
- package/dist/gateway/static/root/assets/home-page-B2Kagoh8.js +3 -0
- package/dist/gateway/static/root/assets/{image-generation-api-GMTaS6eI.js → image-generation-api-Bu7PyVSh.js} +1 -1
- package/dist/gateway/static/root/assets/index-CYT5DOzr.js +150 -0
- package/dist/gateway/static/root/assets/index-D6e3tPL-.css +1 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-DhGYddbI.js → keyboard-shortcuts-settings-BMhCuVBZ.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-BHYbFjqy.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-CmnrBmWi.js → local-apps-page-ijIe7_y2.js} +1 -1
- package/dist/gateway/static/root/assets/locale-store-deR2zRaE.js +1 -0
- package/dist/gateway/static/root/assets/logs-page-IIn8Tess.js +2 -0
- package/dist/gateway/static/root/assets/management-settings--V_fovKD.js +1 -0
- package/dist/gateway/static/root/assets/{markdown-split-CZaBPOVn.js → markdown-split-Dt9-in6W.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-CiKvSgCv.js → media-plugins-B3pj_iO0.js} +1 -1
- package/dist/gateway/static/root/assets/messages-B4XqB8I6.js +3 -0
- package/dist/gateway/static/root/assets/{notes-page-Bisbzqlz.js → notes-page-DZ366lIT.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-S2sBVOLw.js +4 -0
- package/dist/gateway/static/root/assets/{page-tabs-BxlwhAbH.js → page-tabs-C5ge434C.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-RM8wXxfT.js → preview-open-alternatives-BFa9DgSV.js} +1 -1
- package/dist/gateway/static/root/assets/product-delivery-tRr-7IxY.js +1 -0
- package/dist/gateway/static/root/assets/{product-open-page-DdBlibek.js → product-open-page-Dc9CcWdu.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-BilzoCJ7.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-BoQUyacP.js +1 -0
- package/dist/gateway/static/root/assets/remote-access-hub-DUyUaCRF.js +1 -0
- package/dist/gateway/static/root/assets/{schema-form-BDKbpmXv.js → schema-form-B84DckWe.js} +1 -1
- package/dist/gateway/static/root/assets/{schemas-C6onAggk.js → schemas-zIBW3wiV.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-Dzxlq1F0.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-TzwlZxU6.js +1 -0
- package/dist/gateway/static/root/assets/settings-form-section-Dp9itvdy.js +1 -0
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-DgIp8_S6.js → settings-loading-skeleton-CCtlhoy7.js} +1 -1
- package/dist/gateway/static/root/assets/settings-page-DQmMKf8r.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-layout-97LmwrzC.js → settings-page-layout-EQIOJa_L.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-Cwi-SPja.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-BH7i3g1S.js → share-preview-page-C4_B2jvf.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-CkyuGlZK.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-BJCePQK5.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-BYWLfmJi.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page.utils-s-a5WV9j.js → skills-page.utils-Jhm24i4h.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-BxjeMT5k.js → system-settings-panel-Dpx2ags2.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-BahycnfW.js → task-detail-page-DLAdxI6e.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-BRxdsmic.js → theme-store-DnBOcGXi.js} +1 -1
- package/dist/gateway/static/root/assets/{typed-models-lib-39MjwPSq.js → typed-models-lib-DULmTHUB.js} +1 -1
- package/dist/gateway/static/root/assets/use-autosave-BrjVk5VH.js +1 -0
- package/dist/gateway/static/root/assets/user-context-page-9AAFpGAL.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-XU-7sBSg.js → voice-api-key-field-BISTPfq_.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-CJqu8UHq.js → work-discovery-overlay-Wr-uF7VA.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-page-BWds95sL.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DXtg8Qxl.js → workflow-run-setup-panel-DHqHP8_6.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-0b4_DFHr.js +11 -0
- package/dist/gateway/static/root/index.html +9 -9
- package/dist/package.js +1 -1
- package/dist/packages/endpoint-tools-protocol/src/index.js +184 -0
- package/dist/packages/gateway-contract/src/tool-activity.js +0 -36
- package/dist/packages/realtime-client/src/index.js +256 -0
- package/dist/packages/realtime-protocol/src/index.js +88 -0
- package/dist/src/agent/agent-manager.d.ts +1 -1
- package/dist/src/agent/agent-manager.js +7 -13
- package/dist/src/agent/background-review/coordinator.js +1 -1
- package/dist/src/agent/background-review/prompts.d.ts +1 -1
- package/dist/src/agent/background-review/prompts.js +3 -1
- package/dist/src/agent/background-review/run-background-review.d.ts +2 -0
- package/dist/src/agent/background-review/run-background-review.js +10 -9
- package/dist/src/agent/bootstrap/bootstrap-cache.d.ts +0 -1
- package/dist/src/agent/bootstrap/bootstrap-cache.js +3 -4
- package/dist/src/agent/bootstrap/bootstrap-files.d.ts +0 -4
- package/dist/src/agent/bootstrap/bootstrap-files.js +3 -4
- package/dist/src/agent/bootstrap/filter-bootstrap-files.js +1 -4
- package/dist/src/agent/bootstrap/load-bootstrap-files.d.ts +0 -1
- package/dist/src/agent/bootstrap/load-bootstrap-files.js +1 -14
- package/dist/src/agent/bootstrap/types.d.ts +1 -1
- package/dist/src/agent/client-error-format.d.ts +1 -1
- package/dist/src/agent/client-error-format.js +1 -1
- package/dist/src/agent/context/workspace-templates/SOUL.md +1 -1
- package/dist/src/agent/external-tools/endpoint-provider.d.ts +17 -0
- package/dist/src/agent/external-tools/endpoint-provider.js +93 -0
- package/dist/src/agent/external-tools/gateway-tools.js +1 -1
- package/dist/src/agent/external-tools/index.d.ts +4 -5
- package/dist/src/agent/external-tools/index.js +8 -2
- package/dist/src/agent/external-tools/types.d.ts +8 -1
- package/dist/src/agent/external-tools/types.js +2 -1
- package/dist/src/agent/inbound/inbound-loop.js +4 -0
- package/dist/src/agent/inbound/turn-dispatcher.d.ts +9 -8
- package/dist/src/agent/inbound/turn-dispatcher.js +13 -11
- package/dist/src/agent/memory/builtin-provider.d.ts +2 -4
- package/dist/src/agent/memory/builtin-provider.js +35 -15
- package/dist/src/agent/memory/context/types.d.ts +3 -1
- package/dist/src/agent/memory/create-memory-manager.js +2 -0
- package/dist/src/agent/memory/index.d.ts +1 -1
- package/dist/src/agent/memory/index.js +1 -1
- package/dist/src/agent/memory/manager.d.ts +9 -1
- package/dist/src/agent/memory/manager.js +39 -9
- package/dist/src/agent/memory/memory-config.d.ts +1 -1
- package/dist/src/agent/memory/memory-config.js +1 -1
- package/dist/src/agent/memory/source-origin.js +0 -2
- package/dist/src/agent/memory/types.d.ts +5 -1
- package/dist/src/agent/memory/understanding/service.d.ts +10 -10
- package/dist/src/agent/memory/understanding/service.js +108 -176
- package/dist/src/agent/memory/understanding/types.d.ts +7 -8
- package/dist/src/agent/memory/user-context-coordinator.d.ts +2 -1
- package/dist/src/agent/memory/user-context-coordinator.js +27 -41
- package/dist/src/agent/messaging/command-handler.d.ts +2 -2
- package/dist/src/agent/messaging/command-handler.js +3 -3
- package/dist/src/agent/orchestration/agent-orchestrator.js +4 -7
- package/dist/src/agent/prompt/sections/memory-skills.js +4 -4
- package/dist/src/agent/prompt/sections/tooling.js +0 -10
- package/dist/src/agent/prompt/service-prompt-builder.d.ts +0 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +4 -33
- package/dist/src/agent/prompt/system-prompt.js +1 -2
- package/dist/src/agent/service/async-queue.d.ts +1 -1
- package/dist/src/agent/service/async-queue.js +1 -1
- package/dist/src/agent/service/direct-turn-helpers.d.ts +1 -1
- package/dist/src/agent/service/direct-turn-helpers.js +2 -2
- package/dist/src/agent/service/process-direct-one-shot.d.ts +3 -1
- package/dist/src/agent/service/process-direct-one-shot.js +1 -1
- package/dist/src/agent/service/process-direct-streaming.d.ts +7 -5
- package/dist/src/agent/service/process-direct-streaming.js +5 -5
- package/dist/src/agent/service.d.ts +2 -3
- package/dist/src/agent/service.js +10 -21
- package/dist/src/agent/service.types.d.ts +2 -0
- package/dist/src/agent/session/index.d.ts +1 -1
- package/dist/src/agent/session/session-context.d.ts +2 -0
- package/dist/src/agent/session/session-context.js +4 -0
- package/dist/src/agent/session/session-state-bag.d.ts +4 -4
- package/dist/src/agent/session/session-state-bag.js +1 -1
- package/dist/src/agent/skills/marketplace/adapters/clawhub/adapter.js +1 -1
- package/dist/src/agent/streaming/reasoning-visibility.d.ts +6 -0
- package/dist/src/agent/streaming/{reasoning-visibility-sse.js → reasoning-visibility.js} +3 -6
- package/dist/src/agent/tools/dreaming-tool.d.ts +0 -2
- package/dist/src/agent/tools/dreaming-tool.js +13 -38
- package/dist/src/agent/tools/factory.d.ts +4 -3
- package/dist/src/agent/tools/factory.js +2 -10
- package/dist/src/agent/tools/index.d.ts +0 -1
- package/dist/src/agent/tools/index.js +1 -2
- package/dist/src/agent/tools/memory-tool.js +1 -1
- package/dist/src/agent/workspace-runtime/registry.d.ts +3 -5
- package/dist/src/agent/workspace-runtime/registry.js +2 -15
- package/dist/src/agent-manifest/schema.d.ts +17 -17
- package/dist/src/agent-runtime/index.js +1 -1
- package/dist/src/agent-runtime/memory-runtime.d.ts +2 -2
- package/dist/src/agent-runtime/runtime-profile.js +1 -1
- package/dist/src/automations/domain/types.d.ts +2 -1
- package/dist/src/automations/domain/validation.d.ts +29 -29
- package/dist/src/automations/draft/automation-draft-validator.d.ts +3 -3
- package/dist/src/automations/service/action-executor.js +4 -1
- package/dist/src/channels/pairing/pairing-challenge.d.ts +1 -1
- package/dist/src/channels/pairing/pairing-challenge.js +1 -1
- package/dist/src/chat-commands/builtins/understanding.js +2 -5
- package/dist/src/cli/commands/agent/stream-renderer.js +4 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/init.js +3 -22
- package/dist/src/cli/templates.js +1 -1
- package/dist/src/config/index.js +3 -3
- package/dist/src/config/paths.d.ts +0 -5
- package/dist/src/config/paths.js +2 -11
- package/dist/src/config/rules.js +0 -5
- package/dist/src/config/schema.d.ts +27 -122
- package/dist/src/config/schema.js +9 -42
- package/dist/src/config/web-patch.js +0 -1
- package/dist/src/connectors/learning-coordinator.js +75 -3
- package/dist/src/endpoint-tools/auth.d.ts +20 -0
- package/dist/src/endpoint-tools/auth.js +51 -0
- package/dist/src/endpoint-tools/index.d.ts +5 -0
- package/dist/src/endpoint-tools/index.js +6 -0
- package/dist/src/endpoint-tools/invocation-service.d.ts +68 -0
- package/dist/src/endpoint-tools/invocation-service.js +190 -0
- package/dist/src/endpoint-tools/policy.d.ts +10 -0
- package/dist/src/endpoint-tools/policy.js +18 -0
- package/dist/src/endpoint-tools/registry.d.ts +45 -0
- package/dist/src/endpoint-tools/registry.js +121 -0
- package/dist/src/endpoint-tools/runtime.d.ts +23 -0
- package/dist/src/endpoint-tools/runtime.js +86 -0
- package/dist/src/endpoint-tools/upload-service.d.ts +41 -0
- package/dist/src/endpoint-tools/upload-service.js +103 -0
- package/dist/src/extensions/types/hooks.d.ts +1 -1
- package/dist/src/extensions/update.js +1 -1
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/agent-builtin-tools.js +0 -5
- package/dist/src/gateway/agents-admin.d.ts +0 -7
- package/dist/src/gateway/agents-admin.js +3 -32
- package/dist/src/gateway/chat-stream/protocol.d.ts +0 -1
- package/dist/src/gateway/clarify-bridge.d.ts +5 -4
- package/dist/src/gateway/clarify-bridge.js +3 -4
- package/dist/src/gateway/dreaming-automation-reconciler.d.ts +3 -3
- package/dist/src/gateway/dreaming-automation-reconciler.js +48 -88
- package/dist/src/gateway/heartbeat/service.js +4 -1
- package/dist/src/gateway/hono/app.js +1 -5
- package/dist/src/gateway/hono/index.d.ts +0 -1
- package/dist/src/gateway/hono/index.js +1 -2
- package/dist/src/gateway/hono/lib/config-payload.d.ts +20 -9
- package/dist/src/gateway/hono/lib/config-payload.js +3 -2
- package/dist/src/gateway/hono/middleware/auth.js +3 -5
- package/dist/src/gateway/hono/oauth-async.d.ts +1 -0
- package/dist/src/gateway/hono/oauth-async.js +17 -2
- package/dist/src/gateway/hono/routes/agent-stream.js +49 -6
- package/dist/src/gateway/hono/routes/agents.js +1 -33
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/gateway.d.ts +2 -2
- package/dist/src/gateway/hono/routes/config-patch/gateway.js +0 -19
- package/dist/src/gateway/hono/routes/config-patch/misc.js +17 -1
- package/dist/src/gateway/hono/routes/connectors.js +13 -12
- package/dist/src/gateway/hono/routes/deps.d.ts +0 -2
- package/dist/src/gateway/hono/routes/endpoint-tools.d.ts +3 -0
- package/dist/src/gateway/hono/routes/endpoint-tools.js +196 -0
- package/dist/src/gateway/hono/routes/index.js +6 -2
- package/dist/src/gateway/hono/routes/lazy-bundles.js +1 -5
- package/dist/src/gateway/hono/routes/logs.js +0 -4
- package/dist/src/gateway/hono/routes/public-gateway.js +2 -2
- package/dist/src/gateway/hono/routes/realtime.d.ts +3 -0
- package/dist/src/gateway/hono/routes/realtime.js +35 -0
- package/dist/src/gateway/hono/routes/status.js +0 -7
- package/dist/src/gateway/hono/routes/understanding-sources.d.ts +3 -0
- package/dist/src/gateway/hono/routes/understanding-sources.js +203 -0
- package/dist/src/gateway/hono/routes/work-discovery.d.ts +2 -0
- package/dist/src/gateway/hono/routes/work-discovery.js +3 -134
- package/dist/src/gateway/hono/routes/workflows.js +1 -1
- package/dist/src/gateway/hono/routes/you.d.ts +0 -31
- package/dist/src/gateway/hono/routes/you.js +230 -1161
- package/dist/src/gateway/index.d.ts +1 -1
- package/dist/src/gateway/index.js +1 -2
- package/dist/src/gateway/protocol.d.ts +1 -7
- package/dist/src/gateway/security/index.js +1 -1
- package/dist/src/gateway/security/operator-scopes.js +1 -1
- package/dist/src/gateway/server.js +4 -4
- package/dist/src/gateway/service/agent-runner.d.ts +11 -9
- package/dist/src/gateway/service/agent-runner.js +18 -18
- package/dist/src/gateway/service/config-coordinator.d.ts +3 -3
- package/dist/src/gateway/service/run-gateway-agent.d.ts +4 -3
- package/dist/src/gateway/service/run-gateway-agent.js +15 -17
- package/dist/src/gateway/service/session-input-coordinator.d.ts +3 -0
- package/dist/src/gateway/service/session-input-coordinator.js +4 -2
- package/dist/src/gateway/service/types.d.ts +0 -5
- package/dist/src/gateway/service.d.ts +7 -6
- package/dist/src/gateway/service.js +43 -26
- package/dist/src/infra/update-runner.js +1 -1
- package/dist/src/knowledge/connected-knowledge-pipeline.js +1 -1
- package/dist/src/knowledge/connected-understanding-pipeline.d.ts +2 -4
- package/dist/src/knowledge/connected-understanding-pipeline.js +31 -81
- package/dist/src/knowledge/index.js +2 -2
- package/dist/src/knowledge/people-graph.d.ts +22 -25
- package/dist/src/knowledge/people-graph.js +76 -43
- package/dist/src/mcp/channel-bridge.d.ts +6 -9
- package/dist/src/mcp/channel-bridge.js +48 -76
- package/dist/src/mcp/channel-server.js +2 -6
- package/dist/src/proactive/execution/context.js +8 -13
- package/dist/src/realtime/broker.d.ts +31 -0
- package/dist/src/realtime/broker.js +114 -0
- package/dist/src/realtime/runtime.d.ts +20 -0
- package/dist/src/realtime/runtime.js +263 -0
- package/dist/src/realtime/tickets.d.ts +15 -0
- package/dist/src/realtime/tickets.js +38 -0
- package/dist/src/realtime/writer.d.ts +15 -0
- package/dist/src/realtime/writer.js +78 -0
- package/dist/src/share/share-config.js +0 -1
- package/dist/src/share/site-share-config.js +0 -1
- package/dist/src/storage/sqlite/connector-account-repository.js +0 -1
- package/dist/src/storage/sqlite/context-consolidation-repository.d.ts +37 -0
- package/dist/src/storage/sqlite/context-consolidation-repository.js +64 -0
- package/dist/src/storage/sqlite/endpoint-principal-repository.d.ts +17 -0
- package/dist/src/storage/sqlite/endpoint-principal-repository.js +54 -0
- package/dist/src/storage/sqlite/endpoint-tool-invocation-repository.d.ts +25 -0
- package/dist/src/storage/sqlite/endpoint-tool-invocation-repository.js +42 -0
- package/dist/src/storage/sqlite/fts.d.ts +2 -0
- package/dist/src/storage/sqlite/fts.js +29 -1
- package/dist/src/storage/sqlite/index.d.ts +6 -6
- package/dist/src/storage/sqlite/index.js +7 -7
- package/dist/src/storage/sqlite/knowledge-repository.d.ts +9 -2
- package/dist/src/storage/sqlite/knowledge-repository.js +58 -10
- package/dist/src/storage/sqlite/memory-records-repository.d.ts +7 -56
- package/dist/src/storage/sqlite/memory-records-repository.js +68 -218
- package/dist/src/storage/sqlite/migrations/109_endpoint_principals.sql +14 -0
- package/dist/src/storage/sqlite/migrations/110_session_input_origin.sql +43 -0
- package/dist/src/storage/sqlite/migrations/111_endpoint_tool_invocations.sql +18 -0
- package/dist/src/storage/sqlite/migrations/112_endpoint_instance_bindings.sql +8 -0
- package/dist/src/storage/sqlite/migrations/113_memory_evidence_single_source.sql +54 -0
- package/dist/src/storage/sqlite/migrations/114_user_context_domain.sql +193 -0
- package/dist/src/storage/sqlite/migrations/115_remove_legacy_user_context.sql +6 -0
- package/dist/src/storage/sqlite/migrations/116_structured_context_consolidation.sql +38 -0
- package/dist/src/storage/sqlite/migrations/117_unified_understanding_sources.sql +110 -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/schema.js +1 -1
- package/dist/src/storage/sqlite/schema.sql +0 -20
- package/dist/src/storage/sqlite/session-input-repository.d.ts +3 -0
- package/dist/src/storage/sqlite/session-input-repository.js +5 -3
- package/dist/src/storage/sqlite/user-context-quality-repository.d.ts +34 -0
- package/dist/src/storage/sqlite/user-context-quality-repository.js +74 -0
- package/dist/src/storage/sqlite/user-context-repository.d.ts +64 -0
- package/dist/src/storage/sqlite/user-context-repository.js +383 -0
- package/dist/src/tasks/home-query-service.d.ts +1 -1
- package/dist/src/tui/backends/embedded-backend.js +5 -2
- package/dist/src/tui/backends/{gateway-sse-backend.d.ts → gateway-realtime-backend.d.ts} +13 -10
- package/dist/src/tui/backends/{gateway-sse-backend.js → gateway-realtime-backend.js} +114 -151
- package/dist/src/tui/tool-summary.js +1 -7
- package/dist/src/tui/tui-agent-events.d.ts +0 -1
- package/dist/src/tui/tui-agent-events.js +2 -15
- package/dist/src/tui/tui-backend.d.ts +4 -4
- package/dist/src/tui/tui-run-state.js +0 -4
- package/dist/src/tui/tui-startup-resources.js +1 -2
- package/dist/src/tui/tui-types.d.ts +2 -9
- package/dist/src/tui/tui-types.js +0 -1
- package/dist/src/tui/tui.js +5 -5
- package/dist/src/tunnel/gateway-lifecycle.d.ts +1 -1
- package/dist/src/tunnel/gateway-lifecycle.js +1 -1
- package/dist/src/user-context/config.d.ts +17 -210
- package/dist/src/user-context/config.js +19 -85
- package/dist/src/user-context/consolidation.d.ts +26 -0
- package/dist/src/user-context/consolidation.js +115 -0
- package/dist/src/user-context/domain.d.ts +75 -0
- package/dist/src/user-context/domain.js +4 -0
- package/dist/src/user-context/manual-understanding.d.ts +7 -14
- package/dist/src/user-context/manual-understanding.js +19 -49
- package/dist/src/{agent/memory/context → user-context}/planner.d.ts +5 -6
- package/dist/src/user-context/planner.js +311 -0
- package/dist/src/user-context/relationship-continuity.d.ts +3 -6
- package/dist/src/user-context/relationship-continuity.js +39 -32
- package/dist/src/user-context/sources/catalog.d.ts +2 -0
- package/dist/src/user-context/sources/catalog.js +149 -0
- package/dist/src/user-context/sources/index.d.ts +3 -0
- package/dist/src/user-context/sources/index.js +3 -0
- package/dist/src/user-context/sources/repository.d.ts +40 -0
- package/dist/src/user-context/sources/repository.js +164 -0
- package/dist/src/user-context/sources/types.d.ts +83 -0
- package/dist/src/user-context/understandingQuality.d.ts +5 -0
- package/dist/src/user-context/understandingQuality.js +44 -0
- package/dist/src/utils/logger/log-stream.d.ts +3 -10
- package/dist/src/utils/logger/log-stream.js +2 -73
- package/dist/src/utils/logger/pino-record.d.ts +1 -1
- package/dist/src/utils/logger/streams.js +1 -1
- package/dist/src/work-discovery/analyzer.d.ts +4 -3
- package/dist/src/work-discovery/analyzer.js +21 -16
- package/dist/src/work-discovery/incremental-repository.js +42 -40
- package/dist/src/work-discovery/index.js +3 -3
- package/dist/src/work-discovery/service.d.ts +7 -7
- package/dist/src/work-discovery/service.js +241 -190
- package/dist/src/work-discovery/source-repository.js +42 -53
- package/dist/src/work-discovery/types.d.ts +2 -14
- package/package.json +5 -7
- package/dist/gateway/static/root/assets/agents-C6OV-gMm.js +0 -2
- package/dist/gateway/static/root/assets/apps-page-Ci14lDeO.js +0 -1
- package/dist/gateway/static/root/assets/automations-page-Q1xmb4Rh.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-DbowrHXD.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DoZPFdKF.js +0 -7
- package/dist/gateway/static/root/assets/capability-presets-api-Dn-7MMEo.js +0 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-Bt8Hnx0h.js +0 -1
- package/dist/gateway/static/root/assets/channels-settings-Bpsebsru.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-DFmdYRE5.js +0 -1
- package/dist/gateway/static/root/assets/connector-logo-TRr9ybf6.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-Tg5kl22i.js +0 -2
- package/dist/gateway/static/root/assets/cron-expression-B3B1eqnr.js +0 -2
- package/dist/gateway/static/root/assets/extension-settings-page-C9ag5tb5.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-9g8uIry9.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-fl1oC_-5.js +0 -1
- package/dist/gateway/static/root/assets/home-page-Bao9jq_z.js +0 -3
- package/dist/gateway/static/root/assets/index-Cl5n1f_U.css +0 -1
- package/dist/gateway/static/root/assets/index-OJgiMh07.js +0 -223
- package/dist/gateway/static/root/assets/local-app-workbench-page-B69NvtvH.js +0 -2
- package/dist/gateway/static/root/assets/locale-store-D6hs74o5.js +0 -1
- package/dist/gateway/static/root/assets/logs-page-Cq3cABqg.js +0 -7
- package/dist/gateway/static/root/assets/messages-D02NNLCZ.js +0 -3
- package/dist/gateway/static/root/assets/notes-workbench-BOZfJFhE.js +0 -4
- package/dist/gateway/static/root/assets/product-delivery-C8JbSj5Y.js +0 -1
- package/dist/gateway/static/root/assets/project-detail-page-TSKFb2tN.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-BokeBrTT.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-C56anxCX.js +0 -1
- package/dist/gateway/static/root/assets/segmented-styles-BL8oLBEp.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-C7TQADrD.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BDOPKeAX.js +0 -1
- package/dist/gateway/static/root/assets/settings-form-section-zxo5ZGOu.js +0 -1
- package/dist/gateway/static/root/assets/settings-page-BUPSIa9P.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BRg766eW.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-DhEAviQ_.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-Ct7AV8ls.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-DoVuprZm.js +0 -2
- package/dist/gateway/static/root/assets/time-picker-BGk_Tbsj.js +0 -1
- package/dist/gateway/static/root/assets/use-save-bar-registration-5aVSjTjO.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-B9K41qmy.js +0 -1
- package/dist/gateway/static/root/assets/work-discovery-page-BBVnRHju.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-Bs_tYfst.js +0 -11
- package/dist/src/agent/code-intelligence/binary.d.ts +0 -15
- package/dist/src/agent/code-intelligence/binary.js +0 -372
- package/dist/src/agent/code-intelligence/index.d.ts +0 -4
- package/dist/src/agent/code-intelligence/index.js +0 -4
- package/dist/src/agent/code-intelligence/runtime.d.ts +0 -34
- package/dist/src/agent/code-intelligence/runtime.js +0 -280
- package/dist/src/agent/code-intelligence/tool-gating.d.ts +0 -5
- package/dist/src/agent/code-intelligence/tool-gating.js +0 -6
- package/dist/src/agent/code-intelligence/tools.d.ts +0 -6
- package/dist/src/agent/code-intelligence/tools.js +0 -266
- package/dist/src/agent/code-intelligence/types.d.ts +0 -22
- package/dist/src/agent/memory/context/planner.js +0 -286
- package/dist/src/agent/memory/dreaming/config.d.ts +0 -48
- package/dist/src/agent/memory/dreaming/config.js +0 -98
- package/dist/src/agent/memory/dreaming/constants.d.ts +0 -12
- package/dist/src/agent/memory/dreaming/constants.js +0 -18
- package/dist/src/agent/memory/dreaming/deep-promotion.d.ts +0 -19
- package/dist/src/agent/memory/dreaming/deep-promotion.js +0 -152
- package/dist/src/agent/memory/dreaming/light-sweep.d.ts +0 -16
- package/dist/src/agent/memory/dreaming/light-sweep.js +0 -115
- package/dist/src/agent/memory/dreaming/preview.d.ts +0 -23
- package/dist/src/agent/memory/dreaming/preview.js +0 -52
- package/dist/src/agent/memory/dreaming/promotion-lifecycle.d.ts +0 -16
- package/dist/src/agent/memory/dreaming/promotion-lifecycle.js +0 -44
- package/dist/src/agent/memory/dreaming/rem-patterns.d.ts +0 -19
- package/dist/src/agent/memory/dreaming/rem-patterns.js +0 -150
- package/dist/src/agent/memory/dreaming/runner.d.ts +0 -10
- package/dist/src/agent/memory/dreaming/runner.js +0 -78
- package/dist/src/agent/memory/dreaming/schedule.d.ts +0 -23
- package/dist/src/agent/memory/dreaming/schedule.js +0 -38
- package/dist/src/agent/memory/dreaming/scope.d.ts +0 -11
- package/dist/src/agent/memory/dreaming/scope.js +0 -33
- package/dist/src/agent/memory/dreaming/utils.d.ts +0 -3
- package/dist/src/agent/memory/dreaming/utils.js +0 -31
- package/dist/src/agent/streaming/reasoning-visibility-sse.d.ts +0 -15
- package/dist/src/gateway/agent-run-relay.d.ts +0 -19
- package/dist/src/gateway/agent-run-relay.js +0 -169
- package/dist/src/gateway/hono/routes/memory.d.ts +0 -3
- package/dist/src/gateway/hono/routes/memory.js +0 -460
- package/dist/src/gateway/hono/sse.d.ts +0 -53
- package/dist/src/gateway/hono/sse.js +0 -207
- package/dist/src/gateway/service/sse-hub.d.ts +0 -10
- package/dist/src/gateway/service/sse-hub.js +0 -53
- package/dist/src/storage/sqlite/dreaming-repository.d.ts +0 -61
- package/dist/src/storage/sqlite/dreaming-repository.js +0 -88
- package/dist/src/storage/sqlite/memory-readiness-repository.d.ts +0 -7
- package/dist/src/storage/sqlite/memory-readiness-repository.js +0 -30
- package/dist/src/storage/sqlite/memory-reference-consent-repository.d.ts +0 -27
- package/dist/src/storage/sqlite/memory-reference-consent-repository.js +0 -107
- package/dist/src/storage/sqlite/user-claims-repository.d.ts +0 -101
- package/dist/src/storage/sqlite/user-claims-repository.js +0 -241
- package/dist/src/storage/sqlite/user-profile-setup-repository.d.ts +0 -3
- package/dist/src/storage/sqlite/user-profile-setup-repository.js +0 -32
- package/dist/src/tui/sse-consumer.d.ts +0 -15
- package/dist/src/tui/sse-consumer.js +0 -73
- package/dist/src/user-context/context-compiler.d.ts +0 -27
- package/dist/src/user-context/context-compiler.js +0 -48
- package/dist/src/user-context/import.d.ts +0 -12
- package/dist/src/user-context/import.js +0 -51
- package/dist/src/user-context/memory-episode-evaluator.d.ts +0 -32
- package/dist/src/user-context/memory-episode-evaluator.js +0 -35
- package/dist/src/user-context/memory-readiness.d.ts +0 -33
- package/dist/src/user-context/memory-readiness.js +0 -41
- package/dist/src/user-context/memory-use-audit.d.ts +0 -10
- package/dist/src/user-context/memory-use-audit.js +0 -26
- package/dist/src/user-context/personal-playbook.d.ts +0 -11
- package/dist/src/user-context/personal-playbook.js +0 -41
- package/dist/src/user-context/profile.d.ts +0 -37
- package/dist/src/user-context/profile.js +0 -163
- package/dist/src/user-context/projection.d.ts +0 -120
- package/dist/src/user-context/projection.js +0 -262
- package/dist/src/user-context/source-recommendations.d.ts +0 -13
- package/dist/src/user-context/source-recommendations.js +0 -85
- /package/dist/src/{agent/code-intelligence → user-context/sources}/types.js +0 -0
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { createLogger } from "../../../utils/logger/index.js";
|
|
2
|
-
import { init_logger } from "../../../utils/logger.js";
|
|
3
|
-
import { appendMemorySignal, appendMemoryTraceEvent, hasUnresolvedMemoryConflict } from "../../../storage/sqlite/memory-records-repository.js";
|
|
4
|
-
import { consumeMemoryReferenceConsent, ensureMemoryReferenceConsentRequest, hasMemoryReferenceConsent } from "../../../storage/sqlite/memory-reference-consent-repository.js";
|
|
5
|
-
import "../../../storage/sqlite/index.js";
|
|
6
|
-
import { readAgentMessageContent } from "../agent-message-access.js";
|
|
7
|
-
import { resolveMemoryStability } from "../lifecycle.js";
|
|
8
|
-
import { classifyMemoryContextOrigin } from "../source-origin.js";
|
|
9
|
-
import { USER_CONTEXT_MEMORY_KINDS, isUserContextRecord } from "../../../user-context/projection.js";
|
|
10
|
-
import { buildUserContextBlock } from "../context-fence.js";
|
|
11
|
-
import { randomUUID } from "node:crypto";
|
|
12
|
-
//#region src/agent/memory/context/planner.ts
|
|
13
|
-
init_logger();
|
|
14
|
-
const DEFAULT_MAX_CONTEXT_CHARS = 12e3;
|
|
15
|
-
const DEFAULT_MAX_RESULTS = 12;
|
|
16
|
-
const BASELINE_KINDS = [
|
|
17
|
-
"boundary",
|
|
18
|
-
"preference",
|
|
19
|
-
"tool_preference",
|
|
20
|
-
"routine",
|
|
21
|
-
"user_profile",
|
|
22
|
-
"personal_logistics"
|
|
23
|
-
];
|
|
24
|
-
const SELF_SUMMARY_PATTERNS = [
|
|
25
|
-
/(?:介绍|说说|描述|总结)(?:一下|下)?你?(?:所)?(?:了解|知道|认知)(?:到)?的?我/u,
|
|
26
|
-
/你眼中的我/u,
|
|
27
|
-
/(?:关于我你|你(?:对我|关于我))(?:有)?(?:哪些|什么)?(?:了解|认知|知道|记得|印象)/u,
|
|
28
|
-
/(?:what (?:do|can) you|what you) (?:know|understand|remember) about me/i,
|
|
29
|
-
/(?:describe|summari[sz]e|introduce) me/i,
|
|
30
|
-
/(?:how do you see|your impression of) me/i
|
|
31
|
-
];
|
|
32
|
-
const log = createLogger("UserContextPlanner");
|
|
33
|
-
function isUserSelfSummaryQuery(query) {
|
|
34
|
-
return SELF_SUMMARY_PATTERNS.some((pattern) => pattern.test(query));
|
|
35
|
-
}
|
|
36
|
-
function sectionFor(record) {
|
|
37
|
-
if (record.kind === "boundary") return "safety";
|
|
38
|
-
if (record.kind === "preference" || record.kind === "user_profile" || record.kind === "relationship" || record.kind === "routine" || record.kind === "personal_logistics" || record.kind === "tool_preference") return "interaction";
|
|
39
|
-
return "task";
|
|
40
|
-
}
|
|
41
|
-
function rejectReason(record, now, hasReferenceConsent) {
|
|
42
|
-
if (record.tags?.includes("playbook:disabled")) return "disabled";
|
|
43
|
-
if (record.conflictGroupId && hasUnresolvedMemoryConflict(record.conflictGroupId)) return "conflict";
|
|
44
|
-
if (record.validFrom && Date.parse(record.validFrom) > now) return "not_yet_valid";
|
|
45
|
-
if (record.validTo && Date.parse(record.validTo) < now || record.expiresAt && Date.parse(record.expiresAt) < now) return "expired";
|
|
46
|
-
if (record.sensitivity === "secret" || record.sensitivity === "regulated") return "sensitive";
|
|
47
|
-
if (record.disclosurePolicy === "ask_before_reference" && !hasReferenceConsent) return "requires_consent";
|
|
48
|
-
if (record.status === "needs_review" || record.status === "stale" || resolveMemoryStability(record, now).reviewDue) return "needs_review";
|
|
49
|
-
}
|
|
50
|
-
function scoreResult(result, now) {
|
|
51
|
-
const confidence = result.record.confidence ?? .5;
|
|
52
|
-
const explicitness = result.record.explicitness === "explicit" ? 1 : result.record.explicitness === "observed" ? .65 : .4;
|
|
53
|
-
const stability = resolveMemoryStability(result.record, now).score;
|
|
54
|
-
return Math.max(0, Math.min(1, result.score * .45 + confidence * .1 + result.record.importance * .2 + explicitness * .1 + stability * .15));
|
|
55
|
-
}
|
|
56
|
-
function citationFor(result, requesterAgentId) {
|
|
57
|
-
const base = result.citation.path ?? `${result.citation.providerId}:${result.citation.recordId}`;
|
|
58
|
-
if (result.citation.lineStart == null) return base;
|
|
59
|
-
const end = result.citation.lineEnd && result.citation.lineEnd !== result.citation.lineStart ? `-L${result.citation.lineEnd}` : "";
|
|
60
|
-
return `${base}#L${result.citation.lineStart}${end}`;
|
|
61
|
-
}
|
|
62
|
-
function evidenceLabel(item) {
|
|
63
|
-
if (item.origin === "told_by_user") return "The user explicitly shared this";
|
|
64
|
-
if (item.origin === "observed") return "Observed across prior work";
|
|
65
|
-
if (item.origin === "connected_source") return "A connected source provided this";
|
|
66
|
-
return "An inference that may be wrong";
|
|
67
|
-
}
|
|
68
|
-
function prependAgentContext(message, block) {
|
|
69
|
-
if (!block) return message;
|
|
70
|
-
const prefix = `${block}\n\n`;
|
|
71
|
-
const content = readAgentMessageContent(message);
|
|
72
|
-
if (typeof content === "string") return {
|
|
73
|
-
...message,
|
|
74
|
-
content: prefix + content
|
|
75
|
-
};
|
|
76
|
-
if (Array.isArray(content) && content.length > 0) {
|
|
77
|
-
const first = content[0];
|
|
78
|
-
if (first.type === "text" && typeof first.text === "string") {
|
|
79
|
-
const copy = [...content];
|
|
80
|
-
copy[0] = {
|
|
81
|
-
type: "text",
|
|
82
|
-
text: prefix + first.text
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
...message,
|
|
86
|
-
content: copy
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
...message,
|
|
91
|
-
content: [{
|
|
92
|
-
type: "text",
|
|
93
|
-
text: prefix
|
|
94
|
-
}, ...content]
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return message;
|
|
98
|
-
}
|
|
99
|
-
var UserContextPlanner = class {
|
|
100
|
-
async plan(params) {
|
|
101
|
-
const traceId = randomUUID();
|
|
102
|
-
const query = params.query.trim();
|
|
103
|
-
if (!query) return {
|
|
104
|
-
traceId,
|
|
105
|
-
modelMessage: params.userMessage,
|
|
106
|
-
items: [],
|
|
107
|
-
rejected: [],
|
|
108
|
-
consentRequests: [],
|
|
109
|
-
estimatedTokens: 0,
|
|
110
|
-
allocation: params.allocation
|
|
111
|
-
};
|
|
112
|
-
const maxResults = params.allocation?.maxResults ?? DEFAULT_MAX_RESULTS;
|
|
113
|
-
const maxContextChars = params.allocation?.maxChars ?? DEFAULT_MAX_CONTEXT_CHARS;
|
|
114
|
-
const started = Date.now();
|
|
115
|
-
const scope = {
|
|
116
|
-
userId: "local-owner",
|
|
117
|
-
sessionKey: params.sessionKey
|
|
118
|
-
};
|
|
119
|
-
const selfSummary = isUserSelfSummaryQuery(query);
|
|
120
|
-
const baselineKinds = selfSummary ? USER_CONTEXT_MEMORY_KINDS : BASELINE_KINDS;
|
|
121
|
-
const [searchedResults, baselineLists] = await Promise.all([params.memoryManager.search({
|
|
122
|
-
query,
|
|
123
|
-
scope,
|
|
124
|
-
maxResults,
|
|
125
|
-
minScore: .15
|
|
126
|
-
}).catch(() => []), Promise.all(baselineKinds.map((kind) => params.memoryManager.list({
|
|
127
|
-
kind,
|
|
128
|
-
status: "active",
|
|
129
|
-
scope
|
|
130
|
-
}).catch(() => [])))]);
|
|
131
|
-
const taskResults = selfSummary ? searchedResults.filter((result) => isUserContextRecord(result.record)) : searchedResults;
|
|
132
|
-
const taskIds = new Set(taskResults.map((result) => result.record.id));
|
|
133
|
-
const baselineResults = baselineLists.flat().filter((record) => !taskIds.has(record.id)).filter((record) => isUserContextRecord(record)).filter((record) => selfSummary || record.kind === "boundary" || record.explicitness === "explicit" || record.importance >= .7).map((record) => ({
|
|
134
|
-
record,
|
|
135
|
-
score: record.kind === "boundary" ? .7 : selfSummary ? .6 : .42,
|
|
136
|
-
snippet: record.content,
|
|
137
|
-
citation: {
|
|
138
|
-
providerId: record.providerId,
|
|
139
|
-
recordId: record.id,
|
|
140
|
-
path: record.source.path,
|
|
141
|
-
lineStart: record.source.lineStart,
|
|
142
|
-
lineEnd: record.source.lineEnd,
|
|
143
|
-
createdAt: record.createdAt
|
|
144
|
-
}
|
|
145
|
-
}));
|
|
146
|
-
const results = [...taskResults, ...baselineResults];
|
|
147
|
-
const now = Date.now();
|
|
148
|
-
const excluded = new Set(params.excludedRecordIds ?? []);
|
|
149
|
-
const rejected = [];
|
|
150
|
-
const consentRequests = [];
|
|
151
|
-
const ranked = results.filter((result) => !excluded.has(result.record.id)).map((result) => ({
|
|
152
|
-
result,
|
|
153
|
-
score: scoreResult(result, now)
|
|
154
|
-
})).sort((a, b) => b.score - a.score).filter((entry, index, all) => all.findIndex((candidate) => candidate.result.record.id === entry.result.record.id) === index).slice(0, maxResults);
|
|
155
|
-
const items = [];
|
|
156
|
-
let usedChars = 0;
|
|
157
|
-
for (const { result, score } of ranked) {
|
|
158
|
-
const needsConsent = result.record.disclosurePolicy === "ask_before_reference" && result.record.sensitivity !== "secret" && result.record.sensitivity !== "regulated";
|
|
159
|
-
const hasReferenceConsent = needsConsent ? hasMemoryReferenceConsent(result.record.id, params.sessionKey) : false;
|
|
160
|
-
const reason = rejectReason(result.record, now, hasReferenceConsent) ?? (score < .25 ? "low_score" : void 0);
|
|
161
|
-
if (reason) {
|
|
162
|
-
rejected.push({
|
|
163
|
-
recordId: result.record.id,
|
|
164
|
-
reason
|
|
165
|
-
});
|
|
166
|
-
if (reason === "requires_consent") {
|
|
167
|
-
const request = ensureMemoryReferenceConsentRequest({
|
|
168
|
-
recordId: result.record.id,
|
|
169
|
-
sessionKey: params.sessionKey,
|
|
170
|
-
purpose: query
|
|
171
|
-
});
|
|
172
|
-
consentRequests.push({
|
|
173
|
-
id: request.id,
|
|
174
|
-
recordId: request.recordId,
|
|
175
|
-
statement: result.record.content,
|
|
176
|
-
purpose: request.purpose
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
const content = result.snippet.trim();
|
|
182
|
-
if (usedChars + content.length > maxContextChars) {
|
|
183
|
-
rejected.push({
|
|
184
|
-
recordId: result.record.id,
|
|
185
|
-
reason: "budget"
|
|
186
|
-
});
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (needsConsent && !consumeMemoryReferenceConsent(result.record.id, params.sessionKey)) {
|
|
190
|
-
rejected.push({
|
|
191
|
-
recordId: result.record.id,
|
|
192
|
-
reason: "requires_consent"
|
|
193
|
-
});
|
|
194
|
-
const request = ensureMemoryReferenceConsentRequest({
|
|
195
|
-
recordId: result.record.id,
|
|
196
|
-
sessionKey: params.sessionKey,
|
|
197
|
-
purpose: query
|
|
198
|
-
});
|
|
199
|
-
consentRequests.push({
|
|
200
|
-
id: request.id,
|
|
201
|
-
recordId: request.recordId,
|
|
202
|
-
statement: result.record.content,
|
|
203
|
-
purpose: request.purpose
|
|
204
|
-
});
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
usedChars += content.length;
|
|
208
|
-
items.push({
|
|
209
|
-
recordId: result.record.id,
|
|
210
|
-
content,
|
|
211
|
-
score,
|
|
212
|
-
section: sectionFor(result.record),
|
|
213
|
-
citation: citationFor(result, params.agentId),
|
|
214
|
-
origin: classifyMemoryContextOrigin(result.record),
|
|
215
|
-
stability: resolveMemoryStability(result.record, now).score
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
const sections = [];
|
|
219
|
-
for (const [section, title] of [
|
|
220
|
-
["safety", "Boundaries"],
|
|
221
|
-
["task", "Relevant facts"],
|
|
222
|
-
["interaction", "Interaction preferences"]
|
|
223
|
-
]) {
|
|
224
|
-
const sectionItems = items.filter((item) => item.section === section);
|
|
225
|
-
if (sectionItems.length > 0) sections.push(`${title}:\n${sectionItems.map((item) => `- ${item.content}\n Evidence: ${evidenceLabel(item)}`).join("\n")}`);
|
|
226
|
-
}
|
|
227
|
-
const consentNotice = consentRequests.length > 0 ? "A relevant saved understanding requires the user’s explicit permission before it can be referenced. Do not infer or reveal its contents. Briefly ask the user to approve the pending item in You > Understanding, then continue without it." : "";
|
|
228
|
-
const block = [buildUserContextBlock(sections.join("\n\n")), consentNotice].filter(Boolean).join("\n\n");
|
|
229
|
-
try {
|
|
230
|
-
for (const item of items) appendMemorySignal({
|
|
231
|
-
signal: {
|
|
232
|
-
source: "context_injection",
|
|
233
|
-
recordId: item.recordId,
|
|
234
|
-
score: item.score,
|
|
235
|
-
content: item.content,
|
|
236
|
-
metadata: {
|
|
237
|
-
traceId,
|
|
238
|
-
turnId: params.turnId,
|
|
239
|
-
query
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
providerId: "local",
|
|
243
|
-
sourceAgentId: params.agentId,
|
|
244
|
-
sessionKey: params.sessionKey
|
|
245
|
-
});
|
|
246
|
-
appendMemoryTraceEvent({
|
|
247
|
-
traceId,
|
|
248
|
-
phase: "inject",
|
|
249
|
-
providerId: "user-understanding",
|
|
250
|
-
sessionKey: params.sessionKey,
|
|
251
|
-
turnId: params.turnId,
|
|
252
|
-
request: {
|
|
253
|
-
query,
|
|
254
|
-
rejected,
|
|
255
|
-
contextItems: items.map((item) => ({
|
|
256
|
-
recordId: item.recordId,
|
|
257
|
-
section: item.section,
|
|
258
|
-
origin: item.origin,
|
|
259
|
-
stability: item.stability,
|
|
260
|
-
citation: item.citation
|
|
261
|
-
}))
|
|
262
|
-
},
|
|
263
|
-
resultCount: items.length,
|
|
264
|
-
selectedRecordIds: items.map((item) => item.recordId),
|
|
265
|
-
durationMs: Date.now() - started
|
|
266
|
-
});
|
|
267
|
-
} catch (err) {
|
|
268
|
-
log.debug({
|
|
269
|
-
err,
|
|
270
|
-
traceId,
|
|
271
|
-
sessionKey: params.sessionKey
|
|
272
|
-
}, "Context plan trace was not persisted");
|
|
273
|
-
}
|
|
274
|
-
return {
|
|
275
|
-
traceId,
|
|
276
|
-
modelMessage: prependAgentContext(params.userMessage, block),
|
|
277
|
-
items,
|
|
278
|
-
rejected,
|
|
279
|
-
consentRequests,
|
|
280
|
-
estimatedTokens: Math.ceil(block.length / 4),
|
|
281
|
-
allocation: params.allocation
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
//#endregion
|
|
286
|
-
export { UserContextPlanner, isUserSelfSummaryQuery, prependAgentContext };
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Config } from '../../../config/schema.js';
|
|
2
|
-
import type { DreamingMode } from '../../../storage/sqlite/index.js';
|
|
3
|
-
import type { DreamingSchedule, DreamingSettings } from '../../../user-context/config.js';
|
|
4
|
-
import { type DreamingPhaseId } from './constants.js';
|
|
5
|
-
export type DreamingLightConfig = {
|
|
6
|
-
enabled: boolean;
|
|
7
|
-
schedule: DreamingSchedule;
|
|
8
|
-
lookbackDays: number;
|
|
9
|
-
limit: number;
|
|
10
|
-
};
|
|
11
|
-
export type DreamingDeepConfig = {
|
|
12
|
-
enabled: boolean;
|
|
13
|
-
schedule: DreamingSchedule;
|
|
14
|
-
minScore: number;
|
|
15
|
-
minRecallCount: number;
|
|
16
|
-
minUniqueQueries: number;
|
|
17
|
-
limit: number;
|
|
18
|
-
recencyHalfLifeDays: number;
|
|
19
|
-
maxAgeDays: number;
|
|
20
|
-
};
|
|
21
|
-
export type DreamingRemConfig = {
|
|
22
|
-
enabled: boolean;
|
|
23
|
-
schedule: DreamingSchedule;
|
|
24
|
-
lookbackDays: number;
|
|
25
|
-
limit: number;
|
|
26
|
-
minPatternStrength: number;
|
|
27
|
-
};
|
|
28
|
-
export type DreamingResolvedConfig = {
|
|
29
|
-
requestedMode: DreamingMode;
|
|
30
|
-
mode: DreamingMode;
|
|
31
|
-
enabled: boolean;
|
|
32
|
-
writeDisposition: 'none' | 'candidate' | 'active';
|
|
33
|
-
automaticReady: boolean;
|
|
34
|
-
downgradeReason?: 'memory_policy' | 'quality_gate';
|
|
35
|
-
timezone: string;
|
|
36
|
-
phases: {
|
|
37
|
-
light: DreamingLightConfig;
|
|
38
|
-
deep: DreamingDeepConfig;
|
|
39
|
-
rem: DreamingRemConfig;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
export declare function resolveDreamingSettings(cfg: Config | undefined): DreamingSettings;
|
|
43
|
-
/** Resolve the full three-phase dreaming config and its effective write authority. */
|
|
44
|
-
export declare function resolveDreamingConfig(cfg: Config | undefined, options?: {
|
|
45
|
-
automaticReady?: boolean;
|
|
46
|
-
}): DreamingResolvedConfig;
|
|
47
|
-
/** Check if a specific phase is enabled (global + phase-level). */
|
|
48
|
-
export declare function isPhaseEnabled(config: DreamingResolvedConfig, phase: DreamingPhaseId): boolean;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import "./constants.js";
|
|
2
|
-
import { DEFAULT_DREAMING_SCHEDULES, resolveDreamingTimezone } from "./schedule.js";
|
|
3
|
-
//#region src/agent/memory/dreaming/config.ts
|
|
4
|
-
function clampScore(value, fallback) {
|
|
5
|
-
if (!Number.isFinite(value)) return fallback;
|
|
6
|
-
return Math.max(0, Math.min(1, value));
|
|
7
|
-
}
|
|
8
|
-
function toPositiveInt(value, fallback) {
|
|
9
|
-
const num = typeof value === "string" ? Number(value) : Number(value);
|
|
10
|
-
if (!Number.isFinite(num)) return fallback;
|
|
11
|
-
const floored = Math.floor(num);
|
|
12
|
-
return floored > 0 ? floored : fallback;
|
|
13
|
-
}
|
|
14
|
-
function toNonNegInt(value, fallback) {
|
|
15
|
-
const num = typeof value === "string" ? Number(value) : Number(value);
|
|
16
|
-
if (!Number.isFinite(num)) return fallback;
|
|
17
|
-
const floored = Math.floor(num);
|
|
18
|
-
return floored >= 0 ? floored : fallback;
|
|
19
|
-
}
|
|
20
|
-
function resolveDreamingSettings(cfg) {
|
|
21
|
-
const dreaming = cfg?.userContext.dreaming;
|
|
22
|
-
return {
|
|
23
|
-
mode: dreaming?.mode ?? "off",
|
|
24
|
-
timezone: resolveDreamingTimezone(dreaming?.timezone),
|
|
25
|
-
phases: {
|
|
26
|
-
light: {
|
|
27
|
-
enabled: dreaming?.phases?.light?.enabled !== false,
|
|
28
|
-
schedule: dreaming?.phases?.light?.schedule ?? DEFAULT_DREAMING_SCHEDULES.light
|
|
29
|
-
},
|
|
30
|
-
deep: {
|
|
31
|
-
enabled: dreaming?.phases?.deep?.enabled !== false,
|
|
32
|
-
schedule: dreaming?.phases?.deep?.schedule ?? DEFAULT_DREAMING_SCHEDULES.deep
|
|
33
|
-
},
|
|
34
|
-
rem: {
|
|
35
|
-
enabled: dreaming?.phases?.rem?.enabled !== false,
|
|
36
|
-
schedule: dreaming?.phases?.rem?.schedule ?? DEFAULT_DREAMING_SCHEDULES.rem
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/** Resolve the full three-phase dreaming config and its effective write authority. */
|
|
42
|
-
function resolveDreamingConfig(cfg, options = {}) {
|
|
43
|
-
const dreaming = cfg?.userContext.dreaming;
|
|
44
|
-
const settings = resolveDreamingSettings(cfg);
|
|
45
|
-
const requestedMode = settings.mode;
|
|
46
|
-
const memoryMode = cfg?.userContext.memory.mode ?? "off";
|
|
47
|
-
const automaticReady = options.automaticReady === true;
|
|
48
|
-
const mode = cfg?.userContext.enabled !== true || memoryMode === "off" ? "off" : memoryMode === "readOnly" ? requestedMode === "off" ? "off" : "observe" : memoryMode === "confirmWrite" && requestedMode === "automatic" ? "review" : requestedMode === "automatic" && !automaticReady ? "review" : requestedMode;
|
|
49
|
-
const enabled = mode !== "off";
|
|
50
|
-
const writeDisposition = mode === "automatic" ? "active" : mode === "review" ? "candidate" : "none";
|
|
51
|
-
const timezone = settings.timezone;
|
|
52
|
-
const lightRaw = dreaming?.phases?.light ?? {};
|
|
53
|
-
const light = {
|
|
54
|
-
enabled: enabled && settings.phases.light.enabled,
|
|
55
|
-
schedule: settings.phases.light.schedule,
|
|
56
|
-
lookbackDays: toPositiveInt(lightRaw?.lookbackDays, 2),
|
|
57
|
-
limit: toNonNegInt(lightRaw?.limit, 100)
|
|
58
|
-
};
|
|
59
|
-
const deepRaw = dreaming?.phases?.deep ?? {};
|
|
60
|
-
const deep = {
|
|
61
|
-
enabled: enabled && settings.phases.deep.enabled,
|
|
62
|
-
schedule: settings.phases.deep.schedule,
|
|
63
|
-
minScore: clampScore(Number(deepRaw?.minScore), .8),
|
|
64
|
-
minRecallCount: toPositiveInt(deepRaw?.minRecallCount, 3),
|
|
65
|
-
minUniqueQueries: toPositiveInt(deepRaw?.minUniqueQueries, 3),
|
|
66
|
-
limit: toNonNegInt(deepRaw?.limit, 10),
|
|
67
|
-
recencyHalfLifeDays: toPositiveInt(deepRaw?.recencyHalfLifeDays, 14),
|
|
68
|
-
maxAgeDays: toPositiveInt(deepRaw?.maxAgeDays, 30)
|
|
69
|
-
};
|
|
70
|
-
const remRaw = dreaming?.phases?.rem ?? {};
|
|
71
|
-
const rem = {
|
|
72
|
-
enabled: enabled && settings.phases.rem.enabled,
|
|
73
|
-
schedule: settings.phases.rem.schedule,
|
|
74
|
-
lookbackDays: toPositiveInt(remRaw?.lookbackDays, 7),
|
|
75
|
-
limit: toNonNegInt(remRaw?.limit, 10),
|
|
76
|
-
minPatternStrength: clampScore(Number(remRaw?.minPatternStrength), .75)
|
|
77
|
-
};
|
|
78
|
-
return {
|
|
79
|
-
requestedMode,
|
|
80
|
-
mode,
|
|
81
|
-
enabled,
|
|
82
|
-
writeDisposition,
|
|
83
|
-
automaticReady,
|
|
84
|
-
...requestedMode === "automatic" && mode !== "automatic" ? { downgradeReason: memoryMode === "confirmWrite" || memoryMode === "readOnly" ? "memory_policy" : "quality_gate" } : {},
|
|
85
|
-
timezone,
|
|
86
|
-
phases: {
|
|
87
|
-
light,
|
|
88
|
-
deep,
|
|
89
|
-
rem
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/** Check if a specific phase is enabled (global + phase-level). */
|
|
94
|
-
function isPhaseEnabled(config, phase) {
|
|
95
|
-
return config.enabled && config.phases[phase].enabled;
|
|
96
|
-
}
|
|
97
|
-
//#endregion
|
|
98
|
-
export { isPhaseEnabled, resolveDreamingConfig, resolveDreamingSettings };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type DreamingPhaseId = 'light' | 'deep' | 'rem';
|
|
2
|
-
export declare const DREAMING_ALGORITHM_VERSION = "structured-v1";
|
|
3
|
-
export declare const DREAMING_PHASES: readonly DreamingPhaseId[];
|
|
4
|
-
export declare const DREAMING_SWEEP_TOKEN = "__xopc_memory_dreaming_sweep__";
|
|
5
|
-
export declare const DREAMING_LIGHT_SWEEP_TOKEN = "__xopc_memory_dreaming_light_sweep__";
|
|
6
|
-
export declare const DREAMING_REM_SWEEP_TOKEN = "__xopc_memory_dreaming_rem_sweep__";
|
|
7
|
-
export declare const DREAMING_AUTOMATION_TAG = "[managed-by=xopc.memory.dreaming]";
|
|
8
|
-
export declare const DREAMING_DEEP_AUTOMATION_NAME = "Memory Dreaming - Deep Promotion";
|
|
9
|
-
export declare const DREAMING_LIGHT_AUTOMATION_NAME = "Memory Dreaming - Light Sweep";
|
|
10
|
-
export declare const DREAMING_REM_AUTOMATION_NAME = "Memory Dreaming - REM Patterns";
|
|
11
|
-
export declare const DEFAULT_RECENCY_HALF_LIFE_DAYS = 14;
|
|
12
|
-
export declare const DEFAULT_MAX_AGE_DAYS = 30;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//#region src/agent/memory/dreaming/constants.ts
|
|
2
|
-
const DREAMING_ALGORITHM_VERSION = "structured-v1";
|
|
3
|
-
const DREAMING_PHASES = [
|
|
4
|
-
"light",
|
|
5
|
-
"deep",
|
|
6
|
-
"rem"
|
|
7
|
-
];
|
|
8
|
-
const DREAMING_SWEEP_TOKEN = "__xopc_memory_dreaming_sweep__";
|
|
9
|
-
const DREAMING_LIGHT_SWEEP_TOKEN = "__xopc_memory_dreaming_light_sweep__";
|
|
10
|
-
const DREAMING_REM_SWEEP_TOKEN = "__xopc_memory_dreaming_rem_sweep__";
|
|
11
|
-
const DREAMING_AUTOMATION_TAG = "[managed-by=xopc.memory.dreaming]";
|
|
12
|
-
const DREAMING_DEEP_AUTOMATION_NAME = "Memory Dreaming - Deep Promotion";
|
|
13
|
-
const DREAMING_LIGHT_AUTOMATION_NAME = "Memory Dreaming - Light Sweep";
|
|
14
|
-
const DREAMING_REM_AUTOMATION_NAME = "Memory Dreaming - REM Patterns";
|
|
15
|
-
const DEFAULT_RECENCY_HALF_LIFE_DAYS = 14;
|
|
16
|
-
const DEFAULT_MAX_AGE_DAYS = 30;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { DEFAULT_MAX_AGE_DAYS, DEFAULT_RECENCY_HALF_LIFE_DAYS, DREAMING_ALGORITHM_VERSION, DREAMING_AUTOMATION_TAG, DREAMING_DEEP_AUTOMATION_NAME, DREAMING_LIGHT_AUTOMATION_NAME, DREAMING_LIGHT_SWEEP_TOKEN, DREAMING_PHASES, DREAMING_REM_AUTOMATION_NAME, DREAMING_REM_SWEEP_TOKEN, DREAMING_SWEEP_TOKEN };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type DreamingActiveMode } from '../../../storage/sqlite/index.js';
|
|
2
|
-
import type { DreamingDeepConfig } from './config.js';
|
|
3
|
-
export type { DreamingDeepConfig } from './config.js';
|
|
4
|
-
/** Consolidate useful candidates from structured recall and injection signals. */
|
|
5
|
-
export declare function runDreamingDeepPromotion(params: {
|
|
6
|
-
agentId: string;
|
|
7
|
-
runId: string;
|
|
8
|
-
mode: DreamingActiveMode;
|
|
9
|
-
workspaceDir: string;
|
|
10
|
-
config?: Partial<DreamingDeepConfig>;
|
|
11
|
-
sensitiveWritePolicy?: 'deny' | 'confirm' | 'allow';
|
|
12
|
-
now?: Date;
|
|
13
|
-
}): Promise<{
|
|
14
|
-
ok: boolean;
|
|
15
|
-
reason: string;
|
|
16
|
-
candidates: number;
|
|
17
|
-
applied: number;
|
|
18
|
-
memoryPath: string;
|
|
19
|
-
}>;
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { createLogger } from "../../../utils/logger/index.js";
|
|
2
|
-
import { init_logger } from "../../../utils/logger.js";
|
|
3
|
-
import { recordDreamingDecision } from "../../../storage/sqlite/dreaming-repository.js";
|
|
4
|
-
import { appendMemorySignal, appendMemoryTraceEvent, listMemoryRecords, listMemorySignals, setMemoryRecordStatus } from "../../../storage/sqlite/memory-records-repository.js";
|
|
5
|
-
import "../../../storage/sqlite/index.js";
|
|
6
|
-
import { resolveDeepDefaults } from "./utils.js";
|
|
7
|
-
//#region src/agent/memory/dreaming/deep-promotion.ts
|
|
8
|
-
init_logger();
|
|
9
|
-
const log = createLogger("Dreaming:Deep");
|
|
10
|
-
const MEMORY_STORE_URI = "sqlite://memory_records";
|
|
11
|
-
/** Consolidate useful candidates from structured recall and injection signals. */
|
|
12
|
-
async function runDreamingDeepPromotion(params) {
|
|
13
|
-
const cfg = resolveDeepDefaults(params.config);
|
|
14
|
-
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
15
|
-
const started = Date.now();
|
|
16
|
-
if (!cfg.enabled || cfg.limit === 0) {
|
|
17
|
-
const reason = !cfg.enabled ? "dreaming disabled" : "dreaming limit=0";
|
|
18
|
-
trace(params, reason, [], 0, started);
|
|
19
|
-
return {
|
|
20
|
-
ok: true,
|
|
21
|
-
reason,
|
|
22
|
-
candidates: 0,
|
|
23
|
-
applied: 0,
|
|
24
|
-
memoryPath: MEMORY_STORE_URI
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
const cutoff = now.getTime() - cfg.maxAgeDays * 864e5;
|
|
29
|
-
const records = listMemoryRecords({
|
|
30
|
-
providerId: "local",
|
|
31
|
-
workspaceId: params.workspaceDir,
|
|
32
|
-
status: "candidate",
|
|
33
|
-
limit: 500
|
|
34
|
-
});
|
|
35
|
-
const signals = listMemorySignals({
|
|
36
|
-
workspaceId: params.workspaceDir,
|
|
37
|
-
limit: 500
|
|
38
|
-
});
|
|
39
|
-
const byRecord = /* @__PURE__ */ new Map();
|
|
40
|
-
for (const signal of signals) {
|
|
41
|
-
if (!signal.recordId || Date.parse(signal.createdAt) < cutoff) continue;
|
|
42
|
-
const group = byRecord.get(signal.recordId) ?? [];
|
|
43
|
-
group.push(signal);
|
|
44
|
-
byRecord.set(signal.recordId, group);
|
|
45
|
-
}
|
|
46
|
-
const ranked = records.flatMap((record) => {
|
|
47
|
-
if ((record.sensitivity ?? "normal") !== "normal" && params.sensitiveWritePolicy !== "allow") return [];
|
|
48
|
-
const recallSignals = (byRecord.get(record.id) ?? []).filter((signal) => signal.source === "search_recall" || signal.source === "context_injection");
|
|
49
|
-
const queries = new Set(recallSignals.map((signal) => String(signal.metadata.query ?? "")).filter(Boolean));
|
|
50
|
-
const avgScore = recallSignals.length ? recallSignals.reduce((sum, signal) => sum + (signal.score ?? 0), 0) / recallSignals.length : 0;
|
|
51
|
-
const ageDays = Math.max(0, (now.getTime() - Date.parse(record.updatedAt)) / 864e5);
|
|
52
|
-
const score = Math.max(0, Math.min(1, avgScore * Math.pow(.5, ageDays / cfg.recencyHalfLifeDays)));
|
|
53
|
-
if (recallSignals.length < cfg.minRecallCount || queries.size < cfg.minUniqueQueries || score < cfg.minScore) return [];
|
|
54
|
-
return [{
|
|
55
|
-
recordId: record.id,
|
|
56
|
-
score,
|
|
57
|
-
recallCount: recallSignals.length,
|
|
58
|
-
uniqueQueries: queries.size,
|
|
59
|
-
content: record.content
|
|
60
|
-
}];
|
|
61
|
-
}).sort((left, right) => right.score - left.score).slice(0, cfg.limit);
|
|
62
|
-
const policy = params.mode === "automatic" ? "allow" : params.mode === "review" ? "confirm" : "deny";
|
|
63
|
-
let applied = 0;
|
|
64
|
-
for (const candidate of ranked) {
|
|
65
|
-
const action = policy === "allow" ? "activate" : policy === "confirm" ? "propose" : "observe";
|
|
66
|
-
recordDreamingDecision({
|
|
67
|
-
runId: params.runId,
|
|
68
|
-
recordId: candidate.recordId,
|
|
69
|
-
action,
|
|
70
|
-
reasonCode: "deep_evidence_threshold_met",
|
|
71
|
-
score: candidate.score,
|
|
72
|
-
evidence: {
|
|
73
|
-
recallCount: candidate.recallCount,
|
|
74
|
-
uniqueQueries: candidate.uniqueQueries
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
if (policy === "allow") {
|
|
78
|
-
if (!setMemoryRecordStatus(candidate.recordId, "active", now.getTime())) continue;
|
|
79
|
-
applied += 1;
|
|
80
|
-
appendMemorySignal({
|
|
81
|
-
signal: {
|
|
82
|
-
source: "dreaming",
|
|
83
|
-
recordId: candidate.recordId,
|
|
84
|
-
score: candidate.score,
|
|
85
|
-
content: candidate.content,
|
|
86
|
-
metadata: {
|
|
87
|
-
phase: "deep",
|
|
88
|
-
recallCount: candidate.recallCount,
|
|
89
|
-
uniqueQueries: candidate.uniqueQueries
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
providerId: "local",
|
|
93
|
-
sourceAgentId: params.agentId,
|
|
94
|
-
workspaceId: params.workspaceDir
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const reason = ranked.length === 0 ? "no eligible candidates" : policy === "allow" ? "candidate consolidation complete" : policy === "confirm" ? "candidates retained for user review" : "analysis complete; writes denied by policy";
|
|
99
|
-
trace(params, reason, ranked.map((candidate) => candidate.recordId), applied, started);
|
|
100
|
-
log.info({
|
|
101
|
-
workspaceDir: params.workspaceDir,
|
|
102
|
-
candidates: ranked.length,
|
|
103
|
-
applied,
|
|
104
|
-
policy
|
|
105
|
-
}, "Dreaming deep consolidation complete");
|
|
106
|
-
return {
|
|
107
|
-
ok: true,
|
|
108
|
-
reason,
|
|
109
|
-
candidates: ranked.length,
|
|
110
|
-
applied,
|
|
111
|
-
memoryPath: MEMORY_STORE_URI
|
|
112
|
-
};
|
|
113
|
-
} catch (err) {
|
|
114
|
-
const error = err instanceof Error ? err.message : String(err);
|
|
115
|
-
appendMemoryTraceEvent({
|
|
116
|
-
phase: "dreaming_deep",
|
|
117
|
-
providerId: "local",
|
|
118
|
-
sourceAgentId: params.agentId,
|
|
119
|
-
request: { workspaceId: params.workspaceDir },
|
|
120
|
-
error,
|
|
121
|
-
durationMs: Date.now() - started
|
|
122
|
-
});
|
|
123
|
-
log.error({
|
|
124
|
-
err,
|
|
125
|
-
workspaceDir: params.workspaceDir
|
|
126
|
-
}, `Dreaming deep consolidation failed: ${error}`);
|
|
127
|
-
return {
|
|
128
|
-
ok: false,
|
|
129
|
-
reason: error,
|
|
130
|
-
candidates: 0,
|
|
131
|
-
applied: 0,
|
|
132
|
-
memoryPath: MEMORY_STORE_URI
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function trace(params, reason, selectedRecordIds, applied, started) {
|
|
137
|
-
appendMemoryTraceEvent({
|
|
138
|
-
phase: "dreaming_deep",
|
|
139
|
-
providerId: "local",
|
|
140
|
-
sourceAgentId: params.agentId,
|
|
141
|
-
request: {
|
|
142
|
-
workspaceId: params.workspaceDir,
|
|
143
|
-
reason,
|
|
144
|
-
applied
|
|
145
|
-
},
|
|
146
|
-
resultCount: selectedRecordIds.length,
|
|
147
|
-
selectedRecordIds,
|
|
148
|
-
durationMs: Date.now() - started
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
//#endregion
|
|
152
|
-
export { runDreamingDeepPromotion };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { DreamingLightConfig } from './config.js';
|
|
2
|
-
type LightExecutionConfig = Pick<DreamingLightConfig, 'enabled' | 'lookbackDays' | 'limit'>;
|
|
3
|
-
/** Stage recent structured records as consolidation observations. */
|
|
4
|
-
export declare function runLightSweep(params: {
|
|
5
|
-
runId: string;
|
|
6
|
-
workspaceDir: string;
|
|
7
|
-
config?: Partial<LightExecutionConfig>;
|
|
8
|
-
now?: Date;
|
|
9
|
-
}): Promise<{
|
|
10
|
-
ok: boolean;
|
|
11
|
-
reason: string;
|
|
12
|
-
scannedEntries: number;
|
|
13
|
-
newSignals: number;
|
|
14
|
-
deduped: number;
|
|
15
|
-
}>;
|
|
16
|
-
export {};
|