@kvali/cli 0.7.6 → 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/kvali.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  // src/index.ts
4
4
  import { lstat, writeFile } from "node:fs/promises";
5
5
  import os3 from "node:os";
6
- import path19 from "node:path";
6
+ import path20 from "node:path";
7
7
  import process2 from "node:process";
8
8
  import { fileURLToPath } from "node:url";
9
9
 
@@ -498,6 +498,7 @@ var OPUS_45_PLUS = p(5, 6.25, 10, 0.5, 25);
498
498
  var OPUS_LEGACY = p(15, 18.75, 30, 1.5, 75);
499
499
  var SONNET_4 = p(3, 3.75, 6, 0.3, 15);
500
500
  var ANTHROPIC_PRICES = {
501
+ "fable-5-2": p(8, 10, 16, 0.2, 40),
501
502
  "fable-5-1": p(10, 12.5, 20, 0.25, 50),
502
503
  "mythos-5-1": p(10, 12.5, 20, 0.25, 50),
503
504
  "opus-5-5": { ...p(4, 5, 8, 0.2, 20), fastMultiplier: 2 },
@@ -616,8 +617,246 @@ var Pricing = class {
616
617
  }
617
618
  };
618
619
 
619
- // ../core/src/util/jsonl.ts
620
+ // ../core/src/wake.ts
621
+ import { execFile, spawn } from "node:child_process";
620
622
  import { promises as fsp } from "node:fs";
623
+ import path from "node:path";
624
+ var KEEP_AWAKE_GRACE_MS = 6e4;
625
+ var KEEP_AWAKE_QUIET_MS = 10 * 6e4;
626
+ var POWER_TTL_MS = 6e4;
627
+ var RETRY_MS = 6e4;
628
+ var QUICK_END_MS = 5e3;
629
+ function agentsWorking(sessions, now) {
630
+ return sessions.some((s) => {
631
+ if (s.status !== "working") return false;
632
+ const running = !!s.activity && s.activity.endedAt === void 0 && s.activity.kind !== "thinking" && s.activity.kind !== "message";
633
+ const last = Math.max(s.updatedAt, s.pulse?.at ?? 0);
634
+ return running || now - last < KEEP_AWAKE_QUIET_MS;
635
+ });
636
+ }
637
+ function holdCommand(platform, pid) {
638
+ if (!Number.isSafeInteger(pid) || pid <= 0) return void 0;
639
+ switch (platform) {
640
+ case "darwin":
641
+ return { cmd: "caffeinate", args: ["-i", "-w", String(pid)] };
642
+ case "linux":
643
+ return {
644
+ cmd: "systemd-inhibit",
645
+ args: ["--what=idle", "--who=Kvali", "--why=An AI agent is working", "--mode=block", "sh", "-c", `while kill -0 ${pid} 2>/dev/null; do sleep 30; done`]
646
+ };
647
+ case "win32":
648
+ return {
649
+ cmd: "powershell.exe",
650
+ args: [
651
+ "-NoProfile",
652
+ "-NonInteractive",
653
+ "-Command",
654
+ [
655
+ `$k = Add-Type -Name Awake -Namespace Kvali -PassThru -MemberDefinition '[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint f);'`,
656
+ // ES_CONTINUOUS | ES_SYSTEM_REQUIRED, written in decimal: PowerShell 5 reads 0x80000001 as a negative Int32.
657
+ "[void]$k::SetThreadExecutionState([uint32]2147483649)",
658
+ `while (Get-Process -Id ${pid} -ErrorAction SilentlyContinue) { Start-Sleep -Seconds 30 }`
659
+ ].join("; ")
660
+ ]
661
+ };
662
+ default:
663
+ return void 0;
664
+ }
665
+ }
666
+ function parsePmset(out) {
667
+ if (/'AC Power'/.test(out)) return true;
668
+ if (/'Battery Power'/.test(out)) return false;
669
+ return void 0;
670
+ }
671
+ function parseWinBattery(out) {
672
+ const v = out.trim();
673
+ if (!v) return true;
674
+ const n = Number(v.split(/\s+/)[0]);
675
+ if (!Number.isInteger(n)) return void 0;
676
+ return ![1, 4, 5].includes(n);
677
+ }
678
+ function linuxMains(supplies) {
679
+ if (!supplies.length) return true;
680
+ const external = supplies.filter((s) => s.type === "Mains" || s.type.startsWith("USB"));
681
+ if (external.some((s) => s.online === "1")) return true;
682
+ if (supplies.some((s) => s.type === "Battery")) return false;
683
+ return void 0;
684
+ }
685
+ function run(cmd, args) {
686
+ return new Promise((resolve) => {
687
+ try {
688
+ execFile(cmd, args, { timeout: 5e3, windowsHide: true }, (err, stdout) => resolve(err ? void 0 : String(stdout)));
689
+ } catch {
690
+ resolve(void 0);
691
+ }
692
+ });
693
+ }
694
+ async function onMainsPower(platform = process.platform) {
695
+ if (platform === "darwin") {
696
+ const out = await run("pmset", ["-g", "ps"]);
697
+ return out === void 0 ? void 0 : parsePmset(out);
698
+ }
699
+ if (platform === "win32") {
700
+ const out = await run("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "(Get-CimInstance -ClassName Win32_Battery | Select-Object -First 1).BatteryStatus"]);
701
+ return out === void 0 ? void 0 : parseWinBattery(out);
702
+ }
703
+ if (platform === "linux") {
704
+ const base = "/sys/class/power_supply";
705
+ try {
706
+ const names = await fsp.readdir(base);
707
+ const read = async (name, file) => (await fsp.readFile(path.join(base, name, file), "utf8").catch(() => void 0))?.trim();
708
+ const supplies = await Promise.all(names.map(async (n) => ({ type: await read(n, "type") ?? "", online: await read(n, "online") })));
709
+ return linuxMains(supplies);
710
+ } catch {
711
+ return true;
712
+ }
713
+ }
714
+ return void 0;
715
+ }
716
+ function spawnHold(c) {
717
+ const child = spawn(c.cmd, c.args, { stdio: "ignore", windowsHide: true });
718
+ child.unref();
719
+ let ended;
720
+ let done = false;
721
+ const end2 = (missing) => {
722
+ if (done) return;
723
+ done = true;
724
+ ended?.(missing);
725
+ };
726
+ child.on("error", (err) => end2(err.code === "ENOENT"));
727
+ child.on("exit", () => end2(false));
728
+ return {
729
+ stop: () => {
730
+ done = true;
731
+ try {
732
+ child.kill();
733
+ } catch {
734
+ }
735
+ },
736
+ onEnd: (fn) => {
737
+ ended = fn;
738
+ }
739
+ };
740
+ }
741
+ var KeepAwake = class {
742
+ hold;
743
+ releaseTimer;
744
+ mode = "off";
745
+ working = false;
746
+ missing = false;
747
+ retryAt = 0;
748
+ powerReading;
749
+ listeners = /* @__PURE__ */ new Set();
750
+ platform;
751
+ pid;
752
+ graceMs;
753
+ now;
754
+ o;
755
+ constructor(o = {}) {
756
+ this.o = o;
757
+ this.platform = o.platform ?? process.platform;
758
+ this.pid = o.pid ?? process.pid;
759
+ this.graceMs = o.graceMs ?? KEEP_AWAKE_GRACE_MS;
760
+ this.now = o.now ?? Date.now;
761
+ }
762
+ /** True while the computer is being kept awake. */
763
+ get active() {
764
+ return !!this.hold;
765
+ }
766
+ /** Called when `active` changes. */
767
+ onChange(fn) {
768
+ this.listeners.add(fn);
769
+ return () => this.listeners.delete(fn);
770
+ }
771
+ async update(working, mode) {
772
+ if (mode !== this.mode) this.missing = false;
773
+ this.mode = mode;
774
+ this.working = working;
775
+ if (mode === "off") return this.release("turned off");
776
+ if (!working) {
777
+ if (this.hold && this.releaseTimer === void 0) {
778
+ const t = (this.o.setTimer ?? setTimeout)(() => {
779
+ this.releaseTimer = void 0;
780
+ if (!this.working) this.release("no agent is working");
781
+ }, this.graceMs);
782
+ t?.unref?.();
783
+ this.releaseTimer = t;
784
+ }
785
+ return;
786
+ }
787
+ this.clearRelease();
788
+ if (mode === "whenPluggedIn" && await this.mains() === false) return this.release("on battery");
789
+ if (!this.working || this.mode === "off" || this.mode === "whenPluggedIn" && this.powerReading?.mains === false) return;
790
+ this.acquire();
791
+ }
792
+ dispose() {
793
+ this.release();
794
+ this.listeners.clear();
795
+ }
796
+ async mains() {
797
+ const now = this.now();
798
+ if (this.powerReading && now - this.powerReading.at < POWER_TTL_MS) return this.powerReading.mains;
799
+ const mains = await (this.o.power ?? (() => onMainsPower(this.platform)))().catch(() => void 0);
800
+ this.powerReading = { at: this.now(), mains };
801
+ return mains;
802
+ }
803
+ acquire() {
804
+ if (this.hold || this.missing || this.now() < this.retryAt) return;
805
+ const c = holdCommand(this.platform, this.pid);
806
+ if (!c) {
807
+ this.missing = true;
808
+ this.o.log?.(`Keeping the computer awake isn't supported on ${this.platform}.`);
809
+ return;
810
+ }
811
+ let hold;
812
+ try {
813
+ hold = (this.o.start ?? spawnHold)(c);
814
+ } catch (err) {
815
+ this.missing = true;
816
+ this.o.log?.(`Could not keep the computer awake: ${err.message}`);
817
+ return;
818
+ }
819
+ this.hold = hold;
820
+ const startedAt = this.now();
821
+ hold.onEnd((missing) => {
822
+ if (this.hold !== hold) return;
823
+ this.hold = void 0;
824
+ if (missing) {
825
+ this.missing = true;
826
+ this.o.log?.(`Could not keep the computer awake: ${c.cmd} was not found.`);
827
+ } else if (this.now() - startedAt < QUICK_END_MS) {
828
+ this.missing = true;
829
+ this.o.log?.(`Could not keep the computer awake: ${c.cmd} stopped right after it started.`);
830
+ } else {
831
+ this.retryAt = this.now() + RETRY_MS;
832
+ this.o.log?.(`The hold that kept the computer awake (${c.cmd}) ended by itself.`);
833
+ }
834
+ this.emit();
835
+ });
836
+ this.o.log?.("Keeping the computer awake while an agent works.");
837
+ this.emit();
838
+ }
839
+ release(why) {
840
+ this.clearRelease();
841
+ if (!this.hold) return;
842
+ const hold = this.hold;
843
+ this.hold = void 0;
844
+ hold.stop();
845
+ if (why) this.o.log?.(`The computer may sleep again (${why}).`);
846
+ this.emit();
847
+ }
848
+ clearRelease() {
849
+ if (this.releaseTimer === void 0) return;
850
+ (this.o.clearTimer ?? ((t) => clearTimeout(t)))(this.releaseTimer);
851
+ this.releaseTimer = void 0;
852
+ }
853
+ emit() {
854
+ for (const fn of this.listeners) fn(this.active);
855
+ }
856
+ };
857
+
858
+ // ../core/src/util/jsonl.ts
859
+ import { promises as fsp2 } from "node:fs";
621
860
  var CHUNK_BYTES = 1 << 20;
622
861
  var MAX_LINE_BYTES = 8 << 20;
623
862
  var JsonlTail = class {
@@ -628,8 +867,8 @@ var JsonlTail = class {
628
867
  mtimeMs = -1;
629
868
  ino;
630
869
  path;
631
- constructor(path20) {
632
- this.path = path20;
870
+ constructor(path21) {
871
+ this.path = path21;
633
872
  }
634
873
  /** Byte offset of the first unconsumed byte. */
635
874
  get position() {
@@ -642,7 +881,7 @@ var JsonlTail = class {
642
881
  async read(onRecord, onReset) {
643
882
  let st;
644
883
  try {
645
- st = await fsp.stat(this.path);
884
+ st = await fsp2.stat(this.path);
646
885
  } catch {
647
886
  return { changed: false, reset: false, lines: 0 };
648
887
  }
@@ -658,7 +897,7 @@ var JsonlTail = class {
658
897
  }
659
898
  this.ino = st.ino;
660
899
  let lines = 0;
661
- const fh = await fsp.open(this.path, "r");
900
+ const fh = await fsp2.open(this.path, "r");
662
901
  try {
663
902
  const chunk = Buffer.allocUnsafe(CHUNK_BYTES);
664
903
  let pos = this.offset;
@@ -785,10 +1024,10 @@ function staleness(updatedAt, ctx) {
785
1024
 
786
1025
  // ../core/src/engine.ts
787
1026
  import os from "node:os";
788
- import path11 from "node:path";
1027
+ import path12 from "node:path";
789
1028
 
790
1029
  // ../core/src/adapters/antigravity.ts
791
- import path2 from "node:path";
1030
+ import path3 from "node:path";
792
1031
 
793
1032
  // ../core/src/util/checklist.ts
794
1033
  var ITEM_RE = /^([ \t]*)(?:[-*+]|\d{1,9}[.)])[ \t]+\[([ xX/\-~>!?])\][ \t]+(\S.*)$/;
@@ -868,27 +1107,27 @@ function parseChecklist(markdown) {
868
1107
  }
869
1108
 
870
1109
  // ../core/src/util/fs.ts
871
- import { existsSync, promises as fsp2 } from "node:fs";
872
- import path from "node:path";
1110
+ import { existsSync, promises as fsp3 } from "node:fs";
1111
+ import path2 from "node:path";
873
1112
  async function listDir(dir) {
874
1113
  try {
875
- return await fsp2.readdir(dir, { withFileTypes: true });
1114
+ return await fsp3.readdir(dir, { withFileTypes: true });
876
1115
  } catch {
877
1116
  return [];
878
1117
  }
879
1118
  }
880
1119
  async function statSafe(p2) {
881
1120
  try {
882
- return await fsp2.stat(p2);
1121
+ return await fsp3.stat(p2);
883
1122
  } catch {
884
1123
  return void 0;
885
1124
  }
886
1125
  }
887
1126
  async function readTextSafe(p2, maxBytes = 4 << 20) {
888
1127
  try {
889
- const st = await fsp2.stat(p2);
1128
+ const st = await fsp3.stat(p2);
890
1129
  if (!st.isFile() || st.size > maxBytes) return void 0;
891
- return await fsp2.readFile(p2, "utf8");
1130
+ return await fsp3.readFile(p2, "utf8");
892
1131
  } catch {
893
1132
  return void 0;
894
1133
  }
@@ -904,7 +1143,7 @@ async function readJsonSafe(p2, maxBytes = 4 << 20) {
904
1143
  }
905
1144
  var rootCache = /* @__PURE__ */ new Map();
906
1145
  function findGitRoot(p2, maxLevels = 12) {
907
- let dir = path.resolve(p2);
1146
+ let dir = path2.resolve(p2);
908
1147
  const visited = [];
909
1148
  for (let i = 0; i < maxLevels; i += 1) {
910
1149
  if (rootCache.has(dir)) {
@@ -913,11 +1152,11 @@ function findGitRoot(p2, maxLevels = 12) {
913
1152
  return hit;
914
1153
  }
915
1154
  visited.push(dir);
916
- if (existsSync(path.join(dir, ".git"))) {
1155
+ if (existsSync(path2.join(dir, ".git"))) {
917
1156
  for (const v of visited) rootCache.set(v, dir);
918
1157
  return dir;
919
1158
  }
920
- const parent = path.dirname(dir);
1159
+ const parent = path2.dirname(dir);
921
1160
  if (parent === dir) break;
922
1161
  dir = parent;
923
1162
  }
@@ -925,8 +1164,8 @@ function findGitRoot(p2, maxLevels = 12) {
925
1164
  return void 0;
926
1165
  }
927
1166
  function isWithin(child, parent) {
928
- const rel2 = path.relative(parent, child);
929
- return rel2 === "" || !rel2.startsWith("..") && !path.isAbsolute(rel2);
1167
+ const rel2 = path2.relative(parent, child);
1168
+ return rel2 === "" || !rel2.startsWith("..") && !path2.isAbsolute(rel2);
930
1169
  }
931
1170
 
932
1171
  // ../core/src/util/task-timer.ts
@@ -1063,7 +1302,7 @@ function argmax(m) {
1063
1302
  }
1064
1303
  function commonAncestor(dirs) {
1065
1304
  if (!dirs.length) return void 0;
1066
- const split = dirs.map((d) => d.split(path2.sep));
1305
+ const split = dirs.map((d) => d.split(path3.sep));
1067
1306
  const first = split[0];
1068
1307
  let n = first.length;
1069
1308
  for (const parts of split) {
@@ -1071,7 +1310,7 @@ function commonAncestor(dirs) {
1071
1310
  while (i < n && i < parts.length && parts[i] === first[i]) i += 1;
1072
1311
  n = i;
1073
1312
  }
1074
- const joined = first.slice(0, n).join(path2.sep);
1313
+ const joined = first.slice(0, n).join(path3.sep);
1075
1314
  return joined || void 0;
1076
1315
  }
1077
1316
  function inferProject(votes, home) {
@@ -1089,7 +1328,7 @@ function inferProject(votes, home) {
1089
1328
  if (gitWeight * 2 >= total) return argmax(byGit);
1090
1329
  const strong = [...votes].filter(([, w]) => w * 10 >= total).map(([d]) => d);
1091
1330
  const anc = commonAncestor(strong);
1092
- const tooGeneric = !anc || anc.split(path2.sep).filter(Boolean).length < 2 || home !== void 0 && (isWithin(home, anc) || path2.dirname(anc) === home);
1331
+ const tooGeneric = !anc || anc.split(path3.sep).filter(Boolean).length < 2 || home !== void 0 && (isWithin(home, anc) || path3.dirname(anc) === home);
1093
1332
  return tooGeneric ? argmax(votes) : anc;
1094
1333
  }
1095
1334
  function humanize(tool) {
@@ -1117,8 +1356,8 @@ var AntigravityAdapter = class {
1117
1356
  this.extraBrainDirs = extraBrainDirs;
1118
1357
  }
1119
1358
  brainDirs(ctx) {
1120
- const g = path2.join(ctx.home, ".gemini");
1121
- return [path2.join(g, "antigravity-ide", "brain"), path2.join(g, "antigravity", "brain"), ...this.extraBrainDirs];
1359
+ const g = path3.join(ctx.home, ".gemini");
1360
+ return [path3.join(g, "antigravity-ide", "brain"), path3.join(g, "antigravity", "brain"), ...this.extraBrainDirs];
1122
1361
  }
1123
1362
  async poll(ctx) {
1124
1363
  const now = ctx.now();
@@ -1147,7 +1386,7 @@ var AntigravityAdapter = class {
1147
1386
  return {
1148
1387
  id,
1149
1388
  dir,
1150
- tail: new JsonlTail(path2.join(dir, ".system_generated", "logs", "transcript.jsonl")),
1389
+ tail: new JsonlTail(path3.join(dir, ".system_generated", "logs", "transcript.jsonl")),
1151
1390
  updatedAt: 0,
1152
1391
  votes: /* @__PURE__ */ new Map(),
1153
1392
  projectVotesAt: -1,
@@ -1164,10 +1403,10 @@ var AntigravityAdapter = class {
1164
1403
  for (const brain of this.brainDirs(ctx)) {
1165
1404
  for (const d of await listDir(brain)) {
1166
1405
  if (!d.isDirectory() || !/^[0-9a-f-]{36}$/i.test(d.name)) continue;
1167
- const dir = path2.join(brain, d.name);
1406
+ const dir = path3.join(brain, d.name);
1168
1407
  const stats = await Promise.all([
1169
- statSafe(path2.join(dir, ".system_generated", "logs", "transcript.jsonl")),
1170
- statSafe(path2.join(dir, "task.md"))
1408
+ statSafe(path3.join(dir, ".system_generated", "logs", "transcript.jsonl")),
1409
+ statSafe(path3.join(dir, "task.md"))
1171
1410
  ]);
1172
1411
  const mtimeMs = Math.max(...stats.map((s) => s?.mtimeMs ?? 0));
1173
1412
  if (mtimeMs && now - mtimeMs <= ctx.activeWindowMs) found.push({ dir, id: d.name, mtimeMs });
@@ -1194,7 +1433,7 @@ var AntigravityAdapter = class {
1194
1433
  const status = String(o.status ?? "");
1195
1434
  const source = String(o.source ?? "");
1196
1435
  const tools = [];
1197
- const gemini = path2.join(ctx.home, ".gemini");
1436
+ const gemini = path3.join(ctx.home, ".gemini");
1198
1437
  const running = st.recent[0];
1199
1438
  if (running && running.endedAt === void 0 && status !== "RUNNING") running.endedAt = at;
1200
1439
  for (const tc of Array.isArray(o.tool_calls) ? o.tool_calls : []) {
@@ -1217,8 +1456,8 @@ var AntigravityAdapter = class {
1217
1456
  }
1218
1457
  for (const [key, weight] of Object.entries(PATH_ARGS)) {
1219
1458
  const v = decodeArg(args[key]);
1220
- if (typeof v !== "string" || !path2.isAbsolute(v) || isWithin(v, gemini)) continue;
1221
- const dir = key === "Cwd" || key === "DirectoryPath" || key === "SearchDirectory" ? v : path2.dirname(v);
1459
+ if (typeof v !== "string" || !path3.isAbsolute(v) || isWithin(v, gemini)) continue;
1460
+ const dir = key === "Cwd" || key === "DirectoryPath" || key === "SearchDirectory" ? v : path3.dirname(v);
1222
1461
  st.votes.set(dir, (st.votes.get(dir) ?? 0) + weight);
1223
1462
  }
1224
1463
  }
@@ -1252,13 +1491,13 @@ var AntigravityAdapter = class {
1252
1491
  const model = /`Model Selection` from .*? to (.+?)\.(?:\s|$)/.exec(content)?.[1];
1253
1492
  if (model) st.model = model.trim();
1254
1493
  const doc = /Active Document: (\/[^\n]+?)(?: \([A-Z_]+\))?\s*$/m.exec(content)?.[1];
1255
- if (doc && path2.isAbsolute(doc) && !isWithin(doc, gemini)) {
1256
- const dir = path2.dirname(doc);
1494
+ if (doc && path3.isAbsolute(doc) && !isWithin(doc, gemini)) {
1495
+ const dir = path3.dirname(doc);
1257
1496
  st.votes.set(dir, (st.votes.get(dir) ?? 0) + 1);
1258
1497
  }
1259
1498
  }
1260
1499
  async readTask(st) {
1261
- const file = path2.join(st.dir, "task.md");
1500
+ const file = path3.join(st.dir, "task.md");
1262
1501
  const s = await statSafe(file);
1263
1502
  if (!s) {
1264
1503
  st.task = void 0;
@@ -1267,7 +1506,7 @@ var AntigravityAdapter = class {
1267
1506
  if (st.task?.mtimeMs === s.mtimeMs) return;
1268
1507
  const md = await readTextSafe(file, 1 << 20);
1269
1508
  const parsed = md ? parseChecklist(md) : void 0;
1270
- const meta = await readJsonSafe(path2.join(st.dir, "task.md.metadata.json"));
1509
+ const meta = await readJsonSafe(path3.join(st.dir, "task.md.metadata.json"));
1271
1510
  st.task = {
1272
1511
  mtimeMs: s.mtimeMs,
1273
1512
  title: (parsed?.title !== void 0 ? withoutTrackerSuffix(parsed.title) : void 0) || void 0,
@@ -1338,7 +1577,7 @@ var AntigravityAdapter = class {
1338
1577
  tasks,
1339
1578
  activity,
1340
1579
  daily: Object.keys(st.daily).length ? st.daily : void 0,
1341
- sources: [path2.join(st.dir, "task.md"), st.tail.path]
1580
+ sources: [path3.join(st.dir, "task.md"), st.tail.path]
1342
1581
  };
1343
1582
  }
1344
1583
  };
@@ -1350,7 +1589,7 @@ function withoutTrackerSuffix(title) {
1350
1589
  }
1351
1590
 
1352
1591
  // ../core/src/adapters/claude-code.ts
1353
- import path3 from "node:path";
1592
+ import path4 from "node:path";
1354
1593
 
1355
1594
  // ../core/src/util/loop-watch.ts
1356
1595
  var SAME_ERROR_RUNS = 4;
@@ -1464,7 +1703,7 @@ function normStatus(s) {
1464
1703
  }
1465
1704
  function rel(file, cwd) {
1466
1705
  if (typeof file !== "string") return void 0;
1467
- if (cwd && file.startsWith(cwd + path3.sep)) return file.slice(cwd.length + 1);
1706
+ if (cwd && file.startsWith(cwd + path4.sep)) return file.slice(cwd.length + 1);
1468
1707
  return file;
1469
1708
  }
1470
1709
  function describeClaudeTool(name, input, cwd, at) {
@@ -1519,7 +1758,7 @@ var ClaudeCodeAdapter = class {
1519
1758
  limitBook = new LimitBook();
1520
1759
  configDir(ctx) {
1521
1760
  const fromEnv = ctx.env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim();
1522
- return fromEnv || path3.join(ctx.home, ".claude");
1761
+ return fromEnv || path4.join(ctx.home, ".claude");
1523
1762
  }
1524
1763
  async poll(ctx) {
1525
1764
  const now = ctx.now();
@@ -1529,7 +1768,7 @@ var ClaudeCodeAdapter = class {
1529
1768
  }
1530
1769
  const out = [];
1531
1770
  for (const entry of this.sessions.values()) {
1532
- await isolated(ctx, `[claude-code] ${path3.basename(entry.state.file)}`, async () => {
1771
+ await isolated(ctx, `[claude-code] ${path4.basename(entry.state.file)}`, async () => {
1533
1772
  const res = await entry.tail.read(
1534
1773
  (rec) => this.onRecord(entry.state, rec, ctx, false),
1535
1774
  () => {
@@ -1541,7 +1780,7 @@ var ClaudeCodeAdapter = class {
1541
1780
  }
1542
1781
  await isolated(ctx, "[claude-code] subagents", () => this.readLegacyAgents(ctx));
1543
1782
  for (const entry of this.sessions.values()) {
1544
- const s = await isolated(ctx, `[claude-code] ${path3.basename(entry.state.file)}`, () => this.toSession(entry.state, ctx));
1783
+ const s = await isolated(ctx, `[claude-code] ${path4.basename(entry.state.file)}`, () => this.toSession(entry.state, ctx));
1545
1784
  if (s) out.push(s);
1546
1785
  }
1547
1786
  return out;
@@ -1555,13 +1794,13 @@ var ClaudeCodeAdapter = class {
1555
1794
  const now = ctx.now();
1556
1795
  const full = now - this.lastFullScan >= 6e4;
1557
1796
  if (full) this.lastFullScan = now;
1558
- const projectsDir = path3.join(this.configDir(ctx), "projects");
1797
+ const projectsDir = path4.join(this.configDir(ctx), "projects");
1559
1798
  const found = [];
1560
1799
  const legacy = [];
1561
1800
  const seenDirs = /* @__PURE__ */ new Set();
1562
1801
  for (const d of await listDir(projectsDir)) {
1563
1802
  if (!d.isDirectory()) continue;
1564
- const dir = path3.join(projectsDir, d.name);
1803
+ const dir = path4.join(projectsDir, d.name);
1565
1804
  seenDirs.add(dir);
1566
1805
  const dst = await statSafe(dir);
1567
1806
  if (!dst) continue;
@@ -1570,7 +1809,7 @@ var ClaudeCodeAdapter = class {
1570
1809
  const files = [];
1571
1810
  for (const f of await listDir(dir)) {
1572
1811
  if (!f.isFile() || !f.name.endsWith(".jsonl")) continue;
1573
- const file = path3.join(dir, f.name);
1812
+ const file = path4.join(dir, f.name);
1574
1813
  const st = await statSafe(file);
1575
1814
  if (st) files.push({ file, mtimeMs: st.mtimeMs });
1576
1815
  }
@@ -1580,7 +1819,7 @@ var ClaudeCodeAdapter = class {
1580
1819
  for (const f of cached.files) {
1581
1820
  const mtimeMs = Math.max(f.mtimeMs, this.sessions.get(f.file)?.state.updatedAt ?? 0);
1582
1821
  if (now - mtimeMs > ctx.activeWindowMs) continue;
1583
- (path3.basename(f.file).startsWith("agent-") ? legacy : found).push({ file: f.file, mtimeMs });
1822
+ (path4.basename(f.file).startsWith("agent-") ? legacy : found).push({ file: f.file, mtimeMs });
1584
1823
  }
1585
1824
  }
1586
1825
  for (const dir of [...this.dirCache.keys()]) if (!seenDirs.has(dir)) this.dirCache.delete(dir);
@@ -1598,8 +1837,8 @@ var ClaudeCodeAdapter = class {
1598
1837
  const daily = {};
1599
1838
  return {
1600
1839
  file,
1601
- sessionId: path3.basename(file, ".jsonl"),
1602
- projectDir: path3.dirname(file),
1840
+ sessionId: path4.basename(file, ".jsonl"),
1841
+ projectDir: path4.dirname(file),
1603
1842
  updatedAt: 0,
1604
1843
  usage: { seen: /* @__PURE__ */ new Set() },
1605
1844
  tokens: emptyTokens(),
@@ -1926,20 +2165,20 @@ var ClaudeCodeAdapter = class {
1926
2165
  async readSideFiles(st, ctx, changed) {
1927
2166
  const config = this.configDir(ctx);
1928
2167
  if (changed || st.taskDir === void 0) {
1929
- const dir = path3.join(config, "tasks", st.sessionId);
2168
+ const dir = path4.join(config, "tasks", st.sessionId);
1930
2169
  const entries = (await listDir(dir)).filter((e) => e.isFile() && e.name.endsWith(".json"));
1931
2170
  if (entries.length === 0) st.taskDir = { sig: "", tasks: [] };
1932
2171
  else {
1933
- const stats = await Promise.all(entries.map((e) => statSafe(path3.join(dir, e.name))));
2172
+ const stats = await Promise.all(entries.map((e) => statSafe(path4.join(dir, e.name))));
1934
2173
  const sig = entries.map((e, i) => `${e.name}:${stats[i]?.mtimeMs ?? 0}`).join("|");
1935
2174
  if (sig !== st.taskDir?.sig) {
1936
2175
  const tasks = [];
1937
2176
  const timed = [];
1938
2177
  for (const [i, e] of entries.entries()) {
1939
- const t = await readJsonSafe(path3.join(dir, e.name));
2178
+ const t = await readJsonSafe(path4.join(dir, e.name));
1940
2179
  if (!t || t.status === "deleted") continue;
1941
2180
  const task = {
1942
- id: String(t.id ?? path3.basename(e.name, ".json")),
2181
+ id: String(t.id ?? path4.basename(e.name, ".json")),
1943
2182
  title: String(t.subject ?? t.title ?? ""),
1944
2183
  activeTitle: typeof t.activeForm === "string" ? t.activeForm : void 0,
1945
2184
  status: normStatus(t.status)
@@ -1953,14 +2192,14 @@ var ClaudeCodeAdapter = class {
1953
2192
  }
1954
2193
  }
1955
2194
  }
1956
- const liveFile = path3.join(ctx.liveDir, "claude-code", `${st.sessionId}.json`);
2195
+ const liveFile = path4.join(ctx.liveDir, "claude-code", `${st.sessionId}.json`);
1957
2196
  const lst = await statSafe(liveFile);
1958
2197
  if (!lst) st.live = void 0;
1959
2198
  else if (lst.mtimeMs !== st.live?.mtimeMs) {
1960
2199
  const live = await readJsonSafe(liveFile);
1961
2200
  st.live = live ? { ...live, mtimeMs: lst.mtimeMs } : void 0;
1962
2201
  }
1963
- const pulseFile = path3.join(ctx.liveDir, "claude-code", `${st.sessionId}.mod.json`);
2202
+ const pulseFile = path4.join(ctx.liveDir, "claude-code", `${st.sessionId}.mod.json`);
1964
2203
  const pst = await statSafe(pulseFile);
1965
2204
  if (!pst) st.pulse = void 0;
1966
2205
  else if (pst.mtimeMs !== st.pulse?.mtimeMs) {
@@ -1971,13 +2210,13 @@ var ClaudeCodeAdapter = class {
1971
2210
  const now = ctx.now();
1972
2211
  if (now - st.lastSubagentScan >= 5e3) {
1973
2212
  st.lastSubagentScan = now;
1974
- const subDir = path3.join(st.projectDir, st.sessionId, "subagents");
2213
+ const subDir = path4.join(st.projectDir, st.sessionId, "subagents");
1975
2214
  const dirs = [subDir];
1976
- for (const run of await listDir(path3.join(subDir, "workflows"))) if (run.isDirectory()) dirs.push(path3.join(subDir, "workflows", run.name));
2215
+ for (const run2 of await listDir(path4.join(subDir, "workflows"))) if (run2.isDirectory()) dirs.push(path4.join(subDir, "workflows", run2.name));
1977
2216
  for (const dir of dirs) {
1978
2217
  for (const f of await listDir(dir)) {
1979
2218
  if (!f.isFile() || !f.name.endsWith(".jsonl")) continue;
1980
- const file = path3.join(dir, f.name);
2219
+ const file = path4.join(dir, f.name);
1981
2220
  if (!st.subagents.has(file)) st.subagents.set(file, { tail: new JsonlTail(file) });
1982
2221
  }
1983
2222
  }
@@ -2178,11 +2417,11 @@ var ClaudeCodeAdapter = class {
2178
2417
  };
2179
2418
 
2180
2419
  // ../core/src/adapters/cline.ts
2181
- import path5 from "node:path";
2182
- import { promises as fsp3 } from "node:fs";
2420
+ import path6 from "node:path";
2421
+ import { promises as fsp4 } from "node:fs";
2183
2422
 
2184
2423
  // ../core/src/util/editors.ts
2185
- import path4 from "node:path";
2424
+ import path5 from "node:path";
2186
2425
  var EDITOR_APPS = [
2187
2426
  "Code",
2188
2427
  "Code - Insiders",
@@ -2211,10 +2450,10 @@ var SERVER_DIRS = [
2211
2450
  ];
2212
2451
  function editorUserDataDirs(home, env, platform = process.platform) {
2213
2452
  const out = [];
2214
- if (env.VSCODE_PORTABLE) out.push(path4.join(env.VSCODE_PORTABLE, "user-data"));
2215
- const base = platform === "darwin" ? path4.join(home, "Library", "Application Support") : platform === "win32" ? env.APPDATA ?? path4.join(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME ?? path4.join(home, ".config");
2216
- for (const app of EDITOR_APPS) out.push(path4.join(base, app));
2217
- for (const dir of SERVER_DIRS) out.push(path4.join(home, dir, "data"));
2453
+ if (env.VSCODE_PORTABLE) out.push(path5.join(env.VSCODE_PORTABLE, "user-data"));
2454
+ const base = platform === "darwin" ? path5.join(home, "Library", "Application Support") : platform === "win32" ? env.APPDATA ?? path5.join(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME ?? path5.join(home, ".config");
2455
+ for (const app of EDITOR_APPS) out.push(path5.join(base, app));
2456
+ for (const dir of SERVER_DIRS) out.push(path5.join(home, dir, "data"));
2218
2457
  return out;
2219
2458
  }
2220
2459
 
@@ -2572,14 +2811,14 @@ var ClineFamilyAdapter = class {
2572
2811
  const dirs = /* @__PURE__ */ new Set();
2573
2812
  const storageRoots = [];
2574
2813
  for (const userData of editorUserDataDirs(ctx.home, ctx.env, this.options.platform)) {
2575
- const user = path5.join(userData, "User");
2576
- storageRoots.push(path5.join(user, "globalStorage"));
2577
- for (const p2 of await listDir(path5.join(user, "profiles"))) if (p2.isDirectory()) storageRoots.push(path5.join(user, "profiles", p2.name, "globalStorage"));
2814
+ const user = path6.join(userData, "User");
2815
+ storageRoots.push(path6.join(user, "globalStorage"));
2816
+ for (const p2 of await listDir(path6.join(user, "profiles"))) if (p2.isDirectory()) storageRoots.push(path6.join(user, "profiles", p2.name, "globalStorage"));
2578
2817
  }
2579
2818
  for (const extra of this.options.extraStorageDirs ?? []) storageRoots.push(extra);
2580
2819
  for (const root of storageRoots) {
2581
2820
  for (const e of await listDir(root)) {
2582
- if (e.isDirectory() && this.extensions.includes(e.name.toLowerCase())) dirs.add(path5.join(root, e.name));
2821
+ if (e.isDirectory() && this.extensions.includes(e.name.toLowerCase())) dirs.add(path6.join(root, e.name));
2583
2822
  }
2584
2823
  }
2585
2824
  for (const d of this.standaloneDirs(ctx)) dirs.add(d);
@@ -2592,9 +2831,9 @@ var ClineFamilyAdapter = class {
2592
2831
  const now = ctx.now();
2593
2832
  const found = [];
2594
2833
  for (const store of this.stores.values()) {
2595
- const tasksDir = path5.join(store.dir, "tasks");
2834
+ const tasksDir = path6.join(store.dir, "tasks");
2596
2835
  const names = (await listDir(tasksDir)).filter((e) => e.isDirectory() && !e.name.startsWith(".") && !e.name.startsWith("_")).map((e) => e.name);
2597
- const index = this.flavor === "roo" ? path5.join(tasksDir, "_index.json") : path5.join(store.dir, "state", "taskHistory.json");
2836
+ const index = this.flavor === "roo" ? path6.join(tasksDir, "_index.json") : path6.join(store.dir, "state", "taskHistory.json");
2598
2837
  const indexMtime = (await statSafe(index))?.mtimeMs ?? 0;
2599
2838
  const sweep = now - store.lastSweep >= SWEEP_MS || indexMtime !== store.indexMtime;
2600
2839
  if (sweep) {
@@ -2607,7 +2846,7 @@ var ClineFamilyAdapter = class {
2607
2846
  for (let i = 0; i < toStat.length; i += 64) {
2608
2847
  await Promise.all(
2609
2848
  toStat.slice(i, i + 64).map(async (id) => {
2610
- const st = await statSafe(path5.join(tasksDir, id, "ui_messages.json"));
2849
+ const st = await statSafe(path6.join(tasksDir, id, "ui_messages.json"));
2611
2850
  store.seen.set(id, st?.mtimeMs ?? 0);
2612
2851
  })
2613
2852
  );
@@ -2615,10 +2854,10 @@ var ClineFamilyAdapter = class {
2615
2854
  for (const [id, mtimeMs] of store.seen) if (mtimeMs && now - mtimeMs <= ctx.activeWindowMs) found.push({ store, id, mtimeMs });
2616
2855
  }
2617
2856
  found.sort((a, b) => b.mtimeMs - a.mtimeMs);
2618
- const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [path5.join(f.store.dir, "tasks", f.id), f]));
2857
+ const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [path6.join(f.store.dir, "tasks", f.id), f]));
2619
2858
  for (const [dir, f] of keep) {
2620
2859
  if (this.tracked.has(dir)) continue;
2621
- this.tracked.set(dir, { id: f.id, dir, file: path5.join(dir, "ui_messages.json"), mtimeMs: -1, size: -1, readAt: 0, store: f.store });
2860
+ this.tracked.set(dir, { id: f.id, dir, file: path6.join(dir, "ui_messages.json"), mtimeMs: -1, size: -1, readAt: 0, store: f.store });
2622
2861
  }
2623
2862
  for (const dir of [...this.tracked.keys()]) if (!keep.has(dir)) this.tracked.delete(dir);
2624
2863
  }
@@ -2643,7 +2882,7 @@ var ClineFamilyAdapter = class {
2643
2882
  }
2644
2883
  }
2645
2884
  if (this.flavor === "roo") {
2646
- const hf = path5.join(t.dir, "history_item.json");
2885
+ const hf = path6.join(t.dir, "history_item.json");
2647
2886
  const hs = await statSafe(hf);
2648
2887
  if (hs && hs.mtimeMs !== t.history?.mtimeMs) {
2649
2888
  const value = await readJsonSafe(hf, 4 << 20);
@@ -2651,7 +2890,7 @@ var ClineFamilyAdapter = class {
2651
2890
  }
2652
2891
  const now = ctx.now();
2653
2892
  if (!t.modelFile || now - t.modelFile.checkedAt >= MODEL_CHECK_MS) {
2654
- const mf = path5.join(t.dir, "api_conversation_history.json");
2893
+ const mf = path6.join(t.dir, "api_conversation_history.json");
2655
2894
  const ms = await statSafe(mf);
2656
2895
  const prev = t.modelFile;
2657
2896
  t.modelFile = { mtimeMs: ms?.mtimeMs ?? 0, checkedAt: now, model: prev?.model };
@@ -2665,7 +2904,7 @@ var ClineFamilyAdapter = class {
2665
2904
  async readClineHistory(store, id, now) {
2666
2905
  if (store.history && store.history.byId.has(id) && now - store.history.readAt < HISTORY_EVERY_MS) return;
2667
2906
  if (store.history && now - store.history.readAt < 2e3) return;
2668
- const file = path5.join(store.dir, "state", "taskHistory.json");
2907
+ const file = path6.join(store.dir, "state", "taskHistory.json");
2669
2908
  const st = await statSafe(file);
2670
2909
  if (!st || st.mtimeMs === store.history?.mtimeMs) return;
2671
2910
  const items = await readJsonSafe(file, 64 << 20);
@@ -2750,7 +2989,7 @@ async function lastModelIn(file, size) {
2750
2989
  if (len <= 0) return void 0;
2751
2990
  let fh;
2752
2991
  try {
2753
- fh = await fsp3.open(file, "r");
2992
+ fh = await fsp4.open(file, "r");
2754
2993
  const buf = Buffer.alloc(len);
2755
2994
  await fh.read(buf, 0, len, size - len);
2756
2995
  const text = buf.toString("utf8");
@@ -2765,8 +3004,8 @@ async function lastModelIn(file, size) {
2765
3004
  }
2766
3005
  function clineDataDir(home, env) {
2767
3006
  if (env.CLINE_DATA_DIR) return env.CLINE_DATA_DIR;
2768
- if (env.CLINE_DIR) return path5.join(env.CLINE_DIR, "data");
2769
- return path5.join(home, ".cline", "data");
3007
+ if (env.CLINE_DIR) return path6.join(env.CLINE_DIR, "data");
3008
+ return path6.join(home, ".cline", "data");
2770
3009
  }
2771
3010
  var ClineAdapter = class extends ClineFamilyAdapter {
2772
3011
  id = "cline";
@@ -2790,7 +3029,7 @@ var RooCodeAdapter = class extends ClineFamilyAdapter {
2790
3029
  async customStorageDirs(ctx) {
2791
3030
  const out = [];
2792
3031
  for (const userData of editorUserDataDirs(ctx.home, ctx.env, this.options.platform)) {
2793
- const text = await readTextSafe(path5.join(userData, "User", "settings.json"), 2 << 20);
3032
+ const text = await readTextSafe(path6.join(userData, "User", "settings.json"), 2 << 20);
2794
3033
  const m = text && /"roo-cline\.customStoragePath"\s*:\s*"((?:[^"\\]|\\.)+)"/.exec(text);
2795
3034
  if (m) {
2796
3035
  try {
@@ -2947,7 +3186,7 @@ var ClineSdkSessions = class {
2947
3186
  tracked = /* @__PURE__ */ new Map();
2948
3187
  lastDiscovery = 0;
2949
3188
  root(ctx) {
2950
- return ctx.env.CLINE_SESSION_DATA_DIR || path5.join(clineDataDir(ctx.home, ctx.env), "sessions");
3189
+ return ctx.env.CLINE_SESSION_DATA_DIR || path6.join(clineDataDir(ctx.home, ctx.env), "sessions");
2951
3190
  }
2952
3191
  async poll(ctx, label) {
2953
3192
  const now = ctx.now();
@@ -2971,9 +3210,9 @@ var ClineSdkSessions = class {
2971
3210
  const found = [];
2972
3211
  for (const e of await listDir(root)) {
2973
3212
  if (!e.isDirectory() || e.name.includes("__") || e.name.startsWith(".")) continue;
2974
- const dir = path5.join(root, e.name);
2975
- const manifest = await statSafe(path5.join(dir, `${e.name}.json`));
2976
- const messages = await statSafe(path5.join(dir, `${e.name}.messages.json`));
3213
+ const dir = path6.join(root, e.name);
3214
+ const manifest = await statSafe(path6.join(dir, `${e.name}.json`));
3215
+ const messages = await statSafe(path6.join(dir, `${e.name}.messages.json`));
2977
3216
  const mtimeMs = Math.max(manifest?.mtimeMs ?? 0, messages?.mtimeMs ?? 0);
2978
3217
  if (mtimeMs && now - mtimeMs <= ctx.activeWindowMs) found.push({ dir, id: e.name, mtimeMs });
2979
3218
  }
@@ -2981,7 +3220,7 @@ var ClineSdkSessions = class {
2981
3220
  const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [f.dir, f]));
2982
3221
  for (const [dir, f] of keep) {
2983
3222
  if (!this.tracked.has(dir)) {
2984
- this.tracked.set(dir, { dir, id: f.id, manifestFile: path5.join(dir, `${f.id}.json`), manifestMtime: -1, messagesMtime: -1, messagesSize: -1 });
3223
+ this.tracked.set(dir, { dir, id: f.id, manifestFile: path6.join(dir, `${f.id}.json`), manifestMtime: -1, messagesMtime: -1, messagesSize: -1 });
2985
3224
  }
2986
3225
  }
2987
3226
  for (const dir of [...this.tracked.keys()]) if (!keep.has(dir)) this.tracked.delete(dir);
@@ -2996,7 +3235,7 @@ var ClineSdkSessions = class {
2996
3235
  }
2997
3236
  }
2998
3237
  const declared = typeof t.manifest?.messages_path === "string" ? t.manifest.messages_path : void 0;
2999
- let file = path5.join(t.dir, `${t.id}.messages.json`);
3238
+ let file = path6.join(t.dir, `${t.id}.messages.json`);
3000
3239
  let st = await statSafe(file);
3001
3240
  if (!st && declared) {
3002
3241
  st = await statSafe(declared);
@@ -3103,7 +3342,7 @@ var ClineSdkSessions = class {
3103
3342
  };
3104
3343
 
3105
3344
  // ../core/src/adapters/codex.ts
3106
- import path6 from "node:path";
3345
+ import path7 from "node:path";
3107
3346
  function codexFailure(output) {
3108
3347
  let text = typeof output === "string" ? output : output && typeof output === "object" ? JSON.stringify(output) : "";
3109
3348
  if (!text) return void 0;
@@ -3167,22 +3406,22 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3167
3406
  id = "codex";
3168
3407
  label = "Codex";
3169
3408
  async discover(ctx) {
3170
- const home = ctx.env.CODEX_HOME || path6.join(ctx.home, ".codex");
3171
- const root = path6.join(home, "sessions");
3409
+ const home = ctx.env.CODEX_HOME || path7.join(ctx.home, ".codex");
3410
+ const root = path7.join(home, "sessions");
3172
3411
  const now = ctx.now();
3173
3412
  const days = Math.max(1, Math.ceil(ctx.activeWindowMs / 864e5) + 1);
3174
3413
  const dirs = /* @__PURE__ */ new Set();
3175
3414
  for (let i = 0; i <= days; i += 1) {
3176
3415
  const d = new Date(now - i * 864e5);
3177
3416
  const pad = (n) => String(n).padStart(2, "0");
3178
- dirs.add(path6.join(root, String(d.getFullYear()), pad(d.getMonth() + 1), pad(d.getDate())));
3179
- dirs.add(path6.join(root, String(d.getUTCFullYear()), pad(d.getUTCMonth() + 1), pad(d.getUTCDate())));
3417
+ dirs.add(path7.join(root, String(d.getFullYear()), pad(d.getMonth() + 1), pad(d.getDate())));
3418
+ dirs.add(path7.join(root, String(d.getUTCFullYear()), pad(d.getUTCMonth() + 1), pad(d.getUTCDate())));
3180
3419
  }
3181
3420
  const out = [];
3182
3421
  for (const dir of dirs) {
3183
3422
  for (const f of await listDir(dir)) {
3184
3423
  if (!f.isFile() || !f.name.startsWith("rollout-") || !f.name.endsWith(".jsonl")) continue;
3185
- const file = path6.join(dir, f.name);
3424
+ const file = path7.join(dir, f.name);
3186
3425
  const st = await statSafe(file);
3187
3426
  if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
3188
3427
  }
@@ -3194,7 +3433,7 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3194
3433
  const daily = {};
3195
3434
  return {
3196
3435
  file,
3197
- id: m ? m[1] : path6.basename(file, ".jsonl"),
3436
+ id: m ? m[1] : path7.basename(file, ".jsonl"),
3198
3437
  isSubagent: false,
3199
3438
  updatedAt: 0,
3200
3439
  prevTotal: 0,
@@ -3495,7 +3734,7 @@ function loopOf(st, status, now) {
3495
3734
  }
3496
3735
 
3497
3736
  // ../core/src/adapters/copilot.ts
3498
- import path7 from "node:path";
3737
+ import path8 from "node:path";
3499
3738
 
3500
3739
  // ../core/src/util/sqlite.ts
3501
3740
  var loaded;
@@ -3663,12 +3902,12 @@ function dbStatus(s) {
3663
3902
  return s === "done" ? "completed" : s === "in_progress" ? "in_progress" : s === "blocked" ? "blocked" : "pending";
3664
3903
  }
3665
3904
  function createState(file) {
3666
- const dir = path7.dirname(file);
3905
+ const dir = path8.dirname(file);
3667
3906
  const daily = {};
3668
3907
  return {
3669
3908
  file,
3670
3909
  dir,
3671
- id: path7.basename(dir),
3910
+ id: path8.basename(dir),
3672
3911
  updatedAt: 0,
3673
3912
  workspaceMtime: -1,
3674
3913
  turnOpen: false,
@@ -3912,14 +4151,14 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
3912
4151
  id = "copilot";
3913
4152
  label = "Copilot";
3914
4153
  root(ctx) {
3915
- return ctx.env.COPILOT_HOME || path7.join(ctx.home, ".copilot");
4154
+ return ctx.env.COPILOT_HOME || path8.join(ctx.home, ".copilot");
3916
4155
  }
3917
4156
  async discover(ctx) {
3918
- const dir = path7.join(this.root(ctx), "session-state");
4157
+ const dir = path8.join(this.root(ctx), "session-state");
3919
4158
  const out = [];
3920
4159
  for (const e of await listDir(dir)) {
3921
4160
  if (!e.isDirectory()) continue;
3922
- const file = path7.join(dir, e.name, "events.jsonl");
4161
+ const file = path8.join(dir, e.name, "events.jsonl");
3923
4162
  const st = await statSafe(file);
3924
4163
  if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
3925
4164
  }
@@ -3937,7 +4176,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
3937
4176
  }
3938
4177
  async afterRead(st, ctx) {
3939
4178
  const now = ctx.now();
3940
- const ws = path7.join(st.dir, "workspace.yaml");
4179
+ const ws = path8.join(st.dir, "workspace.yaml");
3941
4180
  const wst = await statSafe(ws);
3942
4181
  if (wst && wst.mtimeMs !== st.workspaceMtime) {
3943
4182
  st.workspaceMtime = wst.mtimeMs;
@@ -3954,7 +4193,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
3954
4193
  st.alive = locks.length ? live.length > 0 : void 0;
3955
4194
  st.pid = live[0];
3956
4195
  }
3957
- const dbFile = path7.join(st.dir, "session.db");
4196
+ const dbFile = path8.join(st.dir, "session.db");
3958
4197
  const dbm = Math.max((await statSafe(dbFile))?.mtimeMs ?? 0, (await statSafe(`${dbFile}-wal`))?.mtimeMs ?? 0);
3959
4198
  if (dbm && dbm !== st.dbMtime) {
3960
4199
  st.dbMtime = dbm;
@@ -4056,7 +4295,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
4056
4295
  };
4057
4296
 
4058
4297
  // ../core/src/adapters/gemini-cli.ts
4059
- import path8 from "node:path";
4298
+ import path9 from "node:path";
4060
4299
  var PENDING_TOOL = /* @__PURE__ */ new Set(["scheduled", "validating", "executing"]);
4061
4300
  function todoStatus2(s) {
4062
4301
  switch (s) {
@@ -4130,8 +4369,8 @@ var GeminiCliAdapter = class {
4130
4369
  const homes = [ctx.env.GEMINI_CLI_HOME, ctx.home].filter((h) => !!h);
4131
4370
  const out = /* @__PURE__ */ new Set();
4132
4371
  for (const h of homes) {
4133
- out.add(path8.join(h, ".gemini", "tmp"));
4134
- out.add(path8.join(h, ".cache", ".gemini", "tmp"));
4372
+ out.add(path9.join(h, ".gemini", "tmp"));
4373
+ out.add(path9.join(h, ".cache", ".gemini", "tmp"));
4135
4374
  }
4136
4375
  return [...out];
4137
4376
  }
@@ -4179,18 +4418,18 @@ var GeminiCliAdapter = class {
4179
4418
  for (const root of this.roots(ctx)) {
4180
4419
  for (const proj of await listDir(root)) {
4181
4420
  if (!proj.isDirectory()) continue;
4182
- const projDir = path8.join(root, proj.name);
4183
- const chats = path8.join(projDir, "chats");
4421
+ const projDir = path9.join(root, proj.name);
4422
+ const chats = path9.join(projDir, "chats");
4184
4423
  const files = (await listDir(chats)).filter(
4185
4424
  (f) => f.isFile() && f.name.startsWith("session-") && (f.name.endsWith(".jsonl") || f.name.endsWith(".json"))
4186
4425
  );
4187
4426
  if (files.length === 0) continue;
4188
4427
  let project;
4189
4428
  for (const f of files) {
4190
- const file = path8.join(chats, f.name);
4429
+ const file = path9.join(chats, f.name);
4191
4430
  const st = await statSafe(file);
4192
4431
  if (!st || now - st.mtimeMs > ctx.activeWindowMs) continue;
4193
- if (project === void 0) project = (await readTextSafe(path8.join(projDir, ".project_root"), 8192))?.trim() || "";
4432
+ if (project === void 0) project = (await readTextSafe(path9.join(projDir, ".project_root"), 8192))?.trim() || "";
4194
4433
  found.push({ file, mtimeMs: st.mtimeMs, project: project || void 0 });
4195
4434
  }
4196
4435
  }
@@ -4320,7 +4559,7 @@ var GeminiCliAdapter = class {
4320
4559
  key: `gemini-cli:${st.sessionId ?? st.file}`,
4321
4560
  agent: "gemini-cli",
4322
4561
  agentLabel: this.label,
4323
- id: st.sessionId ?? path8.basename(st.file),
4562
+ id: st.sessionId ?? path9.basename(st.file),
4324
4563
  title: st.summary ? truncate(st.summary, 100) : title ?? "Untitled session",
4325
4564
  titleFromPrompt: !st.summary && title !== void 0 ? true : void 0,
4326
4565
  projectPath: st.projectPath,
@@ -4351,7 +4590,7 @@ var GeminiCliAdapter = class {
4351
4590
  };
4352
4591
 
4353
4592
  // ../core/src/adapters/opencode.ts
4354
- import path9 from "node:path";
4593
+ import path10 from "node:path";
4355
4594
  var num = (v) => typeof v === "number" && Number.isFinite(v) ? v : Number(v) || 0;
4356
4595
  function parseData(v) {
4357
4596
  if (v && typeof v === "object") return v;
@@ -4663,13 +4902,13 @@ var OpenCodeFamilyAdapter = class {
4663
4902
  this.options = options;
4664
4903
  }
4665
4904
  dataDir(ctx) {
4666
- return path9.join(ctx.env.XDG_DATA_HOME || path9.join(ctx.home, ".local", "share"), this.app);
4905
+ return path10.join(ctx.env.XDG_DATA_HOME || path10.join(ctx.home, ".local", "share"), this.app);
4667
4906
  }
4668
4907
  databaseFile(ctx) {
4669
4908
  if (this.options.dbFile) return this.options.dbFile;
4670
4909
  const override = ctx.env[this.dbEnv];
4671
- if (override && override !== ":memory:") return path9.isAbsolute(override) ? override : path9.join(this.dataDir(ctx), override);
4672
- return path9.join(this.dataDir(ctx), `${this.app}.db`);
4910
+ if (override && override !== ":memory:") return path10.isAbsolute(override) ? override : path10.join(this.dataDir(ctx), override);
4911
+ return path10.join(this.dataDir(ctx), `${this.app}.db`);
4673
4912
  }
4674
4913
  async poll(ctx) {
4675
4914
  const now = ctx.now();
@@ -4898,7 +5137,7 @@ var OpenCodeFamilyAdapter = class {
4898
5137
  const untitled = !rowTitle || /^(New session|Child session)( - \d{4}-\d\d-\d\dT[\d:.]+Z?)?$/.test(rowTitle);
4899
5138
  const title = untitled ? f.title : truncate(rowTitle, 100);
4900
5139
  const model = parseData(row.model);
4901
- const dir = typeof row.directory === "string" && row.directory ? row.directory.replace(/\//g, path9.sep === "\\" ? "\\" : "/") : void 0;
5140
+ const dir = typeof row.directory === "string" && row.directory ? row.directory.replace(/\//g, path10.sep === "\\" ? "\\" : "/") : void 0;
4902
5141
  const rowTokens = "tokens_input" in row ? {
4903
5142
  input: num(row.tokens_input),
4904
5143
  output: num(row.tokens_output) + num(row.tokens_reasoning),
@@ -4973,7 +5212,7 @@ var LiveProbe = class {
4973
5212
  });
4974
5213
  }
4975
5214
  async readService(ctx) {
4976
- const file = path9.join(ctx.env.XDG_STATE_HOME || path9.join(ctx.home, ".local", "state"), "opencode", "service.json");
5215
+ const file = path10.join(ctx.env.XDG_STATE_HOME || path10.join(ctx.home, ".local", "state"), "opencode", "service.json");
4977
5216
  const info = await readJsonSafe(file, 64 << 10);
4978
5217
  const now = ctx.now();
4979
5218
  if (!info || typeof info.url !== "string") {
@@ -5041,8 +5280,8 @@ var KiloCodeAdapter = class extends OpenCodeFamilyAdapter {
5041
5280
  };
5042
5281
 
5043
5282
  // ../core/src/adapters/progress-file.ts
5044
- import { promises as fsp4 } from "node:fs";
5045
- import path10 from "node:path";
5283
+ import { promises as fsp5 } from "node:fs";
5284
+ import path11 from "node:path";
5046
5285
  var STATUS_WORDS = lookupTable({
5047
5286
  working: "working",
5048
5287
  running: "working",
@@ -5061,7 +5300,7 @@ var MAX_PROGRESS_FILES = 20;
5061
5300
  var MAX_LISTED = 500;
5062
5301
  async function realpathSafe(p2) {
5063
5302
  try {
5064
- return await fsp4.realpath(p2);
5303
+ return await fsp5.realpath(p2);
5065
5304
  } catch {
5066
5305
  return void 0;
5067
5306
  }
@@ -5074,10 +5313,10 @@ var ProgressFileAdapter = class {
5074
5313
  async poll(ctx) {
5075
5314
  const files = [];
5076
5315
  for (const root of ctx.workspaceRoots) {
5077
- const agentsDir = path10.join(root, ".agents");
5078
- const names = [path10.join(agentsDir, "progress.md")];
5079
- for (const f of (await listDir(path10.join(agentsDir, "progress"))).slice(0, MAX_LISTED)) {
5080
- if (f.isFile() && f.name.endsWith(".md")) names.push(path10.join(agentsDir, "progress", f.name));
5316
+ const agentsDir = path11.join(root, ".agents");
5317
+ const names = [path11.join(agentsDir, "progress.md")];
5318
+ for (const f of (await listDir(path11.join(agentsDir, "progress"))).slice(0, MAX_LISTED)) {
5319
+ if (f.isFile() && f.name.endsWith(".md")) names.push(path11.join(agentsDir, "progress", f.name));
5081
5320
  }
5082
5321
  const realRoot = await realpathSafe(root);
5083
5322
  if (!realRoot) continue;
@@ -5152,7 +5391,7 @@ var ProgressFileAdapter = class {
5152
5391
 
5153
5392
  // ../core/src/engine.ts
5154
5393
  function defaultLiveDir(home = os.homedir()) {
5155
- return path11.join(home, ".kvali", "live");
5394
+ return path12.join(home, ".kvali", "live");
5156
5395
  }
5157
5396
  function createDefaultAdapters(opts = {}) {
5158
5397
  return [
@@ -5352,31 +5591,31 @@ var Engine = class {
5352
5591
  };
5353
5592
 
5354
5593
  // ../core/src/hooks/hub.ts
5355
- import { promises as fsp6 } from "node:fs";
5594
+ import { promises as fsp7 } from "node:fs";
5356
5595
  import http from "node:http";
5357
- import path12 from "node:path";
5596
+ import path13 from "node:path";
5358
5597
 
5359
5598
  // ../core/src/util/files.ts
5360
5599
  import { randomBytes } from "node:crypto";
5361
- import { promises as fsp5 } from "node:fs";
5600
+ import { promises as fsp6 } from "node:fs";
5362
5601
  async function writeFileSafely(file, text, mode) {
5363
5602
  let current;
5364
5603
  try {
5365
- const st = await fsp5.lstat(file);
5604
+ const st = await fsp6.lstat(file);
5366
5605
  current = { link: st.isSymbolicLink(), mode: st.mode & 511 };
5367
5606
  } catch {
5368
5607
  }
5369
5608
  if (current?.link) {
5370
- await fsp5.writeFile(file, text);
5609
+ await fsp6.writeFile(file, text);
5371
5610
  return;
5372
5611
  }
5373
5612
  const tmp = `${file}.kvali-${process.pid}-${randomBytes(4).toString("hex")}.tmp`;
5374
5613
  try {
5375
- await fsp5.writeFile(tmp, text, { mode: mode ?? current?.mode ?? 420, flag: "wx" });
5376
- if (current) await fsp5.chmod(tmp, mode ?? current.mode);
5377
- await fsp5.rename(tmp, file);
5614
+ await fsp6.writeFile(tmp, text, { mode: mode ?? current?.mode ?? 420, flag: "wx" });
5615
+ if (current) await fsp6.chmod(tmp, mode ?? current.mode);
5616
+ await fsp6.rename(tmp, file);
5378
5617
  } catch (err) {
5379
- await fsp5.rm(tmp, { force: true }).catch(() => void 0);
5618
+ await fsp6.rm(tmp, { force: true }).catch(() => void 0);
5380
5619
  throw err;
5381
5620
  }
5382
5621
  }
@@ -5528,40 +5767,40 @@ var HookHub = class {
5528
5767
  }
5529
5768
  }
5530
5769
  async store(agent, ev) {
5531
- const dir = path12.join(this.opts.liveDir, agent);
5532
- await fsp6.mkdir(dir, { recursive: true, mode: 448 });
5533
- await writeFileSafely(path12.join(dir, `${ev.sessionId}.json`), JSON.stringify(ev), 384);
5770
+ const dir = path13.join(this.opts.liveDir, agent);
5771
+ await fsp7.mkdir(dir, { recursive: true, mode: 448 });
5772
+ await writeFileSafely(path13.join(dir, `${ev.sessionId}.json`), JSON.stringify(ev), 384);
5534
5773
  }
5535
5774
  };
5536
5775
 
5537
5776
  // ../core/src/hooks/claude-install.ts
5538
- import { promises as fsp8 } from "node:fs";
5777
+ import { promises as fsp9 } from "node:fs";
5539
5778
  import os2 from "node:os";
5540
- import path14 from "node:path";
5779
+ import path15 from "node:path";
5541
5780
 
5542
5781
  // ../core/src/hooks/claude-plugin.ts
5543
- import { execFile } from "node:child_process";
5782
+ import { execFile as execFile2 } from "node:child_process";
5544
5783
  import { createHash } from "node:crypto";
5545
- import { constants as fsc, promises as fsp7 } from "node:fs";
5546
- import path13 from "node:path";
5784
+ import { constants as fsc, promises as fsp8 } from "node:fs";
5785
+ import path14 from "node:path";
5547
5786
  var CLAUDE_PLUGIN_ID = "kvali@kvali";
5548
5787
  var CLAUDE_MARKETPLACE = "kvali";
5549
- var kvaliPluginDir = (home) => path13.join(home, ".kvali", "claude-plugin");
5550
- var stateFile = (home) => path13.join(home, ".kvali", "state.json");
5788
+ var kvaliPluginDir = (home) => path14.join(home, ".kvali", "claude-plugin");
5789
+ var stateFile = (home) => path14.join(home, ".kvali", "state.json");
5551
5790
  async function filesUnder(dir, base = dir) {
5552
5791
  const out = [];
5553
5792
  let entries;
5554
5793
  try {
5555
- entries = await fsp7.readdir(dir, { withFileTypes: true });
5794
+ entries = await fsp8.readdir(dir, { withFileTypes: true });
5556
5795
  } catch {
5557
5796
  return out;
5558
5797
  }
5559
5798
  for (const e of entries) {
5560
- const full = path13.join(dir, e.name);
5799
+ const full = path14.join(dir, e.name);
5561
5800
  if (e.isDirectory()) {
5562
- if (path13.relative(base, full) === path13.join(".claude-plugin", "types")) continue;
5801
+ if (path14.relative(base, full) === path14.join(".claude-plugin", "types")) continue;
5563
5802
  out.push(...await filesUnder(full, base));
5564
- } else if (e.isFile()) out.push(path13.relative(base, full));
5803
+ } else if (e.isFile()) out.push(path14.relative(base, full));
5565
5804
  }
5566
5805
  return out.sort();
5567
5806
  }
@@ -5570,16 +5809,16 @@ async function pluginFingerprint(dir) {
5570
5809
  if (!files.length) return void 0;
5571
5810
  const h = createHash("sha256");
5572
5811
  for (const f of files) {
5573
- h.update(f.split(path13.sep).join("/"));
5812
+ h.update(f.split(path14.sep).join("/"));
5574
5813
  h.update("\0");
5575
- h.update(await fsp7.readFile(path13.join(dir, f)));
5814
+ h.update(await fsp8.readFile(path14.join(dir, f)));
5576
5815
  h.update("\0");
5577
5816
  }
5578
5817
  return h.digest("hex");
5579
5818
  }
5580
5819
  async function pluginVersion(dir) {
5581
5820
  try {
5582
- const v = JSON.parse(await fsp7.readFile(path13.join(dir, ".claude-plugin", "plugin.json"), "utf8")).version;
5821
+ const v = JSON.parse(await fsp8.readFile(path14.join(dir, ".claude-plugin", "plugin.json"), "utf8")).version;
5583
5822
  return typeof v === "string" ? v : void 0;
5584
5823
  } catch {
5585
5824
  return void 0;
@@ -5599,28 +5838,28 @@ async function syncClaudePlugin(bundledDir, home) {
5599
5838
  const [mine, theirs] = await Promise.all([pluginVersion(bundledDir), pluginVersion(target)]);
5600
5839
  if (mine && theirs && compareVersions(mine, theirs) < 0) return false;
5601
5840
  const next = `${target}.next`;
5602
- await fsp7.rm(next, { recursive: true, force: true });
5603
- await fsp7.mkdir(path13.dirname(target), { recursive: true });
5604
- await fsp7.cp(bundledDir, next, { recursive: true });
5605
- await fsp7.rm(target, { recursive: true, force: true });
5606
- await fsp7.rename(next, target);
5841
+ await fsp8.rm(next, { recursive: true, force: true });
5842
+ await fsp8.mkdir(path14.dirname(target), { recursive: true });
5843
+ await fsp8.cp(bundledDir, next, { recursive: true });
5844
+ await fsp8.rm(target, { recursive: true, force: true });
5845
+ await fsp8.rename(next, target);
5607
5846
  return true;
5608
5847
  }
5609
5848
  async function claudeExtensionDirs(home) {
5610
5849
  const roots = [".vscode", ".vscode-insiders", ".vscode-oss", ".cursor", ".windsurf", ".antigravity", ".antigravity-ide", ".kiro"].map(
5611
- (d) => path13.join(home, d, "extensions")
5850
+ (d) => path14.join(home, d, "extensions")
5612
5851
  );
5613
5852
  const found = [];
5614
5853
  for (const root of roots) {
5615
5854
  let names = [];
5616
5855
  try {
5617
- names = await fsp7.readdir(root);
5856
+ names = await fsp8.readdir(root);
5618
5857
  } catch {
5619
5858
  continue;
5620
5859
  }
5621
- for (const n of names) if (n.toLowerCase().startsWith("anthropic.claude-code-")) found.push(path13.join(root, n));
5860
+ for (const n of names) if (n.toLowerCase().startsWith("anthropic.claude-code-")) found.push(path14.join(root, n));
5622
5861
  }
5623
- const ver = (p2) => (/-(\d+)\.(\d+)\.(\d+)/.exec(path13.basename(p2)) ?? []).slice(1).map(Number);
5862
+ const ver = (p2) => (/-(\d+)\.(\d+)\.(\d+)/.exec(path14.basename(p2)) ?? []).slice(1).map(Number);
5624
5863
  return found.sort((a, b) => {
5625
5864
  const [x, y] = [ver(a), ver(b)];
5626
5865
  for (let i = 0; i < 3; i += 1) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (y[i] ?? 0) - (x[i] ?? 0);
@@ -5632,23 +5871,23 @@ async function findClaudeBinary(opts) {
5632
5871
  const names = win ? ["claude.exe", "claude.cmd"] : ["claude"];
5633
5872
  const candidates = [];
5634
5873
  for (const d of opts.extensionDirs ?? []) {
5635
- const bin = path13.join(d, "resources", "native-binary");
5874
+ const bin = path14.join(d, "resources", "native-binary");
5636
5875
  let inside = [];
5637
5876
  try {
5638
- inside = await fsp7.readdir(bin);
5877
+ inside = await fsp8.readdir(bin);
5639
5878
  } catch {
5640
5879
  continue;
5641
5880
  }
5642
5881
  const ranked = inside.filter((n) => /^claude([-.].*)?$/i.test(n) && !/\.(json|md|txt|map)$/i.test(n)).sort((x, y) => x.length - y.length);
5643
- for (const n of ranked) candidates.push(path13.join(bin, n));
5882
+ for (const n of ranked) candidates.push(path14.join(bin, n));
5644
5883
  }
5645
- for (const dir of (opts.env?.PATH ?? opts.env?.Path ?? "").split(path13.delimiter)) if (dir) for (const n of names) candidates.push(path13.join(dir, n));
5646
- candidates.push(path13.join(opts.home, ".claude", "local", names[0]), path13.join(opts.home, ".local", "bin", names[0]));
5884
+ for (const dir of (opts.env?.PATH ?? opts.env?.Path ?? "").split(path14.delimiter)) if (dir) for (const n of names) candidates.push(path14.join(dir, n));
5885
+ candidates.push(path14.join(opts.home, ".claude", "local", names[0]), path14.join(opts.home, ".local", "bin", names[0]));
5647
5886
  if (!win) candidates.push("/opt/homebrew/bin/claude", "/usr/local/bin/claude");
5648
5887
  for (const c of candidates) {
5649
5888
  try {
5650
- await fsp7.access(c, win ? fsc.F_OK : fsc.X_OK);
5651
- if ((await fsp7.stat(c)).isFile()) return c;
5889
+ await fsp8.access(c, win ? fsc.F_OK : fsc.X_OK);
5890
+ if ((await fsp8.stat(c)).isFile()) return c;
5652
5891
  } catch {
5653
5892
  }
5654
5893
  }
@@ -5658,7 +5897,7 @@ function runClaude(bin, args, env, timeoutMs = 6e4) {
5658
5897
  const cmdShim = process.platform === "win32" && /\.cmd$/i.test(bin);
5659
5898
  const argv = cmdShim ? args.map((a) => /[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a) : [...args];
5660
5899
  return new Promise((resolve) => {
5661
- execFile(
5900
+ execFile2(
5662
5901
  cmdShim ? `"${bin}"` : bin,
5663
5902
  argv,
5664
5903
  { env, timeout: timeoutMs, windowsHide: true, maxBuffer: 8 * 1024 * 1024, shell: cmdShim },
@@ -5701,7 +5940,7 @@ async function installClaudePlugin(bin, dir, env) {
5701
5940
  }
5702
5941
  async function claudePluginEnabled(settingsFile) {
5703
5942
  try {
5704
- const s = JSON.parse(await fsp7.readFile(settingsFile, "utf8"));
5943
+ const s = JSON.parse(await fsp8.readFile(settingsFile, "utf8"));
5705
5944
  return s?.enabledPlugins?.[CLAUDE_PLUGIN_ID] === true;
5706
5945
  } catch {
5707
5946
  return false;
@@ -5709,14 +5948,14 @@ async function claudePluginEnabled(settingsFile) {
5709
5948
  }
5710
5949
  async function readKvaliState(home) {
5711
5950
  try {
5712
- return JSON.parse(await fsp7.readFile(stateFile(home), "utf8")) ?? {};
5951
+ return JSON.parse(await fsp8.readFile(stateFile(home), "utf8")) ?? {};
5713
5952
  } catch {
5714
5953
  return {};
5715
5954
  }
5716
5955
  }
5717
5956
  async function writeKvaliState(home, patch) {
5718
5957
  const next = { ...await readKvaliState(home), ...patch };
5719
- await fsp7.mkdir(path13.dirname(stateFile(home)), { recursive: true, mode: 448 });
5958
+ await fsp8.mkdir(path14.dirname(stateFile(home)), { recursive: true, mode: 448 });
5720
5959
  await writeFileSafely(stateFile(home), `${JSON.stringify(next, null, 2)}
5721
5960
  `);
5722
5961
  }
@@ -5729,12 +5968,12 @@ async function removeClaudePlugin(opts) {
5729
5968
  const list = await runClaude(opts.bin, ["plugin", "marketplace", "list", "--json"], opts.env);
5730
5969
  try {
5731
5970
  const mk = JSON.parse(list.out.slice(list.out.indexOf("["))).find((m) => m.name === CLAUDE_MARKETPLACE);
5732
- if (mk && mk.path && path13.resolve(mk.path) === path13.resolve(dir)) await runClaude(opts.bin, ["plugin", "marketplace", "remove", CLAUDE_MARKETPLACE], opts.env);
5971
+ if (mk && mk.path && path14.resolve(mk.path) === path14.resolve(dir)) await runClaude(opts.bin, ["plugin", "marketplace", "remove", CLAUDE_MARKETPLACE], opts.env);
5733
5972
  } catch {
5734
5973
  }
5735
5974
  } else {
5736
5975
  try {
5737
- const raw = await fsp7.readFile(opts.settingsFile, "utf8");
5976
+ const raw = await fsp8.readFile(opts.settingsFile, "utf8");
5738
5977
  const s = JSON.parse(raw);
5739
5978
  let changed = false;
5740
5979
  if (s.enabledPlugins && CLAUDE_PLUGIN_ID in s.enabledPlugins) {
@@ -5742,16 +5981,16 @@ async function removeClaudePlugin(opts) {
5742
5981
  changed = true;
5743
5982
  }
5744
5983
  const mk = s.extraKnownMarketplaces?.[CLAUDE_MARKETPLACE];
5745
- if (mk?.source?.path && path13.resolve(mk.source.path) === path13.resolve(dir)) {
5984
+ if (mk?.source?.path && path14.resolve(mk.source.path) === path14.resolve(dir)) {
5746
5985
  delete s.extraKnownMarketplaces[CLAUDE_MARKETPLACE];
5747
5986
  changed = true;
5748
5987
  }
5749
- if (changed) await fsp7.writeFile(opts.settingsFile, `${JSON.stringify(s, null, 2)}
5988
+ if (changed) await fsp8.writeFile(opts.settingsFile, `${JSON.stringify(s, null, 2)}
5750
5989
  `);
5751
5990
  } catch {
5752
5991
  }
5753
5992
  }
5754
- await fsp7.rm(dir, { recursive: true, force: true });
5993
+ await fsp8.rm(dir, { recursive: true, force: true });
5755
5994
  await writeKvaliState(opts.home, { claudePlugin: false });
5756
5995
  return true;
5757
5996
  }
@@ -5766,8 +6005,8 @@ var CLAUDE_HOOKS = [
5766
6005
  var CLAUDE_HOOK_EVENTS = CLAUDE_HOOKS.map((h) => h.event);
5767
6006
  var MARKER = "/v1/events/claude-code";
5768
6007
  function claudeSettingsPath(home = os2.homedir(), env = process.env) {
5769
- const dir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path14.join(home, ".claude");
5770
- return path14.join(dir, "settings.json");
6008
+ const dir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path15.join(home, ".claude");
6009
+ return path15.join(dir, "settings.json");
5771
6010
  }
5772
6011
  function claudeHookCommand(port = DEFAULT_HOOK_PORT, sync = false) {
5773
6012
  const url = `http://127.0.0.1:${port}${MARKER}`;
@@ -5779,7 +6018,7 @@ function hookEntry(spec, port) {
5779
6018
  async function readSettings(file) {
5780
6019
  let text;
5781
6020
  try {
5782
- text = await fsp8.readFile(file, "utf8");
6021
+ text = await fsp9.readFile(file, "utf8");
5783
6022
  } catch (err) {
5784
6023
  if (err.code === "ENOENT") return {};
5785
6024
  throw err;
@@ -5836,7 +6075,7 @@ async function claudeHooksStatus(file = claudeSettingsPath(), port = DEFAULT_HOO
5836
6075
  return current === CLAUDE_HOOKS.length && total === CLAUDE_HOOKS.length ? "installed" : "outdated";
5837
6076
  }
5838
6077
  async function writeWithBackup(file, before, settings) {
5839
- await fsp8.mkdir(path14.dirname(file), { recursive: true });
6078
+ await fsp9.mkdir(path15.dirname(file), { recursive: true });
5840
6079
  let backup;
5841
6080
  if (before !== void 0) {
5842
6081
  backup = `${file}.kvali-backup`;
@@ -5852,7 +6091,7 @@ function canonical(v) {
5852
6091
  );
5853
6092
  }
5854
6093
  async function installClaudeHooks(file = claudeSettingsPath(), port = DEFAULT_HOOK_PORT) {
5855
- const before = await fsp8.readFile(file, "utf8").catch(() => void 0);
6094
+ const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
5856
6095
  const current = await readSettings(file);
5857
6096
  const settings = withoutKvali(current);
5858
6097
  settings.hooks = settings.hooks && typeof settings.hooks === "object" ? settings.hooks : {};
@@ -5868,7 +6107,7 @@ function envOf(settings) {
5868
6107
  return settings.env && typeof settings.env === "object" && !Array.isArray(settings.env) ? settings.env : void 0;
5869
6108
  }
5870
6109
  async function enableClaudeTodoTools(file, home) {
5871
- const before = await fsp8.readFile(file, "utf8").catch(() => void 0);
6110
+ const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
5872
6111
  const settings = await readSettings(file);
5873
6112
  const env = envOf(settings);
5874
6113
  if (env && CLAUDE_TODO_TOOLS_ENV in env) return { changed: false };
@@ -5879,7 +6118,7 @@ async function enableClaudeTodoTools(file, home) {
5879
6118
  }
5880
6119
  async function disableClaudeTodoTools(file, home) {
5881
6120
  if (!(await readKvaliState(home)).claudeTodoTools) return { changed: false };
5882
- const before = await fsp8.readFile(file, "utf8").catch(() => void 0);
6121
+ const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
5883
6122
  let changed = false;
5884
6123
  if (before !== void 0) {
5885
6124
  const settings = await readSettings(file);
@@ -5896,7 +6135,7 @@ async function disableClaudeTodoTools(file, home) {
5896
6135
  return { changed };
5897
6136
  }
5898
6137
  async function uninstallClaudeHooks(file = claudeSettingsPath()) {
5899
- const before = await fsp8.readFile(file, "utf8").catch(() => void 0);
6138
+ const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
5900
6139
  if (before === void 0) return { changed: false };
5901
6140
  const settings = await readSettings(file);
5902
6141
  const next = withoutKvali(settings);
@@ -5905,8 +6144,8 @@ async function uninstallClaudeHooks(file = claudeSettingsPath()) {
5905
6144
  }
5906
6145
 
5907
6146
  // ../core/src/protocol.ts
5908
- import { promises as fsp9 } from "node:fs";
5909
- import path15 from "node:path";
6147
+ import { promises as fsp10 } from "node:fs";
6148
+ import path16 from "node:path";
5910
6149
  var PROGRESS_PROTOCOL_MARKER = "<!-- kvali:progress-protocol v2 -->";
5911
6150
  function progressProtocolSnippet() {
5912
6151
  return `${PROGRESS_PROTOCOL_MARKER}
@@ -5981,13 +6220,13 @@ function withBlock(text, name, snippet) {
5981
6220
  return { text: `${text}${sep}${snippet}`, result: "added" };
5982
6221
  }
5983
6222
  function globalInstructionFiles(home, env = {}) {
5984
- const claude = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path15.join(home, ".claude");
5985
- const codex = env.CODEX_HOME || path15.join(home, ".codex");
5986
- const gemini = path15.join(home, ".gemini");
6223
+ const claude = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path16.join(home, ".claude");
6224
+ const codex = env.CODEX_HOME || path16.join(home, ".codex");
6225
+ const gemini = path16.join(home, ".gemini");
5987
6226
  return [
5988
- { id: "claude-code", agent: "Claude Code", dir: claude, file: path15.join(claude, "CLAUDE.md") },
5989
- { id: "codex", agent: "Codex", dir: codex, file: path15.join(codex, "AGENTS.md") },
5990
- { id: "gemini", agent: "Gemini CLI / Antigravity", dir: gemini, file: path15.join(gemini, "GEMINI.md") }
6227
+ { id: "claude-code", agent: "Claude Code", dir: claude, file: path16.join(claude, "CLAUDE.md") },
6228
+ { id: "codex", agent: "Codex", dir: codex, file: path16.join(codex, "AGENTS.md") },
6229
+ { id: "gemini", agent: "Gemini CLI / Antigravity", dir: gemini, file: path16.join(gemini, "GEMINI.md") }
5991
6230
  ];
5992
6231
  }
5993
6232
  function withoutBlock(text, name) {
@@ -6005,13 +6244,13 @@ async function removeGlobalPlanRule(home, env = {}) {
6005
6244
  for (const target of globalInstructionFiles(home, env)) {
6006
6245
  let text;
6007
6246
  try {
6008
- text = await fsp9.readFile(target.file, "utf8");
6247
+ text = await fsp10.readFile(target.file, "utf8");
6009
6248
  } catch {
6010
6249
  continue;
6011
6250
  }
6012
6251
  const next = withoutBlock(text, "plan-rule");
6013
6252
  if (next === void 0) continue;
6014
- if (next.trim() === "") await fsp9.unlink(target.file);
6253
+ if (next.trim() === "") await fsp10.unlink(target.file);
6015
6254
  else await writeFileSafely(target.file, next);
6016
6255
  changed.push(target.file);
6017
6256
  }
@@ -6019,7 +6258,7 @@ async function removeGlobalPlanRule(home, env = {}) {
6019
6258
  }
6020
6259
  async function readOptional(file) {
6021
6260
  try {
6022
- return await fsp9.readFile(file, "utf8");
6261
+ return await fsp10.readFile(file, "utf8");
6023
6262
  } catch {
6024
6263
  return void 0;
6025
6264
  }
@@ -6029,7 +6268,7 @@ async function addGlobalPlanRule(home, env = {}, only) {
6029
6268
  for (const target of globalInstructionFiles(home, env)) {
6030
6269
  if (only && !only.includes(target.id)) continue;
6031
6270
  try {
6032
- const st = await fsp9.stat(target.dir);
6271
+ const st = await fsp10.stat(target.dir);
6033
6272
  if (!st.isDirectory()) continue;
6034
6273
  } catch {
6035
6274
  continue;
@@ -6041,7 +6280,7 @@ async function addGlobalPlanRule(home, env = {}, only) {
6041
6280
  return out;
6042
6281
  }
6043
6282
  async function addProgressProtocol(root) {
6044
- const file = path15.join(root, "AGENTS.md");
6283
+ const file = path16.join(root, "AGENTS.md");
6045
6284
  const current = await readOptional(file);
6046
6285
  const next = withBlock(current ?? "# AGENTS.md\n\n", "progress-protocol", progressProtocolSnippet());
6047
6286
  if (next.result !== "exists") await writeFileSafely(file, next.text);
@@ -6050,11 +6289,11 @@ async function addProgressProtocol(root) {
6050
6289
 
6051
6290
  // ../core/src/hooks/replies.ts
6052
6291
  import { existsSync as existsSync2 } from "node:fs";
6053
- import path16 from "node:path";
6292
+ import path17 from "node:path";
6054
6293
  var CLAUDE_PLAN_CONTEXT = "Progress tracking (Kvali): if this request takes more than two steps, start by creating a task list with TaskCreate or TodoWrite, whichever you have (if neither is in your tool list, look for them once with ToolSearch, and go on without a list if they are not there), keep exactly one task in_progress, and mark each task completed as soon as it is done. The user follows your progress from that list, so keep it current.";
6055
6294
  function pluginRunsIn(liveDir, sessionId) {
6056
6295
  if (!/^[A-Za-z0-9-]{8,80}$/.test(sessionId)) return false;
6057
- return existsSync2(path16.join(liveDir, "claude-code", `${sessionId}.mod.json`));
6296
+ return existsSync2(path17.join(liveDir, "claude-code", `${sessionId}.mod.json`));
6058
6297
  }
6059
6298
  function claudeHookReply(ev, session, pluginRuns = false) {
6060
6299
  if (ev.event !== "UserPromptSubmit") return void 0;
@@ -6067,23 +6306,23 @@ function claudeHookReply(ev, session, pluginRuns = false) {
6067
6306
  }
6068
6307
 
6069
6308
  // ../core/src/setup.ts
6070
- import { promises as fsp10 } from "node:fs";
6071
- import path17 from "node:path";
6309
+ import { promises as fsp11 } from "node:fs";
6310
+ import path18 from "node:path";
6072
6311
  async function isDir(p2) {
6073
6312
  try {
6074
- return (await fsp10.stat(p2)).isDirectory();
6313
+ return (await fsp11.stat(p2)).isDirectory();
6075
6314
  } catch {
6076
6315
  return false;
6077
6316
  }
6078
6317
  }
6079
6318
  async function detectAgents(home, env = {}) {
6080
- const claudeDir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path17.join(home, ".claude");
6319
+ const claudeDir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path18.join(home, ".claude");
6081
6320
  const [claude, codex, gemini, ag1, ag2] = await Promise.all([
6082
6321
  isDir(claudeDir),
6083
- isDir(env.CODEX_HOME || path17.join(home, ".codex")),
6084
- isDir(path17.join(home, ".gemini")),
6085
- isDir(path17.join(home, ".gemini", "antigravity")),
6086
- isDir(path17.join(home, ".gemini", "antigravity-ide"))
6322
+ isDir(env.CODEX_HOME || path18.join(home, ".codex")),
6323
+ isDir(path18.join(home, ".gemini")),
6324
+ isDir(path18.join(home, ".gemini", "antigravity")),
6325
+ isDir(path18.join(home, ".gemini", "antigravity-ide"))
6087
6326
  ]);
6088
6327
  return { claude, codex, gemini, antigravity: ag1 || ag2 };
6089
6328
  }
@@ -6142,8 +6381,8 @@ async function removeSetup(home, env = {}, opts = {}) {
6142
6381
 
6143
6382
  // ../core/src/phone.ts
6144
6383
  import { randomBytes as randomBytes2, randomInt } from "node:crypto";
6145
- import { promises as fsp11 } from "node:fs";
6146
- import path18 from "node:path";
6384
+ import { promises as fsp12 } from "node:fs";
6385
+ import path19 from "node:path";
6147
6386
  var PHONE_EVENTS = ["needs-you", "done", "steps", "actions", "error", "stuck", "limits"];
6148
6387
  var DEFAULT_PHONE_EVENTS = ["needs-you", "done", "error", "stuck", "steps", "limits"];
6149
6388
  var DEFAULT_EVENTS_V1 = ["needs-you", "done", "error", "stuck"];
@@ -6151,7 +6390,7 @@ var DEFAULT_EVENTS_V2 = ["needs-you", "done", "error", "stuck", "steps"];
6151
6390
  var PHONE_CONFIG_VERSION = 3;
6152
6391
  var DEFAULT_NTFY_SERVER = "https://ntfy.sh";
6153
6392
  var DEFAULT_DONE_AFTER_SEC = 120;
6154
- var kvaliConfigFile = (home) => path18.join(home, ".kvali", "config.json");
6393
+ var kvaliConfigFile = (home) => path19.join(home, ".kvali", "config.json");
6155
6394
  var TOPIC_RE = /^[A-Za-z0-9_-]{1,64}$/;
6156
6395
  var TELEGRAM_TOKEN_RE = /^\d{5,15}:[A-Za-z0-9_-]{30,64}$/;
6157
6396
  var DISCORD_WEBHOOK_RE = /^https:\/\/(?:(?:ptb|canary)\.)?discord(?:app)?\.com\/api\/webhooks\/\d{5,25}\/[A-Za-z0-9_-]{20,120}$/;
@@ -6191,7 +6430,7 @@ function normalizePhoneConfig(raw) {
6191
6430
  }
6192
6431
  async function readPhoneConfig(home) {
6193
6432
  try {
6194
- const all = JSON.parse(await fsp11.readFile(kvaliConfigFile(home), "utf8"));
6433
+ const all = JSON.parse(await fsp12.readFile(kvaliConfigFile(home), "utf8"));
6195
6434
  return normalizePhoneConfig(all?.phone);
6196
6435
  } catch {
6197
6436
  return void 0;
@@ -6201,7 +6440,7 @@ async function writePhoneConfig(home, cfg) {
6201
6440
  const file = kvaliConfigFile(home);
6202
6441
  let all = {};
6203
6442
  try {
6204
- const parsed = JSON.parse(await fsp11.readFile(file, "utf8"));
6443
+ const parsed = JSON.parse(await fsp12.readFile(file, "utf8"));
6205
6444
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) all = parsed;
6206
6445
  } catch {
6207
6446
  }
@@ -6218,14 +6457,14 @@ async function writePhoneConfig(home, cfg) {
6218
6457
  doneAfter: cfg.doneAfterSec ?? DEFAULT_DONE_AFTER_SEC
6219
6458
  };
6220
6459
  else delete all.phone;
6221
- await fsp11.mkdir(path18.dirname(file), { recursive: true, mode: 448 });
6460
+ await fsp12.mkdir(path19.dirname(file), { recursive: true, mode: 448 });
6222
6461
  await writeFileSafely(file, `${JSON.stringify(all, null, 2)}
6223
6462
  `, 384);
6224
6463
  }
6225
6464
  async function secureKvaliHome(home, create = false) {
6226
- const dir = path18.dirname(kvaliConfigFile(home));
6227
- if (create) await fsp11.mkdir(dir, { recursive: true, mode: 448 }).catch(() => void 0);
6228
- await fsp11.chmod(dir, 448).catch(() => void 0);
6465
+ const dir = path19.dirname(kvaliConfigFile(home));
6466
+ if (create) await fsp12.mkdir(dir, { recursive: true, mode: 448 }).catch(() => void 0);
6467
+ await fsp12.chmod(dir, 448).catch(() => void 0);
6229
6468
  }
6230
6469
  function newTopic() {
6231
6470
  const alphabet = "abcdefghijkmnpqrstuvwxyz23456789";
@@ -6840,7 +7079,7 @@ var PhoneNotifier = class {
6840
7079
  const now = Date.now();
6841
7080
  if (!force && now - this.checkedAt < 5e3) return;
6842
7081
  this.checkedAt = now;
6843
- const st = await fsp11.stat(kvaliConfigFile(this.opts.home)).catch(() => void 0);
7082
+ const st = await fsp12.stat(kvaliConfigFile(this.opts.home)).catch(() => void 0);
6844
7083
  const mtime = st?.mtimeMs ?? 0;
6845
7084
  if (!force && mtime === this.mtime) return;
6846
7085
  this.mtime = mtime;
@@ -6855,7 +7094,7 @@ var PhoneNotifier = class {
6855
7094
  this.again = true;
6856
7095
  return this.running;
6857
7096
  }
6858
- const run = (async () => {
7097
+ const run2 = (async () => {
6859
7098
  try {
6860
7099
  do {
6861
7100
  this.again = false;
@@ -6865,8 +7104,8 @@ var PhoneNotifier = class {
6865
7104
  this.running = void 0;
6866
7105
  }
6867
7106
  })();
6868
- this.running = run;
6869
- return run;
7107
+ this.running = run2;
7108
+ return run2;
6870
7109
  }
6871
7110
  /** Looks again every few seconds until `dispose`. */
6872
7111
  start() {
@@ -8580,7 +8819,7 @@ function qrTerminal(text, color = true) {
8580
8819
  }
8581
8820
 
8582
8821
  // src/index.ts
8583
- var VERSION = "0.7.6";
8822
+ var VERSION = "0.7.7";
8584
8823
  function parse(argv) {
8585
8824
  const opts = {
8586
8825
  json: false,
@@ -8594,7 +8833,8 @@ function parse(argv) {
8594
8833
  private: false,
8595
8834
  steps: void 0,
8596
8835
  events: void 0,
8597
- doneAfter: void 0
8836
+ doneAfter: void 0,
8837
+ keepAwake: "off"
8598
8838
  };
8599
8839
  const cmd = [];
8600
8840
  for (let i = 0; i < argv.length; i += 1) {
@@ -8613,7 +8853,7 @@ function parse(argv) {
8613
8853
  break;
8614
8854
  case "--project":
8615
8855
  case "-p":
8616
- opts.project = path19.resolve(next());
8856
+ opts.project = path20.resolve(next());
8617
8857
  break;
8618
8858
  case "--here":
8619
8859
  opts.project = process2.cwd();
@@ -8625,10 +8865,10 @@ function parse(argv) {
8625
8865
  break;
8626
8866
  }
8627
8867
  case "--home":
8628
- opts.home = path19.resolve(next());
8868
+ opts.home = path20.resolve(next());
8629
8869
  break;
8630
8870
  case "--brain-dir":
8631
- opts.brainDirs.push(path19.resolve(next()));
8871
+ opts.brainDirs.push(path20.resolve(next()));
8632
8872
  break;
8633
8873
  case "--port": {
8634
8874
  const port = Number(next());
@@ -8671,6 +8911,12 @@ function parse(argv) {
8671
8911
  opts.doneAfter = Math.round(sec);
8672
8912
  break;
8673
8913
  }
8914
+ case "--keep-awake":
8915
+ opts.keepAwake = "whenPluggedIn";
8916
+ break;
8917
+ case "--keep-awake=always":
8918
+ opts.keepAwake = "always";
8919
+ break;
8674
8920
  case "--svg":
8675
8921
  opts.svg = argv[i + 1] !== void 0 && !argv[i + 1].startsWith("-") ? argv[++i] : "";
8676
8922
  break;
@@ -8718,6 +8964,7 @@ Options
8718
8964
  --home <dir> read agent data from another home directory
8719
8965
  --port <n> hook hub port (default ${DEFAULT_HOOK_PORT})
8720
8966
  --no-hub do not listen for hook events (and send no phone notifications)
8967
+ --keep-awake keep this computer awake while an agent works, on mains power (--keep-awake=always: on battery too)
8721
8968
  --no-color
8722
8969
  kvali phone options: --server <url> (self-hosted ntfy) --token <token> --private (no project or step names)
8723
8970
  --events needs-you,done,steps,actions,error,stuck,limits (what to hear about) --done-after <seconds> (shortest task worth a notification; 0: every task) --no-steps`;
@@ -8900,7 +9147,7 @@ async function week(opts, svgFile) {
8900
9147
  ].join("\n")
8901
9148
  );
8902
9149
  if (svgFile !== void 0) {
8903
- const file = path19.resolve(svgFile || `kvali-week-${w.days[w.days.length - 1].day}.svg`);
9150
+ const file = path20.resolve(svgFile || `kvali-week-${w.days[w.days.length - 1].day}.svg`);
8904
9151
  if ((await lstat(file).catch(() => void 0))?.isSymbolicLink()) fail(`${file} is a symbolic link; give the card another file name`);
8905
9152
  await writeFile(file, weekSvg(w));
8906
9153
  console.log(`
@@ -9065,6 +9312,14 @@ async function phone(sub, opts, arg) {
9065
9312
  ].join("\n")
9066
9313
  );
9067
9314
  }
9315
+ function startKeepAwake(engine, opts, say) {
9316
+ if (opts.keepAwake === "off") return void 0;
9317
+ const awake = new KeepAwake({ log: say });
9318
+ const check = () => void awake.update(agentsWorking(engine.snapshot.sessions, Date.now()), opts.keepAwake);
9319
+ engine.onSnapshot(check);
9320
+ setInterval(check, 3e4).unref();
9321
+ return awake;
9322
+ }
9068
9323
  async function main() {
9069
9324
  const { cmd, opts } = parse(process2.argv.slice(2));
9070
9325
  await secureKvaliHome(opts.home);
@@ -9078,7 +9333,7 @@ async function main() {
9078
9333
  const d = await detectAgents(opts.home, process2.env);
9079
9334
  const changes = setupChanges(d);
9080
9335
  if (!changes.length) fail("no supported agent found (~/.claude, ~/.codex, ~/.gemini)");
9081
- const pluginDir = path19.join(path19.dirname(fileURLToPath(import.meta.url)), "claude-plugin");
9336
+ const pluginDir = path20.join(path20.dirname(fileURLToPath(import.meta.url)), "claude-plugin");
9082
9337
  const r = await applySetup(opts.home, process2.env, opts.port, d, { pluginDir });
9083
9338
  const lines = changes.map((c) => ` \u2022 ${c}`);
9084
9339
  if (r.claude === "plugin") lines.push(" Claude Code: new sessions show the Kvali pane; type /reload-plugins in sessions already open.");
@@ -9094,7 +9349,7 @@ async function main() {
9094
9349
  return;
9095
9350
  }
9096
9351
  if (cmd[0] === "protocol") {
9097
- const r = await addProgressProtocol(path19.resolve(cmd[1] ?? "."));
9352
+ const r = await addProgressProtocol(path20.resolve(cmd[1] ?? "."));
9098
9353
  const said = {
9099
9354
  created: `Created ${r.file} with the progress protocol.`,
9100
9355
  added: `Added the progress protocol to ${r.file}.`,
@@ -9121,17 +9376,19 @@ async function main() {
9121
9376
  startPhone(engine, hub, opts.home, (line) => {
9122
9377
  phoneLine = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${line}`;
9123
9378
  });
9379
+ const awake = startKeepAwake(engine, opts);
9124
9380
  const out = process2.stdout;
9125
9381
  out.write(`${ESC}?1049h${ESC}?25l`);
9126
9382
  const restore = () => {
9127
9383
  out.write(`${ESC}?25h${ESC}?1049l`);
9384
+ awake?.dispose();
9128
9385
  hub?.dispose();
9129
9386
  engine.dispose();
9130
9387
  };
9131
9388
  const draw = (snap) => out.write(`${ESC}H${ESC}2J${render(snap, opts)}
9132
9389
  ${paint(opts.color).gray(`
9133
9390
  ${phoneLine ? `${phoneLine}
9134
- ` : ""}q to quit`)}`);
9391
+ ` : ""}${awake?.active ? "keeping this computer awake \xB7 " : ""}q to quit`)}`);
9135
9392
  engine.onSnapshot(draw);
9136
9393
  engine.start();
9137
9394
  const clock = setInterval(() => draw(engine.snapshot), 1e3);
@@ -9163,10 +9420,12 @@ async function watch(opts) {
9163
9420
  const say = (line) => console.log(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${line}`);
9164
9421
  hub.start();
9165
9422
  startPhone(engine, hub, opts.home, say);
9423
+ const awake = startKeepAwake(engine, opts, say);
9166
9424
  engine.start();
9167
9425
  const cfg = await readPhoneConfig(opts.home);
9168
9426
  say(cfg ? `watching agents; phone notifications go to ${channelNames(cfg)}` : "watching agents; phone notifications are not set up (run `kvali phone`)");
9169
9427
  const stop = () => {
9428
+ awake?.dispose();
9170
9429
  hub.dispose();
9171
9430
  engine.dispose();
9172
9431
  process2.exit(0);