dsh-cross-memory 0.2.2 → 0.2.3

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.
@@ -61,6 +61,10 @@ export const CONSOLIDATE_JSON_SCHEMA = {
61
61
  title: { type: 'string' },
62
62
  body: { type: 'string' },
63
63
  tags: { type: 'array', items: { type: 'string' } },
64
+ // The prompt's reply template asks for `keys`; a schema that omits it
65
+ // (with `additionalProperties: false`) rejects every prompt-compliant
66
+ // answer, and the child's whole run ends as an error.
67
+ keys: { type: 'array', items: { type: 'string' } },
64
68
  appliesTo: { type: 'string' },
65
69
  durability: { type: 'string', enum: ['durable', 'snapshot'] },
66
70
  asOf: { type: 'string' },
@@ -132,20 +136,57 @@ export function renderConsolidationInput(entries, projectLabel, currentPersona)
132
136
  }
133
137
  return blocks.join('\n');
134
138
  }
135
- /** Parse and validate the agent's JSON reply into a plan. */
136
- export function parsePlan(text, knownIds, maxUpserts) {
139
+ /**
140
+ * Try every `{` in a model reply as the start of a JSON object.
141
+ *
142
+ * A reply is not always pure JSON. A reasoning model sketches the reply shape
143
+ * before it answers ("{\"memories\":[...]}"), and prose around the answer can
144
+ * quote a brace too. Slicing from the FIRST `{` to the last `}` read that sketch
145
+ * as if it were the plan, the parse threw, and the pass reported "no plan" while
146
+ * the child had in fact returned one. Every opening brace is a candidate start
147
+ * instead; the first slice the caller accepts wins.
148
+ *
149
+ * @param text - the model's reply.
150
+ * @param accept - decodes one parsed candidate, or returns `undefined` to keep scanning.
151
+ * @returns the first accepted value, or `undefined` when no candidate is usable.
152
+ */
153
+ function scanJsonObjects(text, accept) {
137
154
  const trimmed = text.trim().replace(/^```(?:json)?\s*/iu, '').replace(/```$/u, '').trim();
138
- const start = trimmed.indexOf('{');
139
- const end = trimmed.lastIndexOf('}');
140
- if (start < 0 || end <= start)
141
- return undefined;
142
- let parsed;
143
- try {
144
- parsed = JSON.parse(trimmed.slice(start, end + 1));
145
- }
146
- catch {
155
+ const first = trimmed.indexOf('{');
156
+ const last = trimmed.lastIndexOf('}');
157
+ if (first < 0 || last <= first)
147
158
  return undefined;
159
+ for (let start = first; start >= 0 && start < last; start = trimmed.indexOf('{', start + 1)) {
160
+ let parsed;
161
+ try {
162
+ parsed = JSON.parse(trimmed.slice(start, last + 1));
163
+ }
164
+ catch {
165
+ continue;
166
+ }
167
+ const accepted = accept(parsed);
168
+ if (accepted !== undefined)
169
+ return accepted;
148
170
  }
171
+ return undefined;
172
+ }
173
+ /** Parse and validate the agent's JSON reply into a plan. */
174
+ export function parsePlan(text, knownIds, maxUpserts) {
175
+ return scanJsonObjects(text, (parsed) => planFromReply(parsed, knownIds, maxUpserts));
176
+ }
177
+ /**
178
+ * Decode one parsed reply object into a validated plan.
179
+ *
180
+ * Split out from {@link parsePlan} so the brace scan can try more than one
181
+ * candidate: a slice that parses but carries no plan (an example the model
182
+ * quoted) must not stop the scan.
183
+ *
184
+ * @param parsed - one parsed JSON value from a candidate slice.
185
+ * @param knownIds - ids present in the reviewed page.
186
+ * @param maxUpserts - cap on returned memories.
187
+ * @returns the validated plan, or `undefined` when this value carries none.
188
+ */
189
+ function planFromReply(parsed, knownIds, maxUpserts) {
149
190
  if (typeof parsed !== 'object' || parsed === null)
150
191
  return undefined;
151
192
  const record = parsed;
@@ -395,10 +436,21 @@ export async function runConsolidation(seam, request) {
395
436
  const input = renderConsolidationInput(request.entries, request.projectLabel, request.persona);
396
437
  const timeout = AbortSignal.any([request.signal, AbortSignal.timeout(request.timeoutMs)]);
397
438
  const prompt = [{ type: 'text', text: `${CONSOLIDATE_SYSTEM}\n\n---\n\n${input}` }];
398
- const reply = await runChild(seam, prompt, request, timeout);
399
- if (reply === undefined)
439
+ const answer = await runChild(seam, prompt, request, timeout);
440
+ if (answer === undefined) {
441
+ request.onSkip?.('the subagent seam could not run a tool-free child');
400
442
  return undefined;
401
- return parsePlan(reply, known, request.maxUpserts);
443
+ }
444
+ const plan = parsePlan(answer.text, known, request.maxUpserts);
445
+ // "No plan" is not one condition: the child may have answered not at all, or
446
+ // answered without the JSON. Naming which one, and how its run ended, is what
447
+ // turns a silent no-op into a diagnosable failure.
448
+ if (plan === undefined) {
449
+ request.onSkip?.(answer.text.trim().length === 0
450
+ ? `the child returned no text (stopReason: ${answer.stopReason ?? 'unknown'})`
451
+ : `the child's reply carried no plan (${answer.text.length} chars, stopReason: ${answer.stopReason ?? 'unknown'})`);
452
+ }
453
+ return plan;
402
454
  }
403
455
  /**
404
456
  * Build the spec the 0.2.1-rc.2 seam takes.
@@ -424,6 +476,11 @@ export function buildActivationSpec(request, prompt, timeout, outputSchema = CON
424
476
  // descriptor validator BEFORE the child starts, and the symptom is a
425
477
  // silently dead consolidation pass rather than a start error.
426
478
  label: CONSOLIDATE_LABEL,
479
+ // The result is consumed here, not by the parent conversation: a settlement
480
+ // notice for this child is noise, and when the child misses
481
+ // `structured_output` that notice reads as a failure even though the answer
482
+ // arrived. See {@link ActivationSpec.delivery}.
483
+ delivery: 'caller',
427
484
  // Same class of mistake as the label, one field later: the kernel reads
428
485
  // `spec.signal` and never `spec.request.signal`, so it has to be here too.
429
486
  signal: timeout,
@@ -445,7 +502,24 @@ export function buildActivationSpec(request, prompt, timeout, outputSchema = CON
445
502
  };
446
503
  }
447
504
  /**
448
- * Ask the seam for one restricted child and return its answer as text.
505
+ * Read one child's ending as a single string.
506
+ *
507
+ * The kernel reports `stopReason` as a string ("completed", "error",
508
+ * "max-tokens", …); an older seam wrapped it as `{ kind }`. Both are read here
509
+ * because this value is only ever used for a diagnostic line.
510
+ *
511
+ * @param value - the raw `stopReason`.
512
+ * @returns the reason text, or `undefined` when the seam reported none.
513
+ */
514
+ function stopReasonText(value) {
515
+ if (typeof value === 'string')
516
+ return value;
517
+ if (typeof value === 'object' && value !== null && 'kind' in value && typeof value.kind === 'string')
518
+ return value.kind;
519
+ return undefined;
520
+ }
521
+ /**
522
+ * Ask the seam for one restricted child and return its answer.
449
523
  *
450
524
  * The 0.2.1-rc.2 seam is preferred, but only with a preset: a child that names
451
525
  * no preset inherits the parent's composition, and the parent's tools are what
@@ -455,7 +529,7 @@ export function buildActivationSpec(request, prompt, timeout, outputSchema = CON
455
529
  * @param prompt - the child's single user message.
456
530
  * @param request - route, caps, and the preset name.
457
531
  * @param timeout - the child's deadline.
458
- * @returns the child's text, or `undefined` when the seam cannot run it.
532
+ * @returns the child's answer, or `undefined` when the seam cannot run it.
459
533
  */
460
534
  async function runChild(seam, prompt, request, timeout, outputSchema = CONSOLIDATE_JSON_SCHEMA) {
461
535
  const agentOptions = request.provider !== undefined && request.model !== undefined
@@ -463,7 +537,8 @@ async function runChild(seam, prompt, request, timeout, outputSchema = CONSOLIDA
463
537
  : undefined;
464
538
  if (typeof seam.startActivation === 'function' && request.agentPreset !== undefined) {
465
539
  const run = await seam.startActivation(buildActivationSpec(request, prompt, timeout, outputSchema));
466
- return textOf(await run.result);
540
+ const result = await run.result;
541
+ return { text: textOf(result), ...stopReasonOf(result) };
467
542
  }
468
543
  if (typeof seam.start === 'function') {
469
544
  const run = await seam.start('spawn', {
@@ -477,15 +552,32 @@ async function runChild(seam, prompt, request, timeout, outputSchema = CONSOLIDA
477
552
  // only output is the JSON plan it returns.
478
553
  toolFilter: { deny: request.denyTools },
479
554
  });
480
- return textOf(await run.result);
555
+ const result = await run.result;
556
+ return { text: textOf(result), ...stopReasonOf(result) };
481
557
  }
482
558
  return undefined;
483
559
  }
560
+ /**
561
+ * Pick the run's reported stop reason out of a finished child result.
562
+ * @param result - the child's finished run.
563
+ * @returns the optional `stopReason` property, or nothing when absent.
564
+ */
565
+ function stopReasonOf(result) {
566
+ const reason = stopReasonText(result.stopReason);
567
+ return reason === undefined ? {} : { stopReason: reason };
568
+ }
484
569
  /**
485
570
  * Read one child's answer as text.
486
571
  *
487
572
  * A child that answered through the structured-output tool carries the plan in
488
573
  * `structured`; a child that answered in prose carries it in the text blocks.
574
+ *
575
+ * The kernel's `output` is the child's last assistant message *content*, which
576
+ * includes its reasoning blocks. A reasoning block also carries a `text` field,
577
+ * so reading every block that has one glues the child's scratchpad — full of
578
+ * example JSON braces — in front of the plan and the plan no longer parses.
579
+ * Only blocks the model sent as its answer count here.
580
+ *
489
581
  * @param result - the child's finished run.
490
582
  * @returns the text the plan is parsed from.
491
583
  */
@@ -493,7 +585,8 @@ function textOf(result) {
493
585
  if (typeof result.structured === 'object' && result.structured !== null)
494
586
  return JSON.stringify(result.structured);
495
587
  return result.output
496
- .map((block) => (typeof block === 'object' && block !== null && 'text' in block && typeof block.text === 'string' ? block.text : ''))
588
+ .map((block) => (typeof block === 'object' && block !== null && 'type' in block && block.type === 'text' && 'text' in block && typeof block.text === 'string' ? block.text : ''))
589
+ .filter((text) => text.length > 0)
497
590
  .join('\n');
498
591
  }
499
592
  /**
@@ -540,9 +633,14 @@ export async function runConsolidationDirect(llm, request) {
540
633
  .filter((block) => block.type === 'text')
541
634
  .map((block) => block.text)
542
635
  .join('\n');
543
- if (text.trim().length === 0)
636
+ if (text.trim().length === 0) {
637
+ request.onSkip?.('the model returned an empty reply');
544
638
  return undefined;
545
- return parsePlan(text, known, request.maxUpserts);
639
+ }
640
+ const plan = parsePlan(text, known, request.maxUpserts);
641
+ if (plan === undefined)
642
+ request.onSkip?.(`the model's reply carried no plan (${text.length} chars)`);
643
+ return plan;
546
644
  }
547
645
  /**
548
646
  * Choose which memories one consolidation pass reviews.
@@ -1042,21 +1140,11 @@ export async function adjudicateDisputes(seam, request, disputes) {
1042
1140
  const reply = await runChild(seam, prompt, request, timeout, ADJUDICATE_JSON_SCHEMA);
1043
1141
  if (reply === undefined)
1044
1142
  return [];
1045
- const trimmed = reply.trim().replace(/^```(?:json)?\s*/iu, '').replace(/```$/u, '').trim();
1046
- const start = trimmed.indexOf('{');
1047
- const end = trimmed.lastIndexOf('}');
1048
- if (start < 0 || end <= start)
1049
- return [];
1050
- let parsed;
1051
- try {
1052
- parsed = JSON.parse(trimmed.slice(start, end + 1));
1053
- }
1054
- catch {
1055
- return [];
1056
- }
1057
- if (typeof parsed !== 'object' || parsed === null)
1143
+ // The same brace scan the plan parse uses: the adjudicator's reply can be
1144
+ // wrapped in prose or preceded by a quoted sketch just like the plan's.
1145
+ const record0 = scanJsonObjects(reply.text, (parsed) => typeof parsed === 'object' && parsed !== null ? parsed : undefined);
1146
+ if (record0 === undefined)
1058
1147
  return [];
1059
- const record0 = parsed;
1060
1148
  const rows = Array.isArray(record0['decisions']) ? record0['decisions'] : [];
1061
1149
  const known = new Set(disputes.map((dispute) => dispute.id));
1062
1150
  const verdicts = [];
package/lib/index.js CHANGED
@@ -2764,7 +2764,9 @@ export class MemoriesRuntime {
2764
2764
  const proposed = await this.runConsolidationPass(parent, entries, root);
2765
2765
  if (proposed === undefined) {
2766
2766
  this.state.deleteJob(CONSOLIDATE_JOB);
2767
- this.consolidateSkip = 'the pass produced no plan; the warn line above names the reason';
2767
+ // `onSkip` records the concrete reason; this is the fallback for a
2768
+ // route that declined before it could name one.
2769
+ this.consolidateSkip ??= 'the pass produced no plan';
2768
2770
  return undefined;
2769
2771
  }
2770
2772
  // A scope is where a memory is injected from, so it is not something a pass
@@ -2875,6 +2877,9 @@ export class MemoriesRuntime {
2875
2877
  });
2876
2878
  this.noteLimitRefusal(error);
2877
2879
  this.log.warn('dsh-cross-memory: consolidation failed for session %s: %s', parent.session.id, message);
2880
+ // The command reports `consolidateSkipReason`; without this the failure
2881
+ // surfaced as "Nothing to consolidate: unknown reason".
2882
+ this.consolidateSkip = `the pass failed: ${message}`;
2878
2883
  return undefined;
2879
2884
  }
2880
2885
  }
@@ -3314,6 +3319,15 @@ export class MemoriesRuntime {
3314
3319
  // extraction pass already uses: a plan for a full page of memories is the
3315
3320
  // same size of answer as a page of drafts.
3316
3321
  maxOutputTokens: this.settings.extractMaxOutputTokens,
3322
+ // A pass that returns no plan is a normal outcome, but a silent one is
3323
+ // not: without this the command reported a stale sentence about a "warn
3324
+ // line above" that no code ever wrote, and the child's real ending (a
3325
+ // failed structured-output capture, an empty answer, an unusable reply)
3326
+ // was lost. The reason goes into the log AND into the command's report.
3327
+ onSkip: (reason) => {
3328
+ this.consolidateSkip = reason;
3329
+ this.log.warn('dsh-cross-memory: the consolidation pass produced no plan: %s', reason);
3330
+ },
3317
3331
  signal: this.lifecycle.signal,
3318
3332
  };
3319
3333
  const seam = this.subagents;
@@ -4446,7 +4460,7 @@ async function handleCommand(runtime, invocation) {
4446
4460
  const summary = await runtime.consolidateNow(invocation.agent, { apply: false, force: true });
4447
4461
  // The old fallback listed three causes and named the real one only by luck;
4448
4462
  // every silent path now records why it declined.
4449
- return { kind: 'success', text: summary ?? `Nothing to consolidate: ${runtime.consolidateSkipReason ?? 'unknown reason'}` };
4463
+ return { kind: 'success', text: summary ?? `No consolidation plan was produced: ${runtime.consolidateSkipReason ?? 'unknown reason'}` };
4450
4464
  }
4451
4465
  case 'plan': {
4452
4466
  const pending = await runtime.pendingPlan();
@@ -12,8 +12,8 @@ import { mkdtemp, rm } from 'node:fs/promises';
12
12
  import { tmpdir } from 'node:os';
13
13
  import { join } from 'node:path';
14
14
  import test from 'node:test';
15
- import { assertObjectJsonSchema } from '@deepseek-ai/dsh-tools';
16
- import { CONSOLIDATE_DENY_TOOLS, CONSOLIDATE_JSON_SCHEMA, clearPendingPlan, classifyPlan, denyToolsFor, applyPlan, hasApplicableFragment, parsePlan, pinExistingScopes, proposalIsFresh, readPendingPlan, renderConsolidationInput, runConsolidation, runConsolidationDirect, writePendingPlan, } from '../consolidate.js';
15
+ import { assertObjectJsonSchema, validateJsonSchemaValue } from '@deepseek-ai/dsh-tools';
16
+ import { CONSOLIDATE_DENY_TOOLS, CONSOLIDATE_JSON_SCHEMA, CONSOLIDATE_SYSTEM, clearPendingPlan, classifyPlan, denyToolsFor, applyPlan, hasApplicableFragment, parsePlan, pinExistingScopes, proposalIsFresh, readPendingPlan, renderConsolidationInput, runConsolidation, runConsolidationDirect, writePendingPlan, } from '../consolidate.js';
17
17
  /** Build one entry. */
18
18
  function entry(partial) {
19
19
  return { scope: 'global', kind: 'fact', tags: [], keys: [], createdAt: 1, updatedAt: 1, uses: 0, lastUsedAt: 0, lastSurfacedAt: 0, source: 'auto', ...partial };
@@ -428,3 +428,103 @@ test('an existing memory is pinned to its own scope; only new memories choose on
428
428
  assert.equal(twinsResult.pinned.length, 0, 'naming the copy it lives in is not a move');
429
429
  assert.equal(twinsResult.plan.upserts[0]?.scope, 'project');
430
430
  });
431
+ /** A request for the modern preset seam over two existing entries. */
432
+ function modernRequest(overrides = {}) {
433
+ return {
434
+ parent: {},
435
+ entries: [entry({ id: 'a', title: 'A', body: 'a' }), entry({ id: 'b', title: 'B', body: 'b' })],
436
+ projectLabel: 'project:x',
437
+ maxUpserts: 10,
438
+ denyTools: [...CONSOLIDATE_DENY_TOOLS],
439
+ agentPreset: 'memories-consolidator',
440
+ timeoutMs: 5_000,
441
+ signal: new AbortController().signal,
442
+ ...overrides,
443
+ };
444
+ }
445
+ test('a plan in the closing text survives the reasoning block in front of it', async () => {
446
+ // The kernel hands the plugin the child's last assistant message *content*,
447
+ // reasoning blocks included, and a reasoning model sketches the reply shape
448
+ // before it answers. Reading every block that carries a `text` field glued
449
+ // that sketch in front of the plan, the brace slice started inside the sketch,
450
+ // the parse threw, and the pass reported "no plan" while the child had in
451
+ // fact returned one (2026-11-06, /memories consolidate).
452
+ const replyText = JSON.stringify({
453
+ memories: [{ id: 'a', scope: 'global', kind: 'fact', title: 'A merged', body: 'a and b merged', tags: [], keys: ['a'], appliesTo: 'when', derivedFrom: ['b'] }],
454
+ retire: ['b'], skills: [], notes: 'merged A and B', persona: '',
455
+ });
456
+ const reasoning = 'The reply shape is {"memories":[...],"retire":[...]}, so ids must exist. Merge A and B.';
457
+ const seam = {
458
+ startActivation: async () => ({
459
+ // `stopReason` is a string in the kernel; the child never called
460
+ // structured_output, so the kernel forces 'error'.
461
+ result: Promise.resolve({ output: [{ type: 'reasoning', text: reasoning }, { type: 'text', text: replyText }], structured: undefined, stopReason: 'error' }),
462
+ }),
463
+ };
464
+ const plan = await runConsolidation(seam, modernRequest());
465
+ assert.ok(plan !== undefined, 'the plan in the closing text must be recovered');
466
+ assert.equal(plan.notes, 'merged A and B');
467
+ assert.deepEqual(plan.retire, ['b']);
468
+ assert.equal(plan.upserts[0]?.id, 'a');
469
+ assert.equal(plan.upserts[0]?.keys?.[0], 'a');
470
+ });
471
+ test('parsePlan still finds the plan when prose before it quotes JSON', () => {
472
+ const reply = '{"memories":[{"id":null,"scope":"global","kind":"fact","title":"t","body":"b","tags":[],"keys":[],"appliesTo":"when"}],"retire":[],"skills":[],"notes":"n"}';
473
+ const plan = parsePlan(`I could answer {"memories":[],"retire":[]} but the plan is:\n${reply}`, new Set(), 10);
474
+ assert.ok(plan !== undefined);
475
+ assert.equal(plan.upserts.length, 1);
476
+ assert.equal(plan.notes, 'n');
477
+ });
478
+ test('the output schema accepts every field the prompt template names', () => {
479
+ // The prompt's reply template is the child's contract. `additionalProperties:
480
+ // false` plus a field the schema omits makes a prompt-following answer
481
+ // unparseable by the kernel, which ends the whole child run as an error.
482
+ // `keys` was that hole: the template asked for it and the schema forbade it.
483
+ const template = CONSOLIDATE_SYSTEM.split('\n').find((line) => line.startsWith('{"memories"'));
484
+ if (template === undefined)
485
+ throw new Error('the prompt must carry the reply template');
486
+ const named = new Set([...template.matchAll(/"([A-Za-z]+)":/gu)].flatMap((match) => match[1] === undefined ? [] : [match[1]]));
487
+ const allowed = new Set();
488
+ const collect = (node) => {
489
+ if (typeof node !== 'object' || node === null)
490
+ return;
491
+ const record = node;
492
+ const properties = record['properties'];
493
+ if (typeof properties === 'object' && properties !== null) {
494
+ for (const [name, sub] of Object.entries(properties)) {
495
+ allowed.add(name);
496
+ collect(sub);
497
+ }
498
+ }
499
+ if ('items' in record)
500
+ collect(record['items']);
501
+ };
502
+ collect(CONSOLIDATE_JSON_SCHEMA);
503
+ for (const name of named)
504
+ assert.ok(allowed.has(name), `the template names "${name}", the schema must allow it`);
505
+ // A reply that exercises the whole template — including `keys` — must pass.
506
+ const reply = {
507
+ memories: [{ id: null, scope: 'global', kind: 'fact', title: 't', body: 'b', tags: ['x'], keys: ['k'], appliesTo: 'when', durability: 'durable', derivedFrom: [] }],
508
+ retire: [],
509
+ skills: [{ name: 'n', description: 'd', steps: ['s'] }],
510
+ notes: 'n',
511
+ persona: 'p',
512
+ };
513
+ // `assertObjectJsonSchema` narrows the const to the asserted schema type the
514
+ // validator takes, so the same schema the child is held to is the one checked.
515
+ assertObjectJsonSchema(CONSOLIDATE_JSON_SCHEMA);
516
+ assert.deepEqual(validateJsonSchemaValue(CONSOLIDATE_JSON_SCHEMA, reply), [], 'a template-shaped reply must validate');
517
+ });
518
+ test('a child that answers without a plan names why the pass stopped', async () => {
519
+ const reasons = [];
520
+ const seam = {
521
+ startActivation: async () => ({
522
+ result: Promise.resolve({ output: [{ type: 'text', text: 'I could not decide.' }], structured: undefined, stopReason: 'error' }),
523
+ }),
524
+ };
525
+ const plan = await runConsolidation(seam, modernRequest({ onSkip: (reason) => reasons.push(reason) }));
526
+ assert.equal(plan, undefined);
527
+ assert.equal(reasons.length, 1, 'the no-plan branch must report exactly once');
528
+ assert.match(reasons[0] ?? '', /carried no plan/u);
529
+ assert.match(reasons[0] ?? '', /stopReason: error/u, 'the child ending goes into the report');
530
+ });
@@ -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`.
@@ -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
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-cross-memory",
3
3
  "description": "Cross-session memory for the DeepSeek Harness: project-scoped and global memories with an explicit memory tool, idle-time background extraction, consolidation, and layered summary injection",
4
- "version": "0.2.2",
4
+ "version": "0.2.3",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public"