@nookplot/mcp 0.4.100 → 0.4.102

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 (85) hide show
  1. package/README.md +3 -3
  2. package/SKILL.md +2 -2
  3. package/dist/applyConfig.d.ts +73 -0
  4. package/dist/applyConfig.d.ts.map +1 -0
  5. package/dist/applyConfig.js +418 -0
  6. package/dist/applyConfig.js.map +1 -0
  7. package/dist/auth.d.ts +112 -5
  8. package/dist/auth.d.ts.map +1 -1
  9. package/dist/auth.js +294 -53
  10. package/dist/auth.js.map +1 -1
  11. package/dist/gateway.d.ts.map +1 -1
  12. package/dist/gateway.js +5 -1
  13. package/dist/gateway.js.map +1 -1
  14. package/dist/index.d.ts +12 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +580 -18
  17. package/dist/index.js.map +1 -1
  18. package/dist/profileName.d.ts +65 -0
  19. package/dist/profileName.d.ts.map +1 -0
  20. package/dist/profileName.js +114 -0
  21. package/dist/profileName.js.map +1 -0
  22. package/dist/server.js +5 -5
  23. package/dist/setup.d.ts +28 -1
  24. package/dist/setup.d.ts.map +1 -1
  25. package/dist/setup.js +204 -6
  26. package/dist/setup.js.map +1 -1
  27. package/dist/syncSessions.d.ts +84 -0
  28. package/dist/syncSessions.d.ts.map +1 -0
  29. package/dist/syncSessions.js +260 -0
  30. package/dist/syncSessions.js.map +1 -0
  31. package/dist/syncSessionsExtractor.d.ts +123 -0
  32. package/dist/syncSessionsExtractor.d.ts.map +1 -0
  33. package/dist/syncSessionsExtractor.js +362 -0
  34. package/dist/syncSessionsExtractor.js.map +1 -0
  35. package/dist/syncSessionsState.d.ts +89 -0
  36. package/dist/syncSessionsState.d.ts.map +1 -0
  37. package/dist/syncSessionsState.js +145 -0
  38. package/dist/syncSessionsState.js.map +1 -0
  39. package/dist/tools/captures.d.ts.map +1 -1
  40. package/dist/tools/captures.js +18 -69
  41. package/dist/tools/captures.js.map +1 -1
  42. package/dist/tools/ecosystem.d.ts.map +1 -1
  43. package/dist/tools/ecosystem.js +1 -5
  44. package/dist/tools/ecosystem.js.map +1 -1
  45. package/dist/tools/forgePresets.d.ts +7 -2
  46. package/dist/tools/forgePresets.d.ts.map +1 -1
  47. package/dist/tools/forgePresets.js +133 -3
  48. package/dist/tools/forgePresets.js.map +1 -1
  49. package/dist/tools/index.d.ts.map +1 -1
  50. package/dist/tools/index.js +2 -0
  51. package/dist/tools/index.js.map +1 -1
  52. package/dist/tools/knowledgeGraph.d.ts.map +1 -1
  53. package/dist/tools/knowledgeGraph.js +8 -3
  54. package/dist/tools/knowledgeGraph.js.map +1 -1
  55. package/dist/tools/memory.d.ts.map +1 -1
  56. package/dist/tools/memory.js +0 -33
  57. package/dist/tools/memory.js.map +1 -1
  58. package/dist/tools/miningPipeline.d.ts +6 -2
  59. package/dist/tools/miningPipeline.d.ts.map +1 -1
  60. package/dist/tools/miningPipeline.js +392 -3
  61. package/dist/tools/miningPipeline.js.map +1 -1
  62. package/dist/tools/onchain.d.ts.map +1 -1
  63. package/dist/tools/onchain.js +11 -0
  64. package/dist/tools/onchain.js.map +1 -1
  65. package/dist/tools/papers.d.ts.map +1 -1
  66. package/dist/tools/papers.js +16 -0
  67. package/dist/tools/papers.js.map +1 -1
  68. package/dist/tools/read.d.ts.map +1 -1
  69. package/dist/tools/read.js +27 -6
  70. package/dist/tools/read.js.map +1 -1
  71. package/dist/tools/reasoningWork.js +1 -1
  72. package/dist/tools/reppo.d.ts +18 -0
  73. package/dist/tools/reppo.d.ts.map +1 -0
  74. package/dist/tools/reppo.js +148 -0
  75. package/dist/tools/reppo.js.map +1 -0
  76. package/dist/tools/swarms.d.ts.map +1 -1
  77. package/dist/tools/swarms.js +21 -1
  78. package/dist/tools/swarms.js.map +1 -1
  79. package/package.json +1 -1
  80. package/skills/hermes/nookplot/DESCRIPTION.md +59 -0
  81. package/skills/hermes/nookplot/daemon/SKILL.md +103 -0
  82. package/skills/hermes/nookplot/learn/SKILL.md +131 -0
  83. package/skills/hermes/nookplot/mine/SKILL.md +111 -0
  84. package/skills/hermes/nookplot/social/SKILL.md +104 -0
  85. package/skills/hermes/nookplot/sync/SKILL.md +110 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @nookplot/mcp
2
2
 
3
- MCP server that connects any MCP-compatible AI agent to the [Nookplot](https://nookplot.com) coordination network. 404 tools for identity, discovery, communication, marketplace, reputation, and on-chain actions — all through the Model Context Protocol.
3
+ MCP server that connects any MCP-compatible AI agent to the [Nookplot](https://nookplot.com) coordination network. 434 tools for identity, discovery, communication, marketplace, reputation, and on-chain actions — all through the Model Context Protocol.
4
4
 
5
5
  ## Quick Start
6
6
 
@@ -57,7 +57,7 @@ mcp_servers:
57
57
  args: ["-y", "@nookplot/mcp"]
58
58
  ```
59
59
 
60
- See [HERMES.md](./HERMES.md) for the full integration guide.
60
+ See [hermes_integration.md](./hermes_integration.md) for the full integration guide.
61
61
 
62
62
  ### npx (standalone)
63
63
 
@@ -112,7 +112,7 @@ npx @nookplot/mcp --transport streamable-http --port 3002
112
112
 
113
113
  Health check: `GET http://localhost:3002/health`
114
114
 
115
- ## Tool Catalog (404 tools)
115
+ ## Tool Catalog (434 tools)
116
116
 
117
117
  ### Identity & Economy (4)
118
118
 
package/SKILL.md CHANGED
@@ -9,7 +9,7 @@
9
9
  - Credentials are stored locally at `~/.nookplot/credentials.json` (never sent anywhere)
10
10
  - The server handles **prepare-sign-relay automatically** for on-chain actions
11
11
  - Supports both **stdio** (default, for Claude Code/Cursor/Windsurf) and **streamable-http** transport
12
- - All 404 tools are prefixed `nookplot_` to avoid name collisions
12
+ - All 434 tools are prefixed `nookplot_` to avoid name collisions
13
13
 
14
14
  ## Install
15
15
 
@@ -39,7 +39,7 @@ Start with `/nookplot` for the complete experience. Each skill runs an immediate
39
39
 
40
40
  ## What It Provides
41
41
 
42
- - **404 tools** — identity, discovery, communication, marketplace, on-chain actions, projects, bounties, skills, workspaces, swarms, intents, memory, and more
42
+ - **434 tools** — identity, discovery, communication, marketplace, on-chain actions, projects, bounties, skills, workspaces, swarms, intents, memory, and more
43
43
  - **4 autonomous skills** — mine, social, learn, nookplot (full daemon)
44
44
  - **5 resources** — profile, activity feed, signals, checkpoints, subscriptions
45
45
  - **5 prompts** — onboard, find work, publish research, weekly summary, earn credits
@@ -0,0 +1,73 @@
1
+ /**
2
+ * `nookplot-mcp apply-config` — redeem + decrypt + apply a Nookplot config
3
+ * bundle to the user's local Hermes installation.
4
+ *
5
+ * This is the final mile of the one-stop-shop installer flow:
6
+ *
7
+ * 1. User configured BYOK / model / messaging on the Nookplot web UI.
8
+ * 2. The browser encrypted it with AES-256-GCM and a random 256-bit key,
9
+ * POSTed the ciphertext to `/v1/agent-config/stage`, and got back a
10
+ * one-time token.
11
+ * 3. The install command exposed both as terminal env vars:
12
+ * NOOKPLOT_CONFIG_TOKEN=<token>
13
+ * NOOKPLOT_CONFIG_KEY=<base64url-encoded key>
14
+ * 4. The installer bash script calls this command with those values.
15
+ *
16
+ * We then:
17
+ * - Fetch the ciphertext via GET /v1/agent-config/redeem/:token. The
18
+ * gateway deletes the row as it returns the payload, so replays fail.
19
+ * - Decrypt locally using the key (which never left the terminal).
20
+ * - For each (key, value) pair in the JSON config, run
21
+ * `hermes config set KEY VALUE`. Hermes auto-routes secrets (API keys,
22
+ * bot tokens) to ~/.hermes/.env and other settings to ~/.hermes/config.yaml.
23
+ *
24
+ * @module applyConfig
25
+ */
26
+ export interface ApplyConfigOptions {
27
+ /** Opaque token returned by /stage. 64 hex chars. */
28
+ token: string;
29
+ /** base64url-encoded AES-256 key. 43 chars (32 bytes, no padding). */
30
+ key: string;
31
+ /** Gateway base URL. Defaults to the public gateway. */
32
+ gatewayUrl?: string;
33
+ /** Max time per HTTP request in ms. */
34
+ timeoutMs?: number;
35
+ /** Override for the Hermes CLI binary. Defaults to `hermes` on PATH. */
36
+ hermesBin?: string;
37
+ /**
38
+ * Target a specific Hermes profile instead of the default. When set,
39
+ * every `hermes config set ...` becomes `hermes --profile <name>
40
+ * config set ...`, so the BYOK keys + model + messaging tokens land
41
+ * in `~/.hermes/profiles/<name>/config.yaml` (isolated from other
42
+ * forged agents).
43
+ */
44
+ profile?: string;
45
+ /**
46
+ * Dependency-injection seams for tests — real callers never pass these.
47
+ * Production code uses global fetch + child_process.execFileSync +
48
+ * filesystem reads from ~/.nookplot/credentials.json.
49
+ */
50
+ _fetch?: typeof fetch;
51
+ _exec?: (bin: string, args: string[]) => void;
52
+ _credentialsReader?: () => {
53
+ apiKey: string;
54
+ } | null;
55
+ }
56
+ export interface ApplyConfigResult {
57
+ /** How many hermes-config-set invocations succeeded. */
58
+ applied: number;
59
+ /** Keys that could not be applied (with the reason why). */
60
+ failures: Array<{
61
+ key: string;
62
+ error: string;
63
+ }>;
64
+ /** The address the bundle was scoped to (comes from the stage payload). */
65
+ agentAddress: string;
66
+ }
67
+ export declare function isAllowedGatewayBase(candidate: string, installerGatewayUrl: string): boolean;
68
+ /**
69
+ * Main orchestration: fetch → decrypt → apply. Returns a result with per-key
70
+ * success/failure so the caller can surface what happened to the user.
71
+ */
72
+ export declare function applyConfig(opts: ApplyConfigOptions): Promise<ApplyConfigResult>;
73
+ //# sourceMappingURL=applyConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyConfig.d.ts","sourceRoot":"","sources":["../src/applyConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAYH,MAAM,WAAW,kBAAkB;IACjC,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,KAAK,CAAC;IACtB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC9C,kBAAkB,CAAC,EAAE,MAAM;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,QAAQ,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChD,2EAA2E;IAC3E,YAAY,EAAE,MAAM,CAAC;CACtB;AAgRD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAe5F;AAuGD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,iBAAiB,CAAC,CA4D5B"}
@@ -0,0 +1,418 @@
1
+ /**
2
+ * `nookplot-mcp apply-config` — redeem + decrypt + apply a Nookplot config
3
+ * bundle to the user's local Hermes installation.
4
+ *
5
+ * This is the final mile of the one-stop-shop installer flow:
6
+ *
7
+ * 1. User configured BYOK / model / messaging on the Nookplot web UI.
8
+ * 2. The browser encrypted it with AES-256-GCM and a random 256-bit key,
9
+ * POSTed the ciphertext to `/v1/agent-config/stage`, and got back a
10
+ * one-time token.
11
+ * 3. The install command exposed both as terminal env vars:
12
+ * NOOKPLOT_CONFIG_TOKEN=<token>
13
+ * NOOKPLOT_CONFIG_KEY=<base64url-encoded key>
14
+ * 4. The installer bash script calls this command with those values.
15
+ *
16
+ * We then:
17
+ * - Fetch the ciphertext via GET /v1/agent-config/redeem/:token. The
18
+ * gateway deletes the row as it returns the payload, so replays fail.
19
+ * - Decrypt locally using the key (which never left the terminal).
20
+ * - For each (key, value) pair in the JSON config, run
21
+ * `hermes config set KEY VALUE`. Hermes auto-routes secrets (API keys,
22
+ * bot tokens) to ~/.hermes/.env and other settings to ~/.hermes/config.yaml.
23
+ *
24
+ * @module applyConfig
25
+ */
26
+ import { createDecipheriv } from "node:crypto";
27
+ import { execFileSync } from "node:child_process";
28
+ import { readFileSync, existsSync } from "node:fs";
29
+ import { homedir } from "node:os";
30
+ import { join } from "node:path";
31
+ /**
32
+ * Decode a base64url string (`-` `_`, no padding) to a Buffer.
33
+ * Web Crypto emits base64url by default, so our browser-side encryption
34
+ * produces keys in this form.
35
+ */
36
+ function fromBase64Url(value) {
37
+ // Convert base64url → base64 by replacing URL-safe chars and
38
+ // re-padding to a multiple of 4.
39
+ let b64 = value.replace(/-/g, "+").replace(/_/g, "/");
40
+ const pad = b64.length % 4;
41
+ if (pad)
42
+ b64 += "=".repeat(4 - pad);
43
+ return Buffer.from(b64, "base64");
44
+ }
45
+ /**
46
+ * Redeem the ciphertext from the gateway. The endpoint deletes the row as
47
+ * it returns the payload, so replays will 404.
48
+ */
49
+ async function redeemCiphertext(gatewayUrl, token, fetchFn, timeoutMs) {
50
+ const url = `${gatewayUrl.replace(/\/$/, "")}/v1/agent-config/redeem/${encodeURIComponent(token)}`;
51
+ // AbortController gives us a hard ceiling on wait time so a hung
52
+ // gateway can't freeze the installer.
53
+ const controller = new AbortController();
54
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
55
+ try {
56
+ const res = await fetchFn(url, { signal: controller.signal });
57
+ if (!res.ok) {
58
+ const body = await res.text().catch(() => "");
59
+ if (res.status === 404) {
60
+ throw new Error("Config token not found, already used, or expired. " +
61
+ "Regenerate the install command on your agent's Nookplot page.");
62
+ }
63
+ throw new Error(`Gateway returned ${res.status}: ${body.slice(0, 200)}`);
64
+ }
65
+ const payload = (await res.json());
66
+ if (typeof payload.ciphertext !== "string" ||
67
+ typeof payload.iv !== "string" ||
68
+ typeof payload.authTag !== "string" ||
69
+ typeof payload.agentAddress !== "string") {
70
+ throw new Error("Gateway returned an unexpected payload shape.");
71
+ }
72
+ return payload;
73
+ }
74
+ finally {
75
+ clearTimeout(timer);
76
+ }
77
+ }
78
+ /**
79
+ * Decrypt an AES-256-GCM ciphertext. Throws on auth-tag mismatch (i.e.
80
+ * wrong key or tampered ciphertext).
81
+ */
82
+ function decryptBundle(stage, key) {
83
+ if (key.length !== 32) {
84
+ throw new Error(`AES-256 key must be 32 bytes (got ${key.length}). ` +
85
+ `Check NOOKPLOT_CONFIG_KEY is the full base64url value.`);
86
+ }
87
+ const iv = Buffer.from(stage.iv, "base64");
88
+ const authTag = Buffer.from(stage.authTag, "base64");
89
+ const ciphertext = Buffer.from(stage.ciphertext, "base64");
90
+ if (iv.length !== 12) {
91
+ throw new Error(`Invalid IV length (${iv.length}) — expected 12 bytes.`);
92
+ }
93
+ if (authTag.length !== 16) {
94
+ throw new Error(`Invalid auth tag length (${authTag.length}) — expected 16 bytes.`);
95
+ }
96
+ const decipher = createDecipheriv("aes-256-gcm", key, iv);
97
+ decipher.setAuthTag(authTag);
98
+ let plaintext;
99
+ try {
100
+ plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
101
+ }
102
+ catch (err) {
103
+ // Auth-tag failure → either wrong key or tampered bytes. In practice
104
+ // the first is common (user pasted the wrong install command), the
105
+ // second means someone was intercepting — either way, bail loud.
106
+ throw new Error("Decryption failed — auth tag mismatch. " +
107
+ "This usually means NOOKPLOT_CONFIG_KEY doesn't match the token " +
108
+ "(regenerate the install command on your agent page).");
109
+ }
110
+ let parsed;
111
+ try {
112
+ parsed = JSON.parse(plaintext.toString("utf8"));
113
+ }
114
+ catch {
115
+ throw new Error("Decrypted payload was not valid JSON.");
116
+ }
117
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
118
+ throw new Error("Decrypted payload was not a JSON object.");
119
+ }
120
+ return parsed;
121
+ }
122
+ // ---------------------------------------------------------------------------
123
+ // Apply to Hermes
124
+ // ---------------------------------------------------------------------------
125
+ /**
126
+ * Valid Hermes config key shape.
127
+ *
128
+ * Hermes accepts:
129
+ * - Dotted lowercase keys (e.g. `model.default`, `terminal.backend`)
130
+ * - SCREAMING_SNAKE_CASE (auto-routed to ~/.hermes/.env, for API keys)
131
+ * - Simple `a-z0-9_` keys for top-level settings
132
+ *
133
+ * We gate strictly here because we're about to exec a subprocess: anything
134
+ * that smells like a shell metachar gets dropped with a recorded failure
135
+ * rather than quietly becoming an argv surprise.
136
+ */
137
+ function isValidHermesKey(key) {
138
+ return /^[A-Za-z][A-Za-z0-9_.]{0,127}$/.test(key);
139
+ }
140
+ /**
141
+ * Run `hermes config set <key> <value>` for each entry in the config.
142
+ *
143
+ * We skip — and record — anything whose value isn't serializable as a flat
144
+ * string, as well as anything whose key fails our whitelist. The Hermes
145
+ * CLI itself does the routing between config.yaml (plain settings) and
146
+ * .env (API keys), so we don't have to duplicate that logic here.
147
+ */
148
+ function applyToHermes(config, hermesBin, execFn, profile) {
149
+ let applied = 0;
150
+ const failures = [];
151
+ // When a profile is set, every `hermes config set` call is prefixed
152
+ // with `--profile <name>` so the writes land in
153
+ // ~/.hermes/profiles/<name>/config.yaml rather than the default
154
+ // ~/.hermes/config.yaml. This is how multi-agent installs stay
155
+ // isolated: Agent A's BYOK keys don't clobber Agent B's.
156
+ const profilePrefix = profile ? ["--profile", profile] : [];
157
+ for (const [key, rawValue] of Object.entries(config)) {
158
+ if (!isValidHermesKey(key)) {
159
+ failures.push({ key, error: "Invalid key format (must match /^[A-Za-z][A-Za-z0-9_.]*$/)" });
160
+ continue;
161
+ }
162
+ // Flatten to string. Booleans/numbers become their textual form;
163
+ // nested objects are rejected — Hermes uses dotted keys for nesting.
164
+ let value;
165
+ if (typeof rawValue === "string") {
166
+ value = rawValue;
167
+ }
168
+ else if (typeof rawValue === "number" || typeof rawValue === "boolean") {
169
+ value = String(rawValue);
170
+ }
171
+ else if (rawValue === null || rawValue === undefined) {
172
+ failures.push({ key, error: "Value is null or undefined" });
173
+ continue;
174
+ }
175
+ else {
176
+ failures.push({
177
+ key,
178
+ error: "Value must be a string, number, or boolean (use dotted keys for nesting)",
179
+ });
180
+ continue;
181
+ }
182
+ try {
183
+ // We pass each arg as a separate argv element — no shell involved,
184
+ // so there's no shell-injection surface even if `value` contains
185
+ // funky characters. (Which it will, for API keys.)
186
+ execFn(hermesBin, [...profilePrefix, "config", "set", key, value]);
187
+ applied += 1;
188
+ }
189
+ catch (err) {
190
+ failures.push({
191
+ key,
192
+ error: err instanceof Error ? err.message : String(err),
193
+ });
194
+ }
195
+ }
196
+ return { applied, failures };
197
+ }
198
+ // ---------------------------------------------------------------------------
199
+ // Entry point
200
+ // ---------------------------------------------------------------------------
201
+ // ---------------------------------------------------------------------------
202
+ // Platform-mode expansion
203
+ // ---------------------------------------------------------------------------
204
+ /**
205
+ * Expand a "platform" mode bundle into concrete Hermes inference config.
206
+ *
207
+ * When the user picked "Fast & cheap" or "Smart max-effort" on Forge, the
208
+ * bundle from the web UI doesn't carry a real API key — those presets use
209
+ * Nookplot's gateway proxy (OpenAI-compat at /v1/openai/v1/chat/completions),
210
+ * which charges the user's NOOK balance. The bundle instead carries SENTINEL
211
+ * keys that signal "expand me locally":
212
+ *
213
+ * __nookplot_inference_mode = "platform"
214
+ * __nookplot_platform_model = "hermes-3-llama-3.1-8b" (or whichever model)
215
+ * __nookplot_gateway_base = "https://gateway.nookplot.com" (optional)
216
+ *
217
+ * This function:
218
+ * 1. Detects the platform-mode marker.
219
+ * 2. Reads the user's Nookplot API key from local ~/.nookplot/credentials.json.
220
+ * The API key NEVER touches the bundle (so it never lands on the gateway
221
+ * staging table or in transit). The web-staged bundle only has the
222
+ * metadata above; expansion happens at install time on the user's machine.
223
+ * 3. Returns a NEW config object with sentinels stripped + gateway-proxy
224
+ * Hermes config keys added (model.base_url, OPENAI_API_KEY, model.default).
225
+ *
226
+ * Returns the original config unchanged when no platform marker is present —
227
+ * BYOK + messaging-only bundles continue to work exactly as before.
228
+ *
229
+ * Why the indirection vs. just including the API key in the bundle:
230
+ * - Bundle ciphertext lands on the gateway briefly (15-minute TTL). Even
231
+ * though it's encrypted client-side, fewer copies of the user's API key
232
+ * in transit = less attack surface.
233
+ * - Bundle is one-time-use; a user re-installing on a new machine would
234
+ * need a new bundle. Reading from local creds avoids that round-trip.
235
+ * - Future per-agent scoped tokens slot in here without changing the
236
+ * bundle protocol.
237
+ */
238
+ /**
239
+ * Whitelist of trusted gateway origins for the `__nookplot_gateway_base`
240
+ * override. This guards against bundle-tamper key exfiltration.
241
+ *
242
+ * The installer's own `gatewayUrl` argument is always trusted (it was
243
+ * baked into the install script by the gateway that served it), so we
244
+ * also accept any URL whose origin matches `gatewayUrl`'s origin —
245
+ * that covers staging environments transparently.
246
+ */
247
+ const TRUSTED_GATEWAY_ORIGINS = new Set([
248
+ "https://gateway.nookplot.com",
249
+ "https://gateway-dev.nookplot.com",
250
+ "http://localhost:8080",
251
+ "http://localhost:3000",
252
+ "http://127.0.0.1:8080",
253
+ "http://127.0.0.1:3000",
254
+ ]);
255
+ export function isAllowedGatewayBase(candidate, installerGatewayUrl) {
256
+ let candidateOrigin;
257
+ try {
258
+ candidateOrigin = new URL(candidate).origin;
259
+ }
260
+ catch {
261
+ return false; // malformed URL
262
+ }
263
+ if (TRUSTED_GATEWAY_ORIGINS.has(candidateOrigin))
264
+ return true;
265
+ // Also accept anything matching the installer's own gateway origin.
266
+ try {
267
+ if (new URL(installerGatewayUrl).origin === candidateOrigin)
268
+ return true;
269
+ }
270
+ catch {
271
+ /* fall through */
272
+ }
273
+ return false;
274
+ }
275
+ function expandPlatformInference(config, gatewayUrl, credentialsReader) {
276
+ const mode = config["__nookplot_inference_mode"];
277
+ if (mode !== "platform") {
278
+ // Fast path: nothing to expand. Strip any rogue __nookplot_* keys
279
+ // anyway so they never reach the Hermes key-validity check.
280
+ const stripped = {};
281
+ for (const [k, v] of Object.entries(config)) {
282
+ if (!k.startsWith("__nookplot_"))
283
+ stripped[k] = v;
284
+ }
285
+ return stripped;
286
+ }
287
+ const model = typeof config["__nookplot_platform_model"] === "string"
288
+ ? config["__nookplot_platform_model"]
289
+ : null;
290
+ // The bundle MAY override the gateway base for staging / dev contexts, but
291
+ // we whitelist the host because this URL becomes `model.base_url` in Hermes
292
+ // — which means the user's freshly-written `OPENAI_API_KEY` (read from
293
+ // local credentials) will be sent there on every inference. A bundle that
294
+ // smuggles `__nookplot_gateway_base: "https://evil.example/..."` would
295
+ // exfiltrate the user's API key on first call.
296
+ //
297
+ // Trust set: production gateway, dev gateway, localhost (development),
298
+ // plus whatever was passed as `gatewayUrl` (the installer's argument —
299
+ // already validated upstream). Anything else is silently ignored, falling
300
+ // back to `gatewayUrl`.
301
+ const rawBaseOverride = typeof config["__nookplot_gateway_base"] === "string"
302
+ ? config["__nookplot_gateway_base"]
303
+ : null;
304
+ const baseOverride = rawBaseOverride && isAllowedGatewayBase(rawBaseOverride, gatewayUrl)
305
+ ? rawBaseOverride
306
+ : null;
307
+ if (rawBaseOverride && !baseOverride) {
308
+ console.error(`[nookplot-mcp] Ignoring untrusted __nookplot_gateway_base override (${rawBaseOverride}). Using ${gatewayUrl} instead. ` +
309
+ `This protects your API key from being sent to an attacker-controlled gateway.`);
310
+ }
311
+ // Read local API key. If not found, abort the expansion — the user needs
312
+ // to register first via `nookplot register` or by deploying their first
313
+ // agent through the web flow.
314
+ const creds = credentialsReader();
315
+ if (!creds || !creds.apiKey) {
316
+ throw new Error("Platform inference mode requires a registered Nookplot account, " +
317
+ "but no credentials were found at ~/.nookplot/credentials.json. " +
318
+ "Run `nookplot register` first, or deploy your first agent on nookplot.com.");
319
+ }
320
+ // Build the expanded config. Strip ALL __nookplot_* sentinels so the
321
+ // downstream Hermes-key validator never sees them.
322
+ const expanded = {};
323
+ for (const [k, v] of Object.entries(config)) {
324
+ if (!k.startsWith("__nookplot_"))
325
+ expanded[k] = v;
326
+ }
327
+ // Trailing-slash-safe base URL. Hermes will append /chat/completions to
328
+ // model.base_url, so we end at /v1/openai/v1 (path includes the inner /v1
329
+ // because OpenAI-compat clients expect it — see openaiAdapter.ts mounting).
330
+ const base = (baseOverride ?? gatewayUrl).replace(/\/+$/, "");
331
+ expanded["model.base_url"] = `${base}/v1/openai/v1`;
332
+ // Use OPENAI_API_KEY because the gateway adapter speaks OpenAI's protocol;
333
+ // Hermes routes auth via the OpenAI provider config when model.base_url
334
+ // is set. Hermes auto-routes SCREAMING_SNAKE_CASE keys to ~/.hermes/.env
335
+ // (or the per-profile .env).
336
+ expanded["OPENAI_API_KEY"] = creds.apiKey;
337
+ // Default model — only set if the bundle specified one. (Forge always
338
+ // does, but we don't blow up if it's missing.)
339
+ if (model && !expanded["model.default"]) {
340
+ expanded["model.default"] = model;
341
+ }
342
+ return expanded;
343
+ }
344
+ /**
345
+ * Default credentials reader — reads ~/.nookplot/credentials.json and returns
346
+ * { apiKey } or null. Isolated from applyConfig main logic so tests can
347
+ * inject a stub without filesystem access.
348
+ */
349
+ function defaultCredentialsReader() {
350
+ try {
351
+ const credsPath = join(homedir(), ".nookplot", "credentials.json");
352
+ if (!existsSync(credsPath))
353
+ return null;
354
+ const raw = readFileSync(credsPath, "utf-8");
355
+ const parsed = JSON.parse(raw);
356
+ if (typeof parsed.apiKey !== "string" || !parsed.apiKey)
357
+ return null;
358
+ return { apiKey: parsed.apiKey };
359
+ }
360
+ catch {
361
+ return null;
362
+ }
363
+ }
364
+ /**
365
+ * Main orchestration: fetch → decrypt → apply. Returns a result with per-key
366
+ * success/failure so the caller can surface what happened to the user.
367
+ */
368
+ export async function applyConfig(opts) {
369
+ if (!opts.token || !/^[a-f0-9]{64}$/i.test(opts.token)) {
370
+ throw new Error("Invalid NOOKPLOT_CONFIG_TOKEN (must be 64 hex chars). " +
371
+ "Regenerate the install command on your agent's Nookplot page.");
372
+ }
373
+ if (!opts.key) {
374
+ throw new Error("Missing NOOKPLOT_CONFIG_KEY env var.");
375
+ }
376
+ const gatewayUrl = opts.gatewayUrl ?? "https://gateway.nookplot.com";
377
+ const timeoutMs = opts.timeoutMs ?? 15_000;
378
+ const hermesBin = opts.hermesBin ?? "hermes";
379
+ const fetchFn = opts._fetch ?? fetch;
380
+ const execFn = opts._exec ??
381
+ ((bin, args) => {
382
+ execFileSync(bin, args, { stdio: "pipe" });
383
+ });
384
+ // Parse the key from base64url.
385
+ let keyBytes;
386
+ try {
387
+ keyBytes = fromBase64Url(opts.key);
388
+ }
389
+ catch (err) {
390
+ throw new Error(`Could not decode NOOKPLOT_CONFIG_KEY as base64url: ${err instanceof Error ? err.message : String(err)}`);
391
+ }
392
+ // 1. Fetch the encrypted bundle (one-time-use token — gateway deletes
393
+ // the row as it responds).
394
+ const stage = await redeemCiphertext(gatewayUrl, opts.token, fetchFn, timeoutMs);
395
+ // 2. Decrypt locally. Auth-tag failures are surfaced as a clear error
396
+ // so the user can regenerate the install command.
397
+ const config = decryptBundle(stage, keyBytes);
398
+ // 2b. Expand platform-mode bundles. For Fast/Smart presets, the bundle
399
+ // contains __nookplot_* sentinel keys that we resolve locally —
400
+ // fetching the user's API key from ~/.nookplot/credentials.json
401
+ // (NEVER from the bundle) and rewriting to concrete model.base_url
402
+ // + OPENAI_API_KEY + model.default config that points Hermes at
403
+ // our gateway's OpenAI-compat adapter.
404
+ //
405
+ // For BYOK + messaging-only bundles this is a no-op (just strips
406
+ // any rogue __nookplot_* keys defensively).
407
+ const credsReader = opts._credentialsReader ?? defaultCredentialsReader;
408
+ const expanded = expandPlatformInference(config, gatewayUrl, credsReader);
409
+ // 3. Apply each entry via `hermes config set`. Hermes routes secrets
410
+ // to .env and other settings to config.yaml.
411
+ const { applied, failures } = applyToHermes(expanded, hermesBin, execFn, opts.profile);
412
+ return {
413
+ applied,
414
+ failures,
415
+ agentAddress: stage.agentAddress,
416
+ };
417
+ }
418
+ //# sourceMappingURL=applyConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyConfig.js","sourceRoot":"","sources":["../src/applyConfig.ts"],"names":[],"mappings":"AA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