lobstah 0.7.5 → 0.7.6

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/runner.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // packages/runner/src/index.ts
2
- import * as fs27 from "node:fs";
3
- import * as path23 from "node:path";
2
+ import * as fs29 from "node:fs";
3
+ import * as path25 from "node:path";
4
4
 
5
5
  // packages/core/dist/types.js
6
6
  var VERBS = ["working", "needs-decision", "blocked", "paused", "done", "failed"];
@@ -8,9 +8,9 @@ var TERMINAL_VERBS = ["done", "failed"];
8
8
  var WAITING_ON = ["review", "pr", "deploy", "person", "external"];
9
9
  var WAITING_ON_VERBS = ["paused", "needs-decision", "blocked"];
10
10
 
11
- // packages/core/dist/stats.js
12
- import * as fs18 from "node:fs";
13
- import * as path14 from "node:path";
11
+ // packages/core/dist/queue.js
12
+ import * as fs22 from "node:fs";
13
+ import * as path18 from "node:path";
14
14
 
15
15
  // packages/core/dist/paths.js
16
16
  import * as os from "node:os";
@@ -74,106 +74,8 @@ function evidencePath(id, lane) {
74
74
  return path.join(laneDirs(lane).state, `${id}.evidence`);
75
75
  }
76
76
 
77
- // packages/core/dist/worker-metadata.js
78
- var WORKER_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"];
79
- var WORKER_PERMISSIONS = ["default", "acceptEdits", "plan", "dontAsk", "bypassPermissions", "auto"];
80
- function localModel(value) {
81
- return typeof value === "string" && /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,127}$/.test(value) ? value : null;
82
- }
83
- function choice(value, values) {
84
- return typeof value === "string" && values.includes(value) ? value : null;
85
- }
86
- function workerMetadata(input = {}) {
87
- return {
88
- harness: localModel(input.harness),
89
- model: localModel(input.model),
90
- config: { effort: choice(input.config?.effort, WORKER_EFFORTS), permissionMode: choice(input.config?.permissionMode, WORKER_PERMISSIONS) },
91
- ...typeof input.observedAt === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(input.observedAt) && Number.isFinite(Date.parse(input.observedAt)) ? { observedAt: input.observedAt } : {}
92
- };
93
- }
94
-
95
- // packages/core/dist/worker-profile.js
96
- var WORKER_HARNESSES = ["claude", "codex", "other"];
97
- var WORKER_MODEL_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/;
98
- var WORKER_MODELS = [
99
- "other",
100
- "opus",
101
- "sonnet",
102
- "haiku",
103
- "fable",
104
- "opusplan",
105
- "claude-opus-4",
106
- "claude-opus-4-1",
107
- "claude-opus-4-5",
108
- "claude-opus-4-6",
109
- "claude-opus-5",
110
- "claude-opus-5-5",
111
- "claude-sonnet-4",
112
- "claude-sonnet-4-5",
113
- "claude-sonnet-4-6",
114
- "claude-sonnet-5",
115
- "claude-haiku-4-5",
116
- "claude-opus-4-20250514",
117
- "claude-sonnet-4-20250514",
118
- "claude-sonnet-4-5-20250929",
119
- "claude-haiku-4-5-20251001",
120
- "claude-opus-4-1-20250805",
121
- "claude-opus-4-5-20251101",
122
- "gpt-5",
123
- "gpt-5-codex",
124
- "gpt-5.1",
125
- "gpt-5.1-codex",
126
- "gpt-5.1-codex-mini",
127
- "gpt-5.1-codex-max",
128
- "gpt-5.2",
129
- "gpt-5.2-codex",
130
- "gpt-5.3-codex",
131
- "gpt-5.4",
132
- "gpt-5.4-mini",
133
- "gpt-5.5",
134
- "gpt-5.6-sol",
135
- "gpt-5.6-terra",
136
- "gpt-5.6-luna",
137
- "gpt-6",
138
- "gpt-6-sol",
139
- "gpt-6-astra",
140
- "gpt-6-luna",
141
- "gpt-6.1-sol",
142
- "codex-mini-latest",
143
- "o1",
144
- "o3",
145
- "o3-mini",
146
- "o4-mini"
147
- ];
148
- function choice2(value, choices) {
149
- return typeof value === "string" && choices.includes(value) ? value : null;
150
- }
151
- function safeModel(value) {
152
- if (value === void 0 || value === null || value === "")
153
- return null;
154
- return typeof value === "string" && WORKER_MODEL_RE.test(value) && WORKER_MODELS.includes(value) ? value : "other";
155
- }
156
- function workerProfile(input = {}) {
157
- return {
158
- harness: input.harness === void 0 || input.harness === null ? null : choice2(input.harness, WORKER_HARNESSES) ?? "other",
159
- model: safeModel(input.model),
160
- config: { effort: choice2(input.effort, WORKER_EFFORTS), permissionMode: choice2(input.permissionMode, WORKER_PERMISSIONS) }
161
- };
162
- }
163
- function sanitizeWorker(value) {
164
- return workerProfile({ harness: value?.harness, model: value?.model, effort: value?.config?.effort, permissionMode: value?.config?.permissionMode });
165
- }
166
-
167
- // packages/core/dist/soak.js
168
- import * as fs17 from "node:fs";
169
- import * as path13 from "node:path";
170
-
171
- // packages/core/dist/queue.js
172
- import * as fs4 from "node:fs";
173
- import * as path3 from "node:path";
174
-
175
77
  // packages/core/dist/status.js
176
- import * as fs3 from "node:fs";
78
+ import * as fs21 from "node:fs";
177
79
 
178
80
  // packages/core/dist/activity.js
179
81
  import * as fs2 from "node:fs";
@@ -382,138 +284,109 @@ var ActivityTracker = class {
382
284
  }
383
285
  };
384
286
 
385
- // packages/core/dist/status.js
386
- function isVerb(v) {
387
- return VERBS.includes(v);
287
+ // packages/core/dist/stats.js
288
+ import * as fs20 from "node:fs";
289
+ import * as path17 from "node:path";
290
+
291
+ // packages/core/dist/worker-metadata.js
292
+ var WORKER_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"];
293
+ var WORKER_PERMISSIONS = ["default", "acceptEdits", "plan", "dontAsk", "bypassPermissions", "auto"];
294
+ function localModel(value) {
295
+ return typeof value === "string" && /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,127}$/.test(value) ? value : null;
388
296
  }
389
- function isWaitingOn(v) {
390
- return WAITING_ON.includes(v);
297
+ function choice(value, values) {
298
+ return typeof value === "string" && values.includes(value) ? value : null;
391
299
  }
392
- var DURATION = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/i;
393
- var UNIT_MS = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 };
394
- function parseUntil(v, now2 = Date.now()) {
395
- const d = DURATION.exec(v.trim());
396
- if (d)
397
- return new Date(now2 + Number(d[1]) * UNIT_MS[d[2].toLowerCase()]).toISOString();
398
- const t = Date.parse(v);
399
- if (Number.isNaN(t))
400
- throw new Error(`invalid --until "${v}" \u2014 an ISO time (2026-10-01T09:00Z) or a duration (30m, 4h, 2d)`);
401
- return new Date(t).toISOString();
300
+ function workerMetadata(input = {}) {
301
+ return {
302
+ harness: localModel(input.harness),
303
+ model: localModel(input.model),
304
+ config: { effort: choice(input.config?.effort, WORKER_EFFORTS), permissionMode: choice(input.config?.permissionMode, WORKER_PERMISSIONS) },
305
+ ...typeof input.observedAt === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(input.observedAt) && Number.isFinite(Date.parse(input.observedAt)) ? { observedAt: input.observedAt } : {}
306
+ };
402
307
  }
403
- function waitingFields(verb, w, now2 = Date.now()) {
404
- const out = {};
405
- if ((w.waitingOn !== void 0 || w.link !== void 0) && !WAITING_ON_VERBS.includes(verb)) {
406
- throw new Error(`--waiting-on and --link are valid only with ${WAITING_ON_VERBS.join(", ")} \u2014 not ${verb}`);
407
- }
408
- if (w.until !== void 0 && verb !== "paused")
409
- throw new Error(`--until is valid only with paused \u2014 not ${verb}`);
410
- if (w.waitingOn !== void 0) {
411
- if (!isWaitingOn(w.waitingOn)) {
412
- throw new Error(`invalid --waiting-on "${w.waitingOn}" \u2014 must be one of: ${WAITING_ON.join(", ")}`);
413
- }
414
- out.waitingOn = w.waitingOn;
415
- }
416
- if (w.link !== void 0) {
417
- let url;
418
- try {
419
- url = new URL(w.link);
420
- } catch {
421
- url = void 0;
422
- }
423
- if (!url || url.protocol !== "http:" && url.protocol !== "https:") {
424
- throw new Error(`invalid --link "${w.link}" \u2014 must be an http or https URL`);
425
- }
426
- out.link = url.href;
427
- }
428
- if (w.until !== void 0)
429
- out.until = parseUntil(w.until, now2);
430
- return out;
308
+
309
+ // packages/core/dist/worker-profile.js
310
+ var WORKER_HARNESSES = ["claude", "codex", "other"];
311
+ var WORKER_MODEL_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/;
312
+ var WORKER_MODELS = [
313
+ "other",
314
+ "opus",
315
+ "sonnet",
316
+ "haiku",
317
+ "fable",
318
+ "opusplan",
319
+ "claude-opus-4",
320
+ "claude-opus-4-1",
321
+ "claude-opus-4-5",
322
+ "claude-opus-4-6",
323
+ "claude-opus-5",
324
+ "claude-opus-5-5",
325
+ "claude-sonnet-4",
326
+ "claude-sonnet-4-5",
327
+ "claude-sonnet-4-6",
328
+ "claude-sonnet-5",
329
+ "claude-haiku-4-5",
330
+ "claude-opus-4-20250514",
331
+ "claude-sonnet-4-20250514",
332
+ "claude-sonnet-4-5-20250929",
333
+ "claude-haiku-4-5-20251001",
334
+ "claude-opus-4-1-20250805",
335
+ "claude-opus-4-5-20251101",
336
+ "gpt-5",
337
+ "gpt-5-codex",
338
+ "gpt-5.1",
339
+ "gpt-5.1-codex",
340
+ "gpt-5.1-codex-mini",
341
+ "gpt-5.1-codex-max",
342
+ "gpt-5.2",
343
+ "gpt-5.2-codex",
344
+ "gpt-5.3-codex",
345
+ "gpt-5.4",
346
+ "gpt-5.4-mini",
347
+ "gpt-5.5",
348
+ "gpt-5.6-sol",
349
+ "gpt-5.6-terra",
350
+ "gpt-5.6-luna",
351
+ "gpt-6",
352
+ "gpt-6-sol",
353
+ "gpt-6-astra",
354
+ "gpt-6-luna",
355
+ "gpt-6.1-sol",
356
+ "codex-mini-latest",
357
+ "o1",
358
+ "o3",
359
+ "o3-mini",
360
+ "o4-mini"
361
+ ];
362
+ function choice2(value, choices) {
363
+ return typeof value === "string" && choices.includes(value) ? value : null;
431
364
  }
432
- function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
433
- if (!isVerb(verb)) {
434
- throw new Error(`invalid status verb "${verb}" \u2014 must be one of: ${VERBS.join(", ")}`);
435
- }
436
- const extra = waiting ? waitingFields(verb, waiting) : {};
437
- const entry = {
438
- at: at ?? (/* @__PURE__ */ new Date()).toISOString(),
439
- verb,
440
- ...note ? { note } : {},
441
- ...extra,
442
- ...reported ? { reported: true } : {}
365
+ function safeModel(value) {
366
+ if (value === void 0 || value === null || value === "")
367
+ return null;
368
+ return typeof value === "string" && WORKER_MODEL_RE.test(value) && WORKER_MODELS.includes(value) ? value : "other";
369
+ }
370
+ function workerProfile(input = {}) {
371
+ return {
372
+ harness: input.harness === void 0 || input.harness === null ? null : choice2(input.harness, WORKER_HARNESSES) ?? "other",
373
+ model: safeModel(input.model),
374
+ config: { effort: choice2(input.effort, WORKER_EFFORTS), permissionMode: choice2(input.permissionMode, WORKER_PERMISSIONS) }
443
375
  };
444
- fs3.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
445
- `);
446
- if (verb === "done") {
447
- try {
448
- recordCatch(id, lane);
449
- } catch {
450
- }
451
- }
452
- return entry;
453
376
  }
454
- function readStatusLog(id, lane) {
455
- const file2 = statusPath(id, lane);
456
- if (!fs3.existsSync(file2))
457
- return [];
458
- return fs3.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
459
- try {
460
- const parsed = JSON.parse(line);
461
- return isVerb(parsed.verb) ? [parsed] : [];
462
- } catch {
463
- return [];
464
- }
465
- });
466
- }
467
- function pausedWaiting(entry) {
468
- return entry?.verb === "paused" && entry.waitingOn !== void 0;
377
+ function sanitizeWorker(value) {
378
+ return workerProfile({ harness: value?.harness, model: value?.model, effort: value?.config?.effort, permissionMode: value?.config?.permissionMode });
469
379
  }
470
380
 
471
- // packages/core/dist/queue.js
472
- function requeue(id, lane) {
473
- const dirs = laneDirs(lane);
474
- const activeDir = path3.join(dirs.active, id);
475
- const file2 = path3.join(activeDir, "descriptor.json");
476
- const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
477
- const tmp = uniqueTempPath(file2);
478
- fs4.writeFileSync(tmp, JSON.stringify(d, null, 2));
479
- atomicRenameSync(tmp, file2);
480
- fs4.renameSync(file2, path3.join(dirs.queue, `${id}.json`));
481
- fs4.rmSync(activeDir, { recursive: true, force: true });
482
- }
483
- function readDescriptor(id, lane) {
484
- const file2 = path3.join(laneDirs(lane).active, id, "descriptor.json");
485
- return JSON.parse(fs4.readFileSync(file2, "utf8"));
486
- }
487
- function storedDescriptor(id, lane) {
488
- const dirs = laneDirs(lane);
489
- for (const file2 of [
490
- path3.join(dirs.queue, `${id}.json`),
491
- path3.join(dirs.active, id, "descriptor.json"),
492
- path3.join(dirs.done, id, "descriptor.json")
493
- ]) {
494
- try {
495
- return JSON.parse(fs4.readFileSync(file2, "utf8"));
496
- } catch {
497
- }
498
- }
499
- return void 0;
500
- }
501
- function activeIds(lane) {
502
- return readDirIfPresent(laneDirs(lane).active).filter((f) => !f.startsWith("."));
503
- }
504
- function complete(id, lane) {
505
- const dirs = laneDirs(lane);
506
- fs4.renameSync(path3.join(dirs.active, id), path3.join(dirs.done, id));
507
- }
508
- function cancelRequested(id, lane) {
509
- return fs4.existsSync(path3.join(laneDirs(lane).active, id, "cancel"));
510
- }
381
+ // packages/core/dist/soak.js
382
+ import * as fs18 from "node:fs";
383
+ import * as path15 from "node:path";
511
384
 
512
385
  // packages/core/dist/evidence.js
513
- import * as fs5 from "node:fs";
386
+ import * as fs3 from "node:fs";
514
387
  function readEvidence(id, lane) {
515
388
  try {
516
- return JSON.parse(fs5.readFileSync(evidencePath(id, lane), "utf8"));
389
+ return JSON.parse(fs3.readFileSync(evidencePath(id, lane), "utf8"));
517
390
  } catch {
518
391
  return {};
519
392
  }
@@ -521,13 +394,13 @@ function readEvidence(id, lane) {
521
394
  function mergeEvidence(id, lane, patch) {
522
395
  const file2 = evidencePath(id, lane);
523
396
  const tmp = uniqueTempPath(file2);
524
- fs5.writeFileSync(tmp, JSON.stringify({ ...readEvidence(id, lane), ...patch }, null, 2));
397
+ fs3.writeFileSync(tmp, JSON.stringify({ ...readEvidence(id, lane), ...patch }, null, 2));
525
398
  atomicRenameSync(tmp, file2);
526
399
  }
527
400
 
528
401
  // packages/core/dist/pushes.js
529
- import * as fs6 from "node:fs";
530
- import * as path4 from "node:path";
402
+ import * as fs4 from "node:fs";
403
+ import * as path3 from "node:path";
531
404
  var MAX_PUSHES = 20;
532
405
  var PUSH_HEAD = "HEAD";
533
406
  var VALUE_OPTIONS = /* @__PURE__ */ new Set(["-o", "--push-option", "--repo", "--receive-pack", "--exec"]);
@@ -582,18 +455,18 @@ function gitPushTargets(command) {
582
455
  return found ? [...new Set(targets)] : void 0;
583
456
  }
584
457
  function gitDirAt(dir) {
585
- let at = path4.resolve(dir);
458
+ let at = path3.resolve(dir);
586
459
  for (; ; ) {
587
- const dotGit = path4.join(at, ".git");
460
+ const dotGit = path3.join(at, ".git");
588
461
  try {
589
- const stat = fs6.statSync(dotGit);
462
+ const stat = fs4.statSync(dotGit);
590
463
  if (stat.isDirectory())
591
464
  return dotGit;
592
- const m = /^gitdir:\s*(.+)$/m.exec(fs6.readFileSync(dotGit, "utf8"));
593
- return m ? path4.resolve(at, m[1].trim()) : void 0;
465
+ const m = /^gitdir:\s*(.+)$/m.exec(fs4.readFileSync(dotGit, "utf8"));
466
+ return m ? path3.resolve(at, m[1].trim()) : void 0;
594
467
  } catch {
595
468
  }
596
- const up = path4.dirname(at);
469
+ const up = path3.dirname(at);
597
470
  if (up === at)
598
471
  return void 0;
599
472
  at = up;
@@ -604,7 +477,7 @@ function currentBranchAt(dir) {
604
477
  if (!gitDir)
605
478
  return void 0;
606
479
  try {
607
- const m = /^ref:\s*refs\/heads\/(.+)$/m.exec(fs6.readFileSync(path4.join(gitDir, "HEAD"), "utf8"));
480
+ const m = /^ref:\s*refs\/heads\/(.+)$/m.exec(fs4.readFileSync(path3.join(gitDir, "HEAD"), "utf8"));
608
481
  return m ? m[1].trim() : void 0;
609
482
  } catch {
610
483
  return void 0;
@@ -624,12 +497,12 @@ function recordPush(id, lane, branches, at = (/* @__PURE__ */ new Date()).toISOS
624
497
 
625
498
  // packages/core/dist/notices.js
626
499
  import fs16 from "node:fs";
627
- import * as path12 from "node:path";
500
+ import * as path13 from "node:path";
628
501
 
629
502
  // packages/core/dist/config.js
630
- import * as fs7 from "node:fs";
503
+ import * as fs5 from "node:fs";
631
504
  import * as os2 from "node:os";
632
- import * as path5 from "node:path";
505
+ import * as path4 from "node:path";
633
506
 
634
507
  // node_modules/.pnpm/smol-toml@1.8.0/node_modules/smol-toml/dist/date.js
635
508
  var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
@@ -1354,12 +1227,15 @@ function parseAttentionKinds(raw) {
1354
1227
  }
1355
1228
  function parseSoak(raw) {
1356
1229
  const soak = { ...DEFAULT_SOAK, ...raw ?? {} };
1230
+ if (typeof soak.acceptWharfStarts !== "boolean")
1231
+ throw new Error("soak.acceptWharfStarts must be true or false");
1357
1232
  if (soak.terminal !== void 0 && soak.terminal !== "terminal" && soak.terminal !== "iterm") {
1358
1233
  throw new Error(`soak.terminal: unknown terminal "${String(soak.terminal)}" in ${configPath()} \u2014 use "terminal" or "iterm"`);
1359
1234
  }
1360
1235
  return soak;
1361
1236
  }
1362
1237
  var DEFAULT_SOAK = {
1238
+ acceptWharfStarts: false,
1363
1239
  deferSecs: 90,
1364
1240
  claimIdleNoticeSecs: 180,
1365
1241
  ttlSecs: 1800,
@@ -1396,14 +1272,14 @@ var DEFAULT_LIMITS = {
1396
1272
  releaseOnMerge: false
1397
1273
  };
1398
1274
  function configPath() {
1399
- return path5.join(lobstahHome(), "config.toml");
1275
+ return path4.join(lobstahHome(), "config.toml");
1400
1276
  }
1401
1277
  function expandHome(p) {
1402
- return p.startsWith("~/") ? path5.join(os2.homedir(), p.slice(2)) : p;
1278
+ return p.startsWith("~/") ? path4.join(os2.homedir(), p.slice(2)) : p;
1403
1279
  }
1404
1280
  function loadConfig() {
1405
1281
  const file2 = configPath();
1406
- const raw = fs7.existsSync(file2) ? parse(fs7.readFileSync(file2, "utf8")) : {};
1282
+ const raw = fs5.existsSync(file2) ? parse(fs5.readFileSync(file2, "utf8")) : {};
1407
1283
  const petOpen = raw.pet?.open ?? "tab";
1408
1284
  if (!["tab", "app", "helm"].includes(petOpen))
1409
1285
  throw new Error(`[pet].open must be "tab", "app", or "helm" in ${configPath()}`);
@@ -1424,10 +1300,14 @@ function loadConfig() {
1424
1300
  const reposRaw = raw.repos ?? {};
1425
1301
  const repos = {};
1426
1302
  for (const [key, r] of Object.entries(reposRaw)) {
1303
+ if (r.traps !== void 0 && (typeof r.traps !== "number" || !Number.isSafeInteger(r.traps) || r.traps < 0)) {
1304
+ throw new Error(`[repos.${key}].traps must be a non-negative whole number`);
1305
+ }
1427
1306
  if (r.review !== void 0 && !validReviewTool(r.review))
1428
1307
  throw new Error(`[repos.${key}].review must be github, graphite, linear, linear-app, or an HTTPS template with {owner}, {repo}, {number}`);
1429
1308
  repos[key] = {
1430
1309
  path: expandHome(String(r.path ?? "")),
1310
+ ...r.traps !== void 0 ? { traps: r.traps } : {},
1431
1311
  ...r.review !== void 0 ? { review: r.review } : {},
1432
1312
  origin: r.origin ? String(r.origin) : void 0,
1433
1313
  trunk: String(r.trunk ?? "main"),
@@ -1445,9 +1325,17 @@ function loadConfig() {
1445
1325
  };
1446
1326
  }
1447
1327
  const groundsRaw = raw.grounds ?? {};
1328
+ const wharves = {};
1329
+ for (const [name, value] of Object.entries(raw.wharves ?? {})) {
1330
+ if (!/^[A-Za-z0-9_-]{1,64}$/.test(name))
1331
+ throw new Error("invalid wharf name");
1332
+ wharves[name] = parseBackendLocation({ ...value, kind: "wharf" });
1333
+ }
1448
1334
  const grounds = {};
1449
1335
  for (const [key, g] of Object.entries(groundsRaw)) {
1450
- grounds[key] = { repos: Array.isArray(g.repos) ? g.repos.map(String) : [] };
1336
+ if (g.wharf !== void 0 && (typeof g.wharf !== "string" || !wharves[g.wharf]))
1337
+ throw new Error(`grounds ${key}: unknown wharf`);
1338
+ grounds[key] = { repos: Array.isArray(g.repos) ? g.repos.map(String) : [], ...g.wharf ? { wharf: String(g.wharf) } : {} };
1451
1339
  }
1452
1340
  return {
1453
1341
  repos,
@@ -1459,6 +1347,7 @@ function loadConfig() {
1459
1347
  pet: { open: petOpen },
1460
1348
  watch,
1461
1349
  grounds,
1350
+ wharves,
1462
1351
  pools: parsePools(raw.pools, repos),
1463
1352
  notifyCommand: raw.notifyCommand ? String(raw.notifyCommand) : void 0,
1464
1353
  notifyVerbs: Array.isArray(raw.notifyVerbs) ? raw.notifyVerbs.map(String) : void 0,
@@ -1508,25 +1397,25 @@ function firstMeaningfulLine(...outputs) {
1508
1397
  }
1509
1398
 
1510
1399
  // packages/core/dist/pr-poll.js
1511
- import * as fs11 from "node:fs";
1512
- import * as path9 from "node:path";
1400
+ import * as fs9 from "node:fs";
1401
+ import * as path8 from "node:path";
1513
1402
 
1514
1403
  // packages/core/dist/prs.js
1515
- import * as fs8 from "node:fs";
1516
- import * as path6 from "node:path";
1404
+ import * as fs6 from "node:fs";
1405
+ import * as path5 from "node:path";
1517
1406
  function prsDir() {
1518
- return path6.join(lobstahHome(), "prs");
1407
+ return path5.join(lobstahHome(), "prs");
1519
1408
  }
1520
1409
  function prRecordFile(key) {
1521
1410
  const ref = parsePrRef(key);
1522
1411
  if (!ref)
1523
1412
  throw new Error(`not a PR key: ${key}`);
1524
1413
  const safe = (s) => s.replace(/[^A-Za-z0-9._-]/g, "_");
1525
- return path6.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
1414
+ return path5.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
1526
1415
  }
1527
1416
  function readPr(key) {
1528
1417
  try {
1529
- return JSON.parse(fs8.readFileSync(prRecordFile(key), "utf8"));
1418
+ return JSON.parse(fs6.readFileSync(prRecordFile(key), "utf8"));
1530
1419
  } catch {
1531
1420
  return void 0;
1532
1421
  }
@@ -1534,13 +1423,13 @@ function readPr(key) {
1534
1423
  function readPrs() {
1535
1424
  let files;
1536
1425
  try {
1537
- files = fs8.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
1426
+ files = fs6.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
1538
1427
  } catch {
1539
1428
  return [];
1540
1429
  }
1541
1430
  return files.flatMap((f) => {
1542
1431
  try {
1543
- const r = JSON.parse(fs8.readFileSync(path6.join(prsDir(), f), "utf8"));
1432
+ const r = JSON.parse(fs6.readFileSync(path5.join(prsDir(), f), "utf8"));
1544
1433
  return typeof r.key === "string" && typeof r.url === "string" ? [r] : [];
1545
1434
  } catch {
1546
1435
  return [];
@@ -1549,16 +1438,16 @@ function readPrs() {
1549
1438
  }
1550
1439
 
1551
1440
  // packages/core/dist/watch.js
1552
- import fs10 from "node:fs";
1553
- import * as path8 from "node:path";
1441
+ import fs8 from "node:fs";
1442
+ import * as path7 from "node:path";
1554
1443
 
1555
1444
  // packages/core/dist/github-budget.js
1556
- import * as fs9 from "node:fs";
1557
- import * as path7 from "node:path";
1558
- var file = () => path7.join(lobstahHome(), "github-budget.json");
1445
+ import * as fs7 from "node:fs";
1446
+ import * as path6 from "node:path";
1447
+ var file = () => path6.join(lobstahHome(), "github-budget.json");
1559
1448
  function read() {
1560
1449
  try {
1561
- return JSON.parse(fs9.readFileSync(file(), "utf8"));
1450
+ return JSON.parse(fs7.readFileSync(file(), "utf8"));
1562
1451
  } catch {
1563
1452
  return { resources: {} };
1564
1453
  }
@@ -1572,27 +1461,27 @@ function githubBlockedUntil(now2 = Date.now()) {
1572
1461
 
1573
1462
  // packages/core/dist/watch.js
1574
1463
  function watchesDir() {
1575
- return path8.join(lobstahHome(), "watches");
1464
+ return path7.join(lobstahHome(), "watches");
1576
1465
  }
1577
1466
  function slug(key) {
1578
1467
  return key.replace(/[^A-Za-z0-9._-]+/g, "-");
1579
1468
  }
1580
1469
  function watchPath(key) {
1581
- return path8.join(watchesDir(), `${slug(key)}.json`);
1470
+ return path7.join(watchesDir(), `${slug(key)}.json`);
1582
1471
  }
1583
1472
  function readWatch(key) {
1584
1473
  try {
1585
- return JSON.parse(fs10.readFileSync(watchPath(key), "utf8"));
1474
+ return JSON.parse(fs8.readFileSync(watchPath(key), "utf8"));
1586
1475
  } catch {
1587
1476
  return void 0;
1588
1477
  }
1589
1478
  }
1590
1479
 
1591
1480
  // packages/core/dist/pr-poll.js
1592
- var cycleFile = (repo) => path9.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
1481
+ var cycleFile = (repo) => path8.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
1593
1482
  var readCycle = (repo) => {
1594
1483
  try {
1595
- return JSON.parse(fs11.readFileSync(cycleFile(repo), "utf8"));
1484
+ return JSON.parse(fs9.readFileSync(cycleFile(repo), "utf8"));
1596
1485
  } catch {
1597
1486
  return void 0;
1598
1487
  }
@@ -1685,23 +1574,23 @@ function parseUnresolvedThreads(stdout) {
1685
1574
  }
1686
1575
 
1687
1576
  // packages/core/dist/worktrees.js
1688
- import * as fs12 from "node:fs";
1689
- import * as path10 from "node:path";
1577
+ import * as fs10 from "node:fs";
1578
+ import * as path9 from "node:path";
1690
1579
  var LANES = ["work", "chore"];
1691
1580
  function worktreePath(id) {
1692
- return path10.join(lobstahHome(), "worktrees", id);
1581
+ return path9.join(lobstahHome(), "worktrees", id);
1693
1582
  }
1694
1583
  function readRecord(file2) {
1695
1584
  try {
1696
- const r = JSON.parse(fs12.readFileSync(file2, "utf8"));
1585
+ const r = JSON.parse(fs10.readFileSync(file2, "utf8"));
1697
1586
  return typeof r.path === "string" ? r : void 0;
1698
1587
  } catch {
1699
1588
  return void 0;
1700
1589
  }
1701
1590
  }
1702
1591
  function ownerOfPath(p) {
1703
- const rel = path10.relative(path10.join(lobstahHome(), "worktrees"), p);
1704
- if (!rel || rel.startsWith("..") || path10.isAbsolute(rel))
1592
+ const rel = path9.relative(path9.join(lobstahHome(), "worktrees"), p);
1593
+ if (!rel || rel.startsWith("..") || path9.isAbsolute(rel))
1705
1594
  return void 0;
1706
1595
  return rel.split(/[\\/]/)[0];
1707
1596
  }
@@ -1714,7 +1603,7 @@ function dispatchWorktree(id, lane) {
1714
1603
  }
1715
1604
  const dirs = laneDirs(l);
1716
1605
  for (const dir of [dirs.active, dirs.done]) {
1717
- const rec = readRecord(path10.join(dir, id, "worktree.json"));
1606
+ const rec = readRecord(path9.join(dir, id, "worktree.json"));
1718
1607
  if (rec) {
1719
1608
  const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
1720
1609
  return { path: rec.path, owner, reused: owner !== id };
@@ -1726,7 +1615,7 @@ function dispatchWorktree(id, lane) {
1726
1615
  function laneOf(id) {
1727
1616
  for (const l of LANES) {
1728
1617
  const d = laneDirs(l);
1729
- if (fs12.existsSync(path10.join(d.queue, `${id}.json`)) || fs12.existsSync(path10.join(d.active, id)) || fs12.existsSync(path10.join(d.done, id))) {
1618
+ if (fs10.existsSync(path9.join(d.queue, `${id}.json`)) || fs10.existsSync(path9.join(d.active, id)) || fs10.existsSync(path9.join(d.done, id))) {
1730
1619
  return l;
1731
1620
  }
1732
1621
  }
@@ -1746,7 +1635,7 @@ function followUpAncestors(id, lane) {
1746
1635
  function chainWorktree(followUp) {
1747
1636
  for (const id of [followUp, ...followUpAncestors(followUp)]) {
1748
1637
  const wt = dispatchWorktree(id, laneOf(id));
1749
- if (fs12.existsSync(wt.path))
1638
+ if (fs10.existsSync(wt.path))
1750
1639
  return { ...wt, from: id };
1751
1640
  }
1752
1641
  return void 0;
@@ -1761,27 +1650,27 @@ function processAlive(pid) {
1761
1650
  }
1762
1651
  }
1763
1652
  function worktreeGitDir(wt) {
1764
- const dotGit = path10.join(wt, ".git");
1653
+ const dotGit = path9.join(wt, ".git");
1765
1654
  try {
1766
- const st = fs12.statSync(dotGit);
1655
+ const st = fs10.statSync(dotGit);
1767
1656
  if (st.isDirectory())
1768
1657
  return dotGit;
1769
- const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs12.readFileSync(dotGit, "utf8"));
1770
- return m ? path10.resolve(wt, m[1]) : void 0;
1658
+ const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs10.readFileSync(dotGit, "utf8"));
1659
+ return m ? path9.resolve(wt, m[1]) : void 0;
1771
1660
  } catch {
1772
1661
  return void 0;
1773
1662
  }
1774
1663
  }
1775
1664
  function worktreeLockFile(wt) {
1776
1665
  const gitDir = worktreeGitDir(wt);
1777
- return gitDir ? path10.join(gitDir, "lobstah.lock") : void 0;
1666
+ return gitDir ? path9.join(gitDir, "lobstah.lock") : void 0;
1778
1667
  }
1779
1668
  function readWorktreeLock(wt) {
1780
1669
  const file2 = worktreeLockFile(wt);
1781
1670
  if (!file2)
1782
1671
  return void 0;
1783
1672
  try {
1784
- return JSON.parse(fs12.readFileSync(file2, "utf8"));
1673
+ return JSON.parse(fs10.readFileSync(file2, "utf8"));
1785
1674
  } catch {
1786
1675
  return void 0;
1787
1676
  }
@@ -1789,7 +1678,7 @@ function readWorktreeLock(wt) {
1789
1678
  function lockIsLive(lock) {
1790
1679
  if (lock.kind === "warm")
1791
1680
  return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
1792
- return fs12.existsSync(path10.join(laneDirs(lock.lane).active, lock.id));
1681
+ return fs10.existsSync(path9.join(laneDirs(lock.lane).active, lock.id));
1793
1682
  }
1794
1683
  function worktreeHolder(wt) {
1795
1684
  const lock = readWorktreeLock(wt);
@@ -1802,7 +1691,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1802
1691
  return { id: "(no git dir)", lane, pid: 0, at: mine.at };
1803
1692
  for (let attempt = 0; attempt < 3; attempt++) {
1804
1693
  try {
1805
- fs12.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
1694
+ fs10.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
1806
1695
  return void 0;
1807
1696
  } catch (err) {
1808
1697
  if (err.code !== "EEXIST")
@@ -1810,7 +1699,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1810
1699
  }
1811
1700
  let raw;
1812
1701
  try {
1813
- raw = fs12.readFileSync(file2, "utf8");
1702
+ raw = fs10.readFileSync(file2, "utf8");
1814
1703
  } catch {
1815
1704
  continue;
1816
1705
  }
@@ -1821,14 +1710,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1821
1710
  held2 = void 0;
1822
1711
  }
1823
1712
  if (held2?.id === id) {
1824
- fs12.writeFileSync(file2, JSON.stringify(mine, null, 2));
1713
+ fs10.writeFileSync(file2, JSON.stringify(mine, null, 2));
1825
1714
  return void 0;
1826
1715
  }
1827
1716
  if (held2 && lockIsLive(held2))
1828
1717
  return held2;
1829
1718
  try {
1830
- if (fs12.readFileSync(file2, "utf8") === raw)
1831
- fs12.rmSync(file2, { force: true });
1719
+ if (fs10.readFileSync(file2, "utf8") === raw)
1720
+ fs10.rmSync(file2, { force: true });
1832
1721
  } catch {
1833
1722
  }
1834
1723
  }
@@ -1840,22 +1729,22 @@ function releaseWorktreeLock(wt, id) {
1840
1729
  if (!file2)
1841
1730
  return;
1842
1731
  if (readWorktreeLock(wt)?.id === id)
1843
- fs12.rmSync(file2, { force: true });
1732
+ fs10.rmSync(file2, { force: true });
1844
1733
  }
1845
1734
 
1846
1735
  // packages/core/dist/events.js
1847
- import * as fs13 from "node:fs";
1736
+ import * as fs11 from "node:fs";
1848
1737
  function appendEvent(id, lane, ev) {
1849
- fs13.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
1738
+ fs11.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
1850
1739
  `);
1851
1740
  }
1852
1741
  function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
1853
1742
  const file2 = eventsPath(id, lane);
1854
1743
  try {
1855
- fs13.utimesSync(file2, at, at);
1744
+ fs11.utimesSync(file2, at, at);
1856
1745
  } catch {
1857
- fs13.appendFileSync(file2, "");
1858
- fs13.utimesSync(file2, at, at);
1746
+ fs11.appendFileSync(file2, "");
1747
+ fs11.utimesSync(file2, at, at);
1859
1748
  }
1860
1749
  }
1861
1750
 
@@ -1869,31 +1758,31 @@ function isFinished(id, lane) {
1869
1758
  }
1870
1759
 
1871
1760
  // packages/core/dist/pools.js
1872
- import * as fs14 from "node:fs";
1873
- import * as path11 from "node:path";
1761
+ import * as fs12 from "node:fs";
1762
+ import * as path10 from "node:path";
1874
1763
  function poolsRoot() {
1875
- return path11.join(lobstahHome(), "pools");
1764
+ return path10.join(lobstahHome(), "pools");
1876
1765
  }
1877
1766
  function poolDir(pool) {
1878
- return path11.join(poolsRoot(), pool);
1767
+ return path10.join(poolsRoot(), pool);
1879
1768
  }
1880
1769
  function poolSlotPath(pool, slot) {
1881
- return path11.join(poolDir(pool), String(slot));
1770
+ return path10.join(poolDir(pool), String(slot));
1882
1771
  }
1883
1772
  function slotsDir(pool) {
1884
- return path11.join(poolDir(pool), ".slots");
1773
+ return path10.join(poolDir(pool), ".slots");
1885
1774
  }
1886
1775
  function poolSlotOf(p) {
1887
1776
  const real = (x) => {
1888
1777
  try {
1889
- return fs14.realpathSync.native(x);
1778
+ return fs12.realpathSync.native(x);
1890
1779
  } catch {
1891
- return path11.resolve(x);
1780
+ return path10.resolve(x);
1892
1781
  }
1893
1782
  };
1894
- for (const [rootDir, dir] of [[poolsRoot(), path11.resolve(p)], [real(poolsRoot()), real(p)]]) {
1895
- const rel = path11.relative(rootDir, dir);
1896
- if (!rel || rel.startsWith("..") || path11.isAbsolute(rel))
1783
+ for (const [rootDir, dir] of [[poolsRoot(), path10.resolve(p)], [real(poolsRoot()), real(p)]]) {
1784
+ const rel = path10.relative(rootDir, dir);
1785
+ if (!rel || rel.startsWith("..") || path10.isAbsolute(rel))
1897
1786
  continue;
1898
1787
  const parts = rel.split(/[\\/]/);
1899
1788
  if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
@@ -1907,20 +1796,20 @@ function poolSlotLabel(pool, slot) {
1907
1796
  }
1908
1797
  function readJson(file2) {
1909
1798
  try {
1910
- return JSON.parse(fs14.readFileSync(file2, "utf8"));
1799
+ return JSON.parse(fs12.readFileSync(file2, "utf8"));
1911
1800
  } catch {
1912
1801
  return void 0;
1913
1802
  }
1914
1803
  }
1915
1804
  function writeJson(file2, value) {
1916
- fs14.mkdirSync(path11.dirname(file2), { recursive: true });
1805
+ fs12.mkdirSync(path10.dirname(file2), { recursive: true });
1917
1806
  const tmp = uniqueTempPath(file2);
1918
- fs14.writeFileSync(tmp, JSON.stringify(value, null, 2));
1807
+ fs12.writeFileSync(tmp, JSON.stringify(value, null, 2));
1919
1808
  atomicRenameSync(tmp, file2);
1920
1809
  }
1921
- var metaFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.json`);
1922
- var claimFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.claim.json`);
1923
- var outFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.out.json`);
1810
+ var metaFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.json`);
1811
+ var claimFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.claim.json`);
1812
+ var outFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.out.json`);
1924
1813
  function readSlotMeta(pool, slot) {
1925
1814
  return readJson(metaFile(pool, slot)) ?? {};
1926
1815
  }
@@ -1940,7 +1829,7 @@ function writeSlotOut(pool, slot, out) {
1940
1829
  writeJson(outFile(pool, slot), out);
1941
1830
  }
1942
1831
  function clearSlotOut(pool, slot) {
1943
- fs14.rmSync(outFile(pool, slot), { force: true });
1832
+ fs12.rmSync(outFile(pool, slot), { force: true });
1944
1833
  }
1945
1834
  function dispatchHolder(dir) {
1946
1835
  const lock = readWorktreeLock(dir);
@@ -1950,7 +1839,7 @@ function poolSlotView(pool, slot) {
1950
1839
  const dir = poolSlotPath(pool, slot);
1951
1840
  const lastClaim = readSlotClaim(pool, slot)?.id;
1952
1841
  const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
1953
- if (!fs14.existsSync(dir)) {
1842
+ if (!fs12.existsSync(dir)) {
1954
1843
  const meta2 = readSlotMeta(pool, slot);
1955
1844
  return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
1956
1845
  }
@@ -1965,8 +1854,8 @@ function poolSlotView(pool, slot) {
1965
1854
  return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
1966
1855
  return { ...base, state: "free" };
1967
1856
  }
1968
- var warmStateFile = (pool) => path11.join(poolDir(pool), ".warm-state.json");
1969
- var warmLockFile = (pool) => path11.join(poolDir(pool), ".warm.lock");
1857
+ var warmStateFile = (pool) => path10.join(poolDir(pool), ".warm-state.json");
1858
+ var warmLockFile = (pool) => path10.join(poolDir(pool), ".warm.lock");
1970
1859
  var POOL_WARM_MAX_MS = 60 * 6e4;
1971
1860
  function readPoolWarmState(pool) {
1972
1861
  return readJson(warmStateFile(pool)) ?? {};
@@ -1988,15 +1877,15 @@ function poolWarmRunning(pool, now2 = Date.now()) {
1988
1877
  }
1989
1878
  function takePoolWarmLock(pool) {
1990
1879
  const file2 = warmLockFile(pool);
1991
- fs14.mkdirSync(path11.dirname(file2), { recursive: true });
1880
+ fs12.mkdirSync(path10.dirname(file2), { recursive: true });
1992
1881
  const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
1993
1882
  for (let attempt = 0; attempt < 2; attempt++) {
1994
1883
  try {
1995
- fs14.writeFileSync(file2, mine, { flag: "wx" });
1884
+ fs12.writeFileSync(file2, mine, { flag: "wx" });
1996
1885
  return () => {
1997
1886
  try {
1998
- if (fs14.readFileSync(file2, "utf8") === mine)
1999
- fs14.rmSync(file2, { force: true });
1887
+ if (fs12.readFileSync(file2, "utf8") === mine)
1888
+ fs12.rmSync(file2, { force: true });
2000
1889
  } catch {
2001
1890
  }
2002
1891
  };
@@ -2006,7 +1895,7 @@ function takePoolWarmLock(pool) {
2006
1895
  }
2007
1896
  if (poolWarmRunning(pool))
2008
1897
  return void 0;
2009
- fs14.rmSync(file2, { force: true });
1898
+ fs12.rmSync(file2, { force: true });
2010
1899
  }
2011
1900
  return void 0;
2012
1901
  }
@@ -2015,26 +1904,191 @@ var POOL_FETCH_MS = 10 * 6e4;
2015
1904
  var POOL_RECHECK_MS = 5 * 6e4;
2016
1905
 
2017
1906
  // packages/core/dist/disk.js
2018
- import * as fs15 from "node:fs";
1907
+ import * as fs13 from "node:fs";
2019
1908
  var GB = 1024 ** 3;
2020
1909
  var statfsFreeBytes = (dir) => {
2021
- const s = fs15.statfsSync(dir);
1910
+ const s = fs13.statfsSync(dir);
2022
1911
  return Number(s.bavail) * Number(s.bsize);
2023
1912
  };
2024
1913
  function formatGB(bytes) {
2025
1914
  return `${(bytes / GB).toFixed(1).replace(/\.0$/, "")} GB`;
2026
1915
  }
2027
1916
 
1917
+ // packages/core/dist/inbox.js
1918
+ import * as fs14 from "node:fs";
1919
+ import * as path11 from "node:path";
1920
+ var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
1921
+ function inboxDir(id, lane) {
1922
+ return path11.join(laneDirs(lane).inbox, id);
1923
+ }
1924
+ function unhandled(id, lane) {
1925
+ const dir = inboxDir(id, lane);
1926
+ return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs14.readFileSync(path11.join(dir, f), "utf8") }));
1927
+ }
1928
+ function acknowledge(id, lane, file2) {
1929
+ const dir = inboxDir(id, lane);
1930
+ fs14.mkdirSync(path11.join(dir, "handled"), { recursive: true });
1931
+ fs14.renameSync(path11.join(dir, file2), path11.join(dir, "handled", file2));
1932
+ try {
1933
+ fs14.renameSync(path11.join(dir, metaName(file2)), path11.join(dir, "handled", metaName(file2)));
1934
+ } catch {
1935
+ }
1936
+ }
1937
+
1938
+ // packages/core/dist/resume.js
1939
+ import * as fs15 from "node:fs";
1940
+ import * as os3 from "node:os";
1941
+ import * as path12 from "node:path";
1942
+ import { spawnSync as spawnSync2 } from "node:child_process";
1943
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-([0-9a-f])[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1944
+ function harnessFromSessionId(sessionId) {
1945
+ const version = sessionId ? UUID.exec(sessionId)?.[1] : void 0;
1946
+ return version === "7" ? "codex" : version === "4" ? "claude" : void 0;
1947
+ }
1948
+ function claimOf(id, lane) {
1949
+ const dirs = laneDirs(lane);
1950
+ for (const dir of [dirs.active, dirs.done]) {
1951
+ try {
1952
+ return JSON.parse(fs15.readFileSync(path12.join(dir, id, "claim.json"), "utf8"));
1953
+ } catch {
1954
+ }
1955
+ }
1956
+ return void 0;
1957
+ }
1958
+ function laneOf2(id) {
1959
+ for (const lane of ["work", "chore"]) {
1960
+ if (storedDescriptor(id, lane) || readEvidence(id, lane).sessionId)
1961
+ return lane;
1962
+ }
1963
+ return void 0;
1964
+ }
1965
+ function resolveSessionHarness(id, cfg, laneHint) {
1966
+ const lane = laneHint ?? laneOf2(id);
1967
+ if (!lane)
1968
+ return {};
1969
+ const ev = readEvidence(id, lane);
1970
+ const sessionId = ev.sessionId;
1971
+ const out = (harness, source) => ({
1972
+ sessionId,
1973
+ harness,
1974
+ source,
1975
+ lane
1976
+ });
1977
+ if (ev.harness)
1978
+ return out(ev.harness, "evidence");
1979
+ const claim = claimOf(id, lane);
1980
+ if (claim?.harness)
1981
+ return out(claim.harness, "trap");
1982
+ if (ev.deliveredTo?.startsWith("wt:")) {
1983
+ const reg = readTrap(ev.deliveredTo.slice("wt:".length));
1984
+ if (reg?.harness)
1985
+ return out(reg.harness, "trap");
1986
+ }
1987
+ const byId = harnessFromSessionId(sessionId);
1988
+ if (byId)
1989
+ return out(byId, "session-id");
1990
+ const d = storedDescriptor(id, lane);
1991
+ const repo = d && cfg?.repos[d.repo];
1992
+ const fromDescriptor = d?.harness ?? repo?.harness?.default ?? cfg?.harness.default;
1993
+ if (fromDescriptor)
1994
+ return out(fromDescriptor, "descriptor");
1995
+ return { sessionId, lane };
1996
+ }
1997
+ var UNRESUMABLE = /no conversation found|no rollout found|thread\/resume failed|(session|thread|conversation)( id)?[^.\n]{0,80}\b(not found|does not exist|unknown|invalid)|(could not|cannot|failed to|unable to) (find|load|resume)[^.\n]{0,40}\b(session|thread|conversation)/i;
1998
+ function isUnresumable(error) {
1999
+ return error !== void 0 && UNRESUMABLE.test(error);
2000
+ }
2001
+ function worktreeProgress(worktree, trunk) {
2002
+ if (!worktree || !fs15.existsSync(worktree))
2003
+ return "No worktree progress recorded.";
2004
+ const git2 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
2005
+ const commits = trunk ? git2("log", "--oneline", `origin/${trunk}..HEAD`) : git2("log", "--oneline", "-15");
2006
+ const status = git2("status", "--short");
2007
+ return `Commits so far:
2008
+ ${commits || "(none)"}
2009
+
2010
+ Uncommitted changes:
2011
+ ${status || "(clean)"}`;
2012
+ }
2013
+ function originProgress(originId, lane) {
2014
+ const ev = readEvidence(originId, lane);
2015
+ const last = readStatusLog(originId, lane).at(-1);
2016
+ const lines = [`The earlier dispatch ${originId} left:`];
2017
+ if (ev.branch)
2018
+ lines.push(`- branch: ${ev.branch}`);
2019
+ if (ev.prUrl)
2020
+ lines.push(`- PR: ${ev.prUrl}`);
2021
+ if (last)
2022
+ lines.push(`- last status: ${last.verb}${last.note ? ` \u2014 ${last.note}` : ""}`);
2023
+ if (ev.commits?.length)
2024
+ lines.push("- commits:", ...ev.commits.map((c) => ` ${c}`));
2025
+ if (lines.length === 1)
2026
+ lines.push("- (no recorded branch, PR, or commits)");
2027
+ return lines.join("\n");
2028
+ }
2029
+ function handoffNote(fromHarness, progress, why) {
2030
+ return `You are taking over this dispatch from a previous agent session (harness: ${fromHarness}). Its conversation is not available${why ? ` (${why})` : ""} \u2014 the state below is the ground truth. Review it, then continue the brief from where it stops.
2031
+
2032
+ ${progress}`;
2033
+ }
2034
+ function codexHome(env = process.env) {
2035
+ return env.CODEX_HOME ?? path12.join(os3.homedir(), ".codex");
2036
+ }
2037
+ function codexRolloutFile(threadId, home = codexHome()) {
2038
+ const suffix = `-${threadId}.jsonl`;
2039
+ const walk = (dir, depth) => {
2040
+ let entries;
2041
+ try {
2042
+ entries = fs15.readdirSync(dir, { withFileTypes: true });
2043
+ } catch {
2044
+ return void 0;
2045
+ }
2046
+ for (const e of entries) {
2047
+ if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
2048
+ return path12.join(dir, e.name);
2049
+ }
2050
+ if (depth === 0)
2051
+ return void 0;
2052
+ for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
2053
+ const hit = walk(path12.join(dir, e.name), depth - 1);
2054
+ if (hit)
2055
+ return hit;
2056
+ }
2057
+ return void 0;
2058
+ };
2059
+ return walk(path12.join(home, "sessions"), 3) ?? walk(path12.join(home, "archived_sessions"), 0);
2060
+ }
2061
+ function codexDesktopThread(threadId, home = codexHome()) {
2062
+ const file2 = codexRolloutFile(threadId, home);
2063
+ if (!file2)
2064
+ return void 0;
2065
+ let head = "";
2066
+ try {
2067
+ const fd = fs15.openSync(file2, "r");
2068
+ try {
2069
+ const buf = Buffer.alloc(4096);
2070
+ head = buf.subarray(0, fs15.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
2071
+ } finally {
2072
+ fs15.closeSync(fd);
2073
+ }
2074
+ } catch {
2075
+ return void 0;
2076
+ }
2077
+ const originator = /"originator"\s*:\s*"([^"]*)"/.exec(head)?.[1];
2078
+ return originator && /desktop/i.test(originator) ? originator : void 0;
2079
+ }
2080
+ var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
2081
+
2028
2082
  // packages/core/dist/notices.js
2029
2083
  function noticesDir() {
2030
- return path12.join(lobstahHome(), "notices");
2084
+ return path13.join(lobstahHome(), "notices");
2031
2085
  }
2032
2086
  var counter = 0;
2033
2087
  function postNotice(n) {
2034
2088
  const dir = noticesDir();
2035
2089
  fs16.mkdirSync(dir, { recursive: true });
2036
2090
  if (n.dedupeKey) {
2037
- const marker = path12.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
2091
+ const marker = path13.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
2038
2092
  try {
2039
2093
  fs16.writeFileSync(marker, "", { flag: "wx" });
2040
2094
  } catch {
@@ -2054,7 +2108,7 @@ function postNotice(n) {
2054
2108
  ...n.quiet ? { quiet: true } : {},
2055
2109
  ...n.stateHash ? { stateHash: n.stateHash } : {}
2056
2110
  };
2057
- const file2 = path12.join(dir, `${seq}.json`);
2111
+ const file2 = path13.join(dir, `${seq}.json`);
2058
2112
  const tmp = uniqueTempPath(file2);
2059
2113
  fs16.writeFileSync(tmp, JSON.stringify(notice, null, 2));
2060
2114
  atomicRenameSync(tmp, file2);
@@ -2072,39 +2126,83 @@ function attachmentBlock(attachments) {
2072
2126
  ].join("\n");
2073
2127
  }
2074
2128
 
2129
+ // packages/core/dist/helm.js
2130
+ import * as fs17 from "node:fs";
2131
+ import * as path14 from "node:path";
2132
+ function helmDir() {
2133
+ return path14.join(lobstahHome(), "helm");
2134
+ }
2135
+ function listHelms() {
2136
+ try {
2137
+ return fs17.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs17.readFileSync(path14.join(helmDir(), f), "utf8")));
2138
+ } catch {
2139
+ return [];
2140
+ }
2141
+ }
2142
+ function liveHelms(ttlMs, now2 = Date.now()) {
2143
+ return listHelms().filter((h) => now2 - (Date.parse(h.heartbeatAt) || 0) <= ttlMs);
2144
+ }
2145
+
2075
2146
  // packages/core/dist/soak.js
2076
2147
  function regPath(trapId) {
2077
- return path13.join(soakingDir(), `${trapId}.json`);
2148
+ return path15.join(soakingDir(), `${trapId}.json`);
2078
2149
  }
2079
2150
  function readTrap(trapId) {
2080
2151
  try {
2081
- return JSON.parse(fs17.readFileSync(regPath(trapId), "utf8"));
2152
+ return JSON.parse(fs18.readFileSync(regPath(trapId), "utf8"));
2082
2153
  } catch {
2083
2154
  return void 0;
2084
2155
  }
2085
2156
  }
2086
2157
  function listTraps() {
2087
2158
  try {
2088
- return fs17.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs17.readFileSync(path13.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
2159
+ return fs18.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs18.readFileSync(path15.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
2089
2160
  } catch {
2090
2161
  return [];
2091
2162
  }
2092
2163
  }
2093
2164
  function claimPath(id, lane) {
2094
- return path13.join(laneDirs(lane).active, id, "claim.json");
2165
+ return path15.join(laneDirs(lane).active, id, "claim.json");
2095
2166
  }
2096
2167
  function readSessionClaim(id, lane) {
2097
2168
  try {
2098
- return JSON.parse(fs17.readFileSync(claimPath(id, lane), "utf8"));
2169
+ return JSON.parse(fs18.readFileSync(claimPath(id, lane), "utf8"));
2099
2170
  } catch {
2100
2171
  return void 0;
2101
2172
  }
2102
2173
  }
2103
2174
 
2175
+ // packages/core/dist/catch-context.js
2176
+ import * as fs19 from "node:fs";
2177
+ import * as path16 from "node:path";
2178
+ function readCatchContext(dir, id) {
2179
+ try {
2180
+ return JSON.parse(fs19.readFileSync(path16.join(dir, `${id}.catch-context`), "utf8"));
2181
+ } catch {
2182
+ return {};
2183
+ }
2184
+ }
2185
+ function observeLocalCatch(id, lane, phase, now2 = Date.now()) {
2186
+ const dir = laneDirs(lane).state, old = readCatchContext(dir, id), cfg = loadConfig();
2187
+ if (phase === "finish" && Object.hasOwn(old, "helm"))
2188
+ return;
2189
+ const repo = storedDescriptor(id, lane)?.repo;
2190
+ const helms = liveHelms(cfg.helm.ttlSecs * 1e3, now2);
2191
+ const present = repo ? helms.some((h) => h.repos.includes(repo)) : null;
2192
+ const next = phase === "claim" ? { claimHelm: present, location: "local" } : { ...old, location: "local", helm: old.claimHelm === true || present === true ? true : old.claimHelm === false && present === false ? false : null };
2193
+ const file2 = path16.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
2194
+ try {
2195
+ fs19.writeFileSync(tmp, JSON.stringify(next));
2196
+ fs19.renameSync(tmp, file2);
2197
+ } finally {
2198
+ fs19.rmSync(tmp, { force: true });
2199
+ }
2200
+ }
2201
+
2104
2202
  // packages/core/dist/stats.js
2105
2203
  var DAILY_RETENTION_DAYS = 400;
2106
2204
  function statsPath() {
2107
- return path14.join(lobstahHome(), "stats.json");
2205
+ return path17.join(lobstahHome(), "stats.json");
2108
2206
  }
2109
2207
  function shiftDay(day, days) {
2110
2208
  const [y, m, d] = day.split("-").map(Number);
@@ -2117,7 +2215,7 @@ function localDay(at = Date.now()) {
2117
2215
  function readCatchFacts(stateDir, id) {
2118
2216
  let last;
2119
2217
  try {
2120
- for (const line of fs18.readFileSync(path14.join(stateDir, `${id}.status`), "utf8").split("\n")) {
2218
+ for (const line of fs20.readFileSync(path17.join(stateDir, `${id}.status`), "utf8").split("\n")) {
2121
2219
  if (!line.trim())
2122
2220
  continue;
2123
2221
  try {
@@ -2133,7 +2231,7 @@ function readCatchFacts(stateDir, id) {
2133
2231
  let trap;
2134
2232
  let worker = workerProfile();
2135
2233
  try {
2136
- const evidence = JSON.parse(fs18.readFileSync(path14.join(stateDir, `${id}.evidence`), "utf8"));
2234
+ const evidence = JSON.parse(fs20.readFileSync(path17.join(stateDir, `${id}.evidence`), "utf8"));
2137
2235
  const to = evidence.deliveredTo;
2138
2236
  if (typeof to === "string" && to.startsWith("wt:"))
2139
2237
  trap = to;
@@ -2141,7 +2239,8 @@ function readCatchFacts(stateDir, id) {
2141
2239
  worker = sanitizeWorker(reg ?? evidence.worker ?? workerProfile({ harness: evidence.harness }));
2142
2240
  } catch {
2143
2241
  }
2144
- return { done: true, worker, ...typeof last.at === "string" ? { at: last.at } : {}, ...trap ? { trap } : {} };
2242
+ const context = readCatchContext(stateDir, id);
2243
+ return { done: true, worker, helm: context.helm, location: context.location, ...typeof last.at === "string" ? { at: last.at } : {}, ...trap ? { trap } : {} };
2145
2244
  }
2146
2245
  function emptyStore(now2) {
2147
2246
  return {
@@ -2189,6 +2288,15 @@ function add(store, facts, now2) {
2189
2288
  store.utc = { date: utcDay, catches: 0, perTrap: {}, trapWorkers: {}, byWorker: [] };
2190
2289
  if ((at ? new Date(at).toISOString().slice(0, 10) : utcDay) === utcDay) {
2191
2290
  store.utc.catches++;
2291
+ const usage = store.utc.usage ??= { withHelm: 0, withoutHelm: 0, onLocal: 0, onWharf: 0 };
2292
+ if (facts.helm === true)
2293
+ usage.withHelm++;
2294
+ if (facts.helm === false)
2295
+ usage.withoutHelm++;
2296
+ if (facts.location === "local")
2297
+ usage.onLocal++;
2298
+ if (facts.location === "wharf")
2299
+ usage.onWharf++;
2192
2300
  const worker = sanitizeWorker(facts.worker);
2193
2301
  if (facts.trap) {
2194
2302
  store.utc.perTrap[facts.trap] = (store.utc.perTrap[facts.trap] ?? 0) + 1;
@@ -2206,7 +2314,7 @@ function add(store, facts, now2) {
2206
2314
  }
2207
2315
  function backfillSources() {
2208
2316
  const live = ["work", "chore"].map((lane) => ({ dir: laneDirs(lane).state, live: true }));
2209
- const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path14.join(lobstahHome(), name), live: false })).filter((s) => fs18.statSync(s.dir).isDirectory());
2317
+ const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path17.join(lobstahHome(), name), live: false })).filter((s) => fs20.statSync(s.dir).isDirectory());
2210
2318
  return [...live, ...backups];
2211
2319
  }
2212
2320
  function backfillStats(now2 = Date.now(), alreadyCounted) {
@@ -2278,85 +2386,237 @@ function parseStore(text) {
2278
2386
  var complete2 = (s) => !!s && s.daily !== void 0;
2279
2387
  function writeStore(store) {
2280
2388
  const file2 = statsPath();
2281
- fs18.mkdirSync(path14.dirname(file2), { recursive: true });
2389
+ fs20.mkdirSync(path17.dirname(file2), { recursive: true });
2390
+ const tmp = uniqueTempPath(file2);
2391
+ fs20.writeFileSync(tmp, JSON.stringify(store));
2392
+ atomicRenameSync(tmp, file2);
2393
+ }
2394
+ function withStatsLock(action) {
2395
+ fs20.mkdirSync(lobstahHome(), { recursive: true });
2396
+ const lock = `${statsPath()}.lock`;
2397
+ const deadline = Date.now() + 1e4;
2398
+ for (; ; ) {
2399
+ try {
2400
+ fs20.mkdirSync(lock);
2401
+ break;
2402
+ } catch (err) {
2403
+ if (err.code !== "EEXIST")
2404
+ throw err;
2405
+ try {
2406
+ if (Date.now() - fs20.statSync(lock).mtimeMs > 12e4)
2407
+ fs20.rmdirSync(lock);
2408
+ } catch {
2409
+ }
2410
+ if (Date.now() >= deadline)
2411
+ throw new Error("stats store locked");
2412
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
2413
+ }
2414
+ }
2415
+ try {
2416
+ return action();
2417
+ } finally {
2418
+ fs20.rmdirSync(lock);
2419
+ }
2420
+ }
2421
+ function loadOrBackfill(now2) {
2422
+ let text;
2423
+ try {
2424
+ text = fs20.readFileSync(statsPath(), "utf8");
2425
+ } catch (err) {
2426
+ if (err.code !== "ENOENT")
2427
+ throw err;
2428
+ }
2429
+ const saved = text === void 0 ? void 0 : parseStore(text);
2430
+ if (complete2(saved) && saved.utc?.trapWorkers !== void 0 && saved.utc.byWorker !== void 0)
2431
+ return saved;
2432
+ if (saved) {
2433
+ const store2 = complete2(saved) ? saved : backfillDaily({ ...saved, daily: {} }, now2);
2434
+ if (!store2.utc) {
2435
+ store2.utc = backfillStats(now2, new Set(store2.counted)).utc;
2436
+ }
2437
+ if (store2.utc.trapWorkers === void 0 || store2.utc.byWorker === void 0) {
2438
+ const history = backfillStats(now2, new Set(store2.counted)).utc;
2439
+ if (history?.date === store2.utc.date) {
2440
+ store2.utc.trapWorkers ??= history.trapWorkers ?? {};
2441
+ store2.utc.byWorker ??= history.byWorker ?? [];
2442
+ } else {
2443
+ store2.utc.trapWorkers ??= {};
2444
+ store2.utc.byWorker ??= [];
2445
+ }
2446
+ }
2447
+ writeStore(store2);
2448
+ return store2;
2449
+ }
2450
+ if (text !== void 0)
2451
+ fs20.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2452
+ const store = backfillStats(now2);
2453
+ writeStore(store);
2454
+ return store;
2455
+ }
2456
+ function recordCatch(id, lane, now2 = Date.now()) {
2457
+ withStatsLock(() => {
2458
+ const store = loadOrBackfill(now2);
2459
+ if (store.counted.includes(id))
2460
+ return;
2461
+ const facts = readCatchFacts(laneDirs(lane).state, id);
2462
+ if (!facts.done)
2463
+ return;
2464
+ add(store, facts, now2);
2465
+ store.counted.push(id);
2466
+ writeStore(store);
2467
+ });
2468
+ }
2469
+
2470
+ // packages/core/dist/status.js
2471
+ function isVerb(v) {
2472
+ return VERBS.includes(v);
2473
+ }
2474
+ function isWaitingOn(v) {
2475
+ return WAITING_ON.includes(v);
2476
+ }
2477
+ var DURATION = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/i;
2478
+ var UNIT_MS = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 };
2479
+ function parseUntil(v, now2 = Date.now()) {
2480
+ const d = DURATION.exec(v.trim());
2481
+ if (d)
2482
+ return new Date(now2 + Number(d[1]) * UNIT_MS[d[2].toLowerCase()]).toISOString();
2483
+ const t = Date.parse(v);
2484
+ if (Number.isNaN(t))
2485
+ throw new Error(`invalid --until "${v}" \u2014 an ISO time (2026-10-01T09:00Z) or a duration (30m, 4h, 2d)`);
2486
+ return new Date(t).toISOString();
2487
+ }
2488
+ function waitingFields(verb, w, now2 = Date.now()) {
2489
+ const out = {};
2490
+ if ((w.waitingOn !== void 0 || w.link !== void 0) && !WAITING_ON_VERBS.includes(verb)) {
2491
+ throw new Error(`--waiting-on and --link are valid only with ${WAITING_ON_VERBS.join(", ")} \u2014 not ${verb}`);
2492
+ }
2493
+ if (w.until !== void 0 && verb !== "paused")
2494
+ throw new Error(`--until is valid only with paused \u2014 not ${verb}`);
2495
+ if (w.waitingOn !== void 0) {
2496
+ if (!isWaitingOn(w.waitingOn)) {
2497
+ throw new Error(`invalid --waiting-on "${w.waitingOn}" \u2014 must be one of: ${WAITING_ON.join(", ")}`);
2498
+ }
2499
+ out.waitingOn = w.waitingOn;
2500
+ }
2501
+ if (w.link !== void 0) {
2502
+ let url;
2503
+ try {
2504
+ url = new URL(w.link);
2505
+ } catch {
2506
+ url = void 0;
2507
+ }
2508
+ if (!url || url.protocol !== "http:" && url.protocol !== "https:") {
2509
+ throw new Error(`invalid --link "${w.link}" \u2014 must be an http or https URL`);
2510
+ }
2511
+ out.link = url.href;
2512
+ }
2513
+ if (w.until !== void 0)
2514
+ out.until = parseUntil(w.until, now2);
2515
+ if (verb === "paused" && (out.waitingOn === "person" || out.waitingOn === "review" && out.link && !parsePrRef(out.link))) {
2516
+ throw new Error("Waiting on a human requires needs-decision: report needs-decision with the question or the thing to look at.");
2517
+ }
2518
+ return out;
2519
+ }
2520
+ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
2521
+ if (!isVerb(verb)) {
2522
+ throw new Error(`invalid status verb "${verb}" \u2014 must be one of: ${VERBS.join(", ")}`);
2523
+ }
2524
+ const extra = waiting ? waitingFields(verb, waiting) : {};
2525
+ const entry = {
2526
+ at: at ?? (/* @__PURE__ */ new Date()).toISOString(),
2527
+ verb,
2528
+ ...note ? { note } : {},
2529
+ ...extra,
2530
+ ...reported ? { reported: true } : {}
2531
+ };
2532
+ if (verb === "done") {
2533
+ try {
2534
+ observeLocalCatch(id, lane, "finish");
2535
+ } catch {
2536
+ }
2537
+ }
2538
+ fs21.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
2539
+ `);
2540
+ if (verb === "done") {
2541
+ try {
2542
+ recordCatch(id, lane);
2543
+ } catch {
2544
+ }
2545
+ }
2546
+ return entry;
2547
+ }
2548
+ function readStatusLog(id, lane) {
2549
+ const file2 = statusPath(id, lane);
2550
+ if (!fs21.existsSync(file2))
2551
+ return [];
2552
+ return fs21.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
2553
+ try {
2554
+ const parsed = JSON.parse(line);
2555
+ return isVerb(parsed.verb) ? [parsed] : [];
2556
+ } catch {
2557
+ return [];
2558
+ }
2559
+ });
2560
+ }
2561
+ function pausedWaiting(entry) {
2562
+ return entry?.verb === "paused" && entry.waitingOn !== void 0;
2563
+ }
2564
+
2565
+ // packages/core/dist/queue.js
2566
+ function requeue(id, lane) {
2567
+ const dirs = laneDirs(lane);
2568
+ const activeDir = path18.join(dirs.active, id);
2569
+ const file2 = path18.join(activeDir, "descriptor.json");
2570
+ const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
2282
2571
  const tmp = uniqueTempPath(file2);
2283
- fs18.writeFileSync(tmp, JSON.stringify(store));
2572
+ fs22.writeFileSync(tmp, JSON.stringify(d, null, 2));
2284
2573
  atomicRenameSync(tmp, file2);
2574
+ fs22.renameSync(file2, path18.join(dirs.queue, `${id}.json`));
2575
+ fs22.rmSync(activeDir, { recursive: true, force: true });
2285
2576
  }
2286
- function withStatsLock(action) {
2287
- fs18.mkdirSync(lobstahHome(), { recursive: true });
2288
- const lock = `${statsPath()}.lock`;
2289
- const deadline = Date.now() + 1e4;
2290
- for (; ; ) {
2577
+ function readDescriptor(id, lane) {
2578
+ const file2 = path18.join(laneDirs(lane).active, id, "descriptor.json");
2579
+ return JSON.parse(fs22.readFileSync(file2, "utf8"));
2580
+ }
2581
+ function storedDescriptor(id, lane) {
2582
+ const dirs = laneDirs(lane);
2583
+ for (const file2 of [
2584
+ path18.join(dirs.queue, `${id}.json`),
2585
+ path18.join(dirs.active, id, "descriptor.json"),
2586
+ path18.join(dirs.done, id, "descriptor.json")
2587
+ ]) {
2291
2588
  try {
2292
- fs18.mkdirSync(lock);
2293
- break;
2294
- } catch (err) {
2295
- if (err.code !== "EEXIST")
2296
- throw err;
2297
- try {
2298
- if (Date.now() - fs18.statSync(lock).mtimeMs > 12e4)
2299
- fs18.rmdirSync(lock);
2300
- } catch {
2301
- }
2302
- if (Date.now() >= deadline)
2303
- throw new Error("stats store locked");
2304
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
2589
+ return JSON.parse(fs22.readFileSync(file2, "utf8"));
2590
+ } catch {
2305
2591
  }
2306
2592
  }
2307
- try {
2308
- return action();
2309
- } finally {
2310
- fs18.rmdirSync(lock);
2311
- }
2593
+ return void 0;
2312
2594
  }
2313
- function loadOrBackfill(now2) {
2314
- let text;
2315
- try {
2316
- text = fs18.readFileSync(statsPath(), "utf8");
2317
- } catch (err) {
2318
- if (err.code !== "ENOENT")
2319
- throw err;
2320
- }
2321
- const saved = text === void 0 ? void 0 : parseStore(text);
2322
- if (complete2(saved) && saved.utc?.trapWorkers !== void 0 && saved.utc.byWorker !== void 0)
2323
- return saved;
2324
- if (saved) {
2325
- const store2 = complete2(saved) ? saved : backfillDaily({ ...saved, daily: {} }, now2);
2326
- if (!store2.utc) {
2327
- store2.utc = backfillStats(now2, new Set(store2.counted)).utc;
2328
- }
2329
- if (store2.utc.trapWorkers === void 0 || store2.utc.byWorker === void 0) {
2330
- const history = backfillStats(now2, new Set(store2.counted)).utc;
2331
- if (history?.date === store2.utc.date) {
2332
- store2.utc.trapWorkers ??= history.trapWorkers ?? {};
2333
- store2.utc.byWorker ??= history.byWorker ?? [];
2334
- } else {
2335
- store2.utc.trapWorkers ??= {};
2336
- store2.utc.byWorker ??= [];
2337
- }
2338
- }
2339
- writeStore(store2);
2340
- return store2;
2341
- }
2342
- if (text !== void 0)
2343
- fs18.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2344
- const store = backfillStats(now2);
2345
- writeStore(store);
2346
- return store;
2595
+ function activeIds(lane) {
2596
+ return readDirIfPresent(laneDirs(lane).active).filter((f) => !f.startsWith("."));
2347
2597
  }
2348
- function recordCatch(id, lane, now2 = Date.now()) {
2349
- withStatsLock(() => {
2350
- const store = loadOrBackfill(now2);
2351
- if (store.counted.includes(id))
2352
- return;
2353
- const facts = readCatchFacts(laneDirs(lane).state, id);
2354
- if (!facts.done)
2355
- return;
2356
- add(store, facts, now2);
2357
- store.counted.push(id);
2358
- writeStore(store);
2359
- });
2598
+ function complete(id, lane) {
2599
+ const dirs = laneDirs(lane);
2600
+ fs22.renameSync(path18.join(dirs.active, id), path18.join(dirs.done, id));
2601
+ }
2602
+ function cancelRequested(id, lane) {
2603
+ return fs22.existsSync(path18.join(laneDirs(lane).active, id, "cancel"));
2604
+ }
2605
+
2606
+ // packages/core/dist/backend.js
2607
+ function parseBackendLocation(raw) {
2608
+ if (raw === void 0)
2609
+ return void 0;
2610
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
2611
+ throw new Error("backend must be a wharf configuration");
2612
+ const b = raw;
2613
+ if (b.kind !== "wharf" || typeof b.url !== "string" || typeof b.account !== "string" || typeof b.tokenEnv !== "string" || !/^[a-zA-Z0-9_-]{1,64}$/.test(b.account) || !/^[A-Z][A-Z0-9_]{0,127}$/.test(b.tokenEnv))
2614
+ throw new Error("backend requires kind=wharf, url, account and tokenEnv");
2615
+ const url = new URL(b.url);
2616
+ if (url.username || url.password || url.search || url.hash || url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))) {
2617
+ throw new Error("backend url must use HTTPS (HTTP is allowed only for loopback tests), without credentials");
2618
+ }
2619
+ return { kind: "wharf", url: b.url.replace(/\/$/, ""), account: b.account, tokenEnv: b.tokenEnv };
2360
2620
  }
2361
2621
 
2362
2622
  // packages/core/dist/decisions.js
@@ -2382,43 +2642,22 @@ var ANSWER_TYPES = {
2382
2642
  };
2383
2643
  var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
2384
2644
 
2385
- // packages/core/dist/inbox.js
2386
- import * as fs19 from "node:fs";
2387
- import * as path15 from "node:path";
2388
- var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
2389
- function inboxDir(id, lane) {
2390
- return path15.join(laneDirs(lane).inbox, id);
2391
- }
2392
- function unhandled(id, lane) {
2393
- const dir = inboxDir(id, lane);
2394
- return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs19.readFileSync(path15.join(dir, f), "utf8") }));
2395
- }
2396
- function acknowledge(id, lane, file2) {
2397
- const dir = inboxDir(id, lane);
2398
- fs19.mkdirSync(path15.join(dir, "handled"), { recursive: true });
2399
- fs19.renameSync(path15.join(dir, file2), path15.join(dir, "handled", file2));
2400
- try {
2401
- fs19.renameSync(path15.join(dir, metaName(file2)), path15.join(dir, "handled", metaName(file2)));
2402
- } catch {
2403
- }
2404
- }
2405
-
2406
2645
  // packages/core/dist/harness.js
2407
- import * as fs20 from "node:fs";
2408
- import * as path16 from "node:path";
2646
+ import * as fs23 from "node:fs";
2647
+ import * as path19 from "node:path";
2409
2648
  import { createRequire } from "node:module";
2410
2649
  function resolveOnPath(bin, pathVar = process.env.PATH) {
2411
2650
  if (!pathVar)
2412
2651
  return void 0;
2413
2652
  const names = process.platform === "win32" ? [bin, `${bin}.exe`, `${bin}.cmd`, `${bin}.bat`] : [bin];
2414
- for (const dir of pathVar.split(path16.delimiter)) {
2653
+ for (const dir of pathVar.split(path19.delimiter)) {
2415
2654
  if (!dir)
2416
2655
  continue;
2417
2656
  for (const name of names) {
2418
- const candidate = path16.join(dir, name);
2657
+ const candidate = path19.join(dir, name);
2419
2658
  try {
2420
- fs20.accessSync(candidate, fs20.constants.X_OK);
2421
- if (fs20.statSync(candidate).isFile())
2659
+ fs23.accessSync(candidate, fs23.constants.X_OK);
2660
+ if (fs23.statSync(candidate).isFile())
2422
2661
  return candidate;
2423
2662
  } catch {
2424
2663
  }
@@ -2439,8 +2678,8 @@ function codexInvocation(argv) {
2439
2678
  } catch {
2440
2679
  }
2441
2680
  for (const dir of require_.resolve.paths("@openai/codex") ?? []) {
2442
- const cli = path16.join(dir, "@openai", "codex", "bin", "codex.js");
2443
- if (fs20.existsSync(cli))
2681
+ const cli = path19.join(dir, "@openai", "codex", "bin", "codex.js");
2682
+ if (fs23.existsSync(cli))
2444
2683
  return { file: process.execPath, argv: [cli, ...argv] };
2445
2684
  }
2446
2685
  return void 0;
@@ -2492,150 +2731,6 @@ function pushRule(branch, id = "<dispatch id>", mode = "rebase", also = []) {
2492
2731
  ].join(" ");
2493
2732
  }
2494
2733
 
2495
- // packages/core/dist/resume.js
2496
- import * as fs21 from "node:fs";
2497
- import * as os3 from "node:os";
2498
- import * as path17 from "node:path";
2499
- import { spawnSync as spawnSync2 } from "node:child_process";
2500
- var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-([0-9a-f])[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
2501
- function harnessFromSessionId(sessionId) {
2502
- const version = sessionId ? UUID.exec(sessionId)?.[1] : void 0;
2503
- return version === "7" ? "codex" : version === "4" ? "claude" : void 0;
2504
- }
2505
- function claimOf(id, lane) {
2506
- const dirs = laneDirs(lane);
2507
- for (const dir of [dirs.active, dirs.done]) {
2508
- try {
2509
- return JSON.parse(fs21.readFileSync(path17.join(dir, id, "claim.json"), "utf8"));
2510
- } catch {
2511
- }
2512
- }
2513
- return void 0;
2514
- }
2515
- function laneOf2(id) {
2516
- for (const lane of ["work", "chore"]) {
2517
- if (storedDescriptor(id, lane) || readEvidence(id, lane).sessionId)
2518
- return lane;
2519
- }
2520
- return void 0;
2521
- }
2522
- function resolveSessionHarness(id, cfg, laneHint) {
2523
- const lane = laneHint ?? laneOf2(id);
2524
- if (!lane)
2525
- return {};
2526
- const ev = readEvidence(id, lane);
2527
- const sessionId = ev.sessionId;
2528
- const out = (harness, source) => ({
2529
- sessionId,
2530
- harness,
2531
- source,
2532
- lane
2533
- });
2534
- if (ev.harness)
2535
- return out(ev.harness, "evidence");
2536
- const claim = claimOf(id, lane);
2537
- if (claim?.harness)
2538
- return out(claim.harness, "trap");
2539
- if (ev.deliveredTo?.startsWith("wt:")) {
2540
- const reg = readTrap(ev.deliveredTo.slice("wt:".length));
2541
- if (reg?.harness)
2542
- return out(reg.harness, "trap");
2543
- }
2544
- const byId = harnessFromSessionId(sessionId);
2545
- if (byId)
2546
- return out(byId, "session-id");
2547
- const d = storedDescriptor(id, lane);
2548
- const repo = d && cfg?.repos[d.repo];
2549
- const fromDescriptor = d?.harness ?? repo?.harness?.default ?? cfg?.harness.default;
2550
- if (fromDescriptor)
2551
- return out(fromDescriptor, "descriptor");
2552
- return { sessionId, lane };
2553
- }
2554
- var UNRESUMABLE = /no conversation found|no rollout found|thread\/resume failed|(session|thread|conversation)( id)?[^.\n]{0,80}\b(not found|does not exist|unknown|invalid)|(could not|cannot|failed to|unable to) (find|load|resume)[^.\n]{0,40}\b(session|thread|conversation)/i;
2555
- function isUnresumable(error) {
2556
- return error !== void 0 && UNRESUMABLE.test(error);
2557
- }
2558
- function worktreeProgress(worktree, trunk) {
2559
- if (!worktree || !fs21.existsSync(worktree))
2560
- return "No worktree progress recorded.";
2561
- const git2 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
2562
- const commits = trunk ? git2("log", "--oneline", `origin/${trunk}..HEAD`) : git2("log", "--oneline", "-15");
2563
- const status = git2("status", "--short");
2564
- return `Commits so far:
2565
- ${commits || "(none)"}
2566
-
2567
- Uncommitted changes:
2568
- ${status || "(clean)"}`;
2569
- }
2570
- function originProgress(originId, lane) {
2571
- const ev = readEvidence(originId, lane);
2572
- const last = readStatusLog(originId, lane).at(-1);
2573
- const lines = [`The earlier dispatch ${originId} left:`];
2574
- if (ev.branch)
2575
- lines.push(`- branch: ${ev.branch}`);
2576
- if (ev.prUrl)
2577
- lines.push(`- PR: ${ev.prUrl}`);
2578
- if (last)
2579
- lines.push(`- last status: ${last.verb}${last.note ? ` \u2014 ${last.note}` : ""}`);
2580
- if (ev.commits?.length)
2581
- lines.push("- commits:", ...ev.commits.map((c) => ` ${c}`));
2582
- if (lines.length === 1)
2583
- lines.push("- (no recorded branch, PR, or commits)");
2584
- return lines.join("\n");
2585
- }
2586
- function handoffNote(fromHarness, progress, why) {
2587
- return `You are taking over this dispatch from a previous agent session (harness: ${fromHarness}). Its conversation is not available${why ? ` (${why})` : ""} \u2014 the state below is the ground truth. Review it, then continue the brief from where it stops.
2588
-
2589
- ${progress}`;
2590
- }
2591
- function codexHome(env = process.env) {
2592
- return env.CODEX_HOME ?? path17.join(os3.homedir(), ".codex");
2593
- }
2594
- function codexRolloutFile(threadId, home = codexHome()) {
2595
- const suffix = `-${threadId}.jsonl`;
2596
- const walk = (dir, depth) => {
2597
- let entries;
2598
- try {
2599
- entries = fs21.readdirSync(dir, { withFileTypes: true });
2600
- } catch {
2601
- return void 0;
2602
- }
2603
- for (const e of entries) {
2604
- if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
2605
- return path17.join(dir, e.name);
2606
- }
2607
- if (depth === 0)
2608
- return void 0;
2609
- for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
2610
- const hit = walk(path17.join(dir, e.name), depth - 1);
2611
- if (hit)
2612
- return hit;
2613
- }
2614
- return void 0;
2615
- };
2616
- return walk(path17.join(home, "sessions"), 3) ?? walk(path17.join(home, "archived_sessions"), 0);
2617
- }
2618
- function codexDesktopThread(threadId, home = codexHome()) {
2619
- const file2 = codexRolloutFile(threadId, home);
2620
- if (!file2)
2621
- return void 0;
2622
- let head = "";
2623
- try {
2624
- const fd = fs21.openSync(file2, "r");
2625
- try {
2626
- const buf = Buffer.alloc(4096);
2627
- head = buf.subarray(0, fs21.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
2628
- } finally {
2629
- fs21.closeSync(fd);
2630
- }
2631
- } catch {
2632
- return void 0;
2633
- }
2634
- const originator = /"originator"\s*:\s*"([^"]*)"/.exec(head)?.[1];
2635
- return originator && /desktop/i.test(originator) ? originator : void 0;
2636
- }
2637
- var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
2638
-
2639
2734
  // packages/core/dist/models.js
2640
2735
  var MODEL_OWNERS = [
2641
2736
  [/^(anthropic[/.])?(claude|opus|sonnet|haiku|fable)(\b|-|$)|^opusplan$/i, "claude"],
@@ -2657,8 +2752,8 @@ function droppedModelNote(harness, dropped) {
2657
2752
  }
2658
2753
 
2659
2754
  // packages/runner/src/run.ts
2660
- import * as fs26 from "node:fs";
2661
- import * as path22 from "node:path";
2755
+ import * as fs28 from "node:fs";
2756
+ import * as path24 from "node:path";
2662
2757
  import { execFileSync as execFileSync2 } from "node:child_process";
2663
2758
  import { fileURLToPath as fileURLToPath2 } from "node:url";
2664
2759
 
@@ -2954,25 +3049,25 @@ function createClaudeAdapter() {
2954
3049
  }
2955
3050
 
2956
3051
  // packages/adapters/dist/codex.js
2957
- import * as fs22 from "node:fs";
3052
+ import * as fs24 from "node:fs";
2958
3053
  import * as os4 from "node:os";
2959
- import * as path18 from "node:path";
3054
+ import * as path20 from "node:path";
2960
3055
  import { spawn as spawn2 } from "node:child_process";
2961
3056
  function isolatedCodexHome() {
2962
- const dir = path18.join(lobstahHome(), "codex-home");
2963
- fs22.mkdirSync(dir, { recursive: true });
2964
- const auth = path18.join(dir, "auth.json");
2965
- const realAuth = path18.join(os4.homedir(), ".codex", "auth.json");
2966
- if (!fs22.existsSync(auth) && fs22.existsSync(realAuth)) {
3057
+ const dir = path20.join(lobstahHome(), "codex-home");
3058
+ fs24.mkdirSync(dir, { recursive: true });
3059
+ const auth = path20.join(dir, "auth.json");
3060
+ const realAuth = path20.join(os4.homedir(), ".codex", "auth.json");
3061
+ if (!fs24.existsSync(auth) && fs24.existsSync(realAuth)) {
2967
3062
  try {
2968
- fs22.symlinkSync(realAuth, auth);
3063
+ fs24.symlinkSync(realAuth, auth);
2969
3064
  } catch {
2970
- fs22.copyFileSync(realAuth, auth);
3065
+ fs24.copyFileSync(realAuth, auth);
2971
3066
  }
2972
3067
  }
2973
- const cfg = path18.join(dir, "config.toml");
2974
- if (!fs22.existsSync(cfg)) {
2975
- fs22.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
3068
+ const cfg = path20.join(dir, "config.toml");
3069
+ if (!fs24.existsSync(cfg)) {
3070
+ fs24.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
2976
3071
  }
2977
3072
  return dir;
2978
3073
  }
@@ -3175,15 +3270,15 @@ function loadAdapter(name) {
3175
3270
  }
3176
3271
 
3177
3272
  // packages/worktree/dist/index.js
3178
- import * as fs24 from "node:fs";
3179
- import * as path20 from "node:path";
3273
+ import * as fs26 from "node:fs";
3274
+ import * as path22 from "node:path";
3180
3275
  import { createHash } from "node:crypto";
3181
3276
  import { exec, execFile as execFile2, execFileSync } from "node:child_process";
3182
3277
  import { promisify as promisify2 } from "node:util";
3183
3278
 
3184
3279
  // packages/worktree/dist/pool.js
3185
- import * as fs23 from "node:fs";
3186
- import * as path19 from "node:path";
3280
+ import * as fs25 from "node:fs";
3281
+ import * as path21 from "node:path";
3187
3282
  import { execFile } from "node:child_process";
3188
3283
  import { promisify } from "node:util";
3189
3284
  var run = promisify(execFile);
@@ -3245,17 +3340,17 @@ function takeOut(name, pool, slot, reason, dispatch, notice = true) {
3245
3340
  function trapIn(dir) {
3246
3341
  const real = (p) => {
3247
3342
  try {
3248
- return fs23.realpathSync.native(p);
3343
+ return fs25.realpathSync.native(p);
3249
3344
  } catch {
3250
- return path19.resolve(p);
3345
+ return path21.resolve(p);
3251
3346
  }
3252
3347
  };
3253
3348
  const here = real(dir);
3254
3349
  return listTraps().some((t) => {
3255
3350
  if (typeof t.worktree !== "string")
3256
3351
  return false;
3257
- const rel = path19.relative(here, real(t.worktree));
3258
- return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
3352
+ const rel = path21.relative(here, real(t.worktree));
3353
+ return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
3259
3354
  });
3260
3355
  }
3261
3356
  async function claimPoolSlot(input) {
@@ -3263,7 +3358,7 @@ async function claimPoolSlot(input) {
3263
3358
  const refused = [];
3264
3359
  for (let slot = 1; slot <= pool.size; slot++) {
3265
3360
  const dir = poolSlotPath(name, slot);
3266
- if (fs23.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
3361
+ if (fs25.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
3267
3362
  writeSlotClaim(name, slot, { id, lane, at: (/* @__PURE__ */ new Date()).toISOString() });
3268
3363
  return { claimed: true, dir, slot, label: poolSlotLabel(name, slot) };
3269
3364
  }
@@ -3311,7 +3406,7 @@ async function resetPoolWorktree(repo, dir, id, fromRemoteBranch = repo.trunk) {
3311
3406
  }
3312
3407
  var WARM_ID = "pool-warm";
3313
3408
  async function createSlot(repo, dir) {
3314
- fs23.mkdirSync(path19.dirname(dir), { recursive: true });
3409
+ fs25.mkdirSync(path21.dirname(dir), { recursive: true });
3315
3410
  await oneAtATime(repo.path, async () => {
3316
3411
  await tryGit(repo.path, "worktree", "prune");
3317
3412
  await gitShared(repo.path, "worktree", "add", "--detach", dir, `origin/${repo.trunk}`);
@@ -3333,7 +3428,7 @@ async function warmPool(name, opts = {}) {
3333
3428
  if (!release)
3334
3429
  return false;
3335
3430
  try {
3336
- if (!fs23.existsSync(repo.path)) {
3431
+ if (!fs25.existsSync(repo.path)) {
3337
3432
  if (!repo.origin)
3338
3433
  throw new Error(`repo path ${repo.path} missing and no origin configured`);
3339
3434
  await run("git", ["clone", repo.origin, repo.path], { env: process.env });
@@ -3346,8 +3441,8 @@ async function warmPool(name, opts = {}) {
3346
3441
  const dir = poolSlotPath(name, slot);
3347
3442
  const label = poolSlotLabel(name, slot);
3348
3443
  const meta = readSlotMeta(name, slot);
3349
- if (!fs23.existsSync(dir)) {
3350
- fs23.mkdirSync(poolsRoot(), { recursive: true });
3444
+ if (!fs25.existsSync(dir)) {
3445
+ fs25.mkdirSync(poolsRoot(), { recursive: true });
3351
3446
  let free = Infinity;
3352
3447
  try {
3353
3448
  free = need > 0 ? read2(poolsRoot()) : Infinity;
@@ -3490,7 +3585,7 @@ function pidAlive2(pid) {
3490
3585
  var BUSY = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
3491
3586
  function takeRepoLock(file2, mine) {
3492
3587
  try {
3493
- fs24.writeFileSync(file2, mine, { flag: "wx" });
3588
+ fs26.writeFileSync(file2, mine, { flag: "wx" });
3494
3589
  return { state: "held" };
3495
3590
  } catch (err) {
3496
3591
  const code = err.code ?? "";
@@ -3500,8 +3595,8 @@ function takeRepoLock(file2, mine) {
3500
3595
  let raw = "";
3501
3596
  let age = 0;
3502
3597
  try {
3503
- raw = fs24.readFileSync(file2, "utf8");
3504
- age = Date.now() - fs24.statSync(file2).mtimeMs;
3598
+ raw = fs26.readFileSync(file2, "utf8");
3599
+ age = Date.now() - fs26.statSync(file2).mtimeMs;
3505
3600
  } catch {
3506
3601
  return { state: "retry" };
3507
3602
  }
@@ -3514,8 +3609,8 @@ function takeRepoLock(file2, mine) {
3514
3609
  const stale = age > REPO_LOCK_WAIT_MS || (holder ? !pidAlive2(holder.pid) : age > 5e3);
3515
3610
  if (stale) {
3516
3611
  try {
3517
- if (fs24.readFileSync(file2, "utf8") === raw)
3518
- fs24.rmSync(file2, { force: true });
3612
+ if (fs26.readFileSync(file2, "utf8") === raw)
3613
+ fs26.rmSync(file2, { force: true });
3519
3614
  } catch {
3520
3615
  }
3521
3616
  return { state: "retry" };
@@ -3524,13 +3619,13 @@ function takeRepoLock(file2, mine) {
3524
3619
  }
3525
3620
  function releaseRepoLock(file2, mine) {
3526
3621
  try {
3527
- if (fs24.readFileSync(file2, "utf8") === mine)
3528
- fs24.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
3622
+ if (fs26.readFileSync(file2, "utf8") === mine)
3623
+ fs26.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
3529
3624
  } catch {
3530
3625
  }
3531
3626
  }
3532
3627
  async function withRepoLock(common, fn) {
3533
- const file2 = path20.join(common, "lobstah-git.lock");
3628
+ const file2 = path22.join(common, "lobstah-git.lock");
3534
3629
  const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
3535
3630
  const deadline = Date.now() + REPO_LOCK_WAIT_MS;
3536
3631
  let held = false;
@@ -3566,7 +3661,7 @@ async function oneAtATime(cwd, fn) {
3566
3661
  }
3567
3662
  function fetchStamps(common) {
3568
3663
  try {
3569
- return JSON.parse(fs24.readFileSync(path20.join(common, "lobstah-fetch.json"), "utf8"));
3664
+ return JSON.parse(fs26.readFileSync(path22.join(common, "lobstah-fetch.json"), "utf8"));
3570
3665
  } catch {
3571
3666
  return {};
3572
3667
  }
@@ -3580,15 +3675,15 @@ async function fetchShared(cwd, remote, ref) {
3580
3675
  const started = Date.now();
3581
3676
  await gitShared(cwd, "fetch", remote, ref);
3582
3677
  const stamps = { ...fetchStamps(common), [key]: started };
3583
- fs24.writeFileSync(path20.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
3678
+ fs26.writeFileSync(path22.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
3584
3679
  });
3585
3680
  }
3586
3681
  async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
3587
3682
  const dir = worktreePath(id);
3588
- if (fs24.existsSync(dir)) {
3683
+ if (fs26.existsSync(dir)) {
3589
3684
  throw new Error(`worktree for ${id} already exists at ${dir} \u2014 never allocate a second`);
3590
3685
  }
3591
- if (!fs24.existsSync(repo.path)) {
3686
+ if (!fs26.existsSync(repo.path)) {
3592
3687
  if (!repo.origin)
3593
3688
  throw new Error(`repo path ${repo.path} missing and no origin configured`);
3594
3689
  await run2("git", ["clone", repo.origin, repo.path], { env: process.env });
@@ -3603,7 +3698,7 @@ async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
3603
3698
  async function recoverWorktree(repo, id) {
3604
3699
  const dir = worktreePath(id);
3605
3700
  try {
3606
- if (fs24.statSync(path20.join(dir, ".git")).isFile()) {
3701
+ if (fs26.statSync(path22.join(dir, ".git")).isFile()) {
3607
3702
  const branch = await git(dir, "symbolic-ref", "--quiet", "HEAD");
3608
3703
  const root = await git(dir, "rev-parse", "--show-toplevel");
3609
3704
  const common = await git(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
@@ -3641,27 +3736,27 @@ function setupHash(repo, dir) {
3641
3736
  const h = createHash("sha256");
3642
3737
  h.update(JSON.stringify(repo.setup ?? []));
3643
3738
  for (const name of LOCKFILES) {
3644
- const file2 = path20.join(dir, name);
3645
- if (!fs24.existsSync(file2))
3739
+ const file2 = path22.join(dir, name);
3740
+ if (!fs26.existsSync(file2))
3646
3741
  continue;
3647
3742
  h.update(`\0${name}\0`);
3648
- h.update(fs24.readFileSync(file2));
3743
+ h.update(fs26.readFileSync(file2));
3649
3744
  }
3650
3745
  return h.digest("hex");
3651
3746
  }
3652
3747
  function setupRecordFile(dir) {
3653
3748
  const gitDir = worktreeGitDir(dir);
3654
- return gitDir ? path20.join(gitDir, "lobstah-setup.json") : void 0;
3749
+ return gitDir ? path22.join(gitDir, "lobstah-setup.json") : void 0;
3655
3750
  }
3656
3751
  function recordSetup(repo, dir) {
3657
3752
  const file2 = setupRecordFile(dir);
3658
3753
  if (file2)
3659
- fs24.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
3754
+ fs26.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
3660
3755
  }
3661
3756
  function recordedSetupHash(dir) {
3662
3757
  const file2 = setupRecordFile(dir);
3663
3758
  try {
3664
- return file2 ? JSON.parse(fs24.readFileSync(file2, "utf8")).hash : void 0;
3759
+ return file2 ? JSON.parse(fs26.readFileSync(file2, "utf8")).hash : void 0;
3665
3760
  } catch {
3666
3761
  return void 0;
3667
3762
  }
@@ -3674,9 +3769,9 @@ function poolReused(slot, by) {
3674
3769
  function realpath(p) {
3675
3770
  let r;
3676
3771
  try {
3677
- r = fs24.realpathSync.native(p);
3772
+ r = fs26.realpathSync.native(p);
3678
3773
  } catch {
3679
- r = path20.resolve(p);
3774
+ r = path22.resolve(p);
3680
3775
  }
3681
3776
  return process.platform === "win32" ? r.toLowerCase() : r;
3682
3777
  }
@@ -3724,8 +3819,8 @@ async function chooseWorktree(input) {
3724
3819
  for (const t of listTraps()) {
3725
3820
  if (typeof t.worktree !== "string")
3726
3821
  continue;
3727
- const rel = path20.relative(here, realpath(t.worktree));
3728
- if (!rel.startsWith("..") && !path20.isAbsolute(rel))
3822
+ const rel = path22.relative(here, realpath(t.worktree));
3823
+ if (!rel.startsWith("..") && !path22.isAbsolute(rel))
3729
3824
  return { reuse: false, reason: "origin worktree is a trap\u2019s" };
3730
3825
  }
3731
3826
  for (const l of ["work", "chore"]) {
@@ -4153,8 +4248,8 @@ function startWallClock(opts) {
4153
4248
  import { execFile as execFile3 } from "node:child_process";
4154
4249
  import { promisify as promisify3 } from "node:util";
4155
4250
  import { fileURLToPath } from "node:url";
4156
- import * as fs25 from "node:fs";
4157
- import * as path21 from "node:path";
4251
+ import * as fs27 from "node:fs";
4252
+ import * as path23 from "node:path";
4158
4253
  var exec2 = promisify3(execFile3);
4159
4254
  function firstLine(err) {
4160
4255
  const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr).trim() : "";
@@ -4184,10 +4279,10 @@ function keepRemote(opts) {
4184
4279
  const note = (message) => mergeEvidence(id, lane, { note: message.slice(0, 300) });
4185
4280
  if (existingPrUrl) mergeEvidence(id, lane, { prUrl: existingPrUrl });
4186
4281
  const registerWatch = async (url) => {
4187
- const root = path21.resolve(path21.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
4188
- const localCli = path21.join(root, "apps", "cli", "dist", "main.js");
4282
+ const root = path23.resolve(path23.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
4283
+ const localCli = path23.join(root, "apps", "cli", "dist", "main.js");
4189
4284
  const args = ["watch", "add", url, "--for", id];
4190
- if (fs25.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
4285
+ if (fs27.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
4191
4286
  else await command("lobstah", args, 15e3);
4192
4287
  };
4193
4288
  let lastSeenHead;
@@ -4368,16 +4463,16 @@ function coldNote(cold, cwd, trunk) {
4368
4463
  }
4369
4464
  async function main(activeDir, lane, seams = {}) {
4370
4465
  const deps = { ...defaultDeps, ...seams };
4371
- const id = path22.basename(activeDir);
4466
+ const id = path24.basename(activeDir);
4372
4467
  if (isTrapCatch(id, lane)) throw new Error(`refusing headless runner for trap catch ${id}`);
4373
4468
  const status = (verb, note) => appendStatus(id, lane, verb, note);
4374
4469
  const cfg = loadConfig();
4375
- const descriptor = JSON.parse(fs26.readFileSync(path22.join(activeDir, "descriptor.json"), "utf8"));
4470
+ const descriptor = JSON.parse(fs28.readFileSync(path24.join(activeDir, "descriptor.json"), "utf8"));
4376
4471
  const resolved = resolveDispatch(descriptor, cfg);
4377
4472
  const repo = cfg.repos[descriptor.repo];
4378
- const briefFile = path22.join(activeDir, "brief.md");
4379
- if (!fs26.existsSync(briefFile)) fs26.writeFileSync(briefFile, descriptor.brief);
4380
- const brief = fs26.readFileSync(briefFile, "utf8");
4473
+ const briefFile = path24.join(activeDir, "brief.md");
4474
+ if (!fs28.existsSync(briefFile)) fs28.writeFileSync(briefFile, descriptor.brief);
4475
+ const brief = fs28.readFileSync(briefFile, "utf8");
4381
4476
  const attempts = Number(process.env.LOBSTAH_ATTEMPTS ?? "1");
4382
4477
  const wake = process.env.LOBSTAH_WAKE;
4383
4478
  const runnerInfo = {
@@ -4385,7 +4480,7 @@ async function main(activeDir, lane, seams = {}) {
4385
4480
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
4386
4481
  attempts
4387
4482
  };
4388
- fs26.writeFileSync(path22.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
4483
+ fs28.writeFileSync(path24.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
4389
4484
  if (descriptor.systemRepair && descriptor.pr?.url) {
4390
4485
  const state = deps.prState(descriptor.pr.url) ?? readPr(parsePrRef(descriptor.pr.url)?.key ?? "")?.state;
4391
4486
  if (state === "MERGED" || state === "CLOSED") {
@@ -4402,14 +4497,14 @@ async function main(activeDir, lane, seams = {}) {
4402
4497
  resolvedHarness: resolved.harness,
4403
4498
  envResume: process.env.LOBSTAH_RESUME
4404
4499
  });
4405
- const wtFile = path22.join(activeDir, "worktree.json");
4500
+ const wtFile = path24.join(activeDir, "worktree.json");
4406
4501
  let recorded;
4407
4502
  let recovered = false;
4408
4503
  let choice3;
4409
- if (fs26.existsSync(wtFile)) {
4410
- recorded = JSON.parse(fs26.readFileSync(wtFile, "utf8")).path;
4411
- if (!fs26.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
4412
- } else if (fs26.existsSync(worktreePath(id))) {
4504
+ if (fs28.existsSync(wtFile)) {
4505
+ recorded = JSON.parse(fs28.readFileSync(wtFile, "utf8")).path;
4506
+ if (!fs28.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
4507
+ } else if (fs28.existsSync(worktreePath(id))) {
4413
4508
  recorded = await recoverWorktree(repo, id);
4414
4509
  recovered = true;
4415
4510
  } else if (descriptor.followUp && cfg.limits.reuseWorktree !== false) {
@@ -4464,7 +4559,7 @@ async function main(activeDir, lane, seams = {}) {
4464
4559
  if (held) throw new Error(`worktree at ${cwd} is in use by ${held.id} \u2014 wait for that dispatch to release it before retrying`);
4465
4560
  if (recovered) {
4466
4561
  await deps.prepareReuse(repo, cwd);
4467
- fs26.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4562
+ fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4468
4563
  }
4469
4564
  } else if (choice3?.reuse) {
4470
4565
  cwd = choice3.path;
@@ -4475,17 +4570,17 @@ async function main(activeDir, lane, seams = {}) {
4475
4570
  type: "runner",
4476
4571
  data: { worktree: cwd, worktreeOf: choice3.owner, setupRan }
4477
4572
  });
4478
- fs26.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
4573
+ fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
4479
4574
  } else if (poolClaim) {
4480
4575
  cwd = poolClaim.dir;
4481
4576
  await deps.resetPool(repo, cwd, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
4482
- fs26.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
4577
+ fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
4483
4578
  } else {
4484
4579
  cwd = await deps.allocate(repo, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
4485
4580
  acquireWorktreeLock(cwd, id, lane);
4486
- fs26.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4581
+ fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4487
4582
  }
4488
- const worktreeOf = JSON.parse(fs26.readFileSync(wtFile, "utf8")).of;
4583
+ const worktreeOf = JSON.parse(fs28.readFileSync(wtFile, "utf8")).of;
4489
4584
  const inPool = poolSlotOf(cwd);
4490
4585
  mergeEvidence(id, lane, { worktree: cwd, worktreeOf, ...inPool ? { pool: poolSlotLabel(inPool.pool, inPool.slot) } : {} });
4491
4586
  const existingPr = boundPr(descriptor, lane);
@@ -4517,14 +4612,14 @@ async function main(activeDir, lane, seams = {}) {
4517
4612
  const envNudge = [process.env.LOBSTAH_NUDGE, wakeNote()].filter(Boolean).join("\n\n") || void 0;
4518
4613
  const planNudge = plan.cold && !envNudge ? coldNote(plan.cold, cwd, repo.trunk) : void 0;
4519
4614
  const promptWith = (nudge) => buildPrompt(brief, { id, nudge, attachments: descriptor.attachments, existingPr });
4520
- const binDir = path22.resolve(path22.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
4521
- const workerPath = fs26.existsSync(path22.join(binDir, "lobstah")) ? `${binDir}${path22.delimiter}${process.env.PATH ?? ""}` : void 0;
4615
+ const binDir = path24.resolve(path24.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
4616
+ const workerPath = fs28.existsSync(path24.join(binDir, "lobstah")) ? `${binDir}${path24.delimiter}${process.env.PATH ?? ""}` : void 0;
4522
4617
  let wallClockHit = false;
4523
4618
  let current;
4524
- const wallFile = path22.join(activeDir, "wallclock.json");
4619
+ const wallFile = path24.join(activeDir, "wallclock.json");
4525
4620
  const wallState = (() => {
4526
4621
  try {
4527
- return JSON.parse(fs26.readFileSync(wallFile, "utf8"));
4622
+ return JSON.parse(fs28.readFileSync(wallFile, "utf8"));
4528
4623
  } catch {
4529
4624
  return { elapsedMs: 0, windowMs: resolved.limits.wallClockSecs * 1e3 };
4530
4625
  }
@@ -4543,8 +4638,8 @@ async function main(activeDir, lane, seams = {}) {
4543
4638
  ) * 1e3;
4544
4639
  const persistWall = (elapsedMs, windowMs) => {
4545
4640
  const tmp = uniqueTempPath(wallFile);
4546
- fs26.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
4547
- fs26.renameSync(tmp, wallFile);
4641
+ fs28.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
4642
+ fs28.renameSync(tmp, wallFile);
4548
4643
  };
4549
4644
  const madeProgress = () => {
4550
4645
  const activity = readActivity(id, lane);
@@ -4848,13 +4943,13 @@ async function reapStarted(root = process.pid, graceMs) {
4848
4943
  var EXIT_LINGER_MS = 5e3;
4849
4944
  function runRunner(activeDirArg2, laneArg2) {
4850
4945
  const lane = laneArg2 === "chore" ? "chore" : "work";
4851
- const id = path23.basename(activeDirArg2);
4946
+ const id = path25.basename(activeDirArg2);
4852
4947
  main(activeDirArg2, lane, { reap: () => reapStarted(process.pid) }).catch((err) => {
4853
4948
  try {
4854
4949
  if (!isFinished(id, lane)) {
4855
4950
  appendStatus(id, lane, "failed", String(err instanceof Error ? err.message : err).slice(0, 500));
4856
4951
  }
4857
- fs27.renameSync(activeDirArg2, path23.join(laneDirs(lane).done, id));
4952
+ fs29.renameSync(activeDirArg2, path25.join(laneDirs(lane).done, id));
4858
4953
  } catch {
4859
4954
  }
4860
4955
  process.exitCode = 1;