claude-yes 1.164.0 → 1.166.0
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/dist/SUPPORTED_CLIS-ClQgRKQu.js +8 -0
- package/dist/{SUPPORTED_CLIS-C_J_okdw.js → SUPPORTED_CLIS-Xem8nliL.js} +2 -2
- package/dist/cli.js +14 -5
- package/dist/index.js +2 -2
- package/dist/{remotes-DkNuq417.js → remotes-ClT1bq16.js} +1 -1
- package/dist/{remotes-DBCvpp3B.js → remotes-T6nf0t3K.js} +2 -2
- package/dist/{schedule-B-Ncgklt.js → schedule-CwAX3y8s.js} +5 -5
- package/dist/{serve-yVh9Y6ot.js → serve-DeJBMba0.js} +12 -9
- package/dist/{setup-BmYrvUsz.js → setup-hWG3ZBG3.js} +3 -3
- package/dist/{share-Bq_tDXQU.js → share-BjqQBWM-.js} +1 -1
- package/dist/spawnGate-B_VDMXYL.js +107 -0
- package/dist/spawnGate-UH73I2le.js +5 -0
- package/dist/{subcommands-BbKngO7F.js → subcommands-BY0mIDo9.js} +230 -20
- package/dist/subcommands-BnsjTNpy.js +9 -0
- package/dist/{tray-BMzpUSfa.js → tray-CZarCA2Q.js} +1 -1
- package/dist/{ts-BzyVSzo1.js → ts-CXxZiZKE.js} +2 -2
- package/dist/{versionChecker-CCHuozmQ.js → versionChecker-Dv5DhRs3.js} +2 -2
- package/dist/{webrtcRemote-Ccdzmuc-.js → webrtcRemote-GAgF5K45.js} +1 -1
- package/dist/{workspaceConfig-B0Q9-q2B.js → workspaceConfig-D3OH7and.js} +41 -2
- package/package.json +1 -1
- package/ts/cli.ts +21 -0
- package/ts/needsInput.spec.ts +42 -1
- package/ts/needsInput.ts +54 -0
- package/ts/serve.ts +8 -0
- package/ts/spawnGate.spec.ts +155 -0
- package/ts/spawnGate.ts +123 -0
- package/ts/subcommands.spec.ts +33 -1
- package/ts/subcommands.ts +308 -31
- package/ts/workspaceConfig.spec.ts +85 -0
- package/ts/workspaceConfig.ts +64 -0
- package/dist/SUPPORTED_CLIS-CmJam_wA.js +0 -8
- package/dist/subcommands-C-aCmtre.js +0 -9
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "./ts-CXxZiZKE.js";
|
|
2
|
+
import "./logger-CDIsZ-Pp.js";
|
|
3
|
+
import "./versionChecker-Dv5DhRs3.js";
|
|
4
|
+
import "./pidStore-BfoBWUjc.js";
|
|
5
|
+
import "./globalPidIndex-DlmmJlO8.js";
|
|
6
|
+
import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-Xem8nliL.js";
|
|
7
|
+
|
|
8
|
+
export { SUPPORTED_CLIS };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as CLIS_CONFIG } from "./ts-
|
|
1
|
+
import { t as CLIS_CONFIG } from "./ts-CXxZiZKE.js";
|
|
2
2
|
|
|
3
3
|
//#region ts/SUPPORTED_CLIS.ts
|
|
4
4
|
const SUPPORTED_CLIS = Object.keys(CLIS_CONFIG);
|
|
5
5
|
|
|
6
6
|
//#endregion
|
|
7
7
|
export { SUPPORTED_CLIS as t };
|
|
8
|
-
//# sourceMappingURL=SUPPORTED_CLIS-
|
|
8
|
+
//# sourceMappingURL=SUPPORTED_CLIS-Xem8nliL.js.map
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { t as invokedCliName } from "./invokedCli-uqM2YYA7.js";
|
|
3
3
|
import { n as logger } from "./logger-CDIsZ-Pp.js";
|
|
4
|
-
import { i as versionString, n as displayVersion, r as getInstalledPackage, t as checkAndAutoUpdate } from "./versionChecker-
|
|
4
|
+
import { i as versionString, n as displayVersion, r as getInstalledPackage, t as checkAndAutoUpdate } from "./versionChecker-Dv5DhRs3.js";
|
|
5
5
|
import { argv } from "process";
|
|
6
6
|
import { execFileSync, spawn } from "child_process";
|
|
7
7
|
import ms from "ms";
|
|
@@ -481,7 +481,7 @@ function buildRustArgs(argv, cliFromScript, supportedClis) {
|
|
|
481
481
|
const rawArg = process.argv[2];
|
|
482
482
|
const managerCommands = !invokedCliName(process.argv);
|
|
483
483
|
const isHelpFlag = rawArg === "-h" || rawArg === "--help";
|
|
484
|
-
const { isSubcommand, runSubcommand, cmdHelp } = await import("./subcommands-
|
|
484
|
+
const { isSubcommand, runSubcommand, cmdHelp } = await import("./subcommands-BnsjTNpy.js");
|
|
485
485
|
if (isHelpFlag && process.argv.length === 3) {
|
|
486
486
|
cmdHelp(managerCommands);
|
|
487
487
|
process.exit(0);
|
|
@@ -495,14 +495,23 @@ await checkAndAutoUpdate();
|
|
|
495
495
|
logger.info(versionString());
|
|
496
496
|
const config = parseCliArgs(process.argv);
|
|
497
497
|
if (config.tray) {
|
|
498
|
-
const { startTray } = await import("./tray-
|
|
498
|
+
const { startTray } = await import("./tray-CZarCA2Q.js");
|
|
499
499
|
await startTray();
|
|
500
500
|
await new Promise(() => {});
|
|
501
501
|
}
|
|
502
502
|
{
|
|
503
|
-
const { ensureTray } = await import("./tray-
|
|
503
|
+
const { ensureTray } = await import("./tray-CZarCA2Q.js");
|
|
504
504
|
ensureTray();
|
|
505
505
|
}
|
|
506
|
+
if (!config.showVersion && !config.appendPrompt && !config.tray) {
|
|
507
|
+
const { waitForSpawnCapacity } = await import("./spawnGate-UH73I2le.js");
|
|
508
|
+
await waitForSpawnCapacity({
|
|
509
|
+
onWait: (reason, waitedMs) => {
|
|
510
|
+
if (config.verbose || waitedMs === 0) console.error(`[agent-yes] spawn gate: ${reason} — waiting…`);
|
|
511
|
+
},
|
|
512
|
+
onProceedAnyway: (reason, waitedMs) => console.error(`[agent-yes] spawn gate: ${reason} — waited ${Math.round(waitedMs / 1e3)}s, proceeding anyway`)
|
|
513
|
+
});
|
|
514
|
+
}
|
|
506
515
|
if (config.useRust) {
|
|
507
516
|
let rustBinary;
|
|
508
517
|
try {
|
|
@@ -514,7 +523,7 @@ if (config.useRust) {
|
|
|
514
523
|
}
|
|
515
524
|
}
|
|
516
525
|
if (rustBinary) {
|
|
517
|
-
const { SUPPORTED_CLIS } = await import("./SUPPORTED_CLIS-
|
|
526
|
+
const { SUPPORTED_CLIS } = await import("./SUPPORTED_CLIS-ClQgRKQu.js");
|
|
518
527
|
const rustArgs = buildRustArgs(process.argv, config.cli, SUPPORTED_CLIS);
|
|
519
528
|
if (config.verbose) {
|
|
520
529
|
console.log(`[rust] Using binary: ${rustBinary}`);
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as removeControlCharacters, i as AgentContext, n as agentYes, r as config, t as CLIS_CONFIG } from "./ts-
|
|
1
|
+
import { a as removeControlCharacters, i as AgentContext, n as agentYes, r as config, t as CLIS_CONFIG } from "./ts-CXxZiZKE.js";
|
|
2
2
|
import "./logger-CDIsZ-Pp.js";
|
|
3
|
-
import "./versionChecker-
|
|
3
|
+
import "./versionChecker-Dv5DhRs3.js";
|
|
4
4
|
import "./pidStore-BfoBWUjc.js";
|
|
5
5
|
import "./globalPidIndex-DlmmJlO8.js";
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./e2e-Bfw7qL9O.js";
|
|
2
2
|
import "./webrtcLink-CBZkZ-LT.js";
|
|
3
|
-
import { a as resolveRemoteSpec, i as readRemotes, n as deleteRemoteAlias, o as writeRemoteAlias, r as parseDirectRemoteSpec, t as cmdRemote } from "./remotes-
|
|
3
|
+
import { a as resolveRemoteSpec, i as readRemotes, n as deleteRemoteAlias, o as writeRemoteAlias, r as parseDirectRemoteSpec, t as cmdRemote } from "./remotes-T6nf0t3K.js";
|
|
4
4
|
|
|
5
5
|
export { cmdRemote };
|
|
@@ -86,7 +86,7 @@ async function resolveRemoteSpec(spec) {
|
|
|
86
86
|
* The bridge lives for the rest of the process (torn down on `process.exit`).
|
|
87
87
|
*/
|
|
88
88
|
async function resolveWebrtc(link, keyword) {
|
|
89
|
-
const { startWebrtcBridge } = await import("./webrtcRemote-
|
|
89
|
+
const { startWebrtcBridge } = await import("./webrtcRemote-GAgF5K45.js");
|
|
90
90
|
const bridge = await startWebrtcBridge(link);
|
|
91
91
|
return {
|
|
92
92
|
url: bridge.baseUrl,
|
|
@@ -173,4 +173,4 @@ async function cmdRemote(rest) {
|
|
|
173
173
|
|
|
174
174
|
//#endregion
|
|
175
175
|
export { resolveRemoteSpec as a, readRemotes as i, deleteRemoteAlias as n, writeRemoteAlias as o, parseDirectRemoteSpec as r, cmdRemote as t };
|
|
176
|
-
//# sourceMappingURL=remotes-
|
|
176
|
+
//# sourceMappingURL=remotes-T6nf0t3K.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./ts-
|
|
1
|
+
import "./ts-CXxZiZKE.js";
|
|
2
2
|
import "./logger-CDIsZ-Pp.js";
|
|
3
|
-
import "./versionChecker-
|
|
3
|
+
import "./versionChecker-Dv5DhRs3.js";
|
|
4
4
|
import "./pidStore-BfoBWUjc.js";
|
|
5
5
|
import "./globalPidIndex-DlmmJlO8.js";
|
|
6
|
-
import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-
|
|
7
|
-
import {
|
|
6
|
+
import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-Xem8nliL.js";
|
|
7
|
+
import { l as resolveSpawnCwd } from "./workspaceConfig-D3OH7and.js";
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
|
|
10
10
|
//#region ts/oxmgrService.ts
|
|
@@ -141,4 +141,4 @@ async function cmdSchedule(rest) {
|
|
|
141
141
|
|
|
142
142
|
//#endregion
|
|
143
143
|
export { cmdSchedule };
|
|
144
|
-
//# sourceMappingURL=schedule-
|
|
144
|
+
//# sourceMappingURL=schedule-CwAX3y8s.js.map
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import "./ts-
|
|
1
|
+
import "./ts-CXxZiZKE.js";
|
|
2
2
|
import "./logger-CDIsZ-Pp.js";
|
|
3
|
-
import { r as getInstalledPackage } from "./versionChecker-
|
|
3
|
+
import { r as getInstalledPackage } from "./versionChecker-Dv5DhRs3.js";
|
|
4
4
|
import "./pidStore-BfoBWUjc.js";
|
|
5
5
|
import { a as updateGlobalPidStatus } from "./globalPidIndex-DlmmJlO8.js";
|
|
6
6
|
import { t as pgidForWrapper } from "./reaper-C-eWAxIj.js";
|
|
7
7
|
import "./configShared-CEyhl0WH.js";
|
|
8
|
-
import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-
|
|
8
|
+
import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-Xem8nliL.js";
|
|
9
9
|
import "./e2e-Bfw7qL9O.js";
|
|
10
10
|
import "./webrtcLink-CBZkZ-LT.js";
|
|
11
|
-
import "./remotes-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import "./remotes-T6nf0t3K.js";
|
|
12
|
+
import { c as isProvisionAllowed, i as getSpawnHook, l as resolveSpawnCwd, r as getProvisionRoot, s as hasSpawnHook } from "./workspaceConfig-D3OH7and.js";
|
|
13
|
+
import { A as writeToIpc, D as snapshotStatus, S as resolveOne, b as renderRawLog, c as extractNeedsInput, h as listRecords, i as controlCodeFromName, l as extractTaskCounts, o as deriveLiveStatus, v as readNotes, y as readPtysize } from "./subcommands-BY0mIDo9.js";
|
|
14
|
+
import { r as spawnRejectionReason } from "./spawnGate-B_VDMXYL.js";
|
|
14
15
|
import yargs from "yargs";
|
|
15
16
|
import { mkdir, open, readFile, stat, unlink, writeFile } from "fs/promises";
|
|
16
17
|
import { homedir, hostname, userInfo } from "os";
|
|
@@ -307,7 +308,7 @@ async function cmdServeDaemon(sub, args) {
|
|
|
307
308
|
let shareLink = null;
|
|
308
309
|
let shareLinkMinted = false;
|
|
309
310
|
if (webrtcDaemon) try {
|
|
310
|
-
const { loadOrCreateShareRoom, shareLinkFromRoomUrl } = await import("./share-
|
|
311
|
+
const { loadOrCreateShareRoom, shareLinkFromRoomUrl } = await import("./share-BjqQBWM-.js");
|
|
311
312
|
const explicit = explicitWebrtcUrl(effArgs);
|
|
312
313
|
shareLink = shareLinkFromRoomUrl(explicit ?? await loadOrCreateShareRoom());
|
|
313
314
|
shareLinkMinted = !explicit;
|
|
@@ -1169,6 +1170,8 @@ Options:
|
|
|
1169
1170
|
const cli = String(body.cli ?? "claude");
|
|
1170
1171
|
if (!SUPPORTED_CLIS.includes(cli)) return new Response(`unsupported cli: ${cli}`, { status: 400 });
|
|
1171
1172
|
const prompt = String(body.prompt ?? "");
|
|
1173
|
+
const reject = await spawnRejectionReason();
|
|
1174
|
+
if (reject) return new Response(reject, { status: 429 });
|
|
1172
1175
|
let cwd;
|
|
1173
1176
|
let provisioned = null;
|
|
1174
1177
|
const fork = body.fork && typeof body.fork.fromCwd === "string" && body.fork.fromCwd.trim() && typeof body.fork.branch === "string" && body.fork.branch.trim() ? {
|
|
@@ -1383,7 +1386,7 @@ Options:
|
|
|
1383
1386
|
const webrtcVal = argv.webrtc ?? argv.share;
|
|
1384
1387
|
const explicitUrl = typeof webrtcVal === "string" && webrtcVal.startsWith("webrtc://") ? webrtcVal : void 0;
|
|
1385
1388
|
try {
|
|
1386
|
-
const { startShare, loadOrCreateShareRoom } = await import("./share-
|
|
1389
|
+
const { startShare, loadOrCreateShareRoom } = await import("./share-BjqQBWM-.js");
|
|
1387
1390
|
const linkFile = path.join(process.env.AGENT_YES_HOME ?? path.join(homedir(), ".agent-yes"), ".share-link");
|
|
1388
1391
|
const announce = async (room, link, rotated) => {
|
|
1389
1392
|
const lead = rotated ? "the room was rejected by signaling (stale generation) — rotated to a fresh link" : "shared over WebRTC — open this link (the token is eaten from the URL on open)";
|
|
@@ -1442,4 +1445,4 @@ Options:
|
|
|
1442
1445
|
|
|
1443
1446
|
//#endregion
|
|
1444
1447
|
export { cmdServe };
|
|
1445
|
-
//# sourceMappingURL=serve-
|
|
1448
|
+
//# sourceMappingURL=serve-DeJBMba0.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as getWorkspaceRoot, u as setWorkspaceRoot } from "./workspaceConfig-D3OH7and.js";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { stdin, stdout } from "node:process";
|
|
4
4
|
import { createInterface } from "node:readline/promises";
|
|
@@ -32,7 +32,7 @@ async function cmdSetup(rest) {
|
|
|
32
32
|
if (!existsSync(abs)) process.stderr.write(` note: that directory doesn't exist yet — create it, or agents spawned there will fail\n`);
|
|
33
33
|
if (noShare) return 0;
|
|
34
34
|
process.stdout.write(`\nsharing this machine to agent-yes.com…\n`);
|
|
35
|
-
const { cmdServe } = await import("./serve-
|
|
35
|
+
const { cmdServe } = await import("./serve-DeJBMba0.js");
|
|
36
36
|
return cmdServe([
|
|
37
37
|
"install",
|
|
38
38
|
"--share",
|
|
@@ -42,4 +42,4 @@ async function cmdSetup(rest) {
|
|
|
42
42
|
|
|
43
43
|
//#endregion
|
|
44
44
|
export { cmdSetup };
|
|
45
|
-
//# sourceMappingURL=setup-
|
|
45
|
+
//# sourceMappingURL=setup-hWG3ZBG3.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { i as readGlobalPids } from "./globalPidIndex-DlmmJlO8.js";
|
|
2
|
+
import { a as getSpawnWaitMs, n as getMinFreeMb, t as getMaxAgents } from "./workspaceConfig-D3OH7and.js";
|
|
3
|
+
import { readFile } from "fs/promises";
|
|
4
|
+
|
|
5
|
+
//#region ts/spawnGate.ts
|
|
6
|
+
/**
|
|
7
|
+
* Spawn admission control — keep an unbounded fan-out of agents from exhausting
|
|
8
|
+
* host RAM and tripping the kernel OOM-killer (which, on a box with no cgroup
|
|
9
|
+
* memory limit, hangs the whole machine). Two opt-in limits:
|
|
10
|
+
* - {@link getMaxAgents} — max concurrently-live agents
|
|
11
|
+
* - {@link getMinFreeMb} — minimum free memory before admitting a spawn
|
|
12
|
+
*
|
|
13
|
+
* Two entry points share one instantaneous check ({@link spawnRejectionReason}):
|
|
14
|
+
* - the `ay serve` daemon HARD-REJECTS (`/api/spawn` → 429) so the caller retries;
|
|
15
|
+
* - the CLI path BLOCKS-AND-WAITS ({@link waitForSpawnCapacity}) with φ-backoff,
|
|
16
|
+
* failing open after a timeout so recursive `ay <cli>` spawns get spaced out
|
|
17
|
+
* (the actual cause of the burst storms) without ever deadlocking a workflow.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* System available memory in MB. Prefers Linux `/proc/meminfo` `MemAvailable`
|
|
21
|
+
* (the kernel's own estimate of what's reclaimable without swapping — far more
|
|
22
|
+
* accurate than free RAM), falling back to `os.freemem()` on other platforms or
|
|
23
|
+
* if the file can't be parsed. Returns null when nothing usable is available.
|
|
24
|
+
*/
|
|
25
|
+
async function memAvailableMb() {
|
|
26
|
+
try {
|
|
27
|
+
const txt = await readFile("/proc/meminfo", "utf-8");
|
|
28
|
+
const m = /^MemAvailable:\s+(\d+)\s*kB/m.exec(txt);
|
|
29
|
+
if (m) return Math.floor(Number(m[1]) / 1024);
|
|
30
|
+
} catch {}
|
|
31
|
+
try {
|
|
32
|
+
const { freemem } = await import("os");
|
|
33
|
+
return Math.floor(freemem() / (1024 * 1024));
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** True when at least one spawn limit is configured (else the gate is a no-op). */
|
|
39
|
+
function spawnGateEnabled() {
|
|
40
|
+
return getMaxAgents() !== void 0 || getMinFreeMb() !== void 0;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Instantaneous capacity check. Returns a human-readable reason string when a
|
|
44
|
+
* new spawn should be held back (cap reached / memory too low), or null when
|
|
45
|
+
* there's capacity. Both limits are opt-in — unset means no check.
|
|
46
|
+
*
|
|
47
|
+
* NOTE — the `maxAgents` count is BEST-EFFORT, not a hard barrier: the check is
|
|
48
|
+
* non-atomic (check here → register in `pids.jsonl` later, in another process),
|
|
49
|
+
* so a simultaneous burst can briefly overshoot the cap before the new wrappers
|
|
50
|
+
* appear in the live count. That's acceptable because (a) the CLI path's
|
|
51
|
+
* φ-backoff desynchronizes retries, spreading a burst out, and (b) `minFreeMb`
|
|
52
|
+
* is the HARD OOM guard — it's re-evaluated against live `/proc/meminfo` on every
|
|
53
|
+
* attempt, so once RAM actually drops, further spawns are held regardless of the
|
|
54
|
+
* count. Exact admission would need a cross-process reservation+lock (a TTL'd
|
|
55
|
+
* reservation file); deliberately deferred to avoid stale reservations wedging
|
|
56
|
+
* spawns, which would be worse than a transient overshoot.
|
|
57
|
+
*/
|
|
58
|
+
async function spawnRejectionReason() {
|
|
59
|
+
const maxAgents = getMaxAgents();
|
|
60
|
+
if (maxAgents !== void 0) {
|
|
61
|
+
const live = (await readGlobalPids({ liveOnly: true })).length;
|
|
62
|
+
if (live >= maxAgents) return `too many agents running (${live}/${maxAgents}) — this agent wasn't started. Please wait for one to finish and try again. (host: raise "maxAgents" in ~/.agent-yes/config.json or AGENT_YES_MAX_AGENTS)`;
|
|
63
|
+
}
|
|
64
|
+
const minFreeMb = getMinFreeMb();
|
|
65
|
+
if (minFreeMb !== void 0) {
|
|
66
|
+
const avail = await memAvailableMb();
|
|
67
|
+
if (avail !== null && avail < minFreeMb) return `the host is low on memory (${avail}MB free, needs ${minFreeMb}MB) — this agent wasn't started, to avoid crashing the machine. Please try again in a moment. (host: adjust "minFreeMb" in ~/.agent-yes/config.json or AGENT_YES_MIN_FREE_MB)`;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const PHI = 1.618;
|
|
72
|
+
const BACKOFF_CAP_MS = 6e4;
|
|
73
|
+
const BACKOFF_BASE_MS = 1e3;
|
|
74
|
+
/**
|
|
75
|
+
* Block until there's spawn capacity, polling with φ-backoff (1s × φⁿ, capped at
|
|
76
|
+
* 60s — there is no OS event for "memory freed", so polling is unavoidable here).
|
|
77
|
+
* Fails open after {@link getSpawnWaitMs} ms (default 10 min): on timeout it logs
|
|
78
|
+
* and proceeds, so a set of mutually-waiting recursive spawns can never deadlock
|
|
79
|
+
* permanently. A no-op (returns immediately) when no limit is configured, so it
|
|
80
|
+
* adds ~zero overhead to the spawn hot path for users who haven't opted in.
|
|
81
|
+
*
|
|
82
|
+
* `sleep`/`now` are injectable for tests. `onWait` fires once per backoff cycle.
|
|
83
|
+
*/
|
|
84
|
+
async function waitForSpawnCapacity(opts) {
|
|
85
|
+
if (!spawnGateEnabled()) return;
|
|
86
|
+
const maxWaitMs = opts?.maxWaitMs ?? getSpawnWaitMs();
|
|
87
|
+
const now = opts?.now ?? (() => performance.now());
|
|
88
|
+
const sleep = opts?.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
89
|
+
const start = now();
|
|
90
|
+
let delay = BACKOFF_BASE_MS;
|
|
91
|
+
for (;;) {
|
|
92
|
+
const reason = await spawnRejectionReason();
|
|
93
|
+
if (!reason) return;
|
|
94
|
+
const waited = now() - start;
|
|
95
|
+
if (waited >= maxWaitMs) {
|
|
96
|
+
opts?.onProceedAnyway?.(reason, waited);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
opts?.onWait?.(reason, waited);
|
|
100
|
+
await sleep(Math.min(delay, BACKOFF_CAP_MS, maxWaitMs - waited));
|
|
101
|
+
delay = Math.min(delay * PHI, BACKOFF_CAP_MS);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { waitForSpawnCapacity as i, spawnGateEnabled as n, spawnRejectionReason as r, memAvailableMb as t };
|
|
107
|
+
//# sourceMappingURL=spawnGate-B_VDMXYL.js.map
|