worktrust 0.11.9 → 0.11.11

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/log-session.mjs CHANGED
@@ -67,6 +67,7 @@ import { fileURLToPath } from "node:url";
67
67
  import { createHash, createHmac, createPrivateKey, createPublicKey, randomBytes, sign as cryptoSign } from "node:crypto";
68
68
 
69
69
  import { readProjectModes, projectModeOf, confidentialPayload, CONFIDENTIAL_REPO_CODE } from "./project-modes.mjs"; import { moduleArgs, moduleExecutable, readPrivateFile, createPrivateFile } from "./package-integrity.mjs"; import { remoteSteeredOf } from "./remote-steered.mjs"; // 2026-11-07: a day steered from a phone is measured headless, steered_from "remote", never the person's hours (owner decision 1)
70
+ import { READ_FAILURES, READ_BYTES, claudeLinesFrom, fileLines, transcriptLines, sessionFinders } from "./session-readers.mjs"; // 0.11.10: the readers the hook and `look` share
70
71
 
71
72
  async function main() {
72
73
  const args = process.argv.slice(2), NODE_FLAGS = process.versions.node === "26.5.0" ? ["--no-concurrent-sparkplug"] : [];
@@ -242,128 +243,11 @@ const { stackOfFiles = () => [], displayStackOfFiles = () => [] } = (await impor
242
243
  const EXPORT_PATHS = []; for (let i = 0; i < args.length; i += 1) if (args[i] === "--export" && args[i + 1]) EXPORT_PATHS.push(args[i + 1]);
243
244
  const DATABASE_CLIENTS = ["hermes", "goose", "opencode", "openclaw", "cursor", "copilot", "gemini-cli", "ollama", "open-webui"]; // the registry's keys, the name each line carries (0.10.35: Gemini CLI; 2026-11-09: the Ollama app, Open WebUI)
244
245
  const LIVE_SOURCE = new RegExp(`^(codex|antigravity|${DATABASE_CLIENTS.join("|")}):`); // a sweep entry's id → the client it names (every database client, 0.6.16)
245
- const READER_FILES = ["project-modes.mjs", "history-outbox.mjs", "transcript-readers.mjs", "session-databases.mjs", "session-local-models.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "claude-mod.mjs", "remote-steered.mjs"]; // 0.7.4: the derived record travels with the hook; 0.10.10: the export reader; 0.10.11: the stack rules; 0.10.15: the mod
246
- /** The roots this machine's transcripts live under; a test names its own. */
247
- const claudeRoot = () => value("transcript-root") ?? join(homedir(), ".claude", "projects");
248
- const codexRoot = () => { const given = value("codex-root"); if (given) return given.replace(/^~(?=\/|$)/, homedir()); return value("transcript-root") ? null : join(homedir(), ".codex", "sessions"); };
249
- /** Every Codex rollout and Antigravity conversation on this machine, an excluded project's threads skipped by their working directory. */
250
- function* codexRollouts() {
251
- const root = codexRoot();
252
- for (const file of root ? codexRolloutFiles(root) : []) {
253
- const cwd = codexCwd(file);
254
- if (cwd && excluded(cwd)) continue;
255
- yield { id: `codex:${codexIdOf(file)}`, file };
256
- }
257
- yield* antigravityConversations();
258
- yield* databaseConversations();
259
- }
260
- /** The attended sessions of the clients that keep a database (session-databases.mjs); an excluded folder skipped. */
261
- function* databaseConversations() {
262
- const given = Object.fromEntries(DATABASE_CLIENTS.map((client) => [client, value(`${client}-root`)]).filter(([, root]) => root));
263
- for (const { client, sessionId, file, cwd, writtenAt } of databaseSessions(given, Boolean(value("transcript-root")))) {
264
- if (!(cwd && excluded(cwd))) yield { id: `${client}:${sessionId}`, file, writtenAt };
265
- }
266
- }
267
- /** Antigravity beside Codex: one transcript per conversation, its folder known only from the Stop hook. */
268
- function* antigravityConversations() {
269
- const given = value("antigravity-root");
270
- for (const { conversationId, file } of antigravityTranscripts(given || !value("transcript-root") ? antigravityRoots(given) : [])) {
271
- const { cwd } = antigravityContext(conversationId);
272
- if (!(cwd && excluded(cwd))) yield { id: `antigravity:${conversationId}`, file };
273
- }
274
- }
275
- /**
276
- * A FILE'S LINES, READ IN CHUNKS (0.10.32). A whole-file `readFileSync(file, "utf8")` throws past the longest string Node
277
- * makes (about 512 MB), and that throw was read as "this file cannot be read": the owner's VS Code session passed it on
278
- * 2026-10-18 (797 MB by 10-28) and from then on measured no day at all, live or re-measured. Read 8 MB at a time, one
279
- * line at a time; re-iterable (each pass opens the file again); null only when the file cannot be opened.
280
- */
281
- const CHUNK_BYTES = 8 << 20;
282
- /**
283
- * A READ THAT FAILS IS COUNTED, NEVER SILENT (0.10.32): a transcript that exists and cannot be opened or read to its end
284
- * is one failure. The run keeps the count in sessions.json (`npx worktrust status` says it) and tells WorkTrust the
285
- * count alone, never which file or what was in it (reportUnreadable).
286
- */
287
- const READ_FAILURES = { n: 0 };
288
- /** The bytes this run read from transcripts (the resume's own measure, below): said on stderr under WORKTRUST_HOOK_DEBUG, never sent. */
289
- const READ_BYTES = { n: 0 };
290
- /**
291
- * What a resume trusts of the bytes it does not read again: eight 4 KB samples before the offset, the first and the last of
292
- * them at its edges and six spread evenly between, hashed with the offset (32 KB read, whatever the file's length).
293
- */
294
- const EDGE_BYTES = 4096, EDGE_SAMPLES = 8;
295
- const edgesOf = (fd, end) => {
296
- const hash = createHash("sha256").update(`worktrust-read-position|${end}|`), buffer = Buffer.allocUnsafe(EDGE_BYTES);
297
- const starts = end <= EDGE_BYTES ? [0] : [...new Set(Array.from({ length: EDGE_SAMPLES }, (_, k) => Math.floor((k * (end - EDGE_BYTES)) / (EDGE_SAMPLES - 1))))];
298
- for (const from of starts) {
299
- const want = Math.min(EDGE_BYTES, end - from);
300
- let got = 0;
301
- while (got < want) { const n = readSync(fd, buffer, got, want - got, from + got); if (n <= 0) break; got += n; }
302
- READ_BYTES.n += got;
303
- hash.update(buffer.subarray(0, got));
304
- }
305
- return hash.digest("base64url").slice(0, 22);
306
- };
307
- /**
308
- * The lines from byte `from` (a line boundary), split on the newline BYTE, which no UTF-8 sequence holds, and decoded line by
309
- * line. `at`, when given, says where each yielded line starts (`at.line`) and, read through the same descriptor the lines came
310
- * from: the file's identity (`at.dev`, `at.ino`), the offset after its last newline (`at.end`, set before an unterminated last
311
- * line is yielded) and the hash of its edges before that offset (`at.hash`). `at.failed` is a read that failed (counted, as
312
- * always); `at.moved` a file that is not the one `expect` names (another identity, shorter than its offset, other bytes at its
313
- * edges): nothing is yielded and nothing counted, and the caller reads it whole.
314
- */
315
- function* chunkedLines(file, from = 0, at = null, expect = null) {
316
- let fd;
317
- try { fd = openSync(file, "r"); } catch { READ_FAILURES.n += 1; if (at) at.failed = true; return; }
318
- try {
319
- if (at || expect) {
320
- let stat; try { stat = fstatSync(fd); } catch { READ_FAILURES.n += 1; if (at) at.failed = true; return; }
321
- if (at) { at.dev = String(stat.dev); at.ino = String(stat.ino); }
322
- if (expect) {
323
- let same = false;
324
- try { same = String(stat.dev) === expect.dev && String(stat.ino) === expect.ino && stat.size >= expect.end && expect.end >= from && (expect.end === 0 ? expect.hash === null : edgesOf(fd, expect.end) === expect.hash); } catch { same = false; }
325
- if (!same) { if (at) at.moved = true; return; }
326
- }
327
- }
328
- const buffer = Buffer.allocUnsafe(CHUNK_BYTES);
329
- let pending = [], position = from, lineStart = from;
330
- for (;;) {
331
- let n;
332
- try { n = readSync(fd, buffer, 0, CHUNK_BYTES, position); } catch { READ_FAILURES.n += 1; if (at) at.failed = true; return; }
333
- if (n <= 0) break;
334
- READ_BYTES.n += n;
335
- const chunk = buffer.subarray(0, n);
336
- let start = 0;
337
- for (let nl = chunk.indexOf(10); nl !== -1; nl = chunk.indexOf(10, start)) {
338
- const text = pending.length > 0 ? Buffer.concat([...pending, chunk.subarray(start, nl)]).toString("utf8") : chunk.toString("utf8", start, nl);
339
- pending = [];
340
- if (at) at.line = lineStart;
341
- lineStart = position + nl + 1; start = nl + 1;
342
- yield text;
343
- }
344
- if (start < n) pending.push(Buffer.from(chunk.subarray(start)));
345
- position += n;
346
- }
347
- if (at) { at.end = lineStart; try { at.hash = lineStart > 0 ? edgesOf(fd, lineStart) : null; } catch { READ_FAILURES.n += 1; at.failed = true; } }
348
- const rest = pending.length > 0 ? Buffer.concat(pending).toString("utf8") : "";
349
- if (rest) { if (at) at.line = lineStart; yield rest; }
350
- } finally { closeSync(fd); }
351
- }
352
- /** A Claude Code transcript's lines as objects from byte `from`, `at` and `expect` as chunkedLines takes them. */
353
- function* claudeLinesFrom(file, from, at, expect) { for (const raw of chunkedLines(file, from, at, expect)) { if (!raw.trim()) continue; let line; try { line = JSON.parse(raw); } catch { continue; } yield line; } }
354
- const fileLines = (file) => {
355
- try { closeSync(openSync(file, "r")); } catch (error) { if (error?.code !== "ENOENT") READ_FAILURES.n += 1; return null; }
356
- return { [Symbol.iterator]: () => chunkedLines(file) };
357
- };
358
- /** A transcript's lines as objects, whichever client wrote it; null when the file cannot be read. A Claude Code transcript is parsed lazily, as it is read. */
359
- const parsedLines = (file) => {
360
- if (DATABASE_SESSION.test(file)) return databaseLines(file);
361
- const lines = fileLines(file);
362
- if (!lines) return null;
363
- if (CODEX_ROLLOUT.test(file)) return [...codexLines(lines)];
364
- if (ANTIGRAVITY_TRANSCRIPT.test(file)) { const id = antigravityIdOf(file); return [...antigravityLines(lines, { id, ...antigravityContext(id) })]; }
365
- return { *[Symbol.iterator]() { for (const raw of lines) { if (!raw.trim()) continue; try { yield JSON.parse(raw); } catch { /* a torn line */ } } } };
366
- };
246
+ const READER_FILES = ["project-modes.mjs", "history-outbox.mjs", "transcript-readers.mjs", "session-readers.mjs", "session-databases.mjs", "session-local-models.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "claude-mod.mjs", "remote-steered.mjs"]; // 0.7.4: the derived record travels with the hook; 0.10.10: the export reader; 0.10.11: the stack rules; 0.10.15: the mod
247
+ // THE SESSION READERS (0.11.10: split into session-readers.mjs unchanged, shared with `npx worktrust look`): reading a session file
248
+ // in chunks, the failures counted, and finding every AI app's sessions, an excluded project skipped before a file is opened.
249
+ const parsedLines = transcriptLines({ DATABASE_SESSION, databaseLines, CODEX_ROLLOUT, codexLines, ANTIGRAVITY_TRANSCRIPT, antigravityIdOf, antigravityLines, antigravityContext });
250
+ const { claudeRoot, codexRoot, allTranscripts, candidates } = sessionFinders({ value, excluded, DATABASE_CLIENTS, codexRolloutFiles, codexCwd, codexIdOf, antigravityRoots, antigravityTranscripts, antigravityContext, databaseSessions });
367
251
  /** The coupling Codex holds, when Claude Code holds none: the same door, read from ~/.codex/config.toml. */
368
252
  function codexCoupling() {
369
253
  let toml; try { toml = readFileSync(join(homedir(), ".codex", "config.toml"), "utf8"); } catch { return null; }
@@ -1489,53 +1373,6 @@ function folderEntries(given) {
1489
1373
  return { entries: entries.sort((a, b) => a.at.localeCompare(b.at)), report: { stretches: report.stretches, skipped: report.skipped, days: days.length, first: days[0] ?? null, last: days.at(-1) ?? null } };
1490
1374
  }
1491
1375
 
1492
- /** Every transcript this machine holds, excluded projects skipped before a file is opened. */
1493
- function* allTranscripts() {
1494
- const root = claudeRoot();
1495
- if (existsSync(root)) for (const dir of readdirSync(root)) {
1496
- if (excluded(dir)) continue;
1497
- let files;
1498
- try { files = readdirSync(join(root, dir)); } catch { continue; }
1499
- for (const file of files) if (file.endsWith(".jsonl")) yield { id: file.replace(/\.jsonl$/, ""), file: join(root, dir, file) };
1500
- }
1501
- yield* codexRollouts();
1502
- }
1503
-
1504
- /**
1505
- * EVERY TRANSCRIPT, with what it was last written. The two filters that used to live here decided
1506
- * the wrong thing at the wrong level:
1507
- *
1508
- * - "idle 30 minutes" skipped the file being typed into, and with it every earlier day of a
1509
- * session that has been open for a fortnight. Whether a DAY is finished is a fact about the day.
1510
- * - "not older than 48 hours" skipped the machine that was closed for four months, which is
1511
- * exactly the person whose work needs collecting when they come back.
1512
- *
1513
- * The caller opens a file only when it has been written since the watermark says we last read it,
1514
- * so a sweep over a hundred transcripts costs a hundred `stat` calls and nothing more.
1515
- */
1516
- function* candidates() {
1517
- for (const rollout of codexRollouts()) {
1518
- if (rollout.writtenAt) { yield rollout; continue; } // a database session knows its own last moment
1519
- let stat; try { stat = statSync(rollout.file); } catch { continue; }
1520
- yield { ...rollout, writtenAt: stat.mtimeMs };
1521
- }
1522
- const root = claudeRoot();
1523
- if (!existsSync(root)) return;
1524
- for (const dir of readdirSync(root)) {
1525
- if (excluded(dir)) continue;
1526
- const path = join(root, dir);
1527
- let files;
1528
- try { files = readdirSync(path); } catch { continue; }
1529
- for (const file of files) {
1530
- if (!file.endsWith(".jsonl")) continue;
1531
- const full = join(path, file);
1532
- let stat;
1533
- try { stat = statSync(full); } catch { continue; }
1534
- yield { id: file.replace(/\.jsonl$/, ""), file: full, writtenAt: stat.mtimeMs };
1535
- }
1536
- }
1537
- }
1538
-
1539
1376
  function hookInput() {
1540
1377
  // Only when something was piped in. Reading fd 0 on a terminal waits for an EOF that never
1541
1378
  // comes, and a hook that hangs is worse than one that does nothing. A dry run READS it, so the
@@ -1 +1 @@
1
- {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"e8abb38c293b57b71d3a6163d6242d1f375e773372b91b6d8ce39c584c51262a","CHANGELOG.md":"3cae60d5eb0302bdcd0c737cc594677ddc8151359bfd3538d6707800225d35fd","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"8d0383d51db8bb0959eb3fa4eab482337c58492b254406c519e562911537d35f","README.md":"dd395252638bd253766b6b3bfe2362b687e86a17825982432245dcc776206a03","SECURITY.md":"6a798d875f48ae84c3a677397e5611e03b94215944952e0f61e13f6cfc949745","chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","cli-colour.mjs":"fa16b61ad179999c5c5365255182acf69bcba1eb5f5ce7b0e1e18c11f56130ae","cli-menu-remote.mjs":"4f7284911d86e4463797e7dec976c4c10f46e6fdb3053c5ad211210e1efe25e5","cli-menu.mjs":"09eed126c220ffdfba8fedd7f2730ddcbc75471c31dcb5ce066c02592aa3b3b9","commit-rules.mjs":"e94cc32a5415f6d9e978145ab9505ac4ae0bac9431e6e9104b9b37155260b51f","config-edits.mjs":"527a7674f9d52b284bfda3b8089eb4b930a709bf14aedbec7f6eef1e59ef52ee","count-behaviour.mjs":"06b0ecbc222087160dc64c0b302391631e8e799038364c317c6cd28449c5044d","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","engine-release.json":"8d97ea82525b5fcc6680fc8255caabc7ab68f4b04977b0e60e1326e09c6afed5","export-facts.mjs":"3bbb46c80e8678b5cea7e15dcbfc456a2b48595053241c2b3cea508092f9b917","folder-picker.mjs":"daeb379626d5716f91f588064c6b4083618279320c006c177960cc93f056d96a","git-commits.mjs":"af0ed45a2a42c8e17cabfb3649a2f524dbf80230f8a6ec1c6b775fed7d34dc9c","history-outbox.mjs":"85c70389effc5b4ec9d9b33af9192314e67f47af2752515b42a7959344ce2354","history-progress.mjs":"dcc25ee94b727f2605a763349a4d8764640335d6cf0043fb6108cebeed16dcb9","log-session.mjs":"167fe3718415fe690c9e4f7a3a993520e8c652edcf61184cc14cfec2db67d7bc","node-guide.mjs":"5bf52c5028b07a80ec4d41be365eb025dfce74328f41f928a26ce6737b1f9cc4","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"0c8c690398d7bde34ddd45ae0f73bdf0546e8bc5f71cbf2de1f1db5d9092f5dc","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"cd111cae0f53a25a2d878a158479abfb1ace353361454843f91a16d241101d46","project-modes.mjs":"ada26e68297fbeb90e4e91d75a90fd2d7cc107b999a9702840675b5a7529463e","remote-adapter-claude-code.mjs":"6db24891f7b0c56c00b337e52f4d4aeb8c9a0413b3bf46d0fc8a45328ea71b3e","remote-adapter-codex.mjs":"d2fd6c61d9e3c4a45e9b10da1aa3c15d45c86629d6456e4a8d25ad95b13eb209","remote-adapter-opencode.mjs":"ddd7f3ec0b4ba92f4744453d60fda338b63550e3ec7b23fa3acc668df1d64eb7","remote-adapter-terminal.mjs":"9237d3747a25126fcdad42c0eab10e69393754388a6014b30fb0890b9c735888","remote-admin.mjs":"ac4d434c0a374159b27accac3fdd0324ff96ffe32227fba054cc62d00e58d35b","remote-agent-switch.mjs":"7ff5448f29f05a47d7298d730b21243a1bcf8a215b434a0c7fbf5f3cb0889041","remote-approval-bridge.mjs":"092f17b7969e4f35bea064315d04dcde1faa6a3fd3e737dcc05aece82c7a37c4","remote-approvals.mjs":"63847226e398f9eb5b8d3989ba2b2436fbedd898385eb5f2f63bbdf07fbe6852","remote-attachments.mjs":"2e9c1277329a45cf26c0c62abda632cf0ab9fad78d0504416ecee9805220e16c","remote-cdp.mjs":"70e333a1ebe845e872cc3a703a0a507391f8ce59640bdbd662bdad55eeff216b","remote-changes.mjs":"2141fece4961a5bc1bb1b046f78222812617457b1ba6452275eac6a897e62e19","remote-claude-events.mjs":"58822471203c6a1b66cf81c115c4d713657c3dea5c7b98df959f894ee5b2e704","remote-claude-progress.mjs":"2ca626d3dbc16d8d570abe1df6477b7e44ffb43c1d9145228ec5ea1928e415ca","remote-cli.mjs":"651a7f16e7475029985007ea97f4b838f8378ab620d3f3c2ab718da155fce94d","remote-coalesce.mjs":"cb0967d9cfe81e3892bcade8349d6814db98be8c2adbdb54df0b8d1b142f65d1","remote-codex-events.mjs":"58657d6070a50c837737cb85f5a1eaf9c2cbc4e1adfe3e970748ab3b2af94631","remote-connections.mjs":"e24ff04ed61647e164b6f055d4f691366f3204fe445140afc5f34abbed5d4080","remote-countdown.mjs":"85cf2d01fe5ca49895e08a3d5de346bb5e4a8dd31b9fda3fd9f9534d9e1e47cf","remote-daemon.mjs":"94d4896b0e1203f7a5bc7224a6221a36f4c20be89caee78b3ab37b9b6a2dac1d","remote-endorse.mjs":"89eda4883567176703e01e44d83e987271bc2a6134e108f517b3b213719a21f9","remote-inventory.mjs":"a8245604d41373819738eaf06ec1d2242cb5f7b2e60aa316f31d2f8742b8c70d","remote-journal.mjs":"907ebd48c53162b22dc743ef95b53c1a6be6886a7495605b5cfa820b8de9d330","remote-live-preview.mjs":"faa70f9260ac05037204c2a0c3facf4ffe42f68408948390b341b453a2932289","remote-opencode-events.mjs":"3108375501ead2c2c78bce1435cc2a9fe6d2af1d7ff1fb42e12ff3e0f5d9af9c","remote-opencode-session.mjs":"681b201d833a7d7d025122b3a79663bcdc0a989aefd39d8018a28113d8810caf","remote-pairing.mjs":"d8c2aba394fe73d850ea000c758e6b926c87b122eaf5c6aa92ec1183e90f90e1","remote-pipeline-config.mjs":"00cde6a61ce21144c51ac56fce42fee159aa9dba6586218a7ea790ce4a6bd40b","remote-pipeline-parsers.mjs":"43ca0d332d7bc883c4759a754a555815ae5dfe133446b91ba9f2e48a350fa20f","remote-pipeline.mjs":"b856ead989b29ddb618ef69bbacd104bae2b02c9d1c5214291d08ce469a8b24e","remote-policy.mjs":"16ea015ad5de3c357bce730ea8ea98571dc981d8591fb5156b1941b2c557a381","remote-preview.mjs":"fe504ad6f83dcb4a4ebdcc018686a9a5a900c47cdf8c45b75e7d02e2f3056155","remote-projects.mjs":"ec8c530ad3e880bca21a4d4078ecd68b6aaafcc442b50087127868d952034d5f","remote-protocol.mjs":"93f8c2031895d4e01006a1951d7c0e79ef71b86b2777eed5dfa966ab131e446d","remote-qr.mjs":"b80e2b4a5bc020cf6ed92e91d06b327cb5197de1c35b3445a0fc2c7a3bf1ab3f","remote-release-plans.mjs":"11884a62b7d6dcccb5e154a26603bdf650f7b40f946329fb174d8c13729bec74","remote-releases.mjs":"fb08b72593ea00013c8b679e0c0d7dee95b0fd7cc5fd31b80ac575d0e340927d","remote-run.mjs":"c180c401613e0c01dfc471bb6226ebb035a7299839f81c6e38ff714d75d68c3f","remote-screen-approvals.mjs":"c43ab286d36a38d17639d155782ffa017f1a9b6806a09b82ed0142a1290b6000","remote-screen-push.mjs":"4ee8bd48d24b2c87581e9f33d8354a86381f7febd82f89ed509a7a87c1442608","remote-screen-states.mjs":"7c3c86a584bebf52461f3cab39c05ea2a13910061704d48fc622956e842940f7","remote-service.mjs":"a3a5502e0f6f43b04e37ee778f43d88f4c219776439cfed0d8fa0b511e0c9637","remote-session-list.mjs":"494fdbe20f0542806ac6c42ad149c52e2d3ace23a3a7567f96dc7e80d092c727","remote-sessions.mjs":"1efb7869cef6090cbbeae15ff1e5ffe99dca3742f9c245686d6758bb705587d6","remote-settings.mjs":"ca16f39416a457bd5ceb1df847596e1b4bcd2894310eb6514664a619dee4981f","remote-steered.mjs":"d7afde92c62c87abbdb84b0cfea2eea4752e90a2e453e52a54812c4fe0395190","remote-steering.mjs":"7ba22e6110cea3ac75a4f084f8f92a5bd90c31a19d3ce58a88a0843bdadea834","remote-store.mjs":"7226d006d03788ea2a8de30226ab5f6bf45b1bcbb10ee7d4e28bf2c3cca5a2a7","remote-terminal-cli.mjs":"82a048b75e412d0b6db076afbb84cab7c754dec72b6c8b6af4d4906b38e988a7","remote-terminal-sessions.mjs":"6ab51824890a18768d23cedc499f3840b2b02a8ed651463c1fe2d74dd352a361","remote-transport.mjs":"68650fd77ea09b5762377f87cabdc1c73a34d77324aa5bf0cd9742094a50c32b","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","self-update.mjs":"378e3620d48c72cf0bf812be408883b995cdb2223de34a20f762dd73eeffb258","session-databases.mjs":"a16ffbc50ccc0e78f370ebe07f871d1a80f1977472e478e3599e7abfdc90c1b7","session-local-models.mjs":"bacd38ff8dd3056b552982ec52eb57c7b8ca86e1a46cd4cba30fc340e3e28fd4","setup-mcp.mjs":"b732e3dd9b3e522b7cc8acf167ce28ba8f1a8dee797ee15bd7c3b02919b13e6f","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"e9f20415c2b5d62a09f35a63075002ebd1da56edb32f242d52822d58ecbd8ac3","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"e2ac72ef0f14bb8b8f756f67c65b6adc88bc899e2794e8f0edcf305290ab7f33"},"format":"worktrust-package/1","kind":"npm","version":"0.11.9"},"signature":"9_ypkspVXoOYgaTLdv4CCVZ0IOr5m9RLTjtNVLFw_cl0VaVPbStkxGx9OuPFDcLX7kcP0jt2_EyE6GjaRiKdAw"}
1
+ {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"e8abb38c293b57b71d3a6163d6242d1f375e773372b91b6d8ce39c584c51262a","CHANGELOG.md":"33d0abeeb265d7acd6d8c4d6b4256c2c77238262d1a5bd114f7ffce910724148","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"eb210c9cab5dbb6a2c293a003a7604e7fb6e5f7b95ab22b382171dc7adeed41a","README.md":"897ec58b3ae18d0997b97378f4de0119c4aca5f012ca12436b39c483679eea76","SECURITY.md":"6a798d875f48ae84c3a677397e5611e03b94215944952e0f61e13f6cfc949745","chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","cli-colour.mjs":"fa16b61ad179999c5c5365255182acf69bcba1eb5f5ce7b0e1e18c11f56130ae","cli-look.mjs":"1bcc1314f53a4b886d19ac7a4eb4010b5e86d9e00b8e880ccbcd43f515c6dfd9","cli-menu-remote.mjs":"8e933adf5c849f28cd1fcec879ff8480794a15d34a6be25585e68454d8512bf6","cli-menu.mjs":"67928264a9cb7fcf4a4bb2ee546cba1eee36c180ea76bd669834c33d9508fc89","commit-rules.mjs":"e94cc32a5415f6d9e978145ab9505ac4ae0bac9431e6e9104b9b37155260b51f","config-edits.mjs":"527a7674f9d52b284bfda3b8089eb4b930a709bf14aedbec7f6eef1e59ef52ee","count-behaviour.mjs":"06b0ecbc222087160dc64c0b302391631e8e799038364c317c6cd28449c5044d","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","engine-release.json":"703167caac49c4f0a0413ef6f159be0757f222c7292520ac874774051573e5ab","export-facts.mjs":"3bbb46c80e8678b5cea7e15dcbfc456a2b48595053241c2b3cea508092f9b917","folder-picker.mjs":"daeb379626d5716f91f588064c6b4083618279320c006c177960cc93f056d96a","git-commits.mjs":"af0ed45a2a42c8e17cabfb3649a2f524dbf80230f8a6ec1c6b775fed7d34dc9c","history-outbox.mjs":"85c70389effc5b4ec9d9b33af9192314e67f47af2752515b42a7959344ce2354","history-progress.mjs":"dcc25ee94b727f2605a763349a4d8764640335d6cf0043fb6108cebeed16dcb9","log-session.mjs":"171f4abb0d603d58446129e007de9e9dc0f707bde33b1b4481a134376ed301c8","node-guide.mjs":"5bf52c5028b07a80ec4d41be365eb025dfce74328f41f928a26ce6737b1f9cc4","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"d990b5a01958c88c33f2ba12994b854c058a079b08220636859c49d177ed5b2f","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"cd111cae0f53a25a2d878a158479abfb1ace353361454843f91a16d241101d46","project-modes.mjs":"ada26e68297fbeb90e4e91d75a90fd2d7cc107b999a9702840675b5a7529463e","remote-adapter-claude-code.mjs":"d0558bb123a29a934db1bf8162e7c3f37e8ccde4c502178d47e9b4cbb3a0491b","remote-adapter-codex.mjs":"0370611044e6f5f6ef3ca370e0f6ef237468f01ecc890b019da8167730eb75eb","remote-adapter-opencode.mjs":"062c571cc4ab972412044066c236a9f20794cfb841c66cc9c0e9e5ec1133699e","remote-adapter-terminal.mjs":"c047a362474abb90b7968b8a624358af40a989ad137166a03bc955409ff1dc82","remote-admin.mjs":"ac4d434c0a374159b27accac3fdd0324ff96ffe32227fba054cc62d00e58d35b","remote-agent-switch.mjs":"7ff5448f29f05a47d7298d730b21243a1bcf8a215b434a0c7fbf5f3cb0889041","remote-approval-bridge.mjs":"092f17b7969e4f35bea064315d04dcde1faa6a3fd3e737dcc05aece82c7a37c4","remote-approvals.mjs":"63847226e398f9eb5b8d3989ba2b2436fbedd898385eb5f2f63bbdf07fbe6852","remote-attachments.mjs":"2e9c1277329a45cf26c0c62abda632cf0ab9fad78d0504416ecee9805220e16c","remote-cdp.mjs":"70e333a1ebe845e872cc3a703a0a507391f8ce59640bdbd662bdad55eeff216b","remote-changes.mjs":"2141fece4961a5bc1bb1b046f78222812617457b1ba6452275eac6a897e62e19","remote-claude-events.mjs":"58822471203c6a1b66cf81c115c4d713657c3dea5c7b98df959f894ee5b2e704","remote-claude-progress.mjs":"2ca626d3dbc16d8d570abe1df6477b7e44ffb43c1d9145228ec5ea1928e415ca","remote-cli.mjs":"fa3ada1e8845855789d61daac8c69853d81dcde25dfbffc223d6fed17c7efa94","remote-coalesce.mjs":"cb0967d9cfe81e3892bcade8349d6814db98be8c2adbdb54df0b8d1b142f65d1","remote-codex-events.mjs":"58657d6070a50c837737cb85f5a1eaf9c2cbc4e1adfe3e970748ab3b2af94631","remote-connections.mjs":"1863863930f6df968084571be16c2382fbb0ba3ae64e26a9f9c90a7f9bf0b157","remote-countdown.mjs":"85cf2d01fe5ca49895e08a3d5de346bb5e4a8dd31b9fda3fd9f9534d9e1e47cf","remote-daemon.mjs":"e7e02ded144990ab45da66466804f58f764ba187b729fa040c8743acca6f6f0e","remote-endorse.mjs":"89eda4883567176703e01e44d83e987271bc2a6134e108f517b3b213719a21f9","remote-inventory.mjs":"98a65a066772ef183f405a1455c02db6827f06e80ed601796c65c19f9be10f09","remote-journal.mjs":"907ebd48c53162b22dc743ef95b53c1a6be6886a7495605b5cfa820b8de9d330","remote-live-preview.mjs":"faa70f9260ac05037204c2a0c3facf4ffe42f68408948390b341b453a2932289","remote-opencode-events.mjs":"3108375501ead2c2c78bce1435cc2a9fe6d2af1d7ff1fb42e12ff3e0f5d9af9c","remote-opencode-session.mjs":"681b201d833a7d7d025122b3a79663bcdc0a989aefd39d8018a28113d8810caf","remote-pairing.mjs":"f42bfb9c0b19ba3363c7b1c3d98cbd01c2bc7856acd763bf9e8ee53fefeccf2a","remote-pipeline-config.mjs":"00cde6a61ce21144c51ac56fce42fee159aa9dba6586218a7ea790ce4a6bd40b","remote-pipeline-parsers.mjs":"43ca0d332d7bc883c4759a754a555815ae5dfe133446b91ba9f2e48a350fa20f","remote-pipeline.mjs":"b856ead989b29ddb618ef69bbacd104bae2b02c9d1c5214291d08ce469a8b24e","remote-policy.mjs":"16ea015ad5de3c357bce730ea8ea98571dc981d8591fb5156b1941b2c557a381","remote-preview.mjs":"fe504ad6f83dcb4a4ebdcc018686a9a5a900c47cdf8c45b75e7d02e2f3056155","remote-projects.mjs":"ec8c530ad3e880bca21a4d4078ecd68b6aaafcc442b50087127868d952034d5f","remote-protocol.mjs":"a48c96b30172004623a228d126309623280456793cc26c1ac232e737717e26c7","remote-qr.mjs":"73e7743c33e35b1b01d6df3260e876beab419179265aa201a101596b4a813d86","remote-release-plans.mjs":"11884a62b7d6dcccb5e154a26603bdf650f7b40f946329fb174d8c13729bec74","remote-releases.mjs":"fb08b72593ea00013c8b679e0c0d7dee95b0fd7cc5fd31b80ac575d0e340927d","remote-run.mjs":"5dce92062a4e5073b17860223bf1fc7362a23c620d81c8df535b8a580f590fe8","remote-screen-approvals.mjs":"c43ab286d36a38d17639d155782ffa017f1a9b6806a09b82ed0142a1290b6000","remote-screen-push.mjs":"4ee8bd48d24b2c87581e9f33d8354a86381f7febd82f89ed509a7a87c1442608","remote-screen-states.mjs":"7c3c86a584bebf52461f3cab39c05ea2a13910061704d48fc622956e842940f7","remote-service.mjs":"a3a5502e0f6f43b04e37ee778f43d88f4c219776439cfed0d8fa0b511e0c9637","remote-session-list.mjs":"494fdbe20f0542806ac6c42ad149c52e2d3ace23a3a7567f96dc7e80d092c727","remote-sessions.mjs":"c4055a1e08e929319f10b309ab5a9c42b78127b744f4df7d128bdc7d10ea951c","remote-settings.mjs":"ca16f39416a457bd5ceb1df847596e1b4bcd2894310eb6514664a619dee4981f","remote-steered.mjs":"d7afde92c62c87abbdb84b0cfea2eea4752e90a2e453e52a54812c4fe0395190","remote-steering.mjs":"593447f3b7abbf3b91237d6d8a1aebcce9fbddc5ea5874341241ee45d83e5196","remote-store.mjs":"592a87f0ab8f53cc8eee1318a309310e27cb01d4549caebad6d51c3fad1b75ac","remote-terminal-cli.mjs":"82a048b75e412d0b6db076afbb84cab7c754dec72b6c8b6af4d4906b38e988a7","remote-terminal-sessions.mjs":"6ab51824890a18768d23cedc499f3840b2b02a8ed651463c1fe2d74dd352a361","remote-transport.mjs":"68650fd77ea09b5762377f87cabdc1c73a34d77324aa5bf0cd9742094a50c32b","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","self-update.mjs":"378e3620d48c72cf0bf812be408883b995cdb2223de34a20f762dd73eeffb258","session-databases.mjs":"a16ffbc50ccc0e78f370ebe07f871d1a80f1977472e478e3599e7abfdc90c1b7","session-local-models.mjs":"bacd38ff8dd3056b552982ec52eb57c7b8ca86e1a46cd4cba30fc340e3e28fd4","session-readers.mjs":"14cbd2c92d87511b396feaa54710f00d5e3929b55e01dc559f39c5def13777a2","setup-mcp.mjs":"b732e3dd9b3e522b7cc8acf167ce28ba8f1a8dee797ee15bd7c3b02919b13e6f","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"3dfdd9d2189063f24dbd5c2abec6bb21e2bb36f22b89d0d84282e12216022670","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"5cb20c2f9d99969633b0060309232d0df362a4a6fd57659cbdc8fda4b774cd52"},"format":"worktrust-package/1","kind":"npm","version":"0.11.11"},"signature":"uEUw7UtAUairrKuQidJDfMFPGZH6gYoTJYEb6xSC18Sf0HJOUc7w9PMZTCotikJr4VEWIde1nAkDSFXK0wlcAw"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worktrust",
3
- "version": "0.11.9",
3
+ "version": "0.11.11",
4
4
  "description": "Couple this computer to WorkTrust: approve a code in your browser, and every AI app here reports what you built. Metadata only, no dependencies.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,6 +12,7 @@
12
12
  "log-session.mjs",
13
13
  "count-behaviour.mjs",
14
14
  "transcript-readers.mjs",
15
+ "session-readers.mjs",
15
16
  "session-databases.mjs",
16
17
  "session-local-models.mjs",
17
18
  "config-edits.mjs",
@@ -97,6 +98,7 @@
97
98
  "cli-menu.mjs",
98
99
  "cli-menu-remote.mjs",
99
100
  "cli-colour.mjs",
101
+ "cli-look.mjs",
100
102
  "node-guide.mjs",
101
103
  "remote-countdown.mjs",
102
104
  "remote-connections.mjs",
@@ -15,9 +15,11 @@
15
15
  * The approval tool is remote-approval-bridge.mjs, started by Claude Code itself from the MCP config written here.
16
16
  */
17
17
  import { spawn } from "node:child_process";
18
- import { writeFileSync, rmSync } from "node:fs";
19
- import { isAbsolute } from "node:path";
18
+ import { readFileSync, writeFileSync, rmSync } from "node:fs";
19
+ import { homedir } from "node:os";
20
+ import { isAbsolute, join } from "node:path";
20
21
  import { PLAN_HINT } from "./remote-approval-bridge.mjs";
22
+ import { REVIEWED_COMMANDS } from "./remote-policy.mjs";
21
23
 
22
24
  export const APPROVAL_TOOL = "mcp__worktrust_remote__approve";
23
25
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
@@ -38,8 +40,32 @@ export const REMOTE_DENY = Object.freeze([
38
40
  "Bash(vercel:*)", "Bash(netlify:*)", "Bash(fly:*)", "Bash(flyctl:*)", "Bash(firebase:*)", "Bash(heroku:*)", "Bash(wrangler:*)", "Bash(kubectl:*)", "Bash(helm:*)", "Bash(terraform:*)", "Bash(pulumi:*)", "Bash(eas:*)",
39
41
  "Bash(rm -rf:*)", "Bash(sudo:*)", "Read(**/.env)", "Read(**/.env.*)", "Read(~/.ssh/**)", "Read(**/*.pem)", "Read(**/*.key)", "Read(~/.aws/**)", "Read(~/.worktrust/**)",
40
42
  "Edit(~/.worktrust/**)", "Write(~/.worktrust/**)", "Edit(**/.env)", "Edit(**/.env.*)",
43
+ // NO SHIP SCRIPT FROM A PHONE (review 2026-11-14, S0): a script run through a shell, a ship's yes, the release scripts, a
44
+ // GitHub release or workflow, the database. Deploy and publish are started at the desk, never from the phone.
45
+ "Bash(zsh:*)", "Bash(bash:*)", "Bash(sh:*)", "Bash(SHIP_YES=1:*)", "Bash(node scripts/deploy-production.mjs:*)", "Bash(node scripts/mobile-update.mjs:*)",
46
+ "Bash(gh release:*)", "Bash(gh workflow:*)", "Bash(psql:*)",
41
47
  ]);
42
48
 
49
+ /**
50
+ * THE PERSON'S OWN BASH ALLOW RULES ARE DESK GRANTS (review 2026-11-14, S0). `--setting-sources user` still loads the user's
51
+ * settings (`$CLAUDE_CONFIG_DIR/settings.json`, else ~/.claude/settings.json), and their `permissions.allow` apply BEFORE the
52
+ * permission-prompt tool: `Bash(zsh ~/.config/…/ships/*)`, `Bash(node scripts/deploy-production.mjs*)` would run from a phone
53
+ * prompt, or a repository's hidden instruction, with no approval at all. So every Bash allow rule that is not a reviewed
54
+ * command (remote-policy.mjs REVIEWED_COMMANDS, with or without `:*`) comes back as a DENY for the remote session (deny beats
55
+ * allow). The file is only READ, at the session's start, never written. Missing: nothing to deny. Unreadable or not JSON:
56
+ * the allows are not known, so the session gets no shell at all (`Bash`).
57
+ */
58
+ export function userAllowDenies({ env = process.env, home = homedir(), read = (file) => readFileSync(file, "utf8") } = {}) {
59
+ const file = join(env.CLAUDE_CONFIG_DIR || join(home, ".claude"), "settings.json");
60
+ let text;
61
+ try { text = read(file); } catch (error) { return error?.code === "ENOENT" ? [] : ["Bash"]; }
62
+ let allow;
63
+ try { allow = JSON.parse(text)?.permissions?.allow ?? []; } catch { return ["Bash"]; }
64
+ if (!Array.isArray(allow)) return ["Bash"];
65
+ const reviewed = new Set(REVIEWED_COMMANDS.flatMap((line) => [`Bash(${line})`, `Bash(${line}:*)`]));
66
+ return [...new Set(allow.filter((rule) => typeof rule === "string" && /^Bash(\(|$)/.test(rule.trim()) && !reviewed.has(rule.trim())).map((rule) => rule.trim()))];
67
+ }
68
+
43
69
  /** The planning tools of the session's own MCP server (remote-approval-bridge.mjs): they only write a plan, so no prompt. */
44
70
  export const PLAN_TOOLS = Object.freeze(["mcp__worktrust_remote__plan_release", "mcp__worktrust_remote__plan_task", "mcp__worktrust_remote__plan_list"]);
45
71
  /** The one line the session's system prompt gains (owner, 2026-11-08: the agent arranges its own work); one text, the bridge's. */
@@ -59,7 +85,7 @@ export const EDIT_MODE_DENY = Object.freeze(["**/.claude/**", "**/.mcp.json", "*
59
85
  /** The agent mode (protocol AGENT_MODES; the older `ask` is `manual`) → Claude Code's own permission mode, from its help. */
60
86
  const PERMISSION_OF = { ask: "askMode", manual: "askMode", plan: "planMode", edit: "editMode", auto: "autoMode" };
61
87
 
62
- export function claudeArgs({ features, mode, model, resume, sessionRef, mcpConfig, effort = null, addDirs = [] }) {
88
+ export function claudeArgs({ features, mode, model, resume, sessionRef, mcpConfig, effort = null, addDirs = [], userDenies = userAllowDenies() }) {
63
89
  if (!Object.hasOwn(PERMISSION_OF, mode)) throw new Error("the protocol offers the manual, edit, plan and auto modes only");
64
90
  const permission = features[PERMISSION_OF[mode]];
65
91
  if (!permission) throw new Error("this Claude Code offers no such permission mode");
@@ -73,7 +99,7 @@ export function claudeArgs({ features, mode, model, resume, sessionRef, mcpConfi
73
99
  if (!features.disallowed || !features.settingSources) throw new Error("this Claude Code cannot take deny rules or limit its setting sources");
74
100
  // --replay-user-messages: Claude Code echoes each user message as it reads it (isReplay), which is how a live steer is
75
101
  // known to have entered the running turn (remote-steering.mjs; measured on 2.1.286: at the next tool boundary).
76
- return ["-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose", ...(features.replay ? ["--replay-user-messages"] : []), "--permission-mode", permission, "--setting-sources", "user", "--disallowedTools", ...REMOTE_DENY, ...(unasked ? EDIT_MODE_DENY : []),
102
+ return ["-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose", ...(features.replay ? ["--replay-user-messages"] : []), "--permission-mode", permission, "--setting-sources", "user", "--disallowedTools", ...REMOTE_DENY, ...userDenies, ...(unasked ? EDIT_MODE_DENY : []),
77
103
  ...(features.allowed ? ["--allowedTools", ...PLAN_TOOLS] : []), ...(features.appendPrompt ? ["--append-system-prompt", PLAN_HINT] : []),
78
104
  "--permission-prompt-tool", APPROVAL_TOOL, "--mcp-config", mcpConfig, ...(features.partial ? ["--include-partial-messages"] : []), ...(model ? ["--model", model] : []), ...(effort ? ["--effort", effort] : []), ...(addDirs.length ? ["--add-dir", ...addDirs] : []), ...(resume ? ["--resume", resume] : ["--session-id", sessionRef])];
79
105
  }
@@ -22,10 +22,12 @@
22
22
  * without a prompt (else Codex asks by `mcpServer/elicitation/request`), and the server's instructions reach the agent.
23
23
  */
24
24
  import { spawn } from "node:child_process";
25
- import { chmodSync, realpathSync, writeFileSync } from "node:fs";
26
- import { isAbsolute } from "node:path";
25
+ import { chmodSync, readdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
26
+ import { homedir } from "node:os";
27
+ import { isAbsolute, join } from "node:path";
27
28
  import { changePaths, codexApprovalAsTool, refusalFor } from "./remote-codex-events.mjs";
28
29
  import { PLAN_TOOL_NAMES } from "./remote-approval-bridge.mjs";
30
+ import { REVIEWED_COMMANDS } from "./remote-policy.mjs";
29
31
 
30
32
  const MODEL = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
31
33
  const THREAD = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -68,12 +70,49 @@ export function writeBridgeSession(file, { socket, token }) {
68
70
  return file;
69
71
  }
70
72
 
73
+ /**
74
+ * THE PERSON'S OWN CODEX RULES ARE DESK GRANTS (S0 for Codex, release 33; PROTOCOL.md §Approvals). Codex reads its execpolicy
75
+ * `.rules` files (`$CODEX_HOME/rules/`, else ~/.codex/rules/, and a project's `.codex/rules/`) whatever a session asks, and a
76
+ * `prefix_rule` whose decision is `allow` (the default when none is named) runs that command outside the sandbox without
77
+ * asking: a desk's "always allow `zsh …/ships/*`" would run a ship script from a phone prompt. `codex exec` has
78
+ * `--ignore-rules`; `codex app-server` (0.154.0) has no such flag and no config key that unloads them, so there is NO way to
79
+ * deny them per session. So the files are only READ here, at the session's start, never written: every allow that is not a
80
+ * reviewed command (remote-policy.mjs REVIEWED_COMMANDS, matched by its words) is returned, and a remote Codex session is
81
+ * refused while any is there (remote-sessions.mjs, `not_allowed`): then every command it runs is one the phone approved or
82
+ * one Codex itself deems read-only. A folder that cannot be read (other than missing) or a rule that cannot be read as a
83
+ * plain list of words counts as an allow: unknown is never allowed.
84
+ */
85
+ export function codexDeskGrants({ env = process.env, home = homedir(), projectPath = null, read = (f) => readFileSync(f, "utf8"), list = (d) => readdirSync(d) } = {}) {
86
+ const dirs = [join(env.CODEX_HOME || join(env.HOME || home, ".codex"), "rules"), ...(projectPath ? [join(projectPath, ".codex", "rules")] : [])];
87
+ const reviewed = new Set(REVIEWED_COMMANDS);
88
+ const out = [];
89
+ for (const dir of dirs) {
90
+ let names;
91
+ try { names = list(dir).filter((n) => n.endsWith(".rules")).sort(); } catch (error) { if (error?.code !== "ENOENT") out.push(`${dir}: unreadable`); continue; }
92
+ for (const name of names) {
93
+ let text;
94
+ try { text = read(join(dir, name)); } catch { out.push(`${name}: unreadable`); continue; }
95
+ const code = text.replace(/#[^\n]*/g, "");
96
+ for (const m of code.matchAll(/prefix_rule\s*\(([\s\S]*?)\)\s*(?=prefix_rule|$)/g)) {
97
+ const decision = /decision\s*=\s*"([a-z]+)"/.exec(m[1])?.[1] ?? "allow";
98
+ if (decision === "prompt" || decision === "forbidden") continue;
99
+ const words = /pattern\s*=\s*\[([^\[\]]*)\]/.exec(m[1])?.[1];
100
+ const line = words !== undefined && /^\s*("[^"\\]*"\s*,\s*)*"[^"\\]*"\s*,?\s*$/.test(words) ? [...words.matchAll(/"([^"\\]*)"/g)].map((w) => w[1]).join(" ") : null;
101
+ if (line === null || !reviewed.has(line)) out.push(`${name}: ${line ?? "a rule that is not a plain list of words"}`);
102
+ }
103
+ }
104
+ }
105
+ return out;
106
+ }
107
+
71
108
  /** thread/start or thread/resume parameters from the protocol's closed options. */
72
109
  export function threadParams({ cwd, model, mode, resume }) {
73
110
  if (mode !== "ask" && mode !== "plan") throw new Error("the protocol offers the ask and plan modes only");
74
111
  if (model !== null && !MODEL.test(model)) throw new Error("not a model name");
75
112
  if (resume !== null && !isCodexThreadId(resume)) throw new Error("a resume id is Codex's own thread id");
76
- const common = { cwd, approvalPolicy: "untrusted", sandbox: mode === "plan" ? "read-only" : "workspace-write", ...(model ? { model } : {}) };
113
+ // approvalsReviewer "user" (S0 for Codex, release 33): the person's config may route approvals to Codex's own reviewing
114
+ // subagent (`approvals_reviewer = "auto_review"`, which approves by itself); a remote session's go to the phone, always.
115
+ const common = { cwd, approvalPolicy: "untrusted", approvalsReviewer: "user", sandbox: mode === "plan" ? "read-only" : "workspace-write", ...(model ? { model } : {}) };
77
116
  return resume ? { method: "thread/resume", params: { threadId: resume, ...common } } : { method: "thread/start", params: common };
78
117
  }
79
118
 
@@ -81,15 +120,17 @@ const text = (t) => [{ type: "text", text: t }];
81
120
 
82
121
  /**
83
122
  * o: { file, cwd, env, model, mode, resume, plans?, onMessage(msg), onThread(threadId), onExit(how), approve(tool, input) → Promise<boolean> }.
84
- * → { pid, alive, write(text), steer(text) → Promise<{ ok }>, interrupt() → Promise<boolean>, stop(), close() }.
123
+ * → { pid, alive, write(text), steer(text) → Promise<{ ok }>, interrupt() → Promise<boolean>, setModel(model), stop(), close() }.
124
+ * setModel (release 33): the next `turn/start` carries `model`, which the app-server takes "for this turn and subsequent turns"
125
+ * (its own JSON schema, 0.154.0); the thread and the process stay.
85
126
  */
86
127
  export function startCodex(o) {
87
128
  const child = spawn(o.file, codexArgs({ cwd: o.cwd, plans: o.plans ?? null }), { cwd: o.cwd, env: o.env, stdio: ["pipe", "pipe", "pipe"], detached: process.platform !== "win32", windowsHide: true });
88
- let buffer = "", exited = false, nextId = 1, threadId = null, turnId = null, ready = false;
129
+ let buffer = "", exited = false, nextId = 1, threadId = null, turnId = null, ready = false, switched = null;
89
130
  const waiting = new Map(), queue = [], fileChanges = {};
90
131
  const send = (msg) => { if (!exited) child.stdin.write(`${JSON.stringify(msg)}\n`); };
91
132
  const call = (method, params) => new Promise((resolve) => { if (exited) { resolve({ error: { message: "codex exited" } }); return; } const id = nextId++; waiting.set(id, resolve); send({ id, method, params }); });
92
- const turn = (t) => call("turn/start", { threadId, input: text(t) });
133
+ const turn = (t) => call("turn/start", { threadId, input: text(t), ...(switched ? { model: switched } : {}) });
93
134
  async function answer(msg) {
94
135
  // An MCP server's question (a tool call to approve, a form): the planning tools never ask (approval_mode above), and
95
136
  // nothing else of an MCP server is the phone's to answer. Declined in the elicitation's own shape.
@@ -142,6 +183,8 @@ export function startCodex(o) {
142
183
  /** Words into the running turn, guarded by its id: a turn that just ended refuses them, and they wait for the next. */
143
184
  async steer(t) { if (!ready || !turnId) return { ok: false }; const r = await call("turn/steer", { threadId, expectedTurnId: turnId, input: text(t) }); return { ok: !r.error }; },
144
185
  async interrupt() { if (!ready || !turnId) return false; const r = await call("turn/interrupt", { threadId, turnId }); return !r.error; },
186
+ /** Another of Codex's own models from the next turn on (a name the computer listed and checked; never free text). */
187
+ setModel(model) { if (typeof model !== "string" || !MODEL.test(model)) throw new Error("not a model name"); switched = model; },
145
188
  async stop(graceMs = 3000) {
146
189
  if (exited) return;
147
190
  if (turnId) await Promise.race([this.interrupt(), new Promise((r) => setTimeout(r, 1000))]);
@@ -25,8 +25,10 @@
25
25
  */
26
26
  import { spawn } from "node:child_process";
27
27
  import { randomBytes } from "node:crypto";
28
- import { realpathSync } from "node:fs";
29
- import { isAbsolute, relative } from "node:path";
28
+ import { readFileSync, realpathSync } from "node:fs";
29
+ import { homedir } from "node:os";
30
+ import { isAbsolute, join, relative } from "node:path";
31
+ import { REVIEWED_COMMANDS } from "./remote-policy.mjs";
30
32
 
31
33
  const MODEL = /^[A-Za-z0-9][A-Za-z0-9._:/@+#-]{0,127}$/;
32
34
  const SESSION = /^ses_[0-9a-f]{12}[0-9A-Za-z]{14}$/;
@@ -47,7 +49,51 @@ export function openCodeArgs({ sessionRef, model, mode }) {
47
49
  if (!isOpenCodeSessionId(sessionRef)) throw new Error("an OpenCode session id is ses_ and 26 characters");
48
50
  if (model !== null && !MODEL.test(model)) throw new Error("not a model name");
49
51
  if (mode !== "ask" && mode !== "plan") throw new Error("the protocol offers the ask and plan modes only");
50
- return ["run", "--format", "json", "--session", sessionRef, ...(model ? ["--model", model] : []), ...(mode === "plan" ? ["--agent", "plan"] : [])];
52
+ // The agent is always named (release 33): a person's `default_agent` could otherwise pick one of their own, with its rules.
53
+ return ["run", "--format", "json", "--session", sessionRef, ...(model ? ["--model", model] : []), "--agent", mode === "plan" ? "plan" : "build"];
54
+ }
55
+
56
+ /**
57
+ * NO SHIP SCRIPT FROM A PHONE, FOR OPENCODE (S0, release 33; PROTOCOL.md §Approvals). The run's own config sits above the
58
+ * person's and the project's, but OpenCode merges configs key by key: a `permission.bash` OBJECT of ours keeps every key of
59
+ * theirs it does not name, so a desk grant such as `"zsh /Users/…/ships/*": "allow"` would still run without asking. So
60
+ * the person's global config (`$OPENCODE_CONFIG`, `$XDG_CONFIG_HOME/opencode/opencode.json[c]`, else ~/.config/opencode/)
61
+ * and the project's own `opencode.json[c]` are only READ at the session's start, never written, and each bash pattern they
62
+ * allow (in `permission.bash` and in any agent's) that is not a reviewed command comes back under the same key as `deny`;
63
+ * the fixed list (OPENCODE_DENY) is denied besides. A file that is there but cannot be read or parsed: the allows are not
64
+ * known, so the session gets no shell at all (`unreadable`). Missing files deny nothing more.
65
+ */
66
+ export const OPENCODE_DENY = Object.freeze(["zsh *", "bash *", "sh *", "SHIP_YES=1 *", "node scripts/deploy-production.mjs*", "node scripts/mobile-update.mjs*", "gh release*", "gh workflow*", "psql*", "git push*", "npm publish*", "pnpm publish*", "vercel *", "eas *", "sudo *", "curl *", "wget *"]);
67
+
68
+ /** JSON with comments and trailing commas (OpenCode's .jsonc) as JSON; strings are kept as they are. */
69
+ export function jsoncText(text) {
70
+ let out = "", i = 0;
71
+ while (i < text.length) {
72
+ const c = text[i];
73
+ if (c === '"') { const end = /"(?:[^"\\]|\\.)*"/y; end.lastIndex = i; const m = end.exec(text); if (!m) return null; out += m[0]; i += m[0].length; continue; }
74
+ if (c === "/" && text[i + 1] === "/") { while (i < text.length && text[i] !== "\n") i += 1; continue; }
75
+ if (c === "/" && text[i + 1] === "*") { const end = text.indexOf("*/", i + 2); if (end < 0) return null; i = end + 2; continue; }
76
+ out += c; i += 1;
77
+ }
78
+ return out.replace(/,(\s*[}\]])/g, "$1");
79
+ }
80
+
81
+ export function openCodeDeskDenies({ env = process.env, home = homedir(), projectPath = null, read = (f) => readFileSync(f, "utf8") } = {}) {
82
+ const base = env.XDG_CONFIG_HOME || join(env.HOME || home, ".config");
83
+ const files = [...(env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : []), join(base, "opencode", "opencode.json"), join(base, "opencode", "opencode.jsonc"), ...(projectPath ? [join(projectPath, "opencode.json"), join(projectPath, "opencode.jsonc")] : [])];
84
+ const reviewed = new Set(REVIEWED_COMMANDS.flatMap((line) => [line, `${line} *`, `${line}*`]));
85
+ const denies = new Set(), edits = new Set();
86
+ for (const file of files) {
87
+ let text;
88
+ try { text = read(file); } catch (error) { if (error?.code === "ENOENT") continue; return { denies: [], edits: [], unreadable: true }; }
89
+ let config;
90
+ try { const clean = jsoncText(text); config = clean === null ? null : JSON.parse(clean); } catch { config = null; }
91
+ if (!config || typeof config !== "object") return { denies: [], edits: [], unreadable: true };
92
+ const bashes = [config.permission?.bash, ...Object.values(config.agent ?? {}).map((a) => a?.permission?.bash)];
93
+ for (const bash of bashes) if (bash && typeof bash === "object") for (const [pattern, decision] of Object.entries(bash)) if (decision === "allow" && pattern !== "*" && !reviewed.has(pattern)) denies.add(pattern);
94
+ for (const edit of [config.permission?.edit, ...Object.values(config.agent ?? {}).map((a) => a?.permission?.edit)]) if (edit && typeof edit === "object") for (const [pattern, decision] of Object.entries(edit)) if (decision === "allow" && pattern !== "*") edits.add(pattern);
95
+ }
96
+ return { denies: [...denies].sort(), edits: [...edits].sort(), unreadable: false };
51
97
  }
52
98
 
53
99
  const SECRET_READS = ["*.env", "*.env.*", "*.envrc", "*.netrc", "*.npmrc", "*.pypirc", "*.git-credentials", "*.pem", "*.key", "*.p12", "*.pfx", "*id_rsa*", "*id_ed25519*", "*id_ecdsa*", "*credentials*", "*secret*"];
@@ -57,12 +103,15 @@ const noWildcard = (text) => typeof text === "string" && text.length > 0 && !/[*
57
103
  * `{ tool: "Edit", path }` (relative to the project), allowed by their exact text on top of "ask". String values replace
58
104
  * whatever a person's or a repository's config set for the same key (OpenCode merges configs key by key).
59
105
  */
60
- export function permissionConfig(mode, allow = []) {
106
+ export function permissionConfig(mode, allow = [], desk = { denies: [], unreadable: false }) {
61
107
  const read = Object.fromEntries([["*", "allow"], ...SECRET_READS.map((p) => [p, "deny"])]);
62
108
  const bash = allow.filter((a) => a.tool === "Bash" && noWildcard(a.command)), edit = allow.filter((a) => a.tool === "Edit" && noWildcard(a.path));
109
+ // S0 (release 33): the fixed denies and the person's own allows as denies, last, so they outrank every allow; no shell at all
110
+ // when the person's config could not be read.
63
111
  const permission = { "*": "ask", read, glob: "allow", grep: "allow", list: "allow", todowrite: "allow", external_directory: "deny", question: "deny", doom_loop: "deny",
64
- bash: bash.length ? Object.fromEntries([["*", "ask"], ...bash.map((a) => [a.command, "allow"])]) : "ask",
65
- edit: mode === "plan" ? "deny" : edit.length ? Object.fromEntries([["*", "ask"], ...edit.map((a) => [a.path, "allow"])]) : "ask" };
112
+ bash: desk.unreadable ? "deny" : Object.fromEntries([["*", "ask"], ...bash.map((a) => [a.command, "allow"]), ...[...OPENCODE_DENY, ...desk.denies].map((p) => [p, "deny"])]),
113
+ // A path the person allows at the desk asks here (their key, our value): only the phone's approval of this run allows one.
114
+ edit: mode === "plan" ? "deny" : edit.length ? Object.fromEntries([["*", "ask"], ...(desk.edits ?? []).map((p) => [p, "ask"]), ...edit.map((a) => [a.path, "allow"])]) : "ask" };
66
115
  return { permission, agent: { build: { permission }, plan: { permission: { ...permission, edit: "deny" } } } };
67
116
  }
68
117
 
@@ -94,15 +143,17 @@ const MAX_FOLLOW_UPS = 3;
94
143
 
95
144
  /**
96
145
  * o: { file, cwd, env, model, mode, sessionRef, onMessage(line), onExit(how), approve(tool, input) → Promise<boolean> }.
97
- * → { pid, alive, write(text), interrupt() → Promise<boolean>, stop(), close() }. A turn is one run and its follow-ups;
98
- * onMessage hears each JSON line and `wt.turn_started` / `wt.turn_ended` around them.
146
+ * → { pid, alive, write(text), interrupt() → Promise<boolean>, setModel(model), stop(), close() }. A turn is one run and its
147
+ * follow-ups; onMessage hears each JSON line and `wt.turn_started` / `wt.turn_ended` around them. setModel (release 33): the
148
+ * next run's `--model`, the same `--session`.
99
149
  */
100
150
  export function startOpenCode(o) {
101
- const args = openCodeArgs({ sessionRef: o.sessionRef, model: o.model, mode: o.mode });
151
+ let args = openCodeArgs({ sessionRef: o.sessionRef, model: o.model, mode: o.mode });
152
+ const desk = openCodeDeskDenies({ env: o.env, projectPath: o.cwd }); // read once, at the session's start (S0)
102
153
  let child = null, closed = false, interrupted = false, busy = false, exited = false;
103
154
  const queue = [];
104
155
  const runOnce = (text, allow) => new Promise((resolve) => {
105
- const env = { ...o.env, OPENCODE_CONFIG_CONTENT: JSON.stringify(permissionConfig(o.mode, allow)) };
156
+ const env = { ...o.env, OPENCODE_CONFIG_CONTENT: JSON.stringify(permissionConfig(o.mode, allow, desk)) };
106
157
  const run = child = spawn(o.file, args, { cwd: o.cwd, env, stdio: ["pipe", "pipe", "pipe"], detached: process.platform !== "win32", windowsHide: true });
107
158
  const asks = [];
108
159
  let buffer = "";
@@ -154,6 +205,8 @@ export function startOpenCode(o) {
154
205
  alive: () => !closed,
155
206
  sessionRef: () => o.sessionRef,
156
207
  write: (t) => { if (closed) return; if (busy) queue.push(t); else turn(t); },
208
+ /** Another of OpenCode's own models from the next run on, checked as the first one was (openCodeArgs throws on anything else). */
209
+ setModel(model) { args = openCodeArgs({ sessionRef: o.sessionRef, model, mode: o.mode }); },
157
210
  /** End the running turn: OpenCode cancels its session's work on SIGINT and exits; the session stays for the next prompt. */
158
211
  async interrupt() { if (!child) return false; interrupted = true; await halt(3000); return true; },
159
212
  async stop(graceMs = 3000) {
@@ -21,7 +21,7 @@
21
21
  import { execFile, spawn } from "node:child_process";
22
22
  import { writeFileSync, chmodSync, mkdirSync, existsSync } from "node:fs";
23
23
  import { isAbsolute, join } from "node:path";
24
- import { REMOTE_DENY } from "./remote-adapter-claude-code.mjs";
24
+ import { REMOTE_DENY, userAllowDenies } from "./remote-adapter-claude-code.mjs";
25
25
 
26
26
  export const SOCKET = "worktrust-remote";
27
27
  /** Our socket, or a throwaway one a test names (`worktrust-remote-test-<pid>`); never "default", never a path. */
@@ -221,7 +221,7 @@ export const NO_TMUX = Object.freeze({ socket: SOCKET, config: null, env: {}, ve
221
221
  * No text from the phone is an argument: a model the computer listed, a mode from the closed set, a uuid.
222
222
  */
223
223
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
224
- export function terminalClaudeArgs({ features, mode, model, resume, sessionRef }) {
224
+ export function terminalClaudeArgs({ features, mode, model, resume, sessionRef, userDenies = userAllowDenies() }) {
225
225
  if (mode !== "ask" && mode !== "plan") throw new Error("the protocol offers the ask and plan modes only");
226
226
  const permission = mode === "plan" ? features?.planMode : features?.askMode;
227
227
  if (!permission) throw new Error("this Claude Code offers no such permission mode");
@@ -229,7 +229,8 @@ export function terminalClaudeArgs({ features, mode, model, resume, sessionRef }
229
229
  if (resume !== null && !UUID.test(resume ?? "")) throw new Error("a resume id is Claude Code's own session uuid");
230
230
  if (resume === null && !UUID.test(sessionRef ?? "")) throw new Error("a new session needs its uuid");
231
231
  if (model !== null && (typeof model !== "string" || model.startsWith("-") || !/^[A-Za-z0-9._:@[\]-]{1,128}$/.test(model))) throw new Error("not a model name");
232
- return ["--permission-mode", permission, "--setting-sources", "user", "--disallowedTools", ...REMOTE_DENY, ...(model ? ["--model", model] : []), ...(resume ? ["--resume", resume] : ["--session-id", sessionRef])];
232
+ // The person's own Bash allow rules come back as denies here too (remote-adapter-claude-code.mjs userAllowDenies, S0).
233
+ return ["--permission-mode", permission, "--setting-sources", "user", "--disallowedTools", ...REMOTE_DENY, ...userDenies, ...(model ? ["--model", model] : []), ...(resume ? ["--resume", resume] : ["--session-id", sessionRef])];
233
234
  }
234
235
 
235
236
  /**