@silverprotocol/core 0.6.7 → 0.7.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 (52) hide show
  1. package/README.md +55 -7
  2. package/dist/agjson.d.ts +29 -8
  3. package/dist/agjson.d.ts.map +1 -1
  4. package/dist/agjson.js +28 -7
  5. package/dist/agjson.js.map +1 -1
  6. package/dist/atomic-push.d.ts +51 -0
  7. package/dist/atomic-push.d.ts.map +1 -0
  8. package/dist/atomic-push.js +188 -0
  9. package/dist/atomic-push.js.map +1 -0
  10. package/dist/copy-json.d.ts +12 -0
  11. package/dist/copy-json.d.ts.map +1 -0
  12. package/dist/copy-json.js +21 -0
  13. package/dist/copy-json.js.map +1 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/ingest.d.ts +41 -5
  19. package/dist/ingest.d.ts.map +1 -1
  20. package/dist/ingest.js +53 -30
  21. package/dist/ingest.js.map +1 -1
  22. package/dist/input-check.d.ts +51 -0
  23. package/dist/input-check.d.ts.map +1 -0
  24. package/dist/input-check.js +113 -0
  25. package/dist/input-check.js.map +1 -0
  26. package/dist/record.d.ts +68 -0
  27. package/dist/record.d.ts.map +1 -0
  28. package/dist/record.js +112 -0
  29. package/dist/record.js.map +1 -0
  30. package/dist/reduce.d.ts +0 -14
  31. package/dist/reduce.d.ts.map +1 -1
  32. package/dist/reduce.js +270 -68
  33. package/dist/reduce.js.map +1 -1
  34. package/dist/stream-assembler.d.ts +54 -5
  35. package/dist/stream-assembler.d.ts.map +1 -1
  36. package/dist/stream-assembler.js +62 -5
  37. package/dist/stream-assembler.js.map +1 -1
  38. package/dist/wire.d.ts +96 -0
  39. package/dist/wire.d.ts.map +1 -1
  40. package/dist/wire.js +309 -0
  41. package/dist/wire.js.map +1 -1
  42. package/package.json +1 -1
  43. package/src/agjson.ts +33 -10
  44. package/src/atomic-push.ts +217 -0
  45. package/src/copy-json.ts +27 -0
  46. package/src/index.ts +3 -0
  47. package/src/ingest.ts +71 -26
  48. package/src/input-check.ts +124 -0
  49. package/src/record.ts +132 -0
  50. package/src/reduce.ts +234 -56
  51. package/src/stream-assembler.ts +82 -10
  52. package/src/wire.ts +303 -0
package/dist/ingest.js CHANGED
@@ -10,48 +10,71 @@
10
10
  * depth (SPEC.md:27 does not limit "untouched" to the top level). After a
11
11
  * successful `AgEvent.safeParse`, the returned event is an own-property deep
12
12
  * copy of the RAW input, not zod's validated output, which strips unknown
13
- * nested keys. The copy equals the validated value only because no schema in
14
- * agjson.ts rewrites values (no transform/default/coerce/catch/pipe/
15
- * preprocess); ingest.test.ts guards that.
13
+ * nested keys. The copy carries the same keys and values as the validated
14
+ * value only because no schema in agjson.ts rewrites values (no transform/
15
+ * default/coerce/catch/pipe/preprocess); ingest.test.ts guards that. It is
16
+ * NOT byte-identical to it: nested objects keep the PRODUCER's key order,
17
+ * where zod's output (and so 0.6.4's ingest) used the schema's. Over the
18
+ * 0.6.5 corpus that reordered 64 of 1,103 events, all inside `usage`.
16
19
  *
17
20
  * One exception, at every depth: a key named `__proto__` is dropped, never
18
21
  * copied. A consumer must not let wire data select the prototype of any object
19
22
  * it materialises (JSON.parse keeps such a key as an own property, and
20
23
  * assigning it would run Object.prototype's setter).
24
+ *
25
+ * Forward-compatible ingest (draft.4 §0.2, workspace#20 stage 2). Every input
26
+ * lands in exactly one of three places:
27
+ * - a WELL-FORMED ENVELOPE (a JSON object whose `type` is a string and whose
28
+ * `seq` is a finite number) that validates → the event, as above;
29
+ * - a well-formed envelope that does NOT validate (an undefined type, an
30
+ * unknown enum value or block, a malformed known type) → IN PLACE, the
31
+ * stub `{type: "ext.agjson.ignored", seq, ignoredType, raw}`. It is a
32
+ * typed ext event: it never folds, but a Reducer counts its `seq` slot,
33
+ * so an ignored event can no longer open a false gap. `raw` is the
34
+ * original frame (same copy rules) and is LIVE-ONLY: never persist it;
35
+ * - anything else (not an object, a non-string `type`, a missing or
36
+ * non-number `seq`) → not an event and occupies no slot: returns
37
+ * undefined and is reported through the optional `onReject` callback.
38
+ * ingestAgEvent/ingestAgEvents never throw, even if `onReject` does.
21
39
  */
22
40
  import { AgEvent } from "./agjson.js";
23
- /** Own-property deep copy of a JSON value, dropping `__proto__` at every depth. */
24
- function copyJson(v) {
25
- if (Array.isArray(v))
26
- return v.map(copyJson);
27
- if (v === null || typeof v !== "object")
28
- return v;
29
- const out = {};
30
- for (const k of Object.keys(v)) {
31
- if (k === "__proto__")
32
- continue;
33
- // DEFINED, never assigned (belt and braces with the skip above).
34
- Object.defineProperty(out, k, {
35
- value: copyJson(v[k]),
36
- enumerable: true,
37
- writable: true,
38
- configurable: true,
39
- });
40
- }
41
- return out;
42
- }
43
- export function ingestAgEvent(v) {
41
+ import { copyJson } from "./copy-json.js";
42
+ function envelopeProblem(v) {
44
43
  if (v === null || typeof v !== "object" || Array.isArray(v))
44
+ return "not-object";
45
+ if (typeof v["type"] !== "string")
46
+ return "type-not-string";
47
+ const seq = v["seq"];
48
+ if (typeof seq !== "number" || !Number.isFinite(seq))
49
+ return "seq-not-number";
50
+ return undefined;
51
+ }
52
+ export function ingestAgEvent(v, opts) {
53
+ const problem = envelopeProblem(v);
54
+ if (problem !== undefined) {
55
+ try {
56
+ opts?.onReject?.({ input: v, reason: problem });
57
+ }
58
+ catch {
59
+ // never-throw contract: a host callback bug must not break ingest
60
+ }
45
61
  return undefined;
46
- const r = AgEvent.safeParse(v);
47
- if (!r.success)
48
- return undefined;
49
- return copyJson(v);
62
+ }
63
+ const env = v;
64
+ if (AgEvent.safeParse(v).success)
65
+ return copyJson(v);
66
+ const stub = {
67
+ type: "ext.agjson.ignored",
68
+ seq: env["seq"],
69
+ ignoredType: env["type"],
70
+ raw: copyJson(v),
71
+ };
72
+ return stub;
50
73
  }
51
- export function ingestAgEvents(vs) {
74
+ export function ingestAgEvents(vs, opts) {
52
75
  const out = [];
53
76
  for (const v of vs) {
54
- const e = ingestAgEvent(v);
77
+ const e = ingestAgEvent(v, opts);
55
78
  if (e !== undefined)
56
79
  out.push(e);
57
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ingest.js","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,OAAO,EAAkB,MAAM,aAAa,CAAC;AAEtD,mFAAmF;AACnF,SAAS,QAAQ,CAAC,CAAY;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IAClD,MAAM,GAAG,GAA+B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,IAAI,CAAC,KAAK,WAAW;YAAE,SAAS;QAChC,iEAAiE;QACjE,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE;YAC5B,KAAK,EAAE,QAAQ,CAAE,CAAgC,CAAC,CAAC,CAAE,CAAC;YACtD,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAAY;IACxC,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9E,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,CAAC,CAAC,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IACjC,OAAO,QAAQ,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CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAClD,CAAC;QAAC,MAAM,CAAC;YACP,kEAAkE;QACpE,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,GAAG,GAAG,CAA+B,CAAC;IAC5C,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO;QAAE,OAAO,QAAQ,CAAC,CAAC,CAAuB,CAAC;IAC3E,MAAM,IAAI,GAAmB;QAC3B,IAAI,EAAE,oBAAoB;QAC1B,GAAG,EAAE,GAAG,CAAC,KAAK,CAAW;QACzB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAW;QAClC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;KACjB,CAAC;IACF,OAAO,IAA0B,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAe,EAAE,IAAoB;IAClE,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACnB,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * input-check.ts — the reference AgInput receiver check (draft.4 §0.2,
3
+ * workspace#20 decision 6: option 1 "omit the element, reject the input";
4
+ * input classes per the founder's ALT-1 ruling, bar wf_a8a31902-fb5).
5
+ *
6
+ * A receiver passes unknown object fields through untouched, and REJECTS THE
7
+ * WHOLE INPUT, before acting on any part of it, when the input fails this
8
+ * specification's schema in any way other than an unknown field. The
9
+ * rejection names ONE path and ONE class:
10
+ *
11
+ * - `major-mismatch`, at `["version"]`: `version` differs in MAJOR (§12);
12
+ * - `unknown-value`: the value at the path is a STRING that the closed set
13
+ * there does not define (an `AgInput.kind`, an `AgHitlAnswer.status`, a
14
+ * reasoning `effort`, an `AgBlock` `type`, …). zod's codes alone cannot
15
+ * tell this from malformed, so the rule reads the raw value (bar CB-6);
16
+ * - `malformed`: every other failure — a missing value, a value of the wrong
17
+ * JSON type, a value that breaks a stated constraint, a non-JSON input, or
18
+ * a `protocol` other than `"agjson"` (it names the protocol; it is not a
19
+ * closed set). An input that is not a JSON object is malformed at `[]`.
20
+ *
21
+ * Order and scope: `protocol` is judged first, then `version`, then the rest.
22
+ * The `AgInputEnvelope` members are checked whatever the `kind`; a member that
23
+ * only an undefined `kind` would select is not checked, nor any other member of
24
+ * an `AgBlock` whose `type` is undefined. When the rest has both malformed and
25
+ * unknown-value problems, the class is malformed, at the path of the first
26
+ * malformed problem in the reference's order; otherwise the first
27
+ * unknown-value. Inside a plain union, only a branch whose shape fits the
28
+ * value's JSON type is read (a string against an enum branch, an object
29
+ * against an object branch).
30
+ *
31
+ * An accepted input comes back as an own-property deep copy of the RAW value,
32
+ * so unknown fields stay intact at every depth (`__proto__` dropped, as
33
+ * ingest). A sender that receives `unknown-value` at a path inside an
34
+ * `AgBlock[]` MAY resend without that element.
35
+ */
36
+ import { AgInput } from "./agjson.js";
37
+ export type AgInputCheckCode = "unknown-value" | "malformed" | "major-mismatch";
38
+ export type AgInputCheck = {
39
+ ok: true;
40
+ input: AgInput;
41
+ } | {
42
+ ok: false;
43
+ code: AgInputCheckCode;
44
+ path: (string | number)[];
45
+ };
46
+ /**
47
+ * Check a received AgInput (draft.4 §0.2). Returns the input, unknown fields
48
+ * intact, or a typed rejection naming one path and one class.
49
+ */
50
+ export declare function checkAgInput(raw: unknown): AgInputCheck;
51
+ //# sourceMappingURL=input-check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-check.d.ts","sourceRoot":"","sources":["../src/input-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EAAkB,OAAO,EAAmC,MAAM,aAAa,CAAC;AAIvF,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,WAAW,GAAG,gBAAgB,CAAC;AAEhF,MAAM,MAAM,YAAY,GACpB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC5B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CAAE,CAAC;AAqDrE;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAuBvD"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * input-check.ts — the reference AgInput receiver check (draft.4 §0.2,
3
+ * workspace#20 decision 6: option 1 "omit the element, reject the input";
4
+ * input classes per the founder's ALT-1 ruling, bar wf_a8a31902-fb5).
5
+ *
6
+ * A receiver passes unknown object fields through untouched, and REJECTS THE
7
+ * WHOLE INPUT, before acting on any part of it, when the input fails this
8
+ * specification's schema in any way other than an unknown field. The
9
+ * rejection names ONE path and ONE class:
10
+ *
11
+ * - `major-mismatch`, at `["version"]`: `version` differs in MAJOR (§12);
12
+ * - `unknown-value`: the value at the path is a STRING that the closed set
13
+ * there does not define (an `AgInput.kind`, an `AgHitlAnswer.status`, a
14
+ * reasoning `effort`, an `AgBlock` `type`, …). zod's codes alone cannot
15
+ * tell this from malformed, so the rule reads the raw value (bar CB-6);
16
+ * - `malformed`: every other failure — a missing value, a value of the wrong
17
+ * JSON type, a value that breaks a stated constraint, a non-JSON input, or
18
+ * a `protocol` other than `"agjson"` (it names the protocol; it is not a
19
+ * closed set). An input that is not a JSON object is malformed at `[]`.
20
+ *
21
+ * Order and scope: `protocol` is judged first, then `version`, then the rest.
22
+ * The `AgInputEnvelope` members are checked whatever the `kind`; a member that
23
+ * only an undefined `kind` would select is not checked, nor any other member of
24
+ * an `AgBlock` whose `type` is undefined. When the rest has both malformed and
25
+ * unknown-value problems, the class is malformed, at the path of the first
26
+ * malformed problem in the reference's order; otherwise the first
27
+ * unknown-value. Inside a plain union, only a branch whose shape fits the
28
+ * value's JSON type is read (a string against an enum branch, an object
29
+ * against an object branch).
30
+ *
31
+ * An accepted input comes back as an own-property deep copy of the RAW value,
32
+ * so unknown fields stay intact at every depth (`__proto__` dropped, as
33
+ * ingest). A sender that receives `unknown-value` at a path inside an
34
+ * `AgBlock[]` MAY resend without that element.
35
+ */
36
+ import { AGJSON_VERSION, AgInput, AgInputEnvelope } from "./agjson.js";
37
+ import { copyJson } from "./copy-json.js";
38
+ import { isJsonValue } from "./wire.js";
39
+ /** The raw value at `path`, read through own properties only. */
40
+ function at(root, path) {
41
+ let v = root;
42
+ for (const k of path) {
43
+ if (v === null || typeof v !== "object" || !Object.hasOwn(v, k))
44
+ return undefined;
45
+ v = v[k];
46
+ }
47
+ return v;
48
+ }
49
+ const toPath = (p) => p.filter((k) => typeof k !== "symbol");
50
+ const samePath = (a, b) => a.length === b.length && a.every((k, i) => k === b[i]);
51
+ /**
52
+ * Every problem one issue stands for. `unknown-value` iff the raw value at its
53
+ * path is a string outside the closed set there (an enum's `values`, a
54
+ * discriminator's `options`); a plain union is read through the branch that
55
+ * fits the value's JSON type; anything else is `malformed`.
56
+ */
57
+ function problemsOf(root, issue, prefix) {
58
+ const path = [...prefix, ...toPath(issue.path)];
59
+ const raw = at(root, path);
60
+ const set = issue.code === "invalid_value" ? issue.values : issue.code === "invalid_union" ? issue.options : undefined;
61
+ if (set !== undefined && typeof raw === "string" && !set.includes(raw))
62
+ return [{ code: "unknown-value", path }];
63
+ if (issue.code === "invalid_union" && issue.errors !== undefined && issue.errors.length > 0) {
64
+ // A branch that is malformed AT the union's own path does not fit the
65
+ // value's JSON type (a string branch against an array, an enum against an
66
+ // object); the first branch that fits is the one the value was meant for.
67
+ const fitting = issue.errors
68
+ .map((branch) => branch.flatMap((i) => problemsOf(root, i, path)))
69
+ .filter((ps) => ps.length > 0 && !ps.some((p) => p.code === "malformed" && samePath(p.path, path)));
70
+ return fitting[0] ?? [{ code: "malformed", path }];
71
+ }
72
+ return [{ code: "malformed", path }];
73
+ }
74
+ const MAJOR = AGJSON_VERSION.split(".")[0];
75
+ const reject = (code, path) => ({ ok: false, code, path });
76
+ /**
77
+ * Check a received AgInput (draft.4 §0.2). Returns the input, unknown fields
78
+ * intact, or a typed rejection naming one path and one class.
79
+ */
80
+ export function checkAgInput(raw) {
81
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
82
+ return reject("malformed", []);
83
+ // protocol first: it names the protocol, so anything but "agjson" is not AgJSON at all.
84
+ if (!Object.hasOwn(raw, "protocol") || raw.protocol !== "agjson")
85
+ return reject("malformed", ["protocol"]);
86
+ // then version: another major is major-mismatch; any other version problem is malformed.
87
+ const version = Object.hasOwn(raw, "version") ? raw.version : undefined;
88
+ if (typeof version !== "string" || !/^\d+\./.test(version))
89
+ return reject("malformed", ["version"]);
90
+ if (version.split(".")[0] !== MAJOR)
91
+ return reject("major-mismatch", ["version"]);
92
+ // then the rest.
93
+ if (!isJsonValue(raw))
94
+ return reject("malformed", []);
95
+ const parsed = AgInput.safeParse(raw);
96
+ if (parsed.success)
97
+ return { ok: true, input: copyJson(raw) };
98
+ const issues = parsed.error.issues;
99
+ const problems = [];
100
+ // An undefined kind stops zod at the discriminator: judge the envelope
101
+ // members anyway, and never the members only that kind would select.
102
+ if (issues.some((i) => i.code === "invalid_union" && i.options !== undefined && samePath(toPath(i.path), ["kind"]))) {
103
+ const envelope = AgInputEnvelope.safeParse(raw);
104
+ if (!envelope.success)
105
+ for (const i of envelope.error.issues)
106
+ problems.push(...problemsOf(raw, i, []));
107
+ }
108
+ for (const i of issues)
109
+ problems.push(...problemsOf(raw, i, []));
110
+ const pick = problems.find((p) => p.code === "malformed") ?? problems.find((p) => p.code === "unknown-value");
111
+ return pick === undefined ? reject("malformed", []) : reject(pick.code, pick.path);
112
+ }
113
+ //# sourceMappingURL=input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AI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AACrF,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * record.ts — lenient readers for STORED records (draft.4 §0.2, workspace#20
3
+ * decision 6, founder ruling 2026-09-23: option 1, "omit the element, reject
4
+ * the input").
5
+ *
6
+ * §0.2's consumer posture also binds a reader of a stored `AgMessage` or
7
+ * `AgMemoryRecord` it did not receive inside an event. These readers
8
+ * implement it:
9
+ *
10
+ * - A stored `AgMessage` is materialized only when its `id` is a string, its
11
+ * `role` an `AgRole`, its `content` an array and its other defined fields
12
+ * valid. Otherwise there is no value, and ONE report carries the whole record
13
+ * verbatim.
14
+ * - An element of `content[]` that fails `AgBlock` at any depth (an undefined
15
+ * `type`, or an undefined value in a closed set inside a known block) is
16
+ * omitted WHOLE and reported with its index and verbatim value. A
17
+ * tool-result is omitted, never altered. The remaining elements keep their
18
+ * order.
19
+ * - In an array of stored records, a record that fails is omitted and
20
+ * reported with its index. Nothing is ever coerced.
21
+ * - Unknown object fields pass through untouched at every depth: every value
22
+ * returned is an own-property deep copy of the RAW input, never zod's output
23
+ * (which strips unknown keys). A key named `__proto__` is dropped at every
24
+ * depth (the shared copy stage-1 ingest uses). The input is never mutated.
25
+ * - Inserting each report's `raw` at its reported index reproduces the stored
26
+ * record or array.
27
+ *
28
+ * What a reader returns is a VIEW. It MUST NOT be persisted in place of the
29
+ * stored record: a component that persists or forwards a record keeps it as
30
+ * received.
31
+ *
32
+ * Records carried by EVENTS are out of scope: they keep the whole-event rule
33
+ * (ingest.ts). Disclosed, not fixed: a `messages.snapshot` holding one unknown
34
+ * block fails `AgEvent`, becomes an `ext.agjson.ignored` stub and so cannot
35
+ * un-park a live fold, while the same message read here from storage keeps its
36
+ * readable blocks. That stays so until decision 5's snapshot leg is ruled.
37
+ */
38
+ import { AgMemoryRecord, AgMessage, type JsonValue } from "./agjson.js";
39
+ /** One omitted element or record: where it was, its type when it had one, and its verbatim value. */
40
+ export interface AgRecordReport {
41
+ /** From the value passed to the reader: `[]` for the whole record, `["content", i]` for an element, `[i]` or `[i, "content", j]` inside an array. */
42
+ path: (string | number)[];
43
+ /** The omitted element's `type`, when it is a string (a content element's block type). */
44
+ ignoredType?: string;
45
+ /** The omitted value, verbatim (an own-property copy; `__proto__` dropped). */
46
+ raw: JsonValue;
47
+ }
48
+ /** The result of reading one stored record: a value when it was materialized, and every omission. */
49
+ export interface AgRecordRead<T> {
50
+ value?: T;
51
+ reports: AgRecordReport[];
52
+ }
53
+ /** The result of reading an array of stored records. */
54
+ export interface AgRecordsRead<T> {
55
+ value: T[];
56
+ reports: AgRecordReport[];
57
+ }
58
+ /**
59
+ * Read one stored `AgMessage` (draft.4 §0.2). Omits and reports each
60
+ * unreadable `content[]` element; a record that cannot be materialized has no
61
+ * `value` and one report at path `[]`.
62
+ */
63
+ export declare function readStoredAgMessage(raw: unknown): AgRecordRead<AgMessage>;
64
+ /** Read an array of stored `AgMessage`s: each unreadable message or element is omitted and reported, prefixed with its index. */
65
+ export declare function readStoredAgMessages(raws: readonly unknown[]): AgRecordsRead<AgMessage>;
66
+ /** Read an array of stored `AgMemoryRecord`s: a record that fails (an undefined `scope`, a missing `value`, …) is omitted and reported at `[i]`. */
67
+ export declare function readStoredAgMemoryRecords(raws: readonly unknown[]): AgRecordsRead<AgMemoryRecord>;
68
+ //# sourceMappingURL=record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAW,cAAc,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAIjF,qGAAqG;AACrG,MAAM,WAAW,cAAc;IAC7B,qJAAqJ;IACrJ,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC1B,0FAA0F;IAC1F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,GAAG,EAAE,SAAS,CAAC;CAChB;AAED,qGAAqG;AACrG,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED,wDAAwD;AACxD,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAcD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,CA0BzE;AAED,iIAAiI;AACjI,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,aAAa,CAAC,SAAS,CAAC,CAUvF;AAED,oJAAoJ;AACpJ,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,aAAa,CAAC,cAAc,CAAC,CASjG"}
package/dist/record.js ADDED
@@ -0,0 +1,112 @@
1
+ /**
2
+ * record.ts — lenient readers for STORED records (draft.4 §0.2, workspace#20
3
+ * decision 6, founder ruling 2026-09-23: option 1, "omit the element, reject
4
+ * the input").
5
+ *
6
+ * §0.2's consumer posture also binds a reader of a stored `AgMessage` or
7
+ * `AgMemoryRecord` it did not receive inside an event. These readers
8
+ * implement it:
9
+ *
10
+ * - A stored `AgMessage` is materialized only when its `id` is a string, its
11
+ * `role` an `AgRole`, its `content` an array and its other defined fields
12
+ * valid. Otherwise there is no value, and ONE report carries the whole record
13
+ * verbatim.
14
+ * - An element of `content[]` that fails `AgBlock` at any depth (an undefined
15
+ * `type`, or an undefined value in a closed set inside a known block) is
16
+ * omitted WHOLE and reported with its index and verbatim value. A
17
+ * tool-result is omitted, never altered. The remaining elements keep their
18
+ * order.
19
+ * - In an array of stored records, a record that fails is omitted and
20
+ * reported with its index. Nothing is ever coerced.
21
+ * - Unknown object fields pass through untouched at every depth: every value
22
+ * returned is an own-property deep copy of the RAW input, never zod's output
23
+ * (which strips unknown keys). A key named `__proto__` is dropped at every
24
+ * depth (the shared copy stage-1 ingest uses). The input is never mutated.
25
+ * - Inserting each report's `raw` at its reported index reproduces the stored
26
+ * record or array.
27
+ *
28
+ * What a reader returns is a VIEW. It MUST NOT be persisted in place of the
29
+ * stored record: a component that persists or forwards a record keeps it as
30
+ * received.
31
+ *
32
+ * Records carried by EVENTS are out of scope: they keep the whole-event rule
33
+ * (ingest.ts). Disclosed, not fixed: a `messages.snapshot` holding one unknown
34
+ * block fails `AgEvent`, becomes an `ext.agjson.ignored` stub and so cannot
35
+ * un-park a live fold, while the same message read here from storage keeps its
36
+ * readable blocks. That stays so until decision 5's snapshot leg is ruled.
37
+ */
38
+ import { AgBlock, AgMemoryRecord, AgMessage } from "./agjson.js";
39
+ import { copyJson } from "./copy-json.js";
40
+ import { isJsonValue, toJsonValueSafe } from "./wire.js";
41
+ const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
42
+ /** A value as a report can carry it: a JSON value is copied verbatim; a
43
+ * non-JSON one (never read from JSON storage) is made JSON-safe. */
44
+ const reportRaw = (v) => (isJsonValue(v) ? copyJson(v) : toJsonValueSafe(v));
45
+ function report(path, raw, ignoredType) {
46
+ return { path, ...(ignoredType !== undefined ? { ignoredType } : {}), raw: reportRaw(raw) };
47
+ }
48
+ /**
49
+ * Read one stored `AgMessage` (draft.4 §0.2). Omits and reports each
50
+ * unreadable `content[]` element; a record that cannot be materialized has no
51
+ * `value` and one report at path `[]`.
52
+ */
53
+ export function readStoredAgMessage(raw) {
54
+ if (!isJsonValue(raw) || !isObject(raw) || !Array.isArray(raw["content"]))
55
+ return { reports: [report([], raw)] };
56
+ const kept = [];
57
+ const reports = [];
58
+ raw["content"].forEach((element, i) => {
59
+ if (AgBlock.safeParse(element).success) {
60
+ kept.push(copyJson(element));
61
+ return;
62
+ }
63
+ const type = isObject(element) && typeof element["type"] === "string" ? element["type"] : undefined;
64
+ reports.push(report(["content", i], element, type));
65
+ });
66
+ // The copy keeps the stored key order, with the readable elements in place of content.
67
+ const view = {};
68
+ for (const k of Object.keys(raw)) {
69
+ if (k === "__proto__")
70
+ continue;
71
+ Object.defineProperty(view, k, {
72
+ value: k === "content" ? kept : copyJson(raw[k]),
73
+ enumerable: true,
74
+ writable: true,
75
+ configurable: true,
76
+ });
77
+ }
78
+ // Every other defined field must be valid; else the whole record is reported.
79
+ if (!AgMessage.safeParse(view).success)
80
+ return { reports: [report([], raw)] };
81
+ return { value: view, reports };
82
+ }
83
+ /** Read an array of stored `AgMessage`s: each unreadable message or element is omitted and reported, prefixed with its index. */
84
+ export function readStoredAgMessages(raws) {
85
+ if (!Array.isArray(raws))
86
+ return { value: [], reports: [report([], raws)] };
87
+ const value = [];
88
+ const reports = [];
89
+ raws.forEach((raw, i) => {
90
+ const r = readStoredAgMessage(raw);
91
+ if (r.value !== undefined)
92
+ value.push(r.value);
93
+ for (const rep of r.reports)
94
+ reports.push({ ...rep, path: [i, ...rep.path] });
95
+ });
96
+ return { value, reports };
97
+ }
98
+ /** Read an array of stored `AgMemoryRecord`s: a record that fails (an undefined `scope`, a missing `value`, …) is omitted and reported at `[i]`. */
99
+ export function readStoredAgMemoryRecords(raws) {
100
+ if (!Array.isArray(raws))
101
+ return { value: [], reports: [report([], raws)] };
102
+ const value = [];
103
+ const reports = [];
104
+ raws.forEach((raw, i) => {
105
+ if (isJsonValue(raw) && isObject(raw) && AgMemoryRecord.safeParse(raw).success)
106
+ value.push(copyJson(raw));
107
+ else
108
+ reports.push(report([i], raw));
109
+ });
110
+ return { value, reports };
111
+ }
112
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names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CAAC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO;YAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAA8B,CAAC,CAAC;;YAClI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC"}
package/dist/reduce.d.ts CHANGED
@@ -21,20 +21,6 @@ export declare class Reducer {
21
21
  * @param candidateIndex The event's `candidateIndex` (absent → 0).
22
22
  */
23
23
  openMessage(turnId: string | undefined, candidateIndex?: number): AgMessage | undefined;
24
- /**
25
- * Defensive turn lookup: get an existing `AgTurnRecord` by turnId, or create a
26
- * minimal stub if the record-on-turn event arrives before its `turn.start`.
27
- *
28
- * Record-on-turn events (turn.done, turn.error, turn.abort, source, handoff,
29
- * prompt.blocked, guardrail.result, display.required) all carry `turnId` (optional
30
- * in the base schema). When turnId is undefined, fall back to the sole open turn
31
- * (single-turn-stream default). If still ambiguous, create a fallback record keyed
32
- * on "unknown-turn" — the stub will be visible in turns[] but can be reconciled on
33
- * a subsequent messages.snapshot resync.
34
- *
35
- * AgTurnRecord requires `threadId`; when creating a defensive stub we use the
36
- * turnId itself as a placeholder (no threadId is available without turn.start).
37
- */
38
24
  ensureTurn(turnId: string | undefined): AgTurnRecord;
39
25
  /**
40
26
  * Materialize the current fold state as a DEFENSIVE DEEP COPY.
@@ -1 +1 @@
1
- {"version":3,"file":"reduce.d.ts","sourceRoot":"","sources":["../src/reduce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAEP,cAAc,EACd,SAAS,EAIT,YAAY,EAKb,MAAM,aAAa,CAAC;AAiErB,qBAAa,OAAO;;IA0ClB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI;IAq9BvB;;;;;;;;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