sphica 0.6.52 → 0.6.53

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.
@@ -46770,8 +46770,49 @@ async function authorityOf(db, ids, asOf) {
46770
46770
 
46771
46771
  // server/src/capture.ts
46772
46772
  import { spawn as spawn2 } from "node:child_process";
46773
- import fs7 from "node:fs";
46774
- import path7 from "node:path";
46773
+ import fs9 from "node:fs";
46774
+ import path9 from "node:path";
46775
+
46776
+ // server/src/codex-log.ts
46777
+ import fs4 from "node:fs";
46778
+ import path4 from "node:path";
46779
+ var SESSION_META_BYTES = 256 * 1024;
46780
+ var text3 = (v) => typeof v === "string" ? v : null;
46781
+ function codexThread(input2) {
46782
+ const file2 = input2.transcript_path;
46783
+ if (typeof file2 !== "string" || !path4.isAbsolute(file2))
46784
+ return null;
46785
+ let fd;
46786
+ try {
46787
+ if (!fs4.lstatSync(file2).isFile())
46788
+ return null;
46789
+ fd = fs4.openSync(file2, "r");
46790
+ const buffer = Buffer.alloc(SESSION_META_BYTES);
46791
+ const read = fs4.readSync(fd, buffer, 0, SESSION_META_BYTES, 0);
46792
+ const end = buffer.subarray(0, read).indexOf(10);
46793
+ if (end < 0)
46794
+ return null;
46795
+ const line = JSON.parse(buffer.subarray(0, end).toString("utf8"));
46796
+ const payload = line?.payload;
46797
+ if (line?.type !== "session_meta" || !payload || typeof payload !== "object" || Array.isArray(payload))
46798
+ return null;
46799
+ const source = payload.source;
46800
+ return {
46801
+ id: text3(payload.id),
46802
+ originator: text3(payload.originator),
46803
+ threadSource: text3(payload.thread_source),
46804
+ parent: text3(payload.parent_thread_id),
46805
+ subagent: source && typeof source === "object" ? text3(source.subagent) : null
46806
+ };
46807
+ } catch {
46808
+ return null;
46809
+ } finally {
46810
+ if (fd !== undefined)
46811
+ fs4.closeSync(fd);
46812
+ }
46813
+ }
46814
+ var ownThread = (input2, thread) => Boolean(input2.session_id) && thread?.id === input2.session_id && thread?.threadSource === "user";
46815
+ var childThread = (input2, thread) => input2.session_id && thread?.threadSource === "subagent" && thread.parent === input2.session_id && thread.id !== null && thread.id !== input2.session_id && /^[\x21-\x7e]{1,200}$/.test(thread.id) ? thread.id : null;
46775
46816
 
46776
46817
  // server/src/knowledge.ts
46777
46818
  var UNIT_KINDS = [
@@ -46798,25 +46839,47 @@ var FIELD_TYPES = ["text", "enum", "integer", "date"];
46798
46839
  var HOSTS = ["claude-code", "codex"];
46799
46840
  var sessionId = (projectId, host, externalId) => uuidFrom(String(projectId), host, externalId);
46800
46841
 
46801
- // server/src/project.ts
46842
+ // server/src/once.ts
46802
46843
  import fs5 from "node:fs";
46844
+ import os3 from "node:os";
46803
46845
  import path5 from "node:path";
46846
+ function markOnce(kind, key) {
46847
+ const user = (() => {
46848
+ try {
46849
+ return os3.userInfo().username;
46850
+ } catch {
46851
+ return String(process.getuid?.() ?? "user");
46852
+ }
46853
+ })();
46854
+ const dir = path5.join(os3.tmpdir(), `sphica-${sha256(user).toString("hex").slice(0, 12)}`, kind);
46855
+ try {
46856
+ fs5.mkdirSync(dir, { recursive: true, mode: 448 });
46857
+ fs5.writeFileSync(path5.join(dir, sha256(key).toString("hex").slice(0, 24)), "", { flag: "wx" });
46858
+ return true;
46859
+ } catch (e) {
46860
+ return e.code !== "EEXIST";
46861
+ }
46862
+ }
46863
+
46864
+ // server/src/project.ts
46865
+ import fs7 from "node:fs";
46866
+ import path7 from "node:path";
46804
46867
  import { fileURLToPath as fileURLToPath2 } from "node:url";
46805
46868
 
46806
46869
  // server/src/anchors.ts
46807
46870
  import crypto2 from "node:crypto";
46808
- import fs4 from "node:fs";
46809
- import path4 from "node:path";
46871
+ import fs6 from "node:fs";
46872
+ import path6 from "node:path";
46810
46873
  var MAX_BYTES = 2 * 1024 * 1024;
46811
- var leaves = (rel) => rel === ".." || rel.startsWith(`..${path4.sep}`) || path4.isAbsolute(rel);
46874
+ var leaves = (rel) => rel === ".." || rel.startsWith(`..${path6.sep}`) || path6.isAbsolute(rel);
46812
46875
  var literal3 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
46813
46876
  function readBytes(root, rel) {
46814
- const abs = path4.join(root, rel);
46815
- if (leaves(path4.relative(root, abs)))
46877
+ const abs = path6.join(root, rel);
46878
+ if (leaves(path6.relative(root, abs)))
46816
46879
  return;
46817
46880
  let st;
46818
46881
  try {
46819
- st = fs4.lstatSync(abs, { throwIfNoEntry: false });
46882
+ st = fs6.lstatSync(abs, { throwIfNoEntry: false });
46820
46883
  } catch (e) {
46821
46884
  return e.code === "ENOTDIR" ? null : undefined;
46822
46885
  }
@@ -46825,10 +46888,10 @@ function readBytes(root, rel) {
46825
46888
  if (!st.isFile() || st.size > MAX_BYTES)
46826
46889
  return;
46827
46890
  try {
46828
- const inside = path4.relative(fs4.realpathSync(root), fs4.realpathSync(abs));
46891
+ const inside = path6.relative(fs6.realpathSync(root), fs6.realpathSync(abs));
46829
46892
  if (leaves(inside))
46830
46893
  return;
46831
- const buf = fs4.readFileSync(abs);
46894
+ const buf = fs6.readFileSync(abs);
46832
46895
  return buf.includes(0) ? undefined : buf;
46833
46896
  } catch {
46834
46897
  return;
@@ -46840,25 +46903,25 @@ function readRepoText(root, rel) {
46840
46903
  return { text: buf, hash: buf === null ? "absent" : "unreadable" };
46841
46904
  return { text: buf.toString("utf8"), hash: crypto2.createHash("sha256").update(buf).digest("hex") };
46842
46905
  }
46843
- function findSymbol(text3, symbol2) {
46906
+ function findSymbol(text4, symbol2) {
46844
46907
  const re = new RegExp(`(?<![\\w$])${literal3(symbol2)}(?![\\w$])`);
46845
- const lines = text3.split(/\r?\n/);
46908
+ const lines = text4.split(/\r?\n/);
46846
46909
  return { lines, i: lines.findIndex((l) => re.test(l)) };
46847
46910
  }
46848
- function swallowed(text3, symbol2) {
46911
+ function swallowed(text4, symbol2) {
46849
46912
  if (mask(symbol2) !== symbol2)
46850
46913
  return true;
46851
- if (text3 === undefined)
46914
+ if (text4 === undefined)
46852
46915
  return true;
46853
- if (text3 === null)
46916
+ if (text4 === null)
46854
46917
  return false;
46855
46918
  const re = new RegExp(`(?<![\\w$])${literal3(symbol2)}(?![\\w$])`, "g");
46856
46919
  let raw = 0;
46857
- for (let m = re.exec(text3);m; m = re.exec(text3))
46920
+ for (let m = re.exec(text4);m; m = re.exec(text4))
46858
46921
  raw++;
46859
46922
  if (raw === 0)
46860
46923
  return false;
46861
- const masked = mask(text3);
46924
+ const masked = mask(text4);
46862
46925
  const holes = placeholderRanges(masked);
46863
46926
  let h = 0;
46864
46927
  let kept = 0;
@@ -46871,14 +46934,14 @@ function swallowed(text3, symbol2) {
46871
46934
  }
46872
46935
  return kept !== raw;
46873
46936
  }
46874
- function masksSymbolIn(text3, symbol2) {
46937
+ function masksSymbolIn(text4, symbol2) {
46875
46938
  const trimmed = symbol2.trim();
46876
- return swallowed(text3, symbol2) || trimmed !== symbol2 && trimmed !== "" && swallowed(text3, trimmed);
46939
+ return swallowed(text4, symbol2) || trimmed !== symbol2 && trimmed !== "" && swallowed(text4, trimmed);
46877
46940
  }
46878
- function locateIn(text3, symbol2) {
46879
- if (typeof text3 !== "string")
46941
+ function locateIn(text4, symbol2) {
46942
+ if (typeof text4 !== "string")
46880
46943
  return null;
46881
- const { lines, i } = findSymbol(text3, symbol2);
46944
+ const { lines, i } = findSymbol(text4, symbol2);
46882
46945
  if (i < 0)
46883
46946
  return null;
46884
46947
  const line = lines[i] ?? "";
@@ -46898,20 +46961,20 @@ ${l}`).join("");
46898
46961
  function fileState(root, rel) {
46899
46962
  if (!root)
46900
46963
  return "unknown";
46901
- if (leaves(path4.relative(root, path4.join(root, rel))))
46964
+ if (leaves(path6.relative(root, path6.join(root, rel))))
46902
46965
  return "unknown";
46903
46966
  let realRoot;
46904
46967
  try {
46905
- realRoot = fs4.realpathSync(root);
46968
+ realRoot = fs6.realpathSync(root);
46906
46969
  } catch {
46907
46970
  return "unknown";
46908
46971
  }
46909
46972
  let at = root;
46910
46973
  for (const part of rel.split("/")) {
46911
- at = path4.join(at, part);
46974
+ at = path6.join(at, part);
46912
46975
  let st;
46913
46976
  try {
46914
- st = fs4.lstatSync(at, { throwIfNoEntry: false });
46977
+ st = fs6.lstatSync(at, { throwIfNoEntry: false });
46915
46978
  } catch (e) {
46916
46979
  if (e.code === "ENOTDIR")
46917
46980
  return "gone";
@@ -46921,7 +46984,7 @@ function fileState(root, rel) {
46921
46984
  return "gone";
46922
46985
  if (st.isSymbolicLink()) {
46923
46986
  try {
46924
- if (leaves(path4.relative(realRoot, fs4.realpathSync(at))))
46987
+ if (leaves(path6.relative(realRoot, fs6.realpathSync(at))))
46925
46988
  return "unknown";
46926
46989
  } catch {
46927
46990
  return "unknown";
@@ -46935,7 +46998,7 @@ function pathKind(root, rel) {
46935
46998
  if (state !== "present" || !root)
46936
46999
  return state === "gone" ? "gone" : "unknown";
46937
47000
  try {
46938
- const st = fs4.statSync(path4.join(root, rel));
47001
+ const st = fs6.statSync(path6.join(root, rel));
46939
47002
  return st.isFile() ? "file" : st.isDirectory() ? "directory" : "unknown";
46940
47003
  } catch {
46941
47004
  return "unknown";
@@ -46943,7 +47006,7 @@ function pathKind(root, rel) {
46943
47006
  }
46944
47007
 
46945
47008
  // server/src/project.ts
46946
- var localFile = () => path5.join(sphicaHome(), "projects.json");
47009
+ var localFile = () => path7.join(sphicaHome(), "projects.json");
46947
47010
  var LOCAL_KEY = /^[a-z0-9][a-z0-9._-]*$/;
46948
47011
  function legacyRemote(url2) {
46949
47012
  const raw = String(url2 ?? "").trim();
@@ -46982,7 +47045,7 @@ var top = (dir) => ask(() => topLevel(dir, { timeout: 5000 }));
46982
47045
  function localMap() {
46983
47046
  let raw;
46984
47047
  try {
46985
- raw = fs5.readFileSync(localFile(), "utf8");
47048
+ raw = fs7.readFileSync(localFile(), "utf8");
46986
47049
  } catch (e) {
46987
47050
  if (e.code === "ENOENT")
46988
47051
  return {};
@@ -46994,12 +47057,12 @@ function localMap() {
46994
47057
  } catch {
46995
47058
  m = null;
46996
47059
  }
46997
- if (!m || typeof m !== "object" || Array.isArray(m) || Object.entries(m).some(([root, name]) => !path5.isAbsolute(root) || typeof name !== "string" || !LOCAL_KEY.test(name)))
47060
+ if (!m || typeof m !== "object" || Array.isArray(m) || Object.entries(m).some(([root, name]) => !path7.isAbsolute(root) || typeof name !== "string" || !LOCAL_KEY.test(name)))
46998
47061
  throw new Error(`${localFile()} is not a valid JSON project table. Fix or delete it, then name the project again.`);
46999
47062
  return m;
47000
47063
  }
47001
47064
  function identify(dir) {
47002
- const given = path5.resolve(dir);
47065
+ const given = path7.resolve(dir);
47003
47066
  const found = top(given);
47004
47067
  const root = found || given;
47005
47068
  const legacy = found ? legacyRemote(ask(() => originUrl(root, { timeout: 5000 }))) : null;
@@ -47009,11 +47072,11 @@ function identify(dir) {
47009
47072
  return { key, legacyKey: `git:${legacy}`, root, name: remote.split("/").slice(1).join("/") || remote };
47010
47073
  }
47011
47074
  const map3 = localMap();
47012
- for (let d = root;; d = path5.dirname(d)) {
47075
+ for (let d = root;; d = path7.dirname(d)) {
47013
47076
  const local = map3[d];
47014
47077
  if (local && LOCAL_KEY.test(local))
47015
47078
  return { key: `local:${local}`, legacyKey: `local:${local}`, root: d, name: local };
47016
- if (found || path5.dirname(d) === d)
47079
+ if (found || path7.dirname(d) === d)
47017
47080
  return null;
47018
47081
  }
47019
47082
  }
@@ -47042,11 +47105,11 @@ async function projectId(db, key) {
47042
47105
  return r?.id ?? null;
47043
47106
  }
47044
47107
  function relativeTo(root, file2, cwd = root) {
47045
- const abs = path5.resolve(cwd, file2);
47046
- const rel = path5.relative(root, abs);
47108
+ const abs = path7.resolve(cwd, file2);
47109
+ const rel = path7.relative(root, abs);
47047
47110
  if (!rel || leaves(rel) || /\p{Cc}/u.test(rel))
47048
47111
  return null;
47049
- return rel.split(path5.sep).join("/");
47112
+ return rel.split(path7.sep).join("/");
47050
47113
  }
47051
47114
  function patchPaths(patch) {
47052
47115
  const out = [];
@@ -47060,8 +47123,8 @@ function patchPaths(patch) {
47060
47123
  }
47061
47124
 
47062
47125
  // server/src/worktree.ts
47063
- import fs6 from "node:fs";
47064
- import path6 from "node:path";
47126
+ import fs8 from "node:fs";
47127
+ import path8 from "node:path";
47065
47128
  var MAX_PATHS = 200;
47066
47129
  var LIMITS = { timeout: 5000, max: 16 * 1024 * 1024 };
47067
47130
  var STATUS_DEADLINE = 5000;
@@ -47086,7 +47149,7 @@ async function snapshot(root) {
47086
47149
  continue;
47087
47150
  let st;
47088
47151
  try {
47089
- st = fs6.lstatSync(path6.join(root, p), { throwIfNoEntry: false });
47152
+ st = fs8.lstatSync(path8.join(root, p), { throwIfNoEntry: false });
47090
47153
  } catch {
47091
47154
  st = undefined;
47092
47155
  }
@@ -47118,15 +47181,15 @@ function changed(root, before, after) {
47118
47181
  }
47119
47182
 
47120
47183
  // server/src/capture.ts
47121
- var spoolDir = () => path7.join(sphicaHome(), "spool");
47122
- var stateFile = () => path7.join(sphicaHome(), "capture.json");
47123
- var rejectedDir = () => path7.join(spoolDir(), "rejected");
47124
- var unregisteredDir = () => path7.join(spoolDir(), "unregistered");
47125
- var callsDir = () => path7.join(spoolDir(), "calls");
47126
- var callsRejectedDir = () => path7.join(callsDir(), "rejected");
47184
+ var spoolDir = () => path9.join(sphicaHome(), "spool");
47185
+ var stateFile = () => path9.join(sphicaHome(), "capture.json");
47186
+ var rejectedDir = () => path9.join(spoolDir(), "rejected");
47187
+ var unregisteredDir = () => path9.join(spoolDir(), "unregistered");
47188
+ var callsDir = () => path9.join(spoolDir(), "calls");
47189
+ var callsRejectedDir = () => path9.join(callsDir(), "rejected");
47127
47190
  var HOLD_DAYS = 30;
47128
47191
  var HOLD_MAX = 1000;
47129
- var baselineDir = () => path7.join(sphicaHome(), "worktree");
47192
+ var baselineDir = () => path9.join(sphicaHome(), "worktree");
47130
47193
  function current(raw) {
47131
47194
  const r = raw;
47132
47195
  if (typeof r.project !== "string")
@@ -47175,7 +47238,7 @@ ${z2}`,
47175
47238
  function prune(held, removed = () => {}) {
47176
47239
  let files;
47177
47240
  try {
47178
- files = fs7.readdirSync(held).filter((f) => f.endsWith(".json") && !f.startsWith(".")).sort();
47241
+ files = fs9.readdirSync(held).filter((f) => f.endsWith(".json") && !f.startsWith(".")).sort();
47179
47242
  } catch {
47180
47243
  return;
47181
47244
  }
@@ -47183,26 +47246,26 @@ function prune(held, removed = () => {}) {
47183
47246
  const stale = files.filter((f) => Number(f.split("-")[0]) < cutoff);
47184
47247
  const over = files.slice(0, Math.max(0, files.length - HOLD_MAX));
47185
47248
  for (const f of new Set([...stale, ...over])) {
47186
- fs7.rmSync(path7.join(held, f), { force: true });
47249
+ fs9.rmSync(path9.join(held, f), { force: true });
47187
47250
  removed();
47188
47251
  }
47189
47252
  }
47190
47253
  function put(dir, record4) {
47191
- fs7.mkdirSync(dir, { recursive: true, mode: 448 });
47254
+ fs9.mkdirSync(dir, { recursive: true, mode: 448 });
47192
47255
  const name = `${Date.now()}-${process.pid}-${Math.random().toString(36).slice(2, 10)}.json`;
47193
- const tmp = path7.join(dir, `.${name}`);
47194
- fs7.writeFileSync(tmp, JSON.stringify(record4), { mode: 384 });
47195
- fs7.renameSync(tmp, path7.join(dir, name));
47196
- return path7.join(dir, name);
47256
+ const tmp = path9.join(dir, `.${name}`);
47257
+ fs9.writeFileSync(tmp, JSON.stringify(record4), { mode: 384 });
47258
+ fs9.renameSync(tmp, path9.join(dir, name));
47259
+ return path9.join(dir, name);
47197
47260
  }
47198
47261
  function spool(record4) {
47199
47262
  put(spoolDir(), record4);
47200
47263
  }
47201
47264
  var branchOf = (root) => {
47202
47265
  try {
47203
- const dotgit = path7.join(root, ".git");
47204
- const gitdir = fs7.statSync(dotgit).isFile() ? path7.resolve(root, fs7.readFileSync(dotgit, "utf8").match(/^gitdir: (.+)$/m)?.[1]?.trim() ?? "") : dotgit;
47205
- const h = fs7.readFileSync(path7.join(gitdir, "HEAD"), "utf8").trim();
47266
+ const dotgit = path9.join(root, ".git");
47267
+ const gitdir = fs9.statSync(dotgit).isFile() ? path9.resolve(root, fs9.readFileSync(dotgit, "utf8").match(/^gitdir: (.+)$/m)?.[1]?.trim() ?? "") : dotgit;
47268
+ const h = fs9.readFileSync(path9.join(gitdir, "HEAD"), "utf8").trim();
47206
47269
  return h.startsWith("ref: refs/heads/") ? h.slice("ref: refs/heads/".length) : null;
47207
47270
  } catch {
47208
47271
  return null;
@@ -47248,7 +47311,7 @@ Notes: ${notes.trim()}` : "";
47248
47311
  };
47249
47312
  }
47250
47313
  function captureNotice(file2 = dbFile()) {
47251
- if (!fs7.existsSync(file2))
47314
+ if (!fs9.existsSync(file2))
47252
47315
  return panel("sphica: no database, so conversations are not recorded", [file2], "Create it with sphica init");
47253
47316
  const s = readState();
47254
47317
  if (s.unreadable)
@@ -47259,15 +47322,15 @@ function captureNotice(file2 = dbFile()) {
47259
47322
  return panel(`sphica: the database rejected ${plural2(s.rejected, "record")}`, [rejectedDir(), `Move them back to ${spoolDir()} to resend`], "Fix them first, then check with sphica doctor");
47260
47323
  return null;
47261
47324
  }
47262
- var turnDir = (host, session) => path7.join(baselineDir(), digest(`${host}\x00${session}`));
47263
- var startFile = (dir, turn) => path7.join(dir, `${digest(turn)}.json`);
47325
+ var turnDir = (host, session) => path9.join(baselineDir(), digest(`${host}\x00${session}`));
47326
+ var startFile = (dir, turn) => path9.join(dir, `${digest(turn)}.json`);
47264
47327
  var isStart = (v) => {
47265
47328
  const s = v;
47266
47329
  return !!s && typeof s === "object" && typeof s.turn === "string" && typeof s.running === "boolean" && (s.seq === null || Number.isSafeInteger(s.seq)) && (s.entries === null || typeof s.entries === "object" && !Array.isArray(s.entries)) && (s.head === null || typeof s.head === "string");
47267
47330
  };
47268
47331
  function readStart(file2) {
47269
47332
  try {
47270
- const s = JSON.parse(fs7.readFileSync(file2, "utf8"));
47333
+ const s = JSON.parse(fs9.readFileSync(file2, "utf8"));
47271
47334
  return isStart(s) ? s : null;
47272
47335
  } catch {
47273
47336
  return null;
@@ -47276,7 +47339,7 @@ function readStart(file2) {
47276
47339
  function readStarts(dir) {
47277
47340
  let names;
47278
47341
  try {
47279
- names = fs7.readdirSync(dir);
47342
+ names = fs9.readdirSync(dir);
47280
47343
  } catch (e) {
47281
47344
  return e.code === "ENOENT" ? [] : null;
47282
47345
  }
@@ -47284,7 +47347,7 @@ function readStarts(dir) {
47284
47347
  for (const name of names) {
47285
47348
  if (name.startsWith("."))
47286
47349
  continue;
47287
- const s = readStart(path7.join(dir, name));
47350
+ const s = readStart(path9.join(dir, name));
47288
47351
  if (!s)
47289
47352
  return null;
47290
47353
  starts2.push(s);
@@ -47299,10 +47362,10 @@ function newestTurn(starts2) {
47299
47362
  return at.length === 1 ? at[0]?.turn ?? null : null;
47300
47363
  }
47301
47364
  function writeStart(dir, s, file2 = startFile(dir, s.turn)) {
47302
- fs7.mkdirSync(dir, { recursive: true, mode: 448 });
47303
- const tmp = path7.join(dir, `.${path7.basename(file2)}.${process.pid}.tmp`);
47304
- fs7.writeFileSync(tmp, JSON.stringify(s), { mode: 384 });
47305
- fs7.renameSync(tmp, file2);
47365
+ fs9.mkdirSync(dir, { recursive: true, mode: 448 });
47366
+ const tmp = path9.join(dir, `.${path9.basename(file2)}.${process.pid}.tmp`);
47367
+ fs9.writeFileSync(tmp, JSON.stringify(s), { mode: 384 });
47368
+ fs9.renameSync(tmp, file2);
47306
47369
  }
47307
47370
  async function openTurn(dir, turn, root) {
47308
47371
  if (readStart(startFile(dir, turn))?.running)
@@ -47332,22 +47395,22 @@ function stopTurn(dir, turn) {
47332
47395
  }
47333
47396
  function pruneBaselines() {
47334
47397
  const cutoff = Date.now() - HOLD_DAYS * 24 * 60 * 60 * 1000;
47335
- const fresh = (file2) => (fs7.statSync(file2, { throwIfNoEntry: false })?.mtimeMs ?? Date.now()) >= cutoff;
47398
+ const fresh = (file2) => (fs9.statSync(file2, { throwIfNoEntry: false })?.mtimeMs ?? Date.now()) >= cutoff;
47336
47399
  let names;
47337
47400
  try {
47338
- names = fs7.readdirSync(baselineDir());
47401
+ names = fs9.readdirSync(baselineDir());
47339
47402
  } catch {
47340
47403
  return;
47341
47404
  }
47342
47405
  for (const name of names) {
47343
- const at = path7.join(baselineDir(), name);
47344
- if (!fs7.statSync(at, { throwIfNoEntry: false })?.isDirectory()) {
47406
+ const at = path9.join(baselineDir(), name);
47407
+ if (!fs9.statSync(at, { throwIfNoEntry: false })?.isDirectory()) {
47345
47408
  if (!fresh(at))
47346
- fs7.rmSync(at, { force: true });
47409
+ fs9.rmSync(at, { force: true });
47347
47410
  } else {
47348
- const files = fs7.readdirSync(at);
47349
- if (files.length && !files.some((f) => fresh(path7.join(at, f))))
47350
- fs7.rmSync(at, { recursive: true, force: true });
47411
+ const files = fs9.readdirSync(at);
47412
+ if (files.length && !files.some((f) => fresh(path9.join(at, f))))
47413
+ fs9.rmSync(at, { recursive: true, force: true });
47351
47414
  }
47352
47415
  }
47353
47416
  }
@@ -47365,22 +47428,36 @@ async function attemptAsync(fn) {
47365
47428
  return;
47366
47429
  }
47367
47430
  }
47431
+ function whoseTurn(host, input2) {
47432
+ if (!isOwnerTurn(input2, undefined, undefined, host === "codex" ? process.env.CODEX_THREAD_ID : undefined))
47433
+ return "other";
47434
+ if (host !== "codex")
47435
+ return "owner";
47436
+ const thread = codexThread(input2);
47437
+ if (ownThread(input2, thread))
47438
+ return "owner";
47439
+ return childThread(input2, thread) === null ? "unconfirmed" : "other";
47440
+ }
47441
+ var unconfirmed = (input2) => !markOnce("unconfirmed", `codex\x00${input2.session_id}`) ? null : typeof input2.transcript_path === "string" ? panel("sphica: this Codex session is not recorded", ["Its session log does not show that these messages are yours"], "Update Sphica and Codex; if it stays, report it") : panel("sphica: this Codex session is not recorded", [
47442
+ "Codex named no session log (as with --ephemeral), so Sphica cannot confirm these messages are yours"
47443
+ ], "To record a session, start Codex without --ephemeral");
47368
47444
  async function onHook(host, input2) {
47369
47445
  const event = input2.hook_event_name;
47370
- const owner = () => isOwnerTurn(input2, undefined, undefined, host === "codex" ? process.env.CODEX_THREAD_ID : undefined);
47446
+ const whose = whoseTurn(host, input2);
47447
+ if (whose !== "owner")
47448
+ return {
47449
+ flush: false,
47450
+ notice: whose === "unconfirmed" && event === "UserPromptSubmit" ? unconfirmed(input2) : null
47451
+ };
47371
47452
  if (event === "SessionStart") {
47372
- if (!owner())
47373
- return { flush: false };
47374
47453
  const file2 = process.env.CLAUDE_ENV_FILE;
47375
47454
  if (file2 && input2.session_id && /^[A-Za-z0-9_-]+$/.test(input2.session_id)) {
47376
- fs7.appendFileSync(file2, `export SPHICA_PARENT_SESSION=${input2.session_id}
47455
+ fs9.appendFileSync(file2, `export SPHICA_PARENT_SESSION=${input2.session_id}
47377
47456
  `);
47378
47457
  }
47379
47458
  attempt(pruneBaselines);
47380
47459
  return { flush: false, notice: captureNotice() };
47381
47460
  }
47382
- if (!owner())
47383
- return { flush: false };
47384
47461
  if (event === "Interrupt") {
47385
47462
  const turn2 = input2.prompt_id ?? input2.turn_id;
47386
47463
  if (turn2)
@@ -47456,7 +47533,7 @@ async function onHook(host, input2) {
47456
47533
  function readStateFile() {
47457
47534
  let raw = {};
47458
47535
  try {
47459
- const parsed = JSON.parse(fs7.readFileSync(stateFile(), "utf8"));
47536
+ const parsed = JSON.parse(fs9.readFileSync(stateFile(), "utf8"));
47460
47537
  if (parsed && typeof parsed === "object")
47461
47538
  raw = parsed;
47462
47539
  } catch {}
@@ -47470,7 +47547,7 @@ function readStateFile() {
47470
47547
  }
47471
47548
  function writeState(s) {
47472
47549
  try {
47473
- fs7.writeFileSync(stateFile(), JSON.stringify({ ...s, pruned: s.pruned ?? readStateFile().pruned }));
47550
+ fs9.writeFileSync(stateFile(), JSON.stringify({ ...s, pruned: s.pruned ?? readStateFile().pruned }));
47474
47551
  } catch {}
47475
47552
  }
47476
47553
  function readState() {
@@ -47486,7 +47563,7 @@ function readState() {
47486
47563
  }
47487
47564
  function listQueue(dir) {
47488
47565
  try {
47489
- const names = fs7.readdirSync(dir);
47566
+ const names = fs9.readdirSync(dir);
47490
47567
  return {
47491
47568
  files: names.filter((f) => f.endsWith(".json") && !f.startsWith(".")),
47492
47569
  temp: names.filter((f) => f.endsWith(".json") && f.startsWith(".")),
@@ -47498,25 +47575,25 @@ function listQueue(dir) {
47498
47575
  }
47499
47576
  }
47500
47577
  function lock() {
47501
- const file2 = path7.join(spoolDir(), ".lock");
47502
- fs7.mkdirSync(spoolDir(), { recursive: true, mode: 448 });
47578
+ const file2 = path9.join(spoolDir(), ".lock");
47579
+ fs9.mkdirSync(spoolDir(), { recursive: true, mode: 448 });
47503
47580
  for (let attempt2 = 0;attempt2 < 2; attempt2++) {
47504
47581
  try {
47505
- fs7.writeFileSync(file2, String(process.pid), { flag: "wx", mode: 384 });
47582
+ fs9.writeFileSync(file2, String(process.pid), { flag: "wx", mode: 384 });
47506
47583
  return () => {
47507
47584
  try {
47508
- if (fs7.readFileSync(file2, "utf8") === String(process.pid))
47509
- fs7.rmSync(file2, { force: true });
47585
+ if (fs9.readFileSync(file2, "utf8") === String(process.pid))
47586
+ fs9.rmSync(file2, { force: true });
47510
47587
  } catch {}
47511
47588
  };
47512
47589
  } catch (e) {
47513
47590
  if (e.code !== "EEXIST")
47514
47591
  throw e;
47515
47592
  }
47516
- const st = fs7.statSync(file2, { throwIfNoEntry: false });
47593
+ const st = fs9.statSync(file2, { throwIfNoEntry: false });
47517
47594
  if (!st)
47518
47595
  continue;
47519
- const holder = Number(fs7.readFileSync(file2, "utf8") || 0);
47596
+ const holder = Number(fs9.readFileSync(file2, "utf8") || 0);
47520
47597
  const fresh = Date.now() - st.mtimeMs < 5 * 60000;
47521
47598
  const alive = (() => {
47522
47599
  if (holder <= 0)
@@ -47529,7 +47606,7 @@ function lock() {
47529
47606
  })();
47530
47607
  if (alive && fresh)
47531
47608
  return null;
47532
- fs7.rmSync(file2, { force: true });
47609
+ fs9.rmSync(file2, { force: true });
47533
47610
  }
47534
47611
  return null;
47535
47612
  }
@@ -47629,23 +47706,23 @@ var REJECTED = new Set([18, 19, 20, 25]);
47629
47706
  var rejected = (e) => REJECTED.has(sqliteCode(e) ?? -1);
47630
47707
  var queued = (from) => {
47631
47708
  try {
47632
- return fs7.readdirSync(from).filter((f) => f.endsWith(".json") && !f.startsWith(".")).sort().map((name) => ({ name, from }));
47709
+ return fs9.readdirSync(from).filter((f) => f.endsWith(".json") && !f.startsWith(".")).sort().map((name) => ({ name, from }));
47633
47710
  } catch {
47634
47711
  return [];
47635
47712
  }
47636
47713
  };
47637
47714
  var CODE_NAMES = { 18: "TOOBIG", 19: "CONSTRAINT", 20: "MISMATCH", 25: "RANGE" };
47638
47715
  function setAside(from, name, dir, reason2) {
47639
- fs7.mkdirSync(dir, { recursive: true, mode: 448 });
47716
+ fs9.mkdirSync(dir, { recursive: true, mode: 448 });
47640
47717
  try {
47641
- fs7.renameSync(path7.join(from, name), path7.join(dir, name));
47718
+ fs9.renameSync(path9.join(from, name), path9.join(dir, name));
47642
47719
  } catch (e) {
47643
47720
  if (e.code === "ENOENT")
47644
47721
  return;
47645
47722
  throw e;
47646
47723
  }
47647
47724
  try {
47648
- fs7.writeFileSync(path7.join(dir, `${name}.reason`), reason2, { mode: 384 });
47725
+ fs9.writeFileSync(path9.join(dir, `${name}.reason`), reason2, { mode: 384 });
47649
47726
  } catch {}
47650
47727
  }
47651
47728
  async function sendBatch(db, names) {
@@ -47655,7 +47732,7 @@ async function sendBatch(db, names) {
47655
47732
  let raw;
47656
47733
  let r;
47657
47734
  try {
47658
- raw = JSON.parse(fs7.readFileSync(path7.join(from, name), "utf8"));
47735
+ raw = JSON.parse(fs9.readFileSync(path9.join(from, name), "utf8"));
47659
47736
  } catch {
47660
47737
  setAside(from, name, rejectedDir(), "unreadable");
47661
47738
  continue;
@@ -47669,7 +47746,7 @@ async function sendBatch(db, names) {
47669
47746
  if (r)
47670
47747
  records.push({ name, from, r });
47671
47748
  else
47672
- fs7.rmSync(path7.join(from, name), { force: true });
47749
+ fs9.rmSync(path9.join(from, name), { force: true });
47673
47750
  }
47674
47751
  let sent = 0;
47675
47752
  let strayed = [];
@@ -47697,12 +47774,12 @@ async function sendBatch(db, names) {
47697
47774
  for (const x of bad)
47698
47775
  setAside(x.from, x.name, rejectedDir(), x.why);
47699
47776
  if (strayed.length) {
47700
- fs7.mkdirSync(held, { recursive: true, mode: 448 });
47777
+ fs9.mkdirSync(held, { recursive: true, mode: 448 });
47701
47778
  for (const x of strayed) {
47702
47779
  if (x.from === held)
47703
47780
  continue;
47704
47781
  try {
47705
- fs7.renameSync(path7.join(x.from, x.name), path7.join(held, x.name));
47782
+ fs9.renameSync(path9.join(x.from, x.name), path9.join(held, x.name));
47706
47783
  } catch (e) {
47707
47784
  if (e.code !== "ENOENT")
47708
47785
  throw e;
@@ -47712,7 +47789,7 @@ async function sendBatch(db, names) {
47712
47789
  const moved = new Set([...bad, ...strayed].map((x) => x.name));
47713
47790
  for (const x of records)
47714
47791
  if (!moved.has(x.name))
47715
- fs7.rmSync(path7.join(x.from, x.name), { force: true });
47792
+ fs9.rmSync(path9.join(x.from, x.name), { force: true });
47716
47793
  return { sent, rejected: bad.length };
47717
47794
  }
47718
47795
  async function sendObservations(db, names) {
@@ -47723,16 +47800,16 @@ async function sendObservations(db, names) {
47723
47800
  };
47724
47801
  const rows = [];
47725
47802
  for (const { name, from } of names) {
47726
- let text3;
47803
+ let text4;
47727
47804
  try {
47728
- text3 = fs7.readFileSync(path7.join(from, name), "utf8");
47805
+ text4 = fs9.readFileSync(path9.join(from, name), "utf8");
47729
47806
  } catch {
47730
47807
  continue;
47731
47808
  }
47732
47809
  let o = null;
47733
47810
  let why = "unreadable";
47734
47811
  try {
47735
- o = observation(JSON.parse(text3));
47812
+ o = observation(JSON.parse(text4));
47736
47813
  why = "shape";
47737
47814
  } catch {}
47738
47815
  if (o)
@@ -47764,7 +47841,7 @@ async function sendObservations(db, names) {
47764
47841
  aside(x.name, why);
47765
47842
  else
47766
47843
  try {
47767
- fs7.rmSync(path7.join(callsDir(), x.name), { force: true });
47844
+ fs9.rmSync(path9.join(callsDir(), x.name), { force: true });
47768
47845
  } catch {}
47769
47846
  }
47770
47847
  return true;
@@ -47907,7 +47984,7 @@ async function observeRecordCall(file2, input2, owner, waitMs = OBSERVE_WAIT_MS)
47907
47984
  }
47908
47985
  if (kept)
47909
47986
  try {
47910
- fs7.rmSync(kept, { force: true });
47987
+ fs9.rmSync(kept, { force: true });
47911
47988
  } catch {}
47912
47989
  }
47913
47990
  async function main() {
@@ -47985,8 +48062,8 @@ var plainEnv = () => ({
47985
48062
  CLICOLOR_FORCE: "0"
47986
48063
  });
47987
48064
  var ghCwd = startDir;
47988
- var gh = (repo, timeout = 60000) => async (path8, all = false) => {
47989
- const { stdout } = await exec("gh", ["api", `repos/${repo}/${path8}`, ...HOST, ...all ? ["--paginate", "--slurp"] : []], {
48065
+ var gh = (repo, timeout = 60000) => async (path10, all = false) => {
48066
+ const { stdout } = await exec("gh", ["api", `repos/${repo}/${path10}`, ...HOST, ...all ? ["--paginate", "--slurp"] : []], {
47990
48067
  encoding: "utf8",
47991
48068
  maxBuffer: MAX_RESPONSE,
47992
48069
  timeout,
@@ -47995,9 +48072,9 @@ var gh = (repo, timeout = 60000) => async (path8, all = false) => {
47995
48072
  cwd: ghCwd()
47996
48073
  }).catch((e) => {
47997
48074
  if (e.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER")
47998
- throw new Error(`${path8.split("?")[0]} is too large to read (over ${MAX_RESPONSE / 1024 / 1024} MB)`);
48075
+ throw new Error(`${path10.split("?")[0]} is too large to read (over ${MAX_RESPONSE / 1024 / 1024} MB)`);
47999
48076
  if (e.killed)
48000
- throw new Error(`${path8.split("?")[0]} did not answer within ${timeout / 1000} seconds`);
48077
+ throw new Error(`${path10.split("?")[0]} did not answer within ${timeout / 1000} seconds`);
48001
48078
  throw e;
48002
48079
  });
48003
48080
  const parsed = JSON.parse(stdout);
@@ -48843,34 +48920,34 @@ var instructionFile = (relative) => {
48843
48920
  var KEY = /^[a-z0-9][a-z0-9._/-]{0,63}$/;
48844
48921
  var FIELD_NAME2 = /^[a-z][a-z0-9_]{0,39}$/;
48845
48922
  var SOURCE_REF = /^s[1-9][0-9]{0,15}$/;
48846
- var text3 = (max) => exports_external.string().trim().min(1).max(max);
48923
+ var text4 = (max) => exports_external.string().trim().min(1).max(max);
48847
48924
  var Quote = exports_external.object({ source: exports_external.string().regex(SOURCE_REF, "cite a source ref such as s12"), quote: exports_external.string() }).strict();
48848
48925
  var Evidence = Quote.extend({
48849
48926
  role: exports_external.enum(EVIDENCE_ROLES).exclude(["reconsiders"]),
48850
- reported_speaker: text3(100).optional()
48927
+ reported_speaker: text4(100).optional()
48851
48928
  }).strict();
48852
48929
  var Unit = exports_external.object({
48853
48930
  key: exports_external.string().regex(KEY, "use lowercase letters, digits, and . _ - / (at most 64)"),
48854
48931
  kind: exports_external.enum(UNIT_KINDS),
48855
48932
  stance: exports_external.enum(STANCES).optional(),
48856
- text: text3(2000),
48857
- why: text3(2000).optional(),
48858
- scope_note: text3(1000).optional(),
48859
- revisit_when: text3(1000).optional(),
48860
- no_code_surface: text3(500).optional(),
48933
+ text: text4(2000),
48934
+ why: text4(2000).optional(),
48935
+ scope_note: text4(1000).optional(),
48936
+ revisit_when: text4(1000).optional(),
48937
+ no_code_surface: text4(500).optional(),
48861
48938
  options: exports_external.array(exports_external.object({
48862
- text: text3(500),
48939
+ text: text4(500),
48863
48940
  outcome: exports_external.enum(OPTION_OUTCOMES),
48864
- why: text3(2000).optional(),
48865
- reconsider_when: text3(1000).optional(),
48941
+ why: text4(2000).optional(),
48942
+ reconsider_when: text4(1000).optional(),
48866
48943
  reconsider_quote: Quote.optional(),
48867
48944
  evidence: exports_external.array(Evidence.partial({ role: true })).max(10).default([])
48868
48945
  }).strict()).max(12).default([]),
48869
48946
  evidence: exports_external.array(Evidence).max(20).default([]),
48870
48947
  adoption: exports_external.array(Quote).max(5).default([]),
48871
48948
  anchors: exports_external.array(exports_external.object({
48872
- path: text3(500),
48873
- symbol: text3(200).optional(),
48949
+ path: text4(500),
48950
+ symbol: text4(200).optional(),
48874
48951
  role: exports_external.enum(["applies_to", "evidence"]),
48875
48952
  commit: exports_external.string().regex(/^[0-9a-f]{40}$/, "a full 40-character commit sha").optional(),
48876
48953
  lines: exports_external.tuple([exports_external.number().int().positive(), exports_external.number().int().positive()]).optional()
@@ -48881,25 +48958,25 @@ var Unit = exports_external.object({
48881
48958
  answers: exports_external.array(exports_external.string().min(1)).max(5).default([]),
48882
48959
  fields: exports_external.array(exports_external.object({
48883
48960
  name: exports_external.string().regex(FIELD_NAME2, "a defined field name"),
48884
- value: text3(200),
48961
+ value: text4(200),
48885
48962
  quote: Quote
48886
48963
  }).strict()).max(12).default([])
48887
48964
  }).strict();
48888
48965
  var FieldDef = exports_external.object({
48889
48966
  name: exports_external.string().regex(FIELD_NAME2, "a lowercase letter, then lowercase letters, digits, and _ (at most 40)"),
48890
48967
  type: exports_external.enum(FIELD_TYPES),
48891
- label: text3(100),
48892
- description: text3(500),
48893
- enum: exports_external.array(text3(100)).min(1).max(30).optional(),
48968
+ label: text4(100),
48969
+ description: text4(500),
48970
+ enum: exports_external.array(text4(100)).min(1).max(30).optional(),
48894
48971
  kinds: exports_external.array(exports_external.enum(UNIT_KINDS)).max(UNIT_KINDS.length).default([]),
48895
48972
  quote: Quote
48896
48973
  }).strict();
48897
48974
  var Work = exports_external.object({
48898
48975
  key: exports_external.string().regex(KEY),
48899
- title: text3(200).optional(),
48900
- goal: text3(1000).optional(),
48901
- current: text3(2000).optional(),
48902
- next: exports_external.array(text3(500)).max(10).optional(),
48976
+ title: text4(200).optional(),
48977
+ goal: text4(1000).optional(),
48978
+ current: text4(2000).optional(),
48979
+ next: exports_external.array(text4(500)).max(10).optional(),
48903
48980
  status: exports_external.enum(WORK_STATUSES).optional()
48904
48981
  }).strict();
48905
48982
  var Record = exports_external.object({
@@ -49336,8 +49413,8 @@ function valueInQuote(type, value, quote) {
49336
49413
  return standsAlone(quote, value);
49337
49414
  return [...quote.matchAll(NUMBER)].some((m) => m[0].replace(/^\+/, "").replaceAll(",", "") === value);
49338
49415
  }
49339
- var ciPath = (path8) => {
49340
- const p = path8.toLowerCase().replace(/\/+$/, "");
49416
+ var ciPath = (path10) => {
49417
+ const p = path10.toLowerCase().replace(/\/+$/, "");
49341
49418
  return p === ".github" || p === ".github/workflows" || p.startsWith(".github/workflows/");
49342
49419
  };
49343
49420
  async function agentRefusal(db, u, x, s, evidence, anchors) {
@@ -49350,7 +49427,7 @@ async function agentRefusal(db, u, x, s, evidence, anchors) {
49350
49427
  if (!evidence.some((e) => e.role === "decides" && e.source === x.source && e.start === x.start && e.end === x.end))
49351
49428
  return "quote the same words as decides evidence: the AI choosing, not reporting, proposing, or asking";
49352
49429
  const governs = anchors.filter((a) => a.role === "applies_to").map((a) => a.path);
49353
- const bound = anchors.map((a) => a.path).find((path8) => instructionFile(path8) || ciPath(path8));
49430
+ const bound = anchors.map((a) => a.path).find((path10) => instructionFile(path10) || ciPath(path10));
49354
49431
  if (bound)
49355
49432
  return `${bound} holds rules or CI agents follow; only the owner adopts decisions about it`;
49356
49433
  if (await db.selectFrom("agent_ineligible_source").select("source_id").where("source_id", "=", x.source).executeTakeFirst())
@@ -49812,12 +49889,12 @@ function readExcerpt(root, file3) {
49812
49889
  if (privateKeyRanges(buf.toString("utf8")).some(([s, e]) => s < to && e > from && (s < from || e > to)))
49813
49890
  throw new Error(`${p} lines ${a}-${b} are inside a private key; cite lines outside it`);
49814
49891
  const raw = buf.subarray(from, to).toString("utf8");
49815
- const text4 = mask(raw);
49892
+ const text5 = mask(raw);
49816
49893
  const before = buf.subarray(0, from).toString("utf8");
49817
49894
  const after = buf.subarray(to).toString("utf8");
49818
- if (mask(before + raw) !== mask(before) + text4 || mask(raw + after) !== text4 + mask(after))
49895
+ if (mask(before + raw) !== mask(before) + text5 || mask(raw + after) !== text5 + mask(after))
49819
49896
  throw new Error(`${p} lines ${a}-${b} cut through text Sphica masks; cite more lines around it`);
49820
- return { path: p, commit, blob, size, lines: [a, b], raw, text: text4 };
49897
+ return { path: p, commit, blob, size, lines: [a, b], raw, text: text5 };
49821
49898
  }
49822
49899
  var excerptKey = (file3) => JSON.stringify([file3.path, file3.commit, file3.lines]);
49823
49900
  function excerptOf(facts, file3) {
@@ -50314,12 +50391,12 @@ ${c.errors.map((e) => ` ${e}`).join(`
50314
50391
  var CONTROL_SEQUENCE = /(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]?/;
50315
50392
  var HIDDEN = new RegExp(`${STRING_SEQUENCE.source}|${CONTROL_SEQUENCE.source}`, "g");
50316
50393
  function sequences(all) {
50317
- const text4 = all.toString("utf8");
50394
+ const text5 = all.toString("utf8");
50318
50395
  const out = [];
50319
50396
  let index = 0;
50320
50397
  let at = 0;
50321
- for (const m of text4.matchAll(HIDDEN)) {
50322
- at += bytes(text4.slice(index, m.index));
50398
+ for (const m of text5.matchAll(HIDDEN)) {
50399
+ at += bytes(text5.slice(index, m.index));
50323
50400
  index = m.index + m[0].length;
50324
50401
  if (plain2(m[0]) === "")
50325
50402
  out.push([at, at + bytes(m[0])]);
@@ -50333,11 +50410,11 @@ function cutEnd(all, hide2, from, room) {
50333
50410
  const end = inside ? inside[0] > from ? inside[0] : inside[1] : cut;
50334
50411
  return bytes(plain2(all.subarray(from, end).toString("utf8"))) > Math.max(room, 0) ? cut : end;
50335
50412
  }
50336
- function shownStart(text4, room) {
50337
- const whole = plain2(text4);
50413
+ function shownStart(text5, room) {
50414
+ const whole = plain2(text5);
50338
50415
  if (bytes(whole) <= room)
50339
- return { text: whole, end: bytes(text4), whole: true };
50340
- const all = Buffer.from(text4, "utf8");
50416
+ return { text: whole, end: bytes(text5), whole: true };
50417
+ const all = Buffer.from(text5, "utf8");
50341
50418
  const end = cutEnd(all, sequences(all), 0, room);
50342
50419
  return { text: plain2(all.subarray(0, end).toString("utf8")), end, whole: false };
50343
50420
  }
@@ -50856,12 +50933,12 @@ async function contextText(db, id, projectId2, root, after, auto = false, signal
50856
50933
  const heading = label(end);
50857
50934
  const max = room - (heading ? bytes(heading) + 1 : 0);
50858
50935
  const body = entry(it, context ? Math.min(CONTEXT_BYTES, max) : max);
50859
- const text4 = heading ? `${heading}
50936
+ const text5 = heading ? `${heading}
50860
50937
  ${body}` : body;
50861
- if (page2.length && used + bytes(text4) + 1 > room)
50938
+ if (page2.length && used + bytes(text5) + 1 > room)
50862
50939
  break;
50863
- page2.push({ id: it.id, text: text4, context });
50864
- used += bytes(text4) + 1;
50940
+ page2.push({ id: it.id, text: text5, context });
50941
+ used += bytes(text5) + 1;
50865
50942
  }
50866
50943
  const left = items.length - end;
50867
50944
  const nextNo = pageNo + (page2.some((x) => !x.context) ? 1 : 0);
@@ -51117,28 +51194,28 @@ async function saveText(db, id, projectId2, root, record4, probe, call) {
51117
51194
  lines: errors3.map((x) => `✗ ${x}`)
51118
51195
  }));
51119
51196
  });
51120
- const text4 = firstPage({
51197
+ const text5 = firstPage({
51121
51198
  kind: "save",
51122
51199
  projectId: projectId2,
51123
51200
  lead: ["✓ saved", ...tally(done.saved, done.changes, done.lines)],
51124
51201
  lines: done.lines
51125
51202
  });
51126
51203
  shownTo.delete(id);
51127
- return text4;
51204
+ return text5;
51128
51205
  }
51129
51206
 
51130
51207
  // server/src/backups.ts
51131
- import fs8 from "node:fs";
51132
- import path8 from "node:path";
51133
- var backupDir = (file3 = dbFile()) => path8.join(path8.dirname(file3), "backups");
51134
- var stem = (file3) => path8.basename(file3).replace(/\.db$/, "");
51208
+ import fs10 from "node:fs";
51209
+ import path10 from "node:path";
51210
+ var backupDir = (file3 = dbFile()) => path10.join(path10.dirname(file3), "backups");
51211
+ var stem = (file3) => path10.basename(file3).replace(/\.db$/, "");
51135
51212
  var pattern = (file3) => new RegExp(`^${stem(file3).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\.rev\\d+\\.(\\d{8}T\\d{9}Z)\\.\\d+\\.db$`);
51136
51213
  function backups(file3 = dbFile()) {
51137
51214
  const dir = backupDir(file3);
51138
- if (!fs8.existsSync(dir))
51215
+ if (!fs10.existsSync(dir))
51139
51216
  return [];
51140
51217
  const named = pattern(file3);
51141
- return fs8.readdirSync(dir).filter((f) => named.test(f)).sort((a, b) => (named.exec(b)?.[1] ?? "").localeCompare(named.exec(a)?.[1] ?? "") || b.localeCompare(a)).map((f) => path8.join(dir, f));
51218
+ return fs10.readdirSync(dir).filter((f) => named.test(f)).sort((a, b) => (named.exec(b)?.[1] ?? "").localeCompare(named.exec(a)?.[1] ?? "") || b.localeCompare(a)).map((f) => path10.join(dir, f));
51142
51219
  }
51143
51220
 
51144
51221
  // server/src/forget.ts
@@ -51307,14 +51384,14 @@ function forgetWords(o, file3) {
51307
51384
  }
51308
51385
  function forgetQuestion(o, file3) {
51309
51386
  const w = forgetWords(o, file3);
51310
- const text4 = (kept) => [
51387
+ const text5 = (kept) => [
51311
51388
  `Forget ${plural2(o.sources.length, "source")} for good?`,
51312
51389
  ...w.must,
51313
51390
  ...w.records.slice(0, kept),
51314
51391
  ...kept < w.records.length ? [`and ${plural2(w.records.length - kept, "more record")}: forget_preview lists every one`] : []
51315
51392
  ].join(`
51316
51393
  `);
51317
- return text4(fitCount(w.records, READ_BUDGET, text4));
51394
+ return text5(fitCount(w.records, READ_BUDGET, text5));
51318
51395
  }
51319
51396
 
51320
51397
  // server/src/stdio-limit.ts
@@ -51493,7 +51570,7 @@ server.registerTool("forget_apply", {
51493
51570
  if (n > 0) {
51494
51571
  const refused2 = (why) => new Error(`${why}, so nothing was forgotten`);
51495
51572
  if (!server.server.getClientCapabilities()?.elicitation)
51496
- throw refused2("This host cannot ask you directly (run /sphica:forget in Claude Code)");
51573
+ throw refused2("This host cannot ask you directly (run forget in an interactive Claude Code or Codex session)");
51497
51574
  let answer;
51498
51575
  try {
51499
51576
  answer = await server.server.elicitInput({