worktrust 0.11.6 → 0.11.8

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/node-guide.mjs ADDED
@@ -0,0 +1,134 @@
1
+ /**
2
+ * REMOTE AGENT ON A NODE THAT IS TOO OLD: THE WAYS FORWARD (CLI 0.11.8, owner 2026-11-13). package.json promises Node 18
3
+ * for measuring; Remote Agent's one live connection needs the WebSocket Node has from 22.4. A `remote` command there does
4
+ * not end at a refusal: it says so plainly, says measuring keeps working, and shows the ways to a working Remote Agent,
5
+ * each with its exact command.
6
+ *
7
+ * WHAT THIS MODULE MAY RUN, AND HOW (held by check-cli-package's node-guide rule):
8
+ * - only a command from its OWN CLOSED LIST below (RUNNABLE): never a word from a person's input, a file or the network;
9
+ * - as an argv array handed to spawn, never a shell string, never `shell: true`;
10
+ * - only a user-level tool (fnm, volta, Homebrew, pipx): never sudo, never a system package manager, never an installer
11
+ * that asks for an administrator; those are printed for the person to run;
12
+ * - only after the exact command was shown and the person typed yes (Enter is No). Without a terminal, or with --yes,
13
+ * nothing is asked and nothing runs: the text is printed and the command ends with a failure code.
14
+ * nvm is a shell function and asdf's words differ per version: both are printed, never run. There is no "newer Node just
15
+ * for WorkTrust through npx": that Node would come from npm's `node` package, which nothing here verifies; the Python
16
+ * package is that way, with the official Node it locks by hash.
17
+ */
18
+ import { spawn, spawnSync } from "node:child_process";
19
+ import { existsSync, realpathSync } from "node:fs";
20
+ import { delimiter, join } from "node:path";
21
+ import { createInterface } from "node:readline/promises";
22
+
23
+ export const NODE_FLOOR = [22, 4];
24
+ /** The one sentence a script reads (stderr, exit 1); null where this Node can hold the connection. */
25
+ export const remoteNeedsNode = (has = typeof globalThis.WebSocket === "function", version = process.versions.node) =>
26
+ (has ? null : `remote needs Node 22.4 or later for its connection (this is ${version}); the Python package bundles one`);
27
+ export const nodeIsEnough = (version) => { const [a, b] = String(version).replace(/^v/, "").split(".").map(Number); return a > NODE_FLOOR[0] || (a === NODE_FLOOR[0] && b >= NODE_FLOOR[1]); };
28
+
29
+ /**
30
+ * Whether a `remote <sub>` command stops at the ways forward on this Node (asked by remote-cli.mjs before anything is read,
31
+ * asked, written or sent). Node before 22.4 has no WebSocket, so nothing that starts, links, allows or changes something
32
+ * runs. The ways to LOOK and to STOP stay: a person who moved to an older Node can still see the state, pause it, turn it
33
+ * off and close its connections.
34
+ */
35
+ const REMOTE_WITHOUT = new Set(["status", "pause", "disable", "disconnect"]);
36
+ export const remoteStopsHere = (sub, has = typeof globalThis.WebSocket === "function") => !REMOTE_WITHOUT.has(sub) && !has;
37
+
38
+ /** The closed list: every command this module can run. A way's `argv` is built from these words and nothing else. */
39
+ const RUNNABLE = Object.freeze({
40
+ fnm: [["fnm", "install", "22"], ["fnm", "default", "22"]],
41
+ volta: [["volta", "install", "node@22"]],
42
+ brew: [["brew", "upgrade", "node"]],
43
+ });
44
+ const shown = (argvs) => argvs.map((argv) => argv.join(" ")).join(" && ");
45
+
46
+ /** An executable of this name on PATH (its full path), or null. Reads directories only; runs nothing. */
47
+ export function onPath(name, env = process.env, platform = process.platform) {
48
+ const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
49
+ for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter).filter(Boolean)) for (const ext of exts) { const file = join(dir, name + ext); if (existsSync(file)) return file; }
50
+ return null;
51
+ }
52
+
53
+ /**
54
+ * How this computer's Node is installed, by where the running Node lives, and the command that updates it. Pure: `has(name)`
55
+ * says whether a tool is on PATH. `argv` is set only for a user-level manager this module may run; otherwise the command
56
+ * is for the person (`argv: null`).
57
+ */
58
+ export function nodeManager({ execPath = process.execPath, env = process.env, platform = process.platform, has = (name) => Boolean(onPath(name)) } = {}) {
59
+ const path = String(execPath).replace(/\\/g, "/");
60
+ const way = (id, name, text, argv = null) => ({ id, name, shown: text, argv });
61
+ if (path.includes("/.nvm/") || (env.NVM_DIR && path.startsWith(String(env.NVM_DIR).replace(/\\/g, "/")))) return way("nvm", "nvm", "nvm install 22 && nvm alias default 22");
62
+ if (/\/fnm(_multishells)?\/|\/\.fnm\//.test(path) || (env.FNM_DIR && path.startsWith(String(env.FNM_DIR).replace(/\\/g, "/")))) return way("fnm", "fnm", shown(RUNNABLE.fnm), has("fnm") ? RUNNABLE.fnm : null);
63
+ if (path.includes("/.volta/") || (env.VOLTA_HOME && path.startsWith(String(env.VOLTA_HOME).replace(/\\/g, "/")))) return way("volta", "Volta", shown(RUNNABLE.volta), has("volta") ? RUNNABLE.volta : null);
64
+ if (path.includes("/.asdf/")) return way("asdf", "asdf", "asdf install nodejs latest:22 (then make it your default: asdf set -u nodejs latest:22, or asdf global on asdf before 0.16)");
65
+ if (/^\/opt\/homebrew\/|^\/usr\/local\/(Cellar|opt)\/|^\/home\/linuxbrew\//.test(path)) {
66
+ if (/\/node@\d+\//.test(path)) return way("brew", "Homebrew", "brew install node@22 && brew link --overwrite --force node@22");
67
+ return way("brew", "Homebrew", shown(RUNNABLE.brew), has("brew") ? RUNNABLE.brew : null);
68
+ }
69
+ if (platform === "win32") return way("windows", "the Windows installer", "winget upgrade OpenJS.NodeJS.LTS (or the installer from https://nodejs.org/en/download)");
70
+ return way("system", "your system's own package", "install Node 22 from https://nodejs.org/en/download (or your distribution's NodeSource package)");
71
+ }
72
+
73
+ /** The Python package: run through pipx where pipx is, else the line that installs it. */
74
+ export function pythonWay(args, has = (name) => Boolean(onPath(name))) {
75
+ if (has("pipx")) return { id: "pipx", shown: `pipx run worktrust ${args.join(" ")}`.trimEnd(), argv: [["pipx", "run", "worktrust", ...args]] };
76
+ if (has("python3") || has("python")) return { id: "pip", shown: `${has("python3") ? "python3" : "python"} -m pip install worktrust (then: worktrust ${args.join(" ")})`.replace(/ \)$/, ")"), argv: null };
77
+ return { id: "none", shown: "install Python 3.10 or later, then: pip install worktrust", argv: null };
78
+ }
79
+
80
+ /** What is said, the same bytes with or without a terminal. */
81
+ export function guidanceLines({ version = process.versions.node, manager, python }) {
82
+ return [
83
+ "",
84
+ ` Remote Agent needs Node 22.4 or later for its live connection. This computer runs Node ${version}.`,
85
+ " Measuring your work keeps working as it is.",
86
+ "",
87
+ " Ways forward:",
88
+ ` 1 Update this computer's Node (${manager.name})`,
89
+ ` ${manager.shown}`,
90
+ " 2 Use the Python package, which brings its own Node",
91
+ ` ${python.shown}`,
92
+ ];
93
+ }
94
+
95
+ const runArgv = (argv) => new Promise((resolve) => {
96
+ const child = spawn(argv[0], argv.slice(1), { stdio: "inherit" });
97
+ child.on("error", () => resolve(1));
98
+ child.on("exit", (code) => resolve(code ?? 1));
99
+ });
100
+ const typedLine = async (question) => { const prompt = createInterface({ input: process.stdin, output: process.stdout }); const answer = (await prompt.question(question)).trim().toLowerCase(); prompt.close(); return answer; };
101
+ const nodeOnPath = () => { const node = onPath("node"); if (!node) return null; const asked = spawnSync(node, ["--version"], { encoding: "utf8", timeout: 10_000 }); return asked.status === 0 ? { path: realpathSync(node), version: asked.stdout.trim().replace(/^v/, "") } : null; };
102
+
103
+ /**
104
+ * A `remote` command on a Node without the WebSocket: say it, show the ways, and (a person's terminal only) take one on a
105
+ * typed yes. `io`: the CLI's say, fail, ask and has. `deps` are the seams the tests hold: interactive, line, run, findNode,
106
+ * rerun(nodePath, args) → the exit code of this same CLI started again under that Node, connected.
107
+ */
108
+ export async function guideToNode(io, args, deps = {}) {
109
+ const sentence = remoteNeedsNode(false, deps.version ?? process.versions.node);
110
+ const manager = deps.manager ?? nodeManager(), python = deps.python ?? pythonWay(args);
111
+ const interactive = deps.interactive ?? (Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY) && !io.has("yes"));
112
+ // Started again: this same CLI (the launcher this process was started with, verified as always) under the Node just found.
113
+ const rerun = deps.rerun ?? ((nodePath, cliArgs) => runArgv([nodePath, process.argv[1], ...cliArgs]));
114
+ const run = deps.run ?? runArgv, again = `npx worktrust ${args.join(" ")}`.trimEnd();
115
+ for (const line of guidanceLines({ version: deps.version, manager, python })) io.say(line);
116
+ const leave = (words) => { io.say(` ${words}`); io.fail(sentence); };
117
+ if (!interactive) leave("Nothing was installed or changed.");
118
+ io.say(" q Leave");
119
+ const pick = await (deps.line ?? typedLine)(" Choose 1 or 2, or q to leave [1]: ");
120
+ const way = pick === "" || pick === "1" ? manager : pick === "2" ? python : null;
121
+ if (!way) leave("Nothing was installed or changed.");
122
+ if (!way.argv) leave(`That one is yours to run: ${way.shown}. Then run \`${again}\` again. Nothing was installed or changed.`);
123
+ io.say(` This runs: ${way.shown}`);
124
+ if (!(await io.ask("Run it now?", false))) leave("Nothing was run. Nothing was installed or changed.");
125
+ for (const argv of way.argv) { const code = await run(argv); if (code !== 0) leave(`\`${argv.join(" ")}\` ended with code ${code}. WorkTrust changed nothing.`); }
126
+ if (way === python) return; // pipx ran this same command with the Python package's own Node
127
+ const node = (deps.findNode ?? nodeOnPath)();
128
+ if (!node || !nodeIsEnough(node.version)) leave(`Node on this terminal's PATH is ${node ? `still ${node.version}` : "not found"}. Open a new terminal and run \`${again}\` again.`);
129
+ io.say(` ✓ Node is now ${node.version}.`);
130
+ // The session hook and the AI-app doors name a Node by its path: `update` under the new one repairs a path that moved.
131
+ if (deps.connected) { io.say(" Bringing the session hook and your AI apps onto it (npx worktrust update):"); await rerun(node.path, ["update"]); }
132
+ io.say(` Continuing: ${again}`);
133
+ process.exitCode = await rerun(node.path, args);
134
+ }
@@ -1 +1 @@
1
- {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"e8abb38c293b57b71d3a6163d6242d1f375e773372b91b6d8ce39c584c51262a","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"b38ea343eb95892d4164274be4184d6e34eade9d4c454e1dcf8bc7735736425e","README.md":"420c1a5489fa6097de712e4c70431c57fdbd1eda1ffb598a6a6ef3126b2ce3e8","SECURITY.md":"6a798d875f48ae84c3a677397e5611e03b94215944952e0f61e13f6cfc949745","chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","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":"d16df62414188bdff924a9cc694eabc79ee915b424b7b82b6509b8cde2f0650c","export-facts.mjs":"3bbb46c80e8678b5cea7e15dcbfc456a2b48595053241c2b3cea508092f9b917","git-commits.mjs":"af0ed45a2a42c8e17cabfb3649a2f524dbf80230f8a6ec1c6b775fed7d34dc9c","history-outbox.mjs":"85c70389effc5b4ec9d9b33af9192314e67f47af2752515b42a7959344ce2354","history-progress.mjs":"dcc25ee94b727f2605a763349a4d8764640335d6cf0043fb6108cebeed16dcb9","log-session.mjs":"167fe3718415fe690c9e4f7a3a993520e8c652edcf61184cc14cfec2db67d7bc","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"60e03bddf5dda48f311891699908ab50f5b66a3d60565fb131790516c91cbc1a","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"cd111cae0f53a25a2d878a158479abfb1ace353361454843f91a16d241101d46","project-modes.mjs":"ada26e68297fbeb90e4e91d75a90fd2d7cc107b999a9702840675b5a7529463e","remote-adapter-claude-code.mjs":"a5ef08186128d9fe4023944378bb0ff5682a8ae64ffdb07ef5e76cc51894d721","remote-adapter-codex.mjs":"d2fd6c61d9e3c4a45e9b10da1aa3c15d45c86629d6456e4a8d25ad95b13eb209","remote-adapter-opencode.mjs":"ddd7f3ec0b4ba92f4744453d60fda338b63550e3ec7b23fa3acc668df1d64eb7","remote-adapter-terminal.mjs":"9237d3747a25126fcdad42c0eab10e69393754388a6014b30fb0890b9c735888","remote-agent-switch.mjs":"7ff5448f29f05a47d7298d730b21243a1bcf8a215b434a0c7fbf5f3cb0889041","remote-approval-bridge.mjs":"092f17b7969e4f35bea064315d04dcde1faa6a3fd3e737dcc05aece82c7a37c4","remote-approvals.mjs":"5a371e049ceb154100a3b0c1900d8a2c1fc193b01e8069f11ce1690bcf4df3e1","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":"f2ce16401a2c63db6628c83b01b18c949e96545c5ff34ecb8d3d2bd70d473998","remote-coalesce.mjs":"cb0967d9cfe81e3892bcade8349d6814db98be8c2adbdb54df0b8d1b142f65d1","remote-codex-events.mjs":"58657d6070a50c837737cb85f5a1eaf9c2cbc4e1adfe3e970748ab3b2af94631","remote-daemon.mjs":"5dadcced9bd2c69be8c48afbaabbf50bd16879612ada0553aa2284a873907492","remote-endorse.mjs":"89eda4883567176703e01e44d83e987271bc2a6134e108f517b3b213719a21f9","remote-inventory.mjs":"43954e427141b4303ca13d22068d50bfc81e544b085bce335b8e8d59dc520468","remote-journal.mjs":"907ebd48c53162b22dc743ef95b53c1a6be6886a7495605b5cfa820b8de9d330","remote-live-preview.mjs":"faa70f9260ac05037204c2a0c3facf4ffe42f68408948390b341b453a2932289","remote-opencode-events.mjs":"3108375501ead2c2c78bce1435cc2a9fe6d2af1d7ff1fb42e12ff3e0f5d9af9c","remote-opencode-session.mjs":"681b201d833a7d7d025122b3a79663bcdc0a989aefd39d8018a28113d8810caf","remote-pairing.mjs":"536fa695d1d684314dd572e9af2b77266a4e20246b7105d946b5fb60039e8344","remote-pipeline-config.mjs":"00cde6a61ce21144c51ac56fce42fee159aa9dba6586218a7ea790ce4a6bd40b","remote-pipeline-parsers.mjs":"43ca0d332d7bc883c4759a754a555815ae5dfe133446b91ba9f2e48a350fa20f","remote-pipeline.mjs":"b856ead989b29ddb618ef69bbacd104bae2b02c9d1c5214291d08ce469a8b24e","remote-policy.mjs":"aacf7578537021ab3849095bb1f58f0ed12c453c6ca2ab1352a1716fb13b0ca4","remote-preview.mjs":"fe504ad6f83dcb4a4ebdcc018686a9a5a900c47cdf8c45b75e7d02e2f3056155","remote-projects.mjs":"d07997167d1f51139ff010c8753639e48c5cd33688568459e184eabb12bfff84","remote-protocol.mjs":"7b2a78e585983be40e240b9ab0b2e31a69e586bd72292071886c60b217d97a60","remote-qr.mjs":"b80e2b4a5bc020cf6ed92e91d06b327cb5197de1c35b3445a0fc2c7a3bf1ab3f","remote-release-plans.mjs":"11884a62b7d6dcccb5e154a26603bdf650f7b40f946329fb174d8c13729bec74","remote-releases.mjs":"fb08b72593ea00013c8b679e0c0d7dee95b0fd7cc5fd31b80ac575d0e340927d","remote-run.mjs":"c72c77fdd14115e66f1f2be383ca4f1363a4cecc9dced9cc48cbb3e4bb44bc66","remote-screen-approvals.mjs":"c43ab286d36a38d17639d155782ffa017f1a9b6806a09b82ed0142a1290b6000","remote-screen-push.mjs":"4ee8bd48d24b2c87581e9f33d8354a86381f7febd82f89ed509a7a87c1442608","remote-screen-states.mjs":"7c3c86a584bebf52461f3cab39c05ea2a13910061704d48fc622956e842940f7","remote-service.mjs":"1b9d4ecf99b667f2ab7c78fe1dfd5cf507cbb36c5bcad15bfa2a88c313ae758e","remote-session-list.mjs":"494fdbe20f0542806ac6c42ad149c52e2d3ace23a3a7567f96dc7e80d092c727","remote-sessions.mjs":"64ae363f8b5f38c58c21afbeaa7951d9592c608c3c83cceb78b21700a64467e9","remote-steered.mjs":"d7afde92c62c87abbdb84b0cfea2eea4752e90a2e453e52a54812c4fe0395190","remote-steering.mjs":"7ba22e6110cea3ac75a4f084f8f92a5bd90c31a19d3ce58a88a0843bdadea834","remote-store.mjs":"51645f8355923fe51de00233477266a99e94d4ca1f98f797f96e4ebb15927e9a","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":"9c89d6397852a6a971e3b31a8513fa09754f3870f4a28787abc3c333c80157dc"},"format":"worktrust-package/1","kind":"npm","version":"0.11.6"},"signature":"A9tyY6f40tkdbWhj6k3SUuqP9Bwr6X71sf566eDHl7l38iD-LfdZIaoh8qN131y3RyXT5zaV1kAw1gSyxeq3BA"}
1
+ {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"e8abb38c293b57b71d3a6163d6242d1f375e773372b91b6d8ce39c584c51262a","CHANGELOG.md":"c307685ed7d0afd3a75193e60d051a44fa56eb5278b2417c5182dc6f019f628f","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"b38ea343eb95892d4164274be4184d6e34eade9d4c454e1dcf8bc7735736425e","README.md":"6b714719a918730db48c4d329cd17ffbb83acc1941fb5d8e54f6e237f588b512","SECURITY.md":"6a798d875f48ae84c3a677397e5611e03b94215944952e0f61e13f6cfc949745","chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","cli-colour.mjs":"fa16b61ad179999c5c5365255182acf69bcba1eb5f5ce7b0e1e18c11f56130ae","cli-menu-remote.mjs":"6477b3c6986290a9ac70f1f7310abcc0415dfbe9e08f412c48dd41b60c4b6c44","cli-menu.mjs":"566a8cb60a050a506101b2900358d31c05907d66565ff194cd8efe9039e04ca5","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":"dc8d2c5721938373efa50729790128ddee5f26476cc24c710b1349c7fdbfee75","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":"612abff8a1013c28fd8f68402b8b9b466925e5289c6a1c6214c01c165cfa44cd","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":"81a0b8f83b5c0bbbd8c4599071585520cb6ad1ebaa2e5824c51bb5f6dd0ab6e8"},"format":"worktrust-package/1","kind":"npm","version":"0.11.8"},"signature":"xmOaY-LlVHJMteyQeg9o341pooWfqpDK5bRLmtoynFcHrdwtwH-xcmpuDwUAODbjHwI-gIMKbmI54WqI-bVxCQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worktrust",
3
- "version": "0.11.6",
3
+ "version": "0.11.8",
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": {
@@ -24,6 +24,7 @@
24
24
  "stack-rules.mjs",
25
25
  "runtime-install.mjs",
26
26
  "README.md",
27
+ "CHANGELOG.md",
27
28
  "SECURITY.md",
28
29
  "LICENSE",
29
30
  "AGENTS.md",
@@ -90,7 +91,16 @@
90
91
  "remote-pairing.mjs",
91
92
  "remote-qr.mjs",
92
93
  "remote-cli.mjs",
93
- "remote-agent-switch.mjs"
94
+ "remote-agent-switch.mjs",
95
+ "remote-settings.mjs",
96
+ "folder-picker.mjs",
97
+ "cli-menu.mjs",
98
+ "cli-menu-remote.mjs",
99
+ "cli-colour.mjs",
100
+ "node-guide.mjs",
101
+ "remote-countdown.mjs",
102
+ "remote-connections.mjs",
103
+ "remote-admin.mjs"
94
104
  ],
95
105
  "engines": {
96
106
  "node": ">=18"
@@ -2,9 +2,10 @@
2
2
  * THE CLAUDE CODE ADAPTER, STRUCTURED (2026-11-07). One managed process per remote session:
3
3
  *
4
4
  * claude -p --input-format stream-json --output-format stream-json --verbose
5
- * --permission-mode <the mode its help lists for "ask", or plan>
5
+ * --permission-mode <the mode its help lists for manual, edit (acceptEdits), plan or auto; 0.11.7>
6
6
  * --permission-prompt-tool mcp__worktrust_remote__approve --mcp-config <this session's file>
7
- * [--model <a model the computer listed>] (--session-id <uuid chosen here> | --resume <the agent's own id>)
7
+ * [--model <a model the computer listed>] [--effort <a level its help lists>] [--add-dir <extra projects the
8
+ * computer resolved from its own inventory>] (--session-id <uuid chosen here> | --resume <the agent's own id>)
8
9
  *
9
10
  * in the granted project folder, in a process group of its own. Every argument comes from this file and the closed start
10
11
  * options the computer checked again (checkStart); no text from the phone becomes an argument except a resume id that is
@@ -15,6 +16,7 @@
15
16
  */
16
17
  import { spawn } from "node:child_process";
17
18
  import { writeFileSync, rmSync } from "node:fs";
19
+ import { isAbsolute } from "node:path";
18
20
  import { PLAN_HINT } from "./remote-approval-bridge.mjs";
19
21
 
20
22
  export const APPROVAL_TOOL = "mcp__worktrust_remote__approve";
@@ -43,19 +45,37 @@ export const PLAN_TOOLS = Object.freeze(["mcp__worktrust_remote__plan_release",
43
45
  /** The one line the session's system prompt gains (owner, 2026-11-08: the agent arranges its own work); one text, the bridge's. */
44
46
  export { PLAN_HINT };
45
47
 
46
- export function claudeArgs({ features, mode, model, resume, sessionRef, mcpConfig }) {
47
- if (mode !== "ask" && mode !== "plan") throw new Error("the protocol offers the ask and plan modes only");
48
- const permission = mode === "plan" ? features.planMode : features.askMode;
48
+ /**
49
+ * WHAT A SESSION THAT EDITS WITHOUT ASKING MAY STILL NEVER EDIT (CLI 0.11.7). In `edit` (acceptEdits) and `auto` Claude Code
50
+ * writes without the permission tool, so the files the computer's policy keeps at the keyboard (remote-policy.mjs RULE_FILE
51
+ * and SCRIPT_FILE: permission rules, hooks, the repository's own config, and the files that say what a reviewed command
52
+ * runs) are denied outright: an edited package.json would turn the phone's next reviewed `npm test` into anything.
53
+ */
54
+ export const EDIT_MODE_DENY = Object.freeze(["**/.claude/**", "**/.mcp.json", "**/.claude.json", "**/.codex/**", "**/.cursor/**", "**/.git/**", "**/.husky/**", "**/.vscode/**", "**/.idea/**",
55
+ "**/.envrc", "**/.npmrc", "**/.yarnrc", "**/.yarnrc.yml", "**/.gitattributes", "**/.gitmodules", "**/package.json", "**/Makefile", "**/justfile", "**/pyproject.toml", "**/setup.py", "**/setup.cfg",
56
+ "**/tox.ini", "**/noxfile.py", "**/conftest.py", "**/pytest.ini", "**/Cargo.toml", "**/build.rs", "**/go.mod", "**/deno.json", "**/turbo.json", "**/nx.json", "**/*.config.js", "**/*.config.mjs", "**/*.config.cjs", "**/*.config.ts"]
57
+ .flatMap((glob) => [`Edit(${glob})`, `Write(${glob})`, `NotebookEdit(${glob})`]));
58
+
59
+ /** The agent mode (protocol AGENT_MODES; the older `ask` is `manual`) → Claude Code's own permission mode, from its help. */
60
+ const PERMISSION_OF = { ask: "askMode", manual: "askMode", plan: "planMode", edit: "editMode", auto: "autoMode" };
61
+
62
+ export function claudeArgs({ features, mode, model, resume, sessionRef, mcpConfig, effort = null, addDirs = [] }) {
63
+ if (!Object.hasOwn(PERMISSION_OF, mode)) throw new Error("the protocol offers the manual, edit, plan and auto modes only");
64
+ const permission = features[PERMISSION_OF[mode]];
49
65
  if (!permission) throw new Error("this Claude Code offers no such permission mode");
66
+ if (effort !== null && !(features.efforts ?? []).includes(effort)) throw new Error("this Claude Code offers no such effort level");
67
+ if (!Array.isArray(addDirs) || addDirs.some((d) => typeof d !== "string" || !isAbsolute(d))) throw new Error("an extra project is an absolute path the computer resolved");
68
+ if (addDirs.length > 0 && !features.addDir) throw new Error("this Claude Code takes no extra directories");
69
+ const unasked = mode === "edit" || mode === "auto";
50
70
  if (resume !== null && !isClaudeSessionId(resume)) throw new Error("a resume id is Claude Code's own session uuid");
51
71
  if (resume === null && !isClaudeSessionId(sessionRef)) throw new Error("a new session needs its uuid");
52
72
  if (model !== null && (typeof model !== "string" || model.startsWith("-") || !/^[A-Za-z0-9._:@\[\]-]{1,128}$/.test(model))) throw new Error("not a model name");
53
73
  if (!features.disallowed || !features.settingSources) throw new Error("this Claude Code cannot take deny rules or limit its setting sources");
54
74
  // --replay-user-messages: Claude Code echoes each user message as it reads it (isReplay), which is how a live steer is
55
75
  // known to have entered the running turn (remote-steering.mjs; measured on 2.1.286: at the next tool boundary).
56
- 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,
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 : []),
57
77
  ...(features.allowed ? ["--allowedTools", ...PLAN_TOOLS] : []), ...(features.appendPrompt ? ["--append-system-prompt", PLAN_HINT] : []),
58
- "--permission-prompt-tool", APPROVAL_TOOL, "--mcp-config", mcpConfig, ...(features.partial ? ["--include-partial-messages"] : []), ...(model ? ["--model", model] : []), ...(resume ? ["--resume", resume] : ["--session-id", sessionRef])];
78
+ "--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])];
59
79
  }
60
80
 
61
81
  /** The session's MCP config: our bridge only, its socket and its one-time token. Mode 0600, removed with the session. */
@@ -0,0 +1,109 @@
1
+ /**
2
+ * THIS COMPUTER'S SETTINGS FROM THE APP OR THE WEB (part B of CLI 0.11.7, owner 2026-11-12; docs/remote-agents/PROTOCOL.md
3
+ * §Managing a computer from the app). A phone or a browser sends ONE change, sealed in `device.configure { settings_change:
4
+ * { change, proof } }`, with a proof the Passport app signed after the person's authenticator answered for that exact change
5
+ * (crypto/admin.ts). This file is the computer's half:
6
+ *
7
+ * adminRefusal the gate, in this order: `remote admin on` at the keyboard (off: refused, whatever the proof); the proof
8
+ * verified against the issuer keys PINNED in this build, for THIS computer's device id and account, for
9
+ * the change as it arrived, unexpired, and its jti never spent here (spent ones are kept in
10
+ * admin-proofs.json past their expiry). Every refusal leaves every setting as it was.
11
+ * resolveAdminChange the change in the keyboard's own terms, resolved from THIS computer's lists by id: a folder by
12
+ * the id of a folder this computer suggested (folderSuggestions, its own HMAC), a new folder by one name
13
+ * made in the home folder (makeProjectsFolder), a root by its id, a connection by its device id. No
14
+ * path is ever read from the change: there is no field to read one from, and none is looked for.
15
+ * adminInventory what the settings page draws, sealed only for a phone that asked `extended`: the admin switch, the
16
+ * suggested folders with their project counts, and the connections by name.
17
+ *
18
+ * remote-settings.mjs applySettingsChange calls adminRefusal and resolveAdminChange for a source `{ kind: "admin" }` and
19
+ * then applies the result through the SAME rules as a typed command (checkRoot, MAX_ROOTS, removePhones).
20
+ */
21
+ import { createHmac } from "node:crypto";
22
+ import { homedir } from "node:os";
23
+ import { makeProjectsFolder, suggestedFolders } from "./folder-picker.mjs";
24
+ import { connections } from "./remote-connections.mjs";
25
+ import { checkRoot, rootLabel } from "./remote-projects.mjs";
26
+ import * as P from "./remote-protocol.mjs";
27
+ import { ensureRemoteDir, loadKeys, loadRoots, readJson, writeJson } from "./remote-store.mjs";
28
+
29
+ const SPENT_FILE = "admin-proofs.json";
30
+ const MAX_SPENT = 500;
31
+
32
+ /** A stable opaque id for a folder this computer suggests: an HMAC of its path under the computer's own secret. */
33
+ export const folderIdOf = (projectSecret, path) =>
34
+ `fld_${P.toBase64Url(createHmac("sha256", Buffer.from(projectSecret)).update(`worktrust-remote/v1/folder\n${path}`).digest().subarray(0, 16))}`;
35
+
36
+ /** The folders this computer suggests for projects (its own detected ones), each with its id and the root it already is. */
37
+ export function folderSuggestions(projectSecret, home = homedir(), roots = loadRoots()) {
38
+ return suggestedFolders(home).slice(0, 12).map((f) => {
39
+ const canonical = checkRoot(f.path);
40
+ const root = canonical.ok ? roots.find((r) => r.path === canonical.path) : null;
41
+ return { folder_id: folderIdOf(projectSecret, f.path), label: rootLabel(f.path), projects: Math.min(2000, f.projects), root_id: root?.root_id ?? null, path: f.path };
42
+ });
43
+ }
44
+
45
+ /** The inventory's part-B fields (sealed for an `extended` phone only, remote-daemon.mjs bodyFor). */
46
+ export function adminInventory({ projectSecret, settings }) {
47
+ return {
48
+ admin: settings.admin !== false,
49
+ folders: projectSecret ? folderSuggestions(projectSecret).map(({ path: _path, ...f }) => f) : [],
50
+ connections: connections().slice(0, 40).map((c) => ({ device_id: c.device_id, name: String(c.name).slice(0, 64), kind: c.kind, fingerprint: c.fingerprint, state: c.state, since: c.since ?? null, last_seen: c.last_seen ?? null })),
51
+ };
52
+ }
53
+
54
+ /** One use per proof: a jti is spent here before its change is applied, and kept until its proof has expired. */
55
+ export function spendAdminJti(jti, expSeconds, now = Date.now()) {
56
+ const kept = (readJson(SPENT_FILE, { spent: [] })?.spent ?? []).filter((s) => s && typeof s.jti === "string" && Number.isFinite(s.exp) && s.exp * 1000 + P.CLOCK_SKEW_MS >= now);
57
+ if (kept.some((s) => s.jti === jti)) return "seen";
58
+ ensureRemoteDir();
59
+ writeJson(SPENT_FILE, { spent: [...kept, { jti, exp: expSeconds }].slice(-MAX_SPENT) });
60
+ return "fresh";
61
+ }
62
+
63
+ const CODE_OF = { expired: "expired", lifetime: "expired", not_yet_valid: "expired", replay: "conflict" };
64
+ const SAID = { expired: "the approval expired (five minutes): change it again", conflict: "that approval was used already", not_allowed: "the approval does not hold for this computer and this change" };
65
+
66
+ /**
67
+ * THE GATE. `source`: { kind: "admin", proof, issuerKeys, claims, now } where issuerKeys are the daemon's pinned keys and
68
+ * claims this computer's own verified binding. → null when the change may be applied, else { reason, code } (the code is
69
+ * the protocol's reject reason: not_allowed, expired, conflict).
70
+ */
71
+ export function adminRefusal(change, source, settings) {
72
+ if (settings.admin === false) return { code: "not_allowed", reason: "managing this computer from the app or the web is off here (npx worktrust remote admin on)" };
73
+ const shaped = P.validate(P.ADMIN_CHANGE_SPEC, change);
74
+ if (!shaped.ok || P.adminChangeRule(change)) return { code: "not_allowed", reason: "not a change this computer takes from the app" };
75
+ if (typeof source?.proof !== "string" || !source.claims || !source.issuerKeys) return { code: "not_allowed", reason: SAID.not_allowed };
76
+ const verified = P.verifyAdminProof(source.proof, { issuerKeys: source.issuerKeys, now: source.now ?? Date.now(), deviceId: source.claims.device_id, sub: source.claims.sub, change, spendJti: (jti, exp) => spendAdminJti(jti, exp, source.now ?? Date.now()) });
77
+ if (!verified.ok) { const code = CODE_OF[verified.code] ?? "not_allowed"; return { code, reason: SAID[code] }; }
78
+ return null;
79
+ }
80
+
81
+ /**
82
+ * The change in the keyboard's terms, resolved from this computer's own lists by id; → { ok: true, change, setting } or
83
+ * { ok: false, code: "not_found" | "unsupported", reason }.
84
+ */
85
+ export function resolveAdminChange(change, projectSecret = loadKeys()?.projectSecret) {
86
+ const missing = (reason) => ({ ok: false, code: "not_found", reason });
87
+ const setting = P.settingOf(change);
88
+ if (change.what === "modes") return { ok: true, setting, change: { what: "modes", [change.allowed ? "allow" : "deny"]: change.mode } };
89
+ if (change.what === "folder") {
90
+ const found = projectSecret ? folderSuggestions(projectSecret).find((f) => f.folder_id === change.folder_id) : null;
91
+ return found ? { ok: true, setting, change: { what: "roots", add: found.path, git_init: false } } : missing("that folder is not one this computer suggests any more");
92
+ }
93
+ if (change.what === "new_folder") {
94
+ if (!P.adminFolderNameOk(change.name)) return { ok: false, code: "unsupported", reason: "one folder name" };
95
+ const made = makeProjectsFolder(change.name);
96
+ return made.ok ? { ok: true, setting, change: { what: "roots", add: made.path, git_init: true } } : { ok: false, code: "unsupported", reason: made.reason };
97
+ }
98
+ if (change.what === "root") {
99
+ const root = loadRoots().find((r) => r.root_id === change.root_id);
100
+ if (!root) return missing("no root by that id here");
101
+ if (change.act === "remove") return { ok: true, setting, change: { what: "roots", remove: root.root_id } };
102
+ return { ok: true, setting, change: { what: "roots", add: root.path, git_init: change.act === "git_init_on" } };
103
+ }
104
+ const link = connections().find((c) => c.device_id === change.device_id);
105
+ return link ? { ok: true, setting, change: { what: "connections", remove: link.fingerprint } } : missing("no phone or browser by that id is linked here");
106
+ }
107
+
108
+ /** The words the run terminal shows for a change from the app (remote-run.mjs notice). */
109
+ export const SETTING_WORDS = Object.freeze({ modes: "This computer's allowed modes", folders: "This computer's folders", roots: "This computer's roots", connections: "This computer's connections" });
@@ -20,7 +20,7 @@ import { createServer } from "node:net";
20
20
  import { chmodSync, existsSync, mkdirSync, rmSync } from "node:fs";
21
21
  import { join } from "node:path";
22
22
  import * as P from "./remote-protocol.mjs";
23
- import { classifyAction, phoneMayDecide } from "./remote-policy.mjs";
23
+ import { classifyAction, phoneMayDecide, projectForAction } from "./remote-policy.mjs";
24
24
 
25
25
  export const APPROVAL_LIFETIME_MS = 5 * 60_000;
26
26
 
@@ -42,7 +42,7 @@ export function createApprovals(ctx) {
42
42
  /** One permission request from the bridge → the answer the bridge gives Claude Code. */
43
43
  async function request(session, toolName, input, preset = null) {
44
44
  if (ctx.paused()) return deny("WorkTrust remote is paused on this computer; denied");
45
- const { action, reason } = preset ?? classifyAction(session.adapter, toolName, input, session.projectPath);
45
+ const { action, reason } = preset ?? classifyAction(session.adapter, toolName, input, projectForAction(session, input));
46
46
  if (!phoneMayDecide(action)) {
47
47
  ctx.emit(session.session_id, "agent.output_delta", { stream: "tool", offset: 0, text: `Denied on the computer (${action.tool}): ${reason}` }, session.command_id);
48
48
  return deny(`WorkTrust remote: ${reason}`);