@bli-cockpit/telemetry-core 0.1.67 → 0.1.69
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.
- package/dist/evidence-upload.d.ts +31 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/log-digest/index.d.ts +1 -1
- package/dist/log-digest/index.js +1 -1
- package/dist/log-digest/log-projects.js +20 -2
- package/dist/log-digest/stored.d.ts +5 -0
- package/dist/log-digest/stored.js +6 -0
- package/dist/session-facts-skills.d.ts +72 -0
- package/dist/session-facts-skills.js +201 -0
- package/dist/session-facts-spawn.d.ts +41 -0
- package/dist/session-facts-spawn.js +50 -0
- package/dist/session-facts.d.ts +26 -0
- package/dist/session-facts.js +16 -1
- package/package.json +1 -1
|
@@ -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,6 +584,20 @@ 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>>>;
|
|
593
|
+
spawn: z.ZodOptional<z.ZodObject<{
|
|
594
|
+
kind: z.ZodEnum<{
|
|
595
|
+
interactive: "interactive";
|
|
596
|
+
worker: "worker";
|
|
597
|
+
subagent: "subagent";
|
|
598
|
+
}>;
|
|
599
|
+
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
600
|
+
}, z.core.$strict>>;
|
|
587
601
|
}, z.core.$strict>>;
|
|
588
602
|
session_file_mtime: z.ZodOptional<z.ZodString>;
|
|
589
603
|
repo_fingerprint: z.ZodOptional<z.ZodString>;
|
|
@@ -693,6 +707,20 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
|
|
|
693
707
|
transcript_files: z.ZodNumber;
|
|
694
708
|
truncated_models: z.ZodNumber;
|
|
695
709
|
truncated_tool_names: z.ZodNumber;
|
|
710
|
+
skill_use: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
711
|
+
skill: z.ZodString;
|
|
712
|
+
plugin: z.ZodNullable<z.ZodString>;
|
|
713
|
+
by_person: z.ZodNumber;
|
|
714
|
+
by_agent: z.ZodNumber;
|
|
715
|
+
}, z.core.$strict>>>;
|
|
716
|
+
spawn: z.ZodOptional<z.ZodObject<{
|
|
717
|
+
kind: z.ZodEnum<{
|
|
718
|
+
interactive: "interactive";
|
|
719
|
+
worker: "worker";
|
|
720
|
+
subagent: "subagent";
|
|
721
|
+
}>;
|
|
722
|
+
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
723
|
+
}, z.core.$strict>>;
|
|
696
724
|
}, z.core.$strict>>;
|
|
697
725
|
session_file_mtime: z.ZodOptional<z.ZodString>;
|
|
698
726
|
repo_fingerprint: z.ZodOptional<z.ZodString>;
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ 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";
|
|
29
|
+
export * from "./session-facts-spawn.js";
|
|
28
30
|
export * from "./source-adapter.js";
|
|
29
31
|
export * from "./ticket-id.js";
|
|
30
32
|
export * from "./trace-sink.js";
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ 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";
|
|
29
|
+
export * from "./session-facts-spawn.js";
|
|
28
30
|
export * from "./source-adapter.js";
|
|
29
31
|
export * from "./ticket-id.js";
|
|
30
32
|
export * from "./trace-sink.js";
|
|
@@ -13,7 +13,7 @@ export { readCollector, receiptLine, streamLines, windowShare } from "./sources/
|
|
|
13
13
|
export { RAILWAY_ENVIRONMENT, RAILWAY_PROJECT_ID, railwayRefusal, readRailway } from "./sources/railway.js";
|
|
14
14
|
export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRecordLines, vercelRefusal, type VercelClasses, type VercelRecord } from "./sources/vercel.js";
|
|
15
15
|
export { readStdin } from "./sources/stdin.js";
|
|
16
|
-
export { LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, type DigestedLines, type StillRefusing, type StoredMerge, type StoredRow, type StoredWindow, type UnreadableSource, } from "./stored.js";
|
|
16
|
+
export { BLIND_TEMPLATE_PREFIX, LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, type DigestedLines, type StillRefusing, type StoredMerge, type StoredRow, type StoredWindow, type UnreadableSource, } from "./stored.js";
|
|
17
17
|
export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
|
|
18
18
|
export { BRAIN_PROJECT_IDS, LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, brainRouteFor, findLogProject, type BrainConfig, type BrainMergePolicy, type BrainRoute, type GcpSource, type LogProject, type LogSource, type NotWiredSource, type RailwaySource, type SupabaseSource, type SupabaseStream, type VercelSource, } from "./log-projects.js";
|
|
19
19
|
export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
|
package/dist/log-digest/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export { readCollector, receiptLine, streamLines, windowShare } from "./sources/
|
|
|
13
13
|
export { RAILWAY_ENVIRONMENT, RAILWAY_PROJECT_ID, railwayRefusal, readRailway } from "./sources/railway.js";
|
|
14
14
|
export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRecordLines, vercelRefusal } from "./sources/vercel.js";
|
|
15
15
|
export { readStdin } from "./sources/stdin.js";
|
|
16
|
-
export { LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, } from "./stored.js";
|
|
16
|
+
export { BLIND_TEMPLATE_PREFIX, LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, } from "./stored.js";
|
|
17
17
|
export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
|
|
18
18
|
export { BRAIN_PROJECT_IDS, LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, brainRouteFor, findLogProject, } from "./log-projects.js";
|
|
19
19
|
export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
|
|
@@ -81,6 +81,9 @@ export const LOG_PROJECTS = [
|
|
|
81
81
|
// The website's own Supabase project, not Pearl Portal's (named in the Pearl Portal session's handoff on ticket 12860).
|
|
82
82
|
supabase("blue-pearl-website", "wcdvrwqwnhbsqtyoqrot"),
|
|
83
83
|
],
|
|
84
|
+
// Both Vercel projects are git-linked to BLI-INC/blue-pearl-landing-page (`vercel api /v9/projects`, 2026-10-08). Its AGENTS.md:
|
|
85
|
+
// a merge to `main` is a deploy of the live site and the Supabase dry-run check is the merge gate, so the brain stops at the PR.
|
|
86
|
+
brain: { repos: { default: "BLI-INC/blue-pearl-landing-page" }, base_branch: "main", merge: "pr_only", daily_runs: 2 },
|
|
84
87
|
},
|
|
85
88
|
{
|
|
86
89
|
id: "pearl-portal",
|
|
@@ -92,7 +95,7 @@ export const LOG_PROJECTS = [
|
|
|
92
95
|
// read-only service account tower-logs-reader@buildlaunchiterate (roles/logging.viewer). Its staging service,
|
|
93
96
|
// staging-bluepearlmortgage, exists but is unused: never registered.
|
|
94
97
|
gcpCloudRun("buildlaunchiterate", "blue-pearl-mortgage"),
|
|
95
|
-
notWired("sentry:build-launch-iterate/javascript-nextjs", "sentry", "sentry_token_not_mintable: the Pearl frontend also reports to Sentry (org build-launch-iterate, project javascript-nextjs); a read-only internal-integration token (event:read, project:read, org:read) needs org-level write that the existing Sentry login lacks (creating the integration answered 403), so no token was minted and Edward's broader personal token was not copied;
|
|
98
|
+
notWired("sentry:build-launch-iterate/javascript-nextjs", "sentry", "sentry_token_not_mintable: the Pearl frontend also reports to Sentry (org build-launch-iterate, project javascript-nextjs); a read-only internal-integration token (event:read, project:read, org:read) needs org-level write that the existing Sentry login lacks (creating the integration answered 403), so no token was minted and Edward's broader personal token was not copied. Probed 2026-10-08: the only Sentry credential on a Vercel project that reaches this org is the Pearl frontend's own SENTRY_AUTH_TOKEN (a build token), and it answers 403 on the organization, the project, its issues and its events; the Tower dashboard's is write-only; PortPal's project has none. Create the integration in Sentry settings, then register the source"),
|
|
96
99
|
],
|
|
97
100
|
// Both repos' AGENTS.md say "Do not auto-merge. Stop at PR unless user says merge" (read 2026-10-07), so pr_only. A line
|
|
98
101
|
// from the Cloud Run backend is fixed in its own repo; every other source is the frontend.
|
|
@@ -108,8 +111,11 @@ export const LOG_PROJECTS = [
|
|
|
108
111
|
name: "Triage OCR",
|
|
109
112
|
sources: [
|
|
110
113
|
vercel("triage-ocr", "prj_649ktBEpFEkkd46MFAbIFRml55N3"),
|
|
111
|
-
notWired("supabase:triage-ocr", "supabase", "the repo's Supabase ref (xdcheixvpvanblntpisx) is in no Supabase organization the Tower login can read
|
|
114
|
+
notWired("supabase:triage-ocr", "supabase", "owner unknown, dropped by Edward 2026-10-08: the repo's Supabase ref (xdcheixvpvanblntpisx) is in no Supabase organization the Tower login can read"),
|
|
112
115
|
],
|
|
116
|
+
// Git-linked to BLI-INC/triage-ocr (production branch main). Its CLAUDE.md says every change to main is a pull request behind
|
|
117
|
+
// required checks and never authorises an agent to merge, so the brain stops at the PR.
|
|
118
|
+
brain: { repos: { default: "BLI-INC/triage-ocr" }, base_branch: "main", merge: "pr_only", daily_runs: 2 },
|
|
113
119
|
},
|
|
114
120
|
{
|
|
115
121
|
id: "triage-crm",
|
|
@@ -118,6 +124,10 @@ export const LOG_PROJECTS = [
|
|
|
118
124
|
vercel("triage-engine", "prj_PYzJea8t6bgMeUlHGZnwNFklH7GU"),
|
|
119
125
|
supabase("Triage-CRM", "qpzgytjwjgyvevtmrjai"),
|
|
120
126
|
],
|
|
127
|
+
// The Vercel project triage-engine (root apps/web) is git-linked to BLI-INC/Triage_Engine; its settings name feat/web-base as
|
|
128
|
+
// the production branch but every production deployment of 2026-10-05 came from `main`, which is the repo's default branch.
|
|
129
|
+
// No AGENTS.md merge permission, so the brain stops at the PR.
|
|
130
|
+
brain: { repos: { default: "BLI-INC/Triage_Engine" }, base_branch: "main", merge: "pr_only", daily_runs: 2 },
|
|
121
131
|
},
|
|
122
132
|
{
|
|
123
133
|
id: "kolm",
|
|
@@ -147,6 +157,9 @@ export const LOG_PROJECTS = [
|
|
|
147
157
|
vercel("bkt-reply-copilot", "prj_zvDt2gD4N69hMpU7zfzgNBFlDhgR"),
|
|
148
158
|
supabase("Black Knight Tire", "lvfxhppyzfnvooerblrz"),
|
|
149
159
|
],
|
|
160
|
+
// NO brain block, on purpose (2026-10-08): the marketplace Vercel project has no git link (CLI deploys), and the repo's AGENTS.md
|
|
161
|
+
// says `origin/main` is only the Next.js bootstrap and "choosing the shared trunk is an open decision with Edward". Only
|
|
162
|
+
// vercel:bkt-reply-copilot has a repo (BLI-INC/bkt-marketplace-assistant, main). Add the block once the trunk is chosen.
|
|
150
163
|
},
|
|
151
164
|
{
|
|
152
165
|
id: "sublimation-squad",
|
|
@@ -155,6 +168,9 @@ export const LOG_PROJECTS = [
|
|
|
155
168
|
vercel("sublimation", "prj_CK3YtimGeLZoEbk66Tzr9SVbayWH"),
|
|
156
169
|
supabase("Sublimation-Website", "jlfrjgqvevdnyilkpoue"),
|
|
157
170
|
],
|
|
171
|
+
// Git-linked to BLI-INC/sublimation-squad, whose production branch and default branch are `master`. Its CLAUDE.md applies
|
|
172
|
+
// migrations on merge to `master` and has no agent merge permission, so the brain stops at the PR.
|
|
173
|
+
brain: { repos: { default: "BLI-INC/sublimation-squad" }, base_branch: "master", merge: "pr_only", daily_runs: 2 },
|
|
158
174
|
},
|
|
159
175
|
{
|
|
160
176
|
id: "bli-website",
|
|
@@ -163,6 +179,8 @@ export const LOG_PROJECTS = [
|
|
|
163
179
|
vercel("bli-website", "prj_7CvxylNLGAFeUeWzEXY7lYjHllIs"),
|
|
164
180
|
vercel("buildlaunchiterate", "prj_Tk79luzslERUZyA8xuGvciVBdPhX"),
|
|
165
181
|
],
|
|
182
|
+
// Both Vercel projects are git-linked to BLI-INC/bli-website (production branch main); no agent merge permission in its CLAUDE.md.
|
|
183
|
+
brain: { repos: { default: "BLI-INC/bli-website" }, base_branch: "main", merge: "pr_only", daily_runs: 2 },
|
|
166
184
|
},
|
|
167
185
|
{
|
|
168
186
|
id: "keep-downloader",
|
|
@@ -22,6 +22,11 @@ export declare const LOCAL_ACCESS_REFUSALS: ReadonlySet<string>;
|
|
|
22
22
|
/** A window keeps at most this many templates; the rest are counted, never silently lost. */
|
|
23
23
|
export declare const STORED_MAX_TEMPLATES_PER_WINDOW = 200;
|
|
24
24
|
/** One template in one window of one source of one project. Metadata only: the example is redacted and cut. */
|
|
25
|
+
/**
|
|
26
|
+
* The start of the template of a digest-made incident that says a source could not be read at all (BLI-13068). The incident step
|
|
27
|
+
* writes it; the orchestrator's open-incident read leaves it out, because a session cannot set a platform token.
|
|
28
|
+
*/
|
|
29
|
+
export declare const BLIND_TEMPLATE_PREFIX = "log source unreadable: ";
|
|
25
30
|
export interface StoredRow {
|
|
26
31
|
project: string;
|
|
27
32
|
source: string;
|
|
@@ -26,6 +26,12 @@ export const LOCAL_ACCESS_REFUSALS = new Set([
|
|
|
26
26
|
]);
|
|
27
27
|
/** A window keeps at most this many templates; the rest are counted, never silently lost. */
|
|
28
28
|
export const STORED_MAX_TEMPLATES_PER_WINDOW = 200;
|
|
29
|
+
/** One template in one window of one source of one project. Metadata only: the example is redacted and cut. */
|
|
30
|
+
/**
|
|
31
|
+
* The start of the template of a digest-made incident that says a source could not be read at all (BLI-13068). The incident step
|
|
32
|
+
* writes it; the orchestrator's open-incident read leaves it out, because a session cannot set a platform token.
|
|
33
|
+
*/
|
|
34
|
+
export const BLIND_TEMPLATE_PREFIX = "log source unreadable: ";
|
|
29
35
|
const iso = (epoch) => (epoch ? new Date(epoch * 1000).toISOString() : null);
|
|
30
36
|
/** Digests one window's lines and classifies every template with the project's table. */
|
|
31
37
|
export function digestLines(lines, options) {
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who started a session (BLI-13066): a person, or a program acting for one.
|
|
3
|
+
*
|
|
4
|
+
* Setup judges a person's yield on their own (orchestrator) sessions. A
|
|
5
|
+
* headless `claude -p` run, a `codex exec` worker, a grader or a spawned
|
|
6
|
+
* subagent is never judged alone; its verdict goes to the parent. The marker is
|
|
7
|
+
* read from the first main-transcript metadata record, once, and carries ids
|
|
8
|
+
* and a kind word only.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
/** `interactive` is a person's session; `worker` and `subagent` were started by a program. */
|
|
12
|
+
export type SessionSpawnKind = "interactive" | "worker" | "subagent";
|
|
13
|
+
export interface SessionSpawn {
|
|
14
|
+
kind: SessionSpawnKind;
|
|
15
|
+
/** The parent session's id when the transcript names one (Codex `parent_thread_id`, `forked_from_id`). */
|
|
16
|
+
parent_session_id?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const SessionSpawnSchema: z.ZodObject<{
|
|
19
|
+
kind: z.ZodEnum<{
|
|
20
|
+
interactive: "interactive";
|
|
21
|
+
worker: "worker";
|
|
22
|
+
subagent: "subagent";
|
|
23
|
+
}>;
|
|
24
|
+
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
/**
|
|
27
|
+
* Claude Code writes `entrypoint` on its records: `cli` for a person typing in
|
|
28
|
+
* the terminal, `sdk-cli` (and other `sdk-*`) for a program driving it, such as
|
|
29
|
+
* `claude -p`. Measured on 885 transcripts from one week on one machine: 830
|
|
30
|
+
* were `sdk-cli`, every one a single prompt with no tool call; the 54 `cli`
|
|
31
|
+
* ones were the real working sessions. A subagent's own records (isSidechain)
|
|
32
|
+
* never decide it, because they ride inside their parent's session.
|
|
33
|
+
*/
|
|
34
|
+
export declare function claudeSpawn(current: SessionSpawn | null, record: Record<string, unknown>): SessionSpawn | null;
|
|
35
|
+
/**
|
|
36
|
+
* Codex writes who started a session in its first `session_meta`: `source` is
|
|
37
|
+
* `exec` for `codex exec`, `cli` or `vscode` for a person, or an object
|
|
38
|
+
* `{subagent: ...}` for a spawned subagent; `originator` is `codex_exec` for a
|
|
39
|
+
* program-driven run; `parent_thread_id` and `forked_from_id` name a parent.
|
|
40
|
+
*/
|
|
41
|
+
export declare function codexSpawn(current: SessionSpawn | null, meta: Record<string, unknown>): SessionSpawn | null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who started a session (BLI-13066): a person, or a program acting for one.
|
|
3
|
+
*
|
|
4
|
+
* Setup judges a person's yield on their own (orchestrator) sessions. A
|
|
5
|
+
* headless `claude -p` run, a `codex exec` worker, a grader or a spawned
|
|
6
|
+
* subagent is never judged alone; its verdict goes to the parent. The marker is
|
|
7
|
+
* read from the first main-transcript metadata record, once, and carries ids
|
|
8
|
+
* and a kind word only.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
const SPAWN_ID = /^[A-Za-z0-9._-]{1,80}$/u;
|
|
12
|
+
const spawnId = (value) => typeof value === "string" && SPAWN_ID.test(value) ? value : undefined;
|
|
13
|
+
export const SessionSpawnSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
kind: z.enum(["interactive", "worker", "subagent"]),
|
|
16
|
+
parent_session_id: z.string().regex(SPAWN_ID).optional(),
|
|
17
|
+
})
|
|
18
|
+
.strict();
|
|
19
|
+
/**
|
|
20
|
+
* Claude Code writes `entrypoint` on its records: `cli` for a person typing in
|
|
21
|
+
* the terminal, `sdk-cli` (and other `sdk-*`) for a program driving it, such as
|
|
22
|
+
* `claude -p`. Measured on 885 transcripts from one week on one machine: 830
|
|
23
|
+
* were `sdk-cli`, every one a single prompt with no tool call; the 54 `cli`
|
|
24
|
+
* ones were the real working sessions. A subagent's own records (isSidechain)
|
|
25
|
+
* never decide it, because they ride inside their parent's session.
|
|
26
|
+
*/
|
|
27
|
+
export function claudeSpawn(current, record) {
|
|
28
|
+
if (current || record["isSidechain"] === true)
|
|
29
|
+
return current;
|
|
30
|
+
const entrypoint = record["entrypoint"];
|
|
31
|
+
if (typeof entrypoint !== "string" || !entrypoint)
|
|
32
|
+
return current;
|
|
33
|
+
return { kind: entrypoint === "cli" ? "interactive" : "worker" };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Codex writes who started a session in its first `session_meta`: `source` is
|
|
37
|
+
* `exec` for `codex exec`, `cli` or `vscode` for a person, or an object
|
|
38
|
+
* `{subagent: ...}` for a spawned subagent; `originator` is `codex_exec` for a
|
|
39
|
+
* program-driven run; `parent_thread_id` and `forked_from_id` name a parent.
|
|
40
|
+
*/
|
|
41
|
+
export function codexSpawn(current, meta) {
|
|
42
|
+
if (current)
|
|
43
|
+
return current;
|
|
44
|
+
const source = meta["source"];
|
|
45
|
+
const spawnedSubagent = (source !== null && typeof source === "object" && "subagent" in source) || spawnId(meta["parent_thread_id"]) !== undefined;
|
|
46
|
+
const exec = meta["originator"] === "codex_exec" || source === "exec";
|
|
47
|
+
const parent = spawnId(meta["parent_thread_id"]) ?? spawnId(meta["forked_from_id"]);
|
|
48
|
+
const kind = spawnedSubagent ? "subagent" : exec ? "worker" : "interactive";
|
|
49
|
+
return { kind, ...(parent ? { parent_session_id: parent } : {}) };
|
|
50
|
+
}
|
package/dist/session-facts.d.ts
CHANGED
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
* Anthropic-shaped usage the price table expects.
|
|
36
36
|
*/
|
|
37
37
|
import { z } from "zod";
|
|
38
|
+
import { type SessionSpawn } from "./session-facts-spawn.js";
|
|
39
|
+
import { SkillUseTally } from "./session-facts-skills.js";
|
|
40
|
+
import type { SkillUseCount } from "./session-facts-skills.js";
|
|
38
41
|
/** Bump when a counting rule changes, never when a field is added. */
|
|
39
42
|
export declare const SESSION_FACTS_VERSION = "det.v6";
|
|
40
43
|
/** How many distinct models and tool names one session may report. */
|
|
@@ -77,6 +80,13 @@ export interface SessionFacts {
|
|
|
77
80
|
truncated_models: number;
|
|
78
81
|
/** Distinct tool names dropped by the cap. */
|
|
79
82
|
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
|
+
*/
|
|
87
|
+
skill_use?: SkillUseCount[];
|
|
88
|
+
/** BLI-13066: who started the session (`session-facts-spawn.ts`). Absent from a block a CLI published before this field. */
|
|
89
|
+
spawn?: SessionSpawn;
|
|
80
90
|
}
|
|
81
91
|
export interface SessionFactsAccumulator {
|
|
82
92
|
source: SessionFactsSource;
|
|
@@ -94,6 +104,8 @@ export interface SessionFactsAccumulator {
|
|
|
94
104
|
/** Codex only: the newest cumulative total and the model to attribute it to. */
|
|
95
105
|
codex_total_usage: Record<string, unknown> | null;
|
|
96
106
|
codex_model_hint: string | null;
|
|
107
|
+
skill_tally: SkillUseTally;
|
|
108
|
+
spawn: SessionSpawn | null;
|
|
97
109
|
}
|
|
98
110
|
export declare function newSessionFactsAccumulator(source: SessionFactsSource): SessionFactsAccumulator;
|
|
99
111
|
/** One transcript file's size, for callers that never hold its whole text. */
|
|
@@ -172,6 +184,20 @@ export declare const SessionFactsSchema: z.ZodObject<{
|
|
|
172
184
|
transcript_files: z.ZodNumber;
|
|
173
185
|
truncated_models: z.ZodNumber;
|
|
174
186
|
truncated_tool_names: z.ZodNumber;
|
|
187
|
+
skill_use: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
188
|
+
skill: z.ZodString;
|
|
189
|
+
plugin: z.ZodNullable<z.ZodString>;
|
|
190
|
+
by_person: z.ZodNumber;
|
|
191
|
+
by_agent: z.ZodNumber;
|
|
192
|
+
}, z.core.$strict>>>;
|
|
193
|
+
spawn: z.ZodOptional<z.ZodObject<{
|
|
194
|
+
kind: z.ZodEnum<{
|
|
195
|
+
interactive: "interactive";
|
|
196
|
+
worker: "worker";
|
|
197
|
+
subagent: "subagent";
|
|
198
|
+
}>;
|
|
199
|
+
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
200
|
+
}, z.core.$strict>>;
|
|
175
201
|
}, z.core.$strict>;
|
|
176
202
|
export type SessionFactsWire = z.infer<typeof SessionFactsSchema>;
|
|
177
203
|
export { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText, normalizeTurnText, textFromPlainTextBlocks, } from "./session-facts-text.js";
|
package/dist/session-facts.js
CHANGED
|
@@ -35,7 +35,9 @@
|
|
|
35
35
|
* Anthropic-shaped usage the price table expects.
|
|
36
36
|
*/
|
|
37
37
|
import { z } from "zod";
|
|
38
|
-
import { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText
|
|
38
|
+
import { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText } from "./session-facts-text.js";
|
|
39
|
+
import { claudeSpawn, codexSpawn, SessionSpawnSchema } from "./session-facts-spawn.js";
|
|
40
|
+
import { observeClaudeSkillUse, observeCodexSkillUse, SKILL_USE_MAX_SKILLS, SkillUseCountSchema, SkillUseTally } from "./session-facts-skills.js";
|
|
39
41
|
/** Bump when a counting rule changes, never when a field is added. */
|
|
40
42
|
export const SESSION_FACTS_VERSION = "det.v6";
|
|
41
43
|
/** How many distinct models and tool names one session may report. */
|
|
@@ -59,6 +61,8 @@ export function newSessionFactsAccumulator(source) {
|
|
|
59
61
|
transcript_files: 0,
|
|
60
62
|
codex_total_usage: null,
|
|
61
63
|
codex_model_hint: null,
|
|
64
|
+
skill_tally: new SkillUseTally(),
|
|
65
|
+
spawn: null,
|
|
62
66
|
};
|
|
63
67
|
}
|
|
64
68
|
/** One transcript file's size, for callers that never hold its whole text. */
|
|
@@ -84,12 +88,14 @@ export function observeSessionFactsRecord(acc, record) {
|
|
|
84
88
|
}
|
|
85
89
|
function observeClaudeRecord(acc, record) {
|
|
86
90
|
const type = typeof record["type"] === "string" ? record["type"] : "";
|
|
91
|
+
acc.spawn = claudeSpawn(acc.spawn, record);
|
|
87
92
|
if (type === "user") {
|
|
88
93
|
if (record["isMeta"] === true)
|
|
89
94
|
return;
|
|
90
95
|
const text = claudeUserTurnText(record);
|
|
91
96
|
if (text?.trim())
|
|
92
97
|
acc.user_prompt_count += 1;
|
|
98
|
+
observeClaudeSkillUse(acc.skill_tally, record);
|
|
93
99
|
return;
|
|
94
100
|
}
|
|
95
101
|
if (type !== "assistant")
|
|
@@ -122,11 +128,14 @@ function observeClaudeRecord(acc, record) {
|
|
|
122
128
|
continue;
|
|
123
129
|
countTool(acc, typeof b["name"] === "string" ? b["name"] : "unknown");
|
|
124
130
|
}
|
|
131
|
+
observeClaudeSkillUse(acc.skill_tally, record);
|
|
125
132
|
}
|
|
126
133
|
function observeCodexRecord(acc, record) {
|
|
127
134
|
const type = String(record["type"] ?? "");
|
|
128
135
|
const payload = record["payload"];
|
|
129
136
|
const p = payload && typeof payload === "object" ? payload : {};
|
|
137
|
+
if (type === "session_meta")
|
|
138
|
+
return void (acc.spawn = codexSpawn(acc.spawn, p));
|
|
130
139
|
if (type === "turn_context") {
|
|
131
140
|
if (typeof p["model"] === "string")
|
|
132
141
|
acc.codex_model_hint = p["model"];
|
|
@@ -137,6 +146,7 @@ function observeCodexRecord(acc, record) {
|
|
|
137
146
|
if ((itemType === "message" || itemType === "user_message") && p["role"] === "user") {
|
|
138
147
|
if (codexUserTurnText(p)?.trim())
|
|
139
148
|
acc.user_prompt_count += 1;
|
|
149
|
+
observeCodexSkillUse(acc.skill_tally, p);
|
|
140
150
|
return;
|
|
141
151
|
}
|
|
142
152
|
if (itemType === "message" && p["role"] === "assistant") {
|
|
@@ -147,6 +157,7 @@ function observeCodexRecord(acc, record) {
|
|
|
147
157
|
if (itemType === "function_call") {
|
|
148
158
|
countTool(acc, typeof p["name"] === "string" ? p["name"] : "unknown");
|
|
149
159
|
}
|
|
160
|
+
observeCodexSkillUse(acc.skill_tally, p);
|
|
150
161
|
return;
|
|
151
162
|
}
|
|
152
163
|
if (type !== "event_msg")
|
|
@@ -237,6 +248,8 @@ export function finalizeSessionFacts(acc) {
|
|
|
237
248
|
transcript_files: acc.transcript_files,
|
|
238
249
|
truncated_models: usageEntries.length - keptUsage.length,
|
|
239
250
|
truncated_tool_names: toolEntries.length - keptTools.length,
|
|
251
|
+
skill_use: acc.skill_tally.toList().slice(0, SKILL_USE_MAX_SKILLS),
|
|
252
|
+
...(acc.spawn ? { spawn: acc.spawn } : {}),
|
|
240
253
|
};
|
|
241
254
|
}
|
|
242
255
|
/**
|
|
@@ -351,6 +364,8 @@ export const SessionFactsSchema = z
|
|
|
351
364
|
transcript_files: z.number().int().nonnegative(),
|
|
352
365
|
truncated_models: z.number().int().nonnegative(),
|
|
353
366
|
truncated_tool_names: z.number().int().nonnegative(),
|
|
367
|
+
skill_use: z.array(SkillUseCountSchema).max(SKILL_USE_MAX_SKILLS).optional(),
|
|
368
|
+
spawn: SessionSpawnSchema.optional(),
|
|
354
369
|
})
|
|
355
370
|
.strict();
|
|
356
371
|
export { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText, normalizeTurnText, textFromPlainTextBlocks, } from "./session-facts-text.js";
|