dsh-cross-memory 0.2.2 → 0.2.4

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.
@@ -102,15 +102,16 @@ test('a recall that fires, and a near miss that is refused, both reach the log',
102
102
  await runtime.write(session, { scope: 'global', title: 'Prefer pnpm', body: 'Use pnpm, not npm.', tags: [] }, 'tool');
103
103
  await runtime.recallFor(stubAgent(session));
104
104
  assert.ok(lines.some((line) => line.includes('recalled')), `a fired delta is logged at info, got: ${lines.join(' | ')}`);
105
- // The refusal that hides a mis-tuned gate: the memory CLEARS the relevance
106
- // floor and is still turned away by the evidence gate. Reported once per
107
- // conversation so it cannot become noise on a long session.
105
+ // The refusal that hides a mis-tuned gate: the memory clears the lowered
106
+ // relevance floor through its BODY and is still turned away by the evidence
107
+ // gate (no strong-field term). Reported once per conversation so it cannot
108
+ // become noise on a long session.
108
109
  const { runtime: other, lines: otherLines } = await loggedFixture(t);
109
- const gated = stubSession(process.cwd(), '该插件是否有日志');
110
- // Tagged with the shared word, so the turn really does clear the relevance
111
- // floor: that is what makes the refusal the evidence gate's doing, and what
112
- // makes it worth a line in the log.
113
- await other.write(gated, { scope: 'global', title: '插件注册顺序', body: '插件在启动时注册。'.repeat(6), tags: ['插件'] }, 'tool');
110
+ const gated = stubSession(process.cwd(), '日志在哪里看');
111
+ // The shared word lives only in the body: it clears the relevance floor
112
+ // (minScore * ALIAS_FLOOR_SHARE) without earning a strong term, which is what
113
+ // makes the refusal the evidence gate's doing and worth a line in the log.
114
+ await other.write(gated, { scope: 'global', title: '插件注册顺序', body: '插件在启动时注册,日志文件在启动时生成,日志路径可以在配置里改,日志级别分三档。', tags: ['插件'] }, 'tool');
114
115
  await other.recallFor(stubAgent(gated));
115
116
  const nearMisses = () => otherLines.filter((line) => line.includes('near miss worth reading')).length;
116
117
  assert.equal(nearMisses(), 1, 'the refused-but-close case is reported');
@@ -138,17 +139,17 @@ test('an on-demand delta surfaces the memory the current turn matches', async (t
138
139
  test('a delta is injected once per entry and capped per conversation', async (t) => {
139
140
  const { runtime } = await fixture(t);
140
141
  const session = stubSession(process.cwd(), 'pnpm');
141
- await runtime.write(session, { scope: 'global', title: 'Prefer pnpm', body: 'Use pnpm.', tags: [] }, 'tool');
142
142
  const agent = stubAgent(session);
143
- assert.ok(await runtime.recallFor(agent) !== undefined);
143
+ await runtime.write(session, { scope: 'global', title: 'Prefer pnpm', body: 'Use pnpm.', tags: [] }, 'tool');
144
+ assert.ok(await runtime.recallFor(agent) !== undefined, 'the first entry earns a delta');
144
145
  assert.equal(await runtime.recallFor(agent), undefined, 'the same entry is never repeated');
145
- await runtime.write(session, { scope: 'global', title: 'pnpm hoisting', body: 'Hoist pnpm deps.', tags: [] }, 'tool');
146
- assert.ok(await runtime.recallFor(agent) !== undefined, 'a second unseen entry still fits');
147
- await runtime.write(session, { scope: 'global', title: 'pnpm store', body: 'Share the pnpm store.', tags: [] }, 'tool');
148
- assert.ok(await runtime.recallFor(agent) !== undefined, 'up to three');
149
- await runtime.write(session, { scope: 'global', title: 'pnpm audit', body: 'Audit pnpm deps.', tags: [] }, 'tool');
150
- assert.ok(await runtime.recallFor(agent) !== undefined, 'the fourth memory still fits the default cap');
151
- await runtime.write(session, { scope: 'global', title: 'pnpm dedupe', body: 'Dedupe pnpm deps.', tags: [] }, 'tool');
146
+ // The default cap is 8 deltas per conversation. One entry per turn keeps the
147
+ // count unambiguous: each turn recalls exactly the entry that just arrived.
148
+ for (let index = 0; index < 7; index += 1) {
149
+ await runtime.write(session, { scope: 'global', title: `pnpm note ${index}`, body: `Note ${index} about pnpm.`, tags: [] }, 'tool');
150
+ assert.ok(await runtime.recallFor(agent) !== undefined, `entry ${index + 2} still fits the default cap`);
151
+ }
152
+ await runtime.write(session, { scope: 'global', title: 'pnpm overflow', body: 'Overflow note about pnpm.', tags: [] }, 'tool');
152
153
  assert.equal(await runtime.recallFor(agent), undefined, 'the cap stops further deltas');
153
154
  });
154
155
  test('one delta carries every memory the same turn matches, best first', async (t) => {
@@ -193,6 +194,40 @@ test('the delta byte budget bounds one block instead of dropping it', async (t)
193
194
  assert.ok(listed >= 1, 'at least one memory is listed');
194
195
  assert.ok(listed < 8, 'and the budget stopped it short of the whole store');
195
196
  });
197
+ test('a turn that shares only one alias still recalls, and says how it matched', async (t) => {
198
+ const { runtime } = await fixture(t);
199
+ const session = stubSession(process.cwd(), '理零票第一步');
200
+ await runtime.write(session, {
201
+ scope: 'global',
202
+ title: '本仓是一个 pnpm 工作区',
203
+ body: '统一用 pnpm,不要跑 npm install。',
204
+ tags: [],
205
+ keys: ['零票'],
206
+ appliesTo: '整理票据时',
207
+ }, 'tool');
208
+ const message = await runtime.recallFor(stubAgent(session));
209
+ const text = blockText(message);
210
+ // It fires at all: the strict gate refuses this turn (one shared term scoring
211
+ // below the relevance floor), so without the alias pass this is silence.
212
+ assert.match(text, /pnpm 工作区/u);
213
+ // And it announces the weaker match, because a one-word hit read as a strong
214
+ // one is exactly the misreading the annotation exists to prevent.
215
+ assert.match(text, /按别名/u);
216
+ });
217
+ test('a memory the turn only shares body words with is not recalled', async (t) => {
218
+ const { runtime } = await fixture(t);
219
+ const session = stubSession(process.cwd(), '前缀缓存会不会被打断');
220
+ await runtime.write(session, {
221
+ scope: 'global',
222
+ title: '读项目约定再动代码',
223
+ body: '前缀缓存很脆弱,别动它。',
224
+ tags: [],
225
+ appliesTo: '动手之前',
226
+ }, 'tool');
227
+ // The alias pass must not widen what counts as a match: body words are the
228
+ // weakest claim in the store and it never reads them.
229
+ assert.equal(await runtime.recallFor(stubAgent(session)), undefined);
230
+ });
196
231
  test('a bare acknowledgement does not trigger a store scan', async (t) => {
197
232
  const { runtime } = await fixture(t, { recallMinQueryChars: 2 });
198
233
  const session = stubSession(process.cwd(), '好');
@@ -232,23 +267,21 @@ test('a Chinese turn reaches a memory it names in two non-adjacent pairs', async
232
267
  assert.ok(delta !== undefined, 'two shared topic pairs are enough, adjacent or not');
233
268
  assert.match(textOf(delta), /把混装的工作区改动拆成两笔提交/u);
234
269
  });
235
- test('a Chinese turn that only shares common pairs recalls nothing', async (t) => {
270
+ test('a Chinese turn that shares one pair recalls only when the pair clears the floor', async (t) => {
236
271
  const { runtime } = await fixture(t);
237
272
  const session = stubSession(process.cwd(), '该插件是否有日志');
238
- // Shares the isolated pair 插件 with the question and nothing longer. It also
239
- // scores 12, above any floor low enough to admit a paraphrase, so a score
240
- // threshold cannot be the thing that keeps this out — the evidence gate is.
273
+ // Shares the isolated pair 插件 with the question and nothing longer. The
274
+ // default gate is now one term plus the relevance floor, so this recalls: the
275
+ // pair is in the title, and the body word 日志 is not evidence by itself.
241
276
  await runtime.write(session, {
242
277
  scope: 'global',
243
278
  title: '插件注册顺序',
244
279
  body: '插件在启动时注册,日志级别由配置决定。',
245
280
  tags: [],
246
281
  }, 'tool');
247
- assert.equal(await runtime.recallFor(stubAgent(session)), undefined, 'the same characters are not the same phrase');
248
- // One pair is one term, and recall needs two. The body also says 日志, but a
249
- // body word is not evidence: a long memory mentions many things.
250
- const counted = matchCredit((await runtime.search(session, '该插件是否有日志', { limit: 1 }))[0].entry, '该插件是否有日志', 9, 2);
251
- assert.equal(counted.evidence.strongTerms, 1, 'exactly one pair is credited, and it is not enough');
282
+ assert.ok(await runtime.recallFor(stubAgent(session)) !== undefined, 'one shared pair that clears the floor recalls');
283
+ const counted = matchCredit((await runtime.search(session, '该插件是否有日志', { limit: 1 }))[0].entry, '该插件是否有日志', 6, 1);
284
+ assert.equal(counted.evidence.strongTerms, 1, 'exactly one pair is credited');
252
285
  });
253
286
  test('appliesTo is what makes a memory reachable when the title shares no noun', async (t) => {
254
287
  const { runtime } = await fixture(t);
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import assert from 'node:assert/strict';
14
14
  import test from 'node:test';
15
- import { tokenize, termWeight, relevanceOf, relevanceOfOne, searchMemories, FIELD_WEIGHTS, TERM_WEIGHTS } from '../search.js';
15
+ import { ALIAS_FLOOR_SHARE, matchCredit, suggestAliases, tokenize, termWeight, relevanceOf, relevanceOfOne, searchMemories, FIELD_WEIGHTS, TERM_WEIGHTS } from '../search.js';
16
16
  import { isSubstantiveTurn, queryMessages } from '../query.js';
17
17
  /** Build one corpus entry. */
18
18
  function entry(id, title, body, extra = {}, kind = 'fact') {
@@ -140,3 +140,48 @@ test('a turn with no letters, digits, or ideographs is not worth a scan', () =>
140
140
  assert.equal(isSubstantiveTurn(' ... '), false);
141
141
  assert.equal(isSubstantiveTurn(''), false);
142
142
  });
143
+ test('a query that finds nothing is answered with the aliases the store uses', () => {
144
+ // Filed under the product's words, not the user's: the search cannot bridge
145
+ // that gap, so the useful answer names the vocabulary instead of nothing.
146
+ const aliased = entry('prompt-cache', '先读项目约定再动代码', '动手之前先看约定,别直接改。', { keys: ['前缀缓存'], tags: ['prompt'] });
147
+ const groups = [{ scope: 'global', label: 'global', entries: [...CORPUS, aliased] }];
148
+ assert.equal(suggestAliases(groups, '完全无关的一句话', 5)[0]?.term !== undefined, true);
149
+ const shared = suggestAliases(groups, '前缀缓存会不会被打断', 5);
150
+ assert.equal(shared[0]?.term, '前缀缓存');
151
+ assert.ok(shared[0].matched > 0);
152
+ // With no overlap at all the most widely carried terms are still offered:
153
+ // a hint is vocabulary, not a claim, so a fallback list is not a false match.
154
+ const fallback = suggestAliases(groups, 'zzz', 3);
155
+ assert.equal(fallback.length, 3);
156
+ assert.equal(fallback[0]?.matched, 0);
157
+ assert.equal(suggestAliases([{ scope: 'global', label: 'global', entries: [] }], 'x', 5).length, 0);
158
+ });
159
+ test('the alias fallback credits one substantive alias term, and only when the entry files it', () => {
160
+ const floor = 9;
161
+ const aliasFloor = floor * ALIAS_FLOOR_SHARE;
162
+ const base = { id: 'probe', scope: 'global', kind: 'fact', title: '', body: '详情见项目文档。', tags: [], keys: [], createdAt: 0, updatedAt: 0, uses: 0, lastUsedAt: 0, lastSurfacedAt: 0, source: 'auto' };
163
+ const credit = (candidate, query) => ({
164
+ strict: matchCredit(candidate, query, floor, 2, {}).about,
165
+ alias: matchCredit(candidate, query, aliasFloor, 1, { fields: ['keys', 'appliesTo'] }).about,
166
+ relevance: matchCredit(candidate, query, aliasFloor, 1, { fields: ['keys', 'appliesTo'] }).relevance,
167
+ });
168
+ // The case the fallback exists for: the turn names the memory by its other
169
+ // name and shares exactly one term, which the two-term gate refuses.
170
+ const latin = credit({ ...base, title: '本仓是一个 pnpm 工作区', keys: ['monorepo'], appliesTo: '配置 monorepo 工作区时' }, 'monorepo 该怎么配');
171
+ assert.equal(latin.strict, false);
172
+ assert.equal(latin.alias, true);
173
+ // And the reason the floor is scaled rather than shared: one CJK alias term
174
+ // earns 6 here, below the normal 9, so the full floor would have made this
175
+ // pass fire for English turns and never for Chinese ones.
176
+ const cjk = credit({ ...base, title: '网关配置说明', keys: ['端口'], appliesTo: '排查端口冲突时' }, '端口被占用');
177
+ assert.equal(cjk.strict, false);
178
+ assert.equal(cjk.alias, true);
179
+ assert.ok(cjk.relevance < floor && cjk.relevance > aliasFloor);
180
+ // One filed field is not enough: the alias has to be recorded in two of them.
181
+ const keysOnly = credit({ ...base, title: '网关配置说明', keys: ['端口'], appliesTo: '排查冲突时' }, '端口被占用');
182
+ assert.equal(keysOnly.strict, false);
183
+ assert.equal(keysOnly.alias, false);
184
+ // A body mention is never an alias: a long memory mentions many things.
185
+ const bodyOnly = credit({ ...base, title: '读项目约定再动代码', body: '前缀缓存很脆弱,别动它。', appliesTo: '动手之前' }, '前缀缓存会不会被打断');
186
+ assert.equal(bodyOnly.alias, false);
187
+ });
@@ -138,8 +138,11 @@ test('the rotation block gives both scopes a share', async (t) => {
138
138
  await rm(dir, { recursive: true, force: true });
139
139
  });
140
140
  const agent = stubAgent(stubSession(dir));
141
- await seed(runtime, agent.session, 30, 'global memory');
142
- for (let index = 0; index < 20; index += 1) {
141
+ // The summary now lists up to 20 entries per scope, so the rotation needs a
142
+ // store larger than that to have anything left to rotate: 60 global + 40 project
143
+ // leaves 40 + 20 unseen after the summary, and the block gives both a share.
144
+ await seed(runtime, agent.session, 60, 'global memory');
145
+ for (let index = 0; index < 40; index += 1) {
143
146
  await runtime.write(agent.session, {
144
147
  scope: 'project',
145
148
  title: `project memory ${index}`,
@@ -125,6 +125,14 @@ test('the check is not vacuous: a descriptor with an undefined label is rejected
125
125
  // test fails; if this checker stops catching undefined, this one does.
126
126
  assert.throws(() => assertLossless({ version: 1, mode: 'continuable', provider: 'spawn', label: undefined }), /not losslessly JSON-serializable/u);
127
127
  });
128
+ test("the child's result is delivered to the caller, not announced to the parent inbox", () => {
129
+ // The pass awaits `run.result` itself. With the default `parent` delivery the
130
+ // kernel also pushes a settlement message into the parent's inbox, and a child
131
+ // that answers in plain text instead of calling `structured_output` is marked
132
+ // `error` — so a perfectly good plan arrived as "Background subagent failed".
133
+ const spec = buildActivationSpec(routedRequest(), PROMPT, AbortSignal.timeout(1_000));
134
+ assert.equal(spec.delivery, 'caller');
135
+ });
128
136
  test('the spec carries the signal at the top level, where the kernel reads it', () => {
129
137
  // The kernel's continuable path calls `spec.signal.throwIfAborted()` and passes
130
138
  // `spec.signal` into prepareContinuable; it never looks at `spec.request.signal`.
@@ -13,7 +13,7 @@ import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
13
13
  import { hostname, tmpdir } from 'node:os';
14
14
  import { join } from 'node:path';
15
15
  import test from 'node:test';
16
- import { MemorySync, STORE_GITIGNORE, entryStamp, isEntryPath, isHostDescriptorPath, isSessionNotePath, mergeLoopLedgers, newerEntry, newerHostDescriptor, newerSessionNote, nextClockDelay } from '../sync.js';
16
+ import { MemorySync, STORE_GITIGNORE, entryStamp, isEntryPath, isHostDescriptorPath, isPersonaPath, isSessionNotePath, mergeLoopLedgers, mergePersona, newerEntry, newerHostDescriptor, newerSessionNote, nextClockDelay } from '../sync.js';
17
17
  import { applyConflictPlan, isArchivedEntryPath, projectRootOf } from '../sync-runtime.js';
18
18
  import { slugify } from '../storage.js';
19
19
  /** A logger that swallows everything; tests assert on git state, not log text. */
@@ -222,6 +222,51 @@ test('a conflicting host descriptor keeps the newer reading', () => {
222
222
  assert.equal(isHostDescriptorPath('projects/a/project.json'), false);
223
223
  assert.equal(isHostDescriptorPath('entries/hosts/note.md'), false);
224
224
  });
225
+ test('a persona file merges as a bullet union, section by section', () => {
226
+ const ours = ['## 他怎么工作', '- 中文交流', '- 改完自己验', '', '## 他的标准', '- 讨厌假动作', ''].join('\n');
227
+ const theirs = ['## 他怎么工作', '- 中文交流', '- 一条只有 PC 记下的工作方式', '', '## 他的标准', '- 讨厌假动作', '- 一条只有 PC 记下的标准', ''].join('\n');
228
+ const merged = mergePersona(ours, theirs);
229
+ assert.match(merged, /中文交流/u);
230
+ assert.match(merged, /一条只有 PC 记下的工作方式/u);
231
+ assert.match(merged, /一条只有 PC 记下的标准/u);
232
+ assert.equal((merged.match(/- 中文交流/gu) ?? []).length, 1, 'duplicates are dropped');
233
+ assert.ok(merged.indexOf('一条只有 PC 记下的工作方式') < merged.indexOf('## 他的标准'), 'a bullet stays in its own section');
234
+ assert.equal(isPersonaPath('persona/human.md'), true);
235
+ assert.equal(isPersonaPath('entries/one.md'), false);
236
+ });
237
+ test('a modify/delete conflict keeps the edited file instead of aborting the sync', async () => {
238
+ const { remote, left, right } = await twoWayFixture();
239
+ await mkdir(join(left.dir, 'entries'), { recursive: true });
240
+ await writeFile(join(left.dir, 'entries', 'doomed.md'), entryText('doomed', 'left version', '2026-02-01T00:00:00.000Z'));
241
+ await left.sync.run('test');
242
+ await right.sync.run('test');
243
+ // left retires the row; right edits it in parallel
244
+ await rm(join(left.dir, 'entries', 'doomed.md'));
245
+ await left.sync.run('test');
246
+ await writeFile(join(right.dir, 'entries', 'doomed.md'), entryText('doomed', 'right edit survives', '2026-03-01T00:00:00.000Z'));
247
+ const outcome = await right.sync.run('test');
248
+ assert.equal(outcome.pushed, true, 'the delete/modify conflict no longer blocks the push');
249
+ assert.match(await readFile(join(right.dir, 'entries', 'doomed.md'), 'utf8'), /right edit survives/u);
250
+ assert.match(execFileSync('git', ['-C', remote, 'show', 'main:entries/doomed.md'], { encoding: 'utf8' }), /right edit survives/u);
251
+ assert.equal(git(right.dir, 'status', '--porcelain').trim(), '', 'the store is not left mid-rebase');
252
+ });
253
+ test('two machines appending persona bullets both survive the sync', async () => {
254
+ const { remote, left, right } = await twoWayFixture();
255
+ await mkdir(join(left.dir, 'persona'), { recursive: true });
256
+ await writeFile(join(left.dir, 'persona', 'human.md'), ['## 他怎么工作', '- 中文交流', ''].join('\n'));
257
+ await left.sync.run('test');
258
+ await right.sync.run('test');
259
+ await writeFile(join(left.dir, 'persona', 'human.md'), ['## 他怎么工作', '- 中文交流', '- 左机的规则', ''].join('\n'));
260
+ await left.sync.run('test');
261
+ await writeFile(join(right.dir, 'persona', 'human.md'), ['## 他怎么工作', '- 中文交流', '- 右机的规则', ''].join('\n'));
262
+ const outcome = await right.sync.run('test');
263
+ assert.equal(outcome.pushed, true);
264
+ const persona = await readFile(join(right.dir, 'persona', 'human.md'), 'utf8');
265
+ assert.match(persona, /左机的规则/u);
266
+ assert.match(persona, /右机的规则/u);
267
+ assert.match(execFileSync('git', ['-C', remote, 'show', 'main:persona/human.md'], { encoding: 'utf8' }), /右机的规则/u);
268
+ assert.equal(git(right.dir, 'status', '--porcelain').trim(), '');
269
+ });
225
270
  test('the clock schedule picks the next local time, and wraps to tomorrow', () => {
226
271
  const noon = new Date(2026, 9, 26, 12, 0, 0).getTime();
227
272
  assert.equal(nextClockDelay(['12:05'], noon), 5 * 60_000, 'five minutes after noon');
package/lib/tool.js CHANGED
@@ -209,10 +209,18 @@ export function registerMemoryTool(ctx, runtime) {
209
209
  ? await runtime.browse(session, filters)
210
210
  : await runtime.search(session, query, filters);
211
211
  if (hits.length === 0) {
212
+ // Search is lexical, so a miss can mean "filed under another name"
213
+ // rather than "not recorded". Handing back the aliases and tags the
214
+ // store actually uses lets the caller retry with its vocabulary
215
+ // instead of concluding the fact is absent.
216
+ const hints = query.length === 0 ? [] : await runtime.aliasHints(session, query, 12).catch(() => []);
217
+ const vocabulary = hints.length === 0
218
+ ? ''
219
+ : ` The store files memories under these aliases/tags: ${hints.map((hint) => hint.term).join(', ')}. Retry with one of those words.`;
212
220
  return {
213
221
  ok: true,
214
222
  action: args.action,
215
- message: query.length === 0 ? 'No memories stored yet.' : `No memories match ${JSON.stringify(query)}.`,
223
+ message: query.length === 0 ? 'No memories stored yet.' : `No memories match ${JSON.stringify(query)}.${vocabulary}`,
216
224
  results: [],
217
225
  };
218
226
  }
@@ -33,6 +33,16 @@ export interface BackfillWindow {
33
33
  readonly seq: number;
34
34
  readonly text: string;
35
35
  }[];
36
+ /**
37
+ * Always zero: a backfill window is planned from a whole log, so the planner
38
+ * already splits the log into contiguous windows and nothing is skipped.
39
+ *
40
+ * Declared because the window is handed to {@link runExtraction}, which takes
41
+ * an {@link ExtractWindow}. The live path uses the field to detect a backlog
42
+ * and re-window from the oldest end; the backfill path has no backlog to
43
+ * detect.
44
+ */
45
+ readonly skipped: number;
36
46
  }
37
47
  /** Whether this Node build can decompress zstd at all. */
38
48
  export declare function zstdAvailable(): boolean;
@@ -33,10 +33,20 @@ export declare const DEFAULT_SYNC_INTERVAL_MINUTES = 10;
33
33
  export declare const DEFAULT_SYNC_CLOCK = "12:05,18:05";
34
34
  /** Default debounce before a burst of memory writes becomes one commit, in seconds. */
35
35
  export declare const DEFAULT_SYNC_DEBOUNCE_SECONDS = 2;
36
- /** Default byte budget for the injected memory summary. */
37
- export declare const DEFAULT_MAX_SUMMARY_BYTES = 4096;
36
+ /**
37
+ * Default byte budget for the injected memory summary.
38
+ *
39
+ * 4096 was sized when a store held a few dozen entries. On a real long-lived
40
+ * store the summary is the ONLY projection most conversations ever see, and at
41
+ * 4 KB it could not even list the dozen entries the per-scope cap allowed once
42
+ * the entries were Chinese (measured on the Ornn8 six-persona benchmark: a
43
+ * 5120-byte budget rendered 12 of 149-326 live entries, so 96% of the store was
44
+ * invisible unless the on-demand recall happened to fire). 8192 roughly doubles
45
+ * the rendered set at the cost of one extra cached prefix block per session.
46
+ */
47
+ export declare const DEFAULT_MAX_SUMMARY_BYTES = 8192;
38
48
  /** Default cap on entries listed in the injected summary per scope. */
39
- export declare const DEFAULT_MAX_SUMMARY_ENTRIES = 12;
49
+ export declare const DEFAULT_MAX_SUMMARY_ENTRIES = 20;
40
50
  /**
41
51
  * Whether a conversation is told about memories written after its summary.
42
52
  *
@@ -48,6 +58,16 @@ export declare const DEFAULT_MAX_SUMMARY_ENTRIES = 12;
48
58
  * paragraph rather than a second summary.
49
59
  */
50
60
  export declare const DEFAULT_INJECT_DELTA = true;
61
+ /**
62
+ * Byte budget for one delta block.
63
+ *
64
+ * 800 was the first guess and it is too tight to be useful: a complete entry
65
+ * renders at 200-350 bytes once the title, kind, tags and a body preview are
66
+ * in, so the block admitted two entries at most and often one. A late
67
+ * conversation that changed topic then got almost nothing. 1600 fits four to
68
+ * six, which is the size of a topic shift rather than of a single note.
69
+ */
70
+ export declare const DEFAULT_DELTA_MAX_BYTES = 1600;
51
71
  /**
52
72
  * How many additional memories one conversation lists by title only.
53
73
  *
@@ -82,9 +102,11 @@ export declare const DEFAULT_ROTATION_MAX_BYTES = 1600;
82
102
  * on global entries, and in every session the same six were unrelated to the
83
103
  * workspace (a plugin's logger threshold, a sidebar adapter, a model catalog).
84
104
  * Four keeps the portable half visible without letting it bury the scope that is
85
- * actually about this conversation.
105
+ * actually about this conversation. Six follows the per-scope raise: the global
106
+ * half is what every unrelated conversation can use, and four was leaving the
107
+ * same six entries to compete for a budget that now has room.
86
108
  */
87
- export declare const DEFAULT_GLOBAL_SUMMARY_ENTRIES = 4;
109
+ export declare const DEFAULT_GLOBAL_SUMMARY_ENTRIES = 6;
88
110
  /**
89
111
  * Default byte budget for the global section alone, inside {@link DEFAULT_MAX_SUMMARY_BYTES}.
90
112
  *
@@ -148,12 +170,14 @@ export declare const DEFAULT_RECALL_MODE = "on-demand";
148
170
  * paraphrase that shares two bigrams with a title scores around 9-12, so nothing
149
171
  * ever cleared it. The floor is now a strictness knob, and the PRECISION lives in
150
172
  * `recallMinTerms` — the structural evidence gate, which a score threshold cannot
151
- * replace. 9 is just above one shared bigram in a title (8) so that a single
152
- * common word is never sufficient on its own.
173
+ * replace. 6 is deliberately below the 8 a single shared title bigram scores: a
174
+ * one-bigram paraphrase (「北街南街」 against 「南街文具店」) is a real match that
175
+ * the old floor refused, and the term gate plus the hub discount are what keep a
176
+ * shared common word from recalling everything.
153
177
  */
154
- export declare const DEFAULT_RECALL_MIN_SCORE = 9;
178
+ export declare const DEFAULT_RECALL_MIN_SCORE = 6;
155
179
  /** Default cap on recall deltas injected into one conversation. */
156
- export declare const DEFAULT_RECALL_MAX_PER_CONVERSATION = 4;
180
+ export declare const DEFAULT_RECALL_MAX_PER_CONVERSATION = 8;
157
181
  /**
158
182
  * Default byte budget for one recall delta block.
159
183
  *
@@ -162,7 +186,7 @@ export declare const DEFAULT_RECALL_MAX_PER_CONVERSATION = 4;
162
186
  * entry costs about 90. At 800 a two-entry block would not fit, which is why
163
187
  * this is not 400 as it was when a delta could only ever hold one memory.
164
188
  */
165
- export declare const DEFAULT_RECALL_MAX_BYTES = 1200;
189
+ export declare const DEFAULT_RECALL_MAX_BYTES = 2400;
166
190
  /** Default minimum length of a user turn worth a recall decision. */
167
191
  export declare const DEFAULT_RECALL_MIN_QUERY_CHARS = 2;
168
192
  /**
@@ -179,12 +203,16 @@ export declare const DEFAULT_RAW_RECALL_EXCERPTS = 3;
179
203
  /**
180
204
  * Default number of distinct strong-field terms a recall needs.
181
205
  *
182
- * Two is what makes a paraphrased question reachable without letting a shared
183
- * common word in: "这个插件的日志在哪里" shares 插件 and 日志 with a memory titled
184
- * "插件日志的查看方式" (two terms, credited), while "该插件是否有日志" shares only
185
- * 插件 with a title about plugin registration order (one term, not credited).
206
+ * Two was the old precision gate, but a Chinese paraphrase of a stored fact
207
+ * routinely shares exactly ONE substantive word with it: a benchmark turn asking
208
+ * 「理零票第一步」 against a memory filed as 「整理小票先按日期分堆」 shares only
209
+ * 票, and 「点碗粉加两个小菜」 against 「不吃香菜」 shares only 菜. Two terms made
210
+ * those unreachable no matter how high the relevance score was. One term plus the
211
+ * relevance floor is the gate now; the floor (8) is what keeps a shared common
212
+ * word like 插件 or 日志 from recalling everything, and the entity path in
213
+ * `recallFor` adds a second, stronger signal on top.
186
214
  */
187
- export declare const DEFAULT_RECALL_MIN_TERMS = 2;
215
+ export declare const DEFAULT_RECALL_MIN_TERMS = 1;
188
216
  /**
189
217
  * Every valid recall mode.
190
218
  *
@@ -351,6 +379,8 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
351
379
  * the `memory` tool and the on-demand recall path still work.
352
380
  */
353
381
  injectDelta: z<boolean, boolean, "volatile-defined">;
382
+ /** Byte budget for one delta block. */
383
+ deltaMaxBytes: z<number, number, "volatile-defined">;
354
384
  /**
355
385
  * How many extra memories one conversation lists by title only.
356
386
  *
@@ -504,6 +534,8 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
504
534
  * the `memory` tool and the on-demand recall path still work.
505
535
  */
506
536
  injectDelta: z<boolean, boolean, "volatile-defined">;
537
+ /** Byte budget for one delta block. */
538
+ deltaMaxBytes: z<number, number, "volatile-defined">;
507
539
  /**
508
540
  * How many extra memories one conversation lists by title only.
509
541
  *
@@ -635,6 +667,8 @@ export interface MemoriesSettings {
635
667
  recallMinTerms: number;
636
668
  /** Whether memories written after the summary are announced as a delta. */
637
669
  injectDelta: boolean;
670
+ /** Byte budget for one delta block (0 disables the delta). */
671
+ deltaMaxBytes: number;
638
672
  /** How many extra memories one conversation lists by title only (0 disables). */
639
673
  rotationEntries: number;
640
674
  /** User turns between rotation blocks inside one long conversation (0 = once). */
@@ -60,6 +60,12 @@ export declare const CONSOLIDATE_JSON_SCHEMA: {
60
60
  readonly type: 'string';
61
61
  };
62
62
  };
63
+ readonly keys: {
64
+ readonly type: 'array';
65
+ readonly items: {
66
+ readonly type: 'string';
67
+ };
68
+ };
63
69
  readonly appliesTo: {
64
70
  readonly type: 'string';
65
71
  };
@@ -247,6 +253,15 @@ export interface ConsolidateRequest {
247
253
  model: string;
248
254
  reasoningEffort?: string;
249
255
  };
256
+ /**
257
+ * Why this run produced no plan, when it did not.
258
+ *
259
+ * A pass that ends without a plan is a normal outcome (the child can fail, be
260
+ * cut short, or answer in a shape the parser cannot use), but it must not be
261
+ * silent: the caller logs this and reports it to the person who asked for the
262
+ * pass. Called at most once, and only on the no-plan branches.
263
+ */
264
+ readonly onSkip?: (reason: string) => void;
250
265
  readonly signal: AbortSignal;
251
266
  }
252
267
  /**
@@ -296,6 +311,18 @@ export interface ActivationSpec {
296
311
  * kernel boundary, not at this module's type boundary.
297
312
  */
298
313
  signal: AbortSignal;
314
+ /**
315
+ * Where the child's settlement notice goes.
316
+ *
317
+ * `caller` is right for this pass: the plugin consumes `run.result` itself, so
318
+ * a settlement message pushed into the parent's inbox is noise. That noise was
319
+ * actively misleading — the kernel marks a child that answers in plain text
320
+ * instead of calling `structured_output` as `error`, so the parent was told
321
+ * "Background subagent ... failed before it finished" while the plan had in fact
322
+ * arrived intact (2026-11-06). The kernel's own plugin-creator starts its
323
+ * children the same way.
324
+ */
325
+ delivery?: 'caller' | 'parent';
299
326
  request: {
300
327
  prompt: {
301
328
  type: 'text';
@@ -313,15 +340,24 @@ export interface ActivationSpec {
313
340
  agentPreset?: string;
314
341
  };
315
342
  }
343
+ /**
344
+ * One finished child run, as the seam reports it.
345
+ *
346
+ * `stopReason` is a string in the kernel ("completed", "error", "max-tokens",
347
+ * …); an older seam wrapped it as `{ kind }`. Both shapes are declared because
348
+ * the value only feeds a diagnostic line, and reading the wrong one must not
349
+ * turn a reportable failure into a `TypeError`.
350
+ */
351
+ export interface ChildRunResult {
352
+ readonly output: readonly unknown[];
353
+ readonly structured?: unknown;
354
+ readonly stopReason?: string | {
355
+ kind: string;
356
+ };
357
+ }
316
358
  export interface SubagentSeam {
317
359
  startActivation?: (spec: ActivationSpec) => Promise<{
318
- result: Promise<{
319
- output: readonly unknown[];
320
- structured?: unknown;
321
- stopReason?: {
322
- kind: string;
323
- };
324
- }>;
360
+ result: Promise<ChildRunResult>;
325
361
  }>;
326
362
  start?: (name: string, request: {
327
363
  prompt: {
@@ -342,13 +378,7 @@ export interface SubagentSeam {
342
378
  };
343
379
  persona?: string;
344
380
  }) => Promise<{
345
- result: Promise<{
346
- output: readonly unknown[];
347
- structured?: unknown;
348
- stopReason?: {
349
- kind: string;
350
- };
351
- }>;
381
+ result: Promise<ChildRunResult>;
352
382
  }>;
353
383
  }
354
384
  /**