@costrict/csc 4.1.12 → 4.2.1

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.
@@ -427,7 +427,7 @@ async function appendDeadLetter(entry) {
427
427
  // src/services/rawDump/worker.ts
428
428
  import { promises as fs7 } from "fs";
429
429
  import { createHash as createHash2 } from "crypto";
430
- import os6 from "os";
430
+ import os5 from "os";
431
431
  import path7 from "path";
432
432
  import { fileURLToPath } from "url";
433
433
 
@@ -477,8 +477,8 @@ async function saveCoStrictCredentials(credentials) {
477
477
  import { createRequire } from "module";
478
478
  function getVersion() {
479
479
  try {
480
- if (typeof MACRO !== "undefined" && "4.1.12")
481
- return "4.1.12";
480
+ if (typeof MACRO !== "undefined" && "4.2.1")
481
+ return "4.2.1";
482
482
  } catch {}
483
483
  try {
484
484
  const require2 = createRequire(import.meta.url);
@@ -824,841 +824,861 @@ async function releaseQueueLock() {
824
824
 
825
825
  // src/services/rawDump/history.ts
826
826
  import { promises as fs5 } from "fs";
827
- import os5 from "os";
828
827
  import path5 from "path";
829
- var HISTORY_FILE = path5.join(os5.homedir(), ".claude", "history.jsonl");
830
- var cache = null;
831
- async function loadHistory() {
832
- const items = [];
833
- let fileStat = null;
834
- try {
835
- fileStat = await fs5.stat(HISTORY_FILE);
836
- } catch {
837
- cache = null;
838
- return [];
839
- }
828
+
829
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_freeGlobal.js
830
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
831
+ var _freeGlobal_default = freeGlobal;
832
+
833
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_root.js
834
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
835
+ var root = _freeGlobal_default || freeSelf || Function("return this")();
836
+ var _root_default = root;
837
+
838
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Symbol.js
839
+ var Symbol2 = _root_default.Symbol;
840
+ var _Symbol_default = Symbol2;
841
+
842
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getRawTag.js
843
+ var objectProto = Object.prototype;
844
+ var hasOwnProperty = objectProto.hasOwnProperty;
845
+ var nativeObjectToString = objectProto.toString;
846
+ var symToStringTag = _Symbol_default ? _Symbol_default.toStringTag : undefined;
847
+ function getRawTag(value) {
848
+ var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
840
849
  try {
841
- const content = await fs5.readFile(HISTORY_FILE, "utf-8");
842
- const lines = content.split(`
843
- `);
844
- for (const line of lines) {
845
- if (!line.trim())
846
- continue;
847
- try {
848
- const item = JSON.parse(line);
849
- items.push(item);
850
- } catch {}
850
+ value[symToStringTag] = undefined;
851
+ var unmasked = true;
852
+ } catch (e) {}
853
+ var result = nativeObjectToString.call(value);
854
+ if (unmasked) {
855
+ if (isOwn) {
856
+ value[symToStringTag] = tag;
857
+ } else {
858
+ delete value[symToStringTag];
851
859
  }
852
- } catch {
853
- return cache?.items ?? [];
854
860
  }
855
- cache = {
856
- mtime: fileStat.mtimeMs,
857
- size: fileStat.size,
858
- items
859
- };
860
- return cache.items;
861
+ return result;
861
862
  }
862
- async function autoLoadHistory() {
863
- let fileStat = null;
864
- try {
865
- fileStat = await fs5.stat(HISTORY_FILE);
866
- } catch {
867
- if (cache) {
868
- return null;
869
- }
870
- return [];
863
+ var _getRawTag_default = getRawTag;
864
+
865
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_objectToString.js
866
+ var objectProto2 = Object.prototype;
867
+ var nativeObjectToString2 = objectProto2.toString;
868
+ function objectToString(value) {
869
+ return nativeObjectToString2.call(value);
870
+ }
871
+ var _objectToString_default = objectToString;
872
+
873
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetTag.js
874
+ var nullTag = "[object Null]";
875
+ var undefinedTag = "[object Undefined]";
876
+ var symToStringTag2 = _Symbol_default ? _Symbol_default.toStringTag : undefined;
877
+ function baseGetTag(value) {
878
+ if (value == null) {
879
+ return value === undefined ? undefinedTag : nullTag;
871
880
  }
872
- if (cache && cache.mtime === fileStat.mtimeMs && cache.size === fileStat.size) {
873
- return cache.items;
881
+ return symToStringTag2 && symToStringTag2 in Object(value) ? _getRawTag_default(value) : _objectToString_default(value);
882
+ }
883
+ var _baseGetTag_default = baseGetTag;
884
+
885
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObject.js
886
+ function isObject(value) {
887
+ var type = typeof value;
888
+ return value != null && (type == "object" || type == "function");
889
+ }
890
+ var isObject_default = isObject;
891
+
892
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isFunction.js
893
+ var asyncTag = "[object AsyncFunction]";
894
+ var funcTag = "[object Function]";
895
+ var genTag = "[object GeneratorFunction]";
896
+ var proxyTag = "[object Proxy]";
897
+ function isFunction(value) {
898
+ if (!isObject_default(value)) {
899
+ return false;
874
900
  }
875
- return await loadHistory();
901
+ var tag = _baseGetTag_default(value);
902
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
876
903
  }
877
- async function getProjectDirs() {
878
- if (cache) {
879
- let fileStat = null;
904
+ var isFunction_default = isFunction;
905
+
906
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_coreJsData.js
907
+ var coreJsData = _root_default["__core-js_shared__"];
908
+ var _coreJsData_default = coreJsData;
909
+
910
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isMasked.js
911
+ var maskSrcKey = function() {
912
+ var uid = /[^.]+$/.exec(_coreJsData_default && _coreJsData_default.keys && _coreJsData_default.keys.IE_PROTO || "");
913
+ return uid ? "Symbol(src)_1." + uid : "";
914
+ }();
915
+ function isMasked(func) {
916
+ return !!maskSrcKey && maskSrcKey in func;
917
+ }
918
+ var _isMasked_default = isMasked;
919
+
920
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_toSource.js
921
+ var funcProto = Function.prototype;
922
+ var funcToString = funcProto.toString;
923
+ function toSource(func) {
924
+ if (func != null) {
880
925
  try {
881
- fileStat = await fs5.stat(HISTORY_FILE);
882
- } catch {
883
- return [...new Set(cache.items.map((item) => item.project))];
884
- }
885
- if (fileStat.mtimeMs === cache.mtime && fileStat.size === cache.size) {
886
- return [...new Set(cache.items.map((item) => item.project))];
887
- }
926
+ return funcToString.call(func);
927
+ } catch (e) {}
928
+ try {
929
+ return func + "";
930
+ } catch (e) {}
888
931
  }
889
- const items = await loadHistory();
890
- return [...new Set(items.map((item) => item.project))];
932
+ return "";
891
933
  }
934
+ var _toSource_default = toSource;
892
935
 
893
- // src/services/rawDump/session.ts
894
- import { promises as fs6 } from "fs";
895
- import path6 from "path";
936
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsNative.js
937
+ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
938
+ var reIsHostCtor = /^\[object .+?Constructor\]$/;
939
+ var funcProto2 = Function.prototype;
940
+ var objectProto3 = Object.prototype;
941
+ var funcToString2 = funcProto2.toString;
942
+ var hasOwnProperty2 = objectProto3.hasOwnProperty;
943
+ var reIsNative = RegExp("^" + funcToString2.call(hasOwnProperty2).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$");
944
+ function baseIsNative(value) {
945
+ if (!isObject_default(value) || _isMasked_default(value)) {
946
+ return false;
947
+ }
948
+ var pattern = isFunction_default(value) ? reIsNative : reIsHostCtor;
949
+ return pattern.test(_toSource_default(value));
950
+ }
951
+ var _baseIsNative_default = baseIsNative;
896
952
 
897
- // src/services/rawDump/parse.ts
898
- function buildFlows(events) {
899
- const childIndex = new Map;
900
- events.forEach((e) => {
901
- if (e.parentUuid) {
902
- if (!childIndex.has(e.parentUuid))
903
- childIndex.set(e.parentUuid, []);
904
- childIndex.get(e.parentUuid).push(e);
905
- }
906
- });
907
- const visited = new Set;
908
- const flows = [];
909
- events.forEach((e, i) => {
910
- const key = e.uuid || `__idx__${i}`;
911
- if (visited.has(key))
912
- return;
913
- if (!e.parentUuid) {
914
- const flow = [];
915
- const queue2 = [e];
916
- while (queue2.length > 0) {
917
- const curr = queue2.shift();
918
- const currKey = curr.uuid || `__idx__${events.indexOf(curr)}`;
919
- if (visited.has(currKey))
920
- continue;
921
- visited.add(currKey);
922
- flow.push(curr);
923
- const children = childIndex.get(currKey) || [];
924
- children.forEach((child) => {
925
- const childKey = child.uuid || `__idx__${events.indexOf(child)}`;
926
- if (!visited.has(childKey))
927
- queue2.push(child);
928
- });
929
- }
930
- if (flow.length > 0) {
931
- flow.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
932
- flows.push(flow);
933
- }
934
- }
935
- });
936
- return flows;
953
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getValue.js
954
+ function getValue(object, key) {
955
+ return object == null ? undefined : object[key];
937
956
  }
938
- function createConversation(convEvents) {
939
- const userEvent = convEvents[0];
940
- return {
941
- id: userEvent.uuid,
942
- index: -1,
943
- promptId: userEvent.promptId || "",
944
- userEvent,
945
- events: convEvents,
946
- inputTokens: 0,
947
- outputTokens: 0,
948
- cacheReadInputTokens: 0,
949
- cacheCreationInputTokens: 0,
950
- totalTokens: 0,
951
- duration: 0,
952
- sender: "",
953
- diffs: [],
954
- preview: "",
955
- requestContent: "",
956
- responseContent: ""
957
- };
957
+ var _getValue_default = getValue;
958
+
959
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getNative.js
960
+ function getNative(object, key) {
961
+ var value = _getValue_default(object, key);
962
+ return _baseIsNative_default(value) ? value : undefined;
958
963
  }
959
- function fillConversation(conv) {
960
- if (conv.diffs.length > 0 || conv.startTime || conv.inputTokens > 0)
961
- return;
962
- let inputTokens = 0;
963
- let outputTokens = 0;
964
- let cacheReadInputTokens = 0;
965
- let cacheCreationInputTokens = 0;
966
- let startTime;
967
- let endTime;
968
- conv.events.forEach((evt) => {
969
- if (evt.timestamp) {
970
- const t = new Date(evt.timestamp);
971
- if (!startTime)
972
- startTime = t;
973
- endTime = t;
974
- }
975
- if (evt.message?.usage) {
976
- inputTokens += evt.message.usage.input_tokens || 0;
977
- outputTokens += evt.message.usage.output_tokens || 0;
978
- cacheReadInputTokens += evt.message.usage.cache_read_input_tokens || 0;
979
- cacheCreationInputTokens += evt.message.usage.cache_creation_input_tokens || 0;
980
- }
981
- });
982
- conv.inputTokens = inputTokens;
983
- conv.outputTokens = outputTokens;
984
- conv.cacheCreationInputTokens = cacheCreationInputTokens;
985
- conv.cacheReadInputTokens = cacheReadInputTokens;
986
- conv.startTime = startTime;
987
- conv.endTime = endTime;
988
- conv.duration = startTime && endTime ? (endTime.getTime() - startTime.getTime()) / 1000 : 0;
989
- conv.sender = detectSender(conv.userEvent, conv.events[1]);
990
- conv.requestContent = getTextContent(conv.userEvent.message?.content);
991
- conv.preview = conv.requestContent.substring(0, 80);
992
- const responseTexts = [];
993
- for (let j = 1;j < conv.events.length; j++) {
994
- const text = getTextContent(conv.events[j].message?.content);
995
- if (text)
996
- responseTexts.push(text);
997
- }
998
- const diffs = [];
999
- conv.events.forEach((evt) => {
1000
- if (evt.type === "assistant") {
1001
- diffs.push(...extractEventToolDiff(evt, conv.events));
1002
- }
1003
- });
1004
- conv.diffs = diffs;
1005
- conv.events.forEach((evt) => {
1006
- if (evt.type === "assistant") {
1007
- const { error_code, error_reason } = extractError(evt);
1008
- if (error_code) {
1009
- conv.errorCode = error_code;
1010
- conv.errorReason = error_reason;
1011
- }
1012
- }
1013
- });
964
+ var _getNative_default = getNative;
965
+
966
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeCreate.js
967
+ var nativeCreate = _getNative_default(Object, "create");
968
+ var _nativeCreate_default = nativeCreate;
969
+
970
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashClear.js
971
+ function hashClear() {
972
+ this.__data__ = _nativeCreate_default ? _nativeCreate_default(null) : {};
973
+ this.size = 0;
1014
974
  }
1015
- function splitFlowToConversations(flow) {
1016
- const result = [];
1017
- let i = 0;
1018
- while (i < flow.length) {
1019
- if (flow[i].type !== "user") {
1020
- i++;
1021
- continue;
1022
- }
1023
- const convEvents = [flow[i++]];
1024
- while (i < flow.length && flow[i].type !== "user") {
1025
- convEvents.push(flow[i++]);
1026
- }
1027
- const conversation = createConversation(convEvents);
1028
- result.push(conversation);
1029
- }
975
+ var _hashClear_default = hashClear;
976
+
977
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashDelete.js
978
+ function hashDelete(key) {
979
+ var result = this.has(key) && delete this.__data__[key];
980
+ this.size -= result ? 1 : 0;
1030
981
  return result;
1031
982
  }
1032
- function getTextContent(content) {
1033
- if (!content)
1034
- return "";
1035
- if (typeof content === "string")
1036
- return content;
1037
- if (Array.isArray(content)) {
1038
- return content.map((item) => {
1039
- if (typeof item === "object" && item !== null && item.type === "tool_result") {
1040
- return String(item.content || "");
1041
- }
1042
- if (typeof item === "object" && item !== null && item.type === "text") {
1043
- return String(item.text || "");
1044
- }
1045
- return typeof item === "string" ? item : JSON.stringify(item);
1046
- }).join("");
983
+ var _hashDelete_default = hashDelete;
984
+
985
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashGet.js
986
+ var HASH_UNDEFINED = "__lodash_hash_undefined__";
987
+ var objectProto4 = Object.prototype;
988
+ var hasOwnProperty3 = objectProto4.hasOwnProperty;
989
+ function hashGet(key) {
990
+ var data = this.__data__;
991
+ if (_nativeCreate_default) {
992
+ var result = data[key];
993
+ return result === HASH_UNDEFINED ? undefined : result;
1047
994
  }
1048
- return String(content);
995
+ return hasOwnProperty3.call(data, key) ? data[key] : undefined;
1049
996
  }
1050
- function detectSender(assistant, user) {
1051
- const mode = String(assistant.mode ?? "");
1052
- if (mode === "agent" || mode === "auto")
1053
- return "agent";
1054
- if (assistant.agent)
1055
- return "agent";
1056
- if (assistant.isSidechain === true)
1057
- return "agent";
1058
- if (user?.isMeta === true)
1059
- return "agent";
1060
- return "user";
997
+ var _hashGet_default = hashGet;
998
+
999
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashHas.js
1000
+ var objectProto5 = Object.prototype;
1001
+ var hasOwnProperty4 = objectProto5.hasOwnProperty;
1002
+ function hashHas(key) {
1003
+ var data = this.__data__;
1004
+ return _nativeCreate_default ? data[key] !== undefined : hasOwnProperty4.call(data, key);
1061
1005
  }
1062
- var SDK_ERROR_CODE_MAP = {
1063
- authentication_failed: 401,
1064
- billing_error: 402,
1065
- rate_limit: 429,
1066
- invalid_request: 400,
1067
- server_error: 500,
1068
- max_output_tokens: 413,
1069
- unknown: 500
1070
- };
1071
- function extractError(event) {
1072
- const msg = event.message;
1073
- const error = msg.error;
1074
- if (typeof error === "string") {
1075
- const errorCode = SDK_ERROR_CODE_MAP[error] ?? 500;
1076
- const errorDetails = msg.errorDetails;
1077
- const reason = typeof errorDetails === "string" && errorDetails ? errorDetails : error;
1078
- return { error_code: errorCode, error_reason: reason };
1006
+ var _hashHas_default = hashHas;
1007
+
1008
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashSet.js
1009
+ var HASH_UNDEFINED2 = "__lodash_hash_undefined__";
1010
+ function hashSet(key, value) {
1011
+ var data = this.__data__;
1012
+ this.size += this.has(key) ? 0 : 1;
1013
+ data[key] = _nativeCreate_default && value === undefined ? HASH_UNDEFINED2 : value;
1014
+ return this;
1015
+ }
1016
+ var _hashSet_default = hashSet;
1017
+
1018
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Hash.js
1019
+ function Hash(entries) {
1020
+ var index = -1, length = entries == null ? 0 : entries.length;
1021
+ this.clear();
1022
+ while (++index < length) {
1023
+ var entry = entries[index];
1024
+ this.set(entry[0], entry[1]);
1079
1025
  }
1080
- if (typeof error === "object" && error !== null) {
1081
- const err = error;
1082
- const apiError = msg.apiError;
1083
- if (typeof apiError === "string" && apiError === "max_output_tokens") {
1084
- const reason = typeof err.message === "string" ? err.message : "max_output_tokens";
1085
- return { error_code: 413, error_reason: reason };
1026
+ }
1027
+ Hash.prototype.clear = _hashClear_default;
1028
+ Hash.prototype["delete"] = _hashDelete_default;
1029
+ Hash.prototype.get = _hashGet_default;
1030
+ Hash.prototype.has = _hashHas_default;
1031
+ Hash.prototype.set = _hashSet_default;
1032
+ var _Hash_default = Hash;
1033
+
1034
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheClear.js
1035
+ function listCacheClear() {
1036
+ this.__data__ = [];
1037
+ this.size = 0;
1038
+ }
1039
+ var _listCacheClear_default = listCacheClear;
1040
+
1041
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/eq.js
1042
+ function eq(value, other) {
1043
+ return value === other || value !== value && other !== other;
1044
+ }
1045
+ var eq_default = eq;
1046
+
1047
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_assocIndexOf.js
1048
+ function assocIndexOf(array, key) {
1049
+ var length = array.length;
1050
+ while (length--) {
1051
+ if (eq_default(array[length][0], key)) {
1052
+ return length;
1086
1053
  }
1087
- const name = String(err.name ?? "UnknownError");
1088
- const errMessage = typeof err.message === "string" ? err.message : name;
1089
- const errorCode = name === "ProviderAuthError" ? 401 : name === "ContextOverflowError" || name === "MessageOutputLengthError" ? 413 : name === "MessageAbortedError" ? 499 : name === "APIError" && typeof err.statusCode === "number" ? err.statusCode : 500;
1090
- return { error_code: errorCode, error_reason: errMessage };
1091
- }
1092
- if (msg.isApiErrorMessage) {
1093
- return { error_code: 500, error_reason: "api_error_unclassified" };
1094
1054
  }
1095
- return {};
1055
+ return -1;
1096
1056
  }
1097
- function structuredPatchToUnifiedDiff(filePath, patches) {
1098
- if (!patches.length)
1099
- return "";
1100
- const header = `--- a/${filePath}
1101
- +++ b/${filePath}`;
1102
- const hunks = [];
1103
- for (const p of patches) {
1104
- const oldStart = p.oldStart ?? 1;
1105
- const oldLines = p.oldLines ?? 0;
1106
- const newStart = p.newStart ?? 1;
1107
- const newLines = p.newLines ?? 0;
1108
- const lines = p.lines ?? [];
1109
- hunks.push(`@@ -${oldStart},${oldLines} +${newStart},${newLines} @@
1110
- ${lines.join(`
1111
- `)}`);
1057
+ var _assocIndexOf_default = assocIndexOf;
1058
+
1059
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheDelete.js
1060
+ var arrayProto = Array.prototype;
1061
+ var splice = arrayProto.splice;
1062
+ function listCacheDelete(key) {
1063
+ var data = this.__data__, index = _assocIndexOf_default(data, key);
1064
+ if (index < 0) {
1065
+ return false;
1112
1066
  }
1113
- return header + `
1114
- ` + hunks.join(`
1115
- `) + `
1116
- `;
1067
+ var lastIndex = data.length - 1;
1068
+ if (index == lastIndex) {
1069
+ data.pop();
1070
+ } else {
1071
+ splice.call(data, index, 1);
1072
+ }
1073
+ --this.size;
1074
+ return true;
1117
1075
  }
1118
- function generateStringDiff(filePath, oldStr, newStr) {
1119
- const oldLines = oldStr.split(`
1120
- `);
1121
- const newLines = newStr.split(`
1122
- `);
1123
- const header = `--- a/${filePath}
1124
- +++ b/${filePath}`;
1125
- const hunk = `@@ -1,${oldLines.length} +1,${newLines.length} @@`;
1126
- const body = oldLines.map((l) => `-${l}`).concat(newLines.map((l) => `+${l}`)).join(`
1127
- `);
1128
- return header + `
1129
- ` + hunk + `
1130
- ` + body + `
1131
- `;
1076
+ var _listCacheDelete_default = listCacheDelete;
1077
+
1078
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheGet.js
1079
+ function listCacheGet(key) {
1080
+ var data = this.__data__, index = _assocIndexOf_default(data, key);
1081
+ return index < 0 ? undefined : data[index][1];
1132
1082
  }
1133
- function extractEventToolDiff(assistantEvent, allEvents) {
1134
- const diffs = [];
1135
- const msgUuid = assistantEvent.uuid;
1136
- const handledToolUseIds = new Set;
1137
- if (!msgUuid)
1138
- return diffs;
1139
- for (const m of allEvents) {
1140
- if (m.parentUuid !== msgUuid || m.type !== "user")
1141
- continue;
1142
- const tur = m.toolUseResult ?? m.tool_use_result;
1143
- if (!tur)
1144
- continue;
1145
- const filePath = tur.filePath ?? tur.file_path ?? tur.notebook_path ?? "";
1146
- const gitDiff = tur.gitDiff;
1147
- if (gitDiff?.patch && typeof gitDiff.patch === "string" && gitDiff.patch) {
1148
- diffs.push({ file: filePath || String(gitDiff.filename ?? ""), content: gitDiff.patch });
1149
- if (Array.isArray(m.message?.content)) {
1150
- for (const b of m.message.content) {
1151
- if (b?.type === "tool_result" && typeof b.tool_use_id === "string") {
1152
- handledToolUseIds.add(b.tool_use_id);
1153
- }
1154
- }
1155
- }
1156
- continue;
1157
- }
1158
- const sp = tur.structuredPatch;
1159
- if (Array.isArray(sp) && sp.length > 0 && filePath) {
1160
- diffs.push({ file: filePath, content: structuredPatchToUnifiedDiff(filePath, sp) });
1161
- if (Array.isArray(m.message?.content)) {
1162
- for (const b of m.message.content) {
1163
- if (b?.type === "tool_result" && typeof b.tool_use_id === "string") {
1164
- handledToolUseIds.add(b.tool_use_id);
1165
- }
1166
- }
1167
- }
1168
- continue;
1169
- }
1170
- const oldStr = tur.oldString ?? tur.old_string ?? tur.originalFile ?? tur.original_file;
1171
- const newStr = tur.newString ?? tur.new_string ?? tur.content ?? tur.updated_file;
1172
- if (filePath && typeof oldStr === "string" && typeof newStr === "string") {
1173
- diffs.push({ file: filePath, content: generateStringDiff(filePath, oldStr, newStr) });
1174
- } else if (filePath && typeof newStr === "string") {
1175
- diffs.push({ file: filePath, content: generateStringDiff(filePath, "", newStr) });
1176
- }
1083
+ var _listCacheGet_default = listCacheGet;
1084
+
1085
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheHas.js
1086
+ function listCacheHas(key) {
1087
+ return _assocIndexOf_default(this.__data__, key) > -1;
1088
+ }
1089
+ var _listCacheHas_default = listCacheHas;
1090
+
1091
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheSet.js
1092
+ function listCacheSet(key, value) {
1093
+ var data = this.__data__, index = _assocIndexOf_default(data, key);
1094
+ if (index < 0) {
1095
+ ++this.size;
1096
+ data.push([key, value]);
1097
+ } else {
1098
+ data[index][1] = value;
1177
1099
  }
1178
- const content = assistantEvent.message?.content;
1179
- if (Array.isArray(content)) {
1180
- for (const block of content) {
1181
- if (block?.type !== "tool_use")
1182
- continue;
1183
- if (typeof block.id === "string" && handledToolUseIds.has(block.id))
1184
- continue;
1185
- const input = block.input;
1186
- const toolName = block.name;
1187
- const filePath = input?.file_path ?? input?.notebook_path ?? "";
1188
- if (toolName === "Edit" && typeof input?.old_string === "string" && typeof input?.new_string === "string") {
1189
- diffs.push({ file: filePath, content: generateStringDiff(filePath, input.old_string, input.new_string) });
1190
- } else if (toolName === "NotebookEdit" && typeof input?.new_source === "string" && filePath) {
1191
- diffs.push({ file: filePath, content: generateStringDiff(filePath, "", input.new_source) });
1192
- } else if (typeof input?.diff === "string" && input.diff) {
1193
- diffs.push({ file: filePath, content: input.diff });
1194
- } else if (typeof input?.patch === "string" && input.patch) {
1195
- diffs.push({ file: filePath, content: input.patch });
1196
- }
1197
- }
1100
+ return this;
1101
+ }
1102
+ var _listCacheSet_default = listCacheSet;
1103
+
1104
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_ListCache.js
1105
+ function ListCache(entries) {
1106
+ var index = -1, length = entries == null ? 0 : entries.length;
1107
+ this.clear();
1108
+ while (++index < length) {
1109
+ var entry = entries[index];
1110
+ this.set(entry[0], entry[1]);
1198
1111
  }
1199
- return diffs;
1200
1112
  }
1201
- function parseSession(cacheConversations, events) {
1202
- const sessionId = events.find((e) => e.sessionId)?.sessionId || "unknown";
1203
- const version = events.find((e) => e.version)?.version || "";
1204
- const cwd = events.find((e) => e.cwd)?.cwd || "";
1205
- const gitBranch = events.find((e) => e.gitBranch)?.gitBranch || "";
1206
- const conversations = [];
1207
- let totalInputTokens = 0;
1208
- let totalOutputTokens = 0;
1209
- let totalCacheReadInputTokens = 0;
1210
- let totalCacheCreationInputTokens = 0;
1211
- let totalDuration = 0;
1212
- events.forEach((evt) => {
1213
- if (evt.message?.usage) {
1214
- totalInputTokens += evt.message.usage.input_tokens || 0;
1215
- totalOutputTokens += evt.message.usage.output_tokens || 0;
1216
- totalCacheReadInputTokens += evt.message.usage.cache_read_input_tokens || 0;
1217
- totalCacheCreationInputTokens += evt.message.usage.cache_creation_input_tokens || 0;
1218
- }
1219
- });
1220
- const flows = buildFlows(events);
1221
- flows.forEach((flow) => {
1222
- const convResults = splitFlowToConversations(flow);
1223
- convResults.forEach((conversation) => {
1224
- const cached = cacheConversations.find((c) => c.id === conversation.id);
1225
- if (cached && cached.events.length === conversation.events.length) {
1226
- conversations.push(cached);
1227
- } else {
1228
- conversations.push(conversation);
1229
- }
1230
- totalDuration += conversation.duration;
1231
- });
1232
- });
1233
- conversations.sort((a, b) => new Date(a.userEvent.timestamp).getTime() - new Date(b.userEvent.timestamp).getTime());
1234
- conversations.forEach((conv, i) => {
1235
- conv.index = i;
1236
- });
1237
- conversations.forEach((conv) => fillConversation(conv));
1238
- return {
1239
- id: sessionId,
1240
- version,
1241
- cwd,
1242
- gitBranch,
1243
- conversations,
1244
- eventCount: events.length,
1245
- totalInputTokens,
1246
- totalOutputTokens,
1247
- totalCacheCreationInputTokens,
1248
- totalCacheReadInputTokens,
1249
- totalTokens: totalInputTokens + totalOutputTokens,
1250
- totalDuration
1113
+ ListCache.prototype.clear = _listCacheClear_default;
1114
+ ListCache.prototype["delete"] = _listCacheDelete_default;
1115
+ ListCache.prototype.get = _listCacheGet_default;
1116
+ ListCache.prototype.has = _listCacheHas_default;
1117
+ ListCache.prototype.set = _listCacheSet_default;
1118
+ var _ListCache_default = ListCache;
1119
+
1120
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Map.js
1121
+ var Map2 = _getNative_default(_root_default, "Map");
1122
+ var _Map_default = Map2;
1123
+
1124
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheClear.js
1125
+ function mapCacheClear() {
1126
+ this.size = 0;
1127
+ this.__data__ = {
1128
+ hash: new _Hash_default,
1129
+ map: new (_Map_default || _ListCache_default),
1130
+ string: new _Hash_default
1251
1131
  };
1252
1132
  }
1133
+ var _mapCacheClear_default = mapCacheClear;
1253
1134
 
1254
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_freeGlobal.js
1255
- var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
1256
- var _freeGlobal_default = freeGlobal;
1257
-
1258
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_root.js
1259
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
1260
- var root = _freeGlobal_default || freeSelf || Function("return this")();
1261
- var _root_default = root;
1135
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isKeyable.js
1136
+ function isKeyable(value) {
1137
+ var type = typeof value;
1138
+ return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
1139
+ }
1140
+ var _isKeyable_default = isKeyable;
1262
1141
 
1263
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Symbol.js
1264
- var Symbol2 = _root_default.Symbol;
1265
- var _Symbol_default = Symbol2;
1142
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getMapData.js
1143
+ function getMapData(map, key) {
1144
+ var data = map.__data__;
1145
+ return _isKeyable_default(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
1146
+ }
1147
+ var _getMapData_default = getMapData;
1266
1148
 
1267
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getRawTag.js
1268
- var objectProto = Object.prototype;
1269
- var hasOwnProperty = objectProto.hasOwnProperty;
1270
- var nativeObjectToString = objectProto.toString;
1271
- var symToStringTag = _Symbol_default ? _Symbol_default.toStringTag : undefined;
1272
- function getRawTag(value) {
1273
- var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
1274
- try {
1275
- value[symToStringTag] = undefined;
1276
- var unmasked = true;
1277
- } catch (e) {}
1278
- var result = nativeObjectToString.call(value);
1279
- if (unmasked) {
1280
- if (isOwn) {
1281
- value[symToStringTag] = tag;
1282
- } else {
1283
- delete value[symToStringTag];
1284
- }
1285
- }
1149
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheDelete.js
1150
+ function mapCacheDelete(key) {
1151
+ var result = _getMapData_default(this, key)["delete"](key);
1152
+ this.size -= result ? 1 : 0;
1286
1153
  return result;
1287
1154
  }
1288
- var _getRawTag_default = getRawTag;
1155
+ var _mapCacheDelete_default = mapCacheDelete;
1289
1156
 
1290
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_objectToString.js
1291
- var objectProto2 = Object.prototype;
1292
- var nativeObjectToString2 = objectProto2.toString;
1293
- function objectToString(value) {
1294
- return nativeObjectToString2.call(value);
1157
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheGet.js
1158
+ function mapCacheGet(key) {
1159
+ return _getMapData_default(this, key).get(key);
1295
1160
  }
1296
- var _objectToString_default = objectToString;
1161
+ var _mapCacheGet_default = mapCacheGet;
1297
1162
 
1298
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetTag.js
1299
- var nullTag = "[object Null]";
1300
- var undefinedTag = "[object Undefined]";
1301
- var symToStringTag2 = _Symbol_default ? _Symbol_default.toStringTag : undefined;
1302
- function baseGetTag(value) {
1303
- if (value == null) {
1304
- return value === undefined ? undefinedTag : nullTag;
1305
- }
1306
- return symToStringTag2 && symToStringTag2 in Object(value) ? _getRawTag_default(value) : _objectToString_default(value);
1163
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheHas.js
1164
+ function mapCacheHas(key) {
1165
+ return _getMapData_default(this, key).has(key);
1307
1166
  }
1308
- var _baseGetTag_default = baseGetTag;
1167
+ var _mapCacheHas_default = mapCacheHas;
1309
1168
 
1310
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObject.js
1311
- function isObject(value) {
1312
- var type = typeof value;
1313
- return value != null && (type == "object" || type == "function");
1169
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheSet.js
1170
+ function mapCacheSet(key, value) {
1171
+ var data = _getMapData_default(this, key), size = data.size;
1172
+ data.set(key, value);
1173
+ this.size += data.size == size ? 0 : 1;
1174
+ return this;
1314
1175
  }
1315
- var isObject_default = isObject;
1176
+ var _mapCacheSet_default = mapCacheSet;
1316
1177
 
1317
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isFunction.js
1318
- var asyncTag = "[object AsyncFunction]";
1319
- var funcTag = "[object Function]";
1320
- var genTag = "[object GeneratorFunction]";
1321
- var proxyTag = "[object Proxy]";
1322
- function isFunction(value) {
1323
- if (!isObject_default(value)) {
1324
- return false;
1178
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_MapCache.js
1179
+ function MapCache(entries) {
1180
+ var index = -1, length = entries == null ? 0 : entries.length;
1181
+ this.clear();
1182
+ while (++index < length) {
1183
+ var entry = entries[index];
1184
+ this.set(entry[0], entry[1]);
1325
1185
  }
1326
- var tag = _baseGetTag_default(value);
1327
- return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
1328
1186
  }
1329
- var isFunction_default = isFunction;
1187
+ MapCache.prototype.clear = _mapCacheClear_default;
1188
+ MapCache.prototype["delete"] = _mapCacheDelete_default;
1189
+ MapCache.prototype.get = _mapCacheGet_default;
1190
+ MapCache.prototype.has = _mapCacheHas_default;
1191
+ MapCache.prototype.set = _mapCacheSet_default;
1192
+ var _MapCache_default = MapCache;
1330
1193
 
1331
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_coreJsData.js
1332
- var coreJsData = _root_default["__core-js_shared__"];
1333
- var _coreJsData_default = coreJsData;
1334
-
1335
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isMasked.js
1336
- var maskSrcKey = function() {
1337
- var uid = /[^.]+$/.exec(_coreJsData_default && _coreJsData_default.keys && _coreJsData_default.keys.IE_PROTO || "");
1338
- return uid ? "Symbol(src)_1." + uid : "";
1339
- }();
1340
- function isMasked(func) {
1341
- return !!maskSrcKey && maskSrcKey in func;
1342
- }
1343
- var _isMasked_default = isMasked;
1344
-
1345
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_toSource.js
1346
- var funcProto = Function.prototype;
1347
- var funcToString = funcProto.toString;
1348
- function toSource(func) {
1349
- if (func != null) {
1350
- try {
1351
- return funcToString.call(func);
1352
- } catch (e) {}
1353
- try {
1354
- return func + "";
1355
- } catch (e) {}
1356
- }
1357
- return "";
1358
- }
1359
- var _toSource_default = toSource;
1360
-
1361
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsNative.js
1362
- var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
1363
- var reIsHostCtor = /^\[object .+?Constructor\]$/;
1364
- var funcProto2 = Function.prototype;
1365
- var objectProto3 = Object.prototype;
1366
- var funcToString2 = funcProto2.toString;
1367
- var hasOwnProperty2 = objectProto3.hasOwnProperty;
1368
- var reIsNative = RegExp("^" + funcToString2.call(hasOwnProperty2).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$");
1369
- function baseIsNative(value) {
1370
- if (!isObject_default(value) || _isMasked_default(value)) {
1371
- return false;
1194
+ // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/memoize.js
1195
+ var FUNC_ERROR_TEXT = "Expected a function";
1196
+ function memoize(func, resolver) {
1197
+ if (typeof func != "function" || resolver != null && typeof resolver != "function") {
1198
+ throw new TypeError(FUNC_ERROR_TEXT);
1372
1199
  }
1373
- var pattern = isFunction_default(value) ? reIsNative : reIsHostCtor;
1374
- return pattern.test(_toSource_default(value));
1375
- }
1376
- var _baseIsNative_default = baseIsNative;
1377
-
1378
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getValue.js
1379
- function getValue(object, key) {
1380
- return object == null ? undefined : object[key];
1381
- }
1382
- var _getValue_default = getValue;
1383
-
1384
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getNative.js
1385
- function getNative(object, key) {
1386
- var value = _getValue_default(object, key);
1387
- return _baseIsNative_default(value) ? value : undefined;
1200
+ var memoized = function() {
1201
+ var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache = memoized.cache;
1202
+ if (cache.has(key)) {
1203
+ return cache.get(key);
1204
+ }
1205
+ var result = func.apply(this, args);
1206
+ memoized.cache = cache.set(key, result) || cache;
1207
+ return result;
1208
+ };
1209
+ memoized.cache = new (memoize.Cache || _MapCache_default);
1210
+ return memoized;
1388
1211
  }
1389
- var _getNative_default = getNative;
1390
-
1391
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeCreate.js
1392
- var nativeCreate = _getNative_default(Object, "create");
1393
- var _nativeCreate_default = nativeCreate;
1212
+ memoize.Cache = _MapCache_default;
1213
+ var memoize_default = memoize;
1394
1214
 
1395
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashClear.js
1396
- function hashClear() {
1397
- this.__data__ = _nativeCreate_default ? _nativeCreate_default(null) : {};
1398
- this.size = 0;
1399
- }
1400
- var _hashClear_default = hashClear;
1215
+ // src/utils/envUtils.ts
1216
+ import { homedir as homedir2 } from "os";
1217
+ import { join as join2 } from "path";
1401
1218
 
1402
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashDelete.js
1403
- function hashDelete(key) {
1404
- var result = this.has(key) && delete this.__data__[key];
1405
- this.size -= result ? 1 : 0;
1406
- return result;
1407
- }
1408
- var _hashDelete_default = hashDelete;
1219
+ // src/constants/branding.ts
1220
+ var PRODUCT_URL = "https://costrict.ai";
1221
+ var PRODUCT_DOCS_URL = `${PRODUCT_URL}/docs`;
1222
+ var PRODUCT_CHROME_URL = `${PRODUCT_URL}/chrome`;
1223
+ var PRODUCT_SETTINGS_URL = `${PRODUCT_URL}/settings`;
1224
+ var PRODUCT_CODE_URL = `${PRODUCT_URL}/code`;
1225
+ var PRODUCT_SESSION_URL = `${PRODUCT_URL}/session`;
1226
+ var PRODUCT_UPGRADE_URL = `${PRODUCT_URL}/upgrade/max`;
1227
+ var PRODUCT_DOWNLOAD_URL = `${PRODUCT_URL}/download`;
1228
+ var PRODUCT_DESKTOP_API_URL = `${PRODUCT_URL}/api/desktop`;
1229
+ var PRODUCT_OAUTH_CLIENT_METADATA_URL = `${PRODUCT_URL}/oauth/costrict-client-metadata`;
1230
+ var CONFIG_DIR_NAME = ".costrict";
1231
+ var LEGACY_CONFIG_DIR_NAME = ".claude";
1409
1232
 
1410
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashGet.js
1411
- var HASH_UNDEFINED = "__lodash_hash_undefined__";
1412
- var objectProto4 = Object.prototype;
1413
- var hasOwnProperty3 = objectProto4.hasOwnProperty;
1414
- function hashGet(key) {
1415
- var data = this.__data__;
1416
- if (_nativeCreate_default) {
1417
- var result = data[key];
1418
- return result === HASH_UNDEFINED ? undefined : result;
1233
+ // src/utils/envUtils.ts
1234
+ var getCostrictConfigHomeDir = memoize_default(() => {
1235
+ return (process.env.COSTRICT_CONFIG_DIR ?? process.env.CLAUDE_CONFIG_DIR ?? join2(homedir2(), CONFIG_DIR_NAME)).normalize("NFC");
1236
+ }, () => process.env.COSTRICT_CONFIG_DIR ?? process.env.CLAUDE_CONFIG_DIR);
1237
+ var getClaudeConfigHomeDir = getCostrictConfigHomeDir;
1238
+ function getLegacyConfigHomeDir() {
1239
+ if (process.env.COSTRICT_CONFIG_DIR || process.env.CLAUDE_CONFIG_DIR) {
1240
+ return;
1419
1241
  }
1420
- return hasOwnProperty3.call(data, key) ? data[key] : undefined;
1242
+ return join2(homedir2(), LEGACY_CONFIG_DIR_NAME).normalize("NFC");
1421
1243
  }
1422
- var _hashGet_default = hashGet;
1423
1244
 
1424
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashHas.js
1425
- var objectProto5 = Object.prototype;
1426
- var hasOwnProperty4 = objectProto5.hasOwnProperty;
1427
- function hashHas(key) {
1428
- var data = this.__data__;
1429
- return _nativeCreate_default ? data[key] !== undefined : hasOwnProperty4.call(data, key);
1430
- }
1431
- var _hashHas_default = hashHas;
1432
-
1433
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashSet.js
1434
- var HASH_UNDEFINED2 = "__lodash_hash_undefined__";
1435
- function hashSet(key, value) {
1436
- var data = this.__data__;
1437
- this.size += this.has(key) ? 0 : 1;
1438
- data[key] = _nativeCreate_default && value === undefined ? HASH_UNDEFINED2 : value;
1439
- return this;
1440
- }
1441
- var _hashSet_default = hashSet;
1442
-
1443
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Hash.js
1444
- function Hash(entries) {
1445
- var index = -1, length = entries == null ? 0 : entries.length;
1446
- this.clear();
1447
- while (++index < length) {
1448
- var entry = entries[index];
1449
- this.set(entry[0], entry[1]);
1245
+ // src/services/rawDump/history.ts
1246
+ var HISTORY_FILE = path5.join(getClaudeConfigHomeDir(), "history.jsonl");
1247
+ var LEGACY_HISTORY_FILE = (() => {
1248
+ const legacy = getLegacyConfigHomeDir();
1249
+ return legacy ? path5.join(legacy, "history.jsonl") : null;
1250
+ })();
1251
+ async function resolveHistoryFilePath() {
1252
+ try {
1253
+ const s = await fs5.stat(HISTORY_FILE);
1254
+ return { path: HISTORY_FILE, mtimeMs: Number(s.mtimeMs), size: Number(s.size) };
1255
+ } catch {}
1256
+ if (LEGACY_HISTORY_FILE) {
1257
+ try {
1258
+ const s = await fs5.stat(LEGACY_HISTORY_FILE);
1259
+ return { path: LEGACY_HISTORY_FILE, mtimeMs: Number(s.mtimeMs), size: Number(s.size) };
1260
+ } catch {}
1450
1261
  }
1262
+ return null;
1451
1263
  }
1452
- Hash.prototype.clear = _hashClear_default;
1453
- Hash.prototype["delete"] = _hashDelete_default;
1454
- Hash.prototype.get = _hashGet_default;
1455
- Hash.prototype.has = _hashHas_default;
1456
- Hash.prototype.set = _hashSet_default;
1457
- var _Hash_default = Hash;
1458
-
1459
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheClear.js
1460
- function listCacheClear() {
1461
- this.__data__ = [];
1462
- this.size = 0;
1463
- }
1464
- var _listCacheClear_default = listCacheClear;
1465
-
1466
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/eq.js
1467
- function eq(value, other) {
1468
- return value === other || value !== value && other !== other;
1469
- }
1470
- var eq_default = eq;
1471
-
1472
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_assocIndexOf.js
1473
- function assocIndexOf(array, key) {
1474
- var length = array.length;
1475
- while (length--) {
1476
- if (eq_default(array[length][0], key)) {
1477
- return length;
1264
+ var cache = null;
1265
+ async function loadHistory() {
1266
+ const items = [];
1267
+ const resolved = await resolveHistoryFilePath();
1268
+ if (!resolved) {
1269
+ cache = null;
1270
+ return [];
1271
+ }
1272
+ const { path: historyFile, mtimeMs, size } = resolved;
1273
+ try {
1274
+ const content = await fs5.readFile(historyFile, "utf-8");
1275
+ const lines = content.split(`
1276
+ `);
1277
+ for (const line of lines) {
1278
+ if (!line.trim())
1279
+ continue;
1280
+ try {
1281
+ const item = JSON.parse(line);
1282
+ items.push(item);
1283
+ } catch {}
1478
1284
  }
1285
+ } catch {
1286
+ return cache?.items ?? [];
1479
1287
  }
1480
- return -1;
1288
+ cache = {
1289
+ mtime: mtimeMs,
1290
+ size,
1291
+ items
1292
+ };
1293
+ return cache.items;
1481
1294
  }
1482
- var _assocIndexOf_default = assocIndexOf;
1483
-
1484
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheDelete.js
1485
- var arrayProto = Array.prototype;
1486
- var splice = arrayProto.splice;
1487
- function listCacheDelete(key) {
1488
- var data = this.__data__, index = _assocIndexOf_default(data, key);
1489
- if (index < 0) {
1490
- return false;
1491
- }
1492
- var lastIndex = data.length - 1;
1493
- if (index == lastIndex) {
1494
- data.pop();
1495
- } else {
1496
- splice.call(data, index, 1);
1295
+ async function autoLoadHistory() {
1296
+ const resolved = await resolveHistoryFilePath();
1297
+ if (!resolved) {
1298
+ if (cache) {
1299
+ return null;
1300
+ }
1301
+ return [];
1497
1302
  }
1498
- --this.size;
1499
- return true;
1500
- }
1501
- var _listCacheDelete_default = listCacheDelete;
1502
-
1503
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheGet.js
1504
- function listCacheGet(key) {
1505
- var data = this.__data__, index = _assocIndexOf_default(data, key);
1506
- return index < 0 ? undefined : data[index][1];
1507
- }
1508
- var _listCacheGet_default = listCacheGet;
1509
-
1510
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheHas.js
1511
- function listCacheHas(key) {
1512
- return _assocIndexOf_default(this.__data__, key) > -1;
1513
- }
1514
- var _listCacheHas_default = listCacheHas;
1515
-
1516
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheSet.js
1517
- function listCacheSet(key, value) {
1518
- var data = this.__data__, index = _assocIndexOf_default(data, key);
1519
- if (index < 0) {
1520
- ++this.size;
1521
- data.push([key, value]);
1522
- } else {
1523
- data[index][1] = value;
1303
+ if (cache && cache.mtime === resolved.mtimeMs && cache.size === resolved.size) {
1304
+ return cache.items;
1524
1305
  }
1525
- return this;
1306
+ return await loadHistory();
1526
1307
  }
1527
- var _listCacheSet_default = listCacheSet;
1528
-
1529
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_ListCache.js
1530
- function ListCache(entries) {
1531
- var index = -1, length = entries == null ? 0 : entries.length;
1532
- this.clear();
1533
- while (++index < length) {
1534
- var entry = entries[index];
1535
- this.set(entry[0], entry[1]);
1308
+ async function getProjectDirs() {
1309
+ if (cache) {
1310
+ const resolved = await resolveHistoryFilePath();
1311
+ if (!resolved) {
1312
+ return [...new Set(cache.items.map((item) => item.project))];
1313
+ }
1314
+ if (resolved.mtimeMs === cache.mtime && resolved.size === cache.size) {
1315
+ return [...new Set(cache.items.map((item) => item.project))];
1316
+ }
1536
1317
  }
1318
+ const items = await loadHistory();
1319
+ return [...new Set(items.map((item) => item.project))];
1537
1320
  }
1538
- ListCache.prototype.clear = _listCacheClear_default;
1539
- ListCache.prototype["delete"] = _listCacheDelete_default;
1540
- ListCache.prototype.get = _listCacheGet_default;
1541
- ListCache.prototype.has = _listCacheHas_default;
1542
- ListCache.prototype.set = _listCacheSet_default;
1543
- var _ListCache_default = ListCache;
1544
1321
 
1545
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Map.js
1546
- var Map2 = _getNative_default(_root_default, "Map");
1547
- var _Map_default = Map2;
1322
+ // src/services/rawDump/session.ts
1323
+ import { promises as fs6 } from "fs";
1324
+ import path6 from "path";
1548
1325
 
1549
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheClear.js
1550
- function mapCacheClear() {
1551
- this.size = 0;
1552
- this.__data__ = {
1553
- hash: new _Hash_default,
1554
- map: new (_Map_default || _ListCache_default),
1555
- string: new _Hash_default
1556
- };
1326
+ // src/services/rawDump/parse.ts
1327
+ function buildFlows(events) {
1328
+ const childIndex = new Map;
1329
+ events.forEach((e) => {
1330
+ if (e.parentUuid) {
1331
+ if (!childIndex.has(e.parentUuid))
1332
+ childIndex.set(e.parentUuid, []);
1333
+ childIndex.get(e.parentUuid).push(e);
1334
+ }
1335
+ });
1336
+ const visited = new Set;
1337
+ const flows = [];
1338
+ events.forEach((e, i) => {
1339
+ const key = e.uuid || `__idx__${i}`;
1340
+ if (visited.has(key))
1341
+ return;
1342
+ if (!e.parentUuid) {
1343
+ const flow = [];
1344
+ const queue2 = [e];
1345
+ while (queue2.length > 0) {
1346
+ const curr = queue2.shift();
1347
+ const currKey = curr.uuid || `__idx__${events.indexOf(curr)}`;
1348
+ if (visited.has(currKey))
1349
+ continue;
1350
+ visited.add(currKey);
1351
+ flow.push(curr);
1352
+ const children = childIndex.get(currKey) || [];
1353
+ children.forEach((child) => {
1354
+ const childKey = child.uuid || `__idx__${events.indexOf(child)}`;
1355
+ if (!visited.has(childKey))
1356
+ queue2.push(child);
1357
+ });
1358
+ }
1359
+ if (flow.length > 0) {
1360
+ flow.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
1361
+ flows.push(flow);
1362
+ }
1363
+ }
1364
+ });
1365
+ return flows;
1557
1366
  }
1558
- var _mapCacheClear_default = mapCacheClear;
1559
-
1560
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isKeyable.js
1561
- function isKeyable(value) {
1562
- var type = typeof value;
1563
- return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
1367
+ function createConversation(convEvents) {
1368
+ const userEvent = convEvents[0];
1369
+ return {
1370
+ id: userEvent.uuid,
1371
+ index: -1,
1372
+ promptId: userEvent.promptId || "",
1373
+ userEvent,
1374
+ events: convEvents,
1375
+ inputTokens: 0,
1376
+ outputTokens: 0,
1377
+ cacheReadInputTokens: 0,
1378
+ cacheCreationInputTokens: 0,
1379
+ totalTokens: 0,
1380
+ duration: 0,
1381
+ sender: "",
1382
+ diffs: [],
1383
+ preview: "",
1384
+ requestContent: "",
1385
+ responseContent: ""
1386
+ };
1564
1387
  }
1565
- var _isKeyable_default = isKeyable;
1566
-
1567
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getMapData.js
1568
- function getMapData(map, key) {
1569
- var data = map.__data__;
1570
- return _isKeyable_default(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
1388
+ function fillConversation(conv) {
1389
+ if (conv.diffs.length > 0 || conv.startTime || conv.inputTokens > 0)
1390
+ return;
1391
+ let inputTokens = 0;
1392
+ let outputTokens = 0;
1393
+ let cacheReadInputTokens = 0;
1394
+ let cacheCreationInputTokens = 0;
1395
+ let startTime;
1396
+ let endTime;
1397
+ conv.events.forEach((evt) => {
1398
+ if (evt.timestamp) {
1399
+ const t = new Date(evt.timestamp);
1400
+ if (!startTime)
1401
+ startTime = t;
1402
+ endTime = t;
1403
+ }
1404
+ if (evt.message?.usage) {
1405
+ inputTokens += evt.message.usage.input_tokens || 0;
1406
+ outputTokens += evt.message.usage.output_tokens || 0;
1407
+ cacheReadInputTokens += evt.message.usage.cache_read_input_tokens || 0;
1408
+ cacheCreationInputTokens += evt.message.usage.cache_creation_input_tokens || 0;
1409
+ }
1410
+ });
1411
+ conv.inputTokens = inputTokens;
1412
+ conv.outputTokens = outputTokens;
1413
+ conv.cacheCreationInputTokens = cacheCreationInputTokens;
1414
+ conv.cacheReadInputTokens = cacheReadInputTokens;
1415
+ conv.startTime = startTime;
1416
+ conv.endTime = endTime;
1417
+ conv.duration = startTime && endTime ? (endTime.getTime() - startTime.getTime()) / 1000 : 0;
1418
+ conv.sender = detectSender(conv.userEvent, conv.events[1]);
1419
+ conv.requestContent = getTextContent(conv.userEvent.message?.content);
1420
+ conv.preview = conv.requestContent.substring(0, 80);
1421
+ const responseTexts = [];
1422
+ for (let j = 1;j < conv.events.length; j++) {
1423
+ const text = getTextContent(conv.events[j].message?.content);
1424
+ if (text)
1425
+ responseTexts.push(text);
1426
+ }
1427
+ const diffs = [];
1428
+ conv.events.forEach((evt) => {
1429
+ if (evt.type === "assistant") {
1430
+ diffs.push(...extractEventToolDiff(evt, conv.events));
1431
+ }
1432
+ });
1433
+ conv.diffs = diffs;
1434
+ conv.events.forEach((evt) => {
1435
+ if (evt.type === "assistant") {
1436
+ const { error_code, error_reason } = extractError(evt);
1437
+ if (error_code) {
1438
+ conv.errorCode = error_code;
1439
+ conv.errorReason = error_reason;
1440
+ }
1441
+ }
1442
+ });
1571
1443
  }
1572
- var _getMapData_default = getMapData;
1573
-
1574
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheDelete.js
1575
- function mapCacheDelete(key) {
1576
- var result = _getMapData_default(this, key)["delete"](key);
1577
- this.size -= result ? 1 : 0;
1444
+ function splitFlowToConversations(flow) {
1445
+ const result = [];
1446
+ let i = 0;
1447
+ while (i < flow.length) {
1448
+ if (flow[i].type !== "user") {
1449
+ i++;
1450
+ continue;
1451
+ }
1452
+ const convEvents = [flow[i++]];
1453
+ while (i < flow.length && flow[i].type !== "user") {
1454
+ convEvents.push(flow[i++]);
1455
+ }
1456
+ const conversation = createConversation(convEvents);
1457
+ result.push(conversation);
1458
+ }
1578
1459
  return result;
1579
1460
  }
1580
- var _mapCacheDelete_default = mapCacheDelete;
1581
-
1582
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheGet.js
1583
- function mapCacheGet(key) {
1584
- return _getMapData_default(this, key).get(key);
1461
+ function getTextContent(content) {
1462
+ if (!content)
1463
+ return "";
1464
+ if (typeof content === "string")
1465
+ return content;
1466
+ if (Array.isArray(content)) {
1467
+ return content.map((item) => {
1468
+ if (typeof item === "object" && item !== null && item.type === "tool_result") {
1469
+ return String(item.content || "");
1470
+ }
1471
+ if (typeof item === "object" && item !== null && item.type === "text") {
1472
+ return String(item.text || "");
1473
+ }
1474
+ return typeof item === "string" ? item : JSON.stringify(item);
1475
+ }).join("");
1476
+ }
1477
+ return String(content);
1478
+ }
1479
+ function detectSender(assistant, user) {
1480
+ const mode = String(assistant.mode ?? "");
1481
+ if (mode === "agent" || mode === "auto")
1482
+ return "agent";
1483
+ if (assistant.agent)
1484
+ return "agent";
1485
+ if (assistant.isSidechain === true)
1486
+ return "agent";
1487
+ if (user?.isMeta === true)
1488
+ return "agent";
1489
+ return "user";
1490
+ }
1491
+ var SDK_ERROR_CODE_MAP = {
1492
+ authentication_failed: 401,
1493
+ billing_error: 402,
1494
+ rate_limit: 429,
1495
+ invalid_request: 400,
1496
+ server_error: 500,
1497
+ max_output_tokens: 413,
1498
+ unknown: 500
1499
+ };
1500
+ function extractError(event) {
1501
+ const msg = event.message;
1502
+ const error = msg.error;
1503
+ if (typeof error === "string") {
1504
+ const errorCode = SDK_ERROR_CODE_MAP[error] ?? 500;
1505
+ const errorDetails = msg.errorDetails;
1506
+ const reason = typeof errorDetails === "string" && errorDetails ? errorDetails : error;
1507
+ return { error_code: errorCode, error_reason: reason };
1508
+ }
1509
+ if (typeof error === "object" && error !== null) {
1510
+ const err = error;
1511
+ const apiError = msg.apiError;
1512
+ if (typeof apiError === "string" && apiError === "max_output_tokens") {
1513
+ const reason = typeof err.message === "string" ? err.message : "max_output_tokens";
1514
+ return { error_code: 413, error_reason: reason };
1515
+ }
1516
+ const name = String(err.name ?? "UnknownError");
1517
+ const errMessage = typeof err.message === "string" ? err.message : name;
1518
+ const errorCode = name === "ProviderAuthError" ? 401 : name === "ContextOverflowError" || name === "MessageOutputLengthError" ? 413 : name === "MessageAbortedError" ? 499 : name === "APIError" && typeof err.statusCode === "number" ? err.statusCode : 500;
1519
+ return { error_code: errorCode, error_reason: errMessage };
1520
+ }
1521
+ if (msg.isApiErrorMessage) {
1522
+ return { error_code: 500, error_reason: "api_error_unclassified" };
1523
+ }
1524
+ return {};
1585
1525
  }
1586
- var _mapCacheGet_default = mapCacheGet;
1587
-
1588
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheHas.js
1589
- function mapCacheHas(key) {
1590
- return _getMapData_default(this, key).has(key);
1526
+ function structuredPatchToUnifiedDiff(filePath, patches) {
1527
+ if (!patches.length)
1528
+ return "";
1529
+ const header = `--- a/${filePath}
1530
+ +++ b/${filePath}`;
1531
+ const hunks = [];
1532
+ for (const p of patches) {
1533
+ const oldStart = p.oldStart ?? 1;
1534
+ const oldLines = p.oldLines ?? 0;
1535
+ const newStart = p.newStart ?? 1;
1536
+ const newLines = p.newLines ?? 0;
1537
+ const lines = p.lines ?? [];
1538
+ hunks.push(`@@ -${oldStart},${oldLines} +${newStart},${newLines} @@
1539
+ ${lines.join(`
1540
+ `)}`);
1541
+ }
1542
+ return header + `
1543
+ ` + hunks.join(`
1544
+ `) + `
1545
+ `;
1591
1546
  }
1592
- var _mapCacheHas_default = mapCacheHas;
1593
-
1594
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheSet.js
1595
- function mapCacheSet(key, value) {
1596
- var data = _getMapData_default(this, key), size = data.size;
1597
- data.set(key, value);
1598
- this.size += data.size == size ? 0 : 1;
1599
- return this;
1547
+ function generateStringDiff(filePath, oldStr, newStr) {
1548
+ const oldLines = oldStr.split(`
1549
+ `);
1550
+ const newLines = newStr.split(`
1551
+ `);
1552
+ const header = `--- a/${filePath}
1553
+ +++ b/${filePath}`;
1554
+ const hunk = `@@ -1,${oldLines.length} +1,${newLines.length} @@`;
1555
+ const body = oldLines.map((l) => `-${l}`).concat(newLines.map((l) => `+${l}`)).join(`
1556
+ `);
1557
+ return header + `
1558
+ ` + hunk + `
1559
+ ` + body + `
1560
+ `;
1600
1561
  }
1601
- var _mapCacheSet_default = mapCacheSet;
1602
-
1603
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_MapCache.js
1604
- function MapCache(entries) {
1605
- var index = -1, length = entries == null ? 0 : entries.length;
1606
- this.clear();
1607
- while (++index < length) {
1608
- var entry = entries[index];
1609
- this.set(entry[0], entry[1]);
1562
+ function extractEventToolDiff(assistantEvent, allEvents) {
1563
+ const diffs = [];
1564
+ const msgUuid = assistantEvent.uuid;
1565
+ const handledToolUseIds = new Set;
1566
+ if (!msgUuid)
1567
+ return diffs;
1568
+ for (const m of allEvents) {
1569
+ if (m.parentUuid !== msgUuid || m.type !== "user")
1570
+ continue;
1571
+ const tur = m.toolUseResult ?? m.tool_use_result;
1572
+ if (!tur)
1573
+ continue;
1574
+ const filePath = tur.filePath ?? tur.file_path ?? tur.notebook_path ?? "";
1575
+ const gitDiff = tur.gitDiff;
1576
+ if (gitDiff?.patch && typeof gitDiff.patch === "string" && gitDiff.patch) {
1577
+ diffs.push({ file: filePath || String(gitDiff.filename ?? ""), content: gitDiff.patch });
1578
+ if (Array.isArray(m.message?.content)) {
1579
+ for (const b of m.message.content) {
1580
+ if (b?.type === "tool_result" && typeof b.tool_use_id === "string") {
1581
+ handledToolUseIds.add(b.tool_use_id);
1582
+ }
1583
+ }
1584
+ }
1585
+ continue;
1586
+ }
1587
+ const sp = tur.structuredPatch;
1588
+ if (Array.isArray(sp) && sp.length > 0 && filePath) {
1589
+ diffs.push({ file: filePath, content: structuredPatchToUnifiedDiff(filePath, sp) });
1590
+ if (Array.isArray(m.message?.content)) {
1591
+ for (const b of m.message.content) {
1592
+ if (b?.type === "tool_result" && typeof b.tool_use_id === "string") {
1593
+ handledToolUseIds.add(b.tool_use_id);
1594
+ }
1595
+ }
1596
+ }
1597
+ continue;
1598
+ }
1599
+ const oldStr = tur.oldString ?? tur.old_string ?? tur.originalFile ?? tur.original_file;
1600
+ const newStr = tur.newString ?? tur.new_string ?? tur.content ?? tur.updated_file;
1601
+ if (filePath && typeof oldStr === "string" && typeof newStr === "string") {
1602
+ diffs.push({ file: filePath, content: generateStringDiff(filePath, oldStr, newStr) });
1603
+ } else if (filePath && typeof newStr === "string") {
1604
+ diffs.push({ file: filePath, content: generateStringDiff(filePath, "", newStr) });
1605
+ }
1610
1606
  }
1611
- }
1612
- MapCache.prototype.clear = _mapCacheClear_default;
1613
- MapCache.prototype["delete"] = _mapCacheDelete_default;
1614
- MapCache.prototype.get = _mapCacheGet_default;
1615
- MapCache.prototype.has = _mapCacheHas_default;
1616
- MapCache.prototype.set = _mapCacheSet_default;
1617
- var _MapCache_default = MapCache;
1618
-
1619
- // node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/memoize.js
1620
- var FUNC_ERROR_TEXT = "Expected a function";
1621
- function memoize(func, resolver) {
1622
- if (typeof func != "function" || resolver != null && typeof resolver != "function") {
1623
- throw new TypeError(FUNC_ERROR_TEXT);
1607
+ const content = assistantEvent.message?.content;
1608
+ if (Array.isArray(content)) {
1609
+ for (const block of content) {
1610
+ if (block?.type !== "tool_use")
1611
+ continue;
1612
+ if (typeof block.id === "string" && handledToolUseIds.has(block.id))
1613
+ continue;
1614
+ const input = block.input;
1615
+ const toolName = block.name;
1616
+ const filePath = input?.file_path ?? input?.notebook_path ?? "";
1617
+ if (toolName === "Edit" && typeof input?.old_string === "string" && typeof input?.new_string === "string") {
1618
+ diffs.push({ file: filePath, content: generateStringDiff(filePath, input.old_string, input.new_string) });
1619
+ } else if (toolName === "NotebookEdit" && typeof input?.new_source === "string" && filePath) {
1620
+ diffs.push({ file: filePath, content: generateStringDiff(filePath, "", input.new_source) });
1621
+ } else if (typeof input?.diff === "string" && input.diff) {
1622
+ diffs.push({ file: filePath, content: input.diff });
1623
+ } else if (typeof input?.patch === "string" && input.patch) {
1624
+ diffs.push({ file: filePath, content: input.patch });
1625
+ }
1626
+ }
1624
1627
  }
1625
- var memoized = function() {
1626
- var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache2 = memoized.cache;
1627
- if (cache2.has(key)) {
1628
- return cache2.get(key);
1628
+ return diffs;
1629
+ }
1630
+ function parseSession(cacheConversations, events) {
1631
+ const sessionId = events.find((e) => e.sessionId)?.sessionId || "unknown";
1632
+ const version = events.find((e) => e.version)?.version || "";
1633
+ const cwd = events.find((e) => e.cwd)?.cwd || "";
1634
+ const gitBranch = events.find((e) => e.gitBranch)?.gitBranch || "";
1635
+ const conversations = [];
1636
+ let totalInputTokens = 0;
1637
+ let totalOutputTokens = 0;
1638
+ let totalCacheReadInputTokens = 0;
1639
+ let totalCacheCreationInputTokens = 0;
1640
+ let totalDuration = 0;
1641
+ events.forEach((evt) => {
1642
+ if (evt.message?.usage) {
1643
+ totalInputTokens += evt.message.usage.input_tokens || 0;
1644
+ totalOutputTokens += evt.message.usage.output_tokens || 0;
1645
+ totalCacheReadInputTokens += evt.message.usage.cache_read_input_tokens || 0;
1646
+ totalCacheCreationInputTokens += evt.message.usage.cache_creation_input_tokens || 0;
1629
1647
  }
1630
- var result = func.apply(this, args);
1631
- memoized.cache = cache2.set(key, result) || cache2;
1632
- return result;
1648
+ });
1649
+ const flows = buildFlows(events);
1650
+ flows.forEach((flow) => {
1651
+ const convResults = splitFlowToConversations(flow);
1652
+ convResults.forEach((conversation) => {
1653
+ const cached = cacheConversations.find((c) => c.id === conversation.id);
1654
+ if (cached && cached.events.length === conversation.events.length) {
1655
+ conversations.push(cached);
1656
+ } else {
1657
+ conversations.push(conversation);
1658
+ }
1659
+ totalDuration += conversation.duration;
1660
+ });
1661
+ });
1662
+ conversations.sort((a, b) => new Date(a.userEvent.timestamp).getTime() - new Date(b.userEvent.timestamp).getTime());
1663
+ conversations.forEach((conv, i) => {
1664
+ conv.index = i;
1665
+ });
1666
+ conversations.forEach((conv) => fillConversation(conv));
1667
+ return {
1668
+ id: sessionId,
1669
+ version,
1670
+ cwd,
1671
+ gitBranch,
1672
+ conversations,
1673
+ eventCount: events.length,
1674
+ totalInputTokens,
1675
+ totalOutputTokens,
1676
+ totalCacheCreationInputTokens,
1677
+ totalCacheReadInputTokens,
1678
+ totalTokens: totalInputTokens + totalOutputTokens,
1679
+ totalDuration
1633
1680
  };
1634
- memoized.cache = new (memoize.Cache || _MapCache_default);
1635
- return memoized;
1636
1681
  }
1637
- memoize.Cache = _MapCache_default;
1638
- var memoize_default = memoize;
1639
-
1640
- // src/utils/envUtils.ts
1641
- import { homedir as homedir2 } from "os";
1642
- import { join as join2 } from "path";
1643
-
1644
- // src/constants/branding.ts
1645
- var PRODUCT_URL = "https://costrict.ai";
1646
- var PRODUCT_DOCS_URL = `${PRODUCT_URL}/docs`;
1647
- var PRODUCT_CHROME_URL = `${PRODUCT_URL}/chrome`;
1648
- var PRODUCT_SETTINGS_URL = `${PRODUCT_URL}/settings`;
1649
- var PRODUCT_CODE_URL = `${PRODUCT_URL}/code`;
1650
- var PRODUCT_SESSION_URL = `${PRODUCT_URL}/session`;
1651
- var PRODUCT_UPGRADE_URL = `${PRODUCT_URL}/upgrade/max`;
1652
- var PRODUCT_DOWNLOAD_URL = `${PRODUCT_URL}/download`;
1653
- var PRODUCT_DESKTOP_API_URL = `${PRODUCT_URL}/api/desktop`;
1654
- var PRODUCT_OAUTH_CLIENT_METADATA_URL = `${PRODUCT_URL}/oauth/costrict-client-metadata`;
1655
- var CONFIG_DIR_NAME = ".costrict";
1656
-
1657
- // src/utils/envUtils.ts
1658
- var getCostrictConfigHomeDir = memoize_default(() => {
1659
- return (process.env.COSTRICT_CONFIG_DIR ?? process.env.CLAUDE_CONFIG_DIR ?? join2(homedir2(), CONFIG_DIR_NAME)).normalize("NFC");
1660
- }, () => process.env.COSTRICT_CONFIG_DIR ?? process.env.CLAUDE_CONFIG_DIR);
1661
- var getClaudeConfigHomeDir = getCostrictConfigHomeDir;
1662
1682
 
1663
1683
  // src/services/rawDump/session.ts
1664
1684
  var log2 = createLogger("session");
@@ -2276,7 +2296,7 @@ async function uploadSummary(payload, authData) {
2276
2296
  client_ide: "cli",
2277
2297
  client_version: authData.version,
2278
2298
  client_os: detectOs(),
2279
- client_os_version: os6.release(),
2299
+ client_os_version: os5.release(),
2280
2300
  caller: process.env.CSC_RAW_DUMP_CALLER || "chat"
2281
2301
  };
2282
2302
  await uploadReport(authData, "/raw-store/task-summary", body);
@@ -2578,10 +2598,10 @@ if (scriptPath.endsWith("worker.ts") || scriptPath.endsWith("worker.js")) {
2578
2598
 
2579
2599
  // src/services/rawDump/timerWorker.ts
2580
2600
  import { promises as fs8 } from "fs";
2581
- import os7 from "os";
2601
+ import os6 from "os";
2582
2602
  import path8 from "path";
2583
2603
  var log5 = createLogger("timer");
2584
- var TIMER_LOCK_FILE = path8.join(os7.homedir(), ".claude", "raw-dump", "csc-timer.lock");
2604
+ var TIMER_LOCK_FILE = path8.join(os6.homedir(), ".claude", "raw-dump", "csc-timer.lock");
2585
2605
  var isRunning = false;
2586
2606
  async function acquireTimerLock() {
2587
2607
  try {
@@ -2693,5 +2713,5 @@ export {
2693
2713
  startBatchWorker
2694
2714
  };
2695
2715
 
2696
- //# debugId=19F0142A23AA826964756E2164756E21
2716
+ //# debugId=19FD3202EDB5569A64756E2164756E21
2697
2717
  //# sourceMappingURL=batchWorker.js.map