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.
@@ -0,0 +1,148 @@
1
+ /**
2
+ * THE MENU'S DEEPER LEVELS (CLI 0.11.7; 0.11.8: every item says in one sentence what it does, `info`, beside its command, `hint`): Remote Agent ›, its projects, roots, allowed modes and connections, and the history and
3
+ * preservation choices. Each item still runs one direct command (runShown), named in its muted line; this file only reads
4
+ * the remote settings to label the items and never writes one itself: a change goes through the command, so it goes
5
+ * through applySettingsChange (remote-settings.mjs) like a typed one. Folders are chosen without typing (folder-picker.mjs).
6
+ */
7
+ import { homedir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { choose, runShown, typed } from "./cli-menu.mjs";
10
+ import { makeProjectsFolder, pickFolder, pickerCommand, suggestedFolders } from "./folder-picker.mjs";
11
+ import { connections } from "./remote-connections.mjs";
12
+ import { loadIdentity, loadProjects, loadRoots, loadSettings } from "./remote-store.mjs";
13
+ import { allowedModes } from "./remote-settings.mjs";
14
+
15
+ const BACK = { label: "← Back", hint: "Esc", info: "Returns to the list before this one.", back: true };
16
+ const tilde = (path) => (path.startsWith(homedir()) ? `~${path.slice(homedir().length)}` : path);
17
+
18
+ /** Loop one level: each pick runs, Back or Esc returns; a pick that returns false ends the menu (Ctrl+C after a command). */
19
+ async function level(term, header, title, build) {
20
+ for (;;) {
21
+ const picked = await choose(term, { header, title, items: build() });
22
+ if (picked === "quit") return false;
23
+ if (picked === "back" || picked.item.back) return true;
24
+ if (picked.item.run && (await picked.item.run()) === false) return false;
25
+ }
26
+ }
27
+
28
+ /** The folder the system picker chose, or a typed path where there is no picker. */
29
+ async function chooseFolder(term) {
30
+ const command = pickerCommand();
31
+ if (command) { term.restore(); const path = await pickFolder(command); term.enter(); return path; }
32
+ return typed(term, "No folder picker on this system. Type the folder's path:");
33
+ }
34
+
35
+ /** Roots › Add folders: the suggested folders, ticked with Space, a new folder, or the system's picker. */
36
+ async function addRoots(term, io, header) {
37
+ const have = new Set(loadRoots().map((r) => r.path));
38
+ const offered = suggestedFolders().filter((f) => !have.has(f.path));
39
+ const items = [
40
+ ...offered.map((f) => ({ label: tilde(f.path), note: { text: `${f.projects} project${f.projects === 1 ? "" : "s"} found`, tone: "dim" }, info: "Space ticks it; Enter adds the ticked folders as roots.", tick: true, path: f.path })),
41
+ { label: "+ Make a new folder for my projects", make: true, hint: "npx worktrust remote roots add <folder> --git-init", info: "Asks for a name (Projects by default), makes the folder in your home folder and adds it; new projects in it get git init." },
42
+ { label: "Choose another folder…", pick: true, hint: "npx worktrust remote roots add <folder>", info: "Opens the system's folder picker and adds the folder you choose." },
43
+ BACK,
44
+ ];
45
+ const picked = await choose(term, { header, title: "Add folders where your projects live", items, multi: true });
46
+ if (picked === "quit") return false;
47
+ if (picked === "back" || picked.item.back) return true;
48
+ const chosen = picked.ticked.map((i) => ({ path: i.path, gitInit: false }));
49
+ if (picked.item.make) {
50
+ const name = await typed(term, "Name of the new folder in your home folder:", "Projects");
51
+ term.enter();
52
+ if (name) { const made = makeProjectsFolder(name); if (made.ok) chosen.push({ path: made.path, gitInit: true }); else { term.write(` ${made.reason}\n`); await term.anyKey(); } }
53
+ }
54
+ if (picked.item.pick) { const path = await chooseFolder(term); term.enter(); if (path) chosen.push({ path, gitInit: false }); }
55
+ for (const c of chosen) if ((await runShown(term, io, ["remote", "roots", "add", c.path, ...(c.gitInit ? ["--git-init"] : [])])) === false) return false;
56
+ return true;
57
+ }
58
+
59
+ function rootsMenu(term, io, header) {
60
+ return level(term, header, "Roots for new projects", () => [
61
+ { label: "+ Add folders", hint: "npx worktrust remote roots add <folder>", info: "Opens a list of folders to tick. A phone may open the projects in a root and create new ones there.", run: () => addRoots(term, io, header) },
62
+ ...loadRoots().map((r) => ({ label: `Remove ${tilde(r.path)}`, hint: `npx worktrust remote roots remove ${tilde(r.path)}`, info: "Takes this folder off the list; a phone can no longer open or create projects in it. No file is touched.", run: () => runShown(term, io, ["remote", "roots", "remove", r.path]) })),
63
+ BACK,
64
+ ]);
65
+ }
66
+
67
+ function projectsMenu(term, io, header) {
68
+ return level(term, header, "Projects a phone may steer an agent in", () => [
69
+ { label: "+ Add a project folder…", hint: "npx worktrust remote projects add <folder>", info: "Opens the system's folder picker; a phone may then steer an agent in the folder you choose.", run: async () => { const path = await chooseFolder(term); term.enter(); return path ? runShown(term, io, ["remote", "projects", "add", path]) : true; } },
70
+ ...loadProjects().map((p) => ({ label: `Remove ${tilde(p.path)}`, hint: `npx worktrust remote projects remove ${tilde(p.path)}`, info: "Takes this folder off the list; a phone can no longer start an agent in it. No file is touched.", run: () => runShown(term, io, ["remote", "projects", "remove", p.path]) })),
71
+ BACK,
72
+ ]);
73
+ }
74
+
75
+ function modesMenu(term, io, header) {
76
+ return level(term, header, "Agent modes a phone may start here", () => {
77
+ const allowed = allowedModes(loadSettings());
78
+ const toggle = (mode, words) => ({ label: `${words}: ${allowed.includes(mode) ? "allowed" : "not allowed"}`, hint: `npx worktrust remote modes ${allowed.includes(mode) ? "deny" : "allow"} ${mode}`, info: allowed.includes(mode) ? `Stops a phone from starting an agent in this mode${mode === "edit" ? "; auto goes with it" : ""}.` : `Lets a phone start an agent in this mode${mode === "auto" ? "; allowing auto allows edit too" : ""}.`,
79
+ run: () => runShown(term, io, ["remote", "modes", allowed.includes(mode) ? "deny" : "allow", mode]) });
80
+ return [
81
+ { label: "Manual (asks for every change): always allowed", info: "Always there: the agent asks you before every change.", disabled: true },
82
+ { label: "Plan (read-only): always allowed", info: "Always there: the agent reads and plans, and changes nothing.", disabled: true },
83
+ toggle("edit", "Edit automatically"),
84
+ toggle("auto", "Auto (the agent's own automatic mode)"),
85
+ { label: "Status", hint: "npx worktrust remote modes status", info: "Shows which modes a phone may start here. It only reads.", run: () => runShown(term, io, ["remote", "modes", "status"]) },
86
+ BACK,
87
+ ];
88
+ });
89
+ }
90
+
91
+ function connectionsMenu(term, io, header) {
92
+ return level(term, header, "Connections to this computer", () => {
93
+ const list = connections();
94
+ return [
95
+ { label: "List them", hint: "npx worktrust remote connections", info: "Shows every phone and browser linked to this computer. It only reads.", run: () => runShown(term, io, ["remote", "connections"]) },
96
+ ...list.filter((c) => c.state === "pending").map((c) => ({ label: `Confirm ${c.name} (pending)`, hint: `npx worktrust remote phones confirm ${c.fingerprint}`, info: "Confirms this pending link, so it may steer agents here. Check the fingerprint on the device first.", run: () => runShown(term, io, ["remote", "phones", "confirm", c.fingerprint]) })),
97
+ ...list.map((c) => ({ label: `${c.name} · ${c.kind} · ${c.fingerprint}`, hint: `npx worktrust remote disconnect ${c.n}`, info: "Closes this connection; that device has to be linked again to come back. It asks twice.", run: () => runShown(term, io, ["remote", "disconnect", c.fingerprint]) })),
98
+ ...(list.length > 0 ? [{ label: "Close all connections", hint: "npx worktrust remote disconnect --all", info: "Closes every connection to this computer. You type close all to confirm.", run: () => runShown(term, io, ["remote", "disconnect", "--all"]) }] : []),
99
+ BACK,
100
+ ];
101
+ });
102
+ }
103
+
104
+ /** Remote Agent ›. Approved already: "Link a phone" comes first and approving reads "approve again". */
105
+ export function remoteMenu(term, io, header) {
106
+ return level(term, header, "Remote Agent", () => {
107
+ const approved = Boolean(loadIdentity()), settings = loadSettings();
108
+ const approveMenu = { label: approved ? "Approved ✓ · approve again ›" : "Approve this computer ›", hint: approved ? "npx worktrust remote app --repair" : "npx worktrust remote app | web", info: approved ? "Opens the two ways to approve this computer again; that gives it new keys, and linked phones link again." : "Opens the two ways to approve this computer for Remote Agent. Nothing changes yet.",
109
+ run: () => level(term, header, approved ? "Approve this computer again (new keys)" : "Approve this computer", () => [
110
+ { label: "With the WorkTrust app", hint: `npx worktrust remote app${approved ? " --repair" : ""}`, info: "Shows a QR here; you scan it with the WorkTrust app and approve this computer on your phone.", run: () => runShown(term, io, ["remote", "app", ...(approved ? ["--repair"] : [])]) },
111
+ { label: "In the browser", hint: `npx worktrust remote web${approved ? " --repair" : ""}`, info: "Opens WorkTrust in your browser, where you approve this computer.", run: () => runShown(term, io, ["remote", "web", ...(approved ? ["--repair"] : [])]) },
112
+ BACK,
113
+ ]) };
114
+ const link = { label: "Link a phone (QR here)", hint: "npx worktrust remote pair", info: "Shows a QR here; scanning it with the WorkTrust app links that phone to this computer.", run: () => runShown(term, io, ["remote", "pair"]) };
115
+ const paused = settings.paused !== null;
116
+ return [
117
+ ...(approved ? [link, approveMenu] : [approveMenu, link]),
118
+ { label: "Projects ›", hint: "npx worktrust remote projects", info: "Opens the folders a phone may steer an agent in, to add or remove one.", run: () => projectsMenu(term, io, header) },
119
+ { label: "Roots for new projects ›", hint: "npx worktrust remote roots", info: "Opens the folders whose projects a phone may open, and where it may create new ones.", run: () => rootsMenu(term, io, header) },
120
+ { label: "Allowed modes ›", hint: "npx worktrust remote modes", info: "Opens the agent modes a phone may start here: this computer is the ceiling.", run: () => modesMenu(term, io, header) },
121
+ { label: "Connections ›", hint: "npx worktrust remote connections", info: "Opens the phones and browsers linked here, to confirm or close one.", run: () => connectionsMenu(term, io, header) },
122
+ { label: paused ? "Resume" : "Pause", hint: `npx worktrust remote ${paused ? "resume" : "pause"}`, info: paused ? "Lets linked phones steer agents here again." : "Stops every phone from steering agents here until you resume; links and settings stay.", run: () => runShown(term, io, ["remote", paused ? "resume" : "pause"]) },
123
+ { label: "Status", hint: "npx worktrust remote status", info: "Shows whether Remote Agent is on, its service and what is linked. It only reads.", run: () => runShown(term, io, ["remote", "status"]) },
124
+ BACK,
125
+ ];
126
+ });
127
+ }
128
+
129
+ export function historyMenu(term, io, header) {
130
+ return level(term, header, "Import earlier history", () => [
131
+ { label: "This computer's earlier sessions", hint: "npx worktrust history", info: "Sends the sessions your AI apps still hold here as history. It shows the plan and asks first.", run: () => runShown(term, io, ["history"]) },
132
+ { label: "From your local archive", hint: "npx worktrust history --from-archive", info: "Sends what your local archive holds of sessions your AI apps already deleted. It shows the plan and asks first.", run: () => runShown(term, io, ["history", "--from-archive"]) },
133
+ { label: "From a ChatGPT or Claude export…", hint: "npx worktrust history --export <path>", info: "Asks for the export's path, then shows the plan and asks. These hours are reconstructed, never verified hours.", run: async () => { const path = await typed(term, "The export's path (the zip, its folder or conversations.json):", join(homedir(), "Downloads")); term.enter(); return path ? runShown(term, io, ["history", "--export", path]) : true; } },
134
+ { label: "From a copied session folder…", hint: "npx worktrust history --from-folder <dir>", info: "Opens the folder picker for your own copy of a session folder, then shows the plan and asks. Reconstructed hours.", run: async () => { const path = await chooseFolder(term); term.enter(); return path ? runShown(term, io, ["history", "--from-folder", path]) : true; } },
135
+ BACK,
136
+ ]);
137
+ }
138
+
139
+ export function preserveMenu(term, io, header) {
140
+ return level(term, header, "Preserve evidence", () => [
141
+ { label: "How long each AI app keeps its sessions", hint: "npx worktrust preserve", info: "Shows a report of how long each AI app here keeps its sessions. Nothing is changed or sent.", run: () => runShown(term, io, ["preserve"]) },
142
+ { label: "Keep them longer", hint: "npx worktrust preserve --apply", info: "Sets your AI apps to keep their sessions longer. It asks per change and backs each file up first.", run: () => runShown(term, io, ["preserve", "--apply"]) },
143
+ { label: "Make a local archive", hint: "npx worktrust preserve --archive", info: "Writes a metadata-only, hash-chained record of the measured days to ~/AI-Evidence. Nothing is sent.", run: () => runShown(term, io, ["preserve", "--archive"]) },
144
+ { label: "Check the archive", hint: "npx worktrust preserve --verify", info: "Checks that record: every hash, the chain, each day's root and signature. It only reads.", run: () => runShown(term, io, ["preserve", "--verify"]) },
145
+ { label: "Count hours from the archive", hint: "npx worktrust preserve --summary", info: "Counts hours, tokens per model and parallel sessions from that record. It only reads.", run: () => runShown(term, io, ["preserve", "--summary"]) },
146
+ BACK,
147
+ ]);
148
+ }
package/cli-menu.mjs ADDED
@@ -0,0 +1,245 @@
1
+ /**
2
+ * THE MENU (CLI 0.11.7, owner 2026-11-12: "a navigable menu"). Bare `npx worktrust` in a person's own terminal opens it;
3
+ * everything else is exactly as before. It opens ONLY when menuWanted says so: stdin and stdout are both terminals, no
4
+ * argument at all (so no --yes, --dry-run or --device), not relayed (WORKTRUST_RELAYED), not started by a hook or the MCP
5
+ * door (their WORKTRUST_HOOK_INPUT / WORKTRUST_MCP_TOKEN), not in an AI agent's shell (worktrust.mjs refuses the bare
6
+ * command there before it gets here), and not turned off (WORKTRUST_MENU=off). Hooks, MCP and scripts never wait for a key.
7
+ *
8
+ * Each item runs the direct command it shows in its muted line, as a child of this CLI with the terminal handed over
9
+ * (io.runCli), so people learn the short form and every command keeps its own questions and its own guards. Keys: ↑/↓
10
+ * move, Enter opens, Esc or ← goes back one level, q quits from the top, 1 to 9 jump, Ctrl+C quits. Raw mode and the
11
+ * cursor are restored on every way out (quit, Ctrl+C, an error).
12
+ *
13
+ * 0.11.8 (owner, 2026-11-13): Update comes first and says whether there is something to update; every item carries one plain
14
+ * sentence under it; the menu is redrawn IN PLACE (createTerminal) and never left in the scrollback; colours carry meaning
15
+ * and are off wherever cli-colour.mjs says so (NO_COLOR, --no-color, a pipe). A terminal without cursor addressing
16
+ * (TERM=dumb) gets no menu: the bare command runs as it always did.
17
+ */
18
+ import { emitKeypressEvents } from "node:readline";
19
+ import { createInterface } from "node:readline/promises";
20
+ import { busyWith, clip, coloursFor, visibleLength } from "./cli-colour.mjs";
21
+ import { loadIdentity, loadSettings } from "./remote-store.mjs";
22
+
23
+ /** Whether bare `npx worktrust` opens the menu here. Pure: the caller passes what it knows. */
24
+ export function menuWanted({ args: given = [], env = {}, stdinTTY = false, stdoutTTY = false, agentShell = null } = {}) {
25
+ const args = given.filter((arg) => arg !== "--no-color" && arg !== "--no-colour"); // how it looks, not what it does
26
+ if (args.length !== 0 || !stdinTTY || !stdoutTTY || agentShell) return false;
27
+ if (env.WORKTRUST_MENU === "off" || env.WORKTRUST_RELAYED === "1" || env.WORKTRUST_HOOK_INPUT || env.WORKTRUST_MCP_TOKEN) return false;
28
+ if (env.TERM === "dumb") return false; // no cursor addressing: the menu could only be printed again and again
29
+ return true;
30
+ }
31
+
32
+ /** The menu's painters: by this process's own terminal, environment and arguments (cli-colour.mjs colourWanted). */
33
+ let paint = coloursFor(process.stdout);
34
+ export const muted = (text) => paint.dim(text);
35
+
36
+ /**
37
+ * The terminal, in raw mode while a list waits for a key; restore() always puts it back.
38
+ *
39
+ * THE MENU IS REDRAWN IN PLACE (0.11.8, owner 2026-11-13: the whole menu stood four times in the scrollback before the chosen
40
+ * command ran). 0.11.7 cleared the screen for every redraw, and a terminal keeps a cleared screen in its scrollback: each arrow
41
+ * key and each return from a command left one more copy. Now draw() remembers how many lines the menu took and the next
42
+ * draw goes the cursor up that many, clears to the end of the screen and writes the new lines, in ONE write (no flicker).
43
+ * erase() takes the menu's own lines away before anything else speaks (a command's output, a question), so what stays in
44
+ * the scrollback is what happened, never a menu. A resize cannot trust the count (lines may have wrapped): reset() clears
45
+ * the visible screen once and the menu is drawn once. No line ever wraps: draw() cuts each to the terminal's width.
46
+ */
47
+ export function createTerminal(input = process.stdin, output = process.stdout) {
48
+ let raw = false, drawn = 0;
49
+ const size = () => ({ columns: output.columns || 80, rows: output.rows || 24 });
50
+ const up = () => (drawn > 0 ? `\x1b[${drawn}A\r\x1b[J` : "");
51
+ const draw = (lines) => { const { columns } = size(); output.write(`${up()}${lines.map((line) => clip(line, columns - 1)).join("\n")}\n`); drawn = lines.length; };
52
+ const erase = () => { if (drawn > 0) output.write(up()); drawn = 0; };
53
+ const reset = () => { output.write("\x1b[H\x1b[J"); drawn = 0; };
54
+ /** Text that is not the menu (a reason, a result): the menu's lines go first, and the next draw starts below it. */
55
+ const write = (text) => { erase(); output.write(text); };
56
+ const enter = () => { emitKeypressEvents(input); if (input.isTTY && !raw) { input.setRawMode(true); raw = true; } input.resume(); output.write("\x1b[?25l"); };
57
+ const restore = () => { if (input.isTTY && raw) { try { input.setRawMode(false); } catch { /* gone */ } raw = false; } input.pause(); output.write("\x1b[?25h"); };
58
+ /** The next key, or { name: "resize" } once the terminal's size has settled (many resize events, one answer). */
59
+ const key = () => new Promise((resolve) => {
60
+ let timer = null;
61
+ const done = (value) => { input.off("keypress", onKey); output.off?.("resize", onResize); clearTimeout(timer); resolve(value); };
62
+ const onKey = (str, k = {}) => done({ str, name: k.name ?? str, ctrl: Boolean(k.ctrl) });
63
+ const onResize = () => { clearTimeout(timer); timer = setTimeout(() => done({ name: "resize" }), 60); };
64
+ input.on("keypress", onKey);
65
+ output.on?.("resize", onResize);
66
+ });
67
+ /** A real key: a resize while "Press any key" stands is not one. */
68
+ const anyKey = async () => { for (;;) { const k = await key(); if (k.name !== "resize") return k; } };
69
+ return { write, draw, erase, reset, size, enter, restore, key, anyKey };
70
+ }
71
+
72
+ /**
73
+ * The lines of one list, as text. Pure: `view` is what choose holds, `columns` and `rows` the terminal's size. Each item is
74
+ * its label with the command it runs dimmed beside it, and under it ONE plain sentence saying what it does and what Enter
75
+ * does (owner, 2026-11-13; folded over two lines where the terminal is narrow). The chosen item is marked by `>` and by its ground, never by colour alone. A list taller than
76
+ * the terminal first keeps the sentence for the chosen item only, then shows the items around it: a menu taller than the
77
+ * screen could not be redrawn in place.
78
+ */
79
+ export function menuFrame({ header = [], title = null, items, at = 0, ticked = new Set(), multi = false, top = false, footer = null }, { rows = 24, columns = 100, p = paint } = {}) {
80
+ const head = [...header, ...(title ? ["", ` ${p.bold(title)}`] : []), ""];
81
+ const foot = ["", ` ${p.dim(footer ?? (multi ? "↑/↓ move · Space tick · Enter confirm · Esc back" : `↑/↓ move · Enter open · ${top ? "q quit" : "Esc back"} · 1-9 jump`))}`];
82
+ const room = Math.max(3, rows - 1 - head.length - foot.length);
83
+ const box = (item) => (multi && item.tick ? `[${ticked.has(item.label) ? "x" : " "}] ` : "");
84
+ const named = (item) => `${box(item)}${item.label}${item.note ? ` · ${item.note.text}` : ""}`;
85
+ // The commands stand in one column beside the names (a name longer than 44 pushes only its own command).
86
+ const column = Math.min(44, Math.max(0, ...items.filter((item) => item.hint).map((item) => visibleLength(named(item)))));
87
+ const line = (item, i) => {
88
+ const label = ` ${i < 9 ? i + 1 : " "} ${box(item)}${item.label} `;
89
+ const note = item.note ? `· ${p[item.note.tone]?.(item.note.text) ?? item.note.text}` : "";
90
+ const name = i === at ? p.inverse(label) : item.disabled ? p.dim(label) : p.bold(label);
91
+ return `${i === at ? ">" : " "} ${name}${note}${item.hint ? `${" ".repeat(Math.max(0, column - visibleLength(named(item))) + 3)}${p.dim(item.hint)}` : ""}`;
92
+ };
93
+ // The sentence, on a narrow terminal over two lines at most: folded at a space, never cut by the terminal itself.
94
+ const fold = (text, width) => { if (text.length <= width) return [text]; const cut = text.lastIndexOf(" ", width); return cut < 20 ? [text] : [text.slice(0, cut), text.slice(cut + 1)]; };
95
+ const about = (item) => (item.info ? fold(item.info, Math.max(30, columns - 9)).map((part) => ` ${part}`) : []);
96
+ const all = items.map((item, i) => ({ i, lines: [line(item, i), ...about(item)] }));
97
+ if (all.reduce((n, entry) => n + entry.lines.length, 0) <= room) return [...head, ...all.flatMap((entry) => entry.lines), ...foot];
98
+ const short = items.map((item, i) => (i === at ? [line(item, i), ...about(item)] : [line(item, i)]));
99
+ if (items.length + 2 <= room) return [...head, ...short.flat(), ...foot];
100
+ const span = Math.max(1, room - 4), from = Math.max(0, Math.min(at - Math.floor(span / 2), items.length - span));
101
+ return [...head, ` ${p.dim(from > 0 ? "↑ more" : "")}`, ...short.slice(from, from + span).flat(), ` ${p.dim(from + span < items.length ? "↓ more" : "")}`, ...foot];
102
+ }
103
+
104
+ /**
105
+ * One list: → { item } (Enter or a digit), "back" (Esc, ←), "quit" (q at the top, Ctrl+C). `items`: { label, hint?, info?,
106
+ * note?, disabled? }. `multi`: Space ticks an item that has `tick: true`; the ticked items come back as `ticked`. `header`:
107
+ * the lines, or a function giving them, asked at every draw so a state a command just changed shows at once.
108
+ */
109
+ export async function choose(term, { header = [], title, items, top = false, multi = false, footer = null }) {
110
+ let at = Math.max(0, items.findIndex((i) => !i.disabled));
111
+ const ticked = new Set(items.filter((i) => i.ticked).map((i) => i.label));
112
+ for (;;) {
113
+ term.draw(menuFrame({ header: typeof header === "function" ? header() : header, title, items, at, ticked, multi, top, footer }, term.size()));
114
+ const k = await term.key();
115
+ if (k.name === "resize") { term.reset(); continue; }
116
+ if (k.ctrl && k.name === "c") return "quit";
117
+ if (k.name === "up" || k.name === "k") { do at = (at - 1 + items.length) % items.length; while (items[at].disabled); continue; }
118
+ if (k.name === "down" || k.name === "j") { do at = (at + 1) % items.length; while (items[at].disabled); continue; }
119
+ if (k.name === "escape" || k.name === "left") { if (!top) return "back"; continue; }
120
+ if (k.name === "q" && top) return "quit";
121
+ if (multi && k.name === "space" && items[at].tick) { ticked.has(items[at].label) ? ticked.delete(items[at].label) : ticked.add(items[at].label); continue; }
122
+ if (/^[1-9]$/.test(k.str ?? "") && items[Number(k.str) - 1] && !items[Number(k.str) - 1].disabled) { at = Number(k.str) - 1; if (!multi) return { item: items[at] }; continue; }
123
+ if (k.name === "return" || k.name === "enter") return { item: items[at], ticked: items.filter((i) => ticked.has(i.label)) };
124
+ }
125
+ }
126
+
127
+ /** A line of text typed at the keyboard (out of raw mode), the default already there to edit; null when left empty. */
128
+ export async function typed(term, question, value = "") {
129
+ term.erase();
130
+ term.restore();
131
+ const prompt = createInterface({ input: process.stdin, output: process.stdout });
132
+ const answer = prompt.question(` ${question} `);
133
+ if (value) prompt.write(value);
134
+ const text = (await answer).trim();
135
+ prompt.close();
136
+ return text || null;
137
+ }
138
+
139
+ /** While a command runs, Ctrl+C is the command's (it reaches the child too); the menu stays. */
140
+ let busy = false;
141
+
142
+ /**
143
+ * Run one direct command with the terminal handed over, then wait for a key before the menu comes back. The menu's own
144
+ * lines are taken away first, so the scrollback reads: the command, its output, how it ended. The menu is then drawn once
145
+ * below (the next draw starts fresh).
146
+ */
147
+ export async function runShown(term, io, args, label = null) {
148
+ term.restore();
149
+ busy = true;
150
+ term.write(` ${muted(`› npx worktrust ${args.join(" ")}`.trimEnd())}${label ? ` ${label}` : ""}\n\n`);
151
+ let code = 1;
152
+ try { code = await io.runCli(args); } catch { code = 1; } finally { busy = false; }
153
+ term.enter();
154
+ term.write(`\n ${code === 0 ? paint.green("✓ Done.") : paint.yellow("! It ended with a message above.")} ${muted("Press any key for the menu.")}\n`);
155
+ const k = await term.anyKey();
156
+ return !(k.ctrl && k.name === "c");
157
+ }
158
+
159
+ /** What the Remote Agent item says where this Node has no WebSocket; Enter opens the ways forward (node-guide.mjs). */
160
+ export const REMOTE_NEEDS = "Needs Node 22.4 or later; the Python package bundles one. Enter shows the ways to get there.";
161
+
162
+ const newer = (a, b) => { const x = String(a).split(".").map(Number), y = String(b).split(".").map(Number); for (let i = 0; i < 3; i += 1) if (x[i] !== y[i]) return x[i] > y[i]; return false; };
163
+
164
+ /**
165
+ * What the Update item says beside its name (owner, 2026-11-13), from the state read again after every command, so it is
166
+ * true the moment an update finishes: this computer's installed version behind this CLI's ("0.11.7 → 0.11.8 available"),
167
+ * a newer CLI published than the one running, or "up to date (0.11.8)". Null when this computer is not connected.
168
+ */
169
+ export function updateNote(state) {
170
+ if (!state.connected) return null;
171
+ if (state.installed && newer(state.version, state.installed)) return { text: `${state.installed} → ${state.version} available`, tone: "yellow", behind: "computer" };
172
+ if (state.latest && newer(state.latest, state.version)) return { text: `${state.version} → ${state.latest} available`, tone: "yellow", behind: "cli" };
173
+ return { text: `up to date (${state.version})`, tone: "green", behind: null };
174
+ }
175
+
176
+ /** The header: the version, a newer one when the check says so, and this computer's state in one line. */
177
+ export function headerLines(state) {
178
+ const remote = (() => {
179
+ try {
180
+ const s = loadSettings();
181
+ if (!loadIdentity()) return "not set up";
182
+ return s.enabled ? (s.paused ? "paused" : "on") : "off";
183
+ } catch { return "unknown"; }
184
+ })();
185
+ return [
186
+ ` ${paint.bold(`WorkTrust CLI ${state.version}`)}${state.latest ? ` ${paint.yellow(`! ${state.latest} is out: quit, then npx -y worktrust@latest`)}` : ""}`,
187
+ ` ${state.connected ? `Connected as ${state.account ?? "this computer's account (not recorded: run Check this computer)"}` : "Not connected yet"} · Remote Agent ${remote}`,
188
+ ];
189
+ }
190
+
191
+ /**
192
+ * The top list (owner, 2026-11-13): Update first, then Check, then the rest as before. Pure but for the `run` closures.
193
+ * `open(args)` runs one direct command; `sub` holds the deeper levels.
194
+ */
195
+ export function topItems(state, open = () => true, sub = {}) {
196
+ const door = state.door === "off" ? "Off" : "On";
197
+ const note = updateNote(state);
198
+ const updateInfo = !state.connected ? "Needs a connected computer first: Check this computer connects it."
199
+ : note.behind === "cli" ? `A newer CLI is out. Quit (q) and run npx -y worktrust@latest to get it; Enter here refreshes this computer with ${state.version}.`
200
+ : note.behind === "computer" ? `Brings this computer's hook and AI-app doors from ${state.installed} to ${state.version}; your key and pairing stay.`
201
+ : "Brings this computer's hook and AI-app doors to this version again; your key and pairing stay.";
202
+ return [
203
+ { label: "Update WorkTrust", note, hint: "npx worktrust update", info: updateInfo, run: () => open(["update"]) },
204
+ { label: "Check this computer", hint: "npx worktrust", info: state.connected ? "Shows what is coupled here and finishes what still waits; a change asks first." : "Connects this computer: shows the plan, asks, then you approve it in your browser.", run: () => open([]) },
205
+ // Node before 22.4 has no WebSocket (0.11.8): the item stays, says why, and Enter opens the ways forward, not the levels.
206
+ state.remoteBlocked
207
+ ? { label: "Remote Agent", note: { text: "needs Node 22.4+", tone: "yellow" }, hint: "npx worktrust remote …", info: REMOTE_NEEDS, run: () => open(["remote"]) }
208
+ : { label: "Remote Agent ›", hint: "npx worktrust remote …", info: "Opens the choices for steering this computer's agents from your phone. Nothing changes yet.", run: () => sub.remote?.() },
209
+ { label: "Import earlier history ›", hint: "npx worktrust history …", info: "Opens the ways to send earlier sessions as history. Each one shows its plan and asks first.", run: () => sub.history?.() },
210
+ { label: "Preserve evidence ›", hint: "npx worktrust preserve …", info: "Opens the ways to keep your AI history on this computer. Nothing is sent.", run: () => sub.preserve?.() },
211
+ { label: `WorkTrust in your AI apps: ${door}`, hint: `npx worktrust mcp ${door === "On" ? "off" : "on"}`, info: door === "On" ? "Takes the WorkTrust door out of every AI app here; the session hook keeps measuring your hours." : "Puts the WorkTrust door back in your AI apps, so your AI can log finished work.", run: () => open(["mcp", door === "On" ? "off" : "on"]) },
212
+ { label: "Status", hint: "npx worktrust status", info: "Shows the key, the hook, the door and what this computer measured. It only reads.", run: () => open(["status"]) },
213
+ { label: "Disconnect this computer", hint: "npx worktrust disconnect", info: "Takes WorkTrust out of every AI app here and ends this computer's key. It asks first.", run: () => open(["disconnect"]) },
214
+ { label: "Help · all commands", hint: "npx worktrust help", info: "Lists every command and option. Tip: npx -y worktrust skips npm's own \"Ok to proceed?\" question.", run: () => open(["help"]) },
215
+ { label: "Quit", hint: "q", info: "Leaves the menu. Nothing keeps running.", quit: true },
216
+ ];
217
+ }
218
+
219
+ /** The top of the menu. `io`: { runCli(args) → Promise<code>, state() → { version, installed, latest, account, connected, door } }. */
220
+ // (remoteBlocked is added here: whether this Node lacks the WebSocket Remote Agent needs.)
221
+ export async function runMenu(io) {
222
+ paint = coloursFor(process.stdout);
223
+ const term = createTerminal();
224
+ const quit = () => { term.erase(); term.restore(); };
225
+ const onSignal = () => { if (busy) return; quit(); process.exit(130); };
226
+ process.on("SIGINT", onSignal);
227
+ process.on("SIGTERM", onSignal);
228
+ try {
229
+ term.enter();
230
+ const { remoteMenu, historyMenu, preserveMenu } = await import("./cli-menu-remote.mjs");
231
+ for (;;) {
232
+ // Read again after every command: the version line and the Update item say the new state the moment an update ends.
233
+ const state = { ...(await busyWith("Reading this computer's state", () => io.state())), remoteBlocked: typeof globalThis.WebSocket !== "function" };
234
+ const header = () => headerLines(state);
235
+ const items = topItems(state, (args) => runShown(term, io, args), { remote: () => remoteMenu(term, io, header), history: () => historyMenu(term, io, header), preserve: () => preserveMenu(term, io, header) });
236
+ const picked = await choose(term, { header, items, top: true });
237
+ if (picked === "quit" || picked === "back" || picked.item.quit) break;
238
+ if ((await picked.item.run()) === false) break;
239
+ }
240
+ } finally {
241
+ process.off("SIGINT", onSignal);
242
+ process.off("SIGTERM", onSignal);
243
+ quit();
244
+ }
245
+ }
@@ -1 +1 @@
1
- {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"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","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","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":"engine","version":"0.11.6"},"signature":"96m7Cc7_qCSTboTkayK7YsfopN-5oJI82WouPg4vtn2ZkoHlfl4Cgu3H3G800tJWNBiQoq01UUpq0srE2wG4Dw"}
1
+ {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"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","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","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":"engine","version":"0.11.8"},"signature":"OQuLPGd_-Uen4RtstQufMNJjjOg7v3NMIm74SPIv8gj9KBPM-Q-GSQ7lFSbKc46oqCQf2ceeMFO3rehwjG2OBA"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * FOLDERS WITHOUT TYPING (CLI 0.11.7, owner 2026-11-12), for the menu at this keyboard only: the folders a person's
3
+ * projects usually live in, with how many git projects each holds; the system's own folder picker; a new folder for
4
+ * projects; and which chosen folders macOS guards with its privacy prompt. Nothing here grants anything: every folder
5
+ * chosen still goes through the root and project rules (remote-settings.mjs applySettingsChange, remote-policy.mjs).
6
+ *
7
+ * The picker runs a FIXED program with fixed arguments, never a shell line and never a word from a phone: macOS
8
+ * `osascript -e 'POSIX path of (choose folder …)'`, Windows PowerShell's FolderBrowserDialog, Linux `zenity` when it is
9
+ * there. Without one (a Linux with no zenity, an SSH session) the person types the path, the only typed fallback.
10
+ */
11
+ import { spawn } from "node:child_process";
12
+ import { existsSync, lstatSync, mkdirSync, readdirSync, realpathSync, statSync } from "node:fs";
13
+ import { homedir } from "node:os";
14
+ import { delimiter, join, relative, sep } from "node:path";
15
+
16
+ export const SUGGESTED = Object.freeze(["Desktop", "Documents", "Developer", "Projects", "code", "src"]);
17
+ const isDir = (path) => { try { return statSync(path).isDirectory(); } catch { return false; } };
18
+
19
+ /** How many git projects lie directly inside `dir` (a folder holding .git); hidden folders are not counted. */
20
+ export function gitProjectsIn(dir) {
21
+ let n = 0;
22
+ try {
23
+ for (const d of readdirSync(dir, { withFileTypes: true }).slice(0, 2000)) {
24
+ if (d.name.startsWith(".") || !(d.isDirectory() || d.isSymbolicLink())) continue;
25
+ try { lstatSync(join(dir, d.name, ".git")); n += 1; } catch { /* not a git project */ }
26
+ }
27
+ } catch { return 0; }
28
+ return n;
29
+ }
30
+
31
+ /** The suggested folders that exist here, each with its git projects counted: [{ name, path, projects }]. */
32
+ export function suggestedFolders(home = homedir()) {
33
+ return SUGGESTED.map((name) => ({ name, path: join(home, name) })).filter((f) => isDir(f.path)).map((f) => ({ ...f, projects: gitProjectsIn(f.path) }));
34
+ }
35
+
36
+ const onPath = (bin, path = process.env.PATH ?? "") => path.split(delimiter).some((dir) => dir && existsSync(join(dir, bin)));
37
+
38
+ const PS_PICKER = "Add-Type -AssemblyName System.Windows.Forms; $d = New-Object System.Windows.Forms.FolderBrowserDialog; $d.Description = 'Choose a folder for WorkTrust Remote Agent'; if ($d.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { [Console]::Out.Write($d.SelectedPath) }";
39
+
40
+ /** The system's folder picker as { file, args }, or null when this system has none (then the path is typed). */
41
+ export function pickerCommand(platform = process.platform, has = onPath, env = process.env) {
42
+ if (platform === "darwin") return { file: "/usr/bin/osascript", args: ["-e", 'POSIX path of (choose folder with prompt "Choose a folder for WorkTrust Remote Agent")'] };
43
+ if (platform === "win32") return { file: join(env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe"), args: ["-NoProfile", "-STA", "-Command", PS_PICKER] };
44
+ if (platform === "linux" && (env.DISPLAY || env.WAYLAND_DISPLAY) && has("zenity")) return { file: "zenity", args: ["--file-selection", "--directory", "--title=Choose a folder for WorkTrust Remote Agent"] };
45
+ return null;
46
+ }
47
+
48
+ /** Open the picker and wait: the chosen folder, or null (cancelled, or no picker). */
49
+ export function pickFolder(command = pickerCommand()) {
50
+ if (!command) return Promise.resolve(null);
51
+ return new Promise((resolve) => {
52
+ let out = "";
53
+ const child = spawn(command.file, command.args, { stdio: ["ignore", "pipe", "ignore"], windowsHide: false });
54
+ child.stdout.setEncoding("utf8");
55
+ child.stdout.on("data", (chunk) => { out += chunk; });
56
+ child.on("error", () => resolve(null));
57
+ child.on("close", (code) => { const path = out.trim().replace(/[\\/]$/, ""); resolve(code === 0 && path ? path : null); });
58
+ });
59
+ }
60
+
61
+ /** A new folder's name: one segment, no leading dot. */
62
+ export const FOLDER_NAME = /^[A-Za-z0-9_-][A-Za-z0-9 ._-]{0,99}$/;
63
+
64
+ /** Make ~/<name> for new projects (nothing above or beside it); → { ok, path } or { ok: false, reason }. Existing is fine. */
65
+ export function makeProjectsFolder(name, home = homedir()) {
66
+ if (!FOLDER_NAME.test(name ?? "")) return { ok: false, reason: "a folder name: letters, digits, space, . _ -, not starting with a dot" };
67
+ const path = join(home, name);
68
+ if (isDir(path)) return { ok: true, path, made: false };
69
+ try { mkdirSync(path, { mode: 0o755 }); } catch { return { ok: false, reason: "that folder could not be made" }; }
70
+ return { ok: true, path, made: true };
71
+ }
72
+
73
+ const realOr = (path) => { try { return realpathSync(path); } catch { return path; } };
74
+ const under = (base, path) => { const rel = relative(base, path); return rel === "" || (!rel.startsWith("..") && !rel.startsWith(sep) && !/^[A-Za-z]:/.test(rel)); };
75
+
76
+ /**
77
+ * The folder macOS guards with its privacy prompt that `path` lies in (Desktop, Documents, Downloads, iCloud Drive), or
78
+ * null: elsewhere, or not macOS. A program launchd starts asks for it on its first read, mid-session, unless it was asked once.
79
+ */
80
+ export function protectedFolder(path, home = homedir(), platform = process.platform) {
81
+ if (platform !== "darwin") return null;
82
+ const real = realOr(path), h = realOr(home);
83
+ for (const [name, dir] of [["Desktop", "Desktop"], ["Documents", "Documents"], ["Downloads", "Downloads"], ["iCloud Drive", join("Library", "Mobile Documents")]]) if (under(join(h, dir), real)) return name;
84
+ return null;
85
+ }