@kvali/cli 0.7.6 → 0.7.8
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 +656 -230
- 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
|
|
|
@@ -89,6 +89,16 @@ function restOfPlan(typical, spent, left) {
|
|
|
89
89
|
function fmtClock(ms) {
|
|
90
90
|
return new Date(ms).toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" });
|
|
91
91
|
}
|
|
92
|
+
function limitStopText(stop, now) {
|
|
93
|
+
const what = `Stopped at the ${stop.limit}`;
|
|
94
|
+
if (stop.resetsAt === void 0) return what;
|
|
95
|
+
const when = fmtWhen(stop.resetsAt, now);
|
|
96
|
+
return stop.resetsAt > now ? `${what} \xB7 resets at ${when}` : `${what} \xB7 it reset at ${when}`;
|
|
97
|
+
}
|
|
98
|
+
function fmtWhen(ms, now) {
|
|
99
|
+
if (Math.abs(ms - now) < 20 * 36e5) return fmtClock(ms);
|
|
100
|
+
return `${new Date(ms).toLocaleDateString(void 0, { weekday: "short", day: "numeric", month: "short" })} ${fmtClock(ms)}`;
|
|
101
|
+
}
|
|
92
102
|
function fmtAbout(ms) {
|
|
93
103
|
const m = Math.max(1, Math.round(ms / 6e4));
|
|
94
104
|
return m < 60 ? `~${m}m` : `~${Math.floor(m / 60)}h ${String(m % 60).padStart(2, "0")}m`;
|
|
@@ -498,6 +508,7 @@ var OPUS_45_PLUS = p(5, 6.25, 10, 0.5, 25);
|
|
|
498
508
|
var OPUS_LEGACY = p(15, 18.75, 30, 1.5, 75);
|
|
499
509
|
var SONNET_4 = p(3, 3.75, 6, 0.3, 15);
|
|
500
510
|
var ANTHROPIC_PRICES = {
|
|
511
|
+
"fable-5-2": p(8, 10, 16, 0.2, 40),
|
|
501
512
|
"fable-5-1": p(10, 12.5, 20, 0.25, 50),
|
|
502
513
|
"mythos-5-1": p(10, 12.5, 20, 0.25, 50),
|
|
503
514
|
"opus-5-5": { ...p(4, 5, 8, 0.2, 20), fastMultiplier: 2 },
|
|
@@ -616,8 +627,246 @@ var Pricing = class {
|
|
|
616
627
|
}
|
|
617
628
|
};
|
|
618
629
|
|
|
619
|
-
// ../core/src/
|
|
630
|
+
// ../core/src/wake.ts
|
|
631
|
+
import { execFile, spawn } from "node:child_process";
|
|
620
632
|
import { promises as fsp } from "node:fs";
|
|
633
|
+
import path from "node:path";
|
|
634
|
+
var KEEP_AWAKE_GRACE_MS = 6e4;
|
|
635
|
+
var KEEP_AWAKE_QUIET_MS = 10 * 6e4;
|
|
636
|
+
var POWER_TTL_MS = 6e4;
|
|
637
|
+
var RETRY_MS = 6e4;
|
|
638
|
+
var QUICK_END_MS = 5e3;
|
|
639
|
+
function agentsWorking(sessions, now) {
|
|
640
|
+
return sessions.some((s) => {
|
|
641
|
+
if (s.status !== "working") return false;
|
|
642
|
+
const running = !!s.activity && s.activity.endedAt === void 0 && s.activity.kind !== "thinking" && s.activity.kind !== "message";
|
|
643
|
+
const last = Math.max(s.updatedAt, s.pulse?.at ?? 0);
|
|
644
|
+
return running || now - last < KEEP_AWAKE_QUIET_MS;
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
function holdCommand(platform, pid) {
|
|
648
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return void 0;
|
|
649
|
+
switch (platform) {
|
|
650
|
+
case "darwin":
|
|
651
|
+
return { cmd: "caffeinate", args: ["-i", "-w", String(pid)] };
|
|
652
|
+
case "linux":
|
|
653
|
+
return {
|
|
654
|
+
cmd: "systemd-inhibit",
|
|
655
|
+
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`]
|
|
656
|
+
};
|
|
657
|
+
case "win32":
|
|
658
|
+
return {
|
|
659
|
+
cmd: "powershell.exe",
|
|
660
|
+
args: [
|
|
661
|
+
"-NoProfile",
|
|
662
|
+
"-NonInteractive",
|
|
663
|
+
"-Command",
|
|
664
|
+
[
|
|
665
|
+
`$k = Add-Type -Name Awake -Namespace Kvali -PassThru -MemberDefinition '[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint f);'`,
|
|
666
|
+
// ES_CONTINUOUS | ES_SYSTEM_REQUIRED, written in decimal: PowerShell 5 reads 0x80000001 as a negative Int32.
|
|
667
|
+
"[void]$k::SetThreadExecutionState([uint32]2147483649)",
|
|
668
|
+
`while (Get-Process -Id ${pid} -ErrorAction SilentlyContinue) { Start-Sleep -Seconds 30 }`
|
|
669
|
+
].join("; ")
|
|
670
|
+
]
|
|
671
|
+
};
|
|
672
|
+
default:
|
|
673
|
+
return void 0;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function parsePmset(out) {
|
|
677
|
+
if (/'AC Power'/.test(out)) return true;
|
|
678
|
+
if (/'Battery Power'/.test(out)) return false;
|
|
679
|
+
return void 0;
|
|
680
|
+
}
|
|
681
|
+
function parseWinBattery(out) {
|
|
682
|
+
const v = out.trim();
|
|
683
|
+
if (!v) return true;
|
|
684
|
+
const n = Number(v.split(/\s+/)[0]);
|
|
685
|
+
if (!Number.isInteger(n)) return void 0;
|
|
686
|
+
return ![1, 4, 5].includes(n);
|
|
687
|
+
}
|
|
688
|
+
function linuxMains(supplies) {
|
|
689
|
+
if (!supplies.length) return true;
|
|
690
|
+
const external = supplies.filter((s) => s.type === "Mains" || s.type.startsWith("USB"));
|
|
691
|
+
if (external.some((s) => s.online === "1")) return true;
|
|
692
|
+
if (supplies.some((s) => s.type === "Battery")) return false;
|
|
693
|
+
return void 0;
|
|
694
|
+
}
|
|
695
|
+
function run(cmd, args) {
|
|
696
|
+
return new Promise((resolve) => {
|
|
697
|
+
try {
|
|
698
|
+
execFile(cmd, args, { timeout: 5e3, windowsHide: true }, (err, stdout) => resolve(err ? void 0 : String(stdout)));
|
|
699
|
+
} catch {
|
|
700
|
+
resolve(void 0);
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
async function onMainsPower(platform = process.platform) {
|
|
705
|
+
if (platform === "darwin") {
|
|
706
|
+
const out = await run("pmset", ["-g", "ps"]);
|
|
707
|
+
return out === void 0 ? void 0 : parsePmset(out);
|
|
708
|
+
}
|
|
709
|
+
if (platform === "win32") {
|
|
710
|
+
const out = await run("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "(Get-CimInstance -ClassName Win32_Battery | Select-Object -First 1).BatteryStatus"]);
|
|
711
|
+
return out === void 0 ? void 0 : parseWinBattery(out);
|
|
712
|
+
}
|
|
713
|
+
if (platform === "linux") {
|
|
714
|
+
const base = "/sys/class/power_supply";
|
|
715
|
+
try {
|
|
716
|
+
const names = await fsp.readdir(base);
|
|
717
|
+
const read = async (name, file) => (await fsp.readFile(path.join(base, name, file), "utf8").catch(() => void 0))?.trim();
|
|
718
|
+
const supplies = await Promise.all(names.map(async (n) => ({ type: await read(n, "type") ?? "", online: await read(n, "online") })));
|
|
719
|
+
return linuxMains(supplies);
|
|
720
|
+
} catch {
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return void 0;
|
|
725
|
+
}
|
|
726
|
+
function spawnHold(c) {
|
|
727
|
+
const child = spawn(c.cmd, c.args, { stdio: "ignore", windowsHide: true });
|
|
728
|
+
child.unref();
|
|
729
|
+
let ended;
|
|
730
|
+
let done = false;
|
|
731
|
+
const end2 = (missing) => {
|
|
732
|
+
if (done) return;
|
|
733
|
+
done = true;
|
|
734
|
+
ended?.(missing);
|
|
735
|
+
};
|
|
736
|
+
child.on("error", (err) => end2(err.code === "ENOENT"));
|
|
737
|
+
child.on("exit", () => end2(false));
|
|
738
|
+
return {
|
|
739
|
+
stop: () => {
|
|
740
|
+
done = true;
|
|
741
|
+
try {
|
|
742
|
+
child.kill();
|
|
743
|
+
} catch {
|
|
744
|
+
}
|
|
745
|
+
},
|
|
746
|
+
onEnd: (fn) => {
|
|
747
|
+
ended = fn;
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
var KeepAwake = class {
|
|
752
|
+
hold;
|
|
753
|
+
releaseTimer;
|
|
754
|
+
mode = "off";
|
|
755
|
+
working = false;
|
|
756
|
+
missing = false;
|
|
757
|
+
retryAt = 0;
|
|
758
|
+
powerReading;
|
|
759
|
+
listeners = /* @__PURE__ */ new Set();
|
|
760
|
+
platform;
|
|
761
|
+
pid;
|
|
762
|
+
graceMs;
|
|
763
|
+
now;
|
|
764
|
+
o;
|
|
765
|
+
constructor(o = {}) {
|
|
766
|
+
this.o = o;
|
|
767
|
+
this.platform = o.platform ?? process.platform;
|
|
768
|
+
this.pid = o.pid ?? process.pid;
|
|
769
|
+
this.graceMs = o.graceMs ?? KEEP_AWAKE_GRACE_MS;
|
|
770
|
+
this.now = o.now ?? Date.now;
|
|
771
|
+
}
|
|
772
|
+
/** True while the computer is being kept awake. */
|
|
773
|
+
get active() {
|
|
774
|
+
return !!this.hold;
|
|
775
|
+
}
|
|
776
|
+
/** Called when `active` changes. */
|
|
777
|
+
onChange(fn) {
|
|
778
|
+
this.listeners.add(fn);
|
|
779
|
+
return () => this.listeners.delete(fn);
|
|
780
|
+
}
|
|
781
|
+
async update(working, mode) {
|
|
782
|
+
if (mode !== this.mode) this.missing = false;
|
|
783
|
+
this.mode = mode;
|
|
784
|
+
this.working = working;
|
|
785
|
+
if (mode === "off") return this.release("turned off");
|
|
786
|
+
if (!working) {
|
|
787
|
+
if (this.hold && this.releaseTimer === void 0) {
|
|
788
|
+
const t = (this.o.setTimer ?? setTimeout)(() => {
|
|
789
|
+
this.releaseTimer = void 0;
|
|
790
|
+
if (!this.working) this.release("no agent is working");
|
|
791
|
+
}, this.graceMs);
|
|
792
|
+
t?.unref?.();
|
|
793
|
+
this.releaseTimer = t;
|
|
794
|
+
}
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
this.clearRelease();
|
|
798
|
+
if (mode === "whenPluggedIn" && await this.mains() === false) return this.release("on battery");
|
|
799
|
+
if (!this.working || this.mode === "off" || this.mode === "whenPluggedIn" && this.powerReading?.mains === false) return;
|
|
800
|
+
this.acquire();
|
|
801
|
+
}
|
|
802
|
+
dispose() {
|
|
803
|
+
this.release();
|
|
804
|
+
this.listeners.clear();
|
|
805
|
+
}
|
|
806
|
+
async mains() {
|
|
807
|
+
const now = this.now();
|
|
808
|
+
if (this.powerReading && now - this.powerReading.at < POWER_TTL_MS) return this.powerReading.mains;
|
|
809
|
+
const mains = await (this.o.power ?? (() => onMainsPower(this.platform)))().catch(() => void 0);
|
|
810
|
+
this.powerReading = { at: this.now(), mains };
|
|
811
|
+
return mains;
|
|
812
|
+
}
|
|
813
|
+
acquire() {
|
|
814
|
+
if (this.hold || this.missing || this.now() < this.retryAt) return;
|
|
815
|
+
const c = holdCommand(this.platform, this.pid);
|
|
816
|
+
if (!c) {
|
|
817
|
+
this.missing = true;
|
|
818
|
+
this.o.log?.(`Keeping the computer awake isn't supported on ${this.platform}.`);
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
let hold;
|
|
822
|
+
try {
|
|
823
|
+
hold = (this.o.start ?? spawnHold)(c);
|
|
824
|
+
} catch (err) {
|
|
825
|
+
this.missing = true;
|
|
826
|
+
this.o.log?.(`Could not keep the computer awake: ${err.message}`);
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
this.hold = hold;
|
|
830
|
+
const startedAt = this.now();
|
|
831
|
+
hold.onEnd((missing) => {
|
|
832
|
+
if (this.hold !== hold) return;
|
|
833
|
+
this.hold = void 0;
|
|
834
|
+
if (missing) {
|
|
835
|
+
this.missing = true;
|
|
836
|
+
this.o.log?.(`Could not keep the computer awake: ${c.cmd} was not found.`);
|
|
837
|
+
} else if (this.now() - startedAt < QUICK_END_MS) {
|
|
838
|
+
this.missing = true;
|
|
839
|
+
this.o.log?.(`Could not keep the computer awake: ${c.cmd} stopped right after it started.`);
|
|
840
|
+
} else {
|
|
841
|
+
this.retryAt = this.now() + RETRY_MS;
|
|
842
|
+
this.o.log?.(`The hold that kept the computer awake (${c.cmd}) ended by itself.`);
|
|
843
|
+
}
|
|
844
|
+
this.emit();
|
|
845
|
+
});
|
|
846
|
+
this.o.log?.("Keeping the computer awake while an agent works.");
|
|
847
|
+
this.emit();
|
|
848
|
+
}
|
|
849
|
+
release(why) {
|
|
850
|
+
this.clearRelease();
|
|
851
|
+
if (!this.hold) return;
|
|
852
|
+
const hold = this.hold;
|
|
853
|
+
this.hold = void 0;
|
|
854
|
+
hold.stop();
|
|
855
|
+
if (why) this.o.log?.(`The computer may sleep again (${why}).`);
|
|
856
|
+
this.emit();
|
|
857
|
+
}
|
|
858
|
+
clearRelease() {
|
|
859
|
+
if (this.releaseTimer === void 0) return;
|
|
860
|
+
(this.o.clearTimer ?? ((t) => clearTimeout(t)))(this.releaseTimer);
|
|
861
|
+
this.releaseTimer = void 0;
|
|
862
|
+
}
|
|
863
|
+
emit() {
|
|
864
|
+
for (const fn of this.listeners) fn(this.active);
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
// ../core/src/util/jsonl.ts
|
|
869
|
+
import { promises as fsp2 } from "node:fs";
|
|
621
870
|
var CHUNK_BYTES = 1 << 20;
|
|
622
871
|
var MAX_LINE_BYTES = 8 << 20;
|
|
623
872
|
var JsonlTail = class {
|
|
@@ -628,8 +877,8 @@ var JsonlTail = class {
|
|
|
628
877
|
mtimeMs = -1;
|
|
629
878
|
ino;
|
|
630
879
|
path;
|
|
631
|
-
constructor(
|
|
632
|
-
this.path =
|
|
880
|
+
constructor(path21) {
|
|
881
|
+
this.path = path21;
|
|
633
882
|
}
|
|
634
883
|
/** Byte offset of the first unconsumed byte. */
|
|
635
884
|
get position() {
|
|
@@ -642,7 +891,7 @@ var JsonlTail = class {
|
|
|
642
891
|
async read(onRecord, onReset) {
|
|
643
892
|
let st;
|
|
644
893
|
try {
|
|
645
|
-
st = await
|
|
894
|
+
st = await fsp2.stat(this.path);
|
|
646
895
|
} catch {
|
|
647
896
|
return { changed: false, reset: false, lines: 0 };
|
|
648
897
|
}
|
|
@@ -658,7 +907,7 @@ var JsonlTail = class {
|
|
|
658
907
|
}
|
|
659
908
|
this.ino = st.ino;
|
|
660
909
|
let lines = 0;
|
|
661
|
-
const fh = await
|
|
910
|
+
const fh = await fsp2.open(this.path, "r");
|
|
662
911
|
try {
|
|
663
912
|
const chunk = Buffer.allocUnsafe(CHUNK_BYTES);
|
|
664
913
|
let pos = this.offset;
|
|
@@ -785,10 +1034,10 @@ function staleness(updatedAt, ctx) {
|
|
|
785
1034
|
|
|
786
1035
|
// ../core/src/engine.ts
|
|
787
1036
|
import os from "node:os";
|
|
788
|
-
import
|
|
1037
|
+
import path12 from "node:path";
|
|
789
1038
|
|
|
790
1039
|
// ../core/src/adapters/antigravity.ts
|
|
791
|
-
import
|
|
1040
|
+
import path3 from "node:path";
|
|
792
1041
|
|
|
793
1042
|
// ../core/src/util/checklist.ts
|
|
794
1043
|
var ITEM_RE = /^([ \t]*)(?:[-*+]|\d{1,9}[.)])[ \t]+\[([ xX/\-~>!?])\][ \t]+(\S.*)$/;
|
|
@@ -868,27 +1117,27 @@ function parseChecklist(markdown) {
|
|
|
868
1117
|
}
|
|
869
1118
|
|
|
870
1119
|
// ../core/src/util/fs.ts
|
|
871
|
-
import { existsSync, promises as
|
|
872
|
-
import
|
|
1120
|
+
import { existsSync, promises as fsp3 } from "node:fs";
|
|
1121
|
+
import path2 from "node:path";
|
|
873
1122
|
async function listDir(dir) {
|
|
874
1123
|
try {
|
|
875
|
-
return await
|
|
1124
|
+
return await fsp3.readdir(dir, { withFileTypes: true });
|
|
876
1125
|
} catch {
|
|
877
1126
|
return [];
|
|
878
1127
|
}
|
|
879
1128
|
}
|
|
880
1129
|
async function statSafe(p2) {
|
|
881
1130
|
try {
|
|
882
|
-
return await
|
|
1131
|
+
return await fsp3.stat(p2);
|
|
883
1132
|
} catch {
|
|
884
1133
|
return void 0;
|
|
885
1134
|
}
|
|
886
1135
|
}
|
|
887
1136
|
async function readTextSafe(p2, maxBytes = 4 << 20) {
|
|
888
1137
|
try {
|
|
889
|
-
const st = await
|
|
1138
|
+
const st = await fsp3.stat(p2);
|
|
890
1139
|
if (!st.isFile() || st.size > maxBytes) return void 0;
|
|
891
|
-
return await
|
|
1140
|
+
return await fsp3.readFile(p2, "utf8");
|
|
892
1141
|
} catch {
|
|
893
1142
|
return void 0;
|
|
894
1143
|
}
|
|
@@ -904,7 +1153,7 @@ async function readJsonSafe(p2, maxBytes = 4 << 20) {
|
|
|
904
1153
|
}
|
|
905
1154
|
var rootCache = /* @__PURE__ */ new Map();
|
|
906
1155
|
function findGitRoot(p2, maxLevels = 12) {
|
|
907
|
-
let dir =
|
|
1156
|
+
let dir = path2.resolve(p2);
|
|
908
1157
|
const visited = [];
|
|
909
1158
|
for (let i = 0; i < maxLevels; i += 1) {
|
|
910
1159
|
if (rootCache.has(dir)) {
|
|
@@ -913,11 +1162,11 @@ function findGitRoot(p2, maxLevels = 12) {
|
|
|
913
1162
|
return hit;
|
|
914
1163
|
}
|
|
915
1164
|
visited.push(dir);
|
|
916
|
-
if (existsSync(
|
|
1165
|
+
if (existsSync(path2.join(dir, ".git"))) {
|
|
917
1166
|
for (const v of visited) rootCache.set(v, dir);
|
|
918
1167
|
return dir;
|
|
919
1168
|
}
|
|
920
|
-
const parent =
|
|
1169
|
+
const parent = path2.dirname(dir);
|
|
921
1170
|
if (parent === dir) break;
|
|
922
1171
|
dir = parent;
|
|
923
1172
|
}
|
|
@@ -925,8 +1174,8 @@ function findGitRoot(p2, maxLevels = 12) {
|
|
|
925
1174
|
return void 0;
|
|
926
1175
|
}
|
|
927
1176
|
function isWithin(child, parent) {
|
|
928
|
-
const rel2 =
|
|
929
|
-
return rel2 === "" || !rel2.startsWith("..") && !
|
|
1177
|
+
const rel2 = path2.relative(parent, child);
|
|
1178
|
+
return rel2 === "" || !rel2.startsWith("..") && !path2.isAbsolute(rel2);
|
|
930
1179
|
}
|
|
931
1180
|
|
|
932
1181
|
// ../core/src/util/task-timer.ts
|
|
@@ -1063,7 +1312,7 @@ function argmax(m) {
|
|
|
1063
1312
|
}
|
|
1064
1313
|
function commonAncestor(dirs) {
|
|
1065
1314
|
if (!dirs.length) return void 0;
|
|
1066
|
-
const split = dirs.map((d) => d.split(
|
|
1315
|
+
const split = dirs.map((d) => d.split(path3.sep));
|
|
1067
1316
|
const first = split[0];
|
|
1068
1317
|
let n = first.length;
|
|
1069
1318
|
for (const parts of split) {
|
|
@@ -1071,7 +1320,7 @@ function commonAncestor(dirs) {
|
|
|
1071
1320
|
while (i < n && i < parts.length && parts[i] === first[i]) i += 1;
|
|
1072
1321
|
n = i;
|
|
1073
1322
|
}
|
|
1074
|
-
const joined = first.slice(0, n).join(
|
|
1323
|
+
const joined = first.slice(0, n).join(path3.sep);
|
|
1075
1324
|
return joined || void 0;
|
|
1076
1325
|
}
|
|
1077
1326
|
function inferProject(votes, home) {
|
|
@@ -1089,7 +1338,7 @@ function inferProject(votes, home) {
|
|
|
1089
1338
|
if (gitWeight * 2 >= total) return argmax(byGit);
|
|
1090
1339
|
const strong = [...votes].filter(([, w]) => w * 10 >= total).map(([d]) => d);
|
|
1091
1340
|
const anc = commonAncestor(strong);
|
|
1092
|
-
const tooGeneric = !anc || anc.split(
|
|
1341
|
+
const tooGeneric = !anc || anc.split(path3.sep).filter(Boolean).length < 2 || home !== void 0 && (isWithin(home, anc) || path3.dirname(anc) === home);
|
|
1093
1342
|
return tooGeneric ? argmax(votes) : anc;
|
|
1094
1343
|
}
|
|
1095
1344
|
function humanize(tool) {
|
|
@@ -1117,8 +1366,8 @@ var AntigravityAdapter = class {
|
|
|
1117
1366
|
this.extraBrainDirs = extraBrainDirs;
|
|
1118
1367
|
}
|
|
1119
1368
|
brainDirs(ctx) {
|
|
1120
|
-
const g =
|
|
1121
|
-
return [
|
|
1369
|
+
const g = path3.join(ctx.home, ".gemini");
|
|
1370
|
+
return [path3.join(g, "antigravity-ide", "brain"), path3.join(g, "antigravity", "brain"), ...this.extraBrainDirs];
|
|
1122
1371
|
}
|
|
1123
1372
|
async poll(ctx) {
|
|
1124
1373
|
const now = ctx.now();
|
|
@@ -1147,7 +1396,7 @@ var AntigravityAdapter = class {
|
|
|
1147
1396
|
return {
|
|
1148
1397
|
id,
|
|
1149
1398
|
dir,
|
|
1150
|
-
tail: new JsonlTail(
|
|
1399
|
+
tail: new JsonlTail(path3.join(dir, ".system_generated", "logs", "transcript.jsonl")),
|
|
1151
1400
|
updatedAt: 0,
|
|
1152
1401
|
votes: /* @__PURE__ */ new Map(),
|
|
1153
1402
|
projectVotesAt: -1,
|
|
@@ -1164,10 +1413,10 @@ var AntigravityAdapter = class {
|
|
|
1164
1413
|
for (const brain of this.brainDirs(ctx)) {
|
|
1165
1414
|
for (const d of await listDir(brain)) {
|
|
1166
1415
|
if (!d.isDirectory() || !/^[0-9a-f-]{36}$/i.test(d.name)) continue;
|
|
1167
|
-
const dir =
|
|
1416
|
+
const dir = path3.join(brain, d.name);
|
|
1168
1417
|
const stats = await Promise.all([
|
|
1169
|
-
statSafe(
|
|
1170
|
-
statSafe(
|
|
1418
|
+
statSafe(path3.join(dir, ".system_generated", "logs", "transcript.jsonl")),
|
|
1419
|
+
statSafe(path3.join(dir, "task.md"))
|
|
1171
1420
|
]);
|
|
1172
1421
|
const mtimeMs = Math.max(...stats.map((s) => s?.mtimeMs ?? 0));
|
|
1173
1422
|
if (mtimeMs && now - mtimeMs <= ctx.activeWindowMs) found.push({ dir, id: d.name, mtimeMs });
|
|
@@ -1194,7 +1443,7 @@ var AntigravityAdapter = class {
|
|
|
1194
1443
|
const status = String(o.status ?? "");
|
|
1195
1444
|
const source = String(o.source ?? "");
|
|
1196
1445
|
const tools = [];
|
|
1197
|
-
const gemini =
|
|
1446
|
+
const gemini = path3.join(ctx.home, ".gemini");
|
|
1198
1447
|
const running = st.recent[0];
|
|
1199
1448
|
if (running && running.endedAt === void 0 && status !== "RUNNING") running.endedAt = at;
|
|
1200
1449
|
for (const tc of Array.isArray(o.tool_calls) ? o.tool_calls : []) {
|
|
@@ -1217,8 +1466,8 @@ var AntigravityAdapter = class {
|
|
|
1217
1466
|
}
|
|
1218
1467
|
for (const [key, weight] of Object.entries(PATH_ARGS)) {
|
|
1219
1468
|
const v = decodeArg(args[key]);
|
|
1220
|
-
if (typeof v !== "string" || !
|
|
1221
|
-
const dir = key === "Cwd" || key === "DirectoryPath" || key === "SearchDirectory" ? v :
|
|
1469
|
+
if (typeof v !== "string" || !path3.isAbsolute(v) || isWithin(v, gemini)) continue;
|
|
1470
|
+
const dir = key === "Cwd" || key === "DirectoryPath" || key === "SearchDirectory" ? v : path3.dirname(v);
|
|
1222
1471
|
st.votes.set(dir, (st.votes.get(dir) ?? 0) + weight);
|
|
1223
1472
|
}
|
|
1224
1473
|
}
|
|
@@ -1252,13 +1501,13 @@ var AntigravityAdapter = class {
|
|
|
1252
1501
|
const model = /`Model Selection` from .*? to (.+?)\.(?:\s|$)/.exec(content)?.[1];
|
|
1253
1502
|
if (model) st.model = model.trim();
|
|
1254
1503
|
const doc = /Active Document: (\/[^\n]+?)(?: \([A-Z_]+\))?\s*$/m.exec(content)?.[1];
|
|
1255
|
-
if (doc &&
|
|
1256
|
-
const dir =
|
|
1504
|
+
if (doc && path3.isAbsolute(doc) && !isWithin(doc, gemini)) {
|
|
1505
|
+
const dir = path3.dirname(doc);
|
|
1257
1506
|
st.votes.set(dir, (st.votes.get(dir) ?? 0) + 1);
|
|
1258
1507
|
}
|
|
1259
1508
|
}
|
|
1260
1509
|
async readTask(st) {
|
|
1261
|
-
const file =
|
|
1510
|
+
const file = path3.join(st.dir, "task.md");
|
|
1262
1511
|
const s = await statSafe(file);
|
|
1263
1512
|
if (!s) {
|
|
1264
1513
|
st.task = void 0;
|
|
@@ -1267,7 +1516,7 @@ var AntigravityAdapter = class {
|
|
|
1267
1516
|
if (st.task?.mtimeMs === s.mtimeMs) return;
|
|
1268
1517
|
const md = await readTextSafe(file, 1 << 20);
|
|
1269
1518
|
const parsed = md ? parseChecklist(md) : void 0;
|
|
1270
|
-
const meta = await readJsonSafe(
|
|
1519
|
+
const meta = await readJsonSafe(path3.join(st.dir, "task.md.metadata.json"));
|
|
1271
1520
|
st.task = {
|
|
1272
1521
|
mtimeMs: s.mtimeMs,
|
|
1273
1522
|
title: (parsed?.title !== void 0 ? withoutTrackerSuffix(parsed.title) : void 0) || void 0,
|
|
@@ -1338,7 +1587,7 @@ var AntigravityAdapter = class {
|
|
|
1338
1587
|
tasks,
|
|
1339
1588
|
activity,
|
|
1340
1589
|
daily: Object.keys(st.daily).length ? st.daily : void 0,
|
|
1341
|
-
sources: [
|
|
1590
|
+
sources: [path3.join(st.dir, "task.md"), st.tail.path]
|
|
1342
1591
|
};
|
|
1343
1592
|
}
|
|
1344
1593
|
};
|
|
@@ -1350,7 +1599,7 @@ function withoutTrackerSuffix(title) {
|
|
|
1350
1599
|
}
|
|
1351
1600
|
|
|
1352
1601
|
// ../core/src/adapters/claude-code.ts
|
|
1353
|
-
import
|
|
1602
|
+
import path4 from "node:path";
|
|
1354
1603
|
|
|
1355
1604
|
// ../core/src/util/loop-watch.ts
|
|
1356
1605
|
var SAME_ERROR_RUNS = 4;
|
|
@@ -1407,6 +1656,106 @@ function loopKey(a) {
|
|
|
1407
1656
|
return a.kind === "command" ? `command:${a.detail ?? a.label}` : `${a.label}:${a.detail ?? ""}`;
|
|
1408
1657
|
}
|
|
1409
1658
|
|
|
1659
|
+
// ../core/src/util/limit-stop.ts
|
|
1660
|
+
var LIMIT_TEXT = /^(?:You've hit your|You've reached your|You're out of usage credits|Claude AI usage limit reached)/i;
|
|
1661
|
+
var LIMIT_NAMES = {
|
|
1662
|
+
five_hour: "5-hour limit",
|
|
1663
|
+
seven_day: "weekly limit",
|
|
1664
|
+
seven_day_opus: "Opus limit",
|
|
1665
|
+
seven_day_sonnet: "Sonnet limit",
|
|
1666
|
+
seven_day_overage_included: "Fable limit",
|
|
1667
|
+
overage: "usage credit limit"
|
|
1668
|
+
};
|
|
1669
|
+
var toMs = (v) => v < 1e12 ? v * 1e3 : v;
|
|
1670
|
+
function limitStopOf(record, text, at) {
|
|
1671
|
+
const t = text.trim();
|
|
1672
|
+
const isLimit = record.apiError === "usage_limit_reached" || LIMIT_TEXT.test(t) || record.error === "rate_limit" && /\blimit\b/i.test(t) && !/rate limited/i.test(t);
|
|
1673
|
+
if (!isLimit) return void 0;
|
|
1674
|
+
const info = record.apiErrorParams?.rate_limit_info;
|
|
1675
|
+
let resetsAt = typeof info?.resetsAt === "number" && info.resetsAt > 0 ? toMs(info.resetsAt) : void 0;
|
|
1676
|
+
resetsAt ??= parseResetsAt(t, at);
|
|
1677
|
+
const named = typeof info?.rateLimitType === "string" ? LIMIT_NAMES[info.rateLimitType] : void 0;
|
|
1678
|
+
const said = /^You've (?:hit|reached) your (.+?)(?:\s+·|\.|$)/i.exec(t)?.[1]?.trim();
|
|
1679
|
+
return { at, limit: named ?? (said && said.length <= 40 ? said : "usage limit"), resetsAt };
|
|
1680
|
+
}
|
|
1681
|
+
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
1682
|
+
var DAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
1683
|
+
function validZone(tz) {
|
|
1684
|
+
if (!tz) return void 0;
|
|
1685
|
+
try {
|
|
1686
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
1687
|
+
return tz;
|
|
1688
|
+
} catch {
|
|
1689
|
+
return void 0;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
function wall(t, tz) {
|
|
1693
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
1694
|
+
timeZone: tz,
|
|
1695
|
+
hourCycle: "h23",
|
|
1696
|
+
year: "numeric",
|
|
1697
|
+
month: "numeric",
|
|
1698
|
+
day: "numeric",
|
|
1699
|
+
hour: "numeric",
|
|
1700
|
+
minute: "numeric",
|
|
1701
|
+
weekday: "short"
|
|
1702
|
+
}).formatToParts(new Date(t));
|
|
1703
|
+
const get = (type) => parts.find((p2) => p2.type === type)?.value ?? "";
|
|
1704
|
+
return {
|
|
1705
|
+
y: Number(get("year")),
|
|
1706
|
+
mo: Number(get("month")) - 1,
|
|
1707
|
+
d: Number(get("day")),
|
|
1708
|
+
h: Number(get("hour")) % 24,
|
|
1709
|
+
mi: Number(get("minute")),
|
|
1710
|
+
wd: DAYS.indexOf(get("weekday").slice(0, 3).toLowerCase())
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
function instant(y, mo, d, h, mi, tz) {
|
|
1714
|
+
const want = Date.UTC(y, mo, d, h, mi);
|
|
1715
|
+
let t = want;
|
|
1716
|
+
for (let i = 0; i < 3; i += 1) {
|
|
1717
|
+
const w = wall(t, tz);
|
|
1718
|
+
const diff = want - Date.UTC(w.y, w.mo, w.d, w.h, w.mi);
|
|
1719
|
+
if (diff === 0) break;
|
|
1720
|
+
t += diff;
|
|
1721
|
+
}
|
|
1722
|
+
return t;
|
|
1723
|
+
}
|
|
1724
|
+
function parseResetsAt(text, at) {
|
|
1725
|
+
const legacy = /usage limit reached\|(\d{10,13})/i.exec(text);
|
|
1726
|
+
if (legacy) return toMs(Number(legacy[1]));
|
|
1727
|
+
const rel2 = /\bresets?\s+in\s+(?:(\d+)\s*d(?:ays?)?\s*)?(?:(\d+)\s*h(?:ours?|rs?)?\s*)?(?:(\d+)\s*m(?:in(?:ute)?s?)?)?/i.exec(text);
|
|
1728
|
+
if (rel2 && (rel2[1] || rel2[2] || rel2[3])) return at + ((Number(rel2[1] ?? 0) * 24 + Number(rel2[2] ?? 0)) * 60 + Number(rel2[3] ?? 0)) * 6e4;
|
|
1729
|
+
const m = /\bresets?\s+(?:on\s+)?(?:(sun|mon|tue|wed|thu|fri|sat)[a-z]*,?\s+)?(?:(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?\s+(\d{1,2})(?:st|nd|rd|th)?,?\s+)?(?:at\s+)?(\d{1,2})(?::(\d{2}))?\s*(am|pm)?(?:\s*\(([^)]+)\))?/i.exec(
|
|
1730
|
+
text
|
|
1731
|
+
);
|
|
1732
|
+
if (!m) return void 0;
|
|
1733
|
+
let h = Number(m[4]);
|
|
1734
|
+
const mi = Number(m[5] ?? 0);
|
|
1735
|
+
const ampm = m[6]?.toLowerCase();
|
|
1736
|
+
if (ampm) {
|
|
1737
|
+
if (h < 1 || h > 12) return void 0;
|
|
1738
|
+
h = h % 12 + (ampm === "pm" ? 12 : 0);
|
|
1739
|
+
} else if (!m[5] || h > 23) {
|
|
1740
|
+
return void 0;
|
|
1741
|
+
}
|
|
1742
|
+
if (mi > 59) return void 0;
|
|
1743
|
+
const tz = validZone(m[7]?.trim()) ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
|
|
1744
|
+
const now = wall(at, tz);
|
|
1745
|
+
if (m[2]) {
|
|
1746
|
+
const mo = MONTHS.indexOf(m[2].toLowerCase());
|
|
1747
|
+
const d = Number(m[3]);
|
|
1748
|
+
let t2 = instant(now.y, mo, d, h, mi, tz);
|
|
1749
|
+
if (t2 < at - 864e5) t2 = instant(now.y + 1, mo, d, h, mi, tz);
|
|
1750
|
+
return t2;
|
|
1751
|
+
}
|
|
1752
|
+
let days = 0;
|
|
1753
|
+
if (m[1]) days = (DAYS.indexOf(m[1].toLowerCase()) - now.wd + 7) % 7;
|
|
1754
|
+
let t = instant(now.y, now.mo, now.d + days, h, mi, tz);
|
|
1755
|
+
if (t <= at) t = instant(now.y, now.mo, now.d + days + (m[1] ? 7 : 1), h, mi, tz);
|
|
1756
|
+
return t;
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1410
1759
|
// ../core/src/adapters/claude-code.ts
|
|
1411
1760
|
var PULSE_FRESH_MS = 3e4;
|
|
1412
1761
|
var PULSE_ACTIVE = /* @__PURE__ */ new Set(["requesting", "thinking", "writing", "tool-input", "running", "needs-you", "stalled"]);
|
|
@@ -1464,7 +1813,7 @@ function normStatus(s) {
|
|
|
1464
1813
|
}
|
|
1465
1814
|
function rel(file, cwd) {
|
|
1466
1815
|
if (typeof file !== "string") return void 0;
|
|
1467
|
-
if (cwd && file.startsWith(cwd +
|
|
1816
|
+
if (cwd && file.startsWith(cwd + path4.sep)) return file.slice(cwd.length + 1);
|
|
1468
1817
|
return file;
|
|
1469
1818
|
}
|
|
1470
1819
|
function describeClaudeTool(name, input, cwd, at) {
|
|
@@ -1519,7 +1868,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1519
1868
|
limitBook = new LimitBook();
|
|
1520
1869
|
configDir(ctx) {
|
|
1521
1870
|
const fromEnv = ctx.env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim();
|
|
1522
|
-
return fromEnv ||
|
|
1871
|
+
return fromEnv || path4.join(ctx.home, ".claude");
|
|
1523
1872
|
}
|
|
1524
1873
|
async poll(ctx) {
|
|
1525
1874
|
const now = ctx.now();
|
|
@@ -1529,7 +1878,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1529
1878
|
}
|
|
1530
1879
|
const out = [];
|
|
1531
1880
|
for (const entry of this.sessions.values()) {
|
|
1532
|
-
await isolated(ctx, `[claude-code] ${
|
|
1881
|
+
await isolated(ctx, `[claude-code] ${path4.basename(entry.state.file)}`, async () => {
|
|
1533
1882
|
const res = await entry.tail.read(
|
|
1534
1883
|
(rec) => this.onRecord(entry.state, rec, ctx, false),
|
|
1535
1884
|
() => {
|
|
@@ -1541,7 +1890,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1541
1890
|
}
|
|
1542
1891
|
await isolated(ctx, "[claude-code] subagents", () => this.readLegacyAgents(ctx));
|
|
1543
1892
|
for (const entry of this.sessions.values()) {
|
|
1544
|
-
const s = await isolated(ctx, `[claude-code] ${
|
|
1893
|
+
const s = await isolated(ctx, `[claude-code] ${path4.basename(entry.state.file)}`, () => this.toSession(entry.state, ctx));
|
|
1545
1894
|
if (s) out.push(s);
|
|
1546
1895
|
}
|
|
1547
1896
|
return out;
|
|
@@ -1555,13 +1904,13 @@ var ClaudeCodeAdapter = class {
|
|
|
1555
1904
|
const now = ctx.now();
|
|
1556
1905
|
const full = now - this.lastFullScan >= 6e4;
|
|
1557
1906
|
if (full) this.lastFullScan = now;
|
|
1558
|
-
const projectsDir =
|
|
1907
|
+
const projectsDir = path4.join(this.configDir(ctx), "projects");
|
|
1559
1908
|
const found = [];
|
|
1560
1909
|
const legacy = [];
|
|
1561
1910
|
const seenDirs = /* @__PURE__ */ new Set();
|
|
1562
1911
|
for (const d of await listDir(projectsDir)) {
|
|
1563
1912
|
if (!d.isDirectory()) continue;
|
|
1564
|
-
const dir =
|
|
1913
|
+
const dir = path4.join(projectsDir, d.name);
|
|
1565
1914
|
seenDirs.add(dir);
|
|
1566
1915
|
const dst = await statSafe(dir);
|
|
1567
1916
|
if (!dst) continue;
|
|
@@ -1570,7 +1919,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1570
1919
|
const files = [];
|
|
1571
1920
|
for (const f of await listDir(dir)) {
|
|
1572
1921
|
if (!f.isFile() || !f.name.endsWith(".jsonl")) continue;
|
|
1573
|
-
const file =
|
|
1922
|
+
const file = path4.join(dir, f.name);
|
|
1574
1923
|
const st = await statSafe(file);
|
|
1575
1924
|
if (st) files.push({ file, mtimeMs: st.mtimeMs });
|
|
1576
1925
|
}
|
|
@@ -1580,7 +1929,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1580
1929
|
for (const f of cached.files) {
|
|
1581
1930
|
const mtimeMs = Math.max(f.mtimeMs, this.sessions.get(f.file)?.state.updatedAt ?? 0);
|
|
1582
1931
|
if (now - mtimeMs > ctx.activeWindowMs) continue;
|
|
1583
|
-
(
|
|
1932
|
+
(path4.basename(f.file).startsWith("agent-") ? legacy : found).push({ file: f.file, mtimeMs });
|
|
1584
1933
|
}
|
|
1585
1934
|
}
|
|
1586
1935
|
for (const dir of [...this.dirCache.keys()]) if (!seenDirs.has(dir)) this.dirCache.delete(dir);
|
|
@@ -1598,8 +1947,8 @@ var ClaudeCodeAdapter = class {
|
|
|
1598
1947
|
const daily = {};
|
|
1599
1948
|
return {
|
|
1600
1949
|
file,
|
|
1601
|
-
sessionId:
|
|
1602
|
-
projectDir:
|
|
1950
|
+
sessionId: path4.basename(file, ".jsonl"),
|
|
1951
|
+
projectDir: path4.dirname(file),
|
|
1603
1952
|
updatedAt: 0,
|
|
1604
1953
|
usage: { seen: /* @__PURE__ */ new Set() },
|
|
1605
1954
|
tokens: emptyTokens(),
|
|
@@ -1653,7 +2002,10 @@ var ClaudeCodeAdapter = class {
|
|
|
1653
2002
|
if (st.lastRecordAt === void 0 || ts > st.lastRecordAt) st.lastRecordAt = ts;
|
|
1654
2003
|
}
|
|
1655
2004
|
if (typeof o.version === "string") st.version = o.version;
|
|
1656
|
-
if (typeof o.entrypoint === "string")
|
|
2005
|
+
if (typeof o.entrypoint === "string") {
|
|
2006
|
+
st.entrypoint = o.entrypoint;
|
|
2007
|
+
if (o.entrypoint !== "cli" && /vscode|jetbrains|ide/.test(o.entrypoint)) st.ranInEditor = true;
|
|
2008
|
+
}
|
|
1657
2009
|
if (typeof o.cwd === "string" && o.cwd) {
|
|
1658
2010
|
st.cwd = o.cwd;
|
|
1659
2011
|
st.launchCwd ??= o.cwd;
|
|
@@ -1761,8 +2113,20 @@ var ClaudeCodeAdapter = class {
|
|
|
1761
2113
|
if (typeof m.model === "string" && m.model !== "<synthetic>") st.model = m.model;
|
|
1762
2114
|
st.lastModelAt = ts;
|
|
1763
2115
|
this.countUsage(st, o, ts, ctx, true);
|
|
1764
|
-
if (m.model !== "<synthetic>")
|
|
2116
|
+
if (m.model !== "<synthetic>") {
|
|
2117
|
+
st.trouble = void 0;
|
|
2118
|
+
st.limitStop = void 0;
|
|
2119
|
+
}
|
|
1765
2120
|
if (o.isApiErrorMessage || o.error && m.model === "<synthetic>") {
|
|
2121
|
+
const limit = limitStopOf(o, contentText(m.content), ts);
|
|
2122
|
+
if (limit) {
|
|
2123
|
+
st.limitStop = limit;
|
|
2124
|
+
st.phase = "idle";
|
|
2125
|
+
st.phaseAt = ts;
|
|
2126
|
+
st.open.clear();
|
|
2127
|
+
this.endTurn(st, ts, void 0);
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
1766
2130
|
st.phase = "error";
|
|
1767
2131
|
st.phaseAt = ts;
|
|
1768
2132
|
st.errorText = firstLine(contentText(m.content) || "API error", 120);
|
|
@@ -1915,6 +2279,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1915
2279
|
st.turnOpen = true;
|
|
1916
2280
|
st.turnEndedBy = void 0;
|
|
1917
2281
|
st.loops.reset();
|
|
2282
|
+
st.limitStop = void 0;
|
|
1918
2283
|
}
|
|
1919
2284
|
if (!isCommand) {
|
|
1920
2285
|
st.phase = "working";
|
|
@@ -1926,20 +2291,20 @@ var ClaudeCodeAdapter = class {
|
|
|
1926
2291
|
async readSideFiles(st, ctx, changed) {
|
|
1927
2292
|
const config = this.configDir(ctx);
|
|
1928
2293
|
if (changed || st.taskDir === void 0) {
|
|
1929
|
-
const dir =
|
|
2294
|
+
const dir = path4.join(config, "tasks", st.sessionId);
|
|
1930
2295
|
const entries = (await listDir(dir)).filter((e) => e.isFile() && e.name.endsWith(".json"));
|
|
1931
2296
|
if (entries.length === 0) st.taskDir = { sig: "", tasks: [] };
|
|
1932
2297
|
else {
|
|
1933
|
-
const stats = await Promise.all(entries.map((e) => statSafe(
|
|
2298
|
+
const stats = await Promise.all(entries.map((e) => statSafe(path4.join(dir, e.name))));
|
|
1934
2299
|
const sig = entries.map((e, i) => `${e.name}:${stats[i]?.mtimeMs ?? 0}`).join("|");
|
|
1935
2300
|
if (sig !== st.taskDir?.sig) {
|
|
1936
2301
|
const tasks = [];
|
|
1937
2302
|
const timed = [];
|
|
1938
2303
|
for (const [i, e] of entries.entries()) {
|
|
1939
|
-
const t = await readJsonSafe(
|
|
2304
|
+
const t = await readJsonSafe(path4.join(dir, e.name));
|
|
1940
2305
|
if (!t || t.status === "deleted") continue;
|
|
1941
2306
|
const task = {
|
|
1942
|
-
id: String(t.id ??
|
|
2307
|
+
id: String(t.id ?? path4.basename(e.name, ".json")),
|
|
1943
2308
|
title: String(t.subject ?? t.title ?? ""),
|
|
1944
2309
|
activeTitle: typeof t.activeForm === "string" ? t.activeForm : void 0,
|
|
1945
2310
|
status: normStatus(t.status)
|
|
@@ -1953,14 +2318,14 @@ var ClaudeCodeAdapter = class {
|
|
|
1953
2318
|
}
|
|
1954
2319
|
}
|
|
1955
2320
|
}
|
|
1956
|
-
const liveFile =
|
|
2321
|
+
const liveFile = path4.join(ctx.liveDir, "claude-code", `${st.sessionId}.json`);
|
|
1957
2322
|
const lst = await statSafe(liveFile);
|
|
1958
2323
|
if (!lst) st.live = void 0;
|
|
1959
2324
|
else if (lst.mtimeMs !== st.live?.mtimeMs) {
|
|
1960
2325
|
const live = await readJsonSafe(liveFile);
|
|
1961
2326
|
st.live = live ? { ...live, mtimeMs: lst.mtimeMs } : void 0;
|
|
1962
2327
|
}
|
|
1963
|
-
const pulseFile =
|
|
2328
|
+
const pulseFile = path4.join(ctx.liveDir, "claude-code", `${st.sessionId}.mod.json`);
|
|
1964
2329
|
const pst = await statSafe(pulseFile);
|
|
1965
2330
|
if (!pst) st.pulse = void 0;
|
|
1966
2331
|
else if (pst.mtimeMs !== st.pulse?.mtimeMs) {
|
|
@@ -1971,13 +2336,13 @@ var ClaudeCodeAdapter = class {
|
|
|
1971
2336
|
const now = ctx.now();
|
|
1972
2337
|
if (now - st.lastSubagentScan >= 5e3) {
|
|
1973
2338
|
st.lastSubagentScan = now;
|
|
1974
|
-
const subDir =
|
|
2339
|
+
const subDir = path4.join(st.projectDir, st.sessionId, "subagents");
|
|
1975
2340
|
const dirs = [subDir];
|
|
1976
|
-
for (const
|
|
2341
|
+
for (const run2 of await listDir(path4.join(subDir, "workflows"))) if (run2.isDirectory()) dirs.push(path4.join(subDir, "workflows", run2.name));
|
|
1977
2342
|
for (const dir of dirs) {
|
|
1978
2343
|
for (const f of await listDir(dir)) {
|
|
1979
2344
|
if (!f.isFile() || !f.name.endsWith(".jsonl")) continue;
|
|
1980
|
-
const file =
|
|
2345
|
+
const file = path4.join(dir, f.name);
|
|
1981
2346
|
if (!st.subagents.has(file)) st.subagents.set(file, { tail: new JsonlTail(file) });
|
|
1982
2347
|
}
|
|
1983
2348
|
}
|
|
@@ -2120,6 +2485,10 @@ var ClaudeCodeAdapter = class {
|
|
|
2120
2485
|
if (beat.phase === "interrupted") detail = "Interrupted";
|
|
2121
2486
|
else if (beat.phase === "error") detail = st.errorText ?? "Stopped with an error";
|
|
2122
2487
|
}
|
|
2488
|
+
if (st.limitStop && status !== "working" && status !== "waiting" && status !== "stale") {
|
|
2489
|
+
status = "idle";
|
|
2490
|
+
detail = limitStopText(st.limitStop, now);
|
|
2491
|
+
}
|
|
2123
2492
|
if (status === "working") {
|
|
2124
2493
|
const stale = staleness(lastSignal, ctx);
|
|
2125
2494
|
if (stale) {
|
|
@@ -2146,8 +2515,10 @@ var ClaudeCodeAdapter = class {
|
|
|
2146
2515
|
model: st.model,
|
|
2147
2516
|
agentVersion: st.version,
|
|
2148
2517
|
host: st.entrypoint === void 0 ? void 0 : st.entrypoint === "cli" ? "terminal" : /vscode|jetbrains|ide/.test(st.entrypoint) ? "editor" : "app",
|
|
2518
|
+
ranInEditor: st.ranInEditor || void 0,
|
|
2149
2519
|
status,
|
|
2150
2520
|
statusDetail: detail,
|
|
2521
|
+
limitStop: st.limitStop && status === "idle" ? { ...st.limitStop } : void 0,
|
|
2151
2522
|
startedAt: st.startedAt,
|
|
2152
2523
|
updatedAt: Math.max(st.updatedAt, live?.at ?? 0),
|
|
2153
2524
|
tasks,
|
|
@@ -2178,11 +2549,11 @@ var ClaudeCodeAdapter = class {
|
|
|
2178
2549
|
};
|
|
2179
2550
|
|
|
2180
2551
|
// ../core/src/adapters/cline.ts
|
|
2181
|
-
import
|
|
2182
|
-
import { promises as
|
|
2552
|
+
import path6 from "node:path";
|
|
2553
|
+
import { promises as fsp4 } from "node:fs";
|
|
2183
2554
|
|
|
2184
2555
|
// ../core/src/util/editors.ts
|
|
2185
|
-
import
|
|
2556
|
+
import path5 from "node:path";
|
|
2186
2557
|
var EDITOR_APPS = [
|
|
2187
2558
|
"Code",
|
|
2188
2559
|
"Code - Insiders",
|
|
@@ -2211,10 +2582,10 @@ var SERVER_DIRS = [
|
|
|
2211
2582
|
];
|
|
2212
2583
|
function editorUserDataDirs(home, env, platform = process.platform) {
|
|
2213
2584
|
const out = [];
|
|
2214
|
-
if (env.VSCODE_PORTABLE) out.push(
|
|
2215
|
-
const base = platform === "darwin" ?
|
|
2216
|
-
for (const app of EDITOR_APPS) out.push(
|
|
2217
|
-
for (const dir of SERVER_DIRS) out.push(
|
|
2585
|
+
if (env.VSCODE_PORTABLE) out.push(path5.join(env.VSCODE_PORTABLE, "user-data"));
|
|
2586
|
+
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");
|
|
2587
|
+
for (const app of EDITOR_APPS) out.push(path5.join(base, app));
|
|
2588
|
+
for (const dir of SERVER_DIRS) out.push(path5.join(home, dir, "data"));
|
|
2218
2589
|
return out;
|
|
2219
2590
|
}
|
|
2220
2591
|
|
|
@@ -2572,14 +2943,14 @@ var ClineFamilyAdapter = class {
|
|
|
2572
2943
|
const dirs = /* @__PURE__ */ new Set();
|
|
2573
2944
|
const storageRoots = [];
|
|
2574
2945
|
for (const userData of editorUserDataDirs(ctx.home, ctx.env, this.options.platform)) {
|
|
2575
|
-
const user =
|
|
2576
|
-
storageRoots.push(
|
|
2577
|
-
for (const p2 of await listDir(
|
|
2946
|
+
const user = path6.join(userData, "User");
|
|
2947
|
+
storageRoots.push(path6.join(user, "globalStorage"));
|
|
2948
|
+
for (const p2 of await listDir(path6.join(user, "profiles"))) if (p2.isDirectory()) storageRoots.push(path6.join(user, "profiles", p2.name, "globalStorage"));
|
|
2578
2949
|
}
|
|
2579
2950
|
for (const extra of this.options.extraStorageDirs ?? []) storageRoots.push(extra);
|
|
2580
2951
|
for (const root of storageRoots) {
|
|
2581
2952
|
for (const e of await listDir(root)) {
|
|
2582
|
-
if (e.isDirectory() && this.extensions.includes(e.name.toLowerCase())) dirs.add(
|
|
2953
|
+
if (e.isDirectory() && this.extensions.includes(e.name.toLowerCase())) dirs.add(path6.join(root, e.name));
|
|
2583
2954
|
}
|
|
2584
2955
|
}
|
|
2585
2956
|
for (const d of this.standaloneDirs(ctx)) dirs.add(d);
|
|
@@ -2592,9 +2963,9 @@ var ClineFamilyAdapter = class {
|
|
|
2592
2963
|
const now = ctx.now();
|
|
2593
2964
|
const found = [];
|
|
2594
2965
|
for (const store of this.stores.values()) {
|
|
2595
|
-
const tasksDir =
|
|
2966
|
+
const tasksDir = path6.join(store.dir, "tasks");
|
|
2596
2967
|
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" ?
|
|
2968
|
+
const index = this.flavor === "roo" ? path6.join(tasksDir, "_index.json") : path6.join(store.dir, "state", "taskHistory.json");
|
|
2598
2969
|
const indexMtime = (await statSafe(index))?.mtimeMs ?? 0;
|
|
2599
2970
|
const sweep = now - store.lastSweep >= SWEEP_MS || indexMtime !== store.indexMtime;
|
|
2600
2971
|
if (sweep) {
|
|
@@ -2607,7 +2978,7 @@ var ClineFamilyAdapter = class {
|
|
|
2607
2978
|
for (let i = 0; i < toStat.length; i += 64) {
|
|
2608
2979
|
await Promise.all(
|
|
2609
2980
|
toStat.slice(i, i + 64).map(async (id) => {
|
|
2610
|
-
const st = await statSafe(
|
|
2981
|
+
const st = await statSafe(path6.join(tasksDir, id, "ui_messages.json"));
|
|
2611
2982
|
store.seen.set(id, st?.mtimeMs ?? 0);
|
|
2612
2983
|
})
|
|
2613
2984
|
);
|
|
@@ -2615,10 +2986,10 @@ var ClineFamilyAdapter = class {
|
|
|
2615
2986
|
for (const [id, mtimeMs] of store.seen) if (mtimeMs && now - mtimeMs <= ctx.activeWindowMs) found.push({ store, id, mtimeMs });
|
|
2616
2987
|
}
|
|
2617
2988
|
found.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
2618
|
-
const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [
|
|
2989
|
+
const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [path6.join(f.store.dir, "tasks", f.id), f]));
|
|
2619
2990
|
for (const [dir, f] of keep) {
|
|
2620
2991
|
if (this.tracked.has(dir)) continue;
|
|
2621
|
-
this.tracked.set(dir, { id: f.id, dir, file:
|
|
2992
|
+
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
2993
|
}
|
|
2623
2994
|
for (const dir of [...this.tracked.keys()]) if (!keep.has(dir)) this.tracked.delete(dir);
|
|
2624
2995
|
}
|
|
@@ -2643,7 +3014,7 @@ var ClineFamilyAdapter = class {
|
|
|
2643
3014
|
}
|
|
2644
3015
|
}
|
|
2645
3016
|
if (this.flavor === "roo") {
|
|
2646
|
-
const hf =
|
|
3017
|
+
const hf = path6.join(t.dir, "history_item.json");
|
|
2647
3018
|
const hs = await statSafe(hf);
|
|
2648
3019
|
if (hs && hs.mtimeMs !== t.history?.mtimeMs) {
|
|
2649
3020
|
const value = await readJsonSafe(hf, 4 << 20);
|
|
@@ -2651,7 +3022,7 @@ var ClineFamilyAdapter = class {
|
|
|
2651
3022
|
}
|
|
2652
3023
|
const now = ctx.now();
|
|
2653
3024
|
if (!t.modelFile || now - t.modelFile.checkedAt >= MODEL_CHECK_MS) {
|
|
2654
|
-
const mf =
|
|
3025
|
+
const mf = path6.join(t.dir, "api_conversation_history.json");
|
|
2655
3026
|
const ms = await statSafe(mf);
|
|
2656
3027
|
const prev = t.modelFile;
|
|
2657
3028
|
t.modelFile = { mtimeMs: ms?.mtimeMs ?? 0, checkedAt: now, model: prev?.model };
|
|
@@ -2665,7 +3036,7 @@ var ClineFamilyAdapter = class {
|
|
|
2665
3036
|
async readClineHistory(store, id, now) {
|
|
2666
3037
|
if (store.history && store.history.byId.has(id) && now - store.history.readAt < HISTORY_EVERY_MS) return;
|
|
2667
3038
|
if (store.history && now - store.history.readAt < 2e3) return;
|
|
2668
|
-
const file =
|
|
3039
|
+
const file = path6.join(store.dir, "state", "taskHistory.json");
|
|
2669
3040
|
const st = await statSafe(file);
|
|
2670
3041
|
if (!st || st.mtimeMs === store.history?.mtimeMs) return;
|
|
2671
3042
|
const items = await readJsonSafe(file, 64 << 20);
|
|
@@ -2750,7 +3121,7 @@ async function lastModelIn(file, size) {
|
|
|
2750
3121
|
if (len <= 0) return void 0;
|
|
2751
3122
|
let fh;
|
|
2752
3123
|
try {
|
|
2753
|
-
fh = await
|
|
3124
|
+
fh = await fsp4.open(file, "r");
|
|
2754
3125
|
const buf = Buffer.alloc(len);
|
|
2755
3126
|
await fh.read(buf, 0, len, size - len);
|
|
2756
3127
|
const text = buf.toString("utf8");
|
|
@@ -2765,8 +3136,8 @@ async function lastModelIn(file, size) {
|
|
|
2765
3136
|
}
|
|
2766
3137
|
function clineDataDir(home, env) {
|
|
2767
3138
|
if (env.CLINE_DATA_DIR) return env.CLINE_DATA_DIR;
|
|
2768
|
-
if (env.CLINE_DIR) return
|
|
2769
|
-
return
|
|
3139
|
+
if (env.CLINE_DIR) return path6.join(env.CLINE_DIR, "data");
|
|
3140
|
+
return path6.join(home, ".cline", "data");
|
|
2770
3141
|
}
|
|
2771
3142
|
var ClineAdapter = class extends ClineFamilyAdapter {
|
|
2772
3143
|
id = "cline";
|
|
@@ -2790,7 +3161,7 @@ var RooCodeAdapter = class extends ClineFamilyAdapter {
|
|
|
2790
3161
|
async customStorageDirs(ctx) {
|
|
2791
3162
|
const out = [];
|
|
2792
3163
|
for (const userData of editorUserDataDirs(ctx.home, ctx.env, this.options.platform)) {
|
|
2793
|
-
const text = await readTextSafe(
|
|
3164
|
+
const text = await readTextSafe(path6.join(userData, "User", "settings.json"), 2 << 20);
|
|
2794
3165
|
const m = text && /"roo-cline\.customStoragePath"\s*:\s*"((?:[^"\\]|\\.)+)"/.exec(text);
|
|
2795
3166
|
if (m) {
|
|
2796
3167
|
try {
|
|
@@ -2947,7 +3318,7 @@ var ClineSdkSessions = class {
|
|
|
2947
3318
|
tracked = /* @__PURE__ */ new Map();
|
|
2948
3319
|
lastDiscovery = 0;
|
|
2949
3320
|
root(ctx) {
|
|
2950
|
-
return ctx.env.CLINE_SESSION_DATA_DIR ||
|
|
3321
|
+
return ctx.env.CLINE_SESSION_DATA_DIR || path6.join(clineDataDir(ctx.home, ctx.env), "sessions");
|
|
2951
3322
|
}
|
|
2952
3323
|
async poll(ctx, label) {
|
|
2953
3324
|
const now = ctx.now();
|
|
@@ -2971,9 +3342,9 @@ var ClineSdkSessions = class {
|
|
|
2971
3342
|
const found = [];
|
|
2972
3343
|
for (const e of await listDir(root)) {
|
|
2973
3344
|
if (!e.isDirectory() || e.name.includes("__") || e.name.startsWith(".")) continue;
|
|
2974
|
-
const dir =
|
|
2975
|
-
const manifest = await statSafe(
|
|
2976
|
-
const messages = await statSafe(
|
|
3345
|
+
const dir = path6.join(root, e.name);
|
|
3346
|
+
const manifest = await statSafe(path6.join(dir, `${e.name}.json`));
|
|
3347
|
+
const messages = await statSafe(path6.join(dir, `${e.name}.messages.json`));
|
|
2977
3348
|
const mtimeMs = Math.max(manifest?.mtimeMs ?? 0, messages?.mtimeMs ?? 0);
|
|
2978
3349
|
if (mtimeMs && now - mtimeMs <= ctx.activeWindowMs) found.push({ dir, id: e.name, mtimeMs });
|
|
2979
3350
|
}
|
|
@@ -2981,7 +3352,7 @@ var ClineSdkSessions = class {
|
|
|
2981
3352
|
const keep = new Map(found.slice(0, ctx.maxSessionsPerAgent).map((f) => [f.dir, f]));
|
|
2982
3353
|
for (const [dir, f] of keep) {
|
|
2983
3354
|
if (!this.tracked.has(dir)) {
|
|
2984
|
-
this.tracked.set(dir, { dir, id: f.id, manifestFile:
|
|
3355
|
+
this.tracked.set(dir, { dir, id: f.id, manifestFile: path6.join(dir, `${f.id}.json`), manifestMtime: -1, messagesMtime: -1, messagesSize: -1 });
|
|
2985
3356
|
}
|
|
2986
3357
|
}
|
|
2987
3358
|
for (const dir of [...this.tracked.keys()]) if (!keep.has(dir)) this.tracked.delete(dir);
|
|
@@ -2996,7 +3367,7 @@ var ClineSdkSessions = class {
|
|
|
2996
3367
|
}
|
|
2997
3368
|
}
|
|
2998
3369
|
const declared = typeof t.manifest?.messages_path === "string" ? t.manifest.messages_path : void 0;
|
|
2999
|
-
let file =
|
|
3370
|
+
let file = path6.join(t.dir, `${t.id}.messages.json`);
|
|
3000
3371
|
let st = await statSafe(file);
|
|
3001
3372
|
if (!st && declared) {
|
|
3002
3373
|
st = await statSafe(declared);
|
|
@@ -3103,7 +3474,7 @@ var ClineSdkSessions = class {
|
|
|
3103
3474
|
};
|
|
3104
3475
|
|
|
3105
3476
|
// ../core/src/adapters/codex.ts
|
|
3106
|
-
import
|
|
3477
|
+
import path7 from "node:path";
|
|
3107
3478
|
function codexFailure(output) {
|
|
3108
3479
|
let text = typeof output === "string" ? output : output && typeof output === "object" ? JSON.stringify(output) : "";
|
|
3109
3480
|
if (!text) return void 0;
|
|
@@ -3157,9 +3528,14 @@ function describeCodexCall(name, args, at) {
|
|
|
3157
3528
|
}
|
|
3158
3529
|
return { kind: "tool", label: name, startedAt: at };
|
|
3159
3530
|
}
|
|
3531
|
+
var RESUMED_DAYS = 90;
|
|
3532
|
+
var RESUMED_SCAN_MS = 6e4;
|
|
3160
3533
|
var CodexAdapter = class extends JsonlSessionAdapter {
|
|
3161
3534
|
/** The account's plan windows, from every session's readings. */
|
|
3162
3535
|
limitBook = new LimitBook();
|
|
3536
|
+
/** Rollouts in older day folders that were written lately: sessions resumed since they began. */
|
|
3537
|
+
resumed = [];
|
|
3538
|
+
resumedAt = -Infinity;
|
|
3163
3539
|
limits(ctx) {
|
|
3164
3540
|
const windows = this.limitBook.windows(ctx.now());
|
|
3165
3541
|
return windows.length ? { agent: this.id, agentLabel: this.label, windows } : void 0;
|
|
@@ -3167,34 +3543,64 @@ var CodexAdapter = class extends JsonlSessionAdapter {
|
|
|
3167
3543
|
id = "codex";
|
|
3168
3544
|
label = "Codex";
|
|
3169
3545
|
async discover(ctx) {
|
|
3170
|
-
const home = ctx.env.CODEX_HOME ||
|
|
3171
|
-
const root =
|
|
3546
|
+
const home = ctx.env.CODEX_HOME || path7.join(ctx.home, ".codex");
|
|
3547
|
+
const root = path7.join(home, "sessions");
|
|
3172
3548
|
const now = ctx.now();
|
|
3173
3549
|
const days = Math.max(1, Math.ceil(ctx.activeWindowMs / 864e5) + 1);
|
|
3174
3550
|
const dirs = /* @__PURE__ */ new Set();
|
|
3175
3551
|
for (let i = 0; i <= days; i += 1) {
|
|
3176
3552
|
const d = new Date(now - i * 864e5);
|
|
3177
3553
|
const pad = (n) => String(n).padStart(2, "0");
|
|
3178
|
-
dirs.add(
|
|
3179
|
-
dirs.add(
|
|
3554
|
+
dirs.add(path7.join(root, String(d.getFullYear()), pad(d.getMonth() + 1), pad(d.getDate())));
|
|
3555
|
+
dirs.add(path7.join(root, String(d.getUTCFullYear()), pad(d.getUTCMonth() + 1), pad(d.getUTCDate())));
|
|
3180
3556
|
}
|
|
3181
3557
|
const out = [];
|
|
3558
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3182
3559
|
for (const dir of dirs) {
|
|
3183
3560
|
for (const f of await listDir(dir)) {
|
|
3184
3561
|
if (!f.isFile() || !f.name.startsWith("rollout-") || !f.name.endsWith(".jsonl")) continue;
|
|
3185
|
-
const file =
|
|
3562
|
+
const file = path7.join(dir, f.name);
|
|
3186
3563
|
const st = await statSafe(file);
|
|
3187
|
-
if (st)
|
|
3564
|
+
if (st) {
|
|
3565
|
+
out.push({ path: file, mtimeMs: st.mtimeMs });
|
|
3566
|
+
seen.add(file);
|
|
3567
|
+
}
|
|
3188
3568
|
}
|
|
3189
3569
|
}
|
|
3570
|
+
if (now - this.resumedAt >= RESUMED_SCAN_MS) {
|
|
3571
|
+
this.resumedAt = now;
|
|
3572
|
+
const found = [];
|
|
3573
|
+
for (let i = days + 1; i <= RESUMED_DAYS; i += 1) {
|
|
3574
|
+
const d = new Date(now - i * 864e5);
|
|
3575
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
3576
|
+
for (const dir of /* @__PURE__ */ new Set([
|
|
3577
|
+
path7.join(root, String(d.getFullYear()), pad(d.getMonth() + 1), pad(d.getDate())),
|
|
3578
|
+
path7.join(root, String(d.getUTCFullYear()), pad(d.getUTCMonth() + 1), pad(d.getUTCDate()))
|
|
3579
|
+
])) {
|
|
3580
|
+
if (dirs.has(dir)) continue;
|
|
3581
|
+
for (const f of await listDir(dir)) {
|
|
3582
|
+
if (!f.isFile() || !f.name.startsWith("rollout-") || !f.name.endsWith(".jsonl")) continue;
|
|
3583
|
+
const file = path7.join(dir, f.name);
|
|
3584
|
+
const st = await statSafe(file);
|
|
3585
|
+
if (st && now - st.mtimeMs < ctx.activeWindowMs) found.push(file);
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
this.resumed = found;
|
|
3590
|
+
}
|
|
3591
|
+
for (const file of this.resumed) {
|
|
3592
|
+
if (seen.has(file)) continue;
|
|
3593
|
+
const st = await statSafe(file);
|
|
3594
|
+
if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
|
|
3595
|
+
}
|
|
3190
3596
|
return out;
|
|
3191
3597
|
}
|
|
3192
3598
|
createState(file) {
|
|
3193
|
-
const m = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})
|
|
3599
|
+
const m = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})?\.jsonl$/i.exec(file);
|
|
3194
3600
|
const daily = {};
|
|
3195
3601
|
return {
|
|
3196
3602
|
file,
|
|
3197
|
-
id: m ? m[1] :
|
|
3603
|
+
id: m ? m[1] : path7.basename(file, ".jsonl"),
|
|
3198
3604
|
isSubagent: false,
|
|
3199
3605
|
updatedAt: 0,
|
|
3200
3606
|
prevTotal: 0,
|
|
@@ -3495,7 +3901,7 @@ function loopOf(st, status, now) {
|
|
|
3495
3901
|
}
|
|
3496
3902
|
|
|
3497
3903
|
// ../core/src/adapters/copilot.ts
|
|
3498
|
-
import
|
|
3904
|
+
import path8 from "node:path";
|
|
3499
3905
|
|
|
3500
3906
|
// ../core/src/util/sqlite.ts
|
|
3501
3907
|
var loaded;
|
|
@@ -3663,12 +4069,12 @@ function dbStatus(s) {
|
|
|
3663
4069
|
return s === "done" ? "completed" : s === "in_progress" ? "in_progress" : s === "blocked" ? "blocked" : "pending";
|
|
3664
4070
|
}
|
|
3665
4071
|
function createState(file) {
|
|
3666
|
-
const dir =
|
|
4072
|
+
const dir = path8.dirname(file);
|
|
3667
4073
|
const daily = {};
|
|
3668
4074
|
return {
|
|
3669
4075
|
file,
|
|
3670
4076
|
dir,
|
|
3671
|
-
id:
|
|
4077
|
+
id: path8.basename(dir),
|
|
3672
4078
|
updatedAt: 0,
|
|
3673
4079
|
workspaceMtime: -1,
|
|
3674
4080
|
turnOpen: false,
|
|
@@ -3912,14 +4318,14 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
|
|
|
3912
4318
|
id = "copilot";
|
|
3913
4319
|
label = "Copilot";
|
|
3914
4320
|
root(ctx) {
|
|
3915
|
-
return ctx.env.COPILOT_HOME ||
|
|
4321
|
+
return ctx.env.COPILOT_HOME || path8.join(ctx.home, ".copilot");
|
|
3916
4322
|
}
|
|
3917
4323
|
async discover(ctx) {
|
|
3918
|
-
const dir =
|
|
4324
|
+
const dir = path8.join(this.root(ctx), "session-state");
|
|
3919
4325
|
const out = [];
|
|
3920
4326
|
for (const e of await listDir(dir)) {
|
|
3921
4327
|
if (!e.isDirectory()) continue;
|
|
3922
|
-
const file =
|
|
4328
|
+
const file = path8.join(dir, e.name, "events.jsonl");
|
|
3923
4329
|
const st = await statSafe(file);
|
|
3924
4330
|
if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
|
|
3925
4331
|
}
|
|
@@ -3937,7 +4343,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
|
|
|
3937
4343
|
}
|
|
3938
4344
|
async afterRead(st, ctx) {
|
|
3939
4345
|
const now = ctx.now();
|
|
3940
|
-
const ws =
|
|
4346
|
+
const ws = path8.join(st.dir, "workspace.yaml");
|
|
3941
4347
|
const wst = await statSafe(ws);
|
|
3942
4348
|
if (wst && wst.mtimeMs !== st.workspaceMtime) {
|
|
3943
4349
|
st.workspaceMtime = wst.mtimeMs;
|
|
@@ -3954,7 +4360,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
|
|
|
3954
4360
|
st.alive = locks.length ? live.length > 0 : void 0;
|
|
3955
4361
|
st.pid = live[0];
|
|
3956
4362
|
}
|
|
3957
|
-
const dbFile =
|
|
4363
|
+
const dbFile = path8.join(st.dir, "session.db");
|
|
3958
4364
|
const dbm = Math.max((await statSafe(dbFile))?.mtimeMs ?? 0, (await statSafe(`${dbFile}-wal`))?.mtimeMs ?? 0);
|
|
3959
4365
|
if (dbm && dbm !== st.dbMtime) {
|
|
3960
4366
|
st.dbMtime = dbm;
|
|
@@ -4056,7 +4462,7 @@ var CopilotAdapter = class extends JsonlSessionAdapter {
|
|
|
4056
4462
|
};
|
|
4057
4463
|
|
|
4058
4464
|
// ../core/src/adapters/gemini-cli.ts
|
|
4059
|
-
import
|
|
4465
|
+
import path9 from "node:path";
|
|
4060
4466
|
var PENDING_TOOL = /* @__PURE__ */ new Set(["scheduled", "validating", "executing"]);
|
|
4061
4467
|
function todoStatus2(s) {
|
|
4062
4468
|
switch (s) {
|
|
@@ -4130,8 +4536,8 @@ var GeminiCliAdapter = class {
|
|
|
4130
4536
|
const homes = [ctx.env.GEMINI_CLI_HOME, ctx.home].filter((h) => !!h);
|
|
4131
4537
|
const out = /* @__PURE__ */ new Set();
|
|
4132
4538
|
for (const h of homes) {
|
|
4133
|
-
out.add(
|
|
4134
|
-
out.add(
|
|
4539
|
+
out.add(path9.join(h, ".gemini", "tmp"));
|
|
4540
|
+
out.add(path9.join(h, ".cache", ".gemini", "tmp"));
|
|
4135
4541
|
}
|
|
4136
4542
|
return [...out];
|
|
4137
4543
|
}
|
|
@@ -4179,18 +4585,18 @@ var GeminiCliAdapter = class {
|
|
|
4179
4585
|
for (const root of this.roots(ctx)) {
|
|
4180
4586
|
for (const proj of await listDir(root)) {
|
|
4181
4587
|
if (!proj.isDirectory()) continue;
|
|
4182
|
-
const projDir =
|
|
4183
|
-
const chats =
|
|
4588
|
+
const projDir = path9.join(root, proj.name);
|
|
4589
|
+
const chats = path9.join(projDir, "chats");
|
|
4184
4590
|
const files = (await listDir(chats)).filter(
|
|
4185
4591
|
(f) => f.isFile() && f.name.startsWith("session-") && (f.name.endsWith(".jsonl") || f.name.endsWith(".json"))
|
|
4186
4592
|
);
|
|
4187
4593
|
if (files.length === 0) continue;
|
|
4188
4594
|
let project;
|
|
4189
4595
|
for (const f of files) {
|
|
4190
|
-
const file =
|
|
4596
|
+
const file = path9.join(chats, f.name);
|
|
4191
4597
|
const st = await statSafe(file);
|
|
4192
4598
|
if (!st || now - st.mtimeMs > ctx.activeWindowMs) continue;
|
|
4193
|
-
if (project === void 0) project = (await readTextSafe(
|
|
4599
|
+
if (project === void 0) project = (await readTextSafe(path9.join(projDir, ".project_root"), 8192))?.trim() || "";
|
|
4194
4600
|
found.push({ file, mtimeMs: st.mtimeMs, project: project || void 0 });
|
|
4195
4601
|
}
|
|
4196
4602
|
}
|
|
@@ -4320,7 +4726,7 @@ var GeminiCliAdapter = class {
|
|
|
4320
4726
|
key: `gemini-cli:${st.sessionId ?? st.file}`,
|
|
4321
4727
|
agent: "gemini-cli",
|
|
4322
4728
|
agentLabel: this.label,
|
|
4323
|
-
id: st.sessionId ??
|
|
4729
|
+
id: st.sessionId ?? path9.basename(st.file),
|
|
4324
4730
|
title: st.summary ? truncate(st.summary, 100) : title ?? "Untitled session",
|
|
4325
4731
|
titleFromPrompt: !st.summary && title !== void 0 ? true : void 0,
|
|
4326
4732
|
projectPath: st.projectPath,
|
|
@@ -4351,7 +4757,7 @@ var GeminiCliAdapter = class {
|
|
|
4351
4757
|
};
|
|
4352
4758
|
|
|
4353
4759
|
// ../core/src/adapters/opencode.ts
|
|
4354
|
-
import
|
|
4760
|
+
import path10 from "node:path";
|
|
4355
4761
|
var num = (v) => typeof v === "number" && Number.isFinite(v) ? v : Number(v) || 0;
|
|
4356
4762
|
function parseData(v) {
|
|
4357
4763
|
if (v && typeof v === "object") return v;
|
|
@@ -4663,13 +5069,13 @@ var OpenCodeFamilyAdapter = class {
|
|
|
4663
5069
|
this.options = options;
|
|
4664
5070
|
}
|
|
4665
5071
|
dataDir(ctx) {
|
|
4666
|
-
return
|
|
5072
|
+
return path10.join(ctx.env.XDG_DATA_HOME || path10.join(ctx.home, ".local", "share"), this.app);
|
|
4667
5073
|
}
|
|
4668
5074
|
databaseFile(ctx) {
|
|
4669
5075
|
if (this.options.dbFile) return this.options.dbFile;
|
|
4670
5076
|
const override = ctx.env[this.dbEnv];
|
|
4671
|
-
if (override && override !== ":memory:") return
|
|
4672
|
-
return
|
|
5077
|
+
if (override && override !== ":memory:") return path10.isAbsolute(override) ? override : path10.join(this.dataDir(ctx), override);
|
|
5078
|
+
return path10.join(this.dataDir(ctx), `${this.app}.db`);
|
|
4673
5079
|
}
|
|
4674
5080
|
async poll(ctx) {
|
|
4675
5081
|
const now = ctx.now();
|
|
@@ -4898,7 +5304,7 @@ var OpenCodeFamilyAdapter = class {
|
|
|
4898
5304
|
const untitled = !rowTitle || /^(New session|Child session)( - \d{4}-\d\d-\d\dT[\d:.]+Z?)?$/.test(rowTitle);
|
|
4899
5305
|
const title = untitled ? f.title : truncate(rowTitle, 100);
|
|
4900
5306
|
const model = parseData(row.model);
|
|
4901
|
-
const dir = typeof row.directory === "string" && row.directory ? row.directory.replace(/\//g,
|
|
5307
|
+
const dir = typeof row.directory === "string" && row.directory ? row.directory.replace(/\//g, path10.sep === "\\" ? "\\" : "/") : void 0;
|
|
4902
5308
|
const rowTokens = "tokens_input" in row ? {
|
|
4903
5309
|
input: num(row.tokens_input),
|
|
4904
5310
|
output: num(row.tokens_output) + num(row.tokens_reasoning),
|
|
@@ -4973,7 +5379,7 @@ var LiveProbe = class {
|
|
|
4973
5379
|
});
|
|
4974
5380
|
}
|
|
4975
5381
|
async readService(ctx) {
|
|
4976
|
-
const file =
|
|
5382
|
+
const file = path10.join(ctx.env.XDG_STATE_HOME || path10.join(ctx.home, ".local", "state"), "opencode", "service.json");
|
|
4977
5383
|
const info = await readJsonSafe(file, 64 << 10);
|
|
4978
5384
|
const now = ctx.now();
|
|
4979
5385
|
if (!info || typeof info.url !== "string") {
|
|
@@ -5041,8 +5447,8 @@ var KiloCodeAdapter = class extends OpenCodeFamilyAdapter {
|
|
|
5041
5447
|
};
|
|
5042
5448
|
|
|
5043
5449
|
// ../core/src/adapters/progress-file.ts
|
|
5044
|
-
import { promises as
|
|
5045
|
-
import
|
|
5450
|
+
import { promises as fsp5 } from "node:fs";
|
|
5451
|
+
import path11 from "node:path";
|
|
5046
5452
|
var STATUS_WORDS = lookupTable({
|
|
5047
5453
|
working: "working",
|
|
5048
5454
|
running: "working",
|
|
@@ -5061,7 +5467,7 @@ var MAX_PROGRESS_FILES = 20;
|
|
|
5061
5467
|
var MAX_LISTED = 500;
|
|
5062
5468
|
async function realpathSafe(p2) {
|
|
5063
5469
|
try {
|
|
5064
|
-
return await
|
|
5470
|
+
return await fsp5.realpath(p2);
|
|
5065
5471
|
} catch {
|
|
5066
5472
|
return void 0;
|
|
5067
5473
|
}
|
|
@@ -5074,10 +5480,10 @@ var ProgressFileAdapter = class {
|
|
|
5074
5480
|
async poll(ctx) {
|
|
5075
5481
|
const files = [];
|
|
5076
5482
|
for (const root of ctx.workspaceRoots) {
|
|
5077
|
-
const agentsDir =
|
|
5078
|
-
const names = [
|
|
5079
|
-
for (const f of (await listDir(
|
|
5080
|
-
if (f.isFile() && f.name.endsWith(".md")) names.push(
|
|
5483
|
+
const agentsDir = path11.join(root, ".agents");
|
|
5484
|
+
const names = [path11.join(agentsDir, "progress.md")];
|
|
5485
|
+
for (const f of (await listDir(path11.join(agentsDir, "progress"))).slice(0, MAX_LISTED)) {
|
|
5486
|
+
if (f.isFile() && f.name.endsWith(".md")) names.push(path11.join(agentsDir, "progress", f.name));
|
|
5081
5487
|
}
|
|
5082
5488
|
const realRoot = await realpathSafe(root);
|
|
5083
5489
|
if (!realRoot) continue;
|
|
@@ -5152,7 +5558,7 @@ var ProgressFileAdapter = class {
|
|
|
5152
5558
|
|
|
5153
5559
|
// ../core/src/engine.ts
|
|
5154
5560
|
function defaultLiveDir(home = os.homedir()) {
|
|
5155
|
-
return
|
|
5561
|
+
return path12.join(home, ".kvali", "live");
|
|
5156
5562
|
}
|
|
5157
5563
|
function createDefaultAdapters(opts = {}) {
|
|
5158
5564
|
return [
|
|
@@ -5352,31 +5758,31 @@ var Engine = class {
|
|
|
5352
5758
|
};
|
|
5353
5759
|
|
|
5354
5760
|
// ../core/src/hooks/hub.ts
|
|
5355
|
-
import { promises as
|
|
5761
|
+
import { promises as fsp7 } from "node:fs";
|
|
5356
5762
|
import http from "node:http";
|
|
5357
|
-
import
|
|
5763
|
+
import path13 from "node:path";
|
|
5358
5764
|
|
|
5359
5765
|
// ../core/src/util/files.ts
|
|
5360
5766
|
import { randomBytes } from "node:crypto";
|
|
5361
|
-
import { promises as
|
|
5767
|
+
import { promises as fsp6 } from "node:fs";
|
|
5362
5768
|
async function writeFileSafely(file, text, mode) {
|
|
5363
5769
|
let current;
|
|
5364
5770
|
try {
|
|
5365
|
-
const st = await
|
|
5771
|
+
const st = await fsp6.lstat(file);
|
|
5366
5772
|
current = { link: st.isSymbolicLink(), mode: st.mode & 511 };
|
|
5367
5773
|
} catch {
|
|
5368
5774
|
}
|
|
5369
5775
|
if (current?.link) {
|
|
5370
|
-
await
|
|
5776
|
+
await fsp6.writeFile(file, text);
|
|
5371
5777
|
return;
|
|
5372
5778
|
}
|
|
5373
5779
|
const tmp = `${file}.kvali-${process.pid}-${randomBytes(4).toString("hex")}.tmp`;
|
|
5374
5780
|
try {
|
|
5375
|
-
await
|
|
5376
|
-
if (current) await
|
|
5377
|
-
await
|
|
5781
|
+
await fsp6.writeFile(tmp, text, { mode: mode ?? current?.mode ?? 420, flag: "wx" });
|
|
5782
|
+
if (current) await fsp6.chmod(tmp, mode ?? current.mode);
|
|
5783
|
+
await fsp6.rename(tmp, file);
|
|
5378
5784
|
} catch (err) {
|
|
5379
|
-
await
|
|
5785
|
+
await fsp6.rm(tmp, { force: true }).catch(() => void 0);
|
|
5380
5786
|
throw err;
|
|
5381
5787
|
}
|
|
5382
5788
|
}
|
|
@@ -5528,40 +5934,40 @@ var HookHub = class {
|
|
|
5528
5934
|
}
|
|
5529
5935
|
}
|
|
5530
5936
|
async store(agent, ev) {
|
|
5531
|
-
const dir =
|
|
5532
|
-
await
|
|
5533
|
-
await writeFileSafely(
|
|
5937
|
+
const dir = path13.join(this.opts.liveDir, agent);
|
|
5938
|
+
await fsp7.mkdir(dir, { recursive: true, mode: 448 });
|
|
5939
|
+
await writeFileSafely(path13.join(dir, `${ev.sessionId}.json`), JSON.stringify(ev), 384);
|
|
5534
5940
|
}
|
|
5535
5941
|
};
|
|
5536
5942
|
|
|
5537
5943
|
// ../core/src/hooks/claude-install.ts
|
|
5538
|
-
import { promises as
|
|
5944
|
+
import { promises as fsp9 } from "node:fs";
|
|
5539
5945
|
import os2 from "node:os";
|
|
5540
|
-
import
|
|
5946
|
+
import path15 from "node:path";
|
|
5541
5947
|
|
|
5542
5948
|
// ../core/src/hooks/claude-plugin.ts
|
|
5543
|
-
import { execFile } from "node:child_process";
|
|
5949
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
5544
5950
|
import { createHash } from "node:crypto";
|
|
5545
|
-
import { constants as fsc, promises as
|
|
5546
|
-
import
|
|
5951
|
+
import { constants as fsc, promises as fsp8 } from "node:fs";
|
|
5952
|
+
import path14 from "node:path";
|
|
5547
5953
|
var CLAUDE_PLUGIN_ID = "kvali@kvali";
|
|
5548
5954
|
var CLAUDE_MARKETPLACE = "kvali";
|
|
5549
|
-
var kvaliPluginDir = (home) =>
|
|
5550
|
-
var stateFile = (home) =>
|
|
5955
|
+
var kvaliPluginDir = (home) => path14.join(home, ".kvali", "claude-plugin");
|
|
5956
|
+
var stateFile = (home) => path14.join(home, ".kvali", "state.json");
|
|
5551
5957
|
async function filesUnder(dir, base = dir) {
|
|
5552
5958
|
const out = [];
|
|
5553
5959
|
let entries;
|
|
5554
5960
|
try {
|
|
5555
|
-
entries = await
|
|
5961
|
+
entries = await fsp8.readdir(dir, { withFileTypes: true });
|
|
5556
5962
|
} catch {
|
|
5557
5963
|
return out;
|
|
5558
5964
|
}
|
|
5559
5965
|
for (const e of entries) {
|
|
5560
|
-
const full =
|
|
5966
|
+
const full = path14.join(dir, e.name);
|
|
5561
5967
|
if (e.isDirectory()) {
|
|
5562
|
-
if (
|
|
5968
|
+
if (path14.relative(base, full) === path14.join(".claude-plugin", "types")) continue;
|
|
5563
5969
|
out.push(...await filesUnder(full, base));
|
|
5564
|
-
} else if (e.isFile()) out.push(
|
|
5970
|
+
} else if (e.isFile()) out.push(path14.relative(base, full));
|
|
5565
5971
|
}
|
|
5566
5972
|
return out.sort();
|
|
5567
5973
|
}
|
|
@@ -5570,16 +5976,16 @@ async function pluginFingerprint(dir) {
|
|
|
5570
5976
|
if (!files.length) return void 0;
|
|
5571
5977
|
const h = createHash("sha256");
|
|
5572
5978
|
for (const f of files) {
|
|
5573
|
-
h.update(f.split(
|
|
5979
|
+
h.update(f.split(path14.sep).join("/"));
|
|
5574
5980
|
h.update("\0");
|
|
5575
|
-
h.update(await
|
|
5981
|
+
h.update(await fsp8.readFile(path14.join(dir, f)));
|
|
5576
5982
|
h.update("\0");
|
|
5577
5983
|
}
|
|
5578
5984
|
return h.digest("hex");
|
|
5579
5985
|
}
|
|
5580
5986
|
async function pluginVersion(dir) {
|
|
5581
5987
|
try {
|
|
5582
|
-
const v = JSON.parse(await
|
|
5988
|
+
const v = JSON.parse(await fsp8.readFile(path14.join(dir, ".claude-plugin", "plugin.json"), "utf8")).version;
|
|
5583
5989
|
return typeof v === "string" ? v : void 0;
|
|
5584
5990
|
} catch {
|
|
5585
5991
|
return void 0;
|
|
@@ -5599,28 +6005,28 @@ async function syncClaudePlugin(bundledDir, home) {
|
|
|
5599
6005
|
const [mine, theirs] = await Promise.all([pluginVersion(bundledDir), pluginVersion(target)]);
|
|
5600
6006
|
if (mine && theirs && compareVersions(mine, theirs) < 0) return false;
|
|
5601
6007
|
const next = `${target}.next`;
|
|
5602
|
-
await
|
|
5603
|
-
await
|
|
5604
|
-
await
|
|
5605
|
-
await
|
|
5606
|
-
await
|
|
6008
|
+
await fsp8.rm(next, { recursive: true, force: true });
|
|
6009
|
+
await fsp8.mkdir(path14.dirname(target), { recursive: true });
|
|
6010
|
+
await fsp8.cp(bundledDir, next, { recursive: true });
|
|
6011
|
+
await fsp8.rm(target, { recursive: true, force: true });
|
|
6012
|
+
await fsp8.rename(next, target);
|
|
5607
6013
|
return true;
|
|
5608
6014
|
}
|
|
5609
6015
|
async function claudeExtensionDirs(home) {
|
|
5610
6016
|
const roots = [".vscode", ".vscode-insiders", ".vscode-oss", ".cursor", ".windsurf", ".antigravity", ".antigravity-ide", ".kiro"].map(
|
|
5611
|
-
(d) =>
|
|
6017
|
+
(d) => path14.join(home, d, "extensions")
|
|
5612
6018
|
);
|
|
5613
6019
|
const found = [];
|
|
5614
6020
|
for (const root of roots) {
|
|
5615
6021
|
let names = [];
|
|
5616
6022
|
try {
|
|
5617
|
-
names = await
|
|
6023
|
+
names = await fsp8.readdir(root);
|
|
5618
6024
|
} catch {
|
|
5619
6025
|
continue;
|
|
5620
6026
|
}
|
|
5621
|
-
for (const n of names) if (n.toLowerCase().startsWith("anthropic.claude-code-")) found.push(
|
|
6027
|
+
for (const n of names) if (n.toLowerCase().startsWith("anthropic.claude-code-")) found.push(path14.join(root, n));
|
|
5622
6028
|
}
|
|
5623
|
-
const ver = (p2) => (/-(\d+)\.(\d+)\.(\d+)/.exec(
|
|
6029
|
+
const ver = (p2) => (/-(\d+)\.(\d+)\.(\d+)/.exec(path14.basename(p2)) ?? []).slice(1).map(Number);
|
|
5624
6030
|
return found.sort((a, b) => {
|
|
5625
6031
|
const [x, y] = [ver(a), ver(b)];
|
|
5626
6032
|
for (let i = 0; i < 3; i += 1) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (y[i] ?? 0) - (x[i] ?? 0);
|
|
@@ -5632,23 +6038,23 @@ async function findClaudeBinary(opts) {
|
|
|
5632
6038
|
const names = win ? ["claude.exe", "claude.cmd"] : ["claude"];
|
|
5633
6039
|
const candidates = [];
|
|
5634
6040
|
for (const d of opts.extensionDirs ?? []) {
|
|
5635
|
-
const bin =
|
|
6041
|
+
const bin = path14.join(d, "resources", "native-binary");
|
|
5636
6042
|
let inside = [];
|
|
5637
6043
|
try {
|
|
5638
|
-
inside = await
|
|
6044
|
+
inside = await fsp8.readdir(bin);
|
|
5639
6045
|
} catch {
|
|
5640
6046
|
continue;
|
|
5641
6047
|
}
|
|
5642
6048
|
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(
|
|
6049
|
+
for (const n of ranked) candidates.push(path14.join(bin, n));
|
|
5644
6050
|
}
|
|
5645
|
-
for (const dir of (opts.env?.PATH ?? opts.env?.Path ?? "").split(
|
|
5646
|
-
candidates.push(
|
|
6051
|
+
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));
|
|
6052
|
+
candidates.push(path14.join(opts.home, ".claude", "local", names[0]), path14.join(opts.home, ".local", "bin", names[0]));
|
|
5647
6053
|
if (!win) candidates.push("/opt/homebrew/bin/claude", "/usr/local/bin/claude");
|
|
5648
6054
|
for (const c of candidates) {
|
|
5649
6055
|
try {
|
|
5650
|
-
await
|
|
5651
|
-
if ((await
|
|
6056
|
+
await fsp8.access(c, win ? fsc.F_OK : fsc.X_OK);
|
|
6057
|
+
if ((await fsp8.stat(c)).isFile()) return c;
|
|
5652
6058
|
} catch {
|
|
5653
6059
|
}
|
|
5654
6060
|
}
|
|
@@ -5658,7 +6064,7 @@ function runClaude(bin, args, env, timeoutMs = 6e4) {
|
|
|
5658
6064
|
const cmdShim = process.platform === "win32" && /\.cmd$/i.test(bin);
|
|
5659
6065
|
const argv = cmdShim ? args.map((a) => /[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a) : [...args];
|
|
5660
6066
|
return new Promise((resolve) => {
|
|
5661
|
-
|
|
6067
|
+
execFile2(
|
|
5662
6068
|
cmdShim ? `"${bin}"` : bin,
|
|
5663
6069
|
argv,
|
|
5664
6070
|
{ env, timeout: timeoutMs, windowsHide: true, maxBuffer: 8 * 1024 * 1024, shell: cmdShim },
|
|
@@ -5701,7 +6107,7 @@ async function installClaudePlugin(bin, dir, env) {
|
|
|
5701
6107
|
}
|
|
5702
6108
|
async function claudePluginEnabled(settingsFile) {
|
|
5703
6109
|
try {
|
|
5704
|
-
const s = JSON.parse(await
|
|
6110
|
+
const s = JSON.parse(await fsp8.readFile(settingsFile, "utf8"));
|
|
5705
6111
|
return s?.enabledPlugins?.[CLAUDE_PLUGIN_ID] === true;
|
|
5706
6112
|
} catch {
|
|
5707
6113
|
return false;
|
|
@@ -5709,14 +6115,14 @@ async function claudePluginEnabled(settingsFile) {
|
|
|
5709
6115
|
}
|
|
5710
6116
|
async function readKvaliState(home) {
|
|
5711
6117
|
try {
|
|
5712
|
-
return JSON.parse(await
|
|
6118
|
+
return JSON.parse(await fsp8.readFile(stateFile(home), "utf8")) ?? {};
|
|
5713
6119
|
} catch {
|
|
5714
6120
|
return {};
|
|
5715
6121
|
}
|
|
5716
6122
|
}
|
|
5717
6123
|
async function writeKvaliState(home, patch) {
|
|
5718
6124
|
const next = { ...await readKvaliState(home), ...patch };
|
|
5719
|
-
await
|
|
6125
|
+
await fsp8.mkdir(path14.dirname(stateFile(home)), { recursive: true, mode: 448 });
|
|
5720
6126
|
await writeFileSafely(stateFile(home), `${JSON.stringify(next, null, 2)}
|
|
5721
6127
|
`);
|
|
5722
6128
|
}
|
|
@@ -5729,12 +6135,12 @@ async function removeClaudePlugin(opts) {
|
|
|
5729
6135
|
const list = await runClaude(opts.bin, ["plugin", "marketplace", "list", "--json"], opts.env);
|
|
5730
6136
|
try {
|
|
5731
6137
|
const mk = JSON.parse(list.out.slice(list.out.indexOf("["))).find((m) => m.name === CLAUDE_MARKETPLACE);
|
|
5732
|
-
if (mk && mk.path &&
|
|
6138
|
+
if (mk && mk.path && path14.resolve(mk.path) === path14.resolve(dir)) await runClaude(opts.bin, ["plugin", "marketplace", "remove", CLAUDE_MARKETPLACE], opts.env);
|
|
5733
6139
|
} catch {
|
|
5734
6140
|
}
|
|
5735
6141
|
} else {
|
|
5736
6142
|
try {
|
|
5737
|
-
const raw = await
|
|
6143
|
+
const raw = await fsp8.readFile(opts.settingsFile, "utf8");
|
|
5738
6144
|
const s = JSON.parse(raw);
|
|
5739
6145
|
let changed = false;
|
|
5740
6146
|
if (s.enabledPlugins && CLAUDE_PLUGIN_ID in s.enabledPlugins) {
|
|
@@ -5742,16 +6148,16 @@ async function removeClaudePlugin(opts) {
|
|
|
5742
6148
|
changed = true;
|
|
5743
6149
|
}
|
|
5744
6150
|
const mk = s.extraKnownMarketplaces?.[CLAUDE_MARKETPLACE];
|
|
5745
|
-
if (mk?.source?.path &&
|
|
6151
|
+
if (mk?.source?.path && path14.resolve(mk.source.path) === path14.resolve(dir)) {
|
|
5746
6152
|
delete s.extraKnownMarketplaces[CLAUDE_MARKETPLACE];
|
|
5747
6153
|
changed = true;
|
|
5748
6154
|
}
|
|
5749
|
-
if (changed) await
|
|
6155
|
+
if (changed) await fsp8.writeFile(opts.settingsFile, `${JSON.stringify(s, null, 2)}
|
|
5750
6156
|
`);
|
|
5751
6157
|
} catch {
|
|
5752
6158
|
}
|
|
5753
6159
|
}
|
|
5754
|
-
await
|
|
6160
|
+
await fsp8.rm(dir, { recursive: true, force: true });
|
|
5755
6161
|
await writeKvaliState(opts.home, { claudePlugin: false });
|
|
5756
6162
|
return true;
|
|
5757
6163
|
}
|
|
@@ -5766,8 +6172,8 @@ var CLAUDE_HOOKS = [
|
|
|
5766
6172
|
var CLAUDE_HOOK_EVENTS = CLAUDE_HOOKS.map((h) => h.event);
|
|
5767
6173
|
var MARKER = "/v1/events/claude-code";
|
|
5768
6174
|
function claudeSettingsPath(home = os2.homedir(), env = process.env) {
|
|
5769
|
-
const dir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() ||
|
|
5770
|
-
return
|
|
6175
|
+
const dir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path15.join(home, ".claude");
|
|
6176
|
+
return path15.join(dir, "settings.json");
|
|
5771
6177
|
}
|
|
5772
6178
|
function claudeHookCommand(port = DEFAULT_HOOK_PORT, sync = false) {
|
|
5773
6179
|
const url = `http://127.0.0.1:${port}${MARKER}`;
|
|
@@ -5779,7 +6185,7 @@ function hookEntry(spec, port) {
|
|
|
5779
6185
|
async function readSettings(file) {
|
|
5780
6186
|
let text;
|
|
5781
6187
|
try {
|
|
5782
|
-
text = await
|
|
6188
|
+
text = await fsp9.readFile(file, "utf8");
|
|
5783
6189
|
} catch (err) {
|
|
5784
6190
|
if (err.code === "ENOENT") return {};
|
|
5785
6191
|
throw err;
|
|
@@ -5836,7 +6242,7 @@ async function claudeHooksStatus(file = claudeSettingsPath(), port = DEFAULT_HOO
|
|
|
5836
6242
|
return current === CLAUDE_HOOKS.length && total === CLAUDE_HOOKS.length ? "installed" : "outdated";
|
|
5837
6243
|
}
|
|
5838
6244
|
async function writeWithBackup(file, before, settings) {
|
|
5839
|
-
await
|
|
6245
|
+
await fsp9.mkdir(path15.dirname(file), { recursive: true });
|
|
5840
6246
|
let backup;
|
|
5841
6247
|
if (before !== void 0) {
|
|
5842
6248
|
backup = `${file}.kvali-backup`;
|
|
@@ -5852,7 +6258,7 @@ function canonical(v) {
|
|
|
5852
6258
|
);
|
|
5853
6259
|
}
|
|
5854
6260
|
async function installClaudeHooks(file = claudeSettingsPath(), port = DEFAULT_HOOK_PORT) {
|
|
5855
|
-
const before = await
|
|
6261
|
+
const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
|
|
5856
6262
|
const current = await readSettings(file);
|
|
5857
6263
|
const settings = withoutKvali(current);
|
|
5858
6264
|
settings.hooks = settings.hooks && typeof settings.hooks === "object" ? settings.hooks : {};
|
|
@@ -5868,7 +6274,7 @@ function envOf(settings) {
|
|
|
5868
6274
|
return settings.env && typeof settings.env === "object" && !Array.isArray(settings.env) ? settings.env : void 0;
|
|
5869
6275
|
}
|
|
5870
6276
|
async function enableClaudeTodoTools(file, home) {
|
|
5871
|
-
const before = await
|
|
6277
|
+
const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
|
|
5872
6278
|
const settings = await readSettings(file);
|
|
5873
6279
|
const env = envOf(settings);
|
|
5874
6280
|
if (env && CLAUDE_TODO_TOOLS_ENV in env) return { changed: false };
|
|
@@ -5879,7 +6285,7 @@ async function enableClaudeTodoTools(file, home) {
|
|
|
5879
6285
|
}
|
|
5880
6286
|
async function disableClaudeTodoTools(file, home) {
|
|
5881
6287
|
if (!(await readKvaliState(home)).claudeTodoTools) return { changed: false };
|
|
5882
|
-
const before = await
|
|
6288
|
+
const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
|
|
5883
6289
|
let changed = false;
|
|
5884
6290
|
if (before !== void 0) {
|
|
5885
6291
|
const settings = await readSettings(file);
|
|
@@ -5896,7 +6302,7 @@ async function disableClaudeTodoTools(file, home) {
|
|
|
5896
6302
|
return { changed };
|
|
5897
6303
|
}
|
|
5898
6304
|
async function uninstallClaudeHooks(file = claudeSettingsPath()) {
|
|
5899
|
-
const before = await
|
|
6305
|
+
const before = await fsp9.readFile(file, "utf8").catch(() => void 0);
|
|
5900
6306
|
if (before === void 0) return { changed: false };
|
|
5901
6307
|
const settings = await readSettings(file);
|
|
5902
6308
|
const next = withoutKvali(settings);
|
|
@@ -5905,8 +6311,8 @@ async function uninstallClaudeHooks(file = claudeSettingsPath()) {
|
|
|
5905
6311
|
}
|
|
5906
6312
|
|
|
5907
6313
|
// ../core/src/protocol.ts
|
|
5908
|
-
import { promises as
|
|
5909
|
-
import
|
|
6314
|
+
import { promises as fsp10 } from "node:fs";
|
|
6315
|
+
import path16 from "node:path";
|
|
5910
6316
|
var PROGRESS_PROTOCOL_MARKER = "<!-- kvali:progress-protocol v2 -->";
|
|
5911
6317
|
function progressProtocolSnippet() {
|
|
5912
6318
|
return `${PROGRESS_PROTOCOL_MARKER}
|
|
@@ -5981,13 +6387,13 @@ function withBlock(text, name, snippet) {
|
|
|
5981
6387
|
return { text: `${text}${sep}${snippet}`, result: "added" };
|
|
5982
6388
|
}
|
|
5983
6389
|
function globalInstructionFiles(home, env = {}) {
|
|
5984
|
-
const claude = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() ||
|
|
5985
|
-
const codex = env.CODEX_HOME ||
|
|
5986
|
-
const gemini =
|
|
6390
|
+
const claude = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path16.join(home, ".claude");
|
|
6391
|
+
const codex = env.CODEX_HOME || path16.join(home, ".codex");
|
|
6392
|
+
const gemini = path16.join(home, ".gemini");
|
|
5987
6393
|
return [
|
|
5988
|
-
{ id: "claude-code", agent: "Claude Code", dir: claude, file:
|
|
5989
|
-
{ id: "codex", agent: "Codex", dir: codex, file:
|
|
5990
|
-
{ id: "gemini", agent: "Gemini CLI / Antigravity", dir: gemini, file:
|
|
6394
|
+
{ id: "claude-code", agent: "Claude Code", dir: claude, file: path16.join(claude, "CLAUDE.md") },
|
|
6395
|
+
{ id: "codex", agent: "Codex", dir: codex, file: path16.join(codex, "AGENTS.md") },
|
|
6396
|
+
{ id: "gemini", agent: "Gemini CLI / Antigravity", dir: gemini, file: path16.join(gemini, "GEMINI.md") }
|
|
5991
6397
|
];
|
|
5992
6398
|
}
|
|
5993
6399
|
function withoutBlock(text, name) {
|
|
@@ -6005,13 +6411,13 @@ async function removeGlobalPlanRule(home, env = {}) {
|
|
|
6005
6411
|
for (const target of globalInstructionFiles(home, env)) {
|
|
6006
6412
|
let text;
|
|
6007
6413
|
try {
|
|
6008
|
-
text = await
|
|
6414
|
+
text = await fsp10.readFile(target.file, "utf8");
|
|
6009
6415
|
} catch {
|
|
6010
6416
|
continue;
|
|
6011
6417
|
}
|
|
6012
6418
|
const next = withoutBlock(text, "plan-rule");
|
|
6013
6419
|
if (next === void 0) continue;
|
|
6014
|
-
if (next.trim() === "") await
|
|
6420
|
+
if (next.trim() === "") await fsp10.unlink(target.file);
|
|
6015
6421
|
else await writeFileSafely(target.file, next);
|
|
6016
6422
|
changed.push(target.file);
|
|
6017
6423
|
}
|
|
@@ -6019,7 +6425,7 @@ async function removeGlobalPlanRule(home, env = {}) {
|
|
|
6019
6425
|
}
|
|
6020
6426
|
async function readOptional(file) {
|
|
6021
6427
|
try {
|
|
6022
|
-
return await
|
|
6428
|
+
return await fsp10.readFile(file, "utf8");
|
|
6023
6429
|
} catch {
|
|
6024
6430
|
return void 0;
|
|
6025
6431
|
}
|
|
@@ -6029,7 +6435,7 @@ async function addGlobalPlanRule(home, env = {}, only) {
|
|
|
6029
6435
|
for (const target of globalInstructionFiles(home, env)) {
|
|
6030
6436
|
if (only && !only.includes(target.id)) continue;
|
|
6031
6437
|
try {
|
|
6032
|
-
const st = await
|
|
6438
|
+
const st = await fsp10.stat(target.dir);
|
|
6033
6439
|
if (!st.isDirectory()) continue;
|
|
6034
6440
|
} catch {
|
|
6035
6441
|
continue;
|
|
@@ -6041,7 +6447,7 @@ async function addGlobalPlanRule(home, env = {}, only) {
|
|
|
6041
6447
|
return out;
|
|
6042
6448
|
}
|
|
6043
6449
|
async function addProgressProtocol(root) {
|
|
6044
|
-
const file =
|
|
6450
|
+
const file = path16.join(root, "AGENTS.md");
|
|
6045
6451
|
const current = await readOptional(file);
|
|
6046
6452
|
const next = withBlock(current ?? "# AGENTS.md\n\n", "progress-protocol", progressProtocolSnippet());
|
|
6047
6453
|
if (next.result !== "exists") await writeFileSafely(file, next.text);
|
|
@@ -6050,11 +6456,11 @@ async function addProgressProtocol(root) {
|
|
|
6050
6456
|
|
|
6051
6457
|
// ../core/src/hooks/replies.ts
|
|
6052
6458
|
import { existsSync as existsSync2 } from "node:fs";
|
|
6053
|
-
import
|
|
6459
|
+
import path17 from "node:path";
|
|
6054
6460
|
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
6461
|
function pluginRunsIn(liveDir, sessionId) {
|
|
6056
6462
|
if (!/^[A-Za-z0-9-]{8,80}$/.test(sessionId)) return false;
|
|
6057
|
-
return existsSync2(
|
|
6463
|
+
return existsSync2(path17.join(liveDir, "claude-code", `${sessionId}.mod.json`));
|
|
6058
6464
|
}
|
|
6059
6465
|
function claudeHookReply(ev, session, pluginRuns = false) {
|
|
6060
6466
|
if (ev.event !== "UserPromptSubmit") return void 0;
|
|
@@ -6067,23 +6473,23 @@ function claudeHookReply(ev, session, pluginRuns = false) {
|
|
|
6067
6473
|
}
|
|
6068
6474
|
|
|
6069
6475
|
// ../core/src/setup.ts
|
|
6070
|
-
import { promises as
|
|
6071
|
-
import
|
|
6476
|
+
import { promises as fsp11 } from "node:fs";
|
|
6477
|
+
import path18 from "node:path";
|
|
6072
6478
|
async function isDir(p2) {
|
|
6073
6479
|
try {
|
|
6074
|
-
return (await
|
|
6480
|
+
return (await fsp11.stat(p2)).isDirectory();
|
|
6075
6481
|
} catch {
|
|
6076
6482
|
return false;
|
|
6077
6483
|
}
|
|
6078
6484
|
}
|
|
6079
6485
|
async function detectAgents(home, env = {}) {
|
|
6080
|
-
const claudeDir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() ||
|
|
6486
|
+
const claudeDir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path18.join(home, ".claude");
|
|
6081
6487
|
const [claude, codex, gemini, ag1, ag2] = await Promise.all([
|
|
6082
6488
|
isDir(claudeDir),
|
|
6083
|
-
isDir(env.CODEX_HOME ||
|
|
6084
|
-
isDir(
|
|
6085
|
-
isDir(
|
|
6086
|
-
isDir(
|
|
6489
|
+
isDir(env.CODEX_HOME || path18.join(home, ".codex")),
|
|
6490
|
+
isDir(path18.join(home, ".gemini")),
|
|
6491
|
+
isDir(path18.join(home, ".gemini", "antigravity")),
|
|
6492
|
+
isDir(path18.join(home, ".gemini", "antigravity-ide"))
|
|
6087
6493
|
]);
|
|
6088
6494
|
return { claude, codex, gemini, antigravity: ag1 || ag2 };
|
|
6089
6495
|
}
|
|
@@ -6142,8 +6548,8 @@ async function removeSetup(home, env = {}, opts = {}) {
|
|
|
6142
6548
|
|
|
6143
6549
|
// ../core/src/phone.ts
|
|
6144
6550
|
import { randomBytes as randomBytes2, randomInt } from "node:crypto";
|
|
6145
|
-
import { promises as
|
|
6146
|
-
import
|
|
6551
|
+
import { promises as fsp12 } from "node:fs";
|
|
6552
|
+
import path19 from "node:path";
|
|
6147
6553
|
var PHONE_EVENTS = ["needs-you", "done", "steps", "actions", "error", "stuck", "limits"];
|
|
6148
6554
|
var DEFAULT_PHONE_EVENTS = ["needs-you", "done", "error", "stuck", "steps", "limits"];
|
|
6149
6555
|
var DEFAULT_EVENTS_V1 = ["needs-you", "done", "error", "stuck"];
|
|
@@ -6151,7 +6557,7 @@ var DEFAULT_EVENTS_V2 = ["needs-you", "done", "error", "stuck", "steps"];
|
|
|
6151
6557
|
var PHONE_CONFIG_VERSION = 3;
|
|
6152
6558
|
var DEFAULT_NTFY_SERVER = "https://ntfy.sh";
|
|
6153
6559
|
var DEFAULT_DONE_AFTER_SEC = 120;
|
|
6154
|
-
var kvaliConfigFile = (home) =>
|
|
6560
|
+
var kvaliConfigFile = (home) => path19.join(home, ".kvali", "config.json");
|
|
6155
6561
|
var TOPIC_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
6156
6562
|
var TELEGRAM_TOKEN_RE = /^\d{5,15}:[A-Za-z0-9_-]{30,64}$/;
|
|
6157
6563
|
var DISCORD_WEBHOOK_RE = /^https:\/\/(?:(?:ptb|canary)\.)?discord(?:app)?\.com\/api\/webhooks\/\d{5,25}\/[A-Za-z0-9_-]{20,120}$/;
|
|
@@ -6191,7 +6597,7 @@ function normalizePhoneConfig(raw) {
|
|
|
6191
6597
|
}
|
|
6192
6598
|
async function readPhoneConfig(home) {
|
|
6193
6599
|
try {
|
|
6194
|
-
const all = JSON.parse(await
|
|
6600
|
+
const all = JSON.parse(await fsp12.readFile(kvaliConfigFile(home), "utf8"));
|
|
6195
6601
|
return normalizePhoneConfig(all?.phone);
|
|
6196
6602
|
} catch {
|
|
6197
6603
|
return void 0;
|
|
@@ -6201,7 +6607,7 @@ async function writePhoneConfig(home, cfg) {
|
|
|
6201
6607
|
const file = kvaliConfigFile(home);
|
|
6202
6608
|
let all = {};
|
|
6203
6609
|
try {
|
|
6204
|
-
const parsed = JSON.parse(await
|
|
6610
|
+
const parsed = JSON.parse(await fsp12.readFile(file, "utf8"));
|
|
6205
6611
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) all = parsed;
|
|
6206
6612
|
} catch {
|
|
6207
6613
|
}
|
|
@@ -6218,14 +6624,14 @@ async function writePhoneConfig(home, cfg) {
|
|
|
6218
6624
|
doneAfter: cfg.doneAfterSec ?? DEFAULT_DONE_AFTER_SEC
|
|
6219
6625
|
};
|
|
6220
6626
|
else delete all.phone;
|
|
6221
|
-
await
|
|
6627
|
+
await fsp12.mkdir(path19.dirname(file), { recursive: true, mode: 448 });
|
|
6222
6628
|
await writeFileSafely(file, `${JSON.stringify(all, null, 2)}
|
|
6223
6629
|
`, 384);
|
|
6224
6630
|
}
|
|
6225
6631
|
async function secureKvaliHome(home, create = false) {
|
|
6226
|
-
const dir =
|
|
6227
|
-
if (create) await
|
|
6228
|
-
await
|
|
6632
|
+
const dir = path19.dirname(kvaliConfigFile(home));
|
|
6633
|
+
if (create) await fsp12.mkdir(dir, { recursive: true, mode: 448 }).catch(() => void 0);
|
|
6634
|
+
await fsp12.chmod(dir, 448).catch(() => void 0);
|
|
6229
6635
|
}
|
|
6230
6636
|
function newTopic() {
|
|
6231
6637
|
const alphabet = "abcdefghijkmnpqrstuvwxyz23456789";
|
|
@@ -6840,7 +7246,7 @@ var PhoneNotifier = class {
|
|
|
6840
7246
|
const now = Date.now();
|
|
6841
7247
|
if (!force && now - this.checkedAt < 5e3) return;
|
|
6842
7248
|
this.checkedAt = now;
|
|
6843
|
-
const st = await
|
|
7249
|
+
const st = await fsp12.stat(kvaliConfigFile(this.opts.home)).catch(() => void 0);
|
|
6844
7250
|
const mtime = st?.mtimeMs ?? 0;
|
|
6845
7251
|
if (!force && mtime === this.mtime) return;
|
|
6846
7252
|
this.mtime = mtime;
|
|
@@ -6855,7 +7261,7 @@ var PhoneNotifier = class {
|
|
|
6855
7261
|
this.again = true;
|
|
6856
7262
|
return this.running;
|
|
6857
7263
|
}
|
|
6858
|
-
const
|
|
7264
|
+
const run2 = (async () => {
|
|
6859
7265
|
try {
|
|
6860
7266
|
do {
|
|
6861
7267
|
this.again = false;
|
|
@@ -6865,8 +7271,8 @@ var PhoneNotifier = class {
|
|
|
6865
7271
|
this.running = void 0;
|
|
6866
7272
|
}
|
|
6867
7273
|
})();
|
|
6868
|
-
this.running =
|
|
6869
|
-
return
|
|
7274
|
+
this.running = run2;
|
|
7275
|
+
return run2;
|
|
6870
7276
|
}
|
|
6871
7277
|
/** Looks again every few seconds until `dispose`. */
|
|
6872
7278
|
start() {
|
|
@@ -8580,7 +8986,7 @@ function qrTerminal(text, color = true) {
|
|
|
8580
8986
|
}
|
|
8581
8987
|
|
|
8582
8988
|
// src/index.ts
|
|
8583
|
-
var VERSION = "0.7.
|
|
8989
|
+
var VERSION = "0.7.8";
|
|
8584
8990
|
function parse(argv) {
|
|
8585
8991
|
const opts = {
|
|
8586
8992
|
json: false,
|
|
@@ -8594,7 +9000,8 @@ function parse(argv) {
|
|
|
8594
9000
|
private: false,
|
|
8595
9001
|
steps: void 0,
|
|
8596
9002
|
events: void 0,
|
|
8597
|
-
doneAfter: void 0
|
|
9003
|
+
doneAfter: void 0,
|
|
9004
|
+
keepAwake: "off"
|
|
8598
9005
|
};
|
|
8599
9006
|
const cmd = [];
|
|
8600
9007
|
for (let i = 0; i < argv.length; i += 1) {
|
|
@@ -8613,7 +9020,7 @@ function parse(argv) {
|
|
|
8613
9020
|
break;
|
|
8614
9021
|
case "--project":
|
|
8615
9022
|
case "-p":
|
|
8616
|
-
opts.project =
|
|
9023
|
+
opts.project = path20.resolve(next());
|
|
8617
9024
|
break;
|
|
8618
9025
|
case "--here":
|
|
8619
9026
|
opts.project = process2.cwd();
|
|
@@ -8625,10 +9032,10 @@ function parse(argv) {
|
|
|
8625
9032
|
break;
|
|
8626
9033
|
}
|
|
8627
9034
|
case "--home":
|
|
8628
|
-
opts.home =
|
|
9035
|
+
opts.home = path20.resolve(next());
|
|
8629
9036
|
break;
|
|
8630
9037
|
case "--brain-dir":
|
|
8631
|
-
opts.brainDirs.push(
|
|
9038
|
+
opts.brainDirs.push(path20.resolve(next()));
|
|
8632
9039
|
break;
|
|
8633
9040
|
case "--port": {
|
|
8634
9041
|
const port = Number(next());
|
|
@@ -8671,6 +9078,12 @@ function parse(argv) {
|
|
|
8671
9078
|
opts.doneAfter = Math.round(sec);
|
|
8672
9079
|
break;
|
|
8673
9080
|
}
|
|
9081
|
+
case "--keep-awake":
|
|
9082
|
+
opts.keepAwake = "whenPluggedIn";
|
|
9083
|
+
break;
|
|
9084
|
+
case "--keep-awake=always":
|
|
9085
|
+
opts.keepAwake = "always";
|
|
9086
|
+
break;
|
|
8674
9087
|
case "--svg":
|
|
8675
9088
|
opts.svg = argv[i + 1] !== void 0 && !argv[i + 1].startsWith("-") ? argv[++i] : "";
|
|
8676
9089
|
break;
|
|
@@ -8718,6 +9131,7 @@ Options
|
|
|
8718
9131
|
--home <dir> read agent data from another home directory
|
|
8719
9132
|
--port <n> hook hub port (default ${DEFAULT_HOOK_PORT})
|
|
8720
9133
|
--no-hub do not listen for hook events (and send no phone notifications)
|
|
9134
|
+
--keep-awake keep this computer awake while an agent works, on mains power (--keep-awake=always: on battery too)
|
|
8721
9135
|
--no-color
|
|
8722
9136
|
kvali phone options: --server <url> (self-hosted ntfy) --token <token> --private (no project or step names)
|
|
8723
9137
|
--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 +9314,7 @@ async function week(opts, svgFile) {
|
|
|
8900
9314
|
].join("\n")
|
|
8901
9315
|
);
|
|
8902
9316
|
if (svgFile !== void 0) {
|
|
8903
|
-
const file =
|
|
9317
|
+
const file = path20.resolve(svgFile || `kvali-week-${w.days[w.days.length - 1].day}.svg`);
|
|
8904
9318
|
if ((await lstat(file).catch(() => void 0))?.isSymbolicLink()) fail(`${file} is a symbolic link; give the card another file name`);
|
|
8905
9319
|
await writeFile(file, weekSvg(w));
|
|
8906
9320
|
console.log(`
|
|
@@ -9065,6 +9479,14 @@ async function phone(sub, opts, arg) {
|
|
|
9065
9479
|
].join("\n")
|
|
9066
9480
|
);
|
|
9067
9481
|
}
|
|
9482
|
+
function startKeepAwake(engine, opts, say) {
|
|
9483
|
+
if (opts.keepAwake === "off") return void 0;
|
|
9484
|
+
const awake = new KeepAwake({ log: say });
|
|
9485
|
+
const check = () => void awake.update(agentsWorking(engine.snapshot.sessions, Date.now()), opts.keepAwake);
|
|
9486
|
+
engine.onSnapshot(check);
|
|
9487
|
+
setInterval(check, 3e4).unref();
|
|
9488
|
+
return awake;
|
|
9489
|
+
}
|
|
9068
9490
|
async function main() {
|
|
9069
9491
|
const { cmd, opts } = parse(process2.argv.slice(2));
|
|
9070
9492
|
await secureKvaliHome(opts.home);
|
|
@@ -9078,7 +9500,7 @@ async function main() {
|
|
|
9078
9500
|
const d = await detectAgents(opts.home, process2.env);
|
|
9079
9501
|
const changes = setupChanges(d);
|
|
9080
9502
|
if (!changes.length) fail("no supported agent found (~/.claude, ~/.codex, ~/.gemini)");
|
|
9081
|
-
const pluginDir =
|
|
9503
|
+
const pluginDir = path20.join(path20.dirname(fileURLToPath(import.meta.url)), "claude-plugin");
|
|
9082
9504
|
const r = await applySetup(opts.home, process2.env, opts.port, d, { pluginDir });
|
|
9083
9505
|
const lines = changes.map((c) => ` \u2022 ${c}`);
|
|
9084
9506
|
if (r.claude === "plugin") lines.push(" Claude Code: new sessions show the Kvali pane; type /reload-plugins in sessions already open.");
|
|
@@ -9094,7 +9516,7 @@ async function main() {
|
|
|
9094
9516
|
return;
|
|
9095
9517
|
}
|
|
9096
9518
|
if (cmd[0] === "protocol") {
|
|
9097
|
-
const r = await addProgressProtocol(
|
|
9519
|
+
const r = await addProgressProtocol(path20.resolve(cmd[1] ?? "."));
|
|
9098
9520
|
const said = {
|
|
9099
9521
|
created: `Created ${r.file} with the progress protocol.`,
|
|
9100
9522
|
added: `Added the progress protocol to ${r.file}.`,
|
|
@@ -9121,17 +9543,19 @@ async function main() {
|
|
|
9121
9543
|
startPhone(engine, hub, opts.home, (line) => {
|
|
9122
9544
|
phoneLine = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${line}`;
|
|
9123
9545
|
});
|
|
9546
|
+
const awake = startKeepAwake(engine, opts);
|
|
9124
9547
|
const out = process2.stdout;
|
|
9125
9548
|
out.write(`${ESC}?1049h${ESC}?25l`);
|
|
9126
9549
|
const restore = () => {
|
|
9127
9550
|
out.write(`${ESC}?25h${ESC}?1049l`);
|
|
9551
|
+
awake?.dispose();
|
|
9128
9552
|
hub?.dispose();
|
|
9129
9553
|
engine.dispose();
|
|
9130
9554
|
};
|
|
9131
9555
|
const draw = (snap) => out.write(`${ESC}H${ESC}2J${render(snap, opts)}
|
|
9132
9556
|
${paint(opts.color).gray(`
|
|
9133
9557
|
${phoneLine ? `${phoneLine}
|
|
9134
|
-
` : ""}q to quit`)}`);
|
|
9558
|
+
` : ""}${awake?.active ? "keeping this computer awake \xB7 " : ""}q to quit`)}`);
|
|
9135
9559
|
engine.onSnapshot(draw);
|
|
9136
9560
|
engine.start();
|
|
9137
9561
|
const clock = setInterval(() => draw(engine.snapshot), 1e3);
|
|
@@ -9163,10 +9587,12 @@ async function watch(opts) {
|
|
|
9163
9587
|
const say = (line) => console.log(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${line}`);
|
|
9164
9588
|
hub.start();
|
|
9165
9589
|
startPhone(engine, hub, opts.home, say);
|
|
9590
|
+
const awake = startKeepAwake(engine, opts, say);
|
|
9166
9591
|
engine.start();
|
|
9167
9592
|
const cfg = await readPhoneConfig(opts.home);
|
|
9168
9593
|
say(cfg ? `watching agents; phone notifications go to ${channelNames(cfg)}` : "watching agents; phone notifications are not set up (run `kvali phone`)");
|
|
9169
9594
|
const stop = () => {
|
|
9595
|
+
awake?.dispose();
|
|
9170
9596
|
hub.dispose();
|
|
9171
9597
|
engine.dispose();
|
|
9172
9598
|
process2.exit(0);
|