worktrust 0.11.9 → 0.11.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/LICENSE +3 -0
- package/README.md +18 -12
- package/cli-look.mjs +192 -0
- package/cli-menu-remote.mjs +31 -7
- package/cli-menu.mjs +28 -14
- package/engine-release.json +1 -1
- package/log-session.mjs +6 -169
- package/package-release.json +1 -1
- package/package.json +3 -1
- package/remote-adapter-claude-code.mjs +30 -4
- package/remote-adapter-terminal.mjs +4 -3
- package/remote-cli.mjs +22 -44
- package/remote-connections.mjs +55 -1
- package/remote-pairing.mjs +42 -4
- package/remote-qr.mjs +40 -15
- package/remote-run.mjs +7 -5
- package/remote-store.mjs +10 -0
- package/session-readers.mjs +202 -0
- package/worktrust.mjs +57 -19
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
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
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
|
package/package-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"e8abb38c293b57b71d3a6163d6242d1f375e773372b91b6d8ce39c584c51262a","CHANGELOG.md":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"e8abb38c293b57b71d3a6163d6242d1f375e773372b91b6d8ce39c584c51262a","CHANGELOG.md":"39b7fa620f000dc34e757478828361a052df9df058d8427d7f8a07849de2d225","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"eb210c9cab5dbb6a2c293a003a7604e7fb6e5f7b95ab22b382171dc7adeed41a","README.md":"bc0ee581519430319245531455c0f1418ebd493947c586ed88955542039a3391","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":"cf418de58f8c7467c87cac250cbf975f009cb79c7fde27cedcd321d5a8220843","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":"a33a9d38157011512bf085bc8db2836505f574e5445af3142f1a511cfe33f97c","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":"d2fd6c61d9e3c4a45e9b10da1aa3c15d45c86629d6456e4a8d25ad95b13eb209","remote-adapter-opencode.mjs":"ddd7f3ec0b4ba92f4744453d60fda338b63550e3ec7b23fa3acc668df1d64eb7","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":"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":"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":"93f8c2031895d4e01006a1951d7c0e79ef71b86b2777eed5dfa966ab131e446d","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":"1efb7869cef6090cbbeae15ff1e5ffe99dca3742f9c245686d6758bb705587d6","remote-settings.mjs":"ca16f39416a457bd5ceb1df847596e1b4bcd2894310eb6514664a619dee4981f","remote-steered.mjs":"d7afde92c62c87abbdb84b0cfea2eea4752e90a2e453e52a54812c4fe0395190","remote-steering.mjs":"7ba22e6110cea3ac75a4f084f8f92a5bd90c31a19d3ce58a88a0843bdadea834","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":"05974f8dc97844f011cb409789f52089b5f21d37848ed1490e640caf4eab92e6","setup-mcp.mjs":"b732e3dd9b3e522b7cc8acf167ce28ba8f1a8dee797ee15bd7c3b02919b13e6f","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"e9f20415c2b5d62a09f35a63075002ebd1da56edb32f242d52822d58ecbd8ac3","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"4e6b36faf58082ab6531345bf56115957322786dcfd2263dba7536ef2534ccea"},"format":"worktrust-package/1","kind":"npm","version":"0.11.10"},"signature":"sz8svyuVYswAzBU82IP4zwqwrcsumoKcuBBsaDphTW6JLqQoZlE4wY_4EMxgutZDnG3uMKw-yzPpr5Q8U5wxCg"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.10",
|
|
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 {
|
|
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
|
}
|
|
@@ -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
|
-
|
|
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
|
/**
|
package/remote-cli.mjs
CHANGED
|
@@ -41,13 +41,13 @@ import { basename } from "node:path";
|
|
|
41
41
|
import { hostname } from "node:os";
|
|
42
42
|
import { createInterface } from "node:readline/promises";
|
|
43
43
|
import * as P from "./remote-protocol.mjs";
|
|
44
|
-
import { ensureRemoteDir, isLoopbackGateway, issuerKeys, loadIdentity, loadKeys, loadPhones, loadProjects, loadSettings, newKeys, random, readJson, removeFile, saveIdentity, saveKeys, savePhones, saveSettings, writeJson } from "./remote-store.mjs";
|
|
44
|
+
import { ensureRemoteDir, gatewayOf, isLoopbackGateway, issuerKeys, PRODUCTION_GATEWAY, loadIdentity, loadKeys, loadPhones, loadProjects, loadSettings, newKeys, random, readJson, removeFile, saveIdentity, saveKeys, savePhones, saveSettings, writeJson } from "./remote-store.mjs";
|
|
45
45
|
import { canonicalProject } from "./remote-policy.mjs";
|
|
46
|
-
import { IssuerMissing, PairingDenied, PairingExpired, PairingRefused, pairComputer } from "./remote-pairing.mjs";
|
|
46
|
+
import { IssuerMissing, PairingDenied, PairingExpired, PairingRefused, compactForQr, oneScan, oneScanInvite, pairComputer } from "./remote-pairing.mjs";
|
|
47
47
|
import { startCountdown, waitKey } from "./remote-countdown.mjs";
|
|
48
|
-
import { askLine, connectionsCommand, disconnectCommand, removePhones } from "./remote-connections.mjs";
|
|
48
|
+
import { askLine, connectionsCommand, disconnectCommand, linkPhone, removePhones } from "./remote-connections.mjs";
|
|
49
49
|
import { installService, removeService, serviceState, servicePlatform } from "./remote-service.mjs";
|
|
50
|
-
import {
|
|
50
|
+
import { terminalQr } from "./remote-qr.mjs";
|
|
51
51
|
import { webSocketAvailable } from "./remote-transport.mjs";
|
|
52
52
|
import { guideToNode, remoteStopsHere } from "./node-guide.mjs";
|
|
53
53
|
import { inventory } from "./remote-inventory.mjs";
|
|
@@ -60,7 +60,6 @@ import { rootLabel } from "./remote-projects.mjs";
|
|
|
60
60
|
import { adminCommand, allowedModes, applySettingsChange, askMacFolderAccess, folderCheck, modesCommand } from "./remote-settings.mjs";
|
|
61
61
|
|
|
62
62
|
const fingerprintOf = (keys) => P.deviceFingerprint(keys.public);
|
|
63
|
-
const pretty = (code) => `${code.slice(0, 4)}-${code.slice(4)}`;
|
|
64
63
|
/** A question only a person at this keyboard answers: a terminal, a typed "yes"; --yes and Enter are No. */
|
|
65
64
|
export async function askTyped(question) {
|
|
66
65
|
if (!process.stdin.isTTY) return false;
|
|
@@ -79,7 +78,10 @@ function needPaired(io) {
|
|
|
79
78
|
/** `remote app` | `remote web`: the two roads to approve this computer; each does all of what `remote enable` did. */
|
|
80
79
|
async function approve(io, road) {
|
|
81
80
|
const settings = loadSettings();
|
|
82
|
-
|
|
81
|
+
// THE GATEWAY (owner, 2026-11-14: on by default): --gateway, then WORKTRUST_REMOTE_GATEWAY, then this computer's saved choice,
|
|
82
|
+
// then WorkTrust's (PRODUCTION_GATEWAY). Only a choice is saved; null keeps "the default" (remote-store.mjs gatewayOf).
|
|
83
|
+
const chosen = io.flag("gateway") ?? process.env.WORKTRUST_REMOTE_GATEWAY ?? settings.gateway ?? null;
|
|
84
|
+
const gateway = chosen ?? PRODUCTION_GATEWAY;
|
|
83
85
|
if (gateway && !P.isGatewayOrigin(gateway)) io.fail("--gateway is an origin: wss://host[:port], or ws://127.0.0.1:<port> for the dev relay");
|
|
84
86
|
io.say();
|
|
85
87
|
io.say(" WorkTrust remote lets your phone steer the AI agents on this computer. It will:");
|
|
@@ -90,16 +92,19 @@ async function approve(io, road) {
|
|
|
90
92
|
io.say(" - mark every session it steers, so remote work never counts as your AI Hours");
|
|
91
93
|
if (!(await io.ask("Continue?"))) return;
|
|
92
94
|
ensureRemoteDir();
|
|
93
|
-
let identity = loadIdentity();
|
|
95
|
+
let identity = loadIdentity(), ready = null;
|
|
94
96
|
if (!identity || io.has("repair")) {
|
|
95
97
|
const keys = newKeys();
|
|
96
98
|
const pub = P.publicKeysOf(P.importSecretKeys(keys));
|
|
97
99
|
try {
|
|
98
100
|
// The request's own clock under the QR or link (remote-countdown.mjs); after an expiry, Enter asks again with a new one.
|
|
99
|
-
let paired = null;
|
|
101
|
+
let paired = null, once = null;
|
|
100
102
|
while (!paired) {
|
|
103
|
+
// ONE SCAN (0.11.10, remote-pairing.mjs): the app's road carries the pairing secret in the QR's fragment; a new one per QR.
|
|
104
|
+
// --no-pair links no phone, so it carries no pairing secret and writes no invite (review 2026-11-14, P3-6).
|
|
105
|
+
once = road === "app" && !io.has("device") && !io.has("no-pair") ? oneScan({ gateway, publicKeys: pub, nowMs: Date.now(), random }) : null;
|
|
101
106
|
try {
|
|
102
|
-
paired = await pairComputer({ origin: io.origin, secret: P.importSecretKeys(keys), publicKeys: pub, host: hostname(), os: io.os, device: io.has("device"), road, showQr: (link) => io.say(
|
|
107
|
+
paired = await pairComputer({ origin: io.origin, secret: P.importSecretKeys(keys), publicKeys: pub, host: hostname(), os: io.os, device: io.has("device"), road, once, showLink: io.has("show-link"), showQr: (link) => io.say(terminalQr(compactForQr(link), { color: Boolean(process.stdout.isTTY) && !process.env.NO_COLOR })), issuerKeys: issuerKeys(gateway), say: io.say, openBrowser: io.openBrowser, countdown: (w) => startCountdown(w) });
|
|
103
108
|
} catch (error) {
|
|
104
109
|
if (error instanceof PairingDenied) return;
|
|
105
110
|
if (!(error instanceof PairingExpired) || !process.stdin.isTTY) throw error;
|
|
@@ -110,53 +115,26 @@ async function approve(io, road) {
|
|
|
110
115
|
saveKeys(keys);
|
|
111
116
|
identity = { v: 1, device_id: paired.device_id, binding: paired.binding, sub: paired.sub, origin: io.origin, paired_at: Date.now() };
|
|
112
117
|
saveIdentity(identity);
|
|
118
|
+
// The daemon confirms the phone that proves this QR's secret; read per hello, so it is there before the service starts.
|
|
119
|
+
if (once && once.e * 1000 > Date.now()) writeJson("invite.json", (ready = oneScanInvite(once, paired.device_id, P.generatePairingCode(random), Date.now())));
|
|
113
120
|
io.say(` ✓ Paired${paired.account ? ` for ${paired.account}` : ""}. This computer's remote key: ${P.deviceFingerprint(pub)}`);
|
|
114
121
|
} catch (error) {
|
|
115
122
|
if (error instanceof IssuerMissing || error instanceof PairingRefused) io.fail(error.message);
|
|
116
123
|
throw error;
|
|
117
124
|
}
|
|
118
125
|
} else io.say(` Already paired (${identity.device_id}); --repair pairs again with new keys.`);
|
|
119
|
-
saveSettings({ ...settings, enabled: true, paused: null, gateway:
|
|
126
|
+
saveSettings({ ...settings, enabled: true, paused: null, gateway: chosen, agent_path: process.env.PATH ?? null });
|
|
120
127
|
if (loadProjects().length === 0 && loadRoots().length === 0) io.say(" No folder is granted yet: npx worktrust remote roots add <folder> (or the menu: npx worktrust › Remote Agent › Roots)");
|
|
121
|
-
if (!gateway) { io.say(" No gateway is set: the production gateway is not live yet. Nothing runs until one is (--gateway)."); return; }
|
|
122
128
|
if (servicePlatform() === "foreground") { io.say(" ✓ This computer is connected to Remote Agent."); io.say(" Windows: there is no service; run `npx worktrust remote run` and keep that terminal open."); return; }
|
|
123
129
|
const runtime = await io.prepare();
|
|
124
130
|
const service = installService({ program: [runtime.node, ...runtime.nodeArgs, runtime.entry, "remote", "run"], path: process.env.PATH ?? "" });
|
|
125
131
|
io.say(service.started ? ` ✓ The service runs (${service.kind}, while you are logged in; linger stays off).` : ` ! The service file was written (${service.file}) but did not start; run \`npx worktrust remote run\` to see why.`);
|
|
126
132
|
if (service.started) io.say(" ✓ This computer is connected to Remote Agent.");
|
|
127
|
-
if (!io.has("no-pair")) await
|
|
133
|
+
if (!io.has("no-pair")) await linkPhone(io, ready);
|
|
128
134
|
}
|
|
129
135
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const settings = loadSettings();
|
|
133
|
-
if (!settings.enabled || !settings.gateway) io.fail("remote is off or has no gateway: run `npx worktrust remote app` (or `remote web`)");
|
|
134
|
-
const started = Date.now();
|
|
135
|
-
const invite = P.createPairingInvite({ gateway: settings.gateway, deviceId: identity.device_id, ed25519_pub: keys.public.ed25519_pub, x25519_pub: keys.public.x25519_pub, nowMs: started, random });
|
|
136
|
-
const code = P.generatePairingCode(random);
|
|
137
|
-
writeJson("invite.json", { ...invite, code, used: false, created_at: started });
|
|
138
|
-
const link = P.encodePairingInvite(invite);
|
|
139
|
-
io.say();
|
|
140
|
-
io.say(" Scan this with the WorkTrust app (or the phone's camera):");
|
|
141
|
-
io.say(renderQr(qrMatrix(link).modules, { color: Boolean(process.stdout.isTTY) && !process.env.NO_COLOR }));
|
|
142
|
-
io.say(` Link: ${link}`);
|
|
143
|
-
io.say(` No camera? Type this code in the app: ${pretty(code)} (then confirm the phone here with \`npx worktrust remote phones\`)`);
|
|
144
|
-
io.say(" The code and the QR work once, for five minutes. Ctrl+C cancels.");
|
|
145
|
-
const cancel = () => { removeFile("invite.json"); process.exit(130); };
|
|
146
|
-
process.once("SIGINT", cancel);
|
|
147
|
-
const before = new Set(loadPhones().pending.map((p) => p.fingerprint));
|
|
148
|
-
while (Date.now() < invite.e * 1000) {
|
|
149
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
150
|
-
const phones = loadPhones();
|
|
151
|
-
const paired = phones.confirmed.find((p) => p.how === "qr" && p.confirmed_at >= started);
|
|
152
|
-
if (paired) { process.off("SIGINT", cancel); io.say(` ✓ Paired: phone · ${paired.fingerprint}`); return; }
|
|
153
|
-
const asked = phones.pending.find((p) => !before.has(p.fingerprint));
|
|
154
|
-
if (asked) { process.off("SIGINT", cancel); io.say(` A phone asked by code (${asked.fingerprint}). Confirm it at this keyboard: npx worktrust remote phones confirm ${asked.fingerprint}`); return; }
|
|
155
|
-
}
|
|
156
|
-
process.off("SIGINT", cancel);
|
|
157
|
-
removeFile("invite.json");
|
|
158
|
-
io.say(" The pairing code expired. Run `npx worktrust remote pair` for a new one.");
|
|
159
|
-
}
|
|
136
|
+
/** `remote pair`: a new QR for a phone (remote-connections.mjs `linkPhone`, which also ends `remote app`). */
|
|
137
|
+
const pair = (io) => linkPhone(io);
|
|
160
138
|
|
|
161
139
|
async function phones(io, rest) {
|
|
162
140
|
const list = loadPhones();
|
|
@@ -284,12 +262,12 @@ function status(io) {
|
|
|
284
262
|
const settings = loadSettings(), identity = loadIdentity(), keys = identity ? loadKeys() : null, phonesList = loadPhones(), service = serviceState();
|
|
285
263
|
const agents = inventory({ env: { ...process.env, PATH: settings.agent_path ?? process.env.PATH } }).reports.filter((r) => r.installed);
|
|
286
264
|
const summary = { enabled: settings.enabled, paused: settings.paused, paired: Boolean(identity), device_id: identity?.device_id ?? null, fingerprint: keys ? fingerprintOf(keys) : null,
|
|
287
|
-
gateway: settings.gateway, service, node_websocket: webSocketAvailable(), phones: { confirmed: phonesList.confirmed.length, pending: phonesList.pending.length, browsers_added: phonesList.confirmed.filter((p) => p.how === "endorsed").length, allow_endorse: settings.allow_endorse === true }, projects: loadProjects().length, modes_allowed: allowedModes(settings), admin: settings.admin !== false,
|
|
265
|
+
gateway: gatewayOf(settings), gateway_default: settings.gateway === null || settings.gateway === undefined, service, node_websocket: webSocketAvailable(), phones: { confirmed: phonesList.confirmed.length, pending: phonesList.pending.length, browsers_added: phonesList.confirmed.filter((p) => p.how === "endorsed").length, allow_endorse: settings.allow_endorse === true }, projects: loadProjects().length, modes_allowed: allowedModes(settings), admin: settings.admin !== false,
|
|
288
266
|
agents: agents.map((a) => ({ adapter: a.adapter, version: a.version, adapter_ready: a.capabilities.start, switched_off: a.capabilities.start && (a.adapter === "codex" || a.adapter === "opencode") && settings[a.adapter] !== true, models: a.models === null ? "not listed" : a.models.length })), invite_open: Boolean(readJson("invite.json")?.used === false) };
|
|
289
267
|
if (io.has("json")) { io.say(JSON.stringify(summary, null, 2)); return; }
|
|
290
268
|
io.say(` Remote: ${settings.enabled ? (settings.paused ? `paused (${settings.paused === "desk" ? "here" : "from a phone"})` : "on") : "off"}`);
|
|
291
269
|
io.say(` Paired: ${identity ? `${identity.device_id} · key ${summary.fingerprint}` : "no"}`);
|
|
292
|
-
io.say(` Gateway: ${
|
|
270
|
+
io.say(` Gateway: ${summary.gateway === PRODUCTION_GATEWAY ? `${new URL(PRODUCTION_GATEWAY).host} (WorkTrust's)` : `${summary.gateway}${isLoopbackGateway(summary.gateway) ? " (this computer: dev relay)" : " (chosen here)"}`}`);
|
|
293
271
|
io.say(` Service: ${service.kind === "foreground" ? "none on this system: run `npx worktrust remote run`" : `${service.installed ? "installed" : "not installed"}, ${service.running ? "running" : "not running"}`}`);
|
|
294
272
|
io.say(` Phones: ${summary.phones.confirmed} confirmed (${summary.phones.browsers_added} browsers added by a phone), ${summary.phones.pending} pending · Folders granted: ${summary.projects}`);
|
|
295
273
|
io.say(` Phones may add a browser: ${summary.phones.allow_endorse ? "yes" : "no"}`);
|
package/remote-connections.mjs
CHANGED
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
* never a model name it was not told.
|
|
12
12
|
*/
|
|
13
13
|
import { createInterface } from "node:readline/promises";
|
|
14
|
-
import { loadIdentity, loadKeys, loadPhones, savePhones } from "./remote-store.mjs";
|
|
14
|
+
import { gatewayOf, loadIdentity, loadKeys, loadPhones, loadSettings, random, removeFile, savePhones, writeJson } from "./remote-store.mjs";
|
|
15
15
|
import * as P from "./remote-protocol.mjs";
|
|
16
|
+
import { terminalQr } from "./remote-qr.mjs";
|
|
17
|
+
import { compactForQr } from "./remote-pairing.mjs";
|
|
16
18
|
|
|
17
19
|
const KEEP_REMOVED = 20;
|
|
18
20
|
const when = (ms) => (Number.isFinite(ms) ? new Date(ms).toISOString().slice(0, 16).replace("T", " ") : "never");
|
|
@@ -89,3 +91,55 @@ export async function disconnectCommand(io, rest, ask, tty = Boolean(process.std
|
|
|
89
91
|
removePhones([c.fingerprint]);
|
|
90
92
|
io.say(` ✓ Disconnected ${c.name}: it can no longer steer this computer. End its key for your whole account too: app.worktrust.io › Settings › Remote Agent.`);
|
|
91
93
|
}
|
|
94
|
+
|
|
95
|
+
/** How long `remote app` waits for the phone that scanned its one QR before it shows the pairing QR (0.11.10). */
|
|
96
|
+
export const ONE_SCAN_WAIT_MS = 30_000;
|
|
97
|
+
const pretty = (code) => `${code.slice(0, 4)}-${code.slice(4)}`;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* LINK A PHONE (`remote pair`, and the end of `remote app`; moved here from remote-cli.mjs in 0.11.10). Without `ready`: a new
|
|
101
|
+
* invite (five minutes, one phone, once), its QR, its link and the typed code, as before. With `ready` (the one-scan invite
|
|
102
|
+
* `remote app` wrote once the issuer named this computer, remote-pairing.mjs `oneScanInvite`): no second QR while the phone
|
|
103
|
+
* that scanned the first one links by itself; after `waitMs`, or for a phone that opened the code with the camera or runs an
|
|
104
|
+
* older app, the SAME invite as the pairing QR, with one line why. A phone that proves the secret is confirmed by the daemon
|
|
105
|
+
* (PROTOCOL.md §Pairing); a phone that asked by the typed code waits for `remote phones confirm` at this keyboard.
|
|
106
|
+
*/
|
|
107
|
+
export async function linkPhone(io, ready = null, { waitMs = ONE_SCAN_WAIT_MS, now = Date.now, tick = 1000 } = {}) {
|
|
108
|
+
const keys = loadKeys(), identity = loadIdentity(), settings = loadSettings();
|
|
109
|
+
if (!keys || !identity) io.fail("this computer is not paired for remote yet: run `npx worktrust remote app` (or `remote web`)");
|
|
110
|
+
// Off is its own state (owner, 2026-11-14): a missing gateway no longer exists, WorkTrust's is the default (gatewayOf).
|
|
111
|
+
if (!settings.enabled) io.fail("remote is off on this computer: run `npx worktrust remote app` (or `remote web`)");
|
|
112
|
+
const started = now();
|
|
113
|
+
const invite = ready ?? { ...P.createPairingInvite({ gateway: gatewayOf(settings), deviceId: identity.device_id, ed25519_pub: keys.public.ed25519_pub, x25519_pub: keys.public.x25519_pub, nowMs: started, random }), code: P.generatePairingCode(random), used: false, created_at: started };
|
|
114
|
+
if (!ready) writeJson("invite.json", invite);
|
|
115
|
+
const { code, used: _used, created_at: since, ...bare } = invite;
|
|
116
|
+
const link = P.encodePairingInvite(bare);
|
|
117
|
+
let shown = false;
|
|
118
|
+
const show = (why) => {
|
|
119
|
+
shown = true;
|
|
120
|
+
io.say();
|
|
121
|
+
io.say(why ?? " Scan this with the WorkTrust app (or the phone's camera):");
|
|
122
|
+
io.say(terminalQr(compactForQr(link), { color: Boolean(process.stdout.isTTY) && !process.env.NO_COLOR }));
|
|
123
|
+
io.say(` Link: ${link}`);
|
|
124
|
+
io.say(` No camera? Type this code in the app: ${pretty(code)} (then confirm the phone here with \`npx worktrust remote phones\`)`);
|
|
125
|
+
io.say(" The code and the QR work once, for five minutes. Ctrl+C cancels.");
|
|
126
|
+
};
|
|
127
|
+
if (ready) io.say(" Linking the phone that scanned the code …"); else show();
|
|
128
|
+
const cancel = () => { removeFile("invite.json"); process.exit(130); };
|
|
129
|
+
process.once("SIGINT", cancel);
|
|
130
|
+
const before = new Set(loadPhones().pending.map((p) => p.fingerprint));
|
|
131
|
+
try {
|
|
132
|
+
while (now() < invite.e * 1000) {
|
|
133
|
+
await new Promise((resolve) => setTimeout(resolve, tick));
|
|
134
|
+
const phones = loadPhones();
|
|
135
|
+
const paired = phones.confirmed.find((p) => p.how === "qr" && p.confirmed_at >= since);
|
|
136
|
+
if (paired) { io.say(` ✓ Paired: phone · ${paired.fingerprint}`); return paired; }
|
|
137
|
+
const asked = phones.pending.find((p) => !before.has(p.fingerprint));
|
|
138
|
+
if (asked) { io.say(` A phone asked by code (${asked.fingerprint}). Confirm it at this keyboard: npx worktrust remote phones confirm ${asked.fingerprint}`); return null; }
|
|
139
|
+
if (!shown && now() - started >= waitMs) show(" No phone linked by itself (the code was opened with the camera, or the app is older): scan this in the WorkTrust app.");
|
|
140
|
+
}
|
|
141
|
+
} finally { process.off("SIGINT", cancel); }
|
|
142
|
+
removeFile("invite.json");
|
|
143
|
+
io.say(" The pairing code expired. Run `npx worktrust remote pair` for a new one.");
|
|
144
|
+
return null;
|
|
145
|
+
}
|