agent-shim 11.66.0 → 11.66.2
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/cli.cjs +89 -24
- package/dist/index.cjs +21 -15
- package/dist/index.mjs +21 -15
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -28806,6 +28806,22 @@ function daemonAdmits(fs31, allowlistFile, recordedHash, required2) {
|
|
|
28806
28806
|
const served = parseAllowlistFile(content);
|
|
28807
28807
|
return recordedHash === hashAllowlistFile(content) && required2.every((upstream) => served.includes(upstream));
|
|
28808
28808
|
}
|
|
28809
|
+
function startSupervisorUnderLock(params) {
|
|
28810
|
+
const { paths, ports } = params;
|
|
28811
|
+
ports.fs.mkdirp(paths.headroomDir);
|
|
28812
|
+
const created = ports.fs.writeFileExclusive(paths.headroomLockFile, `${JSON.stringify({ pid: params.holderPid, at: ports.now() })}
|
|
28813
|
+
`);
|
|
28814
|
+
if (created) {
|
|
28815
|
+
ports.spawnSupervisor(paths);
|
|
28816
|
+
return "spawned";
|
|
28817
|
+
}
|
|
28818
|
+
const lock = readStartLock(ports.fs, paths.headroomLockFile);
|
|
28819
|
+
if (lock === void 0 || !ports.isRunning(lock.pid)) {
|
|
28820
|
+
ports.fs.removeRecursive(paths.headroomLockFile);
|
|
28821
|
+
return "cleared-stale-lock";
|
|
28822
|
+
}
|
|
28823
|
+
return "held";
|
|
28824
|
+
}
|
|
28809
28825
|
function ensureHeadroom(params) {
|
|
28810
28826
|
const { paths, ports } = params;
|
|
28811
28827
|
let deadline = ports.now() + HEADROOM_START_TIMEOUT_MS;
|
|
@@ -28851,21 +28867,11 @@ function ensureHeadroom(params) {
|
|
|
28851
28867
|
);
|
|
28852
28868
|
}
|
|
28853
28869
|
} else if (!spawnedSupervisor) {
|
|
28854
|
-
|
|
28855
|
-
|
|
28856
|
-
paths.headroomLockFile,
|
|
28857
|
-
`${JSON.stringify({ pid: params.launcherPid, at: ports.now() })}
|
|
28858
|
-
`
|
|
28859
|
-
);
|
|
28860
|
-
if (created) {
|
|
28861
|
-
ports.spawnSupervisor(paths);
|
|
28870
|
+
const started = startSupervisorUnderLock({ paths, holderPid: params.launcherPid, ports });
|
|
28871
|
+
if (started === "spawned") {
|
|
28862
28872
|
spawnedSupervisor = true;
|
|
28863
|
-
} else {
|
|
28864
|
-
|
|
28865
|
-
if (lock === void 0 || !ports.isRunning(lock.pid)) {
|
|
28866
|
-
ports.fs.removeRecursive(paths.headroomLockFile);
|
|
28867
|
-
continue;
|
|
28868
|
-
}
|
|
28873
|
+
} else if (started === "cleared-stale-lock") {
|
|
28874
|
+
continue;
|
|
28869
28875
|
}
|
|
28870
28876
|
}
|
|
28871
28877
|
if (ports.now() >= deadline) {
|
|
@@ -37176,7 +37182,7 @@ var init_package = __esm({
|
|
|
37176
37182
|
"package.json"() {
|
|
37177
37183
|
package_default = {
|
|
37178
37184
|
name: "agent-shim",
|
|
37179
|
-
version: "11.66.
|
|
37185
|
+
version: "11.66.2",
|
|
37180
37186
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
37181
37187
|
license: "MIT",
|
|
37182
37188
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -119239,6 +119245,50 @@ function showSession(fs31, identitiesDir, identities, query, onlyIdentity) {
|
|
|
119239
119245
|
// src/frontdoor/commands.ts
|
|
119240
119246
|
init_realPorts();
|
|
119241
119247
|
|
|
119248
|
+
// src/headroom/keeper.ts
|
|
119249
|
+
init_ensure();
|
|
119250
|
+
init_state2();
|
|
119251
|
+
function createHeadroomKeeper(deps) {
|
|
119252
|
+
const { paths, ports, log } = deps;
|
|
119253
|
+
let lastAttemptAt;
|
|
119254
|
+
const releaseOwnLock = () => {
|
|
119255
|
+
if (readStartLock(ports.fs, paths.headroomLockFile)?.pid === deps.ownPid) {
|
|
119256
|
+
ports.fs.removeRecursive(paths.headroomLockFile);
|
|
119257
|
+
}
|
|
119258
|
+
};
|
|
119259
|
+
const tick = () => {
|
|
119260
|
+
const state = resolveServingHeadroomState(ports.fs, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
|
|
119261
|
+
const supervisorPid = state?.supervisorPid;
|
|
119262
|
+
const orphans = listSessions(ports.fs, paths.headroomSessionsDir).filter((session) => ports.isRunning(session.pid) && !ports.isRunning(session.supervisorPid));
|
|
119263
|
+
if (supervisorPid !== void 0 && ports.isRunning(supervisorPid)) {
|
|
119264
|
+
lastAttemptAt = void 0;
|
|
119265
|
+
releaseOwnLock();
|
|
119266
|
+
for (const session of orphans) {
|
|
119267
|
+
writeSession(ports.fs, paths.headroomSessionsDir, { ...session, supervisorPid });
|
|
119268
|
+
}
|
|
119269
|
+
if (orphans.length > 0) {
|
|
119270
|
+
log(`front door: re-registered ${String(orphans.length)} launcher(s) against headroom supervisor ${String(supervisorPid)}`);
|
|
119271
|
+
}
|
|
119272
|
+
return { kind: "serving", rebound: orphans.map((session) => session.pid) };
|
|
119273
|
+
}
|
|
119274
|
+
if (orphans.length === 0) {
|
|
119275
|
+
return { kind: "idle" };
|
|
119276
|
+
}
|
|
119277
|
+
if (lastAttemptAt !== void 0 && ports.now() - lastAttemptAt < HEADROOM_START_TIMEOUT_MS) {
|
|
119278
|
+
return { kind: "backing-off", waiting: orphans.length };
|
|
119279
|
+
}
|
|
119280
|
+
releaseOwnLock();
|
|
119281
|
+
lastAttemptAt = ports.now();
|
|
119282
|
+
const start = startSupervisorUnderLock({ paths, holderPid: deps.ownPid, ports });
|
|
119283
|
+
log(`front door: headroom supervisor is not running and ${String(orphans.length)} launcher(s) are registered against it (${start})`);
|
|
119284
|
+
return { kind: "starting", start, waiting: orphans.length };
|
|
119285
|
+
};
|
|
119286
|
+
return { tick };
|
|
119287
|
+
}
|
|
119288
|
+
|
|
119289
|
+
// src/frontdoor/commands.ts
|
|
119290
|
+
init_supervisor();
|
|
119291
|
+
|
|
119242
119292
|
// src/supervise/registry.ts
|
|
119243
119293
|
var import_node_path36 = __toESM(require("node:path"), 1);
|
|
119244
119294
|
init_zod();
|
|
@@ -139424,6 +139474,21 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
139424
139474
|
timer.unref();
|
|
139425
139475
|
keeperTimers.push(timer);
|
|
139426
139476
|
};
|
|
139477
|
+
const headroomKeeper = createHeadroomKeeper({
|
|
139478
|
+
paths,
|
|
139479
|
+
ownPid: process.pid,
|
|
139480
|
+
ports: { fs: realFarmFs, now: () => Date.now(), isRunning: realIsProcessRunning, spawnSupervisor: (layout) => spawnDetachedSupervisor(layout, "__headroom-supervisor", layout.headroomLogPath) },
|
|
139481
|
+
log
|
|
139482
|
+
});
|
|
139483
|
+
const headroomKeeperTimer = setInterval(() => {
|
|
139484
|
+
try {
|
|
139485
|
+
headroomKeeper.tick();
|
|
139486
|
+
} catch (error63) {
|
|
139487
|
+
log(`headroom keeper failed: ${error63 instanceof Error ? error63.message : String(error63)}`);
|
|
139488
|
+
}
|
|
139489
|
+
}, HEADROOM_POLL_MS);
|
|
139490
|
+
headroomKeeperTimer.unref();
|
|
139491
|
+
keeperTimers.push(headroomKeeperTimer);
|
|
139427
139492
|
everyFreshnessInterval(() => {
|
|
139428
139493
|
try {
|
|
139429
139494
|
const pools = readPools(paths);
|
|
@@ -140397,18 +140462,18 @@ function sweepStaleRunDirectories(root) {
|
|
|
140397
140462
|
}
|
|
140398
140463
|
}
|
|
140399
140464
|
}
|
|
140400
|
-
function runProgram(runRoot, file2, args, cwd, options = {}) {
|
|
140401
|
-
return options.outputInFile === true ? runWithOutputInFile(runRoot, file2, args, cwd) : runWithPipe(file2, args, cwd);
|
|
140465
|
+
function runProgram(runRoot, timeoutMs, file2, args, cwd, options = {}) {
|
|
140466
|
+
return options.outputInFile === true ? runWithOutputInFile(runRoot, timeoutMs, file2, args, cwd) : runWithPipe(timeoutMs, file2, args, cwd);
|
|
140402
140467
|
}
|
|
140403
|
-
function runWithPipe(file2, args, cwd) {
|
|
140468
|
+
function runWithPipe(timeoutMs, file2, args, cwd) {
|
|
140404
140469
|
try {
|
|
140405
|
-
const result = spawnSyncBlocking("a statusline command", file2, args, { cwd, encoding: "utf8", timeout:
|
|
140470
|
+
const result = spawnSyncBlocking("a statusline command", file2, args, { cwd, encoding: "utf8", timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: RUN_MAX_OUTPUT_BYTES, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
|
|
140406
140471
|
return result.error === void 0 && result.status === 0 ? result.stdout : void 0;
|
|
140407
140472
|
} catch {
|
|
140408
140473
|
return void 0;
|
|
140409
140474
|
}
|
|
140410
140475
|
}
|
|
140411
|
-
function runWithOutputInFile(runRoot, file2, args, cwd) {
|
|
140476
|
+
function runWithOutputInFile(runRoot, timeoutMs, file2, args, cwd) {
|
|
140412
140477
|
let directory;
|
|
140413
140478
|
try {
|
|
140414
140479
|
sweepStaleRunDirectories(runRoot);
|
|
@@ -140417,7 +140482,7 @@ function runWithOutputInFile(runRoot, file2, args, cwd) {
|
|
|
140417
140482
|
const descriptor = import_node_fs23.default.openSync(import_node_path56.default.join(directory, "stdout"), "wx+", RUN_FILE_MODE);
|
|
140418
140483
|
try {
|
|
140419
140484
|
const limited = process.platform === "win32" ? { command: file2, args } : fileSizeLimitedCommand("/bin/sh", file2, args);
|
|
140420
|
-
const result = spawnSyncBlocking("a statusline command", limited.command, limited.args, { cwd, timeout:
|
|
140485
|
+
const result = spawnSyncBlocking("a statusline command", limited.command, limited.args, { cwd, timeout: timeoutMs, killSignal: "SIGKILL", stdio: ["ignore", descriptor, "ignore"], windowsHide: true });
|
|
140421
140486
|
return result.error === void 0 && result.status === 0 ? readOutput(descriptor) : void 0;
|
|
140422
140487
|
} finally {
|
|
140423
140488
|
import_node_fs23.default.closeSync(descriptor);
|
|
@@ -140447,7 +140512,7 @@ function discard(target) {
|
|
|
140447
140512
|
function readMemoryUse() {
|
|
140448
140513
|
const totalBytes = import_node_os12.default.totalmem();
|
|
140449
140514
|
if (process.platform === "darwin") {
|
|
140450
|
-
const output2 = runWithPipe("/usr/bin/vm_stat", [], process.cwd());
|
|
140515
|
+
const output2 = runWithPipe(RUN_TIMEOUT_MS, "/usr/bin/vm_stat", [], process.cwd());
|
|
140451
140516
|
const usedBytes = output2 === void 0 ? void 0 : usedBytesFromVmStat(output2);
|
|
140452
140517
|
return usedBytes === void 0 ? void 0 : { usedBytes, totalBytes };
|
|
140453
140518
|
}
|
|
@@ -140457,7 +140522,7 @@ function readMemoryUse() {
|
|
|
140457
140522
|
}
|
|
140458
140523
|
return { usedBytes: totalBytes - import_node_os12.default.freemem(), totalBytes };
|
|
140459
140524
|
}
|
|
140460
|
-
function realStatuslinePorts(env, stateDirectory) {
|
|
140525
|
+
function realStatuslinePorts(env, stateDirectory, runTimeoutMs = RUN_TIMEOUT_MS) {
|
|
140461
140526
|
const { locale, timeZone } = Intl.DateTimeFormat().resolvedOptions();
|
|
140462
140527
|
return {
|
|
140463
140528
|
env,
|
|
@@ -140480,7 +140545,7 @@ function realStatuslinePorts(env, stateDirectory) {
|
|
|
140480
140545
|
return void 0;
|
|
140481
140546
|
}
|
|
140482
140547
|
},
|
|
140483
|
-
run: (file2, args, cwd, options) => runProgram(import_node_path56.default.join(stateDirectory, RUN_DIRECTORY), file2, args, cwd, options),
|
|
140548
|
+
run: (file2, args, cwd, options) => runProgram(import_node_path56.default.join(stateDirectory, RUN_DIRECTORY), runTimeoutMs, file2, args, cwd, options),
|
|
140484
140549
|
entryKind: (target) => {
|
|
140485
140550
|
try {
|
|
140486
140551
|
return import_node_fs23.default.lstatSync(target).isDirectory() ? "directory" : "other";
|
package/dist/index.cjs
CHANGED
|
@@ -4751,7 +4751,7 @@ var init_package = __esm({
|
|
|
4751
4751
|
"package.json"() {
|
|
4752
4752
|
package_default = {
|
|
4753
4753
|
name: "agent-shim",
|
|
4754
|
-
version: "11.66.
|
|
4754
|
+
version: "11.66.2",
|
|
4755
4755
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
4756
4756
|
license: "MIT",
|
|
4757
4757
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -5241,6 +5241,22 @@ function daemonAdmits(fs14, allowlistFile, recordedHash, required) {
|
|
|
5241
5241
|
const served = parseAllowlistFile(content);
|
|
5242
5242
|
return recordedHash === hashAllowlistFile(content) && required.every((upstream) => served.includes(upstream));
|
|
5243
5243
|
}
|
|
5244
|
+
function startSupervisorUnderLock(params) {
|
|
5245
|
+
const { paths, ports } = params;
|
|
5246
|
+
ports.fs.mkdirp(paths.headroomDir);
|
|
5247
|
+
const created = ports.fs.writeFileExclusive(paths.headroomLockFile, `${JSON.stringify({ pid: params.holderPid, at: ports.now() })}
|
|
5248
|
+
`);
|
|
5249
|
+
if (created) {
|
|
5250
|
+
ports.spawnSupervisor(paths);
|
|
5251
|
+
return "spawned";
|
|
5252
|
+
}
|
|
5253
|
+
const lock = readStartLock(ports.fs, paths.headroomLockFile);
|
|
5254
|
+
if (lock === void 0 || !ports.isRunning(lock.pid)) {
|
|
5255
|
+
ports.fs.removeRecursive(paths.headroomLockFile);
|
|
5256
|
+
return "cleared-stale-lock";
|
|
5257
|
+
}
|
|
5258
|
+
return "held";
|
|
5259
|
+
}
|
|
5244
5260
|
function ensureHeadroom(params) {
|
|
5245
5261
|
const { paths, ports } = params;
|
|
5246
5262
|
let deadline = ports.now() + HEADROOM_START_TIMEOUT_MS;
|
|
@@ -5286,21 +5302,11 @@ function ensureHeadroom(params) {
|
|
|
5286
5302
|
);
|
|
5287
5303
|
}
|
|
5288
5304
|
} else if (!spawnedSupervisor) {
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
paths.headroomLockFile,
|
|
5292
|
-
`${JSON.stringify({ pid: params.launcherPid, at: ports.now() })}
|
|
5293
|
-
`
|
|
5294
|
-
);
|
|
5295
|
-
if (created) {
|
|
5296
|
-
ports.spawnSupervisor(paths);
|
|
5305
|
+
const started = startSupervisorUnderLock({ paths, holderPid: params.launcherPid, ports });
|
|
5306
|
+
if (started === "spawned") {
|
|
5297
5307
|
spawnedSupervisor = true;
|
|
5298
|
-
} else {
|
|
5299
|
-
|
|
5300
|
-
if (lock === void 0 || !ports.isRunning(lock.pid)) {
|
|
5301
|
-
ports.fs.removeRecursive(paths.headroomLockFile);
|
|
5302
|
-
continue;
|
|
5303
|
-
}
|
|
5308
|
+
} else if (started === "cleared-stale-lock") {
|
|
5309
|
+
continue;
|
|
5304
5310
|
}
|
|
5305
5311
|
}
|
|
5306
5312
|
if (ports.now() >= deadline) {
|
package/dist/index.mjs
CHANGED
|
@@ -4727,7 +4727,7 @@ var init_package = __esm({
|
|
|
4727
4727
|
"package.json"() {
|
|
4728
4728
|
package_default = {
|
|
4729
4729
|
name: "agent-shim",
|
|
4730
|
-
version: "11.66.
|
|
4730
|
+
version: "11.66.2",
|
|
4731
4731
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
4732
4732
|
license: "MIT",
|
|
4733
4733
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -5218,6 +5218,22 @@ function daemonAdmits(fs14, allowlistFile, recordedHash, required) {
|
|
|
5218
5218
|
const served = parseAllowlistFile(content);
|
|
5219
5219
|
return recordedHash === hashAllowlistFile(content) && required.every((upstream) => served.includes(upstream));
|
|
5220
5220
|
}
|
|
5221
|
+
function startSupervisorUnderLock(params) {
|
|
5222
|
+
const { paths, ports } = params;
|
|
5223
|
+
ports.fs.mkdirp(paths.headroomDir);
|
|
5224
|
+
const created = ports.fs.writeFileExclusive(paths.headroomLockFile, `${JSON.stringify({ pid: params.holderPid, at: ports.now() })}
|
|
5225
|
+
`);
|
|
5226
|
+
if (created) {
|
|
5227
|
+
ports.spawnSupervisor(paths);
|
|
5228
|
+
return "spawned";
|
|
5229
|
+
}
|
|
5230
|
+
const lock = readStartLock(ports.fs, paths.headroomLockFile);
|
|
5231
|
+
if (lock === void 0 || !ports.isRunning(lock.pid)) {
|
|
5232
|
+
ports.fs.removeRecursive(paths.headroomLockFile);
|
|
5233
|
+
return "cleared-stale-lock";
|
|
5234
|
+
}
|
|
5235
|
+
return "held";
|
|
5236
|
+
}
|
|
5221
5237
|
function ensureHeadroom(params) {
|
|
5222
5238
|
const { paths, ports } = params;
|
|
5223
5239
|
let deadline = ports.now() + HEADROOM_START_TIMEOUT_MS;
|
|
@@ -5263,21 +5279,11 @@ function ensureHeadroom(params) {
|
|
|
5263
5279
|
);
|
|
5264
5280
|
}
|
|
5265
5281
|
} else if (!spawnedSupervisor) {
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
paths.headroomLockFile,
|
|
5269
|
-
`${JSON.stringify({ pid: params.launcherPid, at: ports.now() })}
|
|
5270
|
-
`
|
|
5271
|
-
);
|
|
5272
|
-
if (created) {
|
|
5273
|
-
ports.spawnSupervisor(paths);
|
|
5282
|
+
const started = startSupervisorUnderLock({ paths, holderPid: params.launcherPid, ports });
|
|
5283
|
+
if (started === "spawned") {
|
|
5274
5284
|
spawnedSupervisor = true;
|
|
5275
|
-
} else {
|
|
5276
|
-
|
|
5277
|
-
if (lock === void 0 || !ports.isRunning(lock.pid)) {
|
|
5278
|
-
ports.fs.removeRecursive(paths.headroomLockFile);
|
|
5279
|
-
continue;
|
|
5280
|
-
}
|
|
5285
|
+
} else if (started === "cleared-stale-lock") {
|
|
5286
|
+
continue;
|
|
5281
5287
|
}
|
|
5282
5288
|
}
|
|
5283
5289
|
if (ports.now() >= deadline) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-shim",
|
|
3
|
-
"version": "11.66.
|
|
3
|
+
"version": "11.66.2",
|
|
4
4
|
"description": "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Joseph Mearman <joseph@mearman.co.uk>",
|