@bli-cockpit/telemetry-core 0.1.90 → 0.1.92

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,12 @@
1
+ /**
2
+ * The click-by-click guide for the one manual step in the BLI Memory rollout:
3
+ * trusting the bli-memory hooks in Codex (CLI and ChatGPT desktop app, macOS
4
+ * and Windows). Every surface that tells a person "trust the hooks" links here
5
+ * instead of stopping at "run /hooks": the fleet board line, `cockpit doctor`,
6
+ * `cockpit memory install`, the machine health card.
7
+ *
8
+ * Its own file, and its own `./codex-hooks-trust-guide` export, so a browser
9
+ * component can import one string without pulling in the whole package.
10
+ * Repo copy of the guide: `docs/runbooks/codex-hooks-trust.md` (BLI-23315).
11
+ */
12
+ export declare const CODEX_HOOKS_TRUST_GUIDE_URL = "https://tower.buildlaunchiterate.ca/docs/trust-the-bli-memory-hooks-in-codex";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The click-by-click guide for the one manual step in the BLI Memory rollout:
3
+ * trusting the bli-memory hooks in Codex (CLI and ChatGPT desktop app, macOS
4
+ * and Windows). Every surface that tells a person "trust the hooks" links here
5
+ * instead of stopping at "run /hooks": the fleet board line, `cockpit doctor`,
6
+ * `cockpit memory install`, the machine health card.
7
+ *
8
+ * Its own file, and its own `./codex-hooks-trust-guide` export, so a browser
9
+ * component can import one string without pulling in the whole package.
10
+ * Repo copy of the guide: `docs/runbooks/codex-hooks-trust.md` (BLI-23315).
11
+ */
12
+ export const CODEX_HOOKS_TRUST_GUIDE_URL = "https://tower.buildlaunchiterate.ca/docs/trust-the-bli-memory-hooks-in-codex";
@@ -130,6 +130,13 @@ export declare const RawEvidenceUploadBeginObjectSchema: z.ZodObject<{
130
130
  }, z.core.$strict>;
131
131
  chunk_size_bytes: z.ZodNumber;
132
132
  chunk_count: z.ZodNumber;
133
+ image_use: z.ZodOptional<z.ZodObject<{
134
+ session_id: z.ZodString;
135
+ source: z.ZodEnum<{
136
+ codex: "codex";
137
+ claude_code: "claude_code";
138
+ }>;
139
+ }, z.core.$strict>>;
133
140
  }, z.core.$strict>;
134
141
  export type RawEvidenceUploadBeginObject = z.infer<typeof RawEvidenceUploadBeginObjectSchema>;
135
142
  export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
@@ -235,6 +242,13 @@ export declare const RawEvidenceUploadBeginRequestSchema: z.ZodObject<{
235
242
  }, z.core.$strict>;
236
243
  chunk_size_bytes: z.ZodNumber;
237
244
  chunk_count: z.ZodNumber;
245
+ image_use: z.ZodOptional<z.ZodObject<{
246
+ session_id: z.ZodString;
247
+ source: z.ZodEnum<{
248
+ codex: "codex";
249
+ claude_code: "claude_code";
250
+ }>;
251
+ }, z.core.$strict>>;
238
252
  }, z.core.$strict>>;
239
253
  }, z.core.$strict>;
240
254
  export type RawEvidenceUploadBeginRequest = z.infer<typeof RawEvidenceUploadBeginRequestSchema>;
@@ -407,6 +421,13 @@ export declare const RawEvidenceUploadCommitRequestSchema: z.ZodObject<{
407
421
  byte_size: z.ZodNumber;
408
422
  chunk_hash_sha256: z.ZodString;
409
423
  }, z.core.$strict>>>;
424
+ image_use: z.ZodOptional<z.ZodObject<{
425
+ session_id: z.ZodString;
426
+ source: z.ZodEnum<{
427
+ codex: "codex";
428
+ claude_code: "claude_code";
429
+ }>;
430
+ }, z.core.$strict>>;
410
431
  }, z.core.$strict>;
411
432
  export type RawEvidenceUploadCommitRequest = z.infer<typeof RawEvidenceUploadCommitRequestSchema>;
412
433
  export declare const RawEvidenceUploadCommitResponseSchema: z.ZodObject<{
@@ -1,5 +1,6 @@
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";
@@ -83,6 +84,12 @@ export const RawEvidenceUploadBeginObjectSchema = z
83
84
  .int()
84
85
  .positive()
85
86
  .max(RAW_EVIDENCE_UPLOAD_MAX_CHUNK_COUNT),
87
+ /**
88
+ * BLI-23329: required when the object key is an image object (`<operator>/images/<sha256>.<ext>`), refused
89
+ * on any other. Names the agent session this image is staged for, so the server can record that session as
90
+ * a user of the image in the same step that confirms it.
91
+ */
92
+ image_use: ImageUseSchema.optional(),
86
93
  })
87
94
  .strict();
88
95
  export const RawEvidenceUploadBeginRequestSchema = z
@@ -175,6 +182,8 @@ export const RawEvidenceUploadCommitRequestSchema = z
175
182
  upload_id: NonEmptyStringSchema,
176
183
  object_key: NonEmptyStringSchema,
177
184
  direct_chunks: z.array(RawEvidenceDirectChunkSchema).max(RAW_EVIDENCE_UPLOAD_MAX_CHUNK_COUNT).optional(),
185
+ /** BLI-23329: as on `begin`; the commit of an image object records this session as a user of the image. */
186
+ image_use: ImageUseSchema.optional(),
178
187
  })
179
188
  .strict();
180
189
  export const RawEvidenceUploadCommitResponseSchema = z
@@ -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
@@ -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 "./image-store.js";
17
18
  export * from "./pdf-markers.js";
18
19
  export * from "./transcript-images.js";
19
20
  export * from "./image-byte-scan.js";
@@ -24,6 +25,7 @@ export * from "./memory-hook-stats.js";
24
25
  export * from "./sync-revive-contract.js";
25
26
  export * from "./memory-extract-context.js";
26
27
  export * from "./memory-hook-performance.js";
28
+ export * from "./codex-hooks-trust-guide.js";
27
29
  export * from "./memory-install-receipt.js";
28
30
  export * from "./outbound-guard.js";
29
31
  export * from "./paths.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 "./image-store.js";
17
18
  export * from "./pdf-markers.js";
18
19
  export * from "./transcript-images.js";
19
20
  export * from "./image-byte-scan.js";
@@ -24,6 +25,7 @@ export * from "./memory-hook-stats.js";
24
25
  export * from "./sync-revive-contract.js";
25
26
  export * from "./memory-extract-context.js";
26
27
  export * from "./memory-hook-performance.js";
28
+ export * from "./codex-hooks-trust-guide.js";
27
29
  export * from "./memory-install-receipt.js";
28
30
  export * from "./outbound-guard.js";
29
31
  export * from "./paths.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.90",
3
+ "version": "0.1.92",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,6 +15,11 @@
15
15
  "import": "./dist/index.js",
16
16
  "default": "./dist/index.js"
17
17
  },
18
+ "./codex-hooks-trust-guide": {
19
+ "types": "./dist/codex-hooks-trust-guide.d.ts",
20
+ "import": "./dist/codex-hooks-trust-guide.js",
21
+ "default": "./dist/codex-hooks-trust-guide.js"
22
+ },
18
23
  "./memory-experience": {
19
24
  "types": "./dist/memory-experience.d.ts",
20
25
  "import": "./dist/memory-experience.js",