@polymorphism-tech/morph-spec 10.10.0 → 10.11.0
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/README.md +2 -2
- package/claude-plugin.json +1 -1
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/docs/CLI.md +2 -2
- package/framework/hooks/shared/build-check.js +35 -2
- package/framework/mcp/registry.json +30 -42
- package/framework/rules/nextjs-standards.md +2 -2
- package/framework/rules/ui-design.md +1 -1
- package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
- package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
- package/framework/skills/core/morph-apply/SKILL.md +2 -1
- package/framework/skills/core/morph-plan/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +5 -3
- package/framework/standards/STANDARDS.json +3 -2
- package/framework/standards/frontend/nextjs/components.md +36 -1
- package/framework/standards/frontend/nextjs/lint.md +23 -1
- package/framework/standards/frontend/nextjs/nextjs-patterns.md +1 -1
- package/framework/templates/docs/ui-mockups.md +5 -1
- package/package.json +1 -1
- package/src/commands/mcp/mcp-setup.js +8 -103
- package/src/commands/project/init.js +1 -21
- package/src/commands/project/update.js +20 -0
- package/src/lib/installers/effects.js +6 -0
- package/src/lib/installers/mcp-installer.js +4 -295
- package/src/lib/installers/stack-tooling.js +53 -0
- package/src/lib/risk-detector.js +8 -0
- package/src/lib/specs/screen-checklist.js +57 -8
- package/src/lib/stack/stack-scan.js +13 -1
|
@@ -12,9 +12,7 @@ import {
|
|
|
12
12
|
formatMcpStatusTable,
|
|
13
13
|
loadMcpRegistry,
|
|
14
14
|
isRemoteMcp,
|
|
15
|
-
|
|
16
|
-
patchConfigForPlatform,
|
|
17
|
-
setupStitch
|
|
15
|
+
patchConfigForPlatform
|
|
18
16
|
} from '../../lib/installers/mcp-installer.js';
|
|
19
17
|
import { detectClaudeConfig } from '../../lib/detectors/claude-config-detector.js';
|
|
20
18
|
import { detectProject } from '../../lib/detectors/index.js';
|
|
@@ -141,7 +139,7 @@ async function autoInstall(targetPath, stack, existingMcps, integrations, enable
|
|
|
141
139
|
console.log(chalk.gray(` Skipped (already configured): ${result.skipped.join(', ')}`));
|
|
142
140
|
}
|
|
143
141
|
|
|
144
|
-
const skillResults = installCompanionSkills(orchestration.autoInstallable);
|
|
142
|
+
const skillResults = installCompanionSkills(orchestration.autoInstallable, undefined, targetPath);
|
|
145
143
|
for (const r of skillResults) {
|
|
146
144
|
if (r.success) {
|
|
147
145
|
console.log(chalk.green(` ✓ Companion skills installed: ${r.repo}`));
|
|
@@ -199,79 +197,6 @@ async function setupSpecificMcp(targetPath, name, stack, existingMcps) {
|
|
|
199
197
|
|
|
200
198
|
const credentials = mcpEntry.install.credentials || [];
|
|
201
199
|
|
|
202
|
-
if (name === 'stitch' && !mcpEntry.install.autoInstall) {
|
|
203
|
-
console.log(chalk.cyan(`\n Setting up Stitch MCP (automated)\n`));
|
|
204
|
-
console.log(chalk.gray(` Usage: ${mcpEntry.usage}`));
|
|
205
|
-
console.log('');
|
|
206
|
-
|
|
207
|
-
let gcpProject;
|
|
208
|
-
const gcpCred = credentials.find(c => c.envVar === 'STITCH_GCP_PROJECT');
|
|
209
|
-
const { gcpProjectInput } = await inquirer.prompt([{
|
|
210
|
-
type: 'input',
|
|
211
|
-
name: 'gcpProjectInput',
|
|
212
|
-
message: gcpCred ? `${gcpCred.name} (leave blank for auto-detect):` : 'GCP Project ID (blank for auto-detect):',
|
|
213
|
-
}]);
|
|
214
|
-
if (gcpProjectInput?.trim()) gcpProject = gcpProjectInput.trim();
|
|
215
|
-
|
|
216
|
-
const spinner = ora('Setting up Stitch MCP...').start();
|
|
217
|
-
const result = await setupStitch(targetPath, { gcpProject });
|
|
218
|
-
|
|
219
|
-
for (const step of result.steps) {
|
|
220
|
-
if (step.success) {
|
|
221
|
-
switch (step.step) {
|
|
222
|
-
case 'find-gcloud': spinner.text = `gcloud found (${step.source})`; break;
|
|
223
|
-
case 'verify-adc': spinner.text = 'ADC credentials verified'; break;
|
|
224
|
-
case 'detect-project': spinner.text = `GCP project: ${step.gcpProject}`; break;
|
|
225
|
-
case 'enable-api': spinner.text = 'Stitch API enabled'; break;
|
|
226
|
-
case 'generate-proxy': spinner.text = `Proxy generated: ${step.proxyPath}`; break;
|
|
227
|
-
case 'install-mcp': spinner.text = 'MCP config installed in .mcp.json'; break;
|
|
228
|
-
case 'health-check': spinner.text = `Health-check passed (protocol ${step.protocolVersion})`; break;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (result.success) {
|
|
234
|
-
spinner.succeed('Stitch MCP setup complete');
|
|
235
|
-
for (const step of result.steps) {
|
|
236
|
-
if (step.step === 'health-check' && step.success) {
|
|
237
|
-
console.log(chalk.green(` ✓ Health-check passed (protocol ${step.protocolVersion})`));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
} else {
|
|
241
|
-
const failedStep = result.steps.find(s => !s.success && s.step !== 'enable-api' && s.step !== 'health-check');
|
|
242
|
-
spinner.fail(`Stitch setup failed at: ${failedStep?.step || 'unknown'}`);
|
|
243
|
-
if (failedStep?.error) {
|
|
244
|
-
console.log(chalk.red(` ${failedStep.error}`));
|
|
245
|
-
}
|
|
246
|
-
const healthStep = result.steps.find(s => s.step === 'health-check');
|
|
247
|
-
if (healthStep && !healthStep.success) {
|
|
248
|
-
console.log(chalk.yellow(` ⚠ Health-check: ${healthStep.error}`));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (mcpEntry.companionSkills?.installCommand) {
|
|
253
|
-
const { installSkills } = await inquirer.prompt([{
|
|
254
|
-
type: 'confirm',
|
|
255
|
-
name: 'installSkills',
|
|
256
|
-
message: 'Install Stitch companion skills (design, loop, etc.)?',
|
|
257
|
-
default: true
|
|
258
|
-
}]);
|
|
259
|
-
if (installSkills) {
|
|
260
|
-
const skillResults = installCompanionSkills({ stitch: mcpEntry });
|
|
261
|
-
for (const r of skillResults) {
|
|
262
|
-
if (r.success) {
|
|
263
|
-
console.log(chalk.green(` ✓ Companion skills installed: ${r.repo}`));
|
|
264
|
-
} else {
|
|
265
|
-
console.log(chalk.yellow(` ⚠ Failed to install companion skills: ${r.repo}`));
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
console.log('');
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
200
|
if (mcpEntry.install.autoInstall) {
|
|
276
201
|
const spinner = ora(`Installing ${name}...`).start();
|
|
277
202
|
const result = await installAutoMcps(targetPath, { [name]: mcpEntry });
|
|
@@ -280,6 +205,11 @@ async function setupSpecificMcp(targetPath, name, stack, existingMcps) {
|
|
|
280
205
|
} else {
|
|
281
206
|
spinner.info(`${name} MCP already configured`);
|
|
282
207
|
}
|
|
208
|
+
for (const r of installCompanionSkills({ [name]: mcpEntry }, undefined, targetPath)) {
|
|
209
|
+
console.log(r.success
|
|
210
|
+
? chalk.green(` ✓ Companion skills installed: ${r.repo}`)
|
|
211
|
+
: chalk.yellow(` ⚠ Failed to install companion skills: ${r.repo}`));
|
|
212
|
+
}
|
|
283
213
|
console.log('');
|
|
284
214
|
return;
|
|
285
215
|
}
|
|
@@ -395,7 +325,7 @@ async function interactiveWizard(targetPath, stack, existingMcps, integrations,
|
|
|
395
325
|
const result = await installAutoMcps(targetPath, orchestration.autoInstallable);
|
|
396
326
|
spinner.succeed(`Installed: ${result.added.join(', ')}`);
|
|
397
327
|
|
|
398
|
-
const skillResults = installCompanionSkills(orchestration.autoInstallable);
|
|
328
|
+
const skillResults = installCompanionSkills(orchestration.autoInstallable, undefined, targetPath);
|
|
399
329
|
for (const r of skillResults) {
|
|
400
330
|
if (r.success) {
|
|
401
331
|
console.log(chalk.green(` ✓ Companion skills: ${r.repo}`));
|
|
@@ -425,31 +355,6 @@ async function interactiveWizard(targetPath, stack, existingMcps, integrations,
|
|
|
425
355
|
}]);
|
|
426
356
|
|
|
427
357
|
if (setupNow) {
|
|
428
|
-
if (name === 'stitch' && !entry.install.autoInstall) {
|
|
429
|
-
const gcpCred = entry.install.credentials?.find(c => c.envVar === 'STITCH_GCP_PROJECT');
|
|
430
|
-
const { gcpProject } = await inquirer.prompt([{
|
|
431
|
-
type: 'input',
|
|
432
|
-
name: 'gcpProject',
|
|
433
|
-
message: gcpCred ? `${gcpCred.name} (blank for auto-detect):` : 'GCP Project ID (blank for auto-detect):',
|
|
434
|
-
}]);
|
|
435
|
-
|
|
436
|
-
const stitchSpinner = ora('Setting up Stitch MCP...').start();
|
|
437
|
-
const stitchResult = await setupStitch(targetPath, { gcpProject: gcpProject?.trim() || undefined });
|
|
438
|
-
if (stitchResult.success) {
|
|
439
|
-
stitchSpinner.succeed('Stitch MCP setup complete');
|
|
440
|
-
} else {
|
|
441
|
-
const failedStep = stitchResult.steps.find(s => !s.success && s.step !== 'enable-api' && s.step !== 'health-check');
|
|
442
|
-
stitchSpinner.fail(`Stitch setup failed: ${failedStep?.error || 'unknown'}`);
|
|
443
|
-
}
|
|
444
|
-
if (entry.companionSkills?.installCommand) {
|
|
445
|
-
const skillResults = installCompanionSkills({ stitch: entry });
|
|
446
|
-
for (const r of skillResults) {
|
|
447
|
-
if (r.success) console.log(chalk.green(` ✓ Companion skills: ${r.repo}`));
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
358
|
if (isRemoteMcp(entry.install.config)) {
|
|
454
359
|
console.log(chalk.cyan(` Launching ${capitalizedName} OAuth...`));
|
|
455
360
|
try {
|
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
generateSetupInstructions,
|
|
25
25
|
formatMcpStatusTable,
|
|
26
26
|
isRemoteMcp,
|
|
27
|
-
setupStitch,
|
|
28
27
|
loadMcpRegistry
|
|
29
28
|
} from '../../lib/installers/mcp-installer.js';
|
|
30
29
|
import { setupInfra } from '../../scripts/setup-infra.js';
|
|
@@ -303,7 +302,7 @@ export async function initCommand(options) {
|
|
|
303
302
|
autoInstalled[name] = orchestration.autoInstallable[name];
|
|
304
303
|
}
|
|
305
304
|
|
|
306
|
-
const skillResults = installCompanionSkills(orchestration.autoInstallable);
|
|
305
|
+
const skillResults = installCompanionSkills(orchestration.autoInstallable, undefined, targetPath);
|
|
307
306
|
for (const r of skillResults) {
|
|
308
307
|
if (r.success) {
|
|
309
308
|
logger.info(`✓ Companion skills installed: ${r.repo}`);
|
|
@@ -332,25 +331,6 @@ export async function initCommand(options) {
|
|
|
332
331
|
}]);
|
|
333
332
|
|
|
334
333
|
if (setupNow) {
|
|
335
|
-
if (name === 'stitch' && !entry.install.autoInstall) {
|
|
336
|
-
spinner.start('Setting up Stitch MCP...');
|
|
337
|
-
const stitchResult = await setupStitch(targetPath);
|
|
338
|
-
if (stitchResult.success) {
|
|
339
|
-
spinner.succeed('Stitch MCP setup complete');
|
|
340
|
-
manualInstalled[name] = entry;
|
|
341
|
-
} else {
|
|
342
|
-
const failedStep = stitchResult.steps.find(s => !s.success && s.step !== 'enable-api' && s.step !== 'health-check');
|
|
343
|
-
spinner.fail(`Stitch setup failed: ${failedStep?.error || 'unknown'}`);
|
|
344
|
-
}
|
|
345
|
-
if (entry.companionSkills?.installCommand) {
|
|
346
|
-
const skillResults = installCompanionSkills({ stitch: entry });
|
|
347
|
-
for (const r of skillResults) {
|
|
348
|
-
if (r.success) logger.success(` Companion skills installed: ${r.repo}`);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
334
|
if (isRemoteMcp(entry.install.config)) {
|
|
355
335
|
const url = entry.install.config.url;
|
|
356
336
|
logger.info(` Launching ${capitalizedName} OAuth authentication...`);
|
|
@@ -34,6 +34,8 @@ import { detectStackTags, mergeDetectedTags } from '../../lib/installers/stack-s
|
|
|
34
34
|
import { updateClaudeMdAgentsBlock, installRulesForStack, installCommandsForStack } from '../../scripts/setup-infra.js';
|
|
35
35
|
import { reconcileLegacyTemplatesCopy } from '../../lib/installers/templates-reconcile.js';
|
|
36
36
|
import { createEffects } from '../../lib/installers/effects.js';
|
|
37
|
+
import { syncStackTooling } from '../../lib/installers/stack-tooling.js';
|
|
38
|
+
import { detectClaudeConfig } from '../../lib/detectors/claude-config-detector.js';
|
|
37
39
|
import { applyEditorSettings } from '../../lib/worktree/vscode-settings.js';
|
|
38
40
|
import { registerProject } from '../../lib/projects/registry.js';
|
|
39
41
|
import {
|
|
@@ -571,6 +573,21 @@ export async function updateCommand(options = {}) {
|
|
|
571
573
|
updateSpinner.text = 'Updating Claude Code hooks...';
|
|
572
574
|
const hooksResult = await installClaudeHooks(targetPath, { fx });
|
|
573
575
|
|
|
576
|
+
updateSpinner.text = 'Syncing stack MCPs, skills and registries...';
|
|
577
|
+
let tooling = null;
|
|
578
|
+
try {
|
|
579
|
+
const claudeConfig = await detectClaudeConfig(targetPath);
|
|
580
|
+
tooling = await syncStackTooling(targetPath, {
|
|
581
|
+
config: configBackup, fx, exec: options.exec,
|
|
582
|
+
existingMcps: claudeConfig.mcpServers ?? [], enabledPlugins: claudeConfig.enabledPlugins ?? [],
|
|
583
|
+
});
|
|
584
|
+
for (const repo of tooling.skillsFailed) {
|
|
585
|
+
notices.push(`a skill de ${repo} não instalou (sem rede?): rode \`morph-spec update\` de novo ou \`morph-spec mcp setup\``);
|
|
586
|
+
}
|
|
587
|
+
} catch (err) {
|
|
588
|
+
logger.dim(` ⚠ MCPs do stack não sincronizados (${err.message})`);
|
|
589
|
+
}
|
|
590
|
+
|
|
574
591
|
updateSpinner.text = 'Checking CLAUDE.md import...';
|
|
575
592
|
const claudeMdDest = join(targetPath, 'CLAUDE.md');
|
|
576
593
|
await injectMorphImport(claudeMdDest, fx);
|
|
@@ -643,6 +660,9 @@ export async function updateCommand(options = {}) {
|
|
|
643
660
|
logger.dim(` ✓ .claude/agents/ (${agentsResult?.agents?.length ?? '?'} personas — stack: ${tagsLabel})`);
|
|
644
661
|
logger.dim(` ✓ .claude/rules/ (${rulesResult?.installed ?? '?'} stack-filtered rules)`);
|
|
645
662
|
if (commandsCopied) logger.dim(' ✓ .claude/commands/');
|
|
663
|
+
if (tooling?.mcps.length) logger.dim(` ✓ .mcp.json (+ ${tooling.mcps.join(', ')})`);
|
|
664
|
+
if (tooling?.skills.length) logger.dim(` ✓ .claude/skills/ (+ skill de ${tooling.skills.join(', ')})`);
|
|
665
|
+
if (tooling?.registries.length) logger.dim(` ✓ components.json (+ ${tooling.registries.join(', ')})`);
|
|
646
666
|
if (graphIgnore?.migrated) {
|
|
647
667
|
logger.dim(' ✓ .graphifyignore (dublês, fixtures e helpers de teste voltam ao grafo da raiz no próximo refresh');
|
|
648
668
|
logger.dim(' em background — início de sessão ou comando git do agente; numa worktree: morph-spec graph refresh)');
|
|
@@ -96,6 +96,12 @@ export function createEffects({ dryRun = false } = {}) {
|
|
|
96
96
|
return result.status === 0;
|
|
97
97
|
},
|
|
98
98
|
|
|
99
|
+
// Para o efeito que já tem escritor próprio: registra, e só executa fora do dry.
|
|
100
|
+
apply(verb, target, action, detail) {
|
|
101
|
+
record(verb, target, { detail });
|
|
102
|
+
return dryRun ? undefined : action();
|
|
103
|
+
},
|
|
104
|
+
|
|
99
105
|
list() {
|
|
100
106
|
return effects.map((e) => ({ ...e }));
|
|
101
107
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
|
-
import { readFileSync
|
|
3
|
-
import { execSync
|
|
4
|
-
import { homedir } from 'os';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
5
4
|
import { installMcpServers } from '../../utils/claude-settings-manager.js';
|
|
6
5
|
import { mcpServerNames } from '../../utils/agents-installer.js';
|
|
7
6
|
|
|
@@ -112,7 +111,7 @@ export async function installAutoMcps(targetPath, mcpsToInstall) {
|
|
|
112
111
|
return installMcpServers(targetPath, servers);
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
export function installCompanionSkills(mcpsInstalled, exec = execSync) {
|
|
114
|
+
export function installCompanionSkills(mcpsInstalled, exec = execSync, cwd = process.cwd()) {
|
|
116
115
|
const results = [];
|
|
117
116
|
|
|
118
117
|
for (const [name, entry] of Object.entries(mcpsInstalled)) {
|
|
@@ -120,7 +119,7 @@ export function installCompanionSkills(mcpsInstalled, exec = execSync) {
|
|
|
120
119
|
if (!companion?.installCommand) continue;
|
|
121
120
|
|
|
122
121
|
try {
|
|
123
|
-
exec(companion.installCommand, { stdio: 'inherit', timeout:
|
|
122
|
+
exec(companion.installCommand, { stdio: 'inherit', timeout: 120000, cwd });
|
|
124
123
|
results.push({ name, repo: companion.repo, success: true });
|
|
125
124
|
} catch {
|
|
126
125
|
results.push({ name, repo: companion.repo, success: false });
|
|
@@ -130,296 +129,6 @@ export function installCompanionSkills(mcpsInstalled, exec = execSync) {
|
|
|
130
129
|
return results;
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
export function getStitchProxyTemplate(gcpProject) {
|
|
134
|
-
return `#!/usr/bin/env node
|
|
135
|
-
/**
|
|
136
|
-
* Stitch MCP stdio-to-HTTP proxy with Google auth
|
|
137
|
-
* Generated by morph-spec mcp setup stitch
|
|
138
|
-
*/
|
|
139
|
-
const { execSync } = require('child_process');
|
|
140
|
-
const { createInterface } = require('readline');
|
|
141
|
-
|
|
142
|
-
const STITCH_URL = 'https://stitch.googleapis.com/mcp';
|
|
143
|
-
const PROJECT_ID = '${gcpProject}';
|
|
144
|
-
|
|
145
|
-
// Cross-platform gcloud path: Windows uses gcloud.cmd from Cloud SDK install
|
|
146
|
-
const GCLOUD = process.platform === 'win32'
|
|
147
|
-
? (process.env.LOCALAPPDATA || '') + '/Google/Cloud SDK/google-cloud-sdk/bin/gcloud.cmd'
|
|
148
|
-
: 'gcloud';
|
|
149
|
-
|
|
150
|
-
let cachedToken = null;
|
|
151
|
-
let tokenExpiry = 0;
|
|
152
|
-
let pendingRequests = 0;
|
|
153
|
-
let stdinClosed = false;
|
|
154
|
-
let sessionId = null;
|
|
155
|
-
|
|
156
|
-
function getToken() {
|
|
157
|
-
if (cachedToken && Date.now() < tokenExpiry) return cachedToken;
|
|
158
|
-
try {
|
|
159
|
-
cachedToken = execSync(\`"\${GCLOUD}" auth application-default print-access-token\`, {
|
|
160
|
-
encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 10000
|
|
161
|
-
}).trim();
|
|
162
|
-
tokenExpiry = Date.now() + 50 * 60 * 1000; // 50-minute TTL
|
|
163
|
-
return cachedToken;
|
|
164
|
-
} catch {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function maybeExit() {
|
|
170
|
-
if (stdinClosed && pendingRequests === 0) process.exit(0);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async function handleMessage(line) {
|
|
174
|
-
let msg;
|
|
175
|
-
try { msg = JSON.parse(line); } catch { return; }
|
|
176
|
-
|
|
177
|
-
// Notifications (no id) don't need responses
|
|
178
|
-
if (msg.id === undefined && msg.method === 'notifications/initialized') return;
|
|
179
|
-
|
|
180
|
-
const token = getToken();
|
|
181
|
-
if (!token) {
|
|
182
|
-
if (msg.id !== undefined) {
|
|
183
|
-
process.stdout.write(JSON.stringify({
|
|
184
|
-
jsonrpc: '2.0', id: msg.id,
|
|
185
|
-
error: { code: -32000, message: 'Failed to get gcloud auth token. Run: gcloud auth application-default login' }
|
|
186
|
-
}) + '\\n');
|
|
187
|
-
}
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const headers = {
|
|
192
|
-
'Content-Type': 'application/json',
|
|
193
|
-
'Authorization': \`Bearer \${token}\`,
|
|
194
|
-
'x-goog-user-project': PROJECT_ID,
|
|
195
|
-
};
|
|
196
|
-
if (sessionId) headers['mcp-session-id'] = sessionId;
|
|
197
|
-
|
|
198
|
-
pendingRequests++;
|
|
199
|
-
try {
|
|
200
|
-
const res = await fetch(STITCH_URL, { method: 'POST', headers, body: JSON.stringify(msg) });
|
|
201
|
-
|
|
202
|
-
// Track sticky session
|
|
203
|
-
const sid = res.headers.get('mcp-session-id');
|
|
204
|
-
if (sid) sessionId = sid;
|
|
205
|
-
|
|
206
|
-
// Retry once on 401 (expired token)
|
|
207
|
-
if (res.status === 401) {
|
|
208
|
-
cachedToken = null;
|
|
209
|
-
tokenExpiry = 0;
|
|
210
|
-
const retryToken = getToken();
|
|
211
|
-
if (retryToken) {
|
|
212
|
-
headers['Authorization'] = \`Bearer \${retryToken}\`;
|
|
213
|
-
const retryRes = await fetch(STITCH_URL, { method: 'POST', headers, body: JSON.stringify(msg) });
|
|
214
|
-
const retryText = await retryRes.text();
|
|
215
|
-
if (retryText.trim()) {
|
|
216
|
-
process.stdout.write(retryText.endsWith('\\n') ? retryText : retryText + '\\n');
|
|
217
|
-
}
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const text = await res.text();
|
|
223
|
-
if (text.trim()) {
|
|
224
|
-
process.stdout.write(text.endsWith('\\n') ? text : text + '\\n');
|
|
225
|
-
}
|
|
226
|
-
} catch (err) {
|
|
227
|
-
if (msg.id !== undefined) {
|
|
228
|
-
process.stdout.write(JSON.stringify({
|
|
229
|
-
jsonrpc: '2.0', id: msg.id,
|
|
230
|
-
error: { code: -32000, message: \`Stitch API error: \${err.message}\` }
|
|
231
|
-
}) + '\\n');
|
|
232
|
-
}
|
|
233
|
-
} finally {
|
|
234
|
-
pendingRequests--;
|
|
235
|
-
maybeExit();
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const rl = createInterface({ input: process.stdin });
|
|
240
|
-
rl.on('line', handleMessage);
|
|
241
|
-
rl.on('close', () => { stdinClosed = true; maybeExit(); });
|
|
242
|
-
`;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export function generateStitchProxy(targetPath, gcpProject) {
|
|
246
|
-
const claudeDir = join(targetPath, '.claude');
|
|
247
|
-
if (!existsSync(claudeDir)) {
|
|
248
|
-
mkdirSync(claudeDir, { recursive: true });
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const proxyPath = join(claudeDir, 'stitch-proxy.cjs');
|
|
252
|
-
writeFileSync(proxyPath, getStitchProxyTemplate(gcpProject), 'utf-8');
|
|
253
|
-
|
|
254
|
-
return { proxyPath };
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export function findGcloud(exec = execSync) {
|
|
258
|
-
try {
|
|
259
|
-
exec('gcloud --version', { stdio: ['pipe', 'pipe', 'pipe'], timeout: 10000 });
|
|
260
|
-
return { gcloudPath: 'gcloud', source: 'system' };
|
|
261
|
-
} catch {}
|
|
262
|
-
|
|
263
|
-
if (process.platform === 'win32') {
|
|
264
|
-
const winPath = join(process.env.LOCALAPPDATA || '', 'Google', 'Cloud SDK', 'google-cloud-sdk', 'bin', 'gcloud.cmd');
|
|
265
|
-
if (existsSync(winPath)) {
|
|
266
|
-
return { gcloudPath: winPath, source: 'windows-sdk' };
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const bundledDir = join(homedir(), '.stitch-mcp');
|
|
271
|
-
const bundledBin = process.platform === 'win32'
|
|
272
|
-
? join(bundledDir, 'google-cloud-sdk', 'bin', 'gcloud.cmd')
|
|
273
|
-
: join(bundledDir, 'google-cloud-sdk', 'bin', 'gcloud');
|
|
274
|
-
if (existsSync(bundledBin)) {
|
|
275
|
-
return { gcloudPath: bundledBin, source: 'bundled' };
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return { gcloudPath: null, source: 'not-found' };
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export async function setupStitch(targetPath, options = {}) {
|
|
282
|
-
const exec = options._exec || execSync;
|
|
283
|
-
const steps = [];
|
|
284
|
-
|
|
285
|
-
const { gcloudPath, source: gcloudSource } = findGcloud(exec);
|
|
286
|
-
if (!gcloudPath) {
|
|
287
|
-
steps.push({ step: 'find-gcloud', success: false, error: 'gcloud CLI not found. Install from: https://cloud.google.com/sdk/docs/install' });
|
|
288
|
-
return { success: false, steps };
|
|
289
|
-
}
|
|
290
|
-
steps.push({ step: 'find-gcloud', success: true, gcloudPath, source: gcloudSource });
|
|
291
|
-
|
|
292
|
-
const gcloudCmd = gcloudPath.includes(' ') ? `"${gcloudPath}"` : gcloudPath;
|
|
293
|
-
|
|
294
|
-
try {
|
|
295
|
-
exec(`${gcloudCmd} auth application-default print-access-token`, {
|
|
296
|
-
encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 15000
|
|
297
|
-
});
|
|
298
|
-
steps.push({ step: 'verify-adc', success: true });
|
|
299
|
-
} catch {
|
|
300
|
-
steps.push({ step: 'verify-adc', success: false, error: 'No ADC credentials. Run: gcloud auth application-default login' });
|
|
301
|
-
return { success: false, steps };
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
let gcpProject = options.gcpProject;
|
|
305
|
-
if (!gcpProject) {
|
|
306
|
-
const configPath = join(targetPath, '.morph', 'config', 'config.json');
|
|
307
|
-
if (existsSync(configPath)) {
|
|
308
|
-
try {
|
|
309
|
-
const config = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
310
|
-
gcpProject = config.gcpProject || config.project?.gcpProject;
|
|
311
|
-
} catch {}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
if (!gcpProject) {
|
|
315
|
-
try {
|
|
316
|
-
gcpProject = exec(`${gcloudCmd} config get-value project`, {
|
|
317
|
-
encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 10000
|
|
318
|
-
}).trim();
|
|
319
|
-
if (!gcpProject || gcpProject === '(unset)') gcpProject = null;
|
|
320
|
-
} catch {}
|
|
321
|
-
}
|
|
322
|
-
if (!gcpProject) {
|
|
323
|
-
steps.push({ step: 'detect-project', success: false, error: 'Could not detect GCP project. Pass it explicitly or set via: gcloud config set project <id>' });
|
|
324
|
-
return { success: false, steps };
|
|
325
|
-
}
|
|
326
|
-
steps.push({ step: 'detect-project', success: true, gcpProject });
|
|
327
|
-
|
|
328
|
-
try {
|
|
329
|
-
exec(`${gcloudCmd} services enable stitch.googleapis.com --project=${gcpProject}`, {
|
|
330
|
-
encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 30000
|
|
331
|
-
});
|
|
332
|
-
steps.push({ step: 'enable-api', success: true });
|
|
333
|
-
} catch (err) {
|
|
334
|
-
steps.push({ step: 'enable-api', success: false, error: `Failed to enable stitch API: ${err.message}` });
|
|
335
|
-
// Non-fatal: the API may already be enabled and the user may lack permission to re-enable it.
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
const { proxyPath } = generateStitchProxy(targetPath, gcpProject);
|
|
339
|
-
steps.push({ step: 'generate-proxy', success: true, proxyPath });
|
|
340
|
-
|
|
341
|
-
const mcpResult = await installMcpServers(targetPath, {
|
|
342
|
-
stitch: { type: 'stdio', command: 'node', args: ['.claude/stitch-proxy.cjs'] }
|
|
343
|
-
});
|
|
344
|
-
steps.push({ step: 'install-mcp', success: true, added: mcpResult.added, skipped: mcpResult.skipped });
|
|
345
|
-
|
|
346
|
-
const healthResult = await healthCheckStitchProxy(proxyPath);
|
|
347
|
-
steps.push({ step: 'health-check', ...healthResult });
|
|
348
|
-
|
|
349
|
-
const allCriticalPassed = steps.every(s =>
|
|
350
|
-
s.success || s.step === 'enable-api' || s.step === 'health-check'
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
return { success: allCriticalPassed, steps, gcpProject };
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
export function healthCheckStitchProxy(proxyPath) {
|
|
357
|
-
return new Promise((resolve) => {
|
|
358
|
-
const initMsg = JSON.stringify({
|
|
359
|
-
jsonrpc: '2.0',
|
|
360
|
-
id: 1,
|
|
361
|
-
method: 'initialize',
|
|
362
|
-
params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'morph-spec', version: '1.0.0' } }
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
const child = spawn('node', [proxyPath], {
|
|
366
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
367
|
-
timeout: 20000,
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
let output = '';
|
|
371
|
-
let timedOut = false;
|
|
372
|
-
|
|
373
|
-
const timer = setTimeout(() => {
|
|
374
|
-
timedOut = true;
|
|
375
|
-
child.kill();
|
|
376
|
-
resolve({ success: false, error: 'Health-check timed out after 20s' });
|
|
377
|
-
}, 20000);
|
|
378
|
-
|
|
379
|
-
child.stdout.on('data', (data) => {
|
|
380
|
-
output += data.toString();
|
|
381
|
-
const lines = output.split('\n').filter(l => l.trim());
|
|
382
|
-
for (const line of lines) {
|
|
383
|
-
try {
|
|
384
|
-
const resp = JSON.parse(line);
|
|
385
|
-
if (resp.result?.protocolVersion) {
|
|
386
|
-
clearTimeout(timer);
|
|
387
|
-
child.kill();
|
|
388
|
-
resolve({ success: true, protocolVersion: resp.result.protocolVersion });
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
if (resp.error) {
|
|
392
|
-
clearTimeout(timer);
|
|
393
|
-
child.kill();
|
|
394
|
-
resolve({ success: false, error: resp.error.message || 'MCP error' });
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
} catch {}
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
child.on('error', (err) => {
|
|
402
|
-
if (!timedOut) {
|
|
403
|
-
clearTimeout(timer);
|
|
404
|
-
resolve({ success: false, error: err.message });
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
child.on('close', (code) => {
|
|
409
|
-
if (!timedOut) {
|
|
410
|
-
clearTimeout(timer);
|
|
411
|
-
resolve({ success: false, error: output.trim()
|
|
412
|
-
? `Proxy exited with code ${code} — unexpected output`
|
|
413
|
-
: `Proxy exited with code ${code} and no output`
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
child.stdin.write(initMsg + '\n');
|
|
419
|
-
child.stdin.end();
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
132
|
export async function installMcpWithCredentials(targetPath, name, mcpEntry, credentialValues) {
|
|
424
133
|
const config = patchConfigForPlatform({ ...mcpEntry.install.config });
|
|
425
134
|
config.env = { ...config.env, ...credentialValues };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { PACKAGE_LOCATIONS } from '../../../framework/hooks/shared/frontend-locations.js';
|
|
5
|
+
import { filterByStack, installAutoMcps, installCompanionSkills, orchestrateMcpSetup } from './mcp-installer.js';
|
|
6
|
+
|
|
7
|
+
function componentsJsonFiles(targetPath, frontendPath) {
|
|
8
|
+
const locations = [...new Set([frontendPath, ...PACKAGE_LOCATIONS].filter(Boolean))];
|
|
9
|
+
return locations.map((loc) => join(targetPath, loc, 'components.json')).filter((file) => existsSync(file));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function missingRegistries(file, wanted) {
|
|
13
|
+
let json;
|
|
14
|
+
try { json = JSON.parse(readFileSync(file, 'utf8').replace(/^/, '')); } catch { return null; }
|
|
15
|
+
const current = json.registries ?? {};
|
|
16
|
+
const missing = Object.entries(wanted).filter(([name]) => !(name in current));
|
|
17
|
+
return missing.length > 0 ? { json, missing } : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* O que um MCP do stack precisa para valer num projeto já iniciado: a entrada em `.mcp.json`, a skill
|
|
22
|
+
* que o acompanha e os registries no `components.json`. Só acrescenta; o que o projeto declarou fica.
|
|
23
|
+
*/
|
|
24
|
+
export async function syncStackTooling(targetPath, options) {
|
|
25
|
+
const { config, existingMcps = [], enabledPlugins = [], fx, exec = execSync } = options;
|
|
26
|
+
const stack = config?.project?.stack ?? '';
|
|
27
|
+
const integrations = config?.project?.integrations ?? [];
|
|
28
|
+
const result = { mcps: [], skills: [], skillsFailed: [], registries: [] };
|
|
29
|
+
|
|
30
|
+
const { registry, autoInstallable } = orchestrateMcpSetup(targetPath, stack, existingMcps, { autoOnly: true, integrations, enabledPlugins });
|
|
31
|
+
const mcps = Object.keys(autoInstallable);
|
|
32
|
+
if (mcps.length > 0) {
|
|
33
|
+
await fx.apply('installMcp', join(targetPath, '.mcp.json'), () => installAutoMcps(targetPath, autoInstallable), mcps.join(', '));
|
|
34
|
+
result.mcps = mcps;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (const [name, entry] of Object.entries(filterByStack(registry, stack, integrations))) {
|
|
38
|
+
// O update apaga `.claude/skills/` inteiro antes: a skill é reinstalada toda vez, não só quando falta.
|
|
39
|
+
if (entry.companionSkills?.installCommand) {
|
|
40
|
+
const [outcome] = await fx.apply('installSkill', join(targetPath, '.claude', 'skills'),
|
|
41
|
+
() => installCompanionSkills({ [name]: entry }, exec, targetPath), entry.companionSkills.repo) ?? [];
|
|
42
|
+
if (outcome) (outcome.success ? result.skills : result.skillsFailed).push(entry.companionSkills.repo);
|
|
43
|
+
}
|
|
44
|
+
if (!entry.projectRegistries) continue;
|
|
45
|
+
for (const file of componentsJsonFiles(targetPath, config?.project?.frontendPath)) {
|
|
46
|
+
const found = missingRegistries(file, entry.projectRegistries);
|
|
47
|
+
if (!found) continue;
|
|
48
|
+
fx.writeJson(file, { ...found.json, registries: { ...found.json.registries, ...Object.fromEntries(found.missing) } });
|
|
49
|
+
result.registries.push(...found.missing.map(([registryName]) => registryName));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
package/src/lib/risk-detector.js
CHANGED
|
@@ -64,6 +64,12 @@ export function uiuxChecklistPause(screenChecklist) {
|
|
|
64
64
|
+ ' — volume, paginação, ordenação, filtro, os três estados, mobile e abas por tela'
|
|
65
65
|
+ ' ("não se aplica" vale, se escrito)';
|
|
66
66
|
}
|
|
67
|
+
const components = screenChecklist.components ?? [];
|
|
68
|
+
if (components.length > 0) {
|
|
69
|
+
return `origem de componente sem resposta em 1-design/mockups.md: ${firstOf(components)}`
|
|
70
|
+
+ ' — busque no projeto e nos registries do shadcn antes de escrever;'
|
|
71
|
+
+ ' cada linha de `### Componentes` é projeto, registry ou novo';
|
|
72
|
+
}
|
|
67
73
|
const prototypes = screenChecklist.prototypes ?? [];
|
|
68
74
|
if (prototypes.length === 0) return null;
|
|
69
75
|
return `protótipo incompleto: ${firstOf(prototypes)}`
|
|
@@ -444,6 +450,8 @@ export function getRiskSignals(signals) {
|
|
|
444
450
|
out.push(problems.length > 0
|
|
445
451
|
? `checklist de tela incompleto (${problems.length} problema(s))`
|
|
446
452
|
: `checklist de tela completo (${screens.length} tela(s))`);
|
|
453
|
+
const components = signals.screenChecklist.components ?? [];
|
|
454
|
+
if (components.length > 0) out.push(`origem de componente sem resposta (${components.length} problema(s))`);
|
|
447
455
|
const prototypes = signals.screenChecklist.prototypes ?? [];
|
|
448
456
|
if (screens.length > 0) {
|
|
449
457
|
out.push(prototypes.length > 0
|