@productbrain/mcp 0.0.1-beta.149 → 0.0.1-beta.14913
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 +5 -1
- package/README.md +67 -0
- package/dist/chunk-IFJHH4SQ.js +1916 -0
- package/dist/chunk-IFJHH4SQ.js.map +1 -0
- package/dist/chunk-Z72YK5TB.js +12410 -0
- package/dist/chunk-Z72YK5TB.js.map +1 -0
- package/dist/cli/index.js +1 -1
- package/dist/http.js +520 -328
- package/dist/http.js.map +1 -1
- package/dist/index.js +12 -33
- package/dist/index.js.map +1 -1
- package/dist/setup-HRXTTJ4U.js +204 -0
- package/dist/setup-HRXTTJ4U.js.map +1 -0
- package/dist/views/src/entry-cards/index.html +108 -90
- package/dist/views/src/graph-constellation/index.html +111 -93
- package/package.json +12 -9
- package/dist/chunk-H7XBZ4H3.js +0 -15229
- package/dist/chunk-H7XBZ4H3.js.map +0 -1
- package/dist/chunk-MOPOQUJP.js +0 -312
- package/dist/chunk-MOPOQUJP.js.map +0 -1
- package/dist/setup-YYADLH22.js +0 -297
- package/dist/setup-YYADLH22.js.map +0 -1
package/dist/chunk-MOPOQUJP.js
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
// src/analytics.ts
|
|
2
|
-
import { userInfo } from "os";
|
|
3
|
-
import { PostHog } from "posthog-node";
|
|
4
|
-
var client = null;
|
|
5
|
-
var distinctId = "anonymous";
|
|
6
|
-
var POSTHOG_HOST = "https://eu.i.posthog.com";
|
|
7
|
-
function log(msg) {
|
|
8
|
-
if (process.env.MCP_DEBUG === "1") {
|
|
9
|
-
process.stderr.write(msg);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function getBuildTimeKey() {
|
|
13
|
-
try {
|
|
14
|
-
return "";
|
|
15
|
-
} catch {
|
|
16
|
-
return "";
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function initAnalytics() {
|
|
20
|
-
const apiKey = process.env.POSTHOG_MCP_KEY || getBuildTimeKey();
|
|
21
|
-
if (!apiKey) {
|
|
22
|
-
log("[MCP-ANALYTICS] No PostHog key \u2014 tracking disabled (set SYNERGYOS_POSTHOG_KEY at build time for publish)\n");
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
client = new PostHog(apiKey, {
|
|
26
|
-
host: POSTHOG_HOST,
|
|
27
|
-
flushAt: 1,
|
|
28
|
-
flushInterval: 5e3,
|
|
29
|
-
featureFlagsPollingInterval: 3e4
|
|
30
|
-
});
|
|
31
|
-
distinctId = process.env.MCP_USER_ID || fallbackDistinctId();
|
|
32
|
-
log(`[MCP-ANALYTICS] Initialized \u2014 host=${POSTHOG_HOST} distinctId=${distinctId}
|
|
33
|
-
`);
|
|
34
|
-
}
|
|
35
|
-
function fallbackDistinctId() {
|
|
36
|
-
try {
|
|
37
|
-
return userInfo().username;
|
|
38
|
-
} catch {
|
|
39
|
-
return `os-${process.pid}`;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function trackSessionStarted(workspaceId, serverVersion) {
|
|
43
|
-
if (!client) return;
|
|
44
|
-
client.capture({
|
|
45
|
-
distinctId,
|
|
46
|
-
event: "mcp_session_started",
|
|
47
|
-
properties: {
|
|
48
|
-
workspace_id: workspaceId,
|
|
49
|
-
server_version: serverVersion,
|
|
50
|
-
source: "mcp-server",
|
|
51
|
-
$groups: { workspace: workspaceId }
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function trackToolCall(fn, status, durationMs, workspaceId, errorMsg) {
|
|
56
|
-
const properties = {
|
|
57
|
-
tool: fn,
|
|
58
|
-
status,
|
|
59
|
-
duration_ms: durationMs,
|
|
60
|
-
workspace_id: workspaceId,
|
|
61
|
-
source: "mcp-server",
|
|
62
|
-
$groups: { workspace: workspaceId }
|
|
63
|
-
};
|
|
64
|
-
if (errorMsg) properties.error = errorMsg;
|
|
65
|
-
if (!client) return;
|
|
66
|
-
client.capture({
|
|
67
|
-
distinctId,
|
|
68
|
-
event: "mcp_tool_called",
|
|
69
|
-
properties
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function trackSetupStarted() {
|
|
73
|
-
if (!client) return;
|
|
74
|
-
client.capture({
|
|
75
|
-
distinctId,
|
|
76
|
-
event: "mcp_setup_started",
|
|
77
|
-
properties: {
|
|
78
|
-
source: "mcp-server",
|
|
79
|
-
platform: process.platform
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function trackSetupCompleted(chosenClient, outcome) {
|
|
84
|
-
if (!client) return;
|
|
85
|
-
client.capture({
|
|
86
|
-
distinctId,
|
|
87
|
-
event: "mcp_setup_completed",
|
|
88
|
-
properties: {
|
|
89
|
-
client: chosenClient,
|
|
90
|
-
outcome,
|
|
91
|
-
source: "mcp-server",
|
|
92
|
-
platform: process.platform
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
function trackQualityVerdict(workspaceId, props) {
|
|
97
|
-
if (!client) return;
|
|
98
|
-
client.capture({
|
|
99
|
-
distinctId,
|
|
100
|
-
event: "quality_verdict_generated",
|
|
101
|
-
properties: {
|
|
102
|
-
...props,
|
|
103
|
-
workspace_id: workspaceId,
|
|
104
|
-
source_system: "mcp-server",
|
|
105
|
-
$groups: { workspace: workspaceId }
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function trackQualityCheck(workspaceId, props) {
|
|
110
|
-
if (!client) return;
|
|
111
|
-
client.capture({
|
|
112
|
-
distinctId,
|
|
113
|
-
event: "quality_verdict_checked",
|
|
114
|
-
properties: {
|
|
115
|
-
...props,
|
|
116
|
-
workspace_id: workspaceId,
|
|
117
|
-
source_system: "mcp-server",
|
|
118
|
-
$groups: { workspace: workspaceId }
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function trackCaptureClassifierEvent(event, workspaceId, props) {
|
|
123
|
-
if (!client) return;
|
|
124
|
-
try {
|
|
125
|
-
client.capture({
|
|
126
|
-
distinctId,
|
|
127
|
-
event,
|
|
128
|
-
properties: {
|
|
129
|
-
...props,
|
|
130
|
-
workspace_id: workspaceId,
|
|
131
|
-
source_system: "mcp-server",
|
|
132
|
-
$groups: { workspace: workspaceId }
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
} catch {
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function trackCaptureClassifierEvaluated(workspaceId, props) {
|
|
139
|
-
trackCaptureClassifierEvent("mcp_capture_classifier_evaluated", workspaceId, props);
|
|
140
|
-
}
|
|
141
|
-
function trackCaptureClassifierAutoRouted(workspaceId, props) {
|
|
142
|
-
trackCaptureClassifierEvent("mcp_capture_classifier_auto_routed", workspaceId, props);
|
|
143
|
-
}
|
|
144
|
-
function trackCaptureClassifierFallback(workspaceId, props) {
|
|
145
|
-
trackCaptureClassifierEvent("mcp_capture_classifier_fallback", workspaceId, props);
|
|
146
|
-
}
|
|
147
|
-
function trackChainEntryCommitted(workspaceId, props) {
|
|
148
|
-
if (!client) return;
|
|
149
|
-
try {
|
|
150
|
-
client.capture({
|
|
151
|
-
distinctId,
|
|
152
|
-
event: "chain_entry_committed",
|
|
153
|
-
properties: {
|
|
154
|
-
workspace_id: workspaceId,
|
|
155
|
-
source_system: "mcp-server",
|
|
156
|
-
$groups: { workspace: workspaceId },
|
|
157
|
-
...props
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
} catch {
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
function trackKnowledgeGap(workspaceId, props) {
|
|
164
|
-
if (!client) return;
|
|
165
|
-
try {
|
|
166
|
-
client.capture({
|
|
167
|
-
distinctId,
|
|
168
|
-
event: "knowledge_gap_detected",
|
|
169
|
-
properties: {
|
|
170
|
-
...props,
|
|
171
|
-
query: props.query.slice(0, 200),
|
|
172
|
-
workspace_id: workspaceId,
|
|
173
|
-
source_system: "mcp-server",
|
|
174
|
-
$groups: { workspace: workspaceId }
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
} catch {
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function trackCaptureQualityHints(workspaceId, props) {
|
|
181
|
-
if (!client) return;
|
|
182
|
-
try {
|
|
183
|
-
client.capture({
|
|
184
|
-
distinctId,
|
|
185
|
-
event: "mcp_capture_quality_hints",
|
|
186
|
-
properties: {
|
|
187
|
-
...props,
|
|
188
|
-
workspace_id: workspaceId,
|
|
189
|
-
source_system: "mcp-server",
|
|
190
|
-
$groups: { workspace: workspaceId }
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
} catch {
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function trackCaptureRelationSuggestions(workspaceId, props) {
|
|
197
|
-
if (!client) return;
|
|
198
|
-
try {
|
|
199
|
-
client.capture({
|
|
200
|
-
distinctId,
|
|
201
|
-
event: "mcp_capture_relation_suggestions",
|
|
202
|
-
properties: {
|
|
203
|
-
...props,
|
|
204
|
-
workspace_id: workspaceId,
|
|
205
|
-
source_system: "mcp-server",
|
|
206
|
-
$groups: { workspace: workspaceId }
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
} catch {
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
function getPostHogClient() {
|
|
213
|
-
return client;
|
|
214
|
-
}
|
|
215
|
-
async function shutdownAnalytics() {
|
|
216
|
-
await client?.shutdown();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/cli/config-writer.ts
|
|
220
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
221
|
-
import { join, dirname } from "path";
|
|
222
|
-
import { homedir, platform } from "os";
|
|
223
|
-
var SERVER_ENTRY_KEY = "Product Brain";
|
|
224
|
-
var LEGACY_ENTRY_KEY = "productbrain";
|
|
225
|
-
var MCP_NPX_PACKAGE = "@productbrain/mcp@beta";
|
|
226
|
-
function buildServerEntry(apiKey) {
|
|
227
|
-
return {
|
|
228
|
-
command: "npx",
|
|
229
|
-
args: ["-y", MCP_NPX_PACKAGE],
|
|
230
|
-
env: { PRODUCTBRAIN_API_KEY: apiKey }
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
function getCursorConfigPath() {
|
|
234
|
-
return join(process.cwd(), ".cursor", "mcp.json");
|
|
235
|
-
}
|
|
236
|
-
function getClaudeDesktopConfigPath() {
|
|
237
|
-
const os = platform();
|
|
238
|
-
if (os === "darwin") {
|
|
239
|
-
return join(
|
|
240
|
-
homedir(),
|
|
241
|
-
"Library",
|
|
242
|
-
"Application Support",
|
|
243
|
-
"Claude",
|
|
244
|
-
"claude_desktop_config.json"
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
if (os === "win32") {
|
|
248
|
-
const appData = process.env.APPDATA ?? join(homedir(), "AppData", "Roaming");
|
|
249
|
-
return join(appData, "Claude", "claude_desktop_config.json");
|
|
250
|
-
}
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
function resolveClient(name) {
|
|
254
|
-
if (name === "Cursor") {
|
|
255
|
-
return { name, configPath: getCursorConfigPath() };
|
|
256
|
-
}
|
|
257
|
-
const configPath = getClaudeDesktopConfigPath();
|
|
258
|
-
return configPath ? { name, configPath } : null;
|
|
259
|
-
}
|
|
260
|
-
function readJsonSafe(path) {
|
|
261
|
-
if (!existsSync(path)) return {};
|
|
262
|
-
try {
|
|
263
|
-
return JSON.parse(readFileSync(path, "utf-8"));
|
|
264
|
-
} catch {
|
|
265
|
-
return {};
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
async function writeClientConfig(client2, apiKey) {
|
|
269
|
-
const config = readJsonSafe(client2.configPath);
|
|
270
|
-
const serversKey = "mcpServers";
|
|
271
|
-
if (!config[serversKey]) config[serversKey] = {};
|
|
272
|
-
if (config[serversKey][LEGACY_ENTRY_KEY]) {
|
|
273
|
-
const legacy = config[serversKey][LEGACY_ENTRY_KEY];
|
|
274
|
-
config[serversKey][SERVER_ENTRY_KEY] = {
|
|
275
|
-
...buildServerEntry(apiKey),
|
|
276
|
-
env: { ...legacy.env, PRODUCTBRAIN_API_KEY: legacy.env?.PRODUCTBRAIN_API_KEY ?? apiKey }
|
|
277
|
-
};
|
|
278
|
-
delete config[serversKey][LEGACY_ENTRY_KEY];
|
|
279
|
-
} else {
|
|
280
|
-
const existing = config[serversKey][SERVER_ENTRY_KEY];
|
|
281
|
-
config[serversKey][SERVER_ENTRY_KEY] = existing ? { ...existing, env: { ...existing.env, PRODUCTBRAIN_API_KEY: apiKey } } : buildServerEntry(apiKey);
|
|
282
|
-
}
|
|
283
|
-
const dir = dirname(client2.configPath);
|
|
284
|
-
if (!existsSync(dir)) {
|
|
285
|
-
mkdirSync(dir, { recursive: true });
|
|
286
|
-
}
|
|
287
|
-
writeFileSync(client2.configPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
288
|
-
return true;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export {
|
|
292
|
-
initAnalytics,
|
|
293
|
-
trackSessionStarted,
|
|
294
|
-
trackToolCall,
|
|
295
|
-
trackSetupStarted,
|
|
296
|
-
trackSetupCompleted,
|
|
297
|
-
trackQualityVerdict,
|
|
298
|
-
trackQualityCheck,
|
|
299
|
-
trackCaptureClassifierEvaluated,
|
|
300
|
-
trackCaptureClassifierAutoRouted,
|
|
301
|
-
trackCaptureClassifierFallback,
|
|
302
|
-
trackChainEntryCommitted,
|
|
303
|
-
trackKnowledgeGap,
|
|
304
|
-
trackCaptureQualityHints,
|
|
305
|
-
trackCaptureRelationSuggestions,
|
|
306
|
-
getPostHogClient,
|
|
307
|
-
shutdownAnalytics,
|
|
308
|
-
MCP_NPX_PACKAGE,
|
|
309
|
-
resolveClient,
|
|
310
|
-
writeClientConfig
|
|
311
|
-
};
|
|
312
|
-
//# sourceMappingURL=chunk-MOPOQUJP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/analytics.ts","../src/cli/config-writer.ts"],"sourcesContent":["/**\n * PostHog analytics for SynergyOS maintainers — tracks MCP usage (sessions, tool calls).\n * Not user-facing. Key is injected at build time via SYNERGYOS_POSTHOG_KEY.\n * Override with POSTHOG_MCP_KEY for self-hosted deployments.\n */\n\nimport { userInfo } from \"node:os\";\nimport { PostHog } from \"posthog-node\";\n\nlet client: PostHog | null = null;\nlet distinctId = \"anonymous\";\n\nconst POSTHOG_HOST = \"https://eu.i.posthog.com\";\n\n/** Injected at build time: SYNERGYOS_POSTHOG_KEY env when running `npm run build`/publish. */\ndeclare const __SYNERGYOS_POSTHOG_KEY__: string;\n\n/** Only write to stderr when MCP_DEBUG=1 for quieter default DX. */\nfunction log(msg: string): void {\n if (process.env.MCP_DEBUG === \"1\") {\n process.stderr.write(msg);\n }\n}\n\nfunction getBuildTimeKey(): string {\n try {\n return __SYNERGYOS_POSTHOG_KEY__;\n } catch {\n // Not replaced by bundler (e.g. running via tsx in tests) — treat as absent.\n return \"\";\n }\n}\n\nexport function initAnalytics(): void {\n const apiKey = process.env.POSTHOG_MCP_KEY || getBuildTimeKey();\n if (!apiKey) {\n log(\"[MCP-ANALYTICS] No PostHog key — tracking disabled (set SYNERGYOS_POSTHOG_KEY at build time for publish)\\n\");\n return;\n }\n\n client = new PostHog(apiKey, {\n host: POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 5000,\n featureFlagsPollingInterval: 30_000,\n });\n distinctId = process.env.MCP_USER_ID || fallbackDistinctId();\n\n log(`[MCP-ANALYTICS] Initialized — host=${POSTHOG_HOST} distinctId=${distinctId}\\n`);\n}\n\nfunction fallbackDistinctId(): string {\n try {\n return userInfo().username;\n } catch {\n return `os-${process.pid}`;\n }\n}\n\nexport function trackSessionStarted(\n workspaceId: string,\n serverVersion: string,\n): void {\n if (!client) return;\n client.capture({\n distinctId,\n event: \"mcp_session_started\",\n properties: {\n workspace_id: workspaceId,\n server_version: serverVersion,\n source: \"mcp-server\",\n $groups: { workspace: workspaceId },\n },\n });\n}\n\nexport function trackToolCall(\n fn: string,\n status: \"ok\" | \"error\",\n durationMs: number,\n workspaceId: string,\n errorMsg?: string,\n): void {\n const properties: Record<string, unknown> = {\n tool: fn,\n status,\n duration_ms: durationMs,\n workspace_id: workspaceId,\n source: \"mcp-server\",\n $groups: { workspace: workspaceId },\n };\n if (errorMsg) properties.error = errorMsg;\n\n if (!client) return;\n client.capture({\n distinctId,\n event: \"mcp_tool_called\",\n properties,\n });\n}\n\nexport function trackSetupStarted(): void {\n if (!client) return;\n client.capture({\n distinctId,\n event: \"mcp_setup_started\",\n properties: {\n source: \"mcp-server\",\n platform: process.platform,\n },\n });\n}\n\nexport function trackSetupCompleted(\n chosenClient: string,\n outcome: \"config_written\" | \"config_existed\" | \"snippet_shown\" | \"write_error\",\n): void {\n if (!client) return;\n client.capture({\n distinctId,\n event: \"mcp_setup_completed\",\n properties: {\n client: chosenClient,\n outcome,\n source: \"mcp-server\",\n platform: process.platform,\n },\n });\n}\n\nexport function trackQualityVerdict(\n workspaceId: string,\n props: {\n entry_id: string;\n entry_type: string;\n tier: string;\n context: string;\n passed: boolean;\n source: string;\n criteria_total: number;\n criteria_failed: number;\n llm_scheduled: boolean;\n },\n): void {\n if (!client) return;\n client.capture({\n distinctId,\n event: \"quality_verdict_generated\",\n properties: {\n ...props,\n workspace_id: workspaceId,\n source_system: \"mcp-server\",\n $groups: { workspace: workspaceId },\n },\n });\n}\n\nexport function trackQualityCheck(\n workspaceId: string,\n props: {\n entry_id: string;\n entry_type: string;\n tier: string;\n passed: boolean;\n source: string;\n llm_status?: string;\n llm_duration_ms?: number;\n llm_error?: string;\n has_roger_martin: boolean;\n },\n): void {\n if (!client) return;\n client.capture({\n distinctId,\n event: \"quality_verdict_checked\",\n properties: {\n ...props,\n workspace_id: workspaceId,\n source_system: \"mcp-server\",\n $groups: { workspace: workspaceId },\n },\n });\n}\n\nexport type ClassifierReasonCategory =\n | \"auto-routed\"\n | \"low-confidence\"\n | \"ambiguous\"\n | \"non-provisioned\";\n\ntype CaptureClassifierTelemetryProps = {\n predicted_collection: string;\n confidence: number;\n auto_routed: boolean;\n reason_category: ClassifierReasonCategory;\n explicit_collection_provided: boolean;\n};\n\nfunction trackCaptureClassifierEvent(\n event: \"mcp_capture_classifier_evaluated\" | \"mcp_capture_classifier_auto_routed\" | \"mcp_capture_classifier_fallback\",\n workspaceId: string,\n props: CaptureClassifierTelemetryProps,\n): void {\n if (!client) return;\n try {\n client.capture({\n distinctId,\n event,\n properties: {\n ...props,\n workspace_id: workspaceId,\n source_system: \"mcp-server\",\n $groups: { workspace: workspaceId },\n },\n });\n } catch {\n // Analytics are advisory and must never break capture flow.\n }\n}\n\nexport function trackCaptureClassifierEvaluated(\n workspaceId: string,\n props: CaptureClassifierTelemetryProps,\n): void {\n trackCaptureClassifierEvent(\"mcp_capture_classifier_evaluated\", workspaceId, props);\n}\n\nexport function trackCaptureClassifierAutoRouted(\n workspaceId: string,\n props: CaptureClassifierTelemetryProps,\n): void {\n trackCaptureClassifierEvent(\"mcp_capture_classifier_auto_routed\", workspaceId, props);\n}\n\nexport function trackCaptureClassifierFallback(\n workspaceId: string,\n props: CaptureClassifierTelemetryProps,\n): void {\n trackCaptureClassifierEvent(\"mcp_capture_classifier_fallback\", workspaceId, props);\n}\n\n/** GLO-26 / TEN-156: every SSOT commit for PostHog funnels (split auto vs manual). */\nexport function trackChainEntryCommitted(\n workspaceId: string,\n props: {\n entry_id: string;\n collection?: string;\n commit_method: \"auto\" | \"manual\";\n surface:\n | \"mcp_commit_tool\"\n | \"mcp_capture\"\n | \"mcp_wrapup\";\n },\n): void {\n if (!client) return;\n try {\n client.capture({\n distinctId,\n event: \"chain_entry_committed\",\n properties: {\n workspace_id: workspaceId,\n source_system: \"mcp-server\",\n $groups: { workspace: workspaceId },\n ...props,\n },\n });\n } catch {\n // Analytics must never break the tool path.\n }\n}\n\nexport function trackKnowledgeGap(\n workspaceId: string,\n props: {\n query: string;\n tool: string;\n action: string;\n gap_type: \"search_zero\" | \"context_task_empty\" | \"context_entry_isolated\" | \"context_graph_empty\";\n collection_scope?: string;\n },\n): void {\n if (!client) return;\n try {\n client.capture({\n distinctId,\n event: \"knowledge_gap_detected\",\n properties: {\n ...props,\n query: props.query.slice(0, 200),\n workspace_id: workspaceId,\n source_system: \"mcp-server\",\n $groups: { workspace: workspaceId },\n },\n });\n } catch {\n // Analytics must never break the tool response path.\n }\n}\n\n// ── BET-272 S6 / STD-155: Capture intelligence observability ────────────────\n\n/** Fires when formative quality hints are returned at capture time. */\nexport function trackCaptureQualityHints(\n workspaceId: string,\n props: {\n collection: string;\n hint_count: number;\n hint_fields: string[];\n },\n): void {\n if (!client) return;\n try {\n client.capture({\n distinctId,\n event: \"mcp_capture_quality_hints\",\n properties: {\n ...props,\n workspace_id: workspaceId,\n source_system: \"mcp-server\",\n $groups: { workspace: workspaceId },\n },\n });\n } catch {\n // Analytics must never break capture flow.\n }\n}\n\n/** Fires when relation suggestions are returned at capture time. */\nexport function trackCaptureRelationSuggestions(\n workspaceId: string,\n props: {\n collection: string;\n suggestion_count: number;\n relation_types: string[];\n avg_confidence: number;\n },\n): void {\n if (!client) return;\n try {\n client.capture({\n distinctId,\n event: \"mcp_capture_relation_suggestions\",\n properties: {\n ...props,\n workspace_id: workspaceId,\n source_system: \"mcp-server\",\n $groups: { workspace: workspaceId },\n },\n });\n } catch {\n // Analytics must never break capture flow.\n }\n}\n\nexport function getPostHogClient(): PostHog | null {\n return client;\n}\n\nexport async function shutdownAnalytics(): Promise<void> {\n await client?.shutdown();\n}\n","/**\n * Multi-client MCP config detection and writer.\n *\n * Supports:\n * - Cursor: .cursor/mcp.json in cwd (project-level)\n * - Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)\n * %APPDATA%/Claude/claude_desktop_config.json (Windows)\n *\n * The writer reads existing config, merges the new server entry (never\n * overwrites existing entries), and writes back. Falls back to printing\n * a snippet for unsupported OS or unknown formats.\n */\n\nimport { existsSync, readFileSync, writeFileSync, mkdirSync } from \"node:fs\";\nimport { join, dirname } from \"node:path\";\nimport { homedir, platform } from \"node:os\";\n\nexport interface McpClientInfo {\n name: string;\n configPath: string;\n}\n\nconst SERVER_ENTRY_KEY = \"Product Brain\";\nconst LEGACY_ENTRY_KEY = \"productbrain\";\n\n/**\n * Canonical npx package specifier. Update here when exiting beta.\n * Frontend mirror: src/lib/constants/mcp.ts\n * Business rule: BR-84 (Chain)\n */\nexport const MCP_NPX_PACKAGE = \"@productbrain/mcp@beta\";\n\nfunction buildServerEntry(apiKey: string) {\n return {\n command: \"npx\",\n args: [\"-y\", MCP_NPX_PACKAGE],\n env: { PRODUCTBRAIN_API_KEY: apiKey },\n };\n}\n\n// ── Detection ───────────────────────────────────────────────────────────\n\nfunction getCursorConfigPath(): string {\n return join(process.cwd(), \".cursor\", \"mcp.json\");\n}\n\nfunction getClaudeDesktopConfigPath(): string | null {\n const os = platform();\n if (os === \"darwin\") {\n return join(\n homedir(),\n \"Library\",\n \"Application Support\",\n \"Claude\",\n \"claude_desktop_config.json\",\n );\n }\n if (os === \"win32\") {\n const appData = process.env.APPDATA ?? join(homedir(), \"AppData\", \"Roaming\");\n return join(appData, \"Claude\", \"claude_desktop_config.json\");\n }\n // Linux: no official Claude Desktop location yet\n return null;\n}\n\nexport function resolveClient(name: \"Cursor\" | \"Claude Desktop\"): McpClientInfo | null {\n if (name === \"Cursor\") {\n return { name, configPath: getCursorConfigPath() };\n }\n const configPath = getClaudeDesktopConfigPath();\n return configPath ? { name, configPath } : null;\n}\n\n// ── Writing ─────────────────────────────────────────────────────────────\n\nfunction readJsonSafe(path: string): Record<string, any> {\n if (!existsSync(path)) return {};\n try {\n return JSON.parse(readFileSync(path, \"utf-8\"));\n } catch {\n return {};\n }\n}\n\n/**\n * Write or merge the Product Brain server entry into a client config file.\n * Migrates legacy \"productbrain\" key to \"Product Brain\" when present.\n * Returns true if the config was written, false if already present.\n */\nexport async function writeClientConfig(\n client: McpClientInfo,\n apiKey: string,\n): Promise<boolean> {\n const config = readJsonSafe(client.configPath);\n\n const serversKey = \"mcpServers\";\n if (!config[serversKey]) config[serversKey] = {};\n\n // Migrate legacy \"productbrain\" key or update existing Product Brain with new API key\n if (config[serversKey][LEGACY_ENTRY_KEY]) {\n const legacy = config[serversKey][LEGACY_ENTRY_KEY];\n config[serversKey][SERVER_ENTRY_KEY] = {\n ...buildServerEntry(apiKey),\n env: { ...legacy.env, PRODUCTBRAIN_API_KEY: legacy.env?.PRODUCTBRAIN_API_KEY ?? apiKey },\n };\n delete config[serversKey][LEGACY_ENTRY_KEY];\n } else {\n const existing = config[serversKey][SERVER_ENTRY_KEY];\n config[serversKey][SERVER_ENTRY_KEY] = existing\n ? { ...existing, env: { ...existing.env, PRODUCTBRAIN_API_KEY: apiKey } }\n : buildServerEntry(apiKey);\n }\n\n const dir = dirname(client.configPath);\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n\n writeFileSync(client.configPath, JSON.stringify(config, null, 2) + \"\\n\", \"utf-8\");\n return true;\n}\n"],"mappings":";AAMA,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAExB,IAAI,SAAyB;AAC7B,IAAI,aAAa;AAEjB,IAAM,eAAe;AAMrB,SAAS,IAAI,KAAmB;AAC9B,MAAI,QAAQ,IAAI,cAAc,KAAK;AACjC,YAAQ,OAAO,MAAM,GAAG;AAAA,EAC1B;AACF;AAEA,SAAS,kBAA0B;AACjC,MAAI;AACF,WAAO;AAAA,EACT,QAAQ;AAEN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,gBAAsB;AACpC,QAAM,SAAS,QAAQ,IAAI,mBAAmB,gBAAgB;AAC9D,MAAI,CAAC,QAAQ;AACX,QAAI,iHAA4G;AAChH;AAAA,EACF;AAEA,WAAS,IAAI,QAAQ,QAAQ;AAAA,IAC3B,MAAM;AAAA,IACN,SAAS;AAAA,IACT,eAAe;AAAA,IACf,6BAA6B;AAAA,EAC/B,CAAC;AACD,eAAa,QAAQ,IAA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,UAAU,EAAE,gBAAgB,IAAI,WACnC,EAAE,GAAG,UAAU,KAAK,EAAE,GAAG,SAAS,KAAK,sBAAsB,OAAO,EAAE,IACtE,iBAAiB,MAAM;AAAA,EAC7B;AAEA,QAAM,MAAM,QAAQA,QAAO,UAAU;AACrC,MAAI,CAAC,WAAW,GAAG,GAAG;AACpB,cAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,EACpC;AAEA,gBAAcA,QAAO,YAAY,KAAK,UAAU,QAAQ,MAAM,CAAC,IAAI,MAAM,OAAO;AAChF,SAAO;AACT;","names":["client"]}
|
package/dist/setup-YYADLH22.js
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
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-MOPOQUJP.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://trustworthy-kangaroo-277.convex.site";
|
|
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/mcp`, {
|
|
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-YYADLH22.js.map
|