worktrust 0.11.7 → 0.11.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +380 -0
- package/LICENSE +2 -0
- package/README.md +213 -307
- package/cli-colour.mjs +86 -0
- package/cli-menu-remote.mjs +131 -55
- package/cli-menu.mjs +245 -68
- package/engine-release.json +1 -1
- package/node-guide.mjs +134 -0
- package/package-release.json +1 -1
- package/package.json +4 -1
- package/remote-cli.mjs +2 -1
- package/worktrust.mjs +61 -23
package/cli-colour.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* COLOUR WITH MEANING (CLI 0.11.8, owner 2026-11-13). One small module, no dependency, used by the menu (cli-menu.mjs) and by
|
|
3
|
+
* the commands' status lines (worktrust.mjs `say`, so update, check, status, remote and the rest speak the same way):
|
|
4
|
+
*
|
|
5
|
+
* accent a spinner while something runs green a success line (✓, Done)
|
|
6
|
+
* yellow a warning (!) red an error (✗, `worktrust: …` on stderr; the exit code stays as it was)
|
|
7
|
+
* dim secondary text: the command an item runs, a hint bold a title
|
|
8
|
+
*
|
|
9
|
+
* NEVER COLOUR ALONE: a colour only wraps a line that already carries its word or symbol; with colours off the text is byte
|
|
10
|
+
* for byte what it was before 0.11.8. And colours are OFF (colourWanted) for anything a program reads: a hook, the MCP door,
|
|
11
|
+
* a pipe, CI. In order: a hook or the MCP door never, whatever is set; `--no-color` and NO_COLOR turn them off; FORCE_COLOR
|
|
12
|
+
* turns them on (0 or false: off); otherwise only on a terminal whose TERM is not `dumb`. Windows: Node's console layer
|
|
13
|
+
* translates these sequences on a real terminal from Windows 10 on; an older console stays plain.
|
|
14
|
+
*/
|
|
15
|
+
import { release } from "node:os";
|
|
16
|
+
|
|
17
|
+
/** Whether this stream gets colours. Pure: the caller passes what it knows. `machine`: a hook or the MCP door is speaking. */
|
|
18
|
+
export function colourWanted({ env = {}, args = [], isTTY = false, platform = "", osRelease = "", machine = false } = {}) {
|
|
19
|
+
if (machine || env.WORKTRUST_HOOK_INPUT || env.WORKTRUST_MCP_TOKEN) return false;
|
|
20
|
+
if (args.includes("--no-color") || args.includes("--no-colour")) return false;
|
|
21
|
+
if (env.NO_COLOR) return false;
|
|
22
|
+
if (env.FORCE_COLOR !== undefined && env.FORCE_COLOR !== "") return !["0", "false"].includes(String(env.FORCE_COLOR).toLowerCase());
|
|
23
|
+
if (!isTTY || env.TERM === "dumb") return false;
|
|
24
|
+
if (platform === "win32" && Number(String(osRelease).split(".")[0]) < 10) return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const SGR = { bold: "1", dim: "2", inverse: "7", red: "31", green: "32", yellow: "33", accent: "36" };
|
|
29
|
+
|
|
30
|
+
/** The painters for one answer of colourWanted. Off, each returns its text unchanged. */
|
|
31
|
+
export function painter(on) {
|
|
32
|
+
const wrap = (code) => (text) => (on ? `\x1b[${code}m${text}\x1b[0m` : text);
|
|
33
|
+
const p = Object.fromEntries(Object.entries(SGR).map(([name, code]) => [name, wrap(code)]));
|
|
34
|
+
/** A whole status line by the symbol or word it already carries; any other line is returned as it is. */
|
|
35
|
+
const status = (line) => {
|
|
36
|
+
if (!on || typeof line !== "string" || line === "") return line;
|
|
37
|
+
if (/^\s*✓ /.test(line) || /^\s*Done\b/.test(line)) return p.green(line);
|
|
38
|
+
if (/^\s*! /.test(line)) return p.yellow(line);
|
|
39
|
+
if (/^\s*✗ /.test(line) || /^worktrust: /.test(line)) return p.red(line);
|
|
40
|
+
if (/^\s*WorkTrust · /.test(line)) return p.bold(line);
|
|
41
|
+
return line;
|
|
42
|
+
};
|
|
43
|
+
return { on: Boolean(on), ...p, status };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The painters for a stream of this process (stdout by default), by this process's own environment and arguments. */
|
|
47
|
+
export function coloursFor(stream = process.stdout, { machine = false } = {}) {
|
|
48
|
+
return painter(colourWanted({ env: process.env, args: process.argv.slice(2), isTTY: Boolean(stream?.isTTY), platform: process.platform, osRelease: release(), machine }));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** What a person sees of a text: its length without the colour sequences. */
|
|
52
|
+
export const visibleLength = (text) => [...String(text).replace(/\x1b\[[0-9;]*m/g, "")].length;
|
|
53
|
+
|
|
54
|
+
/** A text cut to `width` visible characters (… at the cut), its colour sequences kept and closed. A line never wraps. */
|
|
55
|
+
export function clip(text, width) {
|
|
56
|
+
if (width < 1 || visibleLength(text) <= width) return text;
|
|
57
|
+
let out = "", seen = 0;
|
|
58
|
+
for (const part of String(text).split(/(\x1b\[[0-9;]*m)/)) {
|
|
59
|
+
if (part.startsWith("\x1b[")) { out += part; continue; }
|
|
60
|
+
for (const char of part) { if (seen === width - 1) return `${out}…${text.includes("\x1b[") ? "\x1b[0m" : ""}`; out += char; seen += 1; }
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A spinner in the accent colour while something runs: → stop(). Only on a real terminal with colours on; anywhere else it
|
|
69
|
+
* writes nothing at all, so a pipe, a hook and CI read the same bytes as before. stop() removes the line it drew.
|
|
70
|
+
* It draws on the line the cursor is on, which must be empty: start it between lines, never in the middle of one.
|
|
71
|
+
*/
|
|
72
|
+
export function spinner(words, { stream = process.stdout, paint = coloursFor(stream), interval = 80, delay = 150 } = {}) {
|
|
73
|
+
if (!paint.on || !stream?.isTTY) return () => {};
|
|
74
|
+
let at = 0, shown = false, stopped = false, timer = null;
|
|
75
|
+
const frame = () => { shown = true; stream.write(`\r ${paint.accent(FRAMES[at % FRAMES.length])} ${paint.dim(words)}\x1b[K`); at += 1; };
|
|
76
|
+
// Work that ends at once shows no spinner at all: a line that flashes is worse than none.
|
|
77
|
+
const wait = setTimeout(() => { frame(); timer = setInterval(frame, interval); timer.unref?.(); }, delay);
|
|
78
|
+
wait.unref?.();
|
|
79
|
+
return () => { if (stopped) return; stopped = true; clearTimeout(wait); clearInterval(timer); if (shown) stream.write("\r\x1b[K"); };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Run `work` behind a spinner; the spinner is gone before anything else is said, also when the work fails. */
|
|
83
|
+
export async function busyWith(words, work, options) {
|
|
84
|
+
const stop = spinner(words, options);
|
|
85
|
+
try { return await work(); } finally { stop(); }
|
|
86
|
+
}
|
package/cli-menu-remote.mjs
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* THE MENU'S DEEPER LEVELS (CLI 0.11.7): Remote Agent ›, its projects, roots, allowed modes and connections, and the history and
|
|
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
3
|
* preservation choices. Each item still runs one direct command (runShown), named in its muted line; this file only reads
|
|
4
4
|
* the remote settings to label the items and never writes one itself: a change goes through the command, so it goes
|
|
5
5
|
* through applySettingsChange (remote-settings.mjs) like a typed one. Folders are chosen without typing (folder-picker.mjs).
|
|
6
|
+
*
|
|
7
|
+
* 0.11.9 (owner, 2026-11-14): every sentence fits the one-row form (60 characters at most), and Remote Agent asks for the
|
|
8
|
+
* approval FIRST: what cannot work before it cannot be chosen (remoteItems).
|
|
6
9
|
*/
|
|
7
10
|
import { homedir } from "node:os";
|
|
8
11
|
import { join } from "node:path";
|
|
9
|
-
import { choose,
|
|
12
|
+
import { choose, remoteState, runShown, typed } from "./cli-menu.mjs";
|
|
10
13
|
import { makeProjectsFolder, pickFolder, pickerCommand, suggestedFolders } from "./folder-picker.mjs";
|
|
11
14
|
import { connections } from "./remote-connections.mjs";
|
|
12
15
|
import { loadIdentity, loadProjects, loadRoots, loadSettings } from "./remote-store.mjs";
|
|
13
16
|
import { allowedModes } from "./remote-settings.mjs";
|
|
14
17
|
|
|
15
|
-
const BACK = { label: "← Back", back: true };
|
|
18
|
+
const BACK = { label: "← Back", hint: "Esc", back: true }; // its name and its key say it: no sentence of its own (owner, 2026-11-14)
|
|
16
19
|
const tilde = (path) => (path.startsWith(homedir()) ? `~${path.slice(homedir().length)}` : path);
|
|
17
20
|
|
|
18
21
|
/** 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) {
|
|
22
|
+
async function level(term, header, title, build, io = null) {
|
|
20
23
|
for (;;) {
|
|
21
|
-
const picked = await choose(term, { header, title, items: build() });
|
|
24
|
+
const picked = await choose(term, { header, title: typeof title === "function" ? title() : title, items: build() });
|
|
22
25
|
if (picked === "quit") return false;
|
|
23
26
|
if (picked === "back" || picked.item.back) return true;
|
|
24
|
-
|
|
27
|
+
const result = picked.item.run ? await picked.item.run() : true;
|
|
28
|
+
await io?.state?.(); // the head above reads this computer again: what the command changed shows at once
|
|
29
|
+
if (result === false) return false;
|
|
30
|
+
if (result === "back") return true; // the step this level was for is done (0.11.9: approved): the level above draws again
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -37,9 +43,9 @@ async function addRoots(term, io, header) {
|
|
|
37
43
|
const have = new Set(loadRoots().map((r) => r.path));
|
|
38
44
|
const offered = suggestedFolders().filter((f) => !have.has(f.path));
|
|
39
45
|
const items = [
|
|
40
|
-
...offered.map((f) => ({ label:
|
|
41
|
-
{ label: "+ Make a new folder for my projects", make: true, hint: "
|
|
42
|
-
{ label: "Choose another folder…", pick: true, hint: "the
|
|
46
|
+
...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 })),
|
|
47
|
+
{ label: "+ Make a new folder for my projects", make: true, hint: "npx worktrust remote roots add <folder> --git-init", info: "Makes a folder in your home folder and adds it as a root." },
|
|
48
|
+
{ label: "Choose another folder…", pick: true, hint: "npx worktrust remote roots add <folder>", info: "Opens the folder picker and adds the folder you choose." },
|
|
43
49
|
BACK,
|
|
44
50
|
];
|
|
45
51
|
const picked = await choose(term, { header, title: "Add folders where your projects live", items, multi: true });
|
|
@@ -49,7 +55,7 @@ async function addRoots(term, io, header) {
|
|
|
49
55
|
if (picked.item.make) {
|
|
50
56
|
const name = await typed(term, "Name of the new folder in your home folder:", "Projects");
|
|
51
57
|
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.
|
|
58
|
+
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
59
|
}
|
|
54
60
|
if (picked.item.pick) { const path = await chooseFolder(term); term.enter(); if (path) chosen.push({ path, gitInit: false }); }
|
|
55
61
|
for (const c of chosen) if ((await runShown(term, io, ["remote", "roots", "add", c.path, ...(c.gitInit ? ["--git-init"] : [])])) === false) return false;
|
|
@@ -58,16 +64,16 @@ async function addRoots(term, io, header) {
|
|
|
58
64
|
|
|
59
65
|
function rootsMenu(term, io, header) {
|
|
60
66
|
return level(term, header, "Roots for new projects", () => [
|
|
61
|
-
{ label: "+ Add folders", hint: "npx worktrust remote roots add <folder>
|
|
62
|
-
...loadRoots().map((r) => ({ label: `Remove ${tilde(r.path)}`, hint: `npx worktrust remote roots remove ${tilde(r.path)}`, run: () => runShown(term, io, ["remote", "roots", "remove", r.path]) })),
|
|
67
|
+
{ label: "+ Add folders", hint: "npx worktrust remote roots add <folder>", info: "Choose folders whose projects a phone may open or add to.", run: () => addRoots(term, io, header) },
|
|
68
|
+
...loadRoots().map((r) => ({ label: `Remove ${tilde(r.path)}`, hint: `npx worktrust remote roots remove ${tilde(r.path)}`, info: "A phone can no longer use this folder. No file is touched.", run: () => runShown(term, io, ["remote", "roots", "remove", r.path]) })),
|
|
63
69
|
BACK,
|
|
64
70
|
]);
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
function projectsMenu(term, io, header) {
|
|
68
74
|
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>
|
|
70
|
-
...loadProjects().map((p) => ({ label: `Remove ${tilde(p.path)}`, hint: `npx worktrust remote projects remove ${tilde(p.path)}`, run: () => runShown(term, io, ["remote", "projects", "remove", p.path]) })),
|
|
75
|
+
{ label: "+ Add a project folder…", hint: "npx worktrust remote projects add <folder>", info: "Pick a folder a phone may steer an agent in.", run: async () => { const path = await chooseFolder(term); term.enter(); return path ? runShown(term, io, ["remote", "projects", "add", path]) : true; } },
|
|
76
|
+
...loadProjects().map((p) => ({ label: `Remove ${tilde(p.path)}`, hint: `npx worktrust remote projects remove ${tilde(p.path)}`, info: "A phone can no longer start an agent here. No file changes.", run: () => runShown(term, io, ["remote", "projects", "remove", p.path]) })),
|
|
71
77
|
BACK,
|
|
72
78
|
]);
|
|
73
79
|
}
|
|
@@ -75,74 +81,144 @@ function projectsMenu(term, io, header) {
|
|
|
75
81
|
function modesMenu(term, io, header) {
|
|
76
82
|
return level(term, header, "Agent modes a phone may start here", () => {
|
|
77
83
|
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}${mode === "
|
|
84
|
+
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 this mode${mode === "edit" ? "; auto goes too" : ""}.` : `Lets a phone start this mode${mode === "auto" ? "; that allows edit too" : ""}.`,
|
|
79
85
|
run: () => runShown(term, io, ["remote", "modes", allowed.includes(mode) ? "deny" : "allow", mode]) });
|
|
80
86
|
return [
|
|
81
|
-
{ label: "Manual
|
|
82
|
-
{ label: "Plan
|
|
87
|
+
{ label: "Manual: always allowed", info: "Always there: the agent asks before every change.", disabled: true },
|
|
88
|
+
{ label: "Plan: always allowed", info: "Always there: the agent reads and plans, changes nothing.", disabled: true },
|
|
83
89
|
toggle("edit", "Edit automatically"),
|
|
84
|
-
toggle("auto", "Auto
|
|
85
|
-
{ label: "Status", hint: "npx worktrust remote modes status", run: () => runShown(term, io, ["remote", "modes", "status"]) },
|
|
90
|
+
toggle("auto", "Auto mode"),
|
|
91
|
+
{ label: "Status", hint: "npx worktrust remote modes status", info: "Shows which modes a phone may start. It only reads.", run: () => runShown(term, io, ["remote", "modes", "status"]) },
|
|
86
92
|
BACK,
|
|
87
93
|
];
|
|
88
94
|
});
|
|
89
95
|
}
|
|
90
96
|
|
|
97
|
+
/**
|
|
98
|
+
* THE LINKED DEVICES, AS A TABLE (0.11.9, owner 2026-11-14): one row per connection: name, kind, since, last activity. Enter
|
|
99
|
+
* opens that connection's acts. Disconnect runs the same `remote disconnect <fingerprint>` a person types, with its typed
|
|
100
|
+
* confirmation (remote-connections.mjs, a security decision of 2026-11-12): the menu confirms nothing itself and fills nothing in.
|
|
101
|
+
*/
|
|
102
|
+
const day = (ms) => (Number.isFinite(ms) ? new Date(ms).toISOString().slice(0, 10) : "not known");
|
|
91
103
|
function connectionsMenu(term, io, header) {
|
|
92
104
|
return level(term, header, "Connections to this computer", () => {
|
|
93
|
-
const list = connections();
|
|
105
|
+
const list = connections(), wide = Math.min(20, Math.max(4, ...list.map((c) => c.name.length))), last = term.size().columns >= 72; // a narrow terminal keeps name, kind and since
|
|
106
|
+
if (list.length === 0) return [
|
|
107
|
+
{ label: "No phone or browser is linked yet.", info: "Link one with the row below.", disabled: true, quiet: "Nothing to open here." },
|
|
108
|
+
{ label: "Link a phone (QR here)", hint: "npx worktrust remote pair", info: "Shows a QR that links a phone to this computer.", run: () => runShown(term, io, ["remote", "pair"]) },
|
|
109
|
+
BACK,
|
|
110
|
+
];
|
|
111
|
+
const acts = (c) => () => level(term, header, `${c.name} · ${c.kind} · ${c.fingerprint}`, () => [
|
|
112
|
+
...(c.state === "pending" ? [{ label: "Confirm it", hint: `npx worktrust remote phones confirm ${c.fingerprint}`, info: "Confirms this link. Check the fingerprint on the device.", run: async () => ((await runShown(term, io, ["remote", "phones", "confirm", c.fingerprint])) === false ? false : "back") }] : []),
|
|
113
|
+
{ label: "Disconnect", hint: `npx worktrust remote disconnect ${c.fingerprint}`, info: "Closes it. You type its name or code to confirm.", run: async () => ((await runShown(term, io, ["remote", "disconnect", c.fingerprint])) === false ? false : "back") },
|
|
114
|
+
BACK,
|
|
115
|
+
], io);
|
|
94
116
|
return [
|
|
95
|
-
{ label: "
|
|
96
|
-
|
|
97
|
-
...list.map((c) => ({ label: `${c.name} · ${c.kind} · ${c.fingerprint}`, hint: `npx worktrust remote disconnect ${c.n} Enter: disconnect (asks twice)`, run: () => runShown(term, io, ["remote", "disconnect", c.fingerprint]) })),
|
|
98
|
-
...(list.length > 0 ? [{ label: "Close all connections", hint: "npx worktrust remote disconnect --all type close all to confirm", run: () => runShown(term, io, ["remote", "disconnect", "--all"]) }] : []),
|
|
117
|
+
...list.map((c) => ({ label: `${c.name.length > wide ? `${c.name.slice(0, wide - 1)}…` : c.name.padEnd(wide)} ${c.kind.padEnd(7)} since ${day(c.since)}${last ? ` last ${day(c.last_seen)}` : ""}${c.state === "pending" ? " pending" : ""}`, hint: `npx worktrust remote disconnect ${c.n}`, info: `Enter opens ${c.name} · ${c.fingerprint}.`, run: acts(c) })),
|
|
118
|
+
{ label: "Disconnect all…", hint: "npx worktrust remote disconnect --all", info: "Closes every connection. You type close all to confirm.", run: () => runShown(term, io, ["remote", "disconnect", "--all"]) },
|
|
99
119
|
BACK,
|
|
100
120
|
];
|
|
101
|
-
});
|
|
121
|
+
}, io);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* SHARING (0.11.9, owner 2026-11-14): what this computer sends, in words, and the switches that exist. Each switch runs the
|
|
126
|
+
* command a person types (`mcp off | on`, `remote pause | resume`); the session hook has no switch in the CLI (measuring is
|
|
127
|
+
* paused in WorkTrust under Sources, and `disconnect` takes it out), so its row says so and cannot be chosen. One app alone
|
|
128
|
+
* cannot be coupled or uncoupled by a command today, so there is no row per app. The state is read again at every draw.
|
|
129
|
+
*/
|
|
130
|
+
export function sharingItems(state, remote, act = {}) {
|
|
131
|
+
const doorOn = state.door === "on", live = ["approved", "paused"].includes(remote.word), paused = remote.word === "paused";
|
|
132
|
+
return [
|
|
133
|
+
{ label: `Session hook: ${state.hook === true ? "on" : state.hook === false ? "not installed" : "not known"}`, note: { text: "no switch here", tone: "dim" }, info: "Sends times, tokens, models and tools. Never content.", disabled: true, quiet: "Pause it under Sources." },
|
|
134
|
+
state.door === "on" || state.door === "off"
|
|
135
|
+
? { label: `WorkTrust in your AI apps: ${doorOn ? `on${Number.isInteger(state.apps) ? ` (${state.apps} app${state.apps === 1 ? "" : "s"})` : ""}` : "off"}`, hint: `npx worktrust mcp ${doorOn ? "off" : "on"}`, info: doorOn ? "On: your AI logs finished work. Enter takes the door out." : "Off: hours only. Enter puts the door back in your AI apps.", run: () => act.door?.(doorOn ? "off" : "on") }
|
|
136
|
+
: { label: "WorkTrust in your AI apps: not known", hint: "npx worktrust mcp status", info: "Its state could not be read. Enter shows it.", run: () => act.door?.("status") },
|
|
137
|
+
live
|
|
138
|
+
? { label: `Remote Agent: ${paused ? "paused" : "on"}`, hint: `npx worktrust remote ${paused ? "resume" : "pause"}`, info: paused ? "Paused: no phone steers agents here. Enter resumes." : "On: linked phones steer agents here. Enter pauses.", run: () => act.remote?.(paused ? "resume" : "pause") }
|
|
139
|
+
: { label: `Remote Agent: ${remote.word}`, hint: "npx worktrust remote …", info: "Lets your phone steer this computer's agents.", disabled: true, quiet: remote.word === "not known" ? "Its state could not be read." : "Set it up under Remote Agent." },
|
|
140
|
+
BACK,
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
export async function sharingMenu(term, io, header) {
|
|
144
|
+
for (;;) {
|
|
145
|
+
const state = await io.state();
|
|
146
|
+
const picked = await choose(term, { header, title: "Sharing", items: sharingItems(state, remoteState(), { door: (to) => runShown(term, io, ["mcp", to]), remote: (to) => runShown(term, io, ["remote", to]) }) });
|
|
147
|
+
if (picked === "quit") return false;
|
|
148
|
+
if (picked === "back" || picked.item.back) return true;
|
|
149
|
+
if ((await picked.item.run()) === false) return false;
|
|
150
|
+
}
|
|
102
151
|
}
|
|
103
152
|
|
|
104
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* WHETHER THIS COMPUTER IS APPROVED FOR REMOTE AGENT, in three states (0.11.9): true (its identity is here), false (none),
|
|
155
|
+
* null when the file could not be read (remote-store readJson refuses an unreadable or non-private one): not known is
|
|
156
|
+
* never "not approved".
|
|
157
|
+
*/
|
|
158
|
+
export function approval() { try { return Boolean(loadIdentity()); } catch { return null; } }
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Remote Agent's rows (owner, 2026-11-14: "first the approve, and once that succeeded you go on to the other steps"). Pure:
|
|
162
|
+
* `approved` is approval()'s answer, `act` what each row does. NOT APPROVED: the approval is first and chosen, and what
|
|
163
|
+
* cannot work before it cannot be chosen. By the code: `remote pair` and adding a project or a root refuse without this
|
|
164
|
+
* computer's remote keys (remote-cli.mjs needPaired, remote-settings.mjs applyRules), and no phone can be linked, so there
|
|
165
|
+
* is no connection to list and nothing to pause. Allowed modes is a local setting and Status only reads: both stay.
|
|
166
|
+
* APPROVED: Link a phone first, and approving again stays (new keys). NOT KNOWN: every row can be chosen and the title says so.
|
|
167
|
+
*/
|
|
168
|
+
export function remoteItems(approved, paused, act = {}) {
|
|
169
|
+
const wait = approved === false ? { disabled: true, quiet: "Approve this computer first.", note: { text: "not yet", tone: "dim" } } : {};
|
|
170
|
+
const approve = { label: approved ? "Approved ✓ · approve again ›" : "Approve this computer ›", hint: approved ? "npx worktrust remote app --repair" : "npx worktrust remote app | web", info: approved ? "Approve again: new keys, and linked phones link again." : "Needed once: your account allows steering this computer.", run: act.approve };
|
|
171
|
+
const link = { label: "Link a phone (QR here)", hint: "npx worktrust remote pair", info: "Shows a QR that links a phone to this computer.", run: act.link, ...wait };
|
|
172
|
+
return [
|
|
173
|
+
...(approved ? [link, approve] : [approve, link]),
|
|
174
|
+
{ label: "Projects ›", hint: "npx worktrust remote projects", info: "Folders a phone may steer an agent in.", run: act.projects, ...wait },
|
|
175
|
+
{ label: "Roots for new projects ›", hint: "npx worktrust remote roots", info: "Where a phone may open and create projects.", run: act.roots, ...wait },
|
|
176
|
+
{ label: "Allowed modes ›", hint: "npx worktrust remote modes", info: "Agent modes a phone may start. This computer is the limit.", run: act.modes },
|
|
177
|
+
{ label: "Connections ›", hint: "npx worktrust remote connections", info: "Phones and browsers linked here.", run: act.connections, ...wait },
|
|
178
|
+
{ label: paused ? "Resume" : "Pause", hint: `npx worktrust remote ${paused ? "resume" : "pause"}`, info: paused ? "Lets linked phones steer agents here again." : "Stops every phone until you resume. Links stay.", run: act.pause, ...wait },
|
|
179
|
+
{ label: "Status", hint: "npx worktrust remote status", info: "Shows if Remote Agent is on and what is linked. Only reads.", run: act.status },
|
|
180
|
+
BACK,
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Remote Agent ›. The rows are read again after every command, so an approval made here opens the other steps at once. */
|
|
105
185
|
export function remoteMenu(term, io, header) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
186
|
+
const title = () => (approval() === null ? "Remote Agent · its state could not be read" : "Remote Agent");
|
|
187
|
+
return level(term, header, title, () => {
|
|
188
|
+
const approved = approval(), paused = (() => { try { return loadSettings().paused !== null; } catch { return false; } })();
|
|
189
|
+
// The two roads; one that leaves this computer approved returns to the list above, which now opens on Link a phone.
|
|
190
|
+
const road = (which) => async () => ((await runShown(term, io, ["remote", which, ...(approved ? ["--repair"] : [])])) === false ? false : approved === false && approval() === true ? "back" : true);
|
|
191
|
+
return remoteItems(approved, paused, {
|
|
192
|
+
approve: () => level(term, header, approved ? "Approve this computer again (new keys)" : "Approve this computer", () => [
|
|
193
|
+
{ label: "With the WorkTrust app", hint: `npx worktrust remote app${approved ? " --repair" : ""}`, info: "Shows a QR; scan it with the WorkTrust app and approve.", run: road("app") },
|
|
194
|
+
{ label: "In the browser", hint: `npx worktrust remote web${approved ? " --repair" : ""}`, info: "Opens WorkTrust in your browser, where you approve.", run: road("web") },
|
|
112
195
|
BACK,
|
|
113
|
-
])
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
{ label: "Allowed modes ›", hint: "npx worktrust remote modes", run: () => modesMenu(term, io, header) },
|
|
121
|
-
{ label: "Connections ›", hint: "npx worktrust remote connections", run: () => connectionsMenu(term, io, header) },
|
|
122
|
-
{ label: paused ? "Resume" : "Pause", hint: `npx worktrust remote ${paused ? "resume" : "pause"}`, run: () => runShown(term, io, ["remote", paused ? "resume" : "pause"]) },
|
|
123
|
-
{ label: "Status", hint: "npx worktrust remote status", run: () => runShown(term, io, ["remote", "status"]) },
|
|
124
|
-
BACK,
|
|
125
|
-
];
|
|
126
|
-
});
|
|
196
|
+
], io),
|
|
197
|
+
link: () => runShown(term, io, ["remote", "pair"]),
|
|
198
|
+
projects: () => projectsMenu(term, io, header), roots: () => rootsMenu(term, io, header), modes: () => modesMenu(term, io, header), connections: () => connectionsMenu(term, io, header),
|
|
199
|
+
pause: () => runShown(term, io, ["remote", paused ? "resume" : "pause"]),
|
|
200
|
+
status: () => runShown(term, io, ["remote", "status"]),
|
|
201
|
+
});
|
|
202
|
+
}, io);
|
|
127
203
|
}
|
|
128
204
|
|
|
129
205
|
export function historyMenu(term, io, header) {
|
|
130
206
|
return level(term, header, "Import earlier history", () => [
|
|
131
|
-
{ label: "
|
|
132
|
-
{ label: "
|
|
133
|
-
{ label: "
|
|
134
|
-
{ label: "
|
|
207
|
+
{ label: "Sessions on this computer", hint: "npx worktrust history", info: "Sessions your AI apps still hold. Shows a plan, asks first.", run: () => runShown(term, io, ["history"]) },
|
|
208
|
+
{ label: "Your local archive", hint: "npx worktrust history --from-archive", info: "Sessions your apps deleted, from your archive. Asks first.", run: () => runShown(term, io, ["history", "--from-archive"]) },
|
|
209
|
+
{ label: "A ChatGPT or Claude export…", hint: "npx worktrust history --export <path>", info: "Asks for its path. Reconstructed hours, never verified.", 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; } },
|
|
210
|
+
{ label: "A copied session folder…", hint: "npx worktrust history --from-folder <dir>", info: "Your copy of a session folder. Reconstructed, not verified.", run: async () => { const path = await chooseFolder(term); term.enter(); return path ? runShown(term, io, ["history", "--from-folder", path]) : true; } },
|
|
135
211
|
BACK,
|
|
136
212
|
]);
|
|
137
213
|
}
|
|
138
214
|
|
|
139
215
|
export function preserveMenu(term, io, header) {
|
|
140
216
|
return level(term, header, "Preserve evidence", () => [
|
|
141
|
-
{ label: "How long each AI app keeps
|
|
142
|
-
{ label: "Keep them longer", hint: "npx worktrust preserve --apply
|
|
143
|
-
{ label: "Make a local archive", hint: "npx worktrust preserve --archive", run: () => runShown(term, io, ["preserve", "--archive"]) },
|
|
144
|
-
{ label: "Check the archive", hint: "npx worktrust preserve --verify", run: () => runShown(term, io, ["preserve", "--verify"]) },
|
|
145
|
-
{ label: "Count hours from the archive", hint: "npx worktrust preserve --summary", run: () => runShown(term, io, ["preserve", "--summary"]) },
|
|
217
|
+
{ label: "How long each AI app keeps sessions", hint: "npx worktrust preserve", info: "Shows how long each AI app keeps sessions. Changes nothing.", run: () => runShown(term, io, ["preserve"]) },
|
|
218
|
+
{ label: "Keep them longer", hint: "npx worktrust preserve --apply", info: "Keeps sessions longer. Asks per change, backs up first.", run: () => runShown(term, io, ["preserve", "--apply"]) },
|
|
219
|
+
{ label: "Make a local archive", hint: "npx worktrust preserve --archive", info: "Writes a metadata-only record to ~/AI-Evidence. Not sent.", run: () => runShown(term, io, ["preserve", "--archive"]) },
|
|
220
|
+
{ label: "Check the archive", hint: "npx worktrust preserve --verify", info: "Checks that record's hashes and signatures. It only reads.", run: () => runShown(term, io, ["preserve", "--verify"]) },
|
|
221
|
+
{ label: "Count hours from the archive", hint: "npx worktrust preserve --summary", info: "Counts hours and tokens from that record. It only reads.", run: () => runShown(term, io, ["preserve", "--summary"]) },
|
|
146
222
|
BACK,
|
|
147
223
|
]);
|
|
148
224
|
}
|