dsh-taskbridge 1.5.1 → 1.5.3

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.
@@ -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,15 +425,127 @@ 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' },
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' },
422
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' },
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' },
423
471
  ];
424
472
 
425
473
  /** The `version = "…"` line of an agent file, at column 0. */
426
474
  const VERSION_LINE = /^version[ \t]*=[ \t]*"([^"]*)"\r?$/mu;
427
475
 
476
+ /**
477
+ * Read agent text with CRLF terminators folded to LF.
478
+ *
479
+ * The shipped template is stored with CRLF terminators while {@link renderAgentFile} writes
480
+ * the managed file with LF, so the terminator spelling alone is not a content difference.
481
+ * Only `\r\n` is folded: a BOM, a lone `\r`, a tab, a trailing space, a blank line, a comment
482
+ * and the version line all stay exactly as they are, so every one of them still makes a file
483
+ * a different text. A `\r\r\n` therefore keeps the extra `\r` and stays different too.
484
+ * Classification may use this fold; every write and delete still re-proves the exact bytes it
485
+ * read (`agent.expect`).
486
+ * @param {string} text - agent file or template text.
487
+ * @returns {string} the text with CRLF folded to LF.
488
+ */
489
+ function normalizeLineEndings(text) {
490
+ return text.replace(/\r\n/gu, '\n');
491
+ }
492
+
493
+ /**
494
+ * The normalization above applied to BOTH texts, i.e. "is this the same text?".
495
+ * @param {string} contents - text read from an agent file.
496
+ * @param {string} template - text this build would write.
497
+ * @returns {boolean} true when the two texts differ at most in CRLF/LF spelling.
498
+ */
499
+ function sameAgentText(contents, template) {
500
+ if (contents === template) return true;
501
+ return normalizeLineEndings(contents) === normalizeLineEndings(template);
502
+ }
503
+
504
+ /**
505
+ * Is this file one of the exact agent files an earlier release shipped?
506
+ *
507
+ * The only case where install may replace an existing file. The test is content identity: a
508
+ * single changed character changes the digest, and the version line is deliberately *not*
509
+ * used as proof.
510
+ *
511
+ * The one tolerated difference is the CRLF/LF spelling of the SAME text, which is why the
512
+ * file is also matched as its whole text normalized to LF and as that text with every
513
+ * terminator spelled CRLF. Both digests are compared against the SAME enumerated table above —
514
+ * that table is never rebuilt, widened, re-versioned or emptied.
515
+ *
516
+ * That equivalent branch is only reachable when the normalized text still contains NO `\r` at
517
+ * all. A `\r` left over after storing the CRLF/LF fold is a character of the file, not a
518
+ * spelling: a file whose every line was rewritten to `\r\r\n` normalizes to text that already
519
+ * looks CRLF, so without this guard it would match the published CRLF digest and be claimed as
520
+ * ours (then overwritten). Such a file is an operator edit and stays `modified`.
521
+ * Everything else still fails too: an added or removed line, a comment, a trailing space, a tab,
522
+ * a BOM, a changed version line or any other edit hashes to nothing in the table.
523
+ * @param {string} contents - installed file text.
524
+ * @param {object} [options] - `ignoreVersion`: compare with the version line masked, used only
525
+ * to explain *why* a file is `modified` in the status note. It never grants refresh or removal.
526
+ * @returns {boolean} true when the file is a known published build of this template.
527
+ */
528
+ export function isKnownPriorTemplate(contents, { ignoreVersion = false } = {}) {
529
+ if (typeof contents !== 'string') return false;
530
+ const known = (text) => KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digest(text));
531
+ if (known(contents)) return true;
532
+ const lf = normalizeLineEndings(contents);
533
+ // A leftover `\r` means the file has a CR no spelling fold accounts for, so no equivalent
534
+ // digest may claim it. This guard wraps ONLY the equivalent branch; the diagnosis below is
535
+ // still reachable for such a file.
536
+ if (!lf.includes('\r')) {
537
+ if (known(lf)) return true;
538
+ const crlf = lf.replace(/\n/gu, '\r\n');
539
+ if (crlf !== contents && known(crlf)) return true;
540
+ }
541
+ if (!ignoreVersion) return false;
542
+ // Explanation-only path: the same body with the version line stripped still has to
543
+ // match a known build, which distinguishes "operator edited a managed file" from
544
+ // "this file was never ours".
545
+ const stripped = contents.replace(VERSION_LINE, 'version = "\u0000"');
546
+ return KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digest(stripped));
547
+ }
548
+
428
549
  /** Stable states reported for the agent file. */
429
550
  export const AGENT_STATES = Object.freeze({
430
551
  missing: 'not-installed',
@@ -1112,11 +1233,18 @@ async function readLinkTarget(path) {
1112
1233
  /**
1113
1234
  * Compare the installed agent file with the template this build would write.
1114
1235
  *
1115
- * The order matters. Content equality is checked first, so a byte-identical file is
1116
- * `installed` no matter what its version line says. Only then is the exact
1117
- * known-template list consulted, and only a byte-exact match to a published build is
1118
- * `outdated`. Everything else is `modified`: a body edit, a stray byte, a tampered
1119
- * or invented version line, or a file that merely looks like ours.
1236
+ * The order matters. Content equality is checked first, so a file that is the same text
1237
+ * as the template is `installed` no matter what its version line says; "the same text"
1238
+ * includes the CRLF/LF spelling, because the shipped template's terminators are not part
1239
+ * of its content (see {@link normalizeLineEndings}). Only then is the exact known-template
1240
+ * list consulted, and only a match to a published build is `outdated`. Everything else is
1241
+ * `modified`: a body edit, a stray byte, a tampered or invented version line, or a file
1242
+ * that merely looks like ours.
1243
+ *
1244
+ * `contents` is always the text EXACTLY as read, and `expect` (the status field derived
1245
+ * from it) is what the write and delete paths re-prove against, so a file rewritten
1246
+ * between the read and the write is still detected even though this classification is
1247
+ * line-ending tolerant.
1120
1248
  * @param {string} path - agent file path.
1121
1249
  * @param {string} template - template text this build would write.
1122
1250
  * @returns {Promise<{ state: string, present: boolean, reason: string | null, contents: string | null }>} agent state and the exact bytes it was derived from.
@@ -1126,7 +1254,7 @@ async function readAgentState(path, template) {
1126
1254
  if (existing.kind === 'missing') return { state: AGENT_STATES.missing, present: false, reason: null, contents: null };
1127
1255
  if (existing.kind === 'other') return { state: AGENT_STATES.conflict, present: true, reason: 'not-a-regular-file', contents: null };
1128
1256
  const contents = existing.contents;
1129
- if (contents === template) return { state: AGENT_STATES.installed, present: true, reason: null, contents };
1257
+ if (sameAgentText(contents, template)) return { state: AGENT_STATES.installed, present: true, reason: null, contents };
1130
1258
  if (isKnownPriorTemplate(contents)) return { state: AGENT_STATES.outdated, present: true, reason: null, contents };
1131
1259
  return {
1132
1260
  state: AGENT_STATES.modified,
@@ -1215,32 +1343,6 @@ function linkedBoundaryRefusal(status) {
1215
1343
  };
1216
1344
  }
1217
1345
 
1218
- /**
1219
- * Is this file one of the exact agent files an earlier release shipped?
1220
- *
1221
- * The only case where install may replace an existing file. The test is content
1222
- * identity against the enumerated digest list, which cannot be satisfied by an
1223
- * operator edit: a single changed byte changes the digest. The version line is
1224
- * deliberately *not* used as proof — an operator can edit a body while leaving (or
1225
- * lowering) that line, and a heuristic on it is exactly how a customised agent
1226
- * gets overwritten.
1227
- * @param {string} contents - installed file text.
1228
- * @param {object} [options] - `ignoreVersion`: compare with the version line masked,
1229
- * used only to explain *why* a file is `modified` in the status note.
1230
- * @returns {boolean} true when the file is a known published build of this template.
1231
- */
1232
- export function isKnownPriorTemplate(contents, { ignoreVersion = false } = {}) {
1233
- if (typeof contents !== 'string') return false;
1234
- const digestValue = digest(contents);
1235
- if (KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digestValue)) return true;
1236
- if (!ignoreVersion) return false;
1237
- // Explanation-only path: the same body with the version line stripped still has to
1238
- // match a known build, which distinguishes "operator edited a managed file" from
1239
- // "this file was never ours".
1240
- const stripped = contents.replace(VERSION_LINE, 'version = "\u0000"');
1241
- return KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digest(stripped));
1242
- }
1243
-
1244
1346
  /**
1245
1347
  * Write a file that must not exist yet, atomically and exclusively.
1246
1348
  *
@@ -2186,15 +2288,23 @@ export function removeMcpEntry(document) {
2186
2288
 
2187
2289
  /**
2188
2290
  * Render the agent file from the shipped template plus this package's version.
2291
+ *
2292
+ * The MANAGED file is written with LF terminators, whatever the template's own spelling
2293
+ * is: this repository stores `codex/dsh-taskbridge.toml` CRLF, and a renderer that echoed
2294
+ * that spelling would make the file it writes depend on the checkout it was built from.
2295
+ * Only the terminators are touched — every other byte of the body is copied verbatim
2296
+ * (spaces, tabs, blank lines, comments), and {@link readAgentTemplate} still returns the
2297
+ * template exactly as shipped, so the source TOML is never rewritten.
2189
2298
  * @param {string} template - shipped template.
2190
2299
  * @param {string} version - package version.
2191
- * @returns {string} file contents.
2300
+ * @returns {string} file contents, LF-terminated.
2192
2301
  */
2193
2302
  export function renderAgentFile(template, version) {
2194
2303
  const marker = `version = ${renderString(version)}`;
2195
- if (/^version = ".*"$/mu.test(template)) return template.replace(/^version = ".*"$/mu, marker);
2304
+ const text = normalizeLineEndings(template);
2305
+ if (/^version = ".*"$/mu.test(text)) return text.replace(/^version = ".*"$/mu, marker);
2196
2306
  // Keep the provenance header first, then the version marker, then the rest.
2197
- const lines = template.split('\n');
2307
+ const lines = text.split('\n');
2198
2308
  const insertAt = lines.findIndex((line) => line.trim() !== '' && !line.trimStart().startsWith('#'));
2199
2309
  const resolved = insertAt === -1 ? lines.length : insertAt;
2200
2310
  lines.splice(resolved, 0, marker);
package/src/mcp/server.js CHANGED
@@ -289,7 +289,11 @@ export const TOOLS = Object.freeze([
289
289
  + 'reuses that task\u2019s recorded execution checkout and DSH Session internally, taking no execution '
290
290
  + 'location from '
291
291
  + 'the caller. An unknown, unfinished, removed or differently-sourced parent is refused rather than '
292
- + 'started as a new conversation.',
292
+ + 'started as a new conversation. '
293
+ + 'The commander must first plan and scope ONE cohesive, independently verifiable work packet. '
294
+ + 'Split a separable multi-stage goal before dispatch; include the chosen approach, scope and acceptance '
295
+ + 'checks. A simple complete task may use one packet. Rules, planning and final review remain with '
296
+ + 'the commander; a verification-only packet does not authorize implementation changes.',
293
297
  // It creates work, so it is not a read; it is not destructive of anything the
294
298
  // operator already has, and repeating it creates ANOTHER task (never idempotent).
295
299
  annotations: Object.freeze({
@@ -314,7 +318,7 @@ export const TOOLS = Object.freeze([
314
318
  + 'an execution.workspacePath or any other internal execution location in its place, because a '
315
319
  + 'different source path names a different repository and the continuation is refused.',
316
320
  },
317
- prompt: { type: 'string', description: 'The task to perform.' },
321
+ prompt: { type: 'string', description: 'One commander-planned work packet: objective, chosen approach, owned files or modules, constraints and acceptance checks. Roadmap context does not authorize future packets. A verification-only assignment permits checks and evidence, not implementation edits.' },
318
322
  title: { type: 'string', maxLength: 120, description: 'Short work-content title in the operator\'s language, e.g. 修复登录错误. Used to name the new DSH Workspace; omit role instructions and task ids. A follow-up keeps its existing Workspace name.' },
319
323
  overrides: {
320
324
  type: 'object',