dsh-taskbridge 1.5.2 → 1.5.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.
@@ -0,0 +1,82 @@
1
+ // Shared contract for `goalDescription` and `completionSummary`: <= 2000 Unicode code points
2
+ // (Chinese, newlines and emoji count once), trimmed, non-strings refused, re-checked post-redaction.
3
+
4
+ export const TASK_DESCRIPTION_MAX_CHARS = 2_000;
5
+
6
+ export const TASK_DESCRIPTION_FIELDS = Object.freeze({
7
+ goal: 'goalDescription',
8
+ summary: 'completionSummary',
9
+ });
10
+
11
+ export function normalizeTaskDescription(value) {
12
+ return typeof value === 'string' ? value.trim() : '';
13
+ }
14
+
15
+ export function taskDescriptionLength(value) {
16
+ return typeof value === 'string' ? Array.from(value).length : 0;
17
+ }
18
+
19
+ /** Build refusal facts naming field, measured code-point length and limit (never echoing text). */
20
+ export function taskDescriptionRefusal(field, value, reason) {
21
+ const limit = TASK_DESCRIPTION_MAX_CHARS;
22
+ const length = taskDescriptionLength(value);
23
+ if (reason === 'type') {
24
+ return {
25
+ field,
26
+ limit,
27
+ length,
28
+ unit: 'unicode-code-points',
29
+ message: `${field} must be a string of at most ${limit} Unicode code points`,
30
+ };
31
+ }
32
+ return {
33
+ field,
34
+ limit,
35
+ length,
36
+ unit: 'unicode-code-points',
37
+ message: `${field} must be at most ${limit} Unicode code points, but it is ${length}`,
38
+ };
39
+ }
40
+
41
+ export function taskDescriptionPresent(value) {
42
+ if (value === undefined) return false;
43
+ return typeof value === 'string' ? value.trim() !== '' : true;
44
+ }
45
+
46
+ export function readTaskDescription(value, field) {
47
+ if (!taskDescriptionPresent(value)) return { ok: true, value: null, length: 0 };
48
+ if (typeof value !== 'string') {
49
+ return { ok: false, refusal: taskDescriptionRefusal(field, value, 'type') };
50
+ }
51
+ const text = value.trim();
52
+ if (text === '') return { ok: true, value: null, length: 0 };
53
+ const length = taskDescriptionLength(text);
54
+ if (length > TASK_DESCRIPTION_MAX_CHARS) {
55
+ return { ok: false, refusal: taskDescriptionRefusal(field, text, 'length') };
56
+ }
57
+ return { ok: true, value: text, length };
58
+ }
59
+
60
+ /** Canonicalize once: type, trim, inbound bound, redact, and post-redaction bound. */
61
+ export function canonicalTaskDescription(value, field, redact) {
62
+ const read = readTaskDescription(value, field);
63
+ if (read.ok === false) return read;
64
+ if (read.value === null) return read;
65
+ const masked = typeof redact === 'function' ? redact(read.value) : read.value;
66
+ const stored = typeof masked === 'string' ? masked.trim() : '';
67
+ if (stored === '') return { ok: true, value: null, length: 0 };
68
+ const length = taskDescriptionLength(stored);
69
+ if (length > TASK_DESCRIPTION_MAX_CHARS) {
70
+ return { ok: false, refusal: taskDescriptionRefusal(field, stored, 'length') };
71
+ }
72
+ return { ok: true, value: stored, length };
73
+ }
74
+
75
+ /** Load-only code-point truncation leaving room for a marker without splitting surrogate pairs. */
76
+ export function truncateTaskDescription(value, markerChars = 0, limit = TASK_DESCRIPTION_MAX_CHARS) {
77
+ if (typeof value !== 'string' || value === '') return null;
78
+ const points = Array.from(value);
79
+ if (points.length <= limit) return value;
80
+ const keep = Math.max(0, limit - Math.max(0, Math.trunc(markerChars)));
81
+ return points.slice(0, keep).join('');
82
+ }
package/src/mcp/server.js CHANGED
@@ -89,6 +89,12 @@ import {
89
89
  reviewNoteOverflow,
90
90
  truncateCodePoints,
91
91
  } from '../jobs/review-note.js';
92
+ import {
93
+ TASK_DESCRIPTION_FIELDS,
94
+ TASK_DESCRIPTION_MAX_CHARS,
95
+ canonicalTaskDescription,
96
+ readTaskDescription,
97
+ } from '../jobs/task-descriptions.js';
92
98
  import { waitForTask } from './wait.js';
93
99
  import { QUESTION_ANSWER_KIND, createCallMetrics, correlationId } from './metrics.js';
94
100
  // The engine's own per-call permission bounds. Imported rather than re-stated so this
@@ -143,6 +149,10 @@ export const MAX_REVIEW_NOTE_PAGE_CHARS = 2_000;
143
149
  /** Default page size of a `reviewNoteOffset` read. */
144
150
  export const DEFAULT_REVIEW_NOTE_PAGE_CHARS = 2_000;
145
151
 
152
+ /** Largest and default page size of a `completionSummaryOffset` read, in code points. */
153
+ export const MAX_COMPLETION_SUMMARY_PAGE_CHARS = TASK_DESCRIPTION_MAX_CHARS;
154
+ export const DEFAULT_COMPLETION_SUMMARY_PAGE_CHARS = TASK_DESCRIPTION_MAX_CHARS;
155
+
146
156
  /** Bound on one execution-plane request. */
147
157
  export const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
148
158
 
@@ -175,6 +185,9 @@ export const MIN_WAIT_SECONDS = 1;
175
185
  */
176
186
  export const MAX_REVIEW_NOTE_CHARS = REVIEW_NOTE_MAX_CHARS;
177
187
 
188
+ /** Longest `goalDescription` / `completionSummary`, in Unicode code points. */
189
+ export const MAX_TASK_DESCRIPTION_CHARS = TASK_DESCRIPTION_MAX_CHARS;
190
+
178
191
  /**
179
192
  * How many requests may be in flight at once on the stdio transport.
180
193
  *
@@ -289,7 +302,11 @@ export const TOOLS = Object.freeze([
289
302
  + 'reuses that task\u2019s recorded execution checkout and DSH Session internally, taking no execution '
290
303
  + 'location from '
291
304
  + 'the caller. An unknown, unfinished, removed or differently-sourced parent is refused rather than '
292
- + 'started as a new conversation.',
305
+ + 'started as a new conversation. '
306
+ + 'The commander must first plan and scope ONE cohesive, independently verifiable work packet. '
307
+ + 'Split a separable multi-stage goal before dispatch; include the chosen approach, scope and acceptance '
308
+ + 'checks. A simple complete task may use one packet. Rules, planning and final review remain with '
309
+ + 'the commander; a verification-only packet does not authorize implementation changes.',
293
310
  // It creates work, so it is not a read; it is not destructive of anything the
294
311
  // operator already has, and repeating it creates ANOTHER task (never idempotent).
295
312
  annotations: Object.freeze({
@@ -314,7 +331,7 @@ export const TOOLS = Object.freeze([
314
331
  + 'an execution.workspacePath or any other internal execution location in its place, because a '
315
332
  + 'different source path names a different repository and the continuation is refused.',
316
333
  },
317
- prompt: { type: 'string', description: 'The task to perform.' },
334
+ prompt: { type: 'string', description: 'One commander-planned work packet: objective, chosen approach, owned files or modules, constraints and acceptance checks. Roadmap context does not authorize future packets. A verification-only assignment permits checks and evidence, not implementation edits.' },
318
335
  title: { type: 'string', maxLength: 120, description: 'Short work-content title in the operator\'s language, e.g. 修复登录错误. Used to name the new DSH Workspace; omit role instructions and task ids. A follow-up keeps its existing Workspace name.' },
319
336
  overrides: {
320
337
  type: 'object',
@@ -343,6 +360,20 @@ export const TOOLS = Object.freeze([
343
360
  + 'isolation override either. An unknown, still-running, removed or differently-sourced parent is '
344
361
  + 'refused, never replaced by a new conversation.',
345
362
  },
363
+ goalDescription: {
364
+ type: 'string',
365
+ maxLength: MAX_TASK_DESCRIPTION_CHARS,
366
+ // The bound is counted in Unicode code points, not in UTF-16 units.
367
+ codePointLength: true,
368
+ description: 'OPTIONAL. What THIS round of work is for, in your own words: the goal you planned, '
369
+ + 'not the packet of instructions (that is `prompt`). At most 2000 Unicode code points, so Chinese, '
370
+ + 'line breaks and emoji each count once; surrounding whitespace is trimmed and inner line breaks are '
371
+ + 'kept. A longer value, or one that is not a string (including `null`), is REFUSED before a task '
372
+ + 'exists \u2014 it is never shortened \u2014 and a blank value is the same as omitting it. It is stored with the '
373
+ + 'task record and appears in the `goalDescription` field of the task view that `delegate_submit` '
374
+ + 'returns and of `delegate_result`; it is never derived from the prompt, a parent task or the result, '
375
+ + 'and it does not change what the worker is told.',
376
+ },
346
377
  },
347
378
  required: ['workspacePath', 'prompt'],
348
379
  additionalProperties: false,
@@ -354,10 +385,10 @@ export const TOOLS = Object.freeze([
354
385
  description: 'Read one task this connection submitted: state, effective provider/model/effort, '
355
386
  + 'changed-file summary, bounded diff, validation evidence and review outcome. '
356
387
  + 'A finished execution is not host acceptance. '
357
- + 'The review note is returned in full when it fits; when the whole answer is too large the answer says '
358
- + '`hostAcceptance.noteOmitted: true` and the text is read in pages with `reviewNoteOffset` and '
359
- + '`reviewNoteLimit` (a page answer carries only the slice, `noteChars`, `nextOffset` and `complete`). '
360
- + 'A note is never silently shortened.',
388
+ + 'The review note and completion summary are returned in full when they fit; when the whole answer is '
389
+ + 'too large they are marked `hostAcceptance.noteOmitted: true` (read with `reviewNoteOffset`/'
390
+ + '`reviewNoteLimit`) or `hostAcceptance.completionSummaryOmitted: true` (read with '
391
+ + '`completionSummaryOffset`/`completionSummaryLimit`), never silently shortened.',
361
392
  // A read of a stored task: no work is created, changed or cancelled.
362
393
  annotations: Object.freeze({
363
394
  title: 'Read task result',
@@ -384,6 +415,19 @@ export const TOOLS = Object.freeze([
384
415
  description: `Code points of the review note to return per page (1..${MAX_REVIEW_NOTE_PAGE_CHARS}, `
385
416
  + 'default 2000). Only meaningful together with reviewNoteOffset.',
386
417
  },
418
+ completionSummaryOffset: {
419
+ type: 'integer',
420
+ minimum: 0,
421
+ description: 'Read hostAcceptance.completionSummary from this CODE-POINT offset when '
422
+ + 'completionSummaryOmitted is true. Returns ONLY the summary slice plus summaryChars, nextOffset and complete.',
423
+ },
424
+ completionSummaryLimit: {
425
+ type: 'integer',
426
+ minimum: 1,
427
+ maximum: MAX_COMPLETION_SUMMARY_PAGE_CHARS,
428
+ description: `Code points of completionSummary per page (1..${MAX_COMPLETION_SUMMARY_PAGE_CHARS}, `
429
+ + 'default 2000). Only meaningful together with completionSummaryOffset.',
430
+ },
387
431
  },
388
432
  required: ['taskId'],
389
433
  additionalProperties: false,
@@ -722,6 +766,22 @@ export const TOOLS = Object.freeze([
722
766
  + 'note is refused with its actual length instead of being cut. '
723
767
  + 'It is evidence of your review, never a grant and never a place for credentials.',
724
768
  },
769
+ completionSummary: {
770
+ type: 'string',
771
+ maxLength: MAX_TASK_DESCRIPTION_CHARS,
772
+ codePointLength: true,
773
+ description: 'OPTIONAL. What was actually DONE in this round, in your own words, after reviewing the '
774
+ + 'evidence \u2014 the counterpart of the submission\u2019s `goalDescription`. At most 2000 Unicode code points '
775
+ + '(Chinese, line breaks and emoji count once); surrounding whitespace is trimmed and inner line breaks '
776
+ + 'are kept; a longer or non-string value is refused, never shortened; a blank value is the same as '
777
+ + 'omitting it. It may accompany `accepted` or `changes-requested` \u2014 with the latter it states only the '
778
+ + 'part that was completed and does NOT mean the task passed. It is recorded inside the same review '
779
+ + 'write as `decision` and `note`, under `hostAcceptance.completionSummary`, and becomes visible only '
780
+ + 'once that write is durable. A finished execution, worker output or a run that merely looked '
781
+ + 'successful never produces one. It is part of the review\u2019s identity: repeating the same decision and '
782
+ + 'note WITH the same summary is an idempotent no-op, and a different summary \u2014 or adding one to an '
783
+ + 'already recorded review \u2014 is refused like any other different conclusion.',
784
+ },
725
785
  },
726
786
  required: ['taskId', 'decision', 'note'],
727
787
  additionalProperties: false,
@@ -822,6 +882,16 @@ const TOOL_ROUTES = Object.freeze({
822
882
  delegate_metrics: null,
823
883
  });
824
884
 
885
+ /** Canonicalize a description argument (enforcing post-redaction code-point bound). */
886
+ function canonicalizeToolDescription(tool, key, field) {
887
+ const read = canonicalTaskDescription(field, key, redactText);
888
+ if (read.ok === false) {
889
+ throw new McpError('MCP_ARGUMENT_RANGE',
890
+ `${tool.name}.${key} must be at most ${read.refusal.limit} Unicode code points, but it is ${read.refusal.length}`);
891
+ }
892
+ return read.value ?? '';
893
+ }
894
+
825
895
  /**
826
896
  * The one argument this surface adds to a request it forwards.
827
897
  *
@@ -981,7 +1051,10 @@ function validateArgs(tool, args) {
981
1051
  if (typeof declared.minLength === 'number' && field.length < declared.minLength) {
982
1052
  throw new McpError('MCP_ARGUMENT_REQUIRED', `${tool.name}.${key} must not be empty`);
983
1053
  }
984
- out[key] = field;
1054
+ // The two commander descriptions also pass the redaction-length half of the rule.
1055
+ out[key] = (key === TASK_DESCRIPTION_FIELDS.goal || key === TASK_DESCRIPTION_FIELDS.summary)
1056
+ ? canonicalizeToolDescription(tool, key, field)
1057
+ : field;
985
1058
  } else if (declared.type === 'boolean') {
986
1059
  // Strict: a model that sends the string "true" gets a refusal naming the
987
1060
  // field instead of a silently truthy value reaching the plane.
@@ -1017,8 +1090,16 @@ function validateArgs(tool, args) {
1017
1090
  throw new McpError('MCP_ARGUMENT_ENUM', `${tool.name}.${key} must be one of ${declared.enum.join(', ')}`);
1018
1091
  }
1019
1092
  }
1020
- if (tool.name === 'delegate_result' && out.reviewNoteLimit !== undefined && out.reviewNoteOffset === undefined) {
1021
- throw new McpError('MCP_ARGUMENT_REQUIRED', 'delegate_result.reviewNoteLimit requires reviewNoteOffset');
1093
+ if (tool.name === 'delegate_result') {
1094
+ if (out.reviewNoteLimit !== undefined && out.reviewNoteOffset === undefined) {
1095
+ throw new McpError('MCP_ARGUMENT_REQUIRED', 'delegate_result.reviewNoteLimit requires reviewNoteOffset');
1096
+ }
1097
+ if (out.completionSummaryLimit !== undefined && out.completionSummaryOffset === undefined) {
1098
+ throw new McpError('MCP_ARGUMENT_REQUIRED', 'delegate_result.completionSummaryLimit requires completionSummaryOffset');
1099
+ }
1100
+ if (out.reviewNoteOffset !== undefined && out.completionSummaryOffset !== undefined) {
1101
+ throw new McpError('MCP_ARGUMENTS_INVALID', 'delegate_result cannot combine reviewNoteOffset and completionSummaryOffset');
1102
+ }
1022
1103
  }
1023
1104
  return out;
1024
1105
  }
@@ -1189,11 +1270,29 @@ function trimAllStrings(value, path, cap, collect, depth = 0) {
1189
1270
  const out = {};
1190
1271
  for (const [key, item] of Object.entries(value)) {
1191
1272
  const childPath = path === '' ? key : `${path}.${key}`;
1273
+ if (isDescriptionField(key, item, path)) {
1274
+ out[key] = item;
1275
+ continue;
1276
+ }
1192
1277
  out[key] = trimAllStrings(item, childPath, cap, collect, depth + 1);
1193
1278
  }
1194
1279
  return out;
1195
1280
  }
1196
1281
 
1282
+ /** True when `value` is a legal description string at a published task/acceptance position. */
1283
+ function isDescriptionField(key, value, parentPath) {
1284
+ if (key !== TASK_DESCRIPTION_FIELDS.goal && key !== TASK_DESCRIPTION_FIELDS.summary) return false;
1285
+ if (typeof value !== 'string') return false;
1286
+ if (key === TASK_DESCRIPTION_FIELDS.goal) {
1287
+ if (parentPath !== '' && parentPath !== 'task' && !/^tasks\[\d+\]$/u.test(parentPath)) return false;
1288
+ } else if (parentPath !== 'hostAcceptance'
1289
+ && parentPath !== 'task.hostAcceptance'
1290
+ && !/^tasks\[\d+\]\.hostAcceptance$/u.test(parentPath)) {
1291
+ return false;
1292
+ }
1293
+ return reviewNoteLength(value) <= TASK_DESCRIPTION_MAX_CHARS;
1294
+ }
1295
+
1197
1296
  /**
1198
1297
  * Replace one heavy field with a bounded summary that keeps its shape.
1199
1298
  * @param {unknown} source - field value.
@@ -1425,10 +1524,14 @@ function projectWithStage(value, stage, collect) {
1425
1524
  }
1426
1525
  // A full result KEEPS the whole note while it fits; when a stage has to give it up it
1427
1526
  // is marked `noteOmitted` and read back in pages, never shortened. (`prefix` already
1428
- // ends in a dot.)
1429
- const acceptance = target.hostAcceptance;
1430
- if (acceptance !== null && typeof acceptance === 'object') {
1431
- target.hostAcceptance = boundAcceptance(acceptance, `${prefix}hostAcceptance`, collect, stage.omitNote === true);
1527
+ // ends in a dot.) Skeleton stages bound `hostAcceptance` once inside `skeletonize`.
1528
+ if (stage.skeletonChars === undefined) {
1529
+ const acceptance = target.hostAcceptance;
1530
+ if (acceptance !== null && typeof acceptance === 'object' && !Array.isArray(acceptance)) {
1531
+ target.hostAcceptance = boundAcceptance(
1532
+ acceptance, `${prefix}hostAcceptance`, collect, stage.omitNote === true, stage.omitSummary === true,
1533
+ );
1534
+ }
1432
1535
  }
1433
1536
  // The settled decision trail is HISTORY; the pending request is the thing the
1434
1537
  // commander must act on NOW. Under a bound the history goes first, so a running
@@ -1448,15 +1551,21 @@ function projectWithStage(value, stage, collect) {
1448
1551
  }
1449
1552
  }
1450
1553
  }
1554
+ if (stage.skeletonChars === undefined && projected.hostAcceptance !== null
1555
+ && typeof projected.hostAcceptance === 'object' && !Array.isArray(projected.hostAcceptance)) {
1556
+ projected.hostAcceptance = boundAcceptance(
1557
+ projected.hostAcceptance, 'hostAcceptance', collect, stage.omitNote === true, stage.omitSummary === true,
1558
+ );
1559
+ }
1451
1560
  if (Array.isArray(projected.tasks) && projected.tasks.length > stage.lists) {
1452
1561
  collect.push(truncationRecord('tasks', { total: projected.tasks.length, omitted: projected.tasks.length - stage.lists }));
1453
1562
  projected.tasks = projected.tasks.slice(0, stage.lists);
1454
1563
  }
1455
1564
  if (stage.skeletonChars !== undefined) {
1456
1565
  const cap = stage.skeletonChars;
1457
- if (projected.task !== undefined) projected.task = skeletonize(projected.task, 'task', cap, collect);
1566
+ if (projected.task !== undefined) projected.task = skeletonize(projected.task, 'task', cap, collect, stage);
1458
1567
  if (Array.isArray(projected.tasks)) {
1459
- projected.tasks = projected.tasks.map((task, index) => skeletonize(task, `tasks[${index}]`, cap, collect));
1568
+ projected.tasks = projected.tasks.map((task, index) => skeletonize(task, `tasks[${index}]`, cap, collect, stage));
1460
1569
  }
1461
1570
  // Anything else at the top level (a status answer's grants, a list's extras)
1462
1571
  // is trimmed rather than dropped, so nothing disappears unexplained. The
@@ -1482,15 +1591,54 @@ function projectWithStage(value, stage, collect) {
1482
1591
  }
1483
1592
  if (key === 'answerReceipt' || key === 'decisionReceipt') continue;
1484
1593
  if (key === 'hostAcceptance' && item !== null && typeof item === 'object' && !Array.isArray(item)) {
1485
- projected[key] = boundAcceptance(item, key, collect);
1594
+ projected[key] = boundAcceptance(item, key, collect, stage.omitNote === true, stage.omitSummary === true);
1486
1595
  continue;
1487
1596
  }
1488
1597
  projected[key] = trimAllStrings(item, key, cap, collect);
1489
1598
  }
1490
1599
  }
1600
+ guardDescriptionFields(projected, stage.skeletonChars ?? TRUNCATED_FIELD_CAPS.listItemChars, collect);
1491
1601
  return projected;
1492
1602
  }
1493
1603
 
1604
+ /** Bound any anomalous value sitting at `goalDescription` or `hostAcceptance.completionSummary`. */
1605
+ function guardDescriptionFields(answer, cap, collect) {
1606
+ const inspect = (task, prefix) => {
1607
+ if (task === null || typeof task !== 'object' || Array.isArray(task)) return;
1608
+ if (Object.hasOwn(task, TASK_DESCRIPTION_FIELDS.goal)) {
1609
+ const goal = task[TASK_DESCRIPTION_FIELDS.goal];
1610
+ if (typeof goal !== 'string' || reviewNoteLength(goal) > TASK_DESCRIPTION_MAX_CHARS) {
1611
+ task[TASK_DESCRIPTION_FIELDS.goal] = boundValue(
1612
+ goal,
1613
+ `${prefix}${TASK_DESCRIPTION_FIELDS.goal}`,
1614
+ cap,
1615
+ collect,
1616
+ );
1617
+ }
1618
+ }
1619
+ const acceptance = task.hostAcceptance;
1620
+ if (acceptance !== null && typeof acceptance === 'object' && !Array.isArray(acceptance)
1621
+ && Object.hasOwn(acceptance, TASK_DESCRIPTION_FIELDS.summary)) {
1622
+ const summary = acceptance[TASK_DESCRIPTION_FIELDS.summary];
1623
+ if (typeof summary !== 'string' || reviewNoteLength(summary) > TASK_DESCRIPTION_MAX_CHARS) {
1624
+ acceptance[TASK_DESCRIPTION_FIELDS.summary] = boundValue(
1625
+ summary,
1626
+ `${prefix}hostAcceptance.${TASK_DESCRIPTION_FIELDS.summary}`,
1627
+ cap,
1628
+ collect,
1629
+ );
1630
+ }
1631
+ }
1632
+ };
1633
+ inspect(answer.task ?? null, 'task.');
1634
+ if (Array.isArray(answer.tasks)) {
1635
+ for (let index = 0; index < answer.tasks.length; index += 1) inspect(answer.tasks[index], `tasks[${index}].`);
1636
+ }
1637
+ if (answer.hostAcceptance !== null && typeof answer.hostAcceptance === 'object') {
1638
+ inspect({ hostAcceptance: answer.hostAcceptance }, '');
1639
+ }
1640
+ }
1641
+
1494
1642
  /**
1495
1643
  * The identity, state, routing, refusal and acceptance block that is never
1496
1644
  * dropped, renderable even when nothing else fits.
@@ -1500,7 +1648,7 @@ function projectWithStage(value, stage, collect) {
1500
1648
  * @param {object[]} collect - truncation records.
1501
1649
  * @returns {object} skeleton.
1502
1650
  */
1503
- function skeletonize(task, path, cap, collect) {
1651
+ function skeletonize(task, path, cap, collect, stage = {}) {
1504
1652
  if (task === null || typeof task !== 'object' || Array.isArray(task)) return task ?? null;
1505
1653
  const pick = (key) => (key in task ? boundValue(task[key], `${path}.${key}`, cap, collect) : undefined);
1506
1654
  const out = {};
@@ -1509,6 +1657,16 @@ function skeletonize(task, path, cap, collect) {
1509
1657
  // The Agent Teams verdict is four booleans and a short reason: it survives every
1510
1658
  // bound so a compressed answer still says whether teams are on for this run.
1511
1659
  'agentTeams', 'team']) {
1660
+ if (key === 'hostAcceptance') {
1661
+ // Projected directly from the uncut review block so the generic per-string cap never
1662
+ // shortens `completionSummary` or `note` before their field-specific rules run.
1663
+ if (!('hostAcceptance' in task)) continue;
1664
+ const raw = task.hostAcceptance;
1665
+ out.hostAcceptance = raw === null || typeof raw !== 'object' || Array.isArray(raw)
1666
+ ? (raw ?? null)
1667
+ : boundAcceptance(raw, `${path}.hostAcceptance`, collect, stage.omitNote === true, stage.omitSummary === true);
1668
+ continue;
1669
+ }
1512
1670
  const value = pick(key);
1513
1671
  if (value === undefined) continue;
1514
1672
  if (key === 'execution' && value !== null && typeof value === 'object') {
@@ -1518,12 +1676,6 @@ function skeletonize(task, path, cap, collect) {
1518
1676
  }
1519
1677
  } else if (key === 'route' || key === 'reviewRoute') {
1520
1678
  out[key] = value === null ? null : boundValue(value, `${path}.${key}`, cap, collect);
1521
- } else if (key === 'hostAcceptance') {
1522
- // The recorded CONCLUSION is restored to its own bound after the generic walk, so a
1523
- // small per-string cap can never shorten what the host concluded while leaving a
1524
- // record that still reads as the whole note. A note beyond the accepted bound is
1525
- // cut once, and the cut is stated.
1526
- out[key] = value === null ? null : boundAcceptance(value, `${path}.hostAcceptance`, collect);
1527
1679
  } else {
1528
1680
  out[key] = value;
1529
1681
  }
@@ -1536,6 +1688,12 @@ function skeletonize(task, path, cap, collect) {
1536
1688
  // operation can never read as complete.
1537
1689
  const pending = pendingPermissionsOf(task, path, collect);
1538
1690
  if (pending !== undefined) out.permission = pending;
1691
+ const goal = verbatimDescription(task);
1692
+ if (goal !== null) {
1693
+ out.goalDescription = goal;
1694
+ } else if (task?.goalDescription !== undefined) {
1695
+ out.goalDescription = boundValue(task.goalDescription, `${path}.goalDescription`, cap, collect);
1696
+ }
1539
1697
  if (task.question?.pending !== null && typeof task.question?.pending === 'object') {
1540
1698
  out.question = boundQuestionBlock(task.question, `${path}.question`, collect, QUESTION_WIRE_BUDGET);
1541
1699
  }
@@ -1544,28 +1702,61 @@ function skeletonize(task, path, cap, collect) {
1544
1702
  return out;
1545
1703
  }
1546
1704
 
1705
+ function verbatimDescription(source) {
1706
+ const value = source?.goalDescription;
1707
+ if (typeof value !== 'string') return null;
1708
+ return reviewNoteLength(value) <= TASK_DESCRIPTION_MAX_CHARS ? value : null;
1709
+ }
1710
+
1547
1711
  /**
1548
1712
  * Bound a recorded host review for a skeletonised answer.
1549
1713
  *
1550
1714
  * The conclusion fields are carried as the engine states them — `accepted`, `state`,
1551
1715
  * `acceptedAt`, `by` — because they are the answer to "was this accepted?", and the note
1552
- * keeps its own generous cap rather than the skeleton's per-string one. Anything else
1553
- * present is bounded generically, so a widened record cannot smuggle a long value in
1554
- * through this exception.
1716
+ * keeps its own generous cap rather than the skeleton's per-string one. The completion
1717
+ * summary is bounded the same way as the note: kept whole when the record carries one, and
1718
+ * omitted explicitly with its length when the body has to be given up, so it is never
1719
+ * silently cut. Anything else present is bounded generically, so a widened record cannot
1720
+ * smuggle a long value in through this exception.
1555
1721
  * @param {object} acceptance - host-acceptance record.
1556
1722
  * @param {string} path - JSON path.
1557
1723
  * @param {object[]} collect - truncation records.
1558
1724
  * @returns {object} bounded record.
1559
1725
  */
1560
- function boundAcceptance(acceptance, path, collect, omitNoteText = false) {
1561
- if (omitNoteText) return omitNote(acceptance, `${path}.note`, collect);
1726
+ function boundAcceptance(acceptance, path, collect, omitNoteText = false, omitSummaryText = false) {
1727
+ if (omitNoteText) return omitNote(acceptance, `${path}.note`, collect, omitSummaryText);
1562
1728
  const out = {};
1563
1729
  for (const [key, value] of Object.entries(acceptance)) {
1564
1730
  if (key === 'note' && typeof value === 'string') {
1565
- out[key] = value;
1731
+ out[key] = reviewNoteLength(value) <= REVIEW_NOTE_MAX_CHARS
1732
+ ? value
1733
+ : boundValue(value, `${path}.note`, REVIEW_NOTE_MAX_CHARS, collect);
1566
1734
  continue;
1567
1735
  }
1568
- if (['accepted', 'state', 'acceptedAt', 'by', 'noteChars', 'noteOmitted'].includes(key)) {
1736
+ if (key === 'completionSummary') {
1737
+ if (value === undefined || value === null) continue;
1738
+ if (typeof value === 'string' && reviewNoteLength(value) <= TASK_DESCRIPTION_MAX_CHARS) {
1739
+ if (omitSummaryText) {
1740
+ const summaryLen = reviewNoteLength(value);
1741
+ out.completionSummaryChars = acceptance.completionSummaryChars ?? summaryLen;
1742
+ out.completionSummaryOmitted = true;
1743
+ collect.push({
1744
+ path: `${path}.completionSummary`,
1745
+ field: 'text',
1746
+ keptChars: 0,
1747
+ omittedChars: summaryLen,
1748
+ detail: 'the completion summary is read with delegate_result completionSummaryOffset/completionSummaryLimit',
1749
+ });
1750
+ } else {
1751
+ out[key] = value;
1752
+ }
1753
+ } else {
1754
+ out[key] = boundValue(value, `${path}.completionSummary`, 240, collect);
1755
+ }
1756
+ continue;
1757
+ }
1758
+ if (['accepted', 'state', 'acceptedAt', 'by', 'noteChars', 'noteOmitted',
1759
+ 'completionSummaryChars', 'completionSummaryOmitted'].includes(key)) {
1569
1760
  out[key] = value;
1570
1761
  continue;
1571
1762
  }
@@ -1575,16 +1766,15 @@ function boundAcceptance(acceptance, path, collect, omitNoteText = false) {
1575
1766
  }
1576
1767
 
1577
1768
  /**
1578
- * Mark a review note the projection had to drop, instead of publishing a shortened body.
1579
- *
1580
- * The body is never silently cut: `noteOmitted: true` plus `noteChars` says the note is
1581
- * still there, and `reviewNoteOffset`/`reviewNoteLimit` read it in full.
1582
- * @param {object} acceptance - host-acceptance record (mutated copy).
1769
+ * Drop the note body (it is pageable) and keep a legal summary unless explicitly omitted.
1770
+ * @param {object} acceptance - host-acceptance record.
1583
1771
  * @param {string} path - JSON path of the note.
1584
1772
  * @param {object[]} collect - truncation records.
1585
- * @returns {object} the acceptance with an explicitly omitted note.
1773
+ * @param {boolean} [omitSummaryText] - omit a legal summary explicitly when even it cannot fit.
1774
+ * @returns {object} the acceptance with an explicitly omitted note and bounded summary.
1586
1775
  */
1587
- function omitNote(acceptance, path, collect) {
1776
+ function omitNote(acceptance, path, collect, omitSummaryText = false) {
1777
+ const basePath = path.replace(/\.note$/u, '');
1588
1778
  const length = typeof acceptance.note === 'string' ? Array.from(acceptance.note).length : 0;
1589
1779
  if (acceptance.note !== undefined && acceptance.note !== null) {
1590
1780
  collect.push({
@@ -1595,9 +1785,46 @@ function omitNote(acceptance, path, collect) {
1595
1785
  detail: 'the review note is read with delegate_result reviewNoteOffset/reviewNoteLimit',
1596
1786
  });
1597
1787
  }
1598
- const { note, ...rest } = acceptance;
1788
+ const { note, completionSummary, ...rest } = acceptance;
1599
1789
  void note;
1600
- return { ...rest, noteChars: acceptance.noteChars ?? length, noteOmitted: true };
1790
+ const out = {};
1791
+ for (const [key, value] of Object.entries(rest)) {
1792
+ if (['accepted', 'state', 'acceptedAt', 'by', 'noteChars', 'noteOmitted',
1793
+ 'completionSummaryChars', 'completionSummaryOmitted'].includes(key)) {
1794
+ out[key] = value;
1795
+ } else {
1796
+ out[key] = boundValue(value, `${basePath}.${key}`, 240, collect);
1797
+ }
1798
+ }
1799
+ out.noteChars = acceptance.noteChars ?? length;
1800
+ out.noteOmitted = true;
1801
+ if (completionSummary !== undefined && completionSummary !== null) {
1802
+ if (typeof completionSummary === 'string' && reviewNoteLength(completionSummary) <= TASK_DESCRIPTION_MAX_CHARS) {
1803
+ if (omitSummaryText) {
1804
+ const summaryLen = reviewNoteLength(completionSummary);
1805
+ out.completionSummaryChars = acceptance.completionSummaryChars ?? summaryLen;
1806
+ out.completionSummaryOmitted = true;
1807
+ collect.push({
1808
+ path: `${basePath}.completionSummary`,
1809
+ field: 'text',
1810
+ keptChars: 0,
1811
+ omittedChars: summaryLen,
1812
+ detail: 'the completion summary is read with delegate_result completionSummaryOffset/completionSummaryLimit',
1813
+ });
1814
+ } else {
1815
+ out.completionSummary = completionSummary;
1816
+ }
1817
+ } else {
1818
+ // Not a description this build would have stored: bound it and state the cut.
1819
+ out.completionSummary = boundValue(
1820
+ completionSummary,
1821
+ `${basePath}.completionSummary`,
1822
+ 240,
1823
+ collect,
1824
+ );
1825
+ }
1826
+ }
1827
+ return out;
1601
1828
  }
1602
1829
 
1603
1830
  /**
@@ -1882,7 +2109,9 @@ function boundedJson(value) {
1882
2109
  // full width, and only the body becomes `noteOmitted`, readable in pages.
1883
2110
  { executionText: 120, reviewText: 120, lists: 1, permissionEvidence: 1, omitNote: true },
1884
2111
  { executionText: 80, reviewText: 80, lists: 1, permissionEvidence: 0, skeletonChars: 240 },
1885
- { executionText: 40, reviewText: 40, lists: 1, permissionEvidence: 0, skeletonChars: 96 },
2112
+ { executionText: 80, reviewText: 80, lists: 1, permissionEvidence: 0, skeletonChars: 240, omitNote: true },
2113
+ { executionText: 40, reviewText: 40, lists: 1, permissionEvidence: 0, skeletonChars: 96, omitNote: true },
2114
+ { executionText: 40, reviewText: 40, lists: 1, permissionEvidence: 0, skeletonChars: 96, omitNote: true, omitSummary: true },
1886
2115
  ];
1887
2116
  const apply = (stage) => {
1888
2117
  const records = [];
@@ -2419,9 +2648,11 @@ export function createMcpServer(options) {
2419
2648
  } else {
2420
2649
  result = await callExecution(route, payload);
2421
2650
  }
2422
- // A paged read of the review note returns only its slice: it is a different, small
2423
- // ANSWER shape, not a projection of the big one.
2424
- const page = name === 'delegate_result' ? reviewNotePage(payload, result) : null;
2651
+ // A paged read of the review note or completion summary returns only its slice:
2652
+ // it is a different, small ANSWER shape, not a projection of the big one.
2653
+ const page = name === 'delegate_result'
2654
+ ? (reviewNotePage(payload, result) ?? completionSummaryPage(payload, result))
2655
+ : null;
2425
2656
  const bounded = boundedJson(page ?? result);
2426
2657
  producedText = bounded.text;
2427
2658
  // A structurally trimmed answer is a real answer, so `isError` stays unset;
@@ -3289,6 +3520,59 @@ function reviewNotePage(payload, result) {
3289
3520
  by: acceptance.by ?? null,
3290
3521
  noteChars: points.length,
3291
3522
  noteOmitted: true,
3523
+ ...(typeof acceptance.completionSummary === 'string' && acceptance.completionSummary !== ''
3524
+ ? {
3525
+ completionSummaryChars: Array.from(acceptance.completionSummary).length,
3526
+ completionSummaryOmitted: true,
3527
+ }
3528
+ : {}),
3529
+ },
3530
+ reviewPersistence: task?.reviewPersistence ?? null,
3531
+ };
3532
+ }
3533
+
3534
+ /**
3535
+ * Build the page answer for one `completionSummaryOffset` read, or null for a normal result.
3536
+ * @param {object} payload - validated `delegate_result` arguments.
3537
+ * @param {object} result - the plane's answer.
3538
+ * @returns {object | null} the page answer, or null when this is not a summary paged read.
3539
+ */
3540
+ function completionSummaryPage(payload, result) {
3541
+ if (payload?.completionSummaryOffset === undefined) return null;
3542
+ const task = result?.task !== null && typeof result?.task === 'object' ? result.task : null;
3543
+ const acceptance = task?.hostAcceptance ?? result?.hostAcceptance ?? null;
3544
+ const summary = typeof acceptance?.completionSummary === 'string' ? acceptance.completionSummary : '';
3545
+ const points = Array.from(summary);
3546
+ const offset = Math.min(payload.completionSummaryOffset, points.length);
3547
+ const limit = payload.completionSummaryLimit ?? DEFAULT_COMPLETION_SUMMARY_PAGE_CHARS;
3548
+ const slice = points.slice(offset, offset + limit).join('');
3549
+ const next = offset + (offset + limit < points.length ? limit : points.length - offset);
3550
+ const noteChars = typeof acceptance?.note === 'string'
3551
+ ? Array.from(acceptance.note).length
3552
+ : (typeof acceptance?.noteChars === 'number' ? acceptance.noteChars : 0);
3553
+ return {
3554
+ ok: true,
3555
+ taskId: task?.taskId ?? payload.taskId,
3556
+ state: task?.state ?? null,
3557
+ completionSummary: {
3558
+ offset,
3559
+ limit,
3560
+ text: slice,
3561
+ summaryChars: points.length,
3562
+ nextOffset: next < points.length ? next : null,
3563
+ complete: next >= points.length,
3564
+ present: summary !== '',
3565
+ },
3566
+ hostAcceptance: acceptance === null
3567
+ ? null
3568
+ : {
3569
+ accepted: acceptance.accepted === true,
3570
+ state: acceptance.state ?? null,
3571
+ acceptedAt: acceptance.acceptedAt ?? null,
3572
+ by: acceptance.by ?? null,
3573
+ noteChars,
3574
+ noteOmitted: true,
3575
+ ...(summary !== '' ? { completionSummaryChars: points.length, completionSummaryOmitted: true } : {}),
3292
3576
  },
3293
3577
  reviewPersistence: task?.reviewPersistence ?? null,
3294
3578
  };