@reclaimprotocol/agent 0.1.29 → 0.1.32

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 (91) hide show
  1. package/README.md +28 -9
  2. package/lib/consts.d.ts +5 -5
  3. package/lib/consts.js +7 -7
  4. package/lib/live/tunnel-watchdog.d.ts +1 -0
  5. package/lib/live/tunnel-watchdog.js +66 -0
  6. package/lib/live/tunnel.d.ts +30 -7
  7. package/lib/live/tunnel.js +217 -40
  8. package/lib/mcp/api/operations.gen.d.ts +12 -0
  9. package/lib/mcp/api/operations.gen.js +548 -59
  10. package/lib/mcp/api/tools.js +27 -5
  11. package/lib/mcp/instructions.js +23 -32
  12. package/lib/mcp/remap_errors.js +6 -0
  13. package/lib/mcp/server.js +2 -8
  14. package/lib/mcp/start.js +3 -5
  15. package/lib/mcp/success-response.d.ts +5 -0
  16. package/lib/mcp/success-response.js +21 -0
  17. package/lib/mcp/tools/agent/attach.js +9 -66
  18. package/lib/mcp/tools/agent/build.d.ts +0 -3
  19. package/lib/mcp/tools/agent/build.js +3 -4
  20. package/lib/mcp/tools/agent/how-it-works.d.ts +5 -15
  21. package/lib/mcp/tools/agent/how-it-works.js +9 -22
  22. package/lib/mcp/tools/agent/live-view.d.ts +1 -15
  23. package/lib/mcp/tools/agent/live-view.js +71 -96
  24. package/lib/mcp/tools/agent/propose.js +7 -23
  25. package/lib/mcp/tools/agent/publish.js +80 -18
  26. package/lib/mcp/tools/agent/session.d.ts +4 -7
  27. package/lib/mcp/tools/agent/session.js +8 -23
  28. package/lib/mcp/tools/verification/result.d.ts +2 -1
  29. package/lib/mcp/tools/verification/result.js +29 -28
  30. package/lib/old/client.d.ts +2 -2
  31. package/lib/old/flag.d.ts +2 -5
  32. package/lib/old/flag.js +2 -5
  33. package/lib/old/instructions.d.ts +1 -1
  34. package/lib/old/instructions.js +1 -1
  35. package/lib/old/to-register.d.ts +4 -3
  36. package/lib/old/tools/get-provider-info.js +3 -1
  37. package/lib/old/tools/publish.js +11 -14
  38. package/lib/proof/attestor-auth.d.ts +9 -1
  39. package/lib/proof/attestor-auth.js +15 -2
  40. package/lib/proof/attestor.d.ts +2 -2
  41. package/lib/proof/attestor.js +20 -2
  42. package/lib/proof/pod-prover.js +1 -1
  43. package/lib/proof/proof-core.d.ts +4 -0
  44. package/lib/proof/proof-core.js +20 -0
  45. package/lib/provider/injection-doc.d.ts +3 -2
  46. package/lib/provider/injection-doc.js +12 -10
  47. package/lib/provider/matcher.js +19 -15
  48. package/lib/provider/to-version.d.ts +3 -0
  49. package/lib/provider/to-version.js +2 -1
  50. package/package.json +3 -3
  51. package/skill/SKILL.builder.md +44 -86
  52. package/skill/SKILL.common.md +38 -22
  53. package/skill/SKILL.old.md +21 -5
  54. package/skill/builder-mode.md +62 -4
  55. package/skill/community-contributions.md +12 -3
  56. package/skill/hash-validation.md +9 -9
  57. package/skill/interception.md +39 -46
  58. package/skill/old-mode.md +25 -0
  59. package/skill/user-script.md +24 -8
  60. package/skill/verification-client-integration.md +133 -0
  61. package/src/consts.ts +9 -7
  62. package/src/mcp/api/operations.gen.ts +550 -59
  63. package/src/mcp/api/tools.ts +38 -7
  64. package/src/mcp/instructions.ts +33 -32
  65. package/src/mcp/remap_errors.ts +6 -0
  66. package/src/mcp/server.ts +2 -8
  67. package/src/mcp/start.ts +3 -5
  68. package/src/mcp/success-response.ts +26 -0
  69. package/src/mcp/tools/agent/attach.ts +9 -71
  70. package/src/mcp/tools/agent/build.ts +4 -7
  71. package/src/mcp/tools/agent/how-it-works.ts +9 -22
  72. package/src/mcp/tools/agent/live-view.ts +76 -116
  73. package/src/mcp/tools/agent/propose.ts +7 -23
  74. package/src/mcp/tools/agent/publish.ts +89 -18
  75. package/src/mcp/tools/agent/session.ts +6 -23
  76. package/src/mcp/tools/verification/result.ts +30 -29
  77. package/src/old/client.ts +2 -2
  78. package/src/old/flag.ts +2 -5
  79. package/src/old/instructions.ts +1 -1
  80. package/src/old/to-register.ts +4 -3
  81. package/src/old/tools/get-provider-info.ts +3 -1
  82. package/src/old/tools/publish.ts +16 -14
  83. package/src/proof/attestor-auth.ts +18 -1
  84. package/src/proof/attestor.ts +24 -3
  85. package/src/proof/pod-prover.ts +1 -1
  86. package/src/proof/proof-core.ts +28 -0
  87. package/src/provider/injection-doc.ts +12 -10
  88. package/src/provider/matcher.ts +25 -17
  89. package/src/provider/to-version.ts +7 -1
  90. package/src/live/cloudflared.ts +0 -348
  91. package/src/live/tunnel.ts +0 -254
@@ -0,0 +1,133 @@
1
+ # Integrate a Builder verification client
2
+
3
+ ## Set up an application with the coding agent
4
+
5
+ When asked to integrate Reclaim into an app, inspect that app's frontend,
6
+ backend, package manager, configuration, and callback conventions. Complete
7
+ the integration in its codebase and run its relevant checks. The MCP tools
8
+ configure Builder resources; the coding agent's file tools edit the app.
9
+
10
+ If the app depends on `@reclaimprotocol/js-sdk`, ask the developer first:
11
+ keep it (call `set_devtools_mode({ mode: "old" })` and have them restart the MCP
12
+ server), or migrate to the Builder session flow below. When
13
+ migrating, remove `@reclaimprotocol/js-sdk` and replace its
14
+ `ReclaimProofRequest` and `verifyProof` calls with the session flow below.
15
+
16
+ 1. Use `get_devtools_mode` to confirm Builder mode and `get_me` or
17
+ `authenticate` to sign in as the developer. Find the intended organization
18
+ with `list_orgs`; call `create_org` only when a new organization is wanted.
19
+ 2. Register a callback URL owned by the app's backend with
20
+ `create_org_callback_subscription`. Include terminal success, rejection,
21
+ error, cancellation, and expiry events. If the app needs encrypted results,
22
+ register its public key with `set_org_keypair`; retain the private key only
23
+ in the backend.
24
+ 3. An organization owner can call `issue_org_token`. Its `orgSecret` is shown
25
+ once. Put it in the app backend's secret configuration as
26
+ `RECLAIM_ORG_SECRET`; keep it out of frontend bundles, logs, source control,
27
+ and the final response. Reuse an already configured secret when available;
28
+ issue a new token when setup needs one.
29
+ 4. Prefer plain HTTP from the backend. Create sessions with
30
+ `POST /verifications/sessions` (`Authorization: Bearer <orgSecret>`), save
31
+ each returned session ID alongside the app's own user or order, and return
32
+ only `verificationUrl` to the frontend. The frontend opens that URL and asks
33
+ its backend for the final status (`GET /verifications/sessions/{sessionId}`);
34
+ a browser redirect alone is not proof of success. Use
35
+ `@reclaimprotocol/client` (`ReclaimVerification.create({ orgSecret })`,
36
+ `sessions.create`) only when the developer asks for it.
37
+ 5. Add a backend callback endpoint. Persist each delivery idempotently and load
38
+ the expected session ID and org ID from app storage. To verify the result on
39
+ your callback, install `@reclaimprotocol/client` in the backend and call
40
+ `reclaim.results.receive(body, { reclaimSessionId, expectedAud,
41
+ orgEthPrivateKey })`. Use the verified proof data to update app state.
42
+ Handle callback retries and terminal failure outcomes.
43
+ 6. Exercise one session through the selected registered Verification Client,
44
+ inspect its Builder events, and test the app's success and failure paths.
45
+ Omit `verificationClientUrl` to use the Portal, or select another client
46
+ from `VerificationClient` in the SDK. Do not send an unregistered URL or
47
+ call a legacy backend for an `api=2` session.
48
+
49
+ The one-time management calls above use the developer's Builder login. The
50
+ consumer backend uses the separate organization token. The SDK's API-only
51
+ entry point, `@reclaimprotocol/client/api`, is available when an application
52
+ needs typed Builder operations without the full verification workflow.
53
+
54
+ ## Create and launch a session
55
+
56
+ Consumers authenticate with an organization token (`rorg_…`, issued in the
57
+ dashboard or via `POST /orgs/{orgId}/token`) and call
58
+ `POST /verifications/sessions`. Open the returned `verificationUrl` for the
59
+ claimant. It contains only the registered Verification Client URL, session ID,
60
+ and `api=2` mode selector.
61
+
62
+ A consumer can pass `launchOptions` (`redirectUrl`/`redirectUrlOptions` on
63
+ success, `cancelRedirectUrl`/`cancelRedirectUrlOptions` on cancellation, `https:`
64
+ only) in the `POST /verifications/sessions` body. Builder validates and stores
65
+ them on the session at creation and returns them unchanged from bootstrap
66
+ (`session.launchOptions`); it never redirects to them itself — only the
67
+ Verification Client that renders the flow does. Set `diagnostics: true` on the
68
+ same request only for deliberate troubleshooting, since diagnostic logs can
69
+ contain personal data; Builder appends `diag=1` to `verificationUrl` for that
70
+ session and strips any `diag` the consumer's own `verificationClientUrl` carries.
71
+
72
+ An optional `themeId` selects an active organization theme. If it is absent,
73
+ Builder snapshots the organization's most recently updated active theme. A
74
+ localized consent block tells supported clients to show consent before the
75
+ first provider. Branding and theme data don't affect proof trust.
76
+
77
+ ## Call the direct Builder API
78
+
79
+ In `api=2` mode, send the registered client UUID in `x-reclaim-vc-id` on every
80
+ request. Generate the client from `packages/app/openapi.yaml`; don't hand-write
81
+ route types or proxy these calls through `api.reclaimprotocol.org`.
82
+ The UUID must match the session, but it is public and doesn't authenticate the
83
+ caller.
84
+
85
+ | Route | Purpose |
86
+ | --- | --- |
87
+ | `GET /verifications/sessions/{sessionId}/bootstrap` | Load the session, resolved recipes, runtime configuration, branding, and theme. |
88
+ | `PATCH /verifications/sessions/{sessionId}/claimant` | Update the latest claimant and device snapshot. |
89
+ | `POST /verifications/sessions/{sessionId}/events` | Report canonical lower-snake-case analytics events. |
90
+ | `POST /verifications/sessions/{sessionId}/attestor-auth` | Request session-bound attestor authentication. Don't send a legacy application secret or provider signature. |
91
+ | `POST /verifications/sessions/{sessionId}/results` | Submit exact proof objects or a terminal error/cancellation. Builder atomically records the canonical outcome and prepares signed callback delivery. |
92
+
93
+ URLs without `api=2` stay on each client's existing legacy path. Builder mode
94
+ must not call legacy lifecycle, application-info, or result APIs.
95
+
96
+ ## Preserve and verify proofs
97
+
98
+ Verification Clients put each exact proof in the Builder result. They
99
+ don't reverify proofs. Builder signs the outer result JWS without
100
+ rewriting the proof.
101
+
102
+ Consumers call `verifyResultFull` on their backend. It verifies the registered
103
+ Builder issuer, outer JWS, session, audience, and every proof with the local
104
+ `verifyRequestProof` implementation. Treat outer `extracted_parameters` and
105
+ `content_hash` as diagnostics, not trusted proof inputs.
106
+
107
+ Results are delivered to the org's registered callback subscriptions
108
+ (`POST /orgs/{orgId}/callback-subscriptions`), plaintext by default. When the
109
+ org has enabled `canEncryptResult` on its secp256k1 keypair
110
+ (`PUT /orgs/{orgId}/keypair`), Builder ECIES-encrypts the terminal payload to
111
+ that public key instead; decrypt it with `@reclaimprotocol/client`'s
112
+ `decryptCallback`/`verifyResult` and the org's eth private key before treating
113
+ it as a result. A session created without `canEncryptResult` never needs this
114
+ step. Troubleshoot a stuck or failed session with `get_verification_session`,
115
+ `list_verification_events`, and `list_org_verification_sessions`.
116
+
117
+ ## Use the browser extension
118
+
119
+ For an `api=2` URL, use
120
+ `reclaimExtensionSDK.fromVerificationUrl` or `initBuilder` with the returned
121
+ `verificationClientId`, then call `startVerification()`. The extension sends
122
+ `x-reclaim-vc-id`, loads recipes from bootstrap, runs them sequentially, and
123
+ submits the raw proofs. It doesn't perform redundant `allowedJsRequests`
124
+ validation. Missing or unknown `api` values keep the existing `init`,
125
+ `fromJsonString`, and direct-callback behavior.
126
+
127
+ ## Bind a TEE nonce when required
128
+
129
+ A consumer can pass `orgEthPrivateKey` to `sessions.create`. The SDK derives the
130
+ legacy-compatible nonce locally, signs the binding payload with EIP-191, and
131
+ calls `PUT /verifications/sessions/{sessionId}/tee-nonce` with the organization
132
+ token. The private key stays in the consumer process. Bind before proof
133
+ generation; the same binding is idempotent and a different binding is rejected.
package/src/consts.ts CHANGED
@@ -64,12 +64,13 @@ export function reclaimHome(): string {
64
64
 
65
65
  /**
66
66
  * `USE_OLD_DEVTOOLS` — single source of truth for which backend the MCP
67
- * server targets. Defaults to OLD devtools while the builder backend is under
68
- * development. Builder mode must be opted into EXPLICITLY with
69
- * `USE_OLD_DEVTOOLS=false`; anything else keeps old mode on.
67
+ * server targets. Builder is the default. Set `USE_OLD_DEVTOOLS=true` to
68
+ * explicitly use the legacy backend.
70
69
  */
71
70
  export function useOldDevtools(): boolean {
72
- return (process.env.USE_OLD_DEVTOOLS ?? '').trim().toLowerCase() !== 'false'
71
+ return ['true', '1'].includes(
72
+ (process.env.USE_OLD_DEVTOOLS ?? '').trim().toLowerCase(),
73
+ )
73
74
  }
74
75
 
75
76
  /** True when `USE_OLD_DEVTOOLS` is set to a non-empty value (explicit). */
@@ -79,7 +80,8 @@ function oldDevtoolsEnvSet(): boolean {
79
80
 
80
81
  /**
81
82
  * Effective mode, layering the persisted preference under the env var:
82
- * explicit `USE_OLD_DEVTOOLS` wins → persisted config `mode` → default (old).
83
+ * explicit `USE_OLD_DEVTOOLS` wins → persisted config `mode` →
84
+ * default (builder).
83
85
  * The persisted value comes from `~/.reclaim/config.json` (set via the
84
86
  * `set_devtools_mode` tool); the caller reads it so this module needn't import
85
87
  * `ConfigStore` (which would create an import cycle).
@@ -93,13 +95,13 @@ export function resolveOldMode(persisted?: 'old' | 'builder'): boolean {
93
95
  return persisted === 'old'
94
96
  }
95
97
 
96
- return true
98
+ return false
97
99
  }
98
100
 
99
101
  /**
100
102
  * Where the effective mode came from — the same precedence as
101
103
  * `resolveOldMode`: explicit `USE_OLD_DEVTOOLS` env var → persisted config
102
- * `mode` → default (old). Surfaced by the `get_devtools_mode` tool so the
104
+ * `mode` → default (builder). Surfaced by the `get_devtools_mode` tool so the
103
105
  * user can tell why the server is in the mode it reports.
104
106
  */
105
107
  export function oldModeSource(