fullcourtdefense-cli 1.35.10 → 1.36.2

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.
Files changed (74) hide show
  1. package/dist/actionPolicyEngine.d.ts +24 -0
  2. package/dist/actionPolicyEngine.js +79 -19
  3. package/dist/approvalPrompt.d.ts +15 -0
  4. package/dist/approvalPrompt.js +157 -20
  5. package/dist/askDialog.d.ts +2 -0
  6. package/dist/askDialog.js +15 -1
  7. package/dist/askHeader.d.ts +81 -0
  8. package/dist/askHeader.js +573 -0
  9. package/dist/blockExplanation.d.ts +9 -0
  10. package/dist/blockExplanation.js +14 -0
  11. package/dist/callerEnv.d.ts +1 -1
  12. package/dist/callerEnv.js +14 -0
  13. package/dist/cloudGrant.d.ts +46 -0
  14. package/dist/cloudGrant.js +420 -0
  15. package/dist/cloudGrantTools.d.ts +97 -0
  16. package/dist/cloudGrantTools.js +1112 -0
  17. package/dist/commandNarrative.d.ts +8 -0
  18. package/dist/commandNarrative.js +222 -49
  19. package/dist/commands/cmdGuard.js +3 -1
  20. package/dist/commands/daemon.js +56 -2
  21. package/dist/commands/deterministicGuard.d.ts +70 -4
  22. package/dist/commands/deterministicGuard.js +494 -63
  23. package/dist/commands/discover.js +50 -16
  24. package/dist/commands/discoverAgentFiles.d.ts +2 -0
  25. package/dist/commands/discoverAgentFiles.js +1 -0
  26. package/dist/commands/discoverPaths.d.ts +4 -0
  27. package/dist/commands/discoverPaths.js +19 -1
  28. package/dist/commands/discoverProjectRoots.d.ts +72 -0
  29. package/dist/commands/discoverProjectRoots.js +327 -0
  30. package/dist/commands/discoverProxy.d.ts +1 -1
  31. package/dist/commands/discoverProxy.js +1 -1
  32. package/dist/commands/discoverSecrets.d.ts +44 -0
  33. package/dist/commands/discoverSecrets.js +158 -14
  34. package/dist/commands/hook.js +25 -10
  35. package/dist/commands/knownMcpServers.d.ts +8 -2
  36. package/dist/commands/knownMcpServers.js +33 -2
  37. package/dist/commands/mcpGateway.js +9 -7
  38. package/dist/commands/posixShellGuard.js +1 -1
  39. package/dist/commands/shellGuard.js +86 -26
  40. package/dist/commands/uninstallAll.d.ts +1 -7
  41. package/dist/commands/uninstallAll.js +6 -45
  42. package/dist/commands/watchdog.js +17 -3
  43. package/dist/config.d.ts +1 -1
  44. package/dist/config.js +3 -3
  45. package/dist/credentialGrant.d.ts +48 -0
  46. package/dist/credentialGrant.js +29 -18
  47. package/dist/credentialStore.js +1 -1
  48. package/dist/devConfirm.d.ts +51 -3
  49. package/dist/devConfirm.js +226 -33
  50. package/dist/distress.d.ts +2 -0
  51. package/dist/distress.js +2 -0
  52. package/dist/grantTargets.d.ts +21 -0
  53. package/dist/grantTargets.js +235 -0
  54. package/dist/localSafetySnapshot.js +2 -0
  55. package/dist/msiProductCode.d.ts +10 -0
  56. package/dist/msiProductCode.js +124 -0
  57. package/dist/notify.js +1 -0
  58. package/dist/selfTest.d.ts +1 -1
  59. package/dist/selfTest.js +1 -1
  60. package/dist/selfUpdate.d.ts +108 -0
  61. package/dist/selfUpdate.js +353 -18
  62. package/dist/shellAst.d.ts +2 -0
  63. package/dist/shellAst.js +7 -1
  64. package/dist/shellAstLoader.js +14 -1
  65. package/dist/telemetry.d.ts +3 -0
  66. package/dist/telemetry.js +1 -0
  67. package/dist/version.json +1 -1
  68. package/installer/macos/guardian/ai.fullcourtdefense.guardian.plist +19 -0
  69. package/installer/macos/guardian/fcd-guardian.sh +590 -0
  70. package/installer/macos/guardian/install-guardian.sh +32 -0
  71. package/installer/macos/guardian/uninstall-guardian.sh +12 -0
  72. package/installer/windows/README.md +88 -0
  73. package/installer/windows/rescue/FullCourtDefense-Rescue.ps1 +229 -0
  74. package/package.json +11 -1
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throughRunner = throughRunner;
4
+ exports.unreadTarget = unreadTarget;
5
+ exports.unreadNoun = unreadNoun;
6
+ /**
7
+ * Program uses that act on something outside the machine whose target this
8
+ * CLI does not read yet: a cloud account, a remote docker host or registry, a
9
+ * database, an SSH host, a package registry or git remote, a secret store, or
10
+ * a web API that is sent data. Each such use adds `<label>|?|?` to the grant's
11
+ * cloud entries (`cloudGrant.ts`), so "Always allow" is not offered for it and
12
+ * a grant recorded before the entry existed does not cover it.
13
+ *
14
+ * Structural only: the program a use runs (`scanShellPrograms`), its first
15
+ * command words and its flags — never a word search over the line. Package
16
+ * runners (`npx prisma …`, `pnpm dlx …`, `python -m twine …`) are looked
17
+ * through to the tool they run. `--version` / `help` touch nothing remote.
18
+ */
19
+ const credentialGrant_1 = require("./credentialGrant");
20
+ /** Programs that always act on a remote target (outside their local-only subcommands). */
21
+ const ALWAYS_REMOTE = {
22
+ // cloud / infrastructure
23
+ 'aws-vault': 'environment', gsutil: 'environment', bq: 'environment', oci: 'environment', doctl: 'environment',
24
+ firebase: 'environment', supabase: 'environment', vercel: 'environment', netlify: 'environment', heroku: 'environment',
25
+ fly: 'environment', flyctl: 'environment', wrangler: 'environment', eksctl: 'environment', pulumi: 'environment',
26
+ cdk: 'environment', serverless: 'environment',
27
+ sls: 'environment', sam: 'environment', argocd: 'environment',
28
+ // databases
29
+ mongosh: 'database', mongo: 'database', 'redis-cli': 'database',
30
+ sqlcmd: 'database', cqlsh: 'database', flyway: 'database', liquibase: 'database',
31
+ // secret stores
32
+ vault: 'secret', op: 'secret', doppler: 'secret', infisical: 'secret',
33
+ };
34
+ /** First command words that only print help / version / format files locally. */
35
+ const LOCAL_SUBCOMMANDS = new Set(['version', 'help', 'completion', 'fmt', 'validate']);
36
+ const LOCAL_ONLY_FLAGS = new Set(['--version', '-version', '-v', '-V', '--help', '-help', '-h', '-?']);
37
+ const DOCKER_LIKE = new Set(['docker', 'podman', 'nerdctl']);
38
+ /** Global options that point docker at another daemon. */
39
+ const DOCKER_REMOTE_FLAGS = new Set(['-H', '--host', '--context', '-c', '--url', '--connection', '--remote', '-r']);
40
+ const DOCKER_VALUED_GLOBALS = new Set(['-H', '--host', '--context', '-c', '--config', '-l', '--log-level', '--tlscacert', '--tlscert', '--tlskey', '--url', '--connection', '--identity', '--namespace', '-n', '--address', '-a']);
41
+ const PUBLISHERS = new Set(['npm', 'pnpm', 'yarn', 'bun']);
42
+ const WEB_SENDERS = new Set(['curl', 'wget', 'invoke-restmethod', 'irm', 'invoke-webrequest', 'iwr', 'http', 'https', 'xh']);
43
+ const WRITE_METHODS = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
44
+ /** Leading non-flag words (command path), skipping the values of the given flags. */
45
+ function commandWords(argv, valued = new Set(), max = 3) {
46
+ const out = [];
47
+ for (let k = 0; k < argv.length && out.length < max; k++) {
48
+ const bare = (0, credentialGrant_1.unquote)(argv[k]);
49
+ if (bare === '--')
50
+ continue;
51
+ if (bare.startsWith('-')) {
52
+ if (valued.has(bare) && !bare.includes('='))
53
+ k++;
54
+ continue;
55
+ }
56
+ out.push(bare.toLowerCase());
57
+ }
58
+ return out;
59
+ }
60
+ function flagPresent(argv, names) {
61
+ return argv.some(w => names.has((0, credentialGrant_1.unquote)(w).split('=')[0]));
62
+ }
63
+ /** A global option before the subcommand that points docker at another daemon (`-H tcp://…`, `--context prod`). */
64
+ function dockerRemoteGlobal(argv) {
65
+ for (let k = 0; k < argv.length; k++) {
66
+ const bare = (0, credentialGrant_1.unquote)(argv[k]);
67
+ if (!bare.startsWith('-'))
68
+ return false;
69
+ const flag = bare.split('=')[0];
70
+ if (DOCKER_REMOTE_FLAGS.has(flag))
71
+ return true;
72
+ if (DOCKER_VALUED_GLOBALS.has(flag) && !bare.includes('='))
73
+ k++;
74
+ }
75
+ return false;
76
+ }
77
+ /** Nothing but a version / help request. */
78
+ function localOnly(argv) {
79
+ const words = commandWords(argv, new Set(), 1);
80
+ if (words.length)
81
+ return LOCAL_SUBCOMMANDS.has(words[0]);
82
+ return argv.length > 0 && argv.every(w => LOCAL_ONLY_FLAGS.has((0, credentialGrant_1.unquote)(w)));
83
+ }
84
+ /** `npx prisma …` -> `prisma …`; `python -m twine …` -> `twine …`; else the use itself. */
85
+ function throughRunner(name, argv) {
86
+ const words = argv.map(w => (0, credentialGrant_1.unquote)(w));
87
+ const nextTool = (from) => {
88
+ for (let k = from; k < words.length; k++) {
89
+ if (words[k] === '--')
90
+ continue;
91
+ if (words[k].startsWith('-'))
92
+ continue;
93
+ return { name: words[k].toLowerCase().replace(/^.*[\\/]/, '').replace(/@[^@/]*$/, ''), argv: argv.slice(k + 1) };
94
+ }
95
+ return undefined;
96
+ };
97
+ if (name === 'npx' || name === 'bunx')
98
+ return nextTool(0) || { name, argv: [...argv] };
99
+ if ((name === 'pnpm' || name === 'yarn' || name === 'npm' || name === 'bun') && /^(?:dlx|exec|x)$/.test((words.find(w => !w.startsWith('-')) || '').toLowerCase())) {
100
+ return nextTool(words.findIndex(w => !w.startsWith('-')) + 1) || { name, argv: [...argv] };
101
+ }
102
+ if (/^(?:python\d*(?:\.\d+)?|py)$/.test(name)) {
103
+ const m = words.indexOf('-m');
104
+ if (m >= 0 && words[m + 1])
105
+ return { name: words[m + 1].toLowerCase(), argv: argv.slice(m + 2) };
106
+ }
107
+ return { name, argv: [...argv] };
108
+ }
109
+ /** The write method a web sender uses, or undefined for a read. */
110
+ function webWriteMethod(name, argv) {
111
+ const words = argv.map(w => (0, credentialGrant_1.unquote)(w));
112
+ if (name === 'curl') {
113
+ let sends = false;
114
+ for (let k = 0; k < words.length; k++) {
115
+ const w = words[k];
116
+ let request;
117
+ if (w === '--request')
118
+ request = words[k + 1];
119
+ else if (w.startsWith('--request='))
120
+ request = w.slice(10);
121
+ else if (/^--(?:data(?:-raw|-binary|-urlencode|-ascii)?|json|form(?:-string)?|upload-file)(?:=|$)/.test(w))
122
+ sends = true;
123
+ else if (/^-[A-Za-z]/.test(w)) {
124
+ // A short-flag cluster (`-sSX POST`, `-sXPOST`, `-sd a=1`): a valued letter takes the rest or the next word.
125
+ const letters = w.slice(1);
126
+ for (let c = 0; c < letters.length; c++) {
127
+ if (letters[c] === 'X') {
128
+ request = letters.slice(c + 1) || words[k + 1];
129
+ break;
130
+ }
131
+ if ('dFT'.includes(letters[c])) {
132
+ sends = true;
133
+ break;
134
+ }
135
+ if ('HowuAebcmrzDEYyCQPtU'.includes(letters[c]))
136
+ break;
137
+ }
138
+ }
139
+ if (request !== undefined) {
140
+ const method = request.replace(/^["']|["']$/g, '').toUpperCase();
141
+ return WRITE_METHODS.has(method) ? method : method === 'GET' || method === 'HEAD' ? undefined : 'SEND';
142
+ }
143
+ }
144
+ return sends ? 'POST' : undefined;
145
+ }
146
+ if (name === 'wget') {
147
+ const method = words.find(w => w.startsWith('--method='))?.slice(9) ?? (words.indexOf('--method') >= 0 ? words[words.indexOf('--method') + 1] : undefined);
148
+ if (method)
149
+ return WRITE_METHODS.has(method.toUpperCase()) ? method.toUpperCase() : undefined;
150
+ return words.some(w => /^--(?:post|body)-(?:data|file)(?:=|$)/.test(w)) ? 'POST' : undefined;
151
+ }
152
+ if (name === 'http' || name === 'https' || name === 'xh') {
153
+ const first = words.find(w => !w.startsWith('-'));
154
+ if (first && WRITE_METHODS.has(first.toUpperCase()) && first === first.toUpperCase())
155
+ return first;
156
+ // Request items after the URL (`a=1`, `a:=1`, `f@file`) make httpie send a body.
157
+ const positional = words.filter(w => !w.startsWith('-'));
158
+ return positional.slice(1).some(w => /^[^:=@/]+(?:=|:=|@|=@|:=@)/.test(w)) ? 'POST' : undefined;
159
+ }
160
+ // Invoke-RestMethod / Invoke-WebRequest
161
+ for (let k = 0; k < words.length; k++) {
162
+ const param = words[k].match(/^-(method|custommethod)(?::(.*))?$/i);
163
+ if (param) {
164
+ const value = (param[2] ?? words[k + 1] ?? '').replace(/^["']|["']$/g, '').toUpperCase();
165
+ return WRITE_METHODS.has(value) ? value : value === 'GET' || value === 'HEAD' || value === 'OPTIONS' ? undefined : 'SEND';
166
+ }
167
+ }
168
+ return words.some(w => /^-(?:body|infile|form)(?::|$)/i.test(w)) ? 'POST' : undefined;
169
+ }
170
+ /**
171
+ * The unread remote target of one program use, or undefined when the use is
172
+ * local or already read elsewhere (gcloud, aws, kube tools). `env` is the
173
+ * caller's environment (`DOCKER_HOST`); `destinationBound` = the grant already
174
+ * binds where data goes (a credential binding or the rule's destination host),
175
+ * so a web write is not refused for an unknown destination.
176
+ */
177
+ function unreadTarget(programName, programArgv, env, destinationBound) {
178
+ const { name, argv } = throughRunner(programName, programArgv);
179
+ const always = ALWAYS_REMOTE[name];
180
+ if (always)
181
+ return localOnly(argv) ? undefined : { label: name, noun: always };
182
+ const words = commandWords(argv, name === 'git' ? new Set(['-C', '-c', '--git-dir', '--work-tree', '--namespace']) : DOCKER_LIKE.has(name) ? DOCKER_VALUED_GLOBALS : new Set());
183
+ // git push is read by `gitPushUse` (remote + branch).
184
+ if (name === 'git')
185
+ return undefined;
186
+ if (PUBLISHERS.has(name)) {
187
+ if (words[0] === 'publish' || (name === 'yarn' && words[0] === 'npm' && words[1] === 'publish'))
188
+ return { label: `${name} publish`, noun: 'destination' };
189
+ return undefined;
190
+ }
191
+ if (name === 'twine')
192
+ return words[0] === 'upload' ? { label: 'twine upload', noun: 'destination' } : undefined;
193
+ if (name === 'gh')
194
+ return words[0] === 'release' && (words[1] === 'create' || words[1] === 'upload') ? { label: 'gh release', noun: 'destination' } : undefined;
195
+ if (name === 'prisma')
196
+ return (words[0] === 'migrate' && (words[1] === 'deploy' || words[1] === 'reset')) ? { label: 'prisma migrate', noun: 'database' } : undefined;
197
+ if (name === 'dbt')
198
+ return /^(?:run|seed|snapshot|build)$/.test(words[0] || '') ? { label: 'dbt', noun: 'database' } : undefined;
199
+ // ssh / scp / sftp / rsync are read by `remoteUses` (host).
200
+ if (name === 'rsync' || name === 'ssh' || name === 'scp' || name === 'sftp')
201
+ return undefined;
202
+ if (DOCKER_LIKE.has(name)) {
203
+ if (words[0] === 'login' || (words[0] === 'registry' && words[1] === 'login'))
204
+ return { label: `${name} login`, noun: 'registry' };
205
+ if (words.includes('push') && words.indexOf('push') <= 1)
206
+ return { label: `${name} push`, noun: 'registry' };
207
+ if (flagPresent(argv, new Set(['--push'])))
208
+ return { label: `${name} push`, noun: 'registry' };
209
+ if (dockerRemoteGlobal(argv) || (words[0] === 'context' && words[1] === 'use'))
210
+ return { label: name, noun: 'host' };
211
+ if ((env.DOCKER_HOST || '').trim() || ((env.DOCKER_CONTEXT || '').trim() && !/^(?:default|desktop-linux|desktop-windows)$/.test((env.DOCKER_CONTEXT || '').trim())))
212
+ return { label: name, noun: 'host' };
213
+ return undefined;
214
+ }
215
+ if (WEB_SENDERS.has(name) && !destinationBound) {
216
+ const method = webWriteMethod(name, argv);
217
+ return method ? { label: `${name} ${method}`, noun: 'destination' } : undefined;
218
+ }
219
+ return undefined;
220
+ }
221
+ /** The noun of an unread entry label (`git push` -> destination). */
222
+ function unreadNoun(label) {
223
+ const [name, sub] = label.split(' ');
224
+ if (ALWAYS_REMOTE[name])
225
+ return ALWAYS_REMOTE[name];
226
+ if (sub === 'login' || (sub === 'push' && DOCKER_LIKE.has(name)))
227
+ return 'registry';
228
+ if (DOCKER_LIKE.has(name) && !sub)
229
+ return 'host';
230
+ if (name === 'rsync')
231
+ return 'host';
232
+ if (name === 'dbt' || name === 'prisma')
233
+ return 'database';
234
+ return 'destination';
235
+ }
@@ -44,6 +44,7 @@ const os = __importStar(require("os"));
44
44
  const path = __importStar(require("path"));
45
45
  const deterministicGuard_1 = require("./commands/deterministicGuard");
46
46
  const honeypot_1 = require("./honeypot");
47
+ const msiProductCode_1 = require("./msiProductCode");
47
48
  const distress_1 = require("./distress");
48
49
  const CACHE_TTL_MS = 60_000;
49
50
  const CACHE_DIR = path.join(os.homedir(), '.fullcourtdefense');
@@ -277,6 +278,7 @@ function snapshotToScanOptions(snapshot, extra = {}) {
277
278
  // surface (hooks, MCP gateway, desktop chat guard) gets honeypot
278
279
  // detection through this single seam.
279
280
  honeypotPaths: (0, honeypot_1.getHoneypotPaths)(),
281
+ fcdProductCodes: (0, msiProductCode_1.getRecordedMsiProductCodes)(),
280
282
  ...extra,
281
283
  };
282
284
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Product code of the installed FullCourtDefense MSI, from the registry
3
+ * uninstall hive (both 64-bit and WOW6432Node views). Undefined on npm
4
+ * installs or when the MSI entry is missing.
5
+ */
6
+ export declare function parseMsiProductCodeFromRegOutput(output: string): string | undefined;
7
+ export declare function findMsiProductCode(): string | undefined;
8
+ export declare function getRecordedMsiProductCodes(file?: string): string[];
9
+ /** Puts `productCode` first in the recorded list. Returns false when nothing was written. */
10
+ export declare function recordMsiProductCode(productCode: string | undefined, file?: string): boolean;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseMsiProductCodeFromRegOutput = parseMsiProductCodeFromRegOutput;
37
+ exports.findMsiProductCode = findMsiProductCode;
38
+ exports.getRecordedMsiProductCodes = getRecordedMsiProductCodes;
39
+ exports.recordMsiProductCode = recordMsiProductCode;
40
+ const fs = __importStar(require("fs"));
41
+ const os = __importStar(require("os"));
42
+ const path = __importStar(require("path"));
43
+ const child_process_1 = require("child_process");
44
+ /**
45
+ * The installed FullCourtDefense MSI ProductCode, recorded on this machine so
46
+ * the Local Safety guard can recognize `msiexec /x {GUID}` without a registry
47
+ * read on the hook path. The daemon records it at start (every install and
48
+ * upgrade relaunches the daemon); the guard reads it through snapshotToScanOptions.
49
+ */
50
+ const STATE_FILE = path.join(os.homedir(), '.fullcourtdefense', 'msi-product.json');
51
+ const GUID_RE = /^\{[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\}$/;
52
+ /** The previous codes stay listed for the window between an upgrade and the daemon restart. */
53
+ const MAX_CODES = 3;
54
+ /**
55
+ * Product code of the installed FullCourtDefense MSI, from the registry
56
+ * uninstall hive (both 64-bit and WOW6432Node views). Undefined on npm
57
+ * installs or when the MSI entry is missing.
58
+ */
59
+ function parseMsiProductCodeFromRegOutput(output) {
60
+ // `reg query … /s /f FullCourtDefense /d` prints the matching key path line
61
+ // followed by its matching values. We want the {GUID} keyed entry whose
62
+ // DisplayName is FullCourtDefense.
63
+ const lines = output.split(/\r?\n/);
64
+ let currentGuid;
65
+ for (const line of lines) {
66
+ const keyMatch = line.match(/\\Uninstall\\(\{[0-9A-Fa-f-]{36}\})\s*$/);
67
+ if (keyMatch) {
68
+ currentGuid = keyMatch[1];
69
+ continue;
70
+ }
71
+ if (currentGuid && /DisplayName\s+REG_SZ\s+FullCourtDefense\s*$/i.test(line.trim())) {
72
+ return currentGuid;
73
+ }
74
+ }
75
+ return undefined;
76
+ }
77
+ function findMsiProductCode() {
78
+ if (process.platform !== 'win32')
79
+ return undefined;
80
+ const hives = [
81
+ 'HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall',
82
+ 'HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall',
83
+ ];
84
+ for (const hive of hives) {
85
+ const query = (0, child_process_1.spawnSync)('reg', ['query', hive, '/s', '/f', 'FullCourtDefense', '/d'], {
86
+ encoding: 'utf8', windowsHide: true, timeout: 30_000,
87
+ });
88
+ if (query.status !== 0 || !query.stdout)
89
+ continue;
90
+ const code = parseMsiProductCodeFromRegOutput(query.stdout);
91
+ if (code)
92
+ return code;
93
+ }
94
+ return undefined;
95
+ }
96
+ function getRecordedMsiProductCodes(file = STATE_FILE) {
97
+ try {
98
+ const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
99
+ return Array.isArray(parsed.productCodes)
100
+ ? parsed.productCodes.filter((code) => typeof code === 'string' && GUID_RE.test(code))
101
+ : [];
102
+ }
103
+ catch {
104
+ return [];
105
+ }
106
+ }
107
+ /** Puts `productCode` first in the recorded list. Returns false when nothing was written. */
108
+ function recordMsiProductCode(productCode, file = STATE_FILE) {
109
+ if (!productCode || !GUID_RE.test(productCode))
110
+ return false;
111
+ const code = productCode.toUpperCase();
112
+ const previous = getRecordedMsiProductCodes(file);
113
+ if (previous[0] === code)
114
+ return false;
115
+ const productCodes = [code, ...previous.filter(existing => existing.toUpperCase() !== code)].slice(0, MAX_CODES);
116
+ try {
117
+ fs.mkdirSync(path.dirname(file), { recursive: true });
118
+ fs.writeFileSync(file, JSON.stringify({ productCodes, recordedAt: new Date().toISOString() }, null, 2), { encoding: 'utf8', mode: 0o600 });
119
+ return true;
120
+ }
121
+ catch {
122
+ return false;
123
+ }
124
+ }
package/dist/notify.js CHANGED
@@ -123,6 +123,7 @@ function notifyWindowsWindow(n) {
123
123
  '$f.MaximizeBox=$false; $f.MinimizeBox=$false; $f.ShowInTaskbar=$true;',
124
124
  '$f.BackColor=[System.Drawing.Color]::FromArgb(180,30,40);',
125
125
  '$l=New-Object System.Windows.Forms.Label;',
126
+ '$l.UseMnemonic=$false;',
126
127
  '$l.Text=$env:FCD_NOTIFY_TEXT;',
127
128
  '$l.ForeColor=[System.Drawing.Color]::White;',
128
129
  '$l.Font=New-Object System.Drawing.Font("Segoe UI",10,[System.Drawing.FontStyle]::Bold);',
@@ -7,7 +7,7 @@ import { type BoundaryVerification } from './boundaryVerification';
7
7
  * is actively EXERCISED: DPAPI roundtrip (encrypt AND decrypt a probe value),
8
8
  * PowerShell spawn + language mode, control-plane reachability, authenticated
9
9
  * bundle fetch, IDE hook/gateway integrity, and the MSI updater scheduled
10
- * task. One click in the console answers in ~30 seconds what the lptx1110
10
+ * task. One click in the console answers in ~30 seconds what the devbox-01
11
11
  * incident took a day of customer back-and-forth to establish.
12
12
  *
13
13
  * Deliberate privacy boundary: metadata only — never scans customer files,
package/dist/selfTest.js CHANGED
@@ -51,7 +51,7 @@ async function runDeepSelfTest(input) {
51
51
  add({ id: 'native_store', label: 'Credential Manager (native) roundtrip', ok: native.ok, optional: true, detail: native.detail });
52
52
  // 3. DPAPI roundtrip — encrypt AND decrypt a probe value with the exact
53
53
  // snippets the CLI uses for the shield key. This is the check that would
54
- // have identified the lptx1110 credential break in one click. Kept as its
54
+ // have identified the devbox-01 credential break in one click. Kept as its
55
55
  // own check: it is the fallback store for machines without the native
56
56
  // binding and the rollback path to ≤1.21.33.
57
57
  const probe = (0, config_1.dpapiRoundtripProbe)();
@@ -26,6 +26,34 @@ export interface SelfUpdateResult {
26
26
  detail: string;
27
27
  }
28
28
  export declare function resolveNpmCommand(platform?: NodeJS.Platform, execPath?: string, exists?: typeof fs.existsSync): string;
29
+ /**
30
+ * Folders `npm install -g` must write for this install: `node_modules` (the
31
+ * package is replaced there) and, on POSIX, `<prefix>/bin` (the bin links).
32
+ * Empty when this is not a global npm install (repo checkout, npx cache).
33
+ */
34
+ export declare function npmGlobalWriteTargets(packageDir?: string, platform?: NodeJS.Platform): string[];
35
+ /** The first write target this process cannot write, if any. */
36
+ export declare function unwritableNpmTarget(targets?: string[], canWrite?: (dir: string) => boolean): string | undefined;
37
+ /** The exact command an admin runs when this user cannot write the npm prefix. */
38
+ export declare function npmAdminFixCommand(targetVersion: string, platform?: NodeJS.Platform): string;
39
+ /** Outcome of the last detached `npm install -g`, written by the helper process. */
40
+ export interface NpmUpdateResult {
41
+ target: string;
42
+ exitCode: number | null;
43
+ signal?: string;
44
+ error?: string;
45
+ stderrTail?: string;
46
+ finishedAt: string;
47
+ }
48
+ export declare function readNpmUpdateResult(): NpmUpdateResult | undefined;
49
+ /** Pure: did this npm run fail because the user may not write the prefix? */
50
+ export declare function npmFailedOnPermissions(result: NpmUpdateResult | undefined): boolean;
51
+ /**
52
+ * Runs detached: `npm install -g`, records exit code + stderr tail for the
53
+ * daemon (update_needs_admin / update_loop detail), and relaunches the daemon
54
+ * from the replaced entry only when npm exited 0.
55
+ */
56
+ export declare const NPM_UPDATE_HELPER = "\nconst { spawnSync, spawn } = require('child_process');\nconst fs = require('fs');\nconst [npm, target, resultFile, nodeExe, entry] = JSON.parse(process.argv[1]);\nconst run = spawnSync(npm, ['install', '-g', 'fullcourtdefense-cli@' + target], { encoding: 'utf8', windowsHide: true, shell: process.platform === 'win32', timeout: 15 * 60000 });\nconst tail = text => String(text || '').split(/\\r?\\n/).map(l => l.trim()).filter(Boolean).slice(-6).join(' | ').slice(-600);\ntry {\n fs.writeFileSync(resultFile, JSON.stringify({ target, exitCode: run.status, signal: run.signal || undefined, error: run.error ? run.error.message : undefined, stderrTail: tail(run.stderr), finishedAt: new Date().toISOString() }));\n} catch {}\nif (run.status === 0) spawn(nodeExe, [entry, 'daemon'], { detached: true, stdio: 'ignore', windowsHide: true }).unref();\n";
29
57
  /**
30
58
  * The updater task command for an install root. Prefers the Node updater
31
59
  * (runs on the MSI's own bundled runtime — no powershell.exe spawn, which
@@ -60,6 +88,71 @@ export declare function buildUpdaterTaskXml(root: string, apiUrl: string): strin
60
88
  * elevated token to re-register a SYSTEM task, silent no-op otherwise.
61
89
  */
62
90
  export declare function modernizeUpdaterTask(log: (message: string) => void, apiUrl?: string): void;
91
+ /**
92
+ * Folder of the updater run lock and result: under Program Files, where a
93
+ * standard user cannot create a file. In %ProgramData% any user could plant a
94
+ * "live" lock and silence the watchdog, the daemon's update kick and recovery.
95
+ * Same derivation as Update-FullCourtDefense.js; the harness's sandboxed
96
+ * ProgramData (FCD_UPDATER_PROGRAMDATA) stands in for it.
97
+ */
98
+ export declare function updaterStateDir(env?: NodeJS.ProcessEnv): string;
99
+ /**
100
+ * The updater's single-instance lock (<Program Files>\FullCourtDefense State\
101
+ * updater.lock.json), written by the SYSTEM task from stage 1 through the end
102
+ * of stage 2 (Update-FullCourtDefense.js). Readable by every user.
103
+ */
104
+ export interface UpdaterRunLock {
105
+ runId: string;
106
+ pid?: number;
107
+ childPid?: number;
108
+ stage?: string;
109
+ fromVersion?: string;
110
+ targetVersion?: string;
111
+ startedAt?: string;
112
+ /** Windows BootId when the lock was written (updaters from 1.36.1 on). */
113
+ bootId?: number;
114
+ /** Monotonic uptime when the lock was written (updaters from 1.36.1 on). */
115
+ uptimeMs?: number;
116
+ }
117
+ export interface BootStamp {
118
+ bootId?: number;
119
+ uptimeMs: number;
120
+ }
121
+ /** Same boot identity the updater stamps into its lock (Update-FullCourtDefense.js bootStamp). */
122
+ export declare function currentBootStamp(): BootStamp;
123
+ /** Pure: was this lock written before the current boot? Locks without a stamp (old updaters) never are. */
124
+ export declare function updaterLockFromPreviousBoot(lock: UpdaterRunLock, boot: BootStamp): boolean;
125
+ /** Same bound as the updater's LOCK_MAX_AGE_MS: an older lock is abandoned. */
126
+ export declare function updaterLockMaxAgeMs(): number;
127
+ /** Is this lock held by a live updater process, written in this boot, and young enough to trust? */
128
+ export declare function updaterRunIsActive(lock: UpdaterRunLock | undefined, nowMs: number, isPidAlive: (pid: number) => boolean, maxAgeMs?: number, bootStamp?: () => BootStamp): boolean;
129
+ /**
130
+ * The updater run in progress on this machine, or undefined. While one is
131
+ * active the daemon must not trigger another run and the watchdog must not
132
+ * revive the old build mid-install — both did, and the two runs killed each
133
+ * other (2026-09-20). Windows only; never throws.
134
+ */
135
+ export declare function readActiveUpdaterRun(nowMs?: number, isPidAlive?: (pid: number) => boolean): UpdaterRunLock | undefined;
136
+ /** The updater's last recorded outcome (updater-result.json), if any. */
137
+ export interface UpdaterRunResult {
138
+ runId?: string;
139
+ fromVersion?: string;
140
+ targetVersion?: string;
141
+ outcome?: 'installed' | 'failed';
142
+ error?: string;
143
+ startedAt?: string;
144
+ finishedAt?: string;
145
+ }
146
+ export declare function readLastUpdaterResult(): UpdaterRunResult | undefined;
147
+ /**
148
+ * Pure: did the daemon's last proof of life fall inside an updater run? A
149
+ * daemon that died then was stopped by the updater, not by EDR/AV. The death
150
+ * itself lands within one heartbeat after `lastAliveAt`, hence the slack.
151
+ */
152
+ export declare function deathDuringUpdaterRun(lastAliveAt: string | undefined, run: {
153
+ startedAt?: string;
154
+ finishedAt?: string;
155
+ } | undefined, slackMs?: number): boolean;
63
156
  /**
64
157
  * Updater script log (%ProgramData%\FullCourtDefense\updater.log) — the
65
158
  * elevated task's own words. Read by the diagnostics bundle and the update-
@@ -78,6 +171,21 @@ export declare function readUpdaterLogTail(maxLines?: number): string[];
78
171
  * in the console. Cheap no-op when there is no attempts record.
79
172
  */
80
173
  export declare function clearResolvedUpdateLoop(currentVersion: string | undefined, log?: (message: string) => void): void;
174
+ /** Pure: does a persisted kick for this exact target/fromVersion still hold the cooldown? */
175
+ export declare function updateKickStillCoolingDown(record: {
176
+ target?: string;
177
+ fromVersion?: string;
178
+ startedAt?: string;
179
+ } | undefined, target: string, fromVersion: string, nowMs: number, cooldownMs?: number): boolean;
180
+ /** Pure: update_loop detail in the words of the path that is looping (MSI updater task vs npm). */
181
+ export declare function updateLoopDetail(input: {
182
+ kind: InstallKind;
183
+ target: string;
184
+ attempts: number;
185
+ currentVersion?: string;
186
+ updaterTail: string[];
187
+ npmResult?: NpmUpdateResult;
188
+ }): string;
81
189
  /**
82
190
  * Upgrade this machine to targetVersion if it is newer than currentVersion.
83
191
  * Cheap no-op when already current, when a kick is still pending, or when the