worktrust 0.11.8 → 0.11.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/LICENSE +5 -0
- package/README.md +54 -26
- package/cli-look.mjs +192 -0
- package/cli-menu-remote.mjs +153 -53
- package/cli-menu.mjs +168 -69
- package/engine-release.json +1 -1
- package/log-session.mjs +6 -169
- package/package-release.json +1 -1
- package/package.json +3 -1
- package/remote-adapter-claude-code.mjs +30 -4
- package/remote-adapter-terminal.mjs +4 -3
- package/remote-cli.mjs +22 -44
- package/remote-connections.mjs +55 -1
- package/remote-pairing.mjs +42 -4
- package/remote-qr.mjs +40 -15
- package/remote-run.mjs +7 -5
- package/remote-store.mjs +10 -0
- package/session-readers.mjs +202 -0
- package/worktrust.mjs +98 -31
package/cli-menu.mjs
CHANGED
|
@@ -14,11 +14,21 @@
|
|
|
14
14
|
* sentence under it; the menu is redrawn IN PLACE (createTerminal) and never left in the scrollback; colours carry meaning
|
|
15
15
|
* and are off wherever cli-colour.mjs says so (NO_COLOR, --no-color, a pipe). A terminal without cursor addressing
|
|
16
16
|
* (TERM=dumb) gets no menu: the bare command runs as it always did.
|
|
17
|
+
*
|
|
18
|
+
* 0.11.9 (owner, 2026-11-14): a computer that is NOT connected gets a short menu (firstItems: Connect, Preserve, Help, Quit),
|
|
19
|
+
* and the full one the moment Connect succeeds, without running anything again (menuLoop reads the state after every command).
|
|
20
|
+
* And an Update with nothing to update is still drawn, dimmed and in words, and cannot be chosen (updateNote's `settled`).
|
|
21
|
+
* ONE ROW PER ITEM (owner, 2026-11-14: "the text under 1 is annoying"): number, action, command, explanation on one line
|
|
22
|
+
* where the terminal is wide enough, else the chosen row's explanation on one fixed line under the list (menuFrame). No row
|
|
23
|
+
* moves when the choice moves. A ROW THAT CANNOT BE CHOSEN is one mechanism for every menu: `disabled`, with `quiet`, the
|
|
24
|
+
* line its digit answers; the arrows pass it, it is dimmed, and its words say why (a note beside its name), never colour alone.
|
|
25
|
+
* Esc quits at the top like q and goes back one level below it. The head of a connected computer is a summary (headerLines):
|
|
26
|
+
* account, this computer, Remote Agent and its connections, and what this computer shares, from local files only.
|
|
17
27
|
*/
|
|
18
28
|
import { emitKeypressEvents } from "node:readline";
|
|
19
29
|
import { createInterface } from "node:readline/promises";
|
|
20
30
|
import { busyWith, clip, coloursFor, visibleLength } from "./cli-colour.mjs";
|
|
21
|
-
import { loadIdentity, loadSettings } from "./remote-store.mjs";
|
|
31
|
+
import { loadIdentity, loadPhones, loadSettings } from "./remote-store.mjs";
|
|
22
32
|
|
|
23
33
|
/** Whether bare `npx worktrust` opens the menu here. Pure: the caller passes what it knows. */
|
|
24
34
|
export function menuWanted({ args: given = [], env = {}, stdinTTY = false, stdoutTTY = false, agentShell = null } = {}) {
|
|
@@ -41,8 +51,8 @@ export const muted = (text) => paint.dim(text);
|
|
|
41
51
|
* key and each return from a command left one more copy. Now draw() remembers how many lines the menu took and the next
|
|
42
52
|
* 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
53
|
* 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
|
|
45
|
-
* the
|
|
54
|
+
* the scrollback is what happened, never a menu. A resize takes the menu's own counted lines away and draws it once more;
|
|
55
|
+
* nothing above the menu (a command's output, a QR still waiting to be scanned) is ever cleared or written over. No line ever wraps: draw() cuts each to the terminal's width.
|
|
46
56
|
*/
|
|
47
57
|
export function createTerminal(input = process.stdin, output = process.stdout) {
|
|
48
58
|
let raw = false, drawn = 0;
|
|
@@ -50,7 +60,11 @@ export function createTerminal(input = process.stdin, output = process.stdout) {
|
|
|
50
60
|
const up = () => (drawn > 0 ? `\x1b[${drawn}A\r\x1b[J` : "");
|
|
51
61
|
const draw = (lines) => { const { columns } = size(); output.write(`${up()}${lines.map((line) => clip(line, columns - 1)).join("\n")}\n`); drawn = lines.length; };
|
|
52
62
|
const erase = () => { if (drawn > 0) output.write(up()); drawn = 0; };
|
|
53
|
-
|
|
63
|
+
// A RESIZE TAKES ONLY THE MENU'S OWN LINES (owner, 2026-11-14: a QR cut off halfway). It cleared the visible screen from its
|
|
64
|
+
// top (`ESC[H ESC[J`), and with it whatever a command had printed above the menu. Every line is clipped to the width, so a
|
|
65
|
+
// narrower terminal can only fold the menu into MORE rows than `drawn`: going up `drawn` rows lands inside the menu at worst
|
|
66
|
+
// (an old line may stay above the new menu), never in the output above it.
|
|
67
|
+
const reset = () => erase();
|
|
54
68
|
/** Text that is not the menu (a reason, a result): the menu's lines go first, and the next draw starts below it. */
|
|
55
69
|
const write = (text) => { erase(); output.write(text); };
|
|
56
70
|
const enter = () => { emitKeypressEvents(input); if (input.isTTY && !raw) { input.setRawMode(true); raw = true; } input.resume(); output.write("\x1b[?25l"); };
|
|
@@ -69,54 +83,71 @@ export function createTerminal(input = process.stdin, output = process.stdout) {
|
|
|
69
83
|
return { write, draw, erase, reset, size, enter, restore, key, anyKey };
|
|
70
84
|
}
|
|
71
85
|
|
|
86
|
+
const wrap = (text, width) => { const out = []; let line = ""; for (const word of text.split(" ")) { if (line && line.length + 1 + word.length > width) { out.push(line); line = word; } else line = line ? `${line} ${word}` : word; } return line ? [...out, line] : out; };
|
|
87
|
+
|
|
72
88
|
/**
|
|
73
|
-
* The lines of one list, as text. Pure: `view` is what choose holds, `columns` and `rows` the terminal's size.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
89
|
+
* The lines of one list, as text. Pure: `view` is what choose holds, `columns` and `rows` the terminal's size. ONE ROW PER
|
|
90
|
+
* ITEM (0.11.9), and the rows never move when the choice moves:
|
|
91
|
+
* wide four columns on one line: number, action, command (dim), explanation (dim). Only when EVERY row's explanation
|
|
92
|
+
* fits whole (no sentence is ever cut), so the form does not depend on which row is chosen.
|
|
93
|
+
* narrower three columns, and the chosen row's explanation on fixed lines under the list, above the keys: as many lines as
|
|
94
|
+
* the longest explanation of this list needs at this width, always, so nothing jumps. 80 columns is this form.
|
|
95
|
+
* < 60 the command column goes too; and at any width a command that would not fit whole on its row is left out.
|
|
96
|
+
* The chosen item is marked by `>` and by its ground, never by colour alone. `asked` is the row whose digit was pressed
|
|
97
|
+
* though it cannot be chosen: its `quiet` line (and its explanation, where that is not on its row) is said under the list.
|
|
98
|
+
* A list taller than the terminal shows the items around the chosen one: a menu taller than the screen could not be redrawn in place.
|
|
78
99
|
*/
|
|
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
|
|
81
|
-
const
|
|
82
|
-
const
|
|
100
|
+
export function menuFrame({ header = [], title = null, items, at = 0, ticked = new Set(), multi = false, top = false, footer = null, asked = null }, { rows = 24, columns = 100, p = paint } = {}) {
|
|
101
|
+
const width = columns - 1;
|
|
102
|
+
const heads = (lines) => [...lines, ...(title ? ["", ` ${p.bold(title)}`] : []), ""];
|
|
103
|
+
const keys = ` ${p.dim(footer ?? (multi ? "↑/↓ move · Space tick · Enter confirm · Esc back" : `↑/↓ move · Enter open · Esc ${top ? "quit" : "back"} · 1-9 jump`))}`;
|
|
83
104
|
const box = (item) => (multi && item.tick ? `[${ticked.has(item.label) ? "x" : " "}] ` : "");
|
|
84
|
-
const
|
|
85
|
-
// The commands stand in one column beside the names (a name longer than
|
|
86
|
-
const
|
|
105
|
+
const size = (item) => visibleLength(`${box(item)}${item.label}${item.note ? ` · ${item.note.text}` : ""}`);
|
|
106
|
+
// The commands stand in one column beside the names (a name longer than 64 pushes only its own command; a table row is a name).
|
|
107
|
+
const nameCol = Math.min(64, Math.max(0, ...items.map(size))), hintCol = Math.max(0, ...items.map((item) => (item.hint ?? "").length));
|
|
108
|
+
const upTo = (item) => 6 + Math.max(nameCol, size(item)) + 3; // where this row's command starts
|
|
109
|
+
const wide = columns >= 60 && items.every((item) => !item.info || upTo(item) + hintCol + 3 + item.info.length <= width);
|
|
87
110
|
const line = (item, i) => {
|
|
88
111
|
const label = ` ${i < 9 ? i + 1 : " "} ${box(item)}${item.label} `;
|
|
89
112
|
const note = item.note ? `· ${p[item.note.tone]?.(item.note.text) ?? item.note.text}` : "";
|
|
90
113
|
const name = i === at ? p.inverse(label) : item.disabled ? p.dim(label) : p.bold(label);
|
|
91
|
-
|
|
114
|
+
const gap = " ".repeat(Math.max(0, nameCol - size(item)) + (item.note ? 3 : 2)); // a name without a note ends in its own space
|
|
115
|
+
if (wide) return `${i === at ? ">" : " "} ${name}${note}${gap}${p.dim(item.info ? (item.hint ?? "").padEnd(hintCol) : item.hint ?? "")}${item.info ? ` ${p.dim(item.info)}` : ""}`;
|
|
116
|
+
return `${i === at ? ">" : " "} ${name}${note}${columns >= 60 && item.hint && upTo(item) + item.hint.length <= width ? `${gap}${p.dim(item.hint)}` : ""}`;
|
|
92
117
|
};
|
|
93
|
-
//
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
118
|
+
// Under the list: what the chosen row does or, after the digit of a row that cannot be chosen, why not.
|
|
119
|
+
const told = (item, refused) => [refused ? item.quiet : null, item.info].filter(Boolean).join(" ");
|
|
120
|
+
const need = Math.max(1, ...items.map((item) => wrap(told(item, item.disabled), width - 2).length));
|
|
121
|
+
const said = wrap(asked === null ? told(items[at], false) : told(items[asked], true), width - 2).map((part) => ` ${part}`);
|
|
122
|
+
const foot = wide ? ["", keys, ...(asked === null ? [] : [` ${p.dim(items[asked].quiet ?? items[asked].info ?? "")}`])] : ["", ...said, ...Array(Math.max(0, need - said.length)).fill(""), "", keys];
|
|
123
|
+
// A terminal too short for the list under the whole head keeps the head's first line only: the list matters more than the summary.
|
|
124
|
+
const all = items.map(line), fits = (lines) => all.length <= rows - 1 - lines.length - foot.length;
|
|
125
|
+
const head = fits(heads(header)) ? heads(header) : heads(header.slice(0, 1)), room = Math.max(3, rows - 1 - head.length - foot.length);
|
|
126
|
+
if (all.length <= room) return [...head, ...all, ...foot];
|
|
127
|
+
const span = Math.max(1, room - 2), from = Math.max(0, Math.min(at - Math.floor(span / 2), items.length - span));
|
|
128
|
+
return [...head, ` ${p.dim(from > 0 ? "↑ more" : "")}`, ...all.slice(from, from + span), ` ${p.dim(from + span < items.length ? "↓ more" : "")}`, ...foot];
|
|
102
129
|
}
|
|
103
130
|
|
|
104
131
|
/**
|
|
105
132
|
* One list: → { item } (Enter or a digit), "back" (Esc, ←), "quit" (q at the top, Ctrl+C). `items`: { label, hint?, info?,
|
|
106
|
-
* note?, disabled? }.
|
|
133
|
+
* note?, disabled?, quiet? }. A disabled item is never chosen: the arrows pass it, the list opens on the first item that can
|
|
134
|
+
* be, and its digit only says its `quiet` line. `multi`: Space ticks an item that has `tick: true`; the ticked items come back as `ticked`. `header`:
|
|
107
135
|
* the lines, or a function giving them, asked at every draw so a state a command just changed shows at once.
|
|
108
136
|
*/
|
|
109
137
|
export async function choose(term, { header = [], title, items, top = false, multi = false, footer = null }) {
|
|
110
138
|
let at = Math.max(0, items.findIndex((i) => !i.disabled));
|
|
111
139
|
const ticked = new Set(items.filter((i) => i.ticked).map((i) => i.label));
|
|
140
|
+
let asked = null; // the row whose digit was pressed though it cannot be chosen (0.11.9), said under the list until the next key
|
|
112
141
|
for (;;) {
|
|
113
|
-
term.draw(menuFrame({ header: typeof header === "function" ? header() : header, title, items, at, ticked, multi, top, footer }, term.size()));
|
|
142
|
+
term.draw(menuFrame({ header: typeof header === "function" ? header() : header, title, items, at, ticked, multi, top, footer, asked }, term.size()));
|
|
114
143
|
const k = await term.key();
|
|
115
144
|
if (k.name === "resize") { term.reset(); continue; }
|
|
145
|
+
asked = /^[1-9]$/.test(k.str ?? "") && items[Number(k.str) - 1]?.disabled ? Number(k.str) - 1 : null;
|
|
116
146
|
if (k.ctrl && k.name === "c") return "quit";
|
|
117
147
|
if (k.name === "up" || k.name === "k") { do at = (at - 1 + items.length) % items.length; while (items[at].disabled); continue; }
|
|
118
148
|
if (k.name === "down" || k.name === "j") { do at = (at + 1) % items.length; while (items[at].disabled); continue; }
|
|
119
|
-
if (k.name === "escape"
|
|
149
|
+
if (k.name === "escape") return top ? "quit" : "back"; // 0.11.9: Esc leaves the top like q (a lone Esc: readline tells it from an arrow's sequence)
|
|
150
|
+
if (k.name === "left") { if (!top) return "back"; continue; }
|
|
120
151
|
if (k.name === "q" && top) return "quit";
|
|
121
152
|
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
153
|
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; }
|
|
@@ -142,22 +173,24 @@ let busy = false;
|
|
|
142
173
|
/**
|
|
143
174
|
* Run one direct command with the terminal handed over, then wait for a key before the menu comes back. The menu's own
|
|
144
175
|
* 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).
|
|
176
|
+
* below (the next draw starts fresh). `pause: false` (0.11.10, look): no key is waited for and the code comes back, so a
|
|
177
|
+
* list can follow the command's output at once.
|
|
146
178
|
*/
|
|
147
|
-
export async function runShown(term, io, args, label = null) {
|
|
179
|
+
export async function runShown(term, io, args, label = null, { pause = true } = {}) {
|
|
148
180
|
term.restore();
|
|
149
181
|
busy = true;
|
|
150
182
|
term.write(` ${muted(`› npx worktrust ${args.join(" ")}`.trimEnd())}${label ? ` ${label}` : ""}\n\n`);
|
|
151
183
|
let code = 1;
|
|
152
184
|
try { code = await io.runCli(args); } catch { code = 1; } finally { busy = false; }
|
|
153
185
|
term.enter();
|
|
186
|
+
if (!pause) return code;
|
|
154
187
|
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
188
|
const k = await term.anyKey();
|
|
156
189
|
return !(k.ctrl && k.name === "c");
|
|
157
190
|
}
|
|
158
191
|
|
|
159
192
|
/** 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
|
|
193
|
+
export const REMOTE_NEEDS = "Needs Node 22.4 or later. Enter shows the ways to get it.";
|
|
161
194
|
|
|
162
195
|
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
196
|
|
|
@@ -165,58 +198,133 @@ const newer = (a, b) => { const x = String(a).split(".").map(Number), y = String
|
|
|
165
198
|
* What the Update item says beside its name (owner, 2026-11-13), from the state read again after every command, so it is
|
|
166
199
|
* true the moment an update finishes: this computer's installed version behind this CLI's ("0.11.7 → 0.11.8 available"),
|
|
167
200
|
* a newer CLI published than the one running, or "up to date (0.11.8)". Null when this computer is not connected.
|
|
201
|
+
*
|
|
202
|
+
* THREE STATES, NEVER TWO (0.11.9, owner 2026-11-14: "now you can do the update twice"). Something to update; nothing to
|
|
203
|
+
* update and KNOWN so (`settled`: this computer runs this CLI's version and the registry answered that none is newer), which
|
|
204
|
+
* is the one state where the item cannot be chosen; and not known (the registry did not answer, or this computer's version
|
|
205
|
+
* is not this CLI's): that one says what it knows, claims no "up to date", and can still be chosen.
|
|
168
206
|
*/
|
|
169
207
|
export function updateNote(state) {
|
|
170
208
|
if (!state.connected) return null;
|
|
171
209
|
if (state.installed && newer(state.version, state.installed)) return { text: `${state.installed} → ${state.version} available`, tone: "yellow", behind: "computer" };
|
|
172
210
|
if (state.latest && newer(state.latest, state.version)) return { text: `${state.version} → ${state.latest} available`, tone: "yellow", behind: "cli" };
|
|
173
|
-
return { text:
|
|
211
|
+
if (!state.latestKnown) return { text: "newest not checked", tone: "dim", behind: null };
|
|
212
|
+
return { text: `up to date (${state.version})`, tone: state.installed === state.version ? "dim" : "green", behind: null, settled: state.installed === state.version };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Remote Agent here, in one word, with its confirmed connections; from this computer's own files. A file that cannot be read
|
|
217
|
+
* is "not known", never "not set up" (remote-store readJson refuses an unreadable or non-private one).
|
|
218
|
+
*/
|
|
219
|
+
export function remoteState() {
|
|
220
|
+
try { const s = loadSettings(), links = loadPhones().confirmed.length; return { links, word: !loadIdentity() ? "not set up" : !s.enabled ? "off" : s.paused ? "paused" : "approved" }; }
|
|
221
|
+
catch { return { links: null, word: "not known" }; }
|
|
174
222
|
}
|
|
175
223
|
|
|
176
|
-
/**
|
|
224
|
+
/**
|
|
225
|
+
* The head. Not connected: the version and the one fact. Connected (0.11.9, owner 2026-11-14): a summary, label and value,
|
|
226
|
+
* of what this computer's own files say; never the key, never a secret; a date not recorded is a dash, a state that could
|
|
227
|
+
* not be read is "not known". `state`: version, latest, account, host, since, hook, door, apps (worktrust.mjs).
|
|
228
|
+
*/
|
|
177
229
|
export function headerLines(state) {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
230
|
+
const title = ` ${paint.bold(`WorkTrust CLI ${state.version}`)}${state.latest ? ` ${paint.yellow(`! ${state.latest} is out: quit, then npx -y worktrust@latest`)}` : ""}`;
|
|
231
|
+
if (!state.connected) return [title, " Not connected yet"];
|
|
232
|
+
const row = (label, value) => ` ${paint.dim(label.padEnd(14))} ${value}`, remote = remoteState(), host = String(state.host ?? "this computer");
|
|
233
|
+
const known = (value, yes, no) => (value === true ? yes : value === false ? no : "not known");
|
|
234
|
+
return [
|
|
235
|
+
title,
|
|
236
|
+
row("Account", state.account ?? "not recorded: run Check this computer"),
|
|
237
|
+
row("Account type", PLAN_WORDS[state.plan] ?? "not known"), // the server's answer (api/cli/door), never guessed here
|
|
238
|
+
row("This computer", `${host.length > 28 ? `${host.slice(0, 27)}…` : host} · connected since ${/^\d{4}-\d{2}-\d{2}/.test(String(state.since ?? "")) ? String(state.since).slice(0, 10) : "-"}`),
|
|
239
|
+
row("Remote Agent", `${remote.links === null || ["not set up", "off"].includes(remote.word) ? remote.word : `${remote.word}, ${remote.links} connection${remote.links === 1 ? "" : "s"}`}${state.remoteAccess === "premium_required" ? " · needs Premium" : ""}`),
|
|
240
|
+
row("Sharing", `session hook ${known(state.hook, "on", "not installed")} · AI apps ${state.door === "off" ? "off" : state.door === "on" ? `on${Number.isInteger(state.apps) ? ` (${state.apps})` : ""}` : "not known"} · Remote Agent ${remote.word === "not set up" ? "off" : remote.word}`),
|
|
241
|
+
];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** The account's plan in words (owner, 2026-11-14), as WorkTrust answered it; anything else, or no answer, is "not known". */
|
|
245
|
+
const PLAN_WORDS = { free: "Free", premium: "Premium" };
|
|
246
|
+
const HELP = (open) => ({ label: "Help · all commands", hint: "npx worktrust help", info: "Lists all commands. npx -y worktrust skips npm's question.", run: () => open(["help"]) });
|
|
247
|
+
const QUIT = { label: "Quit", hint: "q", info: "Leaves the menu. Nothing keeps running.", quit: true };
|
|
248
|
+
const PRESERVE = (sub, info) => ({ label: "Preserve evidence ›", hint: "npx worktrust preserve …", info, run: () => sub.preserve?.() });
|
|
249
|
+
/** 0.11.10 (owner, 2026-11-14): the first row before sign-in; the table, then what to do with it (cli-look.mjs lookMenu). */
|
|
250
|
+
const LOOK = (sub) => ({ label: "Look at this computer", hint: "npx worktrust look", info: "Reads what your AI apps recorded here. Nothing is sent.", run: () => sub.look?.() });
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* THE FIRST MENU (0.11.9, owner 2026-11-14): what a computer that is not connected can do, and nothing that needs a
|
|
254
|
+
* connected one (no Update, Remote Agent, Import, AI apps switch, Status, Disconnect). Preserve needs no account, no key
|
|
255
|
+
* and no network at any of its levels (preserve.mjs; worktrust.mjs loads no key for it), so all of it stays. 0.11.10: Look at this computer comes
|
|
256
|
+
* first, the table of what the AI apps recorded here (`look`, reads only), then Connect or Preserve with it.
|
|
257
|
+
*/
|
|
258
|
+
export function firstItems(open = () => true, sub = {}) {
|
|
185
259
|
return [
|
|
186
|
-
|
|
187
|
-
|
|
260
|
+
LOOK(sub),
|
|
261
|
+
{ label: "Connect this computer", hint: "npx worktrust connect", info: "Asks before it writes; your browser signs in to WorkTrust.", run: () => open(["connect"]) },
|
|
262
|
+
PRESERVE(sub, "Keep your AI history here. No account; nothing is sent."),
|
|
263
|
+
HELP(open), QUIT,
|
|
188
264
|
];
|
|
189
265
|
}
|
|
190
266
|
|
|
267
|
+
/** Why the first menu still stands after Connect ran, in one line, by how the command ended (0 without a key: a No or a dry run). */
|
|
268
|
+
export function connectReason(code) {
|
|
269
|
+
if (code === 0) return "Connect stopped before the sign-in; nothing was written. 2 tries again.";
|
|
270
|
+
if (code === 130) return "Connect was cancelled; this computer is not connected. 2 tries again.";
|
|
271
|
+
return "Connect ended with the message above; not connected. 2 tries again.";
|
|
272
|
+
}
|
|
273
|
+
|
|
191
274
|
/**
|
|
192
275
|
* The top list (owner, 2026-11-13): Update first, then Check, then the rest as before. Pure but for the `run` closures.
|
|
193
276
|
* `open(args)` runs one direct command; `sub` holds the deeper levels.
|
|
194
277
|
*/
|
|
195
278
|
export function topItems(state, open = () => true, sub = {}) {
|
|
196
|
-
|
|
279
|
+
if (!state.connected) return firstItems(open, sub);
|
|
197
280
|
const note = updateNote(state);
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
: note.behind === "computer" ? `Brings this computer
|
|
201
|
-
:
|
|
281
|
+
const same = state.installed === state.version; // then `update` changes nothing and says so (worktrust.mjs update, 0.11.9)
|
|
282
|
+
const updateInfo = note.behind === "cli" ? "Newer CLI: quit, then npx -y worktrust@latest update."
|
|
283
|
+
: note.behind === "computer" ? `Brings this computer from ${state.installed} to ${state.version}. Your key stays.`
|
|
284
|
+
: note.settled ? "Nothing to update: this computer runs the latest version."
|
|
285
|
+
: same ? "Newest version not checked. Enter changes nothing here."
|
|
286
|
+
: "Sets up this computer's hook and AI-app doors again.";
|
|
202
287
|
return [
|
|
203
|
-
{ label: "Update WorkTrust", note, hint: "npx worktrust update", info: updateInfo, run: () => open(["update"]) },
|
|
204
|
-
{ label: "Check this computer", hint: "npx worktrust", info:
|
|
288
|
+
{ label: "Update WorkTrust", note, hint: "npx worktrust update", info: updateInfo, run: () => open(["update"]), ...(note.settled ? { disabled: true, quiet: "Already up to date." } : {}) },
|
|
289
|
+
{ label: "Check this computer", hint: "npx worktrust", info: "Shows what is coupled here and finishes what waits.", run: () => open([]) },
|
|
205
290
|
// 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
291
|
state.remoteBlocked
|
|
207
292
|
? { label: "Remote Agent", note: { text: "needs Node 22.4+", tone: "yellow" }, hint: "npx worktrust remote …", info: REMOTE_NEEDS, run: () => open(["remote"]) }
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
{ label: "
|
|
211
|
-
|
|
212
|
-
{ label: "
|
|
213
|
-
{ label: "
|
|
214
|
-
{ label: "
|
|
215
|
-
|
|
293
|
+
// REMOTE AGENT IS PART OF PREMIUM (owner, 2026-11-14): only the server's own `premium_required` locks it; the row stays.
|
|
294
|
+
: { label: "Remote Agent ›", hint: "npx worktrust remote …", run: () => sub.remote?.(), ...(state.remoteAccess === "premium_required" ? { note: { text: "Premium", tone: "yellow" }, info: "Part of Premium. Enter shows how to upgrade." } : { info: "Steer this computer's agents from your phone." }) },
|
|
295
|
+
{ label: "Import earlier history ›", hint: "npx worktrust history …", info: "Send earlier sessions as history. Each way asks first.", run: () => sub.history?.() },
|
|
296
|
+
PRESERVE(sub, "Keep your AI history on this computer. Nothing is sent."),
|
|
297
|
+
{ label: "Sharing ›", hint: "npx worktrust mcp …", info: "What this computer sends, and the switches for it.", run: () => sub.sharing?.() },
|
|
298
|
+
{ label: "Status", hint: "npx worktrust status", info: "Shows the key, the hook and the door. It only reads.", run: () => open(["status"]) },
|
|
299
|
+
{ label: "Disconnect this computer", hint: "npx worktrust disconnect", info: "Takes WorkTrust out and ends this computer's key. It asks.", run: () => open(["disconnect"]) },
|
|
300
|
+
HELP(open), QUIT,
|
|
216
301
|
];
|
|
217
302
|
}
|
|
218
303
|
|
|
219
|
-
/**
|
|
304
|
+
/**
|
|
305
|
+
* The menu's loop, apart from the process (0.11.9) so a test can drive it. The state is read again after every command: the
|
|
306
|
+
* version line and the Update item say the new state the moment an update ends, and the first menu becomes the full one the
|
|
307
|
+
* moment Connect leaves a key. When Connect ran and there is still no key, the first menu stays and its header says why.
|
|
308
|
+
*/
|
|
309
|
+
export async function menuLoop(term, io, levels) {
|
|
310
|
+
let last = null, state = null; // the command the top level ran last and how it ended; this computer's state as last read
|
|
311
|
+
const read = async () => (state = { ...(await busyWith("Reading this computer's state", () => io.state())), remoteBlocked: typeof globalThis.WebSocket !== "function" });
|
|
312
|
+
// A deeper level reads the state again after each of its commands (inner.state), so the head above it is true at once.
|
|
313
|
+
const inner = { runCli: (args) => io.runCli(args), state: read, openUrl: (url) => io.openUrl?.(url) };
|
|
314
|
+
for (;;) {
|
|
315
|
+
await read();
|
|
316
|
+
const why = !state.connected && last?.args[0] === "connect" ? connectReason(last.code) : null;
|
|
317
|
+
const header = () => [...headerLines(state), ...(why ? [` ${paint.yellow(`! ${why}`)}`] : [])];
|
|
318
|
+
const open = (args) => { const ran = { args, code: 1 }; last = ran; return runShown(term, { runCli: async (given) => (ran.code = await io.runCli(given)) }, args); };
|
|
319
|
+
const items = topItems(state, open, { ...Object.fromEntries(["remote", "history", "preserve", "sharing"].map((name) => [name, () => levels[`${name}Menu`](term, inner, header)])), look: async () => (await import("./cli-look.mjs")).lookMenu(term, inner, levels) });
|
|
320
|
+
const picked = await choose(term, { header, items, top: true });
|
|
321
|
+
if (picked === "quit" || picked === "back" || picked.item.quit) break;
|
|
322
|
+
last = null;
|
|
323
|
+
if ((await picked.item.run()) === false) break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** The top of the menu. `io`: { runCli(args) → Promise<code>, state() → { version, installed, latest, latestKnown, account, connected, door, host, since, hook, apps, plan, remoteAccess, upgrade }, openUrl(url) }. */
|
|
220
328
|
// (remoteBlocked is added here: whether this Node lacks the WebSocket Remote Agent needs.)
|
|
221
329
|
export async function runMenu(io) {
|
|
222
330
|
paint = coloursFor(process.stdout);
|
|
@@ -227,16 +335,7 @@ export async function runMenu(io) {
|
|
|
227
335
|
process.on("SIGTERM", onSignal);
|
|
228
336
|
try {
|
|
229
337
|
term.enter();
|
|
230
|
-
|
|
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
|
-
}
|
|
338
|
+
await menuLoop(term, io, await import("./cli-menu-remote.mjs"));
|
|
240
339
|
} finally {
|
|
241
340
|
process.off("SIGINT", onSignal);
|
|
242
341
|
process.off("SIGTERM", onSignal);
|
package/engine-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","cli-colour.mjs":"fa16b61ad179999c5c5365255182acf69bcba1eb5f5ce7b0e1e18c11f56130ae","cli-menu-remote.mjs":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","cli-colour.mjs":"fa16b61ad179999c5c5365255182acf69bcba1eb5f5ce7b0e1e18c11f56130ae","cli-look.mjs":"1bcc1314f53a4b886d19ac7a4eb4010b5e86d9e00b8e880ccbcd43f515c6dfd9","cli-menu-remote.mjs":"8e933adf5c849f28cd1fcec879ff8480794a15d34a6be25585e68454d8512bf6","cli-menu.mjs":"67928264a9cb7fcf4a4bb2ee546cba1eee36c180ea76bd669834c33d9508fc89","commit-rules.mjs":"e94cc32a5415f6d9e978145ab9505ac4ae0bac9431e6e9104b9b37155260b51f","config-edits.mjs":"527a7674f9d52b284bfda3b8089eb4b930a709bf14aedbec7f6eef1e59ef52ee","count-behaviour.mjs":"06b0ecbc222087160dc64c0b302391631e8e799038364c317c6cd28449c5044d","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","export-facts.mjs":"3bbb46c80e8678b5cea7e15dcbfc456a2b48595053241c2b3cea508092f9b917","folder-picker.mjs":"daeb379626d5716f91f588064c6b4083618279320c006c177960cc93f056d96a","git-commits.mjs":"af0ed45a2a42c8e17cabfb3649a2f524dbf80230f8a6ec1c6b775fed7d34dc9c","history-outbox.mjs":"85c70389effc5b4ec9d9b33af9192314e67f47af2752515b42a7959344ce2354","history-progress.mjs":"dcc25ee94b727f2605a763349a4d8764640335d6cf0043fb6108cebeed16dcb9","log-session.mjs":"171f4abb0d603d58446129e007de9e9dc0f707bde33b1b4481a134376ed301c8","node-guide.mjs":"5bf52c5028b07a80ec4d41be365eb025dfce74328f41f928a26ce6737b1f9cc4","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"cd111cae0f53a25a2d878a158479abfb1ace353361454843f91a16d241101d46","project-modes.mjs":"ada26e68297fbeb90e4e91d75a90fd2d7cc107b999a9702840675b5a7529463e","remote-adapter-claude-code.mjs":"d0558bb123a29a934db1bf8162e7c3f37e8ccde4c502178d47e9b4cbb3a0491b","remote-adapter-codex.mjs":"d2fd6c61d9e3c4a45e9b10da1aa3c15d45c86629d6456e4a8d25ad95b13eb209","remote-adapter-opencode.mjs":"ddd7f3ec0b4ba92f4744453d60fda338b63550e3ec7b23fa3acc668df1d64eb7","remote-adapter-terminal.mjs":"c047a362474abb90b7968b8a624358af40a989ad137166a03bc955409ff1dc82","remote-admin.mjs":"ac4d434c0a374159b27accac3fdd0324ff96ffe32227fba054cc62d00e58d35b","remote-agent-switch.mjs":"7ff5448f29f05a47d7298d730b21243a1bcf8a215b434a0c7fbf5f3cb0889041","remote-approval-bridge.mjs":"092f17b7969e4f35bea064315d04dcde1faa6a3fd3e737dcc05aece82c7a37c4","remote-approvals.mjs":"63847226e398f9eb5b8d3989ba2b2436fbedd898385eb5f2f63bbdf07fbe6852","remote-attachments.mjs":"2e9c1277329a45cf26c0c62abda632cf0ab9fad78d0504416ecee9805220e16c","remote-cdp.mjs":"70e333a1ebe845e872cc3a703a0a507391f8ce59640bdbd662bdad55eeff216b","remote-changes.mjs":"2141fece4961a5bc1bb1b046f78222812617457b1ba6452275eac6a897e62e19","remote-claude-events.mjs":"58822471203c6a1b66cf81c115c4d713657c3dea5c7b98df959f894ee5b2e704","remote-claude-progress.mjs":"2ca626d3dbc16d8d570abe1df6477b7e44ffb43c1d9145228ec5ea1928e415ca","remote-cli.mjs":"fa3ada1e8845855789d61daac8c69853d81dcde25dfbffc223d6fed17c7efa94","remote-coalesce.mjs":"cb0967d9cfe81e3892bcade8349d6814db98be8c2adbdb54df0b8d1b142f65d1","remote-codex-events.mjs":"58657d6070a50c837737cb85f5a1eaf9c2cbc4e1adfe3e970748ab3b2af94631","remote-connections.mjs":"1863863930f6df968084571be16c2382fbb0ba3ae64e26a9f9c90a7f9bf0b157","remote-countdown.mjs":"85cf2d01fe5ca49895e08a3d5de346bb5e4a8dd31b9fda3fd9f9534d9e1e47cf","remote-daemon.mjs":"94d4896b0e1203f7a5bc7224a6221a36f4c20be89caee78b3ab37b9b6a2dac1d","remote-endorse.mjs":"89eda4883567176703e01e44d83e987271bc2a6134e108f517b3b213719a21f9","remote-inventory.mjs":"a8245604d41373819738eaf06ec1d2242cb5f7b2e60aa316f31d2f8742b8c70d","remote-journal.mjs":"907ebd48c53162b22dc743ef95b53c1a6be6886a7495605b5cfa820b8de9d330","remote-live-preview.mjs":"faa70f9260ac05037204c2a0c3facf4ffe42f68408948390b341b453a2932289","remote-opencode-events.mjs":"3108375501ead2c2c78bce1435cc2a9fe6d2af1d7ff1fb42e12ff3e0f5d9af9c","remote-opencode-session.mjs":"681b201d833a7d7d025122b3a79663bcdc0a989aefd39d8018a28113d8810caf","remote-pairing.mjs":"f42bfb9c0b19ba3363c7b1c3d98cbd01c2bc7856acd763bf9e8ee53fefeccf2a","remote-pipeline-config.mjs":"00cde6a61ce21144c51ac56fce42fee159aa9dba6586218a7ea790ce4a6bd40b","remote-pipeline-parsers.mjs":"43ca0d332d7bc883c4759a754a555815ae5dfe133446b91ba9f2e48a350fa20f","remote-pipeline.mjs":"b856ead989b29ddb618ef69bbacd104bae2b02c9d1c5214291d08ce469a8b24e","remote-policy.mjs":"16ea015ad5de3c357bce730ea8ea98571dc981d8591fb5156b1941b2c557a381","remote-preview.mjs":"fe504ad6f83dcb4a4ebdcc018686a9a5a900c47cdf8c45b75e7d02e2f3056155","remote-projects.mjs":"ec8c530ad3e880bca21a4d4078ecd68b6aaafcc442b50087127868d952034d5f","remote-protocol.mjs":"93f8c2031895d4e01006a1951d7c0e79ef71b86b2777eed5dfa966ab131e446d","remote-qr.mjs":"73e7743c33e35b1b01d6df3260e876beab419179265aa201a101596b4a813d86","remote-release-plans.mjs":"11884a62b7d6dcccb5e154a26603bdf650f7b40f946329fb174d8c13729bec74","remote-releases.mjs":"fb08b72593ea00013c8b679e0c0d7dee95b0fd7cc5fd31b80ac575d0e340927d","remote-run.mjs":"5dce92062a4e5073b17860223bf1fc7362a23c620d81c8df535b8a580f590fe8","remote-screen-approvals.mjs":"c43ab286d36a38d17639d155782ffa017f1a9b6806a09b82ed0142a1290b6000","remote-screen-push.mjs":"4ee8bd48d24b2c87581e9f33d8354a86381f7febd82f89ed509a7a87c1442608","remote-screen-states.mjs":"7c3c86a584bebf52461f3cab39c05ea2a13910061704d48fc622956e842940f7","remote-service.mjs":"a3a5502e0f6f43b04e37ee778f43d88f4c219776439cfed0d8fa0b511e0c9637","remote-session-list.mjs":"494fdbe20f0542806ac6c42ad149c52e2d3ace23a3a7567f96dc7e80d092c727","remote-sessions.mjs":"1efb7869cef6090cbbeae15ff1e5ffe99dca3742f9c245686d6758bb705587d6","remote-settings.mjs":"ca16f39416a457bd5ceb1df847596e1b4bcd2894310eb6514664a619dee4981f","remote-steered.mjs":"d7afde92c62c87abbdb84b0cfea2eea4752e90a2e453e52a54812c4fe0395190","remote-steering.mjs":"7ba22e6110cea3ac75a4f084f8f92a5bd90c31a19d3ce58a88a0843bdadea834","remote-store.mjs":"592a87f0ab8f53cc8eee1318a309310e27cb01d4549caebad6d51c3fad1b75ac","remote-terminal-cli.mjs":"82a048b75e412d0b6db076afbb84cab7c754dec72b6c8b6af4d4906b38e988a7","remote-terminal-sessions.mjs":"6ab51824890a18768d23cedc499f3840b2b02a8ed651463c1fe2d74dd352a361","remote-transport.mjs":"68650fd77ea09b5762377f87cabdc1c73a34d77324aa5bf0cd9742094a50c32b","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","self-update.mjs":"378e3620d48c72cf0bf812be408883b995cdb2223de34a20f762dd73eeffb258","session-databases.mjs":"a16ffbc50ccc0e78f370ebe07f871d1a80f1977472e478e3599e7abfdc90c1b7","session-local-models.mjs":"bacd38ff8dd3056b552982ec52eb57c7b8ca86e1a46cd4cba30fc340e3e28fd4","session-readers.mjs":"05974f8dc97844f011cb409789f52089b5f21d37848ed1490e640caf4eab92e6","setup-mcp.mjs":"b732e3dd9b3e522b7cc8acf167ce28ba8f1a8dee797ee15bd7c3b02919b13e6f","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"e9f20415c2b5d62a09f35a63075002ebd1da56edb32f242d52822d58ecbd8ac3","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"4e6b36faf58082ab6531345bf56115957322786dcfd2263dba7536ef2534ccea"},"format":"worktrust-package/1","kind":"engine","version":"0.11.10"},"signature":"DSgN6BM_8GBDweufi6IkqxgVmXGmynQMcH7M4COB1DygIaOSAFW5itgWL-gNV642IEpRXT9zea6qdn__NJibDg"}
|