@vellumai/assistant 0.11.9 → 0.11.10-dev.202609091114.7b6342c
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/ARCHITECTURE.md +2 -2
- package/Dockerfile +6 -12
- package/docs/architecture/memory.md +17 -9
- package/docs/guardian-request-flow.md +7 -4
- package/docs/runbook-trusted-contacts.md +13 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +72 -0
- package/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/openapi.yaml +729 -63
- package/package.json +1 -1
- package/src/__tests__/agent-loop-mutable-latest-user-message.test.ts +19 -21
- package/src/__tests__/assistant-event-hub-machine-name.test.ts +40 -0
- package/src/__tests__/assistant-event-hub.test.ts +45 -0
- package/src/__tests__/cli-memory-v2-reembed-skills.test.ts +0 -1
- package/src/__tests__/compactor-assistant-tail-preview.test.ts +111 -0
- package/src/__tests__/compactor-tail-resolution.test.ts +116 -0
- package/src/__tests__/computer-use-native-history.test.ts +30 -0
- package/src/__tests__/computer-use-window-schema.test.ts +24 -0
- package/src/__tests__/config-get-vision-flag.test.ts +36 -0
- package/src/__tests__/config-loader-validation-reset-notice.test.ts +47 -15
- package/src/__tests__/context-search-conversations-source.test.ts +27 -5
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +189 -195
- package/src/__tests__/conversation-agent-loop.test.ts +690 -50
- package/src/__tests__/conversation-fork-crud.test.ts +132 -45
- package/src/__tests__/conversation-fork-retrospective.test.ts +9 -7
- package/src/__tests__/conversation-lifecycle.test.ts +684 -10
- package/src/__tests__/conversation-pairing.test.ts +10 -9
- package/src/__tests__/conversation-runtime-assembly.test.ts +288 -1
- package/src/__tests__/conversation-surfaces-history-restored-completion.test.ts +21 -4
- package/src/__tests__/conversation-surfaces-point-at-budget.test.ts +150 -0
- package/src/__tests__/conversation-surfaces-point-at-capability.test.ts +161 -0
- package/src/__tests__/copy-composer-tc-templates.test.ts +2 -2
- package/src/__tests__/credential-security-invariants.test.ts +1 -0
- package/src/__tests__/delivered-post-record.test.ts +107 -0
- package/src/__tests__/guardian-action-service-scope.test.ts +53 -0
- package/src/__tests__/guardian-question-mode.test.ts +88 -138
- package/src/__tests__/headless-browser-mode.test.ts +63 -13
- package/src/__tests__/heartbeat-disk-pressure.test.ts +2 -0
- package/src/__tests__/heartbeat-service.test.ts +118 -27
- package/src/__tests__/host-cu-proxy.test.ts +159 -1
- package/src/__tests__/host-proxy-interface.test.ts +15 -0
- package/src/__tests__/host-proxy-preactivation.test.ts +61 -0
- package/src/__tests__/injector-chain.test.ts +3 -3
- package/src/__tests__/injector-registry-order-guard.test.ts +1 -1
- package/src/__tests__/injector-v3-suppression.test.ts +587 -45
- package/src/__tests__/llm-schema.test.ts +70 -2
- package/src/__tests__/logger.test.ts +33 -32
- package/src/__tests__/mcp-config-secret-boundary.test.ts +2 -0
- package/src/__tests__/memory-config-file-parity.test.ts +18 -0
- package/src/__tests__/memory-retrieval-hook.test.ts +53 -3
- package/src/__tests__/messages-read-boundary-guard.test.ts +0 -1
- package/src/__tests__/messaging-send-tool.test.ts +251 -128
- package/src/__tests__/messaging-shared.test.ts +19 -0
- package/src/__tests__/notification-decision-fallback.test.ts +98 -76
- package/src/__tests__/notification-decision-strategy.test.ts +10 -38
- package/src/__tests__/notification-events-source-context-probe.test.ts +211 -0
- package/src/__tests__/openai-responses-prompt-cache.test.ts +7 -2
- package/src/__tests__/openai-responses-provider.test.ts +42 -0
- package/src/__tests__/outlook-messaging-provider.test.ts +9 -0
- package/src/__tests__/platform-callback-registration.test.ts +162 -3
- package/src/__tests__/plugin-api-webhook-url.test.ts +66 -4
- package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -0
- package/src/__tests__/pricing.test.ts +29 -0
- package/src/__tests__/prompt-cache-cross-turn-stability.test.ts +63 -3
- package/src/__tests__/scheduler-result-notification.test.ts +209 -0
- package/src/__tests__/strip-memory-injections.test.ts +75 -27
- package/src/__tests__/tool-approval-seed-content-blocks.test.ts +4 -13
- package/src/acp/auto-install.test.ts +35 -1
- package/src/acp/resolve-agent.test.ts +3 -3
- package/src/agent/loop.ts +116 -45
- package/src/api/constants/personality-sliders.test.ts +21 -0
- package/src/api/constants/personality-sliders.ts +64 -0
- package/src/api/events/contact-record-request.ts +16 -4
- package/src/api/events/contact-request.ts +10 -1
- package/src/api/index.ts +12 -0
- package/src/api/responses/memory-v3-selection-log.ts +64 -13
- package/src/api/surfaces.ts +6 -5
- package/src/background-wake/next-wake.test.ts +13 -0
- package/src/background-wake/next-wake.ts +4 -2
- package/src/calls/__tests__/voice-session-bridge.test.ts +166 -0
- package/src/calls/__tests__/voice-turn-sight-hold.test.ts +301 -0
- package/src/calls/voice-session-bridge.ts +162 -1
- package/src/calls/voice-triage-escalate.ts +1 -1
- package/src/channels/types.ts +14 -0
- package/src/cli/__tests__/catalog-search-help.test.ts +1 -0
- package/src/cli/__tests__/contacts-address-prompt-cli.test.ts +701 -0
- package/src/cli/__tests__/contacts-record-prompt-cli.test.ts +276 -15
- package/src/cli/__tests__/roadmap-cli.test.ts +313 -0
- package/src/cli/__tests__/run-assistant-command.ts +59 -20
- package/src/cli/commands/__tests__/conversations-slack.test.ts +12 -0
- package/src/cli/commands/__tests__/plugins-search.test.ts +81 -0
- package/src/cli/commands/config.help.ts +3 -1
- package/src/cli/commands/contacts.help.ts +179 -12
- package/src/cli/commands/contacts.ts +442 -47
- package/src/cli/commands/memory/worker.ts +1 -1
- package/src/cli/commands/platform/__tests__/credits-format.test.ts +152 -0
- package/src/cli/commands/platform/__tests__/credits.test.ts +20 -0
- package/src/cli/commands/platform/credits-format.ts +108 -0
- package/src/cli/commands/platform/index.help.ts +33 -11
- package/src/cli/commands/platform/index.ts +7 -18
- package/src/cli/commands/plugins.help.ts +4 -1
- package/src/cli/commands/plugins.ts +2 -1
- package/src/cli/commands/roadmap.help.ts +171 -0
- package/src/cli/commands/roadmap.ts +358 -0
- package/src/cli/index.help.ts +2 -0
- package/src/cli/lib/__tests__/cli-output.test.ts +5 -0
- package/src/cli/lib/cli-output.ts +6 -6
- package/src/cli/program.ts +2 -0
- package/src/config/__tests__/webhook-routing.test.ts +42 -0
- package/src/config/acp-defaults.test.ts +3 -3
- package/src/config/acp-defaults.ts +5 -5
- package/src/config/bundled-skills/acp/SKILL.md +8 -11
- package/src/config/bundled-skills/computer-use/SKILL.md +21 -0
- package/src/config/bundled-skills/computer-use/TOOLS.json +6 -0
- package/src/config/bundled-skills/contacts/SKILL.md +61 -11
- package/src/config/bundled-skills/messaging/SKILL.md +2 -0
- package/src/config/bundled-skills/messaging/TOOLS.json +4 -4
- package/src/config/bundled-skills/messaging/tools/messaging-send.ts +160 -36
- package/src/config/bundled-skills/messaging/tools/shared.ts +6 -0
- package/src/config/bundled-skills/schedule/SKILL.md +10 -2
- package/src/config/bundled-skills/screen-annotation/SKILL.md +80 -0
- package/src/config/bundled-skills/screen-annotation/TOOLS.json +73 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-annotation.test.ts +74 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-clear-marks.ts +33 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-point-at.ts +25 -0
- package/src/config/env-registry.ts +2 -0
- package/src/config/feature-flag-registry.json +39 -7
- package/src/config/input-modalities.test.ts +71 -0
- package/src/config/input-modalities.ts +95 -0
- package/src/config/loader.ts +2 -0
- package/src/config/schemas/__tests__/memory-v3.test.ts +58 -15
- package/src/config/schemas/heartbeat.ts +3 -3
- package/src/config/schemas/llm.ts +47 -10
- package/src/config/schemas/memory-storage.test.ts +39 -0
- package/src/config/schemas/memory-storage.ts +21 -0
- package/src/config/schemas/memory-v3.ts +73 -46
- package/src/config/schemas/services.ts +18 -0
- package/src/config/webhook-routing.ts +12 -2
- package/src/context/compactor.ts +12 -13
- package/src/context/strip-injections.ts +29 -25
- package/src/context/token-estimator.ts +2 -2
- package/src/daemon/__tests__/embedding-reconcile.test.ts +77 -0
- package/src/daemon/__tests__/lifecycle-embedding-reconcile.test.ts +3 -0
- package/src/daemon/__tests__/turn-actor.test.ts +68 -0
- package/src/daemon/conversation-agent-loop-handlers.ts +152 -22
- package/src/daemon/conversation-agent-loop.ts +19 -3
- package/src/daemon/conversation-messaging.ts +3 -2
- package/src/daemon/conversation-runtime-assembly.ts +191 -69
- package/src/daemon/conversation-surfaces.ts +32 -62
- package/src/daemon/conversation.ts +153 -46
- package/src/daemon/embedding-reconcile.ts +64 -1
- package/src/daemon/handlers/config-embeddings.ts +31 -0
- package/src/daemon/host-cu-proxy.ts +66 -50
- package/src/daemon/host-cu-target.ts +139 -0
- package/src/daemon/host-proxy-preactivation.ts +29 -1
- package/src/daemon/mcp-reload-service.ts +6 -0
- package/src/daemon/providers-setup.ts +5 -26
- package/src/daemon/trust-context.ts +1 -1
- package/src/daemon/turn-actor.ts +46 -0
- package/src/heartbeat/heartbeat-service.ts +72 -13
- package/src/inbound/platform-callback-registration.ts +77 -11
- package/src/inbound/pod-webhook-claim.ts +35 -0
- package/src/inbound/velay-webhooks-gate.ts +20 -0
- package/src/ipc/gateway-client.ts +91 -0
- package/src/live-voice/__tests__/live-voice-photo.test.ts +174 -0
- package/src/live-voice/__tests__/live-voice-session-guardian.test.ts +127 -0
- package/src/live-voice/__tests__/live-voice-session-telemetry.test.ts +42 -2
- package/src/live-voice/__tests__/live-voice-sight-frame.test.ts +81 -0
- package/src/live-voice/__tests__/protocol.test.ts +67 -0
- package/src/live-voice/live-voice-connection.ts +14 -1
- package/src/live-voice/live-voice-photo.ts +109 -4
- package/src/live-voice/live-voice-session-manager.ts +10 -1
- package/src/live-voice/live-voice-session.ts +196 -31
- package/src/live-voice/protocol.ts +134 -1
- package/src/mcp/__tests__/reload-signal-emission.test.ts +54 -0
- package/src/mcp/__tests__/reload-signal.test.ts +57 -0
- package/src/mcp/__tests__/startup.test.ts +150 -0
- package/src/mcp/reload-signal.ts +50 -0
- package/src/mcp/startup.ts +101 -0
- package/src/messaging/providers/outlook/adapter.ts +2 -13
- package/src/messaging/providers/outlook/client.ts +13 -1
- package/src/messaging/providers/outlook/types.ts +3 -0
- package/src/messaging/providers/telegram-bot/adapter.ts +9 -2
- package/src/messaging/providers/telegram-bot/client.ts +8 -2
- package/src/messaging/providers/whatsapp/adapter.ts +9 -2
- package/src/messaging/providers/whatsapp/client.ts +8 -2
- package/src/notifications/AGENTS.md +5 -0
- package/src/notifications/README.md +21 -7
- package/src/notifications/__tests__/assistant-reply-producer.test.ts +3 -10
- package/src/notifications/__tests__/background-failure-signal.test.ts +96 -0
- package/src/notifications/__tests__/broadcaster.test.ts +171 -7
- package/src/notifications/__tests__/decision-engine.test.ts +79 -6
- package/src/notifications/__tests__/edit-notification.test.ts +59 -0
- package/src/notifications/__tests__/resolve-visible-in-source.test.ts +96 -0
- package/src/notifications/__tests__/schedule-result-producer.test.ts +397 -0
- package/src/notifications/access-request-copy.ts +5 -5
- package/src/notifications/approval-card-data.ts +29 -13
- package/src/notifications/assistant-reply-producer.ts +0 -4
- package/src/notifications/background-failure-signal.ts +13 -1
- package/src/notifications/broadcaster.ts +65 -2
- package/src/notifications/conversation-pairing.ts +263 -155
- package/src/notifications/copy-composer.ts +38 -22
- package/src/notifications/decision-engine.ts +89 -61
- package/src/notifications/delivered-post-record.ts +81 -0
- package/src/notifications/deliveries-store.ts +8 -1
- package/src/notifications/edit-notification.ts +16 -0
- package/src/notifications/events-store.ts +68 -2
- package/src/notifications/guardian-question-mode.ts +24 -232
- package/src/notifications/home-feed-side-effect.ts +1 -0
- package/src/notifications/notification-utils.ts +13 -5
- package/src/notifications/resolve-visible-in-source.ts +56 -0
- package/src/notifications/schedule-result-producer.ts +275 -0
- package/src/notifications/signal.ts +5 -0
- package/src/oauth/__tests__/seed-providers-managed.test.ts +82 -0
- package/src/oauth/seed-providers.ts +201 -3
- package/src/onboarding/onboarding-events-store.ts +14 -8
- package/src/persistence/conversation-crud.ts +68 -19
- package/src/persistence/embeddings/embedding-backend.test.ts +162 -0
- package/src/persistence/embeddings/embedding-backend.ts +148 -11
- package/src/persistence/embeddings/embedding-gemini.test.ts +328 -9
- package/src/persistence/embeddings/embedding-gemini.ts +211 -27
- package/src/persistence/embeddings/embedding-openai.test.ts +113 -0
- package/src/persistence/embeddings/embedding-openai.ts +55 -4
- package/src/persistence/embeddings/embedding-types.test.ts +24 -0
- package/src/persistence/embeddings/embedding-types.ts +25 -1
- package/src/persistence/job-utils.ts +6 -2
- package/src/persistence/message-metadata.ts +20 -0
- package/src/persistence/migrations/283-memory-v3-selections-message-id-and-sections.ts +2 -1
- package/src/persistence/migrations/376-notification-deliveries-canonical-message-id.ts +37 -0
- package/src/persistence/schema/memory-injection.ts +31 -9
- package/src/persistence/schema/notifications.ts +8 -0
- package/src/persistence/steps.ts +2 -0
- package/src/plugin-api/index.ts +2 -1
- package/src/plugin-api/vision-support.test.ts +81 -0
- package/src/plugin-api/vision-support.ts +57 -10
- package/src/plugin-api/webhook-url.ts +18 -4
- package/src/plugins/AGENTS.md +1 -1
- package/src/plugins/defaults/channel/injectors.ts +3 -1
- package/src/plugins/defaults/injector-order.ts +2 -2
- package/src/plugins/defaults/memory/AGENTS.md +263 -30
- package/src/plugins/defaults/memory/__tests__/conversation-memory-orphan-sweep.test.ts +4 -0
- package/src/plugins/defaults/memory/__tests__/conversation-memory-purge.test.ts +6 -0
- package/src/plugins/defaults/memory/__tests__/db-memory-attach.test.ts +9 -3
- package/src/plugins/defaults/memory/__tests__/memory-log-stores-degraded.test.ts +3 -7
- package/src/plugins/defaults/memory/__tests__/relocated-memory-test-rows.ts +18 -0
- package/src/plugins/defaults/memory/context-search/sources/conversations.ts +16 -2
- package/src/plugins/defaults/memory/conversation-memory-purge.ts +2 -0
- package/src/plugins/defaults/memory/fork-conversation-memory.ts +13 -13
- package/src/plugins/defaults/memory/graph/__tests__/conversation-graph-memory-v2-routing.test.ts +19 -12
- package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +17 -15
- package/src/plugins/defaults/memory/graph-topology/build-memory-graph.ts +1 -1
- package/src/plugins/defaults/memory/hooks/__tests__/post-compact.test.ts +121 -0
- package/src/plugins/defaults/memory/hooks/init.ts +10 -0
- package/src/plugins/defaults/memory/hooks/injection-metadata.ts +100 -0
- package/src/plugins/defaults/memory/hooks/post-compact.ts +19 -7
- package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +11 -83
- package/src/plugins/defaults/memory/injectors.ts +4 -4
- package/src/plugins/defaults/memory/job-handlers.ts +4 -1
- package/src/plugins/defaults/memory/jobs/__tests__/embed-concept-page.test.ts +1 -0
- package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +11 -3
- package/src/plugins/defaults/memory/memory-db.ts +4 -0
- package/src/plugins/defaults/memory/memory-marker.ts +28 -17
- package/src/plugins/defaults/memory/src/__tests__/memory-v2-simulate-route.test.ts +0 -1
- package/src/plugins/defaults/memory/src/__tests__/memory-worker-routes.test.ts +20 -0
- package/src/plugins/defaults/memory/src/memory-item-routes.test.ts +0 -1
- package/src/plugins/defaults/memory/src/memory-worker-routes.ts +3 -1
- package/src/plugins/defaults/memory/substrate/__tests__/cli-command-store.test.ts +1 -1
- package/src/plugins/defaults/memory/substrate/__tests__/consolidation-job.test.ts +66 -0
- package/src/plugins/defaults/memory/substrate/__tests__/injected-block-slugs.test.ts +345 -0
- package/src/plugins/defaults/memory/substrate/__tests__/page-index.test.ts +0 -1
- package/src/plugins/defaults/memory/substrate/__tests__/prompts-consolidation.test.ts +170 -1
- package/src/plugins/defaults/memory/substrate/__tests__/reembed-job.test.ts +1 -0
- package/src/plugins/defaults/memory/substrate/capability-slugs.ts +53 -0
- package/src/plugins/defaults/memory/substrate/cli-command-store.ts +4 -18
- package/src/plugins/defaults/memory/substrate/consolidation-job.ts +40 -1
- package/src/plugins/defaults/memory/substrate/ingest.ts +11 -9
- package/src/plugins/defaults/memory/substrate/injected-block-slugs.ts +426 -42
- package/src/plugins/defaults/memory/substrate/page-index.ts +5 -4
- package/src/plugins/defaults/memory/substrate/prompts/consolidation.ts +127 -14
- package/src/plugins/defaults/memory/substrate/skill-store.ts +1 -18
- package/src/plugins/defaults/memory/v2/__tests__/backfill-jobs.test.ts +1 -0
- package/src/plugins/defaults/memory/v2/__tests__/injection.test.ts +2 -8
- package/src/plugins/defaults/memory/v2/__tests__/router.test.ts +0 -1
- package/src/plugins/defaults/memory/v2/injection.ts +4 -4
- package/src/plugins/defaults/memory/v3/__tests__/capabilities.test.ts +16 -0
- package/src/plugins/defaults/memory/v3/__tests__/carry-integration.test.ts +1004 -319
- package/src/plugins/defaults/memory/v3/__tests__/dense.test.ts +227 -4
- package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +836 -263
- package/src/plugins/defaults/memory/v3/__tests__/live-integration.test.ts +65 -38
- package/src/plugins/defaults/memory/v3/__tests__/maintain-job.test.ts +354 -3
- package/src/plugins/defaults/memory/v3/__tests__/orchestrate.test.ts +688 -104
- package/src/plugins/defaults/memory/v3/__tests__/overlong-sections.test.ts +109 -0
- package/src/plugins/defaults/memory/v3/__tests__/page-content.test.ts +144 -0
- package/src/plugins/defaults/memory/v3/__tests__/plugin-schema.test.ts +534 -0
- package/src/plugins/defaults/memory/v3/__tests__/pool-log-store.test.ts +449 -0
- package/src/plugins/defaults/memory/v3/__tests__/pool-select.test.ts +265 -27
- package/src/plugins/defaults/memory/v3/__tests__/render-injection.test.ts +34 -117
- package/src/plugins/defaults/memory/v3/__tests__/section-dense-store.test.ts +491 -4
- package/src/plugins/defaults/memory/v3/__tests__/section-needle.test.ts +124 -1
- package/src/plugins/defaults/memory/v3/__tests__/sections.test.ts +264 -4
- package/src/plugins/defaults/memory/v3/__tests__/selection-log-store.test.ts +560 -22
- package/src/plugins/defaults/memory/v3/__tests__/shadow-integration.test.ts +40 -33
- package/src/plugins/defaults/memory/v3/__tests__/shadow-plugin.test.ts +718 -63
- package/src/plugins/defaults/memory/v3/__tests__/types.test.ts +83 -2
- package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
- package/src/plugins/defaults/memory/v3/capabilities.ts +90 -14
- package/src/plugins/defaults/memory/v3/card.test.ts +15 -16
- package/src/plugins/defaults/memory/v3/card.ts +16 -15
- package/src/plugins/defaults/memory/v3/dense.ts +10 -0
- package/src/plugins/defaults/memory/v3/ever-injected-store.test.ts +643 -140
- package/src/plugins/defaults/memory/v3/ever-injected-store.ts +462 -212
- package/src/plugins/defaults/memory/v3/hot-set.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/injector.ts +366 -278
- package/src/plugins/defaults/memory/v3/learned-edges.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/maintain-job.ts +299 -73
- package/src/plugins/defaults/memory/v3/orchestrate.ts +327 -214
- package/src/plugins/defaults/memory/v3/overlong-sections.ts +83 -0
- package/src/plugins/defaults/memory/v3/page-content.ts +72 -92
- package/src/plugins/defaults/memory/v3/plugin-schema.ts +346 -0
- package/src/plugins/defaults/memory/v3/pool-log-store.ts +291 -0
- package/src/plugins/defaults/memory/v3/pool-select.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/pool-select.ts +160 -60
- package/src/plugins/defaults/memory/v3/prune.test.ts +1042 -329
- package/src/plugins/defaults/memory/v3/prune.ts +433 -270
- package/src/plugins/defaults/memory/v3/rare-term-lane.test.ts +269 -0
- package/src/plugins/defaults/memory/v3/rare-term-lane.ts +141 -0
- package/src/plugins/defaults/memory/v3/render-injection.ts +43 -82
- package/src/plugins/defaults/memory/v3/section-dense-store.ts +316 -28
- package/src/plugins/defaults/memory/v3/section-needle.ts +145 -11
- package/src/plugins/defaults/memory/v3/sections.ts +103 -16
- package/src/plugins/defaults/memory/v3/selection-log-store.ts +243 -78
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +189 -68
- package/src/plugins/defaults/memory/v3/tuning-profile.ts +6 -0
- package/src/plugins/defaults/memory/v3/types.ts +169 -23
- package/src/plugins/defaults/memory/v3-eval/__tests__/eval-packets.test.ts +21 -4
- package/src/plugins/defaults/memory/v3-eval/eval-packets.ts +77 -26
- package/src/plugins/types.ts +14 -0
- package/src/providers/__tests__/connection-model-compat.test.ts +1 -0
- package/src/providers/__tests__/provider-secret-catalog.test.ts +4 -0
- package/src/providers/__tests__/xml-tool-call-salvage.test.ts +172 -0
- package/src/providers/inline-audio-support.test.ts +34 -0
- package/src/providers/inline-audio-support.ts +27 -0
- package/src/providers/model-catalog.ts +102 -0
- package/src/providers/openai/__tests__/chat-completions-extra-body.test.ts +51 -0
- package/src/providers/openai/__tests__/chat-completions-provider-xml-salvage.test.ts +291 -0
- package/src/providers/openai/chat-completions-provider.ts +114 -14
- package/src/providers/openai/codex-models.ts +1 -0
- package/src/providers/openai/responses-provider.ts +65 -15
- package/src/providers/opencode/client.test.ts +24 -0
- package/src/providers/opencode/client.ts +6 -1
- package/src/providers/provider-secret-catalog.ts +11 -1
- package/src/providers/retry.ts +6 -0
- package/src/providers/vellum/client.ts +14 -1
- package/src/providers/vellum/personality-directions.test.ts +163 -0
- package/src/providers/vellum/personality-directions.ts +120 -0
- package/src/providers/xml-tool-call-salvage.ts +212 -0
- package/src/runtime/AGENTS.md +7 -2
- package/src/runtime/__tests__/background-job-runner.test.ts +115 -0
- package/src/runtime/__tests__/guardian-form-registry.test.ts +0 -32
- package/src/runtime/__tests__/host-observe.test.ts +44 -0
- package/src/runtime/assistant-event-hub.ts +14 -9
- package/src/runtime/auth/__tests__/guard-tests.test.ts +1 -4
- package/src/runtime/auth/__tests__/route-policy.test.ts +65 -0
- package/src/runtime/auth/same-actor.ts +4 -3
- package/src/runtime/background-job-runner.ts +10 -0
- package/src/runtime/channel-reply-delivery.ts +1 -162
- package/src/runtime/guardian-action-service.ts +20 -1
- package/src/runtime/host-observe.ts +56 -6
- package/src/runtime/http-server.ts +35 -0
- package/src/runtime/outbound-post-reconciliation.ts +183 -0
- package/src/runtime/routes/__tests__/contact-address-prompt-route.test.ts +231 -0
- package/src/runtime/routes/__tests__/contact-record-prompt-route.test.ts +59 -3
- package/src/runtime/routes/__tests__/guardian-form-routes.test.ts +85 -0
- package/src/runtime/routes/__tests__/heartbeat-routes.test.ts +24 -0
- package/src/runtime/routes/__tests__/platform-credits-routes.test.ts +239 -0
- package/src/runtime/routes/__tests__/roadmap-routes.test.ts +469 -0
- package/src/runtime/routes/__tests__/watch-routes.test.ts +70 -1
- package/src/runtime/routes/__tests__/webhook-routes.test.ts +83 -0
- package/src/runtime/routes/contact-prompt-routes.ts +177 -28
- package/src/runtime/routes/conversation-query-routes.ts +53 -11
- package/src/runtime/routes/events-routes.ts +13 -3
- package/src/runtime/routes/guardian-action-routes.ts +7 -0
- package/src/runtime/routes/guardian-form-routes.ts +6 -4
- package/src/runtime/routes/heartbeat-routes.ts +41 -53
- package/src/runtime/routes/index.ts +2 -2
- package/src/runtime/routes/integrations/a2a.ts +12 -3
- package/src/runtime/routes/integrations/vercel.ts +13 -3
- package/src/runtime/routes/platform-routes.ts +175 -23
- package/src/runtime/routes/roadmap-routes.ts +744 -0
- package/src/runtime/routes/watch-routes.ts +50 -0
- package/src/runtime/routes/webhook-routes.ts +24 -2
- package/src/runtime/web-presence.ts +13 -9
- package/src/schedule/__tests__/schedule-timezone.test.ts +21 -3
- package/src/schedule/__tests__/worker-mcp-tools.test.ts +88 -0
- package/src/schedule/schedule-timezone.ts +25 -0
- package/src/schedule/scheduler.ts +19 -0
- package/src/schedule/worker.ts +119 -2
- package/src/telemetry/__tests__/live-voice-funnel.test.ts +32 -0
- package/src/telemetry/live-voice-funnel.ts +33 -0
- package/src/tools/acp/list-agents.test.ts +1 -1
- package/src/tools/browser/__tests__/browser-status.test.ts +3 -0
- package/src/tools/browser/browser-execution.ts +117 -53
- package/src/tools/browser/browser-status-constants.ts +6 -6
- package/src/tools/capability-offer.test.ts +87 -0
- package/src/tools/capability-offer.ts +93 -0
- package/src/tools/computer-use/definitions.ts +6 -0
- package/src/tools/computer-use/skill-proxy-bridge.ts +10 -0
- package/src/tools/terminal/safe-env.ts +2 -0
- package/src/watch/__tests__/watch-retro.test.ts +11 -10
- package/src/watch/__tests__/watch-session-manager.test.ts +75 -1
- package/src/watch/watch-retro.ts +10 -9
- package/src/watch/watch-session-manager.ts +17 -0
- package/src/runtime/routes/__tests__/sight-frame-routes.test.ts +0 -487
- package/src/runtime/routes/sight-frame-routes.ts +0 -136
|
@@ -1,64 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The memory-v3 {@link Injector}s: frozen net-new
|
|
2
|
+
* The memory-v3 {@link Injector}s: frozen net-new sections + per-turn pointer.
|
|
3
3
|
*
|
|
4
4
|
* Two injectors share one orchestration result per turn (memoized via
|
|
5
|
-
* {@link observeTurnOnce} so re-entry assemblies
|
|
6
|
-
* post-compaction re-injection
|
|
5
|
+
* {@link observeTurnOnce}, so re-entry assemblies, overflow convergence and
|
|
6
|
+
* post-compaction re-injection, reuse the turn's selections instead of
|
|
7
7
|
* re-running the selector):
|
|
8
8
|
*
|
|
9
9
|
* - {@link memoryV3Injector} (id `memory-v3`, `after-memory-prefix`): the
|
|
10
|
-
* PERSISTENT layer.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
10
|
+
* PERSISTENT layer. The injection unit is the SECTION: each selected page
|
|
11
|
+
* contributes every section selected for it, or its lead when it was
|
|
12
|
+
* selected with none (a capability slug contributes its whole capability
|
|
13
|
+
* content). It renders only this turn's NET-NEW units, the pairs
|
|
14
|
+
* `(slug, section key)` not already active in the section store, inside
|
|
15
|
+
* one `<memory>` block. The resident pairs are stamped with the turn's
|
|
16
|
+
* selection time (`touchSelected`, the prune valve's recency); the
|
|
17
|
+
* net-new record (`recordInjected`) and the valve schedule are DEFERRED
|
|
18
|
+
* to a commit callback the block carries
|
|
19
|
+
* (`meta[MEMORY_V3_COMMIT_META_KEY]`), which runtime assembly invokes
|
|
20
|
+
* only when the block attached to a user tail, so a block that fails to
|
|
21
|
+
* attach never claims its sections (which would suppress them until
|
|
22
|
+
* compaction). The user-prompt-submit hook persists the unwrapped text
|
|
23
|
+
* under `metadata.memoryV3InjectedBlock` and `conversation.ts` rehydrates
|
|
24
|
+
* it on load. The block is FROZEN thereafter: prior turns' blocks stay
|
|
25
|
+
* byte-identical in history, ride the provider's cached prefix, and
|
|
26
|
+
* survive restarts, mirroring v2's `memoryInjectedBlock`. An all-repeat
|
|
27
|
+
* turn returns an EMPTY-TEXT block: assembly attaches nothing, but its
|
|
28
|
+
* presence keys v2 suppression. A `null` return (failure, empty
|
|
29
|
+
* selection, every net-new section rendered empty) attaches no v3 block,
|
|
30
|
+
* and since the hook skips v2 retrieval under `memory-v3-live` the turn
|
|
31
|
+
* gets no NEW injected memory (prior turns' frozen sections still ride
|
|
32
|
+
* history).
|
|
31
33
|
*
|
|
32
|
-
* - {@link
|
|
33
|
-
* `after-memory-prefix`): the per-turn
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
34
|
+
* - {@link memoryV3PointerInjector} (id `memory-v3-pointer`,
|
|
35
|
+
* `after-memory-prefix`): the per-turn pointer layer. Lists this turn's
|
|
36
|
+
* selected sections that are ALREADY resident in history as a
|
|
37
|
+
* `<memory_pointer>` block of `memory/concepts/<slug>.md § <key>` lines,
|
|
38
|
+
* no bodies, so the model knows which frozen sections the turn is about.
|
|
39
|
+
* The entries are re-validated against the section store at render time:
|
|
40
|
+
* a pair the valve tombstoned since classification is dropped (it
|
|
41
|
+
* re-injects on its next selection), and with nothing left no block is
|
|
42
|
+
* emitted. Runtime assembly splices the block right after any frozen
|
|
43
|
+
* `<memory>` sections; the hook persists the wrapped text under
|
|
44
|
+
* `metadata.memoryV3PointerBlock` and `conversation.ts` rehydrates it.
|
|
45
|
+
* Historical user messages keep the pointer they were sent with, so the
|
|
46
|
+
* prefix through them stays byte-identical; re-entry and post-compaction
|
|
47
|
+
* assemblies tail-strip the current pointer before splicing a fresh one.
|
|
45
48
|
*
|
|
46
49
|
* Gating: `memory.v3.live` (config) runs orchestration and attaches blocks;
|
|
47
|
-
* with it off,
|
|
50
|
+
* with it off, nothing runs and nothing is attached. Both injectors apply
|
|
51
|
+
* the personal-memory trust gate ({@link isPersonalMemoryAllowed}): an
|
|
52
|
+
* untrusted remote actor's turn produces, records, and persists nothing,
|
|
53
|
+
* since v3 blocks are persisted to message metadata and rehydrated forever.
|
|
48
54
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* Known mirror-of-v2 limitation: cards attached by mid-turn re-entry
|
|
58
|
-
* assemblies (post-compaction re-injection) live only in memory — metadata is
|
|
59
|
-
* persisted at the first-call site only — so a restart drops them while the
|
|
60
|
-
* store still claims them, exactly as v2's `lastInjectedBlock` reinject does.
|
|
61
|
-
* The next compaction clears the store and resets both layers.
|
|
55
|
+
* A re-entry assembly (the post-compaction hook, which also serves the
|
|
56
|
+
* overflow ladder's rungs) attaches its blocks in memory only: metadata is
|
|
57
|
+
* persisted at the first-call site alone, and every message a re-entry
|
|
58
|
+
* attaches to predates a compaction's `historyStrippedAt` marker, which
|
|
59
|
+
* keeps `loadFromDb` from rehydrating it. How a re-entry, and an assembly
|
|
60
|
+
* whose run messages a transcript replaces, classify the turn's units is
|
|
61
|
+
* documented at the partition in {@link memoryV3Injector}.
|
|
62
62
|
*/
|
|
63
63
|
|
|
64
64
|
import { getConfig } from "../../../../config/loader.js";
|
|
@@ -70,6 +70,7 @@ import {
|
|
|
70
70
|
type PendingConversationNotice,
|
|
71
71
|
queueConversationNotice,
|
|
72
72
|
} from "../../../../daemon/conversation-notices.js";
|
|
73
|
+
import { findConversationOrSubagent } from "../../../../daemon/conversation-registry.js";
|
|
73
74
|
import { isPersonalMemoryAllowed } from "../../../../daemon/trust-context.js";
|
|
74
75
|
import {
|
|
75
76
|
type InjectionBlock,
|
|
@@ -77,63 +78,105 @@ import {
|
|
|
77
78
|
type TurnContext,
|
|
78
79
|
} from "../../../types.js";
|
|
79
80
|
import { getLogger } from "../logging.js";
|
|
80
|
-
import { wrapMemoryBlock,
|
|
81
|
-
import {
|
|
82
|
-
import {
|
|
83
|
-
|
|
81
|
+
import { wrapMemoryBlock, wrapMemoryPointerBlock } from "../memory-marker.js";
|
|
82
|
+
import { renderedBytes } from "../substrate/injected-block-slugs.js";
|
|
83
|
+
import {
|
|
84
|
+
type InjectionUnit,
|
|
85
|
+
injectionUnits,
|
|
86
|
+
isCapabilitySlug,
|
|
87
|
+
} from "./capabilities.js";
|
|
88
|
+
import {
|
|
89
|
+
getActiveSections,
|
|
90
|
+
getPrunedSections,
|
|
91
|
+
recordInjected,
|
|
92
|
+
sectionRefSetHas,
|
|
93
|
+
touchSelected,
|
|
94
|
+
} from "./ever-injected-store.js";
|
|
84
95
|
import type { OrchestrateResult } from "./orchestrate.js";
|
|
85
|
-
import {
|
|
96
|
+
import { renderV3InjectionEntry } from "./page-content.js";
|
|
86
97
|
import { MemoryV3RetrievalUnavailableError } from "./pool-select.js";
|
|
87
98
|
import { schedulePruneValve } from "./prune.js";
|
|
88
99
|
import {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
type SpotlightEntry,
|
|
100
|
+
renderInjectionBlockInner,
|
|
101
|
+
renderPointerInner,
|
|
92
102
|
} from "./render-injection.js";
|
|
93
103
|
import { observeTurn } from "./shadow-plugin.js";
|
|
94
104
|
import {
|
|
95
105
|
MEMORY_V3_BLOCK_ID,
|
|
96
106
|
MEMORY_V3_COMMIT_META_KEY,
|
|
97
|
-
|
|
107
|
+
MEMORY_V3_POINTER_BLOCK_ID,
|
|
108
|
+
type SectionRef,
|
|
98
109
|
type Slug,
|
|
99
110
|
} from "./types.js";
|
|
100
111
|
|
|
101
112
|
const log = getLogger("memory-v3-shadow");
|
|
102
113
|
|
|
103
114
|
/**
|
|
104
|
-
* Cap on the per-conversation
|
|
105
|
-
*
|
|
106
|
-
* re-runs orchestration
|
|
115
|
+
* Cap on the per-conversation memo below, counted over IDLE conversations:
|
|
116
|
+
* the least-recently-touched idle entry is evicted first, and an evicted
|
|
117
|
+
* conversation simply re-runs orchestration on its next turn. A memo whose
|
|
118
|
+
* turn is still running is never evicted ({@link turnInFlight}), whatever
|
|
119
|
+
* the number of other conversations touching the process: a later re-entry
|
|
120
|
+
* of that turn re-emits the memo's rendered entries, and without them it
|
|
121
|
+
* would read the turn's committed sections as resident and emit pointers
|
|
122
|
+
* for bodies the re-injection strip cleared. The map can therefore exceed
|
|
123
|
+
* the cap by the number of turns in flight, never by idle entries, and the
|
|
124
|
+
* touches that follow such a burst, inserts and refreshes alike, evict idle
|
|
125
|
+
* entries until it fits again.
|
|
107
126
|
*/
|
|
108
127
|
const MAX_TRACKED_CONVERSATIONS = 256;
|
|
128
|
+
let trackedConversationsCap = MAX_TRACKED_CONVERSATIONS;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Whether the conversation's turn is running: the live conversation's
|
|
132
|
+
* processing flag, set at turn start and cleared in the agent loop's
|
|
133
|
+
* `finally`, which is the window every re-entry assembly runs in. A
|
|
134
|
+
* conversation the registry does not hold, or a registry double without the
|
|
135
|
+
* method, reads as idle.
|
|
136
|
+
*/
|
|
137
|
+
function turnInFlight(conversationId: string): boolean {
|
|
138
|
+
const conversation = findConversationOrSubagent(conversationId);
|
|
139
|
+
return (
|
|
140
|
+
typeof conversation?.isProcessing === "function" &&
|
|
141
|
+
conversation.isProcessing()
|
|
142
|
+
);
|
|
143
|
+
}
|
|
109
144
|
|
|
110
145
|
/**
|
|
111
146
|
* LRU-set `key` on `map`: delete-then-set so a re-touched key moves to the
|
|
112
147
|
* back of the Map's insertion order (a plain `set` on an existing key keeps
|
|
113
148
|
* its original position, which would evict the most long-lived ACTIVE
|
|
114
|
-
* conversation first). Eviction
|
|
115
|
-
* key at the cap
|
|
149
|
+
* conversation first). Eviction fires on any touch, an insert or a refresh
|
|
150
|
+
* of a tracked key, that finds the rest of the map at the cap, and takes
|
|
151
|
+
* the least-recently-touched entries whose turn is not in flight.
|
|
116
152
|
*/
|
|
117
153
|
function lruSet<V>(map: Map<string, V>, key: string, value: V): void {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
154
|
+
map.delete(key);
|
|
155
|
+
// Evict idle entries, least recently touched first, until the entry fits
|
|
156
|
+
// the cap: a burst of turns in flight can carry the map past it, and the
|
|
157
|
+
// touches that follow bring it back once they finish. A refresh evicts
|
|
158
|
+
// like an insert, since after a burst the only conversations still
|
|
159
|
+
// active may all be tracked already.
|
|
160
|
+
for (const candidate of map.keys()) {
|
|
161
|
+
if (map.size < trackedConversationsCap) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
if (!turnInFlight(candidate)) {
|
|
165
|
+
map.delete(candidate);
|
|
124
166
|
}
|
|
125
167
|
}
|
|
126
168
|
map.set(key, value);
|
|
127
169
|
}
|
|
128
170
|
|
|
171
|
+
/** Test-only: the memo's current size. */
|
|
172
|
+
export function memoryV3TurnMemoSizeForTests(): number {
|
|
173
|
+
return observedTurns.size;
|
|
174
|
+
}
|
|
175
|
+
|
|
129
176
|
function queueMemoryV3ConversationNotice(
|
|
130
177
|
err: MemoryV3RetrievalUnavailableError,
|
|
131
178
|
ctx: TurnContext,
|
|
132
|
-
live: boolean,
|
|
133
179
|
): void {
|
|
134
|
-
if (!live) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
180
|
const notice: PendingConversationNotice = err.conversationNotice ?? {
|
|
138
181
|
source: "memory_v3",
|
|
139
182
|
code: "UNKNOWN",
|
|
@@ -148,11 +191,38 @@ function queueMemoryV3ConversationNotice(
|
|
|
148
191
|
);
|
|
149
192
|
}
|
|
150
193
|
|
|
194
|
+
/**
|
|
195
|
+
* The gates both injectors share: memory on, v3 live, a trusted actor, and
|
|
196
|
+
* not the voice front door (which keeps carried sections from history but
|
|
197
|
+
* defers current-turn retrieval to the escalated leg so memory cannot delay
|
|
198
|
+
* its first token).
|
|
199
|
+
*/
|
|
200
|
+
function turnIsEligible(ctx: TurnContext): boolean {
|
|
201
|
+
const config = getConfig();
|
|
202
|
+
if (!isMemoryEnabled(config) || !isMemoryV3Live(config)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
if (!isPersonalMemoryAllowed(ctx.trust)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return ctx.callSite !== "voiceFrontDoor";
|
|
209
|
+
}
|
|
210
|
+
|
|
151
211
|
// ─── shared per-turn orchestration memo ─────────────────────────────────────
|
|
152
212
|
|
|
153
213
|
interface ObservedTurn {
|
|
154
214
|
turnIndex: number;
|
|
155
215
|
result: Promise<OrchestrateResult | null>;
|
|
216
|
+
/** The resident sections this turn's latest sections-produce pointed at,
|
|
217
|
+
* rendered by the pointer injector (which runs after it). */
|
|
218
|
+
pointer?: SectionRef[];
|
|
219
|
+
/** The entries the turn's FIRST produce rendered net-new (the ones its
|
|
220
|
+
* commit recorded), by slug and section key. A re-entry assembly within
|
|
221
|
+
* the turn re-emits them byte for byte instead of partitioning them
|
|
222
|
+
* against the store, which counts them active although their only copy
|
|
223
|
+
* rode the tail the re-injection strip cleared. Set even when empty, so
|
|
224
|
+
* a re-entry is recognised as one. */
|
|
225
|
+
rendered?: ReadonlyMap<Slug, ReadonlyMap<string, string>>;
|
|
156
226
|
}
|
|
157
227
|
|
|
158
228
|
/** Latest observed turn per conversation (both injectors + re-entry sites
|
|
@@ -161,7 +231,7 @@ const observedTurns = new Map<string, ObservedTurn>();
|
|
|
161
231
|
|
|
162
232
|
/**
|
|
163
233
|
* Run {@link observeTurn} once per (conversation, turn) and memoize the
|
|
164
|
-
* promise. The
|
|
234
|
+
* promise. The sections and pointer injectors both consume the result, and
|
|
165
235
|
* re-entry assemblies within the same turn (overflow convergence,
|
|
166
236
|
* post-compaction re-injection) reuse the turn's selections rather than
|
|
167
237
|
* paying a second selector call. A new `turnIndex` replaces the entry, so the
|
|
@@ -180,97 +250,64 @@ function observeTurnOnce(
|
|
|
180
250
|
return result;
|
|
181
251
|
}
|
|
182
252
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
253
|
+
function observedTurn(
|
|
254
|
+
conversationId: string,
|
|
255
|
+
turnIndex: number,
|
|
256
|
+
): ObservedTurn | undefined {
|
|
257
|
+
const cached = observedTurns.get(conversationId);
|
|
258
|
+
return cached && cached.turnIndex === turnIndex ? cached : undefined;
|
|
188
259
|
}
|
|
189
260
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
* spotlight too.
|
|
199
|
-
*/
|
|
200
|
-
function computeSpotlightEntries(
|
|
201
|
-
result: OrchestrateResult,
|
|
202
|
-
n: number,
|
|
203
|
-
): SpotlightEntry[] {
|
|
204
|
-
const selected = new Set<Slug>(result.selections.map((s) => s.slug));
|
|
205
|
-
const entries: SpotlightEntry[] = [];
|
|
206
|
-
for (const candidate of result.lanes.finder) {
|
|
207
|
-
if (entries.length >= n) {
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
if (!selected.has(candidate.slug)) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
// Capability slugs never spotlight: their card already carries the whole
|
|
214
|
-
// injection form, and their index "sections" are slices of the full-help
|
|
215
|
-
// body the injection layer deliberately keeps out of context.
|
|
216
|
-
if (isCapabilitySlug(candidate.slug)) {
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
const section = result.matchedSections.get(candidate.slug);
|
|
220
|
-
if (!section) {
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
entries.push({
|
|
224
|
-
slug: candidate.slug,
|
|
225
|
-
title: section.title,
|
|
226
|
-
text: section.text,
|
|
227
|
-
});
|
|
261
|
+
function rememberPointerEntries(
|
|
262
|
+
conversationId: string,
|
|
263
|
+
turnIndex: number,
|
|
264
|
+
entries: SectionRef[],
|
|
265
|
+
): void {
|
|
266
|
+
const cached = observedTurn(conversationId, turnIndex);
|
|
267
|
+
if (cached) {
|
|
268
|
+
cached.pointer = entries;
|
|
228
269
|
}
|
|
229
|
-
return entries;
|
|
230
270
|
}
|
|
231
271
|
|
|
232
|
-
|
|
233
|
-
* Fold this turn's entries into the conversation's ring and return the
|
|
234
|
-
* rendered window: current turn first, then previous turns newest-first,
|
|
235
|
-
* deduped by slug § heading, bounded by `n × (windowTurns + 1)` entries by
|
|
236
|
-
* construction. Re-observing the SAME turn (re-entry assembly) replaces that
|
|
237
|
-
* turn's entry rather than accumulating.
|
|
238
|
-
*/
|
|
239
|
-
function updateSpotlightWindow(
|
|
272
|
+
function rememberRendered(
|
|
240
273
|
conversationId: string,
|
|
241
274
|
turnIndex: number,
|
|
242
|
-
entries:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
for (const entry of turn.entries) {
|
|
255
|
-
const key = `${entry.slug}§${entry.title}`;
|
|
256
|
-
if (seen.has(key)) {
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
seen.add(key);
|
|
260
|
-
window.push(entry);
|
|
275
|
+
entries: ReadonlyArray<SectionRef & { text: string }>,
|
|
276
|
+
): void {
|
|
277
|
+
const cached = observedTurn(conversationId, turnIndex);
|
|
278
|
+
if (!cached) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const rendered = new Map<Slug, Map<string, string>>();
|
|
282
|
+
for (const { slug, key, text } of entries) {
|
|
283
|
+
let keys = rendered.get(slug);
|
|
284
|
+
if (!keys) {
|
|
285
|
+
keys = new Map();
|
|
286
|
+
rendered.set(slug, keys);
|
|
261
287
|
}
|
|
288
|
+
keys.set(key, text);
|
|
262
289
|
}
|
|
263
|
-
|
|
290
|
+
cached.rendered = rendered;
|
|
264
291
|
}
|
|
265
292
|
|
|
266
|
-
/** Test-only reset for the per-turn memo and
|
|
267
|
-
|
|
293
|
+
/** Test-only reset for the per-turn memo and its cap; a `capacity` shrinks
|
|
294
|
+
* the cap so eviction is reachable with a handful of conversations. */
|
|
295
|
+
export function resetMemoryV3InjectorStateForTests(
|
|
296
|
+
capacity: number = MAX_TRACKED_CONVERSATIONS,
|
|
297
|
+
): void {
|
|
268
298
|
observedTurns.clear();
|
|
269
|
-
|
|
299
|
+
trackedConversationsCap = capacity;
|
|
270
300
|
}
|
|
271
301
|
|
|
272
302
|
// ─── injectors ───────────────────────────────────────────────────────────────
|
|
273
303
|
|
|
304
|
+
/** One unit this assembly's block carries, in selection order: `text` is
|
|
305
|
+
* the first produce's entry when re-emitted by a re-entry, and is rendered
|
|
306
|
+
* here otherwise. */
|
|
307
|
+
interface BlockSlot extends InjectionUnit {
|
|
308
|
+
text: string | undefined;
|
|
309
|
+
}
|
|
310
|
+
|
|
274
311
|
export const memoryV3Injector: Injector = {
|
|
275
312
|
name: "memory-v3-shadow",
|
|
276
313
|
// High order so it sorts last; the live `<memory>` block uses the
|
|
@@ -278,20 +315,7 @@ export const memoryV3Injector: Injector = {
|
|
|
278
315
|
// of this sort key, which only orders content-producing injectors.
|
|
279
316
|
order: 1000,
|
|
280
317
|
async produce(ctx: TurnContext): Promise<InjectionBlock | null> {
|
|
281
|
-
|
|
282
|
-
if (!isMemoryEnabled(config)) {
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
const live = isMemoryV3Live(config);
|
|
286
|
-
if (!live) {
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
if (!isPersonalMemoryAllowed(ctx.trust)) {
|
|
290
|
-
return null;
|
|
291
|
-
}
|
|
292
|
-
// The front door keeps carried cards from history but defers current-turn
|
|
293
|
-
// retrieval to the escalated leg so memory cannot delay its first token.
|
|
294
|
-
if (ctx.callSite === "voiceFrontDoor") {
|
|
318
|
+
if (!turnIsEligible(ctx)) {
|
|
295
319
|
return null;
|
|
296
320
|
}
|
|
297
321
|
|
|
@@ -300,7 +324,7 @@ export const memoryV3Injector: Injector = {
|
|
|
300
324
|
observed = await observeTurnOnce(ctx.conversationId, ctx.turnIndex);
|
|
301
325
|
} catch (err) {
|
|
302
326
|
if (err instanceof MemoryV3RetrievalUnavailableError) {
|
|
303
|
-
queueMemoryV3ConversationNotice(err, ctx
|
|
327
|
+
queueMemoryV3ConversationNotice(err, ctx);
|
|
304
328
|
log.error(
|
|
305
329
|
{
|
|
306
330
|
err: err.message,
|
|
@@ -314,8 +338,8 @@ export const memoryV3Injector: Injector = {
|
|
|
314
338
|
}
|
|
315
339
|
// Empty selection → return null (attach nothing). The user-prompt-submit
|
|
316
340
|
// hook skipped v2 retrieval under live, so a turn with nothing selected
|
|
317
|
-
// simply gets no v3 `<memory>` block (prior turns' frozen
|
|
318
|
-
// history).
|
|
341
|
+
// simply gets no v3 `<memory>` block (prior turns' frozen sections still
|
|
342
|
+
// ride history).
|
|
319
343
|
if (!observed || observed.selections.length === 0) {
|
|
320
344
|
return null;
|
|
321
345
|
}
|
|
@@ -324,72 +348,169 @@ export const memoryV3Injector: Injector = {
|
|
|
324
348
|
const result = observed;
|
|
325
349
|
|
|
326
350
|
try {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
351
|
+
// Partition this turn's injection units: each selected section under
|
|
352
|
+
// its own key, a page selected with none under `""` (its lead;
|
|
353
|
+
// capability content injects whole under `""` too).
|
|
354
|
+
// - A pair tombstoned since the turn's first produce is skipped: a
|
|
355
|
+
// re-entry never revives what the valve pruned.
|
|
356
|
+
// - On a re-entry assembly (`rendered` set by the first produce) an
|
|
357
|
+
// entry the first produce rendered is re-emitted from the memo byte
|
|
358
|
+
// for byte: the store counts it active, but its only copy rode the
|
|
359
|
+
// tail the re-injection strip cleared, so the store alone would
|
|
360
|
+
// read it as resident and drop it for the rest of the turn. A
|
|
361
|
+
// re-entry block carries no commit (and runtime assembly withholds
|
|
362
|
+
// one on a `reinjection` assembly besides), so a turn's sections
|
|
363
|
+
// are recorded once, at the first-call site; after a compaction they
|
|
364
|
+
// stay unclaimed until the next turn injects them net-new onto its
|
|
365
|
+
// own persisted message, and the newest-copy rule
|
|
366
|
+
// (`stripPrunedSectionsFromMessages`) retires the re-entry copy.
|
|
367
|
+
// - A pair active in the store is resident: a pointer entry, stamped
|
|
368
|
+
// with the turn's selection time below. Capability slugs are
|
|
369
|
+
// stamped too but left out of the pointer (no `memory/concepts/`
|
|
370
|
+
// path to point at).
|
|
371
|
+
// - Every other pair renders net-new, including one the first produce
|
|
372
|
+
// saw resident whose copy a compaction's store reset has since
|
|
373
|
+
// unclaimed (neither active nor tombstoned), in memory only.
|
|
374
|
+
// Under a run-messages replacement (`ctx.replacesRunMessages`: the
|
|
375
|
+
// Slack chronological transcript, rendered from persisted rows, so it
|
|
376
|
+
// carries no earlier turn's block) residency means nothing. The
|
|
377
|
+
// store's active set is not consulted, every pair renders or
|
|
378
|
+
// re-emits, none is pointed at, and the block carries no commit, so
|
|
379
|
+
// nothing is recorded or scheduled and runtime assembly attaches the
|
|
380
|
+
// block in memory only as the prompt's single copy. A Slack
|
|
381
|
+
// conversation whose transcript injector is absent is not replaced and
|
|
382
|
+
// injects as an ordinary committed turn.
|
|
383
|
+
const rendered = observedTurn(
|
|
384
|
+
ctx.conversationId,
|
|
385
|
+
ctx.turnIndex,
|
|
386
|
+
)?.rendered;
|
|
387
|
+
const firstProduce = rendered === undefined;
|
|
388
|
+
const replaced = ctx.replacesRunMessages === true;
|
|
389
|
+
const active = replaced ? null : getActiveSections(ctx.conversationId);
|
|
390
|
+
const pruned = firstProduce
|
|
391
|
+
? undefined
|
|
392
|
+
: getPrunedSections(ctx.conversationId);
|
|
393
|
+
const resident: SectionRef[] = [];
|
|
394
|
+
const slots: BlockSlot[] = [];
|
|
395
|
+
for (const { slug, key, matched } of injectionUnits(result.selections)) {
|
|
396
|
+
if (pruned && sectionRefSetHas(pruned, slug, key)) {
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
const reemitted = rendered?.get(slug)?.get(key);
|
|
400
|
+
if (reemitted !== undefined) {
|
|
401
|
+
slots.push({ slug, key, matched, text: reemitted });
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (active && sectionRefSetHas(active, slug, key)) {
|
|
405
|
+
resident.push({ slug, key });
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
slots.push({ slug, key, matched, text: undefined });
|
|
409
|
+
}
|
|
410
|
+
rememberPointerEntries(
|
|
411
|
+
ctx.conversationId,
|
|
412
|
+
ctx.turnIndex,
|
|
413
|
+
resident.filter(({ slug }) => !isCapabilitySlug(slug)),
|
|
414
|
+
);
|
|
415
|
+
// The turn's selection time, stamped on the resident pairs NOW, in the
|
|
416
|
+
// same synchronous segment as the classification above: the page reads
|
|
417
|
+
// below yield to the event loop, and a prune valve queued by an earlier
|
|
418
|
+
// turn's commit fires on a timer, so it can run while they are awaited
|
|
419
|
+
// and would otherwise rank a pair this turn is about by its stale
|
|
420
|
+
// stamp and evict it. The stamp is a recency bump, not a claim, so a
|
|
421
|
+
// turn whose block never attaches (or that returns null below because
|
|
422
|
+
// every net-new pair rendered empty) bumps harmlessly. Only the first
|
|
423
|
+
// produce stamps: a re-entry re-emits the turn's selections, and a
|
|
424
|
+
// run-messages replacement claims nothing (`resident` is empty there).
|
|
425
|
+
// The net-new pairs take the same time with their record in the commit.
|
|
426
|
+
const selectedAt = Date.now();
|
|
427
|
+
if (firstProduce) {
|
|
428
|
+
touchSelected(ctx.conversationId, resident, selectedAt);
|
|
429
|
+
}
|
|
331
430
|
|
|
332
|
-
// Render net-new
|
|
333
|
-
//
|
|
431
|
+
// Render net-new sections (each an independent page read, so in
|
|
432
|
+
// parallel), skipping pairs that resolve to no content (deleted pages,
|
|
433
|
+
// unresolvable capabilities, empty sections): nothing is attached for
|
|
334
434
|
// them, so nothing is recorded either.
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
435
|
+
const netNew = slots.filter((slot) => slot.text === undefined);
|
|
436
|
+
const renderedNow = await Promise.all(
|
|
437
|
+
netNew.map(({ slug, matched }) =>
|
|
438
|
+
renderV3InjectionEntry(slug, matched),
|
|
439
|
+
),
|
|
440
|
+
);
|
|
441
|
+
for (const [i, slot] of netNew.entries()) {
|
|
442
|
+
slot.text = renderedNow[i]!;
|
|
443
|
+
}
|
|
444
|
+
const entries: Array<SectionRef & { text: string }> = [];
|
|
445
|
+
for (const { slug, key, text } of slots) {
|
|
446
|
+
if (text !== undefined && text.trim().length > 0) {
|
|
447
|
+
entries.push({ slug, key, text });
|
|
340
448
|
}
|
|
341
449
|
}
|
|
342
|
-
// Every net-new
|
|
450
|
+
// Every net-new section rendered empty: return null rather than an
|
|
343
451
|
// empty-text block. Under live there is no v2 block, so the turn simply
|
|
344
|
-
// gets no new memory. Distinct from the all-repeat case (empty
|
|
345
|
-
// where the empty block correctly keeps v2 suppressed
|
|
346
|
-
// already ride history.
|
|
347
|
-
if (netNew.length > 0 &&
|
|
452
|
+
// gets no new memory. Distinct from the all-repeat case (empty
|
|
453
|
+
// `netNew`), where the empty block correctly keeps v2 suppressed
|
|
454
|
+
// because the sections already ride history.
|
|
455
|
+
if (netNew.length > 0 && entries.length === 0) {
|
|
348
456
|
return null;
|
|
349
457
|
}
|
|
350
|
-
const entries = cards.map(({ slug, card }) => ({
|
|
351
|
-
slug,
|
|
352
|
-
// Capability cards (skills / CLI commands) render with their own
|
|
353
|
-
// `# Skill:` / `# CLI command:` headers, which the prune valve's
|
|
354
|
-
// `# memory/concepts/<slug>.md` section grammar can never locate to
|
|
355
|
-
// free. Record them at zero bytes so they never inflate the freeable
|
|
356
|
-
// resident accounting (the valve would otherwise loop-fire on bytes
|
|
357
|
-
// it cannot free).
|
|
358
|
-
bytes: isCapabilitySlug(slug) ? 0 : cardBytes(card),
|
|
359
|
-
}));
|
|
360
|
-
|
|
361
|
-
// The everInjected store write and the prune-valve schedule are
|
|
362
|
-
// DEFERRED to this commit callback, invoked by runtime assembly at the
|
|
363
|
-
// point where attachment is guaranteed (the turn's tail is a user
|
|
364
|
-
// message — the same gate as metadata capture). Recording here in
|
|
365
|
-
// `produce()` would let a never-attached turn (non-user tail) claim
|
|
366
|
-
// cards in the store, suppressing them until compaction. The valve is
|
|
367
|
-
// scheduled after `recordInjected` so the resident accounting includes
|
|
368
|
-
// this turn's cards; stable-prefix lane members (core/hot/fresh) are
|
|
369
|
-
// exempt — the selector's stable prefix must never be pruned out from
|
|
370
|
-
// under it.
|
|
371
|
-
const commit = (): void => {
|
|
372
|
-
recordInjected(ctx.conversationId, entries);
|
|
373
|
-
schedulePruneValve(ctx.conversationId, {
|
|
374
|
-
exemptSlugs: new Set<Slug>([
|
|
375
|
-
...result.lanes.core,
|
|
376
|
-
...result.lanes.hot,
|
|
377
|
-
...result.lanes.fresh,
|
|
378
|
-
]),
|
|
379
|
-
});
|
|
380
|
-
};
|
|
381
458
|
|
|
382
459
|
// Empty net-new → empty-text block: assembly attaches no content
|
|
383
460
|
// (`applyInjectionBlock` no-ops empty text) but the block's presence
|
|
384
461
|
// still marks v3 as this turn's `<memory>` source for v2 suppression.
|
|
385
|
-
const inner =
|
|
386
|
-
|
|
462
|
+
const inner = renderInjectionBlockInner(entries.map((e) => e.text));
|
|
463
|
+
const block: InjectionBlock = {
|
|
387
464
|
id: MEMORY_V3_BLOCK_ID,
|
|
388
465
|
text: inner.length === 0 ? "" : wrapMemoryBlock(inner),
|
|
389
466
|
// Mirror v2's dynamic `<memory>` block placement.
|
|
390
467
|
placement: "after-memory-prefix",
|
|
391
|
-
meta: { [MEMORY_V3_COMMIT_META_KEY]: commit },
|
|
392
468
|
};
|
|
469
|
+
if (!firstProduce) {
|
|
470
|
+
return block;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
rememberRendered(ctx.conversationId, ctx.turnIndex, entries);
|
|
474
|
+
// A block rendered for a run-messages replacement rides that prompt
|
|
475
|
+
// only: no copy of it persists, so the store must not claim its
|
|
476
|
+
// sections and the valve has nothing new to account for.
|
|
477
|
+
if (replaced) {
|
|
478
|
+
return block;
|
|
479
|
+
}
|
|
480
|
+
// The net-new record and the prune-valve schedule are DEFERRED to this
|
|
481
|
+
// commit callback, invoked by runtime assembly at the point where
|
|
482
|
+
// attachment is guaranteed (the turn's tail is a user message, the
|
|
483
|
+
// same gate as metadata capture). Recording here in `produce()` would
|
|
484
|
+
// let a never-attached turn (non-user tail) claim sections in the
|
|
485
|
+
// store, suppressing them until compaction. Only the turn's first
|
|
486
|
+
// produce carries it: a re-entry block re-emits what this one rendered
|
|
487
|
+
// and is never persisted, so it must not record anything. The valve is
|
|
488
|
+
// scheduled after the record so the resident accounting, and the
|
|
489
|
+
// recency it ranks by, include this turn's sections (the resident
|
|
490
|
+
// pairs carry their stamp from the classification above); it evicts by
|
|
491
|
+
// recency with no lane exemptions. It runs on a timer, so this turn's
|
|
492
|
+
// block may not have folded back into the live history when it strips;
|
|
493
|
+
// a section it prunes from this very turn is stripped by assembly Step
|
|
494
|
+
// 0 on the next turn, which applies the store's full tombstone set
|
|
495
|
+
// every turn.
|
|
496
|
+
const commit = (): void => {
|
|
497
|
+
recordInjected(
|
|
498
|
+
ctx.conversationId,
|
|
499
|
+
entries.map(({ slug, key, text }) => ({
|
|
500
|
+
slug,
|
|
501
|
+
key,
|
|
502
|
+
// Capability content (skills / CLI commands) renders with its own
|
|
503
|
+
// `# Skill:` / `# CLI command:` header, which the prune valve's
|
|
504
|
+
// section grammar can never locate to free. Record it at zero
|
|
505
|
+
// bytes so it never inflates the freeable resident accounting
|
|
506
|
+
// (the valve would otherwise loop-fire on bytes it cannot free).
|
|
507
|
+
bytes: isCapabilitySlug(slug) ? 0 : renderedBytes(text),
|
|
508
|
+
})),
|
|
509
|
+
selectedAt,
|
|
510
|
+
);
|
|
511
|
+
schedulePruneValve(ctx.conversationId);
|
|
512
|
+
};
|
|
513
|
+
return { ...block, meta: { [MEMORY_V3_COMMIT_META_KEY]: commit } };
|
|
393
514
|
} catch (err) {
|
|
394
515
|
log.warn(
|
|
395
516
|
{
|
|
@@ -403,73 +524,40 @@ export const memoryV3Injector: Injector = {
|
|
|
403
524
|
},
|
|
404
525
|
};
|
|
405
526
|
|
|
406
|
-
export const
|
|
407
|
-
name: "memory-v3-
|
|
408
|
-
// After the
|
|
527
|
+
export const memoryV3PointerInjector: Injector = {
|
|
528
|
+
name: "memory-v3-pointer",
|
|
529
|
+
// After the sections injector, whose produce records the resident
|
|
530
|
+
// selections of this assembly on the shared memo (a re-entry recomputes
|
|
531
|
+
// them, so the pointer follows what its own block re-emitted or rendered).
|
|
409
532
|
order: 1001,
|
|
410
533
|
async produce(ctx: TurnContext): Promise<InjectionBlock | null> {
|
|
411
|
-
|
|
412
|
-
if (!isMemoryEnabled(config)) {
|
|
534
|
+
if (!turnIsEligible(ctx)) {
|
|
413
535
|
return null;
|
|
414
536
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (!isMemoryV3Live(config)) {
|
|
537
|
+
const remembered = observedTurn(ctx.conversationId, ctx.turnIndex)?.pointer;
|
|
538
|
+
if (!remembered || remembered.length === 0) {
|
|
418
539
|
return null;
|
|
419
540
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
const { n, windowTurns } = config.memory.v3.spotlight;
|
|
434
|
-
const current = computeSpotlightEntries(result, n);
|
|
435
|
-
const window = updateSpotlightWindow(
|
|
436
|
-
ctx.conversationId,
|
|
437
|
-
ctx.turnIndex,
|
|
438
|
-
current,
|
|
439
|
-
windowTurns,
|
|
440
|
-
);
|
|
441
|
-
if (window.length === 0) {
|
|
442
|
-
return null;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
return {
|
|
446
|
-
id: MEMORY_V3_SPOTLIGHT_BLOCK_ID,
|
|
447
|
-
text: wrapMemorySpotlightBlock(renderSpotlightInner(window)),
|
|
448
|
-
// Immediately after frozen `<memory>` cards. `countMemoryPrefixBlocks`
|
|
449
|
-
// counts `<memory>` but not `<memory_spotlight>`, so this lands
|
|
450
|
-
// between the cards and NOW.md / user text.
|
|
451
|
-
placement: "after-memory-prefix",
|
|
452
|
-
};
|
|
453
|
-
} catch (err) {
|
|
454
|
-
if (err instanceof MemoryV3RetrievalUnavailableError) {
|
|
455
|
-
queueMemoryV3ConversationNotice(err, ctx, true);
|
|
456
|
-
log.error(
|
|
457
|
-
{
|
|
458
|
-
err: err.message,
|
|
459
|
-
conversationId: ctx.conversationId,
|
|
460
|
-
},
|
|
461
|
-
"memory-v3 spotlight selection failed; skipping spotlight",
|
|
462
|
-
);
|
|
463
|
-
return null;
|
|
464
|
-
}
|
|
465
|
-
log.warn(
|
|
466
|
-
{
|
|
467
|
-
err: err instanceof Error ? err.message : String(err),
|
|
468
|
-
conversationId: ctx.conversationId,
|
|
469
|
-
},
|
|
470
|
-
"memory-v3 spotlight render failed (non-fatal) — skipping spotlight",
|
|
471
|
-
);
|
|
541
|
+
// Re-validate against the store at render time: the sections injector
|
|
542
|
+
// classified these pairs as resident before awaiting its page reads, and
|
|
543
|
+
// a prune valve queued by an earlier turn's commit can fire in that
|
|
544
|
+
// window and tombstone one of them, stripping its body from the live
|
|
545
|
+
// history. A pair no longer active is dropped rather than pointed at; it
|
|
546
|
+
// is simply absent this turn and re-injects on its next selection.
|
|
547
|
+
const active = getActiveSections(ctx.conversationId);
|
|
548
|
+
const entries = remembered.filter(({ slug, key }) =>
|
|
549
|
+
sectionRefSetHas(active, slug, key),
|
|
550
|
+
);
|
|
551
|
+
if (entries.length === 0) {
|
|
472
552
|
return null;
|
|
473
553
|
}
|
|
554
|
+
return {
|
|
555
|
+
id: MEMORY_V3_POINTER_BLOCK_ID,
|
|
556
|
+
text: wrapMemoryPointerBlock(renderPointerInner(entries)),
|
|
557
|
+
// Immediately after the frozen `<memory>` blocks: `countMemoryPrefixBlocks`
|
|
558
|
+
// counts `<memory>` but not `<memory_pointer>`, so this lands between
|
|
559
|
+
// the sections and NOW.md / user text.
|
|
560
|
+
placement: "after-memory-prefix",
|
|
561
|
+
};
|
|
474
562
|
},
|
|
475
563
|
};
|