@codemieai/code 0.0.27 → 0.0.29

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 (484) hide show
  1. package/README.md +9 -11
  2. package/bin/agent-executor.js +1 -1
  3. package/dist/agents/codemie-code/agent.js +1 -1
  4. package/dist/agents/codemie-code/config.d.ts +1 -1
  5. package/dist/agents/codemie-code/config.d.ts.map +1 -1
  6. package/dist/agents/codemie-code/config.js +3 -4
  7. package/dist/agents/codemie-code/config.js.map +1 -1
  8. package/dist/agents/codemie-code/index.js +1 -1
  9. package/dist/agents/codemie-code/storage/todoStorage.d.ts.map +1 -1
  10. package/dist/agents/codemie-code/storage/todoStorage.js +2 -2
  11. package/dist/agents/codemie-code/storage/todoStorage.js.map +1 -1
  12. package/dist/agents/codemie-code/tools/index.js +1 -1
  13. package/dist/agents/codemie-code/tools/index.js.map +1 -1
  14. package/dist/agents/core/AgentCLI.d.ts.map +1 -1
  15. package/dist/agents/core/AgentCLI.js +6 -10
  16. package/dist/agents/core/AgentCLI.js.map +1 -1
  17. package/dist/agents/core/BaseAgentAdapter.d.ts +17 -9
  18. package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
  19. package/dist/agents/core/BaseAgentAdapter.js +80 -72
  20. package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
  21. package/dist/agents/core/extension/BaseExtensionInstaller.d.ts +258 -0
  22. package/dist/agents/core/extension/BaseExtensionInstaller.d.ts.map +1 -0
  23. package/dist/agents/core/extension/BaseExtensionInstaller.js +522 -0
  24. package/dist/agents/core/extension/BaseExtensionInstaller.js.map +1 -0
  25. package/dist/agents/core/lifecycle-helpers.d.ts.map +1 -1
  26. package/dist/agents/core/lifecycle-helpers.js +16 -2
  27. package/dist/agents/core/lifecycle-helpers.js.map +1 -1
  28. package/dist/agents/core/metrics/index.d.ts +0 -2
  29. package/dist/agents/core/metrics/index.d.ts.map +1 -1
  30. package/dist/agents/core/metrics/index.js +0 -3
  31. package/dist/agents/core/metrics/index.js.map +1 -1
  32. package/dist/agents/core/metrics/types.d.ts +4 -232
  33. package/dist/agents/core/metrics/types.d.ts.map +1 -1
  34. package/dist/agents/core/metrics/types.js +2 -2
  35. package/dist/agents/core/session/BaseProcessor.d.ts +72 -0
  36. package/dist/agents/core/session/BaseProcessor.d.ts.map +1 -0
  37. package/dist/agents/core/session/BaseProcessor.js +9 -0
  38. package/dist/agents/core/session/BaseProcessor.js.map +1 -0
  39. package/dist/agents/core/session/BaseSessionAdapter.d.ts +99 -0
  40. package/dist/agents/core/session/BaseSessionAdapter.d.ts.map +1 -0
  41. package/dist/agents/core/session/BaseSessionAdapter.js +9 -0
  42. package/dist/agents/core/session/BaseSessionAdapter.js.map +1 -0
  43. package/dist/agents/core/session/SessionStore.d.ts +23 -0
  44. package/dist/agents/core/session/SessionStore.d.ts.map +1 -0
  45. package/dist/agents/core/session/SessionStore.js +75 -0
  46. package/dist/agents/core/session/SessionStore.js.map +1 -0
  47. package/dist/agents/core/session/session-config.d.ts +27 -0
  48. package/dist/agents/core/session/session-config.d.ts.map +1 -0
  49. package/dist/agents/core/session/session-config.js +61 -0
  50. package/dist/agents/core/session/session-config.js.map +1 -0
  51. package/dist/agents/core/session/types.d.ts +87 -0
  52. package/dist/agents/core/session/types.d.ts.map +1 -0
  53. package/dist/agents/core/session/types.js +8 -0
  54. package/dist/agents/core/session/types.js.map +1 -0
  55. package/dist/agents/core/session/utils/jsonl-reader.d.ts +15 -0
  56. package/dist/agents/core/session/utils/jsonl-reader.d.ts.map +1 -0
  57. package/dist/agents/core/session/utils/jsonl-reader.js +33 -0
  58. package/dist/agents/core/session/utils/jsonl-reader.js.map +1 -0
  59. package/dist/agents/core/session/utils/jsonl-writer.d.ts +26 -0
  60. package/dist/agents/core/session/utils/jsonl-writer.d.ts.map +1 -0
  61. package/dist/agents/core/session/utils/jsonl-writer.js +56 -0
  62. package/dist/agents/core/session/utils/jsonl-writer.js.map +1 -0
  63. package/dist/agents/core/types.d.ts +78 -11
  64. package/dist/agents/core/types.d.ts.map +1 -1
  65. package/dist/agents/plugins/claude/claude-message-types.d.ts +74 -0
  66. package/dist/agents/plugins/claude/claude-message-types.d.ts.map +1 -0
  67. package/dist/agents/plugins/claude/claude-message-types.js +8 -0
  68. package/dist/agents/plugins/claude/claude-message-types.js.map +1 -0
  69. package/dist/agents/plugins/claude/claude.plugin-installer.d.ts +53 -0
  70. package/dist/agents/plugins/claude/claude.plugin-installer.d.ts.map +1 -0
  71. package/dist/agents/plugins/claude/claude.plugin-installer.js +63 -0
  72. package/dist/agents/plugins/claude/claude.plugin-installer.js.map +1 -0
  73. package/dist/agents/plugins/claude/claude.plugin.d.ts +26 -0
  74. package/dist/agents/plugins/claude/claude.plugin.d.ts.map +1 -0
  75. package/dist/agents/plugins/{claude.plugin.js → claude/claude.plugin.js} +20 -11
  76. package/dist/agents/plugins/claude/claude.plugin.js.map +1 -0
  77. package/dist/agents/plugins/claude/claude.session.d.ts +60 -0
  78. package/dist/agents/plugins/claude/claude.session.d.ts.map +1 -0
  79. package/dist/agents/plugins/claude/claude.session.js +339 -0
  80. package/dist/agents/plugins/claude/claude.session.js.map +1 -0
  81. package/dist/agents/plugins/claude/plugin/.claude-plugin/local-install.json +15 -0
  82. package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +9 -0
  83. package/dist/agents/plugins/claude/plugin/README.md +299 -0
  84. package/dist/agents/plugins/claude/plugin/claude-templates/README.md +539 -0
  85. package/dist/agents/plugins/claude/plugin/claude-templates/templates/CLAUDE.md.template +511 -0
  86. package/dist/agents/plugins/claude/plugin/claude-templates/templates/INDEX.md +205 -0
  87. package/dist/agents/plugins/claude/plugin/claude-templates/templates/TEMPLATE_SIZES.md +74 -0
  88. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/api/api-patterns.md.template +207 -0
  89. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/layered-architecture.md.template +143 -0
  90. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/project-structure.md.template +127 -0
  91. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/data/database-patterns.md.template +168 -0
  92. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/development/development-practices.md.template +210 -0
  93. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/integration/external-integrations.md.template +160 -0
  94. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/security/security-practices.md.template +170 -0
  95. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/standards/code-quality.md.template +150 -0
  96. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/standards/git-workflow.md.template +177 -0
  97. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/testing/testing-patterns.md.template +143 -0
  98. package/dist/agents/plugins/claude/plugin/commands/README.md +0 -0
  99. package/dist/agents/plugins/claude/plugin/commands/codemie-catchup.md +10 -0
  100. package/dist/agents/plugins/claude/plugin/commands/codemie-init.md +731 -0
  101. package/dist/agents/plugins/claude/plugin/commands/memory-add.md +44 -0
  102. package/dist/agents/plugins/claude/plugin/commands/memory-init.md +18 -0
  103. package/dist/agents/plugins/claude/plugin/commands/memory-refresh.md +54 -0
  104. package/dist/agents/plugins/claude/plugin/hooks/hooks.json +71 -0
  105. package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.d.ts +51 -0
  106. package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.d.ts.map +1 -0
  107. package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js +840 -0
  108. package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js.map +1 -0
  109. package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.d.ts +37 -0
  110. package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.d.ts.map +1 -0
  111. package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js +275 -0
  112. package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js.map +1 -0
  113. package/dist/agents/plugins/codemie-code.plugin.js +1 -1
  114. package/dist/agents/plugins/codemie-code.plugin.js.map +1 -1
  115. package/dist/agents/plugins/gemini/extension/README.md +88 -0
  116. package/dist/agents/plugins/gemini/extension/gemini-extension.json +11 -0
  117. package/dist/agents/plugins/gemini/extension/hooks/hooks.json +65 -0
  118. package/dist/agents/plugins/gemini/gemini.extension-installer.d.ts +49 -0
  119. package/dist/agents/plugins/gemini/gemini.extension-installer.d.ts.map +1 -0
  120. package/dist/agents/plugins/gemini/gemini.extension-installer.js +63 -0
  121. package/dist/agents/plugins/gemini/gemini.extension-installer.js.map +1 -0
  122. package/dist/agents/plugins/gemini/gemini.hook-transformer.d.ts +43 -0
  123. package/dist/agents/plugins/gemini/gemini.hook-transformer.d.ts.map +1 -0
  124. package/dist/agents/plugins/gemini/gemini.hook-transformer.js +57 -0
  125. package/dist/agents/plugins/gemini/gemini.hook-transformer.js.map +1 -0
  126. package/dist/agents/plugins/gemini/gemini.plugin.d.ts +32 -0
  127. package/dist/agents/plugins/gemini/gemini.plugin.d.ts.map +1 -0
  128. package/dist/agents/plugins/gemini/gemini.plugin.js +136 -0
  129. package/dist/agents/plugins/gemini/gemini.plugin.js.map +1 -0
  130. package/dist/agents/plugins/gemini/gemini.session-adapter.d.ts +68 -0
  131. package/dist/agents/plugins/gemini/gemini.session-adapter.d.ts.map +1 -0
  132. package/dist/agents/plugins/gemini/gemini.session-adapter.js +268 -0
  133. package/dist/agents/plugins/gemini/gemini.session-adapter.js.map +1 -0
  134. package/dist/agents/plugins/gemini/session/processors/gemini.conversations-processor.d.ts +36 -0
  135. package/dist/agents/plugins/gemini/session/processors/gemini.conversations-processor.d.ts.map +1 -0
  136. package/dist/agents/plugins/gemini/session/processors/gemini.conversations-processor.js +186 -0
  137. package/dist/agents/plugins/gemini/session/processors/gemini.conversations-processor.js.map +1 -0
  138. package/dist/agents/plugins/gemini/session/processors/gemini.metrics-processor.d.ts +32 -0
  139. package/dist/agents/plugins/gemini/session/processors/gemini.metrics-processor.d.ts.map +1 -0
  140. package/dist/agents/plugins/gemini/session/processors/gemini.metrics-processor.js +193 -0
  141. package/dist/agents/plugins/gemini/session/processors/gemini.metrics-processor.js.map +1 -0
  142. package/dist/agents/plugins/gemini/session/utils/token-aggregator.d.ts +26 -0
  143. package/dist/agents/plugins/gemini/session/utils/token-aggregator.d.ts.map +1 -0
  144. package/dist/agents/plugins/gemini/session/utils/token-aggregator.js +38 -0
  145. package/dist/agents/plugins/gemini/session/utils/token-aggregator.js.map +1 -0
  146. package/dist/agents/plugins/gemini/session/utils/tool-aggregator.d.ts +33 -0
  147. package/dist/agents/plugins/gemini/session/utils/tool-aggregator.d.ts.map +1 -0
  148. package/dist/agents/plugins/gemini/session/utils/tool-aggregator.js +58 -0
  149. package/dist/agents/plugins/gemini/session/utils/tool-aggregator.js.map +1 -0
  150. package/dist/agents/plugins/gemini/session/utils/turn-detector.d.ts +70 -0
  151. package/dist/agents/plugins/gemini/session/utils/turn-detector.d.ts.map +1 -0
  152. package/dist/agents/plugins/gemini/session/utils/turn-detector.js +86 -0
  153. package/dist/agents/plugins/gemini/session/utils/turn-detector.js.map +1 -0
  154. package/dist/agents/registry.d.ts +7 -2
  155. package/dist/agents/registry.d.ts.map +1 -1
  156. package/dist/agents/registry.js +17 -8
  157. package/dist/agents/registry.js.map +1 -1
  158. package/dist/cli/commands/analytics/data-loader.d.ts +1 -1
  159. package/dist/cli/commands/analytics/data-loader.d.ts.map +1 -1
  160. package/dist/cli/commands/analytics/data-loader.js +3 -3
  161. package/dist/cli/commands/analytics/data-loader.js.map +1 -1
  162. package/dist/cli/commands/analytics/index.js +1 -1
  163. package/dist/cli/commands/analytics/index.js.map +1 -1
  164. package/dist/cli/commands/doctor/checks/AIConfigCheck.js +1 -1
  165. package/dist/cli/commands/doctor/checks/AIConfigCheck.js.map +1 -1
  166. package/dist/cli/commands/doctor/checks/AwsCliCheck.js +1 -1
  167. package/dist/cli/commands/doctor/checks/AwsCliCheck.js.map +1 -1
  168. package/dist/cli/commands/doctor/checks/NpmCheck.js +1 -1
  169. package/dist/cli/commands/doctor/checks/NpmCheck.js.map +1 -1
  170. package/dist/cli/commands/doctor/checks/PythonCheck.d.ts +13 -0
  171. package/dist/cli/commands/doctor/checks/PythonCheck.d.ts.map +1 -1
  172. package/dist/cli/commands/doctor/checks/PythonCheck.js +91 -32
  173. package/dist/cli/commands/doctor/checks/PythonCheck.js.map +1 -1
  174. package/dist/cli/commands/doctor/checks/UvCheck.js +1 -1
  175. package/dist/cli/commands/doctor/checks/UvCheck.js.map +1 -1
  176. package/dist/cli/commands/doctor/types.d.ts +1 -1
  177. package/dist/cli/commands/doctor/types.d.ts.map +1 -1
  178. package/dist/cli/commands/hook.d.ts +7 -0
  179. package/dist/cli/commands/hook.d.ts.map +1 -0
  180. package/dist/cli/commands/hook.js +788 -0
  181. package/dist/cli/commands/hook.js.map +1 -0
  182. package/dist/cli/commands/profile/auth.js +1 -1
  183. package/dist/cli/commands/profile/auth.js.map +1 -1
  184. package/dist/{utils/profile-display.d.ts → cli/commands/profile/display.d.ts} +3 -3
  185. package/dist/cli/commands/profile/display.d.ts.map +1 -0
  186. package/dist/{utils/profile-display.js → cli/commands/profile/display.js} +2 -2
  187. package/dist/cli/commands/profile/display.js.map +1 -0
  188. package/dist/cli/commands/profile/index.js +2 -2
  189. package/dist/cli/commands/profile/index.js.map +1 -1
  190. package/dist/cli/commands/setup.d.ts.map +1 -1
  191. package/dist/cli/commands/setup.js +4 -5
  192. package/dist/cli/commands/setup.js.map +1 -1
  193. package/dist/cli/commands/update.d.ts +3 -0
  194. package/dist/cli/commands/update.d.ts.map +1 -0
  195. package/dist/cli/commands/update.js +291 -0
  196. package/dist/cli/commands/update.js.map +1 -0
  197. package/dist/cli/commands/version.js +1 -1
  198. package/dist/cli/commands/version.js.map +1 -1
  199. package/dist/{utils → cli}/first-time.d.ts +4 -0
  200. package/dist/cli/first-time.d.ts.map +1 -0
  201. package/dist/{utils → cli}/first-time.js +27 -14
  202. package/dist/cli/first-time.js.map +1 -0
  203. package/dist/cli/index.js +6 -2
  204. package/dist/cli/index.js.map +1 -1
  205. package/dist/env/manager.d.ts.map +1 -1
  206. package/dist/env/manager.js +3 -4
  207. package/dist/env/manager.js.map +1 -1
  208. package/dist/frameworks/core/BaseFrameworkAdapter.js +1 -1
  209. package/dist/frameworks/core/BaseFrameworkAdapter.js.map +1 -1
  210. package/dist/frameworks/core/types.d.ts +1 -1
  211. package/dist/frameworks/plugins/bmad.plugin.js +2 -2
  212. package/dist/frameworks/plugins/bmad.plugin.js.map +1 -1
  213. package/dist/frameworks/plugins/speckit.plugin.d.ts.map +1 -1
  214. package/dist/frameworks/plugins/speckit.plugin.js +2 -3
  215. package/dist/frameworks/plugins/speckit.plugin.js.map +1 -1
  216. package/dist/index.d.ts +1 -1
  217. package/dist/index.d.ts.map +1 -1
  218. package/dist/index.js +1 -1
  219. package/dist/index.js.map +1 -1
  220. package/dist/migrations/001-config-rename.migration.d.ts.map +1 -1
  221. package/dist/migrations/001-config-rename.migration.js +2 -2
  222. package/dist/migrations/001-config-rename.migration.js.map +1 -1
  223. package/dist/migrations/002-consolidate-sessions.migration.d.ts +50 -0
  224. package/dist/migrations/002-consolidate-sessions.migration.d.ts.map +1 -0
  225. package/dist/migrations/002-consolidate-sessions.migration.js +220 -0
  226. package/dist/migrations/002-consolidate-sessions.migration.js.map +1 -0
  227. package/dist/migrations/index.d.ts +1 -0
  228. package/dist/migrations/index.d.ts.map +1 -1
  229. package/dist/migrations/index.js +3 -2
  230. package/dist/migrations/index.js.map +1 -1
  231. package/dist/migrations/tracker.d.ts.map +1 -1
  232. package/dist/migrations/tracker.js +2 -2
  233. package/dist/migrations/tracker.js.map +1 -1
  234. package/dist/providers/core/base/http-client.js +1 -1
  235. package/dist/providers/core/types.d.ts +1 -1
  236. package/dist/providers/plugins/ollama/ollama.template.d.ts.map +1 -1
  237. package/dist/providers/plugins/ollama/ollama.template.js +3 -1
  238. package/dist/providers/plugins/ollama/ollama.template.js.map +1 -1
  239. package/dist/providers/plugins/sso/index.d.ts +1 -1
  240. package/dist/providers/plugins/sso/index.d.ts.map +1 -1
  241. package/dist/providers/plugins/sso/index.js +1 -1
  242. package/dist/providers/plugins/sso/index.js.map +1 -1
  243. package/dist/providers/plugins/sso/proxy/plugins/index.d.ts +1 -1
  244. package/dist/providers/plugins/sso/proxy/plugins/index.d.ts.map +1 -1
  245. package/dist/providers/plugins/sso/proxy/plugins/index.js +3 -3
  246. package/dist/providers/plugins/sso/proxy/plugins/index.js.map +1 -1
  247. package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.d.ts +40 -0
  248. package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.d.ts.map +1 -0
  249. package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js +194 -0
  250. package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js.map +1 -0
  251. package/dist/providers/plugins/sso/proxy/proxy-http-client.d.ts +1 -0
  252. package/dist/providers/plugins/sso/proxy/proxy-http-client.d.ts.map +1 -1
  253. package/dist/providers/plugins/sso/proxy/proxy-http-client.js +40 -6
  254. package/dist/providers/plugins/sso/proxy/proxy-http-client.js.map +1 -1
  255. package/dist/providers/plugins/sso/session/BaseProcessor.d.ts +72 -0
  256. package/dist/providers/plugins/sso/session/BaseProcessor.d.ts.map +1 -0
  257. package/dist/providers/plugins/sso/session/BaseProcessor.js +9 -0
  258. package/dist/providers/plugins/sso/session/BaseProcessor.js.map +1 -0
  259. package/dist/providers/plugins/sso/session/BaseSessionAdapter.d.ts +99 -0
  260. package/dist/providers/plugins/sso/session/BaseSessionAdapter.d.ts.map +1 -0
  261. package/dist/providers/plugins/sso/session/BaseSessionAdapter.js +9 -0
  262. package/dist/providers/plugins/sso/session/BaseSessionAdapter.js.map +1 -0
  263. package/dist/providers/plugins/sso/session/SessionSyncer.d.ts +36 -0
  264. package/dist/providers/plugins/sso/session/SessionSyncer.d.ts.map +1 -0
  265. package/dist/providers/plugins/sso/session/SessionSyncer.js +140 -0
  266. package/dist/providers/plugins/sso/session/SessionSyncer.js.map +1 -0
  267. package/dist/providers/plugins/sso/session/processors/conversations/conversation-api-client.d.ts +26 -0
  268. package/dist/providers/plugins/sso/session/processors/conversations/conversation-api-client.d.ts.map +1 -0
  269. package/dist/providers/plugins/sso/session/processors/conversations/conversation-api-client.js +146 -0
  270. package/dist/providers/plugins/sso/session/processors/conversations/conversation-api-client.js.map +1 -0
  271. package/dist/providers/plugins/sso/session/processors/conversations/conversation-sync-processor.d.ts +23 -0
  272. package/dist/providers/plugins/sso/session/processors/conversations/conversation-sync-processor.d.ts.map +1 -0
  273. package/dist/providers/plugins/sso/session/processors/conversations/conversation-sync-processor.js +171 -0
  274. package/dist/providers/plugins/sso/session/processors/conversations/conversation-sync-processor.js.map +1 -0
  275. package/dist/providers/plugins/sso/session/processors/conversations/conversation-types.d.ts +69 -0
  276. package/dist/providers/plugins/sso/session/processors/conversations/conversation-types.d.ts.map +1 -0
  277. package/dist/providers/plugins/sso/session/processors/conversations/conversation-types.js +7 -0
  278. package/dist/providers/plugins/sso/session/processors/conversations/conversation-types.js.map +1 -0
  279. package/dist/providers/plugins/sso/session/processors/metrics/MetricsWriter.d.ts +30 -0
  280. package/dist/providers/plugins/sso/session/processors/metrics/MetricsWriter.d.ts.map +1 -0
  281. package/dist/providers/plugins/sso/session/processors/metrics/MetricsWriter.js +79 -0
  282. package/dist/providers/plugins/sso/session/processors/metrics/MetricsWriter.js.map +1 -0
  283. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-aggregator.d.ts → session/processors/metrics/metrics-aggregator.d.ts} +6 -5
  284. package/dist/providers/plugins/sso/session/processors/metrics/metrics-aggregator.d.ts.map +1 -0
  285. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-aggregator.js → session/processors/metrics/metrics-aggregator.js} +20 -12
  286. package/dist/providers/plugins/sso/session/processors/metrics/metrics-aggregator.js.map +1 -0
  287. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-sender.d.ts → session/processors/metrics/metrics-api-client.d.ts} +18 -11
  288. package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.d.ts.map +1 -0
  289. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-sender.js → session/processors/metrics/metrics-api-client.js} +143 -15
  290. package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.js.map +1 -0
  291. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-post-processor.d.ts → session/processors/metrics/metrics-post-processor.d.ts} +3 -3
  292. package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.d.ts.map +1 -0
  293. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-post-processor.js → session/processors/metrics/metrics-post-processor.js} +3 -3
  294. package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.js.map +1 -0
  295. package/dist/providers/plugins/sso/session/processors/metrics/metrics-sync-processor.d.ts +24 -0
  296. package/dist/providers/plugins/sso/session/processors/metrics/metrics-sync-processor.d.ts.map +1 -0
  297. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-sync.plugin.js → session/processors/metrics/metrics-sync-processor.js} +94 -165
  298. package/dist/providers/plugins/sso/session/processors/metrics/metrics-sync-processor.js.map +1 -0
  299. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-types.d.ts → session/processors/metrics/metrics-types.d.ts} +2 -1
  300. package/dist/providers/plugins/sso/session/processors/metrics/metrics-types.d.ts.map +1 -0
  301. package/dist/providers/plugins/sso/{metrics/sync/sso.metrics-types.js → session/processors/metrics/metrics-types.js} +1 -1
  302. package/dist/providers/plugins/sso/session/processors/metrics/metrics-types.js.map +1 -0
  303. package/dist/providers/plugins/sso/session/utils/jsonl-reader.d.ts +15 -0
  304. package/dist/providers/plugins/sso/session/utils/jsonl-reader.d.ts.map +1 -0
  305. package/dist/providers/plugins/sso/session/utils/jsonl-reader.js +33 -0
  306. package/dist/providers/plugins/sso/session/utils/jsonl-reader.js.map +1 -0
  307. package/dist/providers/plugins/sso/session/utils/jsonl-writer.d.ts +26 -0
  308. package/dist/providers/plugins/sso/session/utils/jsonl-writer.d.ts.map +1 -0
  309. package/dist/providers/plugins/sso/{metrics/sync/sso.jsonl-writer.js → session/utils/jsonl-writer.js} +11 -27
  310. package/dist/providers/plugins/sso/session/utils/jsonl-writer.js.map +1 -0
  311. package/dist/providers/plugins/sso/sso.auth.js +1 -1
  312. package/dist/providers/plugins/sso/sso.auth.js.map +1 -1
  313. package/dist/providers/plugins/sso/sso.http-client.d.ts +1 -1
  314. package/dist/providers/plugins/sso/sso.http-client.js +1 -1
  315. package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
  316. package/dist/providers/plugins/sso/sso.template.d.ts.map +1 -1
  317. package/dist/providers/plugins/sso/sso.template.js +71 -43
  318. package/dist/providers/plugins/sso/sso.template.js.map +1 -1
  319. package/dist/utils/{config-loader.d.ts → config.d.ts} +6 -1
  320. package/dist/utils/config.d.ts.map +1 -0
  321. package/dist/utils/{config-loader.js → config.js} +30 -4
  322. package/dist/utils/config.js.map +1 -0
  323. package/dist/utils/errors.d.ts +89 -0
  324. package/dist/utils/errors.d.ts.map +1 -1
  325. package/dist/utils/errors.js +340 -0
  326. package/dist/utils/errors.js.map +1 -1
  327. package/dist/utils/exec.d.ts +6 -0
  328. package/dist/utils/exec.d.ts.map +1 -1
  329. package/dist/utils/exec.js +6 -0
  330. package/dist/utils/exec.js.map +1 -1
  331. package/dist/utils/file-operations.d.ts +20 -0
  332. package/dist/utils/file-operations.d.ts.map +1 -0
  333. package/dist/utils/file-operations.js +48 -0
  334. package/dist/utils/file-operations.js.map +1 -0
  335. package/dist/utils/logger.d.ts +2 -1
  336. package/dist/utils/logger.d.ts.map +1 -1
  337. package/dist/utils/logger.js +15 -7
  338. package/dist/utils/logger.js.map +1 -1
  339. package/dist/utils/{json-parser.d.ts → parsers.d.ts} +1 -1
  340. package/dist/utils/parsers.d.ts.map +1 -0
  341. package/dist/utils/{json-parser.js → parsers.js} +1 -1
  342. package/dist/utils/parsers.js.map +1 -0
  343. package/dist/utils/{path-utils.d.ts → paths.d.ts} +77 -12
  344. package/dist/utils/paths.d.ts.map +1 -0
  345. package/dist/utils/{path-utils.js → paths.js} +103 -12
  346. package/dist/utils/paths.js.map +1 -0
  347. package/dist/utils/{npm.d.ts → processes.d.ts} +44 -7
  348. package/dist/utils/processes.d.ts.map +1 -0
  349. package/dist/utils/{npm.js → processes.js} +129 -10
  350. package/dist/utils/processes.js.map +1 -0
  351. package/dist/utils/profile.d.ts +1 -16
  352. package/dist/utils/profile.d.ts.map +1 -1
  353. package/dist/utils/profile.js +1 -27
  354. package/dist/utils/profile.js.map +1 -1
  355. package/dist/utils/security.d.ts +62 -0
  356. package/dist/utils/security.d.ts.map +1 -0
  357. package/dist/utils/security.js +396 -0
  358. package/dist/utils/security.js.map +1 -0
  359. package/package.json +11 -11
  360. package/scripts/copy-plugins.js +57 -0
  361. package/scripts/license-check.js +23 -0
  362. package/bin/codemie-codex.js +0 -18
  363. package/bin/codemie-deepagents.js +0 -18
  364. package/dist/agents/core/BaseMetricsAdapter.d.ts +0 -165
  365. package/dist/agents/core/BaseMetricsAdapter.d.ts.map +0 -1
  366. package/dist/agents/core/BaseMetricsAdapter.js +0 -308
  367. package/dist/agents/core/BaseMetricsAdapter.js.map +0 -1
  368. package/dist/agents/core/metrics/MetricsOrchestrator.d.ts +0 -81
  369. package/dist/agents/core/metrics/MetricsOrchestrator.d.ts.map +0 -1
  370. package/dist/agents/core/metrics/MetricsOrchestrator.js +0 -417
  371. package/dist/agents/core/metrics/MetricsOrchestrator.js.map +0 -1
  372. package/dist/agents/core/metrics/core/DeltaWriter.d.ts +0 -49
  373. package/dist/agents/core/metrics/core/DeltaWriter.d.ts.map +0 -1
  374. package/dist/agents/core/metrics/core/DeltaWriter.js +0 -152
  375. package/dist/agents/core/metrics/core/DeltaWriter.js.map +0 -1
  376. package/dist/agents/core/metrics/core/FileSnapshotter.d.ts +0 -22
  377. package/dist/agents/core/metrics/core/FileSnapshotter.d.ts.map +0 -1
  378. package/dist/agents/core/metrics/core/FileSnapshotter.js +0 -74
  379. package/dist/agents/core/metrics/core/FileSnapshotter.js.map +0 -1
  380. package/dist/agents/core/metrics/core/SessionCorrelator.d.ts +0 -34
  381. package/dist/agents/core/metrics/core/SessionCorrelator.d.ts.map +0 -1
  382. package/dist/agents/core/metrics/core/SessionCorrelator.js +0 -157
  383. package/dist/agents/core/metrics/core/SessionCorrelator.js.map +0 -1
  384. package/dist/agents/core/metrics/core/SyncStateManager.d.ts +0 -69
  385. package/dist/agents/core/metrics/core/SyncStateManager.d.ts.map +0 -1
  386. package/dist/agents/core/metrics/core/SyncStateManager.js +0 -283
  387. package/dist/agents/core/metrics/core/SyncStateManager.js.map +0 -1
  388. package/dist/agents/core/metrics/session/SessionStore.d.ts +0 -43
  389. package/dist/agents/core/metrics/session/SessionStore.d.ts.map +0 -1
  390. package/dist/agents/core/metrics/session/SessionStore.js +0 -146
  391. package/dist/agents/core/metrics/session/SessionStore.js.map +0 -1
  392. package/dist/agents/core/metrics-config.d.ts +0 -38
  393. package/dist/agents/core/metrics-config.d.ts.map +0 -1
  394. package/dist/agents/core/metrics-config.js +0 -95
  395. package/dist/agents/core/metrics-config.js.map +0 -1
  396. package/dist/agents/plugins/claude.metrics.d.ts +0 -102
  397. package/dist/agents/plugins/claude.metrics.d.ts.map +0 -1
  398. package/dist/agents/plugins/claude.metrics.js +0 -656
  399. package/dist/agents/plugins/claude.metrics.js.map +0 -1
  400. package/dist/agents/plugins/claude.plugin.d.ts +0 -19
  401. package/dist/agents/plugins/claude.plugin.d.ts.map +0 -1
  402. package/dist/agents/plugins/claude.plugin.js.map +0 -1
  403. package/dist/agents/plugins/codex.plugin.d.ts +0 -17
  404. package/dist/agents/plugins/codex.plugin.d.ts.map +0 -1
  405. package/dist/agents/plugins/codex.plugin.js +0 -386
  406. package/dist/agents/plugins/codex.plugin.js.map +0 -1
  407. package/dist/agents/plugins/deepagents.plugin.d.ts +0 -21
  408. package/dist/agents/plugins/deepagents.plugin.d.ts.map +0 -1
  409. package/dist/agents/plugins/deepagents.plugin.js +0 -104
  410. package/dist/agents/plugins/deepagents.plugin.js.map +0 -1
  411. package/dist/agents/plugins/gemini.metrics.d.ts +0 -99
  412. package/dist/agents/plugins/gemini.metrics.d.ts.map +0 -1
  413. package/dist/agents/plugins/gemini.metrics.js +0 -475
  414. package/dist/agents/plugins/gemini.metrics.js.map +0 -1
  415. package/dist/agents/plugins/gemini.plugin.d.ts +0 -16
  416. package/dist/agents/plugins/gemini.plugin.d.ts.map +0 -1
  417. package/dist/agents/plugins/gemini.plugin.js +0 -80
  418. package/dist/agents/plugins/gemini.plugin.js.map +0 -1
  419. package/dist/agents/plugins/history-parser.d.ts +0 -52
  420. package/dist/agents/plugins/history-parser.d.ts.map +0 -1
  421. package/dist/agents/plugins/history-parser.js +0 -155
  422. package/dist/agents/plugins/history-parser.js.map +0 -1
  423. package/dist/providers/plugins/sso/metrics/sync/sso.jsonl-writer.d.ts +0 -28
  424. package/dist/providers/plugins/sso/metrics/sync/sso.jsonl-writer.d.ts.map +0 -1
  425. package/dist/providers/plugins/sso/metrics/sync/sso.jsonl-writer.js.map +0 -1
  426. package/dist/providers/plugins/sso/metrics/sync/sso.lifecycle-handler.d.ts +0 -62
  427. package/dist/providers/plugins/sso/metrics/sync/sso.lifecycle-handler.d.ts.map +0 -1
  428. package/dist/providers/plugins/sso/metrics/sync/sso.lifecycle-handler.js +0 -157
  429. package/dist/providers/plugins/sso/metrics/sync/sso.lifecycle-handler.js.map +0 -1
  430. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-aggregator.d.ts.map +0 -1
  431. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-aggregator.js.map +0 -1
  432. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-api-client.d.ts +0 -32
  433. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-api-client.d.ts.map +0 -1
  434. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-api-client.js +0 -159
  435. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-api-client.js.map +0 -1
  436. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-post-processor.d.ts.map +0 -1
  437. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-post-processor.js.map +0 -1
  438. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sender.d.ts.map +0 -1
  439. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sender.js.map +0 -1
  440. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sync.plugin.d.ts +0 -36
  441. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sync.plugin.d.ts.map +0 -1
  442. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-sync.plugin.js.map +0 -1
  443. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-types.d.ts.map +0 -1
  444. package/dist/providers/plugins/sso/metrics/sync/sso.metrics-types.js.map +0 -1
  445. package/dist/utils/config-loader.d.ts.map +0 -1
  446. package/dist/utils/config-loader.js.map +0 -1
  447. package/dist/utils/credential-store.d.ts +0 -22
  448. package/dist/utils/credential-store.d.ts.map +0 -1
  449. package/dist/utils/credential-store.js +0 -165
  450. package/dist/utils/credential-store.js.map +0 -1
  451. package/dist/utils/dirname.d.ts +0 -7
  452. package/dist/utils/dirname.d.ts.map +0 -1
  453. package/dist/utils/dirname.js +0 -11
  454. package/dist/utils/dirname.js.map +0 -1
  455. package/dist/utils/error-context.d.ts +0 -90
  456. package/dist/utils/error-context.d.ts.map +0 -1
  457. package/dist/utils/error-context.js +0 -338
  458. package/dist/utils/error-context.js.map +0 -1
  459. package/dist/utils/first-time.d.ts.map +0 -1
  460. package/dist/utils/first-time.js.map +0 -1
  461. package/dist/utils/git.d.ts +0 -13
  462. package/dist/utils/git.d.ts.map +0 -1
  463. package/dist/utils/git.js +0 -37
  464. package/dist/utils/git.js.map +0 -1
  465. package/dist/utils/installation-id.d.ts +0 -10
  466. package/dist/utils/installation-id.d.ts.map +0 -1
  467. package/dist/utils/installation-id.js +0 -30
  468. package/dist/utils/installation-id.js.map +0 -1
  469. package/dist/utils/json-parser.d.ts.map +0 -1
  470. package/dist/utils/json-parser.js.map +0 -1
  471. package/dist/utils/npm.d.ts.map +0 -1
  472. package/dist/utils/npm.js.map +0 -1
  473. package/dist/utils/path-utils.d.ts.map +0 -1
  474. package/dist/utils/path-utils.js.map +0 -1
  475. package/dist/utils/profile-display.d.ts.map +0 -1
  476. package/dist/utils/profile-display.js.map +0 -1
  477. package/dist/utils/sanitize.d.ts +0 -28
  478. package/dist/utils/sanitize.d.ts.map +0 -1
  479. package/dist/utils/sanitize.js +0 -212
  480. package/dist/utils/sanitize.js.map +0 -1
  481. package/dist/utils/which.d.ts +0 -20
  482. package/dist/utils/which.d.ts.map +0 -1
  483. package/dist/utils/which.js +0 -54
  484. package/dist/utils/which.js.map +0 -1
@@ -1,656 +0,0 @@
1
- /**
2
- * Claude Metrics Adapter
3
- *
4
- * Implements metrics support for Claude Code agent.
5
- * Handles Claude-specific file formats and parsing logic.
6
- */
7
- import { readFile, readdir } from 'fs/promises';
8
- import { join, dirname } from 'path';
9
- import { existsSync } from 'fs';
10
- import { BaseMetricsAdapter } from '../core/BaseMetricsAdapter.js';
11
- import { logger } from '../../utils/logger.js';
12
- import { parseMultiLineJSON } from '../../utils/json-parser.js';
13
- import { HistoryParser } from './history-parser.js';
14
- import { getFilename, matchesPathStructure, validatePathDepth, isValidUuidFilename } from '../../utils/path-utils.js';
15
- export class ClaudeMetricsAdapter extends BaseMetricsAdapter {
16
- // Note: dataPaths now comes from ClaudePluginMetadata passed via constructor
17
- /**
18
- * Check if file matches Claude session pattern
19
- * Pattern: ~/.claude/projects/{hash}/{session-id}.jsonl
20
- * Note: Claude uses JSONL (JSON Lines) format, not regular JSON
21
- * Matches UUID format but EXCLUDES agent-* files (those are sub-agents)
22
- *
23
- * Cross-platform implementation using reusable path utilities
24
- */
25
- matchesSessionPattern(filePath) {
26
- // Get constants from metadata (dataPaths passed via constructor)
27
- if (!this.metadata?.dataPaths?.home || !this.metadata?.dataPaths?.sessions) {
28
- return false;
29
- }
30
- const claudeDir = this.metadata.dataPaths.home; // '.claude'
31
- const projectsDir = this.metadata.dataPaths.sessions; // 'projects'
32
- const sessionExt = '.jsonl';
33
- // Check structure: .claude/projects/{hash}/{uuid}.jsonl
34
- // Uses cross-platform path utilities that normalize separators
35
- if (!matchesPathStructure(filePath, claudeDir, [projectsDir])) {
36
- return false;
37
- }
38
- // Validate depth: .claude + projects + hash + filename = 3 segments after .claude
39
- if (!validatePathDepth(filePath, claudeDir, 3)) {
40
- return false;
41
- }
42
- // Get the filename (last part)
43
- const filename = getFilename(filePath);
44
- // Explicitly reject agent-* files (sub-agents/sidechains)
45
- if (filename.startsWith('agent-')) {
46
- return false;
47
- }
48
- // Validate UUID format in filename
49
- return isValidUuidFilename(filename, sessionExt);
50
- }
51
- /**
52
- * Find all agent-*.jsonl files in the same directory as the session file
53
- * that belong to the same Claude sessionId (filters by sessionId)
54
- *
55
- * Agent files contain sub-agent/tool execution data with potentially different models
56
- *
57
- * @param sessionFilePath - Path to the main session file
58
- * @returns Array of agent file paths matching the same sessionId
59
- */
60
- async findAgentFiles(sessionFilePath) {
61
- try {
62
- const dir = dirname(sessionFilePath);
63
- if (!existsSync(dir)) {
64
- return [];
65
- }
66
- // Read the sessionId from the file (may not be on first line)
67
- // First line is often file-history-snapshot without sessionId
68
- const mainContent = await readFile(sessionFilePath, 'utf-8');
69
- const lines = mainContent.split('\n').filter(l => l.trim());
70
- let targetSessionId;
71
- for (const line of lines.slice(0, 10)) { // Check first 10 lines
72
- try {
73
- const event = JSON.parse(line);
74
- if (event.sessionId) {
75
- targetSessionId = event.sessionId;
76
- break;
77
- }
78
- }
79
- catch {
80
- continue;
81
- }
82
- }
83
- if (!targetSessionId) {
84
- logger.debug(`[ClaudeMetrics] No sessionId found in ${sessionFilePath}`);
85
- return [];
86
- }
87
- // Find all agent files in the directory
88
- const files = await readdir(dir);
89
- const agentFileCandidates = files
90
- .filter(f => f.startsWith('agent-') && f.endsWith('.jsonl'))
91
- .map(f => join(dir, f));
92
- // Filter agent files by matching sessionId
93
- const matchingAgentFiles = [];
94
- for (const agentFile of agentFileCandidates) {
95
- try {
96
- const content = await readFile(agentFile, 'utf-8');
97
- const firstLine = content.split('\n')[0];
98
- if (firstLine) {
99
- const firstEvent = JSON.parse(firstLine);
100
- if (firstEvent.sessionId === targetSessionId) {
101
- matchingAgentFiles.push(agentFile);
102
- }
103
- }
104
- }
105
- catch {
106
- // Skip files that can't be parsed
107
- continue;
108
- }
109
- }
110
- logger.debug(`[ClaudeMetrics] Found ${matchingAgentFiles.length} agent files for session ${targetSessionId}`);
111
- return matchingAgentFiles;
112
- }
113
- catch (error) {
114
- logger.debug(`[ClaudeMetrics] Failed to find agent files:`, error);
115
- return [];
116
- }
117
- }
118
- /**
119
- * Parse all models from agent files
120
- * Agent files may contain different models used by sub-agents/tools
121
- *
122
- * @param agentFilePaths - Array of agent file paths
123
- * @returns Map of model names to call counts
124
- */
125
- async parseModelsFromAgentFiles(agentFilePaths) {
126
- const modelCalls = new Map();
127
- for (const filePath of agentFilePaths) {
128
- try {
129
- const content = await readFile(filePath, 'utf-8');
130
- const jsonObjects = parseMultiLineJSON(content);
131
- for (const obj of jsonObjects) {
132
- if (obj.message?.model) {
133
- const model = obj.message.model;
134
- modelCalls.set(model, (modelCalls.get(model) || 0) + 1);
135
- }
136
- }
137
- }
138
- catch (error) {
139
- logger.debug(`[ClaudeMetrics] Failed to parse agent file ${filePath}:`, error);
140
- }
141
- }
142
- return modelCalls;
143
- }
144
- /**
145
- * Extract session ID from Claude file path
146
- * Examples:
147
- * ~/.claude/projects/abc123/session-def-456.jsonl → session-def-456
148
- * ~/.claude/projects/abc123/agent-abc123de.jsonl → agent-abc123de
149
- */
150
- extractSessionId(path) {
151
- const match = path.match(/([a-z0-9-]+)\.jsonl$/);
152
- return match?.[1] || '';
153
- }
154
- /**
155
- * Parse Claude session file (multi-line JSON objects) and extract metrics
156
- * Each object contains a conversation turn with message data
157
- */
158
- async parseSessionFile(path) {
159
- try {
160
- const content = await readFile(path, 'utf-8');
161
- const jsonObjects = parseMultiLineJSON(content);
162
- if (jsonObjects.length === 0) {
163
- throw new Error('Empty session file');
164
- }
165
- // Parse first object to get session metadata
166
- const firstObject = jsonObjects[0];
167
- const sessionId = firstObject.sessionId || '';
168
- const workingDirectory = firstObject.cwd || '';
169
- const gitBranch = firstObject.gitBranch;
170
- // Aggregate metrics from all objects
171
- let inputTokens = 0;
172
- let outputTokens = 0;
173
- let cacheCreationTokens = 0;
174
- let cacheReadTokens = 0;
175
- // Track all models (not just first)
176
- const modelCalls = new Map();
177
- // Tool tracking maps
178
- const toolCalls = [];
179
- const toolUseMap = new Map();
180
- for (const turn of jsonObjects) {
181
- // Track all models with call counts
182
- if (turn.message?.model) {
183
- const model = turn.message.model;
184
- modelCalls.set(model, (modelCalls.get(model) || 0) + 1);
185
- }
186
- // Aggregate token usage
187
- if (turn.message?.usage) {
188
- const usage = turn.message.usage;
189
- inputTokens += usage.input_tokens || 0;
190
- outputTokens += usage.output_tokens || 0;
191
- cacheCreationTokens += usage.cache_creation_input_tokens || 0;
192
- cacheReadTokens += usage.cache_read_input_tokens || 0;
193
- }
194
- // Extract tool use events (from assistant messages)
195
- if (turn.message?.role === 'assistant' && Array.isArray(turn.message.content)) {
196
- for (const block of turn.message.content) {
197
- if (block.type === 'tool_use') {
198
- // Store tool_use for later correlation
199
- toolUseMap.set(block.id, {
200
- name: block.name,
201
- timestamp: turn.timestamp || Date.now(),
202
- input: block.input
203
- });
204
- }
205
- }
206
- }
207
- // Extract tool result events (from user messages)
208
- if (turn.message?.role === 'user' && Array.isArray(turn.message.content)) {
209
- for (const block of turn.message.content) {
210
- if (block.type === 'tool_result') {
211
- const toolUse = toolUseMap.get(block.tool_use_id);
212
- if (toolUse) {
213
- const toolCall = {
214
- id: block.tool_use_id,
215
- name: toolUse.name, // Use raw tool name
216
- timestamp: toolUse.timestamp,
217
- status: block.is_error ? 'error' : 'success',
218
- input: toolUse.input,
219
- error: block.is_error ? (typeof block.content === 'string' ? block.content : JSON.stringify(block.content)) : undefined
220
- };
221
- // Extract file operation details
222
- const fileOp = this.extractFileOperation(toolUse.name, toolUse.input);
223
- if (fileOp) {
224
- toolCall.fileOperation = fileOp;
225
- }
226
- toolCalls.push(toolCall);
227
- }
228
- }
229
- }
230
- }
231
- }
232
- // Parse agent files to get models from sub-agents/tools
233
- const agentFiles = await this.findAgentFiles(path);
234
- const agentModels = await this.parseModelsFromAgentFiles(agentFiles);
235
- // Merge agent models with session models
236
- for (const [model, count] of agentModels) {
237
- modelCalls.set(model, (modelCalls.get(model) || 0) + count);
238
- }
239
- // Build aggregated tool usage summary
240
- const toolUsageSummary = this.buildToolUsageSummary(toolCalls);
241
- // Get all models (raw, unnormalized)
242
- const allModels = Array.from(modelCalls.keys());
243
- const snapshot = {
244
- sessionId,
245
- timestamp: Date.now(),
246
- tokens: {
247
- input: inputTokens,
248
- output: outputTokens,
249
- cacheCreation: cacheCreationTokens > 0 ? cacheCreationTokens : undefined,
250
- cacheRead: cacheReadTokens > 0 ? cacheReadTokens : undefined
251
- },
252
- toolCalls,
253
- toolUsageSummary,
254
- turnCount: jsonObjects.length,
255
- model: allModels.length > 0 ? allModels[0] : undefined, // Primary model for backward compat
256
- metadata: {
257
- workingDirectory,
258
- gitBranch,
259
- totalInputTokens: inputTokens + cacheCreationTokens + cacheReadTokens,
260
- models: allModels, // All raw model names (unnormalized)
261
- modelCalls: Object.fromEntries(modelCalls) // Map of model -> call count
262
- }
263
- };
264
- logger.debug(`[ClaudeMetrics] Parsed session ${sessionId}: ${inputTokens} input, ${outputTokens} output, ` +
265
- `${cacheReadTokens} cache read, ${toolCalls.length} tool calls, ${allModels.length} models`);
266
- return snapshot;
267
- }
268
- catch (error) {
269
- logger.error(`[ClaudeMetrics] Failed to parse session file: ${path}`, error);
270
- throw error;
271
- }
272
- }
273
- /**
274
- * Extract file operation details from tool input and result
275
- * Uses raw tool names (provider-specific, e.g., "Write", "Edit", "Read")
276
- *
277
- * @param toolName - Tool name (Read, Write, Edit, etc.)
278
- * @param input - Tool input parameters
279
- * @param toolUseResult - Tool execution result with structured data (optional)
280
- */
281
- extractFileOperation(toolName, input, toolUseResult) {
282
- // Map raw tool names to operation types
283
- const typeMap = {
284
- 'Read': 'read',
285
- 'Write': 'write',
286
- 'Edit': 'edit',
287
- // Note: Bash excluded - too varied to categorize reliably
288
- 'Grep': 'grep',
289
- 'Glob': 'glob'
290
- };
291
- const type = typeMap[toolName];
292
- if (!type)
293
- return undefined;
294
- const fileOp = { type };
295
- // Extract file path from toolUseResult (most accurate) or input
296
- const filePath = toolUseResult?.filePath || toolUseResult?.file?.filePath || input?.file_path || input?.path;
297
- if (filePath) {
298
- fileOp.path = filePath;
299
- fileOp.format = this.extractFormat(filePath);
300
- fileOp.language = this.detectLanguage(filePath);
301
- }
302
- else if (input?.pattern) {
303
- // For Grep/Glob operations
304
- fileOp.pattern = input.pattern;
305
- }
306
- // Extract line changes from toolUseResult (most accurate source)
307
- if (toolName === 'Write') {
308
- // Write tool: calculate from toolUseResult.content or toolUseResult.file or input.content
309
- const content = toolUseResult?.content || toolUseResult?.file?.content || input?.content;
310
- if (content) {
311
- const lines = content.split('\n');
312
- fileOp.linesAdded = lines.length;
313
- }
314
- else if (toolUseResult?.file?.numLines) {
315
- fileOp.linesAdded = toolUseResult.file.numLines;
316
- }
317
- else if (toolUseResult?.file?.totalLines) {
318
- fileOp.linesAdded = toolUseResult.file.totalLines;
319
- }
320
- }
321
- else if (toolName === 'Edit' && toolUseResult?.structuredPatch) {
322
- // Edit tool: use structured patch to get accurate line counts
323
- let added = 0;
324
- let removed = 0;
325
- for (const patch of toolUseResult.structuredPatch) {
326
- // Parse patch.lines array: "+line" = added, "-line" = removed, " line" = unchanged
327
- for (const line of patch.lines || []) {
328
- if (line.startsWith('+')) {
329
- added++;
330
- }
331
- else if (line.startsWith('-')) {
332
- removed++;
333
- }
334
- // Lines starting with space are unchanged (context)
335
- }
336
- }
337
- if (added > 0)
338
- fileOp.linesAdded = added;
339
- if (removed > 0)
340
- fileOp.linesRemoved = removed;
341
- // If no adds/removes but edit happened, count as modified
342
- if (added === 0 && removed === 0 && toolUseResult.structuredPatch.length > 0) {
343
- fileOp.linesModified = toolUseResult.structuredPatch[0].oldLines || 0;
344
- }
345
- }
346
- else if (toolName === 'Read' && toolUseResult?.file) {
347
- // Read tool: no line changes, but we have file info
348
- // numLines already captured above
349
- }
350
- return fileOp;
351
- }
352
- /**
353
- * Claude uses hash-based watermark (full file rewrite)
354
- */
355
- getWatermarkStrategy() {
356
- return 'hash';
357
- }
358
- /**
359
- * Claude initialization delay: 500ms
360
- */
361
- getInitDelay() {
362
- return 500;
363
- }
364
- /**
365
- * Get user prompts for a specific session
366
- * Claude stores user prompts in history file (path from metadata)
367
- *
368
- * @param sessionId - Claude session ID
369
- * @param fromTimestamp - Start timestamp (Unix ms) - optional
370
- * @param toTimestamp - End timestamp (Unix ms) - optional
371
- * @returns Array of user prompts
372
- */
373
- async getUserPrompts(sessionId, fromTimestamp, toTimestamp) {
374
- try {
375
- // Get user prompts file path from metadata
376
- if (!this.metadata?.dataPaths?.home || !this.metadata?.dataPaths?.user_prompts) {
377
- logger.debug(`[ClaudeMetrics] No user prompts path configured in metadata`);
378
- return [];
379
- }
380
- const historyPath = this.getUserPromptsPath();
381
- const parser = new HistoryParser(historyPath);
382
- // Get prompts for this session within time range
383
- const prompts = await parser.getPromptsInRange(sessionId, fromTimestamp, toTimestamp);
384
- logger.debug(`[ClaudeMetrics] Found ${prompts.length} user prompts for session ${sessionId}`);
385
- return prompts;
386
- }
387
- catch (error) {
388
- logger.error(`[ClaudeMetrics] Failed to get user prompts for session ${sessionId}:`, error);
389
- return [];
390
- }
391
- }
392
- /**
393
- * Parse session file and extract incremental delta records
394
- * Returns array of delta records for turns with token usage
395
- *
396
- * Automatically discovers and parses ALL agent files for the session
397
- * to capture sub-agents/sidechains that share the same Claude sessionId
398
- *
399
- * @param path - Path to agent session file
400
- * @param processedRecordIds - Set of record IDs already written to metrics
401
- * @param attachedUserPromptTexts - Set of user prompt texts already attached (persisted from sync state)
402
- */
403
- async parseIncrementalMetrics(path, processedRecordIds = new Set(), attachedUserPromptTexts = new Set()) {
404
- try {
405
- // Find ALL agent files for this session (including sidechains)
406
- const agentFiles = await this.findAgentFiles(path);
407
- // Add the main file to the list if not already included
408
- if (!agentFiles.includes(path)) {
409
- agentFiles.unshift(path);
410
- }
411
- logger.debug(`[ClaudeMetrics] Analyzing ${agentFiles.length} session file${agentFiles.length !== 1 ? 's' : ''} (including sidechains)`);
412
- // Track initial size to determine newly attached prompts
413
- const initialAttachedCount = attachedUserPromptTexts.size;
414
- // Parse all agent files and merge deltas
415
- const allDeltas = [];
416
- let maxLastLine = 0;
417
- for (const agentFile of agentFiles) {
418
- const { deltas, lastLine } = await this.parseAgentFileDeltas(agentFile, processedRecordIds, attachedUserPromptTexts);
419
- if (deltas.length > 0) {
420
- logger.debug(`[ClaudeMetrics] Found ${deltas.length} new interaction${deltas.length !== 1 ? 's' : ''} in ${agentFile.split('/').pop()}`);
421
- }
422
- allDeltas.push(...deltas);
423
- maxLastLine = Math.max(maxLastLine, lastLine);
424
- }
425
- // Calculate newly attached prompts (after processing - before processing)
426
- const newlyAttachedPrompts = Array.from(attachedUserPromptTexts).slice(initialAttachedCount);
427
- return {
428
- deltas: allDeltas,
429
- lastLine: maxLastLine,
430
- newlyAttachedPrompts
431
- };
432
- }
433
- catch (error) {
434
- logger.error(`[ClaudeMetrics] Failed to parse incremental metrics: ${path}`, error);
435
- throw error;
436
- }
437
- }
438
- /**
439
- * Parse a single agent file for deltas
440
- * Extracted from parseIncrementalMetrics for reuse across multiple files
441
- *
442
- * @param path - Path to agent file
443
- * @param processedRecordIds - Set of record IDs already processed
444
- * @param attachedUserPrompts - Set of user prompt display texts that have been attached (shared across files)
445
- */
446
- async parseAgentFileDeltas(path, processedRecordIds, attachedUserPrompts = new Set()) {
447
- try {
448
- const content = await readFile(path, 'utf-8');
449
- const jsonObjects = parseMultiLineJSON(content);
450
- if (jsonObjects.length === 0) {
451
- return { deltas: [], lastLine: 0 };
452
- }
453
- // FIRST PASS: Build tool_result map from ALL jsonObjects
454
- // This ensures we can match tool_results that come after tool_use in the file
455
- const toolResultMap = new Map();
456
- for (const record of jsonObjects) {
457
- if (record.message?.role === 'user' && Array.isArray(record.message.content)) {
458
- for (const block of record.message.content) {
459
- if (block.type === 'tool_result') {
460
- toolResultMap.set(block.tool_use_id, {
461
- timestamp: record.timestamp,
462
- isError: block.is_error || false,
463
- errorMessage: block.is_error ? (typeof block.content === 'string' ? block.content : JSON.stringify(block.content)) : undefined,
464
- durationMs: block.durationMs,
465
- toolUseResult: record.toolUseResult // Contains structured patch and file details
466
- });
467
- }
468
- }
469
- }
470
- }
471
- // Extract session ID from first record that has one
472
- let extractedSessionId = '';
473
- for (const record of jsonObjects) {
474
- if (record.sessionId) {
475
- extractedSessionId = record.sessionId;
476
- break;
477
- }
478
- }
479
- // ZERO PASS: Get user prompts from history.jsonl and build UUID map
480
- // Map user prompt UUIDs to prompts for direct correlation
481
- const userPromptsByUuid = new Map();
482
- try {
483
- const userPrompts = await this.getUserPrompts(extractedSessionId);
484
- logger.debug(`[ClaudeMetrics] Found ${userPrompts.length} user prompts in history.jsonl for session ${extractedSessionId}`);
485
- // Build a map of record UUIDs to user prompts
486
- // We'll correlate by finding user messages that match prompts
487
- for (const record of jsonObjects) {
488
- if (record.type === 'user' &&
489
- record.message?.role === 'user' &&
490
- typeof record.message.content === 'string') {
491
- // This is an initial user message (not a tool result)
492
- const messageContent = record.message.content;
493
- const recordTime = typeof record.timestamp === 'string'
494
- ? new Date(record.timestamp).getTime()
495
- : record.timestamp;
496
- // Find matching prompt from history.jsonl by content or timestamp
497
- const matchingPrompt = userPrompts.find(p => {
498
- // Match by content (most reliable)
499
- if (p.display === messageContent) {
500
- return true;
501
- }
502
- // Fallback: match by timestamp (±10 seconds window for initial prompts)
503
- const timeDiff = Math.abs(p.timestamp - recordTime);
504
- return timeDiff <= 10000; // 10 second window
505
- });
506
- if (matchingPrompt && record.uuid) {
507
- userPromptsByUuid.set(record.uuid, matchingPrompt);
508
- }
509
- }
510
- }
511
- logger.debug(`[ClaudeMetrics] Matched ${userPromptsByUuid.size} prompts to message UUIDs`);
512
- }
513
- catch (error) {
514
- logger.debug(`[ClaudeMetrics] Could not load user prompts (non-critical):`, error);
515
- // Continue without user prompts - non-critical feature
516
- }
517
- // SECOND PASS: Create deltas for NEW records with usage (assistant messages)
518
- // Skip records that have already been processed
519
- const deltas = [];
520
- const sessionModels = []; // Track all unique models
521
- let lastUserPrompt;
522
- for (const record of jsonObjects) {
523
- // Track user prompts as we iterate (BEFORE processing/skipping)
524
- // Only update lastUserPrompt for INITIAL user messages (with string content), not tool_result messages
525
- if (record.type === 'user' &&
526
- record.uuid &&
527
- userPromptsByUuid.has(record.uuid) &&
528
- record.message?.role === 'user' &&
529
- typeof record.message.content === 'string') {
530
- lastUserPrompt = userPromptsByUuid.get(record.uuid);
531
- }
532
- // Skip records already processed
533
- if (processedRecordIds.has(record.uuid)) {
534
- continue;
535
- }
536
- // Collect all unique models from all records (not just first)
537
- if (record.message?.model && !sessionModels.includes(record.message.model)) {
538
- sessionModels.push(record.message.model);
539
- }
540
- // Create delta for records with token usage
541
- if (record.message?.usage && record.message?.role === 'assistant') {
542
- // Check if this record has tool_use blocks waiting for tool_results
543
- let hasUnresolvedTools = false;
544
- if (Array.isArray(record.message.content)) {
545
- for (const block of record.message.content) {
546
- if (block.type === 'tool_use') {
547
- if (!toolResultMap.has(block.id)) {
548
- hasUnresolvedTools = true;
549
- break;
550
- }
551
- }
552
- }
553
- }
554
- // Skip records with tool_use blocks that haven't received tool_results yet
555
- if (hasUnresolvedTools) {
556
- logger.debug(`[ClaudeMetrics] Skipping record ${record.uuid} - waiting for tool results`);
557
- continue;
558
- }
559
- const usage = record.message.usage;
560
- const inputTokens = usage.input_tokens || 0;
561
- const outputTokens = usage.output_tokens || 0;
562
- const cacheCreationTokens = usage.cache_creation_input_tokens || 0;
563
- const cacheReadTokens = usage.cache_read_input_tokens || 0;
564
- // Extract tool_use IDs from this record
565
- const tools = {};
566
- const toolStatus = {};
567
- const fileOperations = [];
568
- let apiErrorMessage;
569
- if (Array.isArray(record.message.content)) {
570
- for (const block of record.message.content) {
571
- if (block.type === 'tool_use') {
572
- // block IS the tool_use with name and input
573
- const toolResult = toolResultMap.get(block.id);
574
- // Only count if we have tool_result (tool was executed)
575
- if (toolResult) {
576
- // Use raw tool name (provider-specific)
577
- const toolName = block.name;
578
- tools[toolName] = (tools[toolName] || 0) + 1;
579
- // Track success/failure
580
- if (!toolStatus[toolName]) {
581
- toolStatus[toolName] = { success: 0, failure: 0 };
582
- }
583
- if (toolResult.isError) {
584
- toolStatus[toolName].failure++;
585
- // Capture first error message
586
- if (!apiErrorMessage && toolResult.errorMessage) {
587
- apiErrorMessage = toolResult.errorMessage;
588
- }
589
- }
590
- else {
591
- toolStatus[toolName].success++;
592
- // Only extract file operations for successful tool calls
593
- const fileOp = this.extractFileOperation(toolName, block.input, toolResult.toolUseResult);
594
- if (fileOp) {
595
- // Add durationMs if available
596
- if (toolResult.durationMs) {
597
- fileOp.durationMs = toolResult.durationMs;
598
- }
599
- fileOperations.push(fileOp);
600
- }
601
- }
602
- }
603
- }
604
- }
605
- }
606
- // Include user prompt ONLY for the first assistant response after a user prompt
607
- // Use shared Set to prevent duplication across ALL agent files
608
- const userPrompts = [];
609
- if (lastUserPrompt && lastUserPrompt.display && !attachedUserPrompts.has(lastUserPrompt.display)) {
610
- userPrompts.push({
611
- count: 1,
612
- text: lastUserPrompt.display
613
- });
614
- // Mark as attached to prevent duplicate counting across multiple assistant turns AND agent files
615
- attachedUserPrompts.add(lastUserPrompt.display);
616
- // Clear lastUserPrompt so it doesn't attach to subsequent assistant turns
617
- lastUserPrompt = undefined;
618
- }
619
- // Get model and gitBranch for this turn
620
- const turnModel = record.message?.model;
621
- const gitBranch = record.gitBranch;
622
- // Create delta record (use message UUID as recordId for backtracking)
623
- const delta = {
624
- recordId: record.uuid, // Use message UUID for backtracking
625
- sessionId: '', // Will be set by caller
626
- agentSessionId: record.sessionId || '',
627
- timestamp: record.timestamp || new Date().toISOString(),
628
- gitBranch,
629
- tokens: {
630
- input: inputTokens,
631
- output: outputTokens,
632
- cacheCreation: cacheCreationTokens > 0 ? cacheCreationTokens : undefined,
633
- cacheRead: cacheReadTokens > 0 ? cacheReadTokens : undefined
634
- },
635
- tools,
636
- toolStatus: Object.keys(toolStatus).length > 0 ? toolStatus : undefined,
637
- fileOperations: fileOperations.length > 0 ? fileOperations : undefined,
638
- userPrompts: userPrompts.length > 0 ? userPrompts : undefined,
639
- apiErrorMessage,
640
- models: turnModel ? [turnModel] : undefined // Store raw model name(s) for this turn
641
- };
642
- deltas.push(delta);
643
- }
644
- }
645
- return {
646
- deltas,
647
- lastLine: jsonObjects.length
648
- };
649
- }
650
- catch (error) {
651
- logger.error(`[ClaudeMetrics] Failed to parse incremental metrics: ${path}`, error);
652
- throw error;
653
- }
654
- }
655
- }
656
- //# sourceMappingURL=claude.metrics.js.map