lobstah 0.7.4 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -7
- package/dist/main.js +11517 -7879
- package/dist/runner.js +894 -693
- package/dist/wharf-trap-runner.js +12 -0
- package/docs/configuration.md +13 -1
- package/docs/man.md +1 -1
- package/docs/vocabulary.md +2 -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,18 +8,30 @@ 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";
|
|
17
17
|
import * as path from "node:path";
|
|
18
|
-
import
|
|
18
|
+
import fs from "node:fs";
|
|
19
19
|
import { randomUUID } from "node:crypto";
|
|
20
20
|
function uniqueTempPath(file2) {
|
|
21
21
|
return `${file2}.tmp-${process.pid}-${randomUUID()}`;
|
|
22
22
|
}
|
|
23
|
+
function atomicRenameSync(source, target, deadline = Date.now() + 1e4) {
|
|
24
|
+
for (; ; ) {
|
|
25
|
+
try {
|
|
26
|
+
fs.renameSync(source, target);
|
|
27
|
+
return;
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (!["EPERM", "EBUSY", "EACCES"].includes(err.code ?? "") || Date.now() >= deadline)
|
|
30
|
+
throw err;
|
|
31
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
23
35
|
function readDirIfPresent(dir) {
|
|
24
36
|
try {
|
|
25
37
|
return fs.readdirSync(dir);
|
|
@@ -62,106 +74,8 @@ function evidencePath(id, lane) {
|
|
|
62
74
|
return path.join(laneDirs(lane).state, `${id}.evidence`);
|
|
63
75
|
}
|
|
64
76
|
|
|
65
|
-
// packages/core/dist/worker-metadata.js
|
|
66
|
-
var WORKER_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"];
|
|
67
|
-
var WORKER_PERMISSIONS = ["default", "acceptEdits", "plan", "dontAsk", "bypassPermissions", "auto"];
|
|
68
|
-
function localModel(value) {
|
|
69
|
-
return typeof value === "string" && /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,127}$/.test(value) ? value : null;
|
|
70
|
-
}
|
|
71
|
-
function choice(value, values) {
|
|
72
|
-
return typeof value === "string" && values.includes(value) ? value : null;
|
|
73
|
-
}
|
|
74
|
-
function workerMetadata(input = {}) {
|
|
75
|
-
return {
|
|
76
|
-
harness: localModel(input.harness),
|
|
77
|
-
model: localModel(input.model),
|
|
78
|
-
config: { effort: choice(input.config?.effort, WORKER_EFFORTS), permissionMode: choice(input.config?.permissionMode, WORKER_PERMISSIONS) },
|
|
79
|
-
...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 } : {}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// packages/core/dist/worker-profile.js
|
|
84
|
-
var WORKER_HARNESSES = ["claude", "codex", "other"];
|
|
85
|
-
var WORKER_MODEL_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
86
|
-
var WORKER_MODELS = [
|
|
87
|
-
"other",
|
|
88
|
-
"opus",
|
|
89
|
-
"sonnet",
|
|
90
|
-
"haiku",
|
|
91
|
-
"fable",
|
|
92
|
-
"opusplan",
|
|
93
|
-
"claude-opus-4",
|
|
94
|
-
"claude-opus-4-1",
|
|
95
|
-
"claude-opus-4-5",
|
|
96
|
-
"claude-opus-4-6",
|
|
97
|
-
"claude-opus-5",
|
|
98
|
-
"claude-opus-5-5",
|
|
99
|
-
"claude-sonnet-4",
|
|
100
|
-
"claude-sonnet-4-5",
|
|
101
|
-
"claude-sonnet-4-6",
|
|
102
|
-
"claude-sonnet-5",
|
|
103
|
-
"claude-haiku-4-5",
|
|
104
|
-
"claude-opus-4-20250514",
|
|
105
|
-
"claude-sonnet-4-20250514",
|
|
106
|
-
"claude-sonnet-4-5-20250929",
|
|
107
|
-
"claude-haiku-4-5-20251001",
|
|
108
|
-
"claude-opus-4-1-20250805",
|
|
109
|
-
"claude-opus-4-5-20251101",
|
|
110
|
-
"gpt-5",
|
|
111
|
-
"gpt-5-codex",
|
|
112
|
-
"gpt-5.1",
|
|
113
|
-
"gpt-5.1-codex",
|
|
114
|
-
"gpt-5.1-codex-mini",
|
|
115
|
-
"gpt-5.1-codex-max",
|
|
116
|
-
"gpt-5.2",
|
|
117
|
-
"gpt-5.2-codex",
|
|
118
|
-
"gpt-5.3-codex",
|
|
119
|
-
"gpt-5.4",
|
|
120
|
-
"gpt-5.4-mini",
|
|
121
|
-
"gpt-5.5",
|
|
122
|
-
"gpt-5.6-sol",
|
|
123
|
-
"gpt-5.6-terra",
|
|
124
|
-
"gpt-5.6-luna",
|
|
125
|
-
"gpt-6",
|
|
126
|
-
"gpt-6-sol",
|
|
127
|
-
"gpt-6-astra",
|
|
128
|
-
"gpt-6-luna",
|
|
129
|
-
"gpt-6.1-sol",
|
|
130
|
-
"codex-mini-latest",
|
|
131
|
-
"o1",
|
|
132
|
-
"o3",
|
|
133
|
-
"o3-mini",
|
|
134
|
-
"o4-mini"
|
|
135
|
-
];
|
|
136
|
-
function choice2(value, choices) {
|
|
137
|
-
return typeof value === "string" && choices.includes(value) ? value : null;
|
|
138
|
-
}
|
|
139
|
-
function safeModel(value) {
|
|
140
|
-
if (value === void 0 || value === null || value === "")
|
|
141
|
-
return null;
|
|
142
|
-
return typeof value === "string" && WORKER_MODEL_RE.test(value) && WORKER_MODELS.includes(value) ? value : "other";
|
|
143
|
-
}
|
|
144
|
-
function workerProfile(input = {}) {
|
|
145
|
-
return {
|
|
146
|
-
harness: input.harness === void 0 || input.harness === null ? null : choice2(input.harness, WORKER_HARNESSES) ?? "other",
|
|
147
|
-
model: safeModel(input.model),
|
|
148
|
-
config: { effort: choice2(input.effort, WORKER_EFFORTS), permissionMode: choice2(input.permissionMode, WORKER_PERMISSIONS) }
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function sanitizeWorker(value) {
|
|
152
|
-
return workerProfile({ harness: value?.harness, model: value?.model, effort: value?.config?.effort, permissionMode: value?.config?.permissionMode });
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// packages/core/dist/soak.js
|
|
156
|
-
import * as fs16 from "node:fs";
|
|
157
|
-
import * as path13 from "node:path";
|
|
158
|
-
|
|
159
|
-
// packages/core/dist/queue.js
|
|
160
|
-
import * as fs4 from "node:fs";
|
|
161
|
-
import * as path3 from "node:path";
|
|
162
|
-
|
|
163
77
|
// packages/core/dist/status.js
|
|
164
|
-
import * as
|
|
78
|
+
import * as fs21 from "node:fs";
|
|
165
79
|
|
|
166
80
|
// packages/core/dist/activity.js
|
|
167
81
|
import * as fs2 from "node:fs";
|
|
@@ -289,7 +203,7 @@ function activityFromEvent(ev, root) {
|
|
|
289
203
|
function atomicWrite(file2, content) {
|
|
290
204
|
const tmp = uniqueTempPath(file2);
|
|
291
205
|
fs2.writeFileSync(tmp, content);
|
|
292
|
-
|
|
206
|
+
atomicRenameSync(tmp, file2);
|
|
293
207
|
}
|
|
294
208
|
function writeActivity(id, lane, a) {
|
|
295
209
|
const safe = { at: a.at, kind: a.kind, summary: redactSummary(a.summary) };
|
|
@@ -370,149 +284,129 @@ var ActivityTracker = class {
|
|
|
370
284
|
}
|
|
371
285
|
};
|
|
372
286
|
|
|
373
|
-
// packages/core/dist/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
function isWaitingOn(v) {
|
|
378
|
-
return WAITING_ON.includes(v);
|
|
379
|
-
}
|
|
380
|
-
var DURATION = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/i;
|
|
381
|
-
var UNIT_MS = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 };
|
|
382
|
-
function parseUntil(v, now2 = Date.now()) {
|
|
383
|
-
const d = DURATION.exec(v.trim());
|
|
384
|
-
if (d)
|
|
385
|
-
return new Date(now2 + Number(d[1]) * UNIT_MS[d[2].toLowerCase()]).toISOString();
|
|
386
|
-
const t = Date.parse(v);
|
|
387
|
-
if (Number.isNaN(t))
|
|
388
|
-
throw new Error(`invalid --until "${v}" \u2014 an ISO time (2026-10-01T09:00Z) or a duration (30m, 4h, 2d)`);
|
|
389
|
-
return new Date(t).toISOString();
|
|
390
|
-
}
|
|
391
|
-
function waitingFields(verb, w, now2 = Date.now()) {
|
|
392
|
-
const out = {};
|
|
393
|
-
if ((w.waitingOn !== void 0 || w.link !== void 0) && !WAITING_ON_VERBS.includes(verb)) {
|
|
394
|
-
throw new Error(`--waiting-on and --link are valid only with ${WAITING_ON_VERBS.join(", ")} \u2014 not ${verb}`);
|
|
395
|
-
}
|
|
396
|
-
if (w.until !== void 0 && verb !== "paused")
|
|
397
|
-
throw new Error(`--until is valid only with paused \u2014 not ${verb}`);
|
|
398
|
-
if (w.waitingOn !== void 0) {
|
|
399
|
-
if (!isWaitingOn(w.waitingOn)) {
|
|
400
|
-
throw new Error(`invalid --waiting-on "${w.waitingOn}" \u2014 must be one of: ${WAITING_ON.join(", ")}`);
|
|
401
|
-
}
|
|
402
|
-
out.waitingOn = w.waitingOn;
|
|
403
|
-
}
|
|
404
|
-
if (w.link !== void 0) {
|
|
405
|
-
let url;
|
|
406
|
-
try {
|
|
407
|
-
url = new URL(w.link);
|
|
408
|
-
} catch {
|
|
409
|
-
url = void 0;
|
|
410
|
-
}
|
|
411
|
-
if (!url || url.protocol !== "http:" && url.protocol !== "https:") {
|
|
412
|
-
throw new Error(`invalid --link "${w.link}" \u2014 must be an http or https URL`);
|
|
413
|
-
}
|
|
414
|
-
out.link = url.href;
|
|
415
|
-
}
|
|
416
|
-
if (w.until !== void 0)
|
|
417
|
-
out.until = parseUntil(w.until, now2);
|
|
418
|
-
return out;
|
|
419
|
-
}
|
|
420
|
-
function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
|
|
421
|
-
if (!isVerb(verb)) {
|
|
422
|
-
throw new Error(`invalid status verb "${verb}" \u2014 must be one of: ${VERBS.join(", ")}`);
|
|
423
|
-
}
|
|
424
|
-
const extra = waiting ? waitingFields(verb, waiting) : {};
|
|
425
|
-
const entry = {
|
|
426
|
-
at: at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
427
|
-
verb,
|
|
428
|
-
...note ? { note } : {},
|
|
429
|
-
...extra,
|
|
430
|
-
...reported ? { reported: true } : {}
|
|
431
|
-
};
|
|
432
|
-
fs3.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
|
|
433
|
-
`);
|
|
434
|
-
if (verb === "done") {
|
|
435
|
-
try {
|
|
436
|
-
recordCatch(id, lane);
|
|
437
|
-
} catch {
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return entry;
|
|
441
|
-
}
|
|
442
|
-
function readStatusLog(id, lane) {
|
|
443
|
-
const file2 = statusPath(id, lane);
|
|
444
|
-
if (!fs3.existsSync(file2))
|
|
445
|
-
return [];
|
|
446
|
-
return fs3.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
|
|
447
|
-
try {
|
|
448
|
-
const parsed = JSON.parse(line);
|
|
449
|
-
return isVerb(parsed.verb) ? [parsed] : [];
|
|
450
|
-
} catch {
|
|
451
|
-
return [];
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
function pausedWaiting(entry) {
|
|
456
|
-
return entry?.verb === "paused" && entry.waitingOn !== void 0;
|
|
457
|
-
}
|
|
287
|
+
// packages/core/dist/stats.js
|
|
288
|
+
import * as fs20 from "node:fs";
|
|
289
|
+
import * as path17 from "node:path";
|
|
458
290
|
|
|
459
|
-
// packages/core/dist/
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
fs4.rmSync(activeDir, { recursive: true, force: true });
|
|
465
|
-
}
|
|
466
|
-
function storedDescriptor(id, lane) {
|
|
467
|
-
const dirs = laneDirs(lane);
|
|
468
|
-
for (const file2 of [
|
|
469
|
-
path3.join(dirs.queue, `${id}.json`),
|
|
470
|
-
path3.join(dirs.active, id, "descriptor.json"),
|
|
471
|
-
path3.join(dirs.done, id, "descriptor.json")
|
|
472
|
-
]) {
|
|
473
|
-
try {
|
|
474
|
-
return JSON.parse(fs4.readFileSync(file2, "utf8"));
|
|
475
|
-
} catch {
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
return void 0;
|
|
479
|
-
}
|
|
480
|
-
function activeIds(lane) {
|
|
481
|
-
return readDirIfPresent(laneDirs(lane).active).filter((f) => !f.startsWith("."));
|
|
482
|
-
}
|
|
483
|
-
function complete(id, lane) {
|
|
484
|
-
const dirs = laneDirs(lane);
|
|
485
|
-
fs4.renameSync(path3.join(dirs.active, id), path3.join(dirs.done, id));
|
|
486
|
-
}
|
|
487
|
-
function cancelRequested(id, lane) {
|
|
488
|
-
return fs4.existsSync(path3.join(laneDirs(lane).active, id, "cancel"));
|
|
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;
|
|
489
296
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
import * as fs5 from "node:fs";
|
|
493
|
-
function readEvidence(id, lane) {
|
|
494
|
-
try {
|
|
495
|
-
return JSON.parse(fs5.readFileSync(evidencePath(id, lane), "utf8"));
|
|
496
|
-
} catch {
|
|
497
|
-
return {};
|
|
498
|
-
}
|
|
297
|
+
function choice(value, values) {
|
|
298
|
+
return typeof value === "string" && values.includes(value) ? value : null;
|
|
499
299
|
}
|
|
500
|
-
function
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
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
|
+
};
|
|
505
307
|
}
|
|
506
308
|
|
|
507
|
-
// packages/core/dist/
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
var
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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;
|
|
364
|
+
}
|
|
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) }
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function sanitizeWorker(value) {
|
|
378
|
+
return workerProfile({ harness: value?.harness, model: value?.model, effort: value?.config?.effort, permissionMode: value?.config?.permissionMode });
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// packages/core/dist/soak.js
|
|
382
|
+
import * as fs18 from "node:fs";
|
|
383
|
+
import * as path15 from "node:path";
|
|
384
|
+
|
|
385
|
+
// packages/core/dist/evidence.js
|
|
386
|
+
import * as fs3 from "node:fs";
|
|
387
|
+
function readEvidence(id, lane) {
|
|
388
|
+
try {
|
|
389
|
+
return JSON.parse(fs3.readFileSync(evidencePath(id, lane), "utf8"));
|
|
390
|
+
} catch {
|
|
391
|
+
return {};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function mergeEvidence(id, lane, patch) {
|
|
395
|
+
const file2 = evidencePath(id, lane);
|
|
396
|
+
const tmp = uniqueTempPath(file2);
|
|
397
|
+
fs3.writeFileSync(tmp, JSON.stringify({ ...readEvidence(id, lane), ...patch }, null, 2));
|
|
398
|
+
atomicRenameSync(tmp, file2);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// packages/core/dist/pushes.js
|
|
402
|
+
import * as fs4 from "node:fs";
|
|
403
|
+
import * as path3 from "node:path";
|
|
404
|
+
var MAX_PUSHES = 20;
|
|
405
|
+
var PUSH_HEAD = "HEAD";
|
|
406
|
+
var VALUE_OPTIONS = /* @__PURE__ */ new Set(["-o", "--push-option", "--repo", "--receive-pack", "--exec"]);
|
|
407
|
+
function words(segment) {
|
|
408
|
+
const out = [];
|
|
409
|
+
const re = /"((?:[^"\\]|\\.)*)"|'([^']*)'|(\S+)/g;
|
|
516
410
|
for (let m = re.exec(segment); m; m = re.exec(segment))
|
|
517
411
|
out.push(m[1] ?? m[2] ?? m[3] ?? "");
|
|
518
412
|
return out;
|
|
@@ -561,18 +455,18 @@ function gitPushTargets(command) {
|
|
|
561
455
|
return found ? [...new Set(targets)] : void 0;
|
|
562
456
|
}
|
|
563
457
|
function gitDirAt(dir) {
|
|
564
|
-
let at =
|
|
458
|
+
let at = path3.resolve(dir);
|
|
565
459
|
for (; ; ) {
|
|
566
|
-
const dotGit =
|
|
460
|
+
const dotGit = path3.join(at, ".git");
|
|
567
461
|
try {
|
|
568
|
-
const stat =
|
|
462
|
+
const stat = fs4.statSync(dotGit);
|
|
569
463
|
if (stat.isDirectory())
|
|
570
464
|
return dotGit;
|
|
571
|
-
const m = /^gitdir:\s*(.+)$/m.exec(
|
|
572
|
-
return m ?
|
|
465
|
+
const m = /^gitdir:\s*(.+)$/m.exec(fs4.readFileSync(dotGit, "utf8"));
|
|
466
|
+
return m ? path3.resolve(at, m[1].trim()) : void 0;
|
|
573
467
|
} catch {
|
|
574
468
|
}
|
|
575
|
-
const up =
|
|
469
|
+
const up = path3.dirname(at);
|
|
576
470
|
if (up === at)
|
|
577
471
|
return void 0;
|
|
578
472
|
at = up;
|
|
@@ -583,7 +477,7 @@ function currentBranchAt(dir) {
|
|
|
583
477
|
if (!gitDir)
|
|
584
478
|
return void 0;
|
|
585
479
|
try {
|
|
586
|
-
const m = /^ref:\s*refs\/heads\/(.+)$/m.exec(
|
|
480
|
+
const m = /^ref:\s*refs\/heads\/(.+)$/m.exec(fs4.readFileSync(path3.join(gitDir, "HEAD"), "utf8"));
|
|
587
481
|
return m ? m[1].trim() : void 0;
|
|
588
482
|
} catch {
|
|
589
483
|
return void 0;
|
|
@@ -602,13 +496,13 @@ function recordPush(id, lane, branches, at = (/* @__PURE__ */ new Date()).toISOS
|
|
|
602
496
|
}
|
|
603
497
|
|
|
604
498
|
// packages/core/dist/notices.js
|
|
605
|
-
import
|
|
606
|
-
import * as
|
|
499
|
+
import fs16 from "node:fs";
|
|
500
|
+
import * as path13 from "node:path";
|
|
607
501
|
|
|
608
502
|
// packages/core/dist/config.js
|
|
609
|
-
import * as
|
|
503
|
+
import * as fs5 from "node:fs";
|
|
610
504
|
import * as os2 from "node:os";
|
|
611
|
-
import * as
|
|
505
|
+
import * as path4 from "node:path";
|
|
612
506
|
|
|
613
507
|
// node_modules/.pnpm/smol-toml@1.8.0/node_modules/smol-toml/dist/date.js
|
|
614
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;
|
|
@@ -1255,6 +1149,30 @@ function parse(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
|
|
|
1255
1149
|
return res;
|
|
1256
1150
|
}
|
|
1257
1151
|
|
|
1152
|
+
// packages/core/dist/pr-review.js
|
|
1153
|
+
var REVIEW_PRESETS = {
|
|
1154
|
+
github: "https://github.com/{owner}/{repo}/pull/{number}",
|
|
1155
|
+
graphite: "https://app.graphite.com/github/pr/{owner}/{repo}/{number}",
|
|
1156
|
+
linear: "https://linear.review/{owner}/{repo}/pull/{number}",
|
|
1157
|
+
"linear-app": "linear://review/{owner}/{repo}/pull/{number}"
|
|
1158
|
+
};
|
|
1159
|
+
function validReviewTool(value) {
|
|
1160
|
+
if (typeof value !== "string")
|
|
1161
|
+
return false;
|
|
1162
|
+
if (Object.hasOwn(REVIEW_PRESETS, value))
|
|
1163
|
+
return true;
|
|
1164
|
+
if (value.length > 2048 || !["owner", "repo", "number"].every((key) => value.includes(`{${key}}`)))
|
|
1165
|
+
return false;
|
|
1166
|
+
if (/\{(?!owner\}|repo\}|number\})|[\s<>]/.test(value))
|
|
1167
|
+
return false;
|
|
1168
|
+
try {
|
|
1169
|
+
const url = new URL(value.replaceAll("{owner}", "owner").replaceAll("{repo}", "repo").replaceAll("{number}", "1"));
|
|
1170
|
+
return url.protocol === "https:" && !url.username && !url.password;
|
|
1171
|
+
} catch {
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1258
1176
|
// packages/core/dist/config.js
|
|
1259
1177
|
var POOL_NAME = /^[A-Za-z0-9_-]+$/;
|
|
1260
1178
|
function parsePools(raw, repos) {
|
|
@@ -1309,12 +1227,15 @@ function parseAttentionKinds(raw) {
|
|
|
1309
1227
|
}
|
|
1310
1228
|
function parseSoak(raw) {
|
|
1311
1229
|
const soak = { ...DEFAULT_SOAK, ...raw ?? {} };
|
|
1230
|
+
if (typeof soak.acceptWharfStarts !== "boolean")
|
|
1231
|
+
throw new Error("soak.acceptWharfStarts must be true or false");
|
|
1312
1232
|
if (soak.terminal !== void 0 && soak.terminal !== "terminal" && soak.terminal !== "iterm") {
|
|
1313
1233
|
throw new Error(`soak.terminal: unknown terminal "${String(soak.terminal)}" in ${configPath()} \u2014 use "terminal" or "iterm"`);
|
|
1314
1234
|
}
|
|
1315
1235
|
return soak;
|
|
1316
1236
|
}
|
|
1317
1237
|
var DEFAULT_SOAK = {
|
|
1238
|
+
acceptWharfStarts: false,
|
|
1318
1239
|
deferSecs: 90,
|
|
1319
1240
|
claimIdleNoticeSecs: 180,
|
|
1320
1241
|
ttlSecs: 1800,
|
|
@@ -1323,6 +1244,9 @@ var DEFAULT_SOAK = {
|
|
|
1323
1244
|
signOffGraceSecs: 600
|
|
1324
1245
|
};
|
|
1325
1246
|
var DEFAULT_HELM = {
|
|
1247
|
+
queuedNoticeSecs: 180,
|
|
1248
|
+
stalledNoticeSecs: 1200,
|
|
1249
|
+
idleWorkingNoticeSecs: 60,
|
|
1326
1250
|
ttlSecs: 1800,
|
|
1327
1251
|
reportSecs: 900,
|
|
1328
1252
|
armGraceSecs: 5
|
|
@@ -1348,15 +1272,24 @@ var DEFAULT_LIMITS = {
|
|
|
1348
1272
|
releaseOnMerge: false
|
|
1349
1273
|
};
|
|
1350
1274
|
function configPath() {
|
|
1351
|
-
return
|
|
1275
|
+
return path4.join(lobstahHome(), "config.toml");
|
|
1352
1276
|
}
|
|
1353
1277
|
function expandHome(p) {
|
|
1354
|
-
return p.startsWith("~/") ?
|
|
1278
|
+
return p.startsWith("~/") ? path4.join(os2.homedir(), p.slice(2)) : p;
|
|
1355
1279
|
}
|
|
1356
1280
|
function loadConfig() {
|
|
1357
1281
|
const file2 = configPath();
|
|
1358
|
-
const raw =
|
|
1282
|
+
const raw = fs5.existsSync(file2) ? parse(fs5.readFileSync(file2, "utf8")) : {};
|
|
1283
|
+
const petOpen = raw.pet?.open ?? "tab";
|
|
1284
|
+
if (!["tab", "app", "helm"].includes(petOpen))
|
|
1285
|
+
throw new Error(`[pet].open must be "tab", "app", or "helm" in ${configPath()}`);
|
|
1359
1286
|
const watch = { ...DEFAULT_WATCH, ...raw.watch ?? {} };
|
|
1287
|
+
const helm = { ...DEFAULT_HELM, ...raw.helm ?? {} };
|
|
1288
|
+
for (const key of ["queuedNoticeSecs", "stalledNoticeSecs", "idleWorkingNoticeSecs"]) {
|
|
1289
|
+
if (typeof helm[key] !== "number" || !Number.isFinite(helm[key]) || helm[key] < 0) {
|
|
1290
|
+
throw new Error(`[helm].${key} must be a non-negative number in ${configPath()}`);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1360
1293
|
if (typeof watch.repairCooldownSecs !== "number" || !Number.isFinite(watch.repairCooldownSecs) || watch.repairCooldownSecs < 0) {
|
|
1361
1294
|
throw new Error(`[watch].repairCooldownSecs must be a non-negative number in ${configPath()}`);
|
|
1362
1295
|
}
|
|
@@ -1367,8 +1300,15 @@ function loadConfig() {
|
|
|
1367
1300
|
const reposRaw = raw.repos ?? {};
|
|
1368
1301
|
const repos = {};
|
|
1369
1302
|
for (const [key, r] of Object.entries(reposRaw)) {
|
|
1303
|
+
if (r.traps !== void 0 && (typeof r.traps !== "number" || !Number.isSafeInteger(r.traps) || r.traps < 0)) {
|
|
1304
|
+
throw new Error(`[repos.${key}].traps must be a non-negative whole number`);
|
|
1305
|
+
}
|
|
1306
|
+
if (r.review !== void 0 && !validReviewTool(r.review))
|
|
1307
|
+
throw new Error(`[repos.${key}].review must be github, graphite, linear, linear-app, or an HTTPS template with {owner}, {repo}, {number}`);
|
|
1370
1308
|
repos[key] = {
|
|
1371
1309
|
path: expandHome(String(r.path ?? "")),
|
|
1310
|
+
...r.traps !== void 0 ? { traps: r.traps } : {},
|
|
1311
|
+
...r.review !== void 0 ? { review: r.review } : {},
|
|
1372
1312
|
origin: r.origin ? String(r.origin) : void 0,
|
|
1373
1313
|
trunk: String(r.trunk ?? "main"),
|
|
1374
1314
|
setup: Array.isArray(r.setup) ? r.setup.map(String) : void 0,
|
|
@@ -1385,19 +1325,29 @@ function loadConfig() {
|
|
|
1385
1325
|
};
|
|
1386
1326
|
}
|
|
1387
1327
|
const groundsRaw = raw.grounds ?? {};
|
|
1328
|
+
const wharves = {};
|
|
1329
|
+
for (const [name, value] of Object.entries(raw.wharves ?? {})) {
|
|
1330
|
+
if (!/^[A-Za-z0-9_-]{1,64}$/.test(name))
|
|
1331
|
+
throw new Error("invalid wharf name");
|
|
1332
|
+
wharves[name] = parseBackendLocation({ ...value, kind: "wharf" });
|
|
1333
|
+
}
|
|
1388
1334
|
const grounds = {};
|
|
1389
1335
|
for (const [key, g] of Object.entries(groundsRaw)) {
|
|
1390
|
-
|
|
1336
|
+
if (g.wharf !== void 0 && (typeof g.wharf !== "string" || !wharves[g.wharf]))
|
|
1337
|
+
throw new Error(`grounds ${key}: unknown wharf`);
|
|
1338
|
+
grounds[key] = { repos: Array.isArray(g.repos) ? g.repos.map(String) : [], ...g.wharf ? { wharf: String(g.wharf) } : {} };
|
|
1391
1339
|
}
|
|
1392
1340
|
return {
|
|
1393
1341
|
repos,
|
|
1394
1342
|
harness: raw.harness ?? {},
|
|
1395
1343
|
limits: { ...DEFAULT_LIMITS, ...raw.limits ?? {} },
|
|
1396
1344
|
soak: parseSoak(raw.soak),
|
|
1397
|
-
helm
|
|
1345
|
+
helm,
|
|
1398
1346
|
glass: { ...DEFAULT_GLASS, ...raw.glass ?? {} },
|
|
1347
|
+
pet: { open: petOpen },
|
|
1399
1348
|
watch,
|
|
1400
1349
|
grounds,
|
|
1350
|
+
wharves,
|
|
1401
1351
|
pools: parsePools(raw.pools, repos),
|
|
1402
1352
|
notifyCommand: raw.notifyCommand ? String(raw.notifyCommand) : void 0,
|
|
1403
1353
|
notifyVerbs: Array.isArray(raw.notifyVerbs) ? raw.notifyVerbs.map(String) : void 0,
|
|
@@ -1447,25 +1397,25 @@ function firstMeaningfulLine(...outputs) {
|
|
|
1447
1397
|
}
|
|
1448
1398
|
|
|
1449
1399
|
// packages/core/dist/pr-poll.js
|
|
1450
|
-
import * as
|
|
1451
|
-
import * as
|
|
1400
|
+
import * as fs9 from "node:fs";
|
|
1401
|
+
import * as path8 from "node:path";
|
|
1452
1402
|
|
|
1453
1403
|
// packages/core/dist/prs.js
|
|
1454
|
-
import * as
|
|
1455
|
-
import * as
|
|
1404
|
+
import * as fs6 from "node:fs";
|
|
1405
|
+
import * as path5 from "node:path";
|
|
1456
1406
|
function prsDir() {
|
|
1457
|
-
return
|
|
1407
|
+
return path5.join(lobstahHome(), "prs");
|
|
1458
1408
|
}
|
|
1459
1409
|
function prRecordFile(key) {
|
|
1460
1410
|
const ref = parsePrRef(key);
|
|
1461
1411
|
if (!ref)
|
|
1462
1412
|
throw new Error(`not a PR key: ${key}`);
|
|
1463
1413
|
const safe = (s) => s.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
1464
|
-
return
|
|
1414
|
+
return path5.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
|
|
1465
1415
|
}
|
|
1466
1416
|
function readPr(key) {
|
|
1467
1417
|
try {
|
|
1468
|
-
return JSON.parse(
|
|
1418
|
+
return JSON.parse(fs6.readFileSync(prRecordFile(key), "utf8"));
|
|
1469
1419
|
} catch {
|
|
1470
1420
|
return void 0;
|
|
1471
1421
|
}
|
|
@@ -1473,13 +1423,13 @@ function readPr(key) {
|
|
|
1473
1423
|
function readPrs() {
|
|
1474
1424
|
let files;
|
|
1475
1425
|
try {
|
|
1476
|
-
files =
|
|
1426
|
+
files = fs6.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
|
|
1477
1427
|
} catch {
|
|
1478
1428
|
return [];
|
|
1479
1429
|
}
|
|
1480
1430
|
return files.flatMap((f) => {
|
|
1481
1431
|
try {
|
|
1482
|
-
const r = JSON.parse(
|
|
1432
|
+
const r = JSON.parse(fs6.readFileSync(path5.join(prsDir(), f), "utf8"));
|
|
1483
1433
|
return typeof r.key === "string" && typeof r.url === "string" ? [r] : [];
|
|
1484
1434
|
} catch {
|
|
1485
1435
|
return [];
|
|
@@ -1488,16 +1438,16 @@ function readPrs() {
|
|
|
1488
1438
|
}
|
|
1489
1439
|
|
|
1490
1440
|
// packages/core/dist/watch.js
|
|
1491
|
-
import
|
|
1492
|
-
import * as
|
|
1441
|
+
import fs8 from "node:fs";
|
|
1442
|
+
import * as path7 from "node:path";
|
|
1493
1443
|
|
|
1494
1444
|
// packages/core/dist/github-budget.js
|
|
1495
|
-
import * as
|
|
1496
|
-
import * as
|
|
1497
|
-
var file = () =>
|
|
1445
|
+
import * as fs7 from "node:fs";
|
|
1446
|
+
import * as path6 from "node:path";
|
|
1447
|
+
var file = () => path6.join(lobstahHome(), "github-budget.json");
|
|
1498
1448
|
function read() {
|
|
1499
1449
|
try {
|
|
1500
|
-
return JSON.parse(
|
|
1450
|
+
return JSON.parse(fs7.readFileSync(file(), "utf8"));
|
|
1501
1451
|
} catch {
|
|
1502
1452
|
return { resources: {} };
|
|
1503
1453
|
}
|
|
@@ -1511,27 +1461,27 @@ function githubBlockedUntil(now2 = Date.now()) {
|
|
|
1511
1461
|
|
|
1512
1462
|
// packages/core/dist/watch.js
|
|
1513
1463
|
function watchesDir() {
|
|
1514
|
-
return
|
|
1464
|
+
return path7.join(lobstahHome(), "watches");
|
|
1515
1465
|
}
|
|
1516
1466
|
function slug(key) {
|
|
1517
1467
|
return key.replace(/[^A-Za-z0-9._-]+/g, "-");
|
|
1518
1468
|
}
|
|
1519
1469
|
function watchPath(key) {
|
|
1520
|
-
return
|
|
1470
|
+
return path7.join(watchesDir(), `${slug(key)}.json`);
|
|
1521
1471
|
}
|
|
1522
1472
|
function readWatch(key) {
|
|
1523
1473
|
try {
|
|
1524
|
-
return JSON.parse(
|
|
1474
|
+
return JSON.parse(fs8.readFileSync(watchPath(key), "utf8"));
|
|
1525
1475
|
} catch {
|
|
1526
1476
|
return void 0;
|
|
1527
1477
|
}
|
|
1528
1478
|
}
|
|
1529
1479
|
|
|
1530
1480
|
// packages/core/dist/pr-poll.js
|
|
1531
|
-
var cycleFile = (repo) =>
|
|
1481
|
+
var cycleFile = (repo) => path8.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
|
|
1532
1482
|
var readCycle = (repo) => {
|
|
1533
1483
|
try {
|
|
1534
|
-
return JSON.parse(
|
|
1484
|
+
return JSON.parse(fs9.readFileSync(cycleFile(repo), "utf8"));
|
|
1535
1485
|
} catch {
|
|
1536
1486
|
return void 0;
|
|
1537
1487
|
}
|
|
@@ -1623,71 +1573,24 @@ function parseUnresolvedThreads(stdout) {
|
|
|
1623
1573
|
}
|
|
1624
1574
|
}
|
|
1625
1575
|
|
|
1626
|
-
// packages/core/dist/notices.js
|
|
1627
|
-
function noticesDir() {
|
|
1628
|
-
return path10.join(lobstahHome(), "notices");
|
|
1629
|
-
}
|
|
1630
|
-
var counter = 0;
|
|
1631
|
-
function postNotice(n) {
|
|
1632
|
-
const dir = noticesDir();
|
|
1633
|
-
fs12.mkdirSync(dir, { recursive: true });
|
|
1634
|
-
if (n.dedupeKey) {
|
|
1635
|
-
const marker = path10.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
|
|
1636
|
-
try {
|
|
1637
|
-
fs12.writeFileSync(marker, "", { flag: "wx" });
|
|
1638
|
-
} catch {
|
|
1639
|
-
return void 0;
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
const seq = `${String(Date.now()).padStart(15, "0")}-${process.pid}-${String(counter++).padStart(8, "0")}`;
|
|
1643
|
-
const notice = {
|
|
1644
|
-
seq,
|
|
1645
|
-
kind: n.kind,
|
|
1646
|
-
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1647
|
-
text: n.text,
|
|
1648
|
-
refId: n.refId,
|
|
1649
|
-
...n.url ? { url: n.url } : {},
|
|
1650
|
-
repo: n.repo,
|
|
1651
|
-
by: n.by,
|
|
1652
|
-
...n.quiet ? { quiet: true } : {},
|
|
1653
|
-
...n.stateHash ? { stateHash: n.stateHash } : {}
|
|
1654
|
-
};
|
|
1655
|
-
const file2 = path10.join(dir, `${seq}.json`);
|
|
1656
|
-
const tmp = uniqueTempPath(file2);
|
|
1657
|
-
fs12.writeFileSync(tmp, JSON.stringify(notice, null, 2));
|
|
1658
|
-
fs12.renameSync(tmp, file2);
|
|
1659
|
-
return notice;
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
// packages/core/dist/attachments.js
|
|
1663
|
-
function attachmentBlock(attachments) {
|
|
1664
|
-
if (attachments.length === 0)
|
|
1665
|
-
return "";
|
|
1666
|
-
return [
|
|
1667
|
-
"--- ATTACHMENTS ---",
|
|
1668
|
-
...attachments.map((a) => `${a.name} (${a.type}, ${a.bytes} bytes) at ${a.path}`),
|
|
1669
|
-
"Images and PDFs can be read directly with your file tools."
|
|
1670
|
-
].join("\n");
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
1576
|
// packages/core/dist/worktrees.js
|
|
1674
|
-
import * as
|
|
1675
|
-
import * as
|
|
1577
|
+
import * as fs10 from "node:fs";
|
|
1578
|
+
import * as path9 from "node:path";
|
|
1676
1579
|
var LANES = ["work", "chore"];
|
|
1677
1580
|
function worktreePath(id) {
|
|
1678
|
-
return
|
|
1581
|
+
return path9.join(lobstahHome(), "worktrees", id);
|
|
1679
1582
|
}
|
|
1680
1583
|
function readRecord(file2) {
|
|
1681
1584
|
try {
|
|
1682
|
-
const r = JSON.parse(
|
|
1585
|
+
const r = JSON.parse(fs10.readFileSync(file2, "utf8"));
|
|
1683
1586
|
return typeof r.path === "string" ? r : void 0;
|
|
1684
1587
|
} catch {
|
|
1685
1588
|
return void 0;
|
|
1686
1589
|
}
|
|
1687
1590
|
}
|
|
1688
1591
|
function ownerOfPath(p) {
|
|
1689
|
-
const rel =
|
|
1690
|
-
if (!rel || rel.startsWith("..") ||
|
|
1592
|
+
const rel = path9.relative(path9.join(lobstahHome(), "worktrees"), p);
|
|
1593
|
+
if (!rel || rel.startsWith("..") || path9.isAbsolute(rel))
|
|
1691
1594
|
return void 0;
|
|
1692
1595
|
return rel.split(/[\\/]/)[0];
|
|
1693
1596
|
}
|
|
@@ -1700,7 +1603,7 @@ function dispatchWorktree(id, lane) {
|
|
|
1700
1603
|
}
|
|
1701
1604
|
const dirs = laneDirs(l);
|
|
1702
1605
|
for (const dir of [dirs.active, dirs.done]) {
|
|
1703
|
-
const rec = readRecord(
|
|
1606
|
+
const rec = readRecord(path9.join(dir, id, "worktree.json"));
|
|
1704
1607
|
if (rec) {
|
|
1705
1608
|
const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
|
|
1706
1609
|
return { path: rec.path, owner, reused: owner !== id };
|
|
@@ -1712,7 +1615,7 @@ function dispatchWorktree(id, lane) {
|
|
|
1712
1615
|
function laneOf(id) {
|
|
1713
1616
|
for (const l of LANES) {
|
|
1714
1617
|
const d = laneDirs(l);
|
|
1715
|
-
if (
|
|
1618
|
+
if (fs10.existsSync(path9.join(d.queue, `${id}.json`)) || fs10.existsSync(path9.join(d.active, id)) || fs10.existsSync(path9.join(d.done, id))) {
|
|
1716
1619
|
return l;
|
|
1717
1620
|
}
|
|
1718
1621
|
}
|
|
@@ -1732,7 +1635,7 @@ function followUpAncestors(id, lane) {
|
|
|
1732
1635
|
function chainWorktree(followUp) {
|
|
1733
1636
|
for (const id of [followUp, ...followUpAncestors(followUp)]) {
|
|
1734
1637
|
const wt = dispatchWorktree(id, laneOf(id));
|
|
1735
|
-
if (
|
|
1638
|
+
if (fs10.existsSync(wt.path))
|
|
1736
1639
|
return { ...wt, from: id };
|
|
1737
1640
|
}
|
|
1738
1641
|
return void 0;
|
|
@@ -1747,27 +1650,27 @@ function processAlive(pid) {
|
|
|
1747
1650
|
}
|
|
1748
1651
|
}
|
|
1749
1652
|
function worktreeGitDir(wt) {
|
|
1750
|
-
const dotGit =
|
|
1653
|
+
const dotGit = path9.join(wt, ".git");
|
|
1751
1654
|
try {
|
|
1752
|
-
const st =
|
|
1655
|
+
const st = fs10.statSync(dotGit);
|
|
1753
1656
|
if (st.isDirectory())
|
|
1754
1657
|
return dotGit;
|
|
1755
|
-
const m = /^gitdir:\s*(.+?)\s*$/m.exec(
|
|
1756
|
-
return m ?
|
|
1658
|
+
const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs10.readFileSync(dotGit, "utf8"));
|
|
1659
|
+
return m ? path9.resolve(wt, m[1]) : void 0;
|
|
1757
1660
|
} catch {
|
|
1758
1661
|
return void 0;
|
|
1759
1662
|
}
|
|
1760
1663
|
}
|
|
1761
1664
|
function worktreeLockFile(wt) {
|
|
1762
1665
|
const gitDir = worktreeGitDir(wt);
|
|
1763
|
-
return gitDir ?
|
|
1666
|
+
return gitDir ? path9.join(gitDir, "lobstah.lock") : void 0;
|
|
1764
1667
|
}
|
|
1765
1668
|
function readWorktreeLock(wt) {
|
|
1766
1669
|
const file2 = worktreeLockFile(wt);
|
|
1767
1670
|
if (!file2)
|
|
1768
1671
|
return void 0;
|
|
1769
1672
|
try {
|
|
1770
|
-
return JSON.parse(
|
|
1673
|
+
return JSON.parse(fs10.readFileSync(file2, "utf8"));
|
|
1771
1674
|
} catch {
|
|
1772
1675
|
return void 0;
|
|
1773
1676
|
}
|
|
@@ -1775,7 +1678,7 @@ function readWorktreeLock(wt) {
|
|
|
1775
1678
|
function lockIsLive(lock) {
|
|
1776
1679
|
if (lock.kind === "warm")
|
|
1777
1680
|
return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
|
|
1778
|
-
return
|
|
1681
|
+
return fs10.existsSync(path9.join(laneDirs(lock.lane).active, lock.id));
|
|
1779
1682
|
}
|
|
1780
1683
|
function worktreeHolder(wt) {
|
|
1781
1684
|
const lock = readWorktreeLock(wt);
|
|
@@ -1788,7 +1691,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
1788
1691
|
return { id: "(no git dir)", lane, pid: 0, at: mine.at };
|
|
1789
1692
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
1790
1693
|
try {
|
|
1791
|
-
|
|
1694
|
+
fs10.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
|
|
1792
1695
|
return void 0;
|
|
1793
1696
|
} catch (err) {
|
|
1794
1697
|
if (err.code !== "EEXIST")
|
|
@@ -1796,7 +1699,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
1796
1699
|
}
|
|
1797
1700
|
let raw;
|
|
1798
1701
|
try {
|
|
1799
|
-
raw =
|
|
1702
|
+
raw = fs10.readFileSync(file2, "utf8");
|
|
1800
1703
|
} catch {
|
|
1801
1704
|
continue;
|
|
1802
1705
|
}
|
|
@@ -1807,14 +1710,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
1807
1710
|
held2 = void 0;
|
|
1808
1711
|
}
|
|
1809
1712
|
if (held2?.id === id) {
|
|
1810
|
-
|
|
1713
|
+
fs10.writeFileSync(file2, JSON.stringify(mine, null, 2));
|
|
1811
1714
|
return void 0;
|
|
1812
1715
|
}
|
|
1813
1716
|
if (held2 && lockIsLive(held2))
|
|
1814
1717
|
return held2;
|
|
1815
1718
|
try {
|
|
1816
|
-
if (
|
|
1817
|
-
|
|
1719
|
+
if (fs10.readFileSync(file2, "utf8") === raw)
|
|
1720
|
+
fs10.rmSync(file2, { force: true });
|
|
1818
1721
|
} catch {
|
|
1819
1722
|
}
|
|
1820
1723
|
}
|
|
@@ -1826,23 +1729,24 @@ function releaseWorktreeLock(wt, id) {
|
|
|
1826
1729
|
if (!file2)
|
|
1827
1730
|
return;
|
|
1828
1731
|
if (readWorktreeLock(wt)?.id === id)
|
|
1829
|
-
|
|
1732
|
+
fs10.rmSync(file2, { force: true });
|
|
1830
1733
|
}
|
|
1831
1734
|
|
|
1832
|
-
// packages/core/dist/
|
|
1833
|
-
import * as
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1735
|
+
// packages/core/dist/events.js
|
|
1736
|
+
import * as fs11 from "node:fs";
|
|
1737
|
+
function appendEvent(id, lane, ev) {
|
|
1738
|
+
fs11.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
|
|
1739
|
+
`);
|
|
1740
|
+
}
|
|
1741
|
+
function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
|
|
1742
|
+
const file2 = eventsPath(id, lane);
|
|
1743
|
+
try {
|
|
1744
|
+
fs11.utimesSync(file2, at, at);
|
|
1745
|
+
} catch {
|
|
1746
|
+
fs11.appendFileSync(file2, "");
|
|
1747
|
+
fs11.utimesSync(file2, at, at);
|
|
1748
|
+
}
|
|
1841
1749
|
}
|
|
1842
|
-
|
|
1843
|
-
// packages/core/dist/pools.js
|
|
1844
|
-
import * as fs15 from "node:fs";
|
|
1845
|
-
import * as path12 from "node:path";
|
|
1846
1750
|
|
|
1847
1751
|
// packages/core/dist/slots.js
|
|
1848
1752
|
function isTrapCatch(id, lane) {
|
|
@@ -1854,29 +1758,31 @@ function isFinished(id, lane) {
|
|
|
1854
1758
|
}
|
|
1855
1759
|
|
|
1856
1760
|
// packages/core/dist/pools.js
|
|
1761
|
+
import * as fs12 from "node:fs";
|
|
1762
|
+
import * as path10 from "node:path";
|
|
1857
1763
|
function poolsRoot() {
|
|
1858
|
-
return
|
|
1764
|
+
return path10.join(lobstahHome(), "pools");
|
|
1859
1765
|
}
|
|
1860
1766
|
function poolDir(pool) {
|
|
1861
|
-
return
|
|
1767
|
+
return path10.join(poolsRoot(), pool);
|
|
1862
1768
|
}
|
|
1863
1769
|
function poolSlotPath(pool, slot) {
|
|
1864
|
-
return
|
|
1770
|
+
return path10.join(poolDir(pool), String(slot));
|
|
1865
1771
|
}
|
|
1866
1772
|
function slotsDir(pool) {
|
|
1867
|
-
return
|
|
1773
|
+
return path10.join(poolDir(pool), ".slots");
|
|
1868
1774
|
}
|
|
1869
1775
|
function poolSlotOf(p) {
|
|
1870
1776
|
const real = (x) => {
|
|
1871
1777
|
try {
|
|
1872
|
-
return
|
|
1778
|
+
return fs12.realpathSync.native(x);
|
|
1873
1779
|
} catch {
|
|
1874
|
-
return
|
|
1780
|
+
return path10.resolve(x);
|
|
1875
1781
|
}
|
|
1876
1782
|
};
|
|
1877
|
-
for (const [rootDir, dir] of [[poolsRoot(),
|
|
1878
|
-
const rel =
|
|
1879
|
-
if (!rel || rel.startsWith("..") ||
|
|
1783
|
+
for (const [rootDir, dir] of [[poolsRoot(), path10.resolve(p)], [real(poolsRoot()), real(p)]]) {
|
|
1784
|
+
const rel = path10.relative(rootDir, dir);
|
|
1785
|
+
if (!rel || rel.startsWith("..") || path10.isAbsolute(rel))
|
|
1880
1786
|
continue;
|
|
1881
1787
|
const parts = rel.split(/[\\/]/);
|
|
1882
1788
|
if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
|
|
@@ -1890,20 +1796,20 @@ function poolSlotLabel(pool, slot) {
|
|
|
1890
1796
|
}
|
|
1891
1797
|
function readJson(file2) {
|
|
1892
1798
|
try {
|
|
1893
|
-
return JSON.parse(
|
|
1799
|
+
return JSON.parse(fs12.readFileSync(file2, "utf8"));
|
|
1894
1800
|
} catch {
|
|
1895
1801
|
return void 0;
|
|
1896
1802
|
}
|
|
1897
1803
|
}
|
|
1898
1804
|
function writeJson(file2, value) {
|
|
1899
|
-
|
|
1805
|
+
fs12.mkdirSync(path10.dirname(file2), { recursive: true });
|
|
1900
1806
|
const tmp = uniqueTempPath(file2);
|
|
1901
|
-
|
|
1902
|
-
|
|
1807
|
+
fs12.writeFileSync(tmp, JSON.stringify(value, null, 2));
|
|
1808
|
+
atomicRenameSync(tmp, file2);
|
|
1903
1809
|
}
|
|
1904
|
-
var metaFile = (pool, slot) =>
|
|
1905
|
-
var claimFile = (pool, slot) =>
|
|
1906
|
-
var outFile = (pool, slot) =>
|
|
1810
|
+
var metaFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.json`);
|
|
1811
|
+
var claimFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.claim.json`);
|
|
1812
|
+
var outFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.out.json`);
|
|
1907
1813
|
function readSlotMeta(pool, slot) {
|
|
1908
1814
|
return readJson(metaFile(pool, slot)) ?? {};
|
|
1909
1815
|
}
|
|
@@ -1923,7 +1829,7 @@ function writeSlotOut(pool, slot, out) {
|
|
|
1923
1829
|
writeJson(outFile(pool, slot), out);
|
|
1924
1830
|
}
|
|
1925
1831
|
function clearSlotOut(pool, slot) {
|
|
1926
|
-
|
|
1832
|
+
fs12.rmSync(outFile(pool, slot), { force: true });
|
|
1927
1833
|
}
|
|
1928
1834
|
function dispatchHolder(dir) {
|
|
1929
1835
|
const lock = readWorktreeLock(dir);
|
|
@@ -1933,7 +1839,7 @@ function poolSlotView(pool, slot) {
|
|
|
1933
1839
|
const dir = poolSlotPath(pool, slot);
|
|
1934
1840
|
const lastClaim = readSlotClaim(pool, slot)?.id;
|
|
1935
1841
|
const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
|
|
1936
|
-
if (!
|
|
1842
|
+
if (!fs12.existsSync(dir)) {
|
|
1937
1843
|
const meta2 = readSlotMeta(pool, slot);
|
|
1938
1844
|
return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
|
|
1939
1845
|
}
|
|
@@ -1948,8 +1854,8 @@ function poolSlotView(pool, slot) {
|
|
|
1948
1854
|
return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
|
|
1949
1855
|
return { ...base, state: "free" };
|
|
1950
1856
|
}
|
|
1951
|
-
var warmStateFile = (pool) =>
|
|
1952
|
-
var warmLockFile = (pool) =>
|
|
1857
|
+
var warmStateFile = (pool) => path10.join(poolDir(pool), ".warm-state.json");
|
|
1858
|
+
var warmLockFile = (pool) => path10.join(poolDir(pool), ".warm.lock");
|
|
1953
1859
|
var POOL_WARM_MAX_MS = 60 * 6e4;
|
|
1954
1860
|
function readPoolWarmState(pool) {
|
|
1955
1861
|
return readJson(warmStateFile(pool)) ?? {};
|
|
@@ -1971,15 +1877,15 @@ function poolWarmRunning(pool, now2 = Date.now()) {
|
|
|
1971
1877
|
}
|
|
1972
1878
|
function takePoolWarmLock(pool) {
|
|
1973
1879
|
const file2 = warmLockFile(pool);
|
|
1974
|
-
|
|
1880
|
+
fs12.mkdirSync(path10.dirname(file2), { recursive: true });
|
|
1975
1881
|
const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1976
1882
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
1977
1883
|
try {
|
|
1978
|
-
|
|
1884
|
+
fs12.writeFileSync(file2, mine, { flag: "wx" });
|
|
1979
1885
|
return () => {
|
|
1980
1886
|
try {
|
|
1981
|
-
if (
|
|
1982
|
-
|
|
1887
|
+
if (fs12.readFileSync(file2, "utf8") === mine)
|
|
1888
|
+
fs12.rmSync(file2, { force: true });
|
|
1983
1889
|
} catch {
|
|
1984
1890
|
}
|
|
1985
1891
|
};
|
|
@@ -1989,7 +1895,7 @@ function takePoolWarmLock(pool) {
|
|
|
1989
1895
|
}
|
|
1990
1896
|
if (poolWarmRunning(pool))
|
|
1991
1897
|
return void 0;
|
|
1992
|
-
|
|
1898
|
+
fs12.rmSync(file2, { force: true });
|
|
1993
1899
|
}
|
|
1994
1900
|
return void 0;
|
|
1995
1901
|
}
|
|
@@ -1997,39 +1903,306 @@ var POOL_RETRY_MS = 10 * 6e4;
|
|
|
1997
1903
|
var POOL_FETCH_MS = 10 * 6e4;
|
|
1998
1904
|
var POOL_RECHECK_MS = 5 * 6e4;
|
|
1999
1905
|
|
|
1906
|
+
// packages/core/dist/disk.js
|
|
1907
|
+
import * as fs13 from "node:fs";
|
|
1908
|
+
var GB = 1024 ** 3;
|
|
1909
|
+
var statfsFreeBytes = (dir) => {
|
|
1910
|
+
const s = fs13.statfsSync(dir);
|
|
1911
|
+
return Number(s.bavail) * Number(s.bsize);
|
|
1912
|
+
};
|
|
1913
|
+
function formatGB(bytes) {
|
|
1914
|
+
return `${(bytes / GB).toFixed(1).replace(/\.0$/, "")} GB`;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
// packages/core/dist/inbox.js
|
|
1918
|
+
import * as fs14 from "node:fs";
|
|
1919
|
+
import * as path11 from "node:path";
|
|
1920
|
+
var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
|
|
1921
|
+
function inboxDir(id, lane) {
|
|
1922
|
+
return path11.join(laneDirs(lane).inbox, id);
|
|
1923
|
+
}
|
|
1924
|
+
function unhandled(id, lane) {
|
|
1925
|
+
const dir = inboxDir(id, lane);
|
|
1926
|
+
return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs14.readFileSync(path11.join(dir, f), "utf8") }));
|
|
1927
|
+
}
|
|
1928
|
+
function acknowledge(id, lane, file2) {
|
|
1929
|
+
const dir = inboxDir(id, lane);
|
|
1930
|
+
fs14.mkdirSync(path11.join(dir, "handled"), { recursive: true });
|
|
1931
|
+
fs14.renameSync(path11.join(dir, file2), path11.join(dir, "handled", file2));
|
|
1932
|
+
try {
|
|
1933
|
+
fs14.renameSync(path11.join(dir, metaName(file2)), path11.join(dir, "handled", metaName(file2)));
|
|
1934
|
+
} catch {
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
// packages/core/dist/resume.js
|
|
1939
|
+
import * as fs15 from "node:fs";
|
|
1940
|
+
import * as os3 from "node:os";
|
|
1941
|
+
import * as path12 from "node:path";
|
|
1942
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
1943
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-([0-9a-f])[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
1944
|
+
function harnessFromSessionId(sessionId) {
|
|
1945
|
+
const version = sessionId ? UUID.exec(sessionId)?.[1] : void 0;
|
|
1946
|
+
return version === "7" ? "codex" : version === "4" ? "claude" : void 0;
|
|
1947
|
+
}
|
|
1948
|
+
function claimOf(id, lane) {
|
|
1949
|
+
const dirs = laneDirs(lane);
|
|
1950
|
+
for (const dir of [dirs.active, dirs.done]) {
|
|
1951
|
+
try {
|
|
1952
|
+
return JSON.parse(fs15.readFileSync(path12.join(dir, id, "claim.json"), "utf8"));
|
|
1953
|
+
} catch {
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
return void 0;
|
|
1957
|
+
}
|
|
1958
|
+
function laneOf2(id) {
|
|
1959
|
+
for (const lane of ["work", "chore"]) {
|
|
1960
|
+
if (storedDescriptor(id, lane) || readEvidence(id, lane).sessionId)
|
|
1961
|
+
return lane;
|
|
1962
|
+
}
|
|
1963
|
+
return void 0;
|
|
1964
|
+
}
|
|
1965
|
+
function resolveSessionHarness(id, cfg, laneHint) {
|
|
1966
|
+
const lane = laneHint ?? laneOf2(id);
|
|
1967
|
+
if (!lane)
|
|
1968
|
+
return {};
|
|
1969
|
+
const ev = readEvidence(id, lane);
|
|
1970
|
+
const sessionId = ev.sessionId;
|
|
1971
|
+
const out = (harness, source) => ({
|
|
1972
|
+
sessionId,
|
|
1973
|
+
harness,
|
|
1974
|
+
source,
|
|
1975
|
+
lane
|
|
1976
|
+
});
|
|
1977
|
+
if (ev.harness)
|
|
1978
|
+
return out(ev.harness, "evidence");
|
|
1979
|
+
const claim = claimOf(id, lane);
|
|
1980
|
+
if (claim?.harness)
|
|
1981
|
+
return out(claim.harness, "trap");
|
|
1982
|
+
if (ev.deliveredTo?.startsWith("wt:")) {
|
|
1983
|
+
const reg = readTrap(ev.deliveredTo.slice("wt:".length));
|
|
1984
|
+
if (reg?.harness)
|
|
1985
|
+
return out(reg.harness, "trap");
|
|
1986
|
+
}
|
|
1987
|
+
const byId = harnessFromSessionId(sessionId);
|
|
1988
|
+
if (byId)
|
|
1989
|
+
return out(byId, "session-id");
|
|
1990
|
+
const d = storedDescriptor(id, lane);
|
|
1991
|
+
const repo = d && cfg?.repos[d.repo];
|
|
1992
|
+
const fromDescriptor = d?.harness ?? repo?.harness?.default ?? cfg?.harness.default;
|
|
1993
|
+
if (fromDescriptor)
|
|
1994
|
+
return out(fromDescriptor, "descriptor");
|
|
1995
|
+
return { sessionId, lane };
|
|
1996
|
+
}
|
|
1997
|
+
var UNRESUMABLE = /no conversation found|no rollout found|thread\/resume failed|(session|thread|conversation)( id)?[^.\n]{0,80}\b(not found|does not exist|unknown|invalid)|(could not|cannot|failed to|unable to) (find|load|resume)[^.\n]{0,40}\b(session|thread|conversation)/i;
|
|
1998
|
+
function isUnresumable(error) {
|
|
1999
|
+
return error !== void 0 && UNRESUMABLE.test(error);
|
|
2000
|
+
}
|
|
2001
|
+
function worktreeProgress(worktree, trunk) {
|
|
2002
|
+
if (!worktree || !fs15.existsSync(worktree))
|
|
2003
|
+
return "No worktree progress recorded.";
|
|
2004
|
+
const git2 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
|
|
2005
|
+
const commits = trunk ? git2("log", "--oneline", `origin/${trunk}..HEAD`) : git2("log", "--oneline", "-15");
|
|
2006
|
+
const status = git2("status", "--short");
|
|
2007
|
+
return `Commits so far:
|
|
2008
|
+
${commits || "(none)"}
|
|
2009
|
+
|
|
2010
|
+
Uncommitted changes:
|
|
2011
|
+
${status || "(clean)"}`;
|
|
2012
|
+
}
|
|
2013
|
+
function originProgress(originId, lane) {
|
|
2014
|
+
const ev = readEvidence(originId, lane);
|
|
2015
|
+
const last = readStatusLog(originId, lane).at(-1);
|
|
2016
|
+
const lines = [`The earlier dispatch ${originId} left:`];
|
|
2017
|
+
if (ev.branch)
|
|
2018
|
+
lines.push(`- branch: ${ev.branch}`);
|
|
2019
|
+
if (ev.prUrl)
|
|
2020
|
+
lines.push(`- PR: ${ev.prUrl}`);
|
|
2021
|
+
if (last)
|
|
2022
|
+
lines.push(`- last status: ${last.verb}${last.note ? ` \u2014 ${last.note}` : ""}`);
|
|
2023
|
+
if (ev.commits?.length)
|
|
2024
|
+
lines.push("- commits:", ...ev.commits.map((c) => ` ${c}`));
|
|
2025
|
+
if (lines.length === 1)
|
|
2026
|
+
lines.push("- (no recorded branch, PR, or commits)");
|
|
2027
|
+
return lines.join("\n");
|
|
2028
|
+
}
|
|
2029
|
+
function handoffNote(fromHarness, progress, why) {
|
|
2030
|
+
return `You are taking over this dispatch from a previous agent session (harness: ${fromHarness}). Its conversation is not available${why ? ` (${why})` : ""} \u2014 the state below is the ground truth. Review it, then continue the brief from where it stops.
|
|
2031
|
+
|
|
2032
|
+
${progress}`;
|
|
2033
|
+
}
|
|
2034
|
+
function codexHome(env = process.env) {
|
|
2035
|
+
return env.CODEX_HOME ?? path12.join(os3.homedir(), ".codex");
|
|
2036
|
+
}
|
|
2037
|
+
function codexRolloutFile(threadId, home = codexHome()) {
|
|
2038
|
+
const suffix = `-${threadId}.jsonl`;
|
|
2039
|
+
const walk = (dir, depth) => {
|
|
2040
|
+
let entries;
|
|
2041
|
+
try {
|
|
2042
|
+
entries = fs15.readdirSync(dir, { withFileTypes: true });
|
|
2043
|
+
} catch {
|
|
2044
|
+
return void 0;
|
|
2045
|
+
}
|
|
2046
|
+
for (const e of entries) {
|
|
2047
|
+
if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
|
|
2048
|
+
return path12.join(dir, e.name);
|
|
2049
|
+
}
|
|
2050
|
+
if (depth === 0)
|
|
2051
|
+
return void 0;
|
|
2052
|
+
for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
|
|
2053
|
+
const hit = walk(path12.join(dir, e.name), depth - 1);
|
|
2054
|
+
if (hit)
|
|
2055
|
+
return hit;
|
|
2056
|
+
}
|
|
2057
|
+
return void 0;
|
|
2058
|
+
};
|
|
2059
|
+
return walk(path12.join(home, "sessions"), 3) ?? walk(path12.join(home, "archived_sessions"), 0);
|
|
2060
|
+
}
|
|
2061
|
+
function codexDesktopThread(threadId, home = codexHome()) {
|
|
2062
|
+
const file2 = codexRolloutFile(threadId, home);
|
|
2063
|
+
if (!file2)
|
|
2064
|
+
return void 0;
|
|
2065
|
+
let head = "";
|
|
2066
|
+
try {
|
|
2067
|
+
const fd = fs15.openSync(file2, "r");
|
|
2068
|
+
try {
|
|
2069
|
+
const buf = Buffer.alloc(4096);
|
|
2070
|
+
head = buf.subarray(0, fs15.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
|
|
2071
|
+
} finally {
|
|
2072
|
+
fs15.closeSync(fd);
|
|
2073
|
+
}
|
|
2074
|
+
} catch {
|
|
2075
|
+
return void 0;
|
|
2076
|
+
}
|
|
2077
|
+
const originator = /"originator"\s*:\s*"([^"]*)"/.exec(head)?.[1];
|
|
2078
|
+
return originator && /desktop/i.test(originator) ? originator : void 0;
|
|
2079
|
+
}
|
|
2080
|
+
var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
|
|
2081
|
+
|
|
2082
|
+
// packages/core/dist/notices.js
|
|
2083
|
+
function noticesDir() {
|
|
2084
|
+
return path13.join(lobstahHome(), "notices");
|
|
2085
|
+
}
|
|
2086
|
+
var counter = 0;
|
|
2087
|
+
function postNotice(n) {
|
|
2088
|
+
const dir = noticesDir();
|
|
2089
|
+
fs16.mkdirSync(dir, { recursive: true });
|
|
2090
|
+
if (n.dedupeKey) {
|
|
2091
|
+
const marker = path13.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
|
|
2092
|
+
try {
|
|
2093
|
+
fs16.writeFileSync(marker, "", { flag: "wx" });
|
|
2094
|
+
} catch {
|
|
2095
|
+
return void 0;
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
const seq = `${String(Date.now()).padStart(15, "0")}-${process.pid}-${String(counter++).padStart(8, "0")}`;
|
|
2099
|
+
const notice = {
|
|
2100
|
+
seq,
|
|
2101
|
+
kind: n.kind,
|
|
2102
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2103
|
+
text: n.text,
|
|
2104
|
+
refId: n.refId,
|
|
2105
|
+
...n.url ? { url: n.url } : {},
|
|
2106
|
+
repo: n.repo,
|
|
2107
|
+
by: n.by,
|
|
2108
|
+
...n.quiet ? { quiet: true } : {},
|
|
2109
|
+
...n.stateHash ? { stateHash: n.stateHash } : {}
|
|
2110
|
+
};
|
|
2111
|
+
const file2 = path13.join(dir, `${seq}.json`);
|
|
2112
|
+
const tmp = uniqueTempPath(file2);
|
|
2113
|
+
fs16.writeFileSync(tmp, JSON.stringify(notice, null, 2));
|
|
2114
|
+
atomicRenameSync(tmp, file2);
|
|
2115
|
+
return notice;
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
// packages/core/dist/attachments.js
|
|
2119
|
+
function attachmentBlock(attachments) {
|
|
2120
|
+
if (attachments.length === 0)
|
|
2121
|
+
return "";
|
|
2122
|
+
return [
|
|
2123
|
+
"--- ATTACHMENTS ---",
|
|
2124
|
+
...attachments.map((a) => `${a.name} (${a.type}, ${a.bytes} bytes) at ${a.path}`),
|
|
2125
|
+
"Images and PDFs can be read directly with your file tools."
|
|
2126
|
+
].join("\n");
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
// packages/core/dist/helm.js
|
|
2130
|
+
import * as fs17 from "node:fs";
|
|
2131
|
+
import * as path14 from "node:path";
|
|
2132
|
+
function helmDir() {
|
|
2133
|
+
return path14.join(lobstahHome(), "helm");
|
|
2134
|
+
}
|
|
2135
|
+
function listHelms() {
|
|
2136
|
+
try {
|
|
2137
|
+
return fs17.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs17.readFileSync(path14.join(helmDir(), f), "utf8")));
|
|
2138
|
+
} catch {
|
|
2139
|
+
return [];
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
function liveHelms(ttlMs, now2 = Date.now()) {
|
|
2143
|
+
return listHelms().filter((h) => now2 - (Date.parse(h.heartbeatAt) || 0) <= ttlMs);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2000
2146
|
// packages/core/dist/soak.js
|
|
2001
2147
|
function regPath(trapId) {
|
|
2002
|
-
return
|
|
2148
|
+
return path15.join(soakingDir(), `${trapId}.json`);
|
|
2003
2149
|
}
|
|
2004
2150
|
function readTrap(trapId) {
|
|
2005
2151
|
try {
|
|
2006
|
-
return JSON.parse(
|
|
2152
|
+
return JSON.parse(fs18.readFileSync(regPath(trapId), "utf8"));
|
|
2007
2153
|
} catch {
|
|
2008
2154
|
return void 0;
|
|
2009
2155
|
}
|
|
2010
2156
|
}
|
|
2011
2157
|
function listTraps() {
|
|
2012
2158
|
try {
|
|
2013
|
-
return
|
|
2159
|
+
return fs18.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs18.readFileSync(path15.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
|
|
2014
2160
|
} catch {
|
|
2015
2161
|
return [];
|
|
2016
2162
|
}
|
|
2017
2163
|
}
|
|
2018
2164
|
function claimPath(id, lane) {
|
|
2019
|
-
return
|
|
2165
|
+
return path15.join(laneDirs(lane).active, id, "claim.json");
|
|
2020
2166
|
}
|
|
2021
2167
|
function readSessionClaim(id, lane) {
|
|
2022
2168
|
try {
|
|
2023
|
-
return JSON.parse(
|
|
2169
|
+
return JSON.parse(fs18.readFileSync(claimPath(id, lane), "utf8"));
|
|
2024
2170
|
} catch {
|
|
2025
2171
|
return void 0;
|
|
2026
2172
|
}
|
|
2027
2173
|
}
|
|
2028
2174
|
|
|
2175
|
+
// packages/core/dist/catch-context.js
|
|
2176
|
+
import * as fs19 from "node:fs";
|
|
2177
|
+
import * as path16 from "node:path";
|
|
2178
|
+
function readCatchContext(dir, id) {
|
|
2179
|
+
try {
|
|
2180
|
+
return JSON.parse(fs19.readFileSync(path16.join(dir, `${id}.catch-context`), "utf8"));
|
|
2181
|
+
} catch {
|
|
2182
|
+
return {};
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
function observeLocalCatch(id, lane, phase, now2 = Date.now()) {
|
|
2186
|
+
const dir = laneDirs(lane).state, old = readCatchContext(dir, id), cfg = loadConfig();
|
|
2187
|
+
if (phase === "finish" && Object.hasOwn(old, "helm"))
|
|
2188
|
+
return;
|
|
2189
|
+
const repo = storedDescriptor(id, lane)?.repo;
|
|
2190
|
+
const helms = liveHelms(cfg.helm.ttlSecs * 1e3, now2);
|
|
2191
|
+
const present = repo ? helms.some((h) => h.repos.includes(repo)) : null;
|
|
2192
|
+
const next = phase === "claim" ? { claimHelm: present, location: "local" } : { ...old, location: "local", helm: old.claimHelm === true || present === true ? true : old.claimHelm === false && present === false ? false : null };
|
|
2193
|
+
const file2 = path16.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
|
|
2194
|
+
try {
|
|
2195
|
+
fs19.writeFileSync(tmp, JSON.stringify(next));
|
|
2196
|
+
fs19.renameSync(tmp, file2);
|
|
2197
|
+
} finally {
|
|
2198
|
+
fs19.rmSync(tmp, { force: true });
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2029
2202
|
// packages/core/dist/stats.js
|
|
2030
2203
|
var DAILY_RETENTION_DAYS = 400;
|
|
2031
2204
|
function statsPath() {
|
|
2032
|
-
return
|
|
2205
|
+
return path17.join(lobstahHome(), "stats.json");
|
|
2033
2206
|
}
|
|
2034
2207
|
function shiftDay(day, days) {
|
|
2035
2208
|
const [y, m, d] = day.split("-").map(Number);
|
|
@@ -2042,7 +2215,7 @@ function localDay(at = Date.now()) {
|
|
|
2042
2215
|
function readCatchFacts(stateDir, id) {
|
|
2043
2216
|
let last;
|
|
2044
2217
|
try {
|
|
2045
|
-
for (const line of
|
|
2218
|
+
for (const line of fs20.readFileSync(path17.join(stateDir, `${id}.status`), "utf8").split("\n")) {
|
|
2046
2219
|
if (!line.trim())
|
|
2047
2220
|
continue;
|
|
2048
2221
|
try {
|
|
@@ -2058,7 +2231,7 @@ function readCatchFacts(stateDir, id) {
|
|
|
2058
2231
|
let trap;
|
|
2059
2232
|
let worker = workerProfile();
|
|
2060
2233
|
try {
|
|
2061
|
-
const evidence = JSON.parse(
|
|
2234
|
+
const evidence = JSON.parse(fs20.readFileSync(path17.join(stateDir, `${id}.evidence`), "utf8"));
|
|
2062
2235
|
const to = evidence.deliveredTo;
|
|
2063
2236
|
if (typeof to === "string" && to.startsWith("wt:"))
|
|
2064
2237
|
trap = to;
|
|
@@ -2066,7 +2239,8 @@ function readCatchFacts(stateDir, id) {
|
|
|
2066
2239
|
worker = sanitizeWorker(reg ?? evidence.worker ?? workerProfile({ harness: evidence.harness }));
|
|
2067
2240
|
} catch {
|
|
2068
2241
|
}
|
|
2069
|
-
|
|
2242
|
+
const context = readCatchContext(stateDir, id);
|
|
2243
|
+
return { done: true, worker, helm: context.helm, location: context.location, ...typeof last.at === "string" ? { at: last.at } : {}, ...trap ? { trap } : {} };
|
|
2070
2244
|
}
|
|
2071
2245
|
function emptyStore(now2) {
|
|
2072
2246
|
return {
|
|
@@ -2114,6 +2288,15 @@ function add(store, facts, now2) {
|
|
|
2114
2288
|
store.utc = { date: utcDay, catches: 0, perTrap: {}, trapWorkers: {}, byWorker: [] };
|
|
2115
2289
|
if ((at ? new Date(at).toISOString().slice(0, 10) : utcDay) === utcDay) {
|
|
2116
2290
|
store.utc.catches++;
|
|
2291
|
+
const usage = store.utc.usage ??= { withHelm: 0, withoutHelm: 0, onLocal: 0, onWharf: 0 };
|
|
2292
|
+
if (facts.helm === true)
|
|
2293
|
+
usage.withHelm++;
|
|
2294
|
+
if (facts.helm === false)
|
|
2295
|
+
usage.withoutHelm++;
|
|
2296
|
+
if (facts.location === "local")
|
|
2297
|
+
usage.onLocal++;
|
|
2298
|
+
if (facts.location === "wharf")
|
|
2299
|
+
usage.onWharf++;
|
|
2117
2300
|
const worker = sanitizeWorker(facts.worker);
|
|
2118
2301
|
if (facts.trap) {
|
|
2119
2302
|
store.utc.perTrap[facts.trap] = (store.utc.perTrap[facts.trap] ?? 0) + 1;
|
|
@@ -2131,7 +2314,7 @@ function add(store, facts, now2) {
|
|
|
2131
2314
|
}
|
|
2132
2315
|
function backfillSources() {
|
|
2133
2316
|
const live = ["work", "chore"].map((lane) => ({ dir: laneDirs(lane).state, live: true }));
|
|
2134
|
-
const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir:
|
|
2317
|
+
const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path17.join(lobstahHome(), name), live: false })).filter((s) => fs20.statSync(s.dir).isDirectory());
|
|
2135
2318
|
return [...live, ...backups];
|
|
2136
2319
|
}
|
|
2137
2320
|
function backfillStats(now2 = Date.now(), alreadyCounted) {
|
|
@@ -2203,25 +2386,25 @@ function parseStore(text) {
|
|
|
2203
2386
|
var complete2 = (s) => !!s && s.daily !== void 0;
|
|
2204
2387
|
function writeStore(store) {
|
|
2205
2388
|
const file2 = statsPath();
|
|
2206
|
-
|
|
2389
|
+
fs20.mkdirSync(path17.dirname(file2), { recursive: true });
|
|
2207
2390
|
const tmp = uniqueTempPath(file2);
|
|
2208
|
-
|
|
2209
|
-
|
|
2391
|
+
fs20.writeFileSync(tmp, JSON.stringify(store));
|
|
2392
|
+
atomicRenameSync(tmp, file2);
|
|
2210
2393
|
}
|
|
2211
2394
|
function withStatsLock(action) {
|
|
2212
|
-
|
|
2395
|
+
fs20.mkdirSync(lobstahHome(), { recursive: true });
|
|
2213
2396
|
const lock = `${statsPath()}.lock`;
|
|
2214
2397
|
const deadline = Date.now() + 1e4;
|
|
2215
2398
|
for (; ; ) {
|
|
2216
2399
|
try {
|
|
2217
|
-
|
|
2400
|
+
fs20.mkdirSync(lock);
|
|
2218
2401
|
break;
|
|
2219
2402
|
} catch (err) {
|
|
2220
2403
|
if (err.code !== "EEXIST")
|
|
2221
2404
|
throw err;
|
|
2222
2405
|
try {
|
|
2223
|
-
if (Date.now() -
|
|
2224
|
-
|
|
2406
|
+
if (Date.now() - fs20.statSync(lock).mtimeMs > 12e4)
|
|
2407
|
+
fs20.rmdirSync(lock);
|
|
2225
2408
|
} catch {
|
|
2226
2409
|
}
|
|
2227
2410
|
if (Date.now() >= deadline)
|
|
@@ -2232,13 +2415,13 @@ function withStatsLock(action) {
|
|
|
2232
2415
|
try {
|
|
2233
2416
|
return action();
|
|
2234
2417
|
} finally {
|
|
2235
|
-
|
|
2418
|
+
fs20.rmdirSync(lock);
|
|
2236
2419
|
}
|
|
2237
2420
|
}
|
|
2238
2421
|
function loadOrBackfill(now2) {
|
|
2239
2422
|
let text;
|
|
2240
2423
|
try {
|
|
2241
|
-
text =
|
|
2424
|
+
text = fs20.readFileSync(statsPath(), "utf8");
|
|
2242
2425
|
} catch (err) {
|
|
2243
2426
|
if (err.code !== "ENOENT")
|
|
2244
2427
|
throw err;
|
|
@@ -2261,28 +2444,180 @@ function loadOrBackfill(now2) {
|
|
|
2261
2444
|
store2.utc.byWorker ??= [];
|
|
2262
2445
|
}
|
|
2263
2446
|
}
|
|
2264
|
-
writeStore(store2);
|
|
2265
|
-
return store2;
|
|
2447
|
+
writeStore(store2);
|
|
2448
|
+
return store2;
|
|
2449
|
+
}
|
|
2450
|
+
if (text !== void 0)
|
|
2451
|
+
fs20.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
|
|
2452
|
+
const store = backfillStats(now2);
|
|
2453
|
+
writeStore(store);
|
|
2454
|
+
return store;
|
|
2455
|
+
}
|
|
2456
|
+
function recordCatch(id, lane, now2 = Date.now()) {
|
|
2457
|
+
withStatsLock(() => {
|
|
2458
|
+
const store = loadOrBackfill(now2);
|
|
2459
|
+
if (store.counted.includes(id))
|
|
2460
|
+
return;
|
|
2461
|
+
const facts = readCatchFacts(laneDirs(lane).state, id);
|
|
2462
|
+
if (!facts.done)
|
|
2463
|
+
return;
|
|
2464
|
+
add(store, facts, now2);
|
|
2465
|
+
store.counted.push(id);
|
|
2466
|
+
writeStore(store);
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
// packages/core/dist/status.js
|
|
2471
|
+
function isVerb(v) {
|
|
2472
|
+
return VERBS.includes(v);
|
|
2473
|
+
}
|
|
2474
|
+
function isWaitingOn(v) {
|
|
2475
|
+
return WAITING_ON.includes(v);
|
|
2476
|
+
}
|
|
2477
|
+
var DURATION = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/i;
|
|
2478
|
+
var UNIT_MS = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 };
|
|
2479
|
+
function parseUntil(v, now2 = Date.now()) {
|
|
2480
|
+
const d = DURATION.exec(v.trim());
|
|
2481
|
+
if (d)
|
|
2482
|
+
return new Date(now2 + Number(d[1]) * UNIT_MS[d[2].toLowerCase()]).toISOString();
|
|
2483
|
+
const t = Date.parse(v);
|
|
2484
|
+
if (Number.isNaN(t))
|
|
2485
|
+
throw new Error(`invalid --until "${v}" \u2014 an ISO time (2026-10-01T09:00Z) or a duration (30m, 4h, 2d)`);
|
|
2486
|
+
return new Date(t).toISOString();
|
|
2487
|
+
}
|
|
2488
|
+
function waitingFields(verb, w, now2 = Date.now()) {
|
|
2489
|
+
const out = {};
|
|
2490
|
+
if ((w.waitingOn !== void 0 || w.link !== void 0) && !WAITING_ON_VERBS.includes(verb)) {
|
|
2491
|
+
throw new Error(`--waiting-on and --link are valid only with ${WAITING_ON_VERBS.join(", ")} \u2014 not ${verb}`);
|
|
2492
|
+
}
|
|
2493
|
+
if (w.until !== void 0 && verb !== "paused")
|
|
2494
|
+
throw new Error(`--until is valid only with paused \u2014 not ${verb}`);
|
|
2495
|
+
if (w.waitingOn !== void 0) {
|
|
2496
|
+
if (!isWaitingOn(w.waitingOn)) {
|
|
2497
|
+
throw new Error(`invalid --waiting-on "${w.waitingOn}" \u2014 must be one of: ${WAITING_ON.join(", ")}`);
|
|
2498
|
+
}
|
|
2499
|
+
out.waitingOn = w.waitingOn;
|
|
2500
|
+
}
|
|
2501
|
+
if (w.link !== void 0) {
|
|
2502
|
+
let url;
|
|
2503
|
+
try {
|
|
2504
|
+
url = new URL(w.link);
|
|
2505
|
+
} catch {
|
|
2506
|
+
url = void 0;
|
|
2507
|
+
}
|
|
2508
|
+
if (!url || url.protocol !== "http:" && url.protocol !== "https:") {
|
|
2509
|
+
throw new Error(`invalid --link "${w.link}" \u2014 must be an http or https URL`);
|
|
2510
|
+
}
|
|
2511
|
+
out.link = url.href;
|
|
2512
|
+
}
|
|
2513
|
+
if (w.until !== void 0)
|
|
2514
|
+
out.until = parseUntil(w.until, now2);
|
|
2515
|
+
if (verb === "paused" && (out.waitingOn === "person" || out.waitingOn === "review" && out.link && !parsePrRef(out.link))) {
|
|
2516
|
+
throw new Error("Waiting on a human requires needs-decision: report needs-decision with the question or the thing to look at.");
|
|
2517
|
+
}
|
|
2518
|
+
return out;
|
|
2519
|
+
}
|
|
2520
|
+
function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
|
|
2521
|
+
if (!isVerb(verb)) {
|
|
2522
|
+
throw new Error(`invalid status verb "${verb}" \u2014 must be one of: ${VERBS.join(", ")}`);
|
|
2523
|
+
}
|
|
2524
|
+
const extra = waiting ? waitingFields(verb, waiting) : {};
|
|
2525
|
+
const entry = {
|
|
2526
|
+
at: at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
2527
|
+
verb,
|
|
2528
|
+
...note ? { note } : {},
|
|
2529
|
+
...extra,
|
|
2530
|
+
...reported ? { reported: true } : {}
|
|
2531
|
+
};
|
|
2532
|
+
if (verb === "done") {
|
|
2533
|
+
try {
|
|
2534
|
+
observeLocalCatch(id, lane, "finish");
|
|
2535
|
+
} catch {
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
fs21.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
|
|
2539
|
+
`);
|
|
2540
|
+
if (verb === "done") {
|
|
2541
|
+
try {
|
|
2542
|
+
recordCatch(id, lane);
|
|
2543
|
+
} catch {
|
|
2544
|
+
}
|
|
2266
2545
|
}
|
|
2267
|
-
|
|
2268
|
-
fs17.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
|
|
2269
|
-
const store = backfillStats(now2);
|
|
2270
|
-
writeStore(store);
|
|
2271
|
-
return store;
|
|
2546
|
+
return entry;
|
|
2272
2547
|
}
|
|
2273
|
-
function
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
return;
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2548
|
+
function readStatusLog(id, lane) {
|
|
2549
|
+
const file2 = statusPath(id, lane);
|
|
2550
|
+
if (!fs21.existsSync(file2))
|
|
2551
|
+
return [];
|
|
2552
|
+
return fs21.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
|
|
2553
|
+
try {
|
|
2554
|
+
const parsed = JSON.parse(line);
|
|
2555
|
+
return isVerb(parsed.verb) ? [parsed] : [];
|
|
2556
|
+
} catch {
|
|
2557
|
+
return [];
|
|
2558
|
+
}
|
|
2284
2559
|
});
|
|
2285
2560
|
}
|
|
2561
|
+
function pausedWaiting(entry) {
|
|
2562
|
+
return entry?.verb === "paused" && entry.waitingOn !== void 0;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
// packages/core/dist/queue.js
|
|
2566
|
+
function requeue(id, lane) {
|
|
2567
|
+
const dirs = laneDirs(lane);
|
|
2568
|
+
const activeDir = path18.join(dirs.active, id);
|
|
2569
|
+
const file2 = path18.join(activeDir, "descriptor.json");
|
|
2570
|
+
const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2571
|
+
const tmp = uniqueTempPath(file2);
|
|
2572
|
+
fs22.writeFileSync(tmp, JSON.stringify(d, null, 2));
|
|
2573
|
+
atomicRenameSync(tmp, file2);
|
|
2574
|
+
fs22.renameSync(file2, path18.join(dirs.queue, `${id}.json`));
|
|
2575
|
+
fs22.rmSync(activeDir, { recursive: true, force: true });
|
|
2576
|
+
}
|
|
2577
|
+
function readDescriptor(id, lane) {
|
|
2578
|
+
const file2 = path18.join(laneDirs(lane).active, id, "descriptor.json");
|
|
2579
|
+
return JSON.parse(fs22.readFileSync(file2, "utf8"));
|
|
2580
|
+
}
|
|
2581
|
+
function storedDescriptor(id, lane) {
|
|
2582
|
+
const dirs = laneDirs(lane);
|
|
2583
|
+
for (const file2 of [
|
|
2584
|
+
path18.join(dirs.queue, `${id}.json`),
|
|
2585
|
+
path18.join(dirs.active, id, "descriptor.json"),
|
|
2586
|
+
path18.join(dirs.done, id, "descriptor.json")
|
|
2587
|
+
]) {
|
|
2588
|
+
try {
|
|
2589
|
+
return JSON.parse(fs22.readFileSync(file2, "utf8"));
|
|
2590
|
+
} catch {
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
return void 0;
|
|
2594
|
+
}
|
|
2595
|
+
function activeIds(lane) {
|
|
2596
|
+
return readDirIfPresent(laneDirs(lane).active).filter((f) => !f.startsWith("."));
|
|
2597
|
+
}
|
|
2598
|
+
function complete(id, lane) {
|
|
2599
|
+
const dirs = laneDirs(lane);
|
|
2600
|
+
fs22.renameSync(path18.join(dirs.active, id), path18.join(dirs.done, id));
|
|
2601
|
+
}
|
|
2602
|
+
function cancelRequested(id, lane) {
|
|
2603
|
+
return fs22.existsSync(path18.join(laneDirs(lane).active, id, "cancel"));
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
// packages/core/dist/backend.js
|
|
2607
|
+
function parseBackendLocation(raw) {
|
|
2608
|
+
if (raw === void 0)
|
|
2609
|
+
return void 0;
|
|
2610
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
2611
|
+
throw new Error("backend must be a wharf configuration");
|
|
2612
|
+
const b = raw;
|
|
2613
|
+
if (b.kind !== "wharf" || typeof b.url !== "string" || typeof b.account !== "string" || typeof b.tokenEnv !== "string" || !/^[a-zA-Z0-9_-]{1,64}$/.test(b.account) || !/^[A-Z][A-Z0-9_]{0,127}$/.test(b.tokenEnv))
|
|
2614
|
+
throw new Error("backend requires kind=wharf, url, account and tokenEnv");
|
|
2615
|
+
const url = new URL(b.url);
|
|
2616
|
+
if (url.username || url.password || url.search || url.hash || url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))) {
|
|
2617
|
+
throw new Error("backend url must use HTTPS (HTTP is allowed only for loopback tests), without credentials");
|
|
2618
|
+
}
|
|
2619
|
+
return { kind: "wharf", url: b.url.replace(/\/$/, ""), account: b.account, tokenEnv: b.tokenEnv };
|
|
2620
|
+
}
|
|
2286
2621
|
|
|
2287
2622
|
// packages/core/dist/decisions.js
|
|
2288
2623
|
var DECISION_DETAIL_MAX = 64 * 1024;
|
|
@@ -2307,59 +2642,22 @@ var ANSWER_TYPES = {
|
|
|
2307
2642
|
};
|
|
2308
2643
|
var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
|
|
2309
2644
|
|
|
2310
|
-
// packages/core/dist/inbox.js
|
|
2311
|
-
import * as fs18 from "node:fs";
|
|
2312
|
-
import * as path15 from "node:path";
|
|
2313
|
-
var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
|
|
2314
|
-
function inboxDir(id, lane) {
|
|
2315
|
-
return path15.join(laneDirs(lane).inbox, id);
|
|
2316
|
-
}
|
|
2317
|
-
function unhandled(id, lane) {
|
|
2318
|
-
const dir = inboxDir(id, lane);
|
|
2319
|
-
return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs18.readFileSync(path15.join(dir, f), "utf8") }));
|
|
2320
|
-
}
|
|
2321
|
-
function acknowledge(id, lane, file2) {
|
|
2322
|
-
const dir = inboxDir(id, lane);
|
|
2323
|
-
fs18.mkdirSync(path15.join(dir, "handled"), { recursive: true });
|
|
2324
|
-
fs18.renameSync(path15.join(dir, file2), path15.join(dir, "handled", file2));
|
|
2325
|
-
try {
|
|
2326
|
-
fs18.renameSync(path15.join(dir, metaName(file2)), path15.join(dir, "handled", metaName(file2)));
|
|
2327
|
-
} catch {
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
|
|
2331
|
-
// packages/core/dist/events.js
|
|
2332
|
-
import * as fs19 from "node:fs";
|
|
2333
|
-
function appendEvent(id, lane, ev) {
|
|
2334
|
-
fs19.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
|
|
2335
|
-
`);
|
|
2336
|
-
}
|
|
2337
|
-
function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
|
|
2338
|
-
const file2 = eventsPath(id, lane);
|
|
2339
|
-
try {
|
|
2340
|
-
fs19.utimesSync(file2, at, at);
|
|
2341
|
-
} catch {
|
|
2342
|
-
fs19.appendFileSync(file2, "");
|
|
2343
|
-
fs19.utimesSync(file2, at, at);
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
2645
|
// packages/core/dist/harness.js
|
|
2348
|
-
import * as
|
|
2349
|
-
import * as
|
|
2646
|
+
import * as fs23 from "node:fs";
|
|
2647
|
+
import * as path19 from "node:path";
|
|
2350
2648
|
import { createRequire } from "node:module";
|
|
2351
2649
|
function resolveOnPath(bin, pathVar = process.env.PATH) {
|
|
2352
2650
|
if (!pathVar)
|
|
2353
2651
|
return void 0;
|
|
2354
2652
|
const names = process.platform === "win32" ? [bin, `${bin}.exe`, `${bin}.cmd`, `${bin}.bat`] : [bin];
|
|
2355
|
-
for (const dir of pathVar.split(
|
|
2653
|
+
for (const dir of pathVar.split(path19.delimiter)) {
|
|
2356
2654
|
if (!dir)
|
|
2357
2655
|
continue;
|
|
2358
2656
|
for (const name of names) {
|
|
2359
|
-
const candidate =
|
|
2657
|
+
const candidate = path19.join(dir, name);
|
|
2360
2658
|
try {
|
|
2361
|
-
|
|
2362
|
-
if (
|
|
2659
|
+
fs23.accessSync(candidate, fs23.constants.X_OK);
|
|
2660
|
+
if (fs23.statSync(candidate).isFile())
|
|
2363
2661
|
return candidate;
|
|
2364
2662
|
} catch {
|
|
2365
2663
|
}
|
|
@@ -2380,8 +2678,8 @@ function codexInvocation(argv) {
|
|
|
2380
2678
|
} catch {
|
|
2381
2679
|
}
|
|
2382
2680
|
for (const dir of require_.resolve.paths("@openai/codex") ?? []) {
|
|
2383
|
-
const cli =
|
|
2384
|
-
if (
|
|
2681
|
+
const cli = path19.join(dir, "@openai", "codex", "bin", "codex.js");
|
|
2682
|
+
if (fs23.existsSync(cli))
|
|
2385
2683
|
return { file: process.execPath, argv: [cli, ...argv] };
|
|
2386
2684
|
}
|
|
2387
2685
|
return void 0;
|
|
@@ -2433,150 +2731,6 @@ function pushRule(branch, id = "<dispatch id>", mode = "rebase", also = []) {
|
|
|
2433
2731
|
].join(" ");
|
|
2434
2732
|
}
|
|
2435
2733
|
|
|
2436
|
-
// packages/core/dist/resume.js
|
|
2437
|
-
import * as fs21 from "node:fs";
|
|
2438
|
-
import * as os3 from "node:os";
|
|
2439
|
-
import * as path17 from "node:path";
|
|
2440
|
-
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
2441
|
-
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;
|
|
2442
|
-
function harnessFromSessionId(sessionId) {
|
|
2443
|
-
const version = sessionId ? UUID.exec(sessionId)?.[1] : void 0;
|
|
2444
|
-
return version === "7" ? "codex" : version === "4" ? "claude" : void 0;
|
|
2445
|
-
}
|
|
2446
|
-
function claimOf(id, lane) {
|
|
2447
|
-
const dirs = laneDirs(lane);
|
|
2448
|
-
for (const dir of [dirs.active, dirs.done]) {
|
|
2449
|
-
try {
|
|
2450
|
-
return JSON.parse(fs21.readFileSync(path17.join(dir, id, "claim.json"), "utf8"));
|
|
2451
|
-
} catch {
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
return void 0;
|
|
2455
|
-
}
|
|
2456
|
-
function laneOf2(id) {
|
|
2457
|
-
for (const lane of ["work", "chore"]) {
|
|
2458
|
-
if (storedDescriptor(id, lane) || readEvidence(id, lane).sessionId)
|
|
2459
|
-
return lane;
|
|
2460
|
-
}
|
|
2461
|
-
return void 0;
|
|
2462
|
-
}
|
|
2463
|
-
function resolveSessionHarness(id, cfg, laneHint) {
|
|
2464
|
-
const lane = laneHint ?? laneOf2(id);
|
|
2465
|
-
if (!lane)
|
|
2466
|
-
return {};
|
|
2467
|
-
const ev = readEvidence(id, lane);
|
|
2468
|
-
const sessionId = ev.sessionId;
|
|
2469
|
-
const out = (harness, source) => ({
|
|
2470
|
-
sessionId,
|
|
2471
|
-
harness,
|
|
2472
|
-
source,
|
|
2473
|
-
lane
|
|
2474
|
-
});
|
|
2475
|
-
if (ev.harness)
|
|
2476
|
-
return out(ev.harness, "evidence");
|
|
2477
|
-
const claim = claimOf(id, lane);
|
|
2478
|
-
if (claim?.harness)
|
|
2479
|
-
return out(claim.harness, "trap");
|
|
2480
|
-
if (ev.deliveredTo?.startsWith("wt:")) {
|
|
2481
|
-
const reg = readTrap(ev.deliveredTo.slice("wt:".length));
|
|
2482
|
-
if (reg?.harness)
|
|
2483
|
-
return out(reg.harness, "trap");
|
|
2484
|
-
}
|
|
2485
|
-
const byId = harnessFromSessionId(sessionId);
|
|
2486
|
-
if (byId)
|
|
2487
|
-
return out(byId, "session-id");
|
|
2488
|
-
const d = storedDescriptor(id, lane);
|
|
2489
|
-
const repo = d && cfg?.repos[d.repo];
|
|
2490
|
-
const fromDescriptor = d?.harness ?? repo?.harness?.default ?? cfg?.harness.default;
|
|
2491
|
-
if (fromDescriptor)
|
|
2492
|
-
return out(fromDescriptor, "descriptor");
|
|
2493
|
-
return { sessionId, lane };
|
|
2494
|
-
}
|
|
2495
|
-
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;
|
|
2496
|
-
function isUnresumable(error) {
|
|
2497
|
-
return error !== void 0 && UNRESUMABLE.test(error);
|
|
2498
|
-
}
|
|
2499
|
-
function worktreeProgress(worktree, trunk) {
|
|
2500
|
-
if (!worktree || !fs21.existsSync(worktree))
|
|
2501
|
-
return "No worktree progress recorded.";
|
|
2502
|
-
const git2 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
|
|
2503
|
-
const commits = trunk ? git2("log", "--oneline", `origin/${trunk}..HEAD`) : git2("log", "--oneline", "-15");
|
|
2504
|
-
const status = git2("status", "--short");
|
|
2505
|
-
return `Commits so far:
|
|
2506
|
-
${commits || "(none)"}
|
|
2507
|
-
|
|
2508
|
-
Uncommitted changes:
|
|
2509
|
-
${status || "(clean)"}`;
|
|
2510
|
-
}
|
|
2511
|
-
function originProgress(originId, lane) {
|
|
2512
|
-
const ev = readEvidence(originId, lane);
|
|
2513
|
-
const last = readStatusLog(originId, lane).at(-1);
|
|
2514
|
-
const lines = [`The earlier dispatch ${originId} left:`];
|
|
2515
|
-
if (ev.branch)
|
|
2516
|
-
lines.push(`- branch: ${ev.branch}`);
|
|
2517
|
-
if (ev.prUrl)
|
|
2518
|
-
lines.push(`- PR: ${ev.prUrl}`);
|
|
2519
|
-
if (last)
|
|
2520
|
-
lines.push(`- last status: ${last.verb}${last.note ? ` \u2014 ${last.note}` : ""}`);
|
|
2521
|
-
if (ev.commits?.length)
|
|
2522
|
-
lines.push("- commits:", ...ev.commits.map((c) => ` ${c}`));
|
|
2523
|
-
if (lines.length === 1)
|
|
2524
|
-
lines.push("- (no recorded branch, PR, or commits)");
|
|
2525
|
-
return lines.join("\n");
|
|
2526
|
-
}
|
|
2527
|
-
function handoffNote(fromHarness, progress, why) {
|
|
2528
|
-
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.
|
|
2529
|
-
|
|
2530
|
-
${progress}`;
|
|
2531
|
-
}
|
|
2532
|
-
function codexHome(env = process.env) {
|
|
2533
|
-
return env.CODEX_HOME ?? path17.join(os3.homedir(), ".codex");
|
|
2534
|
-
}
|
|
2535
|
-
function codexRolloutFile(threadId, home = codexHome()) {
|
|
2536
|
-
const suffix = `-${threadId}.jsonl`;
|
|
2537
|
-
const walk = (dir, depth) => {
|
|
2538
|
-
let entries;
|
|
2539
|
-
try {
|
|
2540
|
-
entries = fs21.readdirSync(dir, { withFileTypes: true });
|
|
2541
|
-
} catch {
|
|
2542
|
-
return void 0;
|
|
2543
|
-
}
|
|
2544
|
-
for (const e of entries) {
|
|
2545
|
-
if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
|
|
2546
|
-
return path17.join(dir, e.name);
|
|
2547
|
-
}
|
|
2548
|
-
if (depth === 0)
|
|
2549
|
-
return void 0;
|
|
2550
|
-
for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
|
|
2551
|
-
const hit = walk(path17.join(dir, e.name), depth - 1);
|
|
2552
|
-
if (hit)
|
|
2553
|
-
return hit;
|
|
2554
|
-
}
|
|
2555
|
-
return void 0;
|
|
2556
|
-
};
|
|
2557
|
-
return walk(path17.join(home, "sessions"), 3) ?? walk(path17.join(home, "archived_sessions"), 0);
|
|
2558
|
-
}
|
|
2559
|
-
function codexDesktopThread(threadId, home = codexHome()) {
|
|
2560
|
-
const file2 = codexRolloutFile(threadId, home);
|
|
2561
|
-
if (!file2)
|
|
2562
|
-
return void 0;
|
|
2563
|
-
let head = "";
|
|
2564
|
-
try {
|
|
2565
|
-
const fd = fs21.openSync(file2, "r");
|
|
2566
|
-
try {
|
|
2567
|
-
const buf = Buffer.alloc(4096);
|
|
2568
|
-
head = buf.subarray(0, fs21.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
|
|
2569
|
-
} finally {
|
|
2570
|
-
fs21.closeSync(fd);
|
|
2571
|
-
}
|
|
2572
|
-
} catch {
|
|
2573
|
-
return void 0;
|
|
2574
|
-
}
|
|
2575
|
-
const originator = /"originator"\s*:\s*"([^"]*)"/.exec(head)?.[1];
|
|
2576
|
-
return originator && /desktop/i.test(originator) ? originator : void 0;
|
|
2577
|
-
}
|
|
2578
|
-
var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
|
|
2579
|
-
|
|
2580
2734
|
// packages/core/dist/models.js
|
|
2581
2735
|
var MODEL_OWNERS = [
|
|
2582
2736
|
[/^(anthropic[/.])?(claude|opus|sonnet|haiku|fable)(\b|-|$)|^opusplan$/i, "claude"],
|
|
@@ -2598,8 +2752,8 @@ function droppedModelNote(harness, dropped) {
|
|
|
2598
2752
|
}
|
|
2599
2753
|
|
|
2600
2754
|
// packages/runner/src/run.ts
|
|
2601
|
-
import * as
|
|
2602
|
-
import * as
|
|
2755
|
+
import * as fs28 from "node:fs";
|
|
2756
|
+
import * as path24 from "node:path";
|
|
2603
2757
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
2604
2758
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
2605
2759
|
|
|
@@ -2895,25 +3049,25 @@ function createClaudeAdapter() {
|
|
|
2895
3049
|
}
|
|
2896
3050
|
|
|
2897
3051
|
// packages/adapters/dist/codex.js
|
|
2898
|
-
import * as
|
|
3052
|
+
import * as fs24 from "node:fs";
|
|
2899
3053
|
import * as os4 from "node:os";
|
|
2900
|
-
import * as
|
|
3054
|
+
import * as path20 from "node:path";
|
|
2901
3055
|
import { spawn as spawn2 } from "node:child_process";
|
|
2902
3056
|
function isolatedCodexHome() {
|
|
2903
|
-
const dir =
|
|
2904
|
-
|
|
2905
|
-
const auth =
|
|
2906
|
-
const realAuth =
|
|
2907
|
-
if (!
|
|
3057
|
+
const dir = path20.join(lobstahHome(), "codex-home");
|
|
3058
|
+
fs24.mkdirSync(dir, { recursive: true });
|
|
3059
|
+
const auth = path20.join(dir, "auth.json");
|
|
3060
|
+
const realAuth = path20.join(os4.homedir(), ".codex", "auth.json");
|
|
3061
|
+
if (!fs24.existsSync(auth) && fs24.existsSync(realAuth)) {
|
|
2908
3062
|
try {
|
|
2909
|
-
|
|
3063
|
+
fs24.symlinkSync(realAuth, auth);
|
|
2910
3064
|
} catch {
|
|
2911
|
-
|
|
3065
|
+
fs24.copyFileSync(realAuth, auth);
|
|
2912
3066
|
}
|
|
2913
3067
|
}
|
|
2914
|
-
const cfg =
|
|
2915
|
-
if (!
|
|
2916
|
-
|
|
3068
|
+
const cfg = path20.join(dir, "config.toml");
|
|
3069
|
+
if (!fs24.existsSync(cfg)) {
|
|
3070
|
+
fs24.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
|
|
2917
3071
|
}
|
|
2918
3072
|
return dir;
|
|
2919
3073
|
}
|
|
@@ -3116,15 +3270,15 @@ function loadAdapter(name) {
|
|
|
3116
3270
|
}
|
|
3117
3271
|
|
|
3118
3272
|
// packages/worktree/dist/index.js
|
|
3119
|
-
import * as
|
|
3120
|
-
import * as
|
|
3273
|
+
import * as fs26 from "node:fs";
|
|
3274
|
+
import * as path22 from "node:path";
|
|
3121
3275
|
import { createHash } from "node:crypto";
|
|
3122
3276
|
import { exec, execFile as execFile2, execFileSync } from "node:child_process";
|
|
3123
3277
|
import { promisify as promisify2 } from "node:util";
|
|
3124
3278
|
|
|
3125
3279
|
// packages/worktree/dist/pool.js
|
|
3126
|
-
import * as
|
|
3127
|
-
import * as
|
|
3280
|
+
import * as fs25 from "node:fs";
|
|
3281
|
+
import * as path21 from "node:path";
|
|
3128
3282
|
import { execFile } from "node:child_process";
|
|
3129
3283
|
import { promisify } from "node:util";
|
|
3130
3284
|
var run = promisify(execFile);
|
|
@@ -3186,17 +3340,17 @@ function takeOut(name, pool, slot, reason, dispatch, notice = true) {
|
|
|
3186
3340
|
function trapIn(dir) {
|
|
3187
3341
|
const real = (p) => {
|
|
3188
3342
|
try {
|
|
3189
|
-
return
|
|
3343
|
+
return fs25.realpathSync.native(p);
|
|
3190
3344
|
} catch {
|
|
3191
|
-
return
|
|
3345
|
+
return path21.resolve(p);
|
|
3192
3346
|
}
|
|
3193
3347
|
};
|
|
3194
3348
|
const here = real(dir);
|
|
3195
3349
|
return listTraps().some((t) => {
|
|
3196
3350
|
if (typeof t.worktree !== "string")
|
|
3197
3351
|
return false;
|
|
3198
|
-
const rel =
|
|
3199
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
3352
|
+
const rel = path21.relative(here, real(t.worktree));
|
|
3353
|
+
return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
3200
3354
|
});
|
|
3201
3355
|
}
|
|
3202
3356
|
async function claimPoolSlot(input) {
|
|
@@ -3204,7 +3358,7 @@ async function claimPoolSlot(input) {
|
|
|
3204
3358
|
const refused = [];
|
|
3205
3359
|
for (let slot = 1; slot <= pool.size; slot++) {
|
|
3206
3360
|
const dir = poolSlotPath(name, slot);
|
|
3207
|
-
if (
|
|
3361
|
+
if (fs25.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
|
|
3208
3362
|
writeSlotClaim(name, slot, { id, lane, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3209
3363
|
return { claimed: true, dir, slot, label: poolSlotLabel(name, slot) };
|
|
3210
3364
|
}
|
|
@@ -3252,7 +3406,7 @@ async function resetPoolWorktree(repo, dir, id, fromRemoteBranch = repo.trunk) {
|
|
|
3252
3406
|
}
|
|
3253
3407
|
var WARM_ID = "pool-warm";
|
|
3254
3408
|
async function createSlot(repo, dir) {
|
|
3255
|
-
|
|
3409
|
+
fs25.mkdirSync(path21.dirname(dir), { recursive: true });
|
|
3256
3410
|
await oneAtATime(repo.path, async () => {
|
|
3257
3411
|
await tryGit(repo.path, "worktree", "prune");
|
|
3258
3412
|
await gitShared(repo.path, "worktree", "add", "--detach", dir, `origin/${repo.trunk}`);
|
|
@@ -3274,7 +3428,7 @@ async function warmPool(name, opts = {}) {
|
|
|
3274
3428
|
if (!release)
|
|
3275
3429
|
return false;
|
|
3276
3430
|
try {
|
|
3277
|
-
if (!
|
|
3431
|
+
if (!fs25.existsSync(repo.path)) {
|
|
3278
3432
|
if (!repo.origin)
|
|
3279
3433
|
throw new Error(`repo path ${repo.path} missing and no origin configured`);
|
|
3280
3434
|
await run("git", ["clone", repo.origin, repo.path], { env: process.env });
|
|
@@ -3287,8 +3441,8 @@ async function warmPool(name, opts = {}) {
|
|
|
3287
3441
|
const dir = poolSlotPath(name, slot);
|
|
3288
3442
|
const label = poolSlotLabel(name, slot);
|
|
3289
3443
|
const meta = readSlotMeta(name, slot);
|
|
3290
|
-
if (!
|
|
3291
|
-
|
|
3444
|
+
if (!fs25.existsSync(dir)) {
|
|
3445
|
+
fs25.mkdirSync(poolsRoot(), { recursive: true });
|
|
3292
3446
|
let free = Infinity;
|
|
3293
3447
|
try {
|
|
3294
3448
|
free = need > 0 ? read2(poolsRoot()) : Infinity;
|
|
@@ -3431,7 +3585,7 @@ function pidAlive2(pid) {
|
|
|
3431
3585
|
var BUSY = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
3432
3586
|
function takeRepoLock(file2, mine) {
|
|
3433
3587
|
try {
|
|
3434
|
-
|
|
3588
|
+
fs26.writeFileSync(file2, mine, { flag: "wx" });
|
|
3435
3589
|
return { state: "held" };
|
|
3436
3590
|
} catch (err) {
|
|
3437
3591
|
const code = err.code ?? "";
|
|
@@ -3441,8 +3595,8 @@ function takeRepoLock(file2, mine) {
|
|
|
3441
3595
|
let raw = "";
|
|
3442
3596
|
let age = 0;
|
|
3443
3597
|
try {
|
|
3444
|
-
raw =
|
|
3445
|
-
age = Date.now() -
|
|
3598
|
+
raw = fs26.readFileSync(file2, "utf8");
|
|
3599
|
+
age = Date.now() - fs26.statSync(file2).mtimeMs;
|
|
3446
3600
|
} catch {
|
|
3447
3601
|
return { state: "retry" };
|
|
3448
3602
|
}
|
|
@@ -3455,8 +3609,8 @@ function takeRepoLock(file2, mine) {
|
|
|
3455
3609
|
const stale = age > REPO_LOCK_WAIT_MS || (holder ? !pidAlive2(holder.pid) : age > 5e3);
|
|
3456
3610
|
if (stale) {
|
|
3457
3611
|
try {
|
|
3458
|
-
if (
|
|
3459
|
-
|
|
3612
|
+
if (fs26.readFileSync(file2, "utf8") === raw)
|
|
3613
|
+
fs26.rmSync(file2, { force: true });
|
|
3460
3614
|
} catch {
|
|
3461
3615
|
}
|
|
3462
3616
|
return { state: "retry" };
|
|
@@ -3465,13 +3619,13 @@ function takeRepoLock(file2, mine) {
|
|
|
3465
3619
|
}
|
|
3466
3620
|
function releaseRepoLock(file2, mine) {
|
|
3467
3621
|
try {
|
|
3468
|
-
if (
|
|
3469
|
-
|
|
3622
|
+
if (fs26.readFileSync(file2, "utf8") === mine)
|
|
3623
|
+
fs26.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
|
|
3470
3624
|
} catch {
|
|
3471
3625
|
}
|
|
3472
3626
|
}
|
|
3473
3627
|
async function withRepoLock(common, fn) {
|
|
3474
|
-
const file2 =
|
|
3628
|
+
const file2 = path22.join(common, "lobstah-git.lock");
|
|
3475
3629
|
const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3476
3630
|
const deadline = Date.now() + REPO_LOCK_WAIT_MS;
|
|
3477
3631
|
let held = false;
|
|
@@ -3507,7 +3661,7 @@ async function oneAtATime(cwd, fn) {
|
|
|
3507
3661
|
}
|
|
3508
3662
|
function fetchStamps(common) {
|
|
3509
3663
|
try {
|
|
3510
|
-
return JSON.parse(
|
|
3664
|
+
return JSON.parse(fs26.readFileSync(path22.join(common, "lobstah-fetch.json"), "utf8"));
|
|
3511
3665
|
} catch {
|
|
3512
3666
|
return {};
|
|
3513
3667
|
}
|
|
@@ -3521,15 +3675,15 @@ async function fetchShared(cwd, remote, ref) {
|
|
|
3521
3675
|
const started = Date.now();
|
|
3522
3676
|
await gitShared(cwd, "fetch", remote, ref);
|
|
3523
3677
|
const stamps = { ...fetchStamps(common), [key]: started };
|
|
3524
|
-
|
|
3678
|
+
fs26.writeFileSync(path22.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
|
|
3525
3679
|
});
|
|
3526
3680
|
}
|
|
3527
3681
|
async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
|
|
3528
3682
|
const dir = worktreePath(id);
|
|
3529
|
-
if (
|
|
3683
|
+
if (fs26.existsSync(dir)) {
|
|
3530
3684
|
throw new Error(`worktree for ${id} already exists at ${dir} \u2014 never allocate a second`);
|
|
3531
3685
|
}
|
|
3532
|
-
if (!
|
|
3686
|
+
if (!fs26.existsSync(repo.path)) {
|
|
3533
3687
|
if (!repo.origin)
|
|
3534
3688
|
throw new Error(`repo path ${repo.path} missing and no origin configured`);
|
|
3535
3689
|
await run2("git", ["clone", repo.origin, repo.path], { env: process.env });
|
|
@@ -3544,7 +3698,7 @@ async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
|
|
|
3544
3698
|
async function recoverWorktree(repo, id) {
|
|
3545
3699
|
const dir = worktreePath(id);
|
|
3546
3700
|
try {
|
|
3547
|
-
if (
|
|
3701
|
+
if (fs26.statSync(path22.join(dir, ".git")).isFile()) {
|
|
3548
3702
|
const branch = await git(dir, "symbolic-ref", "--quiet", "HEAD");
|
|
3549
3703
|
const root = await git(dir, "rev-parse", "--show-toplevel");
|
|
3550
3704
|
const common = await git(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
@@ -3582,27 +3736,27 @@ function setupHash(repo, dir) {
|
|
|
3582
3736
|
const h = createHash("sha256");
|
|
3583
3737
|
h.update(JSON.stringify(repo.setup ?? []));
|
|
3584
3738
|
for (const name of LOCKFILES) {
|
|
3585
|
-
const file2 =
|
|
3586
|
-
if (!
|
|
3739
|
+
const file2 = path22.join(dir, name);
|
|
3740
|
+
if (!fs26.existsSync(file2))
|
|
3587
3741
|
continue;
|
|
3588
3742
|
h.update(`\0${name}\0`);
|
|
3589
|
-
h.update(
|
|
3743
|
+
h.update(fs26.readFileSync(file2));
|
|
3590
3744
|
}
|
|
3591
3745
|
return h.digest("hex");
|
|
3592
3746
|
}
|
|
3593
3747
|
function setupRecordFile(dir) {
|
|
3594
3748
|
const gitDir = worktreeGitDir(dir);
|
|
3595
|
-
return gitDir ?
|
|
3749
|
+
return gitDir ? path22.join(gitDir, "lobstah-setup.json") : void 0;
|
|
3596
3750
|
}
|
|
3597
3751
|
function recordSetup(repo, dir) {
|
|
3598
3752
|
const file2 = setupRecordFile(dir);
|
|
3599
3753
|
if (file2)
|
|
3600
|
-
|
|
3754
|
+
fs26.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
|
|
3601
3755
|
}
|
|
3602
3756
|
function recordedSetupHash(dir) {
|
|
3603
3757
|
const file2 = setupRecordFile(dir);
|
|
3604
3758
|
try {
|
|
3605
|
-
return file2 ? JSON.parse(
|
|
3759
|
+
return file2 ? JSON.parse(fs26.readFileSync(file2, "utf8")).hash : void 0;
|
|
3606
3760
|
} catch {
|
|
3607
3761
|
return void 0;
|
|
3608
3762
|
}
|
|
@@ -3615,9 +3769,9 @@ function poolReused(slot, by) {
|
|
|
3615
3769
|
function realpath(p) {
|
|
3616
3770
|
let r;
|
|
3617
3771
|
try {
|
|
3618
|
-
r =
|
|
3772
|
+
r = fs26.realpathSync.native(p);
|
|
3619
3773
|
} catch {
|
|
3620
|
-
r =
|
|
3774
|
+
r = path22.resolve(p);
|
|
3621
3775
|
}
|
|
3622
3776
|
return process.platform === "win32" ? r.toLowerCase() : r;
|
|
3623
3777
|
}
|
|
@@ -3665,8 +3819,8 @@ async function chooseWorktree(input) {
|
|
|
3665
3819
|
for (const t of listTraps()) {
|
|
3666
3820
|
if (typeof t.worktree !== "string")
|
|
3667
3821
|
continue;
|
|
3668
|
-
const rel =
|
|
3669
|
-
if (!rel.startsWith("..") && !
|
|
3822
|
+
const rel = path22.relative(here, realpath(t.worktree));
|
|
3823
|
+
if (!rel.startsWith("..") && !path22.isAbsolute(rel))
|
|
3670
3824
|
return { reuse: false, reason: "origin worktree is a trap\u2019s" };
|
|
3671
3825
|
}
|
|
3672
3826
|
for (const l of ["work", "chore"]) {
|
|
@@ -4094,8 +4248,8 @@ function startWallClock(opts) {
|
|
|
4094
4248
|
import { execFile as execFile3 } from "node:child_process";
|
|
4095
4249
|
import { promisify as promisify3 } from "node:util";
|
|
4096
4250
|
import { fileURLToPath } from "node:url";
|
|
4097
|
-
import * as
|
|
4098
|
-
import * as
|
|
4251
|
+
import * as fs27 from "node:fs";
|
|
4252
|
+
import * as path23 from "node:path";
|
|
4099
4253
|
var exec2 = promisify3(execFile3);
|
|
4100
4254
|
function firstLine(err) {
|
|
4101
4255
|
const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr).trim() : "";
|
|
@@ -4125,10 +4279,10 @@ function keepRemote(opts) {
|
|
|
4125
4279
|
const note = (message) => mergeEvidence(id, lane, { note: message.slice(0, 300) });
|
|
4126
4280
|
if (existingPrUrl) mergeEvidence(id, lane, { prUrl: existingPrUrl });
|
|
4127
4281
|
const registerWatch = async (url) => {
|
|
4128
|
-
const root =
|
|
4129
|
-
const localCli =
|
|
4282
|
+
const root = path23.resolve(path23.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
4283
|
+
const localCli = path23.join(root, "apps", "cli", "dist", "main.js");
|
|
4130
4284
|
const args = ["watch", "add", url, "--for", id];
|
|
4131
|
-
if (
|
|
4285
|
+
if (fs27.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
|
|
4132
4286
|
else await command("lobstah", args, 15e3);
|
|
4133
4287
|
};
|
|
4134
4288
|
let lastSeenHead;
|
|
@@ -4309,16 +4463,16 @@ function coldNote(cold, cwd, trunk) {
|
|
|
4309
4463
|
}
|
|
4310
4464
|
async function main(activeDir, lane, seams = {}) {
|
|
4311
4465
|
const deps = { ...defaultDeps, ...seams };
|
|
4312
|
-
const id =
|
|
4466
|
+
const id = path24.basename(activeDir);
|
|
4313
4467
|
if (isTrapCatch(id, lane)) throw new Error(`refusing headless runner for trap catch ${id}`);
|
|
4314
4468
|
const status = (verb, note) => appendStatus(id, lane, verb, note);
|
|
4315
4469
|
const cfg = loadConfig();
|
|
4316
|
-
const descriptor = JSON.parse(
|
|
4470
|
+
const descriptor = JSON.parse(fs28.readFileSync(path24.join(activeDir, "descriptor.json"), "utf8"));
|
|
4317
4471
|
const resolved = resolveDispatch(descriptor, cfg);
|
|
4318
4472
|
const repo = cfg.repos[descriptor.repo];
|
|
4319
|
-
const briefFile =
|
|
4320
|
-
if (!
|
|
4321
|
-
const brief =
|
|
4473
|
+
const briefFile = path24.join(activeDir, "brief.md");
|
|
4474
|
+
if (!fs28.existsSync(briefFile)) fs28.writeFileSync(briefFile, descriptor.brief);
|
|
4475
|
+
const brief = fs28.readFileSync(briefFile, "utf8");
|
|
4322
4476
|
const attempts = Number(process.env.LOBSTAH_ATTEMPTS ?? "1");
|
|
4323
4477
|
const wake = process.env.LOBSTAH_WAKE;
|
|
4324
4478
|
const runnerInfo = {
|
|
@@ -4326,7 +4480,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4326
4480
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4327
4481
|
attempts
|
|
4328
4482
|
};
|
|
4329
|
-
|
|
4483
|
+
fs28.writeFileSync(path24.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
|
|
4330
4484
|
if (descriptor.systemRepair && descriptor.pr?.url) {
|
|
4331
4485
|
const state = deps.prState(descriptor.pr.url) ?? readPr(parsePrRef(descriptor.pr.url)?.key ?? "")?.state;
|
|
4332
4486
|
if (state === "MERGED" || state === "CLOSED") {
|
|
@@ -4343,14 +4497,14 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4343
4497
|
resolvedHarness: resolved.harness,
|
|
4344
4498
|
envResume: process.env.LOBSTAH_RESUME
|
|
4345
4499
|
});
|
|
4346
|
-
const wtFile =
|
|
4500
|
+
const wtFile = path24.join(activeDir, "worktree.json");
|
|
4347
4501
|
let recorded;
|
|
4348
4502
|
let recovered = false;
|
|
4349
4503
|
let choice3;
|
|
4350
|
-
if (
|
|
4351
|
-
recorded = JSON.parse(
|
|
4352
|
-
if (!
|
|
4353
|
-
} else if (
|
|
4504
|
+
if (fs28.existsSync(wtFile)) {
|
|
4505
|
+
recorded = JSON.parse(fs28.readFileSync(wtFile, "utf8")).path;
|
|
4506
|
+
if (!fs28.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
|
|
4507
|
+
} else if (fs28.existsSync(worktreePath(id))) {
|
|
4354
4508
|
recorded = await recoverWorktree(repo, id);
|
|
4355
4509
|
recovered = true;
|
|
4356
4510
|
} else if (descriptor.followUp && cfg.limits.reuseWorktree !== false) {
|
|
@@ -4405,7 +4559,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4405
4559
|
if (held) throw new Error(`worktree at ${cwd} is in use by ${held.id} \u2014 wait for that dispatch to release it before retrying`);
|
|
4406
4560
|
if (recovered) {
|
|
4407
4561
|
await deps.prepareReuse(repo, cwd);
|
|
4408
|
-
|
|
4562
|
+
fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
|
|
4409
4563
|
}
|
|
4410
4564
|
} else if (choice3?.reuse) {
|
|
4411
4565
|
cwd = choice3.path;
|
|
@@ -4416,17 +4570,17 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4416
4570
|
type: "runner",
|
|
4417
4571
|
data: { worktree: cwd, worktreeOf: choice3.owner, setupRan }
|
|
4418
4572
|
});
|
|
4419
|
-
|
|
4573
|
+
fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
|
|
4420
4574
|
} else if (poolClaim) {
|
|
4421
4575
|
cwd = poolClaim.dir;
|
|
4422
4576
|
await deps.resetPool(repo, cwd, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
|
|
4423
|
-
|
|
4577
|
+
fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
|
|
4424
4578
|
} else {
|
|
4425
4579
|
cwd = await deps.allocate(repo, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
|
|
4426
4580
|
acquireWorktreeLock(cwd, id, lane);
|
|
4427
|
-
|
|
4581
|
+
fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
|
|
4428
4582
|
}
|
|
4429
|
-
const worktreeOf = JSON.parse(
|
|
4583
|
+
const worktreeOf = JSON.parse(fs28.readFileSync(wtFile, "utf8")).of;
|
|
4430
4584
|
const inPool = poolSlotOf(cwd);
|
|
4431
4585
|
mergeEvidence(id, lane, { worktree: cwd, worktreeOf, ...inPool ? { pool: poolSlotLabel(inPool.pool, inPool.slot) } : {} });
|
|
4432
4586
|
const existingPr = boundPr(descriptor, lane);
|
|
@@ -4458,14 +4612,14 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4458
4612
|
const envNudge = [process.env.LOBSTAH_NUDGE, wakeNote()].filter(Boolean).join("\n\n") || void 0;
|
|
4459
4613
|
const planNudge = plan.cold && !envNudge ? coldNote(plan.cold, cwd, repo.trunk) : void 0;
|
|
4460
4614
|
const promptWith = (nudge) => buildPrompt(brief, { id, nudge, attachments: descriptor.attachments, existingPr });
|
|
4461
|
-
const binDir =
|
|
4462
|
-
const workerPath =
|
|
4615
|
+
const binDir = path24.resolve(path24.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
|
|
4616
|
+
const workerPath = fs28.existsSync(path24.join(binDir, "lobstah")) ? `${binDir}${path24.delimiter}${process.env.PATH ?? ""}` : void 0;
|
|
4463
4617
|
let wallClockHit = false;
|
|
4464
4618
|
let current;
|
|
4465
|
-
const wallFile =
|
|
4619
|
+
const wallFile = path24.join(activeDir, "wallclock.json");
|
|
4466
4620
|
const wallState = (() => {
|
|
4467
4621
|
try {
|
|
4468
|
-
return JSON.parse(
|
|
4622
|
+
return JSON.parse(fs28.readFileSync(wallFile, "utf8"));
|
|
4469
4623
|
} catch {
|
|
4470
4624
|
return { elapsedMs: 0, windowMs: resolved.limits.wallClockSecs * 1e3 };
|
|
4471
4625
|
}
|
|
@@ -4484,8 +4638,8 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4484
4638
|
) * 1e3;
|
|
4485
4639
|
const persistWall = (elapsedMs, windowMs) => {
|
|
4486
4640
|
const tmp = uniqueTempPath(wallFile);
|
|
4487
|
-
|
|
4488
|
-
|
|
4641
|
+
fs28.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
|
|
4642
|
+
fs28.renameSync(tmp, wallFile);
|
|
4489
4643
|
};
|
|
4490
4644
|
const madeProgress = () => {
|
|
4491
4645
|
const activity = readActivity(id, lane);
|
|
@@ -4652,6 +4806,53 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4652
4806
|
|
|
4653
4807
|
// packages/runner/src/reap.ts
|
|
4654
4808
|
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
4809
|
+
|
|
4810
|
+
// packages/runner/src/windows-processes.ts
|
|
4811
|
+
var WINDOWS_PROCESS_SNAPSHOT = String.raw`
|
|
4812
|
+
$ErrorActionPreference = 'Stop'
|
|
4813
|
+
Add-Type -TypeDefinition @'
|
|
4814
|
+
using System;
|
|
4815
|
+
using System.ComponentModel;
|
|
4816
|
+
using System.Runtime.InteropServices;
|
|
4817
|
+
public static class LobstahProcessSnapshot {
|
|
4818
|
+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
4819
|
+
public struct Entry {
|
|
4820
|
+
public uint size, usage, pid;
|
|
4821
|
+
public UIntPtr heap;
|
|
4822
|
+
public uint module, threads, parent;
|
|
4823
|
+
public int priority;
|
|
4824
|
+
public uint flags;
|
|
4825
|
+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string exe;
|
|
4826
|
+
}
|
|
4827
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
4828
|
+
static extern IntPtr CreateToolhelp32Snapshot(uint flags, uint pid);
|
|
4829
|
+
[DllImport("kernel32.dll", EntryPoint = "Process32FirstW", ExactSpelling = true, SetLastError = true)]
|
|
4830
|
+
static extern bool First(IntPtr snapshot, ref Entry entry);
|
|
4831
|
+
[DllImport("kernel32.dll", EntryPoint = "Process32NextW", ExactSpelling = true, SetLastError = true)]
|
|
4832
|
+
static extern bool Next(IntPtr snapshot, ref Entry entry);
|
|
4833
|
+
[DllImport("kernel32.dll")]
|
|
4834
|
+
static extern bool CloseHandle(IntPtr handle);
|
|
4835
|
+
public static void Print() {
|
|
4836
|
+
IntPtr snapshot = CreateToolhelp32Snapshot(2, 0); // TH32CS_SNAPPROCESS only
|
|
4837
|
+
if (snapshot == new IntPtr(-1)) throw new Win32Exception(Marshal.GetLastWin32Error());
|
|
4838
|
+
try {
|
|
4839
|
+
Entry entry = new Entry();
|
|
4840
|
+
entry.size = (uint)Marshal.SizeOf(typeof(Entry));
|
|
4841
|
+
bool more = First(snapshot, ref entry);
|
|
4842
|
+
while (more) {
|
|
4843
|
+
Console.WriteLine("{0} {1}", entry.pid, entry.parent);
|
|
4844
|
+
more = Next(snapshot, ref entry);
|
|
4845
|
+
}
|
|
4846
|
+
int error = Marshal.GetLastWin32Error();
|
|
4847
|
+
if (error != 18) throw new Win32Exception(error); // ERROR_NO_MORE_FILES
|
|
4848
|
+
} finally { CloseHandle(snapshot); }
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
'@
|
|
4852
|
+
[LobstahProcessSnapshot]::Print()
|
|
4853
|
+
`;
|
|
4854
|
+
|
|
4855
|
+
// packages/runner/src/reap.ts
|
|
4655
4856
|
function listProcesses() {
|
|
4656
4857
|
if (process.platform === "win32") {
|
|
4657
4858
|
const out2 = execFileSync3(
|
|
@@ -4660,7 +4861,7 @@ function listProcesses() {
|
|
|
4660
4861
|
"-NoProfile",
|
|
4661
4862
|
"-NonInteractive",
|
|
4662
4863
|
"-Command",
|
|
4663
|
-
|
|
4864
|
+
WINDOWS_PROCESS_SNAPSHOT
|
|
4664
4865
|
],
|
|
4665
4866
|
{ encoding: "utf8", windowsHide: true, timeout: 3e4, stdio: ["ignore", "pipe", "ignore"] }
|
|
4666
4867
|
);
|
|
@@ -4742,13 +4943,13 @@ async function reapStarted(root = process.pid, graceMs) {
|
|
|
4742
4943
|
var EXIT_LINGER_MS = 5e3;
|
|
4743
4944
|
function runRunner(activeDirArg2, laneArg2) {
|
|
4744
4945
|
const lane = laneArg2 === "chore" ? "chore" : "work";
|
|
4745
|
-
const id =
|
|
4946
|
+
const id = path25.basename(activeDirArg2);
|
|
4746
4947
|
main(activeDirArg2, lane, { reap: () => reapStarted(process.pid) }).catch((err) => {
|
|
4747
4948
|
try {
|
|
4748
4949
|
if (!isFinished(id, lane)) {
|
|
4749
4950
|
appendStatus(id, lane, "failed", String(err instanceof Error ? err.message : err).slice(0, 500));
|
|
4750
4951
|
}
|
|
4751
|
-
|
|
4952
|
+
fs29.renameSync(activeDirArg2, path25.join(laneDirs(lane).done, id));
|
|
4752
4953
|
} catch {
|
|
4753
4954
|
}
|
|
4754
4955
|
process.exitCode = 1;
|