@cchistory/lite 0.4.2 → 0.4.4
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/INSTALL.md +1 -1
- package/README.md +10 -1
- package/apps/lite-cli/dist/agent-contract.d.ts +83 -0
- package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -0
- package/apps/lite-cli/dist/agent-contract.js +273 -0
- package/apps/lite-cli/dist/agent-contract.js.map +1 -0
- package/apps/lite-cli/dist/index.d.ts +1 -0
- package/apps/lite-cli/dist/index.d.ts.map +1 -1
- package/apps/lite-cli/dist/index.js +193 -55
- package/apps/lite-cli/dist/index.js.map +1 -1
- package/apps/lite-cli/dist/index.test.js +515 -18
- package/apps/lite-cli/dist/index.test.js.map +1 -1
- package/apps/lite-cli/dist/json-v2.js +1 -1
- package/apps/lite-cli/dist/json-v2.js.map +1 -1
- package/apps/lite-cli/dist/version.d.ts +11 -0
- package/apps/lite-cli/dist/version.d.ts.map +1 -0
- package/apps/lite-cli/dist/version.js +11 -0
- package/apps/lite-cli/dist/version.js.map +1 -0
- package/apps/lite-tui/dist/index.d.ts.map +1 -1
- package/apps/lite-tui/dist/index.js +26 -4
- package/apps/lite-tui/dist/index.js.map +1 -1
- package/apps/lite-tui/dist/index.test.js +97 -2
- package/apps/lite-tui/dist/index.test.js.map +1 -1
- package/apps/lite-tui/dist/model.d.ts.map +1 -1
- package/apps/lite-tui/dist/model.js +16 -8
- package/apps/lite-tui/dist/model.js.map +1 -1
- package/apps/lite-tui/dist/render.d.ts +1 -1
- package/apps/lite-tui/dist/render.js +1 -1
- package/apps/lite-tui/dist/render.js.map +1 -1
- package/apps/lite-tui/dist/render.test.js +38 -13
- package/apps/lite-tui/dist/render.test.js.map +1 -1
- package/apps/lite-tui/dist/text.d.ts +2 -2
- package/apps/lite-tui/dist/text.d.ts.map +1 -1
- package/apps/lite-tui/dist/text.js +2 -23
- package/apps/lite-tui/dist/text.js.map +1 -1
- package/apps/lite-tui/dist/version.d.ts +3 -2
- package/apps/lite-tui/dist/version.d.ts.map +1 -1
- package/apps/lite-tui/dist/version.js +3 -2
- package/apps/lite-tui/dist/version.js.map +1 -1
- package/apps/lite-tui/dist/view-model.d.ts +7 -6
- package/apps/lite-tui/dist/view-model.d.ts.map +1 -1
- package/apps/lite-tui/dist/view-model.js +10 -8
- package/apps/lite-tui/dist/view-model.js.map +1 -1
- package/docs/guide/for-agents.md +117 -0
- package/docs/guide/lite.md +355 -0
- package/node_modules/@cchistory/canonical/dist/index.test.js +47 -0
- package/node_modules/@cchistory/canonical/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/project-linker.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/project-linker.js +5 -2
- package/node_modules/@cchistory/canonical/dist/project-linker.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/projection-audit.d.ts +1 -1
- package/node_modules/@cchistory/canonical/dist/projection-audit.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/projection-audit.js +11 -0
- package/node_modules/@cchistory/canonical/dist/projection-audit.js.map +1 -1
- package/node_modules/@cchistory/canonical/package.json +1 -1
- package/node_modules/@cchistory/domain/dist/index.d.ts +7 -0
- package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/domain/dist/index.js +25 -0
- package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
- package/node_modules/@cchistory/domain/dist/index.test.js +17 -1
- package/node_modules/@cchistory/domain/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/domain/package.json +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts +31 -1
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.js +92 -3
- package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.test.js +8 -0
- package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts +5 -2
- package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/node-memory.js +32 -5
- package/node_modules/@cchistory/live-runtime/dist/node-memory.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts +157 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js +445 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js +555 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts +19 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.js +56 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/package.json +1 -1
- package/node_modules/@cchistory/source-adapters/package.json +1 -1
- package/package.json +13 -5
- package/schemas/cchistory-lite-agent-v1.schema.json +205 -0
- package/schemas/cchistory-lite-v2.schema.json +1 -1
- package/skills/using-cchistory-lite/SKILL.md +80 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { access, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { access, cp, mkdir, mkdtemp, readFile, rm, symlink, truncate, writeFile } from "node:fs/promises";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { PassThrough } from "node:stream";
|
|
6
6
|
import { setTimeout as delay } from "node:timers/promises";
|
|
7
7
|
import test from "node:test";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { LiveHistorySnapshot, scanLiteHistory, } from "@cchistory/live-runtime";
|
|
10
|
-
import { formatTuiLaunchError, runLiteCli } from "./index.js";
|
|
9
|
+
import { FULL_SCAN_MEMORY_MULTIPLIER, LIGHT_SCAN_MEMORY_MULTIPLIER, LiveHistorySnapshot, MAX_OLD_SPACE_MIB, MIN_OLD_SPACE_MIB, SCAN_GUARD_REFUSE_AVAILABLE_FRACTION, SCAN_GUARD_WARN_AVAILABLE_FRACTION, SCAN_LOCK_WAIT_MS, SCAN_WATCHDOG_MIN_FLOOR_BYTES, SCAN_WATCHDOG_TOTAL_FLOOR_FRACTION, scanLiteHistory, ScanGuardAbortedError, ScanGuardRefusedError, } from "@cchistory/live-runtime";
|
|
10
|
+
import { formatTuiLaunchError, runLiteCli, VERSION } from "./index.js";
|
|
11
|
+
import { buildAgentContract } from "./agent-contract.js";
|
|
11
12
|
import { compactPayload } from "./json-v2.js";
|
|
12
13
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");
|
|
13
14
|
const codexRoot = path.join(repoRoot, "mock_data", ".codex", "sessions");
|
|
@@ -83,7 +84,7 @@ test("Lite CLI searches, reports stats, and writes one-way export", async () =>
|
|
|
83
84
|
assert.equal(statsPayload.kind, "stats");
|
|
84
85
|
assert.ok(statsPayload.overview.total_turns > 0);
|
|
85
86
|
const humanStats = captureIo(tempHome);
|
|
86
|
-
assert.equal(await runLiteCli(["stats", ...sourceArgs], humanStats.io), 0);
|
|
87
|
+
assert.equal(await runLiteCli(["stats", ...sourceArgs, "--no-dir"], humanStats.io), 0);
|
|
87
88
|
assert.match(humanStats.stdout.join(""), /Excluded zero-token turns:/);
|
|
88
89
|
const rollup = captureIo(tempHome);
|
|
89
90
|
assert.equal(await runLiteCli(["stats", "--by", "source", ...unscopedArgs], rollup.io), 0);
|
|
@@ -635,7 +636,7 @@ test("Lite CLI latest parses defaults, aliases, and positional counts", async ()
|
|
|
635
636
|
turns: [pendingTurn, ...snapshot.data.turns],
|
|
636
637
|
});
|
|
637
638
|
const latestSessions = captureIo(repoRoot, undefined, { scan: async () => zeroTurnSnapshot });
|
|
638
|
-
assert.equal(await runLiteCli(["latest"], latestSessions.io), 0);
|
|
639
|
+
assert.equal(await runLiteCli(["latest", "--no-dir"], latestSessions.io), 0);
|
|
639
640
|
const latestSessionText = latestSessions.stdout.join("");
|
|
640
641
|
assert.match(latestSessionText, /Latest sessions \(6, newest first; one record = one session\)/);
|
|
641
642
|
assert.match(latestSessionText, /● just now ·/);
|
|
@@ -651,12 +652,12 @@ test("Lite CLI latest parses defaults, aliases, and positional counts", async ()
|
|
|
651
652
|
const resumableSessionRef = snapshot.getSessionDisplayRef(resumableSession.id) ?? resumableSession.id;
|
|
652
653
|
assert.equal(latestSessionText.includes(`session ${resumableSessionRef}`), false, "latest must not repeat a session id when a resume command already identifies the session");
|
|
653
654
|
const narrowSessions = captureIo(repoRoot, undefined, { scan: scanner, columns: 40 });
|
|
654
|
-
assert.equal(await runLiteCli(["ls", "sessions", "--all"], narrowSessions.io), 0);
|
|
655
|
+
assert.equal(await runLiteCli(["ls", "sessions", "--all", "--no-dir"], narrowSessions.io), 0);
|
|
655
656
|
const narrowSessionText = narrowSessions.stdout.join("");
|
|
656
657
|
assert.ok(narrowSessionText.split("\n").slice(1).every((line) => displayColumnsForTest(line) <= 40), "session rows must stay within the injected terminal width");
|
|
657
658
|
assert.ok(narrowSessionText.replace(/\s+/gu, "").includes(resumableSession.resume_command.replace(/\s+/gu, "")), "wrapped resume commands must retain every non-whitespace character");
|
|
658
659
|
const latestTurns = captureIo(repoRoot, undefined, { scan: scanner });
|
|
659
|
-
assert.equal(await runLiteCli(["latest", "turns", "1"], latestTurns.io), 0);
|
|
660
|
+
assert.equal(await runLiteCli(["latest", "turns", "1", "--no-dir"], latestTurns.io), 0);
|
|
660
661
|
const latestTurnText = latestTurns.stdout.join("");
|
|
661
662
|
const firstTurn = snapshot.listResolvedTurns()[0];
|
|
662
663
|
assert.ok(firstTurn);
|
|
@@ -676,7 +677,7 @@ test("Lite CLI latest parses defaults, aliases, and positional counts", async ()
|
|
|
676
677
|
assert.ok(latestTurnText.includes(new Intl.NumberFormat("en-US").format(firstTurnTokens)));
|
|
677
678
|
}
|
|
678
679
|
const narrowTurns = captureIo(repoRoot, undefined, { scan: scanner, columns: 70 });
|
|
679
|
-
assert.equal(await runLiteCli(["latest", "turns", "1"], narrowTurns.io), 0);
|
|
680
|
+
assert.equal(await runLiteCli(["latest", "turns", "1", "--no-dir"], narrowTurns.io), 0);
|
|
680
681
|
assert.ok(narrowTurns.stdout.join("").split("\n").every((line) => displayColumnsForTest(line) <= 70), "latest output must stay within a narrow terminal width");
|
|
681
682
|
const defaults = captureIo(repoRoot, undefined, { scan: async () => zeroTurnSnapshot });
|
|
682
683
|
assert.equal(await runLiteCli(["latest", "--json", "--no-dir"], defaults.io), 0);
|
|
@@ -723,12 +724,12 @@ test("Lite CLI ls limits human and JSON output and rejects conflicting controls
|
|
|
723
724
|
const snapshot = await getCodexSnapshot();
|
|
724
725
|
const scanner = async () => snapshot;
|
|
725
726
|
const projects = captureIo(repoRoot, undefined, { scan: scanner });
|
|
726
|
-
assert.equal(await runLiteCli(["ls", "projects", "--limit", "1"], projects.io), 0);
|
|
727
|
+
assert.equal(await runLiteCli(["ls", "projects", "--limit", "1", "--no-dir"], projects.io), 0);
|
|
727
728
|
assert.match(projects.stdout.join(""), /Projects \(1 of \d+, most active first; one record = one project\)/);
|
|
728
729
|
assert.match(projects.stdout.join(""), /● /);
|
|
729
730
|
assert.doesNotMatch(projects.stdout.join(""), /ACTIVITY\s+LINKAGE\s+SESS\s+TURNS\s+DIRECTORY/);
|
|
730
731
|
const limited = captureIo(repoRoot, undefined, { scan: scanner });
|
|
731
|
-
assert.equal(await runLiteCli(["ls", "sessions", "--limit", "1"], limited.io), 0);
|
|
732
|
+
assert.equal(await runLiteCli(["ls", "sessions", "--limit", "1", "--no-dir"], limited.io), 0);
|
|
732
733
|
assert.match(limited.stdout.join(""), /Sessions \(1 of 5, newest first; one record = one session\)/);
|
|
733
734
|
assert.match(limited.stdout.join(""), /● .* · Codex/);
|
|
734
735
|
assert.doesNotMatch(limited.stdout.join(""), /UPDATED\s+SOURCE\s+SESSION\s+TURNS/);
|
|
@@ -767,6 +768,7 @@ test("Lite CLI ls limits human and JSON output and rejects conflicting controls
|
|
|
767
768
|
});
|
|
768
769
|
assert.equal(await runLiteCli(["ls", "sources", "--dir", "/workspace"], invalidScope.io), 2);
|
|
769
770
|
assert.match(invalidScope.stderr.join(""), /--dir is not valid for ls sources/);
|
|
771
|
+
assert.match(invalidScope.stderr.join(""), /Drop --dir and pass --limit-files/);
|
|
770
772
|
assert.equal(rejectedScans, 0);
|
|
771
773
|
});
|
|
772
774
|
test("Lite CLI applies --dir to sessions, search, stats, and project trees", async () => {
|
|
@@ -860,6 +862,29 @@ test("Lite CLI show resolves canonical session refs before a source-wide detail
|
|
|
860
862
|
assert.doesNotMatch(rendered.stdout.join(""), /\n\{/);
|
|
861
863
|
}
|
|
862
864
|
});
|
|
865
|
+
test("Lite CLI markdown export uses the light scan-guard profile; JSON export stays full", async () => {
|
|
866
|
+
const snapshot = await getCodexSnapshot();
|
|
867
|
+
const scanFor = async (args) => {
|
|
868
|
+
const calls = [];
|
|
869
|
+
const captured = captureIo(repoRoot, undefined, {
|
|
870
|
+
scan: async (options) => {
|
|
871
|
+
calls.push(options);
|
|
872
|
+
return snapshot;
|
|
873
|
+
},
|
|
874
|
+
});
|
|
875
|
+
assert.equal(await runLiteCli(args, captured.io), 0, captured.stderr.join(""));
|
|
876
|
+
return calls[0];
|
|
877
|
+
};
|
|
878
|
+
const markdown = await scanFor(["export", "--format", "markdown", "--out", "-"]);
|
|
879
|
+
assert.equal(markdown?.contextMode, "none");
|
|
880
|
+
assert.equal(markdown?.scanGuard?.profile, "light");
|
|
881
|
+
const json = await scanFor(["export", "--format", "json", "--out", "-"]);
|
|
882
|
+
assert.equal(json?.contextMode, "full");
|
|
883
|
+
assert.equal(json?.scanGuard?.profile, "full");
|
|
884
|
+
const jsonl = await scanFor(["export", "--format", "jsonl", "--out", "-"]);
|
|
885
|
+
assert.equal(jsonl?.contextMode, "full");
|
|
886
|
+
assert.equal(jsonl?.scanGuard?.profile, "full");
|
|
887
|
+
});
|
|
863
888
|
test("Lite CLI sample is a bounded latest-shaped preview", async () => {
|
|
864
889
|
const snapshot = await getCodexSnapshot();
|
|
865
890
|
const scanOptions = [];
|
|
@@ -871,12 +896,19 @@ test("Lite CLI sample is a bounded latest-shaped preview", async () => {
|
|
|
871
896
|
});
|
|
872
897
|
assert.equal(await runLiteCli(["sample", "3", "--json"], captured.io), 0);
|
|
873
898
|
assert.equal(scanOptions[0]?.sample?.perSource, 3);
|
|
874
|
-
assert.equal(scanOptions[0]?.directoryScope,
|
|
899
|
+
assert.equal(scanOptions[0]?.directoryScope, repoRoot);
|
|
875
900
|
const payload = JSON.parse(captured.stdout.join(""));
|
|
876
901
|
assert.equal(payload.kind, "sessions");
|
|
877
902
|
assert.equal(payload.sampled, true);
|
|
878
903
|
assert.equal(payload.sample_per_source, 3);
|
|
879
904
|
});
|
|
905
|
+
test("the CLI version matches the package manifest", async () => {
|
|
906
|
+
const manifest = JSON.parse(await readFile(path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "package.json"), "utf8"));
|
|
907
|
+
assert.equal(VERSION, manifest.version);
|
|
908
|
+
const captured = captureIo(repoRoot);
|
|
909
|
+
assert.equal(await runLiteCli(["--version"], captured.io), 0);
|
|
910
|
+
assert.equal(captured.stdout.join(""), `${VERSION}\n`);
|
|
911
|
+
});
|
|
880
912
|
test("Lite CLI help documents latest, limits, and directory scope", async () => {
|
|
881
913
|
const captured = captureIo(repoRoot);
|
|
882
914
|
assert.equal(await runLiteCli(["help"], captured.io), 0);
|
|
@@ -892,6 +924,46 @@ test("Lite CLI help documents latest, limits, and directory scope", async () =>
|
|
|
892
924
|
assert.match(help, /last real message activity/);
|
|
893
925
|
assert.match(help, /Sessions without a\nworking directory are excluded/);
|
|
894
926
|
assert.match(help, /does not open parent project folders or later Codex cwd lines/);
|
|
927
|
+
assert.match(help, /default: current directory/);
|
|
928
|
+
assert.match(help, /can use a lot of memory/);
|
|
929
|
+
assert.match(help, /TUI and export still scan every selected source/);
|
|
930
|
+
assert.match(help, /--offset <n>/);
|
|
931
|
+
assert.match(help, /--project <ref>/);
|
|
932
|
+
assert.match(help, /--by <dimension>/);
|
|
933
|
+
assert.match(help, /--format jsonl\|json\|markdown/);
|
|
934
|
+
assert.match(help, /--out <file\|->/);
|
|
935
|
+
assert.match(help, /cchistory-lite help \[command\]/);
|
|
936
|
+
// store/db appear only in the closing line that documents their absence.
|
|
937
|
+
const knownFlags = new Set([
|
|
938
|
+
"source-root",
|
|
939
|
+
"source",
|
|
940
|
+
"limit-files",
|
|
941
|
+
"limit",
|
|
942
|
+
"offset",
|
|
943
|
+
"project",
|
|
944
|
+
"by",
|
|
945
|
+
"format",
|
|
946
|
+
"out",
|
|
947
|
+
"dir",
|
|
948
|
+
"request",
|
|
949
|
+
"safe",
|
|
950
|
+
"json",
|
|
951
|
+
"help",
|
|
952
|
+
"version",
|
|
953
|
+
"all",
|
|
954
|
+
"no-dir",
|
|
955
|
+
"store",
|
|
956
|
+
"db",
|
|
957
|
+
]);
|
|
958
|
+
const documentedFlags = new Set([...help.matchAll(/--([a-z][a-z-]*)/gu)].map((match) => match[1]));
|
|
959
|
+
for (const flag of documentedFlags) {
|
|
960
|
+
assert.ok(knownFlags.has(flag), `help documents unknown option --${flag}`);
|
|
961
|
+
}
|
|
962
|
+
for (const flag of knownFlags) {
|
|
963
|
+
if (flag === "store" || flag === "db")
|
|
964
|
+
continue;
|
|
965
|
+
assert.ok(documentedFlags.has(flag), `help omits accepted option --${flag}`);
|
|
966
|
+
}
|
|
895
967
|
});
|
|
896
968
|
test("Lite CLI colorizes collection cards semantically on a TTY", async () => {
|
|
897
969
|
const snapshot = await getCodexSnapshot();
|
|
@@ -904,7 +976,7 @@ test("Lite CLI colorizes collection cards semantically on a TTY", async () => {
|
|
|
904
976
|
process.env.TERM = "xterm-256color";
|
|
905
977
|
try {
|
|
906
978
|
const tty = captureIo(repoRoot, undefined, { scan: scanner, isTTY: true });
|
|
907
|
-
assert.equal(await runLiteCli(["ls", "sessions", "--all"], tty.io), 0);
|
|
979
|
+
assert.equal(await runLiteCli(["ls", "sessions", "--all", "--no-dir"], tty.io), 0);
|
|
908
980
|
const text = tty.stdout.join("");
|
|
909
981
|
// Gray tier: heading, timestamps, counts, session ids, resume command body.
|
|
910
982
|
assert.ok(text.includes(`${E}[2mSessions (`));
|
|
@@ -945,22 +1017,22 @@ test("Lite CLI colorizes collection cards semantically on a TTY", async () => {
|
|
|
945
1017
|
assert.ok(text.includes(`${E}[35m`) && text.includes(`${E}[0m ${E}[1m${E}[32m`));
|
|
946
1018
|
assert.ok(!text.includes(`${E}[4m`));
|
|
947
1019
|
const ttyTurns = captureIo(repoRoot, undefined, { scan: scanner, isTTY: true });
|
|
948
|
-
assert.equal(await runLiteCli(["latest", "turns", "2"], ttyTurns.io), 0);
|
|
1020
|
+
assert.equal(await runLiteCli(["latest", "turns", "2", "--no-dir"], ttyTurns.io), 0);
|
|
949
1021
|
const turnsText = ttyTurns.stdout.join("");
|
|
950
1022
|
assert.ok(turnsText.includes(`${E}[34mCodex${E}[0m`));
|
|
951
1023
|
assert.ok(turnsText.includes(`${E}[1m${E}[32m `));
|
|
952
1024
|
assert.ok(turnsText.includes(`${E}[35m`));
|
|
953
1025
|
const ttyProjects = captureIo(repoRoot, undefined, { scan: scanner, isTTY: true });
|
|
954
|
-
assert.equal(await runLiteCli(["ls", "projects", "--all"], ttyProjects.io), 0);
|
|
1026
|
+
assert.equal(await runLiteCli(["ls", "projects", "--all", "--no-dir"], ttyProjects.io), 0);
|
|
955
1027
|
assert.ok(ttyProjects.stdout.join("").includes(`${E}[2m● ${E}[0m${E}[1m${E}[32m`));
|
|
956
1028
|
const ttySearch = captureIo(repoRoot, undefined, { scan: scanner, isTTY: true });
|
|
957
|
-
assert.equal(await runLiteCli(["search", "mock"], ttySearch.io), 0);
|
|
1029
|
+
assert.equal(await runLiteCli(["search", "mock", "--no-dir"], ttySearch.io), 0);
|
|
958
1030
|
const searchText = ttySearch.stdout.join("");
|
|
959
1031
|
assert.ok(searchText.includes(`${E}[2m- sess:`));
|
|
960
1032
|
assert.ok(searchText.includes(`${E}[1m${E}[32m `));
|
|
961
1033
|
// Non-TTY output stays pure text.
|
|
962
1034
|
const plain = captureIo(repoRoot, undefined, { scan: scanner });
|
|
963
|
-
assert.equal(await runLiteCli(["ls", "sessions", "--all"], plain.io), 0);
|
|
1035
|
+
assert.equal(await runLiteCli(["ls", "sessions", "--all", "--no-dir"], plain.io), 0);
|
|
964
1036
|
assert.ok(!plain.stdout.join("").includes(E));
|
|
965
1037
|
}
|
|
966
1038
|
finally {
|
|
@@ -1003,7 +1075,7 @@ test("Lite CLI renders container storage as an estimated share and omits zero by
|
|
|
1003
1075
|
],
|
|
1004
1076
|
});
|
|
1005
1077
|
const captured = captureIo(repoRoot, undefined, { scan: async () => sharedSnapshot });
|
|
1006
|
-
assert.equal(await runLiteCli(["ls", "sessions", "--all"], captured.io), 0);
|
|
1078
|
+
assert.equal(await runLiteCli(["ls", "sessions", "--all", "--no-dir"], captured.io), 0);
|
|
1007
1079
|
const text = captured.stdout.join("");
|
|
1008
1080
|
assert.ok(text.includes("≈12KB of 10.0MB db"));
|
|
1009
1081
|
assert.ok(!text.includes("· 0B"));
|
|
@@ -1045,7 +1117,7 @@ test("Lite CLI puts the session title after the model and omits prompt-history i
|
|
|
1045
1117
|
sessions: [promptHistory, ...snapshot.data.sessions],
|
|
1046
1118
|
});
|
|
1047
1119
|
const captured = captureIo(repoRoot, undefined, { scan: async () => mixedSnapshot });
|
|
1048
|
-
assert.equal(await runLiteCli(["ls", "sessions", "--all"], captured.io), 0);
|
|
1120
|
+
assert.equal(await runLiteCli(["ls", "sessions", "--all", "--no-dir"], captured.io), 0);
|
|
1049
1121
|
const text = captured.stdout.join("");
|
|
1050
1122
|
const model = target.model?.trim();
|
|
1051
1123
|
assert.ok(model);
|
|
@@ -1081,6 +1153,38 @@ test("Lite CLI JSON search defaults to cwd and --no-dir restores the unscoped sn
|
|
|
1081
1153
|
assert.equal(await runLiteCli(["search", "Review", "--json", "--dir", scoped.working_directory, "--no-dir"], conflict.io), 2);
|
|
1082
1154
|
assert.match(conflict.stderr.join(""), /--no-dir and --dir cannot be used together/);
|
|
1083
1155
|
});
|
|
1156
|
+
test("Lite CLI human collection commands default to cwd and announce the scope", async () => {
|
|
1157
|
+
const snapshot = await getCodexSnapshot();
|
|
1158
|
+
const scanOptions = [];
|
|
1159
|
+
const scanner = async (options) => {
|
|
1160
|
+
scanOptions.push(options);
|
|
1161
|
+
return snapshot;
|
|
1162
|
+
};
|
|
1163
|
+
const human = captureIo(repoRoot, undefined, { scan: scanner });
|
|
1164
|
+
assert.equal(await runLiteCli(["latest"], human.io), 0);
|
|
1165
|
+
assert.equal(scanOptions.at(-1)?.directoryScope, repoRoot);
|
|
1166
|
+
assert.match(human.stderr.join(""), /Filtering sessions whose working directory is under /);
|
|
1167
|
+
assert.match(human.stderr.join(""), /\(current directory\)/);
|
|
1168
|
+
assert.match(human.stderr.join(""), /memory estimate still covers every selected source root/);
|
|
1169
|
+
assert.match(human.stderr.join(""), /Whole-machine listing: --no-dir/);
|
|
1170
|
+
assert.doesNotMatch(human.stdout.join(""), /Filtering sessions whose working directory/);
|
|
1171
|
+
const json = captureIo(repoRoot, undefined, { scan: scanner });
|
|
1172
|
+
assert.equal(await runLiteCli(["latest", "--json"], json.io), 0);
|
|
1173
|
+
assert.equal(scanOptions.at(-1)?.directoryScope, repoRoot);
|
|
1174
|
+
assert.doesNotMatch(json.stderr.join(""), /Filtering sessions whose working directory/);
|
|
1175
|
+
assert.doesNotMatch(json.stderr.join(""), /Whole-machine listing/);
|
|
1176
|
+
const unscoped = captureIo(repoRoot, undefined, { scan: scanner });
|
|
1177
|
+
assert.equal(await runLiteCli(["latest", "--no-dir"], unscoped.io), 0);
|
|
1178
|
+
assert.equal(scanOptions.at(-1)?.directoryScope, undefined);
|
|
1179
|
+
assert.match(unscoped.stderr.join(""), /Listing every selected source on this machine/);
|
|
1180
|
+
assert.match(unscoped.stderr.join(""), /memory estimate still covers every selected source root/);
|
|
1181
|
+
assert.match(unscoped.stderr.join(""), /Bound with --source, --limit-files, or sample/);
|
|
1182
|
+
const exportRun = captureIo(repoRoot, undefined, { scan: scanner });
|
|
1183
|
+
assert.equal(await runLiteCli(["export", "--format", "markdown", "--out", "-"], exportRun.io), 0);
|
|
1184
|
+
assert.equal(scanOptions.at(-1)?.directoryScope, undefined);
|
|
1185
|
+
assert.doesNotMatch(exportRun.stderr.join(""), /Filtering sessions whose working directory/);
|
|
1186
|
+
assert.doesNotMatch(exportRun.stderr.join(""), /Listing every selected source on this machine/);
|
|
1187
|
+
});
|
|
1084
1188
|
test("Lite CLI query latest and list count the same unit they return", async () => {
|
|
1085
1189
|
const snapshot = await getCodexSnapshot();
|
|
1086
1190
|
const request = JSON.stringify({
|
|
@@ -1235,6 +1339,399 @@ test("Lite shell JSON-lines keeps the snapshot when refresh fails and uses struc
|
|
|
1235
1339
|
assert.equal(startupError.schema, "cchistory-lite-error/v1");
|
|
1236
1340
|
assert.equal(startupError.error.code, "scan_failed");
|
|
1237
1341
|
});
|
|
1342
|
+
test("Lite CLI scan guard refuses a scan whose estimate risks the machine, teaches the bounds, and bends to the kill-switch", async () => {
|
|
1343
|
+
const tempHome = await mkdtemp(path.join(os.tmpdir(), "cchistory-lite-guard-cli-"));
|
|
1344
|
+
const hugeRoot = path.join(tempHome, "huge-codex");
|
|
1345
|
+
try {
|
|
1346
|
+
await cp(codexRoot, hugeRoot, { recursive: true });
|
|
1347
|
+
// Sparse: reports 256 GiB without allocating real bytes.
|
|
1348
|
+
const hugeFile = path.join(hugeRoot, "huge.bin");
|
|
1349
|
+
await writeFile(hugeFile, "");
|
|
1350
|
+
await truncate(hugeFile, 256 * 1024 ** 3);
|
|
1351
|
+
const sourceArgs = ["--source-root", `codex=${hugeRoot}`, "--source", "codex", "--safe"];
|
|
1352
|
+
const refused = captureIo(tempHome);
|
|
1353
|
+
assert.equal(await runLiteCli(["sources", ...sourceArgs], refused.io), 1);
|
|
1354
|
+
assert.equal(refused.stdout.join(""), "");
|
|
1355
|
+
const message = refused.stderr.join("");
|
|
1356
|
+
assert.match(message, /Refusing to scan/);
|
|
1357
|
+
assert.match(message, /Selected source roots/);
|
|
1358
|
+
assert.match(message, /codex/);
|
|
1359
|
+
assert.match(message, /does not shrink source bytes/);
|
|
1360
|
+
assert.match(message, /--source <slot>/);
|
|
1361
|
+
assert.match(message, /--limit-files/);
|
|
1362
|
+
assert.match(message, /sample/);
|
|
1363
|
+
assert.match(message, /ls sources --limit-files 1/);
|
|
1364
|
+
assert.match(message, /shell/);
|
|
1365
|
+
assert.match(message, /query/);
|
|
1366
|
+
assert.match(message, /CCHISTORY_SCAN_GUARD=0/);
|
|
1367
|
+
assert.doesNotMatch(message, /--dir is already on/);
|
|
1368
|
+
const refusedJson = captureIo(tempHome);
|
|
1369
|
+
assert.equal(await runLiteCli(["sources", "--json", ...sourceArgs], refusedJson.io), 1);
|
|
1370
|
+
assert.equal(refusedJson.stdout.join(""), "");
|
|
1371
|
+
const errorPayload = JSON.parse(refusedJson.stderr.join(""));
|
|
1372
|
+
assert.equal(errorPayload.schema, "cchistory-lite-error/v1");
|
|
1373
|
+
assert.equal(errorPayload.error.code, "scan_guard_refused");
|
|
1374
|
+
assert.match(errorPayload.error.message, /Refusing to scan/);
|
|
1375
|
+
// Bounded probes bypass the lock and the estimate even on the same root.
|
|
1376
|
+
const sampled = captureIo(tempHome);
|
|
1377
|
+
assert.equal(await runLiteCli(["sample", "1", ...sourceArgs, "--no-dir"], sampled.io), 0, sampled.stderr.join(""));
|
|
1378
|
+
const shown = captureIo(tempHome);
|
|
1379
|
+
assert.equal(await runLiteCli(["show", "session", "sess:codex:019ce4fd-8290-7501-afc4-0e9486733614", ...sourceArgs], shown.io), 0, shown.stderr.join(""));
|
|
1380
|
+
process.env.CCHISTORY_SCAN_GUARD = "0";
|
|
1381
|
+
try {
|
|
1382
|
+
const allowed = captureIo(tempHome);
|
|
1383
|
+
assert.equal(await runLiteCli(["sources", ...sourceArgs], allowed.io), 0, allowed.stderr.join(""));
|
|
1384
|
+
}
|
|
1385
|
+
finally {
|
|
1386
|
+
delete process.env.CCHISTORY_SCAN_GUARD;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
finally {
|
|
1390
|
+
await rm(tempHome, { recursive: true, force: true });
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
test("Lite CLI maps scan guard refusals and aborts to exit 1 with distinct structured codes", async () => {
|
|
1394
|
+
const tempHome = await mkdtemp(path.join(os.tmpdir(), "cchistory-lite-guard-errors-"));
|
|
1395
|
+
try {
|
|
1396
|
+
const aborted = captureIo(tempHome, undefined, {
|
|
1397
|
+
scan: async () => {
|
|
1398
|
+
throw new ScanGuardAbortedError({ availableBytes: 300 * 1024 ** 2, floorBytes: 512 * 1024 ** 2 });
|
|
1399
|
+
},
|
|
1400
|
+
});
|
|
1401
|
+
assert.equal(await runLiteCli(["sources", "--json"], aborted.io), 1);
|
|
1402
|
+
assert.equal(aborted.stdout.join(""), "");
|
|
1403
|
+
const abortPayload = JSON.parse(aborted.stderr.join(""));
|
|
1404
|
+
assert.equal(abortPayload.schema, "cchistory-lite-error/v1");
|
|
1405
|
+
assert.equal(abortPayload.error.code, "scan_guard_aborted");
|
|
1406
|
+
const refused = captureIo(tempHome, undefined, {
|
|
1407
|
+
scan: async () => {
|
|
1408
|
+
throw new ScanGuardRefusedError({
|
|
1409
|
+
reason: "scan_in_progress",
|
|
1410
|
+
holder: { pid: 4321, startedAt: "2026-08-30T00:00:00.000Z" },
|
|
1411
|
+
waitedMs: 30_000,
|
|
1412
|
+
});
|
|
1413
|
+
},
|
|
1414
|
+
});
|
|
1415
|
+
assert.equal(await runLiteCli(["latest", "--json"], refused.io), 1);
|
|
1416
|
+
assert.equal(refused.stdout.join(""), "");
|
|
1417
|
+
const refusalPayload = JSON.parse(refused.stderr.join(""));
|
|
1418
|
+
assert.equal(refusalPayload.error.code, "scan_guard_refused");
|
|
1419
|
+
assert.match(refusalPayload.error.message, /another cchistory-lite scan/);
|
|
1420
|
+
const scopedRefuse = captureIo(tempHome, undefined, {
|
|
1421
|
+
scan: async () => {
|
|
1422
|
+
throw new ScanGuardRefusedError({
|
|
1423
|
+
reason: "estimated_memory",
|
|
1424
|
+
assessment: {
|
|
1425
|
+
status: "refuse",
|
|
1426
|
+
profile: "light",
|
|
1427
|
+
estimatedBytes: 17 * 1024 ** 3,
|
|
1428
|
+
availableBytes: 1.3 * 1024 ** 3,
|
|
1429
|
+
scannedBytes: 4.3 * 1024 ** 3,
|
|
1430
|
+
detail: "synthetic",
|
|
1431
|
+
roots: [{ path: "/root/.claude/projects", bytes: 4.3 * 1024 ** 3, slot_id: "claude_code" }],
|
|
1432
|
+
},
|
|
1433
|
+
});
|
|
1434
|
+
},
|
|
1435
|
+
});
|
|
1436
|
+
assert.equal(await runLiteCli(["latest", "sessions", "40"], scopedRefuse.io), 1);
|
|
1437
|
+
assert.match(scopedRefuse.stderr.join(""), /--dir is already on for this command/);
|
|
1438
|
+
assert.match(scopedRefuse.stderr.join(""), /does not shrink source bytes/);
|
|
1439
|
+
assert.match(scopedRefuse.stderr.join(""), /claude_code/);
|
|
1440
|
+
// Human mode prints the plain message, not the JSON envelope.
|
|
1441
|
+
const human = captureIo(tempHome, undefined, {
|
|
1442
|
+
scan: async () => {
|
|
1443
|
+
throw new ScanGuardRefusedError({ reason: "scan_in_progress", holder: { pid: 4321 }, waitedMs: 30_000 });
|
|
1444
|
+
},
|
|
1445
|
+
});
|
|
1446
|
+
assert.equal(await runLiteCli(["sources"], human.io), 1);
|
|
1447
|
+
assert.match(human.stderr.join(""), /Refusing to scan/);
|
|
1448
|
+
assert.throws(() => JSON.parse(human.stderr.join("")));
|
|
1449
|
+
}
|
|
1450
|
+
finally {
|
|
1451
|
+
await rm(tempHome, { recursive: true, force: true });
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
test("Lite CLI prints a one-line scan guard warning on stderr and proceeds", async () => {
|
|
1455
|
+
const tempHome = await mkdtemp(path.join(os.tmpdir(), "cchistory-lite-guard-warn-"));
|
|
1456
|
+
try {
|
|
1457
|
+
const warned = captureIo(tempHome, undefined, {
|
|
1458
|
+
scan: async (options) => {
|
|
1459
|
+
options.onScanGuardEvent?.({
|
|
1460
|
+
type: "warn",
|
|
1461
|
+
assessment: {
|
|
1462
|
+
status: "warn",
|
|
1463
|
+
profile: "light",
|
|
1464
|
+
estimatedBytes: 600,
|
|
1465
|
+
availableBytes: 1000,
|
|
1466
|
+
scannedBytes: 150,
|
|
1467
|
+
detail: "synthetic",
|
|
1468
|
+
},
|
|
1469
|
+
});
|
|
1470
|
+
return getCodexSnapshot();
|
|
1471
|
+
},
|
|
1472
|
+
});
|
|
1473
|
+
assert.equal(await runLiteCli(["sources", "--json"], warned.io), 0);
|
|
1474
|
+
assert.match(warned.stderr.join(""), /Scan guard warning/);
|
|
1475
|
+
assert.match(warned.stderr.join(""), /CCHISTORY_SCAN_GUARD=0/);
|
|
1476
|
+
assert.equal(JSON.parse(warned.stdout.join("")).kind, "sources");
|
|
1477
|
+
}
|
|
1478
|
+
finally {
|
|
1479
|
+
await rm(tempHome, { recursive: true, force: true });
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
test("Lite CLI agent prints the machine-readable contract without scanning", async () => {
|
|
1483
|
+
const captured = captureIo(repoRoot, undefined, {
|
|
1484
|
+
scan: async () => {
|
|
1485
|
+
throw new Error("agent must not scan");
|
|
1486
|
+
},
|
|
1487
|
+
});
|
|
1488
|
+
assert.equal(await runLiteCli(["agent"], captured.io), 0);
|
|
1489
|
+
assert.equal(captured.stderr.join(""), "");
|
|
1490
|
+
const contract = JSON.parse(captured.stdout.join(""));
|
|
1491
|
+
assert.equal(contract.schema, "cchistory-lite-agent/v1");
|
|
1492
|
+
assert.equal(contract.kind, "agent_contract");
|
|
1493
|
+
assert.equal(contract.cli.name, "cchistory-lite");
|
|
1494
|
+
assert.match(contract.cli.version, /^\d+\.\d+\.\d+/u);
|
|
1495
|
+
const commandNames = ["sources", "ls", "latest", "sample", "tree", "search", "show", "stats", "query", "shell", "export", "tui", "help", "agent"];
|
|
1496
|
+
assert.deepEqual(Object.keys(contract.commands).sort(), [...commandNames].sort());
|
|
1497
|
+
for (const name of commandNames) {
|
|
1498
|
+
const command = contract.commands[name];
|
|
1499
|
+
assert.equal(command.name, name);
|
|
1500
|
+
assert.ok(command.summary.length > 0, `${name} is missing a summary`);
|
|
1501
|
+
assert.ok(command.usage.startsWith(`cchistory-lite ${name}`), `${name} usage must start with the command line`);
|
|
1502
|
+
assert.ok(Array.isArray(command.flags), `${name} flags must be an array`);
|
|
1503
|
+
}
|
|
1504
|
+
assert.deepEqual(contract.exit_codes.map((entry) => entry.code).sort(), [0, 1, 2]);
|
|
1505
|
+
const envNames = contract.env.map((entry) => entry.name);
|
|
1506
|
+
for (const name of ["NO_COLOR", "FORCE_COLOR", "CCHISTORY_SHOW_RUNTIME_WARNINGS", "CCHISTORY_SCAN_GUARD"]) {
|
|
1507
|
+
assert.ok(envNames.includes(name), `contract env omits ${name}`);
|
|
1508
|
+
}
|
|
1509
|
+
// The documented guard numbers are the runtime constants, not copies.
|
|
1510
|
+
const guard = contract.cost_model.scan_guard;
|
|
1511
|
+
assert.equal(guard.light_scan_memory_multiplier, LIGHT_SCAN_MEMORY_MULTIPLIER);
|
|
1512
|
+
assert.equal(guard.full_scan_memory_multiplier, FULL_SCAN_MEMORY_MULTIPLIER);
|
|
1513
|
+
assert.equal(guard.warn_available_fraction, SCAN_GUARD_WARN_AVAILABLE_FRACTION);
|
|
1514
|
+
assert.equal(guard.refuse_available_fraction, SCAN_GUARD_REFUSE_AVAILABLE_FRACTION);
|
|
1515
|
+
assert.equal(guard.lock_wait_ms, SCAN_LOCK_WAIT_MS);
|
|
1516
|
+
assert.equal(guard.watchdog_floor.min_floor_bytes, SCAN_WATCHDOG_MIN_FLOOR_BYTES);
|
|
1517
|
+
assert.equal(guard.watchdog_floor.total_floor_fraction, SCAN_WATCHDOG_TOTAL_FLOOR_FRACTION);
|
|
1518
|
+
assert.deepEqual(guard.kill_switch, { env: "CCHISTORY_SCAN_GUARD", value: "0" });
|
|
1519
|
+
assert.deepEqual([...guard.error_codes].sort(), ["scan_guard_aborted", "scan_guard_refused"]);
|
|
1520
|
+
assert.equal(contract.cost_model.heap_ceiling.min_old_space_mib, MIN_OLD_SPACE_MIB);
|
|
1521
|
+
assert.equal(contract.cost_model.heap_ceiling.max_old_space_mib, MAX_OLD_SPACE_MIB);
|
|
1522
|
+
assert.equal(contract.trust_model.content_trust, "untrusted_history");
|
|
1523
|
+
const schemaIds = contract.output_schemas.map((entry) => entry.id);
|
|
1524
|
+
for (const id of [
|
|
1525
|
+
"cchistory-lite/v2",
|
|
1526
|
+
"cchistory-lite-canonical/v1",
|
|
1527
|
+
"cchistory-lite-query/v2",
|
|
1528
|
+
"cchistory-lite-query-result/v2",
|
|
1529
|
+
"cchistory-lite-error/v1",
|
|
1530
|
+
"cchistory-lite-export/v1",
|
|
1531
|
+
"cchistory-lite-agent/v1",
|
|
1532
|
+
]) {
|
|
1533
|
+
assert.ok(schemaIds.includes(id), `contract output_schemas omits ${id}`);
|
|
1534
|
+
}
|
|
1535
|
+
assert.equal(contract.docs.agent_guide, "docs/guide/for-agents.md");
|
|
1536
|
+
assert.equal(contract.docs.cli_guide, "docs/guide/lite.md");
|
|
1537
|
+
assert.equal(contract.docs.skill, "skills/using-cchistory-lite/SKILL.md");
|
|
1538
|
+
});
|
|
1539
|
+
test("Lite CLI agent contract satisfies its shipped JSON schema structurally", async () => {
|
|
1540
|
+
const captured = captureIo(repoRoot, undefined, {
|
|
1541
|
+
scan: async () => {
|
|
1542
|
+
throw new Error("agent must not scan");
|
|
1543
|
+
},
|
|
1544
|
+
});
|
|
1545
|
+
assert.equal(await runLiteCli(["agent"], captured.io), 0);
|
|
1546
|
+
const contract = JSON.parse(captured.stdout.join(""));
|
|
1547
|
+
const schema = JSON.parse(await readFile(path.join(repoRoot, "schemas", "cchistory-lite-agent-v1.schema.json"), "utf8"));
|
|
1548
|
+
for (const key of schema.required) {
|
|
1549
|
+
assert.ok(key in contract, `contract is missing required key ${key}`);
|
|
1550
|
+
}
|
|
1551
|
+
assert.equal(contract.schema, schema.properties.schema.const);
|
|
1552
|
+
assert.equal(contract.kind, schema.properties.kind.const);
|
|
1553
|
+
const commands = contract.commands;
|
|
1554
|
+
assert.deepEqual(Object.keys(commands).sort(), [...schema.properties.commands.required].sort());
|
|
1555
|
+
for (const [name, command] of Object.entries(commands)) {
|
|
1556
|
+
for (const key of schema.$defs.command.required) {
|
|
1557
|
+
assert.ok(key in command, `command ${name} is missing ${key}`);
|
|
1558
|
+
}
|
|
1559
|
+
for (const flag of command.flags) {
|
|
1560
|
+
assert.ok(schema.$defs.flag.properties.kind.enum.includes(flag.kind), `command ${name} has a flag with unknown kind ${flag.kind}`);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
const exitCodes = contract.exit_codes.map((entry) => entry.code);
|
|
1564
|
+
const allowedCodes = schema.properties.exit_codes.items.properties.code.enum;
|
|
1565
|
+
assert.deepEqual(exitCodes.sort(), [...allowedCodes].sort());
|
|
1566
|
+
assert.equal(contract.trust_model.content_trust, schema.properties.trust_model.properties.content_trust.const);
|
|
1567
|
+
const docs = contract.docs;
|
|
1568
|
+
assert.equal(docs.agent_guide, schema.properties.docs.properties.agent_guide.const);
|
|
1569
|
+
assert.equal(docs.cli_guide, schema.properties.docs.properties.cli_guide.const);
|
|
1570
|
+
assert.equal(docs.skill, schema.properties.docs.properties.skill.const);
|
|
1571
|
+
});
|
|
1572
|
+
test("Lite CLI agent contract flags match the parser in both directions", async () => {
|
|
1573
|
+
const snapshot = await getCodexSnapshot();
|
|
1574
|
+
const project = snapshot.listProjects()[0];
|
|
1575
|
+
const session = snapshot.listResolvedSessions()[0];
|
|
1576
|
+
assert.ok(project && session);
|
|
1577
|
+
const contract = buildAgentContract("0.0.0-test");
|
|
1578
|
+
const globalFlags = new Set(contract.global_flags.map((flag) => flag.name));
|
|
1579
|
+
const universe = new Set(globalFlags);
|
|
1580
|
+
for (const command of Object.values(contract.commands)) {
|
|
1581
|
+
for (const flag of command.flags)
|
|
1582
|
+
universe.add(flag.name);
|
|
1583
|
+
}
|
|
1584
|
+
// The parser's full flag vocabulary; like the help test's knownFlags, drift
|
|
1585
|
+
// here must be reflected in the contract before this audit can pass.
|
|
1586
|
+
const parserFlags = [
|
|
1587
|
+
"--source-root", "--source", "--limit-files", "--limit", "--offset", "--project", "--by",
|
|
1588
|
+
"--format", "--out", "--dir", "--request", "--safe", "--json", "--all", "--no-dir",
|
|
1589
|
+
"--help", "--version",
|
|
1590
|
+
];
|
|
1591
|
+
assert.deepEqual([...universe].sort(), [...parserFlags].sort());
|
|
1592
|
+
const tails = {
|
|
1593
|
+
sources: [],
|
|
1594
|
+
ls: ["sessions"],
|
|
1595
|
+
latest: ["sessions", "1"],
|
|
1596
|
+
sample: ["1"],
|
|
1597
|
+
tree: ["projects"],
|
|
1598
|
+
search: ["mock"],
|
|
1599
|
+
show: ["session", session.id],
|
|
1600
|
+
stats: [],
|
|
1601
|
+
query: ["--request", "-"],
|
|
1602
|
+
shell: [],
|
|
1603
|
+
export: ["--format", "jsonl", "--out", "-"],
|
|
1604
|
+
tui: [],
|
|
1605
|
+
help: [],
|
|
1606
|
+
agent: [],
|
|
1607
|
+
};
|
|
1608
|
+
const flagArgs = (name) => {
|
|
1609
|
+
switch (name) {
|
|
1610
|
+
case "--source-root": return [name, `codex=${codexRoot}`];
|
|
1611
|
+
case "--source": return [name, "codex"];
|
|
1612
|
+
case "--limit-files": return [name, "4"];
|
|
1613
|
+
case "--limit": return [name, "1"];
|
|
1614
|
+
case "--offset": return [name, "0"];
|
|
1615
|
+
case "--project": return [name, project.project_id];
|
|
1616
|
+
case "--by": return [name, "source"];
|
|
1617
|
+
case "--format": return [name, "jsonl"];
|
|
1618
|
+
case "--out": return [name, "-"];
|
|
1619
|
+
case "--dir": return [name, repoRoot];
|
|
1620
|
+
case "--request": return [name, "-"];
|
|
1621
|
+
default: return [name];
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
const run = async (argv) => {
|
|
1625
|
+
const captured = captureIo(repoRoot, async () => 0, {
|
|
1626
|
+
scan: async () => snapshot,
|
|
1627
|
+
readStdin: async () => `${JSON.stringify({
|
|
1628
|
+
schema: "cchistory-lite-query/v2",
|
|
1629
|
+
operations: [{ id: "s", kind: "list", collection: "sessions", limit: 1 }],
|
|
1630
|
+
})}\n`,
|
|
1631
|
+
readLine: async () => null,
|
|
1632
|
+
});
|
|
1633
|
+
return runLiteCli(argv, captured.io);
|
|
1634
|
+
};
|
|
1635
|
+
for (const [name, command] of Object.entries(contract.commands)) {
|
|
1636
|
+
const tail = tails[name];
|
|
1637
|
+
if (name === "help") {
|
|
1638
|
+
// help renders before option validation, so every known flag is accepted
|
|
1639
|
+
// and ignored; the rejection direction does not apply to it.
|
|
1640
|
+
for (const flag of universe) {
|
|
1641
|
+
assert.equal(await run([name, ...tail, ...flagArgs(flag)]), 0, `help must accept ${flag}`);
|
|
1642
|
+
}
|
|
1643
|
+
assert.equal(await run([name, ...tail, "--json=canonical"]), 0, "help must accept --json=canonical");
|
|
1644
|
+
continue;
|
|
1645
|
+
}
|
|
1646
|
+
const accepted = new Set([...globalFlags, ...command.flags.map((flag) => flag.name)]);
|
|
1647
|
+
for (const flag of universe) {
|
|
1648
|
+
const argv = tail.includes(flag) ? [name, ...tail] : [name, ...tail, ...flagArgs(flag)];
|
|
1649
|
+
const code = await run(argv);
|
|
1650
|
+
if (accepted.has(flag)) {
|
|
1651
|
+
assert.equal(code, 0, `${name} must accept ${flag} (argv: ${argv.join(" ")})`);
|
|
1652
|
+
}
|
|
1653
|
+
else {
|
|
1654
|
+
assert.equal(code, 2, `${name} must reject ${flag} (argv: ${argv.join(" ")})`);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
const canonicalAccepted = command.flags.some((flag) => flag.name === "--json" && flag.values?.includes("canonical"));
|
|
1658
|
+
const canonicalArgv = [name, ...tail, "--json=canonical"];
|
|
1659
|
+
assert.equal(await run(canonicalArgv), canonicalAccepted ? 0 : 2, `${name} ${canonicalAccepted ? "must accept" : "must reject"} --json=canonical`);
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
test("Lite CLI agent skill and guide print the shipped docs", async () => {
|
|
1663
|
+
const noScan = {
|
|
1664
|
+
scan: async () => {
|
|
1665
|
+
throw new Error("agent must not scan");
|
|
1666
|
+
},
|
|
1667
|
+
};
|
|
1668
|
+
const skill = captureIo(repoRoot, undefined, noScan);
|
|
1669
|
+
assert.equal(await runLiteCli(["agent", "skill"], skill.io), 0);
|
|
1670
|
+
const skillDoc = await readFile(path.join(repoRoot, "skills", "using-cchistory-lite", "SKILL.md"), "utf8");
|
|
1671
|
+
assert.equal(skill.stdout.join(""), skillDoc);
|
|
1672
|
+
const guide = captureIo(repoRoot, undefined, noScan);
|
|
1673
|
+
assert.equal(await runLiteCli(["agent", "guide"], guide.io), 0);
|
|
1674
|
+
const guideDoc = await readFile(path.join(repoRoot, "docs", "guide", "for-agents.md"), "utf8");
|
|
1675
|
+
assert.equal(guide.stdout.join(""), guideDoc);
|
|
1676
|
+
const unknown = captureIo(repoRoot, undefined, noScan);
|
|
1677
|
+
assert.equal(await runLiteCli(["agent", "bogus"], unknown.io), 2);
|
|
1678
|
+
const unknownError = JSON.parse(unknown.stderr.join(""));
|
|
1679
|
+
assert.equal(unknownError.schema, "cchistory-lite-error/v1");
|
|
1680
|
+
assert.equal(unknownError.error.code, "invalid_usage");
|
|
1681
|
+
const extra = captureIo(repoRoot, undefined, noScan);
|
|
1682
|
+
assert.equal(await runLiteCli(["agent", "skill", "extra"], extra.io), 2);
|
|
1683
|
+
});
|
|
1684
|
+
test("Lite CLI help leads with the agent path and prints per-command contracts", async () => {
|
|
1685
|
+
const captured = captureIo(repoRoot);
|
|
1686
|
+
assert.equal(await runLiteCli(["help"], captured.io), 0);
|
|
1687
|
+
const help = captured.stdout.join("");
|
|
1688
|
+
const head = help.split("\n").slice(0, 20).join("\n");
|
|
1689
|
+
assert.match(head, /cchistory-lite agent/);
|
|
1690
|
+
assert.match(head, /agent skill/);
|
|
1691
|
+
assert.match(head, /agent guide/);
|
|
1692
|
+
assert.match(head, /sample --json/);
|
|
1693
|
+
assert.match(head, /--source <slot>/);
|
|
1694
|
+
assert.match(head, /ls sources --limit-files 1/);
|
|
1695
|
+
assert.match(head, /does not shrink source bytes/);
|
|
1696
|
+
assert.match(head, /Do not discard stderr/);
|
|
1697
|
+
assert.match(help, /cchistory-lite agent \[skill\|guide\]/);
|
|
1698
|
+
const sourcesHelp = captureIo(repoRoot);
|
|
1699
|
+
assert.equal(await runLiteCli(["help", "sources"], sourcesHelp.io), 0);
|
|
1700
|
+
const sourcesText = sourcesHelp.stdout.join("");
|
|
1701
|
+
assert.match(sourcesText, /List resolved source adapters/);
|
|
1702
|
+
assert.match(sourcesText, /cchistory-lite sources/);
|
|
1703
|
+
assert.match(sourcesText, /no --dir\/--no-dir/);
|
|
1704
|
+
assert.doesNotMatch(sourcesText, /through the command synopsis below/);
|
|
1705
|
+
const flagHelp = captureIo(repoRoot);
|
|
1706
|
+
assert.equal(await runLiteCli(["sources", "--help"], flagHelp.io), 0);
|
|
1707
|
+
assert.equal(flagHelp.stdout.join(""), sourcesText);
|
|
1708
|
+
const lsHelp = captureIo(repoRoot);
|
|
1709
|
+
assert.equal(await runLiteCli(["help", "ls"], lsHelp.io), 0);
|
|
1710
|
+
assert.match(lsHelp.stdout.join(""), /ls sources always lists every selected adapter/);
|
|
1711
|
+
assert.match(lsHelp.stdout.join(""), /bound it with --limit-files/);
|
|
1712
|
+
const unknownHelp = captureIo(repoRoot);
|
|
1713
|
+
assert.equal(await runLiteCli(["help", "bogus"], unknownHelp.io), 0);
|
|
1714
|
+
assert.match(unknownHelp.stdout.join(""), /Unknown Lite command: bogus/);
|
|
1715
|
+
assert.match(unknownHelp.stdout.join(""), /Known commands:/);
|
|
1716
|
+
});
|
|
1717
|
+
test("Lite CLI dead-end flags and unknown adapters teach the next command", async () => {
|
|
1718
|
+
const noScan = {
|
|
1719
|
+
scan: async () => {
|
|
1720
|
+
throw new Error("usage errors must not scan");
|
|
1721
|
+
},
|
|
1722
|
+
};
|
|
1723
|
+
const sourcesNoDir = captureIo(repoRoot, undefined, noScan);
|
|
1724
|
+
assert.equal(await runLiteCli(["sources", "--no-dir"], sourcesNoDir.io), 2);
|
|
1725
|
+
assert.match(sourcesNoDir.stderr.join(""), /--no-dir is not valid for sources/);
|
|
1726
|
+
assert.match(sourcesNoDir.stderr.join(""), /Drop --no-dir and pass --limit-files/);
|
|
1727
|
+
assert.match(sourcesNoDir.stderr.join(""), /ls sources --limit-files 1/);
|
|
1728
|
+
const unknown = captureIo(repoRoot);
|
|
1729
|
+
assert.equal(await runLiteCli(["latest", "--source", "claude"], unknown.io), 1);
|
|
1730
|
+
assert.match(unknown.stderr.join(""), /Unknown Lite source adapter: claude/);
|
|
1731
|
+
assert.match(unknown.stderr.join(""), /Registered slots:/);
|
|
1732
|
+
assert.match(unknown.stderr.join(""), /claude_code/);
|
|
1733
|
+
assert.match(unknown.stderr.join(""), /not a single project folder/);
|
|
1734
|
+
});
|
|
1238
1735
|
function captureIo(cwd, spawnTui, overrides = {}) {
|
|
1239
1736
|
const stdout = [];
|
|
1240
1737
|
const stderr = [];
|