@peasant-labs/schema 0.44.0 → 0.46.0

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.
@@ -1,6 +1,6 @@
1
1
  export declare function sessionGraphCapabilityFixtures(): {
2
2
  readonly requiredNames: {
3
- readonly derivation: readonly ["legacy-empty", "root-null", "usage-null", "model-only", "source-ref-only", "count-only-zero", "count-only-positive", "root-only", "purpose-only-interaction", "purpose-only-delegated", "purpose-only-helper", "purpose-only-unknown", "relationship-only", "main-deeper-provenance", "folded-call-provenance", "folded-result-provenance", "earlier-only", "earlier-nested-tool-native-usage-model", "navigation-only-read", "retained-accumulates-all", "thinking-level-session-seed", "thinking-level-raw-only-seed", "thinking-level-root-turn", "thinking-level-earlier-nested-turn", "thinking-level-absent-needs-no-token"];
3
+ readonly derivation: readonly ["legacy-empty", "root-null", "usage-null", "model-only", "source-ref-only", "count-only-zero", "count-only-positive", "root-only", "purpose-only-interaction", "purpose-only-delegated", "purpose-only-helper", "purpose-only-unknown", "relationship-only", "main-deeper-provenance", "folded-call-provenance", "folded-result-provenance", "earlier-only", "earlier-nested-tool-native-usage-model", "navigation-only-read", "retained-accumulates-all", "thinking-level-session-seed", "thinking-level-raw-only-seed", "thinking-level-root-turn", "thinking-level-earlier-nested-turn", "thinking-level-absent-needs-no-token", "content-parts-root-text-only", "content-parts-root-image", "content-parts-earlier-nested"];
4
4
  readonly reader: readonly ["advertisement-omitted", "advertisement-empty", "advertisement-null", "advertisement-unknown-duplicate-unordered", "advertisement-future-suffix", "advertisement-retained-duplicate"];
5
5
  readonly producer: readonly ["producer-canonical-four", "producer-unsorted-four", "producer-duplicate", "producer-unknown", "producer-canonical-retained", "producer-unsorted-retained", "producer-duplicate-retained", "producer-canonical-thinking-level", "producer-unsorted-thinking-level"];
6
6
  };
@@ -393,6 +393,54 @@ export declare function sessionGraphCapabilityFixtures(): {
393
393
  readonly detailJSON: "{\"id\":\"fixture-session\",\"startTime\":\"2020-01-01T00:00:00Z\",\"endTime\":\"2020-01-01T00:00:00Z\",\"durationMins\":0,\"totalTokens\":0,\"tokensIn\":0,\"tokensOut\":0,\"turnCount\":1,\"toolCallCount\":0,\"harness\":\"codex\",\"outcome\":\"resolved\",\"sessionOrigin\":\"unknown\",\"turns\":[{\"index\":0,\"role\":\"assistant\",\"content\":\"\",\"depth\":0,\"timestamp\":\"2020-01-01T00:00:00Z\"}]}";
394
394
  };
395
395
  readonly expected: {};
396
+ }, {
397
+ readonly name: "content-parts-root-text-only";
398
+ readonly classification: "must-pass";
399
+ readonly provenance: {
400
+ readonly source: "requirement";
401
+ readonly ref: "content-capability-negotiation content_parts_v1";
402
+ };
403
+ readonly mutation: {
404
+ readonly description: "adds one ordered text part to a root turn";
405
+ };
406
+ readonly input: {
407
+ readonly detailJSON: "{\"id\":\"fixture-session\",\"startTime\":\"2020-01-01T00:00:00Z\",\"endTime\":\"2020-01-01T00:00:00Z\",\"durationMins\":0,\"totalTokens\":0,\"tokensIn\":0,\"tokensOut\":0,\"turnCount\":1,\"toolCallCount\":0,\"harness\":\"claude-code\",\"outcome\":\"resolved\",\"sessionOrigin\":\"unknown\",\"turns\":[{\"index\":0,\"role\":\"user\",\"content\":\"\",\"depth\":0,\"timestamp\":\"2020-01-01T00:00:00Z\",\"contentParts\":[{\"type\":\"text\",\"text\":\"look\"}]}]}";
408
+ };
409
+ readonly expected: {
410
+ readonly capabilities: readonly ["content_parts_v1"];
411
+ };
412
+ }, {
413
+ readonly name: "content-parts-root-image";
414
+ readonly classification: "must-pass";
415
+ readonly provenance: {
416
+ readonly source: "requirement";
417
+ readonly ref: "content-capability-negotiation content_parts_v1";
418
+ };
419
+ readonly mutation: {
420
+ readonly description: "adds one inline local image part to a root turn";
421
+ };
422
+ readonly input: {
423
+ readonly detailJSON: "{\"id\":\"fixture-session\",\"startTime\":\"2020-01-01T00:00:00Z\",\"endTime\":\"2020-01-01T00:00:00Z\",\"durationMins\":0,\"totalTokens\":0,\"tokensIn\":0,\"tokensOut\":0,\"turnCount\":1,\"toolCallCount\":0,\"harness\":\"claude-code\",\"outcome\":\"resolved\",\"sessionOrigin\":\"unknown\",\"turns\":[{\"index\":0,\"role\":\"user\",\"content\":\"\",\"depth\":0,\"timestamp\":\"2020-01-01T00:00:00Z\",\"contentParts\":[{\"type\":\"image\",\"image\":{\"ref\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"mediaType\":\"image/png\",\"byteSize\":2048}}]}]}";
424
+ };
425
+ readonly expected: {
426
+ readonly capabilities: readonly ["content_parts_v1"];
427
+ };
428
+ }, {
429
+ readonly name: "content-parts-earlier-nested";
430
+ readonly classification: "must-pass";
431
+ readonly provenance: {
432
+ readonly source: "requirement";
433
+ readonly ref: "content-capability-negotiation content_parts_v1";
434
+ };
435
+ readonly mutation: {
436
+ readonly description: "adds an ordered text part inside an earlier-history partition";
437
+ };
438
+ readonly input: {
439
+ readonly detailJSON: "{\"id\":\"fixture-session\",\"startTime\":\"2020-01-01T00:00:00Z\",\"endTime\":\"2020-01-01T00:00:00Z\",\"durationMins\":0,\"totalTokens\":0,\"tokensIn\":0,\"tokensOut\":0,\"turnCount\":0,\"toolCallCount\":0,\"harness\":\"claude-code\",\"outcome\":\"resolved\",\"sessionOrigin\":\"unknown\",\"turns\":[],\"earlierHistory\":[{\"state\":\"uncertain_migrated\",\"turns\":[{\"index\":0,\"role\":\"assistant\",\"content\":\"\",\"depth\":0,\"timestamp\":\"2020-01-01T00:00:00Z\",\"contentParts\":[{\"type\":\"text\",\"text\":\"look\"}]}]}]}";
440
+ };
441
+ readonly expected: {
442
+ readonly capabilities: readonly ["content_parts_v1", "session_graph_provenance_v1"];
443
+ };
396
444
  }];
397
445
  };
398
446
  readonly reader: {
package/dist/index.js CHANGED
@@ -55,13 +55,19 @@ function scanRawJson(text, policy) {
55
55
  return scanner;
56
56
  }
57
57
  export function parseSessionDetailPayloadValue(value) {
58
+ return parseSessionDetailPayloadForMode(value, "local");
59
+ }
60
+ function parsePublishedSessionDetailPayloadValue(value) {
61
+ return parseSessionDetailPayloadForMode(value, "published");
62
+ }
63
+ function parseSessionDetailPayloadForMode(value, mode) {
58
64
  rejectWireAliases(value, "SessionDetailPayload");
59
65
  rejectExplicitNullEvidence(value);
60
66
  validateRawGraphValue(value);
61
67
  const normalized = structuredClone(value);
62
68
  normalizeEmptyOptionalPublicRefs(normalized);
63
69
  const payload = zSessionDetailPayload.parse(normalized);
64
- validateSessionDetail(payload);
70
+ validateSessionDetail(payload, mode);
65
71
  return payload;
66
72
  }
67
73
  function normalizeEmptyOptionalPublicRefs(value) {
@@ -125,11 +131,14 @@ export function parseTranscriptContentText(text) {
125
131
  if (!isRecord(raw))
126
132
  return zTranscriptContent.parse(raw);
127
133
  rejectWireAliases(raw, "TranscriptContent");
128
- const normalizedEnvelope = { ...raw, sessionDetail: parseSessionDetailPayloadValue(raw.sessionDetail) };
134
+ // TranscriptContent is publication-only: peasant builds it for push, while a
135
+ // standalone local export is a bare SessionDetailPayload. Decode its detail
136
+ // with the published image shape so a local ref or size cannot leak through.
137
+ const normalizedEnvelope = { ...raw, sessionDetail: parsePublishedSessionDetailPayloadValue(raw.sessionDetail) };
129
138
  const content = zTranscriptContent.parse(normalizedEnvelope);
130
139
  if (content.sessionDetail === undefined || content.sessionDetail === null)
131
140
  failSemantic("sessionDetail is required");
132
- parseSessionDetailPayloadValue(content.sessionDetail);
141
+ parsePublishedSessionDetailPayloadValue(content.sessionDetail);
133
142
  return content;
134
143
  }
135
144
  export function parseServerMessageRaw(text) {
@@ -304,19 +313,38 @@ class RawJsonScanner {
304
313
  fail(reason) { throw new TypeError(`Raw JSON validation failed at @peasant-labs/schema scanRawJsonText during pre-decode scanning near character ${this.position}: ${reason}; JSON.parse would otherwise lose or misinterpret evidence; correct the raw JSON and retry.`); }
305
314
  }
306
315
  function pointerMatches(pattern, path) { const expected = pattern.split("/"); const actual = path.split("/"); return expected.length === actual.length && expected.every((part, index) => part === "*" || part === actual[index]); }
307
- function validateSessionDetail(payload) {
316
+ function validateSessionDetail(payload, mode) {
308
317
  validateRetainedUnknown(payload);
309
318
  validateRelationships(payload);
319
+ validateContentParts(payload.turns ?? [], mode);
310
320
  const state = newDetailState(payload);
311
321
  const turns = validateTurnEvidence(payload.turns ?? [], state);
312
322
  validateMetadataRecords(payload.nativeMetadata ?? [], turns, state);
313
323
  for (const section of payload.earlierHistory ?? []) {
324
+ validateContentParts(section.turns ?? [], mode);
314
325
  const earlierTurns = validateTurnEvidence(section.turns ?? [], state);
315
326
  validateMetadataRecords(section.nativeMetadata ?? [], earlierTurns, state);
316
327
  }
317
328
  if (state.nativeCount > 0 && String(payload.harness) !== "pi")
318
329
  failSemantic("Pi native metadata requires harness pi across every history partition");
319
330
  }
331
+ function validateContentParts(turns, mode) {
332
+ for (const turn of turns)
333
+ for (const part of turn.contentParts ?? []) {
334
+ if (part.type === "text") {
335
+ if (part.text !== undefined && !validUnicode(part.text))
336
+ failSemantic("content part text is not valid Unicode");
337
+ continue;
338
+ }
339
+ if (part.image === undefined)
340
+ continue; // the part-level schema already refuses this
341
+ const reason = part.image.omittedReason;
342
+ if (mode === "local" && reason === "not_published")
343
+ failSemantic("durable local detail must not carry the not_published image reason");
344
+ if (mode === "published" && reason !== "not_published")
345
+ failSemantic("a published detail must carry the not_published image reason on every image part");
346
+ }
347
+ }
320
348
  function validateRetainedUnknown(payload) {
321
349
  if ((payload.retainedUnknown?.length ?? 0) > 0 && payload.diagnostics?.partial !== true)
322
350
  failSemantic("retainedUnknown requires diagnostics.partial=true");
@@ -9,6 +9,7 @@ import type { SessionDetailPayload } from "./contract/zod.gen.js";
9
9
  * discovered list down to the tokens they understand without stringly typing.
10
10
  */
11
11
  export declare const KnownContentCapability: Readonly<{
12
+ readonly ContentPartsV1: "content_parts_v1";
12
13
  readonly DetailedUsageV1: "detailed_usage_v1";
13
14
  readonly NativeMetadataV1: "native_metadata_v1";
14
15
  readonly ObservedModelV1: "observed_model_v1";
@@ -8,6 +8,7 @@
8
8
  * discovered list down to the tokens they understand without stringly typing.
9
9
  */
10
10
  export const KnownContentCapability = Object.freeze({
11
+ ContentPartsV1: "content_parts_v1",
11
12
  DetailedUsageV1: "detailed_usage_v1",
12
13
  NativeMetadataV1: "native_metadata_v1",
13
14
  ObservedModelV1: "observed_model_v1",
@@ -16,7 +17,7 @@ export const KnownContentCapability = Object.freeze({
16
17
  ThinkingLevelV1: "thinking_level_v1",
17
18
  ToolNamespaceV1: "tool_namespace_v1",
18
19
  });
19
- export const AllContentCapabilities = Object.freeze([KnownContentCapability.DetailedUsageV1, KnownContentCapability.NativeMetadataV1, KnownContentCapability.ObservedModelV1, KnownContentCapability.RetainedUnknownV1, KnownContentCapability.SessionGraphProvenanceV1, KnownContentCapability.ThinkingLevelV1, KnownContentCapability.ToolNamespaceV1]);
20
+ export const AllContentCapabilities = Object.freeze([KnownContentCapability.ContentPartsV1, KnownContentCapability.DetailedUsageV1, KnownContentCapability.NativeMetadataV1, KnownContentCapability.ObservedModelV1, KnownContentCapability.RetainedUnknownV1, KnownContentCapability.SessionGraphProvenanceV1, KnownContentCapability.ThinkingLevelV1, KnownContentCapability.ToolNamespaceV1]);
20
21
  export function isContentCapability(value) {
21
22
  return typeof value === "string" && AllContentCapabilities.includes(value);
22
23
  }
@@ -45,6 +46,8 @@ function visitTurns(turns, found) {
45
46
  found.add(KnownContentCapability.ObservedModelV1);
46
47
  if ((turn.thinkingLevel ?? "") !== "" || (turn.thinkingLevelRaw ?? "") !== "")
47
48
  found.add(KnownContentCapability.ThinkingLevelV1);
49
+ if ((turn.contentParts?.length ?? 0) > 0)
50
+ found.add(KnownContentCapability.ContentPartsV1);
48
51
  if (turn.toolCalls?.some((tool) => tool.namespace !== undefined))
49
52
  found.add(KnownContentCapability.ToolNamespaceV1);
50
53
  if (turn.usage != null || turn.toolCalls?.some((tool) => tool.usage != null))