@codelia/cli 0.1.82 → 0.1.84
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/index.cjs +70 -8
- package/dist/index.js +74 -8
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ var TOP_LEVEL_HELP_TEXT = [
|
|
|
34
34
|
"",
|
|
35
35
|
"Commands:",
|
|
36
36
|
" mcp ... Manage MCP servers and auth",
|
|
37
|
+
" session ... List, pin, archive, or clean up session run logs",
|
|
37
38
|
"",
|
|
38
39
|
"Runtime options:",
|
|
39
40
|
" --approval-mode <minimal|trusted|full-access>",
|
|
@@ -66,6 +67,7 @@ var hasPromptFlag = (args2) => {
|
|
|
66
67
|
return false;
|
|
67
68
|
};
|
|
68
69
|
var resolveTopLevelAction = (args2) => {
|
|
70
|
+
if (args2[0] === "session") return "session";
|
|
69
71
|
if (args2[0] === "mcp") {
|
|
70
72
|
return "mcp";
|
|
71
73
|
}
|
|
@@ -836,12 +838,59 @@ var runMcpCommand = async (values) => {
|
|
|
836
838
|
return 1;
|
|
837
839
|
};
|
|
838
840
|
|
|
841
|
+
// src/commands/session.ts
|
|
842
|
+
var import_storage3 = require("@codelia/storage");
|
|
843
|
+
var HELP = "usage: codelia session list | pin|unpin|archive|unarchive <session_id> | cleanup\nArchive removes diagnostics and compresses unpinned run events, including legacy gzip. Original messages, active context and reference data remain; diagnostic dumps may expire.";
|
|
844
|
+
async function runSessionCommand(args2) {
|
|
845
|
+
const [action, sessionId, extra] = args2;
|
|
846
|
+
if (!action || action === "--help" || action === "help") {
|
|
847
|
+
console.log(HELP);
|
|
848
|
+
return 0;
|
|
849
|
+
}
|
|
850
|
+
if (action === "list" || action === "cleanup" ? sessionId !== void 0 : !["pin", "unpin", "archive", "unarchive"].includes(action) || !sessionId || extra !== void 0 || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(sessionId)) {
|
|
851
|
+
console.error(HELP);
|
|
852
|
+
return 1;
|
|
853
|
+
}
|
|
854
|
+
const paths = (0, import_storage3.resolveStoragePaths)();
|
|
855
|
+
const sessions = new import_storage3.SessionStateStoreImpl({ paths });
|
|
856
|
+
try {
|
|
857
|
+
if (action === "list") {
|
|
858
|
+
for (const session2 of (await sessions.list()).sort(
|
|
859
|
+
(a, b) => b.updated_at.localeCompare(a.updated_at)
|
|
860
|
+
))
|
|
861
|
+
console.log(
|
|
862
|
+
`${session2.session_id} ${session2.updated_at} ${session2.pinned ? "pinned" : "unpinned"} ${session2.archived_at ? "archived" : "active"}`
|
|
863
|
+
);
|
|
864
|
+
return 0;
|
|
865
|
+
}
|
|
866
|
+
if (action === "cleanup") {
|
|
867
|
+
console.log(JSON.stringify(await (0, import_storage3.cleanupRunLogs)({ paths, sessions })));
|
|
868
|
+
return 0;
|
|
869
|
+
}
|
|
870
|
+
if (!sessionId) return 1;
|
|
871
|
+
const patch = action === "pin" || action === "unpin" ? { pinned: action === "pin" } : { archived: action === "archive" };
|
|
872
|
+
const session = await sessions.updateMetadata(sessionId, patch);
|
|
873
|
+
console.log(JSON.stringify(session));
|
|
874
|
+
if (!session.pinned && action !== "unarchive")
|
|
875
|
+
console.log(
|
|
876
|
+
JSON.stringify(await (0, import_storage3.cleanupRunLogs)({ paths, sessions, sessionId }))
|
|
877
|
+
);
|
|
878
|
+
return 0;
|
|
879
|
+
} catch (error) {
|
|
880
|
+
console.error(
|
|
881
|
+
`Session command failed: ${error instanceof Error ? error.message : String(error)}`
|
|
882
|
+
);
|
|
883
|
+
return 1;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
839
887
|
// src/prompt-mode.ts
|
|
840
888
|
var import_node_child_process3 = require("child_process");
|
|
841
889
|
|
|
842
890
|
// src/atif.ts
|
|
843
891
|
var import_promises = require("fs/promises");
|
|
844
892
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
893
|
+
var import_storage4 = require("@codelia/storage");
|
|
845
894
|
var asRecord = (value) => typeof value === "object" && value !== null ? value : null;
|
|
846
895
|
var asString = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
847
896
|
var stringifyContent = (value) => {
|
|
@@ -1007,9 +1056,14 @@ var sessionRecordsToAtif = (records, runId) => {
|
|
|
1007
1056
|
extra: { source_record: "fallback" }
|
|
1008
1057
|
});
|
|
1009
1058
|
}
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1012
|
-
|
|
1059
|
+
const compactUsage = records.filter((record) => record.type === "llm.usage");
|
|
1060
|
+
const compactSequences = new Set(compactUsage.map((record) => record.seq));
|
|
1061
|
+
const usage = extractUsageMetrics([
|
|
1062
|
+
...compactUsage,
|
|
1063
|
+
...records.filter(
|
|
1064
|
+
(record) => record.type === "llm.response" && !compactSequences.has(record.seq)
|
|
1065
|
+
)
|
|
1066
|
+
]);
|
|
1013
1067
|
return {
|
|
1014
1068
|
schema_version: "ATIF-v1.6",
|
|
1015
1069
|
session_id: extractSessionId(header, runStart, runId),
|
|
@@ -1041,7 +1095,11 @@ var parseSessionJsonl = (raw) => {
|
|
|
1041
1095
|
}
|
|
1042
1096
|
return out;
|
|
1043
1097
|
};
|
|
1044
|
-
var readSessionJsonl = async (filePath) =>
|
|
1098
|
+
var readSessionJsonl = async (filePath) => {
|
|
1099
|
+
const lines = [];
|
|
1100
|
+
for await (const line of (0, import_storage4.readRunLogLines)(filePath)) lines.push(line);
|
|
1101
|
+
return parseSessionJsonl(lines.join("\n"));
|
|
1102
|
+
};
|
|
1045
1103
|
var writeAtifFromSessionJsonl = async ({
|
|
1046
1104
|
sessionLogPath,
|
|
1047
1105
|
runId,
|
|
@@ -1062,10 +1120,10 @@ var import_node_child_process2 = require("child_process");
|
|
|
1062
1120
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
1063
1121
|
var import_node_module = require("module");
|
|
1064
1122
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
1065
|
-
var
|
|
1123
|
+
var import_storage5 = require("@codelia/storage");
|
|
1066
1124
|
|
|
1067
1125
|
// src/version.ts
|
|
1068
|
-
var CLI_VERSION = "0.1.
|
|
1126
|
+
var CLI_VERSION = "0.1.84".trim().length > 0 ? "0.1.84" : "0.0.0";
|
|
1069
1127
|
|
|
1070
1128
|
// src/tui/launcher.ts
|
|
1071
1129
|
var resolveTuiBinaryName = (platform) => platform === "win32" ? "codelia-tui.exe" : "codelia-tui";
|
|
@@ -1089,8 +1147,8 @@ var isExecutable = (candidate) => {
|
|
|
1089
1147
|
};
|
|
1090
1148
|
var initStorage = async () => {
|
|
1091
1149
|
try {
|
|
1092
|
-
const paths = (0,
|
|
1093
|
-
await (0,
|
|
1150
|
+
const paths = (0, import_storage5.resolveStoragePaths)();
|
|
1151
|
+
await (0, import_storage5.ensureStorageDirs)(paths);
|
|
1094
1152
|
} catch (error) {
|
|
1095
1153
|
console.warn(
|
|
1096
1154
|
`Failed to initialize storage directories: ${describeError3(error)}`
|
|
@@ -1674,6 +1732,10 @@ var main = async () => {
|
|
|
1674
1732
|
process.exitCode = exitCode;
|
|
1675
1733
|
return;
|
|
1676
1734
|
}
|
|
1735
|
+
case "session": {
|
|
1736
|
+
process.exitCode = await runSessionCommand(args.slice(1));
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1677
1739
|
case "prompt": {
|
|
1678
1740
|
const prompt = validatePromptText(resolvePromptText(args));
|
|
1679
1741
|
const approvalMode = resolvePromptModeApproval(args);
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var TOP_LEVEL_HELP_TEXT = [
|
|
|
9
9
|
"",
|
|
10
10
|
"Commands:",
|
|
11
11
|
" mcp ... Manage MCP servers and auth",
|
|
12
|
+
" session ... List, pin, archive, or clean up session run logs",
|
|
12
13
|
"",
|
|
13
14
|
"Runtime options:",
|
|
14
15
|
" --approval-mode <minimal|trusted|full-access>",
|
|
@@ -41,6 +42,7 @@ var hasPromptFlag = (args2) => {
|
|
|
41
42
|
return false;
|
|
42
43
|
};
|
|
43
44
|
var resolveTopLevelAction = (args2) => {
|
|
45
|
+
if (args2[0] === "session") return "session";
|
|
44
46
|
if (args2[0] === "mcp") {
|
|
45
47
|
return "mcp";
|
|
46
48
|
}
|
|
@@ -820,12 +822,63 @@ var runMcpCommand = async (values) => {
|
|
|
820
822
|
return 1;
|
|
821
823
|
};
|
|
822
824
|
|
|
825
|
+
// src/commands/session.ts
|
|
826
|
+
import {
|
|
827
|
+
cleanupRunLogs,
|
|
828
|
+
resolveStoragePaths as resolveStoragePaths2,
|
|
829
|
+
SessionStateStoreImpl
|
|
830
|
+
} from "@codelia/storage";
|
|
831
|
+
var HELP = "usage: codelia session list | pin|unpin|archive|unarchive <session_id> | cleanup\nArchive removes diagnostics and compresses unpinned run events, including legacy gzip. Original messages, active context and reference data remain; diagnostic dumps may expire.";
|
|
832
|
+
async function runSessionCommand(args2) {
|
|
833
|
+
const [action, sessionId, extra] = args2;
|
|
834
|
+
if (!action || action === "--help" || action === "help") {
|
|
835
|
+
console.log(HELP);
|
|
836
|
+
return 0;
|
|
837
|
+
}
|
|
838
|
+
if (action === "list" || action === "cleanup" ? sessionId !== void 0 : !["pin", "unpin", "archive", "unarchive"].includes(action) || !sessionId || extra !== void 0 || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(sessionId)) {
|
|
839
|
+
console.error(HELP);
|
|
840
|
+
return 1;
|
|
841
|
+
}
|
|
842
|
+
const paths = resolveStoragePaths2();
|
|
843
|
+
const sessions = new SessionStateStoreImpl({ paths });
|
|
844
|
+
try {
|
|
845
|
+
if (action === "list") {
|
|
846
|
+
for (const session2 of (await sessions.list()).sort(
|
|
847
|
+
(a, b) => b.updated_at.localeCompare(a.updated_at)
|
|
848
|
+
))
|
|
849
|
+
console.log(
|
|
850
|
+
`${session2.session_id} ${session2.updated_at} ${session2.pinned ? "pinned" : "unpinned"} ${session2.archived_at ? "archived" : "active"}`
|
|
851
|
+
);
|
|
852
|
+
return 0;
|
|
853
|
+
}
|
|
854
|
+
if (action === "cleanup") {
|
|
855
|
+
console.log(JSON.stringify(await cleanupRunLogs({ paths, sessions })));
|
|
856
|
+
return 0;
|
|
857
|
+
}
|
|
858
|
+
if (!sessionId) return 1;
|
|
859
|
+
const patch = action === "pin" || action === "unpin" ? { pinned: action === "pin" } : { archived: action === "archive" };
|
|
860
|
+
const session = await sessions.updateMetadata(sessionId, patch);
|
|
861
|
+
console.log(JSON.stringify(session));
|
|
862
|
+
if (!session.pinned && action !== "unarchive")
|
|
863
|
+
console.log(
|
|
864
|
+
JSON.stringify(await cleanupRunLogs({ paths, sessions, sessionId }))
|
|
865
|
+
);
|
|
866
|
+
return 0;
|
|
867
|
+
} catch (error) {
|
|
868
|
+
console.error(
|
|
869
|
+
`Session command failed: ${error instanceof Error ? error.message : String(error)}`
|
|
870
|
+
);
|
|
871
|
+
return 1;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
823
875
|
// src/prompt-mode.ts
|
|
824
876
|
import { spawn as spawn3 } from "child_process";
|
|
825
877
|
|
|
826
878
|
// src/atif.ts
|
|
827
|
-
import { mkdir,
|
|
879
|
+
import { mkdir, rename, writeFile } from "fs/promises";
|
|
828
880
|
import path2 from "path";
|
|
881
|
+
import { readRunLogLines } from "@codelia/storage";
|
|
829
882
|
var asRecord = (value) => typeof value === "object" && value !== null ? value : null;
|
|
830
883
|
var asString = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
831
884
|
var stringifyContent = (value) => {
|
|
@@ -991,9 +1044,14 @@ var sessionRecordsToAtif = (records, runId) => {
|
|
|
991
1044
|
extra: { source_record: "fallback" }
|
|
992
1045
|
});
|
|
993
1046
|
}
|
|
994
|
-
const
|
|
995
|
-
|
|
996
|
-
|
|
1047
|
+
const compactUsage = records.filter((record) => record.type === "llm.usage");
|
|
1048
|
+
const compactSequences = new Set(compactUsage.map((record) => record.seq));
|
|
1049
|
+
const usage = extractUsageMetrics([
|
|
1050
|
+
...compactUsage,
|
|
1051
|
+
...records.filter(
|
|
1052
|
+
(record) => record.type === "llm.response" && !compactSequences.has(record.seq)
|
|
1053
|
+
)
|
|
1054
|
+
]);
|
|
997
1055
|
return {
|
|
998
1056
|
schema_version: "ATIF-v1.6",
|
|
999
1057
|
session_id: extractSessionId(header, runStart, runId),
|
|
@@ -1025,7 +1083,11 @@ var parseSessionJsonl = (raw) => {
|
|
|
1025
1083
|
}
|
|
1026
1084
|
return out;
|
|
1027
1085
|
};
|
|
1028
|
-
var readSessionJsonl = async (filePath) =>
|
|
1086
|
+
var readSessionJsonl = async (filePath) => {
|
|
1087
|
+
const lines = [];
|
|
1088
|
+
for await (const line of readRunLogLines(filePath)) lines.push(line);
|
|
1089
|
+
return parseSessionJsonl(lines.join("\n"));
|
|
1090
|
+
};
|
|
1029
1091
|
var writeAtifFromSessionJsonl = async ({
|
|
1030
1092
|
sessionLogPath,
|
|
1031
1093
|
runId,
|
|
@@ -1046,10 +1108,10 @@ import { spawn as spawn2 } from "child_process";
|
|
|
1046
1108
|
import fsSync from "fs";
|
|
1047
1109
|
import { createRequire } from "module";
|
|
1048
1110
|
import path3 from "path";
|
|
1049
|
-
import { ensureStorageDirs, resolveStoragePaths as
|
|
1111
|
+
import { ensureStorageDirs, resolveStoragePaths as resolveStoragePaths3 } from "@codelia/storage";
|
|
1050
1112
|
|
|
1051
1113
|
// src/version.ts
|
|
1052
|
-
var CLI_VERSION = "0.1.
|
|
1114
|
+
var CLI_VERSION = "0.1.84".trim().length > 0 ? "0.1.84" : "0.0.0";
|
|
1053
1115
|
|
|
1054
1116
|
// src/tui/launcher.ts
|
|
1055
1117
|
var resolveTuiBinaryName = (platform) => platform === "win32" ? "codelia-tui.exe" : "codelia-tui";
|
|
@@ -1073,7 +1135,7 @@ var isExecutable = (candidate) => {
|
|
|
1073
1135
|
};
|
|
1074
1136
|
var initStorage = async () => {
|
|
1075
1137
|
try {
|
|
1076
|
-
const paths =
|
|
1138
|
+
const paths = resolveStoragePaths3();
|
|
1077
1139
|
await ensureStorageDirs(paths);
|
|
1078
1140
|
} catch (error) {
|
|
1079
1141
|
console.warn(
|
|
@@ -1658,6 +1720,10 @@ var main = async () => {
|
|
|
1658
1720
|
process.exitCode = exitCode;
|
|
1659
1721
|
return;
|
|
1660
1722
|
}
|
|
1723
|
+
case "session": {
|
|
1724
|
+
process.exitCode = await runSessionCommand(args.slice(1));
|
|
1725
|
+
return;
|
|
1726
|
+
}
|
|
1661
1727
|
case "prompt": {
|
|
1662
1728
|
const prompt = validatePromptText(resolvePromptText(args));
|
|
1663
1729
|
const approvalMode = resolvePromptModeApproval(args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codelia/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.84",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -20,19 +20,19 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@codelia/config-loader": "0.1.
|
|
24
|
-
"@codelia/protocol": "0.1.
|
|
25
|
-
"@codelia/runtime": "0.1.
|
|
26
|
-
"@codelia/storage": "0.1.
|
|
23
|
+
"@codelia/config-loader": "0.1.84",
|
|
24
|
+
"@codelia/protocol": "0.1.84",
|
|
25
|
+
"@codelia/runtime": "0.1.84",
|
|
26
|
+
"@codelia/storage": "0.1.84",
|
|
27
27
|
"cac": "^6.7.14",
|
|
28
28
|
"zod": "^4.3.6"
|
|
29
29
|
},
|
|
30
30
|
"optionalDependencies": {
|
|
31
|
-
"@codelia/tui-darwin-arm64": "0.1.
|
|
32
|
-
"@codelia/tui-darwin-x64": "0.1.
|
|
33
|
-
"@codelia/tui-linux-arm64": "0.1.
|
|
34
|
-
"@codelia/tui-linux-x64": "0.1.
|
|
35
|
-
"@codelia/tui-win32-x64": "0.1.
|
|
31
|
+
"@codelia/tui-darwin-arm64": "0.1.84",
|
|
32
|
+
"@codelia/tui-darwin-x64": "0.1.84",
|
|
33
|
+
"@codelia/tui-linux-arm64": "0.1.84",
|
|
34
|
+
"@codelia/tui-linux-x64": "0.1.84",
|
|
35
|
+
"@codelia/tui-win32-x64": "0.1.84"
|
|
36
36
|
},
|
|
37
37
|
"overrides": {
|
|
38
38
|
"gaxios": "7.1.4"
|