worktrust 0.10.25 → 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 +39 -20
- package/SECURITY.md +14 -4
- 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/package-release.json +1 -1
- package/package.json +5 -2
- package/preserve.mjs +10 -9
- package/worktrust.mjs +35 -38
package/AGENTS.md
CHANGED
|
@@ -7,7 +7,7 @@ the rules of this package.
|
|
|
7
7
|
|
|
8
8
|
## Do not run it for the person
|
|
9
9
|
|
|
10
|
-
The bare `worktrust` command, `connect`, `update`, `history` (and `--rebuild`), `disconnect`, `preserve`, `codex`, `antigravity` and the
|
|
10
|
+
The bare `worktrust` command, `connect`, `update`, `history` (and `--rebuild`), `disconnect`, `protect-key`, `preserve`, `codex`, `antigravity` and the
|
|
11
11
|
import commands change what this computer sends or couples. **Only the person runs them, in their own terminal.** In an
|
|
12
12
|
agent's shell the CLI refuses these actions, `--yes` included. Version 0.10.12 adds the missing default-command
|
|
13
13
|
guard and tests both fresh and coupled synthetic homes. Do not work around the policy: do not unset
|
package/README.md
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
# worktrust
|
|
2
2
|
|
|
3
|
-
## Candidate 0.10.
|
|
3
|
+
## Candidate 0.10.26: OS credential storage
|
|
4
4
|
|
|
5
|
-
Not published yet.
|
|
5
|
+
Not published yet; 0.10.25 is the preceding live release. This candidate adds explicit
|
|
6
|
+
`worktrust protect-key` migration: an OS-vault wrapping key protects the locally encrypted
|
|
7
|
+
coupling credentials. It does not attest that local activity is truthful. See
|
|
8
|
+
[credential protection](#credential-protection) before enabling it.
|
|
9
|
+
|
|
10
|
+
After an approved update, WorkTrust receives the running version without
|
|
6
11
|
an activity upload. Pending metadata batches can be resumed with `worktrust history --resume`,
|
|
7
12
|
even after an AI app removed the original session files. Review-held revisions need review;
|
|
8
13
|
reconnecting does not approve them. Keep archives for work that was never queued.
|
|
9
14
|
|
|
10
|
-
The
|
|
15
|
+
The server limits new personal registrations to five active device
|
|
11
16
|
identities. AI apps sharing one key share one slot; cloned keys share account upload capacity.
|
|
12
17
|
Retiring a device preserves earlier data. Existing accounts above the limit are preserved but
|
|
13
18
|
cannot add another identity. Version labels and device signatures are not independent evidence
|
|
@@ -24,8 +29,8 @@ npx worktrust@latest
|
|
|
24
29
|
**The official npm package** is `worktrust`, published by the npm account **worktrustio** with
|
|
25
30
|
provenance from this repository (github.com/fhomey/worktrust-cli). Check it on npmjs.com before you run
|
|
26
31
|
it; a package of another name or from another publisher is not ours. Use the complete package:
|
|
27
|
-
individual support scripts are no longer downloaded and executed during setup.
|
|
28
|
-
|
|
32
|
+
individual support scripts are no longer downloaded and executed during setup. The live 0.10.25
|
|
33
|
+
release includes signed startup checks; 0.10.21 does not include this guard.
|
|
29
34
|
|
|
30
35
|
**Python tool runners:** this repository also builds `worktrust` for `uvx` and `pipx` from the
|
|
31
36
|
same measurement modules. Native wheels (0.10.13+) include a pinned official Node runtime,
|
|
@@ -381,20 +386,33 @@ a day it sealed before), but such a day reaches WorkTrust as reconstructed. It i
|
|
|
381
386
|
pairing: `connect` always mints a fresh pair, because a private key that lived on disk before the pairing would weaken
|
|
382
387
|
the proof of possession the pairing binds, for nothing your record would gain.
|
|
383
388
|
|
|
384
|
-
##
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
389
|
+
## Credential protection
|
|
390
|
+
|
|
391
|
+
Existing installations keep private file storage until the person opts in. In the 0.10.26
|
|
392
|
+
candidate, run `worktrust update`, quit the AI apps, then run `worktrust protect-key` and restart
|
|
393
|
+
those apps. A new computer can run `worktrust protect-key` before connecting. `worktrust status`
|
|
394
|
+
shows the storage mode. This command is local and does not publish or change a Passport.
|
|
395
|
+
|
|
396
|
+
Protected mode encrypts the token, pending renewal token, device private key and coupling metadata
|
|
397
|
+
with AES-256-GCM in `~/.worktrust/key.json`. Its random encryption key lives in macOS Keychain,
|
|
398
|
+
Windows Credential Manager, or Linux Secret Service (`/usr/bin/secret-tool` from libsecret-tools,
|
|
399
|
+
with a running, unlocked desktop secret service). No keychain reset is performed. First-time
|
|
400
|
+
protection may require OS approval; background reads never request an unlock prompt. An unavailable
|
|
401
|
+
vault stops uploads without advancing their checkpoints. There is no plaintext fallback.
|
|
402
|
+
|
|
403
|
+
Migration verifies the vault write before atomically replacing the old file. No plaintext backup
|
|
404
|
+
is created. Existing backups and already running processes can still hold the old secrets; this
|
|
405
|
+
is not secure erasure of an SSD or revocation of previously copied credentials. The local archive's
|
|
406
|
+
separate continuity key (`archive-key.json`) is not migrated by this command. `preserve` remains
|
|
407
|
+
offline and refuses to silently change signing identity when protected credentials are unavailable.
|
|
408
|
+
|
|
409
|
+
- **AI apps use the bridge.** The bridge and hooks read the protected credentials as the OS user;
|
|
410
|
+
their settings contain a launcher command, not the credentials. Update every installed bridge
|
|
411
|
+
first: older releases cannot read the encrypted format. Protected mode refuses `--direct`.
|
|
412
|
+
- **A device signature proves possession.** The server stores the public key and checks fresh
|
|
413
|
+
signed requests and single-use nonces. Neither file encryption nor an OS vault proves genuine
|
|
414
|
+
local activity. Software authorized as the same OS user may still obtain or use these secrets.
|
|
415
|
+
This is not a hardware-bound, non-exportable key. Revoke the connection if it may be compromised.
|
|
398
416
|
- **The key renews itself every week.** A new secret is made here, only its hash is sent, signed,
|
|
399
417
|
and last week's key stops working.
|
|
400
418
|
- `npx worktrust --direct` writes a plain key into the apps' settings instead, for an app
|
|
@@ -467,7 +485,8 @@ never as proof.
|
|
|
467
485
|
## Undo
|
|
468
486
|
|
|
469
487
|
`npx worktrust@latest disconnect` removes the WorkTrust entries (Hermes's hook with them), the hook (and Codex's `notify` line and
|
|
470
|
-
Antigravity's `worktrust` hook when WorkTrust set them), the
|
|
488
|
+
Antigravity's `worktrust` hook when WorkTrust set them), the credentials and installed bridge scripts.
|
|
489
|
+
Protected mode retains an encrypted empty slot and its OS wrapping key so reconnecting stays protected.
|
|
471
490
|
A small note of the previous account (masked) remains so that a later coupling by another account
|
|
472
491
|
does not offer its earlier work. Other retained files and your local evidence archive are not an
|
|
473
492
|
automatic server or archive erasure.
|
package/SECURITY.md
CHANGED
|
@@ -28,12 +28,22 @@ private transcripts or account data in a public issue.
|
|
|
28
28
|
|
|
29
29
|
## Where the key is, and how long it lives
|
|
30
30
|
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
- Existing installations use a private local file until explicit `worktrust protect-key` migration
|
|
32
|
+
(0.10.26 candidate). Base64 in that legacy file is not encryption.
|
|
33
|
+
- Protected mode uses AES-256-GCM for all coupling secrets and OS storage for a separate random
|
|
34
|
+
wrapping key: macOS Keychain, Windows Credential Manager with local-machine persistence, or
|
|
35
|
+
Linux Secret Service. Only a random identifier, provider, nonce, ciphertext and authentication
|
|
36
|
+
tag remain in `key.json`. Private file checks and atomic replacement still apply. Locked,
|
|
37
|
+
missing or unavailable OS storage fails closed, without a new key or plaintext fallback.
|
|
38
|
+
- This is exportable software credential protection, not hardware attestation. Other software
|
|
39
|
+
authorized as the OS user can request decryption; an attacker controlling the launcher or OS
|
|
40
|
+
can bypass local checks. Local activity remains untrusted for independent public claims.
|
|
41
|
+
- The command does not reset a vault, change its ACLs, erase backups, revoke stolen credentials,
|
|
42
|
+
or move the independent offline archive continuity key. New setup is opt-in; it is not an
|
|
43
|
+
automatic migration of existing users. Hooks never write vault items or trigger unlock UI.
|
|
34
44
|
- In the default mode, requests carry an Ed25519 proof. WorkTrust refuses a bound token without a
|
|
35
45
|
fresh signature (two minutes, a nonce spent once). A bearer token alone is insufficient; theft of
|
|
36
|
-
the
|
|
46
|
+
the legacy plaintext credentials, or the protected file together with access to its OS wrapping key, defeats that protection. Profile/device hashes are not hardware
|
|
37
47
|
attestation. Revoke the computer in WorkTrust if its credential file may have been copied.
|
|
38
48
|
- `--direct` instead places an unbound bearer token in AI client settings and does not provide the
|
|
39
49
|
same proof requirement. Do not apply the default mode's guarantees to that mode.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** OS-backed wrapping key, AES-256-GCM credentials. The OS account can still request decryption.
|
|
2
|
+
* No attestation: signed input remains subject to the server's claim-specific trust gates.
|
|
3
|
+
*/
|
|
4
|
+
import { createCipheriv, createDecipheriv, createPrivateKey, createPublicKey, randomBytes } from 'node:crypto';
|
|
5
|
+
import { rmSync } from 'node:fs';
|
|
6
|
+
import { readPrivateFile, writePrivateFile, createPrivateFile } from './package-integrity.mjs';
|
|
7
|
+
import { nativeKeyStore } from './credential-vault.mjs';
|
|
8
|
+
const FORMAT = 'worktrust-os-key/1';
|
|
9
|
+
function validEntry(entry) {
|
|
10
|
+
if (entry !== null && (!entry || typeof entry !== 'object' || Array.isArray(entry) || typeof entry.token !== 'string' || !entry.token)) throw Error('KEY_FILE_INVALID');
|
|
11
|
+
return entry;
|
|
12
|
+
}
|
|
13
|
+
function decode(bytes) {
|
|
14
|
+
if (bytes === null) return null;
|
|
15
|
+
try {
|
|
16
|
+
if (bytes.startsWith('{')) {
|
|
17
|
+
const e = JSON.parse(bytes);
|
|
18
|
+
if (e.format !== FORMAT || !/^[a-f0-9]{64}$/.test(e.id) || !/^[a-z-]{1,40}$/.test(e.provider)
|
|
19
|
+
|| !/^[a-f0-9]{24}$/.test(e.iv) || !/^[a-f0-9]{32}$/.test(e.tag) || typeof e.ciphertext !== 'string'
|
|
20
|
+
|| !/^[A-Za-z0-9+/]+={0,2}$/.test(e.ciphertext)
|
|
21
|
+
|| Object.keys(e).sort().join(',') !== 'ciphertext,format,id,iv,provider,tag') throw Error();
|
|
22
|
+
return e;
|
|
23
|
+
}
|
|
24
|
+
return validEntry(JSON.parse(Buffer.from(bytes, 'base64').toString('utf8')));
|
|
25
|
+
} catch { throw Error('KEY_FILE_INVALID'); }
|
|
26
|
+
}
|
|
27
|
+
function wrappingKey(vault, envelope) {
|
|
28
|
+
if (envelope.provider !== vault.name) throw Error('KEYSTORE_UNAVAILABLE');
|
|
29
|
+
const value = vault.get(envelope.id);
|
|
30
|
+
if (typeof value !== 'string' || !/^[a-f0-9]{64}$/.test(value)) throw Error('KEYSTORE_UNAVAILABLE');
|
|
31
|
+
return Buffer.from(value, 'hex');
|
|
32
|
+
}
|
|
33
|
+
const aad = e => Buffer.from(`${FORMAT}\n${e.provider}\n${e.id}`);
|
|
34
|
+
function open(vault, e) {
|
|
35
|
+
if (!e || e.format !== FORMAT) return e;
|
|
36
|
+
const key = wrappingKey(vault, e);
|
|
37
|
+
try {
|
|
38
|
+
const cipher = createDecipheriv('aes-256-gcm', key, Buffer.from(e.iv, 'hex'));
|
|
39
|
+
cipher.setAAD(aad(e)); cipher.setAuthTag(Buffer.from(e.tag, 'hex'));
|
|
40
|
+
return validEntry(JSON.parse(Buffer.concat([cipher.update(Buffer.from(e.ciphertext, 'base64')), cipher.final()]).toString('utf8')));
|
|
41
|
+
} catch { throw Error('KEY_FILE_INVALID'); }
|
|
42
|
+
finally { key.fill(0); }
|
|
43
|
+
}
|
|
44
|
+
function seal(vault, reference, entry) {
|
|
45
|
+
const key = wrappingKey(vault, reference);
|
|
46
|
+
try {
|
|
47
|
+
const iv = randomBytes(12), cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
48
|
+
cipher.setAAD(aad(reference));
|
|
49
|
+
const ciphertext = Buffer.concat([cipher.update(JSON.stringify(validEntry(entry)), 'utf8'), cipher.final()]);
|
|
50
|
+
return JSON.stringify({ format: FORMAT, provider: reference.provider, id: reference.id, iv: iv.toString('hex'), tag: cipher.getAuthTag().toString('hex'), ciphertext: ciphertext.toString('base64') });
|
|
51
|
+
} finally { key.fill(0); }
|
|
52
|
+
}
|
|
53
|
+
export function createCredentialStore(file, vault = nativeKeyStore()) {
|
|
54
|
+
const read = () => decode(readPrivateFile(file));
|
|
55
|
+
function locked(action) {
|
|
56
|
+
const lock = `${file}.lock`;
|
|
57
|
+
try { createPrivateFile(lock, JSON.stringify({ pid: process.pid })); }
|
|
58
|
+
catch (error) { throw Error(error.code === 'EEXIST' ? 'KEY_STORE_BUSY' : 'KEY_FILE_UNSAFE'); }
|
|
59
|
+
try { return action(); } finally { rmSync(lock); }
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
load() { return open(vault, read()); },
|
|
63
|
+
protected() { return read()?.format === FORMAT; },
|
|
64
|
+
save(entry) {
|
|
65
|
+
return locked(() => {
|
|
66
|
+
const old = read();
|
|
67
|
+
// Authenticate the previous envelope before replacing it; corruption is never reset quietly.
|
|
68
|
+
if (old?.format === FORMAT) { open(vault, old); writePrivateFile(file, seal(vault, old, entry)); }
|
|
69
|
+
else writePrivateFile(file, Buffer.from(JSON.stringify(validEntry(entry))).toString('base64'));
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
protect() {
|
|
73
|
+
return locked(() => {
|
|
74
|
+
const old = read();
|
|
75
|
+
if (old?.format === FORMAT) { open(vault, old); return; }
|
|
76
|
+
const reference = { format: FORMAT, provider: vault.name, id: randomBytes(32).toString('hex') };
|
|
77
|
+
const secret = randomBytes(32).toString('hex'); let committed = false;
|
|
78
|
+
try {
|
|
79
|
+
vault.put(reference.id, secret);
|
|
80
|
+
if (vault.get(reference.id) !== secret) throw Error('KEYSTORE_UNAVAILABLE');
|
|
81
|
+
const envelope = seal(vault, reference, old);
|
|
82
|
+
if (JSON.stringify(open(vault, JSON.parse(envelope))) !== JSON.stringify(old)) throw Error('KEYSTORE_UNAVAILABLE');
|
|
83
|
+
writePrivateFile(file, envelope); committed = true;
|
|
84
|
+
} finally {
|
|
85
|
+
// If preparation fails the old credentials survive. No backup containing plaintext is made.
|
|
86
|
+
if (!committed) { try { vault.remove(reference.id); } catch { /* orphan random wrapping key, no credentials */ } }
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
erase() {
|
|
91
|
+
return locked(() => {
|
|
92
|
+
const old = read();
|
|
93
|
+
// An encrypted empty slot keeps the storage preference through disconnect/reconnect.
|
|
94
|
+
if (old?.format === FORMAT) { open(vault, old); writePrivateFile(file, seal(vault, old, null)); }
|
|
95
|
+
else rmSync(file, { force: true });
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Archive signing shares the coupling store; an unavailable vault is not an absent device. */
|
|
102
|
+
export function readDeviceSigningKey(file) {
|
|
103
|
+
const entry = createCredentialStore(file).load();
|
|
104
|
+
if (!entry?.device) return null;
|
|
105
|
+
try {
|
|
106
|
+
const privateKey = createPrivateKey(entry.device);
|
|
107
|
+
return { privateKey, publicX: createPublicKey(privateKey).export({ format: "jwk" }).x, kind: "device" };
|
|
108
|
+
} catch { return null; }
|
|
109
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Fixed helper programs are covered by the release manifest. No request is evaluated as code. */
|
|
2
|
+
export const macKeychainScript = String.raw`
|
|
3
|
+
ObjC.import('Foundation'); ObjC.import('Security');
|
|
4
|
+
function run() {
|
|
5
|
+
try {
|
|
6
|
+
var data = $.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile;
|
|
7
|
+
var request = JSON.parse(ObjC.unwrap($.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding)));
|
|
8
|
+
if (!/^[a-f0-9]{64}$/.test(request.id) || request.service !== 'io.worktrust.cli.credentials.v1') throw Error();
|
|
9
|
+
// No reset, default-keychain change, ACL broadening or partition-list modification.
|
|
10
|
+
$.SecKeychainSetUserInteractionAllowed(request.op === 'put');
|
|
11
|
+
var query = $.NSMutableDictionary.alloc.init;
|
|
12
|
+
query.setObjectForKey(ObjC.castRefToObject($.kSecClassGenericPassword), ObjC.castRefToObject($.kSecClass));
|
|
13
|
+
query.setObjectForKey($(request.service), ObjC.castRefToObject($.kSecAttrService));
|
|
14
|
+
query.setObjectForKey($(request.id), ObjC.castRefToObject($.kSecAttrAccount));
|
|
15
|
+
var status, result = Ref();
|
|
16
|
+
if (request.op === 'get') {
|
|
17
|
+
query.setObjectForKey(ObjC.castRefToObject($.kCFBooleanTrue), ObjC.castRefToObject($.kSecReturnData));
|
|
18
|
+
query.setObjectForKey(ObjC.castRefToObject($.kSecMatchLimitOne), ObjC.castRefToObject($.kSecMatchLimit));
|
|
19
|
+
status = $.SecItemCopyMatching(query, result);
|
|
20
|
+
if (status !== 0) throw Error();
|
|
21
|
+
return JSON.stringify({ok: true, value: ObjC.unwrap($.NSString.alloc.initWithDataEncoding(ObjC.castRefToObject(result[0]), $.NSUTF8StringEncoding))});
|
|
22
|
+
}
|
|
23
|
+
if (request.op === 'put') {
|
|
24
|
+
if (!/^[a-f0-9]{64}$/.test(request.value)) throw Error();
|
|
25
|
+
query.setObjectForKey($(request.value).dataUsingEncoding($.NSUTF8StringEncoding), ObjC.castRefToObject($.kSecValueData));
|
|
26
|
+
query.setObjectForKey($('WorkTrust CLI credential encryption'), ObjC.castRefToObject($.kSecAttrLabel));
|
|
27
|
+
query.setObjectForKey(ObjC.castRefToObject($.kCFBooleanFalse), ObjC.castRefToObject($.kSecAttrSynchronizable));
|
|
28
|
+
status = $.SecItemAdd(query, null);
|
|
29
|
+
} else if (request.op === 'remove') { status = $.SecItemDelete(query); }
|
|
30
|
+
else throw Error();
|
|
31
|
+
if (status !== 0 && !(request.op === 'remove' && status === -25300)) throw Error();
|
|
32
|
+
return '{"ok":true}';
|
|
33
|
+
} catch (_) { return '{"ok":false}'; }
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
export const windowsCredentialScript = String.raw`
|
|
37
|
+
$ErrorActionPreference = 'Stop'
|
|
38
|
+
try {
|
|
39
|
+
$request = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
|
40
|
+
if ($request.id -cnotmatch '^[a-f0-9]{64}$' -or $request.service -cne 'io.worktrust.cli.credentials.v1') { throw 'invalid' }
|
|
41
|
+
Add-Type -TypeDefinition @'
|
|
42
|
+
using System;
|
|
43
|
+
using System.Runtime.InteropServices;
|
|
44
|
+
public static class WorkTrustVault {
|
|
45
|
+
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] public struct Credential {
|
|
46
|
+
public uint Flags; public uint Type; public string TargetName; public string Comment;
|
|
47
|
+
public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten;
|
|
48
|
+
public uint CredentialBlobSize; public IntPtr CredentialBlob; public uint Persist;
|
|
49
|
+
public uint AttributeCount; public IntPtr Attributes; public string TargetAlias; public string UserName;
|
|
50
|
+
}
|
|
51
|
+
[DllImport("advapi32.dll", EntryPoint="CredWriteW", CharSet=CharSet.Unicode, SetLastError=true)] public static extern bool Write(ref Credential value, uint flags);
|
|
52
|
+
[DllImport("advapi32.dll", EntryPoint="CredReadW", CharSet=CharSet.Unicode, SetLastError=true)] public static extern bool Read(string target, uint type, uint flags, out IntPtr value);
|
|
53
|
+
[DllImport("advapi32.dll", EntryPoint="CredDeleteW", CharSet=CharSet.Unicode, SetLastError=true)] public static extern bool Delete(string target, uint type, uint flags);
|
|
54
|
+
[DllImport("advapi32.dll", EntryPoint="CredFree")] public static extern void Free(IntPtr value);
|
|
55
|
+
}
|
|
56
|
+
'@
|
|
57
|
+
$target = $request.service + '/' + $request.id
|
|
58
|
+
if ($request.op -ceq 'get') {
|
|
59
|
+
$pointer = [IntPtr]::Zero
|
|
60
|
+
if (![WorkTrustVault]::Read($target, 1, 0, [ref]$pointer)) { throw 'unavailable' }
|
|
61
|
+
try {
|
|
62
|
+
$credential = [Runtime.InteropServices.Marshal]::PtrToStructure($pointer, [type][WorkTrustVault+Credential])
|
|
63
|
+
if ($credential.CredentialBlobSize -ne 128) { throw 'invalid' }
|
|
64
|
+
$value = [Runtime.InteropServices.Marshal]::PtrToStringUni($credential.CredentialBlob, 64)
|
|
65
|
+
@{ok=$true; value=$value} | ConvertTo-Json -Compress
|
|
66
|
+
} finally { [WorkTrustVault]::Free($pointer) }
|
|
67
|
+
} elseif ($request.op -ceq 'put') {
|
|
68
|
+
if ($request.value -cnotmatch '^[a-f0-9]{64}$') { throw 'invalid' }
|
|
69
|
+
$credential = New-Object WorkTrustVault+Credential
|
|
70
|
+
$credential.Type=1; $credential.TargetName=$target; $credential.UserName='WorkTrust CLI'
|
|
71
|
+
$credential.Persist=2; $credential.CredentialBlobSize=128
|
|
72
|
+
$credential.CredentialBlob=[Runtime.InteropServices.Marshal]::StringToCoTaskMemUni($request.value)
|
|
73
|
+
try { if (![WorkTrustVault]::Write([ref]$credential, 0)) { throw 'unavailable' } }
|
|
74
|
+
finally { [Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($credential.CredentialBlob) }
|
|
75
|
+
'{"ok":true}'
|
|
76
|
+
} elseif ($request.op -ceq 'remove') {
|
|
77
|
+
$removed = [WorkTrustVault]::Delete($target, 1, 0)
|
|
78
|
+
if (!$removed -and [Runtime.InteropServices.Marshal]::GetLastWin32Error() -ne 1168) { throw 'unavailable' }
|
|
79
|
+
'{"ok":true}'
|
|
80
|
+
} else { throw 'invalid' }
|
|
81
|
+
} catch { '{"ok":false}'; exit 1 }
|
|
82
|
+
`;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Native OS facilities only. Secrets travel over stdin/stdout, never arguments or log output.
|
|
2
|
+
* Only explicit protect-key writes a vault item. Runtime reads never request an unlock prompt.
|
|
3
|
+
*/
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { existsSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { userInfo } from 'node:os';
|
|
8
|
+
import { macKeychainScript, windowsCredentialScript } from './credential-vault-scripts.mjs';
|
|
9
|
+
const SERVICE = 'io.worktrust.cli.credentials.v1';
|
|
10
|
+
function invoke(executable, args, input) {
|
|
11
|
+
// Do not inherit credential-bearing WorkTrust environment variables into the OS helper.
|
|
12
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^(WORKTRUST_|NODE_|PYTHON|DYLD_|LD_)/.test(key)));
|
|
13
|
+
if (process.platform === "darwin") env.HOME = userInfo().homedir; // Keychain belongs to the OS user, not a caller-supplied HOME.
|
|
14
|
+
// Windows PowerShell compiles the small Credential Manager binding on every call; a cold start on a slow or busy
|
|
15
|
+
// machine passed eight seconds on native CI (2026-10-20), so it gets thirty there. Elsewhere eight remain.
|
|
16
|
+
const r = spawnSync(executable, args, { input, env, encoding: 'utf8', timeout: process.platform === 'win32' ? 30000 : 8000, maxBuffer: 32768, windowsHide: true });
|
|
17
|
+
if (r.error || r.status !== 0) throw Error('KEYSTORE_UNAVAILABLE');
|
|
18
|
+
return r.stdout.trim();
|
|
19
|
+
}
|
|
20
|
+
export function nativeKeyStore() {
|
|
21
|
+
const platform = process.platform;
|
|
22
|
+
const name = platform === 'darwin' ? 'macos-keychain' : platform === 'win32' ? 'windows-credential-manager' : platform === 'linux' ? 'linux-secret-service' : 'unsupported';
|
|
23
|
+
function call(op, id, value) {
|
|
24
|
+
if (!/^[a-f0-9]{64}$/.test(id) || (value !== undefined && !/^[a-f0-9]{64}$/.test(value))) throw Error('KEYSTORE_INVALID_REQUEST');
|
|
25
|
+
if (platform === 'darwin' || platform === 'win32') {
|
|
26
|
+
const executable = platform === 'darwin' ? '/usr/bin/osascript' : join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
|
|
27
|
+
const args = platform === 'darwin' ? ['-l', 'JavaScript', '-e', macKeychainScript] : ['-NoLogo', '-NoProfile', '-NonInteractive', '-Command', windowsCredentialScript];
|
|
28
|
+
const out = invoke(executable, args, JSON.stringify({ op, id, value, service: SERVICE }));
|
|
29
|
+
try { const reply = JSON.parse(out); if (reply.ok === true) return reply.value ?? null; } catch { /* never log OS error payloads */ }
|
|
30
|
+
throw Error('KEYSTORE_UNAVAILABLE');
|
|
31
|
+
}
|
|
32
|
+
if (platform === 'linux') {
|
|
33
|
+
const executable = '/usr/bin/secret-tool';
|
|
34
|
+
if (!existsSync(executable)) throw Error('KEYSTORE_UNAVAILABLE');
|
|
35
|
+
const attributes = ['service', SERVICE, 'account', id];
|
|
36
|
+
if (op === 'get') {
|
|
37
|
+
// `lookup` can unlock and prompt. `search` without --unlock never does.
|
|
38
|
+
const out = invoke(executable, ['search', '--all', ...attributes], '');
|
|
39
|
+
const secrets = [...out.matchAll(/^secret = ([a-f0-9]{64})$/gm)];
|
|
40
|
+
if (secrets.length !== 1) throw Error('KEYSTORE_UNAVAILABLE');
|
|
41
|
+
return secrets[0][1];
|
|
42
|
+
}
|
|
43
|
+
if (op === 'put') return invoke(executable, ['store', '--label=WorkTrust CLI credential encryption', ...attributes], value);
|
|
44
|
+
if (op === 'remove') return invoke(executable, ['clear', ...attributes], '');
|
|
45
|
+
}
|
|
46
|
+
throw Error('KEYSTORE_UNAVAILABLE');
|
|
47
|
+
}
|
|
48
|
+
return { name, get: id => call('get', id), put: (id, value) => call('put', id, value), remove: id => call('remove', id) };
|
|
49
|
+
}
|
package/engine-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","history-outbox.mjs":"1bdca17b807c76e4a8e7bf42c6f07e12e8ae8e4466417cafdd26b1f58bf178a5","log-session.mjs":"c5e6e4d44a85768f21c25945b8630f31306ec2665193886870c1010ef6bf3c26","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","history-outbox.mjs":"1bdca17b807c76e4a8e7bf42c6f07e12e8ae8e4466417cafdd26b1f58bf178a5","log-session.mjs":"c5e6e4d44a85768f21c25945b8630f31306ec2665193886870c1010ef6bf3c26","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"3e369083ba43bcda2fa0622fd526aa64fcf8ad66e7b6e8f23821752c4d47ad27","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"6ecfbf44f001dd433512b26736031ebc855b154e2bb0a401e2512b43623cd9cd","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"78260b4615226ac901211094a908e7535e2d8b8ff18856d907a817f3cb5a1e08"},"format":"worktrust-package/1","kind":"engine","version":"0.10.26"},"signature":"5pk8vqS79gPJPO03dpO7dV4HLSbFeeD-kk2WUy_-3RUTYznr4o33rmkH5CGlO9nR6eWlITxWg3Mz6nFBI7leBA"}
|
package/package-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"c6f5280c5bf81a14db4bdc282218fb005706e92dd9a9170c0e727716ee91685a","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"3096ed1693974a90e1f4f59bf01c9559d94a7941d933e36fb81d3995a97f25c1","README.md":"997cb24638d7fda2d8961203c4e603de24cdb587968198644185140267753607","SECURITY.md":"f43e38504c477dc8ccdeed28cb2b244b6db3c816e962975645c250dde44cc86b","chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","engine-release.json":"feee10195c45a0e9083df08683542f6614c1897ff4ee05fb364da9dec463b66c","history-outbox.mjs":"1bdca17b807c76e4a8e7bf42c6f07e12e8ae8e4466417cafdd26b1f58bf178a5","log-session.mjs":"c5e6e4d44a85768f21c25945b8630f31306ec2665193886870c1010ef6bf3c26","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"6e09593a7aff4ad236eca7553c532635e30008a2a31ed11118fbeeb4ecadf895","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"3e369083ba43bcda2fa0622fd526aa64fcf8ad66e7b6e8f23821752c4d47ad27","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"6ecfbf44f001dd433512b26736031ebc855b154e2bb0a401e2512b43623cd9cd","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"78260b4615226ac901211094a908e7535e2d8b8ff18856d907a817f3cb5a1e08"},"format":"worktrust-package/1","kind":"npm","version":"0.10.26"},"signature":"q5cJvi49xrDpbczLrs3W4GQ9pW4By9E0FkoR3yDzkLEi8672crlnZ7THHLFZEjgP9skpCY7liNsf2ENL1FpLDQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.26",
|
|
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": {
|
|
@@ -34,7 +34,10 @@
|
|
|
34
34
|
"worktrust-launch.mjs",
|
|
35
35
|
"engine-release.json",
|
|
36
36
|
"package-release.json",
|
|
37
|
-
"history-outbox.mjs"
|
|
37
|
+
"history-outbox.mjs",
|
|
38
|
+
"credential-store.mjs",
|
|
39
|
+
"credential-vault.mjs",
|
|
40
|
+
"credential-vault-scripts.mjs"
|
|
38
41
|
],
|
|
39
42
|
"engines": {
|
|
40
43
|
"node": ">=18"
|
package/preserve.mjs
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* (`prev`, `hash`), appended and never rewritten; each day has proofs/<day>.json, its root, signed with the device key
|
|
24
24
|
* (~/.worktrust/key.json) when there is one. Today waits for the next run. Nothing leaves this computer.
|
|
25
25
|
*/
|
|
26
|
+
import { readDeviceSigningKey } from "./credential-store.mjs";
|
|
26
27
|
import { moduleArgs, moduleExecutable, readPrivateFile, createPrivateFile } from "./package-integrity.mjs";
|
|
27
28
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
28
29
|
import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes, sign, verify } from "node:crypto";
|
|
@@ -190,13 +191,12 @@ function archiveSalt() {
|
|
|
190
191
|
try { const made = randomBytes(32).toString("hex"); createPrivateFile(file, `${made}\n`); return made; } catch { try { return readPrivateFile(file)?.trim() ?? null; } catch { return null; } }
|
|
191
192
|
}
|
|
192
193
|
/** The device key, when this computer is coupled: its private half signs, its public half goes into the proof. */
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return { privateKey, publicX: createPublicKey(privateKey).export({ format: "jwk" }).x, kind: "device" };
|
|
198
|
-
} catch { return null; }
|
|
194
|
+
let cachedDeviceKey;
|
|
195
|
+
function deviceKey(required = false) {
|
|
196
|
+
try { if (cachedDeviceKey === undefined) cachedDeviceKey = readDeviceSigningKey(home(".worktrust", "key.json")); return cachedDeviceKey; }
|
|
197
|
+
catch (error) { if (required) throw error; return null; }
|
|
199
198
|
}
|
|
199
|
+
|
|
200
200
|
/**
|
|
201
201
|
* THE LOCAL ARCHIVE KEY (owner, 2026-10-10): a computer that is not coupled still signs its archive, with an Ed25519 key made
|
|
202
202
|
* here (~/.worktrust/archive-key.json, mode 600, folder 700), so a day's root can be told from an edit and the chain stays one
|
|
@@ -308,6 +308,9 @@ function archive(dir) {
|
|
|
308
308
|
fresh.push(line);
|
|
309
309
|
}
|
|
310
310
|
fresh.sort((a, b) => a.started_at.localeCompare(b.started_at) || a.client.localeCompare(b.client) || a.stretch_ref.localeCompare(b.stretch_ref));
|
|
311
|
+
let key;
|
|
312
|
+
try { key = deviceKey(true) ?? archiveKey(true); }
|
|
313
|
+
catch { say(" Signing key unavailable. Unlock your OS vault and retry. No archive data was changed."); process.exitCode = 1; return; }
|
|
311
314
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
312
315
|
let prev = existing.lines.at(-1)?.hash ?? null, seq = existing.lines.length;
|
|
313
316
|
const all = [...existing.lines];
|
|
@@ -322,9 +325,7 @@ function archive(dir) {
|
|
|
322
325
|
// A day that gained lines gets its root again over all of its lines; the lines themselves are never rewritten.
|
|
323
326
|
// THIS KEY SIGNS ONLY ITS OWN LINES (0.6.18, audit S7): a day is signed when every earlier line of it was already under
|
|
324
327
|
// this key's signature (or there were none); a day that came into the folder from elsewhere keeps an unsigned root.
|
|
325
|
-
//
|
|
326
|
-
// there is none. A day or a manifest either of this computer's keys sealed is this computer's to seal again.
|
|
327
|
-
const key = deviceKey() ?? archiveKey(true);
|
|
328
|
+
// Either of this computer's keys may reseal its own days; the signer was resolved before mutation.
|
|
328
329
|
const mineX = new Set(ownKeys().map((own) => own.publicX));
|
|
329
330
|
const ours = (document) => !document || (key && typeof document.signature === "string" && mineX.has(document.public_key));
|
|
330
331
|
mkdirSync(join(dir, "proofs"), { recursive: true });
|
package/worktrust.mjs
CHANGED
|
@@ -39,15 +39,12 @@
|
|
|
39
39
|
* with its secret, can exchange for the key. Nothing is typed, and a link forwarded to someone else
|
|
40
40
|
* approves nothing they can collect. Without a browser (`--device`, or over SSH) the terminal shows
|
|
41
41
|
* a code that you type yourself at app.worktrust.io/connect/computer.
|
|
42
|
-
* WHERE THE KEY LIVES.
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* WorkTrust, the private half stays in the key file. Every call the bridge, the hook and
|
|
49
|
-
* the counter make carries a fresh signature (`WorkTrust-Proof`), and WorkTrust refuses a call
|
|
50
|
-
* 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.
|
|
51
48
|
*
|
|
52
49
|
* THE KEY RENEWS ITSELF EVERY WEEK. The bridge or the hook makes a new secret on this computer, sends
|
|
53
50
|
* only its hash, signed with the current key, and stores the new one; a copy of last week's key stops
|
|
@@ -78,12 +75,12 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
|
|
|
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`);
|
|
@@ -274,7 +271,7 @@ const KEY_FILE = join(HOME_DIR, "key.json");
|
|
|
274
271
|
const STABLE_FILE = join(HOME_DIR, "worktrust.mjs");
|
|
275
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. */
|
|
@@ -303,29 +300,22 @@ function saveStableEntry() {
|
|
|
303
300
|
finally { try { rmSync(temporary); } catch { /* already renamed */ } }
|
|
304
301
|
}
|
|
305
302
|
|
|
306
|
-
/**
|
|
307
|
-
*
|
|
308
|
-
* private key and when it was last renewed. NO KEYCHAIN (owner, 2026-10-03): a keychain tool can ask
|
|
309
|
-
* the person to "reset" a keychain it cannot find, which deletes every password on the machine, and
|
|
310
|
-
* many will not let a tool near their keychain at all. This file is never written into an AI app's
|
|
311
|
-
* 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.
|
|
312
305
|
*/
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
},
|
|
327
|
-
erase() { try { rmSync(KEY_FILE); } catch { /* gone */ } },
|
|
328
|
-
};
|
|
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
|
+
}
|
|
329
319
|
|
|
330
320
|
/**
|
|
331
321
|
* WHICH ACCOUNT THIS COMPUTER LAST FED, after `disconnect` (owner, 2026-10-04). The key file goes; this
|
|
@@ -487,6 +477,9 @@ async function bridge() {
|
|
|
487
477
|
let message;
|
|
488
478
|
try { message = JSON.parse(line); } catch { continue; }
|
|
489
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; }
|
|
490
483
|
if (!key) { if (message.id !== undefined) answer(message.id, "WorkTrust is not connected on this computer: run `npx worktrust connect`."); continue; }
|
|
491
484
|
try {
|
|
492
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 });
|
|
@@ -602,6 +595,7 @@ async function update() {
|
|
|
602
595
|
}
|
|
603
596
|
|
|
604
597
|
async function connect() {
|
|
598
|
+
if (has("direct") && keyStore.protected()) fail("Protected credentials use the local bridge; --direct would expose them in app settings.");
|
|
605
599
|
const host = (flag("name") ?? hostname()).replace(/\.local$/i, "").slice(0, 64);
|
|
606
600
|
say();
|
|
607
601
|
say(` WorkTrust · connect ${host} (${OS_NAME})`);
|
|
@@ -1032,7 +1026,7 @@ async function disconnect() {
|
|
|
1032
1026
|
const plan = await run(paths["setup-mcp.mjs"], ["--remove"], PLACEHOLDER, true);
|
|
1033
1027
|
say(" 1. The WorkTrust door comes out of every AI app here:");
|
|
1034
1028
|
for (const line of planLines(plan.out)) say(line);
|
|
1035
|
-
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)");
|
|
1036
1030
|
say(" but for one note of which account this computer fed (masked), so a later coupling by another account starts clean.");
|
|
1037
1031
|
say(" 3. The key itself stays valid until you revoke it: WorkTrust → Sources → Devices → this computer → Revoke.");
|
|
1038
1032
|
say();
|
|
@@ -1104,6 +1098,7 @@ async function status() {
|
|
|
1104
1098
|
const door = Object.entries(servers).find(([name, server]) => /worktrust/i.test(`${name} ${server?.url ?? ""} ${(server?.args ?? []).join(" ")}`));
|
|
1105
1099
|
say(door ? ` Claude Code: coupled (${door[1].url ?? "through the local bridge"})` : " Claude Code: not coupled. Run `npx worktrust connect`.");
|
|
1106
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"}`);
|
|
1107
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)");
|
|
1108
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)");
|
|
1109
1104
|
let hook = false;
|
|
@@ -1188,6 +1183,7 @@ function help() {
|
|
|
1188
1183
|
say(" days this computer's own sessions lack, reconstructed, never verified hours (asks first)");
|
|
1189
1184
|
say(" worktrust disconnect take WorkTrust out of every AI app here (asks first)");
|
|
1190
1185
|
say(" worktrust status what is coupled here");
|
|
1186
|
+
say(" worktrust protect-key after update: move credential protection into the OS vault (asks first)");
|
|
1191
1187
|
say(" worktrust orchestration report --file recording.jsonl inspect local agent metadata; sends nothing");
|
|
1192
1188
|
say(" worktrust mod the WorkTrust mod for Claude Code: what it counts, and whether it is on");
|
|
1193
1189
|
say(" install turn it on: counts permission answers, effort levels, context peaks and subagents (asks first)");
|
|
@@ -1206,10 +1202,10 @@ function help() {
|
|
|
1206
1202
|
// before anything is read or written, --yes included. The hook and the MCP bridge are started by the agent's client
|
|
1207
1203
|
// itself and stay as they are; `status` only reads.
|
|
1208
1204
|
async function main() {
|
|
1209
|
-
if (!moduleArgs || !moduleExecutable) fail("Use the complete WorkTrust package from npm/PyPI or the signed preservation kit; individual scripts cannot run.");
|
|
1205
|
+
if (!moduleArgs || !moduleExecutable || !createCredentialStore) fail("Use the complete WorkTrust package from npm/PyPI or the signed preservation kit; individual scripts cannot run.");
|
|
1210
1206
|
if (Number(process.versions.node.split(".")[0]) < 18) fail("needs Node 18 or later (fetch is built in from 18).");
|
|
1211
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"];
|
|
1212
|
-
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"]);
|
|
1213
1209
|
const agentShell = AGENT_ENV.find((name) => process.env[name] && process.env[name] !== "0");
|
|
1214
1210
|
if (agentShell && PERSON_ONLY.has(command)) {
|
|
1215
1211
|
say();
|
|
@@ -1243,7 +1239,7 @@ if (await relayToNewest()) return;
|
|
|
1243
1239
|
|
|
1244
1240
|
if (!["version", "help", "preserve"].includes(command)) {
|
|
1245
1241
|
try { keyStore.load(); }
|
|
1246
|
-
catch { fail("The local WorkTrust key file is unsafe or damaged. Upload stopped.
|
|
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."); }
|
|
1247
1243
|
}
|
|
1248
1244
|
if (command === "version") say(CLI_VERSION);
|
|
1249
1245
|
else if (command === "default") { if (keyStore.load()) await again(); else await connect(); }
|
|
@@ -1251,6 +1247,7 @@ else if (command === "mcp") await bridge();
|
|
|
1251
1247
|
else if (command === "hook") await hook();
|
|
1252
1248
|
else if (command === "connect") await connect();
|
|
1253
1249
|
else if (command === "update") await update();
|
|
1250
|
+
else if (command === "protect-key") await protectKey();
|
|
1254
1251
|
else if (command === "history") await history();
|
|
1255
1252
|
// NOT FROM THE TERMINAL (owner, 2026-10-04): an ACCOUNT is connected under Sources in the app, where the
|
|
1256
1253
|
// page also says what is already connected: Claude and ChatGPT on the web and their earlier
|