@bli-cockpit/telemetry-core 0.1.75 → 0.1.77

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.
@@ -2,12 +2,9 @@
2
2
  * Session facts: everything deterministic about one transcript, counted once,
3
3
  * where the file already is.
4
4
  *
5
- * BLI-4341 part A. Until now the only place a session's token totals were
6
- * computed was the server: `@bli-cockpit/harvest-analysis` downloaded the
7
- * transcript back out of Storage and summed it (`det.v5`). The collector holds
8
- * the same bytes at harvest time and had already read every line, so the
9
- * download was pure re-work, and a session with no analysis run had no token
10
- * count at all.
5
+ * BLI-4341 part A. Token totals used to be computed only on the server, which downloaded the transcript back out of
6
+ * Storage and summed it (`det.v5`), though the collector holds the same bytes at harvest time and had already read
7
+ * every line; a session with no analysis run had no token count at all.
11
8
  *
12
9
  * This module is the ONE implementation of those rules. The collector feeds it
13
10
  * at upload; the server extractor feeds it the same records during its own
@@ -72,6 +69,8 @@ export interface SessionFacts {
72
69
  first_timestamp: string | null;
73
70
  last_timestamp: string | null;
74
71
  wall_duration_seconds: number | null;
72
+ /** Ticket 19258: seconds in use (`session-facts-active.ts`). Absent from a block counted before this field. */
73
+ active_seconds?: number;
75
74
  transcript_bytes: number;
76
75
  transcript_lines: number;
77
76
  /** Main plus any sidecars the caller fed in. */
@@ -80,10 +79,7 @@ export interface SessionFacts {
80
79
  truncated_models: number;
81
80
  /** Distinct tool names dropped by the cap. */
82
81
  truncated_tool_names: number;
83
- /**
84
- * BLI-13056: skills used, by the person (typed) and by the agent (tool call).
85
- * Names and counts only. Absent from a block a CLI published before this field.
86
- */
82
+ /** BLI-13056: skills used, by the person (typed) and by the agent (tool call); names and counts only. Absent from a block a CLI published before this field. */
87
83
  skill_use?: SkillUseCount[];
88
84
  /** BLI-13066: who started the session (`session-facts-spawn.ts`). Absent from a block a CLI published before this field. */
89
85
  spawn?: SessionSpawn;
@@ -98,6 +94,7 @@ export interface SessionFactsAccumulator {
98
94
  tool_calls_by_name: Record<string, number>;
99
95
  first_timestamp_ms: number | null;
100
96
  last_timestamp_ms: number | null;
97
+ timestamps_ms: number[];
101
98
  transcript_bytes: number;
102
99
  transcript_lines: number;
103
100
  transcript_files: number;
@@ -179,6 +176,7 @@ export declare const SessionFactsSchema: z.ZodObject<{
179
176
  first_timestamp: z.ZodNullable<z.ZodString>;
180
177
  last_timestamp: z.ZodNullable<z.ZodString>;
181
178
  wall_duration_seconds: z.ZodNullable<z.ZodNumber>;
179
+ active_seconds: z.ZodOptional<z.ZodNumber>;
182
180
  transcript_bytes: z.ZodNumber;
183
181
  transcript_lines: z.ZodNumber;
184
182
  transcript_files: z.ZodNumber;
@@ -196,6 +194,16 @@ export declare const SessionFactsSchema: z.ZodObject<{
196
194
  worker: "worker";
197
195
  subagent: "subagent";
198
196
  }>;
197
+ client_app: z.ZodOptional<z.ZodEnum<{
198
+ unknown: "unknown";
199
+ claude_cli: "claude_cli";
200
+ claude_desktop: "claude_desktop";
201
+ claude_ide: "claude_ide";
202
+ codex_cli: "codex_cli";
203
+ codex_desktop: "codex_desktop";
204
+ codex_ide: "codex_ide";
205
+ codex_exec: "codex_exec";
206
+ }>>;
199
207
  parent_session_id: z.ZodOptional<z.ZodString>;
200
208
  }, z.core.$strict>>;
201
209
  }, z.core.$strict>;
@@ -2,12 +2,9 @@
2
2
  * Session facts: everything deterministic about one transcript, counted once,
3
3
  * where the file already is.
4
4
  *
5
- * BLI-4341 part A. Until now the only place a session's token totals were
6
- * computed was the server: `@bli-cockpit/harvest-analysis` downloaded the
7
- * transcript back out of Storage and summed it (`det.v5`). The collector holds
8
- * the same bytes at harvest time and had already read every line, so the
9
- * download was pure re-work, and a session with no analysis run had no token
10
- * count at all.
5
+ * BLI-4341 part A. Token totals used to be computed only on the server, which downloaded the transcript back out of
6
+ * Storage and summed it (`det.v5`), though the collector holds the same bytes at harvest time and had already read
7
+ * every line; a session with no analysis run had no token count at all.
11
8
  *
12
9
  * This module is the ONE implementation of those rules. The collector feeds it
13
10
  * at upload; the server extractor feeds it the same records during its own
@@ -36,6 +33,7 @@
36
33
  */
37
34
  import { z } from "zod";
38
35
  import { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText } from "./session-facts-text.js";
36
+ import { activeSeconds } from "./session-facts-active.js";
39
37
  import { claudeSpawn, codexSpawn, SessionSpawnSchema } from "./session-facts-spawn.js";
40
38
  import { observeClaudeSkillUse, observeCodexSkillUse, SKILL_USE_MAX_SKILLS, SkillUseCountSchema, SkillUseTally } from "./session-facts-skills.js";
41
39
  /** Bump when a counting rule changes, never when a field is added. */
@@ -56,6 +54,7 @@ export function newSessionFactsAccumulator(source) {
56
54
  tool_calls_by_name: {},
57
55
  first_timestamp_ms: null,
58
56
  last_timestamp_ms: null,
57
+ timestamps_ms: [],
59
58
  transcript_bytes: 0,
60
59
  transcript_lines: 0,
61
60
  transcript_files: 0,
@@ -76,6 +75,7 @@ export function observeSessionFactsRecord(acc, record) {
76
75
  acc.record_count += 1;
77
76
  const ms = parseTimestampMs(record["timestamp"]);
78
77
  if (ms != null) {
78
+ acc.timestamps_ms.push(ms);
79
79
  acc.first_timestamp_ms =
80
80
  acc.first_timestamp_ms == null ? ms : Math.min(acc.first_timestamp_ms, ms);
81
81
  acc.last_timestamp_ms =
@@ -216,12 +216,7 @@ export function finalizeSessionFacts(acc) {
216
216
  const keptTools = toolEntries.slice(0, SESSION_FACTS_MAX_TOOL_NAMES);
217
217
  const usage_by_model = Object.fromEntries(keptUsage);
218
218
  const tool_calls_by_name = Object.fromEntries(keptTools);
219
- const totals = keptUsage.reduce((sum, [, usage]) => ({
220
- input_tokens: sum.input_tokens + usage.input_tokens,
221
- output_tokens: sum.output_tokens + usage.output_tokens,
222
- cache_read_input_tokens: sum.cache_read_input_tokens + usage.cache_read_input_tokens,
223
- cache_creation_input_tokens: sum.cache_creation_input_tokens + usage.cache_creation_input_tokens,
224
- }), emptyUsage());
219
+ const totals = sumUsage(keptUsage.map(([, usage]) => usage));
225
220
  const first = acc.first_timestamp_ms;
226
221
  const last = acc.last_timestamp_ms;
227
222
  return {
@@ -250,6 +245,7 @@ export function finalizeSessionFacts(acc) {
250
245
  truncated_tool_names: toolEntries.length - keptTools.length,
251
246
  skill_use: acc.skill_tally.toList().slice(0, SKILL_USE_MAX_SKILLS),
252
247
  ...(acc.spawn ? { spawn: acc.spawn } : {}),
248
+ active_seconds: activeSeconds(acc.timestamps_ms),
253
249
  };
254
250
  }
255
251
  /**
@@ -299,6 +295,14 @@ function usageTotal(usage) {
299
295
  usage.cache_read_input_tokens +
300
296
  usage.cache_creation_input_tokens);
301
297
  }
298
+ function sumUsage(usages) {
299
+ return usages.reduce((sum, usage) => ({
300
+ input_tokens: sum.input_tokens + usage.input_tokens,
301
+ output_tokens: sum.output_tokens + usage.output_tokens,
302
+ cache_read_input_tokens: sum.cache_read_input_tokens + usage.cache_read_input_tokens,
303
+ cache_creation_input_tokens: sum.cache_creation_input_tokens + usage.cache_creation_input_tokens,
304
+ }), emptyUsage());
305
+ }
302
306
  function emptyUsage() {
303
307
  return {
304
308
  input_tokens: 0,
@@ -359,6 +363,7 @@ export const SessionFactsSchema = z
359
363
  first_timestamp: z.string().datetime({ offset: true }).nullable(),
360
364
  last_timestamp: z.string().datetime({ offset: true }).nullable(),
361
365
  wall_duration_seconds: z.number().int().nonnegative().nullable(),
366
+ active_seconds: z.number().int().nonnegative().optional(),
362
367
  transcript_bytes: z.number().int().nonnegative(),
363
368
  transcript_lines: z.number().int().nonnegative(),
364
369
  transcript_files: z.number().int().nonnegative(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.75",
3
+ "version": "0.1.77",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",