@codelia/cli 0.1.67 → 0.1.69
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 +253 -16
- package/dist/index.js +253 -16
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -838,15 +838,231 @@ var runMcpCommand = async (values) => {
|
|
|
838
838
|
// src/prompt-mode.ts
|
|
839
839
|
var import_node_child_process3 = require("child_process");
|
|
840
840
|
|
|
841
|
+
// src/atif.ts
|
|
842
|
+
var import_promises = require("fs/promises");
|
|
843
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
844
|
+
var asRecord = (value) => typeof value === "object" && value !== null ? value : null;
|
|
845
|
+
var asString = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
846
|
+
var stringifyContent = (value) => {
|
|
847
|
+
if (typeof value === "string") return value;
|
|
848
|
+
if (value == null) return "";
|
|
849
|
+
try {
|
|
850
|
+
return JSON.stringify(value);
|
|
851
|
+
} catch {
|
|
852
|
+
return String(value);
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
var normalizeTimestamp = (value) => {
|
|
856
|
+
const raw = asString(value);
|
|
857
|
+
if (!raw) return void 0;
|
|
858
|
+
const date = new Date(raw);
|
|
859
|
+
if (Number.isNaN(date.getTime())) return raw;
|
|
860
|
+
return date.toISOString();
|
|
861
|
+
};
|
|
862
|
+
var extractInputText = (input) => {
|
|
863
|
+
const direct = asRecord(input);
|
|
864
|
+
if (!direct) return asString(input);
|
|
865
|
+
if (direct.type === "text") return asString(direct.text);
|
|
866
|
+
return stringifyContent(direct);
|
|
867
|
+
};
|
|
868
|
+
var extractModelName = (record) => {
|
|
869
|
+
const model = asRecord(record?.model);
|
|
870
|
+
return asString(model?.name) ?? asString(model?.id);
|
|
871
|
+
};
|
|
872
|
+
var extractSessionId = (header, runStart, fallbackRunId) => asString(header?.session_id) ?? asString(runStart?.session_id) ?? asString(asRecord(runStart?.output)?.session_id) ?? fallbackRunId;
|
|
873
|
+
var createStepIdAllocator = () => {
|
|
874
|
+
let next = 1;
|
|
875
|
+
return () => next++;
|
|
876
|
+
};
|
|
877
|
+
var pushTextStep = (steps, nextStepId, source, message, timestamp, extra) => {
|
|
878
|
+
if (!message?.trim()) return;
|
|
879
|
+
steps.push({
|
|
880
|
+
step_id: nextStepId(),
|
|
881
|
+
...timestamp ? { timestamp } : {},
|
|
882
|
+
source,
|
|
883
|
+
message,
|
|
884
|
+
...extra ? { extra } : {}
|
|
885
|
+
});
|
|
886
|
+
};
|
|
887
|
+
var getOrCreateToolStep = (steps, nextStepId, callId, timestamp) => {
|
|
888
|
+
const existing = steps.find(
|
|
889
|
+
(step2) => step2.tool_calls?.some((call) => call.tool_call_id === callId)
|
|
890
|
+
);
|
|
891
|
+
if (existing) return existing;
|
|
892
|
+
const step = {
|
|
893
|
+
step_id: nextStepId(),
|
|
894
|
+
...timestamp ? { timestamp } : {},
|
|
895
|
+
source: "agent",
|
|
896
|
+
message: "",
|
|
897
|
+
tool_calls: []
|
|
898
|
+
};
|
|
899
|
+
steps.push(step);
|
|
900
|
+
return step;
|
|
901
|
+
};
|
|
902
|
+
var extractUsageMetrics = (records) => {
|
|
903
|
+
return records.map((record) => asRecord(asRecord(record.output)?.usage)).filter((usage) => !!usage).reduce(
|
|
904
|
+
(acc, usage) => {
|
|
905
|
+
acc.total_prompt_tokens += Number(usage.input_tokens ?? 0);
|
|
906
|
+
acc.total_completion_tokens += Number(usage.output_tokens ?? 0);
|
|
907
|
+
acc.total_cached_tokens += Number(
|
|
908
|
+
usage.input_cached_tokens ?? asRecord(usage.input_tokens_details)?.cached_tokens ?? 0
|
|
909
|
+
);
|
|
910
|
+
return acc;
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
total_prompt_tokens: 0,
|
|
914
|
+
total_completion_tokens: 0,
|
|
915
|
+
total_cached_tokens: 0
|
|
916
|
+
}
|
|
917
|
+
);
|
|
918
|
+
};
|
|
919
|
+
var sessionRecordsToAtif = (records, runId) => {
|
|
920
|
+
const header = records.find((record) => record.type === "header");
|
|
921
|
+
const runStart = records.find((record) => record.type === "run.start");
|
|
922
|
+
const modelName = extractModelName(header);
|
|
923
|
+
const nextStepId = createStepIdAllocator();
|
|
924
|
+
const steps = [];
|
|
925
|
+
pushTextStep(
|
|
926
|
+
steps,
|
|
927
|
+
nextStepId,
|
|
928
|
+
"user",
|
|
929
|
+
extractInputText(asRecord(runStart?.input)),
|
|
930
|
+
normalizeTimestamp(runStart?.ts),
|
|
931
|
+
{ source_record: "run.start" }
|
|
932
|
+
);
|
|
933
|
+
for (const record of records) {
|
|
934
|
+
if (record.type !== "agent.event") continue;
|
|
935
|
+
const event = asRecord(record.event);
|
|
936
|
+
if (!event) continue;
|
|
937
|
+
const timestamp = normalizeTimestamp(record.ts);
|
|
938
|
+
const eventType = asString(event.type);
|
|
939
|
+
if (eventType === "text") {
|
|
940
|
+
pushTextStep(
|
|
941
|
+
steps,
|
|
942
|
+
nextStepId,
|
|
943
|
+
"agent",
|
|
944
|
+
asString(event.content),
|
|
945
|
+
timestamp,
|
|
946
|
+
{ source_record: "agent.event.text" }
|
|
947
|
+
);
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
if (eventType === "reasoning") {
|
|
951
|
+
const content = asString(event.content);
|
|
952
|
+
if (!content) continue;
|
|
953
|
+
steps.push({
|
|
954
|
+
step_id: nextStepId(),
|
|
955
|
+
...timestamp ? { timestamp } : {},
|
|
956
|
+
source: "agent",
|
|
957
|
+
message: "",
|
|
958
|
+
reasoning_content: content,
|
|
959
|
+
extra: { source_record: "agent.event.reasoning" }
|
|
960
|
+
});
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
if (eventType === "tool_call") {
|
|
964
|
+
const callId = asString(event.tool_call_id) ?? `tool_call_${String(steps.length + 1)}`;
|
|
965
|
+
const step = getOrCreateToolStep(steps, nextStepId, callId, timestamp);
|
|
966
|
+
step.tool_calls ??= [];
|
|
967
|
+
step.tool_calls.push({
|
|
968
|
+
tool_call_id: callId,
|
|
969
|
+
function_name: asString(event.tool) ?? "unknown",
|
|
970
|
+
arguments: asRecord(event.args) ?? {}
|
|
971
|
+
});
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
if (eventType === "tool_result") {
|
|
975
|
+
const callId = asString(event.tool_call_id);
|
|
976
|
+
const step = callId ? getOrCreateToolStep(steps, nextStepId, callId, timestamp) : {
|
|
977
|
+
step_id: nextStepId(),
|
|
978
|
+
...timestamp ? { timestamp } : {},
|
|
979
|
+
source: "agent",
|
|
980
|
+
message: ""
|
|
981
|
+
};
|
|
982
|
+
if (!callId) steps.push(step);
|
|
983
|
+
step.observation ??= { results: [] };
|
|
984
|
+
step.observation.results.push({
|
|
985
|
+
...callId ? { source_call_id: callId } : {},
|
|
986
|
+
content: stringifyContent(event.result)
|
|
987
|
+
});
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
if (eventType === "final") {
|
|
991
|
+
pushTextStep(
|
|
992
|
+
steps,
|
|
993
|
+
nextStepId,
|
|
994
|
+
"agent",
|
|
995
|
+
asString(event.content),
|
|
996
|
+
timestamp,
|
|
997
|
+
{ source_record: "agent.event.final" }
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
if (steps.length === 0) {
|
|
1002
|
+
steps.push({
|
|
1003
|
+
step_id: nextStepId(),
|
|
1004
|
+
source: "user",
|
|
1005
|
+
message: "(no prompt captured)",
|
|
1006
|
+
extra: { source_record: "fallback" }
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
const usage = extractUsageMetrics(
|
|
1010
|
+
records.filter((record) => record.type === "llm.response")
|
|
1011
|
+
);
|
|
1012
|
+
return {
|
|
1013
|
+
schema_version: "ATIF-v1.6",
|
|
1014
|
+
session_id: extractSessionId(header, runStart, runId),
|
|
1015
|
+
agent: {
|
|
1016
|
+
name: "codelia",
|
|
1017
|
+
version: "unknown",
|
|
1018
|
+
...modelName ? { model_name: modelName } : {}
|
|
1019
|
+
},
|
|
1020
|
+
steps,
|
|
1021
|
+
final_metrics: {
|
|
1022
|
+
...usage,
|
|
1023
|
+
total_steps: steps.length
|
|
1024
|
+
},
|
|
1025
|
+
extra: {
|
|
1026
|
+
run_id: runId,
|
|
1027
|
+
source: "codelia-session-jsonl",
|
|
1028
|
+
conversion: "session-records-to-atif-v1.6"
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
};
|
|
1032
|
+
var parseSessionJsonl = (raw) => {
|
|
1033
|
+
const out = [];
|
|
1034
|
+
for (const line of raw.split("\n")) {
|
|
1035
|
+
if (!line.trim()) continue;
|
|
1036
|
+
try {
|
|
1037
|
+
out.push(JSON.parse(line));
|
|
1038
|
+
} catch {
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return out;
|
|
1042
|
+
};
|
|
1043
|
+
var readSessionJsonl = async (filePath) => parseSessionJsonl(await (0, import_promises.readFile)(filePath, "utf8"));
|
|
1044
|
+
var writeAtifFromSessionJsonl = async ({
|
|
1045
|
+
sessionLogPath,
|
|
1046
|
+
runId,
|
|
1047
|
+
outPath
|
|
1048
|
+
}) => {
|
|
1049
|
+
const records = await readSessionJsonl(sessionLogPath);
|
|
1050
|
+
const trajectory = sessionRecordsToAtif(records, runId);
|
|
1051
|
+
await (0, import_promises.mkdir)(import_node_path2.default.dirname(outPath), { recursive: true });
|
|
1052
|
+
await (0, import_promises.writeFile)(outPath, `${JSON.stringify(trajectory, null, 2)}
|
|
1053
|
+
`, "utf8");
|
|
1054
|
+
return trajectory;
|
|
1055
|
+
};
|
|
1056
|
+
|
|
841
1057
|
// src/tui/launcher.ts
|
|
842
1058
|
var import_node_child_process2 = require("child_process");
|
|
843
1059
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
844
1060
|
var import_node_module = require("module");
|
|
845
|
-
var
|
|
1061
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
846
1062
|
var import_storage3 = require("@codelia/storage");
|
|
847
1063
|
|
|
848
1064
|
// src/version.ts
|
|
849
|
-
var CLI_VERSION = "0.1.
|
|
1065
|
+
var CLI_VERSION = "0.1.69".trim().length > 0 ? "0.1.69" : "0.0.0";
|
|
850
1066
|
|
|
851
1067
|
// src/tui/launcher.ts
|
|
852
1068
|
var resolveTuiBinaryName = (platform) => platform === "win32" ? "codelia-tui.exe" : "codelia-tui";
|
|
@@ -883,9 +1099,9 @@ var resolveCliPackageRoot = () => {
|
|
|
883
1099
|
if (!scriptPath) return null;
|
|
884
1100
|
try {
|
|
885
1101
|
const resolvedScriptPath = import_node_fs.default.realpathSync(scriptPath);
|
|
886
|
-
const scriptDir =
|
|
887
|
-
if (
|
|
888
|
-
return
|
|
1102
|
+
const scriptDir = import_node_path3.default.dirname(resolvedScriptPath);
|
|
1103
|
+
if (import_node_path3.default.basename(scriptDir) === "dist") {
|
|
1104
|
+
return import_node_path3.default.dirname(scriptDir);
|
|
889
1105
|
}
|
|
890
1106
|
return scriptDir;
|
|
891
1107
|
} catch {
|
|
@@ -895,9 +1111,9 @@ var resolveCliPackageRoot = () => {
|
|
|
895
1111
|
var resolveRuntimeRequireBase = () => {
|
|
896
1112
|
const cliPackageRoot = resolveCliPackageRoot();
|
|
897
1113
|
if (cliPackageRoot) {
|
|
898
|
-
return
|
|
1114
|
+
return import_node_path3.default.resolve(cliPackageRoot, "package.json");
|
|
899
1115
|
}
|
|
900
|
-
return
|
|
1116
|
+
return import_node_path3.default.resolve(process.cwd(), "package.json");
|
|
901
1117
|
};
|
|
902
1118
|
var runtimeRequire = (0, import_node_module.createRequire)(resolveRuntimeRequireBase());
|
|
903
1119
|
var resolveBundledRuntimeEntry = () => {
|
|
@@ -924,8 +1140,8 @@ var resolveOptionalTuiBinaryPath = (platform = process.platform, arch = process.
|
|
|
924
1140
|
if (!packageJsonPath) {
|
|
925
1141
|
return null;
|
|
926
1142
|
}
|
|
927
|
-
return
|
|
928
|
-
|
|
1143
|
+
return import_node_path3.default.resolve(
|
|
1144
|
+
import_node_path3.default.dirname(packageJsonPath),
|
|
929
1145
|
"bin",
|
|
930
1146
|
resolveTuiBinaryName(platform)
|
|
931
1147
|
);
|
|
@@ -970,22 +1186,22 @@ var resolveTuiCommand = (options = {}) => {
|
|
|
970
1186
|
const optionalTuiBinary = resolveOptionalBinary(platform, arch);
|
|
971
1187
|
const localCandidates = [
|
|
972
1188
|
...cliPackageRoot ? [
|
|
973
|
-
|
|
974
|
-
|
|
1189
|
+
import_node_path3.default.resolve(cliPackageRoot, "dist/bin", tuiBinaryName),
|
|
1190
|
+
import_node_path3.default.resolve(
|
|
975
1191
|
cliPackageRoot,
|
|
976
1192
|
"../../crates/tui/target/release",
|
|
977
1193
|
tuiBinaryName
|
|
978
1194
|
),
|
|
979
|
-
|
|
1195
|
+
import_node_path3.default.resolve(
|
|
980
1196
|
cliPackageRoot,
|
|
981
1197
|
"../../crates/tui/target/debug",
|
|
982
1198
|
tuiBinaryName
|
|
983
1199
|
)
|
|
984
1200
|
] : [],
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1201
|
+
import_node_path3.default.resolve(cwd, "target/release", tuiBinaryName),
|
|
1202
|
+
import_node_path3.default.resolve(cwd, "target/debug", tuiBinaryName),
|
|
1203
|
+
import_node_path3.default.resolve(cwd, "crates/tui/target/release", tuiBinaryName),
|
|
1204
|
+
import_node_path3.default.resolve(cwd, "crates/tui/target/debug", tuiBinaryName)
|
|
989
1205
|
];
|
|
990
1206
|
const candidates = [
|
|
991
1207
|
...localCandidates,
|
|
@@ -1170,6 +1386,7 @@ var runPromptMode = async (options) => {
|
|
|
1170
1386
|
});
|
|
1171
1387
|
let buffer = "";
|
|
1172
1388
|
let runId = null;
|
|
1389
|
+
let sessionLogPath = null;
|
|
1173
1390
|
let finalText = "";
|
|
1174
1391
|
let terminalStatus = null;
|
|
1175
1392
|
let terminalMessage;
|
|
@@ -1313,6 +1530,7 @@ var runPromptMode = async (options) => {
|
|
|
1313
1530
|
}
|
|
1314
1531
|
const runResult = typeof runResponse.result === "object" && runResponse.result !== null ? runResponse.result : null;
|
|
1315
1532
|
runId = typeof runResult?.run_id === "string" ? runResult.run_id : null;
|
|
1533
|
+
sessionLogPath = typeof runResult?.session_log_path === "string" ? runResult.session_log_path : null;
|
|
1316
1534
|
if (!runId) {
|
|
1317
1535
|
throw new Error("run.start did not return run_id");
|
|
1318
1536
|
}
|
|
@@ -1340,6 +1558,25 @@ var runPromptMode = async (options) => {
|
|
|
1340
1558
|
}
|
|
1341
1559
|
}
|
|
1342
1560
|
if (terminalStatus === "completed") {
|
|
1561
|
+
const atifOut = process.env.CODELIA_ATIF_OUT?.trim();
|
|
1562
|
+
if (atifOut) {
|
|
1563
|
+
if (!sessionLogPath || !runId) {
|
|
1564
|
+
console.error("CODELIA_ATIF_OUT was set but session log path is missing");
|
|
1565
|
+
return 1;
|
|
1566
|
+
}
|
|
1567
|
+
try {
|
|
1568
|
+
await writeAtifFromSessionJsonl({
|
|
1569
|
+
sessionLogPath,
|
|
1570
|
+
runId,
|
|
1571
|
+
outPath: atifOut
|
|
1572
|
+
});
|
|
1573
|
+
} catch (error) {
|
|
1574
|
+
console.error(
|
|
1575
|
+
`Failed to write ATIF trajectory: ${error instanceof Error ? error.message : String(error)}`
|
|
1576
|
+
);
|
|
1577
|
+
return 1;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1343
1580
|
if (finalText.trim().length > 0) {
|
|
1344
1581
|
console.log(finalText);
|
|
1345
1582
|
}
|
package/dist/index.js
CHANGED
|
@@ -822,15 +822,231 @@ var runMcpCommand = async (values) => {
|
|
|
822
822
|
// src/prompt-mode.ts
|
|
823
823
|
import { spawn as spawn3 } from "child_process";
|
|
824
824
|
|
|
825
|
+
// src/atif.ts
|
|
826
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
827
|
+
import path2 from "path";
|
|
828
|
+
var asRecord = (value) => typeof value === "object" && value !== null ? value : null;
|
|
829
|
+
var asString = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
830
|
+
var stringifyContent = (value) => {
|
|
831
|
+
if (typeof value === "string") return value;
|
|
832
|
+
if (value == null) return "";
|
|
833
|
+
try {
|
|
834
|
+
return JSON.stringify(value);
|
|
835
|
+
} catch {
|
|
836
|
+
return String(value);
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var normalizeTimestamp = (value) => {
|
|
840
|
+
const raw = asString(value);
|
|
841
|
+
if (!raw) return void 0;
|
|
842
|
+
const date = new Date(raw);
|
|
843
|
+
if (Number.isNaN(date.getTime())) return raw;
|
|
844
|
+
return date.toISOString();
|
|
845
|
+
};
|
|
846
|
+
var extractInputText = (input) => {
|
|
847
|
+
const direct = asRecord(input);
|
|
848
|
+
if (!direct) return asString(input);
|
|
849
|
+
if (direct.type === "text") return asString(direct.text);
|
|
850
|
+
return stringifyContent(direct);
|
|
851
|
+
};
|
|
852
|
+
var extractModelName = (record) => {
|
|
853
|
+
const model = asRecord(record?.model);
|
|
854
|
+
return asString(model?.name) ?? asString(model?.id);
|
|
855
|
+
};
|
|
856
|
+
var extractSessionId = (header, runStart, fallbackRunId) => asString(header?.session_id) ?? asString(runStart?.session_id) ?? asString(asRecord(runStart?.output)?.session_id) ?? fallbackRunId;
|
|
857
|
+
var createStepIdAllocator = () => {
|
|
858
|
+
let next = 1;
|
|
859
|
+
return () => next++;
|
|
860
|
+
};
|
|
861
|
+
var pushTextStep = (steps, nextStepId, source, message, timestamp, extra) => {
|
|
862
|
+
if (!message?.trim()) return;
|
|
863
|
+
steps.push({
|
|
864
|
+
step_id: nextStepId(),
|
|
865
|
+
...timestamp ? { timestamp } : {},
|
|
866
|
+
source,
|
|
867
|
+
message,
|
|
868
|
+
...extra ? { extra } : {}
|
|
869
|
+
});
|
|
870
|
+
};
|
|
871
|
+
var getOrCreateToolStep = (steps, nextStepId, callId, timestamp) => {
|
|
872
|
+
const existing = steps.find(
|
|
873
|
+
(step2) => step2.tool_calls?.some((call) => call.tool_call_id === callId)
|
|
874
|
+
);
|
|
875
|
+
if (existing) return existing;
|
|
876
|
+
const step = {
|
|
877
|
+
step_id: nextStepId(),
|
|
878
|
+
...timestamp ? { timestamp } : {},
|
|
879
|
+
source: "agent",
|
|
880
|
+
message: "",
|
|
881
|
+
tool_calls: []
|
|
882
|
+
};
|
|
883
|
+
steps.push(step);
|
|
884
|
+
return step;
|
|
885
|
+
};
|
|
886
|
+
var extractUsageMetrics = (records) => {
|
|
887
|
+
return records.map((record) => asRecord(asRecord(record.output)?.usage)).filter((usage) => !!usage).reduce(
|
|
888
|
+
(acc, usage) => {
|
|
889
|
+
acc.total_prompt_tokens += Number(usage.input_tokens ?? 0);
|
|
890
|
+
acc.total_completion_tokens += Number(usage.output_tokens ?? 0);
|
|
891
|
+
acc.total_cached_tokens += Number(
|
|
892
|
+
usage.input_cached_tokens ?? asRecord(usage.input_tokens_details)?.cached_tokens ?? 0
|
|
893
|
+
);
|
|
894
|
+
return acc;
|
|
895
|
+
},
|
|
896
|
+
{
|
|
897
|
+
total_prompt_tokens: 0,
|
|
898
|
+
total_completion_tokens: 0,
|
|
899
|
+
total_cached_tokens: 0
|
|
900
|
+
}
|
|
901
|
+
);
|
|
902
|
+
};
|
|
903
|
+
var sessionRecordsToAtif = (records, runId) => {
|
|
904
|
+
const header = records.find((record) => record.type === "header");
|
|
905
|
+
const runStart = records.find((record) => record.type === "run.start");
|
|
906
|
+
const modelName = extractModelName(header);
|
|
907
|
+
const nextStepId = createStepIdAllocator();
|
|
908
|
+
const steps = [];
|
|
909
|
+
pushTextStep(
|
|
910
|
+
steps,
|
|
911
|
+
nextStepId,
|
|
912
|
+
"user",
|
|
913
|
+
extractInputText(asRecord(runStart?.input)),
|
|
914
|
+
normalizeTimestamp(runStart?.ts),
|
|
915
|
+
{ source_record: "run.start" }
|
|
916
|
+
);
|
|
917
|
+
for (const record of records) {
|
|
918
|
+
if (record.type !== "agent.event") continue;
|
|
919
|
+
const event = asRecord(record.event);
|
|
920
|
+
if (!event) continue;
|
|
921
|
+
const timestamp = normalizeTimestamp(record.ts);
|
|
922
|
+
const eventType = asString(event.type);
|
|
923
|
+
if (eventType === "text") {
|
|
924
|
+
pushTextStep(
|
|
925
|
+
steps,
|
|
926
|
+
nextStepId,
|
|
927
|
+
"agent",
|
|
928
|
+
asString(event.content),
|
|
929
|
+
timestamp,
|
|
930
|
+
{ source_record: "agent.event.text" }
|
|
931
|
+
);
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
if (eventType === "reasoning") {
|
|
935
|
+
const content = asString(event.content);
|
|
936
|
+
if (!content) continue;
|
|
937
|
+
steps.push({
|
|
938
|
+
step_id: nextStepId(),
|
|
939
|
+
...timestamp ? { timestamp } : {},
|
|
940
|
+
source: "agent",
|
|
941
|
+
message: "",
|
|
942
|
+
reasoning_content: content,
|
|
943
|
+
extra: { source_record: "agent.event.reasoning" }
|
|
944
|
+
});
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
947
|
+
if (eventType === "tool_call") {
|
|
948
|
+
const callId = asString(event.tool_call_id) ?? `tool_call_${String(steps.length + 1)}`;
|
|
949
|
+
const step = getOrCreateToolStep(steps, nextStepId, callId, timestamp);
|
|
950
|
+
step.tool_calls ??= [];
|
|
951
|
+
step.tool_calls.push({
|
|
952
|
+
tool_call_id: callId,
|
|
953
|
+
function_name: asString(event.tool) ?? "unknown",
|
|
954
|
+
arguments: asRecord(event.args) ?? {}
|
|
955
|
+
});
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
if (eventType === "tool_result") {
|
|
959
|
+
const callId = asString(event.tool_call_id);
|
|
960
|
+
const step = callId ? getOrCreateToolStep(steps, nextStepId, callId, timestamp) : {
|
|
961
|
+
step_id: nextStepId(),
|
|
962
|
+
...timestamp ? { timestamp } : {},
|
|
963
|
+
source: "agent",
|
|
964
|
+
message: ""
|
|
965
|
+
};
|
|
966
|
+
if (!callId) steps.push(step);
|
|
967
|
+
step.observation ??= { results: [] };
|
|
968
|
+
step.observation.results.push({
|
|
969
|
+
...callId ? { source_call_id: callId } : {},
|
|
970
|
+
content: stringifyContent(event.result)
|
|
971
|
+
});
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
if (eventType === "final") {
|
|
975
|
+
pushTextStep(
|
|
976
|
+
steps,
|
|
977
|
+
nextStepId,
|
|
978
|
+
"agent",
|
|
979
|
+
asString(event.content),
|
|
980
|
+
timestamp,
|
|
981
|
+
{ source_record: "agent.event.final" }
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (steps.length === 0) {
|
|
986
|
+
steps.push({
|
|
987
|
+
step_id: nextStepId(),
|
|
988
|
+
source: "user",
|
|
989
|
+
message: "(no prompt captured)",
|
|
990
|
+
extra: { source_record: "fallback" }
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
const usage = extractUsageMetrics(
|
|
994
|
+
records.filter((record) => record.type === "llm.response")
|
|
995
|
+
);
|
|
996
|
+
return {
|
|
997
|
+
schema_version: "ATIF-v1.6",
|
|
998
|
+
session_id: extractSessionId(header, runStart, runId),
|
|
999
|
+
agent: {
|
|
1000
|
+
name: "codelia",
|
|
1001
|
+
version: "unknown",
|
|
1002
|
+
...modelName ? { model_name: modelName } : {}
|
|
1003
|
+
},
|
|
1004
|
+
steps,
|
|
1005
|
+
final_metrics: {
|
|
1006
|
+
...usage,
|
|
1007
|
+
total_steps: steps.length
|
|
1008
|
+
},
|
|
1009
|
+
extra: {
|
|
1010
|
+
run_id: runId,
|
|
1011
|
+
source: "codelia-session-jsonl",
|
|
1012
|
+
conversion: "session-records-to-atif-v1.6"
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
};
|
|
1016
|
+
var parseSessionJsonl = (raw) => {
|
|
1017
|
+
const out = [];
|
|
1018
|
+
for (const line of raw.split("\n")) {
|
|
1019
|
+
if (!line.trim()) continue;
|
|
1020
|
+
try {
|
|
1021
|
+
out.push(JSON.parse(line));
|
|
1022
|
+
} catch {
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return out;
|
|
1026
|
+
};
|
|
1027
|
+
var readSessionJsonl = async (filePath) => parseSessionJsonl(await readFile(filePath, "utf8"));
|
|
1028
|
+
var writeAtifFromSessionJsonl = async ({
|
|
1029
|
+
sessionLogPath,
|
|
1030
|
+
runId,
|
|
1031
|
+
outPath
|
|
1032
|
+
}) => {
|
|
1033
|
+
const records = await readSessionJsonl(sessionLogPath);
|
|
1034
|
+
const trajectory = sessionRecordsToAtif(records, runId);
|
|
1035
|
+
await mkdir(path2.dirname(outPath), { recursive: true });
|
|
1036
|
+
await writeFile(outPath, `${JSON.stringify(trajectory, null, 2)}
|
|
1037
|
+
`, "utf8");
|
|
1038
|
+
return trajectory;
|
|
1039
|
+
};
|
|
1040
|
+
|
|
825
1041
|
// src/tui/launcher.ts
|
|
826
1042
|
import { spawn as spawn2 } from "child_process";
|
|
827
1043
|
import fsSync from "fs";
|
|
828
1044
|
import { createRequire } from "module";
|
|
829
|
-
import
|
|
1045
|
+
import path3 from "path";
|
|
830
1046
|
import { ensureStorageDirs, resolveStoragePaths as resolveStoragePaths2 } from "@codelia/storage";
|
|
831
1047
|
|
|
832
1048
|
// src/version.ts
|
|
833
|
-
var CLI_VERSION = "0.1.
|
|
1049
|
+
var CLI_VERSION = "0.1.69".trim().length > 0 ? "0.1.69" : "0.0.0";
|
|
834
1050
|
|
|
835
1051
|
// src/tui/launcher.ts
|
|
836
1052
|
var resolveTuiBinaryName = (platform) => platform === "win32" ? "codelia-tui.exe" : "codelia-tui";
|
|
@@ -867,9 +1083,9 @@ var resolveCliPackageRoot = () => {
|
|
|
867
1083
|
if (!scriptPath) return null;
|
|
868
1084
|
try {
|
|
869
1085
|
const resolvedScriptPath = fsSync.realpathSync(scriptPath);
|
|
870
|
-
const scriptDir =
|
|
871
|
-
if (
|
|
872
|
-
return
|
|
1086
|
+
const scriptDir = path3.dirname(resolvedScriptPath);
|
|
1087
|
+
if (path3.basename(scriptDir) === "dist") {
|
|
1088
|
+
return path3.dirname(scriptDir);
|
|
873
1089
|
}
|
|
874
1090
|
return scriptDir;
|
|
875
1091
|
} catch {
|
|
@@ -879,9 +1095,9 @@ var resolveCliPackageRoot = () => {
|
|
|
879
1095
|
var resolveRuntimeRequireBase = () => {
|
|
880
1096
|
const cliPackageRoot = resolveCliPackageRoot();
|
|
881
1097
|
if (cliPackageRoot) {
|
|
882
|
-
return
|
|
1098
|
+
return path3.resolve(cliPackageRoot, "package.json");
|
|
883
1099
|
}
|
|
884
|
-
return
|
|
1100
|
+
return path3.resolve(process.cwd(), "package.json");
|
|
885
1101
|
};
|
|
886
1102
|
var runtimeRequire = createRequire(resolveRuntimeRequireBase());
|
|
887
1103
|
var resolveBundledRuntimeEntry = () => {
|
|
@@ -908,8 +1124,8 @@ var resolveOptionalTuiBinaryPath = (platform = process.platform, arch = process.
|
|
|
908
1124
|
if (!packageJsonPath) {
|
|
909
1125
|
return null;
|
|
910
1126
|
}
|
|
911
|
-
return
|
|
912
|
-
|
|
1127
|
+
return path3.resolve(
|
|
1128
|
+
path3.dirname(packageJsonPath),
|
|
913
1129
|
"bin",
|
|
914
1130
|
resolveTuiBinaryName(platform)
|
|
915
1131
|
);
|
|
@@ -954,22 +1170,22 @@ var resolveTuiCommand = (options = {}) => {
|
|
|
954
1170
|
const optionalTuiBinary = resolveOptionalBinary(platform, arch);
|
|
955
1171
|
const localCandidates = [
|
|
956
1172
|
...cliPackageRoot ? [
|
|
957
|
-
|
|
958
|
-
|
|
1173
|
+
path3.resolve(cliPackageRoot, "dist/bin", tuiBinaryName),
|
|
1174
|
+
path3.resolve(
|
|
959
1175
|
cliPackageRoot,
|
|
960
1176
|
"../../crates/tui/target/release",
|
|
961
1177
|
tuiBinaryName
|
|
962
1178
|
),
|
|
963
|
-
|
|
1179
|
+
path3.resolve(
|
|
964
1180
|
cliPackageRoot,
|
|
965
1181
|
"../../crates/tui/target/debug",
|
|
966
1182
|
tuiBinaryName
|
|
967
1183
|
)
|
|
968
1184
|
] : [],
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1185
|
+
path3.resolve(cwd, "target/release", tuiBinaryName),
|
|
1186
|
+
path3.resolve(cwd, "target/debug", tuiBinaryName),
|
|
1187
|
+
path3.resolve(cwd, "crates/tui/target/release", tuiBinaryName),
|
|
1188
|
+
path3.resolve(cwd, "crates/tui/target/debug", tuiBinaryName)
|
|
973
1189
|
];
|
|
974
1190
|
const candidates = [
|
|
975
1191
|
...localCandidates,
|
|
@@ -1154,6 +1370,7 @@ var runPromptMode = async (options) => {
|
|
|
1154
1370
|
});
|
|
1155
1371
|
let buffer = "";
|
|
1156
1372
|
let runId = null;
|
|
1373
|
+
let sessionLogPath = null;
|
|
1157
1374
|
let finalText = "";
|
|
1158
1375
|
let terminalStatus = null;
|
|
1159
1376
|
let terminalMessage;
|
|
@@ -1297,6 +1514,7 @@ var runPromptMode = async (options) => {
|
|
|
1297
1514
|
}
|
|
1298
1515
|
const runResult = typeof runResponse.result === "object" && runResponse.result !== null ? runResponse.result : null;
|
|
1299
1516
|
runId = typeof runResult?.run_id === "string" ? runResult.run_id : null;
|
|
1517
|
+
sessionLogPath = typeof runResult?.session_log_path === "string" ? runResult.session_log_path : null;
|
|
1300
1518
|
if (!runId) {
|
|
1301
1519
|
throw new Error("run.start did not return run_id");
|
|
1302
1520
|
}
|
|
@@ -1324,6 +1542,25 @@ var runPromptMode = async (options) => {
|
|
|
1324
1542
|
}
|
|
1325
1543
|
}
|
|
1326
1544
|
if (terminalStatus === "completed") {
|
|
1545
|
+
const atifOut = process.env.CODELIA_ATIF_OUT?.trim();
|
|
1546
|
+
if (atifOut) {
|
|
1547
|
+
if (!sessionLogPath || !runId) {
|
|
1548
|
+
console.error("CODELIA_ATIF_OUT was set but session log path is missing");
|
|
1549
|
+
return 1;
|
|
1550
|
+
}
|
|
1551
|
+
try {
|
|
1552
|
+
await writeAtifFromSessionJsonl({
|
|
1553
|
+
sessionLogPath,
|
|
1554
|
+
runId,
|
|
1555
|
+
outPath: atifOut
|
|
1556
|
+
});
|
|
1557
|
+
} catch (error) {
|
|
1558
|
+
console.error(
|
|
1559
|
+
`Failed to write ATIF trajectory: ${error instanceof Error ? error.message : String(error)}`
|
|
1560
|
+
);
|
|
1561
|
+
return 1;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1327
1564
|
if (finalText.trim().length > 0) {
|
|
1328
1565
|
console.log(finalText);
|
|
1329
1566
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codelia/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.69",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20 <25"
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@codelia/config-loader": "0.1.
|
|
23
|
-
"@codelia/protocol": "0.1.
|
|
24
|
-
"@codelia/runtime": "0.1.
|
|
25
|
-
"@codelia/storage": "0.1.
|
|
22
|
+
"@codelia/config-loader": "0.1.69",
|
|
23
|
+
"@codelia/protocol": "0.1.69",
|
|
24
|
+
"@codelia/runtime": "0.1.69",
|
|
25
|
+
"@codelia/storage": "0.1.69",
|
|
26
26
|
"cac": "^6.7.14",
|
|
27
27
|
"zod": "^4.3.6"
|
|
28
28
|
},
|
|
29
29
|
"optionalDependencies": {
|
|
30
|
-
"@codelia/tui-darwin-arm64": "0.1.
|
|
31
|
-
"@codelia/tui-darwin-x64": "0.1.
|
|
32
|
-
"@codelia/tui-linux-arm64": "0.1.
|
|
33
|
-
"@codelia/tui-linux-x64": "0.1.
|
|
34
|
-
"@codelia/tui-win32-x64": "0.1.
|
|
30
|
+
"@codelia/tui-darwin-arm64": "0.1.69",
|
|
31
|
+
"@codelia/tui-darwin-x64": "0.1.69",
|
|
32
|
+
"@codelia/tui-linux-arm64": "0.1.69",
|
|
33
|
+
"@codelia/tui-linux-x64": "0.1.69",
|
|
34
|
+
"@codelia/tui-win32-x64": "0.1.69"
|
|
35
35
|
},
|
|
36
36
|
"overrides": {
|
|
37
37
|
"gaxios": "7.1.4"
|