@polymorphism-tech/morph-spec 10.12.1 → 11.0.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/CLAUDE.md +27 -57
- package/README.md +51 -340
- package/bin/morph-spec.js +22 -373
- package/docs/CHEATSHEET.md +37 -166
- package/docs/QUICKSTART.md +14 -74
- package/framework/CLAUDE.md +15 -26
- package/framework/MORPH.md +34 -101
- package/framework/agents.json +8 -8
- package/framework/commands/morph-apply.md +5 -5
- package/framework/commands/morph-infra.md +1 -1
- package/framework/docs/CLI.md +74 -886
- package/framework/evals/review-checklist.md +14 -14
- package/framework/hooks/README.md +21 -189
- package/framework/hooks/claude-code/core/README.md +2 -5
- package/framework/hooks/claude-code/core/conventional-commit.js +2 -2
- package/framework/hooks/claude-code/core/denylist.json +3 -3
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +2 -2
- package/framework/hooks/claude-code/core/masked-exit.js +6 -6
- package/framework/hooks/claude-code/core/pre-bash-denylist.js +2 -2
- package/framework/hooks/claude-code/core/protect-spec-files.js +17 -61
- package/framework/hooks/claude-code/core/stack-changed.js +35 -0
- package/framework/hooks/claude-code/core/validate-completion.js +32 -87
- package/framework/hooks/shared/{heavy-command.js → command-kind.js} +6 -79
- package/framework/hooks/shared/command-tokens.js +0 -139
- package/framework/hooks/shared/contract.js +14 -0
- package/framework/hooks/shared/feature-slug.js +21 -0
- package/framework/hooks/shared/frontend-locations.js +0 -1
- package/framework/hooks/shared/git-paths.js +0 -15
- package/framework/hooks/shared/graph-freshness.js +0 -19
- package/framework/hooks/shared/hook-response.js +0 -7
- package/framework/hooks/shared/morph-cli.js +2 -81
- package/framework/hooks/shared/owner-words.js +2 -120
- package/framework/hooks/shared/payload-utils.js +0 -39
- package/framework/hooks/shared/report-progress.js +7 -101
- package/framework/hooks/statusline.js +16 -60
- package/framework/mcp/registry.json +2 -2
- package/framework/rules/ai-agents-standards.md +1 -1
- package/framework/rules/asaas-standards.md +1 -1
- package/framework/rules/ef-standards.md +1 -1
- package/framework/rules/gsap-standards.md +1 -1
- package/framework/rules/hangfire-standards.md +1 -1
- package/framework/rules/implement-report.md +3 -3
- package/framework/rules/neon-auth-standards.md +1 -1
- package/framework/rules/nextjs-standards.md +1 -1
- package/framework/rules/plan-grammar.md +13 -11
- package/framework/rules/resend-standards.md +1 -1
- package/framework/rules/ui-design.md +4 -0
- package/framework/schemas/config.schema.json +95 -310
- package/framework/skills/README.md +12 -32
- 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 +21 -46
- package/framework/skills/core/morph-plan/SKILL.md +28 -63
- package/framework/skills/core/morph-uiux/SKILL.md +23 -25
- package/framework/{templates/docs/ui-mockups.md → skills/core/morph-uiux/references/mockups.md} +4 -4
- package/framework/standards/STANDARDS.json +10 -11
- package/framework/standards/STANDARDS.meta.json +1 -1
- package/framework/standards/ai-agents/evals-with-cache.md +18 -32
- package/framework/standards/ai-agents/observability-patterns.md +2 -2
- package/framework/standards/architecture/code-comments.md +2 -5
- package/framework/standards/architecture/engineering-lens.md +1 -1
- package/framework/standards/backend/dotnet/testing.md +4 -4
- package/framework/standards/frontend/nextjs/lint.md +24 -10
- package/framework/standards/frontend/nextjs/testing.md +2 -2
- package/framework/standards/infrastructure/docker/local-compose-isolation.md +14 -30
- package/framework/templates/CLAUDE.md.core.guide.md +2 -2
- package/framework/templates/README.md +1 -1
- package/framework/templates/REGISTRY.json +3 -33
- package/framework/templates/docs/plan.md +3 -2
- package/framework/templates/dotnet/ai-kit/README.md +2 -4
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheMissException.cs +1 -1
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalFixture.cs +1 -1
- package/package.json +1 -2
- package/src/commands/graph/explain.js +2 -1
- package/src/commands/graph/status.js +2 -1
- package/src/commands/mcp/mcp-setup.js +1 -2
- package/src/commands/project/doctor.js +5 -341
- package/src/commands/project/env.js +21 -52
- package/src/commands/project/init-contract.js +47 -0
- package/src/commands/project/init.js +36 -66
- package/src/commands/project/stack-scan.js +1 -1
- package/src/commands/project/update.js +15 -50
- package/src/commands/validation/check.js +128 -0
- package/src/commands/validation/plan-check.js +41 -64
- package/src/commands/validation/prove-red.js +1 -1
- package/src/core/paths/output-schema.js +0 -22
- package/src/core/templates/template-renderer.js +0 -14
- package/src/lib/ai/ai-project-scan.js +1 -6
- package/src/lib/check/attempts.js +38 -0
- package/src/lib/check/signals.js +145 -0
- package/src/lib/config/project-config.js +13 -0
- package/src/lib/contract/apply.js +62 -0
- package/src/lib/contract/defaults.js +96 -0
- package/src/lib/contract/merge.js +79 -0
- package/src/lib/contract/ports.js +43 -0
- package/src/lib/contract/scan.js +102 -0
- package/src/lib/detectors/claude-config-detector.js +7 -0
- package/src/lib/{procs → detectors}/mcp-config.js +1 -37
- package/src/lib/diff/diff-lines.js +64 -0
- package/src/lib/generators/architecture-scanner.js +1 -1
- package/src/lib/generators/scaffold-generator.js +0 -7
- package/src/lib/git/default-branch.js +0 -122
- package/src/lib/graph/diff-tree.js +2 -1
- package/src/lib/graph/god-nodes.js +2 -1
- package/src/lib/graph/graphify-runtime.js +0 -1
- package/src/lib/graph/graphifyignore.js +1 -1
- package/src/lib/graph/sanitize.js +2 -8
- package/src/lib/installers/memory-installer.js +15 -30
- package/src/lib/installers/stack-sync.js +16 -9
- package/src/lib/plan/checks.js +20 -64
- package/src/lib/plan/media.js +1 -1
- package/src/lib/plan/plan-parser.js +5 -5
- package/src/lib/review-reports.js +3 -77
- package/src/lib/scan/worktree-dirs.js +3 -0
- package/src/lib/specs/adr-index.js +2 -2
- package/src/lib/stack/dotnet-build-ignores.js +10 -2
- package/src/lib/stack/stack-scan.js +2 -2
- package/src/lib/stack-filter.js +3 -2
- package/src/lib/tests-audit/audit.js +1 -1
- package/src/scripts/setup-infra.js +6 -59
- package/src/utils/agents-installer.js +1 -34
- package/src/utils/atomic-json.js +27 -0
- package/src/utils/file-copier.js +4 -12
- package/src/utils/hooks-installer.js +9 -107
- package/claude-plugin.json +0 -14
- package/framework/commands/morph-archive.md +0 -46
- package/framework/commands/morph-hotfix.md +0 -17
- package/framework/commands/morph-preflight.md +0 -180
- package/framework/commands/morph-review.md +0 -15
- package/framework/commands/morph-status.md +0 -37
- package/framework/hooks/claude-code/core/block-destructive-worktree-removal.js +0 -80
- package/framework/hooks/claude-code/core/block-raw-worktree-add.js +0 -72
- package/framework/hooks/claude-code/core/enforce-phase-writes.js +0 -100
- package/framework/hooks/claude-code/core/gate-guard.js +0 -148
- package/framework/hooks/claude-code/core/heavy-gate.js +0 -78
- package/framework/hooks/claude-code/core/heavy-release.js +0 -23
- package/framework/hooks/claude-code/core/loop-detect.js +0 -79
- package/framework/hooks/claude-code/core/state-sync.js +0 -214
- package/framework/hooks/claude-code/core/telemetry-log.js +0 -259
- package/framework/hooks/claude-code/core/test-budget.js +0 -29
- package/framework/hooks/claude-code/core/worktree-context.js +0 -249
- package/framework/hooks/claude-code/core/worktree-create.js +0 -119
- package/framework/hooks/claude-code/core/worktree-env-inject.js +0 -68
- package/framework/hooks/claude-code/core/worktree-remove.js +0 -55
- package/framework/hooks/shared/build-check.js +0 -120
- package/framework/hooks/shared/claim-registry.js +0 -125
- package/framework/hooks/shared/e2e-check.js +0 -1022
- package/framework/hooks/shared/feature-locator.js +0 -82
- package/framework/hooks/shared/gate-event.js +0 -18
- package/framework/hooks/shared/gate-question.js +0 -20
- package/framework/hooks/shared/heavy-config.js +0 -113
- package/framework/hooks/shared/heavy-holders.js +0 -85
- package/framework/hooks/shared/heavy-slots.js +0 -280
- package/framework/hooks/shared/host-services.js +0 -440
- package/framework/hooks/shared/next-step.js +0 -181
- package/framework/hooks/shared/redact-secrets.js +0 -44
- package/framework/hooks/shared/reparse-scan.js +0 -40
- package/framework/hooks/shared/state-reader.js +0 -220
- package/framework/hooks/shared/state-writer.js +0 -112
- package/framework/hooks/shared/telemetry-logger.js +0 -101
- package/framework/hooks/shared/transcript-usage.js +0 -58
- package/framework/hooks/shared/worktree-root.js +0 -71
- package/framework/phases.json +0 -92
- package/framework/schemas/feature.schema.json +0 -242
- package/framework/skills/core/morph-apply/references/hotfix.md +0 -46
- package/framework/skills/core/morph-apply/references/machine.md +0 -30
- package/framework/skills/core/morph-apply/references/review.md +0 -77
- package/framework/skills/core/morph-plan/references/critique.md +0 -51
- package/framework/skills/core/morph-plan/references/interview.md +0 -37
- package/framework/templates/state.template.json +0 -17
- package/src/commands/dashboard/dashboard.js +0 -74
- package/src/commands/e2e/e2e.js +0 -400
- package/src/commands/observability/cost.js +0 -283
- package/src/commands/project/branch.js +0 -129
- package/src/commands/project/claim.js +0 -132
- package/src/commands/project/doctor-procs.js +0 -162
- package/src/commands/project/fleet.js +0 -66
- package/src/commands/project/heavy.js +0 -81
- package/src/commands/project/install-plugin-cmd.js +0 -27
- package/src/commands/project/status.js +0 -61
- package/src/commands/project/worktree.js +0 -1234
- package/src/commands/state/advance.js +0 -248
- package/src/commands/state/approve.js +0 -303
- package/src/commands/state/archive.js +0 -231
- package/src/commands/state/auto-approval.js +0 -67
- package/src/commands/state/create.js +0 -274
- package/src/commands/state/delete.js +0 -192
- package/src/commands/state/finish.js +0 -1247
- package/src/commands/state/gate-check.js +0 -244
- package/src/commands/state/gate-decision.js +0 -122
- package/src/commands/state/list.js +0 -244
- package/src/commands/state/next.js +0 -24
- package/src/commands/state/recap.js +0 -80
- package/src/commands/state/report-check.js +0 -244
- package/src/commands/state/retype.js +0 -110
- package/src/commands/validation/verify.js +0 -421
- package/src/core/state/feature-identity.js +0 -10
- package/src/core/state/gate-order.js +0 -23
- package/src/core/state/lifecycle-audit.js +0 -171
- package/src/core/state/state-manager.js +0 -523
- package/src/core/templates/template-seed.js +0 -21
- package/src/core/work-types.js +0 -44
- package/src/dashboard/app/App.jsx +0 -84
- package/src/dashboard/app/components/ActivityFeed.jsx +0 -166
- package/src/dashboard/app/components/CommandPalette.jsx +0 -144
- package/src/dashboard/app/components/DetailPanel.jsx +0 -43
- package/src/dashboard/app/components/EntityLink.jsx +0 -42
- package/src/dashboard/app/components/ErrorBoundary.jsx +0 -47
- package/src/dashboard/app/components/FlowGraph.jsx +0 -19
- package/src/dashboard/app/components/GatePauses.jsx +0 -116
- package/src/dashboard/app/components/KnowledgeMarkdown.jsx +0 -42
- package/src/dashboard/app/components/Markdown.jsx +0 -38
- package/src/dashboard/app/components/PhaseRail.jsx +0 -100
- package/src/dashboard/app/components/SearchFilter.jsx +0 -36
- package/src/dashboard/app/components/SessionMap.jsx +0 -77
- package/src/dashboard/app/components/Sidebar.jsx +0 -147
- package/src/dashboard/app/hooks/useMorphQuery.js +0 -44
- package/src/dashboard/app/hooks/usePref.js +0 -34
- package/src/dashboard/app/lib/format.js +0 -69
- package/src/dashboard/app/lib/phases.js +0 -75
- package/src/dashboard/app/lib/project.js +0 -38
- package/src/dashboard/app/main.jsx +0 -13
- package/src/dashboard/app/pages/Activity.jsx +0 -28
- package/src/dashboard/app/pages/AgentMap.jsx +0 -363
- package/src/dashboard/app/pages/FeatureDetail.jsx +0 -579
- package/src/dashboard/app/pages/Features.jsx +0 -393
- package/src/dashboard/app/pages/Guide.jsx +0 -145
- package/src/dashboard/app/pages/HookInspector.jsx +0 -444
- package/src/dashboard/app/pages/PhasePipeline.jsx +0 -273
- package/src/dashboard/app/pages/Portfolio.jsx +0 -190
- package/src/dashboard/app/pages/RulesMap.jsx +0 -285
- package/src/dashboard/app/pages/SkillsLibrary.jsx +0 -468
- package/src/dashboard/app/pages/Standards.jsx +0 -392
- package/src/dashboard/app/styles/index.css +0 -187
- package/src/dashboard/index.html +0 -14
- package/src/dashboard/package.json +0 -32
- package/src/dashboard/scanner/activity-scanner.js +0 -321
- package/src/dashboard/scanner/agents-scanner.js +0 -67
- package/src/dashboard/scanner/docs-scanner.js +0 -34
- package/src/dashboard/scanner/feature-status.js +0 -7
- package/src/dashboard/scanner/features-scanner.js +0 -397
- package/src/dashboard/scanner/hooks-scanner.js +0 -96
- package/src/dashboard/scanner/index.js +0 -21
- package/src/dashboard/scanner/phases-scanner.js +0 -14
- package/src/dashboard/scanner/portfolio.js +0 -129
- package/src/dashboard/scanner/project-api.js +0 -160
- package/src/dashboard/scanner/rules-scanner.js +0 -46
- package/src/dashboard/scanner/skills-scanner.js +0 -104
- package/src/dashboard/scanner/standards-scanner.js +0 -38
- package/src/dashboard/vite-plugin-morph-data.js +0 -120
- package/src/dashboard/vite.config.js +0 -26
- package/src/lib/ci/ci-verify.js +0 -30
- package/src/lib/ci/github-ci.js +0 -52
- package/src/lib/ci/pr-checks.js +0 -76
- package/src/lib/e2e/applicability.js +0 -39
- package/src/lib/e2e/compose-env.js +0 -80
- package/src/lib/e2e/stack-teardown.js +0 -96
- package/src/lib/git/branch-classifier.js +0 -104
- package/src/lib/git/evidence-staleness.js +0 -40
- package/src/lib/git/gh.js +0 -15
- package/src/lib/git/pending-prs.js +0 -58
- package/src/lib/git/pr-files.js +0 -31
- package/src/lib/git/pr-index.js +0 -39
- package/src/lib/git/tree-fingerprint.js +0 -58
- package/src/lib/git/tree-state.js +0 -125
- package/src/lib/heavy/cleanup.js +0 -72
- package/src/lib/heavy/gate.js +0 -168
- package/src/lib/heavy/live-stacks.js +0 -64
- package/src/lib/heavy/reclaim.js +0 -107
- package/src/lib/heavy/watchdog.js +0 -46
- package/src/lib/next-step.js +0 -12
- package/src/lib/plan/critique.js +0 -67
- package/src/lib/plan/plan-template.js +0 -18
- package/src/lib/procs/classify.js +0 -91
- package/src/lib/procs/list.js +0 -124
- package/src/lib/procs/prune.js +0 -47
- package/src/lib/procs/wslconfig.js +0 -70
- package/src/lib/projects/registry.js +0 -121
- package/src/lib/recap/piper.js +0 -36
- package/src/lib/recap/recap.js +0 -259
- package/src/lib/review-confirmation.js +0 -66
- package/src/lib/risk/diff-risk.js +0 -137
- package/src/lib/risk-detector.js +0 -638
- package/src/lib/specs/design-seed.js +0 -18
- package/src/lib/specs/screen-checklist.js +0 -315
- package/src/lib/stack/stack-profile.js +0 -69
- package/src/lib/tasks/eval-node.js +0 -293
- package/src/lib/tasks/linux-runner.js +0 -200
- package/src/lib/tasks/test-nodes.js +0 -414
- package/src/lib/tasks/test-runner.js +0 -569
- package/src/lib/telemetry/metrics.js +0 -384
- package/src/lib/telemetry/telemetry-reader.js +0 -276
- package/src/lib/telemetry/verify-event.js +0 -57
- package/src/lib/validators/code-budget/code-budget-validator.js +0 -170
- package/src/lib/validators/contracts/contract-compliance-validator.js +0 -219
- package/src/lib/validators/nextjs/next-component-validator.js +0 -142
- package/src/lib/validators/packages/package-validator.js +0 -310
- package/src/lib/validators/reuse/reuse-validator.js +0 -202
- package/src/lib/validators/reuse/symbol-scanner.js +0 -64
- package/src/lib/validators/validation-runner.js +0 -188
- package/src/lib/validators/verify-cache.js +0 -63
- package/src/lib/validators/verify-runner.js +0 -971
- package/src/lib/verify/affected.js +0 -143
- package/src/lib/verify/detached.js +0 -159
- package/src/lib/view/feature-html.js +0 -480
- package/src/lib/view/feature-page.client.js +0 -109
- package/src/lib/view/feature-page.css +0 -278
- package/src/lib/view/feature-view.js +0 -113
- package/src/lib/view/flow-layers.js +0 -79
- package/src/lib/view/flow-svg.js +0 -63
- package/src/lib/view/tokens.css +0 -18
- package/src/lib/work-type-detector.js +0 -81
- package/src/lib/worktree/dirs.js +0 -3
- package/src/lib/worktree/docker-audit.js +0 -175
- package/src/lib/worktree/env-allocator.js +0 -177
- package/src/lib/worktree/feature-truth.js +0 -145
- package/src/lib/worktree/finish-backup.js +0 -529
- package/src/lib/worktree/fleet-scanner.js +0 -223
- package/src/lib/worktree/ignored-triage.js +0 -136
- package/src/lib/worktree/vscode-settings.js +0 -112
- package/src/lib/worktree/worktree-audit.js +0 -323
- package/src/lib/worktree/worktree-include.js +0 -44
- package/src/scripts/install-plugin.js +0 -114
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { join, relative
|
|
1
|
+
import { join, relative } from 'path';
|
|
2
2
|
import { execSync } from 'child_process';
|
|
3
|
-
import { existsSync } from 'fs';
|
|
4
3
|
import { platform, homedir } from 'os';
|
|
5
4
|
import fs from 'fs-extra';
|
|
6
5
|
import chalk from 'chalk';
|
|
7
6
|
import { logger } from '../../utils/logger.js';
|
|
8
7
|
import { pathExists, readJson } from '../../utils/file-copier.js';
|
|
9
8
|
import { checkClaudeMdImport } from '../../utils/claude-md-injector.js';
|
|
10
|
-
import { buildPrIndex } from '../../lib/git/pr-index.js';
|
|
11
|
-
import { pendingPrFeatures, MORPH_BRANCH_RE } from '../../lib/git/pending-prs.js';
|
|
12
|
-
import { prCarriesFeature } from '../../lib/git/pr-files.js';
|
|
13
9
|
import {
|
|
14
10
|
checkCLIOutdated,
|
|
15
11
|
checkProjectOutdated,
|
|
@@ -20,17 +16,9 @@ import { checkMissingAgents, checkAgentsDrift, maxTurnsError } from '../../utils
|
|
|
20
16
|
import { getProjectTags } from '../../lib/stack-filter.js';
|
|
21
17
|
import { stackRuleGaps } from '../../lib/installers/stack-sync.js';
|
|
22
18
|
import { auditGraph } from '../../lib/graph/graph-health.js';
|
|
23
|
-
import { auditFeatureLifecycle } from '../../core/state/lifecycle-audit.js';
|
|
24
|
-
import { validateTestNodes, morphConfigPath, discoverFrontendPackages } from '../../lib/tasks/test-nodes.js';
|
|
25
|
-
import { samePathCase } from '../../lib/worktree/docker-audit.js';
|
|
26
19
|
|
|
27
20
|
const isWindows = platform() === 'win32';
|
|
28
21
|
|
|
29
|
-
// NTFS is case-insensitive: case folding goes through `samePathCase`, the one copy of that rule.
|
|
30
|
-
function normCwd(root, cwd) {
|
|
31
|
-
return samePathCase(resolve(root, String(cwd ?? '.')).replace(/\\/g, '/'));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
22
|
export function checkInstalledPlugins(pluginsData) {
|
|
35
23
|
const REQUIRED = ['context7'];
|
|
36
24
|
return Object.fromEntries(
|
|
@@ -77,9 +65,7 @@ const REQUIRED_COMMAND_FILES = [
|
|
|
77
65
|
'src/commands/project/init.js',
|
|
78
66
|
'src/commands/project/update.js',
|
|
79
67
|
'src/commands/project/doctor.js',
|
|
80
|
-
'src/commands/
|
|
81
|
-
'src/commands/project/worktree.js',
|
|
82
|
-
'src/commands/state/approve.js',
|
|
68
|
+
'src/commands/validation/check.js',
|
|
83
69
|
'src/commands/scaffold/scaffold.js',
|
|
84
70
|
'src/commands/mcp/mcp-setup.js',
|
|
85
71
|
'src/commands/context/context-refresh.js',
|
|
@@ -315,67 +301,6 @@ async function doctorFullCommand(frameworkRoot) {
|
|
|
315
301
|
"GitHub ops (issues/PRs/releases) usam o gh CLI — instale https://cli.github.com e rode 'gh auth login'");
|
|
316
302
|
}
|
|
317
303
|
|
|
318
|
-
console.log(chalk.cyan('\n .morph/state.json — Schema Version'));
|
|
319
|
-
const statePath = join(frameworkRoot, '.morph/state.json');
|
|
320
|
-
if (await pathExists(statePath)) {
|
|
321
|
-
try {
|
|
322
|
-
const state = JSON.parse(await fs.readFile(statePath, 'utf8'));
|
|
323
|
-
const isCurrent = state.version === '5.0.0';
|
|
324
|
-
check(`state.json schema (${state.version})`, isCurrent, true,
|
|
325
|
-
isCurrent ? '' : `expected 5.0.0, found ${state.version} — run any CLI command to auto-migrate`);
|
|
326
|
-
} catch {
|
|
327
|
-
check('state.json parse', false, false, 'invalid JSON');
|
|
328
|
-
}
|
|
329
|
-
} else {
|
|
330
|
-
check('state.json', false, true, 'not found (run: morph-spec init)');
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// Mesma autoridade do `verify` (validateTestNodes). Pula sem `config.json` ou sem `project.tests`:
|
|
334
|
-
// não há contrato a violar, e `doctor --full` não pode ter ✗ aqui. WARN, nunca ERROR.
|
|
335
|
-
const testsConfigPath = morphConfigPath(frameworkRoot);
|
|
336
|
-
if (await pathExists(testsConfigPath)) {
|
|
337
|
-
let testsConfig = null;
|
|
338
|
-
try {
|
|
339
|
-
testsConfig = JSON.parse((await fs.readFile(testsConfigPath, 'utf8')).replace(/^\uFEFF/, ''));
|
|
340
|
-
} catch {
|
|
341
|
-
testsConfig = null; // config ilegível já é reportado pelo doctor base
|
|
342
|
-
}
|
|
343
|
-
if (testsConfig?.project?.tests !== undefined) {
|
|
344
|
-
console.log(chalk.cyan('\n .morph/config/config.json — project.tests[]'));
|
|
345
|
-
const declared = validateTestNodes(testsConfig, frameworkRoot);
|
|
346
|
-
const broken = declared.filter((n) => n.status === 'fail');
|
|
347
|
-
check(`config tests[] (${declared.length - broken.length}/${declared.length})`,
|
|
348
|
-
broken.length === 0, true,
|
|
349
|
-
broken.length > 0
|
|
350
|
-
? broken.map((n) => n.reason ?? `invalid-test-node: ${n.id}`).join('; ')
|
|
351
|
-
: '');
|
|
352
|
-
|
|
353
|
-
// A vitest/jest package.json that no declared node covers is a suite outside the gate (WARN only).
|
|
354
|
-
// Compared by RESOLVED path so a different spelling of the same dir doesn't warn.
|
|
355
|
-
const declaredCwds = new Set(declared.map((n) => normCwd(frameworkRoot, n.cwd)));
|
|
356
|
-
const uncoveredPkgs = discoverFrontendPackages(frameworkRoot, testsConfig)
|
|
357
|
-
.filter((pkg) => !declaredCwds.has(normCwd(frameworkRoot, pkg.cwd)));
|
|
358
|
-
if (uncoveredPkgs.length > 0) {
|
|
359
|
-
check(
|
|
360
|
-
`config tests[] cobre package.json de frontend — sem nó: ${uncoveredPkgs.map((p) => `${p.cwd} (${p.runner})`).join(', ')}`,
|
|
361
|
-
false, true,
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
} else if (typeof testsConfig?.project?.testCommand === 'string' && testsConfig.project.testCommand.trim()) {
|
|
365
|
-
// testCommand é opaco: cobertura aqui é só "o comando MENCIONA o runner do package.json".
|
|
366
|
-
const testCommand = testsConfig.project.testCommand;
|
|
367
|
-
const uncoveredPkgs = discoverFrontendPackages(frameworkRoot, testsConfig)
|
|
368
|
-
.filter((pkg) => !testCommand.includes(pkg.runner));
|
|
369
|
-
if (uncoveredPkgs.length > 0) {
|
|
370
|
-
console.log(chalk.cyan('\n .morph/config/config.json — project.testCommand'));
|
|
371
|
-
check(
|
|
372
|
-
`config testCommand cobre package.json de frontend — sem nó: ${uncoveredPkgs.map((p) => `${p.cwd} (${p.runner})`).join(', ')}`,
|
|
373
|
-
false, true,
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
304
|
console.log('\n' + '─'.repeat(60));
|
|
380
305
|
console.log(chalk.bold('\nResults:\n'));
|
|
381
306
|
for (const c of checks) {
|
|
@@ -540,152 +465,13 @@ async function doctorMcpCommand(targetPath) {
|
|
|
540
465
|
logger.blank();
|
|
541
466
|
}
|
|
542
467
|
|
|
543
|
-
/**
|
|
544
|
-
* `--prune` runs only safe repairs (`git worktree prune`, EMPTY unregistered dirs) and the
|
|
545
|
-
* finish-backup retention; a directory that still holds something is reported, never deleted.
|
|
546
|
-
*/
|
|
547
|
-
export async function doctorWorktreesCommand(targetPath, options = {}) {
|
|
548
|
-
const { auditWorktrees, pruneWorktrees } = await import('../../lib/worktree/worktree-audit.js');
|
|
549
|
-
|
|
550
|
-
let backupRetention = null;
|
|
551
|
-
let prune = null;
|
|
552
|
-
if (options.prune) {
|
|
553
|
-
const beforeIssues = auditWorktrees(targetPath);
|
|
554
|
-
const beforeMissing = beforeIssues.filter((i) => i.type === 'registered-missing').length;
|
|
555
|
-
const beforeDangling = beforeIssues.filter((i) => i.type === 'dangling-registration').length;
|
|
556
|
-
const beforeEmptyDirs = beforeIssues.filter((i) => i.type === 'unregistered-dir' && i.empty).length;
|
|
557
|
-
const result = await pruneWorktrees(targetPath);
|
|
558
|
-
// Under --json the only thing on stdout is the JSON: a status line in front
|
|
559
|
-
// of it breaks every caller that parses the output.
|
|
560
|
-
prune = {
|
|
561
|
-
pruned: Boolean(result.pruned),
|
|
562
|
-
...(result.pruned ? { orphanRegistrations: beforeMissing } : { error: result.error }),
|
|
563
|
-
removedEmptyDirs: result.removedEmptyDirs,
|
|
564
|
-
clearedRegistrations: result.clearedRegistrations.map((r) => r.feature),
|
|
565
|
-
};
|
|
566
|
-
if (!options.json) {
|
|
567
|
-
if (result.pruned) logger.success(`git worktree prune: ${beforeMissing} registro(s) órfão(s) removido(s).`);
|
|
568
|
-
else logger.warn(`prune falhou: ${result.error}`);
|
|
569
|
-
if (result.removedEmptyDirs.length) {
|
|
570
|
-
logger.success(`${result.removedEmptyDirs.length}/${beforeEmptyDirs} diretório(s) vazio(s) removido(s): ${result.removedEmptyDirs.join(', ')}`);
|
|
571
|
-
}
|
|
572
|
-
if (result.clearedRegistrations.length) {
|
|
573
|
-
logger.success(`registro de worktree limpo em ${result.clearedRegistrations.length}/${beforeDangling} feature(s): ${result.clearedRegistrations.map((r) => r.feature).join(', ')}`);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
const { resolvePrimaryRoot } = await import('./worktree.js');
|
|
578
|
-
const { applyEditorSettings } = await import('../../lib/worktree/vscode-settings.js');
|
|
579
|
-
const editor = applyEditorSettings(resolvePrimaryRoot(targetPath));
|
|
580
|
-
if (editor.status !== 'off') {
|
|
581
|
-
prune.editorSettings = editor;
|
|
582
|
-
if (!options.json && editor.status === 'write') logger.success(`.vscode/settings.json: ${editor.added.length} exclusão(ões) de worktree adicionada(s)`);
|
|
583
|
-
if (!options.json && editor.status === 'suggest') logger.warn(`.vscode/settings.json não foi alterado (${editor.reason}); cole isto nele:\n${editor.snippet}`);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
const { applyBackupRetention, summarizeRetention } = await import('../../lib/worktree/finish-backup.js');
|
|
587
|
-
// The explicit prune is the one that reaches the backups written before the
|
|
588
|
-
// retention existed (no manifest): the automatic one never touches them.
|
|
589
|
-
backupRetention = summarizeRetention(applyBackupRetention(resolvePrimaryRoot(targetPath), { includeLegacy: true }));
|
|
590
|
-
if (backupRetention?.skipped && !options.json) {
|
|
591
|
-
logger.warn(`retenção dos backups do finish PULADA: ${backupRetention.skipped}`);
|
|
592
|
-
} else if (backupRetention && !options.json) {
|
|
593
|
-
const stripped = backupRetention.secretsStripped ? `, ${backupRetention.secretsStripped} arquivo(s) .env* apagado(s)` : '';
|
|
594
|
-
const adopted = backupRetention.adopted ? `, ${backupRetention.adopted} backup(s) antigo(s) mantido(s) ganharam manifesto` : '';
|
|
595
|
-
logger.success(`retenção dos backups do finish: ${backupRetention.removed ?? 0} pasta(s) removida(s)${stripped}${adopted}`);
|
|
596
|
-
for (const d of backupRetention.declined || []) logger.warn(`backup mantido: ${d.backup} (${d.reason})`);
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
const issues = auditWorktrees(targetPath);
|
|
601
|
-
// `info`/`warn` entries are REPORTED, not failures: CI must not go red for an open PR, a hand-made
|
|
602
|
-
// tree or a running container. The human path below splits the same way.
|
|
603
|
-
const isProblem = (i) => !['info', 'warn'].includes(i.severity);
|
|
604
|
-
|
|
605
|
-
if (options.json) {
|
|
606
|
-
console.log(JSON.stringify({ issues, ...(prune ? { prune } : {}), ...(backupRetention ? { backupRetention } : {}) }, null, 2));
|
|
607
|
-
return !issues.some(isProblem);
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
logger.header('MORPH-SPEC Worktrees');
|
|
611
|
-
if (issues.length === 0) {
|
|
612
|
-
logger.success('Worktrees reconciliados — git, disco e features batem.');
|
|
613
|
-
return true;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
// `unintegrated-work` is a worktree doing its job, not an inconsistency: counting it nags people
|
|
617
|
-
// into destroying work to silence the warning.
|
|
618
|
-
const informational = issues.filter((i) => !isProblem(i));
|
|
619
|
-
const problems = issues.filter(isProblem);
|
|
620
|
-
|
|
621
|
-
if (problems.length) logger.warn(`${problems.length} inconsistência(s):`);
|
|
622
|
-
for (const i of problems) {
|
|
623
|
-
console.log(` ⚠ ${i.type}`);
|
|
624
|
-
console.log(` ${i.detail}`);
|
|
625
|
-
console.log(` → ${i.fix}`);
|
|
626
|
-
}
|
|
627
|
-
for (const i of informational) {
|
|
628
|
-
console.log(i.severity === 'warn' ? chalk.yellow(` ⚠ ${i.type}`) : ` ℹ ${i.type}`);
|
|
629
|
-
console.log(` ${i.detail}`);
|
|
630
|
-
console.log(` → ${i.fix}`);
|
|
631
|
-
}
|
|
632
|
-
// An EMPTY unregistered dir is prunable too, so the hint must mention it.
|
|
633
|
-
const prunable = (i) => i.type === 'registered-missing'
|
|
634
|
-
|| i.type === 'dangling-registration'
|
|
635
|
-
|| (i.type === 'unregistered-dir' && i.empty);
|
|
636
|
-
if (problems.some(prunable) && !options.prune) {
|
|
637
|
-
logger.dim('\n Rode `morph-spec doctor --worktrees --prune` para limpar os registros órfãos e os diretórios vazios.');
|
|
638
|
-
}
|
|
639
|
-
if (!problems.length) {
|
|
640
|
-
logger.success('Nenhuma inconsistência — os itens acima são informativos.');
|
|
641
|
-
return true;
|
|
642
|
-
}
|
|
643
|
-
return false;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
const PR_STALE_DAYS = 7;
|
|
647
|
-
|
|
648
|
-
/** `null` = DESCONHECIDO (o índice não pôde ser construído), nunca "sem PRs". */
|
|
649
|
-
function auditPullRequests(root) {
|
|
650
|
-
const index = buildPrIndex(root);
|
|
651
|
-
if (!index) return null;
|
|
652
|
-
const issues = [];
|
|
653
|
-
|
|
654
|
-
for (const p of pendingPrFeatures(root, { index }) || []) {
|
|
655
|
-
if (p.ageDays != null && p.ageDays >= PR_STALE_DAYS) {
|
|
656
|
-
issues.push({
|
|
657
|
-
feature: p.feature,
|
|
658
|
-
type: 'pr-awaiting-merge',
|
|
659
|
-
detail: `PR #${p.number} aberto há ${p.ageDays}d e sem cópia local — mergeie ou feche`,
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
for (const [branch, pr] of index) {
|
|
665
|
-
const m = branch.match(MORPH_BRANCH_RE);
|
|
666
|
-
if (!m || pr.state !== 'MERGED') continue;
|
|
667
|
-
const feature = m[1];
|
|
668
|
-
if (existsSync(join(root, '.morph', 'archive', feature))) continue;
|
|
669
|
-
// Só `false` (diff lido, sem a feature) cala o aviso; `null` — não pude
|
|
670
|
-
// ler o diff — o mantém, ou um `git pull` realmente faltando ficaria mudo.
|
|
671
|
-
if (prCarriesFeature(root, pr.number, feature) === false) continue;
|
|
672
|
-
issues.push({
|
|
673
|
-
feature,
|
|
674
|
-
type: 'pr-merged-not-landed',
|
|
675
|
-
detail: `PR #${pr.number} foi mergeado mas .morph/archive/${feature} não está aqui — falta \`git pull\`?`,
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
return issues;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
468
|
/**
|
|
683
469
|
* Superfície própria, fora do `--full` (cujo renderer mostra `skip` como ✗) e do default.
|
|
684
470
|
* Exit 1 só com algum `error`; `warn` e `skip` nunca mudam o código de saída.
|
|
685
471
|
*/
|
|
686
472
|
export async function doctorAiCommand(targetPath, options = {}) {
|
|
687
473
|
const { collectAiChecks, aiExitCode, allSkipped } = await import('../../lib/ai/ai-checks.js');
|
|
688
|
-
const { readMorphConfig } = await import('../../lib/
|
|
474
|
+
const { readMorphConfig } = await import('../../lib/config/project-config.js');
|
|
689
475
|
|
|
690
476
|
logger.header('AI Health Check (.NET + agentes)');
|
|
691
477
|
logger.blank();
|
|
@@ -740,33 +526,9 @@ export async function doctorAiCommand(targetPath, options = {}) {
|
|
|
740
526
|
}
|
|
741
527
|
|
|
742
528
|
export async function doctorCommand(options = {}) {
|
|
743
|
-
// `--json`/`--prune` only mean something under `--worktrees` or `--procs`: refuse rather than
|
|
744
|
-
// drop the flag in silence and hand a script a banner where it asked for JSON.
|
|
745
|
-
const scoped = ['json', 'prune'].filter((f) => options[f]);
|
|
746
|
-
if (scoped.length && !options.worktrees && !options.procs) {
|
|
747
|
-
const flags = scoped.map((f) => `--${f}`).join(' e ');
|
|
748
|
-
logger.error(`${flags} só se aplica${scoped.length > 1 ? 'm' : ''} a \`morph-spec doctor --worktrees\` ou \`morph-spec doctor --procs\`.`);
|
|
749
|
-
logger.dim(` Rode: morph-spec doctor --worktrees ${scoped.map((f) => `--${f}`).join(' ')}`);
|
|
750
|
-
process.exitCode = 1;
|
|
751
|
-
return false;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// `--prune` é uma flag só e poda coisas diferentes em cada modo; juntar os dois
|
|
755
|
-
// modos faria as duas podas destrutivas rodarem sob um único pedido.
|
|
756
|
-
if (options.procs) {
|
|
757
|
-
const conflicts = ['full', 'mcp', 'worktrees', 'reset'].filter((f) => options[f]);
|
|
758
|
-
if (conflicts.length) {
|
|
759
|
-
const flags = conflicts.map((f) => `--${f}`).join(' e ');
|
|
760
|
-
logger.error(`--procs não se combina com ${flags} — cada superfície tem o seu relatório, o seu código de saída e a sua poda.`);
|
|
761
|
-
logger.dim(' Rode: morph-spec doctor --procs');
|
|
762
|
-
process.exitCode = 1;
|
|
763
|
-
return false;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
529
|
// `--ai` com outra superfície daria dois códigos de saída no mesmo processo: recusa.
|
|
768
530
|
if (options.ai) {
|
|
769
|
-
const conflicts = ['full', 'mcp'
|
|
531
|
+
const conflicts = ['full', 'mcp'].filter((f) => options[f]);
|
|
770
532
|
if (conflicts.length) {
|
|
771
533
|
const flags = conflicts.map((f) => `--${f}`).join(' e ');
|
|
772
534
|
logger.error(`--ai não se combina com ${flags} — cada superfície tem o seu relatório e o seu código de saída.`);
|
|
@@ -810,18 +572,6 @@ export async function doctorCommand(options = {}) {
|
|
|
810
572
|
return doctorMcpCommand(process.cwd());
|
|
811
573
|
}
|
|
812
574
|
|
|
813
|
-
if (options.worktrees) {
|
|
814
|
-
const clean = await doctorWorktreesCommand(process.cwd(), options);
|
|
815
|
-
// The audit result must reach the exit code: Commander discards an action's return value.
|
|
816
|
-
if (!clean) process.exitCode = 1;
|
|
817
|
-
return clean;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
if (options.procs) {
|
|
821
|
-
const { doctorProcsCommand } = await import('./doctor-procs.js');
|
|
822
|
-
return doctorProcsCommand(process.cwd(), options);
|
|
823
|
-
}
|
|
824
|
-
|
|
825
575
|
const targetPath = process.cwd();
|
|
826
576
|
|
|
827
577
|
logger.header('MORPH-SPEC Health Check');
|
|
@@ -1170,60 +920,6 @@ export async function doctorCommand(options = {}) {
|
|
|
1170
920
|
hasErrors = true;
|
|
1171
921
|
}
|
|
1172
922
|
|
|
1173
|
-
const statePath = join(targetPath, '.morph', 'state.json');
|
|
1174
|
-
if (await pathExists(statePath)) {
|
|
1175
|
-
try {
|
|
1176
|
-
const stateContent = await readJson(statePath);
|
|
1177
|
-
if (stateContent.version && stateContent.features) {
|
|
1178
|
-
const featureCount = Object.keys(stateContent.features).length;
|
|
1179
|
-
checks.push({ name: 'state.json', status: 'ok', msg: `${featureCount} feature(s)` });
|
|
1180
|
-
} else {
|
|
1181
|
-
checks.push({ name: 'state.json', status: 'warn', msg: 'invalid schema' });
|
|
1182
|
-
hasWarnings = true;
|
|
1183
|
-
}
|
|
1184
|
-
} catch {
|
|
1185
|
-
checks.push({ name: 'state.json', status: 'error', msg: 'invalid JSON' });
|
|
1186
|
-
hasErrors = true;
|
|
1187
|
-
}
|
|
1188
|
-
} else {
|
|
1189
|
-
checks.push({ name: 'state.json', status: 'warn', msg: 'not initialized (run: morph-spec init)' });
|
|
1190
|
-
hasWarnings = true;
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
// Warn only (advisory); the per-feature detail is printed after the summary.
|
|
1194
|
-
const lifecycleIssues = auditFeatureLifecycle(targetPath);
|
|
1195
|
-
if (lifecycleIssues.length === 0) {
|
|
1196
|
-
checks.push({ name: 'feature lifecycle', status: 'ok' });
|
|
1197
|
-
} else {
|
|
1198
|
-
checks.push({
|
|
1199
|
-
name: 'feature lifecycle',
|
|
1200
|
-
status: 'warn',
|
|
1201
|
-
msg: `${lifecycleIssues.length} inconsistenc${lifecycleIssues.length === 1 ? 'y' : 'ies'} (see below)`,
|
|
1202
|
-
});
|
|
1203
|
-
hasWarnings = true;
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
// Offline-safe: `auditPullRequests` never throws and returns `null` when it cannot ask, which
|
|
1207
|
-
// renders as "não verificado", never `✓`.
|
|
1208
|
-
let prIssues;
|
|
1209
|
-
try {
|
|
1210
|
-
prIssues = auditPullRequests(targetPath);
|
|
1211
|
-
} catch {
|
|
1212
|
-
prIssues = null; // fail-open — um doctor não pode ficar mais ruidoso porque o gh sumiu
|
|
1213
|
-
}
|
|
1214
|
-
if (prIssues === null) {
|
|
1215
|
-
checks.push({ name: 'pull requests', status: 'skip', msg: 'gh indisponível — não verificado' });
|
|
1216
|
-
} else if (prIssues.length === 0) {
|
|
1217
|
-
checks.push({ name: 'pull requests', status: 'ok' });
|
|
1218
|
-
} else {
|
|
1219
|
-
checks.push({
|
|
1220
|
-
name: 'pull requests',
|
|
1221
|
-
status: 'warn',
|
|
1222
|
-
msg: `${prIssues.length} pendência${prIssues.length === 1 ? '' : 's'} (veja abaixo)`,
|
|
1223
|
-
});
|
|
1224
|
-
hasWarnings = true;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
923
|
// Opcional: nunca 'missing', um projeto que não usa o grafo segue com o doctor verde.
|
|
1228
924
|
const graphAudit = auditGraph(targetPath);
|
|
1229
925
|
if (graphAudit.status === 'warn') {
|
|
@@ -1233,23 +929,10 @@ export async function doctorCommand(options = {}) {
|
|
|
1233
929
|
checks.push({ name: 'codebase graph', status: 'ok', msg: graphAudit.msg });
|
|
1234
930
|
}
|
|
1235
931
|
|
|
1236
|
-
// O que o morph-spec guarda dentro do `.git` (backups do finish, registros de
|
|
1237
|
-
// porta e de claim) cresce sem aparecer em `git status`. Informação — `ok` ou
|
|
1238
|
-
// `warn`, nunca falha —, e nenhuma linha quando não há nada guardado.
|
|
1239
|
-
try {
|
|
1240
|
-
const { resolvePrimaryRoot } = await import('./worktree.js');
|
|
1241
|
-
const { morphStoreCheck } = await import('../../lib/worktree/finish-backup.js');
|
|
1242
|
-
const storeCheck = morphStoreCheck(resolvePrimaryRoot(targetPath));
|
|
1243
|
-
if (storeCheck) {
|
|
1244
|
-
checks.push(storeCheck);
|
|
1245
|
-
if (storeCheck.status === 'warn') hasWarnings = true;
|
|
1246
|
-
}
|
|
1247
|
-
} catch {}
|
|
1248
|
-
|
|
1249
932
|
const frameworkTemplatesRoot = join(import.meta.dirname, '..', '..', '..', 'framework', 'templates');
|
|
1250
933
|
const keyTemplates = [
|
|
1251
934
|
{ name: 'plan.md', path: join(frameworkTemplatesRoot, 'docs', 'plan.md') },
|
|
1252
|
-
{ name: '
|
|
935
|
+
{ name: 'morph-uiux mockups.md', path: join(frameworkTemplatesRoot, '..', 'skills', 'core', 'morph-uiux', 'references', 'mockups.md') }
|
|
1253
936
|
];
|
|
1254
937
|
const missingTemplates = [];
|
|
1255
938
|
for (const template of keyTemplates) {
|
|
@@ -1287,29 +970,10 @@ export async function doctorCommand(options = {}) {
|
|
|
1287
970
|
} else if (check.status === 'error') {
|
|
1288
971
|
console.log(chalk.red(` ✗ ${check.name}`) + chalk.gray(` (${check.msg})`));
|
|
1289
972
|
} else if (check.status === 'skip') {
|
|
1290
|
-
// "Não verificado" nunca soma em hasWarnings/hasErrors: um `gh` indisponível não muda o exit code.
|
|
1291
973
|
console.log(chalk.gray(` ○ ${check.name}`) + chalk.gray(check.msg ? ` (${check.msg})` : ''));
|
|
1292
974
|
}
|
|
1293
975
|
}
|
|
1294
976
|
|
|
1295
|
-
if (lifecycleIssues.length) {
|
|
1296
|
-
logger.blank();
|
|
1297
|
-
console.log(chalk.yellow(' Feature lifecycle inconsistencies:'));
|
|
1298
|
-
for (const issue of lifecycleIssues) {
|
|
1299
|
-
console.log(chalk.gray(` • ${issue.feature} [${issue.type}] — ${issue.detail}`));
|
|
1300
|
-
}
|
|
1301
|
-
console.log(chalk.gray(" Fix: 'morph-spec approve' (order), '--description' on create, or 'morph-spec delete' for dead scaffolds."));
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
if (prIssues?.length) {
|
|
1305
|
-
logger.blank();
|
|
1306
|
-
console.log(chalk.yellow(' Pull requests pendentes:'));
|
|
1307
|
-
for (const issue of prIssues) {
|
|
1308
|
-
console.log(chalk.gray(` • ${issue.feature} [${issue.type}] — ${issue.detail}`));
|
|
1309
|
-
}
|
|
1310
|
-
console.log(chalk.gray(' `finish --pr` abre o PR; quem encerra a feature é o merge.'));
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
977
|
logger.blank();
|
|
1314
978
|
|
|
1315
979
|
if (hasErrors) {
|
|
@@ -1,69 +1,38 @@
|
|
|
1
|
-
import { execFileSync } from 'child_process';
|
|
2
|
-
import { readFileSync } from 'fs';
|
|
3
|
-
import { join, resolve } from 'path';
|
|
4
1
|
import chalk from 'chalk';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
/** `morph/<f>` → `<f>`; `morph-task/<n>` → `task/<n>`; anything else → null. */
|
|
10
|
-
export function envKeyFromBranch(branch) {
|
|
11
|
-
if (!branch) return null;
|
|
12
|
-
const feature = branch.match(/^morph\/(.+)$/)?.[1];
|
|
13
|
-
if (feature) return feature;
|
|
14
|
-
const task = branch.match(/^morph-task\/(.+)$/)?.[1];
|
|
15
|
-
return task ? `task/${task}` : null;
|
|
16
|
-
}
|
|
2
|
+
import { execFileSync } from 'child_process';
|
|
3
|
+
import { readMorphConfig } from '../../lib/config/project-config.js';
|
|
4
|
+
import { branchEnv } from '../../lib/contract/ports.js';
|
|
17
5
|
|
|
18
|
-
function
|
|
6
|
+
function currentBranch(cwd) {
|
|
19
7
|
try {
|
|
20
|
-
|
|
8
|
+
const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
|
|
9
|
+
return branch && branch !== 'HEAD' ? branch : null;
|
|
21
10
|
} catch {
|
|
22
11
|
return null;
|
|
23
12
|
}
|
|
24
13
|
}
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
15
|
+
/** The worktree's ports and compose project, derived from the branch: null outside a branch. */
|
|
16
|
+
export function worktreeEnv(cwd = process.cwd(), branch = currentBranch(cwd)) {
|
|
17
|
+
if (!branch) return null;
|
|
18
|
+
const config = readMorphConfig(cwd) ?? {};
|
|
19
|
+
return branchEnv(branch, { stack: config.project?.stack ?? '', aliases: config.e2e?.portEnvNames });
|
|
33
20
|
}
|
|
34
21
|
|
|
35
22
|
const shq = (v) => `'${String(v).replace(/'/g, "'\\''")}'`;
|
|
23
|
+
const psq = (v) => `"${String(v).replace(/[`"$]/g, '`$&')}"`;
|
|
36
24
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return { error: 'no-feature', message: 'Nenhuma feature: passe o nome ou rode de uma branch morph/{f} / morph-task/{n}.' };
|
|
42
|
-
}
|
|
43
|
-
const common = gitCommonDir(cwd);
|
|
44
|
-
if (!common) {
|
|
45
|
-
return { error: 'not-a-git-repo', message: 'Fora de um repositório git não há bloco de portas.' };
|
|
46
|
-
}
|
|
47
|
-
const root = resolvePrimaryRoot(cwd);
|
|
48
|
-
const env = buildComposeEnv({ cwd: root, config: readConfig(root), featureName: key, gitCommonDir: common, withCredentials });
|
|
49
|
-
return { key, env };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function render(env, format) {
|
|
53
|
-
const entries = Object.entries(env);
|
|
54
|
-
if (format === 'json') return JSON.stringify(env, null, 2);
|
|
55
|
-
if (format === 'powershell') return entries.map(([k, v]) => `$env:${k}="${String(v).replace(/"/g, '`"')}"`).join('\n');
|
|
56
|
-
return entries.map(([k, v]) => `export ${k}=${shq(v)}`).join('\n');
|
|
25
|
+
export function render(env, { powershell = false } = {}) {
|
|
26
|
+
return Object.entries(env)
|
|
27
|
+
.map(([k, v]) => (powershell ? `$env:${k}=${psq(v)}` : `export ${k}=${shq(v)}`))
|
|
28
|
+
.join('\n');
|
|
57
29
|
}
|
|
58
30
|
|
|
59
|
-
export function envCommand(
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
else console.error(chalk.red(`✗ ${result.message}`));
|
|
31
|
+
export function envCommand(options = {}) {
|
|
32
|
+
const env = worktreeEnv();
|
|
33
|
+
if (!env) {
|
|
34
|
+
console.error(chalk.red('Fora de um branch (HEAD solto ou sem git): as portas vêm do nome do branch.'));
|
|
64
35
|
process.exit(1);
|
|
65
36
|
}
|
|
66
|
-
|
|
67
|
-
console.log(render(result.env, format));
|
|
68
|
-
process.exit(0);
|
|
37
|
+
console.log(options.json ? JSON.stringify(env, null, 2) : render(env, options));
|
|
69
38
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { applyContract, installPreview, planContract } from '../../lib/contract/apply.js';
|
|
3
|
+
import { installStackAssets } from '../../lib/installers/stack-assets.js';
|
|
4
|
+
|
|
5
|
+
const ACTION = { added: 'novo', updated: 'atualizado pelo scan', kept: 'mantido (editado à mão)', removed: 'removido (o scan não gera mais)' };
|
|
6
|
+
|
|
7
|
+
export function contractLines(plan) {
|
|
8
|
+
const p = plan.config.project ?? {};
|
|
9
|
+
const lines = [];
|
|
10
|
+
lines.push(`Stack: ${p.stack ?? 'não detectada (repo vazio: o init pergunta; sem terminal, use --stack)'}${p.tags?.length ? ` · tags: ${p.tags.join(', ')}` : ''}`);
|
|
11
|
+
if (p.deps?.compose) lines.push(`Dependências: docker compose -f ${p.deps.compose} -p <branch>`);
|
|
12
|
+
const tests = Array.isArray(p.tests) ? p.tests : [];
|
|
13
|
+
lines.push(tests.length ? 'Testes:' : 'Testes: nenhum comando encontrado (edite project.tests à mão)');
|
|
14
|
+
for (const t of tests) lines.push(` ${(t.tier ?? 'full').padEnd(4)} ${t.id}: ${t.cwd ? `[${t.cwd}] ` : ''}${t.command}`);
|
|
15
|
+
for (const [cat, globs] of Object.entries(p.risk ?? {})) lines.push(`Risco ${cat}: ${globs.length} caminho(s)`);
|
|
16
|
+
lines.push(`Segredos de teste: ${p.testSecrets?.length ? p.testSecrets.join(', ') : 'nenhum'}`);
|
|
17
|
+
if (p.limits) lines.push(`Limites: ${p.limits.maxScenarios} cenários, ${p.limits.maxFiles} arquivos, ${p.limits.maxIterations} tentativas, para após ${p.limits.sameErrorStop} no mesmo erro`);
|
|
18
|
+
for (const r of plan.report) lines.push(` ${r.key}: ${ACTION[r.action] ?? r.action}`);
|
|
19
|
+
return lines;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function previewLines(tags) {
|
|
23
|
+
const preview = installPreview(tags);
|
|
24
|
+
return Object.entries(preview).map(([kind, list]) => `Instala ${kind}: ${list.length ? list.join(', ') : '—'}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** `init --dry-run`: the contract and the install list, nothing written. */
|
|
28
|
+
export function initDryRun(root, { json = false } = {}) {
|
|
29
|
+
const plan = planContract(root);
|
|
30
|
+
const preview = installPreview(plan.tags);
|
|
31
|
+
if (json) {
|
|
32
|
+
console.log(JSON.stringify({ config: plan.config, report: plan.report, tags: plan.tags, install: preview }, null, 2));
|
|
33
|
+
return plan;
|
|
34
|
+
}
|
|
35
|
+
console.log(chalk.bold('morph-spec init --dry-run (nada foi gravado)'));
|
|
36
|
+
for (const line of [...contractLines(plan), ...previewLines(plan.tags)]) console.log(` ${line}`);
|
|
37
|
+
return plan;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Re-running `init`: the contract follows the repo, hand edits stay, the stack's assets are installed. */
|
|
41
|
+
export async function refreshContract(root) {
|
|
42
|
+
const plan = applyContract(root);
|
|
43
|
+
await installStackAssets(root, plan.tags);
|
|
44
|
+
console.log(chalk.green('✓ Contrato atualizado em .morph/config/config.json'));
|
|
45
|
+
for (const line of contractLines(plan)) console.log(` ${line}`);
|
|
46
|
+
return plan;
|
|
47
|
+
}
|