@bli-cockpit/telemetry-core 0.1.71 → 0.1.72
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.
|
@@ -6,23 +6,30 @@
|
|
|
6
6
|
* line. Measured on one laptop on 2026-10-09 that was 17% of Claude bytes and 59% of Codex bytes.
|
|
7
7
|
* The collector finds every such image, sends each distinct one ONCE to the describe door (a
|
|
8
8
|
* short text description, kept against the image's sha256), and, only when the switch below says
|
|
9
|
-
* so, replaces the base64 in the uploaded transcript with the short marker built here
|
|
9
|
+
* so, replaces the base64 in the uploaded transcript with the short marker built here and strips
|
|
10
|
+
* the transcript's duplicate copies and bookkeeping (the slim transcript).
|
|
10
11
|
*
|
|
11
12
|
* This file is shared by the collector (builds the marker, builds the request), the dashboard
|
|
12
13
|
* (validates the request, answers) and anything that reads a marker back. Pure: no I/O, no env.
|
|
13
14
|
*/
|
|
14
15
|
import { z } from "zod";
|
|
15
16
|
/**
|
|
16
|
-
* `describe_and_keep` every distinct image is described, the transcript still carries the image
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* `describe_and_keep` every distinct image is described, the transcript still carries the image and
|
|
18
|
+
* is uploaded exactly as it is on disk. The slim transcript is NOT computed
|
|
19
|
+
* and NOT uploaded in this mode.
|
|
20
|
+
* `describe_and_drop` every image that has a stored description is replaced by its marker (an image
|
|
21
|
+
* that could not be described is KEPT, never dropped without a description),
|
|
22
|
+
* and the uploaded transcript is the SLIM transcript: the duplicate copies and
|
|
23
|
+
* the bookkeeping are stripped too, every line stays. What is stripped and
|
|
24
|
+
* kept: docs/architecture/image-descriptions.md, code in
|
|
25
|
+
* packages/cockpit-local-collector/src/slim/.
|
|
20
26
|
*/
|
|
21
27
|
export type ImageHandlingMode = "describe_and_keep" | "describe_and_drop";
|
|
22
28
|
/**
|
|
23
|
-
* The one line Edward changes to start
|
|
24
|
-
*
|
|
25
|
-
*
|
|
29
|
+
* The one line Edward changes to start uploading slim transcripts (images described and dropped,
|
|
30
|
+
* duplicate copies and bookkeeping stripped). Default is keep. The collector reads it at run time,
|
|
31
|
+
* so flipping it needs a CLI release (`gh workflow run release.yml -f tag=latest`) and then
|
|
32
|
+
* `cockpit settings cli-floor <version>`; no other file changes.
|
|
26
33
|
*/
|
|
27
34
|
export declare const IMAGE_HANDLING_MODE: ImageHandlingMode;
|
|
28
35
|
/**
|
|
@@ -6,16 +6,18 @@
|
|
|
6
6
|
* line. Measured on one laptop on 2026-10-09 that was 17% of Claude bytes and 59% of Codex bytes.
|
|
7
7
|
* The collector finds every such image, sends each distinct one ONCE to the describe door (a
|
|
8
8
|
* short text description, kept against the image's sha256), and, only when the switch below says
|
|
9
|
-
* so, replaces the base64 in the uploaded transcript with the short marker built here
|
|
9
|
+
* so, replaces the base64 in the uploaded transcript with the short marker built here and strips
|
|
10
|
+
* the transcript's duplicate copies and bookkeeping (the slim transcript).
|
|
10
11
|
*
|
|
11
12
|
* This file is shared by the collector (builds the marker, builds the request), the dashboard
|
|
12
13
|
* (validates the request, answers) and anything that reads a marker back. Pure: no I/O, no env.
|
|
13
14
|
*/
|
|
14
15
|
import { z } from "zod";
|
|
15
16
|
/**
|
|
16
|
-
* The one line Edward changes to start
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* The one line Edward changes to start uploading slim transcripts (images described and dropped,
|
|
18
|
+
* duplicate copies and bookkeeping stripped). Default is keep. The collector reads it at run time,
|
|
19
|
+
* so flipping it needs a CLI release (`gh workflow run release.yml -f tag=latest`) and then
|
|
20
|
+
* `cockpit settings cli-floor <version>`; no other file changes.
|
|
19
21
|
*/
|
|
20
22
|
export const IMAGE_HANDLING_MODE = "describe_and_keep";
|
|
21
23
|
// ---------------------------------------------------------------------------
|
|
@@ -11,7 +11,10 @@ export interface EmbeddedImage {
|
|
|
11
11
|
/** Decoded size in bytes. */
|
|
12
12
|
byteSize: number;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Cheap check on raw bytes before anyone decodes a whole transcript to text: does it hold a data
|
|
16
|
+
* URL, or a string that starts the way a PNG, JPEG, GIF or WebP does in base64?
|
|
17
|
+
*/
|
|
15
18
|
export declare function mightHoldEmbeddedImages(bytes: Buffer): boolean;
|
|
16
19
|
/** Every embedded image in `text`, in order. Runs that are not images are skipped. */
|
|
17
20
|
export declare function findEmbeddedImages(text: string): EmbeddedImage[];
|
|
@@ -1,41 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Find the base64 images inside a transcript's text, and swap them for short markers (BLI-16977).
|
|
3
3
|
*
|
|
4
|
-
* A
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* A transcript stores a picture as one long run of base64 characters, in one of two shapes:
|
|
5
|
+
*
|
|
6
|
+
* - a JSON string that is NOTHING BUT the run (`"data":"<base64>"` in a Claude image block, a
|
|
7
|
+
* Codex `image_gen` result, an MCP image, a Codex `toolSurface.screenshot` value, ...). Any key
|
|
8
|
+
* name, any depth: the finder looks at the string, not at what it is called.
|
|
9
|
+
* - a data URL (`data:image/png;base64,<base64>`) anywhere inside a string (a Codex `image_url`).
|
|
10
|
+
*
|
|
11
|
+
* Either way this file decodes each run far enough to know it IS an image (magic bytes, never the
|
|
12
|
+
* transcript's own claim) and what its sha256 is, and can rewrite the text with a marker in place
|
|
13
|
+
* of chosen images.
|
|
9
14
|
*
|
|
10
15
|
* Pure: text in, text out. No network, no disk, no environment. A run that does not decode to a
|
|
11
16
|
* PNG, JPEG, GIF or WebP is left exactly as it is (a PDF, a long token, a hex dump).
|
|
12
17
|
*
|
|
13
|
-
* The rewrite keeps the JSON line valid: in the
|
|
14
|
-
* inside its quotes; in the
|
|
15
|
-
*
|
|
18
|
+
* The rewrite keeps the JSON line valid: in the whole-string form only the base64 is replaced,
|
|
19
|
+
* inside its quotes; in the data-URL form the whole data URL is replaced, inside the string it sat
|
|
20
|
+
* in. So every parser that read the line before still reads it.
|
|
16
21
|
*/
|
|
17
22
|
import { createHash } from "node:crypto";
|
|
18
23
|
import { IMAGE_MIN_BASE64_CHARS, formatImageMarker, sniffImageMediaType, } from "./image-descriptions.js";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
const BASE64_RUN = `[A-Za-z0-9+/=]{${IMAGE_MIN_BASE64_CHARS},}`;
|
|
25
|
+
/**
|
|
26
|
+
* What the first characters of a base64 run look like for each type we accept: PNG `iVBOR`, JPEG
|
|
27
|
+
* `/9j/`, GIF `R0lGO`, WebP (RIFF) `UklGR`. Anchoring the whole-string form on these keeps the scan
|
|
28
|
+
* fast (no 500-character attempt after every quote); the decoded bytes are still sniffed after.
|
|
29
|
+
*/
|
|
30
|
+
const IMAGE_BASE64_STARTS = String.raw `(?:iVBOR|\/9j\/|R0lGO|UklGR)`;
|
|
31
|
+
/**
|
|
32
|
+
* 1: a run that starts like an image and sits between two quotes (plain `"` or the `\"` of a JSON
|
|
33
|
+
* string that was itself stored inside a string), so it is the whole string.
|
|
34
|
+
* 2: a data URL prefix, then the run.
|
|
35
|
+
*/
|
|
36
|
+
const IMAGE_STRING = new RegExp(`(?<=")(${IMAGE_BASE64_STARTS}[A-Za-z0-9+/=]{${IMAGE_MIN_BASE64_CHARS - 5},})(?=\\\\?")|(data:image/[a-z0-9.+-]+;base64,)(${BASE64_RUN})`, "g");
|
|
37
|
+
/**
|
|
38
|
+
* Cheap check on raw bytes before anyone decodes a whole transcript to text: does it hold a data
|
|
39
|
+
* URL, or a string that starts the way a PNG, JPEG, GIF or WebP does in base64?
|
|
40
|
+
*/
|
|
22
41
|
export function mightHoldEmbeddedImages(bytes) {
|
|
23
|
-
return bytes.includes("base64") ||
|
|
42
|
+
return (bytes.includes("base64") ||
|
|
43
|
+
bytes.includes("iVBOR") ||
|
|
44
|
+
bytes.includes("/9j/") ||
|
|
45
|
+
bytes.includes("R0lGO") ||
|
|
46
|
+
bytes.includes("UklGR"));
|
|
24
47
|
}
|
|
25
48
|
/** Every embedded image in `text`, in order. Runs that are not images are skipped. */
|
|
26
49
|
export function findEmbeddedImages(text) {
|
|
27
50
|
const found = [];
|
|
28
|
-
for (const match of text.matchAll(
|
|
29
|
-
const
|
|
30
|
-
const run = (
|
|
51
|
+
for (const match of text.matchAll(IMAGE_STRING)) {
|
|
52
|
+
const isWholeString = match[1] !== undefined;
|
|
53
|
+
const run = (isWholeString ? match[1] : match[3]) ?? "";
|
|
31
54
|
const matchStart = match.index ?? 0;
|
|
32
|
-
const base64Start = matchStart + (
|
|
55
|
+
const base64Start = matchStart + (isWholeString ? 0 : match[2].length);
|
|
33
56
|
const bytes = Buffer.from(run, "base64");
|
|
34
57
|
const mediaType = sniffImageMediaType(bytes);
|
|
35
58
|
if (!mediaType)
|
|
36
59
|
continue;
|
|
37
60
|
found.push({
|
|
38
|
-
replaceStart:
|
|
61
|
+
replaceStart: isWholeString ? base64Start : matchStart,
|
|
39
62
|
replaceEnd: base64Start + run.length,
|
|
40
63
|
base64Start,
|
|
41
64
|
base64End: base64Start + run.length,
|