worktrust 0.10.21 → 0.10.23
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 +28 -11
- package/SECURITY.md +8 -1
- package/engine-release.json +1 -0
- package/package-integrity.mjs +82 -0
- package/package-release.json +1 -0
- package/package.json +7 -3
- package/runtime-install.mjs +2 -1
- package/worktrust-launch.mjs +96 -0
- package/worktrust.mjs +16 -29
package/README.md
CHANGED
|
@@ -9,12 +9,9 @@ npx worktrust@latest
|
|
|
9
9
|
|
|
10
10
|
**The official npm package** is `worktrust`, published by the npm account **worktrustio** with
|
|
11
11
|
provenance from this repository (github.com/fhomey/worktrust-cli). Check it on npmjs.com before you run
|
|
12
|
-
it; a package of another name or from another publisher is not ours.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
curl -fsSO https://app.worktrust.io/counter/worktrust.mjs && node worktrust.mjs
|
|
17
|
-
```
|
|
12
|
+
it; a package of another name or from another publisher is not ours. Use the complete package:
|
|
13
|
+
individual support scripts are no longer downloaded and executed during setup. Version 0.10.22
|
|
14
|
+
adds a signed launcher. Check the registry for availability; 0.10.21 does not include this guard.
|
|
18
15
|
|
|
19
16
|
**Python tool runners:** this repository also builds `worktrust` for `uvx` and `pipx` from the
|
|
20
17
|
same measurement modules. Native wheels (0.10.13+) include a pinned official Node runtime,
|
|
@@ -254,7 +251,7 @@ and counts, exactly as the session hook reads it.
|
|
|
254
251
|
|
|
255
252
|
## Rebuild the history
|
|
256
253
|
|
|
257
|
-
From **0.10.21
|
|
254
|
+
From **0.10.21**, changed measured history waits for review before it
|
|
258
255
|
can replace measurements already received for that computer, client and historical day.
|
|
259
256
|
The earlier receipt is retained as local activity, not independent proof of human effort.
|
|
260
257
|
Other computers and periods remain on the record, including an unavailable old laptop.
|
|
@@ -391,7 +388,7 @@ which would delete every password on the computer, and many people rightly keep
|
|
|
391
388
|
|
|
392
389
|
## What it reads, writes and sends
|
|
393
390
|
|
|
394
|
-
From **0.10.21
|
|
391
|
+
From **0.10.21**, before each submission the hook keeps a local
|
|
395
392
|
metadata file in `~/.worktrust/measurements/`. The `worktrust-measurement/1` format retains
|
|
396
393
|
the available timeline, opaque stretch reference, dates, counts and collector identifiers.
|
|
397
394
|
It omits prompts, answers, titles, repository names, file paths, endpoint URLs and credentials.
|
|
@@ -423,13 +420,13 @@ never as proof.
|
|
|
423
420
|
|
|
424
421
|
## Why you can check it
|
|
425
422
|
|
|
426
|
-
- **No dependencies and no install scripts.** Plain files, readable
|
|
423
|
+
- **No npm dependencies and no install scripts.** Plain files, readable
|
|
427
424
|
in an afternoon: `worktrust.mjs` (this command), `setup-mcp.mjs` (writes the MCP entries),
|
|
428
425
|
`log-session.mjs` (the session hook), `count-behaviour.mjs` (the local counter) and `preserve.mjs`
|
|
429
426
|
(keep your history), with the readers they import.
|
|
430
427
|
- **Bundled measurement modules.** The npm package includes its counter and readers. Interactive
|
|
431
|
-
commands can check the registry
|
|
432
|
-
|
|
428
|
+
commands can check the registry for a version notice; they no longer execute another npm
|
|
429
|
+
version automatically. Installation stays with the selected package manager. See SECURITY.md.
|
|
433
430
|
- **Provenance.** The release workflow requests npm provenance from the public source repository.
|
|
434
431
|
Verify the actual version's attestation and contents before relying on that origin; the manifest
|
|
435
432
|
setting alone does not establish it. `npm audit signatures` checks an installed dependency tree.
|
|
@@ -479,3 +476,23 @@ The licence is free of charge. `preserve` (with `--apply`, `--archive`, `--verif
|
|
|
479
476
|
with or without an account; every other feature is for WorkTrust account holders, and without an account the rest may
|
|
480
477
|
only be installed and evaluated. The archives and files the CLI makes from your own data are yours.
|
|
481
478
|
From 0.10.18 on; versions up to and including 0.10.17 were published under the MIT licence and stay under it.
|
|
479
|
+
|
|
480
|
+
## Release signatures and the limits of verification
|
|
481
|
+
|
|
482
|
+
From 0.10.22, the official launcher verifies fixed release files through `worktrust-launch.mjs` before
|
|
483
|
+
starting the shared engine. Python uses the `pycryptodomex` library to verify its package and
|
|
484
|
+
bundled runtime before Node executes. Final npm/Python/source/preservation downloads are
|
|
485
|
+
covered by an Ed25519-signed `release-artifacts.json`, containing their SHA-256 values and the
|
|
486
|
+
source commit. Verify against the separately pinned publisher key, not a key supplied by the manifest.
|
|
487
|
+
|
|
488
|
+
The initial package-manager installation and host interpreter are trusted bootstrap boundaries.
|
|
489
|
+
A computer owner can alter or bypass a launcher; software signatures do not attest execution.
|
|
490
|
+
|
|
491
|
+
Local Claude records and other client activity are outside this release manifest. An official
|
|
492
|
+
CLI can read edited input. `cli_digest` remains client-reported diagnostic metadata and cannot
|
|
493
|
+
prove which program ran. SHA-256/SHA-512 are not encryption; HTTPS protects transport. Public
|
|
494
|
+
claim eligibility remains the server publication gate's responsibility.
|
|
495
|
+
|
|
496
|
+
Revoking a computer key stops new submissions, not the validity of every historical publication.
|
|
497
|
+
Passport withdrawal is a separate audited operation. Neither operation automatically erases the
|
|
498
|
+
person's prior data. Release signing keys, computer keys and passport signing keys are separate.
|
package/SECURITY.md
CHANGED
|
@@ -12,7 +12,7 @@ private transcripts or account data in a public issue.
|
|
|
12
12
|
A setup dry run is not a sandbox for the whole invocation: the standalone bootstrap can download
|
|
13
13
|
scripts first, and the interactive entry can check for a newer release.
|
|
14
14
|
- Submissions go to the configured WorkTrust MCP endpoint. Interactive commands can also contact
|
|
15
|
-
the npm registry
|
|
15
|
+
the npm registry for a version notice. The unpublished patch based on 0.10.21 no longer executes a newer version from that notice. The npm package bundles its runtime
|
|
16
16
|
modules, but installation and automatic relay still use the network. `preserve` itself is local.
|
|
17
17
|
A custom `--origin`, URL or registry override changes whom you trust.
|
|
18
18
|
- The key it receives is a WorkTrust coupling for this computer: it can submit work metadata to your
|
|
@@ -78,6 +78,13 @@ are resource bounds, not a sandbox or independent validation of the export's tru
|
|
|
78
78
|
|
|
79
79
|
## Verifying a version
|
|
80
80
|
|
|
81
|
+
The unpublished maintenance patch based on 0.10.21 removes automatic execution based only on a newer registry
|
|
82
|
+
version string. The separate signed release/receipt components in the monorepo's
|
|
83
|
+
`tools/worktrust-release` are engineering candidates: production signing keys, final artifact
|
|
84
|
+
signing and npm/Python launcher integration are not yet provisioned. The current Python bundle
|
|
85
|
+
manifest detects file corruption but is not itself an authenticated WorkTrust release signature.
|
|
86
|
+
Do not treat its matching SHA-256 values as proof that modified input describes genuine work.
|
|
87
|
+
|
|
81
88
|
The release configuration names https://github.com/fhomey/worktrust-cli and requests npm provenance.
|
|
82
89
|
Check the particular published version's attestation and compare its contents to that commit before
|
|
83
90
|
relying on those properties. A manifest flag or matching version string alone is not proof that an
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","log-session.mjs":"b99f082a58f0a92375026f52b62eb72173f06614b844e3def06b3ed40942b103","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"b9d81dc88cf5c19ccfbf334a7af84a0c4e299a0e9e4d4091132253e22f855dc3","preserve-lines.mjs":"18081b745b8c47838448b0a49a129a363e29d3f2f5207bc591187d860157b456","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"38f83bd933853a986fef61f4e452c27d4a3adc6000f5c9201ef70f270b404eac","runtime-install.mjs":"b9d2e4febbf400a679eeb3a14b74eef6c2062c5b626d45872a193b7502d3201c","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"70f63b61cf1e28fb2b7471e7768d596b0cf166ccdc9d1ce859ee58d29b2ecabc","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"f28f699f986c72d99af8a7542d317f6dbb9e26d114f6ad083013567e08b8a650","worktrust.mjs":"b563a702634b41c064fdd0b6ad842c77ff851dfcf682b370c677114f8f75c061"},"format":"worktrust-package/1","kind":"engine","version":"0.10.23"},"signature":"g-Lbodi3WAsZnCC1kW05ecOXhxXCNgSITU67By6g3zJMQB5T7ksGWIO5FIP1d1Yf3IP5PlCyMTiJjm0C__8wCg"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Official launcher verification. Pinned keys are generated from reviewed release configuration. */
|
|
2
|
+
import { createHash, createPublicKey, verify, randomBytes } from 'node:crypto';
|
|
3
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, mkdirSync, writeFileSync, renameSync, rmSync } from 'node:fs';
|
|
4
|
+
import { join, dirname } from 'node:path';
|
|
5
|
+
|
|
6
|
+
export const RELEASE_KEYS = {"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5":"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAxe/h8yLe+e4iKYSx/2lzS7MgHIgzM+mi1XjofW1VKo4=\n-----END PUBLIC KEY-----\n"}; // GENERATED_RELEASE_KEYS
|
|
7
|
+
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
8
|
+
const canonical = value => {
|
|
9
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string') return JSON.stringify(value);
|
|
10
|
+
if (typeof value === 'number' && Number.isSafeInteger(value)) return String(value);
|
|
11
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
|
|
12
|
+
if (value && Object.getPrototypeOf(value) === Object.prototype) return `{${Object.keys(value).sort().map(k => `${JSON.stringify(k)}:${canonical(value[k])}`).join(',')}}`;
|
|
13
|
+
throw Error('PACKAGE_INVALID_MANIFEST');
|
|
14
|
+
};
|
|
15
|
+
const exact = (value, keys) => value && Object.keys(value).sort().join(',') === keys.sort().join(',');
|
|
16
|
+
const safe = name => {
|
|
17
|
+
if (typeof name !== 'string' || name.length > 240) return false;
|
|
18
|
+
const parts = name.split('/');
|
|
19
|
+
return parts.every((p, i) => (/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(p) && p !== '..')
|
|
20
|
+
|| (p === '.claude-plugin' && i > 0 && i < parts.length - 1 && parts[i - 1] === 'agent'));
|
|
21
|
+
};
|
|
22
|
+
function regular(path) {
|
|
23
|
+
const s = lstatSync(path);
|
|
24
|
+
if (s.isSymbolicLink() || !s.isFile()) throw Error('PACKAGE_NON_REGULAR_FILE');
|
|
25
|
+
return s;
|
|
26
|
+
}
|
|
27
|
+
function filesIn(root, prefix = '') {
|
|
28
|
+
const s = lstatSync(root);
|
|
29
|
+
if (s.isSymbolicLink() || !s.isDirectory()) throw Error('PACKAGE_NON_REGULAR_DIRECTORY');
|
|
30
|
+
return readdirSync(root).flatMap(name => {
|
|
31
|
+
const path = join(root, name), stat = lstatSync(path);
|
|
32
|
+
if (stat.isSymbolicLink()) throw Error('PACKAGE_NON_REGULAR_FILE');
|
|
33
|
+
return stat.isDirectory() ? filesIn(path, prefix + name + '/') : [prefix + name];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export function verifyPackage(root, kind = 'npm') {
|
|
37
|
+
const signatureName = kind === 'engine' ? 'engine-release.json' : 'package-release.json';
|
|
38
|
+
const path = join(root, signatureName);
|
|
39
|
+
if (regular(path).size > 1024 * 1024) throw Error('PACKAGE_MANIFEST_TOO_LARGE');
|
|
40
|
+
const signed = JSON.parse(readFileSync(path, 'utf8'));
|
|
41
|
+
if (!exact(signed, ['keyId', 'payload', 'signature']) || !Object.hasOwn(RELEASE_KEYS, signed.keyId) || !/^[A-Za-z0-9_-]{86}$/.test(signed.signature)) throw Error('PACKAGE_UNTRUSTED_SIGNATURE');
|
|
42
|
+
const pem = RELEASE_KEYS[signed.keyId], key = createPublicKey(pem);
|
|
43
|
+
if (key.asymmetricKeyType !== 'ed25519' || hash(key.export({ format: 'der', type: 'spki' })) !== signed.keyId
|
|
44
|
+
|| !verify(null, Buffer.from('worktrust:package:1\n' + canonical(signed.payload)), key, Buffer.from(signed.signature, 'base64url'))) throw Error('PACKAGE_UNTRUSTED_SIGNATURE');
|
|
45
|
+
const m = signed.payload;
|
|
46
|
+
if (!exact(m, ['format', 'kind', 'version', 'files']) || m.format !== 'worktrust-package/1' || m.kind !== kind || !/^\d+\.\d+\.\d+$/.test(m.version)
|
|
47
|
+
|| !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');
|
|
48
|
+
const expected = Object.keys(m.files).sort();
|
|
49
|
+
for (const name of expected) {
|
|
50
|
+
if (!safe(name) || name === signatureName || !/^[a-f0-9]{64}$/.test(m.files[name])) throw Error('PACKAGE_INVALID_MANIFEST');
|
|
51
|
+
let parent = root;
|
|
52
|
+
for (const part of name.split('/').slice(0, -1)) { parent = join(parent, part); const s = lstatSync(parent); if (s.isSymbolicLink() || !s.isDirectory()) throw Error('PACKAGE_NON_REGULAR_DIRECTORY'); }
|
|
53
|
+
const file = join(root, name);
|
|
54
|
+
if (regular(file).size > 128 * 1024 * 1024 || hash(readFileSync(file)) !== m.files[name]) throw Error('PACKAGE_FILE_CHANGED');
|
|
55
|
+
}
|
|
56
|
+
const found = filesIn(root).filter(name => name !== signatureName && (kind !== 'engine' || name.endsWith('.mjs'))).sort();
|
|
57
|
+
if (JSON.stringify(found) !== JSON.stringify(expected)) throw Error('PACKAGE_FILE_LIST_CHANGED');
|
|
58
|
+
if (/const CLI_VERSION = "([^"]+)";/.exec(readFileSync(join(root, 'worktrust.mjs'), 'utf8'))?.[1] !== m.version) throw Error('PACKAGE_VERSION_MISMATCH');
|
|
59
|
+
return { manifest: m, identity: hash(readFileSync(path)), signatureName };
|
|
60
|
+
}
|
|
61
|
+
export function installSignedPackage(source, home) {
|
|
62
|
+
const checked = verifyPackage(source), store = join(home, 'verified');
|
|
63
|
+
if (!existsSync(home)) mkdirSync(home, { mode: 0o700 });
|
|
64
|
+
const owned = lstatSync(home);
|
|
65
|
+
if (owned.isSymbolicLink() || !owned.isDirectory()) throw Error('PACKAGE_NON_REGULAR_DIRECTORY');
|
|
66
|
+
if (!existsSync(store)) mkdirSync(store, { mode: 0o700 });
|
|
67
|
+
const stored = lstatSync(store);
|
|
68
|
+
if (stored.isSymbolicLink() || !stored.isDirectory()) throw Error('PACKAGE_NON_REGULAR_DIRECTORY');
|
|
69
|
+
const target = join(store, checked.identity);
|
|
70
|
+
if (existsSync(target)) { if (verifyPackage(target).identity !== checked.identity) throw Error('PACKAGE_INSTALLATION_IDENTITY_MISMATCH'); return join(target, 'worktrust-launch.mjs'); }
|
|
71
|
+
const pending = join(store, '.pending-' + randomBytes(16).toString('hex'));
|
|
72
|
+
mkdirSync(pending, { mode: 0o700 });
|
|
73
|
+
try {
|
|
74
|
+
for (const name of [...Object.keys(checked.manifest.files), checked.signatureName]) {
|
|
75
|
+
const path = join(pending, name); mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
76
|
+
writeFileSync(path, readFileSync(join(source, name)), { flag: 'wx', mode: 0o600 });
|
|
77
|
+
}
|
|
78
|
+
if (verifyPackage(pending).identity !== checked.identity) throw Error('PACKAGE_INSTALLATION_IDENTITY_MISMATCH');
|
|
79
|
+
try { renameSync(pending, target); } catch (error) { if (!existsSync(target)) throw error; if (verifyPackage(target).identity !== checked.identity) throw Error('PACKAGE_INSTALLATION_IDENTITY_MISMATCH'); }
|
|
80
|
+
} finally { rmSync(pending, { recursive: true, force: true }); }
|
|
81
|
+
return join(target, 'worktrust-launch.mjs');
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"d1db152d88338df23b5900beed6a69bedc2900b6f53fef3f036b46dd7a07b841","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"3096ed1693974a90e1f4f59bf01c9559d94a7941d933e36fb81d3995a97f25c1","README.md":"560104ad89115bb9392a39ba31431546296605e23ba7134aebb65e398b54741d","SECURITY.md":"e3ed1927cbceef97b38ca630aadd0a91a0df02368f822f4fd66e3ed0b6a07e8d","chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","engine-release.json":"1b8113feffe4a6c8c513f885c2a507eac002c661a79526734ac054453a6466a2","log-session.mjs":"b99f082a58f0a92375026f52b62eb72173f06614b844e3def06b3ed40942b103","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"b9d81dc88cf5c19ccfbf334a7af84a0c4e299a0e9e4d4091132253e22f855dc3","package.json":"29ed1c5bfa3075d6970b94a7b922d85dfdcce7a4e3afc6808d340ae421a3aa0d","preserve-lines.mjs":"18081b745b8c47838448b0a49a129a363e29d3f2f5207bc591187d860157b456","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"38f83bd933853a986fef61f4e452c27d4a3adc6000f5c9201ef70f270b404eac","runtime-install.mjs":"b9d2e4febbf400a679eeb3a14b74eef6c2062c5b626d45872a193b7502d3201c","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"70f63b61cf1e28fb2b7471e7768d596b0cf166ccdc9d1ce859ee58d29b2ecabc","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"f28f699f986c72d99af8a7542d317f6dbb9e26d114f6ad083013567e08b8a650","worktrust.mjs":"b563a702634b41c064fdd0b6ad842c77ff851dfcf682b370c677114f8f75c061"},"format":"worktrust-package/1","kind":"npm","version":"0.10.23"},"signature":"WESSe1_j0LegjJCE5a8xKYLoeKmDic5pLIK8bUpCSV2yqnU7P4UIfOosoux_buhU6-khECj2I_rNUTz4YQsbCw"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.23",
|
|
4
4
|
"description": "Couple this computer to WorkTrust: approve a code in your browser, and every AI app here reports what you built. Metadata only, no dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"worktrust": "worktrust.mjs"
|
|
7
|
+
"worktrust": "worktrust-launch.mjs"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"worktrust.mjs",
|
|
@@ -29,7 +29,11 @@
|
|
|
29
29
|
"orchestration-contract.mjs",
|
|
30
30
|
"orchestration-evidence.mjs",
|
|
31
31
|
"orchestration-report.mjs",
|
|
32
|
-
"claude-mod.mjs"
|
|
32
|
+
"claude-mod.mjs",
|
|
33
|
+
"package-integrity.mjs",
|
|
34
|
+
"worktrust-launch.mjs",
|
|
35
|
+
"engine-release.json",
|
|
36
|
+
"package-release.json"
|
|
33
37
|
],
|
|
34
38
|
"engines": {
|
|
35
39
|
"node": ">=18"
|
package/runtime-install.mjs
CHANGED
|
@@ -30,6 +30,7 @@ export function installRuntime(runtime, engine, home, moduleNames) {
|
|
|
30
30
|
if (!/^[a-z][a-z0-9-]*\.mjs$/.test(name)) throw Error("invalid engine module name");
|
|
31
31
|
contents.set(`engine/${name}`, checkedBytes(join(engine, name)));
|
|
32
32
|
}
|
|
33
|
+
if (existsSync(join(engine, "engine-release.json"))) contents.set("engine/engine-release.json", checkedBytes(join(engine, "engine-release.json")));
|
|
33
34
|
const identities = Object.fromEntries([...contents].map(([name, bytes]) => [name, hash(bytes)]));
|
|
34
35
|
const identity = Buffer.from(JSON.stringify(identities));
|
|
35
36
|
const installations = join(home, "installations"), installed = join(installations, hash(identity));
|
|
@@ -60,5 +61,5 @@ export function installRuntime(runtime, engine, home, moduleNames) {
|
|
|
60
61
|
} finally { rmSync(temporary, { recursive: true, force: true }); }
|
|
61
62
|
}
|
|
62
63
|
// Existing immutable directories are never replaced, including executables used by Windows processes.
|
|
63
|
-
return { executable: join(installed, "runtime", executable), bridge: join(installed, "engine", "worktrust.mjs") };
|
|
64
|
+
return { executable: join(installed, "runtime", executable), bridge: join(installed, "engine", contents.has("engine/engine-release.json") ? "worktrust-launch.mjs" : "worktrust.mjs") };
|
|
64
65
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// GENERATED by scripts/build-cli-launchers.mjs; verify before importing any local module.
|
|
3
|
+
/** Official launcher verification. Pinned keys are generated from reviewed release configuration. */
|
|
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';
|
|
7
|
+
|
|
8
|
+
const RELEASE_KEYS = {"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5":"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAxe/h8yLe+e4iKYSx/2lzS7MgHIgzM+mi1XjofW1VKo4=\n-----END PUBLIC KEY-----\n"}; // GENERATED_RELEASE_KEYS
|
|
9
|
+
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
10
|
+
const canonical = value => {
|
|
11
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string') return JSON.stringify(value);
|
|
12
|
+
if (typeof value === 'number' && Number.isSafeInteger(value)) return String(value);
|
|
13
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
|
|
14
|
+
if (value && Object.getPrototypeOf(value) === Object.prototype) return `{${Object.keys(value).sort().map(k => `${JSON.stringify(k)}:${canonical(value[k])}`).join(',')}}`;
|
|
15
|
+
throw Error('PACKAGE_INVALID_MANIFEST');
|
|
16
|
+
};
|
|
17
|
+
const exact = (value, keys) => value && Object.keys(value).sort().join(',') === keys.sort().join(',');
|
|
18
|
+
const safe = name => {
|
|
19
|
+
if (typeof name !== 'string' || name.length > 240) return false;
|
|
20
|
+
const parts = name.split('/');
|
|
21
|
+
return parts.every((p, i) => (/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(p) && p !== '..')
|
|
22
|
+
|| (p === '.claude-plugin' && i > 0 && i < parts.length - 1 && parts[i - 1] === 'agent'));
|
|
23
|
+
};
|
|
24
|
+
function regular(path) {
|
|
25
|
+
const s = lstatSync(path);
|
|
26
|
+
if (s.isSymbolicLink() || !s.isFile()) throw Error('PACKAGE_NON_REGULAR_FILE');
|
|
27
|
+
return s;
|
|
28
|
+
}
|
|
29
|
+
function filesIn(root, prefix = '') {
|
|
30
|
+
const s = lstatSync(root);
|
|
31
|
+
if (s.isSymbolicLink() || !s.isDirectory()) throw Error('PACKAGE_NON_REGULAR_DIRECTORY');
|
|
32
|
+
return readdirSync(root).flatMap(name => {
|
|
33
|
+
const path = join(root, name), stat = lstatSync(path);
|
|
34
|
+
if (stat.isSymbolicLink()) throw Error('PACKAGE_NON_REGULAR_FILE');
|
|
35
|
+
return stat.isDirectory() ? filesIn(path, prefix + name + '/') : [prefix + name];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function verifyPackage(root, kind = 'npm') {
|
|
39
|
+
const signatureName = kind === 'engine' ? 'engine-release.json' : 'package-release.json';
|
|
40
|
+
const path = join(root, signatureName);
|
|
41
|
+
if (regular(path).size > 1024 * 1024) throw Error('PACKAGE_MANIFEST_TOO_LARGE');
|
|
42
|
+
const signed = JSON.parse(readFileSync(path, 'utf8'));
|
|
43
|
+
if (!exact(signed, ['keyId', 'payload', 'signature']) || !Object.hasOwn(RELEASE_KEYS, signed.keyId) || !/^[A-Za-z0-9_-]{86}$/.test(signed.signature)) throw Error('PACKAGE_UNTRUSTED_SIGNATURE');
|
|
44
|
+
const pem = RELEASE_KEYS[signed.keyId], key = createPublicKey(pem);
|
|
45
|
+
if (key.asymmetricKeyType !== 'ed25519' || hash(key.export({ format: 'der', type: 'spki' })) !== signed.keyId
|
|
46
|
+
|| !verify(null, Buffer.from('worktrust:package:1\n' + canonical(signed.payload)), key, Buffer.from(signed.signature, 'base64url'))) throw Error('PACKAGE_UNTRUSTED_SIGNATURE');
|
|
47
|
+
const m = signed.payload;
|
|
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');
|
|
50
|
+
const expected = Object.keys(m.files).sort();
|
|
51
|
+
for (const name of expected) {
|
|
52
|
+
if (!safe(name) || name === signatureName || !/^[a-f0-9]{64}$/.test(m.files[name])) throw Error('PACKAGE_INVALID_MANIFEST');
|
|
53
|
+
let parent = root;
|
|
54
|
+
for (const part of name.split('/').slice(0, -1)) { parent = join(parent, part); const s = lstatSync(parent); if (s.isSymbolicLink() || !s.isDirectory()) throw Error('PACKAGE_NON_REGULAR_DIRECTORY'); }
|
|
55
|
+
const file = join(root, name);
|
|
56
|
+
if (regular(file).size > 128 * 1024 * 1024 || hash(readFileSync(file)) !== m.files[name]) throw Error('PACKAGE_FILE_CHANGED');
|
|
57
|
+
}
|
|
58
|
+
const found = filesIn(root).filter(name => name !== signatureName && (kind !== 'engine' || name.endsWith('.mjs'))).sort();
|
|
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');
|
|
61
|
+
return { manifest: m, identity: hash(readFileSync(path)), signatureName };
|
|
62
|
+
}
|
|
63
|
+
function installSignedPackage(source, home) {
|
|
64
|
+
const checked = verifyPackage(source), store = join(home, 'verified');
|
|
65
|
+
if (!existsSync(home)) mkdirSync(home, { mode: 0o700 });
|
|
66
|
+
const owned = lstatSync(home);
|
|
67
|
+
if (owned.isSymbolicLink() || !owned.isDirectory()) throw Error('PACKAGE_NON_REGULAR_DIRECTORY');
|
|
68
|
+
if (!existsSync(store)) mkdirSync(store, { mode: 0o700 });
|
|
69
|
+
const stored = lstatSync(store);
|
|
70
|
+
if (stored.isSymbolicLink() || !stored.isDirectory()) throw Error('PACKAGE_NON_REGULAR_DIRECTORY');
|
|
71
|
+
const target = join(store, checked.identity);
|
|
72
|
+
if (existsSync(target)) { if (verifyPackage(target).identity !== checked.identity) throw Error('PACKAGE_INSTALLATION_IDENTITY_MISMATCH'); return join(target, 'worktrust-launch.mjs'); }
|
|
73
|
+
const pending = join(store, '.pending-' + randomBytes(16).toString('hex'));
|
|
74
|
+
mkdirSync(pending, { mode: 0o700 });
|
|
75
|
+
try {
|
|
76
|
+
for (const name of [...Object.keys(checked.manifest.files), checked.signatureName]) {
|
|
77
|
+
const path = join(pending, name); mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
78
|
+
writeFileSync(path, readFileSync(join(source, name)), { flag: 'wx', mode: 0o600 });
|
|
79
|
+
}
|
|
80
|
+
if (verifyPackage(pending).identity !== checked.identity) throw Error('PACKAGE_INSTALLATION_IDENTITY_MISMATCH');
|
|
81
|
+
try { renameSync(pending, target); } catch (error) { if (!existsSync(target)) throw error; if (verifyPackage(target).identity !== checked.identity) throw Error('PACKAGE_INSTALLATION_IDENTITY_MISMATCH'); }
|
|
82
|
+
} finally { rmSync(pending, { recursive: true, force: true }); }
|
|
83
|
+
return join(target, 'worktrust-launch.mjs');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
import { fileURLToPath } from 'node:url';
|
|
87
|
+
const root = dirname(fileURLToPath(import.meta.url));
|
|
88
|
+
try {
|
|
89
|
+
verifyPackage(root, existsSync(join(root, 'package.json')) ? 'npm' : 'engine');
|
|
90
|
+
process.argv[1] = join(root, 'worktrust.mjs');
|
|
91
|
+
await import('./worktrust.mjs');
|
|
92
|
+
} catch (error) {
|
|
93
|
+
const category = /^PACKAGE_[A-Z_]+$/.test(error.message) ? error.message : 'PACKAGE_VERIFICATION_FAILED';
|
|
94
|
+
process.stderr.write(`worktrust: ${category}. Execution stopped; reinstall an official WorkTrust release.\n`);
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
}
|
package/worktrust.mjs
CHANGED
|
@@ -78,12 +78,12 @@ 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.10.
|
|
81
|
+
const CLI_VERSION = "0.10.23";
|
|
82
82
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
83
83
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
84
84
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
85
85
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
86
|
-
const SCRIPTS = ["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"];
|
|
86
|
+
const SCRIPTS = ["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
87
|
/** The modules the scripts import by name from beside them; a download keeps that name. */
|
|
88
88
|
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
89
|
const downloaded = (name) => (IMPORTED.has(name) ? name : `${name}.download.mjs`);
|
|
@@ -128,15 +128,7 @@ async function post(path, body) {
|
|
|
128
128
|
/** The three scripts: from the package when it carries them; otherwise from the same site, once, into ~/.worktrust. */
|
|
129
129
|
async function scripts() {
|
|
130
130
|
if (BUNDLED) return Object.fromEntries(SCRIPTS.map((name) => [name, join(HERE, name)]));
|
|
131
|
-
|
|
132
|
-
const paths = {};
|
|
133
|
-
for (const name of SCRIPTS) {
|
|
134
|
-
const response = await fetch(`${ORIGIN}/counter/${name}`);
|
|
135
|
-
if (!response.ok) fail(`could not download ${name} (${response.status}).`);
|
|
136
|
-
paths[name] = join(HOME_DIR, downloaded(name));
|
|
137
|
-
writeFileSync(paths[name], await response.text(), { mode: 0o600 });
|
|
138
|
-
}
|
|
139
|
-
return paths;
|
|
131
|
+
fail("Use the complete official npm/Python package or preservation kit. Individual scripts are not downloaded or executed without release verification.");
|
|
140
132
|
}
|
|
141
133
|
|
|
142
134
|
/** Run a script; its output is shown, or collected for the plan. The key travels in the environment only. */
|
|
@@ -277,7 +269,14 @@ const ensureHome = () => { mkdirSync(HOME_DIR, { recursive: true, mode: 0o700 })
|
|
|
277
269
|
|
|
278
270
|
/** A tool-runner cache is disposable. Install the whole verified runtime/engine before changing wiring. */
|
|
279
271
|
async function prepareBundledRuntime() {
|
|
280
|
-
if (
|
|
272
|
+
if (runtimePrepared) return;
|
|
273
|
+
if (!process.env.WORKTRUST_BUNDLED_RUNTIME_DIR) {
|
|
274
|
+
if (existsSync(join(HERE, "package-release.json"))) {
|
|
275
|
+
if (existsSync(HOME_DIR) && (!lstatSync(HOME_DIR).isDirectory() || lstatSync(HOME_DIR).isSymbolicLink())) fail("the WorkTrust directory must be a directory, not a symlink.");
|
|
276
|
+
ensureHome(); const { installSignedPackage } = await import("./package-integrity.mjs"); STABLE = installSignedPackage(HERE, HOME_DIR); runtimePrepared = true;
|
|
277
|
+
}
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
281
280
|
const { installRuntime } = await import("./runtime-install.mjs");
|
|
282
281
|
if (existsSync(HOME_DIR) && (!lstatSync(HOME_DIR).isDirectory() || lstatSync(HOME_DIR).isSymbolicLink())) fail("the WorkTrust directory must be a directory, not a symlink.");
|
|
283
282
|
ensureHome();
|
|
@@ -1193,15 +1192,10 @@ if (agentShell && PERSON_ONLY.has(command)) {
|
|
|
1193
1192
|
return (process.exitCode = 3);
|
|
1194
1193
|
}
|
|
1195
1194
|
|
|
1196
|
-
/**
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1199
|
-
* which version is newest (the version string only, nothing of this computer, two seconds at most) and, when this one is
|
|
1200
|
-
* older, hands the same command to the newest through npx and steps aside. Offline, npm slow, no terminal (a script, a
|
|
1201
|
-
* test), an AI agent's shell: this version runs as it is. The bridge and the hook, which run many times a day from the
|
|
1202
|
-
* stable copy, never ask.
|
|
1195
|
+
/** Interactive version notice only. Registry metadata is not a trusted signed release catalogue.
|
|
1196
|
+
* Hooks, bridge and offline preserve never check. Installation remains with the person's package manager
|
|
1197
|
+
* until the signed release updater has a provisioned trust root and has passed the distribution gates.
|
|
1203
1198
|
*/
|
|
1204
|
-
// NOT `preserve` (0.10.8): it promises no network connection at all (the site and its kit say so), so it never asks npm.
|
|
1205
1199
|
const RELAY_COMMANDS = new Set(["default", "connect", "update", "history", "status", "disconnect", "codex", "antigravity"]);
|
|
1206
1200
|
const semverNewer = (a, b) => { const x = a.split(".").map(Number), y = b.split(".").map(Number); for (let i = 0; i < 3; i += 1) if (x[i] !== y[i]) return x[i] > y[i]; return false; };
|
|
1207
1201
|
async function newestVersion() {
|
|
@@ -1216,15 +1210,8 @@ async function relayToNewest() {
|
|
|
1216
1210
|
if (process.env.WORKTRUST_RELAYED === "1" || !RELAY_COMMANDS.has(command) || !process.stdin.isTTY || !process.stdout.isTTY) return;
|
|
1217
1211
|
const latest = await newestVersion();
|
|
1218
1212
|
if (!latest || !semverNewer(latest, CLI_VERSION)) return;
|
|
1219
|
-
say(`
|
|
1220
|
-
|
|
1221
|
-
const env = { ...process.env, WORKTRUST_RELAYED: "1" };
|
|
1222
|
-
// A .cmd shim on Windows needs a shell: one line, each argument quoted for cmd.exe, never an argument list beside it.
|
|
1223
|
-
const quote = (arg) => (/^[\w@%+=:,./\\-]+$/.test(arg) ? arg : `"${String(arg).replace(/"/g, '\\"')}"`);
|
|
1224
|
-
const child = platform() === "win32" ? spawn(["npx", ...argv].map(quote).join(" "), { stdio: "inherit", env, shell: true }) : spawn("npx", argv, { stdio: "inherit", env });
|
|
1225
|
-
const code = await new Promise((done) => { child.on("error", () => done(null)); child.on("close", (exit) => done(exit)); });
|
|
1226
|
-
if (code === null) { say(" The newest could not be started; this version runs instead."); return; }
|
|
1227
|
-
process.exitCode = code; return true;
|
|
1213
|
+
say(` WorkTrust ${latest} is available. Automatic execution is paused until signed release verification is configured.`);
|
|
1214
|
+
say(" Update explicitly using the package manager you installed with. This invocation keeps its current version.");
|
|
1228
1215
|
}
|
|
1229
1216
|
if (await relayToNewest()) return;
|
|
1230
1217
|
|