@cortexkit/opencode-antigravity-auth 3.0.10 → 3.0.12

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 (110) hide show
  1. package/dist/cli.js +2077 -1451
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +207 -120
  4. package/dist/index.js +1526 -861
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +214 -127
  7. package/dist/server.js +1524 -859
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +7 -1
  11. package/dist/src/common-auth-embedded/claustrum/consumer.js +17 -2
  12. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  13. package/dist/src/common-auth-embedded/claustrum/enrollment.js +27 -0
  14. package/dist/src/common-auth-embedded/claustrum/errors.d.ts +1 -1
  15. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  16. package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
  17. package/dist/src/common-auth-embedded/claustrum/quota-writer.js +4 -54
  18. package/dist/src/common-auth-embedded/claustrum/roster.d.ts +31 -0
  19. package/dist/src/common-auth-embedded/claustrum/roster.js +72 -0
  20. package/dist/src/common-auth-embedded/commands/builtins.d.ts +37 -0
  21. package/dist/src/common-auth-embedded/commands/builtins.js +95 -13
  22. package/dist/src/common-auth-embedded/commands/index.d.ts +1 -1
  23. package/dist/src/common-auth-embedded/fs/private-files.d.ts +2 -0
  24. package/dist/src/common-auth-embedded/fs/private-files.js +49 -3
  25. package/dist/src/common-auth-embedded/opencode2/install.d.ts +3 -2
  26. package/dist/src/common-auth-embedded/opencode2/install.js +184 -63
  27. package/dist/src/common-auth-embedded/opencode2/types.d.ts +43 -6
  28. package/dist/src/common-auth-embedded/quota/pending.js +48 -0
  29. package/dist/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  30. package/dist/src/common-auth-embedded/setup/enroll.js +116 -34
  31. package/dist/src/common-auth-embedded/setup/index.d.ts +1 -0
  32. package/dist/src/common-auth-embedded/setup/index.js +1 -0
  33. package/dist/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
  34. package/dist/src/common-auth-embedded/setup/process-fence.js +56 -1
  35. package/dist/src/common-auth-embedded/setup/types.d.ts +5 -0
  36. package/dist/src/common-auth-embedded/source-output.json +121 -97
  37. package/dist/src/common-auth-embedded/store/attribution.d.ts +5 -0
  38. package/dist/src/common-auth-embedded/store/attribution.js +39 -25
  39. package/dist/src/common-auth-embedded/store/pool.d.ts +17 -0
  40. package/dist/src/common-auth-embedded/store/pool.js +18 -3
  41. package/dist/src/common-auth-embedded/store/pull.js +3 -1
  42. package/dist/src/common-auth-embedded/store/quota-writer.js +298 -0
  43. package/dist/src/common-auth-embedded/store/runtime.d.ts +2 -0
  44. package/dist/src/plugin/lifecycle.d.ts.map +1 -1
  45. package/dist/src/plugin/lifecycle.js +48 -27
  46. package/dist/src/plugin/lifecycle.js.map +1 -1
  47. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  48. package/dist/src/plugin/shared/request-services.js +3 -2
  49. package/dist/src/plugin/shared/request-services.js.map +1 -1
  50. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  51. package/dist/src/plugin/vault-custody.js +13 -3
  52. package/dist/src/plugin/vault-custody.js.map +1 -1
  53. package/dist/tui-build-map.json +5 -5
  54. package/dist/tui-ga-build-map.json +1 -1
  55. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +7 -1
  56. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  57. package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +1 -1
  58. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  59. package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +31 -0
  60. package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +37 -0
  61. package/dist/types/src/common-auth-embedded/commands/index.d.ts +1 -1
  62. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +3 -2
  63. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +43 -6
  64. package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  65. package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -0
  66. package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
  67. package/dist/types/src/common-auth-embedded/setup/types.d.ts +5 -0
  68. package/dist/types/src/common-auth-embedded/store/attribution.d.ts +5 -0
  69. package/dist/types/src/common-auth-embedded/store/pool.d.ts +17 -0
  70. package/dist/types/src/common-auth-embedded/store/runtime.d.ts +2 -0
  71. package/dist/types/src/plugin/lifecycle.d.ts.map +1 -1
  72. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  73. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  74. package/package.json +2 -2
  75. package/src/common-auth-embedded/claustrum/consumer.d.ts +7 -1
  76. package/src/common-auth-embedded/claustrum/consumer.js +17 -2
  77. package/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
  78. package/src/common-auth-embedded/claustrum/enrollment.js +27 -0
  79. package/src/common-auth-embedded/claustrum/errors.d.ts +1 -1
  80. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  81. package/src/common-auth-embedded/claustrum/index.js +1 -1
  82. package/src/common-auth-embedded/claustrum/quota-writer.js +4 -54
  83. package/src/common-auth-embedded/claustrum/roster.d.ts +31 -0
  84. package/src/common-auth-embedded/claustrum/roster.js +72 -0
  85. package/src/common-auth-embedded/commands/builtins.d.ts +37 -0
  86. package/src/common-auth-embedded/commands/builtins.js +95 -13
  87. package/src/common-auth-embedded/commands/index.d.ts +1 -1
  88. package/src/common-auth-embedded/fs/private-files.d.ts +2 -0
  89. package/src/common-auth-embedded/fs/private-files.js +49 -3
  90. package/src/common-auth-embedded/opencode2/install.d.ts +3 -2
  91. package/src/common-auth-embedded/opencode2/install.js +184 -63
  92. package/src/common-auth-embedded/opencode2/types.d.ts +43 -6
  93. package/src/common-auth-embedded/quota/pending.js +48 -0
  94. package/src/common-auth-embedded/setup/enroll.d.ts +34 -0
  95. package/src/common-auth-embedded/setup/enroll.js +116 -34
  96. package/src/common-auth-embedded/setup/index.d.ts +1 -0
  97. package/src/common-auth-embedded/setup/index.js +1 -0
  98. package/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
  99. package/src/common-auth-embedded/setup/process-fence.js +56 -1
  100. package/src/common-auth-embedded/setup/types.d.ts +5 -0
  101. package/src/common-auth-embedded/source-output.json +121 -97
  102. package/src/common-auth-embedded/store/attribution.d.ts +5 -0
  103. package/src/common-auth-embedded/store/attribution.js +39 -25
  104. package/src/common-auth-embedded/store/pool.d.ts +17 -0
  105. package/src/common-auth-embedded/store/pool.js +18 -3
  106. package/src/common-auth-embedded/store/pull.js +3 -1
  107. package/src/common-auth-embedded/store/quota-writer.js +298 -0
  108. package/src/common-auth-embedded/store/runtime.d.ts +2 -0
  109. package/src/tui-compiled/common-auth-embedded/fs/private-files.js +49 -3
  110. package/src/tui-raw/common-auth-embedded/fs/private-files.js +49 -3
@@ -1,17 +1,53 @@
1
1
  import { setTimeout as delay } from 'node:timers/promises';
2
2
  import { writeEnrollmentTokenFile } from '@cortexkit/claustrum-client';
3
3
  import { printLine } from '../auth-menu/terminal.js';
4
- import { ClaustrumEnrollmentManager, connectClaustrumEnrollmentClient, hostEnrollmentPaths, } from '../claustrum/enrollment.js';
4
+ import { ClaustrumEnrollmentManager, connectClaustrumEnrollmentClient, hostEnrollmentPaths, UNSUPPORTED_ENROLLMENT_CODE, } from '../claustrum/enrollment.js';
5
5
  import { ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
6
6
  const ENROLLMENT_INCOMPLETE_MESSAGE = 'Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.';
7
+ /** Fixed text: no version, host or account detail, so it is safe to print anywhere. */
8
+ export const UNSUPPORTED_VAULT_MESSAGE = 'This Claustrum vault is too old to connect plugins. Run ck upgrade to move to Claustrum v0.2.0 or newer (read "Upgrading from v0.1.3" in its release notes first), or run setup without --claustrum to use local accounts.';
9
+ /**
10
+ * The longest setup waits, in total, for the vault to create the enrollment
11
+ * request and for an operator to approve it. It matches the wait setup always
12
+ * had (300 one-second polls), but is now measured on the clock: a vault that
13
+ * answers each request slowly can no longer stretch it.
14
+ */
15
+ export const ENROLLMENT_WAIT_MS = 300_000;
16
+ /** The pause between polls while a created request waits for approval. */
17
+ const APPROVAL_POLL_MS = 1000;
18
+ /**
19
+ * Pauses between proposals the vault failed to accept for a reason worth
20
+ * retrying; the last value repeats until the overall wait runs out.
21
+ */
22
+ const PROPOSE_BACKOFF_MS = [1000, 2000, 4000, 8000, 16_000, 30_000];
23
+ /** Vault codes are short snake_case words; anything else is shown as `unknown`. */
24
+ function safeCode(code) {
25
+ return code && /^[a-z][a-z0-9_]{0,63}$/.test(code) ? code : 'unknown';
26
+ }
7
27
  /**
8
28
  * Thrown when the enrollment ended without writing the host's token: the vault
9
- * could not be reached, it refused the request, or approval never came before
10
- * setup stopped waiting. Setup can then report the host as not connected
11
- * without reading its files. The message is the same one a plain error would
12
- * carry, so the user sees no difference.
29
+ * could not be reached, it cannot enroll plugins, it refused the request, it
30
+ * never created one, approval never came before setup stopped waiting, or
31
+ * the enrollment failed in some other way (`incomplete`).
32
+ * Setup can then report the host as not connected without reading its files.
33
+ * The message is fixed text built only from vetted values, never from what
34
+ * the vault or client threw. `lastErrorCode` is the last enrollment error code
35
+ * setup saw, from the vault or from the client's transport (for example
36
+ * `transport_error`), for diagnostics; it carries no secret.
13
37
  */
14
38
  export class HostNotEnrolledError extends Error {
39
+ reason;
40
+ lastErrorCode;
41
+ constructor(message, details) {
42
+ super(message);
43
+ this.name = 'HostNotEnrolledError';
44
+ this.reason = details.reason;
45
+ if (details.lastErrorCode !== undefined)
46
+ this.lastErrorCode = safeCode(details.lastErrorCode);
47
+ }
48
+ }
49
+ function approveCommand(requestId, name) {
50
+ return `ck auth enroll approve --request-id ${requestId} --name ${name}`;
15
51
  }
16
52
  /** Enroll an independently revocable host; plugin callbacks choose its credential store and account permissions. */
17
53
  export async function connectSetupHost(plugin, host, io, terminal, fence) {
@@ -22,59 +58,105 @@ export async function connectSetupHost(plugin, host, io, terminal, fence) {
22
58
  connectionFile: plugin.vault.connectionFile,
23
59
  handshakeTimeoutMs: 2000,
24
60
  }).catch(() => {
25
- throw new HostNotEnrolledError('Claustrum connection failed; start ck and rerun setup.');
61
+ throw new HostNotEnrolledError('Claustrum connection failed; start ck and rerun setup.', { reason: 'connection-failed' });
26
62
  });
63
+ const now = io.now ?? (() => performance.now());
64
+ const wait = io.wait ?? delay;
27
65
  try {
28
66
  const manager = new ClaustrumEnrollmentManager({
29
67
  proposedName: name,
30
68
  paths,
31
- client: {
32
- enrollPropose: async (input) => {
33
- await fence();
34
- return client.enrollPropose(input);
35
- },
36
- enrollPoll: async (input) => {
37
- await fence();
38
- return client.enrollPoll(input);
39
- },
40
- },
69
+ // Each tick of the wait below checks the fence once, just before
70
+ // reconcile proposes or polls. Checking again inside every vault call
71
+ // doubled the process listings per tick, and on Windows each listing
72
+ // starts PowerShell.
73
+ client,
41
74
  writeTokenFile: async (path, file) => {
75
+ // Writing the token is what connects the host: check once more.
42
76
  await fence();
43
77
  await writeEnrollmentTokenFile(path, file);
44
78
  },
45
79
  });
80
+ printLine(terminal, `Asking the vault to connect ${name}…`);
81
+ const deadline = now() + ENROLLMENT_WAIT_MS;
46
82
  let printedRequest;
47
- for (let tick = 0; tick < 300; tick++) {
83
+ let lastCode;
84
+ let reportedCode;
85
+ let failedProposals = 0;
86
+ for (;;) {
48
87
  await fence();
49
88
  const status = await manager.reconcile();
50
89
  if (status.state === 'approved') {
51
90
  printLine(terminal, `Connected ${host} to Claustrum.`);
52
91
  return;
53
92
  }
93
+ if (status.state === 'unavailable' &&
94
+ status.code === UNSUPPORTED_ENROLLMENT_CODE)
95
+ throw new HostNotEnrolledError(UNSUPPORTED_VAULT_MESSAGE, {
96
+ reason: 'unsupported-vault',
97
+ lastErrorCode: status.code,
98
+ });
54
99
  if (status.state !== 'pending' && status.state !== 'busy')
55
- throw new HostNotEnrolledError('Claustrum enrollment refused; inspect its status with ck before rerunning setup.');
56
- if (status.state === 'pending' &&
57
- status.requestId &&
58
- status.requestId !== printedRequest) {
59
- if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
60
- throw new HostNotEnrolledError('Invalid enrollment request id.');
61
- printedRequest = status.requestId;
62
- printLine(terminal, 'Waiting for approval. In another terminal, run:');
63
- printLine(terminal, ` ck auth enroll approve --request-id ${status.requestId} --name ${name}`);
64
- printLine(terminal, `Enrollment files: ${paths.statePath}, ${paths.tokenPath}`);
100
+ throw new HostNotEnrolledError('Claustrum enrollment refused; inspect its status with ck before rerunning setup.', {
101
+ reason: 'refused',
102
+ ...('code' in status && { lastErrorCode: status.code }),
103
+ });
104
+ let pause = APPROVAL_POLL_MS;
105
+ if (status.state === 'busy')
106
+ lastCode = 'busy';
107
+ else if (status.retryCode)
108
+ lastCode = status.retryCode;
109
+ if (status.state === 'pending' && status.requestId) {
110
+ failedProposals = 0;
111
+ if (status.requestId !== printedRequest) {
112
+ if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
113
+ throw new HostNotEnrolledError('Invalid enrollment request id.', {
114
+ reason: 'invalid-request',
115
+ });
116
+ printedRequest = status.requestId;
117
+ printLine(terminal, 'Waiting for approval. In another terminal, run:');
118
+ printLine(terminal, ` ${approveCommand(status.requestId, name)}`);
119
+ printLine(terminal, `Enrollment files: ${paths.statePath}, ${paths.tokenPath}`);
120
+ }
65
121
  }
66
- await (io.wait ?? delay)(1000);
122
+ else if (status.state === 'pending' && status.retryCode) {
123
+ // No request id came back. Back off instead of asking
124
+ // again every second, and say so once per distinct code.
125
+ pause =
126
+ PROPOSE_BACKOFF_MS[Math.min(failedProposals, PROPOSE_BACKOFF_MS.length - 1)] ?? APPROVAL_POLL_MS;
127
+ failedProposals++;
128
+ const code = safeCode(status.retryCode);
129
+ if (code !== reportedCode) {
130
+ reportedCode = code;
131
+ printLine(terminal, `The vault has not created the request yet (${code}); retrying.`);
132
+ }
133
+ }
134
+ const remaining = deadline - now();
135
+ if (remaining <= 0)
136
+ break;
137
+ await wait(Math.min(pause, remaining));
67
138
  }
68
- throw new HostNotEnrolledError('Claustrum approval is still pending; approve with ck and rerun setup.');
139
+ if (printedRequest)
140
+ throw new HostNotEnrolledError(`Claustrum approval is still pending. In another terminal, run: ${approveCommand(printedRequest, name)} and then rerun setup.`, {
141
+ reason: 'approval-pending',
142
+ ...(lastCode !== undefined && { lastErrorCode: lastCode }),
143
+ });
144
+ const code = safeCode(lastCode);
145
+ throw new HostNotEnrolledError(`The vault never created the enrollment request (last error: ${code}). Check that ck is running, then rerun setup.`, { reason: 'request-not-created', lastErrorCode: code });
69
146
  }
70
147
  catch (error) {
71
148
  if (error instanceof ProcessFenceViolationError ||
72
- error instanceof ProcessInspectionError)
149
+ error instanceof ProcessInspectionError ||
150
+ // Built above from fixed text and vetted values only.
151
+ error instanceof HostNotEnrolledError)
73
152
  throw error;
74
- // Enrollment exceptions can carry request secrets or bearer tokens; never display them.
75
- if (error instanceof HostNotEnrolledError)
76
- throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE);
77
- throw new Error(ENROLLMENT_INCOMPLETE_MESSAGE);
153
+ // Enrollment exceptions can carry request secrets or bearer tokens; never
154
+ // display them. Only a vetted error code goes into the diagnostics.
155
+ const code = error?.code;
156
+ throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE, {
157
+ reason: 'incomplete',
158
+ ...(typeof code === 'string' && { lastErrorCode: code }),
159
+ });
78
160
  }
79
161
  finally {
80
162
  client.close();
@@ -1,6 +1,7 @@
1
1
  export { AMBIGUOUS_OPENCODE_MESSAGE, runSetup } from './command.js';
2
2
  export { SetupCommandError, setupEnrollment } from './command-error.js';
3
3
  export { detectHosts, detectOpenCodeGeneration, findExecutableOnPath, openCodeDesktopMarkers, } from './detect.js';
4
+ export { ENROLLMENT_WAIT_MS, HostNotEnrolledError, type HostNotEnrolledReason, UNSUPPORTED_VAULT_MESSAGE, } from './enroll.js';
4
5
  export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, type ProcessInspectionStep, } from './process-fence.js';
5
6
  export { type PlannedWrite, planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
6
7
  export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnrollmentOutcome, SetupEnvironment, SetupFileSystem, SetupHost, SetupHostEnrollment, SetupIO, SetupPlugin, SetupResult, } from './types.js';
@@ -1,5 +1,6 @@
1
1
  export { AMBIGUOUS_OPENCODE_MESSAGE, runSetup } from './command.js';
2
2
  export { SetupCommandError, setupEnrollment } from './command-error.js';
3
3
  export { detectHosts, detectOpenCodeGeneration, findExecutableOnPath, openCodeDesktopMarkers, } from './detect.js';
4
+ export { ENROLLMENT_WAIT_MS, HostNotEnrolledError, UNSUPPORTED_VAULT_MESSAGE, } from './enroll.js';
4
5
  export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
5
6
  export { planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
@@ -39,6 +39,13 @@ export declare function listSetupProcesses(runner?: CommandRunner, options?: {
39
39
  * a container this process can hold any small PID a fixture uses.
40
40
  */
41
41
  selfPid?: number;
42
+ /**
43
+ * Windows only: answer with one CIM query for the images a fence cares
44
+ * about (host programs, Node and Bun), returning image name, PID and
45
+ * command line together, instead of `tasklist` followed by a second CIM
46
+ * query. The result lists only those processes.
47
+ */
48
+ hostImagesOnly?: boolean;
42
49
  }): Promise<Array<{
43
50
  pid: number;
44
51
  command: string;
@@ -5,6 +5,18 @@ import { defaultCommandRunner } from './command-runner.js';
5
5
  const WINDOWS_CIM_TIMEOUT_MS = 45_000;
6
6
  const HOSTS = new Set(['opencode', 'litecode', 'opencode2', 'pi']);
7
7
  const RUNTIMES = new Set(['node', 'bun']);
8
+ /**
9
+ * The fence's one Windows query. It selects every image whose name starts
10
+ * with a host or runtime name, a superset of what `hostName` can recognize
11
+ * from an image (it strips only an extension), and returns image name, PID
12
+ * and command line from one snapshot. The answer always carries
13
+ * `complete: true`, so an empty or cut-off answer is never mistaken for an
14
+ * empty process list.
15
+ */
16
+ const WINDOWS_FENCE_FILTER = [...HOSTS, ...RUNTIMES]
17
+ .map((name) => `Name LIKE '${name}%'`)
18
+ .join(' OR ');
19
+ const WINDOWS_FENCE_QUERY = `$ErrorActionPreference = 'Stop'; $rows = @(Get-CimInstance Win32_Process -Filter "${WINDOWS_FENCE_FILTER}" | Select-Object Name,ProcessId,CommandLine); ConvertTo-Json -Compress -Depth 3 -InputObject @{ complete = $true; processes = $rows }`;
8
20
  const PI_SCRIPT_PATTERN = /(?:^|[/\\])pi-coding-agent[/\\]dist[/\\](?:(?:bundle|bun)[/\\])?cli\.m?js$/i;
9
21
  /** Splits a command line into arguments, keeping double-quoted ones whole. */
10
22
  function commandArguments(command) {
@@ -169,6 +181,45 @@ export async function listSetupProcesses(runner = defaultCommandRunner, options
169
181
  }
170
182
  };
171
183
  try {
184
+ if (windows && options.hostImagesOnly) {
185
+ const details = await inspect('CIM', 'powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', WINDOWS_FENCE_QUERY], WINDOWS_CIM_TIMEOUT_MS);
186
+ if (details.exitCode !== 0)
187
+ throw new ProcessInspectionError(inspection);
188
+ // An empty or truncated answer fails to parse or lacks `complete`, so a
189
+ // query that silently printed nothing is never read as "no hosts".
190
+ const value = JSON.parse(details.stdout);
191
+ if (!value ||
192
+ typeof value !== 'object' ||
193
+ !('complete' in value) ||
194
+ value.complete !== true ||
195
+ !('processes' in value))
196
+ throw new ProcessInspectionError(inspection);
197
+ const listed = value.processes;
198
+ const rows = listed === null ? [] : Array.isArray(listed) ? listed : [listed];
199
+ const processes = [];
200
+ for (const row of rows) {
201
+ if (!row ||
202
+ typeof row !== 'object' ||
203
+ !('Name' in row) ||
204
+ typeof row.Name !== 'string' ||
205
+ !('ProcessId' in row) ||
206
+ !Number.isSafeInteger(row.ProcessId) ||
207
+ row.ProcessId < 0 ||
208
+ !('CommandLine' in row))
209
+ throw new ProcessInspectionError(inspection);
210
+ const pid = row.ProcessId;
211
+ // As with tasklist, a host program is judged by its image name, and
212
+ // a Node or Bun process by the script on its command line. A runtime
213
+ // whose command line cannot be read cannot be cleared.
214
+ if (!/^(?:node|bun)\.exe$/i.test(row.Name))
215
+ processes.push({ pid, command: row.Name });
216
+ else if (typeof row.CommandLine === 'string')
217
+ processes.push({ pid, command: row.CommandLine });
218
+ else if (pid !== selfPid)
219
+ throw new ProcessInspectionError(inspection);
220
+ }
221
+ return processes;
222
+ }
172
223
  const result = await inspect(windows ? 'tasklist' : 'ps', windows ? 'tasklist.exe' : 'ps', windows ? ['/fo', 'csv', '/nh'] : ['-eo', 'pid,command']);
173
224
  if (result.exitCode !== 0)
174
225
  throw new ProcessInspectionError(inspection);
@@ -246,7 +297,11 @@ export function createProcessFence(runner = defaultCommandRunner, options = {})
246
297
  const isHost = (entry) => entry.pid !== selfPid && hostName(entry.command) !== null;
247
298
  return {
248
299
  async listRunningHosts(env) {
249
- return (await listSetupProcesses(runner, { ...options, env })).filter(isHost);
300
+ return (await listSetupProcesses(runner, {
301
+ ...options,
302
+ env,
303
+ hostImagesOnly: true,
304
+ })).filter(isHost);
250
305
  },
251
306
  async previewRunningHosts(env) {
252
307
  const processes = await listSetupProcesses(runner, {
@@ -125,6 +125,11 @@ export interface SetupIO {
125
125
  handshakeTimeoutMs: number;
126
126
  }) => Promise<ClaustrumEnrollmentConnection>;
127
127
  wait?: (ms: number) => Promise<void>;
128
+ /**
129
+ * Monotonic milliseconds that bound the enrollment wait. Defaults to
130
+ * `performance.now`; tests pair it with `wait` to run a fake clock.
131
+ */
132
+ now?: () => number;
128
133
  }
129
134
  export interface HostDetection {
130
135
  installed: boolean;