@reclaimprotocol/agent 0.1.32 → 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/lib/authoring/backend.d.ts +13 -0
  2. package/lib/authoring/index.d.ts +1 -1
  3. package/lib/authoring/tools.js +78 -42
  4. package/lib/config/store.d.ts +10 -0
  5. package/lib/mcp/api/operations.gen.d.ts +247 -4
  6. package/lib/mcp/api/operations.gen.js +6519 -337
  7. package/lib/mcp/api/tools.d.ts +10 -2
  8. package/lib/mcp/api/tools.js +55 -4
  9. package/lib/mcp/instructions.js +11 -11
  10. package/lib/mcp/server.d.ts +1 -1
  11. package/lib/mcp/server.js +3 -0
  12. package/lib/mcp/start.js +6 -1
  13. package/lib/mcp/success-response.js +5 -1
  14. package/lib/mcp/tools/agent/analyze.js +5 -4
  15. package/lib/mcp/tools/agent/attach.js +11 -7
  16. package/lib/mcp/tools/agent/build.js +3 -1
  17. package/lib/mcp/tools/agent/capture.d.ts +2 -2
  18. package/lib/mcp/tools/agent/capture.js +15 -11
  19. package/lib/mcp/tools/agent/eval.js +4 -3
  20. package/lib/mcp/tools/agent/find.js +9 -10
  21. package/lib/mcp/tools/agent/how-it-works.js +1 -0
  22. package/lib/mcp/tools/agent/live-view.js +10 -7
  23. package/lib/mcp/tools/agent/pod-proof.js +7 -11
  24. package/lib/mcp/tools/agent/propose.js +4 -3
  25. package/lib/mcp/tools/agent/publish.d.ts +2 -1
  26. package/lib/mcp/tools/agent/publish.js +12 -6
  27. package/lib/mcp/tools/agent/replay.js +10 -7
  28. package/lib/mcp/tools/agent/session.js +16 -8
  29. package/lib/mcp/tools/agent/shared.js +3 -2
  30. package/lib/mcp/tools/agent/start-integration.d.ts +15 -0
  31. package/lib/mcp/tools/agent/start-integration.js +61 -0
  32. package/lib/mcp/tools/authenticate/authenticate.js +9 -11
  33. package/lib/mcp/tools/authenticate/build.js +2 -0
  34. package/lib/mcp/tools/authenticate/builder-access.js +1 -0
  35. package/lib/mcp/tools/authenticate/eth-key.d.ts +8 -0
  36. package/lib/mcp/tools/authenticate/eth-key.js +27 -15
  37. package/lib/mcp/tools/authenticate/import.js +18 -31
  38. package/lib/mcp/tools/authenticate/issue-org-token.d.ts +8 -0
  39. package/lib/mcp/tools/authenticate/issue-org-token.js +60 -0
  40. package/lib/mcp/tools/authenticate/issue.js +9 -9
  41. package/lib/mcp/tools/authenticate/org-key-store.d.ts +10 -0
  42. package/lib/mcp/tools/authenticate/org-key-store.js +23 -0
  43. package/lib/mcp/tools/authenticate/resolve-owner-key.js +10 -12
  44. package/lib/mcp/tools/mode/mode.js +2 -0
  45. package/lib/mcp/tools/verification/result.js +52 -12
  46. package/lib/tools/registry.d.ts +12 -0
  47. package/lib/tools/registry.js +1 -0
  48. package/package.json +2 -2
  49. package/skill/SKILL.builder.md +77 -73
  50. package/skill/SKILL.common.md +2 -1
  51. package/skill/builder-mode.md +135 -120
  52. package/skill/start-integration.md +49 -0
  53. package/skill/user-script.md +64 -0
  54. package/skill/verification-client-integration.md +131 -28
  55. package/src/authoring/backend.ts +15 -0
  56. package/src/authoring/index.ts +2 -0
  57. package/src/authoring/tools.ts +86 -42
  58. package/src/config/store.ts +11 -0
  59. package/src/mcp/api/operations.gen.ts +6563 -373
  60. package/src/mcp/api/tools.ts +70 -5
  61. package/src/mcp/instructions.ts +11 -11
  62. package/src/mcp/server.ts +4 -0
  63. package/src/mcp/start.ts +6 -1
  64. package/src/mcp/success-response.ts +5 -1
  65. package/src/mcp/tools/agent/analyze.ts +5 -4
  66. package/src/mcp/tools/agent/attach.ts +11 -7
  67. package/src/mcp/tools/agent/build.ts +5 -1
  68. package/src/mcp/tools/agent/capture.ts +20 -12
  69. package/src/mcp/tools/agent/eval.ts +4 -3
  70. package/src/mcp/tools/agent/find.ts +9 -10
  71. package/src/mcp/tools/agent/how-it-works.ts +1 -0
  72. package/src/mcp/tools/agent/live-view.ts +10 -7
  73. package/src/mcp/tools/agent/pod-proof.ts +7 -11
  74. package/src/mcp/tools/agent/propose.ts +4 -3
  75. package/src/mcp/tools/agent/publish.ts +12 -4
  76. package/src/mcp/tools/agent/replay.ts +10 -7
  77. package/src/mcp/tools/agent/session.ts +16 -8
  78. package/src/mcp/tools/agent/shared.ts +7 -2
  79. package/src/mcp/tools/agent/start-integration.ts +83 -0
  80. package/src/mcp/tools/authenticate/authenticate.ts +9 -11
  81. package/src/mcp/tools/authenticate/build.ts +2 -0
  82. package/src/mcp/tools/authenticate/builder-access.ts +1 -0
  83. package/src/mcp/tools/authenticate/eth-key.ts +48 -18
  84. package/src/mcp/tools/authenticate/import.ts +21 -36
  85. package/src/mcp/tools/authenticate/issue-org-token.ts +84 -0
  86. package/src/mcp/tools/authenticate/issue.ts +9 -9
  87. package/src/mcp/tools/authenticate/org-key-store.ts +25 -0
  88. package/src/mcp/tools/authenticate/resolve-owner-key.ts +10 -12
  89. package/src/mcp/tools/mode/mode.ts +2 -0
  90. package/src/mcp/tools/verification/result.ts +58 -13
  91. package/src/tools/registry.ts +14 -0
@@ -5,10 +5,13 @@ export function sessionTools(attachRef, captures) {
5
5
  return [
6
6
  defineTool({
7
7
  name: 'get_session',
8
- description: 'Report the current attach state, the live captureIds, and the '
9
- + 'persisted browser config. Call it to check whether a browser is '
10
- + 'still attached before reattaching, or to recover a captureId.',
8
+ description: 'Returns the current attach state, the live captureIds, the '
9
+ + 'persisted browser config, and the navigation script kept by '
10
+ + '`test_user_script`. Call it to check whether a browser is still '
11
+ + 'attached before reattaching, or to recover a captureId or the '
12
+ + 'kept script.',
11
13
  inputSchema: { type: 'object', properties: {} },
14
+ annotations: { readOnlyHint: true, openWorldHint: false },
12
15
  }, async () => ({
13
16
  config: attachRef.config.read()?.browser_agent,
14
17
  attached: Boolean(attachRef.current),
@@ -19,22 +22,27 @@ export function sessionTools(attachRef, captures) {
19
22
  orgId: attachRef.current?.orgId,
20
23
  captures: [...captures.sessions.keys()],
21
24
  activeTab: captures.activeTab,
25
+ keptUserScript: captures.keptScript?.script,
22
26
  })),
23
27
  defineTool({
24
28
  name: 'dispose_browser',
25
- description: 'Stop captures, disconnect the current browser, and immediately '
26
- + 'delete a Builder-hosted Popcorn session. Custom CDP sessions '
27
- + 'are disconnected but never deleted by Reclaim.',
29
+ description: 'Stops captures, disconnects the current browser, and deletes a '
30
+ + 'Builder-hosted browser session at once. Clears the kept '
31
+ + 'navigation script. Reclaim disconnects a custom CDP browser but '
32
+ + 'never deletes it.',
28
33
  inputSchema: { type: 'object', properties: {} },
34
+ annotations: { destructiveHint: true, openWorldHint: true },
29
35
  }, async () => {
30
36
  await resetAll(attachRef, captures);
31
37
  return { disposed: true };
32
38
  }),
33
39
  defineTool({
34
40
  name: 'reset_session',
35
- description: 'Stop all captures and clear capture state — drops every '
36
- + 'session\'s drafts and their in-memory secrets.',
41
+ description: 'Stops all captures and clears capture state, dropping every '
42
+ + 'draft and its in-memory secrets. Also disconnects the browser '
43
+ + 'and clears the kept navigation script.',
37
44
  inputSchema: { type: 'object', properties: {} },
45
+ annotations: { destructiveHint: true, openWorldHint: true },
38
46
  }, async () => {
39
47
  await resetAll(attachRef, captures);
40
48
  return { reset: true };
@@ -32,12 +32,13 @@ function withLocalOprfMode(provider) {
32
32
  /** The local backend for one capture: drive its tab over CDP, read its
33
33
  * captured requests, prove via the in-process attestor, replay by re-fetching
34
34
  * FROM INSIDE the tab (real cookies/session — see proof/page-replay.ts). */
35
- function localBackend(entry) {
35
+ function localBackend(entry, kept) {
36
36
  const { tabClient, session, drafts } = entry;
37
37
  const sendCdp = (method, params) => {
38
38
  return tabClient.send(method, params ?? {});
39
39
  };
40
40
  return {
41
+ kept,
41
42
  capture: session,
42
43
  drafts,
43
44
  sendCdp,
@@ -131,7 +132,7 @@ export function sharedAuthoringTools(captures) {
131
132
  throw new Error(`no capture ${captureId} — call start_capture first `
132
133
  + '(it has been reset or never started).');
133
134
  }
134
- return localBackend(entry);
135
+ return localBackend(entry, captures);
135
136
  };
136
137
  return authoringTools(resolveBackend).map((tool) => {
137
138
  if (tool.definition.name === 'run_proof') {
@@ -0,0 +1,15 @@
1
+ import { type RegisteredTool } from '../../server.ts';
2
+ interface StartIntegrationArgs {
3
+ goal: string;
4
+ orgId?: string;
5
+ providerIds?: string[];
6
+ }
7
+ /**
8
+ * Returns the plan a coding agent follows to add Reclaim verification to the
9
+ * developer's app, from sign-in to a tested Verify button. The plan lives in
10
+ * `skill/start-integration.md`; this tool fills in the inputs.
11
+ */
12
+ export declare function startIntegrationTool(): RegisteredTool;
13
+ /** Fill the plan template. Exported for tests. */
14
+ export declare function renderStartIntegration(args: StartIntegrationArgs): string;
15
+ export {};
@@ -0,0 +1,61 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { defineTool } from "../../server.js";
4
+ /**
5
+ * Returns the plan a coding agent follows to add Reclaim verification to the
6
+ * developer's app, from sign-in to a tested Verify button. The plan lives in
7
+ * `skill/start-integration.md`; this tool fills in the inputs.
8
+ */
9
+ export function startIntegrationTool() {
10
+ return defineTool({
11
+ name: 'start_integration',
12
+ description: 'Returns a step-by-step plan for adding Reclaim verification to the '
13
+ + 'current codebase: sign in, build or choose a provider, then add the '
14
+ + 'session route, callback, and Verify button. Call it first when a '
15
+ + 'developer wants their users to prove something, and follow the '
16
+ + 'plan to the end. Changes nothing itself.',
17
+ inputSchema: {
18
+ type: 'object',
19
+ required: ['goal'],
20
+ properties: {
21
+ goal: {
22
+ type: 'string',
23
+ minLength: 1,
24
+ maxLength: 300,
25
+ description: 'What the developer\'s users prove, for example, "they have '
26
+ + 'a GitHub account with 100 followers".',
27
+ },
28
+ orgId: {
29
+ type: 'string',
30
+ format: 'uuid',
31
+ description: 'Organization to use. Omit to choose from the list.',
32
+ },
33
+ providerIds: {
34
+ type: 'array',
35
+ maxItems: 10,
36
+ items: { type: 'string' },
37
+ description: 'Existing provider IDs to use. Omit to build a new provider.',
38
+ },
39
+ },
40
+ },
41
+ annotations: { readOnlyHint: true, openWorldHint: false },
42
+ }, async (args) => renderStartIntegration(args));
43
+ }
44
+ /** Fill the plan template. Exported for tests. */
45
+ export function renderStartIntegration(args) {
46
+ const providerIds = args.providerIds?.length
47
+ ? args.providerIds.map((id) => `\`${id}\``).join(', ')
48
+ : undefined;
49
+ const values = {
50
+ goal: args.goal,
51
+ orgId: args.orgId,
52
+ providerIds,
53
+ };
54
+ const template = readFileSync(fileURLToPath(new URL('../../../../skill/start-integration.md', import.meta.url)), 'utf8');
55
+ return template
56
+ // Keep a conditional block only when its input was given (or not given).
57
+ .replace(/<!-- (if|ifnot):(\w+) -->\n([\s\S]*?)<!-- endif -->\n/g, (_, kind, name, body) => {
58
+ return (kind === 'if') === Boolean(values[name]) ? body : '';
59
+ })
60
+ .replace(/\{\{(\w+)\}\}/g, (_, name) => values[name] ?? '');
61
+ }
@@ -16,18 +16,16 @@ export function authenticateTool(client, name = 'reclaim_authenticate') {
16
16
  + 'get_me_providers; those need the separate old-devtools login, '
17
17
  + 'reclaim_authenticate. Check both with get_devtools_mode. '
18
18
  : '')
19
- + 'Authorize the CLI / MCP to make authenticated API calls. Opens '
20
- + 'the '
21
- + 'browser to the builder sign-in page (standard OAuth 2.0 ' +
22
- 'authorization-code + PKCE with a localhost redirect) and waits for ' +
23
- 'the user to sign in and approve. On success the access token is ' +
24
- 'cached in ~/.reclaim/config.json and activated for this session.\n\n' +
25
- 'Call with no arguments. This bearer token authenticates ' +
26
- 'dashboard/org-management calls (for example, list_orgs, or ' +
27
- 'issuing an org secret). Programmatic verification calls use a ' +
28
- 'separate org secret ' +
29
- '(rorg_…, set as RECLAIM_ORG_SECRET).',
19
+ + 'Signs the developer in to Builder. Opens the Builder sign-in page '
20
+ + 'in their browser (OAuth 2.0 authorization code with PKCE, '
21
+ + 'redirecting to a localhost port this server opens) and waits for '
22
+ + 'them to approve. Saves the access token in ~/.reclaim/config.json '
23
+ + 'with mode 0600 and uses it for this session; the token is never '
24
+ + 'returned. The token authorizes organization-management tools such '
25
+ + 'as `list_orgs`. Programmatic verification tools use a separate '
26
+ + 'organization key; see `issue_org_token`. Call with no arguments.',
30
27
  inputSchema: { type: 'object', properties: {} },
28
+ annotations: { openWorldHint: true, idempotentHint: true },
31
29
  }, async () => runOAuthLoopback(client));
32
30
  }
33
31
  const _customFetchForOauth = async (url, options) => {
@@ -1,6 +1,7 @@
1
1
  import { authenticateTool } from "./authenticate.js";
2
2
  import { importTool } from "./import.js";
3
3
  import { issueTool } from "./issue.js";
4
+ import { issueOrgTokenTool } from "./issue-org-token.js";
4
5
  import { resolveOwnerKeyTool } from "./resolve-owner-key.js";
5
6
  /**
6
7
  * Local-only key tools — no backend client needed. These manage the eth
@@ -23,6 +24,7 @@ export function buildLocalCredentialTools() {
23
24
  export function buildCredentialTools(client) {
24
25
  return [
25
26
  authenticateTool(client),
27
+ issueOrgTokenTool(client),
26
28
  ...buildLocalCredentialTools(),
27
29
  ];
28
30
  }
@@ -26,6 +26,7 @@ export function buildBuilderOrganizationTools(client) {
26
26
  cursor: { type: 'string', maxLength: 500 },
27
27
  },
28
28
  },
29
+ annotations: { readOnlyHint: true, openWorldHint: true },
29
30
  }, async ({ cursor }) => {
30
31
  const { data } = await client.call('ListOrgs', {
31
32
  query: { ...(cursor ? { cursor } : {}) },
@@ -19,6 +19,14 @@ export declare function normalizeEthHex(value: string): string;
19
19
  * ask for one (see `resolve_owner_key`).
20
20
  */
21
21
  export declare function resolveEthKey(projectDir?: string): ResolvedEthKey | undefined;
22
+ /** Append `entry` to the project `.gitignore` if not already present. */
23
+ export declare function ensureGitignored(projectDir: string, entry: string): void;
24
+ /**
25
+ * Set `name=value` in a dotenv file, replacing an existing line or appending
26
+ * one. Writes with mode 0600 and adds the file to the project `.gitignore`.
27
+ * `envFile` is relative to `projectDir`.
28
+ */
29
+ export declare function upsertEnvVar(projectDir: string, envFile: string, name: string, value: string): string;
22
30
  /**
23
31
  * Persist a raw eth private key to the project `.env` as
24
32
  * `RECLAIM_PRIVATE_KEY=0x…` (upsert; mode 0600; `.env` added to `.gitignore`).
@@ -16,8 +16,8 @@
16
16
  */
17
17
  import { deriveFromPrivateKey } from '@reclaimprotocol/client';
18
18
  import assert from 'node:assert';
19
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
20
- import { isAbsolute, join } from 'node:path';
19
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync, } from 'node:fs';
20
+ import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
21
21
  import { privateKey, privateKeyFile } from "../../../consts.js";
22
22
  import { findProjectRoot } from "../../../paths.js";
23
23
  const ENV_VAR = 'RECLAIM_PRIVATE_KEY';
@@ -80,7 +80,7 @@ export function resolveEthKey(projectDir = findProjectRoot(process.cwd())) {
80
80
  return undefined;
81
81
  }
82
82
  /** Append `entry` to the project `.gitignore` if not already present. */
83
- function ensureGitignored(projectDir, entry) {
83
+ export function ensureGitignored(projectDir, entry) {
84
84
  const path = join(projectDir, '.gitignore');
85
85
  const current = existsSync(path) ? readFileSync(path, 'utf8') : '';
86
86
  if (current.split('\n').some((l) => l.trim() === entry)) {
@@ -90,26 +90,38 @@ function ensureGitignored(projectDir, entry) {
90
90
  writeFileSync(path, current + prefix + entry + '\n');
91
91
  }
92
92
  /**
93
- * Persist a raw eth private key to the project `.env` as
94
- * `RECLAIM_PRIVATE_KEY=0x…` (upsert; mode 0600; `.env` added to `.gitignore`).
95
- * Used by `issue_credentials` (generate) and `import_credentials` (supplied
96
- * hex). Returns the derived address and the `.env` path.
93
+ * Set `name=value` in a dotenv file, replacing an existing line or appending
94
+ * one. Writes with mode 0600 and adds the file to the project `.gitignore`.
95
+ * `envFile` is relative to `projectDir`.
97
96
  */
98
- export function writeEthKey(privateKeyHex, projectDir = findProjectRoot(process.cwd())) {
99
- const hex = normalizeEthHex(privateKeyHex);
100
- const envPath = join(projectDir, ENV_FILE);
101
- const line = `${ENV_VAR}=${hex}`;
97
+ export function upsertEnvVar(projectDir, envFile, name, value) {
98
+ const envPath = resolve(projectDir, envFile);
99
+ const line = `${name}=${value}`;
102
100
  const existing = existsSync(envPath) ? readFileSync(envPath, 'utf8') : '';
103
- const re = new RegExp(`^\\s*${ENV_VAR}\\s*=.*$`, 'm');
101
+ const re = new RegExp(`^\\s*${name}\\s*=.*$`, 'm');
104
102
  let next;
105
103
  if (re.test(existing)) {
106
- next = existing.replace(re, line);
104
+ // A function replacer keeps `$` sequences in the value literal.
105
+ next = existing.replace(re, () => line);
107
106
  }
108
107
  else {
109
108
  const prefix = existing && !existing.endsWith('\n') ? '\n' : '';
110
109
  next = existing + prefix + line + '\n';
111
110
  }
111
+ mkdirSync(dirname(envPath), { recursive: true });
112
112
  writeFileSync(envPath, next, { mode: 0o600 });
113
- ensureGitignored(projectDir, ENV_FILE);
114
- return { path: envPath, address: deriveFromPrivateKey(hex).address };
113
+ chmodSync(envPath, 0o600);
114
+ ensureGitignored(projectDir, relative(projectDir, envPath));
115
+ return envPath;
116
+ }
117
+ /**
118
+ * Persist a raw eth private key to the project `.env` as
119
+ * `RECLAIM_PRIVATE_KEY=0x…` (upsert; mode 0600; `.env` added to `.gitignore`).
120
+ * Used by `issue_credentials` (generate) and `import_credentials` (supplied
121
+ * hex). Returns the derived address and the `.env` path.
122
+ */
123
+ export function writeEthKey(privateKeyHex, projectDir = findProjectRoot(process.cwd())) {
124
+ const hex = normalizeEthHex(privateKeyHex);
125
+ const path = upsertEnvVar(projectDir, ENV_FILE, ENV_VAR, hex);
126
+ return { path, address: deriveFromPrivateKey(hex).address };
115
127
  }
@@ -5,53 +5,40 @@ import { writeEthKey } from "./eth-key.js";
5
5
  export function importTool() {
6
6
  return defineTool({
7
7
  name: 'import_credentials',
8
- description: 'Import an eth proof-owner key the dev already holds and persist it ' +
9
- 'to the project `.env` as RECLAIM_PRIVATE_KEY=0x… (mode 0600; `.env` ' +
10
- 'added to .gitignore). Provide EITHER `privateKey` (raw 0x-hex, 64 ' +
11
- 'chars) OR `keyFile` (path to a file holding the raw 0x-hex key). ' +
12
- 'The address is derived locally; the private key is never ' +
13
- 'returned. This is a local signing key only (not registered ' +
14
- 'with any server, ' +
15
- 'unrelated to org auth or encryption).',
8
+ description: 'Imports an eth proof-owner key from a file the developer already '
9
+ + 'holds. Reads the raw 0x-hex key from `keyFile` and writes it to '
10
+ + 'the project `.env` as RECLAIM_PRIVATE_KEY (mode 0600; `.env` '
11
+ + 'added to .gitignore). Returns the derived address and the `.env` '
12
+ + 'path; never the key. The key is a local signing key only: it is '
13
+ + 'not registered with any server and is unrelated to org auth or '
14
+ + 'encryption. To create a new key instead, use `issue_credentials`.',
16
15
  inputSchema: {
17
16
  type: 'object',
17
+ required: ['keyFile'],
18
18
  properties: {
19
- privateKey: {
20
- type: 'string',
21
- pattern: '^0x?[0-9a-fA-F]{64}$',
22
- description: 'Raw Ethereum private key, 0x-prefixed hex (64 hex chars).',
23
- },
24
19
  keyFile: {
25
20
  type: 'string',
26
- description: 'Path to a file containing the raw 0x-hex private key ' +
27
- '(absolute or project-relative).',
21
+ description: 'Path to a file containing the raw 0x-hex private key '
22
+ + '(absolute or relative to the working directory).',
28
23
  },
29
24
  projectDir: {
30
25
  type: 'string',
31
- description: 'Project directory whose `.env` the key is written to. ' +
32
- 'Defaults to the closest ancestor of cwd containing .git or ' +
33
- 'package.json.',
26
+ description: 'Project directory whose `.env` the key is written to. '
27
+ + 'Defaults to the closest ancestor of cwd containing .git or '
28
+ + 'package.json.',
34
29
  },
35
30
  },
36
31
  },
32
+ annotations: { readOnlyHint: false, destructiveHint: false },
37
33
  }, async (args) => {
38
- if (!args.privateKey && !args.keyFile) {
39
- throw new Error('Provide either `privateKey` (0x-hex) or `keyFile`.');
40
- }
41
- if (args.privateKey && args.keyFile) {
42
- throw new Error('Provide only one of `privateKey` or `keyFile`.');
43
- }
44
34
  const projectDir = findProjectRoot(args.projectDir || process.cwd());
45
- const privateKeyHex = args.keyFile
46
- ? readFileSync(args.keyFile, 'utf8')
47
- : args.privateKey;
48
- const { path, address } = writeEthKey(privateKeyHex, projectDir);
35
+ const { path, address } = writeEthKey(readFileSync(args.keyFile, 'utf8'), projectDir);
49
36
  return {
50
37
  address,
51
38
  path,
52
- note: 'Eth proof-owner key written to .env as RECLAIM_PRIVATE_KEY ' +
53
- '(mode 0600). resolve_owner_key resolves it from .env. Keep .env ' +
54
- 'secret — it has been added to .gitignore.',
39
+ note: 'Eth proof-owner key written to .env as RECLAIM_PRIVATE_KEY '
40
+ + '(mode 0600). resolve_owner_key resolves it from .env. Keep .env '
41
+ + 'secret: it has been added to .gitignore.',
55
42
  };
56
43
  });
57
44
  }
@@ -0,0 +1,8 @@
1
+ import type { ReclaimClient } from '@reclaimprotocol/client/api';
2
+ import { type RegisteredTool } from '../../server.ts';
3
+ /**
4
+ * Issues an organization API key and stores it on disk, so the key never
5
+ * passes through the agent's transcript. Replaces the generated
6
+ * `issue_org_token` operation, which returned the key in its response.
7
+ */
8
+ export declare function issueOrgTokenTool(client: ReclaimClient): RegisteredTool;
@@ -0,0 +1,60 @@
1
+ import assert from 'node:assert';
2
+ import { isAbsolute, relative, resolve } from 'node:path';
3
+ import { defineTool } from "../../server.js";
4
+ import { upsertEnvVar } from "./eth-key.js";
5
+ import { saveOrgKey } from "./org-key-store.js";
6
+ /**
7
+ * Issues an organization API key and stores it on disk, so the key never
8
+ * passes through the agent's transcript. Replaces the generated
9
+ * `issue_org_token` operation, which returned the key in its response.
10
+ */
11
+ export function issueOrgTokenTool(client) {
12
+ return defineTool({
13
+ name: 'issue_org_token',
14
+ description: 'Issues an organization API key (owner only) and writes it to a '
15
+ + 'server env file in the project, so the app can read it at runtime. '
16
+ + 'Also saves it on this machine for the org-key tools. Returns the '
17
+ + 'org, file, variable, and last four characters; never the key. '
18
+ + 'Replaces an existing variable of the same name in the file. '
19
+ + 'Adds the file to .gitignore. Use when the app needs a key, or '
20
+ + 'before `create_verification_session`.',
21
+ inputSchema: {
22
+ type: 'object',
23
+ required: ['orgId', 'projectDir'],
24
+ properties: {
25
+ orgId: { type: 'string', format: 'uuid' },
26
+ projectDir: {
27
+ type: 'string',
28
+ description: 'Absolute path of the app\'s project directory.',
29
+ },
30
+ envFile: {
31
+ type: 'string',
32
+ description: 'Env file to write, relative to `projectDir`. Default `.env`.',
33
+ },
34
+ envVar: {
35
+ type: 'string',
36
+ pattern: '^[A-Za-z_][A-Za-z0-9_]*$',
37
+ description: 'Variable name to set. Default `RECLAIM_ORG_SECRET`.',
38
+ },
39
+ },
40
+ },
41
+ annotations: { openWorldHint: true, destructiveHint: false },
42
+ }, async (args) => {
43
+ assert(isAbsolute(args.projectDir), new Error('`projectDir` must be an absolute path.'));
44
+ const envFile = args.envFile || '.env';
45
+ const envVar = args.envVar || 'RECLAIM_ORG_SECRET';
46
+ const inside = relative(args.projectDir, resolve(args.projectDir, envFile));
47
+ assert(inside && !inside.startsWith('..') && !isAbsolute(inside), new Error('`envFile` must be inside `projectDir`.'));
48
+ const { data } = await client.call('IssueOrgToken', {
49
+ params: { orgId: args.orgId },
50
+ });
51
+ const path = upsertEnvVar(args.projectDir, envFile, envVar, data.orgSecret);
52
+ saveOrgKey(args.orgId, data.orgSecret);
53
+ return {
54
+ orgId: args.orgId,
55
+ envFile: path,
56
+ envVar,
57
+ last4: data.last4,
58
+ };
59
+ });
60
+ }
@@ -5,15 +5,14 @@ import { writeEthKey } from "./eth-key.js";
5
5
  export function issueTool() {
6
6
  return defineTool({
7
7
  name: 'issue_credentials',
8
- description: 'Generate a fresh secp256k1 eth proof-owner key-pair (the key ' +
9
- 'that signs local claim creation) and write the raw private key to ' +
10
- 'the project `.env` as RECLAIM_PRIVATE_KEY=0x… (mode 0600; `.env` ' +
11
- 'added to .gitignore). This is a LOCAL signing key only — it is NOT ' +
12
- 'registered with any server and is unrelated to org auth (the org ' +
13
- 'secret) or encryption (the eth decrypt key). ALWAYS confirm with ' +
14
- 'the dev before generating a new key. After writing, run_proof picks ' +
15
- 'it up automatically via resolve_owner_key. The private key is never ' +
16
- 'returned in the response.',
8
+ description: 'Generates a new secp256k1 eth proof-owner key and writes the '
9
+ + 'private key to the project `.env` as RECLAIM_PRIVATE_KEY (mode '
10
+ + '0600; `.env` added to .gitignore). Returns the address and the '
11
+ + '`.env` path; never the key. The key is a local signing key only: '
12
+ + 'it is not registered with any server and is unrelated to org auth '
13
+ + 'or encryption. Confirm with the developer before replacing an '
14
+ + 'existing key. `run_proof` then picks it up through '
15
+ + '`resolve_owner_key`.',
17
16
  inputSchema: {
18
17
  type: 'object',
19
18
  properties: {
@@ -25,6 +24,7 @@ export function issueTool() {
25
24
  },
26
25
  },
27
26
  },
27
+ annotations: { destructiveHint: false },
28
28
  }, async (args) => {
29
29
  const projectDir = findProjectRoot(args.projectDir || process.cwd());
30
30
  const keypair = generateKeypair();
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Save an organization API key (`rorg_…`) in the local config (mode 0600), so
3
+ * the org-key tools can use it without the key passing through a transcript.
4
+ */
5
+ export declare function saveOrgKey(orgId: string, secret: string): void;
6
+ /**
7
+ * The saved key for `orgId`, or the most recently saved key when no org is
8
+ * given. Returns `undefined` when none is saved.
9
+ */
10
+ export declare function savedOrgKey(orgId?: string): string | undefined;
@@ -0,0 +1,23 @@
1
+ import { ConfigStore } from "../../../config/store.js";
2
+ /**
3
+ * Save an organization API key (`rorg_…`) in the local config (mode 0600), so
4
+ * the org-key tools can use it without the key passing through a transcript.
5
+ */
6
+ export function saveOrgKey(orgId, secret) {
7
+ const saved = new ConfigStore().read()?.org_keys;
8
+ new ConfigStore().write({
9
+ org_keys: {
10
+ byOrg: { ...saved?.byOrg, [orgId]: secret },
11
+ recent: orgId,
12
+ },
13
+ });
14
+ }
15
+ /**
16
+ * The saved key for `orgId`, or the most recently saved key when no org is
17
+ * given. Returns `undefined` when none is saved.
18
+ */
19
+ export function savedOrgKey(orgId) {
20
+ const saved = new ConfigStore().read()?.org_keys;
21
+ const id = orgId || saved?.recent;
22
+ return id ? saved?.byOrg[id] : undefined;
23
+ }
@@ -16,18 +16,16 @@ import { ENV_FILE, resolveEthKey } from "./eth-key.js";
16
16
  export function resolveOwnerKeyTool() {
17
17
  return defineTool({
18
18
  name: 'resolve_owner_key',
19
- description: 'Resolve which eth proof-owner key run_proof should sign with — ' +
20
- 'call this BEFORE run_proof. Checks, in order: RECLAIM_PRIVATE_KEY ' +
21
- 'in the MCP env, a RECLAIM_PRIVATE_KEY=0x… line in the project .env, ' +
22
- 'then a file at RECLAIM_PRIVATE_KEY_FILE holding the raw hex. ' +
23
- 'Returns { ready: true, address, source } when one is ' +
24
- 'available — pass `address` to run_proof as `ownerAddress`. ' +
25
- 'Returns { ready: false } ' +
26
- 'when none exists: then ask the dev to generate one ' +
27
- '(issue_credentials) or import one they already hold ' +
28
- '(import_credentials, accepts 0x-hex or a key-file path), and call ' +
29
- 'resolve_owner_key again. Never exposes the private key.',
19
+ description: 'Finds the eth proof-owner key `run_proof` signs with. Call it '
20
+ + 'before `run_proof`. Checks RECLAIM_PRIVATE_KEY in the MCP env, a '
21
+ + 'RECLAIM_PRIVATE_KEY line in the project .env, then the file at '
22
+ + 'RECLAIM_PRIVATE_KEY_FILE. Returns { ready: true, address, source '
23
+ + '}: pass `address` to `run_proof` as `ownerAddress`. Returns { '
24
+ + 'ready: false } when none exists: ask the developer to create one '
25
+ + 'with `issue_credentials` or import one with `import_credentials` '
26
+ + '(a key file), then call it again. Never returns the key.',
30
27
  inputSchema: { type: 'object', properties: {} },
28
+ annotations: { readOnlyHint: true, openWorldHint: false },
31
29
  }, async () => {
32
30
  const projectDir = findProjectRoot(process.cwd());
33
31
  const resolved = resolveEthKey(projectDir);
@@ -45,7 +43,7 @@ export function resolveOwnerKeyTool() {
45
43
  `env, no RECLAIM_PRIVATE_KEY in ${join(projectDir, ENV_FILE)}, and ` +
46
44
  'no RECLAIM_PRIVATE_KEY_FILE. Ask the dev to generate one via ' +
47
45
  'issue_credentials, or import one they already hold via ' +
48
- 'import_credentials (0x-hex or a key-file path). Then call ' +
46
+ 'import_credentials (a key file). Then call ' +
49
47
  'resolve_owner_key again and pass its address to run_proof as ' +
50
48
  'ownerAddress.',
51
49
  };
@@ -44,6 +44,7 @@ export function buildModeTools(config, currentOldMode) {
44
44
  },
45
45
  required: ['mode'],
46
46
  },
47
+ annotations: { openWorldHint: false, idempotentHint: true },
47
48
  }, async (parsed) => {
48
49
  config.write({ mode: parsed.mode });
49
50
  const restartRequired = parsed.mode !== current;
@@ -71,6 +72,7 @@ export function buildModeTools(config, currentOldMode) {
71
72
  + 'the staleness with an error naming the tool to re-run. Which '
72
73
  + 'login authorizes what: how_it_works({ topic: "auth" }).',
73
74
  inputSchema: { type: 'object', properties: {} },
75
+ annotations: { readOnlyHint: true, openWorldHint: false },
74
76
  }, async () => {
75
77
  const persisted = config.read()?.mode;
76
78
  const oldIdentity = config.read()?.old_devtools;