@reclaimprotocol/agent 0.1.10 → 0.1.11

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.
@@ -15,6 +15,76 @@ import "../proof/patch-domhandler.js";
15
15
  /** Identifying attributes stable enough to anchor an xPath on (value-bearing
16
16
  * attrs like `content`/`href`/`value` are excluded). */
17
17
  const IDENT_ATTRS = ['name', 'property', 'itemprop', 'data-testid', 'rel', 'for'];
18
+ /** Base weight by anchor kind: purpose-built test hooks and ids beat classes,
19
+ * which beat a positional path. Modulated by {@link tokenQuality}. */
20
+ const TYPE_WEIGHT = {
21
+ 'ident-attr': 0.95,
22
+ id: 0.9,
23
+ class: 0.6,
24
+ positional: 0.3,
25
+ };
26
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
27
+ /**
28
+ * How likely an identifier token is to survive a future render, by its SHAPE —
29
+ * framework-agnostic, so it catches generated ids/classes from any tool (this
30
+ * year's or next) without naming them. Returns `[0.02, 1]`.
31
+ *
32
+ * Volatile shapes (machine-generated): a `:` (React `useId` `:r1:`, Radix), a
33
+ * UUID, digit-heavy or trailing-digit tokens (`ember123`, `tab-2`), hex/hash
34
+ * runs (`css-1a2b3c`), or opaque wordless strings. Durable shapes (human
35
+ * authored): real word segments, kebab/snake of words (`settings-header`,
36
+ * `primary_email_select`).
37
+ */
38
+ function tokenQuality(token) {
39
+ const t = token.trim();
40
+ if (!t) {
41
+ return 0.3;
42
+ }
43
+ // Kill signals — these tokens are (almost) always per-render generated.
44
+ if (t.includes(':') || UUID_RE.test(t)) {
45
+ return 0.05;
46
+ }
47
+ let q = 1;
48
+ const len = t.length;
49
+ const digits = (t.match(/\d/g) ?? []).length;
50
+ const digitRatio = digits / len;
51
+ // A trailing digit run after letters is the classic generated-id tail.
52
+ if (/[A-Za-z][-_]?\d+$/.test(t)) {
53
+ q *= 0.3;
54
+ }
55
+ if (digitRatio > 0.3) {
56
+ q *= 0.4;
57
+ }
58
+ else if (digitRatio > 0.15) {
59
+ q *= 0.7;
60
+ }
61
+ // A pure hex/short-hash run (`1a2b3c`, `deadbeef`) — no semantic content.
62
+ if (/^[0-9a-f]{6,}$/i.test(t)) {
63
+ q *= 0.15;
64
+ }
65
+ // A real word — an alpha run ≥3 that ITSELF contains a vowel — is the
66
+ // strongest durability signal; its absence means the token is opaque /
67
+ // hash-like (`css-1a2b3c`, `sc-bdfBwQ`). Checking per-segment matters: a
68
+ // stray vowel elsewhere in a hash must not count as "has a word".
69
+ const hasWord = (t.match(/[A-Za-z]+/g) ?? [])
70
+ .some((run) => run.length >= 3 && /[aeiou]/i.test(run));
71
+ if (!hasWord) {
72
+ q *= 0.3;
73
+ }
74
+ if (len > 40) {
75
+ q *= 0.6;
76
+ }
77
+ return Math.max(0.02, Math.min(1, q));
78
+ }
79
+ /** Stability score for a candidate: base weight for its kind × the shape
80
+ * quality of its identifier, minus a small depth nudge so a nearer/shorter
81
+ * anchor wins an otherwise-tie. Positional paths score on kind alone. */
82
+ function anchorStability(c) {
83
+ const base = TYPE_WEIGHT[c.kind];
84
+ const quality = c.kind === 'positional' ? 1 : tokenQuality(c.token ?? '');
85
+ const depthNudge = 1 - Math.min(c.depth, 8) * 0.01;
86
+ return base * quality * depthNudge;
87
+ }
18
88
  /**
19
89
  * A verified xPath to the tightest element containing one of `targets`, or
20
90
  * undefined if the value isn't present in the parsed tree. Prefers a short
@@ -45,14 +115,24 @@ export function elementAnchor(html, targets) {
45
115
  if (startIndex === null || endIndex === null) {
46
116
  return undefined;
47
117
  }
48
- for (const candidate of candidateXPaths(el)) {
49
- if (matchesUniquely(doc, candidate, el)) {
50
- // `[startIndex, endIndex)` is exactly the slice the attestor reveals for
51
- // this xPath (its getNodeRange uses these same parse5 source locations).
52
- return { xPath: candidate, start: startIndex, end: endIndex };
53
- }
118
+ // Score EVERY candidate that provably resolves (first-match, uniquely) to the
119
+ // target, and take the most durable — not merely the first that resolves.
120
+ // Because each survivor already matches uniquely NOW, the choice only trades
121
+ // on FUTURE stability; it can never pick a wrong/non-resolving node.
122
+ const verified = [...candidateXPaths(el)]
123
+ .map((c, i) => ({ c, i }))
124
+ .filter(({ c }) => matchesUniquely(doc, c.xPath, el));
125
+ if (!verified.length) {
126
+ return undefined;
54
127
  }
55
- return undefined;
128
+ verified.sort((a, b) => {
129
+ return anchorStability(b.c) - anchorStability(a.c) ||
130
+ a.c.depth - b.c.depth ||
131
+ a.i - b.i;
132
+ });
133
+ // `[startIndex, endIndex)` is exactly the slice the attestor reveals for this
134
+ // xPath (its getNodeRange uses these same parse5 source locations).
135
+ return { xPath: verified[0].c.xPath, start: startIndex, end: endIndex };
56
136
  }
57
137
  /** The tightest element that DIRECTLY holds a target. Prefers a COMPLETE-value
58
138
  * occurrence — an attribute whose value IS the target, or a text child that IS
@@ -97,46 +177,119 @@ function smallestElement(els) {
97
177
  .sort((a, b) => elementSpan(a) - elementSpan(b))
98
178
  .at(0);
99
179
  }
100
- /** Candidate xPaths for `el`, best (most stable / shortest) first. */
180
+ /** Every candidate xPath for `el`, each tagged with what it anchors on. The
181
+ * caller verifies + scores them ({@link anchorStability}) rather than trusting
182
+ * emission order, so the DURABILITY winner is chosen, not the first that
183
+ * resolves. Order here is only the final tie-break. */
101
184
  function* candidateXPaths(el) {
102
185
  const tag = el.name;
103
186
  const a = el.attribs ?? {};
104
187
  if (a.id) {
105
- yield `//${tag}[@id=${xpathLiteral(a.id)}]`;
188
+ yield { xPath: `//${tag}[@id=${xpathLiteral(a.id)}]`, kind: 'id',
189
+ token: a.id, depth: 0 };
106
190
  }
107
191
  for (const name of IDENT_ATTRS) {
108
192
  if (a[name]) {
109
- yield `//${tag}[@${name}=${xpathLiteral(a[name])}]`;
110
- }
111
- }
112
- if (a.class) {
113
- const distinctive = a.class
114
- .split(/\s+/)
115
- .filter(Boolean)
116
- .sort((x, y) => y.length - x.length)[0];
117
- if (distinctive) {
118
- yield `//${tag}[contains(@class, ${xpathLiteral(distinctive)})]`;
193
+ yield { xPath: `//${tag}[@${name}=${xpathLiteral(a[name])}]`,
194
+ kind: 'ident-attr', token: a[name], depth: 0 };
119
195
  }
120
196
  }
121
197
  // A uniquely-identified DIRECT child pins the parent without a positional
122
- // path (`//span[span[@id="labels"]]`). Self-verification (firstSelected)
123
- // discards it when the child id/attr isn't unique — e.g. GitHub reuses
124
- // `id="labels"` per email row — so it never silently matches the wrong node.
198
+ // path (`//span[span[@id="labels"]]`). Self-verification discards it when the
199
+ // child id/attr isn't unique — e.g. GitHub reuses `id="labels"` per email row
200
+ // — so it never silently matches the wrong node.
125
201
  for (const child of el.children) {
126
202
  if (!isTag(child)) {
127
203
  continue;
128
204
  }
129
205
  const ca = child.attribs ?? {};
130
206
  if (ca.id) {
131
- yield `//${tag}[${child.name}[@id=${xpathLiteral(ca.id)}]]`;
207
+ yield { xPath: `//${tag}[${child.name}[@id=${xpathLiteral(ca.id)}]]`,
208
+ kind: 'id', token: ca.id, depth: 0 };
132
209
  }
133
210
  for (const name of IDENT_ATTRS) {
134
211
  if (ca[name]) {
135
- yield `//${tag}[${child.name}[@${name}=${xpathLiteral(ca[name])}]]`;
212
+ yield {
213
+ xPath: `//${tag}[${child.name}[@${name}=${xpathLiteral(ca[name])}]]`,
214
+ kind: 'ident-attr', token: ca[name], depth: 0,
215
+ };
136
216
  }
137
217
  }
138
218
  }
139
- yield absolutePath(el);
219
+ // The value element's own distinctive class.
220
+ const distinctive = distinctiveClass(a.class);
221
+ if (distinctive) {
222
+ yield { xPath: `//${tag}[contains(@class, ${xpathLiteral(distinctive)})]`,
223
+ kind: 'class', token: distinctive, depth: 0 };
224
+ }
225
+ // Ancestor-anchored (id/attr, then class), descending positionally to `el`.
226
+ yield* ancestorAnchoredCandidates(el);
227
+ yield { xPath: absolutePath(el), kind: 'positional', depth: 99 };
228
+ }
229
+ /** The longest whitespace-delimited token of a class attribute (the most
230
+ * distinctive one), or undefined when there's no class. */
231
+ function distinctiveClass(cls) {
232
+ return (cls ?? '')
233
+ .split(/\s+/)
234
+ .filter(Boolean)
235
+ .sort((x, y) => y.length - x.length)[0];
236
+ }
237
+ /** Positional path from `anc` (exclusive) down to `el` (inclusive), e.g.
238
+ * `/ul[1]/li[3]/a[1]`; empty string when `anc` is not an ancestor of `el`. */
239
+ function relativeSteps(anc, el) {
240
+ const parts = [];
241
+ let node = el;
242
+ while (node && isTag(node) && node !== anc) {
243
+ const tag = node.name;
244
+ let index = 1;
245
+ for (let sib = node.prev; sib; sib = sib.prev) {
246
+ if (isTag(sib) && sib.name === tag) {
247
+ index++;
248
+ }
249
+ }
250
+ parts.unshift(`/${tag}[${index}]`);
251
+ node = node.parent;
252
+ }
253
+ return node === anc ? parts.join('') : '';
254
+ }
255
+ /** Ancestors of `el` (nearest first) with their depth, skipping
256
+ * `html`/`body`/`head` (≈ the absolute path) and non-ancestors. Capped depth
257
+ * keeps paths short. */
258
+ function* anchorAncestors(el) {
259
+ let depth = 1;
260
+ for (let anc = el.parent; anc && isTag(anc) && depth <= 10; anc = anc.parent, depth++) {
261
+ const tag = anc.name;
262
+ if (tag === 'html' || tag === 'body' || tag === 'head') {
263
+ continue;
264
+ }
265
+ const rel = relativeSteps(anc, el);
266
+ if (rel) {
267
+ yield { tag, attribs: anc.attribs ?? {}, rel, depth };
268
+ }
269
+ }
270
+ }
271
+ /** Ancestor-anchored candidates, descending positionally to `el`
272
+ * (`//div[@id="nav"]/ul[1]/li[1]/a[1]`): an id / identifying-attr or a
273
+ * distinctive-class anchor per ancestor, tagged with its kind + depth so the
274
+ * scorer weighs a stable ancestor id above the value's own utility class. */
275
+ function* ancestorAnchoredCandidates(el) {
276
+ for (const { tag, attribs, rel, depth } of anchorAncestors(el)) {
277
+ if (attribs.id) {
278
+ yield { xPath: `//${tag}[@id=${xpathLiteral(attribs.id)}]${rel}`,
279
+ kind: 'id', token: attribs.id, depth };
280
+ }
281
+ for (const name of IDENT_ATTRS) {
282
+ if (attribs[name]) {
283
+ const xp = `//${tag}[@${name}=${xpathLiteral(attribs[name])}]${rel}`;
284
+ yield { xPath: xp, kind: 'ident-attr', token: attribs[name], depth };
285
+ }
286
+ }
287
+ const dc = distinctiveClass(attribs.class);
288
+ if (dc) {
289
+ yield { xPath: `//${tag}[contains(@class, ${xpathLiteral(dc)})]${rel}`,
290
+ kind: 'class', token: dc, depth };
291
+ }
292
+ }
140
293
  }
141
294
  /** Chrome "full XPath"-style absolute path: `/html[1]/body[1]/…/tag[n]`, where
142
295
  * n is the element's 1-based position among same-tag siblings. */
@@ -1,4 +1,10 @@
1
1
  import type { CapturedRequest, OprfMode, ReclaimProvider, ResponseMatch, ResponseRedaction, SecretParamRef } from './schema.ts';
2
+ /** OPRF mode to apply when the caller passed none: the anti-leak floor —
3
+ * force-hash a value whose SHAPE is unambiguous PII, but ONLY when it's
4
+ * OPRF-hashable AND within the 62-byte MPC-circuit cap (UTF-8). Undefined =
5
+ * leave plaintext (a longer value can't be OPRF'd; contextual PII + the proven
6
+ * identity are the model's/plaintext call). */
7
+ export declare function defaultSensitiveHash(value: string): OprfMode | undefined;
2
8
  /** One value to extract from the request: the captured `value`, a `name` (its
3
9
  * param / capture-group), and an optional per-target OPRF `hash`. */
4
10
  export interface DraftTarget {
@@ -1,6 +1,35 @@
1
- import { synthesizeMatcher } from "./matcher.js";
1
+ import { isOprfHashable, OPRF_MAX_BYTES, synthesizeMatcher } from "./matcher.js";
2
2
  import { splitSecrets } from "./secrets.js";
3
- /** Request headers that must NOT survive into the provider params. Two kinds:
3
+ /** OPRF mode for the auto-hash floor — TEE-native (attestor rejects oprf-raw,
4
+ * isn't set up for gnark oprf). */
5
+ const DEFAULT_SENSITIVE_HASH = 'oprf-mpc';
6
+ // The deterministic ANTI-LEAK FLOOR: values whose SHAPE is unambiguously
7
+ // sensitive PII, force-hashed no matter the field name or the model's judgment.
8
+ // Deliberately only FIXED-FORMAT identifiers — OPRF is byte-exact, so a
9
+ // self-mutable value (a display name re-cased) would be grindable and pointless
10
+ // to hash; and a bare number is ambiguous (a private account id vs a PUBLIC
11
+ // user id / follower count that's meant to be proven in the clear). Those
12
+ // contextual calls are the model's, via an explicit per-target `hash`. This
13
+ // floor is universal (not domain-specific) and high-precision.
14
+ const EMAIL_VALUE = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
15
+ const SSN_VALUE = /^\d{3}-\d{2}-\d{4}$/;
16
+ const IBAN_VALUE = /^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/;
17
+ function isCanonicalPii(value) {
18
+ return EMAIL_VALUE.test(value)
19
+ || SSN_VALUE.test(value) || IBAN_VALUE.test(value);
20
+ }
21
+ /** OPRF mode to apply when the caller passed none: the anti-leak floor —
22
+ * force-hash a value whose SHAPE is unambiguous PII, but ONLY when it's
23
+ * OPRF-hashable AND within the 62-byte MPC-circuit cap (UTF-8). Undefined =
24
+ * leave plaintext (a longer value can't be OPRF'd; contextual PII + the proven
25
+ * identity are the model's/plaintext call). */
26
+ export function defaultSensitiveHash(value) {
27
+ const hashable = isCanonicalPii(value)
28
+ && isOprfHashable(value)
29
+ && Buffer.byteLength(value, 'utf8') <= OPRF_MAX_BYTES;
30
+ return hashable ? DEFAULT_SENSITIVE_HASH : undefined;
31
+ }
32
+ /** Request headers that must NOT survive into the provider params. Three kinds:
4
33
  * - Conditional headers (`if-none-match`/`if-modified-since`/…): a captured
5
34
  * cached ETag/date makes the origin answer 304/412 when the attestor
6
35
  * re-issues, and the attestor treats non-2xx as failure. We always want the
@@ -8,7 +37,14 @@ import { splitSecrets } from "./secrets.js";
8
37
  * - Transfer headers the ATTESTOR sets itself (`connection: close`,
9
38
  * `accept-encoding: identity`). Passing our own duplicates/collides with the
10
39
  * request the attestor builds, so leave them out — the attestor already
11
- * forces `identity` (uncompressed, so its byte-matching works). */
40
+ * forces `identity` (uncompressed, so its byte-matching works).
41
+ * - Host / framing headers the TRANSPORT owns (`host`, `content-length`,
42
+ * `transfer-encoding`) and HTTP/2 pseudo-headers (`:authority`/`:method`/…,
43
+ * which CDP surfaces on h2 captures). The attestor derives `Host` from the
44
+ * URL and sets its own; a baked `Host` produces a DUPLICATE
45
+ * (`found: h,h`) that fails the receipt check / 400s the origin. A stale
46
+ * `content-length` breaks a re-serialized body. Pseudo-headers aren't valid
47
+ * real headers at all. */
12
48
  const STRIP_REQUEST_HEADERS = new Set([
13
49
  'if-none-match',
14
50
  'if-modified-since',
@@ -17,14 +53,22 @@ const STRIP_REQUEST_HEADERS = new Set([
17
53
  'if-range',
18
54
  'connection',
19
55
  'accept-encoding',
56
+ 'host',
57
+ 'content-length',
58
+ 'transfer-encoding',
20
59
  ]);
60
+ /** True for an HTTP/2 pseudo-header (`:authority`, `:method`, `:path`,
61
+ * `:scheme`) — never a valid request header the attestor can replay. */
62
+ function isPseudoHeader(name) {
63
+ return name.startsWith(':');
64
+ }
21
65
  /** Drop the headers the attestor manages or that would 304 at proof time
22
66
  * (see {@link STRIP_REQUEST_HEADERS}); keep every other captured header so the
23
67
  * attestor's replay looks like the browser's request. */
24
68
  function sanitizeRequestHeaders(headers) {
25
69
  const out = {};
26
70
  for (const [k, v] of Object.entries(headers)) {
27
- if (STRIP_REQUEST_HEADERS.has(k.toLowerCase())) {
71
+ if (STRIP_REQUEST_HEADERS.has(k.toLowerCase()) || isPseudoHeader(k)) {
28
72
  continue;
29
73
  }
30
74
  out[k] = v;
@@ -103,7 +147,12 @@ export function draftProvider(req, targets, name, hash) {
103
147
  + 'give them distinct names');
104
148
  }
105
149
  seenParams.add(paramName);
106
- const synthesis = synthesizeMatcher(req.responseBody, req.contentType, t.value, paramName, t.hash ?? hash);
150
+ // Precedence: explicit per-target hash → explicit request-wide hash →
151
+ // the anti-leak floor (force-OPRF values whose SHAPE is unambiguous PII).
152
+ // The model makes the contextual calls (which named fields are sensitive)
153
+ // via an explicit per-target hash; this floor only guarantees the obvious.
154
+ const effectiveHash = t.hash ?? hash ?? defaultSensitiveHash(t.value);
155
+ const synthesis = synthesizeMatcher(req.responseBody, req.contentType, t.value, paramName, effectiveHash);
107
156
  if (!synthesis) {
108
157
  throw new Error(`target value "${t.value}" not found in`
109
158
  + ` response body for request ${req.requestId}`);
@@ -31,3 +31,7 @@ export interface MatcherSynthesis {
31
31
  * proof time. Throws when `hash` is set on a free-form value (no safe class).
32
32
  */
33
33
  export declare function synthesizeMatcher(body: string, contentType: string, target: string, paramName: string, hash?: OprfMode): MatcherSynthesis | undefined;
34
+ /** True when `target` has a character class safe to OPRF-hash. Free-form values
35
+ * (names with spaces, arbitrary unicode/punctuation) return false — the caller
36
+ * must NOT default them to a hash (it would throw in synthesizeMatcher). */
37
+ export declare function isOprfHashable(target: string): boolean;
@@ -548,3 +548,9 @@ function inferValueClass(target) {
548
548
  }
549
549
  return undefined;
550
550
  }
551
+ /** True when `target` has a character class safe to OPRF-hash. Free-form values
552
+ * (names with spaces, arbitrary unicode/punctuation) return false — the caller
553
+ * must NOT default them to a hash (it would throw in synthesizeMatcher). */
554
+ export function isOprfHashable(target) {
555
+ return inferValueClass(target) !== undefined;
556
+ }
@@ -25,6 +25,19 @@ export interface AllowedJsRequest extends DraftRequest {
25
25
  multiple?: boolean;
26
26
  /** Fail validation if no request matches this template. Default true. */
27
27
  required?: boolean;
28
+ /** Names of `${var}` placeholders in this template's `responseMatches`/
29
+ * `responseRedactions` that get substituted at verify time from the
30
+ * submitted proof's own witness params (e.g. an index list a
31
+ * `Reclaim.requestClaim` call attached alongside its `{{var}}`
32
+ * extractions). Omit (or leave empty) when the template has no such
33
+ * placeholders — verification then matches it literally as-is. */
34
+ templateParams?: string[];
35
+ /** How multiple values for `templateParams` expand into request specs.
36
+ * `'separate'` (default): one independent spec per value, each expected
37
+ * to match its own proof. `'merge'`: all values folded into ONE spec
38
+ * with one `responseMatches`/`responseRedactions` entry per value,
39
+ * matching a single proof that bundles them all into one claim. */
40
+ templateParamsMode?: 'separate' | 'merge';
28
41
  }
29
42
  /** Optional extras for a create-version body beyond the request list. */
30
43
  export interface CreateVersionOptions {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reclaimprotocol/agent",
3
3
  "title": "Reclaim Agent",
4
- "version": "0.1.10",
4
+ "version": "0.1.11",
5
5
  "description": "Reclaim Protocol's tools for agents — Reclaim Protocol lets your app verify **data points** about its users — a follower count, an account balance, an order history. This package gives your AI coding agent the tools to **find, build, test and fix the _data verification providers_** (the recipes that verify a data point) by inspecting and replaying captured requests, checking sessions, evaluate proofs, publishing updates, and much more.",
6
6
  "type": "module",
7
7
  "main": "./lib/index.js",
@@ -205,6 +205,82 @@ export function authoringTools(
205
205
  }))
206
206
  },
207
207
  ),
208
+ defineTool<Record<string, unknown>>(
209
+ {
210
+ name: 'wait_for_login',
211
+ description:
212
+ 'Wait for the user to finish logging in. Polls the browser\'s '
213
+ + 'REAL cookies over CDP (httpOnly INCLUDED) until a NEW session '
214
+ + 'cookie appears, ignoring analytics/bot cookies. The ONLY '
215
+ + 'correct login wait — NEVER use wait_for_page for it: page JS '
216
+ + 'can\'t see the httpOnly session cookie (hangs the whole '
217
+ + 'timeout), yet DOES see pre-login tracking cookies (a '
218
+ + 'length/substring check fires instantly, before the user '
219
+ + 'types). Snapshots the baseline itself — call right after '
220
+ + 'navigating to the login page. Does NOT navigate (never yanks '
221
+ + 'the user off login/2FA). Returns { loggedIn, newCookies }.',
222
+ inputSchema: objectSchema({ timeoutMs: { type: 'number' } }),
223
+ },
224
+ async(args) => {
225
+ const backend = resolveBackend(args)
226
+ const deadline = Date.now() + (Number(args.timeoutMs) || 180_000)
227
+ const cookies = async() => {
228
+ const res = (await backend.sendCdp('Network.getCookies')) as {
229
+ cookies?: { name: string, httpOnly?: boolean }[]
230
+ }
231
+ return res.cookies ?? []
232
+ }
233
+
234
+ // Analytics / bot-protection / pre-auth infra cookies appear (and
235
+ // rotate) without any login — never the signal, even when new.
236
+ const JUNK = new RegExp('^(' + [
237
+ '_ga', '_gid', '_gat', '_ym', '__ddg', '__gads', '__gpi', '__eoi',
238
+ '__utm', '_fbp', 'fbp', 'fr', 'FCCDCF', 'pinLogger',
239
+ 'userFirstVisit', 'cf_', '_dd_', 'bcookie', 'bscookie', 'lidc',
240
+ ].join('|') + ')', 'i')
241
+ // A real session/auth cookie name. Deliberately NOT bare `token` — a
242
+ // challenge/CSRF token (e.g. LinkedIn `chp_token`) contains it and is
243
+ // set BEFORE auth completes. Any new httpOnly cookie is also a
244
+ // candidate (server-set session cookies are usually httpOnly).
245
+ const SESSION = /sess|sid|jwt|_session|auth|logged.?in|remember|li_at/i
246
+ // Auth/challenge URL paths — while the page is still on one, login is
247
+ // NOT done (a mid-flow cookie must not count). Cross-site-stable, far
248
+ // more so than cookie names.
249
+ const AUTH_URL = new RegExp([
250
+ 'login', 'signin', 'sign-in', 'challenge', 'checkpoint', '\\buas\\b',
251
+ 'authorize', '\\bsso\\b', 'mfa', '2fa', 'two-factor', 'otp', 'verify',
252
+ 'password',
253
+ ].join('|'), 'i')
254
+ const offAuthUrl = async() => {
255
+ const { value } = await evalInPage(backend, 'location.href')
256
+ const href = typeof value === 'string' ? value : ''
257
+ try {
258
+ const u = new URL(href)
259
+ return !AUTH_URL.test(u.pathname + u.search)
260
+ } catch{
261
+ return false
262
+ }
263
+ }
264
+
265
+ const initial = await cookies()
266
+ const baseline = new Set(initial.map((c) => c.name))
267
+ while(Date.now() < deadline) {
268
+ const current = await cookies()
269
+ const fresh = current
270
+ .filter((c) => !baseline.has(c.name) && !JUNK.test(c.name))
271
+ const hit = fresh.filter((c) => c.httpOnly || SESSION.test(c.name))
272
+ // BOTH required: a new session cookie AND the page has left the auth
273
+ // flow. Either alone false-positives (mid-flow token; stray nav).
274
+ if(hit.length && await offAuthUrl()) {
275
+ return { loggedIn: true, newCookies: hit.map((c) => c.name) }
276
+ }
277
+
278
+ await sleep(1000)
279
+ }
280
+
281
+ return { loggedIn: false, newCookies: [] }
282
+ },
283
+ ),
208
284
  defineTool<Record<string, unknown>>(
209
285
  {
210
286
  name: 'list_requests',
@@ -21,7 +21,12 @@ export function findTool(resolveBackend: ResolveBackend): RegisteredTool {
21
21
  'Search captured responses for any encoding of `value` (raw, '
22
22
  + 'URL/JSON/HTML-escaped, …). Returns a ranked candidate list with '
23
23
  + 'the matched variant, score, and a short snippet — used to locate '
24
- + 'the request that returns a target. Server-side; bodies stay here.',
24
+ + 'the request that returns a target. Also finds SPLIT matches: when '
25
+ + '`value` is multi-word (e.g. a full name), a response that carries '
26
+ + 'every word SEPARATELY (a JSON profile API with first/last name in '
27
+ + 'distinct fields) is returned with `splitMatch:true` — prove those '
28
+ + 'per-field (a redaction per part) rather than as one string. '
29
+ + 'Server-side; bodies stay here.',
25
30
  inputSchema: objectSchema(
26
31
  { value: { type: 'string' }, limit: { type: 'number' } },
27
32
  ['value'],
@@ -29,37 +34,60 @@ export function findTool(resolveBackend: ResolveBackend): RegisteredTool {
29
34
  },
30
35
  async(args) => {
31
36
  const backend = resolveBackend(args)
32
- const variants = normalizeCandidates(String(args.value))
37
+ const value = String(args.value)
38
+ const variants = normalizeCandidates(value)
39
+ // Name-part tokens (≥3 chars) for split-field detection — a JSON API
40
+ // often carries a full name as separate first/last fields, so the whole
41
+ // string never matches even though the value IS there.
42
+ const tokens = value.split(/\s+/).filter((t) => t.length >= 3)
43
+ const snip = (body: string, idx: number, len: number) => {
44
+ const s = Math.max(0, idx - 40)
45
+
46
+ return body.slice(s, Math.min(body.length, idx + len + 40))
47
+ }
48
+
33
49
  const ranked = []
34
50
  for(const r of backend.capture.requests.values()) {
35
51
  if(!r.responseBody) {
36
52
  continue
37
53
  }
38
54
 
55
+ const body = r.responseBody
56
+ // Prefer JSON responses + smaller bodies (likely API endpoints).
57
+ const base = (r.contentType.includes('json') ? 10 : 0)
58
+ + Math.max(0, 5 - Math.log10(Math.max(r.size, 1)))
59
+
39
60
  let hit: { snippet: string, variant: string } | undefined
40
61
  for(const v of variants) {
41
- const idx = r.responseBody.indexOf(v)
62
+ const idx = body.indexOf(v)
42
63
  if(idx >= 0) {
43
- const start = Math.max(0, idx - 40)
44
- const end = Math.min(r.responseBody.length, idx + v.length + 40)
45
- hit = { snippet: r.responseBody.slice(start, end), variant: v }
64
+ hit = { snippet: snip(body, idx, v.length), variant: v }
46
65
  break
47
66
  }
48
67
  }
49
68
 
50
- if(!hit) {
69
+ if(hit) {
70
+ // Whole-value match — ranked above split matches (+5).
71
+ ranked.push({
72
+ ...publicRequest(r),
73
+ matchedVariant: hit.variant,
74
+ snippet: hit.snippet,
75
+ score: base + 5,
76
+ })
51
77
  continue
52
78
  }
53
79
 
54
- // Prefer JSON responses + smaller bodies (likely API endpoints).
55
- const score = (r.contentType.includes('json') ? 10 : 0)
56
- + Math.max(0, 5 - Math.log10(Math.max(r.size, 1)))
57
- ranked.push({
58
- ...publicRequest(r),
59
- matchedVariant: hit.variant,
60
- snippet: hit.snippet,
61
- score,
62
- })
80
+ // Split match: every word present separately (e.g. first/last name
81
+ // in distinct JSON fields). Requires ≥2 tokens so it's specific.
82
+ if(tokens.length >= 2 && tokens.every((t) => body.includes(t))) {
83
+ ranked.push({
84
+ ...publicRequest(r),
85
+ matchedVariant: `split:${tokens.join('+')}`,
86
+ splitMatch: true,
87
+ snippet: snip(body, body.indexOf(tokens[0]), tokens[0].length),
88
+ score: base,
89
+ })
90
+ }
63
91
  }
64
92
 
65
93
  ranked.sort((a, b) => b.score - a.score)
@@ -83,12 +83,12 @@ export function proposeTool(resolveBackend: ResolveBackend): RegisteredTool {
83
83
  }
84
84
 
85
85
  for(const t of targets) {
86
- if((t.hash ?? defaultHash) !== undefined
87
- && t.value.length > OPRF_MAX_BYTES) {
86
+ const bytes = Buffer.byteLength(t.value, 'utf8')
87
+ if((t.hash ?? defaultHash) !== undefined && bytes > OPRF_MAX_BYTES) {
88
88
  throw new Error(
89
89
  `OPRF caps hashed values at ${OPRF_MAX_BYTES} bytes; got `
90
- + `${t.value.length}-byte "${t.value}". Use a tighter `
91
- + 'target or drop `hash`.',
90
+ + `${bytes}-byte "${t.value}". Use a tighter target or drop `
91
+ + '`hash`.',
92
92
  )
93
93
  }
94
94
  }
package/src/old/client.ts CHANGED
@@ -147,24 +147,6 @@ export class ReclaimOldClient {
147
147
  )
148
148
  }
149
149
 
150
- /** Full `providerConfig` (loginUrl, customInjection, requestData, ...) for
151
- * one version — the latest when `version` is omitted. Readable for ANY
152
- * non-archived provider (not owner-restricted), same as the dashboard's
153
- * edit-form prefill fetch. */
154
- getProviderConfig(
155
- providerId: string,
156
- version?: string,
157
- ): Promise<unknown> {
158
- return this.#request(
159
- 'GET',
160
- `/providers/${encodeURIComponent(providerId)}/config`,
161
- {
162
- auth: true,
163
- query: version ? { versionNumber: version } : undefined,
164
- },
165
- )
166
- }
167
-
168
150
  /** Partial update on the PROVIDER document itself — name/description/
169
151
  * providerType/tags/isActive, after creation. The backend 403s if you
170
152
  * don't own the provider (and aren't admin); other providerConfig-style
@@ -93,6 +93,8 @@ interface OldRequestData {
93
93
  export interface OldInjectedRequestData extends OldRequestData {
94
94
  required?: boolean
95
95
  multiple?: boolean
96
+ templateParams?: string[]
97
+ templateParamsMode?: 'separate' | 'merge'
96
98
  }
97
99
 
98
100
  /** Build the single `requestData` entry shared by register + update. Takes
@@ -200,11 +202,15 @@ function requestDataFrom(providers: ReclaimProvider[]): OldRequestData[] {
200
202
  export function injectedRequestDataFrom(
201
203
  requests: AllowedJsRequest[],
202
204
  ): OldInjectedRequestData[] {
203
- return requests.map((req) => ({
204
- ...requestDataFromProvider(req),
205
- required: req.required ?? true,
206
- multiple: req.multiple ?? true,
207
- }))
205
+ return requests.map((req) => {
206
+ return {
207
+ ...requestDataFromProvider(req),
208
+ required: req.required ?? true,
209
+ multiple: req.multiple ?? true,
210
+ templateParams: req.templateParams,
211
+ templateParamsMode: req.templateParamsMode,
212
+ }
213
+ })
208
214
  }
209
215
 
210
216
  /** Body for `POST /api/providers/register` — new provider + v1.0.0. Every