@reclaimprotocol/agent 0.1.22 → 0.1.24

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 (163) hide show
  1. package/README.md +55 -20
  2. package/lib/authoring/backend.d.ts +13 -10
  3. package/lib/authoring/tools.js +106 -9
  4. package/lib/cdp/browser-proxy.d.ts +78 -0
  5. package/lib/cdp/browser-proxy.js +186 -0
  6. package/lib/cdp/capture-engine.js +8 -7
  7. package/lib/cdp/client.d.ts +10 -0
  8. package/lib/cdp/geo.d.ts +10 -0
  9. package/lib/cdp/geo.js +36 -0
  10. package/lib/cdp/index.d.ts +1 -0
  11. package/lib/cdp/index.js +1 -0
  12. package/lib/live/cloudflared.d.ts +15 -0
  13. package/lib/live/cloudflared.js +268 -0
  14. package/lib/live/page.d.ts +20 -0
  15. package/lib/live/page.js +134 -0
  16. package/lib/live/tunnel.d.ts +23 -0
  17. package/lib/live/tunnel.js +120 -0
  18. package/lib/live/viewer.d.ts +28 -0
  19. package/lib/live/viewer.js +232 -0
  20. package/lib/mcp/api/operations.gen.js +34 -26
  21. package/lib/mcp/api/to-zod.d.ts +1 -1
  22. package/lib/mcp/api/to-zod.js +1 -1
  23. package/lib/mcp/api/tools.js +1 -1
  24. package/lib/mcp/instructions.d.ts +15 -2
  25. package/lib/mcp/instructions.js +101 -38
  26. package/lib/mcp/start.js +4 -3
  27. package/lib/mcp/tools/agent/analyze.js +5 -1
  28. package/lib/mcp/tools/agent/attach.d.ts +8 -1
  29. package/lib/mcp/tools/agent/attach.js +166 -22
  30. package/lib/mcp/tools/agent/build.d.ts +13 -8
  31. package/lib/mcp/tools/agent/build.js +22 -11
  32. package/lib/mcp/tools/agent/capture.js +5 -1
  33. package/lib/mcp/tools/agent/eval.js +3 -1
  34. package/lib/mcp/tools/agent/find.js +6 -5
  35. package/lib/mcp/tools/agent/how-it-works.d.ts +15 -7
  36. package/lib/mcp/tools/agent/how-it-works.js +57 -17
  37. package/lib/mcp/tools/agent/live-view.d.ts +21 -0
  38. package/lib/mcp/tools/agent/live-view.js +153 -0
  39. package/lib/mcp/tools/agent/pod-proof.d.ts +8 -0
  40. package/lib/mcp/tools/agent/pod-proof.js +64 -0
  41. package/lib/mcp/tools/agent/propose.js +29 -3
  42. package/lib/mcp/tools/agent/proxy.d.ts +3 -0
  43. package/lib/mcp/tools/agent/proxy.js +199 -0
  44. package/lib/mcp/tools/agent/publish.js +49 -77
  45. package/lib/mcp/tools/agent/session.d.ts +2 -1
  46. package/lib/mcp/tools/agent/session.js +26 -7
  47. package/lib/mcp/tools/agent/shared.js +17 -8
  48. package/lib/mcp/tools/authenticate/authenticate.d.ts +11 -0
  49. package/lib/mcp/tools/authenticate/authenticate.js +143 -121
  50. package/lib/mcp/tools/authenticate/builder-access.d.ts +8 -3
  51. package/lib/mcp/tools/authenticate/builder-access.js +8 -3
  52. package/lib/mcp/tools/mode/mode.d.ts +1 -1
  53. package/lib/mcp/tools/mode/mode.js +26 -7
  54. package/lib/old/client.d.ts +9 -0
  55. package/lib/old/client.js +19 -1
  56. package/lib/old/instructions.d.ts +9 -1
  57. package/lib/old/instructions.js +4 -6
  58. package/lib/old/login-cdp.d.ts +2 -2
  59. package/lib/old/login-cdp.js +46 -6
  60. package/lib/old/to-register.d.ts +20 -8
  61. package/lib/old/to-register.js +7 -1
  62. package/lib/old/tools/authenticate.js +9 -1
  63. package/lib/old/tools/get-provider-info.js +6 -5
  64. package/lib/old/tools/issue-app-credentials.js +3 -2
  65. package/lib/old/tools/me-providers.js +3 -1
  66. package/lib/old/tools/publish.d.ts +1 -1
  67. package/lib/old/tools/publish.js +132 -129
  68. package/lib/old/tools/update-provider-metadata.d.ts +1 -1
  69. package/lib/old/tools/update-provider-metadata.js +1 -1
  70. package/lib/old/tools/verify-sdk-setup.js +1 -1
  71. package/lib/proof/attestor.d.ts +3 -3
  72. package/lib/proof/debug-response-dump.js +4 -4
  73. package/lib/proof/index.d.ts +1 -0
  74. package/lib/proof/index.js +1 -0
  75. package/lib/proof/page-replay.d.ts +36 -0
  76. package/lib/proof/page-replay.js +76 -0
  77. package/lib/proof/pod-prover.d.ts +47 -0
  78. package/lib/proof/pod-prover.js +155 -0
  79. package/lib/proof/replay.d.ts +28 -0
  80. package/lib/proof/replay.js +39 -18
  81. package/lib/provider/dom-xpath.js +11 -9
  82. package/lib/provider/draft.d.ts +13 -8
  83. package/lib/provider/draft.js +47 -13
  84. package/lib/provider/injection-doc.d.ts +23 -1
  85. package/lib/provider/injection-doc.js +34 -21
  86. package/lib/provider/match-redaction-warning.d.ts +2 -2
  87. package/lib/provider/match-redaction-warning.js +3 -3
  88. package/lib/provider/matcher.js +122 -12
  89. package/lib/provider/secrets.d.ts +3 -3
  90. package/lib/provider/secrets.js +3 -3
  91. package/lib/provider/to-version.d.ts +12 -9
  92. package/lib/provider/to-version.js +16 -4
  93. package/lib/tools/registry.d.ts +5 -5
  94. package/lib/tools/registry.js +5 -5
  95. package/package.json +4 -3
  96. package/samples/demo-server/README.md +7 -6
  97. package/skill/SKILL.builder.md +356 -189
  98. package/skill/SKILL.common.md +314 -79
  99. package/skill/SKILL.old.md +340 -155
  100. package/skill/builder-mode.md +58 -17
  101. package/skill/hash-validation.md +170 -0
  102. package/skill/interception.md +235 -0
  103. package/skill/js-sdk-integration.md +13 -7
  104. package/skill/old-mode.md +53 -12
  105. package/skill/user-script.md +61 -0
  106. package/src/authoring/backend.ts +13 -10
  107. package/src/authoring/tools.ts +128 -9
  108. package/src/cdp/capture-engine.ts +8 -7
  109. package/src/cdp/client.ts +8 -0
  110. package/src/cdp/geo.ts +52 -0
  111. package/src/cdp/index.ts +1 -0
  112. package/src/consts.ts +1 -0
  113. package/src/live/cloudflared.ts +348 -0
  114. package/src/live/page.ts +145 -0
  115. package/src/live/tunnel.ts +157 -0
  116. package/src/live/viewer.ts +293 -0
  117. package/src/mcp/api/operations.gen.ts +34 -26
  118. package/src/mcp/api/to-zod.ts +1 -1
  119. package/src/mcp/api/tools.ts +1 -1
  120. package/src/mcp/instructions.ts +121 -48
  121. package/src/mcp/start.ts +4 -3
  122. package/src/mcp/tools/agent/analyze.ts +5 -1
  123. package/src/mcp/tools/agent/attach.ts +194 -22
  124. package/src/mcp/tools/agent/build.ts +26 -15
  125. package/src/mcp/tools/agent/capture.ts +5 -1
  126. package/src/mcp/tools/agent/eval.ts +4 -1
  127. package/src/mcp/tools/agent/find.ts +6 -5
  128. package/src/mcp/tools/agent/how-it-works.ts +62 -21
  129. package/src/mcp/tools/agent/live-view.ts +198 -0
  130. package/src/mcp/tools/agent/pod-proof.ts +90 -0
  131. package/src/mcp/tools/agent/propose.ts +31 -3
  132. package/src/mcp/tools/agent/publish.ts +54 -78
  133. package/src/mcp/tools/agent/session.ts +26 -5
  134. package/src/mcp/tools/agent/shared.ts +19 -8
  135. package/src/mcp/tools/authenticate/authenticate.ts +167 -165
  136. package/src/mcp/tools/authenticate/builder-access.ts +8 -3
  137. package/src/mcp/tools/mode/mode.ts +28 -7
  138. package/src/old/client.ts +30 -1
  139. package/src/old/instructions.ts +4 -10
  140. package/src/old/login-cdp.ts +50 -6
  141. package/src/old/to-register.ts +28 -8
  142. package/src/old/tools/authenticate.ts +9 -1
  143. package/src/old/tools/get-provider-info.ts +6 -5
  144. package/src/old/tools/issue-app-credentials.ts +3 -2
  145. package/src/old/tools/me-providers.ts +3 -1
  146. package/src/old/tools/publish.ts +140 -130
  147. package/src/old/tools/update-provider-metadata.ts +1 -1
  148. package/src/old/tools/verify-sdk-setup.ts +1 -1
  149. package/src/proof/attestor.ts +3 -3
  150. package/src/proof/debug-response-dump.ts +4 -4
  151. package/src/proof/index.ts +8 -0
  152. package/src/proof/page-replay.ts +131 -0
  153. package/src/proof/pod-prover.ts +231 -0
  154. package/src/proof/replay.ts +60 -19
  155. package/src/provider/dom-xpath.ts +11 -9
  156. package/src/provider/draft.ts +56 -13
  157. package/src/provider/injection-doc.ts +37 -24
  158. package/src/provider/match-redaction-warning.ts +3 -3
  159. package/src/provider/matcher.ts +151 -10
  160. package/src/provider/secrets.ts +3 -3
  161. package/src/provider/to-version.ts +30 -13
  162. package/src/tools/registry.ts +5 -5
  163. package/skill/injection-api.md +0 -335
@@ -1,32 +1,73 @@
1
- import {
2
- PROVIDER_GUIDE_BUILDER,
3
- PROVIDER_GUIDE_OLD,
4
- } from '../../instructions.ts'
1
+ import { guideFor } from '../../instructions.ts'
5
2
  import { defineTool, type RegisteredTool } from '../../server.ts'
6
3
 
7
4
  /**
8
- * Serves the full provider-authoring guide on demand. The MCP server's
9
- * always-on `instructions` are a terse tool-flow reference; this tool returns
10
- * the deep version (workflow, decision frameworks, gotchas, "never do" rules)
11
- * so any MCP client — not just Claude Code, which alone auto-loads skills — can
12
- * pull it. `oldMode` selects the backend-specific guide so the agent is never
13
- * told to call auth/publish tools that aren't registered in its mode.
14
- * Stateless: callable before `attach_browser`.
5
+ * Serves the provider-authoring guide on demand, ONE TOPIC AT A TIME. The
6
+ * server's always-on `instructions` are a terse tool-flow reference; this tool
7
+ * is the deep version, so any MCP client — not just Claude Code, which alone
8
+ * auto-loads skills — can pull it.
9
+ *
10
+ * Topic-scoped rather than all-at-once because the full guide is ~7k tokens:
11
+ * paying that to answer "how do I mark a header secret?" crowds out the actual
12
+ * task, which is exactly what makes an agent slow and prone to inventing
13
+ * details. Every response carries the topic index, so a caller that guessed
14
+ * wrong (or called with no topic at all) always learns what else is available
15
+ * without a second round-trip.
16
+ *
17
+ * `oldMode` selects the backend-specific guide, so the agent is never told to
18
+ * call auth/publish tools that aren't registered in its mode. Stateless:
19
+ * callable before `attach_browser`.
15
20
  */
16
21
  export function howItWorksTool(oldMode: boolean): RegisteredTool {
17
- const guide = oldMode ? PROVIDER_GUIDE_OLD : PROVIDER_GUIDE_BUILDER
18
- return defineTool<Record<string, never>>(
22
+ const guide = guideFor(oldMode)
23
+ const names = [...guide.topics.keys()]
24
+
25
+ return defineTool<{ topic?: string }>(
19
26
  {
20
27
  name: 'how_it_works',
21
28
  description:
22
- 'Return the full Reclaim provider-authoring guide for THIS server: '
23
- + 'the capture → draft → replay → prove → publish workflow, decision '
24
- + 'frameworks (login detection, OPRF privacy, context vs bare params), '
25
- + 'multi-request handling, troubleshooting, and what never to do. '
26
- + 'Call this BEFORE building a provider unless you are already '
27
- + 'fluent in the flow.',
28
- inputSchema: { type: 'object', properties: {} },
29
+ 'Reclaim provider-authoring guide for THIS server, by topic. Call it '
30
+ + 'with no arguments for the overview plus the topic index, then again '
31
+ + 'for whichever topic you need. Topics: '
32
+ + names.join(', ')
33
+ + '. Use `all` for the entire guide at once (large — prefer a topic). '
34
+ + 'Read the relevant topic BEFORE acting unless you are already fluent '
35
+ + 'in that part of the flow.',
36
+ inputSchema: {
37
+ type: 'object',
38
+ properties: {
39
+ topic: {
40
+ type: 'string',
41
+ // Deliberately NOT an `enum`: schema validation runs before the
42
+ // handler, so an enum turns a mistyped topic into a validation
43
+ // error instead of a response carrying the real topic list. A
44
+ // plain string lets the tool answer the mistake usefully.
45
+ description:
46
+ 'Which section to return: ' + names.join(', ')
47
+ + ', or `all`. Omit for the overview + topic index. An '
48
+ + 'unrecognized value comes back with the list, not an error.',
49
+ },
50
+ },
51
+ },
52
+ },
53
+ async({ topic }) => {
54
+ if(topic === 'all') {
55
+ return { topic: 'all', topics: guide.index, guide: guide.full }
56
+ }
57
+
58
+ const requested = topic ?? 'overview'
59
+ const section = guide.topics.get(requested)
60
+ if(!section) {
61
+ // Not an error: hand back the index so the caller self-corrects in
62
+ // the same turn rather than retrying blind.
63
+ return {
64
+ error: `Unknown topic "${requested}".`,
65
+ topics: guide.index,
66
+ guide: guide.topics.get('overview'),
67
+ }
68
+ }
69
+
70
+ return { topic: requested, topics: guide.index, guide: section }
29
71
  },
30
- async() => ({ guide }),
31
72
  )
32
73
  }
@@ -0,0 +1,198 @@
1
+ /**
2
+ * `share_browser_view` / `stop_browser_view` — put the LOCAL attached tab
3
+ * behind a public URL so someone who is not at this machine can watch it, and
4
+ * optionally drive it.
5
+ *
6
+ * Scoped to the CDP-attached modes (`dedicated`, `attach`, `custom`) on
7
+ * purpose. A `builder`-mode browser is a Popcorn pod that already ships its
8
+ * own hosted live view on `attach_browser`'s `liveViewUrl`; tunnelling a
9
+ * second one would duplicate it and burn a share URL for nothing, so this
10
+ * refuses and points at the one that exists.
11
+ *
12
+ * The share is deliberately explicit and single-instance: one live view per
13
+ * attached browser, started only when asked for, and torn down by
14
+ * `stop_browser_view`, `dispose_browser`, or `reset_session`.
15
+ */
16
+ import { badRequest, conflict } from '@hapi/boom'
17
+ import assert from 'node:assert'
18
+ import { startTunnel, type Tunnel } from '../../../live/tunnel.ts'
19
+ import { type LiveView, startLiveView } from '../../../live/viewer.ts'
20
+ import { LOGGER } from '../../../logger.ts'
21
+ import { defineTool, type RegisteredTool } from '../../server.ts'
22
+ import type { AttachState } from './attach.ts'
23
+ import type { CaptureStore } from './capture.ts'
24
+
25
+ /** Modes whose browser we reach over our own CDP connection, and which
26
+ * therefore have no hosted live view of their own. */
27
+ const SHAREABLE_MODES = new Set(['dedicated', 'attach', 'custom'])
28
+
29
+ export interface LiveShare {
30
+ view: LiveView
31
+ tunnel: Tunnel
32
+ url: string
33
+ interactive: boolean
34
+ startedAt: number
35
+ }
36
+
37
+ export interface LiveShareRef {
38
+ current?: LiveShare
39
+ }
40
+
41
+ /** Tear down whatever share is running. Safe when none is. Exported so the
42
+ * session tools can call it from `dispose_browser` / `reset_session`. */
43
+ export async function stopLiveShare(ref: LiveShareRef): Promise<boolean> {
44
+ const share = ref.current
45
+ if(!share) {
46
+ return false
47
+ }
48
+
49
+ ref.current = undefined
50
+ await share.view.stop().catch((err) => {
51
+ LOGGER.warn({ err }, 'live view: server stop failed')
52
+ })
53
+ await share.tunnel.stop().catch((err) => {
54
+ LOGGER.warn({ err }, 'live view: tunnel stop failed')
55
+ })
56
+ return true
57
+ }
58
+
59
+ export function liveViewTools(
60
+ attachRef: { current?: AttachState },
61
+ captures: CaptureStore,
62
+ shareRef: LiveShareRef,
63
+ ): RegisteredTool[] {
64
+ return [
65
+ defineTool<{ tabId?: string, interactive?: boolean }>(
66
+ {
67
+ name: 'share_browser_view',
68
+ description:
69
+ 'Put the attached tab behind a PUBLIC HTTPS URL (a cloudflared '
70
+ + 'quick tunnel) so someone elsewhere can watch it live, and by '
71
+ + 'default click and type in it. Use it to hand a login or a 2FA '
72
+ + 'step to the person who holds the credentials, or to let a '
73
+ + 'colleague watch a capture. Returns the URL — relay it to the '
74
+ + 'developer VERBATIM, on its own line. '
75
+ + 'ONLY for a locally attached browser (attach_browser mode '
76
+ + '`dedicated`, `attach`, or `custom`). In `builder` mode the '
77
+ + 'Popcorn browser already has a hosted live view: use the '
78
+ + '`liveViewUrl` that attach_browser returned instead. '
79
+ + 'THE URL IS A CREDENTIAL: anyone holding it can see this tab, '
80
+ + 'and with the default `interactive: true` can act in it as the '
81
+ + 'signed-in user. Share it only with the person who needs it, and '
82
+ + 'call stop_browser_view the moment they are done. Pass '
83
+ + '`interactive: false` for a watch-only link. '
84
+ + 'Needs cloudflared: an existing install on PATH is used as-is, '
85
+ + 'otherwise it is downloaded once to ~/.reclaim/bin on first '
86
+ + 'share (never at install time). Set RECLAIM_CLOUDFLARED_PATH to '
87
+ + 'point at your own copy instead.',
88
+ inputSchema: {
89
+ type: 'object',
90
+ properties: {
91
+ tabId: {
92
+ type: 'string',
93
+ description:
94
+ 'Tab to stream, from list_tabs. Defaults to the tab the '
95
+ + 'active capture is on, else the first tab.',
96
+ },
97
+ interactive: {
98
+ type: 'boolean',
99
+ description:
100
+ 'Let the viewer click and type in the page. Default true. '
101
+ + 'Set false to stream a read-only view.',
102
+ },
103
+ },
104
+ },
105
+ },
106
+ async({ tabId, interactive }) => {
107
+ const attached = attachRef.current
108
+ assert(attached, badRequest(
109
+ 'No browser attached. Call attach_browser first.',
110
+ ))
111
+ assert(SHAREABLE_MODES.has(attached.mode), badRequest(
112
+ `share_browser_view does not apply to \`${attached.mode}\` mode. `
113
+ + 'That browser already has a hosted live view — use the '
114
+ + '`liveViewUrl` from attach_browser'
115
+ + (attached.liveViewUrl ? `: ${attached.liveViewUrl}` : '')
116
+ + '.',
117
+ ))
118
+ assert(!shareRef.current, conflict(
119
+ 'A live view is already running at '
120
+ + `${shareRef.current?.url}. Call stop_browser_view first, or `
121
+ + 'reuse that URL.',
122
+ ))
123
+
124
+ const tabs = tabId || captures.activeTab
125
+ ? []
126
+ : await attached.handles.listTabs()
127
+ const target = tabId ?? captures.activeTab ?? tabs[0]?.tabId
128
+ assert(target, badRequest(
129
+ 'No tab to stream. Open a tab, or call list_tabs to pick one.',
130
+ ))
131
+
132
+ const tab = await attached.handles.attachToTab(target)
133
+ const wantsInput = interactive !== false
134
+ const view = await startLiveView({
135
+ tab,
136
+ interactive: wantsInput,
137
+ title: `Reclaim — ${attached.mode} browser`,
138
+ })
139
+
140
+ let tunnel: Tunnel
141
+ try {
142
+ tunnel = await startTunnel(view.port)
143
+ } catch(err) {
144
+ // Don't leave the loopback server behind if the tunnel failed.
145
+ await view.stop().catch(() => {})
146
+ throw err
147
+ }
148
+
149
+ const url = `${tunnel.url}${view.path}`
150
+ const share: LiveShare = {
151
+ view, tunnel, url, interactive: wantsInput, startedAt: Date.now(),
152
+ }
153
+ shareRef.current = share
154
+ LOGGER.info({ mode: attached.mode, interactive: wantsInput },
155
+ 'live view shared')
156
+
157
+ return {
158
+ url,
159
+ interactive: wantsInput,
160
+ tabId: target,
161
+ ...(share.tunnel.binary.source === 'downloaded'
162
+ ? { cloudflaredInstalled: true }
163
+ : {}),
164
+ ...(share.tunnel.ready ? {} : { propagating: true }),
165
+ _notes: [
166
+ ...(share.tunnel.binary.source === 'downloaded'
167
+ ? ['cloudflared was not installed, so it was downloaded once '
168
+ + 'to ~/.reclaim/bin. Mention that; later shares reuse it.']
169
+ : []),
170
+ ...(share.tunnel.ready
171
+ ? []
172
+ : ['The tunnel had not started routing yet — if the URL '
173
+ + 'errors, wait a few seconds and reload.']),
174
+ 'Relay `url` to the developer verbatim, on its own line.',
175
+ 'The URL is a credential: it needs no login, and anyone with '
176
+ + 'it can see this tab'
177
+ + (wantsInput ? ' and act in it as the signed-in user.' : '.'),
178
+ 'Call stop_browser_view when they are done — the tunnel stays '
179
+ + 'open until you do.',
180
+ ],
181
+ }
182
+ },
183
+ ),
184
+ defineTool<Record<string, never>>(
185
+ {
186
+ name: 'stop_browser_view',
187
+ description:
188
+ 'Close the public live view opened by share_browser_view: stops '
189
+ + 'the screen stream and shuts the tunnel down, so the URL stops '
190
+ + 'resolving. Call it as soon as the person you shared with is '
191
+ + 'finished. The browser itself stays attached and the capture '
192
+ + 'keeps running.',
193
+ inputSchema: { type: 'object', properties: {} },
194
+ },
195
+ async() => ({ stopped: await stopLiveShare(shareRef) }),
196
+ ),
197
+ ]
198
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Prove a drafted recipe through the Popcorn pod's OWN `/reclaim/prove` — the
3
+ * remote browser session's own API for creating a proof from that same
4
+ * session — instead of the local in-process attestor SDK (`run_proof`).
5
+ * Recommended for any `builder`-mode attach: the pod is the SAME enclave that
6
+ * holds the browser's TLS session, so proving there reaches the target from
7
+ * the identical exit IP the browser used — including the country-routed egress
8
+ * Popcorn applies when the session was allocated with a country. A local SDK
9
+ * proof runs from the agent's own network instead, which won't match a
10
+ * country-locked / IP-allowlisted target the remote browser could reach.
11
+ *
12
+ * Builder mode only (needs the attach's pod `apiUrl`, from
13
+ * `CreateAgentBrowserSession`) — throws a clear error otherwise rather than
14
+ * silently falling back to the local path.
15
+ */
16
+ import { badRequest } from '@hapi/boom'
17
+ import assert from 'node:assert'
18
+ import type { ConfigStore } from '../../../config/store.ts'
19
+ import { popcornProve } from '../../../proof/pod-prover.ts'
20
+ import { buildHttpParams } from '../../../proof/proof-core.ts'
21
+ import { defineTool, type RegisteredTool } from '../../server.ts'
22
+ import type { AttachState } from './attach.ts'
23
+ import type { CaptureStore } from './capture.ts'
24
+ import { shapeRichProofResult } from './proof.ts'
25
+
26
+ export function podProofTools(
27
+ attachRef: { current?: AttachState, config: ConfigStore },
28
+ captures: CaptureStore,
29
+ ): RegisteredTool[] {
30
+ const tool = defineTool<{ captureId: string, draftId: string }>(
31
+ {
32
+ name: 'run_proof_via_pod',
33
+ description:
34
+ 'Prove the drafted recipe through the Popcorn pod\'s own TEE '
35
+ + '(/reclaim/prove) instead of the local attestor SDK — this is '
36
+ + 'the remote browser session\'s own api for creating a proof '
37
+ + 'from that same session. Use this instead of run_proof '
38
+ + 'whenever this capture\'s '
39
+ + 'attach mode is "builder": the pod is the same enclave that '
40
+ + 'held the browser\'s TLS session (and its country-routed egress, '
41
+ + 'if any), so '
42
+ + 'the proof reaches the target from the browser\'s own exit IP. '
43
+ + 'No ownerAddress needed — the pod signs with the attestor\'s '
44
+ + 'own TEE key, not a local credential.',
45
+ inputSchema: {
46
+ type: 'object',
47
+ properties: {
48
+ captureId: { type: 'string' },
49
+ draftId: { type: 'string' },
50
+ },
51
+ required: ['captureId', 'draftId'],
52
+ },
53
+ },
54
+ async({ captureId, draftId }) => {
55
+ const apiUrl = attachRef.current?.apiUrl
56
+ assert(
57
+ apiUrl,
58
+ badRequest(
59
+ 'No pod api available for this attach — run_proof_via_pod needs '
60
+ + 'mode "builder" (attach_browser), not local/custom CDP.',
61
+ ),
62
+ )
63
+
64
+ const entry = captures.sessions.get(captureId)
65
+ assert(
66
+ entry,
67
+ badRequest(
68
+ `no capture ${captureId} — call start_capture first `
69
+ + '(it has been reset or never started).',
70
+ ),
71
+ )
72
+
73
+ const draft = entry.drafts.get(draftId)
74
+ assert(draft, badRequest(`no draft ${draftId} in capture ${captureId}`))
75
+
76
+ const result = await popcornProve({
77
+ apiUrl,
78
+ params: buildHttpParams(draft.provider),
79
+ secretParams: { headers: draft.secrets },
80
+ })
81
+
82
+ return shapeRichProofResult(result, {
83
+ provider: draft.provider,
84
+ hasSecrets: Object.keys(draft.secrets).length > 0,
85
+ })
86
+ },
87
+ )
88
+
89
+ return [tool]
90
+ }
@@ -23,18 +23,43 @@ export function proposeTool(resolveBackend: ResolveBackend): RegisteredTool {
23
23
  + 'one match + redaction per target. Returns a draftId + recipe '
24
24
  + '(never secrets). Prefer a SINGLE request holding ALL values. '
25
25
  + 'Single-value shorthand: `target` + `name`. Per-target `hash` '
26
- + 'OPRF-hashes that value.',
26
+ + 'OPRF-hashes that value. BY DEFAULT each `name` is shortened to '
27
+ + 'its last alphanumeric token, lowercased, to form the param key '
28
+ + '(for example, "employer_name" → "name") — pick names that stay '
29
+ + 'distinct '
30
+ + 'after shortening ("firstName"/"surname", not "first_name"/'
31
+ + '"last_name"). Pass `shortenNames: false` to use each `name` '
32
+ + 'VERBATIM as the param key instead — it becomes both a regex '
33
+ + 'capture-group name and a paramValues key, so it must be a plain '
34
+ + 'identifier (letters/digits/underscore, not starting with a '
35
+ + 'digit); we recommend lower_snake_case (for example, '
36
+ + '"employer_name"), '
37
+ + 'but you choose the exact name.',
27
38
  inputSchema: objectSchema(
28
39
  {
29
40
  requestId: { type: 'string' },
30
41
  name: { type: 'string' },
42
+ shortenNames: {
43
+ type: 'boolean',
44
+ description:
45
+ 'Default true: shorten each target `name` to its last '
46
+ + 'alphanumeric token, lowercased, to form the param key. '
47
+ + 'Set false to use `name` verbatim instead (must be a plain '
48
+ + 'identifier — lower_snake_case recommended).',
49
+ },
31
50
  targets: {
32
51
  type: 'array',
33
52
  items: {
34
53
  type: 'object',
35
54
  properties: {
36
55
  value: { type: 'string' },
37
- name: { type: 'string' },
56
+ name: {
57
+ type: 'string',
58
+ description:
59
+ 'The param key, or the source of one — see '
60
+ + '`shortenNames`. Must stay distinct from other targets\' '
61
+ + 'names after whichever treatment applies.',
62
+ },
38
63
  hash: {
39
64
  type: 'string',
40
65
  enum: ['oprf-raw', 'oprf', 'oprf-mpc'],
@@ -54,6 +79,9 @@ export function proposeTool(resolveBackend: ResolveBackend): RegisteredTool {
54
79
  const requestId = String(args.requestId)
55
80
  const providerName = String(args.name)
56
81
  const defaultHash = args.hash as OprfMode | undefined
82
+ const shortenNames = typeof args.shortenNames === 'boolean'
83
+ ? args.shortenNames
84
+ : true
57
85
 
58
86
  // Explicit multi-value `targets`, else the single `target` shorthand.
59
87
  const raw = Array.isArray(args.targets) ? args.targets : []
@@ -103,7 +131,7 @@ export function proposeTool(resolveBackend: ResolveBackend): RegisteredTool {
103
131
  }
104
132
 
105
133
  const { provider, secretRefs, extractions } = draftProvider(
106
- captured, targets, providerName, defaultHash,
134
+ captured, targets, providerName, defaultHash, { shortenNames },
107
135
  )
108
136
  // Materialize the real secret header values for later replay/prove;
109
137
  // they stay in the server-side draft, never in this result.
@@ -1,6 +1,9 @@
1
1
  import type { ReclaimClient } from '@reclaimprotocol/client'
2
2
  import type { JSONSchema } from 'zod/v4/core'
3
- import { INJECTION_GUIDE } from '../../../provider/injection-doc.ts'
3
+ import {
4
+ ALLOWED_REQUESTS_HINT,
5
+ USER_SCRIPT_HINT,
6
+ } from '../../../provider/injection-doc.ts'
4
7
  import {
5
8
  countsFor,
6
9
  matchRedactionWarnings,
@@ -82,7 +85,8 @@ const PROVIDER_SCHEMA: JSONSchema.Schema = {
82
85
  type: 'object',
83
86
  description:
84
87
  'A `provider` object from propose_provider, passed through verbatim — ' +
85
- 'the tool builds the version body (the requests[] entry etc.) for you.',
88
+ 'the tool builds the version body (the requests[] entry and so on) ' +
89
+ 'for you.',
86
90
  properties: {
87
91
  name: { type: 'string', description: 'Verification name.' },
88
92
  ...REQUEST_DRAFT_PROPERTIES,
@@ -95,7 +99,7 @@ const PROVIDER_SCHEMA: JSONSchema.Schema = {
95
99
  paramValues: {
96
100
  type: 'object',
97
101
  description:
98
- 'Real values for the {{param}} placeholders, e.g. ' +
102
+ 'Real values for the {{param}} placeholders, for example, ' +
99
103
  '{ "username": "Syed" }.',
100
104
  },
101
105
  },
@@ -111,8 +115,8 @@ const ALLOWED_JS_REQUEST_SCHEMA: JSONSchema.Schema = {
111
115
  multiple: {
112
116
  type: 'boolean',
113
117
  description:
114
- 'Allow the template to match many requests (e.g. pagination). ' +
115
- 'Default true.',
118
+ 'Allow the template to match many requests (for example, ' +
119
+ 'pagination). Default true.',
116
120
  },
117
121
  required: {
118
122
  type: 'boolean',
@@ -136,8 +140,8 @@ interface PublishArgs {
136
140
  allowedJsRequests?: AllowedJsRequest[]
137
141
  interceptorOptions?: {
138
142
  interceptorType: 'HAWKEYE' | 'MSWJS' | 'CDP'
139
- isDocumentRequestReplayEnabled?: boolean
140
143
  interceptorSettings?: string
144
+ isDocumentRequestReplayEnabled?: boolean
141
145
  }
142
146
  }
143
147
 
@@ -149,36 +153,21 @@ export function createVersionFromCaptureTool(
149
153
  {
150
154
  name: 'create_provider_version_from_capture',
151
155
  description:
152
- 'Persist drafted ReclaimProvider(s) as a provider version. ' +
153
- 'Call this after run_proof succeeds, passing the `provider` ' +
154
- 'object(s) from propose_provider VERBATIM. This tool builds the ' +
155
- 'body (the requests[] array, webSettings, etc.) for you — do NOT ' +
156
- 'hand-construct that shape or call create_provider_version directly. ' +
157
- 'For a MULTI-REQUEST provider, pass `providers: [...]` (each entry a ' +
158
- 'proven draft) — every entry becomes one request in the version, and ' +
159
- 'all are required at verification time. Pass a single `provider` ' +
160
- 'for the one-request case (exactly one of `provider`/`providers`). ' +
161
- 'For data gated behind login/navigation, supply `jsUserScripts` (a ' +
162
- 'page-injection script that drives the page to where the request ' +
163
- 'fires) and/or `allowedJsRequests` (extra requests the script may ' +
164
- 'fire, e.g. pagination). ' +
165
- 'Omit `version` to have the tool auto-select the next available ' +
166
- 'version (it lists existing versions and bumps past the highest). ' +
167
- 'The version lands on the draft branch — to go live, call ' +
168
- '`publish_provider_version` (PRIVATE) or ' +
169
- '`submit_provider_version_for_review` (PUBLIC) afterwards. ' +
156
+ 'Persist drafted ReclaimProvider(s) as a provider version, after ' +
157
+ 'run_proof succeeds. Pass the `provider` object(s) from ' +
158
+ 'propose_provider VERBATIM — this tool builds the version body ' +
159
+ '(requests[], webSettings, …) for you; do NOT hand-construct that ' +
160
+ 'shape or call create_provider_version directly. Exactly one of ' +
161
+ '`provider` (one request) or `providers` (a multi-request provider — ' +
162
+ 'every entry is required at verification time). Omit `version` to ' +
163
+ 'auto-bump past the highest existing one. The version lands on the ' +
164
+ 'draft branch: call `publish_provider_version` (PRIVATE) or ' +
165
+ '`submit_provider_version_for_review` (PUBLIC) to go live. ' +
170
166
  '`requiredContext` is derived from any {{context.<name>}} ' +
171
- 'placeholders across ALL requests (plus injected requests / script) ' +
172
- 'and returned on the created version — when present, tell the dev ' +
173
- 'verbatim which context fields consumers MUST send when creating ' +
174
- 'sessions (verification matches those values exactly; a missing ' +
175
- 'field is a 400 at session create). ' +
176
- 'Refine types/descriptions via `update_provider_version` while ' +
177
- 'still on draft. ' +
178
- 'On success, if a browser is still attached, the response\'s ' +
179
- '`_notes` reminds you to confirm with the developer before ' +
180
- 'calling `dispose_browser` — never close it unprompted, they ' +
181
- 'may want it for further edits.',
167
+ 'placeholders and returned on the created version — relay it to the ' +
168
+ 'dev verbatim, since a session missing those fields is a 400. Always ' +
169
+ 'read the response\'s `_notes`. ' +
170
+ 'Full walkthrough: how_it_works({ topic: "publish" }).',
182
171
  inputSchema: {
183
172
  type: 'object',
184
173
  properties: {
@@ -200,13 +189,15 @@ export function createVersionFromCaptureTool(
200
189
  type: 'string',
201
190
  description:
202
191
  'The website URL the user landed on to trigger the request ' +
203
- '(e.g. https://github.com/Syed). The URL the verification ' +
204
- 'flow opens for end-users — NOT the API URL inside the provider.',
192
+ '(for example, https://github.com/Syed). The URL the ' +
193
+ 'verification flow opens for end-users — NOT the API URL ' +
194
+ 'inside the provider.',
205
195
  },
206
196
  notes: {
207
197
  type: 'string',
208
198
  description:
209
- 'Short change note (e.g. "Initial draft from browser capture").',
199
+ 'Short change note (for example, "Initial draft from ' +
200
+ 'browser capture").',
210
201
  },
211
202
  version: {
212
203
  type: 'object',
@@ -223,67 +214,52 @@ export function createVersionFromCaptureTool(
223
214
  jsUserScripts: {
224
215
  type: 'string',
225
216
  description:
226
- 'Plain JavaScript injected into the provider page before every ' +
227
- 'page load (stored as webSettings.jsUserScripts). Use standard ' +
228
- 'browser APIs (window.location, element.click(), forms) to ' +
229
- 'drive login/navigation so the target request fires — the ' +
230
- 'client already intercepts page requests, and window.Reclaim ' +
231
- 'is only for rare edge cases, not navigation. The Builder ' +
232
- 'verification client installs this to run before every page ' +
233
- 'load (before navigating to initialUrl), matching old-devtool ' +
234
- 'customInjection; window.Reclaim itself is not yet exposed ' +
235
- 'there, so prefer plain browser JS. Guide:\n\n' +
236
- INJECTION_GUIDE,
217
+ USER_SCRIPT_HINT +
218
+ ' Stored as webSettings.jsUserScripts; the Builder ' +
219
+ 'verification client runs it before every page load ' +
220
+ '(including before navigating to initialUrl), matching ' +
221
+ 'old-devtools customInjection. window.Reclaim is not exposed ' +
222
+ 'there yet, so prefer plain browser JS.',
237
223
  },
238
224
  allowedJsRequests: {
239
225
  type: 'array',
240
226
  description:
241
- 'Extra requests the injection script is allowed to fire ' +
242
- '(e.g. paginated API calls), as RequestSelectionTemplates. ' +
243
- '`multiple`/`required` default to true. ' +
244
- '⚠️ BEFORE populating this to gate ' +
245
- '`verifyProof(proof, { providerId })` (old-devtools calls the ' +
246
- 'same concept `allowedInjectedRequestData` — same mechanics, ' +
247
- 'different field name): this whole entry (url, method, body, ' +
248
- 'responseMatches, responseRedactions) feeds a client-side ' +
249
- 'hash-equality check, and `url` is hashed VERBATIM — no regex/ ' +
250
- 'template resolution, even with `urlType: REGEX` or ' +
251
- '`TEMPLATE`. If the real captured URL contains ANY per-session ' +
252
- 'part (a tracking nonce, CSRF token, cache-busting timestamp), ' +
253
- 'no declared spec can EVER hash-match a real proof — populating' +
254
- ' this for such a provider makes verifyProof reject every real ' +
255
- 'proof, which is worse than leaving it empty. Diff the same ' +
256
- 'endpoint\'s captured URL across two separate sessions before ' +
257
- 'wiring this up. If provider-hash validation keeps causing ' +
258
- 'problems (unstable url, or any other persistent mismatch), ' +
259
- 'the fallback on the verifying side is `verifyProof(proof, { ' +
260
- 'dangerouslyDisableContentValidation: true })` — trusts only ' +
261
- 'the attestor\'s signature, skips the hash-equality check ' +
262
- 'entirely; see the "Provider-hash validation" section of the ' +
263
- 'injection script\'s guide for the full mechanics and when to ' +
264
- 'reach for it.',
227
+ 'Extra requests the user script is allowed to fire (for ' +
228
+ 'example, paginated API calls), as ' +
229
+ 'RequestSelectionTemplates. ' +
230
+ '`multiple`/`required` default to true. Old-devtools calls the ' +
231
+ 'same concept `allowedInjectedRequestData`. ' +
232
+ ALLOWED_REQUESTS_HINT,
265
233
  items: ALLOWED_JS_REQUEST_SCHEMA,
266
234
  },
267
235
  interceptorOptions: {
268
236
  type: 'object',
269
237
  description:
270
238
  'In-app interception settings, stored as ' +
271
- 'webSettings.clientOptions.inapp.interceptorOptions. ' +
272
- '`isDocumentRequestReplayEnabled` is the INVERSE of ' +
273
- 'old-devtools\' `disableRequestReplay`: true replays the ' +
274
- 'main document request via the attestor (default false).',
239
+ 'webSettings.clientOptions.inapp.interceptorOptions — only ' +
240
+ 'needed for a genuine live-interception provider (a real ' +
241
+ 'HAWKEYE/MSWJS script, not the standard capture→replay flow).',
275
242
  properties: {
276
243
  interceptorType: {
277
244
  type: 'string',
278
245
  enum: ['HAWKEYE', 'MSWJS', 'CDP'],
279
246
  description: 'How traffic interception is implemented.',
280
247
  },
281
- isDocumentRequestReplayEnabled: { type: 'boolean' },
282
248
  interceptorSettings: {
283
249
  type: 'string',
284
250
  description:
285
251
  'Free-form JSON config for the chosen interceptor.',
286
252
  },
253
+ isDocumentRequestReplayEnabled: {
254
+ type: 'boolean',
255
+ description:
256
+ 'Whether the page\'s own document/navigation request is ' +
257
+ 'genuinely replayed through the interceptor, rather than ' +
258
+ 'constructed locally. Defaults to `false` (disabled) when ' +
259
+ 'omitted. Only meaningful for HAWKEYE/MSWJS — pass `true` ' +
260
+ 'when the target value is embedded in the page\'s own HTML ' +
261
+ 'rather than a separate API call. Inert for CDP.',
262
+ },
287
263
  },
288
264
  required: ['interceptorType'],
289
265
  },