iterate 0.2.7 → 0.3.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.
Files changed (218) hide show
  1. package/README.md +86 -76
  2. package/THIRD_PARTY_NOTICES.md +55 -0
  3. package/bin/iterate.js +11 -3
  4. package/dist/api-url-B6404M82.mjs +17 -0
  5. package/dist/api-url-B6404M82.mjs.map +1 -0
  6. package/dist/app-ref-BipL0feU.mjs +35 -0
  7. package/dist/app-ref-BipL0feU.mjs.map +1 -0
  8. package/dist/app-ref-C1CrgXqX.mjs +7 -0
  9. package/dist/app-ref-C1CrgXqX.mjs.map +1 -0
  10. package/dist/app-ref-DYai_om1.mjs +7 -0
  11. package/dist/app-ref-DYai_om1.mjs.map +1 -0
  12. package/dist/cli-D0c-pDL_.mjs +1010 -0
  13. package/dist/cli-D0c-pDL_.mjs.map +1 -0
  14. package/dist/client.d.ts +3 -0
  15. package/dist/client.mjs +4 -0
  16. package/dist/cloudflare-BTm90gQ4.mjs +951 -0
  17. package/dist/cloudflare-BTm90gQ4.mjs.map +1 -0
  18. package/dist/contract-s4FW4eES.mjs +309 -0
  19. package/dist/contract-s4FW4eES.mjs.map +1 -0
  20. package/dist/document-review/index.d.ts +5 -0
  21. package/dist/document-review/types.d.ts +107 -0
  22. package/dist/document-review.mjs +7015 -0
  23. package/dist/document-review.mjs.map +1 -0
  24. package/dist/durable-object-processor-durability-CNsTjAJS.mjs +205 -0
  25. package/dist/durable-object-processor-durability-CNsTjAJS.mjs.map +1 -0
  26. package/dist/idempotency-DleloJNt.mjs +28 -0
  27. package/dist/idempotency-DleloJNt.mjs.map +1 -0
  28. package/dist/index.mjs +1 -1
  29. package/dist/itx/api-url.d.ts +6 -0
  30. package/dist/itx/itx-node-client.d.ts +65 -0
  31. package/dist/itx/itx-session.d.ts +215 -0
  32. package/dist/itx/owned-rpc-session.d.ts +14 -0
  33. package/dist/itx/query-client.d.ts +10 -0
  34. package/dist/itx-api.generated.d.ts +6195 -0
  35. package/dist/itx-session-sjud8GiT.mjs +534 -0
  36. package/dist/itx-session-sjud8GiT.mjs.map +1 -0
  37. package/dist/live-state-BJNqOwFw.mjs +299 -0
  38. package/dist/live-state-BJNqOwFw.mjs.map +1 -0
  39. package/dist/next/api.d.ts +479 -0
  40. package/dist/next/api.mjs +0 -0
  41. package/dist/next/app-server.d.ts +44 -0
  42. package/dist/next/app-server.mjs +479 -0
  43. package/dist/next/app-server.mjs.map +1 -0
  44. package/dist/next/app-session.d.ts +49 -0
  45. package/dist/next/app-session.mjs +238 -0
  46. package/dist/next/app-session.mjs.map +1 -0
  47. package/dist/next/app.d.ts +29 -0
  48. package/dist/next/app.mjs +141 -0
  49. package/dist/next/app.mjs.map +1 -0
  50. package/dist/next/client/live-state.d.ts +63 -0
  51. package/dist/next/client/oauth.d.ts +12 -0
  52. package/dist/next/client/react.d.ts +109 -0
  53. package/dist/next/client/socket.d.ts +6 -0
  54. package/dist/next/client.mjs +156 -0
  55. package/dist/next/client.mjs.map +1 -0
  56. package/dist/next/expression.d.ts +146 -0
  57. package/dist/next/expression.mjs +399 -0
  58. package/dist/next/expression.mjs.map +1 -0
  59. package/dist/next/lib.d.ts +56 -0
  60. package/dist/next/lib.mjs +199 -0
  61. package/dist/next/lib.mjs.map +1 -0
  62. package/dist/next/oauth-scopes.d.ts +32 -0
  63. package/dist/next/oauth-scopes.mjs +40 -0
  64. package/dist/next/oauth-scopes.mjs.map +1 -0
  65. package/dist/next/oauth.mjs +29 -0
  66. package/dist/next/oauth.mjs.map +1 -0
  67. package/dist/next/principal.d.ts +64 -0
  68. package/dist/next/principal.mjs +98 -0
  69. package/dist/next/principal.mjs.map +1 -0
  70. package/dist/next/project-ingress.d.ts +37 -0
  71. package/dist/next/project-ingress.mjs +75 -0
  72. package/dist/next/project-ingress.mjs.map +1 -0
  73. package/dist/next/react.mjs +285 -0
  74. package/dist/next/react.mjs.map +1 -0
  75. package/dist/next/sdk/auth.d.ts +5 -0
  76. package/dist/next/sdk/index.d.ts +112 -0
  77. package/dist/next/sdk.mjs +139 -0
  78. package/dist/next/sdk.mjs.map +1 -0
  79. package/dist/next/stream/processor.d.ts +378 -0
  80. package/dist/next/stream/processor.mjs +582 -0
  81. package/dist/next/stream/processor.mjs.map +1 -0
  82. package/dist/next/stream/run.d.ts +58 -0
  83. package/dist/next/stream/run.mjs +40 -0
  84. package/dist/next/stream/run.mjs.map +1 -0
  85. package/dist/next-node.d.ts +15 -0
  86. package/dist/next-node.mjs +51 -0
  87. package/dist/next-node.mjs.map +1 -0
  88. package/dist/node.d.ts +3 -0
  89. package/dist/node.mjs +185 -0
  90. package/dist/node.mjs.map +1 -0
  91. package/dist/processor-host-capabilities-BMFH3KTM.mjs +56 -0
  92. package/dist/processor-host-capabilities-BMFH3KTM.mjs.map +1 -0
  93. package/dist/processors/cloudflare.d.ts +3 -0
  94. package/dist/processors/durable-object-processor-durability.d.ts +79 -0
  95. package/dist/processors/event-consumption-metrics.d.ts +82 -0
  96. package/dist/processors/idempotency.d.ts +13 -0
  97. package/dist/processors/index.d.ts +12 -0
  98. package/dist/processors/processor-contracts.d.ts +342 -0
  99. package/dist/processors/processor-facet.d.ts +186 -0
  100. package/dist/processors/processor-host-capabilities.d.ts +60 -0
  101. package/dist/processors/prompt-sections.d.ts +17 -0
  102. package/dist/processors/rpc-types.d.ts +515 -0
  103. package/dist/processors/schemas.d.ts +102 -0
  104. package/dist/processors/stream-handle.d.ts +45 -0
  105. package/dist/processors/stream-processor-keepalive.d.ts +95 -0
  106. package/dist/processors/stream-processor-registry.d.ts +233 -0
  107. package/dist/processors/stream-processor-runner.d.ts +289 -0
  108. package/dist/processors/stream-processor.d.ts +339 -0
  109. package/dist/processors/stream-runtime-metrics.d.ts +107 -0
  110. package/dist/processors/testing.d.ts +302 -0
  111. package/dist/processors-BoNyeBfQ.mjs +10 -0
  112. package/dist/processors-BoNyeBfQ.mjs.map +1 -0
  113. package/dist/processors-cloudflare.mjs +3 -0
  114. package/dist/processors-testing.mjs +435 -0
  115. package/dist/processors-testing.mjs.map +1 -0
  116. package/dist/processors.mjs +52 -0
  117. package/dist/processors.mjs.map +1 -0
  118. package/dist/protocol-DnK_f2m6.mjs +251 -0
  119. package/dist/protocol-DnK_f2m6.mjs.map +1 -0
  120. package/dist/sdk/capnweb/index.d.ts +2 -0
  121. package/dist/sdk/capnweb/live-state/compact.d.ts +5 -0
  122. package/dist/sdk/capnweb/live-state/diff.d.ts +41 -0
  123. package/dist/sdk/capnweb/live-state/engine.d.ts +44 -0
  124. package/dist/sdk/capnweb/live-state/index.d.ts +41 -0
  125. package/dist/sdk/capnweb/live-state/protocol.d.ts +87 -0
  126. package/dist/sdk/capnweb/live-state/retain.d.ts +23 -0
  127. package/dist/sdk/capnweb/live-state/store.d.ts +20 -0
  128. package/dist/sdk/capnweb/live-state/types.d.ts +11 -0
  129. package/dist/sdk/capnweb/react.d.ts +45 -0
  130. package/dist/sdk/capnweb/react.mjs +316 -0
  131. package/dist/sdk/capnweb/react.mjs.map +1 -0
  132. package/dist/sdk/capnweb.mjs +4 -0
  133. package/dist/sdk/itx/react.d.ts +191 -0
  134. package/dist/sdk/itx/react.mjs +383 -0
  135. package/dist/sdk/itx/react.mjs.map +1 -0
  136. package/dist/sdk-DMB-IM11.mjs +933 -0
  137. package/dist/sdk-DMB-IM11.mjs.map +1 -0
  138. package/dist/sdk.d.ts +339 -0
  139. package/dist/sdk.mjs +2 -0
  140. package/dist/serve-itx.d.ts +46 -0
  141. package/dist/starter-apps/flake-dashboard/app-ref.d.ts +31 -0
  142. package/dist/starter-apps/flake-dashboard/configured-worker.mjs +1055 -0
  143. package/dist/starter-apps/flake-dashboard/configured-worker.mjs.map +1 -0
  144. package/dist/starter-apps/flake-dashboard/contract.d.ts +4839 -0
  145. package/dist/starter-apps/flake-dashboard/contract.mjs +2 -0
  146. package/dist/starter-apps/flake-dashboard/index.d.ts +17 -0
  147. package/dist/starter-apps/flake-dashboard/index.mjs +56 -0
  148. package/dist/starter-apps/flake-dashboard/index.mjs.map +1 -0
  149. package/dist/starter-apps/flake-dashboard/worker.d.ts +4607 -0
  150. package/dist/starter-apps/github-ai-linter/ai-linter.d.ts +8914 -0
  151. package/dist/starter-apps/github-ai-linter/configured-worker.mjs +17987 -0
  152. package/dist/starter-apps/github-ai-linter/configured-worker.mjs.map +1 -0
  153. package/dist/starter-apps/github-ai-linter/contract.d.ts +9193 -0
  154. package/dist/starter-apps/github-ai-linter/index.d.ts +10 -0
  155. package/dist/starter-apps/github-ai-linter/index.mjs +36 -0
  156. package/dist/starter-apps/github-ai-linter/index.mjs.map +1 -0
  157. package/dist/starter-apps/github-ai-linter/prompt.d.ts +13 -0
  158. package/dist/starter-apps/github-ai-linter/review-bot.d.ts +808 -0
  159. package/dist/starter-apps/github-ai-linter/rules.d.ts +34 -0
  160. package/dist/starter-apps/github-ai-linter/worker-ref.d.ts +19 -0
  161. package/dist/starter-apps/github-ai-linter/worker.d.ts +19 -0
  162. package/dist/starter-apps/github-ai-linter/worker.mjs +947 -0
  163. package/dist/starter-apps/github-ai-linter/worker.mjs.map +1 -0
  164. package/dist/starter-apps/guestbook/app-ref.d.ts +27 -0
  165. package/dist/starter-apps/guestbook/client.d.ts +7 -0
  166. package/dist/starter-apps/guestbook/client.mjs +59 -0
  167. package/dist/starter-apps/guestbook/configured-worker.mjs +205 -0
  168. package/dist/starter-apps/guestbook/configured-worker.mjs.map +1 -0
  169. package/dist/starter-apps/guestbook/index.d.ts +9 -0
  170. package/dist/starter-apps/guestbook/index.mjs +31 -0
  171. package/dist/starter-apps/guestbook/index.mjs.map +1 -0
  172. package/dist/starter-apps/guestbook/processor.d.ts +2267 -0
  173. package/dist/starter-apps/guestbook/worker.d.ts +26 -0
  174. package/dist/starter-apps/guestbook/worker.mjs +191 -0
  175. package/dist/starter-apps/guestbook/worker.mjs.map +1 -0
  176. package/dist/starter-apps/media/configured-worker.mjs +577 -0
  177. package/dist/starter-apps/media/configured-worker.mjs.map +1 -0
  178. package/dist/starter-apps/media/index.mjs +36 -0
  179. package/dist/starter-apps/media/index.mjs.map +1 -0
  180. package/dist/starter-apps/media/ref.mjs +20 -0
  181. package/dist/starter-apps/media/ref.mjs.map +1 -0
  182. package/dist/starter-apps/media/worker.mjs +579 -0
  183. package/dist/starter-apps/media/worker.mjs.map +1 -0
  184. package/dist/starter-apps/notes/configured-worker.mjs +6134 -0
  185. package/dist/starter-apps/notes/configured-worker.mjs.map +1 -0
  186. package/dist/starter-apps/notes/index.mjs +23 -0
  187. package/dist/starter-apps/notes/index.mjs.map +1 -0
  188. package/dist/starter-apps/notes/ref.mjs +21 -0
  189. package/dist/starter-apps/notes/ref.mjs.map +1 -0
  190. package/dist/starter-apps/notes/worker.mjs +427 -0
  191. package/dist/starter-apps/notes/worker.mjs.map +1 -0
  192. package/dist/starter-apps/todo/client.mjs +59 -0
  193. package/dist/starter-apps/todo/configured-worker.mjs +2864 -0
  194. package/dist/starter-apps/todo/configured-worker.mjs.map +1 -0
  195. package/dist/starter-apps/todo/index.d.ts +8 -0
  196. package/dist/starter-apps/todo/index.mjs +29 -0
  197. package/dist/starter-apps/todo/index.mjs.map +1 -0
  198. package/dist/stream-processor-keepalive-DAQTP6m3.mjs +2082 -0
  199. package/dist/stream-processor-keepalive-DAQTP6m3.mjs.map +1 -0
  200. package/dist/usingCtx-inzbY1Qz.mjs +57 -0
  201. package/dist/usingCtx-mZx5nsAW.mjs +11800 -0
  202. package/dist/usingCtx-mZx5nsAW.mjs.map +1 -0
  203. package/dist/worker-ref-DZxPDmb_.mjs +390 -0
  204. package/dist/worker-ref-DZxPDmb_.mjs.map +1 -0
  205. package/menubar/Iterate.entitlements +12 -0
  206. package/menubar/Iterate.swift +914 -0
  207. package/menubar/IterateIcon.swift +145 -0
  208. package/menubar/README.md +28 -0
  209. package/menubar/build-menubar-app.sh +59 -0
  210. package/package.json +235 -18
  211. package/dist/cli-DMS4kJph.mjs +0 -868
  212. package/dist/cli-DMS4kJph.mjs.map +0 -1
  213. package/dist/config-DtnR7Lv7.mjs +0 -170
  214. package/dist/config-DtnR7Lv7.mjs.map +0 -1
  215. package/dist/index.d.mts.map +0 -1
  216. package/dist/stream-tui/agent-chat-terminal.d.mts +0 -1
  217. package/dist/stream-tui/agent-chat-terminal.mjs +0 -933
  218. package/dist/stream-tui/agent-chat-terminal.mjs.map +0 -1
@@ -0,0 +1,399 @@
1
+ import { codedError, jsonEqual } from "./lib.mjs";
2
+ import { RpcTarget } from "capnweb";
3
+ import JSON5 from "json5";
4
+ //#region src/next/expression.ts
5
+ /** A STRING expression is for what a person types: short. Anything bigger — a worker's source, a large
6
+ * literal — rides the PARSED form (`["itx","workers",["get",{ source }]]`), which is plain data and never
7
+ * meets json5. The cap is O(1), before any parsing (stock json5 allocates per character and a
8
+ * multi-megabyte literal kills a 128 MiB isolate — the 2026-09-07 wave-0 plan, issue 2). */
9
+ const ITX_EXPRESSION_STRING_MAX_CHARS = 2048;
10
+ /** The name a step carries: the property itself, or a call step's method. */
11
+ const itxExpressionStepName = (step) => Array.isArray(step) ? step[0] : step;
12
+ const IDENT = /^[A-Za-z_$][A-Za-z0-9_$-]*/;
13
+ const RESERVED = new Set([
14
+ "__proto__",
15
+ "constructor",
16
+ "prototype"
17
+ ]);
18
+ /** The marker's array-half spelling, the one reserved literal. */
19
+ const ITX_EXPRESSION_HOLE = { "@": true };
20
+ /** The merge entry's key — `...@` — read by rule 7. */
21
+ const ITX_EXPRESSION_MERGE_KEY = "...@";
22
+ /** A single- or double-quoted string literal (escapes honored) or a JSON5 comment (block or line):
23
+ * THE one pattern every walk that must skip what is inside them is built from — the marker lex, the
24
+ * marker print, the paren matcher. In an alternation a span is consumed whole, so nothing inside one
25
+ * (a quote in a comment, an `@` in a string) is ever seen by the other alternatives. */
26
+ const STRING_OR_COMMENT = String.raw`"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'|/\*[\s\S]*?\*/|//[^\n]*`;
27
+ const isStringOrComment = (match) => match[0] === "\"" || match[0] === "'" || match[0] === "/";
28
+ /** In call args: a literal (kept verbatim) or a marker — `...@` before `@`, so the merge form wins. */
29
+ const MARKERS_IN_ARGS = new RegExp(`${STRING_OR_COMMENT}|\\.\\.\\.@|@`, "g");
30
+ /** In JSON5's printed output: the marker literal `{'@':true}` and the merge entry `'...@':true` are
31
+ * spelled with a single-quoted key and matched on those exact boundaries — listed BEFORE the literal
32
+ * alternative so the entry's `'...@'` is read as the entry, not as a string. A user's string that
33
+ * merely contains those characters is emitted by JSON5 as a longer (double-quoted) literal and is
34
+ * consumed whole. */
35
+ const MARKERS_IN_PRINT = new RegExp(`\\{'@':true\\}|'\\.\\.\\.@':true|${STRING_OR_COMMENT}`, "g");
36
+ /** A bracket outside a literal. */
37
+ const BRACKETS = new RegExp(`${STRING_OR_COMMENT}|[()[\\]{}]`, "g");
38
+ /** Is `value` the marker literal `{ "@": true }`? */
39
+ const isItxExpressionHole = (value) => jsonEqual(value, ITX_EXPRESSION_HOLE);
40
+ /** Does `value` (a step, an arg tree, a whole expression) hold the marker or a merge entry anywhere? */
41
+ function containsItxExpressionHole(value) {
42
+ if (isItxExpressionHole(value)) return true;
43
+ if (Array.isArray(value)) return value.some(containsItxExpressionHole);
44
+ if (value !== null && typeof value === "object") return value["...@"] === true || Object.values(value).some(containsItxExpressionHole);
45
+ return false;
46
+ }
47
+ /** Index of the `)` closing the `(` at `open`; tracks bracket depth, skipping quoted string args. */
48
+ function matchingParen(source, open) {
49
+ let depth = 0;
50
+ BRACKETS.lastIndex = open;
51
+ for (let bracket = BRACKETS.exec(source); bracket; bracket = BRACKETS.exec(source)) {
52
+ if (isStringOrComment(bracket[0])) continue;
53
+ if ("([{".includes(bracket[0])) depth++;
54
+ else if (--depth === 0) return bracket.index;
55
+ }
56
+ throw new Error(`expression: unbalanced "(" in ${JSON.stringify(source)}`);
57
+ }
58
+ /** Parse the STRING half: dotted names + `.method(args)` calls (args JSON5-parsed); rejects reserved
59
+ * names + bare scope calls. `holes: true` — a rewrite rule's TARGET only — lexes `@` / `...@` into
60
+ * the marker literals; anywhere else a bare `@` is refused. */
61
+ function parse(source, options) {
62
+ if (source.length > ITX_EXPRESSION_STRING_MAX_CHARS) throw codedError("EXPRESSION_TOO_LONG", `itx expression: ${source.length} chars is over the ${ITX_EXPRESSION_STRING_MAX_CHARS}-char limit for the string form — a string expression is for what a person types; pass the parsed form instead: ["itx","workers",["get",{ source: … }]]`);
63
+ const s = source.trim();
64
+ const steps = [];
65
+ let i = 0;
66
+ function fail(m) {
67
+ throw new Error(`expression: ${m} in ${JSON.stringify(source)}`);
68
+ }
69
+ const readName = () => {
70
+ const m = IDENT.exec(s.slice(i));
71
+ if (!m) fail(`name expected at ${i}`);
72
+ if (RESERVED.has(m[0])) fail(`reserved name "${m[0]}"`);
73
+ i += m[0].length;
74
+ return m[0];
75
+ };
76
+ steps.push(readName());
77
+ while (i < s.length) {
78
+ const c = s[i];
79
+ if (/\s/.test(c)) i++;
80
+ else if (c === ".") steps.push((i++, readName()));
81
+ else if (c === "(") {
82
+ const end = matchingParen(s, i);
83
+ const inner = s.slice(i + 1, end).trim().replace(MARKERS_IN_ARGS, (match) => {
84
+ if (isStringOrComment(match)) return match;
85
+ if (!options?.holes) fail("`@` (the caller's input) is legal only in a rewrite rule's target");
86
+ return match === "@" ? JSON.stringify(ITX_EXPRESSION_HOLE) : `${JSON.stringify(ITX_EXPRESSION_MERGE_KEY)}:true`;
87
+ });
88
+ let args = [];
89
+ try {
90
+ if (inner !== "") args = JSON5.parse(`[${inner}]`);
91
+ } catch (e) {
92
+ fail(`call args are not JSON5 (${e.message})`);
93
+ }
94
+ const previous = steps.at(-1);
95
+ if (Array.isArray(previous)) steps.push(["", ...args]);
96
+ else {
97
+ const name = steps.pop();
98
+ if (typeof name !== "string") fail("a call must follow a name");
99
+ if (steps.length === 0) fail("cannot call the scope symbol itself");
100
+ steps.push([name, ...args]);
101
+ }
102
+ i = end + 1;
103
+ } else fail(`unexpected ${JSON.stringify(c)} at ${i}`);
104
+ }
105
+ return steps;
106
+ }
107
+ /** The array half, checked the way the parser checks the string half — every name step an identifier
108
+ * that is not reserved, every call step `[method, ...args]` with an identifier method (or `""`, the
109
+ * anonymous call, only right after a call) — WITHOUT printing and re-parsing: a stored target carries a worker's whole source as
110
+ * data, and that data must never meet the string codec (the 2 KiB cap, json5). Throws in the
111
+ * parser's words. */
112
+ function assertItxExpressionShape(expression) {
113
+ const fail = (m) => {
114
+ throw new Error(`expression: ${m} in ${JSON.stringify(expression).slice(0, 200)}`);
115
+ };
116
+ if (!Array.isArray(expression) || expression.length === 0) fail("an expression is a non-empty array");
117
+ const name = (step, what) => {
118
+ if (!IDENT.test(step) || IDENT.exec(step)[0] !== step) fail(`${what} ${JSON.stringify(step)} is not an identifier`);
119
+ if (RESERVED.has(step)) fail(`reserved name "${step}"`);
120
+ };
121
+ expression.forEach((step, i) => {
122
+ if (typeof step === "string") {
123
+ name(step, i === 0 ? "the root" : "a name step");
124
+ return;
125
+ }
126
+ if (!Array.isArray(step) || typeof step[0] !== "string") fail(`step ${i} is neither a name nor [method, ...args]`);
127
+ const [method] = step;
128
+ if (method === "") {
129
+ if (i === 0 || !Array.isArray(expression[i - 1])) fail("the anonymous call `f(x)(y)` follows a call");
130
+ } else name(method, "a method");
131
+ if (i === 0) fail("a call on the root itself");
132
+ });
133
+ }
134
+ /** THE ONE NORMALIZING DOOR: either half, normalized to the array half and checked — a string is
135
+ * parsed (short by rule), an array is shape-checked in place. Every door that takes an
136
+ * `ItxExpressionInput` (the edge `invoke`, the resolver, the event builders, the prefix parser
137
+ * below) enters through it. */
138
+ function normalizedItxExpression(input, options) {
139
+ if (typeof input === "string") return parse(input, options);
140
+ assertItxExpressionShape(input);
141
+ return input;
142
+ }
143
+ /** Object args print with their keys SORTED, so two spellings of one object are one canonical string
144
+ * — one rewrite-rule row, one facet memo, one library connection memo (library.ts) — the way
145
+ * `jsonEqual` already matches them. A `JSON.stringify` / `JSON5.stringify` replacer. */
146
+ const keySortedForPrint = (_key, value) => value !== null && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.keys(value).sort().map((k) => [k, value[k]])) : value;
147
+ /** Canonical stored form: dotted path + `.method(args)` calls (args `JSON5.stringify`d, object keys
148
+ * sorted). `holes: true` — a rewrite rule's TARGET only — spells the marker literals back as `@` /
149
+ * `...@`, and `parse(print(e, { holes: true }), { holes: true })` round-trips; without it the
150
+ * reserved literals print as the plain JSON5 they are, so a CALL that happens to carry `{ "@": true }`
151
+ * as data round-trips through `parse` (no holes) unchanged — the resolve/invoke law holds for it. */
152
+ function print(expr, options) {
153
+ return expr.map((step, i) => {
154
+ const dot = i ? "." : "";
155
+ if (typeof step === "string") return dot + step;
156
+ const json = JSON5.stringify(step.slice(1), keySortedForPrint).slice(1, -1);
157
+ const args = options?.holes ? json.replace(MARKERS_IN_PRINT, (match) => match === "{'@':true}" ? "@" : match === "'...@':true" ? "...@" : match) : json;
158
+ return step[0] === "" ? `(${args})` : `${dot}${step[0]}(${args})`;
159
+ }).join("");
160
+ }
161
+ /** Parse an itx-expression prefix (either codec half) — `normalizedItxExpression` (so every step is
162
+ * an identifier that is not reserved, in either half) plus the two refusals only a PREFIX has: the
163
+ * anonymous call step (`f(x)(y)` — a prefix cannot call a result), and a call step with NO args,
164
+ * which pins nothing and is the same prefix as the plain name: spell `itx.ai.run`. */
165
+ function parseItxExpressionPrefix(source) {
166
+ const expr = normalizedItxExpression(source);
167
+ const spelled = typeof source === "string" ? source : print(expr);
168
+ for (const step of expr) {
169
+ if (!Array.isArray(step)) continue;
170
+ if (step[0] === "") throw new Error(`an itx-expression prefix cannot call a result — ${JSON.stringify(spelled)}`);
171
+ if (step.length === 1) throw new Error(`an itx-expression prefix pins literal args with a call step — ${JSON.stringify(spelled)} has "${step[0]}()" with none; spell "${step[0]}"`);
172
+ }
173
+ return expr;
174
+ }
175
+ /** THE ONE canonical spelling of an itx-expression prefix — the rewrite-rule table's key, what a lent
176
+ * stub is keyed by through `provide`'s sugar: parsed, then printed (dotted names; pinned args as JSON5
177
+ * literals). */
178
+ function canonicalItxExpressionPrefix(source) {
179
+ return print(parseItxExpressionPrefix(source));
180
+ }
181
+ const PIPELINED_RPC_BRANDS = [];
182
+ /** Register a pipelinable promise brand (the workerd entrypoint's two calls at boot). */
183
+ function registerPipelinedRpcBrand(brand) {
184
+ PIPELINED_RPC_BRANDS.push(brand);
185
+ }
186
+ const pipelined = (v) => PIPELINED_RPC_BRANDS.some((b) => v instanceof b);
187
+ /** Resolve one step's property. `__proto__` / `constructor` / `prototype` never resolve — `constructor`
188
+ * would hand out the class itself (trusted clients or not, that is not a step anyone means). */
189
+ function stepGet(value, key) {
190
+ if (key === "__proto__" || key === "constructor" || key === "prototype") return void 0;
191
+ return Reflect.get(value, key);
192
+ }
193
+ /**
194
+ * THE step walk: property steps `Reflect.get` with the receiver carried; call steps `Reflect.apply`
195
+ * ON that receiver (detaching a method from a Workers-RPC receiver breaks it); an ordinary promise
196
+ * is awaited between steps, a branded one (PIPELINED_RPC_BRANDS, above) is not.
197
+ *
198
+ * ⚠️ DataCloneError LEARNING:
199
+ * invoke facet/RPC-stub methods with `Reflect.apply(fn, receiver, args)`, NEVER `stub[m].apply(stub,
200
+ * args)`. Reading `.apply` off an RPC stub's method proxy is a capnweb PIPELINED REMOTE PATH;
201
+ * calling it passes the stub as an argument, so workerd serializes it — and a Worker-Loader facet
202
+ * stub may never be serialized (`requireAllowsTransfer()` throws unconditionally) → `DataCloneError:
203
+ * Durable Object Facet stubs cannot be transferred between Workers`. Do not "simplify" this away.
204
+ */
205
+ async function walkSteps(start, steps) {
206
+ let { value, receiver } = start;
207
+ for (const [stepIndex, step] of steps.entries()) {
208
+ if (!pipelined(value)) value = await value;
209
+ if (value == null) throw new Error(`hit ${String(value)} at step ${stepIndex + 1} of ${print(steps)} (${JSON.stringify(step)})`);
210
+ if (typeof step === "string") {
211
+ receiver = value;
212
+ value = stepGet(value, step);
213
+ } else {
214
+ const [method, ...args] = step;
215
+ if (method === "") {
216
+ value = callOn(value, receiver, args);
217
+ receiver = void 0;
218
+ if (!pipelined(value)) value = await value;
219
+ continue;
220
+ }
221
+ const fn = stepGet(value, method);
222
+ if (typeof fn !== "function") throw codedError("NOT_A_METHOD", `${JSON.stringify(method)} is not a method at step ${stepIndex + 1} of ${print(steps)}`);
223
+ receiver = void 0;
224
+ value = Reflect.apply(fn, value, args);
225
+ if (!pipelined(value)) value = await value;
226
+ }
227
+ }
228
+ return {
229
+ value: pipelined(value) ? value : await value,
230
+ receiver
231
+ };
232
+ }
233
+ /** Apply `args` to a resolved value on its carried receiver, or a LOUD error if it is not callable
234
+ * (never the silent arg-drop apps/os shipped). An `InvokeHandle` is NOT a JS function (a real
235
+ * RpcTarget so dotted access pipelines — the invoke handle section), so ROOT-calling it dispatches
236
+ * those args at its EMPTY path: `handle(events,range)` ⇒ the bare callback the handle fronts. The one
237
+ * bridge between "callable capability" and "pipelinable RpcTarget". */
238
+ async function callOn(value, receiver, args) {
239
+ if (typeof value === "function") return Reflect.apply(value, receiver, args);
240
+ if (value instanceof InvokeHandle) return value.applyRoot(args);
241
+ throw codedError("NOT_A_METHOD", `target is not callable but ${args.length} arg(s) were passed`);
242
+ }
243
+ /** Names that must NEVER become dynamic capability segments — a dispatcher answering them would turn
244
+ * a plain property probe into a live capability call. Enforced at the prototype-chain hop and at
245
+ * every depth of the path proxies it hands out. Two kinds, one set: */
246
+ const RESERVED_SEGMENT_NAMES = new Set([
247
+ "__defineGetter__",
248
+ "__defineSetter__",
249
+ "__lookupGetter__",
250
+ "__lookupSetter__",
251
+ "__proto__",
252
+ "apply",
253
+ "bind",
254
+ "call",
255
+ "catch",
256
+ "constructor",
257
+ "dup",
258
+ "finally",
259
+ "hasOwnProperty",
260
+ "isPrototypeOf",
261
+ "map",
262
+ "onRpcBroken",
263
+ "propertyIsEnumerable",
264
+ "prototype",
265
+ "then",
266
+ "toLocaleString",
267
+ "toString",
268
+ "valueOf",
269
+ "toJSON",
270
+ "asymmetricMatch"
271
+ ]);
272
+ /** The path proxy: a function-backed Proxy (not an RpcTarget instance) — each missing property
273
+ * extends `path`, and applying the function reduces the whole accumulated access into ONE
274
+ * `invoke(expression)` call, `[...root, ...path.slice(0, -1), [path.at(-1), ...args]]`. */
275
+ function createItxExpressionPathProxy(invoker, root, path) {
276
+ const valueFor = (key) => createItxExpressionPathProxy(invoker, root, [...path, key]);
277
+ return new Proxy(function() {}, {
278
+ apply(_target, _thisArg, args) {
279
+ const method = path[path.length - 1];
280
+ const expr = [
281
+ ...root,
282
+ ...path.slice(0, -1),
283
+ [method, ...args]
284
+ ];
285
+ return invoker.invoke(expr);
286
+ },
287
+ get(target, key, receiver) {
288
+ if (typeof key === "symbol") return Reflect.get(target, key, receiver);
289
+ if (RESERVED_SEGMENT_NAMES.has(key)) return void 0;
290
+ return valueFor(key);
291
+ },
292
+ getOwnPropertyDescriptor(target, key) {
293
+ const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
294
+ if (descriptor) return descriptor;
295
+ if (typeof key === "symbol" || RESERVED_SEGMENT_NAMES.has(key)) return void 0;
296
+ return {
297
+ configurable: true,
298
+ enumerable: true,
299
+ value: valueFor(key),
300
+ writable: false
301
+ };
302
+ },
303
+ has(target, key) {
304
+ if (typeof key === "symbol") return key in target;
305
+ return !RESERVED_SEGMENT_NAMES.has(key);
306
+ }
307
+ });
308
+ }
309
+ /** Install the hop drawn in the header on a class's PROTOTYPE CHAIN, with the scope `root` (`["itx"]`
310
+ * for the edge context, `[]` for a handle). Call ONCE per class. Constructor inheritance is
311
+ * untouched — only `Class.prototype`'s parent link changes, and the hop forwards everything it does
312
+ * not intercept. */
313
+ function installPrototypeInvokeFallback(cls, root) {
314
+ const parentPrototype = Object.getPrototypeOf(cls.prototype);
315
+ const hop = new Proxy(Object.create(parentPrototype), { get(hopTarget, key, receiver) {
316
+ if (typeof key === "symbol" || key in hopTarget) return Reflect.get(hopTarget, key, receiver);
317
+ if (RESERVED_SEGMENT_NAMES.has(key)) return void 0;
318
+ if (!(receiver instanceof cls)) return;
319
+ return createItxExpressionPathProxy(receiver, root, [key]);
320
+ } });
321
+ Object.setPrototypeOf(cls.prototype, hop);
322
+ }
323
+ /** A branded, pipelinable handle for a MID-CHAIN capability (`facets.get(name)`, `cd(path)`,
324
+ * `workers.get(spec)`, a lent stub) whose unknown dotted members reduce into ONE dispatch of the
325
+ * itx-expression STEPS relative to it; the constructor's `dispatch` routes those steps into the
326
+ * underlying object. Declared members (`invoke` / `applyRoot`) win over the fallback, so a
327
+ * capability cannot be named either — the two reserved words this wrapper adds. */
328
+ var InvokeHandle = class extends RpcTarget {
329
+ #dispatchItxExpressionSteps;
330
+ constructor(dispatchItxExpressionSteps) {
331
+ super();
332
+ this.#dispatchItxExpressionSteps = dispatchItxExpressionSteps;
333
+ }
334
+ /** THE reduce door the prototype hop dispatches onto; the expression is RELATIVE to this handle. */
335
+ invoke(itxExpressionSteps) {
336
+ return this.#dispatchItxExpressionSteps(itxExpressionSteps);
337
+ }
338
+ /** Call the bare capability this handle fronts — the ANONYMOUS call step (`callOn` in the dispatch section
339
+ * uses it when a rewritten call's target IS a handle: `handle(events, range)`). */
340
+ applyRoot(args) {
341
+ return this.#dispatchItxExpressionSteps([["", ...args]]);
342
+ }
343
+ };
344
+ installPrototypeInvokeFallback(InvokeHandle, []);
345
+ /** Walk itx-expression steps off a capnweb stub; the ANONYMOUS call step (`""`) calls the value
346
+ * itself (a bare function lent as a capability). NO await inside the loop: on a capnweb stub every
347
+ * step is a PIPELINED path, so an n-step chain costs ONE round trip, flushed by the caller's single
348
+ * await. A DIRECT call on the stub, never `.apply`: reading `.apply` off a capnweb stub's method is
349
+ * itself a pipelined remote path (`walkSteps`'s DataCloneError learning). Exported for the library
350
+ * tier, which may import this module only. */
351
+ function walkStepsOnRpcStub(stub, steps) {
352
+ let value = stub;
353
+ for (const step of steps) if (typeof step === "string") value = value[step];
354
+ else {
355
+ const [method, ...args] = step;
356
+ value = method === "" ? value(...args) : value[method](...args);
357
+ }
358
+ return value;
359
+ }
360
+ /** `itx.facets.get(name)` / `itx.facets.get(name, { source, className })` — a facet of this context. */
361
+ var FacetHandle = class extends InvokeHandle {};
362
+ /** A HANDLE ON THE WIRE IS THE EXPRESSION THAT NAMES IT. An `InvokeHandle` a context mints (`repos.get(path)`,
363
+ * `workspaces.get(path)`, `facets.get(name)`, `cd(path)`, `workers.get(spec)`) holds no state — it is a
364
+ * dispatch closure over a path — yet as a Workers-RPC result it would cross a hop as a LIVE stub whose
365
+ * session keeps the context's actor resident for as long as the holder keeps it (prd 2026-09-22: ~125
366
+ * such sessions parked around the clock). So the context's RPC door answers with THIS instead: the
367
+ * caller's own expression, which from the caller's root denotes the same handle; the caller mints its
368
+ * own handle over it (`materializeItxHandleReference`), and every later verb is one whole call the
369
+ * context resolves from scratch. Nothing outlives a call. A lent client stub (`RpcStubHandle`) is the
370
+ * one handle that IS live and crosses as itself. */
371
+ const ITX_HANDLE_REFERENCE_KEY = "$itxHandleExpression";
372
+ const isItxHandleReference = (value) => Boolean(value) && typeof value === "object" && Array.isArray(value["$itxHandleExpression"]);
373
+ /** What a context's RPC door hands back for `expression`'s result: a reference when the result is a
374
+ * path-shaped handle (an `InvokeHandle` that is not a lent stub) or a reference from a hop below —
375
+ * re-rooted, since `expression` is how THIS caller reached it — else nothing (the result crosses as it
376
+ * is). Runtime args that fold into a terminal NAME fold here exactly as the resolver folds them, so the
377
+ * reference is the call the resolver ran; args left over apply to the value and never name a handle. */
378
+ function itxHandleReferenceOf(result, expression, args = []) {
379
+ const last = expression.at(-1);
380
+ const folded = args.length > 0 && typeof last === "string" && expression.length > 1 ? [...expression.slice(0, -1), [last, ...args]] : args.length > 0 ? void 0 : expression;
381
+ if (!folded) return void 0;
382
+ if (!(result instanceof InvokeHandle && !(result instanceof RpcStubHandle)) && !isItxHandleReference(result)) return void 0;
383
+ return { [ITX_HANDLE_REFERENCE_KEY]: folded };
384
+ }
385
+ /** The holder's side: a reference becomes a handle of the HOLDER's own whose every dotted call is one
386
+ * whole expression through `invoke` — the reference's expression plus the steps. Anything else passes
387
+ * through untouched. The proxy hands relative steps; a caller's own `.invoke("itx.whoami()")` is a
388
+ * whole call, spelled from the root. */
389
+ function materializeItxHandleReference(result, invoke) {
390
+ if (!isItxHandleReference(result)) return result;
391
+ const expression = result[ITX_HANDLE_REFERENCE_KEY];
392
+ return new InvokeHandle((steps) => invoke(typeof steps === "string" || steps[0] === "itx" ? normalizedItxExpression(steps) : [...expression, ...steps]));
393
+ }
394
+ /** `itx.rpcStubs.get(key)` — a live stub lent to the registry. */
395
+ var RpcStubHandle = class extends InvokeHandle {};
396
+ //#endregion
397
+ export { FacetHandle, ITX_EXPRESSION_MERGE_KEY, ITX_HANDLE_REFERENCE_KEY, InvokeHandle, RpcStubHandle, callOn, canonicalItxExpressionPrefix, containsItxExpressionHole, installPrototypeInvokeFallback, isItxExpressionHole, isItxHandleReference, itxExpressionStepName, itxHandleReferenceOf, keySortedForPrint, materializeItxHandleReference, normalizedItxExpression, parse, parseItxExpressionPrefix, print, registerPipelinedRpcBrand, walkSteps, walkStepsOnRpcStub };
398
+
399
+ //# sourceMappingURL=expression.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expression.mjs","names":["#dispatchItxExpressionSteps"],"sources":["../../src/next/expression.ts"],"sourcesContent":["// context/expression.ts — THE expression codec: the STRING half (itx.facets.get(\"core\")) ⇄ the\n// STRUCTURED half ([\"itx\", \"facets\", [\"get\", \"core\"]]). Args are ONE JSON5 grammar, comments included\n// (no hand-rolled number/object parser; __proto__-safe); expressions are persisted NAMES, so deleting\n// one IS revocation. The rewrite rules (match, rank, rewrite) are ./itx-expression-rewriting.ts. Two more concepts\n// ride with the codec, the only platform primitives the library tier may import:\n// dispatch — `walkSteps` / `callOn`: EXECUTE a rewritten call's steps against a live object graph\n// invoke handle — `InvokeHandle` + the prototype hop: the DOTTED DOOR, every unknown chain one `invoke(expression)`\nimport JSON5 from \"json5\";\nimport { RpcTarget } from \"capnweb\";\nimport { codedError, jsonEqual } from \"./lib.ts\";\n\n/** A STRING expression is for what a person types: short. Anything bigger — a worker's source, a large\n * literal — rides the PARSED form (`[\"itx\",\"workers\",[\"get\",{ source }]]`), which is plain data and never\n * meets json5. The cap is O(1), before any parsing (stock json5 allocates per character and a\n * multi-megabyte literal kills a 128 MiB isolate — the 2026-09-07 wave-0 plan, issue 2). */\nconst ITX_EXPRESSION_STRING_MAX_CHARS = 2048;\n\n/** One step: a property read (string) or a call (`[method, ...args]`). Args are plain JSON. The\n * method `\"\"` is the ANONYMOUS call — call the value itself: `itx.builtins.rpcStubs.get('cam')(1, 2)`\n * is `[\"itx\",\"builtins\",\"rpcStubs\",[\"get\",\"cam\"],[\"\",1,2]]` — what a `provide(stub)` rule spells when\n * the lent stub is called with args. */\nexport type ItxExpressionStep = string | [method: string, ...args: unknown[]];\n/** An itx expression as data: the scope root (`itx`) then get/call steps. THE parsed form every door\n * works on. */\nexport type ItxExpression = ItxExpressionStep[];\n/** THE dispatch target, in EITHER codec half — a dotted string that starts with the scope root\n * (`\"itx.facets.get('core')\"`) OR the parsed structured form (`[\"itx\",\"facets\",[\"get\",\"core\"]]`).\n * Both carry call args (the string via `.method(args)`), and `normalizedItxExpression` normalizes\n * either to the structured form — so either works wherever one works, at every door that dispatches. */\nexport type ItxExpressionInput = string | ItxExpression;\n/** An itx-expression PREFIX — a rewrite rule's `match`: dotted names, any of which may be a call step\n * PINNING literal args — `itx.ai.run` or `itx.ai.run('gpt-5')` or `itx.repo.get('main').files`. A\n * pinned arg must equal the call's arg at that position for the rule to match, and is CONSUMED by\n * the match (partial application): `itx.ai.run('gpt-5') ⇒ itx.openai.chat` makes\n * `itx.ai.run('gpt-5', inputs)` into `itx.openai.chat(inputs)`. */\nexport type ItxExpressionPrefix = ItxExpression;\n/** The name a step carries: the property itself, or a call step's method. */\nexport const itxExpressionStepName = (step: ItxExpressionStep | undefined): string | undefined =>\n Array.isArray(step) ? step[0] : step;\n\nconst IDENT = /^[A-Za-z_$][A-Za-z0-9_$-]*/;\nconst RESERVED = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n// ── `@`, THE CALLER'S INPUT — a rewrite rule's target may hold it, nothing else may ──\n// In the string half a bare `@` outside a string literal is the marker (`'@cf/…'` inside quotes is a\n// string like any other); `...@` as an object-literal entry is the merge form. In the array half the\n// marker is ONE reserved literal, `{ \"@\": true }`, and the merge entry the key `\"...@\"` with the value\n// `true` — so the stored form is plain JSON, and those two spellings are unspellable as literals in a\n// target (the codec's one reservation). What `@` MEANS is rule 7 in ./itx-expression-rewriting.ts; here\n// it is only lexed (parse, targets only) and printed back (print, targets only).\n/** The marker's array-half spelling, the one reserved literal. */\nconst ITX_EXPRESSION_HOLE = { \"@\": true } as const;\n/** The merge entry's key — `...@` — read by rule 7. */\nexport const ITX_EXPRESSION_MERGE_KEY = \"...@\";\n\n/** A single- or double-quoted string literal (escapes honored) or a JSON5 comment (block or line):\n * THE one pattern every walk that must skip what is inside them is built from — the marker lex, the\n * marker print, the paren matcher. In an alternation a span is consumed whole, so nothing inside one\n * (a quote in a comment, an `@` in a string) is ever seen by the other alternatives. */\nconst STRING_OR_COMMENT = String.raw`\"(?:[^\"\\\\]|\\\\[\\s\\S])*\"|'(?:[^'\\\\]|\\\\[\\s\\S])*'|/\\*[\\s\\S]*?\\*/|//[^\\n]*`;\nconst isStringOrComment = (match: string): boolean =>\n match[0] === '\"' || match[0] === \"'\" || match[0] === \"/\";\n/** In call args: a literal (kept verbatim) or a marker — `...@` before `@`, so the merge form wins. */\nconst MARKERS_IN_ARGS = new RegExp(`${STRING_OR_COMMENT}|\\\\.\\\\.\\\\.@|@`, \"g\");\n/** In JSON5's printed output: the marker literal `{'@':true}` and the merge entry `'...@':true` are\n * spelled with a single-quoted key and matched on those exact boundaries — listed BEFORE the literal\n * alternative so the entry's `'...@'` is read as the entry, not as a string. A user's string that\n * merely contains those characters is emitted by JSON5 as a longer (double-quoted) literal and is\n * consumed whole. */\nconst MARKERS_IN_PRINT = new RegExp(`\\\\{'@':true\\\\}|'\\\\.\\\\.\\\\.@':true|${STRING_OR_COMMENT}`, \"g\");\n/** A bracket outside a literal. */\nconst BRACKETS = new RegExp(`${STRING_OR_COMMENT}|[()[\\\\]{}]`, \"g\");\n\n/** Is `value` the marker literal `{ \"@\": true }`? */\nexport const isItxExpressionHole = (value: unknown): boolean =>\n jsonEqual(value, ITX_EXPRESSION_HOLE);\n\n/** Does `value` (a step, an arg tree, a whole expression) hold the marker or a merge entry anywhere? */\nexport function containsItxExpressionHole(value: unknown): boolean {\n if (isItxExpressionHole(value)) return true;\n if (Array.isArray(value)) return value.some(containsItxExpressionHole);\n // oxlint-disable-next-line iterate/simple-truthiness-check -- `value` is `unknown`; the typeof separates real objects from primitives (a bare truthiness check would recurse into strings/numbers)\n if (value !== null && typeof value === \"object\")\n return (\n (value as Record<string, unknown>)[ITX_EXPRESSION_MERGE_KEY] === true ||\n Object.values(value).some(containsItxExpressionHole)\n );\n return false;\n}\n\n/** Index of the `)` closing the `(` at `open`; tracks bracket depth, skipping quoted string args. */\nfunction matchingParen(source: string, open: number): number {\n let depth = 0;\n BRACKETS.lastIndex = open;\n for (let bracket = BRACKETS.exec(source); bracket; bracket = BRACKETS.exec(source)) {\n if (isStringOrComment(bracket[0])) continue;\n if (\"([{\".includes(bracket[0])) depth++;\n else if (--depth === 0) return bracket.index;\n }\n throw new Error(`expression: unbalanced \"(\" in ${JSON.stringify(source)}`);\n}\n\n/** Parse the STRING half: dotted names + `.method(args)` calls (args JSON5-parsed); rejects reserved\n * names + bare scope calls. `holes: true` — a rewrite rule's TARGET only — lexes `@` / `...@` into\n * the marker literals; anywhere else a bare `@` is refused. */\nexport function parse(source: string, options?: { holes?: boolean }): ItxExpression {\n if (source.length > ITX_EXPRESSION_STRING_MAX_CHARS)\n throw codedError(\n \"EXPRESSION_TOO_LONG\",\n `itx expression: ${source.length} chars is over the ${ITX_EXPRESSION_STRING_MAX_CHARS}-char limit for the string form — a string expression is for what a person types; pass the parsed form instead: [\"itx\",\"workers\",[\"get\",{ source: … }]]`,\n );\n const s = source.trim();\n const steps: ItxExpression = [];\n let i = 0;\n function fail(m: string): never {\n throw new Error(`expression: ${m} in ${JSON.stringify(source)}`); // decl, not arrow: TS never-narrows\n }\n const readName = (): string => {\n const m = IDENT.exec(s.slice(i));\n if (!m) fail(`name expected at ${i}`);\n if (RESERVED.has(m[0])) fail(`reserved name \"${m[0]}\"`);\n i += m[0].length;\n return m[0];\n };\n steps.push(readName()); // the scope root (itx)\n while (i < s.length) {\n const c = s[i];\n if (/\\s/.test(c)) i++;\n else if (c === \".\") steps.push((i++, readName()));\n else if (c === \"(\") {\n const end = matchingParen(s, i);\n const raw = s.slice(i + 1, end).trim();\n // `@` outside a string literal: the marker (targets only), a refusal everywhere else.\n const inner = raw.replace(MARKERS_IN_ARGS, (match) => {\n if (isStringOrComment(match)) return match;\n if (!options?.holes)\n fail(\"`@` (the caller's input) is legal only in a rewrite rule's target\");\n return match === \"@\"\n ? JSON.stringify(ITX_EXPRESSION_HOLE)\n : `${JSON.stringify(ITX_EXPRESSION_MERGE_KEY)}:true`;\n });\n let args: unknown[] = [];\n try {\n if (inner !== \"\") args = JSON5.parse(`[${inner}]`) as unknown[];\n } catch (e) {\n fail(`call args are not JSON5 (${(e as Error).message})`);\n }\n const previous = steps.at(-1);\n if (Array.isArray(previous))\n steps.push([\"\", ...args]); // `f(x)(y)`: call the result itself\n else {\n const name = steps.pop();\n if (typeof name !== \"string\") fail(\"a call must follow a name\");\n if (steps.length === 0) fail(\"cannot call the scope symbol itself\");\n steps.push([name, ...args]);\n }\n i = end + 1;\n } else fail(`unexpected ${JSON.stringify(c)} at ${i}`);\n }\n return steps;\n}\n\n/** The array half, checked the way the parser checks the string half — every name step an identifier\n * that is not reserved, every call step `[method, ...args]` with an identifier method (or `\"\"`, the\n * anonymous call, only right after a call) — WITHOUT printing and re-parsing: a stored target carries a worker's whole source as\n * data, and that data must never meet the string codec (the 2 KiB cap, json5). Throws in the\n * parser's words. */\nfunction assertItxExpressionShape(expression: ItxExpression): void {\n const fail = (m: string): never => {\n throw new Error(`expression: ${m} in ${JSON.stringify(expression).slice(0, 200)}`);\n };\n // oxlint-disable-next-line iterate/simple-truthiness-check -- runtime shape validation of wire/stored data; the ItxExpression array type is a claim here, not a guarantee\n if (!Array.isArray(expression) || expression.length === 0)\n fail(\"an expression is a non-empty array\");\n const name = (step: string, what: string) => {\n if (!IDENT.test(step) || IDENT.exec(step)![0] !== step)\n fail(`${what} ${JSON.stringify(step)} is not an identifier`);\n if (RESERVED.has(step)) fail(`reserved name \"${step}\"`);\n };\n expression.forEach((step, i) => {\n if (typeof step === \"string\") {\n name(step, i === 0 ? \"the root\" : \"a name step\");\n return;\n }\n // oxlint-disable-next-line iterate/simple-truthiness-check -- runtime shape validation of wire/stored data; the step's static array type is a claim here, not a guarantee\n if (!Array.isArray(step) || typeof step[0] !== \"string\")\n fail(`step ${i} is neither a name nor [method, ...args]`);\n const [method] = step;\n if (method === \"\") {\n if (i === 0 || !Array.isArray(expression[i - 1]))\n fail(\"the anonymous call `f(x)(y)` follows a call\");\n } else name(method, \"a method\");\n if (i === 0) fail(\"a call on the root itself\");\n });\n // No hole check on the array half: `{ \"@\": true }` carried as DATA is data (edge#6) — only the\n // STRING form lexes a bare `@` into the marker, and only for a rule's target.\n}\n\n/** THE ONE NORMALIZING DOOR: either half, normalized to the array half and checked — a string is\n * parsed (short by rule), an array is shape-checked in place. Every door that takes an\n * `ItxExpressionInput` (the edge `invoke`, the resolver, the event builders, the prefix parser\n * below) enters through it. */\nexport function normalizedItxExpression(\n input: ItxExpressionInput,\n options?: { holes?: boolean },\n): ItxExpression {\n if (typeof input === \"string\") return parse(input, options);\n assertItxExpressionShape(input);\n return input;\n}\n\n/** Object args print with their keys SORTED, so two spellings of one object are one canonical string\n * — one rewrite-rule row, one facet memo, one library connection memo (library.ts) — the way\n * `jsonEqual` already matches them. A `JSON.stringify` / `JSON5.stringify` replacer. */\nexport const keySortedForPrint = (_key: string, value: unknown): unknown =>\n // oxlint-disable-next-line iterate/simple-truthiness-check -- `value` is `unknown` (a JSON replacer arg); the typeof discriminates real objects from primitive values\n value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? Object.fromEntries(\n Object.keys(value as Record<string, unknown>)\n .sort()\n .map((k) => [k, (value as Record<string, unknown>)[k]]),\n )\n : value;\n\n/** Canonical stored form: dotted path + `.method(args)` calls (args `JSON5.stringify`d, object keys\n * sorted). `holes: true` — a rewrite rule's TARGET only — spells the marker literals back as `@` /\n * `...@`, and `parse(print(e, { holes: true }), { holes: true })` round-trips; without it the\n * reserved literals print as the plain JSON5 they are, so a CALL that happens to carry `{ \"@\": true }`\n * as data round-trips through `parse` (no holes) unchanged — the resolve/invoke law holds for it. */\nexport function print(expr: ItxExpression, options?: { holes?: boolean }): string {\n return expr\n .map((step, i) => {\n const dot = i ? \".\" : \"\";\n if (typeof step === \"string\") return dot + step;\n const json = JSON5.stringify(step.slice(1), keySortedForPrint).slice(1, -1);\n const args = options?.holes\n ? json.replace(MARKERS_IN_PRINT, (match) =>\n match === \"{'@':true}\" ? \"@\" : match === \"'...@':true\" ? \"...@\" : match,\n )\n : json;\n return step[0] === \"\" ? `(${args})` : `${dot}${step[0]}(${args})`;\n })\n .join(\"\");\n}\n\n/** Parse an itx-expression prefix (either codec half) — `normalizedItxExpression` (so every step is\n * an identifier that is not reserved, in either half) plus the two refusals only a PREFIX has: the\n * anonymous call step (`f(x)(y)` — a prefix cannot call a result), and a call step with NO args,\n * which pins nothing and is the same prefix as the plain name: spell `itx.ai.run`. */\nexport function parseItxExpressionPrefix(source: ItxExpressionInput): ItxExpressionPrefix {\n const expr = normalizedItxExpression(source);\n const spelled = typeof source === \"string\" ? source : print(expr);\n for (const step of expr) {\n if (!Array.isArray(step)) continue;\n if (step[0] === \"\")\n throw new Error(`an itx-expression prefix cannot call a result — ${JSON.stringify(spelled)}`);\n if (step.length === 1)\n throw new Error(\n `an itx-expression prefix pins literal args with a call step — ${JSON.stringify(spelled)} has \"${step[0]}()\" with none; spell \"${step[0]}\"`,\n );\n }\n return expr;\n}\n\n/** THE ONE canonical spelling of an itx-expression prefix — the rewrite-rule table's key, what a lent\n * stub is keyed by through `provide`'s sugar: parsed, then printed (dotted names; pinned args as JSON5\n * literals). */\nexport function canonicalItxExpressionPrefix(source: ItxExpressionInput): string {\n return print(parseItxExpressionPrefix(source));\n}\n\n// ── dispatch ── EXECUTE a rewritten call's steps against a LIVE object graph (the codec that\n// turns strings ⇄ these structures is above; the rules that rewrite a call to a built-in\n// root are ./itx-expression-rewriting.ts). `walkSteps` is THE step walk — `ItxExpressionResolver`\n// replays the steps after the root with it; the facet door and the delivery loop walk steps on a\n// local object with it. `callOn` applies args to a resolved value. The dotted write-half (a handle\n// whose dotted access reduces into one dispatch) is `InvokeHandle` (the next section) — the\n// ONE such primitive, pipelinable over Workers RPC.\n\n// Promise brands the step walk threads UNAWAITED: property access and calls pipeline on them\n// natively, so the whole chain reduces into one round trip and the caller's terminal await is the\n// single flush. os-next iterate-context.ts registers the native cloudflare:workers brands and capnweb's at boot — that\n// import can't live here because the unit lane runs this module in Node, where the list stays empty\n// and every step is simply awaited.\nconst PIPELINED_RPC_BRANDS: (abstract new (...args: never[]) => unknown)[] = [];\n/** Register a pipelinable promise brand (the workerd entrypoint's two calls at boot). */\nexport function registerPipelinedRpcBrand(brand: abstract new (...args: never[]) => unknown): void {\n PIPELINED_RPC_BRANDS.push(brand);\n}\nconst pipelined = (v: unknown): boolean => PIPELINED_RPC_BRANDS.some((b) => v instanceof b);\n\n/** Resolve one step's property. `__proto__` / `constructor` / `prototype` never resolve — `constructor`\n * would hand out the class itself (trusted clients or not, that is not a step anyone means). */\nfunction stepGet(value: object, key: string): unknown {\n if (key === \"__proto__\" || key === \"constructor\" || key === \"prototype\") return undefined;\n return Reflect.get(value, key);\n}\n\n/**\n * THE step walk: property steps `Reflect.get` with the receiver carried; call steps `Reflect.apply`\n * ON that receiver (detaching a method from a Workers-RPC receiver breaks it); an ordinary promise\n * is awaited between steps, a branded one (PIPELINED_RPC_BRANDS, above) is not.\n *\n * ⚠️ DataCloneError LEARNING:\n * invoke facet/RPC-stub methods with `Reflect.apply(fn, receiver, args)`, NEVER `stub[m].apply(stub,\n * args)`. Reading `.apply` off an RPC stub's method proxy is a capnweb PIPELINED REMOTE PATH;\n * calling it passes the stub as an argument, so workerd serializes it — and a Worker-Loader facet\n * stub may never be serialized (`requireAllowsTransfer()` throws unconditionally) → `DataCloneError:\n * Durable Object Facet stubs cannot be transferred between Workers`. Do not \"simplify\" this away.\n */\nexport async function walkSteps(\n start: { value: unknown; receiver: unknown },\n steps: ItxExpression,\n): Promise<{ value: unknown; receiver: unknown }> {\n let { value, receiver } = start;\n for (const [stepIndex, step] of steps.entries()) {\n if (!pipelined(value)) value = await value;\n if (value == null)\n throw new Error(\n `hit ${String(value)} at step ${stepIndex + 1} of ${print(steps)} (${JSON.stringify(step)})`,\n );\n if (typeof step === \"string\") {\n receiver = value;\n value = stepGet(value as object, step);\n } else {\n const [method, ...args] = step;\n if (method === \"\") {\n // the ANONYMOUS call step (expression.ts): call the value itself — a live stub's root call\n value = callOn(value, receiver, args);\n receiver = undefined;\n if (!pipelined(value)) value = await value;\n continue;\n }\n const fn = stepGet(value as object, method);\n if (typeof fn !== \"function\")\n throw codedError(\n \"NOT_A_METHOD\",\n `${JSON.stringify(method)} is not a method at step ${stepIndex + 1} of ${print(steps)}`,\n );\n receiver = undefined;\n value = Reflect.apply(fn, value, args);\n if (!pipelined(value)) value = await value;\n }\n }\n return { value: pipelined(value) ? value : await value, receiver };\n}\n\n/** Apply `args` to a resolved value on its carried receiver, or a LOUD error if it is not callable\n * (never the silent arg-drop apps/os shipped). An `InvokeHandle` is NOT a JS function (a real\n * RpcTarget so dotted access pipelines — the invoke handle section), so ROOT-calling it dispatches\n * those args at its EMPTY path: `handle(events,range)` ⇒ the bare callback the handle fronts. The one\n * bridge between \"callable capability\" and \"pipelinable RpcTarget\". */\nexport async function callOn(value: unknown, receiver: unknown, args: unknown[]): Promise<unknown> {\n if (typeof value === \"function\") return Reflect.apply(value, receiver, args);\n if (value instanceof InvokeHandle) return value.applyRoot(args);\n throw codedError(\"NOT_A_METHOD\", `target is not callable but ${args.length} arg(s) were passed`);\n}\n\n// ── invoke handle ── THE DOTTED DOOR: how a surface that declares only fixed methods is\n// spoken as deep dotted access (`itx.slack.chat.postMessage({...})`), every unknown segment\n// accumulating into ONE `invoke(expression)` dispatch, `[...root, ...prefix, [method, ...args]]`.\n// Declared members always win. The pieces: the reserved names, the function-backed PATH PROXY, the\n// PROTOTYPE HOP that installs the fallback on a class, `InvokeHandle` (the genuine RpcTarget a\n// mid-chain capability is handed back as), and `walkStepsOnRpcStub`.\n//\n// WHY A PROTOTYPE HOP AND NOT A PROXY AROUND THE INSTANCE (tried FIRST and reverted): workerd RPC\n// classifies a call's RESULT for promise pipelining with native brand checks a JS Proxy can never\n// pass (`serializeJsValueWithPipeline` in worker-rpc.c++ → `NonPipelinable`; cloudflare/workerd#6873).\n// So a surface returned FROM A METHOD must hand back a REAL, unproxied instance or every pipelined\n// call on it dies with \"The RPC receiver does not implement the method ...\". A mid-chain call\n// returns its handle ACROSS an RPC boundary (`itx.facets.get('b').hello()` is two dispatches), and\n// capnweb's RpcTarget IS the native `cloudflare:workers` RpcTarget on workerd, so a real RpcTarget\n// passes on both hops. The hop squares that with dynamic dispatch by inserting one proxied link\n// BETWEEN `Class.prototype` and its parent:\n//\n// instance ──proto──▶ Class.prototype ──proto──▶ Proxy(hop) ──proto──▶ parent\n//\n// - The instance is a genuine, natively-branded RpcTarget → the pipeline classifier accepts it.\n// - Declared members resolve BEFORE the hop — built-ins win, so a dynamic capability can never\n// shadow a declared name (the deliberate trade-off).\n// - Unknown string keys reach the hop's `get` trap and become path proxies, dispatched via the\n// receiver's own `invoke`; the receiver IS the invoker, so it wires with zero glue.\n// - Instances stay clean of own properties, so Workers RPC's instance-property protection needs\n// no `getOwnPropertyDescriptor` help.\n//\n// KNOWN QUIRKS (accepted, by parity with apps/os): no `has` trap on the hop, so `\"x\" in instance`\n// reflects DECLARED members only while `instance.x` conjures a dispatcher — feature-detect with\n// access, not `in`; a typo'd built-in (`itx.strems`) is a syntactically valid dynamic dispatch that\n// fails at the capability table, not a crisp missing-method error.\n//\n// The library tier may import this module and the codec only (library.test.ts).\n\n/** The dispatch door every dotted miss collapses onto. `IterateContextRpcTarget` implements it directly (root\n * `itx`); a mid-chain `InvokeHandle` implements it relative to itself (empty root). */\ntype InvokeTarget = {\n invoke(itxExpression: ItxExpression): unknown;\n};\n\n/** Names that must NEVER become dynamic capability segments — a dispatcher answering them would turn\n * a plain property probe into a live capability call. Enforced at the prototype-chain hop and at\n * every depth of the path proxies it hands out. Two kinds, one set: */\nconst RESERVED_SEGMENT_NAMES: ReadonlySet<string> = new Set([\n // JS/RPC protocol machinery a framework or capnweb probes on any object (`then` above all: an\n // instance must never look thenable, or every `await` of it would resolve a capability).\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n \"__proto__\",\n \"apply\",\n \"bind\",\n \"call\",\n \"catch\",\n \"constructor\",\n \"dup\",\n \"finally\",\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"map\",\n \"onRpcBroken\",\n \"propertyIsEnumerable\",\n \"prototype\",\n \"then\",\n \"toLocaleString\",\n \"toString\",\n \"valueOf\",\n // Names common protocols LOOK UP on arbitrary objects and CALL if callable: JSON.stringify\n // (toJSON) and vitest/jest equality (asymmetricMatch). The asymmetricMatch case is worse than\n // noise — vitest treats any object with a callable asymmetricMatch as an asymmetric matcher, and\n // a dispatcher returning a (truthy) Promise makes the equality SPURIOUSLY PASS. The bar for this\n // half is HIGH (these names become unreachable as dotted segments; explicit invoke still\n // reaches them): probed-and-called by ubiquitous protocols AND implausible as capability names.\n \"toJSON\",\n \"asymmetricMatch\",\n]);\n\n/** The path proxy: a function-backed Proxy (not an RpcTarget instance) — each missing property\n * extends `path`, and applying the function reduces the whole accumulated access into ONE\n * `invoke(expression)` call, `[...root, ...path.slice(0, -1), [path.at(-1), ...args]]`. */\nfunction createItxExpressionPathProxy(\n invoker: InvokeTarget,\n root: readonly string[],\n path: string[],\n): unknown {\n const valueFor = (key: string) => createItxExpressionPathProxy(invoker, root, [...path, key]);\n return new Proxy(function () {}, {\n apply(_target, _thisArg, args) {\n const method = path[path.length - 1];\n const expr: ItxExpression = [...root, ...path.slice(0, -1), [method, ...(args as unknown[])]];\n return invoker.invoke(expr);\n },\n get(target, key, receiver) {\n if (typeof key === \"symbol\") return Reflect.get(target, key, receiver);\n if (RESERVED_SEGMENT_NAMES.has(key)) return undefined;\n return valueFor(key);\n },\n getOwnPropertyDescriptor(target, key) {\n const descriptor = Reflect.getOwnPropertyDescriptor(target, key);\n if (descriptor) return descriptor;\n if (typeof key === \"symbol\" || RESERVED_SEGMENT_NAMES.has(key)) return undefined;\n // Cap'n Web's server-side path traversal probes own descriptors before reading a segment, so\n // dynamic roots must look discoverable here to reach the apply trap.\n return { configurable: true, enumerable: true, value: valueFor(key), writable: false };\n },\n has(target, key) {\n if (typeof key === \"symbol\") return key in target;\n return !RESERVED_SEGMENT_NAMES.has(key);\n },\n });\n}\n\n/** Install the hop drawn in the header on a class's PROTOTYPE CHAIN, with the scope `root` (`[\"itx\"]`\n * for the edge context, `[]` for a handle). Call ONCE per class. Constructor inheritance is\n * untouched — only `Class.prototype`'s parent link changes, and the hop forwards everything it does\n * not intercept. */\nexport function installPrototypeInvokeFallback<T extends abstract new (...args: never[]) => object>(\n cls: T,\n root: readonly string[],\n): void {\n const parentPrototype = Object.getPrototypeOf(cls.prototype) as object;\n const hop = new Proxy(Object.create(parentPrototype) as object, {\n get(hopTarget, key, receiver) {\n // Symbols and anything the parent chain already answers (dispose protocol, capnweb\n // internals, Object.prototype) pass through with the instance as receiver.\n if (typeof key === \"symbol\" || key in hopTarget) {\n return Reflect.get(hopTarget, key, receiver);\n }\n if (RESERVED_SEGMENT_NAMES.has(key)) return undefined;\n // The dynamic fallback exists for INSTANCES. A lookup whose receiver is not one — someone\n // probing `Class.prototype.foo` directly, a framework walking prototypes — must see plain\n // \"undefined\", not conjure a dispatcher over an uninitialized receiver.\n if (!(receiver instanceof (cls as unknown as abstract new (...args: never[]) => object))) {\n return undefined;\n }\n // The receiver IS the invoker (it implements invoke). Its method resolves at CALL\n // time, so a trap firing mid-construction (a property miss on `this` before field initializers\n // ran) can't bake a dispatcher over half-initialized state into the path proxy.\n return createItxExpressionPathProxy(receiver as unknown as InvokeTarget, root, [key]);\n },\n });\n Object.setPrototypeOf(cls.prototype, hop);\n}\n\n/** A branded, pipelinable handle for a MID-CHAIN capability (`facets.get(name)`, `cd(path)`,\n * `workers.get(spec)`, a lent stub) whose unknown dotted members reduce into ONE dispatch of the\n * itx-expression STEPS relative to it; the constructor's `dispatch` routes those steps into the\n * underlying object. Declared members (`invoke` / `applyRoot`) win over the fallback, so a\n * capability cannot be named either — the two reserved words this wrapper adds. */\nexport class InvokeHandle extends RpcTarget {\n readonly #dispatchItxExpressionSteps: (itxExpressionSteps: ItxExpression) => unknown;\n constructor(dispatchItxExpressionSteps: (itxExpressionSteps: ItxExpression) => unknown) {\n super();\n this.#dispatchItxExpressionSteps = dispatchItxExpressionSteps;\n }\n /** THE reduce door the prototype hop dispatches onto; the expression is RELATIVE to this handle. */\n invoke(itxExpressionSteps: ItxExpression): unknown {\n return this.#dispatchItxExpressionSteps(itxExpressionSteps);\n }\n /** Call the bare capability this handle fronts — the ANONYMOUS call step (`callOn` in the dispatch section\n * uses it when a rewritten call's target IS a handle: `handle(events, range)`). */\n applyRoot(args: unknown[]): unknown {\n return this.#dispatchItxExpressionSteps([[\"\", ...args]]);\n }\n}\ninstallPrototypeInvokeFallback(InvokeHandle, []);\n\n/** Walk itx-expression steps off a capnweb stub; the ANONYMOUS call step (`\"\"`) calls the value\n * itself (a bare function lent as a capability). NO await inside the loop: on a capnweb stub every\n * step is a PIPELINED path, so an n-step chain costs ONE round trip, flushed by the caller's single\n * await. A DIRECT call on the stub, never `.apply`: reading `.apply` off a capnweb stub's method is\n * itself a pipelined remote path (`walkSteps`'s DataCloneError learning). Exported for the library\n * tier, which may import this module only. */\nexport function walkStepsOnRpcStub(stub: unknown, steps: ItxExpression): unknown {\n let value: unknown = stub;\n for (const step of steps) {\n if (typeof step === \"string\") value = (value as Record<string, unknown>)[step];\n else {\n const [method, ...args] = step;\n value =\n method === \"\"\n ? (value as (...a: unknown[]) => unknown)(...args)\n : (value as Record<string, (...a: unknown[]) => unknown>)[method](...args);\n }\n }\n return value;\n}\n\n// ── the two BRANDS the subscription delivery loop reads: the kinds that OWN THEIR PROGRESS, so a push\n// needs no cursor on the stream side (subscription-delivery.ts). Nothing is declared on any event;\n// the brand is minted where the built-in mints the handle. ──\n\n/** `itx.facets.get(name)` / `itx.facets.get(name, { source, className })` — a facet of this context. */\nexport class FacetHandle extends InvokeHandle {}\n\n/** A HANDLE ON THE WIRE IS THE EXPRESSION THAT NAMES IT. An `InvokeHandle` a context mints (`repos.get(path)`,\n * `workspaces.get(path)`, `facets.get(name)`, `cd(path)`, `workers.get(spec)`) holds no state — it is a\n * dispatch closure over a path — yet as a Workers-RPC result it would cross a hop as a LIVE stub whose\n * session keeps the context's actor resident for as long as the holder keeps it (prd 2026-09-22: ~125\n * such sessions parked around the clock). So the context's RPC door answers with THIS instead: the\n * caller's own expression, which from the caller's root denotes the same handle; the caller mints its\n * own handle over it (`materializeItxHandleReference`), and every later verb is one whole call the\n * context resolves from scratch. Nothing outlives a call. A lent client stub (`RpcStubHandle`) is the\n * one handle that IS live and crosses as itself. */\nexport const ITX_HANDLE_REFERENCE_KEY = \"$itxHandleExpression\";\nexport type ItxHandleReference = { [ITX_HANDLE_REFERENCE_KEY]: ItxExpression };\n\nexport const isItxHandleReference = (value: unknown): value is ItxHandleReference =>\n Boolean(value) &&\n typeof value === \"object\" &&\n Array.isArray((value as Record<string, unknown>)[ITX_HANDLE_REFERENCE_KEY]);\n\n/** What a context's RPC door hands back for `expression`'s result: a reference when the result is a\n * path-shaped handle (an `InvokeHandle` that is not a lent stub) or a reference from a hop below —\n * re-rooted, since `expression` is how THIS caller reached it — else nothing (the result crosses as it\n * is). Runtime args that fold into a terminal NAME fold here exactly as the resolver folds them, so the\n * reference is the call the resolver ran; args left over apply to the value and never name a handle. */\nexport function itxHandleReferenceOf(\n result: unknown,\n expression: ItxExpression,\n args: unknown[] = [],\n): ItxHandleReference | undefined {\n const last = expression.at(-1);\n const folded =\n args.length > 0 && typeof last === \"string\" && expression.length > 1\n ? [...expression.slice(0, -1), [last, ...args] as ItxExpressionStep]\n : args.length > 0\n ? undefined\n : expression;\n if (!folded) return undefined;\n const isPathShapedHandle = result instanceof InvokeHandle && !(result instanceof RpcStubHandle);\n if (!isPathShapedHandle && !isItxHandleReference(result)) return undefined;\n return { [ITX_HANDLE_REFERENCE_KEY]: folded };\n}\n\n/** The holder's side: a reference becomes a handle of the HOLDER's own whose every dotted call is one\n * whole expression through `invoke` — the reference's expression plus the steps. Anything else passes\n * through untouched. The proxy hands relative steps; a caller's own `.invoke(\"itx.whoami()\")` is a\n * whole call, spelled from the root. */\nexport function materializeItxHandleReference(\n result: unknown,\n invoke: (expression: ItxExpression) => unknown,\n): unknown {\n if (!isItxHandleReference(result)) return result;\n const expression = result[ITX_HANDLE_REFERENCE_KEY];\n return new InvokeHandle((steps) =>\n invoke(\n typeof steps === \"string\" || steps[0] === \"itx\"\n ? normalizedItxExpression(steps as ItxExpressionInput)\n : [...expression, ...steps],\n ),\n );\n}\n/** `itx.rpcStubs.get(key)` — a live stub lent to the registry. */\nexport class RpcStubHandle extends InvokeHandle {}\n"],"mappings":";;;;;;;;AAeA,MAAM,kCAAkC;;AAsBxC,MAAa,yBAAyB,SACpC,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK;AAElC,MAAM,QAAQ;AACd,MAAM,WAAW,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW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uBAA2D;;;;;;AAO5E,SAAgB,qBACd,QACA,YACA,OAAkB,CAAC,GACa;CAChC,MAAM,OAAO,WAAW,GAAG,EAAE;CAC7B,MAAM,SACJ,KAAK,SAAS,KAAK,OAAO,SAAS,YAAY,WAAW,SAAS,IAC/D,CAAC,GAAG,WAAW,MAAM,GAAG,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAsB,IACjE,KAAK,SAAS,IACZ,KAAA,IACA;CACR,IAAI,CAAC,QAAQ,OAAO,KAAA;CAEpB,IAAI,EADuB,kBAAkB,gBAAgB,EAAE,kBAAkB,mBACtD,CAAC,qBAAqB,MAAM,GAAG,OAAO,KAAA;CACjE,OAAO,GAAG,2BAA2B,OAAO;AAC9C;;;;;AAMA,SAAgB,8BACd,QACA,QACS;CACT,IAAI,CAAC,qBAAqB,MAAM,GAAG,OAAO;CAC1C,MAAM,aAAa,OAAO;CAC1B,OAAO,IAAI,cAAc,UACvB,OACE,OAAO,UAAU,YAAY,MAAM,OAAO,QACtC,wBAAwB,KAA2B,IACnD,CAAC,GAAG,YAAY,GAAG,KAAK,CAC9B,CACF;AACF;;AAEA,IAAa,gBAAb,cAAmC,aAAa,CAAC"}
@@ -0,0 +1,56 @@
1
+ /** The stable machine-readable codes — SCREAMING_SNAKE, defined once, both ends import this. */
2
+ type ErrorCode = "SCHEDULE_LIMIT" | "INVALID_INPUT" | "IDENTITY_CONFLICT" | "GRANT_NOT_FOUND" | "NO_ITX_EXPRESSION_MATCH" | "IDEMPOTENCY_CONFLICT" | "OFFSET_CONFLICT" | "EVENT_TOO_LARGE" | "REDUCE_CHECKPOINT_TOO_LARGE" | "EVENT_UNREADABLE" | "STREAM_PAUSED" | "INVALID_CONTEXT" | "EXPRESSION_TOO_LONG" | "FACET_SOURCE_TOO_LARGE" | "INVALID_CREDENTIALS" | "UNAUTHENTICATED" | "FORBIDDEN" | "PROJECT_NAME_TAKEN" | "RPC_STUB_OFFLINE" | "NOT_A_METHOD" | "NO_FACET" | "FACET_NO_UPGRADE" | "WAIT_TIMEOUT" | "TIMEOUT";
3
+ /** A plain Error carrying `code` (+ optional `data`) as own enumerable properties. */
4
+ export declare function codedError(code: ErrorCode, message: string, data?: unknown): Error;
5
+ /** The code of an error that crossed any number of hops — undefined for uncoded errors. */
6
+ export declare function errorCode(error: unknown): ErrorCode | undefined;
7
+ type Scalar = string | number | boolean | null;
8
+ /** Print ONE bounded console.error line for an unexpected failure; never throws. */
9
+ export declare function reportIssue(failureSite: string, caught: unknown, attributes?: Record<string, Scalar | undefined>): void;
10
+ export type PatchOp = {
11
+ op: "add";
12
+ path: string;
13
+ value: unknown;
14
+ } | {
15
+ op: "replace";
16
+ path: string;
17
+ value: unknown;
18
+ } | {
19
+ op: "remove";
20
+ path: string;
21
+ };
22
+ /** Structural deep-equal over plain JSON values — order-insensitive, unbudgeted (JSON is acyclic).
23
+ * THE one deep-equal: the live-state diff's "don't emit" test AND the idempotency-body compare
24
+ * (re-exported through stream/processor.ts). The `Object.hasOwn(b, k)` guard is load-bearing — without
25
+ * it, two objects with the same key COUNT but different key SETS compare equal. */
26
+ export declare function jsonEqual(a: unknown, b: unknown): boolean;
27
+ /** Structural diff `a → b`, or undefined when deep-equal (the producer's "don't emit" signal).
28
+ * Objects recurse per key; arrays get the chat-log fast paths (pure append → `add …/-` ops,
29
+ * pure tail-truncate → `remove` ops) and are replaced wholesale on any middle divergence —
30
+ * the LiveView trade: optimize the growing log, full-render the rewrite.
31
+ * Both sides are JSON-normalized first — the wire is JSON, so the diff must see exactly what
32
+ * the wire will carry: undefined-valued keys vanish, Dates become their ISO strings, array
33
+ * holes become null. Diffing what you didn't normalize is how a Date change goes silent. */
34
+ export declare function diff(a: unknown, b: unknown): PatchOp[] | undefined;
35
+ /** Apply a patch non-mutatingly (clone-then-mutate). The client half of `diff` — exported
36
+ * through the SDK so subscribers need no third-party json-patch dependency. */
37
+ export declare function applyPatch<T>(doc: T, ops: PatchOp[]): T;
38
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number, what: string | (() => string)): Promise<T>;
39
+ /** Whether `request` may spend the cookies it carries: its `Origin` header is this origin, or absent
40
+ * (a non-browser client — curl, a script). A browser stamps the page's origin on every WebSocket
41
+ * handshake, every cross-site fetch and every form POST, so a foreign origin means a foreign site
42
+ * drove the request with the visitor's cookie riding along. A malformed `Origin` (the literal
43
+ * `null` of a sandboxed document included) is foreign. */
44
+ export declare function isSameOriginBrowserRequest(request: Pick<Request, "url" | "headers">): boolean;
45
+ /** `next` as a path on `origin`, else "/" — a redirect never leaves the host: `//evil.example`,
46
+ * `/\evil.example` and an absolute URL all resolve to a foreign origin and fall back to "/". The
47
+ * issuer's login redirect uses it too (os-next issuer-pages.ts). */
48
+ export declare function sameOriginPath(next: string, origin: string): string;
49
+ /** Only plain HTTP loopback origins use development login and client registration. */
50
+ export declare function isLocalOrigin(origin: string): boolean;
51
+ /** Resolve a `cd` target against a context's own path — the one resolver every `cd` (the edge
52
+ * method, the built-in root, the library's relative handles) shares. Absolute ("/agents/x") stands alone; relative
53
+ * ("agents/x", "../inbox", ".") joins onto `base`. `.` and `..` resolve; the root cannot be
54
+ * escaped ("/.." is "/"). The result is canonical: leading slash, no trailing slash but for "/". */
55
+ export declare function resolveContextPath(basePath: string, contextPath: string): string;
56
+ export {};