@reclaimprotocol/agent 0.1.1-dev.1 → 0.1.2

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 (232) hide show
  1. package/README.md +1 -1
  2. package/lib/cdp/capture-engine.d.ts +66 -0
  3. package/lib/cdp/capture-engine.js +153 -0
  4. package/lib/cdp/capture.d.ts +9 -20
  5. package/lib/cdp/capture.js +14 -138
  6. package/lib/cdp/index.d.ts +3 -0
  7. package/lib/cdp/index.js +6 -0
  8. package/lib/cdp/launcher.js +4 -3
  9. package/lib/config/store.d.ts +7 -6
  10. package/lib/config/store.js +2 -2
  11. package/lib/consts.d.ts +68 -0
  12. package/lib/consts.js +134 -0
  13. package/lib/index.d.ts +2 -2
  14. package/lib/index.js +1 -1
  15. package/lib/logger.js +2 -1
  16. package/lib/mcp/api/operations.gen.d.ts +100 -48
  17. package/lib/mcp/api/operations.gen.js +1129 -194
  18. package/lib/mcp/api/to-zod.d.ts +24 -0
  19. package/lib/mcp/api/to-zod.js +94 -0
  20. package/lib/mcp/api/tools.js +1 -1
  21. package/lib/mcp/credentials/authenticate.d.ts +3 -0
  22. package/lib/mcp/{tools/credentials → credentials}/authenticate.js +3 -3
  23. package/lib/mcp/credentials/build.d.ts +5 -0
  24. package/lib/mcp/credentials/build.js +18 -0
  25. package/lib/mcp/{tools/credentials → credentials}/cache.d.ts +9 -9
  26. package/lib/mcp/{tools/credentials → credentials}/cache.js +36 -19
  27. package/lib/mcp/credentials/import.d.ts +2 -0
  28. package/lib/mcp/{tools/credentials → credentials}/import.js +2 -2
  29. package/lib/mcp/credentials/issue.d.ts +2 -0
  30. package/lib/mcp/{tools/credentials → credentials}/issue.js +4 -4
  31. package/lib/mcp/credentials/keypair.d.ts +17 -0
  32. package/lib/mcp/credentials/keypair.js +48 -0
  33. package/lib/mcp/credentials/link.d.ts +3 -0
  34. package/lib/mcp/credentials/link.js +107 -0
  35. package/lib/mcp/{tools/credentials → credentials}/list-cached.d.ts +1 -1
  36. package/lib/mcp/{tools/credentials → credentials}/list-cached.js +5 -5
  37. package/lib/mcp/credentials/owner-key.d.ts +23 -0
  38. package/lib/mcp/credentials/owner-key.js +58 -0
  39. package/lib/mcp/credentials/paths.d.ts +12 -0
  40. package/lib/mcp/credentials/paths.js +35 -0
  41. package/lib/mcp/credentials/poll.d.ts +27 -0
  42. package/lib/mcp/credentials/poll.js +61 -0
  43. package/lib/mcp/{tools/credentials → credentials}/resolve-owner-key.d.ts +1 -1
  44. package/lib/mcp/{tools/credentials → credentials}/resolve-owner-key.js +2 -2
  45. package/lib/mcp/credentials/session-cache.d.ts +14 -0
  46. package/lib/mcp/credentials/session-cache.js +42 -0
  47. package/lib/mcp/{tools/credentials → credentials}/status.d.ts +1 -1
  48. package/lib/mcp/credentials/status.js +76 -0
  49. package/lib/mcp/instructions.d.ts +1 -0
  50. package/lib/mcp/instructions.js +11 -0
  51. package/lib/mcp/register.d.ts +38 -0
  52. package/lib/mcp/register.js +80 -0
  53. package/lib/mcp/server.d.ts +2 -8
  54. package/lib/mcp/server.js +3 -33
  55. package/lib/mcp/start.js +17 -11
  56. package/lib/mcp/tools/agent/build.d.ts +5 -9
  57. package/lib/mcp/tools/agent/build.js +7 -24
  58. package/lib/mcp/tools/agent/index.d.ts +2 -0
  59. package/lib/mcp/tools/agent/index.js +3 -0
  60. package/lib/mcp/tools/agent/proof.js +3 -7
  61. package/lib/mcp/tools/agent/propose.js +13 -2
  62. package/lib/mcp/tools/agent/publish.js +172 -75
  63. package/lib/mcp/tools/agent/replay.js +0 -5
  64. package/lib/mcp/tools/analyze.d.ts +3 -0
  65. package/lib/mcp/tools/analyze.js +26 -0
  66. package/lib/mcp/tools/attach.d.ts +11 -0
  67. package/lib/mcp/tools/attach.js +72 -0
  68. package/lib/mcp/tools/authenticate/authenticate.js +107 -0
  69. package/lib/mcp/tools/authenticate/build.d.ts +15 -0
  70. package/lib/mcp/tools/authenticate/build.js +28 -0
  71. package/lib/mcp/tools/authenticate/decrypt-key.d.ts +19 -0
  72. package/lib/mcp/tools/authenticate/decrypt-key.js +46 -0
  73. package/lib/mcp/tools/authenticate/eth-key.d.ts +31 -0
  74. package/lib/mcp/tools/authenticate/eth-key.js +116 -0
  75. package/lib/mcp/tools/authenticate/import.js +57 -0
  76. package/lib/mcp/tools/authenticate/index.d.ts +2 -0
  77. package/lib/mcp/tools/authenticate/index.js +4 -0
  78. package/lib/mcp/tools/authenticate/issue.js +42 -0
  79. package/lib/mcp/tools/authenticate/resolve-owner-key.d.ts +13 -0
  80. package/lib/mcp/tools/authenticate/resolve-owner-key.js +53 -0
  81. package/lib/mcp/tools/capture.d.ts +10 -0
  82. package/lib/mcp/tools/capture.js +142 -0
  83. package/lib/mcp/tools/eval.d.ts +5 -0
  84. package/lib/mcp/tools/eval.js +127 -0
  85. package/lib/mcp/tools/find.d.ts +3 -0
  86. package/lib/mcp/tools/find.js +60 -0
  87. package/lib/mcp/tools/index.d.ts +3 -0
  88. package/lib/mcp/tools/index.js +6 -0
  89. package/lib/mcp/tools/owner-key.d.ts +2 -0
  90. package/lib/mcp/tools/owner-key.js +63 -0
  91. package/lib/mcp/tools/proof.d.ts +3 -0
  92. package/lib/mcp/tools/proof.js +214 -0
  93. package/lib/mcp/tools/propose.d.ts +9 -0
  94. package/lib/mcp/tools/propose.js +75 -0
  95. package/lib/mcp/tools/publish.d.ts +3 -0
  96. package/lib/mcp/tools/publish.js +59 -0
  97. package/lib/mcp/tools/replay.d.ts +3 -0
  98. package/lib/mcp/tools/replay.js +46 -0
  99. package/lib/mcp/tools/session.d.ts +10 -0
  100. package/lib/mcp/tools/session.js +29 -0
  101. package/lib/mcp/tools/verification/build.d.ts +12 -0
  102. package/lib/mcp/tools/verification/build.js +14 -0
  103. package/lib/mcp/tools/verification/diagnose.d.ts +11 -0
  104. package/lib/mcp/tools/verification/diagnose.js +132 -0
  105. package/lib/mcp/tools/verification/index.d.ts +1 -0
  106. package/lib/mcp/tools/verification/index.js +2 -0
  107. package/lib/mcp/tools/verification/result.d.ts +11 -0
  108. package/lib/mcp/tools/verification/result.js +126 -0
  109. package/lib/mcp/verifications/build.d.ts +5 -0
  110. package/lib/mcp/verifications/build.js +14 -0
  111. package/lib/mcp/verifications/create.d.ts +3 -0
  112. package/lib/mcp/verifications/create.js +57 -0
  113. package/lib/mcp/verifications/find.d.ts +3 -0
  114. package/lib/mcp/verifications/find.js +37 -0
  115. package/lib/mcp/verifications/get.d.ts +3 -0
  116. package/lib/mcp/verifications/get.js +26 -0
  117. package/lib/mcp/verifications/update.d.ts +3 -0
  118. package/lib/mcp/verifications/update.js +78 -0
  119. package/lib/old/client.d.ts +3 -0
  120. package/lib/old/flag.d.ts +4 -1
  121. package/lib/old/flag.js +4 -3
  122. package/lib/old/identity.d.ts +0 -10
  123. package/lib/old/identity.js +8 -7
  124. package/lib/old/instructions.d.ts +0 -6
  125. package/lib/old/instructions.js +6 -24
  126. package/lib/old/login-cdp.d.ts +0 -3
  127. package/lib/old/login-cdp.js +2 -4
  128. package/lib/old/to-register.d.ts +3 -0
  129. package/lib/old/to-register.js +32 -7
  130. package/lib/old/tools/authenticate.js +2 -1
  131. package/lib/old/tools/publish.js +71 -10
  132. package/lib/paths.js +2 -2
  133. package/lib/proof/attestor.d.ts +33 -1
  134. package/lib/proof/attestor.js +67 -64
  135. package/lib/proof/index.d.ts +5 -0
  136. package/lib/proof/index.js +6 -0
  137. package/lib/proof/proof-core.d.ts +35 -0
  138. package/lib/proof/proof-core.js +84 -0
  139. package/lib/provider/index.d.ts +5 -0
  140. package/lib/provider/index.js +9 -0
  141. package/lib/provider/injection-doc.d.ts +1 -0
  142. package/lib/provider/injection-doc.js +17 -0
  143. package/lib/provider/match-redaction-warning.d.ts +25 -0
  144. package/lib/provider/match-redaction-warning.js +35 -0
  145. package/lib/provider/schema.d.ts +16 -0
  146. package/lib/provider/schema.js +11 -1
  147. package/lib/provider/to-version.d.ts +61 -12
  148. package/lib/provider/to-version.js +109 -24
  149. package/lib/provider/verification-checks.d.ts +12 -0
  150. package/lib/provider/verification-checks.js +30 -0
  151. package/lib/routes.gen.d.ts +271 -0
  152. package/lib/routes.gen.js +73 -0
  153. package/lib/types/openapi.gen.d.ts +3967 -0
  154. package/lib/types/openapi.gen.js +5 -0
  155. package/package.json +16 -7
  156. package/skill/SKILL.md +35 -14
  157. package/skill/builder-mode.md +13 -0
  158. package/skill/injection-api.md +42 -0
  159. package/skill/old-mode.md +15 -0
  160. package/src/cdp/capture-engine.ts +256 -0
  161. package/src/cdp/capture.ts +25 -185
  162. package/src/cdp/index.ts +6 -0
  163. package/src/cdp/launcher.ts +5 -4
  164. package/src/config/store.ts +7 -6
  165. package/src/consts.ts +164 -0
  166. package/src/index.ts +2 -4
  167. package/src/logger.ts +2 -1
  168. package/src/mcp/api/operations.gen.ts +1155 -194
  169. package/src/mcp/api/to-zod.ts +115 -0
  170. package/src/mcp/api/tools.ts +9 -3
  171. package/src/mcp/instructions.ts +15 -0
  172. package/src/mcp/server.ts +5 -50
  173. package/src/mcp/start.ts +27 -11
  174. package/src/mcp/tools/agent/build.ts +7 -27
  175. package/src/mcp/tools/agent/index.ts +4 -0
  176. package/src/mcp/tools/agent/proof.ts +3 -8
  177. package/src/mcp/tools/agent/propose.ts +13 -2
  178. package/src/mcp/tools/agent/publish.ts +218 -92
  179. package/src/mcp/tools/agent/replay.ts +0 -5
  180. package/src/mcp/tools/{credentials → authenticate}/authenticate.ts +9 -8
  181. package/src/mcp/tools/authenticate/build.ts +32 -0
  182. package/src/mcp/tools/authenticate/decrypt-key.ts +59 -0
  183. package/src/mcp/tools/authenticate/eth-key.ts +162 -0
  184. package/src/mcp/tools/authenticate/import.ts +73 -0
  185. package/src/mcp/tools/authenticate/index.ts +4 -0
  186. package/src/mcp/tools/authenticate/issue.ts +50 -0
  187. package/src/mcp/tools/authenticate/resolve-owner-key.ts +60 -0
  188. package/src/mcp/tools/index.ts +6 -0
  189. package/src/mcp/tools/verification/build.ts +16 -0
  190. package/src/mcp/tools/verification/index.ts +2 -0
  191. package/src/mcp/tools/verification/result.ts +154 -0
  192. package/src/old/client.ts +3 -0
  193. package/src/old/flag.ts +4 -3
  194. package/src/old/identity.ts +8 -7
  195. package/src/old/instructions.ts +10 -25
  196. package/src/old/login-cdp.ts +2 -5
  197. package/src/old/to-register.ts +58 -26
  198. package/src/old/tools/authenticate.ts +2 -1
  199. package/src/old/tools/publish.ts +92 -16
  200. package/src/paths.ts +2 -2
  201. package/src/proof/attestor.ts +114 -72
  202. package/src/proof/index.ts +21 -0
  203. package/src/proof/proof-core.ts +119 -0
  204. package/src/provider/index.ts +20 -0
  205. package/src/provider/injection-doc.ts +21 -0
  206. package/src/provider/match-redaction-warning.ts +53 -0
  207. package/src/provider/schema.ts +23 -0
  208. package/src/provider/to-version.ts +180 -33
  209. package/src/provider/verification-checks.ts +36 -0
  210. package/lib/mcp/tools/credentials/build.d.ts +0 -16
  211. package/lib/mcp/tools/credentials/build.js +0 -33
  212. package/lib/mcp/tools/credentials/status.js +0 -62
  213. package/src/mcp/tools/credentials/build.ts +0 -37
  214. package/src/mcp/tools/credentials/cache.ts +0 -161
  215. package/src/mcp/tools/credentials/env-file.ts +0 -101
  216. package/src/mcp/tools/credentials/import.ts +0 -72
  217. package/src/mcp/tools/credentials/issue.ts +0 -107
  218. package/src/mcp/tools/credentials/list-cached.ts +0 -66
  219. package/src/mcp/tools/credentials/register.ts +0 -49
  220. package/src/mcp/tools/credentials/resolve-owner-key.ts +0 -78
  221. package/src/mcp/tools/credentials/status.ts +0 -82
  222. package/src/types/openapi.ts +0 -7
  223. /package/lib/mcp/{tools/credentials → credentials}/env-file.d.ts +0 -0
  224. /package/lib/mcp/{tools/credentials → credentials}/env-file.js +0 -0
  225. /package/lib/mcp/{tools/credentials → credentials}/register.d.ts +0 -0
  226. /package/lib/mcp/{tools/credentials → credentials}/register.js +0 -0
  227. /package/lib/mcp/tools/{credentials → authenticate}/authenticate.d.ts +0 -0
  228. /package/lib/mcp/tools/{credentials → authenticate}/import.d.ts +0 -0
  229. /package/lib/mcp/tools/{credentials → authenticate}/issue.d.ts +0 -0
  230. /package/lib/mcp/tools/{credentials → authenticate}/session-cache.d.ts +0 -0
  231. /package/lib/mcp/tools/{credentials → authenticate}/session-cache.js +0 -0
  232. /package/src/mcp/tools/{credentials → authenticate}/session-cache.ts +0 -0
@@ -1,101 +0,0 @@
1
- import {
2
- appendFileSync,
3
- chmodSync,
4
- existsSync,
5
- readFileSync,
6
- writeFileSync,
7
- } from 'node:fs'
8
- import { join } from 'node:path'
9
-
10
- const PRIVATE_KEY = 'RECLAIM_PRIVATE_KEY'
11
- const GITIGNORE_LINE = '.env'
12
-
13
- export type EnvWriteResult = {
14
- envPath: string
15
- gitignorePath: string
16
- gitignoreAppended: boolean
17
- }
18
-
19
- /**
20
- * Idempotently set `RECLAIM_PRIVATE_KEY` in the project's `.env`, then
21
- * `chmod 0600` it. The private key is the only secret we write — the
22
- * ETH address (and public key) are derived from it on demand, so there
23
- * is no separate address variable to keep in sync. Existing variables
24
- * are replaced in place; other lines are preserved verbatim so we
25
- * don't trample on unrelated config the user wrote by hand.
26
- *
27
- * Also appends `.env` to the project's `.gitignore` if it isn't
28
- * already listed.
29
- */
30
- export function writeAppCredentialsToEnv(
31
- projectDir: string,
32
- privateKey: string,
33
- ): EnvWriteResult {
34
- const envPath = join(projectDir, '.env')
35
- const lines = existsSync(envPath)
36
- ? readFileSync(envPath, 'utf8').split('\n')
37
- : []
38
-
39
- setOrInsert(lines, PRIVATE_KEY, privateKey)
40
-
41
- const body = lines.join('\n').replace(/\n+$/, '') + '\n'
42
- writeFileSync(envPath, body, { mode: 0o600 })
43
- chmodSync(envPath, 0o600)
44
-
45
- const gitignorePath = join(projectDir, '.gitignore')
46
- const gitignoreAppended = ensureLine(gitignorePath, GITIGNORE_LINE)
47
-
48
- return { envPath, gitignorePath, gitignoreAppended }
49
- }
50
-
51
- /**
52
- * Read `RECLAIM_PRIVATE_KEY` back out of the project's `.env`, if set.
53
- * Read live (not from `process.env`) so a credential written by
54
- * `issue_credentials` / `import_credentials` is picked up immediately,
55
- * without a Claude Code restart. Returns undefined when the file or the
56
- * variable is absent.
57
- */
58
- export function readPrivateKeyFromEnvFile(
59
- projectDir: string,
60
- ): string | undefined {
61
- const envPath = join(projectDir, '.env')
62
- if(!existsSync(envPath)) {
63
- return undefined
64
- }
65
-
66
- const prefix = `${PRIVATE_KEY}=`
67
- const line = readFileSync(envPath, 'utf8')
68
- .split('\n')
69
- .find((l) => l.startsWith(prefix))
70
- const value = line?.slice(prefix.length).trim()
71
- return value || undefined
72
- }
73
-
74
- function setOrInsert(lines: string[], key: string, value: string) {
75
- const prefix = `${key}=`
76
- const idx = lines.findIndex((l) => l.startsWith(prefix))
77
- const next = `${key}=${value}`
78
- if(idx >= 0) {
79
- lines[idx] = next
80
- return
81
- }
82
-
83
- lines.push(next)
84
- }
85
-
86
- function ensureLine(path: string, line: string): boolean {
87
- if(!existsSync(path)) {
88
- writeFileSync(path, line + '\n', { mode: 0o644 })
89
- return true
90
- }
91
-
92
- const body = readFileSync(path, 'utf8')
93
- const present = body.split('\n').some((l) => l.trim() === line)
94
- if(present) {
95
- return false
96
- }
97
-
98
- const suffix = body.endsWith('\n') ? '' : '\n'
99
- appendFileSync(path, suffix + line + '\n')
100
- return true
101
- }
@@ -1,72 +0,0 @@
1
- import { deriveFromPrivateKey } from '@reclaimprotocol/client'
2
- import { findProjectRoot } from '../../../paths.ts'
3
- import { defineTool, type RegisteredTool } from '../../server.ts'
4
- import { persistCredentialLocally } from './register.ts'
5
-
6
- export function importTool(): RegisteredTool {
7
- return defineTool<{
8
- privateKey: string
9
- label?: string
10
- projectDir?: string
11
- writeEnv?: boolean
12
- }>(
13
- {
14
- name: 'import_credentials',
15
- description:
16
- 'Import an existing Reclaim app credential the user ' +
17
- 'already holds elsewhere. Provide the private key ' +
18
- '(0x-prefixed hex, 64 chars); we derive the address ' +
19
- 'locally and cache it. By default also writes ' +
20
- 'RECLAIM_PRIVATE_KEY to the project .env (0600) and appends ' +
21
- '.env to .gitignore; pass `writeEnv: false` to keep it in ' +
22
- 'the local cache (memory) only and leave .env untouched. ' +
23
- 'ALWAYS ask the dev whether to save to .env before writing. ' +
24
- 'The credential stays local-only (SANDBOX); link it to an ' +
25
- 'org to use it in production.',
26
- inputSchema: {
27
- type: 'object',
28
- properties: {
29
- privateKey: {
30
- type: 'string',
31
- pattern: '^0x[0-9a-fA-F]{64}$',
32
- description:
33
- '0x-prefixed hex private key (64 hex chars / 32 bytes).',
34
- },
35
- label: {
36
- type: 'string',
37
- minLength: 1,
38
- maxLength: 100,
39
- },
40
- projectDir: {
41
- type: 'string',
42
- description:
43
- 'Project directory to write .env into. Defaults ' +
44
- 'to the closest ancestor of cwd containing ' +
45
- '.git or package.json.',
46
- },
47
- writeEnv: {
48
- type: 'boolean',
49
- description:
50
- 'Write RECLAIM_PRIVATE_KEY to the project .env ' +
51
- '(default true). Set false to cache in memory only, ' +
52
- 'without touching .env.',
53
- },
54
- },
55
- required: ['privateKey'],
56
- },
57
- },
58
- async(args) => {
59
- const keypair = deriveFromPrivateKey(args.privateKey)
60
- const projectDir = findProjectRoot(args.projectDir || process.cwd())
61
-
62
- const persisted = persistCredentialLocally(
63
- keypair,
64
- args.label,
65
- projectDir,
66
- args.writeEnv ?? true,
67
- )
68
-
69
- return { ...persisted }
70
- },
71
- )
72
- }
@@ -1,107 +0,0 @@
1
- import { generateKeypair } from '@reclaimprotocol/client'
2
- import { findProjectRoot } from '../../../paths.ts'
3
- import { defineTool, type RegisteredTool } from '../../server.ts'
4
- import { findCredentialFromCachedBy } from './cache.ts'
5
- import { persistCredentialLocally } from './register.ts'
6
-
7
- export function issueTool(): RegisteredTool {
8
- return defineTool<{
9
- reuseCachedAppPk?: string
10
- label?: string
11
- projectDir?: string
12
- writeEnv?: boolean
13
- }>(
14
- {
15
- name: 'issue_credentials',
16
- description:
17
- 'Mint a fresh anonymous Reclaim app key-pair (or reuse ' +
18
- 'a cached one via `reuseCachedAppPk`) and cache it locally. ' +
19
- 'By default also writes RECLAIM_PRIVATE_KEY to the project ' +
20
- '.env (mode 0600) and appends .env to .gitignore; pass ' +
21
- '`writeEnv: false` to keep it in the local cache (memory) ' +
22
- 'only and leave .env untouched. ALWAYS ask the dev whether ' +
23
- 'to save to .env before writing it. The key-pair is ' +
24
- 'generated locally and is NOT registered with the server — ' +
25
- 'anonymous credentials operate in SANDBOX mode entirely ' +
26
- 'client-side. PREFER REUSE over generating a new credential ' +
27
- 'unless the user explicitly asks for a new app identity. To ' +
28
- 'use a credential for verification in production, link it to ' +
29
- 'an organization (via link_credential) and add billing.',
30
- inputSchema: {
31
- type: 'object',
32
- properties: {
33
- reuseCachedAppPk: {
34
- type: 'string',
35
- pattern: '^0x[0-9a-fA-F]{40}$',
36
- description:
37
- 'Lowercase ETH address of a cached credential ' +
38
- 'to reuse instead of minting a new one.',
39
- },
40
- label: {
41
- type: 'string',
42
- minLength: 1,
43
- maxLength: 100,
44
- description: 'Human label stored in the local cache.',
45
- },
46
- projectDir: {
47
- type: 'string',
48
- description:
49
- 'Project directory to write .env into. Defaults ' +
50
- 'to the closest ancestor of cwd containing ' +
51
- '.git or package.json.',
52
- },
53
- writeEnv: {
54
- type: 'boolean',
55
- description:
56
- 'Write RECLAIM_PRIVATE_KEY to the project .env ' +
57
- '(default true). Set false to cache the credential ' +
58
- 'in memory only, without touching .env.',
59
- },
60
- },
61
- },
62
- },
63
- async(args) => {
64
- const projectDir = findProjectRoot(args.projectDir || process.cwd())
65
- let keypair: { address: string, privateKey: string } | undefined
66
- let reused = false
67
-
68
- if(args.reuseCachedAppPk) {
69
- const cached = findCredentialFromCachedBy(args.reuseCachedAppPk)
70
- if(!cached) {
71
- throw new Error(
72
- `No cached credential for ${args.reuseCachedAppPk}. ` +
73
- 'Call list_cached_credentials first.',
74
- )
75
- }
76
-
77
- keypair = {
78
- address: cached.address,
79
- privateKey: cached.privateKey,
80
- }
81
- reused = true
82
- } else {
83
- keypair = generateKeypair()
84
- }
85
-
86
- const writeEnv = args.writeEnv ?? true
87
- const persisted = persistCredentialLocally(
88
- keypair,
89
- args.label,
90
- projectDir,
91
- writeEnv,
92
- )
93
-
94
- return {
95
- reused,
96
- ...persisted,
97
- note: writeEnv
98
- ? 'Private key written to .env (and the local cache); it is ' +
99
- 'NOT in this response on purpose. The credential is ' +
100
- 'local-only (SANDBOX); link it to an org for production.'
101
- : 'Private key cached in memory only (.env untouched). Sign ' +
102
- 'proofs with it by passing run_proof({ ownerAddress }). The ' +
103
- 'credential is local-only (SANDBOX).',
104
- }
105
- },
106
- )
107
- }
@@ -1,66 +0,0 @@
1
- import { findProjectRoot } from '../../../paths.ts'
2
- import { defineTool, type RegisteredTool } from '../../server.ts'
3
- import { readCredentialsFromCache, suggestCredentialForDir } from './cache.ts'
4
-
5
- export function listCachedTool(): RegisteredTool {
6
- return defineTool<Record<string, never>>(
7
- {
8
- name: 'list_cached_credentials',
9
- description:
10
- 'List Reclaim app credentials (ETH key-pairs) cached ' +
11
- 'locally in ~/.reclaim/config.json. Returns one ' +
12
- 'row per credential with address, optional label and ' +
13
- 'orgId, createdAt, createdIn (where it was first created), ' +
14
- 'and the project directories that have used it. Private keys ' +
15
- 'are stripped. The response also reports `currentDir` and ' +
16
- 'flags the best credential for it (`suggested`, plus ' +
17
- '`suggestedAddress`/`suggestionReason`) — prefer reusing that ' +
18
- 'one over minting a new credential. When the cache is empty a ' +
19
- '`suggestion` string explains how to create one.',
20
- inputSchema: {
21
- type: 'object',
22
- properties: {},
23
- },
24
- },
25
- async() => {
26
- const doc = readCredentialsFromCache()
27
- const currentDir = findProjectRoot(process.cwd())
28
- const suggestion = suggestCredentialForDir(currentDir, doc.credentials)
29
- const suggestedAddress = suggestion?.credential.address
30
-
31
- const items = doc.credentials.map((c) => ({
32
- address: c.address,
33
- label: c.label,
34
- orgId: c.orgId,
35
- createdAt: c.createdAt,
36
- createdIn: c.createdIn,
37
- projectDirs: c.projectDirs,
38
- matchesCurrentDir:
39
- c.createdIn === currentDir || c.projectDirs.includes(currentDir),
40
- suggested: c.address === suggestedAddress,
41
- }))
42
-
43
- // Promote the single suggested row to the top; stable sort keeps
44
- // the rest in insertion (newest-first) order.
45
- items.sort((a, b) => Number(b.suggested) - Number(a.suggested))
46
-
47
- if(items.length === 0) {
48
- return {
49
- items,
50
- currentDir,
51
- suggestion:
52
- 'No cached credentials. Call issue_credentials to mint a new ' +
53
- 'app key-pair, or import_credentials if you already hold a ' +
54
- 'private key. Do not invent credentials.',
55
- }
56
- }
57
-
58
- return {
59
- items,
60
- currentDir,
61
- suggestedAddress,
62
- suggestionReason: suggestion?.reason,
63
- }
64
- },
65
- )
66
- }
@@ -1,49 +0,0 @@
1
- import type { EthKeypair } from '@reclaimprotocol/client'
2
- import { type CachedCredential, upsertCredential } from './cache.ts'
3
- import { type EnvWriteResult, writeAppCredentialsToEnv } from './env-file.ts'
4
-
5
- /** Shape returned by `persistCredentialLocally` — the fields both
6
- * `issue_credentials` and `import_credentials` expose in their MCP
7
- * responses. The env-file fields are present only when the credential
8
- * was persisted to `.env` (`writeEnv: true`); a memory-only credential
9
- * lives in the cache and omits them. */
10
- export type PersistedCredential = Pick<
11
- CachedCredential,
12
- 'address' | 'label'
13
- > &
14
- Partial<EnvWriteResult> & { wroteEnv: boolean }
15
-
16
- /** Local persistence step shared by `issue_credentials` and
17
- * `import_credentials`. Always upserts the credentials cache; when
18
- * `writeEnv` is true (default) it also writes `RECLAIM_PRIVATE_KEY` to
19
- * the project `.env` (0600) and appends `.env` to `.gitignore`. Pass
20
- * `writeEnv: false` to keep the credential in the cache (memory) only,
21
- * without touching the project's `.env`. */
22
- export function persistCredentialLocally(
23
- keypair: EthKeypair,
24
- label: string | undefined,
25
- projectDir: string,
26
- writeEnv = true,
27
- ): PersistedCredential {
28
- const cached = upsertCredential({
29
- address: keypair.address,
30
- privateKey: keypair.privateKey,
31
- label,
32
- createdAt: new Date().toISOString(),
33
- createdIn: projectDir,
34
- projectDirs: [projectDir],
35
- })
36
- if(!writeEnv) {
37
- return { address: cached.address, label: cached.label, wroteEnv: false }
38
- }
39
-
40
- const env = writeAppCredentialsToEnv(projectDir, keypair.privateKey)
41
- return {
42
- address: cached.address,
43
- label: cached.label,
44
- wroteEnv: true,
45
- envPath: env.envPath,
46
- gitignorePath: env.gitignorePath,
47
- gitignoreAppended: env.gitignoreAppended,
48
- }
49
- }
@@ -1,78 +0,0 @@
1
- import { deriveFromPrivateKey } from '@reclaimprotocol/client'
2
- import { findProjectRoot } from '../../../paths.ts'
3
- import { defineTool, type RegisteredTool } from '../../server.ts'
4
- import { suggestCredentialForDir } from './cache.ts'
5
- import { readPrivateKeyFromEnvFile } from './env-file.ts'
6
-
7
- /**
8
- * Decide which app credential `run_proof` should sign with, BEFORE
9
- * calling it. `run_proof` requires an `ownerAddress` and does no
10
- * resolution of its own — this is the single place that "checks memory,
11
- * env, etc and offers options".
12
- *
13
- * Checks, in order: `RECLAIM_PRIVATE_KEY` in the MCP env → the project
14
- * `.env` → the best cached credential for this directory. Never returns
15
- * the private key — only the address to pass through as `ownerAddress`.
16
- */
17
- export function resolveOwnerKeyTool(): RegisteredTool {
18
- return defineTool<Record<string, never>>(
19
- {
20
- name: 'resolve_owner_key',
21
- description:
22
- 'Resolve which app credential run_proof should sign with — ' +
23
- 'call this BEFORE run_proof. Checks, in order: ' +
24
- 'RECLAIM_PRIVATE_KEY in the MCP env, RECLAIM_PRIVATE_KEY in the ' +
25
- 'project .env, then the best cached credential for this ' +
26
- 'directory. Returns { ready: true, address, source } when one ' +
27
- 'is available — pass `address` to run_proof as `ownerAddress`. ' +
28
- 'Returns { ready: false } when none exists: then ask the dev to ' +
29
- 'provide a private key (import_credentials) or create one ' +
30
- '(issue_credentials) — optionally with writeEnv:false to keep ' +
31
- 'it in the local cache (memory) only — and call resolve_owner_key ' +
32
- 'again. Never exposes the private key.',
33
- inputSchema: { type: 'object', properties: {} },
34
- },
35
- async() => {
36
- const dir = findProjectRoot(process.cwd())
37
-
38
- const envKey = process.env.RECLAIM_PRIVATE_KEY
39
- if(envKey) {
40
- return {
41
- ready: true,
42
- address: deriveFromPrivateKey(envKey).address,
43
- source: 'env',
44
- }
45
- }
46
-
47
- const dotenvKey = readPrivateKeyFromEnvFile(dir)
48
- if(dotenvKey) {
49
- return {
50
- ready: true,
51
- address: deriveFromPrivateKey(dotenvKey).address,
52
- source: 'dotenv',
53
- }
54
- }
55
-
56
- const suggestion = suggestCredentialForDir(dir)
57
- if(suggestion) {
58
- return {
59
- ready: true,
60
- address: suggestion.credential.address,
61
- source: 'cache',
62
- reason: suggestion.reason,
63
- }
64
- }
65
-
66
- return {
67
- ready: false,
68
- message:
69
- 'No app credential available (no RECLAIM_PRIVATE_KEY in env ' +
70
- 'or .env, and the cache is empty). Ask the dev to provide ' +
71
- 'their private key via import_credentials, or create one via ' +
72
- 'issue_credentials (pass writeEnv:false to keep it out of ' +
73
- '.env). Then call resolve_owner_key again and pass its ' +
74
- 'address to run_proof as ownerAddress.',
75
- }
76
- },
77
- )
78
- }
@@ -1,82 +0,0 @@
1
- import {
2
- deriveFromPrivateKey,
3
- type ReclaimClient,
4
- } from '@reclaimprotocol/client'
5
- import assert from 'node:assert'
6
- import { findProjectRoot } from '../../../paths.ts'
7
- import { defineTool, type RegisteredTool } from '../../server.ts'
8
- import { suggestCredentialForDir } from './cache.ts'
9
-
10
- export function statusTool(client: ReclaimClient): RegisteredTool {
11
- return defineTool<{ address?: string }>(
12
- {
13
- name: 'reclaim_status',
14
- description:
15
- 'Report the live mode (SANDBOX | PRODUCTION | REVOKED) ' +
16
- 'of a Reclaim app credential. Pass `address` — or omit it ' +
17
- 'to derive the address from RECLAIM_PRIVATE_KEY, falling ' +
18
- 'back to the best cached credential for this directory. ' +
19
- 'Useful to confirm a credential is linked to an org ' +
20
- 'with billing before running a production flow.',
21
- inputSchema: {
22
- type: 'object',
23
- properties: {
24
- address: {
25
- type: 'string',
26
- pattern: '^0x[0-9a-fA-F]{40}$',
27
- description:
28
- 'Lowercase ETH address. Defaults to the address ' +
29
- 'derived from RECLAIM_PRIVATE_KEY, then the cached ' +
30
- 'credential suggested for the current directory.',
31
- },
32
- },
33
- },
34
- },
35
- async(args) => {
36
- let address = args.address?.toLowerCase()
37
- if(!address && process.env.RECLAIM_PRIVATE_KEY) {
38
- address = deriveFromPrivateKey(process.env.RECLAIM_PRIVATE_KEY).address
39
- }
40
-
41
- if(!address) {
42
- address = suggestCredentialForDir(findProjectRoot(process.cwd()))
43
- ?.credential.address
44
- }
45
-
46
- assert(
47
- address,
48
- new Error(
49
- 'No address given, RECLAIM_PRIVATE_KEY is not set, and the ' +
50
- 'cache is empty. Run issue_credentials or import_credentials ' +
51
- 'first.',
52
- )
53
- )
54
-
55
- const credResult = await client
56
- .call('GetCredentialByAddress', { params: { address } })
57
- const cred = credResult.data
58
-
59
- // A registered credential always carries an `id`; its absence means
60
- // the server had no row for this address — a local-only credential.
61
- const localOnly = !cred.id
62
-
63
- return {
64
- address: cred.address,
65
- mode: cred.mode,
66
- orgId: cred.orgId,
67
- label: cred.label,
68
- revokedAt: cred.revokedAt,
69
- lastUsedAt: cred.lastUsedAt,
70
- ...(localOnly ? {
71
- note:
72
- 'Local-only credential — not registered with the server. '
73
- + 'It operates in SANDBOX, which is all you need to publish '
74
- + 'a verification (only an auth token is required — no '
75
- + 'credential link). Linking it to an org with billing (via '
76
- + 'link_credential) is only needed for the upcoming feature '
77
- + 'that runs verifications for your own app’s users.',
78
- } : {}),
79
- }
80
- },
81
- )
82
- }
@@ -1,7 +0,0 @@
1
- import type { components } from '@reclaimprotocol/client'
2
-
3
- export type CredentialAttachSession =
4
- components['schemas']['CredentialAttachSession']
5
- export type CreateProviderVersionRequest =
6
- components['schemas']['CreateProviderVersionRequest']
7
- export type ProviderVersionRef = components['schemas']['ProviderVersionRef']