lobstah 0.7.5 → 0.7.7
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/README.md +25 -7
- package/dist/main.js +11633 -7246
- package/dist/runner.js +774 -654
- package/dist/wharf-trap-runner.js +12 -0
- package/docs/configuration.md +22 -1
- package/docs/harness/claude-code.md +2 -0
- package/docs/harness/codex.md +1 -0
- package/docs/man.md +45 -1
- package/docs/vocabulary.md +8 -2
- package/package.json +4 -1
package/dist/runner.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/runner/src/index.ts
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
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/
|
|
12
|
-
import * as
|
|
13
|
-
import * as
|
|
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
|
|
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/
|
|
386
|
-
|
|
387
|
-
|
|
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
|
|
390
|
-
return
|
|
297
|
+
function choice(value, values) {
|
|
298
|
+
return typeof value === "string" && values.includes(value) ? value : null;
|
|
391
299
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
|
433
|
-
if (
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
|
455
|
-
|
|
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/
|
|
472
|
-
|
|
473
|
-
|
|
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
|
|
386
|
+
import * as fs3 from "node:fs";
|
|
514
387
|
function readEvidence(id, lane) {
|
|
515
388
|
try {
|
|
516
|
-
return JSON.parse(
|
|
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
|
-
|
|
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
|
|
530
|
-
import * as
|
|
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 =
|
|
458
|
+
let at = path3.resolve(dir);
|
|
586
459
|
for (; ; ) {
|
|
587
|
-
const dotGit =
|
|
460
|
+
const dotGit = path3.join(at, ".git");
|
|
588
461
|
try {
|
|
589
|
-
const stat =
|
|
462
|
+
const stat = fs4.statSync(dotGit);
|
|
590
463
|
if (stat.isDirectory())
|
|
591
464
|
return dotGit;
|
|
592
|
-
const m = /^gitdir:\s*(.+)$/m.exec(
|
|
593
|
-
return m ?
|
|
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 =
|
|
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(
|
|
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
|
|
500
|
+
import * as path13 from "node:path";
|
|
628
501
|
|
|
629
502
|
// packages/core/dist/config.js
|
|
630
|
-
import * as
|
|
503
|
+
import * as fs5 from "node:fs";
|
|
631
504
|
import * as os2 from "node:os";
|
|
632
|
-
import * as
|
|
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,
|
|
@@ -1373,9 +1249,11 @@ var DEFAULT_HELM = {
|
|
|
1373
1249
|
idleWorkingNoticeSecs: 60,
|
|
1374
1250
|
ttlSecs: 1800,
|
|
1375
1251
|
reportSecs: 900,
|
|
1376
|
-
armGraceSecs: 5
|
|
1252
|
+
armGraceSecs: 5,
|
|
1253
|
+
todoStaleDays: 3
|
|
1377
1254
|
};
|
|
1378
1255
|
var DEFAULT_GLASS = { port: 4949 };
|
|
1256
|
+
var DEFAULT_WAIT = { baseTimeoutSecs: 900, baseRepeats: 3, maxTimeoutSecs: 14400 };
|
|
1379
1257
|
var DEFAULT_WATCH = { maxForksPerCycle: 3, autoRepair: true, conflicts: true, checks: true, maxRepairsPerPr: 2, maxRepairsWithoutProgress: 2, repairSettleSecs: 600, repairCooldownSecs: 0, repairTrapWaitSecs: 600 };
|
|
1380
1258
|
var DEFAULT_LIMITS = {
|
|
1381
1259
|
maxConcurrent: 2,
|
|
@@ -1396,20 +1274,36 @@ var DEFAULT_LIMITS = {
|
|
|
1396
1274
|
releaseOnMerge: false
|
|
1397
1275
|
};
|
|
1398
1276
|
function configPath() {
|
|
1399
|
-
return
|
|
1277
|
+
return path4.join(lobstahHome(), "config.toml");
|
|
1400
1278
|
}
|
|
1401
1279
|
function expandHome(p) {
|
|
1402
|
-
return p.startsWith("~/") ?
|
|
1280
|
+
return p.startsWith("~/") ? path4.join(os2.homedir(), p.slice(2)) : p;
|
|
1403
1281
|
}
|
|
1404
1282
|
function loadConfig() {
|
|
1405
1283
|
const file2 = configPath();
|
|
1406
|
-
const raw =
|
|
1284
|
+
const raw = fs5.existsSync(file2) ? parse(fs5.readFileSync(file2, "utf8")) : {};
|
|
1407
1285
|
const petOpen = raw.pet?.open ?? "tab";
|
|
1408
1286
|
if (!["tab", "app", "helm"].includes(petOpen))
|
|
1409
1287
|
throw new Error(`[pet].open must be "tab", "app", or "helm" in ${configPath()}`);
|
|
1410
1288
|
const watch = { ...DEFAULT_WATCH, ...raw.watch ?? {} };
|
|
1411
1289
|
const helm = { ...DEFAULT_HELM, ...raw.helm ?? {} };
|
|
1412
|
-
|
|
1290
|
+
const wait = { ...DEFAULT_WAIT, ...raw.wait ?? {} };
|
|
1291
|
+
for (const key of ["baseTimeoutSecs", "baseRepeats", "maxTimeoutSecs"]) {
|
|
1292
|
+
if (typeof wait[key] !== "number" || !Number.isSafeInteger(wait[key]) || wait[key] <= 0)
|
|
1293
|
+
throw new Error(`[wait].${key} must be a positive whole number in ${configPath()}`);
|
|
1294
|
+
}
|
|
1295
|
+
if (wait.maxTimeoutSecs < wait.baseTimeoutSecs)
|
|
1296
|
+
throw new Error(`[wait].maxTimeoutSecs must be at least baseTimeoutSecs in ${configPath()}`);
|
|
1297
|
+
if (helm.timezone !== void 0) {
|
|
1298
|
+
if (typeof helm.timezone !== "string" || !helm.timezone.trim())
|
|
1299
|
+
throw new Error("[helm].timezone must be an IANA timezone");
|
|
1300
|
+
try {
|
|
1301
|
+
new Intl.DateTimeFormat("en", { timeZone: helm.timezone });
|
|
1302
|
+
} catch {
|
|
1303
|
+
throw new Error("[helm].timezone must be an IANA timezone");
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
for (const key of ["queuedNoticeSecs", "stalledNoticeSecs", "idleWorkingNoticeSecs", "todoStaleDays"]) {
|
|
1413
1307
|
if (typeof helm[key] !== "number" || !Number.isFinite(helm[key]) || helm[key] < 0) {
|
|
1414
1308
|
throw new Error(`[helm].${key} must be a non-negative number in ${configPath()}`);
|
|
1415
1309
|
}
|
|
@@ -1424,10 +1318,14 @@ function loadConfig() {
|
|
|
1424
1318
|
const reposRaw = raw.repos ?? {};
|
|
1425
1319
|
const repos = {};
|
|
1426
1320
|
for (const [key, r] of Object.entries(reposRaw)) {
|
|
1321
|
+
if (r.traps !== void 0 && (typeof r.traps !== "number" || !Number.isSafeInteger(r.traps) || r.traps < 0)) {
|
|
1322
|
+
throw new Error(`[repos.${key}].traps must be a non-negative whole number`);
|
|
1323
|
+
}
|
|
1427
1324
|
if (r.review !== void 0 && !validReviewTool(r.review))
|
|
1428
1325
|
throw new Error(`[repos.${key}].review must be github, graphite, linear, linear-app, or an HTTPS template with {owner}, {repo}, {number}`);
|
|
1429
1326
|
repos[key] = {
|
|
1430
1327
|
path: expandHome(String(r.path ?? "")),
|
|
1328
|
+
...r.traps !== void 0 ? { traps: r.traps } : {},
|
|
1431
1329
|
...r.review !== void 0 ? { review: r.review } : {},
|
|
1432
1330
|
origin: r.origin ? String(r.origin) : void 0,
|
|
1433
1331
|
trunk: String(r.trunk ?? "main"),
|
|
@@ -1445,9 +1343,17 @@ function loadConfig() {
|
|
|
1445
1343
|
};
|
|
1446
1344
|
}
|
|
1447
1345
|
const groundsRaw = raw.grounds ?? {};
|
|
1346
|
+
const wharves = {};
|
|
1347
|
+
for (const [name, value] of Object.entries(raw.wharves ?? {})) {
|
|
1348
|
+
if (!/^[A-Za-z0-9_-]{1,64}$/.test(name))
|
|
1349
|
+
throw new Error("invalid wharf name");
|
|
1350
|
+
wharves[name] = parseBackendLocation({ ...value, kind: "wharf" });
|
|
1351
|
+
}
|
|
1448
1352
|
const grounds = {};
|
|
1449
1353
|
for (const [key, g] of Object.entries(groundsRaw)) {
|
|
1450
|
-
|
|
1354
|
+
if (g.wharf !== void 0 && (typeof g.wharf !== "string" || !wharves[g.wharf]))
|
|
1355
|
+
throw new Error(`grounds ${key}: unknown wharf`);
|
|
1356
|
+
grounds[key] = { repos: Array.isArray(g.repos) ? g.repos.map(String) : [], ...g.wharf ? { wharf: String(g.wharf) } : {} };
|
|
1451
1357
|
}
|
|
1452
1358
|
return {
|
|
1453
1359
|
repos,
|
|
@@ -1455,10 +1361,12 @@ function loadConfig() {
|
|
|
1455
1361
|
limits: { ...DEFAULT_LIMITS, ...raw.limits ?? {} },
|
|
1456
1362
|
soak: parseSoak(raw.soak),
|
|
1457
1363
|
helm,
|
|
1364
|
+
wait,
|
|
1458
1365
|
glass: { ...DEFAULT_GLASS, ...raw.glass ?? {} },
|
|
1459
1366
|
pet: { open: petOpen },
|
|
1460
1367
|
watch,
|
|
1461
1368
|
grounds,
|
|
1369
|
+
wharves,
|
|
1462
1370
|
pools: parsePools(raw.pools, repos),
|
|
1463
1371
|
notifyCommand: raw.notifyCommand ? String(raw.notifyCommand) : void 0,
|
|
1464
1372
|
notifyVerbs: Array.isArray(raw.notifyVerbs) ? raw.notifyVerbs.map(String) : void 0,
|
|
@@ -1508,25 +1416,25 @@ function firstMeaningfulLine(...outputs) {
|
|
|
1508
1416
|
}
|
|
1509
1417
|
|
|
1510
1418
|
// packages/core/dist/pr-poll.js
|
|
1511
|
-
import * as
|
|
1512
|
-
import * as
|
|
1419
|
+
import * as fs9 from "node:fs";
|
|
1420
|
+
import * as path8 from "node:path";
|
|
1513
1421
|
|
|
1514
1422
|
// packages/core/dist/prs.js
|
|
1515
|
-
import * as
|
|
1516
|
-
import * as
|
|
1423
|
+
import * as fs6 from "node:fs";
|
|
1424
|
+
import * as path5 from "node:path";
|
|
1517
1425
|
function prsDir() {
|
|
1518
|
-
return
|
|
1426
|
+
return path5.join(lobstahHome(), "prs");
|
|
1519
1427
|
}
|
|
1520
1428
|
function prRecordFile(key) {
|
|
1521
1429
|
const ref = parsePrRef(key);
|
|
1522
1430
|
if (!ref)
|
|
1523
1431
|
throw new Error(`not a PR key: ${key}`);
|
|
1524
1432
|
const safe = (s) => s.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
1525
|
-
return
|
|
1433
|
+
return path5.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
|
|
1526
1434
|
}
|
|
1527
1435
|
function readPr(key) {
|
|
1528
1436
|
try {
|
|
1529
|
-
return JSON.parse(
|
|
1437
|
+
return JSON.parse(fs6.readFileSync(prRecordFile(key), "utf8"));
|
|
1530
1438
|
} catch {
|
|
1531
1439
|
return void 0;
|
|
1532
1440
|
}
|
|
@@ -1534,13 +1442,13 @@ function readPr(key) {
|
|
|
1534
1442
|
function readPrs() {
|
|
1535
1443
|
let files;
|
|
1536
1444
|
try {
|
|
1537
|
-
files =
|
|
1445
|
+
files = fs6.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
|
|
1538
1446
|
} catch {
|
|
1539
1447
|
return [];
|
|
1540
1448
|
}
|
|
1541
1449
|
return files.flatMap((f) => {
|
|
1542
1450
|
try {
|
|
1543
|
-
const r = JSON.parse(
|
|
1451
|
+
const r = JSON.parse(fs6.readFileSync(path5.join(prsDir(), f), "utf8"));
|
|
1544
1452
|
return typeof r.key === "string" && typeof r.url === "string" ? [r] : [];
|
|
1545
1453
|
} catch {
|
|
1546
1454
|
return [];
|
|
@@ -1549,16 +1457,16 @@ function readPrs() {
|
|
|
1549
1457
|
}
|
|
1550
1458
|
|
|
1551
1459
|
// packages/core/dist/watch.js
|
|
1552
|
-
import
|
|
1553
|
-
import * as
|
|
1460
|
+
import fs8 from "node:fs";
|
|
1461
|
+
import * as path7 from "node:path";
|
|
1554
1462
|
|
|
1555
1463
|
// packages/core/dist/github-budget.js
|
|
1556
|
-
import * as
|
|
1557
|
-
import * as
|
|
1558
|
-
var file = () =>
|
|
1464
|
+
import * as fs7 from "node:fs";
|
|
1465
|
+
import * as path6 from "node:path";
|
|
1466
|
+
var file = () => path6.join(lobstahHome(), "github-budget.json");
|
|
1559
1467
|
function read() {
|
|
1560
1468
|
try {
|
|
1561
|
-
return JSON.parse(
|
|
1469
|
+
return JSON.parse(fs7.readFileSync(file(), "utf8"));
|
|
1562
1470
|
} catch {
|
|
1563
1471
|
return { resources: {} };
|
|
1564
1472
|
}
|
|
@@ -1572,27 +1480,27 @@ function githubBlockedUntil(now2 = Date.now()) {
|
|
|
1572
1480
|
|
|
1573
1481
|
// packages/core/dist/watch.js
|
|
1574
1482
|
function watchesDir() {
|
|
1575
|
-
return
|
|
1483
|
+
return path7.join(lobstahHome(), "watches");
|
|
1576
1484
|
}
|
|
1577
1485
|
function slug(key) {
|
|
1578
1486
|
return key.replace(/[^A-Za-z0-9._-]+/g, "-");
|
|
1579
1487
|
}
|
|
1580
1488
|
function watchPath(key) {
|
|
1581
|
-
return
|
|
1489
|
+
return path7.join(watchesDir(), `${slug(key)}.json`);
|
|
1582
1490
|
}
|
|
1583
1491
|
function readWatch(key) {
|
|
1584
1492
|
try {
|
|
1585
|
-
return JSON.parse(
|
|
1493
|
+
return JSON.parse(fs8.readFileSync(watchPath(key), "utf8"));
|
|
1586
1494
|
} catch {
|
|
1587
1495
|
return void 0;
|
|
1588
1496
|
}
|
|
1589
1497
|
}
|
|
1590
1498
|
|
|
1591
1499
|
// packages/core/dist/pr-poll.js
|
|
1592
|
-
var cycleFile = (repo) =>
|
|
1500
|
+
var cycleFile = (repo) => path8.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
|
|
1593
1501
|
var readCycle = (repo) => {
|
|
1594
1502
|
try {
|
|
1595
|
-
return JSON.parse(
|
|
1503
|
+
return JSON.parse(fs9.readFileSync(cycleFile(repo), "utf8"));
|
|
1596
1504
|
} catch {
|
|
1597
1505
|
return void 0;
|
|
1598
1506
|
}
|
|
@@ -1624,7 +1532,7 @@ function parsePrRef(s) {
|
|
|
1624
1532
|
const number = Number(n);
|
|
1625
1533
|
return { owner, repo, number, key: `pr:${owner}/${repo}#${number}`, url: `https://github.com/${owner}/${repo}/pull/${number}` };
|
|
1626
1534
|
}
|
|
1627
|
-
var PR_VIEW_FIELDS = "title,state,isDraft,isCrossRepository,headRefOid,baseRefName,baseRefOid,headRefName,mergeStateStatus,reviewDecision,statusCheckRollup,mergedAt,closedAt,updatedAt,reviews";
|
|
1535
|
+
var PR_VIEW_FIELDS = "title,state,isDraft,isCrossRepository,headRefOid,baseRefName,baseRefOid,headRefName,mergeStateStatus,reviewDecision,statusCheckRollup,createdAt,mergedAt,closedAt,updatedAt,reviews";
|
|
1628
1536
|
var PR_VIEW_FIELDS_NO_CHECKS = PR_VIEW_FIELDS.split(",").filter((f) => f !== "statusCheckRollup").join(",");
|
|
1629
1537
|
var FORBIDDEN = /resource not accessible by (integration|personal access token)/i;
|
|
1630
1538
|
function ghPrView(ref) {
|
|
@@ -1685,23 +1593,23 @@ function parseUnresolvedThreads(stdout) {
|
|
|
1685
1593
|
}
|
|
1686
1594
|
|
|
1687
1595
|
// packages/core/dist/worktrees.js
|
|
1688
|
-
import * as
|
|
1689
|
-
import * as
|
|
1596
|
+
import * as fs10 from "node:fs";
|
|
1597
|
+
import * as path9 from "node:path";
|
|
1690
1598
|
var LANES = ["work", "chore"];
|
|
1691
1599
|
function worktreePath(id) {
|
|
1692
|
-
return
|
|
1600
|
+
return path9.join(lobstahHome(), "worktrees", id);
|
|
1693
1601
|
}
|
|
1694
1602
|
function readRecord(file2) {
|
|
1695
1603
|
try {
|
|
1696
|
-
const r = JSON.parse(
|
|
1604
|
+
const r = JSON.parse(fs10.readFileSync(file2, "utf8"));
|
|
1697
1605
|
return typeof r.path === "string" ? r : void 0;
|
|
1698
1606
|
} catch {
|
|
1699
1607
|
return void 0;
|
|
1700
1608
|
}
|
|
1701
1609
|
}
|
|
1702
1610
|
function ownerOfPath(p) {
|
|
1703
|
-
const rel =
|
|
1704
|
-
if (!rel || rel.startsWith("..") ||
|
|
1611
|
+
const rel = path9.relative(path9.join(lobstahHome(), "worktrees"), p);
|
|
1612
|
+
if (!rel || rel.startsWith("..") || path9.isAbsolute(rel))
|
|
1705
1613
|
return void 0;
|
|
1706
1614
|
return rel.split(/[\\/]/)[0];
|
|
1707
1615
|
}
|
|
@@ -1714,7 +1622,7 @@ function dispatchWorktree(id, lane) {
|
|
|
1714
1622
|
}
|
|
1715
1623
|
const dirs = laneDirs(l);
|
|
1716
1624
|
for (const dir of [dirs.active, dirs.done]) {
|
|
1717
|
-
const rec = readRecord(
|
|
1625
|
+
const rec = readRecord(path9.join(dir, id, "worktree.json"));
|
|
1718
1626
|
if (rec) {
|
|
1719
1627
|
const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
|
|
1720
1628
|
return { path: rec.path, owner, reused: owner !== id };
|
|
@@ -1726,7 +1634,7 @@ function dispatchWorktree(id, lane) {
|
|
|
1726
1634
|
function laneOf(id) {
|
|
1727
1635
|
for (const l of LANES) {
|
|
1728
1636
|
const d = laneDirs(l);
|
|
1729
|
-
if (
|
|
1637
|
+
if (fs10.existsSync(path9.join(d.queue, `${id}.json`)) || fs10.existsSync(path9.join(d.active, id)) || fs10.existsSync(path9.join(d.done, id))) {
|
|
1730
1638
|
return l;
|
|
1731
1639
|
}
|
|
1732
1640
|
}
|
|
@@ -1746,7 +1654,7 @@ function followUpAncestors(id, lane) {
|
|
|
1746
1654
|
function chainWorktree(followUp) {
|
|
1747
1655
|
for (const id of [followUp, ...followUpAncestors(followUp)]) {
|
|
1748
1656
|
const wt = dispatchWorktree(id, laneOf(id));
|
|
1749
|
-
if (
|
|
1657
|
+
if (fs10.existsSync(wt.path))
|
|
1750
1658
|
return { ...wt, from: id };
|
|
1751
1659
|
}
|
|
1752
1660
|
return void 0;
|
|
@@ -1761,27 +1669,27 @@ function processAlive(pid) {
|
|
|
1761
1669
|
}
|
|
1762
1670
|
}
|
|
1763
1671
|
function worktreeGitDir(wt) {
|
|
1764
|
-
const dotGit =
|
|
1672
|
+
const dotGit = path9.join(wt, ".git");
|
|
1765
1673
|
try {
|
|
1766
|
-
const st =
|
|
1674
|
+
const st = fs10.statSync(dotGit);
|
|
1767
1675
|
if (st.isDirectory())
|
|
1768
1676
|
return dotGit;
|
|
1769
|
-
const m = /^gitdir:\s*(.+?)\s*$/m.exec(
|
|
1770
|
-
return m ?
|
|
1677
|
+
const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs10.readFileSync(dotGit, "utf8"));
|
|
1678
|
+
return m ? path9.resolve(wt, m[1]) : void 0;
|
|
1771
1679
|
} catch {
|
|
1772
1680
|
return void 0;
|
|
1773
1681
|
}
|
|
1774
1682
|
}
|
|
1775
1683
|
function worktreeLockFile(wt) {
|
|
1776
1684
|
const gitDir = worktreeGitDir(wt);
|
|
1777
|
-
return gitDir ?
|
|
1685
|
+
return gitDir ? path9.join(gitDir, "lobstah.lock") : void 0;
|
|
1778
1686
|
}
|
|
1779
1687
|
function readWorktreeLock(wt) {
|
|
1780
1688
|
const file2 = worktreeLockFile(wt);
|
|
1781
1689
|
if (!file2)
|
|
1782
1690
|
return void 0;
|
|
1783
1691
|
try {
|
|
1784
|
-
return JSON.parse(
|
|
1692
|
+
return JSON.parse(fs10.readFileSync(file2, "utf8"));
|
|
1785
1693
|
} catch {
|
|
1786
1694
|
return void 0;
|
|
1787
1695
|
}
|
|
@@ -1789,7 +1697,7 @@ function readWorktreeLock(wt) {
|
|
|
1789
1697
|
function lockIsLive(lock) {
|
|
1790
1698
|
if (lock.kind === "warm")
|
|
1791
1699
|
return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
|
|
1792
|
-
return
|
|
1700
|
+
return fs10.existsSync(path9.join(laneDirs(lock.lane).active, lock.id));
|
|
1793
1701
|
}
|
|
1794
1702
|
function worktreeHolder(wt) {
|
|
1795
1703
|
const lock = readWorktreeLock(wt);
|
|
@@ -1802,7 +1710,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
1802
1710
|
return { id: "(no git dir)", lane, pid: 0, at: mine.at };
|
|
1803
1711
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
1804
1712
|
try {
|
|
1805
|
-
|
|
1713
|
+
fs10.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
|
|
1806
1714
|
return void 0;
|
|
1807
1715
|
} catch (err) {
|
|
1808
1716
|
if (err.code !== "EEXIST")
|
|
@@ -1810,7 +1718,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
1810
1718
|
}
|
|
1811
1719
|
let raw;
|
|
1812
1720
|
try {
|
|
1813
|
-
raw =
|
|
1721
|
+
raw = fs10.readFileSync(file2, "utf8");
|
|
1814
1722
|
} catch {
|
|
1815
1723
|
continue;
|
|
1816
1724
|
}
|
|
@@ -1821,14 +1729,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
1821
1729
|
held2 = void 0;
|
|
1822
1730
|
}
|
|
1823
1731
|
if (held2?.id === id) {
|
|
1824
|
-
|
|
1732
|
+
fs10.writeFileSync(file2, JSON.stringify(mine, null, 2));
|
|
1825
1733
|
return void 0;
|
|
1826
1734
|
}
|
|
1827
1735
|
if (held2 && lockIsLive(held2))
|
|
1828
1736
|
return held2;
|
|
1829
1737
|
try {
|
|
1830
|
-
if (
|
|
1831
|
-
|
|
1738
|
+
if (fs10.readFileSync(file2, "utf8") === raw)
|
|
1739
|
+
fs10.rmSync(file2, { force: true });
|
|
1832
1740
|
} catch {
|
|
1833
1741
|
}
|
|
1834
1742
|
}
|
|
@@ -1840,22 +1748,22 @@ function releaseWorktreeLock(wt, id) {
|
|
|
1840
1748
|
if (!file2)
|
|
1841
1749
|
return;
|
|
1842
1750
|
if (readWorktreeLock(wt)?.id === id)
|
|
1843
|
-
|
|
1751
|
+
fs10.rmSync(file2, { force: true });
|
|
1844
1752
|
}
|
|
1845
1753
|
|
|
1846
1754
|
// packages/core/dist/events.js
|
|
1847
|
-
import * as
|
|
1755
|
+
import * as fs11 from "node:fs";
|
|
1848
1756
|
function appendEvent(id, lane, ev) {
|
|
1849
|
-
|
|
1757
|
+
fs11.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
|
|
1850
1758
|
`);
|
|
1851
1759
|
}
|
|
1852
1760
|
function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
|
|
1853
1761
|
const file2 = eventsPath(id, lane);
|
|
1854
1762
|
try {
|
|
1855
|
-
|
|
1763
|
+
fs11.utimesSync(file2, at, at);
|
|
1856
1764
|
} catch {
|
|
1857
|
-
|
|
1858
|
-
|
|
1765
|
+
fs11.appendFileSync(file2, "");
|
|
1766
|
+
fs11.utimesSync(file2, at, at);
|
|
1859
1767
|
}
|
|
1860
1768
|
}
|
|
1861
1769
|
|
|
@@ -1869,31 +1777,31 @@ function isFinished(id, lane) {
|
|
|
1869
1777
|
}
|
|
1870
1778
|
|
|
1871
1779
|
// packages/core/dist/pools.js
|
|
1872
|
-
import * as
|
|
1873
|
-
import * as
|
|
1780
|
+
import * as fs12 from "node:fs";
|
|
1781
|
+
import * as path10 from "node:path";
|
|
1874
1782
|
function poolsRoot() {
|
|
1875
|
-
return
|
|
1783
|
+
return path10.join(lobstahHome(), "pools");
|
|
1876
1784
|
}
|
|
1877
1785
|
function poolDir(pool) {
|
|
1878
|
-
return
|
|
1786
|
+
return path10.join(poolsRoot(), pool);
|
|
1879
1787
|
}
|
|
1880
1788
|
function poolSlotPath(pool, slot) {
|
|
1881
|
-
return
|
|
1789
|
+
return path10.join(poolDir(pool), String(slot));
|
|
1882
1790
|
}
|
|
1883
1791
|
function slotsDir(pool) {
|
|
1884
|
-
return
|
|
1792
|
+
return path10.join(poolDir(pool), ".slots");
|
|
1885
1793
|
}
|
|
1886
1794
|
function poolSlotOf(p) {
|
|
1887
1795
|
const real = (x) => {
|
|
1888
1796
|
try {
|
|
1889
|
-
return
|
|
1797
|
+
return fs12.realpathSync.native(x);
|
|
1890
1798
|
} catch {
|
|
1891
|
-
return
|
|
1799
|
+
return path10.resolve(x);
|
|
1892
1800
|
}
|
|
1893
1801
|
};
|
|
1894
|
-
for (const [rootDir, dir] of [[poolsRoot(),
|
|
1895
|
-
const rel =
|
|
1896
|
-
if (!rel || rel.startsWith("..") ||
|
|
1802
|
+
for (const [rootDir, dir] of [[poolsRoot(), path10.resolve(p)], [real(poolsRoot()), real(p)]]) {
|
|
1803
|
+
const rel = path10.relative(rootDir, dir);
|
|
1804
|
+
if (!rel || rel.startsWith("..") || path10.isAbsolute(rel))
|
|
1897
1805
|
continue;
|
|
1898
1806
|
const parts = rel.split(/[\\/]/);
|
|
1899
1807
|
if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
|
|
@@ -1907,20 +1815,20 @@ function poolSlotLabel(pool, slot) {
|
|
|
1907
1815
|
}
|
|
1908
1816
|
function readJson(file2) {
|
|
1909
1817
|
try {
|
|
1910
|
-
return JSON.parse(
|
|
1818
|
+
return JSON.parse(fs12.readFileSync(file2, "utf8"));
|
|
1911
1819
|
} catch {
|
|
1912
1820
|
return void 0;
|
|
1913
1821
|
}
|
|
1914
1822
|
}
|
|
1915
1823
|
function writeJson(file2, value) {
|
|
1916
|
-
|
|
1824
|
+
fs12.mkdirSync(path10.dirname(file2), { recursive: true });
|
|
1917
1825
|
const tmp = uniqueTempPath(file2);
|
|
1918
|
-
|
|
1826
|
+
fs12.writeFileSync(tmp, JSON.stringify(value, null, 2));
|
|
1919
1827
|
atomicRenameSync(tmp, file2);
|
|
1920
1828
|
}
|
|
1921
|
-
var metaFile = (pool, slot) =>
|
|
1922
|
-
var claimFile = (pool, slot) =>
|
|
1923
|
-
var outFile = (pool, slot) =>
|
|
1829
|
+
var metaFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.json`);
|
|
1830
|
+
var claimFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.claim.json`);
|
|
1831
|
+
var outFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.out.json`);
|
|
1924
1832
|
function readSlotMeta(pool, slot) {
|
|
1925
1833
|
return readJson(metaFile(pool, slot)) ?? {};
|
|
1926
1834
|
}
|
|
@@ -1940,7 +1848,7 @@ function writeSlotOut(pool, slot, out) {
|
|
|
1940
1848
|
writeJson(outFile(pool, slot), out);
|
|
1941
1849
|
}
|
|
1942
1850
|
function clearSlotOut(pool, slot) {
|
|
1943
|
-
|
|
1851
|
+
fs12.rmSync(outFile(pool, slot), { force: true });
|
|
1944
1852
|
}
|
|
1945
1853
|
function dispatchHolder(dir) {
|
|
1946
1854
|
const lock = readWorktreeLock(dir);
|
|
@@ -1950,7 +1858,7 @@ function poolSlotView(pool, slot) {
|
|
|
1950
1858
|
const dir = poolSlotPath(pool, slot);
|
|
1951
1859
|
const lastClaim = readSlotClaim(pool, slot)?.id;
|
|
1952
1860
|
const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
|
|
1953
|
-
if (!
|
|
1861
|
+
if (!fs12.existsSync(dir)) {
|
|
1954
1862
|
const meta2 = readSlotMeta(pool, slot);
|
|
1955
1863
|
return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
|
|
1956
1864
|
}
|
|
@@ -1965,8 +1873,8 @@ function poolSlotView(pool, slot) {
|
|
|
1965
1873
|
return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
|
|
1966
1874
|
return { ...base, state: "free" };
|
|
1967
1875
|
}
|
|
1968
|
-
var warmStateFile = (pool) =>
|
|
1969
|
-
var warmLockFile = (pool) =>
|
|
1876
|
+
var warmStateFile = (pool) => path10.join(poolDir(pool), ".warm-state.json");
|
|
1877
|
+
var warmLockFile = (pool) => path10.join(poolDir(pool), ".warm.lock");
|
|
1970
1878
|
var POOL_WARM_MAX_MS = 60 * 6e4;
|
|
1971
1879
|
function readPoolWarmState(pool) {
|
|
1972
1880
|
return readJson(warmStateFile(pool)) ?? {};
|
|
@@ -1988,15 +1896,15 @@ function poolWarmRunning(pool, now2 = Date.now()) {
|
|
|
1988
1896
|
}
|
|
1989
1897
|
function takePoolWarmLock(pool) {
|
|
1990
1898
|
const file2 = warmLockFile(pool);
|
|
1991
|
-
|
|
1899
|
+
fs12.mkdirSync(path10.dirname(file2), { recursive: true });
|
|
1992
1900
|
const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1993
1901
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
1994
1902
|
try {
|
|
1995
|
-
|
|
1903
|
+
fs12.writeFileSync(file2, mine, { flag: "wx" });
|
|
1996
1904
|
return () => {
|
|
1997
1905
|
try {
|
|
1998
|
-
if (
|
|
1999
|
-
|
|
1906
|
+
if (fs12.readFileSync(file2, "utf8") === mine)
|
|
1907
|
+
fs12.rmSync(file2, { force: true });
|
|
2000
1908
|
} catch {
|
|
2001
1909
|
}
|
|
2002
1910
|
};
|
|
@@ -2006,7 +1914,7 @@ function takePoolWarmLock(pool) {
|
|
|
2006
1914
|
}
|
|
2007
1915
|
if (poolWarmRunning(pool))
|
|
2008
1916
|
return void 0;
|
|
2009
|
-
|
|
1917
|
+
fs12.rmSync(file2, { force: true });
|
|
2010
1918
|
}
|
|
2011
1919
|
return void 0;
|
|
2012
1920
|
}
|
|
@@ -2015,26 +1923,191 @@ var POOL_FETCH_MS = 10 * 6e4;
|
|
|
2015
1923
|
var POOL_RECHECK_MS = 5 * 6e4;
|
|
2016
1924
|
|
|
2017
1925
|
// packages/core/dist/disk.js
|
|
2018
|
-
import * as
|
|
1926
|
+
import * as fs13 from "node:fs";
|
|
2019
1927
|
var GB = 1024 ** 3;
|
|
2020
1928
|
var statfsFreeBytes = (dir) => {
|
|
2021
|
-
const s =
|
|
1929
|
+
const s = fs13.statfsSync(dir);
|
|
2022
1930
|
return Number(s.bavail) * Number(s.bsize);
|
|
2023
1931
|
};
|
|
2024
1932
|
function formatGB(bytes) {
|
|
2025
1933
|
return `${(bytes / GB).toFixed(1).replace(/\.0$/, "")} GB`;
|
|
2026
1934
|
}
|
|
2027
1935
|
|
|
1936
|
+
// packages/core/dist/inbox.js
|
|
1937
|
+
import * as fs14 from "node:fs";
|
|
1938
|
+
import * as path11 from "node:path";
|
|
1939
|
+
var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
|
|
1940
|
+
function inboxDir(id, lane) {
|
|
1941
|
+
return path11.join(laneDirs(lane).inbox, id);
|
|
1942
|
+
}
|
|
1943
|
+
function unhandled(id, lane) {
|
|
1944
|
+
const dir = inboxDir(id, lane);
|
|
1945
|
+
return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs14.readFileSync(path11.join(dir, f), "utf8") }));
|
|
1946
|
+
}
|
|
1947
|
+
function acknowledge(id, lane, file2) {
|
|
1948
|
+
const dir = inboxDir(id, lane);
|
|
1949
|
+
fs14.mkdirSync(path11.join(dir, "handled"), { recursive: true });
|
|
1950
|
+
fs14.renameSync(path11.join(dir, file2), path11.join(dir, "handled", file2));
|
|
1951
|
+
try {
|
|
1952
|
+
fs14.renameSync(path11.join(dir, metaName(file2)), path11.join(dir, "handled", metaName(file2)));
|
|
1953
|
+
} catch {
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
// packages/core/dist/resume.js
|
|
1958
|
+
import * as fs15 from "node:fs";
|
|
1959
|
+
import * as os3 from "node:os";
|
|
1960
|
+
import * as path12 from "node:path";
|
|
1961
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
1962
|
+
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;
|
|
1963
|
+
function harnessFromSessionId(sessionId) {
|
|
1964
|
+
const version = sessionId ? UUID.exec(sessionId)?.[1] : void 0;
|
|
1965
|
+
return version === "7" ? "codex" : version === "4" ? "claude" : void 0;
|
|
1966
|
+
}
|
|
1967
|
+
function claimOf(id, lane) {
|
|
1968
|
+
const dirs = laneDirs(lane);
|
|
1969
|
+
for (const dir of [dirs.active, dirs.done]) {
|
|
1970
|
+
try {
|
|
1971
|
+
return JSON.parse(fs15.readFileSync(path12.join(dir, id, "claim.json"), "utf8"));
|
|
1972
|
+
} catch {
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
return void 0;
|
|
1976
|
+
}
|
|
1977
|
+
function laneOf2(id) {
|
|
1978
|
+
for (const lane of ["work", "chore"]) {
|
|
1979
|
+
if (storedDescriptor(id, lane) || readEvidence(id, lane).sessionId)
|
|
1980
|
+
return lane;
|
|
1981
|
+
}
|
|
1982
|
+
return void 0;
|
|
1983
|
+
}
|
|
1984
|
+
function resolveSessionHarness(id, cfg, laneHint) {
|
|
1985
|
+
const lane = laneHint ?? laneOf2(id);
|
|
1986
|
+
if (!lane)
|
|
1987
|
+
return {};
|
|
1988
|
+
const ev = readEvidence(id, lane);
|
|
1989
|
+
const sessionId = ev.sessionId;
|
|
1990
|
+
const out = (harness, source) => ({
|
|
1991
|
+
sessionId,
|
|
1992
|
+
harness,
|
|
1993
|
+
source,
|
|
1994
|
+
lane
|
|
1995
|
+
});
|
|
1996
|
+
if (ev.harness)
|
|
1997
|
+
return out(ev.harness, "evidence");
|
|
1998
|
+
const claim = claimOf(id, lane);
|
|
1999
|
+
if (claim?.harness)
|
|
2000
|
+
return out(claim.harness, "trap");
|
|
2001
|
+
if (ev.deliveredTo?.startsWith("wt:")) {
|
|
2002
|
+
const reg = readTrap(ev.deliveredTo.slice("wt:".length));
|
|
2003
|
+
if (reg?.harness)
|
|
2004
|
+
return out(reg.harness, "trap");
|
|
2005
|
+
}
|
|
2006
|
+
const byId = harnessFromSessionId(sessionId);
|
|
2007
|
+
if (byId)
|
|
2008
|
+
return out(byId, "session-id");
|
|
2009
|
+
const d = storedDescriptor(id, lane);
|
|
2010
|
+
const repo = d && cfg?.repos[d.repo];
|
|
2011
|
+
const fromDescriptor = d?.harness ?? repo?.harness?.default ?? cfg?.harness.default;
|
|
2012
|
+
if (fromDescriptor)
|
|
2013
|
+
return out(fromDescriptor, "descriptor");
|
|
2014
|
+
return { sessionId, lane };
|
|
2015
|
+
}
|
|
2016
|
+
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;
|
|
2017
|
+
function isUnresumable(error) {
|
|
2018
|
+
return error !== void 0 && UNRESUMABLE.test(error);
|
|
2019
|
+
}
|
|
2020
|
+
function worktreeProgress(worktree, trunk) {
|
|
2021
|
+
if (!worktree || !fs15.existsSync(worktree))
|
|
2022
|
+
return "No worktree progress recorded.";
|
|
2023
|
+
const git2 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
|
|
2024
|
+
const commits = trunk ? git2("log", "--oneline", `origin/${trunk}..HEAD`) : git2("log", "--oneline", "-15");
|
|
2025
|
+
const status = git2("status", "--short");
|
|
2026
|
+
return `Commits so far:
|
|
2027
|
+
${commits || "(none)"}
|
|
2028
|
+
|
|
2029
|
+
Uncommitted changes:
|
|
2030
|
+
${status || "(clean)"}`;
|
|
2031
|
+
}
|
|
2032
|
+
function originProgress(originId, lane) {
|
|
2033
|
+
const ev = readEvidence(originId, lane);
|
|
2034
|
+
const last = readStatusLog(originId, lane).at(-1);
|
|
2035
|
+
const lines = [`The earlier dispatch ${originId} left:`];
|
|
2036
|
+
if (ev.branch)
|
|
2037
|
+
lines.push(`- branch: ${ev.branch}`);
|
|
2038
|
+
if (ev.prUrl)
|
|
2039
|
+
lines.push(`- PR: ${ev.prUrl}`);
|
|
2040
|
+
if (last)
|
|
2041
|
+
lines.push(`- last status: ${last.verb}${last.note ? ` \u2014 ${last.note}` : ""}`);
|
|
2042
|
+
if (ev.commits?.length)
|
|
2043
|
+
lines.push("- commits:", ...ev.commits.map((c) => ` ${c}`));
|
|
2044
|
+
if (lines.length === 1)
|
|
2045
|
+
lines.push("- (no recorded branch, PR, or commits)");
|
|
2046
|
+
return lines.join("\n");
|
|
2047
|
+
}
|
|
2048
|
+
function handoffNote(fromHarness, progress, why) {
|
|
2049
|
+
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.
|
|
2050
|
+
|
|
2051
|
+
${progress}`;
|
|
2052
|
+
}
|
|
2053
|
+
function codexHome(env = process.env) {
|
|
2054
|
+
return env.CODEX_HOME ?? path12.join(os3.homedir(), ".codex");
|
|
2055
|
+
}
|
|
2056
|
+
function codexRolloutFile(threadId, home = codexHome()) {
|
|
2057
|
+
const suffix = `-${threadId}.jsonl`;
|
|
2058
|
+
const walk = (dir, depth) => {
|
|
2059
|
+
let entries;
|
|
2060
|
+
try {
|
|
2061
|
+
entries = fs15.readdirSync(dir, { withFileTypes: true });
|
|
2062
|
+
} catch {
|
|
2063
|
+
return void 0;
|
|
2064
|
+
}
|
|
2065
|
+
for (const e of entries) {
|
|
2066
|
+
if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
|
|
2067
|
+
return path12.join(dir, e.name);
|
|
2068
|
+
}
|
|
2069
|
+
if (depth === 0)
|
|
2070
|
+
return void 0;
|
|
2071
|
+
for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
|
|
2072
|
+
const hit = walk(path12.join(dir, e.name), depth - 1);
|
|
2073
|
+
if (hit)
|
|
2074
|
+
return hit;
|
|
2075
|
+
}
|
|
2076
|
+
return void 0;
|
|
2077
|
+
};
|
|
2078
|
+
return walk(path12.join(home, "sessions"), 3) ?? walk(path12.join(home, "archived_sessions"), 0);
|
|
2079
|
+
}
|
|
2080
|
+
function codexDesktopThread(threadId, home = codexHome()) {
|
|
2081
|
+
const file2 = codexRolloutFile(threadId, home);
|
|
2082
|
+
if (!file2)
|
|
2083
|
+
return void 0;
|
|
2084
|
+
let head = "";
|
|
2085
|
+
try {
|
|
2086
|
+
const fd = fs15.openSync(file2, "r");
|
|
2087
|
+
try {
|
|
2088
|
+
const buf = Buffer.alloc(4096);
|
|
2089
|
+
head = buf.subarray(0, fs15.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
|
|
2090
|
+
} finally {
|
|
2091
|
+
fs15.closeSync(fd);
|
|
2092
|
+
}
|
|
2093
|
+
} catch {
|
|
2094
|
+
return void 0;
|
|
2095
|
+
}
|
|
2096
|
+
const originator = /"originator"\s*:\s*"([^"]*)"/.exec(head)?.[1];
|
|
2097
|
+
return originator && /desktop/i.test(originator) ? originator : void 0;
|
|
2098
|
+
}
|
|
2099
|
+
var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
|
|
2100
|
+
|
|
2028
2101
|
// packages/core/dist/notices.js
|
|
2029
2102
|
function noticesDir() {
|
|
2030
|
-
return
|
|
2103
|
+
return path13.join(lobstahHome(), "notices");
|
|
2031
2104
|
}
|
|
2032
2105
|
var counter = 0;
|
|
2033
2106
|
function postNotice(n) {
|
|
2034
2107
|
const dir = noticesDir();
|
|
2035
2108
|
fs16.mkdirSync(dir, { recursive: true });
|
|
2036
2109
|
if (n.dedupeKey) {
|
|
2037
|
-
const marker =
|
|
2110
|
+
const marker = path13.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
|
|
2038
2111
|
try {
|
|
2039
2112
|
fs16.writeFileSync(marker, "", { flag: "wx" });
|
|
2040
2113
|
} catch {
|
|
@@ -2054,7 +2127,7 @@ function postNotice(n) {
|
|
|
2054
2127
|
...n.quiet ? { quiet: true } : {},
|
|
2055
2128
|
...n.stateHash ? { stateHash: n.stateHash } : {}
|
|
2056
2129
|
};
|
|
2057
|
-
const file2 =
|
|
2130
|
+
const file2 = path13.join(dir, `${seq}.json`);
|
|
2058
2131
|
const tmp = uniqueTempPath(file2);
|
|
2059
2132
|
fs16.writeFileSync(tmp, JSON.stringify(notice, null, 2));
|
|
2060
2133
|
atomicRenameSync(tmp, file2);
|
|
@@ -2072,39 +2145,83 @@ function attachmentBlock(attachments) {
|
|
|
2072
2145
|
].join("\n");
|
|
2073
2146
|
}
|
|
2074
2147
|
|
|
2148
|
+
// packages/core/dist/helm.js
|
|
2149
|
+
import * as fs17 from "node:fs";
|
|
2150
|
+
import * as path14 from "node:path";
|
|
2151
|
+
function helmDir() {
|
|
2152
|
+
return path14.join(lobstahHome(), "helm");
|
|
2153
|
+
}
|
|
2154
|
+
function listHelms() {
|
|
2155
|
+
try {
|
|
2156
|
+
return fs17.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs17.readFileSync(path14.join(helmDir(), f), "utf8")));
|
|
2157
|
+
} catch {
|
|
2158
|
+
return [];
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
function liveHelms(ttlMs, now2 = Date.now()) {
|
|
2162
|
+
return listHelms().filter((h) => now2 - (Date.parse(h.heartbeatAt) || 0) <= ttlMs);
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2075
2165
|
// packages/core/dist/soak.js
|
|
2076
2166
|
function regPath(trapId) {
|
|
2077
|
-
return
|
|
2167
|
+
return path15.join(soakingDir(), `${trapId}.json`);
|
|
2078
2168
|
}
|
|
2079
2169
|
function readTrap(trapId) {
|
|
2080
2170
|
try {
|
|
2081
|
-
return JSON.parse(
|
|
2171
|
+
return JSON.parse(fs18.readFileSync(regPath(trapId), "utf8"));
|
|
2082
2172
|
} catch {
|
|
2083
2173
|
return void 0;
|
|
2084
2174
|
}
|
|
2085
2175
|
}
|
|
2086
2176
|
function listTraps() {
|
|
2087
2177
|
try {
|
|
2088
|
-
return
|
|
2178
|
+
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
2179
|
} catch {
|
|
2090
2180
|
return [];
|
|
2091
2181
|
}
|
|
2092
2182
|
}
|
|
2093
2183
|
function claimPath(id, lane) {
|
|
2094
|
-
return
|
|
2184
|
+
return path15.join(laneDirs(lane).active, id, "claim.json");
|
|
2095
2185
|
}
|
|
2096
2186
|
function readSessionClaim(id, lane) {
|
|
2097
2187
|
try {
|
|
2098
|
-
return JSON.parse(
|
|
2188
|
+
return JSON.parse(fs18.readFileSync(claimPath(id, lane), "utf8"));
|
|
2099
2189
|
} catch {
|
|
2100
2190
|
return void 0;
|
|
2101
2191
|
}
|
|
2102
2192
|
}
|
|
2103
2193
|
|
|
2194
|
+
// packages/core/dist/catch-context.js
|
|
2195
|
+
import * as fs19 from "node:fs";
|
|
2196
|
+
import * as path16 from "node:path";
|
|
2197
|
+
function readCatchContext(dir, id) {
|
|
2198
|
+
try {
|
|
2199
|
+
return JSON.parse(fs19.readFileSync(path16.join(dir, `${id}.catch-context`), "utf8"));
|
|
2200
|
+
} catch {
|
|
2201
|
+
return {};
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
function observeLocalCatch(id, lane, phase, now2 = Date.now()) {
|
|
2205
|
+
const dir = laneDirs(lane).state, old = readCatchContext(dir, id), cfg = loadConfig();
|
|
2206
|
+
if (phase === "finish" && Object.hasOwn(old, "helm"))
|
|
2207
|
+
return;
|
|
2208
|
+
const repo = storedDescriptor(id, lane)?.repo;
|
|
2209
|
+
const helms = liveHelms(cfg.helm.ttlSecs * 1e3, now2);
|
|
2210
|
+
const present = repo ? helms.some((h) => h.repos.includes(repo)) : null;
|
|
2211
|
+
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 };
|
|
2212
|
+
const file2 = path16.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
|
|
2213
|
+
try {
|
|
2214
|
+
fs19.writeFileSync(tmp, JSON.stringify(next));
|
|
2215
|
+
fs19.renameSync(tmp, file2);
|
|
2216
|
+
} finally {
|
|
2217
|
+
fs19.rmSync(tmp, { force: true });
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2104
2221
|
// packages/core/dist/stats.js
|
|
2105
2222
|
var DAILY_RETENTION_DAYS = 400;
|
|
2106
2223
|
function statsPath() {
|
|
2107
|
-
return
|
|
2224
|
+
return path17.join(lobstahHome(), "stats.json");
|
|
2108
2225
|
}
|
|
2109
2226
|
function shiftDay(day, days) {
|
|
2110
2227
|
const [y, m, d] = day.split("-").map(Number);
|
|
@@ -2117,7 +2234,7 @@ function localDay(at = Date.now()) {
|
|
|
2117
2234
|
function readCatchFacts(stateDir, id) {
|
|
2118
2235
|
let last;
|
|
2119
2236
|
try {
|
|
2120
|
-
for (const line of
|
|
2237
|
+
for (const line of fs20.readFileSync(path17.join(stateDir, `${id}.status`), "utf8").split("\n")) {
|
|
2121
2238
|
if (!line.trim())
|
|
2122
2239
|
continue;
|
|
2123
2240
|
try {
|
|
@@ -2133,7 +2250,7 @@ function readCatchFacts(stateDir, id) {
|
|
|
2133
2250
|
let trap;
|
|
2134
2251
|
let worker = workerProfile();
|
|
2135
2252
|
try {
|
|
2136
|
-
const evidence = JSON.parse(
|
|
2253
|
+
const evidence = JSON.parse(fs20.readFileSync(path17.join(stateDir, `${id}.evidence`), "utf8"));
|
|
2137
2254
|
const to = evidence.deliveredTo;
|
|
2138
2255
|
if (typeof to === "string" && to.startsWith("wt:"))
|
|
2139
2256
|
trap = to;
|
|
@@ -2141,7 +2258,8 @@ function readCatchFacts(stateDir, id) {
|
|
|
2141
2258
|
worker = sanitizeWorker(reg ?? evidence.worker ?? workerProfile({ harness: evidence.harness }));
|
|
2142
2259
|
} catch {
|
|
2143
2260
|
}
|
|
2144
|
-
|
|
2261
|
+
const context = readCatchContext(stateDir, id);
|
|
2262
|
+
return { done: true, worker, helm: context.helm, location: context.location, ...typeof last.at === "string" ? { at: last.at } : {}, ...trap ? { trap } : {} };
|
|
2145
2263
|
}
|
|
2146
2264
|
function emptyStore(now2) {
|
|
2147
2265
|
return {
|
|
@@ -2189,6 +2307,15 @@ function add(store, facts, now2) {
|
|
|
2189
2307
|
store.utc = { date: utcDay, catches: 0, perTrap: {}, trapWorkers: {}, byWorker: [] };
|
|
2190
2308
|
if ((at ? new Date(at).toISOString().slice(0, 10) : utcDay) === utcDay) {
|
|
2191
2309
|
store.utc.catches++;
|
|
2310
|
+
const usage = store.utc.usage ??= { withHelm: 0, withoutHelm: 0, onLocal: 0, onWharf: 0 };
|
|
2311
|
+
if (facts.helm === true)
|
|
2312
|
+
usage.withHelm++;
|
|
2313
|
+
if (facts.helm === false)
|
|
2314
|
+
usage.withoutHelm++;
|
|
2315
|
+
if (facts.location === "local")
|
|
2316
|
+
usage.onLocal++;
|
|
2317
|
+
if (facts.location === "wharf")
|
|
2318
|
+
usage.onWharf++;
|
|
2192
2319
|
const worker = sanitizeWorker(facts.worker);
|
|
2193
2320
|
if (facts.trap) {
|
|
2194
2321
|
store.utc.perTrap[facts.trap] = (store.utc.perTrap[facts.trap] ?? 0) + 1;
|
|
@@ -2206,7 +2333,7 @@ function add(store, facts, now2) {
|
|
|
2206
2333
|
}
|
|
2207
2334
|
function backfillSources() {
|
|
2208
2335
|
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:
|
|
2336
|
+
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
2337
|
return [...live, ...backups];
|
|
2211
2338
|
}
|
|
2212
2339
|
function backfillStats(now2 = Date.now(), alreadyCounted) {
|
|
@@ -2278,87 +2405,242 @@ function parseStore(text) {
|
|
|
2278
2405
|
var complete2 = (s) => !!s && s.daily !== void 0;
|
|
2279
2406
|
function writeStore(store) {
|
|
2280
2407
|
const file2 = statsPath();
|
|
2281
|
-
|
|
2408
|
+
fs20.mkdirSync(path17.dirname(file2), { recursive: true });
|
|
2409
|
+
const tmp = uniqueTempPath(file2);
|
|
2410
|
+
fs20.writeFileSync(tmp, JSON.stringify(store));
|
|
2411
|
+
atomicRenameSync(tmp, file2);
|
|
2412
|
+
}
|
|
2413
|
+
function withStatsLock(action) {
|
|
2414
|
+
fs20.mkdirSync(lobstahHome(), { recursive: true });
|
|
2415
|
+
const lock = `${statsPath()}.lock`;
|
|
2416
|
+
const deadline = Date.now() + 1e4;
|
|
2417
|
+
for (; ; ) {
|
|
2418
|
+
try {
|
|
2419
|
+
fs20.mkdirSync(lock);
|
|
2420
|
+
break;
|
|
2421
|
+
} catch (err) {
|
|
2422
|
+
if (err.code !== "EEXIST")
|
|
2423
|
+
throw err;
|
|
2424
|
+
try {
|
|
2425
|
+
if (Date.now() - fs20.statSync(lock).mtimeMs > 12e4)
|
|
2426
|
+
fs20.rmdirSync(lock);
|
|
2427
|
+
} catch {
|
|
2428
|
+
}
|
|
2429
|
+
if (Date.now() >= deadline)
|
|
2430
|
+
throw new Error("stats store locked");
|
|
2431
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
try {
|
|
2435
|
+
return action();
|
|
2436
|
+
} finally {
|
|
2437
|
+
fs20.rmdirSync(lock);
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
function loadOrBackfill(now2) {
|
|
2441
|
+
let text;
|
|
2442
|
+
try {
|
|
2443
|
+
text = fs20.readFileSync(statsPath(), "utf8");
|
|
2444
|
+
} catch (err) {
|
|
2445
|
+
if (err.code !== "ENOENT")
|
|
2446
|
+
throw err;
|
|
2447
|
+
}
|
|
2448
|
+
const saved = text === void 0 ? void 0 : parseStore(text);
|
|
2449
|
+
if (complete2(saved) && saved.utc?.trapWorkers !== void 0 && saved.utc.byWorker !== void 0)
|
|
2450
|
+
return saved;
|
|
2451
|
+
if (saved) {
|
|
2452
|
+
const store2 = complete2(saved) ? saved : backfillDaily({ ...saved, daily: {} }, now2);
|
|
2453
|
+
if (!store2.utc) {
|
|
2454
|
+
store2.utc = backfillStats(now2, new Set(store2.counted)).utc;
|
|
2455
|
+
}
|
|
2456
|
+
if (store2.utc.trapWorkers === void 0 || store2.utc.byWorker === void 0) {
|
|
2457
|
+
const history = backfillStats(now2, new Set(store2.counted)).utc;
|
|
2458
|
+
if (history?.date === store2.utc.date) {
|
|
2459
|
+
store2.utc.trapWorkers ??= history.trapWorkers ?? {};
|
|
2460
|
+
store2.utc.byWorker ??= history.byWorker ?? [];
|
|
2461
|
+
} else {
|
|
2462
|
+
store2.utc.trapWorkers ??= {};
|
|
2463
|
+
store2.utc.byWorker ??= [];
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
writeStore(store2);
|
|
2467
|
+
return store2;
|
|
2468
|
+
}
|
|
2469
|
+
if (text !== void 0)
|
|
2470
|
+
fs20.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
|
|
2471
|
+
const store = backfillStats(now2);
|
|
2472
|
+
writeStore(store);
|
|
2473
|
+
return store;
|
|
2474
|
+
}
|
|
2475
|
+
function recordCatch(id, lane, now2 = Date.now()) {
|
|
2476
|
+
withStatsLock(() => {
|
|
2477
|
+
const store = loadOrBackfill(now2);
|
|
2478
|
+
if (store.counted.includes(id))
|
|
2479
|
+
return;
|
|
2480
|
+
const facts = readCatchFacts(laneDirs(lane).state, id);
|
|
2481
|
+
if (!facts.done)
|
|
2482
|
+
return;
|
|
2483
|
+
add(store, facts, now2);
|
|
2484
|
+
store.counted.push(id);
|
|
2485
|
+
writeStore(store);
|
|
2486
|
+
});
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2489
|
+
// packages/core/dist/status.js
|
|
2490
|
+
function isVerb(v) {
|
|
2491
|
+
return VERBS.includes(v);
|
|
2492
|
+
}
|
|
2493
|
+
function isWaitingOn(v) {
|
|
2494
|
+
return WAITING_ON.includes(v);
|
|
2495
|
+
}
|
|
2496
|
+
var DURATION = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/i;
|
|
2497
|
+
var UNIT_MS = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 };
|
|
2498
|
+
function parseUntil(v, now2 = Date.now()) {
|
|
2499
|
+
const d = DURATION.exec(v.trim());
|
|
2500
|
+
if (d)
|
|
2501
|
+
return new Date(now2 + Number(d[1]) * UNIT_MS[d[2].toLowerCase()]).toISOString();
|
|
2502
|
+
const t = Date.parse(v);
|
|
2503
|
+
if (Number.isNaN(t))
|
|
2504
|
+
throw new Error(`invalid --until "${v}" \u2014 an ISO time (2026-10-01T09:00Z) or a duration (30m, 4h, 2d)`);
|
|
2505
|
+
return new Date(t).toISOString();
|
|
2506
|
+
}
|
|
2507
|
+
function waitingFields(verb, w, now2 = Date.now()) {
|
|
2508
|
+
const out = {};
|
|
2509
|
+
if ((w.waitingOn !== void 0 || w.link !== void 0) && !WAITING_ON_VERBS.includes(verb)) {
|
|
2510
|
+
throw new Error(`--waiting-on and --link are valid only with ${WAITING_ON_VERBS.join(", ")} \u2014 not ${verb}`);
|
|
2511
|
+
}
|
|
2512
|
+
if (w.until !== void 0 && verb !== "paused")
|
|
2513
|
+
throw new Error(`--until is valid only with paused \u2014 not ${verb}`);
|
|
2514
|
+
if (w.waitingOn !== void 0) {
|
|
2515
|
+
if (!isWaitingOn(w.waitingOn)) {
|
|
2516
|
+
throw new Error(`invalid --waiting-on "${w.waitingOn}" \u2014 must be one of: ${WAITING_ON.join(", ")}`);
|
|
2517
|
+
}
|
|
2518
|
+
out.waitingOn = w.waitingOn;
|
|
2519
|
+
}
|
|
2520
|
+
if (w.link !== void 0) {
|
|
2521
|
+
let url;
|
|
2522
|
+
try {
|
|
2523
|
+
url = new URL(w.link);
|
|
2524
|
+
} catch {
|
|
2525
|
+
url = void 0;
|
|
2526
|
+
}
|
|
2527
|
+
if (!url || url.protocol !== "http:" && url.protocol !== "https:") {
|
|
2528
|
+
throw new Error(`invalid --link "${w.link}" \u2014 must be an http or https URL`);
|
|
2529
|
+
}
|
|
2530
|
+
out.link = url.href;
|
|
2531
|
+
}
|
|
2532
|
+
if (w.until !== void 0)
|
|
2533
|
+
out.until = parseUntil(w.until, now2);
|
|
2534
|
+
if (verb === "paused" && (out.waitingOn === "person" || out.waitingOn === "review" && out.link && !parsePrRef(out.link))) {
|
|
2535
|
+
throw new Error("Waiting on a human requires needs-decision: report needs-decision with the question or the thing to look at.");
|
|
2536
|
+
}
|
|
2537
|
+
return out;
|
|
2538
|
+
}
|
|
2539
|
+
function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
|
|
2540
|
+
if (!isVerb(verb)) {
|
|
2541
|
+
throw new Error(`invalid status verb "${verb}" \u2014 must be one of: ${VERBS.join(", ")}`);
|
|
2542
|
+
}
|
|
2543
|
+
const extra = waiting ? waitingFields(verb, waiting) : {};
|
|
2544
|
+
const entry = {
|
|
2545
|
+
at: at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
2546
|
+
verb,
|
|
2547
|
+
...note ? { note } : {},
|
|
2548
|
+
...extra,
|
|
2549
|
+
...reported ? { reported: true } : {}
|
|
2550
|
+
};
|
|
2551
|
+
if (verb === "done") {
|
|
2552
|
+
try {
|
|
2553
|
+
observeLocalCatch(id, lane, "finish");
|
|
2554
|
+
} catch {
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
fs21.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
|
|
2558
|
+
`);
|
|
2559
|
+
if (verb === "done") {
|
|
2560
|
+
try {
|
|
2561
|
+
recordCatch(id, lane);
|
|
2562
|
+
} catch {
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
return entry;
|
|
2566
|
+
}
|
|
2567
|
+
function readStatusLog(id, lane) {
|
|
2568
|
+
const file2 = statusPath(id, lane);
|
|
2569
|
+
if (!fs21.existsSync(file2))
|
|
2570
|
+
return [];
|
|
2571
|
+
return fs21.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
|
|
2572
|
+
try {
|
|
2573
|
+
const parsed = JSON.parse(line);
|
|
2574
|
+
return isVerb(parsed.verb) ? [parsed] : [];
|
|
2575
|
+
} catch {
|
|
2576
|
+
return [];
|
|
2577
|
+
}
|
|
2578
|
+
});
|
|
2579
|
+
}
|
|
2580
|
+
function pausedWaiting(entry) {
|
|
2581
|
+
return entry?.verb === "paused" && entry.waitingOn !== void 0;
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
// packages/core/dist/queue.js
|
|
2585
|
+
function requeue(id, lane) {
|
|
2586
|
+
const dirs = laneDirs(lane);
|
|
2587
|
+
const activeDir = path18.join(dirs.active, id);
|
|
2588
|
+
const file2 = path18.join(activeDir, "descriptor.json");
|
|
2589
|
+
const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2282
2590
|
const tmp = uniqueTempPath(file2);
|
|
2283
|
-
|
|
2591
|
+
fs22.writeFileSync(tmp, JSON.stringify(d, null, 2));
|
|
2284
2592
|
atomicRenameSync(tmp, file2);
|
|
2593
|
+
fs22.renameSync(file2, path18.join(dirs.queue, `${id}.json`));
|
|
2594
|
+
fs22.rmSync(activeDir, { recursive: true, force: true });
|
|
2285
2595
|
}
|
|
2286
|
-
function
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2596
|
+
function readDescriptor(id, lane) {
|
|
2597
|
+
const file2 = path18.join(laneDirs(lane).active, id, "descriptor.json");
|
|
2598
|
+
return JSON.parse(fs22.readFileSync(file2, "utf8"));
|
|
2599
|
+
}
|
|
2600
|
+
function storedDescriptor(id, lane) {
|
|
2601
|
+
const dirs = laneDirs(lane);
|
|
2602
|
+
for (const file2 of [
|
|
2603
|
+
path18.join(dirs.queue, `${id}.json`),
|
|
2604
|
+
path18.join(dirs.active, id, "descriptor.json"),
|
|
2605
|
+
path18.join(dirs.done, id, "descriptor.json")
|
|
2606
|
+
]) {
|
|
2291
2607
|
try {
|
|
2292
|
-
|
|
2293
|
-
|
|
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);
|
|
2608
|
+
return JSON.parse(fs22.readFileSync(file2, "utf8"));
|
|
2609
|
+
} catch {
|
|
2305
2610
|
}
|
|
2306
2611
|
}
|
|
2307
|
-
|
|
2308
|
-
return action();
|
|
2309
|
-
} finally {
|
|
2310
|
-
fs18.rmdirSync(lock);
|
|
2311
|
-
}
|
|
2612
|
+
return void 0;
|
|
2312
2613
|
}
|
|
2313
|
-
function
|
|
2314
|
-
|
|
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;
|
|
2614
|
+
function activeIds(lane) {
|
|
2615
|
+
return readDirIfPresent(laneDirs(lane).active).filter((f) => !f.startsWith("."));
|
|
2347
2616
|
}
|
|
2348
|
-
function
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2617
|
+
function complete(id, lane) {
|
|
2618
|
+
const dirs = laneDirs(lane);
|
|
2619
|
+
fs22.renameSync(path18.join(dirs.active, id), path18.join(dirs.done, id));
|
|
2620
|
+
}
|
|
2621
|
+
function cancelRequested(id, lane) {
|
|
2622
|
+
return fs22.existsSync(path18.join(laneDirs(lane).active, id, "cancel"));
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
// packages/core/dist/backend.js
|
|
2626
|
+
function parseBackendLocation(raw) {
|
|
2627
|
+
if (raw === void 0)
|
|
2628
|
+
return void 0;
|
|
2629
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
2630
|
+
throw new Error("backend must be a wharf configuration");
|
|
2631
|
+
const b = raw;
|
|
2632
|
+
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))
|
|
2633
|
+
throw new Error("backend requires kind=wharf, url, account and tokenEnv");
|
|
2634
|
+
const url = new URL(b.url);
|
|
2635
|
+
if (url.username || url.password || url.search || url.hash || url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))) {
|
|
2636
|
+
throw new Error("backend url must use HTTPS (HTTP is allowed only for loopback tests), without credentials");
|
|
2637
|
+
}
|
|
2638
|
+
return { kind: "wharf", url: b.url.replace(/\/$/, ""), account: b.account, tokenEnv: b.tokenEnv };
|
|
2360
2639
|
}
|
|
2361
2640
|
|
|
2641
|
+
// packages/core/dist/todos.js
|
|
2642
|
+
var CLOSED_KEEP_MS = 30 * 24 * 3600 * 1e3;
|
|
2643
|
+
|
|
2362
2644
|
// packages/core/dist/decisions.js
|
|
2363
2645
|
var DECISION_DETAIL_MAX = 64 * 1024;
|
|
2364
2646
|
var ANSWER_TYPES = {
|
|
@@ -2382,43 +2664,25 @@ var ANSWER_TYPES = {
|
|
|
2382
2664
|
};
|
|
2383
2665
|
var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
|
|
2384
2666
|
|
|
2385
|
-
// packages/core/dist/
|
|
2386
|
-
|
|
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
|
-
}
|
|
2667
|
+
// packages/core/dist/grants.js
|
|
2668
|
+
var ONCE_TTL_MS = 60 * 60 * 1e3;
|
|
2405
2669
|
|
|
2406
2670
|
// packages/core/dist/harness.js
|
|
2407
|
-
import * as
|
|
2408
|
-
import * as
|
|
2671
|
+
import * as fs23 from "node:fs";
|
|
2672
|
+
import * as path19 from "node:path";
|
|
2409
2673
|
import { createRequire } from "node:module";
|
|
2410
2674
|
function resolveOnPath(bin, pathVar = process.env.PATH) {
|
|
2411
2675
|
if (!pathVar)
|
|
2412
2676
|
return void 0;
|
|
2413
2677
|
const names = process.platform === "win32" ? [bin, `${bin}.exe`, `${bin}.cmd`, `${bin}.bat`] : [bin];
|
|
2414
|
-
for (const dir of pathVar.split(
|
|
2678
|
+
for (const dir of pathVar.split(path19.delimiter)) {
|
|
2415
2679
|
if (!dir)
|
|
2416
2680
|
continue;
|
|
2417
2681
|
for (const name of names) {
|
|
2418
|
-
const candidate =
|
|
2682
|
+
const candidate = path19.join(dir, name);
|
|
2419
2683
|
try {
|
|
2420
|
-
|
|
2421
|
-
if (
|
|
2684
|
+
fs23.accessSync(candidate, fs23.constants.X_OK);
|
|
2685
|
+
if (fs23.statSync(candidate).isFile())
|
|
2422
2686
|
return candidate;
|
|
2423
2687
|
} catch {
|
|
2424
2688
|
}
|
|
@@ -2439,8 +2703,8 @@ function codexInvocation(argv) {
|
|
|
2439
2703
|
} catch {
|
|
2440
2704
|
}
|
|
2441
2705
|
for (const dir of require_.resolve.paths("@openai/codex") ?? []) {
|
|
2442
|
-
const cli =
|
|
2443
|
-
if (
|
|
2706
|
+
const cli = path19.join(dir, "@openai", "codex", "bin", "codex.js");
|
|
2707
|
+
if (fs23.existsSync(cli))
|
|
2444
2708
|
return { file: process.execPath, argv: [cli, ...argv] };
|
|
2445
2709
|
}
|
|
2446
2710
|
return void 0;
|
|
@@ -2492,150 +2756,6 @@ function pushRule(branch, id = "<dispatch id>", mode = "rebase", also = []) {
|
|
|
2492
2756
|
].join(" ");
|
|
2493
2757
|
}
|
|
2494
2758
|
|
|
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
2759
|
// packages/core/dist/models.js
|
|
2640
2760
|
var MODEL_OWNERS = [
|
|
2641
2761
|
[/^(anthropic[/.])?(claude|opus|sonnet|haiku|fable)(\b|-|$)|^opusplan$/i, "claude"],
|
|
@@ -2657,8 +2777,8 @@ function droppedModelNote(harness, dropped) {
|
|
|
2657
2777
|
}
|
|
2658
2778
|
|
|
2659
2779
|
// packages/runner/src/run.ts
|
|
2660
|
-
import * as
|
|
2661
|
-
import * as
|
|
2780
|
+
import * as fs28 from "node:fs";
|
|
2781
|
+
import * as path24 from "node:path";
|
|
2662
2782
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
2663
2783
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
2664
2784
|
|
|
@@ -2954,25 +3074,25 @@ function createClaudeAdapter() {
|
|
|
2954
3074
|
}
|
|
2955
3075
|
|
|
2956
3076
|
// packages/adapters/dist/codex.js
|
|
2957
|
-
import * as
|
|
3077
|
+
import * as fs24 from "node:fs";
|
|
2958
3078
|
import * as os4 from "node:os";
|
|
2959
|
-
import * as
|
|
3079
|
+
import * as path20 from "node:path";
|
|
2960
3080
|
import { spawn as spawn2 } from "node:child_process";
|
|
2961
3081
|
function isolatedCodexHome() {
|
|
2962
|
-
const dir =
|
|
2963
|
-
|
|
2964
|
-
const auth =
|
|
2965
|
-
const realAuth =
|
|
2966
|
-
if (!
|
|
3082
|
+
const dir = path20.join(lobstahHome(), "codex-home");
|
|
3083
|
+
fs24.mkdirSync(dir, { recursive: true });
|
|
3084
|
+
const auth = path20.join(dir, "auth.json");
|
|
3085
|
+
const realAuth = path20.join(os4.homedir(), ".codex", "auth.json");
|
|
3086
|
+
if (!fs24.existsSync(auth) && fs24.existsSync(realAuth)) {
|
|
2967
3087
|
try {
|
|
2968
|
-
|
|
3088
|
+
fs24.symlinkSync(realAuth, auth);
|
|
2969
3089
|
} catch {
|
|
2970
|
-
|
|
3090
|
+
fs24.copyFileSync(realAuth, auth);
|
|
2971
3091
|
}
|
|
2972
3092
|
}
|
|
2973
|
-
const cfg =
|
|
2974
|
-
if (!
|
|
2975
|
-
|
|
3093
|
+
const cfg = path20.join(dir, "config.toml");
|
|
3094
|
+
if (!fs24.existsSync(cfg)) {
|
|
3095
|
+
fs24.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
|
|
2976
3096
|
}
|
|
2977
3097
|
return dir;
|
|
2978
3098
|
}
|
|
@@ -3175,15 +3295,15 @@ function loadAdapter(name) {
|
|
|
3175
3295
|
}
|
|
3176
3296
|
|
|
3177
3297
|
// packages/worktree/dist/index.js
|
|
3178
|
-
import * as
|
|
3179
|
-
import * as
|
|
3298
|
+
import * as fs26 from "node:fs";
|
|
3299
|
+
import * as path22 from "node:path";
|
|
3180
3300
|
import { createHash } from "node:crypto";
|
|
3181
3301
|
import { exec, execFile as execFile2, execFileSync } from "node:child_process";
|
|
3182
3302
|
import { promisify as promisify2 } from "node:util";
|
|
3183
3303
|
|
|
3184
3304
|
// packages/worktree/dist/pool.js
|
|
3185
|
-
import * as
|
|
3186
|
-
import * as
|
|
3305
|
+
import * as fs25 from "node:fs";
|
|
3306
|
+
import * as path21 from "node:path";
|
|
3187
3307
|
import { execFile } from "node:child_process";
|
|
3188
3308
|
import { promisify } from "node:util";
|
|
3189
3309
|
var run = promisify(execFile);
|
|
@@ -3245,17 +3365,17 @@ function takeOut(name, pool, slot, reason, dispatch, notice = true) {
|
|
|
3245
3365
|
function trapIn(dir) {
|
|
3246
3366
|
const real = (p) => {
|
|
3247
3367
|
try {
|
|
3248
|
-
return
|
|
3368
|
+
return fs25.realpathSync.native(p);
|
|
3249
3369
|
} catch {
|
|
3250
|
-
return
|
|
3370
|
+
return path21.resolve(p);
|
|
3251
3371
|
}
|
|
3252
3372
|
};
|
|
3253
3373
|
const here = real(dir);
|
|
3254
3374
|
return listTraps().some((t) => {
|
|
3255
3375
|
if (typeof t.worktree !== "string")
|
|
3256
3376
|
return false;
|
|
3257
|
-
const rel =
|
|
3258
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
3377
|
+
const rel = path21.relative(here, real(t.worktree));
|
|
3378
|
+
return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
3259
3379
|
});
|
|
3260
3380
|
}
|
|
3261
3381
|
async function claimPoolSlot(input) {
|
|
@@ -3263,7 +3383,7 @@ async function claimPoolSlot(input) {
|
|
|
3263
3383
|
const refused = [];
|
|
3264
3384
|
for (let slot = 1; slot <= pool.size; slot++) {
|
|
3265
3385
|
const dir = poolSlotPath(name, slot);
|
|
3266
|
-
if (
|
|
3386
|
+
if (fs25.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
|
|
3267
3387
|
writeSlotClaim(name, slot, { id, lane, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3268
3388
|
return { claimed: true, dir, slot, label: poolSlotLabel(name, slot) };
|
|
3269
3389
|
}
|
|
@@ -3311,7 +3431,7 @@ async function resetPoolWorktree(repo, dir, id, fromRemoteBranch = repo.trunk) {
|
|
|
3311
3431
|
}
|
|
3312
3432
|
var WARM_ID = "pool-warm";
|
|
3313
3433
|
async function createSlot(repo, dir) {
|
|
3314
|
-
|
|
3434
|
+
fs25.mkdirSync(path21.dirname(dir), { recursive: true });
|
|
3315
3435
|
await oneAtATime(repo.path, async () => {
|
|
3316
3436
|
await tryGit(repo.path, "worktree", "prune");
|
|
3317
3437
|
await gitShared(repo.path, "worktree", "add", "--detach", dir, `origin/${repo.trunk}`);
|
|
@@ -3333,7 +3453,7 @@ async function warmPool(name, opts = {}) {
|
|
|
3333
3453
|
if (!release)
|
|
3334
3454
|
return false;
|
|
3335
3455
|
try {
|
|
3336
|
-
if (!
|
|
3456
|
+
if (!fs25.existsSync(repo.path)) {
|
|
3337
3457
|
if (!repo.origin)
|
|
3338
3458
|
throw new Error(`repo path ${repo.path} missing and no origin configured`);
|
|
3339
3459
|
await run("git", ["clone", repo.origin, repo.path], { env: process.env });
|
|
@@ -3346,8 +3466,8 @@ async function warmPool(name, opts = {}) {
|
|
|
3346
3466
|
const dir = poolSlotPath(name, slot);
|
|
3347
3467
|
const label = poolSlotLabel(name, slot);
|
|
3348
3468
|
const meta = readSlotMeta(name, slot);
|
|
3349
|
-
if (!
|
|
3350
|
-
|
|
3469
|
+
if (!fs25.existsSync(dir)) {
|
|
3470
|
+
fs25.mkdirSync(poolsRoot(), { recursive: true });
|
|
3351
3471
|
let free = Infinity;
|
|
3352
3472
|
try {
|
|
3353
3473
|
free = need > 0 ? read2(poolsRoot()) : Infinity;
|
|
@@ -3490,7 +3610,7 @@ function pidAlive2(pid) {
|
|
|
3490
3610
|
var BUSY = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
3491
3611
|
function takeRepoLock(file2, mine) {
|
|
3492
3612
|
try {
|
|
3493
|
-
|
|
3613
|
+
fs26.writeFileSync(file2, mine, { flag: "wx" });
|
|
3494
3614
|
return { state: "held" };
|
|
3495
3615
|
} catch (err) {
|
|
3496
3616
|
const code = err.code ?? "";
|
|
@@ -3500,8 +3620,8 @@ function takeRepoLock(file2, mine) {
|
|
|
3500
3620
|
let raw = "";
|
|
3501
3621
|
let age = 0;
|
|
3502
3622
|
try {
|
|
3503
|
-
raw =
|
|
3504
|
-
age = Date.now() -
|
|
3623
|
+
raw = fs26.readFileSync(file2, "utf8");
|
|
3624
|
+
age = Date.now() - fs26.statSync(file2).mtimeMs;
|
|
3505
3625
|
} catch {
|
|
3506
3626
|
return { state: "retry" };
|
|
3507
3627
|
}
|
|
@@ -3514,8 +3634,8 @@ function takeRepoLock(file2, mine) {
|
|
|
3514
3634
|
const stale = age > REPO_LOCK_WAIT_MS || (holder ? !pidAlive2(holder.pid) : age > 5e3);
|
|
3515
3635
|
if (stale) {
|
|
3516
3636
|
try {
|
|
3517
|
-
if (
|
|
3518
|
-
|
|
3637
|
+
if (fs26.readFileSync(file2, "utf8") === raw)
|
|
3638
|
+
fs26.rmSync(file2, { force: true });
|
|
3519
3639
|
} catch {
|
|
3520
3640
|
}
|
|
3521
3641
|
return { state: "retry" };
|
|
@@ -3524,13 +3644,13 @@ function takeRepoLock(file2, mine) {
|
|
|
3524
3644
|
}
|
|
3525
3645
|
function releaseRepoLock(file2, mine) {
|
|
3526
3646
|
try {
|
|
3527
|
-
if (
|
|
3528
|
-
|
|
3647
|
+
if (fs26.readFileSync(file2, "utf8") === mine)
|
|
3648
|
+
fs26.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
|
|
3529
3649
|
} catch {
|
|
3530
3650
|
}
|
|
3531
3651
|
}
|
|
3532
3652
|
async function withRepoLock(common, fn) {
|
|
3533
|
-
const file2 =
|
|
3653
|
+
const file2 = path22.join(common, "lobstah-git.lock");
|
|
3534
3654
|
const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3535
3655
|
const deadline = Date.now() + REPO_LOCK_WAIT_MS;
|
|
3536
3656
|
let held = false;
|
|
@@ -3566,7 +3686,7 @@ async function oneAtATime(cwd, fn) {
|
|
|
3566
3686
|
}
|
|
3567
3687
|
function fetchStamps(common) {
|
|
3568
3688
|
try {
|
|
3569
|
-
return JSON.parse(
|
|
3689
|
+
return JSON.parse(fs26.readFileSync(path22.join(common, "lobstah-fetch.json"), "utf8"));
|
|
3570
3690
|
} catch {
|
|
3571
3691
|
return {};
|
|
3572
3692
|
}
|
|
@@ -3580,15 +3700,15 @@ async function fetchShared(cwd, remote, ref) {
|
|
|
3580
3700
|
const started = Date.now();
|
|
3581
3701
|
await gitShared(cwd, "fetch", remote, ref);
|
|
3582
3702
|
const stamps = { ...fetchStamps(common), [key]: started };
|
|
3583
|
-
|
|
3703
|
+
fs26.writeFileSync(path22.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
|
|
3584
3704
|
});
|
|
3585
3705
|
}
|
|
3586
3706
|
async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
|
|
3587
3707
|
const dir = worktreePath(id);
|
|
3588
|
-
if (
|
|
3708
|
+
if (fs26.existsSync(dir)) {
|
|
3589
3709
|
throw new Error(`worktree for ${id} already exists at ${dir} \u2014 never allocate a second`);
|
|
3590
3710
|
}
|
|
3591
|
-
if (!
|
|
3711
|
+
if (!fs26.existsSync(repo.path)) {
|
|
3592
3712
|
if (!repo.origin)
|
|
3593
3713
|
throw new Error(`repo path ${repo.path} missing and no origin configured`);
|
|
3594
3714
|
await run2("git", ["clone", repo.origin, repo.path], { env: process.env });
|
|
@@ -3603,7 +3723,7 @@ async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
|
|
|
3603
3723
|
async function recoverWorktree(repo, id) {
|
|
3604
3724
|
const dir = worktreePath(id);
|
|
3605
3725
|
try {
|
|
3606
|
-
if (
|
|
3726
|
+
if (fs26.statSync(path22.join(dir, ".git")).isFile()) {
|
|
3607
3727
|
const branch = await git(dir, "symbolic-ref", "--quiet", "HEAD");
|
|
3608
3728
|
const root = await git(dir, "rev-parse", "--show-toplevel");
|
|
3609
3729
|
const common = await git(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
@@ -3641,27 +3761,27 @@ function setupHash(repo, dir) {
|
|
|
3641
3761
|
const h = createHash("sha256");
|
|
3642
3762
|
h.update(JSON.stringify(repo.setup ?? []));
|
|
3643
3763
|
for (const name of LOCKFILES) {
|
|
3644
|
-
const file2 =
|
|
3645
|
-
if (!
|
|
3764
|
+
const file2 = path22.join(dir, name);
|
|
3765
|
+
if (!fs26.existsSync(file2))
|
|
3646
3766
|
continue;
|
|
3647
3767
|
h.update(`\0${name}\0`);
|
|
3648
|
-
h.update(
|
|
3768
|
+
h.update(fs26.readFileSync(file2));
|
|
3649
3769
|
}
|
|
3650
3770
|
return h.digest("hex");
|
|
3651
3771
|
}
|
|
3652
3772
|
function setupRecordFile(dir) {
|
|
3653
3773
|
const gitDir = worktreeGitDir(dir);
|
|
3654
|
-
return gitDir ?
|
|
3774
|
+
return gitDir ? path22.join(gitDir, "lobstah-setup.json") : void 0;
|
|
3655
3775
|
}
|
|
3656
3776
|
function recordSetup(repo, dir) {
|
|
3657
3777
|
const file2 = setupRecordFile(dir);
|
|
3658
3778
|
if (file2)
|
|
3659
|
-
|
|
3779
|
+
fs26.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
|
|
3660
3780
|
}
|
|
3661
3781
|
function recordedSetupHash(dir) {
|
|
3662
3782
|
const file2 = setupRecordFile(dir);
|
|
3663
3783
|
try {
|
|
3664
|
-
return file2 ? JSON.parse(
|
|
3784
|
+
return file2 ? JSON.parse(fs26.readFileSync(file2, "utf8")).hash : void 0;
|
|
3665
3785
|
} catch {
|
|
3666
3786
|
return void 0;
|
|
3667
3787
|
}
|
|
@@ -3674,9 +3794,9 @@ function poolReused(slot, by) {
|
|
|
3674
3794
|
function realpath(p) {
|
|
3675
3795
|
let r;
|
|
3676
3796
|
try {
|
|
3677
|
-
r =
|
|
3797
|
+
r = fs26.realpathSync.native(p);
|
|
3678
3798
|
} catch {
|
|
3679
|
-
r =
|
|
3799
|
+
r = path22.resolve(p);
|
|
3680
3800
|
}
|
|
3681
3801
|
return process.platform === "win32" ? r.toLowerCase() : r;
|
|
3682
3802
|
}
|
|
@@ -3724,8 +3844,8 @@ async function chooseWorktree(input) {
|
|
|
3724
3844
|
for (const t of listTraps()) {
|
|
3725
3845
|
if (typeof t.worktree !== "string")
|
|
3726
3846
|
continue;
|
|
3727
|
-
const rel =
|
|
3728
|
-
if (!rel.startsWith("..") && !
|
|
3847
|
+
const rel = path22.relative(here, realpath(t.worktree));
|
|
3848
|
+
if (!rel.startsWith("..") && !path22.isAbsolute(rel))
|
|
3729
3849
|
return { reuse: false, reason: "origin worktree is a trap\u2019s" };
|
|
3730
3850
|
}
|
|
3731
3851
|
for (const l of ["work", "chore"]) {
|
|
@@ -4153,8 +4273,8 @@ function startWallClock(opts) {
|
|
|
4153
4273
|
import { execFile as execFile3 } from "node:child_process";
|
|
4154
4274
|
import { promisify as promisify3 } from "node:util";
|
|
4155
4275
|
import { fileURLToPath } from "node:url";
|
|
4156
|
-
import * as
|
|
4157
|
-
import * as
|
|
4276
|
+
import * as fs27 from "node:fs";
|
|
4277
|
+
import * as path23 from "node:path";
|
|
4158
4278
|
var exec2 = promisify3(execFile3);
|
|
4159
4279
|
function firstLine(err) {
|
|
4160
4280
|
const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr).trim() : "";
|
|
@@ -4184,10 +4304,10 @@ function keepRemote(opts) {
|
|
|
4184
4304
|
const note = (message) => mergeEvidence(id, lane, { note: message.slice(0, 300) });
|
|
4185
4305
|
if (existingPrUrl) mergeEvidence(id, lane, { prUrl: existingPrUrl });
|
|
4186
4306
|
const registerWatch = async (url) => {
|
|
4187
|
-
const root =
|
|
4188
|
-
const localCli =
|
|
4307
|
+
const root = path23.resolve(path23.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
4308
|
+
const localCli = path23.join(root, "apps", "cli", "dist", "main.js");
|
|
4189
4309
|
const args = ["watch", "add", url, "--for", id];
|
|
4190
|
-
if (
|
|
4310
|
+
if (fs27.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
|
|
4191
4311
|
else await command("lobstah", args, 15e3);
|
|
4192
4312
|
};
|
|
4193
4313
|
let lastSeenHead;
|
|
@@ -4368,16 +4488,16 @@ function coldNote(cold, cwd, trunk) {
|
|
|
4368
4488
|
}
|
|
4369
4489
|
async function main(activeDir, lane, seams = {}) {
|
|
4370
4490
|
const deps = { ...defaultDeps, ...seams };
|
|
4371
|
-
const id =
|
|
4491
|
+
const id = path24.basename(activeDir);
|
|
4372
4492
|
if (isTrapCatch(id, lane)) throw new Error(`refusing headless runner for trap catch ${id}`);
|
|
4373
4493
|
const status = (verb, note) => appendStatus(id, lane, verb, note);
|
|
4374
4494
|
const cfg = loadConfig();
|
|
4375
|
-
const descriptor = JSON.parse(
|
|
4495
|
+
const descriptor = JSON.parse(fs28.readFileSync(path24.join(activeDir, "descriptor.json"), "utf8"));
|
|
4376
4496
|
const resolved = resolveDispatch(descriptor, cfg);
|
|
4377
4497
|
const repo = cfg.repos[descriptor.repo];
|
|
4378
|
-
const briefFile =
|
|
4379
|
-
if (!
|
|
4380
|
-
const brief =
|
|
4498
|
+
const briefFile = path24.join(activeDir, "brief.md");
|
|
4499
|
+
if (!fs28.existsSync(briefFile)) fs28.writeFileSync(briefFile, descriptor.brief);
|
|
4500
|
+
const brief = fs28.readFileSync(briefFile, "utf8");
|
|
4381
4501
|
const attempts = Number(process.env.LOBSTAH_ATTEMPTS ?? "1");
|
|
4382
4502
|
const wake = process.env.LOBSTAH_WAKE;
|
|
4383
4503
|
const runnerInfo = {
|
|
@@ -4385,7 +4505,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4385
4505
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4386
4506
|
attempts
|
|
4387
4507
|
};
|
|
4388
|
-
|
|
4508
|
+
fs28.writeFileSync(path24.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
|
|
4389
4509
|
if (descriptor.systemRepair && descriptor.pr?.url) {
|
|
4390
4510
|
const state = deps.prState(descriptor.pr.url) ?? readPr(parsePrRef(descriptor.pr.url)?.key ?? "")?.state;
|
|
4391
4511
|
if (state === "MERGED" || state === "CLOSED") {
|
|
@@ -4402,14 +4522,14 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4402
4522
|
resolvedHarness: resolved.harness,
|
|
4403
4523
|
envResume: process.env.LOBSTAH_RESUME
|
|
4404
4524
|
});
|
|
4405
|
-
const wtFile =
|
|
4525
|
+
const wtFile = path24.join(activeDir, "worktree.json");
|
|
4406
4526
|
let recorded;
|
|
4407
4527
|
let recovered = false;
|
|
4408
4528
|
let choice3;
|
|
4409
|
-
if (
|
|
4410
|
-
recorded = JSON.parse(
|
|
4411
|
-
if (!
|
|
4412
|
-
} else if (
|
|
4529
|
+
if (fs28.existsSync(wtFile)) {
|
|
4530
|
+
recorded = JSON.parse(fs28.readFileSync(wtFile, "utf8")).path;
|
|
4531
|
+
if (!fs28.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
|
|
4532
|
+
} else if (fs28.existsSync(worktreePath(id))) {
|
|
4413
4533
|
recorded = await recoverWorktree(repo, id);
|
|
4414
4534
|
recovered = true;
|
|
4415
4535
|
} else if (descriptor.followUp && cfg.limits.reuseWorktree !== false) {
|
|
@@ -4464,7 +4584,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4464
4584
|
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
4585
|
if (recovered) {
|
|
4466
4586
|
await deps.prepareReuse(repo, cwd);
|
|
4467
|
-
|
|
4587
|
+
fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
|
|
4468
4588
|
}
|
|
4469
4589
|
} else if (choice3?.reuse) {
|
|
4470
4590
|
cwd = choice3.path;
|
|
@@ -4475,17 +4595,17 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4475
4595
|
type: "runner",
|
|
4476
4596
|
data: { worktree: cwd, worktreeOf: choice3.owner, setupRan }
|
|
4477
4597
|
});
|
|
4478
|
-
|
|
4598
|
+
fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
|
|
4479
4599
|
} else if (poolClaim) {
|
|
4480
4600
|
cwd = poolClaim.dir;
|
|
4481
4601
|
await deps.resetPool(repo, cwd, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
|
|
4482
|
-
|
|
4602
|
+
fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
|
|
4483
4603
|
} else {
|
|
4484
4604
|
cwd = await deps.allocate(repo, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
|
|
4485
4605
|
acquireWorktreeLock(cwd, id, lane);
|
|
4486
|
-
|
|
4606
|
+
fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
|
|
4487
4607
|
}
|
|
4488
|
-
const worktreeOf = JSON.parse(
|
|
4608
|
+
const worktreeOf = JSON.parse(fs28.readFileSync(wtFile, "utf8")).of;
|
|
4489
4609
|
const inPool = poolSlotOf(cwd);
|
|
4490
4610
|
mergeEvidence(id, lane, { worktree: cwd, worktreeOf, ...inPool ? { pool: poolSlotLabel(inPool.pool, inPool.slot) } : {} });
|
|
4491
4611
|
const existingPr = boundPr(descriptor, lane);
|
|
@@ -4517,14 +4637,14 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4517
4637
|
const envNudge = [process.env.LOBSTAH_NUDGE, wakeNote()].filter(Boolean).join("\n\n") || void 0;
|
|
4518
4638
|
const planNudge = plan.cold && !envNudge ? coldNote(plan.cold, cwd, repo.trunk) : void 0;
|
|
4519
4639
|
const promptWith = (nudge) => buildPrompt(brief, { id, nudge, attachments: descriptor.attachments, existingPr });
|
|
4520
|
-
const binDir =
|
|
4521
|
-
const workerPath =
|
|
4640
|
+
const binDir = path24.resolve(path24.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
|
|
4641
|
+
const workerPath = fs28.existsSync(path24.join(binDir, "lobstah")) ? `${binDir}${path24.delimiter}${process.env.PATH ?? ""}` : void 0;
|
|
4522
4642
|
let wallClockHit = false;
|
|
4523
4643
|
let current;
|
|
4524
|
-
const wallFile =
|
|
4644
|
+
const wallFile = path24.join(activeDir, "wallclock.json");
|
|
4525
4645
|
const wallState = (() => {
|
|
4526
4646
|
try {
|
|
4527
|
-
return JSON.parse(
|
|
4647
|
+
return JSON.parse(fs28.readFileSync(wallFile, "utf8"));
|
|
4528
4648
|
} catch {
|
|
4529
4649
|
return { elapsedMs: 0, windowMs: resolved.limits.wallClockSecs * 1e3 };
|
|
4530
4650
|
}
|
|
@@ -4543,8 +4663,8 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4543
4663
|
) * 1e3;
|
|
4544
4664
|
const persistWall = (elapsedMs, windowMs) => {
|
|
4545
4665
|
const tmp = uniqueTempPath(wallFile);
|
|
4546
|
-
|
|
4547
|
-
|
|
4666
|
+
fs28.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
|
|
4667
|
+
fs28.renameSync(tmp, wallFile);
|
|
4548
4668
|
};
|
|
4549
4669
|
const madeProgress = () => {
|
|
4550
4670
|
const activity = readActivity(id, lane);
|
|
@@ -4848,13 +4968,13 @@ async function reapStarted(root = process.pid, graceMs) {
|
|
|
4848
4968
|
var EXIT_LINGER_MS = 5e3;
|
|
4849
4969
|
function runRunner(activeDirArg2, laneArg2) {
|
|
4850
4970
|
const lane = laneArg2 === "chore" ? "chore" : "work";
|
|
4851
|
-
const id =
|
|
4971
|
+
const id = path25.basename(activeDirArg2);
|
|
4852
4972
|
main(activeDirArg2, lane, { reap: () => reapStarted(process.pid) }).catch((err) => {
|
|
4853
4973
|
try {
|
|
4854
4974
|
if (!isFinished(id, lane)) {
|
|
4855
4975
|
appendStatus(id, lane, "failed", String(err instanceof Error ? err.message : err).slice(0, 500));
|
|
4856
4976
|
}
|
|
4857
|
-
|
|
4977
|
+
fs29.renameSync(activeDirArg2, path25.join(laneDirs(lane).done, id));
|
|
4858
4978
|
} catch {
|
|
4859
4979
|
}
|
|
4860
4980
|
process.exitCode = 1;
|