dsh-taskbridge 1.6.0 → 1.7.0

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +41 -41
  3. package/THIRD_PARTY_NOTICES.txt +23 -0
  4. package/codex/dsh-taskbridge.toml +140 -71
  5. package/docs/INTRODUCTION.md +44 -22
  6. package/docs/INTRODUCTION.zh.md +32 -26
  7. package/docs/codex-integration.md +90 -10
  8. package/docs/contracts-stage-b.md +4 -4
  9. package/docs/conversation-placement.md +25 -7
  10. package/docs/plugin-market.md +1 -1
  11. package/docs/releases/1.7.0.zh.md +11 -0
  12. package/docs/runtime-compatibility.md +4 -11
  13. package/docs/silent-wait.md +69 -31
  14. package/docs/taskbridge-upgrade.md +1 -1
  15. package/docs/worker-permissions.md +4 -14
  16. package/docs/workspace-grouping.md +126 -0
  17. package/lib/client.d.ts +365 -3
  18. package/lib/client.js +260 -5
  19. package/locale/en.json +1 -1
  20. package/locale/zh.json +1 -1
  21. package/package.json +7 -19
  22. package/src/client/api.js +550 -90
  23. package/src/client/index.jsx +699 -307
  24. package/src/client/sidebar.jsx +6 -5
  25. package/src/client/styles.js +251 -0
  26. package/src/client/task-cleanup.js +304 -0
  27. package/src/client/task-records-table.jsx +217 -0
  28. package/src/client/task-view.js +226 -10
  29. package/src/client/workspace-groups.js +482 -0
  30. package/src/client/workspaces-browser.jsx +770 -0
  31. package/src/codex/agent-ownership.js +270 -0
  32. package/src/codex/installer.js +525 -35
  33. package/src/codex/seam.js +5 -0
  34. package/src/config/defaults.js +63 -17
  35. package/src/config/settings.js +60 -62
  36. package/src/config/validate.js +126 -71
  37. package/src/http/respond.js +8 -0
  38. package/src/http/user-plane.js +197 -2
  39. package/src/index.js +50 -42
  40. package/src/jobs/activity.js +968 -78
  41. package/src/jobs/engine.js +784 -230
  42. package/src/jobs/history.js +188 -12
  43. package/src/jobs/plan-store.js +5 -0
  44. package/src/jobs/record-cleanup.js +196 -0
  45. package/src/jobs/task-tree.js +5 -3
  46. package/src/jobs/title.js +129 -12
  47. package/src/mcp/server.js +16 -8
  48. package/src/mcp/wait.js +64 -5
  49. package/src/runtime/agent-runner.js +53 -15
  50. package/src/runtime/worker-prompt.js +53 -0
  51. package/src/workspace/locks.js +288 -167
  52. package/docs/releases/1.4.0-token-benchmark.zh.md +0 -40
  53. package/docs/releases/1.4.0.zh.md +0 -54
  54. package/docs/releases/1.4.1.zh.md +0 -59
  55. package/docs/releases/1.4.2.zh.md +0 -23
  56. package/docs/releases/1.5.0-token-benchmark.zh.md +0 -73
  57. package/docs/releases/1.5.0.zh.md +0 -51
  58. package/docs/releases/1.5.1.zh.md +0 -70
  59. package/docs/releases/1.5.2.zh.md +0 -30
  60. package/docs/releases/1.5.3-test.1.zh.md +0 -28
  61. package/docs/releases/1.5.3-test.2.zh.md +0 -24
  62. package/docs/releases/1.5.3.zh.md +0 -33
  63. package/docs/releases/1.5.4.zh.md +0 -25
  64. package/src/review/preset.js +0 -868
  65. package/src/review/prompts.js +0 -145
  66. package/src/review/reviewer.js +0 -933
@@ -0,0 +1,270 @@
1
+ // The Codex agent-ownership record: ONE small JSON file per real Codex home, holding the
2
+ // LF-normalized SHA-256 of the agent template this plugin last proved it wrote there.
3
+ //
4
+ // Why it exists
5
+ // -------------
6
+ // Ownership of `$CODEX_HOME/agents/dsh-taskbridge.toml` is decided by CONTENT, never by the
7
+ // file name, a marker or a version line (see `src/codex/installer.js`). A template whose byte
8
+ // form was not enumerated in `KNOWN_AGENT_TEMPLATES` therefore looked like "somebody else's
9
+ // file" after an upgrade, and the plugin refused to refresh a file it had written itself.
10
+ // Enumerating every future release by hand does not scale, so this record answers the OTHER
11
+ // half of the question — "is this reachable file the current release's template?" — without
12
+ // either a per-release digest table or a heuristic on names, markers or version lines.
13
+ //
14
+ // What it is
15
+ // ----------
16
+ // `<plugin data dir>/codex-agent-ownership/<sha256 of the real home>.json`:
17
+ //
18
+ // { "schemaVersion": 1, "codexHome": "<real home>", "templateLfSha256": "<64 hex>" }
19
+ //
20
+ // * keyed by the REAL home this plugin pinned, never by a spelling of it: the file name is a
21
+ // digest of that path, so two different homes can never collide even on a case-sensitive
22
+ // filesystem, and no case equivalence is ever inferred;
23
+ // * ONE digest, LF-normalized: CRLF and LF spellings of the same text agree, and nothing else
24
+ // is normalized — an edited character, an added line, a tab or a rewritten `version` line all
25
+ // change the digest. The template body and the record hold no credentials and no config.
26
+ //
27
+ // Reading is bounded and non-creating: an absolute `DSH_HOME` or the existing default only, a
28
+ // regular file of bounded size, and every ancestor proved to be a REAL directory (a link or a
29
+ // reparse point anywhere on the way is "no record" — such a directory is never created here).
30
+ // A missing, unreadable, malformed, differently-keyed or over-sized record is NO record: the
31
+ // file is then classified exactly as before, which is what keeps an operator's file theirs.
32
+
33
+ import { createHash } from 'node:crypto';
34
+ import { lstat, readFile } from 'node:fs/promises';
35
+ import { homedir } from 'node:os';
36
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
37
+
38
+ /** Schema version of the record this module writes. */
39
+ export const OWNERSHIP_SCHEMA_VERSION = 1;
40
+
41
+ /** Directory, inside the plugin data directory, that holds one file per Codex home. */
42
+ export const OWNERSHIP_DIR_NAME = 'codex-agent-ownership';
43
+
44
+ /** A digest: lowercase hex SHA-256. */
45
+ const SHA256 = /^[0-9a-f]{64}$/u;
46
+
47
+ /** Bound on a record file this module is willing to parse (~1 KB, never content). */
48
+ const MAX_RECORD_BYTES = 4096;
49
+
50
+ /**
51
+ * The plugin's own data directory: `$DSH_HOME/data/dsh-delegate`.
52
+ *
53
+ * An ABSOLUTE `DSH_HOME` is the only accepted override — a relative one would resolve against
54
+ * the harness working directory and let the record land somewhere nobody named. Without one the
55
+ * documented `~/.dsh` default applies, exactly as for the installation record.
56
+ * @param {Record<string, string | undefined>} [env] - environment (`DSH_HOME`).
57
+ * @returns {string | null} absolute plugin data directory, or null when `DSH_HOME` is unusable.
58
+ */
59
+ export function pluginDataDirectory(env = process.env) {
60
+ const configured = typeof env.DSH_HOME === 'string' ? env.DSH_HOME.trim() : '';
61
+ if (configured === '') return join(resolve(homedir()), '.dsh', 'data', 'dsh-delegate');
62
+ if (!isAbsolute(configured)) return null;
63
+ return join(resolve(configured), 'data', 'dsh-delegate');
64
+ }
65
+
66
+ /**
67
+ * The record path for one Codex home.
68
+ *
69
+ * The file name is the digest of the REAL home path, so it identifies a directory rather than
70
+ * reproducing its spelling — no case folding, no separator guessing, no collision between two
71
+ * homes that differ only in case on a case-sensitive filesystem.
72
+ * @param {string} codexHome - the REAL (pinned) Codex home.
73
+ * @param {Record<string, string | undefined>} [env] - environment (`DSH_HOME`).
74
+ * @returns {string | null} absolute record path, or null when the data directory is unusable.
75
+ */
76
+ export function ownershipRecordPath(codexHome, env = process.env) {
77
+ const dataDir = pluginDataDirectory(env);
78
+ if (dataDir === null) return null;
79
+ if (typeof codexHome !== 'string' || codexHome.trim() === '' || !isAbsolute(codexHome)) return null;
80
+ const key = createHash('sha256').update(resolve(codexHome), 'utf8').digest('hex');
81
+ return join(dataDir, OWNERSHIP_DIR_NAME, `${key}.json`);
82
+ }
83
+
84
+ /**
85
+ * Check that every existing ancestor of `target` is a REAL directory.
86
+ *
87
+ * A link, a junction/reparse point that `lstat` reports as a directory, an unreadable level or a
88
+ * non-directory refuses the whole path. A missing level is reported as `missing` instead of
89
+ * being created, so a READ can never build the data tree it is inspecting — the writer decides
90
+ * whether to create it. The components come from the host's own path rules, so a POSIX `/`, a
91
+ * Windows drive and a UNC share all keep their root.
92
+ * @param {string} target - absolute path to inspect (the file itself is not inspected).
93
+ * @param {Function} classify - the installer's own boundary proof, bound to `lstat` and the
94
+ * platform attribute read. Injected so this module never grows a second, weaker copy of it.
95
+ * @returns {Promise<{ ok: boolean, missing: boolean, reason: string }>} verdict.
96
+ */
97
+ async function inspectRealChain(target, classify) {
98
+ const absolute = resolve(target);
99
+ const root = rootOf(absolute);
100
+ let current = root;
101
+ if ((await classify(root)) !== 'directory') return { ok: false, missing: false, reason: 'ancestor-not-a-directory' };
102
+ for (const part of absolute.slice(root.length).split(/[\\/]+/u).filter((part) => part !== '')) {
103
+ current = join(current, part);
104
+ const kind = await classify(current);
105
+ if (kind === 'directory') continue;
106
+ if (kind === 'missing') return { ok: false, missing: true, reason: 'ancestor-missing' };
107
+ if (kind === 'link') return { ok: false, missing: false, reason: 'ancestor-is-a-link' };
108
+ return { ok: false, missing: false, reason: 'ancestor-not-a-directory' };
109
+ }
110
+ return { ok: true, missing: false, reason: 'ok' };
111
+ }
112
+
113
+ /**
114
+ * The volume root of an absolute path, using the host's own rules.
115
+ * @param {string} absolute - resolved absolute path.
116
+ * @returns {string} the root (`/`, `C:\` or `\\host\share\`).
117
+ */
118
+ function rootOf(absolute) {
119
+ const drive = /^[A-Za-z]:[\\/]/u.exec(absolute);
120
+ // The separator is part of the root: without it `join('C:', 'Users')` yields `C:Users`, a
121
+ // RELATIVE path, and the walk would leave the tree it is supposed to prove.
122
+ if (drive !== null) return `${drive[0].slice(0, 2)}${drive[0][2] === '/' ? '/' : '\\'}`;
123
+ const unc = /^[\\/]{2}[^\\/]+[\\/][^\\/]+[\\/]/u.exec(absolute);
124
+ if (unc !== null) return unc[0];
125
+ return /^[\\/]/u.test(absolute) ? absolute[0] : '';
126
+ }
127
+
128
+ /**
129
+ * The template digest this plugin last proved it wrote into one Codex home, or null.
130
+ *
131
+ * Returns null — "no record" — for every case that cannot be proved: an unusable data directory,
132
+ * a path that does not exist yet, a link anywhere on the way, a file that is not a regular,
133
+ * bounded, exactly-keyed record of this home, or any I/O failure. Null only ever means the file
134
+ * on disk is classified by its content alone, never that something was adopted.
135
+ * @param {object} options - `codexHome` (real, pinned), `env`, `classify` (see {@link inspectRealChain}).
136
+ * @returns {Promise<string | null>} LF-normalized template digest, or null.
137
+ */
138
+ export async function recallTemplateDigest({ codexHome, env = process.env, classify } = {}) {
139
+ const path = ownershipRecordPath(codexHome, env);
140
+ if (path === null) return null;
141
+ if (typeof classify !== 'function') return null;
142
+ const chain = await inspectRealChain(dirname(path), classify);
143
+ if (chain.ok !== true) return null;
144
+ const info = await lstat(path).catch(() => null);
145
+ // A junction is a directory to `lstat`, and a symlink is not a regular file: both are refused.
146
+ if (info === null || info.isSymbolicLink() || !info.isFile()) return null;
147
+ if (info.size > MAX_RECORD_BYTES) return null;
148
+ let parsed;
149
+ try {
150
+ parsed = JSON.parse(await readFile(path, 'utf8'));
151
+ } catch {
152
+ return null;
153
+ }
154
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return null;
155
+ if (parsed.schemaVersion !== OWNERSHIP_SCHEMA_VERSION) return null;
156
+ // The interior must name THIS home. A record copied from another home (or hand-edited to a
157
+ // different path) therefore authorizes nothing, whatever its file name says.
158
+ if (typeof parsed.codexHome !== 'string' || resolve(parsed.codexHome) !== resolve(codexHome)) return null;
159
+ if (typeof parsed.templateLfSha256 !== 'string' || !SHA256.test(parsed.templateLfSha256)) return null;
160
+ return parsed.templateLfSha256;
161
+ }
162
+
163
+ /**
164
+ * Record the digest of the template this plugin has just proved it wrote into one home.
165
+ *
166
+ * The digest is recomputed from the CURRENT file, which the caller has already proved is exactly
167
+ * the template this build renders — never from a value the caller remembered. An unchanged
168
+ * record is not rewritten (no write, no mtime change). An unusable or unproved path writes
169
+ * nothing.
170
+ * @param {object} options - `codexHome` (real, pinned), `env`, `template` (the rendered text
171
+ * the file must equal), `readFile` (`(path) => Promise<string>`, injected for the installer's
172
+ * own compare-before-write step), `writeFileAtomic`, `classify`.
173
+ * @returns {Promise<{ ok: true, written: boolean } | { ok: false, reason: string }>} outcome.
174
+ */
175
+ export async function rememberTemplateDigest({
176
+ codexHome,
177
+ env = process.env,
178
+ template,
179
+ agentPath,
180
+ readFile: read = readFile,
181
+ writeFileAtomic,
182
+ mkdir: makeDirectory,
183
+ classify,
184
+ } = {}) {
185
+ const path = ownershipRecordPath(codexHome, env);
186
+ if (path === null) return { ok: false, reason: 'record-path-unusable' };
187
+ if (typeof template !== 'string' || template === '') return { ok: false, reason: 'no-template' };
188
+ if (typeof classify !== 'function') return { ok: false, reason: 'no-classifier' };
189
+ if (typeof writeFileAtomic !== 'function' || typeof makeDirectory !== 'function') {
190
+ return { ok: false, reason: 'no-writer' };
191
+ }
192
+ // Re-read the file NOW. If it is not exactly what this build renders, nothing is recorded:
193
+ // the proof must come from the bytes on disk, not from the caller's intention.
194
+ let current;
195
+ try {
196
+ current = await read(agentPath);
197
+ } catch {
198
+ return { ok: false, reason: 'agent-unreadable' };
199
+ }
200
+ if (current !== template) return { ok: false, reason: 'agent-not-this-template' };
201
+
202
+ const chain = await inspectRealChain(dirname(path), classify);
203
+ if (chain.ok !== true) {
204
+ if (chain.reason !== 'ancestor-missing') return { ok: false, reason: chain.reason };
205
+ // The record directory does not exist yet: create it one level at a time and re-prove.
206
+ if (!(await createArchiveDirectory(dirname(path), classify, makeDirectory))) {
207
+ return { ok: false, reason: 'record-directory-unusable' };
208
+ }
209
+ }
210
+ const document = `${JSON.stringify({
211
+ schemaVersion: OWNERSHIP_SCHEMA_VERSION,
212
+ codexHome: resolve(codexHome),
213
+ templateLfSha256: digestLf(template),
214
+ })}\n`;
215
+ const existing = await read(path).catch(() => null);
216
+ if (existing === document) return { ok: true, written: false };
217
+ try {
218
+ await writeFileAtomic(path, document);
219
+ } catch {
220
+ return { ok: false, reason: 'record-write-failed' };
221
+ }
222
+ return { ok: true, written: true };
223
+ }
224
+
225
+ /**
226
+ * Create the record directory (and any missing level of it), proving each one after creating it.
227
+ *
228
+ * Never recursive: a recursive create would walk through a link that appeared in the window.
229
+ * @param {string} directory - absolute directory to create.
230
+ * @param {Function} classify - boundary proof.
231
+ * @param {Function} makeDirectory - `mkdir(path, { mode })`.
232
+ * @returns {Promise<boolean>} whether a real directory now exists there.
233
+ */
234
+ async function createArchiveDirectory(directory, classify, makeDirectory) {
235
+ const absolute = resolve(directory);
236
+ const root = rootOf(absolute);
237
+ let current = root;
238
+ // The ROOT itself is a boundary, not a level to create: `C:\` or `/` cannot be a link this
239
+ // module may create, but a reparse point at the volume root is refused like any other.
240
+ if ((await classify(root)) !== 'directory') return false;
241
+ for (const part of absolute.slice(root.length).split(/[\\/]+/u).filter((part) => part !== '')) {
242
+ current = join(current, part);
243
+ const kind = await classify(current);
244
+ if (kind === 'directory') continue;
245
+ if (kind !== 'missing') return false;
246
+ try {
247
+ await makeDirectory(current, { mode: 0o700 });
248
+ } catch (error) {
249
+ if (error?.code !== 'EEXIST') return false;
250
+ }
251
+ if ((await classify(current)) !== 'directory') return false;
252
+ }
253
+ return true;
254
+ }
255
+
256
+ /**
257
+ * The LF-normalized SHA-256 of an agent text.
258
+ *
259
+ * Folding CRLF to LF is the ONLY tolerated difference, exactly as `isKnownPriorTemplate` treats
260
+ * the published identities: the shipped template is stored with CRLF while the managed file is
261
+ * written with LF, so the terminator spelling is not a content difference. Nothing else is
262
+ * normalized — a version line, a comment, a blank line, a tab, a trailing space or a BOM all
263
+ * survive and change the digest. A `\r` left after the fold is a character of the file, not a
264
+ * spelling, and is therefore hashed as it is.
265
+ * @param {string} text - agent file or template text.
266
+ * @returns {string} lowercase hex SHA-256.
267
+ */
268
+ export function digestLf(text) {
269
+ return createHash('sha256').update(String(text).replace(/\r\n/gu, '\n'), 'utf8').digest('hex');
270
+ }