@bli-cockpit/telemetry-core 0.1.91 → 0.1.93

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.
@@ -0,0 +1,73 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The collector giving up on an object it already opened (BLI-2539).
4
+ *
5
+ * `begin` writes a ledger row for every object in the batch, then chunks go one
6
+ * object at a time. When one object's chunks fail its siblings still finish, so
7
+ * the production shape is a single failure among committed rows rather than a
8
+ * truncated batch. The collector knows exactly why that object died — it
9
+ * composes labels like `chunk_0_failed_http_500` — and until this route existed
10
+ * it had nowhere to send them: begin/chunk/commit has no call meaning "I quit".
11
+ * The row stayed `pending` with a null reason until a drain relabelled it
12
+ * `staging_incomplete`, which describes the shape and not the cause. 275 rows
13
+ * reached that state by 2026-08-14.
14
+ *
15
+ * The reason is a label, never free text or an error body: it lands in
16
+ * `status_reason`, which is read by `classifyUploadFailure`, and an unlisted
17
+ * label classifies as `unknown` rather than being guessed into a bucket. That
18
+ * is also what keeps these rows recoverable — `unknown` is not permanent, so
19
+ * the row stays open (still `pending`, staged chunks intact) and the next
20
+ * `begin` resumes it. Only a reason classified permanent fails the row closed.
21
+ */
22
+ export declare const RawEvidenceUploadAbortRequestSchema: z.ZodObject<{
23
+ schema_version: z.ZodLiteral<"ambient-raw-evidence-upload-abort.v1">;
24
+ generated_at: z.ZodString;
25
+ provenance: z.ZodObject<{
26
+ capture_source: z.ZodEnum<{
27
+ unknown: "unknown";
28
+ codex_jsonl: "codex_jsonl";
29
+ codex_otel: "codex_otel";
30
+ car_state: "car_state";
31
+ git_state: "git_state";
32
+ github_state: "github_state";
33
+ linear_state: "linear_state";
34
+ mcp_local: "mcp_local";
35
+ claude_jsonl: "claude_jsonl";
36
+ claude_hooks: "claude_hooks";
37
+ manual_event: "manual_event";
38
+ collector_runtime: "collector_runtime";
39
+ }>;
40
+ capture_adapter_version: z.ZodString;
41
+ collector_version: z.ZodString;
42
+ repo: z.ZodString;
43
+ branch: z.ZodString;
44
+ repo_label: z.ZodOptional<z.ZodString>;
45
+ repo_fingerprint: z.ZodOptional<z.ZodString>;
46
+ repo_origin_url: z.ZodOptional<z.ZodString>;
47
+ worktree_label: z.ZodOptional<z.ZodString>;
48
+ worktree_fingerprint: z.ZodOptional<z.ZodString>;
49
+ worktree_is_primary: z.ZodOptional<z.ZodBoolean>;
50
+ operator_id: z.ZodString;
51
+ session_id: z.ZodString;
52
+ work_context_id: z.ZodString;
53
+ }, z.core.$strict>;
54
+ upload_id: z.ZodString;
55
+ object_key: z.ZodString;
56
+ reason: z.ZodString;
57
+ uploaded_chunk_count: z.ZodOptional<z.ZodNumber>;
58
+ }, z.core.$strict>;
59
+ export type RawEvidenceUploadAbortRequest = z.infer<typeof RawEvidenceUploadAbortRequestSchema>;
60
+ export declare const RawEvidenceUploadAbortResponseSchema: z.ZodObject<{
61
+ ok: z.ZodLiteral<true>;
62
+ status: z.ZodEnum<{
63
+ reason_recorded: "reason_recorded";
64
+ aborted: "aborted";
65
+ already_terminal: "already_terminal";
66
+ }>;
67
+ upload_id: z.ZodString;
68
+ object_key: z.ZodString;
69
+ status_reason: z.ZodString;
70
+ retryable: z.ZodBoolean;
71
+ will_reopen: z.ZodBoolean;
72
+ }, z.core.$strict>;
73
+ export type RawEvidenceUploadAbortResponse = z.infer<typeof RawEvidenceUploadAbortResponseSchema>;
@@ -0,0 +1,69 @@
1
+ import { z } from "zod";
2
+ import { CaptureProvenanceSchema, IsoDateTimeSchema, NonEmptyStringSchema, } from "./common.js";
3
+ import { SafeLabelSchema } from "./evidence-upload.js";
4
+ /**
5
+ * The collector giving up on an object it already opened (BLI-2539).
6
+ *
7
+ * `begin` writes a ledger row for every object in the batch, then chunks go one
8
+ * object at a time. When one object's chunks fail its siblings still finish, so
9
+ * the production shape is a single failure among committed rows rather than a
10
+ * truncated batch. The collector knows exactly why that object died — it
11
+ * composes labels like `chunk_0_failed_http_500` — and until this route existed
12
+ * it had nowhere to send them: begin/chunk/commit has no call meaning "I quit".
13
+ * The row stayed `pending` with a null reason until a drain relabelled it
14
+ * `staging_incomplete`, which describes the shape and not the cause. 275 rows
15
+ * reached that state by 2026-08-14.
16
+ *
17
+ * The reason is a label, never free text or an error body: it lands in
18
+ * `status_reason`, which is read by `classifyUploadFailure`, and an unlisted
19
+ * label classifies as `unknown` rather than being guessed into a bucket. That
20
+ * is also what keeps these rows recoverable — `unknown` is not permanent, so
21
+ * the row stays open (still `pending`, staged chunks intact) and the next
22
+ * `begin` resumes it. Only a reason classified permanent fails the row closed.
23
+ */
24
+ export const RawEvidenceUploadAbortRequestSchema = z
25
+ .object({
26
+ schema_version: z.literal("ambient-raw-evidence-upload-abort.v1"),
27
+ generated_at: IsoDateTimeSchema,
28
+ provenance: CaptureProvenanceSchema,
29
+ upload_id: NonEmptyStringSchema,
30
+ object_key: NonEmptyStringSchema,
31
+ reason: SafeLabelSchema,
32
+ // How far the object actually got before the collector gave up. The server
33
+ // already knows the received chunk count; this is what the CLIENT believed,
34
+ // and a disagreement between the two is itself worth being able to see.
35
+ uploaded_chunk_count: z.number().int().nonnegative().optional(),
36
+ })
37
+ .strict();
38
+ export const RawEvidenceUploadAbortResponseSchema = z
39
+ .object({
40
+ ok: z.literal(true),
41
+ // `reason_recorded` is the ordinary answer: the reason landed on the
42
+ // still-open row, whose staged chunks stay resumable by the next `begin`.
43
+ // `aborted` means the reason was classified permanent and the row failed
44
+ // closed. `already_terminal` covers a row the server had already settled —
45
+ // a drain that ran first, or a duplicate abort after a retry. Reporting
46
+ // these back distinguishes "we recorded your reason" from "someone beat
47
+ // you to it", which a bare 200 would hide.
48
+ status: z.enum(["reason_recorded", "aborted", "already_terminal"]),
49
+ upload_id: NonEmptyStringSchema,
50
+ object_key: NonEmptyStringSchema,
51
+ status_reason: SafeLabelSchema,
52
+ // Two booleans because the underlying questions are not each other's
53
+ // negation, and one field would have to lie about half of them.
54
+ //
55
+ // `retryable` is `isRetryableUploadFailure`: is repeating this KNOWN to
56
+ // help? An unclassified reason answers no — refusing to promise something
57
+ // nobody has reasoned about.
58
+ //
59
+ // `will_reopen` is `!isPermanentUploadFailure`: is this row still open (or
60
+ // re-openable) for the next `begin`? An unclassified reason answers yes —
61
+ // refusing to abandon an object over a word it cannot read.
62
+ //
63
+ // So a composed transport label like `chunk_0_failed_http_500` comes back
64
+ // `retryable: false, will_reopen: true`, which is the honest pair: we are
65
+ // not claiming a retry succeeds, and we are not writing the row off.
66
+ retryable: z.boolean(),
67
+ will_reopen: z.boolean(),
68
+ })
69
+ .strict();
@@ -0,0 +1,26 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * BLI-23345: the base a grown transcript extends. The collector names the snapshot it last committed
4
+ * (it holds the hash and size; the pointer's supersede claim already names the key) and sends only the
5
+ * bytes after `base_byte_size`; the server composes base + tail into the final object. A request with
6
+ * this field plans `chunk_count` over the TAIL, not the final object. Size and count ceilings are the
7
+ * begin route's to enforce (the base must be smaller than a final object that already passed them).
8
+ */
9
+ export declare const RawEvidenceUploadExtendRequestSchema: z.ZodObject<{
10
+ base_object_key: z.ZodString;
11
+ base_content_hash_sha256: z.ZodString;
12
+ base_byte_size: z.ZodNumber;
13
+ }, z.core.$strict>;
14
+ export type RawEvidenceUploadExtendRequest = z.infer<typeof RawEvidenceUploadExtendRequestSchema>;
15
+ /** The tail plan the server accepted: the base it will read, where the tail starts, and its geometry. */
16
+ export declare const RawEvidenceUploadExtendAcceptedSchema: z.ZodObject<{
17
+ base_object_key: z.ZodString;
18
+ base_content_hash_sha256: z.ZodString;
19
+ base_byte_size: z.ZodNumber;
20
+ tail_offset: z.ZodNumber;
21
+ tail_size: z.ZodNumber;
22
+ chunk_count: z.ZodNumber;
23
+ }, z.core.$strict>;
24
+ export type RawEvidenceUploadExtendAccepted = z.infer<typeof RawEvidenceUploadExtendAcceptedSchema>;
25
+ /** Commit refusal: the base object is gone or no longer matches; re-offer the whole object. */
26
+ export declare const EXTEND_BASE_UNAVAILABLE = "extend_base_unavailable";
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ import { NonEmptyStringSchema, Sha256Schema } from "./common.js";
3
+ /**
4
+ * BLI-23345: the base a grown transcript extends. The collector names the snapshot it last committed
5
+ * (it holds the hash and size; the pointer's supersede claim already names the key) and sends only the
6
+ * bytes after `base_byte_size`; the server composes base + tail into the final object. A request with
7
+ * this field plans `chunk_count` over the TAIL, not the final object. Size and count ceilings are the
8
+ * begin route's to enforce (the base must be smaller than a final object that already passed them).
9
+ */
10
+ export const RawEvidenceUploadExtendRequestSchema = z
11
+ .object({
12
+ base_object_key: NonEmptyStringSchema,
13
+ base_content_hash_sha256: Sha256Schema,
14
+ base_byte_size: z.number().int().positive(),
15
+ })
16
+ .strict();
17
+ /** The tail plan the server accepted: the base it will read, where the tail starts, and its geometry. */
18
+ export const RawEvidenceUploadExtendAcceptedSchema = RawEvidenceUploadExtendRequestSchema.extend({
19
+ tail_offset: z.number().int().positive(),
20
+ tail_size: z.number().int().positive(),
21
+ chunk_count: z.number().int().positive(),
22
+ }).strict();
23
+ /** Commit refusal: the base object is gone or no longer matches; re-offer the whole object. */
24
+ export const EXTEND_BASE_UNAVAILABLE = "extend_base_unavailable";
@@ -13,6 +13,7 @@ export declare const RAW_EVIDENCE_UPLOAD_MAX_CHUNK_COUNT = 192;
13
13
  export declare const RAW_EVIDENCE_UPLOAD_MAX_FILE_BYTES: number;
14
14
  export declare const RAW_EVIDENCE_UPLOAD_MAX_OBJECTS_PER_BEGIN = 25;
15
15
  export declare const CODEX_SESSION_REPORT_MAX_SESSIONS = 200;
16
+ export declare const SafeLabelSchema: z.ZodString;
16
17
  /**
17
18
  * Receipt returned by the pre-ledger single-shot upload route. Older
18
19
  * dashboards still use this path, so the collector must prove that a 2xx
@@ -128,8 +129,20 @@ export declare const RawEvidenceUploadBeginObjectSchema: z.ZodObject<{
128
129
  stub_replaced: "stub_replaced";
129
130
  }>>;
130
131
  }, z.core.$strict>;
132
+ extend: z.ZodOptional<z.ZodObject<{
133
+ base_object_key: z.ZodString;
134
+ base_content_hash_sha256: z.ZodString;
135
+ base_byte_size: z.ZodNumber;
136
+ }, z.core.$strict>>;
131
137
  chunk_size_bytes: z.ZodNumber;
132
138
  chunk_count: z.ZodNumber;
139
+ image_use: z.ZodOptional<z.ZodObject<{
140
+ session_id: z.ZodString;
141
+ source: z.ZodEnum<{
142
+ codex: "codex";
143
+ claude_code: "claude_code";
144
+ }>;
145
+ }, z.core.$strict>>;
133
146
  }, z.core.$strict>;
134
147
  export type RawEvidenceUploadBeginObject = z.infer<typeof RawEvidenceUploadBeginObjectSchema>;
135
148
  export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
@@ -233,8 +246,20 @@ export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
233
246
  stub_replaced: "stub_replaced";
234
247
  }>>;
235
248
  }, z.core.$strict>;
249
+ extend: z.ZodOptional<z.ZodObject<{
250
+ base_object_key: z.ZodString;
251
+ base_content_hash_sha256: z.ZodString;
252
+ base_byte_size: z.ZodNumber;
253
+ }, z.core.$strict>>;
236
254
  chunk_size_bytes: z.ZodNumber;
237
255
  chunk_count: z.ZodNumber;
256
+ image_use: z.ZodOptional<z.ZodObject<{
257
+ session_id: z.ZodString;
258
+ source: z.ZodEnum<{
259
+ codex: "codex";
260
+ claude_code: "claude_code";
261
+ }>;
262
+ }, z.core.$strict>>;
238
263
  }, z.core.$strict>>;
239
264
  }, z.core.$strict>;
240
265
  export type RawEvidenceUploadBeginRequest = z.infer<typeof RawEvidenceUploadBeginRequestSchema>;
@@ -279,6 +304,15 @@ export declare const RawEvidenceUploadBeginResponseObjectSchema: z.ZodObject<{
279
304
  zstd: "zstd";
280
305
  br: "br";
281
306
  }>>>;
307
+ extend: z.ZodOptional<z.ZodObject<{
308
+ base_object_key: z.ZodString;
309
+ base_content_hash_sha256: z.ZodString;
310
+ base_byte_size: z.ZodNumber;
311
+ tail_offset: z.ZodNumber;
312
+ tail_size: z.ZodNumber;
313
+ chunk_count: z.ZodNumber;
314
+ }, z.core.$strict>>;
315
+ extend_refused: z.ZodOptional<z.ZodString>;
282
316
  }, z.core.$strict>;
283
317
  export type RawEvidenceUploadBeginResponseObject = z.infer<typeof RawEvidenceUploadBeginResponseObjectSchema>;
284
318
  export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
@@ -305,6 +339,15 @@ export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
305
339
  zstd: "zstd";
306
340
  br: "br";
307
341
  }>>>;
342
+ extend: z.ZodOptional<z.ZodObject<{
343
+ base_object_key: z.ZodString;
344
+ base_content_hash_sha256: z.ZodString;
345
+ base_byte_size: z.ZodNumber;
346
+ tail_offset: z.ZodNumber;
347
+ tail_size: z.ZodNumber;
348
+ chunk_count: z.ZodNumber;
349
+ }, z.core.$strict>>;
350
+ extend_refused: z.ZodOptional<z.ZodString>;
308
351
  }, z.core.$strict>>;
309
352
  }, z.core.$strict>;
310
353
  export type RawEvidenceUploadBeginResponse = z.infer<typeof RawEvidenceUploadBeginResponseSchema>;
@@ -407,6 +450,13 @@ export declare const RawEvidenceUploadCommitRequestSchema: z.ZodObject<{
407
450
  byte_size: z.ZodNumber;
408
451
  chunk_hash_sha256: z.ZodString;
409
452
  }, z.core.$strict>>>;
453
+ image_use: z.ZodOptional<z.ZodObject<{
454
+ session_id: z.ZodString;
455
+ source: z.ZodEnum<{
456
+ codex: "codex";
457
+ claude_code: "claude_code";
458
+ }>;
459
+ }, z.core.$strict>>;
410
460
  }, z.core.$strict>;
411
461
  export type RawEvidenceUploadCommitRequest = z.infer<typeof RawEvidenceUploadCommitRequestSchema>;
412
462
  export declare const RawEvidenceUploadCommitResponseSchema: z.ZodObject<{
@@ -451,78 +501,6 @@ export declare const RawEvidenceUploadCommitResponseSchema: z.ZodObject<{
451
501
  }, z.core.$strict>>;
452
502
  }, z.core.$strict>;
453
503
  export type RawEvidenceUploadCommitResponse = z.infer<typeof RawEvidenceUploadCommitResponseSchema>;
454
- /**
455
- * The collector giving up on an object it already opened (BLI-2539).
456
- *
457
- * `begin` writes a ledger row for every object in the batch, then chunks go one
458
- * object at a time. When one object's chunks fail its siblings still finish, so
459
- * the production shape is a single failure among committed rows rather than a
460
- * truncated batch. The collector knows exactly why that object died — it
461
- * composes labels like `chunk_0_failed_http_500` — and until this route existed
462
- * it had nowhere to send them: begin/chunk/commit has no call meaning "I quit".
463
- * The row stayed `pending` with a null reason until a drain relabelled it
464
- * `staging_incomplete`, which describes the shape and not the cause. 275 rows
465
- * reached that state by 2026-08-14.
466
- *
467
- * The reason is a label, never free text or an error body: it lands in
468
- * `status_reason`, which is read by `classifyUploadFailure`, and an unlisted
469
- * label classifies as `unknown` rather than being guessed into a bucket. That
470
- * is also what keeps these rows recoverable — `unknown` is not permanent, so
471
- * the row stays open (still `pending`, staged chunks intact) and the next
472
- * `begin` resumes it. Only a reason classified permanent fails the row closed.
473
- */
474
- export declare const RawEvidenceUploadAbortRequestSchema: z.ZodObject<{
475
- schema_version: z.ZodLiteral<"ambient-raw-evidence-upload-abort.v1">;
476
- generated_at: z.ZodString;
477
- provenance: z.ZodObject<{
478
- capture_source: z.ZodEnum<{
479
- unknown: "unknown";
480
- codex_jsonl: "codex_jsonl";
481
- codex_otel: "codex_otel";
482
- car_state: "car_state";
483
- git_state: "git_state";
484
- github_state: "github_state";
485
- linear_state: "linear_state";
486
- mcp_local: "mcp_local";
487
- claude_jsonl: "claude_jsonl";
488
- claude_hooks: "claude_hooks";
489
- manual_event: "manual_event";
490
- collector_runtime: "collector_runtime";
491
- }>;
492
- capture_adapter_version: z.ZodString;
493
- collector_version: z.ZodString;
494
- repo: z.ZodString;
495
- branch: z.ZodString;
496
- repo_label: z.ZodOptional<z.ZodString>;
497
- repo_fingerprint: z.ZodOptional<z.ZodString>;
498
- repo_origin_url: z.ZodOptional<z.ZodString>;
499
- worktree_label: z.ZodOptional<z.ZodString>;
500
- worktree_fingerprint: z.ZodOptional<z.ZodString>;
501
- worktree_is_primary: z.ZodOptional<z.ZodBoolean>;
502
- operator_id: z.ZodString;
503
- session_id: z.ZodString;
504
- work_context_id: z.ZodString;
505
- }, z.core.$strict>;
506
- upload_id: z.ZodString;
507
- object_key: z.ZodString;
508
- reason: z.ZodString;
509
- uploaded_chunk_count: z.ZodOptional<z.ZodNumber>;
510
- }, z.core.$strict>;
511
- export type RawEvidenceUploadAbortRequest = z.infer<typeof RawEvidenceUploadAbortRequestSchema>;
512
- export declare const RawEvidenceUploadAbortResponseSchema: z.ZodObject<{
513
- ok: z.ZodLiteral<true>;
514
- status: z.ZodEnum<{
515
- reason_recorded: "reason_recorded";
516
- aborted: "aborted";
517
- already_terminal: "already_terminal";
518
- }>;
519
- upload_id: z.ZodString;
520
- object_key: z.ZodString;
521
- status_reason: z.ZodString;
522
- retryable: z.ZodBoolean;
523
- will_reopen: z.ZodBoolean;
524
- }, z.core.$strict>;
525
- export type RawEvidenceUploadAbortResponse = z.infer<typeof RawEvidenceUploadAbortResponseSchema>;
526
504
  /**
527
505
  * Codex session attribution report.
528
506
  *
@@ -1,8 +1,10 @@
1
1
  import { z } from "zod";
2
2
  import { CaptureProvenanceSchema, IsoDateTimeSchema, NonEmptyStringSchema, Sha256Schema, } from "./common.js";
3
+ import { ImageUseSchema } from "./image-store.js";
3
4
  import { RawEvidencePointerSchema } from "./privacy.js";
4
5
  import { RawEvidenceRedactionMetadataSchema } from "./secret-guards.js";
5
6
  import { SessionFactsSchema } from "./session-facts.js";
7
+ import { RawEvidenceUploadExtendAcceptedSchema, RawEvidenceUploadExtendRequestSchema } from "./evidence-upload-extend.js";
6
8
  /**
7
9
  * Chunked raw-evidence upload wire contract.
8
10
  *
@@ -38,7 +40,7 @@ export const RAW_EVIDENCE_UPLOAD_MAX_CHUNK_COUNT = 192;
38
40
  export const RAW_EVIDENCE_UPLOAD_MAX_FILE_BYTES = 500 * 1024 * 1024;
39
41
  export const RAW_EVIDENCE_UPLOAD_MAX_OBJECTS_PER_BEGIN = 25;
40
42
  export const CODEX_SESSION_REPORT_MAX_SESSIONS = 200;
41
- const SafeLabelSchema = z
43
+ export const SafeLabelSchema = z
42
44
  .string()
43
45
  .trim()
44
46
  .min(1)
@@ -73,6 +75,7 @@ export const RawEvidenceLegacyUploadResponseSchema = z
73
75
  export const RawEvidenceUploadBeginObjectSchema = z
74
76
  .object({
75
77
  pointer: RawEvidencePointerSchema,
78
+ extend: RawEvidenceUploadExtendRequestSchema.optional(),
76
79
  chunk_size_bytes: z
77
80
  .number()
78
81
  .int()
@@ -83,6 +86,12 @@ export const RawEvidenceUploadBeginObjectSchema = z
83
86
  .int()
84
87
  .positive()
85
88
  .max(RAW_EVIDENCE_UPLOAD_MAX_CHUNK_COUNT),
89
+ /**
90
+ * BLI-23329: required when the object key is an image object (`<operator>/images/<sha256>.<ext>`), refused
91
+ * on any other. Names the agent session this image is staged for, so the server can record that session as
92
+ * a user of the image in the same step that confirms it.
93
+ */
94
+ image_use: ImageUseSchema.optional(),
86
95
  })
87
96
  .strict();
88
97
  export const RawEvidenceUploadBeginRequestSchema = z
@@ -128,6 +137,11 @@ export const RawEvidenceUploadBeginResponseObjectSchema = z
128
137
  // `EVIDENCE_CODECS_HEADER`; this schema is strict, so an old collector must never be shown the
129
138
  // key. Absent means gzip only.
130
139
  accepted_encodings: z.array(RawEvidenceUploadEncodingSchema).optional(),
140
+ // BLI-23345: present only on an answer to a request that carried `extend`. `extend` is the accepted
141
+ // tail plan (chunk indexes below count the TAIL); `extend_refused` names why the server opened a
142
+ // whole-object plan instead.
143
+ extend: RawEvidenceUploadExtendAcceptedSchema.optional(),
144
+ extend_refused: SafeLabelSchema.optional(),
131
145
  })
132
146
  .strict();
133
147
  export const RawEvidenceUploadBeginResponseSchema = z
@@ -175,6 +189,8 @@ export const RawEvidenceUploadCommitRequestSchema = z
175
189
  upload_id: NonEmptyStringSchema,
176
190
  object_key: NonEmptyStringSchema,
177
191
  direct_chunks: z.array(RawEvidenceDirectChunkSchema).max(RAW_EVIDENCE_UPLOAD_MAX_CHUNK_COUNT).optional(),
192
+ /** BLI-23329: as on `begin`; the commit of an image object records this session as a user of the image. */
193
+ image_use: ImageUseSchema.optional(),
178
194
  })
179
195
  .strict();
180
196
  export const RawEvidenceUploadCommitResponseSchema = z
@@ -188,72 +204,6 @@ export const RawEvidenceUploadCommitResponseSchema = z
188
204
  redaction: RawEvidenceRedactionMetadataSchema.optional(),
189
205
  })
190
206
  .strict();
191
- /**
192
- * The collector giving up on an object it already opened (BLI-2539).
193
- *
194
- * `begin` writes a ledger row for every object in the batch, then chunks go one
195
- * object at a time. When one object's chunks fail its siblings still finish, so
196
- * the production shape is a single failure among committed rows rather than a
197
- * truncated batch. The collector knows exactly why that object died — it
198
- * composes labels like `chunk_0_failed_http_500` — and until this route existed
199
- * it had nowhere to send them: begin/chunk/commit has no call meaning "I quit".
200
- * The row stayed `pending` with a null reason until a drain relabelled it
201
- * `staging_incomplete`, which describes the shape and not the cause. 275 rows
202
- * reached that state by 2026-08-14.
203
- *
204
- * The reason is a label, never free text or an error body: it lands in
205
- * `status_reason`, which is read by `classifyUploadFailure`, and an unlisted
206
- * label classifies as `unknown` rather than being guessed into a bucket. That
207
- * is also what keeps these rows recoverable — `unknown` is not permanent, so
208
- * the row stays open (still `pending`, staged chunks intact) and the next
209
- * `begin` resumes it. Only a reason classified permanent fails the row closed.
210
- */
211
- export const RawEvidenceUploadAbortRequestSchema = z
212
- .object({
213
- schema_version: z.literal("ambient-raw-evidence-upload-abort.v1"),
214
- generated_at: IsoDateTimeSchema,
215
- provenance: CaptureProvenanceSchema,
216
- upload_id: NonEmptyStringSchema,
217
- object_key: NonEmptyStringSchema,
218
- reason: SafeLabelSchema,
219
- // How far the object actually got before the collector gave up. The server
220
- // already knows the received chunk count; this is what the CLIENT believed,
221
- // and a disagreement between the two is itself worth being able to see.
222
- uploaded_chunk_count: z.number().int().nonnegative().optional(),
223
- })
224
- .strict();
225
- export const RawEvidenceUploadAbortResponseSchema = z
226
- .object({
227
- ok: z.literal(true),
228
- // `reason_recorded` is the ordinary answer: the reason landed on the
229
- // still-open row, whose staged chunks stay resumable by the next `begin`.
230
- // `aborted` means the reason was classified permanent and the row failed
231
- // closed. `already_terminal` covers a row the server had already settled —
232
- // a drain that ran first, or a duplicate abort after a retry. Reporting
233
- // these back distinguishes "we recorded your reason" from "someone beat
234
- // you to it", which a bare 200 would hide.
235
- status: z.enum(["reason_recorded", "aborted", "already_terminal"]),
236
- upload_id: NonEmptyStringSchema,
237
- object_key: NonEmptyStringSchema,
238
- status_reason: SafeLabelSchema,
239
- // Two booleans because the underlying questions are not each other's
240
- // negation, and one field would have to lie about half of them.
241
- //
242
- // `retryable` is `isRetryableUploadFailure`: is repeating this KNOWN to
243
- // help? An unclassified reason answers no — refusing to promise something
244
- // nobody has reasoned about.
245
- //
246
- // `will_reopen` is `!isPermanentUploadFailure`: is this row still open (or
247
- // re-openable) for the next `begin`? An unclassified reason answers yes —
248
- // refusing to abandon an object over a word it cannot read.
249
- //
250
- // So a composed transport label like `chunk_0_failed_http_500` comes back
251
- // `retryable: false, will_reopen: true`, which is the honest pair: we are
252
- // not claiming a retry succeeds, and we are not writing the row off.
253
- retryable: z.boolean(),
254
- will_reopen: z.boolean(),
255
- })
256
- .strict();
257
207
  /**
258
208
  * Codex session attribution report.
259
209
  *
@@ -23,8 +23,20 @@ import { z } from "zod";
23
23
  * the bookkeeping are stripped too, every line stays. What is stripped and
24
24
  * kept: docs/architecture/image-descriptions.md, code in
25
25
  * packages/cockpit-local-collector/src/slim/.
26
+ * `store_and_drop` as `describe_and_drop`, but an image is replaced only once Tower has stored it and
27
+ * recorded this session as a user of it (BLI-23329).
26
28
  */
27
- export type ImageHandlingMode = "describe_and_keep" | "describe_and_drop";
29
+ export type ImageHandlingMode = "describe_and_keep" | "describe_and_drop" | "store_and_drop";
30
+ /**
31
+ * `store_and_drop` (BLI-23329) is `describe_and_drop` with one more step in front of the swap: each distinct
32
+ * image is stored ONCE on Tower, by its sha256, and a session's image is replaced by its marker only after
33
+ * Tower confirmed it this tick (`already_committed` or `committed`, with the session recorded as a user of the
34
+ * image). An image Tower did not confirm (offline, refused, over budget) stays inline: never lost.
35
+ * Docs: docs/architecture/image-descriptions.md, "Store once".
36
+ */
37
+ export declare function modeDropsImages(mode: ImageHandlingMode): boolean;
38
+ /** True only for the mode that stores image bytes on Tower. */
39
+ export declare function modeStoresImages(mode: ImageHandlingMode): boolean;
28
40
  /**
29
41
  * The FLEET DEFAULT and the fallback: the mode a machine uses when Tower has no setting for it and it
30
42
  * has never heard from Tower. Default is keep (images stay in the transcript, uploaded as on disk).
@@ -144,5 +156,24 @@ export declare const ImageReadResponseSchema: z.ZodObject<{
144
156
  }, z.core.$strict>>;
145
157
  }, z.core.$strict>;
146
158
  export type ImageReadResponse = z.infer<typeof ImageReadResponseSchema>;
159
+ /** The whole sha256 of an image: what `GET /api/ambient/images?sha256=…&bytes=1` (BLI-23329) needs. A prefix cannot name one stored object. */
160
+ export declare const ImageFullHashQuerySchema: z.ZodString;
161
+ /** `bytes=1` returns the decoded image; with `as=base64` the same bytes arrive as JSON `{ ok, sha256, media_type, byte_size, content_base64 }` (for a client that cannot read a binary body). */
162
+ export declare const ImageBytesAsSchema: z.ZodEnum<{
163
+ base64: "base64";
164
+ }>;
165
+ export declare const ImageBytesJsonResponseSchema: z.ZodObject<{
166
+ ok: z.ZodLiteral<true>;
167
+ sha256: z.ZodString;
168
+ media_type: z.ZodEnum<{
169
+ "image/png": "image/png";
170
+ "image/jpeg": "image/jpeg";
171
+ "image/gif": "image/gif";
172
+ "image/webp": "image/webp";
173
+ }>;
174
+ byte_size: z.ZodNumber;
175
+ content_base64: z.ZodString;
176
+ }, z.core.$strict>;
177
+ export type ImageBytesJsonResponse = z.infer<typeof ImageBytesJsonResponseSchema>;
147
178
  /** A sha256 or a prefix of one (the 16 characters a marker carries). */
148
179
  export declare const ImageHashQuerySchema: z.ZodString;
@@ -13,6 +13,20 @@
13
13
  * (validates the request, answers) and anything that reads a marker back. Pure: no I/O, no env.
14
14
  */
15
15
  import { z } from "zod";
16
+ /**
17
+ * `store_and_drop` (BLI-23329) is `describe_and_drop` with one more step in front of the swap: each distinct
18
+ * image is stored ONCE on Tower, by its sha256, and a session's image is replaced by its marker only after
19
+ * Tower confirmed it this tick (`already_committed` or `committed`, with the session recorded as a user of the
20
+ * image). An image Tower did not confirm (offline, refused, over budget) stays inline: never lost.
21
+ * Docs: docs/architecture/image-descriptions.md, "Store once".
22
+ */
23
+ export function modeDropsImages(mode) {
24
+ return mode === "describe_and_drop" || mode === "store_and_drop";
25
+ }
26
+ /** True only for the mode that stores image bytes on Tower. */
27
+ export function modeStoresImages(mode) {
28
+ return mode === "store_and_drop";
29
+ }
16
30
  /**
17
31
  * The FLEET DEFAULT and the fallback: the mode a machine uses when Tower has no setting for it and it
18
32
  * has never heard from Tower. Default is keep (images stay in the transcript, uploaded as on disk).
@@ -142,5 +156,18 @@ export const ImageReadResponseSchema = z
142
156
  descriptions: z.array(ImageDescriptionSchema),
143
157
  })
144
158
  .strict();
159
+ /** The whole sha256 of an image: what `GET /api/ambient/images?sha256=…&bytes=1` (BLI-23329) needs. A prefix cannot name one stored object. */
160
+ export const ImageFullHashQuerySchema = Sha256Schema;
161
+ /** `bytes=1` returns the decoded image; with `as=base64` the same bytes arrive as JSON `{ ok, sha256, media_type, byte_size, content_base64 }` (for a client that cannot read a binary body). */
162
+ export const ImageBytesAsSchema = z.enum(["base64"]);
163
+ export const ImageBytesJsonResponseSchema = z
164
+ .object({
165
+ ok: z.literal(true),
166
+ sha256: Sha256Schema,
167
+ media_type: z.enum(IMAGE_MEDIA_TYPES),
168
+ byte_size: z.number().int().positive(),
169
+ content_base64: z.string().min(4),
170
+ })
171
+ .strict();
145
172
  /** A sha256 or a prefix of one (the 16 characters a marker carries). */
146
173
  export const ImageHashQuerySchema = z.string().regex(/^[0-9a-f]{12,64}$/, "give 12 to 64 lowercase hex characters of the sha256");
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Store each distinct image once (BLI-23329): the object key, the "this session uses this image" claim, and the
3
+ * limits both ends of the wire agree on. Pure: no I/O, no env.
4
+ *
5
+ * Plain words: an image Tower stores is one object per person and picture, named by the picture's sha256. Every
6
+ * session that shows the picture is recorded as a USER of it. The collector replaces an image in a transcript
7
+ * with its marker only after Tower confirmed that record, and forgetting a session lets go of the pictures only
8
+ * that session used. Official terms: content-addressed object, reference-counted retention.
9
+ *
10
+ * Owner doc: docs/architecture/image-descriptions.md, "Store once".
11
+ */
12
+ import { z } from "zod";
13
+ import { type ImageMediaType } from "./image-descriptions.js";
14
+ /** The second key segment: `<operator>/images/<sha256>.<ext>`. An ordinary work context may never be called this. */
15
+ export declare const IMAGE_STORE_NAMESPACE = "images";
16
+ /**
17
+ * The biggest decoded image the store takes. Measured on one laptop the largest was 3.2 MB; the commit door holds a
18
+ * declared image whole to validate it (`evidence-assembly.ts`), so this stays far below that 64 MiB bound. A larger
19
+ * image stays inline in its transcript and is counted (`image_too_large_to_store`).
20
+ */
21
+ export declare const IMAGE_STORE_MAX_BYTES: number;
22
+ /** Decoded images a collector moves into the store per sync, and the seconds it may spend doing so. */
23
+ export declare const IMAGE_STORE_MAX_PER_RUN = 200;
24
+ export declare const IMAGE_STORE_MAX_RUN_MS = 120000;
25
+ /** The agent session id forget keys on (`forget_my_session`): the same shape the describe door's `session_id` takes. */
26
+ export declare const IMAGE_USE_SESSION_ID: RegExp;
27
+ /** Which transcript's session is staging the image: sent on `begin` and on `commit` of an image object. */
28
+ export declare const ImageUseSchema: z.ZodObject<{
29
+ session_id: z.ZodString;
30
+ source: z.ZodEnum<{
31
+ codex: "codex";
32
+ claude_code: "claude_code";
33
+ }>;
34
+ }, z.core.$strict>;
35
+ export type ImageUse = z.infer<typeof ImageUseSchema>;
36
+ export declare function imageObjectKey(operatorId: string, sha256: string, mediaType: ImageMediaType): string;
37
+ export interface ParsedImageObjectKey {
38
+ operatorId: string;
39
+ sha256: string;
40
+ extension: "png" | "jpg" | "gif" | "webp";
41
+ mediaType: ImageMediaType;
42
+ }
43
+ /** The parts of an image object key, or null when the key is not one. */
44
+ export declare function parseImageObjectKey(objectKey: string): ParsedImageObjectKey | null;
45
+ export declare function isImageObjectKey(objectKey: string): boolean;
46
+ /** The ones a bucket allowlist and a validator both need. */
47
+ export declare const IMAGE_STORE_MEDIA_TYPES: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Store each distinct image once (BLI-23329): the object key, the "this session uses this image" claim, and the
3
+ * limits both ends of the wire agree on. Pure: no I/O, no env.
4
+ *
5
+ * Plain words: an image Tower stores is one object per person and picture, named by the picture's sha256. Every
6
+ * session that shows the picture is recorded as a USER of it. The collector replaces an image in a transcript
7
+ * with its marker only after Tower confirmed that record, and forgetting a session lets go of the pictures only
8
+ * that session used. Official terms: content-addressed object, reference-counted retention.
9
+ *
10
+ * Owner doc: docs/architecture/image-descriptions.md, "Store once".
11
+ */
12
+ import { z } from "zod";
13
+ import { IMAGE_MEDIA_TYPES } from "./image-descriptions.js";
14
+ /** The second key segment: `<operator>/images/<sha256>.<ext>`. An ordinary work context may never be called this. */
15
+ export const IMAGE_STORE_NAMESPACE = "images";
16
+ /**
17
+ * The biggest decoded image the store takes. Measured on one laptop the largest was 3.2 MB; the commit door holds a
18
+ * declared image whole to validate it (`evidence-assembly.ts`), so this stays far below that 64 MiB bound. A larger
19
+ * image stays inline in its transcript and is counted (`image_too_large_to_store`).
20
+ */
21
+ export const IMAGE_STORE_MAX_BYTES = 20 * 1024 * 1024;
22
+ /** Decoded images a collector moves into the store per sync, and the seconds it may spend doing so. */
23
+ export const IMAGE_STORE_MAX_PER_RUN = 200;
24
+ export const IMAGE_STORE_MAX_RUN_MS = 120_000;
25
+ const EXTENSION_BY_TYPE = {
26
+ "image/png": "png",
27
+ "image/jpeg": "jpg",
28
+ "image/gif": "gif",
29
+ "image/webp": "webp",
30
+ };
31
+ const TYPE_BY_EXTENSION = new Map(Object.entries(EXTENSION_BY_TYPE).map(([type, ext]) => [ext, type]));
32
+ /** The agent session id forget keys on (`forget_my_session`): the same shape the describe door's `session_id` takes. */
33
+ export const IMAGE_USE_SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
34
+ /** Which transcript's session is staging the image: sent on `begin` and on `commit` of an image object. */
35
+ export const ImageUseSchema = z
36
+ .object({
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"]),
39
+ })
40
+ .strict();
41
+ const IMAGE_KEY = /^([A-Za-z0-9._-]+)\/images\/([0-9a-f]{64})\.(png|jpg|gif|webp)$/;
42
+ export function imageObjectKey(operatorId, sha256, mediaType) {
43
+ return `${operatorId}/${IMAGE_STORE_NAMESPACE}/${sha256}.${EXTENSION_BY_TYPE[mediaType]}`;
44
+ }
45
+ /** The parts of an image object key, or null when the key is not one. */
46
+ export function parseImageObjectKey(objectKey) {
47
+ const match = IMAGE_KEY.exec(objectKey);
48
+ if (!match)
49
+ return null;
50
+ const mediaType = TYPE_BY_EXTENSION.get(match[3]);
51
+ if (!mediaType)
52
+ return null;
53
+ return { operatorId: match[1], sha256: match[2], extension: match[3], mediaType };
54
+ }
55
+ export function isImageObjectKey(objectKey) {
56
+ return IMAGE_KEY.test(objectKey);
57
+ }
58
+ /** The ones a bucket allowlist and a validator both need. */
59
+ export const IMAGE_STORE_MEDIA_TYPES = IMAGE_MEDIA_TYPES;
package/dist/index.d.ts CHANGED
@@ -11,9 +11,12 @@ export * from "./evidence-rules-fingerprint.js";
11
11
  export * from "./evidence-stubs.js";
12
12
  export * from "./evidence-transcripts.js";
13
13
  export * from "./evidence-upload.js";
14
+ export * from "./evidence-upload-abort.js";
15
+ export * from "./evidence-upload-extend.js";
14
16
  export * from "./image-description-store.js";
15
17
  export * from "./image-descriptions.js";
16
18
  export * from "./image-marker-resolver.js";
19
+ export * from "./image-store.js";
17
20
  export * from "./pdf-markers.js";
18
21
  export * from "./transcript-images.js";
19
22
  export * from "./image-byte-scan.js";
package/dist/index.js CHANGED
@@ -11,9 +11,12 @@ export * from "./evidence-rules-fingerprint.js";
11
11
  export * from "./evidence-stubs.js";
12
12
  export * from "./evidence-transcripts.js";
13
13
  export * from "./evidence-upload.js";
14
+ export * from "./evidence-upload-abort.js";
15
+ export * from "./evidence-upload-extend.js";
14
16
  export * from "./image-description-store.js";
15
17
  export * from "./image-descriptions.js";
16
18
  export * from "./image-marker-resolver.js";
19
+ export * from "./image-store.js";
17
20
  export * from "./pdf-markers.js";
18
21
  export * from "./transcript-images.js";
19
22
  export * from "./image-byte-scan.js";
@@ -19,6 +19,7 @@
19
19
  // stripped only when the remaining stem is itself a listed reason — see
20
20
  // `baseUploadFailureReason` — so the table still decides everything and an
21
21
  // unreasoned-about stem stays `unknown`.
22
+ import { EXTEND_BASE_UNAVAILABLE } from "./evidence-upload-extend.js";
22
23
  /**
23
24
  * The reason written when nothing in the pipeline explained itself.
24
25
  *
@@ -237,6 +238,11 @@ const UPLOAD_FAILURE_CLASSES = {
237
238
  // the final write uses `upsert: false` on purpose, so the row would loop as
238
239
  // `skipped_storage_error` for as long as anyone kept running the pass.
239
240
  object_key_holds_other_content: "deterministic",
241
+ // BLI-23345. A tail upload whose base vanished (commit) or whose staging only ever held the tail
242
+ // (drain). The collector still holds the whole staged file and the next `begin` without a tail plan
243
+ // resets the row, so the identical retry is exactly right.
244
+ [EXTEND_BASE_UNAVAILABLE]: "transient",
245
+ extend_row_needs_whole_upload: "transient",
240
246
  // Attribution never produced a target, so there is nowhere to put the object.
241
247
  // Widening discovery can change this; running the same scan again cannot.
242
248
  cwd_outside_scanned_worktrees: "deterministic",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.91",
3
+ "version": "0.1.93",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",