@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
|
@@ -13,7 +13,13 @@
|
|
|
13
13
|
* - the span-query pass — the dense lane re-run over the current
|
|
14
14
|
* message's clause chunks as separate queries at a small per-chunk
|
|
15
15
|
* budget (`spanQueryK`), rescuing motifs a long multi-topic message's
|
|
16
|
-
* single query vector averages away
|
|
16
|
+
* single query vector averages away,
|
|
17
|
+
* - the entity lane (`entityLane`) and the rare-term lane
|
|
18
|
+
* (`rareTermLane`), which key on one strong token each (a
|
|
19
|
+
* distinctive `## ` heading token the message names; a query word
|
|
20
|
+
* that occurs in at most a handful of sections) so the section a
|
|
21
|
+
* name or a rare word points at surfaces regardless of the
|
|
22
|
+
* message's bulk theme, and
|
|
17
23
|
* - link-graph edge expansion (`edgeExpand`) over the top
|
|
18
24
|
* user-message needle+dense article seeds, and
|
|
19
25
|
* - learned-edge expansion (`edgeExpand` over the co-selection NPMI
|
|
@@ -31,9 +37,14 @@
|
|
|
31
37
|
* throw inside it logs a warning and falls through to normal selection.
|
|
32
38
|
* 2. Build the candidate pool in CACHE ORDER: the stable prefix —
|
|
33
39
|
* `[...core (file order), ...hot (score order), ...fresh (recency order),
|
|
34
|
-
* ...always-candidate (skills
|
|
35
|
-
* init
|
|
36
|
-
* surfacing order)
|
|
40
|
+
* ...always-candidate (skills listed every turn)]`, all computed at lane
|
|
41
|
+
* init, followed by the finder candidates (needle → dense → reply →
|
|
42
|
+
* span → entity → rare → edge → learned surfacing order), one line per
|
|
43
|
+
* distinct (page, matched section) and at most `finderSectionsPerPage`
|
|
44
|
+
* lines per page from the lanes other than entity and rare (an entity
|
|
45
|
+
* line and a rare-term line never count against the cap or yield to it;
|
|
46
|
+
* see `poolLine`), so a page whose sections match different parts of
|
|
47
|
+
* the message is shown section by section. The stable prefix
|
|
37
48
|
* is identical across consecutive turns while the lanes are unchanged
|
|
38
49
|
* (lane invalidation at consolidation is the recompute cadence), so the
|
|
39
50
|
* selector input's leading segment rides the provider KV cache (the
|
|
@@ -42,16 +53,17 @@
|
|
|
42
53
|
* Stable-prefix candidates render as FULL CARDS (`renderCard` — head
|
|
43
54
|
* section + TOC), pre-rendered at lane init (`prefixCards`) so the
|
|
44
55
|
* rendered prefix is byte-identical across turns. Finder candidates
|
|
45
|
-
* render as compact snippet lines: the matched section's
|
|
46
|
-
*
|
|
47
|
-
*
|
|
56
|
+
* render as compact snippet lines: the matched section's
|
|
57
|
+
* keyword-in-context window around the query terms that scored it (or
|
|
58
|
+
* the curated `links` description for an edge hit), falling back to
|
|
59
|
+
* the page's lead-section text when no match text exists.
|
|
48
60
|
*
|
|
49
61
|
* The finder tail is NOT deduped against the stable prefix: a finder hit
|
|
50
62
|
* on a core/hot page keeps its matched-section line (and its
|
|
51
|
-
* `
|
|
52
|
-
* section
|
|
53
|
-
* page itself sits in the stable prefix. The selector
|
|
54
|
-
*
|
|
63
|
+
* `lanes.finder` entry), so the selector and the
|
|
64
|
+
* section injection see that page's CURRENT relevance even though the
|
|
65
|
+
* page itself sits in the stable prefix. The selector merges selections
|
|
66
|
+
* per slug, carrying every selected section.
|
|
55
67
|
* 3. A SINGLE forced-tool select (`selectPool`) over the whole pool. The
|
|
56
68
|
* result is this turn's selections — current turn only. Cross-turn
|
|
57
69
|
* persistence is the injector's job (net-new blocks frozen into history),
|
|
@@ -65,7 +77,7 @@ import {
|
|
|
65
77
|
} from "../../../../daemon/turn-latency-sub-spans.js";
|
|
66
78
|
import { recordWatchdogEvent } from "../../../../telemetry/watchdog-events-store.js";
|
|
67
79
|
import { getLogger } from "../logging.js";
|
|
68
|
-
import
|
|
80
|
+
import { injectionUnits } from "./capabilities.js";
|
|
69
81
|
import { denseLaneScored } from "./dense.js";
|
|
70
82
|
import type { EdgeGraph } from "./edge.js";
|
|
71
83
|
import { edgeExpand } from "./edge.js";
|
|
@@ -78,15 +90,21 @@ import type {
|
|
|
78
90
|
StableCandidate,
|
|
79
91
|
} from "./pool-select.js";
|
|
80
92
|
import { selectAllPoolCandidates, selectPool } from "./pool-select.js";
|
|
93
|
+
import {
|
|
94
|
+
type RareTermHit,
|
|
95
|
+
rareTermLane,
|
|
96
|
+
type RareTermLaneOptions,
|
|
97
|
+
} from "./rare-term-lane.js";
|
|
81
98
|
import type { SectionNeedle } from "./section-needle.js";
|
|
82
99
|
import { spanChunksOf } from "./span-query.js";
|
|
83
|
-
import
|
|
84
|
-
FinderLane,
|
|
85
|
-
MemoryRoutingTurn,
|
|
86
|
-
Section,
|
|
87
|
-
SectionIndex,
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
import {
|
|
101
|
+
type FinderLane,
|
|
102
|
+
type MemoryRoutingTurn,
|
|
103
|
+
type Section,
|
|
104
|
+
type SectionIndex,
|
|
105
|
+
sectionKey,
|
|
106
|
+
type SelectedPage,
|
|
107
|
+
type Slug,
|
|
90
108
|
} from "./types.js";
|
|
91
109
|
|
|
92
110
|
// Named to disambiguate from the unrelated `src/config/memory-v3-gate.ts`: this
|
|
@@ -159,6 +177,10 @@ export const DEFAULT_NEEDLE_K = 12;
|
|
|
159
177
|
export const DEFAULT_DENSE_K = 0;
|
|
160
178
|
/** Default hard cap on entity-lane articles folded into the pool per turn. */
|
|
161
179
|
export const DEFAULT_ENTITY_CAP = 8;
|
|
180
|
+
/** Contributing query terms carried per finder candidate for its
|
|
181
|
+
* keyword-in-context snippet (the renderer uses the first one that occurs
|
|
182
|
+
* in the section body). */
|
|
183
|
+
const SNIPPET_TERMS = 3;
|
|
162
184
|
|
|
163
185
|
export interface OrchestrateDeps {
|
|
164
186
|
sectionIndex: SectionIndex;
|
|
@@ -180,7 +202,7 @@ export interface OrchestrateDeps {
|
|
|
180
202
|
/** The modification-recency fresh set in recency order (computed at lane
|
|
181
203
|
* init with core and hot excluded). Follows hot in the stable prefix. */
|
|
182
204
|
freshSlugs: Slug[];
|
|
183
|
-
/** Skills
|
|
205
|
+
/** Skills placed in the candidate pool every turn regardless of retrieval
|
|
184
206
|
* (existence-filtered and core/hot/fresh-excluded at lane init). Follow fresh
|
|
185
207
|
* in the stable prefix so the selector always sees them. */
|
|
186
208
|
alwaysCandidateSlugs?: Slug[];
|
|
@@ -197,6 +219,21 @@ export interface OrchestrateDeps {
|
|
|
197
219
|
/** Hard cap on entity-lane articles. Defaults to {@link DEFAULT_ENTITY_CAP}.
|
|
198
220
|
* Ignored when `entityIndex` is omitted (the lane is off). */
|
|
199
221
|
entityCap?: number;
|
|
222
|
+
/** Rare-term lane tuning (canonical value: `memory.v3.rareTerm`): the df
|
|
223
|
+
* ceiling for a query word to count as rare (`maxDf`, lowered on a smaller
|
|
224
|
+
* corpus by `maxDfFraction`), the sections surfaced per rare word, and the
|
|
225
|
+
* per-turn cap. Omitted disables the lane, which the caller does whenever
|
|
226
|
+
* the selector is off: rare lines are candidates for a judge, not evidence
|
|
227
|
+
* strong enough to inject unjudged. */
|
|
228
|
+
rareTerm?: RareTermLaneOptions;
|
|
229
|
+
/** Cap on finder lines one page may carry per turn, applied in surfacing
|
|
230
|
+
* order (needle, dense, reply, span); a section-less edge or learned line
|
|
231
|
+
* counts as one. An entity line and a rare-term line are outside the cap,
|
|
232
|
+
* neither counted against it nor displaced by it (the lanes' own
|
|
233
|
+
* `entityCap` and `rareTerm.cap` bound those per turn), so a page carries
|
|
234
|
+
* at most this many lines plus its entity and rare lines (canonical
|
|
235
|
+
* value, default included: `memory.v3.finderSectionsPerPage`). */
|
|
236
|
+
finderSectionsPerPage: number;
|
|
200
237
|
/** Per-lane article budget for the reply-query pass (needle + dense re-run
|
|
201
238
|
* over `turn.previousAssistantMessage` as separate queries). `0` or
|
|
202
239
|
* omitted disables the pass (canonical value: `memory.v3.replyQueryK`). */
|
|
@@ -242,26 +279,36 @@ export interface OrchestrateDeps {
|
|
|
242
279
|
* `MEMORY_V3_FULL_PROFILE_MIN_PAGES`; omitted drops the field from the
|
|
243
280
|
* telemetry detail (the gate itself never reads it). */
|
|
244
281
|
realConceptPageCount?: number;
|
|
245
|
-
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
|
|
282
|
+
/** Whether one of this turn's injection units (`injectionUnits` in
|
|
283
|
+
* `capabilities.ts`: a selected section, or the lead of a page selected
|
|
284
|
+
* with none, by page slug and section-store key) is already resident in
|
|
285
|
+
* the conversation. Used ONLY to compute the `net_new_count` telemetry
|
|
286
|
+
* field, selections it rejects are what the injector actually renders.
|
|
287
|
+
* Read-only and side-effect-free: selection never consults it, and
|
|
288
|
+
* omitting it just drops the field. The injector reads the same store, so
|
|
289
|
+
* the two agree for a turn that has not yet committed. */
|
|
290
|
+
isResident?: (slug: Slug, key: string) => boolean;
|
|
252
291
|
}
|
|
253
292
|
|
|
254
|
-
/** A finder-lane candidate: the slug, the
|
|
255
|
-
* the
|
|
293
|
+
/** A finder-lane candidate, one pool line: the slug, the matched section
|
|
294
|
+
* when the lane scored one (absent for an edge or learned hit), the query
|
|
295
|
+
* terms that contributed most to that match (best first; they drive the
|
|
296
|
+
* selector's keyword-in-context snippet, and a rare-term line carries the
|
|
297
|
+
* one word it was keyed on as its only term), the descriptor that
|
|
298
|
+
* justified the line, and the lane that surfaced it. One page can carry
|
|
299
|
+
* several candidates, one per distinct matched section, in surfacing
|
|
300
|
+
* order. */
|
|
256
301
|
export interface FinderCandidate {
|
|
257
302
|
slug: Slug;
|
|
303
|
+
section?: Section;
|
|
304
|
+
terms?: string[];
|
|
258
305
|
descriptor: string;
|
|
259
306
|
lane: FinderLane;
|
|
260
307
|
}
|
|
261
308
|
|
|
262
309
|
/**
|
|
263
|
-
* The candidate lanes in cache order. `core`, `hot`, and `
|
|
264
|
-
* stable prefix (byte-identical across turns while lanes are unchanged);
|
|
310
|
+
* The candidate lanes in cache order. `core`, `hot`, `fresh`, and `always` are
|
|
311
|
+
* the stable prefix (byte-identical across turns while lanes are unchanged);
|
|
265
312
|
* `finder` is the dynamic tail and MAY repeat a stable-prefix slug (a finder
|
|
266
313
|
* hit on a stable-prefix page is kept so its current relevance stays visible
|
|
267
314
|
* downstream).
|
|
@@ -273,24 +320,31 @@ export interface OrchestrateLanes {
|
|
|
273
320
|
hot: Slug[];
|
|
274
321
|
/** Modification-recency fresh set, recency order (never overlaps core/hot). */
|
|
275
322
|
fresh: Slug[];
|
|
276
|
-
/**
|
|
323
|
+
/** Always-candidate skills, install order (never overlaps core/hot/fresh). */
|
|
324
|
+
always: Slug[];
|
|
325
|
+
/** Finder candidates in surfacing order: one per distinct (page, matched
|
|
326
|
+
* section), capped per page, deduped among themselves only. */
|
|
277
327
|
finder: FinderCandidate[];
|
|
278
328
|
}
|
|
279
329
|
|
|
280
330
|
export interface OrchestrateResult {
|
|
281
|
-
/** This turn's selections,
|
|
282
|
-
*
|
|
331
|
+
/** This turn's selections, one per slug with the selected finder lines'
|
|
332
|
+
* sections merged in pool order (the merge is `selectPool`'s contract);
|
|
333
|
+
* the injector renders each of them. Current turn only: there is no
|
|
283
334
|
* carried-forward set unioned in. */
|
|
284
335
|
selections: SelectedPage[];
|
|
285
|
-
/** The matched `Section` for each candidate slug that had one, keyed by slug.
|
|
286
|
-
* Populated from the finder-lane hits — including hits on core/hot pages —
|
|
287
|
-
* and consumed by the injector to render each selected slug's matched
|
|
288
|
-
* section (progressive disclosure). */
|
|
289
|
-
matchedSections: Map<Slug, Section>;
|
|
290
336
|
/** The candidate lanes in cache order; see {@link OrchestrateLanes}. Consumed
|
|
291
|
-
* by the selection telemetry (lane attribution)
|
|
292
|
-
* rendering
|
|
337
|
+
* by the selection telemetry (lane attribution), the per-turn pool record
|
|
338
|
+
* (`pool-log-store.ts`), and the downstream selector rendering. */
|
|
293
339
|
lanes: OrchestrateLanes;
|
|
340
|
+
/** Whether the selector LLM judged a non-empty pool this turn (the
|
|
341
|
+
* `selector_ran` telemetry field). False when the pool was empty, when the
|
|
342
|
+
* disabled-selector passthrough kept every candidate, and when a closed
|
|
343
|
+
* injection gate hard-skipped selection. On that last path `lanes` still
|
|
344
|
+
* carries the stable prefix as computed, but no pool was ever assembled,
|
|
345
|
+
* so a false value with empty `selections` means the selector was given
|
|
346
|
+
* nothing. */
|
|
347
|
+
selectorRan: boolean;
|
|
294
348
|
}
|
|
295
349
|
|
|
296
350
|
/** Stable-order de-duplication preserving first occurrence. */
|
|
@@ -408,11 +462,12 @@ export async function orchestrate(
|
|
|
408
462
|
),
|
|
409
463
|
]),
|
|
410
464
|
);
|
|
411
|
-
// Everything from here to the step-3 selection
|
|
412
|
-
// entity
|
|
413
|
-
// assembly
|
|
414
|
-
// region rather than wrapped calls. Gate-closed early returns
|
|
415
|
-
// record on purpose: the expansion work didn't happen on those
|
|
465
|
+
// Everything from here to the step-3 selection (finder assembly, the
|
|
466
|
+
// entity and rare-term lanes, the injection gate, edge + learned-edge
|
|
467
|
+
// expansion, pool assembly) is synchronous in-memory work, measured as one
|
|
468
|
+
// `v3_expand` region rather than wrapped calls. Gate-closed early returns
|
|
469
|
+
// skip the record on purpose: the expansion work didn't happen on those
|
|
470
|
+
// turns.
|
|
416
471
|
const expandStartedAt = Date.now();
|
|
417
472
|
|
|
418
473
|
// Dense hits restricted to pages still in the live section index. A deleted
|
|
@@ -424,152 +479,176 @@ export async function orchestrate(
|
|
|
424
479
|
deps.sectionIndex.byArticle.has(hit.article),
|
|
425
480
|
);
|
|
426
481
|
|
|
427
|
-
// `
|
|
428
|
-
//
|
|
429
|
-
//
|
|
430
|
-
//
|
|
431
|
-
//
|
|
432
|
-
|
|
482
|
+
// `finder` accumulates the pool's dynamic tail: one entry per distinct
|
|
483
|
+
// (article, matched section), in the needle → dense → reply → span →
|
|
484
|
+
// entity → rare call order, so a page whose sections match different parts of
|
|
485
|
+
// the message carries one line per section and the selector sees each
|
|
486
|
+
// section's own text. A hit that resolves to no section (an edge or
|
|
487
|
+
// learned neighbour, a dense ordinal the index no longer holds) is one
|
|
488
|
+
// section-less line per page, added only when nothing has surfaced the
|
|
489
|
+
// page yet. Each page's lines are capped at `finderSectionsPerPage` in
|
|
490
|
+
// surfacing order, its entity and rare lines aside (`poolLine`). Hits on
|
|
491
|
+
// stable-prefix slugs are kept like any other, so the selector and the
|
|
492
|
+
// injection see those pages' CURRENT relevance.
|
|
493
|
+
const finderCap = deps.finderSectionsPerPage;
|
|
433
494
|
const finder: FinderCandidate[] = [];
|
|
434
|
-
const
|
|
495
|
+
const finderByArticle = new Map<Slug, FinderCandidate[]>();
|
|
496
|
+
|
|
497
|
+
// Whether a line counts against its page's cap. An entity line and a
|
|
498
|
+
// rare-term line do not: both lanes key on one strong token the message
|
|
499
|
+
// names and run after every lane that fills the cap, so holding them to
|
|
500
|
+
// the cap would displace exactly the line each lane exists to surface.
|
|
501
|
+
// The lanes' own caps (`entityCap`, `rareTerm.cap`) bound the lines they
|
|
502
|
+
// add per turn instead.
|
|
503
|
+
const countsAgainstCap = (line: FinderCandidate): boolean =>
|
|
504
|
+
line.lane !== "entity" && line.lane !== "rare";
|
|
435
505
|
|
|
436
|
-
//
|
|
437
|
-
//
|
|
438
|
-
|
|
506
|
+
// Pool a line for its page unless the page already carries it or is at
|
|
507
|
+
// the cap: a line with a section duplicates a line for the same section
|
|
508
|
+
// key; a section-less line duplicates any line. The cap holds the page's
|
|
509
|
+
// counted lines at `finderCap`; a line outside the cap joins past it, so a
|
|
510
|
+
// page carries at most `finderCap` counted lines plus its entity and rare
|
|
511
|
+
// lines, `finderCap + entityCap + rareTerm.cap` in all.
|
|
512
|
+
const poolLine = (candidate: FinderCandidate): void => {
|
|
513
|
+
const lines = finderByArticle.get(candidate.slug) ?? [];
|
|
514
|
+
const key = candidate.section ? sectionKey(candidate.section) : undefined;
|
|
515
|
+
const duplicate =
|
|
516
|
+
key === undefined
|
|
517
|
+
? lines.length > 0
|
|
518
|
+
: lines.some((c) => c.section && sectionKey(c.section) === key);
|
|
519
|
+
const atCap =
|
|
520
|
+
countsAgainstCap(candidate) &&
|
|
521
|
+
lines.filter(countsAgainstCap).length >= finderCap;
|
|
522
|
+
if (duplicate || atCap) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
lines.push(candidate);
|
|
526
|
+
finderByArticle.set(candidate.slug, lines);
|
|
527
|
+
finder.push(candidate);
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
// A lane hit on section `doc` (an index into `sections`) scored against
|
|
531
|
+
// `query`, whose best-contributing terms ride the line for the selector's
|
|
532
|
+
// keyword-in-context snippet. A `doc` the index does not hold pools as a
|
|
533
|
+
// section-less line with a blank descriptor.
|
|
534
|
+
const addSectionHit = (
|
|
439
535
|
slug: Slug,
|
|
440
|
-
|
|
441
|
-
descriptor: string | undefined,
|
|
536
|
+
doc: number | undefined,
|
|
442
537
|
lane: FinderLane,
|
|
538
|
+
query: string,
|
|
443
539
|
): void => {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
540
|
+
const section = doc === undefined ? undefined : sections[doc];
|
|
541
|
+
poolLine(
|
|
542
|
+
doc !== undefined && section
|
|
543
|
+
? {
|
|
544
|
+
slug,
|
|
545
|
+
section,
|
|
546
|
+
terms: deps.needle.topTerms(doc, query, SNIPPET_TERMS),
|
|
547
|
+
descriptor: section.text,
|
|
548
|
+
lane,
|
|
549
|
+
}
|
|
550
|
+
: { slug, descriptor: "", lane },
|
|
551
|
+
);
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
// A rare-term hit is keyed on one query word, which is the line's only
|
|
555
|
+
// snippet term and, through the lane, its tag.
|
|
556
|
+
const addRareHit = (hit: RareTermHit): void => {
|
|
557
|
+
const section = sections[hit.section]!;
|
|
558
|
+
poolLine({
|
|
559
|
+
slug: hit.article,
|
|
560
|
+
section,
|
|
561
|
+
terms: [hit.term],
|
|
562
|
+
descriptor: section.text,
|
|
563
|
+
lane: "rare",
|
|
455
564
|
});
|
|
456
565
|
};
|
|
457
566
|
|
|
458
|
-
//
|
|
459
|
-
//
|
|
567
|
+
// A page surfaced by association (an edge or learned neighbour): no
|
|
568
|
+
// section, described by its curated `links` text or a fallback.
|
|
569
|
+
const addNeighbour = (
|
|
570
|
+
slug: Slug,
|
|
571
|
+
descriptor: string | undefined,
|
|
572
|
+
lane: FinderLane,
|
|
573
|
+
): void => {
|
|
574
|
+
poolLine({ slug, descriptor: descriptor ?? "", lane });
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
// Step 1a: needle hits, `section` is an index into `sections`.
|
|
460
578
|
for (const hit of needled) {
|
|
461
|
-
|
|
579
|
+
addSectionHit(hit.article, hit.section, "needle", turn.currentMessage);
|
|
462
580
|
}
|
|
463
581
|
|
|
464
|
-
// Step 1b: dense hits
|
|
465
|
-
//
|
|
466
|
-
//
|
|
467
|
-
//
|
|
468
|
-
// `denseOwnedSection` tracks the articles whose recorded matched section
|
|
469
|
-
// came from THIS loop (needle records first and wins ties), along with the
|
|
470
|
-
// hit's cosine score — the span pass upgrades those sections when a clause
|
|
471
|
-
// query finds a strictly stronger match under the same metric.
|
|
472
|
-
const denseOwnedSection = new Map<Slug, number>();
|
|
582
|
+
// Step 1b: dense hits, `section` is the matched ORDINAL; resolve it to the
|
|
583
|
+
// section's index via the section index. An ordinal the in-memory index
|
|
584
|
+
// does not hold yields a section-less candidate (blank descriptor).
|
|
473
585
|
for (const hit of densed) {
|
|
474
586
|
// A deleted page's points can linger in Qdrant; keep only live-index
|
|
475
587
|
// articles. The section index is rebuilt from `getPageIndex` at `initLanes`,
|
|
476
588
|
// so `byArticle` holds exactly the live pages (synthetic capability slugs
|
|
477
|
-
// included)
|
|
589
|
+
// included), only truly-deleted pages are dropped here.
|
|
478
590
|
if (!deps.sectionIndex.byArticle.has(hit.article)) {
|
|
479
591
|
continue;
|
|
480
592
|
}
|
|
481
|
-
|
|
482
|
-
deps.sectionIndex,
|
|
593
|
+
addSectionHit(
|
|
483
594
|
hit.article,
|
|
484
|
-
hit.section,
|
|
595
|
+
sectionDocByOrdinal(deps.sectionIndex, hit.article, hit.section),
|
|
596
|
+
"dense",
|
|
597
|
+
turn.currentMessage,
|
|
485
598
|
);
|
|
486
|
-
if (section && !matchedSections.has(hit.article)) {
|
|
487
|
-
denseOwnedSection.set(hit.article, hit.score);
|
|
488
|
-
}
|
|
489
|
-
addFinder(hit.article, section, undefined, "dense");
|
|
490
599
|
}
|
|
491
600
|
|
|
492
|
-
// Step 1b': reply-query hits
|
|
493
|
-
//
|
|
494
|
-
//
|
|
495
|
-
//
|
|
496
|
-
// and the spotlight render the reply-matched section.
|
|
601
|
+
// Step 1b': reply-query hits. A section the user-message lanes already
|
|
602
|
+
// pooled is a no-op (`poolLine`'s pair dedup), so only a genuinely
|
|
603
|
+
// reply-surfaced section tags `"reply"`; its snippet terms come from the
|
|
604
|
+
// reply text it was scored against.
|
|
497
605
|
for (const hit of replyNeedled) {
|
|
498
|
-
|
|
606
|
+
addSectionHit(hit.article, hit.section, "reply", replyQuery);
|
|
499
607
|
}
|
|
500
608
|
for (const hit of replyDensed) {
|
|
501
609
|
if (!deps.sectionIndex.byArticle.has(hit.article)) {
|
|
502
610
|
continue;
|
|
503
611
|
}
|
|
504
|
-
|
|
612
|
+
addSectionHit(
|
|
505
613
|
hit.article,
|
|
506
|
-
|
|
507
|
-
undefined,
|
|
614
|
+
sectionDocByOrdinal(deps.sectionIndex, hit.article, hit.section),
|
|
508
615
|
"reply",
|
|
616
|
+
replyQuery,
|
|
509
617
|
);
|
|
510
618
|
}
|
|
511
619
|
|
|
512
|
-
// Step 1b'': span-query hits
|
|
513
|
-
// budget.
|
|
514
|
-
//
|
|
515
|
-
//
|
|
516
|
-
// excluded from the injection gate (which scores
|
|
517
|
-
// dense only) and from the edge-expansion seeds.
|
|
620
|
+
// Step 1b'': span-query hits, union-additive at the pass's own small
|
|
621
|
+
// budget. A section a primary or reply lane already pooled is a no-op; a
|
|
622
|
+
// different section of an already-surfaced page joins as its own line,
|
|
623
|
+
// which is the buried-clause match the pass exists to recover. Like the
|
|
624
|
+
// reply pass, span hits are excluded from the injection gate (which scores
|
|
625
|
+
// current-message needle + dense only) and from the edge-expansion seeds.
|
|
518
626
|
//
|
|
519
|
-
//
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
const
|
|
524
|
-
for (const hit of spanDensed.flat()) {
|
|
525
|
-
const prev = bestSpanHits.get(hit.article);
|
|
526
|
-
if (!prev || hit.score > prev.score) {
|
|
527
|
-
bestSpanHits.set(hit.article, hit);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
// For an article a primary lane already surfaced, upgrade its matched
|
|
531
|
-
// section/descriptor ONLY when the existing section was recorded by the
|
|
532
|
-
// full-message dense hit and the span's cosine is strictly higher — same
|
|
533
|
-
// encoder, same collection, so the comparison is evidence, not judgment.
|
|
534
|
-
// Needle- and reply-recorded sections stay (BM25 and cosine scores are not
|
|
535
|
-
// comparable, and the reply pass's own convention is first-wins); lane
|
|
536
|
-
// attribution never changes here.
|
|
537
|
-
for (const hit of bestSpanHits.values()) {
|
|
627
|
+
// Several chunks can hit one article on different sections; they are
|
|
628
|
+
// pooled strongest cosine first, so chunk order never decides which
|
|
629
|
+
// sections fill the page's cap.
|
|
630
|
+
const spanHits = spanDensed.flat().sort((a, c) => c.score - a.score);
|
|
631
|
+
for (const hit of spanHits) {
|
|
538
632
|
if (!deps.sectionIndex.byArticle.has(hit.article)) {
|
|
539
633
|
continue;
|
|
540
634
|
}
|
|
541
|
-
|
|
542
|
-
deps.sectionIndex,
|
|
635
|
+
addSectionHit(
|
|
543
636
|
hit.article,
|
|
544
|
-
hit.section,
|
|
637
|
+
sectionDocByOrdinal(deps.sectionIndex, hit.article, hit.section),
|
|
638
|
+
"span",
|
|
639
|
+
turn.currentMessage,
|
|
545
640
|
);
|
|
546
|
-
const denseScore = denseOwnedSection.get(hit.article);
|
|
547
|
-
if (section && denseScore !== undefined && hit.score > denseScore) {
|
|
548
|
-
matchedSections.set(hit.article, section);
|
|
549
|
-
const existing = finder.find((c) => c.slug === hit.article);
|
|
550
|
-
if (existing) {
|
|
551
|
-
existing.descriptor = section.text;
|
|
552
|
-
}
|
|
553
|
-
continue;
|
|
554
|
-
}
|
|
555
|
-
addFinder(hit.article, section, undefined, "span");
|
|
556
641
|
}
|
|
557
642
|
|
|
558
|
-
// Step 1b''': entity lane
|
|
643
|
+
// Step 1b''': entity lane, sections whose `## ` heading NAMES a distinctive
|
|
559
644
|
// entity the message mentions. Additive BM25 buries a single named entity
|
|
560
645
|
// under a long, multi-topic message's bulk theme; this keys on the heading
|
|
561
|
-
// vocabulary so the
|
|
562
|
-
// theme
|
|
563
|
-
//
|
|
564
|
-
//
|
|
565
|
-
//
|
|
566
|
-
//
|
|
567
|
-
// takes precedence over any bulk-theme section a prior lane (needle / dense /
|
|
568
|
-
// reply) already recorded for the SAME page: `addFinder` keeps the first
|
|
569
|
-
// matched section and skips duplicate slugs, so override the matched section
|
|
570
|
-
// and the existing finder descriptor here before delegating, ensuring
|
|
571
|
-
// injection, the spotlight, and the selector snippet all render the heading
|
|
572
|
-
// rather than the earlier non-entity match.
|
|
646
|
+
// vocabulary so the section the user named surfaces regardless of the bulk
|
|
647
|
+
// theme, as its own line beside any bulk-theme section a prior lane pooled
|
|
648
|
+
// for the same page (a no-op when that lane already pooled the heading).
|
|
649
|
+
// Runs before edge expansion so an entity hit counts as surfaced (edge
|
|
650
|
+
// won't re-surface its page section-less); it is NOT added to the edge
|
|
651
|
+
// seeds, so it only contributes its own section.
|
|
573
652
|
if (deps.entityIndex) {
|
|
574
653
|
for (const hit of entityLane(
|
|
575
654
|
deps.entityIndex,
|
|
@@ -577,25 +656,39 @@ export async function orchestrate(
|
|
|
577
656
|
turn.currentMessage,
|
|
578
657
|
deps.entityCap ?? DEFAULT_ENTITY_CAP,
|
|
579
658
|
)) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
659
|
+
addSectionHit(hit.article, hit.section, "entity", turn.currentMessage);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// Step 1b'''': rare-term lane, the sections a rare query word occurs in. A
|
|
664
|
+
// word found in at most `maxDf` sections is a near-certain signal on its
|
|
665
|
+
// own: additive BM25 lets the message's bulk theme pick a page's section,
|
|
666
|
+
// and a query on the clause alone cannot rank a page whose only
|
|
667
|
+
// distinctive token is that word. Each rare word's top sections by
|
|
668
|
+
// single-term score join as their own lines, tagged with the word, which
|
|
669
|
+
// also centers the selector's snippet; a section a prior lane pooled is a
|
|
670
|
+
// no-op, and a page the prior lanes filled to the per-page cap still
|
|
671
|
+
// takes its rare lines (`poolLine`). Like the entity lane, rare hits feed
|
|
672
|
+
// neither the gate nor the edge seeds.
|
|
673
|
+
if (deps.rareTerm) {
|
|
674
|
+
for (const hit of rareTermLane(
|
|
675
|
+
deps.needle,
|
|
676
|
+
deps.sectionIndex,
|
|
677
|
+
turn.currentMessage,
|
|
678
|
+
deps.rareTerm,
|
|
679
|
+
)) {
|
|
680
|
+
addRareHit(hit);
|
|
589
681
|
}
|
|
590
682
|
}
|
|
591
683
|
|
|
592
|
-
// Step 1b'''': opt-in injection gate. With the CURRENT-message finder lanes
|
|
593
|
-
// hand (needle + dense
|
|
594
|
-
// whether retrieval is confident enough to spend the
|
|
595
|
-
// turn. Default-off via `?.enabled`; pass-open on
|
|
596
|
-
// never drop a turn's memory). A closed gate
|
|
597
|
-
// (empty selections) or, when `bypassForCore`
|
|
598
|
-
// stable prefix only
|
|
684
|
+
// Step 1b''''': opt-in injection gate. With the CURRENT-message finder lanes
|
|
685
|
+
// in hand (needle + dense, NOT reply/span/entity/rare/edge, which only add
|
|
686
|
+
// recall), decide whether retrieval is confident enough to spend the
|
|
687
|
+
// selectPool LLM call this turn. Default-off via `?.enabled`; pass-open on
|
|
688
|
+
// any throw (a gate bug must never drop a turn's memory). A closed gate
|
|
689
|
+
// either hard-skips selection (empty selections) or, when `bypassForCore`
|
|
690
|
+
// is set, runs selectPool over the stable prefix only, never the finder
|
|
691
|
+
// tail.
|
|
599
692
|
//
|
|
600
693
|
// The gate is dense-gated: it only runs when the live dense lane produced hits
|
|
601
694
|
// (`liveDensed.length > 0`). In healthy operation dense returns top-k hits for
|
|
@@ -650,18 +743,25 @@ export async function orchestrate(
|
|
|
650
743
|
// the provider (also a 0%).
|
|
651
744
|
// The last is why `poolSize` decides this rather than each call site: an empty
|
|
652
745
|
// pool is not a judgment that nothing was relevant, and no caller has to
|
|
653
|
-
// remember that.
|
|
746
|
+
// remember that. `selectorRanOver` is that rule; the selection event and the
|
|
747
|
+
// result's `selectorRan` both read it.
|
|
654
748
|
// `selector_kept_all` and `net_new_count` separate what the selector JUDGED
|
|
655
749
|
// from what actually reaches the turn, which `selected_count` alone conflates:
|
|
656
750
|
// - kept_all: the recall-safe fallback fired (model omitted `ids`), so every
|
|
657
751
|
// candidate was kept without a real judgment. Distinguishes "kept the whole
|
|
658
752
|
// pool because it gave up" from "explicitly selected a large set", which
|
|
659
753
|
// otherwise look identical and inflate the same way.
|
|
660
|
-
// - net_new:
|
|
661
|
-
//
|
|
662
|
-
//
|
|
663
|
-
//
|
|
664
|
-
//
|
|
754
|
+
// - net_new: the injection units among the selections (`injectionUnits`:
|
|
755
|
+
// each selected section, or the lead of a page selected with none, a
|
|
756
|
+
// capability page as one unit) not already live in the conversation,
|
|
757
|
+
// the injector renders only these (prior turns' sections ride
|
|
758
|
+
// history), so it is the real incremental injection, where
|
|
759
|
+
// `selected_count` re-counts the whole standing set every turn.
|
|
760
|
+
// Omitted when the caller did not supply `isResident` (tests,
|
|
761
|
+
// shadow-less paths). The count reads the same units the injector will
|
|
762
|
+
// (a closed gate's selections carry no sections, so it counts leads).
|
|
763
|
+
const selectorRanOver = (poolSize: number): boolean =>
|
|
764
|
+
deps.selectorEnabled !== false && poolSize > 0;
|
|
665
765
|
const recordSelection = (
|
|
666
766
|
selections: SelectedPage[],
|
|
667
767
|
poolSize: number,
|
|
@@ -670,14 +770,15 @@ export async function orchestrate(
|
|
|
670
770
|
const detail: Record<string, unknown> = {
|
|
671
771
|
gate_reason: gateOutcome?.reason ?? null,
|
|
672
772
|
gate_pass: gateOutcome?.pass ?? null,
|
|
673
|
-
selector_ran:
|
|
773
|
+
selector_ran: selectorRanOver(poolSize),
|
|
674
774
|
selector_kept_all: keptAll,
|
|
675
775
|
selected_count: selections.length,
|
|
676
776
|
pool_size: poolSize,
|
|
677
777
|
};
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
778
|
+
const isResident = deps.isResident;
|
|
779
|
+
if (isResident !== undefined) {
|
|
780
|
+
detail.net_new_count = injectionUnits(selections).filter(
|
|
781
|
+
({ slug, key }) => !isResident(slug, key),
|
|
681
782
|
).length;
|
|
682
783
|
}
|
|
683
784
|
if (deps.realConceptPageCount !== undefined) {
|
|
@@ -739,12 +840,15 @@ export async function orchestrate(
|
|
|
739
840
|
checked_articles: gate.checkedArticles,
|
|
740
841
|
});
|
|
741
842
|
if (!gate.pass) {
|
|
742
|
-
// A closed gate produces no finder lane
|
|
743
|
-
//
|
|
744
|
-
const closed = (
|
|
843
|
+
// A closed gate produces no finder lane; only `selections` and
|
|
844
|
+
// `selectorRan` differ between bypass (stable prefix) and hard-skip.
|
|
845
|
+
const closed = (
|
|
846
|
+
selections: SelectedPage[],
|
|
847
|
+
selectorRan: boolean,
|
|
848
|
+
): OrchestrateResult => ({
|
|
745
849
|
selections,
|
|
746
|
-
|
|
747
|
-
|
|
850
|
+
lanes: { core, hot, fresh, always, finder: [] },
|
|
851
|
+
selectorRan,
|
|
748
852
|
});
|
|
749
853
|
if (deps.gateConfig.bypassForCore) {
|
|
750
854
|
// Select over the stable prefix only. `runSelection` mirrors the
|
|
@@ -762,13 +866,14 @@ export async function orchestrate(
|
|
|
762
866
|
finder: [],
|
|
763
867
|
});
|
|
764
868
|
recordSelection(bypassed, stableOnly.length, keptAll);
|
|
765
|
-
return closed(bypassed);
|
|
869
|
+
return closed(bypassed, selectorRanOver(stableOnly.length));
|
|
766
870
|
}
|
|
767
871
|
// Hard skip: the selector is never consulted, so this is a zero
|
|
768
872
|
// selection BY CONSTRUCTION, not a judgment that nothing was relevant.
|
|
769
|
-
// `selector_ran: false` keeps it out of any relevance rate
|
|
873
|
+
// `selector_ran: false` keeps it out of any relevance rate, and the
|
|
874
|
+
// result's `selectorRan` keeps it out of the persisted pool record.
|
|
770
875
|
recordSelection([], 0, false);
|
|
771
|
-
return closed([]);
|
|
876
|
+
return closed([], false);
|
|
772
877
|
}
|
|
773
878
|
}
|
|
774
879
|
}
|
|
@@ -783,8 +888,8 @@ export async function orchestrate(
|
|
|
783
888
|
// its first/lead section on a zero-score match. That lead is often empty for
|
|
784
889
|
// heading-structured pages, and it is the curated `links` description (not
|
|
785
890
|
// the lead) that made the candidate relevant. So we record NO matched
|
|
786
|
-
// section for edge-only pages (pass `undefined`)
|
|
787
|
-
//
|
|
891
|
+
// section for edge-only pages (pass `undefined`): the candidate is a
|
|
892
|
+
// section-less line and a selection of it injects the page's lead.
|
|
788
893
|
// `bestSection`'s text is kept only as the select-pool DESCRIPTOR fallback
|
|
789
894
|
// for when the traversed edge carried no curated `links` description.
|
|
790
895
|
const seeds = unique<Slug>([
|
|
@@ -795,14 +900,13 @@ export async function orchestrate(
|
|
|
795
900
|
seedCount: deps.edgeSeeds,
|
|
796
901
|
perSeed: deps.edgePerSeed,
|
|
797
902
|
cap: deps.edgeCap,
|
|
798
|
-
alive: (slug) => !
|
|
903
|
+
alive: (slug) => !finderByArticle.has(slug) && !stablePrefix.has(slug),
|
|
799
904
|
});
|
|
800
905
|
for (const neighbor of surfaced) {
|
|
801
906
|
const best = deps.needle.bestSection(neighbor.article, turn.currentMessage);
|
|
802
907
|
const fallbackDescriptor = best >= 0 ? sections[best]?.text : undefined;
|
|
803
|
-
|
|
908
|
+
addNeighbour(
|
|
804
909
|
neighbor.article,
|
|
805
|
-
undefined,
|
|
806
910
|
neighbor.description ?? fallbackDescriptor,
|
|
807
911
|
"edge",
|
|
808
912
|
);
|
|
@@ -820,16 +924,15 @@ export async function orchestrate(
|
|
|
820
924
|
seedCount: deps.edgeSeeds,
|
|
821
925
|
perSeed: deps.learnedPerSeed,
|
|
822
926
|
cap: deps.learnedCap,
|
|
823
|
-
alive: (slug) => !
|
|
927
|
+
alive: (slug) => !finderByArticle.has(slug) && !stablePrefix.has(slug),
|
|
824
928
|
});
|
|
825
929
|
for (const neighbor of learned) {
|
|
826
930
|
const best = deps.needle.bestSection(
|
|
827
931
|
neighbor.article,
|
|
828
932
|
turn.currentMessage,
|
|
829
933
|
);
|
|
830
|
-
|
|
934
|
+
addNeighbour(
|
|
831
935
|
neighbor.article,
|
|
832
|
-
undefined,
|
|
833
936
|
best >= 0 ? sections[best]?.text : undefined,
|
|
834
937
|
"learned",
|
|
835
938
|
);
|
|
@@ -843,12 +946,15 @@ export async function orchestrate(
|
|
|
843
946
|
// byte-identical across turns while the lanes are unchanged. The tail is
|
|
844
947
|
// NOT deduped against the prefix — a finder hit on a core/hot page renders
|
|
845
948
|
// its own snippet line so its CURRENT relevance stays visible; `selectPool`
|
|
846
|
-
//
|
|
847
|
-
// back to the page's
|
|
949
|
+
// merges selections per slug. Each line carries its matched section and
|
|
950
|
+
// snippet terms; a candidate with no match text falls back to the page's
|
|
951
|
+
// lead-section snippet.
|
|
848
952
|
const stable = buildStable();
|
|
849
953
|
const finderTail: PoolCandidate[] = finder.map((c) => ({
|
|
850
954
|
slug: c.slug,
|
|
851
955
|
lane: c.lane,
|
|
956
|
+
section: c.section,
|
|
957
|
+
terms: c.terms,
|
|
852
958
|
descriptor:
|
|
853
959
|
c.descriptor.trim().length > 0
|
|
854
960
|
? c.descriptor
|
|
@@ -856,50 +962,57 @@ export async function orchestrate(
|
|
|
856
962
|
}));
|
|
857
963
|
|
|
858
964
|
// Step 3: a SINGLE forced-tool select over the cache-ordered pool. The
|
|
859
|
-
// selections come back slug-deduped (
|
|
860
|
-
//
|
|
861
|
-
//
|
|
965
|
+
// selections come back slug-deduped (`selectPool`'s contract).
|
|
966
|
+
// `selectorPrompt` is the (optionally overridden) instruction scaffold;
|
|
967
|
+
// `undefined` falls through to the bundled default.
|
|
862
968
|
const pool = { stable, finder: finderTail };
|
|
863
969
|
recordLatencySubSpan(
|
|
864
970
|
"v3_expand",
|
|
865
971
|
"Gate & edge expansion",
|
|
866
972
|
Date.now() - expandStartedAt,
|
|
867
973
|
);
|
|
974
|
+
const poolSize = stable.length + finderTail.length;
|
|
868
975
|
const { selections, keptAll } = await runSelection(pool);
|
|
869
|
-
recordSelection(selections,
|
|
976
|
+
recordSelection(selections, poolSize, keptAll);
|
|
870
977
|
|
|
871
978
|
return {
|
|
872
979
|
selections,
|
|
873
|
-
|
|
874
|
-
|
|
980
|
+
lanes: { core, hot, fresh, always, finder },
|
|
981
|
+
selectorRan: selectorRanOver(poolSize),
|
|
875
982
|
};
|
|
876
983
|
}
|
|
877
984
|
|
|
878
985
|
/**
|
|
879
|
-
* Resolve a dense-lane hit's matched ordinal to
|
|
880
|
-
*
|
|
881
|
-
* scan the article's sections for the matching ordinal. Returns
|
|
882
|
-
* when the article or ordinal is not in the index (e.g. the dense
|
|
883
|
-
* ahead of the in-memory rebuild).
|
|
986
|
+
* Resolve a dense-lane hit's matched ordinal to its index into
|
|
987
|
+
* `index.sections`. The dense store keys sections by `(article, ordinal)`, so
|
|
988
|
+
* we scan the article's sections for the matching ordinal. Returns
|
|
989
|
+
* `undefined` when the article or ordinal is not in the index (e.g. the dense
|
|
990
|
+
* store is ahead of the in-memory rebuild).
|
|
884
991
|
*/
|
|
885
|
-
|
|
992
|
+
function sectionDocByOrdinal(
|
|
886
993
|
index: SectionIndex,
|
|
887
994
|
article: Slug,
|
|
888
995
|
ordinal: number,
|
|
889
|
-
):
|
|
890
|
-
const
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
}
|
|
894
|
-
for (const i of indices) {
|
|
895
|
-
const section = index.sections[i];
|
|
896
|
-
if (section && section.ordinal === ordinal) {
|
|
897
|
-
return section;
|
|
996
|
+
): number | undefined {
|
|
997
|
+
for (const doc of index.byArticle.get(article) ?? []) {
|
|
998
|
+
if (index.sections[doc]?.ordinal === ordinal) {
|
|
999
|
+
return doc;
|
|
898
1000
|
}
|
|
899
1001
|
}
|
|
900
1002
|
return undefined;
|
|
901
1003
|
}
|
|
902
1004
|
|
|
1005
|
+
/** The concrete `Section` a dense-lane hit's ordinal resolves to; see
|
|
1006
|
+
* {@link sectionDocByOrdinal}. */
|
|
1007
|
+
export function sectionByOrdinal(
|
|
1008
|
+
index: SectionIndex,
|
|
1009
|
+
article: Slug,
|
|
1010
|
+
ordinal: number,
|
|
1011
|
+
): Section | undefined {
|
|
1012
|
+
const doc = sectionDocByOrdinal(index, article, ordinal);
|
|
1013
|
+
return doc === undefined ? undefined : index.sections[doc];
|
|
1014
|
+
}
|
|
1015
|
+
|
|
903
1016
|
/**
|
|
904
1017
|
* The text of an article's LEAD (first) section, or `""` when the article has
|
|
905
1018
|
* no indexed sections. Used as the finder-line snippet fallback when a
|