@reticlehq/core 3.1.0 → 3.2.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.
package/dist/wire/net.js CHANGED
@@ -207,3 +207,27 @@ export function urlForMatch(data) {
207
207
  const url = data['url'];
208
208
  return 'string' === typeof url ? url : '';
209
209
  }
210
+ /**
211
+ * The NET_REQUEST field carrying a DISCRIMINATOR for the request body.
212
+ *
213
+ * `duplicate-request` asks whether two writes in one action's window were the same write. Method
214
+ * plus URL cannot answer that — a command-bus API posts every mutation to one endpoint, and a
215
+ * submit that intentionally saves and then advances sends two different payloads to the same URL —
216
+ * and the body that could answer it is not on the record: capturing bodies by default would put
217
+ * passwords, tokens and customer data on the wire for every request an app makes.
218
+ *
219
+ * So the page sends a fingerprint of the body's SHAPE instead: key names, value types and the total
220
+ * length, hashed. It is equal for two identical payloads and different for two payloads that differ
221
+ * in structure or size, which is all the rule needs, and it is not a projection of the payload —
222
+ * no character of any value is ever read into it, so there is nothing in it to recover.
223
+ */
224
+ export const REQUEST_SHAPE_FIELD = 'requestShape';
225
+ /**
226
+ * The fingerprint of a request that carried NO body.
227
+ *
228
+ * A KNOWN discriminator, not a missing one: two bodyless POSTs to one URL are indistinguishable to
229
+ * the server too, so they are allowed to be a duplicate. A body the page cannot read as text
230
+ * (FormData, Blob, a stream) omits the field ALTOGETHER, which is the same statement an older SDK
231
+ * makes by not sending it: a body may have existed and nothing about it is on the record.
232
+ */
233
+ export const REQUEST_SHAPE_NONE = 'none';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Reading the snapshot tree — the one line-per-element text format the browser emits.
3
+ *
4
+ * It lives in core because it is a WIRE format: the browser writes it, and several things on the
5
+ * Node side read it back. It was previously a helper beside the MCP tool handlers, which made every
6
+ * other reader import from the tool surface to parse a string the tool surface does not own — and a
7
+ * directory guard caught exactly that the moment a second layer needed it.
8
+ *
9
+ * A line looks like:
10
+ *
11
+ * - button "Pay $42.00" (ref=e4) [disabled]
12
+ *
13
+ * Only elements carrying a `ref` can be acted on, so only those are returned.
14
+ */
15
+ /** One interactive element: its ref, and the line it came from with the ref taken out. */
16
+ export interface InteractiveItem {
17
+ ref: string;
18
+ desc: string;
19
+ }
20
+ /**
21
+ * Parse interactive elements (those with refs) out of a snapshot tree.
22
+ *
23
+ * The description used to be built with a SECOND regex, `/\s*\(ref=e\d+\)/`, whose leading `\s*`
24
+ * made it quadratic: on a line with a long run of whitespace the engine retries the unbounded
25
+ * prefix at every position before failing the literal that follows. The tree is page-derived, so
26
+ * that run is app-controlled, and CodeQL flagged it as a polynomial ReDoS on the release branch.
27
+ *
28
+ * `REF` has already located the token, so the description is the line with that exact span cut
29
+ * out. The `\s*` was NOT redundant -- it ate the gap left behind when a ref sits mid-line, and two
30
+ * pinned tests failed when it was dropped outright -- so the prefix is trimmed instead. `trimEnd`
31
+ * is a string method: same result, linear, and one fewer regex to keep in step with the first.
32
+ */
33
+ export declare function parseInteractive(tree: string): InteractiveItem[];
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Reading the snapshot tree — the one line-per-element text format the browser emits.
3
+ *
4
+ * It lives in core because it is a WIRE format: the browser writes it, and several things on the
5
+ * Node side read it back. It was previously a helper beside the MCP tool handlers, which made every
6
+ * other reader import from the tool surface to parse a string the tool surface does not own — and a
7
+ * directory guard caught exactly that the moment a second layer needed it.
8
+ *
9
+ * A line looks like:
10
+ *
11
+ * - button "Pay $42.00" (ref=e4) [disabled]
12
+ *
13
+ * Only elements carrying a `ref` can be acted on, so only those are returned.
14
+ */
15
+ const REF = /\(ref=(e\d+)\)/;
16
+ /**
17
+ * Parse interactive elements (those with refs) out of a snapshot tree.
18
+ *
19
+ * The description used to be built with a SECOND regex, `/\s*\(ref=e\d+\)/`, whose leading `\s*`
20
+ * made it quadratic: on a line with a long run of whitespace the engine retries the unbounded
21
+ * prefix at every position before failing the literal that follows. The tree is page-derived, so
22
+ * that run is app-controlled, and CodeQL flagged it as a polynomial ReDoS on the release branch.
23
+ *
24
+ * `REF` has already located the token, so the description is the line with that exact span cut
25
+ * out. The `\s*` was NOT redundant -- it ate the gap left behind when a ref sits mid-line, and two
26
+ * pinned tests failed when it was dropped outright -- so the prefix is trimmed instead. `trimEnd`
27
+ * is a string method: same result, linear, and one fewer regex to keep in step with the first.
28
+ */
29
+ export function parseInteractive(tree) {
30
+ const items = [];
31
+ for (const line of tree.split('\n')) {
32
+ const match = REF.exec(line);
33
+ if (match !== null) {
34
+ const token = match[0];
35
+ const at = line.indexOf(token);
36
+ items.push({
37
+ ref: match[1] ?? '',
38
+ desc: `${line.slice(0, at).trimEnd()}${line.slice(at + token.length)}`.trim(),
39
+ });
40
+ }
41
+ }
42
+ return items;
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reticlehq/core",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "The Reticle foundation: the shared wire contract — types, zod schemas, constants, messages, and the isomorphic kernel that every Reticle package (browser SDK, server, kits, test harness) imports. Depends only on zod.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",