worktrust 0.10.24 → 0.10.26
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/AGENTS.md +1 -1
- package/README.md +46 -20
- package/SECURITY.md +38 -8
- package/credential-store.mjs +109 -0
- package/credential-vault-scripts.mjs +82 -0
- package/credential-vault.mjs +49 -0
- package/engine-release.json +1 -1
- package/log-session.mjs +19 -84
- package/package-integrity.mjs +83 -6
- package/package-release.json +1 -1
- package/package.json +5 -2
- package/preserve-lines.mjs +2 -1
- package/preserve.mjs +16 -17
- package/runtime-install.mjs +48 -6
- package/setup-mcp.mjs +20 -18
- package/worktrust-launch.mjs +90 -8
- package/worktrust.mjs +69 -62
package/worktrust-launch.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// GENERATED by scripts/build-cli-launchers.mjs; verify before importing any local module.
|
|
3
3
|
/** Official launcher verification. Pinned keys are generated from reviewed release configuration. */
|
|
4
4
|
import { createHash, createPublicKey, verify, randomBytes } from 'node:crypto';
|
|
5
|
-
import { existsSync, lstatSync, readFileSync, readdirSync, mkdirSync, writeFileSync, renameSync, rmSync } from 'node:fs';
|
|
6
|
-
import { join, dirname } from 'node:path';
|
|
5
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, mkdirSync, writeFileSync, renameSync, rmSync, constants, openSync, closeSync, fstatSync, fchmodSync, readSync, fsyncSync } from 'node:fs';
|
|
6
|
+
import { join, dirname, basename, isAbsolute } from 'node:path';
|
|
7
7
|
|
|
8
8
|
const RELEASE_KEYS = {"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5":"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAxe/h8yLe+e4iKYSx/2lzS7MgHIgzM+mi1XjofW1VKo4=\n-----END PUBLIC KEY-----\n"}; // GENERATED_RELEASE_KEYS
|
|
9
9
|
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
@@ -18,7 +18,7 @@ const exact = (value, keys) => value && Object.keys(value).sort().join(',') ===
|
|
|
18
18
|
const safe = name => {
|
|
19
19
|
if (typeof name !== 'string' || name.length > 240) return false;
|
|
20
20
|
const parts = name.split('/');
|
|
21
|
-
return parts.every((p, i) => (/^[A-Za-z0-
|
|
21
|
+
return parts.every((p, i) => (/^[A-Za-z0-9_][A-Za-z0-9._-]*$/.test(p) && p !== '..')
|
|
22
22
|
|| (p === '.claude-plugin' && i > 0 && i < parts.length - 1 && parts[i - 1] === 'agent'));
|
|
23
23
|
};
|
|
24
24
|
function regular(path) {
|
|
@@ -46,7 +46,7 @@ function verifyPackage(root, kind = 'npm') {
|
|
|
46
46
|
|| !verify(null, Buffer.from('worktrust:package:1\n' + canonical(signed.payload)), key, Buffer.from(signed.signature, 'base64url'))) throw Error('PACKAGE_UNTRUSTED_SIGNATURE');
|
|
47
47
|
const m = signed.payload;
|
|
48
48
|
if (!exact(m, ['format', 'kind', 'version', 'files']) || m.format !== 'worktrust-package/1' || m.kind !== kind || !/^\d+\.\d+\.\d+$/.test(m.version)
|
|
49
|
-
|| !m.files || Array.isArray(m.files) || typeof m.files !== 'object' || Object.keys(m.files).length > 2000 || !Object.hasOwn(m.files, 'worktrust.mjs')) throw Error('PACKAGE_INVALID_MANIFEST');
|
|
49
|
+
|| !m.files || Array.isArray(m.files) || typeof m.files !== 'object' || Object.keys(m.files).length > 2000 || !Object.hasOwn(m.files, kind === 'python' ? 'bundle/worktrust.mjs' : 'worktrust.mjs')) throw Error('PACKAGE_INVALID_MANIFEST');
|
|
50
50
|
const expected = Object.keys(m.files).sort();
|
|
51
51
|
for (const name of expected) {
|
|
52
52
|
if (!safe(name) || name === signatureName || !/^[a-f0-9]{64}$/.test(m.files[name])) throw Error('PACKAGE_INVALID_MANIFEST');
|
|
@@ -55,9 +55,9 @@ function verifyPackage(root, kind = 'npm') {
|
|
|
55
55
|
const file = join(root, name);
|
|
56
56
|
if (regular(file).size > 128 * 1024 * 1024 || hash(readFileSync(file)) !== m.files[name]) throw Error('PACKAGE_FILE_CHANGED');
|
|
57
57
|
}
|
|
58
|
-
const found = filesIn(root).filter(name => name !== signatureName && (kind !== 'engine' || name.endsWith('.mjs'))).sort();
|
|
58
|
+
const found = filesIn(root).filter(name => (kind !== 'python' || !name.split('/').includes('__pycache__')) && name !== signatureName && (kind !== 'engine' || name.endsWith('.mjs'))).sort();
|
|
59
59
|
if (JSON.stringify(found) !== JSON.stringify(expected)) throw Error('PACKAGE_FILE_LIST_CHANGED');
|
|
60
|
-
if (/const CLI_VERSION = "([^"]+)";/.exec(readFileSync(join(root, 'worktrust.mjs'), 'utf8'))?.[1] !== m.version) throw Error('PACKAGE_VERSION_MISMATCH');
|
|
60
|
+
if (/const CLI_VERSION = "([^"]+)";/.exec(readFileSync(join(root, kind === 'python' ? 'bundle/worktrust.mjs' : 'worktrust.mjs'), 'utf8'))?.[1] !== m.version) throw Error('PACKAGE_VERSION_MISMATCH');
|
|
61
61
|
return { manifest: m, identity: hash(readFileSync(path)), signatureName };
|
|
62
62
|
}
|
|
63
63
|
function installSignedPackage(source, home) {
|
|
@@ -83,12 +83,94 @@ function installSignedPackage(source, home) {
|
|
|
83
83
|
return join(target, 'worktrust-launch.mjs');
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** Child processes of the official launcher re-enter verification, including long-lived MCP bridges.
|
|
87
|
+
* Raw source test harnesses retain direct entry; they are not authenticated release launches.
|
|
88
|
+
*/
|
|
89
|
+
function persistentPython(root) {
|
|
90
|
+
return globalThis[Symbol.for("worktrust.verifiedReleaseRoot")] === root
|
|
91
|
+
&& basename(root) === "engine" && /^[a-f0-9]{64}$/.test(basename(dirname(root)))
|
|
92
|
+
&& basename(dirname(dirname(root))) === "installations"
|
|
93
|
+
&& typeof process.env.WORKTRUST_BUNDLED_PYTHON === "string" && isAbsolute(process.env.WORKTRUST_BUNDLED_PYTHON)
|
|
94
|
+
&& process.env.WORKTRUST_INSTALLED_LAUNCHER === join(dirname(root), "worktrust-launch.py")
|
|
95
|
+
&& process.env.WORKTRUST_BUNDLED_PYTHON;
|
|
96
|
+
}
|
|
97
|
+
function moduleExecutable(root) { return persistentPython(root) || process.execPath; }
|
|
98
|
+
function moduleArgs(root, name, args = []) {
|
|
99
|
+
if (!["worktrust.mjs", "setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "preserve.mjs"].includes(name)) throw Error("PACKAGE_INVALID_ENTRY");
|
|
100
|
+
if (persistentPython(root)) return ["-I", process.env.WORKTRUST_INSTALLED_LAUNCHER, "--internal-module", name, ...args];
|
|
101
|
+
const flags = process.versions.node === "26.5.0" ? ["--no-concurrent-sparkplug"] : [];
|
|
102
|
+
return globalThis[Symbol.for("worktrust.verifiedReleaseRoot")] === root
|
|
103
|
+
? [...flags, join(root, "worktrust-launch.mjs"), "--internal-module", name, ...args]
|
|
104
|
+
: [...flags, join(root, name), ...args];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Credentials stay outside the immutable release. File hygiene reduces cross-user theft;
|
|
108
|
+
// it does not attest the machine owner or the truth of data they choose to sign.
|
|
109
|
+
function privateDirectory(path, create) {
|
|
110
|
+
if (create) mkdirSync(path, { recursive: true, mode: 0o700 });
|
|
111
|
+
const before = lstatSync(path);
|
|
112
|
+
if (!before.isDirectory() || before.isSymbolicLink() || (process.getuid && before.uid !== process.getuid())) throw Error('KEY_FILE_UNSAFE');
|
|
113
|
+
// Windows ACLs remain the responsibility of the user's private profile directory.
|
|
114
|
+
if (process.platform !== 'win32') {
|
|
115
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
116
|
+
try { const current = fstatSync(fd); if (current.ino !== before.ino || current.dev !== before.dev) throw Error('KEY_FILE_UNSAFE'); fchmodSync(fd, 0o700); }
|
|
117
|
+
finally { closeSync(fd); }
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function privateStat(stat) {
|
|
121
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.size > 65536 || (process.getuid && stat.uid !== process.getuid())) throw Error('KEY_FILE_UNSAFE');
|
|
122
|
+
}
|
|
123
|
+
/** Bounded descriptor read; never follow a linked credential, pipe, device or directory. */
|
|
124
|
+
function readPrivateFile(file) {
|
|
125
|
+
let fd;
|
|
126
|
+
try {
|
|
127
|
+
privateDirectory(dirname(file), false);
|
|
128
|
+
const before = lstatSync(file); privateStat(before);
|
|
129
|
+
fd = openSync(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
130
|
+
const current = fstatSync(fd); privateStat(current);
|
|
131
|
+
if (current.ino !== before.ino || current.dev !== before.dev) throw Error('KEY_FILE_UNSAFE');
|
|
132
|
+
if (process.platform !== 'win32') fchmodSync(fd, 0o600);
|
|
133
|
+
const bytes = Buffer.alloc(65537); let size = 0, next;
|
|
134
|
+
while (size < bytes.length && (next = readSync(fd, bytes, size, bytes.length - size, null)) > 0) size += next;
|
|
135
|
+
if (size > 65536) throw Error('KEY_FILE_UNSAFE');
|
|
136
|
+
return bytes.subarray(0, size).toString('utf8');
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (error.code === 'ENOENT') return null;
|
|
139
|
+
throw Error('KEY_FILE_UNSAFE');
|
|
140
|
+
} finally { if (fd !== undefined) closeSync(fd); }
|
|
141
|
+
}
|
|
142
|
+
/** Exclusive random temp, flush, atomic replace. Existing credentials survive a failed write. */
|
|
143
|
+
function writePrivateFile(file, bytes) {
|
|
144
|
+
if (Buffer.byteLength(bytes) > 65536) throw Error('KEY_FILE_UNSAFE');
|
|
145
|
+
privateDirectory(dirname(file), true);
|
|
146
|
+
try { privateStat(lstatSync(file)); } catch (error) { if (error.code !== 'ENOENT') throw Error('KEY_FILE_UNSAFE'); }
|
|
147
|
+
const temporary = file + '.' + randomBytes(16).toString('hex') + '.tmp'; let fd;
|
|
148
|
+
try {
|
|
149
|
+
fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
|
|
150
|
+
writeFileSync(fd, bytes); fsyncSync(fd); closeSync(fd); fd = undefined;
|
|
151
|
+
renameSync(temporary, file);
|
|
152
|
+
} finally { if (fd !== undefined) closeSync(fd); rmSync(temporary, { force: true }); }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** First creation only, used by offline archive secrets; never overwrite an existing key. */
|
|
156
|
+
function createPrivateFile(file, bytes) {
|
|
157
|
+
if (Buffer.byteLength(bytes) > 65536) throw Error('KEY_FILE_UNSAFE');
|
|
158
|
+
privateDirectory(dirname(file), true);
|
|
159
|
+
const fd = openSync(file, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
|
|
160
|
+
try { writeFileSync(fd, bytes); fsyncSync(fd); } finally { closeSync(fd); }
|
|
161
|
+
}
|
|
162
|
+
|
|
86
163
|
import { fileURLToPath } from 'node:url';
|
|
87
164
|
const root = dirname(fileURLToPath(import.meta.url));
|
|
88
165
|
try {
|
|
89
166
|
verifyPackage(root, existsSync(join(root, 'package.json')) ? 'npm' : 'engine');
|
|
90
|
-
|
|
91
|
-
|
|
167
|
+
Object.defineProperty(globalThis, Symbol.for('worktrust.verifiedReleaseRoot'), { value: root });
|
|
168
|
+
const internal = process.argv[2] === '--internal-module';
|
|
169
|
+
const entry = internal ? process.argv[3] : 'worktrust.mjs';
|
|
170
|
+
if (!['worktrust.mjs', 'setup-mcp.mjs', 'log-session.mjs', 'count-behaviour.mjs', 'preserve.mjs'].includes(entry)) throw Error('PACKAGE_INVALID_ENTRY');
|
|
171
|
+
if (internal) process.argv.splice(2, 2);
|
|
172
|
+
process.argv[1] = join(root, entry);
|
|
173
|
+
await import('./' + entry);
|
|
92
174
|
} catch (error) {
|
|
93
175
|
const category = /^PACKAGE_[A-Z_]+$/.test(error.message) ? error.message : 'PACKAGE_VERIFICATION_FAILED';
|
|
94
176
|
process.stderr.write(`worktrust: ${category}. Execution stopped; reinstall an official WorkTrust release.\n`);
|
package/worktrust.mjs
CHANGED
|
@@ -32,24 +32,19 @@
|
|
|
32
32
|
* WHAT RUNS. From the npm package, everything that runs is in the package: this file,
|
|
33
33
|
* `setup-mcp.mjs` (gives every AI app here the WorkTrust door), `log-session.mjs` (the session hook)
|
|
34
34
|
* and `count-behaviour.mjs` (the local counter, pinned: never replaced from the network), with
|
|
35
|
-
* `transcript-readers.mjs` (how Codex and Antigravity logs are read, imported by the last two).
|
|
36
|
-
* is downloaded. Run as a single file from WorkTrust's site instead, it fetches those from that
|
|
37
|
-
* same site, and says so before it asks.
|
|
35
|
+
* `transcript-readers.mjs` (how Codex and Antigravity logs are read, imported by the last two). Individual support scripts are never downloaded or executed outside the complete release.
|
|
38
36
|
* HOW THE ACCOUNT IS DECIDED. By default this terminal listens on 127.0.0.1 for one answer and holds
|
|
39
37
|
* a PKCE secret. Your browser opens WorkTrust, you approve this computer there (signed in, second
|
|
40
38
|
* factor), and the browser is sent back to 127.0.0.1 with a one-time code that only this terminal,
|
|
41
39
|
* with its secret, can exchange for the key. Nothing is typed, and a link forwarded to someone else
|
|
42
40
|
* approves nothing they can collect. Without a browser (`--device`, or over SSH) the terminal shows
|
|
43
41
|
* a code that you type yourself at app.worktrust.io/connect/computer.
|
|
44
|
-
* WHERE THE KEY LIVES.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* WorkTrust, the private half stays in the key file. Every call the bridge, the hook and
|
|
51
|
-
* the counter make carries a fresh signature (`WorkTrust-Proof`), and WorkTrust refuses a call
|
|
52
|
-
* through this key without one: a copied key alone is worth nothing.
|
|
42
|
+
* WHERE THE KEY LIVES. A private local file until the person runs protect-key; then an encrypted
|
|
43
|
+
* envelope in that file, with its wrapping key in the OS vault. AI apps run the bridge and never
|
|
44
|
+
* receive these credentials in their settings. Protected mode refuses --direct.
|
|
45
|
+
* SIGNATURES PROVE POSSESSION. connect makes an Ed25519 pair and registers the public half.
|
|
46
|
+
* Requests carry fresh signatures and single-use nonces. Software authorized as the same OS user
|
|
47
|
+
* may still use the private key; neither file encryption nor signatures prove truthful activity.
|
|
53
48
|
*
|
|
54
49
|
* THE KEY RENEWS ITSELF EVERY WEEK. The bridge or the hook makes a new secret on this computer, sends
|
|
55
50
|
* only its hash, signed with the current key, and stores the new one; a copy of last week's key stops
|
|
@@ -67,23 +62,25 @@ import { createHash, createPublicKey, generateKeyPairSync, randomBytes, sign } f
|
|
|
67
62
|
import { createServer } from "node:http";
|
|
68
63
|
import { chmodSync, closeSync, copyFileSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
69
64
|
import { homedir, hostname, platform } from "node:os";
|
|
70
|
-
import { dirname, join } from "node:path";
|
|
65
|
+
import { dirname, join, basename } from "node:path";
|
|
71
66
|
import { createInterface } from "node:readline/promises";
|
|
72
67
|
import { createInterface as lines } from "node:readline";
|
|
73
68
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
74
69
|
|
|
70
|
+
const { moduleArgs, moduleExecutable, readPrivateFile, writePrivateFile } = await import("./package-integrity.mjs").catch(() => ({}));
|
|
71
|
+
|
|
75
72
|
const args = process.argv.slice(2);
|
|
76
73
|
const VALUED = ["--name", "--origin", "--url", "--export", "--from-folder"];
|
|
77
74
|
const command = args.includes("--help") ? "help" : args.includes("--version") ? "version" : args.find((arg, at) => !arg.startsWith("--") && !(at > 0 && VALUED.includes(args[at - 1]))) ?? "default";
|
|
78
75
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
79
76
|
const has = (name) => args.includes(`--${name}`);
|
|
80
77
|
/** 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.10.
|
|
78
|
+
const CLI_VERSION = "0.10.26";
|
|
82
79
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
83
80
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
84
81
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
85
82
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
86
|
-
const SCRIPTS = ["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", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs"];
|
|
83
|
+
const SCRIPTS = ["credential-store.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", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs"];
|
|
87
84
|
/** The modules the scripts import by name from beside them; a download keeps that name. */
|
|
88
85
|
const IMPORTED = new Set(["transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs"]);
|
|
89
86
|
const downloaded = (name) => (IMPORTED.has(name) ? name : `${name}.download.mjs`);
|
|
@@ -125,7 +122,7 @@ async function post(path, body) {
|
|
|
125
122
|
return { status: response.status, json: await response.json().catch(() => ({})) };
|
|
126
123
|
}
|
|
127
124
|
|
|
128
|
-
/**
|
|
125
|
+
/** Every helper belongs to this complete release. No loose-file download fallback. */
|
|
129
126
|
async function scripts() {
|
|
130
127
|
if (BUNDLED) return Object.fromEntries(SCRIPTS.map((name) => [name, join(HERE, name)]));
|
|
131
128
|
fail("Use the complete official npm/Python package or preservation kit. Individual scripts are not downloaded or executed without release verification.");
|
|
@@ -142,7 +139,7 @@ function historyQueueScope(token) {
|
|
|
142
139
|
/** Run a script; its output is shown, or collected for the plan. The key travels in the environment only. */
|
|
143
140
|
function run(path, scriptArgs, token, collect = false, extraEnv = {}) {
|
|
144
141
|
return new Promise((resolve) => {
|
|
145
|
-
const child = spawn(
|
|
142
|
+
const child = spawn(moduleExecutable(HERE), [...moduleArgs(HERE, basename(path), scriptArgs)], { stdio: collect ? ["ignore", "pipe", "pipe"] : "inherit", env: { ...process.env, WORKTRUST_MCP_URL: MCP, WORKTRUST_MCP_TOKEN: token, WORKTRUST_NODE: NODE, WORKTRUST_NODE_ARGS: JSON.stringify(NODE_ARGS), WORKTRUST_CLI_VERSION: CLI_VERSION, WORKTRUST_HISTORY_SCOPE: historyQueueScope(token), ...extraEnv } });
|
|
146
143
|
let out = "";
|
|
147
144
|
child.stdout?.on("data", (chunk) => { out += chunk; });
|
|
148
145
|
child.stderr?.on("data", (chunk) => { out += chunk; });
|
|
@@ -272,14 +269,18 @@ async function pairByCode(host, extra) {
|
|
|
272
269
|
let NODE = process.env.WORKTRUST_BUNDLED_RUNTIME_DIR ? process.execPath : (process.env.PATH ?? "").split(OS === "windows" ? ";" : ":").map((dir) => join(dir, OS === "windows" ? "node.exe" : "node")).find((path) => existsSync(path)) ?? process.execPath;
|
|
273
270
|
const KEY_FILE = join(HOME_DIR, "key.json");
|
|
274
271
|
const STABLE_FILE = join(HOME_DIR, "worktrust.mjs");
|
|
275
|
-
let STABLE =
|
|
272
|
+
let STABLE = join(HERE, "worktrust-launch.mjs"), runtimePrepared = false, NODE_ARGS = [];
|
|
276
273
|
const RENEW_EVERY_MS = 7 * 24 * 3600_000;
|
|
277
|
-
const KEY_PLACE = "~/.worktrust/key.json (
|
|
274
|
+
const KEY_PLACE = "~/.worktrust/key.json (storage protection is shown by worktrust status)";
|
|
278
275
|
const ensureHome = () => { mkdirSync(HOME_DIR, { recursive: true, mode: 0o700 }); try { chmodSync(HOME_DIR, 0o700); } catch { /* Windows */ } };
|
|
279
276
|
|
|
280
277
|
/** A tool-runner cache is disposable. Install the whole verified runtime/engine before changing wiring. */
|
|
281
278
|
async function prepareBundledRuntime() {
|
|
282
279
|
if (runtimePrepared) return;
|
|
280
|
+
const installedLauncher = join(dirname(HERE), "worktrust-launch.py");
|
|
281
|
+
if (moduleExecutable(HERE) !== process.execPath) {
|
|
282
|
+
NODE = process.env.WORKTRUST_BUNDLED_PYTHON; NODE_ARGS = ["-I"]; STABLE = installedLauncher; runtimePrepared = true; return;
|
|
283
|
+
}
|
|
283
284
|
if (!process.env.WORKTRUST_BUNDLED_RUNTIME_DIR) {
|
|
284
285
|
if (existsSync(join(HERE, "package-release.json"))) {
|
|
285
286
|
if (existsSync(HOME_DIR) && (!lstatSync(HOME_DIR).isDirectory() || lstatSync(HOME_DIR).isSymbolicLink())) fail("the WorkTrust directory must be a directory, not a symlink.");
|
|
@@ -291,35 +292,30 @@ async function prepareBundledRuntime() {
|
|
|
291
292
|
if (existsSync(HOME_DIR) && (!lstatSync(HOME_DIR).isDirectory() || lstatSync(HOME_DIR).isSymbolicLink())) fail("the WorkTrust directory must be a directory, not a symlink.");
|
|
292
293
|
ensureHome();
|
|
293
294
|
const installed = installRuntime(process.env.WORKTRUST_BUNDLED_RUNTIME_DIR, HERE, HOME_DIR, ["worktrust.mjs", ...SCRIPTS, "preserve.mjs", "preserve-lines.mjs", "preserve-summary.mjs"]);
|
|
294
|
-
NODE = installed.executable; STABLE = installed.bridge; runtimePrepared = true;
|
|
295
|
+
NODE = installed.executable; NODE_ARGS = installed.args; STABLE = installed.bridge; runtimePrepared = true;
|
|
295
296
|
}
|
|
296
297
|
function saveStableEntry() {
|
|
297
|
-
const temporary = `${
|
|
298
|
-
try { writeFileSync(temporary,
|
|
298
|
+
const target = join(HOME_DIR, "installed-release.json"), temporary = `${target}.${randomBytes(8).toString("hex")}.tmp`;
|
|
299
|
+
try { writeFileSync(temporary, JSON.stringify({ version: CLI_VERSION }), { flag: "wx", mode: 0o600 }); renameSync(temporary, target); }
|
|
299
300
|
finally { try { rmSync(temporary); } catch { /* already renamed */ } }
|
|
300
301
|
}
|
|
301
302
|
|
|
302
|
-
/**
|
|
303
|
-
*
|
|
304
|
-
* private key and when it was last renewed. NO KEYCHAIN (owner, 2026-10-03): a keychain tool can ask
|
|
305
|
-
* the person to "reset" a keychain it cannot find, which deletes every password on the machine, and
|
|
306
|
-
* many will not let a tool near their keychain at all. This file is never written into an AI app's
|
|
307
|
-
* settings: the apps run the bridge, which reads it.
|
|
303
|
+
/** Existing file credentials remain readable until the person explicitly protects them.
|
|
304
|
+
* The OS wrapping key is never written into an AI app or the encrypted credential file.
|
|
308
305
|
*/
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
};
|
|
306
|
+
const { createCredentialStore } = await import("./credential-store.mjs").catch(() => ({}));
|
|
307
|
+
const keyStore = createCredentialStore?.(KEY_FILE);
|
|
308
|
+
async function protectKey() {
|
|
309
|
+
say(" Protect the WorkTrust token and signing key with this OS account's credential vault.");
|
|
310
|
+
say(" Quit AI apps first; restart them after this finishes. Older bridges cannot read protected credentials.");
|
|
311
|
+
say(" This protects stored secrets. It does not prove that local activity is genuine.");
|
|
312
|
+
if (has("dry-run")) { say(" Dry run: no vault or credential was changed."); return; }
|
|
313
|
+
if (keyStore.load() && stableVersion() !== CLI_VERSION) fail("Run worktrust update from this release first, then quit your AI apps and run worktrust protect-key.");
|
|
314
|
+
if (!(await ask("Protect the local credentials?"))) return;
|
|
315
|
+
try { keyStore.protect(); }
|
|
316
|
+
catch { fail("OS credential storage was unavailable or the credential file could not be safely replaced. Existing credentials were preserved. Unlock your OS vault, check worktrust status, and retry. No keychain reset is needed."); }
|
|
317
|
+
say(" Credentials are protected by the OS vault. Restart your AI apps. No account data or Passport was changed.");
|
|
318
|
+
}
|
|
323
319
|
|
|
324
320
|
/**
|
|
325
321
|
* WHICH ACCOUNT THIS COMPUTER LAST FED, after `disconnect` (owner, 2026-10-04). The key file goes; this
|
|
@@ -467,7 +463,7 @@ function sweepAtMostHourly() {
|
|
|
467
463
|
const stamp = join(HOME_DIR, "bridge-swept-at");
|
|
468
464
|
try { if (Date.now() - Number(readFileSync(stamp, "utf8")) < 3_600_000) return; } catch { /* never swept here */ }
|
|
469
465
|
try { mkdirSync(HOME_DIR, { recursive: true }); writeFileSync(stamp, String(Date.now())); } catch { return; }
|
|
470
|
-
try { spawn(
|
|
466
|
+
try { spawn(moduleExecutable(HERE), [...moduleArgs(HERE, "worktrust.mjs", ["hook"])], { detached: true, stdio: "ignore" }).unref(); } catch { /* the next start sweeps */ }
|
|
471
467
|
}
|
|
472
468
|
|
|
473
469
|
async function bridge() {
|
|
@@ -481,6 +477,9 @@ async function bridge() {
|
|
|
481
477
|
let message;
|
|
482
478
|
try { message = JSON.parse(line); } catch { continue; }
|
|
483
479
|
if (message.method === "initialize" && message.params?.clientInfo?.name) agent = `${message.params.clientInfo.name}/${message.params.clientInfo.version ?? "0"} (worktrust-bridge) worktrust-cli/${CLI_VERSION}`;
|
|
480
|
+
// A long-lived bridge must not keep using a cached key after local disconnect or vault lock.
|
|
481
|
+
try { key = await freshKey(); }
|
|
482
|
+
catch { key = null; if (message.id !== undefined) answer(message.id, "WorkTrust credential storage is unavailable. Unlock your OS vault and retry; no request was sent."); continue; }
|
|
484
483
|
if (!key) { if (message.id !== undefined) answer(message.id, "WorkTrust is not connected on this computer: run `npx worktrust connect`."); continue; }
|
|
485
484
|
try {
|
|
486
485
|
const response = await fetch(key.url, { method: "POST", headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${key.token}`, "user-agent": agent, ...(session ? { "mcp-session-id": session } : {}), ...proof(key.device, key.url, line) }, body: line });
|
|
@@ -510,7 +509,7 @@ async function hook() {
|
|
|
510
509
|
if (has("hermes") || has("goose")) return sessionEnd();
|
|
511
510
|
const key = await freshKey();
|
|
512
511
|
if (!key) return;
|
|
513
|
-
const child = spawn(
|
|
512
|
+
const child = spawn(moduleExecutable(HERE), [...moduleArgs(HERE, "log-session.mjs", args.filter((arg) => arg !== "hook"))], { stdio: "inherit", env: { ...process.env, WORKTRUST_MCP_URL: key.url, WORKTRUST_MCP_TOKEN: key.token, WORKTRUST_CLI_VERSION: CLI_VERSION, WORKTRUST_HISTORY_SCOPE: historyQueueScope(key.token), ...(key.device ? { WORKTRUST_DEVICE_KEY: key.device } : {}) } }); // 0.10.20: the hook names the version that started it, beside each line
|
|
514
513
|
process.exitCode = await new Promise((resolve, reject) => { child.on("error", reject); child.on("close", (code) => resolve(code ?? 1)); });
|
|
515
514
|
}
|
|
516
515
|
|
|
@@ -533,7 +532,7 @@ async function antigravityStop() {
|
|
|
533
532
|
process.stdin.on("end", () => { clearTimeout(timer); resolve(text); });
|
|
534
533
|
process.stdin.on("error", () => { clearTimeout(timer); resolve(text); });
|
|
535
534
|
});
|
|
536
|
-
try { spawn(
|
|
535
|
+
try { spawn(moduleExecutable(HERE), [...moduleArgs(HERE, "worktrust.mjs", ["hook", "--antigravity"])], { detached: true, stdio: "ignore", env: { ...process.env, WORKTRUST_HOOK_INPUT: input.slice(0, 65536) } }).unref(); } catch { /* the next run sweeps it */ }
|
|
537
536
|
process.stdin.pause(); return;
|
|
538
537
|
}
|
|
539
538
|
|
|
@@ -547,7 +546,7 @@ async function antigravityStop() {
|
|
|
547
546
|
async function sessionEnd() {
|
|
548
547
|
writeSync(1, "{}\n");
|
|
549
548
|
if (!process.stdin.isTTY) await new Promise((resolve) => { const timer = setTimeout(resolve, 2000); process.stdin.on("data", () => {}); process.stdin.on("end", () => { clearTimeout(timer); resolve(); }); process.stdin.on("error", () => { clearTimeout(timer); resolve(); }); });
|
|
550
|
-
try { spawn(
|
|
549
|
+
try { spawn(moduleExecutable(HERE), [...moduleArgs(HERE, "worktrust.mjs", ["hook"])], { detached: true, stdio: "ignore" }).unref(); } catch { /* the next run sweeps it */ }
|
|
551
550
|
process.stdin.pause(); return;
|
|
552
551
|
}
|
|
553
552
|
|
|
@@ -583,7 +582,7 @@ async function update() {
|
|
|
583
582
|
// Out first, then in: an app that held a key of its own (a hand-made entry) moves onto the bridge.
|
|
584
583
|
await run(paths["setup-mcp.mjs"], ["--remove", "--write"], key.token, true);
|
|
585
584
|
if ((await run(paths["setup-mcp.mjs"], ["--write", "--bridge", STABLE], key.token)).code !== 0) fail("coupling the AI apps failed; the output above says where.");
|
|
586
|
-
const hookArgs = ["--install",
|
|
585
|
+
const hookArgs = ["--install", "--via", STABLE];
|
|
587
586
|
if ((await run(paths["log-session.mjs"], hookArgs, key.token, false)).code !== 0) fail("installing the session hook failed; the output above says where.");
|
|
588
587
|
// Codex installed since, or a No said at connect: the one question, asked again (or "already set").
|
|
589
588
|
await offerCodex();
|
|
@@ -596,6 +595,7 @@ async function update() {
|
|
|
596
595
|
}
|
|
597
596
|
|
|
598
597
|
async function connect() {
|
|
598
|
+
if (has("direct") && keyStore.protected()) fail("Protected credentials use the local bridge; --direct would expose them in app settings.");
|
|
599
599
|
const host = (flag("name") ?? hostname()).replace(/\.local$/i, "").slice(0, 64);
|
|
600
600
|
say();
|
|
601
601
|
say(` WorkTrust · connect ${host} (${OS_NAME})`);
|
|
@@ -611,7 +611,6 @@ async function connect() {
|
|
|
611
611
|
if (!has("replace") && !(await ask("Couple it again?", false))) { say(" Stopped. Nothing was changed: this computer stays coupled as it is."); return; }
|
|
612
612
|
say();
|
|
613
613
|
}
|
|
614
|
-
if (!BUNDLED) say(` The three scripts that do the work are downloaded from ${ORIGIN} first. From npm they come in the package.\n`);
|
|
615
614
|
const paths = await scripts();
|
|
616
615
|
const direct = has("direct");
|
|
617
616
|
const plan = await run(paths["setup-mcp.mjs"], direct ? [] : ["--bridge", STABLE], PLACEHOLDER, true);
|
|
@@ -623,7 +622,7 @@ async function connect() {
|
|
|
623
622
|
if (foundApps.length === 0) say(" (no AI app found here yet; run connect again after installing one)");
|
|
624
623
|
if (!direct) say(` 3. The key is kept in ${KEY_PLACE}, works only on this computer (every call is signed) and is renewed every week.`);
|
|
625
624
|
say(` ${direct ? 3 : 4}. The session hook is installed:`);
|
|
626
|
-
say(
|
|
625
|
+
say(" + The hook and counter from the checked release, retained outside the package-manager cache");
|
|
627
626
|
say(` + ${join(homedir(), ".claude", "settings.json")} → SessionStart, SessionEnd and PreCompact run it`);
|
|
628
627
|
say();
|
|
629
628
|
say(" Sent to WorkTrust afterwards: durations, token counts, model names, a layer keyword, counts,");
|
|
@@ -661,7 +660,7 @@ async function connect() {
|
|
|
661
660
|
// A NEW COUPLING SENDS NOTHING FROM BEFORE IT (log-session THE FLOORS): `--from-now` for a first coupling and a change
|
|
662
661
|
// of account; the same account coupled again keeps its watermarks. A change of account also closes the history offer.
|
|
663
662
|
const floors = !previous || switched ? ["--from-now", ...(switched ? ["--history-floor", "now"] : [])] : [];
|
|
664
|
-
const hookArgs = ["--install", ...floors,
|
|
663
|
+
const hookArgs = ["--install", ...floors, "--via", STABLE, ...(direct ? ["--direct"] : [])];
|
|
665
664
|
if ((await run(paths["log-session.mjs"], hookArgs, token, false, { WORKTRUST_CODEX_OFFER: "1" })).code !== 0) fail("installing the session hook failed; the output above says where.");
|
|
666
665
|
await offerCodex();
|
|
667
666
|
await offerAntigravity();
|
|
@@ -720,7 +719,7 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
|
|
|
720
719
|
}
|
|
721
720
|
|
|
722
721
|
/** The version stamped in the stable copy in ~/.worktrust, the CLI this computer ran before an update; null without one. */
|
|
723
|
-
const stableVersion = () => { try { return /const CLI_VERSION = "([^"]+)";/.exec(readFileSync(STABLE_FILE, "utf8"))?.[1] ?? null; } catch { return null; } };
|
|
722
|
+
const stableVersion = () => { try { const installed = JSON.parse(readFileSync(join(HOME_DIR, "installed-release.json"), "utf8")); if (/^\d+\.\d+\.\d+$/.test(installed.version)) return installed.version; } catch { /* older registration */ } try { return /const CLI_VERSION = "([^"]+)";/.exec(readFileSync(STABLE_FILE, "utf8"))?.[1] ?? null; } catch { return null; } };
|
|
724
723
|
|
|
725
724
|
/**
|
|
726
725
|
* OFFERED ONCE, BY `update`, IN PLAIN WORDS (owner, 2026-10-07): when the computer's earlier lines were made by an earlier CLI
|
|
@@ -937,9 +936,9 @@ function writeCodex(rows) {
|
|
|
937
936
|
async function offerCodex() {
|
|
938
937
|
if (!existsSync(join(homedir(), ".codex"))) { if (command === "codex") say(" Codex is not on this computer (no ~/.codex)."); return; }
|
|
939
938
|
const viaBridge = existsSync(STABLE);
|
|
940
|
-
const hookFile =
|
|
939
|
+
const hookFile = STABLE;
|
|
941
940
|
if (!existsSync(hookFile)) { say(" Couple this computer first: npx worktrust"); return; }
|
|
942
|
-
const desired = () => `notify = [${(viaBridge ? [NODE, STABLE, "hook", "--codex-notify"] : [NODE, hookFile, "--codex-notify"]).map((part) => JSON.stringify(part)).join(", ")}]`;
|
|
941
|
+
const desired = () => `notify = [${(viaBridge ? [NODE, ...NODE_ARGS, STABLE, "hook", "--codex-notify"] : [NODE, ...NODE_ARGS, hookFile, "--codex-notify"]).map((part) => JSON.stringify(part)).join(", ")}]`;
|
|
943
942
|
let want = desired();
|
|
944
943
|
const found = codexNotify();
|
|
945
944
|
say();
|
|
@@ -986,7 +985,7 @@ function writeAgyHooks(hooks) {
|
|
|
986
985
|
async function offerAntigravity() {
|
|
987
986
|
if (!antigravityHere()) { if (command === "antigravity") say(" Antigravity is not on this computer (no ~/.gemini/config or ~/.gemini/antigravity*)."); return; }
|
|
988
987
|
if (!existsSync(STABLE)) { say(" Couple this computer first: npx worktrust"); return; }
|
|
989
|
-
const desired = () => ({ enabled: true, Stop: [{ type: "command", command: `"${NODE}" "${STABLE}" hook --antigravity-stop`, timeout: 10 }] });
|
|
988
|
+
const desired = () => ({ enabled: true, Stop: [{ type: "command", command: `"${NODE}" ${NODE_ARGS.map(arg => JSON.stringify(arg)).join(" ")}${NODE_ARGS.length ? " " : ""}"${STABLE}" hook --antigravity-stop`, timeout: 10 }] });
|
|
990
989
|
let want = desired();
|
|
991
990
|
const hooks = agyHooks();
|
|
992
991
|
say();
|
|
@@ -1027,7 +1026,7 @@ async function disconnect() {
|
|
|
1027
1026
|
const plan = await run(paths["setup-mcp.mjs"], ["--remove"], PLACEHOLDER, true);
|
|
1028
1027
|
say(" 1. The WorkTrust door comes out of every AI app here:");
|
|
1029
1028
|
for (const line of planLines(plan.out)) say(line);
|
|
1030
|
-
say(" 2. The session hook comes out of ~/.claude/settings.json (and Codex's notify line and Antigravity's worktrust hook, when WorkTrust set them),
|
|
1029
|
+
say(" 2. The session hook comes out of ~/.claude/settings.json (and Codex's notify line and Antigravity's worktrust hook, when WorkTrust set them), credentials are removed (an encrypted empty slot keeps the OS-vault preference)");
|
|
1031
1030
|
say(" but for one note of which account this computer fed (masked), so a later coupling by another account starts clean.");
|
|
1032
1031
|
say(" 3. The key itself stays valid until you revoke it: WorkTrust → Sources → Devices → this computer → Revoke.");
|
|
1033
1032
|
say();
|
|
@@ -1042,7 +1041,7 @@ async function disconnect() {
|
|
|
1042
1041
|
previousNote.save(keyStore.load());
|
|
1043
1042
|
keyStore.erase();
|
|
1044
1043
|
// Everything of ours on this computer goes; the folder too, when nothing else is left in it.
|
|
1045
|
-
for (const name of [
|
|
1044
|
+
for (const name of [STABLE_FILE, ...SCRIPTS.map((script) => join(HOME_DIR, downloaded(script))), join(HOME_DIR, "pinned")]) { try { rmSync(name); } catch { /* gone */ } }
|
|
1046
1045
|
try { rmSync(HOME_DIR, { recursive: false }); } catch { /* not empty, or gone */ }
|
|
1047
1046
|
say();
|
|
1048
1047
|
say(" Done. Revoke the key in WorkTrust to finish.");
|
|
@@ -1099,15 +1098,16 @@ async function status() {
|
|
|
1099
1098
|
const door = Object.entries(servers).find(([name, server]) => /worktrust/i.test(`${name} ${server?.url ?? ""} ${(server?.args ?? []).join(" ")}`));
|
|
1100
1099
|
say(door ? ` Claude Code: coupled (${door[1].url ?? "through the local bridge"})` : " Claude Code: not coupled. Run `npx worktrust connect`.");
|
|
1101
1100
|
const key = keyStore.load();
|
|
1101
|
+
say(` Credential storage: ${keyStore.protected() ? "OS vault + encrypted local file" : "private local file; use worktrust protect-key after updating"}`);
|
|
1102
1102
|
say(key ? ` Key: in ${KEY_PLACE}, ${key.device ? "bound to this computer, " : ""}last renewed ${String(key.renewedAt ?? "").slice(0, 10) || "never"}` : " Key: not on this computer (or written into the apps' settings with --direct)");
|
|
1103
1103
|
if (key) say(key.account ? ` Account: ${key.account}${key.coupledAt ? `, coupled ${String(key.coupledAt).slice(0, 10)}` : ""}` : " Account: not recorded (coupled by an older version; `npx worktrust connect` records it)");
|
|
1104
1104
|
let hook = false;
|
|
1105
|
-
try { hook = /log-session|worktrust
|
|
1105
|
+
try { hook = /log-session|worktrust(?:-launch)?\.(?:mjs|py)\\?" hook/.test(readFileSync(join(homedir(), ".claude", "settings.json"), "utf8")); } catch { /* none */ }
|
|
1106
1106
|
say(hook ? " Session hook: installed" : " Session hook: not installed");
|
|
1107
1107
|
if (existsSync(join(homedir(), ".codex"))) { const notify = codexNotify().text ?? ""; say(isOurNotify(notify) ? " Codex: wakes the session hook" : " Codex: does not wake the session hook (npx worktrust update asks)"); }
|
|
1108
|
-
if (existsSync(join(homedir(), ".hermes"))) { let text = ""; try { text = readFileSync(join(homedir(), ".hermes", "config.yaml"), "utf8"); } catch { /* none */ } say(/worktrust
|
|
1108
|
+
if (existsSync(join(homedir(), ".hermes"))) { let text = ""; try { text = readFileSync(join(homedir(), ".hermes", "config.yaml"), "utf8"); } catch { /* none */ } say(/worktrust(?:-launch)?\.(?:mjs|py)\\?" hook --hermes/.test(text) ? " Hermes Agent: wakes the session hook" : " Hermes Agent: does not wake the session hook (npx worktrust update writes it)"); }
|
|
1109
1109
|
if (antigravityHere()) say(agyHooks()?.worktrust ? " Antigravity: wakes the session hook" : " Antigravity: does not wake the session hook (npx worktrust update asks)");
|
|
1110
|
-
say(
|
|
1110
|
+
say(" Counter: from this release, checked by the official launcher");
|
|
1111
1111
|
await measuredHere();
|
|
1112
1112
|
}
|
|
1113
1113
|
|
|
@@ -1116,7 +1116,7 @@ async function status() {
|
|
|
1116
1116
|
* with each stretch (kinds and counts, never text). Read here by the hook beside this file; nothing is sent to show it.
|
|
1117
1117
|
*/
|
|
1118
1118
|
async function measuredHere() {
|
|
1119
|
-
const hook =
|
|
1119
|
+
const hook = join(HERE, "log-session.mjs");
|
|
1120
1120
|
if (!hook) return;
|
|
1121
1121
|
// Through the CLI's one way of starting a script (never a synchronous child: check-computer-pairing), with no door to send to.
|
|
1122
1122
|
const read = await run(hook, ["--evidence-summary"], "", true, { WORKTRUST_MCP_URL: "", WORKTRUST_HOOK_INPUT: "" });
|
|
@@ -1150,7 +1150,7 @@ function claudeKeepsDays() {
|
|
|
1150
1150
|
async function preserve() {
|
|
1151
1151
|
const script = join(HERE, "preserve.mjs");
|
|
1152
1152
|
if (!existsSync(script)) fail("preserve runs from the package: npx worktrust@latest preserve");
|
|
1153
|
-
const child = spawn(
|
|
1153
|
+
const child = spawn(moduleExecutable(HERE), [...moduleArgs(HERE, "preserve.mjs", args.filter((arg) => arg !== "preserve"))], { stdio: "inherit", env: { ...process.env, WORKTRUST_COLLECTOR: `worktrust-cli/${CLI_VERSION}` } });
|
|
1154
1154
|
process.exitCode = await new Promise((resolve) => child.on("exit", (code) => resolve(code ?? 1)));
|
|
1155
1155
|
}
|
|
1156
1156
|
|
|
@@ -1183,6 +1183,7 @@ function help() {
|
|
|
1183
1183
|
say(" days this computer's own sessions lack, reconstructed, never verified hours (asks first)");
|
|
1184
1184
|
say(" worktrust disconnect take WorkTrust out of every AI app here (asks first)");
|
|
1185
1185
|
say(" worktrust status what is coupled here");
|
|
1186
|
+
say(" worktrust protect-key after update: move credential protection into the OS vault (asks first)");
|
|
1186
1187
|
say(" worktrust orchestration report --file recording.jsonl inspect local agent metadata; sends nothing");
|
|
1187
1188
|
say(" worktrust mod the WorkTrust mod for Claude Code: what it counts, and whether it is on");
|
|
1188
1189
|
say(" install turn it on: counts permission answers, effort levels, context peaks and subagents (asks first)");
|
|
@@ -1201,9 +1202,10 @@ function help() {
|
|
|
1201
1202
|
// before anything is read or written, --yes included. The hook and the MCP bridge are started by the agent's client
|
|
1202
1203
|
// itself and stay as they are; `status` only reads.
|
|
1203
1204
|
async function main() {
|
|
1205
|
+
if (!moduleArgs || !moduleExecutable || !createCredentialStore) fail("Use the complete WorkTrust package from npm/PyPI or the signed preservation kit; individual scripts cannot run.");
|
|
1204
1206
|
if (Number(process.versions.node.split(".")[0]) < 18) fail("needs Node 18 or later (fetch is built in from 18).");
|
|
1205
1207
|
const AGENT_ENV = ["CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "CODEX_SANDBOX", "CODEX_CI", "GEMINI_CLI", "CURSOR_AGENT", "OPENCODE", "CLINE_ACTIVE", "AIDER_CHAT", "ANTIGRAVITY_AGENT", "WINDSURF_AGENT"];
|
|
1206
|
-
const PERSON_ONLY = new Set(["default", "connect", "update", "history", "disconnect", "preserve", "codex", "antigravity", "sources", "web", "import", "orchestration", "mod"]);
|
|
1208
|
+
const PERSON_ONLY = new Set(["default", "connect", "update", "history", "disconnect", "preserve", "codex", "antigravity", "sources", "web", "import", "orchestration", "mod", "protect-key"]);
|
|
1207
1209
|
const agentShell = AGENT_ENV.find((name) => process.env[name] && process.env[name] !== "0");
|
|
1208
1210
|
if (agentShell && PERSON_ONLY.has(command)) {
|
|
1209
1211
|
say();
|
|
@@ -1235,12 +1237,17 @@ async function relayToNewest() {
|
|
|
1235
1237
|
}
|
|
1236
1238
|
if (await relayToNewest()) return;
|
|
1237
1239
|
|
|
1240
|
+
if (!["version", "help", "preserve"].includes(command)) {
|
|
1241
|
+
try { keyStore.load(); }
|
|
1242
|
+
catch { fail("The local WorkTrust key file is unsafe or damaged, or the OS vault is locked or unavailable. Upload stopped. Unlock your OS vault and retry. Do not delete the key file or reset the keychain."); }
|
|
1243
|
+
}
|
|
1238
1244
|
if (command === "version") say(CLI_VERSION);
|
|
1239
1245
|
else if (command === "default") { if (keyStore.load()) await again(); else await connect(); }
|
|
1240
1246
|
else if (command === "mcp") await bridge();
|
|
1241
1247
|
else if (command === "hook") await hook();
|
|
1242
1248
|
else if (command === "connect") await connect();
|
|
1243
1249
|
else if (command === "update") await update();
|
|
1250
|
+
else if (command === "protect-key") await protectKey();
|
|
1244
1251
|
else if (command === "history") await history();
|
|
1245
1252
|
// NOT FROM THE TERMINAL (owner, 2026-10-04): an ACCOUNT is connected under Sources in the app, where the
|
|
1246
1253
|
// page also says what is already connected: Claude and ChatGPT on the web and their earlier
|