dsh-taskbridge 1.5.3 → 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.
- package/CHANGELOG.md +8 -0
- package/README.md +8 -7
- package/codex/dsh-taskbridge.toml +35 -38
- package/docs/INTRODUCTION.md +2 -1
- package/docs/INTRODUCTION.zh.md +2 -1
- package/docs/codex-integration.md +8 -2
- package/docs/plugin-market.md +1 -1
- package/docs/releases/1.5.4.zh.md +25 -0
- package/docs/runtime-compatibility.md +1 -1
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +1 -1
- package/package.json +2 -1
- package/src/codex/installer.js +3 -0
- package/src/http/execution-plane.js +34 -2
- package/src/index.d.ts +62 -5
- package/src/jobs/engine.js +96 -17
- package/src/jobs/history.js +166 -14
- package/src/jobs/task-descriptions.js +82 -0
- package/src/mcp/server.js +321 -41
- package/src/mcp/wait.js +7 -2
|
@@ -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
|
*
|
|
@@ -347,6 +360,20 @@ export const TOOLS = Object.freeze([
|
|
|
347
360
|
+ 'isolation override either. An unknown, still-running, removed or differently-sourced parent is '
|
|
348
361
|
+ 'refused, never replaced by a new conversation.',
|
|
349
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
|
+
},
|
|
350
377
|
},
|
|
351
378
|
required: ['workspacePath', 'prompt'],
|
|
352
379
|
additionalProperties: false,
|
|
@@ -358,10 +385,10 @@ export const TOOLS = Object.freeze([
|
|
|
358
385
|
description: 'Read one task this connection submitted: state, effective provider/model/effort, '
|
|
359
386
|
+ 'changed-file summary, bounded diff, validation evidence and review outcome. '
|
|
360
387
|
+ 'A finished execution is not host acceptance. '
|
|
361
|
-
+ 'The review note
|
|
362
|
-
+ '`hostAcceptance.noteOmitted: true`
|
|
363
|
-
+ '`reviewNoteLimit`
|
|
364
|
-
+ '
|
|
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.',
|
|
365
392
|
// A read of a stored task: no work is created, changed or cancelled.
|
|
366
393
|
annotations: Object.freeze({
|
|
367
394
|
title: 'Read task result',
|
|
@@ -388,6 +415,19 @@ export const TOOLS = Object.freeze([
|
|
|
388
415
|
description: `Code points of the review note to return per page (1..${MAX_REVIEW_NOTE_PAGE_CHARS}, `
|
|
389
416
|
+ 'default 2000). Only meaningful together with reviewNoteOffset.',
|
|
390
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
|
+
},
|
|
391
431
|
},
|
|
392
432
|
required: ['taskId'],
|
|
393
433
|
additionalProperties: false,
|
|
@@ -726,6 +766,22 @@ export const TOOLS = Object.freeze([
|
|
|
726
766
|
+ 'note is refused with its actual length instead of being cut. '
|
|
727
767
|
+ 'It is evidence of your review, never a grant and never a place for credentials.',
|
|
728
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
|
+
},
|
|
729
785
|
},
|
|
730
786
|
required: ['taskId', 'decision', 'note'],
|
|
731
787
|
additionalProperties: false,
|
|
@@ -826,6 +882,16 @@ const TOOL_ROUTES = Object.freeze({
|
|
|
826
882
|
delegate_metrics: null,
|
|
827
883
|
});
|
|
828
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
|
+
|
|
829
895
|
/**
|
|
830
896
|
* The one argument this surface adds to a request it forwards.
|
|
831
897
|
*
|
|
@@ -985,7 +1051,10 @@ function validateArgs(tool, args) {
|
|
|
985
1051
|
if (typeof declared.minLength === 'number' && field.length < declared.minLength) {
|
|
986
1052
|
throw new McpError('MCP_ARGUMENT_REQUIRED', `${tool.name}.${key} must not be empty`);
|
|
987
1053
|
}
|
|
988
|
-
|
|
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;
|
|
989
1058
|
} else if (declared.type === 'boolean') {
|
|
990
1059
|
// Strict: a model that sends the string "true" gets a refusal naming the
|
|
991
1060
|
// field instead of a silently truthy value reaching the plane.
|
|
@@ -1021,8 +1090,16 @@ function validateArgs(tool, args) {
|
|
|
1021
1090
|
throw new McpError('MCP_ARGUMENT_ENUM', `${tool.name}.${key} must be one of ${declared.enum.join(', ')}`);
|
|
1022
1091
|
}
|
|
1023
1092
|
}
|
|
1024
|
-
if (tool.name === 'delegate_result'
|
|
1025
|
-
|
|
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
|
+
}
|
|
1026
1103
|
}
|
|
1027
1104
|
return out;
|
|
1028
1105
|
}
|
|
@@ -1193,11 +1270,29 @@ function trimAllStrings(value, path, cap, collect, depth = 0) {
|
|
|
1193
1270
|
const out = {};
|
|
1194
1271
|
for (const [key, item] of Object.entries(value)) {
|
|
1195
1272
|
const childPath = path === '' ? key : `${path}.${key}`;
|
|
1273
|
+
if (isDescriptionField(key, item, path)) {
|
|
1274
|
+
out[key] = item;
|
|
1275
|
+
continue;
|
|
1276
|
+
}
|
|
1196
1277
|
out[key] = trimAllStrings(item, childPath, cap, collect, depth + 1);
|
|
1197
1278
|
}
|
|
1198
1279
|
return out;
|
|
1199
1280
|
}
|
|
1200
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
|
+
|
|
1201
1296
|
/**
|
|
1202
1297
|
* Replace one heavy field with a bounded summary that keeps its shape.
|
|
1203
1298
|
* @param {unknown} source - field value.
|
|
@@ -1429,10 +1524,14 @@ function projectWithStage(value, stage, collect) {
|
|
|
1429
1524
|
}
|
|
1430
1525
|
// A full result KEEPS the whole note while it fits; when a stage has to give it up it
|
|
1431
1526
|
// is marked `noteOmitted` and read back in pages, never shortened. (`prefix` already
|
|
1432
|
-
// ends in a dot.)
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
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
|
+
}
|
|
1436
1535
|
}
|
|
1437
1536
|
// The settled decision trail is HISTORY; the pending request is the thing the
|
|
1438
1537
|
// commander must act on NOW. Under a bound the history goes first, so a running
|
|
@@ -1452,15 +1551,21 @@ function projectWithStage(value, stage, collect) {
|
|
|
1452
1551
|
}
|
|
1453
1552
|
}
|
|
1454
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
|
+
}
|
|
1455
1560
|
if (Array.isArray(projected.tasks) && projected.tasks.length > stage.lists) {
|
|
1456
1561
|
collect.push(truncationRecord('tasks', { total: projected.tasks.length, omitted: projected.tasks.length - stage.lists }));
|
|
1457
1562
|
projected.tasks = projected.tasks.slice(0, stage.lists);
|
|
1458
1563
|
}
|
|
1459
1564
|
if (stage.skeletonChars !== undefined) {
|
|
1460
1565
|
const cap = stage.skeletonChars;
|
|
1461
|
-
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);
|
|
1462
1567
|
if (Array.isArray(projected.tasks)) {
|
|
1463
|
-
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));
|
|
1464
1569
|
}
|
|
1465
1570
|
// Anything else at the top level (a status answer's grants, a list's extras)
|
|
1466
1571
|
// is trimmed rather than dropped, so nothing disappears unexplained. The
|
|
@@ -1486,15 +1591,54 @@ function projectWithStage(value, stage, collect) {
|
|
|
1486
1591
|
}
|
|
1487
1592
|
if (key === 'answerReceipt' || key === 'decisionReceipt') continue;
|
|
1488
1593
|
if (key === 'hostAcceptance' && item !== null && typeof item === 'object' && !Array.isArray(item)) {
|
|
1489
|
-
projected[key] = boundAcceptance(item, key, collect);
|
|
1594
|
+
projected[key] = boundAcceptance(item, key, collect, stage.omitNote === true, stage.omitSummary === true);
|
|
1490
1595
|
continue;
|
|
1491
1596
|
}
|
|
1492
1597
|
projected[key] = trimAllStrings(item, key, cap, collect);
|
|
1493
1598
|
}
|
|
1494
1599
|
}
|
|
1600
|
+
guardDescriptionFields(projected, stage.skeletonChars ?? TRUNCATED_FIELD_CAPS.listItemChars, collect);
|
|
1495
1601
|
return projected;
|
|
1496
1602
|
}
|
|
1497
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
|
+
|
|
1498
1642
|
/**
|
|
1499
1643
|
* The identity, state, routing, refusal and acceptance block that is never
|
|
1500
1644
|
* dropped, renderable even when nothing else fits.
|
|
@@ -1504,7 +1648,7 @@ function projectWithStage(value, stage, collect) {
|
|
|
1504
1648
|
* @param {object[]} collect - truncation records.
|
|
1505
1649
|
* @returns {object} skeleton.
|
|
1506
1650
|
*/
|
|
1507
|
-
function skeletonize(task, path, cap, collect) {
|
|
1651
|
+
function skeletonize(task, path, cap, collect, stage = {}) {
|
|
1508
1652
|
if (task === null || typeof task !== 'object' || Array.isArray(task)) return task ?? null;
|
|
1509
1653
|
const pick = (key) => (key in task ? boundValue(task[key], `${path}.${key}`, cap, collect) : undefined);
|
|
1510
1654
|
const out = {};
|
|
@@ -1513,6 +1657,16 @@ function skeletonize(task, path, cap, collect) {
|
|
|
1513
1657
|
// The Agent Teams verdict is four booleans and a short reason: it survives every
|
|
1514
1658
|
// bound so a compressed answer still says whether teams are on for this run.
|
|
1515
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
|
+
}
|
|
1516
1670
|
const value = pick(key);
|
|
1517
1671
|
if (value === undefined) continue;
|
|
1518
1672
|
if (key === 'execution' && value !== null && typeof value === 'object') {
|
|
@@ -1522,12 +1676,6 @@ function skeletonize(task, path, cap, collect) {
|
|
|
1522
1676
|
}
|
|
1523
1677
|
} else if (key === 'route' || key === 'reviewRoute') {
|
|
1524
1678
|
out[key] = value === null ? null : boundValue(value, `${path}.${key}`, cap, collect);
|
|
1525
|
-
} else if (key === 'hostAcceptance') {
|
|
1526
|
-
// The recorded CONCLUSION is restored to its own bound after the generic walk, so a
|
|
1527
|
-
// small per-string cap can never shorten what the host concluded while leaving a
|
|
1528
|
-
// record that still reads as the whole note. A note beyond the accepted bound is
|
|
1529
|
-
// cut once, and the cut is stated.
|
|
1530
|
-
out[key] = value === null ? null : boundAcceptance(value, `${path}.hostAcceptance`, collect);
|
|
1531
1679
|
} else {
|
|
1532
1680
|
out[key] = value;
|
|
1533
1681
|
}
|
|
@@ -1540,6 +1688,12 @@ function skeletonize(task, path, cap, collect) {
|
|
|
1540
1688
|
// operation can never read as complete.
|
|
1541
1689
|
const pending = pendingPermissionsOf(task, path, collect);
|
|
1542
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
|
+
}
|
|
1543
1697
|
if (task.question?.pending !== null && typeof task.question?.pending === 'object') {
|
|
1544
1698
|
out.question = boundQuestionBlock(task.question, `${path}.question`, collect, QUESTION_WIRE_BUDGET);
|
|
1545
1699
|
}
|
|
@@ -1548,28 +1702,61 @@ function skeletonize(task, path, cap, collect) {
|
|
|
1548
1702
|
return out;
|
|
1549
1703
|
}
|
|
1550
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
|
+
|
|
1551
1711
|
/**
|
|
1552
1712
|
* Bound a recorded host review for a skeletonised answer.
|
|
1553
1713
|
*
|
|
1554
1714
|
* The conclusion fields are carried as the engine states them — `accepted`, `state`,
|
|
1555
1715
|
* `acceptedAt`, `by` — because they are the answer to "was this accepted?", and the note
|
|
1556
|
-
* keeps its own generous cap rather than the skeleton's per-string one.
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
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.
|
|
1559
1721
|
* @param {object} acceptance - host-acceptance record.
|
|
1560
1722
|
* @param {string} path - JSON path.
|
|
1561
1723
|
* @param {object[]} collect - truncation records.
|
|
1562
1724
|
* @returns {object} bounded record.
|
|
1563
1725
|
*/
|
|
1564
|
-
function boundAcceptance(acceptance, path, collect, omitNoteText = false) {
|
|
1565
|
-
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);
|
|
1566
1728
|
const out = {};
|
|
1567
1729
|
for (const [key, value] of Object.entries(acceptance)) {
|
|
1568
1730
|
if (key === 'note' && typeof value === 'string') {
|
|
1569
|
-
out[key] = value
|
|
1731
|
+
out[key] = reviewNoteLength(value) <= REVIEW_NOTE_MAX_CHARS
|
|
1732
|
+
? value
|
|
1733
|
+
: boundValue(value, `${path}.note`, REVIEW_NOTE_MAX_CHARS, collect);
|
|
1570
1734
|
continue;
|
|
1571
1735
|
}
|
|
1572
|
-
if (
|
|
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)) {
|
|
1573
1760
|
out[key] = value;
|
|
1574
1761
|
continue;
|
|
1575
1762
|
}
|
|
@@ -1579,16 +1766,15 @@ function boundAcceptance(acceptance, path, collect, omitNoteText = false) {
|
|
|
1579
1766
|
}
|
|
1580
1767
|
|
|
1581
1768
|
/**
|
|
1582
|
-
*
|
|
1583
|
-
*
|
|
1584
|
-
* The body is never silently cut: `noteOmitted: true` plus `noteChars` says the note is
|
|
1585
|
-
* still there, and `reviewNoteOffset`/`reviewNoteLimit` read it in full.
|
|
1586
|
-
* @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.
|
|
1587
1771
|
* @param {string} path - JSON path of the note.
|
|
1588
1772
|
* @param {object[]} collect - truncation records.
|
|
1589
|
-
* @
|
|
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.
|
|
1590
1775
|
*/
|
|
1591
|
-
function omitNote(acceptance, path, collect) {
|
|
1776
|
+
function omitNote(acceptance, path, collect, omitSummaryText = false) {
|
|
1777
|
+
const basePath = path.replace(/\.note$/u, '');
|
|
1592
1778
|
const length = typeof acceptance.note === 'string' ? Array.from(acceptance.note).length : 0;
|
|
1593
1779
|
if (acceptance.note !== undefined && acceptance.note !== null) {
|
|
1594
1780
|
collect.push({
|
|
@@ -1599,9 +1785,46 @@ function omitNote(acceptance, path, collect) {
|
|
|
1599
1785
|
detail: 'the review note is read with delegate_result reviewNoteOffset/reviewNoteLimit',
|
|
1600
1786
|
});
|
|
1601
1787
|
}
|
|
1602
|
-
const { note, ...rest } = acceptance;
|
|
1788
|
+
const { note, completionSummary, ...rest } = acceptance;
|
|
1603
1789
|
void note;
|
|
1604
|
-
|
|
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;
|
|
1605
1828
|
}
|
|
1606
1829
|
|
|
1607
1830
|
/**
|
|
@@ -1886,7 +2109,9 @@ function boundedJson(value) {
|
|
|
1886
2109
|
// full width, and only the body becomes `noteOmitted`, readable in pages.
|
|
1887
2110
|
{ executionText: 120, reviewText: 120, lists: 1, permissionEvidence: 1, omitNote: true },
|
|
1888
2111
|
{ executionText: 80, reviewText: 80, lists: 1, permissionEvidence: 0, skeletonChars: 240 },
|
|
1889
|
-
{ executionText:
|
|
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 },
|
|
1890
2115
|
];
|
|
1891
2116
|
const apply = (stage) => {
|
|
1892
2117
|
const records = [];
|
|
@@ -2423,9 +2648,11 @@ export function createMcpServer(options) {
|
|
|
2423
2648
|
} else {
|
|
2424
2649
|
result = await callExecution(route, payload);
|
|
2425
2650
|
}
|
|
2426
|
-
// A paged read of the review note returns only its slice:
|
|
2427
|
-
// ANSWER shape, not a projection of the big one.
|
|
2428
|
-
const page = name === 'delegate_result'
|
|
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;
|
|
2429
2656
|
const bounded = boundedJson(page ?? result);
|
|
2430
2657
|
producedText = bounded.text;
|
|
2431
2658
|
// A structurally trimmed answer is a real answer, so `isError` stays unset;
|
|
@@ -3293,6 +3520,59 @@ function reviewNotePage(payload, result) {
|
|
|
3293
3520
|
by: acceptance.by ?? null,
|
|
3294
3521
|
noteChars: points.length,
|
|
3295
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 } : {}),
|
|
3296
3576
|
},
|
|
3297
3577
|
reviewPersistence: task?.reviewPersistence ?? null,
|
|
3298
3578
|
};
|
package/src/mcp/wait.js
CHANGED
|
@@ -180,17 +180,22 @@ export function compactTask(task) {
|
|
|
180
180
|
// what a host needs to act, and the body is read on demand through `delegate_result`.
|
|
181
181
|
// The object is kept (with `noteOmitted`) so an old client cannot read "no note" as
|
|
182
182
|
// "not reviewed", and `reviewPersistence` states whether the conclusion is durable yet.
|
|
183
|
+
// A recorded summary is reported the same way, only when one exists, so an old shape holds.
|
|
183
184
|
const acceptance = out.hostAcceptance;
|
|
184
185
|
if (acceptance !== null && typeof acceptance === 'object' && !Array.isArray(acceptance)) {
|
|
186
|
+
const summaryChars = acceptance.completionSummaryChars
|
|
187
|
+
?? (typeof acceptance.completionSummary === 'string' ? Array.from(acceptance.completionSummary).length : 0);
|
|
185
188
|
out.hostAcceptance = {
|
|
186
189
|
accepted: acceptance.accepted === true,
|
|
187
190
|
state: acceptance.state ?? null,
|
|
188
191
|
acceptedAt: acceptance.acceptedAt ?? null,
|
|
189
192
|
by: acceptance.by ?? null,
|
|
190
|
-
// Counted from the body when it is here, so the
|
|
191
|
-
// on a view that carries the full note.
|
|
193
|
+
// Counted from the body when it is here, so the real length is stated.
|
|
192
194
|
noteChars: acceptance.noteChars ?? (typeof acceptance.note === 'string' ? Array.from(acceptance.note).length : 0),
|
|
193
195
|
noteOmitted: true,
|
|
196
|
+
...(summaryChars > 0
|
|
197
|
+
? { completionSummaryChars: summaryChars, completionSummaryOmitted: true }
|
|
198
|
+
: {}),
|
|
194
199
|
};
|
|
195
200
|
}
|
|
196
201
|
if (task.reviewPersistence !== undefined) out.reviewPersistence = task.reviewPersistence;
|