@polymorphism-tech/morph-spec 11.1.1 → 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 +13 -23
- package/docs/CHEATSHEET.md +3 -3
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +3 -1
- package/framework/MORPH.md +8 -3
- package/framework/agents.json +4 -4
- package/framework/docs/CLI.md +28 -18
- package/framework/evals/review-checklist.md +35 -18
- package/framework/hooks/README.md +18 -11
- package/framework/hooks/claude-code/core/README.md +2 -2
- package/framework/hooks/claude-code/core/chain.js +9 -25
- package/framework/hooks/claude-code/core/comment-guard.js +3 -9
- package/framework/hooks/claude-code/core/conventional-commit.js +3 -3
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +6 -6
- package/framework/hooks/claude-code/core/masked-exit.js +4 -3
- package/framework/hooks/claude-code/core/pre-bash-denylist.js +2 -2
- package/framework/hooks/claude-code/core/protect-spec-files.js +2 -4
- package/framework/hooks/claude-code/core/stack-changed.js +5 -4
- package/framework/hooks/claude-code/core/validate-completion.js +15 -12
- package/framework/hooks/shared/contract.js +22 -1
- package/framework/hooks/shared/git-paths.js +6 -0
- package/framework/hooks/shared/graph-freshness.js +3 -3
- package/framework/hooks/shared/graph-refresh.js +5 -10
- package/framework/hooks/shared/hook-response.js +1 -18
- package/framework/hooks/shared/payload-utils.js +12 -1
- package/framework/hooks/shared/phase-utils.js +4 -52
- package/framework/hooks/shared/report-progress.js +1 -1
- package/framework/mcp/registry.json +16 -32
- package/framework/rules/ai-agents-standards.md +9 -1
- package/framework/rules/dotnet-templates.md +32 -33
- package/framework/rules/gsap-standards.md +8 -0
- package/framework/rules/infrastructure-standards.md +9 -9
- package/framework/rules/mcp-standards.md +10 -0
- package/framework/rules/neon-standards.md +4 -4
- package/framework/rules/nextjs-templates.md +10 -11
- package/framework/rules/ui-design.md +2 -2
- package/framework/schemas/config.schema.json +11 -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 +6 -4
- package/framework/skills/core/morph-plan/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +5 -5
- 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 +125 -267
- package/framework/templates/README.md +52 -82
- package/framework/templates/REGISTRY.json +1 -281
- 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 +2 -2
- 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 +3 -5
- package/framework/templates/frontend/nextjs/gsap-scroll-section.tsx.hbs +13 -17
- package/framework/templates/infrastructure/docker/docker-compose.template.yml +15 -16
- package/framework/templates/infrastructure/github/README.md +10 -13
- package/package.json +7 -16
- package/src/commands/graph/build.js +2 -2
- package/src/commands/mcp/manual-setup.js +95 -0
- package/src/commands/mcp/mcp-setup.js +26 -192
- package/src/commands/project/doctor.js +48 -142
- package/src/commands/project/env.js +2 -1
- package/src/commands/project/init-contract.js +2 -2
- package/src/commands/project/init.js +34 -294
- package/src/commands/project/stack-scan.js +6 -14
- package/src/commands/project/stack-set.js +3 -1
- package/src/commands/project/standards.js +1 -2
- package/src/commands/project/update.js +87 -205
- package/src/commands/scaffold/scaffold.js +43 -5
- package/src/commands/validation/check.js +12 -10
- package/src/commands/validation/prove-red.js +61 -22
- package/src/core/paths/output-schema.js +8 -27
- package/src/core/templates/template-registry.js +8 -43
- package/src/core/templates/template-renderer.js +3 -200
- package/src/lib/ai/ai-checks.js +1 -1
- package/src/lib/ai/ai-project-scan.js +2 -5
- package/src/lib/ai/code-audit.js +3 -8
- package/src/lib/ai/registry-audit.js +2 -1
- package/src/lib/check/signals.js +25 -7
- package/src/lib/config/project-config.js +3 -2
- package/src/lib/contract/apply.js +2 -1
- package/src/lib/contract/defaults.js +2 -2
- package/src/lib/contract/merge.js +1 -0
- package/src/lib/contract/scan.js +5 -5
- package/src/lib/detectors/claude-config-detector.js +44 -98
- package/src/lib/detectors/mcp-config.js +2 -1
- package/src/lib/diff/diff-lines.js +4 -9
- package/src/lib/generators/scaffold-generator.js +5 -17
- package/src/lib/git/default-branch.js +5 -13
- package/src/lib/graph/graph-health.js +1 -1
- package/src/lib/graph/graph-loader.js +2 -1
- package/src/lib/graph/graphifyignore.js +5 -5
- package/src/lib/graph/sanitize.js +2 -2
- package/src/lib/installers/effects.js +0 -13
- package/src/lib/installers/install-manifest.js +56 -0
- package/src/lib/installers/mcp-installer.js +16 -19
- package/src/lib/installers/memory-installer.js +5 -8
- package/src/lib/installers/rules-installer.js +9 -15
- package/src/lib/installers/stack-assets.js +54 -7
- package/src/lib/installers/stack-sync.js +16 -16
- 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 +4 -3
- package/src/lib/plan/media.js +6 -6
- package/src/lib/plan/plan-parser.js +6 -11
- package/src/lib/review-reports.js +13 -18
- package/src/lib/scan/worktree-dirs.js +1 -3
- package/src/lib/specs/adr-index.js +4 -4
- package/src/lib/specs/revocations.js +3 -3
- package/src/lib/stack/stack-scan.js +4 -4
- package/src/lib/standards/registry.js +1 -1
- package/src/lib/standards/verified-against.js +3 -3
- package/src/lib/tests-audit/audit.js +3 -3
- package/src/lib/text.js +5 -0
- package/src/scripts/global-install.js +41 -19
- package/src/scripts/setup-infra.js +68 -187
- package/src/utils/agents-installer.js +21 -60
- package/src/utils/claude-md-injector.js +16 -50
- package/src/utils/claude-settings-manager.js +29 -27
- package/src/utils/file-copier.js +3 -4
- package/src/utils/hooks-installer.js +83 -62
- package/src/utils/skills-installer.js +18 -78
- package/src/utils/version-checker.js +2 -31
- package/CLAUDE.md +0 -118
- package/framework/commands/create-umbraco-lp.md +0 -37
- package/framework/commands/migrate-lp-to-umbraco.md +0 -35
- package/framework/commands/morph-apply.md +0 -14
- package/framework/hooks/shared/spawn-command.js +0 -23
- package/framework/templates/CLAUDE.md.core.guide.md +0 -29
- package/framework/templates/CLAUDE.md.core.template +0 -22
- 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/context/ARCHITECTURE.md +0 -106
- 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/commands/context/context-refresh.js +0 -63
- package/src/lib/detectors/index.js +0 -178
- package/src/lib/generators/architecture-scanner.js +0 -543
- package/src/lib/generators/settings-generator.js +0 -97
- package/src/lib/graph/god-nodes.js +0 -65
- package/src/lib/installers/templates-reconcile.js +0 -26
|
@@ -58,7 +58,7 @@ export function getInstalledMcps(existingServers, registry, enabledPlugins = [])
|
|
|
58
58
|
return installed;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
function checkPrerequisites(mcpEntry) {
|
|
62
62
|
const prereqs = mcpEntry.install?.prerequisites || [];
|
|
63
63
|
const results = [];
|
|
64
64
|
|
|
@@ -83,29 +83,26 @@ export function isRemoteMcp(config) {
|
|
|
83
83
|
return config.type === 'http' || config.url != null;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
|
|
93
|
-
command: 'cmd',
|
|
94
|
-
args: ['/c', 'npx', ...(config.args || [])]
|
|
95
|
-
};
|
|
86
|
+
const WINDOWS_SHIMS = new Set(['npx', 'npm', 'pnpm', 'yarn']);
|
|
87
|
+
|
|
88
|
+
// These are `.cmd` shims on Windows, which Claude Code cannot spawn without a shell. `.mcp.json` therefore
|
|
89
|
+
// carries the form of the OS that ran the install: there is no single form both sides can start.
|
|
90
|
+
export function platformConfig(config, platform = process.platform) {
|
|
91
|
+
if (platform !== 'win32' || !WINDOWS_SHIMS.has(config.command)) return { ...config };
|
|
92
|
+
return { ...config, command: 'cmd', args: ['/c', config.command, ...(config.args ?? [])] };
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
export async function installAutoMcps(targetPath, mcpsToInstall) {
|
|
95
|
+
export async function installAutoMcps(targetPath, mcpsToInstall, platform = process.platform) {
|
|
99
96
|
const servers = {};
|
|
100
97
|
|
|
101
98
|
for (const [name, entry] of Object.entries(mcpsToInstall)) {
|
|
102
|
-
let config =
|
|
99
|
+
let config = platformConfig(entry.install.config, platform);
|
|
103
100
|
if (!isRemoteMcp(config)) {
|
|
104
101
|
if (config.env && Object.values(config.env).every(v => !v)) {
|
|
105
102
|
delete config.env;
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
|
-
servers[name] =
|
|
105
|
+
servers[name] = config;
|
|
109
106
|
}
|
|
110
107
|
|
|
111
108
|
return installMcpServers(targetPath, servers);
|
|
@@ -130,7 +127,7 @@ export function installCompanionSkills(mcpsInstalled, exec = execSync, cwd = pro
|
|
|
130
127
|
}
|
|
131
128
|
|
|
132
129
|
export async function installMcpWithCredentials(targetPath, name, mcpEntry, credentialValues) {
|
|
133
|
-
const config =
|
|
130
|
+
const config = platformConfig(mcpEntry.install.config);
|
|
134
131
|
config.env = { ...config.env, ...credentialValues };
|
|
135
132
|
return installMcpServers(targetPath, { [name]: config });
|
|
136
133
|
}
|
|
@@ -150,12 +147,12 @@ export function generateSetupInstructions(name, mcpEntry) {
|
|
|
150
147
|
return {
|
|
151
148
|
configSnippet,
|
|
152
149
|
credentialUrls,
|
|
153
|
-
cliCommand: setupGuide || `claude mcp add --transport http ${name} ${config.url}`,
|
|
150
|
+
cliCommand: setupGuide || `claude mcp add --transport http --scope project ${name} ${config.url}`,
|
|
154
151
|
isRemote: true
|
|
155
152
|
};
|
|
156
153
|
}
|
|
157
154
|
|
|
158
|
-
const snippetConfig =
|
|
155
|
+
const snippetConfig = platformConfig(config);
|
|
159
156
|
if (credentials.length > 0) {
|
|
160
157
|
snippetConfig.env = {};
|
|
161
158
|
for (const cred of credentials) {
|
|
@@ -231,7 +228,7 @@ export function formatMcpStatusTable(orchestration, justInstalled = {}) {
|
|
|
231
228
|
|
|
232
229
|
const { autoInstallable, alreadyInstalled, needsManualSetup, notRelevant, prerequisitesMissing, registry } = orchestration;
|
|
233
230
|
|
|
234
|
-
for (const
|
|
231
|
+
for (const name of Object.keys(justInstalled)) {
|
|
235
232
|
const mcpEntry = registry.mcps[name];
|
|
236
233
|
rows.push({
|
|
237
234
|
name,
|
|
@@ -240,7 +237,7 @@ export function formatMcpStatusTable(orchestration, justInstalled = {}) {
|
|
|
240
237
|
});
|
|
241
238
|
}
|
|
242
239
|
|
|
243
|
-
for (const
|
|
240
|
+
for (const name of Object.keys(autoInstallable)) {
|
|
244
241
|
if (justInstalled[name]) continue;
|
|
245
242
|
rows.push({
|
|
246
243
|
name,
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
// The path encoding mirrors Claude Code's scheme (slashes and colons become dashes);
|
|
2
|
-
// MORPH_MEMORY_ROOT overrides the root in tests.
|
|
3
|
-
|
|
4
1
|
import fs from 'fs-extra';
|
|
5
2
|
import { join } from 'path';
|
|
6
3
|
import { homedir } from 'os';
|
|
7
4
|
|
|
5
|
+
// Claude Code names the project folder by turning every non-alphanumeric character into a dash.
|
|
6
|
+
export const encodeProjectPath = (projectPath) => projectPath.replace(/[^A-Za-z0-9]/g, '-');
|
|
7
|
+
|
|
8
8
|
function getMemoryRoot(projectPath) {
|
|
9
9
|
if (process.env.MORPH_MEMORY_ROOT) return process.env.MORPH_MEMORY_ROOT;
|
|
10
|
-
|
|
11
|
-
const encoded = projectPath.replace(/[:\\/]/g, '-').replace(/^-+/, '');
|
|
12
|
-
return join(homedir(), '.claude', 'projects', encoded, 'memory');
|
|
10
|
+
return join(homedir(), '.claude', 'projects', encodeProjectPath(projectPath), 'memory');
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
function projectMemoryContent(info) {
|
|
@@ -54,8 +52,7 @@ metadata:
|
|
|
54
52
|
|
|
55
53
|
# morph-spec context locations
|
|
56
54
|
|
|
57
|
-
- \`.morph/context/
|
|
58
|
-
- \`.morph/context/design-system.md\` — design tokens and components (source of truth)
|
|
55
|
+
- \`.morph/context/design-system.md\` — design tokens and components, when the project has a UI
|
|
59
56
|
- \`.morph/specs/adrs/\` — project-scope decisions, written by plan-check
|
|
60
57
|
- \`.morph/framework/CLI.md\` — the CLI reference, one section per command
|
|
61
58
|
- \`.morph/framework/evals/review-checklist.md\` — what the review personas check (SHIP/FIX + evidence-typed blockers)
|
|
@@ -2,6 +2,7 @@ import { readFileSync, readdirSync } from 'fs';
|
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { parseStacks, shouldInstall } from '../stack-filter.js';
|
|
4
4
|
import { realEffects } from './effects.js';
|
|
5
|
+
import { pruneOwned } from './install-manifest.js';
|
|
5
6
|
|
|
6
7
|
export const MAF_TAG = 'maf';
|
|
7
8
|
export const MAF_RULE = 'ai-agents-standards.md';
|
|
@@ -31,27 +32,20 @@ export function installRuleFile(rulesSrc, rulesDest, file, projectTags, fx = rea
|
|
|
31
32
|
else fx.writeFile(to, desired);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
export function installRulesForStack(rulesSrc, rulesDest, projectTags, fx = realEffects()) {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
35
|
+
/** `previous`: the rules the manifest records. `prune: false` when the caller already emptied `rulesDest`. */
|
|
36
|
+
export function installRulesForStack(rulesSrc, rulesDest, projectTags, fx = realEffects(), { previous = [], prune = true } = {}) {
|
|
37
|
+
const shipped = readdirSync(rulesSrc).filter(f => f.endsWith('.md'));
|
|
38
|
+
const names = [];
|
|
38
39
|
|
|
39
|
-
for (const file of
|
|
40
|
+
for (const file of shipped) {
|
|
40
41
|
const content = readFileSync(join(rulesSrc, file), 'utf-8');
|
|
41
42
|
if (shouldInstall(parseStacks(content), projectTags)) {
|
|
42
43
|
installRuleFile(rulesSrc, rulesDest, file, projectTags, fx);
|
|
43
|
-
|
|
44
|
+
names.push(file);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
if (!fx.dryRun) {
|
|
49
|
-
for (const file of readdirSync(rulesDest).filter(f => f.endsWith('.md'))) {
|
|
50
|
-
if (!installed.has(file)) {
|
|
51
|
-
fx.remove(join(rulesDest, file));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
48
|
+
if (prune) pruneOwned(rulesDest, { previous, shipped, installed: names, fx });
|
|
55
49
|
|
|
56
|
-
return { installed:
|
|
50
|
+
return { installed: names.length, names };
|
|
57
51
|
}
|
|
@@ -1,17 +1,64 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from 'fs';
|
|
1
2
|
import { join } from 'path';
|
|
2
3
|
import { installRulesForStack } from './rules-installer.js';
|
|
3
|
-
import {
|
|
4
|
+
import { realEffects } from './effects.js';
|
|
5
|
+
import { ASSET_DIRS, pruneOwned, readManifest, writeManifest } from './install-manifest.js';
|
|
6
|
+
import { parseStacks, shouldInstall } from '../stack-filter.js';
|
|
4
7
|
import { installSkills } from '../../utils/skills-installer.js';
|
|
5
8
|
import { installAgents } from '../../utils/agents-installer.js';
|
|
9
|
+
import { syncAssetDeny } from '../../utils/hooks-installer.js';
|
|
6
10
|
|
|
7
11
|
const FRAMEWORK_SRC = join(import.meta.dirname, '..', '..', '..', 'framework');
|
|
8
12
|
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
13
|
+
/** `previous`: the commands the manifest records. `prune: false` when the caller already emptied `commandsDest`. */
|
|
14
|
+
export function installCommandsForStack(commandsSrc, commandsDest, projectTags, fx = realEffects(), { previous = [], prune = true } = {}) {
|
|
15
|
+
const shipped = readdirSync(commandsSrc).filter(f => f.endsWith('.md'));
|
|
16
|
+
const names = [];
|
|
17
|
+
for (const file of shipped) {
|
|
18
|
+
if (!shouldInstall(parseStacks(readFileSync(join(commandsSrc, file), 'utf-8')), projectTags)) continue;
|
|
19
|
+
fx.copyFile(join(commandsSrc, file), join(commandsDest, file));
|
|
20
|
+
names.push(file);
|
|
21
|
+
}
|
|
22
|
+
if (prune) pruneOwned(commandsDest, { previous, shipped, installed: names, fx });
|
|
23
|
+
return { installed: names.length, names };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Rules, commands, skills and agents filtered by `stacks:`; an empty tag list installs the universal ones.
|
|
28
|
+
* Removes only what morph-spec owns (`pruneOwned`), then the manifest becomes what this run installed.
|
|
29
|
+
* `manifest`: the one read before anything was deleted. `createManifest`: a full install or `update`.
|
|
30
|
+
*/
|
|
31
|
+
export async function installAssetsForTags(targetPath, tags, {
|
|
32
|
+
frameworkSrc = FRAMEWORK_SRC, fx = realEffects(), manifest = readManifest(targetPath), prune = true, createManifest = false,
|
|
33
|
+
} = {}) {
|
|
34
|
+
const claudeDir = join(targetPath, '.claude');
|
|
35
|
+
const owned = (dir) => ({ previous: manifest?.[dir] ?? [], prune });
|
|
36
|
+
const results = {};
|
|
37
|
+
for (const [dir, install] of [['rules', installRulesForStack], ['commands', installCommandsForStack]]) {
|
|
38
|
+
fx.ensureDir(join(claudeDir, dir));
|
|
39
|
+
results[dir] = install(join(frameworkSrc, dir), join(claudeDir, dir), tags, fx, owned(dir));
|
|
40
|
+
}
|
|
41
|
+
results.skills = await installSkills(targetPath, { projectTags: tags, fx, ...owned('skills') });
|
|
42
|
+
results.agents = await installAgents(targetPath, frameworkSrc, { projectTags: tags, fx, ...owned('agents') });
|
|
43
|
+
|
|
44
|
+
// An install with no manifest stays without one here: `update` still owes it the last whole-folder
|
|
45
|
+
// clean, and a manifest born from a partial reinstall would turn what is left over into the user's.
|
|
46
|
+
const written = manifest || createManifest
|
|
47
|
+
? writeManifest(targetPath, Object.fromEntries(ASSET_DIRS.map((dir) => [dir, results[dir].names])), fx)
|
|
48
|
+
: null;
|
|
49
|
+
return { ...results, manifest: written };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** For the paths that reinstall the assets and not the hooks: the per-asset deny follows the new manifest. */
|
|
53
|
+
export async function refreshAssetsForTags(targetPath, tags, options = {}) {
|
|
54
|
+
const result = await installAssetsForTags(targetPath, tags, options);
|
|
55
|
+
if (result.manifest) syncAssetDeny(targetPath, { manifest: result.manifest, fx: options.fx });
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The one path init and stack-set share; a project with no tag keeps what setup-infra installed. */
|
|
60
|
+
export async function installStackAssets(targetPath, stackTags, options) {
|
|
11
61
|
if (stackTags.length === 0) return false;
|
|
12
|
-
|
|
13
|
-
installCommandsForStack(join(frameworkSrc, 'commands'), join(targetPath, '.claude', 'commands'), stackTags);
|
|
14
|
-
await installSkills(targetPath, { projectTags: stackTags });
|
|
15
|
-
await installAgents(targetPath, frameworkSrc, { projectTags: stackTags });
|
|
62
|
+
await refreshAssetsForTags(targetPath, stackTags, options);
|
|
16
63
|
return true;
|
|
17
64
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
-
import { detectProject } from '../detectors/index.js';
|
|
4
3
|
import { scanRepo } from '../contract/scan.js';
|
|
5
4
|
import { getProjectTags, parseStacks, shouldInstall } from '../stack-filter.js';
|
|
6
5
|
import { WORKTREE_DIR_NAMES } from '../scan/worktree-dirs.js';
|
|
6
|
+
import { readJsonFile } from '../json-file.js';
|
|
7
7
|
import { createEffects } from './effects.js';
|
|
8
|
+
import { addToManifest } from './install-manifest.js';
|
|
9
|
+
import { syncAssetDeny } from '../../utils/hooks-installer.js';
|
|
8
10
|
import { MAF_RULE, MAF_TAG, installRuleFile, ruleContentFor } from './rules-installer.js';
|
|
9
11
|
|
|
10
12
|
const COMPOSE_CANDIDATES = ['compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml'];
|
|
11
13
|
|
|
12
14
|
function resolveComposeFile(cwd, config) {
|
|
13
|
-
const configured = config?.e2e?.composeFile;
|
|
15
|
+
const configured = config?.project?.deps?.compose ?? config?.e2e?.composeFile;
|
|
14
16
|
if (configured) return existsSync(join(cwd, configured)) ? configured : null;
|
|
15
17
|
return COMPOSE_CANDIDATES.find((name) => existsSync(join(cwd, name))) ?? null;
|
|
16
18
|
}
|
|
@@ -32,7 +34,7 @@ function ruleFiles(rulesSrc) {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/** The tags some rule's `stacks:` names: the only detected tags worth persisting. */
|
|
35
|
-
|
|
37
|
+
function ruleTags(rulesSrc = RULES_SRC) {
|
|
36
38
|
return new Set(ruleFiles(rulesSrc).flatMap(({ stacks }) => stacks).filter((s) => s !== '*'));
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -56,14 +58,12 @@ function walk(root, visit) {
|
|
|
56
58
|
|
|
57
59
|
/**
|
|
58
60
|
* `tags`: what the files show, for picking rules. `persist`: the subset safe to write into config.json —
|
|
59
|
-
* `docker` only with a compose file
|
|
61
|
+
* `docker` only with a compose file: a declared `docker` without one has no dependencies to bring up.
|
|
60
62
|
*/
|
|
61
63
|
export function detectStackTags(projectDir, { config = null, rulesSrc = RULES_SRC } = {}) {
|
|
62
64
|
const found = new Set();
|
|
63
|
-
const
|
|
64
|
-
for (const t of
|
|
65
|
-
for (const t of structure.integrations) found.add(t);
|
|
66
|
-
for (const t of scanRepo(projectDir).tags) found.add(t);
|
|
65
|
+
const scan = scanRepo(projectDir);
|
|
66
|
+
for (const t of [...(scan.stack ?? '').split('+'), ...scan.tags]) found.add(t);
|
|
67
67
|
|
|
68
68
|
walk(projectDir, (name, path) => {
|
|
69
69
|
if (name.endsWith('.csproj') || name.endsWith('.sln') || name.endsWith('.slnx')) found.add('dotnet');
|
|
@@ -101,10 +101,6 @@ export function mergeDetectedTags(config, tags) {
|
|
|
101
101
|
|
|
102
102
|
const configPathOf = (projectDir) => join(projectDir, '.morph', 'config', 'config.json');
|
|
103
103
|
|
|
104
|
-
function readConfig(path) {
|
|
105
|
-
return JSON.parse(readFileSync(path, 'utf-8').replace(/^/, ''));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
104
|
function missingRules(projectDir, tags, rulesSrc) {
|
|
109
105
|
const rulesDest = join(projectDir, '.claude', 'rules');
|
|
110
106
|
const missing = [];
|
|
@@ -140,7 +136,7 @@ export function syncStackRules(projectDir, {
|
|
|
140
136
|
const configPath = configPathOf(projectDir);
|
|
141
137
|
if (!existsSync(configPath)) return { ...NOOP };
|
|
142
138
|
let config;
|
|
143
|
-
try { config =
|
|
139
|
+
try { config = readJsonFile(configPath); } catch {
|
|
144
140
|
warnOnce(log, `${configPath} ilegível — regras de stack não sincronizadas`);
|
|
145
141
|
return { ...NOOP };
|
|
146
142
|
}
|
|
@@ -159,6 +155,10 @@ export function syncStackRules(projectDir, {
|
|
|
159
155
|
installRuleFile(rulesSrc, rulesDest, file, tags, fx);
|
|
160
156
|
log(` + .claude/rules/${file} (stack: ${tags.join('+')})`);
|
|
161
157
|
}
|
|
158
|
+
if (missing.length) {
|
|
159
|
+
const manifest = addToManifest(projectDir, 'rules', missing, fx);
|
|
160
|
+
if (manifest) syncAssetDeny(projectDir, { manifest, fx });
|
|
161
|
+
}
|
|
162
162
|
return { added: missing, updated: stale, tags, configChanged: merged.changed };
|
|
163
163
|
} catch (err) {
|
|
164
164
|
warnOnce(log, err?.message ?? String(err));
|
|
@@ -191,9 +191,9 @@ export function setProjectStack(projectDir, stack, {
|
|
|
191
191
|
return { error: `tag desconhecida: ${unknown.join(', ') || '(stack vazia)'}. Stack: ${known.stacks.join(' | ')} (unidas por +); --with: ${known.integrations.join(', ')}` };
|
|
192
192
|
}
|
|
193
193
|
let config;
|
|
194
|
-
try { config =
|
|
194
|
+
try { config = readJsonFile(configPath); } catch { return { error: `${configPath} ilegível` }; }
|
|
195
195
|
if (integrations.includes('docker') && !resolveComposeFile(projectDir, config)) {
|
|
196
|
-
return { error: 'docker sem compose
|
|
196
|
+
return { error: 'docker sem compose não sobe as dependências dos testes: crie o compose primeiro (o plan-check e o update declaram docker quando ele existir)' };
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
const project = { ...(config.project ?? {}), stack: stackTags.join('+') };
|
|
@@ -209,7 +209,7 @@ export function stackRuleGaps(projectDir, { rulesSrc = RULES_SRC } = {}) {
|
|
|
209
209
|
try {
|
|
210
210
|
const configPath = configPathOf(projectDir);
|
|
211
211
|
if (!existsSync(configPath)) return null;
|
|
212
|
-
const config =
|
|
212
|
+
const config = readJsonFile(configPath);
|
|
213
213
|
const stack = config?.project?.stack;
|
|
214
214
|
const detected = detectStackTags(projectDir, { config, rulesSrc });
|
|
215
215
|
const tags = [...new Set([...getProjectTags(config), ...detected.tags])];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process';
|
|
2
|
-
import { existsSync
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { readJsonFile } from '../json-file.js';
|
|
4
5
|
import { PACKAGE_LOCATIONS } from '../../../framework/hooks/shared/frontend-locations.js';
|
|
5
6
|
import { filterByStack, installAutoMcps, installCompanionSkills, orchestrateMcpSetup } from './mcp-installer.js';
|
|
6
7
|
|
|
@@ -11,7 +12,7 @@ function componentsJsonFiles(targetPath, frontendPath) {
|
|
|
11
12
|
|
|
12
13
|
function missingRegistries(file, wanted) {
|
|
13
14
|
let json;
|
|
14
|
-
try { json =
|
|
15
|
+
try { json = readJsonFile(file); } catch { return null; }
|
|
15
16
|
const current = json.registries ?? {};
|
|
16
17
|
const missing = Object.entries(wanted).filter(([name]) => !(name in current));
|
|
17
18
|
return missing.length > 0 ? { json, missing } : null;
|
|
@@ -24,7 +25,7 @@ function missingRegistries(file, wanted) {
|
|
|
24
25
|
export async function syncStackTooling(targetPath, options) {
|
|
25
26
|
const { config, existingMcps = [], enabledPlugins = [], fx, exec = execSync } = options;
|
|
26
27
|
const stack = config?.project?.stack ?? '';
|
|
27
|
-
const integrations = config?.project?.integrations ?? [];
|
|
28
|
+
const integrations = [...new Set([...(config?.project?.integrations ?? []), ...(config?.project?.tags ?? [])])];
|
|
28
29
|
const result = { mcps: [], skills: [], skillsFailed: [], registries: [] };
|
|
29
30
|
|
|
30
31
|
const { registry, autoInstallable } = orchestrateMcpSetup(targetPath, stack, existingMcps, { autoOnly: true, integrations, enabledPlugins });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
|
|
3
|
+
// PowerShell 5.1's `Out-File -Encoding utf8` writes a BOM that JSON.parse rejects.
|
|
4
|
+
export const stripBom = (text) => text.replace(/^/, '');
|
|
5
|
+
|
|
6
|
+
/** Throws on a missing file or invalid JSON: the caller decides what an unreadable file means. */
|
|
7
|
+
export function readJsonFile(path) {
|
|
8
|
+
return JSON.parse(stripBom(readFileSync(path, 'utf8')));
|
|
9
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** The inline justification that lets a criterion talk about an artifact on purpose. */
|
|
2
2
|
export const ARTIFACT_MARKER_RE = /por\s+que\s+artefato\s*:/i;
|
|
3
3
|
|
|
4
|
-
// Node
|
|
4
|
+
// Node 22 has no inline `(?i:…)` modifier, and the rest of the regex must stay case-sensitive.
|
|
5
5
|
const anyCase = (word) => [...word].map((c) => {
|
|
6
6
|
const lo = c.toLowerCase();
|
|
7
7
|
const up = c.toUpperCase();
|
package/src/lib/plan/checks.js
CHANGED
|
@@ -3,16 +3,17 @@ import { frozenBody } from '../../../framework/hooks/shared/errata.js';
|
|
|
3
3
|
import { findArtifactTerms } from './artifact-vocabulary.js';
|
|
4
4
|
import { mediaCitationError } from './media.js';
|
|
5
5
|
import { scenarioLabel, WORK_NAME } from '../../../framework/hooks/shared/owner-words.js';
|
|
6
|
+
import { foldAccents } from '../text.js';
|
|
6
7
|
import { PROOF_KINDS, RISK_KINDS, REWORK_RUNGS, REUSE_VERDICTS, ADR_SCOPES, SECTIONS, CONFLICTS_HEADING } from './plan-parser.js';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const CHECKS_VERSION = 1;
|
|
9
10
|
|
|
10
11
|
/** sha256 of the plan without its errata: appending a correction never invalidates the extracted checks. */
|
|
11
12
|
export function planHash(text) {
|
|
12
13
|
return createHash('sha256').update(frozenBody(text), 'utf8').digest('hex');
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
const foldRisk = (s) => s.
|
|
16
|
+
const foldRisk = (s) => foldAccents(s.replace(/`/g, '')).trim();
|
|
16
17
|
const RISK_BY_FOLD = new Map(RISK_KINDS.map((r) => [foldRisk(r), r]));
|
|
17
18
|
const RUNG_BY_FOLD = new Map(REWORK_RUNGS.map((r) => [foldRisk(r), r]));
|
|
18
19
|
const canonicalRung = (rung) => (rung === null ? null : RUNG_BY_FOLD.get(foldRisk(rung)) ?? false);
|
|
@@ -162,4 +163,4 @@ export function buildChecks(feature, text, plan) {
|
|
|
162
163
|
|
|
163
164
|
// The scenarios came from the issue, or the agent proposed them because the issue had none: then someone approves first.
|
|
164
165
|
const sourceOf = (text) => (/^propost/i.test(String(text ?? '').trim()) ? 'proposta' : text ? 'issue' : null);
|
|
165
|
-
const summaryOf = (plan) => ({ name: plan.summary?.name ?? null, after: plan.summary?.after ?? null, source: sourceOf(plan.summary?.source) });
|
|
166
|
+
const summaryOf = (plan) => ({ name: plan.summary?.name ?? null, after: plan.summary?.after ?? null, watch: plan.summary?.watch ?? [], source: sourceOf(plan.summary?.source) });
|
package/src/lib/plan/media.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import { foldAccents } from '../text.js';
|
|
2
|
+
|
|
3
|
+
const MEDIA_STANDARD_IDS = [
|
|
2
4
|
'ai-agents-modalities-image-gen',
|
|
3
5
|
'ai-agents-media-video',
|
|
4
6
|
'ai-agents-media-pipeline',
|
|
5
7
|
];
|
|
6
8
|
|
|
7
9
|
// O plano escreve o standard pelo id ou pelo caminho (com ou sem `framework/`/`standards/`).
|
|
8
|
-
|
|
10
|
+
function standardIdOf(value) {
|
|
9
11
|
return String(value ?? '').trim().replace(/\\/g, '/')
|
|
10
12
|
.replace(/^(\.morph\/)?(framework\/)?(standards\/)?/, '')
|
|
11
13
|
.replace(/\.md$/, '')
|
|
12
14
|
.replace(/\//g, '-');
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
function featureGeneratesMedia(planText) {
|
|
16
18
|
if (typeof planText !== 'string') return false;
|
|
17
19
|
const tokens = new Set(planText.split(/[\s`'",;:()[\]|]+/).map((t) => standardIdOf(t.replace(/[.!?]+$/, ''))));
|
|
18
20
|
return MEDIA_STANDARD_IDS.some((id) => tokens.has(id));
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
const fold = (s) => s.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase();
|
|
22
|
-
|
|
23
23
|
// Vocabulário estreito de propósito: "imagem" sozinha (upload, avatar) não é mídia gerada.
|
|
24
24
|
const GENERATED_MEDIA_RE = new RegExp([
|
|
25
25
|
String.raw`\b(gera[rd]?[ao]?s?|geracao|generat\w*)\b[^.\n]{0,40}\b(imagem|imagens|images?|videos?|ilustrac\w*|thumbnails?)\b`,
|
|
@@ -33,7 +33,7 @@ const NO_MEDIA_RE = /^\s*[-*]?\s*\**midia gerada:?\**:?\s*nao\b/m;
|
|
|
33
33
|
/** Plano que fala em gerar imagem ou vídeo e não cita o standard deixaria o guardrail desarmado em silêncio. */
|
|
34
34
|
export function mediaCitationError(planText) {
|
|
35
35
|
if (typeof planText !== 'string' || featureGeneratesMedia(planText)) return null;
|
|
36
|
-
const text =
|
|
36
|
+
const text = foldAccents(planText);
|
|
37
37
|
if (NO_MEDIA_RE.test(text)) return null;
|
|
38
38
|
const hit = GENERATED_MEDIA_RE.exec(text);
|
|
39
39
|
if (!hit) return null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { tableCells, isTableLine, SEPARATOR_ROW_RE } from '../specs/gfm-table.js';
|
|
2
|
+
import { foldAccents } from '../text.js';
|
|
2
3
|
import { ARTIFACT_MARKER_RE } from './artifact-vocabulary.js';
|
|
3
4
|
import { markdownLines } from '../../../framework/hooks/shared/errata.js';
|
|
4
5
|
|
|
@@ -36,7 +37,7 @@ const TITLE_RE = /^\s*t[ií]tulo\s*:\s*(.*?)\s*$/i;
|
|
|
36
37
|
const SUMMARY_RE = /^\s*[-*]\s+\**\s*(nome|tipo|hoje|depois|origem|aten[çc][ãa]o)\s*\**\s*:\s*\**\s*(.+?)\s*$/i;
|
|
37
38
|
const SUMMARY_KEYS = { nome: 'name', tipo: 'kind', hoje: 'today', depois: 'after', origem: 'source' };
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
const ADR_PLAIN = {
|
|
40
41
|
decided: /^\s*\*\*Decidimos:\*\*\s*(.+?)\s*$/im,
|
|
41
42
|
why: /^\s*\*\*Por qu[eê]:\*\*\s*(.+?)\s*$/im,
|
|
42
43
|
cost: /^\s*\*\*O que custa:\*\*\s*(.+?)\s*$/im,
|
|
@@ -44,7 +45,7 @@ export const ADR_PLAIN = {
|
|
|
44
45
|
const WHY_RE =new RegExp(String.raw`^\s*>\s*` + ARTIFACT_MARKER_RE.source + String.raw`\s*(.*?)\s*$`, 'i');
|
|
45
46
|
const SCOPE_RE = /^\s*\*\*Alcance:\*\*\s*(.*?)\s*$/i;
|
|
46
47
|
|
|
47
|
-
const fold = (s) => s
|
|
48
|
+
const fold = (s) => foldAccents(s).trim();
|
|
48
49
|
|
|
49
50
|
function splitSections(lines) {
|
|
50
51
|
const sections = [];
|
|
@@ -150,12 +151,11 @@ function parseReuse(lines) {
|
|
|
150
151
|
line: line.n,
|
|
151
152
|
});
|
|
152
153
|
}
|
|
153
|
-
return
|
|
154
|
+
return rows;
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
function parseSummary(lines) {
|
|
157
158
|
const found = { name: null, kind: null, today: null, after: null, source: null, watch: [] };
|
|
158
|
-
const rest = [];
|
|
159
159
|
let open = null;
|
|
160
160
|
for (const line of lines) {
|
|
161
161
|
const m = !line.fenced && SUMMARY_RE.exec(line.raw);
|
|
@@ -168,9 +168,8 @@ function parseSummary(lines) {
|
|
|
168
168
|
}
|
|
169
169
|
if (open && /^\s+\S/.test(line.raw)) { open.text += ` ${line.raw.trim()}`; continue; }
|
|
170
170
|
open = null;
|
|
171
|
-
rest.push(line.raw);
|
|
172
171
|
}
|
|
173
|
-
return { name: found.name?.text ?? null, kind: found.kind?.text.trim().toLowerCase() ?? null, today: found.today?.text ?? null, after: found.after?.text ?? null, source: found.source?.text ?? null, watch: found.watch.map((w) => w.text)
|
|
172
|
+
return { name: found.name?.text ?? null, kind: found.kind?.text.trim().toLowerCase() ?? null, today: found.today?.text ?? null, after: found.after?.text ?? null, source: found.source?.text ?? null, watch: found.watch.map((w) => w.text) };
|
|
174
173
|
}
|
|
175
174
|
|
|
176
175
|
function parseDefaults(lines) {
|
|
@@ -215,7 +214,6 @@ export function parsePlan(text) {
|
|
|
215
214
|
}
|
|
216
215
|
const body = (key) => byName.get(key)?.lines ?? [];
|
|
217
216
|
const decisions = parseDecisions(body('decisions'));
|
|
218
|
-
const reuse = parseReuse(body('reuse'));
|
|
219
217
|
const errata = byName.get('errata');
|
|
220
218
|
|
|
221
219
|
return {
|
|
@@ -224,14 +222,11 @@ export function parsePlan(text) {
|
|
|
224
222
|
scenarios: parseScenarios(body('scenarios')),
|
|
225
223
|
adrs: decisions.adrs,
|
|
226
224
|
conflicts: decisions.conflicts,
|
|
227
|
-
reuse: reuse
|
|
228
|
-
reuseHeader: reuse.header,
|
|
225
|
+
reuse: parseReuse(body('reuse')),
|
|
229
226
|
summary: parseSummary(body('summary')),
|
|
230
227
|
defaults: parseDefaults(body('defaults')),
|
|
231
228
|
states: parseStates(body('states')),
|
|
232
229
|
flow: parseStates(body('flow')),
|
|
233
|
-
text: Object.fromEntries(Object.keys(SECTIONS).map((k) => [k, body(k).map((l) => l.raw).join('\n').trim()])),
|
|
234
|
-
errata: errata ? errata.lines.map((l) => l.raw).join('\n').trim() : null,
|
|
235
230
|
sectionsAfterErrata: errata ? sections.filter((s) => s.line > errata.line).map((s) => s.name) : [],
|
|
236
231
|
};
|
|
237
232
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { OUTPUT_SCHEMA } from '../core/paths/output-schema.js';
|
|
4
|
+
import { tableCells } from './specs/gfm-table.js';
|
|
5
|
+
import { foldAccents } from './text.js';
|
|
4
6
|
import { PARTIAL_MARKER } from '../../framework/hooks/shared/report-progress.js';
|
|
5
7
|
|
|
6
8
|
export const VERDICT_TOKEN = '**Verdict:**';
|
|
7
9
|
export const REVIEWED_SHA_TOKEN = '**Reviewed-SHA:**';
|
|
8
10
|
export const VERDICTS = ['SHIP', 'FIX'];
|
|
9
11
|
export const BLOCKER_TYPES = ['check', 'teste', 'regressao', 'seguranca', 'escopo', 'arquitetura', 'performance', 'irreversivel'];
|
|
10
|
-
|
|
12
|
+
const CHECK_STATUSES = ['PROVADO', 'NÃO PROVADO', 'FALHA'];
|
|
11
13
|
|
|
12
14
|
export const REVIEW_ROLES = {
|
|
13
15
|
verifier: { output: 'verifierReport', persona: 'morph-verifier' },
|
|
@@ -16,7 +18,7 @@ export const REVIEW_ROLES = {
|
|
|
16
18
|
};
|
|
17
19
|
const ROLE_ORDER = Object.keys(REVIEW_ROLES);
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
const reviewFileName = (role) => OUTPUT_SCHEMA[REVIEW_ROLES[role].output].filename;
|
|
20
22
|
|
|
21
23
|
// Append-only: uma reavaliação acrescenta ao fim, e vale o ÚLTIMO token/seção.
|
|
22
24
|
const VERDICT_RE = /\*\*Verdict:\*\*\s*([A-Za-z]+)/g;
|
|
@@ -39,13 +41,13 @@ function lastSectionBody(text, re) {
|
|
|
39
41
|
return bodies.length ? bodies[bodies.length - 1] : null;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
const normalize = (s) => String(s ?? '')
|
|
44
|
+
const normalize = (s) => foldAccents(String(s ?? '')).replace(/\s+/g, ' ').trim();
|
|
43
45
|
const cleanId = (s) => String(s ?? '').replace(/[*`_]/g, '').trim().toUpperCase();
|
|
44
46
|
|
|
45
47
|
const isSeparator = (cells) => cells.every((c) => /^:?-{2,}:?$/.test(c) || c === '');
|
|
46
48
|
|
|
47
49
|
// A status table a confirmation lists under "Nenhum." is skipped; any other header off the
|
|
48
|
-
// contract still counts, so its rows land in `untyped` and
|
|
50
|
+
// contract still counts, so its rows land in `untyped` and `reviewSignals` reads them as `revisao-fix`.
|
|
49
51
|
const isStatusHeader = (header) => /^(situacao|status)$/.test(normalize(header[1]));
|
|
50
52
|
|
|
51
53
|
function tableRows(body, keepHeader = () => true) {
|
|
@@ -54,10 +56,9 @@ function tableRows(body, keepHeader = () => true) {
|
|
|
54
56
|
const lines = body.split(/\r?\n/);
|
|
55
57
|
for (const [i, line] of lines.entries()) {
|
|
56
58
|
if (!/^\s*\|/.test(line)) { skipping = false; continue; }
|
|
57
|
-
const cells = line
|
|
59
|
+
const cells = tableCells(line);
|
|
58
60
|
if (isSeparator(cells)) continue;
|
|
59
|
-
|
|
60
|
-
if (next && /^\s*\|/.test(lines[i + 1]) && isSeparator(next) && !skipping) {
|
|
61
|
+
if (/^\s*\|/.test(lines[i + 1] ?? '') && isSeparator(tableCells(lines[i + 1])) && !skipping) {
|
|
61
62
|
skipping = !keepHeader(cells);
|
|
62
63
|
continue;
|
|
63
64
|
}
|
|
@@ -105,19 +106,14 @@ function splitRounds(text) {
|
|
|
105
106
|
return starts.map((s, i) => text.slice(i === 0 ? 0 : s, starts[i + 1] ?? text.length));
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
/**
|
|
109
|
-
* Um relatório de review lido do texto. `checks` é `null` sem a seção `## Checks`.
|
|
110
|
-
* `rounds`: uma entrada por veredito, na ordem do arquivo, com o que aquela rodada escreveu.
|
|
111
|
-
*/
|
|
109
|
+
/** Um relatório de review lido do texto. `checks` é `null` sem a seção `## Checks`. */
|
|
112
110
|
export function parseReviewReport(text) {
|
|
113
111
|
if (typeof text !== 'string') {
|
|
114
|
-
return { partial: false, verdict: undefined, blockers: [], untyped: [],
|
|
112
|
+
return { partial: false, verdict: undefined, blockers: [], untyped: [], checks: null, reviewedSha: null };
|
|
115
113
|
}
|
|
116
|
-
|
|
117
|
-
const last =
|
|
118
|
-
|
|
119
|
-
// Blockers belong to the round that wrote them: a confirmation without `## Bloqueadores` closes the earlier ones.
|
|
120
|
-
return { ...parseRound(text), blockers: last.blockers, untyped: last.untyped, rounds };
|
|
114
|
+
// Blockers belong to the last verdict: one written without `## Bloqueadores` closes the earlier ones.
|
|
115
|
+
const last = parseRound(splitRounds(text).at(-1));
|
|
116
|
+
return { ...parseRound(text), blockers: last.blockers, untyped: last.untyped };
|
|
121
117
|
}
|
|
122
118
|
|
|
123
119
|
function parseRound(text) {
|
|
@@ -130,7 +126,6 @@ function parseRound(text) {
|
|
|
130
126
|
partial: PARTIAL_MARKER.test(firstLine),
|
|
131
127
|
verdict: verdicts.length ? verdicts[verdicts.length - 1] : undefined,
|
|
132
128
|
...(blockersBody === null ? { blockers: [], untyped: [] } : parseBlockers(blockersBody)),
|
|
133
|
-
superseded: verdicts.slice(0, -1),
|
|
134
129
|
checks: checksBodies.length === 0 ? null : parseChecks(checksBodies),
|
|
135
130
|
reviewedSha: shas.length ? shas[shas.length - 1] : null,
|
|
136
131
|
};
|