@polymorphism-tech/morph-spec 11.2.0 → 11.3.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 +3 -2
- package/bin/morph-spec.js +7 -7
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +1 -1
- package/framework/MORPH.md +2 -2
- package/framework/agents.json +4 -4
- package/framework/docs/CLI.md +19 -11
- package/framework/evals/review-checklist.md +26 -2
- package/framework/hooks/README.md +3 -2
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +2 -2
- package/framework/mcp/registry.json +15 -15
- package/framework/rules/ai-agents-standards.md +9 -1
- package/framework/rules/gsap-standards.md +8 -0
- package/framework/rules/mcp-standards.md +10 -0
- package/framework/schemas/config.schema.json +7 -0
- 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 +4 -3
- package/framework/skills/core/morph-plan/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +1 -1
- package/framework/standards/STANDARDS.json +8 -4
- package/framework/standards/STANDARDS.meta.json +1 -1
- package/framework/standards/ai-agents/agent-archetypes.md +1 -1
- package/framework/standards/ai-agents/middleware-patterns.md +0 -2
- package/framework/standards/ai-agents/prompt-sources.md +2 -2
- package/framework/standards/ai-agents/providers/model-registry.md +9 -12
- package/framework/standards/ai-agents/rag-custom-pgvector.md +2 -9
- package/framework/standards/frontend/design-system/ai-image-generation.md +1 -1
- package/framework/standards/infrastructure/docker/local-compose-isolation.md +2 -2
- package/framework/standards/integration/mcp/mcp-tools.md +124 -266
- package/framework/templates/README.md +52 -82
- package/framework/templates/REGISTRY.json +0 -206
- package/framework/templates/code/sql/ai-agents/agent-prompts-migration.sql.template +3 -4
- package/framework/templates/context/design-system.md +1 -1
- package/framework/templates/docs/plan.md +1 -1
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/model-registry.v2.json +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaDisclosureTests.cs +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Morph.AiKit.Tests.csproj +2 -4
- package/framework/templates/frontend/nextjs/gsap-scroll-section.tsx.hbs +13 -17
- package/framework/templates/infrastructure/github/README.md +10 -13
- package/package.json +2 -2
- package/src/commands/mcp/manual-setup.js +95 -0
- package/src/commands/mcp/mcp-setup.js +23 -191
- package/src/commands/project/doctor.js +6 -16
- package/src/commands/project/init-contract.js +2 -2
- package/src/commands/project/init.js +15 -133
- package/src/commands/project/stack-scan.js +6 -14
- package/src/commands/project/stack-set.js +1 -1
- package/src/commands/project/standards.js +1 -2
- package/src/commands/project/update.js +52 -66
- package/src/commands/scaffold/scaffold.js +28 -7
- package/src/lib/ai/ai-project-scan.js +1 -4
- package/src/lib/ai/code-audit.js +1 -6
- package/src/lib/ai/registry-audit.js +2 -1
- package/src/lib/config/project-config.js +3 -2
- package/src/lib/contract/apply.js +2 -1
- package/src/lib/contract/merge.js +1 -0
- package/src/lib/contract/scan.js +5 -5
- package/src/lib/detectors/claude-config-detector.js +45 -47
- package/src/lib/detectors/mcp-config.js +2 -1
- package/src/lib/diff/diff-lines.js +2 -7
- package/src/lib/graph/graph-loader.js +2 -1
- package/src/lib/graph/graphifyignore.js +2 -1
- package/src/lib/installers/install-manifest.js +56 -0
- package/src/lib/installers/mcp-installer.js +14 -5
- package/src/lib/installers/rules-installer.js +9 -15
- package/src/lib/installers/stack-assets.js +42 -21
- package/src/lib/installers/stack-sync.js +12 -12
- package/src/lib/installers/stack-tooling.js +4 -3
- package/src/lib/json-file.js +9 -0
- package/src/lib/plan/artifact-vocabulary.js +1 -1
- package/src/lib/plan/checks.js +3 -2
- package/src/lib/plan/media.js +3 -3
- package/src/lib/plan/plan-parser.js +5 -10
- package/src/lib/review-reports.js +5 -4
- package/src/lib/stack/stack-scan.js +1 -1
- package/src/lib/standards/verified-against.js +1 -1
- package/src/lib/tests-audit/audit.js +1 -1
- package/src/lib/text.js +5 -0
- package/src/scripts/setup-infra.js +22 -33
- package/src/utils/agents-installer.js +13 -30
- package/src/utils/claude-md-injector.js +16 -50
- package/src/utils/claude-settings-manager.js +2 -2
- package/src/utils/file-copier.js +3 -4
- package/src/utils/hooks-installer.js +55 -20
- package/src/utils/skills-installer.js +18 -78
- package/framework/templates/IDE-SNIPPETS.md +0 -262
- package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +0 -26
- package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +0 -28
- package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +0 -99
- package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +0 -40
- package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +0 -54
- package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +0 -53
- package/framework/templates/code/dotnet/contracts/README.md +0 -74
- package/framework/templates/code/dotnet/database/vector-entity.cs +0 -49
- package/framework/templates/code/sql/ai-agents/pgvector-embeddings-migration.sql.template +0 -91
- package/framework/templates/code/sql/postgresql-migration.template.sql +0 -108
- package/framework/templates/code/typescript/contracts.ts +0 -140
- package/framework/templates/examples/design-system-examples.md +0 -354
- package/framework/templates/infrastructure/docker/Dockerfile.template +0 -58
- package/framework/templates/infrastructure/github/actions/docker-build-push/action.yml.hbs +0 -45
- package/framework/templates/infrastructure/github/actions/health-check/action.yml.hbs +0 -27
- package/framework/templates/integrations/asaas-client.cs +0 -332
- package/framework/templates/integrations/asaas-webhook.cs +0 -290
- package/framework/templates/integrations/neon-auth-config.cs +0 -170
- package/framework/templates/ui/design-system.css +0 -226
- package/src/lib/detectors/index.js +0 -153
- package/src/lib/installers/templates-reconcile.js +0 -26
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { readMorphConfig } from '../../lib/config/project-config.js';
|
|
2
2
|
import { scanStack, renderStackScan } from '../../lib/stack/stack-scan.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
export function
|
|
4
|
+
/** Prints, never writes: the plan reads stdout. */
|
|
5
|
+
export function stackScanCommand(options = {}) {
|
|
6
|
+
const cwd = process.cwd();
|
|
6
7
|
const result = scanStack(cwd, readMorphConfig(cwd));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export function stackScanCommand(featureName, options = {}) {
|
|
11
|
-
const result = runStackScan(featureName);
|
|
12
|
-
if (options.json) {
|
|
13
|
-
const { markdown, ...rest } = result;
|
|
14
|
-
console.log(JSON.stringify(rest, null, 2));
|
|
15
|
-
} else {
|
|
16
|
-
process.stdout.write(result.markdown);
|
|
17
|
-
}
|
|
18
|
-
process.exit(result.exit);
|
|
8
|
+
if (options.json) console.log(JSON.stringify(result, null, 2));
|
|
9
|
+
else process.stdout.write(renderStackScan(result, 'projeto'));
|
|
10
|
+
process.exit(0);
|
|
19
11
|
}
|
|
@@ -16,7 +16,7 @@ export async function stackSetCommand(stack, options = {}) {
|
|
|
16
16
|
process.exit(1);
|
|
17
17
|
}
|
|
18
18
|
const { stack: declared, integrations: declaredIntegrations, sync } = result;
|
|
19
|
-
// The whole tag set, not only what was declared now: the install removes every
|
|
19
|
+
// The whole tag set, not only what was declared now: the install removes every framework asset outside it.
|
|
20
20
|
await installStackAssets(process.cwd(), [...new Set([...getProjectTags(readMorphConfig(process.cwd())), ...sync.tags])]);
|
|
21
21
|
if (options.json) {
|
|
22
22
|
console.log(JSON.stringify({ stack: declared, integrations: declaredIntegrations, rulesAdded: sync.added, rulesUpdated: sync.updated }, null, 2));
|
|
@@ -140,8 +140,7 @@ function parseTagsOption(raw) {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export function standardsCommand(options = {}) {
|
|
143
|
-
const
|
|
144
|
-
const standardsJsonPath = resolveStandardsJsonPath(cwd);
|
|
143
|
+
const standardsJsonPath = resolveStandardsJsonPath(process.cwd());
|
|
145
144
|
|
|
146
145
|
if (!standardsJsonPath) {
|
|
147
146
|
console.error(chalk.red('\n❌ STANDARDS.json não encontrado — nem em .morph/framework/standards/ nem no pacote.'));
|
|
@@ -22,15 +22,12 @@ import {
|
|
|
22
22
|
MAJOR_JUMP_LIMIT
|
|
23
23
|
} from '../../utils/version-checker.js';
|
|
24
24
|
import { installClaudeHooks, installGlobalStatusline } from '../../utils/claude-settings-manager.js';
|
|
25
|
-
import {
|
|
26
|
-
import { installAgents } from '../../utils/agents-installer.js';
|
|
27
|
-
import { injectMorphImport } from '../../utils/claude-md-injector.js';
|
|
25
|
+
import { removeMorphImport } from '../../utils/claude-md-injector.js';
|
|
28
26
|
import { getProjectTags } from '../../lib/stack-filter.js';
|
|
29
27
|
import { detectStackTags, mergeDetectedTags } from '../../lib/installers/stack-sync.js';
|
|
30
|
-
import { updateClaudeMdAgentsBlock } from '../../scripts/setup-infra.js';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import { reconcileLegacyTemplatesCopy } from '../../lib/installers/templates-reconcile.js';
|
|
28
|
+
import { CONFIG_SCHEMA_REF, hooksPayloadFilter, updateClaudeMdAgentsBlock } from '../../scripts/setup-infra.js';
|
|
29
|
+
import { installAssetsForTags } from '../../lib/installers/stack-assets.js';
|
|
30
|
+
import { ASSET_DIRS, readManifest } from '../../lib/installers/install-manifest.js';
|
|
34
31
|
import { createEffects } from '../../lib/installers/effects.js';
|
|
35
32
|
import { syncStackTooling } from '../../lib/installers/stack-tooling.js';
|
|
36
33
|
import { detectClaudeConfig } from '../../lib/detectors/claude-config-detector.js';
|
|
@@ -44,23 +41,25 @@ async function backupUserConfig(morphPath) {
|
|
|
44
41
|
return (await pathExists(configPath)) ? readJson(configPath) : null;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
/** Payload folders only morph-spec writes: wiped whole on every update. `.morph/framework/installed.json` is outside all of them. */
|
|
45
|
+
export function frameworkDirsToClean(morphPath) {
|
|
49
46
|
return [
|
|
50
|
-
// framework/templates is left out on purpose: reconcileLegacyTemplatesCopy() decides whether
|
|
51
|
-
// a local copy is a user override to preserve.
|
|
52
47
|
join(morphPath, 'framework', 'standards'),
|
|
53
48
|
join(morphPath, 'framework', 'hooks'),
|
|
54
49
|
join(morphPath, 'framework', 'schemas'),
|
|
55
50
|
join(morphPath, 'framework', 'evals'),
|
|
56
51
|
join(morphPath, 'config'),
|
|
57
|
-
join(claudeDir, 'commands'),
|
|
58
|
-
join(claudeDir, 'rules'),
|
|
59
|
-
join(claudeDir, 'skills'),
|
|
60
|
-
join(claudeDir, 'agents'),
|
|
61
52
|
];
|
|
62
53
|
}
|
|
63
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The four `.claude` folders the project shares with morph-spec. Wiped whole only once, for an install
|
|
57
|
+
* with no manifest; with one, the installers remove file by file what the manifest and the package name.
|
|
58
|
+
*/
|
|
59
|
+
export function assetDirsToClean(targetPath) {
|
|
60
|
+
return ASSET_DIRS.map((dir) => join(targetPath, '.claude', dir));
|
|
61
|
+
}
|
|
62
|
+
|
|
64
63
|
function sweepRemove(dir, fx) {
|
|
65
64
|
let entries;
|
|
66
65
|
try {
|
|
@@ -83,12 +82,12 @@ function sweepRemove(dir, fx) {
|
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
85
|
+
* Com `wipeAssets`, os installers rodam depois com `prune: false`: em dry as pastas ainda estão no disco,
|
|
86
|
+
* e a poda preveria remoções que a execução real, com elas já vazias, nunca faz.
|
|
88
87
|
*/
|
|
89
|
-
function cleanFrameworkDirs(morphPath, targetPath, fx) {
|
|
88
|
+
function cleanFrameworkDirs(morphPath, targetPath, fx, { wipeAssets }) {
|
|
90
89
|
const cleaned = [];
|
|
91
|
-
for (const dir of frameworkDirsToClean(morphPath, targetPath)) {
|
|
90
|
+
for (const dir of [...frameworkDirsToClean(morphPath), ...(wipeAssets ? assetDirsToClean(targetPath) : [])]) {
|
|
92
91
|
if (existsSync(dir)) cleaned.push({ dir, files: sweepRemove(dir, fx) });
|
|
93
92
|
}
|
|
94
93
|
return cleaned;
|
|
@@ -104,6 +103,7 @@ function restoreUserConfig(morphPath, targetPath, configBackup, currentVersion,
|
|
|
104
103
|
fx.writeJson(configPath, configBackup);
|
|
105
104
|
} else {
|
|
106
105
|
const defaultConfig = {
|
|
106
|
+
$schema: CONFIG_SCHEMA_REF,
|
|
107
107
|
frameworkVersion: currentVersion,
|
|
108
108
|
project: { name: basename(resolve(targetPath)) },
|
|
109
109
|
};
|
|
@@ -354,25 +354,37 @@ export async function updateCommand(options = {}) {
|
|
|
354
354
|
logger.dim(' ✓ Created .morph directory structure');
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
// Lido antes de qualquer remoção; em dry o manifesto novo só existe em memória.
|
|
358
|
+
const manifest = readManifest(targetPath);
|
|
359
|
+
const wipeAssets = manifest === null && !needsInitialization;
|
|
360
|
+
if (wipeAssets) {
|
|
361
|
+
notices.push('Instalação anterior ao manifesto (`.morph/framework/installed.json`): '
|
|
362
|
+
+ '`.claude/{commands,rules,skills,agents}` são apagadas por inteiro, pela última vez. '
|
|
363
|
+
+ 'Até esta versão o `update` sempre limpou essas pastas inteiras e o deny do settings bloqueava edição em rules e skills, '
|
|
364
|
+
+ 'então não há como separar o que seria seu. Daqui em diante só sai o que o manifesto registra: arquivo seu nelas fica.');
|
|
365
|
+
}
|
|
366
|
+
|
|
357
367
|
const updateSpinner = ora(dryRun ? 'Prevendo efeitos...' : 'Updating MORPH-SPEC...').start();
|
|
358
368
|
let cleaned = [];
|
|
359
369
|
|
|
360
370
|
try {
|
|
361
371
|
updateSpinner.text = 'Cleaning old framework files...';
|
|
362
|
-
cleaned = cleanFrameworkDirs(morphPath, targetPath, fx);
|
|
372
|
+
cleaned = cleanFrameworkDirs(morphPath, targetPath, fx, { wipeAssets });
|
|
363
373
|
// Written back at once: a failure in the installs below must not leave the project without its contract.
|
|
364
374
|
if (configBackup) restoreUserConfig(morphPath, targetPath, configBackup, cliCheck.current, fx);
|
|
365
375
|
logger.dim(' ✓ Old framework files removed');
|
|
366
376
|
|
|
367
|
-
|
|
368
|
-
|
|
377
|
+
if (existsSync(join(morphPath, 'framework', 'templates'))) {
|
|
378
|
+
notices.push('.morph/framework/templates/ não é lido: os templates vêm do pacote (`morph-spec scaffold show <id>`). Apague a pasta.');
|
|
379
|
+
}
|
|
369
380
|
|
|
370
381
|
updateSpinner.text = 'Updating standards, hooks, charter, schemas and evals...';
|
|
371
382
|
for (const dir of ['standards', 'hooks', 'schemas', 'evals']) {
|
|
372
|
-
fx.copyDir(join(frameworkDir, dir), join(morphPath, 'framework', dir));
|
|
383
|
+
fx.copyDir(join(frameworkDir, dir), join(morphPath, 'framework', dir), dir === 'hooks' ? { filter: hooksPayloadFilter } : {});
|
|
384
|
+
}
|
|
385
|
+
for (const file of ['agents.json', 'ai-pin.json', 'MORPH.md']) {
|
|
386
|
+
fx.copyFile(join(frameworkDir, file), join(morphPath, 'framework', file));
|
|
373
387
|
}
|
|
374
|
-
fx.copyFile(join(frameworkDir, 'agents.json'), join(morphPath, 'framework', 'agents.json'));
|
|
375
|
-
fx.copyFile(join(frameworkDir, 'MORPH.md'), join(morphPath, 'framework', 'MORPH.md'));
|
|
376
388
|
fx.copyFile(join(frameworkDir, 'docs', 'CLI.md'), join(morphPath, 'framework', 'CLI.md'));
|
|
377
389
|
for (const dead of [join(morphPath, 'framework', 'phases.json'), join(morphPath, 'context', 'README.md')]) {
|
|
378
390
|
if (existsSync(dead)) fx.remove(dead);
|
|
@@ -388,7 +400,7 @@ export async function updateCommand(options = {}) {
|
|
|
388
400
|
if (configBackup) projectTags = getProjectTags(configBackup);
|
|
389
401
|
} catch {}
|
|
390
402
|
// The same detection as `syncStackRules`, folded in before the installs: `restoreUserConfig`
|
|
391
|
-
// writes `configBackup`, and a dry run sees `.claude/rules/`
|
|
403
|
+
// writes `configBackup`, and a dry run sees `.claude/rules/` as it was, not as this run leaves it.
|
|
392
404
|
if (configBackup) {
|
|
393
405
|
try {
|
|
394
406
|
const detected = detectStackTags(targetPath, { config: configBackup });
|
|
@@ -398,34 +410,16 @@ export async function updateCommand(options = {}) {
|
|
|
398
410
|
logger.dim(` ✓ config.json: + ${merged.added.join(', ')} (detectado nos arquivos)`);
|
|
399
411
|
}
|
|
400
412
|
projectTags = [...new Set([...getProjectTags(configBackup), ...detected.tags])];
|
|
401
|
-
} catch {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
let commandsCopied = false;
|
|
405
|
-
const commandsSrc = join(frameworkDir, 'commands');
|
|
406
|
-
if (await pathExists(commandsSrc)) {
|
|
407
|
-
const commandsDest = join(claudeDest, 'commands');
|
|
408
|
-
fx.ensureDir(commandsDest);
|
|
409
|
-
installCommandsForStack(commandsSrc, commandsDest, projectTags, fx);
|
|
410
|
-
commandsCopied = true;
|
|
411
|
-
} else {
|
|
412
|
-
logger.warn(' ⚠ framework/commands/ source missing — commands not updated');
|
|
413
|
+
} catch (err) {
|
|
414
|
+
logger.dim(` ⚠ stack não redetectada nos arquivos (${err.message}): valem as tags do config.json`);
|
|
415
|
+
}
|
|
413
416
|
}
|
|
414
417
|
|
|
415
|
-
updateSpinner.text = 'Syncing
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
const agentsResult =
|
|
420
|
-
|
|
421
|
-
updateSpinner.text = 'Syncing rules to .claude/rules/...';
|
|
422
|
-
const rulesSrc = join(frameworkDir, 'rules');
|
|
423
|
-
const rulesDest = join(claudeDest, 'rules');
|
|
424
|
-
let rulesResult = null;
|
|
425
|
-
if (await pathExists(rulesSrc)) {
|
|
426
|
-
fx.ensureDir(rulesDest);
|
|
427
|
-
rulesResult = installRulesForStack(rulesSrc, rulesDest, projectTags, fx);
|
|
428
|
-
}
|
|
418
|
+
updateSpinner.text = 'Syncing commands, rules, skills and agents to .claude/...';
|
|
419
|
+
const assets = await installAssetsForTags(targetPath, projectTags, {
|
|
420
|
+
frameworkSrc: frameworkDir, fx, manifest, prune: !wipeAssets, createManifest: true,
|
|
421
|
+
});
|
|
422
|
+
const agentsResult = assets.agents;
|
|
429
423
|
|
|
430
424
|
updateSpinner.text = 'Syncing .claude/CLAUDE.md...';
|
|
431
425
|
const runtimeSrc = join(frameworkDir, 'CLAUDE.md');
|
|
@@ -447,7 +441,7 @@ export async function updateCommand(options = {}) {
|
|
|
447
441
|
}
|
|
448
442
|
|
|
449
443
|
updateSpinner.text = 'Updating Claude Code hooks...';
|
|
450
|
-
const hooksResult = await installClaudeHooks(targetPath, { fx });
|
|
444
|
+
const hooksResult = await installClaudeHooks(targetPath, { fx, manifest: assets.manifest });
|
|
451
445
|
|
|
452
446
|
updateSpinner.text = 'Syncing stack MCPs, skills and registries...';
|
|
453
447
|
let tooling = null;
|
|
@@ -464,9 +458,7 @@ export async function updateCommand(options = {}) {
|
|
|
464
458
|
logger.dim(` ⚠ MCPs do stack não sincronizados (${err.message})`);
|
|
465
459
|
}
|
|
466
460
|
|
|
467
|
-
|
|
468
|
-
const claudeMdDest = join(targetPath, 'CLAUDE.md');
|
|
469
|
-
await injectMorphImport(claudeMdDest, fx);
|
|
461
|
+
await removeMorphImport(join(targetPath, 'CLAUDE.md'), fx);
|
|
470
462
|
|
|
471
463
|
updateSpinner.text = 'Restoring user configuration...';
|
|
472
464
|
restoreUserConfig(morphPath, targetPath, configBackup, cliCheck.current, fx);
|
|
@@ -508,21 +500,15 @@ export async function updateCommand(options = {}) {
|
|
|
508
500
|
|
|
509
501
|
logger.blank();
|
|
510
502
|
logger.info('Updated files:');
|
|
511
|
-
if (templatesReconcile === 'removed-legacy') {
|
|
512
|
-
logger.dim(' ✓ .morph/framework/templates/ (legacy installer copy removed — resolved from package)');
|
|
513
|
-
} else if (templatesReconcile === 'preserved-override') {
|
|
514
|
-
logger.dim(' ⚠ .morph/framework/templates/ (local override present — preserved untouched, not updated)');
|
|
515
|
-
}
|
|
516
|
-
|
|
517
503
|
// Counts make a silent stack-filter downgrade visible (a dotnet project with "1 persona");
|
|
518
504
|
// only compact tags, since integrations are long free text.
|
|
519
505
|
const compactTags = projectTags.filter(t => !t.includes(' '));
|
|
520
506
|
const tagsLabel = compactTags.length > 0 ? compactTags.join('+') : 'universal only';
|
|
521
507
|
logger.dim(` ✓ .claude/settings.local.json (${hooksResult.installed} hooks installed)`);
|
|
522
|
-
logger.dim(` ✓ .claude/skills/ (${
|
|
523
|
-
logger.dim(` ✓ .claude/agents/ (${
|
|
524
|
-
logger.dim(` ✓ .claude/rules/ (${
|
|
525
|
-
|
|
508
|
+
logger.dim(` ✓ .claude/skills/ (${assets.skills.installed} skills — stack: ${tagsLabel})`);
|
|
509
|
+
logger.dim(` ✓ .claude/agents/ (${assets.agents.installed} personas — stack: ${tagsLabel})`);
|
|
510
|
+
logger.dim(` ✓ .claude/rules/ (${assets.rules.installed} stack-filtered rules)`);
|
|
511
|
+
logger.dim(` ✓ .claude/commands/ (${assets.commands.installed} commands)`);
|
|
526
512
|
if (tooling?.mcps.length) logger.dim(` ✓ .mcp.json (+ ${tooling.mcps.join(', ')})`);
|
|
527
513
|
if (tooling?.skills.length) logger.dim(` ✓ .claude/skills/ (+ skill de ${tooling.skills.join(', ')})`);
|
|
528
514
|
if (tooling?.registries.length) logger.dim(` ✓ components.json (+ ${tooling.registries.join(', ')})`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { readFileSync, statSync } from 'fs';
|
|
3
|
-
import { relative } from 'path';
|
|
2
|
+
import { readFileSync, readdirSync, statSync } from 'fs';
|
|
3
|
+
import { join, relative } from 'path';
|
|
4
4
|
import { logger } from '../../utils/logger.js';
|
|
5
5
|
import {
|
|
6
6
|
scaffoldDotnetSlice,
|
|
@@ -108,16 +108,37 @@ export async function scaffoldNextjsCommand(feature, options) {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
function projectFiles(root, rel = '') {
|
|
112
|
+
return readdirSync(join(root, rel), { withFileTypes: true }).flatMap((e) => {
|
|
113
|
+
const child = rel ? `${rel}/${e.name}` : e.name;
|
|
114
|
+
if (e.isDirectory()) return ['bin', 'obj', 'TestResults'].includes(e.name) ? [] : projectFiles(root, child);
|
|
115
|
+
return [child];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Prints a package template verbatim: templates are never copied into the project. A template that is a
|
|
121
|
+
* whole project lists its files, and prints the one named by `file`.
|
|
122
|
+
*/
|
|
123
|
+
export function scaffoldShowCommand(templateId, file) {
|
|
113
124
|
if (!getTemplateById(templateId)) {
|
|
114
125
|
logger.error(`Template "${templateId}" not found in the package registry`);
|
|
115
126
|
process.exit(1);
|
|
116
127
|
}
|
|
117
128
|
const path = resolveFrameworkTemplatePath(templateId);
|
|
118
|
-
if (statSync(path).isDirectory()) {
|
|
119
|
-
|
|
129
|
+
if (!statSync(path).isDirectory()) {
|
|
130
|
+
process.stdout.write(readFileSync(path, 'utf-8'));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const files = projectFiles(path).sort();
|
|
134
|
+
if (!file) {
|
|
135
|
+
process.stdout.write(`${files.join('\n')}\n`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const wanted = String(file).replace(/\\/g, '/');
|
|
139
|
+
if (!files.includes(wanted)) {
|
|
140
|
+
logger.error(`"${wanted}" is not a file of "${templateId}": morph-spec scaffold show ${templateId} lists them`);
|
|
120
141
|
process.exit(1);
|
|
121
142
|
}
|
|
122
|
-
process.stdout.write(readFileSync(path, 'utf-8'));
|
|
143
|
+
process.stdout.write(readFileSync(join(path, wanted), 'utf-8'));
|
|
123
144
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { readdirSync, readFileSync, statSync, existsSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { WORKTREE_DIR_NAMES } from '../scan/worktree-dirs.js';
|
|
7
|
+
import { stripBom } from '../json-file.js';
|
|
7
8
|
|
|
8
9
|
export const SCAN_IGNORED_DIRS = new Set([
|
|
9
10
|
'node_modules',
|
|
@@ -33,10 +34,6 @@ export function isAiPackage(name) {
|
|
|
33
34
|
);
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
function stripBom(text) {
|
|
37
|
-
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
37
|
/** Tags fecham na ordem e todo `<` tem `>`: um `.csproj` truncado vira `unreadable`, não "sem drift". */
|
|
41
38
|
export function isWellFormedXml(xml) {
|
|
42
39
|
const stack = [];
|
package/src/lib/ai/code-audit.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { readFileSync } from 'node:fs';
|
|
6
6
|
import { relative } from 'node:path';
|
|
7
7
|
import { collectProjectFiles } from './ai-project-scan.js';
|
|
8
|
+
import { lineOf } from '../text.js';
|
|
8
9
|
import { stripComments } from '../../../framework/hooks/shared/comment-stripper.js';
|
|
9
10
|
|
|
10
11
|
/** Símbolos renomeados antes do 1.0 GA, e o nome vivo de cada um. */
|
|
@@ -14,12 +15,6 @@ const RENAMED_SYMBOLS = {
|
|
|
14
15
|
ChatMessageStore: 'a conversa persistida do projeto (ver ai-agents/agent-session.md)',
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
function lineOf(text, index) {
|
|
18
|
-
let line = 1;
|
|
19
|
-
for (let i = 0; i < index && i < text.length; i++) if (text[i] === '\n') line += 1;
|
|
20
|
-
return line;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
18
|
function collectCsharpFiles(root) {
|
|
24
19
|
return collectProjectFiles(root, (name) => name.toLowerCase().endsWith('.cs'));
|
|
25
20
|
}
|
|
@@ -5,6 +5,7 @@ import { readFileSync } from 'node:fs';
|
|
|
5
5
|
import { existsSync } from 'node:fs';
|
|
6
6
|
import { isAbsolute, join, basename } from 'node:path';
|
|
7
7
|
import { collectProjectFiles } from './ai-project-scan.js';
|
|
8
|
+
import { stripBom } from '../json-file.js';
|
|
8
9
|
import { jsoncToJson } from '../../../framework/hooks/shared/comment-stripper.js';
|
|
9
10
|
|
|
10
11
|
const MAX_JSON_CHARS = 512 * 1024;
|
|
@@ -15,7 +16,7 @@ function readJsonSafe(file) {
|
|
|
15
16
|
try {
|
|
16
17
|
const raw = readFileSync(file, 'utf8');
|
|
17
18
|
if (raw.length > MAX_JSON_CHARS) return null;
|
|
18
|
-
const text =
|
|
19
|
+
const text = stripBom(raw);
|
|
19
20
|
try {
|
|
20
21
|
return JSON.parse(text);
|
|
21
22
|
} catch {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
+
import { readJsonFile } from '../json-file.js';
|
|
3
4
|
import { CONTRACT_FILE } from '../../../framework/hooks/shared/contract.js';
|
|
4
5
|
|
|
5
6
|
export function readMorphConfig(projectPath) {
|
|
6
7
|
const configPath = join(projectPath, CONTRACT_FILE);
|
|
7
8
|
if (!existsSync(configPath)) return null;
|
|
8
9
|
try {
|
|
9
|
-
return
|
|
10
|
+
return readJsonFile(configPath);
|
|
10
11
|
} catch {
|
|
11
12
|
return null;
|
|
12
13
|
}
|
|
@@ -3,6 +3,7 @@ import { dirname, join } from 'path';
|
|
|
3
3
|
import { atomicWriteJson } from '../../utils/atomic-json.js';
|
|
4
4
|
import { CONTRACT_FILE } from '../../../framework/hooks/shared/contract.js';
|
|
5
5
|
import { readMorphConfig } from '../config/project-config.js';
|
|
6
|
+
import { readJsonFile } from '../json-file.js';
|
|
6
7
|
import { getProjectTags, parseStacks, shouldInstall } from '../stack-filter.js';
|
|
7
8
|
import { scanRepo } from './scan.js';
|
|
8
9
|
import { contractFromScan } from './defaults.js';
|
|
@@ -12,7 +13,7 @@ const FRAMEWORK_SRC = join(import.meta.dirname, '..', '..', '..', 'framework');
|
|
|
12
13
|
// Inside config.json, not beside it: `update` wipes .morph/config/ and restores only that file.
|
|
13
14
|
export const PRINTS_KEY = '_generated';
|
|
14
15
|
|
|
15
|
-
const readJson = (path) => { try { return
|
|
16
|
+
const readJson = (path) => { try { return readJsonFile(path); } catch { return null; } };
|
|
16
17
|
|
|
17
18
|
/** What `init` would write, without writing: the dry run and the real run share it. */
|
|
18
19
|
export function planContract(root) {
|
|
@@ -63,6 +63,7 @@ export function mergeContract(config, contract, previousPrints = {}) {
|
|
|
63
63
|
out.project ??= {};
|
|
64
64
|
const p = out.project;
|
|
65
65
|
|
|
66
|
+
out.$schema ??= '../framework/schemas/config.schema.json';
|
|
66
67
|
out.contractVersion = contract.contractVersion;
|
|
67
68
|
p.stack = mergeValue('project.stack', p.stack, contract.stack, prints, report);
|
|
68
69
|
p.tags = mergeValue('project.tags', p.tags, contract.tags, prints, report);
|
package/src/lib/contract/scan.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'fs';
|
|
2
2
|
import { join, relative } from 'path';
|
|
3
3
|
import { WORKTREE_DIR_NAMES } from '../scan/worktree-dirs.js';
|
|
4
|
+
import { stripBom } from '../json-file.js';
|
|
4
5
|
|
|
5
6
|
const SKIP_DIRS = new Set([
|
|
6
7
|
'node_modules', '.git', 'bin', 'obj', 'dist', 'build', 'out', 'coverage', '.next', '.nuxt', '.morph', '.claude',
|
|
@@ -9,7 +10,7 @@ const SKIP_DIRS = new Set([
|
|
|
9
10
|
]);
|
|
10
11
|
const MAX_DEPTH = 4;
|
|
11
12
|
|
|
12
|
-
const MANIFEST = /^(package\.json|pyproject\.toml|requirements(-[\w-]+)?\.txt|components\.json|
|
|
13
|
+
const MANIFEST = /^(package\.json|pyproject\.toml|requirements(-[\w-]+)?\.txt|components\.json|(docker-)?compose(\.[\w-]+)?\.ya?ml|Dockerfile)$|\.(csproj|slnx?)$/i;
|
|
13
14
|
|
|
14
15
|
const fwd = (p) => p.replace(/\\/g, '/');
|
|
15
16
|
|
|
@@ -31,7 +32,7 @@ function walk(root) {
|
|
|
31
32
|
return found.sort();
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
const readText = (root, rel) => { try { return readFileSync(join(root, rel), 'utf8')
|
|
35
|
+
const readText = (root, rel) => { try { return stripBom(readFileSync(join(root, rel), 'utf8')); } catch { return ''; } };
|
|
35
36
|
const readJson = (root, rel) => { try { return JSON.parse(readText(root, rel)); } catch { return null; } };
|
|
36
37
|
const dirOf = (rel) => (rel.includes('/') ? rel.slice(0, rel.lastIndexOf('/')) : '.');
|
|
37
38
|
|
|
@@ -51,7 +52,7 @@ function nodePackage(root, rel) {
|
|
|
51
52
|
if (!pkg) return null;
|
|
52
53
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
53
54
|
const scripts = Object.fromEntries(Object.entries(pkg.scripts || {}).filter(([, v]) => typeof v === 'string'));
|
|
54
|
-
return { dir: dirOf(rel),
|
|
55
|
+
return { dir: dirOf(rel), deps: Object.keys(deps), scripts };
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
function dotnetProject(root, rel) {
|
|
@@ -76,7 +77,6 @@ export function scanRepo(root) {
|
|
|
76
77
|
const solutions = files.filter((f) => /\.slnx?$/i.test(f));
|
|
77
78
|
const python = files.filter((f) => /(^|\/)(pyproject\.toml|requirements(-[\w-]+)?\.txt)$/i.test(f)).map((f) => pythonProject(root, f));
|
|
78
79
|
const compose = files.filter((f) => /(^|\/)(docker-)?compose(\.[\w-]+)?\.ya?ml$/i.test(f));
|
|
79
|
-
const playwright = files.filter((f) => /(^|\/)playwright\.config\./.test(f));
|
|
80
80
|
|
|
81
81
|
for (const p of node) for (const [dep, tag] of NODE_TAGS) if (p.deps.includes(dep)) tags.add(tag);
|
|
82
82
|
for (const p of dotnet) for (const pkg of p.packages) for (const [re, tag] of DOTNET_TAGS) if (re.test(pkg)) tags.add(tag);
|
|
@@ -97,6 +97,6 @@ export function scanRepo(root) {
|
|
|
97
97
|
return {
|
|
98
98
|
stack: stacks.length ? stacks.join('+') : null,
|
|
99
99
|
tags: [...tags].sort(),
|
|
100
|
-
node, dotnet, solutions, python, compose,
|
|
100
|
+
node, dotnet, solutions, python, compose,
|
|
101
101
|
};
|
|
102
102
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
|
+
import { readJsonFile } from '../json-file.js';
|
|
4
5
|
import { readMcpConfig } from './mcp-config.js';
|
|
5
6
|
|
|
6
7
|
// User settings first, then the project's: a later file overrides, and `false` turns a plugin off.
|
|
@@ -14,7 +15,7 @@ export function readEnabledPlugins(targetPath, home = homedir()) {
|
|
|
14
15
|
for (const file of files) {
|
|
15
16
|
if (!existsSync(file)) continue;
|
|
16
17
|
try {
|
|
17
|
-
const map =
|
|
18
|
+
const map = readJsonFile(file).enabledPlugins;
|
|
18
19
|
if (!map || typeof map !== 'object') continue;
|
|
19
20
|
for (const [id, on] of Object.entries(map)) merged.set(id, on === true);
|
|
20
21
|
} catch {}
|
|
@@ -33,58 +34,55 @@ export function detectClaudeConfig(targetPath) {
|
|
|
33
34
|
|
|
34
35
|
const mcpJsonNames = new Set();
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const mcpJsonPath = join(targetPath, '.mcp.json');
|
|
38
|
+
if (existsSync(mcpJsonPath)) {
|
|
39
|
+
try {
|
|
40
|
+
const mcpJson = readJsonFile(mcpJsonPath);
|
|
41
|
+
const mcps = mcpJson.mcpServers || {};
|
|
42
|
+
for (const [name, config] of Object.entries(mcps)) {
|
|
43
|
+
result.mcpServers.push({ name, config });
|
|
44
|
+
mcpJsonNames.add(name);
|
|
45
|
+
}
|
|
46
|
+
} catch {}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const settingsPaths = [
|
|
50
|
+
join(targetPath, '.claude', 'settings.json'),
|
|
51
|
+
join(targetPath, '.claude', 'settings.local.json'),
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
for (const sp of settingsPaths) {
|
|
55
|
+
if (existsSync(sp)) {
|
|
39
56
|
try {
|
|
40
|
-
const
|
|
41
|
-
|
|
57
|
+
const settings = readJsonFile(sp);
|
|
58
|
+
// Legacy entries: .mcp.json wins; among settings files, the later one wins.
|
|
59
|
+
const mcps = settings.mcpServers || {};
|
|
42
60
|
for (const [name, config] of Object.entries(mcps)) {
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
if (mcpJsonNames.has(name)) continue;
|
|
62
|
+
const idx = result.mcpServers.findIndex(m => m.name === name);
|
|
63
|
+
if (idx >= 0) {
|
|
64
|
+
result.mcpServers[idx] = { name, config };
|
|
65
|
+
} else {
|
|
66
|
+
result.mcpServers.push({ name, config });
|
|
67
|
+
}
|
|
45
68
|
}
|
|
46
69
|
} catch {}
|
|
47
70
|
}
|
|
71
|
+
}
|
|
48
72
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
for (const sp of settingsPaths) {
|
|
55
|
-
if (existsSync(sp)) {
|
|
56
|
-
try {
|
|
57
|
-
const settings = JSON.parse(readFileSync(sp, 'utf8'));
|
|
58
|
-
// Legacy entries: .mcp.json wins; among settings files, the later one wins.
|
|
59
|
-
const mcps = settings.mcpServers || {};
|
|
60
|
-
for (const [name, config] of Object.entries(mcps)) {
|
|
61
|
-
if (mcpJsonNames.has(name)) continue;
|
|
62
|
-
const idx = result.mcpServers.findIndex(m => m.name === name);
|
|
63
|
-
if (idx >= 0) {
|
|
64
|
-
result.mcpServers[idx] = { name, config };
|
|
65
|
-
} else {
|
|
66
|
-
result.mcpServers.push({ name, config });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} catch {}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// User and local scopes live in ~/.claude.json: missing them rewrites a server the user already has into .mcp.json.
|
|
74
|
-
for (const s of readMcpConfig({ projectDir: targetPath }).servers) {
|
|
75
|
-
if (s.scope === 'project' || result.mcpServers.some(m => m.name === s.name)) continue;
|
|
76
|
-
result.mcpServers.push({ name: s.name, config: { command: s.command, args: s.args, url: s.url }, source: s.scope });
|
|
77
|
-
}
|
|
73
|
+
// User and local scopes live in ~/.claude.json: missing them rewrites a server the user already has into .mcp.json.
|
|
74
|
+
for (const s of readMcpConfig({ projectDir: targetPath }).servers) {
|
|
75
|
+
if (s.scope === 'project' || result.mcpServers.some(m => m.name === s.name)) continue;
|
|
76
|
+
result.mcpServers.push({ name: s.name, config: { command: s.command, args: s.args, url: s.url }, source: s.scope });
|
|
77
|
+
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
} catch {
|
|
79
|
+
const pluginsPath = join(homedir(), '.claude', 'plugins', 'installed_plugins.json');
|
|
80
|
+
if (existsSync(pluginsPath)) {
|
|
81
|
+
try {
|
|
82
|
+
const pluginsData = readJsonFile(pluginsPath);
|
|
83
|
+
const plugins = pluginsData.plugins || {};
|
|
84
|
+
result.plugins = Object.keys(plugins);
|
|
85
|
+
} catch {}
|
|
88
86
|
}
|
|
89
87
|
|
|
90
88
|
return result;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join, resolve } from 'node:path';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
+
import { stripBom } from '../json-file.js';
|
|
4
5
|
import { jsoncToJson } from '../../../framework/hooks/shared/comment-stripper.js';
|
|
5
6
|
import { readEnabledPlugins } from './claude-config-detector.js';
|
|
6
7
|
|
|
7
8
|
function readJsonc(file, unreadable) {
|
|
8
9
|
if (!existsSync(file)) return null;
|
|
9
10
|
try {
|
|
10
|
-
return JSON.parse(jsoncToJson(readFileSync(file, 'utf8')
|
|
11
|
+
return JSON.parse(jsoncToJson(stripBom(readFileSync(file, 'utf8'))));
|
|
11
12
|
} catch {
|
|
12
13
|
unreadable.push(file);
|
|
13
14
|
return null;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { execFileSync } from 'child_process';
|
|
2
|
-
import { minimatch } from 'minimatch';
|
|
3
2
|
|
|
4
3
|
// O predicado único de "é teste" (grafo, stack-scan, prove-red). Só três formas de pasta, porque
|
|
5
4
|
// `[^/]*[Tt]ests?/` genérico também casaria `latest/` e `contests/`.
|
|
@@ -21,13 +20,9 @@ export function git(cwd, args) {
|
|
|
21
20
|
// An agent reads these as instructions: a changed sentence is changed behaviour, whatever the extension.
|
|
22
21
|
const PROMPT_PATH = /(^|\/)(prompts?|agents?|skills?|playbooks?|personas?|instructions?|\.claude)\/|(^|\/)(CLAUDE|AGENTS|GEMINI|MORPH|SKILL|copilot-instructions)\.md$|prompt[^/]*$/i;
|
|
23
22
|
|
|
24
|
-
function
|
|
25
|
-
return PROMPT_PATH.test(path) || promptGlobs.some((g) => minimatch(path, g));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function fileClass(path, promptGlobs = []) {
|
|
23
|
+
export function fileClass(path) {
|
|
29
24
|
if (path.startsWith('.morph/')) return 'state';
|
|
30
|
-
if (
|
|
25
|
+
if (PROMPT_PATH.test(path)) return 'code';
|
|
31
26
|
if (DOC_PATH.test(path)) return 'doc';
|
|
32
27
|
if (CONFIG_PATH.test(path) && !WIDE_PATH.test(path)) return 'config';
|
|
33
28
|
return isTestPath(path) || /(^|\/)e2e\//.test(path) ? 'test' : 'code';
|