dsh-taskbridge 1.3.2 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/mcp/server.js CHANGED
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // Design rule taken from SPEC §10–11: an external MCP client may *exercise* an
4
4
  // authorization the operator already created, and may do nothing else. So this
5
- // server exposes seven tools and maps each one onto one execution-plane route:
5
+ // server exposes eight tools and maps each one onto one execution-plane route:
6
6
  //
7
7
  // delegate_status → GET /dsh-delegate/x/status
8
8
  // delegate_submit → POST /dsh-delegate/x/tasks
@@ -10,6 +10,7 @@
10
10
  // delegate_wait → POST /dsh-delegate/x/tasks/observe (repeated)
11
11
  // delegate_cancel → POST /dsh-delegate/x/tasks/cancel
12
12
  // delegate_permission_decide → POST /dsh-delegate/x/tasks/permission
13
+ // delegate_review → POST /dsh-delegate/x/tasks/review
13
14
  // delegate_preflight → POST /dsh-delegate/x/workspace/preflight
14
15
  //
15
16
  // `delegate_wait` is a read like `delegate_result`, and it is the one tool whose
@@ -33,6 +34,14 @@
33
34
  // a real tool-surface restriction, but NOT a claim that a process running as the same OS
34
35
  // user could not reach the shared local-MCP endpoint directly. See `runtime/permissions.js`.
35
36
  //
37
+ // `delegate_review` is the second narrow write, and it is the ONLY thing that records a
38
+ // task's `hostAcceptance`: the commander's own delivery conclusion (`accepted` or
39
+ // `changes-requested`). A finished run stays `awaiting-host-review` — that underlying
40
+ // state is what keeps older clients and `continueFromTaskId` compatible — and the review
41
+ // lives in its own field. It cannot approve a permission, change the switch, a provider,
42
+ // a model, the isolation or a credential, merge a diff, or create work; it also cannot
43
+ // be reached by the worker's own catalog, for the same reason as above.
44
+ //
36
45
  // `delegate_preflight` is the one addition that is not an authorization at all: it
37
46
  // is a read-only measurement of a workspace, and it exists so a dispatcher can
38
47
  // learn before submitting that a checkout is dirty, is not a repository, or would
@@ -62,6 +71,13 @@
62
71
  // made it fail at link time with `ERR_MODULE_NOT_FOUND` before it could report
63
72
  // anything at all.
64
73
  import { diagnostic, redactText } from '../config/redact.js';
74
+ import {
75
+ REVIEW_NOTE_MAX_CHARS,
76
+ normalizeReviewNote,
77
+ reviewNoteLength,
78
+ reviewNoteOverflow,
79
+ truncateCodePoints,
80
+ } from '../jobs/review-note.js';
65
81
  import { waitForTask } from './wait.js';
66
82
 
67
83
  /** Protocol revisions this server can speak, newest first (as the SDK lists them). */
@@ -76,11 +92,22 @@ export const SUPPORTED_PROTOCOL_VERSIONS = Object.freeze([
76
92
  export const LATEST_PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[0];
77
93
 
78
94
  /** Identifies this server in the handshake. */
79
- export const SERVER_INFO = Object.freeze({ name: 'dsh-delegate', version: '1.3.2' });
95
+ export const SERVER_INFO = Object.freeze({ name: 'dsh-delegate', version: '1.4.1' });
80
96
 
81
97
  /** Bound on a tool result's text. A task view can be large; a model's context cannot. */
82
98
  export const MAX_TOOL_TEXT_CHARS = 20_000;
83
99
 
100
+ /**
101
+ * Largest page of a review note one `delegate_result` call returns, in code points.
102
+ *
103
+ * A page is deliberately small: it exists so a note far larger than the tool-text bound can
104
+ * be read in full, a page at a time, without one answer blowing a model's context.
105
+ */
106
+ export const MAX_REVIEW_NOTE_PAGE_CHARS = 2_000;
107
+
108
+ /** Default page size of a `reviewNoteOffset` read. */
109
+ export const DEFAULT_REVIEW_NOTE_PAGE_CHARS = 2_000;
110
+
84
111
  /** Bound on one execution-plane request. */
85
112
  export const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
86
113
 
@@ -102,6 +129,17 @@ export const MAX_WAIT_SECONDS = 3_600;
102
129
  /** Shortest deadline one `delegate_wait` call may ask for, in seconds. */
103
130
  export const MIN_WAIT_SECONDS = 1;
104
131
 
132
+ /**
133
+ * Longest `delegate_review` note, in Unicode code points.
134
+ *
135
+ * This is the shared definition (`src/jobs/review-note.js`), re-exported because the MCP
136
+ * catalog is the first surface a client sees. The same value bounds the execution plane,
137
+ * the engine and the durable history projection, and all of them count CODE POINTS, not
138
+ * UTF-16 units: a note written in Chinese or with emoji gets the same room, and a
139
+ * surrogate pair cannot be split by a bound.
140
+ */
141
+ export const MAX_REVIEW_NOTE_CHARS = REVIEW_NOTE_MAX_CHARS;
142
+
105
143
  /**
106
144
  * How many requests may be in flight at once on the stdio transport.
107
145
  *
@@ -259,7 +297,11 @@ export const TOOLS = Object.freeze([
259
297
  title: 'Read task result',
260
298
  description: 'Read one task this connection submitted: state, effective provider/model/effort, '
261
299
  + 'changed-file summary, bounded diff, validation evidence and review outcome. '
262
- + 'A finished execution is not host acceptance.',
300
+ + 'A finished execution is not host acceptance. '
301
+ + 'The review note is returned in full when it fits; when the whole answer is too large the answer says '
302
+ + '`hostAcceptance.noteOmitted: true` and the text is read in pages with `reviewNoteOffset` and '
303
+ + '`reviewNoteLimit` (a page answer carries only the slice, `noteChars`, `nextOffset` and `complete`). '
304
+ + 'A note is never silently shortened.',
263
305
  // A read of a stored task: no work is created, changed or cancelled.
264
306
  annotations: Object.freeze({
265
307
  title: 'Read task result',
@@ -272,6 +314,20 @@ export const TOOLS = Object.freeze([
272
314
  type: 'object',
273
315
  properties: {
274
316
  taskId: { type: 'string', description: 'Task identity returned by delegate_submit.' },
317
+ reviewNoteOffset: {
318
+ type: 'integer',
319
+ minimum: 0,
320
+ description: 'Read the review note from this CODE-POINT offset. Omit it for the normal full result; '
321
+ + 'supplying it (with or without reviewNoteLimit) returns ONLY the note slice plus its total '
322
+ + 'length, nextOffset and complete.',
323
+ },
324
+ reviewNoteLimit: {
325
+ type: 'integer',
326
+ minimum: 1,
327
+ maximum: MAX_REVIEW_NOTE_PAGE_CHARS,
328
+ description: `Code points of the review note to return per page (1..${MAX_REVIEW_NOTE_PAGE_CHARS}, `
329
+ + 'default 2000). Only meaningful together with reviewNoteOffset.',
330
+ },
275
331
  },
276
332
  required: ['taskId'],
277
333
  additionalProperties: false,
@@ -282,11 +338,23 @@ export const TOOLS = Object.freeze([
282
338
  title: 'Wait for a task to need you',
283
339
  description: 'Follow ONE task this connection submitted and return as soon as it needs the host. '
284
340
  + 'A single call blocks for up to waitSeconds (default 3600) and returns a COMPACT answer: '
285
- + '`reason` is `permission` (a per-call request is pending), `attention` (no activity for about ten '
286
- + 'minutes, so the run may be stuck), `ready` (the run ended and is awaiting host review), `failed`, '
287
- + '`cancelled` or `interrupted`. '
288
- + '`reason: "wait-limit"` means the deadline was reached and NOTHING changed: call delegate_wait again '
289
- + 'with the same taskId — do not review, resubmit or restart the task. '
341
+ + '`reason` is `permission` (a per-call request is pending), `attention` (the run has been silent for '
342
+ + 'the configured inactivity threshold, ten minutes by default, so it may be stuck), `ready` (the run '
343
+ + 'ended and is awaiting host review), `failed`, `cancelled` or `interrupted`. '
344
+ + 'An `attention` answer may instead carry a `failure` block (kind `repeated-tool-failure`, with '
345
+ + 'toolName/failureCode/consecutive): the worker repeated the SAME operation and failed the same way '
346
+ + 'several times in a row. It is a question for the host, reported once; nothing is cancelled, retimed '
347
+ + 'or reconfigured automatically. '
348
+ + '`reason: "wait-limit"` means only that this call\u2019s own budget ran out with nothing changed: it is '
349
+ + 'reported with `actionable: false` and `terminal: false`. Call delegate_wait again with the same '
350
+ + 'taskId and omit waitSeconds — do not review, resubmit, restart or cancel the task. '
351
+ + 'Normal use is delegate_wait({ taskId }) with no second argument: the default already covers a full '
352
+ + 'hour and the call re-issues its own internal observations, so there is no reason to shorten it or to '
353
+ + 'poll delegate_result or delegate_status while a task runs. A shorter waitSeconds is accepted for a '
354
+ + 'one-off diagnostic you were explicitly asked for. '
355
+ + 'The internal observation cadence (about one bounded request every 25 seconds) belongs to THIS '
356
+ + 'program; it is not a polling rate for the agent, and nothing about it requires action while nothing '
357
+ + 'has changed. '
290
358
  + 'Heartbeats are internal to this call and are never returned. '
291
359
  + 'This tool reads; it never submits, cancels or decides anything, and it does not fetch the task\u2019s '
292
360
  + 'diff or full result (use delegate_result for that, after an actionable reason). '
@@ -299,7 +367,21 @@ export const TOOLS = Object.freeze([
299
367
  + '`terminal: true` with `state: "interrupted"` means the task record itself is a restart history '
300
368
  + 'and will not resume. If the reason carried a settled state it is reported as that outcome '
301
369
  + '(`ready`/`failed`/`cancelled`). A missing or unrecognized state is reported as '
302
- + '`terminal: false` with nothing asserted: check before deciding.',
370
+ + '`terminal: false` with nothing asserted: check before deciding. '
371
+ + 'This call ending, or your own client tool timeout firing, says NOTHING about the execution: the task '
372
+ + 'may still be running. Keep its taskId, and if you need to know more read one compact fact with '
373
+ + 'delegate_result rather than assuming either way; never submit a duplicate, restart or cancel it '
374
+ + 'because a wait or a client timeout ended. '
375
+ + 'A host may hand a wait back early on its own tool/exec time limit even though this call asked for an '
376
+ + 'hour. That outer event is not `wait-limit` and is not a result: the MCP observation did not end and the '
377
+ + 'worker did not stop. Continue the SAME exec cell (do not open a second wait, read delegate_result, poll '
378
+ + 'delegate_status or submit a duplicate) and ask for the longest yield the host supports — when a yield or '
379
+ + 'pragmas parameter exists, an ordinary wait should request roughly 1200000 ms (20 minutes), not a minute, '
380
+ + 'and re-issuing every second is polling rather than waiting. A one-minute return is a caller choice, not a '
381
+ + 'documented hard limit, so do not present it as the client maximum and do not claim every client offers '
382
+ + 'the same yield. This plugin cannot create a background waiter or wake the agent: if the available yield '
383
+ + 'is genuinely short with no automatic continuation, a long wait costs one resumed turn per yield window, '
384
+ + 'and that limit must be reported honestly rather than worked around.',
303
385
  // A LONG read, and that is the point: `readOnlyHint` is what tells a
304
386
  // concurrency-aware client this call may be held for an hour without being a
305
387
  // mutating operation. A serialising host still ignores it; the independent
@@ -319,8 +401,10 @@ export const TOOLS = Object.freeze([
319
401
  type: 'integer',
320
402
  minimum: MIN_WAIT_SECONDS,
321
403
  maximum: MAX_WAIT_SECONDS,
322
- description: 'How long this one call may wait, in seconds (default 3600). '
323
- + 'A returned `wait-limit` means this deadline was reached, not that the task stalled.',
404
+ description: 'OPTIONAL. Omit it for normal waiting: the default is 3600 seconds (one hour). '
405
+ + 'Set it only for a shorter, one-off diagnostic you were explicitly asked to make. It cannot '
406
+ + 'extend a wait beyond 3600. A returned `wait-limit` with `actionable: false` means this '
407
+ + 'deadline was reached, not that the task stalled or ended.',
324
408
  },
325
409
  },
326
410
  required: ['taskId'],
@@ -399,6 +483,61 @@ export const TOOLS = Object.freeze([
399
483
  additionalProperties: false,
400
484
  }),
401
485
  }),
486
+ Object.freeze({
487
+ name: 'delegate_review',
488
+ title: 'Record the host review of a delivered task',
489
+ description: 'Record YOUR OWN delivery review of one task this connection submitted. A finished run stays '
490
+ + '\u0060awaiting-host-review\u0060 until you say what you concluded: this tool records that conclusion, and it '
491
+ + 'is the only thing that does. '
492
+ + '\u0060decision: "accepted"\u0060 means you reviewed the evidence with \u0060delegate_result\u0060 and it is right; '
493
+ + '\u0060decision: "changes-requested"\u0060 means it needs correction. Either way \u0060note\u0060 is required and '
494
+ + 'bounded (at most 8000 Unicode code points, so Chinese, line breaks and emoji all count once) — it is the '
495
+ + 'recorded conclusion, not a place for secrets. A longer note is refused before anything is written; it is '
496
+ + 'never silently shortened. '
497
+ + 'This cannot approve a permission request, change the switch, a provider, a model, the isolation or a '
498
+ + 'credential, merge or apply the diff, or create another task. Execution completion is never accepted '
499
+ + 'automatically: until this is called the task stays unreviewed. '
500
+ + 'Only a task awaiting host review (execution finished) can be reviewed; a running, failed, cancelled or '
501
+ + 'interrupted task, or another connection\u2019s task, is refused. '
502
+ + 'The first decision is final for this task: repeating the SAME decision with the SAME note is an '
503
+ + 'idempotent no-op, and a DIFFERENT conclusion is refused \u2014 send a follow-up task with '
504
+ + '\u0060continueFromTaskId\u0060 instead, so the original conclusion is preserved.',
505
+ // It records a conclusion on an existing task. It can neither read a workspace nor
506
+ // start, stop or re-configure anything, and a replayed identical decision changes
507
+ // nothing — but a DIFFERENT second decision is a refusal, so it is not fully
508
+ // idempotent either.
509
+ annotations: Object.freeze({
510
+ title: 'Record the host review of a delivered task',
511
+ readOnlyHint: false,
512
+ destructiveHint: false,
513
+ idempotentHint: false,
514
+ openWorldHint: false,
515
+ }),
516
+ inputSchema: Object.freeze({
517
+ type: 'object',
518
+ properties: {
519
+ taskId: { type: 'string', description: 'Task identity returned by delegate_submit.' },
520
+ decision: {
521
+ type: 'string',
522
+ enum: ['accepted', 'changes-requested'],
523
+ description: 'accepted records that you reviewed the result and accept it; changes-requested records '
524
+ + 'that it needs correction.',
525
+ },
526
+ note: {
527
+ type: 'string',
528
+ maxLength: MAX_REVIEW_NOTE_CHARS,
529
+ // The bound is counted in Unicode code points, not in UTF-16 units.
530
+ codePointLength: true,
531
+ description: 'Required non-empty bounded conclusion (at most 8000 Unicode code points), stored redacted. '
532
+ + 'The count is Unicode code points, so Chinese text, line breaks and emoji each count once; a longer '
533
+ + 'note is refused with its actual length instead of being cut. '
534
+ + 'It is evidence of your review, never a grant and never a place for credentials.',
535
+ },
536
+ },
537
+ required: ['taskId', 'decision', 'note'],
538
+ additionalProperties: false,
539
+ }),
540
+ }),
402
541
  Object.freeze({
403
542
  name: 'delegate_preflight',
404
543
  title: 'Inspect workspace before dispatch',
@@ -439,6 +578,7 @@ const TOOL_ROUTES = Object.freeze({
439
578
  delegate_wait: 'observe',
440
579
  delegate_cancel: 'cancel',
441
580
  delegate_permission_decide: 'permission',
581
+ delegate_review: 'review',
442
582
  delegate_preflight: 'preflight',
443
583
  });
444
584
 
@@ -479,6 +619,22 @@ function validateArgs(tool, args) {
479
619
  const field = value[key];
480
620
  if (declared.type === 'string') {
481
621
  if (typeof field !== 'string') throw new McpError('MCP_ARGUMENT_TYPE', `${tool.name}.${key} must be a string`);
622
+ // A declared bound is enforced, not merely advertised: a note over the limit is
623
+ // refused with the field named instead of reaching the plane and being cut there.
624
+ // A `maxLength` is a code-point bound (the shared review-note rule), so it is
625
+ // measured the same way every other surface measures it: `.length` would count an
626
+ // emoji twice and refuse a note the plane would have accepted.
627
+ if (typeof declared.maxLength === 'number' && declared.codePointLength === true) {
628
+ // Measured on the NORMALIZED text (the shared trim), so surrounding whitespace
629
+ // cannot make this layer refuse a note the plane would have accepted.
630
+ const points = reviewNoteLength(normalizeReviewNote(field));
631
+ if (points > declared.maxLength) {
632
+ throw new McpError('MCP_ARGUMENT_RANGE',
633
+ `${tool.name}.${key} must be at most ${declared.maxLength} Unicode code points, but it is ${points}`);
634
+ }
635
+ } else if (typeof declared.maxLength === 'number' && field.length > declared.maxLength) {
636
+ throw new McpError('MCP_ARGUMENT_RANGE', `${tool.name}.${key} must be at most ${declared.maxLength} characters`);
637
+ }
482
638
  out[key] = field;
483
639
  } else if (declared.type === 'boolean') {
484
640
  // Strict: a model that sends the string "true" gets a refusal naming the
@@ -508,6 +664,9 @@ function validateArgs(tool, args) {
508
664
  throw new McpError('MCP_ARGUMENT_ENUM', `${tool.name}.${key} must be one of ${declared.enum.join(', ')}`);
509
665
  }
510
666
  }
667
+ if (tool.name === 'delegate_result' && out.reviewNoteLimit !== undefined && out.reviewNoteOffset === undefined) {
668
+ throw new McpError('MCP_ARGUMENT_REQUIRED', 'delegate_result.reviewNoteLimit requires reviewNoteOffset');
669
+ }
511
670
  return out;
512
671
  }
513
672
 
@@ -794,6 +953,13 @@ function projectWithStage(value, stage, collect) {
794
953
  if (typeof target.reviewRouteError === 'string') {
795
954
  target.reviewRouteError = boundedText(target.reviewRouteError, stage.skeletonChars ?? 400, `${prefix}reviewRouteError`, collect);
796
955
  }
956
+ // A full result KEEPS the whole note while it fits; when a stage has to give it up it
957
+ // is marked `noteOmitted` and read back in pages, never shortened. (`prefix` already
958
+ // ends in a dot.)
959
+ const acceptance = target.hostAcceptance;
960
+ if (acceptance !== null && typeof acceptance === 'object') {
961
+ target.hostAcceptance = boundAcceptance(acceptance, `${prefix}hostAcceptance`, collect, stage.omitNote === true);
962
+ }
797
963
  // The settled decision trail is HISTORY; the pending request is the thing the
798
964
  // commander must act on NOW. Under a bound the history goes first, so a running
799
965
  // task can never keep an outstanding request invisible behind old evidence.
@@ -827,12 +993,20 @@ function projectWithStage(value, stage, collect) {
827
993
  // exception is `permission`: a wait answer publishes the pending operation there,
828
994
  // and a generic per-string cut would shorten the operation WITHOUT updating
829
995
  // `argumentsComplete`/`allowBlocked`, publishing a shortened operation that still
830
- // reads as complete. It is bounded by the permission rule instead.
996
+ // reads as complete. It is bounded by the permission rule instead. A top-level
997
+ // `hostAcceptance` (the review answer) is the recorded conclusion and is bounded by
998
+ // its own rule, so a small per-string cap cannot shorten it.
831
999
  for (const [key, item] of Object.entries(projected)) {
832
1000
  if (key === 'task' || key === 'tasks' || key === 'ok') continue;
833
- projected[key] = key === 'permission'
834
- ? boundPermissionBlock(item, key, collect)
835
- : trimAllStrings(item, key, cap, collect);
1001
+ if (key === 'permission') {
1002
+ projected[key] = boundPermissionBlock(item, key, collect);
1003
+ continue;
1004
+ }
1005
+ if (key === 'hostAcceptance' && item !== null && typeof item === 'object' && !Array.isArray(item)) {
1006
+ projected[key] = boundAcceptance(item, key, collect);
1007
+ continue;
1008
+ }
1009
+ projected[key] = trimAllStrings(item, key, cap, collect);
836
1010
  }
837
1011
  }
838
1012
  return projected;
@@ -862,6 +1036,12 @@ function skeletonize(task, path, cap, collect) {
862
1036
  }
863
1037
  } else if (key === 'route' || key === 'reviewRoute') {
864
1038
  out[key] = value === null ? null : boundValue(value, `${path}.${key}`, cap, collect);
1039
+ } else if (key === 'hostAcceptance') {
1040
+ // The recorded CONCLUSION is restored to its own bound after the generic walk, so a
1041
+ // small per-string cap can never shorten what the host concluded while leaving a
1042
+ // record that still reads as the whole note. A note beyond the accepted bound is
1043
+ // cut once, and the cut is stated.
1044
+ out[key] = value === null ? null : boundAcceptance(value, `${path}.hostAcceptance`, collect);
865
1045
  } else {
866
1046
  out[key] = value;
867
1047
  }
@@ -879,6 +1059,62 @@ function skeletonize(task, path, cap, collect) {
879
1059
  return out;
880
1060
  }
881
1061
 
1062
+ /**
1063
+ * Bound a recorded host review for a skeletonised answer.
1064
+ *
1065
+ * The conclusion fields are carried as the engine states them — `accepted`, `state`,
1066
+ * `acceptedAt`, `by` — because they are the answer to "was this accepted?", and the note
1067
+ * keeps its own generous cap rather than the skeleton's per-string one. Anything else
1068
+ * present is bounded generically, so a widened record cannot smuggle a long value in
1069
+ * through this exception.
1070
+ * @param {object} acceptance - host-acceptance record.
1071
+ * @param {string} path - JSON path.
1072
+ * @param {object[]} collect - truncation records.
1073
+ * @returns {object} bounded record.
1074
+ */
1075
+ function boundAcceptance(acceptance, path, collect, omitNoteText = false) {
1076
+ if (omitNoteText) return omitNote(acceptance, `${path}.note`, collect);
1077
+ const out = {};
1078
+ for (const [key, value] of Object.entries(acceptance)) {
1079
+ if (key === 'note' && typeof value === 'string') {
1080
+ out[key] = value;
1081
+ continue;
1082
+ }
1083
+ if (['accepted', 'state', 'acceptedAt', 'by', 'noteChars', 'noteOmitted'].includes(key)) {
1084
+ out[key] = value;
1085
+ continue;
1086
+ }
1087
+ out[key] = boundValue(value, `${path}.${key}`, 240, collect);
1088
+ }
1089
+ return out;
1090
+ }
1091
+
1092
+ /**
1093
+ * Mark a review note the projection had to drop, instead of publishing a shortened body.
1094
+ *
1095
+ * The body is never silently cut: `noteOmitted: true` plus `noteChars` says the note is
1096
+ * still there, and `reviewNoteOffset`/`reviewNoteLimit` read it in full.
1097
+ * @param {object} acceptance - host-acceptance record (mutated copy).
1098
+ * @param {string} path - JSON path of the note.
1099
+ * @param {object[]} collect - truncation records.
1100
+ * @returns {object} the acceptance with an explicitly omitted note.
1101
+ */
1102
+ function omitNote(acceptance, path, collect) {
1103
+ const length = typeof acceptance.note === 'string' ? Array.from(acceptance.note).length : 0;
1104
+ if (acceptance.note !== undefined && acceptance.note !== null) {
1105
+ collect.push({
1106
+ path,
1107
+ field: 'text',
1108
+ keptChars: 0,
1109
+ omittedChars: length,
1110
+ detail: 'the review note is read with delegate_result reviewNoteOffset/reviewNoteLimit',
1111
+ });
1112
+ }
1113
+ const { note, ...rest } = acceptance;
1114
+ void note;
1115
+ return { ...rest, noteChars: acceptance.noteChars ?? length, noteOmitted: true };
1116
+ }
1117
+
882
1118
  /**
883
1119
  * The live pending permission request of one task, bounded but never skeletal.
884
1120
  *
@@ -1057,7 +1293,8 @@ function boundValue(value, path, cap, collect) {
1057
1293
  if (key === 'permission' && item !== null && typeof item === 'object' && !Array.isArray(item)) {
1058
1294
  out[key] = boundPermissionBlock(item, `${path}.permission`, collect);
1059
1295
  continue;
1060
- } out[key] = boundValue(item, `${path}.${key}`, cap, collect);
1296
+ }
1297
+ out[key] = boundValue(item, `${path}.${key}`, cap, collect);
1061
1298
  }
1062
1299
  return out;
1063
1300
  }
@@ -1133,6 +1370,10 @@ function boundedJson(value) {
1133
1370
  { executionText: 400, reviewText: 400, lists: 20, permissionEvidence: 4 },
1134
1371
  { executionText: 200, reviewText: 200, lists: 5, permissionEvidence: 2 },
1135
1372
  { executionText: 120, reviewText: 120, lists: 1, permissionEvidence: 1 },
1373
+ // Before the answer is skeletonised (whose small per-string cap would otherwise CUT the
1374
+ // note), the note is given up explicitly: identity, state and everything else stay at
1375
+ // full width, and only the body becomes `noteOmitted`, readable in pages.
1376
+ { executionText: 120, reviewText: 120, lists: 1, permissionEvidence: 1, omitNote: true },
1136
1377
  { executionText: 80, reviewText: 80, lists: 1, permissionEvidence: 0, skeletonChars: 240 },
1137
1378
  { executionText: 40, reviewText: 40, lists: 1, permissionEvidence: 0, skeletonChars: 96 },
1138
1379
  ];
@@ -1450,7 +1691,10 @@ export function createMcpServer(options) {
1450
1691
  const result = name === 'delegate_wait'
1451
1692
  ? await waitAnswer(payload, context)
1452
1693
  : await callExecution(route, payload);
1453
- const bounded = boundedJson(result);
1694
+ // A paged read of the review note returns only its slice: it is a different, small
1695
+ // ANSWER shape, not a projection of the big one.
1696
+ const page = name === 'delegate_result' ? reviewNotePage(payload, result) : null;
1697
+ const bounded = boundedJson(page ?? result);
1454
1698
  // A structurally trimmed answer is a real answer, so `isError` stays unset;
1455
1699
  // only an answer that could not be delivered at all is reported as an error.
1456
1700
  return bounded.isError
@@ -1554,16 +1798,42 @@ export function createMcpServer(options) {
1554
1798
  + 'task stays `running` with phase `awaiting-permission`. Answer exactly one such request with '
1555
1799
  + 'delegate_permission_decide (`allow-once` or `reject`). That decision covers only that call, is '
1556
1800
  + 'never a standing grant, and cannot approve anything else. To follow a task without polling, use '
1557
- + 'delegate_wait: one call blocks until the task needs you (permission, ready, failed, cancelled, '
1558
- + 'interrupted) or until its deadline, in which case it answers reason "wait-limit" and you call '
1559
- + 'it again with the same taskId instead of reviewing or resubmitting anything. '
1801
+ + 'delegate_wait({ taskId }): one call blocks until the task needs you (permission, ready, failed, '
1802
+ + 'cancelled, interrupted) or until its own one-hour deadline, in which case it answers reason '
1803
+ + '`wait-limit` with `actionable: false` and you call it again with the same taskId instead of '
1804
+ + 'reviewing or resubmitting anything. Omit waitSeconds for normal waiting: the default already '
1805
+ + 'covers an hour, it cannot be raised above 3600, and a shorter value is only for a one-off '
1806
+ + 'diagnostic you were explicitly asked for. The approximately 25-second observation cadence '
1807
+ + 'inside delegate_wait is internal to this program, not a polling rate: while nothing has '
1808
+ + 'changed, do not read intermediate code or diff, do not research or implement in parallel, and '
1809
+ + 'do not narrate unchanged snapshots — wait, and review once on delivery. A wait ending, or your '
1810
+ + 'own client tool timeout firing, does not prove the execution stopped or that it is alive: keep '
1811
+ + 'the taskId and check one compact fact if you need to, and never duplicate, restart or cancel a '
1812
+ + 'task merely because a wait or a client timeout ended. '
1560
1813
  + '`interrupted` never means the execution stopped by itself: this call returns it at once '
1561
1814
  + 'with `terminal: false` while the task is still pending or running (wait again on the same '
1562
1815
  + 'taskId); only a task record that is itself interrupted (a restart history) is `terminal: true`. '
1816
+ + 'A host that hands the wait back on its own tool/exec time limit is reporting an OUTER limit, '
1817
+ + 'not a result: the MCP observation did not end and the worker did not stop. Continue the SAME '
1818
+ + 'exec cell on the taskId you hold, ask for the longest yield the host supports (roughly 1200000 '
1819
+ + 'ms when a yield/pragmas parameter exists, not a minute) rather than re-issuing every second, and '
1820
+ + 'do not open a second wait, read delegate_result or submit a duplicate. A one-minute return is a '
1821
+ + 'caller choice, not a documented hard limit, and not every client offers the same yield. This '
1822
+ + 'plugin cannot create a background waiter or wake the agent, so a client with only a short yield '
1823
+ + 'and no automatic continuation costs one resumed turn per yield window — state that plainly '
1824
+ + 'instead of inventing a wake-up. An `attention` answer that carries a `failure` '
1825
+ + 'block means the worker repeated the same failed operation several times while still running: '
1826
+ + 'it is a question for the host, sent once, and nothing is cancelled or reconfigured for it. '
1563
1827
  + 'If a host serialises tool calls so that this '
1564
1828
  + 'connection is blocked by a long wait, the independently installed `dsh-delegate-control` '
1565
1829
  + 'binary can report or cancel one task from a separate process; it cannot submit, configure or '
1566
- + 'change the switch.',
1830
+ + 'change the switch. '
1831
+ + 'When a task reaches `ready`/`awaiting-host-review`, finish YOUR review and record it with '
1832
+ + 'delegate_review ({ taskId, decision: "accepted" | "changes-requested", note }): that call is the '
1833
+ + 'only thing that records host acceptance, and until it is made the task stays unreviewed. '
1834
+ + 'Completion is never acceptance on its own, and a review cannot approve permissions, change '
1835
+ + 'settings or models, merge the diff or create work. The first decision is final for that task; '
1836
+ + 'to request a correction, send a follow-up with `continueFromTaskId`.',
1567
1837
  });
1568
1838
  }
1569
1839
  case 'notifications/initialized':
@@ -1819,3 +2089,57 @@ export async function serveStdio(options) {
1819
2089
  await writeChain;
1820
2090
  return { inflight: inputEnded, closed, drained: pending.size === 0 };
1821
2091
  }
2092
+
2093
+ // ---------------------------------------------------------------------------
2094
+ // Paged review-note reads (R5)
2095
+ // ---------------------------------------------------------------------------
2096
+ //
2097
+ // A review note may be up to 8000 code points, and the same note appears twice in a full
2098
+ // result (`hostAcceptance` and inside the task), which can exceed the tool-text bound. The
2099
+ // full result therefore states `noteOmitted` when it had to give the body up, and this
2100
+ // reader returns the body a page at a time: every page carries its own total, so a caller
2101
+ // can reassemble the EXACT text and can tell a complete read from a partial one.
2102
+
2103
+ /**
2104
+ * Build the page answer for one `reviewNoteOffset` read, or null for a normal result.
2105
+ * @param {object} payload - validated `delegate_result` arguments.
2106
+ * @param {object} result - the plane's answer.
2107
+ * @returns {object | null} the page answer, or null when this is not a paged read.
2108
+ */
2109
+ function reviewNotePage(payload, result) {
2110
+ if (payload?.reviewNoteOffset === undefined) return null;
2111
+ const task = result?.task !== null && typeof result?.task === 'object' ? result.task : null;
2112
+ const acceptance = task?.hostAcceptance ?? result?.hostAcceptance ?? null;
2113
+ const note = typeof acceptance?.note === 'string' ? acceptance.note : '';
2114
+ const points = Array.from(note);
2115
+ const offset = Math.min(payload.reviewNoteOffset, points.length);
2116
+ const limit = payload.reviewNoteLimit ?? DEFAULT_REVIEW_NOTE_PAGE_CHARS;
2117
+ const slice = points.slice(offset, offset + limit).join('');
2118
+ const next = offset + (offset + limit < points.length ? limit : points.length - offset);
2119
+ return {
2120
+ ok: true,
2121
+ taskId: task?.taskId ?? payload.taskId,
2122
+ state: task?.state ?? null,
2123
+ reviewNote: {
2124
+ offset,
2125
+ limit,
2126
+ text: slice,
2127
+ noteChars: points.length,
2128
+ nextOffset: next < points.length ? next : null,
2129
+ complete: next >= points.length,
2130
+ // Stated so a paged read is never confused with "the task has no analysis".
2131
+ present: note !== '',
2132
+ },
2133
+ hostAcceptance: acceptance === null
2134
+ ? null
2135
+ : {
2136
+ accepted: acceptance.accepted === true,
2137
+ state: acceptance.state ?? null,
2138
+ acceptedAt: acceptance.acceptedAt ?? null,
2139
+ by: acceptance.by ?? null,
2140
+ noteChars: points.length,
2141
+ noteOmitted: true,
2142
+ },
2143
+ reviewPersistence: task?.reviewPersistence ?? null,
2144
+ };
2145
+ }