@vellumai/assistant 0.12.2-staging.7 → 0.12.2
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/docs/architecture/memory.md +2 -11
- package/docs/desktop-browser-cli.md +2 -4
- package/node_modules/@vellumai/environments/src/shell.test.ts +0 -21
- package/node_modules/@vellumai/environments/src/shell.ts +0 -24
- package/node_modules/@vellumai/gateway-client/src/inbound-contract.ts +2 -8
- package/openapi.yaml +2 -6
- package/package.json +1 -1
- package/scripts/smoke-desktop-browser-cli.ts +0 -1
- package/src/__tests__/agent-loop.test.ts +0 -124
- package/src/__tests__/approval-interception-trust-gates.test.ts +0 -40
- package/src/__tests__/channel-approval.test.ts +14 -9
- package/src/__tests__/conversation-agent-loop.test.ts +0 -25
- package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -0
- package/src/__tests__/run-conversation-turn-persistence.test.ts +1 -138
- package/src/__tests__/script-proxy-certs.test.ts +1 -1
- package/src/__tests__/subagent-tool-gate-mode.test.ts +0 -169
- package/src/__tests__/terminal-tools.test.ts +0 -8
- package/src/__tests__/unicode.test.ts +0 -36
- package/src/agent/loop.ts +0 -19
- package/src/api/index.ts +0 -6
- package/src/approvals/approval-primitive.ts +2 -5
- package/src/approvals/scoped-approval-grants.ts +2 -6
- package/src/daemon/__tests__/conversation-tool-setup.test.ts +0 -43
- package/src/daemon/conversation-agent-loop.ts +0 -2
- package/src/daemon/conversation-tool-setup.ts +1 -57
- package/src/daemon/conversation.ts +0 -17
- package/src/daemon/daemon-control.ts +6 -2
- package/src/daemon/orphan-reaper.ts +3 -4
- package/src/daemon/tool-setup-types.ts +0 -6
- package/src/daemon/wake-conversation-ops.ts +15 -38
- package/src/desktop/desktop-automation-lease.test.ts +0 -143
- package/src/desktop/desktop-automation-lease.ts +3 -39
- package/src/messaging/provider-message-metadata.ts +3 -3
- package/src/notifications/__tests__/copy-composer.test.ts +0 -70
- package/src/notifications/copy-composer.ts +3 -11
- package/src/oauth/seed-providers.ts +30 -0
- package/src/persistence/conversation-plugin-facade.ts +0 -13
- package/src/persistence/schema/index.ts +0 -1
- package/src/persistence/steps.ts +0 -2
- package/src/plugin-api/conversation-turn.ts +7 -31
- package/src/plugin-api/index.ts +1 -9
- package/src/plugins/defaults/memory/AGENTS.md +2 -14
- package/src/plugins/defaults/memory/__tests__/buffer-format.test.ts +0 -43
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +0 -46
- package/src/plugins/defaults/memory/buffer-format.ts +0 -40
- package/src/plugins/defaults/memory/context-search/agent-runner.ts +2 -1
- package/src/plugins/defaults/memory/context-search/format.ts +1 -2
- package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +1 -2
- package/src/plugins/defaults/memory/context-search/sources/workspace.ts +1 -2
- package/src/plugins/defaults/memory/graph/capability-seed.ts +2 -1
- package/src/plugins/defaults/memory/graph/tool-handlers.ts +42 -1
- package/src/plugins/defaults/memory/host-utils.ts +10 -0
- package/src/plugins/defaults/memory/injectors.ts +3 -4
- package/src/plugins/defaults/memory/memory-retrospective-job.ts +181 -55
- package/src/plugins/defaults/memory/substrate/__tests__/consolidation-job.test.ts +99 -407
- package/src/plugins/defaults/memory/substrate/__tests__/consolidation-prompt-flag-gating-guard.test.ts +0 -10
- package/src/plugins/defaults/memory/substrate/__tests__/prompts-consolidation.test.ts +7 -107
- package/src/plugins/defaults/memory/substrate/consolidation-job.ts +86 -307
- package/src/plugins/defaults/memory/substrate/page-index.ts +1 -2
- package/src/plugins/defaults/memory/substrate/prompts/consolidation.ts +49 -89
- package/src/plugins/defaults/memory/substrate/sweep-job.ts +1 -1
- package/src/plugins/defaults/memory/tools.ts +1 -1
- package/src/plugins/defaults/memory/v1/graph/consolidation.ts +2 -2
- package/src/plugins/defaults/memory/v1/graph/extraction.ts +1 -2
- package/src/plugins/defaults/memory/v1/graph/retriever.ts +1 -1
- package/src/plugins/defaults/memory/v2/__tests__/migration.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/__tests__/reranker.test.ts +2 -5
- package/src/plugins/defaults/memory/v2/reranker.ts +1 -2
- package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +1 -81
- package/src/plugins/defaults/memory/v3/__tests__/orchestrate.test.ts +0 -87
- package/src/plugins/defaults/memory/v3/__tests__/shadow-plugin.test.ts +0 -21
- package/src/plugins/defaults/memory/v3/card.ts +1 -2
- package/src/plugins/defaults/memory/v3/injector.ts +178 -212
- package/src/plugins/defaults/memory/v3/orchestrate.ts +22 -86
- package/src/plugins/defaults/memory/v3/pool-select.ts +7 -10
- package/src/plugins/defaults/memory/v3/sections.ts +1 -2
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +1 -10
- package/src/plugins/defaults/tool-result-truncate/terminal.ts +46 -1
- package/src/runtime/AGENTS.md +1 -1
- package/src/runtime/__tests__/agent-wake.test.ts +1 -86
- package/src/runtime/agent-wake.ts +4 -20
- package/src/runtime/guardian-action-service.ts +17 -2
- package/src/runtime/guardian-reply-router.ts +8 -1
- package/src/runtime/routes/channel-route-shared.ts +9 -1
- package/src/runtime/routes/desktop-setup-routes.test.ts +2 -2
- package/src/runtime/routes/desktop-setup-routes.ts +3 -7
- package/src/runtime/routes/guardian-approval-interception.ts +0 -24
- package/src/runtime/routes/inbound-message-handler.ts +3 -2
- package/src/runtime/routes/inbound-stages/background-dispatch.test.ts +1 -1
- package/src/runtime/routes/inbound-stages/background-dispatch.ts +4 -7
- package/src/schedule/run-script.ts +2 -2
- package/src/tools/host-terminal/host-shell.ts +6 -12
- package/src/tools/shared/filesystem/file-ops-service.ts +31 -1
- package/src/tools/shared/shell-output.test.ts +0 -10
- package/src/tools/shared/shell-output.ts +2 -14
- package/src/tools/skills/sandbox-runner.ts +2 -13
- package/src/tools/skills/scaffold-managed.ts +1 -2
- package/src/tools/terminal/__tests__/safe-env.test.ts +0 -29
- package/src/tools/terminal/safe-env.ts +1 -30
- package/src/tools/terminal/sanitized-bash.ts +2 -15
- package/src/tools/terminal/shell.test.ts +0 -29
- package/src/tools/terminal/shell.ts +7 -13
- package/src/util/host-process.test.ts +1 -17
- package/src/util/host-process.ts +0 -24
- package/src/util/unicode.ts +0 -29
- package/src/__tests__/db-conversation-tool-surface.test.ts +0 -144
- package/src/api/events/desktop-activity-changed.ts +0 -10
- package/src/persistence/conversation-tool-surface.ts +0 -86
- package/src/persistence/migrations/378-create-conversation-tool-surfaces.test.ts +0 -78
- package/src/persistence/migrations/378-create-conversation-tool-surfaces.ts +0 -29
- package/src/persistence/schema/conversation-tool-surfaces.ts +0 -22
- package/src/plugin-api/plugin-channel-turn-trust.test.ts +0 -133
- package/src/plugin-api/plugin-channel-turn-trust.ts +0 -71
- package/src/plugins/defaults/memory/__tests__/buffer-file.test.ts +0 -320
- package/src/plugins/defaults/memory/__tests__/fixtures/buffer-appender.ts +0 -17
- package/src/plugins/defaults/memory/__tests__/memory-run-evidence.test.ts +0 -161
- package/src/plugins/defaults/memory/buffer-file.ts +0 -354
- package/src/plugins/defaults/memory/memory-run-evidence.ts +0 -213
- package/src/plugins/defaults/memory/substrate/consolidation-tool-surface.ts +0 -34
- package/src/tools/terminal/shell-launch.test.ts +0 -162
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { safeStringSlice } from "@vellumai/plugin-api";
|
|
2
|
-
|
|
3
1
|
import { FRONTMATTER_REGEX, parseFrontmatterFields } from "../frontmatter.js";
|
|
2
|
+
import { safeStringSlice } from "../host-utils.js";
|
|
4
3
|
import { injectedConceptHeader } from "../substrate/injected-block-slugs.js";
|
|
5
4
|
import { LINK_SEPARATOR, parseLinkEntry } from "../substrate/page-links.js";
|
|
6
5
|
import type { Slug } from "./types.js";
|
|
@@ -173,22 +173,15 @@ export function memoryV3TurnMemoSizeForTests(): number {
|
|
|
173
173
|
return observedTurns.size;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
/** What the turn still got when the selector could not run: nothing (the
|
|
177
|
-
* orchestration itself failed) or the stable prefix unjudged. */
|
|
178
|
-
type MemoryV3DegradedScope = "none" | "stable-prefix";
|
|
179
|
-
|
|
180
176
|
function queueMemoryV3ConversationNotice(
|
|
181
177
|
err: MemoryV3RetrievalUnavailableError,
|
|
182
178
|
ctx: TurnContext,
|
|
183
|
-
scope: MemoryV3DegradedScope,
|
|
184
179
|
): void {
|
|
185
180
|
const notice: PendingConversationNotice = err.conversationNotice ?? {
|
|
186
181
|
source: "memory_v3",
|
|
187
182
|
code: "UNKNOWN",
|
|
188
183
|
userMessage:
|
|
189
|
-
|
|
190
|
-
? "Memory selection is temporarily unavailable, so this response draws only on your core memories. You can retry in a moment."
|
|
191
|
-
: "Memory is temporarily unavailable, so this response may not use your saved memories. You can retry in a moment.",
|
|
184
|
+
"Memory is temporarily unavailable, so this response may not use your saved memories. You can retry in a moment.",
|
|
192
185
|
errorCategory: "memory_v3_degraded",
|
|
193
186
|
};
|
|
194
187
|
queueConversationNotice(
|
|
@@ -331,7 +324,7 @@ export const memoryV3Injector: Injector = {
|
|
|
331
324
|
observed = await observeTurnOnce(ctx.conversationId, ctx.turnIndex);
|
|
332
325
|
} catch (err) {
|
|
333
326
|
if (err instanceof MemoryV3RetrievalUnavailableError) {
|
|
334
|
-
queueMemoryV3ConversationNotice(err, ctx
|
|
327
|
+
queueMemoryV3ConversationNotice(err, ctx);
|
|
335
328
|
log.error(
|
|
336
329
|
{
|
|
337
330
|
err: err.message,
|
|
@@ -343,220 +336,193 @@ export const memoryV3Injector: Injector = {
|
|
|
343
336
|
}
|
|
344
337
|
return null;
|
|
345
338
|
}
|
|
346
|
-
|
|
339
|
+
// Empty selection → return null (attach nothing). The user-prompt-submit
|
|
340
|
+
// hook skipped v2 retrieval under live, so a turn with nothing selected
|
|
341
|
+
// simply gets no v3 `<memory>` block (prior turns' frozen sections still
|
|
342
|
+
// ride history).
|
|
343
|
+
if (!observed || observed.selections.length === 0) {
|
|
347
344
|
return null;
|
|
348
345
|
}
|
|
349
|
-
const
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
346
|
+
// `const` so the non-null narrowing survives capture in the `commit`
|
|
347
|
+
// closure below (a `let` would re-widen to `OrchestrateResult | null`).
|
|
348
|
+
const result = observed;
|
|
349
|
+
|
|
350
|
+
try {
|
|
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)),
|
|
370
414
|
);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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
|
+
}
|
|
375
430
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
return null;
|
|
389
|
-
}
|
|
390
|
-
try {
|
|
391
|
-
// Partition this turn's injection units: each selected section under
|
|
392
|
-
// its own key, a page selected with none under `""` (its lead;
|
|
393
|
-
// capability content injects whole under `""` too).
|
|
394
|
-
// - A pair tombstoned since the turn's first produce is skipped: a
|
|
395
|
-
// re-entry never revives what the valve pruned.
|
|
396
|
-
// - On a re-entry assembly (`rendered` set by the first produce) an
|
|
397
|
-
// entry the first produce rendered is re-emitted from the memo byte
|
|
398
|
-
// for byte: the store counts it active, but its only copy rode the
|
|
399
|
-
// tail the re-injection strip cleared, so the store alone would
|
|
400
|
-
// read it as resident and drop it for the rest of the turn. A
|
|
401
|
-
// re-entry block carries no commit (and runtime assembly withholds
|
|
402
|
-
// one on a `reinjection` assembly besides), so a turn's sections
|
|
403
|
-
// are recorded once, at the first-call site; after a compaction they
|
|
404
|
-
// stay unclaimed until the next turn injects them net-new onto its
|
|
405
|
-
// own persisted message, and the newest-copy rule
|
|
406
|
-
// (`stripPrunedSectionsFromMessages`) retires the re-entry copy.
|
|
407
|
-
// - A pair active in the store is resident: a pointer entry, stamped
|
|
408
|
-
// with the turn's selection time below. Capability slugs are
|
|
409
|
-
// stamped too but left out of the pointer (no `memory/concepts/`
|
|
410
|
-
// path to point at).
|
|
411
|
-
// - Every other pair renders net-new, including one the first produce
|
|
412
|
-
// saw resident whose copy a compaction's store reset has since
|
|
413
|
-
// unclaimed (neither active nor tombstoned), in memory only.
|
|
414
|
-
// Under a run-messages replacement (`ctx.replacesRunMessages`: the
|
|
415
|
-
// Slack chronological transcript, rendered from persisted rows, so it
|
|
416
|
-
// carries no earlier turn's block) residency means nothing. The
|
|
417
|
-
// store's active set is not consulted, every pair renders or
|
|
418
|
-
// re-emits, none is pointed at, and the block carries no commit, so
|
|
419
|
-
// nothing is recorded or scheduled and runtime assembly attaches the
|
|
420
|
-
// block in memory only as the prompt's single copy. A Slack
|
|
421
|
-
// conversation whose transcript injector is absent is not replaced and
|
|
422
|
-
// injects as an ordinary committed turn.
|
|
423
|
-
const rendered = observedTurn(ctx.conversationId, ctx.turnIndex)?.rendered;
|
|
424
|
-
const firstProduce = rendered === undefined;
|
|
425
|
-
const replaced = ctx.replacesRunMessages === true;
|
|
426
|
-
const active = replaced ? null : getActiveSections(ctx.conversationId);
|
|
427
|
-
const pruned = firstProduce
|
|
428
|
-
? undefined
|
|
429
|
-
: getPrunedSections(ctx.conversationId);
|
|
430
|
-
const resident: SectionRef[] = [];
|
|
431
|
-
const slots: BlockSlot[] = [];
|
|
432
|
-
for (const { slug, key, matched } of injectionUnits(result.selections)) {
|
|
433
|
-
if (pruned && sectionRefSetHas(pruned, slug, key)) {
|
|
434
|
-
continue;
|
|
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
|
|
434
|
+
// them, so nothing is recorded either.
|
|
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]!;
|
|
435
443
|
}
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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 });
|
|
448
|
+
}
|
|
440
449
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
450
|
+
// Every net-new section rendered empty: return null rather than an
|
|
451
|
+
// empty-text block. Under live there is no v2 block, so the turn simply
|
|
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) {
|
|
456
|
+
return null;
|
|
444
457
|
}
|
|
445
|
-
slots.push({ slug, key, matched, text: undefined });
|
|
446
|
-
}
|
|
447
|
-
rememberPointerEntries(
|
|
448
|
-
ctx.conversationId,
|
|
449
|
-
ctx.turnIndex,
|
|
450
|
-
resident.filter(({ slug }) => !isCapabilitySlug(slug)),
|
|
451
|
-
);
|
|
452
|
-
// The turn's selection time, stamped on the resident pairs NOW, in the
|
|
453
|
-
// same synchronous segment as the classification above: the page reads
|
|
454
|
-
// below yield to the event loop, and a prune valve queued by an earlier
|
|
455
|
-
// turn's commit fires on a timer, so it can run while they are awaited
|
|
456
|
-
// and would otherwise rank a pair this turn is about by its stale
|
|
457
|
-
// stamp and evict it. The stamp is a recency bump, not a claim, so a
|
|
458
|
-
// turn whose block never attaches (or that returns null below because
|
|
459
|
-
// every net-new pair rendered empty) bumps harmlessly. Only the first
|
|
460
|
-
// produce stamps: a re-entry re-emits the turn's selections, and a
|
|
461
|
-
// run-messages replacement claims nothing (`resident` is empty there).
|
|
462
|
-
// The net-new pairs take the same time with their record in the commit.
|
|
463
|
-
const selectedAt = Date.now();
|
|
464
|
-
if (firstProduce) {
|
|
465
|
-
touchSelected(ctx.conversationId, resident, selectedAt);
|
|
466
|
-
}
|
|
467
458
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
for (const { slug, key, text } of slots) {
|
|
481
|
-
if (text !== undefined && text.trim().length > 0) {
|
|
482
|
-
entries.push({ slug, key, text });
|
|
459
|
+
// Empty net-new → empty-text block: assembly attaches no content
|
|
460
|
+
// (`applyInjectionBlock` no-ops empty text) but the block's presence
|
|
461
|
+
// still marks v3 as this turn's `<memory>` source for v2 suppression.
|
|
462
|
+
const inner = renderInjectionBlockInner(entries.map((e) => e.text));
|
|
463
|
+
const block: InjectionBlock = {
|
|
464
|
+
id: MEMORY_V3_BLOCK_ID,
|
|
465
|
+
text: inner.length === 0 ? "" : wrapMemoryBlock(inner),
|
|
466
|
+
// Mirror v2's dynamic `<memory>` block placement.
|
|
467
|
+
placement: "after-memory-prefix",
|
|
468
|
+
};
|
|
469
|
+
if (!firstProduce) {
|
|
470
|
+
return block;
|
|
483
471
|
}
|
|
484
|
-
}
|
|
485
|
-
// Every net-new section rendered empty: return null rather than an
|
|
486
|
-
// empty-text block. Under live there is no v2 block, so the turn simply
|
|
487
|
-
// gets no new memory. Distinct from the all-repeat case (empty
|
|
488
|
-
// `netNew`), where the empty block correctly keeps v2 suppressed
|
|
489
|
-
// because the sections already ride history.
|
|
490
|
-
if (netNew.length > 0 && entries.length === 0) {
|
|
491
|
-
return null;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// Empty net-new → empty-text block: assembly attaches no content
|
|
495
|
-
// (`applyInjectionBlock` no-ops empty text) but the block's presence
|
|
496
|
-
// still marks v3 as this turn's `<memory>` source for v2 suppression.
|
|
497
|
-
const inner = renderInjectionBlockInner(entries.map((e) => e.text));
|
|
498
|
-
const block: InjectionBlock = {
|
|
499
|
-
id: MEMORY_V3_BLOCK_ID,
|
|
500
|
-
text: inner.length === 0 ? "" : wrapMemoryBlock(inner),
|
|
501
|
-
// Mirror v2's dynamic `<memory>` block placement.
|
|
502
|
-
placement: "after-memory-prefix",
|
|
503
|
-
};
|
|
504
|
-
if (!firstProduce) {
|
|
505
|
-
return block;
|
|
506
|
-
}
|
|
507
472
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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 } };
|
|
514
|
+
} catch (err) {
|
|
515
|
+
log.warn(
|
|
516
|
+
{
|
|
517
|
+
err: err instanceof Error ? err.message : String(err),
|
|
518
|
+
conversationId: ctx.conversationId,
|
|
519
|
+
},
|
|
520
|
+
"memory-v3 live render failed (non-fatal) — returning null (no v3 block this turn)",
|
|
545
521
|
);
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
log.warn(
|
|
551
|
-
{
|
|
552
|
-
err: err instanceof Error ? err.message : String(err),
|
|
553
|
-
conversationId: ctx.conversationId,
|
|
554
|
-
},
|
|
555
|
-
"memory-v3 live render failed (non-fatal) — returning null (no v3 block this turn)",
|
|
556
|
-
);
|
|
557
|
-
return null;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
};
|
|
560
526
|
|
|
561
527
|
export const memoryV3PointerInjector: Injector = {
|
|
562
528
|
name: "memory-v3-pointer",
|
|
@@ -89,11 +89,7 @@ import type {
|
|
|
89
89
|
SelectorPool,
|
|
90
90
|
StableCandidate,
|
|
91
91
|
} from "./pool-select.js";
|
|
92
|
-
import {
|
|
93
|
-
MemoryV3RetrievalUnavailableError,
|
|
94
|
-
selectAllPoolCandidates,
|
|
95
|
-
selectPool,
|
|
96
|
-
} from "./pool-select.js";
|
|
92
|
+
import { selectAllPoolCandidates, selectPool } from "./pool-select.js";
|
|
97
93
|
import {
|
|
98
94
|
type RareTermHit,
|
|
99
95
|
rareTermLane,
|
|
@@ -343,20 +339,12 @@ export interface OrchestrateResult {
|
|
|
343
339
|
lanes: OrchestrateLanes;
|
|
344
340
|
/** Whether the selector LLM judged a non-empty pool this turn (the
|
|
345
341
|
* `selector_ran` telemetry field). False when the pool was empty, when the
|
|
346
|
-
* disabled-selector passthrough kept every candidate, when a closed
|
|
347
|
-
* injection gate hard-skipped selection
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* means the selector was given nothing. */
|
|
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. */
|
|
352
347
|
selectorRan: boolean;
|
|
353
|
-
/** Set when the selector could not be run this turn (provider unavailable,
|
|
354
|
-
* or no usable tool call after the re-prompt retries). `selections` then
|
|
355
|
-
* holds the stable prefix unjudged; finder candidates are dropped because
|
|
356
|
-
* they are evidence for a judge, not evidence to inject on their own. The
|
|
357
|
-
* live injector queues a notice so the person knows this turn drew on
|
|
358
|
-
* core memories only. */
|
|
359
|
-
selectorFailure?: MemoryV3RetrievalUnavailableError;
|
|
360
348
|
}
|
|
361
349
|
|
|
362
350
|
/** Stable-order de-duplication preserving first occurrence. */
|
|
@@ -414,55 +402,19 @@ export async function orchestrate(
|
|
|
414
402
|
// selector's recall-safe fallback ONLY — the disabled passthrough is not a
|
|
415
403
|
// selector judgment, so it reports `false` (its turns are excluded from any
|
|
416
404
|
// relevance read by `selector_ran` anyway).
|
|
417
|
-
//
|
|
418
|
-
// A selector that cannot run at all (provider unavailable, or no usable
|
|
419
|
-
// tool call after the re-prompt retries) keeps the stable prefix unjudged
|
|
420
|
-
// and drops the finder candidates: the stable cards are
|
|
421
|
-
// conversation-independent and already sit in every turn's pool, while a
|
|
422
|
-
// finder line is evidence for a judge, not evidence to inject on its own.
|
|
423
|
-
// The failure rides the result so the injector can tell the person this
|
|
424
|
-
// turn drew on core memories only.
|
|
425
405
|
const runSelection = (
|
|
426
406
|
pool: SelectorPool,
|
|
427
|
-
): Promise<{
|
|
428
|
-
selections: SelectedPage[];
|
|
429
|
-
keptAll: boolean;
|
|
430
|
-
failure?: MemoryV3RetrievalUnavailableError;
|
|
431
|
-
}> =>
|
|
407
|
+
): Promise<{ selections: SelectedPage[]; keptAll: boolean }> =>
|
|
432
408
|
timeLatencySubSpan("v3_selection", "Memory selection", async () => {
|
|
433
409
|
if (deps.selectorEnabled === false) {
|
|
434
410
|
return { selections: selectAllPoolCandidates(pool), keptAll: false };
|
|
435
411
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
return { selections: pages, keptAll };
|
|
443
|
-
} catch (err) {
|
|
444
|
-
if (!(err instanceof MemoryV3RetrievalUnavailableError)) {
|
|
445
|
-
throw err;
|
|
446
|
-
}
|
|
447
|
-
log.warn(
|
|
448
|
-
{
|
|
449
|
-
conversationId: turn.conversationId,
|
|
450
|
-
turnNumber: turn.turnNumber,
|
|
451
|
-
stableCount: pool.stable.length,
|
|
452
|
-
finderCount: pool.finder.length,
|
|
453
|
-
err: err.message,
|
|
454
|
-
},
|
|
455
|
-
"memory-v3 selector unavailable; keeping the stable prefix unjudged",
|
|
456
|
-
);
|
|
457
|
-
return {
|
|
458
|
-
selections: selectAllPoolCandidates({
|
|
459
|
-
stable: pool.stable,
|
|
460
|
-
finder: [],
|
|
461
|
-
}),
|
|
462
|
-
keptAll: false,
|
|
463
|
-
failure: err,
|
|
464
|
-
};
|
|
465
|
-
}
|
|
412
|
+
const { pages, keptAll } = await selectPool(
|
|
413
|
+
pool,
|
|
414
|
+
turn,
|
|
415
|
+
deps.selectorPrompt,
|
|
416
|
+
);
|
|
417
|
+
return { selections: pages, keptAll };
|
|
466
418
|
});
|
|
467
419
|
|
|
468
420
|
// Step 1: needle (sync BM25) and the enabled dense lane (async embed +
|
|
@@ -808,22 +760,17 @@ export async function orchestrate(
|
|
|
808
760
|
// Omitted when the caller did not supply `isResident` (tests,
|
|
809
761
|
// shadow-less paths). The count reads the same units the injector will
|
|
810
762
|
// (a closed gate's selections carry no sections, so it counts leads).
|
|
811
|
-
const selectorRanOver = (
|
|
812
|
-
poolSize
|
|
813
|
-
failure?: MemoryV3RetrievalUnavailableError,
|
|
814
|
-
): boolean =>
|
|
815
|
-
deps.selectorEnabled !== false && poolSize > 0 && failure === undefined;
|
|
763
|
+
const selectorRanOver = (poolSize: number): boolean =>
|
|
764
|
+
deps.selectorEnabled !== false && poolSize > 0;
|
|
816
765
|
const recordSelection = (
|
|
817
766
|
selections: SelectedPage[],
|
|
818
767
|
poolSize: number,
|
|
819
768
|
keptAll: boolean,
|
|
820
|
-
failure?: MemoryV3RetrievalUnavailableError,
|
|
821
769
|
): void => {
|
|
822
770
|
const detail: Record<string, unknown> = {
|
|
823
771
|
gate_reason: gateOutcome?.reason ?? null,
|
|
824
772
|
gate_pass: gateOutcome?.pass ?? null,
|
|
825
|
-
selector_ran: selectorRanOver(poolSize
|
|
826
|
-
selector_failed: failure !== undefined,
|
|
773
|
+
selector_ran: selectorRanOver(poolSize),
|
|
827
774
|
selector_kept_all: keptAll,
|
|
828
775
|
selected_count: selections.length,
|
|
829
776
|
pool_size: poolSize,
|
|
@@ -898,12 +845,10 @@ export async function orchestrate(
|
|
|
898
845
|
const closed = (
|
|
899
846
|
selections: SelectedPage[],
|
|
900
847
|
selectorRan: boolean,
|
|
901
|
-
selectorFailure?: MemoryV3RetrievalUnavailableError,
|
|
902
848
|
): OrchestrateResult => ({
|
|
903
849
|
selections,
|
|
904
850
|
lanes: { core, hot, fresh, always, finder: [] },
|
|
905
851
|
selectorRan,
|
|
906
|
-
...(selectorFailure ? { selectorFailure } : {}),
|
|
907
852
|
});
|
|
908
853
|
if (deps.gateConfig.bypassForCore) {
|
|
909
854
|
// Select over the stable prefix only. `runSelection` mirrors the
|
|
@@ -916,20 +861,12 @@ export async function orchestrate(
|
|
|
916
861
|
// `denseK > 0` (the dense-gated gate only runs with dense hits; the
|
|
917
862
|
// new-user profile sets `denseK: 0`, so the gate never runs for it).
|
|
918
863
|
const stableOnly = buildStable();
|
|
919
|
-
const {
|
|
920
|
-
selections: bypassed,
|
|
921
|
-
keptAll,
|
|
922
|
-
failure,
|
|
923
|
-
} = await runSelection({
|
|
864
|
+
const { selections: bypassed, keptAll } = await runSelection({
|
|
924
865
|
stable: stableOnly,
|
|
925
866
|
finder: [],
|
|
926
867
|
});
|
|
927
|
-
recordSelection(bypassed, stableOnly.length, keptAll
|
|
928
|
-
return closed(
|
|
929
|
-
bypassed,
|
|
930
|
-
selectorRanOver(stableOnly.length, failure),
|
|
931
|
-
failure,
|
|
932
|
-
);
|
|
868
|
+
recordSelection(bypassed, stableOnly.length, keptAll);
|
|
869
|
+
return closed(bypassed, selectorRanOver(stableOnly.length));
|
|
933
870
|
}
|
|
934
871
|
// Hard skip: the selector is never consulted, so this is a zero
|
|
935
872
|
// selection BY CONSTRUCTION, not a judgment that nothing was relevant.
|
|
@@ -1035,14 +972,13 @@ export async function orchestrate(
|
|
|
1035
972
|
Date.now() - expandStartedAt,
|
|
1036
973
|
);
|
|
1037
974
|
const poolSize = stable.length + finderTail.length;
|
|
1038
|
-
const { selections, keptAll
|
|
1039
|
-
recordSelection(selections, poolSize, keptAll
|
|
975
|
+
const { selections, keptAll } = await runSelection(pool);
|
|
976
|
+
recordSelection(selections, poolSize, keptAll);
|
|
1040
977
|
|
|
1041
978
|
return {
|
|
1042
979
|
selections,
|
|
1043
980
|
lanes: { core, hot, fresh, always, finder },
|
|
1044
|
-
selectorRan: selectorRanOver(poolSize
|
|
1045
|
-
...(failure ? { selectorFailure: failure } : {}),
|
|
981
|
+
selectorRan: selectorRanOver(poolSize),
|
|
1046
982
|
};
|
|
1047
983
|
}
|
|
1048
984
|
|