pi-straw-boss 0.94.0 → 0.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/main.mjs +411 -328
- package/package.json +1 -1
- package/src/bosspair.ts +5 -5
- package/src/control.ts +3 -3
- package/src/headroutes.ts +2 -2
- package/src/reach.ts +4 -4
- package/src/server/ledger.ts +55 -0
- package/src/server/linkwaits.ts +11 -1
- package/src/server/threads.ts +26 -12
- package/src/server/threadsops.ts +11 -5
- package/src/server/towermemory.ts +29 -3
- package/src/server/towerpanel.ts +2 -2
- package/src/server/waitpress.ts +6 -3
- package/src/tools.ts +4 -4
- package/src/wrapup.ts +8 -8
package/dist/server/main.mjs
CHANGED
|
@@ -301,7 +301,7 @@ import {
|
|
|
301
301
|
|
|
302
302
|
// src/server/main.ts
|
|
303
303
|
import { homedir as homedir18 } from "node:os";
|
|
304
|
-
import { join as
|
|
304
|
+
import { join as join64 } from "node:path";
|
|
305
305
|
|
|
306
306
|
// src/boardauto.ts
|
|
307
307
|
import { posix, win32 } from "node:path";
|
|
@@ -2937,11 +2937,11 @@ async function forwardOpenedWait(d, route, from, event, text14) {
|
|
|
2937
2937
|
// src/server/linkwaits.ts
|
|
2938
2938
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
2939
2939
|
import { readFileSync as readFileSync11 } from "node:fs";
|
|
2940
|
-
import { join as
|
|
2940
|
+
import { join as join16 } from "node:path";
|
|
2941
2941
|
|
|
2942
2942
|
// src/server/towermemory.ts
|
|
2943
2943
|
import { readFileSync as readFileSync10 } from "node:fs";
|
|
2944
|
-
import { join as
|
|
2944
|
+
import { join as join15 } from "node:path";
|
|
2945
2945
|
|
|
2946
2946
|
// src/server/waitcard.ts
|
|
2947
2947
|
var CARD = { happened: 160, do: 160, url: 300, command: 300, commandLines: 4, after: 160, label: 24, then: 120, name: 60, from: 200, optionsMin: 2, optionsMax: 4, reason: 120, dueMin: 5, dueMax: 7 * 24 * 60 };
|
|
@@ -3261,16 +3261,59 @@ function createHeadReach({ read: read4, deliver }) {
|
|
|
3261
3261
|
};
|
|
3262
3262
|
}
|
|
3263
3263
|
|
|
3264
|
+
// src/server/ledger.ts
|
|
3265
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
3266
|
+
import { dirname as dirname4, join as join11 } from "node:path";
|
|
3267
|
+
var KINDS2 = ["wait_raised", "wait_answered", "wait_closed", "wait_returned", "wait_parked", "link_wait_open", "link_wait_done", "thread_open", "thread_close", "call_tower", "wrap", "handover"];
|
|
3268
|
+
var WHYS2 = { wait_closed: ["resolved", "dropped"], thread_close: ["done", "blocked", "abandoned"], call_tower: ["milestone", "shared", "blocked"], wrap: ["wrapped", "refused", "auto"] };
|
|
3269
|
+
var BYS = ["terminal", "gui", "phone", "box", "tower"];
|
|
3270
|
+
var ID = /^[A-Za-z0-9_.:#@+=|-]{1,160}$/;
|
|
3271
|
+
var ledgerId = (v) => typeof v === "string" && ID.test(v) ? v : null;
|
|
3272
|
+
var ITEM = /^(?:t_[A-Za-z2-7]{10}|[A-Za-z0-9_-]{1,64}#[1-9][0-9]{0,5})$/;
|
|
3273
|
+
var ledgerFile = (stateDir, at) => join11(stateDir, "ledger", `${new Date(at).toISOString().slice(0, 10)}.jsonl`);
|
|
3274
|
+
function ledgerRow(e, at) {
|
|
3275
|
+
const id2 = ledgerId(e.id);
|
|
3276
|
+
if (!id2 || !KINDS2.includes(e.kind)) return void 0;
|
|
3277
|
+
const why = e.why !== void 0 && WHYS2[e.kind]?.includes(e.why) ? e.why : void 0, item = typeof e.item === "string" && ITEM.test(e.item) ? e.item : void 0;
|
|
3278
|
+
const by = e.kind === "wait_answered" && e.by !== void 0 && BYS.includes(e.by) ? e.by : void 0;
|
|
3279
|
+
return { v: 1, at, kind: e.kind, id: id2, session: ledgerId(e.session), workspace: ledgerId(e.workspace), ...why ? { why } : {}, ...item ? { item } : {}, ...by ? { by } : {} };
|
|
3280
|
+
}
|
|
3281
|
+
var warned = /* @__PURE__ */ new Set();
|
|
3282
|
+
var ledgerSink = {};
|
|
3283
|
+
function noteLedger(stateDir, e, at = Date.now(), warn = ledgerSink.warn) {
|
|
3284
|
+
if (!stateDir) return;
|
|
3285
|
+
const row2 = ledgerRow(e, at);
|
|
3286
|
+
if (!row2) return;
|
|
3287
|
+
const file3 = ledgerFile(stateDir, at), line4 = `${JSON.stringify(row2)}
|
|
3288
|
+
`;
|
|
3289
|
+
try {
|
|
3290
|
+
try {
|
|
3291
|
+
appendFileSync2(file3, line4, { mode: 384 });
|
|
3292
|
+
} catch (error) {
|
|
3293
|
+
if (error.code !== "ENOENT") throw error;
|
|
3294
|
+
mkdirSync3(dirname4(file3), { recursive: true, mode: 448 });
|
|
3295
|
+
appendFileSync2(file3, line4, { mode: 384 });
|
|
3296
|
+
}
|
|
3297
|
+
} catch (error) {
|
|
3298
|
+
if (warned.has(stateDir) || !warn) return;
|
|
3299
|
+
warned.add(stateDir);
|
|
3300
|
+
try {
|
|
3301
|
+
warn(`Straw Boss: the event ledger (${dirname4(file3)}) cannot be written (${error.code ?? error.message}); what it records goes on unrecorded.`);
|
|
3302
|
+
} catch {
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
|
|
3264
3307
|
// src/server/towerruns.ts
|
|
3265
3308
|
import { readFileSync as readFileSync7 } from "node:fs";
|
|
3266
|
-
import { join as
|
|
3309
|
+
import { join as join12 } from "node:path";
|
|
3267
3310
|
var DEFAULT_MAX = 4;
|
|
3268
3311
|
function readTowerRuns(stateDir) {
|
|
3269
3312
|
let section, problem;
|
|
3270
3313
|
try {
|
|
3271
|
-
section = JSON.parse(readFileSync7(
|
|
3314
|
+
section = JSON.parse(readFileSync7(join12(stateDir, "config.json"), "utf8")).towerRuns;
|
|
3272
3315
|
} catch (cause) {
|
|
3273
|
-
if (cause.code !== "ENOENT") problem = `${
|
|
3316
|
+
if (cause.code !== "ENOENT") problem = `${join12(stateDir, "config.json")} cannot be read (${cause.message.slice(0, 120)}), so towerRuns.enabled and max are the defaults: the tower service is on`;
|
|
3274
3317
|
}
|
|
3275
3318
|
const found = typeof section === "object" && section !== null ? section : {};
|
|
3276
3319
|
const max = typeof found.max === "number" && Number.isInteger(found.max) && found.max > 0 ? found.max : DEFAULT_MAX;
|
|
@@ -3281,7 +3324,7 @@ var towerRunsEnabled = (stateDir) => readTowerRuns(stateDir).enabled;
|
|
|
3281
3324
|
// src/trust/settings.ts
|
|
3282
3325
|
import { spawn } from "node:child_process";
|
|
3283
3326
|
import { lstat } from "node:fs/promises";
|
|
3284
|
-
import { join as
|
|
3327
|
+
import { join as join13 } from "node:path";
|
|
3285
3328
|
|
|
3286
3329
|
// src/trust/found.ts
|
|
3287
3330
|
import { createHash as createHash4 } from "node:crypto";
|
|
@@ -3371,9 +3414,9 @@ var runChild = (dir, timeoutMs = PROBE_TIMEOUT_MS, node = process.execPath) => n
|
|
|
3371
3414
|
child.on("close", (status) => done2(status === 0 ? { out } : { failed: "crash" }));
|
|
3372
3415
|
});
|
|
3373
3416
|
async function settingsRefusal(dir, run3 = runChild) {
|
|
3374
|
-
const path =
|
|
3417
|
+
const path = join13(dir, ".pi", "settings.json");
|
|
3375
3418
|
try {
|
|
3376
|
-
await lstat(
|
|
3419
|
+
await lstat(join13(dir, ".pi"));
|
|
3377
3420
|
} catch (error) {
|
|
3378
3421
|
const code = error.code;
|
|
3379
3422
|
if (code === "ENOENT" || code === "ENOTDIR") return;
|
|
@@ -3420,9 +3463,9 @@ async function assertSettingsSafe(dirs, what, run3) {
|
|
|
3420
3463
|
}
|
|
3421
3464
|
|
|
3422
3465
|
// src/trust/files.ts
|
|
3423
|
-
import { chmodSync as chmodSync3, lstatSync as lstatSync3, realpathSync as realpathSync4, mkdirSync as
|
|
3466
|
+
import { chmodSync as chmodSync3, lstatSync as lstatSync3, realpathSync as realpathSync4, mkdirSync as mkdirSync4, readdirSync as readdirSync3, readFileSync as readFileSync9, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3424
3467
|
import { homedir as homedir4 } from "node:os";
|
|
3425
|
-
import { join as
|
|
3468
|
+
import { join as join14, relative as relative2, isAbsolute as isAbsolute3 } from "node:path";
|
|
3426
3469
|
|
|
3427
3470
|
// src/trust/types.ts
|
|
3428
3471
|
var CHOICES = ["trust", "once", "no"];
|
|
@@ -3434,7 +3477,7 @@ var ROLES = ["member", "main", "tower", "subagent", "none"];
|
|
|
3434
3477
|
var RESULT_KEEP_MS = 12e4;
|
|
3435
3478
|
var STALE_MS2 = 6e4;
|
|
3436
3479
|
var MAX_FILE = MAX_FOUND + 4096;
|
|
3437
|
-
var trustDir = (state) =>
|
|
3480
|
+
var trustDir = (state) => join14(state, "trust");
|
|
3438
3481
|
var uid = () => process.getuid?.();
|
|
3439
3482
|
var CONFIRM_MS = 3e4;
|
|
3440
3483
|
var confirmed = /* @__PURE__ */ new Map();
|
|
@@ -3447,8 +3490,8 @@ var lives = (r, wrote, start) => {
|
|
|
3447
3490
|
};
|
|
3448
3491
|
function ensureDir2(dir, ids = process.getuid !== void 0, home = homedir4()) {
|
|
3449
3492
|
try {
|
|
3450
|
-
|
|
3451
|
-
|
|
3493
|
+
mkdirSync4(join14(dir, ".."), { recursive: true, mode: 448 });
|
|
3494
|
+
mkdirSync4(dir, { recursive: true, mode: 448 });
|
|
3452
3495
|
const st = lstatSync3(dir);
|
|
3453
3496
|
if (!st.isDirectory() || st.isSymbolicLink() || ids && st.uid !== uid()) return false;
|
|
3454
3497
|
if (!ids) {
|
|
@@ -3463,12 +3506,12 @@ function ensureDir2(dir, ids = process.getuid !== void 0, home = homedir4()) {
|
|
|
3463
3506
|
}
|
|
3464
3507
|
var temps = 0;
|
|
3465
3508
|
function writeAtomic(dir, name2, value) {
|
|
3466
|
-
const temp =
|
|
3509
|
+
const temp = join14(dir, `${name2}.${process.pid}.${temps++}.tmp`);
|
|
3467
3510
|
try {
|
|
3468
3511
|
writeFileSync3(temp, JSON.stringify(value), { mode: 384, flag: "wx" });
|
|
3469
3512
|
for (let tries = 0; ; tries++) {
|
|
3470
3513
|
try {
|
|
3471
|
-
return renameSync3(temp,
|
|
3514
|
+
return renameSync3(temp, join14(dir, name2));
|
|
3472
3515
|
} catch (error) {
|
|
3473
3516
|
if (tries >= 20 || !["EPERM", "EBUSY", "EACCES"].includes(error.code ?? "")) throw error;
|
|
3474
3517
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
@@ -3508,8 +3551,8 @@ function resultOf(value, id2) {
|
|
|
3508
3551
|
var requestFile = (id2) => `${id2}.json`;
|
|
3509
3552
|
var answerFile = (id2) => `${id2}.answer.json`;
|
|
3510
3553
|
var resultFile = (id2) => `${id2}.result.json`;
|
|
3511
|
-
var readResult = (dir, id2) => ((f) => f ? resultOf(f.value, id2) : void 0)(readJson(
|
|
3512
|
-
var remove = (dir, ...names) => names.forEach((n) => rmSync2(
|
|
3554
|
+
var readResult = (dir, id2) => ((f) => f ? resultOf(f.value, id2) : void 0)(readJson(join14(dir, resultFile(id2)), 4096));
|
|
3555
|
+
var remove = (dir, ...names) => names.forEach((n) => rmSync2(join14(dir, n), { force: true }));
|
|
3513
3556
|
function listRequests(dir, alive2 = lives) {
|
|
3514
3557
|
let names;
|
|
3515
3558
|
try {
|
|
@@ -3521,7 +3564,7 @@ function listRequests(dir, alive2 = lives) {
|
|
|
3521
3564
|
for (const name2 of names) {
|
|
3522
3565
|
const id2 = /^(.+)\.json$/.exec(name2)?.[1];
|
|
3523
3566
|
if (!id2 || !UUID.test(id2)) continue;
|
|
3524
|
-
const file3 = readJson(
|
|
3567
|
+
const file3 = readJson(join14(dir, name2)), r = file3 && requestOf(file3.value, id2);
|
|
3525
3568
|
if (r && alive2(r, file3.mtime)) out.push(r);
|
|
3526
3569
|
}
|
|
3527
3570
|
return out.sort((a, b) => a.at - b.at);
|
|
@@ -3535,7 +3578,7 @@ function sweep(dir, now = Date.now(), alive2 = lives) {
|
|
|
3535
3578
|
}
|
|
3536
3579
|
const ids = /* @__PURE__ */ new Set();
|
|
3537
3580
|
for (const name2 of names) {
|
|
3538
|
-
const file3 = readJson(
|
|
3581
|
+
const file3 = readJson(join14(dir, name2), MAX_FILE), age2 = now - (file3?.mtime ?? lstatMtime(join14(dir, name2)) ?? now), id2 = name2.split(".")[0] ?? "";
|
|
3539
3582
|
if (name2.endsWith(".tmp")) age2 > STALE_MS2 && remove(dir, name2);
|
|
3540
3583
|
else if (!UUID.test(id2)) continue;
|
|
3541
3584
|
else if (name2 === requestFile(id2)) {
|
|
@@ -3546,7 +3589,7 @@ function sweep(dir, now = Date.now(), alive2 = lives) {
|
|
|
3546
3589
|
}
|
|
3547
3590
|
for (const name2 of names) {
|
|
3548
3591
|
const id2 = /^(.+)\.answer\.json$/.exec(name2)?.[1];
|
|
3549
|
-
if (id2 && !ids.has(id2) && now - (lstatMtime(
|
|
3592
|
+
if (id2 && !ids.has(id2) && now - (lstatMtime(join14(dir, name2)) ?? now) > STALE_MS2) remove(dir, name2);
|
|
3550
3593
|
}
|
|
3551
3594
|
}
|
|
3552
3595
|
var lstatMtime = (file3) => {
|
|
@@ -3780,6 +3823,7 @@ function createReach({ pi, cfg, s: s2, guiDir, me, role, tell: tell2 }, server =
|
|
|
3780
3823
|
const tower = await openTower2(workspace);
|
|
3781
3824
|
const result2 = await post(tower.id, message, "call_tower", "tower", reply3, void 0, reason, extra);
|
|
3782
3825
|
if (result2.status !== "sent") throw new Error(`The tower of ${tower.target.label} did not take the message: ${result2.status} ${result2.code ?? ""} ${result2.detail ?? ""}`.trim());
|
|
3826
|
+
noteLedger(guiDir, { kind: "call_tower", id: result2.requestId?.replace(/~r\d+$/, "") ?? tower.id, session: me(), workspace: s2.at?.workspaceId, why: reason }, cfg.now(), (text15) => tell2(text15, "warning"));
|
|
3783
3827
|
const via = tower.routed ? ` (${tower.routed.label} is a sub workspace)` : "";
|
|
3784
3828
|
const text14 = `Sent to the tower of ${tower.target.label}${via}${tower.opened ? " (opened it)" : ""}. ${reply3 ? "It replies through intercom." : "It is told no reply is expected."}`;
|
|
3785
3829
|
return { text: text14, details: { workspace: tower.target.workspace_id, towerId: tower.id, opened: tower.opened, status: result2.status } };
|
|
@@ -4005,7 +4049,7 @@ function tidy2(what, text14, max) {
|
|
|
4005
4049
|
if (chars2(out) > max) throw new Error(`${what} is too long: at most ${max} characters`);
|
|
4006
4050
|
return out;
|
|
4007
4051
|
}
|
|
4008
|
-
var fileOf2 = (slot, workspace) =>
|
|
4052
|
+
var fileOf2 = (slot, workspace) => join15(towerDir(slot, workspace), "memory.json");
|
|
4009
4053
|
var isEntry = (e) => {
|
|
4010
4054
|
const v = e;
|
|
4011
4055
|
return typeof v === "object" && v !== null && typeof v.id === "string" && /^[SDW]\d+$/.test(v.id) && v.id[0] === LETTER[v.kind] && typeof v.text === "string" && (v.by === "boss" || v.by === "run") && typeof v.at === "string" && (v.kind !== "wait" || ["open", "answered", "resolved", "expired"].includes(String(v.state)));
|
|
@@ -4041,20 +4085,38 @@ function loadMemory(slot, workspace) {
|
|
|
4041
4085
|
const asked3 = revived.map((e) => ({ id: `P${next2.P++}`, op: "add", kind: e.kind, text: e.text, run: e.run ?? "earlier build", at: e.at }));
|
|
4042
4086
|
return { memory: { v: 1, rev: raw.rev, next: next2, entries: entries3, proposals: [...proposals, ...asked3] } };
|
|
4043
4087
|
}
|
|
4044
|
-
function updateMemory(slot, workspace, now, change, rev) {
|
|
4088
|
+
function updateMemory(slot, workspace, now, change, rev, by = "tower") {
|
|
4045
4089
|
const { memory, problem } = loadMemory(slot, workspace);
|
|
4046
4090
|
if (problem) throw new Error(problem);
|
|
4047
4091
|
if (rev !== void 0 && rev !== memory.rev) throw Object.assign(new Error("The memory changed since you read it"), { code: "rev", memory });
|
|
4048
4092
|
sweep2(memory, now);
|
|
4049
|
-
const before = JSON.stringify(memory);
|
|
4093
|
+
const before = JSON.stringify(memory), was = marks(memory);
|
|
4050
4094
|
const value = change(memory);
|
|
4051
4095
|
if (JSON.stringify(memory) === before) return { value, memory };
|
|
4052
4096
|
memory.rev += 1;
|
|
4053
4097
|
secretDir(towersDir(slot));
|
|
4054
4098
|
ensureDir(towerDir(slot, workspace));
|
|
4055
4099
|
writeDurable(fileOf2(slot, workspace), memory);
|
|
4100
|
+
noteWaits(slot, workspace, now, was, memory, by);
|
|
4056
4101
|
return { value, memory };
|
|
4057
4102
|
}
|
|
4103
|
+
var marks = (m) => new Map(m.entries.filter((e) => e.kind === "wait").map((e) => [e.id, { state: e.state, press: e.press?.at, parked: e.parked === true, returned: e.returned, session: sessionOf(e) }]));
|
|
4104
|
+
function noteWaits(slot, workspace, now, was, m, by) {
|
|
4105
|
+
const note = (kind, id2, session, extra = {}) => noteLedger(slot.stateDir, { kind, id: id2, session, workspace, ...extra }, now);
|
|
4106
|
+
for (const e of m.entries) {
|
|
4107
|
+
if (e.kind !== "wait") continue;
|
|
4108
|
+
const old = was.get(e.id), session = sessionOf(e);
|
|
4109
|
+
if (!old) note("wait_raised", e.id, session);
|
|
4110
|
+
if (e.parked && !old?.parked) note("wait_parked", e.id, session);
|
|
4111
|
+
const answered = old && (e.press && e.press.at !== old.press && e.press.act !== "secret" || old.state === "open" && e.state === "answered");
|
|
4112
|
+
if (answered) note("wait_answered", e.id, session, { by });
|
|
4113
|
+
if (e.returned && !old?.returned) note("wait_returned", e.id, session);
|
|
4114
|
+
else if (old?.state === "open" && e.state === "resolved" && !answered) note("wait_closed", e.id, session, { why: "resolved" });
|
|
4115
|
+
}
|
|
4116
|
+
const kept = new Set(m.entries.map((e) => e.id));
|
|
4117
|
+
for (const [id2, old] of was) if (!kept.has(id2) && (old.state === "open" || old.state === "answered")) note("wait_closed", id2, old.session, { why: "dropped" });
|
|
4118
|
+
}
|
|
4119
|
+
var sessionOf = (e) => ((from) => from && !from.startsWith("link:") ? from : e.on?.id ?? null)(e.card?.from?.id);
|
|
4058
4120
|
var isOpen = (e) => e.kind === "wait" && (e.state === "open" || e.state === "answered");
|
|
4059
4121
|
var idFor = (m, kind) => `${LETTER[kind]}${m.next[LETTER[kind]]++}`;
|
|
4060
4122
|
function sweep2(m, now) {
|
|
@@ -4544,7 +4606,7 @@ var CLOSED = /* @__PURE__ */ new Set(["done", "declined", "cancelled", "expired"
|
|
|
4544
4606
|
var DELEGABLE = /* @__PURE__ */ new Set(["wait", "incident", "question"]);
|
|
4545
4607
|
var RANK = { open: 0, "sent-plain": 0, told: 1, taken: 2 };
|
|
4546
4608
|
var isOpen2 = (w) => !CLOSED.has(w.state);
|
|
4547
|
-
var file2 = (slot, ws) =>
|
|
4609
|
+
var file2 = (slot, ws) => join16(towerDir(slot, ws), "linkwaits.json");
|
|
4548
4610
|
function loadWaits(slot, ws) {
|
|
4549
4611
|
let text14;
|
|
4550
4612
|
try {
|
|
@@ -4596,8 +4658,14 @@ function createLinkWaits(d) {
|
|
|
4596
4658
|
d.log("link-wait-ledger-unreadable", { ws, problem });
|
|
4597
4659
|
throw new Error(problem);
|
|
4598
4660
|
}
|
|
4661
|
+
const was = new Map(ledger.entries.map((w) => [w.n, isOpen2(w)]));
|
|
4599
4662
|
const value = fn(ledger);
|
|
4600
4663
|
writeWaits(d.slot, ws, ledger);
|
|
4664
|
+
for (const w of ledger.entries) {
|
|
4665
|
+
const open9 = was.get(w.n), session = w.dir === "out" ? w.raiser?.id : (w.claimedBy ?? w.toldTo?.[0])?.id;
|
|
4666
|
+
if (open9 === void 0) noteLedger(d.slot.stateDir, { kind: "link_wait_open", id: `L${w.n}`, session, workspace: ws }, d.now());
|
|
4667
|
+
if (open9 !== false && !isOpen2(w)) noteLedger(d.slot.stateDir, { kind: "link_wait_done", id: `L${w.n}`, session, workspace: ws }, d.now());
|
|
4668
|
+
}
|
|
4601
4669
|
return value;
|
|
4602
4670
|
};
|
|
4603
4671
|
let chain2 = Promise.resolve();
|
|
@@ -5322,12 +5390,12 @@ function startLinkWaits(o) {
|
|
|
5322
5390
|
// src/server/guihost.ts
|
|
5323
5391
|
import { spawn as spawn2 } from "node:child_process";
|
|
5324
5392
|
import { readFileSync as readFileSync20 } from "node:fs";
|
|
5325
|
-
import { join as
|
|
5393
|
+
import { join as join33 } from "node:path";
|
|
5326
5394
|
|
|
5327
5395
|
// src/music.ts
|
|
5328
5396
|
import { open as open2, readdir, realpath, stat } from "node:fs/promises";
|
|
5329
5397
|
import { homedir as homedir5 } from "node:os";
|
|
5330
|
-
import { extname, join as
|
|
5398
|
+
import { extname, join as join17, sep as sep2 } from "node:path";
|
|
5331
5399
|
var TYPES2 = { ".mp3": "audio/mpeg", ".m4a": "audio/mp4", ".aac": "audio/aac", ".ogg": "audio/ogg", ".oga": "audio/ogg", ".opus": "audio/ogg", ".wav": "audio/wav", ".flac": "audio/flac" };
|
|
5332
5400
|
var LIMIT = 200;
|
|
5333
5401
|
var plain2 = (name2) => !name2.startsWith(".") && !/[\\\0-\x1f]/.test(name2) && extname(name2).toLowerCase() in TYPES2;
|
|
@@ -5340,12 +5408,12 @@ function slice(header2, size2) {
|
|
|
5340
5408
|
if (m[2] !== "" && Number(m[2]) < from) return "all";
|
|
5341
5409
|
return from >= size2 ? "bad" : [from, m[2] === "" ? size2 - 1 : Math.min(Number(m[2]), size2 - 1)];
|
|
5342
5410
|
}
|
|
5343
|
-
var musicDirOf = (env = process.env) =>
|
|
5411
|
+
var musicDirOf = (env = process.env) => join17(env.PI_CODING_AGENT_DIR ?? join17(homedir5(), ".pi", "agent"), "straw-boss-music");
|
|
5344
5412
|
function createMusic(dir) {
|
|
5345
5413
|
async function track(name2) {
|
|
5346
5414
|
if (!dir) return void 0;
|
|
5347
5415
|
try {
|
|
5348
|
-
const [root, real3] = await Promise.all([realpath(dir), realpath(
|
|
5416
|
+
const [root, real3] = await Promise.all([realpath(dir), realpath(join17(dir, name2))]);
|
|
5349
5417
|
if (!real3.startsWith(root + sep2)) return void 0;
|
|
5350
5418
|
const s2 = await stat(real3);
|
|
5351
5419
|
return s2.isFile() && s2.size > 0 ? { real: real3, size: s2.size } : void 0;
|
|
@@ -5393,8 +5461,8 @@ import { fileURLToPath } from "node:url";
|
|
|
5393
5461
|
|
|
5394
5462
|
// src/stash.ts
|
|
5395
5463
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
5396
|
-
import { existsSync as existsSync4, linkSync, mkdirSync as
|
|
5397
|
-
import { dirname as
|
|
5464
|
+
import { existsSync as existsSync4, linkSync, mkdirSync as mkdirSync5, readdirSync as readdirSync4, readFileSync as readFileSync12, renameSync as renameSync4, rmSync as rmSync3, statSync as statSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
5465
|
+
import { dirname as dirname5, join as join18 } from "node:path";
|
|
5398
5466
|
var ROLES2 = /* @__PURE__ */ new Set(["tower", "main", "member"]);
|
|
5399
5467
|
var SETTLED = /* @__PURE__ */ new Set(["idle", "done"]);
|
|
5400
5468
|
var SHELLS = /* @__PURE__ */ new Set(["zsh", "bash", "fish", "sh", "dash", "ksh", "tcsh", "csh", "nu", "login"]);
|
|
@@ -5404,8 +5472,8 @@ var CHECK_GAP_MS = 2e3;
|
|
|
5404
5472
|
var JOIN_MS = 6e4;
|
|
5405
5473
|
var no2 = (status, error, reason) => ({ status, body: { error, reason } });
|
|
5406
5474
|
var nameOk = (name2) => typeof name2 === "string" && name2.length > 0 && name2.length <= MAX_NAME && name2 === name2.trim() && !name2.startsWith(".") && !/[/\\\p{Cc}]/u.test(name2);
|
|
5407
|
-
var dirOf = (stateDir) =>
|
|
5408
|
-
var stashFile = (stateDir, name2) =>
|
|
5475
|
+
var dirOf = (stateDir) => join18(stateDir, "stash");
|
|
5476
|
+
var stashFile = (stateDir, name2) => join18(dirOf(stateDir), `${name2}.json`);
|
|
5409
5477
|
function nameFor(label, stateDir) {
|
|
5410
5478
|
const base = label.replace(/[/\\\p{Cc}]/gu, "-").trim().replace(/^\.+/, "").slice(0, MAX_NAME - 4).trim() || "base";
|
|
5411
5479
|
for (let n = 1; ; n++) if (!existsSync4(stashFile(stateDir, n > 1 ? `${base} ${n}` : base))) return n > 1 ? `${base} ${n}` : base;
|
|
@@ -5560,7 +5628,7 @@ async function stashBase(d, json3, closeBase, refresh) {
|
|
|
5560
5628
|
const name2 = typeof json3.name === "string" ? json3.name : nameFor(sv.label, d.stateDir), file3 = stashFile(d.stateDir, name2);
|
|
5561
5629
|
const stash = { version: 1, name: name2, label: sv.label, cwd: sv.cwd, stashedAt: (d.now?.() ?? /* @__PURE__ */ new Date()).toISOString(), tabs: sv.tabs };
|
|
5562
5630
|
if (!stashOk(stash)) return no2(500, "unreadable", "Nothing was stashed: the manifest would not be one a pop can read.");
|
|
5563
|
-
|
|
5631
|
+
mkdirSync5(dirOf(d.stateDir), { recursive: true, mode: 448 });
|
|
5564
5632
|
writeFileSync4(file3, JSON.stringify(stash, null, 2), { mode: 384, flag: "wx" });
|
|
5565
5633
|
const closed = await closeBase(json3.workspace);
|
|
5566
5634
|
if (closed.status === 200) return { status: 200, body: { stashed: name2, sessions: sv.agents.length } };
|
|
@@ -5583,8 +5651,8 @@ async function resume({ run: run3, sleep: sleep2, live, trustDir: trustDir2 }, w
|
|
|
5583
5651
|
}
|
|
5584
5652
|
async function popBase(d, name2) {
|
|
5585
5653
|
if (!nameOk(name2)) throw new Error(`"${name2}" is not a stash name`);
|
|
5586
|
-
const claimed2 =
|
|
5587
|
-
|
|
5654
|
+
const claimed2 = join18(dirOf(d.stateDir), ".popping", `${name2}.json`);
|
|
5655
|
+
mkdirSync5(dirname5(claimed2), { recursive: true, mode: 448 });
|
|
5588
5656
|
try {
|
|
5589
5657
|
renameSync4(stashFile(d.stateDir, name2), claimed2);
|
|
5590
5658
|
} catch (error) {
|
|
@@ -5592,8 +5660,8 @@ async function popBase(d, name2) {
|
|
|
5592
5660
|
}
|
|
5593
5661
|
try {
|
|
5594
5662
|
const r = await open3(d, name2, claimed2);
|
|
5595
|
-
|
|
5596
|
-
renameSync4(claimed2,
|
|
5663
|
+
mkdirSync5(join18(dirOf(d.stateDir), "popped"), { recursive: true, mode: 448 });
|
|
5664
|
+
renameSync4(claimed2, join18(dirOf(d.stateDir), "popped", `${name2}-${(d.now?.() ?? /* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`));
|
|
5597
5665
|
return r;
|
|
5598
5666
|
} catch (error) {
|
|
5599
5667
|
const back = existsSync4(stashFile(d.stateDir, name2)) ? nameFor(name2, d.stateDir) : name2;
|
|
@@ -5722,7 +5790,7 @@ function createCloser({ run: run3, sleep: sleep2, me, sessions, ask, check, stat
|
|
|
5722
5790
|
|
|
5723
5791
|
// src/deploy.ts
|
|
5724
5792
|
var KEPT = 16;
|
|
5725
|
-
var
|
|
5793
|
+
var ID2 = /^[\w-]{8,64}$/;
|
|
5726
5794
|
function createDeploy(given, now = Date.now) {
|
|
5727
5795
|
const plan2 = [...given], state = new Map(plan2.map((id2) => [id2, "pending"])), began = /* @__PURE__ */ new Map(), took = /* @__PURE__ */ new Map();
|
|
5728
5796
|
let active, finished = false, failed2, asking, held2, pane, delivery;
|
|
@@ -5793,7 +5861,7 @@ function createDeploy(given, now = Date.now) {
|
|
|
5793
5861
|
function createDeploys(now) {
|
|
5794
5862
|
const kept = /* @__PURE__ */ new Map();
|
|
5795
5863
|
return {
|
|
5796
|
-
valid: (id2) => typeof id2 === "string" &&
|
|
5864
|
+
valid: (id2) => typeof id2 === "string" && ID2.test(id2),
|
|
5797
5865
|
begin(id2, plan2) {
|
|
5798
5866
|
const deploy = createDeploy(plan2, now);
|
|
5799
5867
|
if (id2 === void 0) return deploy;
|
|
@@ -6088,9 +6156,9 @@ async function withPending(net, fileOf4, relayed) {
|
|
|
6088
6156
|
if (dialogs?.length) [u.mark, b.mark] = ["waiting", "waiting"];
|
|
6089
6157
|
if (dialogs?.length && u !== b.tower) u.note = "waiting on a question";
|
|
6090
6158
|
const file3 = u.mark === "waiting" ? fileOf4(u.key) : void 0;
|
|
6091
|
-
const
|
|
6092
|
-
if (file3) jobs.push(pendingWith(file3).then(({ pending, calls }) => u.pending =
|
|
6093
|
-
else if (dialogs?.length) u.pending =
|
|
6159
|
+
const join65 = (p, calls) => dialogs?.length ? relayed.merge(u.key, p, dialogs, Boolean(file3), calls) : p;
|
|
6160
|
+
if (file3) jobs.push(pendingWith(file3).then(({ pending, calls }) => u.pending = join65(pending, calls)));
|
|
6161
|
+
else if (dialogs?.length) u.pending = join65();
|
|
6094
6162
|
}
|
|
6095
6163
|
for (const b of net.bases) for (const u of unitsOf(b)) u.mark = commanding(u.mark, u.subs.map((c) => c.mark));
|
|
6096
6164
|
await Promise.all(jobs);
|
|
@@ -6110,7 +6178,7 @@ var MAX_DOCS = 32;
|
|
|
6110
6178
|
var MAX_FIELDS = 65;
|
|
6111
6179
|
var MAX_ANSWER = 12 * 1024;
|
|
6112
6180
|
var MARKDOWN = /\.(md|markdown)$/i;
|
|
6113
|
-
var
|
|
6181
|
+
var KINDS3 = ["form", "review", "feedback", "pick", "suggest", "checklist"];
|
|
6114
6182
|
var CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/;
|
|
6115
6183
|
var cardKind = (d) => d.v === 2 ? d.kind : d.kind === "text" && MARKDOWN.test(d.display) ? "blocks" : d.kind;
|
|
6116
6184
|
var isBlocksDoc = (d) => cardKind(d) === "blocks";
|
|
@@ -6168,7 +6236,7 @@ var fieldsOk = (f) => Array.isArray(f) && f.length <= MAX_FIELDS && f.every((x)
|
|
|
6168
6236
|
function answerOk(a) {
|
|
6169
6237
|
if (typeof a !== "object" || a === null) return false;
|
|
6170
6238
|
const { kind, title, fields, ref } = a;
|
|
6171
|
-
if (!
|
|
6239
|
+
if (!KINDS3.includes(kind) || title !== void 0 && !str4(title, 1024) || !fieldsOk(fields) || fields.some(([name2, value]) => CONTROL.test(name2) || CONTROL.test(value)) || Buffer.byteLength(JSON.stringify(fields)) > MAX_ANSWER) return false;
|
|
6172
6240
|
if (ref === void 0) return true;
|
|
6173
6241
|
const { doc: doc2, block } = ref ?? {};
|
|
6174
6242
|
return typeof ref === "object" && ref !== null && Number.isInteger(block) && block >= 0 && block <= MAX_BLOCK && (doc2 === void 0 || str4(doc2, 1024));
|
|
@@ -6204,7 +6272,7 @@ ${id2}`, cap = caps.get(k) ?? randomBytes7(16).toString("hex");
|
|
|
6204
6272
|
// src/history.ts
|
|
6205
6273
|
import { constants as constants3, realpathSync as realpathSync5, watch } from "node:fs";
|
|
6206
6274
|
import { lstat as lstat2, open as openFile, stat as stat3 } from "node:fs/promises";
|
|
6207
|
-
import { basename as basename3, dirname as
|
|
6275
|
+
import { basename as basename3, dirname as dirname6, join as join19, resolve as resolve3 } from "node:path";
|
|
6208
6276
|
|
|
6209
6277
|
// src/todoledger.ts
|
|
6210
6278
|
var TODO_V1 = "todo/v1";
|
|
@@ -6230,11 +6298,11 @@ var PAGE = 150;
|
|
|
6230
6298
|
var HIDDEN2 = /* @__PURE__ */ new Set(["session", "custom", "label", "usage", "context_edit"]);
|
|
6231
6299
|
function canonical2(path) {
|
|
6232
6300
|
if (!path) return void 0;
|
|
6233
|
-
for (let dir = resolve3(path), rest = ""; ; rest =
|
|
6301
|
+
for (let dir = resolve3(path), rest = ""; ; rest = join19(basename3(dir), rest), dir = dirname6(dir)) {
|
|
6234
6302
|
try {
|
|
6235
|
-
return
|
|
6303
|
+
return join19(realpathSync5(dir), rest);
|
|
6236
6304
|
} catch {
|
|
6237
|
-
if (dir ===
|
|
6305
|
+
if (dir === dirname6(dir)) return resolve3(path);
|
|
6238
6306
|
}
|
|
6239
6307
|
}
|
|
6240
6308
|
}
|
|
@@ -6672,13 +6740,13 @@ var keyLabel = (key2) => key2.split("+").map((part3) => part3.length === 1 ? par
|
|
|
6672
6740
|
|
|
6673
6741
|
// src/pull.ts
|
|
6674
6742
|
var MAX_PULL = 12e3;
|
|
6675
|
-
var
|
|
6743
|
+
var WHYS3 = ["no_editor", "stale", "not_taken", "changed", "too_large", "not_cleared", "no_key"];
|
|
6676
6744
|
function checkPull(p) {
|
|
6677
6745
|
if (!p) return void 0;
|
|
6678
6746
|
const { pending, ticket, key: key2, text: text14, empty, reason } = p;
|
|
6679
6747
|
if (key2 !== void 0 && (typeof key2 !== "string" || !DEQUEUE_KEY.test(key2))) return pending === true ? { reason: "no_key" } : void 0;
|
|
6680
6748
|
if (pending !== void 0 && typeof pending !== "boolean" || ticket !== void 0 && (typeof ticket !== "string" || ticket.length > 64) || text14 !== void 0 && (typeof text14 !== "string" || Buffer.byteLength(text14) > MAX_PULL)) return void 0;
|
|
6681
|
-
if (empty !== void 0 && empty !== true || reason !== void 0 && !
|
|
6749
|
+
if (empty !== void 0 && empty !== true || reason !== void 0 && !WHYS3.includes(reason)) return void 0;
|
|
6682
6750
|
return { ...pending !== void 0 ? { pending } : {}, ...ticket !== void 0 ? { ticket } : {}, ...key2 !== void 0 ? { key: key2 } : {}, ...text14 !== void 0 ? { text: text14 } : {}, ...empty ? { empty: true } : {}, ...reason !== void 0 ? { reason } : {} };
|
|
6683
6751
|
}
|
|
6684
6752
|
|
|
@@ -6803,7 +6871,7 @@ function createHub(pi, me, local, onAllow) {
|
|
|
6803
6871
|
} catch {
|
|
6804
6872
|
}
|
|
6805
6873
|
};
|
|
6806
|
-
const
|
|
6874
|
+
const join65 = () => {
|
|
6807
6875
|
try {
|
|
6808
6876
|
if (!channel && me) pi.events.emit(REGISTER2, { namespace: guiNamespace(me), ownerEligible: true, onReady: (c) => channel = c, onEvent });
|
|
6809
6877
|
} catch {
|
|
@@ -6897,12 +6965,12 @@ function createHub(pi, me, local, onAllow) {
|
|
|
6897
6965
|
/** The channel is registered at the first start, before gui.json names this session; later starts in this process reuse it. */
|
|
6898
6966
|
start(onChange) {
|
|
6899
6967
|
[change, active] = [onChange, true];
|
|
6900
|
-
|
|
6968
|
+
join65();
|
|
6901
6969
|
},
|
|
6902
6970
|
/** The server keeps the channel and the gates' tracking up with no page listening, and through a page's stop; bridges relay to it as soon as it owns the channel. */
|
|
6903
6971
|
track() {
|
|
6904
6972
|
tracking = true;
|
|
6905
|
-
|
|
6973
|
+
join65();
|
|
6906
6974
|
},
|
|
6907
6975
|
stop() {
|
|
6908
6976
|
active = false;
|
|
@@ -7012,7 +7080,7 @@ ${d.id}`))));
|
|
|
7012
7080
|
import { createHash as createHash8, randomBytes as randomBytes11 } from "node:crypto";
|
|
7013
7081
|
import { statSync as statSync7 } from "node:fs";
|
|
7014
7082
|
import { createServer } from "node:http";
|
|
7015
|
-
import { extname as extname3, join as
|
|
7083
|
+
import { extname as extname3, join as join22 } from "node:path";
|
|
7016
7084
|
|
|
7017
7085
|
// src/control.ts
|
|
7018
7086
|
import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
@@ -7159,9 +7227,9 @@ function createKeys({ overlay, fresh, secret, answerable, linkRequest: linkReque
|
|
|
7159
7227
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
7160
7228
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
7161
7229
|
import { tmpdir } from "node:os";
|
|
7162
|
-
import { basename as basename4, join as
|
|
7230
|
+
import { basename as basename4, join as join20 } from "node:path";
|
|
7163
7231
|
var MAX_UPLOAD = 20 * 1024 * 1024;
|
|
7164
|
-
var UPLOADS =
|
|
7232
|
+
var UPLOADS = join20(tmpdir(), "pi-straw-boss-uploads");
|
|
7165
7233
|
var no5 = (status, error, reason) => ({ status, body: { error, reason } });
|
|
7166
7234
|
function safeName(raw) {
|
|
7167
7235
|
let name2 = "";
|
|
@@ -7174,7 +7242,7 @@ function safeName(raw) {
|
|
|
7174
7242
|
async function store(bytes, rawName, dir = UPLOADS) {
|
|
7175
7243
|
if (!bytes.length) return no5(400, "bad_request", "The file is empty.");
|
|
7176
7244
|
await mkdir(dir, { recursive: true, mode: 448 });
|
|
7177
|
-
const path =
|
|
7245
|
+
const path = join20(dir, `${Date.now()}-${randomUUID8().slice(0, 8)}-${safeName(rawName)}`);
|
|
7178
7246
|
await writeFile(path, bytes, { mode: 384, flag: "wx" });
|
|
7179
7247
|
return { status: 200, body: { path } };
|
|
7180
7248
|
}
|
|
@@ -7332,7 +7400,7 @@ async function commandReply(tower, key2, typed, answers2, refused3) {
|
|
|
7332
7400
|
async function markAnswered(tower, workspace, id2) {
|
|
7333
7401
|
return { answered: (await tower.memory?.(workspace, { op: "answer", id: id2 }))?.status === 200 ? id2 : false };
|
|
7334
7402
|
}
|
|
7335
|
-
async function headRoutes(tower, [scope, key2 = "", action = ""], json3, text14, far = false) {
|
|
7403
|
+
async function headRoutes(tower, [scope, key2 = "", action = ""], json3, text14, far = false, door = far ? "phone" : "gui") {
|
|
7336
7404
|
if (!tower?.has(HEAD_KEY)) return no7(409, "refused", HEAD_NEEDS_SERVICE);
|
|
7337
7405
|
if (scope === "sessions") {
|
|
7338
7406
|
if (action === "input") {
|
|
@@ -7355,7 +7423,7 @@ async function headRoutes(tower, [scope, key2 = "", action = ""], json3, text14,
|
|
|
7355
7423
|
}
|
|
7356
7424
|
if (key2 === "dialog" && !action) return runRoute(tower, HEAD_KEY, "dialog", json3, far);
|
|
7357
7425
|
if (action) return no7(404, "not_found", "No such action.");
|
|
7358
|
-
if (key2 === "memory") return tower.memory ? tower.memory(HEAD_KEY, json3) : no7(404, "not_found", "No such action.");
|
|
7426
|
+
if (key2 === "memory") return tower.memory ? tower.memory(HEAD_KEY, json3, door) : no7(404, "not_found", "No such action.");
|
|
7359
7427
|
if (key2 === "close") return tower.close ? done(await tower.close(HEAD_KEY), { status: 200, body: {} }) : no7(404, "not_found", "No such action.");
|
|
7360
7428
|
if (key2 === "leave" || key2 === "new") {
|
|
7361
7429
|
if (!tower.conversation) return no7(404, "not_found", "No such action.");
|
|
@@ -7670,7 +7738,7 @@ function createControl({ auto, board, bridge, lan, overlay, link, server: panel,
|
|
|
7670
7738
|
if (scope === "tower") {
|
|
7671
7739
|
if (key2.startsWith("@") || tower?.isHead?.(key2)) return no8(404, "not_found", "No such tower.");
|
|
7672
7740
|
if (action === "dialog" || action === "viewer") return runRoute(tower, key2, action, json3, Boolean(remote || operate));
|
|
7673
|
-
if (action === "memory") return tower?.memory && tower.has(key2) ? tower.memory(key2, json3) : no8(404, "not_found", "No such tower.");
|
|
7741
|
+
if (action === "memory") return tower?.memory && tower.has(key2) ? tower.memory(key2, json3, operate ? "box" : remote ? "phone" : "gui") : no8(404, "not_found", "No such tower.");
|
|
7674
7742
|
if (action === "leave" || action === "new") {
|
|
7675
7743
|
if (!tower?.conversation || !tower.has(key2)) return no8(404, "not_found", "No such tower.");
|
|
7676
7744
|
const done3 = await tower.conversation(key2, action);
|
|
@@ -7685,7 +7753,7 @@ function createControl({ auto, board, bridge, lan, overlay, link, server: panel,
|
|
|
7685
7753
|
}
|
|
7686
7754
|
const unit = tower && scope === "sessions" ? lookup(key2) : void 0, ws = unit?.role === "tower" && tower?.has(unit.base) ? unit.base : void 0;
|
|
7687
7755
|
if (scope === "head" || unit?.role === "head") {
|
|
7688
|
-
const head = await headRoutes(tower, [scope, key2, action], json3, checkText, Boolean(remote || operate));
|
|
7756
|
+
const head = await headRoutes(tower, [scope, key2, action], json3, checkText, Boolean(remote || operate), operate ? "box" : remote ? "phone" : "gui");
|
|
7689
7757
|
if (head) return head;
|
|
7690
7758
|
}
|
|
7691
7759
|
if (tower && ws) {
|
|
@@ -7867,10 +7935,10 @@ function createControl({ auto, board, bridge, lan, overlay, link, server: panel,
|
|
|
7867
7935
|
import { createHash as createHash7, randomBytes as randomBytes9 } from "node:crypto";
|
|
7868
7936
|
import { createReadStream, readFileSync as readFileSync13, realpathSync as realpathSync6, statSync as statSync5 } from "node:fs";
|
|
7869
7937
|
import { pipeline } from "node:stream";
|
|
7870
|
-
import { dirname as
|
|
7938
|
+
import { dirname as dirname7, extname as extname2, resolve as resolve4, sep as sep3 } from "node:path";
|
|
7871
7939
|
|
|
7872
7940
|
// src/blockcount.ts
|
|
7873
|
-
var
|
|
7941
|
+
var KINDS4 = /* @__PURE__ */ new Set(["mermaid", "diff", "cards", "options", "form", "review", "mindmap", "suggest", "checklist", "table", "steps", "stats", "tree"]);
|
|
7874
7942
|
var ALERT_LINE = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\][ \t]*(.*)$/i;
|
|
7875
7943
|
var QUOTE = /^ {0,3}> ?/;
|
|
7876
7944
|
var BACKTICK_FENCE = /^( {0,3})(`{3,})[ \t]*([^`]*)$/;
|
|
@@ -7888,7 +7956,7 @@ function blockCount(markdown) {
|
|
|
7888
7956
|
const marker = fence[2];
|
|
7889
7957
|
let end = i + 1;
|
|
7890
7958
|
while (end < lines.length && !closes(lines[end], marker)) end++;
|
|
7891
|
-
if (
|
|
7959
|
+
if (KINDS4.has(fence[3].trim().split(/\s+/)[0].toLowerCase())) count4++;
|
|
7892
7960
|
i = Math.min(end + 1, lines.length);
|
|
7893
7961
|
continue;
|
|
7894
7962
|
}
|
|
@@ -8031,7 +8099,7 @@ function createDocs(hub, name2, { answered = createAnswered({ load: () => void 0
|
|
|
8031
8099
|
if (!bytes) return void page2(404, "Not found", "No such file beside the document.");
|
|
8032
8100
|
return void res.writeHead(200, heads).end(bytes);
|
|
8033
8101
|
}
|
|
8034
|
-
const real3 = allowed ? file3(resolve4(
|
|
8102
|
+
const real3 = allowed ? file3(resolve4(dirname7(doc2.path), rel), MAX_FILE2, dirname7(doc2.path)) : void 0;
|
|
8035
8103
|
if (!real3) return void page2(404, "Not found", "No such file beside the document.");
|
|
8036
8104
|
res.writeHead(200, heads);
|
|
8037
8105
|
pipeline(createReadStream(real3), res, () => {
|
|
@@ -9019,9 +9087,9 @@ import { pipeline as pipeline2 } from "node:stream";
|
|
|
9019
9087
|
|
|
9020
9088
|
// src/guithemes.ts
|
|
9021
9089
|
import { readdirSync as readdirSync5, readFileSync as readFileSync14, statSync as statSync6 } from "node:fs";
|
|
9022
|
-
import { join as
|
|
9090
|
+
import { join as join21 } from "node:path";
|
|
9023
9091
|
function listBundle(dir) {
|
|
9024
|
-
const bundle = new Map(readdirSync5(dir, { recursive: true, encoding: "utf8" }).filter((f) => statSync6(
|
|
9092
|
+
const bundle = new Map(readdirSync5(dir, { recursive: true, encoding: "utf8" }).filter((f) => statSync6(join21(dir, f)).isFile()).map((f) => [f.split("\\").join("/"), readFileSync14(join21(dir, f))]));
|
|
9025
9093
|
const map = (() => {
|
|
9026
9094
|
try {
|
|
9027
9095
|
return JSON.parse(bundle.get("themes.json")?.toString("utf8") ?? "{}");
|
|
@@ -9042,7 +9110,7 @@ function listBundle(dir) {
|
|
|
9042
9110
|
}
|
|
9043
9111
|
|
|
9044
9112
|
// src/gui.ts
|
|
9045
|
-
var BUNDLE =
|
|
9113
|
+
var BUNDLE = join22(packageRoot(), "dist", "gui");
|
|
9046
9114
|
var TYPES3 = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8", ".svg": "image/svg+xml", ".json": "application/json", ".woff2": "font/woff2", ".mp3": "audio/mpeg", ".png": "image/png", ".webp": "image/webp", ".webmanifest": "application/manifest+json" };
|
|
9047
9115
|
var HEADERS = {
|
|
9048
9116
|
"cache-control": "no-store",
|
|
@@ -9057,7 +9125,7 @@ var REPLACED_ZH = "\u9019\u500B\u7DB2\u5740\u5728\u9019\u88E1\u7121\u6CD5\u4F7F\
|
|
|
9057
9125
|
async function startGui({ auto, board, read: read4, net, call, hub, answered = createAnswered({ load: () => void 0, save: () => {
|
|
9058
9126
|
} }), dir = BUNDLE, paired, port: port2 = 0, remotePort = 0, pollMs = 2e3, idleMs = 1e4, pingMs = 15e3, onStop, refuseTake, onRemote, onRemoteOff, onSaveFailed, spawn: spawn3, close, trust, link, server: panel, tower, bindWaitMs = 0, keep: keep2, desk = false, lan, view: firstView = "auto", music, operateHost: host }) {
|
|
9059
9127
|
try {
|
|
9060
|
-
if (!statSync7(
|
|
9128
|
+
if (!statSync7(join22(dir, "index.html")).isFile()) throw new Error();
|
|
9061
9129
|
} catch {
|
|
9062
9130
|
throw new Error(`The GUI bundle is missing (${dir}); build it with npm run gui:build`);
|
|
9063
9131
|
}
|
|
@@ -9347,7 +9415,7 @@ async function startGui({ auto, board, read: read4, net, call, hub, answered = c
|
|
|
9347
9415
|
|
|
9348
9416
|
// src/net.ts
|
|
9349
9417
|
import { homedir as homedir6 } from "node:os";
|
|
9350
|
-
import { basename as basename5, join as
|
|
9418
|
+
import { basename as basename5, join as join23, sep as sep4 } from "node:path";
|
|
9351
9419
|
|
|
9352
9420
|
// src/waitbudget.ts
|
|
9353
9421
|
var CARD_TEXTS = 24e3;
|
|
@@ -9423,7 +9491,7 @@ function trackActivity(now = Date.now) {
|
|
|
9423
9491
|
var joinedRole = (token) => token === "main" || token === "member" || token === "train" ? token : void 0;
|
|
9424
9492
|
var RECENT_MS = 10 * 6e4;
|
|
9425
9493
|
var raiserView = ({ id: id2, ...rest }, keys) => ({ ...rest, ...id2 && keys.get(id2) ? { key: keys.get(id2) } : {} });
|
|
9426
|
-
function buildNet({ sessions, panes: ps, workspaces: all, children: children2, services, head, sessionDir =
|
|
9494
|
+
function buildNet({ sessions, panes: ps, workspaces: all, children: children2, services, head, sessionDir = join23(process.env.PI_CODING_AGENT_DIR ?? join23(homedir6(), ".pi", "agent"), "sessions") }, refs = /* @__PURE__ */ new Map()) {
|
|
9427
9495
|
const root = canonical2(sessionDir), readable2 = (file3, id2, real3 = file3?.endsWith(".jsonl") ? canonical2(file3) : void 0) => real3 && real3.startsWith(root + sep4) && (!id2 || basename5(real3).endsWith(`_${id2}.jsonl`)) ? real3 : void 0;
|
|
9428
9496
|
const piFile = (pane, id2) => readable2(pane?.agent === "pi" ? pane.agent_session?.value : void 0, id2);
|
|
9429
9497
|
const paneOf2 = (s2) => ps.find((p) => p.pane_id === s2.herdrLocation?.paneId);
|
|
@@ -9464,8 +9532,8 @@ function buildNet({ sessions, panes: ps, workspaces: all, children: children2, s
|
|
|
9464
9532
|
keep2({ key: key2, base: w.workspace_id, name: name2, role: "outside", file: readable2(file3, s2?.id), pane: p.pane_id });
|
|
9465
9533
|
return [{ id: key2, key: key2, control: true, name: name2, role: "outside", mark: mark3, note: note(mark3, s2?.status), subs: [] }];
|
|
9466
9534
|
});
|
|
9467
|
-
const
|
|
9468
|
-
const mark2 = ["waiting", "working"].find((m) =>
|
|
9535
|
+
const marks2 = [...towerSubs.map((c) => c.mark), ...tabs2.flatMap((t) => t.units.flatMap((u) => [u.mark, ...u.subs.map((c) => c.mark)])), ...outposts.map((o) => o.mark)];
|
|
9536
|
+
const mark2 = ["waiting", "working"].find((m) => marks2.includes(m)) ?? markOf(w.agent_status);
|
|
9469
9537
|
if (!tower && !tabs2.length) return [];
|
|
9470
9538
|
const view = tower ? services?.(w.workspace_id) : void 0, { queue, file: runFile, allyFiles, eventFiles, ...service } = view ?? {};
|
|
9471
9539
|
const named = tower && keep2({ key: tower.id, base: w.workspace_id, name: tower.name ?? tower.id, role: "tower", file: view ? readable2(runFile) : piFile(towerPane, tower.id), pane: towerPane?.pane_id });
|
|
@@ -9543,8 +9611,8 @@ function netSource(env) {
|
|
|
9543
9611
|
}
|
|
9544
9612
|
|
|
9545
9613
|
// src/openings.ts
|
|
9546
|
-
import { mkdirSync as
|
|
9547
|
-
import { dirname as
|
|
9614
|
+
import { mkdirSync as mkdirSync6, readFileSync as readFileSync16 } from "node:fs";
|
|
9615
|
+
import { dirname as dirname8 } from "node:path";
|
|
9548
9616
|
var KEPT2 = 64;
|
|
9549
9617
|
var str9 = (v) => typeof v === "string" && v.length > 0;
|
|
9550
9618
|
var DELIVERY = ["none", "pending", "sending", "sent"];
|
|
@@ -9561,7 +9629,7 @@ function createOpenings(file3) {
|
|
|
9561
9629
|
}
|
|
9562
9630
|
const save2 = () => {
|
|
9563
9631
|
if (!file3) return;
|
|
9564
|
-
|
|
9632
|
+
mkdirSync6(dirname8(file3), { recursive: true, mode: 448 });
|
|
9565
9633
|
writeJson(file3, Object.fromEntries(kept));
|
|
9566
9634
|
};
|
|
9567
9635
|
return {
|
|
@@ -9601,12 +9669,12 @@ function createIntents() {
|
|
|
9601
9669
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
9602
9670
|
import { mkdir as mkdir2, readdir as readdir3, realpath as realpath2, rmdir, stat as stat5 } from "node:fs/promises";
|
|
9603
9671
|
import { homedir as homedir7 } from "node:os";
|
|
9604
|
-
import { basename as basename6, dirname as
|
|
9672
|
+
import { basename as basename6, dirname as dirname9, isAbsolute as isAbsolute4, join as join25, relative as relative3, resolve as resolve5, sep as sep5 } from "node:path";
|
|
9605
9673
|
|
|
9606
9674
|
// src/hidden.ts
|
|
9607
9675
|
import { execFile } from "node:child_process";
|
|
9608
9676
|
import { readdir as readdir2 } from "node:fs/promises";
|
|
9609
|
-
import { join as
|
|
9677
|
+
import { join as join24 } from "node:path";
|
|
9610
9678
|
var HiddenError = class extends Error {
|
|
9611
9679
|
};
|
|
9612
9680
|
var COMMAND = '/d /v:off /u /c "dir /b /a:h "%SB_DIR%" 2>nul & dir /b /a:s "%SB_DIR%" 2>nul & exit /b 0"';
|
|
@@ -9641,7 +9709,7 @@ function cached(read4, ttl = 1e4, now = Date.now) {
|
|
|
9641
9709
|
}
|
|
9642
9710
|
var platformHidden = process.platform === "win32" ? cached(cmdHidden) : void 0;
|
|
9643
9711
|
async function hasHidden(root, parts, hidden) {
|
|
9644
|
-
for (const [i, part3] of parts.entries()) if ((await hidden(
|
|
9712
|
+
for (const [i, part3] of parts.entries()) if ((await hidden(join24(root, ...parts.slice(0, i)))).has(part3.toLowerCase())) return true;
|
|
9645
9713
|
return false;
|
|
9646
9714
|
}
|
|
9647
9715
|
|
|
@@ -9675,10 +9743,10 @@ async function listDirs(dir, home = homedir7(), hidden = platformHidden) {
|
|
|
9675
9743
|
const root = await realpath2(home).catch(() => home), names = [], marked2 = await hidden?.(dir);
|
|
9676
9744
|
for (const e of await readdir3(dir, { withFileTypes: true })) {
|
|
9677
9745
|
if (e.name.startsWith(".") || marked2?.has(e.name.toLowerCase())) continue;
|
|
9678
|
-
if (e.isDirectory() || e.isSymbolicLink() && await pickable(
|
|
9746
|
+
if (e.isDirectory() || e.isSymbolicLink() && await pickable(join25(dir, e.name), home, hidden)) names.push(e.name);
|
|
9679
9747
|
}
|
|
9680
9748
|
names.sort((a, b) => a.localeCompare(b));
|
|
9681
|
-
return { path: dir, home: root, sep: sep5, parent: dir === root ? null :
|
|
9749
|
+
return { path: dir, home: root, sep: sep5, parent: dir === root ? null : dirname9(dir), dirs: names.slice(0, MAX_DIRS), truncated: names.length > MAX_DIRS };
|
|
9682
9750
|
}
|
|
9683
9751
|
var BAD_NAME = /[\p{Cc}\p{Cf}\\/<>:"|?*]/u;
|
|
9684
9752
|
var RESERVED2 = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;
|
|
@@ -9688,7 +9756,7 @@ async function makeDir(parent, name2, home = homedir7(), hidden = platformHidden
|
|
|
9688
9756
|
if (!dir) return OUTSIDE2;
|
|
9689
9757
|
const clean6 = typeof name2 === "string" ? name2.trim() : "";
|
|
9690
9758
|
if (!clean6 || Buffer.byteLength(clean6) > 255 || RESERVED2.test(clean6) || clean6.startsWith(".") || /[. ]$/.test(clean6) || BAD_NAME.test(clean6)) return BAD();
|
|
9691
|
-
const path =
|
|
9759
|
+
const path = join25(dir, clean6), made = await mkdir2(path).then(() => true, (error) => error.code === "EEXIST" ? false : error);
|
|
9692
9760
|
if (made instanceof Error) return made.code === "ENAMETOOLONG" ? BAD() : no10(403, "unwritable", `The folder could not be made: ${made.message}`);
|
|
9693
9761
|
const real3 = await pickable(path, home, hidden);
|
|
9694
9762
|
if (!real3 && made) await rmdir(path).catch(() => {
|
|
@@ -9729,7 +9797,7 @@ function createSpawn({ run: run3, sleep: sleep2, call, live, sessionAt, home = h
|
|
|
9729
9797
|
await keep3(ws.worktree?.checkout_path);
|
|
9730
9798
|
for (const pane of await panes(run3, ws.workspace_id).catch(() => [])) await keep3(pane.cwd);
|
|
9731
9799
|
}
|
|
9732
|
-
const named = await Promise.all(["Desktop", "Documents"].map(async (name2) => [name2, await pick3(
|
|
9800
|
+
const named = await Promise.all(["Desktop", "Documents"].map(async (name2) => [name2, await pick3(join25(root, name2))]));
|
|
9733
9801
|
return { home: root, sep: sep5, places: named.flatMap(([name2, path]) => path ? [{ name: name2, path }] : []), recent: recent.slice(0, 10) };
|
|
9734
9802
|
};
|
|
9735
9803
|
const leadOf2 = async (workspaceId, tabId) => {
|
|
@@ -10028,14 +10096,14 @@ var answeredFileDeps = (file3) => ({
|
|
|
10028
10096
|
});
|
|
10029
10097
|
|
|
10030
10098
|
// src/server/lanhost.ts
|
|
10031
|
-
import { mkdirSync as
|
|
10032
|
-
import { join as
|
|
10099
|
+
import { mkdirSync as mkdirSync8, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
10100
|
+
import { join as join27 } from "node:path";
|
|
10033
10101
|
|
|
10034
10102
|
// src/lan/ca.ts
|
|
10035
10103
|
import { createHash as createHash10, createPrivateKey as createPrivateKey3, randomBytes as randomBytes13, X509Certificate } from "node:crypto";
|
|
10036
|
-
import { closeSync as closeSync4, constants as constants5, fstatSync as fstatSync3, lstatSync as lstatSync5, mkdirSync as
|
|
10104
|
+
import { closeSync as closeSync4, constants as constants5, fstatSync as fstatSync3, lstatSync as lstatSync5, mkdirSync as mkdirSync7, openSync as openSync4, readFileSync as readFileSync18, rmSync as rmSync4, writeSync as writeSync2 } from "node:fs";
|
|
10037
10105
|
import { hostname as hostname2 } from "node:os";
|
|
10038
|
-
import { join as
|
|
10106
|
+
import { join as join26 } from "node:path";
|
|
10039
10107
|
|
|
10040
10108
|
// src/lan/x509.ts
|
|
10041
10109
|
import { createHash as createHash9, createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey2, generateKeyPairSync, randomBytes as randomBytes12, sign as sign2 } from "node:crypto";
|
|
@@ -10327,7 +10395,7 @@ var crt = (ca) => caDer(ca);
|
|
|
10327
10395
|
var KEYS2 = ["v", "name", "key", "cert", "created"];
|
|
10328
10396
|
var one2 = (text14, label) => text14.split(`-----BEGIN ${label}-----`).length === 2;
|
|
10329
10397
|
function readCa(dir, deps = {}) {
|
|
10330
|
-
const file3 =
|
|
10398
|
+
const file3 = join26(dir, CA_FILE), platform = deps.platform ?? process.platform, uid2 = "uid" in deps ? deps.uid : process.getuid?.();
|
|
10331
10399
|
let fd;
|
|
10332
10400
|
try {
|
|
10333
10401
|
try {
|
|
@@ -10361,8 +10429,8 @@ function timeMachineExclude(path, platform = process.platform) {
|
|
|
10361
10429
|
}
|
|
10362
10430
|
var temps2 = 0;
|
|
10363
10431
|
function writeCa(dir, ca, deps = {}) {
|
|
10364
|
-
|
|
10365
|
-
const file3 =
|
|
10432
|
+
mkdirSync7(dir, { recursive: true, mode: 448 });
|
|
10433
|
+
const file3 = join26(dir, CA_FILE), temp = `${file3}.${process.pid}.${temps2++}.${randomBytes13(4).toString("hex")}.tmp`;
|
|
10366
10434
|
const fd = openSync4(temp, "wx", 384);
|
|
10367
10435
|
try {
|
|
10368
10436
|
try {
|
|
@@ -11724,11 +11792,11 @@ function createLanHost(o) {
|
|
|
11724
11792
|
function files() {
|
|
11725
11793
|
const found = stored();
|
|
11726
11794
|
if ("lost" in found) return bad("no_ca", "There is no Wi-Fi certificate yet; run /boss gui lan first.", 409);
|
|
11727
|
-
const dir =
|
|
11728
|
-
|
|
11729
|
-
writeFileSync5(
|
|
11730
|
-
writeFileSync5(
|
|
11731
|
-
return reply(200, { dir, files: Object.values(CA_FILES).map((f) =>
|
|
11795
|
+
const dir = join27(o.dir, "lan-ca-files");
|
|
11796
|
+
mkdirSync8(dir, { recursive: true, mode: 448 });
|
|
11797
|
+
writeFileSync5(join27(dir, CA_FILES.profile), mobileconfig(ca));
|
|
11798
|
+
writeFileSync5(join27(dir, CA_FILES.crt), crt(ca));
|
|
11799
|
+
return reply(200, { dir, files: Object.values(CA_FILES).map((f) => join27(dir, f)) });
|
|
11732
11800
|
}
|
|
11733
11801
|
async function reset(unpair) {
|
|
11734
11802
|
const read4 = readCa(o.dir);
|
|
@@ -11737,7 +11805,7 @@ function createLanHost(o) {
|
|
|
11737
11805
|
if (current === "unreadable") return bad("lan_name_unreadable", "This computer's name could not be read just now, so no certificate was made; try again in a moment.", 409);
|
|
11738
11806
|
const next2 = createCa(current, now());
|
|
11739
11807
|
write2(next2);
|
|
11740
|
-
rmSync5(
|
|
11808
|
+
rmSync5(join27(o.dir, "lan-ca-files"), { recursive: true, force: true });
|
|
11741
11809
|
ca = next2;
|
|
11742
11810
|
held2 = void 0;
|
|
11743
11811
|
const wanted = lan().wanted, running = Boolean(listener);
|
|
@@ -11806,11 +11874,11 @@ var isChoice = (value) => typeof value === "string" && CHOICES2.includes(value);
|
|
|
11806
11874
|
var said = (names) => `${names.slice(0, -1).join(", ")}, or ${names.at(-1)}`;
|
|
11807
11875
|
|
|
11808
11876
|
// src/server/guiprefs.ts
|
|
11809
|
-
import { join as
|
|
11877
|
+
import { join as join28 } from "node:path";
|
|
11810
11878
|
var PREFS_FILE = "gui-prefs.json";
|
|
11811
11879
|
var isView = isChoice;
|
|
11812
11880
|
function readView(dir) {
|
|
11813
|
-
const text14 = readOwnedText(
|
|
11881
|
+
const text14 = readOwnedText(join28(dir, PREFS_FILE));
|
|
11814
11882
|
if (text14 === void 0) return "auto";
|
|
11815
11883
|
try {
|
|
11816
11884
|
const v = JSON.parse(text14);
|
|
@@ -11820,7 +11888,7 @@ function readView(dir) {
|
|
|
11820
11888
|
return "auto";
|
|
11821
11889
|
}
|
|
11822
11890
|
function storedIs(dir, view) {
|
|
11823
|
-
const text14 = readOwnedText(
|
|
11891
|
+
const text14 = readOwnedText(join28(dir, PREFS_FILE));
|
|
11824
11892
|
if (text14 === void 0) return view === "auto";
|
|
11825
11893
|
try {
|
|
11826
11894
|
const v = JSON.parse(text14);
|
|
@@ -11829,11 +11897,11 @@ function storedIs(dir, view) {
|
|
|
11829
11897
|
return false;
|
|
11830
11898
|
}
|
|
11831
11899
|
}
|
|
11832
|
-
var writeView = (dir, view) => writeJson(
|
|
11900
|
+
var writeView = (dir, view) => writeJson(join28(dir, PREFS_FILE), { v: 1, view });
|
|
11833
11901
|
|
|
11834
11902
|
// src/server/guisecrets.ts
|
|
11835
11903
|
import { lstatSync as lstatSync6, rmSync as rmSync6 } from "node:fs";
|
|
11836
|
-
import { join as
|
|
11904
|
+
import { join as join29 } from "node:path";
|
|
11837
11905
|
var SECRETS_FILE = "gui-secrets.json";
|
|
11838
11906
|
var HEX = /^[0-9a-f]{32}$/;
|
|
11839
11907
|
var port = (v) => typeof v === "number" && Number.isInteger(v) && v > 0 && v < 65536;
|
|
@@ -11845,8 +11913,8 @@ var present = (file3) => {
|
|
|
11845
11913
|
}
|
|
11846
11914
|
};
|
|
11847
11915
|
function readSecrets(dir) {
|
|
11848
|
-
const text14 = readOwnedText(
|
|
11849
|
-
if (text14 === void 0) return { lost: present(
|
|
11916
|
+
const text14 = readOwnedText(join29(dir, SECRETS_FILE));
|
|
11917
|
+
if (text14 === void 0) return { lost: present(join29(dir, SECRETS_FILE)) ? "corrupt" : "missing" };
|
|
11850
11918
|
try {
|
|
11851
11919
|
const v = JSON.parse(text14);
|
|
11852
11920
|
if (v && typeof v === "object" && v.v === 1 && typeof v.token === "string" && HEX.test(v.token) && typeof v.csrf === "string" && HEX.test(v.csrf) && port(v.port) && port(v.remotePort) && v.token !== v.csrf) {
|
|
@@ -11856,13 +11924,13 @@ function readSecrets(dir) {
|
|
|
11856
11924
|
}
|
|
11857
11925
|
return { lost: "corrupt" };
|
|
11858
11926
|
}
|
|
11859
|
-
var keepSecrets = (dir, secrets) => writeJson(
|
|
11860
|
-
var dropSecrets = (dir) => rmSync6(
|
|
11927
|
+
var keepSecrets = (dir, secrets) => writeJson(join29(dir, SECRETS_FILE), { v: 1, ...secrets });
|
|
11928
|
+
var dropSecrets = (dir) => rmSync6(join29(dir, SECRETS_FILE), { force: true });
|
|
11861
11929
|
|
|
11862
11930
|
// src/server/trainyard.ts
|
|
11863
11931
|
import { readdirSync as readdirSync7 } from "node:fs";
|
|
11864
11932
|
import { availableParallelism, loadavg } from "node:os";
|
|
11865
|
-
import { dirname as
|
|
11933
|
+
import { dirname as dirname10, join as join30 } from "node:path";
|
|
11866
11934
|
var MAX_PROJECTS = 64;
|
|
11867
11935
|
var MAX_VIEW_STEPS = 64;
|
|
11868
11936
|
var MAX_VIEW_CARS = 16;
|
|
@@ -11901,7 +11969,7 @@ function nodsOf(folder, clean6, budget) {
|
|
|
11901
11969
|
return out;
|
|
11902
11970
|
}
|
|
11903
11971
|
for (const name2 of names) {
|
|
11904
|
-
const read4 = readJsonFile(
|
|
11972
|
+
const read4 = readJsonFile(join30(folder, name2), MAX_EVIDENCE_BYTES, budget);
|
|
11905
11973
|
if (!read4.ok) continue;
|
|
11906
11974
|
const value = read4.value;
|
|
11907
11975
|
if (!isObject(value) || !isObject(value.car) || !SHA_RE.test(String(value.car.head)) || !Array.isArray(value.accepted)) continue;
|
|
@@ -11958,8 +12026,8 @@ function cleanWait(wait2, clean6) {
|
|
|
11958
12026
|
if ("lane" in wait2) return { lane: { app: clean6(wait2.lane.app, 64), holder: clean6(wait2.lane.holder, 32), ...wait2.lane.why ? { why: wait2.lane.why } : {} } };
|
|
11959
12027
|
return { target: { target: clean6(wait2.target.target, 128), holder: clean6(wait2.target.holder, 32), ...wait2.target.why ? { why: wait2.target.why } : {} } };
|
|
11960
12028
|
}
|
|
11961
|
-
function unitOf(
|
|
11962
|
-
const claims =
|
|
12029
|
+
function unitOf(join65, project, code, writer) {
|
|
12030
|
+
const claims = join65.trains.filter((u) => u.project === project && u.code === code);
|
|
11963
12031
|
return claims.length === 1 ? claims[0].key : claims.find((u) => u.key === writer)?.key;
|
|
11964
12032
|
}
|
|
11965
12033
|
function readYards(deps, join_) {
|
|
@@ -11988,12 +12056,12 @@ function readYards(deps, join_) {
|
|
|
11988
12056
|
const key3 = unitOf(join_, project, read4.code);
|
|
11989
12057
|
return { code: read4.code, state: "unreadable", reason: clean6(read4.reason, 200), reasonKind: reasonKind(read4.reason), ...key3 ? { key: key3 } : {}, cars: [], steps: [] };
|
|
11990
12058
|
}
|
|
11991
|
-
const { board } = read4, key2 = unitOf(join_, project, board.code, board.writer.session), nods = nodsOf(
|
|
12059
|
+
const { board } = read4, key2 = unitOf(join_, project, board.code, board.writer.session), nods = nodsOf(dirname10(read4.file), clean6, budget);
|
|
11992
12060
|
const factSteps = new Map(fact.steps.map((s2) => [s2.id, s2]));
|
|
11993
12061
|
const view = (s2) => {
|
|
11994
12062
|
const recorded = s2.status === "in_progress" ? (s2.waits ?? []).filter((w) => "lock" in w) : [];
|
|
11995
12063
|
const waits = s2.status === "in_progress" ? [...stepWaits(fact, factSteps.get(s2.id), { trains: facts, ...load3 ? { load: load3 } : {} }), ...recorded].slice(0, 8).map((w) => cleanWait(w, clean6)) : [];
|
|
11996
|
-
const gate = s2.status === "in_progress" ? readGate(
|
|
12064
|
+
const gate = s2.status === "in_progress" ? readGate(join30(dirname10(read4.file), `gate-${s2.id}.json`), budget) : void 0;
|
|
11997
12065
|
const gateOk = gate && gate.train === board.code && gate.step === s2.id && isoTime(gate.since) && isoTime(gate.updated);
|
|
11998
12066
|
return {
|
|
11999
12067
|
id: s2.id,
|
|
@@ -12082,11 +12150,11 @@ function trainyardSeam(o) {
|
|
|
12082
12150
|
|
|
12083
12151
|
// src/boardview.ts
|
|
12084
12152
|
import { statSync as statSync8, readdirSync as readdirSync9 } from "node:fs";
|
|
12085
|
-
import { join as
|
|
12153
|
+
import { join as join32 } from "node:path";
|
|
12086
12154
|
|
|
12087
12155
|
// src/capacity.ts
|
|
12088
|
-
import { mkdirSync as
|
|
12089
|
-
import { dirname as
|
|
12156
|
+
import { mkdirSync as mkdirSync9, readdirSync as readdirSync8, readFileSync as readFileSync19, renameSync as renameSync6, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
|
|
12157
|
+
import { dirname as dirname11, join as join31 } from "node:path";
|
|
12090
12158
|
var MIN = 6e4;
|
|
12091
12159
|
var DEFAULT_POINTS = 1;
|
|
12092
12160
|
var STALE_UNATTENDED_MS = 30 * MIN;
|
|
@@ -12098,11 +12166,11 @@ var DEVICE_FRESH_MS = 5 * MIN;
|
|
|
12098
12166
|
var JOBS = 50;
|
|
12099
12167
|
var DETAIL = 120;
|
|
12100
12168
|
var num2 = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi ? v : void 0;
|
|
12101
|
-
var capDir = (boardDir) =>
|
|
12169
|
+
var capDir = (boardDir) => join31(dirname11(boardDir), "capacity");
|
|
12102
12170
|
function readBudget(stateDir) {
|
|
12103
12171
|
let b;
|
|
12104
12172
|
try {
|
|
12105
|
-
b = JSON.parse(readFileSync19(
|
|
12173
|
+
b = JSON.parse(readFileSync19(join31(stateDir, "config.json"), "utf8")).capacity?.budget;
|
|
12106
12174
|
} catch {
|
|
12107
12175
|
return void 0;
|
|
12108
12176
|
}
|
|
@@ -12111,8 +12179,8 @@ function readBudget(stateDir) {
|
|
|
12111
12179
|
var DEVICE = "_device.json";
|
|
12112
12180
|
var SENT = "_sent.json";
|
|
12113
12181
|
function writeJson2(dir, name2, value) {
|
|
12114
|
-
|
|
12115
|
-
const file3 =
|
|
12182
|
+
mkdirSync9(dir, { recursive: true, mode: 448 });
|
|
12183
|
+
const file3 = join31(dir, name2), temp = `${file3}.${process.pid}.tmp`;
|
|
12116
12184
|
try {
|
|
12117
12185
|
writeFileSync6(temp, `${JSON.stringify(value)}
|
|
12118
12186
|
`, { mode: 384 });
|
|
@@ -12134,7 +12202,7 @@ var jobsOf = (v, max = JOBS) => Array.isArray(v) ? v.slice(0, max).flatMap((j) =
|
|
|
12134
12202
|
const points = num2(j?.points, 0, 10), owner = clean(j?.owner, 64);
|
|
12135
12203
|
return points === void 0 ? [] : [{ ...owner ? { owner } : {}, points, ...num2(j?.until, 0, 864e13) !== void 0 ? { until: j.until } : {} }];
|
|
12136
12204
|
}) : [];
|
|
12137
|
-
var removeCap = (dir, session) => void (safeSession(session) && rmSync7(
|
|
12205
|
+
var removeCap = (dir, session) => void (safeSession(session) && rmSync7(join31(dir, `${session}.json`), { force: true }));
|
|
12138
12206
|
function readCaps(dir) {
|
|
12139
12207
|
let names = [];
|
|
12140
12208
|
try {
|
|
@@ -12142,7 +12210,7 @@ function readCaps(dir) {
|
|
|
12142
12210
|
} catch {
|
|
12143
12211
|
}
|
|
12144
12212
|
return names.flatMap((name2) => {
|
|
12145
|
-
const raw = readJson2(
|
|
12213
|
+
const raw = readJson2(join31(dir, name2)), session = name2.slice(0, -".json".length);
|
|
12146
12214
|
if (raw?.v !== 1 || raw.session !== session || !safeSession(session) || num2(raw.updated, 0, 864e13) === void 0) return [];
|
|
12147
12215
|
const p = raw.pause, at = num2(p?.at, 0, 864e13), until = num2(p?.until, 0, 864e13), detail = clean(p?.detail, DETAIL);
|
|
12148
12216
|
const pause = p?.reason === "quota" && at !== void 0 ? { reason: "quota", at, ...until !== void 0 ? { until } : {}, ...detail ? { detail } : {} } : void 0;
|
|
@@ -12205,11 +12273,11 @@ var roomFor = (d) => d.budget !== void 0 && d.minReady !== void 0 && d.points +
|
|
|
12205
12273
|
var underFor = (d, now) => d.under !== void 0 && now - d.under >= UNDER_HOLD_MS ? now - d.under : void 0;
|
|
12206
12274
|
var writeDevice = (dir, d) => writeJson2(dir, DEVICE, d);
|
|
12207
12275
|
function readDevice(dir, now) {
|
|
12208
|
-
const raw = readJson2(
|
|
12276
|
+
const raw = readJson2(join31(dir, DEVICE));
|
|
12209
12277
|
if (raw?.v !== 1 || num2(raw.at, 0, 864e13) === void 0 || now - raw.at > DEVICE_FRESH_MS || !Array.isArray(raw.mains)) return void 0;
|
|
12210
12278
|
return raw;
|
|
12211
12279
|
}
|
|
12212
|
-
var readSent = (dir) => Object.fromEntries(Object.entries(readJson2(
|
|
12280
|
+
var readSent = (dir) => Object.fromEntries(Object.entries(readJson2(join31(dir, SENT)) ?? {}).filter((e) => typeof e[1] === "number"));
|
|
12213
12281
|
var writeSent = (dir, sent) => writeJson2(dir, SENT, sent);
|
|
12214
12282
|
var pts = (n) => `${round(n)}`;
|
|
12215
12283
|
function clock2(at, now) {
|
|
@@ -12293,7 +12361,7 @@ function cachedEntries(read4 = readEntries) {
|
|
|
12293
12361
|
let sig;
|
|
12294
12362
|
try {
|
|
12295
12363
|
sig = readdirSync9(dir).filter((n) => n.endsWith(".json")).sort().map((n) => {
|
|
12296
|
-
const st = statSync8(
|
|
12364
|
+
const st = statSync8(join32(dir, n));
|
|
12297
12365
|
return `${n}:${st.size}:${st.mtimeMs}:${st.ino}`;
|
|
12298
12366
|
}).join("|");
|
|
12299
12367
|
} catch {
|
|
@@ -12355,8 +12423,8 @@ function createGuiHost(o) {
|
|
|
12355
12423
|
let lan;
|
|
12356
12424
|
let remoteNote;
|
|
12357
12425
|
let rotating;
|
|
12358
|
-
const deploys = createDeploys(), openings = createOpenings(
|
|
12359
|
-
const answered = createAnswered(answeredFileDeps(
|
|
12426
|
+
const deploys = createDeploys(), openings = createOpenings(join33(slot.stateDir, "openings.json")), intents = createIntents(), lock = { busy: false }, trust = createTrustServe({ dir: trustDir(slot.stateDir), herdr: slot.herdr, world: () => cfg.world(), opening: deploys.openingOf });
|
|
12427
|
+
const answered = createAnswered(answeredFileDeps(join33(dir, "answered.json")));
|
|
12360
12428
|
const live = async (session) => (await o.sessions()).some((x) => x.id === session);
|
|
12361
12429
|
const theHub = () => hub ??= createHub(kit.pi, id2, NO_BRIDGE, o.onAllow);
|
|
12362
12430
|
const recorded = () => {
|
|
@@ -12427,7 +12495,7 @@ function createGuiHost(o) {
|
|
|
12427
12495
|
for (const end = Date.now() + RECLAIM_WAIT_MS; Date.now() < end; await new Promise((r) => setTimeout(r, 100))) if (!await listening(seen.port)) return true;
|
|
12428
12496
|
return false;
|
|
12429
12497
|
};
|
|
12430
|
-
const boardDir =
|
|
12498
|
+
const boardDir = join33(slot.stateDir, "board");
|
|
12431
12499
|
const sharedNet = () => current ??= netSource({ ...o.auto ? { auto: () => o.auto.snap(), autoable: () => o.auto.available() } : {}, ...o.tower ? { services: (workspace) => o.tower.view(workspace) } : {}, ...o.head ? { head: o.head } : {}, run: cfg.run, world: cfg.world, sessions, stashed: () => stashedList(slot.stateDir), trust, hub: theHub(), board: boardSeam({ dir: boardDir, now: () => cfg.now() }), trainyard: trainyardSeam({ env: cfg.env, stateDir: slot.stateDir, ...o.trainCars ? { book: o.trainCars } : {}, ...o.trainyard }) });
|
|
12432
12500
|
const watchers = /* @__PURE__ */ new Set();
|
|
12433
12501
|
let lastNet;
|
|
@@ -12456,7 +12524,7 @@ function createGuiHost(o) {
|
|
|
12456
12524
|
call: cfg.call,
|
|
12457
12525
|
hub,
|
|
12458
12526
|
dir: o.bundle ?? BUNDLE,
|
|
12459
|
-
paired:
|
|
12527
|
+
paired: join33(dir, "paired.json"),
|
|
12460
12528
|
answered,
|
|
12461
12529
|
port: prefer.port,
|
|
12462
12530
|
remotePort: prefer.remotePort,
|
|
@@ -12465,7 +12533,7 @@ function createGuiHost(o) {
|
|
|
12465
12533
|
desk: cfg.env.STRAW_BOSS_DESK === "1",
|
|
12466
12534
|
view,
|
|
12467
12535
|
music: musicDirOf(cfg.env),
|
|
12468
|
-
lan: { panel: host.panel, overlay: host.faces, ...slot.primary ? { file:
|
|
12536
|
+
lan: { panel: host.panel, overlay: host.faces, ...slot.primary ? { file: join33(dir, "lan.json") } : {}, notify: host.event, log: (event, fields) => log.line(event, Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, typeof v === "string" || typeof v === "number" || typeof v === "boolean" ? v : JSON.stringify(v)]))) },
|
|
12469
12537
|
link: { call: (name2, args) => o.link.call(name2, args), enable: () => o.link.enable() },
|
|
12470
12538
|
...o.operateHost ? { operateHost: o.operateHost() } : {},
|
|
12471
12539
|
...o.tower ? { tower: o.tower } : {},
|
|
@@ -12565,7 +12633,7 @@ function createGuiHost(o) {
|
|
|
12565
12633
|
};
|
|
12566
12634
|
const gone = (error) => ({ ok: false, error: error.message });
|
|
12567
12635
|
const guiFacts = (g) => ({ url: g.url, port: g.port, remotePort: g.remotePort, token: g.token });
|
|
12568
|
-
const lanFile = () =>
|
|
12636
|
+
const lanFile = () => join33(dir, "lan.json");
|
|
12569
12637
|
const savedLan = () => {
|
|
12570
12638
|
try {
|
|
12571
12639
|
const saved = JSON.parse(readFileSync20(lanFile(), "utf8"));
|
|
@@ -12615,7 +12683,7 @@ function createGuiHost(o) {
|
|
|
12615
12683
|
async start() {
|
|
12616
12684
|
theHub().track();
|
|
12617
12685
|
try {
|
|
12618
|
-
writeJson(
|
|
12686
|
+
writeJson(join33(dir, "hub.json"), { pid, ownerSession: id2 });
|
|
12619
12687
|
} catch (error) {
|
|
12620
12688
|
log.line("hub-json-failed", { text: phrase(error.message, 300) });
|
|
12621
12689
|
o.failed("hub.json", error.message);
|
|
@@ -13189,7 +13257,7 @@ function towerOpener(d) {
|
|
|
13189
13257
|
import { createHash as createHash11 } from "node:crypto";
|
|
13190
13258
|
import { lstatSync as lstatSync7, readFileSync as readFileSync21 } from "node:fs";
|
|
13191
13259
|
import { homedir as homedir8 } from "node:os";
|
|
13192
|
-
import { basename as basename8, isAbsolute as isAbsolute5, join as
|
|
13260
|
+
import { basename as basename8, isAbsolute as isAbsolute5, join as join34 } from "node:path";
|
|
13193
13261
|
var POLL_MS = 6e4;
|
|
13194
13262
|
var JANITOR_MS = 10 * 6e4;
|
|
13195
13263
|
var LEDGER_KEY = "ledger_sweep:";
|
|
@@ -13211,12 +13279,12 @@ var interval = (fn, ms3) => {
|
|
|
13211
13279
|
return () => clearInterval(t);
|
|
13212
13280
|
};
|
|
13213
13281
|
function createLedgerSweep(o) {
|
|
13214
|
-
const { stateDir } = o.slot, marker =
|
|
13282
|
+
const { stateDir } = o.slot, marker = join34(stateDir, "ledger-sweep-date.json"), cancelled2 = new AbortController();
|
|
13215
13283
|
const config = () => {
|
|
13216
|
-
const raw = field(field(load(
|
|
13284
|
+
const raw = field(field(load(join34(stateDir, "config.json")), "ledger"), "janitor");
|
|
13217
13285
|
if (raw === void 0) return void 0;
|
|
13218
13286
|
if (typeof raw !== "string" || !raw.trim() || /[\p{Cc}]/u.test(raw)) throw new Error("ledger.janitor must name one executable by absolute path");
|
|
13219
|
-
const path = raw.startsWith("~/") ?
|
|
13287
|
+
const path = raw.startsWith("~/") ? join34(o.env.HOME ?? homedir8(), raw.slice(2)) : raw;
|
|
13220
13288
|
if (!isAbsolute5(path)) throw new Error("ledger.janitor must name one executable by absolute path");
|
|
13221
13289
|
return path;
|
|
13222
13290
|
};
|
|
@@ -13290,7 +13358,7 @@ function createLedgerSweep(o) {
|
|
|
13290
13358
|
if (ws) matched.push({ workspace: ws, repo: clean(row2.repo, 300), path: clean(row2.path, 400), reason: clean(row2.reason, 300), ...row2.owner_hint ? { owner_hint: clean(row2.owner_hint, 120) } : {} });
|
|
13291
13359
|
else {
|
|
13292
13360
|
const id2 = createHash11("sha256").update(JSON.stringify([row2.repo, row2.path, row2.reason])).digest("hex").slice(0, 24);
|
|
13293
|
-
writeEntry(
|
|
13361
|
+
writeEntry(join34(stateDir, "board"), `ledger-${id2}`, { now: clean(`${basename8(row2.path) || "ledger item"}: ${row2.reason}`, 120), items: [] }, o.now(), { src: "todo", who: "Ledger sweep" });
|
|
13294
13362
|
unmatched++;
|
|
13295
13363
|
}
|
|
13296
13364
|
}
|
|
@@ -13331,7 +13399,7 @@ function createLedgerSweep(o) {
|
|
|
13331
13399
|
// src/link/service.ts
|
|
13332
13400
|
import { readFileSync as readFileSync23 } from "node:fs";
|
|
13333
13401
|
import { homedir as homedir9 } from "node:os";
|
|
13334
|
-
import { join as
|
|
13402
|
+
import { join as join36 } from "node:path";
|
|
13335
13403
|
|
|
13336
13404
|
// src/link/holder.ts
|
|
13337
13405
|
import { Buffer as Buffer5 } from "node:buffer";
|
|
@@ -14009,9 +14077,9 @@ function checkJoiner(o) {
|
|
|
14009
14077
|
|
|
14010
14078
|
// src/link/joinfile.ts
|
|
14011
14079
|
import { constants as constants6, fstatSync as fstatSync4, lstatSync as lstatSync8, openSync as openSync5, readFileSync as readFileSync22, closeSync as closeSync5, unlinkSync } from "node:fs";
|
|
14012
|
-
import { join as
|
|
14080
|
+
import { join as join35 } from "node:path";
|
|
14013
14081
|
var JOIN_FILE = "join.txt";
|
|
14014
|
-
var joinFilePath = (linkDir) =>
|
|
14082
|
+
var joinFilePath = (linkDir) => join35(linkDir, JOIN_FILE);
|
|
14015
14083
|
function fileMark(path) {
|
|
14016
14084
|
try {
|
|
14017
14085
|
const st = lstatSync8(path);
|
|
@@ -17200,8 +17268,8 @@ var waitOf = (v) => {
|
|
|
17200
17268
|
var NOT_SET_UP = "Straw Link is not set up on this computer: no link holder runs here. Open Teams in the GUI and press Set up";
|
|
17201
17269
|
function createLinkService({ kit, stateDir, version, started, pid = process.pid, notify, deps: opts = {}, tower, dialogAnswer, unitStop, operate, operateWatch, controller, onRoster, onHolder }) {
|
|
17202
17270
|
const { pi, cfg } = kit;
|
|
17203
|
-
const store2 = new LinkStore(
|
|
17204
|
-
const home = opts.home ?? homedir9(), agentDir = cfg.env.PI_CODING_AGENT_DIR ??
|
|
17271
|
+
const store2 = new LinkStore(join36(stateDir, "link"), { unattended: () => unattendedNow(policyDeps), unattendedStamp: () => policyStamp(policyDeps.path ?? POLICY_PATH) });
|
|
17272
|
+
const home = opts.home ?? homedir9(), agentDir = cfg.env.PI_CODING_AGENT_DIR ?? join36(home, ".pi", "agent");
|
|
17205
17273
|
const policyDeps = { home, agentDir, ...opts.policy };
|
|
17206
17274
|
const policy = () => readPolicy(policyDeps);
|
|
17207
17275
|
const config = () => readEffectiveConfig(policy(), stateDir, { home, agentDir });
|
|
@@ -17209,7 +17277,7 @@ function createLinkService({ kit, stateDir, version, started, pid = process.pid,
|
|
|
17209
17277
|
const attended = () => policy().mode === "attended";
|
|
17210
17278
|
const guiOwner = () => {
|
|
17211
17279
|
try {
|
|
17212
|
-
return JSON.parse(readFileSync23(
|
|
17280
|
+
return JSON.parse(readFileSync23(join36(stateDir, "gui.json"), "utf8")).ownerSession || void 0;
|
|
17213
17281
|
} catch {
|
|
17214
17282
|
return void 0;
|
|
17215
17283
|
}
|
|
@@ -17267,7 +17335,7 @@ function createLinkService({ kit, stateDir, version, started, pid = process.pid,
|
|
|
17267
17335
|
const gained = async () => {
|
|
17268
17336
|
const fresh = new LinkHolder({
|
|
17269
17337
|
store: store2,
|
|
17270
|
-
boardDir:
|
|
17338
|
+
boardDir: join36(stateDir, "board"),
|
|
17271
17339
|
isHolder: () => Boolean(election?.isHolder()),
|
|
17272
17340
|
config,
|
|
17273
17341
|
stateDir,
|
|
@@ -18331,8 +18399,8 @@ function createOperateHost(deps) {
|
|
|
18331
18399
|
}
|
|
18332
18400
|
for (const [k, v] of Object.entries(units)) if (v.state === (state === "live" ? "live" : "unreachable") && v.scope === scope) delete units[k];
|
|
18333
18401
|
const box = { device: first2.s.offer.device, short: first2.s.offer.short, label: first2.s.offer.label, team: teams, scope, can: canOf(scope), state, ...state === "unreachable" ? { seen } : {}, ...Object.keys(units).length ? { units } : {} };
|
|
18334
|
-
const parts = { tower, tabs: [...tabs2.values()], outposts: [...outposts.values()], outside: [...outside.values()] },
|
|
18335
|
-
return { id: first2.b.id, label: first2.b.label, mark:
|
|
18402
|
+
const parts = { tower, tabs: [...tabs2.values()], outposts: [...outposts.values()], outside: [...outside.values()] }, marks2 = marksOf2(parts);
|
|
18403
|
+
return { id: first2.b.id, label: first2.b.label, mark: marks2.includes("waiting") ? "waiting" : marks2.includes("working") ? "working" : "idle", box, ...parts };
|
|
18336
18404
|
}
|
|
18337
18405
|
function tick() {
|
|
18338
18406
|
if (stopped) return;
|
|
@@ -18463,8 +18531,8 @@ function createOperateHost(deps) {
|
|
|
18463
18531
|
}
|
|
18464
18532
|
|
|
18465
18533
|
// src/server/operateoff.ts
|
|
18466
|
-
import { chmodSync as chmodSync4, lstatSync as lstatSync9, mkdirSync as
|
|
18467
|
-
import { dirname as
|
|
18534
|
+
import { chmodSync as chmodSync4, lstatSync as lstatSync9, mkdirSync as mkdirSync10, readFileSync as readFileSync24, rmSync as rmSync8 } from "node:fs";
|
|
18535
|
+
import { dirname as dirname12 } from "node:path";
|
|
18468
18536
|
var present2 = (path) => {
|
|
18469
18537
|
try {
|
|
18470
18538
|
lstatSync9(path);
|
|
@@ -18486,7 +18554,7 @@ function operateOff(file3, now) {
|
|
|
18486
18554
|
off(at) {
|
|
18487
18555
|
since = at;
|
|
18488
18556
|
try {
|
|
18489
|
-
|
|
18557
|
+
mkdirSync10(dirname12(file3), { recursive: true, mode: 448 });
|
|
18490
18558
|
writeDurableText(file3, `${JSON.stringify({ since: at })}
|
|
18491
18559
|
`);
|
|
18492
18560
|
chmodSync4(file3, 384);
|
|
@@ -18509,14 +18577,14 @@ function operateOff(file3, now) {
|
|
|
18509
18577
|
|
|
18510
18578
|
// src/server/operatewire.ts
|
|
18511
18579
|
import { homedir as homedir10 } from "node:os";
|
|
18512
|
-
import { join as
|
|
18580
|
+
import { join as join38 } from "node:path";
|
|
18513
18581
|
|
|
18514
18582
|
// src/server/towerrunstore.ts
|
|
18515
|
-
import { appendFileSync as
|
|
18516
|
-
import { join as
|
|
18583
|
+
import { appendFileSync as appendFileSync3, readdirSync as readdirSync10, readFileSync as readFileSync25, rmSync as rmSync9 } from "node:fs";
|
|
18584
|
+
import { join as join37 } from "node:path";
|
|
18517
18585
|
var KEEP_RUNS = 50;
|
|
18518
18586
|
var KEEP_NOTES = 10;
|
|
18519
|
-
var runsDir = (slot, workspace) =>
|
|
18587
|
+
var runsDir = (slot, workspace) => join37(towerDir(slot, workspace), "runs");
|
|
18520
18588
|
var readJson3 = (file3) => {
|
|
18521
18589
|
try {
|
|
18522
18590
|
return JSON.parse(readFileSync25(file3, "utf8"));
|
|
@@ -18527,9 +18595,9 @@ var readJson3 = (file3) => {
|
|
|
18527
18595
|
function writeRun(slot, run3) {
|
|
18528
18596
|
ensureDir(towerDir(slot, run3.workspace));
|
|
18529
18597
|
ensureDir(runsDir(slot, run3.workspace));
|
|
18530
|
-
writeDurable(
|
|
18598
|
+
writeDurable(join37(runsDir(slot, run3.workspace), `${safe(run3.id)}.json`), run3);
|
|
18531
18599
|
}
|
|
18532
|
-
var readRun = (slot, workspace, id2) => readJson3(
|
|
18600
|
+
var readRun = (slot, workspace, id2) => readJson3(join37(runsDir(slot, workspace), `${safe(id2)}.json`));
|
|
18533
18601
|
function listRuns(slot, workspace) {
|
|
18534
18602
|
let names = [];
|
|
18535
18603
|
try {
|
|
@@ -18538,15 +18606,15 @@ function listRuns(slot, workspace) {
|
|
|
18538
18606
|
return [];
|
|
18539
18607
|
}
|
|
18540
18608
|
return names.flatMap((n) => {
|
|
18541
|
-
const run3 = readJson3(
|
|
18609
|
+
const run3 = readJson3(join37(runsDir(slot, workspace), n));
|
|
18542
18610
|
return run3 && typeof run3.id === "string" && typeof run3.startedAt === "string" ? [run3] : [];
|
|
18543
18611
|
}).sort((a, b) => a.startedAt.localeCompare(b.startedAt));
|
|
18544
18612
|
}
|
|
18545
18613
|
function pruneRuns(slot, workspace) {
|
|
18546
18614
|
const all = listRuns(slot, workspace);
|
|
18547
|
-
for (const run3 of all.slice(0, Math.max(0, all.length - KEEP_RUNS))) if (run3.outcome) rmSync9(
|
|
18615
|
+
for (const run3 of all.slice(0, Math.max(0, all.length - KEEP_RUNS))) if (run3.outcome) rmSync9(join37(runsDir(slot, workspace), `${safe(run3.id)}.json`), { force: true });
|
|
18548
18616
|
}
|
|
18549
|
-
var notesFile = (slot, workspace) =>
|
|
18617
|
+
var notesFile = (slot, workspace) => join37(towerDir(slot, workspace), "notes.jsonl");
|
|
18550
18618
|
function readNotes(slot, workspace) {
|
|
18551
18619
|
try {
|
|
18552
18620
|
return readFileSync25(notesFile(slot, workspace), "utf8").split("\n").flatMap((line4) => {
|
|
@@ -18565,20 +18633,20 @@ function addNote(slot, workspace, row2) {
|
|
|
18565
18633
|
ensureDir(towerDir(slot, workspace));
|
|
18566
18634
|
const same5 = (r) => r.kind === row2.kind && r.device === row2.device;
|
|
18567
18635
|
const all = [...readNotes(slot, workspace), row2], mine = all.filter(same5);
|
|
18568
|
-
if (mine.length <= KEEP_NOTES) return void
|
|
18636
|
+
if (mine.length <= KEEP_NOTES) return void appendFileSync3(notesFile(slot, workspace), `${JSON.stringify(row2)}
|
|
18569
18637
|
`, { mode: 384 });
|
|
18570
18638
|
const drop = new Set(mine.slice(0, mine.length - KEEP_NOTES));
|
|
18571
18639
|
writeDurableText(notesFile(slot, workspace), all.filter((r) => !drop.has(r)).map((r) => JSON.stringify(r)).join("\n") + "\n");
|
|
18572
18640
|
}
|
|
18573
18641
|
var lastNote = (slot, workspace, kind, device) => readNotes(slot, workspace).filter((r) => r.kind === kind && r.device === device).at(-1);
|
|
18574
|
-
var timerFile = (slot, workspace) =>
|
|
18642
|
+
var timerFile = (slot, workspace) => join37(towerDir(slot, workspace), "timer.json");
|
|
18575
18643
|
var readTimer = (slot, workspace) => readJson3(timerFile(slot, workspace));
|
|
18576
18644
|
function writeTimer(slot, workspace, value) {
|
|
18577
18645
|
ensureDir(towerDir(slot, workspace));
|
|
18578
18646
|
writeDurable(timerFile(slot, workspace), value);
|
|
18579
18647
|
}
|
|
18580
18648
|
var clearTimer = (slot, workspace) => rmSync9(timerFile(slot, workspace), { force: true });
|
|
18581
|
-
var expectsFile = (slot, workspace) =>
|
|
18649
|
+
var expectsFile = (slot, workspace) => join37(towerDir(slot, workspace), "expects.json");
|
|
18582
18650
|
var EXPECT_KEEP_MS = 24 * 36e5;
|
|
18583
18651
|
function readExpects(slot, workspace, now) {
|
|
18584
18652
|
const found = readJson3(expectsFile(slot, workspace));
|
|
@@ -19237,12 +19305,12 @@ function createOperateBox(d) {
|
|
|
19237
19305
|
|
|
19238
19306
|
// src/server/operateledger.ts
|
|
19239
19307
|
import { createHash as createHash14 } from "node:crypto";
|
|
19240
|
-
import { appendFileSync as
|
|
19241
|
-
import { dirname as
|
|
19308
|
+
import { appendFileSync as appendFileSync4, chmodSync as chmodSync5, closeSync as closeSync6, constants as constants7, fstatSync as fstatSync5, mkdirSync as mkdirSync11, openSync as openSync6, readFileSync as readFileSync26, statSync as statSync9 } from "node:fs";
|
|
19309
|
+
import { dirname as dirname13, sep as sep6 } from "node:path";
|
|
19242
19310
|
var KEEP_MS7 = 30 * 24 * 36e5;
|
|
19243
19311
|
var MAX_ROWS2 = 2e3;
|
|
19244
19312
|
var MAX_LIST = 50;
|
|
19245
|
-
var
|
|
19313
|
+
var ID3 = /^[0-9a-f]{16}$/;
|
|
19246
19314
|
var KEY = /^t([0-9a-f]{16})$/;
|
|
19247
19315
|
var CURSOR2 = /^(\d{1,16}):([0-9a-f]{16})$/;
|
|
19248
19316
|
var DEVICE2 = /^[a-z2-7]{26}$/;
|
|
@@ -19252,7 +19320,7 @@ var HEAD2 = "head";
|
|
|
19252
19320
|
var idOf2 = (file3) => createHash14("sha256").update("straw-link/operate-ledger/1\0").update(file3).digest("hex").slice(0, 16);
|
|
19253
19321
|
var isRow = (v) => {
|
|
19254
19322
|
const r = v;
|
|
19255
|
-
return typeof r === "object" && r !== null && typeof r.id === "string" &&
|
|
19323
|
+
return typeof r === "object" && r !== null && typeof r.id === "string" && ID3.test(r.id) && typeof r.team === "string" && (r.team === BOX2 || TEAM.test(r.team)) && (r.device === void 0 || typeof r.device === "string" && DEVICE2.test(r.device)) && typeof r.role === "string" && UNIT_ROLES.includes(r.role) && typeof r.name === "string" && r.name.length <= 200 && typeof r.workspace === "string" && r.workspace.length <= 200 && typeof r.file === "string" && r.file.length > 0 && r.file.length <= 4096 && Number.isSafeInteger(r.first) && Number.isSafeInteger(r.last) && (r.ended === void 0 || r.ended === true) && idOf2(r.file) === r.id;
|
|
19256
19324
|
};
|
|
19257
19325
|
var text7 = (row2) => `${JSON.stringify(row2)}
|
|
19258
19326
|
`;
|
|
@@ -19307,7 +19375,7 @@ function openLedger(d) {
|
|
|
19307
19375
|
const kept = [...rows.values()].filter((r) => at - r.last <= KEEP_MS7).sort(order).slice(0, MAX_ROWS2);
|
|
19308
19376
|
if (kept.length !== rows.size || lines !== rows.size || source && !source.endsWith("\n")) {
|
|
19309
19377
|
try {
|
|
19310
|
-
|
|
19378
|
+
mkdirSync11(dirname13(d.file), { recursive: true, mode: 448 });
|
|
19311
19379
|
writeDurableText(d.file, kept.slice().reverse().map(text7).join(""));
|
|
19312
19380
|
} catch (error) {
|
|
19313
19381
|
failed2(error);
|
|
@@ -19316,8 +19384,8 @@ function openLedger(d) {
|
|
|
19316
19384
|
const book = new Map(kept.map((r) => [r.id, r]));
|
|
19317
19385
|
const write2 = (row3) => {
|
|
19318
19386
|
try {
|
|
19319
|
-
|
|
19320
|
-
|
|
19387
|
+
mkdirSync11(dirname13(d.file), { recursive: true, mode: 448 });
|
|
19388
|
+
appendFileSync4(d.file, text7(row3), { mode: 384 });
|
|
19321
19389
|
} catch (error) {
|
|
19322
19390
|
failed2(error);
|
|
19323
19391
|
}
|
|
@@ -19447,9 +19515,9 @@ function readingOf(net) {
|
|
|
19447
19515
|
return { labels, finished };
|
|
19448
19516
|
}
|
|
19449
19517
|
function operateRecord(o, facts) {
|
|
19450
|
-
const sessionDir = o.sessionDir ??
|
|
19518
|
+
const sessionDir = o.sessionDir ?? join38(process.env.PI_CODING_AGENT_DIR ?? join38(homedir10(), ".pi", "agent"), "sessions");
|
|
19451
19519
|
const ledger = openLedger({
|
|
19452
|
-
file:
|
|
19520
|
+
file: join38(o.slot.stateDir, "link", "operate-ledger.jsonl"),
|
|
19453
19521
|
root: sessionDir,
|
|
19454
19522
|
now: o.now,
|
|
19455
19523
|
label: (device) => o.link()?.holder?.list().flatMap((t) => t.devices).find((x) => x.id === device)?.label,
|
|
@@ -19518,13 +19586,13 @@ function operateWire(o) {
|
|
|
19518
19586
|
// src/server/carops.ts
|
|
19519
19587
|
import { existsSync as existsSync5, readFileSync as readFileSync28 } from "node:fs";
|
|
19520
19588
|
import { homedir as homedir11 } from "node:os";
|
|
19521
|
-
import { join as
|
|
19589
|
+
import { join as join40, parse as parse4, resolve as resolve6 } from "node:path";
|
|
19522
19590
|
|
|
19523
19591
|
// src/server/carbook.ts
|
|
19524
19592
|
import { randomBytes as randomBytes20 } from "node:crypto";
|
|
19525
|
-
import { lstatSync as lstatSync10, mkdirSync as
|
|
19593
|
+
import { lstatSync as lstatSync10, mkdirSync as mkdirSync12, mkdtempSync, readdirSync as readdirSync11, readFileSync as readFileSync27, rmSync as rmSync10, writeFileSync as writeFileSync7 } from "node:fs";
|
|
19526
19594
|
import { hostname as hostname3 } from "node:os";
|
|
19527
|
-
import { isAbsolute as isAbsolute8, join as
|
|
19595
|
+
import { isAbsolute as isAbsolute8, join as join39, parse as parse3 } from "node:path";
|
|
19528
19596
|
var KEEP_MS8 = 24 * 36e5;
|
|
19529
19597
|
var MAX_FORWARDS = 512;
|
|
19530
19598
|
var MAX_FILES = 256;
|
|
@@ -19610,7 +19678,7 @@ var entries = (path) => {
|
|
|
19610
19678
|
return [];
|
|
19611
19679
|
}
|
|
19612
19680
|
};
|
|
19613
|
-
var filesUnder = (dir, prefix = "") => entries(dir).flatMap((n) => kindOf2(
|
|
19681
|
+
var filesUnder = (dir, prefix = "") => entries(dir).flatMap((n) => kindOf2(join39(dir, n)) === "dir" ? filesUnder(join39(dir, n), `${prefix}${n}/`) : [`${prefix}${n}`]);
|
|
19614
19682
|
var INIT_KEYS = /* @__PURE__ */ new Set(["repositoryformatversion", "filemode", "bare", "logallrefupdates", "ignorecase", "precomposeunicode", "symlinks"]);
|
|
19615
19683
|
function strangeConfig(text14) {
|
|
19616
19684
|
let core = false;
|
|
@@ -19632,20 +19700,20 @@ function inspectMirror(dir, code, stage, before) {
|
|
|
19632
19700
|
const bad2 = [];
|
|
19633
19701
|
const top2 = /* @__PURE__ */ new Set(["HEAD", "config", "objects", "refs", ...stage === "init" ? [] : ["FETCH_HEAD"]]);
|
|
19634
19702
|
for (const n of entries(dir)) if (!top2.has(n)) bad2.push(n);
|
|
19635
|
-
for (const n of ["HEAD", "config"]) if (kindOf2(
|
|
19636
|
-
const objects =
|
|
19703
|
+
for (const n of ["HEAD", "config"]) if (kindOf2(join39(dir, n)) !== "file") bad2.push(n);
|
|
19704
|
+
const objects = join39(dir, "objects");
|
|
19637
19705
|
if (kindOf2(objects) !== "dir") bad2.push("objects");
|
|
19638
19706
|
for (const n of entries(objects)) if (n !== "info" && n !== "pack") bad2.push(`objects/${n}`);
|
|
19639
|
-
if (kindOf2(
|
|
19640
|
-
for (const n of entries(
|
|
19641
|
-
const packDir =
|
|
19707
|
+
if (kindOf2(join39(objects, "info")) !== "dir") bad2.push("objects/info");
|
|
19708
|
+
for (const n of entries(join39(objects, "info"))) bad2.push(`objects/info/${n}`);
|
|
19709
|
+
const packDir = join39(objects, "pack");
|
|
19642
19710
|
if (kindOf2(packDir) !== "dir") bad2.push("objects/pack");
|
|
19643
19711
|
const packs = entries(packDir);
|
|
19644
|
-
for (const n of packs) if (!PACK_FILE.test(n) || kindOf2(
|
|
19712
|
+
for (const n of packs) if (!PACK_FILE.test(n) || kindOf2(join39(packDir, n)) !== "file") bad2.push(`objects/pack/${n}`);
|
|
19645
19713
|
const names = packs.filter((n) => n.endsWith(".pack"));
|
|
19646
19714
|
for (const n of names) if (!packs.includes(n.replace(/\.pack$/, ".idx"))) bad2.push(`objects/pack/${n} (no index)`);
|
|
19647
19715
|
if (stage === "init" ? packs.length : names.length !== 1) bad2.push(stage === "init" ? "objects/pack (not empty)" : `objects/pack (the fetch of one branch writes one pack, found ${names.length})`);
|
|
19648
|
-
const refs =
|
|
19716
|
+
const refs = join39(dir, "refs");
|
|
19649
19717
|
if (kindOf2(refs) !== "dir") bad2.push("refs");
|
|
19650
19718
|
const refFiles = kindOf2(refs) === "dir" ? filesUnder(refs) : [];
|
|
19651
19719
|
const wanted = stage === "init" ? [] : [`sb/base/${code}`];
|
|
@@ -19653,12 +19721,12 @@ function inspectMirror(dir, code, stage, before) {
|
|
|
19653
19721
|
if (stage !== "init" && !refFiles.includes(wanted[0])) bad2.push(`refs/${wanted[0]} (missing)`);
|
|
19654
19722
|
if (bad2.length) return { problems: bad2 };
|
|
19655
19723
|
if (stage === "init") {
|
|
19656
|
-
const odd = strangeConfig(readFileSync27(
|
|
19724
|
+
const odd = strangeConfig(readFileSync27(join39(dir, "config"), "utf8"));
|
|
19657
19725
|
if (odd) return { problems: [`config: ${odd}`] };
|
|
19658
|
-
if (!/^ref: refs\/heads\/[A-Za-z0-9._/-]+\r?\n?$/.test(readFileSync27(
|
|
19726
|
+
if (!/^ref: refs\/heads\/[A-Za-z0-9._/-]+\r?\n?$/.test(readFileSync27(join39(dir, "HEAD"), "utf8"))) return { problems: ["HEAD"] };
|
|
19659
19727
|
}
|
|
19660
|
-
const refValue = refFiles.length ? refFiles.map((f) => readFileSync27(
|
|
19661
|
-
const look2 = { refs: refValue, config: readFileSync27(
|
|
19728
|
+
const refValue = refFiles.length ? refFiles.map((f) => readFileSync27(join39(refs, f), "latin1")).join("|") : "";
|
|
19729
|
+
const look2 = { refs: refValue, config: readFileSync27(join39(dir, "config")).toString("latin1"), head: readFileSync27(join39(dir, "HEAD")).toString("latin1"), packs: packs.map((n) => `${n}:${lstatSync10(join39(packDir, n)).size}`).join(",") };
|
|
19662
19730
|
if (before) {
|
|
19663
19731
|
if (look2.config !== before.config) bad2.push("config (changed)");
|
|
19664
19732
|
if (look2.head !== before.head) bad2.push("HEAD (changed)");
|
|
@@ -19670,7 +19738,7 @@ function inspectMirror(dir, code, stage, before) {
|
|
|
19670
19738
|
function mirrorMoved(dir, look2) {
|
|
19671
19739
|
const read4 = (name2) => {
|
|
19672
19740
|
try {
|
|
19673
|
-
return readFileSync27(
|
|
19741
|
+
return readFileSync27(join39(dir, name2)).toString("latin1");
|
|
19674
19742
|
} catch {
|
|
19675
19743
|
return void 0;
|
|
19676
19744
|
}
|
|
@@ -19702,9 +19770,9 @@ var CarBook = class {
|
|
|
19702
19770
|
if (name2.includes(PAST)) return;
|
|
19703
19771
|
const dir = carsDir(this.d.stateDir, project), root = trainboardDir(this.d.stateDir);
|
|
19704
19772
|
try {
|
|
19705
|
-
writePrivate(
|
|
19773
|
+
writePrivate(join39(dir, name2), `${JSON.stringify(held2.file)}
|
|
19706
19774
|
`, root);
|
|
19707
|
-
if (held2.notice) writePrivate(
|
|
19775
|
+
if (held2.notice) writePrivate(join39(dir, noticeName(name2)), `${JSON.stringify(held2.notice)}
|
|
19708
19776
|
`, root);
|
|
19709
19777
|
} catch (error) {
|
|
19710
19778
|
this.d.log?.("cars-journal", { error: error.message.slice(0, 200) });
|
|
@@ -20226,11 +20294,11 @@ var CarBook = class {
|
|
|
20226
20294
|
const { project, url, base, key: code, state, remote } = o;
|
|
20227
20295
|
let work, mirror = "", hosts = "";
|
|
20228
20296
|
try {
|
|
20229
|
-
|
|
20230
|
-
work = mkdtempSync(
|
|
20231
|
-
mirror =
|
|
20232
|
-
|
|
20233
|
-
hosts =
|
|
20297
|
+
mkdirSync12(this.d.dir, { recursive: true, mode: 448 });
|
|
20298
|
+
work = mkdtempSync(join39(this.d.dir, "cars-mirror-"));
|
|
20299
|
+
mirror = join39(work, "repo");
|
|
20300
|
+
mkdirSync12(mirror, { mode: 448 });
|
|
20301
|
+
hosts = join39(work, "known_hosts");
|
|
20234
20302
|
writeFileSync7(hosts, this.d.knownHosts ?? "", { flag: "wx", mode: 384 });
|
|
20235
20303
|
} catch (error) {
|
|
20236
20304
|
this.dropMirror(work);
|
|
@@ -20496,7 +20564,7 @@ async function paneOf(o, paneId) {
|
|
|
20496
20564
|
}
|
|
20497
20565
|
function knownHostsOfUser() {
|
|
20498
20566
|
try {
|
|
20499
|
-
return readFileSync28(
|
|
20567
|
+
return readFileSync28(join40(homedir11(), ".ssh", "known_hosts"), "utf8").slice(0, 4e6);
|
|
20500
20568
|
} catch {
|
|
20501
20569
|
return "";
|
|
20502
20570
|
}
|
|
@@ -20527,16 +20595,16 @@ function startCars(o) {
|
|
|
20527
20595
|
}
|
|
20528
20596
|
|
|
20529
20597
|
// src/server/procsops.ts
|
|
20530
|
-
import { join as
|
|
20598
|
+
import { join as join43 } from "node:path";
|
|
20531
20599
|
import { homedir as homedir12 } from "node:os";
|
|
20532
20600
|
|
|
20533
20601
|
// src/server/procs.ts
|
|
20534
|
-
import { existsSync as existsSync6, mkdirSync as
|
|
20535
|
-
import { join as
|
|
20602
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync13, readdirSync as readdirSync12, readFileSync as readFileSync31, renameSync as renameSync7 } from "node:fs";
|
|
20603
|
+
import { join as join42 } from "node:path";
|
|
20536
20604
|
|
|
20537
20605
|
// src/procs/worktree.ts
|
|
20538
20606
|
import { readFileSync as readFileSync29, realpathSync as realpathSync9, statSync as statSync10 } from "node:fs";
|
|
20539
|
-
import { basename as basename11, dirname as
|
|
20607
|
+
import { basename as basename11, dirname as dirname14, join as join41, relative as relative4, isAbsolute as isAbsolute9, resolve as resolve7 } from "node:path";
|
|
20540
20608
|
var realDisk = {
|
|
20541
20609
|
kind: (path) => {
|
|
20542
20610
|
try {
|
|
@@ -20555,30 +20623,30 @@ var realDisk = {
|
|
|
20555
20623
|
};
|
|
20556
20624
|
function physical(path) {
|
|
20557
20625
|
const abs = resolve7(path), tail = [];
|
|
20558
|
-
for (let dir = abs; ; dir =
|
|
20626
|
+
for (let dir = abs; ; dir = dirname14(dir)) {
|
|
20559
20627
|
try {
|
|
20560
|
-
return
|
|
20628
|
+
return join41(realpathSync9.native(dir), ...tail.reverse());
|
|
20561
20629
|
} catch {
|
|
20562
|
-
if (
|
|
20630
|
+
if (dirname14(dir) === dir) return abs;
|
|
20563
20631
|
tail.push(basename11(dir));
|
|
20564
20632
|
}
|
|
20565
20633
|
}
|
|
20566
20634
|
}
|
|
20567
20635
|
function checkoutOf(cwd, disk = realDisk, real3 = physical) {
|
|
20568
|
-
for (let dir = real3(cwd); ; dir =
|
|
20569
|
-
const git =
|
|
20636
|
+
for (let dir = real3(cwd); ; dir = dirname14(dir)) {
|
|
20637
|
+
const git = join41(dir, ".git"), kind = disk.kind(git);
|
|
20570
20638
|
if (kind === "dir") return { kind: "main", root: dir };
|
|
20571
20639
|
if (kind === "file") {
|
|
20572
20640
|
const gitdir = /^gitdir:\s*(.+?)\s*$/m.exec(disk.read(git) ?? "")?.[1];
|
|
20573
20641
|
if (gitdir && /[\\/]worktrees[\\/][^\\/]+[\\/]?$/.test(gitdir)) {
|
|
20574
|
-
const admin = resolve7(dir, gitdir), back = disk.read(
|
|
20575
|
-
if (disk.kind(admin) === "dir" && back && real3(resolve7(admin, back)) ===
|
|
20642
|
+
const admin = resolve7(dir, gitdir), back = disk.read(join41(admin, "gitdir"))?.trim();
|
|
20643
|
+
if (disk.kind(admin) === "dir" && back && real3(resolve7(admin, back)) === join41(dir, ".git")) return { kind: "linked", root: dir, gitdir };
|
|
20576
20644
|
return { kind: "none" };
|
|
20577
20645
|
}
|
|
20578
20646
|
if (gitdir && /[\\/]modules[\\/]/.test(gitdir)) return { kind: "submodule", root: dir };
|
|
20579
20647
|
return { kind: "none" };
|
|
20580
20648
|
}
|
|
20581
|
-
if (
|
|
20649
|
+
if (dirname14(dir) === dir) return { kind: "none" };
|
|
20582
20650
|
}
|
|
20583
20651
|
}
|
|
20584
20652
|
function under(path, root) {
|
|
@@ -20667,11 +20735,11 @@ function killSet({ owner, live, table, places, markers, protect, reapers, self,
|
|
|
20667
20735
|
// src/procs/marker.ts
|
|
20668
20736
|
import { readFileSync as readFileSync30 } from "node:fs";
|
|
20669
20737
|
var OWNER_KEY = "STRAW_BOSS_OWNER";
|
|
20670
|
-
var
|
|
20738
|
+
var ID4 = /^[A-Za-z0-9._-]{1,64}$/;
|
|
20671
20739
|
var WORD2 = new RegExp(`(?:^|\\s)${OWNER_KEY}=([^\\s]*)(?=\\s|$)`, "g");
|
|
20672
20740
|
function ownerOf2(text14) {
|
|
20673
20741
|
const id2 = [...text14.matchAll(WORD2)].at(-1)?.[1];
|
|
20674
|
-
return id2 &&
|
|
20742
|
+
return id2 && ID4.test(id2) ? id2 : void 0;
|
|
20675
20743
|
}
|
|
20676
20744
|
function parseOwnerRows(text14, wanted) {
|
|
20677
20745
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -20715,14 +20783,14 @@ var OWNERS_FILE = "owners.json";
|
|
|
20715
20783
|
var TICK_MS2 = 1e4;
|
|
20716
20784
|
var SLOW_TICK_MS = 3e4;
|
|
20717
20785
|
var SLOW_AFTER_MS = 1e3;
|
|
20718
|
-
var
|
|
20786
|
+
var ID5 = /^[A-Za-z0-9._-]{1,64}$/;
|
|
20719
20787
|
var DEFER_MAX = 3;
|
|
20720
20788
|
var SHELLS3 = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "fish", "dash", "ksh", "csh", "tcsh"]);
|
|
20721
20789
|
var SNAPSHOT_MAX = 2e3;
|
|
20722
20790
|
var ProcsRefusal = class extends Error {
|
|
20723
20791
|
};
|
|
20724
20792
|
function createProcs(d) {
|
|
20725
|
-
const folder =
|
|
20793
|
+
const folder = join42(d.dir, "procs"), file3 = join42(folder, OWNERS_FILE);
|
|
20726
20794
|
const read4 = d.read ?? (() => readTable()), cwdsOf = d.cwds ?? ((pids) => readCwds(pids)), markersOf = d.markers ?? ((pids) => readOwners(pids));
|
|
20727
20795
|
const inode = d.inode ?? inodeOnDisk, checkout = d.checkout ?? checkoutOf, probe = d.startOf ?? startOf, reap2 = d.reap ?? ((refs) => reap(refs));
|
|
20728
20796
|
const platform = d.platform ?? process.platform, self = d.self ?? [process.pid], real3 = d.real ?? physical, exists = d.exists ?? existsSync6;
|
|
@@ -20734,7 +20802,7 @@ function createProcs(d) {
|
|
|
20734
20802
|
let tickEvery = TICK_MS2, ticking;
|
|
20735
20803
|
const save2 = () => {
|
|
20736
20804
|
try {
|
|
20737
|
-
|
|
20805
|
+
mkdirSync13(folder, { recursive: true, mode: 448 });
|
|
20738
20806
|
writeJson(file3, { v: 1, owners: [...owners.values()] });
|
|
20739
20807
|
} catch (error) {
|
|
20740
20808
|
d.log("procs-error", { text: `owners.json was not written (${error.code ?? error.name})` });
|
|
@@ -20745,7 +20813,7 @@ function createProcs(d) {
|
|
|
20745
20813
|
const parsed = JSON.parse(readFileSync31(file3, "utf8"));
|
|
20746
20814
|
for (const r of Array.isArray(parsed.owners) ? parsed.owners : []) {
|
|
20747
20815
|
const o = r;
|
|
20748
|
-
if (typeof o?.id === "string" &&
|
|
20816
|
+
if (typeof o?.id === "string" && ID5.test(o.id) && Number.isSafeInteger(o.pid) && typeof o.started === "string" && Array.isArray(o.roots) && Array.isArray(o.snapshot)) {
|
|
20749
20817
|
owners.set(o.id, { ...o, snapshot: o.snapshot.filter((s2) => Number.isSafeInteger(s2?.pid) && typeof s2?.started === "string") });
|
|
20750
20818
|
}
|
|
20751
20819
|
}
|
|
@@ -20929,7 +20997,7 @@ function createProcs(d) {
|
|
|
20929
20997
|
async hello(h) {
|
|
20930
20998
|
if (!Number.isSafeInteger(h.pid) || h.pid <= 1) throw new ProcsRefusal("procs-hello needs the pid of the pi");
|
|
20931
20999
|
const id2 = h.id ?? `p${h.pid}`;
|
|
20932
|
-
if (!
|
|
21000
|
+
if (!ID5.test(id2)) throw new ProcsRefusal("procs-hello: the owner id is 1 to 64 letters, digits, and . _ -");
|
|
20933
21001
|
const table = await read4();
|
|
20934
21002
|
const started = table ? table.find((p) => p.pid === h.pid && !p.zombie)?.started : probe(h.pid);
|
|
20935
21003
|
if (!started || h.started !== void 0 && h.started !== started) throw new ProcsRefusal("procs-hello: that pid is not a process of this account with that start time");
|
|
@@ -21037,9 +21105,9 @@ function createProcs(d) {
|
|
|
21037
21105
|
};
|
|
21038
21106
|
}
|
|
21039
21107
|
function serverPids(stateDir) {
|
|
21040
|
-
const files = [
|
|
21108
|
+
const files = [join42(stateDir, "server.json")];
|
|
21041
21109
|
try {
|
|
21042
|
-
for (const hash3 of readdirSync12(
|
|
21110
|
+
for (const hash3 of readdirSync12(join42(stateDir, "servers"))) files.push(join42(stateDir, "servers", hash3, "server.json"));
|
|
21043
21111
|
} catch {
|
|
21044
21112
|
}
|
|
21045
21113
|
const found = [];
|
|
@@ -21057,7 +21125,7 @@ async function protectedSet(table, { run: run3, stateDir, agentDir, self }) {
|
|
|
21057
21125
|
for (const p of table) if (baseName(p.comm) === "herdr") out.push({ pid: p.pid, started: p.started, why: "herdr" });
|
|
21058
21126
|
for (const server of serverPids(stateDir)) out.push({ ...server, why: "sb-server", tree: true });
|
|
21059
21127
|
try {
|
|
21060
|
-
const pid = Number(readFileSync31(
|
|
21128
|
+
const pid = Number(readFileSync31(join42(agentDir, "intercom", "broker.pid"), "utf8").trim());
|
|
21061
21129
|
if (Number.isSafeInteger(pid) && pid > 1) out.push({ pid, why: "intercom-broker", tree: true });
|
|
21062
21130
|
} catch {
|
|
21063
21131
|
}
|
|
@@ -21113,7 +21181,7 @@ function startProcs(o) {
|
|
|
21113
21181
|
self: [o.pid],
|
|
21114
21182
|
platform: o.platform,
|
|
21115
21183
|
...process.getuid ? { ownUid: process.getuid() } : {},
|
|
21116
|
-
protect: (table) => protectedSet(table, { run: o.run, stateDir: o.stateDir, agentDir: o.env.PI_CODING_AGENT_DIR ??
|
|
21184
|
+
protect: (table) => protectedSet(table, { run: o.run, stateDir: o.stateDir, agentDir: o.env.PI_CODING_AGENT_DIR ?? join43(homedir12(), ".pi", "agent"), self: o.pid }),
|
|
21117
21185
|
panes: async () => (await panes(o.run)).map((p) => ({ pane_id: p.pane_id, ...p.terminal_id ? { terminal_id: p.terminal_id } : {}, ...p.cwd ? { cwd: p.cwd } : {}, ...p.workspace_id ? { workspace_id: p.workspace_id } : {} })),
|
|
21118
21186
|
workspaces: async () => (await workspaces(o.run)).flatMap((w) => w.worktree?.is_linked_worktree && w.worktree.checkout_path ? [{ workspace_id: w.workspace_id, checkout_path: w.worktree.checkout_path }] : []),
|
|
21119
21187
|
...o.watch ? { watch: o.watch } : {},
|
|
@@ -21133,7 +21201,7 @@ function startProcs(o) {
|
|
|
21133
21201
|
}
|
|
21134
21202
|
|
|
21135
21203
|
// src/server/watchesops.ts
|
|
21136
|
-
import { join as
|
|
21204
|
+
import { join as join44 } from "node:path";
|
|
21137
21205
|
|
|
21138
21206
|
// src/server/watchread.ts
|
|
21139
21207
|
import { createHash as createHash17, randomBytes as randomBytes21 } from "node:crypto";
|
|
@@ -21617,7 +21685,7 @@ function startWatches(o) {
|
|
|
21617
21685
|
return () => clearTimeout(t);
|
|
21618
21686
|
});
|
|
21619
21687
|
const owner = (session) => ((f) => f ? { live: f.live, workspace: f.base } : void 0)(o.net.lookup(session));
|
|
21620
|
-
const watches = createWatches({ read: (q2) => read4.read(q2), now: o.now, timer, send: o.send, owner, file:
|
|
21688
|
+
const watches = createWatches({ read: (q2) => read4.read(q2), now: o.now, timer, send: o.send, owner, file: join44(slot.dir, "watches.json"), log: o.log });
|
|
21621
21689
|
watches.start();
|
|
21622
21690
|
o.stops.push(() => (watches.stopAll(), read4.stop()));
|
|
21623
21691
|
return { read: read4, watches };
|
|
@@ -21625,12 +21693,12 @@ function startWatches(o) {
|
|
|
21625
21693
|
|
|
21626
21694
|
// src/server/threadsops.ts
|
|
21627
21695
|
import { homedir as homedir13 } from "node:os";
|
|
21628
|
-
import { join as
|
|
21696
|
+
import { join as join46 } from "node:path";
|
|
21629
21697
|
|
|
21630
21698
|
// src/server/childtie.ts
|
|
21631
21699
|
import { readFileSync as readFileSync33, statSync as statSync11 } from "node:fs";
|
|
21632
|
-
import { basename as basename12, dirname as
|
|
21633
|
-
var
|
|
21700
|
+
import { basename as basename12, dirname as dirname15, sep as sep7 } from "node:path";
|
|
21701
|
+
var ID6 = /^[A-Za-z0-9_.:@-]{1,128}$/;
|
|
21634
21702
|
var safeName2 = (name2) => name2.toLowerCase().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
21635
21703
|
var isFile = (path) => {
|
|
21636
21704
|
try {
|
|
@@ -21641,7 +21709,7 @@ var isFile = (path) => {
|
|
|
21641
21709
|
};
|
|
21642
21710
|
function tieQuery(request) {
|
|
21643
21711
|
const path = (v) => typeof v === "string" && v.length > 0 && v.length <= 4096 ? v : void 0;
|
|
21644
|
-
const session = path(request.session), activityFile = path(request.activityFile), child = typeof request.child === "string" &&
|
|
21712
|
+
const session = path(request.session), activityFile = path(request.activityFile), child = typeof request.child === "string" && ID6.test(request.child) ? request.child : void 0;
|
|
21645
21713
|
return session && activityFile && child ? { session, child, activityFile } : void 0;
|
|
21646
21714
|
}
|
|
21647
21715
|
function childEnded(activityFile) {
|
|
@@ -21653,8 +21721,8 @@ function childEnded(activityFile) {
|
|
|
21653
21721
|
}
|
|
21654
21722
|
function tieChild(sessionsDir2, q2) {
|
|
21655
21723
|
const root = canonical2(sessionsDir2), under2 = (path) => path !== void 0 && path.startsWith(root + sep7);
|
|
21656
|
-
const activity = canonical2(q2.activityFile), session = canonical2(q2.session), activityDir = activity &&
|
|
21657
|
-
if (!under2(activity) || !under2(session) || !art || basename12(activity) !== `${q2.child}.json` || basename12(activityDir) !== "subagent-activity" || basename12(
|
|
21724
|
+
const activity = canonical2(q2.activityFile), session = canonical2(q2.session), activityDir = activity && dirname15(activity), art = activityDir && dirname15(activityDir);
|
|
21725
|
+
if (!under2(activity) || !under2(session) || !art || basename12(activity) !== `${q2.child}.json` || basename12(activityDir) !== "subagent-activity" || basename12(dirname15(art)) !== "artifacts" || !isFile(activity)) return { error: "outside the sessions folder" };
|
|
21658
21726
|
const tie = launchScripts(art).find((s2) => s2.id === q2.child && canonical2(s2.session) === session);
|
|
21659
21727
|
if (!tie) return { error: `no launch script ties ${q2.child} to that session` };
|
|
21660
21728
|
if (childEnded(activity)) return { error: "that child is done" };
|
|
@@ -21663,8 +21731,8 @@ function tieChild(sessionsDir2, q2) {
|
|
|
21663
21731
|
}
|
|
21664
21732
|
|
|
21665
21733
|
// src/server/threads.ts
|
|
21666
|
-
import { appendFileSync as
|
|
21667
|
-
import { join as
|
|
21734
|
+
import { appendFileSync as appendFileSync5, mkdirSync as mkdirSync14, readdirSync as readdirSync13, readFileSync as readFileSync34, renameSync as renameSync9, rmSync as rmSync11, writeFileSync as writeFileSync9 } from "node:fs";
|
|
21735
|
+
import { join as join45 } from "node:path";
|
|
21668
21736
|
var ROUNDS = 3;
|
|
21669
21737
|
var IDLE_MS2 = 2 * 36e5;
|
|
21670
21738
|
var TTL_MS = 24 * 36e5;
|
|
@@ -21678,7 +21746,7 @@ var READ_BYTES = 16 * 1024;
|
|
|
21678
21746
|
var MEMBERS = ["worker", "reviewer"];
|
|
21679
21747
|
var TAGS = ["review", "fix", "done", "blocked", "note"];
|
|
21680
21748
|
var no18 = (error) => ({ ok: false, error });
|
|
21681
|
-
var
|
|
21749
|
+
var ID7 = /^T[1-9][0-9]{0,5}$/;
|
|
21682
21750
|
var CONTROL7 = /[\p{Cc}\p{Cf}\u2028\u2029]/u;
|
|
21683
21751
|
var folderOf = (owner) => owner.slice(0, 8).replace(/[^A-Za-z0-9_-]/g, "_") || "_";
|
|
21684
21752
|
var span2 = (ms3) => `${Math.round(ms3 / 36e5)} hours`;
|
|
@@ -21691,15 +21759,15 @@ function createThreads(d) {
|
|
|
21691
21759
|
};
|
|
21692
21760
|
const fixes = (t) => t.posts.filter((p) => p.tag === "fix").length;
|
|
21693
21761
|
const lastAt = (t) => t.posts.at(-1)?.at ?? t.created;
|
|
21694
|
-
const summary = (t) => ({ thread: t.id, ref: key2(t.folder, t.id), worker: t.worker, reviewer: t.reviewer, rounds: t.rounds, fixes: fixes(t), posts: t.posts.length, created: t.created, ...closedOf(t) ? { closed: closedOf(t) } : { open: true } });
|
|
21695
|
-
const files = (t) => ({ meta:
|
|
21762
|
+
const summary = (t) => ({ thread: t.id, ref: key2(t.folder, t.id), worker: t.worker, reviewer: t.reviewer, rounds: t.rounds, fixes: fixes(t), posts: t.posts.length, created: t.created, ...t.item ? { item: t.item } : {}, ...closedOf(t) ? { closed: closedOf(t) } : { open: true } });
|
|
21763
|
+
const files = (t) => ({ meta: join45(d.dir, t.folder, `${t.id}.json`), posts: join45(d.dir, t.folder, `${t.id}.jsonl`) });
|
|
21696
21764
|
const saveMeta = (t) => {
|
|
21697
|
-
const { meta } = files(t), body2 = { id: t.id, owner: t.owner, worker: t.worker, reviewer: t.reviewer, rounds: t.rounds, created: t.created, seen: t.seen };
|
|
21698
|
-
|
|
21765
|
+
const { meta } = files(t), body2 = { id: t.id, owner: t.owner, worker: t.worker, reviewer: t.reviewer, rounds: t.rounds, created: t.created, seen: t.seen, ...t.item ? { item: t.item } : {}, ...t.closed !== void 0 ? { closed: t.closed, closedAs: t.closedAs } : {} };
|
|
21766
|
+
mkdirSync14(join45(d.dir, t.folder), { recursive: true, mode: 448 });
|
|
21699
21767
|
writeFileSync9(`${meta}.tmp`, JSON.stringify({ version: 1, ...body2 }), { mode: 384 });
|
|
21700
21768
|
renameSync9(`${meta}.tmp`, meta);
|
|
21701
21769
|
};
|
|
21702
|
-
const find2 = (owner, id2) =>
|
|
21770
|
+
const find2 = (owner, id2) => ID7.test(id2) ? all.get(key2(folderOf(owner), id2)) : void 0;
|
|
21703
21771
|
const ownOf = (t, owner) => t && t.owner === owner ? t : void 0;
|
|
21704
21772
|
const memberOf = (t, name2) => t.worker === name2 ? "worker" : t.reviewer === name2 ? "reviewer" : void 0;
|
|
21705
21773
|
const forMe = (t, as, since) => t.posts.filter((p) => p.n > since && p.from !== as && p.to.includes(as));
|
|
@@ -21716,16 +21784,26 @@ function createThreads(d) {
|
|
|
21716
21784
|
};
|
|
21717
21785
|
const append = (t, post) => {
|
|
21718
21786
|
const full = { n: t.posts.length + 1, at: d.now(), ...post };
|
|
21719
|
-
|
|
21720
|
-
|
|
21787
|
+
mkdirSync14(join45(d.dir, t.folder), { recursive: true, mode: 448 });
|
|
21788
|
+
appendFileSync5(files(t).posts, `${JSON.stringify(full)}
|
|
21721
21789
|
`, { mode: 384 });
|
|
21722
21790
|
t.posts.push(full);
|
|
21723
21791
|
return full;
|
|
21724
21792
|
};
|
|
21725
|
-
const
|
|
21793
|
+
const closing = (t, as) => {
|
|
21794
|
+
Object.assign(t, { closed: d.now(), closedAs: as });
|
|
21795
|
+
try {
|
|
21796
|
+
saveMeta(t);
|
|
21797
|
+
} catch (error) {
|
|
21798
|
+
d.log?.("thread-save-failed", { thread: t.id, error: error.message });
|
|
21799
|
+
}
|
|
21800
|
+
d.note?.({ kind: "thread_close", id: t.id, session: t.owner, why: as, ...t.item ? { item: t.item } : {} });
|
|
21801
|
+
};
|
|
21802
|
+
const close = (t, reason, as = "abandoned") => {
|
|
21726
21803
|
if (closedOf(t)) return;
|
|
21727
21804
|
append(t, { from: "sb", to: ["worker", "reviewer", "main"], tag: "blocked", text: reason });
|
|
21728
21805
|
d.log?.("thread-closed", { thread: t.id, owner: t.owner.slice(0, 8), by: "sb", reason });
|
|
21806
|
+
closing(t, as);
|
|
21729
21807
|
wake(t);
|
|
21730
21808
|
};
|
|
21731
21809
|
const see = (t, as, tie) => {
|
|
@@ -21738,7 +21816,7 @@ function createThreads(d) {
|
|
|
21738
21816
|
}
|
|
21739
21817
|
};
|
|
21740
21818
|
const tied = (tie, thread) => {
|
|
21741
|
-
if (typeof thread !== "string" || !
|
|
21819
|
+
if (typeof thread !== "string" || !ID7.test(thread)) return no18("thread is T<n>, as your task gives it");
|
|
21742
21820
|
const t = ownOf(find2(tie.parent, thread), tie.parent);
|
|
21743
21821
|
if (!t) return no18(`no thread ${thread} of the session that dispatched you`);
|
|
21744
21822
|
const as = memberOf(t, tie.name);
|
|
@@ -21756,14 +21834,14 @@ function createThreads(d) {
|
|
|
21756
21834
|
for (const folder of folders) {
|
|
21757
21835
|
let names = [];
|
|
21758
21836
|
try {
|
|
21759
|
-
names = readdirSync13(
|
|
21837
|
+
names = readdirSync13(join45(d.dir, folder)).filter((f) => /^T[0-9]+\.json$/.test(f));
|
|
21760
21838
|
} catch {
|
|
21761
21839
|
continue;
|
|
21762
21840
|
}
|
|
21763
21841
|
for (const name2 of names) {
|
|
21764
21842
|
try {
|
|
21765
|
-
const meta = JSON.parse(readFileSync34(
|
|
21766
|
-
if (!
|
|
21843
|
+
const meta = JSON.parse(readFileSync34(join45(d.dir, folder, name2), "utf8"));
|
|
21844
|
+
if (!ID7.test(meta.id) || typeof meta.owner !== "string" || folderOf(meta.owner) !== folder) continue;
|
|
21767
21845
|
let lines = [];
|
|
21768
21846
|
try {
|
|
21769
21847
|
lines = readFileSync34(files({ folder, id: meta.id }).posts, "utf8").split("\n");
|
|
@@ -21789,6 +21867,7 @@ function createThreads(d) {
|
|
|
21789
21867
|
pair(q2) {
|
|
21790
21868
|
const worker = safeName2(q2.worker), reviewer = safeName2(q2.reviewer), rounds = q2.rounds ?? ROUNDS;
|
|
21791
21869
|
if (!worker || !reviewer) return no18("worker and reviewer are the names you give subagent: letters, digits, spaces, or hyphens");
|
|
21870
|
+
if (q2.item !== void 0 && !ITEM.test(q2.item)) return no18("item is a todo uid (t_ and 10 letters or digits) or <session8>#<id>");
|
|
21792
21871
|
if (worker === reviewer) return no18(`worker and reviewer need two names (both read ${worker})`);
|
|
21793
21872
|
if (!Number.isInteger(rounds) || rounds < 1 || rounds > ROUNDS) return no18(`rounds is 1 to ${ROUNDS}`);
|
|
21794
21873
|
const folder = folderOf(q2.owner), mine = [...all.values()].filter((t2) => t2.owner === q2.owner && !closedOf(t2));
|
|
@@ -21796,7 +21875,7 @@ function createThreads(d) {
|
|
|
21796
21875
|
const taken = mine.find((t2) => memberOf(t2, worker) || memberOf(t2, reviewer));
|
|
21797
21876
|
if (taken) return no18(`${memberOf(taken, worker) ? worker : reviewer} is a member of open thread ${taken.id}: give each pair new names`);
|
|
21798
21877
|
const n = 1 + Math.max(0, ...[...all.values()].filter((t2) => t2.folder === folder).map((t2) => Number(t2.id.slice(1))));
|
|
21799
|
-
const t = { id: `T${n}`, owner: q2.owner, worker, reviewer, rounds, created: d.now(), seen: {}, folder, posts: [], waits: /* @__PURE__ */ new Set() };
|
|
21878
|
+
const t = { id: `T${n}`, owner: q2.owner, worker, reviewer, rounds, created: d.now(), seen: {}, ...q2.item ? { item: q2.item } : {}, folder, posts: [], waits: /* @__PURE__ */ new Set() };
|
|
21800
21879
|
try {
|
|
21801
21880
|
saveMeta(t);
|
|
21802
21881
|
} catch (error) {
|
|
@@ -21804,7 +21883,8 @@ function createThreads(d) {
|
|
|
21804
21883
|
}
|
|
21805
21884
|
all.set(key2(folder, t.id), t);
|
|
21806
21885
|
d.log?.("thread-paired", { thread: t.id, owner: q2.owner.slice(0, 8), rounds });
|
|
21807
|
-
|
|
21886
|
+
d.note?.({ kind: "thread_open", id: t.id, session: q2.owner, ...q2.item ? { item: q2.item } : {} });
|
|
21887
|
+
return { ok: true, thread: t.id, worker, reviewer, rounds, ...q2.item ? { item: q2.item } : {} };
|
|
21808
21888
|
},
|
|
21809
21889
|
/** A child's first run: the open thread of its dispatcher that names it, if any. */
|
|
21810
21890
|
member(tie) {
|
|
@@ -21831,11 +21911,11 @@ function createThreads(d) {
|
|
|
21831
21911
|
if (tag === "review" && as !== "worker") return no18("only the worker posts review; the reviewer answers with fix or done");
|
|
21832
21912
|
if (t.posts.length >= MAX_POSTS - 1 && tag !== "done" && tag !== "blocked") return no18(`${t.id} holds ${t.posts.length} posts: post done or blocked`);
|
|
21833
21913
|
if (tag === "fix" && fixes(t) >= t.rounds) {
|
|
21834
|
-
close(t, `${t.rounds} repair round${t.rounds > 1 ? "s" : ""} used
|
|
21914
|
+
close(t, `${t.rounds} repair round${t.rounds > 1 ? "s" : ""} used`, "blocked");
|
|
21835
21915
|
return no18(`${t.id} allows ${t.rounds} repair round${t.rounds > 1 ? "s" : ""} and all are used: the fix is refused, and the thread is closed blocked. Write your final report with the open findings and end`);
|
|
21836
21916
|
}
|
|
21837
21917
|
const post = append(t, { from: as, to, tag, text: q2.text, ...refs?.length ? { refs } : {} });
|
|
21838
|
-
if (tag === "done" || tag === "blocked") d.log?.("thread-closed", { thread: t.id, owner: t.owner.slice(0, 8), by: as, tag });
|
|
21918
|
+
if (tag === "done" || tag === "blocked") d.log?.("thread-closed", { thread: t.id, owner: t.owner.slice(0, 8), by: as, tag }), closing(t, tag);
|
|
21839
21919
|
wake(t);
|
|
21840
21920
|
const after2 = closedOf(t);
|
|
21841
21921
|
return { ok: true, thread: t.id, n: post.n, ...after2 ? { closed: after2 } : {}, ...tag === "fix" ? { round: fixes(t), rounds: t.rounds } : {} };
|
|
@@ -21933,10 +22013,11 @@ function threadReply(threads, request, sessionsDir2) {
|
|
|
21933
22013
|
const thread = text10(request.thread, 40);
|
|
21934
22014
|
return thread ? Promise.resolve(threads.read(owner, thread)) : no19("thread is T<n> or <owner8>/T<n>");
|
|
21935
22015
|
}
|
|
21936
|
-
const worker = text10(request.worker, 200), reviewer = text10(request.reviewer, 200), rounds = request.rounds;
|
|
22016
|
+
const worker = text10(request.worker, 200), reviewer = text10(request.reviewer, 200), rounds = request.rounds, item = request.item;
|
|
21937
22017
|
if (!worker || !reviewer) return no19("thread-pair needs worker and reviewer");
|
|
21938
22018
|
if (rounds !== void 0 && typeof rounds !== "number") return no19("rounds is 1 to 3");
|
|
21939
|
-
|
|
22019
|
+
if (item !== void 0 && typeof item !== "string") return no19("item is a todo uid or <session8>#<id>");
|
|
22020
|
+
return Promise.resolve(threads.pair({ owner, worker, reviewer, ...rounds !== void 0 ? { rounds } : {}, ...item !== void 0 ? { item } : {} }));
|
|
21940
22021
|
}
|
|
21941
22022
|
const q2 = tieQuery(request);
|
|
21942
22023
|
if (!q2) return no19(`${request.cmd} needs session, child, and activityFile`);
|
|
@@ -21952,17 +22033,18 @@ function startThreads(o) {
|
|
|
21952
22033
|
t.unref?.();
|
|
21953
22034
|
return () => clearTimeout(t);
|
|
21954
22035
|
});
|
|
21955
|
-
|
|
22036
|
+
ledgerSink.warn = (text14) => o.log("ledger-unwritable", { text: text14 });
|
|
22037
|
+
const threads = createThreads({ dir: join46(o.slot.dir, "threads"), now: o.now, timer, ended: childEnded, log: o.log, note: (e) => noteLedger(o.slot.stateDir, e, o.now()), ...o.over?.holdMs !== void 0 ? { holdMs: o.over.holdMs } : {} });
|
|
21956
22038
|
o.stops.push(threads.start());
|
|
21957
|
-
return { threads, sessionsDir:
|
|
22039
|
+
return { threads, sessionsDir: join46(o.env.PI_CODING_AGENT_DIR ?? join46(homedir13(), ".pi", "agent"), "sessions") };
|
|
21958
22040
|
}
|
|
21959
22041
|
|
|
21960
22042
|
// src/server/stallops.ts
|
|
21961
22043
|
import { statSync as statSync12 } from "node:fs";
|
|
21962
22044
|
|
|
21963
22045
|
// src/server/stallwatch.ts
|
|
21964
|
-
import { mkdirSync as
|
|
21965
|
-
import { basename as basename13, join as
|
|
22046
|
+
import { mkdirSync as mkdirSync15, readFileSync as readFileSync35 } from "node:fs";
|
|
22047
|
+
import { basename as basename13, join as join47 } from "node:path";
|
|
21966
22048
|
var STALL_FILE = "stallwatch.json";
|
|
21967
22049
|
var SAMPLE_MS = 6e4;
|
|
21968
22050
|
var PAUSE_MS = 18e4;
|
|
@@ -21976,7 +22058,7 @@ var STALL_DEFAULTS = { enabled: true, cpuPercent: 75, cpuMinutes: 5, silentMinut
|
|
|
21976
22058
|
function readStallWatch(stateDir) {
|
|
21977
22059
|
let section;
|
|
21978
22060
|
try {
|
|
21979
|
-
section = JSON.parse(readFileSync35(
|
|
22061
|
+
section = JSON.parse(readFileSync35(join47(stateDir, "config.json"), "utf8")).stallWatch;
|
|
21980
22062
|
} catch {
|
|
21981
22063
|
}
|
|
21982
22064
|
const found = typeof section === "object" && section !== null ? section : {};
|
|
@@ -22026,7 +22108,7 @@ var paneKey = (p) => `${p.pane}
|
|
|
22026
22108
|
${p.terminal ?? ""}`;
|
|
22027
22109
|
var text11 = (v, max) => typeof v === "string" && v.length > 0 && v.length <= max ? v : void 0;
|
|
22028
22110
|
function createStallWatch(d) {
|
|
22029
|
-
const folder =
|
|
22111
|
+
const folder = join47(d.dir, "procs"), file3 = join47(folder, STALL_FILE), self = d.self ?? [process.pid];
|
|
22030
22112
|
const watched = /* @__PURE__ */ new Map();
|
|
22031
22113
|
const unresolved = /* @__PURE__ */ new Map();
|
|
22032
22114
|
let lastAt, on2 = false, busy = false, saved = "", loaded = false, samples = 0, askedLast;
|
|
@@ -22035,7 +22117,7 @@ function createStallWatch(d) {
|
|
|
22035
22117
|
const next2 = kept();
|
|
22036
22118
|
if (next2 === saved) return;
|
|
22037
22119
|
try {
|
|
22038
|
-
|
|
22120
|
+
mkdirSync15(folder, { recursive: true, mode: 448 });
|
|
22039
22121
|
writeJson(file3, JSON.parse(next2));
|
|
22040
22122
|
saved = next2;
|
|
22041
22123
|
} catch (error) {
|
|
@@ -22238,7 +22320,7 @@ function startStall(o) {
|
|
|
22238
22320
|
// src/server/capops.ts
|
|
22239
22321
|
import { readFileSync as readFileSync39, statSync as statSync13 } from "node:fs";
|
|
22240
22322
|
import { availableParallelism as availableParallelism2, homedir as homedir15, loadavg as loadavg2 } from "node:os";
|
|
22241
|
-
import { join as
|
|
22323
|
+
import { join as join52 } from "node:path";
|
|
22242
22324
|
|
|
22243
22325
|
// src/server/capwatch.ts
|
|
22244
22326
|
var MIN2 = 6e4;
|
|
@@ -22360,12 +22442,12 @@ import { homedir as homedir14 } from "node:os";
|
|
|
22360
22442
|
|
|
22361
22443
|
// src/server/workeropen.ts
|
|
22362
22444
|
import { existsSync as existsSync8, readFileSync as readFileSync36 } from "node:fs";
|
|
22363
|
-
import { basename as basename14, dirname as
|
|
22445
|
+
import { basename as basename14, dirname as dirname16, join as join49, resolve as resolve8 } from "node:path";
|
|
22364
22446
|
|
|
22365
22447
|
// src/opener.ts
|
|
22366
22448
|
import { createHash as createHash19, randomUUID as randomUUID12 } from "node:crypto";
|
|
22367
22449
|
import { existsSync as existsSync7 } from "node:fs";
|
|
22368
|
-
import { join as
|
|
22450
|
+
import { join as join48 } from "node:path";
|
|
22369
22451
|
|
|
22370
22452
|
// src/reviver.ts
|
|
22371
22453
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
@@ -22588,7 +22670,7 @@ function opener(env) {
|
|
|
22588
22670
|
const everywhere = await panes(run3);
|
|
22589
22671
|
const codes = new Set(everywhere.flatMap((p) => ((t) => t && t.project === train.project ? [t.code] : [])(trainFromToken(p.tokens?.sb_train))));
|
|
22590
22672
|
if (codes.has(train.code)) throw new OpenLimitError(`The ${trainLabel(train.code)} of project ${train.project} is already open; a code is used once`);
|
|
22591
|
-
if (env.stateDir && existsSync7(
|
|
22673
|
+
if (env.stateDir && existsSync7(join48(trainboardDir(env.stateDir), train.project, train.code))) throw new OpenLimitError(`The ${trainLabel(train.code)} of project ${train.project} was already used (its trainboard is kept); a code is used once, so the next train takes a new code`);
|
|
22592
22674
|
const max = (env.maxTrains ?? readMaxTrains)(dir);
|
|
22593
22675
|
if (typeof max !== "number") throw new OpenLimitError(max.refusal);
|
|
22594
22676
|
const config = (env.appsRefusal ?? openRefusal)(dir, appFromRequest(request));
|
|
@@ -22683,7 +22765,7 @@ var FETCH_MS = 9e4;
|
|
|
22683
22765
|
function readWorkers(stateDir) {
|
|
22684
22766
|
let w;
|
|
22685
22767
|
try {
|
|
22686
|
-
w = JSON.parse(readFileSync36(
|
|
22768
|
+
w = JSON.parse(readFileSync36(join49(stateDir, "config.json"), "utf8")).workers;
|
|
22687
22769
|
} catch {
|
|
22688
22770
|
return void 0;
|
|
22689
22771
|
}
|
|
@@ -22708,7 +22790,7 @@ async function prepareWorktree(o) {
|
|
|
22708
22790
|
};
|
|
22709
22791
|
await git(["check-ref-format", "--branch", branch], o.checkout).catch(refuse3);
|
|
22710
22792
|
const common = resolve8(o.checkout, await git(["rev-parse", "--git-common-dir"], o.checkout).catch(refuse3));
|
|
22711
|
-
const repo = basename14(common) === ".git" ? basename14(
|
|
22793
|
+
const repo = basename14(common) === ".git" ? basename14(dirname16(common)) : basename14(common).replace(/\.git$/, "");
|
|
22712
22794
|
await git(["fetch", "--quiet", "--no-tags", "origin"], o.checkout, FETCH_MS).catch(refuse3);
|
|
22713
22795
|
const sha2 = (ref) => git(["rev-parse", "--verify", "--quiet", `${ref}^{commit}`], o.checkout).catch(() => "");
|
|
22714
22796
|
const remote = await sha2(`refs/remotes/origin/${branch}`), local = await sha2(`refs/heads/${branch}`);
|
|
@@ -22726,7 +22808,7 @@ async function prepareWorktree(o) {
|
|
|
22726
22808
|
if (!baseSha) throw new OpenLimitError(`base origin/${name2} does not exist`);
|
|
22727
22809
|
base = `origin/${name2}`;
|
|
22728
22810
|
}
|
|
22729
|
-
const dir =
|
|
22811
|
+
const dir = join49(o.home, ".herdr", "worktrees", repo, branch.replace(/\//g, "-"));
|
|
22730
22812
|
if (existsSync8(dir)) throw new OpenLimitError(`the worktree ${dir} exists already: one worker per branch`);
|
|
22731
22813
|
const made = !local;
|
|
22732
22814
|
await git(made ? ["worktree", "add", "--no-track", "-b", branch, "--", dir, baseSha] : ["worktree", "add", "--", dir, branch], o.checkout).catch(refuse3);
|
|
@@ -22746,7 +22828,7 @@ async function closeWorktree(o) {
|
|
|
22746
22828
|
await git(["fetch", "--quiet", "--no-tags", "origin"], o.dir, FETCH_MS).catch(() => void 0);
|
|
22747
22829
|
const pushed = await ok(git(["merge-base", "--is-ancestor", head, `refs/remotes/origin/${o.branch}`], o.dir));
|
|
22748
22830
|
if (!pushed && head !== o.baseSha) return { removed: false, reason: `HEAD ${head.slice(0, 12)} is not on origin/${o.branch}`, head };
|
|
22749
|
-
const common = resolve8(o.dir, await git(["rev-parse", "--git-common-dir"], o.dir).catch(() => ".git")), checkout = o.checkout ?? (basename14(common) === ".git" ?
|
|
22831
|
+
const common = resolve8(o.dir, await git(["rev-parse", "--git-common-dir"], o.dir).catch(() => ".git")), checkout = o.checkout ?? (basename14(common) === ".git" ? dirname16(common) : common);
|
|
22750
22832
|
await git(["worktree", "remove", "--", o.dir], checkout).catch(() => void 0);
|
|
22751
22833
|
if (existsSync8(o.dir)) return { removed: false, reason: "git worktree remove failed", head };
|
|
22752
22834
|
if (await git(["rev-parse", "--verify", "--quiet", `refs/heads/${o.branch}`], checkout).catch(() => "") === head) await git(["branch", "-D", "--", o.branch], checkout).catch(() => void 0);
|
|
@@ -22838,19 +22920,19 @@ function createWorkerEnds(d) {
|
|
|
22838
22920
|
|
|
22839
22921
|
// src/server/workerally.ts
|
|
22840
22922
|
import { readFileSync as readFileSync38 } from "node:fs";
|
|
22841
|
-
import { join as
|
|
22923
|
+
import { join as join51 } from "node:path";
|
|
22842
22924
|
|
|
22843
22925
|
// src/capres.ts
|
|
22844
22926
|
import { randomBytes as randomBytes22 } from "node:crypto";
|
|
22845
|
-
import { mkdirSync as
|
|
22846
|
-
import { join as
|
|
22927
|
+
import { mkdirSync as mkdirSync16, readdirSync as readdirSync14, readFileSync as readFileSync37, renameSync as renameSync10, rmSync as rmSync12, writeFileSync as writeFileSync10 } from "node:fs";
|
|
22928
|
+
import { join as join50 } from "node:path";
|
|
22847
22929
|
var RES_EXPIRE_MS = 10 * 6e4;
|
|
22848
22930
|
var FOLDER = "_reserved";
|
|
22849
|
-
var
|
|
22931
|
+
var ID8 = /^[0-9a-z-]{8,64}$/;
|
|
22850
22932
|
function createReservations(dir, now) {
|
|
22851
|
-
const folder =
|
|
22933
|
+
const folder = join50(dir, FOLDER), file3 = (id2) => join50(folder, `${id2}.json`);
|
|
22852
22934
|
const write2 = (r) => {
|
|
22853
|
-
|
|
22935
|
+
mkdirSync16(folder, { recursive: true, mode: 448 });
|
|
22854
22936
|
const temp = `${file3(r.id)}.${process.pid}.tmp`;
|
|
22855
22937
|
try {
|
|
22856
22938
|
writeFileSync10(temp, `${JSON.stringify(r)}
|
|
@@ -22884,8 +22966,8 @@ function createReservations(dir, now) {
|
|
|
22884
22966
|
}
|
|
22885
22967
|
const t = now();
|
|
22886
22968
|
return names.flatMap((name2) => {
|
|
22887
|
-
const id2 = name2.slice(0, -".json".length), r =
|
|
22888
|
-
if (!r || t - r.at > RES_EXPIRE_MS) return rmSync12(
|
|
22969
|
+
const id2 = name2.slice(0, -".json".length), r = ID8.test(id2) ? read4(id2) : void 0;
|
|
22970
|
+
if (!r || t - r.at > RES_EXPIRE_MS) return rmSync12(join50(folder, name2), { force: true }), [];
|
|
22889
22971
|
if (r.launched && rowAt > r.at && shows2(r)) {
|
|
22890
22972
|
if (r.seen === void 0 || rowAt < r.seen) try {
|
|
22891
22973
|
write2({ ...r, seen: rowAt });
|
|
@@ -22943,7 +23025,7 @@ var OPENED_FILE = "workers-opened.json";
|
|
|
22943
23025
|
var OPENED_KEEP_MS2 = 7 * 24 * 36e5;
|
|
22944
23026
|
var readOpened = (stateDir, now) => {
|
|
22945
23027
|
try {
|
|
22946
|
-
const e = JSON.parse(readFileSync38(
|
|
23028
|
+
const e = JSON.parse(readFileSync38(join51(stateDir, OPENED_FILE), "utf8")).entries;
|
|
22947
23029
|
return (Array.isArray(e) ? e : []).filter((x) => typeof x?.ask === "string" && typeof x.main === "string" && typeof x.at === "number" && now - x.at <= OPENED_KEEP_MS2);
|
|
22948
23030
|
} catch {
|
|
22949
23031
|
return [];
|
|
@@ -22961,7 +23043,7 @@ function openWorker(d, peer, request) {
|
|
|
22961
23043
|
const { spec, ask } = request.slip;
|
|
22962
23044
|
return turnOf(d.stateDir, async () => {
|
|
22963
23045
|
let reservation, made, checkout = "", opened;
|
|
22964
|
-
const store2 = createReservations(capDir(
|
|
23046
|
+
const store2 = createReservations(capDir(join51(d.stateDir, "board")), d.now);
|
|
22965
23047
|
const prior = ask ? readOpened(d.stateDir, d.now()).find((x) => x.ask === ask) : void 0;
|
|
22966
23048
|
if (prior) throw new WorkerRepeat(`A worker was already opened for this slip (session ${prior.main}); its report answers the device's ask, so nothing was opened or sent again`);
|
|
22967
23049
|
try {
|
|
@@ -22974,12 +23056,12 @@ function openWorker(d, peer, request) {
|
|
|
22974
23056
|
if (full) throw new OpenLimitError(full);
|
|
22975
23057
|
checkout = await d.checkout();
|
|
22976
23058
|
if (d.within !== void 0 && !d.inside(checkout, d.within)) throw new OpenLimitError("this workspace's checkout is outside the project the team binds on this computer");
|
|
22977
|
-
const got = admitPoints({ room: () => readDevice(capDir(
|
|
23059
|
+
const got = admitPoints({ room: () => readDevice(capDir(join51(d.stateDir, "board")), d.now()), store: store2 }, budget, spec.points, { session: "", worker: "", self: true });
|
|
22978
23060
|
if ("refusal" in got) throw new OpenLimitError(`${got.refusal}: this worker needs ${spec.points}`);
|
|
22979
23061
|
reservation = got.id;
|
|
22980
23062
|
made = await prepareWorktree({ checkout, spec, home: d.home, ...d.reserved ? { reserved: d.reserved(checkout) } : {}, ...d.git ? { git: d.git } : {} });
|
|
22981
23063
|
opened = await d.open({ ...request, role: "worker", worker: { dir: made.dir, branch: made.branch, base: made.base, points: spec.points, label: spec.label, ...spec.model ? { model: spec.model } : {}, ...made.rework ? { rework: true } : {} } });
|
|
22982
|
-
if (ask) writeDurable(
|
|
23064
|
+
if (ask) writeDurable(join51(d.stateDir, OPENED_FILE), { entries: [...readOpened(d.stateDir, d.now()), { ask, main: opened.main, at: d.now() }].slice(-200) });
|
|
22983
23065
|
d.route(opened, { points: spec.points, branch: made.branch, path: made.dir, base: made.base, baseSha: made.baseSha, label: spec.label }, ask);
|
|
22984
23066
|
try {
|
|
22985
23067
|
store2.claim(reservation, opened.main);
|
|
@@ -23051,7 +23133,7 @@ function workerEndsOf(o) {
|
|
|
23051
23133
|
function armedLoop(dir, session, now) {
|
|
23052
23134
|
if (!safeSession(session)) return false;
|
|
23053
23135
|
try {
|
|
23054
|
-
const { loops } = JSON.parse(readFileSync39(
|
|
23136
|
+
const { loops } = JSON.parse(readFileSync39(join52(dir, `loops-${session}.json`), "utf8"));
|
|
23055
23137
|
return Array.isArray(loops) && loops.some((l) => l?.status === "active" && typeof l.expiresAt === "number" && l.expiresAt > now);
|
|
23056
23138
|
} catch {
|
|
23057
23139
|
return false;
|
|
@@ -23089,7 +23171,7 @@ async function tellCap(e, o, at) {
|
|
|
23089
23171
|
}
|
|
23090
23172
|
function startCap(o) {
|
|
23091
23173
|
if (inTestRun() && !o.over) return void 0;
|
|
23092
|
-
const boardDir =
|
|
23174
|
+
const boardDir = join52(o.stateDir, "board");
|
|
23093
23175
|
const watch2 = createCapWatch({
|
|
23094
23176
|
dir: capDir(boardDir),
|
|
23095
23177
|
now: o.now,
|
|
@@ -23112,7 +23194,7 @@ function startCap(o) {
|
|
|
23112
23194
|
return void 0;
|
|
23113
23195
|
}
|
|
23114
23196
|
},
|
|
23115
|
-
(id2, pane) => pane !== void 0 && monitors.has(pane) || o.watching(id2) || armedLoop(
|
|
23197
|
+
(id2, pane) => pane !== void 0 && monitors.has(pane) || o.watching(id2) || armedLoop(join52(homedir15(), ".pi", "loops"), id2, now),
|
|
23116
23198
|
o.workerPoints?.()
|
|
23117
23199
|
);
|
|
23118
23200
|
},
|
|
@@ -23132,7 +23214,7 @@ function startCap(o) {
|
|
|
23132
23214
|
}
|
|
23133
23215
|
|
|
23134
23216
|
// src/server/watchops.ts
|
|
23135
|
-
import { join as
|
|
23217
|
+
import { join as join56 } from "node:path";
|
|
23136
23218
|
|
|
23137
23219
|
// src/server/autowatch.ts
|
|
23138
23220
|
var WATCH_MS = 15 * 6e4;
|
|
@@ -23469,14 +23551,14 @@ ${why}`, d.log("watch-skipped", { why });
|
|
|
23469
23551
|
|
|
23470
23552
|
// src/server/headasks.ts
|
|
23471
23553
|
import { readFileSync as readFileSync40 } from "node:fs";
|
|
23472
|
-
import { join as
|
|
23554
|
+
import { join as join53 } from "node:path";
|
|
23473
23555
|
var ASK_OPEN_MS = 24 * 36e5;
|
|
23474
23556
|
var ASK_CAP = 40;
|
|
23475
23557
|
var ASK_KEEP = 100;
|
|
23476
23558
|
var FIRST2 = 120;
|
|
23477
23559
|
var TEXT_KEEP = 1500;
|
|
23478
23560
|
var GROUP_MS = 6e4;
|
|
23479
|
-
var fileOf3 = (slot) =>
|
|
23561
|
+
var fileOf3 = (slot) => join53(towerDir(slot, HEAD_KEY), "asks.json");
|
|
23480
23562
|
var cut4 = (text14) => {
|
|
23481
23563
|
const t = (text14 ?? "").trim();
|
|
23482
23564
|
return t ? Array.from(t).slice(0, TEXT_KEEP).join("") : void 0;
|
|
@@ -23591,15 +23673,15 @@ import { closeSync as closeSync7, openSync as openSync7, readSync, statSync as s
|
|
|
23591
23673
|
// src/server/headchapters.ts
|
|
23592
23674
|
import { open as open7 } from "node:fs/promises";
|
|
23593
23675
|
import { readFileSync as readFileSync42 } from "node:fs";
|
|
23594
|
-
import { join as
|
|
23676
|
+
import { join as join55 } from "node:path";
|
|
23595
23677
|
|
|
23596
23678
|
// src/server/bossconv.ts
|
|
23597
23679
|
import { lstatSync as lstatSync11, readFileSync as readFileSync41, realpathSync as realpathSync10, rmSync as rmSync13 } from "node:fs";
|
|
23598
23680
|
import { homedir as homedir16 } from "node:os";
|
|
23599
|
-
import { isAbsolute as isAbsolute10, join as
|
|
23681
|
+
import { isAbsolute as isAbsolute10, join as join54, relative as relative5, resolve as resolve9, sep as sep8 } from "node:path";
|
|
23600
23682
|
var BOSS_FILE_MAX = 4 * 1024 * 1024;
|
|
23601
23683
|
var BOSS_FILE_DAYS = 7;
|
|
23602
|
-
var pointerFile = (slot, workspace) =>
|
|
23684
|
+
var pointerFile = (slot, workspace) => join54(towerDir(slot, workspace), "boss-session.json");
|
|
23603
23685
|
function readPointer(slot, workspace) {
|
|
23604
23686
|
try {
|
|
23605
23687
|
const p = JSON.parse(readFileSync41(pointerFile(slot, workspace), "utf8"));
|
|
@@ -23612,7 +23694,7 @@ function writePointer(slot, workspace, pointer) {
|
|
|
23612
23694
|
ensureDir(towerDir(slot, workspace));
|
|
23613
23695
|
writeDurable(pointerFile(slot, workspace), pointer);
|
|
23614
23696
|
}
|
|
23615
|
-
var sessionsRoot = (env = process.env) =>
|
|
23697
|
+
var sessionsRoot = (env = process.env) => join54(env.PI_CODING_AGENT_DIR || join54(homedir16(), ".pi", "agent"), "sessions");
|
|
23616
23698
|
var real2 = (path) => {
|
|
23617
23699
|
try {
|
|
23618
23700
|
return realpathSync10(path);
|
|
@@ -23633,7 +23715,7 @@ function linkIn(file3, root) {
|
|
|
23633
23715
|
if (rel.startsWith("..") || isAbsolute10(rel)) continue;
|
|
23634
23716
|
let at = base;
|
|
23635
23717
|
for (const part3 of rel.split(sep8)) {
|
|
23636
|
-
at =
|
|
23718
|
+
at = join54(at, part3);
|
|
23637
23719
|
try {
|
|
23638
23720
|
if (lstatSync11(at).isSymbolicLink()) return true;
|
|
23639
23721
|
} catch {
|
|
@@ -23671,7 +23753,7 @@ var KEEP2 = 50;
|
|
|
23671
23753
|
var RECAP_LINES = 8;
|
|
23672
23754
|
var RECAP_CHARS = 2e3;
|
|
23673
23755
|
var TAIL_BYTES = 262144;
|
|
23674
|
-
var chaptersFile = (slot) =>
|
|
23756
|
+
var chaptersFile = (slot) => join55(towerDir(slot, HEAD_KEY), "chapters.json");
|
|
23675
23757
|
function readChapters(slot) {
|
|
23676
23758
|
try {
|
|
23677
23759
|
const list2 = JSON.parse(readFileSync42(chaptersFile(slot), "utf8"));
|
|
@@ -23933,8 +24015,8 @@ function towerPanel(towers, run3) {
|
|
|
23933
24015
|
return { label: (await directLine(t, run3, to, text14, door)).label };
|
|
23934
24016
|
}),
|
|
23935
24017
|
conversation: (workspace, what) => asked3((t) => what === "leave" ? t.runs.leave(at(t, workspace)) : t.runs.fresh(at(t, workspace))),
|
|
23936
|
-
// The GUI's route is the one door that is the page; the control socket's `tower-memory` says which of pi's, the prompt's, or a run pane's it is (main.ts).
|
|
23937
|
-
memory: (workspace, json3) => towers().memory(workspace, json3, "gui"),
|
|
24018
|
+
// The GUI's route is the one door that is the page (a paired device's, `phone`; a box controller's, `box`: control.ts); the control socket's `tower-memory` says which of pi's, the prompt's, or a run pane's it is (main.ts).
|
|
24019
|
+
memory: (workspace, json3, door) => towers().memory(workspace, json3, door ?? "gui"),
|
|
23938
24020
|
act: (workspace, what, id2) => asked3((t) => ((ws) => (what === "retry" ? t.runs.retry(ws) : what === "deliver" ? t.runs.deliverAgain(ws, id2) : t.runs.dropParked(ws, id2), {}))(at(t, workspace)))
|
|
23939
24021
|
};
|
|
23940
24022
|
}
|
|
@@ -23972,7 +24054,7 @@ function startAutoWatch(o) {
|
|
|
23972
24054
|
run: o.run,
|
|
23973
24055
|
...o.world ? { world: o.world } : {},
|
|
23974
24056
|
sessions: o.sessions,
|
|
23975
|
-
board: boardSeam({ dir:
|
|
24057
|
+
board: boardSeam({ dir: join56(o.slot.stateDir, "board"), now: o.now }),
|
|
23976
24058
|
trainyard: trainyardSeam({ env: o.env, stateDir: o.slot.stateDir, now: o.now, ...o.book ? { book: o.book } : {} })
|
|
23977
24059
|
});
|
|
23978
24060
|
let stopped = false;
|
|
@@ -24090,8 +24172,8 @@ function runNotice(s2) {
|
|
|
24090
24172
|
|
|
24091
24173
|
// src/server/towers.ts
|
|
24092
24174
|
import { createHash as createHash23 } from "node:crypto";
|
|
24093
|
-
import { mkdirSync as
|
|
24094
|
-
import { join as
|
|
24175
|
+
import { mkdirSync as mkdirSync20, readdirSync as readdirSync16, readFileSync as readFileSync46, rmSync as rmSync15 } from "node:fs";
|
|
24176
|
+
import { join as join63 } from "node:path";
|
|
24095
24177
|
|
|
24096
24178
|
// src/closemain.ts
|
|
24097
24179
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
@@ -24397,9 +24479,9 @@ var clearOrder = (run3, paneIds) => Promise.all(paneIds.map((id2) => report(run3
|
|
|
24397
24479
|
})));
|
|
24398
24480
|
|
|
24399
24481
|
// src/server/head.ts
|
|
24400
|
-
import { chmodSync as chmodSync6, mkdirSync as
|
|
24482
|
+
import { chmodSync as chmodSync6, mkdirSync as mkdirSync17 } from "node:fs";
|
|
24401
24483
|
import { homedir as homedir17 } from "node:os";
|
|
24402
|
-
import { join as
|
|
24484
|
+
import { join as join57 } from "node:path";
|
|
24403
24485
|
var HEAD_REFUSAL = "The head tower takes only the boss's words and answers to its own asks.";
|
|
24404
24486
|
var HEAD_TOKEN = "sb_head";
|
|
24405
24487
|
var HEAD_ORDER = "000.0";
|
|
@@ -24408,10 +24490,10 @@ function refuseHead(client, from, message, log, now) {
|
|
|
24408
24490
|
client.sendMessageReceipt?.({ messageId: message.id, status: "expired", timestamp: now(), detail: HEAD_REFUSAL });
|
|
24409
24491
|
}
|
|
24410
24492
|
var headLabel = (env, stateDir) => localeOf(env, stateDir) === "zh-TW" ? "\u4E3B\u5854\u53F0" : "Head tower";
|
|
24411
|
-
var headFolder = (env) =>
|
|
24493
|
+
var headFolder = (env) => join57(env.PI_CODING_AGENT_DIR || join57(homedir17(), ".pi", "agent"), "straw-boss-head");
|
|
24412
24494
|
async function makeHead(d) {
|
|
24413
24495
|
const cwd = headFolder(d.env), label = headLabel(d.env, d.slot?.stateDir);
|
|
24414
|
-
|
|
24496
|
+
mkdirSync17(cwd, { recursive: true, mode: 448 });
|
|
24415
24497
|
chmodSync6(cwd, 448);
|
|
24416
24498
|
const made = await result(d.run, ["workspace", "create", "--cwd", cwd, "--label", label, "--no-focus"]);
|
|
24417
24499
|
const workspace = made.workspace.workspace_id, tab = made.tab.tab_id, pane = made.root_pane.pane_id;
|
|
@@ -24466,7 +24548,7 @@ function createHead(d) {
|
|
|
24466
24548
|
}
|
|
24467
24549
|
|
|
24468
24550
|
// src/server/headside.ts
|
|
24469
|
-
import { join as
|
|
24551
|
+
import { join as join58 } from "node:path";
|
|
24470
24552
|
|
|
24471
24553
|
// src/server/headbrief.ts
|
|
24472
24554
|
var CAPS2 = { workspaces: 2400, asks: 1200, row: 200, note: 1200, recap: 2e3 };
|
|
@@ -24594,7 +24676,7 @@ async function headBrief(d, input) {
|
|
|
24594
24676
|
const ws = d.record().workspace, all = await workspaces(d.run), at = new Date(input.woken);
|
|
24595
24677
|
const rows = [];
|
|
24596
24678
|
for (const w of all.filter((x) => !isSub(x) && !isHead(x)).slice(0, 20)) {
|
|
24597
|
-
const { rows: mains } = await gatherMains({ run: d.run, now: d.now, sessions: d.sessions, boardDir:
|
|
24679
|
+
const { rows: mains } = await gatherMains({ run: d.run, now: d.now, sessions: d.sessions, boardDir: join58(d.slot.stateDir, "board"), workspace: w, ledger: [] }).catch(() => ({ rows: [] }));
|
|
24598
24680
|
rows.push({ label: phrase5(w.label, 60), id: w.workspace_id, ...w.worktree?.checkout_path ? { folder: w.worktree.checkout_path } : {}, tower: d.towerState(w.workspace_id, w.tokens), rows: mains });
|
|
24599
24681
|
}
|
|
24600
24682
|
const kept = readMemory(d.slot, ws, d.now()), section = memorySection(kept.memory, d.now(), kept.problem), note = lastNote(d.slot, ws, "local");
|
|
@@ -24731,8 +24813,8 @@ function reportText(r) {
|
|
|
24731
24813
|
|
|
24732
24814
|
// src/server/automode.ts
|
|
24733
24815
|
import { randomBytes as randomBytes23 } from "node:crypto";
|
|
24734
|
-
import { mkdirSync as
|
|
24735
|
-
import { join as
|
|
24816
|
+
import { mkdirSync as mkdirSync18, readFileSync as readFileSync43, renameSync as renameSync11, writeFileSync as writeFileSync11 } from "node:fs";
|
|
24817
|
+
import { join as join59 } from "node:path";
|
|
24736
24818
|
var PENDING_MS2 = 10 * 6e4;
|
|
24737
24819
|
var USED_MAX = 500;
|
|
24738
24820
|
var STALE = "This request expired or was replaced: ask again";
|
|
@@ -24748,7 +24830,7 @@ var gistOf = (v) => {
|
|
|
24748
24830
|
};
|
|
24749
24831
|
function readReportFile(dir) {
|
|
24750
24832
|
try {
|
|
24751
|
-
const j = JSON.parse(readFileSync43(
|
|
24833
|
+
const j = JSON.parse(readFileSync43(join59(dir, REPORT_FILE), "utf8"));
|
|
24752
24834
|
return j.v === 1 && typeof j.since === "string" && Array.isArray(j.parked) && Array.isArray(j.lines) ? j : void 0;
|
|
24753
24835
|
} catch {
|
|
24754
24836
|
return void 0;
|
|
@@ -24763,7 +24845,7 @@ function createAutoMode(d) {
|
|
|
24763
24845
|
const listeners = /* @__PURE__ */ new Set();
|
|
24764
24846
|
const readPeriod = () => {
|
|
24765
24847
|
try {
|
|
24766
|
-
const j = JSON.parse(readFileSync43(
|
|
24848
|
+
const j = JSON.parse(readFileSync43(join59(d.dir, PERIOD_FILE), "utf8"));
|
|
24767
24849
|
return typeof j.since === "string" && Array.isArray(j.notes) ? { since: j.since, notes: j.notes.slice(-NOTES_MAX), foreign: Array.isArray(j.foreign) ? j.foreign : [], decided: Array.isArray(j.decided) ? j.decided : [], .../* @__PURE__ */ ((w) => w ? { watch: w } : {})(watchOf(j.watch)) } : void 0;
|
|
24768
24850
|
} catch {
|
|
24769
24851
|
return void 0;
|
|
@@ -24774,8 +24856,8 @@ function createAutoMode(d) {
|
|
|
24774
24856
|
if (period) write2(PERIOD_FILE, period);
|
|
24775
24857
|
};
|
|
24776
24858
|
const write2 = (name2, value) => {
|
|
24777
|
-
const file3 =
|
|
24778
|
-
|
|
24859
|
+
const file3 = join59(d.dir, name2), tmp = `${file3}.${process.pid}.tmp`;
|
|
24860
|
+
mkdirSync18(d.dir, { recursive: true });
|
|
24779
24861
|
writeFileSync11(tmp, `${JSON.stringify(value)}
|
|
24780
24862
|
`, { mode: 384 });
|
|
24781
24863
|
renameSync11(tmp, file3);
|
|
@@ -24992,6 +25074,7 @@ function deliveryOf(status) {
|
|
|
24992
25074
|
if (status === "sent" || status === "delivered") return "delivered";
|
|
24993
25075
|
return status === "queued" ? "queued" : "failed";
|
|
24994
25076
|
}
|
|
25077
|
+
var byOf2 = (via) => via === "gui" || via === "phone" || via === "box" ? via : "terminal";
|
|
24995
25078
|
var doorOf = (via) => via === "prompt" || via === "run-pane" || via === "ask" ? via : "pi";
|
|
24996
25079
|
var askRefused = (request, unattended) => (request.cmd === "boss-waits" && request.ask === true || request.cmd === "tower-memory" && request.via === "ask") && unattended() ? UNATTENDED : void 0;
|
|
24997
25080
|
var cardNotice = (plan2) => plan2.act === "done" || plan2.act === "choose" ? `${plan2.notice} ${ACT_ON_IT}` : plan2.notice;
|
|
@@ -25121,7 +25204,7 @@ async function pressRequest(d, workspace, json3, via = "pi") {
|
|
|
25121
25204
|
let plan2;
|
|
25122
25205
|
const now = d.now();
|
|
25123
25206
|
try {
|
|
25124
|
-
plan2 = updateMemory(d.slot, workspace, now, (m) => pressWait(m, now, json3, d.locale)).value;
|
|
25207
|
+
plan2 = updateMemory(d.slot, workspace, now, (m) => pressWait(m, now, json3, d.locale), void 0, byOf2(via)).value;
|
|
25125
25208
|
} catch (cause) {
|
|
25126
25209
|
return failure(cause);
|
|
25127
25210
|
}
|
|
@@ -25852,8 +25935,8 @@ function runApprover(o) {
|
|
|
25852
25935
|
// src/server/runchild.ts
|
|
25853
25936
|
import { execFile as execFile2, spawn as nodeSpawn } from "node:child_process";
|
|
25854
25937
|
import { randomBytes as randomBytes25 } from "node:crypto";
|
|
25855
|
-
import { appendFileSync as
|
|
25856
|
-
import { delimiter, dirname as
|
|
25938
|
+
import { appendFileSync as appendFileSync6, mkdirSync as mkdirSync19, readFileSync as readFileSync44, readdirSync as readdirSync15, realpathSync as realpathSync11, rmSync as rmSync14, statSync as statSync16 } from "node:fs";
|
|
25939
|
+
import { delimiter, dirname as dirname17, join as join60, win32 as win323 } from "node:path";
|
|
25857
25940
|
var STDIN_ALLOWED = ["abort", "extension_ui_response", "get_state"];
|
|
25858
25941
|
var STDERR_CAP = 256 * 1024;
|
|
25859
25942
|
var STDERR_KEEP = 20;
|
|
@@ -25872,7 +25955,7 @@ function which(name2, path, platform, ext = ".COM;.EXE;.BAT;.CMD") {
|
|
|
25872
25955
|
const ends = platform === "win32" ? ["", ...ext.split(";").map((e) => e.toLowerCase())] : [""];
|
|
25873
25956
|
for (const dir of path.split(platform === "win32" ? ";" : delimiter).filter(Boolean)) {
|
|
25874
25957
|
for (const end of ends) {
|
|
25875
|
-
const file3 =
|
|
25958
|
+
const file3 = join60(dir, name2 + end);
|
|
25876
25959
|
try {
|
|
25877
25960
|
if (statSync16(file3).isFile()) return file3;
|
|
25878
25961
|
} catch {
|
|
@@ -25938,13 +26021,13 @@ function pruneStderr(dir, now) {
|
|
|
25938
26021
|
}
|
|
25939
26022
|
const rows = names.flatMap((n) => {
|
|
25940
26023
|
try {
|
|
25941
|
-
return [{ n, at: statSync16(
|
|
26024
|
+
return [{ n, at: statSync16(join60(dir, n)).mtimeMs }];
|
|
25942
26025
|
} catch {
|
|
25943
26026
|
return [];
|
|
25944
26027
|
}
|
|
25945
26028
|
}).sort((a, b) => b.at - a.at);
|
|
25946
26029
|
rows.forEach((r, i) => {
|
|
25947
|
-
if (i >= STDERR_KEEP || now - r.at > STDERR_KEEP_MS) rmSync14(
|
|
26030
|
+
if (i >= STDERR_KEEP || now - r.at > STDERR_KEEP_MS) rmSync14(join60(dir, r.n), { force: true });
|
|
25948
26031
|
});
|
|
25949
26032
|
}
|
|
25950
26033
|
function startChild(o) {
|
|
@@ -25973,7 +26056,7 @@ function startChild(o) {
|
|
|
25973
26056
|
child.stdout?.on("end", () => split.end());
|
|
25974
26057
|
if (o.stderr) {
|
|
25975
26058
|
try {
|
|
25976
|
-
|
|
26059
|
+
mkdirSync19(dirname17(o.stderr), { recursive: true });
|
|
25977
26060
|
} catch {
|
|
25978
26061
|
}
|
|
25979
26062
|
child.stderr?.on("data", (c) => {
|
|
@@ -25981,7 +26064,7 @@ function startChild(o) {
|
|
|
25981
26064
|
const piece = c.subarray(0, STDERR_CAP - written);
|
|
25982
26065
|
written += piece.length;
|
|
25983
26066
|
try {
|
|
25984
|
-
|
|
26067
|
+
appendFileSync6(o.stderr, piece);
|
|
25985
26068
|
} catch {
|
|
25986
26069
|
}
|
|
25987
26070
|
});
|
|
@@ -26019,7 +26102,7 @@ function startChild(o) {
|
|
|
26019
26102
|
}
|
|
26020
26103
|
};
|
|
26021
26104
|
}
|
|
26022
|
-
var stderrFile = (towerDir2, run3) =>
|
|
26105
|
+
var stderrFile = (towerDir2, run3) => join60(towerDir2, "runs", `${run3.slice(0, 8)}.stderr`);
|
|
26023
26106
|
|
|
26024
26107
|
// src/server/runring.ts
|
|
26025
26108
|
var RING_MAX = 300;
|
|
@@ -26368,7 +26451,7 @@ function createRevoker(d) {
|
|
|
26368
26451
|
}
|
|
26369
26452
|
|
|
26370
26453
|
// src/server/deadwatch.ts
|
|
26371
|
-
import { join as
|
|
26454
|
+
import { join as join61 } from "node:path";
|
|
26372
26455
|
function createDeadWatch(d) {
|
|
26373
26456
|
const seen = /* @__PURE__ */ new Map();
|
|
26374
26457
|
const last = /* @__PURE__ */ new Map();
|
|
@@ -26418,7 +26501,7 @@ function createDeadWatch(d) {
|
|
|
26418
26501
|
busy = false;
|
|
26419
26502
|
}
|
|
26420
26503
|
}
|
|
26421
|
-
return { sweep: sweep3, rows: (workspace) => last.get(workspace) ?? [], ledgerDir:
|
|
26504
|
+
return { sweep: sweep3, rows: (workspace) => last.get(workspace) ?? [], ledgerDir: join61(d.stateDir, "revive") };
|
|
26422
26505
|
}
|
|
26423
26506
|
|
|
26424
26507
|
// src/server/runs.ts
|
|
@@ -28078,8 +28161,8 @@ function allyReceipts(d) {
|
|
|
28078
28161
|
|
|
28079
28162
|
// src/server/towerseen.ts
|
|
28080
28163
|
import { createHash as createHash22 } from "node:crypto";
|
|
28081
|
-
import { appendFileSync as
|
|
28082
|
-
import { join as
|
|
28164
|
+
import { appendFileSync as appendFileSync7, readFileSync as readFileSync45 } from "node:fs";
|
|
28165
|
+
import { join as join62 } from "node:path";
|
|
28083
28166
|
var SEEN_KEEP_MS = 48 * 36e5;
|
|
28084
28167
|
var SEEN_MAX = 5e3;
|
|
28085
28168
|
var SLACK = 500;
|
|
@@ -28097,7 +28180,7 @@ var parse5 = (line4) => {
|
|
|
28097
28180
|
}
|
|
28098
28181
|
};
|
|
28099
28182
|
function openSeen(slot, workspace, now) {
|
|
28100
|
-
const file3 =
|
|
28183
|
+
const file3 = join62(towerDir(slot, workspace), FILE);
|
|
28101
28184
|
const rows = /* @__PURE__ */ new Map();
|
|
28102
28185
|
let text14 = "", lines = 0;
|
|
28103
28186
|
try {
|
|
@@ -28146,7 +28229,7 @@ function openSeen(slot, workspace, now) {
|
|
|
28146
28229
|
if (lines >= SEEN_MAX + SLACK) return rewrite2();
|
|
28147
28230
|
lines++;
|
|
28148
28231
|
ensureDir(towerDir(slot, workspace));
|
|
28149
|
-
|
|
28232
|
+
appendFileSync7(file3, `${JSON.stringify(row2)}
|
|
28150
28233
|
`, { mode: 384 });
|
|
28151
28234
|
},
|
|
28152
28235
|
size: () => rows.size
|
|
@@ -28284,7 +28367,7 @@ function createTowers(o) {
|
|
|
28284
28367
|
const ws = l.record.workspace, all = await workspaces(run3), target2 = all.find((w) => w.workspace_id === ws);
|
|
28285
28368
|
if (!target2 || !l.client) throw new Error("the tower's workspace or its intercom connection is gone");
|
|
28286
28369
|
const first2 = items[0], device = rec.device ?? "";
|
|
28287
|
-
const mains2 = await gatherMains({ run: run3, now, sessions: () => l.client.listSessions(), boardDir:
|
|
28370
|
+
const mains2 = await gatherMains({ run: run3, now, sessions: () => l.client.listSessions(), boardDir: join63(slot.stateDir, "board"), workspace: target2, ledger: [], within: { project: rec.team ? o.ally?.project(rec.team) : void 0 } });
|
|
28288
28371
|
const note = lastNote(slot, ws, "ally", device), at = new Date(woken);
|
|
28289
28372
|
const line4 = (text14) => text14.split("\n").find((x) => x.trim()) ?? "";
|
|
28290
28373
|
return {
|
|
@@ -28306,7 +28389,7 @@ function createTowers(o) {
|
|
|
28306
28389
|
const ws = l.record.workspace, all = await workspaces(run3), target2 = all.find((w) => w.workspace_id === ws);
|
|
28307
28390
|
if (!target2 || !l.client) throw new Error("the tower's workspace or its intercom connection is gone");
|
|
28308
28391
|
if (isHeadL(l)) return headBrief({ slot, run: run3, now, auto: autoLine, record: () => l.record, sessions: () => l.client.listSessions(), towerState, locale: localeOf(o.env, slot.stateDir) }, { woken, run: rec, ...split ? { split } : {} });
|
|
28309
|
-
const mains2 = await gatherMains({ run: run3, now, sessions: () => l.client.listSessions(), boardDir:
|
|
28392
|
+
const mains2 = await gatherMains({ run: run3, now, sessions: () => l.client.listSessions(), boardDir: join63(slot.stateDir, "board"), workspace: target2, ledger: readLedger(slot, ws, now()) });
|
|
28310
28393
|
const lines = await digest.peek(ws).catch(() => []), note = lastNote(slot, ws, "local"), timer = readTimer(slot, ws);
|
|
28311
28394
|
const counts = {};
|
|
28312
28395
|
for (const e of events2) counts[e.kind] = (counts[e.kind] ?? 0) + 1;
|
|
@@ -28396,7 +28479,7 @@ function createTowers(o) {
|
|
|
28396
28479
|
const headless = () => readTowerRuns(slot.stateDir).headless;
|
|
28397
28480
|
const tabless = (l) => l.record.pane === "";
|
|
28398
28481
|
const place = (l) => ({ paneId: l.record.pane, tabId: l.record.tab, workspaceId: l.record.workspace });
|
|
28399
|
-
const dirOf2 = (workspace) =>
|
|
28482
|
+
const dirOf2 = (workspace) => join63(towerDir(slot, workspace));
|
|
28400
28483
|
const error = (code, text14) => log.line("error", { code, text: phrase9(text14, 300) });
|
|
28401
28484
|
const markAnswered2 = async (l, session) => {
|
|
28402
28485
|
try {
|
|
@@ -28495,7 +28578,7 @@ function createTowers(o) {
|
|
|
28495
28578
|
l.kit.attach(client);
|
|
28496
28579
|
l.client = client;
|
|
28497
28580
|
wire(l, client);
|
|
28498
|
-
|
|
28581
|
+
mkdirSync20(dirOf2(l.record.workspace), { recursive: true, mode: 448 });
|
|
28499
28582
|
await client.connect(registration(l), l.record.id);
|
|
28500
28583
|
log.line("tower-registered", { workspace: l.record.workspace, id: l.record.id, pane: l.record.pane });
|
|
28501
28584
|
return true;
|
|
@@ -28792,7 +28875,7 @@ function createTowers(o) {
|
|
|
28792
28875
|
return l;
|
|
28793
28876
|
};
|
|
28794
28877
|
const convertRoles = async () => {
|
|
28795
|
-
const dir =
|
|
28878
|
+
const dir = join63(slot.stateDir, "roles");
|
|
28796
28879
|
let names = [];
|
|
28797
28880
|
try {
|
|
28798
28881
|
names = readdirSync16(dir).filter((name2) => name2.endsWith(".json"));
|
|
@@ -28803,7 +28886,7 @@ function createTowers(o) {
|
|
|
28803
28886
|
for (const name2 of names) {
|
|
28804
28887
|
let record2;
|
|
28805
28888
|
try {
|
|
28806
|
-
record2 = JSON.parse(readFileSync46(
|
|
28889
|
+
record2 = JSON.parse(readFileSync46(join63(dir, name2), "utf8"));
|
|
28807
28890
|
} catch {
|
|
28808
28891
|
continue;
|
|
28809
28892
|
}
|
|
@@ -28819,12 +28902,12 @@ function createTowers(o) {
|
|
|
28819
28902
|
writeService(slot, made);
|
|
28820
28903
|
log.line("tower-converted", { workspace: made.workspace, pane: made.pane });
|
|
28821
28904
|
}
|
|
28822
|
-
rmSync15(
|
|
28905
|
+
rmSync15(join63(dir, name2), { force: true });
|
|
28823
28906
|
}
|
|
28824
28907
|
};
|
|
28825
28908
|
const begin = async () => {
|
|
28826
28909
|
recoverUntil = now() + (o.recoverMs ?? RECOVER_MS);
|
|
28827
|
-
secretDir(
|
|
28910
|
+
secretDir(join63(slot.dir, "tower"));
|
|
28828
28911
|
try {
|
|
28829
28912
|
await convertRoles();
|
|
28830
28913
|
} catch (cause) {
|
|
@@ -29159,7 +29242,7 @@ function createTowers(o) {
|
|
|
29159
29242
|
} : l.open,
|
|
29160
29243
|
closeMain: l.control ? async (query) => forgetClosed(ws, await l.control.closeMain(query)) : void 0,
|
|
29161
29244
|
now,
|
|
29162
|
-
boardDir:
|
|
29245
|
+
boardDir: join63(slot.stateDir, "board"),
|
|
29163
29246
|
label: l.record.label,
|
|
29164
29247
|
...l.control && !peer ? { closePane: (pane) => l.control.closePane(pane), deadPanes: () => l.control.deadPanes() } : {},
|
|
29165
29248
|
stateDir: slot.stateDir,
|
|
@@ -29816,7 +29899,7 @@ async function runServer(o) {
|
|
|
29816
29899
|
let reporter;
|
|
29817
29900
|
let operateBox;
|
|
29818
29901
|
let operateHost;
|
|
29819
|
-
const operateSwitch = operateOff(
|
|
29902
|
+
const operateSwitch = operateOff(join64(slot.stateDir, "link", "operate-off.json"), now);
|
|
29820
29903
|
const makeOperateHost = () => operateHost = createOperateHost({
|
|
29821
29904
|
now,
|
|
29822
29905
|
device: () => link?.holder?.deviceId,
|
|
@@ -30146,7 +30229,7 @@ async function runServer(o) {
|
|
|
30146
30229
|
// The work board's Clear tells a live writer once (boardpanel.ts): one intercom message from the server, under a `board_clear` header.
|
|
30147
30230
|
tell: tellVia(() => client, serverId(slot)),
|
|
30148
30231
|
// The primary server holds the link itself (B3), so the GUI asks the holder in this process as the server, which the holder takes GUI requests from; before it runs, the channel reaches the holder's session. A secondary server holds none and its GUI says so (`no_link`, as its `link` request does): the channel would ask the primary's holder as a session that is not the GUI's host.
|
|
30149
|
-
link: gui.link ?? (!slot.primary ? elsewhereLink() : inProcessLink(createGuiLink({ events: kit.pi.events, id: () => serverId(slot), stateDir: slot.stateDir, agentDir: env.PI_CODING_AGENT_DIR ??
|
|
30232
|
+
link: gui.link ?? (!slot.primary ? elsewhereLink() : inProcessLink(createGuiLink({ events: kit.pi.events, id: () => serverId(slot), stateDir: slot.stateDir, agentDir: env.PI_CODING_AGENT_DIR ?? join64(homedir18(), ".pi", "agent"), log: (text14) => log.line("link", { text: text14 }) }), () => link, () => serverId(slot))),
|
|
30150
30233
|
status: () => ({ state: phase === "ready" ? "live" : phase, version, pid, mode, desk, uptimeMs: now() - startedAt, log: fileOf(slot, "log"), ...own.lastError ? { lastError: own.lastError } : {} }),
|
|
30151
30234
|
restart: gui.restart ?? ((reason) => spawnRestart(cliBeside(), reason, "the GUI", serverEnv(env), slot.dir, void 0, true)),
|
|
30152
30235
|
failed: (code, text14) => recordError(code, text14),
|
|
@@ -30357,7 +30440,7 @@ ${unit}`), note = ws ? readNotes(slot, ws).at(-1) : void 0, sent = ws ? link?.ho
|
|
|
30357
30440
|
towers: () => towers,
|
|
30358
30441
|
now,
|
|
30359
30442
|
home: o.link?.home ?? homedir18(),
|
|
30360
|
-
agentDir: env.PI_CODING_AGENT_DIR ??
|
|
30443
|
+
agentDir: env.PI_CODING_AGENT_DIR ?? join64(o.link?.home ?? homedir18(), ".pi", "agent"),
|
|
30361
30444
|
failed: (from, project, error) => void unitsOut().notify(`tower-open/${from}/${project}/${Math.floor(now() / 6e5)}`, { kind: "tower-open-failed", unit: allyLabel(project), text: `Could not open a tower for ${project}: ${error.message}` }, { device: from })
|
|
30362
30445
|
})
|
|
30363
30446
|
}
|