@bli-cockpit/telemetry-core 0.1.88 → 0.1.89

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.
@@ -17,6 +17,7 @@ import { formatImageMarker, imageMarkerPattern, IMAGE_MIN_BASE64_CHARS } from ".
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";
20
+ import { PDF_RULES_VERSION, formatPdfMarker, formatPdfReference } from "./pdf-markers.js";
20
21
  import { findEmbeddedImages } from "./transcript-images.js";
21
22
  let cached;
22
23
  /** The probe: a tiny PNG header padded past the detector's minimum, in both shapes the detector knows. */
@@ -39,6 +40,10 @@ export function evidenceRulesFingerprint() {
39
40
  image_min_base64_chars: IMAGE_MIN_BASE64_CHARS,
40
41
  image_marker_pattern: describe(imageMarkerPattern()),
41
42
  image_marker_sample: formatImageMarker({ sha256: "0123456789abcdef".repeat(4), mediaType: "image/png", byteSize: 412 * 1024 }),
43
+ // BLI-23347: PDFs become text. The rules version and both marker shapes decide those bytes.
44
+ pdf_rules_version: PDF_RULES_VERSION,
45
+ pdf_marker_sample: formatPdfMarker({ sha256: "0123456789abcdef".repeat(4), pages: 3, byteSize: 412 * 1024, method: "text-layer", notes: ["sample"] }, "body"),
46
+ pdf_reference_sample: formatPdfReference({ sha256: "0123456789abcdef".repeat(4), byteSize: 412 * 1024 }),
42
47
  image_detector_probe: findEmbeddedImages(probe).map((image) => [image.replaceStart, image.replaceEnd, image.mediaType, image.byteSize]),
43
48
  };
44
49
  cached = createHash("sha256").update(JSON.stringify(parts)).digest("hex");
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from "./evidence-upload.js";
14
14
  export * from "./image-description-store.js";
15
15
  export * from "./image-descriptions.js";
16
16
  export * from "./image-marker-resolver.js";
17
+ export * from "./pdf-markers.js";
17
18
  export * from "./transcript-images.js";
18
19
  export * from "./ingest-dto.js";
19
20
  export * from "./local-config.js";
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ export * from "./evidence-upload.js";
14
14
  export * from "./image-description-store.js";
15
15
  export * from "./image-descriptions.js";
16
16
  export * from "./image-marker-resolver.js";
17
+ export * from "./pdf-markers.js";
17
18
  export * from "./transcript-images.js";
18
19
  export * from "./ingest-dto.js";
19
20
  export * from "./local-config.js";
@@ -0,0 +1,21 @@
1
+ /** Bump when the extraction rules (layout heuristics, limits, page-image encoding) change what a PDF becomes. */
2
+ export declare const PDF_RULES_VERSION = "pdf-text.v1";
3
+ /** What every PDF marker starts with: a cheap `includes` check before anyone runs a regex. */
4
+ export declare const PDF_MARKER_START = "[pdf sha256:";
5
+ export declare const PDF_MARKER_END = "[/pdf]";
6
+ export type PdfConversionMethod = "text-layer" | "page-images";
7
+ export interface PdfMarkerFacts {
8
+ sha256: string;
9
+ pages: number;
10
+ byteSize: number;
11
+ method: PdfConversionMethod;
12
+ /** Short plain statements about the conversion ("pages 1-200 of 412 shown"), shown after the method. */
13
+ notes?: readonly string[];
14
+ }
15
+ /** The marker block for the first copy of a PDF: header, body, closing line. */
16
+ export declare function formatPdfMarker(facts: PdfMarkerFacts, body: string): string;
17
+ /** The one-line stand-in for a repeat copy of a PDF already converted earlier in the same transcript. */
18
+ export declare function formatPdfReference(facts: {
19
+ sha256: string;
20
+ byteSize: number;
21
+ }): string;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * PDFs inside collected transcripts: what replaces their base64 (BLI-23347).
3
+ *
4
+ * Claude Code stores a PDF it read as base64, twice on one line (the tool result block and the
5
+ * structured `toolUseResult.file.base64`). In `describe_and_drop` mode the collector replaces each copy:
6
+ *
7
+ * - the FIRST copy of a PDF becomes a marker block: a header line with the sha256 prefix, page count,
8
+ * size and how it was converted, then the converted body (the PDF's text with tables as Markdown, or
9
+ * for a scan the markers of the page images the describe door described), then `[/pdf]`;
10
+ * - every further copy of the same PDF in the same transcript becomes a one-line reference to it.
11
+ *
12
+ * Shared by the collector (builds the marker) and anything that reads a marker back. Pure: no I/O.
13
+ * Changing the format, or `PDF_RULES_VERSION`, changes `evidenceRulesFingerprint()`, which rebuilds every
14
+ * collector's prepare memo once. That is intended: the bytes the collector makes from a PDF changed.
15
+ */
16
+ import { imageSizeLabel } from "./image-descriptions.js";
17
+ /** Bump when the extraction rules (layout heuristics, limits, page-image encoding) change what a PDF becomes. */
18
+ export const PDF_RULES_VERSION = "pdf-text.v1";
19
+ /** What every PDF marker starts with: a cheap `includes` check before anyone runs a regex. */
20
+ export const PDF_MARKER_START = "[pdf sha256:";
21
+ export const PDF_MARKER_END = "[/pdf]";
22
+ /** Hex characters of the sha256 a PDF marker carries (same as an image marker). */
23
+ const PDF_MARKER_HASH_CHARS = 16;
24
+ function header(facts) {
25
+ const hash = facts.sha256.slice(0, PDF_MARKER_HASH_CHARS);
26
+ const pages = `${facts.pages} ${facts.pages === 1 ? "page" : "pages"}`;
27
+ const method = facts.method === "text-layer" ? "text" : "scanned, page images described";
28
+ const notes = (facts.notes ?? []).map((note) => `; ${note}`).join("");
29
+ return `${PDF_MARKER_START}${hash}… ${pages} ${imageSizeLabel(facts.byteSize)} ${method}${notes}]`;
30
+ }
31
+ /** The marker block for the first copy of a PDF: header, body, closing line. */
32
+ export function formatPdfMarker(facts, body) {
33
+ return `${header(facts)}\n${body}\n${PDF_MARKER_END}`;
34
+ }
35
+ /** The one-line stand-in for a repeat copy of a PDF already converted earlier in the same transcript. */
36
+ export function formatPdfReference(facts) {
37
+ const hash = facts.sha256.slice(0, PDF_MARKER_HASH_CHARS);
38
+ return `${PDF_MARKER_START}${hash}… ${imageSizeLabel(facts.byteSize)} same PDF as the earlier copy in this transcript]`;
39
+ }
@@ -10,6 +10,11 @@ export interface EmbeddedImage {
10
10
  mediaType: ImageMediaType;
11
11
  /** Decoded size in bytes. */
12
12
  byteSize: number;
13
+ /**
14
+ * BLI-23347: set on a stand-in for something that is not an image (a PDF's base64). When present the
15
+ * range is swapped for exactly this text, whatever `replace` says, and no image marker is built.
16
+ */
17
+ replacement?: string;
13
18
  }
14
19
  /**
15
20
  * Cheap check on raw bytes before anyone decodes a whole transcript to text: does it hold a data
@@ -83,9 +83,9 @@ export function replaceImagesWithMarkers(text, images, replace) {
83
83
  let replacedCount = 0;
84
84
  let charsSaved = 0;
85
85
  for (const image of images) {
86
- if (!replace(image))
86
+ if (image.replacement === undefined && !replace(image))
87
87
  continue;
88
- const marker = formatImageMarker({
88
+ const marker = image.replacement ?? formatImageMarker({
89
89
  sha256: image.sha256,
90
90
  mediaType: image.mediaType,
91
91
  byteSize: image.byteSize,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.88",
3
+ "version": "0.1.89",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",