worktrust 0.10.37 → 0.11.0
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/LICENSE +43 -18
- package/README.md +59 -2
- package/SECURITY.md +25 -0
- package/chat-exports.mjs +20 -20
- package/engine-release.json +1 -1
- package/export-facts.mjs +71 -0
- package/log-session.mjs +15 -15
- package/package-release.json +1 -1
- package/package.json +36 -2
- package/remote-adapter-claude-code.mjs +111 -0
- package/remote-adapter-codex.mjs +119 -0
- package/remote-approval-bridge.mjs +122 -0
- package/remote-approvals.mjs +124 -0
- package/remote-attachments.mjs +129 -0
- package/remote-changes.mjs +94 -0
- package/remote-claude-events.mjs +212 -0
- package/remote-claude-progress.mjs +328 -0
- package/remote-cli.mjs +325 -0
- package/remote-coalesce.mjs +40 -0
- package/remote-codex-events.mjs +153 -0
- package/remote-daemon.mjs +205 -0
- package/remote-inventory.mjs +132 -0
- package/remote-journal.mjs +155 -0
- package/remote-pairing.mjs +104 -0
- package/remote-pipeline-config.mjs +177 -0
- package/remote-pipeline-parsers.mjs +121 -0
- package/remote-pipeline.mjs +234 -0
- package/remote-policy.mjs +199 -0
- package/remote-preview.mjs +146 -0
- package/remote-projects.mjs +87 -0
- package/remote-protocol.mjs +3881 -0
- package/remote-qr.mjs +175 -0
- package/remote-release-plans.mjs +88 -0
- package/remote-releases.mjs +297 -0
- package/remote-run.mjs +174 -0
- package/remote-service.mjs +101 -0
- package/remote-session-list.mjs +25 -0
- package/remote-sessions.mjs +348 -0
- package/remote-steered.mjs +114 -0
- package/remote-steering.mjs +97 -0
- package/remote-store.mjs +123 -0
- package/remote-transport.mjs +88 -0
- package/worktrust.mjs +13 -6
package/remote-run.mjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `worktrust remote run`: THE DAEMON, WIRED (2026-11-07). The service manager starts it (remote-service.mjs), or the
|
|
3
|
+
* person runs it in the foreground (Windows: foreground only). It refuses to start unless remote is enabled, this computer
|
|
4
|
+
* is paired, a gateway is set and this Node has a WebSocket; it holds a lock so one runs per user; it closes as FAILED any
|
|
5
|
+
* command an earlier run left mid-way (never runs it again); it stops every agent it started when it stops, and it exits
|
|
6
|
+
* by itself when `worktrust remote disable` turns remote off.
|
|
7
|
+
*
|
|
8
|
+
* The agents it starts get this user's environment with every WORKTRUST_ variable removed (no measurement credential, no
|
|
9
|
+
* remote secret) and the PATH the person had when they enabled remote.
|
|
10
|
+
*/
|
|
11
|
+
import { execFileSync } from "node:child_process";
|
|
12
|
+
import { closeSync, openSync, readFileSync, rmSync, writeSync, constants } from "node:fs";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
import * as P from "./remote-protocol.mjs";
|
|
16
|
+
import { loadPreviewGrants } from "./remote-store.mjs";
|
|
17
|
+
import { ensureRemoteDir, issuerKeys, loadDeskMarks, loadIdentity, loadKeys, loadPipelineReviews, loadProjects, loadSettings, readJson, remotePath, random, saveIdentity } from "./remote-store.mjs";
|
|
18
|
+
import { openJournal } from "./remote-journal.mjs";
|
|
19
|
+
import { inventory as listAgents, offered } from "./remote-inventory.mjs";
|
|
20
|
+
|
|
21
|
+
/** The agents as a phone may use them: what is installed, less what the person has not turned on (Codex). */
|
|
22
|
+
const inventory = (o) => offered(listAgents(o), loadSettings());
|
|
23
|
+
import { createApprovals } from "./remote-approvals.mjs";
|
|
24
|
+
import { createSessions } from "./remote-sessions.mjs";
|
|
25
|
+
import { createReleases } from "./remote-releases.mjs";
|
|
26
|
+
import { createPipelines } from "./remote-pipeline.mjs";
|
|
27
|
+
import { createAttachments } from "./remote-attachments.mjs";
|
|
28
|
+
import { createPreview } from "./remote-preview.mjs";
|
|
29
|
+
import { appendPipelineMark } from "./remote-steered.mjs";
|
|
30
|
+
import { createDaemonCore } from "./remote-daemon.mjs";
|
|
31
|
+
import { connectGateway, webSocketAvailable } from "./remote-transport.mjs";
|
|
32
|
+
|
|
33
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
34
|
+
const log = (kind, fields = {}) => process.stderr.write(`${JSON.stringify({ at: new Date().toISOString(), kind, ...fields })}\n`);
|
|
35
|
+
|
|
36
|
+
export function agentEnv(settings, base = process.env) {
|
|
37
|
+
const env = {};
|
|
38
|
+
for (const [key, value] of Object.entries(base)) if (!/^WORKTRUST_/.test(key) && !/^CLAUDE_?CODE/.test(key) && key !== "CLAUDECODE") env[key] = value;
|
|
39
|
+
if (settings.agent_path) env.PATH = settings.agent_path;
|
|
40
|
+
return env;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A pipeline stage's environment: the agents' (no WORKTRUST_ variable), the reviewed folders first on PATH, CI set. */
|
|
44
|
+
export function stageEnv(settings, prepend = [], base = process.env) {
|
|
45
|
+
const env = agentEnv(settings, base);
|
|
46
|
+
env.PATH = [...prepend, env.PATH ?? ""].filter(Boolean).join(process.platform === "win32" ? ";" : ":");
|
|
47
|
+
env.CI = "1";
|
|
48
|
+
return env;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Agents run in process groups of their own, so a daemon that crashed leaves them running. A new daemon ends every group
|
|
53
|
+
* an earlier one recorded whose process is still that session's agent (its command line names the session's own id),
|
|
54
|
+
* before it takes any command (review 2026-11-07, P2-b).
|
|
55
|
+
*/
|
|
56
|
+
/** A process's command line, or "" (the reapers check it is still the process they recorded before they end it). */
|
|
57
|
+
export function commandOf(pid) {
|
|
58
|
+
try { return execFileSync("ps", ["-o", "command=", "-p", String(pid)], { encoding: "utf8", timeout: 5000 }); } catch { return ""; }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function reapOrphans(journal, kill = process.kill.bind(process)) {
|
|
62
|
+
let reaped = 0;
|
|
63
|
+
for (const s of journal.sessions()) {
|
|
64
|
+
if (!Number.isSafeInteger(s.pid) || s.pid <= 1 || !s.agent_session_ref) continue;
|
|
65
|
+
let command = "";
|
|
66
|
+
try { command = execFileSync("ps", ["-o", "command=", "-p", String(s.pid)], { encoding: "utf8", timeout: 5000 }); } catch { command = ""; }
|
|
67
|
+
if (!command.includes(s.agent_session_ref)) { journal.recordSession({ session_id: s.session_id, pid: null }); continue; }
|
|
68
|
+
try { kill(-s.pid, "SIGTERM"); reaped += 1; } catch { /* gone */ }
|
|
69
|
+
journal.recordSession({ session_id: s.session_id, pid: null });
|
|
70
|
+
}
|
|
71
|
+
return reaped;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function lock() {
|
|
75
|
+
const file = remotePath("daemon.lock");
|
|
76
|
+
try {
|
|
77
|
+
const fd = openSync(file, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 0o600);
|
|
78
|
+
writeSync(fd, String(process.pid)); closeSync(fd);
|
|
79
|
+
} catch {
|
|
80
|
+
const pid = Number(readFileSync(file, "utf8"));
|
|
81
|
+
let alive = false;
|
|
82
|
+
try { process.kill(pid, 0); alive = pid !== process.pid; } catch { alive = false; }
|
|
83
|
+
if (alive) throw new Error(`another remote daemon runs (pid ${pid})`);
|
|
84
|
+
rmSync(file, { force: true });
|
|
85
|
+
return lock();
|
|
86
|
+
}
|
|
87
|
+
return () => rmSync(file, { force: true });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function runDaemon({ say = (l) => process.stdout.write(`${l}\n`) } = {}) {
|
|
91
|
+
ensureRemoteDir();
|
|
92
|
+
const settings = loadSettings(), identity = loadIdentity(), keys = loadKeys();
|
|
93
|
+
if (!settings.enabled) throw new Error("remote is off on this computer: run `worktrust remote enable`");
|
|
94
|
+
if (!identity || !keys) throw new Error("this computer is not paired for remote: run `worktrust remote enable`");
|
|
95
|
+
if (!settings.gateway) throw new Error("no gateway is set: the production gateway is not live yet; for local tests pass --gateway ws://127.0.0.1:<port> to `worktrust remote enable`");
|
|
96
|
+
if (!webSocketAvailable()) throw new Error(`remote needs Node 22.4 or later (this is ${process.versions.node})`);
|
|
97
|
+
const keysOf = issuerKeys(settings.gateway);
|
|
98
|
+
const claims = P.verifyBinding(identity.binding, { issuerKeys: keysOf, now: Date.now(), kind: "computer", deviceId: identity.device_id });
|
|
99
|
+
if (!claims.ok) throw new Error(`this computer's binding does not verify (${claims.code}): run \`worktrust remote enable\` again`);
|
|
100
|
+
if (claims.value.exp * 1000 - Date.now() < 7 * 86400_000 && identity.origin) {
|
|
101
|
+
// A binding lives thirty days: renewed in its last week while the device is still approved (docs/remote-agents/ISSUER.md §4).
|
|
102
|
+
const { renewBinding } = await import("./remote-pairing.mjs");
|
|
103
|
+
const fresh = await renewBinding({ origin: identity.origin, identity, secret: keys.secret }).catch(() => null);
|
|
104
|
+
const checked = fresh && P.verifyBinding(fresh, { issuerKeys: keysOf, now: Date.now(), kind: "computer", deviceId: identity.device_id });
|
|
105
|
+
if (checked?.ok && checked.value.ed25519_pub === claims.value.ed25519_pub) { saveIdentity({ ...identity, binding: fresh }); identity.binding = fresh; }
|
|
106
|
+
else log("binding_not_renewed", {});
|
|
107
|
+
}
|
|
108
|
+
const release = lock();
|
|
109
|
+
const journal = openJournal(remotePath("journal.jsonl"));
|
|
110
|
+
for (const id of journal.interrupted()) journal.advance(id, { kind: "failed" }, Date.now(), "interrupted"); // never run again
|
|
111
|
+
if (process.platform !== "win32") reapOrphans(journal);
|
|
112
|
+
journal.compact(Date.now());
|
|
113
|
+
const runDir = remotePath("run");
|
|
114
|
+
let transport = null;
|
|
115
|
+
const local = { secret: keys.secret, binding: identity.binding, claims: claims.value };
|
|
116
|
+
// Files from the phone (into the session's project inbox) and the local preview (2026-11-07).
|
|
117
|
+
const attachments = createAttachments({ journal, now: Date.now, emit: (...a) => core.emit(...a), log,
|
|
118
|
+
sessionProject: (id) => { const s = journal.session(id); return s ? loadProjects().find((p) => p.project_id === s.project_id) ?? null : null; } });
|
|
119
|
+
const preview = createPreview({ emit: (...a) => core.emit(...a), projects: loadProjects, grants: loadPreviewGrants, env: () => agentEnv(loadSettings()), log });
|
|
120
|
+
const core = createDaemonCore({ local, issuerKeys: keysOf, journal, projectSecret: keys.projectSecret, attachments, preview, now: Date.now, random, log, send: (f) => transport?.send(f) ?? false, inventory: (refresh) => inventory({ env: agentEnv(loadSettings()), refresh }), online: () => transport?.ready() ?? false, approvals: null });
|
|
121
|
+
const ctx = { journal, now: Date.now, random, deviceId: identity.device_id, emit: core.emit, paused: () => loadSettings().paused !== null || !loadSettings().enabled, phoneOnline: core.phoneOnline, controllers: core.controllers };
|
|
122
|
+
const approvals = createApprovals(ctx);
|
|
123
|
+
const socket = await approvals.listen(runDir);
|
|
124
|
+
let releases = null; // set below; the hooks run only once events flow
|
|
125
|
+
const sessions = createSessions({ ...ctx, approvals, runDir, node: process.execPath, bridgePath: join(HERE, "remote-approval-bridge.mjs"), socket: () => socket,
|
|
126
|
+
settings: loadSettings, projects: loadProjects, inventory: () => inventory({ env: agentEnv(loadSettings()) }), agentEnv: () => agentEnv(loadSettings()), replay: core.replay,
|
|
127
|
+
onTaskEnded: (id, outcome) => releases.taskEnded(id, outcome), onActivity: () => releases?.activity(),
|
|
128
|
+
onSessionsChanged: () => core.emit(null, "device.inventory", core.inventoryBody(false)), attachments });
|
|
129
|
+
ctx.onApprovalOpened = sessions.onApprovalOpened; ctx.onApprovalSettled = sessions.onApprovalSettled;
|
|
130
|
+
// Releases and pipelines (2026-11-07): one queue for every release's tasks, the reviewed pipeline of each project.
|
|
131
|
+
const pipelines = createPipelines({ journal, now: Date.now, random, emit: core.emit, projects: loadProjects, reviews: loadPipelineReviews, log, logDir: remotePath("pipelines"),
|
|
132
|
+
markLedger: appendPipelineMark, env: (prepend) => stageEnv(loadSettings(), prepend), onEnded: (p) => releases?.pipelineEnded(p), commandOf });
|
|
133
|
+
releases = createReleases({ journal, now: Date.now, random, emit: core.emit, projects: loadProjects, settings: loadSettings, paused: ctx.paused, inventory: () => inventory({ env: agentEnv(loadSettings()) }),
|
|
134
|
+
sessions, pipelines, deskMarks: loadDeskMarks, log });
|
|
135
|
+
// The agent plans its own work (plan_* over the approval socket, 2026-11-08): the same queue, the session's own project.
|
|
136
|
+
ctx.plan = (session, op, args) => releases.plan(session, op, args);
|
|
137
|
+
releases.recover(); // tasks an earlier daemon left running: interrupted, never run again
|
|
138
|
+
pipelines.recover(); // and its pipeline runs
|
|
139
|
+
core.attach(sessions, approvals, releases);
|
|
140
|
+
|
|
141
|
+
const dispatchFrame = async (frame) => {
|
|
142
|
+
if (frame.frame === "hello") core.receiveHello(frame.hello);
|
|
143
|
+
else if (frame.frame === "command") await core.receiveCommand(frame.envelope);
|
|
144
|
+
else if (frame.frame === "relay") { log("relay", { type: frame.event?.type ?? null }); if (frame.event?.type === "device.revoked") core.peerRevoked(frame.event); }
|
|
145
|
+
else if (frame.frame === "error") log("gateway_error", { reason: typeof frame.reason === "string" ? frame.reason.slice(0, 40) : null });
|
|
146
|
+
};
|
|
147
|
+
let sentCode = null;
|
|
148
|
+
const registerCode = (again = false) => {
|
|
149
|
+
const invite = readJson("invite.json");
|
|
150
|
+
if (invite?.code && !invite.used && invite.e * 1000 > Date.now() && (again || sentCode !== invite.code) && transport?.send({ frame: "pair_ticket", ticket: invite.code, expires_at: invite.e * 1000 })) sentCode = invite.code;
|
|
151
|
+
};
|
|
152
|
+
// The production gateway admits a computer on a five-minute assertion from the issuer, asked fresh for every challenge.
|
|
153
|
+
const { requestAssertion } = await import("./remote-pairing.mjs");
|
|
154
|
+
const authorize = () => (identity.origin ? requestAssertion({ origin: identity.origin, deviceId: identity.device_id, secret: keys.secret }) : Promise.resolve(null));
|
|
155
|
+
transport = connectGateway({ url: settings.gateway, identity, signingSecret: keys.secret.ed25519, log, authorize, onFrame: (f) => { dispatchFrame(f).catch((e) => log("frame_failed", { name: e?.name ?? "Error" })); },
|
|
156
|
+
onState: (state, info) => { log("gateway", { state, ...info }); if (state === "ready") registerCode(true); } });
|
|
157
|
+
say(` WorkTrust remote is running for ${identity.device_id} (gateway ${new URL(settings.gateway).host}). Ctrl+C stops it.`);
|
|
158
|
+
let stopping = false;
|
|
159
|
+
const stop = async (code = 0) => {
|
|
160
|
+
if (stopping) return;
|
|
161
|
+
stopping = true;
|
|
162
|
+
approvals.close();
|
|
163
|
+
await pipelines.stopAll();
|
|
164
|
+
await sessions.stopAll();
|
|
165
|
+
transport.close();
|
|
166
|
+
release();
|
|
167
|
+
process.exit(code);
|
|
168
|
+
};
|
|
169
|
+
process.on("SIGINT", () => stop(0));
|
|
170
|
+
process.on("SIGTERM", () => stop(0));
|
|
171
|
+
setInterval(() => { const s = loadSettings(); if (!s.enabled) stop(0); registerCode(); releases.poll(); }, 3000).unref();
|
|
172
|
+
releases.schedule(); // queued tasks a restart kept
|
|
173
|
+
return new Promise(() => {});
|
|
174
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE DAEMON AS A SERVICE OF THIS USER (2026-11-07). Off until `worktrust remote enable`; removed by `disable`.
|
|
3
|
+
*
|
|
4
|
+
* macOS a launchd agent, ~/Library/LaunchAgents/io.worktrust.remote.plist: RunAtLoad, restarted after a crash
|
|
5
|
+
* (KeepAlive SuccessfulExit false), so `disable` (exit 0) stays off; logs in ~/.worktrust/remote/daemon.log
|
|
6
|
+
* Linux a systemd user unit, ~/.config/systemd/user/worktrust-remote.service, Restart=on-failure, the agents in its
|
|
7
|
+
* control group (they stop with it). Linger stays OFF: it runs while this user is logged in, never as standing
|
|
8
|
+
* remote execution on a machine nobody is logged into. Nothing here calls loginctl.
|
|
9
|
+
* Windows no service: `worktrust remote run` in a terminal, in the foreground, for as long as it should run.
|
|
10
|
+
*
|
|
11
|
+
* The unit runs the verified release launcher the CLI installed, with the PATH the person had when they enabled remote
|
|
12
|
+
* (so the agents are found) and nothing else from their environment. Every command is execFile with fixed arguments.
|
|
13
|
+
*/
|
|
14
|
+
import { execFileSync } from "node:child_process";
|
|
15
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { homedir, userInfo } from "node:os";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
|
|
19
|
+
export const LABEL = "io.worktrust.remote";
|
|
20
|
+
export const UNIT = "worktrust-remote.service";
|
|
21
|
+
const xml = (text) => String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
22
|
+
const unitQuote = (text) => `"${String(text).replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "%%")}"`;
|
|
23
|
+
|
|
24
|
+
export const servicePlatform = (platform = process.platform) => (platform === "darwin" ? "launchd" : platform === "linux" ? "systemd" : "foreground");
|
|
25
|
+
export const plistPath = (home = homedir()) => join(home, "Library", "LaunchAgents", `${LABEL}.plist`);
|
|
26
|
+
export const unitPath = (home = homedir()) => join(home, ".config", "systemd", "user", UNIT);
|
|
27
|
+
|
|
28
|
+
export function launchdPlist({ program, path, home = homedir() }) {
|
|
29
|
+
const args = program.map((a) => ` <string>${xml(a)}</string>`).join("\n");
|
|
30
|
+
const log = xml(join(home, ".worktrust", "remote", "daemon.log"));
|
|
31
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
32
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
33
|
+
<plist version="1.0">
|
|
34
|
+
<dict>
|
|
35
|
+
<key>Label</key><string>${LABEL}</string>
|
|
36
|
+
<key>ProgramArguments</key>
|
|
37
|
+
<array>
|
|
38
|
+
${args}
|
|
39
|
+
</array>
|
|
40
|
+
<key>RunAtLoad</key><true/>
|
|
41
|
+
<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
|
|
42
|
+
<key>ThrottleInterval</key><integer>10</integer>
|
|
43
|
+
<key>EnvironmentVariables</key><dict><key>PATH</key><string>${xml(path)}</string><key>HOME</key><string>${xml(home)}</string></dict>
|
|
44
|
+
<key>StandardOutPath</key><string>${log}</string>
|
|
45
|
+
<key>StandardErrorPath</key><string>${log}</string>
|
|
46
|
+
</dict>
|
|
47
|
+
</plist>
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function systemdUnit({ program, path }) {
|
|
52
|
+
return `[Unit]
|
|
53
|
+
Description=WorkTrust remote agents (steer this computer's agents from your phone)
|
|
54
|
+
|
|
55
|
+
[Service]
|
|
56
|
+
ExecStart=${program.map(unitQuote).join(" ")}
|
|
57
|
+
Environment=${unitQuote(`PATH=${path}`)}
|
|
58
|
+
Restart=on-failure
|
|
59
|
+
RestartSec=10
|
|
60
|
+
KillMode=control-group
|
|
61
|
+
|
|
62
|
+
[Install]
|
|
63
|
+
WantedBy=default.target
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const run = (file, args) => { try { execFileSync(file, args, { stdio: "ignore", timeout: 15_000 }); return true; } catch { return false; } };
|
|
68
|
+
|
|
69
|
+
/** Install and start. `program` is [node, ...nodeArgs, launcher, "remote", "run"]. Returns what was done, in words. */
|
|
70
|
+
export function installService({ program, path, platform = process.platform, home = homedir() }) {
|
|
71
|
+
const kind = servicePlatform(platform);
|
|
72
|
+
if (kind === "launchd") {
|
|
73
|
+
const file = plistPath(home);
|
|
74
|
+
mkdirSync(join(home, "Library", "LaunchAgents"), { recursive: true });
|
|
75
|
+
writeFileSync(file, launchdPlist({ program, path, home }), { mode: 0o644 });
|
|
76
|
+
const domain = `gui/${userInfo().uid}`;
|
|
77
|
+
run("launchctl", ["bootout", `${domain}/${LABEL}`]);
|
|
78
|
+
return { kind, file, started: run("launchctl", ["bootstrap", domain, file]) };
|
|
79
|
+
}
|
|
80
|
+
if (kind === "systemd") {
|
|
81
|
+
const file = unitPath(home);
|
|
82
|
+
mkdirSync(join(home, ".config", "systemd", "user"), { recursive: true });
|
|
83
|
+
writeFileSync(file, systemdUnit({ program, path }), { mode: 0o644 });
|
|
84
|
+
return { kind, file, started: run("systemctl", ["--user", "daemon-reload"]) && run("systemctl", ["--user", "enable", "--now", UNIT]) };
|
|
85
|
+
}
|
|
86
|
+
return { kind, file: null, started: false };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function removeService({ platform = process.platform, home = homedir() } = {}) {
|
|
90
|
+
const kind = servicePlatform(platform);
|
|
91
|
+
if (kind === "launchd") { run("launchctl", ["bootout", `gui/${userInfo().uid}/${LABEL}`]); rmSync(plistPath(home), { force: true }); return kind; }
|
|
92
|
+
if (kind === "systemd") { run("systemctl", ["--user", "disable", "--now", UNIT]); rmSync(unitPath(home), { force: true }); run("systemctl", ["--user", "daemon-reload"]); return kind; }
|
|
93
|
+
return kind;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function serviceState({ platform = process.platform, home = homedir() } = {}) {
|
|
97
|
+
const kind = servicePlatform(platform);
|
|
98
|
+
if (kind === "launchd") return { kind, installed: existsSync(plistPath(home)), running: run("launchctl", ["print", `gui/${userInfo().uid}/${LABEL}`]) };
|
|
99
|
+
if (kind === "systemd") return { kind, installed: existsSync(unitPath(home)), running: run("systemctl", ["--user", "is-active", "--quiet", UNIT]) };
|
|
100
|
+
return { kind, installed: false, running: false };
|
|
101
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE PROJECT TREE'S SESSION LIST, split out of remote-sessions.mjs (its size), unchanged: the journal's sessions and the
|
|
3
|
+
* live ones, as device.inventory lists them.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The project tree (2026-11-07): every session this computer knows, live first in its state, then those the journal
|
|
8
|
+
* holds (closed, or waiting to resume after a restart), newest activity first. Names and models are sealed.
|
|
9
|
+
*/
|
|
10
|
+
export function listSessions(ctx, live) {
|
|
11
|
+
const rows = new Map();
|
|
12
|
+
for (const j of ctx.journal.sessions()) {
|
|
13
|
+
if (!j.session_id || !j.adapter) continue;
|
|
14
|
+
rows.set(j.session_id, { session_id: j.session_id, project_id: j.project_id ?? null, adapter: j.adapter, origin: "phone", attention: { activity: "unknown", needs: null, state_change_seq: 0, completion_seq: null }, title: null,
|
|
15
|
+
name: j.name ?? null, model: j.model ?? null, state: j.closed ? "closed" : "idle", last_activity_at: ctx.journal.lastAt(j.session_id) ?? j.at ?? null });
|
|
16
|
+
}
|
|
17
|
+
for (const s of live.values()) {
|
|
18
|
+
if (s.closed) continue;
|
|
19
|
+
const prior = rows.get(s.session_id);
|
|
20
|
+
rows.set(s.session_id, { ...(prior ?? {}), session_id: s.session_id, project_id: s.project_id, adapter: s.adapter, origin: "phone", attention: s.attention ?? { activity: "unknown", needs: null, state_change_seq: 0, completion_seq: null }, title: null,
|
|
21
|
+
name: s.name ?? null, model: s.model ?? null, state: s.turnOpen ? "running" : "idle", last_activity_at: ctx.journal.lastAt(s.session_id) ?? prior?.last_activity_at ?? null,
|
|
22
|
+
...(s.jobs ? { background_jobs: Math.min(99, s.jobs.size) } : {}) });
|
|
23
|
+
}
|
|
24
|
+
return [...rows.values()].sort((a, b) => (b.last_activity_at ?? 0) - (a.last_activity_at ?? 0));
|
|
25
|
+
}
|