@productbrain/mcp 0.0.1-beta.2 → 0.0.1-beta.200
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.
- package/.env.mcp.example +12 -13
- package/dist/chunk-4J2IMFS7.js +15947 -0
- package/dist/chunk-4J2IMFS7.js.map +1 -0
- package/dist/chunk-YMF3IQ5E.js +465 -0
- package/dist/chunk-YMF3IQ5E.js.map +1 -0
- package/dist/cli/index.js +1 -1
- package/dist/http.js +1307 -0
- package/dist/http.js.map +1 -0
- package/dist/index.js +76 -4231
- package/dist/index.js.map +1 -1
- package/dist/setup-RYYXRDPB.js +297 -0
- package/dist/setup-RYYXRDPB.js.map +1 -0
- package/dist/views/src/entry-cards/index.html +227 -0
- package/dist/views/src/graph-constellation/index.html +254 -0
- package/package.json +11 -3
- package/dist/chunk-DGUM43GV.js +0 -11
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/setup-V6HIAYXL.js +0 -227
- package/dist/setup-V6HIAYXL.js.map +0 -1
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
MCP_NPX_PACKAGE,
|
|
4
|
+
initAnalytics,
|
|
5
|
+
resolveClient,
|
|
6
|
+
shutdownAnalytics,
|
|
7
|
+
trackSetupCompleted,
|
|
8
|
+
trackSetupStarted,
|
|
9
|
+
writeClientConfig
|
|
10
|
+
} from "./chunk-YMF3IQ5E.js";
|
|
11
|
+
|
|
12
|
+
// src/cli/setup.ts
|
|
13
|
+
import { execSync } from "child_process";
|
|
14
|
+
import { createInterface } from "readline";
|
|
15
|
+
import { existsSync, writeFileSync, mkdirSync } from "fs";
|
|
16
|
+
import { join } from "path";
|
|
17
|
+
var APP_URL = process.env.PRODUCTBRAIN_APP_URL ?? "https://work.productbrain.io";
|
|
18
|
+
function bold(s) {
|
|
19
|
+
return `\x1B[1m${s}\x1B[0m`;
|
|
20
|
+
}
|
|
21
|
+
function green(s) {
|
|
22
|
+
return `\x1B[32m${s}\x1B[0m`;
|
|
23
|
+
}
|
|
24
|
+
function dim(s) {
|
|
25
|
+
return `\x1B[2m${s}\x1B[0m`;
|
|
26
|
+
}
|
|
27
|
+
function orange(s) {
|
|
28
|
+
return `\x1B[33m${s}\x1B[0m`;
|
|
29
|
+
}
|
|
30
|
+
function log(msg) {
|
|
31
|
+
process.stdout.write(`${msg}
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
function openBrowser(url) {
|
|
35
|
+
const platform = process.platform;
|
|
36
|
+
try {
|
|
37
|
+
if (platform === "darwin") execSync(`open "${url}"`);
|
|
38
|
+
else if (platform === "win32") execSync(`start "" "${url}"`);
|
|
39
|
+
else execSync(`xdg-open "${url}"`);
|
|
40
|
+
} catch {
|
|
41
|
+
log(dim(` Could not open browser automatically.`));
|
|
42
|
+
log(` Open this URL manually: ${url}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function prompt(question) {
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
48
|
+
rl.question(question, (answer) => {
|
|
49
|
+
rl.close();
|
|
50
|
+
resolve(answer.trim());
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function promptChoice(question, choices) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
log("");
|
|
57
|
+
log(bold(question));
|
|
58
|
+
choices.forEach((c, i) => log(` ${i + 1}) ${c}`));
|
|
59
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
60
|
+
rl.question(`
|
|
61
|
+
${dim("Choice [1]:")} `, (line) => {
|
|
62
|
+
rl.close();
|
|
63
|
+
const n = parseInt(line.trim(), 10);
|
|
64
|
+
if (isNaN(n) || n < 1 || n > choices.length) {
|
|
65
|
+
resolve(0);
|
|
66
|
+
} else {
|
|
67
|
+
resolve(n - 1);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
var DEFAULT_CLOUD_URL = "https://gateway.productbrain.io";
|
|
73
|
+
async function verifyWorkspace(apiKey) {
|
|
74
|
+
const siteUrl = process.env.CONVEX_SITE_URL ?? process.env.PRODUCTBRAIN_URL ?? DEFAULT_CLOUD_URL;
|
|
75
|
+
try {
|
|
76
|
+
const res = await fetch(`${siteUrl.replace(/\/$/, "")}/api/aki`, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
Authorization: `Bearer ${apiKey}`
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify({ fn: "resolveWorkspace", args: {} })
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok) return null;
|
|
85
|
+
const json = await res.json();
|
|
86
|
+
return json.data ?? null;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function runSetup() {
|
|
92
|
+
initAnalytics();
|
|
93
|
+
trackSetupStarted();
|
|
94
|
+
log("");
|
|
95
|
+
log(bold(` Product${orange("Brain")} Setup`));
|
|
96
|
+
log(dim(" Connect your AI assistant to your chain\n"));
|
|
97
|
+
const apiKeysUrl = `${APP_URL}/settings/api-keys`;
|
|
98
|
+
log(` ${dim("1. Get your API key from Settings \u2192 API Keys")}`);
|
|
99
|
+
log(` ${dim(apiKeysUrl)}
|
|
100
|
+
`);
|
|
101
|
+
const openNow = await prompt(` Open this URL in your browser? [Y/n]: `);
|
|
102
|
+
if (openNow.toLowerCase() !== "n" && openNow.toLowerCase() !== "no") {
|
|
103
|
+
openBrowser(apiKeysUrl);
|
|
104
|
+
}
|
|
105
|
+
log("");
|
|
106
|
+
log(` ${dim("2. Generate a key (if you don't have one), then copy it.\n")}`);
|
|
107
|
+
const apiKey = await prompt(` Paste your API key (pb_sk_...): `);
|
|
108
|
+
if (!apiKey || !apiKey.startsWith("pb_sk_")) {
|
|
109
|
+
log(` ${orange("!")} Invalid key format. Keys start with pb_sk_.`);
|
|
110
|
+
log(` Get one at ${apiKeysUrl}
|
|
111
|
+
`);
|
|
112
|
+
await shutdownAnalytics();
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
log(` ${green("\u2713")} Key received`);
|
|
116
|
+
const workspace = await verifyWorkspace(apiKey);
|
|
117
|
+
if (workspace) {
|
|
118
|
+
log(` ${green("\u2713")} Connected to workspace: ${bold(workspace.name)} ${dim(`(${workspace.slug})`)}`);
|
|
119
|
+
} else {
|
|
120
|
+
log(` ${orange("!")} Could not verify workspace. Check your key at ${apiKeysUrl}`);
|
|
121
|
+
}
|
|
122
|
+
log("");
|
|
123
|
+
const CLIENT_NAMES = ["Cursor", "Claude Desktop"];
|
|
124
|
+
const options = [...CLIENT_NAMES, "Other"];
|
|
125
|
+
const choice = await promptChoice("Where do you want to set up Product Brain?", options);
|
|
126
|
+
if (choice === 2) {
|
|
127
|
+
printConfigSnippet(apiKey);
|
|
128
|
+
trackSetupCompleted("Other", "snippet_shown");
|
|
129
|
+
} else {
|
|
130
|
+
const client = resolveClient(CLIENT_NAMES[choice]);
|
|
131
|
+
if (client) {
|
|
132
|
+
const outcome = await writeConfig(client, apiKey);
|
|
133
|
+
trackSetupCompleted(CLIENT_NAMES[choice], outcome);
|
|
134
|
+
} else {
|
|
135
|
+
log(` ${orange("!")} ${CLIENT_NAMES[choice]} config path not available on this platform.`);
|
|
136
|
+
printConfigSnippet(apiKey);
|
|
137
|
+
trackSetupCompleted(CLIENT_NAMES[choice], "write_error");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (choice === 0) {
|
|
141
|
+
await offerCursorRulesInstall();
|
|
142
|
+
printDeeplink(apiKey);
|
|
143
|
+
}
|
|
144
|
+
if (choice === 1) {
|
|
145
|
+
printClaudeSnippet();
|
|
146
|
+
}
|
|
147
|
+
log("");
|
|
148
|
+
log(
|
|
149
|
+
` ${green("\u2713")} Done! Restart your AI assistant and try: ${bold('"Start PB"')}`
|
|
150
|
+
);
|
|
151
|
+
printHelpLink();
|
|
152
|
+
await shutdownAnalytics();
|
|
153
|
+
}
|
|
154
|
+
async function writeConfig(client, apiKey) {
|
|
155
|
+
try {
|
|
156
|
+
const wrote = await writeClientConfig(client, apiKey);
|
|
157
|
+
if (wrote) {
|
|
158
|
+
log(` ${green("\u2713")} Wrote config to ${dim(client.configPath)}`);
|
|
159
|
+
return "config_written";
|
|
160
|
+
} else {
|
|
161
|
+
log(` ${dim("\u2139")} ${client.name} already configured \u2014 skipped`);
|
|
162
|
+
return "config_existed";
|
|
163
|
+
}
|
|
164
|
+
} catch (err) {
|
|
165
|
+
log(` ${orange("!")} Could not write ${client.name} config: ${err.message}`);
|
|
166
|
+
printConfigSnippet(apiKey);
|
|
167
|
+
return "write_error";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function printHelpLink() {
|
|
171
|
+
log(` ${dim(`Need help? See ${APP_URL}/settings/api-keys`)}`);
|
|
172
|
+
log("");
|
|
173
|
+
}
|
|
174
|
+
function printConfigSnippet(apiKey) {
|
|
175
|
+
log("");
|
|
176
|
+
log(bold(" Add this to your MCP client config:\n"));
|
|
177
|
+
const snippet = JSON.stringify(
|
|
178
|
+
{
|
|
179
|
+
mcpServers: {
|
|
180
|
+
"Product Brain": {
|
|
181
|
+
command: "npx",
|
|
182
|
+
args: ["-y", MCP_NPX_PACKAGE],
|
|
183
|
+
env: { PRODUCTBRAIN_API_KEY: apiKey }
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
null,
|
|
188
|
+
2
|
|
189
|
+
);
|
|
190
|
+
for (const line of snippet.split("\n")) {
|
|
191
|
+
log(` ${line}`);
|
|
192
|
+
}
|
|
193
|
+
log("");
|
|
194
|
+
}
|
|
195
|
+
var CURSOR_RULE_FILENAME = "product-brain.mdc";
|
|
196
|
+
var CURSOR_RULE_CONTENT = `---
|
|
197
|
+
description: Product Brain MCP \u2014 single source of truth for product knowledge
|
|
198
|
+
globs:
|
|
199
|
+
alwaysApply: true
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
# Product Brain MCP
|
|
203
|
+
|
|
204
|
+
Product Brain is your product knowledge base. The Chain is the single source of truth.
|
|
205
|
+
|
|
206
|
+
Every entry is either a **draft** (captured but not committed) or **committed** (on the Chain, SSOT).
|
|
207
|
+
Committing to the Chain is the compounding act.
|
|
208
|
+
|
|
209
|
+
## Quick Start
|
|
210
|
+
|
|
211
|
+
Say **"Start PB"** or **"Start Product Brain"** to begin. This single call:
|
|
212
|
+
- Orients you to the workspace (readiness, gaps, planned work)
|
|
213
|
+
- Unlocks write tools for the session
|
|
214
|
+
- Surfaces your next recommended action
|
|
215
|
+
|
|
216
|
+
## Tool Workflow
|
|
217
|
+
|
|
218
|
+
1. **Start here**: \`start\` \u2014 workspace context + next action
|
|
219
|
+
2. **Search**: \`entries action=search\` \u2014 find entries across all collections
|
|
220
|
+
3. **Drill in**: \`entries action=get\` \u2014 full record with data, labels, relations
|
|
221
|
+
4. **Context**: \`context action=gather\` \u2014 related knowledge around an entry or task
|
|
222
|
+
5. **Capture**: \`capture\` \u2014 create knowledge with auto-linking + quality score
|
|
223
|
+
6. **Commit**: \`commit-entry\` \u2014 promote drafts to SSOT when confirmation is still required
|
|
224
|
+
7. **Connect**: \`graph action=suggest\` then \`relations action=create\` to build the graph
|
|
225
|
+
|
|
226
|
+
## Bulk Knowledge Input
|
|
227
|
+
|
|
228
|
+
When given a document or batch of knowledge to capture:
|
|
229
|
+
1. Scan the input \u2014 identify all collections needed
|
|
230
|
+
2. Call \`collections action=list\` \u2014 compare against what exists
|
|
231
|
+
3. Propose missing collections to the user for confirmation
|
|
232
|
+
4. Call \`collections action=create\` for each confirmed collection
|
|
233
|
+
5. Then capture entries into the correct collections
|
|
234
|
+
|
|
235
|
+
Never stuff entries into the wrong collection. Never silently skip knowledge.
|
|
236
|
+
|
|
237
|
+
## Rules
|
|
238
|
+
|
|
239
|
+
- In Open mode, user-authored captures can commit immediately unless the user asks to keep them as drafts.
|
|
240
|
+
- In consensus/role modes, only call \`commit-entry\` when the user confirms.
|
|
241
|
+
- Use \`graph action=suggest\` after capturing to discover and create relations.
|
|
242
|
+
- Collections are dynamic \u2014 use \`collections action=create\` when the workspace needs new ones.
|
|
243
|
+
- When lost, fetch \`productbrain://orientation\` for the full system map.
|
|
244
|
+
`;
|
|
245
|
+
function isCursorProject() {
|
|
246
|
+
return existsSync(join(process.cwd(), ".cursor")) || existsSync(join(process.cwd(), ".cursorignore"));
|
|
247
|
+
}
|
|
248
|
+
async function offerCursorRulesInstall() {
|
|
249
|
+
if (!isCursorProject()) return;
|
|
250
|
+
const answer = await prompt(`
|
|
251
|
+
Install Product Brain rule for Cursor? [Y/n]: `);
|
|
252
|
+
if (answer.toLowerCase() === "n" || answer.toLowerCase() === "no") {
|
|
253
|
+
log(dim(" Skipped rule install."));
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const rulesDir = join(process.cwd(), ".cursor", "rules");
|
|
257
|
+
const rulePath = join(rulesDir, CURSOR_RULE_FILENAME);
|
|
258
|
+
if (existsSync(rulePath)) {
|
|
259
|
+
log(` ${dim("\u2139")} Rule already exists at ${dim(rulePath)} \u2014 skipped`);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (!existsSync(rulesDir)) {
|
|
263
|
+
mkdirSync(rulesDir, { recursive: true });
|
|
264
|
+
}
|
|
265
|
+
writeFileSync(rulePath, CURSOR_RULE_CONTENT, "utf-8");
|
|
266
|
+
log(` ${green("\u2713")} Installed rule at ${dim(rulePath)}`);
|
|
267
|
+
}
|
|
268
|
+
function buildDeeplink(apiKey) {
|
|
269
|
+
const config = JSON.stringify({
|
|
270
|
+
command: "npx",
|
|
271
|
+
args: ["-y", MCP_NPX_PACKAGE],
|
|
272
|
+
env: { PRODUCTBRAIN_API_KEY: apiKey }
|
|
273
|
+
});
|
|
274
|
+
const encoded = Buffer.from(config).toString("base64url");
|
|
275
|
+
return `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent("Product Brain")}&config=${encoded}`;
|
|
276
|
+
}
|
|
277
|
+
function printDeeplink(apiKey) {
|
|
278
|
+
const link = buildDeeplink(apiKey);
|
|
279
|
+
log("");
|
|
280
|
+
log(` ${dim("One-click install for Cursor (paste in browser):")}`);
|
|
281
|
+
log(` ${link}`);
|
|
282
|
+
}
|
|
283
|
+
function printClaudeSnippet() {
|
|
284
|
+
log("");
|
|
285
|
+
log(bold(" For Claude Code / CLAUDE.md:"));
|
|
286
|
+
log(dim(" Add this line to your ~/.claude/CLAUDE.md:"));
|
|
287
|
+
log("");
|
|
288
|
+
log(` When Product Brain MCP is available, say "Start PB" at the beginning`);
|
|
289
|
+
log(` of each session to orient to the workspace and unlock write tools.`);
|
|
290
|
+
log(` In Open mode, user-authored captures can commit immediately unless the user asks to keep drafts.`);
|
|
291
|
+
log(` In consensus/role modes, only commit when the user confirms.`);
|
|
292
|
+
log("");
|
|
293
|
+
}
|
|
294
|
+
export {
|
|
295
|
+
runSetup
|
|
296
|
+
};
|
|
297
|
+
//# sourceMappingURL=setup-RYYXRDPB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/setup.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * `npx @productbrain/mcp@beta setup`\n *\n * Guided onboarding: get API key from the app, paste it, write MCP config,\n * and optionally install Cursor rules/skills (additive-only).\n */\n\nimport { execSync } from \"node:child_process\";\nimport { createInterface } from \"node:readline\";\nimport { existsSync, writeFileSync, mkdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { resolveClient, writeClientConfig, MCP_NPX_PACKAGE, type McpClientInfo } from \"./config-writer.js\";\nimport { initAnalytics, trackSetupStarted, trackSetupCompleted, shutdownAnalytics } from \"../analytics.js\";\n\nconst APP_URL =\n process.env.PRODUCTBRAIN_APP_URL ?? \"https://work.productbrain.io\";\n\n// ── Helpers ─────────────────────────────────────────────────────────────\n\nfunction bold(s: string) {\n return `\\x1b[1m${s}\\x1b[0m`;\n}\nfunction green(s: string) {\n return `\\x1b[32m${s}\\x1b[0m`;\n}\nfunction dim(s: string) {\n return `\\x1b[2m${s}\\x1b[0m`;\n}\nfunction orange(s: string) {\n return `\\x1b[33m${s}\\x1b[0m`;\n}\n\nfunction log(msg: string) {\n process.stdout.write(`${msg}\\n`);\n}\n\nfunction openBrowser(url: string) {\n const platform = process.platform;\n try {\n if (platform === \"darwin\") execSync(`open \"${url}\"`);\n else if (platform === \"win32\") execSync(`start \"\" \"${url}\"`);\n else execSync(`xdg-open \"${url}\"`);\n } catch {\n log(dim(` Could not open browser automatically.`));\n log(` Open this URL manually: ${url}`);\n }\n}\n\nfunction prompt(question: string): Promise<string> {\n return new Promise((resolve) => {\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n rl.question(question, (answer) => {\n rl.close();\n resolve(answer.trim());\n });\n });\n}\n\nfunction promptChoice(question: string, choices: string[]): Promise<number> {\n return new Promise((resolve) => {\n log(\"\");\n log(bold(question));\n choices.forEach((c, i) => log(` ${i + 1}) ${c}`));\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n rl.question(`\\n ${dim(\"Choice [1]:\")} `, (line) => {\n rl.close();\n const n = parseInt(line.trim(), 10);\n if (isNaN(n) || n < 1 || n > choices.length) {\n resolve(0);\n } else {\n resolve(n - 1);\n }\n });\n });\n}\n\n// ── Workspace Verification ───────────────────────────────────────────────\n\nconst DEFAULT_CLOUD_URL = \"https://gateway.productbrain.io\";\n\nasync function verifyWorkspace(\n apiKey: string,\n): Promise<{ name: string; slug: string } | null> {\n const siteUrl = process.env.CONVEX_SITE_URL\n ?? process.env.PRODUCTBRAIN_URL\n ?? DEFAULT_CLOUD_URL;\n\n try {\n const res = await fetch(`${siteUrl.replace(/\\/$/, \"\")}/api/aki`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify({ fn: \"resolveWorkspace\", args: {} }),\n });\n\n if (!res.ok) return null;\n const json = (await res.json()) as {\n data?: { name: string; slug: string } | null;\n error?: string;\n };\n return json.data ?? null;\n } catch {\n return null;\n }\n}\n\n// ── Main ────────────────────────────────────────────────────────────────\n\nexport async function runSetup() {\n initAnalytics();\n trackSetupStarted();\n\n log(\"\");\n log(bold(` Product${orange(\"Brain\")} Setup`));\n log(dim(\" Connect your AI assistant to your chain\\n\"));\n\n const apiKeysUrl = `${APP_URL}/settings/api-keys`;\n\n log(` ${dim(\"1. Get your API key from Settings → API Keys\")}`);\n log(` ${dim(apiKeysUrl)}\\n`);\n\n const openNow = await prompt(` Open this URL in your browser? [Y/n]: `);\n if (openNow.toLowerCase() !== \"n\" && openNow.toLowerCase() !== \"no\") {\n openBrowser(apiKeysUrl);\n }\n\n log(\"\");\n log(` ${dim(\"2. Generate a key (if you don't have one), then copy it.\\n\")}`);\n\n const apiKey = await prompt(` Paste your API key (pb_sk_...): `);\n\n if (!apiKey || !apiKey.startsWith(\"pb_sk_\")) {\n log(` ${orange(\"!\")} Invalid key format. Keys start with pb_sk_.`);\n log(` Get one at ${apiKeysUrl}\\n`);\n await shutdownAnalytics();\n process.exit(1);\n }\n\n log(` ${green(\"✓\")} Key received`);\n\n const workspace = await verifyWorkspace(apiKey);\n if (workspace) {\n log(` ${green(\"✓\")} Connected to workspace: ${bold(workspace.name)} ${dim(`(${workspace.slug})`)}`);\n } else {\n log(` ${orange(\"!\")} Could not verify workspace. Check your key at ${apiKeysUrl}`);\n }\n log(\"\");\n\n const CLIENT_NAMES = [\"Cursor\", \"Claude Desktop\"] as const;\n const options = [...CLIENT_NAMES, \"Other\"];\n\n const choice = await promptChoice(\"Where do you want to set up Product Brain?\", options);\n\n if (choice === 2) {\n printConfigSnippet(apiKey);\n trackSetupCompleted(\"Other\", \"snippet_shown\");\n } else {\n const client = resolveClient(CLIENT_NAMES[choice]);\n if (client) {\n const outcome = await writeConfig(client, apiKey);\n trackSetupCompleted(CLIENT_NAMES[choice], outcome);\n } else {\n log(` ${orange(\"!\")} ${CLIENT_NAMES[choice]} config path not available on this platform.`);\n printConfigSnippet(apiKey);\n trackSetupCompleted(CLIENT_NAMES[choice], \"write_error\");\n }\n }\n\n // Cursor-specific: offer to install rule (additive-only)\n if (choice === 0) {\n await offerCursorRulesInstall();\n printDeeplink(apiKey);\n }\n\n // Claude-specific: print snippet (never write to CLAUDE.md)\n if (choice === 1) {\n printClaudeSnippet();\n }\n\n log(\"\");\n log(\n ` ${green(\"✓\")} Done! Restart your AI assistant and try: ${bold('\"Start PB\"')}`,\n );\n printHelpLink();\n await shutdownAnalytics();\n}\n\nasync function writeConfig(\n client: McpClientInfo,\n apiKey: string,\n): Promise<\"config_written\" | \"config_existed\" | \"write_error\"> {\n try {\n const wrote = await writeClientConfig(client, apiKey);\n if (wrote) {\n log(` ${green(\"✓\")} Wrote config to ${dim(client.configPath)}`);\n return \"config_written\";\n } else {\n log(` ${dim(\"ℹ\")} ${client.name} already configured — skipped`);\n return \"config_existed\";\n }\n } catch (err: any) {\n log(` ${orange(\"!\")} Could not write ${client.name} config: ${err.message}`);\n printConfigSnippet(apiKey);\n return \"write_error\";\n }\n}\n\nfunction printHelpLink() {\n log(` ${dim(`Need help? See ${APP_URL}/settings/api-keys`)}`);\n log(\"\");\n}\n\nfunction printConfigSnippet(apiKey: string) {\n log(\"\");\n log(bold(\" Add this to your MCP client config:\\n\"));\n const snippet = JSON.stringify(\n {\n mcpServers: {\n \"Product Brain\": {\n command: \"npx\",\n args: [\"-y\", MCP_NPX_PACKAGE],\n env: { PRODUCTBRAIN_API_KEY: apiKey },\n },\n },\n },\n null,\n 2,\n );\n for (const line of snippet.split(\"\\n\")) {\n log(` ${line}`);\n }\n log(\"\");\n}\n\n// ── Cursor Rules/Skills Install (additive-only) ─────────────────────────\n\nconst CURSOR_RULE_FILENAME = \"product-brain.mdc\";\n\nconst CURSOR_RULE_CONTENT = `---\ndescription: Product Brain MCP — single source of truth for product knowledge\nglobs:\nalwaysApply: true\n---\n\n# Product Brain MCP\n\nProduct Brain is your product knowledge base. The Chain is the single source of truth.\n\nEvery entry is either a **draft** (captured but not committed) or **committed** (on the Chain, SSOT).\nCommitting to the Chain is the compounding act.\n\n## Quick Start\n\nSay **\"Start PB\"** or **\"Start Product Brain\"** to begin. This single call:\n- Orients you to the workspace (readiness, gaps, planned work)\n- Unlocks write tools for the session\n- Surfaces your next recommended action\n\n## Tool Workflow\n\n1. **Start here**: \\`start\\` — workspace context + next action\n2. **Search**: \\`entries action=search\\` — find entries across all collections\n3. **Drill in**: \\`entries action=get\\` — full record with data, labels, relations\n4. **Context**: \\`context action=gather\\` — related knowledge around an entry or task\n5. **Capture**: \\`capture\\` — create knowledge with auto-linking + quality score\n6. **Commit**: \\`commit-entry\\` — promote drafts to SSOT when confirmation is still required\n7. **Connect**: \\`graph action=suggest\\` then \\`relations action=create\\` to build the graph\n\n## Bulk Knowledge Input\n\nWhen given a document or batch of knowledge to capture:\n1. Scan the input — identify all collections needed\n2. Call \\`collections action=list\\` — compare against what exists\n3. Propose missing collections to the user for confirmation\n4. Call \\`collections action=create\\` for each confirmed collection\n5. Then capture entries into the correct collections\n\nNever stuff entries into the wrong collection. Never silently skip knowledge.\n\n## Rules\n\n- In Open mode, user-authored captures can commit immediately unless the user asks to keep them as drafts.\n- In consensus/role modes, only call \\`commit-entry\\` when the user confirms.\n- Use \\`graph action=suggest\\` after capturing to discover and create relations.\n- Collections are dynamic — use \\`collections action=create\\` when the workspace needs new ones.\n- When lost, fetch \\`productbrain://orientation\\` for the full system map.\n`;\n\nfunction isCursorProject(): boolean {\n return existsSync(join(process.cwd(), \".cursor\")) || existsSync(join(process.cwd(), \".cursorignore\"));\n}\n\nasync function offerCursorRulesInstall(): Promise<void> {\n if (!isCursorProject()) return;\n\n const answer = await prompt(`\\n Install Product Brain rule for Cursor? [Y/n]: `);\n if (answer.toLowerCase() === \"n\" || answer.toLowerCase() === \"no\") {\n log(dim(\" Skipped rule install.\"));\n return;\n }\n\n const rulesDir = join(process.cwd(), \".cursor\", \"rules\");\n const rulePath = join(rulesDir, CURSOR_RULE_FILENAME);\n\n if (existsSync(rulePath)) {\n log(` ${dim(\"ℹ\")} Rule already exists at ${dim(rulePath)} — skipped`);\n return;\n }\n\n if (!existsSync(rulesDir)) {\n mkdirSync(rulesDir, { recursive: true });\n }\n\n writeFileSync(rulePath, CURSOR_RULE_CONTENT, \"utf-8\");\n log(` ${green(\"✓\")} Installed rule at ${dim(rulePath)}`);\n}\n\nfunction buildDeeplink(apiKey: string): string {\n const config = JSON.stringify({\n command: \"npx\",\n args: [\"-y\", MCP_NPX_PACKAGE],\n env: { PRODUCTBRAIN_API_KEY: apiKey },\n });\n const encoded = Buffer.from(config).toString(\"base64url\");\n return `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(\"Product Brain\")}&config=${encoded}`;\n}\n\nfunction printDeeplink(apiKey: string): void {\n const link = buildDeeplink(apiKey);\n log(\"\");\n log(` ${dim(\"One-click install for Cursor (paste in browser):\")}`);\n log(` ${link}`);\n}\n\nfunction printClaudeSnippet(): void {\n log(\"\");\n log(bold(\" For Claude Code / CLAUDE.md:\"));\n log(dim(\" Add this line to your ~/.claude/CLAUDE.md:\"));\n log(\"\");\n log(` When Product Brain MCP is available, say \"Start PB\" at the beginning`);\n log(` of each session to orient to the workspace and unlock write tools.`);\n log(` In Open mode, user-authored captures can commit immediately unless the user asks to keep drafts.`);\n log(` In consensus/role modes, only commit when the user confirms.`);\n log(\"\");\n}\n"],"mappings":";;;;;;;;;;;;AASA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,YAAY,eAAe,iBAAiB;AACrD,SAAS,YAAY;AAIrB,IAAM,UACJ,QAAQ,IAAI,wBAAwB;AAItC,SAAS,KAAK,GAAW;AACvB,SAAO,UAAU,CAAC;AACpB;AACA,SAAS,MAAM,GAAW;AACxB,SAAO,WAAW,CAAC;AACrB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