dsh-taskbridge 1.5.2 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/client/api.js CHANGED
@@ -1560,23 +1560,37 @@ export function hostReviewBadge(task) {
1560
1560
  }
1561
1561
 
1562
1562
  /**
1563
- * A task's recorded review conclusion as one bounded display line.
1563
+ * A task's recorded review conclusion as one SHORT display line.
1564
1564
  *
1565
- * Only a short note and the time are shown: the stored note is already redacted, and
1566
- * nothing else about the review exists.
1565
+ * This line carries the conclusion and its time — nothing else. The note BODY deliberately
1566
+ * does not appear here: this row sits beside the detail's own "完整审查意见" block, which
1567
+ * renders the saved text whole. Splicing a bounded cut of it in here produced a second,
1568
+ * truncated copy that read as if the stored text itself had been cut (the misleading
1569
+ * "已截断" line G10 fixes).
1570
+ *
1571
+ * The wording comes from `taskOutcome(...)` and only from there, so this row can never
1572
+ * claim a conclusion the headline contradicts — notably `accepted: true` with a review
1573
+ * record that is not durable yet (a save in flight, a timed-out unconfirmed write, a
1574
+ * failed one). A record written before `reviewPersistence` existed keeps the old
1575
+ * compatibility meaning (stored), which is again exactly what `taskOutcome` decides.
1567
1576
  * @param {object} task - task view.
1568
1577
  * @param {(at: number) => string} formatTime - time formatter from the page.
1569
1578
  * @returns {string} display text.
1570
1579
  */
1571
1580
  export function hostReviewLine(task, formatTime) {
1581
+ const outcome = taskOutcome(task);
1572
1582
  const acceptance = task?.hostAcceptance;
1573
- if (acceptance === null || acceptance === undefined) return '未记录(插件不会自行验收)';
1574
- const label = acceptance.accepted === true ? '审查通过' : '需要修正';
1583
+ if (acceptance === null || acceptance === undefined) {
1584
+ // Nothing recorded. A write that is pending or already failed is its own state, and
1585
+ // `taskOutcome` has already named it — repeating that here would say it twice.
1586
+ const persistence = task?.reviewPersistence;
1587
+ if (persistence?.pending === true || persistence?.state === 'failed') return outcome.label;
1588
+ return '未记录(插件不会自行验收)';
1589
+ }
1575
1590
  const at = typeof acceptance.acceptedAt === 'number' ? `(${formatTime(acceptance.acceptedAt)})` : '';
1576
- const note = typeof acceptance.note === 'string' && acceptance.note !== ''
1577
- ? `:${boundedText(acceptance.note, 200)}`
1578
- : '';
1579
- return `${label}${at}${note}`;
1591
+ // Only a CONFIRMED record is described as saved; an unconfirmed write keeps its own
1592
+ // label and never borrows this suffix.
1593
+ return outcome.decided ? `${outcome.label}${at}(结论已保存)` : `${outcome.label}${at}`;
1580
1594
  }
1581
1595
 
1582
1596
  /**
@@ -209,9 +209,42 @@ export const CSS_TEXT = `
209
209
  .dshdg-fail { color: var(--dsw-alias-label-error, #d92d20); }
210
210
  .dshdg-unknown { color: var(--dsw-alias-label-tertiary, #8a9098); }
211
211
  .dshdg-table { display: grid; gap: 4px; }
212
- .dshdg-kv { display: grid; grid-template-columns: minmax(96px, 140px) minmax(0, 1fr); gap: 4px 10px; }
212
+ .dshdg-kv {
213
+ display: grid;
214
+ grid-template-columns: minmax(96px, 140px) minmax(0, 1fr);
215
+ gap: 4px 10px;
216
+ min-width: 0;
217
+ }
213
218
  .dshdg-kv dt { color: var(--dsw-alias-label-secondary, #61666d); }
214
- .dshdg-kv dd { margin: 0; overflow-wrap: anywhere; }
219
+ .dshdg-kv dd {
220
+ margin: 0;
221
+ /* A grid item defaults to min-width: auto, i.e. "at least as wide as my longest
222
+ unbreakable run" — the single place that pushed a long review note past the panel. */
223
+ min-width: 0;
224
+ overflow-wrap: anywhere;
225
+ }
226
+ /* A recorded review note: shown whole, wrapped inside its own track, never clipped.
227
+ pre-wrap keeps every paragraph break and every space the host stored; anywhere breaks a
228
+ long unbroken run (a path, a URL, 270 code points of Chinese with no spaces). Nothing
229
+ here shortens, hides or line-clamps the body: the block keeps its natural height. */
230
+ .dshdg-note {
231
+ min-width: 0;
232
+ max-width: 100%;
233
+ overflow-wrap: anywhere;
234
+ }
235
+ .dshdg-note-full {
236
+ min-width: 0;
237
+ max-width: 100%;
238
+ margin: 0;
239
+ white-space: pre-wrap;
240
+ overflow-wrap: anywhere;
241
+ word-break: break-word;
242
+ }
243
+ .dshdg-note-preview {
244
+ min-width: 0;
245
+ overflow-wrap: anywhere;
246
+ word-break: break-word;
247
+ }
215
248
  @media (max-width: 560px) {
216
249
  .dshdg-layer, .dshdg-kv { grid-template-columns: minmax(0, 1fr); }
217
250
  }
@@ -8,12 +8,18 @@
8
8
  // 1. `$CODEX_HOME/agents/dsh-taskbridge.toml` — a *managed copy* of the shipped
9
9
  // template `codex/dsh-taskbridge.toml`. Ownership is proved by content, never by
10
10
  // the file name or a version line alone:
11
- // * a file that is byte-identical to the template this build would write is
12
- // `installed` (and removable);
13
- // * a file that matches one of the *known prior shipped templates* in
14
- // {@link KNOWN_AGENT_TEMPLATES} byte for byte is `outdated` (refreshable and
15
- // removable) — a conservative, enumerated list, not a heuristic;
11
+ // * a file that is the same text as the template this build would write is
12
+ // `installed` (and removable). "Same text" admits exactly one difference: CRLF
13
+ // versus LF line terminators (including a mixed spelling of the same lines).
14
+ // Nothing else is normalized — a version line, a comment, a blank line, a
15
+ // trailing space, a tab, a BOM or a lone CR all still make a file different;
16
+ // * a file that is the same text as one of the *known prior shipped templates* in
17
+ // {@link KNOWN_AGENT_TEMPLATES} — as published, or with the terminators spelled
18
+ // the other way per line — is `outdated` (refreshable and removable). The list is
19
+ // still a conservative, enumerated set of published builds, not a heuristic;
16
20
  // * anything else is `modified`/`conflict`: never overwritten, never removed.
21
+ // The tolerant comparison is for CLASSIFICATION only. Every write and delete re-proves
22
+ // the exact bytes it read, so a file edited between the read and the write is kept.
17
23
  // A first install is *exclusive* (`wx`), so a file that appears between the
18
24
  // status read and the write is reported as a conflict instead of replaced.
19
25
  // 2. the `mcp_servers.dsh-delegate` table in `$CODEX_HOME/config.toml`, and only
@@ -111,15 +117,18 @@ export const CODEX_ACTIONS = Object.freeze(['status', 'install', 'repair', 'remo
111
117
  * *as written* (template with the version marker stamped).
112
118
  *
113
119
  * This list, not a heuristic, is what makes `outdated` mean "a build this plugin
114
- * really published". A file that is not byte-identical to one of these is somebody
120
+ * really published". A file that is not identical to one of these texts is somebody
115
121
  * else's file, even if it still carries the managed header and an old version line.
116
- * Regenerating a digest is a deliberate act: add the entry for a release only after
117
- * that release has been packed and its agent file verified.
122
+ * "Identical" admits the CRLF/LF spelling of the same text only (see
123
+ * {@link isKnownPriorTemplate}); the entries below stay the exact published identities and
124
+ * are never derived from the current template. Regenerating a digest is a deliberate act:
125
+ * add the entry for a release only after that release has been packed and its agent file
126
+ * verified.
118
127
  *
119
128
  * The 0.1.6, both 0.1.7 builds, the 0.1.8 and 0.1.9 builds, the published 0.1.10
120
129
  * template (in both its packed CRLF and its LF byte form), the published 0.1.11
121
130
  * template and the published 0.1.12 template are enumerated here because they are
122
- * published Codex agent builds. A file that is not byte-identical to one of these
131
+ * published Codex agent builds. A file that is not identical to one of these
123
132
  * releases or the current template is reported as `modified`, rather than guessed as
124
133
  * ours.
125
134
  * The array is intentionally mutable (not frozen) so a test can pin a temporary
@@ -416,18 +425,130 @@ export const KNOWN_AGENT_TEMPLATES = [
416
425
  // * `da2f428f…` — LF form (39,743 bytes).
417
426
  // * `f55893e7…` — the installed CRLF form (40,259 bytes).
418
427
  { version: '1.5.0', sha256: 'da2f428f726ae64b6895941d5238516346af91b63b038b1d57787be327fb28ee' },
419
- { version: '1.5.0', sha256: 'f55893e7605627c6f0c9a4c55f58a5a1956d4c11b8c03c99569dca241842d8bb' },
420
- // Exact locally installed test.3 product template, verified before preparing 1.5.1.
421
- { version: '1.5.1-test.3', sha256: 'dc1c17f3bdfe171d3c1e7f943d569b12ffe12d6b25190fffe1c8c9550446f29d' },
422
- { version: '1.5.1-test.3', sha256: '06e13895f6df3ec9fbf48b1b40af42940f3ddf2b3afad356751dbd11e1205ff4' },
423
- // Exact published v1.5.1 template; only the version stamp changes in 1.5.2.
424
- { version: '1.5.1', sha256: '3d4fa9d8543306a10a5ac7d337d1538ebf57a20104674192de16ba13f580c0e6' },
428
+ { version: '1.5.0', sha256: 'f55893e7605627c6f0c9a4c55f58a5a1956d4c11b8c03c99569dca241842d8bb' },
429
+ // Exact locally installed test.3 product template, verified before preparing 1.5.1.
430
+ { version: '1.5.1-test.3', sha256: 'dc1c17f3bdfe171d3c1e7f943d569b12ffe12d6b25190fffe1c8c9550446f29d' },
431
+ { version: '1.5.1-test.3', sha256: '06e13895f6df3ec9fbf48b1b40af42940f3ddf2b3afad356751dbd11e1205ff4' },
432
+ // Exact published v1.5.1 template; only the version stamp changes in 1.5.2.
433
+ { version: '1.5.1', sha256: '3d4fa9d8543306a10a5ac7d337d1538ebf57a20104674192de16ba13f580c0e6' },
425
434
  { version: '1.5.1', sha256: 'ad0c09209e60234d369a0589fdc61477efa20b95b02d66534901d6fbc0f4d673' },
435
+ // Published 1.5.2 before the P0 planning rules, preserved in tests/fixtures/agent-1.5.2.toml.
436
+ // These exact LF/CRLF identities allow a managed upgrade without claiming user edits.
437
+ { version: '1.5.2', sha256: 'e0971d206f962ed145d36986334fd27107d3270ead0688e4899b7be2fc1544d2' },
438
+ { version: '1.5.2', sha256: '86ec91643d285ff8fb7e21121b7e4c4cd1cc8687b1190af88865bfb0ff3eab8a' },
439
+ // The INSTALLED local test build `1.5.3-test.1`. Both identities are the bytes of that
440
+ // build's OWN product template, not a reconstruction from today's text: they were
441
+ // preserved byte for byte as `tests/fixtures/agent-1.5.3-test.1.toml` and compared
442
+ // byte-for-byte with the file actually installed on the operator's machine.
443
+ //
444
+ // * `e5e96ae7…` — the installed CRLF form (43,287 bytes, `version = "1.5.3-test.1"`).
445
+ // * `fc767654…` — the same text with every `\r\n` folded to `\n` (42,734 bytes).
446
+ //
447
+ // Without these two an untouched test.1 install hashes to "unknown content" and is
448
+ // reported `modified`, which would make the upgrade to 1.5.3-test.2 impossible. Only
449
+ // these exact bytes qualify: a single edited character still hashes to something
450
+ // unknown and stays the operator's file.
451
+ { version: '1.5.3-test.1', sha256: 'e5e96ae7d0ab3dbfe2d06b58182e2e36c761e0ee622b212f5d0ff584a6412fd0' },
452
+ { version: '1.5.3-test.1', sha256: 'fc7676549dd75fee7ae3ab343a617514dd0d32def9321255b772e29197ac9a76' },
453
+ // The INSTALLED local test build `1.5.3-test.2`, i.e. the last step before the formal
454
+ // 1.5.3 release. Its identity is evidence, not a rendering of today's text: both forms
455
+ // were read from the files of that build that are actually on the operator's machine
456
+ // (saved as `installed-test.2-template.toml` and `installed-test.2-agent.toml`) and were
457
+ // found to differ ONLY in their terminators, the version line being `1.5.3-test.2` in
458
+ // both. The template form is preserved byte for byte as
459
+ // `tests/fixtures/agent-1.5.3-test.2.toml` and compared against the installed one.
460
+ //
461
+ // * `2a905842…` — the shipped template file, CRLF throughout (43,287 bytes).
462
+ // * `77a4e834…` — the file that build actually installed, the same text with LF
463
+ // terminators (42,734 bytes), which is what {@link renderAgentFile} writes.
464
+ //
465
+ // Without these two an untouched test.2 install hashes to "unknown content" and is
466
+ // reported `modified`, which would make the upgrade to the formal 1.5.3 template
467
+ // impossible. Only these exact bytes qualify: a single edited character still hashes to
468
+ // something unknown and stays the operator's file.
469
+ { version: '1.5.3-test.2', sha256: '2a9058424f33b0a022b05aedc3ebfcf35c0cb10eac498b754597dd7f90d3c775' },
470
+ { version: '1.5.3-test.2', sha256: '77a4e83459ef605826cfaa1057d19058c4ae36a5ed6080ebd70c88a0a3dd69fb' },
471
+ // Exact published 1.5.3 template (CRLF/LF), preserved before the placement-rule update.
472
+ { version: '1.5.3', sha256: 'd26428333420f6e37d6a2ed5b953268bb99642eec4c08d46c402002ca6793df8' },
473
+ { version: '1.5.3', sha256: '12c1caac42d461b143e23b0b1e1218e32a735ee665ce13ac56ebef7c0f46cfd3' },
426
474
  ];
427
475
 
428
476
  /** The `version = "…"` line of an agent file, at column 0. */
429
477
  const VERSION_LINE = /^version[ \t]*=[ \t]*"([^"]*)"\r?$/mu;
430
478
 
479
+ /**
480
+ * Read agent text with CRLF terminators folded to LF.
481
+ *
482
+ * The shipped template is stored with CRLF terminators while {@link renderAgentFile} writes
483
+ * the managed file with LF, so the terminator spelling alone is not a content difference.
484
+ * Only `\r\n` is folded: a BOM, a lone `\r`, a tab, a trailing space, a blank line, a comment
485
+ * and the version line all stay exactly as they are, so every one of them still makes a file
486
+ * a different text. A `\r\r\n` therefore keeps the extra `\r` and stays different too.
487
+ * Classification may use this fold; every write and delete still re-proves the exact bytes it
488
+ * read (`agent.expect`).
489
+ * @param {string} text - agent file or template text.
490
+ * @returns {string} the text with CRLF folded to LF.
491
+ */
492
+ function normalizeLineEndings(text) {
493
+ return text.replace(/\r\n/gu, '\n');
494
+ }
495
+
496
+ /**
497
+ * The normalization above applied to BOTH texts, i.e. "is this the same text?".
498
+ * @param {string} contents - text read from an agent file.
499
+ * @param {string} template - text this build would write.
500
+ * @returns {boolean} true when the two texts differ at most in CRLF/LF spelling.
501
+ */
502
+ function sameAgentText(contents, template) {
503
+ if (contents === template) return true;
504
+ return normalizeLineEndings(contents) === normalizeLineEndings(template);
505
+ }
506
+
507
+ /**
508
+ * Is this file one of the exact agent files an earlier release shipped?
509
+ *
510
+ * The only case where install may replace an existing file. The test is content identity: a
511
+ * single changed character changes the digest, and the version line is deliberately *not*
512
+ * used as proof.
513
+ *
514
+ * The one tolerated difference is the CRLF/LF spelling of the SAME text, which is why the
515
+ * file is also matched as its whole text normalized to LF and as that text with every
516
+ * terminator spelled CRLF. Both digests are compared against the SAME enumerated table above —
517
+ * that table is never rebuilt, widened, re-versioned or emptied.
518
+ *
519
+ * That equivalent branch is only reachable when the normalized text still contains NO `\r` at
520
+ * all. A `\r` left over after storing the CRLF/LF fold is a character of the file, not a
521
+ * spelling: a file whose every line was rewritten to `\r\r\n` normalizes to text that already
522
+ * looks CRLF, so without this guard it would match the published CRLF digest and be claimed as
523
+ * ours (then overwritten). Such a file is an operator edit and stays `modified`.
524
+ * Everything else still fails too: an added or removed line, a comment, a trailing space, a tab,
525
+ * a BOM, a changed version line or any other edit hashes to nothing in the table.
526
+ * @param {string} contents - installed file text.
527
+ * @param {object} [options] - `ignoreVersion`: compare with the version line masked, used only
528
+ * to explain *why* a file is `modified` in the status note. It never grants refresh or removal.
529
+ * @returns {boolean} true when the file is a known published build of this template.
530
+ */
531
+ export function isKnownPriorTemplate(contents, { ignoreVersion = false } = {}) {
532
+ if (typeof contents !== 'string') return false;
533
+ const known = (text) => KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digest(text));
534
+ if (known(contents)) return true;
535
+ const lf = normalizeLineEndings(contents);
536
+ // A leftover `\r` means the file has a CR no spelling fold accounts for, so no equivalent
537
+ // digest may claim it. This guard wraps ONLY the equivalent branch; the diagnosis below is
538
+ // still reachable for such a file.
539
+ if (!lf.includes('\r')) {
540
+ if (known(lf)) return true;
541
+ const crlf = lf.replace(/\n/gu, '\r\n');
542
+ if (crlf !== contents && known(crlf)) return true;
543
+ }
544
+ if (!ignoreVersion) return false;
545
+ // Explanation-only path: the same body with the version line stripped still has to
546
+ // match a known build, which distinguishes "operator edited a managed file" from
547
+ // "this file was never ours".
548
+ const stripped = contents.replace(VERSION_LINE, 'version = "\u0000"');
549
+ return KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digest(stripped));
550
+ }
551
+
431
552
  /** Stable states reported for the agent file. */
432
553
  export const AGENT_STATES = Object.freeze({
433
554
  missing: 'not-installed',
@@ -1115,11 +1236,18 @@ async function readLinkTarget(path) {
1115
1236
  /**
1116
1237
  * Compare the installed agent file with the template this build would write.
1117
1238
  *
1118
- * The order matters. Content equality is checked first, so a byte-identical file is
1119
- * `installed` no matter what its version line says. Only then is the exact
1120
- * known-template list consulted, and only a byte-exact match to a published build is
1121
- * `outdated`. Everything else is `modified`: a body edit, a stray byte, a tampered
1122
- * or invented version line, or a file that merely looks like ours.
1239
+ * The order matters. Content equality is checked first, so a file that is the same text
1240
+ * as the template is `installed` no matter what its version line says; "the same text"
1241
+ * includes the CRLF/LF spelling, because the shipped template's terminators are not part
1242
+ * of its content (see {@link normalizeLineEndings}). Only then is the exact known-template
1243
+ * list consulted, and only a match to a published build is `outdated`. Everything else is
1244
+ * `modified`: a body edit, a stray byte, a tampered or invented version line, or a file
1245
+ * that merely looks like ours.
1246
+ *
1247
+ * `contents` is always the text EXACTLY as read, and `expect` (the status field derived
1248
+ * from it) is what the write and delete paths re-prove against, so a file rewritten
1249
+ * between the read and the write is still detected even though this classification is
1250
+ * line-ending tolerant.
1123
1251
  * @param {string} path - agent file path.
1124
1252
  * @param {string} template - template text this build would write.
1125
1253
  * @returns {Promise<{ state: string, present: boolean, reason: string | null, contents: string | null }>} agent state and the exact bytes it was derived from.
@@ -1129,7 +1257,7 @@ async function readAgentState(path, template) {
1129
1257
  if (existing.kind === 'missing') return { state: AGENT_STATES.missing, present: false, reason: null, contents: null };
1130
1258
  if (existing.kind === 'other') return { state: AGENT_STATES.conflict, present: true, reason: 'not-a-regular-file', contents: null };
1131
1259
  const contents = existing.contents;
1132
- if (contents === template) return { state: AGENT_STATES.installed, present: true, reason: null, contents };
1260
+ if (sameAgentText(contents, template)) return { state: AGENT_STATES.installed, present: true, reason: null, contents };
1133
1261
  if (isKnownPriorTemplate(contents)) return { state: AGENT_STATES.outdated, present: true, reason: null, contents };
1134
1262
  return {
1135
1263
  state: AGENT_STATES.modified,
@@ -1218,32 +1346,6 @@ function linkedBoundaryRefusal(status) {
1218
1346
  };
1219
1347
  }
1220
1348
 
1221
- /**
1222
- * Is this file one of the exact agent files an earlier release shipped?
1223
- *
1224
- * The only case where install may replace an existing file. The test is content
1225
- * identity against the enumerated digest list, which cannot be satisfied by an
1226
- * operator edit: a single changed byte changes the digest. The version line is
1227
- * deliberately *not* used as proof — an operator can edit a body while leaving (or
1228
- * lowering) that line, and a heuristic on it is exactly how a customised agent
1229
- * gets overwritten.
1230
- * @param {string} contents - installed file text.
1231
- * @param {object} [options] - `ignoreVersion`: compare with the version line masked,
1232
- * used only to explain *why* a file is `modified` in the status note.
1233
- * @returns {boolean} true when the file is a known published build of this template.
1234
- */
1235
- export function isKnownPriorTemplate(contents, { ignoreVersion = false } = {}) {
1236
- if (typeof contents !== 'string') return false;
1237
- const digestValue = digest(contents);
1238
- if (KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digestValue)) return true;
1239
- if (!ignoreVersion) return false;
1240
- // Explanation-only path: the same body with the version line stripped still has to
1241
- // match a known build, which distinguishes "operator edited a managed file" from
1242
- // "this file was never ours".
1243
- const stripped = contents.replace(VERSION_LINE, 'version = "\u0000"');
1244
- return KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digest(stripped));
1245
- }
1246
-
1247
1349
  /**
1248
1350
  * Write a file that must not exist yet, atomically and exclusively.
1249
1351
  *
@@ -2189,15 +2291,23 @@ export function removeMcpEntry(document) {
2189
2291
 
2190
2292
  /**
2191
2293
  * Render the agent file from the shipped template plus this package's version.
2294
+ *
2295
+ * The MANAGED file is written with LF terminators, whatever the template's own spelling
2296
+ * is: this repository stores `codex/dsh-taskbridge.toml` CRLF, and a renderer that echoed
2297
+ * that spelling would make the file it writes depend on the checkout it was built from.
2298
+ * Only the terminators are touched — every other byte of the body is copied verbatim
2299
+ * (spaces, tabs, blank lines, comments), and {@link readAgentTemplate} still returns the
2300
+ * template exactly as shipped, so the source TOML is never rewritten.
2192
2301
  * @param {string} template - shipped template.
2193
2302
  * @param {string} version - package version.
2194
- * @returns {string} file contents.
2303
+ * @returns {string} file contents, LF-terminated.
2195
2304
  */
2196
2305
  export function renderAgentFile(template, version) {
2197
2306
  const marker = `version = ${renderString(version)}`;
2198
- if (/^version = ".*"$/mu.test(template)) return template.replace(/^version = ".*"$/mu, marker);
2307
+ const text = normalizeLineEndings(template);
2308
+ if (/^version = ".*"$/mu.test(text)) return text.replace(/^version = ".*"$/mu, marker);
2199
2309
  // Keep the provenance header first, then the version marker, then the rest.
2200
- const lines = template.split('\n');
2310
+ const lines = text.split('\n');
2201
2311
  const insertAt = lines.findIndex((line) => line.trim() !== '' && !line.trimStart().startsWith('#'));
2202
2312
  const resolved = insertAt === -1 ? lines.length : insertAt;
2203
2313
  lines.splice(resolved, 0, marker);
@@ -22,6 +22,10 @@ import { classifyError, HttpError, readJsonBody, sendJson } from '../http/respon
22
22
  import { preflightWorkspace } from '../workspace/preflight.js';
23
23
  import { redactText } from '../config/redact.js';
24
24
  import { REVIEW_NOTE_MAX_CHARS, normalizeReviewNote, reviewNoteOverflow } from '../jobs/review-note.js';
25
+ import {
26
+ TASK_DESCRIPTION_FIELDS,
27
+ canonicalTaskDescription,
28
+ } from '../jobs/task-descriptions.js';
25
29
 
26
30
  /** Route prefix owned by this plane. Deliberately not under `/api`. */
27
31
  export const EXECUTION_PREFIX = '/dsh-delegate/x';
@@ -238,6 +242,19 @@ async function submitTask({ req, res, connection, deps }) {
238
242
  const overrides = body.agentTeams === undefined
239
243
  ? body.overrides
240
244
  : { ...(body.overrides ?? {}), agentTeams: body.agentTeams };
245
+ // Checked here as well as in the engine: a bad or redaction-lengthened goal is refused
246
+ // before a task, slot or consumed grant exists.
247
+ const goal = canonicalTaskDescription(body.goalDescription, TASK_DESCRIPTION_FIELDS.goal, redactText);
248
+ if (goal.ok === false) {
249
+ throw new HttpError(400, 'TASK_GOAL_DESCRIPTION_INVALID', goal.refusal.message, {
250
+ field: goal.refusal.field,
251
+ limit: goal.refusal.limit,
252
+ length: goal.refusal.length,
253
+ unit: goal.refusal.unit,
254
+ });
255
+ }
256
+ // The canonical value travels on; the engine re-derives the same form (a no-op).
257
+ const goalField = goal.value === null ? {} : { goalDescription: goal.value };
241
258
  if (deps.engine.authorizationMode === 'switch') {
242
259
  const task = await deps.engine.start({
243
260
  connectionId: connection.connectionId,
@@ -246,6 +263,7 @@ async function submitTask({ req, res, connection, deps }) {
246
263
  ...(body.title === undefined ? {} : { title: body.title }),
247
264
  overrides,
248
265
  ...(continueFromTaskId === undefined ? {} : { continueFromTaskId }),
266
+ ...goalField,
249
267
  });
250
268
  sendJson(res, 202, { ok: true, task });
251
269
  return;
@@ -264,6 +282,7 @@ async function submitTask({ req, res, connection, deps }) {
264
282
  ...(body.title === undefined ? {} : { title: body.title }),
265
283
  overrides,
266
284
  ...(continueFromTaskId === undefined ? {} : { continueFromTaskId }),
285
+ ...goalField,
267
286
  });
268
287
  sendJson(res, 202, { ok: true, task });
269
288
  }
@@ -428,7 +447,7 @@ async function answerQuestion({ req, res, connection, deps }) {
428
447
  });
429
448
  sendJson(res, 200, { ok: true, ...result });
430
449
  }
431
- const REVIEW_FIELDS = Object.freeze(['taskId', 'decision', 'note']);
450
+ const REVIEW_FIELDS = Object.freeze(['taskId', 'decision', 'note', 'completionSummary']);
432
451
 
433
452
  /**
434
453
  * Longest review note the route will even read, in Unicode code points.
@@ -479,6 +498,18 @@ async function recordHostReview({ req, res, connection, deps }) {
479
498
  unit: 'unicode-code-points',
480
499
  });
481
500
  }
501
+ // Optional, checked with the same rule as the goal, refused before any read or write.
502
+ const summary = canonicalTaskDescription(body.completionSummary, TASK_DESCRIPTION_FIELDS.summary, redactText);
503
+ if (summary.ok === false) {
504
+ throw new HttpError(400, 'REVIEW_COMPLETION_SUMMARY_INVALID', summary.refusal.message, {
505
+ field: summary.refusal.field,
506
+ limit: summary.refusal.limit,
507
+ length: summary.refusal.length,
508
+ unit: summary.refusal.unit,
509
+ });
510
+ }
511
+ // The canonical value is sent only when there is one, so `undefined` means "stated none".
512
+ const summaryField = summary.value === null ? {} : { completionSummary: summary.value };
482
513
  let result;
483
514
  try {
484
515
  result = await deps.engine.recordHostReview({
@@ -487,6 +518,7 @@ async function recordHostReview({ req, res, connection, deps }) {
487
518
  taskId: body.taskId,
488
519
  decision: body.decision,
489
520
  note,
521
+ ...summaryField,
490
522
  });
491
523
  } catch (error) {
492
524
  // A finished task read back from durable history (after a restart) is reviewed through
@@ -495,7 +527,7 @@ async function recordHostReview({ req, res, connection, deps }) {
495
527
  result = await deps.engine.recordHistoricalReview({
496
528
  taskId: body.taskId,
497
529
  connectionId: connection.connectionId,
498
- }, body.decision, redactText(note), null);
530
+ }, body.decision, redactText(note), null, summary.value ?? undefined);
499
531
  }
500
532
  sendJson(res, 200, { ok: true, ...result });
501
533
  }
package/src/index.d.ts CHANGED
@@ -105,6 +105,22 @@ export interface DelegateRouteOptions {
105
105
  requireEffort?: boolean;
106
106
  }
107
107
 
108
+ /** Commander-supplied submission fields (`delegate_submit`, `POST /tasks`; prose <= 2000 code points). */
109
+ export interface DelegateSubmitRequest {
110
+ workspacePath: string;
111
+ prompt: string;
112
+ title?: string;
113
+ goalDescription?: string;
114
+ continueFromTaskId?: string;
115
+ overrides?: {
116
+ model?: string;
117
+ reasoningEffort?: string;
118
+ timeoutSeconds?: number;
119
+ [field: string]: unknown;
120
+ };
121
+ agentTeams?: boolean;
122
+ }
123
+
108
124
  /**
109
125
  * One pending per-call permission request, as the task view publishes it.
110
126
  *
@@ -431,7 +447,7 @@ export type DelegateObserveReason =
431
447
  | 'cancelled'
432
448
  | 'interrupted';
433
449
 
434
- /** The compact task summary one observation returns. */
450
+ /** Compact task summary one observation returns (carries summary length/omission flag, no prose). */
435
451
  export interface DelegateObservationSummary {
436
452
  taskId: string;
437
453
  state: 'pending' | 'running' | 'awaiting-host-review' | 'failed' | 'cancelled' | 'interrupted';
@@ -501,14 +517,16 @@ export interface DelegateAgentTeamsOutcome {
501
517
  * A replayed (idempotent) review request and its answer.
502
518
  *
503
519
  * `decision` is the closed vocabulary the review verb accepts; a note is required and
504
- * bounded. Repeating the same decision with the same note is a no-op; a different
505
- * conclusion is refused.
520
+ * bounded. Repeating the same decision with the same note — and the same optional
521
+ * completion summary — is a no-op; a different conclusion is refused.
506
522
  */
507
523
  export interface DelegateReviewRequest {
508
524
  taskId: string;
509
525
  decision: 'accepted' | 'changes-requested';
510
526
  /** Required after trimming; at most 8000 Unicode code points; stored redacted. */
511
527
  note: string;
528
+ /** Optional completion summary (<= 2000 code points, redacted, part of review identity). */
529
+ completionSummary?: string;
512
530
  }
513
531
 
514
532
  /** Answer of one recorded delivery review. */
@@ -542,10 +560,21 @@ export interface DelegateReviewPersistence {
542
560
  error: { code: string; message: string } | null;
543
561
  }
544
562
 
545
- /** A wait carries status and length, never repeats the note body. */
546
- export interface DelegateCompactHostAcceptance extends Omit<DelegateHostAcceptance, 'note'> {
563
+ /** Wait/compact review projection: carries lengths and omission flags, never prose bodies. */
564
+ export interface DelegateCompactHostAcceptance extends Omit<DelegateHostAcceptance, 'note' | 'completionSummary'> {
565
+ noteChars: number;
566
+ noteOmitted: true;
567
+ completionSummaryChars?: number;
568
+ completionSummaryOmitted?: true;
569
+ }
570
+
571
+ /** Bounded review projection where `note` is paged out while a legal `completionSummary` stays whole unless omitted. */
572
+ export interface DelegateOmittedHostAcceptance extends Omit<DelegateHostAcceptance, 'note' | 'completionSummary'> {
547
573
  noteChars: number;
548
574
  noteOmitted: true;
575
+ completionSummary?: string;
576
+ completionSummaryChars?: number;
577
+ completionSummaryOmitted?: true;
549
578
  }
550
579
 
551
580
  /** Optional paged note read on delegate_result; omit offset for the old result shape. */
@@ -574,6 +603,32 @@ export interface DelegateReviewNotePageResult {
574
603
  reviewPersistence: DelegateReviewPersistence | null;
575
604
  }
576
605
 
606
+ /** Optional paged completion-summary read on delegate_result when completionSummaryOmitted is true. */
607
+ export interface DelegateCompletionSummaryPageRequest {
608
+ taskId: string;
609
+ /** Nonnegative Unicode code-point offset. */
610
+ completionSummaryOffset: number;
611
+ /** Integer from 1 to 2000, default 2000. Requires completionSummaryOffset. */
612
+ completionSummaryLimit?: number;
613
+ }
614
+
615
+ export interface DelegateCompletionSummaryPageResult {
616
+ ok: true;
617
+ taskId: string;
618
+ state: string | null;
619
+ completionSummary: {
620
+ offset: number;
621
+ limit: number;
622
+ text: string;
623
+ summaryChars: number;
624
+ nextOffset: number | null;
625
+ complete: boolean;
626
+ present: boolean;
627
+ };
628
+ hostAcceptance: DelegateCompactHostAcceptance | null;
629
+ reviewPersistence: DelegateReviewPersistence | null;
630
+ }
631
+
577
632
  /**
578
633
  * The commander's recorded delivery review of one finished task.
579
634
  *
@@ -592,6 +647,8 @@ export interface DelegateHostAcceptance {
592
647
  by: string;
593
648
  /** The redacted, bounded conclusion. */
594
649
  note: string;
650
+ /** Optional redacted summary recorded with `note` (absent when omitted; never implies acceptance). */
651
+ completionSummary?: string;
595
652
  }
596
653
 
597
654
  /**