@bli-cockpit/telemetry-core 0.1.66 → 0.1.68

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.
@@ -1,5 +1,22 @@
1
1
  import { z } from "zod";
2
2
  export declare const SetupNameSchema: z.ZodString;
3
+ export declare const VersionSourceSchema: z.ZodEnum<{
4
+ cli: "cli";
5
+ package: "package";
6
+ transcript: "transcript";
7
+ none: "none";
8
+ }>;
9
+ export declare const ModelBasisSchema: z.ZodEnum<{
10
+ set: "set";
11
+ none: "none";
12
+ used: "used";
13
+ }>;
14
+ export declare const EffortBasisSchema: z.ZodEnum<{
15
+ set: "set";
16
+ default: "default";
17
+ none: "none";
18
+ observed: "observed";
19
+ }>;
3
20
  export declare const AgentSetupSchema: z.ZodObject<{
4
21
  checked_at: z.ZodString;
5
22
  os: z.ZodEnum<{
@@ -12,6 +29,23 @@ export declare const AgentSetupSchema: z.ZodObject<{
12
29
  version: z.ZodNullable<z.ZodString>;
13
30
  model: z.ZodNullable<z.ZodString>;
14
31
  effort: z.ZodNullable<z.ZodString>;
32
+ version_source: z.ZodOptional<z.ZodEnum<{
33
+ cli: "cli";
34
+ package: "package";
35
+ transcript: "transcript";
36
+ none: "none";
37
+ }>>;
38
+ model_basis: z.ZodOptional<z.ZodEnum<{
39
+ set: "set";
40
+ none: "none";
41
+ used: "used";
42
+ }>>;
43
+ effort_basis: z.ZodOptional<z.ZodEnum<{
44
+ set: "set";
45
+ default: "default";
46
+ none: "none";
47
+ observed: "observed";
48
+ }>>;
15
49
  skills: z.ZodNullable<z.ZodArray<z.ZodString>>;
16
50
  plugins: z.ZodNullable<z.ZodArray<z.ZodString>>;
17
51
  agents: z.ZodNullable<z.ZodArray<z.ZodString>>;
@@ -30,6 +64,23 @@ export declare const AgentSetupSchema: z.ZodObject<{
30
64
  version: z.ZodNullable<z.ZodString>;
31
65
  model: z.ZodNullable<z.ZodString>;
32
66
  effort: z.ZodNullable<z.ZodString>;
67
+ version_source: z.ZodOptional<z.ZodEnum<{
68
+ cli: "cli";
69
+ package: "package";
70
+ transcript: "transcript";
71
+ none: "none";
72
+ }>>;
73
+ model_basis: z.ZodOptional<z.ZodEnum<{
74
+ set: "set";
75
+ none: "none";
76
+ used: "used";
77
+ }>>;
78
+ effort_basis: z.ZodOptional<z.ZodEnum<{
79
+ set: "set";
80
+ default: "default";
81
+ none: "none";
82
+ observed: "observed";
83
+ }>>;
33
84
  skills: z.ZodNullable<z.ZodArray<z.ZodString>>;
34
85
  plugins: z.ZodNullable<z.ZodArray<z.ZodString>>;
35
86
  agents: z.ZodNullable<z.ZodArray<z.ZodString>>;
@@ -5,8 +5,16 @@ import { containsSecretLikeContent } from "./secret-guards.js";
5
5
  export const SetupNameSchema = z.string().max(100).regex(/^[a-z0-9][a-z0-9_.@+-]*$/i)
6
6
  .refine(value => !containsSecretLikeContent(value), "secret_like_name");
7
7
  const names = z.array(SetupNameSchema).max(500);
8
+ // BLI-13055: where each of the three words came from. Optional so receipts
9
+ // written before this field existed still parse; a missing basis reads as
10
+ // "set" when a value is present and as "default" (effort) or "no evidence"
11
+ // (model, version) when it is null.
12
+ export const VersionSourceSchema = z.enum(["cli", "package", "transcript", "none"]);
13
+ export const ModelBasisSchema = z.enum(["set", "used", "none"]);
14
+ export const EffortBasisSchema = z.enum(["set", "observed", "default", "none"]);
8
15
  const tool = z.object({
9
16
  version: SetupNameSchema.nullable(), model: SetupNameSchema.nullable(), effort: SetupNameSchema.nullable(),
17
+ version_source: VersionSourceSchema.optional(), model_basis: ModelBasisSchema.optional(), effort_basis: EffortBasisSchema.optional(),
10
18
  skills: names.nullable(), plugins: names.nullable(), agents: names.nullable(), hooks: names.nullable(),
11
19
  mcp: z.array(z.object({ name: SetupNameSchema, transport: z.enum(["stdio", "http", "sse", "unknown"]) }).strict()).max(500).nullable(),
12
20
  }).strict();
@@ -184,6 +184,23 @@ export declare const CollectorHeartbeatSchema: z.ZodObject<{
184
184
  version: z.ZodNullable<z.ZodString>;
185
185
  model: z.ZodNullable<z.ZodString>;
186
186
  effort: z.ZodNullable<z.ZodString>;
187
+ version_source: z.ZodOptional<z.ZodEnum<{
188
+ cli: "cli";
189
+ package: "package";
190
+ transcript: "transcript";
191
+ none: "none";
192
+ }>>;
193
+ model_basis: z.ZodOptional<z.ZodEnum<{
194
+ set: "set";
195
+ none: "none";
196
+ used: "used";
197
+ }>>;
198
+ effort_basis: z.ZodOptional<z.ZodEnum<{
199
+ set: "set";
200
+ default: "default";
201
+ none: "none";
202
+ observed: "observed";
203
+ }>>;
187
204
  skills: z.ZodNullable<z.ZodArray<z.ZodString>>;
188
205
  plugins: z.ZodNullable<z.ZodArray<z.ZodString>>;
189
206
  agents: z.ZodNullable<z.ZodArray<z.ZodString>>;
@@ -202,6 +219,23 @@ export declare const CollectorHeartbeatSchema: z.ZodObject<{
202
219
  version: z.ZodNullable<z.ZodString>;
203
220
  model: z.ZodNullable<z.ZodString>;
204
221
  effort: z.ZodNullable<z.ZodString>;
222
+ version_source: z.ZodOptional<z.ZodEnum<{
223
+ cli: "cli";
224
+ package: "package";
225
+ transcript: "transcript";
226
+ none: "none";
227
+ }>>;
228
+ model_basis: z.ZodOptional<z.ZodEnum<{
229
+ set: "set";
230
+ none: "none";
231
+ used: "used";
232
+ }>>;
233
+ effort_basis: z.ZodOptional<z.ZodEnum<{
234
+ set: "set";
235
+ default: "default";
236
+ none: "none";
237
+ observed: "observed";
238
+ }>>;
205
239
  skills: z.ZodNullable<z.ZodArray<z.ZodString>>;
206
240
  plugins: z.ZodNullable<z.ZodArray<z.ZodString>>;
207
241
  agents: z.ZodNullable<z.ZodArray<z.ZodString>>;
@@ -239,8 +239,8 @@ export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
239
239
  }, z.core.$strict>;
240
240
  export type RawEvidenceUploadBeginRequest = z.infer<typeof RawEvidenceUploadBeginRequestSchema>;
241
241
  export declare const RawEvidenceUploadDispositionSchema: z.ZodEnum<{
242
- new: "new";
243
242
  resume: "resume";
243
+ new: "new";
244
244
  already_committed: "already_committed";
245
245
  conflict: "conflict";
246
246
  }>;
@@ -249,8 +249,8 @@ export declare const RawEvidenceUploadBeginResponseObjectSchema: z.ZodObject<{
249
249
  object_key: z.ZodString;
250
250
  raw_evidence_pointer_id: z.ZodString;
251
251
  disposition: z.ZodEnum<{
252
- new: "new";
253
252
  resume: "resume";
253
+ new: "new";
254
254
  already_committed: "already_committed";
255
255
  conflict: "conflict";
256
256
  }>;
@@ -266,8 +266,8 @@ export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
266
266
  object_key: z.ZodString;
267
267
  raw_evidence_pointer_id: z.ZodString;
268
268
  disposition: z.ZodEnum<{
269
- new: "new";
270
269
  resume: "resume";
270
+ new: "new";
271
271
  already_committed: "already_committed";
272
272
  conflict: "conflict";
273
273
  }>;
@@ -584,12 +584,19 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
584
584
  transcript_files: z.ZodNumber;
585
585
  truncated_models: z.ZodNumber;
586
586
  truncated_tool_names: z.ZodNumber;
587
+ skill_use: z.ZodOptional<z.ZodArray<z.ZodObject<{
588
+ skill: z.ZodString;
589
+ plugin: z.ZodNullable<z.ZodString>;
590
+ by_person: z.ZodNumber;
591
+ by_agent: z.ZodNumber;
592
+ }, z.core.$strict>>>;
587
593
  }, z.core.$strict>>;
588
594
  session_file_mtime: z.ZodOptional<z.ZodString>;
589
595
  repo_fingerprint: z.ZodOptional<z.ZodString>;
590
596
  worktree_fingerprint: z.ZodOptional<z.ZodString>;
591
597
  repo_label: z.ZodOptional<z.ZodString>;
592
598
  branch: z.ZodOptional<z.ZodString>;
599
+ commit_shas: z.ZodOptional<z.ZodArray<z.ZodString>>;
593
600
  root_scope: z.ZodOptional<z.ZodEnum<{
594
601
  inside: "inside";
595
602
  outside: "outside";
@@ -692,12 +699,19 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
692
699
  transcript_files: z.ZodNumber;
693
700
  truncated_models: z.ZodNumber;
694
701
  truncated_tool_names: z.ZodNumber;
702
+ skill_use: z.ZodOptional<z.ZodArray<z.ZodObject<{
703
+ skill: z.ZodString;
704
+ plugin: z.ZodNullable<z.ZodString>;
705
+ by_person: z.ZodNumber;
706
+ by_agent: z.ZodNumber;
707
+ }, z.core.$strict>>>;
695
708
  }, z.core.$strict>>;
696
709
  session_file_mtime: z.ZodOptional<z.ZodString>;
697
710
  repo_fingerprint: z.ZodOptional<z.ZodString>;
698
711
  worktree_fingerprint: z.ZodOptional<z.ZodString>;
699
712
  repo_label: z.ZodOptional<z.ZodString>;
700
713
  branch: z.ZodOptional<z.ZodString>;
714
+ commit_shas: z.ZodOptional<z.ZodArray<z.ZodString>>;
701
715
  root_scope: z.ZodOptional<z.ZodEnum<{
702
716
  inside: "inside";
703
717
  outside: "outside";
@@ -311,6 +311,17 @@ export const CodexSessionAttributionSchema = z
311
311
  worktree_fingerprint: SafeLabelSchema.optional(),
312
312
  repo_label: BasenameSchema.optional(),
313
313
  branch: z.string().trim().min(1).max(200).optional(),
314
+ /**
315
+ * BLI-13028: full SHAs of the commits this session's working tree created
316
+ * between its first and last transcript timestamp. Metadata only. Absent
317
+ * means the collector did not look (old CLI, no working tree, unreadable
318
+ * git); an empty list means it looked and found none. Lets the Setup page
319
+ * judge a session shipped without relying on its branch.
320
+ */
321
+ commit_shas: z
322
+ .array(z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/))
323
+ .max(100)
324
+ .optional(),
314
325
  root_scope: RootScopeSchema.optional(),
315
326
  cwd_basename: BasenameSchema.optional(),
316
327
  cwd_hash: z
package/dist/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export * from "./risk-flags.js";
25
25
  export * from "./run-verdict.js";
26
26
  export * from "./secret-guards.js";
27
27
  export * from "./session-facts.js";
28
+ export * from "./session-facts-skills.js";
28
29
  export * from "./source-adapter.js";
29
30
  export * from "./ticket-id.js";
30
31
  export * from "./trace-sink.js";
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ export * from "./risk-flags.js";
25
25
  export * from "./run-verdict.js";
26
26
  export * from "./secret-guards.js";
27
27
  export * from "./session-facts.js";
28
+ export * from "./session-facts-skills.js";
28
29
  export * from "./source-adapter.js";
29
30
  export * from "./ticket-id.js";
30
31
  export * from "./trace-sink.js";
@@ -0,0 +1,72 @@
1
+ /**
2
+ * BLI-13056: which skills a session used, and who invoked them. Lives beside
3
+ * `session-facts` because the collector (at upload) and the server (harvest,
4
+ * ladder) must count it by the same rules, and an upload-time `session_metrics`
5
+ * row that lacked it would shadow every extracted row that had it.
6
+ *
7
+ * Two kinds, because "installed" and "used" are different and so are "I typed
8
+ * it" and "the agent reached for it":
9
+ * by_person: the person typed a slash command (Claude Code) or named the
10
+ * skill so Codex injected it into the turn.
11
+ * by_agent: the model called the Skill tool (Claude Code) or opened the
12
+ * skill's SKILL.md (Codex has no Skill tool).
13
+ *
14
+ * Names and counts only. Arguments (`<command-args>`) are never read.
15
+ */
16
+ import { z } from "zod";
17
+ export declare const SKILL_USE_VERSION = "skills.v1";
18
+ /** One session names at most this many distinct skills; the rest are dropped. */
19
+ export declare const SKILL_USE_MAX_SKILLS = 100;
20
+ export declare const SkillUseCountSchema: z.ZodObject<{
21
+ skill: z.ZodString;
22
+ plugin: z.ZodNullable<z.ZodString>;
23
+ by_person: z.ZodNumber;
24
+ by_agent: z.ZodNumber;
25
+ }, z.core.$strict>;
26
+ export interface SkillUseCount {
27
+ /** Name with any plugin prefix and leading `/` or `$` removed. */
28
+ skill: string;
29
+ /** The plugin the name was prefixed with (`plugin:skill`), else null. */
30
+ plugin: string | null;
31
+ by_person: number;
32
+ by_agent: number;
33
+ }
34
+ /** What a `session_metrics` row stores under `scores.skill_use`. */
35
+ export interface SkillUseScore {
36
+ version: typeof SKILL_USE_VERSION;
37
+ skills: SkillUseCount[];
38
+ }
39
+ export declare function skillUseScore(skills: SkillUseCount[]): SkillUseScore;
40
+ export declare function normalizeSkillName(raw: string): {
41
+ skill: string;
42
+ plugin: string | null;
43
+ } | null;
44
+ export declare class SkillUseTally {
45
+ private readonly counts;
46
+ addByPerson(raw: string): void;
47
+ addByAgent(raw: string): void;
48
+ /** Most used first, ties by name, so the stored list is stable. */
49
+ toList(): SkillUseCount[];
50
+ private entry;
51
+ }
52
+ /**
53
+ * The skill a person typed, from a Claude Code user turn. A typed command is
54
+ * recorded as `<command-message>x</command-message><command-name>/x</command-name>
55
+ * <command-args>…</command-args>` in a user record. Returns null for plain text,
56
+ * for the bare names that skill-listing attachments carry, and for built-ins.
57
+ */
58
+ export declare function claudeTypedSkill(content: unknown): string | null;
59
+ /** The skill the model invoked through Claude Code's `Skill` tool. */
60
+ export declare function claudeAgentSkill(input: unknown): string | null;
61
+ /** The skill Codex injected into a user turn (the person named it). */
62
+ export declare function codexTypedSkill(content: unknown): string | null;
63
+ /**
64
+ * The skills a Codex tool call opened. Codex has no Skill tool: the model
65
+ * reads `.../skills/<name>/SKILL.md` with a shell command, so the path is the
66
+ * receipt. One name counts once per call, however many times the path repeats.
67
+ */
68
+ export declare function codexAgentSkills(callArguments: unknown): string[];
69
+ /** Feeds one Claude Code record to the tally: a typed command (user turn) or a `Skill` tool call (assistant turn). */
70
+ export declare function observeClaudeSkillUse(tally: SkillUseTally, record: Record<string, unknown>): void;
71
+ /** Feeds one Codex `response_item` payload to the tally: an injected `<skill>` user turn or a tool call that opened a SKILL.md. */
72
+ export declare function observeCodexSkillUse(tally: SkillUseTally, payload: Record<string, unknown>): void;
@@ -0,0 +1,201 @@
1
+ /**
2
+ * BLI-13056: which skills a session used, and who invoked them. Lives beside
3
+ * `session-facts` because the collector (at upload) and the server (harvest,
4
+ * ladder) must count it by the same rules, and an upload-time `session_metrics`
5
+ * row that lacked it would shadow every extracted row that had it.
6
+ *
7
+ * Two kinds, because "installed" and "used" are different and so are "I typed
8
+ * it" and "the agent reached for it":
9
+ * by_person: the person typed a slash command (Claude Code) or named the
10
+ * skill so Codex injected it into the turn.
11
+ * by_agent: the model called the Skill tool (Claude Code) or opened the
12
+ * skill's SKILL.md (Codex has no Skill tool).
13
+ *
14
+ * Names and counts only. Arguments (`<command-args>`) are never read.
15
+ */
16
+ import { z } from "zod";
17
+ export const SKILL_USE_VERSION = "skills.v1";
18
+ /** One session names at most this many distinct skills; the rest are dropped. */
19
+ export const SKILL_USE_MAX_SKILLS = 100;
20
+ export const SkillUseCountSchema = z
21
+ .object({
22
+ skill: z.string().min(1).max(200),
23
+ plugin: z.string().min(1).max(200).nullable(),
24
+ by_person: z.number().int().nonnegative(),
25
+ by_agent: z.number().int().nonnegative(),
26
+ })
27
+ .strict();
28
+ export function skillUseScore(skills) {
29
+ return { version: SKILL_USE_VERSION, skills };
30
+ }
31
+ /**
32
+ * Typed slash commands that are Claude Code's own controls, not skills.
33
+ * A transcript records them with the same `<command-name>` tag as a skill, so
34
+ * the only way to keep `/clear` out of a skill ranking is to name them.
35
+ */
36
+ const CLAUDE_BUILT_IN_COMMANDS = new Set([
37
+ "add-dir", "agents", "bashes", "bug", "clear", "compact", "config", "context", "cost", "doctor", "effort", "exit",
38
+ "export", "fast", "feedback", "help", "hooks", "ide", "init", "install-github-app", "login", "logout", "mcp",
39
+ "memory", "model", "output-style", "permissions", "plugin", "plugins", "pr-comments", "privacy-settings", "quit",
40
+ "rate-limit-options", "recap", "release-notes", "reload-plugins", "remote-control", "rename", "resume", "rewind",
41
+ "settings", "status", "statusline", "team-onboarding", "terminal-setup", "theme", "todos", "upgrade", "usage", "vim",
42
+ "extra-usage", "stats", "tasks", "keybindings", "mobile", "desktop", "chrome", "skills", "branch", "copy", "diff",
43
+ ]);
44
+ export function normalizeSkillName(raw) {
45
+ const bare = raw.trim().replace(/^[/$]+/, "").trim();
46
+ if (!bare || bare.length > 200 || /\s/.test(bare))
47
+ return null;
48
+ const colon = bare.lastIndexOf(":");
49
+ if (colon < 0)
50
+ return { skill: bare, plugin: null };
51
+ const plugin = bare.slice(0, colon);
52
+ const skill = bare.slice(colon + 1);
53
+ return skill ? { skill, plugin: plugin || null } : null;
54
+ }
55
+ export class SkillUseTally {
56
+ counts = new Map();
57
+ addByPerson(raw) {
58
+ const entry = this.entry(raw);
59
+ if (entry)
60
+ entry.by_person += 1;
61
+ }
62
+ addByAgent(raw) {
63
+ const entry = this.entry(raw);
64
+ if (entry)
65
+ entry.by_agent += 1;
66
+ }
67
+ /** Most used first, ties by name, so the stored list is stable. */
68
+ toList() {
69
+ return [...this.counts.values()]
70
+ .filter((c) => c.by_person + c.by_agent > 0)
71
+ .sort((a, b) => b.by_person + b.by_agent - (a.by_person + a.by_agent) || a.skill.localeCompare(b.skill));
72
+ }
73
+ entry(raw) {
74
+ const name = normalizeSkillName(raw);
75
+ if (!name)
76
+ return null;
77
+ const key = `${name.plugin ?? ""}:${name.skill}`;
78
+ let entry = this.counts.get(key);
79
+ if (!entry) {
80
+ entry = { skill: name.skill, plugin: name.plugin, by_person: 0, by_agent: 0 };
81
+ this.counts.set(key, entry);
82
+ }
83
+ return entry;
84
+ }
85
+ }
86
+ const CLAUDE_COMMAND_RE = /^\s*(?:<command-message>[^<]{0,200}<\/command-message>\s*)?<command-name>([^<]{1,200})<\/command-name>/;
87
+ /**
88
+ * The skill a person typed, from a Claude Code user turn. A typed command is
89
+ * recorded as `<command-message>x</command-message><command-name>/x</command-name>
90
+ * <command-args>…</command-args>` in a user record. Returns null for plain text,
91
+ * for the bare names that skill-listing attachments carry, and for built-ins.
92
+ */
93
+ export function claudeTypedSkill(content) {
94
+ const text = firstText(content);
95
+ if (!text)
96
+ return null;
97
+ const match = CLAUDE_COMMAND_RE.exec(text.slice(0, 600));
98
+ const name = match?.[1]?.trim();
99
+ if (!name?.startsWith("/"))
100
+ return null;
101
+ const parsed = normalizeSkillName(name);
102
+ if (!parsed)
103
+ return null;
104
+ if (!parsed.plugin && CLAUDE_BUILT_IN_COMMANDS.has(parsed.skill))
105
+ return null;
106
+ return name;
107
+ }
108
+ function firstText(content) {
109
+ if (typeof content === "string")
110
+ return content;
111
+ if (!Array.isArray(content))
112
+ return null;
113
+ for (const block of content) {
114
+ const kind = block && typeof block === "object" ? block["type"] : null;
115
+ if (kind === "text" || kind === "input_text") {
116
+ const text = block["text"];
117
+ if (typeof text === "string")
118
+ return text;
119
+ }
120
+ }
121
+ return null;
122
+ }
123
+ /** The skill the model invoked through Claude Code's `Skill` tool. */
124
+ export function claudeAgentSkill(input) {
125
+ if (!input || typeof input !== "object")
126
+ return null;
127
+ const skill = input["skill"];
128
+ return typeof skill === "string" ? skill : null;
129
+ }
130
+ const CODEX_INJECTED_SKILL_RE = /^\s*<skill>\s*<name>([^<]{1,200})<\/name>/;
131
+ /** The skill Codex injected into a user turn (the person named it). */
132
+ export function codexTypedSkill(content) {
133
+ const text = firstText(content);
134
+ if (!text)
135
+ return null;
136
+ return CODEX_INJECTED_SKILL_RE.exec(text.slice(0, 400))?.[1]?.trim() ?? null;
137
+ }
138
+ const CODEX_SKILL_FILE_RE = /\/skills\/(?:\.system\/)?([^/\s"'\\]+)\/SKILL\.md/g;
139
+ const CODEX_PLUGIN_SKILL_RE = /\/plugins\/cache\/[^/\s"'\\]+\/([^/\s"'\\]+)\/[^/\s"'\\]+\/skills\/([^/\s"'\\]+)\/SKILL\.md/g;
140
+ /**
141
+ * The skills a Codex tool call opened. Codex has no Skill tool: the model
142
+ * reads `.../skills/<name>/SKILL.md` with a shell command, so the path is the
143
+ * receipt. One name counts once per call, however many times the path repeats.
144
+ */
145
+ export function codexAgentSkills(callArguments) {
146
+ const text = typeof callArguments === "string" ? callArguments : callArguments == null ? "" : safeStringify(callArguments);
147
+ if (!text.includes("SKILL.md"))
148
+ return [];
149
+ const found = new Set();
150
+ for (const m of text.matchAll(CODEX_PLUGIN_SKILL_RE))
151
+ found.add(`${m[1]}:${m[2]}`);
152
+ for (const m of text.matchAll(CODEX_SKILL_FILE_RE)) {
153
+ const name = m[1];
154
+ if (![...found].some((f) => f.endsWith(`:${name}`)))
155
+ found.add(name);
156
+ }
157
+ return [...found];
158
+ }
159
+ function safeStringify(value) {
160
+ try {
161
+ return JSON.stringify(value);
162
+ }
163
+ catch {
164
+ return "";
165
+ }
166
+ }
167
+ /** Feeds one Claude Code record to the tally: a typed command (user turn) or a `Skill` tool call (assistant turn). */
168
+ export function observeClaudeSkillUse(tally, record) {
169
+ const message = record["message"];
170
+ if (record["type"] === "user") {
171
+ const typed = claudeTypedSkill(message?.["content"]);
172
+ if (typed)
173
+ tally.addByPerson(typed);
174
+ return;
175
+ }
176
+ const content = message?.["content"];
177
+ if (record["type"] !== "assistant" || !Array.isArray(content))
178
+ return;
179
+ for (const block of content) {
180
+ if (!block || typeof block !== "object" || block["type"] !== "tool_use")
181
+ continue;
182
+ if (block["name"] !== "Skill")
183
+ continue;
184
+ const skill = claudeAgentSkill(block["input"]);
185
+ if (skill)
186
+ tally.addByAgent(skill);
187
+ }
188
+ }
189
+ /** Feeds one Codex `response_item` payload to the tally: an injected `<skill>` user turn or a tool call that opened a SKILL.md. */
190
+ export function observeCodexSkillUse(tally, payload) {
191
+ const itemType = String(payload["type"] ?? "");
192
+ if ((itemType === "message" || itemType === "user_message") && payload["role"] === "user") {
193
+ const typed = codexTypedSkill(payload["content"]);
194
+ if (typed)
195
+ tally.addByPerson(typed);
196
+ }
197
+ else if (itemType === "function_call" || itemType === "custom_tool_call") {
198
+ for (const skill of codexAgentSkills(payload["arguments"] ?? payload["input"]))
199
+ tally.addByAgent(skill);
200
+ }
201
+ }
@@ -35,6 +35,7 @@
35
35
  * Anthropic-shaped usage the price table expects.
36
36
  */
37
37
  import { z } from "zod";
38
+ import { SkillUseTally, type SkillUseCount } from "./session-facts-skills.js";
38
39
  /** Bump when a counting rule changes, never when a field is added. */
39
40
  export declare const SESSION_FACTS_VERSION = "det.v6";
40
41
  /** How many distinct models and tool names one session may report. */
@@ -77,6 +78,11 @@ export interface SessionFacts {
77
78
  truncated_models: number;
78
79
  /** Distinct tool names dropped by the cap. */
79
80
  truncated_tool_names: number;
81
+ /**
82
+ * BLI-13056: skills used, by the person (typed) and by the agent (tool call).
83
+ * Names and counts only. Absent from a block a CLI published before this field.
84
+ */
85
+ skill_use?: SkillUseCount[];
80
86
  }
81
87
  export interface SessionFactsAccumulator {
82
88
  source: SessionFactsSource;
@@ -94,6 +100,7 @@ export interface SessionFactsAccumulator {
94
100
  /** Codex only: the newest cumulative total and the model to attribute it to. */
95
101
  codex_total_usage: Record<string, unknown> | null;
96
102
  codex_model_hint: string | null;
103
+ skill_tally: SkillUseTally;
97
104
  }
98
105
  export declare function newSessionFactsAccumulator(source: SessionFactsSource): SessionFactsAccumulator;
99
106
  /** One transcript file's size, for callers that never hold its whole text. */
@@ -172,6 +179,12 @@ export declare const SessionFactsSchema: z.ZodObject<{
172
179
  transcript_files: z.ZodNumber;
173
180
  truncated_models: z.ZodNumber;
174
181
  truncated_tool_names: z.ZodNumber;
182
+ skill_use: z.ZodOptional<z.ZodArray<z.ZodObject<{
183
+ skill: z.ZodString;
184
+ plugin: z.ZodNullable<z.ZodString>;
185
+ by_person: z.ZodNumber;
186
+ by_agent: z.ZodNumber;
187
+ }, z.core.$strict>>>;
175
188
  }, z.core.$strict>;
176
189
  export type SessionFactsWire = z.infer<typeof SessionFactsSchema>;
177
190
  export { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText, normalizeTurnText, textFromPlainTextBlocks, } from "./session-facts-text.js";
@@ -36,6 +36,7 @@
36
36
  */
37
37
  import { z } from "zod";
38
38
  import { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText, } from "./session-facts-text.js";
39
+ import { observeClaudeSkillUse, observeCodexSkillUse, SKILL_USE_MAX_SKILLS, SkillUseCountSchema, SkillUseTally, } from "./session-facts-skills.js";
39
40
  /** Bump when a counting rule changes, never when a field is added. */
40
41
  export const SESSION_FACTS_VERSION = "det.v6";
41
42
  /** How many distinct models and tool names one session may report. */
@@ -59,6 +60,7 @@ export function newSessionFactsAccumulator(source) {
59
60
  transcript_files: 0,
60
61
  codex_total_usage: null,
61
62
  codex_model_hint: null,
63
+ skill_tally: new SkillUseTally(),
62
64
  };
63
65
  }
64
66
  /** One transcript file's size, for callers that never hold its whole text. */
@@ -90,6 +92,7 @@ function observeClaudeRecord(acc, record) {
90
92
  const text = claudeUserTurnText(record);
91
93
  if (text?.trim())
92
94
  acc.user_prompt_count += 1;
95
+ observeClaudeSkillUse(acc.skill_tally, record);
93
96
  return;
94
97
  }
95
98
  if (type !== "assistant")
@@ -122,6 +125,7 @@ function observeClaudeRecord(acc, record) {
122
125
  continue;
123
126
  countTool(acc, typeof b["name"] === "string" ? b["name"] : "unknown");
124
127
  }
128
+ observeClaudeSkillUse(acc.skill_tally, record);
125
129
  }
126
130
  function observeCodexRecord(acc, record) {
127
131
  const type = String(record["type"] ?? "");
@@ -137,6 +141,7 @@ function observeCodexRecord(acc, record) {
137
141
  if ((itemType === "message" || itemType === "user_message") && p["role"] === "user") {
138
142
  if (codexUserTurnText(p)?.trim())
139
143
  acc.user_prompt_count += 1;
144
+ observeCodexSkillUse(acc.skill_tally, p);
140
145
  return;
141
146
  }
142
147
  if (itemType === "message" && p["role"] === "assistant") {
@@ -147,6 +152,7 @@ function observeCodexRecord(acc, record) {
147
152
  if (itemType === "function_call") {
148
153
  countTool(acc, typeof p["name"] === "string" ? p["name"] : "unknown");
149
154
  }
155
+ observeCodexSkillUse(acc.skill_tally, p);
150
156
  return;
151
157
  }
152
158
  if (type !== "event_msg")
@@ -237,6 +243,7 @@ export function finalizeSessionFacts(acc) {
237
243
  transcript_files: acc.transcript_files,
238
244
  truncated_models: usageEntries.length - keptUsage.length,
239
245
  truncated_tool_names: toolEntries.length - keptTools.length,
246
+ skill_use: acc.skill_tally.toList().slice(0, SKILL_USE_MAX_SKILLS),
240
247
  };
241
248
  }
242
249
  /**
@@ -351,6 +358,7 @@ export const SessionFactsSchema = z
351
358
  transcript_files: z.number().int().nonnegative(),
352
359
  truncated_models: z.number().int().nonnegative(),
353
360
  truncated_tool_names: z.number().int().nonnegative(),
361
+ skill_use: z.array(SkillUseCountSchema).max(SKILL_USE_MAX_SKILLS).optional(),
354
362
  })
355
363
  .strict();
356
364
  export { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText, normalizeTurnText, textFromPlainTextBlocks, } from "./session-facts-text.js";
@@ -78,6 +78,23 @@ export declare const SetupReceiptSchema: z.ZodObject<{
78
78
  version: z.ZodNullable<z.ZodString>;
79
79
  model: z.ZodNullable<z.ZodString>;
80
80
  effort: z.ZodNullable<z.ZodString>;
81
+ version_source: z.ZodOptional<z.ZodEnum<{
82
+ cli: "cli";
83
+ package: "package";
84
+ transcript: "transcript";
85
+ none: "none";
86
+ }>>;
87
+ model_basis: z.ZodOptional<z.ZodEnum<{
88
+ set: "set";
89
+ none: "none";
90
+ used: "used";
91
+ }>>;
92
+ effort_basis: z.ZodOptional<z.ZodEnum<{
93
+ set: "set";
94
+ default: "default";
95
+ none: "none";
96
+ observed: "observed";
97
+ }>>;
81
98
  skills: z.ZodNullable<z.ZodArray<z.ZodString>>;
82
99
  plugins: z.ZodNullable<z.ZodArray<z.ZodString>>;
83
100
  agents: z.ZodNullable<z.ZodArray<z.ZodString>>;
@@ -96,6 +113,23 @@ export declare const SetupReceiptSchema: z.ZodObject<{
96
113
  version: z.ZodNullable<z.ZodString>;
97
114
  model: z.ZodNullable<z.ZodString>;
98
115
  effort: z.ZodNullable<z.ZodString>;
116
+ version_source: z.ZodOptional<z.ZodEnum<{
117
+ cli: "cli";
118
+ package: "package";
119
+ transcript: "transcript";
120
+ none: "none";
121
+ }>>;
122
+ model_basis: z.ZodOptional<z.ZodEnum<{
123
+ set: "set";
124
+ none: "none";
125
+ used: "used";
126
+ }>>;
127
+ effort_basis: z.ZodOptional<z.ZodEnum<{
128
+ set: "set";
129
+ default: "default";
130
+ none: "none";
131
+ observed: "observed";
132
+ }>>;
99
133
  skills: z.ZodNullable<z.ZodArray<z.ZodString>>;
100
134
  plugins: z.ZodNullable<z.ZodArray<z.ZodString>>;
101
135
  agents: z.ZodNullable<z.ZodArray<z.ZodString>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",