@kvali/cli 0.7.5 → 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/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/dist/kvali.mjs +486 -226
- package/package.json +1 -1
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
|
|
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/
|
|
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(
|
|
632
|
-
this.path =
|
|
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
|
|
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
|
|
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
|
|
1027
|
+
import path12 from "node:path";
|
|
789
1028
|
|
|
790
1029
|
// ../core/src/adapters/antigravity.ts
|
|
791
|
-
import
|
|
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
|
|
872
|
-
import
|
|
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
|
|
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
|
|
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
|
|
1128
|
+
const st = await fsp3.stat(p2);
|
|
890
1129
|
if (!st.isFile() || st.size > maxBytes) return void 0;
|
|
891
|
-
return await
|
|
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 =
|
|
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(
|
|
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 =
|
|
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 =
|
|
929
|
-
return rel2 === "" || !rel2.startsWith("..") && !
|
|
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(
|
|
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(
|
|
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(
|
|
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 =
|
|
1121
|
-
return [
|
|
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(
|
|
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 =
|
|
1406
|
+
const dir = path3.join(brain, d.name);
|
|
1168
1407
|
const stats = await Promise.all([
|
|
1169
|
-
statSafe(
|
|
1170
|
-
statSafe(
|
|
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 =
|
|
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" || !
|
|
1221
|
-
const dir = key === "Cwd" || key === "DirectoryPath" || key === "SearchDirectory" ? 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 &&
|
|
1256
|
-
const dir =
|
|
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 =
|
|
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(
|
|
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: [
|
|
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
|
|
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 +
|
|
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 ||
|
|
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] ${
|
|
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] ${
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
(
|
|
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:
|
|
1602
|
-
projectDir:
|
|
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(),
|
|
@@ -1844,6 +2083,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1844
2083
|
onUser(st, o, ts) {
|
|
1845
2084
|
const m = o.message;
|
|
1846
2085
|
if (!m || o.isSidechain) return;
|
|
2086
|
+
if (o.isCompactSummary) return;
|
|
1847
2087
|
const content = m.content;
|
|
1848
2088
|
if (Array.isArray(content) && content.some((b) => b?.type === "tool_result")) {
|
|
1849
2089
|
for (const b of content) {
|
|
@@ -1925,20 +2165,20 @@ var ClaudeCodeAdapter = class {
|
|
|
1925
2165
|
async readSideFiles(st, ctx, changed) {
|
|
1926
2166
|
const config = this.configDir(ctx);
|
|
1927
2167
|
if (changed || st.taskDir === void 0) {
|
|
1928
|
-
const dir =
|
|
2168
|
+
const dir = path4.join(config, "tasks", st.sessionId);
|
|
1929
2169
|
const entries = (await listDir(dir)).filter((e) => e.isFile() && e.name.endsWith(".json"));
|
|
1930
2170
|
if (entries.length === 0) st.taskDir = { sig: "", tasks: [] };
|
|
1931
2171
|
else {
|
|
1932
|
-
const stats = await Promise.all(entries.map((e) => statSafe(
|
|
2172
|
+
const stats = await Promise.all(entries.map((e) => statSafe(path4.join(dir, e.name))));
|
|
1933
2173
|
const sig = entries.map((e, i) => `${e.name}:${stats[i]?.mtimeMs ?? 0}`).join("|");
|
|
1934
2174
|
if (sig !== st.taskDir?.sig) {
|
|
1935
2175
|
const tasks = [];
|
|
1936
2176
|
const timed = [];
|
|
1937
2177
|
for (const [i, e] of entries.entries()) {
|
|
1938
|
-
const t = await readJsonSafe(
|
|
2178
|
+
const t = await readJsonSafe(path4.join(dir, e.name));
|
|
1939
2179
|
if (!t || t.status === "deleted") continue;
|
|
1940
2180
|
const task = {
|
|
1941
|
-
id: String(t.id ??
|
|
2181
|
+
id: String(t.id ?? path4.basename(e.name, ".json")),
|
|
1942
2182
|
title: String(t.subject ?? t.title ?? ""),
|
|
1943
2183
|
activeTitle: typeof t.activeForm === "string" ? t.activeForm : void 0,
|
|
1944
2184
|
status: normStatus(t.status)
|
|
@@ -1952,14 +2192,14 @@ var ClaudeCodeAdapter = class {
|
|
|
1952
2192
|
}
|
|
1953
2193
|
}
|
|
1954
2194
|
}
|
|
1955
|
-
const liveFile =
|
|
2195
|
+
const liveFile = path4.join(ctx.liveDir, "claude-code", `${st.sessionId}.json`);
|
|
1956
2196
|
const lst = await statSafe(liveFile);
|
|
1957
2197
|
if (!lst) st.live = void 0;
|
|
1958
2198
|
else if (lst.mtimeMs !== st.live?.mtimeMs) {
|
|
1959
2199
|
const live = await readJsonSafe(liveFile);
|
|
1960
2200
|
st.live = live ? { ...live, mtimeMs: lst.mtimeMs } : void 0;
|
|
1961
2201
|
}
|
|
1962
|
-
const pulseFile =
|
|
2202
|
+
const pulseFile = path4.join(ctx.liveDir, "claude-code", `${st.sessionId}.mod.json`);
|
|
1963
2203
|
const pst = await statSafe(pulseFile);
|
|
1964
2204
|
if (!pst) st.pulse = void 0;
|
|
1965
2205
|
else if (pst.mtimeMs !== st.pulse?.mtimeMs) {
|
|
@@ -1970,13 +2210,13 @@ var ClaudeCodeAdapter = class {
|
|
|
1970
2210
|
const now = ctx.now();
|
|
1971
2211
|
if (now - st.lastSubagentScan >= 5e3) {
|
|
1972
2212
|
st.lastSubagentScan = now;
|
|
1973
|
-
const subDir =
|
|
2213
|
+
const subDir = path4.join(st.projectDir, st.sessionId, "subagents");
|
|
1974
2214
|
const dirs = [subDir];
|
|
1975
|
-
for (const
|
|
2215
|
+
for (const run2 of await listDir(path4.join(subDir, "workflows"))) if (run2.isDirectory()) dirs.push(path4.join(subDir, "workflows", run2.name));
|
|
1976
2216
|
for (const dir of dirs) {
|
|
1977
2217
|
for (const f of await listDir(dir)) {
|
|
1978
2218
|
if (!f.isFile() || !f.name.endsWith(".jsonl")) continue;
|
|
1979
|
-
const file =
|
|
2219
|
+
const file = path4.join(dir, f.name);
|
|
1980
2220
|
if (!st.subagents.has(file)) st.subagents.set(file, { tail: new JsonlTail(file) });
|
|
1981
2221
|
}
|
|
1982
2222
|
}
|
|
@@ -2177,11 +2417,11 @@ var ClaudeCodeAdapter = class {
|
|
|
2177
2417
|
};
|
|
2178
2418
|
|
|
2179
2419
|
// ../core/src/adapters/cline.ts
|
|
2180
|
-
import
|
|
2181
|
-
import { promises as
|
|
2420
|
+
import path6 from "node:path";
|
|
2421
|
+
import { promises as fsp4 } from "node:fs";
|
|
2182
2422
|
|
|
2183
2423
|
// ../core/src/util/editors.ts
|
|
2184
|
-
import
|
|
2424
|
+
import path5 from "node:path";
|
|
2185
2425
|
var EDITOR_APPS = [
|
|
2186
2426
|
"Code",
|
|
2187
2427
|
"Code - Insiders",
|
|
@@ -2210,10 +2450,10 @@ var SERVER_DIRS = [
|
|
|
2210
2450
|
];
|
|
2211
2451
|
function editorUserDataDirs(home, env, platform = process.platform) {
|
|
2212
2452
|
const out = [];
|
|
2213
|
-
if (env.VSCODE_PORTABLE) out.push(
|
|
2214
|
-
const base = platform === "darwin" ?
|
|
2215
|
-
for (const app of EDITOR_APPS) out.push(
|
|
2216
|
-
for (const dir of SERVER_DIRS) out.push(
|
|
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"));
|
|
2217
2457
|
return out;
|
|
2218
2458
|
}
|
|
2219
2459
|
|
|
@@ -2571,14 +2811,14 @@ var ClineFamilyAdapter = class {
|
|
|
2571
2811
|
const dirs = /* @__PURE__ */ new Set();
|
|
2572
2812
|
const storageRoots = [];
|
|
2573
2813
|
for (const userData of editorUserDataDirs(ctx.home, ctx.env, this.options.platform)) {
|
|
2574
|
-
const user =
|
|
2575
|
-
storageRoots.push(
|
|
2576
|
-
for (const p2 of await listDir(
|
|
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"));
|
|
2577
2817
|
}
|
|
2578
2818
|
for (const extra of this.options.extraStorageDirs ?? []) storageRoots.push(extra);
|
|
2579
2819
|
for (const root of storageRoots) {
|
|
2580
2820
|
for (const e of await listDir(root)) {
|
|
2581
|
-
if (e.isDirectory() && this.extensions.includes(e.name.toLowerCase())) dirs.add(
|
|
2821
|
+
if (e.isDirectory() && this.extensions.includes(e.name.toLowerCase())) dirs.add(path6.join(root, e.name));
|
|
2582
2822
|
}
|
|
2583
2823
|
}
|
|
2584
2824
|
for (const d of this.standaloneDirs(ctx)) dirs.add(d);
|
|
@@ -2591,9 +2831,9 @@ var ClineFamilyAdapter = class {
|
|
|
2591
2831
|
const now = ctx.now();
|
|
2592
2832
|
const found = [];
|
|
2593
2833
|
for (const store of this.stores.values()) {
|
|
2594
|
-
const tasksDir =
|
|
2834
|
+
const tasksDir = path6.join(store.dir, "tasks");
|
|
2595
2835
|
const names = (await listDir(tasksDir)).filter((e) => e.isDirectory() && !e.name.startsWith(".") && !e.name.startsWith("_")).map((e) => e.name);
|
|
2596
|
-
const index = this.flavor === "roo" ?
|
|
2836
|
+
const index = this.flavor === "roo" ? path6.join(tasksDir, "_index.json") : path6.join(store.dir, "state", "taskHistory.json");
|
|
2597
2837
|
const indexMtime = (await statSafe(index))?.mtimeMs ?? 0;
|
|
2598
2838
|
const sweep = now - store.lastSweep >= SWEEP_MS || indexMtime !== store.indexMtime;
|
|
2599
2839
|
if (sweep) {
|
|
@@ -2606,7 +2846,7 @@ var ClineFamilyAdapter = class {
|
|
|
2606
2846
|
for (let i = 0; i < toStat.length; i += 64) {
|
|
2607
2847
|
await Promise.all(
|
|
2608
2848
|
toStat.slice(i, i + 64).map(async (id) => {
|
|
2609
|
-
const st = await statSafe(
|
|
2849
|
+
const st = await statSafe(path6.join(tasksDir, id, "ui_messages.json"));
|
|
2610
2850
|
store.seen.set(id, st?.mtimeMs ?? 0);
|
|
2611
2851
|
})
|
|
2612
2852
|
);
|
|
@@ -2614,10 +2854,10 @@ var ClineFamilyAdapter = class {
|
|
|
2614
2854
|
for (const [id, mtimeMs] of store.seen) if (mtimeMs && now - mtimeMs <= ctx.activeWindowMs) found.push({ store, id, mtimeMs });
|
|
2615
2855
|
}
|
|
2616
2856
|
found.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
2617
|
-
const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [
|
|
2857
|
+
const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [path6.join(f.store.dir, "tasks", f.id), f]));
|
|
2618
2858
|
for (const [dir, f] of keep) {
|
|
2619
2859
|
if (this.tracked.has(dir)) continue;
|
|
2620
|
-
this.tracked.set(dir, { id: f.id, dir, file:
|
|
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 });
|
|
2621
2861
|
}
|
|
2622
2862
|
for (const dir of [...this.tracked.keys()]) if (!keep.has(dir)) this.tracked.delete(dir);
|
|
2623
2863
|
}
|
|
@@ -2642,7 +2882,7 @@ var ClineFamilyAdapter = class {
|
|
|
2642
2882
|
}
|
|
2643
2883
|
}
|
|
2644
2884
|
if (this.flavor === "roo") {
|
|
2645
|
-
const hf =
|
|
2885
|
+
const hf = path6.join(t.dir, "history_item.json");
|
|
2646
2886
|
const hs = await statSafe(hf);
|
|
2647
2887
|
if (hs && hs.mtimeMs !== t.history?.mtimeMs) {
|
|
2648
2888
|
const value = await readJsonSafe(hf, 4 << 20);
|
|
@@ -2650,7 +2890,7 @@ var ClineFamilyAdapter = class {
|
|
|
2650
2890
|
}
|
|
2651
2891
|
const now = ctx.now();
|
|
2652
2892
|
if (!t.modelFile || now - t.modelFile.checkedAt >= MODEL_CHECK_MS) {
|
|
2653
|
-
const mf =
|
|
2893
|
+
const mf = path6.join(t.dir, "api_conversation_history.json");
|
|
2654
2894
|
const ms = await statSafe(mf);
|
|
2655
2895
|
const prev = t.modelFile;
|
|
2656
2896
|
t.modelFile = { mtimeMs: ms?.mtimeMs ?? 0, checkedAt: now, model: prev?.model };
|
|
@@ -2664,7 +2904,7 @@ var ClineFamilyAdapter = class {
|
|
|
2664
2904
|
async readClineHistory(store, id, now) {
|
|
2665
2905
|
if (store.history && store.history.byId.has(id) && now - store.history.readAt < HISTORY_EVERY_MS) return;
|
|
2666
2906
|
if (store.history && now - store.history.readAt < 2e3) return;
|
|
2667
|
-
const file =
|
|
2907
|
+
const file = path6.join(store.dir, "state", "taskHistory.json");
|
|
2668
2908
|
const st = await statSafe(file);
|
|
2669
2909
|
if (!st || st.mtimeMs === store.history?.mtimeMs) return;
|
|
2670
2910
|
const items = await readJsonSafe(file, 64 << 20);
|
|
@@ -2749,7 +2989,7 @@ async function lastModelIn(file, size) {
|
|
|
2749
2989
|
if (len <= 0) return void 0;
|
|
2750
2990
|
let fh;
|
|
2751
2991
|
try {
|
|
2752
|
-
fh = await
|
|
2992
|
+
fh = await fsp4.open(file, "r");
|
|
2753
2993
|
const buf = Buffer.alloc(len);
|
|
2754
2994
|
await fh.read(buf, 0, len, size - len);
|
|
2755
2995
|
const text = buf.toString("utf8");
|
|
@@ -2764,8 +3004,8 @@ async function lastModelIn(file, size) {
|
|
|
2764
3004
|
}
|
|
2765
3005
|
function clineDataDir(home, env) {
|
|
2766
3006
|
if (env.CLINE_DATA_DIR) return env.CLINE_DATA_DIR;
|
|
2767
|
-
if (env.CLINE_DIR) return
|
|
2768
|
-
return
|
|
3007
|
+
if (env.CLINE_DIR) return path6.join(env.CLINE_DIR, "data");
|
|
3008
|
+
return path6.join(home, ".cline", "data");
|
|
2769
3009
|
}
|
|
2770
3010
|
var ClineAdapter = class extends ClineFamilyAdapter {
|
|
2771
3011
|
id = "cline";
|
|
@@ -2789,7 +3029,7 @@ var RooCodeAdapter = class extends ClineFamilyAdapter {
|
|
|
2789
3029
|
async customStorageDirs(ctx) {
|
|
2790
3030
|
const out = [];
|
|
2791
3031
|
for (const userData of editorUserDataDirs(ctx.home, ctx.env, this.options.platform)) {
|
|
2792
|
-
const text = await readTextSafe(
|
|
3032
|
+
const text = await readTextSafe(path6.join(userData, "User", "settings.json"), 2 << 20);
|
|
2793
3033
|
const m = text && /"roo-cline\.customStoragePath"\s*:\s*"((?:[^"\\]|\\.)+)"/.exec(text);
|
|
2794
3034
|
if (m) {
|
|
2795
3035
|
try {
|
|
@@ -2946,7 +3186,7 @@ var ClineSdkSessions = class {
|
|
|
2946
3186
|
tracked = /* @__PURE__ */ new Map();
|
|
2947
3187
|
lastDiscovery = 0;
|
|
2948
3188
|
root(ctx) {
|
|
2949
|
-
return ctx.env.CLINE_SESSION_DATA_DIR ||
|
|
3189
|
+
return ctx.env.CLINE_SESSION_DATA_DIR || path6.join(clineDataDir(ctx.home, ctx.env), "sessions");
|
|
2950
3190
|
}
|
|
2951
3191
|
async poll(ctx, label) {
|
|
2952
3192
|
const now = ctx.now();
|
|
@@ -2970,9 +3210,9 @@ var ClineSdkSessions = class {
|
|
|
2970
3210
|
const found = [];
|
|
2971
3211
|
for (const e of await listDir(root)) {
|
|
2972
3212
|
if (!e.isDirectory() || e.name.includes("__") || e.name.startsWith(".")) continue;
|
|
2973
|
-
const dir =
|
|
2974
|
-
const manifest = await statSafe(
|
|
2975
|
-
const messages = await statSafe(
|
|
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`));
|
|
2976
3216
|
const mtimeMs = Math.max(manifest?.mtimeMs ?? 0, messages?.mtimeMs ?? 0);
|
|
2977
3217
|
if (mtimeMs && now - mtimeMs <= ctx.activeWindowMs) found.push({ dir, id: e.name, mtimeMs });
|
|
2978
3218
|
}
|
|
@@ -2980,7 +3220,7 @@ var ClineSdkSessions = class {
|
|
|
2980
3220
|
const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [f.dir, f]));
|
|
2981
3221
|
for (const [dir, f] of keep) {
|
|
2982
3222
|
if (!this.tracked.has(dir)) {
|
|
2983
|
-
this.tracked.set(dir, { dir, id: f.id, manifestFile:
|
|
3223
|
+
this.tracked.set(dir, { dir, id: f.id, manifestFile: path6.join(dir, `${f.id}.json`), manifestMtime: -1, messagesMtime: -1, messagesSize: -1 });
|
|
2984
3224
|
}
|
|
2985
3225
|
}
|
|
2986
3226
|
for (const dir of [...this.tracked.keys()]) if (!keep.has(dir)) this.tracked.delete(dir);
|
|
@@ -2995,7 +3235,7 @@ var ClineSdkSessions = class {
|
|
|
2995
3235
|
}
|
|
2996
3236
|
}
|
|
2997
3237
|
const declared = typeof t.manifest?.messages_path === "string" ? t.manifest.messages_path : void 0;
|
|
2998
|
-
let file =
|
|
3238
|
+
let file = path6.join(t.dir, `${t.id}.messages.json`);
|
|
2999
3239
|
let st = await statSafe(file);
|
|
3000
3240
|
if (!st && declared) {
|
|
3001
3241
|
st = await statSafe(declared);
|
|
@@ -3102,7 +3342,7 @@ var ClineSdkSessions = class {
|
|
|
3102
3342
|
};
|
|
3103
3343
|
|
|
3104
3344
|
// ../core/src/adapters/codex.ts
|
|
3105
|
-
import
|
|
3345
|
+
import path7 from "node:path";
|
|
3106
3346
|
function codexFailure(output) {
|
|
3107
3347
|
let text = typeof output === "string" ? output : output && typeof output === "object" ? JSON.stringify(output) : "";
|
|
3108
3348
|
if (!text) return void 0;
|
|
@@ -3166,22 +3406,22 @@ var CodexAdapter = class extends JsonlSessionAdapter {
|
|
|
3166
3406
|
id = "codex";
|
|
3167
3407
|
label = "Codex";
|
|
3168
3408
|
async discover(ctx) {
|
|
3169
|
-
const home = ctx.env.CODEX_HOME ||
|
|
3170
|
-
const root =
|
|
3409
|
+
const home = ctx.env.CODEX_HOME || path7.join(ctx.home, ".codex");
|
|
3410
|
+
const root = path7.join(home, "sessions");
|
|
3171
3411
|
const now = ctx.now();
|
|
3172
3412
|
const days = Math.max(1, Math.ceil(ctx.activeWindowMs / 864e5) + 1);
|
|
3173
3413
|
const dirs = /* @__PURE__ */ new Set();
|
|
3174
3414
|
for (let i = 0; i <= days; i += 1) {
|
|
3175
3415
|
const d = new Date(now - i * 864e5);
|
|
3176
3416
|
const pad = (n) => String(n).padStart(2, "0");
|
|
3177
|
-
dirs.add(
|
|
3178
|
-
dirs.add(
|
|
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())));
|
|
3179
3419
|
}
|
|
3180
3420
|
const out = [];
|
|
3181
3421
|
for (const dir of dirs) {
|
|
3182
3422
|
for (const f of await listDir(dir)) {
|
|
3183
3423
|
if (!f.isFile() || !f.name.startsWith("rollout-") || !f.name.endsWith(".jsonl")) continue;
|
|
3184
|
-
const file =
|
|
3424
|
+
const file = path7.join(dir, f.name);
|
|
3185
3425
|
const st = await statSafe(file);
|
|
3186
3426
|
if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
|
|
3187
3427
|
}
|
|
@@ -3193,7 +3433,7 @@ var CodexAdapter = class extends JsonlSessionAdapter {
|
|
|
3193
3433
|
const daily = {};
|
|
3194
3434
|
return {
|
|
3195
3435
|
file,
|
|
3196
|
-
id: m ? m[1] :
|
|
3436
|
+
id: m ? m[1] : path7.basename(file, ".jsonl"),
|
|
3197
3437
|
isSubagent: false,
|
|
3198
3438
|
updatedAt: 0,
|
|
3199
3439
|
prevTotal: 0,
|
|
@@ -3494,7 +3734,7 @@ function loopOf(st, status, now) {
|
|
|
3494
3734
|
}
|
|
3495
3735
|
|
|
3496
3736
|
// ../core/src/adapters/copilot.ts
|
|
3497
|
-
import
|
|
3737
|
+
import path8 from "node:path";
|
|
3498
3738
|
|
|
3499
3739
|
// ../core/src/util/sqlite.ts
|
|
3500
3740
|
var loaded;
|
|
@@ -3662,12 +3902,12 @@ function dbStatus(s) {
|
|
|
3662
3902
|
return s === "done" ? "completed" : s === "in_progress" ? "in_progress" : s === "blocked" ? "blocked" : "pending";
|
|
3663
3903
|
}
|
|
3664
3904
|
function createState(file) {
|
|
3665
|
-
const dir =
|
|
3905
|
+
const dir = path8.dirname(file);
|
|
3666
3906
|
const daily = {};
|
|
3667
3907
|
return {
|
|
3668
3908
|
file,
|
|
3669
3909
|
dir,
|
|
3670
|
-
id:
|
|
3910
|
+
id: path8.basename(dir),
|
|
3671
3911
|
updatedAt: 0,
|
|
3672
3912
|
workspaceMtime: -1,
|
|
3673
3913
|
turnOpen: false,
|
|
@@ -3911,14 +4151,14 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
|
|
|
3911
4151
|
id = "copilot";
|
|
3912
4152
|
label = "Copilot";
|
|
3913
4153
|
root(ctx) {
|
|
3914
|
-
return ctx.env.COPILOT_HOME ||
|
|
4154
|
+
return ctx.env.COPILOT_HOME || path8.join(ctx.home, ".copilot");
|
|
3915
4155
|
}
|
|
3916
4156
|
async discover(ctx) {
|
|
3917
|
-
const dir =
|
|
4157
|
+
const dir = path8.join(this.root(ctx), "session-state");
|
|
3918
4158
|
const out = [];
|
|
3919
4159
|
for (const e of await listDir(dir)) {
|
|
3920
4160
|
if (!e.isDirectory()) continue;
|
|
3921
|
-
const file =
|
|
4161
|
+
const file = path8.join(dir, e.name, "events.jsonl");
|
|
3922
4162
|
const st = await statSafe(file);
|
|
3923
4163
|
if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
|
|
3924
4164
|
}
|
|
@@ -3936,7 +4176,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
|
|
|
3936
4176
|
}
|
|
3937
4177
|
async afterRead(st, ctx) {
|
|
3938
4178
|
const now = ctx.now();
|
|
3939
|
-
const ws =
|
|
4179
|
+
const ws = path8.join(st.dir, "workspace.yaml");
|
|
3940
4180
|
const wst = await statSafe(ws);
|
|
3941
4181
|
if (wst && wst.mtimeMs !== st.workspaceMtime) {
|
|
3942
4182
|
st.workspaceMtime = wst.mtimeMs;
|
|
@@ -3953,7 +4193,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
|
|
|
3953
4193
|
st.alive = locks.length ? live.length > 0 : void 0;
|
|
3954
4194
|
st.pid = live[0];
|
|
3955
4195
|
}
|
|
3956
|
-
const dbFile =
|
|
4196
|
+
const dbFile = path8.join(st.dir, "session.db");
|
|
3957
4197
|
const dbm = Math.max((await statSafe(dbFile))?.mtimeMs ?? 0, (await statSafe(`${dbFile}-wal`))?.mtimeMs ?? 0);
|
|
3958
4198
|
if (dbm && dbm !== st.dbMtime) {
|
|
3959
4199
|
st.dbMtime = dbm;
|
|
@@ -4055,7 +4295,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
|
|
|
4055
4295
|
};
|
|
4056
4296
|
|
|
4057
4297
|
// ../core/src/adapters/gemini-cli.ts
|
|
4058
|
-
import
|
|
4298
|
+
import path9 from "node:path";
|
|
4059
4299
|
var PENDING_TOOL = /* @__PURE__ */ new Set(["scheduled", "validating", "executing"]);
|
|
4060
4300
|
function todoStatus2(s) {
|
|
4061
4301
|
switch (s) {
|
|
@@ -4129,8 +4369,8 @@ var GeminiCliAdapter = class {
|
|
|
4129
4369
|
const homes = [ctx.env.GEMINI_CLI_HOME, ctx.home].filter((h) => !!h);
|
|
4130
4370
|
const out = /* @__PURE__ */ new Set();
|
|
4131
4371
|
for (const h of homes) {
|
|
4132
|
-
out.add(
|
|
4133
|
-
out.add(
|
|
4372
|
+
out.add(path9.join(h, ".gemini", "tmp"));
|
|
4373
|
+
out.add(path9.join(h, ".cache", ".gemini", "tmp"));
|
|
4134
4374
|
}
|
|
4135
4375
|
return [...out];
|
|
4136
4376
|
}
|
|
@@ -4178,18 +4418,18 @@ var GeminiCliAdapter = class {
|
|
|
4178
4418
|
for (const root of this.roots(ctx)) {
|
|
4179
4419
|
for (const proj of await listDir(root)) {
|
|
4180
4420
|
if (!proj.isDirectory()) continue;
|
|
4181
|
-
const projDir =
|
|
4182
|
-
const chats =
|
|
4421
|
+
const projDir = path9.join(root, proj.name);
|
|
4422
|
+
const chats = path9.join(projDir, "chats");
|
|
4183
4423
|
const files = (await listDir(chats)).filter(
|
|
4184
4424
|
(f) => f.isFile() && f.name.startsWith("session-") && (f.name.endsWith(".jsonl") || f.name.endsWith(".json"))
|
|
4185
4425
|
);
|
|
4186
4426
|
if (files.length === 0) continue;
|
|
4187
4427
|
let project;
|
|
4188
4428
|
for (const f of files) {
|
|
4189
|
-
const file =
|
|
4429
|
+
const file = path9.join(chats, f.name);
|
|
4190
4430
|
const st = await statSafe(file);
|
|
4191
4431
|
if (!st || now - st.mtimeMs > ctx.activeWindowMs) continue;
|
|
4192
|
-
if (project === void 0) project = (await readTextSafe(
|
|
4432
|
+
if (project === void 0) project = (await readTextSafe(path9.join(projDir, ".project_root"), 8192))?.trim() || "";
|
|
4193
4433
|
found.push({ file, mtimeMs: st.mtimeMs, project: project || void 0 });
|
|
4194
4434
|
}
|
|
4195
4435
|
}
|
|
@@ -4319,7 +4559,7 @@ var GeminiCliAdapter = class {
|
|
|
4319
4559
|
key: `gemini-cli:${st.sessionId ?? st.file}`,
|
|
4320
4560
|
agent: "gemini-cli",
|
|
4321
4561
|
agentLabel: this.label,
|
|
4322
|
-
id: st.sessionId ??
|
|
4562
|
+
id: st.sessionId ?? path9.basename(st.file),
|
|
4323
4563
|
title: st.summary ? truncate(st.summary, 100) : title ?? "Untitled session",
|
|
4324
4564
|
titleFromPrompt: !st.summary && title !== void 0 ? true : void 0,
|
|
4325
4565
|
projectPath: st.projectPath,
|
|
@@ -4350,7 +4590,7 @@ var GeminiCliAdapter = class {
|
|
|
4350
4590
|
};
|
|
4351
4591
|
|
|
4352
4592
|
// ../core/src/adapters/opencode.ts
|
|
4353
|
-
import
|
|
4593
|
+
import path10 from "node:path";
|
|
4354
4594
|
var num = (v) => typeof v === "number" && Number.isFinite(v) ? v : Number(v) || 0;
|
|
4355
4595
|
function parseData(v) {
|
|
4356
4596
|
if (v && typeof v === "object") return v;
|
|
@@ -4662,13 +4902,13 @@ var OpenCodeFamilyAdapter = class {
|
|
|
4662
4902
|
this.options = options;
|
|
4663
4903
|
}
|
|
4664
4904
|
dataDir(ctx) {
|
|
4665
|
-
return
|
|
4905
|
+
return path10.join(ctx.env.XDG_DATA_HOME || path10.join(ctx.home, ".local", "share"), this.app);
|
|
4666
4906
|
}
|
|
4667
4907
|
databaseFile(ctx) {
|
|
4668
4908
|
if (this.options.dbFile) return this.options.dbFile;
|
|
4669
4909
|
const override = ctx.env[this.dbEnv];
|
|
4670
|
-
if (override && override !== ":memory:") return
|
|
4671
|
-
return
|
|
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`);
|
|
4672
4912
|
}
|
|
4673
4913
|
async poll(ctx) {
|
|
4674
4914
|
const now = ctx.now();
|
|
@@ -4897,7 +5137,7 @@ var OpenCodeFamilyAdapter = class {
|
|
|
4897
5137
|
const untitled = !rowTitle || /^(New session|Child session)( - \d{4}-\d\d-\d\dT[\d:.]+Z?)?$/.test(rowTitle);
|
|
4898
5138
|
const title = untitled ? f.title : truncate(rowTitle, 100);
|
|
4899
5139
|
const model = parseData(row.model);
|
|
4900
|
-
const dir = typeof row.directory === "string" && row.directory ? row.directory.replace(/\//g,
|
|
5140
|
+
const dir = typeof row.directory === "string" && row.directory ? row.directory.replace(/\//g, path10.sep === "\\" ? "\\" : "/") : void 0;
|
|
4901
5141
|
const rowTokens = "tokens_input" in row ? {
|
|
4902
5142
|
input: num(row.tokens_input),
|
|
4903
5143
|
output: num(row.tokens_output) + num(row.tokens_reasoning),
|
|
@@ -4972,7 +5212,7 @@ var LiveProbe = class {
|
|
|
4972
5212
|
});
|
|
4973
5213
|
}
|
|
4974
5214
|
async readService(ctx) {
|
|
4975
|
-
const file =
|
|
5215
|
+
const file = path10.join(ctx.env.XDG_STATE_HOME || path10.join(ctx.home, ".local", "state"), "opencode", "service.json");
|
|
4976
5216
|
const info = await readJsonSafe(file, 64 << 10);
|
|
4977
5217
|
const now = ctx.now();
|
|
4978
5218
|
if (!info || typeof info.url !== "string") {
|
|
@@ -5040,8 +5280,8 @@ var KiloCodeAdapter = class extends OpenCodeFamilyAdapter {
|
|
|
5040
5280
|
};
|
|
5041
5281
|
|
|
5042
5282
|
// ../core/src/adapters/progress-file.ts
|
|
5043
|
-
import { promises as
|
|
5044
|
-
import
|
|
5283
|
+
import { promises as fsp5 } from "node:fs";
|
|
5284
|
+
import path11 from "node:path";
|
|
5045
5285
|
var STATUS_WORDS = lookupTable({
|
|
5046
5286
|
working: "working",
|
|
5047
5287
|
running: "working",
|
|
@@ -5060,7 +5300,7 @@ var MAX_PROGRESS_FILES = 20;
|
|
|
5060
5300
|
var MAX_LISTED = 500;
|
|
5061
5301
|
async function realpathSafe(p2) {
|
|
5062
5302
|
try {
|
|
5063
|
-
return await
|
|
5303
|
+
return await fsp5.realpath(p2);
|
|
5064
5304
|
} catch {
|
|
5065
5305
|
return void 0;
|
|
5066
5306
|
}
|
|
@@ -5073,10 +5313,10 @@ var ProgressFileAdapter = class {
|
|
|
5073
5313
|
async poll(ctx) {
|
|
5074
5314
|
const files = [];
|
|
5075
5315
|
for (const root of ctx.workspaceRoots) {
|
|
5076
|
-
const agentsDir =
|
|
5077
|
-
const names = [
|
|
5078
|
-
for (const f of (await listDir(
|
|
5079
|
-
if (f.isFile() && f.name.endsWith(".md")) names.push(
|
|
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));
|
|
5080
5320
|
}
|
|
5081
5321
|
const realRoot = await realpathSafe(root);
|
|
5082
5322
|
if (!realRoot) continue;
|
|
@@ -5151,7 +5391,7 @@ var ProgressFileAdapter = class {
|
|
|
5151
5391
|
|
|
5152
5392
|
// ../core/src/engine.ts
|
|
5153
5393
|
function defaultLiveDir(home = os.homedir()) {
|
|
5154
|
-
return
|
|
5394
|
+
return path12.join(home, ".kvali", "live");
|
|
5155
5395
|
}
|
|
5156
5396
|
function createDefaultAdapters(opts = {}) {
|
|
5157
5397
|
return [
|
|
@@ -5351,31 +5591,31 @@ var Engine = class {
|
|
|
5351
5591
|
};
|
|
5352
5592
|
|
|
5353
5593
|
// ../core/src/hooks/hub.ts
|
|
5354
|
-
import { promises as
|
|
5594
|
+
import { promises as fsp7 } from "node:fs";
|
|
5355
5595
|
import http from "node:http";
|
|
5356
|
-
import
|
|
5596
|
+
import path13 from "node:path";
|
|
5357
5597
|
|
|
5358
5598
|
// ../core/src/util/files.ts
|
|
5359
5599
|
import { randomBytes } from "node:crypto";
|
|
5360
|
-
import { promises as
|
|
5600
|
+
import { promises as fsp6 } from "node:fs";
|
|
5361
5601
|
async function writeFileSafely(file, text, mode) {
|
|
5362
5602
|
let current;
|
|
5363
5603
|
try {
|
|
5364
|
-
const st = await
|
|
5604
|
+
const st = await fsp6.lstat(file);
|
|
5365
5605
|
current = { link: st.isSymbolicLink(), mode: st.mode & 511 };
|
|
5366
5606
|
} catch {
|
|
5367
5607
|
}
|
|
5368
5608
|
if (current?.link) {
|
|
5369
|
-
await
|
|
5609
|
+
await fsp6.writeFile(file, text);
|
|
5370
5610
|
return;
|
|
5371
5611
|
}
|
|
5372
5612
|
const tmp = `${file}.kvali-${process.pid}-${randomBytes(4).toString("hex")}.tmp`;
|
|
5373
5613
|
try {
|
|
5374
|
-
await
|
|
5375
|
-
if (current) await
|
|
5376
|
-
await
|
|
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);
|
|
5377
5617
|
} catch (err) {
|
|
5378
|
-
await
|
|
5618
|
+
await fsp6.rm(tmp, { force: true }).catch(() => void 0);
|
|
5379
5619
|
throw err;
|
|
5380
5620
|
}
|
|
5381
5621
|
}
|
|
@@ -5527,40 +5767,40 @@ var HookHub = class {
|
|
|
5527
5767
|
}
|
|
5528
5768
|
}
|
|
5529
5769
|
async store(agent, ev) {
|
|
5530
|
-
const dir =
|
|
5531
|
-
await
|
|
5532
|
-
await writeFileSafely(
|
|
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);
|
|
5533
5773
|
}
|
|
5534
5774
|
};
|
|
5535
5775
|
|
|
5536
5776
|
// ../core/src/hooks/claude-install.ts
|
|
5537
|
-
import { promises as
|
|
5777
|
+
import { promises as fsp9 } from "node:fs";
|
|
5538
5778
|
import os2 from "node:os";
|
|
5539
|
-
import
|
|
5779
|
+
import path15 from "node:path";
|
|
5540
5780
|
|
|
5541
5781
|
// ../core/src/hooks/claude-plugin.ts
|
|
5542
|
-
import { execFile } from "node:child_process";
|
|
5782
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
5543
5783
|
import { createHash } from "node:crypto";
|
|
5544
|
-
import { constants as fsc, promises as
|
|
5545
|
-
import
|
|
5784
|
+
import { constants as fsc, promises as fsp8 } from "node:fs";
|
|
5785
|
+
import path14 from "node:path";
|
|
5546
5786
|
var CLAUDE_PLUGIN_ID = "kvali@kvali";
|
|
5547
5787
|
var CLAUDE_MARKETPLACE = "kvali";
|
|
5548
|
-
var kvaliPluginDir = (home) =>
|
|
5549
|
-
var stateFile = (home) =>
|
|
5788
|
+
var kvaliPluginDir = (home) => path14.join(home, ".kvali", "claude-plugin");
|
|
5789
|
+
var stateFile = (home) => path14.join(home, ".kvali", "state.json");
|
|
5550
5790
|
async function filesUnder(dir, base = dir) {
|
|
5551
5791
|
const out = [];
|
|
5552
5792
|
let entries;
|
|
5553
5793
|
try {
|
|
5554
|
-
entries = await
|
|
5794
|
+
entries = await fsp8.readdir(dir, { withFileTypes: true });
|
|
5555
5795
|
} catch {
|
|
5556
5796
|
return out;
|
|
5557
5797
|
}
|
|
5558
5798
|
for (const e of entries) {
|
|
5559
|
-
const full =
|
|
5799
|
+
const full = path14.join(dir, e.name);
|
|
5560
5800
|
if (e.isDirectory()) {
|
|
5561
|
-
if (
|
|
5801
|
+
if (path14.relative(base, full) === path14.join(".claude-plugin", "types")) continue;
|
|
5562
5802
|
out.push(...await filesUnder(full, base));
|
|
5563
|
-
} else if (e.isFile()) out.push(
|
|
5803
|
+
} else if (e.isFile()) out.push(path14.relative(base, full));
|
|
5564
5804
|
}
|
|
5565
5805
|
return out.sort();
|
|
5566
5806
|
}
|
|
@@ -5569,16 +5809,16 @@ async function pluginFingerprint(dir) {
|
|
|
5569
5809
|
if (!files.length) return void 0;
|
|
5570
5810
|
const h = createHash("sha256");
|
|
5571
5811
|
for (const f of files) {
|
|
5572
|
-
h.update(f.split(
|
|
5812
|
+
h.update(f.split(path14.sep).join("/"));
|
|
5573
5813
|
h.update("\0");
|
|
5574
|
-
h.update(await
|
|
5814
|
+
h.update(await fsp8.readFile(path14.join(dir, f)));
|
|
5575
5815
|
h.update("\0");
|
|
5576
5816
|
}
|
|
5577
5817
|
return h.digest("hex");
|
|
5578
5818
|
}
|
|
5579
5819
|
async function pluginVersion(dir) {
|
|
5580
5820
|
try {
|
|
5581
|
-
const v = JSON.parse(await
|
|
5821
|
+
const v = JSON.parse(await fsp8.readFile(path14.join(dir, ".claude-plugin", "plugin.json"), "utf8")).version;
|
|
5582
5822
|
return typeof v === "string" ? v : void 0;
|
|
5583
5823
|
} catch {
|
|
5584
5824
|
return void 0;
|
|
@@ -5598,28 +5838,28 @@ async function syncClaudePlugin(bundledDir, home) {
|
|
|
5598
5838
|
const [mine, theirs] = await Promise.all([pluginVersion(bundledDir), pluginVersion(target)]);
|
|
5599
5839
|
if (mine && theirs && compareVersions(mine, theirs) < 0) return false;
|
|
5600
5840
|
const next = `${target}.next`;
|
|
5601
|
-
await
|
|
5602
|
-
await
|
|
5603
|
-
await
|
|
5604
|
-
await
|
|
5605
|
-
await
|
|
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);
|
|
5606
5846
|
return true;
|
|
5607
5847
|
}
|
|
5608
5848
|
async function claudeExtensionDirs(home) {
|
|
5609
5849
|
const roots = [".vscode", ".vscode-insiders", ".vscode-oss", ".cursor", ".windsurf", ".antigravity", ".antigravity-ide", ".kiro"].map(
|
|
5610
|
-
(d) =>
|
|
5850
|
+
(d) => path14.join(home, d, "extensions")
|
|
5611
5851
|
);
|
|
5612
5852
|
const found = [];
|
|
5613
5853
|
for (const root of roots) {
|
|
5614
5854
|
let names = [];
|
|
5615
5855
|
try {
|
|
5616
|
-
names = await
|
|
5856
|
+
names = await fsp8.readdir(root);
|
|
5617
5857
|
} catch {
|
|
5618
5858
|
continue;
|
|
5619
5859
|
}
|
|
5620
|
-
for (const n of names) if (n.toLowerCase().startsWith("anthropic.claude-code-")) found.push(
|
|
5860
|
+
for (const n of names) if (n.toLowerCase().startsWith("anthropic.claude-code-")) found.push(path14.join(root, n));
|
|
5621
5861
|
}
|
|
5622
|
-
const ver = (p2) => (/-(\d+)\.(\d+)\.(\d+)/.exec(
|
|
5862
|
+
const ver = (p2) => (/-(\d+)\.(\d+)\.(\d+)/.exec(path14.basename(p2)) ?? []).slice(1).map(Number);
|
|
5623
5863
|
return found.sort((a, b) => {
|
|
5624
5864
|
const [x, y] = [ver(a), ver(b)];
|
|
5625
5865
|
for (let i = 0; i < 3; i += 1) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (y[i] ?? 0) - (x[i] ?? 0);
|
|
@@ -5631,23 +5871,23 @@ async function findClaudeBinary(opts) {
|
|
|
5631
5871
|
const names = win ? ["claude.exe", "claude.cmd"] : ["claude"];
|
|
5632
5872
|
const candidates = [];
|
|
5633
5873
|
for (const d of opts.extensionDirs ?? []) {
|
|
5634
|
-
const bin =
|
|
5874
|
+
const bin = path14.join(d, "resources", "native-binary");
|
|
5635
5875
|
let inside = [];
|
|
5636
5876
|
try {
|
|
5637
|
-
inside = await
|
|
5877
|
+
inside = await fsp8.readdir(bin);
|
|
5638
5878
|
} catch {
|
|
5639
5879
|
continue;
|
|
5640
5880
|
}
|
|
5641
5881
|
const ranked = inside.filter((n) => /^claude([-.].*)?$/i.test(n) && !/\.(json|md|txt|map)$/i.test(n)).sort((x, y) => x.length - y.length);
|
|
5642
|
-
for (const n of ranked) candidates.push(
|
|
5882
|
+
for (const n of ranked) candidates.push(path14.join(bin, n));
|
|
5643
5883
|
}
|
|
5644
|
-
for (const dir of (opts.env?.PATH ?? opts.env?.Path ?? "").split(
|
|
5645
|
-
candidates.push(
|
|
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]));
|
|
5646
5886
|
if (!win) candidates.push("/opt/homebrew/bin/claude", "/usr/local/bin/claude");
|
|
5647
5887
|
for (const c of candidates) {
|
|
5648
5888
|
try {
|
|
5649
|
-
await
|
|
5650
|
-
if ((await
|
|
5889
|
+
await fsp8.access(c, win ? fsc.F_OK : fsc.X_OK);
|
|
5890
|
+
if ((await fsp8.stat(c)).isFile()) return c;
|
|
5651
5891
|
} catch {
|
|
5652
5892
|
}
|
|
5653
5893
|
}
|
|
@@ -5657,7 +5897,7 @@ function runClaude(bin, args, env, timeoutMs = 6e4) {
|
|
|
5657
5897
|
const cmdShim = process.platform === "win32" && /\.cmd$/i.test(bin);
|
|
5658
5898
|
const argv = cmdShim ? args.map((a) => /[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a) : [...args];
|
|
5659
5899
|
return new Promise((resolve) => {
|
|
5660
|
-
|
|
5900
|
+
execFile2(
|
|
5661
5901
|
cmdShim ? `"${bin}"` : bin,
|
|
5662
5902
|
argv,
|
|
5663
5903
|
{ env, timeout: timeoutMs, windowsHide: true, maxBuffer: 8 * 1024 * 1024, shell: cmdShim },
|
|
@@ -5700,7 +5940,7 @@ async function installClaudePlugin(bin, dir, env) {
|
|
|
5700
5940
|
}
|
|
5701
5941
|
async function claudePluginEnabled(settingsFile) {
|
|
5702
5942
|
try {
|
|
5703
|
-
const s = JSON.parse(await
|
|
5943
|
+
const s = JSON.parse(await fsp8.readFile(settingsFile, "utf8"));
|
|
5704
5944
|
return s?.enabledPlugins?.[CLAUDE_PLUGIN_ID] === true;
|
|
5705
5945
|
} catch {
|
|
5706
5946
|
return false;
|
|
@@ -5708,14 +5948,14 @@ async function claudePluginEnabled(settingsFile) {
|
|
|
5708
5948
|
}
|
|
5709
5949
|
async function readKvaliState(home) {
|
|
5710
5950
|
try {
|
|
5711
|
-
return JSON.parse(await
|
|
5951
|
+
return JSON.parse(await fsp8.readFile(stateFile(home), "utf8")) ?? {};
|
|
5712
5952
|
} catch {
|
|
5713
5953
|
return {};
|
|
5714
5954
|
}
|
|
5715
5955
|
}
|
|
5716
5956
|
async function writeKvaliState(home, patch) {
|
|
5717
5957
|
const next = { ...await readKvaliState(home), ...patch };
|
|
5718
|
-
await
|
|
5958
|
+
await fsp8.mkdir(path14.dirname(stateFile(home)), { recursive: true, mode: 448 });
|
|
5719
5959
|
await writeFileSafely(stateFile(home), `${JSON.stringify(next, null, 2)}
|
|
5720
5960
|
`);
|
|
5721
5961
|
}
|
|
@@ -5728,12 +5968,12 @@ async function removeClaudePlugin(opts) {
|
|
|
5728
5968
|
const list = await runClaude(opts.bin, ["plugin", "marketplace", "list", "--json"], opts.env);
|
|
5729
5969
|
try {
|
|
5730
5970
|
const mk = JSON.parse(list.out.slice(list.out.indexOf("["))).find((m) => m.name === CLAUDE_MARKETPLACE);
|
|
5731
|
-
if (mk && mk.path &&
|
|
5971
|
+
if (mk && mk.path && path14.resolve(mk.path) === path14.resolve(dir)) await runClaude(opts.bin, ["plugin", "marketplace", "remove", CLAUDE_MARKETPLACE], opts.env);
|
|
5732
5972
|
} catch {
|
|
5733
5973
|
}
|
|
5734
5974
|
} else {
|
|
5735
5975
|
try {
|
|
5736
|
-
const raw = await
|
|
5976
|
+
const raw = await fsp8.readFile(opts.settingsFile, "utf8");
|
|
5737
5977
|
const s = JSON.parse(raw);
|
|
5738
5978
|
let changed = false;
|
|
5739
5979
|
if (s.enabledPlugins && CLAUDE_PLUGIN_ID in s.enabledPlugins) {
|
|
@@ -5741,16 +5981,16 @@ async function removeClaudePlugin(opts) {
|
|
|
5741
5981
|
changed = true;
|
|
5742
5982
|
}
|
|
5743
5983
|
const mk = s.extraKnownMarketplaces?.[CLAUDE_MARKETPLACE];
|
|
5744
|
-
if (mk?.source?.path &&
|
|
5984
|
+
if (mk?.source?.path && path14.resolve(mk.source.path) === path14.resolve(dir)) {
|
|
5745
5985
|
delete s.extraKnownMarketplaces[CLAUDE_MARKETPLACE];
|
|
5746
5986
|
changed = true;
|
|
5747
5987
|
}
|
|
5748
|
-
if (changed) await
|
|
5988
|
+
if (changed) await fsp8.writeFile(opts.settingsFile, `${JSON.stringify(s, null, 2)}
|
|
5749
5989
|
`);
|
|
5750
5990
|
} catch {
|
|
5751
5991
|
}
|
|
5752
5992
|
}
|
|
5753
|
-
await
|
|
5993
|
+
await fsp8.rm(dir, { recursive: true, force: true });
|
|
5754
5994
|
await writeKvaliState(opts.home, { claudePlugin: false });
|
|
5755
5995
|
return true;
|
|
5756
5996
|
}
|
|
@@ -5765,8 +6005,8 @@ var CLAUDE_HOOKS = [
|
|
|
5765
6005
|
var CLAUDE_HOOK_EVENTS = CLAUDE_HOOKS.map((h) => h.event);
|
|
5766
6006
|
var MARKER = "/v1/events/claude-code";
|
|
5767
6007
|
function claudeSettingsPath(home = os2.homedir(), env = process.env) {
|
|
5768
|
-
const dir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() ||
|
|
5769
|
-
return
|
|
6008
|
+
const dir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path15.join(home, ".claude");
|
|
6009
|
+
return path15.join(dir, "settings.json");
|
|
5770
6010
|
}
|
|
5771
6011
|
function claudeHookCommand(port = DEFAULT_HOOK_PORT, sync = false) {
|
|
5772
6012
|
const url = `http://127.0.0.1:${port}${MARKER}`;
|
|
@@ -5778,7 +6018,7 @@ function hookEntry(spec, port) {
|
|
|
5778
6018
|
async function readSettings(file) {
|
|
5779
6019
|
let text;
|
|
5780
6020
|
try {
|
|
5781
|
-
text = await
|
|
6021
|
+
text = await fsp9.readFile(file, "utf8");
|
|
5782
6022
|
} catch (err) {
|
|
5783
6023
|
if (err.code === "ENOENT") return {};
|
|
5784
6024
|
throw err;
|
|
@@ -5835,7 +6075,7 @@ async function claudeHooksStatus(file = claudeSettingsPath(), port = DEFAULT_HOO
|
|
|
5835
6075
|
return current === CLAUDE_HOOKS.length && total === CLAUDE_HOOKS.length ? "installed" : "outdated";
|
|
5836
6076
|
}
|
|
5837
6077
|
async function writeWithBackup(file, before, settings) {
|
|
5838
|
-
await
|
|
6078
|
+
await fsp9.mkdir(path15.dirname(file), { recursive: true });
|
|
5839
6079
|
let backup;
|
|
5840
6080
|
if (before !== void 0) {
|
|
5841
6081
|
backup = `${file}.kvali-backup`;
|
|
@@ -5851,7 +6091,7 @@ function canonical(v) {
|
|
|
5851
6091
|
);
|
|
5852
6092
|
}
|
|
5853
6093
|
async function installClaudeHooks(file = claudeSettingsPath(), port = DEFAULT_HOOK_PORT) {
|
|
5854
|
-
const before = await
|
|
6094
|
+
const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
|
|
5855
6095
|
const current = await readSettings(file);
|
|
5856
6096
|
const settings = withoutKvali(current);
|
|
5857
6097
|
settings.hooks = settings.hooks && typeof settings.hooks === "object" ? settings.hooks : {};
|
|
@@ -5867,7 +6107,7 @@ function envOf(settings) {
|
|
|
5867
6107
|
return settings.env && typeof settings.env === "object" && !Array.isArray(settings.env) ? settings.env : void 0;
|
|
5868
6108
|
}
|
|
5869
6109
|
async function enableClaudeTodoTools(file, home) {
|
|
5870
|
-
const before = await
|
|
6110
|
+
const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
|
|
5871
6111
|
const settings = await readSettings(file);
|
|
5872
6112
|
const env = envOf(settings);
|
|
5873
6113
|
if (env && CLAUDE_TODO_TOOLS_ENV in env) return { changed: false };
|
|
@@ -5878,7 +6118,7 @@ async function enableClaudeTodoTools(file, home) {
|
|
|
5878
6118
|
}
|
|
5879
6119
|
async function disableClaudeTodoTools(file, home) {
|
|
5880
6120
|
if (!(await readKvaliState(home)).claudeTodoTools) return { changed: false };
|
|
5881
|
-
const before = await
|
|
6121
|
+
const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
|
|
5882
6122
|
let changed = false;
|
|
5883
6123
|
if (before !== void 0) {
|
|
5884
6124
|
const settings = await readSettings(file);
|
|
@@ -5895,7 +6135,7 @@ async function disableClaudeTodoTools(file, home) {
|
|
|
5895
6135
|
return { changed };
|
|
5896
6136
|
}
|
|
5897
6137
|
async function uninstallClaudeHooks(file = claudeSettingsPath()) {
|
|
5898
|
-
const before = await
|
|
6138
|
+
const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
|
|
5899
6139
|
if (before === void 0) return { changed: false };
|
|
5900
6140
|
const settings = await readSettings(file);
|
|
5901
6141
|
const next = withoutKvali(settings);
|
|
@@ -5904,8 +6144,8 @@ async function uninstallClaudeHooks(file = claudeSettingsPath()) {
|
|
|
5904
6144
|
}
|
|
5905
6145
|
|
|
5906
6146
|
// ../core/src/protocol.ts
|
|
5907
|
-
import { promises as
|
|
5908
|
-
import
|
|
6147
|
+
import { promises as fsp10 } from "node:fs";
|
|
6148
|
+
import path16 from "node:path";
|
|
5909
6149
|
var PROGRESS_PROTOCOL_MARKER = "<!-- kvali:progress-protocol v2 -->";
|
|
5910
6150
|
function progressProtocolSnippet() {
|
|
5911
6151
|
return `${PROGRESS_PROTOCOL_MARKER}
|
|
@@ -5980,13 +6220,13 @@ function withBlock(text, name, snippet) {
|
|
|
5980
6220
|
return { text: `${text}${sep}${snippet}`, result: "added" };
|
|
5981
6221
|
}
|
|
5982
6222
|
function globalInstructionFiles(home, env = {}) {
|
|
5983
|
-
const claude = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() ||
|
|
5984
|
-
const codex = env.CODEX_HOME ||
|
|
5985
|
-
const 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");
|
|
5986
6226
|
return [
|
|
5987
|
-
{ id: "claude-code", agent: "Claude Code", dir: claude, file:
|
|
5988
|
-
{ id: "codex", agent: "Codex", dir: codex, file:
|
|
5989
|
-
{ id: "gemini", agent: "Gemini CLI / Antigravity", dir: gemini, file:
|
|
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") }
|
|
5990
6230
|
];
|
|
5991
6231
|
}
|
|
5992
6232
|
function withoutBlock(text, name) {
|
|
@@ -6004,13 +6244,13 @@ async function removeGlobalPlanRule(home, env = {}) {
|
|
|
6004
6244
|
for (const target of globalInstructionFiles(home, env)) {
|
|
6005
6245
|
let text;
|
|
6006
6246
|
try {
|
|
6007
|
-
text = await
|
|
6247
|
+
text = await fsp10.readFile(target.file, "utf8");
|
|
6008
6248
|
} catch {
|
|
6009
6249
|
continue;
|
|
6010
6250
|
}
|
|
6011
6251
|
const next = withoutBlock(text, "plan-rule");
|
|
6012
6252
|
if (next === void 0) continue;
|
|
6013
|
-
if (next.trim() === "") await
|
|
6253
|
+
if (next.trim() === "") await fsp10.unlink(target.file);
|
|
6014
6254
|
else await writeFileSafely(target.file, next);
|
|
6015
6255
|
changed.push(target.file);
|
|
6016
6256
|
}
|
|
@@ -6018,7 +6258,7 @@ async function removeGlobalPlanRule(home, env = {}) {
|
|
|
6018
6258
|
}
|
|
6019
6259
|
async function readOptional(file) {
|
|
6020
6260
|
try {
|
|
6021
|
-
return await
|
|
6261
|
+
return await fsp10.readFile(file, "utf8");
|
|
6022
6262
|
} catch {
|
|
6023
6263
|
return void 0;
|
|
6024
6264
|
}
|
|
@@ -6028,7 +6268,7 @@ async function addGlobalPlanRule(home, env = {}, only) {
|
|
|
6028
6268
|
for (const target of globalInstructionFiles(home, env)) {
|
|
6029
6269
|
if (only && !only.includes(target.id)) continue;
|
|
6030
6270
|
try {
|
|
6031
|
-
const st = await
|
|
6271
|
+
const st = await fsp10.stat(target.dir);
|
|
6032
6272
|
if (!st.isDirectory()) continue;
|
|
6033
6273
|
} catch {
|
|
6034
6274
|
continue;
|
|
@@ -6040,7 +6280,7 @@ async function addGlobalPlanRule(home, env = {}, only) {
|
|
|
6040
6280
|
return out;
|
|
6041
6281
|
}
|
|
6042
6282
|
async function addProgressProtocol(root) {
|
|
6043
|
-
const file =
|
|
6283
|
+
const file = path16.join(root, "AGENTS.md");
|
|
6044
6284
|
const current = await readOptional(file);
|
|
6045
6285
|
const next = withBlock(current ?? "# AGENTS.md\n\n", "progress-protocol", progressProtocolSnippet());
|
|
6046
6286
|
if (next.result !== "exists") await writeFileSafely(file, next.text);
|
|
@@ -6049,11 +6289,11 @@ async function addProgressProtocol(root) {
|
|
|
6049
6289
|
|
|
6050
6290
|
// ../core/src/hooks/replies.ts
|
|
6051
6291
|
import { existsSync as existsSync2 } from "node:fs";
|
|
6052
|
-
import
|
|
6292
|
+
import path17 from "node:path";
|
|
6053
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.";
|
|
6054
6294
|
function pluginRunsIn(liveDir, sessionId) {
|
|
6055
6295
|
if (!/^[A-Za-z0-9-]{8,80}$/.test(sessionId)) return false;
|
|
6056
|
-
return existsSync2(
|
|
6296
|
+
return existsSync2(path17.join(liveDir, "claude-code", `${sessionId}.mod.json`));
|
|
6057
6297
|
}
|
|
6058
6298
|
function claudeHookReply(ev, session, pluginRuns = false) {
|
|
6059
6299
|
if (ev.event !== "UserPromptSubmit") return void 0;
|
|
@@ -6066,23 +6306,23 @@ function claudeHookReply(ev, session, pluginRuns = false) {
|
|
|
6066
6306
|
}
|
|
6067
6307
|
|
|
6068
6308
|
// ../core/src/setup.ts
|
|
6069
|
-
import { promises as
|
|
6070
|
-
import
|
|
6309
|
+
import { promises as fsp11 } from "node:fs";
|
|
6310
|
+
import path18 from "node:path";
|
|
6071
6311
|
async function isDir(p2) {
|
|
6072
6312
|
try {
|
|
6073
|
-
return (await
|
|
6313
|
+
return (await fsp11.stat(p2)).isDirectory();
|
|
6074
6314
|
} catch {
|
|
6075
6315
|
return false;
|
|
6076
6316
|
}
|
|
6077
6317
|
}
|
|
6078
6318
|
async function detectAgents(home, env = {}) {
|
|
6079
|
-
const claudeDir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() ||
|
|
6319
|
+
const claudeDir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path18.join(home, ".claude");
|
|
6080
6320
|
const [claude, codex, gemini, ag1, ag2] = await Promise.all([
|
|
6081
6321
|
isDir(claudeDir),
|
|
6082
|
-
isDir(env.CODEX_HOME ||
|
|
6083
|
-
isDir(
|
|
6084
|
-
isDir(
|
|
6085
|
-
isDir(
|
|
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"))
|
|
6086
6326
|
]);
|
|
6087
6327
|
return { claude, codex, gemini, antigravity: ag1 || ag2 };
|
|
6088
6328
|
}
|
|
@@ -6141,8 +6381,8 @@ async function removeSetup(home, env = {}, opts = {}) {
|
|
|
6141
6381
|
|
|
6142
6382
|
// ../core/src/phone.ts
|
|
6143
6383
|
import { randomBytes as randomBytes2, randomInt } from "node:crypto";
|
|
6144
|
-
import { promises as
|
|
6145
|
-
import
|
|
6384
|
+
import { promises as fsp12 } from "node:fs";
|
|
6385
|
+
import path19 from "node:path";
|
|
6146
6386
|
var PHONE_EVENTS = ["needs-you", "done", "steps", "actions", "error", "stuck", "limits"];
|
|
6147
6387
|
var DEFAULT_PHONE_EVENTS = ["needs-you", "done", "error", "stuck", "steps", "limits"];
|
|
6148
6388
|
var DEFAULT_EVENTS_V1 = ["needs-you", "done", "error", "stuck"];
|
|
@@ -6150,7 +6390,7 @@ var DEFAULT_EVENTS_V2 = ["needs-you", "done", "error", "stuck", "steps"];
|
|
|
6150
6390
|
var PHONE_CONFIG_VERSION = 3;
|
|
6151
6391
|
var DEFAULT_NTFY_SERVER = "https://ntfy.sh";
|
|
6152
6392
|
var DEFAULT_DONE_AFTER_SEC = 120;
|
|
6153
|
-
var kvaliConfigFile = (home) =>
|
|
6393
|
+
var kvaliConfigFile = (home) => path19.join(home, ".kvali", "config.json");
|
|
6154
6394
|
var TOPIC_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
6155
6395
|
var TELEGRAM_TOKEN_RE = /^\d{5,15}:[A-Za-z0-9_-]{30,64}$/;
|
|
6156
6396
|
var DISCORD_WEBHOOK_RE = /^https:\/\/(?:(?:ptb|canary)\.)?discord(?:app)?\.com\/api\/webhooks\/\d{5,25}\/[A-Za-z0-9_-]{20,120}$/;
|
|
@@ -6190,7 +6430,7 @@ function normalizePhoneConfig(raw) {
|
|
|
6190
6430
|
}
|
|
6191
6431
|
async function readPhoneConfig(home) {
|
|
6192
6432
|
try {
|
|
6193
|
-
const all = JSON.parse(await
|
|
6433
|
+
const all = JSON.parse(await fsp12.readFile(kvaliConfigFile(home), "utf8"));
|
|
6194
6434
|
return normalizePhoneConfig(all?.phone);
|
|
6195
6435
|
} catch {
|
|
6196
6436
|
return void 0;
|
|
@@ -6200,7 +6440,7 @@ async function writePhoneConfig(home, cfg) {
|
|
|
6200
6440
|
const file = kvaliConfigFile(home);
|
|
6201
6441
|
let all = {};
|
|
6202
6442
|
try {
|
|
6203
|
-
const parsed = JSON.parse(await
|
|
6443
|
+
const parsed = JSON.parse(await fsp12.readFile(file, "utf8"));
|
|
6204
6444
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) all = parsed;
|
|
6205
6445
|
} catch {
|
|
6206
6446
|
}
|
|
@@ -6217,14 +6457,14 @@ async function writePhoneConfig(home, cfg) {
|
|
|
6217
6457
|
doneAfter: cfg.doneAfterSec ?? DEFAULT_DONE_AFTER_SEC
|
|
6218
6458
|
};
|
|
6219
6459
|
else delete all.phone;
|
|
6220
|
-
await
|
|
6460
|
+
await fsp12.mkdir(path19.dirname(file), { recursive: true, mode: 448 });
|
|
6221
6461
|
await writeFileSafely(file, `${JSON.stringify(all, null, 2)}
|
|
6222
6462
|
`, 384);
|
|
6223
6463
|
}
|
|
6224
6464
|
async function secureKvaliHome(home, create = false) {
|
|
6225
|
-
const dir =
|
|
6226
|
-
if (create) await
|
|
6227
|
-
await
|
|
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);
|
|
6228
6468
|
}
|
|
6229
6469
|
function newTopic() {
|
|
6230
6470
|
const alphabet = "abcdefghijkmnpqrstuvwxyz23456789";
|
|
@@ -6839,7 +7079,7 @@ var PhoneNotifier = class {
|
|
|
6839
7079
|
const now = Date.now();
|
|
6840
7080
|
if (!force && now - this.checkedAt < 5e3) return;
|
|
6841
7081
|
this.checkedAt = now;
|
|
6842
|
-
const st = await
|
|
7082
|
+
const st = await fsp12.stat(kvaliConfigFile(this.opts.home)).catch(() => void 0);
|
|
6843
7083
|
const mtime = st?.mtimeMs ?? 0;
|
|
6844
7084
|
if (!force && mtime === this.mtime) return;
|
|
6845
7085
|
this.mtime = mtime;
|
|
@@ -6854,7 +7094,7 @@ var PhoneNotifier = class {
|
|
|
6854
7094
|
this.again = true;
|
|
6855
7095
|
return this.running;
|
|
6856
7096
|
}
|
|
6857
|
-
const
|
|
7097
|
+
const run2 = (async () => {
|
|
6858
7098
|
try {
|
|
6859
7099
|
do {
|
|
6860
7100
|
this.again = false;
|
|
@@ -6864,8 +7104,8 @@ var PhoneNotifier = class {
|
|
|
6864
7104
|
this.running = void 0;
|
|
6865
7105
|
}
|
|
6866
7106
|
})();
|
|
6867
|
-
this.running =
|
|
6868
|
-
return
|
|
7107
|
+
this.running = run2;
|
|
7108
|
+
return run2;
|
|
6869
7109
|
}
|
|
6870
7110
|
/** Looks again every few seconds until `dispose`. */
|
|
6871
7111
|
start() {
|
|
@@ -8579,7 +8819,7 @@ function qrTerminal(text, color = true) {
|
|
|
8579
8819
|
}
|
|
8580
8820
|
|
|
8581
8821
|
// src/index.ts
|
|
8582
|
-
var VERSION = "0.7.
|
|
8822
|
+
var VERSION = "0.7.7";
|
|
8583
8823
|
function parse(argv) {
|
|
8584
8824
|
const opts = {
|
|
8585
8825
|
json: false,
|
|
@@ -8593,7 +8833,8 @@ function parse(argv) {
|
|
|
8593
8833
|
private: false,
|
|
8594
8834
|
steps: void 0,
|
|
8595
8835
|
events: void 0,
|
|
8596
|
-
doneAfter: void 0
|
|
8836
|
+
doneAfter: void 0,
|
|
8837
|
+
keepAwake: "off"
|
|
8597
8838
|
};
|
|
8598
8839
|
const cmd = [];
|
|
8599
8840
|
for (let i = 0; i < argv.length; i += 1) {
|
|
@@ -8612,7 +8853,7 @@ function parse(argv) {
|
|
|
8612
8853
|
break;
|
|
8613
8854
|
case "--project":
|
|
8614
8855
|
case "-p":
|
|
8615
|
-
opts.project =
|
|
8856
|
+
opts.project = path20.resolve(next());
|
|
8616
8857
|
break;
|
|
8617
8858
|
case "--here":
|
|
8618
8859
|
opts.project = process2.cwd();
|
|
@@ -8624,10 +8865,10 @@ function parse(argv) {
|
|
|
8624
8865
|
break;
|
|
8625
8866
|
}
|
|
8626
8867
|
case "--home":
|
|
8627
|
-
opts.home =
|
|
8868
|
+
opts.home = path20.resolve(next());
|
|
8628
8869
|
break;
|
|
8629
8870
|
case "--brain-dir":
|
|
8630
|
-
opts.brainDirs.push(
|
|
8871
|
+
opts.brainDirs.push(path20.resolve(next()));
|
|
8631
8872
|
break;
|
|
8632
8873
|
case "--port": {
|
|
8633
8874
|
const port = Number(next());
|
|
@@ -8670,6 +8911,12 @@ function parse(argv) {
|
|
|
8670
8911
|
opts.doneAfter = Math.round(sec);
|
|
8671
8912
|
break;
|
|
8672
8913
|
}
|
|
8914
|
+
case "--keep-awake":
|
|
8915
|
+
opts.keepAwake = "whenPluggedIn";
|
|
8916
|
+
break;
|
|
8917
|
+
case "--keep-awake=always":
|
|
8918
|
+
opts.keepAwake = "always";
|
|
8919
|
+
break;
|
|
8673
8920
|
case "--svg":
|
|
8674
8921
|
opts.svg = argv[i + 1] !== void 0 && !argv[i + 1].startsWith("-") ? argv[++i] : "";
|
|
8675
8922
|
break;
|
|
@@ -8717,6 +8964,7 @@ Options
|
|
|
8717
8964
|
--home <dir> read agent data from another home directory
|
|
8718
8965
|
--port <n> hook hub port (default ${DEFAULT_HOOK_PORT})
|
|
8719
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)
|
|
8720
8968
|
--no-color
|
|
8721
8969
|
kvali phone options: --server <url> (self-hosted ntfy) --token <token> --private (no project or step names)
|
|
8722
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`;
|
|
@@ -8899,7 +9147,7 @@ async function week(opts, svgFile) {
|
|
|
8899
9147
|
].join("\n")
|
|
8900
9148
|
);
|
|
8901
9149
|
if (svgFile !== void 0) {
|
|
8902
|
-
const file =
|
|
9150
|
+
const file = path20.resolve(svgFile || `kvali-week-${w.days[w.days.length - 1].day}.svg`);
|
|
8903
9151
|
if ((await lstat(file).catch(() => void 0))?.isSymbolicLink()) fail(`${file} is a symbolic link; give the card another file name`);
|
|
8904
9152
|
await writeFile(file, weekSvg(w));
|
|
8905
9153
|
console.log(`
|
|
@@ -9064,6 +9312,14 @@ async function phone(sub, opts, arg) {
|
|
|
9064
9312
|
].join("\n")
|
|
9065
9313
|
);
|
|
9066
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
|
+
}
|
|
9067
9323
|
async function main() {
|
|
9068
9324
|
const { cmd, opts } = parse(process2.argv.slice(2));
|
|
9069
9325
|
await secureKvaliHome(opts.home);
|
|
@@ -9077,7 +9333,7 @@ async function main() {
|
|
|
9077
9333
|
const d = await detectAgents(opts.home, process2.env);
|
|
9078
9334
|
const changes = setupChanges(d);
|
|
9079
9335
|
if (!changes.length) fail("no supported agent found (~/.claude, ~/.codex, ~/.gemini)");
|
|
9080
|
-
const pluginDir =
|
|
9336
|
+
const pluginDir = path20.join(path20.dirname(fileURLToPath(import.meta.url)), "claude-plugin");
|
|
9081
9337
|
const r = await applySetup(opts.home, process2.env, opts.port, d, { pluginDir });
|
|
9082
9338
|
const lines = changes.map((c) => ` \u2022 ${c}`);
|
|
9083
9339
|
if (r.claude === "plugin") lines.push(" Claude Code: new sessions show the Kvali pane; type /reload-plugins in sessions already open.");
|
|
@@ -9093,7 +9349,7 @@ async function main() {
|
|
|
9093
9349
|
return;
|
|
9094
9350
|
}
|
|
9095
9351
|
if (cmd[0] === "protocol") {
|
|
9096
|
-
const r = await addProgressProtocol(
|
|
9352
|
+
const r = await addProgressProtocol(path20.resolve(cmd[1] ?? "."));
|
|
9097
9353
|
const said = {
|
|
9098
9354
|
created: `Created ${r.file} with the progress protocol.`,
|
|
9099
9355
|
added: `Added the progress protocol to ${r.file}.`,
|
|
@@ -9120,17 +9376,19 @@ async function main() {
|
|
|
9120
9376
|
startPhone(engine, hub, opts.home, (line) => {
|
|
9121
9377
|
phoneLine = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${line}`;
|
|
9122
9378
|
});
|
|
9379
|
+
const awake = startKeepAwake(engine, opts);
|
|
9123
9380
|
const out = process2.stdout;
|
|
9124
9381
|
out.write(`${ESC}?1049h${ESC}?25l`);
|
|
9125
9382
|
const restore = () => {
|
|
9126
9383
|
out.write(`${ESC}?25h${ESC}?1049l`);
|
|
9384
|
+
awake?.dispose();
|
|
9127
9385
|
hub?.dispose();
|
|
9128
9386
|
engine.dispose();
|
|
9129
9387
|
};
|
|
9130
9388
|
const draw = (snap) => out.write(`${ESC}H${ESC}2J${render(snap, opts)}
|
|
9131
9389
|
${paint(opts.color).gray(`
|
|
9132
9390
|
${phoneLine ? `${phoneLine}
|
|
9133
|
-
` : ""}q to quit`)}`);
|
|
9391
|
+
` : ""}${awake?.active ? "keeping this computer awake \xB7 " : ""}q to quit`)}`);
|
|
9134
9392
|
engine.onSnapshot(draw);
|
|
9135
9393
|
engine.start();
|
|
9136
9394
|
const clock = setInterval(() => draw(engine.snapshot), 1e3);
|
|
@@ -9162,10 +9420,12 @@ async function watch(opts) {
|
|
|
9162
9420
|
const say = (line) => console.log(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${line}`);
|
|
9163
9421
|
hub.start();
|
|
9164
9422
|
startPhone(engine, hub, opts.home, say);
|
|
9423
|
+
const awake = startKeepAwake(engine, opts, say);
|
|
9165
9424
|
engine.start();
|
|
9166
9425
|
const cfg = await readPhoneConfig(opts.home);
|
|
9167
9426
|
say(cfg ? `watching agents; phone notifications go to ${channelNames(cfg)}` : "watching agents; phone notifications are not set up (run `kvali phone`)");
|
|
9168
9427
|
const stop = () => {
|
|
9428
|
+
awake?.dispose();
|
|
9169
9429
|
hub.dispose();
|
|
9170
9430
|
engine.dispose();
|
|
9171
9431
|
process2.exit(0);
|