@ken-jo/agent-connector 0.1.0

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.
Files changed (203) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +6 -0
  3. package/README.md +348 -0
  4. package/dist/amp-QSFH2V7Y.js +217 -0
  5. package/dist/amp-QSFH2V7Y.js.map +1 -0
  6. package/dist/amp-TULUPXXL.js +237 -0
  7. package/dist/amp-TULUPXXL.js.map +1 -0
  8. package/dist/antigravity-CX2YLSY7.js +17 -0
  9. package/dist/antigravity-CX2YLSY7.js.map +1 -0
  10. package/dist/antigravity-STHZWMP3.js +171 -0
  11. package/dist/antigravity-STHZWMP3.js.map +1 -0
  12. package/dist/antigravity-cli-P6HADOAO.js +121 -0
  13. package/dist/antigravity-cli-P6HADOAO.js.map +1 -0
  14. package/dist/antigravity-cli-YQDFVV4U.js +86 -0
  15. package/dist/antigravity-cli-YQDFVV4U.js.map +1 -0
  16. package/dist/chunk-54EMKTTX.js +191 -0
  17. package/dist/chunk-54EMKTTX.js.map +1 -0
  18. package/dist/chunk-7L6ITC4T.js +54 -0
  19. package/dist/chunk-7L6ITC4T.js.map +1 -0
  20. package/dist/chunk-7MSDGHJW.js +316 -0
  21. package/dist/chunk-7MSDGHJW.js.map +1 -0
  22. package/dist/chunk-BCHWFTV4.js +196 -0
  23. package/dist/chunk-BCHWFTV4.js.map +1 -0
  24. package/dist/chunk-DBQMX75U.js +36 -0
  25. package/dist/chunk-DBQMX75U.js.map +1 -0
  26. package/dist/chunk-EXLS7BSI.js +29 -0
  27. package/dist/chunk-EXLS7BSI.js.map +1 -0
  28. package/dist/chunk-JNM3TPLX.js +593 -0
  29. package/dist/chunk-JNM3TPLX.js.map +1 -0
  30. package/dist/chunk-JWNT5KW7.js +197 -0
  31. package/dist/chunk-JWNT5KW7.js.map +1 -0
  32. package/dist/chunk-KHO5WNTP.js +30 -0
  33. package/dist/chunk-KHO5WNTP.js.map +1 -0
  34. package/dist/chunk-LTT56GI3.js +155 -0
  35. package/dist/chunk-LTT56GI3.js.map +1 -0
  36. package/dist/chunk-MEH7GC7R.js +111 -0
  37. package/dist/chunk-MEH7GC7R.js.map +1 -0
  38. package/dist/chunk-MQPNU2CY.js +64 -0
  39. package/dist/chunk-MQPNU2CY.js.map +1 -0
  40. package/dist/chunk-OPXAP3AC.js +12 -0
  41. package/dist/chunk-OPXAP3AC.js.map +1 -0
  42. package/dist/chunk-RK6VBLXP.js +50 -0
  43. package/dist/chunk-RK6VBLXP.js.map +1 -0
  44. package/dist/chunk-TIIP3RG2.js +420 -0
  45. package/dist/chunk-TIIP3RG2.js.map +1 -0
  46. package/dist/chunk-TRKWUNO4.js +702 -0
  47. package/dist/chunk-TRKWUNO4.js.map +1 -0
  48. package/dist/chunk-TRQKHP7D.js +93 -0
  49. package/dist/chunk-TRQKHP7D.js.map +1 -0
  50. package/dist/chunk-WCETQWWK.js +59 -0
  51. package/dist/chunk-WCETQWWK.js.map +1 -0
  52. package/dist/chunk-WV63X7IK.js +357 -0
  53. package/dist/chunk-WV63X7IK.js.map +1 -0
  54. package/dist/chunk-XD7MY6HB.js +343 -0
  55. package/dist/chunk-XD7MY6HB.js.map +1 -0
  56. package/dist/chunk-XNAM7F35.js +276 -0
  57. package/dist/chunk-XNAM7F35.js.map +1 -0
  58. package/dist/chunk-XUCWLJY5.js +238 -0
  59. package/dist/chunk-XUCWLJY5.js.map +1 -0
  60. package/dist/chunk-YNZU6PAV.js +800 -0
  61. package/dist/chunk-YNZU6PAV.js.map +1 -0
  62. package/dist/chunk-YT43MUSJ.js +146 -0
  63. package/dist/chunk-YT43MUSJ.js.map +1 -0
  64. package/dist/claude-code-HKDV7T32.js +637 -0
  65. package/dist/claude-code-HKDV7T32.js.map +1 -0
  66. package/dist/claude-code-W74MNTAC.js +652 -0
  67. package/dist/claude-code-W74MNTAC.js.map +1 -0
  68. package/dist/cli/sdk.d.ts +54 -0
  69. package/dist/cli/sdk.js +82 -0
  70. package/dist/cli/sdk.js.map +1 -0
  71. package/dist/cli.d.ts +2 -0
  72. package/dist/cli.js +15 -0
  73. package/dist/cli.js.map +1 -0
  74. package/dist/codebuff-3PMZJJHP.js +307 -0
  75. package/dist/codebuff-3PMZJJHP.js.map +1 -0
  76. package/dist/codebuff-QX57FJDN.js +220 -0
  77. package/dist/codebuff-QX57FJDN.js.map +1 -0
  78. package/dist/codex-JFQTS6LU.js +593 -0
  79. package/dist/codex-JFQTS6LU.js.map +1 -0
  80. package/dist/codex-Q3ATRRX3.js +364 -0
  81. package/dist/codex-Q3ATRRX3.js.map +1 -0
  82. package/dist/copilot-cli-MTCGHZ2T.js +622 -0
  83. package/dist/copilot-cli-MTCGHZ2T.js.map +1 -0
  84. package/dist/copilot-cli-SJGIXVSD.js +369 -0
  85. package/dist/copilot-cli-SJGIXVSD.js.map +1 -0
  86. package/dist/crush-I7PK3FGI.js +360 -0
  87. package/dist/crush-I7PK3FGI.js.map +1 -0
  88. package/dist/crush-LN5QFFR2.js +183 -0
  89. package/dist/crush-LN5QFFR2.js.map +1 -0
  90. package/dist/cursor-4TMXKJOZ.js +603 -0
  91. package/dist/cursor-4TMXKJOZ.js.map +1 -0
  92. package/dist/cursor-QZ6MTO74.js +194 -0
  93. package/dist/cursor-QZ6MTO74.js.map +1 -0
  94. package/dist/detect-WIAGVYS4.js +68 -0
  95. package/dist/detect-WIAGVYS4.js.map +1 -0
  96. package/dist/doctor-EZW2K4NI.js +372 -0
  97. package/dist/doctor-EZW2K4NI.js.map +1 -0
  98. package/dist/droid-KN6VRMMT.js +424 -0
  99. package/dist/droid-KN6VRMMT.js.map +1 -0
  100. package/dist/droid-W5WF5XEX.js +224 -0
  101. package/dist/droid-W5WF5XEX.js.map +1 -0
  102. package/dist/gemini-cli-CIRW37TU.js +369 -0
  103. package/dist/gemini-cli-CIRW37TU.js.map +1 -0
  104. package/dist/gemini-cli-Y35FFK4M.js +705 -0
  105. package/dist/gemini-cli-Y35FFK4M.js.map +1 -0
  106. package/dist/goose-A3M5GODH.js +212 -0
  107. package/dist/goose-A3M5GODH.js.map +1 -0
  108. package/dist/goose-ZTGTSUFJ.js +480 -0
  109. package/dist/goose-ZTGTSUFJ.js.map +1 -0
  110. package/dist/hermes-H2KV44GK.js +470 -0
  111. package/dist/hermes-H2KV44GK.js.map +1 -0
  112. package/dist/hermes-ZYLMOFLZ.js +196 -0
  113. package/dist/hermes-ZYLMOFLZ.js.map +1 -0
  114. package/dist/hook-YVDILAMZ.js +75 -0
  115. package/dist/hook-YVDILAMZ.js.map +1 -0
  116. package/dist/index.d.ts +22 -0
  117. package/dist/index.js +10 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/install-HQRYZOQ2.js +60 -0
  120. package/dist/install-HQRYZOQ2.js.map +1 -0
  121. package/dist/jetbrains-copilot-HWA3DMH7.js +633 -0
  122. package/dist/jetbrains-copilot-HWA3DMH7.js.map +1 -0
  123. package/dist/kilo-NSWAVP6P.js +235 -0
  124. package/dist/kilo-NSWAVP6P.js.map +1 -0
  125. package/dist/kilo-QXJRCSLT.js +384 -0
  126. package/dist/kilo-QXJRCSLT.js.map +1 -0
  127. package/dist/kilo-cli-EAQTHXUW.js +587 -0
  128. package/dist/kilo-cli-EAQTHXUW.js.map +1 -0
  129. package/dist/kilo-cli-EVBKUODA.js +160 -0
  130. package/dist/kilo-cli-EVBKUODA.js.map +1 -0
  131. package/dist/kimi-EI3UM3ZV.js +155 -0
  132. package/dist/kimi-EI3UM3ZV.js.map +1 -0
  133. package/dist/kimi-GQ7VXNYT.js +423 -0
  134. package/dist/kimi-GQ7VXNYT.js.map +1 -0
  135. package/dist/kiro-UCLSLBW2.js +217 -0
  136. package/dist/kiro-UCLSLBW2.js.map +1 -0
  137. package/dist/kiro-VQTT6LO2.js +451 -0
  138. package/dist/kiro-VQTT6LO2.js.map +1 -0
  139. package/dist/leaderboard-K6ON3SWW.js +137 -0
  140. package/dist/leaderboard-K6ON3SWW.js.map +1 -0
  141. package/dist/mux-T2TV4CIQ.js +211 -0
  142. package/dist/mux-T2TV4CIQ.js.map +1 -0
  143. package/dist/mux-ZMLVAXOO.js +96 -0
  144. package/dist/mux-ZMLVAXOO.js.map +1 -0
  145. package/dist/omp-PB4VDKS6.js +586 -0
  146. package/dist/omp-PB4VDKS6.js.map +1 -0
  147. package/dist/openclaw-ETN2M63O.js +751 -0
  148. package/dist/openclaw-ETN2M63O.js.map +1 -0
  149. package/dist/openclaw-IYA7ASL6.js +150 -0
  150. package/dist/openclaw-IYA7ASL6.js.map +1 -0
  151. package/dist/opencode-FZ33JKUZ.js +734 -0
  152. package/dist/opencode-FZ33JKUZ.js.map +1 -0
  153. package/dist/opencode-HWT3RSMN.js +216 -0
  154. package/dist/opencode-HWT3RSMN.js.map +1 -0
  155. package/dist/package-DLOVE2E4.js +1132 -0
  156. package/dist/package-DLOVE2E4.js.map +1 -0
  157. package/dist/pi-CIU2QHT4.js +208 -0
  158. package/dist/pi-CIU2QHT4.js.map +1 -0
  159. package/dist/pi-UFX2OYFV.js +139 -0
  160. package/dist/pi-UFX2OYFV.js.map +1 -0
  161. package/dist/qwen-code-5POCNU6P.js +573 -0
  162. package/dist/qwen-code-5POCNU6P.js.map +1 -0
  163. package/dist/qwen-code-W7NUCDEN.js +134 -0
  164. package/dist/qwen-code-W7NUCDEN.js.map +1 -0
  165. package/dist/roo-code-IOIUXRDE.js +242 -0
  166. package/dist/roo-code-IOIUXRDE.js.map +1 -0
  167. package/dist/roo-code-ZLKH4A7N.js +229 -0
  168. package/dist/roo-code-ZLKH4A7N.js.map +1 -0
  169. package/dist/runtime/index.d.ts +157 -0
  170. package/dist/runtime/index.js +20 -0
  171. package/dist/runtime/index.js.map +1 -0
  172. package/dist/serve-HVWWY4B6.js +65 -0
  173. package/dist/serve-HVWWY4B6.js.map +1 -0
  174. package/dist/status-FE7TECZD.js +128 -0
  175. package/dist/status-FE7TECZD.js.map +1 -0
  176. package/dist/synthetic-UKR6SMGS.js +178 -0
  177. package/dist/synthetic-UKR6SMGS.js.map +1 -0
  178. package/dist/telemetry-36GESKQQ.js +349 -0
  179. package/dist/telemetry-36GESKQQ.js.map +1 -0
  180. package/dist/trae-JSNDZFKL.js +204 -0
  181. package/dist/trae-JSNDZFKL.js.map +1 -0
  182. package/dist/trae-PA26DPBW.js +157 -0
  183. package/dist/trae-PA26DPBW.js.map +1 -0
  184. package/dist/types-CYUB1OTr.d.ts +427 -0
  185. package/dist/uninstall-IGCKNOSF.js +72 -0
  186. package/dist/uninstall-IGCKNOSF.js.map +1 -0
  187. package/dist/upgrade-JV2VK242.js +104 -0
  188. package/dist/upgrade-JV2VK242.js.map +1 -0
  189. package/dist/usage-6ER6EMEY.js +324 -0
  190. package/dist/usage-6ER6EMEY.js.map +1 -0
  191. package/dist/usage-event-JKBI6XCF.js +48 -0
  192. package/dist/usage-event-JKBI6XCF.js.map +1 -0
  193. package/dist/vscode-copilot-CK3NO54M.js +715 -0
  194. package/dist/vscode-copilot-CK3NO54M.js.map +1 -0
  195. package/dist/warp-JNQA7PBU.js +126 -0
  196. package/dist/warp-JNQA7PBU.js.map +1 -0
  197. package/dist/warp-QNVDXOG4.js +199 -0
  198. package/dist/warp-QNVDXOG4.js.map +1 -0
  199. package/dist/zed-NNNX5MNT.js +272 -0
  200. package/dist/zed-NNNX5MNT.js.map +1 -0
  201. package/dist/zed-VRJKWYUR.js +209 -0
  202. package/dist/zed-VRJKWYUR.js.map +1 -0
  203. package/package.json +79 -0
@@ -0,0 +1,652 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ fileMtimeMs,
4
+ readJsonFile,
5
+ readJsonlLines
6
+ } from "./chunk-RK6VBLXP.js";
7
+ import {
8
+ firstExistingRoot,
9
+ isFile,
10
+ walkFiles
11
+ } from "./chunk-JWNT5KW7.js";
12
+ import {
13
+ emptyTokens,
14
+ inferProvider,
15
+ normalizeWorkspaceKey,
16
+ workspaceLabelFromKey
17
+ } from "./chunk-XD7MY6HB.js";
18
+
19
+ // src/usage/readers/claude-code.ts
20
+ import { basename, dirname, sep } from "path";
21
+ var PLATFORM_ID = "claude-code";
22
+ var DEFAULT_MODEL = "unknown";
23
+ var DEFAULT_PROVIDER = "anthropic";
24
+ var SUBAGENT_FALLBACK = "claude-code-subagent";
25
+ function toNonNegInt(v) {
26
+ const n = typeof v === "number" ? v : typeof v === "string" ? Number(v) : NaN;
27
+ if (!Number.isFinite(n)) return 0;
28
+ return Math.max(0, Math.trunc(n));
29
+ }
30
+ function toIntOrNull(v) {
31
+ if (typeof v === "number" && Number.isFinite(v)) return Math.trunc(v);
32
+ if (typeof v === "string") {
33
+ const n = Number(v);
34
+ if (Number.isFinite(n)) return Math.trunc(n);
35
+ }
36
+ return null;
37
+ }
38
+ function asNonEmptyString(v) {
39
+ return typeof v === "string" && v !== "" ? v : void 0;
40
+ }
41
+ function parseTs(v) {
42
+ if (typeof v === "string") {
43
+ const ms = Date.parse(v);
44
+ if (!Number.isNaN(ms)) return ms;
45
+ const num = Number(v);
46
+ if (Number.isFinite(num) && num > 0) return num >= 1e12 ? num : num * 1e3;
47
+ return null;
48
+ }
49
+ if (typeof v === "number" && Number.isFinite(v) && v > 0) {
50
+ return v >= 1e12 ? v : v * 1e3;
51
+ }
52
+ return null;
53
+ }
54
+ function isObject(v) {
55
+ return typeof v === "object" && v !== null && !Array.isArray(v);
56
+ }
57
+ function resolveProvider(rawModel, hint) {
58
+ const canonicalHint = canonicalProvider(hint);
59
+ if (canonicalHint !== void 0) {
60
+ if (canonicalHint === "anthropic") {
61
+ const inferred2 = rawModel !== void 0 ? inferProvider(rawModel) : null;
62
+ if (inferred2 !== null && inferred2 !== "anthropic") return inferred2;
63
+ return "anthropic";
64
+ }
65
+ return canonicalHint;
66
+ }
67
+ if (rawModel === void 0) return DEFAULT_PROVIDER;
68
+ if (rawModel.trim().includes("/")) {
69
+ const prefixProvider = canonicalProvider(rawModel);
70
+ if (prefixProvider !== void 0) return prefixProvider;
71
+ }
72
+ const inferred = inferProvider(rawModel);
73
+ if (inferred !== null) return inferred;
74
+ return DEFAULT_PROVIDER;
75
+ }
76
+ function canonicalProvider(hint) {
77
+ if (hint === void 0) return void 0;
78
+ const trimmed = hint.trim();
79
+ if (trimmed === "") return void 0;
80
+ const inferred = inferProvider(trimmed);
81
+ if (inferred !== null) return inferred;
82
+ const head = trimmed.split("/")[0];
83
+ if (head !== void 0 && head !== "") return head.toLowerCase();
84
+ return void 0;
85
+ }
86
+ function workspaceFromPath(path) {
87
+ const components = path.split(/[\\/]+/).filter((c) => c !== "");
88
+ for (let i = 0; i + 2 < components.length; i++) {
89
+ if (components[i] === ".claude" && components[i + 1] === "projects") {
90
+ return keyAndLabel(components[i + 2]);
91
+ }
92
+ }
93
+ for (let i = 0; i + 4 < components.length; i++) {
94
+ if (components[i] === ".cc-mirror" && components[i + 2] === "config" && components[i + 3] === "projects") {
95
+ return keyAndLabel(components[i + 4]);
96
+ }
97
+ }
98
+ for (let i = components.length - 2; i >= 0; i--) {
99
+ if (components[i] === "projects") {
100
+ return keyAndLabel(components[i + 1]);
101
+ }
102
+ }
103
+ return {};
104
+ }
105
+ function keyAndLabel(raw) {
106
+ if (raw === void 0) return {};
107
+ const key = normalizeWorkspaceKey(raw);
108
+ if (key === void 0) return {};
109
+ const label = workspaceLabelFromKey(key);
110
+ return label === void 0 ? { projectKey: key } : { projectKey: key, projectLabel: label };
111
+ }
112
+ function stripExt(name) {
113
+ const dot = name.lastIndexOf(".");
114
+ return dot > 0 ? name.slice(0, dot) : name;
115
+ }
116
+ function resolveSubagentName(path, parentSessionId, entryAgentId, cache) {
117
+ const stem = stripExt(basename(path));
118
+ if (stem === "") return SUBAGENT_FALLBACK;
119
+ const metaPath = `${dirname(path)}${sep}${stem}.meta.json`;
120
+ const meta = readJsonFile(metaPath);
121
+ if (isObject(meta)) {
122
+ const agentType = asNonEmptyString(meta["agentType"]);
123
+ if (agentType !== void 0 && agentType.trim() !== "") return agentType;
124
+ }
125
+ const lookupAgentId = entryAgentId !== void 0 && entryAgentId.trim() !== "" ? entryAgentId : agentIdFromStem(stem);
126
+ if (parentSessionId !== void 0 && lookupAgentId !== void 0) {
127
+ const parentPath = findParentSessionPath(path, parentSessionId);
128
+ if (parentPath !== void 0) {
129
+ const subagentType = lookupSubagentTypeInParent(parentPath, lookupAgentId, cache);
130
+ if (subagentType !== void 0) return subagentType;
131
+ }
132
+ }
133
+ return SUBAGENT_FALLBACK;
134
+ }
135
+ function agentIdFromStem(stem) {
136
+ if (!stem.startsWith("agent-")) return void 0;
137
+ const agentStem = stem.slice("agent-".length);
138
+ if (!agentStem.includes("-")) return agentStem;
139
+ const trailing = agentStem.slice(agentStem.lastIndexOf("-") + 1);
140
+ if (trailing !== "" && /^[0-9a-fA-F]+$/.test(trailing)) return trailing;
141
+ return agentStem;
142
+ }
143
+ function findParentSessionPath(sidechainPath, parentSessionId) {
144
+ const parentFilename = `${parentSessionId}.jsonl`;
145
+ const dir = dirname(sidechainPath);
146
+ if (basename(dir) === "subagents") {
147
+ const projectDir = dirname(dirname(dir));
148
+ const candidate = `${projectDir}${sep}${parentFilename}`;
149
+ if (isFile(candidate)) return candidate;
150
+ }
151
+ const flat = `${dir}${sep}${parentFilename}`;
152
+ if (isFile(flat)) return flat;
153
+ return void 0;
154
+ }
155
+ function lookupSubagentTypeInParent(parentPath, targetAgentId, cache) {
156
+ let lookup = cache.get(parentPath);
157
+ if (lookup === void 0) {
158
+ lookup = buildParentSubagentLookup(parentPath);
159
+ cache.set(parentPath, lookup);
160
+ }
161
+ return lookup.get(targetAgentId);
162
+ }
163
+ function buildParentSubagentLookup(parentPath) {
164
+ const out = /* @__PURE__ */ new Map();
165
+ const toolUseTypes = /* @__PURE__ */ new Map();
166
+ const agentIdLinks = /* @__PURE__ */ new Map();
167
+ for (const raw of readJsonlLines(parentPath)) {
168
+ if (!isObject(raw)) continue;
169
+ const message = raw["message"];
170
+ if (!isObject(message)) continue;
171
+ const content = message["content"];
172
+ if (!Array.isArray(content)) continue;
173
+ for (const block of content) {
174
+ if (!isObject(block)) continue;
175
+ const blockType = block["type"];
176
+ if (blockType === "tool_use") {
177
+ const id = asNonEmptyString(block["id"]);
178
+ const input = block["input"];
179
+ const subagentType = isObject(input) ? asNonEmptyString(input["subagent_type"]) : void 0;
180
+ if (id !== void 0 && subagentType !== void 0) {
181
+ toolUseTypes.set(id, subagentType);
182
+ }
183
+ } else if (blockType === "tool_result") {
184
+ const toolUseId = asNonEmptyString(block["tool_use_id"]);
185
+ if (toolUseId === void 0) continue;
186
+ const resultContent = block["content"];
187
+ if (!Array.isArray(resultContent)) continue;
188
+ for (const cb of resultContent) {
189
+ if (!isObject(cb)) continue;
190
+ const text = cb["text"];
191
+ if (typeof text === "string") {
192
+ const aid = extractAgentIdFromText(text);
193
+ if (aid !== void 0) {
194
+ agentIdLinks.set(toolUseId, aid);
195
+ break;
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ for (const [toolUseId, agentId] of agentIdLinks) {
203
+ const subagentType = toolUseTypes.get(toolUseId);
204
+ if (subagentType !== void 0) out.set(agentId, subagentType);
205
+ }
206
+ return out;
207
+ }
208
+ function extractAgentIdFromText(text) {
209
+ const marker = "agentId: ";
210
+ const pos = text.indexOf(marker);
211
+ if (pos < 0) return void 0;
212
+ const rest = text.slice(pos + marker.length);
213
+ let end = 0;
214
+ while (end < rest.length && /[0-9a-zA-Z]/.test(rest[end])) end++;
215
+ return end > 0 ? rest.slice(0, end) : void 0;
216
+ }
217
+ function extractToolResultUsage(value) {
218
+ let total = 0;
219
+ let firstDedupId;
220
+ const seen = /* @__PURE__ */ new Set();
221
+ for (const toolResult of collectToolResultValues(value)) {
222
+ const id = extractToolResultId(toolResult);
223
+ if (id !== void 0) {
224
+ if (seen.has(id)) continue;
225
+ seen.add(id);
226
+ }
227
+ if (firstDedupId === void 0 && id !== void 0) firstDedupId = `tool_result:${id}`;
228
+ total += extractToolResultInputTokens(toolResult);
229
+ }
230
+ if (total <= 0) return void 0;
231
+ return firstDedupId === void 0 ? { inputTokens: total } : { inputTokens: total, dedupId: firstDedupId };
232
+ }
233
+ function collectToolResultValues(value) {
234
+ const results = [];
235
+ if (value["type"] === "tool_result") results.push(value);
236
+ const directTr = value["tool_result"];
237
+ if (isObject(directTr)) results.push(directTr);
238
+ const message = value["message"];
239
+ if (isObject(message)) {
240
+ const msgTr = message["tool_result"];
241
+ if (isObject(msgTr)) results.push(msgTr);
242
+ }
243
+ const content = isObject(message) ? message["content"] : value["content"];
244
+ if (Array.isArray(content)) {
245
+ for (const block of content) {
246
+ if (isObject(block) && block["type"] === "tool_result") results.push(block);
247
+ }
248
+ }
249
+ return results;
250
+ }
251
+ function extractToolResultId(tr) {
252
+ return asNonEmptyString(tr["tool_use_id"]) ?? asNonEmptyString(tr["id"]) ?? asNonEmptyString(tr["tool_result_id"]);
253
+ }
254
+ function extractToolResultInputTokens(tr) {
255
+ const explicit = explicitToolResultInputTokens(tr);
256
+ if (explicit !== void 0) return explicit;
257
+ const chars = toolResultOutputCharCount(tr);
258
+ return chars > 0 ? Math.ceil(chars / 4) : 0;
259
+ }
260
+ function explicitToolResultInputTokens(tr) {
261
+ const toolOutput = isObject(tr["tool_output"]) ? tr["tool_output"] : void 0;
262
+ const usage = isObject(tr["usage"]) ? tr["usage"] : void 0;
263
+ const toolOutputUsage = toolOutput !== void 0 && isObject(toolOutput["usage"]) ? toolOutput["usage"] : void 0;
264
+ const candidates = [
265
+ tr["input_tokens"],
266
+ tr["token_count"],
267
+ tr["tokens"],
268
+ usage?.["input_tokens"],
269
+ toolOutput?.["input_tokens"],
270
+ toolOutput?.["token_count"],
271
+ toolOutput?.["tokens"],
272
+ toolOutputUsage?.["input_tokens"]
273
+ ];
274
+ for (const c of candidates) {
275
+ const n = toIntOrNull(c);
276
+ if (n !== null) return Math.max(0, n);
277
+ }
278
+ return void 0;
279
+ }
280
+ function toolResultOutputCharCount(tr) {
281
+ let chars = 0;
282
+ const toolOutput = tr["tool_output"];
283
+ if (isObject(toolOutput)) {
284
+ const output = toolOutput["output"];
285
+ if (typeof output === "string") chars += [...output].length;
286
+ }
287
+ const content = tr["content"];
288
+ if (typeof content === "string") {
289
+ chars += [...content].length;
290
+ } else if (Array.isArray(content)) {
291
+ for (const block of content) {
292
+ if (!isObject(block)) continue;
293
+ const blockToolOutput = block["tool_output"];
294
+ const blockOutput = isObject(blockToolOutput) ? blockToolOutput["output"] : void 0;
295
+ const text = typeof blockOutput === "string" ? blockOutput : typeof block["text"] === "string" ? block["text"] : void 0;
296
+ if (text !== void 0) chars += [...text].length;
297
+ }
298
+ }
299
+ return chars;
300
+ }
301
+ var PC_DEFAULT = 1;
302
+ var PC_INFERRED = 2;
303
+ var PC_EXPLICIT = 3;
304
+ function providerConfidence(rawModel, hint) {
305
+ const canonicalHint = canonicalProvider(hint);
306
+ if (canonicalHint !== void 0) {
307
+ if (canonicalHint === "anthropic") {
308
+ const inferred = rawModel !== void 0 ? inferProvider(rawModel) : null;
309
+ if (inferred !== null && inferred !== "anthropic") return PC_INFERRED;
310
+ return PC_DEFAULT;
311
+ }
312
+ return PC_EXPLICIT;
313
+ }
314
+ if (rawModel !== void 0) {
315
+ if (rawModel.trim().includes("/") && canonicalProvider(rawModel) !== void 0) return PC_EXPLICIT;
316
+ if (inferProvider(rawModel) !== null) return PC_INFERRED;
317
+ }
318
+ return 0;
319
+ }
320
+ function parseClaudeFile(path, parentCache) {
321
+ const fallbackTs = fileMtimeMs(path);
322
+ const { projectKey, projectLabel } = workspaceFromPath(path);
323
+ if (path.endsWith(".json")) {
324
+ const headless = parseHeadlessJson(path, fallbackTs, projectKey, projectLabel);
325
+ if (headless.length > 0) return headless;
326
+ }
327
+ const lines = readJsonlLines(path);
328
+ if (lines.length === 0) return [];
329
+ let sessionId = stripExt(basename(path)) || "unknown";
330
+ const byKey = /* @__PURE__ */ new Map();
331
+ const ordered = [];
332
+ let lastModel;
333
+ let lastProviderHint;
334
+ let sidechainAgent;
335
+ let sidechainDetected = false;
336
+ const headlessState = newHeadlessState();
337
+ const headlessOut = [];
338
+ for (let li = 0; li < lines.length; li++) {
339
+ const value = lines[li];
340
+ if (!isObject(value)) continue;
341
+ const rawLine = JSON.stringify(value);
342
+ const entryType = value["type"];
343
+ const message = isObject(value["message"]) ? value["message"] : void 0;
344
+ const entryProviderHint = asNonEmptyString(value["providerId"]) ?? asNonEmptyString(value["provider_id"]) ?? asNonEmptyString(value["provider"]);
345
+ if (!sidechainDetected) {
346
+ sidechainDetected = true;
347
+ if (value["isSidechain"] === true) {
348
+ const parentId = asNonEmptyString(value["sessionId"]);
349
+ if (parentId !== void 0) sessionId = parentId;
350
+ sidechainAgent = resolveSubagentName(
351
+ path,
352
+ asNonEmptyString(value["sessionId"]),
353
+ asNonEmptyString(value["agentId"]),
354
+ parentCache
355
+ );
356
+ }
357
+ }
358
+ if (entryType === "user" || entryType === "tool_result") {
359
+ const tr = extractToolResultUsage(value);
360
+ if (tr !== void 0) {
361
+ const rawModel = extractModel(value) ?? (message !== void 0 ? asNonEmptyString(message["model"]) : void 0) ?? lastModel;
362
+ const providerHint = extractProviderHint(value) ?? (message !== void 0 ? messageProviderHint(message) : void 0) ?? entryProviderHint ?? lastProviderHint;
363
+ const ts = parseTs(value["timestamp"]) ?? extractClaudeTimestamp(value) ?? fallbackTs;
364
+ const dedupKey = tr.dedupId !== void 0 ? `claude:tool_result:${sessionId}:${tr.dedupId}` : void 0;
365
+ if (dedupKey !== void 0) {
366
+ const existing = byKey.get(dedupKey);
367
+ if (existing !== void 0) {
368
+ existing.record.tokens.input = Math.max(existing.record.tokens.input, tr.inputTokens);
369
+ if (ts >= existing.record.ts) existing.record.ts = ts;
370
+ continue;
371
+ }
372
+ }
373
+ const tokens = emptyTokens();
374
+ tokens.input = tr.inputTokens;
375
+ const record = buildRecord({
376
+ rawModel,
377
+ providerHint,
378
+ sessionId,
379
+ ts,
380
+ tokens,
381
+ messageCount: 0,
382
+ dedupKey,
383
+ projectKey,
384
+ projectLabel,
385
+ agent: sidechainAgent
386
+ });
387
+ const accum = { record, providerConfidence: providerConfidence(rawModel, providerHint) };
388
+ if (dedupKey !== void 0) byKey.set(dedupKey, accum);
389
+ ordered.push(accum);
390
+ }
391
+ continue;
392
+ }
393
+ if (entryType === "assistant") {
394
+ if (message === void 0) continue;
395
+ const msgModel = asNonEmptyString(message["model"]);
396
+ if (msgModel !== void 0) {
397
+ lastModel = msgModel;
398
+ lastProviderHint = messageProviderHint(message) ?? entryProviderHint;
399
+ }
400
+ const usage = message["usage"];
401
+ if (!isObject(usage)) continue;
402
+ const u = usage;
403
+ const msgId = asNonEmptyString(message["id"]);
404
+ const reqId = asNonEmptyString(value["requestId"]);
405
+ const providerHint = messageProviderHint(message) ?? entryProviderHint;
406
+ let dedupKey;
407
+ if (msgId !== void 0 && reqId !== void 0) dedupKey = `${msgId}:${reqId}`;
408
+ else if (msgId !== void 0) dedupKey = `message:${msgId}`;
409
+ const ts = parseTs(value["timestamp"]) ?? fallbackTs;
410
+ if (dedupKey !== void 0) {
411
+ const existing = byKey.get(dedupKey);
412
+ if (existing !== void 0) {
413
+ mergeUsageMax(existing.record.tokens, u);
414
+ if (ts >= existing.record.ts) existing.record.ts = ts;
415
+ const cand = providerConfidence(msgModel, providerHint);
416
+ if (cand > existing.providerConfidence) {
417
+ existing.providerConfidence = cand;
418
+ existing.record.providerId = resolveProvider(msgModel, providerHint);
419
+ }
420
+ continue;
421
+ }
422
+ }
423
+ if (msgModel === void 0) continue;
424
+ const tokens = emptyTokens();
425
+ tokens.input = toNonNegInt(u.input_tokens);
426
+ tokens.output = toNonNegInt(u.output_tokens);
427
+ tokens.cacheRead = toNonNegInt(u.cache_read_input_tokens);
428
+ tokens.cacheWrite = toNonNegInt(u.cache_creation_input_tokens);
429
+ const record = buildRecord({
430
+ rawModel: msgModel,
431
+ providerHint,
432
+ sessionId,
433
+ ts,
434
+ tokens,
435
+ messageCount: 1,
436
+ dedupKey,
437
+ projectKey,
438
+ projectLabel,
439
+ agent: sidechainAgent
440
+ });
441
+ const accum = { record, providerConfidence: providerConfidence(msgModel, providerHint) };
442
+ if (dedupKey !== void 0) byKey.set(dedupKey, accum);
443
+ ordered.push(accum);
444
+ continue;
445
+ }
446
+ const completed = processHeadlessLine(value, rawLine, sessionId, headlessState, fallbackTs);
447
+ if (completed !== void 0) {
448
+ if (projectKey !== void 0) completed.projectKey = projectKey;
449
+ if (projectLabel !== void 0) completed.projectLabel = projectLabel;
450
+ headlessOut.push(completed);
451
+ }
452
+ }
453
+ const finalHeadless = finalizeHeadlessState(headlessState, sessionId, fallbackTs);
454
+ if (finalHeadless !== void 0) {
455
+ if (projectKey !== void 0) finalHeadless.projectKey = projectKey;
456
+ if (projectLabel !== void 0) finalHeadless.projectLabel = projectLabel;
457
+ headlessOut.push(finalHeadless);
458
+ }
459
+ return [...ordered.map((a) => a.record), ...headlessOut];
460
+ }
461
+ function mergeUsageMax(tokens, u) {
462
+ tokens.input = Math.max(tokens.input, toNonNegInt(u.input_tokens));
463
+ tokens.output = Math.max(tokens.output, toNonNegInt(u.output_tokens));
464
+ tokens.cacheRead = Math.max(tokens.cacheRead, toNonNegInt(u.cache_read_input_tokens));
465
+ tokens.cacheWrite = Math.max(tokens.cacheWrite, toNonNegInt(u.cache_creation_input_tokens));
466
+ }
467
+ function buildRecord(a) {
468
+ const modelId = a.rawModel !== void 0 && a.rawModel !== "" ? a.rawModel : DEFAULT_MODEL;
469
+ const record = {
470
+ platformId: PLATFORM_ID,
471
+ modelId,
472
+ providerId: resolveProvider(a.rawModel, a.providerHint),
473
+ sessionId: a.sessionId,
474
+ tokens: a.tokens,
475
+ ts: a.ts,
476
+ messageCount: a.messageCount,
477
+ confidence: "host-reported"
478
+ };
479
+ if (a.dedupKey !== void 0) record.dedupKey = a.dedupKey;
480
+ if (a.projectKey !== void 0) record.projectKey = a.projectKey;
481
+ if (a.projectLabel !== void 0) record.projectLabel = a.projectLabel;
482
+ if (a.agent !== void 0) record.agent = a.agent;
483
+ return record;
484
+ }
485
+ function extractModel(value) {
486
+ const top = asNonEmptyString(value["model"]);
487
+ if (top !== void 0) return top;
488
+ const message = value["message"];
489
+ return isObject(message) ? asNonEmptyString(message["model"]) : void 0;
490
+ }
491
+ function messageProviderHint(message) {
492
+ return asNonEmptyString(message["providerId"]) ?? asNonEmptyString(message["provider_id"]) ?? asNonEmptyString(message["provider"]);
493
+ }
494
+ function extractProviderHint(value) {
495
+ const top = asNonEmptyString(value["providerId"]) ?? asNonEmptyString(value["provider_id"]) ?? asNonEmptyString(value["provider"]);
496
+ if (top !== void 0) return top;
497
+ const message = value["message"];
498
+ return isObject(message) ? messageProviderHint(message) : void 0;
499
+ }
500
+ function extractClaudeTimestamp(value) {
501
+ const direct = parseTs(value["timestamp"]) ?? parseTs(value["created_at"]);
502
+ if (direct !== null) return direct;
503
+ const message = value["message"];
504
+ if (isObject(message)) {
505
+ const m = parseTs(message["created_at"]);
506
+ if (m !== null) return m;
507
+ }
508
+ return null;
509
+ }
510
+ function newHeadlessState() {
511
+ return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, ts: null };
512
+ }
513
+ function resetHeadlessState(s) {
514
+ s.model = void 0;
515
+ s.providerHint = void 0;
516
+ s.input = 0;
517
+ s.output = 0;
518
+ s.cacheRead = 0;
519
+ s.cacheWrite = 0;
520
+ s.ts = null;
521
+ }
522
+ function parseHeadlessJson(path, fallbackTs, projectKey, projectLabel) {
523
+ const value = readJsonFile(path);
524
+ if (!isObject(value)) return [];
525
+ const record = extractHeadlessMessage(value, "unknown-session", fallbackTs);
526
+ if (record === void 0) return [];
527
+ record.sessionId = stripExt(basename(path)) || "unknown";
528
+ if (projectKey !== void 0) record.projectKey = projectKey;
529
+ if (projectLabel !== void 0) record.projectLabel = projectLabel;
530
+ return [record];
531
+ }
532
+ function processHeadlessLine(value, _rawLine, sessionId, state, fallbackTs) {
533
+ const eventType = typeof value["type"] === "string" ? value["type"] : "";
534
+ switch (eventType) {
535
+ case "message_start": {
536
+ const completed = finalizeHeadlessState(state, sessionId, fallbackTs);
537
+ state.model = extractModel(value);
538
+ state.providerHint = extractProviderHint(value);
539
+ const ts = extractClaudeTimestamp(value);
540
+ if (ts !== null) state.ts = ts;
541
+ const message = value["message"];
542
+ const usage = (isObject(message) && isObject(message["usage"]) ? message["usage"] : void 0) ?? (isObject(value["usage"]) ? value["usage"] : void 0);
543
+ if (usage !== void 0) updateHeadlessUsage(state, usage);
544
+ return completed;
545
+ }
546
+ case "message_delta": {
547
+ const delta = value["delta"];
548
+ const usage = (isObject(value["usage"]) ? value["usage"] : void 0) ?? (isObject(delta) && isObject(delta["usage"]) ? delta["usage"] : void 0);
549
+ if (usage !== void 0) updateHeadlessUsage(state, usage);
550
+ return void 0;
551
+ }
552
+ case "message_stop":
553
+ return finalizeHeadlessState(state, sessionId, fallbackTs);
554
+ default:
555
+ return extractHeadlessMessage(value, sessionId, fallbackTs);
556
+ }
557
+ }
558
+ function updateHeadlessUsage(state, usage) {
559
+ const input = toIntOrNull(usage["input_tokens"]);
560
+ if (input !== null) state.input = Math.max(state.input, input);
561
+ const output = toIntOrNull(usage["output_tokens"]);
562
+ if (output !== null) state.output = Math.max(state.output, output);
563
+ const cacheRead = toIntOrNull(usage["cache_read_input_tokens"]);
564
+ if (cacheRead !== null) state.cacheRead = Math.max(state.cacheRead, cacheRead);
565
+ const cacheWrite = toIntOrNull(usage["cache_creation_input_tokens"]);
566
+ if (cacheWrite !== null) state.cacheWrite = Math.max(state.cacheWrite, cacheWrite);
567
+ }
568
+ function finalizeHeadlessState(state, sessionId, fallbackTs) {
569
+ const rawModel = state.model;
570
+ if (rawModel === void 0) return void 0;
571
+ if (state.input === 0 && state.output === 0 && state.cacheRead === 0 && state.cacheWrite === 0) {
572
+ resetHeadlessState(state);
573
+ return void 0;
574
+ }
575
+ const tokens = emptyTokens();
576
+ tokens.input = Math.max(0, state.input);
577
+ tokens.output = Math.max(0, state.output);
578
+ tokens.cacheRead = Math.max(0, state.cacheRead);
579
+ tokens.cacheWrite = Math.max(0, state.cacheWrite);
580
+ const record = buildRecord({
581
+ rawModel,
582
+ providerHint: state.providerHint,
583
+ sessionId,
584
+ ts: state.ts ?? fallbackTs,
585
+ tokens,
586
+ messageCount: 1,
587
+ dedupKey: void 0,
588
+ projectKey: void 0,
589
+ projectLabel: void 0,
590
+ agent: void 0
591
+ });
592
+ resetHeadlessState(state);
593
+ return record;
594
+ }
595
+ function extractHeadlessMessage(value, sessionId, fallbackTs) {
596
+ const message = value["message"];
597
+ const usage = (isObject(value["usage"]) ? value["usage"] : void 0) ?? (isObject(message) && isObject(message["usage"]) ? message["usage"] : void 0);
598
+ if (usage === void 0) return void 0;
599
+ const rawModel = extractModel(value);
600
+ if (rawModel === void 0) return void 0;
601
+ const providerHint = extractProviderHint(value);
602
+ const ts = extractClaudeTimestamp(value) ?? fallbackTs;
603
+ const tokens = emptyTokens();
604
+ tokens.input = Math.max(0, toIntOrNull(usage["input_tokens"]) ?? 0);
605
+ tokens.output = Math.max(0, toIntOrNull(usage["output_tokens"]) ?? 0);
606
+ tokens.cacheRead = Math.max(0, toIntOrNull(usage["cache_read_input_tokens"]) ?? 0);
607
+ tokens.cacheWrite = Math.max(0, toIntOrNull(usage["cache_creation_input_tokens"]) ?? 0);
608
+ return buildRecord({
609
+ rawModel,
610
+ providerHint,
611
+ sessionId,
612
+ ts,
613
+ tokens,
614
+ messageCount: 1,
615
+ dedupKey: void 0,
616
+ projectKey: void 0,
617
+ projectLabel: void 0,
618
+ agent: void 0
619
+ });
620
+ }
621
+ var claudeCodeReader = {
622
+ platformId: PLATFORM_ID,
623
+ kind: "local",
624
+ async read({ sinceMs }) {
625
+ const root = firstExistingRoot(PLATFORM_ID);
626
+ if (root === void 0) return [];
627
+ const files = walkFiles(root, (name) => {
628
+ if (name.endsWith(".meta.json")) return false;
629
+ return name.endsWith(".jsonl") || name.endsWith(".json");
630
+ });
631
+ const parentCache = /* @__PURE__ */ new Map();
632
+ const records = [];
633
+ for (const file of files) {
634
+ let rows;
635
+ try {
636
+ rows = parseClaudeFile(file, parentCache);
637
+ } catch {
638
+ continue;
639
+ }
640
+ for (const row of rows) {
641
+ if (sinceMs !== void 0 && row.ts < sinceMs) continue;
642
+ records.push(row);
643
+ }
644
+ }
645
+ return records;
646
+ }
647
+ };
648
+ var claude_code_default = claudeCodeReader;
649
+ export {
650
+ claude_code_default as default
651
+ };
652
+ //# sourceMappingURL=claude-code-W74MNTAC.js.map