@jun133/kitty 0.0.15 → 0.0.16
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/README.md +8 -6
- package/dist/{App-CBTIS4IK.mjs → App-K7CBA2FU.mjs} +1 -1
- package/dist/{chunk-7FDXKNTM.mjs → chunk-7FOTCUIH.mjs} +207 -197
- package/dist/{chunk-S4QTRPZ7.mjs → chunk-C3MFBHV3.mjs} +221 -221
- package/dist/{chunk-KUP5OMPB.mjs → chunk-FKBVCYPW.mjs} +1 -1
- package/dist/{chunk-NBKU7KA4.mjs → chunk-L27HOXD2.mjs} +192 -196
- package/dist/{chunk-WIKLME2V.mjs → chunk-LCTAPA2B.mjs} +67 -46
- package/dist/{chunk-AQEMM5VH.mjs → chunk-XY3SQDFZ.mjs} +1 -1
- package/dist/cli.js +6486 -6070
- package/dist/cli.js.map +1 -1
- package/dist/{interactive-BQMJFYHZ.mjs → interactive-ZNDB2JQO.mjs} +5 -5
- package/dist/{oneShot-4QBXBCNN.mjs → oneShot-4SH2HITB.mjs} +3 -3
- package/dist/{session-V7AYOK2Q.mjs → session-WJWPSYBD.mjs} +2 -2
- package/dist/tui.mjs +6 -6
- package/package.json +5 -2
|
@@ -735,10 +735,26 @@ function truncate2(value, maxChars) {
|
|
|
735
735
|
return value.length <= maxChars ? value : `${value.slice(0, maxChars)}...`;
|
|
736
736
|
}
|
|
737
737
|
|
|
738
|
-
// src/
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
738
|
+
// src/session/checkpoint/shared.ts
|
|
739
|
+
import crypto from "crypto";
|
|
740
|
+
import path2 from "path";
|
|
741
|
+
var MAX_COMPLETED_STEPS = 8;
|
|
742
|
+
var MAX_BATCH_TOOLS = 6;
|
|
743
|
+
var MAX_BATCH_PATHS = 6;
|
|
744
|
+
var MAX_SUMMARY_CHARS = 220;
|
|
745
|
+
function fingerprintFocus(focus) {
|
|
746
|
+
return crypto.createHash("sha1").update(focus.trim().toLowerCase()).digest("hex");
|
|
747
|
+
}
|
|
748
|
+
function normalizeText2(value) {
|
|
749
|
+
return String(value ?? "").replace(/\s+/g, " ").trim();
|
|
750
|
+
}
|
|
751
|
+
function truncate3(value, maxChars) {
|
|
752
|
+
if (!value) {
|
|
753
|
+
return void 0;
|
|
754
|
+
}
|
|
755
|
+
return value.length <= maxChars ? value : `${value.slice(0, maxChars)}...`;
|
|
756
|
+
}
|
|
757
|
+
function takeLastUnique2(values, limit) {
|
|
742
758
|
const seen = /* @__PURE__ */ new Set();
|
|
743
759
|
const result = [];
|
|
744
760
|
for (let index = values.length - 1; index >= 0; index -= 1) {
|
|
@@ -748,92 +764,169 @@ function takeLastUnique2(values) {
|
|
|
748
764
|
}
|
|
749
765
|
seen.add(normalized);
|
|
750
766
|
result.unshift(normalized);
|
|
751
|
-
if (result.length >=
|
|
767
|
+
if (result.length >= limit) {
|
|
752
768
|
break;
|
|
753
769
|
}
|
|
754
770
|
}
|
|
755
771
|
return result;
|
|
756
772
|
}
|
|
757
|
-
function
|
|
758
|
-
|
|
773
|
+
function safeParseObject2(raw) {
|
|
774
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
775
|
+
return null;
|
|
776
|
+
}
|
|
777
|
+
try {
|
|
778
|
+
const parsed = JSON.parse(raw);
|
|
779
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
780
|
+
return null;
|
|
781
|
+
}
|
|
782
|
+
return parsed;
|
|
783
|
+
} catch {
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
759
786
|
}
|
|
760
|
-
function
|
|
761
|
-
|
|
787
|
+
function readString(value) {
|
|
788
|
+
const normalized = normalizeText2(value);
|
|
789
|
+
return normalized || void 0;
|
|
762
790
|
}
|
|
763
|
-
function
|
|
764
|
-
if (
|
|
765
|
-
return
|
|
791
|
+
function normalizeToolBatch(toolBatch) {
|
|
792
|
+
if (!toolBatch) {
|
|
793
|
+
return void 0;
|
|
794
|
+
}
|
|
795
|
+
const tools = takeLastUnique2(toolBatch.tools ?? [], MAX_BATCH_TOOLS);
|
|
796
|
+
if (tools.length === 0) {
|
|
797
|
+
return void 0;
|
|
766
798
|
}
|
|
767
|
-
return Math.max(min, Math.min(max, Math.trunc(value)));
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
// src/agent/runtimeTransition/builders.ts
|
|
771
|
-
function createToolBatchTransition(input, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
772
799
|
return {
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
changedPaths: takeLastUnique2(input.changedPaths ?? [])
|
|
778
|
-
},
|
|
779
|
-
timestamp
|
|
800
|
+
tools,
|
|
801
|
+
summary: truncate3(normalizeText2(toolBatch.summary) || `Ran ${tools.join(", ")}`, MAX_SUMMARY_CHARS),
|
|
802
|
+
changedPaths: takeLastUnique2(toolBatch.changedPaths ?? [], MAX_BATCH_PATHS),
|
|
803
|
+
recordedAt: normalizeTimestamp(toolBatch.recordedAt, (/* @__PURE__ */ new Date()).toISOString())
|
|
780
804
|
};
|
|
781
805
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
},
|
|
788
|
-
timestamp
|
|
789
|
-
};
|
|
806
|
+
|
|
807
|
+
// src/session/checkpoint/derivation.ts
|
|
808
|
+
function deriveCompletedSteps(session) {
|
|
809
|
+
const completedActions = session.taskState?.completedActions ?? [];
|
|
810
|
+
return takeLastUnique2(completedActions, MAX_COMPLETED_STEPS);
|
|
790
811
|
}
|
|
791
|
-
function
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
812
|
+
function deriveRecentToolBatchFromMessages(messages, timestamp) {
|
|
813
|
+
let lastToolIndex = messages.length - 1;
|
|
814
|
+
while (lastToolIndex >= 0 && messages[lastToolIndex]?.role !== "tool") {
|
|
815
|
+
lastToolIndex -= 1;
|
|
816
|
+
}
|
|
817
|
+
if (lastToolIndex < 0) {
|
|
818
|
+
return void 0;
|
|
819
|
+
}
|
|
820
|
+
let startIndex = lastToolIndex;
|
|
821
|
+
while (startIndex >= 0 && messages[startIndex]?.role === "tool") {
|
|
822
|
+
startIndex -= 1;
|
|
823
|
+
}
|
|
824
|
+
const toolMessages = messages.slice(startIndex + 1, lastToolIndex + 1).filter((message) => message.role === "tool");
|
|
825
|
+
const toolNames = toolMessages.map((message) => normalizeText2(message.name)).filter(Boolean);
|
|
826
|
+
return buildToolBatch(toolNames, toolMessages, void 0, timestamp);
|
|
827
|
+
}
|
|
828
|
+
function buildToolBatch(toolNames, toolMessages, changedPaths, timestamp) {
|
|
829
|
+
const tools = takeLastUnique2(toolNames, MAX_BATCH_TOOLS);
|
|
830
|
+
if (tools.length === 0) {
|
|
831
|
+
return void 0;
|
|
832
|
+
}
|
|
833
|
+
const batchChangedPaths = takeLastUnique2(
|
|
834
|
+
[
|
|
835
|
+
...changedPaths ?? [],
|
|
836
|
+
...toolMessages.map((message) => readPathFromMessage(message)).filter(Boolean)
|
|
837
|
+
],
|
|
838
|
+
MAX_BATCH_PATHS
|
|
839
|
+
);
|
|
840
|
+
const recordedAt = normalizeTimestamp(
|
|
841
|
+
toolMessages[toolMessages.length - 1]?.createdAt,
|
|
805
842
|
timestamp
|
|
843
|
+
);
|
|
844
|
+
return {
|
|
845
|
+
tools,
|
|
846
|
+
summary: buildToolBatchSummary(tools, batchChangedPaths),
|
|
847
|
+
changedPaths: batchChangedPaths,
|
|
848
|
+
recordedAt
|
|
806
849
|
};
|
|
807
850
|
}
|
|
808
|
-
function
|
|
851
|
+
function readPathFromMessage(message) {
|
|
852
|
+
const payload = safeParseObject2(message.content);
|
|
853
|
+
return readString(payload?.path) ?? readString(payload?.requestedPath);
|
|
854
|
+
}
|
|
855
|
+
function buildToolBatchSummary(toolNames, changedPaths) {
|
|
856
|
+
const fragments = [`Ran ${toolNames.join(", ")}`];
|
|
857
|
+
if (changedPaths.length > 0) {
|
|
858
|
+
fragments.push(`changed ${changedPaths.join(" | ")}`);
|
|
859
|
+
}
|
|
860
|
+
return truncate3(fragments.join("; "), MAX_SUMMARY_CHARS);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// src/session/checkpoint/base.ts
|
|
864
|
+
function createEmptyCheckpoint(timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
809
865
|
return {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
866
|
+
version: 1,
|
|
867
|
+
status: "active",
|
|
868
|
+
completedSteps: [],
|
|
869
|
+
flow: {
|
|
870
|
+
phase: "active",
|
|
871
|
+
runState: {
|
|
872
|
+
status: "idle",
|
|
873
|
+
source: "checkpoint",
|
|
874
|
+
pendingToolCallCount: 0,
|
|
875
|
+
updatedAt: timestamp
|
|
876
|
+
},
|
|
877
|
+
updatedAt: timestamp
|
|
814
878
|
},
|
|
815
|
-
timestamp
|
|
879
|
+
updatedAt: timestamp
|
|
816
880
|
};
|
|
817
881
|
}
|
|
818
|
-
function
|
|
882
|
+
function createCheckpointForFocus(focus, timestamp) {
|
|
819
883
|
return {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
executionIds: takeLastUnique2([...input.executionIds]),
|
|
824
|
-
toolNames: takeLastUnique2([...input.toolNames])
|
|
825
|
-
},
|
|
826
|
-
timestamp
|
|
884
|
+
...createEmptyCheckpoint(timestamp),
|
|
885
|
+
focus,
|
|
886
|
+
focusFingerprint: focus ? fingerprintFocus(focus) : void 0
|
|
827
887
|
};
|
|
828
888
|
}
|
|
829
|
-
function
|
|
889
|
+
function deriveCheckpointFromSession(session, timestamp) {
|
|
890
|
+
const recentToolBatch = deriveRecentToolBatchFromMessages(session.messages, timestamp);
|
|
830
891
|
return {
|
|
831
|
-
session
|
|
832
|
-
|
|
833
|
-
|
|
892
|
+
...createCheckpointForFocus(normalizeText2(session.taskState?.focus) || void 0, timestamp),
|
|
893
|
+
completedSteps: deriveCompletedSteps(session),
|
|
894
|
+
recentToolBatch
|
|
834
895
|
};
|
|
835
896
|
}
|
|
836
897
|
|
|
898
|
+
// src/agent/runtimeTransition/shared.ts
|
|
899
|
+
var MAX_REASON_ITEMS = 6;
|
|
900
|
+
var MAX_REASON_TEXT_CHARS = 220;
|
|
901
|
+
function takeLastUnique3(values) {
|
|
902
|
+
const seen = /* @__PURE__ */ new Set();
|
|
903
|
+
const result = [];
|
|
904
|
+
for (let index = values.length - 1; index >= 0; index -= 1) {
|
|
905
|
+
const normalized = normalizeText3(values[index]);
|
|
906
|
+
if (!normalized || seen.has(normalized)) {
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
seen.add(normalized);
|
|
910
|
+
result.unshift(normalized);
|
|
911
|
+
if (result.length >= MAX_REASON_ITEMS) {
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return result;
|
|
916
|
+
}
|
|
917
|
+
function truncate4(value) {
|
|
918
|
+
return value.length <= MAX_REASON_TEXT_CHARS ? value : `${value.slice(0, MAX_REASON_TEXT_CHARS)}...`;
|
|
919
|
+
}
|
|
920
|
+
function normalizeText3(value) {
|
|
921
|
+
return String(value ?? "").replace(/\s+/g, " ").trim();
|
|
922
|
+
}
|
|
923
|
+
function clampWholeNumber(value, min, max, fallback) {
|
|
924
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
925
|
+
return fallback;
|
|
926
|
+
}
|
|
927
|
+
return Math.max(min, Math.min(max, Math.trunc(value)));
|
|
928
|
+
}
|
|
929
|
+
|
|
837
930
|
// src/agent/runtimeTransition/normalize.ts
|
|
838
931
|
function normalizeRuntimeTransition(transition, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
839
932
|
if (!transition || typeof transition !== "object") {
|
|
@@ -861,7 +954,7 @@ function normalizeRuntimeTransition(transition, timestamp = (/* @__PURE__ */ new
|
|
|
861
954
|
function normalizeContinueTransition(reason, timestamp) {
|
|
862
955
|
switch (reason.code) {
|
|
863
956
|
case "continue.after_tool_batch": {
|
|
864
|
-
const toolNames =
|
|
957
|
+
const toolNames = takeLastUnique3(reason.toolNames);
|
|
865
958
|
if (toolNames.length === 0) {
|
|
866
959
|
return void 0;
|
|
867
960
|
}
|
|
@@ -870,7 +963,7 @@ function normalizeContinueTransition(reason, timestamp) {
|
|
|
870
963
|
reason: {
|
|
871
964
|
code: reason.code,
|
|
872
965
|
toolNames,
|
|
873
|
-
changedPaths:
|
|
966
|
+
changedPaths: takeLastUnique3(reason.changedPaths ?? [])
|
|
874
967
|
},
|
|
875
968
|
timestamp
|
|
876
969
|
};
|
|
@@ -896,9 +989,9 @@ function normalizeRecoverTransition(reason, timestamp) {
|
|
|
896
989
|
reason: {
|
|
897
990
|
code: reason.code,
|
|
898
991
|
consecutiveFailures: clampWholeNumber(reason.consecutiveFailures, 1, 50, 1) ?? 1,
|
|
899
|
-
error:
|
|
900
|
-
configuredModel:
|
|
901
|
-
requestModel:
|
|
992
|
+
error: truncate4(normalizeText3(reason.error) || "request failed"),
|
|
993
|
+
configuredModel: normalizeText3(reason.configuredModel) || "unknown_model",
|
|
994
|
+
requestModel: normalizeText3(reason.requestModel) || "unknown_model",
|
|
902
995
|
contextWindowMessages: clampWholeNumber(reason.contextWindowMessages, 1, 999, 1) ?? 1,
|
|
903
996
|
maxContextChars: clampWholeNumber(reason.maxContextChars, 1, 1e6, 1) ?? 1,
|
|
904
997
|
contextSummaryChars: clampWholeNumber(reason.contextSummaryChars, 1, 1e6, 1) ?? 1,
|
|
@@ -915,7 +1008,7 @@ function normalizeFinalizeTransition(reason, timestamp) {
|
|
|
915
1008
|
action: "finalize",
|
|
916
1009
|
reason: {
|
|
917
1010
|
code: reason.code,
|
|
918
|
-
changedPaths:
|
|
1011
|
+
changedPaths: takeLastUnique3(reason.changedPaths ?? [])
|
|
919
1012
|
},
|
|
920
1013
|
timestamp
|
|
921
1014
|
};
|
|
@@ -924,7 +1017,7 @@ function normalizeYieldTransition(reason, timestamp) {
|
|
|
924
1017
|
if (reason.code !== "yield.execution_wait") {
|
|
925
1018
|
return void 0;
|
|
926
1019
|
}
|
|
927
|
-
const executionIds =
|
|
1020
|
+
const executionIds = takeLastUnique3(reason.executionIds ?? []);
|
|
928
1021
|
if (executionIds.length === 0) {
|
|
929
1022
|
return void 0;
|
|
930
1023
|
}
|
|
@@ -933,7 +1026,7 @@ function normalizeYieldTransition(reason, timestamp) {
|
|
|
933
1026
|
reason: {
|
|
934
1027
|
code: reason.code,
|
|
935
1028
|
executionIds,
|
|
936
|
-
toolNames:
|
|
1029
|
+
toolNames: takeLastUnique3(reason.toolNames ?? [])
|
|
937
1030
|
},
|
|
938
1031
|
timestamp
|
|
939
1032
|
};
|
|
@@ -953,7 +1046,7 @@ function normalizeCheckpointFlow(flow, status, timestamp = (/* @__PURE__ */ new
|
|
|
953
1046
|
});
|
|
954
1047
|
return {
|
|
955
1048
|
phase,
|
|
956
|
-
reason: lastTransition ? formatRuntimeTransitionReason(lastTransition) :
|
|
1049
|
+
reason: lastTransition ? formatRuntimeTransitionReason(lastTransition) : normalizeText3(flow?.reason) || void 0,
|
|
957
1050
|
recoveryFailures: lastTransition?.action === "recover" ? lastTransition.reason.consecutiveFailures : phase === "recovery" ? clampWholeNumber(flow?.recoveryFailures, 1, 50, void 0) : void 0,
|
|
958
1051
|
runState,
|
|
959
1052
|
lastTransition,
|
|
@@ -1023,163 +1116,70 @@ function normalizeRunStateSource(source, status) {
|
|
|
1023
1116
|
return "checkpoint";
|
|
1024
1117
|
}
|
|
1025
1118
|
|
|
1026
|
-
// src/
|
|
1027
|
-
|
|
1028
|
-
import path2 from "path";
|
|
1029
|
-
var MAX_COMPLETED_STEPS = 8;
|
|
1030
|
-
var MAX_BATCH_TOOLS = 6;
|
|
1031
|
-
var MAX_BATCH_PATHS = 6;
|
|
1032
|
-
var MAX_SUMMARY_CHARS = 220;
|
|
1033
|
-
function fingerprintFocus(focus) {
|
|
1034
|
-
return crypto.createHash("sha1").update(focus.trim().toLowerCase()).digest("hex");
|
|
1035
|
-
}
|
|
1036
|
-
function normalizeText3(value) {
|
|
1037
|
-
return String(value ?? "").replace(/\s+/g, " ").trim();
|
|
1038
|
-
}
|
|
1039
|
-
function truncate4(value, maxChars) {
|
|
1040
|
-
if (!value) {
|
|
1041
|
-
return void 0;
|
|
1042
|
-
}
|
|
1043
|
-
return value.length <= maxChars ? value : `${value.slice(0, maxChars)}...`;
|
|
1044
|
-
}
|
|
1045
|
-
function takeLastUnique3(values, limit) {
|
|
1046
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1047
|
-
const result = [];
|
|
1048
|
-
for (let index = values.length - 1; index >= 0; index -= 1) {
|
|
1049
|
-
const normalized = normalizeText3(values[index]);
|
|
1050
|
-
if (!normalized || seen.has(normalized)) {
|
|
1051
|
-
continue;
|
|
1052
|
-
}
|
|
1053
|
-
seen.add(normalized);
|
|
1054
|
-
result.unshift(normalized);
|
|
1055
|
-
if (result.length >= limit) {
|
|
1056
|
-
break;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
return result;
|
|
1060
|
-
}
|
|
1061
|
-
function safeParseObject2(raw) {
|
|
1062
|
-
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
1063
|
-
return null;
|
|
1064
|
-
}
|
|
1065
|
-
try {
|
|
1066
|
-
const parsed = JSON.parse(raw);
|
|
1067
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1068
|
-
return null;
|
|
1069
|
-
}
|
|
1070
|
-
return parsed;
|
|
1071
|
-
} catch {
|
|
1072
|
-
return null;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
function readString(value) {
|
|
1076
|
-
const normalized = normalizeText3(value);
|
|
1077
|
-
return normalized || void 0;
|
|
1078
|
-
}
|
|
1079
|
-
function normalizeToolBatch(toolBatch) {
|
|
1080
|
-
if (!toolBatch) {
|
|
1081
|
-
return void 0;
|
|
1082
|
-
}
|
|
1083
|
-
const tools = takeLastUnique3(toolBatch.tools ?? [], MAX_BATCH_TOOLS);
|
|
1084
|
-
if (tools.length === 0) {
|
|
1085
|
-
return void 0;
|
|
1086
|
-
}
|
|
1119
|
+
// src/agent/runtimeTransition/builders.ts
|
|
1120
|
+
function createToolBatchTransition(input, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1087
1121
|
return {
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1122
|
+
action: "continue",
|
|
1123
|
+
reason: {
|
|
1124
|
+
code: "continue.after_tool_batch",
|
|
1125
|
+
toolNames: takeLastUnique3(input.toolNames),
|
|
1126
|
+
changedPaths: takeLastUnique3(input.changedPaths ?? [])
|
|
1127
|
+
},
|
|
1128
|
+
timestamp
|
|
1092
1129
|
};
|
|
1093
1130
|
}
|
|
1094
|
-
|
|
1095
|
-
// src/session/checkpoint/derivation.ts
|
|
1096
|
-
function deriveCompletedSteps(session) {
|
|
1097
|
-
const completedActions = session.taskState?.completedActions ?? [];
|
|
1098
|
-
return takeLastUnique3(completedActions, MAX_COMPLETED_STEPS);
|
|
1099
|
-
}
|
|
1100
|
-
function deriveRecentToolBatchFromMessages(messages, timestamp) {
|
|
1101
|
-
let lastToolIndex = messages.length - 1;
|
|
1102
|
-
while (lastToolIndex >= 0 && messages[lastToolIndex]?.role !== "tool") {
|
|
1103
|
-
lastToolIndex -= 1;
|
|
1104
|
-
}
|
|
1105
|
-
if (lastToolIndex < 0) {
|
|
1106
|
-
return void 0;
|
|
1107
|
-
}
|
|
1108
|
-
let startIndex = lastToolIndex;
|
|
1109
|
-
while (startIndex >= 0 && messages[startIndex]?.role === "tool") {
|
|
1110
|
-
startIndex -= 1;
|
|
1111
|
-
}
|
|
1112
|
-
const toolMessages = messages.slice(startIndex + 1, lastToolIndex + 1).filter((message) => message.role === "tool");
|
|
1113
|
-
const toolNames = toolMessages.map((message) => normalizeText3(message.name)).filter(Boolean);
|
|
1114
|
-
return buildToolBatch(toolNames, toolMessages, void 0, timestamp);
|
|
1115
|
-
}
|
|
1116
|
-
function buildToolBatch(toolNames, toolMessages, changedPaths, timestamp) {
|
|
1117
|
-
const tools = takeLastUnique3(toolNames, MAX_BATCH_TOOLS);
|
|
1118
|
-
if (tools.length === 0) {
|
|
1119
|
-
return void 0;
|
|
1120
|
-
}
|
|
1121
|
-
const batchChangedPaths = takeLastUnique3(
|
|
1122
|
-
[
|
|
1123
|
-
...changedPaths ?? [],
|
|
1124
|
-
...toolMessages.map((message) => readPathFromMessage(message)).filter(Boolean)
|
|
1125
|
-
],
|
|
1126
|
-
MAX_BATCH_PATHS
|
|
1127
|
-
);
|
|
1128
|
-
const recordedAt = normalizeTimestamp(
|
|
1129
|
-
toolMessages[toolMessages.length - 1]?.createdAt,
|
|
1130
|
-
timestamp
|
|
1131
|
-
);
|
|
1131
|
+
function createEmptyAssistantResponseTransition(timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1132
1132
|
return {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1133
|
+
action: "continue",
|
|
1134
|
+
reason: {
|
|
1135
|
+
code: "continue.empty_assistant_response"
|
|
1136
|
+
},
|
|
1137
|
+
timestamp
|
|
1137
1138
|
};
|
|
1138
1139
|
}
|
|
1139
|
-
function
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1140
|
+
function createProviderRecoveryTransition(input, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1141
|
+
return {
|
|
1142
|
+
action: "recover",
|
|
1143
|
+
reason: {
|
|
1144
|
+
code: "recover.provider_request_retry",
|
|
1145
|
+
consecutiveFailures: Math.max(1, Math.trunc(input.consecutiveFailures)),
|
|
1146
|
+
error: truncate4(normalizeText3(input.error?.message ?? input.error) || "request failed"),
|
|
1147
|
+
configuredModel: normalizeText3(input.configuredModel) || "unknown_model",
|
|
1148
|
+
requestModel: normalizeText3(input.requestModel) || "unknown_model",
|
|
1149
|
+
contextWindowMessages: Math.max(1, Math.trunc(input.requestConfig.contextWindowMessages)),
|
|
1150
|
+
maxContextChars: Math.max(1, Math.trunc(input.requestConfig.maxContextChars)),
|
|
1151
|
+
contextSummaryChars: Math.max(1, Math.trunc(input.requestConfig.contextSummaryChars)),
|
|
1152
|
+
delayMs: Math.max(0, Math.trunc(input.delayMs))
|
|
1153
|
+
},
|
|
1154
|
+
timestamp
|
|
1155
|
+
};
|
|
1149
1156
|
}
|
|
1150
|
-
|
|
1151
|
-
// src/session/checkpoint/base.ts
|
|
1152
|
-
function createEmptyCheckpoint(timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1157
|
+
function createFinalizeTransition(input, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1153
1158
|
return {
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
phase: "active",
|
|
1159
|
-
runState: {
|
|
1160
|
-
status: "idle",
|
|
1161
|
-
source: "checkpoint",
|
|
1162
|
-
pendingToolCallCount: 0,
|
|
1163
|
-
updatedAt: timestamp
|
|
1164
|
-
},
|
|
1165
|
-
updatedAt: timestamp
|
|
1159
|
+
action: "finalize",
|
|
1160
|
+
reason: {
|
|
1161
|
+
code: "finalize.completed",
|
|
1162
|
+
changedPaths: takeLastUnique3([...input.changedPaths])
|
|
1166
1163
|
},
|
|
1167
|
-
|
|
1164
|
+
timestamp
|
|
1168
1165
|
};
|
|
1169
1166
|
}
|
|
1170
|
-
function
|
|
1167
|
+
function createExecutionWaitYieldTransition(input, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1171
1168
|
return {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1169
|
+
action: "yield",
|
|
1170
|
+
reason: {
|
|
1171
|
+
code: "yield.execution_wait",
|
|
1172
|
+
executionIds: takeLastUnique3([...input.executionIds]),
|
|
1173
|
+
toolNames: takeLastUnique3([...input.toolNames])
|
|
1174
|
+
},
|
|
1175
|
+
timestamp
|
|
1175
1176
|
};
|
|
1176
1177
|
}
|
|
1177
|
-
function
|
|
1178
|
-
const recentToolBatch = deriveRecentToolBatchFromMessages(session.messages, timestamp);
|
|
1178
|
+
function buildRunTurnResult(input) {
|
|
1179
1179
|
return {
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1180
|
+
session: input.session,
|
|
1181
|
+
changedPaths: [...input.changedPaths],
|
|
1182
|
+
transition: input.transition
|
|
1183
1183
|
};
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
@@ -1188,14 +1188,14 @@ function normalizeCheckpoint(checkpoint, timestamp = (/* @__PURE__ */ new Date()
|
|
|
1188
1188
|
if (!checkpoint) {
|
|
1189
1189
|
return void 0;
|
|
1190
1190
|
}
|
|
1191
|
-
const focus =
|
|
1191
|
+
const focus = normalizeText2(checkpoint.focus) || void 0;
|
|
1192
1192
|
const status = checkpoint.status === "completed" ? "completed" : "active";
|
|
1193
1193
|
return {
|
|
1194
1194
|
version: 1,
|
|
1195
1195
|
focus,
|
|
1196
|
-
focusFingerprint:
|
|
1196
|
+
focusFingerprint: normalizeText2(checkpoint.focusFingerprint) || (focus ? fingerprintFocus(focus) : void 0),
|
|
1197
1197
|
status,
|
|
1198
|
-
completedSteps:
|
|
1198
|
+
completedSteps: takeLastUnique2(checkpoint.completedSteps ?? [], 8),
|
|
1199
1199
|
recentToolBatch: normalizeToolBatch(checkpoint.recentToolBatch),
|
|
1200
1200
|
flow: normalizeCheckpointFlow(checkpoint.flow, status, timestamp),
|
|
1201
1201
|
updatedAt: normalizeTimestamp(checkpoint.updatedAt, timestamp)
|
|
@@ -1241,7 +1241,7 @@ function noteCheckpointTurnInput(session, input, timestamp = (/* @__PURE__ */ ne
|
|
|
1241
1241
|
};
|
|
1242
1242
|
}
|
|
1243
1243
|
function resolveCurrentFocusCheckpoint(session, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1244
|
-
const focus =
|
|
1244
|
+
const focus = normalizeText2(session.taskState?.focus) || void 0;
|
|
1245
1245
|
const fingerprint = focus ? fingerprintFocus(focus) : void 0;
|
|
1246
1246
|
const checkpoint = normalizeCheckpoint(session.checkpoint, timestamp) ?? createEmptyCheckpoint(timestamp);
|
|
1247
1247
|
if (!focus) {
|
|
@@ -1666,8 +1666,8 @@ export {
|
|
|
1666
1666
|
createExecutionWaitYieldTransition,
|
|
1667
1667
|
buildRunTurnResult,
|
|
1668
1668
|
fingerprintFocus,
|
|
1669
|
-
|
|
1670
|
-
|
|
1669
|
+
normalizeText2 as normalizeText,
|
|
1670
|
+
takeLastUnique2 as takeLastUnique,
|
|
1671
1671
|
createEmptyCheckpoint,
|
|
1672
1672
|
normalizeCheckpoint,
|
|
1673
1673
|
normalizeSessionCheckpoint,
|