@bli-cockpit/telemetry-core 0.1.97 → 0.1.98

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.
@@ -4,6 +4,7 @@ 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";
7
8
  }>;
8
9
  export type AgentArtifactSource = z.infer<typeof AgentArtifactSourceSchema>;
9
10
  export declare const AgentArtifactKindSchema: z.ZodEnum<{
@@ -86,6 +87,7 @@ export declare const AgentImageArtifactSchema: z.ZodObject<{
86
87
  agent_source: z.ZodEnum<{
87
88
  codex: "codex";
88
89
  claude_code: "claude_code";
90
+ opencode: "opencode";
89
91
  }>;
90
92
  source_session_id: z.ZodString;
91
93
  source_message_id: z.ZodOptional<z.ZodString>;
@@ -179,6 +181,7 @@ export declare const AgentImageArtifactReportRequestSchema: z.ZodObject<{
179
181
  agent_source: z.ZodEnum<{
180
182
  codex: "codex";
181
183
  claude_code: "claude_code";
184
+ opencode: "opencode";
182
185
  }>;
183
186
  source_session_id: z.ZodString;
184
187
  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"]);
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,6 +38,7 @@ 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.
@@ -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";
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)\/([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] === "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";
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)\/([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] === "opencode" ? "opencode" : main[1] === "codex" ? "codex" : "claude_code",
67
67
  session_id: main[2],
68
68
  sidecar: null,
69
69
  };
@@ -141,6 +141,7 @@ export declare const RawEvidenceUploadBeginObjectSchema: z.ZodObject<{
141
141
  source: z.ZodEnum<{
142
142
  codex: "codex";
143
143
  claude_code: "claude_code";
144
+ opencode: "opencode";
144
145
  }>;
145
146
  }, z.core.$strict>>;
146
147
  }, z.core.$strict>;
@@ -258,6 +259,7 @@ export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
258
259
  source: z.ZodEnum<{
259
260
  codex: "codex";
260
261
  claude_code: "claude_code";
262
+ opencode: "opencode";
261
263
  }>;
262
264
  }, z.core.$strict>>;
263
265
  }, z.core.$strict>>;
@@ -455,6 +457,7 @@ export declare const RawEvidenceUploadCommitRequestSchema: z.ZodObject<{
455
457
  source: z.ZodEnum<{
456
458
  codex: "codex";
457
459
  claude_code: "claude_code";
460
+ opencode: "opencode";
458
461
  }>;
459
462
  }, z.core.$strict>>;
460
463
  }, z.core.$strict>;
@@ -550,6 +553,7 @@ export type RootScope = z.infer<typeof RootScopeSchema>;
550
553
  export declare const AgentSessionSourceSchema: z.ZodDefault<z.ZodEnum<{
551
554
  codex: "codex";
552
555
  claude_code: "claude_code";
556
+ opencode: "opencode";
553
557
  }>>;
554
558
  export type AgentSessionSource = z.infer<typeof AgentSessionSourceSchema>;
555
559
  export declare const CodexSessionAttributionSchema: z.ZodObject<{
@@ -559,6 +563,7 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
559
563
  source: z.ZodDefault<z.ZodEnum<{
560
564
  codex: "codex";
561
565
  claude_code: "claude_code";
566
+ opencode: "opencode";
562
567
  }>>;
563
568
  observed_at: z.ZodString;
564
569
  attribution_state: z.ZodEnum<{
@@ -579,7 +584,29 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
579
584
  source: z.ZodEnum<{
580
585
  codex: "codex";
581
586
  claude_code: "claude_code";
587
+ opencode: "opencode";
582
588
  }>;
589
+ usage_accounting: z.ZodOptional<z.ZodEnum<{
590
+ complete: "complete";
591
+ partial: "partial";
592
+ unavailable: "unavailable";
593
+ }>>;
594
+ usage_identity_scope: z.ZodOptional<z.ZodEnum<{
595
+ machine: "machine";
596
+ operator: "operator";
597
+ }>>;
598
+ usage_claims: z.ZodOptional<z.ZodArray<z.ZodObject<{
599
+ identity: z.ZodString;
600
+ model: z.ZodString;
601
+ usage: z.ZodObject<{
602
+ input_tokens: z.ZodNumber;
603
+ output_tokens: z.ZodNumber;
604
+ cache_read_input_tokens: z.ZodNumber;
605
+ cache_creation_input_tokens: z.ZodNumber;
606
+ }, z.core.$strict>;
607
+ }, z.core.$strict>>>;
608
+ unknown_usage_records: z.ZodOptional<z.ZodNumber>;
609
+ copied_usage_records: z.ZodOptional<z.ZodNumber>;
583
610
  usage_by_model: z.ZodRecord<z.ZodString, z.ZodObject<{
584
611
  input_tokens: z.ZodNumber;
585
612
  output_tokens: z.ZodNumber;
@@ -705,6 +732,7 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
705
732
  source: z.ZodDefault<z.ZodEnum<{
706
733
  codex: "codex";
707
734
  claude_code: "claude_code";
735
+ opencode: "opencode";
708
736
  }>>;
709
737
  observed_at: z.ZodString;
710
738
  attribution_state: z.ZodEnum<{
@@ -725,7 +753,29 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
725
753
  source: z.ZodEnum<{
726
754
  codex: "codex";
727
755
  claude_code: "claude_code";
756
+ opencode: "opencode";
728
757
  }>;
758
+ usage_accounting: z.ZodOptional<z.ZodEnum<{
759
+ complete: "complete";
760
+ partial: "partial";
761
+ unavailable: "unavailable";
762
+ }>>;
763
+ usage_identity_scope: z.ZodOptional<z.ZodEnum<{
764
+ machine: "machine";
765
+ operator: "operator";
766
+ }>>;
767
+ usage_claims: z.ZodOptional<z.ZodArray<z.ZodObject<{
768
+ identity: z.ZodString;
769
+ model: z.ZodString;
770
+ usage: z.ZodObject<{
771
+ input_tokens: z.ZodNumber;
772
+ output_tokens: z.ZodNumber;
773
+ cache_read_input_tokens: z.ZodNumber;
774
+ cache_creation_input_tokens: z.ZodNumber;
775
+ }, z.core.$strict>;
776
+ }, z.core.$strict>>>;
777
+ unknown_usage_records: z.ZodOptional<z.ZodNumber>;
778
+ copied_usage_records: z.ZodOptional<z.ZodNumber>;
729
779
  usage_by_model: z.ZodRecord<z.ZodString, z.ZodObject<{
730
780
  input_tokens: z.ZodNumber;
731
781
  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"])
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;
@@ -123,7 +123,7 @@ function nextQuotedStart(line, anchor, from, current) {
123
123
  */
124
124
  export function scanImagesInLine(line) {
125
125
  const found = [];
126
- if (line.length < IMAGE_MIN_BASE64_CHARS - 1)
126
+ if (line.length < IMAGE_DATA_URL_MIN_BASE64_CHARS)
127
127
  return found;
128
128
  // For each whole-string start, the next quoted occurrence (-2: not looked for yet, -1: none left).
129
129
  const nextStart = STARTS.map(() => -2);
@@ -163,7 +163,7 @@ export function scanImagesInLine(line) {
163
163
  found.push({ replaceStart: candidate, replaceEnd: end, base64Start: candidate, base64End: end, ...digest });
164
164
  continue;
165
165
  }
166
- // data:image/<type>;base64,<run of at least 500>
166
+ // data:image/<type>;base64,<explicit image payload, including tiny images>
167
167
  let cursor = candidate + DATA_URL.length;
168
168
  const typeStart = cursor;
169
169
  while (cursor < line.length && DATA_URL_LOWER[line[cursor]] === 1)
@@ -174,7 +174,7 @@ export function scanImagesInLine(line) {
174
174
  }
175
175
  const base64Start = cursor + BASE64_TAG.length;
176
176
  const end = runEnd(line, base64Start);
177
- if (end - base64Start < IMAGE_MIN_BASE64_CHARS) {
177
+ if (end - base64Start < IMAGE_DATA_URL_MIN_BASE64_CHARS) {
178
178
  position = candidate + 1;
179
179
  continue;
180
180
  }
@@ -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,7 @@ 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";
99
102
  manual: "manual";
100
103
  }>>;
101
104
  session_id: z.ZodOptional<z.ZodString>;
@@ -119,8 +122,8 @@ export type ImageDescription = z.infer<typeof ImageDescriptionSchema>;
119
122
  export declare const ImageDescribeResponseSchema: z.ZodObject<{
120
123
  ok: z.ZodLiteral<true>;
121
124
  status: z.ZodEnum<{
122
- described: "described";
123
125
  known: "known";
126
+ described: "described";
124
127
  }>;
125
128
  description: z.ZodObject<{
126
129
  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", "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,7 @@ export declare const ImageUseSchema: z.ZodObject<{
30
30
  source: z.ZodEnum<{
31
31
  codex: "codex";
32
32
  claude_code: "claude_code";
33
+ opencode: "opencode";
33
34
  }>;
34
35
  }, z.core.$strict>;
35
36
  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"]),
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,4 @@ 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";
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,4 @@ 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";
@@ -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>;
@@ -0,0 +1,9 @@
1
+ /** Native OpenCode semantics, shared by collection and downloaded-evidence readers. */
2
+ import type { SessionFactsAccumulator } from "./session-facts.js";
3
+ export declare function nativeObject(value: unknown): Record<string, unknown>;
4
+ /** Text comes from native text parts; reasoning, tool output and unknown parts remain separate evidence. */
5
+ export declare function openCodeTurnText(record: Record<string, unknown>, role: "user" | "assistant"): string | null;
6
+ /** Only explicit provider item identities can account copied usage; native message IDs change on a real fork. */
7
+ export declare function openCodeProviderIdentity(info: Record<string, unknown>, parts: Record<string, unknown>[]): string | null;
8
+ /** Count native roles/tools and explicitly accounted usage without treating absent usage as zero coverage. */
9
+ export declare function observeOpenCodeFacts(acc: SessionFactsAccumulator, record: Record<string, unknown>): void;
@@ -0,0 +1,97 @@
1
+ export function nativeObject(value) {
2
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
3
+ }
4
+ /** Text comes from native text parts; reasoning, tool output and unknown parts remain separate evidence. */
5
+ export function openCodeTurnText(record, role) {
6
+ if (record.type === "opencode_part") {
7
+ const part = nativeObject(record.part);
8
+ return !(role === "user" && (part.synthetic === true || part.ignored === true)) && record.role === role && part.type === "text" && typeof part.text === "string" ? part.text : null;
9
+ }
10
+ const info = nativeObject(record.info);
11
+ if (record.type !== "opencode_message" || info.role !== role || !Array.isArray(record.parts))
12
+ return null;
13
+ return record.parts.map(nativeObject).filter((part) => !(role === "user" && (part.synthetic === true || part.ignored === true)) && part.type === "text" && typeof part.text === "string").map((part) => part.text).join("\n") || null;
14
+ }
15
+ /** Only explicit provider item identities can account copied usage; native message IDs change on a real fork. */
16
+ export function openCodeProviderIdentity(info, parts) {
17
+ const provider = typeof info.providerID === "string" ? info.providerID : null;
18
+ const ids = new Set();
19
+ for (const part of parts) {
20
+ for (const [name, value] of Object.entries(nativeObject(part.metadata))) {
21
+ const itemId = nativeObject(value).itemId;
22
+ if (name === provider && typeof itemId === "string" && itemId)
23
+ ids.add(itemId);
24
+ }
25
+ }
26
+ return provider && ids.size ? JSON.stringify([provider, ...[...ids].sort()]) : null;
27
+ }
28
+ /** Count native roles/tools and explicitly accounted usage without treating absent usage as zero coverage. */
29
+ export function observeOpenCodeFacts(acc, record) {
30
+ const info = nativeObject(record.info);
31
+ const time = nativeObject(info.time);
32
+ const partTime = nativeObject(nativeObject(record.part).time);
33
+ for (const value of [time.created, time.completed, partTime.start, partTime.end]) {
34
+ if (typeof value !== "number" || !Number.isFinite(value))
35
+ continue;
36
+ acc.timestamps_ms.push(value);
37
+ acc.first_timestamp_ms = acc.first_timestamp_ms == null ? value : Math.min(acc.first_timestamp_ms, value);
38
+ acc.last_timestamp_ms = acc.last_timestamp_ms == null ? value : Math.max(acc.last_timestamp_ms, value);
39
+ }
40
+ if (record.type === "opencode_message" && info.role === "assistant")
41
+ acc.opencode_usage_messages = (acc.opencode_usage_messages ?? 0) + 1;
42
+ const parts = record.type === "opencode_part" ? [nativeObject(record.part)] : Array.isArray(record.parts) ? record.parts.map(nativeObject) : [];
43
+ const role = record.type === "opencode_part" ? record.role : info.role;
44
+ for (const part of parts) {
45
+ const messageId = String(part.messageID ?? info.id ?? "");
46
+ if (!(role === "user" && (part.synthetic === true || part.ignored === true)) && part.type === "text" && typeof part.text === "string" && part.text.trim()) {
47
+ const turnKey = `turn:${role}:${messageId}`;
48
+ if (!acc.seen_usage_ids.has(turnKey)) {
49
+ acc.seen_usage_ids.add(turnKey);
50
+ if (role === "user")
51
+ acc.user_prompt_count += 1;
52
+ if (role === "assistant")
53
+ acc.assistant_response_count += 1;
54
+ }
55
+ }
56
+ if (part.type === "tool") {
57
+ const key = `tool:${String(part.callID ?? part.id ?? "")}`;
58
+ if (!acc.seen_usage_ids.has(key)) {
59
+ acc.seen_usage_ids.add(key);
60
+ const name = typeof part.tool === "string" ? part.tool.slice(0, 120) : "unknown";
61
+ acc.tool_calls_by_name[name] = (acc.tool_calls_by_name[name] ?? 0) + 1;
62
+ }
63
+ }
64
+ }
65
+ if (record.type !== "opencode_usage")
66
+ return;
67
+ acc.opencode_usage_records = (acc.opencode_usage_records ?? 0) + 1;
68
+ if (record.status === "unknown") {
69
+ acc.unknown_usage_records = (acc.unknown_usage_records ?? 0) + 1;
70
+ return;
71
+ }
72
+ if (typeof record.identity !== "string" || !/^[a-f0-9]{64}$/.test(record.identity) || typeof record.model !== "string")
73
+ return;
74
+ const tokens = nativeObject(record.tokens);
75
+ const cache = nativeObject(tokens.cache);
76
+ const number = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
77
+ const claimedUsage = { input_tokens: number(tokens.input), output_tokens: number(tokens.output) + number(tokens.reasoning), cache_read_input_tokens: number(cache.read), cache_creation_input_tokens: number(cache.write) };
78
+ acc.opencode_usage_claims ??= new Map();
79
+ if (!acc.opencode_usage_claims.has(record.identity) && acc.opencode_usage_claims.size >= 1000) {
80
+ acc.unknown_usage_records = (acc.unknown_usage_records ?? 0) + 1;
81
+ return;
82
+ }
83
+ acc.opencode_usage_claims.set(record.identity, { identity: record.identity, model: record.model.slice(0, 200), usage: claimedUsage });
84
+ if (record.status === "copied") {
85
+ acc.copied_usage_records = (acc.copied_usage_records ?? 0) + 1;
86
+ return;
87
+ }
88
+ if (record.status !== "known" || acc.seen_usage_ids.has(record.identity))
89
+ return;
90
+ acc.seen_usage_ids.add(record.identity);
91
+ const usage = acc.usage_by_model[record.model] ?? { input_tokens: 0, output_tokens: 0, cache_read_input_tokens: 0, cache_creation_input_tokens: 0 };
92
+ usage.input_tokens += number(tokens.input);
93
+ usage.output_tokens += number(tokens.output) + number(tokens.reasoning);
94
+ usage.cache_read_input_tokens += number(cache.read);
95
+ usage.cache_creation_input_tokens += number(cache.write);
96
+ acc.usage_by_model[record.model] = usage;
97
+ }