overvues 0.0.1 → 0.4.10

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 (78) hide show
  1. package/README.md +58 -2
  2. package/dist/ansi.js +24 -0
  3. package/dist/attach-client.js +586 -0
  4. package/dist/auth-connect-browser.js +112 -0
  5. package/dist/auth-connect.js +306 -0
  6. package/dist/browser-bootstrap.js +190 -0
  7. package/dist/browser-loopback.js +289 -0
  8. package/dist/build-identity.js +6 -0
  9. package/dist/codex-reviewer-apparmor.json +4 -0
  10. package/dist/codex-reviewer-seccomp.json +1238 -0
  11. package/dist/codex-runtime-protocol.js +1 -0
  12. package/dist/codex-subscription.js +53 -0
  13. package/dist/config.js +297 -0
  14. package/dist/connect-comparison-code.js +26 -0
  15. package/dist/development-runner.js +109 -0
  16. package/dist/dns-doctor.js +390 -0
  17. package/dist/docker-names.js +47 -0
  18. package/dist/doctor.js +114 -0
  19. package/dist/gadget-job.js +804 -0
  20. package/dist/health-check.js +112 -0
  21. package/dist/help.js +71 -0
  22. package/dist/host-auth.js +22 -0
  23. package/dist/host-diagnostics.js +20 -0
  24. package/dist/host-runtime-identity.js +39 -0
  25. package/dist/host-runtime-metadata.js +56 -0
  26. package/dist/host-service.js +377 -0
  27. package/dist/host-stack.js +484 -0
  28. package/dist/host-supervisor.js +237 -0
  29. package/dist/host-update.js +387 -0
  30. package/dist/hub-address.js +100 -0
  31. package/dist/hub-client.js +459 -0
  32. package/dist/hub-kind.js +88 -0
  33. package/dist/identity.js +73 -0
  34. package/dist/index.js +185 -0
  35. package/dist/init.js +295 -0
  36. package/dist/isolated-run-cache.js +116 -0
  37. package/dist/local-stack.js +685 -0
  38. package/dist/machine-capacity.js +128 -0
  39. package/dist/managed-runner-image.js +13 -0
  40. package/dist/os-acted-record.js +49 -0
  41. package/dist/os-adapter.js +8190 -0
  42. package/dist/os-command.js +292 -0
  43. package/dist/os-handoff.js +274 -0
  44. package/dist/os-keychain.js +247 -0
  45. package/dist/os-machine.js +818 -0
  46. package/dist/os-owner.js +61 -0
  47. package/dist/os-private-file.js +98 -0
  48. package/dist/os-protocol.js +468 -0
  49. package/dist/os-session-store.js +133 -0
  50. package/dist/os-status.js +102 -0
  51. package/dist/picker.js +863 -0
  52. package/dist/portable-workspace-capability.js +60 -0
  53. package/dist/project-environment-capability.js +62 -0
  54. package/dist/project-environment.js +28 -0
  55. package/dist/project-preparation.js +134 -0
  56. package/dist/readiness.js +28 -0
  57. package/dist/redaction.js +27 -0
  58. package/dist/reviewer-isolation-capability.js +61 -0
  59. package/dist/runner-api-auth.js +80 -0
  60. package/dist/runner-command-fence.js +536 -0
  61. package/dist/runner-inspection.js +57 -0
  62. package/dist/runner-inventory.js +587 -0
  63. package/dist/runner-server.js +2520 -0
  64. package/dist/runner-session.js +470 -0
  65. package/dist/runner-slug-folder.js +39 -0
  66. package/dist/runner-slug.js +40 -0
  67. package/dist/setup.js +139 -0
  68. package/dist/shutdown.js +102 -0
  69. package/dist/splash.js +65 -0
  70. package/dist/staged-workspaces.js +441 -0
  71. package/dist/staging-disk.js +97 -0
  72. package/dist/terminal-lane.js +339 -0
  73. package/dist/terminal-recovery.js +502 -0
  74. package/licenses/capnweb.txt +23 -0
  75. package/licenses/moby-profiles.txt +212 -0
  76. package/licenses/ws.txt +22 -0
  77. package/package.json +28 -7
  78. package/cli.js +0 -2
@@ -0,0 +1,390 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { spawnSync } from "node:child_process";
5
+ import { resolve4 } from "node:dns/promises";
6
+ import { HUB_URL, LOCAL_STATE_DIR } from "./config.js";
7
+ import { ansi } from "./ansi.js";
8
+ import { CLI } from "./identity.js";
9
+ const PUBLIC_DNS_PRIMARY = "1.1.1.1";
10
+ const PUBLIC_DNS_SECONDARY = "8.8.8.8";
11
+ const STATE_DIR = join(LOCAL_STATE_DIR || tmpdir(), "dns-doctor");
12
+ const RESOLVER_DIR = "/etc/resolver";
13
+ function usage() {
14
+ process.stderr.write(`Usage: ${CLI.command} doctor dns [status|repair|restore] [--hostname example.com] [--network-service "Wi-Fi"]\n`);
15
+ }
16
+ function runCommand(command, args, inherit = false) {
17
+ const result = spawnSync(command, args, {
18
+ encoding: "utf8",
19
+ stdio: inherit ? "inherit" : ["ignore", "pipe", "pipe"],
20
+ });
21
+ return {
22
+ ok: result.status === 0,
23
+ stdout: result.stdout ?? "",
24
+ stderr: result.stderr ?? "",
25
+ status: result.status,
26
+ };
27
+ }
28
+ function sanitizeServiceName(value) {
29
+ return value.replace(/[^\w.-]+/g, "_");
30
+ }
31
+ function stateFileForHostname(hostname) {
32
+ return join(STATE_DIR, `host-${sanitizeServiceName(hostname)}.json`);
33
+ }
34
+ function resolverFileForHostname(hostname) {
35
+ return join(RESOLVER_DIR, hostname);
36
+ }
37
+ function parseHostnameFromUrl(hubUrl) {
38
+ try {
39
+ return new URL(hubUrl).hostname || "";
40
+ }
41
+ catch {
42
+ return "";
43
+ }
44
+ }
45
+ export function parseDnsDoctorArgs(argv) {
46
+ let action = "status";
47
+ let hostname;
48
+ let networkService;
49
+ let actionSet = false;
50
+ for (let i = 0; i < argv.length; i += 1) {
51
+ const arg = argv[i];
52
+ if (arg === "--hostname" || arg === "--host") {
53
+ const value = argv[i + 1];
54
+ if (!value || value.startsWith("--")) {
55
+ throw new Error(`${arg} requires a value`);
56
+ }
57
+ hostname = value.trim();
58
+ i += 1;
59
+ continue;
60
+ }
61
+ if (arg.startsWith("--hostname=") || arg.startsWith("--host=")) {
62
+ const value = arg.slice(arg.indexOf("=") + 1).trim();
63
+ if (!value)
64
+ throw new Error("hostname requires a value");
65
+ hostname = value;
66
+ continue;
67
+ }
68
+ if (arg === "--network-service") {
69
+ const value = argv[i + 1];
70
+ if (!value || value.startsWith("--")) {
71
+ throw new Error("--network-service requires a value");
72
+ }
73
+ networkService = value.trim();
74
+ i += 1;
75
+ continue;
76
+ }
77
+ if (arg.startsWith("--network-service=")) {
78
+ const value = arg.slice("--network-service=".length).trim();
79
+ if (!value)
80
+ throw new Error("network service requires a value");
81
+ networkService = value;
82
+ continue;
83
+ }
84
+ if (!actionSet && (arg === "status" || arg === "repair" || arg === "restore")) {
85
+ action = arg;
86
+ actionSet = true;
87
+ continue;
88
+ }
89
+ if (!hostname) {
90
+ hostname = arg.trim();
91
+ continue;
92
+ }
93
+ throw new Error(`Unexpected argument: ${arg}`);
94
+ }
95
+ return { action, ...(hostname ? { hostname } : {}), ...(networkService ? { networkService } : {}) };
96
+ }
97
+ export function resolveDnsDoctorHostname(options, dependencies) {
98
+ const explicit = options.hostname?.trim();
99
+ if (explicit)
100
+ return explicit;
101
+ const inferred = parseHostnameFromUrl(dependencies.hubUrl);
102
+ if (inferred)
103
+ return inferred;
104
+ throw new Error(`No hostname provided and no hub URL is configured. Pass --hostname or run \`${CLI.command} init\`.`);
105
+ }
106
+ function readLocalResolverMac(hostname) {
107
+ const result = runCommand("dscacheutil", ["-q", "host", "-a", "name", hostname]);
108
+ if (!result.ok)
109
+ return [];
110
+ return result.stdout
111
+ .split(/\r?\n/)
112
+ .map((line) => line.trim())
113
+ .filter((line) => line.startsWith("ip_address: "))
114
+ .map((line) => line.slice("ip_address: ".length).trim())
115
+ .filter(Boolean);
116
+ }
117
+ async function readLocalResolver(hostname, platform) {
118
+ if (platform === "darwin") {
119
+ return readLocalResolverMac(hostname);
120
+ }
121
+ try {
122
+ return await resolve4(hostname);
123
+ }
124
+ catch {
125
+ return [];
126
+ }
127
+ }
128
+ async function readPublicResolver(hostname) {
129
+ try {
130
+ const response = await fetch(`https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(hostname)}&type=A`, {
131
+ headers: { accept: "application/dns-json" },
132
+ signal: AbortSignal.timeout(3000),
133
+ });
134
+ if (!response.ok)
135
+ return [];
136
+ const body = await response.json();
137
+ if (body.Status !== 0 || !Array.isArray(body.Answer))
138
+ return [];
139
+ return body.Answer
140
+ .filter((answer) => answer?.type === 1 && typeof answer.data === "string")
141
+ .map((answer) => answer.data.trim())
142
+ .filter(Boolean);
143
+ }
144
+ catch {
145
+ return [];
146
+ }
147
+ }
148
+ function verifyHostnameViaIp(hostname, ip) {
149
+ const result = runCommand("curl", [
150
+ "--connect-timeout",
151
+ "5",
152
+ "--resolve",
153
+ `${hostname}:443:${ip}`,
154
+ "-I",
155
+ "-sS",
156
+ `https://${hostname}/`,
157
+ ]);
158
+ return result.ok;
159
+ }
160
+ function printDnsServers(service) {
161
+ const result = runCommand("networksetup", ["-getdnsservers", service]);
162
+ return result.ok ? result.stdout.trim() : result.stderr.trim();
163
+ }
164
+ function defaultInterface() {
165
+ const result = runCommand("route", ["-n", "get", "default"]);
166
+ if (!result.ok)
167
+ return "";
168
+ const line = result.stdout.split(/\r?\n/).find((entry) => entry.includes("interface:"));
169
+ return line?.split("interface:")[1]?.trim() || "";
170
+ }
171
+ function serviceForInterface(iface) {
172
+ const result = runCommand("networksetup", ["-listnetworkserviceorder"]);
173
+ if (!result.ok)
174
+ return "";
175
+ const lines = result.stdout.split(/\r?\n/);
176
+ let currentService = "";
177
+ for (const line of lines) {
178
+ const serviceMatch = line.match(/^\(\d+\)\s+(.*)$/);
179
+ if (serviceMatch) {
180
+ currentService = serviceMatch[1].replace(/^\*\s+/, "").trim();
181
+ continue;
182
+ }
183
+ if (line.includes(`Device: ${iface})`)) {
184
+ return currentService;
185
+ }
186
+ }
187
+ return "";
188
+ }
189
+ function resolveNetworkService(explicit) {
190
+ if (explicit?.trim())
191
+ return explicit.trim();
192
+ const iface = defaultInterface();
193
+ if (!iface) {
194
+ throw new Error("Could not determine the default network interface. Pass --network-service explicitly.");
195
+ }
196
+ const service = serviceForInterface(iface);
197
+ if (!service) {
198
+ throw new Error(`Could not map interface ${iface} to a macOS network service. Pass --network-service explicitly.`);
199
+ }
200
+ return service;
201
+ }
202
+ function ensureStateDir() {
203
+ mkdirSync(STATE_DIR, { recursive: true });
204
+ }
205
+ function saveScopedResolverState(hostname) {
206
+ ensureStateDir();
207
+ const statePath = stateFileForHostname(hostname);
208
+ if (existsSync(statePath))
209
+ return;
210
+ const resolverPath = resolverFileForHostname(hostname);
211
+ const state = existsSync(resolverPath)
212
+ ? { mode: "file", content: readFileSync(resolverPath, "utf8") }
213
+ : { mode: "absent" };
214
+ writeFileSync(statePath, `${JSON.stringify(state, null, 2)}\n`);
215
+ }
216
+ export function renderScopedResolverConfig(hostname) {
217
+ return [
218
+ `# Added by ${CLI.command} doctor dns repair for ${hostname}`,
219
+ `nameserver ${PUBLIC_DNS_PRIMARY}`,
220
+ `nameserver ${PUBLIC_DNS_SECONDARY}`,
221
+ "",
222
+ ].join("\n");
223
+ }
224
+ function writeScopedResolver(hostname, content) {
225
+ ensureStateDir();
226
+ const destination = resolverFileForHostname(hostname);
227
+ const tempPath = join(STATE_DIR, `${sanitizeServiceName(hostname)}.resolver.tmp`);
228
+ writeFileSync(tempPath, content);
229
+ try {
230
+ const ensureDir = runCommand("sudo", ["mkdir", "-p", RESOLVER_DIR], true);
231
+ if (!ensureDir.ok)
232
+ throw new Error(`Failed to create ${RESOLVER_DIR}.`);
233
+ const copy = runCommand("sudo", ["cp", tempPath, destination], true);
234
+ if (!copy.ok)
235
+ throw new Error(`Failed to write scoped resolver for ${hostname}.`);
236
+ const chmod = runCommand("sudo", ["chmod", "644", destination], true);
237
+ if (!chmod.ok)
238
+ throw new Error(`Failed to set permissions on scoped resolver for ${hostname}.`);
239
+ }
240
+ finally {
241
+ rmSync(tempPath, { force: true });
242
+ }
243
+ }
244
+ function installScopedResolver(hostname) {
245
+ writeScopedResolver(hostname, renderScopedResolverConfig(hostname));
246
+ }
247
+ function restoreScopedResolverState(hostname) {
248
+ const statePath = stateFileForHostname(hostname);
249
+ const state = JSON.parse(readFileSync(statePath, "utf8"));
250
+ const resolverPath = resolverFileForHostname(hostname);
251
+ if (state.mode === "absent") {
252
+ const result = runCommand("sudo", ["rm", "-f", resolverPath], true);
253
+ if (!result.ok)
254
+ throw new Error(`Failed to remove scoped resolver for ${hostname}.`);
255
+ }
256
+ else if (state.mode === "file" && typeof state.content === "string") {
257
+ writeScopedResolver(hostname, state.content);
258
+ }
259
+ else {
260
+ throw new Error(`Invalid saved DNS repair state for ${hostname}.`);
261
+ }
262
+ flushMacDns();
263
+ rmSync(statePath, { force: true });
264
+ }
265
+ function flushMacDns() {
266
+ const flush = runCommand("sudo", ["dscacheutil", "-flushcache"], true);
267
+ if (!flush.ok)
268
+ throw new Error("Failed to flush the macOS DNS cache.");
269
+ const reload = runCommand("sudo", ["killall", "-HUP", "mDNSResponder"], true);
270
+ if (!reload.ok)
271
+ throw new Error("Failed to reload mDNSResponder.");
272
+ }
273
+ async function printStatus(hostname, service, platform) {
274
+ const localIps = await readLocalResolver(hostname, platform);
275
+ const publicIps = await readPublicResolver(hostname);
276
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} DNS doctor for ${hostname}\n`);
277
+ if (service) {
278
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Network service ${ansi.dim}${service}${ansi.reset}\n`);
279
+ const dnsServers = printDnsServers(service);
280
+ if (dnsServers) {
281
+ const rendered = dnsServers.replace(/\r?\n/g, ", ");
282
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} DNS servers ${ansi.dim}${rendered}${ansi.reset}\n`);
283
+ }
284
+ }
285
+ if (platform === "darwin") {
286
+ const resolverPath = resolverFileForHostname(hostname);
287
+ if (existsSync(resolverPath)) {
288
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Scoped resolver ${ansi.dim}${resolverPath}${ansi.reset}\n`);
289
+ }
290
+ }
291
+ const localDetail = localIps.length > 0 ? localIps.join(", ") : "(no local result)";
292
+ const publicDetail = publicIps.length > 0 ? publicIps.join(", ") : "(no public result)";
293
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Local resolver ${ansi.dim}${localDetail}${ansi.reset}\n`);
294
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Public DNS ${ansi.dim}${publicDetail}${ansi.reset}\n`);
295
+ if (publicIps.length > 0) {
296
+ const reachable = publicIps.some((ip) => verifyHostnameViaIp(hostname, ip));
297
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Public route ${ansi.dim}${reachable ? "reachable" : "not reachable"}${ansi.reset}\n`);
298
+ }
299
+ return { localIps, publicIps };
300
+ }
301
+ function printMacOnlyMessage(action) {
302
+ const prefix = `${ansi.bold}${CLI.logTag}${ansi.reset}`;
303
+ process.stderr.write(`${prefix} Automatic DNS ${action} currently only supports macOS.\n`);
304
+ process.stderr.write(`${prefix} You can still compare local vs public DNS with \`${CLI.command} doctor dns status --hostname <host>\`.\n`);
305
+ process.exitCode = 1;
306
+ }
307
+ export async function runDnsDoctorCommand(argv, options = {}) {
308
+ if (argv[0] === "help" || argv[0] === "--help" || argv[0] === "-h") {
309
+ usage();
310
+ return;
311
+ }
312
+ const parsed = parseDnsDoctorArgs(argv);
313
+ const dependencies = {
314
+ platform: process.platform,
315
+ hubUrl: options.hubUrlOverride?.trim() || HUB_URL,
316
+ };
317
+ const hostname = resolveDnsDoctorHostname(parsed, dependencies);
318
+ if (parsed.action === "restore") {
319
+ if (dependencies.platform !== "darwin") {
320
+ printMacOnlyMessage("restore");
321
+ return;
322
+ }
323
+ const scopedStatePath = stateFileForHostname(hostname);
324
+ if (existsSync(scopedStatePath)) {
325
+ restoreScopedResolverState(hostname);
326
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Restored scoped DNS resolver state for ${hostname}.\n`);
327
+ return;
328
+ }
329
+ const resolverPath = resolverFileForHostname(hostname);
330
+ if (existsSync(resolverPath)) {
331
+ throw new Error(`No saved DNS repair state was found for ${hostname}. A scoped resolver still exists at ${resolverPath}; remove it manually if you want to clear it.`);
332
+ }
333
+ throw new Error(`No saved DNS repair state was found for ${hostname}.`);
334
+ }
335
+ const service = dependencies.platform === "darwin"
336
+ ? resolveNetworkService(parsed.networkService)
337
+ : null;
338
+ const status = await printStatus(hostname, service, dependencies.platform);
339
+ if (parsed.action === "status") {
340
+ if (status.publicIps.length > 0 && status.localIps.length === 0) {
341
+ if (dependencies.platform === "darwin") {
342
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Public DNS is correct but local macOS resolution is stale.\n`);
343
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Run \`${CLI.command} doctor dns repair --hostname ${hostname}\` to repair it.\n`);
344
+ }
345
+ else {
346
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Public DNS is correct but local resolution is stale.\n`);
347
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Automatic repair currently only supports macOS.\n`);
348
+ }
349
+ process.exitCode = 1;
350
+ return;
351
+ }
352
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} DNS looks healthy.\n`);
353
+ return;
354
+ }
355
+ if (dependencies.platform !== "darwin") {
356
+ printMacOnlyMessage("repair");
357
+ return;
358
+ }
359
+ if (status.publicIps.length === 0) {
360
+ throw new Error(`Public DNS does not resolve ${hostname} yet. This is not a local macOS cache problem.`);
361
+ }
362
+ if (status.localIps.length > 0) {
363
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Local resolution already looks healthy. No repair needed.\n`);
364
+ return;
365
+ }
366
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Flushing local macOS DNS caches...\n`);
367
+ flushMacDns();
368
+ const afterFlush = readLocalResolverMac(hostname);
369
+ if (afterFlush.length > 0) {
370
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Local resolution recovered after the cache flush.\n`);
371
+ return;
372
+ }
373
+ const resolverPath = resolverFileForHostname(hostname);
374
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Local resolution is still stale. Installing a scoped resolver for ${hostname} at ${resolverPath}.\n`);
375
+ saveScopedResolverState(hostname);
376
+ installScopedResolver(hostname);
377
+ flushMacDns();
378
+ const afterSwitch = readLocalResolverMac(hostname);
379
+ if (afterSwitch.length > 0) {
380
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Local resolution recovered after installing the scoped resolver.\n`);
381
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Remove it later with \`${CLI.command} doctor dns restore --hostname ${hostname}\`.\n`);
382
+ return;
383
+ }
384
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} The scoped resolver is installed, but ${hostname} still does not resolve locally.\n`);
385
+ process.stderr.write(`${ansi.bold}${CLI.logTag}${ansi.reset} Remove it later with \`${CLI.command} doctor dns restore --hostname ${hostname}\`.\n`);
386
+ process.exitCode = 1;
387
+ }
388
+ export function printDnsDoctorHelp() {
389
+ usage();
390
+ }
@@ -0,0 +1,47 @@
1
+ import { CLI, IDENTITIES, envVar } from "./identity.js";
2
+ // Every Docker container, volume and label this runner creates is named from
3
+ // one prefix, so a second runner (the startup bench runner, or the other
4
+ // program's runner: `tiller` and `overvues` on one machine) can share the
5
+ // Docker host without seeing or removing this runner's objects. The default is
6
+ // the program's own (identity.ts): "tiller" keeps existing names, "overvues"
7
+ // for the `overvues` build. Read from the process environment
8
+ // (TILLER_DOCKER_NAME_PREFIX, OVERVUES_DOCKER_NAME_PREFIX) when the runner starts.
9
+ export const DEFAULT_DOCKER_NAME_PREFIX = CLI.dockerNamePrefix;
10
+ /** The default prefixes of both programs: no other prefix may end in one. */
11
+ const PROGRAM_PREFIXES = Object.values(IDENTITIES).map((identity) => identity.dockerNamePrefix);
12
+ /**
13
+ * Docker `name=` filters match substrings, so a prefix such as "xtiller"
14
+ * would make "xtiller-ws-staged-1" visible to the default runner's
15
+ * `name=tiller-ws-staged-` filter. Only lowercase letters and digits, no
16
+ * hyphen, and nothing ending in "tiller" or "overvues" except this program's
17
+ * own default.
18
+ */
19
+ export function resolveDockerNamePrefix(value, identity = CLI) {
20
+ const prefix = value?.trim() ?? "";
21
+ if (!prefix)
22
+ return identity.dockerNamePrefix;
23
+ if (prefix === identity.dockerNamePrefix)
24
+ return prefix;
25
+ const endsInProgramPrefix = PROGRAM_PREFIXES.filter((known) => prefix.endsWith(known));
26
+ if (!/^[a-z][a-z0-9]{1,23}$/.test(prefix) || endsInProgramPrefix.length > 0) {
27
+ const reserved = PROGRAM_PREFIXES.map((known) => `"${known}"`).join(" or ");
28
+ throw new Error(`${envVar("DOCKER_NAME_PREFIX", identity)} "${prefix}" must be 2-24 lowercase letters or digits, start with a letter and not end in ${reserved}.`);
29
+ }
30
+ return prefix;
31
+ }
32
+ export const DOCKER_NAME_PREFIX = resolveDockerNamePrefix(process.env[envVar("DOCKER_NAME_PREFIX")]);
33
+ /** `<prefix>-<suffix>`: container and volume names. */
34
+ export function dockerName(suffix, prefix = DOCKER_NAME_PREFIX) {
35
+ return `${prefix}-${suffix}`;
36
+ }
37
+ /** `<prefix>.<key>`: container and volume label keys. */
38
+ export function dockerLabel(key, prefix = DOCKER_NAME_PREFIX) {
39
+ return `${prefix}.${key}`;
40
+ }
41
+ function escapeRegExp(value) {
42
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
43
+ }
44
+ /** `^<prefix>-<pattern>$`: a volume or container name this runner made. */
45
+ export function dockerNamePattern(pattern, prefix = DOCKER_NAME_PREFIX) {
46
+ return new RegExp(`^${escapeRegExp(prefix)}-${pattern}$`);
47
+ }
package/dist/doctor.js ADDED
@@ -0,0 +1,114 @@
1
+ import { HUB_URL } from "./config.js";
2
+ import { readSetupStatusWithValidatedCredential, } from "./host-auth.js";
3
+ import { checkLocalRunnerHealth, } from "./local-stack.js";
4
+ import { collectHubHostChecks } from "./host-diagnostics.js";
5
+ import { hasFailures, hasWarnings, printCheckReport } from "./readiness.js";
6
+ import { collectSetupChecks } from "./setup.js";
7
+ import { CLI } from "./identity.js";
8
+ export async function collectDoctorReport() {
9
+ const setup = await collectSetupChecks();
10
+ const checks = [...setup.checks];
11
+ const setupStatus = HUB_URL
12
+ ? await readSetupStatusWithValidatedCredential()
13
+ : null;
14
+ // A machine is optional while Cloudflare Containers remains the default.
15
+ // Once a machine has registered, surface its durable/live health.
16
+ if (setupStatus
17
+ && (setupStatus.hostRegistered || setupStatus.hostConnected)) {
18
+ checks.push(...collectHubHostChecks(setupStatus));
19
+ }
20
+ if (setupStatus?.enabledHarnesses.includes("codex")) {
21
+ const selectedOpenAIMode = setupStatus.openaiBillingMode ?? null;
22
+ const chatgptAuthStatus = setupStatus.chatgptAuthStatus ?? (setupStatus.hasChatGPTAuth ? "connected" : "missing");
23
+ const hubCodexAuth = chatgptAuthStatus === "connected" || chatgptAuthStatus === "refreshing";
24
+ const selectedCredentialReady = selectedOpenAIMode === "api"
25
+ ? setupStatus.hasOpenAIKey
26
+ : selectedOpenAIMode === "subscription" && hubCodexAuth;
27
+ checks.push({
28
+ id: "chatgpt-auth",
29
+ label: selectedOpenAIMode === "api"
30
+ ? "OpenAI API key"
31
+ : selectedOpenAIMode === "subscription" ? "Codex subscription login" : "OpenAI billing mode",
32
+ level: selectedCredentialReady ? "ok" : "warn",
33
+ detail: selectedOpenAIMode === null
34
+ ? "not selected"
35
+ : selectedOpenAIMode === "api"
36
+ ? setupStatus.hasOpenAIKey ? "configured in the hub" : "not configured"
37
+ : chatgptAuthStatus === "connected"
38
+ ? "stored in the hub"
39
+ : chatgptAuthStatus === "refreshing"
40
+ ? "refreshing connected Codex login"
41
+ : chatgptAuthStatus === "needs_reconnect"
42
+ ? "Codex login needs reconnection"
43
+ : chatgptAuthStatus === "temporarily_unavailable"
44
+ ? "Codex login is temporarily unavailable"
45
+ : "not connected",
46
+ fixHint: selectedCredentialReady
47
+ ? undefined
48
+ : selectedOpenAIMode === null
49
+ ? "select an OpenAI billing mode in Global Settings"
50
+ : selectedOpenAIMode === "api"
51
+ ? "configure OPENAI_API_KEY in Settings"
52
+ : `run \`${CLI.command} auth connect codex\``,
53
+ });
54
+ const routeStatus = setupStatus.codexRouteStatus ?? "unavailable";
55
+ checks.push({
56
+ id: "codex-route",
57
+ label: "OpenAI route",
58
+ level: selectedOpenAIMode !== null && (routeStatus === "available" || routeStatus === "direct_api") ? "ok" : "warn",
59
+ detail: selectedOpenAIMode === null
60
+ ? "no billing mode selected"
61
+ : routeStatus === "available"
62
+ ? "subscription app-server route available"
63
+ : routeStatus === "direct_api"
64
+ ? "direct API route available"
65
+ : routeStatus === "backend_offline"
66
+ ? "selected execution backend is offline"
67
+ : routeStatus === "runtime_update_required"
68
+ ? "connected runtime must be updated"
69
+ : routeStatus === "environment_not_connected"
70
+ ? "environment is not connected"
71
+ : routeStatus === "authentication_unavailable"
72
+ ? "selected OpenAI authentication is unavailable"
73
+ : "no Codex route available",
74
+ fixHint: selectedOpenAIMode !== null && (routeStatus === "available" || routeStatus === "direct_api")
75
+ ? undefined
76
+ : selectedOpenAIMode === null
77
+ ? "select an OpenAI billing mode in Global Settings"
78
+ : selectedOpenAIMode === "api"
79
+ ? "configure OPENAI_API_KEY in Settings"
80
+ : routeStatus === "runtime_update_required"
81
+ ? `run \`${CLI.command} host update\`, then restart the persistent machine service`
82
+ : routeStatus === "backend_offline"
83
+ ? "start or reconnect the selected execution backend"
84
+ : routeStatus === "environment_not_connected"
85
+ ? "start the environment and wait for it to connect"
86
+ : chatgptAuthStatus === "temporarily_unavailable"
87
+ ? `retry shortly; if the problem persists, run \`${CLI.command} auth connect codex\``
88
+ : `run \`${CLI.command} auth connect codex\``,
89
+ });
90
+ }
91
+ const runnerHealth = await checkLocalRunnerHealth();
92
+ checks.push({
93
+ id: "runner-health",
94
+ label: "host container control health",
95
+ level: runnerHealth.ok ? "ok" : "warn",
96
+ detail: runnerHealth.ok ? runnerHealth.detail : runnerHealth.detail ?? "host container control is not responding on localhost",
97
+ fixHint: runnerHealth.ok ? undefined : `run \`${CLI.command} host setup\` to install or restart the execution-machine service`,
98
+ });
99
+ return {
100
+ checks,
101
+ healthy: !hasFailures(checks),
102
+ };
103
+ }
104
+ export async function runDoctor() {
105
+ const report = await collectDoctorReport();
106
+ printCheckReport("Doctor", report.checks);
107
+ const summary = !report.healthy
108
+ ? `${CLI.logTag} Doctor found required setup issues. Fix the failing items above.\n`
109
+ : hasWarnings(report.checks)
110
+ ? `${CLI.logTag} Setup looks healthy. Your machine is currently unavailable; run \`${CLI.command} host setup\` if you want to use it.\n`
111
+ : `${CLI.logTag} Setup and execution-machine services look healthy.\n`;
112
+ process.stderr.write(summary);
113
+ process.exitCode = report.healthy ? 0 : 1;
114
+ }