@silverprotocol/core 0.12.4 → 1.0.0-rc.1

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.
Files changed (57) hide show
  1. package/README.md +17 -9
  2. package/dist/agjson.d.ts +594 -594
  3. package/dist/agjson.d.ts.map +1 -1
  4. package/dist/agjson.js +132 -17
  5. package/dist/agjson.js.map +1 -1
  6. package/dist/atomic-push.js.map +1 -1
  7. package/dist/copy-json.d.ts +31 -4
  8. package/dist/copy-json.d.ts.map +1 -1
  9. package/dist/copy-json.js +147 -15
  10. package/dist/copy-json.js.map +1 -1
  11. package/dist/depth.d.ts +34 -0
  12. package/dist/depth.d.ts.map +1 -0
  13. package/dist/depth.js +141 -0
  14. package/dist/depth.js.map +1 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/ingest.d.ts +7 -2
  20. package/dist/ingest.d.ts.map +1 -1
  21. package/dist/ingest.js +36 -4
  22. package/dist/ingest.js.map +1 -1
  23. package/dist/input-check.d.ts.map +1 -1
  24. package/dist/input-check.js +17 -3
  25. package/dist/input-check.js.map +1 -1
  26. package/dist/json-patch.d.ts.map +1 -1
  27. package/dist/json-patch.js +17 -9
  28. package/dist/json-patch.js.map +1 -1
  29. package/dist/persist.js.map +1 -1
  30. package/dist/record.d.ts.map +1 -1
  31. package/dist/record.js +25 -6
  32. package/dist/record.js.map +1 -1
  33. package/dist/reduce.d.ts +1 -1
  34. package/dist/reduce.d.ts.map +1 -1
  35. package/dist/reduce.js +293 -112
  36. package/dist/reduce.js.map +1 -1
  37. package/dist/stream-assembler.d.ts +6 -7
  38. package/dist/stream-assembler.d.ts.map +1 -1
  39. package/dist/stream-assembler.js +21 -18
  40. package/dist/stream-assembler.js.map +1 -1
  41. package/dist/wire.d.ts +21 -3
  42. package/dist/wire.d.ts.map +1 -1
  43. package/dist/wire.js +34 -5
  44. package/dist/wire.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/agjson.ts +128 -28
  47. package/src/atomic-push.ts +2 -2
  48. package/src/copy-json.ts +143 -17
  49. package/src/depth.ts +138 -0
  50. package/src/index.ts +1 -0
  51. package/src/ingest.ts +35 -4
  52. package/src/input-check.ts +15 -3
  53. package/src/json-patch.ts +21 -8
  54. package/src/record.ts +25 -6
  55. package/src/reduce.ts +273 -111
  56. package/src/stream-assembler.ts +21 -18
  57. package/src/wire.ts +36 -6
package/dist/wire.js CHANGED
@@ -29,6 +29,22 @@ export const JSON_SAFE_MAX_DEPTH_MARK = "[MaxDepth]";
29
29
  * @beta
30
30
  */
31
31
  export const JSON_SAFE_MAX_DEPTH = 1000;
32
+ /**
33
+ * The levels an event's own members may add above a carried value that
34
+ * {@link toJsonValueSafe} capped at {@link JSON_SAFE_MAX_DEPTH}.
35
+ *
36
+ * @beta
37
+ */
38
+ export const AG_EVENT_DEPTH_ALLOWANCE = 16;
39
+ /**
40
+ * The deepest node an event may hold, counted from the event root: the root is
41
+ * at depth 0 and a node's depth is the number of containers above it.
42
+ * {@link JSON_SAFE_MAX_DEPTH} plus {@link AG_EVENT_DEPTH_ALLOWANCE}. A consuming
43
+ * ingest rejects a deeper event, and a reducer parks on one.
44
+ *
45
+ * @beta
46
+ */
47
+ export const AG_EVENT_MAX_DEPTH = JSON_SAFE_MAX_DEPTH + AG_EVENT_DEPTH_ALLOWANCE;
32
48
  /**
33
49
  * True when `v` is ALREADY a plain JSON value, i.e. exactly what a JSON
34
50
  * round-trip of it would produce: `null`, a string, a boolean, a finite
@@ -41,6 +57,15 @@ export const JSON_SAFE_MAX_DEPTH = 1000;
41
57
  * @beta
42
58
  */
43
59
  export function isJsonValue(v) {
60
+ return jsonWalk(v, false);
61
+ }
62
+ /** {@link isJsonValue} where every object also has the ordinary prototype
63
+ * (`Object.prototype`, or `Array.prototype` for an array): no null-prototype
64
+ * node. The fast path of {@link toJsonValueSafeWithIssues} uses it. */
65
+ function isOrdinaryJsonValue(v) {
66
+ return jsonWalk(v, true);
67
+ }
68
+ function jsonWalk(v, ordinaryOnly) {
44
69
  const ancestors = [];
45
70
  const walk = (x, depth) => {
46
71
  if (x === null)
@@ -62,6 +87,8 @@ export function isJsonValue(v) {
62
87
  ancestors.push(o);
63
88
  try {
64
89
  if (Array.isArray(o)) {
90
+ if (ordinaryOnly && Object.getPrototypeOf(o) !== Array.prototype)
91
+ return false;
65
92
  for (let i = 0; i < o.length; i++) {
66
93
  if (!(i in o) || !walk(o[i], depth + 1))
67
94
  return false;
@@ -69,7 +96,7 @@ export function isJsonValue(v) {
69
96
  return true;
70
97
  }
71
98
  const proto = Object.getPrototypeOf(o);
72
- if (proto !== Object.prototype && proto !== null)
99
+ if (proto !== Object.prototype && (ordinaryOnly || proto !== null))
73
100
  return false;
74
101
  if (typeof o.toJSON === "function")
75
102
  return false;
@@ -107,8 +134,10 @@ export function isJsonValue(v) {
107
134
  * Normalizer MUST NOT throw out of `push()` (SPEC.md §8.0). Keep
108
135
  * `JsonValue.parse` for validating data that is already JSON.
109
136
  *
110
- * Plain JSON input (see {@link isJsonValue}) is returned UNCHANGED, as the same
111
- * reference, with no copy. Anything else is rebuilt as a fresh value that
137
+ * Plain JSON input (see {@link isJsonValue}) whose every object has the
138
+ * ordinary prototype is returned UNCHANGED, as the same reference, with no
139
+ * copy. Anything else, a null-prototype node included, is rebuilt as a fresh
140
+ * value whose every object has the ordinary prototype and that
112
141
  * applies `JSON.stringify`'s own rules per node, so for JSON-able input the
113
142
  * result serializes identically to `toJsonValue(v)`:
114
143
  * - `toJSON` is honoured once per node, with the member key (a `Date` becomes
@@ -179,7 +208,7 @@ function isErrorObject(o) {
179
208
  * @beta
180
209
  */
181
210
  export function toJsonValueSafeWithIssues(v) {
182
- if (isJsonValue(v))
211
+ if (isOrdinaryJsonValue(v))
183
212
  return { value: v, issues: [] };
184
213
  const issues = [];
185
214
  const ancestors = [];
@@ -234,7 +263,7 @@ export function toJsonValueSafeWithIssues(v) {
234
263
  return JSON_SAFE_MAX_DEPTH_MARK;
235
264
  }
236
265
  if (isErrorObject(obj)) {
237
- // Deliberate extension beyond JSON (sp-main, 2026-09-24): an Error's
266
+ // Deliberate extension beyond JSON (ruled 2026-09-24): an Error's
238
267
  // `name` and `message` are not enumerable own data, so JSON drops them
239
268
  // and a live error part loses its text. Map it to {name, message, …own
240
269
  // enumerable props}, and NEVER `stack` (it holds local file paths).
package/dist/wire.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,MAAM,CAAC,CAAU;IAC/B,MAAM,CAAC,GAAc,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAU;IACpC,MAAM,CAAC,GAAc,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAC/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;AACrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAyBxC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,CAAU;IACpC,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,KAAa,EAAW,EAAE;QAClD,IAAI,CAAC,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAC5B,QAAQ,OAAO,CAAC,EAAE,CAAC;YACjB,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS;gBACZ,OAAO,IAAI,CA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AC,CAAC;IAEF,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IACnC,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;AACtD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silverprotocol/core",
3
- "version": "0.12.4",
3
+ "version": "1.0.0-rc.1",
4
4
  "description": "AgJSON core — the typed schema (AgInput / AgEvent / AgMessage), the Normalizer interface, and the normative reduce().",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/agjson.ts CHANGED
@@ -7,17 +7,106 @@ import { z } from "zod";
7
7
 
8
8
  // Opaque JSON value (spec §0.1 "unknown" = any-JSON pass-through; NEVER `any`).
9
9
  export type JsonValue = string | number | boolean | null | JsonValue[] | { [k: string]: JsonValue };
10
- export const JsonValue: z.ZodType<JsonValue> = z.lazy(() =>
10
+ // The rules: z.union([z.string(), z.number(), z.boolean(), z.null(),
11
+ // z.array(JsonValue), z.record(z.string(), JsonValue)]). That union recursed
12
+ // once per nesting level, so a value a thousand-odd levels deep overflowed the
13
+ // call stack (sooner in a cold process or under a deep caller). JsonValue
14
+ // applies the same rules in one iterative pass that builds the same output;
15
+ // the union below runs only to report why a value fails.
16
+ const JsonValueUnion: z.ZodType<JsonValue> = z.lazy(() =>
11
17
  z.union([
12
18
  z.string(),
13
19
  z.number(),
14
20
  z.boolean(),
15
21
  z.null(),
16
- z.array(JsonValue),
17
- z.record(z.string(), JsonValue),
22
+ z.array(JsonValueUnion),
23
+ z.record(z.string(), JsonValueUnion),
18
24
  ]),
19
25
  );
20
26
 
27
+ /** zod's isPlainObject: what z.record accepts as a record. */
28
+ function isZodPlainObject(o: object): boolean {
29
+ if (Array.isArray(o)) return false;
30
+ const ctor: unknown = (o as { constructor?: unknown }).constructor;
31
+ if (ctor === undefined || typeof ctor !== "function") return true;
32
+ const prot: unknown = (ctor as { prototype?: unknown }).prototype;
33
+ if (typeof prot !== "object" || prot === null || Array.isArray(prot)) return false;
34
+ return Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf");
35
+ }
36
+
37
+ const isJsonLeaf = (x: unknown): boolean =>
38
+ typeof x === "string" || typeof x === "boolean" || x === null || (typeof x === "number" && Number.isFinite(x));
39
+
40
+ /**
41
+ * The union's output for `v`, or undefined where the union rejects it, in one
42
+ * iterative pass: arrays element by element (a hole is undefined, so it
43
+ * fails), records as z.record reads them (zod's isPlainObject; own enumerable
44
+ * keys in Reflect.ownKeys order, `__proto__` skipped, a symbol key failing).
45
+ * A node reached twice yields one output node, as zod's memo does, so a cycle
46
+ * is copied as a cycle.
47
+ */
48
+ function jsonValueOutput(v: unknown): { value: JsonValue } | undefined {
49
+ if (isJsonLeaf(v)) return { value: v as JsonValue };
50
+ if (typeof v !== "object" || v === null) return undefined;
51
+ type Node = JsonValue[] | { [k: string]: JsonValue };
52
+ const outputs = new Map<object, Node>();
53
+ const pending: object[] = [];
54
+ const nodeOf = (x: object): Node | undefined => {
55
+ const seen = outputs.get(x);
56
+ if (seen !== undefined) return seen;
57
+ let node: Node;
58
+ if (Array.isArray(x)) node = [];
59
+ else if (isZodPlainObject(x)) node = {};
60
+ else return undefined;
61
+ outputs.set(x, node);
62
+ pending.push(x);
63
+ return node;
64
+ };
65
+ const valueOf = (x: unknown): JsonValue | undefined => {
66
+ if (isJsonLeaf(x)) return x as JsonValue;
67
+ if (typeof x !== "object" || x === null) return undefined;
68
+ return nodeOf(x);
69
+ };
70
+ const root = nodeOf(v);
71
+ if (root === undefined) return undefined;
72
+ while (pending.length > 0) {
73
+ const x = pending.pop()!;
74
+ const node = outputs.get(x)!;
75
+ if (Array.isArray(x)) {
76
+ for (let i = 0; i < x.length; i++) {
77
+ const out = valueOf(x[i]);
78
+ if (out === undefined) return undefined;
79
+ (node as JsonValue[])[i] = out;
80
+ }
81
+ continue;
82
+ }
83
+ for (const key of Reflect.ownKeys(x)) {
84
+ if (key === "__proto__") continue;
85
+ if (!Object.prototype.propertyIsEnumerable.call(x, key)) continue;
86
+ if (typeof key !== "string") return undefined;
87
+ const out = valueOf((x as Record<string, unknown>)[key]);
88
+ if (out === undefined) return undefined;
89
+ (node as { [k: string]: JsonValue })[key] = out;
90
+ }
91
+ }
92
+ return { value: root };
93
+ }
94
+
95
+ export const JsonValue: z.ZodType<JsonValue> = z.unknown().transform((v, ctx) => {
96
+ const out = jsonValueOutput(v);
97
+ if (out !== undefined) return out.value;
98
+ let issues: z.core.$ZodIssue[];
99
+ try {
100
+ const r = JsonValueUnion.safeParse(v);
101
+ issues = r.success ? [] : r.error.issues;
102
+ } catch {
103
+ issues = [];
104
+ }
105
+ if (issues.length === 0) issues = [{ code: "custom", message: "Invalid JSON value", path: [], input: v } as z.core.$ZodIssue];
106
+ for (const issue of issues) ctx.issues.push(issue as never);
107
+ return z.NEVER;
108
+ });
109
+
21
110
  // Host-only namespaced side metadata (spec §0.4 `_meta`).
22
111
  export const AgMeta = z.record(z.string(), JsonValue);
23
112
  export type AgMeta = z.infer<typeof AgMeta>;
@@ -32,7 +121,7 @@ export type AgSource = z.infer<typeof AgSource>;
32
121
 
33
122
  // Grounding-source payload union (spec §2/§4): the §4 `source` event's payload
34
123
  // union, extracted here so it can be reused verbatim by BOTH the event arm and
35
- // AgTurnRecord.sources[] — one definition, DRY, cast-free (audit M23).
124
+ // AgTurnRecord.sources[] — one definition, DRY, cast-free.
36
125
  export const AgSourcePayload = z.union([
37
126
  AgSource,
38
127
  z.object({ url: z.string(), title: z.string().optional() }),
@@ -443,7 +532,7 @@ export type AgBlock =
443
532
  toolMetadata?: AgMeta; // per-tool metadata bag (Vercel)
444
533
  dynamic?: boolean; // Vercel dynamic-vs-static tool distinction
445
534
  pendingInput?: AgPendingInput; // MCP MRTR carrier when outcome==="input_required"
446
- preliminary?: boolean; // set when the result is partial/kept-open (tool.done.more:true); cleared by the final tool.done (audit M20)
535
+ preliminary?: boolean; // set when the result is partial/kept-open (tool.done.more:true); cleared by the final tool.done
447
536
  isError?: boolean; // MCP-frozen field, kept verbatim (derived: outcome==="error")
448
537
  providerMetadata?: AgProviderMeta;
449
538
  annotations?: AgAnnotations;
@@ -466,7 +555,7 @@ const blockAnno = {
466
555
  };
467
556
 
468
557
  /**
469
- * The resource-link block (draft.5, pkg-05): MCP's ResourceLink members,
558
+ * The resource-link block (draft.5): MCP's ResourceLink members,
470
559
  * each optional beside the required `uri`. `size` is an integer, as ruled.
471
560
  * It is exported so a normalizer can check each native member against
472
561
  * core's own schema (`AgResourceLinkBlock.shape.<member>.safeParse(v)`), and
@@ -582,7 +671,7 @@ export const AgBlock: z.ZodType<AgBlock> = z.lazy(() =>
582
671
  // (HITL) arm: the turn parks on one or more asks; `result` MAY accompany a pause
583
672
  // (a partial value emitted before parking). `{type:"aborted"}` is turn.abort's
584
673
  // dedicated marker (symmetric with the error arm) — taskState is verbatim-A2A
585
- // only and is NEVER reducer-invented (audit M29).
674
+ // only and is NEVER reducer-invented.
586
675
  export const AgOutcome = z.discriminatedUnion("type", [
587
676
  z.object({ type: z.literal("success"), result: JsonValue.optional() }),
588
677
  // retriable (draft.5): the producer's judgement, recorded from turn.error; absent = unstated, not false.
@@ -705,17 +794,17 @@ export const AgTurnRecord = z.object({
705
794
  sourceIds: z.array(z.string()).optional(),
706
795
  sources: z.array(z.object({
707
796
  sourceId: z.string(),
708
- source: AgSourcePayload, // the §4 source arm's payload union, landed verbatim (audit M23)
797
+ source: AgSourcePayload, // the §4 source arm's payload union, landed verbatim
709
798
  chunkIndex: z.number().optional(),
710
799
  providerMetadata: AgProviderMeta.optional(),
711
- })).optional(), // grounding sources folded from source events (audit M23); sourceIds stays as the derived index
800
+ })).optional(), // grounding sources folded from source events; sourceIds stays as the derived index
712
801
  promptBlocked: z.object({
713
802
  reason: z.enum(["safety", "blocklist", "prohibited", "other"]), // mirrors the §4 prompt.blocked reason enum exactly
714
803
  reasonRaw: z.string().optional(), // folded from prompt.blocked.reasonRaw verbatim (draft.8)
715
804
  safety: z.array(AgSafety).optional(),
716
- }).optional(), // audit M28
805
+ }).optional(),
717
806
  asks: z.array(AgPausedAsk).optional(),
718
- taskState: z.string().optional(), // verbatim A2A TaskState (never reducer-invented — audit M29); no outcome-target mapping (A44)
807
+ taskState: z.string().optional(), // verbatim A2A TaskState (never reducer-invented); no outcome-target mapping
719
808
  displayRequired: z.array(AgDisplayRequired).optional(),
720
809
  trigger: AgTrigger.optional(), // what triggered this turn (A2-additive)
721
810
  guardrails: z.array(z.object({
@@ -860,7 +949,7 @@ export type AgRunConfig = z.infer<typeof AgRunConfig>;
860
949
 
861
950
  // The spec version this SDK implements (SPEC.md status line + §12). Consumers
862
951
  // reject a MAJOR mismatch and accept any same-major version (§12 negotiation).
863
- export const AGJSON_VERSION = "1.0.0-draft.8";
952
+ export const AGJSON_VERSION = "1.0.0-rc.1";
864
953
 
865
954
  const agjsonWireVersion = z
866
955
  .string()
@@ -921,18 +1010,29 @@ const surfaceEnvelope = {
921
1010
 
922
1011
  // A2UI v1.0 client→server `action` (A2UI-frozen names VERBATIM, §0.4). `context`
923
1012
  // = the A2UI resolved data-bindings — the SOLE sanctioned Record<string, unknown>
924
- // (map shape known: string keys; each value opaque per §0.1).
925
- export const AgA2uiSurfaceAction = z.object({
926
- ...surfaceEnvelope,
927
- surface: z.literal("a2ui"),
928
- a2uiMessage: z.literal("action"),
929
- name: z.string(),
930
- sourceComponentId: z.string(),
931
- timestamp: z.string(),
932
- context: z.record(z.string(), z.unknown()),
933
- wantResponse: z.boolean().optional(),
934
- actionId: z.string().optional(),
935
- });
1013
+ // (map shape known: string keys; each value opaque per §0.1). `actionId` is
1014
+ // REQUIRED when `wantResponse` is true (§3).
1015
+ export const AgA2uiSurfaceAction = z
1016
+ .object({
1017
+ ...surfaceEnvelope,
1018
+ surface: z.literal("a2ui"),
1019
+ a2uiMessage: z.literal("action"),
1020
+ name: z.string(),
1021
+ sourceComponentId: z.string(),
1022
+ timestamp: z.string(),
1023
+ context: z.record(z.string(), z.unknown()),
1024
+ wantResponse: z.boolean().optional(),
1025
+ actionId: z.string().optional(),
1026
+ })
1027
+ .superRefine((v, ctx) => {
1028
+ if (v.wantResponse === true && v.actionId === undefined) {
1029
+ ctx.addIssue({
1030
+ code: "custom",
1031
+ message: "wantResponse: true requires actionId (A2UI v1.0 action)",
1032
+ path: ["actionId"],
1033
+ });
1034
+ }
1035
+ });
936
1036
  export type AgA2uiSurfaceAction = z.infer<typeof AgA2uiSurfaceAction>;
937
1037
 
938
1038
  // A2UI v1.0 client→server `functionResponse` (inbound leg of the server
@@ -1057,7 +1157,7 @@ export type AgOpenAiWidgetAction = z.infer<typeof AgOpenAiWidgetAction>;
1057
1157
  // (a2uiMessage / method), so a validation issue names the member that is
1058
1158
  // actually wrong: a plain z.union let every non-matching branch report its
1059
1159
  // own `surface` literal, and the input check (input-check.ts) misclassified
1060
- // e.g. an mcp-app ui/open-link with a non-string url (CB-9). Same members,
1160
+ // e.g. an mcp-app ui/open-link with a non-string url. Same members,
1061
1161
  // same literals, same accepted values; only the failure path is exact.
1062
1162
  export const AgSurfaceInteraction = z.discriminatedUnion("surface", [
1063
1163
  z.discriminatedUnion("a2uiMessage", [AgA2uiSurfaceAction, AgA2uiFunctionResponse, AgA2uiError]),
@@ -1218,7 +1318,7 @@ export const AgClosedEvent = z.discriminatedUnion("type", [
1218
1318
  id: z.string(),
1219
1319
  phase: z.string().optional(), // draft.4: REPLACES the start value when present
1220
1320
  providerMetadata: AgProviderMeta.optional(),
1221
- // STREAMED-text citations carrier (audit M22): citations for a streamed text
1321
+ // STREAMED-text citations carrier: citations for a streamed text
1222
1322
  // block arrive here (not as a duplicate id-less supplement block) and attach
1223
1323
  // to the sealed block named by `id` (spec §5 text.end row).
1224
1324
  citations: z.array(AgCitation).optional(),
@@ -1464,7 +1564,7 @@ export const AgClosedEvent = z.discriminatedUnion("type", [
1464
1564
  artifacts: z.array(AgArtifact).optional(),
1465
1565
  memory: z.array(AgMemoryRecord).optional(),
1466
1566
  }),
1467
- // ── HOST DISPLAY/RUNTIME HINT ── live-only; `capabilities` here = HOST surface render hint (A30).
1567
+ // ── HOST DISPLAY/RUNTIME HINT ── live-only; `capabilities` here = HOST surface render hint.
1468
1568
  z.object({
1469
1569
  ...base,
1470
1570
  type: z.literal("host.context"),
@@ -1512,7 +1612,7 @@ export const AgClosedEvent = z.discriminatedUnion("type", [
1512
1612
  ...base,
1513
1613
  type: z.literal("ui.display-mode"),
1514
1614
  mode: AgDisplayMode,
1515
- granted: AgDisplayMode.optional(), // authoritative reply leg (A52)
1615
+ granted: AgDisplayMode.optional(), // authoritative reply leg
1516
1616
  surfaceId: z.string().optional(),
1517
1617
  toolCallId: z.string().optional(),
1518
1618
  }),
@@ -1,6 +1,6 @@
1
1
  /**
2
- * atomic-push.ts — per-native atomicity for a Normalizer (the fleet guard
3
- * ruling, 2026-09-24, binding; sp-main approved sp-openai's option B).
2
+ * atomic-push.ts — per-native atomicity for a Normalizer (the no-throw guard
3
+ * ruling, 2026-09-24, binding: option B).
4
4
  *
5
5
  * A Normalizer MUST NOT throw out of push() (SPEC.md §8.0). When handling
6
6
  * one native throws anyway, the events it had already produced must be
package/src/copy-json.ts CHANGED
@@ -1,27 +1,153 @@
1
1
  /**
2
- * copy-json.ts — INTERNAL (not re-exported from index.ts).
2
+ * copy-json.ts
3
3
  *
4
4
  * The one own-property deep copy every consumer-side reader in core uses, so
5
- * the §13 rule on `__proto__` has a single code path: stage-1 ingest
5
+ * the §13.7 rule on `__proto__` has a single code path: stage-1 ingest
6
6
  * (ingest.ts), the stored-record readers (record.ts) and the input check
7
- * (input-check.ts).
7
+ * (input-check.ts). `copyJson` is exported for hosts that seed a fold from
8
+ * their own store. The two walks below apply the same omission on the fold's
9
+ * and the emitter's own paths.
8
10
  */
9
11
  import type { JsonValue } from "./agjson.js";
10
12
 
11
- /** Own-property deep copy of a JSON value, dropping `__proto__` at every depth. */
13
+ /**
14
+ * Own-property deep copy of a JSON value, dropping an own `__proto__` member at
15
+ * every depth. Every object and array in the copy has the ordinary prototype.
16
+ * A host that seeds a fold from its own store copies the stored value with it.
17
+ * The copy is iterative, so no nesting depth overflows the stack; a node
18
+ * reached twice is copied once.
19
+ *
20
+ * @beta
21
+ */
12
22
  export function copyJson(v: JsonValue): JsonValue {
13
- if (Array.isArray(v)) return v.map(copyJson);
14
- if (v === null || typeof v !== "object") return v;
15
- const out: { [k: string]: JsonValue } = {};
16
- for (const k of Object.keys(v)) {
17
- if (k === "__proto__") continue;
18
- // DEFINED, never assigned (belt and braces with the skip above).
19
- Object.defineProperty(out, k, {
20
- value: copyJson((v as { [k: string]: JsonValue })[k]!),
21
- enumerable: true,
22
- writable: true,
23
- configurable: true,
24
- });
23
+ type Node = JsonValue[] | { [k: string]: JsonValue };
24
+ const copies = new Map<object, Node>();
25
+ const pending: object[] = [];
26
+ const copyOf = (x: JsonValue): JsonValue => {
27
+ if (x === null || typeof x !== "object") return x;
28
+ let c = copies.get(x);
29
+ if (c === undefined) {
30
+ c = Array.isArray(x) ? [] : {};
31
+ copies.set(x, c);
32
+ pending.push(x);
33
+ }
34
+ return c;
35
+ };
36
+ const root = copyOf(v);
37
+ while (pending.length > 0) {
38
+ const x = pending.pop()!;
39
+ const c = copies.get(x)!;
40
+ if (Array.isArray(x)) {
41
+ for (const item of x) (c as JsonValue[]).push(copyOf(item));
42
+ continue;
43
+ }
44
+ for (const k of Object.keys(x)) {
45
+ if (k === "__proto__") continue;
46
+ // DEFINED, never assigned (belt and braces with the skip above).
47
+ Object.defineProperty(c, k, {
48
+ value: copyOf((x as { [k: string]: JsonValue })[k]!),
49
+ enumerable: true,
50
+ writable: true,
51
+ configurable: true,
52
+ });
53
+ }
54
+ }
55
+ return root;
56
+ }
57
+
58
+ const PROTO = "__proto__";
59
+
60
+ /** True for an object this module treats as a JSON node: an array or a plain-or-null-prototype object. */
61
+ function isPlainNode(v: object): boolean {
62
+ if (Array.isArray(v)) return true;
63
+ const proto: unknown = Object.getPrototypeOf(v);
64
+ return proto === Object.prototype || proto === null;
65
+ }
66
+
67
+ /**
68
+ * INTERNAL. Removes an own `__proto__` member at every depth of a value the
69
+ * caller owns (a structuredClone copy). `delete` removes own members only, so
70
+ * a node without one is untouched. The walk is iterative and visits each
71
+ * object once, so neither nesting depth nor a cycle bounds it.
72
+ */
73
+ export function deleteOwnProtoMember(v: unknown): void {
74
+ const seen = new WeakSet<object>();
75
+ const stack: unknown[] = [v];
76
+ while (stack.length > 0) {
77
+ const x = stack.pop();
78
+ if (x === null || typeof x !== "object" || seen.has(x)) continue;
79
+ seen.add(x);
80
+ if (Array.isArray(x)) {
81
+ for (let i = 0; i < x.length; i++) stack.push(x[i]);
82
+ continue;
83
+ }
84
+ const o = x as Record<string, unknown>;
85
+ if (Object.hasOwn(o, PROTO)) delete o[PROTO];
86
+ for (const k in o) if (Object.hasOwn(o, k)) stack.push(o[k]);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * INTERNAL. A copy of `v` without an own `__proto__` member at any depth that
92
+ * never mutates `v`: when any node holds the member, its arrays and plain (or
93
+ * null-prototype) objects are rebuilt with the ordinary prototype, members DEFINED, never
94
+ * assigned; any other value (a function, a class instance) is carried by
95
+ * reference. Returns `v` itself when no node holds the member, so the common
96
+ * case allocates nothing. Both walks are iterative and visit each object once:
97
+ * a node reached twice is copied once, and a cycle is copied as a cycle.
98
+ */
99
+ export function withoutOwnProtoMember<T>(v: T): T {
100
+ return (hasOwnProtoMember(v) ? rebuild(v) : v) as T;
101
+ }
102
+
103
+ function hasOwnProtoMember(v: unknown): boolean {
104
+ const seen = new WeakSet<object>();
105
+ const stack: unknown[] = [v];
106
+ while (stack.length > 0) {
107
+ const x = stack.pop();
108
+ if (x === null || typeof x !== "object" || seen.has(x) || !isPlainNode(x)) continue;
109
+ seen.add(x);
110
+ if (Array.isArray(x)) {
111
+ for (let i = 0; i < x.length; i++) stack.push(x[i]);
112
+ continue;
113
+ }
114
+ const o = x as Record<string, unknown>;
115
+ if (Object.hasOwn(o, PROTO)) return true;
116
+ for (const k in o) if (Object.hasOwn(o, k)) stack.push(o[k]);
117
+ }
118
+ return false;
119
+ }
120
+
121
+ function rebuild(v: unknown): unknown {
122
+ const copies = new Map<object, unknown[] | Record<string, unknown>>();
123
+ const pending: object[] = [];
124
+ const copyOf = (x: unknown): unknown => {
125
+ if (x === null || typeof x !== "object" || !isPlainNode(x)) return x;
126
+ let c = copies.get(x);
127
+ if (c === undefined) {
128
+ c = Array.isArray(x) ? new Array<unknown>(x.length) : {};
129
+ copies.set(x, c);
130
+ pending.push(x);
131
+ }
132
+ return c;
133
+ };
134
+ const root = copyOf(v);
135
+ while (pending.length > 0) {
136
+ const x = pending.pop()!;
137
+ const c = copies.get(x)!;
138
+ if (Array.isArray(x)) {
139
+ for (let i = 0; i < x.length; i++) if (i in x) (c as unknown[])[i] = copyOf(x[i]);
140
+ continue;
141
+ }
142
+ for (const k of Object.keys(x)) {
143
+ if (k === PROTO) continue;
144
+ Object.defineProperty(c, k, {
145
+ value: copyOf((x as Record<string, unknown>)[k]),
146
+ enumerable: true,
147
+ writable: true,
148
+ configurable: true,
149
+ });
150
+ }
25
151
  }
26
- return out;
152
+ return root;
27
153
  }