@bli-cockpit/telemetry-core 0.1.74 → 0.1.76
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 +40 -0
- package/dist/evidence-upload.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/log-digest/index.d.ts +2 -1
- package/dist/log-digest/index.js +1 -0
- package/dist/log-digest/log-projects.d.ts +15 -1
- package/dist/log-digest/log-projects.js +3 -0
- package/dist/log-digest/mask.js +25 -4
- package/dist/log-digest/remask.d.ts +6 -0
- package/dist/log-digest/remask.js +37 -0
- package/dist/session-client-app.d.ts +21 -0
- package/dist/session-client-app.js +51 -0
- package/dist/session-facts-active.d.ts +7 -0
- package/dist/session-facts-active.js +18 -0
- package/dist/session-facts-spawn.d.ts +36 -0
- package/dist/session-facts-spawn.js +50 -2
- package/dist/session-facts.d.ts +18 -10
- package/dist/session-facts.js +8 -6
- package/package.json +1 -1
|
@@ -257,6 +257,10 @@ export declare const RawEvidenceUploadBeginResponseObjectSchema: z.ZodObject<{
|
|
|
257
257
|
upload_id: z.ZodOptional<z.ZodString>;
|
|
258
258
|
received_chunk_indexes: z.ZodDefault<z.ZodArray<z.ZodNumber>>;
|
|
259
259
|
commit_ready: z.ZodOptional<z.ZodBoolean>;
|
|
260
|
+
signed_uploads: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
261
|
+
chunk_index: z.ZodNumber;
|
|
262
|
+
signed_url: z.ZodString;
|
|
263
|
+
}, z.core.$strict>>>;
|
|
260
264
|
reason: z.ZodOptional<z.ZodString>;
|
|
261
265
|
}, z.core.$strict>;
|
|
262
266
|
export type RawEvidenceUploadBeginResponseObject = z.infer<typeof RawEvidenceUploadBeginResponseObjectSchema>;
|
|
@@ -274,6 +278,10 @@ export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
|
|
|
274
278
|
upload_id: z.ZodOptional<z.ZodString>;
|
|
275
279
|
received_chunk_indexes: z.ZodDefault<z.ZodArray<z.ZodNumber>>;
|
|
276
280
|
commit_ready: z.ZodOptional<z.ZodBoolean>;
|
|
281
|
+
signed_uploads: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
282
|
+
chunk_index: z.ZodNumber;
|
|
283
|
+
signed_url: z.ZodString;
|
|
284
|
+
}, z.core.$strict>>>;
|
|
277
285
|
reason: z.ZodOptional<z.ZodString>;
|
|
278
286
|
}, z.core.$strict>>;
|
|
279
287
|
}, z.core.$strict>;
|
|
@@ -329,6 +337,11 @@ export declare const RawEvidenceUploadChunkResponseSchema: z.ZodObject<{
|
|
|
329
337
|
received_chunk_count: z.ZodNumber;
|
|
330
338
|
}, z.core.$strict>;
|
|
331
339
|
export type RawEvidenceUploadChunkResponse = z.infer<typeof RawEvidenceUploadChunkResponseSchema>;
|
|
340
|
+
export declare const RawEvidenceDirectChunkSchema: z.ZodObject<{
|
|
341
|
+
chunk_index: z.ZodNumber;
|
|
342
|
+
byte_size: z.ZodNumber;
|
|
343
|
+
chunk_hash_sha256: z.ZodString;
|
|
344
|
+
}, z.core.$strict>;
|
|
332
345
|
export declare const RawEvidenceUploadCommitRequestSchema: z.ZodObject<{
|
|
333
346
|
schema_version: z.ZodLiteral<"ambient-raw-evidence-upload-commit.v1">;
|
|
334
347
|
generated_at: z.ZodString;
|
|
@@ -363,6 +376,11 @@ export declare const RawEvidenceUploadCommitRequestSchema: z.ZodObject<{
|
|
|
363
376
|
}, z.core.$strict>;
|
|
364
377
|
upload_id: z.ZodString;
|
|
365
378
|
object_key: z.ZodString;
|
|
379
|
+
direct_chunks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
380
|
+
chunk_index: z.ZodNumber;
|
|
381
|
+
byte_size: z.ZodNumber;
|
|
382
|
+
chunk_hash_sha256: z.ZodString;
|
|
383
|
+
}, z.core.$strict>>>;
|
|
366
384
|
}, z.core.$strict>;
|
|
367
385
|
export type RawEvidenceUploadCommitRequest = z.infer<typeof RawEvidenceUploadCommitRequestSchema>;
|
|
368
386
|
export declare const RawEvidenceUploadCommitResponseSchema: z.ZodObject<{
|
|
@@ -579,6 +597,7 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
|
|
|
579
597
|
first_timestamp: z.ZodNullable<z.ZodString>;
|
|
580
598
|
last_timestamp: z.ZodNullable<z.ZodString>;
|
|
581
599
|
wall_duration_seconds: z.ZodNullable<z.ZodNumber>;
|
|
600
|
+
active_seconds: z.ZodOptional<z.ZodNumber>;
|
|
582
601
|
transcript_bytes: z.ZodNumber;
|
|
583
602
|
transcript_lines: z.ZodNumber;
|
|
584
603
|
transcript_files: z.ZodNumber;
|
|
@@ -596,6 +615,16 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
|
|
|
596
615
|
worker: "worker";
|
|
597
616
|
subagent: "subagent";
|
|
598
617
|
}>;
|
|
618
|
+
client_app: z.ZodOptional<z.ZodEnum<{
|
|
619
|
+
unknown: "unknown";
|
|
620
|
+
claude_cli: "claude_cli";
|
|
621
|
+
claude_desktop: "claude_desktop";
|
|
622
|
+
claude_ide: "claude_ide";
|
|
623
|
+
codex_cli: "codex_cli";
|
|
624
|
+
codex_desktop: "codex_desktop";
|
|
625
|
+
codex_ide: "codex_ide";
|
|
626
|
+
codex_exec: "codex_exec";
|
|
627
|
+
}>>;
|
|
599
628
|
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
600
629
|
}, z.core.$strict>>;
|
|
601
630
|
}, z.core.$strict>>;
|
|
@@ -702,6 +731,7 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
|
|
|
702
731
|
first_timestamp: z.ZodNullable<z.ZodString>;
|
|
703
732
|
last_timestamp: z.ZodNullable<z.ZodString>;
|
|
704
733
|
wall_duration_seconds: z.ZodNullable<z.ZodNumber>;
|
|
734
|
+
active_seconds: z.ZodOptional<z.ZodNumber>;
|
|
705
735
|
transcript_bytes: z.ZodNumber;
|
|
706
736
|
transcript_lines: z.ZodNumber;
|
|
707
737
|
transcript_files: z.ZodNumber;
|
|
@@ -719,6 +749,16 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
|
|
|
719
749
|
worker: "worker";
|
|
720
750
|
subagent: "subagent";
|
|
721
751
|
}>;
|
|
752
|
+
client_app: z.ZodOptional<z.ZodEnum<{
|
|
753
|
+
unknown: "unknown";
|
|
754
|
+
claude_cli: "claude_cli";
|
|
755
|
+
claude_desktop: "claude_desktop";
|
|
756
|
+
claude_ide: "claude_ide";
|
|
757
|
+
codex_cli: "codex_cli";
|
|
758
|
+
codex_desktop: "codex_desktop";
|
|
759
|
+
codex_ide: "codex_ide";
|
|
760
|
+
codex_exec: "codex_exec";
|
|
761
|
+
}>>;
|
|
722
762
|
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
723
763
|
}, z.core.$strict>>;
|
|
724
764
|
}, z.core.$strict>>;
|
package/dist/evidence-upload.js
CHANGED
|
@@ -112,6 +112,10 @@ export const RawEvidenceUploadBeginResponseObjectSchema = z
|
|
|
112
112
|
// A completed staged plan may use a chunk layout from an older collector.
|
|
113
113
|
// The client must commit it directly instead of mixing in its current plan.
|
|
114
114
|
commit_ready: z.boolean().optional(),
|
|
115
|
+
signed_uploads: z.array(z.object({
|
|
116
|
+
chunk_index: z.number().int().nonnegative(),
|
|
117
|
+
signed_url: z.string().url(),
|
|
118
|
+
}).strict()).optional(),
|
|
115
119
|
reason: SafeLabelSchema.optional(),
|
|
116
120
|
})
|
|
117
121
|
.strict();
|
|
@@ -147,6 +151,11 @@ export const RawEvidenceUploadChunkResponseSchema = z
|
|
|
147
151
|
received_chunk_count: z.number().int().nonnegative(),
|
|
148
152
|
})
|
|
149
153
|
.strict();
|
|
154
|
+
export const RawEvidenceDirectChunkSchema = z.object({
|
|
155
|
+
chunk_index: z.number().int().nonnegative(),
|
|
156
|
+
byte_size: z.number().int().positive().max(RAW_EVIDENCE_UPLOAD_MAX_CHUNK_BYTES),
|
|
157
|
+
chunk_hash_sha256: Sha256Schema,
|
|
158
|
+
}).strict();
|
|
150
159
|
export const RawEvidenceUploadCommitRequestSchema = z
|
|
151
160
|
.object({
|
|
152
161
|
schema_version: z.literal("ambient-raw-evidence-upload-commit.v1"),
|
|
@@ -154,6 +163,7 @@ export const RawEvidenceUploadCommitRequestSchema = z
|
|
|
154
163
|
provenance: CaptureProvenanceSchema,
|
|
155
164
|
upload_id: NonEmptyStringSchema,
|
|
156
165
|
object_key: NonEmptyStringSchema,
|
|
166
|
+
direct_chunks: z.array(RawEvidenceDirectChunkSchema).max(RAW_EVIDENCE_UPLOAD_MAX_CHUNK_COUNT).optional(),
|
|
157
167
|
})
|
|
158
168
|
.strict();
|
|
159
169
|
export const RawEvidenceUploadCommitResponseSchema = z
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export * from "./secret-guards.js";
|
|
|
30
30
|
export * from "./session-facts.js";
|
|
31
31
|
export * from "./session-facts-skills.js";
|
|
32
32
|
export * from "./session-facts-spawn.js";
|
|
33
|
+
export * from "./session-facts-active.js";
|
|
34
|
+
export * from "./session-client-app.js";
|
|
33
35
|
export * from "./source-adapter.js";
|
|
34
36
|
export * from "./ticket-id.js";
|
|
35
37
|
export * from "./trace-sink.js";
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,8 @@ export * from "./secret-guards.js";
|
|
|
30
30
|
export * from "./session-facts.js";
|
|
31
31
|
export * from "./session-facts-skills.js";
|
|
32
32
|
export * from "./session-facts-spawn.js";
|
|
33
|
+
export * from "./session-facts-active.js";
|
|
34
|
+
export * from "./session-client-app.js";
|
|
33
35
|
export * from "./source-adapter.js";
|
|
34
36
|
export * from "./ticket-id.js";
|
|
35
37
|
export * from "./trace-sink.js";
|
|
@@ -15,5 +15,6 @@ export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRecor
|
|
|
15
15
|
export { readStdin } from "./sources/stdin.js";
|
|
16
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 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";
|
|
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 DeploysSource, type DbHostSource, 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";
|
|
20
|
+
export { isStaleTemplate, remaskedTemplate, sameFailureUnderCurrentMask } from "./remask.js";
|
package/dist/log-digest/index.js
CHANGED
|
@@ -17,3 +17,4 @@ export { BLIND_TEMPLATE_PREFIX, LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_
|
|
|
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";
|
|
20
|
+
export { isStaleTemplate, remaskedTemplate, sameFailureUnderCurrentMask } from "./remask.js";
|
|
@@ -63,6 +63,20 @@ export interface GcpSource extends SourceBase {
|
|
|
63
63
|
/** The unit prefix of every line. */
|
|
64
64
|
unit_prefix: string;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Deploy and build records (BLI-20772): every Railway deployment of the project and the Vercel deployments of its dashboard,
|
|
68
|
+
* written by the `platform-watch` service into `deploy_records` and `platform_events`. Read by the digest cron as an alert-style
|
|
69
|
+
* unit (already judged by the watcher) and by `cockpit logs search --source deploys`.
|
|
70
|
+
*/
|
|
71
|
+
export interface DeploysSource extends SourceBase {
|
|
72
|
+
kind: "deploys";
|
|
73
|
+
}
|
|
74
|
+
/** Database host health (BLI-20724): one sample a minute and the restarts, in `db_host_samples` and `platform_events`. */
|
|
75
|
+
export interface DbHostSource extends SourceBase {
|
|
76
|
+
kind: "db_host";
|
|
77
|
+
/** The Supabase project ref whose host is sampled. */
|
|
78
|
+
ref: string;
|
|
79
|
+
}
|
|
66
80
|
export interface NotWiredSource extends SourceBase {
|
|
67
81
|
kind: "not_wired";
|
|
68
82
|
/** The platform it would be read from. */
|
|
@@ -73,7 +87,7 @@ export interface NotWiredSource extends SourceBase {
|
|
|
73
87
|
export interface PushSource extends SourceBase {
|
|
74
88
|
kind: "push";
|
|
75
89
|
}
|
|
76
|
-
export type LogSource = PushSource | VercelSource | RailwaySource | SupabaseSource | GcpSource | NotWiredSource;
|
|
90
|
+
export type LogSource = PushSource | VercelSource | RailwaySource | SupabaseSource | GcpSource | DeploysSource | DbHostSource | NotWiredSource;
|
|
77
91
|
/**
|
|
78
92
|
* How the brain may land a fix (BLI-12859). `on_green`: the PR gets auto-merge, which GitHub performs only once the
|
|
79
93
|
* repo's own required checks pass. `pr_only`: the brain opens the PR and stops; a person merges.
|
|
@@ -55,6 +55,9 @@ export const LOG_PROJECTS = [
|
|
|
55
55
|
vercel("bli-cockpit-dashboard", "prj_tKAQTQFCCBIXfnEJWvAbMGAqJjuN", { unit_prefix: "dashboard", family: "dashboard" }),
|
|
56
56
|
{ kind: "railway", source: "railway:bli-cockpit-inference", family: "railway", ...TOWER_RAILWAY },
|
|
57
57
|
supabase("BLI-Cockpit", "bnwolptxyrjalnppqyaf"),
|
|
58
|
+
// BLI-20772 / BLI-20724: written by the `platform-watch` service, aggregated by the digest cron like every other source.
|
|
59
|
+
{ kind: "deploys", source: "deploys:tower", family: "deploys" },
|
|
60
|
+
{ kind: "db_host", source: "db-host:tower", family: "db_host", ref: "bnwolptxyrjalnppqyaf" },
|
|
58
61
|
],
|
|
59
62
|
// AGENTS.md "Velocity": merge on green without asking. `main`'s ruleset requires its checks and allows squash only.
|
|
60
63
|
brain: { repos: { default: "BLI-INC/bli-cockpit" }, base_branch: "main", merge: "on_green", daily_runs: 10 },
|
package/dist/log-digest/mask.js
CHANGED
|
@@ -7,9 +7,15 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Fixed masking order, so a memory address can never fake a status code
|
|
9
9
|
* (`0x7f...403...`): memory addresses, URLs, UUIDs, timestamps, IPs, long hex,
|
|
10
|
-
* long ids,
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
10
|
+
* long ids, build-chunk names and minified frame names, absolute paths, long or
|
|
11
|
+
* numeric quoted strings, `#<digits>` ids, long digit runs glued to a word
|
|
12
|
+
* (`call_490779`), then every other number except a status code in a status
|
|
13
|
+
* position (`HTTP 403`, `status=500`, `[Errno 28]`).
|
|
14
|
+
*
|
|
15
|
+
* BLI-17921: `Call #490779` used to keep its id (the number rule skips a digit
|
|
16
|
+
* run right after `#`), so every call id was its own template, its own incident
|
|
17
|
+
* and its own ticket. The id shapes widened since the Python original are marked
|
|
18
|
+
* below; `python-contract.test.ts` still pins every other line.
|
|
13
19
|
*
|
|
14
20
|
* Known difference from the Python original: `\b`, `\w` and `\d` here are ASCII
|
|
15
21
|
* only, Python's are Unicode. A template next to a non-ASCII letter can differ.
|
|
@@ -38,12 +44,23 @@ const URL_PATTERN = /\b[a-zA-Z][a-zA-Z0-9+.-]*:\/\/([^/\s"'<>?#:]+)[^\s"'<>]*/g;
|
|
|
38
44
|
const UUID = /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/g;
|
|
39
45
|
const TIMESTAMP = /\b\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:[.,]\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?\b|\b\d{2}:\d{2}:\d{2}(?:[.,]\d+)?\b/g;
|
|
40
46
|
const IP_ADDRESS = /\b\d{1,3}(?:\.\d{1,3}){3}(?::\d+)?\b/g;
|
|
41
|
-
|
|
47
|
+
// 8+ hex characters that mix digits and letters, or any 32+ hex run (a md5, sha1, sha256 or a dashless uuid
|
|
48
|
+
// is never a word, even when luck left it without a digit).
|
|
49
|
+
const LONG_HEX = /\b(?=[0-9a-fA-F]*[0-9])(?=[0-9a-fA-F]*[a-fA-F])[0-9a-fA-F]{8,}\b|\b[0-9a-fA-F]{32,}\b/g;
|
|
42
50
|
// 4+ digits: an id, not a unit name.
|
|
43
51
|
const LONG_ID = /\b(?=(?:[A-Za-z_-]*\d){4})(?=[A-Za-z0-9_-]*[A-Za-z])[A-Za-z0-9_-]{20,}={0,2}/g;
|
|
52
|
+
// A Next/Turbopack chunk file name carries a per-build hash: `[root-of-the-server]__14_qotf._.js` (BLI-17921).
|
|
53
|
+
const BUILD_CHUNK = /(\[[\w.-]+\])__[A-Za-z0-9_]{4,}(?=\._\.js)/g;
|
|
54
|
+
// A minified stack frame names a function by one to three letters that change with every build (`at iz (.next/...)`).
|
|
55
|
+
const MINIFIED_FRAME = /\b(at (?:async )?)[A-Za-z_$][\w$]{0,2}( \((?=[^)\s]*\.next\/))/g;
|
|
44
56
|
// A ':' or ',' inside a segment, never a trailing one.
|
|
45
57
|
const PATH = /(?<![\w.<>/])(?:\/(?:[\w.@%+~-]|[:,](?=\w))+){2,}\/?/g;
|
|
46
58
|
const QUOTED = /'([^'\n]{0,300})'|"([^"\n]{0,300})"/g;
|
|
59
|
+
// `Call #490779`, `order #1042`: an id written with a hash sign (BLI-17921). Not `'`, not `#123abc`, not after a digit or another `#`.
|
|
60
|
+
const HASH_NUMBER = /(?<![\d#&])#\d+(?:[.,]\d+)*(?!\w)/g;
|
|
61
|
+
// Digits glued to a word are an id from five after an underscore or six after a letter (`call_49077`, `rec490779`),
|
|
62
|
+
// never `sha256`, `utf8`, `ipv6` or the `ED25519` key type that the Python golden pins.
|
|
63
|
+
const GLUED_DIGITS = /(?<=_)\d{5,}(?!\w)|(?<=[A-Za-z])\d{6,}(?!\w)/g;
|
|
47
64
|
const NUMBER = /(?<![A-Za-z_\d#])\d+(?:[.,]\d+)*/g;
|
|
48
65
|
// A number right after one of these is a status, not a quantity: kept so
|
|
49
66
|
// "HTTP 403" and "HTTP 404" stay different templates.
|
|
@@ -95,8 +112,12 @@ export function mask(input) {
|
|
|
95
112
|
text = text.replace(IP_ADDRESS, "<ip>");
|
|
96
113
|
text = text.replace(LONG_HEX, "<hex>");
|
|
97
114
|
text = text.replace(LONG_ID, "<id>");
|
|
115
|
+
text = text.replace(BUILD_CHUNK, "$1__<hash>");
|
|
116
|
+
text = text.replace(MINIFIED_FRAME, "$1<fn>$2");
|
|
98
117
|
text = text.replace(PATH, maskPath);
|
|
99
118
|
text = text.replace(QUOTED, maskQuoted);
|
|
119
|
+
text = text.replace(HASH_NUMBER, "#");
|
|
120
|
+
text = text.replace(GLUED_DIGITS, "#");
|
|
100
121
|
text = text.replace(NUMBER, keepStatusNumbers);
|
|
101
122
|
return cut(squash(text), TEMPLATE_CHARS);
|
|
102
123
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The stored text a line with this old stored text would get today. */
|
|
2
|
+
export declare function remaskedTemplate(stored: string): string;
|
|
3
|
+
/** True when today's masker changes this stored text, so the id it was filed under is not the id a new sighting would get. */
|
|
4
|
+
export declare function isStaleTemplate(stored: string): boolean;
|
|
5
|
+
/** True when a sighting whose text today is `current` is the same failure as an incident stored as `stored`. */
|
|
6
|
+
export declare function sameFailureUnderCurrentMask(stored: string, current: string): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-masking a stored template under today's masker (BLI-17921).
|
|
3
|
+
*
|
|
4
|
+
* Plain words: when the masker learns a new id shape (`Call #490779` used to keep its number), the same log
|
|
5
|
+
* line gets a NEW template id, and an incident filed under the old id would look like it vanished while a
|
|
6
|
+
* twin opened under the new one. The old row still holds the old masked text, so running today's masker over
|
|
7
|
+
* that text yields the text the new id would have, and the two can be matched. The official term: a lazy
|
|
8
|
+
* schema migration, re-deriving a stored key from stored data at read time.
|
|
9
|
+
*
|
|
10
|
+
* Two rules keep the match honest:
|
|
11
|
+
* - A stored text that re-masks to itself was never touched by the new rules: it is not stale, and its
|
|
12
|
+
* template id is still the right one, so there is nothing to adopt.
|
|
13
|
+
* - The digest cuts a template at 160 characters. A text that was cut by the OLD masker holds fewer of the
|
|
14
|
+
* line's words than the NEW masker's text (the new placeholders are shorter), so equality is the wrong test
|
|
15
|
+
* for a cut text; its prefix, minus the last (possibly chopped) word, is.
|
|
16
|
+
*/
|
|
17
|
+
import { STORED_TEMPLATE_CHARS, scrubForStorage } from "./scrub.js";
|
|
18
|
+
/** A cut text shorter than this gives a prefix too short to tell two failures apart. */
|
|
19
|
+
const MIN_PREFIX_CHARS = 80;
|
|
20
|
+
/** The stored text a line with this old stored text would get today. */
|
|
21
|
+
export function remaskedTemplate(stored) {
|
|
22
|
+
return scrubForStorage(stored, STORED_TEMPLATE_CHARS);
|
|
23
|
+
}
|
|
24
|
+
/** True when today's masker changes this stored text, so the id it was filed under is not the id a new sighting would get. */
|
|
25
|
+
export function isStaleTemplate(stored) {
|
|
26
|
+
return remaskedTemplate(stored) !== stored;
|
|
27
|
+
}
|
|
28
|
+
/** True when a sighting whose text today is `current` is the same failure as an incident stored as `stored`. */
|
|
29
|
+
export function sameFailureUnderCurrentMask(stored, current) {
|
|
30
|
+
const again = remaskedTemplate(stored);
|
|
31
|
+
if (again === current)
|
|
32
|
+
return true;
|
|
33
|
+
if (Array.from(stored).length < STORED_TEMPLATE_CHARS)
|
|
34
|
+
return false;
|
|
35
|
+
const wholeWords = again.slice(0, Math.max(0, again.lastIndexOf(" ")));
|
|
36
|
+
return Array.from(wholeWords).length >= MIN_PREFIX_CHARS && current.startsWith(wholeWords);
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client app of a session read from the HEAD of its transcript (ticket 19258): no full download, no counting.
|
|
3
|
+
*
|
|
4
|
+
* The backfill stages a session's stored raw evidence and hands the first bytes here. The same two functions the
|
|
5
|
+
* session facts use (`claudeSpawn`, `codexSpawn`) decide, so a label read from a head and one counted at upload cannot
|
|
6
|
+
* disagree. `raw` carries the label strings the transcript used (an originator, a source word, an entrypoint), never any
|
|
7
|
+
* text of the conversation, so an unmapped value can be reported and mapped from evidence.
|
|
8
|
+
*/
|
|
9
|
+
import { type ClientApp } from "./session-facts-spawn.js";
|
|
10
|
+
export interface ClientAppRead {
|
|
11
|
+
client_app: ClientApp | null;
|
|
12
|
+
/** The raw marker strings seen, labels only. */
|
|
13
|
+
raw: {
|
|
14
|
+
originator?: string;
|
|
15
|
+
source?: string;
|
|
16
|
+
entrypoint?: string;
|
|
17
|
+
};
|
|
18
|
+
/** `no_marker` when the head named no app (an older Claude Code, a truncated file), else `read`. */
|
|
19
|
+
reason: "read" | "no_marker" | "unreadable";
|
|
20
|
+
}
|
|
21
|
+
export declare function clientAppFromHead(source: "codex" | "claude_code", head: string): ClientAppRead;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client app of a session read from the HEAD of its transcript (ticket 19258): no full download, no counting.
|
|
3
|
+
*
|
|
4
|
+
* The backfill stages a session's stored raw evidence and hands the first bytes here. The same two functions the
|
|
5
|
+
* session facts use (`claudeSpawn`, `codexSpawn`) decide, so a label read from a head and one counted at upload cannot
|
|
6
|
+
* disagree. `raw` carries the label strings the transcript used (an originator, a source word, an entrypoint), never any
|
|
7
|
+
* text of the conversation, so an unmapped value can be reported and mapped from evidence.
|
|
8
|
+
*/
|
|
9
|
+
import { claudeSpawn, codexSpawn } from "./session-facts-spawn.js";
|
|
10
|
+
const MAX_LINES = 200;
|
|
11
|
+
const word = (value) => (typeof value === "string" && value.length > 0 ? value.slice(0, 60) : undefined);
|
|
12
|
+
export function clientAppFromHead(source, head) {
|
|
13
|
+
let spawn = null;
|
|
14
|
+
const raw = {};
|
|
15
|
+
let parsed = 0;
|
|
16
|
+
for (const line of head.split("\n", MAX_LINES)) {
|
|
17
|
+
if (!line.trim())
|
|
18
|
+
continue;
|
|
19
|
+
let record;
|
|
20
|
+
try {
|
|
21
|
+
record = JSON.parse(line);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
continue; // the head can end mid-line; a bad line is skipped, never guessed at
|
|
25
|
+
}
|
|
26
|
+
if (!record || typeof record !== "object")
|
|
27
|
+
continue;
|
|
28
|
+
parsed += 1;
|
|
29
|
+
if (source === "codex") {
|
|
30
|
+
if (record["type"] !== "session_meta")
|
|
31
|
+
continue;
|
|
32
|
+
const payload = (record["payload"] && typeof record["payload"] === "object" ? record["payload"] : {});
|
|
33
|
+
raw.originator = word(payload["originator"]);
|
|
34
|
+
const sourceField = payload["source"];
|
|
35
|
+
raw.source = typeof sourceField === "string" ? word(sourceField) : sourceField && typeof sourceField === "object" ? "subagent" : undefined;
|
|
36
|
+
spawn = codexSpawn(null, payload);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
const next = claudeSpawn(spawn, record);
|
|
40
|
+
if (next && !spawn) {
|
|
41
|
+
raw.entrypoint = word(record["entrypoint"]);
|
|
42
|
+
spawn = next;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (parsed === 0)
|
|
47
|
+
return { client_app: null, raw, reason: "unreadable" };
|
|
48
|
+
if (!spawn?.client_app)
|
|
49
|
+
return { client_app: null, raw, reason: "no_marker" };
|
|
50
|
+
return { client_app: spawn.client_app, raw, reason: "read" };
|
|
51
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Active time of a session (ticket 19258): the harvest's own rule (`extract/claude.ts`, `extract/codex.ts` `IDLE_GAP_MS`).
|
|
3
|
+
* Sort every record timestamp; a gap of 10 minutes or less to the previous record is time in use, a longer gap is idle and
|
|
4
|
+
* is dropped. Order-blind by construction, so a sidecar file read after the main transcript cannot change the answer.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ACTIVE_IDLE_GAP_MS: number;
|
|
7
|
+
export declare function activeSeconds(timestampsMs: readonly number[]): number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Active time of a session (ticket 19258): the harvest's own rule (`extract/claude.ts`, `extract/codex.ts` `IDLE_GAP_MS`).
|
|
3
|
+
* Sort every record timestamp; a gap of 10 minutes or less to the previous record is time in use, a longer gap is idle and
|
|
4
|
+
* is dropped. Order-blind by construction, so a sidecar file read after the main transcript cannot change the answer.
|
|
5
|
+
*/
|
|
6
|
+
export const ACTIVE_IDLE_GAP_MS = 10 * 60 * 1000;
|
|
7
|
+
export function activeSeconds(timestampsMs) {
|
|
8
|
+
if (timestampsMs.length < 2)
|
|
9
|
+
return 0;
|
|
10
|
+
const sorted = [...timestampsMs].sort((a, b) => a - b);
|
|
11
|
+
let active = 0;
|
|
12
|
+
for (let i = 1; i < sorted.length; i += 1) {
|
|
13
|
+
const gap = sorted[i] - sorted[i - 1];
|
|
14
|
+
if (gap <= ACTIVE_IDLE_GAP_MS)
|
|
15
|
+
active += gap;
|
|
16
|
+
}
|
|
17
|
+
return Math.round(active / 1000);
|
|
18
|
+
}
|
|
@@ -10,8 +10,19 @@
|
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
/** `interactive` is a person's session; `worker` and `subagent` were started by a program. */
|
|
12
12
|
export type SessionSpawnKind = "interactive" | "worker" | "subagent";
|
|
13
|
+
/**
|
|
14
|
+
* Which app a session ran in (ticket 19258). A label only: it changes nothing about what is collected.
|
|
15
|
+
* The field names are the ones real transcripts carry, probed 2026-10-14 on 2,222 Codex and 4,558 Claude Code
|
|
16
|
+
* sessions: Codex `session_meta.originator` (`codex_exec`, `codex-tui`, `Codex Desktop`, `codex_work_desktop`,
|
|
17
|
+
* `Claude Code`) and `source` (`exec`, `cli`, `vscode`, or `{subagent: ...}`); Claude Code `entrypoint` (`cli`,
|
|
18
|
+
* `sdk-cli`, `sdk-ts`, `claude-desktop`). A value nobody has observed is `unknown`, never a guess.
|
|
19
|
+
*/
|
|
20
|
+
export declare const CLIENT_APPS: readonly ["claude_cli", "claude_desktop", "claude_ide", "codex_cli", "codex_desktop", "codex_ide", "codex_exec", "unknown"];
|
|
21
|
+
export type ClientApp = (typeof CLIENT_APPS)[number];
|
|
13
22
|
export interface SessionSpawn {
|
|
14
23
|
kind: SessionSpawnKind;
|
|
24
|
+
/** Which app the session ran in. Absent from a block a CLI published before this field. */
|
|
25
|
+
client_app?: ClientApp;
|
|
15
26
|
/** The parent session's id when the transcript names one (Codex `parent_thread_id`, `forked_from_id`). */
|
|
16
27
|
parent_session_id?: string;
|
|
17
28
|
}
|
|
@@ -21,6 +32,16 @@ export declare const SessionSpawnSchema: z.ZodObject<{
|
|
|
21
32
|
worker: "worker";
|
|
22
33
|
subagent: "subagent";
|
|
23
34
|
}>;
|
|
35
|
+
client_app: z.ZodOptional<z.ZodEnum<{
|
|
36
|
+
unknown: "unknown";
|
|
37
|
+
claude_cli: "claude_cli";
|
|
38
|
+
claude_desktop: "claude_desktop";
|
|
39
|
+
claude_ide: "claude_ide";
|
|
40
|
+
codex_cli: "codex_cli";
|
|
41
|
+
codex_desktop: "codex_desktop";
|
|
42
|
+
codex_ide: "codex_ide";
|
|
43
|
+
codex_exec: "codex_exec";
|
|
44
|
+
}>>;
|
|
24
45
|
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
25
46
|
}, z.core.$strict>;
|
|
26
47
|
/**
|
|
@@ -32,6 +53,13 @@ export declare const SessionSpawnSchema: z.ZodObject<{
|
|
|
32
53
|
* never decide it, because they ride inside their parent's session.
|
|
33
54
|
*/
|
|
34
55
|
export declare function claudeSpawn(current: SessionSpawn | null, record: Record<string, unknown>): SessionSpawn | null;
|
|
56
|
+
/**
|
|
57
|
+
* Observed `entrypoint` values only. `sdk-cli` is the CLI binary driven by a program (`claude -p`): the client app
|
|
58
|
+
* is still the CLI, and `spawn.kind` already says a program drove it. `sdk-ts` (the TypeScript SDK, one session seen)
|
|
59
|
+
* and anything unobserved are `unknown`. No IDE value had been observed when this was written; a fleet-wide backfill
|
|
60
|
+
* reports every distinct unmapped value so a real one (a VS Code or JetBrains entrypoint) is added from evidence.
|
|
61
|
+
*/
|
|
62
|
+
export declare function claudeClientApp(entrypoint: string): ClientApp;
|
|
35
63
|
/**
|
|
36
64
|
* Codex writes who started a session in its first `session_meta`: `source` is
|
|
37
65
|
* `exec` for `codex exec`, `cli` or `vscode` for a person, or an object
|
|
@@ -39,3 +67,11 @@ export declare function claudeSpawn(current: SessionSpawn | null, record: Record
|
|
|
39
67
|
* program-driven run; `parent_thread_id` and `forked_from_id` name a parent.
|
|
40
68
|
*/
|
|
41
69
|
export declare function codexSpawn(current: SessionSpawn | null, meta: Record<string, unknown>): SessionSpawn | null;
|
|
70
|
+
/**
|
|
71
|
+
* The originator names the app; the source names the host the app declared. Observed on real files: `codex_exec`
|
|
72
|
+
* (the exec runner), `Codex Desktop` and `codex_work_desktop` (the desktop apps, whose source is `vscode` because they
|
|
73
|
+
* share the app-server), `codex-tui` (the terminal UI: source `cli`, or `vscode` when started from VS Code, which is
|
|
74
|
+
* the IDE). A subagent keeps its parent app's originator. `Claude Code` as an originator is Claude Code driving a Codex
|
|
75
|
+
* run, not a Codex client a person used, so it is `unknown`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function codexClientApp(originator: unknown, source: unknown): ClientApp;
|
|
@@ -8,11 +8,20 @@
|
|
|
8
8
|
* and a kind word only.
|
|
9
9
|
*/
|
|
10
10
|
import { z } from "zod";
|
|
11
|
+
/**
|
|
12
|
+
* Which app a session ran in (ticket 19258). A label only: it changes nothing about what is collected.
|
|
13
|
+
* The field names are the ones real transcripts carry, probed 2026-10-14 on 2,222 Codex and 4,558 Claude Code
|
|
14
|
+
* sessions: Codex `session_meta.originator` (`codex_exec`, `codex-tui`, `Codex Desktop`, `codex_work_desktop`,
|
|
15
|
+
* `Claude Code`) and `source` (`exec`, `cli`, `vscode`, or `{subagent: ...}`); Claude Code `entrypoint` (`cli`,
|
|
16
|
+
* `sdk-cli`, `sdk-ts`, `claude-desktop`). A value nobody has observed is `unknown`, never a guess.
|
|
17
|
+
*/
|
|
18
|
+
export const CLIENT_APPS = ["claude_cli", "claude_desktop", "claude_ide", "codex_cli", "codex_desktop", "codex_ide", "codex_exec", "unknown"];
|
|
11
19
|
const SPAWN_ID = /^[A-Za-z0-9._-]{1,80}$/u;
|
|
12
20
|
const spawnId = (value) => typeof value === "string" && SPAWN_ID.test(value) ? value : undefined;
|
|
13
21
|
export const SessionSpawnSchema = z
|
|
14
22
|
.object({
|
|
15
23
|
kind: z.enum(["interactive", "worker", "subagent"]),
|
|
24
|
+
client_app: z.enum(CLIENT_APPS).optional(),
|
|
16
25
|
parent_session_id: z.string().regex(SPAWN_ID).optional(),
|
|
17
26
|
})
|
|
18
27
|
.strict();
|
|
@@ -30,8 +39,31 @@ export function claudeSpawn(current, record) {
|
|
|
30
39
|
const entrypoint = record["entrypoint"];
|
|
31
40
|
if (typeof entrypoint !== "string" || !entrypoint)
|
|
32
41
|
return current;
|
|
33
|
-
return { kind: entrypoint
|
|
42
|
+
return { kind: PROGRAM_ENTRYPOINT.test(entrypoint) ? "worker" : "interactive", client_app: claudeClientApp(entrypoint) };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Observed `entrypoint` values only. `sdk-cli` is the CLI binary driven by a program (`claude -p`): the client app
|
|
46
|
+
* is still the CLI, and `spawn.kind` already says a program drove it. `sdk-ts` (the TypeScript SDK, one session seen)
|
|
47
|
+
* and anything unobserved are `unknown`. No IDE value had been observed when this was written; a fleet-wide backfill
|
|
48
|
+
* reports every distinct unmapped value so a real one (a VS Code or JetBrains entrypoint) is added from evidence.
|
|
49
|
+
*/
|
|
50
|
+
export function claudeClientApp(entrypoint) {
|
|
51
|
+
if (entrypoint === "cli" || entrypoint === "sdk-cli")
|
|
52
|
+
return "claude_cli";
|
|
53
|
+
if (entrypoint === "claude-desktop")
|
|
54
|
+
return "claude_desktop";
|
|
55
|
+
return "unknown";
|
|
34
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The entrypoints a PROGRAM drives: `sdk-cli` (`claude -p`), `sdk-ts`, `sdk-py`
|
|
59
|
+
* and Claude Code run as an MCP server. Everything else is a person at a
|
|
60
|
+
* keyboard: `cli`, and the editor and desktop apps (`claude-vscode`,
|
|
61
|
+
* `claude-desktop`), which an earlier version of this rule filed as workers and
|
|
62
|
+
* so hid from usage as "automated" (BLI-19277). An unfamiliar entrypoint reads
|
|
63
|
+
* as interactive: a program missed counts as a person's session, never a
|
|
64
|
+
* person's session hidden.
|
|
65
|
+
*/
|
|
66
|
+
const PROGRAM_ENTRYPOINT = /^(?:sdk(?:[-_].+)?|mcp)$/u;
|
|
35
67
|
/**
|
|
36
68
|
* Codex writes who started a session in its first `session_meta`: `source` is
|
|
37
69
|
* `exec` for `codex exec`, `cli` or `vscode` for a person, or an object
|
|
@@ -46,5 +78,21 @@ export function codexSpawn(current, meta) {
|
|
|
46
78
|
const exec = meta["originator"] === "codex_exec" || source === "exec";
|
|
47
79
|
const parent = spawnId(meta["parent_thread_id"]) ?? spawnId(meta["forked_from_id"]);
|
|
48
80
|
const kind = spawnedSubagent ? "subagent" : exec ? "worker" : "interactive";
|
|
49
|
-
return { kind, ...(parent ? { parent_session_id: parent } : {}) };
|
|
81
|
+
return { kind, client_app: codexClientApp(meta["originator"], meta["source"]), ...(parent ? { parent_session_id: parent } : {}) };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The originator names the app; the source names the host the app declared. Observed on real files: `codex_exec`
|
|
85
|
+
* (the exec runner), `Codex Desktop` and `codex_work_desktop` (the desktop apps, whose source is `vscode` because they
|
|
86
|
+
* share the app-server), `codex-tui` (the terminal UI: source `cli`, or `vscode` when started from VS Code, which is
|
|
87
|
+
* the IDE). A subagent keeps its parent app's originator. `Claude Code` as an originator is Claude Code driving a Codex
|
|
88
|
+
* run, not a Codex client a person used, so it is `unknown`.
|
|
89
|
+
*/
|
|
90
|
+
export function codexClientApp(originator, source) {
|
|
91
|
+
if (originator === "codex_exec")
|
|
92
|
+
return "codex_exec";
|
|
93
|
+
if (originator === "Codex Desktop" || originator === "codex_work_desktop")
|
|
94
|
+
return "codex_desktop";
|
|
95
|
+
if (originator === "codex-tui")
|
|
96
|
+
return source === "vscode" ? "codex_ide" : "codex_cli";
|
|
97
|
+
return "unknown";
|
|
50
98
|
}
|
package/dist/session-facts.d.ts
CHANGED
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
* Session facts: everything deterministic about one transcript, counted once,
|
|
3
3
|
* where the file already is.
|
|
4
4
|
*
|
|
5
|
-
* BLI-4341 part A.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the same bytes at harvest time and had already read every line, so the
|
|
9
|
-
* download was pure re-work, and a session with no analysis run had no token
|
|
10
|
-
* count at all.
|
|
5
|
+
* BLI-4341 part A. Token totals used to be computed only on the server, which downloaded the transcript back out of
|
|
6
|
+
* Storage and summed it (`det.v5`), though the collector holds the same bytes at harvest time and had already read
|
|
7
|
+
* every line; a session with no analysis run had no token count at all.
|
|
11
8
|
*
|
|
12
9
|
* This module is the ONE implementation of those rules. The collector feeds it
|
|
13
10
|
* at upload; the server extractor feeds it the same records during its own
|
|
@@ -72,6 +69,8 @@ export interface SessionFacts {
|
|
|
72
69
|
first_timestamp: string | null;
|
|
73
70
|
last_timestamp: string | null;
|
|
74
71
|
wall_duration_seconds: number | null;
|
|
72
|
+
/** Ticket 19258: seconds in use (`session-facts-active.ts`). Absent from a block counted before this field. */
|
|
73
|
+
active_seconds?: number;
|
|
75
74
|
transcript_bytes: number;
|
|
76
75
|
transcript_lines: number;
|
|
77
76
|
/** Main plus any sidecars the caller fed in. */
|
|
@@ -80,10 +79,7 @@ export interface SessionFacts {
|
|
|
80
79
|
truncated_models: number;
|
|
81
80
|
/** Distinct tool names dropped by the cap. */
|
|
82
81
|
truncated_tool_names: number;
|
|
83
|
-
/**
|
|
84
|
-
* BLI-13056: skills used, by the person (typed) and by the agent (tool call).
|
|
85
|
-
* Names and counts only. Absent from a block a CLI published before this field.
|
|
86
|
-
*/
|
|
82
|
+
/** BLI-13056: skills used, by the person (typed) and by the agent (tool call); names and counts only. Absent from a block a CLI published before this field. */
|
|
87
83
|
skill_use?: SkillUseCount[];
|
|
88
84
|
/** BLI-13066: who started the session (`session-facts-spawn.ts`). Absent from a block a CLI published before this field. */
|
|
89
85
|
spawn?: SessionSpawn;
|
|
@@ -98,6 +94,7 @@ export interface SessionFactsAccumulator {
|
|
|
98
94
|
tool_calls_by_name: Record<string, number>;
|
|
99
95
|
first_timestamp_ms: number | null;
|
|
100
96
|
last_timestamp_ms: number | null;
|
|
97
|
+
timestamps_ms: number[];
|
|
101
98
|
transcript_bytes: number;
|
|
102
99
|
transcript_lines: number;
|
|
103
100
|
transcript_files: number;
|
|
@@ -179,6 +176,7 @@ export declare const SessionFactsSchema: z.ZodObject<{
|
|
|
179
176
|
first_timestamp: z.ZodNullable<z.ZodString>;
|
|
180
177
|
last_timestamp: z.ZodNullable<z.ZodString>;
|
|
181
178
|
wall_duration_seconds: z.ZodNullable<z.ZodNumber>;
|
|
179
|
+
active_seconds: z.ZodOptional<z.ZodNumber>;
|
|
182
180
|
transcript_bytes: z.ZodNumber;
|
|
183
181
|
transcript_lines: z.ZodNumber;
|
|
184
182
|
transcript_files: z.ZodNumber;
|
|
@@ -196,6 +194,16 @@ export declare const SessionFactsSchema: z.ZodObject<{
|
|
|
196
194
|
worker: "worker";
|
|
197
195
|
subagent: "subagent";
|
|
198
196
|
}>;
|
|
197
|
+
client_app: z.ZodOptional<z.ZodEnum<{
|
|
198
|
+
unknown: "unknown";
|
|
199
|
+
claude_cli: "claude_cli";
|
|
200
|
+
claude_desktop: "claude_desktop";
|
|
201
|
+
claude_ide: "claude_ide";
|
|
202
|
+
codex_cli: "codex_cli";
|
|
203
|
+
codex_desktop: "codex_desktop";
|
|
204
|
+
codex_ide: "codex_ide";
|
|
205
|
+
codex_exec: "codex_exec";
|
|
206
|
+
}>>;
|
|
199
207
|
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
200
208
|
}, z.core.$strict>>;
|
|
201
209
|
}, z.core.$strict>;
|
package/dist/session-facts.js
CHANGED
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
* Session facts: everything deterministic about one transcript, counted once,
|
|
3
3
|
* where the file already is.
|
|
4
4
|
*
|
|
5
|
-
* BLI-4341 part A.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the same bytes at harvest time and had already read every line, so the
|
|
9
|
-
* download was pure re-work, and a session with no analysis run had no token
|
|
10
|
-
* count at all.
|
|
5
|
+
* BLI-4341 part A. Token totals used to be computed only on the server, which downloaded the transcript back out of
|
|
6
|
+
* Storage and summed it (`det.v5`), though the collector holds the same bytes at harvest time and had already read
|
|
7
|
+
* every line; a session with no analysis run had no token count at all.
|
|
11
8
|
*
|
|
12
9
|
* This module is the ONE implementation of those rules. The collector feeds it
|
|
13
10
|
* at upload; the server extractor feeds it the same records during its own
|
|
@@ -36,6 +33,7 @@
|
|
|
36
33
|
*/
|
|
37
34
|
import { z } from "zod";
|
|
38
35
|
import { claudeAssistantText, claudeUserTurnText, codexAssistantText, codexUserTurnText } from "./session-facts-text.js";
|
|
36
|
+
import { activeSeconds } from "./session-facts-active.js";
|
|
39
37
|
import { claudeSpawn, codexSpawn, SessionSpawnSchema } from "./session-facts-spawn.js";
|
|
40
38
|
import { observeClaudeSkillUse, observeCodexSkillUse, SKILL_USE_MAX_SKILLS, SkillUseCountSchema, SkillUseTally } from "./session-facts-skills.js";
|
|
41
39
|
/** Bump when a counting rule changes, never when a field is added. */
|
|
@@ -56,6 +54,7 @@ export function newSessionFactsAccumulator(source) {
|
|
|
56
54
|
tool_calls_by_name: {},
|
|
57
55
|
first_timestamp_ms: null,
|
|
58
56
|
last_timestamp_ms: null,
|
|
57
|
+
timestamps_ms: [],
|
|
59
58
|
transcript_bytes: 0,
|
|
60
59
|
transcript_lines: 0,
|
|
61
60
|
transcript_files: 0,
|
|
@@ -76,6 +75,7 @@ export function observeSessionFactsRecord(acc, record) {
|
|
|
76
75
|
acc.record_count += 1;
|
|
77
76
|
const ms = parseTimestampMs(record["timestamp"]);
|
|
78
77
|
if (ms != null) {
|
|
78
|
+
acc.timestamps_ms.push(ms);
|
|
79
79
|
acc.first_timestamp_ms =
|
|
80
80
|
acc.first_timestamp_ms == null ? ms : Math.min(acc.first_timestamp_ms, ms);
|
|
81
81
|
acc.last_timestamp_ms =
|
|
@@ -250,6 +250,7 @@ export function finalizeSessionFacts(acc) {
|
|
|
250
250
|
truncated_tool_names: toolEntries.length - keptTools.length,
|
|
251
251
|
skill_use: acc.skill_tally.toList().slice(0, SKILL_USE_MAX_SKILLS),
|
|
252
252
|
...(acc.spawn ? { spawn: acc.spawn } : {}),
|
|
253
|
+
active_seconds: activeSeconds(acc.timestamps_ms),
|
|
253
254
|
};
|
|
254
255
|
}
|
|
255
256
|
/**
|
|
@@ -359,6 +360,7 @@ export const SessionFactsSchema = z
|
|
|
359
360
|
first_timestamp: z.string().datetime({ offset: true }).nullable(),
|
|
360
361
|
last_timestamp: z.string().datetime({ offset: true }).nullable(),
|
|
361
362
|
wall_duration_seconds: z.number().int().nonnegative().nullable(),
|
|
363
|
+
active_seconds: z.number().int().nonnegative().optional(),
|
|
362
364
|
transcript_bytes: z.number().int().nonnegative(),
|
|
363
365
|
transcript_lines: z.number().int().nonnegative(),
|
|
364
366
|
transcript_files: z.number().int().nonnegative(),
|