pi-straw-boss 0.75.0 → 0.75.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,7 @@ import {
17
17
  LAN_PORT,
18
18
  MARK,
19
19
  MAX_SB_BYTES,
20
+ MAX_TICKET_CHARS,
20
21
  POWERSHELL_FLAGS,
21
22
  PROGRESS_OFF,
22
23
  PROTOCOL,
@@ -207,7 +208,7 @@ import {
207
208
  writeStartError,
208
209
  writerAlive,
209
210
  yardPath
210
- } from "./chunk-4OLRDO5C.mjs";
211
+ } from "./chunk-PQZBUOCK.mjs";
211
212
 
212
213
  // src/server/main.ts
213
214
  import { homedir as homedir14 } from "node:os";
@@ -2527,7 +2528,7 @@ function createAsks(slot, now = Date.now) {
2527
2528
 
2528
2529
  // src/server/guihost.ts
2529
2530
  import { spawn as spawn2 } from "node:child_process";
2530
- import { readFileSync as readFileSync16 } from "node:fs";
2531
+ import { readFileSync as readFileSync17 } from "node:fs";
2531
2532
  import { join as join29 } from "node:path";
2532
2533
 
2533
2534
  // src/music.ts
@@ -2599,7 +2600,7 @@ import { fileURLToPath } from "node:url";
2599
2600
 
2600
2601
  // src/stash.ts
2601
2602
  import { randomUUID as randomUUID4 } from "node:crypto";
2602
- import { existsSync as existsSync3, linkSync, mkdirSync as mkdirSync5, readdirSync as readdirSync4, readFileSync as readFileSync7, renameSync as renameSync4, rmSync as rmSync4, statSync as statSync5, writeFileSync as writeFileSync4 } from "node:fs";
2603
+ import { existsSync as existsSync4, linkSync, mkdirSync as mkdirSync5, readdirSync as readdirSync5, readFileSync as readFileSync8, renameSync as renameSync4, rmSync as rmSync4, statSync as statSync5, writeFileSync as writeFileSync4 } from "node:fs";
2603
2604
  import { dirname as dirname4, join as join13 } from "node:path";
2604
2605
 
2605
2606
  // src/trust/settings.ts
@@ -2609,12 +2610,20 @@ import { join as join11 } from "node:path";
2609
2610
 
2610
2611
  // src/trust/found.ts
2611
2612
  import { createHash as createHash4 } from "node:crypto";
2613
+ import { closeSync as closeSync3, constants as constants2, existsSync as existsSync3, fstatSync, lstatSync as lstatSync2, openSync as openSync3, readdirSync as readdirSync3, readFileSync as readFileSync6, realpathSync as realpathSync3 } from "node:fs";
2612
2614
  var MAX_ITEMS = 20;
2613
2615
  var MAX_ITEM = 120;
2614
2616
  var MAX_FOUND = 32768;
2615
2617
  var MAX_READ = 262144;
2616
2618
  var clean3 = (text10) => text10.replace(/[\u0000-\u001f\u007f-\u009f]/g, "").replace(new RegExp("\\p{Cf}", "gu"), "\uFFFD");
2617
2619
  var cleanGroup = (g) => ({ ...g, kind: clean3(g.kind), path: clean3(g.path), items: g.items.map(clean3) });
2620
+ var canonical = (path) => {
2621
+ try {
2622
+ return realpathSync3(path);
2623
+ } catch {
2624
+ return path;
2625
+ }
2626
+ };
2618
2627
  var digestOf = (cwd, found) => createHash4("sha256").update(JSON.stringify(["pi-trust/1", cwd, found])).digest("hex");
2619
2628
 
2620
2629
  // src/trust/settings.ts
@@ -2736,7 +2745,7 @@ async function assertSettingsSafe(dirs, what, run3) {
2736
2745
  }
2737
2746
 
2738
2747
  // src/trust/files.ts
2739
- import { chmodSync as chmodSync4, lstatSync as lstatSync2, realpathSync as realpathSync3, mkdirSync as mkdirSync4, readdirSync as readdirSync3, readFileSync as readFileSync6, renameSync as renameSync3, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
2748
+ import { chmodSync as chmodSync4, lstatSync as lstatSync3, realpathSync as realpathSync4, mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
2740
2749
  import { homedir as homedir5 } from "node:os";
2741
2750
  import { join as join12, relative as relative2, isAbsolute as isAbsolute3 } from "node:path";
2742
2751
 
@@ -2765,10 +2774,10 @@ function ensureDir2(dir, ids = process.getuid !== void 0, home = homedir5()) {
2765
2774
  try {
2766
2775
  mkdirSync4(join12(dir, ".."), { recursive: true, mode: 448 });
2767
2776
  mkdirSync4(dir, { recursive: true, mode: 448 });
2768
- const st = lstatSync2(dir);
2777
+ const st = lstatSync3(dir);
2769
2778
  if (!st.isDirectory() || st.isSymbolicLink() || ids && st.uid !== uid()) return false;
2770
2779
  if (!ids) {
2771
- const inside2 = relative2(realpathSync3.native(home), realpathSync3.native(dir));
2780
+ const inside2 = relative2(realpathSync4.native(home), realpathSync4.native(dir));
2772
2781
  if (inside2.startsWith("..") || isAbsolute3(inside2)) return false;
2773
2782
  }
2774
2783
  if (process.platform !== "win32" && (st.mode & 63) !== 0) chmodSync4(dir, 448);
@@ -2797,9 +2806,9 @@ function writeAtomic(dir, name2, value) {
2797
2806
  }
2798
2807
  function readJson2(file2, max = MAX_FILE) {
2799
2808
  try {
2800
- const st = lstatSync2(file2);
2809
+ const st = lstatSync3(file2);
2801
2810
  if (!st.isFile() || st.size > max || uid() !== void 0 && st.uid !== uid()) return void 0;
2802
- return { value: JSON.parse(readFileSync6(file2, "utf8")), mtime: st.mtimeMs };
2811
+ return { value: JSON.parse(readFileSync7(file2, "utf8")), mtime: st.mtimeMs };
2803
2812
  } catch {
2804
2813
  return void 0;
2805
2814
  }
@@ -2829,7 +2838,7 @@ var remove = (dir, ...names) => names.forEach((n) => rmSync3(join12(dir, n), { f
2829
2838
  function listRequests(dir, alive2 = lives) {
2830
2839
  let names;
2831
2840
  try {
2832
- names = readdirSync3(dir);
2841
+ names = readdirSync4(dir);
2833
2842
  } catch {
2834
2843
  return [];
2835
2844
  }
@@ -2845,7 +2854,7 @@ function listRequests(dir, alive2 = lives) {
2845
2854
  function sweep(dir, now = Date.now(), alive2 = lives) {
2846
2855
  let names;
2847
2856
  try {
2848
- names = readdirSync3(dir);
2857
+ names = readdirSync4(dir);
2849
2858
  } catch {
2850
2859
  return;
2851
2860
  }
@@ -2867,7 +2876,7 @@ function sweep(dir, now = Date.now(), alive2 = lives) {
2867
2876
  }
2868
2877
  var lstatMtime = (file2) => {
2869
2878
  try {
2870
- return lstatSync2(file2).mtimeMs;
2879
+ return lstatSync3(file2).mtimeMs;
2871
2880
  } catch {
2872
2881
  return void 0;
2873
2882
  }
@@ -2904,7 +2913,7 @@ var dirOf = (stateDir) => join13(stateDir, "stash");
2904
2913
  var stashFile = (stateDir, name2) => join13(dirOf(stateDir), `${name2}.json`);
2905
2914
  function nameFor(label, stateDir) {
2906
2915
  const base = label.replace(/[/\\\p{Cc}]/gu, "-").trim().replace(/^\.+/, "").slice(0, MAX_NAME - 4).trim() || "base";
2907
- for (let n = 1; ; n++) if (!existsSync3(stashFile(stateDir, n > 1 ? `${base} ${n}` : base))) return n > 1 ? `${base} ${n}` : base;
2916
+ for (let n = 1; ; n++) if (!existsSync4(stashFile(stateDir, n > 1 ? `${base} ${n}` : base))) return n > 1 ? `${base} ${n}` : base;
2908
2917
  }
2909
2918
  function stashedList(stateDir) {
2910
2919
  return listStashes(stateDir).flatMap((name2) => {
@@ -2918,7 +2927,7 @@ function stashedList(stateDir) {
2918
2927
  }
2919
2928
  function listStashes(stateDir) {
2920
2929
  try {
2921
- return readdirSync4(dirOf(stateDir)).filter((f) => f.endsWith(".json")).map((f) => f.slice(0, -5)).filter(nameOk).sort((a, b) => a.localeCompare(b));
2930
+ return readdirSync5(dirOf(stateDir)).filter((f) => f.endsWith(".json")).map((f) => f.slice(0, -5)).filter(nameOk).sort((a, b) => a.localeCompare(b));
2922
2931
  } catch {
2923
2932
  return [];
2924
2933
  }
@@ -2933,7 +2942,7 @@ function readStash(stateDir, name2, file2 = stashFile(stateDir, name2)) {
2933
2942
  if (!nameOk(name2)) throw new Error(`"${name2}" is not a stash name`);
2934
2943
  let st;
2935
2944
  try {
2936
- st = JSON.parse(readFileSync7(file2, "utf8"));
2945
+ st = JSON.parse(readFileSync8(file2, "utf8"));
2937
2946
  } catch (error) {
2938
2947
  throw new Error(error.code === "ENOENT" ? `Nothing is stashed as "${name2}"` : `The stash "${name2}" cannot be read: ${error.message}`);
2939
2948
  }
@@ -2988,7 +2997,7 @@ async function survey(run3, workspaceId, live, resume2 = true, serviced = false)
2988
2997
  else if (!ROLES2.has(role)) reasons.push(`${who2} is a subagent or outside the net`);
2989
2998
  if (p.agent !== "pi" || !ROLES2.has(role)) continue;
2990
2999
  if (!SETTLED.has(p.agent_status ?? "")) reasons.push(`${who2} is ${p.agent_status ?? "in an unknown state"}`);
2991
- const named = p.agent_session?.value, file2 = named && existsSync3(named) ? named : void 0;
3000
+ const named = p.agent_session?.value, file2 = named && existsSync4(named) ? named : void 0;
2992
3001
  if (!named && resume2) reasons.push(`${who2} has no session file Herdr knows of`);
2993
3002
  if (!cwd2 && resume2) reasons.push(`${who2} has no folder Herdr knows of`);
2994
3003
  if (session) agents.push(session);
@@ -3043,7 +3052,7 @@ async function closeAll(d, me, closeBase, refresh, by, workspace) {
3043
3052
  async function stashBase(d, json3, closeBase, refresh) {
3044
3053
  if (!str2(json3.workspace) || json3.workspace.length > 200) return no2(400, "bad_request", "A base is named by its workspace.");
3045
3054
  if (json3.name !== void 0 && !nameOk(json3.name)) return no2(400, "bad_request", `A stash name has at most ${MAX_NAME} characters, no slash, backslash, or control character, and does not start with a dot.`);
3046
- if (typeof json3.name === "string" && existsSync3(stashFile(d.stateDir, json3.name))) return no2(409, "exists", `Something is stashed as "${json3.name}" already; pop it or pick another name.`);
3055
+ if (typeof json3.name === "string" && existsSync4(stashFile(d.stateDir, json3.name))) return no2(409, "exists", `Something is stashed as "${json3.name}" already; pop it or pick another name.`);
3047
3056
  const sv = await survey(d.run, json3.workspace, await d.sessions(), true, d.service?.(json3.workspace));
3048
3057
  if (!sv) return no2(404, "not_found", "That base is not open any more.");
3049
3058
  const reasons = [...sv.reasons, ...await askSessions(d, sv.agents, refresh)];
@@ -3092,7 +3101,7 @@ async function popBase(d, name2) {
3092
3101
  renameSync4(claimed2, join13(dirOf(d.stateDir), "popped", `${name2}-${(d.now?.() ?? /* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`));
3093
3102
  return r;
3094
3103
  } catch (error) {
3095
- const back = existsSync3(stashFile(d.stateDir, name2)) ? nameFor(name2, d.stateDir) : name2;
3104
+ const back = existsSync4(stashFile(d.stateDir, name2)) ? nameFor(name2, d.stateDir) : name2;
3096
3105
  linkSync(claimed2, stashFile(d.stateDir, back));
3097
3106
  rmSync4(claimed2, { force: true });
3098
3107
  throw back === name2 ? error : new Error(`${error.message}; it is stashed again as "${back}", since "${name2}" was taken meanwhile`);
@@ -3106,7 +3115,7 @@ async function open2(d, name2, file2) {
3106
3115
  }
3107
3116
  const all = st.tabs.flatMap((t) => t.panes);
3108
3117
  const envOf = (kind) => [...roleEnv(kind), ...d.agentDir ? [`PI_CODING_AGENT_DIR=${d.agentDir}`] : []];
3109
- const gone = [.../* @__PURE__ */ new Set([...all.filter((p) => p.session && !existsSync3(p.session)).map((p) => p.session), ...all.map((p) => p.cwd).filter((c) => !statSync5(c, { throwIfNoEntry: false })?.isDirectory())])];
3118
+ const gone = [.../* @__PURE__ */ new Set([...all.filter((p) => p.session && !existsSync4(p.session)).map((p) => p.session), ...all.map((p) => p.cwd).filter((c) => !statSync5(c, { throwIfNoEntry: false })?.isDirectory())])];
3110
3119
  if (gone.length) throw new Error(`Nothing was opened: ${gone.join(", ")} no longer exist${gone.length > 1 ? "" : "s"}`);
3111
3120
  await assertSettingsSafe(all.filter((p) => p.kind !== "shell").map((p) => p.cwd), "The stash");
3112
3121
  const root = st.tabs[0].panes[0];
@@ -3310,7 +3319,7 @@ import { randomUUID as randomUUID6 } from "node:crypto";
3310
3319
  import { open as open4, stat as stat2 } from "node:fs/promises";
3311
3320
 
3312
3321
  // src/netdata.ts
3313
- import { readdirSync as readdirSync5, readFileSync as readFileSync8, statSync as statSync6 } from "node:fs";
3322
+ import { readdirSync as readdirSync6, readFileSync as readFileSync9, statSync as statSync6 } from "node:fs";
3314
3323
  import { basename as basename2, dirname as dirname5, join as join14 } from "node:path";
3315
3324
  var HERDR_MARK = { working: "working", blocked: "waiting", idle: "idle", done: "done" };
3316
3325
  var RECENT_MS = 10 * 6e4;
@@ -3324,7 +3333,7 @@ var commanding = (mark2, subs, monitoring = false) => mark2 === "idle" && (monit
3324
3333
  var artifacts = (file2) => join14(dirname5(file2), "artifacts", basename2(file2, ".jsonl").split("_").pop());
3325
3334
  function readJson3(path) {
3326
3335
  try {
3327
- return JSON.parse(readFileSync8(path, "utf8"));
3336
+ return JSON.parse(readFileSync9(path, "utf8"));
3328
3337
  } catch {
3329
3338
  return {};
3330
3339
  }
@@ -3356,7 +3365,7 @@ function listed(dir) {
3356
3365
  try {
3357
3366
  const stat6 = statSync6(dir, { bigint: true }), cached2 = listings.get(dir);
3358
3367
  if (cached2?.mtime === stat6.mtimeNs && cached2.readAt - Number(stat6.mtimeNs / 1000000n) > RACY_MS) return cached2.names;
3359
- const readAt = Date.now(), names = readdirSync5(dir);
3368
+ const readAt = Date.now(), names = readdirSync6(dir);
3360
3369
  if (listings.size > 200) listings.clear();
3361
3370
  listings.set(dir, { mtime: stat6.mtimeNs, readAt, names });
3362
3371
  return names;
@@ -3369,7 +3378,7 @@ function scriptRead(path) {
3369
3378
  try {
3370
3379
  const { mtimeMs } = statSync6(path), cached2 = scripts.get(path);
3371
3380
  if (cached2?.mtimeMs === mtimeMs) return cached2;
3372
- const text10 = readFileSync8(path, "utf8"), read4 = { mtimeMs, session: text10.match(/PI_SUBAGENT_SESSION='([^']+)'/)?.[1], persistent: /\bPI_SUBAGENT_PERSISTENT=1\b/.test(text10), agent: text10.match(/\bPI_SUBAGENT_AGENT='([^']+)'/)?.[1] };
3381
+ const text10 = readFileSync9(path, "utf8"), read4 = { mtimeMs, session: text10.match(/PI_SUBAGENT_SESSION='([^']+)'/)?.[1], persistent: /\bPI_SUBAGENT_PERSISTENT=1\b/.test(text10), agent: text10.match(/\bPI_SUBAGENT_AGENT='([^']+)'/)?.[1] };
3373
3382
  if (scripts.size > 500) scripts.clear();
3374
3383
  scripts.set(path, read4);
3375
3384
  return read4;
@@ -3779,7 +3788,7 @@ ${id}`, cap = caps.get(k) ?? randomBytes4(16).toString("hex");
3779
3788
  }
3780
3789
 
3781
3790
  // src/history.ts
3782
- import { constants as constants2, realpathSync as realpathSync4, watch } from "node:fs";
3791
+ import { constants as constants3, realpathSync as realpathSync5, watch } from "node:fs";
3783
3792
  import { lstat as lstat2, open as openFile, stat as stat3 } from "node:fs/promises";
3784
3793
  import { basename as basename4, dirname as dirname6, join as join15, resolve as resolve3 } from "node:path";
3785
3794
  var CHUNK2 = 1 << 20;
@@ -3788,20 +3797,20 @@ var TAIL3 = 400;
3788
3797
  var BIG = 16384;
3789
3798
  var PAGE = 150;
3790
3799
  var HIDDEN2 = /* @__PURE__ */ new Set(["session", "custom", "label", "usage", "context_edit"]);
3791
- function canonical(path) {
3800
+ function canonical2(path) {
3792
3801
  if (!path) return void 0;
3793
3802
  for (let dir = resolve3(path), rest = ""; ; rest = join15(basename4(dir), rest), dir = dirname6(dir)) {
3794
3803
  try {
3795
- return join15(realpathSync4(dir), rest);
3804
+ return join15(realpathSync5(dir), rest);
3796
3805
  } catch {
3797
3806
  if (dir === dirname6(dir)) return resolve3(path);
3798
3807
  }
3799
3808
  }
3800
3809
  }
3801
3810
  async function open5(file2) {
3802
- const nofollow = constants2.O_NOFOLLOW ?? 0;
3811
+ const nofollow = constants3.O_NOFOLLOW ?? 0;
3803
3812
  if (!nofollow && (await lstat2(file2)).isSymbolicLink()) throw Object.assign(new Error(`ELOOP: ${file2} is a symbolic link`), { code: "ELOOP" });
3804
- return openFile(file2, constants2.O_RDONLY | nofollow);
3813
+ return openFile(file2, constants3.O_RDONLY | nofollow);
3805
3814
  }
3806
3815
  function openReader(file2, pollMs = 1e3) {
3807
3816
  let ents = [], byId = /* @__PURE__ */ new Map(), path = [], bad2 = 0, size2 = 0, ino = -1, headText = "", head;
@@ -4409,7 +4418,7 @@ function createHub(pi, me, local, onAllow) {
4409
4418
  const hub = {
4410
4419
  receive,
4411
4420
  /** Whether the bridge bound to `key` relays an open dialog of `owner` (a signal from the runtime that owns the approval, not from the session file). With `at` (the unit's pane and file) the bridges are read directly too, so a dialog relayed since the last net reading counts at once. */
4412
- has: (key2, owner2, at) => Boolean(bound2.get(key2)?.b.dialogs.some((d) => d.owner === owner2)) || Boolean(at?.pane && at.file && [...bridges.values()].some((b) => b.pane === at.pane && canonical(b.file ?? void 0) === canonical(at.file) && b.dialogs.some((d) => d.owner === owner2))),
4421
+ has: (key2, owner2, at) => Boolean(bound2.get(key2)?.b.dialogs.some((d) => d.owner === owner2)) || Boolean(at?.pane && at.file && [...bridges.values()].some((b) => b.pane === at.pane && canonical2(b.file ?? void 0) === canonical2(at.file) && b.dialogs.some((d) => d.owner === owner2))),
4413
4422
  get running() {
4414
4423
  return active;
4415
4424
  },
@@ -4459,7 +4468,7 @@ function createHub(pi, me, local, onAllow) {
4459
4468
  [bound2, targets, reach] = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()];
4460
4469
  const shelved = [], cut7 = /* @__PURE__ */ new Set(), queues = /* @__PURE__ */ new Map(), mons = /* @__PURE__ */ new Map(), todos = /* @__PURE__ */ new Map();
4461
4470
  for (const [from, b] of bridges) {
4462
- const file2 = sessions.find((s2) => s2.id === from)?.herdrLocation?.paneId === b.pane ? canonical(b.file ?? void 0) : void 0;
4471
+ const file2 = sessions.find((s2) => s2.id === from)?.herdrLocation?.paneId === b.pane ? canonical2(b.file ?? void 0) : void 0;
4463
4472
  const ref = file2 && [...refs.values()].find((r) => r.pane === b.pane && r.file === file2);
4464
4473
  if (ref) reach.set(ref.key, { from, bridgeId: b.bridgeId }), shelved.push({ key: ref.key, from, bridgeId: b.bridgeId, docs: b.documents ?? [] }), b.docsCut && cut7.add(ref.key);
4465
4474
  if (ref && b.queued?.length) queues.set(ref.key, b.queued);
@@ -5373,7 +5382,7 @@ var localOnlyText = (text10) => {
5373
5382
  var LOCAL_ONLY = "Pairing, remote access, Wi-Fi, the server, the default view, deciding a join request, and answering another session's dialog are managed on this computer's own page or terminal, not from a paired device.";
5374
5383
  var GUARDED = "A /boss send is held to the guards of a remote write (the session it runs in may be driven from elsewhere): this needs this computer's own page, or type it in that session's own terminal.";
5375
5384
  var LINK_LOCAL = "While it waits on a link request, a paired device can only send Escape; approve it on this computer's own page or terminal.";
5376
- function createControl({ auto, board, bridge, lan, overlay, link, server: panel, lookup, call, csrf, canonical: canonical2, pair, remoteOn, remoteOff, paired, saveFailed, spawn: spawn3, close, dismiss, dismissAll, stop, mirrors, grants, secret = async () => true, linkRequest: linkRequest3 = async () => false, answers: answers2, trust, tower, docs, answered }) {
5385
+ function createControl({ auto, board, bridge, lan, overlay, link, server: panel, lookup, call, csrf, canonical: canonical3, pair, remoteOn, remoteOff, paired, saveFailed, spawn: spawn3, close, dismiss, dismissAll, stop, mirrors, grants, secret = async () => true, linkRequest: linkRequest3 = async () => false, answers: answers2, trust, tower, docs, answered }) {
5377
5386
  const busy = /* @__PURE__ */ new Set();
5378
5387
  const lost = () => {
5379
5388
  const reason = paired?.unsaved();
@@ -5647,14 +5656,14 @@ function createControl({ auto, board, bridge, lan, overlay, link, server: panel,
5647
5656
  async function live(found) {
5648
5657
  const { pane } = await call("pane.get", { pane_id: found.pane });
5649
5658
  if (pane.agent !== "pi") throw no8(409, "not_pi", "The pane no longer runs pi.");
5650
- if (canonical2(pane.agent_session?.value) !== found.file) throw no8(409, "moved", "The pane moved to another session.");
5659
+ if (canonical3(pane.agent_session?.value) !== found.file) throw no8(409, "moved", "The pane moved to another session.");
5651
5660
  return pane;
5652
5661
  }
5653
5662
  }
5654
5663
 
5655
5664
  // src/docs.ts
5656
5665
  import { createHash as createHash7, randomBytes as randomBytes6 } from "node:crypto";
5657
- import { createReadStream, readFileSync as readFileSync9, realpathSync as realpathSync5, statSync as statSync7 } from "node:fs";
5666
+ import { createReadStream, readFileSync as readFileSync10, realpathSync as realpathSync6, statSync as statSync7 } from "node:fs";
5658
5667
  import { pipeline } from "node:stream";
5659
5668
  import { dirname as dirname7, extname as extname2, resolve as resolve4, sep as sep3 } from "node:path";
5660
5669
 
@@ -5743,11 +5752,11 @@ function createDocs(hub, name2, { answered = createAnswered({ load: () => void 0
5743
5752
  const body2 = async (doc2) => {
5744
5753
  if (doc2.v === 2) return (await pull(doc2.capability, MAX_DOC))?.toString("utf8");
5745
5754
  const real3 = file2(doc2.path, MAX_DOC);
5746
- return real3 ? readFileSync9(real3, "utf8") : void 0;
5755
+ return real3 ? readFileSync10(real3, "utf8") : void 0;
5747
5756
  };
5748
5757
  const file2 = (path, max, under2) => {
5749
5758
  try {
5750
- const real3 = realpathSync5(path), root = under2 && realpathSync5(under2);
5759
+ const real3 = realpathSync6(path), root = under2 && realpathSync6(under2);
5751
5760
  return (root ? real3.startsWith(root + sep3) : real3 === path) && statSync7(real3).isFile() && statSync7(real3).size <= max ? real3 : void 0;
5752
5761
  } catch {
5753
5762
  return void 0;
@@ -6787,10 +6796,10 @@ function createEntry(access, token, headers) {
6787
6796
  import { pipeline as pipeline2 } from "node:stream";
6788
6797
 
6789
6798
  // src/guithemes.ts
6790
- import { readdirSync as readdirSync6, readFileSync as readFileSync10, statSync as statSync8 } from "node:fs";
6799
+ import { readdirSync as readdirSync7, readFileSync as readFileSync11, statSync as statSync8 } from "node:fs";
6791
6800
  import { join as join17 } from "node:path";
6792
6801
  function listBundle(dir) {
6793
- const bundle = new Map(readdirSync6(dir, { recursive: true, encoding: "utf8" }).filter((f) => statSync8(join17(dir, f)).isFile()).map((f) => [f.split("\\").join("/"), readFileSync10(join17(dir, f))]));
6802
+ const bundle = new Map(readdirSync7(dir, { recursive: true, encoding: "utf8" }).filter((f) => statSync8(join17(dir, f)).isFile()).map((f) => [f.split("\\").join("/"), readFileSync11(join17(dir, f))]));
6794
6803
  const map = (() => {
6795
6804
  try {
6796
6805
  return JSON.parse(bundle.get("themes.json")?.toString("utf8") ?? "{}");
@@ -6888,7 +6897,7 @@ async function startGui({ auto, board, read: read4, net, call, hub, answered = c
6888
6897
  if (net2 !== "tailnet") docs?.revoke(device);
6889
6898
  }, paired, { ...lan ? { file: lan.file } : {}, ...lan?.notify ? { notify: lan.notify } : {}, ...lan?.log ? { log: lan.log } : {} });
6890
6899
  const pair = (code = access.pair(), host2 = access.remote?.host, url = `https://${host2}/${token}/pair/${code}`) => code && host2 ? { url, rows: qr(url).map((row2) => row2.map(Number).join("")), code: access.pairCode() } : void 0;
6891
- const entry = createEntry(access, token, HEADERS), grants = call && createGrants({ call }), mirrors = createMirrors({ call, lookup: (key2) => net?.lookup(key2), secret: waitsForSecret, canonical }), docs = hub && createDocs(hub, (key2) => net?.lookup(key2)?.name ?? key2, { answered });
6900
+ const entry = createEntry(access, token, HEADERS), grants = call && createGrants({ call }), mirrors = createMirrors({ call, lookup: (key2) => net?.lookup(key2), secret: waitsForSecret, canonical: canonical2 }), docs = hub && createDocs(hub, (key2) => net?.lookup(key2)?.name ?? key2, { answered });
6892
6901
  const stop = (asked3) => refuseTake && asked3.take ? false : (setTimeout(() => onStop ? onStop(asked3) : void halt(), 10), true);
6893
6902
  const dismissAll = async () => {
6894
6903
  const n = net?.dismissAll?.() ?? 0;
@@ -6903,7 +6912,7 @@ async function startGui({ auto, board, read: read4, net, call, hub, answered = c
6903
6912
  const done2 = await tower.memory(ws, json3);
6904
6913
  await tick();
6905
6914
  return done2;
6906
- } } : tower, lookup: (key2) => net?.lookup(key2), call, csrf, canonical, pair, remoteOn: onRemote, remoteOff: onRemoteOff, paired: { on: () => Boolean(access.remote), ...access.devices, unsaved: access.unsaved }, saveFailed: onSaveFailed, spawn: spawn3, close: close && (async (kind, json3) => (await tick(), close(kind, json3, tick))), dismiss: async (key2) => typeof key2 === "string" && Boolean(net?.dismiss?.(key2)) && (await tick(), true), dismissAll, mirrors, stop, secret: waitsForSecret, linkRequest: waitsForLinkRequest, trust: trust?.answer, answers: hub && { has: hub.has, replay: hub.replay, ended: hub.ended, send: hub.send, probe: hub.probe, commands: hub.commands, pull: hub.pull, target: async (key2) => (await tick(), hub.target(key2)) }, docs, answered });
6915
+ } } : tower, lookup: (key2) => net?.lookup(key2), call, csrf, canonical: canonical2, pair, remoteOn: onRemote, remoteOff: onRemoteOff, paired: { on: () => Boolean(access.remote), ...access.devices, unsaved: access.unsaved }, saveFailed: onSaveFailed, spawn: spawn3, close: close && (async (kind, json3) => (await tick(), close(kind, json3, tick))), dismiss: async (key2) => typeof key2 === "string" && Boolean(net?.dismiss?.(key2)) && (await tick(), true), dismissAll, mirrors, stop, secret: waitsForSecret, linkRequest: waitsForLinkRequest, trust: trust?.answer, answers: hub && { has: hub.has, replay: hub.replay, ended: hub.ended, send: hub.send, probe: hub.probe, commands: hub.commands, pull: hub.pull, target: async (key2) => (await tick(), hub.target(key2)) }, docs, answered });
6907
6916
  let last, problem, inflight, local;
6908
6917
  let poll, beat;
6909
6918
  const send = (to, data, event) => to.writableEnded || to.write(`${event ? `event: ${event}
@@ -7178,7 +7187,7 @@ var joinedRole = (token) => token === "main" || token === "member" || token ===
7178
7187
  var RECENT_MS2 = 10 * 6e4;
7179
7188
  var raiserView = ({ id, ...rest }, keys) => ({ ...rest, ...id && keys.get(id) ? { key: keys.get(id) } : {} });
7180
7189
  function buildNet({ sessions, panes: ps, workspaces: all, children: children2, services, head, sessionDir = join19(process.env.PI_CODING_AGENT_DIR ?? join19(homedir6(), ".pi", "agent"), "sessions") }, refs = /* @__PURE__ */ new Map()) {
7181
- const root = canonical(sessionDir), readable2 = (file2, id, real3 = file2?.endsWith(".jsonl") ? canonical(file2) : void 0) => real3 && real3.startsWith(root + sep4) && (!id || basename6(real3).endsWith(`_${id}.jsonl`)) ? real3 : void 0;
7190
+ const root = canonical2(sessionDir), readable2 = (file2, id, real3 = file2?.endsWith(".jsonl") ? canonical2(file2) : void 0) => real3 && real3.startsWith(root + sep4) && (!id || basename6(real3).endsWith(`_${id}.jsonl`)) ? real3 : void 0;
7182
7191
  const piFile = (pane, id) => readable2(pane?.agent === "pi" ? pane.agent_session?.value : void 0, id);
7183
7192
  const paneOf = (s2) => ps.find((p) => p.pane_id === s2.herdrLocation?.paneId);
7184
7193
  const note = (mark2, status) => ({ working: status, waiting: "waiting on a question" })[mark2];
@@ -7289,7 +7298,7 @@ function netSource(env) {
7289
7298
  }
7290
7299
 
7291
7300
  // src/openings.ts
7292
- import { mkdirSync as mkdirSync6, readFileSync as readFileSync12 } from "node:fs";
7301
+ import { mkdirSync as mkdirSync6, readFileSync as readFileSync13 } from "node:fs";
7293
7302
  import { dirname as dirname8 } from "node:path";
7294
7303
  var KEPT2 = 64;
7295
7304
  var str7 = (v) => typeof v === "string" && v.length > 0;
@@ -7297,7 +7306,7 @@ var DELIVERY = ["none", "pending", "sending", "sent"];
7297
7306
  function createOpenings(file2) {
7298
7307
  const kept = /* @__PURE__ */ new Map();
7299
7308
  try {
7300
- const saved = file2 ? JSON.parse(readFileSync12(file2, "utf8")) : void 0;
7309
+ const saved = file2 ? JSON.parse(readFileSync13(file2, "utf8")) : void 0;
7301
7310
  if (saved && typeof saved === "object") {
7302
7311
  for (const [id, o] of Object.entries(saved)) {
7303
7312
  if (str7(o?.workspace) && str7(o.tab) && str7(o.pane) && str7(o.dir) && str7(o.label) && DELIVERY.includes(o.delivery)) kept.set(id, { workspace: o.workspace, tab: o.tab, pane: o.pane, dir: o.dir, label: o.label, delivery: o.delivery });
@@ -7330,6 +7339,19 @@ function createOpenings(file2) {
7330
7339
  };
7331
7340
  }
7332
7341
 
7342
+ // src/trust/intent.ts
7343
+ function createIntents() {
7344
+ const live = /* @__PURE__ */ new Set();
7345
+ return {
7346
+ grant(pane, cwd) {
7347
+ const entry = { pane, cwd: canonical(cwd) };
7348
+ live.add(entry);
7349
+ return () => void live.delete(entry);
7350
+ },
7351
+ has: (pane, cwd) => typeof cwd === "string" && [...live].some((e) => e.pane === pane && e.cwd === canonical(cwd))
7352
+ };
7353
+ }
7354
+
7333
7355
  // src/spawn.ts
7334
7356
  import { randomUUID as randomUUID8 } from "node:crypto";
7335
7357
  import { mkdir as mkdir2, readdir as readdir3, realpath as realpath2, rmdir, stat as stat5 } from "node:fs/promises";
@@ -7428,7 +7450,7 @@ async function makeDir(parent, name2, home = homedir7(), hidden = platformHidden
7428
7450
  });
7429
7451
  return real3 ? { status: 200, body: { path: real3, created: made } } : no10(409, "not_a_folder", `${clean6} exists here and is not a folder you can pick.`);
7430
7452
  }
7431
- function createSpawn({ run: run3, sleep: sleep2, call, live, sessionAt, home = homedir7(), hidden = platformHidden, deploys = createDeploys(), trustDir: trustDir2, openings = createOpenings(), note, lock = { busy: false } }) {
7453
+ function createSpawn({ run: run3, sleep: sleep2, call, live, sessionAt, home = homedir7(), hidden = platformHidden, deploys = createDeploys(), trustDir: trustDir2, openings = createOpenings(), intents, note, lock = { busy: false } }) {
7432
7454
  const pick2 = (path) => pickable(path, home, hidden);
7433
7455
  const keep2 = (id, opening3) => {
7434
7456
  try {
@@ -7494,11 +7516,16 @@ function createSpawn({ run: run3, sleep: sleep2, call, live, sessionAt, home = h
7494
7516
  } catch {
7495
7517
  }
7496
7518
  }
7497
- async function boot(d, paneId, name2, prompt, role, joinWaitMs = JOIN_WAIT_MS, track) {
7519
+ async function boot(d, paneId, name2, prompt, role, joinWaitMs = JOIN_WAIT_MS, track, intent) {
7498
7520
  d.go("start");
7499
7521
  d.pane = paneId;
7500
- await startPi(run3, sleep2, `${role ?? "member"}-${randomUUID8().slice(0, 8)}`, paneId, ["--name", name2]);
7501
- await awaitJoin(d, paneId, joinWaitMs, role);
7522
+ const release = intent ? intents?.grant(paneId, intent) : void 0;
7523
+ try {
7524
+ await startPi(run3, sleep2, `${role ?? "member"}-${randomUUID8().slice(0, 8)}`, paneId, ["--name", name2]);
7525
+ await awaitJoin(d, paneId, joinWaitMs, role);
7526
+ } finally {
7527
+ release?.();
7528
+ }
7502
7529
  if (prompt) return deliver(d, paneId, prompt, track);
7503
7530
  }
7504
7531
  const orClose = async (close, open8) => {
@@ -7579,7 +7606,7 @@ function createSpawn({ run: run3, sleep: sleep2, call, live, sessionAt, home = h
7579
7606
  if (id) {
7580
7607
  keep2(id, { ...record2, delivery });
7581
7608
  }
7582
- return boot(d, paneId, `member \xB7 ${basename7(dir) || dir}`, prompt, void 0, joinWaitMs, id ? (state) => void keep2(id, { ...record2, delivery: delivery = state }) : (state) => void (delivery = state));
7609
+ return boot(d, paneId, `member \xB7 ${basename7(dir) || dir}`, prompt, void 0, joinWaitMs, id ? (state) => void keep2(id, { ...record2, delivery: delivery = state }) : (state) => void (delivery = state), dir);
7583
7610
  }).catch((error) => {
7584
7611
  if (id) try {
7585
7612
  openings.drop(id);
@@ -7729,24 +7756,24 @@ function createTrustServe(d) {
7729
7756
  }
7730
7757
 
7731
7758
  // src/server/answeredfile.ts
7732
- import { closeSync as closeSync3, constants as constants3, fstatSync, lstatSync as lstatSync3, openSync as openSync3, readFileSync as readFileSync13, renameSync as renameSync5 } from "node:fs";
7759
+ import { closeSync as closeSync4, constants as constants4, fstatSync as fstatSync2, lstatSync as lstatSync4, openSync as openSync4, readFileSync as readFileSync14, renameSync as renameSync5 } from "node:fs";
7733
7760
  var MAX_BYTES = 32 * 1024 * 1024;
7734
7761
  function readOwnedStrict(file2) {
7735
7762
  let fd;
7736
7763
  try {
7737
- if (lstatSync3(file2).isSymbolicLink()) throw new Error("the record is a link");
7738
- fd = openSync3(file2, process.platform === "win32" ? constants3.O_RDONLY : constants3.O_RDONLY | constants3.O_NOFOLLOW);
7764
+ if (lstatSync4(file2).isSymbolicLink()) throw new Error("the record is a link");
7765
+ fd = openSync4(file2, process.platform === "win32" ? constants4.O_RDONLY : constants4.O_RDONLY | constants4.O_NOFOLLOW);
7739
7766
  } catch (error) {
7740
7767
  if (error.code === "ENOENT") return void 0;
7741
7768
  throw error;
7742
7769
  }
7743
7770
  try {
7744
- const info = fstatSync(fd);
7771
+ const info = fstatSync2(fd);
7745
7772
  if (!info.isFile() || info.size > MAX_BYTES) throw new Error("the record is not a regular file of a sane size");
7746
7773
  if (process.getuid && info.uid !== process.getuid()) throw new Error("the record belongs to another account");
7747
- return readFileSync13(fd, "utf8");
7774
+ return readFileSync14(fd, "utf8");
7748
7775
  } finally {
7749
- closeSync3(fd);
7776
+ closeSync4(fd);
7750
7777
  }
7751
7778
  }
7752
7779
  var answeredFileDeps = (file2) => ({
@@ -7761,7 +7788,7 @@ import { join as join23 } from "node:path";
7761
7788
 
7762
7789
  // src/lan/ca.ts
7763
7790
  import { createHash as createHash10, createPrivateKey as createPrivateKey3, randomBytes as randomBytes10, X509Certificate } from "node:crypto";
7764
- import { closeSync as closeSync4, constants as constants4, fstatSync as fstatSync2, lstatSync as lstatSync4, mkdirSync as mkdirSync7, openSync as openSync4, readFileSync as readFileSync14, rmSync as rmSync5, writeSync as writeSync3 } from "node:fs";
7791
+ import { closeSync as closeSync5, constants as constants5, fstatSync as fstatSync3, lstatSync as lstatSync5, mkdirSync as mkdirSync7, openSync as openSync5, readFileSync as readFileSync15, rmSync as rmSync5, writeSync as writeSync3 } from "node:fs";
7765
7792
  import { hostname as hostname2 } from "node:os";
7766
7793
  import { join as join22 } from "node:path";
7767
7794
 
@@ -7953,7 +7980,7 @@ function localName(deps = {}) {
7953
7980
  const platform = deps.platform ?? process.platform;
7954
7981
  let raw;
7955
7982
  try {
7956
- raw = platform === "darwin" ? (deps.run ?? ((program, args) => String(execFileSyncExe(program, args, { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }))))("/usr/sbin/scutil", ["--get", "LocalHostName"]) : (deps.hostname ?? hostname2)();
7983
+ raw = platform === "darwin" ? (deps.run ?? ((program, args) => String(execFileSyncExe(program, args, { encoding: "utf8", timeout: 3e3, killSignal: "SIGKILL", stdio: ["ignore", "pipe", "ignore"] }))))("/usr/sbin/scutil", ["--get", "LocalHostName"]) : (deps.hostname ?? hostname2)();
7957
7984
  } catch (error) {
7958
7985
  return { unreadable: error instanceof Error ? error.message : String(error) };
7959
7986
  }
@@ -8059,18 +8086,18 @@ function readCa(dir, deps = {}) {
8059
8086
  let fd;
8060
8087
  try {
8061
8088
  try {
8062
- if (lstatSync4(file2).isSymbolicLink()) return { lost: "corrupt" };
8063
- fd = openSync4(file2, platform === "win32" ? constants4.O_RDONLY : constants4.O_RDONLY | constants4.O_NOFOLLOW);
8089
+ if (lstatSync5(file2).isSymbolicLink()) return { lost: "corrupt" };
8090
+ fd = openSync5(file2, platform === "win32" ? constants5.O_RDONLY : constants5.O_RDONLY | constants5.O_NOFOLLOW);
8064
8091
  } catch (error) {
8065
8092
  return { lost: error.code === "ENOENT" ? "missing" : "corrupt" };
8066
8093
  }
8067
- const info = fstatSync2(fd);
8094
+ const info = fstatSync3(fd);
8068
8095
  if (!info.isFile() || uid2 !== void 0 && info.uid !== uid2 || platform !== "win32" && (info.mode & 63) !== 0) return { lost: "corrupt" };
8069
- return shaped(JSON.parse(readFileSync14(fd, "utf8")));
8096
+ return shaped(JSON.parse(readFileSync15(fd, "utf8")));
8070
8097
  } catch {
8071
8098
  return { lost: "corrupt" };
8072
8099
  } finally {
8073
- if (fd !== void 0) closeSync4(fd);
8100
+ if (fd !== void 0) closeSync5(fd);
8074
8101
  }
8075
8102
  }
8076
8103
  function shaped(value) {
@@ -8085,13 +8112,13 @@ function shaped(value) {
8085
8112
  return { ca: { v: 1, name: name2, key: key2, cert, created } };
8086
8113
  }
8087
8114
  function timeMachineExclude(path, platform = process.platform) {
8088
- if (platform === "darwin") execFileSyncExe("/usr/bin/tmutil", ["addexclusion", path], { stdio: "ignore", timeout: 1e4 });
8115
+ if (platform === "darwin") execFileSyncExe("/usr/bin/tmutil", ["addexclusion", path], { stdio: "ignore", timeout: 1e4, killSignal: "SIGKILL" });
8089
8116
  }
8090
8117
  var temps2 = 0;
8091
8118
  function writeCa(dir, ca, deps = {}) {
8092
8119
  mkdirSync7(dir, { recursive: true, mode: 448 });
8093
8120
  const file2 = join22(dir, CA_FILE), temp = `${file2}.${process.pid}.${temps2++}.${randomBytes10(4).toString("hex")}.tmp`;
8094
- const fd = openSync4(temp, "wx", 384);
8121
+ const fd = openSync5(temp, "wx", 384);
8095
8122
  try {
8096
8123
  try {
8097
8124
  (deps.exclude ?? timeMachineExclude)(temp);
@@ -8100,11 +8127,11 @@ function writeCa(dir, ca, deps = {}) {
8100
8127
  deps.log?.("lan-ca-exclude", { code: e.code ?? e.status ?? "failed" });
8101
8128
  }
8102
8129
  writeSync3(fd, JSON.stringify(ca));
8103
- closeSync4(fd);
8130
+ closeSync5(fd);
8104
8131
  renameInto(temp, file2);
8105
8132
  } catch (error) {
8106
8133
  try {
8107
- closeSync4(fd);
8134
+ closeSync5(fd);
8108
8135
  } catch {
8109
8136
  }
8110
8137
  rmSync5(temp, { force: true });
@@ -8183,14 +8210,14 @@ function createFaces(now = Date.now) {
8183
8210
  }
8184
8211
 
8185
8212
  // src/lan/firewall.ts
8186
- import { realpathSync as realpathSync6 } from "node:fs";
8213
+ import { realpathSync as realpathSync7 } from "node:fs";
8187
8214
  import { win32 as win322 } from "node:path";
8188
8215
  var fw = (code, text10, params) => ({ text: text10, code, ...params ? { params } : {} });
8189
8216
  var texts = (list2) => list2.map((n) => n.text);
8190
8217
  var READ_MS = 6e4;
8191
8218
  var MAX_BUFFER = 32 * 1024 * 1024;
8192
- var run2 = (file2, args, options) => new Promise((resolve10, reject) => {
8193
- execFileExe(file2, args, { ...options, encoding: "utf8", windowsHide: true, maxBuffer: MAX_BUFFER }, (error, stdout, stderr) => {
8219
+ var run2 = (file2, args, { timeout, ...options }) => new Promise((resolve10, reject) => {
8220
+ execFileExe(file2, args, { ...options, deadline: timeout, encoding: "utf8", windowsHide: true, maxBuffer: MAX_BUFFER }, (error, stdout, stderr) => {
8194
8221
  if (!error) return resolve10(stdout);
8195
8222
  reject(Object.assign(error, { stderr, stdout }));
8196
8223
  });
@@ -8203,7 +8230,7 @@ var reasonOf = (error, timeoutMs) => {
8203
8230
  async function readFirewall(input, deps = {}) {
8204
8231
  const platform = deps.platform ?? process.platform, execPath = deps.execPath ?? process.execPath, exec = deps.exec ?? run2, env = deps.env ?? process.env;
8205
8232
  if (platform === "darwin") return readMac(execPath, exec, env);
8206
- if (platform === "win32") return readWindows(input, execPath, exec, env, deps.realpath ?? ((p) => realpathSync6.native(p)));
8233
+ if (platform === "win32") return readWindows(input, execPath, exec, env, deps.realpath ?? ((p) => realpathSync7.native(p)));
8207
8234
  return { notes: [], summary: "no firewall check on this platform" };
8208
8235
  }
8209
8236
  var SOCKETFILTERFW = "/usr/libexec/ApplicationFirewall/socketfilterfw";
@@ -9560,14 +9587,14 @@ function storedIs(dir, view) {
9560
9587
  var writeView = (dir, view) => writeJson(join24(dir, PREFS_FILE), { v: 1, view });
9561
9588
 
9562
9589
  // src/server/guisecrets.ts
9563
- import { lstatSync as lstatSync5, rmSync as rmSync7 } from "node:fs";
9590
+ import { lstatSync as lstatSync6, rmSync as rmSync7 } from "node:fs";
9564
9591
  import { join as join25 } from "node:path";
9565
9592
  var SECRETS_FILE = "gui-secrets.json";
9566
9593
  var HEX = /^[0-9a-f]{32}$/;
9567
9594
  var port = (v) => typeof v === "number" && Number.isInteger(v) && v > 0 && v < 65536;
9568
9595
  var present = (file2) => {
9569
9596
  try {
9570
- return Boolean(lstatSync5(file2));
9597
+ return Boolean(lstatSync6(file2));
9571
9598
  } catch {
9572
9599
  return false;
9573
9600
  }
@@ -9588,12 +9615,12 @@ var keepSecrets = (dir, secrets) => writeJson(join25(dir, SECRETS_FILE), { v: 1,
9588
9615
  var dropSecrets = (dir) => rmSync7(join25(dir, SECRETS_FILE), { force: true });
9589
9616
 
9590
9617
  // src/server/trainyard.ts
9591
- import { readdirSync as readdirSync9 } from "node:fs";
9618
+ import { readdirSync as readdirSync10 } from "node:fs";
9592
9619
  import { availableParallelism, loadavg } from "node:os";
9593
9620
  import { dirname as dirname10, join as join27 } from "node:path";
9594
9621
 
9595
9622
  // src/trainswitch.ts
9596
- import { mkdirSync as mkdirSync9, readdirSync as readdirSync8, readFileSync as readFileSync15, renameSync as renameSync6, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
9623
+ import { mkdirSync as mkdirSync9, readdirSync as readdirSync9, readFileSync as readFileSync16, renameSync as renameSync6, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
9597
9624
  import { join as join26 } from "node:path";
9598
9625
  var SWITCH = "STRAW_BOSS_INTEGRATION";
9599
9626
  var ON = /* @__PURE__ */ new Set(["on", "true", "1", "yes"]);
@@ -9612,7 +9639,7 @@ function switchState(env, stateDir) {
9612
9639
  const file2 = join26(stateDir, "config.json");
9613
9640
  let text10;
9614
9641
  try {
9615
- text10 = readFileSync15(file2, "utf8");
9642
+ text10 = readFileSync16(file2, "utf8");
9616
9643
  } catch (error) {
9617
9644
  if (error.code !== "ENOENT") return { off: true, problem: `${file2} cannot be read (${error.message}); integration is off` };
9618
9645
  }
@@ -9658,7 +9685,7 @@ function reasonKind(reason) {
9658
9685
  var text5 = (stateDir) => (value, max) => plain(value.split(stateDir).join("<state>"), max);
9659
9686
  var listDirs2 = (path) => {
9660
9687
  try {
9661
- return { names: readdirSync9(path, { withFileTypes: true }).filter((e) => e.isDirectory() && isName(e.name)).map((e) => e.name).sort() };
9688
+ return { names: readdirSync10(path, { withFileTypes: true }).filter((e) => e.isDirectory() && isName(e.name)).map((e) => e.name).sort() };
9662
9689
  } catch (error) {
9663
9690
  const code = error.code;
9664
9691
  return code === "ENOENT" || code === "ENOTDIR" ? { names: [] } : { names: [], failed: `cannot list ${path}: ${code ?? error.message}` };
@@ -9668,7 +9695,7 @@ function nodsOf(folder, clean6, budget) {
9668
9695
  const out = /* @__PURE__ */ new Map();
9669
9696
  let names = [];
9670
9697
  try {
9671
- names = readdirSync9(folder).filter((n) => /^car-\d{1,3}\.json$/.test(n)).sort().slice(0, MAX_EVIDENCE_COPIES);
9698
+ names = readdirSync10(folder).filter((n) => /^car-\d{1,3}\.json$/.test(n)).sort().slice(0, MAX_EVIDENCE_COPIES);
9672
9699
  } catch {
9673
9700
  return out;
9674
9701
  }
@@ -9753,7 +9780,7 @@ function readYards(deps, join_) {
9753
9780
  const carView = (row2, app, nods) => {
9754
9781
  const accepted = (row2.accepted ?? []).slice(0, 8).map((kind) => ((nod) => nod ? { kind: clean6(kind, 32), nod } : { kind: clean6(kind, 32) })(nods?.get(row2.head)?.get(kind)));
9755
9782
  const notice = noticeOf(app, row2.head);
9756
- return { tickets: row2.tickets.slice(0, 16).map((t) => clean6(t, 64)), branch: clean6(row2.branch, 255), head: row2.head, departs: clean6(row2.departs, 300), ...row2.arrived ? { arrived: row2.arrived } : {}, accepted, ...row2.unverified ? { unverified: true } : {}, ...notice ? { notice } : {} };
9783
+ return { tickets: row2.tickets.map((t) => clean6(t, MAX_TICKET_CHARS)), branch: clean6(row2.branch, 255), head: row2.head, departs: clean6(row2.departs, 300), ...row2.arrived ? { arrived: row2.arrived } : {}, accepted, ...row2.unverified ? { unverified: true } : {}, ...notice ? { notice } : {} };
9757
9784
  };
9758
9785
  const trainRow = (read4, fact) => {
9759
9786
  if (!read4.ok) {
@@ -9853,7 +9880,7 @@ function trainyardSeam(o) {
9853
9880
  }
9854
9881
 
9855
9882
  // src/boardview.ts
9856
- import { statSync as statSync10, readdirSync as readdirSync10 } from "node:fs";
9883
+ import { statSync as statSync10, readdirSync as readdirSync11 } from "node:fs";
9857
9884
  import { join as join28 } from "node:path";
9858
9885
  var MAX_ENDED = 100;
9859
9886
  function mainsOfNet(net) {
@@ -9901,7 +9928,7 @@ function cachedEntries(read4 = readEntries) {
9901
9928
  return (dir) => {
9902
9929
  let sig;
9903
9930
  try {
9904
- sig = readdirSync10(dir).filter((n) => n.endsWith(".json")).sort().map((n) => {
9931
+ sig = readdirSync11(dir).filter((n) => n.endsWith(".json")).sort().map((n) => {
9905
9932
  const st = statSync10(join28(dir, n));
9906
9933
  return `${n}:${st.size}:${st.mtimeMs}:${st.ino}`;
9907
9934
  }).join("|");
@@ -9959,7 +9986,7 @@ function createGuiHost(o) {
9959
9986
  let lan;
9960
9987
  let remoteNote;
9961
9988
  let rotating;
9962
- const deploys = createDeploys(), openings = createOpenings(join29(slot.stateDir, "openings.json")), lock = { busy: false }, trust = createTrustServe({ dir: trustDir(slot.stateDir), herdr: slot.herdr, world: () => cfg.world(), opening: deploys.openingOf });
9989
+ const deploys = createDeploys(), openings = createOpenings(join29(slot.stateDir, "openings.json")), intents = createIntents(), lock = { busy: false }, trust = createTrustServe({ dir: trustDir(slot.stateDir), herdr: slot.herdr, world: () => cfg.world(), opening: deploys.openingOf });
9963
9990
  const answered = createAnswered(answeredFileDeps(join29(dir, "answered.json")));
9964
9991
  const live = async (session) => (await o.sessions()).some((x) => x.id === session);
9965
9992
  const theHub = () => hub ??= createHub(kit.pi, id, NO_BRIDGE, o.onAllow);
@@ -10073,7 +10100,7 @@ function createGuiHost(o) {
10073
10100
  onSaveFailed: (reason) => log.line("error", { code: "paired", text: phrase(reason, 200) }),
10074
10101
  onRemote: async () => void (await switchRemote(running, true, dir, ts), remoteNote = void 0, log.line("remote-on", { how: "page" })),
10075
10102
  onRemoteOff: async () => void (await switchRemote(running, false, dir, ts), remoteNote = void 0, log.line("remote-off", { why: "page" })),
10076
- spawn: createSpawn({ run: cfg.run, sleep: cfg.sleep, call: cfg.call, deploys, lock, trustDir: trustDir(slot.stateDir), openings, note: (event, facts) => log.line(event, facts), live, sessionAt: async (pane) => (await sessions()).find((x) => x.herdrLocation?.paneId === pane)?.id }),
10103
+ spawn: createSpawn({ run: cfg.run, sleep: cfg.sleep, call: cfg.call, deploys, lock, trustDir: trustDir(slot.stateDir), openings, intents, note: (event, facts) => log.line(event, facts), live, sessionAt: async (pane) => (await sessions()).find((x) => x.herdrLocation?.paneId === pane)?.id }),
10077
10104
  close: createCloser({
10078
10105
  run: cfg.run,
10079
10106
  sleep: cfg.sleep,
@@ -10160,7 +10187,7 @@ function createGuiHost(o) {
10160
10187
  const lanFile = () => join29(dir, "lan.json");
10161
10188
  const savedLan = () => {
10162
10189
  try {
10163
- const saved = JSON.parse(readFileSync16(lanFile(), "utf8"));
10190
+ const saved = JSON.parse(readFileSync17(lanFile(), "utf8"));
10164
10191
  return saved?.v === 1 ? saved : void 0;
10165
10192
  } catch {
10166
10193
  return void 0;
@@ -10252,6 +10279,7 @@ function createGuiHost(o) {
10252
10279
  },
10253
10280
  /** The control requests that concern the GUI; undefined for any other. */
10254
10281
  async handle(request) {
10282
+ if (request.cmd === "open-intent") return { ok: true, opened: intents.has(request.pane, request.cwd) };
10255
10283
  if (o.listen === false || !["gui", "gui-stop", "gui-remote", "gui-pair", "gui-rotate", "gui-view", ...LAN_CMDS].includes(request.cmd)) return void 0;
10256
10284
  if (closing) return { ok: false, error: "restarting" };
10257
10285
  while (rotating) {
@@ -10337,7 +10365,7 @@ function spawnRestart(cli, reason, by, env, cwd, start = spawn2) {
10337
10365
  var cliBeside = (from = import.meta.url) => fileURLToPath(new URL(from.endsWith(".ts") ? "./cli.ts" : "./cli.mjs", from));
10338
10366
 
10339
10367
  // src/server/intercom.ts
10340
- import { existsSync as existsSync4, readFileSync as readFileSync17 } from "node:fs";
10368
+ import { existsSync as existsSync5, readFileSync as readFileSync18 } from "node:fs";
10341
10369
  import { createRequire } from "node:module";
10342
10370
  import { dirname as dirname11, join as join30 } from "node:path";
10343
10371
  import { fileURLToPath as fileURLToPath2, pathToFileURL } from "node:url";
@@ -10360,17 +10388,17 @@ function findTsx(from = import.meta.url) {
10360
10388
  }
10361
10389
  let exp;
10362
10390
  try {
10363
- exp = JSON.parse(readFileSync17(manifest, "utf8")).exports?.["./esm/api"];
10391
+ exp = JSON.parse(readFileSync18(manifest, "utf8")).exports?.["./esm/api"];
10364
10392
  } catch {
10365
10393
  }
10366
10394
  const entry = typeof exp === "string" ? exp : exp?.import?.default;
10367
10395
  const file2 = typeof entry === "string" ? join30(dirname11(manifest), entry) : void 0;
10368
- if (file2 && existsSync4(file2)) return file2;
10396
+ if (file2 && existsSync5(file2)) return file2;
10369
10397
  throw new LoaderError("loader", `tsx at ${dirname11(manifest)} has no ESM entry for tsx/esm/api: pi-straw-boss needs tsx ^4.23.15`);
10370
10398
  }
10371
10399
  function intercomVersion(dir) {
10372
10400
  try {
10373
- const version = JSON.parse(readFileSync17(join30(dir, "package.json"), "utf8")).version;
10401
+ const version = JSON.parse(readFileSync18(join30(dir, "package.json"), "utf8")).version;
10374
10402
  return typeof version === "string" ? version : void 0;
10375
10403
  } catch {
10376
10404
  return void 0;
@@ -10787,7 +10815,7 @@ function unitLabel(found) {
10787
10815
  }
10788
10816
 
10789
10817
  // src/server/opentower.ts
10790
- import { realpathSync as realpathSync7 } from "node:fs";
10818
+ import { realpathSync as realpathSync8 } from "node:fs";
10791
10819
  import { basename as basename8 } from "node:path";
10792
10820
  var OpenTowerError = class extends Error {
10793
10821
  code;
@@ -10803,7 +10831,7 @@ var labelOf = (root) => {
10803
10831
  async function openTowerFor(d, project, toWorkspace, existing = false) {
10804
10832
  let root;
10805
10833
  try {
10806
- root = realpathSync7.native(project);
10834
+ root = realpathSync8.native(project);
10807
10835
  } catch {
10808
10836
  throw new OpenTowerError(`The project ${project} does not exist`, "project");
10809
10837
  }
@@ -10834,7 +10862,7 @@ async function openTowerFor(d, project, toWorkspace, existing = false) {
10834
10862
  }
10835
10863
  var realpathOr = (path) => {
10836
10864
  try {
10837
- return realpathSync7.native(path);
10865
+ return realpathSync8.native(path);
10838
10866
  } catch {
10839
10867
  return void 0;
10840
10868
  }
@@ -10857,12 +10885,12 @@ function towerOpener(d) {
10857
10885
  }
10858
10886
 
10859
10887
  // src/server/trainsweep.ts
10860
- import { lstatSync as lstatSync6, rmSync as rmSync9, unlinkSync } from "node:fs";
10888
+ import { lstatSync as lstatSync7, rmSync as rmSync9, unlinkSync } from "node:fs";
10861
10889
  import { dirname as dirname12, join as join31 } from "node:path";
10862
10890
  var headsOf = (board) => [...board.cars.map((c) => c.head), ...(board.removed ?? []).flatMap((r) => r.head ? [r.head] : [])];
10863
10891
  var isFolder = (path) => {
10864
10892
  try {
10865
- return lstatSync6(path).isDirectory();
10893
+ return lstatSync7(path).isDirectory();
10866
10894
  } catch {
10867
10895
  return false;
10868
10896
  }
@@ -10941,7 +10969,7 @@ function startTrainSweep(o) {
10941
10969
  }
10942
10970
 
10943
10971
  // src/link/service.ts
10944
- import { readFileSync as readFileSync20 } from "node:fs";
10972
+ import { readFileSync as readFileSync21 } from "node:fs";
10945
10973
  import { homedir as homedir8 } from "node:os";
10946
10974
  import { join as join34 } from "node:path";
10947
10975
 
@@ -11620,13 +11648,13 @@ function checkJoiner(o) {
11620
11648
  }
11621
11649
 
11622
11650
  // src/link/joinfile.ts
11623
- import { constants as constants5, fstatSync as fstatSync3, lstatSync as lstatSync7, openSync as openSync5, readFileSync as readFileSync18, closeSync as closeSync5, unlinkSync as unlinkSync2 } from "node:fs";
11651
+ import { constants as constants6, fstatSync as fstatSync4, lstatSync as lstatSync8, openSync as openSync6, readFileSync as readFileSync19, closeSync as closeSync6, unlinkSync as unlinkSync2 } from "node:fs";
11624
11652
  import { join as join32 } from "node:path";
11625
11653
  var JOIN_FILE = "join.txt";
11626
11654
  var joinFilePath = (linkDir) => join32(linkDir, JOIN_FILE);
11627
11655
  function fileMark(path) {
11628
11656
  try {
11629
- const st = lstatSync7(path);
11657
+ const st = lstatSync8(path);
11630
11658
  return `${st.dev}:${st.ino}:${st.mtimeMs}`;
11631
11659
  } catch {
11632
11660
  return void 0;
@@ -11636,7 +11664,7 @@ function readJoinFile(path, d = {}) {
11636
11664
  const uid2 = d.uid ?? process.getuid?.();
11637
11665
  if (uid2 === void 0) return { state: "refused", reason: "this platform has no user ids, so the owner of join.txt cannot be checked" };
11638
11666
  try {
11639
- const st = lstatSync7(path);
11667
+ const st = lstatSync8(path);
11640
11668
  if (st.isSymbolicLink()) return { state: "refused", reason: "join.txt is a symlink" };
11641
11669
  if (!st.isFile()) return { state: "refused", reason: "join.txt is not a regular file" };
11642
11670
  } catch (error) {
@@ -11644,17 +11672,17 @@ function readJoinFile(path, d = {}) {
11644
11672
  }
11645
11673
  let fd;
11646
11674
  try {
11647
- fd = openSync5(path, constants5.O_RDONLY | constants5.O_NOFOLLOW | constants5.O_NONBLOCK);
11648
- const st = fstatSync3(fd);
11675
+ fd = openSync6(path, constants6.O_RDONLY | constants6.O_NOFOLLOW | constants6.O_NONBLOCK);
11676
+ const st = fstatSync4(fd);
11649
11677
  if (!st.isFile()) return { state: "refused", reason: "join.txt is not a regular file" };
11650
11678
  if (st.uid !== uid2) return { state: "refused", reason: "join.txt is not owned by this device's own user" };
11651
11679
  if ((st.mode & 511) !== 384) return { state: "refused", reason: `join.txt has mode ${(st.mode & 511).toString(8)}; it has to be 600` };
11652
- return { state: "text", text: readFileSync18(fd, "utf8") };
11680
+ return { state: "text", text: readFileSync19(fd, "utf8") };
11653
11681
  } catch (error) {
11654
11682
  const code = error.code;
11655
11683
  return code === "ENOENT" ? { state: "absent" } : { state: "refused", reason: `join.txt cannot be read: ${code ?? "error"}` };
11656
11684
  } finally {
11657
- if (fd !== void 0) closeSync5(fd);
11685
+ if (fd !== void 0) closeSync6(fd);
11658
11686
  }
11659
11687
  }
11660
11688
  function removeJoinFile(path) {
@@ -12575,13 +12603,13 @@ var Requests = class {
12575
12603
  };
12576
12604
 
12577
12605
  // src/server/towerruns.ts
12578
- import { readFileSync as readFileSync19 } from "node:fs";
12606
+ import { readFileSync as readFileSync20 } from "node:fs";
12579
12607
  import { join as join33 } from "node:path";
12580
12608
  var DEFAULT_MAX = 4;
12581
12609
  function readTowerRuns(stateDir) {
12582
12610
  let section, problem;
12583
12611
  try {
12584
- section = JSON.parse(readFileSync19(join33(stateDir, "config.json"), "utf8")).towerRuns;
12612
+ section = JSON.parse(readFileSync20(join33(stateDir, "config.json"), "utf8")).towerRuns;
12585
12613
  } catch (cause) {
12586
12614
  if (cause.code !== "ENOENT") problem = `${join33(stateDir, "config.json")} cannot be read (${cause.message.slice(0, 120)}), so towerRuns.enabled and max are the defaults: the tower service is on`;
12587
12615
  }
@@ -14715,7 +14743,7 @@ function createLinkService({ kit, stateDir, version, started, pid = process.pid,
14715
14743
  const attended = () => policy().mode === "attended";
14716
14744
  const guiOwner = () => {
14717
14745
  try {
14718
- return JSON.parse(readFileSync20(join34(stateDir, "gui.json"), "utf8")).ownerSession || void 0;
14746
+ return JSON.parse(readFileSync21(join34(stateDir, "gui.json"), "utf8")).ownerSession || void 0;
14719
14747
  } catch {
14720
14748
  return void 0;
14721
14749
  }
@@ -15964,11 +15992,11 @@ function createOperateHost(deps) {
15964
15992
  }
15965
15993
 
15966
15994
  // src/server/operateoff.ts
15967
- import { chmodSync as chmodSync5, lstatSync as lstatSync8, mkdirSync as mkdirSync10, readFileSync as readFileSync21, rmSync as rmSync10 } from "node:fs";
15995
+ import { chmodSync as chmodSync5, lstatSync as lstatSync9, mkdirSync as mkdirSync10, readFileSync as readFileSync22, rmSync as rmSync10 } from "node:fs";
15968
15996
  import { dirname as dirname13 } from "node:path";
15969
15997
  var present2 = (path) => {
15970
15998
  try {
15971
- lstatSync8(path);
15999
+ lstatSync9(path);
15972
16000
  return true;
15973
16001
  } catch (error) {
15974
16002
  return error?.code !== "ENOENT";
@@ -15977,7 +16005,7 @@ var present2 = (path) => {
15977
16005
  function operateOff(file2, now) {
15978
16006
  let since;
15979
16007
  try {
15980
- const text10 = readFileSync21(file2, "utf8"), found = JSON.parse(text10)?.since;
16008
+ const text10 = readFileSync22(file2, "utf8"), found = JSON.parse(text10)?.since;
15981
16009
  since = typeof found === "number" && Number.isSafeInteger(found) && found >= 0 ? found : now();
15982
16010
  } catch (error) {
15983
16011
  since = error?.code === "ENOENT" && !present2(file2) ? void 0 : now();
@@ -16013,7 +16041,7 @@ import { homedir as homedir9 } from "node:os";
16013
16041
  import { join as join37 } from "node:path";
16014
16042
 
16015
16043
  // src/server/allyroute.ts
16016
- import { readFileSync as readFileSync22 } from "node:fs";
16044
+ import { readFileSync as readFileSync23 } from "node:fs";
16017
16045
  import { join as join35 } from "node:path";
16018
16046
  var ROUTES2 = ALLY_FILES[0];
16019
16047
  var ANSWERS = ALLY_FILES[1];
@@ -16027,7 +16055,7 @@ var DEAD_GRACE_MS = 10 * 6e4;
16027
16055
  var OPENED_KEEP_MS = 7 * KEEP_MS2;
16028
16056
  var read2 = (slot, workspace, file2, now) => {
16029
16057
  try {
16030
- const found = JSON.parse(readFileSync22(join35(towerDir(slot, workspace), file2), "utf8"));
16058
+ const found = JSON.parse(readFileSync23(join35(towerDir(slot, workspace), file2), "utf8"));
16031
16059
  return (Array.isArray(found.entries) ? found.entries : []).filter((e) => typeof e?.at === "number" && now - e.at <= (e.kind === "opened" ? OPENED_KEEP_MS : KEEP_MS2));
16032
16060
  } catch {
16033
16061
  return [];
@@ -16109,14 +16137,14 @@ function removeAnswer(slot, workspace, id, now) {
16109
16137
  }
16110
16138
 
16111
16139
  // src/server/towerrunstore.ts
16112
- import { appendFileSync as appendFileSync2, readdirSync as readdirSync11, readFileSync as readFileSync23, rmSync as rmSync11 } from "node:fs";
16140
+ import { appendFileSync as appendFileSync2, readdirSync as readdirSync12, readFileSync as readFileSync24, rmSync as rmSync11 } from "node:fs";
16113
16141
  import { join as join36 } from "node:path";
16114
16142
  var KEEP_RUNS = 50;
16115
16143
  var KEEP_NOTES = 10;
16116
16144
  var runsDir = (slot, workspace) => join36(towerDir(slot, workspace), "runs");
16117
16145
  var readJson4 = (file2) => {
16118
16146
  try {
16119
- return JSON.parse(readFileSync23(file2, "utf8"));
16147
+ return JSON.parse(readFileSync24(file2, "utf8"));
16120
16148
  } catch {
16121
16149
  return void 0;
16122
16150
  }
@@ -16130,7 +16158,7 @@ var readRun = (slot, workspace, id) => readJson4(join36(runsDir(slot, workspace)
16130
16158
  function listRuns(slot, workspace) {
16131
16159
  let names = [];
16132
16160
  try {
16133
- names = readdirSync11(runsDir(slot, workspace)).filter((n) => n.endsWith(".json"));
16161
+ names = readdirSync12(runsDir(slot, workspace)).filter((n) => n.endsWith(".json"));
16134
16162
  } catch {
16135
16163
  return [];
16136
16164
  }
@@ -16146,7 +16174,7 @@ function pruneRuns(slot, workspace) {
16146
16174
  var notesFile = (slot, workspace) => join36(towerDir(slot, workspace), "notes.jsonl");
16147
16175
  function readNotes(slot, workspace) {
16148
16176
  try {
16149
- return readFileSync23(notesFile(slot, workspace), "utf8").split("\n").flatMap((line3) => {
16177
+ return readFileSync24(notesFile(slot, workspace), "utf8").split("\n").flatMap((line3) => {
16150
16178
  try {
16151
16179
  const row2 = JSON.parse(line3);
16152
16180
  return typeof row2?.note === "string" && (row2.kind === "local" || row2.kind === "ally") ? [row2] : [];
@@ -16834,7 +16862,7 @@ function createOperateBox(d) {
16834
16862
 
16835
16863
  // src/server/operateledger.ts
16836
16864
  import { createHash as createHash13 } from "node:crypto";
16837
- import { appendFileSync as appendFileSync3, chmodSync as chmodSync6, closeSync as closeSync6, constants as constants6, fstatSync as fstatSync4, mkdirSync as mkdirSync11, openSync as openSync6, readFileSync as readFileSync24, statSync as statSync11 } from "node:fs";
16865
+ import { appendFileSync as appendFileSync3, chmodSync as chmodSync6, closeSync as closeSync7, constants as constants7, fstatSync as fstatSync5, mkdirSync as mkdirSync11, openSync as openSync7, readFileSync as readFileSync25, statSync as statSync11 } from "node:fs";
16838
16866
  import { dirname as dirname14, sep as sep6 } from "node:path";
16839
16867
  var KEEP_MS7 = 30 * 24 * 36e5;
16840
16868
  var MAX_ROWS2 = 2e3;
@@ -16873,17 +16901,17 @@ function fold(source) {
16873
16901
  }
16874
16902
  var order = (a, b) => b.last - a.last || (a.id < b.id ? 1 : a.id > b.id ? -1 : 0);
16875
16903
  function readable(file2, root) {
16876
- const real3 = canonical(file2), top = canonical(root);
16904
+ const real3 = canonical2(file2), top = canonical2(root);
16877
16905
  if (!real3 || !top || !real3.endsWith(".jsonl") || !real3.startsWith(top + sep6)) return void 0;
16878
16906
  let fd;
16879
16907
  try {
16880
- fd = openSync6(real3, constants6.O_RDONLY | constants6.O_NONBLOCK | (constants6.O_NOFOLLOW ?? 0));
16881
- const s2 = fstatSync4(fd), at = statSync11(real3);
16908
+ fd = openSync7(real3, constants7.O_RDONLY | constants7.O_NONBLOCK | (constants7.O_NOFOLLOW ?? 0));
16909
+ const s2 = fstatSync5(fd), at = statSync11(real3);
16882
16910
  return s2.isFile() && s2.nlink === 1 && s2.dev === at.dev && s2.ino === at.ino ? { real: real3, size: s2.size } : void 0;
16883
16911
  } catch {
16884
16912
  return void 0;
16885
16913
  } finally {
16886
- if (fd !== void 0) closeSync6(fd);
16914
+ if (fd !== void 0) closeSync7(fd);
16887
16915
  }
16888
16916
  }
16889
16917
  function openLedger(d) {
@@ -16891,7 +16919,7 @@ function openLedger(d) {
16891
16919
  });
16892
16920
  let source = "";
16893
16921
  try {
16894
- source = readFileSync24(d.file, "utf8");
16922
+ source = readFileSync25(d.file, "utf8");
16895
16923
  } catch {
16896
16924
  }
16897
16925
  const { rows, lines } = fold(source), at = d.now();
@@ -16929,7 +16957,7 @@ function openLedger(d) {
16929
16957
  const at2 = d.now(), live = /* @__PURE__ */ new Set();
16930
16958
  for (const u of units) {
16931
16959
  if (!u.file || u.role === HEAD2) continue;
16932
- const file2 = canonical(u.file) ?? u.file, id = idOf2(file2), old = book.get(id), over = u.live === false;
16960
+ const file2 = canonical2(u.file) ?? u.file, id = idOf2(file2), old = book.get(id), over = u.live === false;
16933
16961
  if (!old) {
16934
16962
  const prior = owners.get(id), mine = u.owner && ("team" in u.owner ? u.owner.team : BOX2);
16935
16963
  if (!prior && !mine) continue;
@@ -17113,13 +17141,13 @@ function operateWire(o) {
17113
17141
  }
17114
17142
 
17115
17143
  // src/server/carops.ts
17116
- import { existsSync as existsSync5, readFileSync as readFileSync26 } from "node:fs";
17144
+ import { existsSync as existsSync6, readFileSync as readFileSync27 } from "node:fs";
17117
17145
  import { homedir as homedir10 } from "node:os";
17118
17146
  import { join as join39, parse as parse4, resolve as resolve6 } from "node:path";
17119
17147
 
17120
17148
  // src/server/carbook.ts
17121
17149
  import { randomBytes as randomBytes17 } from "node:crypto";
17122
- import { lstatSync as lstatSync9, mkdirSync as mkdirSync12, mkdtempSync, readdirSync as readdirSync12, readFileSync as readFileSync25, rmSync as rmSync12, writeFileSync as writeFileSync7 } from "node:fs";
17150
+ import { lstatSync as lstatSync10, mkdirSync as mkdirSync12, mkdtempSync, readdirSync as readdirSync13, readFileSync as readFileSync26, rmSync as rmSync12, writeFileSync as writeFileSync7 } from "node:fs";
17123
17151
  import { hostname as hostname3 } from "node:os";
17124
17152
  import { isAbsolute as isAbsolute7, join as join38, parse as parse3 } from "node:path";
17125
17153
  var KEEP_MS8 = 24 * 36e5;
@@ -17171,7 +17199,7 @@ function sshCommand(knownHosts) {
17171
17199
  }
17172
17200
  var kindOf2 = (path) => {
17173
17201
  try {
17174
- const st = lstatSync9(path);
17202
+ const st = lstatSync10(path);
17175
17203
  return st.isSymbolicLink() ? "link" : st.isDirectory() ? "dir" : st.isFile() ? "file" : "other";
17176
17204
  } catch {
17177
17205
  return "none";
@@ -17179,7 +17207,7 @@ var kindOf2 = (path) => {
17179
17207
  };
17180
17208
  var entries = (path) => {
17181
17209
  try {
17182
- return readdirSync12(path).sort();
17210
+ return readdirSync13(path).sort();
17183
17211
  } catch {
17184
17212
  return [];
17185
17213
  }
@@ -17227,12 +17255,12 @@ function inspectMirror(dir, code, stage, before) {
17227
17255
  if (stage !== "init" && !refFiles.includes(wanted[0])) bad2.push(`refs/${wanted[0]} (missing)`);
17228
17256
  if (bad2.length) return { problems: bad2 };
17229
17257
  if (stage === "init") {
17230
- const odd = strangeConfig(readFileSync25(join38(dir, "config"), "utf8"));
17258
+ const odd = strangeConfig(readFileSync26(join38(dir, "config"), "utf8"));
17231
17259
  if (odd) return { problems: [`config: ${odd}`] };
17232
- if (!/^ref: refs\/heads\/[A-Za-z0-9._/-]+\r?\n?$/.test(readFileSync25(join38(dir, "HEAD"), "utf8"))) return { problems: ["HEAD"] };
17260
+ if (!/^ref: refs\/heads\/[A-Za-z0-9._/-]+\r?\n?$/.test(readFileSync26(join38(dir, "HEAD"), "utf8"))) return { problems: ["HEAD"] };
17233
17261
  }
17234
- const refValue = refFiles.length ? refFiles.map((f) => readFileSync25(join38(refs, f), "latin1")).join("|") : "";
17235
- const look3 = { refs: refValue, config: readFileSync25(join38(dir, "config")).toString("latin1"), head: readFileSync25(join38(dir, "HEAD")).toString("latin1"), packs: packs.map((n) => `${n}:${lstatSync9(join38(packDir, n)).size}`).join(",") };
17262
+ const refValue = refFiles.length ? refFiles.map((f) => readFileSync26(join38(refs, f), "latin1")).join("|") : "";
17263
+ const look3 = { refs: refValue, config: readFileSync26(join38(dir, "config")).toString("latin1"), head: readFileSync26(join38(dir, "HEAD")).toString("latin1"), packs: packs.map((n) => `${n}:${lstatSync10(join38(packDir, n)).size}`).join(",") };
17236
17264
  if (before) {
17237
17265
  if (look3.config !== before.config) bad2.push("config (changed)");
17238
17266
  if (look3.head !== before.head) bad2.push("HEAD (changed)");
@@ -17253,8 +17281,11 @@ var CarBook = class {
17253
17281
  failures = /* @__PURE__ */ new Map();
17254
17282
  chain = Promise.resolve();
17255
17283
  d;
17284
+ /** Since when this book holds forwards: none made before it is here, whatever the disk holds. */
17285
+ since;
17256
17286
  constructor(deps) {
17257
17287
  this.d = deps;
17288
+ this.since = deps.startedAt ?? deps.now();
17258
17289
  }
17259
17290
  // ---- the display journal: written here, read by the yard, never read back (CR-F003)
17260
17291
  writeCar(project, name2, held) {
@@ -17302,6 +17333,14 @@ var CarBook = class {
17302
17333
  trainOf(project, code) {
17303
17334
  return this.trains.get(`${project}/${code}`);
17304
17335
  }
17336
+ /**
17337
+ * What the refusal of a forward this book does not hold adds while a forward made before the server's start would still be kept (todo #154; live, 0.75.0: a slip forwarded 8 minutes before an install restarted the server could be neither received nor
17338
+ * returned, and the refusal named no cause). Nothing is restored: the tower's forward to this server is the fact, so the way back is that forward again. After `KEEP_MS` no earlier forward would count, and nothing is added.
17339
+ */
17340
+ restartWord() {
17341
+ if (this.d.now() - this.since >= KEEP_MS8) return "";
17342
+ return ` The sb server started at ${iso(this.since)} and keeps a tower's forwards in memory only, so a forward made before that is gone with the restart: ask the car's coordinator to send its slip to the tower again (call_tower why=shared); the tower forwards it again, and then the state is set.`;
17343
+ }
17305
17344
  // ---- the registration: defense in depth
17306
17345
  /**
17307
17346
  * Hands the pi process its secret, once. The session must be live, in a pane Herdr knows, and `pid` one of that pane's foreground processes with the start time the server reads for it. A registration whose process still runs in the pane is not replaced
@@ -17426,8 +17465,9 @@ var CarBook = class {
17426
17465
  let file2, name2, held, label;
17427
17466
  if (setter.role === "main") {
17428
17467
  const sent = this.forwardOf(head, setter.session);
17429
- if (!sent) throw refusal3(`sb: no forward by a tower carries head ${head.slice(0, 12)} to this session: a car slip reaches the integrator only as the tower's tower_send or tower_reply with forward: (the code stamps fwd-from)`);
17468
+ if (!sent) throw refusal3(`sb: no forward by a tower carries head ${head.slice(0, 12)} to this session: a car slip reaches the integrator only as the tower's tower_send or tower_reply with forward: (the code stamps fwd-from).${this.restartWord()}`);
17430
17469
  const slip = sent.slip;
17470
+ if (slip.over) throw refusal3(slip.over);
17431
17471
  name2 = carFileName(slip.app, head);
17432
17472
  held = this.cars.get(project)?.get(name2);
17433
17473
  file2 = held?.file;
@@ -17724,7 +17764,7 @@ function runGit(cwd, args, extra = {}) {
17724
17764
  for (const [key2, value] of Object.entries(process.env)) if (value !== void 0 && KEEP_ENV.test(key2)) env[key2] = value;
17725
17765
  Object.assign(env, { GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_TERMINAL_PROMPT: "0", GIT_OPTIONAL_LOCKS: "0", GIT_CEILING_DIRECTORIES: parse4(resolve6(cwd)).root, ...extra });
17726
17766
  const isolation = ["-c", "core.fsmonitor=", "-c", "core.hooksPath=/dev/null", "-c", "protocol.ext.allow=never", "-c", "submodule.recurse=false", "--no-replace-objects"];
17727
- return new Promise((resolvePromise, reject) => execFileExe("git", [...isolation, "-C", cwd, ...args], { encoding: "utf8", timeout: 6e4, env, windowsHide: true }, (error, stdout, stderr) => error ? reject(Object.assign(error, { stderr })) : resolvePromise(String(stdout).trim())));
17767
+ return new Promise((resolvePromise, reject) => execFileExe("git", [...isolation, "-C", cwd, ...args], { encoding: "utf8", deadline: 6e4, env, windowsHide: true }, (error, stdout, stderr) => error ? reject(Object.assign(error, { stderr })) : resolvePromise(String(stdout).trim())));
17728
17768
  }
17729
17769
  var reply2 = (error) => ({ ok: false, error: error.message });
17730
17770
  function carsReply(cars, request) {
@@ -17764,7 +17804,7 @@ async function look2(o, session) {
17764
17804
  }
17765
17805
  function knownHostsOfUser() {
17766
17806
  try {
17767
- return readFileSync26(join39(homedir10(), ".ssh", "known_hosts"), "utf8").slice(0, 4e6);
17807
+ return readFileSync27(join39(homedir10(), ".ssh", "known_hosts"), "utf8").slice(0, 4e6);
17768
17808
  } catch {
17769
17809
  return "";
17770
17810
  }
@@ -17775,10 +17815,11 @@ function startCars(o) {
17775
17815
  stateDir: o.slot.stateDir,
17776
17816
  dir: o.slot.dir,
17777
17817
  now: o.now,
17818
+ ...o.startedAt !== void 0 ? { startedAt: o.startedAt } : {},
17778
17819
  look: (session) => look2(o, session),
17779
17820
  git: runGit,
17780
17821
  knownHosts: knownHostsOfUser(),
17781
- exists: existsSync5,
17822
+ exists: existsSync6,
17782
17823
  log: o.log,
17783
17824
  startOf: o.startOf,
17784
17825
  onChange: () => notices?.kick(),
@@ -17795,11 +17836,11 @@ import { join as join42 } from "node:path";
17795
17836
  import { homedir as homedir11 } from "node:os";
17796
17837
 
17797
17838
  // src/server/procs.ts
17798
- import { existsSync as existsSync6, mkdirSync as mkdirSync13, readdirSync as readdirSync13, readFileSync as readFileSync29, renameSync as renameSync7 } from "node:fs";
17839
+ import { existsSync as existsSync7, mkdirSync as mkdirSync13, readdirSync as readdirSync14, readFileSync as readFileSync30, renameSync as renameSync7 } from "node:fs";
17799
17840
  import { join as join41 } from "node:path";
17800
17841
 
17801
17842
  // src/procs/worktree.ts
17802
- import { readFileSync as readFileSync27, realpathSync as realpathSync8, statSync as statSync12 } from "node:fs";
17843
+ import { readFileSync as readFileSync28, realpathSync as realpathSync9, statSync as statSync12 } from "node:fs";
17803
17844
  import { basename as basename11, dirname as dirname15, join as join40, relative as relative4, isAbsolute as isAbsolute8, resolve as resolve7 } from "node:path";
17804
17845
  var realDisk = {
17805
17846
  kind: (path) => {
@@ -17811,7 +17852,7 @@ var realDisk = {
17811
17852
  },
17812
17853
  read: (path) => {
17813
17854
  try {
17814
- return readFileSync27(path, "utf8");
17855
+ return readFileSync28(path, "utf8");
17815
17856
  } catch {
17816
17857
  return void 0;
17817
17858
  }
@@ -17821,7 +17862,7 @@ function physical(path) {
17821
17862
  const abs = resolve7(path), tail = [];
17822
17863
  for (let dir = abs; ; dir = dirname15(dir)) {
17823
17864
  try {
17824
- return join40(realpathSync8.native(dir), ...tail.reverse());
17865
+ return join40(realpathSync9.native(dir), ...tail.reverse());
17825
17866
  } catch {
17826
17867
  if (dirname15(dir) === dir) return abs;
17827
17868
  tail.push(basename11(dir));
@@ -17929,7 +17970,7 @@ function killSet({ owner, live, table, places, markers, protect, reapers, self,
17929
17970
  }
17930
17971
 
17931
17972
  // src/procs/marker.ts
17932
- import { readFileSync as readFileSync28 } from "node:fs";
17973
+ import { readFileSync as readFileSync29 } from "node:fs";
17933
17974
  var OWNER_KEY = "STRAW_BOSS_OWNER";
17934
17975
  var ID3 = /^[A-Za-z0-9._-]{1,64}$/;
17935
17976
  var WORD2 = new RegExp(`(?:^|\\s)${OWNER_KEY}=([^\\s]*)(?=\\s|$)`, "g");
@@ -17948,7 +17989,7 @@ function parseOwnerRows(text10, wanted) {
17948
17989
  return out;
17949
17990
  }
17950
17991
  var CHUNK3 = 100;
17951
- async function readOwners(pids, { run: ask = run, platform = process.platform, environ = (pid) => readFileSync28(`/proc/${pid}/environ`) } = {}) {
17992
+ async function readOwners(pids, { run: ask = run, platform = process.platform, environ = (pid) => readFileSync29(`/proc/${pid}/environ`) } = {}) {
17952
17993
  const out = /* @__PURE__ */ new Map();
17953
17994
  if (platform === "win32") return out;
17954
17995
  if (platform === "linux") {
@@ -17989,7 +18030,7 @@ function createProcs(d) {
17989
18030
  const folder = join41(d.dir, "procs"), file2 = join41(folder, OWNERS_FILE);
17990
18031
  const read4 = d.read ?? (() => readTable()), cwdsOf = d.cwds ?? ((pids) => readCwds(pids)), markersOf = d.markers ?? ((pids) => readOwners(pids));
17991
18032
  const inode = d.inode ?? inodeOnDisk, checkout = d.checkout ?? checkoutOf, probe = d.startOf ?? startOf, reap2 = d.reap ?? ((refs) => reap(refs));
17992
- const platform = d.platform ?? process.platform, self = d.self ?? [process.pid], real3 = d.real ?? physical, exists = d.exists ?? existsSync6;
18033
+ const platform = d.platform ?? process.platform, self = d.self ?? [process.pid], real3 = d.real ?? physical, exists = d.exists ?? existsSync7;
17993
18034
  const owners = /* @__PURE__ */ new Map();
17994
18035
  const pending = /* @__PURE__ */ new Set();
17995
18036
  const linked = /* @__PURE__ */ new Map();
@@ -18006,7 +18047,7 @@ function createProcs(d) {
18006
18047
  };
18007
18048
  const load2 = () => {
18008
18049
  try {
18009
- const parsed = JSON.parse(readFileSync29(file2, "utf8"));
18050
+ const parsed = JSON.parse(readFileSync30(file2, "utf8"));
18010
18051
  for (const r of Array.isArray(parsed.owners) ? parsed.owners : []) {
18011
18052
  const o = r;
18012
18053
  if (typeof o?.id === "string" && ID4.test(o.id) && Number.isSafeInteger(o.pid) && typeof o.started === "string" && Array.isArray(o.roots) && Array.isArray(o.snapshot)) {
@@ -18302,13 +18343,13 @@ function createProcs(d) {
18302
18343
  function serverPids(stateDir) {
18303
18344
  const files = [join41(stateDir, "server.json")];
18304
18345
  try {
18305
- for (const hash of readdirSync13(join41(stateDir, "servers"))) files.push(join41(stateDir, "servers", hash, "server.json"));
18346
+ for (const hash of readdirSync14(join41(stateDir, "servers"))) files.push(join41(stateDir, "servers", hash, "server.json"));
18306
18347
  } catch {
18307
18348
  }
18308
18349
  const found = [];
18309
18350
  for (const f of files) {
18310
18351
  try {
18311
- const { pid, started } = JSON.parse(readFileSync29(f, "utf8"));
18352
+ const { pid, started } = JSON.parse(readFileSync30(f, "utf8"));
18312
18353
  if (typeof pid === "number" && Number.isSafeInteger(pid) && pid > 1) found.push({ pid, ...typeof started === "string" && started ? { started } : {} });
18313
18354
  } catch {
18314
18355
  }
@@ -18320,7 +18361,7 @@ async function protectedSet(table, { run: run3, stateDir, agentDir, self }) {
18320
18361
  for (const p of table) if (baseName(p.comm) === "herdr") out.push({ pid: p.pid, started: p.started, why: "herdr" });
18321
18362
  for (const server of serverPids(stateDir)) out.push({ ...server, why: "sb-server", tree: true });
18322
18363
  try {
18323
- const pid = Number(readFileSync29(join41(agentDir, "intercom", "broker.pid"), "utf8").trim());
18364
+ const pid = Number(readFileSync30(join41(agentDir, "intercom", "broker.pid"), "utf8").trim());
18324
18365
  if (Number.isSafeInteger(pid) && pid > 1) out.push({ pid, why: "intercom-broker", tree: true });
18325
18366
  } catch {
18326
18367
  }
@@ -18533,7 +18574,7 @@ function createUnitStop(d) {
18533
18574
 
18534
18575
  // src/server/towers.ts
18535
18576
  import { createHash as createHash20 } from "node:crypto";
18536
- import { mkdirSync as mkdirSync15, readdirSync as readdirSync15, readFileSync as readFileSync36, rmSync as rmSync14 } from "node:fs";
18577
+ import { mkdirSync as mkdirSync15, readdirSync as readdirSync16, readFileSync as readFileSync37, rmSync as rmSync14 } from "node:fs";
18537
18578
  import { join as join53 } from "node:path";
18538
18579
 
18539
18580
  // src/closemain.ts
@@ -18658,11 +18699,11 @@ function createDigest(run3, now) {
18658
18699
 
18659
18700
  // src/opener.ts
18660
18701
  import { createHash as createHash16, randomUUID as randomUUID11 } from "node:crypto";
18661
- import { existsSync as existsSync8 } from "node:fs";
18702
+ import { existsSync as existsSync9 } from "node:fs";
18662
18703
  import { join as join44 } from "node:path";
18663
18704
 
18664
18705
  // src/integrator.ts
18665
- import { existsSync as existsSync7, readdirSync as readdirSync14 } from "node:fs";
18706
+ import { existsSync as existsSync8, readdirSync as readdirSync15 } from "node:fs";
18666
18707
  import { join as join43 } from "node:path";
18667
18708
  var INTEGRATOR = "integrator";
18668
18709
  var MAX_OPENED_INTEGRATORS = 2;
@@ -18674,7 +18715,7 @@ var integratorOf = (token) => {
18674
18715
  };
18675
18716
  function ledgerProjects(stateDir, app) {
18676
18717
  try {
18677
- return readdirSync14(join43(stateDir, "trains")).filter((project) => isName(project) && existsSync7(join43(stateDir, "trains", project, `${app}.json`)));
18718
+ return readdirSync15(join43(stateDir, "trains")).filter((project) => isName(project) && existsSync8(join43(stateDir, "trains", project, `${app}.json`)));
18678
18719
  } catch {
18679
18720
  return [];
18680
18721
  }
@@ -18807,7 +18848,7 @@ function opener(env) {
18807
18848
  const everywhere = await panes(run3);
18808
18849
  const codes = new Set(everywhere.flatMap((p) => ((t) => t && t.project === train.project ? [t.code] : [])(trainFromToken(p.tokens?.sb_train))));
18809
18850
  if (codes.has(train.code)) throw new OpenLimitError(`The ${trainLabel(train.code)} of project ${train.project} is already open; a code is used once`);
18810
- if (env.stateDir && existsSync8(join44(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`);
18851
+ if (env.stateDir && existsSync9(join44(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`);
18811
18852
  const max = (env.maxTrains ?? readMaxTrains)(dir);
18812
18853
  if (typeof max !== "number") throw new OpenLimitError(max.refusal);
18813
18854
  const config = (env.appsRefusal ?? openRefusal)(dir, appFromRequest(request));
@@ -18945,7 +18986,7 @@ import { randomUUID as randomUUID12 } from "node:crypto";
18945
18986
 
18946
18987
  // src/autostate.ts
18947
18988
  import { createHash as createHash18 } from "node:crypto";
18948
- import { readFileSync as readFileSync30 } from "node:fs";
18989
+ import { readFileSync as readFileSync31 } from "node:fs";
18949
18990
  import { join as join45 } from "node:path";
18950
18991
  var AUTO_FILE = "auto.json";
18951
18992
  var OWN_FILE = "auto-own.json";
@@ -18999,7 +19040,7 @@ function parseOwn(raw) {
18999
19040
  }
19000
19041
  var read3 = (dir, name2) => {
19001
19042
  try {
19002
- return readFileSync30(join45(dir, name2), "utf8");
19043
+ return readFileSync31(join45(dir, name2), "utf8");
19003
19044
  } catch {
19004
19045
  return void 0;
19005
19046
  }
@@ -19052,7 +19093,7 @@ var clock = (iso5) => {
19052
19093
  var REPORT_FILE = "auto-report.json";
19053
19094
  function reportSummary(dir) {
19054
19095
  try {
19055
- const r = JSON.parse(readFileSync30(join45(dir, REPORT_FILE), "utf8"));
19096
+ const r = JSON.parse(readFileSync31(join45(dir, REPORT_FILE), "utf8"));
19056
19097
  if (r.v !== 1 || typeof r.since !== "string" || typeof r.until !== "string" || !Array.isArray(r.parked) || !Array.isArray(r.lines)) return void 0;
19057
19098
  return { since: r.since, until: r.until, off: String(r.off ?? ""), parked: r.parked.length, towers: new Set(r.parked.map((p) => p.workspace)).size, cancels: r.lines.filter((l) => l.kind !== "re-asked").reduce((n, l) => n + (l.count ?? 1), 0), decided: r.decided?.length ?? 0, stillWaiting: r.stillWaiting?.length ?? 0 };
19058
19099
  } catch {
@@ -19435,7 +19476,7 @@ function createHead(d) {
19435
19476
  }
19436
19477
 
19437
19478
  // src/server/headasks.ts
19438
- import { readFileSync as readFileSync31 } from "node:fs";
19479
+ import { readFileSync as readFileSync32 } from "node:fs";
19439
19480
  import { join as join47 } from "node:path";
19440
19481
  var ASK_OPEN_MS = 24 * 36e5;
19441
19482
  var ASK_CAP = 40;
@@ -19459,7 +19500,7 @@ function clean5(a) {
19459
19500
  }
19460
19501
  function load(slot) {
19461
19502
  try {
19462
- const f = JSON.parse(readFileSync31(fileOf2(slot), "utf8"));
19503
+ const f = JSON.parse(readFileSync32(fileOf2(slot), "utf8"));
19463
19504
  const asks = Array.isArray(f.asks) ? f.asks.filter(valid2).map(clean5) : [];
19464
19505
  return { next: Number.isInteger(f.next) && f.next >= 1 ? f.next : 1 + Math.max(0, ...asks.map((a) => Number(a.id.slice(1)))), asks };
19465
19506
  } catch {
@@ -19754,7 +19795,7 @@ function headGate({ text: text10, senderWorkspace, isOpen: isOpen3 }) {
19754
19795
  }
19755
19796
 
19756
19797
  // src/server/towermemory.ts
19757
- import { readFileSync as readFileSync32 } from "node:fs";
19798
+ import { readFileSync as readFileSync33 } from "node:fs";
19758
19799
  import { join as join48 } from "node:path";
19759
19800
 
19760
19801
  // src/server/waitcard.ts
@@ -19957,7 +19998,7 @@ var isProposal = (e) => {
19957
19998
  function loadMemory(slot, workspace) {
19958
19999
  let text10;
19959
20000
  try {
19960
- text10 = readFileSync32(fileOf3(slot, workspace), "utf8");
20001
+ text10 = readFileSync33(fileOf3(slot, workspace), "utf8");
19961
20002
  } catch (cause) {
19962
20003
  return cause.code === "ENOENT" ? { memory: emptyMemory() } : { memory: emptyMemory(), problem: `memory.json cannot be read (${cause.code ?? "unknown"})` };
19963
20004
  }
@@ -20568,15 +20609,16 @@ var opt2 = (args, name2) => typeof args[name2] === "string" && args[name2] ? arg
20568
20609
  var json = (result2) => ({ text: JSON.stringify(result2, null, 2), details: result2 });
20569
20610
  var NO_HOLDER2 = /* @__PURE__ */ new Set(["no_holder", "no_link"]);
20570
20611
  var namedFor = /* @__PURE__ */ new Map();
20612
+ var restartWord = (host, at) => host.startedAt !== void 0 && at !== void 0 && at < host.startedAt ? ` The sb server started at ${new Date(host.startedAt).toISOString()}, after this slip came in, and keeps the door's answer in memory only: if the door named this slip's integrators before that, its answer is gone with the restart, so ask the door again the same way and forward then.` : "";
20571
20613
  var PEERS_SLIP = (name2, id) => `${clean(name2, 40)} (session ${id}) was opened for a teammate's device, so its slip is a peer's: it reaches the integrator through the ally run of its device, which marks it origin=remote and asks the boss below dispatch, and never through a local run. Forward nothing of it; it sends the slip again to the tower that opened it.`;
20572
20614
  async function forwardOf(host, args, to) {
20573
20615
  const id = opt2(args, "forward");
20574
20616
  if (id === void 0) return void 0;
20575
20617
  const event = host.forwardEvent?.(id);
20576
- if (!event) throw new Error(`forward ${id.slice(0, 40)} is no call_tower event (why=shared) that this run took: forward a car slip with the id its event header shows`);
20618
+ if (!event) throw new Error(`forward ${id.slice(0, 40)} is no call_tower event (why=shared) that this run took: forward a car slip with the id its event header shows. A slip's event is held only while the run that took it lives and for 24 h: ask its sender to send the slip to the tower again (call_tower why=shared) and forward the new event's id`);
20577
20619
  const net = await host.reach.read(), peers = (session) => deviceToken(net, session) !== void 0 || (host.openedAnywhere ?? host.openedFor)?.(session) !== void 0;
20578
20620
  if (peers(event.from)) throw new Error(PEERS_SLIP(event.from, event.from));
20579
- if (to !== void 0 && !namedFor.get(`${host.identity} ${event.id}`)?.includes(to)) throw new Error(`forward ${event.id} goes only to an integrator the door named for this slip: call boss_open_main with role "integrator", the slip as the request, and its sender, and forward to one of the sessions its answer names.`);
20621
+ if (to !== void 0 && !namedFor.get(`${host.identity} ${event.id}`)?.includes(to)) throw new Error(`forward ${event.id} goes only to an integrator the door named for this slip: call boss_open_main with role "integrator", the slip as the request, and its sender, and forward to one of the sessions its answer names.${restartWord(host, event.at)}`);
20580
20622
  if (to !== void 0 && peers(to)) throw new Error(`Session ${to} was opened for a teammate's device, so no slip is forwarded to it. The boss closes it or renames it.`);
20581
20623
  return { fwd: event.id, fwdFrom: event.from, body: bodyOf(event.text) };
20582
20624
  }
@@ -21048,11 +21090,11 @@ function createRevoker(d) {
21048
21090
 
21049
21091
  // src/server/runs.ts
21050
21092
  import { randomBytes as randomBytes19 } from "node:crypto";
21051
- import { lstatSync as lstatSync11, realpathSync as realpathSync10 } from "node:fs";
21093
+ import { lstatSync as lstatSync12, realpathSync as realpathSync11 } from "node:fs";
21052
21094
  import { basename as basename12, resolve as resolve9, sep as sep8 } from "node:path";
21053
21095
 
21054
21096
  // src/server/bossconv.ts
21055
- import { lstatSync as lstatSync10, readFileSync as readFileSync33, realpathSync as realpathSync9, rmSync as rmSync13 } from "node:fs";
21097
+ import { lstatSync as lstatSync11, readFileSync as readFileSync34, realpathSync as realpathSync10, rmSync as rmSync13 } from "node:fs";
21056
21098
  import { homedir as homedir13 } from "node:os";
21057
21099
  import { isAbsolute as isAbsolute9, join as join50, relative as relative5, resolve as resolve8, sep as sep7 } from "node:path";
21058
21100
  var BOSS_FILE_MAX = 4 * 1024 * 1024;
@@ -21060,7 +21102,7 @@ var BOSS_FILE_DAYS = 7;
21060
21102
  var pointerFile = (slot, workspace) => join50(towerDir(slot, workspace), "boss-session.json");
21061
21103
  function readPointer(slot, workspace) {
21062
21104
  try {
21063
- const p = JSON.parse(readFileSync33(pointerFile(slot, workspace), "utf8"));
21105
+ const p = JSON.parse(readFileSync34(pointerFile(slot, workspace), "utf8"));
21064
21106
  return typeof p.file === "string" && typeof p.run === "string" && typeof p.startedAt === "string" && typeof p.lastAt === "string" && Number.isFinite(Date.parse(p.lastAt)) && Number.isInteger(p.turns) && p.turns >= 0 ? { file: p.file, run: p.run, startedAt: p.startedAt, lastAt: p.lastAt, turns: p.turns, ...p.fresh === true ? { fresh: true } : {} } : void 0;
21065
21107
  } catch {
21066
21108
  return void 0;
@@ -21073,7 +21115,7 @@ function writePointer(slot, workspace, pointer) {
21073
21115
  var sessionsRoot = (env = process.env) => join50(env.PI_CODING_AGENT_DIR || join50(homedir13(), ".pi", "agent"), "sessions");
21074
21116
  var real2 = (path) => {
21075
21117
  try {
21076
- return realpathSync9(path);
21118
+ return realpathSync10(path);
21077
21119
  } catch {
21078
21120
  return void 0;
21079
21121
  }
@@ -21093,7 +21135,7 @@ function linkIn(file2, root) {
21093
21135
  for (const part3 of rel.split(sep7)) {
21094
21136
  at = join50(at, part3);
21095
21137
  try {
21096
- if (lstatSync10(at).isSymbolicLink()) return true;
21138
+ if (lstatSync11(at).isSymbolicLink()) return true;
21097
21139
  } catch {
21098
21140
  return false;
21099
21141
  }
@@ -21112,7 +21154,7 @@ function resumable(pointer, e) {
21112
21154
  if (!path) return { ok: false, why: "the last session file is gone, or not under pi's sessions folder" };
21113
21155
  let stat6;
21114
21156
  try {
21115
- stat6 = lstatSync10(path);
21157
+ stat6 = lstatSync11(path);
21116
21158
  } catch {
21117
21159
  return { ok: false, why: "the last session file is gone" };
21118
21160
  }
@@ -21214,7 +21256,7 @@ var readProcs = (platform = process.platform) => (runId) => {
21214
21256
  const { file: file2, args, options } = cimCommand(runId);
21215
21257
  execFile2(file2, args, options, (error, stdout) => done2(error ? void 0 : parseCim(String(stdout))));
21216
21258
  } else {
21217
- execFileExe("ps", ["-A", "-ww", "-o", "pid=,ppid=,lstart=,command="], { encoding: "utf8", timeout: 5e3, maxBuffer: 16 * 1024 * 1024, env: { ...process.env, LC_ALL: "C", TZ: "UTC" } }, (error, stdout) => done2(error ? void 0 : parsePs(String(stdout), runId)));
21259
+ execFileExe("ps", ["-A", "-ww", "-o", "pid=,ppid=,lstart=,command="], { encoding: "utf8", deadline: 5e3, maxBuffer: 16 * 1024 * 1024, env: { ...process.env, LC_ALL: "C", TZ: "UTC" } }, (error, stdout) => done2(error ? void 0 : parsePs(String(stdout), runId)));
21218
21260
  }
21219
21261
  } catch {
21220
21262
  done2(void 0);
@@ -21233,7 +21275,7 @@ var HEAD_ALLOWED = new Set(HEAD_RUN_TOOLS);
21233
21275
 
21234
21276
  // src/server/headchapters.ts
21235
21277
  import { open as open7 } from "node:fs/promises";
21236
- import { readFileSync as readFileSync34 } from "node:fs";
21278
+ import { readFileSync as readFileSync35 } from "node:fs";
21237
21279
  import { join as join51 } from "node:path";
21238
21280
  var HEAD_CHAPTER_MAX = 8 * 1024 * 1024;
21239
21281
  var KEEP3 = 50;
@@ -21243,7 +21285,7 @@ var TAIL_BYTES = 262144;
21243
21285
  var chaptersFile = (slot) => join51(towerDir(slot, HEAD_KEY), "chapters.json");
21244
21286
  function readChapters(slot) {
21245
21287
  try {
21246
- const list2 = JSON.parse(readFileSync34(chaptersFile(slot), "utf8"));
21288
+ const list2 = JSON.parse(readFileSync35(chaptersFile(slot), "utf8"));
21247
21289
  return Array.isArray(list2) ? list2.filter((c) => Number.isInteger(c?.n) && typeof c.file === "string" && typeof c.from === "string" && typeof c.why === "string") : [];
21248
21290
  } catch {
21249
21291
  return [];
@@ -21305,7 +21347,7 @@ var PROMPT_WAKE_MS = 5 * 6e4;
21305
21347
  var RUNS_SHOWN = 6;
21306
21348
  var onDisk = (file2) => {
21307
21349
  try {
21308
- lstatSync11(file2);
21350
+ lstatSync12(file2);
21309
21351
  return true;
21310
21352
  } catch {
21311
21353
  return false;
@@ -21315,7 +21357,7 @@ var mayAppear = (file2, root) => {
21315
21357
  if (!file2.endsWith(".jsonl")) return false;
21316
21358
  const abs = resolve9(file2), bases = [resolve9(root)];
21317
21359
  try {
21318
- bases.push(realpathSync10(root));
21360
+ bases.push(realpathSync11(root));
21319
21361
  } catch {
21320
21362
  }
21321
21363
  return bases.some((b) => abs.startsWith(b + sep8));
@@ -22776,7 +22818,7 @@ async function pressRequest(d, workspace, json3, via = "pi") {
22776
22818
 
22777
22819
  // src/server/towerseen.ts
22778
22820
  import { createHash as createHash19 } from "node:crypto";
22779
- import { appendFileSync as appendFileSync4, readFileSync as readFileSync35 } from "node:fs";
22821
+ import { appendFileSync as appendFileSync4, readFileSync as readFileSync36 } from "node:fs";
22780
22822
  import { join as join52 } from "node:path";
22781
22823
  var SEEN_KEEP_MS = 48 * 36e5;
22782
22824
  var SEEN_MAX = 5e3;
@@ -22799,7 +22841,7 @@ function openSeen(slot, workspace, now) {
22799
22841
  const rows = /* @__PURE__ */ new Map();
22800
22842
  let text10 = "", lines = 0;
22801
22843
  try {
22802
- text10 = readFileSync35(file2, "utf8");
22844
+ text10 = readFileSync36(file2, "utf8");
22803
22845
  } catch {
22804
22846
  }
22805
22847
  for (const line3 of text10.split("\n")) {
@@ -23410,7 +23452,7 @@ function createTowers(o) {
23410
23452
  const dir = join53(slot.stateDir, "roles");
23411
23453
  let names = [];
23412
23454
  try {
23413
- names = readdirSync15(dir).filter((name2) => name2.endsWith(".json"));
23455
+ names = readdirSync16(dir).filter((name2) => name2.endsWith(".json"));
23414
23456
  } catch {
23415
23457
  return;
23416
23458
  }
@@ -23418,7 +23460,7 @@ function createTowers(o) {
23418
23460
  for (const name2 of names) {
23419
23461
  let record2;
23420
23462
  try {
23421
- record2 = JSON.parse(readFileSync36(join53(dir, name2), "utf8"));
23463
+ record2 = JSON.parse(readFileSync37(join53(dir, name2), "utf8"));
23422
23464
  } catch {
23423
23465
  continue;
23424
23466
  }
@@ -23768,6 +23810,7 @@ function createTowers(o) {
23768
23810
  who: who2,
23769
23811
  identity: l.record.id,
23770
23812
  requests: l.requests,
23813
+ startedAt: o.startedAt,
23771
23814
  allow: (q) => o.allows ? o.allows.take({ pane: who2.pane, ...q, sessions: () => l.client.listSessions() }) : Promise.resolve({ ok: false, reason: "this server holds no Allows" }),
23772
23815
  allowRequest: (q) => o.allows ? o.allows.takeRequest({ pane: who2.pane, ...q, sessions: () => l.client.listSessions() }) : Promise.resolve({ ok: false, reason: "this server holds no Allows" }),
23773
23816
  asks: o.asks ?? { open: () => {
@@ -23777,7 +23820,7 @@ function createTowers(o) {
23777
23820
  forwardEvent: (id) => {
23778
23821
  const event = readQueue(slot, ws).find((e) => e.id === id && e.taken?.run === who2.id && e.kind === "intercom" && e.from);
23779
23822
  const fields = event && fieldsOf(event.text);
23780
- return event && fields?.kind === "call_tower" && fields.why === "shared" ? { id: event.id, from: event.from.id, text: event.text } : void 0;
23823
+ return event && fields?.kind === "call_tower" && fields.why === "shared" ? { id: event.id, from: event.from.id, text: event.text, at: Date.parse(event.at) } : void 0;
23781
23824
  },
23782
23825
  // A reply that settles a blocked call_tower this run took, while auto mode is on, is listed for the return list with the basis it names (autotower.ts `basisOf`) or `none`.
23783
23826
  decided: (to, gist, basis) => {
@@ -24039,7 +24082,7 @@ async function headCommand(t, cmd, text10, extra = {}) {
24039
24082
 
24040
24083
  // src/server/automode.ts
24041
24084
  import { randomBytes as randomBytes20 } from "node:crypto";
24042
- import { mkdirSync as mkdirSync16, readFileSync as readFileSync37, renameSync as renameSync8, writeFileSync as writeFileSync8 } from "node:fs";
24085
+ import { mkdirSync as mkdirSync16, readFileSync as readFileSync38, renameSync as renameSync8, writeFileSync as writeFileSync8 } from "node:fs";
24043
24086
  import { join as join54 } from "node:path";
24044
24087
  var PENDING_MS2 = 10 * 6e4;
24045
24088
  var USED_MAX = 500;
@@ -24056,7 +24099,7 @@ var gistOf = (v) => {
24056
24099
  };
24057
24100
  function readReportFile(dir) {
24058
24101
  try {
24059
- const j = JSON.parse(readFileSync37(join54(dir, REPORT_FILE), "utf8"));
24102
+ const j = JSON.parse(readFileSync38(join54(dir, REPORT_FILE), "utf8"));
24060
24103
  return j.v === 1 && typeof j.since === "string" && Array.isArray(j.parked) && Array.isArray(j.lines) ? j : void 0;
24061
24104
  } catch {
24062
24105
  return void 0;
@@ -24071,7 +24114,7 @@ function createAutoMode(d) {
24071
24114
  const listeners = /* @__PURE__ */ new Set();
24072
24115
  const readPeriod = () => {
24073
24116
  try {
24074
- const j = JSON.parse(readFileSync37(join54(d.dir, PERIOD_FILE), "utf8"));
24117
+ const j = JSON.parse(readFileSync38(join54(d.dir, PERIOD_FILE), "utf8"));
24075
24118
  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 : [] } : void 0;
24076
24119
  } catch {
24077
24120
  return void 0;
@@ -24407,7 +24450,7 @@ function createBackstop(d) {
24407
24450
  }
24408
24451
 
24409
24452
  // src/server/headnet.ts
24410
- import { closeSync as closeSync7, openSync as openSync7, readSync, statSync as statSync13 } from "node:fs";
24453
+ import { closeSync as closeSync8, openSync as openSync8, readSync, statSync as statSync13 } from "node:fs";
24411
24454
  var ASKS = 60;
24412
24455
  var TEXTS = 24e3;
24413
24456
  var TAIL4 = 65536;
@@ -24415,7 +24458,7 @@ var LINE = 160;
24415
24458
  function lastWords(file2) {
24416
24459
  let fd;
24417
24460
  try {
24418
- fd = openSync7(file2, "r");
24461
+ fd = openSync8(file2, "r");
24419
24462
  const { size: size2 } = statSync13(file2), start = Math.max(0, size2 - TAIL4), buf = Buffer.alloc(size2 - start);
24420
24463
  readSync(fd, buf, 0, buf.length, start);
24421
24464
  const rows = buf.toString("utf8").split("\n");
@@ -24429,7 +24472,7 @@ function lastWords(file2) {
24429
24472
  }
24430
24473
  } catch {
24431
24474
  } finally {
24432
- if (fd !== void 0) closeSync7(fd);
24475
+ if (fd !== void 0) closeSync8(fd);
24433
24476
  }
24434
24477
  return {};
24435
24478
  }
@@ -25062,7 +25105,7 @@ async function runServer(o) {
25062
25105
  if (read4.problem !== toldConfig) toldConfig = read4.problem ?? "", read4.problem && recordError("config", read4.problem);
25063
25106
  return read4;
25064
25107
  };
25065
- cars = startCars({ slot, run: cfg.run, now, client: () => client?.isConnected() ? client : void 0, startOf: startOf2, log: (event, facts2) => log.line(event, facts2), stops });
25108
+ cars = startCars({ slot, run: cfg.run, now, startedAt, client: () => client?.isConnected() ? client : void 0, startOf: startOf2, log: (event, facts2) => log.line(event, facts2), stops });
25066
25109
  towers = createTowers({
25067
25110
  ally: allyPort(() => link),
25068
25111
  allows,