@bli-cockpit/telemetry-core 0.1.68 → 0.1.70

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.
@@ -590,6 +590,14 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
590
590
  by_person: z.ZodNumber;
591
591
  by_agent: z.ZodNumber;
592
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>>;
593
601
  }, z.core.$strict>>;
594
602
  session_file_mtime: z.ZodOptional<z.ZodString>;
595
603
  repo_fingerprint: z.ZodOptional<z.ZodString>;
@@ -705,6 +713,14 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
705
713
  by_person: z.ZodNumber;
706
714
  by_agent: z.ZodNumber;
707
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>>;
708
724
  }, z.core.$strict>>;
709
725
  session_file_mtime: z.ZodOptional<z.ZodString>;
710
726
  repo_fingerprint: z.ZodOptional<z.ZodString>;
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export * from "./run-verdict.js";
26
26
  export * from "./secret-guards.js";
27
27
  export * from "./session-facts.js";
28
28
  export * from "./session-facts-skills.js";
29
+ export * from "./session-facts-spawn.js";
29
30
  export * from "./source-adapter.js";
30
31
  export * from "./ticket-id.js";
31
32
  export * from "./trace-sink.js";
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ export * from "./run-verdict.js";
26
26
  export * from "./secret-guards.js";
27
27
  export * from "./session-facts.js";
28
28
  export * from "./session-facts-skills.js";
29
+ export * from "./session-facts-spawn.js";
29
30
  export * from "./source-adapter.js";
30
31
  export * from "./ticket-id.js";
31
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
- 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";
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 PushSource, 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";
@@ -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";
@@ -70,7 +70,10 @@ export interface NotWiredSource extends SourceBase {
70
70
  /** Plain words: why nothing reads it, and what would. */
71
71
  reason: string;
72
72
  }
73
- export type LogSource = VercelSource | RailwaySource | SupabaseSource | GcpSource | NotWiredSource;
73
+ export interface PushSource extends SourceBase {
74
+ kind: "push";
75
+ }
76
+ export type LogSource = PushSource | VercelSource | RailwaySource | SupabaseSource | GcpSource | NotWiredSource;
74
77
  /**
75
78
  * How the brain may land a fix (BLI-12859). `on_green`: the PR gets auto-merge, which GitHub performs only once the
76
79
  * repo's own required checks pass. `pr_only`: the brain opens the PR and stops; a person merges.
@@ -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; create the integration in Sentry settings, then register the source"),
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, so its logs cannot be queried; add the ref once a token with access exists"),
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",
@@ -136,7 +146,7 @@ export const LOG_PROJECTS = [
136
146
  name: "Kaiben",
137
147
  sources: [
138
148
  supabase("kaiben-core", "ozwovnqtzdwptaeslrep"),
139
- notWired("droplet:kaiben-ridestyler", "droplet", "Kaiben's operator already writes a 15-minute fleet digest, but only as files on the droplet (/var/log/kaiben-operator/digest-latest.txt and digests/); there is no HTTP or API read, only ssh, which a Railway cron does not hold; the fix is for the operator to POST its digest to a Tower door"),
149
+ { kind: "push", source: "droplet:kaiben-ridestyler", family: "droplet" },
140
150
  ],
141
151
  },
142
152
  {
@@ -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,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
+ }
@@ -35,7 +35,9 @@
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
+ 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";
39
41
  /** Bump when a counting rule changes, never when a field is added. */
40
42
  export declare const SESSION_FACTS_VERSION = "det.v6";
41
43
  /** How many distinct models and tool names one session may report. */
@@ -83,6 +85,8 @@ export interface SessionFacts {
83
85
  * Names and counts only. Absent from a block a CLI published before this field.
84
86
  */
85
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;
86
90
  }
87
91
  export interface SessionFactsAccumulator {
88
92
  source: SessionFactsSource;
@@ -101,6 +105,7 @@ export interface SessionFactsAccumulator {
101
105
  codex_total_usage: Record<string, unknown> | null;
102
106
  codex_model_hint: string | null;
103
107
  skill_tally: SkillUseTally;
108
+ spawn: SessionSpawn | null;
104
109
  }
105
110
  export declare function newSessionFactsAccumulator(source: SessionFactsSource): SessionFactsAccumulator;
106
111
  /** One transcript file's size, for callers that never hold its whole text. */
@@ -185,6 +190,14 @@ export declare const SessionFactsSchema: z.ZodObject<{
185
190
  by_person: z.ZodNumber;
186
191
  by_agent: z.ZodNumber;
187
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>>;
188
201
  }, z.core.$strict>;
189
202
  export type SessionFactsWire = z.infer<typeof SessionFactsSchema>;
190
203
  export { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText, normalizeTurnText, textFromPlainTextBlocks, } from "./session-facts-text.js";
@@ -35,8 +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, } from "./session-facts-text.js";
39
- import { observeClaudeSkillUse, observeCodexSkillUse, SKILL_USE_MAX_SKILLS, SkillUseCountSchema, SkillUseTally, } from "./session-facts-skills.js";
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";
40
41
  /** Bump when a counting rule changes, never when a field is added. */
41
42
  export const SESSION_FACTS_VERSION = "det.v6";
42
43
  /** How many distinct models and tool names one session may report. */
@@ -61,6 +62,7 @@ export function newSessionFactsAccumulator(source) {
61
62
  codex_total_usage: null,
62
63
  codex_model_hint: null,
63
64
  skill_tally: new SkillUseTally(),
65
+ spawn: null,
64
66
  };
65
67
  }
66
68
  /** One transcript file's size, for callers that never hold its whole text. */
@@ -86,6 +88,7 @@ export function observeSessionFactsRecord(acc, record) {
86
88
  }
87
89
  function observeClaudeRecord(acc, record) {
88
90
  const type = typeof record["type"] === "string" ? record["type"] : "";
91
+ acc.spawn = claudeSpawn(acc.spawn, record);
89
92
  if (type === "user") {
90
93
  if (record["isMeta"] === true)
91
94
  return;
@@ -131,6 +134,8 @@ function observeCodexRecord(acc, record) {
131
134
  const type = String(record["type"] ?? "");
132
135
  const payload = record["payload"];
133
136
  const p = payload && typeof payload === "object" ? payload : {};
137
+ if (type === "session_meta")
138
+ return void (acc.spawn = codexSpawn(acc.spawn, p));
134
139
  if (type === "turn_context") {
135
140
  if (typeof p["model"] === "string")
136
141
  acc.codex_model_hint = p["model"];
@@ -244,6 +249,7 @@ export function finalizeSessionFacts(acc) {
244
249
  truncated_models: usageEntries.length - keptUsage.length,
245
250
  truncated_tool_names: toolEntries.length - keptTools.length,
246
251
  skill_use: acc.skill_tally.toList().slice(0, SKILL_USE_MAX_SKILLS),
252
+ ...(acc.spawn ? { spawn: acc.spawn } : {}),
247
253
  };
248
254
  }
249
255
  /**
@@ -359,6 +365,7 @@ export const SessionFactsSchema = z
359
365
  truncated_models: z.number().int().nonnegative(),
360
366
  truncated_tool_names: z.number().int().nonnegative(),
361
367
  skill_use: z.array(SkillUseCountSchema).max(SKILL_USE_MAX_SKILLS).optional(),
368
+ spawn: SessionSpawnSchema.optional(),
362
369
  })
363
370
  .strict();
364
371
  export { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText, normalizeTurnText, textFromPlainTextBlocks, } from "./session-facts-text.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.68",
3
+ "version": "0.1.70",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",