ps-claw 2026.5.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ps-claw.mjs ADDED
@@ -0,0 +1,661 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import { existsSync, readFileSync, statSync } from "node:fs";
5
+ import { access } from "node:fs/promises";
6
+ import module from "node:module";
7
+ import os from "node:os";
8
+ import path from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+
11
+ const MIN_NODE_MAJOR = 22;
12
+ const MIN_NODE_MINOR = 19;
13
+ const MIN_NODE_VERSION = `${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}`;
14
+
15
+ const parseNodeVersion = (rawVersion) => {
16
+ const [majorRaw = "0", minorRaw = "0"] = rawVersion.split(".");
17
+ return {
18
+ major: Number(majorRaw),
19
+ minor: Number(minorRaw),
20
+ };
21
+ };
22
+
23
+ const isSupportedNodeVersion = (version) =>
24
+ version.major > MIN_NODE_MAJOR ||
25
+ (version.major === MIN_NODE_MAJOR && version.minor >= MIN_NODE_MINOR);
26
+
27
+ const ensureSupportedNodeVersion = () => {
28
+ if (isSupportedNodeVersion(parseNodeVersion(process.versions.node))) {
29
+ return;
30
+ }
31
+
32
+ process.stderr.write(
33
+ `ps-claw: Node.js v${MIN_NODE_VERSION}+ is required (current: v${process.versions.node}).\n` +
34
+ "If you use nvm, run:\n" +
35
+ ` nvm install ${MIN_NODE_MAJOR}\n` +
36
+ ` nvm use ${MIN_NODE_MAJOR}\n` +
37
+ ` nvm alias default ${MIN_NODE_MAJOR}\n`,
38
+ );
39
+ process.exit(1);
40
+ };
41
+
42
+ ensureSupportedNodeVersion();
43
+
44
+ if (tryOutputLauncherVersion(process.argv)) {
45
+ process.exit(0);
46
+ }
47
+
48
+ const isSourceCheckoutLauncher = () =>
49
+ existsSync(new URL("./.git", import.meta.url)) ||
50
+ existsSync(new URL("./src/entry.ts", import.meta.url));
51
+
52
+ const isNodeCompileCacheDisabled = () => process.env.NODE_DISABLE_COMPILE_CACHE !== undefined;
53
+ const isNodeCompileCacheRequested = () =>
54
+ Boolean(process.env.NODE_COMPILE_CACHE) && !isNodeCompileCacheDisabled();
55
+ const sanitizeCompileCachePathSegment = (value) => {
56
+ const normalized = value.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^_+|_+$/g, "");
57
+ return normalized.length > 0 ? normalized : "unknown";
58
+ };
59
+ const readPackageVersion = () => {
60
+ try {
61
+ const parsed = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
62
+ if (typeof parsed?.version === "string" && parsed.version.trim().length > 0) {
63
+ return parsed.version;
64
+ }
65
+ } catch {
66
+ // Fall through to an install-metadata-only cache key.
67
+ }
68
+ return "unknown";
69
+ };
70
+ const resolvePackagedCompileCacheDirectory = () => {
71
+ const packageJsonUrl = new URL("./package.json", import.meta.url);
72
+ const version = sanitizeCompileCachePathSegment(readPackageVersion());
73
+ let installMarker = "no-package-json";
74
+ try {
75
+ const stat = statSync(packageJsonUrl);
76
+ installMarker = `${Math.trunc(stat.mtimeMs)}-${stat.size}`;
77
+ } catch {
78
+ // Package archives should always have package.json, but keep startup best-effort.
79
+ }
80
+ const baseDirectory = isNodeCompileCacheRequested()
81
+ ? process.env.NODE_COMPILE_CACHE
82
+ : path.join(os.tmpdir(), "node-compile-cache");
83
+ return path.join(
84
+ baseDirectory,
85
+ "ps-claw",
86
+ version,
87
+ sanitizeCompileCachePathSegment(installMarker),
88
+ );
89
+ };
90
+
91
+ const respawnSignals =
92
+ process.platform === "win32"
93
+ ? ["SIGTERM", "SIGINT", "SIGBREAK"]
94
+ : ["SIGTERM", "SIGINT", "SIGHUP", "SIGQUIT"];
95
+ const respawnSignalExitGraceMs = 1_000;
96
+ const respawnSignalForceKillGraceMs = 1_000;
97
+ const respawnSignalHardExitGraceMs = 1_000;
98
+
99
+ const runRespawnedChild = (command, args, env) => {
100
+ const child = spawn(command, args, {
101
+ stdio: "inherit",
102
+ env,
103
+ });
104
+ const listeners = new Map();
105
+ // This intentionally overlaps with src/entry.compile-cache.ts; keep the
106
+ // respawn supervision behavior in sync until the launcher can share TS code.
107
+ // Give the child a moment to honor forwarded signals, then exit the wrapper so
108
+ // a child that ignores SIGTERM cannot keep the launcher alive indefinitely.
109
+ let signalExitTimer = null;
110
+ let signalForceKillTimer = null;
111
+ let signalHardExitTimer = null;
112
+ const detach = () => {
113
+ for (const [signal, listener] of listeners) {
114
+ process.off(signal, listener);
115
+ }
116
+ listeners.clear();
117
+ if (signalExitTimer) {
118
+ clearTimeout(signalExitTimer);
119
+ signalExitTimer = null;
120
+ }
121
+ if (signalForceKillTimer) {
122
+ clearTimeout(signalForceKillTimer);
123
+ signalForceKillTimer = null;
124
+ }
125
+ if (signalHardExitTimer) {
126
+ clearTimeout(signalHardExitTimer);
127
+ signalHardExitTimer = null;
128
+ }
129
+ };
130
+ const forceKillChild = () => {
131
+ try {
132
+ child.kill(process.platform === "win32" ? "SIGTERM" : "SIGKILL");
133
+ } catch {
134
+ // Best-effort shutdown fallback.
135
+ }
136
+ };
137
+ const requestChildTermination = () => {
138
+ try {
139
+ child.kill("SIGTERM");
140
+ } catch {
141
+ // Best-effort shutdown fallback.
142
+ }
143
+ signalForceKillTimer = setTimeout(() => {
144
+ forceKillChild();
145
+ signalHardExitTimer = setTimeout(() => {
146
+ process.exit(1);
147
+ }, respawnSignalHardExitGraceMs);
148
+ signalHardExitTimer.unref?.();
149
+ }, respawnSignalForceKillGraceMs);
150
+ signalForceKillTimer.unref?.();
151
+ };
152
+ const scheduleParentExit = () => {
153
+ if (signalExitTimer) {
154
+ return;
155
+ }
156
+ signalExitTimer = setTimeout(() => {
157
+ requestChildTermination();
158
+ }, respawnSignalExitGraceMs);
159
+ signalExitTimer.unref?.();
160
+ };
161
+ for (const signal of respawnSignals) {
162
+ const listener = () => {
163
+ try {
164
+ child.kill(signal);
165
+ } catch {
166
+ // Best-effort signal forwarding.
167
+ }
168
+ scheduleParentExit();
169
+ };
170
+ try {
171
+ process.on(signal, listener);
172
+ listeners.set(signal, listener);
173
+ } catch {
174
+ // Unsupported signal on this platform.
175
+ }
176
+ }
177
+ child.once("exit", (code, signal) => {
178
+ detach();
179
+ if (signal) {
180
+ process.exit(1);
181
+ }
182
+ process.exit(code ?? 1);
183
+ });
184
+ child.once("error", (error) => {
185
+ detach();
186
+ process.stderr.write(
187
+ `[ps-claw] Failed to respawn launcher: ${
188
+ error instanceof Error ? (error.stack ?? error.message) : String(error)
189
+ }\n`,
190
+ );
191
+ process.exit(1);
192
+ });
193
+ return true;
194
+ };
195
+
196
+ const respawnWithoutCompileCacheIfNeeded = () => {
197
+ if (!isSourceCheckoutLauncher()) {
198
+ return false;
199
+ }
200
+ if (process.env.PS_CLAW_SOURCE_COMPILE_CACHE_RESPAWNED === "1") {
201
+ return false;
202
+ }
203
+ if (!module.getCompileCacheDir?.() && !isNodeCompileCacheRequested()) {
204
+ return false;
205
+ }
206
+ const env = {
207
+ ...process.env,
208
+ NODE_DISABLE_COMPILE_CACHE: "1",
209
+ PS_CLAW_SOURCE_COMPILE_CACHE_RESPAWNED: "1",
210
+ };
211
+ delete env.NODE_COMPILE_CACHE;
212
+ return runRespawnedChild(
213
+ process.execPath,
214
+ [...process.execArgv, fileURLToPath(import.meta.url), ...process.argv.slice(2)],
215
+ env,
216
+ );
217
+ };
218
+
219
+ const respawnWithPackagedCompileCacheIfNeeded = () => {
220
+ if (isSourceCheckoutLauncher() || isNodeCompileCacheDisabled()) {
221
+ return false;
222
+ }
223
+ if (process.env.PS_CLAW_PACKAGED_COMPILE_CACHE_RESPAWNED === "1") {
224
+ return false;
225
+ }
226
+ const currentDirectory = module.getCompileCacheDir?.();
227
+ if (!currentDirectory) {
228
+ return false;
229
+ }
230
+ const desiredDirectory = resolvePackagedCompileCacheDirectory();
231
+ if (path.resolve(currentDirectory) === path.resolve(desiredDirectory)) {
232
+ return false;
233
+ }
234
+ const env = {
235
+ ...process.env,
236
+ NODE_COMPILE_CACHE: desiredDirectory,
237
+ PS_CLAW_PACKAGED_COMPILE_CACHE_RESPAWNED: "1",
238
+ };
239
+ return runRespawnedChild(
240
+ process.execPath,
241
+ [...process.execArgv, fileURLToPath(import.meta.url), ...process.argv.slice(2)],
242
+ env,
243
+ );
244
+ };
245
+
246
+ const waitingForCompileCacheRespawn =
247
+ respawnWithoutCompileCacheIfNeeded() || respawnWithPackagedCompileCacheIfNeeded();
248
+
249
+ // https://nodejs.org/api/module.html#module-compile-cache
250
+ if (
251
+ !waitingForCompileCacheRespawn &&
252
+ module.enableCompileCache &&
253
+ !isNodeCompileCacheDisabled() &&
254
+ !isSourceCheckoutLauncher()
255
+ ) {
256
+ try {
257
+ module.enableCompileCache(resolvePackagedCompileCacheDirectory());
258
+ } catch {
259
+ // Ignore errors
260
+ }
261
+ }
262
+
263
+ const getErrorMessage = (err) =>
264
+ err && typeof err === "object" && "message" in err && typeof err.message === "string"
265
+ ? err.message
266
+ : "";
267
+
268
+ const isModuleNotFoundError = (err) =>
269
+ err && typeof err === "object" && "code" in err && err.code === "ERR_MODULE_NOT_FOUND";
270
+
271
+ const isDirectModuleNotFoundError = (err, specifier) => {
272
+ const message = getErrorMessage(err);
273
+ const bunSpecifierMiss =
274
+ message.includes(`Cannot find module '${specifier}'`) ||
275
+ message.includes(`Cannot find module "${specifier}"`);
276
+ const launcherPath = fileURLToPath(import.meta.url);
277
+ const bunLauncherImporterMiss =
278
+ message.includes(` from '${launcherPath}'`) || message.includes(` from "${launcherPath}"`);
279
+
280
+ const expectedUrl = new URL(specifier, import.meta.url);
281
+ const expectedPath = fileURLToPath(expectedUrl);
282
+ const nodePathMiss =
283
+ message.includes(`Cannot find module '${expectedPath}'`) ||
284
+ message.includes(`Cannot find module "${expectedPath}"`);
285
+
286
+ if (isModuleNotFoundError(err)) {
287
+ if (err && typeof err === "object" && "url" in err && err.url === expectedUrl.href) {
288
+ return true;
289
+ }
290
+ return nodePathMiss || (bunSpecifierMiss && bunLauncherImporterMiss);
291
+ }
292
+
293
+ return bunSpecifierMiss && bunLauncherImporterMiss;
294
+ };
295
+
296
+ const installProcessWarningFilter = async () => {
297
+ // Keep bootstrap warnings consistent with the TypeScript runtime.
298
+ for (const specifier of ["./dist/warning-filter.js", "./dist/warning-filter.mjs"]) {
299
+ try {
300
+ const mod = await import(specifier);
301
+ if (typeof mod.installProcessWarningFilter === "function") {
302
+ mod.installProcessWarningFilter();
303
+ return;
304
+ }
305
+ } catch (err) {
306
+ if (isDirectModuleNotFoundError(err, specifier)) {
307
+ continue;
308
+ }
309
+ throw err;
310
+ }
311
+ }
312
+ };
313
+
314
+ const tryImport = async (specifier) => {
315
+ try {
316
+ await import(specifier);
317
+ return true;
318
+ } catch (err) {
319
+ // Only swallow direct entry misses; rethrow transitive resolution failures.
320
+ if (isDirectModuleNotFoundError(err, specifier)) {
321
+ return false;
322
+ }
323
+ throw err;
324
+ }
325
+ };
326
+
327
+ const exists = async (specifier) => {
328
+ try {
329
+ await access(new URL(specifier, import.meta.url));
330
+ return true;
331
+ } catch {
332
+ return false;
333
+ }
334
+ };
335
+
336
+ const buildMissingEntryErrorMessage = async () => {
337
+ const lines = ["ps-claw: missing dist/entry.(m)js (build output)."];
338
+ if (!(await exists("./src/entry.ts"))) {
339
+ return lines.join("\n");
340
+ }
341
+
342
+ lines.push("This install looks like an unbuilt source tree or GitHub source archive.");
343
+ lines.push(
344
+ "Build locally with `pnpm install && pnpm build`, or install a built package instead.",
345
+ );
346
+ lines.push(
347
+ "For pinned GitHub installs, use `npm install -g github:ps-claw/ps-claw#<ref>` instead of a raw `/archive/<ref>.tar.gz` URL.",
348
+ );
349
+ lines.push("For releases, use `npm install -g ps-claw@latest`.");
350
+ return lines.join("\n");
351
+ };
352
+
353
+ const isBareRootHelpInvocation = (argv) =>
354
+ argv.length === 3 && (argv[2] === "--help" || argv[2] === "-h");
355
+
356
+ const resolvePrecomputedCommandHelp = (argv) => {
357
+ if (argv.length !== 4 || (argv[3] !== "--help" && argv[3] !== "-h")) {
358
+ return null;
359
+ }
360
+ if (argv[2] === "browser") {
361
+ return { command: "browser", metadataKey: "browserHelpText" };
362
+ }
363
+ if (argv[2] === "secrets") {
364
+ return { command: "secrets", metadataKey: "secretsHelpText" };
365
+ }
366
+ if (argv[2] === "nodes") {
367
+ return { command: "nodes", metadataKey: "nodesHelpText" };
368
+ }
369
+ return null;
370
+ };
371
+
372
+ const isHelpFastPathDisabled = () =>
373
+ process.env.PS_CLAW_DISABLE_CLI_STARTUP_HELP_FAST_PATH === "1";
374
+
375
+ const normalizeLauncherHomeValue = (value) => {
376
+ const trimmed = value?.trim();
377
+ return trimmed && trimmed !== "undefined" && trimmed !== "null" ? trimmed : undefined;
378
+ };
379
+
380
+ const resolveLauncherOsHomeDir = () =>
381
+ normalizeLauncherHomeValue(process.env.HOME) ??
382
+ normalizeLauncherHomeValue(process.env.USERPROFILE) ??
383
+ os.homedir();
384
+
385
+ const resolveLauncherHomeDir = () => {
386
+ const explicit = normalizeLauncherHomeValue(process.env.PS_CLAW_HOME);
387
+ const rawHome =
388
+ explicit && (explicit === "~" || explicit.startsWith("~/") || explicit.startsWith("~\\"))
389
+ ? explicit.replace(/^~(?=$|[\\/])/, resolveLauncherOsHomeDir())
390
+ : (explicit ?? resolveLauncherOsHomeDir());
391
+ return path.resolve(rawHome);
392
+ };
393
+
394
+ const resolveLauncherUserPath = (input) => {
395
+ if (input === "~") {
396
+ return resolveLauncherHomeDir();
397
+ }
398
+ if (input.startsWith("~/") || input.startsWith("~\\")) {
399
+ return path.join(resolveLauncherHomeDir(), input.slice(2));
400
+ }
401
+ return path.resolve(input);
402
+ };
403
+
404
+ const resolveLauncherConfigPaths = () => {
405
+ const explicit = process.env.PS_CLAW_CONFIG_PATH?.trim();
406
+ if (explicit) {
407
+ return [resolveLauncherUserPath(explicit)];
408
+ }
409
+ const stateOverride = process.env.PS_CLAW_STATE_DIR?.trim();
410
+ if (stateOverride) {
411
+ const stateDir = resolveLauncherUserPath(stateOverride);
412
+ return [path.join(stateDir, "ps-claw.json"), path.join(stateDir, "clawdbot.json")];
413
+ }
414
+ const homeDir = resolveLauncherHomeDir();
415
+ return [
416
+ path.join(homeDir, ".ps-claw", "ps-claw.json"),
417
+ path.join(homeDir, ".ps-claw", "clawdbot.json"),
418
+ path.join(homeDir, ".clawdbot", "ps-claw.json"),
419
+ path.join(homeDir, ".clawdbot", "clawdbot.json"),
420
+ ];
421
+ };
422
+
423
+ const shouldDeferRootHelpToRuntimeEntry = () => {
424
+ if (
425
+ process.env.PS_CLAW_BUNDLED_PLUGINS_DIR?.trim() ||
426
+ process.env.PS_CLAW_DISABLE_BUNDLED_PLUGINS?.trim()
427
+ ) {
428
+ return true;
429
+ }
430
+ for (const configPath of resolveLauncherConfigPaths()) {
431
+ try {
432
+ const raw = readFileSync(configPath, "utf8");
433
+ return /\bplugins\b|\$include\b/.test(raw);
434
+ } catch {
435
+ continue;
436
+ }
437
+ }
438
+ return false;
439
+ };
440
+
441
+ const loadPrecomputedHelpText = (key) => {
442
+ try {
443
+ const raw = readFileSync(new URL("./dist/cli-startup-metadata.json", import.meta.url), "utf8");
444
+ const parsed = JSON.parse(raw);
445
+ const value = parsed?.[key];
446
+ return typeof value === "string" && value.length > 0 ? value : null;
447
+ } catch {
448
+ return null;
449
+ }
450
+ };
451
+
452
+ function tryOutputLauncherVersion(argv) {
453
+ try {
454
+ if (normalizeLauncherMetadataValue(process.env.PS_CLAW_CONTAINER)) {
455
+ return false;
456
+ }
457
+ if (!isLauncherVersionFastPathArgv(argv)) {
458
+ return false;
459
+ }
460
+ const version = resolveLauncherVersion();
461
+ const commit = resolveLauncherCommit();
462
+ process.stdout.write(commit ? `PS Claw ${version} (${commit})\n` : `PS Claw ${version}\n`);
463
+ return true;
464
+ } catch {
465
+ return false;
466
+ }
467
+ }
468
+
469
+ function isLauncherVersionFastPathArgv(argv) {
470
+ return argv.length === 3 && (argv[2] === "--version" || argv[2] === "-V" || argv[2] === "-v");
471
+ }
472
+
473
+ function normalizeLauncherMetadataValue(value) {
474
+ const trimmed = typeof value === "string" ? value.trim() : "";
475
+ return trimmed && trimmed !== "undefined" && trimmed !== "null" ? trimmed : undefined;
476
+ }
477
+
478
+ function readLauncherJson(relativePath) {
479
+ try {
480
+ return JSON.parse(readFileSync(new URL(relativePath, import.meta.url), "utf8"));
481
+ } catch {
482
+ return null;
483
+ }
484
+ }
485
+
486
+ function resolveLauncherVersion() {
487
+ const packageJson = readLauncherJson("./package.json");
488
+ const packageVersion = normalizeLauncherMetadataValue(packageJson?.version);
489
+ if (packageVersion) {
490
+ return packageVersion;
491
+ }
492
+ const buildInfo = readLauncherJson("./dist/build-info.json");
493
+ const buildVersion = normalizeLauncherMetadataValue(buildInfo?.version);
494
+ if (buildVersion) {
495
+ return buildVersion;
496
+ }
497
+ return normalizeLauncherMetadataValue(process.env.PS_CLAW_BUNDLED_VERSION) ?? "0.0.0";
498
+ }
499
+
500
+ function resolveLauncherCommit() {
501
+ const envCommit = formatLauncherCommit(process.env.GIT_COMMIT ?? process.env.GIT_SHA);
502
+ if (envCommit) {
503
+ return envCommit;
504
+ }
505
+ return (
506
+ readLauncherGitCommit() ??
507
+ formatLauncherCommit(readLauncherJson("./dist/build-info.json")?.commit) ??
508
+ formatLauncherCommit(readLauncherJson("./package.json")?.gitHead) ??
509
+ formatLauncherCommit(readLauncherJson("./package.json")?.githead)
510
+ );
511
+ }
512
+
513
+ function formatLauncherCommit(value) {
514
+ if (typeof value !== "string") {
515
+ return null;
516
+ }
517
+ const match = value.trim().match(/[0-9a-fA-F]{7,40}/);
518
+ return match ? match[0].slice(0, 7).toLowerCase() : null;
519
+ }
520
+
521
+ function readLauncherGitCommit() {
522
+ try {
523
+ const gitPath = fileURLToPath(new URL("./.git", import.meta.url));
524
+ const headPath = resolveLauncherGitHeadPath(gitPath);
525
+ if (!headPath) {
526
+ return null;
527
+ }
528
+ const head = readFileSync(headPath, "utf8").trim();
529
+ if (!head) {
530
+ return null;
531
+ }
532
+ if (!head.startsWith("ref:")) {
533
+ return formatLauncherCommit(head);
534
+ }
535
+ const ref = head.replace(/^ref:\s*/i, "").trim();
536
+ if (!ref.startsWith("refs/") || path.isAbsolute(ref) || ref.split("/").includes("..")) {
537
+ return null;
538
+ }
539
+ const refsBase = resolveLauncherGitRefsBase(headPath);
540
+ const refPath = path.resolve(refsBase, ref);
541
+ const rel = path.relative(refsBase, refPath);
542
+ if (!rel || rel.startsWith("..") || path.isAbsolute(rel)) {
543
+ return null;
544
+ }
545
+ try {
546
+ return formatLauncherCommit(readFileSync(refPath, "utf8"));
547
+ } catch {
548
+ return readLauncherPackedRef(refsBase, ref);
549
+ }
550
+ } catch {
551
+ return null;
552
+ }
553
+ }
554
+
555
+ function resolveLauncherGitHeadPath(gitPath) {
556
+ try {
557
+ if (statSync(gitPath).isDirectory()) {
558
+ return path.join(gitPath, "HEAD");
559
+ }
560
+ const raw = readFileSync(gitPath, "utf8").trim();
561
+ if (!raw.startsWith("gitdir:")) {
562
+ return null;
563
+ }
564
+ return path.join(
565
+ path.resolve(path.dirname(gitPath), raw.slice("gitdir:".length).trim()),
566
+ "HEAD",
567
+ );
568
+ } catch {
569
+ return null;
570
+ }
571
+ }
572
+
573
+ function resolveLauncherGitRefsBase(headPath) {
574
+ const gitDir = path.dirname(headPath);
575
+ try {
576
+ const commonDir = readFileSync(path.join(gitDir, "commondir"), "utf8").trim();
577
+ return commonDir ? path.resolve(gitDir, commonDir) : gitDir;
578
+ } catch {
579
+ return gitDir;
580
+ }
581
+ }
582
+
583
+ function readLauncherPackedRef(refsBase, ref) {
584
+ try {
585
+ const packedRefs = readFileSync(path.join(refsBase, "packed-refs"), "utf8");
586
+ for (const line of packedRefs.split("\n")) {
587
+ if (!line || line.startsWith("#") || line.startsWith("^")) {
588
+ continue;
589
+ }
590
+ const [commit, packedRef] = line.trim().split(/\s+/, 2);
591
+ if (packedRef === ref) {
592
+ return formatLauncherCommit(commit);
593
+ }
594
+ }
595
+ } catch {
596
+ // fall through
597
+ }
598
+ return null;
599
+ }
600
+
601
+ const tryOutputBareRootHelp = async () => {
602
+ if (!isBareRootHelpInvocation(process.argv)) {
603
+ return false;
604
+ }
605
+ if (shouldDeferRootHelpToRuntimeEntry()) {
606
+ return false;
607
+ }
608
+ const precomputed = loadPrecomputedHelpText("rootHelpText");
609
+ if (precomputed) {
610
+ process.stdout.write(precomputed);
611
+ return true;
612
+ }
613
+ for (const specifier of ["./dist/cli/program/root-help.js", "./dist/cli/program/root-help.mjs"]) {
614
+ try {
615
+ const mod = await import(specifier);
616
+ if (typeof mod.outputRootHelp === "function") {
617
+ await mod.outputRootHelp();
618
+ return true;
619
+ }
620
+ } catch (err) {
621
+ if (isDirectModuleNotFoundError(err, specifier)) {
622
+ continue;
623
+ }
624
+ throw err;
625
+ }
626
+ }
627
+ return false;
628
+ };
629
+
630
+ const tryOutputPrecomputedCommandHelp = () => {
631
+ const commandHelp = resolvePrecomputedCommandHelp(process.argv);
632
+ if (!commandHelp) {
633
+ return false;
634
+ }
635
+ if (commandHelp.command === "nodes" && shouldDeferRootHelpToRuntimeEntry()) {
636
+ return false;
637
+ }
638
+ const precomputed = loadPrecomputedHelpText(commandHelp.metadataKey);
639
+ if (!precomputed) {
640
+ return false;
641
+ }
642
+ process.stdout.write(precomputed);
643
+ return true;
644
+ };
645
+
646
+ if (!waitingForCompileCacheRespawn) {
647
+ if (!isHelpFastPathDisabled() && (await tryOutputBareRootHelp())) {
648
+ // OK
649
+ } else if (!isHelpFastPathDisabled() && tryOutputPrecomputedCommandHelp()) {
650
+ // OK
651
+ } else {
652
+ await installProcessWarningFilter();
653
+ if (await tryImport("./dist/entry.js")) {
654
+ // OK
655
+ } else if (await tryImport("./dist/entry.mjs")) {
656
+ // OK
657
+ } else {
658
+ throw new Error(await buildMissingEntryErrorMessage());
659
+ }
660
+ }
661
+ }
@@ -0,0 +1,3 @@
1
+ # Keep this file empty (or with only comments) to skip heartbeat API calls.
2
+
3
+ # Add tasks below when you want the agent to check something periodically.