@reclaimprotocol/agent 0.1.5 → 0.1.7

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 (117) hide show
  1. package/lib/authoring/backend.d.ts +0 -24
  2. package/lib/authoring/find.d.ts +3 -0
  3. package/lib/authoring/find.js +54 -0
  4. package/lib/authoring/index.d.ts +3 -3
  5. package/lib/authoring/index.js +4 -3
  6. package/lib/authoring/propose.d.ts +3 -0
  7. package/lib/authoring/propose.js +109 -0
  8. package/lib/authoring/replay.d.ts +10 -0
  9. package/lib/authoring/replay.js +34 -0
  10. package/lib/authoring/tools.d.ts +13 -6
  11. package/lib/authoring/tools.js +108 -293
  12. package/lib/authoring/util.d.ts +27 -0
  13. package/lib/authoring/util.js +21 -0
  14. package/lib/consts.d.ts +6 -1
  15. package/lib/consts.js +9 -2
  16. package/lib/mcp/server.d.ts +2 -41
  17. package/lib/mcp/server.js +6 -34
  18. package/lib/mcp/start.js +4 -2
  19. package/lib/mcp/tools/agent/analyze.js +3 -3
  20. package/lib/mcp/tools/agent/build.d.ts +4 -4
  21. package/lib/mcp/tools/agent/build.js +13 -15
  22. package/lib/mcp/tools/agent/capture.d.ts +13 -1
  23. package/lib/mcp/tools/agent/capture.js +18 -85
  24. package/lib/mcp/tools/agent/eval.d.ts +5 -2
  25. package/lib/mcp/tools/agent/eval.js +11 -121
  26. package/lib/mcp/tools/agent/find.d.ts +10 -3
  27. package/lib/mcp/tools/agent/find.js +25 -31
  28. package/lib/mcp/tools/agent/proof.d.ts +13 -3
  29. package/lib/mcp/tools/agent/proof.js +81 -132
  30. package/lib/mcp/tools/agent/propose.d.ts +10 -9
  31. package/lib/mcp/tools/agent/propose.js +87 -64
  32. package/lib/mcp/tools/agent/replay.d.ts +10 -3
  33. package/lib/mcp/tools/agent/replay.js +29 -36
  34. package/lib/mcp/tools/agent/session.d.ts +1 -3
  35. package/lib/mcp/tools/agent/session.js +5 -5
  36. package/lib/mcp/tools/agent/shared.d.ts +5 -3
  37. package/lib/mcp/tools/agent/shared.js +29 -19
  38. package/lib/old/client.d.ts +39 -0
  39. package/lib/old/client.js +18 -0
  40. package/lib/old/login-cdp.d.ts +24 -5
  41. package/lib/old/login-cdp.js +29 -15
  42. package/lib/old/sdk-client.d.ts +39 -0
  43. package/lib/old/sdk-client.js +85 -0
  44. package/lib/old/to-register.d.ts +69 -0
  45. package/lib/old/to-register.js +55 -2
  46. package/lib/old/tools/authenticate.js +3 -7
  47. package/lib/old/tools/build.d.ts +6 -1
  48. package/lib/old/tools/build.js +11 -1
  49. package/lib/old/tools/get-provider-info.d.ts +16 -0
  50. package/lib/old/tools/get-provider-info.js +73 -0
  51. package/lib/old/tools/get-version-config.d.ts +17 -0
  52. package/lib/old/tools/get-version-config.js +47 -0
  53. package/lib/old/tools/publish.js +208 -2
  54. package/lib/old/tools/update-provider-metadata.d.ts +16 -0
  55. package/lib/old/tools/update-provider-metadata.js +61 -0
  56. package/lib/proof/attestor.d.ts +6 -3
  57. package/lib/proof/attestor.js +10 -1
  58. package/lib/proof/debug-response-dump.d.ts +4 -0
  59. package/lib/proof/debug-response-dump.js +55 -0
  60. package/lib/proof/patch-domhandler.d.ts +1 -0
  61. package/lib/proof/patch-domhandler.js +59 -0
  62. package/lib/proof/zk-files.js +7 -6
  63. package/lib/provider/dom-xpath.d.ts +17 -0
  64. package/lib/provider/dom-xpath.js +187 -0
  65. package/lib/provider/draft.d.ts +30 -2
  66. package/lib/provider/draft.js +117 -28
  67. package/lib/provider/index.d.ts +4 -0
  68. package/lib/provider/index.js +7 -0
  69. package/lib/provider/injection-doc.js +6 -0
  70. package/lib/provider/matcher.d.ts +17 -20
  71. package/lib/provider/matcher.js +394 -280
  72. package/lib/provider/schema.d.ts +7 -5
  73. package/lib/tools/registry.d.ts +14 -0
  74. package/lib/tools/registry.js +32 -0
  75. package/package.json +9 -1
  76. package/skill/SKILL.builder.md +42 -23
  77. package/skill/SKILL.old.md +6 -2
  78. package/skill/builder-mode.md +1 -1
  79. package/skill/injection-api.md +117 -0
  80. package/src/authoring/backend.ts +98 -0
  81. package/src/authoring/index.ts +20 -0
  82. package/src/authoring/tools.ts +273 -0
  83. package/src/authoring/util.ts +42 -0
  84. package/src/consts.ts +15 -2
  85. package/src/mcp/server.ts +11 -78
  86. package/src/mcp/start.ts +4 -1
  87. package/src/mcp/tools/agent/analyze.ts +3 -3
  88. package/src/mcp/tools/agent/build.ts +13 -21
  89. package/src/mcp/tools/agent/capture.ts +31 -115
  90. package/src/mcp/tools/agent/eval.ts +19 -155
  91. package/src/mcp/tools/agent/find.ts +33 -36
  92. package/src/mcp/tools/agent/proof.ts +87 -160
  93. package/src/mcp/tools/agent/propose.ts +93 -85
  94. package/src/mcp/tools/agent/replay.ts +32 -42
  95. package/src/mcp/tools/agent/session.ts +4 -5
  96. package/src/mcp/tools/agent/shared.ts +152 -0
  97. package/src/old/client.ts +60 -0
  98. package/src/old/login-cdp.ts +29 -23
  99. package/src/old/sdk-client.ts +105 -0
  100. package/src/old/to-register.ts +102 -6
  101. package/src/old/tools/authenticate.ts +3 -11
  102. package/src/old/tools/build.ts +12 -0
  103. package/src/old/tools/get-provider-info.ts +91 -0
  104. package/src/old/tools/get-version-config.ts +56 -0
  105. package/src/old/tools/publish.ts +264 -1
  106. package/src/old/tools/update-provider-metadata.ts +72 -0
  107. package/src/proof/attestor.ts +16 -4
  108. package/src/proof/debug-response-dump.ts +70 -0
  109. package/src/proof/patch-domhandler.ts +68 -0
  110. package/src/proof/zk-files.ts +7 -6
  111. package/src/provider/dom-xpath.ts +225 -0
  112. package/src/provider/draft.ts +168 -35
  113. package/src/provider/index.ts +8 -0
  114. package/src/provider/injection-doc.ts +6 -0
  115. package/src/provider/matcher.ts +477 -357
  116. package/src/provider/schema.ts +7 -5
  117. package/src/tools/registry.ts +92 -0
@@ -0,0 +1,91 @@
1
+ import { isBoom } from '@hapi/boom'
2
+ import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
3
+ import type { ReclaimSdkClient } from '../sdk-client.ts'
4
+
5
+ /** Best-effort call: resolve to the response, or to an error string instead
6
+ * of throwing — one endpoint 404ing (e.g. a bad `versionNumber`) shouldn't
7
+ * hide a result the other endpoint DID have. */
8
+ async function attempt(
9
+ label: string,
10
+ call: () => Promise<unknown>,
11
+ ): Promise<{ ok: true, value: unknown } | { ok: false, error: string }> {
12
+ try {
13
+ return { ok: true, value: await call() }
14
+ } catch(err) {
15
+ const message = isBoom(err) ? err.message : String(err)
16
+ return { ok: false, error: `${label}: ${message}` }
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Read provider info from the PUBLIC production SDK backend
22
+ * (`api.reclaimprotocol.org`) — the service the verification SDK/attestor
23
+ * itself calls at runtime, NOT the old-devtools dashboard backend
24
+ * (`get_provider_version_config`, `devapi.reclaimprotocol.org`, requires
25
+ * auth). Both underlying reads are unauthenticated.
26
+ *
27
+ * Fetches BOTH shapes in one call, since they're complementary:
28
+ * - `provider`: full provider + providerConfig, `customInjection` included.
29
+ * - `configs`: the trimmed runtime recipe the attestor actually consumes —
30
+ * `customInjection` deliberately omitted, `isScriptRequestingClaim`
31
+ * computed instead.
32
+ */
33
+ export function getProviderInfoTool(client: ReclaimSdkClient): RegisteredTool {
34
+ return defineTool<{ providerId: string, versionNumber?: string }>(
35
+ {
36
+ name: 'get_provider_info',
37
+ description:
38
+ 'Read a PUBLISHED provider from the public production SDK backend ' +
39
+ '(api.reclaimprotocol.org — what the verification SDK/attestor ' +
40
+ 'itself fetches at runtime), for ANY provider, no auth required. ' +
41
+ 'Different from get_provider_version_config, which reads the old ' +
42
+ 'devtools DASHBOARD backend and requires auth. \n\n' +
43
+ 'Returns two complementary reads for the given version (latest ' +
44
+ 'when `versionNumber` is omitted): `provider` (the full provider ' +
45
+ '+ providerConfig, including `customInjection`) and `configs` (the ' +
46
+ 'trimmed recipe the attestor actually consumes — `customInjection` ' +
47
+ 'is deliberately OMITTED there, replaced by a computed ' +
48
+ '`isScriptRequestingClaim` flag). One endpoint failing (e.g. an ' +
49
+ 'invalid `versionNumber`) is reported under `errors` without ' +
50
+ 'hiding a result the other endpoint did return.',
51
+ inputSchema: {
52
+ type: 'object',
53
+ properties: {
54
+ providerId: {
55
+ type: 'string',
56
+ description: 'UUID of the provider.',
57
+ },
58
+ versionNumber: {
59
+ type: 'string',
60
+ description:
61
+ 'Specific version, e.g. "1.0.2". Omit for the ' +
62
+ "provider's current latest version.",
63
+ },
64
+ },
65
+ required: ['providerId'],
66
+ },
67
+ },
68
+ async({ providerId, versionNumber }) => {
69
+ const [provider, configs] = await Promise.all([
70
+ attempt(
71
+ 'provider',
72
+ () => client.getProvider(providerId, versionNumber),
73
+ ),
74
+ attempt(
75
+ 'configs',
76
+ () => client.getProviderConfigs(providerId, versionNumber),
77
+ ),
78
+ ])
79
+
80
+ const errors = [provider, configs]
81
+ .filter((r) => !r.ok)
82
+ .map((r) => (r as { error: string }).error)
83
+
84
+ return {
85
+ ...(provider.ok ? { provider: provider.value } : {}),
86
+ ...(configs.ok ? { configs: configs.value } : {}),
87
+ ...(errors.length ? { errors } : {}),
88
+ }
89
+ },
90
+ )
91
+ }
@@ -0,0 +1,56 @@
1
+ import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
2
+ import type { ReclaimOldClient } from '../client.ts'
3
+
4
+ /**
5
+ * Read the full `providerConfig` (loginUrl, customInjection, requestData,
6
+ * geoLocation, ...) of one provider version on the old devtools backend —
7
+ * the latest version when `version` is omitted.
8
+ *
9
+ * Exists so a dev/agent can see what's CURRENTLY published before adding a
10
+ * new version with `create_provider_version_from_capture`. That tool always
11
+ * takes a FULL replacement `providerConfig` (no partial-patch endpoint on
12
+ * this backend), so a version added without knowing the current
13
+ * `customInjection` would silently publish it blank — wiping a working
14
+ * login script instead of preserving it. Read it here first, then pass it
15
+ * straight through (or omit `customInjection` on publish to have it carried
16
+ * forward automatically).
17
+ */
18
+ export function getProviderVersionConfigTool(
19
+ client: ReclaimOldClient,
20
+ ): RegisteredTool {
21
+ return defineTool<{ providerId: string, version?: string }>(
22
+ {
23
+ name: 'get_provider_version_config',
24
+ description:
25
+ 'Fetch the full providerConfig (loginUrl, customInjection, ' +
26
+ 'requestData, geoLocation, ...) of one version on the old devtools ' +
27
+ 'backend — the latest version when `version` is omitted. Readable ' +
28
+ 'for any non-archived provider, not just ones you own. Use this ' +
29
+ 'BEFORE calling create_provider_version_from_capture with a ' +
30
+ '`providerId` to see the currently-published customInjection/' +
31
+ 'requestData so you know what you would be changing — that tool ' +
32
+ 'replaces the whole providerConfig, so a field you never see and ' +
33
+ "never pass comes out blank in the new version, even if it's set " +
34
+ 'today.',
35
+ inputSchema: {
36
+ type: 'object',
37
+ properties: {
38
+ providerId: {
39
+ type: 'string',
40
+ description: 'UUID of the provider (from get_me_providers).',
41
+ },
42
+ version: {
43
+ type: 'string',
44
+ description:
45
+ 'Specific version to fetch, e.g. "1.0.2". Omit for the ' +
46
+ "provider's current latest version.",
47
+ },
48
+ },
49
+ required: ['providerId'],
50
+ },
51
+ },
52
+ async({ providerId, version }) => {
53
+ return client.getProviderConfig(providerId, version)
54
+ },
55
+ )
56
+ }
@@ -1,14 +1,18 @@
1
1
  import { Boom, isBoom } from '@hapi/boom'
2
2
  import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
3
+ import { INJECTION_GUIDE } from '../../provider/injection-doc.ts'
3
4
  import {
4
5
  countsFor,
5
6
  matchRedactionWarnings,
6
7
  } from '../../provider/match-redaction-warning.ts'
7
8
  import type { ReclaimProvider } from '../../provider/schema.ts'
9
+ import type { AllowedJsRequest } from '../../provider/to-version.ts'
8
10
  import type { ReclaimOldClient } from '../client.ts'
9
11
  import {
10
12
  bumpPatchString,
11
13
  extractVersions,
14
+ injectedRequestDataFrom,
15
+ type OldInjectedRequestData,
12
16
  type OldProviderOpts,
13
17
  providerToConfigBody,
14
18
  providerToRegisterBody,
@@ -16,6 +20,66 @@ import {
16
20
 
17
21
  const DEFAULT_VERSION_INFO = 'Updated from MCP browser capture'
18
22
 
23
+ /** Fields with no partial-patch equivalent on this backend: a version always
24
+ * replaces the WHOLE `providerConfig`, so omitting one of these on
25
+ * add-version must carry forward the current value rather than publish it
26
+ * blank. `allowedInjectedRequestData` is handled alongside these (further
27
+ * down, inline) since it needs translation when freshly authored, unlike
28
+ * these — which pass through unchanged either way. */
29
+ const PRESERVABLE_KEYS = [
30
+ 'customInjection',
31
+ 'userAgent',
32
+ 'pageTitle',
33
+ 'stepsToFollow',
34
+ 'useIncognitoWebview',
35
+ 'extensionConfig',
36
+ ] as const
37
+
38
+ /** Pull `providerConfig` out of a `get_provider_version_config` /
39
+ * `getProviderConfig` response, tolerant of a missing/malformed shape. */
40
+ function extractProviderConfig(
41
+ resp: unknown,
42
+ ): Record<string, unknown> | undefined {
43
+ if(resp && typeof resp === 'object') {
44
+ const cfg = (resp as { providerConfig?: unknown }).providerConfig
45
+ if(cfg && typeof cfg === 'object') {
46
+ return cfg as Record<string, unknown>
47
+ }
48
+ }
49
+
50
+ return undefined
51
+ }
52
+
53
+ /** Prefer the caller's explicit value; otherwise fall back to `current`'s
54
+ * value (if any) and record `fieldName` as carried forward.
55
+ *
56
+ * `current === null` is treated the SAME as `undefined` (nothing to carry),
57
+ * not as a real value to preserve. These are all optional fields with no
58
+ * Prisma default — a version where one was never set reads back as
59
+ * `null`, not a missing key, because Prisma normalizes an absent optional
60
+ * field to `null` on read. Carrying that `null` "forward" would falsely
61
+ * claim the field was preserved when really nothing was ever there — it
62
+ * most likely means an EARLIER version already lost it (e.g. published
63
+ * before this field had carry-forward support at all), not that this call
64
+ * is doing anything wrong. */
65
+ function resolveField<T>(
66
+ explicit: T | undefined,
67
+ current: unknown,
68
+ fieldName: string,
69
+ carried: string[],
70
+ ): T | undefined {
71
+ if(explicit !== undefined) {
72
+ return explicit
73
+ }
74
+
75
+ if(current !== undefined && current !== null) {
76
+ carried.push(fieldName)
77
+ return current as T
78
+ }
79
+
80
+ return undefined
81
+ }
82
+
19
83
  /**
20
84
  * The old backend lets you add a version only to a provider YOU own. A
21
85
  * `providerId` for a public provider (or anyone else's) comes back as
@@ -71,6 +135,13 @@ export function createVersionFromCaptureTool(
71
135
  useProxy?: boolean
72
136
  providerType?: 'PRIVATE' | 'PUBLIC'
73
137
  notes?: string
138
+ customInjection?: string
139
+ userAgent?: { ios?: string, android?: string }
140
+ pageTitle?: string
141
+ allowedInjectedRequestData?: AllowedJsRequest[]
142
+ stepsToFollow?: string
143
+ useIncognitoWebview?: boolean
144
+ extensionConfig?: unknown
74
145
  }>(
75
146
  {
76
147
  name: 'create_provider_version_from_capture',
@@ -92,6 +163,29 @@ export function createVersionFromCaptureTool(
92
163
  'must come from get_me_providers. To publish your own version of a ' +
93
164
  "PUBLIC provider you don't own, omit `providerId` to register your " +
94
165
  'own copy (you cannot edit someone else\'s provider here). \n\n' +
166
+ 'For data gated behind login/navigation, pass `customInjection` — a ' +
167
+ 'page-injection script (old-devtools\' name for the builder\'s ' +
168
+ 'jsUserScripts) that drives the page to where the request fires. \n\n' +
169
+ 'This backend has NO partial-patch endpoint — adding a version ' +
170
+ 'always replaces the WHOLE providerConfig. When `providerId` is ' +
171
+ 'set, any of `customInjection`, `userAgent`, `pageTitle`, ' +
172
+ '`allowedInjectedRequestData`, `stepsToFollow`, ' +
173
+ '`useIncognitoWebview`, `extensionConfig` that you OMIT is carried ' +
174
+ 'forward unchanged from the currently-published version (so ' +
175
+ 're-publishing requestData never wipes a working login script or ' +
176
+ 'other config someone set via the dashboard). This can only carry ' +
177
+ 'forward what the CURRENT version actually has — if an earlier ' +
178
+ 'version already lost a field (e.g. published before this tool ' +
179
+ 'carried it forward at all), there is nothing left to preserve and ' +
180
+ 'the result legitimately comes back empty/null for that field; ' +
181
+ 'that is not this call failing to carry it forward. Pass an ' +
182
+ 'explicit value (`""`, `[]`, `false`, ...) to intentionally clear ' +
183
+ 'one of them instead, or call get_provider_version_config FIRST ' +
184
+ 'to see exactly what is live today, rather than assuming this ' +
185
+ 'call recovered something that may already be gone. ' +
186
+ '`allowedInjectedRequestData`/`useIncognitoWebview`/' +
187
+ '`extensionConfig` only take effect on add-version — the register ' +
188
+ 'endpoint (no `providerId`) ignores them. \n\n' +
95
189
  'Captured requests must be GET/POST. OPRF redactions are supported.',
96
190
  inputSchema: {
97
191
  type: 'object',
@@ -171,6 +265,78 @@ export function createVersionFromCaptureTool(
171
265
  'Change note for the new version (update only; must be ≥10 ' +
172
266
  'chars or a default is used).',
173
267
  },
268
+ customInjection: {
269
+ type: 'string',
270
+ description:
271
+ 'Plain JavaScript injected into the provider page before every ' +
272
+ 'page load — old-devtools\' name for what the builder calls ' +
273
+ '`webSettings.jsUserScripts`. Use standard browser APIs ' +
274
+ '(window.location, element.click(), forms) to drive login/' +
275
+ 'navigation so the target request fires — window.Reclaim is ' +
276
+ 'only for rare edge cases, not navigation. The backend rejects ' +
277
+ 'a few deprecated injection APIs (e.g. window.payloadData, ' +
278
+ 'window.ReclaimInjected) with a 400. Guide:\n\n' +
279
+ INJECTION_GUIDE,
280
+ },
281
+ userAgent: {
282
+ type: 'object',
283
+ description:
284
+ 'Per-platform user-agent override for the verification ' +
285
+ 'webview. Accepted on register too.',
286
+ properties: {
287
+ ios: { type: 'string' },
288
+ android: { type: 'string' },
289
+ },
290
+ },
291
+ pageTitle: {
292
+ type: 'string',
293
+ description: 'Page title metadata. Accepted on register too.',
294
+ },
295
+ allowedInjectedRequestData: {
296
+ type: 'array',
297
+ description:
298
+ 'Extra requests the customInjection script is allowed to ' +
299
+ 'fire (e.g. pagination) — add-version ONLY, the register ' +
300
+ 'endpoint ignores this. Each item has the same shape as ' +
301
+ '`provider`, plus `multiple`/`required` (default true).',
302
+ items: {
303
+ type: 'object',
304
+ properties: {
305
+ url: { type: 'string' },
306
+ method: { type: 'string' },
307
+ body: { type: 'string' },
308
+ responseMatches: { type: 'array' },
309
+ responseRedactions: { type: 'array' },
310
+ multiple: {
311
+ type: 'boolean',
312
+ description: 'Allow matching many requests. Default true.',
313
+ },
314
+ required: {
315
+ type: 'boolean',
316
+ description:
317
+ 'Fail validation if none match. Default true.',
318
+ },
319
+ },
320
+ required: ['url', 'method'],
321
+ },
322
+ },
323
+ stepsToFollow: {
324
+ type: 'string',
325
+ description:
326
+ 'Free-text setup/manual-verification steps shown to the ' +
327
+ 'dev/verifier. Accepted on register too.',
328
+ },
329
+ useIncognitoWebview: {
330
+ type: 'boolean',
331
+ description:
332
+ 'Run the verification webview in incognito mode. ' +
333
+ 'Add-version ONLY.',
334
+ },
335
+ extensionConfig: {
336
+ description:
337
+ 'Free-form JSON passed through to the client. Add-version ' +
338
+ 'ONLY.',
339
+ },
174
340
  },
175
341
  required: ['initialUrl'],
176
342
  },
@@ -207,11 +373,16 @@ export function createVersionFromCaptureTool(
207
373
  opts.providerType = args.providerType
208
374
  }
209
375
 
376
+ if(args.customInjection !== undefined) {
377
+ opts.customInjection = args.customInjection
378
+ }
379
+
210
380
  // Non-blocking advisory per request — never alters or blocks the
211
381
  // publish; the author keeps full control. Attaches under `_notes`.
212
382
  const notes = matchRedactionWarnings(
213
383
  providers.map((p, i) => countsFor(`Request ${i + 1}`, p)),
214
384
  )
385
+
215
386
  const withNotes = (result: unknown) => {
216
387
  if(notes.length && result && typeof result === 'object') {
217
388
  return { ...result, _notes: notes }
@@ -220,8 +391,50 @@ export function createVersionFromCaptureTool(
220
391
  return result
221
392
  }
222
393
 
223
- // New provider.
394
+ // New provider — no prior version to carry anything forward from.
395
+ // `allowedInjectedRequestData` / `useIncognitoWebview` /
396
+ // `extensionConfig` are accepted on the schema but the register
397
+ // controller never reads them from the body — warn rather than
398
+ // silently drop, so a dev doesn't think they took effect.
224
399
  if(!args.providerId) {
400
+ if(opts.customInjection?.trim()) {
401
+ notes.push(
402
+ 'customInjection will run in the verification client before ' +
403
+ 'every page load (before navigating to initialUrl), matching ' +
404
+ 'the builder\'s jsUserScripts.',
405
+ )
406
+ }
407
+
408
+ const REGISTER_IGNORED_KEYS = [
409
+ 'allowedInjectedRequestData',
410
+ 'useIncognitoWebview',
411
+ 'extensionConfig',
412
+ ] as const
413
+ const ignoredOnRegister = REGISTER_IGNORED_KEYS
414
+ .filter((k) => args[k] !== undefined)
415
+ if(ignoredOnRegister.length) {
416
+ notes.push(
417
+ `${ignoredOnRegister.join(', ')} ${
418
+ ignoredOnRegister.length > 1 ? 'are' : 'is'
419
+ } ignored on register (no providerId) — the old backend only ` +
420
+ 'reads them when adding a version. Publish once to create ' +
421
+ 'the provider, then call this again WITH the returned ' +
422
+ 'providerId to set them.',
423
+ )
424
+ }
425
+
426
+ if(args.userAgent !== undefined) {
427
+ opts.userAgent = args.userAgent
428
+ }
429
+
430
+ if(args.pageTitle !== undefined) {
431
+ opts.pageTitle = args.pageTitle
432
+ }
433
+
434
+ if(args.stepsToFollow !== undefined) {
435
+ opts.stepsToFollow = args.stepsToFollow
436
+ }
437
+
225
438
  const body = providerToRegisterBody(providers, opts)
226
439
  return withNotes(await client.registerProvider(body))
227
440
  }
@@ -232,6 +445,56 @@ export function createVersionFromCaptureTool(
232
445
  // workaround instead of a bare permission error.
233
446
  const providerId = args.providerId
234
447
  try {
448
+ // This backend has no partial-patch endpoint — a version always
449
+ // replaces the WHOLE providerConfig. Anything the caller didn't
450
+ // pass at all is carried forward from the currently-published
451
+ // version instead of going out blank. Pass an explicit empty
452
+ // value ("", [], false) to intentionally clear one.
453
+ const needsCurrent = PRESERVABLE_KEYS.some((k) => args[k] === undefined)
454
+ || args.allowedInjectedRequestData === undefined
455
+ const current = needsCurrent
456
+ ? extractProviderConfig(await client.getProviderConfig(providerId))
457
+ : undefined
458
+
459
+ const carried: string[] = []
460
+ for(const key of PRESERVABLE_KEYS) {
461
+ const resolved = resolveField(args[key], current?.[key], key, carried)
462
+ if(resolved !== undefined) {
463
+ (opts as unknown as Record<string, unknown>)[key] = resolved
464
+ }
465
+ }
466
+
467
+ const freshInjected = args.allowedInjectedRequestData !== undefined
468
+ ? injectedRequestDataFrom(args.allowedInjectedRequestData)
469
+ : undefined
470
+ const resolvedInjected = resolveField<OldInjectedRequestData[]>(
471
+ freshInjected,
472
+ current?.allowedInjectedRequestData,
473
+ 'allowedInjectedRequestData',
474
+ carried,
475
+ )
476
+ if(resolvedInjected !== undefined) {
477
+ opts.allowedInjectedRequestData = resolvedInjected
478
+ }
479
+
480
+ if(carried.length) {
481
+ notes.push(
482
+ 'Not passed, carried forward unchanged from the current ' +
483
+ `published version: ${carried.join(', ')}. Pass an explicit ` +
484
+ 'value ("", [], false, ...) to override any of them, or ' +
485
+ 'call get_provider_version_config first to see what is ' +
486
+ 'live today.',
487
+ )
488
+ }
489
+
490
+ if(args.customInjection !== undefined && opts.customInjection?.trim()) {
491
+ notes.push(
492
+ 'customInjection will run in the verification client before ' +
493
+ 'every page load (before navigating to initialUrl), matching ' +
494
+ 'the builder\'s jsUserScripts.',
495
+ )
496
+ }
497
+
235
498
  const versionsResp = await client.listVersions(providerId)
236
499
  const version = bumpPatchString(extractVersions(versionsResp))
237
500
  const versionInfo =
@@ -0,0 +1,72 @@
1
+ import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
2
+ import type { ReclaimOldClient, UpdateProviderMetadataBody } from '../client.ts'
3
+
4
+ /**
5
+ * Edit provider-level metadata on the old devtools backend
6
+ * (`POST /api/providers/:providerId`) — a genuine PARTIAL update on the
7
+ * PROVIDER document itself, distinct from both
8
+ * `create_provider_version_from_capture` paths: it does NOT touch
9
+ * `providerConfig`/versions at all, and only the fields you pass here
10
+ * change — everything else on the provider is left untouched (no need to
11
+ * re-supply `requestData`/`customInjection`/etc., and
12
+ * no new version is created).
13
+ *
14
+ * The backend 403s if you don't own the provider (and aren't an admin) —
15
+ * surfaced verbatim, same as any other auth failure from this client.
16
+ */
17
+ export function updateProviderMetadataTool(
18
+ client: ReclaimOldClient,
19
+ ): RegisteredTool {
20
+ return defineTool<UpdateProviderMetadataBody & { providerId: string }>(
21
+ {
22
+ name: 'update_provider_metadata',
23
+ description:
24
+ 'Rename, redescribe, retag, flip providerType (PRIVATE/PUBLIC), or ' +
25
+ 'toggle isActive on a provider YOU own — WITHOUT creating a new ' +
26
+ 'version. Only the fields you pass change; everything else ' +
27
+ '(requestData, customInjection, versions, ...) is untouched. Pass ' +
28
+ 'at least one of the optional fields. Get a `providerId` from ' +
29
+ 'get_me_providers.',
30
+ inputSchema: {
31
+ type: 'object',
32
+ properties: {
33
+ providerId: {
34
+ type: 'string',
35
+ description: 'UUID of the provider to update.',
36
+ },
37
+ name: { type: 'string', description: 'New provider name.' },
38
+ description: {
39
+ type: 'string',
40
+ description: 'New provider description.',
41
+ },
42
+ providerType: {
43
+ type: 'string',
44
+ enum: ['PRIVATE', 'PUBLIC'],
45
+ description: 'Change PRIVATE/PUBLIC visibility.',
46
+ },
47
+ tags: {
48
+ type: 'array',
49
+ items: { type: 'string' },
50
+ description: 'Replace the provider\'s tag list.',
51
+ },
52
+ isActive: {
53
+ type: 'boolean',
54
+ description: 'Whether the provider is active.',
55
+ },
56
+ },
57
+ required: ['providerId'],
58
+ },
59
+ },
60
+ async({ providerId, ...body }) => {
61
+ const hasAnyField = Object.values(body).some((v) => v !== undefined)
62
+ if(!hasAnyField) {
63
+ throw new Error(
64
+ 'Pass at least one of: name, description, providerType, tags, ' +
65
+ 'isActive.',
66
+ )
67
+ }
68
+
69
+ return client.updateProviderMetadata(providerId, body)
70
+ },
71
+ )
72
+ }
@@ -10,9 +10,14 @@ import { bytesToHex } from '@noble/hashes/utils.js'
10
10
  import {
11
11
  createClaimOnAttestor, type Logger,
12
12
  } from '@reclaimprotocol/attestor-core'
13
+ // Side-effect: make external domhandler nodes DOM-like so attestor-core's
14
+ // bundled `xpath` accepts them (see patch-domhandler.ts). Must load before any
15
+ // proof runs its response-redaction extraction.
16
+ import './patch-domhandler.ts'
13
17
  import { agentTraceEnabled } from '../consts.ts'
14
18
  import { resolveEthKey } from '../mcp/tools/authenticate/eth-key.ts'
15
19
  import type { ReclaimProvider } from '../provider/schema.ts'
20
+ import { installResponseDump } from './debug-response-dump.ts'
16
21
  import {
17
22
  buildHttpParams, ensureAttestorCrypto, parseClaim, resolveAttestorUrl,
18
23
  } from './proof-core.ts'
@@ -47,9 +52,11 @@ export interface RunAttestorProofOptions {
47
52
  /** Sign with this key directly (e.g. the app/VC's ephemeral per-session key)
48
53
  * instead of resolving from env/.env/file. */
49
54
  ownerPrivateKey?: string
50
- /** ZK engine for `createClaimOnAttestor`. Defaults to `'gnark'`; the app's
51
- * server-side verification runner uses `'snarkjs'`. */
52
- zkEngine?: 'gnark' | 'snarkjs'
55
+ /** ZK engine for `createClaimOnAttestor`. Defaults to `'stwo'` — a pure-WASM
56
+ * prover that runs everywhere (no native shared library, so it works on
57
+ * Windows where `'gnark'` fails to load its `.dll`). Server-side paths that
58
+ * want gnark's speed pin it explicitly (e.g. the verify runner). */
59
+ zkEngine?: 'gnark' | 'snarkjs' | 'stwo'
53
60
  /** Extract the structured {@link AttestorClaim} (claim + attestor signature)
54
61
  * onto the result for nested-proof construction. */
55
62
  includeAttestorClaim?: boolean
@@ -249,6 +256,11 @@ export async function runAttestorProof(
249
256
  const capture = traceEnabled ? makeCaptureLogger() : undefined
250
257
  const attestorLogs = capture?.entries
251
258
 
259
+ // Debug (RECLAIM_AGENT_DUMP_RESPONSE): dump the exact response the
260
+ // attestor validates against, so "Response does not contain X" is
261
+ // diagnosable against the attestor's real server-side fetch.
262
+ installResponseDump()
263
+
252
264
  let claim: unknown
253
265
  try {
254
266
  claim = await createClaimOnAttestor({
@@ -259,7 +271,7 @@ export async function runAttestorProof(
259
271
  },
260
272
  ownerPrivateKey,
261
273
  client: { url: resolveAttestorUrl(opts.attestorUrl) },
262
- zkEngine: opts.zkEngine ?? 'gnark',
274
+ zkEngine: opts.zkEngine ?? 'stwo',
263
275
  ...(capture !== undefined && { logger: capture.logger as Logger }),
264
276
  })
265
277
  } catch(err) {
@@ -0,0 +1,70 @@
1
+ // Debug helper (gated by RECLAIM_AGENT_DUMP_RESPONSE): capture the EXACT
2
+ // response bytes the attestor validates a claim against, plus a per-match
3
+ // presence check. A "Response does not contain X" failure means the attestor's
4
+ // server-side re-fetch differs from what the browser (replay) saw — e.g. GitHub
5
+ // embeds nav/userMenu data for browser requests but not for the attestor's raw
6
+ // fetch. Seeing the attestor's actual response is the only way to tell what it
7
+ // really returned.
8
+ //
9
+ // On each getResponseRedactions call it writes the response to
10
+ // `attestor-last-response.html` in the process CWD and logs the byte count +,
11
+ // for every responseMatch (paramValues substituted), whether it's present.
12
+ import { providers } from '@reclaimprotocol/attestor-core'
13
+ import { writeFileSync } from 'node:fs'
14
+ import { join } from 'node:path'
15
+
16
+ interface RedactionArg {
17
+ response: Uint8Array
18
+ params: {
19
+ responseMatches?: Array<{ value?: string }>
20
+ paramValues?: Record<string, string>
21
+ }
22
+ }
23
+
24
+ let installed = false
25
+
26
+ /** Wrap attestor-core's http `getResponseRedactions` to dump the response it
27
+ * runs against. Idempotent; no-op unless RECLAIM_AGENT_DUMP_RESPONSE is
28
+ * set. */
29
+ export function installResponseDump(): void {
30
+ if(installed || !process.env['RECLAIM_AGENT_DUMP_RESPONSE']) {
31
+ return
32
+ }
33
+
34
+ const http = providers['http'] as unknown as {
35
+ getResponseRedactions?: (arg: RedactionArg) => unknown
36
+ }
37
+ const original = http.getResponseRedactions
38
+ if(typeof original !== 'function') {
39
+ return
40
+ }
41
+
42
+ installed = true
43
+ http.getResponseRedactions = function(this: unknown, arg: RedactionArg) {
44
+ try {
45
+ const bytes = Buffer.from(arg.response)
46
+ const text = bytes.toString('utf8')
47
+ const paramValues = arg.params.paramValues ?? {}
48
+ const matches = (arg.params.responseMatches ?? []).map((m) => {
49
+ let value = m.value ?? ''
50
+ for(const [key, val] of Object.entries(paramValues)) {
51
+ value = value.split(`{{${key}}}`).join(val)
52
+ }
53
+
54
+ return { value, present: text.includes(value) }
55
+ })
56
+ const path = join(process.cwd(), 'attestor-last-response.html')
57
+ writeFileSync(path, text)
58
+ process.stderr.write(`${JSON.stringify({
59
+ tag: 'attestor-response-dump',
60
+ bytes: bytes.length,
61
+ path,
62
+ matches,
63
+ })}\n`)
64
+ } catch{
65
+ // diagnostic only — never break proving
66
+ }
67
+
68
+ return original.call(this, arg)
69
+ }
70
+ }