dsh-taskbridge 1.4.0 → 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/CHANGELOG.md +13 -2
- package/README.md +8 -6
- package/codex/dsh-taskbridge.toml +19 -6
- package/docs/INTRODUCTION.md +19 -17
- package/docs/INTRODUCTION.zh.md +38 -36
- package/docs/codex-integration.md +14 -2
- package/docs/plugin-market.md +1 -1
- package/docs/releases/1.4.1.zh.md +59 -0
- package/docs/runtime-compatibility.md +11 -5
- package/docs/silent-wait.md +14 -0
- package/docs/taskbridge-upgrade.md +1 -1
- package/lib/client.js +159 -21
- package/package.json +144 -143
- package/src/client/api.js +124 -3
- package/src/client/index.jsx +144 -25
- package/src/codex/installer.js +8 -0
- package/src/http/execution-plane.js +133 -17
- package/src/http/user-plane.js +5 -4
- package/src/index.d.ts +59 -5
- package/src/index.js +1 -1
- package/src/jobs/engine.js +849 -117
- package/src/jobs/history.js +124 -6
- package/src/jobs/review-note.js +63 -0
- package/src/mcp/server.js +213 -15
- package/src/mcp/wait.js +18 -0
package/src/jobs/history.js
CHANGED
|
@@ -25,6 +25,7 @@ import * as nodeFs from 'node:fs/promises';
|
|
|
25
25
|
import { dirname, join } from 'node:path';
|
|
26
26
|
|
|
27
27
|
import { redactDeep } from '../config/redact.js';
|
|
28
|
+
import { REVIEW_NOTE_MAX_CHARS, truncateCodePoints } from './review-note.js';
|
|
28
29
|
|
|
29
30
|
/** Persisted document format version. Unknown versions are refused, never migrated. */
|
|
30
31
|
const SCHEMA_VERSION = 1;
|
|
@@ -230,7 +231,7 @@ export class HistoryStore {
|
|
|
230
231
|
async save(view) {
|
|
231
232
|
if (this.disposed) throw this.disposedError();
|
|
232
233
|
if (this.refusal !== null) this.throwIfRefused();
|
|
233
|
-
|
|
234
|
+
let entry = projectView(view, this.maxEntryBytes, { rejectOversizeNote: true });
|
|
234
235
|
const run = this.enqueue(async () => {
|
|
235
236
|
this.throwIfRefused();
|
|
236
237
|
const base = await this.ensureLoaded();
|
|
@@ -243,6 +244,18 @@ export class HistoryStore {
|
|
|
243
244
|
// race must not resurrect a finished task as `running`, so the terminal record
|
|
244
245
|
// wins and the stale checkpoint is discarded instead of stored.
|
|
245
246
|
if (isTerminal(draft[index].state) && !isTerminal(entry.state)) return structuredClone(draft[index]);
|
|
247
|
+
// Inspect the current row INSIDE the write queue. A terminal snapshot can
|
|
248
|
+
// have been captured before a review, then queued behind its slow write.
|
|
249
|
+
const recorded = draft[index].hostAcceptance;
|
|
250
|
+
if (recorded !== null && recorded !== undefined) {
|
|
251
|
+
if (entry.hostAcceptance !== null && entry.hostAcceptance !== undefined
|
|
252
|
+
&& (entry.hostAcceptance.state !== recorded.state || entry.hostAcceptance.note !== recorded.note)) {
|
|
253
|
+
throw new HistoryError(HISTORY_CODES.viewInvalid, 'a saved review cannot be replaced by a task snapshot', {
|
|
254
|
+
taskId: entry.taskId,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
entry = projectView({ ...entry, hostAcceptance: recorded }, this.maxEntryBytes, { rejectOversizeNote: true });
|
|
258
|
+
}
|
|
246
259
|
draft[index] = entry;
|
|
247
260
|
} else {
|
|
248
261
|
draft.push(entry);
|
|
@@ -257,6 +270,48 @@ export class HistoryStore {
|
|
|
257
270
|
return await run;
|
|
258
271
|
}
|
|
259
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Atomically patch ONE stored record through a caller-supplied mutation.
|
|
275
|
+
*
|
|
276
|
+
* The stored row is the base, so a patch can add a conclusion without discarding the
|
|
277
|
+
* execution evidence already on disk, and it runs on the same write queue as `save` so
|
|
278
|
+
* two writes can never interleave. The mutation receives a detached copy of the CURRENT
|
|
279
|
+
* row (re-read under the write) and returns the row to store; throwing refuses with the
|
|
280
|
+
* caller's error and nothing is written.
|
|
281
|
+
* @param {string} taskId - stored task id.
|
|
282
|
+
* @param {(row: object) => object} mutate - mutation of the current stored row.
|
|
283
|
+
* @returns {Promise<object>} detached copy of the stored entry.
|
|
284
|
+
* @throws {HistoryError} `HISTORY_VIEW_INVALID` when this task has no stored row.
|
|
285
|
+
*/
|
|
286
|
+
async update(taskId, mutate) {
|
|
287
|
+
if (this.disposed) throw this.disposedError();
|
|
288
|
+
if (this.refusal !== null) this.throwIfRefused();
|
|
289
|
+
if (typeof taskId !== 'string' || taskId.trim() === '') {
|
|
290
|
+
throw new HistoryError(HISTORY_CODES.viewInvalid, 'a job history update needs a taskId', {});
|
|
291
|
+
}
|
|
292
|
+
const run = this.enqueue(async () => {
|
|
293
|
+
this.throwIfRefused();
|
|
294
|
+
const base = await this.ensureLoaded();
|
|
295
|
+
const index = base.findIndex((job) => job.taskId === taskId);
|
|
296
|
+
if (index < 0) {
|
|
297
|
+
throw new HistoryError(HISTORY_CODES.viewInvalid, 'no stored record exists for this task', { taskId });
|
|
298
|
+
}
|
|
299
|
+
const entry = projectView(await mutate(structuredClone(base[index])), this.maxEntryBytes, { rejectOversizeNote: true });
|
|
300
|
+
if (entry.taskId !== taskId) {
|
|
301
|
+
throw new HistoryError(HISTORY_CODES.viewInvalid, 'a history update may not change the task it patches', { taskId });
|
|
302
|
+
}
|
|
303
|
+
const draft = base.map((job) => structuredClone(job));
|
|
304
|
+
draft[index] = entry;
|
|
305
|
+
draft.sort(compareStored);
|
|
306
|
+
const now = Date.now();
|
|
307
|
+
this.enforceLimits(draft, entry.taskId, now);
|
|
308
|
+
await this.writeDocument(draft, now);
|
|
309
|
+
this.jobs = draft;
|
|
310
|
+
return structuredClone(entry);
|
|
311
|
+
});
|
|
312
|
+
return await run;
|
|
313
|
+
}
|
|
314
|
+
|
|
260
315
|
/**
|
|
261
316
|
* Wait for the in-flight read and every queued write to settle.
|
|
262
317
|
* @returns {Promise<void>} resolves when the document is consistent.
|
|
@@ -489,9 +544,12 @@ export class HistoryStore {
|
|
|
489
544
|
* field, a credential or a native handle by widening its own object.
|
|
490
545
|
* @param {object} view - public job view.
|
|
491
546
|
* @param {number} maxEntryBytes - per-entry byte budget.
|
|
547
|
+
* @param {{ rejectOversizeNote?: boolean }} [options] - `rejectOversizeNote` refuses an
|
|
548
|
+
* oversized review note instead of cutting it (writes); a load keeps the cut.
|
|
492
549
|
* @returns {object} bounded, redacted entry.
|
|
550
|
+
* @throws {HistoryError} when the view, or the note under `rejectOversizeNote`, is invalid.
|
|
493
551
|
*/
|
|
494
|
-
function projectView(view, maxEntryBytes) {
|
|
552
|
+
function projectView(view, maxEntryBytes, options = {}) {
|
|
495
553
|
if (!isPlainObject(view)) {
|
|
496
554
|
throw new HistoryError(HISTORY_CODES.viewInvalid, 'a job history view must be an object', {});
|
|
497
555
|
}
|
|
@@ -504,6 +562,7 @@ function projectView(view, maxEntryBytes) {
|
|
|
504
562
|
}
|
|
505
563
|
|
|
506
564
|
const ctx = newCutContext(view.truncation, maxEntryBytes);
|
|
565
|
+
const acceptance = acceptanceView(view.hostAcceptance, ctx, { rejectOversize: options.rejectOversizeNote === true });
|
|
507
566
|
const entry = {
|
|
508
567
|
taskId,
|
|
509
568
|
state: view.state,
|
|
@@ -545,7 +604,7 @@ function projectView(view, maxEntryBytes) {
|
|
|
545
604
|
activity: activityView(view.activity),
|
|
546
605
|
error: errorView(view.error, ctx),
|
|
547
606
|
cancelledBy: label(view.cancelledBy),
|
|
548
|
-
hostAcceptance:
|
|
607
|
+
hostAcceptance: acceptance,
|
|
549
608
|
// A completed job is not an accepted one. This is fixed, never copied.
|
|
550
609
|
selfApproved: false,
|
|
551
610
|
};
|
|
@@ -1103,18 +1162,70 @@ function errorView(value, ctx) {
|
|
|
1103
1162
|
};
|
|
1104
1163
|
}
|
|
1105
1164
|
|
|
1106
|
-
/**
|
|
1107
|
-
|
|
1165
|
+
/**
|
|
1166
|
+
* Bounded host-acceptance record.
|
|
1167
|
+
*
|
|
1168
|
+
* A recorded conclusion is free prose, so `label()` (256 characters) is the wrong rule for
|
|
1169
|
+
* its note: that silently dropped most of a longer conclusion. A note within the shared
|
|
1170
|
+
* code-point bound is kept exactly as written and REFUSED here when it is longer, so a
|
|
1171
|
+
* caller can never be told a shortened conclusion was saved; a document already carrying
|
|
1172
|
+
* more than the bound keeps read-compatible behaviour.
|
|
1173
|
+
* @param {unknown} value - host-acceptance value.
|
|
1174
|
+
* @param {object} ctx - cut context.
|
|
1175
|
+
* @param {{ rejectOversize?: boolean }} [options] - `rejectOversize` refuses instead of cutting.
|
|
1176
|
+
* @returns {object | null} bounded host-acceptance record.
|
|
1177
|
+
* @throws {HistoryError} `HISTORY_VIEW_INVALID` when the note exceeds the bound and
|
|
1178
|
+
* `rejectOversize` is set.
|
|
1179
|
+
*/
|
|
1180
|
+
function acceptanceView(value, ctx, options = {}) {
|
|
1108
1181
|
if (!isPlainObject(value)) return null;
|
|
1182
|
+
const note = options.rejectOversize === true ? requireNote(value.note) : noteText(value.note, ctx);
|
|
1109
1183
|
return {
|
|
1110
1184
|
accepted: value.accepted === true,
|
|
1111
1185
|
state: label(value.state),
|
|
1112
1186
|
acceptedAt: time(value.acceptedAt),
|
|
1113
1187
|
by: label(value.by),
|
|
1114
|
-
note
|
|
1188
|
+
note,
|
|
1189
|
+
noteChars: typeof value.note === 'string' ? Array.from(value.note).length : null,
|
|
1115
1190
|
};
|
|
1116
1191
|
}
|
|
1117
1192
|
|
|
1193
|
+
/**
|
|
1194
|
+
* Validate an incoming note against the shared bound, refusing rather than cutting.
|
|
1195
|
+
* @param {unknown} value - note.
|
|
1196
|
+
* @returns {string | null} the note as given, or null when there is none.
|
|
1197
|
+
* @throws {HistoryError} `HISTORY_VIEW_INVALID` with the actual length and the limit.
|
|
1198
|
+
*/
|
|
1199
|
+
function requireNote(value) {
|
|
1200
|
+
if (typeof value !== 'string' || value === '') return null;
|
|
1201
|
+
const length = Array.from(value).length;
|
|
1202
|
+
if (length > REVIEW_NOTE_MAX_CHARS) {
|
|
1203
|
+
throw new HistoryError(
|
|
1204
|
+
HISTORY_CODES.viewInvalid,
|
|
1205
|
+
`hostAcceptance.note must be at most ${REVIEW_NOTE_MAX_CHARS} Unicode code points, but it is ${length}`,
|
|
1206
|
+
{ field: 'hostAcceptance.note', limit: REVIEW_NOTE_MAX_CHARS, length, unit: 'unicode-code-points' },
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
return value;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Keep a stored review note as written, cutting only a value beyond the accepted bound and
|
|
1214
|
+
* stating that cut.
|
|
1215
|
+
* @param {unknown} value - note.
|
|
1216
|
+
* @param {object} ctx - cut context.
|
|
1217
|
+
* @returns {string | null} the note, or null when there is none.
|
|
1218
|
+
*/
|
|
1219
|
+
function noteText(value, ctx) {
|
|
1220
|
+
if (typeof value !== 'string' || value === '') return null;
|
|
1221
|
+
const bounded = truncateCodePoints(value, REVIEW_NOTE_MAX_CHARS);
|
|
1222
|
+
if (bounded !== value) {
|
|
1223
|
+
ctx.fields.add('hostAcceptance.note');
|
|
1224
|
+
return `${bounded}${TRUNCATION_MARK}`;
|
|
1225
|
+
}
|
|
1226
|
+
return value;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1118
1229
|
/**
|
|
1119
1230
|
* Bound an open-ended detail object by shape, not by name: depth, key count and
|
|
1120
1231
|
* string size. `redactDeep` still masks every secret-named key inside it.
|
|
@@ -1179,6 +1290,13 @@ function fitEntry(entry, ctx) {
|
|
|
1179
1290
|
|
|
1180
1291
|
/**
|
|
1181
1292
|
* Halve the longest remaining free-text field.
|
|
1293
|
+
*
|
|
1294
|
+
* The recorded host review is NOT in {@link TEXT_PATHS}: an accepted conclusion is the most
|
|
1295
|
+
* valuable prose in the entry, so a large diff or a long worker output is reduced first,
|
|
1296
|
+
* then the long arrays and optional blocks. If a legal note still does not fit beside all
|
|
1297
|
+
* of that, the save is REFUSED — a conclusion is never shortened and then reported saved.
|
|
1298
|
+
* Only a note past the accepted bound (another writer's document) is cut, by
|
|
1299
|
+
* {@link noteText}, with the cut stated.
|
|
1182
1300
|
* @param {object} entry - mutable entry.
|
|
1183
1301
|
* @param {object} ctx - cut context.
|
|
1184
1302
|
* @returns {boolean} whether anything was cut.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// The one bound and normalization for a host-review note.
|
|
2
|
+
//
|
|
3
|
+
// A review note is free prose: Chinese, line breaks and emoji are ordinary in it. That is
|
|
4
|
+
// why the bound is counted in Unicode code points — `Array.from(text).length` — rather than
|
|
5
|
+
// in UTF-16 units, where an emoji counts twice. The same rule applies at every entry point
|
|
6
|
+
// (MCP schema, HTTP route, engine, durable history projection), because a note one layer
|
|
7
|
+
// accepts and another cuts is worse than a refusal: the caller would be told "recorded"
|
|
8
|
+
// about text that was never recorded.
|
|
9
|
+
//
|
|
10
|
+
// This module has no imports on purpose: `src/mcp/server.js` is loaded by the standalone
|
|
11
|
+
// MCP binary, which must not pull the engine or any native DSH module in through a shared
|
|
12
|
+
// constant.
|
|
13
|
+
|
|
14
|
+
/** Longest review note, in Unicode code points. */
|
|
15
|
+
export const REVIEW_NOTE_MAX_CHARS = 8_000;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The normalization applied wherever a note is accepted or stored: surrounding whitespace
|
|
19
|
+
* only. The body of the note is preserved exactly.
|
|
20
|
+
* @param {unknown} value - candidate note.
|
|
21
|
+
* @returns {string} the trimmed note, or '' for a non-string.
|
|
22
|
+
*/
|
|
23
|
+
export function normalizeReviewNote(value) {
|
|
24
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} value - text to measure.
|
|
29
|
+
* @returns {number} length in Unicode code points (0 for a non-string).
|
|
30
|
+
*/
|
|
31
|
+
export function reviewNoteLength(value) {
|
|
32
|
+
return typeof value === 'string' ? Array.from(value).length : 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Refusal facts for an over-long note, so every surface reports the same numbers.
|
|
37
|
+
* @param {string} value - the rejected note.
|
|
38
|
+
* @returns {{ limit: number, length: number, message: string }} bound, actual length, message.
|
|
39
|
+
*/
|
|
40
|
+
export function reviewNoteOverflow(value) {
|
|
41
|
+
const length = reviewNoteLength(value);
|
|
42
|
+
return {
|
|
43
|
+
limit: REVIEW_NOTE_MAX_CHARS,
|
|
44
|
+
length,
|
|
45
|
+
message: `note must be at most ${REVIEW_NOTE_MAX_CHARS} Unicode code points, but it is ${length}`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Cut a string to a code-point bound.
|
|
51
|
+
*
|
|
52
|
+
* Only for a stored value that reached the document some other way (an older build, a
|
|
53
|
+
* hand-edited file). An accepted request is REFUSED when it is too long, never shortened.
|
|
54
|
+
* @param {unknown} value - candidate text.
|
|
55
|
+
* @param {number} [limit] - code points to keep.
|
|
56
|
+
* @returns {string | null} bounded text, or null when the value is not a non-empty string.
|
|
57
|
+
*/
|
|
58
|
+
export function truncateCodePoints(value, limit = REVIEW_NOTE_MAX_CHARS) {
|
|
59
|
+
if (typeof value !== 'string' || value === '') return null;
|
|
60
|
+
const points = Array.from(value);
|
|
61
|
+
if (points.length <= limit) return value;
|
|
62
|
+
return points.slice(0, limit).join('');
|
|
63
|
+
}
|
package/src/mcp/server.js
CHANGED
|
@@ -71,6 +71,13 @@
|
|
|
71
71
|
// made it fail at link time with `ERR_MODULE_NOT_FOUND` before it could report
|
|
72
72
|
// anything at all.
|
|
73
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';
|
|
74
81
|
import { waitForTask } from './wait.js';
|
|
75
82
|
|
|
76
83
|
/** Protocol revisions this server can speak, newest first (as the SDK lists them). */
|
|
@@ -85,11 +92,22 @@ export const SUPPORTED_PROTOCOL_VERSIONS = Object.freeze([
|
|
|
85
92
|
export const LATEST_PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[0];
|
|
86
93
|
|
|
87
94
|
/** Identifies this server in the handshake. */
|
|
88
|
-
export const SERVER_INFO = Object.freeze({ name: 'dsh-delegate', version: '1.4.
|
|
95
|
+
export const SERVER_INFO = Object.freeze({ name: 'dsh-delegate', version: '1.4.1' });
|
|
89
96
|
|
|
90
97
|
/** Bound on a tool result's text. A task view can be large; a model's context cannot. */
|
|
91
98
|
export const MAX_TOOL_TEXT_CHARS = 20_000;
|
|
92
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
|
+
|
|
93
111
|
/** Bound on one execution-plane request. */
|
|
94
112
|
export const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
|
|
95
113
|
|
|
@@ -112,12 +130,15 @@ export const MAX_WAIT_SECONDS = 3_600;
|
|
|
112
130
|
export const MIN_WAIT_SECONDS = 1;
|
|
113
131
|
|
|
114
132
|
/**
|
|
115
|
-
* Longest `delegate_review` note, in
|
|
133
|
+
* Longest `delegate_review` note, in Unicode code points.
|
|
116
134
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
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.
|
|
119
140
|
*/
|
|
120
|
-
export const MAX_REVIEW_NOTE_CHARS =
|
|
141
|
+
export const MAX_REVIEW_NOTE_CHARS = REVIEW_NOTE_MAX_CHARS;
|
|
121
142
|
|
|
122
143
|
/**
|
|
123
144
|
* How many requests may be in flight at once on the stdio transport.
|
|
@@ -276,7 +297,11 @@ export const TOOLS = Object.freeze([
|
|
|
276
297
|
title: 'Read task result',
|
|
277
298
|
description: 'Read one task this connection submitted: state, effective provider/model/effort, '
|
|
278
299
|
+ 'changed-file summary, bounded diff, validation evidence and review outcome. '
|
|
279
|
-
+ '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.',
|
|
280
305
|
// A read of a stored task: no work is created, changed or cancelled.
|
|
281
306
|
annotations: Object.freeze({
|
|
282
307
|
title: 'Read task result',
|
|
@@ -289,6 +314,20 @@ export const TOOLS = Object.freeze([
|
|
|
289
314
|
type: 'object',
|
|
290
315
|
properties: {
|
|
291
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
|
+
},
|
|
292
331
|
},
|
|
293
332
|
required: ['taskId'],
|
|
294
333
|
additionalProperties: false,
|
|
@@ -452,7 +491,9 @@ export const TOOLS = Object.freeze([
|
|
|
452
491
|
+ 'is the only thing that does. '
|
|
453
492
|
+ '\u0060decision: "accepted"\u0060 means you reviewed the evidence with \u0060delegate_result\u0060 and it is right; '
|
|
454
493
|
+ '\u0060decision: "changes-requested"\u0060 means it needs correction. Either way \u0060note\u0060 is required and '
|
|
455
|
-
+ 'bounded (at most
|
|
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. '
|
|
456
497
|
+ 'This cannot approve a permission request, change the switch, a provider, a model, the isolation or a '
|
|
457
498
|
+ 'credential, merge or apply the diff, or create another task. Execution completion is never accepted '
|
|
458
499
|
+ 'automatically: until this is called the task stays unreviewed. '
|
|
@@ -485,7 +526,11 @@ export const TOOLS = Object.freeze([
|
|
|
485
526
|
note: {
|
|
486
527
|
type: 'string',
|
|
487
528
|
maxLength: MAX_REVIEW_NOTE_CHARS,
|
|
488
|
-
|
|
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. '
|
|
489
534
|
+ 'It is evidence of your review, never a grant and never a place for credentials.',
|
|
490
535
|
},
|
|
491
536
|
},
|
|
@@ -576,7 +621,18 @@ function validateArgs(tool, args) {
|
|
|
576
621
|
if (typeof field !== 'string') throw new McpError('MCP_ARGUMENT_TYPE', `${tool.name}.${key} must be a string`);
|
|
577
622
|
// A declared bound is enforced, not merely advertised: a note over the limit is
|
|
578
623
|
// refused with the field named instead of reaching the plane and being cut there.
|
|
579
|
-
|
|
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) {
|
|
580
636
|
throw new McpError('MCP_ARGUMENT_RANGE', `${tool.name}.${key} must be at most ${declared.maxLength} characters`);
|
|
581
637
|
}
|
|
582
638
|
out[key] = field;
|
|
@@ -608,6 +664,9 @@ function validateArgs(tool, args) {
|
|
|
608
664
|
throw new McpError('MCP_ARGUMENT_ENUM', `${tool.name}.${key} must be one of ${declared.enum.join(', ')}`);
|
|
609
665
|
}
|
|
610
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
|
+
}
|
|
611
670
|
return out;
|
|
612
671
|
}
|
|
613
672
|
|
|
@@ -894,6 +953,13 @@ function projectWithStage(value, stage, collect) {
|
|
|
894
953
|
if (typeof target.reviewRouteError === 'string') {
|
|
895
954
|
target.reviewRouteError = boundedText(target.reviewRouteError, stage.skeletonChars ?? 400, `${prefix}reviewRouteError`, collect);
|
|
896
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
|
+
}
|
|
897
963
|
// The settled decision trail is HISTORY; the pending request is the thing the
|
|
898
964
|
// commander must act on NOW. Under a bound the history goes first, so a running
|
|
899
965
|
// task can never keep an outstanding request invisible behind old evidence.
|
|
@@ -927,12 +993,20 @@ function projectWithStage(value, stage, collect) {
|
|
|
927
993
|
// exception is `permission`: a wait answer publishes the pending operation there,
|
|
928
994
|
// and a generic per-string cut would shorten the operation WITHOUT updating
|
|
929
995
|
// `argumentsComplete`/`allowBlocked`, publishing a shortened operation that still
|
|
930
|
-
// 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.
|
|
931
999
|
for (const [key, item] of Object.entries(projected)) {
|
|
932
1000
|
if (key === 'task' || key === 'tasks' || key === 'ok') continue;
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
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);
|
|
936
1010
|
}
|
|
937
1011
|
}
|
|
938
1012
|
return projected;
|
|
@@ -962,6 +1036,12 @@ function skeletonize(task, path, cap, collect) {
|
|
|
962
1036
|
}
|
|
963
1037
|
} else if (key === 'route' || key === 'reviewRoute') {
|
|
964
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);
|
|
965
1045
|
} else {
|
|
966
1046
|
out[key] = value;
|
|
967
1047
|
}
|
|
@@ -979,6 +1059,62 @@ function skeletonize(task, path, cap, collect) {
|
|
|
979
1059
|
return out;
|
|
980
1060
|
}
|
|
981
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
|
+
|
|
982
1118
|
/**
|
|
983
1119
|
* The live pending permission request of one task, bounded but never skeletal.
|
|
984
1120
|
*
|
|
@@ -1157,7 +1293,8 @@ function boundValue(value, path, cap, collect) {
|
|
|
1157
1293
|
if (key === 'permission' && item !== null && typeof item === 'object' && !Array.isArray(item)) {
|
|
1158
1294
|
out[key] = boundPermissionBlock(item, `${path}.permission`, collect);
|
|
1159
1295
|
continue;
|
|
1160
|
-
}
|
|
1296
|
+
}
|
|
1297
|
+
out[key] = boundValue(item, `${path}.${key}`, cap, collect);
|
|
1161
1298
|
}
|
|
1162
1299
|
return out;
|
|
1163
1300
|
}
|
|
@@ -1233,6 +1370,10 @@ function boundedJson(value) {
|
|
|
1233
1370
|
{ executionText: 400, reviewText: 400, lists: 20, permissionEvidence: 4 },
|
|
1234
1371
|
{ executionText: 200, reviewText: 200, lists: 5, permissionEvidence: 2 },
|
|
1235
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 },
|
|
1236
1377
|
{ executionText: 80, reviewText: 80, lists: 1, permissionEvidence: 0, skeletonChars: 240 },
|
|
1237
1378
|
{ executionText: 40, reviewText: 40, lists: 1, permissionEvidence: 0, skeletonChars: 96 },
|
|
1238
1379
|
];
|
|
@@ -1550,7 +1691,10 @@ export function createMcpServer(options) {
|
|
|
1550
1691
|
const result = name === 'delegate_wait'
|
|
1551
1692
|
? await waitAnswer(payload, context)
|
|
1552
1693
|
: await callExecution(route, payload);
|
|
1553
|
-
|
|
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);
|
|
1554
1698
|
// A structurally trimmed answer is a real answer, so `isError` stays unset;
|
|
1555
1699
|
// only an answer that could not be delivered at all is reported as an error.
|
|
1556
1700
|
return bounded.isError
|
|
@@ -1945,3 +2089,57 @@ export async function serveStdio(options) {
|
|
|
1945
2089
|
await writeChain;
|
|
1946
2090
|
return { inflight: inputEnded, closed, drained: pending.size === 0 };
|
|
1947
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
|
+
}
|
package/src/mcp/wait.js
CHANGED
|
@@ -164,6 +164,24 @@ export function compactTask(task) {
|
|
|
164
164
|
for (const key of TASK_FIELDS) {
|
|
165
165
|
if (task[key] !== undefined) out[key] = task[key];
|
|
166
166
|
}
|
|
167
|
+
// A wait NEVER carries the review note body: the conclusion's state, time and length are
|
|
168
|
+
// what a host needs to act, and the body is read on demand through `delegate_result`.
|
|
169
|
+
// The object is kept (with `noteOmitted`) so an old client cannot read "no note" as
|
|
170
|
+
// "not reviewed", and `reviewPersistence` states whether the conclusion is durable yet.
|
|
171
|
+
const acceptance = out.hostAcceptance;
|
|
172
|
+
if (acceptance !== null && typeof acceptance === 'object' && !Array.isArray(acceptance)) {
|
|
173
|
+
out.hostAcceptance = {
|
|
174
|
+
accepted: acceptance.accepted === true,
|
|
175
|
+
state: acceptance.state ?? null,
|
|
176
|
+
acceptedAt: acceptance.acceptedAt ?? null,
|
|
177
|
+
by: acceptance.by ?? null,
|
|
178
|
+
// Counted from the body when it is here, so the summary states the REAL length even
|
|
179
|
+
// on a view that carries the full note.
|
|
180
|
+
noteChars: acceptance.noteChars ?? (typeof acceptance.note === 'string' ? Array.from(acceptance.note).length : 0),
|
|
181
|
+
noteOmitted: true,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (task.reviewPersistence !== undefined) out.reviewPersistence = task.reviewPersistence;
|
|
167
185
|
// Activity and self-check are small, bounded summaries the engine produced for
|
|
168
186
|
// exactly this purpose; they are carried whole rather than re-projected here.
|
|
169
187
|
if (task.activity !== undefined) out.activity = task.activity;
|