@bli-cockpit/telemetry-core 0.1.53 → 0.1.55

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,60 @@
1
+ /**
2
+ * "Which of my stored transcripts are only a redaction-crash stub?" — the wire
3
+ * contract for asking (BLI-11102).
4
+ *
5
+ * When the redactor crashed (BLI‑3238, fixed for the known cause in ticket
6
+ * 11094) the collector uploaded one marker line instead of the session, so the
7
+ * pointer exists and the content does not. A stub is a promise to come back,
8
+ * not a delivery. The collector's cursor cannot tell (it recorded an upload),
9
+ * so the server, which holds the label on the pointer, answers the question and
10
+ * `cockpit backfill` re-offers every session it names.
11
+ *
12
+ * The stub is always the same 42 bytes, so its receipt proves what it holds:
13
+ * content hash `REDACTION_STUB_SHA256`, byte size `REDACTION_STUB_BYTE_SIZE`.
14
+ * That is also why replacing it keeps every byte: it holds no session bytes.
15
+ */
16
+ import { z } from "zod";
17
+ export declare const EVIDENCE_STUBS_SCHEMA_VERSION = "evidence-stubs.v1";
18
+ /** The completeness label and rule id the sanitizer writes on a stub. */
19
+ export declare const REDACTION_STUB_LABEL = "redaction_crashed_stubbed";
20
+ /** The exact bytes of every stub the collector has ever uploaded. */
21
+ export declare const REDACTION_STUB_TEXT = "[REDACTED_LINE:redaction_crashed_stubbed]\n";
22
+ export declare const REDACTION_STUB_BYTE_SIZE = 42;
23
+ /** sha256 of `REDACTION_STUB_TEXT`; pinned by `evidence-stubs.test.ts`. */
24
+ export declare const REDACTION_STUB_SHA256 = "ddaf92c5ea8b178f735944dc753588ce788211340f5106d37b5f44568f6a0fe9";
25
+ /** One page holds at most this many stubs (under the 1,000-row REST cap). */
26
+ export declare const EVIDENCE_STUBS_MAX_PAGE = 500;
27
+ export declare const EvidenceStubsRequestSchema: z.ZodObject<{
28
+ schema_version: z.ZodLiteral<"evidence-stubs.v1">;
29
+ after: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
+ limit: z.ZodOptional<z.ZodNumber>;
31
+ }, z.core.$strict>;
32
+ export type EvidenceStubsRequest = z.infer<typeof EvidenceStubsRequestSchema>;
33
+ export declare const EvidenceStubSchema: z.ZodObject<{
34
+ ref_id: z.ZodString;
35
+ raw_evidence_pointer_id: z.ZodString;
36
+ object_key: z.ZodString;
37
+ received_at: z.ZodString;
38
+ }, z.core.$strict>;
39
+ export type EvidenceStub = z.infer<typeof EvidenceStubSchema>;
40
+ export declare const EvidenceStubsResponseSchema: z.ZodObject<{
41
+ schema_version: z.ZodLiteral<"evidence-stubs.v1">;
42
+ stubs: z.ZodArray<z.ZodObject<{
43
+ ref_id: z.ZodString;
44
+ raw_evidence_pointer_id: z.ZodString;
45
+ object_key: z.ZodString;
46
+ received_at: z.ZodString;
47
+ }, z.core.$strict>>;
48
+ next_after: z.ZodNullable<z.ZodString>;
49
+ }, z.core.$strict>;
50
+ export type EvidenceStubsResponse = z.infer<typeof EvidenceStubsResponseSchema>;
51
+ /**
52
+ * Which agent session a transcript object belongs to, read off its key
53
+ * (`.../codex/<session>/<hash>.jsonl`, `.../claude/<session>/<hash>.jsonl`).
54
+ * The collector names objects this way (`raw-evidence-codex-reader.ts`,
55
+ * `raw-evidence-claude-reader.ts`); anything else is null, never a guess.
56
+ */
57
+ export declare function transcriptSessionFromObjectKey(objectKey: string): {
58
+ source: "codex" | "claude_code";
59
+ session_id: string;
60
+ } | null;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * "Which of my stored transcripts are only a redaction-crash stub?" — the wire
3
+ * contract for asking (BLI-11102).
4
+ *
5
+ * When the redactor crashed (BLI‑3238, fixed for the known cause in ticket
6
+ * 11094) the collector uploaded one marker line instead of the session, so the
7
+ * pointer exists and the content does not. A stub is a promise to come back,
8
+ * not a delivery. The collector's cursor cannot tell (it recorded an upload),
9
+ * so the server, which holds the label on the pointer, answers the question and
10
+ * `cockpit backfill` re-offers every session it names.
11
+ *
12
+ * The stub is always the same 42 bytes, so its receipt proves what it holds:
13
+ * content hash `REDACTION_STUB_SHA256`, byte size `REDACTION_STUB_BYTE_SIZE`.
14
+ * That is also why replacing it keeps every byte: it holds no session bytes.
15
+ */
16
+ import { z } from "zod";
17
+ import { IsoDateTimeSchema, NonEmptyStringSchema } from "./common.js";
18
+ export const EVIDENCE_STUBS_SCHEMA_VERSION = "evidence-stubs.v1";
19
+ /** The completeness label and rule id the sanitizer writes on a stub. */
20
+ export const REDACTION_STUB_LABEL = "redaction_crashed_stubbed";
21
+ /** The exact bytes of every stub the collector has ever uploaded. */
22
+ export const REDACTION_STUB_TEXT = `[REDACTED_LINE:${REDACTION_STUB_LABEL}]\n`;
23
+ export const REDACTION_STUB_BYTE_SIZE = 42;
24
+ /** sha256 of `REDACTION_STUB_TEXT`; pinned by `evidence-stubs.test.ts`. */
25
+ export const REDACTION_STUB_SHA256 = "ddaf92c5ea8b178f735944dc753588ce788211340f5106d37b5f44568f6a0fe9";
26
+ /** One page holds at most this many stubs (under the 1,000-row REST cap). */
27
+ export const EVIDENCE_STUBS_MAX_PAGE = 500;
28
+ export const EvidenceStubsRequestSchema = z
29
+ .object({
30
+ schema_version: z.literal(EVIDENCE_STUBS_SCHEMA_VERSION),
31
+ /** Keyset cursor: the last ref id of the previous page, or null for the first. */
32
+ after: z.string().uuid().nullable().optional(),
33
+ limit: z.number().int().min(1).max(EVIDENCE_STUBS_MAX_PAGE).optional(),
34
+ })
35
+ .strict();
36
+ export const EvidenceStubSchema = z
37
+ .object({
38
+ ref_id: z.string().uuid(),
39
+ raw_evidence_pointer_id: NonEmptyStringSchema,
40
+ object_key: NonEmptyStringSchema,
41
+ received_at: IsoDateTimeSchema,
42
+ })
43
+ .strict();
44
+ export const EvidenceStubsResponseSchema = z
45
+ .object({
46
+ schema_version: z.literal(EVIDENCE_STUBS_SCHEMA_VERSION),
47
+ stubs: z.array(EvidenceStubSchema),
48
+ /** Pass as `after` to read the next page; null once the list is exhausted. */
49
+ next_after: z.string().uuid().nullable(),
50
+ })
51
+ .strict();
52
+ /**
53
+ * Which agent session a transcript object belongs to, read off its key
54
+ * (`.../codex/<session>/<hash>.jsonl`, `.../claude/<session>/<hash>.jsonl`).
55
+ * The collector names objects this way (`raw-evidence-codex-reader.ts`,
56
+ * `raw-evidence-claude-reader.ts`); anything else is null, never a guess.
57
+ */
58
+ export function transcriptSessionFromObjectKey(objectKey) {
59
+ const match = /(?:^|\/)(codex|claude)\/([A-Za-z0-9._-]{1,80})\/[0-9a-f]{16}\.jsonl$/u.exec(objectKey);
60
+ if (!match)
61
+ return null;
62
+ return {
63
+ source: match[1] === "codex" ? "codex" : "claude_code",
64
+ session_id: match[2],
65
+ };
66
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * "Does Tower hold this transcript?" — the wire contract for asking
3
+ * (BLI-11122).
4
+ *
5
+ * On 2026-09-30 an agent freeing disk deleted 1,491 Codex transcripts on the
6
+ * premise that they were already in Tower; 349 had no copy. Nothing could
7
+ * answer the question per file, so the agent guessed. `cockpit sources check`
8
+ * answers it: it lists every CURRENT transcript object the caller owns through
9
+ * this door and compares each against the local file.
10
+ *
11
+ * Current means: not superseded by a later snapshot of the same session, and
12
+ * not excluded. A redaction-crash stub is listed with `stub: true`, because a
13
+ * stub is a promise to come back, not a delivery (see `evidence-stubs.ts`).
14
+ *
15
+ * Read-only, scoped to the caller's own operator rows, one bounded page per
16
+ * call, keyset on the unique ref id under the 1,000-row REST cap.
17
+ */
18
+ import { z } from "zod";
19
+ export declare const EVIDENCE_TRANSCRIPTS_SCHEMA_VERSION = "evidence-transcripts.v1";
20
+ /** One page holds at most this many objects (under the 1,000-row REST cap). */
21
+ export declare const EVIDENCE_TRANSCRIPTS_MAX_PAGE = 500;
22
+ export declare const EvidenceTranscriptsRequestSchema: z.ZodObject<{
23
+ schema_version: z.ZodLiteral<"evidence-transcripts.v1">;
24
+ after: z.ZodOptional<z.ZodNullable<z.ZodString>>;
25
+ limit: z.ZodOptional<z.ZodNumber>;
26
+ }, z.core.$strict>;
27
+ export type EvidenceTranscriptsRequest = z.infer<typeof EvidenceTranscriptsRequestSchema>;
28
+ export declare const EvidenceTranscriptObjectSchema: z.ZodObject<{
29
+ ref_id: z.ZodString;
30
+ object_key: z.ZodString;
31
+ byte_size: z.ZodNullable<z.ZodNumber>;
32
+ content_hash_sha256: z.ZodNullable<z.ZodString>;
33
+ stub: z.ZodBoolean;
34
+ received_at: z.ZodString;
35
+ }, z.core.$strict>;
36
+ export type EvidenceTranscriptObject = z.infer<typeof EvidenceTranscriptObjectSchema>;
37
+ export declare const EvidenceTranscriptsResponseSchema: z.ZodObject<{
38
+ schema_version: z.ZodLiteral<"evidence-transcripts.v1">;
39
+ objects: z.ZodArray<z.ZodObject<{
40
+ ref_id: z.ZodString;
41
+ object_key: z.ZodString;
42
+ byte_size: z.ZodNullable<z.ZodNumber>;
43
+ content_hash_sha256: z.ZodNullable<z.ZodString>;
44
+ stub: z.ZodBoolean;
45
+ received_at: z.ZodString;
46
+ }, z.core.$strict>>;
47
+ next_after: z.ZodNullable<z.ZodString>;
48
+ }, z.core.$strict>;
49
+ export type EvidenceTranscriptsResponse = z.infer<typeof EvidenceTranscriptsResponseSchema>;
50
+ export interface TranscriptFileIdentity {
51
+ source: "codex" | "claude_code";
52
+ session_id: string;
53
+ /** The Claude subagent file's key segment, or null for the session's main transcript. */
54
+ sidecar: string | null;
55
+ }
56
+ /**
57
+ * Which local transcript file an object stands for, read off its key:
58
+ * `.../codex/<session>/<hash16>.jsonl`, `.../claude/<session>/<hash16>.jsonl`
59
+ * or `.../claude/<session>/subagents/<sidecar>-<hash16>.jsonl`. The collector
60
+ * names objects this way (`raw-evidence-codex-reader.ts`,
61
+ * `raw-evidence-claude-reader.ts`); anything else is null, never a guess.
62
+ */
63
+ export declare function transcriptFileFromObjectKey(objectKey: string): TranscriptFileIdentity | null;
64
+ /** The one string both sides key a transcript file by. */
65
+ export declare function transcriptFileKey(identity: TranscriptFileIdentity): string;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * "Does Tower hold this transcript?" — the wire contract for asking
3
+ * (BLI-11122).
4
+ *
5
+ * On 2026-09-30 an agent freeing disk deleted 1,491 Codex transcripts on the
6
+ * premise that they were already in Tower; 349 had no copy. Nothing could
7
+ * answer the question per file, so the agent guessed. `cockpit sources check`
8
+ * answers it: it lists every CURRENT transcript object the caller owns through
9
+ * this door and compares each against the local file.
10
+ *
11
+ * Current means: not superseded by a later snapshot of the same session, and
12
+ * not excluded. A redaction-crash stub is listed with `stub: true`, because a
13
+ * stub is a promise to come back, not a delivery (see `evidence-stubs.ts`).
14
+ *
15
+ * Read-only, scoped to the caller's own operator rows, one bounded page per
16
+ * call, keyset on the unique ref id under the 1,000-row REST cap.
17
+ */
18
+ import { z } from "zod";
19
+ import { IsoDateTimeSchema, NonEmptyStringSchema } from "./common.js";
20
+ export const EVIDENCE_TRANSCRIPTS_SCHEMA_VERSION = "evidence-transcripts.v1";
21
+ /** One page holds at most this many objects (under the 1,000-row REST cap). */
22
+ export const EVIDENCE_TRANSCRIPTS_MAX_PAGE = 500;
23
+ export const EvidenceTranscriptsRequestSchema = z
24
+ .object({
25
+ schema_version: z.literal(EVIDENCE_TRANSCRIPTS_SCHEMA_VERSION),
26
+ /** Keyset cursor: the last ref id of the previous page, or null for the first. */
27
+ after: z.string().uuid().nullable().optional(),
28
+ limit: z.number().int().min(1).max(EVIDENCE_TRANSCRIPTS_MAX_PAGE).optional(),
29
+ })
30
+ .strict();
31
+ export const EvidenceTranscriptObjectSchema = z
32
+ .object({
33
+ ref_id: z.string().uuid(),
34
+ object_key: NonEmptyStringSchema,
35
+ /** Stored bytes; null only on legacy rows written before sizes were kept. */
36
+ byte_size: z.number().int().nonnegative().nullable(),
37
+ /** sha256 of the stored (redacted) bytes; null only on legacy rows. */
38
+ content_hash_sha256: z
39
+ .string()
40
+ .regex(/^[0-9a-f]{64}$/u)
41
+ .nullable(),
42
+ /** The 42-byte redaction-crash marker: no session byte is stored. */
43
+ stub: z.boolean(),
44
+ received_at: IsoDateTimeSchema,
45
+ })
46
+ .strict();
47
+ export const EvidenceTranscriptsResponseSchema = z
48
+ .object({
49
+ schema_version: z.literal(EVIDENCE_TRANSCRIPTS_SCHEMA_VERSION),
50
+ objects: z.array(EvidenceTranscriptObjectSchema),
51
+ /** Pass as `after` to read the next page; null once the list is exhausted. */
52
+ next_after: z.string().uuid().nullable(),
53
+ })
54
+ .strict();
55
+ /**
56
+ * Which local transcript file an object stands for, read off its key:
57
+ * `.../codex/<session>/<hash16>.jsonl`, `.../claude/<session>/<hash16>.jsonl`
58
+ * or `.../claude/<session>/subagents/<sidecar>-<hash16>.jsonl`. The collector
59
+ * names objects this way (`raw-evidence-codex-reader.ts`,
60
+ * `raw-evidence-claude-reader.ts`); anything else is null, never a guess.
61
+ */
62
+ export function transcriptFileFromObjectKey(objectKey) {
63
+ const main = /(?:^|\/)(codex|claude)\/([A-Za-z0-9._-]{1,80})\/[0-9a-f]{16}\.jsonl$/u.exec(objectKey);
64
+ if (main) {
65
+ return {
66
+ source: main[1] === "codex" ? "codex" : "claude_code",
67
+ session_id: main[2],
68
+ sidecar: null,
69
+ };
70
+ }
71
+ const sidecar = /(?:^|\/)claude\/([A-Za-z0-9._-]{1,80})\/subagents\/([A-Za-z0-9._-]{1,80})-[0-9a-f]{16}\.jsonl$/u.exec(objectKey);
72
+ if (!sidecar)
73
+ return null;
74
+ return { source: "claude_code", session_id: sidecar[1], sidecar: sidecar[2] };
75
+ }
76
+ /** The one string both sides key a transcript file by. */
77
+ export function transcriptFileKey(identity) {
78
+ return identity.sidecar
79
+ ? `${identity.source}:${identity.session_id}:subagents/${identity.sidecar}`
80
+ : `${identity.source}:${identity.session_id}`;
81
+ }
@@ -125,6 +125,7 @@ export declare const RawEvidenceUploadBeginObjectSchema: z.ZodObject<{
125
125
  supersedes_pointer_id: z.ZodOptional<z.ZodString>;
126
126
  supersede_rule: z.ZodOptional<z.ZodEnum<{
127
127
  prefix: "prefix";
128
+ stub_replaced: "stub_replaced";
128
129
  }>>;
129
130
  }, z.core.$strict>;
130
131
  chunk_size_bytes: z.ZodNumber;
@@ -229,6 +230,7 @@ export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
229
230
  supersedes_pointer_id: z.ZodOptional<z.ZodString>;
230
231
  supersede_rule: z.ZodOptional<z.ZodEnum<{
231
232
  prefix: "prefix";
233
+ stub_replaced: "stub_replaced";
232
234
  }>>;
233
235
  }, z.core.$strict>;
234
236
  chunk_size_bytes: z.ZodNumber;
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ export * from "./decision-event.js";
6
6
  export * from "./decision-event-id.js";
7
7
  export * from "./evidence-completeness.js";
8
8
  export * from "./evidence-reconcile.js";
9
+ export * from "./evidence-stubs.js";
10
+ export * from "./evidence-transcripts.js";
9
11
  export * from "./evidence-upload.js";
10
12
  export * from "./ingest-dto.js";
11
13
  export * from "./local-config.js";
package/dist/index.js CHANGED
@@ -6,6 +6,8 @@ export * from "./decision-event.js";
6
6
  export * from "./decision-event-id.js";
7
7
  export * from "./evidence-completeness.js";
8
8
  export * from "./evidence-reconcile.js";
9
+ export * from "./evidence-stubs.js";
10
+ export * from "./evidence-transcripts.js";
9
11
  export * from "./evidence-upload.js";
10
12
  export * from "./ingest-dto.js";
11
13
  export * from "./local-config.js";
@@ -321,6 +321,7 @@ export declare const TelemetryIngestEventDtoSchema: z.ZodObject<{
321
321
  supersedes_pointer_id: z.ZodOptional<z.ZodString>;
322
322
  supersede_rule: z.ZodOptional<z.ZodEnum<{
323
323
  prefix: "prefix";
324
+ stub_replaced: "stub_replaced";
324
325
  }>>;
325
326
  }, z.core.$strict>>>;
326
327
  otel: z.ZodOptional<z.ZodObject<{
@@ -804,6 +805,7 @@ export declare const TelemetryIngestEnvelopeSchema: z.ZodObject<{
804
805
  supersedes_pointer_id: z.ZodOptional<z.ZodString>;
805
806
  supersede_rule: z.ZodOptional<z.ZodEnum<{
806
807
  prefix: "prefix";
808
+ stub_replaced: "stub_replaced";
807
809
  }>>;
808
810
  }, z.core.$strict>>>;
809
811
  otel: z.ZodOptional<z.ZodObject<{
@@ -962,6 +964,7 @@ export declare const TelemetryIngestEnvelopeSchema: z.ZodObject<{
962
964
  supersedes_pointer_id: z.ZodOptional<z.ZodString>;
963
965
  supersede_rule: z.ZodOptional<z.ZodEnum<{
964
966
  prefix: "prefix";
967
+ stub_replaced: "stub_replaced";
965
968
  }>>;
966
969
  }, z.core.$strict>>>;
967
970
  }, z.core.$strict>>>;
package/dist/privacy.d.ts CHANGED
@@ -99,6 +99,7 @@ export declare const RawEvidencePointerSchema: z.ZodObject<{
99
99
  supersedes_pointer_id: z.ZodOptional<z.ZodString>;
100
100
  supersede_rule: z.ZodOptional<z.ZodEnum<{
101
101
  prefix: "prefix";
102
+ stub_replaced: "stub_replaced";
102
103
  }>>;
103
104
  }, z.core.$strict>;
104
105
  export type RawEvidencePointer = z.infer<typeof RawEvidencePointerSchema>;
package/dist/privacy.js CHANGED
@@ -101,7 +101,7 @@ export const RawEvidencePointerSchema = z
101
101
  * a verdict: the ingest door re-derives it from Storage before deleting.
102
102
  */
103
103
  supersedes_pointer_id: NonEmptyStringSchema.optional(),
104
- supersede_rule: z.enum(["prefix"]).optional(),
104
+ supersede_rule: z.enum(["prefix", "stub_replaced"]).optional(),
105
105
  })
106
106
  .strict()
107
107
  .superRefine((pointer, context) => {
@@ -1,4 +1,11 @@
1
- export type SupersedeRule = "prefix";
1
+ /**
2
+ * `prefix`: the older snapshot is a byte prefix of the newer one (BLI-11088).
3
+ * `stub_replaced`: the older object is the 42-byte redaction-crash stub, which
4
+ * holds no session bytes, and the newer one is the same agent session
5
+ * redacted whole (BLI-11102). Verified by the ingest door from the stub's
6
+ * receipt and Storage, never taken on the collector's word.
7
+ */
8
+ export type SupersedeRule = "prefix" | "stub_replaced";
2
9
  /**
3
10
  * Truncated prefix hashes at every power of two from 64 bytes, so a rewrite
4
11
  * can be located to a byte range without keeping the old bytes: about 20
@@ -107,6 +107,7 @@ export declare const SourceScanEventSummarySchema: z.ZodObject<{
107
107
  supersedes_pointer_id: z.ZodOptional<z.ZodString>;
108
108
  supersede_rule: z.ZodOptional<z.ZodEnum<{
109
109
  prefix: "prefix";
110
+ stub_replaced: "stub_replaced";
110
111
  }>>;
111
112
  }, z.core.$strict>>>;
112
113
  }, z.core.$strict>;
@@ -229,6 +230,7 @@ export declare const SourceScanResultSchema: z.ZodObject<{
229
230
  supersedes_pointer_id: z.ZodOptional<z.ZodString>;
230
231
  supersede_rule: z.ZodOptional<z.ZodEnum<{
231
232
  prefix: "prefix";
233
+ stub_replaced: "stub_replaced";
232
234
  }>>;
233
235
  }, z.core.$strict>>>;
234
236
  }, z.core.$strict>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",