worktrust 0.11.0 → 0.11.1
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/README.md +9 -0
- package/engine-release.json +1 -1
- package/package-release.json +1 -1
- package/package.json +9 -1
- package/remote-adapter-claude-code.mjs +5 -3
- package/remote-adapter-codex.mjs +45 -5
- package/remote-adapter-terminal.mjs +248 -0
- package/remote-approval-bridge.mjs +30 -7
- package/remote-approvals.mjs +13 -3
- package/remote-cdp.mjs +60 -0
- package/remote-cli.mjs +7 -2
- package/remote-daemon.mjs +18 -3
- package/remote-inventory.mjs +14 -3
- package/remote-live-preview.mjs +205 -0
- package/remote-protocol.mjs +239 -110
- package/remote-run.mjs +18 -3
- package/remote-screen-approvals.mjs +79 -0
- package/remote-screen-push.mjs +76 -0
- package/remote-screen-states.mjs +113 -0
- package/remote-session-list.mjs +25 -2
- package/remote-sessions.mjs +10 -21
- package/remote-store.mjs +4 -3
- package/remote-terminal-cli.mjs +85 -0
- package/remote-terminal-sessions.mjs +291 -0
- package/worktrust.mjs +2 -2
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TERMINAL SESSIONS, BESIDE THE STRUCTURED ONES (release 19, 2026-11-09). A terminal session is Claude Code, interactive,
|
|
3
|
+
* in a tmux session on WorkTrust's own socket (remote-adapter-terminal.mjs): started from a phone (`agent.start` with
|
|
4
|
+
* `mode: "terminal"`) or at the desk (`worktrust remote terminal start`), seen on both, attached at the desk with
|
|
5
|
+
* `worktrust remote attach <id>`. It outlives the daemon: a restart finds it again by its name, and stopping the daemon
|
|
6
|
+
* never ends it.
|
|
7
|
+
*
|
|
8
|
+
* The rules this file holds (test-remote-terminal):
|
|
9
|
+
* - OFF unless the person turned it on at the keyboard (`worktrust remote terminal on`, settings.terminal): no report,
|
|
10
|
+
* no start, no desk session listed. A session it already knows stays its own (never revived as a structured one).
|
|
11
|
+
* - The steered ledger names the agent's session BEFORE tmux starts it (a phone start), and BEFORE the first word a phone
|
|
12
|
+
* types into a desk session. Reading a desk session's screen is not steering it and writes nothing.
|
|
13
|
+
* - A desk session is offered only in a granted project folder and only when it carries its agent's session id
|
|
14
|
+
* (@worktrust_ref): a session the ledger could not name is never steered.
|
|
15
|
+
* - Nothing is typed unless the adapter reports prompts AND the screen's state says idle (promptAllowed); a typed prompt
|
|
16
|
+
* is accepted only when that state is seen to change afterwards (PROTOCOL.md, delivery rule 5). In this slice no
|
|
17
|
+
* screen detector exists, so the report says `prompt: false` and every prompt is refused.
|
|
18
|
+
*/
|
|
19
|
+
import { randomUUID } from "node:crypto";
|
|
20
|
+
import { basename } from "node:path";
|
|
21
|
+
import * as P from "./remote-protocol.mjs";
|
|
22
|
+
import { appendSteered } from "./remote-steered.mjs";
|
|
23
|
+
import { terminalClaudeArgs, terminalTextOk, tmuxNameOf } from "./remote-adapter-terminal.mjs";
|
|
24
|
+
import { createScreenApprovals } from "./remote-screen-approvals.mjs";
|
|
25
|
+
import { createScreenPush } from "./remote-screen-push.mjs";
|
|
26
|
+
|
|
27
|
+
const UNKNOWN = Object.freeze({ activity: "unknown", needs: null, state_change_seq: 0, completion_seq: null });
|
|
28
|
+
const NO_ETA = { kind: "unavailable", source: "none", reason: "no_source" };
|
|
29
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
30
|
+
export const TERMINAL_POLL_MS = 2000;
|
|
31
|
+
/** With control mode, a change is looked at this long after tmux reported it (a burst of output is one look). */
|
|
32
|
+
export const CONTROL_DEBOUNCE_MS = 150;
|
|
33
|
+
/** With control mode alive, the poll still looks at each session every this many rounds (a missed event costs 10 s). */
|
|
34
|
+
const CONTROL_SAFETY_ROUNDS = 5;
|
|
35
|
+
const CONTROL_TRIES = 3;
|
|
36
|
+
const STOP_GRACE_MS = 1500;
|
|
37
|
+
|
|
38
|
+
// ctx: { journal, now, emit, settings(), projects(), inventory() (offered), tmux, claudeFile(), replay, onSessionsChanged?,
|
|
39
|
+
// running() (structured sessions running), detect?(lines) -> { activity, needs } | null, sleep?(ms), markLedger?,
|
|
40
|
+
// approvals? (remote-approvals.mjs: screen dialogs), control? (false: never control mode, the poll only),
|
|
41
|
+
// pushMs?, followMs?, setTimer?, clearTimer? (remote-screen-push.mjs, for tests) }
|
|
42
|
+
export function createTerminalSessions(ctx) {
|
|
43
|
+
const live = new Map();
|
|
44
|
+
let desk = [];
|
|
45
|
+
let recovered = false;
|
|
46
|
+
const on = () => ctx.settings().terminal === true;
|
|
47
|
+
const markLedger = ctx.markLedger ?? appendSteered;
|
|
48
|
+
const sleep = ctx.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
49
|
+
const report = () => ctx.inventory().reports.find((r) => r.adapter === "claude-code" && r.mode === "terminal") ?? null;
|
|
50
|
+
const push = createScreenPush({ now: ctx.now, emit: ctx.emit, pushMs: ctx.pushMs, followMs: ctx.followMs, setTimer: ctx.setTimer, clearTimer: ctx.clearTimer });
|
|
51
|
+
const screen = ctx.approvals ? createScreenApprovals({ approvals: ctx.approvals, emit: ctx.emit, tmux: ctx.tmux, report, agent: "claude-code" }) : null;
|
|
52
|
+
const projectAt = (path) => ctx.projects().find((p) => p.path === path) ?? null;
|
|
53
|
+
const owns = (id) => live.has(id) || ctx.journal.session(id)?.terminal === true || desk.some((d) => d.session_id === id);
|
|
54
|
+
const advance = (id, kind) => { if (id) ctx.journal.advance(id, { kind }, ctx.now()); };
|
|
55
|
+
const mark = (s) => { markLedger({ v: 1, steered: "remote", adapter: "claude-code", agent_session_ref: s.agent_ref, remote_session_id: s.session_id, project_id: s.project_id, how: s.how, first_steered_at: s.first, last_steered_at: ctx.now() }); s.steered = true; };
|
|
56
|
+
|
|
57
|
+
function attention(s, activity, needs = null) {
|
|
58
|
+
const prev = s.attention;
|
|
59
|
+
if (prev && prev.activity === activity && prev.needs === needs) return false;
|
|
60
|
+
const next = { activity, needs, state_change_seq: (prev?.state_change_seq ?? 0) + 1, completion_seq: prev?.completion_seq ?? null };
|
|
61
|
+
s.attention = next;
|
|
62
|
+
ctx.emit(s.session_id, "agent.attention", next, s.command_id, P.notifyHint(prev, next));
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const sessionOf = (fields) => ({ adapter: "claude-code", attention: null, command_id: null, closed: false, stopping: false, pending: null, steered: false, name: null, model: null, first: ctx.now(), ...fields });
|
|
67
|
+
const created = (s, command_id) => ctx.emit(s.session_id, "session.created", { adapter: "claude-code", model: s.model, origin: s.origin, title: null, project_label: basename(s.projectPath).slice(0, 256) || null, name: s.name, mode: "terminal" }, command_id);
|
|
68
|
+
|
|
69
|
+
function close(s) {
|
|
70
|
+
s.closed = true;
|
|
71
|
+
s.watch?.close(); clearTimeout(s.soon); push.stop(s);
|
|
72
|
+
ctx.approvals?.withdraw(s.session_id, "the session ended");
|
|
73
|
+
live.delete(s.session_id);
|
|
74
|
+
ctx.journal.recordSession({ session_id: s.session_id, closed: true });
|
|
75
|
+
ctx.onSessionsChanged?.();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function start(env, payload) {
|
|
79
|
+
if (!on()) return "unsupported";
|
|
80
|
+
const refused = P.checkStart(payload, report() ?? undefined);
|
|
81
|
+
if (refused) return refused;
|
|
82
|
+
if (payload.prompt !== null) return "unsupported"; // nothing is typed until the screen's state is read
|
|
83
|
+
if (live.has(env.session_id) || ctx.journal.session(env.session_id)) return "conflict";
|
|
84
|
+
if (ctx.running() + live.size >= (ctx.settings().max_sessions ?? 4)) return "busy";
|
|
85
|
+
const project = ctx.projects().find((p) => p.project_id === env.project_id);
|
|
86
|
+
if (!project) return "not_found";
|
|
87
|
+
if (payload.resume !== null && !UUID.test(payload.resume)) return "unsupported";
|
|
88
|
+
const s = sessionOf({ session_id: env.session_id, project_id: project.project_id, projectPath: project.path, name: payload.name ?? null, model: payload.model, origin: "phone", how: "started",
|
|
89
|
+
tmux: tmuxNameOf(env.session_id), agent_ref: payload.resume ?? randomUUID(), command_id: env.command_id });
|
|
90
|
+
let argv;
|
|
91
|
+
try { argv = [ctx.claudeFile(), ...terminalClaudeArgs({ features: ctx.inventory().features["claude-code"], mode: payload.permission_mode, model: payload.model, resume: payload.resume, sessionRef: s.agent_ref })]; } catch { return "unsupported"; }
|
|
92
|
+
if (typeof argv[0] !== "string") return "unsupported";
|
|
93
|
+
live.set(s.session_id, s);
|
|
94
|
+
ctx.journal.recordSession({ session_id: s.session_id, adapter: "claude-code", terminal: true, origin: "phone", project_id: s.project_id, agent_session_ref: s.agent_ref, model: s.model, mode: payload.permission_mode, at: ctx.now(), name: s.name });
|
|
95
|
+
mark(s); // the ledger names the agent's session before tmux starts it
|
|
96
|
+
created(s, env.command_id);
|
|
97
|
+
if (!(await ctx.tmux.start({ name: s.tmux, cwd: project.path, argv, ref: s.agent_ref }))) {
|
|
98
|
+
advance(env.command_id, "failed");
|
|
99
|
+
ctx.emit(s.session_id, "agent.failed", { reason: "adapter_error", message: null }, env.command_id);
|
|
100
|
+
close(s);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
advance(env.command_id, "agent_accepted");
|
|
104
|
+
ctx.emit(s.session_id, "command.agent_accepted", {}, env.command_id);
|
|
105
|
+
attention(s, "unknown");
|
|
106
|
+
watch(s);
|
|
107
|
+
ctx.onSessionsChanged?.();
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A desk session the phone opened: known from now on (journal), read-only until a word is typed into it. */
|
|
112
|
+
function adopt(d) {
|
|
113
|
+
const project = projectAt(d.path);
|
|
114
|
+
if (!project || !d.ref) return null;
|
|
115
|
+
const s = sessionOf({ session_id: d.session_id, project_id: project.project_id, projectPath: project.path, origin: "desk", how: "attached", tmux: d.name, agent_ref: d.ref });
|
|
116
|
+
live.set(s.session_id, s);
|
|
117
|
+
desk = desk.filter((x) => x.session_id !== d.session_id);
|
|
118
|
+
ctx.journal.recordSession({ session_id: s.session_id, adapter: "claude-code", terminal: true, origin: "desk", project_id: s.project_id, agent_session_ref: s.agent_ref, model: null, mode: "ask", at: ctx.now(), name: null });
|
|
119
|
+
created(s, null);
|
|
120
|
+
attention(s, "unknown");
|
|
121
|
+
watch(s);
|
|
122
|
+
return s;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function stop(s) {
|
|
126
|
+
s.stopping = true;
|
|
127
|
+
await ctx.tmux.sendKey(s.tmux, "interrupt").catch(() => false);
|
|
128
|
+
for (let waited = 0; waited < STOP_GRACE_MS; waited += 250) { if ((await ctx.tmux.state(s.tmux)).dead) break; await sleep(250); }
|
|
129
|
+
await ctx.tmux.kill(s.tmux);
|
|
130
|
+
advance(s.command_id, "cancelled");
|
|
131
|
+
ctx.emit(s.session_id, "agent.stopped", {}, s.command_id);
|
|
132
|
+
close(s);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function ended(s, state) {
|
|
136
|
+
if (s.stopping) return;
|
|
137
|
+
if (state.status === 0) ctx.emit(s.session_id, "agent.stopped", {}, s.command_id);
|
|
138
|
+
else ctx.emit(s.session_id, "agent.failed", { reason: "agent_exited", message: state.status === null ? null : `The agent exited (${state.status}).` }, s.command_id);
|
|
139
|
+
ctx.tmux.kill(s.tmux).catch(() => false); // the dead pane remain-on-exit kept to read its status
|
|
140
|
+
close(s);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* What the screen says now (remote-screen-states.mjs). A prompt typed before is accepted only once the agent is SEEN
|
|
145
|
+
* taking it afterwards: working, or waiting for the person; a change to unknown (the words still in the input line, a
|
|
146
|
+
* redraw) proves nothing.
|
|
147
|
+
*/
|
|
148
|
+
function seen(s, looked) {
|
|
149
|
+
if (!looked) return;
|
|
150
|
+
const changed = attention(s, looked.activity, looked.activity === "needs_you" ? looked.needs ?? "dialog" : null);
|
|
151
|
+
if (changed && s.pending && s.attention.state_change_seq > s.pending.seq && (looked.activity === "working" || looked.activity === "needs_you")) {
|
|
152
|
+
advance(s.pending.command_id, "agent_accepted");
|
|
153
|
+
ctx.emit(s.session_id, "command.agent_accepted", {}, s.pending.command_id);
|
|
154
|
+
s.command_id = s.pending.command_id;
|
|
155
|
+
s.pending = null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** One look at a session: its end, then what its screen says, then a dialog a phone may answer. Never two at once. */
|
|
160
|
+
async function look(s) {
|
|
161
|
+
if (s.looking) { s.again = true; return; }
|
|
162
|
+
s.looking = true;
|
|
163
|
+
try {
|
|
164
|
+
do {
|
|
165
|
+
s.again = false;
|
|
166
|
+
const state = await ctx.tmux.state(s.tmux);
|
|
167
|
+
if (!state.exists || state.dead) { ended(s, state); return; }
|
|
168
|
+
// What the followers asked for, at least what the detector reads; a follower is pushed the screen when it changed.
|
|
169
|
+
const want = push.linesFor(s);
|
|
170
|
+
if (ctx.detect || want > 0) {
|
|
171
|
+
const cap = await ctx.tmux.capture(s.tmux, Math.max(100, want));
|
|
172
|
+
if (cap && ctx.detect) { seen(s, ctx.detect(cap.lines)); screen?.consider(s, cap.lines); }
|
|
173
|
+
if (cap && want > 0) push.offer(s, cap.lines.length > want ? { lines: cap.lines.slice(-want), cut: true } : cap);
|
|
174
|
+
}
|
|
175
|
+
} while (s.again && !s.closed);
|
|
176
|
+
} finally { s.looking = false; }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** tmux's control mode says WHEN to look (remote-adapter-terminal.mjs control); without it the poll looks every round. */
|
|
180
|
+
function watch(s) {
|
|
181
|
+
if (ctx.control === false || s.closed || s.watch?.alive() || (s.tries ?? 0) >= CONTROL_TRIES) return;
|
|
182
|
+
s.tries = (s.tries ?? 0) + 1;
|
|
183
|
+
s.watch = ctx.tmux.control?.(s.tmux, (kind) => {
|
|
184
|
+
if (kind === "exit") { look(s); return; }
|
|
185
|
+
clearTimeout(s.soon);
|
|
186
|
+
s.soon = setTimeout(() => look(s), CONTROL_DEBOUNCE_MS);
|
|
187
|
+
s.soon.unref?.();
|
|
188
|
+
}) ?? null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function poll() {
|
|
192
|
+
if (!recovered) { recovered = true; await recover(); }
|
|
193
|
+
for (const s of [...live.values()]) {
|
|
194
|
+
watch(s);
|
|
195
|
+
s.rounds = (s.rounds ?? 0) + 1;
|
|
196
|
+
if (!s.watch?.alive() || s.rounds % CONTROL_SAFETY_ROUNDS === 0) await look(s);
|
|
197
|
+
}
|
|
198
|
+
const before = desk.map((d) => d.session_id).join(",");
|
|
199
|
+
desk = on() ? (await ctx.tmux.list()).filter((d) => !d.dead && d.ref && !owns(d.session_id) && projectAt(d.path)) : [];
|
|
200
|
+
if (desk.map((d) => d.session_id).join(",") !== before) ctx.onSessionsChanged?.();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** After a restart: a known session whose tmux session is still there is live again; one that is gone is closed. */
|
|
204
|
+
async function recover() {
|
|
205
|
+
const ours = new Map((await ctx.tmux.list()).map((d) => [d.session_id, d]));
|
|
206
|
+
for (const j of ctx.journal.sessions()) {
|
|
207
|
+
if (j.terminal !== true || j.closed || live.has(j.session_id)) continue;
|
|
208
|
+
const d = ours.get(j.session_id), project = ctx.projects().find((p) => p.project_id === j.project_id);
|
|
209
|
+
if (!d || d.dead || !project) { ctx.journal.recordSession({ session_id: j.session_id, closed: true }); continue; }
|
|
210
|
+
live.set(j.session_id, sessionOf({ session_id: j.session_id, project_id: project.project_id, projectPath: project.path, origin: j.origin ?? "phone", how: j.origin === "desk" ? "attached" : "started",
|
|
211
|
+
tmux: d.name, agent_ref: j.agent_session_ref, model: j.model ?? null, name: j.name ?? null, attention: { ...UNKNOWN } }));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function words(s, type, payload, command_id) {
|
|
216
|
+
if (!on() || !report()?.capabilities.prompt || type === "agent.steer" || payload.interrupt === true || payload.attachments?.length) return "unsupported";
|
|
217
|
+
if (ctx.detect) { const cap = await ctx.tmux.capture(s.tmux, 100); seen(s, cap ? ctx.detect(cap.lines) : { activity: "unknown", needs: null }); } // the screen again, just before the keys
|
|
218
|
+
if (!P.promptAllowed(s.attention)) return s.attention?.activity === "needs_you" ? "agent_blocked" : "busy";
|
|
219
|
+
if (!terminalTextOk(payload.text)) return "unsupported"; // a control character is never typed
|
|
220
|
+
mark(s); // the ledger names the session before a phone's word reaches it
|
|
221
|
+
if (!(await ctx.tmux.sendText(s.tmux, payload.text)) || !(await ctx.tmux.sendKey(s.tmux, "enter"))) return "not_found";
|
|
222
|
+
s.pending = { command_id, seq: s.attention.state_change_seq };
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const statusOf = (s) => {
|
|
227
|
+
const commands = ctx.journal.commandsOf(s.session_id).slice(-100);
|
|
228
|
+
return { state: commands.at(-1)?.state ?? "DEVICE_RECEIVED", control: "none", attention: s.attention, last_event_seq: ctx.journal.lastSeq(s.session_id),
|
|
229
|
+
progress: { kind: "indeterminate" }, eta: NO_ETA, pending_approvals: [], commands };
|
|
230
|
+
};
|
|
231
|
+
const row = (s) => ({ session_id: s.session_id, project_id: s.project_id, adapter: "claude-code", mode: "terminal", origin: s.origin, attention: s.attention ?? UNKNOWN, title: null,
|
|
232
|
+
name: s.name, model: s.model, state: s.attention?.activity === "working" ? "running" : "idle", last_activity_at: ctx.journal.lastAt(s.session_id) ?? s.first });
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
owns, start, poll, statusOf,
|
|
236
|
+
get: (id) => live.get(id) ?? null,
|
|
237
|
+
runningCount: () => live.size,
|
|
238
|
+
/** The daemon stops: its control clients go, the tmux sessions stay. */
|
|
239
|
+
release() { for (const s of live.values()) { s.watch?.close(); clearTimeout(s.soon); } },
|
|
240
|
+
rows: () => [...[...live.values()].map(row),
|
|
241
|
+
...desk.map((d) => ({ session_id: d.session_id, project_id: projectAt(d.path)?.project_id ?? null, adapter: "claude-code", mode: "terminal", origin: "desk", attention: UNKNOWN, title: null, name: null, model: null, state: "idle", last_activity_at: d.created_at }))],
|
|
242
|
+
async handle(env, payload) {
|
|
243
|
+
const type = env.type;
|
|
244
|
+
let s = live.get(env.session_id) ?? null;
|
|
245
|
+
if (type === "session.rename") { if (!s && !ctx.journal.session(env.session_id)) return "not_found"; if (s) s.name = payload.name; ctx.journal.recordSession({ session_id: env.session_id, name: payload.name }); ctx.onSessionsChanged?.(); return "taken"; }
|
|
246
|
+
if (!s && type === "session.attach" && on()) { const d = desk.find((x) => x.session_id === env.session_id); if (d) s = adopt(d); }
|
|
247
|
+
if (!s) return "not_found";
|
|
248
|
+
if (type === "session.attach") { ctx.replay(s.session_id, 0); return "taken"; }
|
|
249
|
+
if (type === "screen.read") {
|
|
250
|
+
push.follow(s, env.sender_device_id, payload.follow, payload.lines); // remote-screen-push.mjs
|
|
251
|
+
const cap = await ctx.tmux.capture(s.tmux, payload.lines);
|
|
252
|
+
if (!cap) return "not_found";
|
|
253
|
+
ctx.emit(s.session_id, "agent.screen", cap, env.command_id);
|
|
254
|
+
push.answered(s, cap);
|
|
255
|
+
return "taken";
|
|
256
|
+
}
|
|
257
|
+
if (type === "status.get") { ctx.emit(s.session_id, "status.report", statusOf(s), env.command_id); return "taken"; }
|
|
258
|
+
if (type === "agent.stop" || type === "session.close") { await stop(s); return "taken"; }
|
|
259
|
+
if (type === "agent.prompt" || type === "agent.steer") return words(s, type, payload, env.command_id);
|
|
260
|
+
if (type === "question.answer") return "not_found";
|
|
261
|
+
return "unsupported"; // pause, resume, focus (tmux cannot raise a window: the phone shows `worktrust remote attach <id>`)
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* One registry for the daemon: terminal sessions answered by their own module, every other one by remote-sessions.mjs.
|
|
268
|
+
* The daemon stopping ends the structured agents and never a terminal session (it lives in tmux, perhaps at the desk).
|
|
269
|
+
*/
|
|
270
|
+
export function withTerminal(structured, terminal, { pollMs = TERMINAL_POLL_MS } = {}) {
|
|
271
|
+
const timer = setInterval(() => { terminal.poll().catch(() => {}); }, pollMs);
|
|
272
|
+
timer.unref?.();
|
|
273
|
+
const merged = () => {
|
|
274
|
+
const rows = terminal.rows(), ids = new Set(rows.map((r) => r.session_id));
|
|
275
|
+
const rest = structured.listAll().filter((r) => !ids.has(r.session_id)).map((r) => (terminal.owns(r.session_id) ? { ...r, mode: "terminal" } : r));
|
|
276
|
+
return [...rows, ...rest].sort((a, b) => (b.last_activity_at ?? 0) - (a.last_activity_at ?? 0));
|
|
277
|
+
};
|
|
278
|
+
return {
|
|
279
|
+
...structured,
|
|
280
|
+
async handle(env, payload) {
|
|
281
|
+
if (env.type === "agent.start") return payload.mode === "terminal" ? terminal.start(env, payload) : structured.handle(env, payload);
|
|
282
|
+
return terminal.owns(env.session_id) ? terminal.handle(env, payload) : structured.handle(env, payload);
|
|
283
|
+
},
|
|
284
|
+
list: () => [...structured.list().filter((r) => !terminal.owns(r.session_id)), ...terminal.rows()],
|
|
285
|
+
listAll: merged,
|
|
286
|
+
get: (id) => structured.get(id) ?? terminal.get(id),
|
|
287
|
+
statusOf: (s) => (terminal.get(s.session_id) === s ? terminal.statusOf(s) : structured.statusOf(s)),
|
|
288
|
+
runningCount: () => structured.runningCount() + terminal.runningCount(),
|
|
289
|
+
async stopAll() { clearInterval(timer); terminal.release?.(); await structured.stopAll(); },
|
|
290
|
+
};
|
|
291
|
+
}
|
package/worktrust.mjs
CHANGED
|
@@ -78,7 +78,7 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
|
|
|
78
78
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
79
79
|
const has = (name) => args.includes(`--${name}`);
|
|
80
80
|
/** This CLI's version, said to the door so the app can tell which computer runs an old one (check-cli-package holds it equal to package.json). */
|
|
81
|
-
const CLI_VERSION = "0.11.
|
|
81
|
+
const CLI_VERSION = "0.11.1";
|
|
82
82
|
/**
|
|
83
83
|
* HOW THIS CLI MEASURES, AS A NUMBER OF ITS OWN (0.10.31; owner, 2026-10-28: 0.10.30 offered a re-measure it had no reason
|
|
84
84
|
* to offer). Raised ONLY when what is measured changes: the timeline, the seconds, the tokens, the steering, the session
|
|
@@ -110,7 +110,7 @@ const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.w
|
|
|
110
110
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
111
111
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
112
112
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
113
|
-
const SCRIPTS = ["credential-store.mjs", "remote-protocol.mjs", "remote-store.mjs", "remote-policy.mjs", "remote-journal.mjs", "remote-steered.mjs", "remote-inventory.mjs", "remote-claude-events.mjs", "remote-claude-progress.mjs", "remote-attachments.mjs", "remote-preview.mjs", "remote-coalesce.mjs", "remote-steering.mjs", "remote-codex-events.mjs", "remote-adapter-codex.mjs", "remote-projects.mjs", "remote-pipeline-config.mjs", "remote-pipeline-parsers.mjs", "remote-pipeline.mjs", "remote-releases.mjs", "remote-release-plans.mjs", "remote-adapter-claude-code.mjs", "remote-approval-bridge.mjs", "remote-approvals.mjs", "remote-sessions.mjs", "remote-session-list.mjs", "remote-changes.mjs", "remote-daemon.mjs", "remote-transport.mjs", "remote-run.mjs", "remote-service.mjs", "remote-pairing.mjs", "remote-qr.mjs", "remote-cli.mjs", "credential-vault.mjs", "credential-vault-scripts.mjs", "history-outbox.mjs", "setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs", "commit-rules.mjs", "git-commits.mjs", "self-update.mjs", "history-progress.mjs"];
|
|
113
|
+
const SCRIPTS = ["credential-store.mjs", "remote-protocol.mjs", "remote-store.mjs", "remote-policy.mjs", "remote-journal.mjs", "remote-steered.mjs", "remote-inventory.mjs", "remote-claude-events.mjs", "remote-claude-progress.mjs", "remote-attachments.mjs", "remote-preview.mjs", "remote-coalesce.mjs", "remote-steering.mjs", "remote-codex-events.mjs", "remote-adapter-codex.mjs", "remote-adapter-terminal.mjs", "remote-terminal-sessions.mjs", "remote-terminal-cli.mjs", "remote-screen-states.mjs", "remote-screen-approvals.mjs", "remote-screen-push.mjs", "remote-cdp.mjs", "remote-live-preview.mjs", "remote-projects.mjs", "remote-pipeline-config.mjs", "remote-pipeline-parsers.mjs", "remote-pipeline.mjs", "remote-releases.mjs", "remote-release-plans.mjs", "remote-adapter-claude-code.mjs", "remote-approval-bridge.mjs", "remote-approvals.mjs", "remote-sessions.mjs", "remote-session-list.mjs", "remote-changes.mjs", "remote-daemon.mjs", "remote-transport.mjs", "remote-run.mjs", "remote-service.mjs", "remote-pairing.mjs", "remote-qr.mjs", "remote-cli.mjs", "credential-vault.mjs", "credential-vault-scripts.mjs", "history-outbox.mjs", "setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs", "commit-rules.mjs", "git-commits.mjs", "self-update.mjs", "history-progress.mjs"];
|
|
114
114
|
/** The modules the scripts import by name from beside them; a download keeps that name. */
|
|
115
115
|
const IMPORTED = new Set(["transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "commit-rules.mjs", "git-commits.mjs"]);
|
|
116
116
|
const downloaded = (name) => (IMPORTED.has(name) ? name : `${name}.download.mjs`);
|