@reclaimprotocol/agent 0.1.23 → 0.1.25

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 (149) hide show
  1. package/README.md +56 -20
  2. package/lib/authoring/backend.d.ts +5 -4
  3. package/lib/authoring/tools.js +30 -30
  4. package/lib/cdp/capture-engine.js +8 -7
  5. package/lib/cdp/claims.d.ts +21 -0
  6. package/lib/cdp/claims.js +129 -0
  7. package/lib/cdp/container.d.ts +85 -0
  8. package/lib/cdp/container.js +481 -0
  9. package/lib/cdp/geo.d.ts +10 -0
  10. package/lib/cdp/geo.js +36 -0
  11. package/lib/cdp/index.d.ts +1 -0
  12. package/lib/cdp/index.js +1 -0
  13. package/lib/live/cloudflared.d.ts +15 -0
  14. package/lib/live/cloudflared.js +268 -0
  15. package/lib/live/tunnel.d.ts +26 -0
  16. package/lib/live/tunnel.js +160 -0
  17. package/lib/mcp/api/operations.gen.js +34 -26
  18. package/lib/mcp/api/to-zod.d.ts +1 -1
  19. package/lib/mcp/api/to-zod.js +1 -1
  20. package/lib/mcp/api/tools.js +1 -1
  21. package/lib/mcp/instructions.d.ts +15 -2
  22. package/lib/mcp/instructions.js +102 -38
  23. package/lib/mcp/start.js +62 -6
  24. package/lib/mcp/tools/agent/analyze.js +5 -1
  25. package/lib/mcp/tools/agent/attach.d.ts +29 -2
  26. package/lib/mcp/tools/agent/attach.js +310 -24
  27. package/lib/mcp/tools/agent/build.d.ts +18 -8
  28. package/lib/mcp/tools/agent/build.js +30 -12
  29. package/lib/mcp/tools/agent/capture.js +5 -1
  30. package/lib/mcp/tools/agent/eval.js +3 -1
  31. package/lib/mcp/tools/agent/find.js +6 -5
  32. package/lib/mcp/tools/agent/how-it-works.d.ts +15 -7
  33. package/lib/mcp/tools/agent/how-it-works.js +57 -17
  34. package/lib/mcp/tools/agent/index.d.ts +1 -2
  35. package/lib/mcp/tools/agent/index.js +1 -1
  36. package/lib/mcp/tools/agent/live-view.d.ts +17 -0
  37. package/lib/mcp/tools/agent/live-view.js +146 -0
  38. package/lib/mcp/tools/agent/pod-proof.d.ts +8 -0
  39. package/lib/mcp/tools/agent/pod-proof.js +64 -0
  40. package/lib/mcp/tools/agent/propose.js +4 -2
  41. package/lib/mcp/tools/agent/publish.js +47 -77
  42. package/lib/mcp/tools/agent/session.d.ts +16 -1
  43. package/lib/mcp/tools/agent/session.js +32 -7
  44. package/lib/mcp/tools/authenticate/authenticate.js +26 -13
  45. package/lib/mcp/tools/mode/mode.d.ts +1 -1
  46. package/lib/mcp/tools/mode/mode.js +10 -22
  47. package/lib/old/client.d.ts +1 -1
  48. package/lib/old/client.js +1 -1
  49. package/lib/old/instructions.d.ts +9 -1
  50. package/lib/old/instructions.js +4 -6
  51. package/lib/old/login-cdp.d.ts +2 -2
  52. package/lib/old/login-cdp.js +46 -6
  53. package/lib/old/to-register.d.ts +3 -2
  54. package/lib/old/to-register.js +1 -1
  55. package/lib/old/tools/authenticate.js +9 -1
  56. package/lib/old/tools/get-provider-info.js +6 -5
  57. package/lib/old/tools/issue-app-credentials.js +3 -2
  58. package/lib/old/tools/publish.d.ts +1 -1
  59. package/lib/old/tools/publish.js +90 -131
  60. package/lib/old/tools/update-provider-metadata.d.ts +1 -1
  61. package/lib/old/tools/update-provider-metadata.js +1 -1
  62. package/lib/old/tools/verify-sdk-setup.js +1 -1
  63. package/lib/proof/attestor.d.ts +3 -3
  64. package/lib/proof/debug-response-dump.js +4 -4
  65. package/lib/proof/index.d.ts +1 -0
  66. package/lib/proof/index.js +1 -0
  67. package/lib/proof/page-replay.d.ts +1 -1
  68. package/lib/proof/page-replay.js +1 -1
  69. package/lib/proof/pod-prover.d.ts +47 -0
  70. package/lib/proof/pod-prover.js +155 -0
  71. package/lib/provider/dom-xpath.js +11 -9
  72. package/lib/provider/draft.d.ts +10 -7
  73. package/lib/provider/draft.js +11 -9
  74. package/lib/provider/injection-doc.d.ts +23 -1
  75. package/lib/provider/injection-doc.js +34 -21
  76. package/lib/provider/match-redaction-warning.d.ts +2 -2
  77. package/lib/provider/match-redaction-warning.js +3 -3
  78. package/lib/provider/matcher.js +13 -12
  79. package/lib/provider/secrets.d.ts +3 -3
  80. package/lib/provider/secrets.js +3 -3
  81. package/lib/provider/to-version.d.ts +7 -6
  82. package/lib/provider/to-version.js +3 -3
  83. package/lib/tools/registry.d.ts +5 -5
  84. package/lib/tools/registry.js +5 -5
  85. package/package.json +3 -3
  86. package/samples/demo-server/README.md +7 -6
  87. package/skill/SKILL.builder.md +356 -189
  88. package/skill/SKILL.common.md +400 -97
  89. package/skill/SKILL.old.md +340 -155
  90. package/skill/builder-mode.md +60 -17
  91. package/skill/hash-validation.md +170 -0
  92. package/skill/interception.md +236 -0
  93. package/skill/js-sdk-integration.md +13 -7
  94. package/skill/old-mode.md +62 -21
  95. package/skill/user-script.md +61 -0
  96. package/src/authoring/backend.ts +5 -4
  97. package/src/authoring/tools.ts +31 -30
  98. package/src/cdp/capture-engine.ts +8 -7
  99. package/src/cdp/claims.ts +153 -0
  100. package/src/cdp/container.ts +593 -0
  101. package/src/cdp/geo.ts +52 -0
  102. package/src/cdp/index.ts +1 -0
  103. package/src/consts.ts +1 -0
  104. package/src/live/cloudflared.ts +348 -0
  105. package/src/live/tunnel.ts +208 -0
  106. package/src/mcp/api/operations.gen.ts +34 -26
  107. package/src/mcp/api/to-zod.ts +1 -1
  108. package/src/mcp/api/tools.ts +1 -1
  109. package/src/mcp/instructions.ts +122 -48
  110. package/src/mcp/start.ts +69 -5
  111. package/src/mcp/tools/agent/analyze.ts +5 -1
  112. package/src/mcp/tools/agent/attach.ts +367 -26
  113. package/src/mcp/tools/agent/build.ts +35 -16
  114. package/src/mcp/tools/agent/capture.ts +5 -1
  115. package/src/mcp/tools/agent/eval.ts +4 -1
  116. package/src/mcp/tools/agent/find.ts +6 -5
  117. package/src/mcp/tools/agent/how-it-works.ts +62 -21
  118. package/src/mcp/tools/agent/index.ts +6 -2
  119. package/src/mcp/tools/agent/live-view.ts +182 -0
  120. package/src/mcp/tools/agent/pod-proof.ts +90 -0
  121. package/src/mcp/tools/agent/propose.ts +4 -2
  122. package/src/mcp/tools/agent/publish.ts +52 -77
  123. package/src/mcp/tools/agent/session.ts +33 -6
  124. package/src/mcp/tools/authenticate/authenticate.ts +28 -13
  125. package/src/mcp/tools/mode/mode.ts +10 -22
  126. package/src/old/client.ts +2 -2
  127. package/src/old/instructions.ts +4 -10
  128. package/src/old/login-cdp.ts +50 -6
  129. package/src/old/to-register.ts +3 -2
  130. package/src/old/tools/authenticate.ts +9 -1
  131. package/src/old/tools/get-provider-info.ts +6 -5
  132. package/src/old/tools/issue-app-credentials.ts +3 -2
  133. package/src/old/tools/publish.ts +95 -131
  134. package/src/old/tools/update-provider-metadata.ts +1 -1
  135. package/src/old/tools/verify-sdk-setup.ts +1 -1
  136. package/src/proof/attestor.ts +3 -3
  137. package/src/proof/debug-response-dump.ts +4 -4
  138. package/src/proof/index.ts +8 -0
  139. package/src/proof/page-replay.ts +1 -1
  140. package/src/proof/pod-prover.ts +231 -0
  141. package/src/provider/dom-xpath.ts +11 -9
  142. package/src/provider/draft.ts +13 -10
  143. package/src/provider/injection-doc.ts +37 -24
  144. package/src/provider/match-redaction-warning.ts +3 -3
  145. package/src/provider/matcher.ts +13 -12
  146. package/src/provider/secrets.ts +3 -3
  147. package/src/provider/to-version.ts +11 -9
  148. package/src/tools/registry.ts +5 -5
  149. package/skill/injection-api.md +0 -364
@@ -2,17 +2,21 @@ import type { ConfigStore } from '../../../config/store.ts'
2
2
  import { defineTool, type RegisteredTool } from '../../server.ts'
3
3
  import { type AttachState, disposeAttached } from './attach.ts'
4
4
  import { type CaptureStore, resetCaptures } from './capture.ts'
5
+ import { type LiveShareRef, stopLiveShare } from './live-view.ts'
5
6
 
6
7
  export function sessionTools(
7
8
  attachRef: { current?: AttachState, config: ConfigStore },
8
9
  captures: CaptureStore,
10
+ liveShare: LiveShareRef,
9
11
  ): RegisteredTool[] {
10
12
  return [
11
13
  defineTool<Record<string, never>>(
12
14
  {
13
15
  name: 'get_session',
14
16
  description:
15
- 'Return current attach state, active captures, and persisted config.',
17
+ 'Report the current attach state, the live captureIds, and the '
18
+ + 'persisted browser config. Call it to check whether a browser is '
19
+ + 'still attached before reattaching, or to recover a captureId.',
16
20
  inputSchema: { type: 'object', properties: {} },
17
21
  },
18
22
  async() => ({
@@ -25,6 +29,13 @@ export function sessionTools(
25
29
  orgId: attachRef.current?.orgId,
26
30
  captures: [...captures.sessions.keys()],
27
31
  activeTab: captures.activeTab,
32
+ // The public share, when one is open — so a caller that lost the
33
+ // URL can recover it instead of opening a second tunnel.
34
+ ...(liveShare.current
35
+ ? {
36
+ sharedView: { url: liveShare.current.url },
37
+ }
38
+ : {}),
28
39
  }),
29
40
  ),
30
41
  defineTool<Record<string, never>>(
@@ -33,11 +44,12 @@ export function sessionTools(
33
44
  description:
34
45
  'Stop captures, disconnect the current browser, and immediately '
35
46
  + 'delete a Builder-hosted Popcorn session. Custom CDP sessions '
36
- + 'are disconnected but never deleted by Reclaim.',
47
+ + 'are disconnected but never deleted by Reclaim. Also closes a '
48
+ + 'public live view opened by share_browser_view.',
37
49
  inputSchema: { type: 'object', properties: {} },
38
50
  },
39
51
  async() => {
40
- await resetAll(attachRef, captures)
52
+ await resetAll(attachRef, captures, liveShare)
41
53
  return { disposed: true }
42
54
  },
43
55
  ),
@@ -46,21 +58,36 @@ export function sessionTools(
46
58
  name: 'reset_session',
47
59
  description:
48
60
  'Stop all captures and clear capture state — drops every '
49
- + 'session\'s drafts and their in-memory secrets.',
61
+ + 'session\'s drafts and their in-memory secrets, and closes a '
62
+ + 'public live view opened by share_browser_view.',
50
63
  inputSchema: { type: 'object', properties: {} },
51
64
  },
52
65
  async() => {
53
- await resetAll(attachRef, captures)
66
+ await resetAll(attachRef, captures, liveShare)
54
67
  return { reset: true }
55
68
  },
56
69
  ),
57
70
  ]
58
71
  }
59
72
 
60
- async function resetAll(
73
+ /**
74
+ * Release everything a session holds: the public tunnel, the captures, and the
75
+ * browser itself.
76
+ *
77
+ * Exported because a session can end WITHOUT anyone calling `dispose_browser` —
78
+ * the developer closes their agent, the client kills the server, the transport
79
+ * drops. Nothing runs on its own then, so `start.ts` runs this. Without it a
80
+ * container keeps running and, worse, a public URL to a live browser outlives
81
+ * the session that created it.
82
+ */
83
+ export async function resetAll(
61
84
  attachRef: { current?: AttachState, config: ConfigStore },
62
85
  captures: CaptureStore,
86
+ liveShare: LiveShareRef,
63
87
  ) {
88
+ // Before the captures: a public URL must never outlive the browser it points
89
+ // at.
90
+ await stopLiveShare(liveShare)
64
91
  await resetCaptures(captures)
65
92
  await disposeAttached(attachRef)
66
93
  }
@@ -18,17 +18,12 @@ export function authenticateTool(
18
18
  name,
19
19
  description:
20
20
  (name === 'authenticate_builder'
21
- ? 'This tool only exists in OLD-DEVTOOLS mode — Builder mode has '
22
- + 'no separate version of it; its own reclaim_authenticate '
23
- + 'already covers everything below. In old-devtools mode, this '
24
- + 'authenticates with Builder for exactly two Builder-exclusive '
25
- + 'features: allocating a Popcorn remote browser (attach_browser '
26
- + 'mode="builder") and listing Builder organizations '
27
- + '(list_builder_organizations — old-devtools has no generated '
28
- + 'org tool of its own). It does NOT authorize '
29
- + 'create_provider_version_from_capture or get_me_providers, '
30
- + 'which need their OWN, separate login via the old-devtools '
31
- + 'reclaim_authenticate tool. Check both with get_devtools_mode. '
21
+ ? 'OLD-DEVTOOLS MODE ONLY, and narrow: it authorizes exactly two '
22
+ + 'Builder-exclusive features — allocating a remote browser '
23
+ + '(attach_browser mode="builder") and list_builder_organizations. '
24
+ + 'It does NOT authorize create_provider_version_from_capture or '
25
+ + 'get_me_providers; those need the separate old-devtools login, '
26
+ + 'reclaim_authenticate. Check both with get_devtools_mode. '
32
27
  : '')
33
28
  + 'Authorize the CLI / MCP to make authenticated API calls. Opens '
34
29
  + 'the '
@@ -37,8 +32,9 @@ export function authenticateTool(
37
32
  'the user to sign in and approve. On success the access token is ' +
38
33
  'cached in ~/.reclaim/config.json and activated for this session.\n\n' +
39
34
  'Call with no arguments. This bearer token authenticates ' +
40
- 'dashboard/org-management calls (e.g. list_orgs, issuing an org ' +
41
- 'secret). Programmatic verification calls use a separate org secret ' +
35
+ 'dashboard/org-management calls (for example, list_orgs, or ' +
36
+ 'issuing an org secret). Programmatic verification calls use a ' +
37
+ 'separate org secret ' +
42
38
  '(rorg_…, set as RECLAIM_ORG_SECRET).',
43
39
  inputSchema: { type: 'object', properties: {} },
44
40
  },
@@ -85,6 +81,18 @@ export async function runOAuthLoopback(
85
81
  const codeChallenge = await oauth.calculatePKCECodeChallenge(codeVerifier)
86
82
  const state = oauth.randomState()
87
83
 
84
+ // openid-client/oauth4webapi refuse any non-HTTPS issuer by default
85
+ // ("only requests to HTTPS are allowed"). Better Auth's own dev default
86
+ // (`canonicalOrigin()`, packages/app/src/consts.ts) is plain
87
+ // `http://localhost:4001` — the server side has no HTTPS requirement at
88
+ // all — so a local `RECLAIM_API_URL=http://localhost:...` would otherwise
89
+ // always fail here. Loosen it ONLY for loopback hosts, matching what the
90
+ // server already trusts (`authTrustedOrigins()` defaults to
91
+ // localhost:4000/4001 outside production); a non-loopback http:// origin
92
+ // still gets the strict check.
93
+ const isLoopbackAuthBase =
94
+ ['localhost', '127.0.0.1', '[::1]'].includes(new URL(authBase).hostname)
95
+
88
96
  // Bind the callback port first: the client is registered for this exact
89
97
  // loopback redirect.
90
98
  const callback = await listenForCallback()
@@ -119,6 +127,13 @@ export async function runOAuthLoopback(
119
127
  // `authorizationCodeGrant` fails instead (confirmed by hitting
120
128
  // exactly that when this only checked method === 'POST').
121
129
  [oauth.customFetch]: _customFetchForOauth,
130
+ // Applies to the `Configuration` this call returns, so the later
131
+ // `buildAuthorizationUrl`/`authorizationCodeGrant` calls below (which
132
+ // reuse that same `config`) stop enforcing HTTPS too — no separate
133
+ // opt-in needed for them.
134
+ ...(isLoopbackAuthBase
135
+ ? { execute: [oauth.allowInsecureRequests] }
136
+ : {}),
122
137
  },
123
138
  )
124
139
  openBrowserFn(
@@ -24,7 +24,7 @@ function hasValidBuilderSession(config: ConfigStore): boolean {
24
24
  * `~/.reclaim/config.json` and applied the NEXT time the server starts —
25
25
  * the registered tool set, server instructions, and backend client are all
26
26
  * fixed at connect time, so the switch requires a restart/reconnect. Follows
27
- * the `attach_chrome` persist-through-config pattern.
27
+ * the `attach_browser` persist-through-config pattern.
28
28
  *
29
29
  * Registered in BOTH modes (so the user can switch either direction) and
30
30
  * outside `buildAgentTools` (so it survives `RECLAIM_AGENT_DISABLED=1`). An
@@ -74,27 +74,15 @@ export function buildModeTools(
74
74
  {
75
75
  name: 'get_devtools_mode',
76
76
  description:
77
- 'Report which backend this MCP server is currently targeting: '
78
- + '"old" (devtools) or "builder" (the builder '
79
- + 'backend). Also reports WHY that mode is in effect (source: '
80
- + 'a USE_OLD_DEVTOOLS env override, the persisted config, or '
81
- + 'the default) and which mode is persisted for the next '
82
- + 'start. Use set_devtools_mode to change it. Also reports '
83
- + 'AUTH status for BOTH auth systems — builderAuthenticated (the '
84
- + 'Builder OAuth login). In BUILDER mode this is the only login '
85
- + 'that exists and covers everything, including org listing '
86
- + '(list_orgs) and remote-browser allocation. In OLD-DEVTOOLS '
87
- + 'mode it is a SEPARATE, additional login (authenticate_builder) '
88
- + 'needed only for two Builder-exclusive features: remote-browser '
89
- + '(Popcorn) allocation and org listing (list_builder_organizations '
90
- + '— old-devtools has no generated org tool of its own). '
91
- + 'oldDevtoolsAuthenticated (the OLD-mode reclaim_authenticate) is '
92
- + 'required separately for create_provider_version_from_capture '
93
- + 'and get_me_providers, and only exists/matters in old-devtools '
94
- + 'mode. Both are presence checks, not '
95
- + 'validity checks — a stale old-devtools token still reports '
96
- + 'true here; a real publish/list call will surface staleness '
97
- + 'with a clear error pointing back at reclaim_authenticate.',
77
+ 'Report which backend this server targets ("old" devtools or '
78
+ + '"builder"), WHY (a USE_OLD_DEVTOOLS env override, the persisted '
79
+ + 'config, or the default), and which mode is persisted for the '
80
+ + 'next start. Change it with set_devtools_mode. Also reports auth '
81
+ + 'status for both login systems: builderAuthenticated and '
82
+ + 'oldDevtoolsAuthenticated. Both are PRESENCE checks, not validity '
83
+ + 'checks — a stale token still reports true; a real call surfaces '
84
+ + 'the staleness with an error naming the tool to re-run. Which '
85
+ + 'login authorizes what: how_it_works({ topic: "auth" }).',
98
86
  inputSchema: { type: 'object', properties: {} },
99
87
  },
100
88
  async() => {
package/src/old/client.ts CHANGED
@@ -50,7 +50,7 @@ export interface RegisterProviderBody {
50
50
  /** Interception mechanism (`NONE` = standard replay flow, the default;
51
51
  * `HAWKEYE`/`MSWJS`/`XHOOK` = JS-context interception; `CDP` = browser-
52
52
  * level). Column default is `HAWKEYE` when omitted entirely — unlike
53
- * `stepsToFollow` etc. above, whether the register endpoint actually
53
+ * `stepsToFollow`, and so on. above, whether the register endpoint actually
54
54
  * PERSISTS this field is UNVERIFIED (no source access to confirm); sent
55
55
  * here on the chance it does, but the publish tool always follows up
56
56
  * with a config (add-version) call regardless, which is confirmed to
@@ -370,7 +370,7 @@ export class ReclaimOldClient {
370
370
  // An identity ALREADY SET (as opposed to `#requireIdentity`'s "never
371
371
  // authenticated" case, which never reaches the backend) plus either a
372
372
  // 401/403 OR a message that itself names token verification means the
373
- // backend rejected a token we had — i.e. it's stale/invalid, not merely
373
+ // backend rejected a token we had — that is, it's stale/invalid, not merely
374
374
  // absent. The message check matters because this backend does NOT
375
375
  // reliably use 401/403 for it — confirmed live: an actually-expired
376
376
  // Firebase token surfaced as "Error while verifying token" with a
@@ -2,14 +2,8 @@
2
2
  * MCP server instructions shown to the LLM when running in OLD-devtools mode
3
3
  * (`USE_OLD_DEVTOOLS` unset or not `false`). Describes the REDUCED tool
4
4
  * surface — there are no org/credential-link/review flows and no generated
5
- * API tools here. The prose lives in `skill/old-mode.md` (published via the
6
- * `files` array); the path resolves identically from `src/old` (dev) and
7
- * `lib/old` (published).
5
+ * API tools here. Both modes' instructions load together in
6
+ * `mcp/instructions` (alongside the topic-split authoring guide); re-exported
7
+ * here so old-mode callers keep importing from their own module.
8
8
  */
9
- import { readFileSync } from 'node:fs'
10
- import { fileURLToPath } from 'node:url'
11
-
12
- export const OLD_MODE_INSTRUCTIONS = readFileSync(
13
- fileURLToPath(new URL('../../skill/old-mode.md', import.meta.url)),
14
- 'utf8',
15
- ).trim()
9
+ export { OLD_MODE_INSTRUCTIONS } from '../mcp/instructions.ts'
@@ -97,8 +97,8 @@ export interface CdpLoginResult {
97
97
  * finish signing in, read the resulting Firebase ID token from page storage,
98
98
  * then clean up. If we had to launch a dedicated Chrome for this, we close the
99
99
  * whole browser afterwards; if we attached to a Chrome that was already up
100
- * (e.g. the capture flow's), we only close the tab we opened so we don't
101
- * disrupt it.
100
+ * (for example, the capture flow's), we only close the tab we opened so we
101
+ * don't disrupt it.
102
102
  */
103
103
  export async function captureFirebaseTokenViaCdp(opts: {
104
104
  loginUrl?: string
@@ -107,7 +107,13 @@ export async function captureFirebaseTokenViaCdp(opts: {
107
107
  }): Promise<CdpLoginResult> {
108
108
  const loginUrl =
109
109
  opts.loginUrl || oldLoginUrl() || DEFAULT_LOGIN_URL
110
- const timeoutMs = opts.timeoutMs ?? 180_000
110
+ // 6 minutes, not 3. On a FRESH Chrome profile the dashboard is a cold load
111
+ // of an ~8.6 MB uncompressed bundle before the login form is even
112
+ // interactive — tens of seconds on a slow link — and only then does the
113
+ // developer start typing credentials and a 2FA code. The old 3-minute
114
+ // budget was routinely spent before they could finish, and the retry that
115
+ // followed looked like a 6-minute hang with no output.
116
+ const timeoutMs = opts.timeoutMs ?? 360_000
111
117
  const pollMs = opts.pollMs ?? 1000
112
118
 
113
119
  const cfg = new ConfigStore().read()?.browser_agent
@@ -123,7 +129,7 @@ export async function captureFirebaseTokenViaCdp(opts: {
123
129
  throw new Error(
124
130
  `attach mode: nothing answering CDP on port ${port}. Launch Chrome ` +
125
131
  `with --remote-debugging-port=${port} AND a non-default ` +
126
- '--user-data-dir, or switch to dedicated mode (attach_chrome).',
132
+ '--user-data-dir, or switch to dedicated mode (attach_browser).',
127
133
  )
128
134
  }
129
135
 
@@ -139,6 +145,10 @@ export async function captureFirebaseTokenViaCdp(opts: {
139
145
  try {
140
146
  const session = await handles.attachToTab(targetId)
141
147
  const deadline = Date.now() + timeoutMs
148
+ // Tracks how far the page got, so a timeout can say WHICH thing stalled:
149
+ // a bundle that never finished downloading is a different problem from a
150
+ // developer who walked away mid-sign-in.
151
+ let sawInteractivePage = false
142
152
  while(Date.now() < deadline) {
143
153
  const result = await session.send('Runtime.evaluate', {
144
154
  expression: EXTRACT_TOKEN_JS,
@@ -150,12 +160,24 @@ export async function captureFirebaseTokenViaCdp(opts: {
150
160
  return { token: value, closedBrowser: launchedByUs }
151
161
  }
152
162
 
163
+ if(!sawInteractivePage) {
164
+ sawInteractivePage = await pageIsInteractive(session)
165
+ }
166
+
153
167
  await new Promise((resolve) => setTimeout(resolve, pollMs))
154
168
  }
155
169
 
170
+ const waited = Math.round(timeoutMs / 1000)
156
171
  throw new Error(
157
- 'Timed out waiting for login. Finish signing in at the opened ' +
158
- 'page, or re-run reclaim_authenticate with a longer timeoutMs.',
172
+ `Timed out after ${waited}s waiting for login. `
173
+ + (sawInteractivePage
174
+ ? 'The page finished loading, so sign-in was never completed — '
175
+ + 'ask the developer to finish signing in at the opened window, '
176
+ + 'then re-run reclaim_authenticate.'
177
+ : 'The page never became interactive, so the dashboard was still '
178
+ + 'loading the whole time. On a fresh Chrome profile its bundle '
179
+ + 'is a large cold download. Retry (the profile is now warm), or '
180
+ + 'pass a bigger timeoutMs.'),
159
181
  )
160
182
  } finally {
161
183
  // Best-effort cleanup — never mask the real result/error.
@@ -173,6 +195,28 @@ export async function captureFirebaseTokenViaCdp(opts: {
173
195
  }
174
196
  }
175
197
 
198
+ /**
199
+ * Whether the login page has reached a usable state. `readyState` alone is not
200
+ * enough for a single-bundle SPA: the document is 'complete' while the app is
201
+ * still parsing, and nothing is clickable yet. Requiring a rendered root as
202
+ * well is what distinguishes "still loading" from "waiting for the human".
203
+ */
204
+ async function pageIsInteractive(
205
+ session: { send: (m: string, p?: object) => Promise<unknown> },
206
+ ): Promise<boolean> {
207
+ try {
208
+ const result = await session.send('Runtime.evaluate', {
209
+ expression:
210
+ 'document.readyState === "complete" '
211
+ + '&& !!document.body && document.body.innerText.trim().length > 0',
212
+ returnByValue: true,
213
+ })
214
+ return runtimeResultValue(result) === true
215
+ } catch{
216
+ return false
217
+ }
218
+ }
219
+
176
220
  function runtimeResultValue(value: unknown): unknown {
177
221
  if(typeof value !== 'object' || !value || !('result' in value)) {
178
222
  return undefined
@@ -39,7 +39,8 @@ export interface OldProviderOpts {
39
39
  /** Page-injection script — the devtools name for the builder's
40
40
  * `webSettings.jsUserScripts`. Top-level on register, nested under
41
41
  * `providerConfig` on config (add-version). The backend rejects a few
42
- * deprecated injection APIs (e.g. `window.payloadData`) with a 400. */
42
+ * deprecated injection APIs (for example, `window.payloadData`) with a
43
+ * 400. */
43
44
  customInjection?: string
44
45
  /** Accepted at register too (unlike the four fields below, which the
45
46
  * backend only accepts on config/add-version). */
@@ -355,7 +356,7 @@ export interface SemverTriplet {
355
356
  /**
356
357
  * Pull `{major,minor,patch}` triplets out of a `/versions` response, tolerant
357
358
  * of the exact envelope (array, `{ providerVersions: [...] }`, `{ items }`,
358
- * etc.). Each entry's `version` is the triplet.
359
+ *, and so on). Each entry's `version` is the triplet.
359
360
  */
360
361
  export function extractVersions(resp: unknown): SemverTriplet[] {
361
362
  const list = pickArray(resp)
@@ -46,6 +46,11 @@ export function authenticateTool(client: ReclaimOldClient): RegisteredTool {
46
46
  'and closes the tab. A previously stored identity that is still ' +
47
47
  'valid is reused first (pass `useBrowser: true` to force a fresh ' +
48
48
  'login). \n\n' +
49
+ 'EXPECT THIS TO TAKE A WHILE ON A FIRST RUN: a fresh Chrome ' +
50
+ 'profile downloads the dashboard cold, so tell the developer it is ' +
51
+ 'loading and that the window is waiting for them — do not re-run ' +
52
+ 'the tool while it is still waiting. It polls for up to 6 minutes ' +
53
+ 'and reports whether the page ever became interactive.\n\n' +
49
54
  'Manual overrides:\n' +
50
55
  '- `token`: paste a Firebase ID token (skips the browser).\n' +
51
56
  '- `ethAddress`: an `eth:0x…` / `0x…` uid for an already-provisioned ' +
@@ -73,7 +78,10 @@ export function authenticateTool(client: ReclaimOldClient): RegisteredTool {
73
78
  timeoutMs: {
74
79
  type: 'number',
75
80
  description:
76
- 'How long to wait for sign-in, in ms (default 180000).',
81
+ 'How long to wait for sign-in, in ms (default 360000, i.e. 6 '
82
+ + 'minutes). A fresh Chrome profile loads the dashboard cold, '
83
+ + 'which can take tens of seconds before the form is usable — '
84
+ + 'that time comes out of this budget.',
77
85
  },
78
86
  useBrowser: {
79
87
  type: 'boolean',
@@ -3,8 +3,8 @@ import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
3
3
  import type { ReclaimSdkClient } from '../sdk-client.ts'
4
4
 
5
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. */
6
+ * of throwing — one endpoint 404ing (for example, a bad `versionNumber`)
7
+ * shouldn't hide a result the other endpoint DID have. */
8
8
  async function attempt(
9
9
  label: string,
10
10
  call: () => Promise<unknown>,
@@ -51,8 +51,9 @@ export function getProviderInfoTool(client: ReclaimSdkClient): RegisteredTool {
51
51
  'computed `isScriptRequestingClaim` flag). Read `provider` here ' +
52
52
  'BEFORE create_provider_version_from_capture so you can pass the ' +
53
53
  'whole existing config back — that tool always creates a new ' +
54
- 'version and carries nothing forward. One endpoint failing (e.g. ' +
55
- 'an invalid `versionNumber`) is reported under `errors` without ' +
54
+ 'version and carries nothing forward. One endpoint failing (for ' +
55
+ 'example, an invalid `versionNumber`) is reported under `errors` ' +
56
+ 'without ' +
56
57
  'hiding a result the other endpoint did return.',
57
58
  inputSchema: {
58
59
  type: 'object',
@@ -64,7 +65,7 @@ export function getProviderInfoTool(client: ReclaimSdkClient): RegisteredTool {
64
65
  versionNumber: {
65
66
  type: 'string',
66
67
  description:
67
- 'Specific version, e.g. "1.0.2". Omit for the ' +
68
+ 'Specific version, for example, "1.0.2". Omit for the ' +
68
69
  "provider's current latest version.",
69
70
  },
70
71
  },
@@ -24,8 +24,9 @@ export function issueAppCredentialsTool(
24
24
  'starts UNLINKED and sandboxed (100 sessions) — call ' +
25
25
  'link_app_to_account to attach it to your dashboard account and ' +
26
26
  'check_app_status to check its state. Store `appSecret` like a ' +
27
- 'password (e.g. in a gitignored .env as RECLAIM_APP_SECRET) — it ' +
28
- 'is returned once and cannot be recovered from the server.',
27
+ 'password (for example, in a gitignored .env as ' +
28
+ 'RECLAIM_APP_SECRET) — it is returned once and cannot be ' +
29
+ 'recovered from the server.',
29
30
  inputSchema: { type: 'object', properties: {} },
30
31
  },
31
32
  async() => {