@codemieai/code 0.11.0 → 0.13.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 (253) hide show
  1. package/README.md +109 -56
  2. package/bin/codemie-copilot.js +224 -0
  3. package/bin/codemie-pi.js +18 -0
  4. package/dist/agents/core/AgentCLI.d.ts.map +1 -1
  5. package/dist/agents/core/AgentCLI.js +16 -10
  6. package/dist/agents/core/AgentCLI.js.map +1 -1
  7. package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
  8. package/dist/agents/core/BaseAgentAdapter.js +43 -19
  9. package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
  10. package/dist/agents/core/agent-aliases.d.ts +17 -0
  11. package/dist/agents/core/agent-aliases.d.ts.map +1 -0
  12. package/dist/agents/core/agent-aliases.js +41 -0
  13. package/dist/agents/core/agent-aliases.js.map +1 -0
  14. package/dist/agents/core/session/BaseSessionAdapter.d.ts +19 -0
  15. package/dist/agents/core/session/BaseSessionAdapter.d.ts.map +1 -1
  16. package/dist/agents/core/session/session-origin-audit.d.ts +13 -0
  17. package/dist/agents/core/session/session-origin-audit.d.ts.map +1 -1
  18. package/dist/agents/core/session/session-origin-audit.js +34 -0
  19. package/dist/agents/core/session/session-origin-audit.js.map +1 -1
  20. package/dist/agents/core/session/stale-session-reconciliation.d.ts +42 -0
  21. package/dist/agents/core/session/stale-session-reconciliation.d.ts.map +1 -0
  22. package/dist/agents/core/session/stale-session-reconciliation.js +141 -0
  23. package/dist/agents/core/session/stale-session-reconciliation.js.map +1 -0
  24. package/dist/agents/core/session/types.d.ts +19 -0
  25. package/dist/agents/core/session/types.d.ts.map +1 -1
  26. package/dist/agents/core/session/types.js +17 -1
  27. package/dist/agents/core/session/types.js.map +1 -1
  28. package/dist/agents/core/types.d.ts +11 -0
  29. package/dist/agents/core/types.d.ts.map +1 -1
  30. package/dist/agents/plugins/codex/codex.reconciliation.d.ts +15 -35
  31. package/dist/agents/plugins/codex/codex.reconciliation.d.ts.map +1 -1
  32. package/dist/agents/plugins/codex/codex.reconciliation.js +8 -139
  33. package/dist/agents/plugins/codex/codex.reconciliation.js.map +1 -1
  34. package/dist/agents/plugins/copilot-cli/copilot-cli-event-types.d.ts +146 -0
  35. package/dist/agents/plugins/copilot-cli/copilot-cli-event-types.d.ts.map +1 -0
  36. package/dist/agents/plugins/copilot-cli/copilot-cli-event-types.js +12 -0
  37. package/dist/agents/plugins/copilot-cli/copilot-cli-event-types.js.map +1 -0
  38. package/dist/agents/plugins/copilot-cli/copilot-cli.constants.d.ts +15 -0
  39. package/dist/agents/plugins/copilot-cli/copilot-cli.constants.d.ts.map +1 -0
  40. package/dist/agents/plugins/copilot-cli/copilot-cli.constants.js +15 -0
  41. package/dist/agents/plugins/copilot-cli/copilot-cli.constants.js.map +1 -0
  42. package/dist/agents/plugins/copilot-cli/copilot-cli.models.d.ts +8 -0
  43. package/dist/agents/plugins/copilot-cli/copilot-cli.models.d.ts.map +1 -0
  44. package/dist/agents/plugins/copilot-cli/copilot-cli.models.js +195 -0
  45. package/dist/agents/plugins/copilot-cli/copilot-cli.models.js.map +1 -0
  46. package/dist/agents/plugins/copilot-cli/copilot-cli.paths.d.ts +11 -0
  47. package/dist/agents/plugins/copilot-cli/copilot-cli.paths.d.ts.map +1 -0
  48. package/dist/agents/plugins/copilot-cli/copilot-cli.paths.js +21 -0
  49. package/dist/agents/plugins/copilot-cli/copilot-cli.paths.js.map +1 -0
  50. package/dist/agents/plugins/copilot-cli/copilot-cli.plugin.d.ts +14 -0
  51. package/dist/agents/plugins/copilot-cli/copilot-cli.plugin.d.ts.map +1 -0
  52. package/dist/agents/plugins/copilot-cli/copilot-cli.plugin.js +263 -0
  53. package/dist/agents/plugins/copilot-cli/copilot-cli.plugin.js.map +1 -0
  54. package/dist/agents/plugins/copilot-cli/copilot-cli.session.d.ts +43 -0
  55. package/dist/agents/plugins/copilot-cli/copilot-cli.session.d.ts.map +1 -0
  56. package/dist/agents/plugins/copilot-cli/copilot-cli.session.js +343 -0
  57. package/dist/agents/plugins/copilot-cli/copilot-cli.session.js.map +1 -0
  58. package/dist/agents/plugins/copilot-cli/copilot-cli.storage-utils.d.ts +10 -0
  59. package/dist/agents/plugins/copilot-cli/copilot-cli.storage-utils.d.ts.map +1 -0
  60. package/dist/agents/plugins/copilot-cli/copilot-cli.storage-utils.js +41 -0
  61. package/dist/agents/plugins/copilot-cli/copilot-cli.storage-utils.js.map +1 -0
  62. package/dist/agents/plugins/copilot-cli/copilot-cli.usage.d.ts +37 -0
  63. package/dist/agents/plugins/copilot-cli/copilot-cli.usage.d.ts.map +1 -0
  64. package/dist/agents/plugins/copilot-cli/copilot-cli.usage.js +96 -0
  65. package/dist/agents/plugins/copilot-cli/copilot-cli.usage.js.map +1 -0
  66. package/dist/agents/plugins/copilot-cli/copilot-cli.workspace.d.ts +17 -0
  67. package/dist/agents/plugins/copilot-cli/copilot-cli.workspace.d.ts.map +1 -0
  68. package/dist/agents/plugins/copilot-cli/copilot-cli.workspace.js +58 -0
  69. package/dist/agents/plugins/copilot-cli/copilot-cli.workspace.js.map +1 -0
  70. package/dist/agents/plugins/copilot-cli/index.d.ts +3 -0
  71. package/dist/agents/plugins/copilot-cli/index.d.ts.map +1 -0
  72. package/dist/agents/plugins/copilot-cli/index.js +3 -0
  73. package/dist/agents/plugins/copilot-cli/index.js.map +1 -0
  74. package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.conversations-processor.d.ts +18 -0
  75. package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.conversations-processor.d.ts.map +1 -0
  76. package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.conversations-processor.js +313 -0
  77. package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.conversations-processor.js.map +1 -0
  78. package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.metrics-processor.d.ts +16 -0
  79. package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.metrics-processor.d.ts.map +1 -0
  80. package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.metrics-processor.js +22 -0
  81. package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.metrics-processor.js.map +1 -0
  82. package/dist/agents/plugins/pi/__tests__/home-redirect.d.ts +12 -0
  83. package/dist/agents/plugins/pi/__tests__/home-redirect.d.ts.map +1 -0
  84. package/dist/agents/plugins/pi/__tests__/home-redirect.js +27 -0
  85. package/dist/agents/plugins/pi/__tests__/home-redirect.js.map +1 -0
  86. package/dist/agents/plugins/pi/extension/README.md +68 -0
  87. package/dist/agents/plugins/pi/extension/index.js +161 -0
  88. package/dist/agents/plugins/pi/extension/package.json +8 -0
  89. package/dist/agents/plugins/pi/index.d.ts +3 -0
  90. package/dist/agents/plugins/pi/index.d.ts.map +1 -0
  91. package/dist/agents/plugins/pi/index.js +3 -0
  92. package/dist/agents/plugins/pi/index.js.map +1 -0
  93. package/dist/agents/plugins/pi/pi.extension.d.ts +60 -0
  94. package/dist/agents/plugins/pi/pi.extension.d.ts.map +1 -0
  95. package/dist/agents/plugins/pi/pi.extension.js +201 -0
  96. package/dist/agents/plugins/pi/pi.extension.js.map +1 -0
  97. package/dist/agents/plugins/pi/pi.incremental-sync.d.ts +63 -0
  98. package/dist/agents/plugins/pi/pi.incremental-sync.d.ts.map +1 -0
  99. package/dist/agents/plugins/pi/pi.incremental-sync.js +266 -0
  100. package/dist/agents/plugins/pi/pi.incremental-sync.js.map +1 -0
  101. package/dist/agents/plugins/pi/pi.models.d.ts +20 -0
  102. package/dist/agents/plugins/pi/pi.models.d.ts.map +1 -0
  103. package/dist/agents/plugins/pi/pi.models.js +201 -0
  104. package/dist/agents/plugins/pi/pi.models.js.map +1 -0
  105. package/dist/agents/plugins/pi/pi.packages.d.ts +11 -0
  106. package/dist/agents/plugins/pi/pi.packages.d.ts.map +1 -0
  107. package/dist/agents/plugins/pi/pi.packages.js +35 -0
  108. package/dist/agents/plugins/pi/pi.packages.js.map +1 -0
  109. package/dist/agents/plugins/pi/pi.paths.d.ts +37 -0
  110. package/dist/agents/plugins/pi/pi.paths.d.ts.map +1 -0
  111. package/dist/agents/plugins/pi/pi.paths.js +146 -0
  112. package/dist/agents/plugins/pi/pi.paths.js.map +1 -0
  113. package/dist/agents/plugins/pi/pi.plugin.d.ts +30 -0
  114. package/dist/agents/plugins/pi/pi.plugin.d.ts.map +1 -0
  115. package/dist/agents/plugins/pi/pi.plugin.js +453 -0
  116. package/dist/agents/plugins/pi/pi.plugin.js.map +1 -0
  117. package/dist/agents/plugins/pi/pi.session.d.ts +114 -0
  118. package/dist/agents/plugins/pi/pi.session.d.ts.map +1 -0
  119. package/dist/agents/plugins/pi/pi.session.js +388 -0
  120. package/dist/agents/plugins/pi/pi.session.js.map +1 -0
  121. package/dist/agents/plugins/pi/pi.setup.d.ts +2 -0
  122. package/dist/agents/plugins/pi/pi.setup.d.ts.map +1 -0
  123. package/dist/agents/plugins/pi/pi.setup.js +33 -0
  124. package/dist/agents/plugins/pi/pi.setup.js.map +1 -0
  125. package/dist/agents/plugins/pi/pi.types.d.ts +143 -0
  126. package/dist/agents/plugins/pi/pi.types.d.ts.map +1 -0
  127. package/dist/agents/plugins/pi/pi.types.js +74 -0
  128. package/dist/agents/plugins/pi/pi.types.js.map +1 -0
  129. package/dist/agents/plugins/pi/session/pi-file-operations.d.ts +17 -0
  130. package/dist/agents/plugins/pi/session/pi-file-operations.d.ts.map +1 -0
  131. package/dist/agents/plugins/pi/session/pi-file-operations.js +98 -0
  132. package/dist/agents/plugins/pi/session/pi-file-operations.js.map +1 -0
  133. package/dist/agents/plugins/pi/session/pi-named-invocations.d.ts +52 -0
  134. package/dist/agents/plugins/pi/session/pi-named-invocations.d.ts.map +1 -0
  135. package/dist/agents/plugins/pi/session/pi-named-invocations.js +189 -0
  136. package/dist/agents/plugins/pi/session/pi-named-invocations.js.map +1 -0
  137. package/dist/agents/plugins/pi/session/pi-user-prompt.d.ts +14 -0
  138. package/dist/agents/plugins/pi/session/pi-user-prompt.d.ts.map +1 -0
  139. package/dist/agents/plugins/pi/session/pi-user-prompt.js +51 -0
  140. package/dist/agents/plugins/pi/session/pi-user-prompt.js.map +1 -0
  141. package/dist/agents/plugins/pi/session/processors/pi.conversations-processor.d.ts +52 -0
  142. package/dist/agents/plugins/pi/session/processors/pi.conversations-processor.d.ts.map +1 -0
  143. package/dist/agents/plugins/pi/session/processors/pi.conversations-processor.js +716 -0
  144. package/dist/agents/plugins/pi/session/processors/pi.conversations-processor.js.map +1 -0
  145. package/dist/agents/plugins/pi/session/processors/pi.metrics-processor.d.ts +104 -0
  146. package/dist/agents/plugins/pi/session/processors/pi.metrics-processor.d.ts.map +1 -0
  147. package/dist/agents/plugins/pi/session/processors/pi.metrics-processor.js +595 -0
  148. package/dist/agents/plugins/pi/session/processors/pi.metrics-processor.js.map +1 -0
  149. package/dist/agents/registry.d.ts +20 -0
  150. package/dist/agents/registry.d.ts.map +1 -1
  151. package/dist/agents/registry.js +29 -2
  152. package/dist/agents/registry.js.map +1 -1
  153. package/dist/cli/commands/analytics/agent-labels.d.ts +3 -0
  154. package/dist/cli/commands/analytics/agent-labels.d.ts.map +1 -0
  155. package/dist/cli/commands/analytics/agent-labels.js +20 -0
  156. package/dist/cli/commands/analytics/agent-labels.js.map +1 -0
  157. package/dist/cli/commands/analytics/cost/cost-enricher.d.ts.map +1 -1
  158. package/dist/cli/commands/analytics/cost/cost-enricher.js +12 -0
  159. package/dist/cli/commands/analytics/cost/cost-enricher.js.map +1 -1
  160. package/dist/cli/commands/analytics/cost/types.d.ts +10 -0
  161. package/dist/cli/commands/analytics/cost/types.d.ts.map +1 -1
  162. package/dist/cli/commands/analytics/cost/usage-readers.d.ts +24 -0
  163. package/dist/cli/commands/analytics/cost/usage-readers.d.ts.map +1 -1
  164. package/dist/cli/commands/analytics/cost/usage-readers.js +253 -54
  165. package/dist/cli/commands/analytics/cost/usage-readers.js.map +1 -1
  166. package/dist/cli/commands/analytics/formatter.d.ts.map +1 -1
  167. package/dist/cli/commands/analytics/formatter.js +10 -2
  168. package/dist/cli/commands/analytics/formatter.js.map +1 -1
  169. package/dist/cli/commands/analytics/index.d.ts.map +1 -1
  170. package/dist/cli/commands/analytics/index.js +22 -0
  171. package/dist/cli/commands/analytics/index.js.map +1 -1
  172. package/dist/cli/commands/analytics/native-loader.d.ts +21 -4
  173. package/dist/cli/commands/analytics/native-loader.d.ts.map +1 -1
  174. package/dist/cli/commands/analytics/native-loader.js +267 -88
  175. package/dist/cli/commands/analytics/native-loader.js.map +1 -1
  176. package/dist/cli/commands/analytics/report/client/app.js +77 -15
  177. package/dist/cli/commands/analytics/report/payload-builder.d.ts.map +1 -1
  178. package/dist/cli/commands/analytics/report/payload-builder.js +32 -2
  179. package/dist/cli/commands/analytics/report/payload-builder.js.map +1 -1
  180. package/dist/cli/commands/analytics/report/types.d.ts +11 -0
  181. package/dist/cli/commands/analytics/report/types.d.ts.map +1 -1
  182. package/dist/cli/commands/hook.d.ts.map +1 -1
  183. package/dist/cli/commands/hook.js +71 -29
  184. package/dist/cli/commands/hook.js.map +1 -1
  185. package/dist/cli/commands/install.d.ts.map +1 -1
  186. package/dist/cli/commands/install.js +9 -7
  187. package/dist/cli/commands/install.js.map +1 -1
  188. package/dist/cli/commands/list.d.ts.map +1 -1
  189. package/dist/cli/commands/list.js +4 -2
  190. package/dist/cli/commands/list.js.map +1 -1
  191. package/dist/cli/commands/setup.d.ts +3 -1
  192. package/dist/cli/commands/setup.d.ts.map +1 -1
  193. package/dist/cli/commands/setup.js +87 -63
  194. package/dist/cli/commands/setup.js.map +1 -1
  195. package/dist/cli/commands/uninstall.d.ts.map +1 -1
  196. package/dist/cli/commands/uninstall.js +6 -4
  197. package/dist/cli/commands/uninstall.js.map +1 -1
  198. package/dist/cli/commands/update.d.ts.map +1 -1
  199. package/dist/cli/commands/update.js +7 -5
  200. package/dist/cli/commands/update.js.map +1 -1
  201. package/dist/cli/first-time.d.ts.map +1 -1
  202. package/dist/cli/first-time.js +10 -9
  203. package/dist/cli/first-time.js.map +1 -1
  204. package/dist/providers/core/auth-validation.d.ts +7 -2
  205. package/dist/providers/core/auth-validation.d.ts.map +1 -1
  206. package/dist/providers/core/auth-validation.js +11 -5
  207. package/dist/providers/core/auth-validation.js.map +1 -1
  208. package/dist/providers/core/types.d.ts +16 -0
  209. package/dist/providers/core/types.d.ts.map +1 -1
  210. package/dist/providers/core/types.js.map +1 -1
  211. package/dist/providers/plugins/sso/proxy/plugins/claude-request-normalizer.plugin.d.ts +8 -3
  212. package/dist/providers/plugins/sso/proxy/plugins/claude-request-normalizer.plugin.d.ts.map +1 -1
  213. package/dist/providers/plugins/sso/proxy/plugins/claude-request-normalizer.plugin.js +46 -11
  214. package/dist/providers/plugins/sso/proxy/plugins/claude-request-normalizer.plugin.js.map +1 -1
  215. package/dist/providers/plugins/sso/proxy/plugins/codex-encrypted-content-sanitizer.plugin.d.ts +23 -13
  216. package/dist/providers/plugins/sso/proxy/plugins/codex-encrypted-content-sanitizer.plugin.d.ts.map +1 -1
  217. package/dist/providers/plugins/sso/proxy/plugins/codex-encrypted-content-sanitizer.plugin.js +75 -18
  218. package/dist/providers/plugins/sso/proxy/plugins/codex-encrypted-content-sanitizer.plugin.js.map +1 -1
  219. package/dist/providers/plugins/sso/proxy/plugins/copilot-encrypted-content-sanitizer.plugin.d.ts +21 -0
  220. package/dist/providers/plugins/sso/proxy/plugins/copilot-encrypted-content-sanitizer.plugin.d.ts.map +1 -0
  221. package/dist/providers/plugins/sso/proxy/plugins/copilot-encrypted-content-sanitizer.plugin.js +133 -0
  222. package/dist/providers/plugins/sso/proxy/plugins/copilot-encrypted-content-sanitizer.plugin.js.map +1 -0
  223. package/dist/providers/plugins/sso/proxy/plugins/header-injection.plugin.js +1 -1
  224. package/dist/providers/plugins/sso/proxy/plugins/header-injection.plugin.js.map +1 -1
  225. package/dist/providers/plugins/sso/proxy/plugins/index.d.ts +2 -1
  226. package/dist/providers/plugins/sso/proxy/plugins/index.d.ts.map +1 -1
  227. package/dist/providers/plugins/sso/proxy/plugins/index.js +4 -2
  228. package/dist/providers/plugins/sso/proxy/plugins/index.js.map +1 -1
  229. package/dist/providers/plugins/sso/proxy/plugins/types.d.ts +11 -0
  230. package/dist/providers/plugins/sso/proxy/plugins/types.d.ts.map +1 -1
  231. package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts +2 -0
  232. package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts.map +1 -1
  233. package/dist/providers/plugins/sso/proxy/sso.proxy.js +37 -1
  234. package/dist/providers/plugins/sso/proxy/sso.proxy.js.map +1 -1
  235. package/dist/providers/plugins/sso/session/SessionSyncer.d.ts.map +1 -1
  236. package/dist/providers/plugins/sso/session/SessionSyncer.js +13 -0
  237. package/dist/providers/plugins/sso/session/SessionSyncer.js.map +1 -1
  238. package/dist/providers/plugins/sso/session/processors/conversations/syncProcessor.js +6 -0
  239. package/dist/providers/plugins/sso/session/processors/conversations/syncProcessor.js.map +1 -1
  240. package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.d.ts +0 -6
  241. package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.d.ts.map +1 -1
  242. package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.js +28 -19
  243. package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.js.map +1 -1
  244. package/dist/providers/plugins/sso/sso.setup-steps.d.ts.map +1 -1
  245. package/dist/providers/plugins/sso/sso.setup-steps.js +39 -22
  246. package/dist/providers/plugins/sso/sso.setup-steps.js.map +1 -1
  247. package/dist/utils/interactive.d.ts +14 -0
  248. package/dist/utils/interactive.d.ts.map +1 -0
  249. package/dist/utils/interactive.js +16 -0
  250. package/dist/utils/interactive.js.map +1 -0
  251. package/package.json +6 -5
  252. package/scripts/copy-plugins.js +6 -0
  253. package/scripts/release.sh +54 -0
@@ -0,0 +1,595 @@
1
+ /**
2
+ * Pi Metrics Processor
3
+ *
4
+ * Translates Pi session JSONL entries into MetricDelta records and writes
5
+ * them to JSONL for eventual sync to the CodeMie API.
6
+ *
7
+ * The processor is re-entrant by design: the incremental-sync timer builds a fresh
8
+ * instance every ~30 s and re-parses each transcript from the top, and the final flush
9
+ * does it once more. Nothing durable may therefore live in an instance field — the
10
+ * session's `{sessionId}_metrics.jsonl` is the record of what has already been reported,
11
+ * and every quantity this processor persists is derived as an increment over it.
12
+ */
13
+ import { readFile } from 'fs/promises';
14
+ import { logger } from '../../../../../utils/logger.js';
15
+ import { extractPiToolCalls, isPiMessageEntry, isPiUserMessage, isPiAssistantMessage, isPiBashExecutionMessage, isPiModelChangeEntry, isPiToolResultMessage, } from '../../pi.types.js';
16
+ import { extractPiFileOperation } from '../pi-file-operations.js';
17
+ import { extractPiNamedInvocations, parseSkillWrapper } from '../pi-named-invocations.js';
18
+ export const PI_METRICS_PROCESSOR_NAME = 'pi-metrics';
19
+ /** Pi's shell-escape tool name, used for `!command` entries that bypass the model. */
20
+ const BASH_TOOL = 'bash';
21
+ function emptyInvocationTotals() {
22
+ return { skillInvocations: {}, agentInvocations: {}, commandInvocations: {} };
23
+ }
24
+ /**
25
+ * Fold ledger counts into transcript counts, keeping the larger count per name.
26
+ *
27
+ * The two sources observe the same events from different vantage points — one
28
+ * `/skill:foo` produces both a ledger record and a `<skill>` wrapper — so summing would
29
+ * double-count. Taking the maximum keeps whichever source saw more without inventing
30
+ * invocations.
31
+ */
32
+ function mergeInvocationCounts(base, extra) {
33
+ if (!extra)
34
+ return;
35
+ for (const [name, count] of Object.entries(extra)) {
36
+ base[name] = Math.max(base[name] ?? 0, count);
37
+ }
38
+ }
39
+ /** Accumulate `extra` into `base`, summing per name. */
40
+ function addInvocationCounts(base, extra) {
41
+ for (const [name, count] of Object.entries(extra)) {
42
+ base[name] = (base[name] ?? 0) + count;
43
+ }
44
+ }
45
+ /**
46
+ * The part of `total` that has not been reported yet.
47
+ *
48
+ * The aggregator sums these maps across deltas, so a delta must carry the *increment*
49
+ * rather than the running total; re-emitting the total on every tick is what multiplied
50
+ * a single `/skill:review` into one count per tick. A name whose persisted count already
51
+ * meets the total contributes nothing, which makes any number of re-parses idempotent.
52
+ */
53
+ function invocationIncrement(total, persisted) {
54
+ const increment = {};
55
+ for (const [name, count] of Object.entries(total)) {
56
+ const remaining = count - (persisted[name] ?? 0);
57
+ if (remaining > 0) {
58
+ increment[name] = remaining;
59
+ }
60
+ }
61
+ return increment;
62
+ }
63
+ /** Whether any of the three maps carries a count worth reporting. */
64
+ function hasInvocations(invocations) {
65
+ return Object.values(invocations).some((counts) => Object.keys(counts).length > 0);
66
+ }
67
+ /**
68
+ * Record id for a delta that exists only to carry invocation counts.
69
+ *
70
+ * Such a delta has no Pi entry to name it after, so it is numbered — and numbered against
71
+ * what the JSONL already holds, so it can never collide with a record already written.
72
+ * Re-parsing the same batch does not produce a second one: the counts it reported are then
73
+ * persisted, which leaves the increment empty and the carrier unneeded.
74
+ */
75
+ function nextInvocationRecordId(sessionId, existingRecordIds) {
76
+ let index = 0;
77
+ while (existingRecordIds.has(`${sessionId}:invocations:${index}`)) {
78
+ index++;
79
+ }
80
+ return `${sessionId}:invocations:${index}`;
81
+ }
82
+ /** Numeric entries of an untrusted JSON value, or undefined when it is not a plain map. */
83
+ function readCountMap(value) {
84
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
85
+ return undefined;
86
+ const counts = {};
87
+ for (const [name, count] of Object.entries(value)) {
88
+ if (typeof count === 'number' && Number.isFinite(count)) {
89
+ counts[name] = count;
90
+ }
91
+ }
92
+ return counts;
93
+ }
94
+ export class PiMetricsProcessor {
95
+ metadata;
96
+ ledgerInvocations;
97
+ name = PI_METRICS_PROCESSOR_NAME;
98
+ priority = 1;
99
+ // Tracks Pi entry ids already seen across all files in this run. /new and /fork
100
+ // copy history into a new transcript; this set prevents double-counting.
101
+ seenEntryIds = new Set();
102
+ // Named invocations observed across the transcripts this instance has parsed, deduped
103
+ // by the entry-id set above. It is a running total, not a report: what actually gets
104
+ // written is this minus whatever the JSONL already carries, so a discarded instance
105
+ // costs nothing but a re-parse.
106
+ runInvocations = emptyInvocationTotals();
107
+ constructor(metadata = undefined, ledgerInvocations = undefined) {
108
+ this.metadata = metadata;
109
+ this.ledgerInvocations = ledgerInvocations;
110
+ }
111
+ shouldProcess(session) {
112
+ return session.messages.length > 0;
113
+ }
114
+ async process(session, context) {
115
+ try {
116
+ const entries = session.messages;
117
+ const persisted = await this.readPersistedMetrics(session.sessionId);
118
+ if (persisted === undefined) {
119
+ return {
120
+ success: true,
121
+ message: 'Skipping metrics processing: could not read existing deltas safely',
122
+ metadata: { recordsProcessed: entries.length, deltasWritten: 0 },
123
+ };
124
+ }
125
+ const existingRecordIds = persisted.recordIds;
126
+ // Bound entry processing to this CodeMie run. On `--continue` / `-r` Pi appends
127
+ // to the same transcript, so entries from earlier runs must not be re-emitted.
128
+ const sessionStartTime = await this.getCodeMieSessionStartTime(session.sessionId, session);
129
+ const gitBranch = context.gitBranch;
130
+ const fallbackModel = process.env.CODEMIE_MODEL;
131
+ const emitUnresolvedToolCalls = context.emitUnresolvedToolCalls ?? true;
132
+ const base = (recordId, timestamp) => ({
133
+ recordId,
134
+ sessionId: session.sessionId,
135
+ agentSessionId: session.metadata?.agentSessionId ??
136
+ context.sessionId ??
137
+ session.sessionId,
138
+ timestamp,
139
+ ...(gitBranch && { gitBranch }),
140
+ });
141
+ // The run's activity window, seeded from what is already on disk so it can only
142
+ // grow. It spans every reportable in-window entry rather than only the entries
143
+ // whose deltas are new — on a re-parse almost nothing is new, and a window built
144
+ // from those alone collapses to the last tick's span.
145
+ let activityStart = persisted.activityStart;
146
+ let activityEnd = persisted.activityEnd;
147
+ const noteActivity = (timestamp) => {
148
+ activityStart = activityStart === undefined ? timestamp : Math.min(activityStart, timestamp);
149
+ activityEnd = activityEnd === undefined ? timestamp : Math.max(activityEnd, timestamp);
150
+ };
151
+ // Track unmatched assistant tool calls in insertion order. When a toolResult
152
+ // arrives, we pair it with the most recent preceding unmatched call for that id.
153
+ const unmatchedToolCalls = [];
154
+ const unmatchedById = new Map();
155
+ const pushUnmatched = (call) => {
156
+ unmatchedToolCalls.push(call);
157
+ const list = unmatchedById.get(call.toolCall.id) ?? [];
158
+ list.push(call);
159
+ unmatchedById.set(call.toolCall.id, list);
160
+ };
161
+ const findAndRemoveUnmatched = (toolCallId) => {
162
+ const list = unmatchedById.get(toolCallId);
163
+ if (!list || list.length === 0)
164
+ return undefined;
165
+ const call = list.pop();
166
+ if (list.length === 0) {
167
+ unmatchedById.delete(toolCallId);
168
+ }
169
+ const index = unmatchedToolCalls.lastIndexOf(call);
170
+ if (index !== -1)
171
+ unmatchedToolCalls.splice(index, 1);
172
+ return call;
173
+ };
174
+ const deltas = [];
175
+ // Entries that passed the dedup and run-window guards, so named invocations are
176
+ // counted for this run only rather than for the whole (possibly resumed) transcript.
177
+ const countedEntries = [];
178
+ let skippedDueToDedup = 0;
179
+ const maybePushDelta = (delta) => {
180
+ if (existingRecordIds.has(delta.recordId)) {
181
+ skippedDueToDedup++;
182
+ return;
183
+ }
184
+ deltas.push(delta);
185
+ };
186
+ for (const entry of entries) {
187
+ if (!entry.id || this.seenEntryIds.has(entry.id)) {
188
+ continue;
189
+ }
190
+ this.seenEntryIds.add(entry.id);
191
+ // A mid-session `/model` switch, so the aggregator's most-used model reflects the
192
+ // model actually in use rather than only the one the run started with.
193
+ if (isPiModelChangeEntry(entry)) {
194
+ const ts = this.entryIsoTimestamp(entry.timestamp, sessionStartTime);
195
+ if (ts < sessionStartTime) {
196
+ continue;
197
+ }
198
+ noteActivity(ts);
199
+ maybePushDelta({
200
+ ...base(`${entry.id}:model`, ts),
201
+ models: [entry.modelId],
202
+ });
203
+ continue;
204
+ }
205
+ if (!isPiMessageEntry(entry)) {
206
+ continue;
207
+ }
208
+ const msg = entry.message;
209
+ if (isPiUserMessage(msg)) {
210
+ const ts = this.entryTimestamp(msg, sessionStartTime);
211
+ if (ts < sessionStartTime) {
212
+ continue;
213
+ }
214
+ noteActivity(ts);
215
+ countedEntries.push(entry);
216
+ const text = this.extractUserText(msg);
217
+ if (!text) {
218
+ continue;
219
+ }
220
+ const recordId = `${entry.id}:prompt`;
221
+ maybePushDelta({
222
+ ...base(recordId, ts),
223
+ userPrompts: [{ count: 1, text }],
224
+ ...(fallbackModel && { models: [fallbackModel] }),
225
+ });
226
+ continue;
227
+ }
228
+ if (isPiAssistantMessage(msg)) {
229
+ const assistantTimestamp = this.entryTimestamp(msg, sessionStartTime);
230
+ if (assistantTimestamp < sessionStartTime) {
231
+ continue;
232
+ }
233
+ noteActivity(assistantTimestamp);
234
+ countedEntries.push(entry);
235
+ const assistantModel = msg.model || fallbackModel;
236
+ const toolCalls = extractPiToolCalls(msg);
237
+ for (const toolCall of toolCalls) {
238
+ pushUnmatched({
239
+ entryId: entry.id,
240
+ toolCall,
241
+ assistantTimestamp,
242
+ assistantModel,
243
+ });
244
+ }
245
+ if (msg.errorMessage) {
246
+ const recordId = `${entry.id}:error`;
247
+ maybePushDelta({
248
+ ...base(recordId, assistantTimestamp),
249
+ apiErrorMessage: msg.errorMessage,
250
+ ...(assistantModel && { models: [assistantModel] }),
251
+ });
252
+ }
253
+ continue;
254
+ }
255
+ if (isPiToolResultMessage(msg)) {
256
+ const ts = this.entryTimestamp(msg, sessionStartTime);
257
+ if (ts < sessionStartTime) {
258
+ continue;
259
+ }
260
+ noteActivity(ts);
261
+ const matched = findAndRemoveUnmatched(msg.toolCallId);
262
+ if (!matched) {
263
+ continue;
264
+ }
265
+ const { entryId, toolCall, assistantTimestamp, assistantModel } = matched;
266
+ const recordId = `${entryId}:${toolCall.id}`;
267
+ const toolName = toolCall.name;
268
+ const toolNameLower = toolName.toLowerCase();
269
+ const isFailure = msg.isError === true;
270
+ const excludedFromErrors = this.metadata?.metricsConfig?.excludeErrorsFromTools?.map((n) => n.toLowerCase()).includes(toolNameLower) ??
271
+ false;
272
+ let fileOps = [];
273
+ let apiErrorMessage;
274
+ if (isFailure && !excludedFromErrors) {
275
+ apiErrorMessage = this.extractToolResultErrorText(msg);
276
+ }
277
+ else if (isFailure && excludedFromErrors) {
278
+ // Keep had_errors/error_tools reachable without uploading raw output.
279
+ apiErrorMessage = `Tool failed: ${toolName}`;
280
+ }
281
+ else if (!isFailure) {
282
+ fileOps = this.extractFileOperations(toolCall, msg).filter((op) => op !== undefined);
283
+ }
284
+ const delta = {
285
+ ...base(recordId, assistantTimestamp),
286
+ tools: { [toolName]: 1 },
287
+ toolStatus: {
288
+ [toolName]: {
289
+ success: isFailure ? 0 : 1,
290
+ failure: isFailure ? 1 : 0,
291
+ },
292
+ },
293
+ ...(fileOps.length > 0 && { fileOperations: fileOps }),
294
+ ...(assistantModel && { models: [assistantModel] }),
295
+ ...(apiErrorMessage && { apiErrorMessage }),
296
+ };
297
+ maybePushDelta(delta);
298
+ continue;
299
+ }
300
+ // A `!command` shell escape: the user ran it directly, so there is no tool
301
+ // call/result pair and no model involved — hence no `models` on this delta.
302
+ if (isPiBashExecutionMessage(msg)) {
303
+ const ts = this.entryTimestamp(msg, sessionStartTime);
304
+ if (ts < sessionStartTime) {
305
+ continue;
306
+ }
307
+ // `!!` withholds the output from the model precisely because it is the user's
308
+ // private shell session. Report nothing about it, not even that it ran.
309
+ if (msg.excludeFromContext === true) {
310
+ continue;
311
+ }
312
+ noteActivity(ts);
313
+ // A cancelled command has no exit code, which counts as a failure.
314
+ const succeeded = msg.exitCode === 0;
315
+ maybePushDelta({
316
+ ...base(`${entry.id}:bash`, ts),
317
+ tools: { [BASH_TOOL]: 1 },
318
+ toolStatus: { [BASH_TOOL]: { success: succeeded ? 1 : 0, failure: succeeded ? 0 : 1 } },
319
+ // The command's own output is never uploaded — `bash` is in
320
+ // excludeErrorsFromTools — so failures carry the same sanitized marker the
321
+ // tool-result path produces.
322
+ ...(!succeeded && { apiErrorMessage: `Tool failed: ${BASH_TOOL}` }),
323
+ });
324
+ continue;
325
+ }
326
+ }
327
+ // Tool calls that never received a result are emitted without status, per spec §7.3 —
328
+ // but only when this call is the run's last word on them. See PiMetricsProcessingContext.
329
+ if (emitUnresolvedToolCalls) {
330
+ for (const unmatched of unmatchedToolCalls) {
331
+ const recordId = `${unmatched.entryId}:${unmatched.toolCall.id}`;
332
+ const toolName = unmatched.toolCall.name;
333
+ maybePushDelta({
334
+ ...base(recordId, unmatched.assistantTimestamp),
335
+ tools: { [toolName]: 1 },
336
+ ...(unmatched.assistantModel && { models: [unmatched.assistantModel] }),
337
+ });
338
+ }
339
+ }
340
+ // Both of these run before the "nothing new" exit. The duration must, because on the
341
+ // final flush every delta is already on disk and an early return would leave whatever
342
+ // the last tick computed. The invocation totals must, because they accumulate across
343
+ // this instance's transcripts and every batch has to settle its own share of them.
344
+ await this.saveActiveDurationMs(session.sessionId, activityStart, activityEnd);
345
+ const invocations = this.pendingInvocations(countedEntries, persisted.invocations);
346
+ // A batch can owe counts while producing no delta to hang them on: a bare
347
+ // `/skill:review` leaves no prompt text once the wrapper is stripped, and a plain
348
+ // assistant reply emits nothing either. Deferring them to the next batch works
349
+ // mid-run but loses them at the final flush, which has no next batch — so the batch
350
+ // that owes them writes a record of its own.
351
+ if (deltas.length === 0 && hasInvocations(invocations)) {
352
+ deltas.push(base(nextInvocationRecordId(session.sessionId, existingRecordIds),
353
+ // The window's own end, so a record that reports no activity cannot widen the
354
+ // activity span it is later read back into.
355
+ activityEnd ?? Date.now()));
356
+ }
357
+ if (deltas.length === 0) {
358
+ return {
359
+ success: true,
360
+ message: `No new deltas (${skippedDueToDedup} already processed)`,
361
+ metadata: { recordsProcessed: entries.length, deltasWritten: 0, deltasSkipped: skippedDueToDedup },
362
+ };
363
+ }
364
+ attachInvocations(deltas, invocations);
365
+ const { MetricsWriter } = await import('../../../../../providers/plugins/sso/session/processors/metrics/MetricsWriter.js');
366
+ const writer = new MetricsWriter(session.sessionId);
367
+ for (const delta of deltas) {
368
+ await writer.appendDelta(delta);
369
+ }
370
+ return {
371
+ success: true,
372
+ message: `Generated ${deltas.length} deltas`,
373
+ metadata: { recordsProcessed: entries.length, deltasWritten: deltas.length, deltasSkipped: skippedDueToDedup },
374
+ };
375
+ }
376
+ catch (error) {
377
+ const msg = error instanceof Error ? error.message : String(error);
378
+ logger.error(`[pi-metrics] Processing failed:`, error);
379
+ return {
380
+ success: false,
381
+ message: `Metrics processing failed: ${msg}`,
382
+ metadata: { failureReason: 'PROCESSING_ERROR' },
383
+ };
384
+ }
385
+ }
386
+ /**
387
+ * The named invocations this batch still owes the aggregator.
388
+ *
389
+ * Folds the batch's entries into this instance's running totals, tops them up with the
390
+ * ledger's view of the same run, and returns only what the JSONL does not already
391
+ * account for. Called on every batch — including ones with no delta of their own, which
392
+ * write a carrier record rather than hand the debt to a batch that may never come.
393
+ */
394
+ pendingInvocations(countedEntries, persisted) {
395
+ const named = extractPiNamedInvocations(countedEntries);
396
+ addInvocationCounts(this.runInvocations.skillInvocations, named.skillInvocations);
397
+ addInvocationCounts(this.runInvocations.agentInvocations, named.agentInvocations);
398
+ addInvocationCounts(this.runInvocations.commandInvocations, named.commandInvocations);
399
+ const skillTotal = { ...this.runInvocations.skillInvocations };
400
+ const commandTotal = { ...this.runInvocations.commandInvocations };
401
+ mergeInvocationCounts(skillTotal, this.ledgerInvocations?.skillCommandInvocations);
402
+ mergeInvocationCounts(commandTotal, this.ledgerInvocations?.commandInvocations);
403
+ return {
404
+ skillInvocations: invocationIncrement(skillTotal, persisted.skillInvocations),
405
+ agentInvocations: invocationIncrement(this.runInvocations.agentInvocations, persisted.agentInvocations),
406
+ commandInvocations: invocationIncrement(commandTotal, persisted.commandInvocations),
407
+ };
408
+ }
409
+ async getCodeMieSessionStartTime(sessionId, session) {
410
+ try {
411
+ const { SessionStore } = await import('../../../../core/session/SessionStore.js');
412
+ const sessionStore = new SessionStore();
413
+ const metadata = await sessionStore.loadSession(sessionId);
414
+ if (metadata?.startTime) {
415
+ return metadata.startTime;
416
+ }
417
+ }
418
+ catch (error) {
419
+ logger.warn('[pi-metrics] Could not load CodeMie session start time, using permissive fallback:', error);
420
+ }
421
+ const createdAt = session.metadata?.createdAt;
422
+ if (createdAt) {
423
+ const parsed = Date.parse(createdAt);
424
+ if (!Number.isNaN(parsed))
425
+ return parsed;
426
+ }
427
+ logger.warn('[pi-metrics] No authoritative start time available, using permissive fallback');
428
+ return 0;
429
+ }
430
+ entryTimestamp(msg, fallback) {
431
+ return typeof msg.timestamp === 'number' && !Number.isNaN(msg.timestamp) ? msg.timestamp : fallback;
432
+ }
433
+ /** Envelope-level entries timestamp with an ISO string, unlike the messages they wrap. */
434
+ entryIsoTimestamp(timestamp, fallback) {
435
+ const parsed = timestamp ? Date.parse(timestamp) : NaN;
436
+ return Number.isNaN(parsed) ? fallback : parsed;
437
+ }
438
+ /**
439
+ * The user's own words, with Pi's `/skill:<name>` wrapper removed. Pi prepends the
440
+ * literal `<skill …>…</skill>` block to the text part that carries the real prompt;
441
+ * `parseSkillWrapper` owns that shape, and the extractor keeps the name it strips.
442
+ */
443
+ extractUserText(msg) {
444
+ if (typeof msg.content === 'string') {
445
+ const text = parseSkillWrapper(msg.content).rest.trim();
446
+ return text || undefined;
447
+ }
448
+ if (!Array.isArray(msg.content))
449
+ return undefined;
450
+ const texts = [];
451
+ for (const part of msg.content) {
452
+ if (typeof part !== 'object' || part === null)
453
+ continue;
454
+ const typed = part;
455
+ if (typed.type !== 'text' || typeof typed.text !== 'string')
456
+ continue;
457
+ const text = parseSkillWrapper(typed.text).rest.trim();
458
+ if (text) {
459
+ texts.push(text);
460
+ }
461
+ }
462
+ return texts.length > 0 ? texts.join('\n') : undefined;
463
+ }
464
+ extractToolResultErrorText(result) {
465
+ const { content } = result;
466
+ if (typeof content === 'string') {
467
+ const text = content.trim();
468
+ return text.length > 0 ? text : undefined;
469
+ }
470
+ if (!Array.isArray(content))
471
+ return undefined;
472
+ const texts = [];
473
+ for (const part of content) {
474
+ if (typeof part !== 'object' || part === null)
475
+ continue;
476
+ const typed = part;
477
+ if (typed.type !== 'text' || typeof typed.text !== 'string')
478
+ continue;
479
+ const text = typed.text.trim();
480
+ if (text)
481
+ texts.push(text);
482
+ }
483
+ const joined = texts.join('\n').trim();
484
+ return joined.length > 0 ? joined : undefined;
485
+ }
486
+ /**
487
+ * Persist the run's activity span.
488
+ *
489
+ * For Pi this is the only writer of the field: `SessionStore.accumulateActiveDuration`
490
+ * keys off `UserPromptSubmit`, which Pi never fires, so it always contributes 0. The
491
+ * bounds arrive already merged with the JSONL's, which makes the value monotonic — a
492
+ * later tick can only widen the window it re-derives.
493
+ *
494
+ * Deliberately a different quantity than Claude's `activeDurationMs`: this is wall clock
495
+ * from the first in-window entry to the last, idle time included, because Pi exposes no
496
+ * event from which idle could be subtracted. Do not "align" the two by narrowing this
497
+ * one — for a Pi session the alternative is not a tighter number, it is zero.
498
+ */
499
+ async saveActiveDurationMs(sessionId, activityStart, activityEnd) {
500
+ if (activityStart === undefined || activityEnd === undefined)
501
+ return;
502
+ const activeDurationMs = activityEnd - activityStart;
503
+ try {
504
+ const { SessionStore } = await import('../../../../core/session/SessionStore.js');
505
+ const sessionStore = new SessionStore();
506
+ const metadata = await sessionStore.loadSession(sessionId);
507
+ if (!metadata || metadata.activeDurationMs === activeDurationMs)
508
+ return;
509
+ metadata.activeDurationMs = activeDurationMs;
510
+ await sessionStore.saveSession(metadata);
511
+ logger.debug(`[pi-metrics] Saved activeDurationMs: ${activeDurationMs}`);
512
+ }
513
+ catch (error) {
514
+ logger.debug('[pi-metrics] Failed to save active duration (non-blocking):', error);
515
+ }
516
+ }
517
+ extractFileOperations(toolCall, result) {
518
+ const op = extractPiFileOperation(toolCall.name, toolCall.arguments, result?.details);
519
+ return op ? [op] : [];
520
+ }
521
+ /**
522
+ * Read back what the session's JSONL already asserts.
523
+ *
524
+ * Returns `undefined` — meaning "do not process" — when the file exists but cannot be
525
+ * read, because processing without it would duplicate every delta in it.
526
+ */
527
+ async readPersistedMetrics(sessionId) {
528
+ const persisted = {
529
+ recordIds: new Set(),
530
+ invocations: emptyInvocationTotals(),
531
+ };
532
+ try {
533
+ const { MetricsWriter } = await import('../../../../../providers/plugins/sso/session/processors/metrics/MetricsWriter.js');
534
+ const writer = new MetricsWriter(sessionId);
535
+ if (!writer.exists()) {
536
+ return persisted;
537
+ }
538
+ const content = await readFile(writer.getFilePath(), 'utf-8');
539
+ for (const line of content.split('\n')) {
540
+ const trimmed = line.trim();
541
+ if (!trimmed)
542
+ continue;
543
+ let delta;
544
+ try {
545
+ delta = JSON.parse(trimmed);
546
+ }
547
+ catch {
548
+ // Skip malformed line rather than discarding the whole set.
549
+ logger.debug('[pi-metrics] Skipping malformed delta line while loading existing record ids');
550
+ continue;
551
+ }
552
+ if (typeof delta.recordId === 'string') {
553
+ persisted.recordIds.add(delta.recordId);
554
+ }
555
+ if (typeof delta.timestamp === 'number' && Number.isFinite(delta.timestamp)) {
556
+ persisted.activityStart =
557
+ persisted.activityStart === undefined
558
+ ? delta.timestamp
559
+ : Math.min(persisted.activityStart, delta.timestamp);
560
+ persisted.activityEnd =
561
+ persisted.activityEnd === undefined
562
+ ? delta.timestamp
563
+ : Math.max(persisted.activityEnd, delta.timestamp);
564
+ }
565
+ addInvocationCounts(persisted.invocations.skillInvocations, readCountMap(delta.skillInvocations) ?? {});
566
+ addInvocationCounts(persisted.invocations.agentInvocations, readCountMap(delta.agentInvocations) ?? {});
567
+ addInvocationCounts(persisted.invocations.commandInvocations, readCountMap(delta.commandInvocations) ?? {});
568
+ }
569
+ return persisted;
570
+ }
571
+ catch (error) {
572
+ logger.warn('[pi-metrics] Could not read existing deltas safely, skipping to avoid duplicates:', error);
573
+ return undefined;
574
+ }
575
+ }
576
+ }
577
+ /**
578
+ * Hang the batch's outstanding name maps off its first delta.
579
+ *
580
+ * They describe the batch rather than any single record, and the aggregator sums them
581
+ * across deltas, so exactly one delta may carry them. Empty maps are omitted entirely
582
+ * so the wire payload keeps its current shape for runs that used none of the three.
583
+ */
584
+ function attachInvocations(deltas, invocations) {
585
+ if (deltas.length === 0)
586
+ return;
587
+ const { skillInvocations, agentInvocations, commandInvocations } = invocations;
588
+ deltas[0] = {
589
+ ...deltas[0],
590
+ ...(Object.keys(skillInvocations).length > 0 && { skillInvocations }),
591
+ ...(Object.keys(agentInvocations).length > 0 && { agentInvocations }),
592
+ ...(Object.keys(commandInvocations).length > 0 && { commandInvocations }),
593
+ };
594
+ }
595
+ //# sourceMappingURL=pi.metrics-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi.metrics-processor.js","sourceRoot":"","sources":["../../../../../../src/agents/plugins/pi/session/processors/pi.metrics-processor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,GAItB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE1F,MAAM,CAAC,MAAM,yBAAyB,GAAG,YAAY,CAAC;AAEtD,sFAAsF;AACtF,MAAM,SAAS,GAAG,MAAM,CAAC;AA+EzB,SAAS,qBAAqB;IAC5B,OAAO,EAAE,gBAAgB,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,CAAC;AAChF,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,qBAAqB,CAAC,IAA4B,EAAE,KAA8B;IACzF,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI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ACF;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,MAAsB,EAAE,WAA6B;IAC9E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAEhC,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,WAAW,CAAC;IAC/E,MAAM,CAAC,CAAC,CAAC,GAAG;QACV,GAAG,MAAM,CAAC,CAAC,CAAC;QACZ,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,gBAAgB,EAAE,CAAC;QACrE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,gBAAgB,EAAE,CAAC;QACrE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,kBAAkB,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC"}
@@ -20,6 +20,26 @@ export declare class AgentRegistry {
20
20
  static getAgent(name: string): AgentAdapter | undefined;
21
21
  static getAllAgents(): AgentAdapter[];
22
22
  static getAgentNames(): string[];
23
+ /**
24
+ * Agents CodeMie can actually install, launch and update — i.e. everything except
25
+ * analytics-only agents, which CodeMie reads telemetry for but never manages.
26
+ *
27
+ * Every agent-MANAGEMENT surface must use this rather than {@link getAllAgents}:
28
+ * install, uninstall, update, list, doctor and the first-run experience. Listing an
29
+ * unmanageable agent there advertises commands that always fail, and `codemie update`
30
+ * is actively destructive — updateAgent() never calls the adapter, it reads
31
+ * `metadata.npmPackage` and runs `npm install -g <pkg> --force`, which would overwrite
32
+ * a user's own install of a third-party tool.
33
+ *
34
+ * {@link getAllAgents} intentionally still returns them, because the analytics pipeline
35
+ * resolves session adapters through the registry.
36
+ */
37
+ static getManageableAgents(): AgentAdapter[];
38
+ /**
39
+ * Installed agents CodeMie can manage. Analytics-only agents are excluded: every
40
+ * consumer of this is a management surface (uninstall, list, doctor), and "installed"
41
+ * is meaningless for an agent CodeMie never installs.
42
+ */
23
43
  static getInstalledAgents(): Promise<AgentAdapter[]>;
24
44
  /**
25
45
  * Get analytics adapter for a specific agent