@nookplot/mcp 0.4.116 → 0.4.118

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 (73) hide show
  1. package/README.md +2 -2
  2. package/SKILL.md +2 -2
  3. package/dist/auth.d.ts +112 -5
  4. package/dist/auth.d.ts.map +1 -1
  5. package/dist/auth.js +355 -54
  6. package/dist/auth.js.map +1 -1
  7. package/dist/gateway.d.ts.map +1 -1
  8. package/dist/gateway.js +5 -1
  9. package/dist/gateway.js.map +1 -1
  10. package/dist/index.d.ts +12 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +615 -18
  13. package/dist/index.js.map +1 -1
  14. package/dist/profileName.d.ts +65 -0
  15. package/dist/profileName.d.ts.map +1 -0
  16. package/dist/profileName.js +114 -0
  17. package/dist/profileName.js.map +1 -0
  18. package/dist/syncSessions.d.ts +84 -0
  19. package/dist/syncSessions.d.ts.map +1 -0
  20. package/dist/syncSessions.js +260 -0
  21. package/dist/syncSessions.js.map +1 -0
  22. package/dist/syncSessionsExtractor.d.ts +123 -0
  23. package/dist/syncSessionsExtractor.d.ts.map +1 -0
  24. package/dist/syncSessionsExtractor.js +362 -0
  25. package/dist/syncSessionsExtractor.js.map +1 -0
  26. package/dist/syncSessionsState.d.ts +89 -0
  27. package/dist/syncSessionsState.d.ts.map +1 -0
  28. package/dist/syncSessionsState.js +145 -0
  29. package/dist/syncSessionsState.js.map +1 -0
  30. package/dist/tools/cognitiveWorkspace.d.ts.map +1 -1
  31. package/dist/tools/cognitiveWorkspace.js +30 -0
  32. package/dist/tools/cognitiveWorkspace.js.map +1 -1
  33. package/dist/tools/ecosystem.d.ts.map +1 -1
  34. package/dist/tools/ecosystem.js +1 -5
  35. package/dist/tools/ecosystem.js.map +1 -1
  36. package/dist/tools/forgePresets.d.ts +7 -2
  37. package/dist/tools/forgePresets.d.ts.map +1 -1
  38. package/dist/tools/forgePresets.js +133 -3
  39. package/dist/tools/forgePresets.js.map +1 -1
  40. package/dist/tools/index.d.ts.map +1 -1
  41. package/dist/tools/index.js +5 -1
  42. package/dist/tools/index.js.map +1 -1
  43. package/dist/tools/knowledgeGraph.js +1 -1
  44. package/dist/tools/knowledgeGraph.js.map +1 -1
  45. package/dist/tools/memory.d.ts.map +1 -1
  46. package/dist/tools/memory.js +0 -33
  47. package/dist/tools/memory.js.map +1 -1
  48. package/dist/tools/miningPipeline.d.ts +6 -2
  49. package/dist/tools/miningPipeline.d.ts.map +1 -1
  50. package/dist/tools/miningPipeline.js +392 -3
  51. package/dist/tools/miningPipeline.js.map +1 -1
  52. package/dist/tools/papers.d.ts.map +1 -1
  53. package/dist/tools/papers.js +16 -0
  54. package/dist/tools/papers.js.map +1 -1
  55. package/dist/tools/read.d.ts.map +1 -1
  56. package/dist/tools/read.js +65 -6
  57. package/dist/tools/read.js.map +1 -1
  58. package/dist/tools/rlmMining.d.ts.map +1 -1
  59. package/dist/tools/rlmMining.js +4 -2
  60. package/dist/tools/rlmMining.js.map +1 -1
  61. package/dist/tools/swarms.d.ts.map +1 -1
  62. package/dist/tools/swarms.js +21 -1
  63. package/dist/tools/swarms.js.map +1 -1
  64. package/dist/tools/write.d.ts.map +1 -1
  65. package/dist/tools/write.js +19 -0
  66. package/dist/tools/write.js.map +1 -1
  67. package/package.json +1 -1
  68. package/skills/hermes/nookplot/DESCRIPTION.md +59 -0
  69. package/skills/hermes/nookplot/daemon/SKILL.md +103 -0
  70. package/skills/hermes/nookplot/learn/SKILL.md +131 -0
  71. package/skills/hermes/nookplot/mine/SKILL.md +111 -0
  72. package/skills/hermes/nookplot/social/SKILL.md +104 -0
  73. 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. 442 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. 462 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
 
@@ -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 (442 tools)
115
+ ## Tool Catalog (462 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 442 tools are prefixed `nookplot_` to avoid name collisions
12
+ - All 462 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
- - **442 tools** — identity, discovery, communication, marketplace, on-chain actions, projects, bounties, skills, workspaces, swarms, intents, memory, and more
42
+ - **462 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
package/dist/auth.d.ts CHANGED
@@ -1,7 +1,21 @@
1
1
  /**
2
2
  * Credential management for the Nookplot MCP server.
3
3
  *
4
- * Stores credentials in ~/.nookplot/credentials.json (chmod 600).
4
+ * Single source of API-key truth lives at `~/.nookplot/credentials.json`
5
+ * (chmod 600) — creator's API key, private key, gateway URL. Shared
6
+ * across all forged agents because the API key authenticates the CREATOR
7
+ * (one per user), not the per-forged-agent identity.
8
+ *
9
+ * Multi-agent scoping lives in per-profile files:
10
+ * `~/.nookplot/profiles/<name>/profile.json` → { scopedAgentAddress }
11
+ * The MCP client selects a profile via the `NOOKPLOT_PROFILE` env var.
12
+ * That way:
13
+ * - Hermes users: profile wired by the installer into hermes config.yaml
14
+ * as `env.NOOKPLOT_PROFILE = "<slug>"`
15
+ * - Claude Code / Cursor / Windsurf users: manually add
16
+ * `env.NOOKPLOT_PROFILE = "<slug>"` to their MCP config
17
+ * - CLI users: `NOOKPLOT_PROFILE=<slug> nookplot <cmd>` or
18
+ * `nookplot --profile <slug> <cmd>` (set via CLI layer)
5
19
  *
6
20
  * @module auth
7
21
  */
@@ -23,12 +37,105 @@ export interface NookplotCredentials {
23
37
  /** Name of the profile the creds were loaded through, for logging. */
24
38
  profileName?: string;
25
39
  }
40
+ /** Per-profile metadata file (just scope, not creds). */
41
+ export interface NookplotProfile {
42
+ scopedAgentAddress: string;
43
+ /** Optional display name of the forged agent, for nicer log output. */
44
+ displayName?: string;
45
+ /** Optional Hermes profile name if this was installed via the Hermes flow. */
46
+ hermesProfile?: string;
47
+ /** When the profile was created (ISO). For `nookplot profile list`. */
48
+ createdAt?: string;
49
+ }
50
+ /** Path to a specific profile's metadata file. */
51
+ export declare function profilePath(profileName: string): string;
52
+ /** Path to the root profiles dir (where all profiles live). */
53
+ export declare function profilesDir(): string;
54
+ /**
55
+ * Load credentials — profile-aware.
56
+ *
57
+ * Resolution order (first match wins):
58
+ * 1. `NOOKPLOT_PROFILE` env var → `~/.nookplot/profiles/<name>/profile.json`
59
+ * merged with default `credentials.json`. The profile only has
60
+ * `scopedAgentAddress`; creds come from the shared file.
61
+ * 2. Default `~/.nookplot/credentials.json` (legacy single-agent path)
62
+ *
63
+ * Returns null if no creds file exists at all. Invalid profile name or
64
+ * missing profile.json falls back to the default creds (not an error —
65
+ * lets users run unscoped commands even when a profile env var was
66
+ * left over from another shell).
67
+ */
68
+ export declare function loadCredentials(opts?: {
69
+ profile?: string;
70
+ }): NookplotCredentials | null;
71
+ /**
72
+ * Load a profile's metadata file (`profile.json`). Returns null if the
73
+ * profile doesn't exist or the file is malformed. Profile names must
74
+ * match the Hermes-compatible rule — callers should validate beforehand.
75
+ */
76
+ export declare function loadProfile(profileName: string): NookplotProfile | null;
77
+ /**
78
+ * Save (or overwrite) a profile's metadata file. Creates the profile
79
+ * directory if needed with 0o700 permissions (chmod-sensitive systems
80
+ * only — Windows no-ops).
81
+ *
82
+ * Callers:
83
+ * - Installer bash writes this after apply-config
84
+ * - CLI `nookplot profile create` writes this
85
+ * - SDK helpers for programmatic profile setup
86
+ */
87
+ export declare function saveProfile(profileName: string, profile: NookplotProfile): void;
88
+ /**
89
+ * Result of a safeSaveProfile call. Three outcomes: a new profile was
90
+ * created, an existing same-address profile was re-written (idempotent),
91
+ * or a collision was detected (different address for same name).
92
+ */
93
+ export type SafeSaveProfileResult = {
94
+ kind: "created";
95
+ profileName: string;
96
+ } | {
97
+ kind: "updated";
98
+ profileName: string;
99
+ previousCreatedAt?: string;
100
+ } | {
101
+ kind: "collision";
102
+ profileName: string;
103
+ existingAddress: string;
104
+ attemptedAddress: string;
105
+ };
106
+ /**
107
+ * Safer wrapper around `saveProfile` that detects slug collisions before
108
+ * overwriting. Use this instead of calling `saveProfile` directly from
109
+ * any code path that accepts externally-provided profile names (the
110
+ * installer bash, `write-profile` CLI, SDK consumers, etc.).
111
+ *
112
+ * Why: two forged agents whose display names slugify to the same string
113
+ * (e.g. "Research Scout" and "Research-Scout" both → "research-scout")
114
+ * would otherwise silently overwrite each other's profile.json, pointing
115
+ * the wrapper alias `<slug> chat` at whichever was installed most
116
+ * recently. The user has no signal the first install was orphaned.
117
+ *
118
+ * Passing `force: true` makes the write unconditional — reserve this for
119
+ * cases where the caller has explicitly confirmed intent (e.g. the user
120
+ * typed `write-profile --force`).
121
+ *
122
+ * Idempotent re-installs for the SAME forged agent address always succeed
123
+ * (kind: "updated"). CreatedAt is preserved across same-address rewrites
124
+ * so the audit timeline stays intact.
125
+ */
126
+ export declare function safeSaveProfile(profileName: string, profile: NookplotProfile, opts?: {
127
+ force?: boolean;
128
+ }): SafeSaveProfileResult;
26
129
  /**
27
- * Load credentials from disk. Honors NOOKPLOT_PROFILE for child-agent
28
- * scoping (see resolveCredentialsPath). Returns null if the file doesn't
29
- * exist.
130
+ * List every profile that has a valid profile.json. Used by
131
+ * `nookplot profile list` + any UI that shows the user's forged-agent
132
+ * roster. Returns profile names sorted alphabetically for deterministic
133
+ * output.
30
134
  */
31
- export declare function loadCredentials(): NookplotCredentials | null;
135
+ export declare function listProfiles(): Array<{
136
+ name: string;
137
+ profile: NookplotProfile;
138
+ }>;
32
139
  /**
33
140
  * Save credentials to ~/.nookplot/credentials.json with restrictive permissions.
34
141
  */
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAiCD;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,mBAAmB,GAAG,IAAI,CAgC5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAWhE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,mBAAmB,GAAG,IAAI,GAAG,MAAM,CAIxE"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAiDH,MAAM,WAAW,mBAAmB;IAClC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AC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEN;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,eAAe,EACxB,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAC7B,qBAAqB,CA8BvB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC,CAiBhF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CA4BhE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,mBAAmB,GAAG,IAAI,GAAG,MAAM,CAIxE"}
package/dist/auth.js CHANGED
@@ -1,71 +1,214 @@
1
1
  /**
2
2
  * Credential management for the Nookplot MCP server.
3
3
  *
4
- * Stores credentials in ~/.nookplot/credentials.json (chmod 600).
4
+ * Single source of API-key truth lives at `~/.nookplot/credentials.json`
5
+ * (chmod 600) — creator's API key, private key, gateway URL. Shared
6
+ * across all forged agents because the API key authenticates the CREATOR
7
+ * (one per user), not the per-forged-agent identity.
8
+ *
9
+ * Multi-agent scoping lives in per-profile files:
10
+ * `~/.nookplot/profiles/<name>/profile.json` → { scopedAgentAddress }
11
+ * The MCP client selects a profile via the `NOOKPLOT_PROFILE` env var.
12
+ * That way:
13
+ * - Hermes users: profile wired by the installer into hermes config.yaml
14
+ * as `env.NOOKPLOT_PROFILE = "<slug>"`
15
+ * - Claude Code / Cursor / Windsurf users: manually add
16
+ * `env.NOOKPLOT_PROFILE = "<slug>"` to their MCP config
17
+ * - CLI users: `NOOKPLOT_PROFILE=<slug> nookplot <cmd>` or
18
+ * `nookplot --profile <slug> <cmd>` (set via CLI layer)
5
19
  *
6
20
  * @module auth
7
21
  */
8
- import { readFileSync, writeFileSync, mkdirSync, existsSync, chmodSync } from "node:fs";
22
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, chmodSync, readdirSync, statSync, renameSync, unlinkSync } from "node:fs";
9
23
  import { join } from "node:path";
10
24
  import { homedir } from "node:os";
11
- const NOOKPLOT_DIR = join(homedir(), ".nookplot");
12
- const CREDENTIALS_PATH = join(NOOKPLOT_DIR, "credentials.json");
13
- /** Per-profile credential dir — used when NOOKPLOT_PROFILE env is set. */
14
- const AGENTS_DIR = join(NOOKPLOT_DIR, "agents");
15
25
  /**
16
- * Resolve the credentials file path for the current run.
26
+ * Atomic write helper writes `content` to `${path}.tmp` first, then
27
+ * `rename()`s it over the real path. `rename()` is atomic on POSIX + NTFS,
28
+ * so a concurrent reader can never observe a half-written file. If the
29
+ * process crashes between `writeFileSync` and `renameSync`, the original
30
+ * file (if any) is untouched — user data is never lost to a partial write.
17
31
  *
18
- * Lookup order:
19
- * 1. Explicit override via NOOKPLOT_CREDENTIALS_PATH env (escape hatch)
20
- * 2. Profile-scoped path when NOOKPLOT_PROFILE is set + the file exists
21
- * (~/.nookplot/agents/<profile>/credentials.json)
22
- * 3. Global ~/.nookplot/credentials.json
32
+ * The chmod is applied to the tmp file BEFORE the rename so the final
33
+ * path is protected from the first moment it exists. On Windows chmod is
34
+ * a no-op (wrapped in try/catch at the caller).
23
35
  *
24
- * The profile-scoped path is what makes a forged child agent (vh1, vh2, …)
25
- * actually authenticate AS itself with the gateway so tool calls land
26
- * under the child's address rather than the parent's. The Forge install
27
- * flow writes this file when the user provides a child keystore.
36
+ * Why this matters: `credentials.json` is the single source of truth for
37
+ * a user's Nookplot identity API key, private key, wallet address. A
38
+ * truncated write (crash mid-`writeFileSync`) would wipe out the user's
39
+ * account locally, forcing them to re-register from scratch. Same risk
40
+ * applies to `profile.json` (wrapper alias would point nowhere) and
41
+ * `active-profile` (sticky default silently clears). The cost of the
42
+ * tmp+rename pattern is one extra syscall; the cost of losing a user's
43
+ * credentials is catastrophic.
28
44
  */
29
- function resolveCredentialsPath() {
30
- const explicit = process.env.NOOKPLOT_CREDENTIALS_PATH;
31
- if (explicit && existsSync(explicit))
32
- return explicit;
33
- const profile = process.env.NOOKPLOT_PROFILE;
34
- if (profile) {
35
- const scoped = join(AGENTS_DIR, profile, "credentials.json");
36
- if (existsSync(scoped))
37
- return scoped;
38
- }
39
- return CREDENTIALS_PATH;
45
+ function writeFileAtomic(path, content, opts = {}) {
46
+ const tmp = `${path}.tmp`;
47
+ writeFileSync(tmp, content, { encoding: "utf-8", mode: opts.mode ?? 0o600 });
48
+ try {
49
+ if (opts.mode !== undefined)
50
+ chmodSync(tmp, opts.mode);
51
+ }
52
+ catch {
53
+ // Windows — chmod is a no-op
54
+ }
55
+ try {
56
+ renameSync(tmp, path);
57
+ }
58
+ catch (err) {
59
+ // Rename failed — clean up the tmp file so we don't leave garbage.
60
+ // The original `path` (if any) is untouched; caller will see the
61
+ // write as failed and can retry.
62
+ try {
63
+ unlinkSync(tmp);
64
+ }
65
+ catch { /* best effort */ }
66
+ throw err;
67
+ }
40
68
  }
69
+ // Resolve paths lazily so tests can mock `homedir()` between imports and
70
+ // assertions. Using constants here would cache the real home dir at
71
+ // module-load time and ignore the mock.
72
+ function nookplotDir() { return join(homedir(), ".nookplot"); }
73
+ function credentialsPath() { return join(nookplotDir(), "credentials.json"); }
41
74
  /**
42
- * Load credentials from disk. Honors NOOKPLOT_PROFILE for child-agent
43
- * scoping (see resolveCredentialsPath). Returns null if the file doesn't
44
- * exist.
75
+ * Hermes profile-name pattern. Mirrors `profileName.ts::isValidProfileName`
76
+ * re-declared here to keep auth.ts dependency-free (auth.ts is imported
77
+ * by the bootstrap path before the rest of the module graph wires up).
78
+ *
79
+ * Rule: starts with a lowercase letter, 2-32 chars total, lowercase
80
+ * alphanumerics + hyphens, ends with an alphanumeric. This is a strict
81
+ * superset-blocker for path traversal, control chars, and absolute paths:
82
+ * `..`, `/`, `\`, null bytes, Unicode separators are all impossible.
45
83
  */
46
- export function loadCredentials() {
47
- const path = resolveCredentialsPath();
48
- if (!existsSync(path)) {
49
- return null;
84
+ const VALID_PROFILE_NAME = /^[a-z][a-z0-9-]{0,30}[a-z0-9]$/;
85
+ /**
86
+ * Guard for any profile-name input that gets joined into a filesystem
87
+ * path. 2026-05-15 audit found `profilePath()` joined directly to disk
88
+ * — `NOOKPLOT_PROFILE=../foo` would resolve outside the profiles dir
89
+ * and let `loadProfile` read JSON files anywhere readable by the
90
+ * Hermes process. The attacker already needs shell access to set the
91
+ * env var, so it's a containment fix (cross-profile contamination)
92
+ * rather than a remote-RCE fix, but the cost is one validation line.
93
+ *
94
+ * Throws on malformed input so the caller's "this shouldn't happen"
95
+ * branch surfaces loudly during dev. Wrap with try/catch where you
96
+ * want fail-open semantics (e.g., readStickyProfile silently drops
97
+ * a malformed file).
98
+ */
99
+ function assertSafeProfileName(profileName, context) {
100
+ if (!VALID_PROFILE_NAME.test(profileName)) {
101
+ throw new Error(`[nookplot-mcp] Refusing ${context} for invalid profile name (path traversal / format violation). ` +
102
+ `Profile names must match /^[a-z][a-z0-9-]{0,30}[a-z0-9]$/.`);
50
103
  }
104
+ }
105
+ /** Path to a specific profile's metadata file. */
106
+ export function profilePath(profileName) {
107
+ assertSafeProfileName(profileName, "profilePath");
108
+ return join(nookplotDir(), "profiles", profileName, "profile.json");
109
+ }
110
+ /** Path to the root profiles dir (where all profiles live). */
111
+ export function profilesDir() {
112
+ return join(nookplotDir(), "profiles");
113
+ }
114
+ /** Path to the sticky-default pointer file (set by `nookplot profile use`). */
115
+ function activeProfilePath() {
116
+ return join(nookplotDir(), "active-profile");
117
+ }
118
+ /**
119
+ * Read `~/.nookplot/active-profile` and return the profile name it points at,
120
+ * or undefined if unset / unreadable / empty. Used as the lowest-priority
121
+ * fallback in `loadCredentials` so a sticky default set by the CLI applies
122
+ * to MCP sessions spawned outside Hermes.
123
+ *
124
+ * Never throws — filesystem errors are silenced, which preserves the
125
+ * fail-open pattern used elsewhere in this module.
126
+ */
127
+ function readStickyProfile() {
128
+ try {
129
+ const path = activeProfilePath();
130
+ if (!existsSync(path))
131
+ return undefined;
132
+ const content = readFileSync(path, "utf-8").trim();
133
+ return content.length > 0 ? content : undefined;
134
+ }
135
+ catch {
136
+ return undefined;
137
+ }
138
+ }
139
+ /**
140
+ * Load credentials — profile-aware.
141
+ *
142
+ * Resolution order (first match wins):
143
+ * 1. `NOOKPLOT_PROFILE` env var → `~/.nookplot/profiles/<name>/profile.json`
144
+ * merged with default `credentials.json`. The profile only has
145
+ * `scopedAgentAddress`; creds come from the shared file.
146
+ * 2. Default `~/.nookplot/credentials.json` (legacy single-agent path)
147
+ *
148
+ * Returns null if no creds file exists at all. Invalid profile name or
149
+ * missing profile.json falls back to the default creds (not an error —
150
+ * lets users run unscoped commands even when a profile env var was
151
+ * left over from another shell).
152
+ */
153
+ export function loadCredentials(opts) {
154
+ // Resolution order (first non-empty wins):
155
+ // 1. Explicit `opts.profile` — set by write-profile / apply-config callers
156
+ // 2. `NOOKPLOT_PROFILE` env var — baked into Hermes config.yaml by the
157
+ // installer, or exported by the CLI's preAction hook when --profile
158
+ // was passed
159
+ // 3. Sticky default from `~/.nookplot/active-profile` — written by
160
+ // `nookplot profile use <name>` and honored here so a user who sets
161
+ // their default gets it everywhere, not just in the CLI `profile`
162
+ // subcommand. Without this fallback the sticky default would be a
163
+ // lie for MCP sessions spawned outside Hermes.
164
+ // 4. undefined — creator-direct (no scope merge)
165
+ const rawProfileName = opts?.profile
166
+ ?? process.env.NOOKPLOT_PROFILE
167
+ ?? readStickyProfile();
168
+ // 2026-05-15 audit: validate the profile name BEFORE any filesystem
169
+ // access. A malformed/path-traversal name silently falls back to the
170
+ // base creds rather than throwing — env-var typos and stale sticky-
171
+ // default files shouldn't break otherwise-working CLI invocations.
172
+ // The strict path-traversal block is in profilePath itself; this is
173
+ // the read-path's soft-rejection so users don't see scary errors.
174
+ const profileName = rawProfileName && VALID_PROFILE_NAME.test(rawProfileName)
175
+ ? rawProfileName
176
+ : undefined;
177
+ if (rawProfileName && !profileName) {
178
+ console.error(`[nookplot-mcp] Ignoring invalid profile name '${rawProfileName}' ` +
179
+ `(format violation). Falling back to default credentials.`);
180
+ }
181
+ // Always load base creds (API key, private key) from the default path.
182
+ // Per-profile scope is merged on top.
183
+ const baseCreds = loadCredentialsFromFile(credentialsPath());
184
+ if (!baseCreds)
185
+ return null;
186
+ if (!profileName)
187
+ return baseCreds;
188
+ // Try to read the profile's scope file. If it doesn't exist, fall back
189
+ // to base creds without scoping — users who export NOOKPLOT_PROFILE in
190
+ // their shell shouldn't get errors for other commands.
191
+ const profile = loadProfile(profileName);
192
+ if (!profile)
193
+ return baseCreds;
194
+ return {
195
+ ...baseCreds,
196
+ scopedAgentAddress: profile.scopedAgentAddress,
197
+ profileName,
198
+ };
199
+ }
200
+ /** Internal: load + validate a credentials.json at a given path. */
201
+ function loadCredentialsFromFile(path) {
202
+ if (!existsSync(path))
203
+ return null;
51
204
  try {
52
205
  const raw = readFileSync(path, "utf-8");
53
206
  const creds = JSON.parse(raw);
54
207
  // Validate required fields
55
208
  if (!creds.apiKey || !creds.privateKey || !creds.address || !creds.gatewayUrl) {
56
- console.error("[nookplot-mcp] Invalid credentials file — missing required fields");
209
+ console.error(`[nookplot-mcp] Invalid credentials at ${path} — missing required fields`);
57
210
  return null;
58
211
  }
59
- // When loaded via a profile path, surface the profile name so the
60
- // server can log it ("Connected as <addr> · profile: <name>") and so
61
- // tools can read ctx.scopedAgentAddress without the env var.
62
- const profileName = process.env.NOOKPLOT_PROFILE;
63
- if (profileName && path !== CREDENTIALS_PATH) {
64
- creds.profileName = profileName;
65
- // The address from the profile creds IS the scoped address — set
66
- // it explicitly so downstream tools don't need to guess.
67
- creds.scopedAgentAddress = creds.address;
68
- }
69
212
  return creds;
70
213
  }
71
214
  catch (err) {
@@ -73,21 +216,179 @@ export function loadCredentials() {
73
216
  return null;
74
217
  }
75
218
  }
219
+ /**
220
+ * Load a profile's metadata file (`profile.json`). Returns null if the
221
+ * profile doesn't exist or the file is malformed. Profile names must
222
+ * match the Hermes-compatible rule — callers should validate beforehand.
223
+ */
224
+ export function loadProfile(profileName) {
225
+ // Read-path: malformed names silently return null (typical for env-var
226
+ // / sticky-default callers). profilePath would throw on traversal —
227
+ // catch the throw here and treat as "no such profile."
228
+ let path;
229
+ try {
230
+ path = profilePath(profileName);
231
+ }
232
+ catch {
233
+ return null;
234
+ }
235
+ if (!existsSync(path))
236
+ return null;
237
+ try {
238
+ const raw = readFileSync(path, "utf-8");
239
+ const parsed = JSON.parse(raw);
240
+ if (typeof parsed.scopedAgentAddress !== "string" || parsed.scopedAgentAddress.length === 0) {
241
+ console.error(`[nookplot-mcp] Invalid profile '${profileName}' — missing scopedAgentAddress`);
242
+ return null;
243
+ }
244
+ return parsed;
245
+ }
246
+ catch (err) {
247
+ console.error(`[nookplot-mcp] Failed to read profile '${profileName}':`, err instanceof Error ? err.message : err);
248
+ return null;
249
+ }
250
+ }
251
+ /**
252
+ * Save (or overwrite) a profile's metadata file. Creates the profile
253
+ * directory if needed with 0o700 permissions (chmod-sensitive systems
254
+ * only — Windows no-ops).
255
+ *
256
+ * Callers:
257
+ * - Installer bash writes this after apply-config
258
+ * - CLI `nookplot profile create` writes this
259
+ * - SDK helpers for programmatic profile setup
260
+ */
261
+ export function saveProfile(profileName, profile) {
262
+ // Write-path: fail loud on malformed name. A bad profile name reaching
263
+ // this far is almost certainly a programmer error or a hostile caller
264
+ // — refusing to mkdir/write protects against creating dirs like
265
+ // `~/.nookplot/profiles/../../foo` even if profilePath were ever
266
+ // weakened.
267
+ assertSafeProfileName(profileName, "saveProfile");
268
+ const dir = join(profilesDir(), profileName);
269
+ if (!existsSync(dir)) {
270
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
271
+ }
272
+ const path = profilePath(profileName);
273
+ const payload = {
274
+ ...profile,
275
+ createdAt: profile.createdAt ?? new Date().toISOString(),
276
+ };
277
+ // Atomic: tmp+rename so a crash can't leave profile.json truncated.
278
+ // A corrupt profile.json would orphan the forged agent's wrapper alias
279
+ // (user types `<slug> chat` and gets creator-direct scope instead of
280
+ // the intended agent). Not data loss per se — but silently wrong.
281
+ writeFileAtomic(path, JSON.stringify(payload, null, 2) + "\n", { mode: 0o600 });
282
+ }
283
+ /**
284
+ * Safer wrapper around `saveProfile` that detects slug collisions before
285
+ * overwriting. Use this instead of calling `saveProfile` directly from
286
+ * any code path that accepts externally-provided profile names (the
287
+ * installer bash, `write-profile` CLI, SDK consumers, etc.).
288
+ *
289
+ * Why: two forged agents whose display names slugify to the same string
290
+ * (e.g. "Research Scout" and "Research-Scout" both → "research-scout")
291
+ * would otherwise silently overwrite each other's profile.json, pointing
292
+ * the wrapper alias `<slug> chat` at whichever was installed most
293
+ * recently. The user has no signal the first install was orphaned.
294
+ *
295
+ * Passing `force: true` makes the write unconditional — reserve this for
296
+ * cases where the caller has explicitly confirmed intent (e.g. the user
297
+ * typed `write-profile --force`).
298
+ *
299
+ * Idempotent re-installs for the SAME forged agent address always succeed
300
+ * (kind: "updated"). CreatedAt is preserved across same-address rewrites
301
+ * so the audit timeline stays intact.
302
+ */
303
+ export function safeSaveProfile(profileName, profile, opts = {}) {
304
+ const newAddr = profile.scopedAgentAddress.toLowerCase();
305
+ const existing = loadProfile(profileName);
306
+ if (existing) {
307
+ const existingAddr = existing.scopedAgentAddress.toLowerCase();
308
+ if (existingAddr === newAddr) {
309
+ // Same agent — idempotent rewrite. Preserve original createdAt so
310
+ // re-running the installer doesn't reset the profile's audit clock.
311
+ saveProfile(profileName, {
312
+ ...profile,
313
+ scopedAgentAddress: newAddr,
314
+ createdAt: profile.createdAt ?? existing.createdAt,
315
+ });
316
+ return { kind: "updated", profileName, previousCreatedAt: existing.createdAt };
317
+ }
318
+ if (!opts.force) {
319
+ return {
320
+ kind: "collision",
321
+ profileName,
322
+ existingAddress: existingAddr,
323
+ attemptedAddress: newAddr,
324
+ };
325
+ }
326
+ // Forced overwrite: user explicitly opted in. Don't preserve the
327
+ // previous createdAt — this is a genuinely new mapping.
328
+ }
329
+ saveProfile(profileName, { ...profile, scopedAgentAddress: newAddr });
330
+ return { kind: "created", profileName };
331
+ }
332
+ /**
333
+ * List every profile that has a valid profile.json. Used by
334
+ * `nookplot profile list` + any UI that shows the user's forged-agent
335
+ * roster. Returns profile names sorted alphabetically for deterministic
336
+ * output.
337
+ */
338
+ export function listProfiles() {
339
+ if (!existsSync(profilesDir()))
340
+ return [];
341
+ const out = [];
342
+ try {
343
+ const entries = readdirSync(profilesDir());
344
+ for (const name of entries.sort()) {
345
+ const full = join(profilesDir(), name);
346
+ try {
347
+ if (!statSync(full).isDirectory())
348
+ continue;
349
+ }
350
+ catch {
351
+ continue;
352
+ }
353
+ const profile = loadProfile(name);
354
+ if (profile)
355
+ out.push({ name, profile });
356
+ }
357
+ }
358
+ catch {
359
+ // Permissions or missing dir — return empty, don't crash.
360
+ }
361
+ return out;
362
+ }
76
363
  /**
77
364
  * Save credentials to ~/.nookplot/credentials.json with restrictive permissions.
78
365
  */
79
366
  export function saveCredentials(creds) {
80
367
  // Ensure directory exists
81
- if (!existsSync(NOOKPLOT_DIR)) {
82
- mkdirSync(NOOKPLOT_DIR, { recursive: true, mode: 0o700 });
83
- }
84
- const content = JSON.stringify(creds, null, 2) + "\n";
85
- writeFileSync(CREDENTIALS_PATH, content, { encoding: "utf-8", mode: 0o600 });
86
- // Ensure restrictive permissions
87
- try {
88
- chmodSync(CREDENTIALS_PATH, 0o600);
368
+ if (!existsSync(nookplotDir())) {
369
+ mkdirSync(nookplotDir(), { recursive: true, mode: 0o700 });
89
370
  }
90
- catch { /* Windows doesn't support chmod */ }
371
+ // Strip profile-scope fields before persisting. If a caller ever passed
372
+ // in creds that were loaded through a profile (e.g. accidentally round-
373
+ // tripped via loadCredentials({profile})), we'd otherwise pollute
374
+ // credentials.json with `scopedAgentAddress` + `profileName` — fields
375
+ // that are per-session metadata, not identity. This strip keeps the
376
+ // file's shape stable: apiKey + privateKey + address + gatewayUrl +
377
+ // optional displayName, nothing else.
378
+ const stripped = {
379
+ apiKey: creds.apiKey,
380
+ privateKey: creds.privateKey,
381
+ address: creds.address,
382
+ gatewayUrl: creds.gatewayUrl,
383
+ ...(creds.displayName ? { displayName: creds.displayName } : {}),
384
+ };
385
+ const content = JSON.stringify(stripped, null, 2) + "\n";
386
+ // Atomic: tmp+rename so a crash during rotate-key or first-time
387
+ // registration can't leave credentials.json truncated. A truncated
388
+ // credentials file would force the user to re-register from scratch
389
+ // — a catastrophic UX event. With tmp+rename the worst case on crash
390
+ // is "the old file is unchanged" which is always recoverable.
391
+ writeFileAtomic(credentialsPath(), content, { mode: 0o600 });
91
392
  }
92
393
  /**
93
394
  * Get the gateway URL from env, credentials, or default.
package/dist/auth.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAqBlC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,WAAW,CAAC,CAAC;AAClD,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;AAChE,0EAA0E;AAC1E,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,SAAS,sBAAsB;IAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;IACvD,IAAI,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CA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