@cortexkit/opencode-antigravity-auth 3.0.6 → 3.0.7

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 (164) hide show
  1. package/dist/cli.js +620 -120
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +128 -44
  4. package/dist/index.js +1469 -675
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +154 -73
  7. package/dist/server.js +1075 -280
  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 +11 -1
  11. package/dist/src/common-auth-embedded/claustrum/consumer.js +38 -1
  12. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
  13. package/dist/src/common-auth-embedded/claustrum/custody.js +17 -0
  14. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  15. package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  16. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +6 -1
  17. package/dist/src/common-auth-embedded/pi-slot/lock.js +7 -3
  18. package/dist/src/common-auth-embedded/quota/format.d.ts +14 -3
  19. package/dist/src/common-auth-embedded/quota/format.js +135 -18
  20. package/dist/src/common-auth-embedded/quota/index.d.ts +1 -1
  21. package/dist/src/common-auth-embedded/quota/index.js +1 -1
  22. package/dist/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  23. package/dist/src/common-auth-embedded/setup/command-error.js +79 -0
  24. package/dist/src/common-auth-embedded/setup/command-runner.js +118 -24
  25. package/dist/src/common-auth-embedded/setup/command.js +75 -19
  26. package/dist/src/common-auth-embedded/setup/enroll.js +17 -5
  27. package/dist/src/common-auth-embedded/setup/index.d.ts +2 -1
  28. package/dist/src/common-auth-embedded/setup/index.js +1 -0
  29. package/dist/src/common-auth-embedded/setup/register.js +8 -2
  30. package/dist/src/common-auth-embedded/setup/types.d.ts +14 -0
  31. package/dist/src/common-auth-embedded/source-output.json +92 -76
  32. package/dist/src/common-auth-embedded/store/pool.d.ts +1 -1
  33. package/dist/src/common-auth-embedded/store/pool.js +0 -1
  34. package/dist/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  35. package/dist/src/common-auth-embedded/store/refresh-lock.js +0 -1
  36. package/dist/src/ga/server/index.d.ts.map +1 -1
  37. package/dist/src/ga/server/index.js +4 -2
  38. package/dist/src/ga/server/index.js.map +1 -1
  39. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  40. package/dist/src/ga/tui/host-ga.js +37 -3
  41. package/dist/src/ga/tui/host-ga.js.map +1 -1
  42. package/dist/src/plugin/config/schema.d.ts.map +1 -1
  43. package/dist/src/plugin/config/schema.js +2 -1
  44. package/dist/src/plugin/config/schema.js.map +1 -1
  45. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  46. package/dist/src/plugin/ga-location-services.js +4 -3
  47. package/dist/src/plugin/ga-location-services.js.map +1 -1
  48. package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
  49. package/dist/src/plugin/gemini-dump.js +2 -5
  50. package/dist/src/plugin/gemini-dump.js.map +1 -1
  51. package/dist/src/plugin/index.d.ts.map +1 -1
  52. package/dist/src/plugin/index.js +3 -3
  53. package/dist/src/plugin/index.js.map +1 -1
  54. package/dist/src/plugin/logging-utils.d.ts.map +1 -1
  55. package/dist/src/plugin/logging-utils.js +2 -5
  56. package/dist/src/plugin/logging-utils.js.map +1 -1
  57. package/dist/src/plugin/request.d.ts +1 -2
  58. package/dist/src/plugin/request.d.ts.map +1 -1
  59. package/dist/src/plugin/request.js +8 -12
  60. package/dist/src/plugin/request.js.map +1 -1
  61. package/dist/src/plugin/shared/request-services.d.ts +8 -1
  62. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  63. package/dist/src/plugin/shared/request-services.js +140 -58
  64. package/dist/src/plugin/shared/request-services.js.map +1 -1
  65. package/dist/src/plugin/shared/vault-request-credentials.d.ts +12 -3
  66. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  67. package/dist/src/plugin/shared/vault-request-credentials.js +3 -0
  68. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  69. package/dist/src/plugin/vault-custody.d.ts +14 -1
  70. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  71. package/dist/src/plugin/vault-custody.js +57 -10
  72. package/dist/src/plugin/vault-custody.js.map +1 -1
  73. package/dist/src/sidebar-projection.d.ts +4 -0
  74. package/dist/src/sidebar-projection.d.ts.map +1 -1
  75. package/dist/src/sidebar-projection.js +6 -2
  76. package/dist/src/sidebar-projection.js.map +1 -1
  77. package/dist/src/tui/quota-layout.d.ts +94 -0
  78. package/dist/src/tui/quota-layout.d.ts.map +1 -0
  79. package/dist/src/tui/quota-layout.js +139 -0
  80. package/dist/src/tui/quota-layout.js.map +1 -0
  81. package/dist/src/tui/route-layout.d.ts +8 -0
  82. package/dist/src/tui/route-layout.d.ts.map +1 -0
  83. package/dist/src/tui/route-layout.js +36 -0
  84. package/dist/src/tui/route-layout.js.map +1 -0
  85. package/dist/src/tui.d.ts.map +1 -1
  86. package/dist/src/tui.js +26 -128
  87. package/dist/src/tui.js.map +1 -1
  88. package/dist/tui-build-map.json +42 -13
  89. package/dist/tui-ga-build-map.json +46 -17
  90. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +11 -1
  91. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
  92. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  93. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  94. package/dist/types/src/common-auth-embedded/quota/format.d.ts +14 -3
  95. package/dist/types/src/common-auth-embedded/quota/index.d.ts +1 -1
  96. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  97. package/dist/types/src/common-auth-embedded/setup/index.d.ts +2 -1
  98. package/dist/types/src/common-auth-embedded/setup/types.d.ts +14 -0
  99. package/dist/types/src/common-auth-embedded/store/pool.d.ts +1 -1
  100. package/dist/types/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  101. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  102. package/dist/types/src/plugin/config/schema.d.ts.map +1 -1
  103. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  104. package/dist/types/src/plugin/gemini-dump.d.ts.map +1 -1
  105. package/dist/types/src/plugin/index.d.ts.map +1 -1
  106. package/dist/types/src/plugin/logging-utils.d.ts.map +1 -1
  107. package/dist/types/src/plugin/request.d.ts +1 -2
  108. package/dist/types/src/plugin/request.d.ts.map +1 -1
  109. package/dist/types/src/plugin/shared/request-services.d.ts +8 -1
  110. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  111. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +12 -3
  112. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  113. package/dist/types/src/plugin/vault-custody.d.ts +14 -1
  114. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  115. package/package.json +3 -3
  116. package/src/common-auth-embedded/claustrum/consumer.d.ts +11 -1
  117. package/src/common-auth-embedded/claustrum/consumer.js +38 -1
  118. package/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
  119. package/src/common-auth-embedded/claustrum/custody.js +17 -0
  120. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  121. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  122. package/src/common-auth-embedded/fs/refresh-file-lock.js +6 -1
  123. package/src/common-auth-embedded/pi-slot/lock.js +7 -3
  124. package/src/common-auth-embedded/quota/format.d.ts +14 -3
  125. package/src/common-auth-embedded/quota/format.js +135 -18
  126. package/src/common-auth-embedded/quota/index.d.ts +1 -1
  127. package/src/common-auth-embedded/quota/index.js +1 -1
  128. package/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  129. package/src/common-auth-embedded/setup/command-error.js +79 -0
  130. package/src/common-auth-embedded/setup/command-runner.js +118 -24
  131. package/src/common-auth-embedded/setup/command.js +75 -19
  132. package/src/common-auth-embedded/setup/enroll.js +17 -5
  133. package/src/common-auth-embedded/setup/index.d.ts +2 -1
  134. package/src/common-auth-embedded/setup/index.js +1 -0
  135. package/src/common-auth-embedded/setup/register.js +8 -2
  136. package/src/common-auth-embedded/setup/types.d.ts +14 -0
  137. package/src/common-auth-embedded/source-output.json +92 -76
  138. package/src/common-auth-embedded/store/pool.d.ts +1 -1
  139. package/src/common-auth-embedded/store/pool.js +0 -1
  140. package/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  141. package/src/common-auth-embedded/store/refresh-lock.js +0 -1
  142. package/src/tui-compiled/common-auth-embedded/quota/format.js +135 -18
  143. package/src/tui-compiled/common-auth-embedded/quota/index.js +1 -1
  144. package/src/tui-compiled/tui/quota-layout.js +378 -0
  145. package/src/tui-compiled/tui/route-layout.js +30 -0
  146. package/src/tui-compiled/tui.js +145 -427
  147. package/src/tui-ga-compiled/host-ga.js +82 -52
  148. package/src/tui-ga-compiled/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
  149. package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
  150. package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +135 -18
  151. package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +1 -1
  152. package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +378 -0
  153. package/src/tui-ga-raw/host-ga.tsx +71 -30
  154. package/src/tui-ga-raw/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
  155. package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
  156. package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +135 -18
  157. package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +1 -1
  158. package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +391 -0
  159. package/src/tui-raw/common-auth-embedded/quota/format.js +135 -18
  160. package/src/tui-raw/common-auth-embedded/quota/index.js +1 -1
  161. package/src/tui-raw/tui/quota-layout.tsx +391 -0
  162. package/src/tui-raw/tui/route-layout.js +30 -0
  163. package/src/tui-raw/tui.tsx +50 -309
  164. package/src/tui.tsx +50 -309
@@ -0,0 +1,79 @@
1
+ import { redact } from '../logger/redact.js';
2
+ import { STDERR_TAIL_MAX_BYTES } from './command-runner.js';
3
+ const PI_INSTALL_ERROR_MESSAGE = 'Pi install failed; run pi install after checking your npm connection.';
4
+ function utf8Tail(value) {
5
+ const bytes = Buffer.from(value, 'utf8');
6
+ if (bytes.length <= STDERR_TAIL_MAX_BYTES)
7
+ return value;
8
+ let start = bytes.length - STDERR_TAIL_MAX_BYTES;
9
+ while (start < bytes.length) {
10
+ const byte = bytes[start];
11
+ if (byte === undefined || (byte & 0xc0) !== 0x80)
12
+ break;
13
+ start++;
14
+ }
15
+ return bytes.subarray(start).toString('utf8');
16
+ }
17
+ function dropPartialLine(tail) {
18
+ const newline = tail.indexOf('\n');
19
+ return newline < 0 ? '' : tail.slice(newline + 1);
20
+ }
21
+ /**
22
+ * Keeps the Pi install refusal message stable while exposing safe process details.
23
+ * A clipped tail can start inside a credential, so discard its first line—or
24
+ * the whole tail if it has no newline—before redacting.
25
+ */
26
+ export class SetupCommandError extends Error {
27
+ step = 'pi-install';
28
+ exitCode;
29
+ signal;
30
+ stderrTail;
31
+ constructor(details) {
32
+ super(PI_INSTALL_ERROR_MESSAGE);
33
+ this.name = 'SetupCommandError';
34
+ this.exitCode = details.exitCode;
35
+ this.signal = details.signal;
36
+ const tail = details.stderrTruncated
37
+ ? dropPartialLine(details.stderrTail)
38
+ : details.stderrTail;
39
+ const redacted = redact(tail);
40
+ this.stderrTail = utf8Tail(typeof redacted === 'string' ? redacted : '');
41
+ }
42
+ }
43
+ const HOST_LABELS = { opencode: 'OpenCode', pi: 'Pi' };
44
+ const OUTCOME_TEXT = {
45
+ enrolled: 'connected to the vault',
46
+ 'not-enrolled': 'not connected',
47
+ unknown: 'unknown, check with ck auth status',
48
+ };
49
+ /** The line setup prints for one host's outcome, e.g. `Pi: not connected`. */
50
+ export function setupEnrollmentLine({ host, outcome, }) {
51
+ return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}`;
52
+ }
53
+ // Outcomes recorded against the value a failed `runSetup` threw. A WeakMap
54
+ // keeps the thrown value itself untouched: setup never reads, rewrites or
55
+ // stringifies what a step or plugin callback threw, so a getter, a proxy or a
56
+ // frozen error behaves exactly as it would without setup in between, and
57
+ // callers that classify errors by message see the original text.
58
+ const recordedEnrollment = new WeakMap();
59
+ /**
60
+ * Remember which hosts a failed setup left connected to the vault, against the
61
+ * thrown value. Only objects can carry a record; a thrown primitive is left as
62
+ * it is, and the printed lines are then the only report.
63
+ */
64
+ export function recordSetupEnrollment(failure, enrollment) {
65
+ if ((typeof failure !== 'object' && typeof failure !== 'function') ||
66
+ !failure)
67
+ return;
68
+ recordedEnrollment.set(failure, Object.freeze(enrollment.map((entry) => Object.freeze({ ...entry }))));
69
+ }
70
+ /**
71
+ * The per-host vault enrollment outcomes a failed `runSetup` recorded for the
72
+ * value it threw, or `undefined` when setup failed before any host's enrollment
73
+ * began, or the value is not one setup threw (or is not an object).
74
+ */
75
+ export function setupEnrollment(error) {
76
+ if ((typeof error !== 'object' && typeof error !== 'function') || !error)
77
+ return undefined;
78
+ return recordedEnrollment.get(error);
79
+ }
@@ -1,35 +1,129 @@
1
- import { execFile } from 'node:child_process';
1
+ import { spawn } from 'node:child_process';
2
+ export const STDERR_TAIL_MAX_BYTES = 4 * 1024;
3
+ const STDOUT_MAX_BYTES = 1024 * 1024;
4
+ class ByteTail {
5
+ buffer = Buffer.alloc(STDERR_TAIL_MAX_BYTES);
6
+ start = 0;
7
+ length = 0;
8
+ truncated = false;
9
+ get didTruncate() {
10
+ return this.truncated;
11
+ }
12
+ push(chunk) {
13
+ if (chunk.length >= STDERR_TAIL_MAX_BYTES) {
14
+ if (chunk.length > STDERR_TAIL_MAX_BYTES || this.length > 0)
15
+ this.truncated = true;
16
+ chunk.copy(this.buffer, 0, chunk.length - STDERR_TAIL_MAX_BYTES);
17
+ this.start = 0;
18
+ this.length = STDERR_TAIL_MAX_BYTES;
19
+ return;
20
+ }
21
+ const overflow = Math.max(0, this.length + chunk.length - STDERR_TAIL_MAX_BYTES);
22
+ if (overflow > 0)
23
+ this.truncated = true;
24
+ this.start = (this.start + overflow) % STDERR_TAIL_MAX_BYTES;
25
+ this.length -= overflow;
26
+ const writeAt = (this.start + this.length) % STDERR_TAIL_MAX_BYTES;
27
+ const firstLength = Math.min(chunk.length, STDERR_TAIL_MAX_BYTES - writeAt);
28
+ chunk.copy(this.buffer, writeAt, 0, firstLength);
29
+ if (firstLength < chunk.length)
30
+ chunk.copy(this.buffer, 0, firstLength);
31
+ this.length += chunk.length;
32
+ }
33
+ toString() {
34
+ const bytes = Buffer.alloc(this.length);
35
+ const firstLength = Math.min(this.length, STDERR_TAIL_MAX_BYTES - this.start);
36
+ this.buffer.copy(bytes, 0, this.start, this.start + firstLength);
37
+ if (firstLength < this.length)
38
+ this.buffer.copy(bytes, firstLength, 0, this.length - firstLength);
39
+ let start = 0;
40
+ while (start < bytes.length) {
41
+ const byte = bytes[start];
42
+ if (byte === undefined || (byte & 0xc0) !== 0x80)
43
+ break;
44
+ start++;
45
+ }
46
+ return bytes.subarray(start).toString('utf8');
47
+ }
48
+ }
2
49
  export const defaultCommandRunner = {
3
50
  run(file, args, options = {}) {
4
51
  return new Promise((resolve) => {
5
52
  const started = performance.now();
6
53
  const timeoutMs = options.timeoutMs ?? 15_000;
7
- execFile(file, [...args], {
8
- env: options.env ?? process.env,
9
- timeout: timeoutMs,
10
- windowsHide: true,
11
- windowsVerbatimArguments: options.windowsVerbatimArguments,
12
- maxBuffer: 1024 * 1024,
13
- }, (error, stdout, stderr) => {
14
- const durationMs = performance.now() - started;
54
+ const stderr = new ByteTail();
55
+ const stdout = [];
56
+ let stdoutLength = 0;
57
+ let outputExceeded = false;
58
+ let spawnError = false;
59
+ let timedOut = false;
60
+ let child;
61
+ try {
62
+ child = spawn(file, [...args], {
63
+ env: options.env ?? process.env,
64
+ windowsHide: true,
65
+ windowsVerbatimArguments: options.windowsVerbatimArguments,
66
+ stdio: ['ignore', 'pipe', 'pipe'],
67
+ });
68
+ }
69
+ catch {
70
+ resolve({
71
+ exitCode: 1,
72
+ stdout: '',
73
+ stderr: '',
74
+ spawnError: true,
75
+ signal: null,
76
+ timedOut: false,
77
+ durationMs: performance.now() - started,
78
+ });
79
+ return;
80
+ }
81
+ const timer = timeoutMs > 0
82
+ ? setTimeout(() => {
83
+ timedOut = true;
84
+ child.kill('SIGTERM');
85
+ }, timeoutMs)
86
+ : undefined;
87
+ child.stdout?.on('data', (chunk) => {
88
+ const remaining = STDOUT_MAX_BYTES - stdoutLength;
89
+ const length = Math.min(remaining, chunk.length);
90
+ if (length > 0) {
91
+ stdout.push(chunk.subarray(0, length));
92
+ stdoutLength += length;
93
+ }
94
+ if (chunk.length > remaining) {
95
+ outputExceeded = true;
96
+ child.kill('SIGTERM');
97
+ }
98
+ });
99
+ child.stderr?.on('data', (chunk) => stderr.push(chunk));
100
+ let settled = false;
101
+ const settle = (code, signal) => {
102
+ if (settled)
103
+ return;
104
+ settled = true;
105
+ if (timer)
106
+ clearTimeout(timer);
15
107
  resolve({
16
- exitCode: error
17
- ? typeof error.code === 'number'
18
- ? error.code
19
- : 1
20
- : 0,
21
- stdout: String(stdout ?? ''),
22
- stderr: String(stderr ?? ''),
23
- signal: error?.signal ?? null,
24
- // Buffer-limit and spawn errors have string codes, not timeout kills.
25
- timedOut: error?.killed === true &&
26
- typeof error.code !== 'string' &&
27
- error.signal === 'SIGTERM' &&
28
- durationMs >= timeoutMs &&
29
- timeoutMs > 0,
30
- durationMs,
108
+ exitCode: spawnError ? 1 : outputExceeded ? 1 : (code ?? 1),
109
+ stdout: Buffer.concat(stdout, stdoutLength).toString('utf8'),
110
+ stderr: stderr.toString(),
111
+ stderrTruncated: stderr.didTruncate,
112
+ ...(spawnError ? { spawnError: true } : {}),
113
+ signal: signal ?? null,
114
+ timedOut,
115
+ durationMs: performance.now() - started,
31
116
  });
117
+ };
118
+ child.once('error', () => {
119
+ spawnError = true;
120
+ // A child that never started (ENOENT, EACCES) has no process for the
121
+ // timer to kill. Node documents no guarantee that 'close' follows that
122
+ // 'error', so settle here rather than wait for it.
123
+ if (child.pid === undefined)
124
+ settle(null, null);
32
125
  });
126
+ child.once('close', (code, signal) => settle(code, signal));
33
127
  });
34
128
  },
35
129
  };
@@ -1,9 +1,10 @@
1
1
  import { select } from '../auth-menu/select.js';
2
2
  import { isInteractive, printLine, processTerminal, } from '../auth-menu/terminal.js';
3
- import { hostEnrollmentPaths } from '../claustrum/enrollment.js';
3
+ import { enrollmentAuthority, hostEnrollmentPaths, } from '../claustrum/enrollment.js';
4
+ import { recordSetupEnrollment, setupEnrollmentLine } from './command-error.js';
4
5
  import { defaultCommandRunner } from './command-runner.js';
5
6
  import { detectHosts } from './detect.js';
6
- import { connectSetupHost } from './enroll.js';
7
+ import { connectSetupHost, HostNotEnrolledError } from './enroll.js';
7
8
  import { setupPaths } from './paths.js';
8
9
  import { assertHostsStopped, createProcessFence, ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
9
10
  import { selectSetupHosts } from './prompts.js';
@@ -52,6 +53,29 @@ function validatePlugin(plugin) {
52
53
  throw new Error('Setup requires lowercase vault names containing only letters, digits and dashes.');
53
54
  }
54
55
  }
56
+ /**
57
+ * Turn what setup recorded into one outcome per selected host, in setup order.
58
+ * A host setup never reached was never asked to enroll. Only a host whose
59
+ * enrollment was in flight when setup failed is checked on disk, by reading its
60
+ * enrollment files once with `enrollmentAuthority`; if that read fails it stays
61
+ * `unknown`.
62
+ */
63
+ async function enrollmentReport(plugin, hosts, recorded) {
64
+ const report = [];
65
+ for (const host of hosts) {
66
+ let outcome = recorded.get(host) ?? 'not-enrolled';
67
+ if (outcome === 'unknown') {
68
+ const { name, paths } = plugin.vault.hosts[host];
69
+ const authority = await enrollmentAuthority(hostEnrollmentPaths(paths), name).catch(() => 'unreadable');
70
+ if (authority === 'vault')
71
+ outcome = 'enrolled';
72
+ else if (authority === 'local')
73
+ outcome = 'not-enrolled';
74
+ }
75
+ report.push({ host, outcome });
76
+ }
77
+ return report;
78
+ }
55
79
  export async function runSetup(plugin, argv = [], io = {}) {
56
80
  const options = flags(argv);
57
81
  validatePlugin(plugin);
@@ -190,23 +214,55 @@ export async function runSetup(plugin, argv = [], io = {}) {
190
214
  hosts: Object.freeze([...hosts]),
191
215
  piAgentDir: detection.pi.directory,
192
216
  };
193
- for (const host of hosts) {
194
- await stopped();
195
- await plugin.beforeSignIn?.(host, context);
196
- await stopped();
197
- if (useVault)
198
- await connectSetupHost(plugin, host, io, terminal, stopped);
199
- else
200
- await plugin.signInLocal(host, context);
201
- await stopped();
202
- await plugin.beforeRegister?.(host, mode, context);
203
- await stopped();
204
- if (host === 'opencode')
205
- await registerOpenCode(writes, stopped);
206
- else
207
- await registerPi(plugin, detection.pi.executable, io);
208
- await stopped();
209
- await plugin.migrate(host, context);
217
+ // Each host's vault enrollment as it happens. A host the operator approved
218
+ // stays enrolled if a later step fails, so a failure reports this record.
219
+ const enrollment = new Map();
220
+ try {
221
+ for (const host of hosts) {
222
+ await stopped();
223
+ await plugin.beforeSignIn?.(host, context);
224
+ await stopped();
225
+ if (useVault) {
226
+ enrollment.set(host, 'unknown');
227
+ try {
228
+ await connectSetupHost(plugin, host, io, terminal, stopped);
229
+ }
230
+ catch (error) {
231
+ if (error instanceof HostNotEnrolledError)
232
+ enrollment.set(host, 'not-enrolled');
233
+ throw error;
234
+ }
235
+ enrollment.set(host, 'enrolled');
236
+ }
237
+ else
238
+ await plugin.signInLocal(host, context);
239
+ await stopped();
240
+ await plugin.beforeRegister?.(host, mode, context);
241
+ await stopped();
242
+ if (host === 'opencode')
243
+ await registerOpenCode(writes, stopped);
244
+ else
245
+ await registerPi(plugin, detection.pi.executable, io);
246
+ await stopped();
247
+ await plugin.migrate(host, context);
248
+ }
249
+ }
250
+ catch (error) {
251
+ // Before any enrollment began nothing is connected: nothing to report.
252
+ if (enrollment.size === 0)
253
+ throw error;
254
+ // A host the operator approved stays enrolled after a later step fails.
255
+ // Print which hosts are connected and record it for `setupEnrollment`,
256
+ // then rethrow the original value untouched. Reporting must never
257
+ // replace the failure, so its own errors are ignored.
258
+ try {
259
+ const report = await enrollmentReport(plugin, hosts, enrollment);
260
+ recordSetupEnrollment(error, report);
261
+ for (const entry of report)
262
+ printLine(terminal, setupEnrollmentLine(entry));
263
+ }
264
+ catch { }
265
+ throw error;
210
266
  }
211
267
  }
212
268
  printLine(terminal, `${options.dryRun ? 'Planned' : 'Configured'} ${plugin.displayName} for ${hosts.join(', ')} (${mode}).`);
@@ -3,6 +3,16 @@ import { writeEnrollmentTokenFile } from '@cortexkit/claustrum-client';
3
3
  import { printLine } from '../auth-menu/terminal.js';
4
4
  import { ClaustrumEnrollmentManager, connectClaustrumEnrollmentClient, hostEnrollmentPaths, } from '../claustrum/enrollment.js';
5
5
  import { ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
6
+ const ENROLLMENT_INCOMPLETE_MESSAGE = 'Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.';
7
+ /**
8
+ * 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.
13
+ */
14
+ export class HostNotEnrolledError extends Error {
15
+ }
6
16
  /** Enroll an independently revocable host; plugin callbacks choose its credential store and account permissions. */
7
17
  export async function connectSetupHost(plugin, host, io, terminal, fence) {
8
18
  const { name, paths: input } = plugin.vault.hosts[host];
@@ -12,7 +22,7 @@ export async function connectSetupHost(plugin, host, io, terminal, fence) {
12
22
  connectionFile: plugin.vault.connectionFile,
13
23
  handshakeTimeoutMs: 2000,
14
24
  }).catch(() => {
15
- throw new Error('Claustrum connection failed; start ck and rerun setup.');
25
+ throw new HostNotEnrolledError('Claustrum connection failed; start ck and rerun setup.');
16
26
  });
17
27
  try {
18
28
  const manager = new ClaustrumEnrollmentManager({
@@ -42,12 +52,12 @@ export async function connectSetupHost(plugin, host, io, terminal, fence) {
42
52
  return;
43
53
  }
44
54
  if (status.state !== 'pending' && status.state !== 'busy')
45
- throw new Error('Claustrum enrollment refused; inspect its status with ck before rerunning setup.');
55
+ throw new HostNotEnrolledError('Claustrum enrollment refused; inspect its status with ck before rerunning setup.');
46
56
  if (status.state === 'pending' &&
47
57
  status.requestId &&
48
58
  status.requestId !== printedRequest) {
49
59
  if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
50
- throw new Error('Invalid enrollment request id.');
60
+ throw new HostNotEnrolledError('Invalid enrollment request id.');
51
61
  printedRequest = status.requestId;
52
62
  printLine(terminal, 'Waiting for approval. In another terminal, run:');
53
63
  printLine(terminal, ` ck auth enroll approve --request-id ${status.requestId} --name ${name}`);
@@ -55,14 +65,16 @@ export async function connectSetupHost(plugin, host, io, terminal, fence) {
55
65
  }
56
66
  await (io.wait ?? delay)(1000);
57
67
  }
58
- throw new Error('Claustrum approval is still pending; approve with ck and rerun setup.');
68
+ throw new HostNotEnrolledError('Claustrum approval is still pending; approve with ck and rerun setup.');
59
69
  }
60
70
  catch (error) {
61
71
  if (error instanceof ProcessFenceViolationError ||
62
72
  error instanceof ProcessInspectionError)
63
73
  throw error;
64
74
  // Enrollment exceptions can carry request secrets or bearer tokens; never display them.
65
- throw new Error('Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.');
75
+ if (error instanceof HostNotEnrolledError)
76
+ throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE);
77
+ throw new Error(ENROLLMENT_INCOMPLETE_MESSAGE);
66
78
  }
67
79
  finally {
68
80
  client.close();
@@ -1,5 +1,6 @@
1
1
  export { AMBIGUOUS_OPENCODE_MESSAGE, runSetup } from './command.js';
2
+ export { SetupCommandError, setupEnrollment } from './command-error.js';
2
3
  export { detectHosts, detectOpenCodeGeneration, findExecutableOnPath, openCodeDesktopMarkers, } from './detect.js';
3
4
  export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, type ProcessInspectionStep, } from './process-fence.js';
4
5
  export { type PlannedWrite, planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
5
- export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnvironment, SetupFileSystem, SetupHost, SetupIO, SetupPlugin, SetupResult, } from './types.js';
6
+ export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnrollmentOutcome, SetupEnvironment, SetupFileSystem, SetupHost, SetupHostEnrollment, SetupIO, SetupPlugin, SetupResult, } from './types.js';
@@ -1,4 +1,5 @@
1
1
  export { AMBIGUOUS_OPENCODE_MESSAGE, runSetup } from './command.js';
2
+ export { SetupCommandError, setupEnrollment } from './command-error.js';
2
3
  export { detectHosts, detectOpenCodeGeneration, findExecutableOnPath, openCodeDesktopMarkers, } from './detect.js';
3
4
  export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
4
5
  export { planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
@@ -1,4 +1,5 @@
1
1
  import { applyEdits, createScanner, findNodeAtLocation, modify, parse, parseTree, } from 'jsonc-parser';
2
+ import { SetupCommandError } from './command-error.js';
2
3
  import { defaultCommandRunner, runResolvedCommand } from './command-runner.js';
3
4
  import { writeHostConfigAtomic } from './config-write.js';
4
5
  import { defaultSetupFileSystem } from './detect.js';
@@ -125,6 +126,11 @@ export async function registerOpenCode(writes, beforeWrite) {
125
126
  export async function registerPi(plugin, executable, io = {}) {
126
127
  const { platform, env } = setupPaths(io);
127
128
  const result = await runResolvedCommand(io.runner ?? defaultCommandRunner, platform, executable, ['install', `npm:${plugin.packages.pi}@${plugin.version}`], env);
128
- if (result.exitCode !== 0)
129
- throw new Error('Pi install failed; run pi install after checking your npm connection.');
129
+ if (result.exitCode !== 0 || result.timedOut)
130
+ throw new SetupCommandError({
131
+ exitCode: result.spawnError ? null : result.exitCode,
132
+ signal: result.signal ?? null,
133
+ stderrTail: result.stderr,
134
+ stderrTruncated: result.stderrTruncated ?? false,
135
+ });
130
136
  }
@@ -3,6 +3,18 @@ import type { ClaustrumEnrollmentConnection, hostEnrollmentPaths } from '../clau
3
3
  export type SetupHost = 'opencode' | 'pi';
4
4
  export type OpenCodeGeneration = '1' | '2' | 'both';
5
5
  export type SetupEnvironment = Record<string, string | undefined>;
6
+ /**
7
+ * What a setup run recorded about one host's vault enrollment when it failed:
8
+ * `enrolled` once approval landed and the token was written, `not-enrolled`
9
+ * when the host was never asked or its enrollment was refused or gave up
10
+ * waiting, and `unknown` when setup failed while the enrollment was still in
11
+ * flight and the host's token file could not settle it.
12
+ */
13
+ export type SetupEnrollmentOutcome = 'enrolled' | 'not-enrolled' | 'unknown';
14
+ export interface SetupHostEnrollment {
15
+ host: SetupHost;
16
+ outcome: SetupEnrollmentOutcome;
17
+ }
6
18
  /**
7
19
  * What setup decided before calling a plugin callback. The OpenCode generation
8
20
  * is the one being registered, after `--opencode` or the interactive choice, so
@@ -57,6 +69,8 @@ export interface CommandResult {
57
69
  exitCode: number;
58
70
  stdout: string;
59
71
  stderr: string;
72
+ spawnError?: boolean;
73
+ stderrTruncated?: boolean;
60
74
  signal?: NodeJS.Signals | null;
61
75
  timedOut?: boolean;
62
76
  durationMs?: number;