@bli-cockpit/telemetry-core 0.1.97 → 0.1.99

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.
Files changed (40) hide show
  1. package/dist/agent-artifacts.d.ts +6 -0
  2. package/dist/agent-artifacts.js +1 -1
  3. package/dist/codex-record-copies.js +11 -6
  4. package/dist/evidence-completeness.d.ts +2 -2
  5. package/dist/evidence-rules-fingerprint.js +3 -1
  6. package/dist/evidence-stubs.d.ts +1 -1
  7. package/dist/evidence-stubs.js +2 -2
  8. package/dist/evidence-transcripts.d.ts +1 -1
  9. package/dist/evidence-transcripts.js +2 -2
  10. package/dist/evidence-upload-abort.d.ts +1 -1
  11. package/dist/evidence-upload.d.ts +61 -3
  12. package/dist/evidence-upload.js +1 -1
  13. package/dist/image-byte-scan.js +35 -6
  14. package/dist/image-descriptions.d.ts +5 -1
  15. package/dist/image-descriptions.js +3 -1
  16. package/dist/image-store.d.ts +2 -0
  17. package/dist/image-store.js +1 -1
  18. package/dist/index.d.ts +6 -0
  19. package/dist/index.js +6 -0
  20. package/dist/ingest-dto.d.ts +2 -2
  21. package/dist/local-config.d.ts +1 -1
  22. package/dist/memory-hook-stats.d.ts +1 -1
  23. package/dist/native-usage-facts.d.ts +8 -0
  24. package/dist/native-usage-facts.js +28 -0
  25. package/dist/opencode-transcript.d.ts +8 -0
  26. package/dist/opencode-transcript.js +72 -0
  27. package/dist/pi-session-facts.d.ts +2 -0
  28. package/dist/pi-session-facts.js +37 -0
  29. package/dist/pi-transcript-usage.js +2 -0
  30. package/dist/session-facts-schema.d.ts +110 -0
  31. package/dist/session-facts-schema.js +63 -0
  32. package/dist/session-facts-spawn.js +2 -0
  33. package/dist/session-facts.d.ts +19 -118
  34. package/dist/session-facts.js +24 -60
  35. package/dist/shelf.d.ts +31 -16
  36. package/dist/shelf.js +18 -8
  37. package/dist/t3-projection-message.d.ts +39 -0
  38. package/dist/t3-projection-message.js +125 -0
  39. package/dist/transcript-images.js +14 -2
  40. package/package.json +1 -1
@@ -4,6 +4,8 @@ export declare const AGENT_IMAGE_ARTIFACT_MAX_REPORT_ITEMS = 100;
4
4
  export declare const AgentArtifactSourceSchema: z.ZodEnum<{
5
5
  codex: "codex";
6
6
  claude_code: "claude_code";
7
+ opencode: "opencode";
8
+ pi: "pi";
7
9
  }>;
8
10
  export type AgentArtifactSource = z.infer<typeof AgentArtifactSourceSchema>;
9
11
  export declare const AgentArtifactKindSchema: z.ZodEnum<{
@@ -86,6 +88,8 @@ export declare const AgentImageArtifactSchema: z.ZodObject<{
86
88
  agent_source: z.ZodEnum<{
87
89
  codex: "codex";
88
90
  claude_code: "claude_code";
91
+ opencode: "opencode";
92
+ pi: "pi";
89
93
  }>;
90
94
  source_session_id: z.ZodString;
91
95
  source_message_id: z.ZodOptional<z.ZodString>;
@@ -179,6 +183,8 @@ export declare const AgentImageArtifactReportRequestSchema: z.ZodObject<{
179
183
  agent_source: z.ZodEnum<{
180
184
  codex: "codex";
181
185
  claude_code: "claude_code";
186
+ opencode: "opencode";
187
+ pi: "pi";
182
188
  }>;
183
189
  source_session_id: z.ZodString;
184
190
  source_message_id: z.ZodOptional<z.ZodString>;
@@ -3,7 +3,7 @@ import { CaptureProvenanceSchema, IsoDateTimeSchema, NonEmptyStringSchema, Sha25
3
3
  export const AGENT_IMAGE_ARTIFACT_MAX_FILE_BYTES = 10 * 1024 * 1024;
4
4
  export const AGENT_IMAGE_ARTIFACT_MAX_REPORT_ITEMS = 100;
5
5
  const UuidSchema = z.string().uuid();
6
- export const AgentArtifactSourceSchema = z.enum(["codex", "claude_code"]);
6
+ export const AgentArtifactSourceSchema = z.enum(["codex", "claude_code", "opencode", "pi"]);
7
7
  export const AgentArtifactKindSchema = z.enum([
8
8
  "screenshot",
9
9
  "image_attachment",
@@ -4,8 +4,10 @@
4
4
  * distinct, as do divergent payloads with the same provider/turn id. Ordinary
5
5
  * native transcripts (without Tower boundaries) are unchanged.
6
6
  */
7
+ import { t3ProjectionMessageSelector } from "./t3-projection-message.js";
7
8
  import { createHash } from "node:crypto";
8
9
  export function codexRevisionRecordSelector() {
10
+ const projection = t3ProjectionMessageSelector();
9
11
  let active = false;
10
12
  const prior = new Map();
11
13
  let current = new Map();
@@ -19,32 +21,35 @@ export function codexRevisionRecordSelector() {
19
21
  return false;
20
22
  }
21
23
  if (!active)
22
- return true;
24
+ return projection(record);
23
25
  // Context is stateful, not a charged request/turn: replay it even in copied history.
24
26
  if (record["type"] === "session_meta" || record["type"] === "turn_context")
25
27
  return true;
26
28
  const hash = createHash("sha256").update(JSON.stringify(record)).digest("hex");
27
29
  const occurrence = (current.get(hash) ?? 0) + 1;
28
30
  current.set(hash, occurrence);
29
- return occurrence > (prior.get(hash) ?? 0);
31
+ return occurrence > (prior.get(hash) ?? 0) && projection(record);
30
32
  };
31
33
  }
32
34
  const selectors = new WeakMap();
35
+ const composites = new WeakSet();
33
36
  const usage = new WeakMap();
34
37
  /** Shared by metadata counting and the Codex metrics reader; returns whether this record contributes. */
35
38
  export function includeCodexRevisionRecord(acc, record) {
36
- if (record["type"] === "tower_codex_segment" && !selectors.has(acc))
39
+ if (!selectors.has(acc))
37
40
  selectors.set(acc, codexRevisionRecordSelector());
38
- return selectors.get(acc)?.(record) ?? true;
41
+ if (record["type"] === "tower_codex_segment")
42
+ composites.add(acc);
43
+ return selectors.get(acc)(record);
39
44
  }
40
45
  /** Latest cumulative event in a composite, ordinary native last-event semantics otherwise. */
41
46
  export function observeCodexCumulativeUsage(acc, record, total) {
42
47
  const timestamp = typeof record["timestamp"] === "string" ? Date.parse(record["timestamp"]) : NaN;
43
48
  const at = Number.isFinite(timestamp) ? timestamp : Number.NEGATIVE_INFINITY;
44
49
  const prior = usage.get(acc);
45
- if (!selectors.has(acc) || !prior || at >= prior.at) {
50
+ if (!composites.has(acc) || !prior || at >= prior.at) {
46
51
  acc.codex_total_usage = total;
47
- if (selectors.has(acc))
52
+ if (composites.has(acc))
48
53
  usage.set(acc, { at, model: acc.codex_model_hint });
49
54
  }
50
55
  }
@@ -2,10 +2,10 @@ import { z } from "zod";
2
2
  export declare const EvidenceCompletenessStatusSchema: z.ZodEnum<{
3
3
  unknown: "unknown";
4
4
  failed: "failed";
5
- empty: "empty";
6
5
  complete: "complete";
7
6
  partial: "partial";
8
7
  unavailable: "unavailable";
8
+ empty: "empty";
9
9
  }>;
10
10
  export type EvidenceCompletenessStatus = z.infer<typeof EvidenceCompletenessStatusSchema>;
11
11
  export declare const EvidenceCompletenessSourceCountSchema: z.ZodObject<{
@@ -71,10 +71,10 @@ export declare const EvidenceCompletenessPayloadSchema: z.ZodObject<{
71
71
  status: z.ZodEnum<{
72
72
  unknown: "unknown";
73
73
  failed: "failed";
74
- empty: "empty";
75
74
  complete: "complete";
76
75
  partial: "partial";
77
76
  unavailable: "unavailable";
77
+ empty: "empty";
78
78
  }>;
79
79
  generated_at: z.ZodString;
80
80
  scan_window: z.ZodObject<{
@@ -13,7 +13,7 @@
13
13
  * locks the literal multiset of every `secret-guards*.ts` file.
14
14
  */
15
15
  import { createHash } from "node:crypto";
16
- import { formatImageMarker, imageMarkerPattern, IMAGE_MIN_BASE64_CHARS } from "./image-descriptions.js";
16
+ import { formatImageMarker, imageMarkerPattern, IMAGE_MIN_BASE64_CHARS, IMAGE_DATA_URL_MIN_BASE64_CHARS } from "./image-descriptions.js";
17
17
  import { SECRET_LIKE_CONTENT_PATTERNS } from "./secret-guards-content-rules.js";
18
18
  import { SECRET_REDACTION_RULES } from "./secret-guards-masking.js";
19
19
  import { SECRET_FILE_SEGMENT_PATTERN } from "./secret-guards-path-rules.js";
@@ -38,12 +38,14 @@ export function evidenceRulesFingerprint() {
38
38
  content_patterns: SECRET_LIKE_CONTENT_PATTERNS.map(describe),
39
39
  file_segment_pattern: describe(SECRET_FILE_SEGMENT_PATTERN),
40
40
  image_min_base64_chars: IMAGE_MIN_BASE64_CHARS,
41
+ image_data_url_min_base64_chars: IMAGE_DATA_URL_MIN_BASE64_CHARS,
41
42
  image_marker_pattern: describe(imageMarkerPattern()),
42
43
  image_marker_sample: formatImageMarker({ sha256: "0123456789abcdef".repeat(4), mediaType: "image/png", byteSize: 412 * 1024 }),
43
44
  // BLI-23347: PDFs become text. The rules version and both marker shapes decide those bytes.
44
45
  pdf_rules_version: PDF_RULES_VERSION,
45
46
  pdf_marker_sample: formatPdfMarker({ sha256: "0123456789abcdef".repeat(4), pages: 3, byteSize: 412 * 1024, method: "text-layer", notes: ["sample"] }, "body"),
46
47
  pdf_reference_sample: formatPdfReference({ sha256: "0123456789abcdef".repeat(4), byteSize: 412 * 1024 }),
48
+ explicit_image_data_payloads: "magic-checked-native-data.v1",
47
49
  image_detector_probe: findEmbeddedImages(probe).map((image) => [image.replaceStart, image.replaceEnd, image.mediaType, image.byteSize]),
48
50
  };
49
51
  cached = createHash("sha256").update(JSON.stringify(parts)).digest("hex");
@@ -55,6 +55,6 @@ export type EvidenceStubsResponse = z.infer<typeof EvidenceStubsResponseSchema>;
55
55
  * `raw-evidence-claude-reader.ts`); anything else is null, never a guess.
56
56
  */
57
57
  export declare function transcriptSessionFromObjectKey(objectKey: string): {
58
- source: "codex" | "claude_code";
58
+ source: "codex" | "claude_code" | "opencode" | "pi";
59
59
  session_id: string;
60
60
  } | null;
@@ -56,11 +56,11 @@ export const EvidenceStubsResponseSchema = z
56
56
  * `raw-evidence-claude-reader.ts`); anything else is null, never a guess.
57
57
  */
58
58
  export function transcriptSessionFromObjectKey(objectKey) {
59
- const match = /(?:^|\/)(codex|claude)\/([A-Za-z0-9._-]{1,80})\/[0-9a-f]{16}\.jsonl$/u.exec(objectKey);
59
+ const match = /(?:^|\/)(codex|claude|opencode|pi)\/([A-Za-z0-9._-]{1,80})\/[0-9a-f]{16}\.jsonl$/u.exec(objectKey);
60
60
  if (!match)
61
61
  return null;
62
62
  return {
63
- source: match[1] === "codex" ? "codex" : "claude_code",
63
+ source: match[1] === "pi" ? "pi" : match[1] === "opencode" ? "opencode" : match[1] === "codex" ? "codex" : "claude_code",
64
64
  session_id: match[2],
65
65
  };
66
66
  }
@@ -48,7 +48,7 @@ export declare const EvidenceTranscriptsResponseSchema: z.ZodObject<{
48
48
  }, z.core.$strict>;
49
49
  export type EvidenceTranscriptsResponse = z.infer<typeof EvidenceTranscriptsResponseSchema>;
50
50
  export interface TranscriptFileIdentity {
51
- source: "codex" | "claude_code";
51
+ source: "codex" | "claude_code" | "opencode" | "pi";
52
52
  session_id: string;
53
53
  /** The Claude subagent file's key segment, or null for the session's main transcript. */
54
54
  sidecar: string | null;
@@ -60,10 +60,10 @@ export const EvidenceTranscriptsResponseSchema = z
60
60
  * `raw-evidence-claude-reader.ts`); anything else is null, never a guess.
61
61
  */
62
62
  export function transcriptFileFromObjectKey(objectKey) {
63
- const main = /(?:^|\/)(codex|claude)\/([A-Za-z0-9._-]{1,80})\/[0-9a-f]{16}\.jsonl$/u.exec(objectKey);
63
+ const main = /(?:^|\/)(codex|claude|opencode|pi)\/([A-Za-z0-9._-]{1,80})\/[0-9a-f]{16}\.jsonl$/u.exec(objectKey);
64
64
  if (main) {
65
65
  return {
66
- source: main[1] === "codex" ? "codex" : "claude_code",
66
+ source: main[1] === "pi" ? "pi" : main[1] === "opencode" ? "opencode" : main[1] === "codex" ? "codex" : "claude_code",
67
67
  session_id: main[2],
68
68
  sidecar: null,
69
69
  };
@@ -60,8 +60,8 @@ export type RawEvidenceUploadAbortRequest = z.infer<typeof RawEvidenceUploadAbor
60
60
  export declare const RawEvidenceUploadAbortResponseSchema: z.ZodObject<{
61
61
  ok: z.ZodLiteral<true>;
62
62
  status: z.ZodEnum<{
63
- reason_recorded: "reason_recorded";
64
63
  aborted: "aborted";
64
+ reason_recorded: "reason_recorded";
65
65
  already_terminal: "already_terminal";
66
66
  }>;
67
67
  upload_id: z.ZodString;
@@ -141,6 +141,8 @@ export declare const RawEvidenceUploadBeginObjectSchema: z.ZodObject<{
141
141
  source: z.ZodEnum<{
142
142
  codex: "codex";
143
143
  claude_code: "claude_code";
144
+ opencode: "opencode";
145
+ pi: "pi";
144
146
  }>;
145
147
  }, z.core.$strict>>;
146
148
  }, z.core.$strict>;
@@ -258,6 +260,8 @@ export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
258
260
  source: z.ZodEnum<{
259
261
  codex: "codex";
260
262
  claude_code: "claude_code";
263
+ opencode: "opencode";
264
+ pi: "pi";
261
265
  }>;
262
266
  }, z.core.$strict>>;
263
267
  }, z.core.$strict>>;
@@ -265,9 +269,9 @@ export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
265
269
  export type RawEvidenceUploadBeginRequest = z.infer<typeof RawEvidenceUploadBeginRequestSchema>;
266
270
  export declare const RawEvidenceUploadDispositionSchema: z.ZodEnum<{
267
271
  resume: "resume";
272
+ conflict: "conflict";
268
273
  new: "new";
269
274
  already_committed: "already_committed";
270
- conflict: "conflict";
271
275
  }>;
272
276
  export type RawEvidenceUploadDisposition = z.infer<typeof RawEvidenceUploadDispositionSchema>;
273
277
  /** How a chunk's bytes are compressed on the wire (BLI-23334). `gzip` is what every collector speaks today; the door decodes all three. */
@@ -287,9 +291,9 @@ export declare const RawEvidenceUploadBeginResponseObjectSchema: z.ZodObject<{
287
291
  raw_evidence_pointer_id: z.ZodString;
288
292
  disposition: z.ZodEnum<{
289
293
  resume: "resume";
294
+ conflict: "conflict";
290
295
  new: "new";
291
296
  already_committed: "already_committed";
292
- conflict: "conflict";
293
297
  }>;
294
298
  upload_id: z.ZodOptional<z.ZodString>;
295
299
  received_chunk_indexes: z.ZodDefault<z.ZodArray<z.ZodNumber>>;
@@ -322,9 +326,9 @@ export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
322
326
  raw_evidence_pointer_id: z.ZodString;
323
327
  disposition: z.ZodEnum<{
324
328
  resume: "resume";
329
+ conflict: "conflict";
325
330
  new: "new";
326
331
  already_committed: "already_committed";
327
- conflict: "conflict";
328
332
  }>;
329
333
  upload_id: z.ZodOptional<z.ZodString>;
330
334
  received_chunk_indexes: z.ZodDefault<z.ZodArray<z.ZodNumber>>;
@@ -455,6 +459,8 @@ export declare const RawEvidenceUploadCommitRequestSchema: z.ZodObject<{
455
459
  source: z.ZodEnum<{
456
460
  codex: "codex";
457
461
  claude_code: "claude_code";
462
+ opencode: "opencode";
463
+ pi: "pi";
458
464
  }>;
459
465
  }, z.core.$strict>>;
460
466
  }, z.core.$strict>;
@@ -550,6 +556,8 @@ export type RootScope = z.infer<typeof RootScopeSchema>;
550
556
  export declare const AgentSessionSourceSchema: z.ZodDefault<z.ZodEnum<{
551
557
  codex: "codex";
552
558
  claude_code: "claude_code";
559
+ opencode: "opencode";
560
+ pi: "pi";
553
561
  }>>;
554
562
  export type AgentSessionSource = z.infer<typeof AgentSessionSourceSchema>;
555
563
  export declare const CodexSessionAttributionSchema: z.ZodObject<{
@@ -559,6 +567,8 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
559
567
  source: z.ZodDefault<z.ZodEnum<{
560
568
  codex: "codex";
561
569
  claude_code: "claude_code";
570
+ opencode: "opencode";
571
+ pi: "pi";
562
572
  }>>;
563
573
  observed_at: z.ZodString;
564
574
  attribution_state: z.ZodEnum<{
@@ -579,7 +589,30 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
579
589
  source: z.ZodEnum<{
580
590
  codex: "codex";
581
591
  claude_code: "claude_code";
592
+ opencode: "opencode";
593
+ pi: "pi";
582
594
  }>;
595
+ usage_accounting: z.ZodOptional<z.ZodEnum<{
596
+ complete: "complete";
597
+ partial: "partial";
598
+ unavailable: "unavailable";
599
+ }>>;
600
+ usage_identity_scope: z.ZodOptional<z.ZodEnum<{
601
+ machine: "machine";
602
+ operator: "operator";
603
+ }>>;
604
+ usage_claims: z.ZodOptional<z.ZodArray<z.ZodObject<{
605
+ identity: z.ZodString;
606
+ model: z.ZodString;
607
+ usage: z.ZodObject<{
608
+ input_tokens: z.ZodNumber;
609
+ output_tokens: z.ZodNumber;
610
+ cache_read_input_tokens: z.ZodNumber;
611
+ cache_creation_input_tokens: z.ZodNumber;
612
+ }, z.core.$strict>;
613
+ }, z.core.$strict>>>;
614
+ unknown_usage_records: z.ZodOptional<z.ZodNumber>;
615
+ copied_usage_records: z.ZodOptional<z.ZodNumber>;
583
616
  usage_by_model: z.ZodRecord<z.ZodString, z.ZodObject<{
584
617
  input_tokens: z.ZodNumber;
585
618
  output_tokens: z.ZodNumber;
@@ -705,6 +738,8 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
705
738
  source: z.ZodDefault<z.ZodEnum<{
706
739
  codex: "codex";
707
740
  claude_code: "claude_code";
741
+ opencode: "opencode";
742
+ pi: "pi";
708
743
  }>>;
709
744
  observed_at: z.ZodString;
710
745
  attribution_state: z.ZodEnum<{
@@ -725,7 +760,30 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
725
760
  source: z.ZodEnum<{
726
761
  codex: "codex";
727
762
  claude_code: "claude_code";
763
+ opencode: "opencode";
764
+ pi: "pi";
728
765
  }>;
766
+ usage_accounting: z.ZodOptional<z.ZodEnum<{
767
+ complete: "complete";
768
+ partial: "partial";
769
+ unavailable: "unavailable";
770
+ }>>;
771
+ usage_identity_scope: z.ZodOptional<z.ZodEnum<{
772
+ machine: "machine";
773
+ operator: "operator";
774
+ }>>;
775
+ usage_claims: z.ZodOptional<z.ZodArray<z.ZodObject<{
776
+ identity: z.ZodString;
777
+ model: z.ZodString;
778
+ usage: z.ZodObject<{
779
+ input_tokens: z.ZodNumber;
780
+ output_tokens: z.ZodNumber;
781
+ cache_read_input_tokens: z.ZodNumber;
782
+ cache_creation_input_tokens: z.ZodNumber;
783
+ }, z.core.$strict>;
784
+ }, z.core.$strict>>>;
785
+ unknown_usage_records: z.ZodOptional<z.ZodNumber>;
786
+ copied_usage_records: z.ZodOptional<z.ZodNumber>;
729
787
  usage_by_model: z.ZodRecord<z.ZodString, z.ZodObject<{
730
788
  input_tokens: z.ZodNumber;
731
789
  output_tokens: z.ZodNumber;
@@ -251,7 +251,7 @@ export const RootScopeSchema = z.enum(["inside", "outside"]);
251
251
  * working unchanged after this schema lands.
252
252
  */
253
253
  export const AgentSessionSourceSchema = z
254
- .enum(["codex", "claude_code"])
254
+ .enum(["codex", "claude_code", "opencode", "pi"])
255
255
  .default("codex");
256
256
  export const CodexSessionAttributionSchema = z
257
257
  .object({
@@ -11,7 +11,7 @@
11
11
  * - a whole-string payload: a base64 run that starts right after a `"`, starts with one of the four
12
12
  * image starts (`iVBOR`, `/9j/`, `R0lGO`, `UklGR`), is at least 495 characters past that start
13
13
  * (so 499 for a JPEG, 500 for the others, exactly as the regex counts) and is closed by `"` or `\"`;
14
- * - a data URL: `data:image/<[a-z0-9.+-]+>;base64,` and then a run of at least 500 characters, no closing
14
+ * - a data URL: `data:image/<[a-z0-9.+-]+>;base64,` and then a run of at least 4 characters (then validated by decoded image magic), no closing
15
15
  * quote needed. The whole URL is the replaced range.
16
16
  *
17
17
  * A match is accepted only when the decoded bytes sniff as PNG, JPEG, GIF or WebP; either way the scan
@@ -28,7 +28,7 @@
28
28
  * short last one, is decoded by that very function.
29
29
  */
30
30
  import { createHash } from "node:crypto";
31
- import { IMAGE_MIN_BASE64_CHARS, sniffImageMediaType } from "./image-descriptions.js";
31
+ import { IMAGE_MIN_BASE64_CHARS, IMAGE_DATA_URL_MIN_BASE64_CHARS, sniffImageMediaType } from "./image-descriptions.js";
32
32
  const QUOTE = 0x22;
33
33
  const BACKSLASH = 0x5c;
34
34
  const EQUALS = 0x3d;
@@ -117,13 +117,41 @@ function nextQuotedStart(line, anchor, from, current) {
117
117
  at = line.indexOf(anchor, at + 1);
118
118
  return at;
119
119
  }
120
+ /** Match the reference's "data" whitespace/colon prefix without copying earlier image payloads. */
121
+ function followsExplicitDataKey(line, payloadStart) {
122
+ const skipWhitespace = (end) => {
123
+ while (end > 0) {
124
+ const byte = line[end - 1];
125
+ if (byte === 0x20 || (byte >= 0x09 && byte <= 0x0d)) {
126
+ end--;
127
+ continue;
128
+ }
129
+ // JavaScript \s also admits these UTF-8 whitespace code points (all at most three bytes).
130
+ let width = 0;
131
+ for (const size of [2, 3])
132
+ if (end >= size && /^\s$/u.test(line.toString("utf8", end - size, end))) {
133
+ width = size;
134
+ break;
135
+ }
136
+ if (!width)
137
+ break;
138
+ end -= width;
139
+ }
140
+ return end;
141
+ };
142
+ let cursor = skipWhitespace(payloadStart - 1); // The quote directly before the payload.
143
+ if (line[cursor - 1] !== 0x3a)
144
+ return false;
145
+ cursor = skipWhitespace(cursor - 1);
146
+ return cursor >= 6 && line.toString("latin1", cursor - 6, cursor) === '"data"';
147
+ }
120
148
  /**
121
149
  * Every embedded image in `line` (one physical line, no `\n` inside), in order, with byte offsets inside
122
150
  * the line. Equal to `findEmbeddedImages` on the decoded text in everything but the unit of the offsets.
123
151
  */
124
152
  export function scanImagesInLine(line) {
125
153
  const found = [];
126
- if (line.length < IMAGE_MIN_BASE64_CHARS - 1)
154
+ if (line.length < IMAGE_DATA_URL_MIN_BASE64_CHARS)
127
155
  return found;
128
156
  // For each whole-string start, the next quoted occurrence (-2: not looked for yet, -1: none left).
129
157
  const nextStart = STARTS.map(() => -2);
@@ -153,7 +181,8 @@ export function scanImagesInLine(line) {
153
181
  const startLength = STARTS[kind].length;
154
182
  const end = runEnd(line, candidate);
155
183
  const closed = end < line.length && (line[end] === QUOTE || (line[end] === BACKSLASH && line[end + 1] === QUOTE));
156
- if (!closed || end - candidate < startLength + (IMAGE_MIN_BASE64_CHARS - 5)) {
184
+ const explicitData = line[end] === QUOTE && followsExplicitDataKey(line, candidate);
185
+ if (!closed || end - candidate < (explicitData ? IMAGE_DATA_URL_MIN_BASE64_CHARS : startLength + (IMAGE_MIN_BASE64_CHARS - 5))) {
157
186
  position = candidate + 1;
158
187
  continue;
159
188
  }
@@ -163,7 +192,7 @@ export function scanImagesInLine(line) {
163
192
  found.push({ replaceStart: candidate, replaceEnd: end, base64Start: candidate, base64End: end, ...digest });
164
193
  continue;
165
194
  }
166
- // data:image/<type>;base64,<run of at least 500>
195
+ // data:image/<type>;base64,<explicit image payload, including tiny images>
167
196
  let cursor = candidate + DATA_URL.length;
168
197
  const typeStart = cursor;
169
198
  while (cursor < line.length && DATA_URL_LOWER[line[cursor]] === 1)
@@ -174,7 +203,7 @@ export function scanImagesInLine(line) {
174
203
  }
175
204
  const base64Start = cursor + BASE64_TAG.length;
176
205
  const end = runEnd(line, base64Start);
177
- if (end - base64Start < IMAGE_MIN_BASE64_CHARS) {
206
+ if (end - base64Start < IMAGE_DATA_URL_MIN_BASE64_CHARS) {
178
207
  position = candidate + 1;
179
208
  continue;
180
209
  }
@@ -56,6 +56,8 @@ export declare const IMAGE_HANDLING_MODE: ImageHandlingMode;
56
56
  export declare const IMAGE_DESCRIBE_MAX_BYTES = 3000000;
57
57
  /** A base64 run shorter than this is not a screenshot (an icon, a hash, a token). */
58
58
  export declare const IMAGE_MIN_BASE64_CHARS = 500;
59
+ /** An explicit image data URL is unambiguous; magic-byte validation still decides whether it is an image. */
60
+ export declare const IMAGE_DATA_URL_MIN_BASE64_CHARS = 4;
59
61
  /** The longest description the door stores. About 300 tokens is 1,200 characters. */
60
62
  export declare const IMAGE_DESCRIPTION_MAX_CHARS = 1600;
61
63
  export declare const IMAGE_MEDIA_TYPES: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
@@ -96,6 +98,8 @@ export declare const ImageDescribeRequestSchema: z.ZodObject<{
96
98
  source: z.ZodOptional<z.ZodEnum<{
97
99
  codex: "codex";
98
100
  claude_code: "claude_code";
101
+ opencode: "opencode";
102
+ pi: "pi";
99
103
  manual: "manual";
100
104
  }>>;
101
105
  session_id: z.ZodOptional<z.ZodString>;
@@ -119,8 +123,8 @@ export type ImageDescription = z.infer<typeof ImageDescriptionSchema>;
119
123
  export declare const ImageDescribeResponseSchema: z.ZodObject<{
120
124
  ok: z.ZodLiteral<true>;
121
125
  status: z.ZodEnum<{
122
- described: "described";
123
126
  known: "known";
127
+ described: "described";
124
128
  }>;
125
129
  description: z.ZodObject<{
126
130
  sha256: z.ZodString;
@@ -49,6 +49,8 @@ export const IMAGE_HANDLING_MODE = "describe_and_keep";
49
49
  export const IMAGE_DESCRIBE_MAX_BYTES = 3_000_000;
50
50
  /** A base64 run shorter than this is not a screenshot (an icon, a hash, a token). */
51
51
  export const IMAGE_MIN_BASE64_CHARS = 500;
52
+ /** An explicit image data URL is unambiguous; magic-byte validation still decides whether it is an image. */
53
+ export const IMAGE_DATA_URL_MIN_BASE64_CHARS = 4;
52
54
  /** The longest description the door stores. About 300 tokens is 1,200 characters. */
53
55
  export const IMAGE_DESCRIPTION_MAX_CHARS = 1_600;
54
56
  // ---------------------------------------------------------------------------
@@ -125,7 +127,7 @@ export const ImageDescribeRequestSchema = z
125
127
  byte_size: z.number().int().min(1).max(IMAGE_DESCRIBE_MAX_BYTES),
126
128
  content_base64: z.string().min(8).max(Math.ceil((IMAGE_DESCRIBE_MAX_BYTES * 4) / 3) + 16),
127
129
  /** Which agent wrote the transcript the image came from. */
128
- source: z.enum(["codex", "claude_code", "manual"]).optional(),
130
+ source: z.enum(["codex", "claude_code", "opencode", "pi", "manual"]).optional(),
129
131
  /** The agent's session id, an id only, for "where did this image appear". */
130
132
  session_id: z.string().min(1).max(200).optional(),
131
133
  })
@@ -30,6 +30,8 @@ export declare const ImageUseSchema: z.ZodObject<{
30
30
  source: z.ZodEnum<{
31
31
  codex: "codex";
32
32
  claude_code: "claude_code";
33
+ opencode: "opencode";
34
+ pi: "pi";
33
35
  }>;
34
36
  }, z.core.$strict>;
35
37
  export type ImageUse = z.infer<typeof ImageUseSchema>;
@@ -35,7 +35,7 @@ export const IMAGE_USE_SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
35
35
  export const ImageUseSchema = z
36
36
  .object({
37
37
  session_id: z.string().regex(IMAGE_USE_SESSION_ID, "session_id must be an agent session id"),
38
- source: z.enum(["codex", "claude_code"]),
38
+ source: z.enum(["codex", "claude_code", "opencode", "pi"]),
39
39
  })
40
40
  .strict();
41
41
  const IMAGE_KEY = /^([A-Za-z0-9._-]+)\/images\/([0-9a-f]{64})\.(png|jpg|gif|webp)$/;
package/dist/index.d.ts CHANGED
@@ -40,6 +40,7 @@ export * from "./run-verdict.js";
40
40
  export * from "./secret-guards.js";
41
41
  export * from "./session-facts.js";
42
42
  export { codexRevisionRecordSelector } from "./codex-record-copies.js";
43
+ export * from "./t3-projection-message.js";
43
44
  export * from "./session-facts-delta.js";
44
45
  export * from "./shelf.js";
45
46
  export * from "./safe-log.js";
@@ -53,3 +54,8 @@ export * from "./ticket-id.js";
53
54
  export * from "./trace-sink.js";
54
55
  export * from "./upload-failure-class.js";
55
56
  export * from "./work-context.js";
57
+ export { openCodeTurnText, openCodeProviderIdentity, nativeObject } from "./opencode-transcript.js";
58
+ export * from "./pi-transcript.js";
59
+ export * from "./pi-transcript-usage.js";
60
+ export * from "./pi-transcript-extract.js";
61
+ export * from "./pi-transcript-lineage.js";
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ export * from "./run-verdict.js";
40
40
  export * from "./secret-guards.js";
41
41
  export * from "./session-facts.js";
42
42
  export { codexRevisionRecordSelector } from "./codex-record-copies.js";
43
+ export * from "./t3-projection-message.js";
43
44
  export * from "./session-facts-delta.js";
44
45
  export * from "./shelf.js";
45
46
  export * from "./safe-log.js";
@@ -53,3 +54,8 @@ export * from "./ticket-id.js";
53
54
  export * from "./trace-sink.js";
54
55
  export * from "./upload-failure-class.js";
55
56
  export * from "./work-context.js";
57
+ export { openCodeTurnText, openCodeProviderIdentity, nativeObject } from "./opencode-transcript.js";
58
+ export * from "./pi-transcript.js";
59
+ export * from "./pi-transcript-usage.js";
60
+ export * from "./pi-transcript-extract.js";
61
+ export * from "./pi-transcript-lineage.js";
@@ -105,10 +105,10 @@ export declare const TelemetryIngestEventDtoSchema: z.ZodObject<{
105
105
  status: z.ZodEnum<{
106
106
  unknown: "unknown";
107
107
  failed: "failed";
108
- empty: "empty";
109
108
  complete: "complete";
110
109
  partial: "partial";
111
110
  unavailable: "unavailable";
111
+ empty: "empty";
112
112
  }>;
113
113
  generated_at: z.ZodString;
114
114
  scan_window: z.ZodObject<{
@@ -589,10 +589,10 @@ export declare const TelemetryIngestEnvelopeSchema: z.ZodObject<{
589
589
  status: z.ZodEnum<{
590
590
  unknown: "unknown";
591
591
  failed: "failed";
592
- empty: "empty";
593
592
  complete: "complete";
594
593
  partial: "partial";
595
594
  unavailable: "unavailable";
595
+ empty: "empty";
596
596
  }>;
597
597
  generated_at: z.ZodString;
598
598
  scan_window: z.ZodObject<{
@@ -27,8 +27,8 @@ export declare const LocalCollectorConfigSchema: z.ZodObject<{
27
27
  shelf_metrics_allow: z.ZodOptional<z.ZodArray<z.ZodEnum<{
28
28
  model: "model";
29
29
  spawn: "spawn";
30
- day: "day";
31
30
  tool: "tool";
31
+ day: "day";
32
32
  }>>>;
33
33
  session_file_path: z.ZodOptional<z.ZodString>;
34
34
  state_dir_path: z.ZodOptional<z.ZodString>;
@@ -93,9 +93,9 @@ export declare const MEMORY_HOOK_BUCKET_PATTERN: RegExp;
93
93
  export declare const MemoryHookStatsFileSchema: z.ZodObject<{
94
94
  schema_version: z.ZodLiteral<"memory-hook-stats.v1">;
95
95
  buckets: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodEnum<{
96
+ stop: "stop";
96
97
  prompt: "prompt";
97
98
  "session-start": "session-start";
98
- stop: "stop";
99
99
  }> & z.core.$partial, z.ZodObject<{
100
100
  runs: z.ZodNumber;
101
101
  printed: z.ZodNumber;
@@ -0,0 +1,8 @@
1
+ /** Shared native usage claims reach operator ownership only after the existing evidence acknowledgment. */
2
+ import type { SessionFactsAccumulator, SessionFactsUsage } from './session-facts.js';
3
+ export declare function observeNativeUsageFacts(acc: SessionFactsAccumulator, claim: {
4
+ status: unknown;
5
+ identity: unknown;
6
+ model: unknown;
7
+ usage: SessionFactsUsage;
8
+ }): void;
@@ -0,0 +1,28 @@
1
+ export function observeNativeUsageFacts(acc, claim) {
2
+ acc.opencode_usage_records = (acc.opencode_usage_records ?? 0) + 1;
3
+ if (claim.status === 'unknown') {
4
+ acc.unknown_usage_records = (acc.unknown_usage_records ?? 0) + 1;
5
+ return;
6
+ }
7
+ if (typeof claim.identity !== 'string' || !/^[a-f0-9]{64}$/.test(claim.identity) || typeof claim.model !== 'string') {
8
+ acc.unknown_usage_records = (acc.unknown_usage_records ?? 0) + 1;
9
+ return;
10
+ }
11
+ acc.opencode_usage_claims ??= new Map();
12
+ if (!acc.opencode_usage_claims.has(claim.identity) && acc.opencode_usage_claims.size >= 1000) {
13
+ acc.unknown_usage_records = (acc.unknown_usage_records ?? 0) + 1;
14
+ return;
15
+ }
16
+ acc.opencode_usage_claims.set(claim.identity, { identity: claim.identity, model: claim.model.slice(0, 200), usage: claim.usage });
17
+ if (claim.status === 'copied') {
18
+ acc.copied_usage_records = (acc.copied_usage_records ?? 0) + 1;
19
+ return;
20
+ }
21
+ if (claim.status !== 'known' || acc.seen_usage_ids.has(claim.identity))
22
+ return;
23
+ acc.seen_usage_ids.add(claim.identity);
24
+ const usage = acc.usage_by_model[claim.model] ?? { input_tokens: 0, output_tokens: 0, cache_read_input_tokens: 0, cache_creation_input_tokens: 0 };
25
+ for (const key of Object.keys(usage))
26
+ usage[key] += claim.usage[key];
27
+ acc.usage_by_model[claim.model] = usage;
28
+ }
@@ -0,0 +1,8 @@
1
+ import type { SessionFactsAccumulator } from "./session-facts.js";
2
+ export declare function nativeObject(value: unknown): Record<string, unknown>;
3
+ /** Text comes from native text parts; reasoning, tool output and unknown parts remain separate evidence. */
4
+ export declare function openCodeTurnText(record: Record<string, unknown>, role: "user" | "assistant"): string | null;
5
+ /** Only explicit provider item identities can account copied usage; native message IDs change on a real fork. */
6
+ export declare function openCodeProviderIdentity(info: Record<string, unknown>, parts: Record<string, unknown>[]): string | null;
7
+ /** Count native roles/tools and explicitly accounted usage without treating absent usage as zero coverage. */
8
+ export declare function observeOpenCodeFacts(acc: SessionFactsAccumulator, record: Record<string, unknown>): void;