@polymorphism-tech/morph-spec 10.12.0 → 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 +31 -86
- 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,421 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { execFileSync } from 'child_process';
|
|
3
|
-
import { resolve } from 'path';
|
|
4
|
-
import { getFeature, updateFeature } from '../../core/state/state-manager.js';
|
|
5
|
-
import { runVerify, VerifyUsageError } from '../../lib/validators/verify-runner.js';
|
|
6
|
-
import { resolvePrimaryRoot } from '../project/worktree.js';
|
|
7
|
-
import { resolveFeatureTree } from '../../lib/worktree/feature-truth.js';
|
|
8
|
-
import { canonicalPath, readMorphConfig } from '../../lib/tasks/test-runner.js';
|
|
9
|
-
import { detectDefaultBranch, getHeadSha } from '../../lib/git/default-branch.js';
|
|
10
|
-
import { featureDiffRisk } from '../../lib/risk/diff-risk.js';
|
|
11
|
-
import { uncommittedCode } from '../../lib/ci/github-ci.js';
|
|
12
|
-
import { EVAL_RUNNER } from '../../lib/tasks/eval-node.js';
|
|
13
|
-
import { buildVerifyEvent, recordVerifyEvent, findRepeatedVerify } from '../../lib/telemetry/verify-event.js';
|
|
14
|
-
import { treeFingerprint } from '../../lib/git/tree-fingerprint.js';
|
|
15
|
-
import { HeavyBusyError } from '../../lib/heavy/gate.js';
|
|
16
|
-
import { afterHeavyRun } from '../../lib/heavy/cleanup.js';
|
|
17
|
-
import { memoryBusyHint } from '../../lib/heavy/live-stacks.js';
|
|
18
|
-
import { readHeavyConfig } from '../../../framework/hooks/shared/heavy-config.js';
|
|
19
|
-
import { reusableLocalStamp, resolvePrProof } from '../../lib/ci/ci-verify.js';
|
|
20
|
-
import { syncStackRules } from '../../lib/installers/stack-sync.js';
|
|
21
|
-
import {
|
|
22
|
-
DETACH_RUN_ENV, DETACH_STAGE_ENV, DETACH_WORKER_ENV, launchWorker, markWorkerExit, runFilesOf, superviseVerify,
|
|
23
|
-
} from '../../lib/verify/detached.js';
|
|
24
|
-
import { watchRun } from '../../lib/heavy/watchdog.js';
|
|
25
|
-
import { RESULT_SAY, TESTS, VERIFY_STEP_SAY, featureRef } from '../../../framework/hooks/shared/owner-words.js';
|
|
26
|
-
import { SESSION_MARK } from '../../../framework/hooks/shared/next-step.js';
|
|
27
|
-
import { ownerRef } from '../../../framework/hooks/shared/report-progress.js';
|
|
28
|
-
|
|
29
|
-
const detachedArgs = () => process.argv.slice(2).filter((arg) => arg !== '--detach');
|
|
30
|
-
|
|
31
|
-
async function runDetached(featureName, options) {
|
|
32
|
-
const result = await superviseVerify({ feature: featureName, args: detachedArgs() });
|
|
33
|
-
if (result.stderr) process.stderr.write(result.stderr);
|
|
34
|
-
if (result.died) {
|
|
35
|
-
const reason = 'a rodada destacada parou sem resultado';
|
|
36
|
-
if (options.json) console.log(JSON.stringify({ status: 'busy', persisted: false, reason }));
|
|
37
|
-
else console.error(chalk.yellow(`⏳ ${reason}: sem stamp, não é vermelho.`));
|
|
38
|
-
} else if (result.stdout) {
|
|
39
|
-
process.stdout.write(result.stdout);
|
|
40
|
-
}
|
|
41
|
-
process.exit(result.exitCode);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function statusIcon(status) {
|
|
45
|
-
if (status === 'pass') return chalk.green('✓');
|
|
46
|
-
if (status === 'fail') return chalk.red('✗');
|
|
47
|
-
return chalk.gray('–');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const seconds = (ms) => (ms >= 1000 ? `${(ms / 1000).toFixed(1).replace('.', ',')} s` : `${ms} ms`);
|
|
51
|
-
|
|
52
|
-
function formatVerifyResult(result, name = result.feature) {
|
|
53
|
-
const lines = [];
|
|
54
|
-
|
|
55
|
-
lines.push('');
|
|
56
|
-
lines.push(chalk.bold(`Testes automáticos de ${name}`));
|
|
57
|
-
if (result.stack) lines.push(chalk.gray(`Tecnologia: ${result.stack}`));
|
|
58
|
-
lines.push('');
|
|
59
|
-
lines.push(result.status === 'pass' ? chalk.green.bold('✓ Passou: tudo o que rodou deu certo.') : chalk.red.bold('✗ Falhou: algo não funcionou. O detalhe está abaixo.'));
|
|
60
|
-
lines.push('');
|
|
61
|
-
const env = result.nodes.tests?.environment;
|
|
62
|
-
if (env) {
|
|
63
|
-
lines.push(chalk.cyan(`Ambiente: ${env.kind} (${env.image})`));
|
|
64
|
-
lines.push('');
|
|
65
|
-
}
|
|
66
|
-
lines.push('Etapas:');
|
|
67
|
-
for (const [step, node] of Object.entries(result.nodes)) {
|
|
68
|
-
const icon = statusIcon(node.status);
|
|
69
|
-
let detail;
|
|
70
|
-
if (node.status === 'skip') {
|
|
71
|
-
detail = node.reason || '';
|
|
72
|
-
} else if (node.reason) {
|
|
73
|
-
// A green e2e still carries meaning worth showing: smoke-only vs specs,
|
|
74
|
-
// warm reuse vs rebuild. Without it, "pass" hides how much was proven.
|
|
75
|
-
detail = `${seconds(node.durationMs)} — ${node.reason}`;
|
|
76
|
-
} else {
|
|
77
|
-
detail = seconds(node.durationMs);
|
|
78
|
-
}
|
|
79
|
-
lines.push(` ${icon} ${(VERIFY_STEP_SAY[step] ?? step).padEnd(24)} ${(RESULT_SAY[node.status] ?? node.status).padEnd(9)} ${chalk.gray(detail)}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (result.feedback.length > 0) {
|
|
83
|
-
lines.push('');
|
|
84
|
-
lines.push('O que deu errado (saída das ferramentas):');
|
|
85
|
-
for (const line of result.feedback) lines.push(` ${line}`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
lines.push('');
|
|
89
|
-
return lines.join('\n');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const NOT_SAVED = {
|
|
93
|
-
filtered: 'rodou só parte dos testes (--filter)',
|
|
94
|
-
'skip-tests': 'pulou os testes (--skip-tests)',
|
|
95
|
-
'skip-build': 'pulou a compilação (--skip-build)',
|
|
96
|
-
'no-persist-flag': 'foi pedido para não gravar (--no-persist)',
|
|
97
|
-
'owner-tree-elsewhere': 'a feature mora em outra pasta (worktree); só a rodada de lá conta',
|
|
98
|
-
'unregistered-worktree': 'esta pasta não é a dona da feature; só a rodada da pasta dona conta',
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
function notSavedSay(reason) {
|
|
102
|
-
if (NOT_SAVED[reason]) return NOT_SAVED[reason];
|
|
103
|
-
if (String(reason).startsWith('record-baseline')) return 'a gravação da linha de base não aconteceu';
|
|
104
|
-
return reason;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const samePath = (a, b) => canonicalPath(a).replace(/\\/g, '/') === canonicalPath(b).replace(/\\/g, '/');
|
|
108
|
-
|
|
109
|
-
// Persists only in the tree that OWNS the feature (`resolveFeatureTree`, asked from the PRIMARY
|
|
110
|
-
// ROOT so every tree agrees): another tree's copy is not what the gates read, and writing it
|
|
111
|
-
// would merge-conflict with the owner's.
|
|
112
|
-
function decidePersistence({ cwd, featureName, noPersist }) {
|
|
113
|
-
if (noPersist) return { persist: false, reason: 'no-persist-flag' };
|
|
114
|
-
|
|
115
|
-
const root = resolvePrimaryRoot(cwd);
|
|
116
|
-
const owner = resolveFeatureTree(featureName, root);
|
|
117
|
-
if (owner.tree && samePath(owner.tree, cwd)) return { persist: true, reason: null };
|
|
118
|
-
return { persist: false, reason: samePath(root, cwd) ? 'owner-tree-elsewhere' : 'unregistered-worktree' };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function baselineStampBlock(baseline) {
|
|
122
|
-
if (baseline?.recorded) return null;
|
|
123
|
-
return baseline?.reason ? `record-baseline: ${baseline.reason}` : 'record-baseline';
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// The single writer of both node maps the schema fixes (`verification.nodes` and the history
|
|
127
|
-
// entry): a stamp missing a node the history has is a half-truth the gate reads as fact.
|
|
128
|
-
function nodeStatuses(result) {
|
|
129
|
-
return {
|
|
130
|
-
build: result.nodes.build.status,
|
|
131
|
-
tests: result.nodes.tests.status,
|
|
132
|
-
validators: result.nodes.validators.status,
|
|
133
|
-
e2e: result.nodes.e2e.status,
|
|
134
|
-
evals: evalsStatusOf(result),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// `'skip'` = eval nodes declared but not run; `null` = no eval node declared. A skipped eval
|
|
139
|
-
// leaves the tests rollup green, so the gate needs this split to tell them apart.
|
|
140
|
-
function evalsStatusOf(result) {
|
|
141
|
-
const runs = (result.nodes.tests?.runs || []).filter((run) => run.runner === EVAL_RUNNER);
|
|
142
|
-
if (runs.length === 0) return null;
|
|
143
|
-
if (runs.some((run) => run.status === 'fail')) return 'fail';
|
|
144
|
-
if (runs.some((run) => run.status === 'pass')) return 'pass';
|
|
145
|
-
return 'skip';
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// First match wins; each keeps the stamp from being written, with its `reason`.
|
|
149
|
-
const PARTIAL_RUN_FLAGS = [['filter', 'filtered'], ['skipTests', 'skip-tests'], ['skipBuild', 'skip-build']];
|
|
150
|
-
|
|
151
|
-
const CI_EXCLUSIVE_FLAGS = [
|
|
152
|
-
['filter', '--filter'], ['skipTests', '--skip-tests'], ['skipBuild', '--skip-build'], ['skipE2e', '--skip-e2e'],
|
|
153
|
-
['freshE2e', '--fresh-e2e'], ['linux', '--linux'], ['recordBaseline', '--record-baseline'], ['refreshCache', '--refresh-cache'],
|
|
154
|
-
['noPersist', '--no-persist'], ['fresh', '--fresh'], ['affected', '--affected'],
|
|
155
|
-
];
|
|
156
|
-
|
|
157
|
-
async function runLocalVerify(featureName, options, fingerprint) {
|
|
158
|
-
try {
|
|
159
|
-
return await runVerify(process.cwd(), featureName, {
|
|
160
|
-
fingerprint,
|
|
161
|
-
fresh: options.fresh,
|
|
162
|
-
affected: options.affected,
|
|
163
|
-
excludeNodes: options.excludeNodes,
|
|
164
|
-
timeout: options.timeout,
|
|
165
|
-
skipTests: options.skipTests,
|
|
166
|
-
skipBuild: options.skipBuild,
|
|
167
|
-
skipE2e: options.skipE2e,
|
|
168
|
-
freshE2e: options.freshE2e,
|
|
169
|
-
filter: options.filter,
|
|
170
|
-
recordBaseline: options.recordBaseline,
|
|
171
|
-
refreshCache: options.refreshCache,
|
|
172
|
-
linux: options.linux,
|
|
173
|
-
linuxImage: options.linuxImage,
|
|
174
|
-
});
|
|
175
|
-
} catch (err) {
|
|
176
|
-
// Exit 2, never a verdict: a `--filter` that selects nothing must not print green or red.
|
|
177
|
-
if (err instanceof VerifyUsageError) {
|
|
178
|
-
console.error(chalk.red(`\n❌ ${err.message}\n`));
|
|
179
|
-
process.exit(2);
|
|
180
|
-
}
|
|
181
|
-
// Ocupado não é veredito: nada foi verificado, então não há stamp nem
|
|
182
|
-
// evento, e o exit 3 nunca é "vermelho".
|
|
183
|
-
if (err instanceof HeavyBusyError) {
|
|
184
|
-
if (options.json) {
|
|
185
|
-
const holders = err.holders.map(({ pid, label, feature, node, since }) => ({ pid, label, feature, node, since }));
|
|
186
|
-
console.log(JSON.stringify({
|
|
187
|
-
status: 'busy', persisted: false, busy: { reason: err.reason, holders, freeGb: err.freeGb, waitedMs: err.waitedMs },
|
|
188
|
-
}, null, 2));
|
|
189
|
-
}
|
|
190
|
-
console.error(chalk.yellow(`\n⏳ ${TESTS[0].toUpperCase()}${TESTS.slice(1)} não rodaram: ${err.message}. Isso não é falha: a máquina estava ocupada e a fila já esperou o prazo dela.`));
|
|
191
|
-
console.error(chalk.gray(` ${SESSION_MARK} não repita em laço; siga sem esta rodada e avise o usuário (\`morph-spec heavy status\` mostra quem segura os slots).\n`));
|
|
192
|
-
const hint = memoryBusyHint(err, process.cwd());
|
|
193
|
-
if (hint) console.error(chalk.yellow(`${hint}\n`));
|
|
194
|
-
process.exit(3);
|
|
195
|
-
}
|
|
196
|
-
throw err;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function exitWithReusedStamp(featureName, reused, why, options) {
|
|
201
|
-
console.error(chalk.green(`\n↪ ${why} (sha ${reused.sha.slice(0, 8)}, ${reused.ts}): nada mudou fora de .morph/ desde aquela rodada verde.\n`));
|
|
202
|
-
if (options.json) {
|
|
203
|
-
console.log(JSON.stringify({
|
|
204
|
-
feature: featureName, status: reused.status, nodes: reused.nodes, e2eReason: reused.e2eReason ?? null,
|
|
205
|
-
reused: { sha: reused.sha, ts: reused.ts, source: reused.source ?? 'local' }, persisted: false, reason: 'stamp-reused',
|
|
206
|
-
}, null, 2));
|
|
207
|
-
}
|
|
208
|
-
process.exit(0);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const E2E_PATH = /(^|\/)(e2e|playwright)\/|\.spec\.[cm]?[jt]sx?$/i;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* When a green affected run stands for the gate: over a low-risk diff it IS the proof (the e2e waiver is
|
|
215
|
-
* classified, never "requested"); over a green complete stamp it renews it when the delta since that stamp
|
|
216
|
-
* reaches only what it ran (selection is from the merge-base, so it covers the delta; e2e it never runs).
|
|
217
|
-
* Only a committed tree: the stamp names a SHA.
|
|
218
|
-
*/
|
|
219
|
-
function affectedProof(cwd, prev, stamp) {
|
|
220
|
-
const dirty = uncommittedCode(cwd);
|
|
221
|
-
if (!stamp.sha || dirty === null || dirty.length > 0) return null;
|
|
222
|
-
const risk = featureDiffRisk(cwd, detectDefaultBranch(cwd));
|
|
223
|
-
if (risk && ['low', 'none'].includes(risk.level)) {
|
|
224
|
-
return { ...stamp, scope: 'affected', e2eReason: 'not applicable: diff de baixo risco, sem lógica (verify --affected)' };
|
|
225
|
-
}
|
|
226
|
-
if (prev?.status !== 'pass' || !prev.sha || prev.pendingPr) return null;
|
|
227
|
-
let delta;
|
|
228
|
-
try {
|
|
229
|
-
delta = execFileSync('git', ['diff', '--name-only', '--no-renames', prev.sha, stamp.sha, '--', '.', ':(exclude).morph'], { cwd, stdio: 'pipe' })
|
|
230
|
-
.toString().split('\n').map((l) => l.trim()).filter(Boolean);
|
|
231
|
-
} catch {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
if (delta.some((p) => E2E_PATH.test(p))) return null;
|
|
235
|
-
return { ...prev, sha: stamp.sha, ts: stamp.ts, renewedBy: 'affected' };
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Exit 2 is "the command cannot mean what you typed" (unknown feature, `--filter` matching
|
|
239
|
-
// nothing, `--record-baseline` without config.json, `--linux` without Docker): never a verdict.
|
|
240
|
-
export async function verifyCommand(featureName, options = {}) {
|
|
241
|
-
const stage = process.env[DETACH_STAGE_ENV];
|
|
242
|
-
if (stage === 'launch') {
|
|
243
|
-
launchWorker({ argv: process.argv.slice(2) });
|
|
244
|
-
process.exit(0);
|
|
245
|
-
}
|
|
246
|
-
if (stage === 'watchdog') {
|
|
247
|
-
const { exit, err } = runFilesOf(process.env[DETACH_RUN_ENV]);
|
|
248
|
-
await watchRun({
|
|
249
|
-
workerPid: Number(process.env[DETACH_WORKER_ENV]), exitFile: exit, errFile: err,
|
|
250
|
-
projectPath: process.cwd(), feature: featureName, config: readHeavyConfig(process.cwd()),
|
|
251
|
-
});
|
|
252
|
-
process.exit(0);
|
|
253
|
-
}
|
|
254
|
-
if (stage === 'worker') {
|
|
255
|
-
markWorkerExit(process.env[DETACH_RUN_ENV]);
|
|
256
|
-
// A verify nested in a test suite must not report as this run.
|
|
257
|
-
delete process.env[DETACH_STAGE_ENV];
|
|
258
|
-
delete process.env[DETACH_RUN_ENV];
|
|
259
|
-
// Out of a shell's reach there is no call timeout to beat, so the queue never needs to refuse.
|
|
260
|
-
process.env.MORPH_HEAVY_WAIT_SEC = String(readHeavyConfig(process.cwd()).detachedWaitMinutes * 60);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
let feature;
|
|
264
|
-
try {
|
|
265
|
-
feature = getFeature(featureName);
|
|
266
|
-
} catch {
|
|
267
|
-
feature = null;
|
|
268
|
-
}
|
|
269
|
-
if (!feature) {
|
|
270
|
-
console.error(chalk.red(`\n❌ Não achei a feature ${featureName} neste projeto.\n`));
|
|
271
|
-
process.exit(2);
|
|
272
|
-
}
|
|
273
|
-
// A green run of this same tree, complete or affected, already covers what an affected run selects.
|
|
274
|
-
if (options.affected && !options.fresh) {
|
|
275
|
-
const fresh = reusableLocalStamp(process.cwd(), feature.verification)
|
|
276
|
-
?? reusableLocalStamp(process.cwd(), feature.verifications?.affected);
|
|
277
|
-
if (fresh) exitWithReusedStamp(featureName, fresh, 'rodada verde deste mesmo tree — não roda de novo', options);
|
|
278
|
-
}
|
|
279
|
-
if (options.detach) await runDetached(featureName, options);
|
|
280
|
-
|
|
281
|
-
syncStackRules(process.cwd(), { persistTags: false, log: (line) => console.error(chalk.gray(line)) });
|
|
282
|
-
|
|
283
|
-
if (options.ci) {
|
|
284
|
-
const conflict = CI_EXCLUSIVE_FLAGS.find(([flag]) => options[flag])?.[1];
|
|
285
|
-
if (conflict) {
|
|
286
|
-
console.error(chalk.red(`\n❌ --ci é a prova completa da feature; não combina com ${conflict}\n`));
|
|
287
|
-
process.exit(2);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Nothing is pushed here: the suites the PR proves are waited for by `finish --pr`, one CI run per SHA.
|
|
292
|
-
let prProof = null;
|
|
293
|
-
if (options.ci) {
|
|
294
|
-
const fresh = reusableLocalStamp(process.cwd(), feature.verification);
|
|
295
|
-
if (fresh) exitWithReusedStamp(featureName, fresh, 'stamp verde e fresco — não roda de novo', options);
|
|
296
|
-
prProof = resolvePrProof(process.cwd(), featureName, readMorphConfig(process.cwd()));
|
|
297
|
-
if (!prProof) console.error(chalk.yellow('\n↪ sem project.prChecks — verify local completo.\n'));
|
|
298
|
-
else if (prProof.local) console.error(chalk.yellow(`\n↪ completa local: ${prProof.local}\n`));
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Taken before the run: it is the tree the run is about to read.
|
|
302
|
-
const fingerprint = treeFingerprint(process.cwd());
|
|
303
|
-
|
|
304
|
-
const pendingPr = prProof?.covers ? prProof : null;
|
|
305
|
-
const result = await runLocalVerify(featureName, { ...options, excludeNodes: pendingPr?.covers }, fingerprint);
|
|
306
|
-
|
|
307
|
-
const cleanup = afterHeavyRun({
|
|
308
|
-
projectPath: process.cwd(),
|
|
309
|
-
config: readHeavyConfig(process.cwd()),
|
|
310
|
-
onlyUnderPressure: true,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
// Only a complete run may stand in for the proof the review gate asks for: the affected one keeps its own record.
|
|
314
|
-
const scopedRun = result.scope === 'affected';
|
|
315
|
-
const historyKey = scopedRun ? 'verifications.affected' : 'verifications.feature';
|
|
316
|
-
// A run that measured only part of the suite must not stand in for the proof a gate asks for:
|
|
317
|
-
// --filter and --skip-*, or a --record-baseline that recorded nothing; --no-persist keeps its own reason.
|
|
318
|
-
const partialRun = options.noPersist ? null : PARTIAL_RUN_FLAGS.find(([flag]) => options[flag])?.[1] ?? null;
|
|
319
|
-
const baselineBlock = options.recordBaseline ? baselineStampBlock(result.baseline) : null;
|
|
320
|
-
const { persist, reason } = baselineBlock
|
|
321
|
-
? { persist: false, reason: baselineBlock }
|
|
322
|
-
: partialRun
|
|
323
|
-
? { persist: false, reason: partialRun }
|
|
324
|
-
: decidePersistence({ cwd: process.cwd(), featureName, noPersist: options.noPersist });
|
|
325
|
-
|
|
326
|
-
let compact = null;
|
|
327
|
-
if (persist) {
|
|
328
|
-
const prevEntry = feature.verifications?.[scopedRun ? 'affected' : 'feature'];
|
|
329
|
-
const now = new Date().toISOString();
|
|
330
|
-
compact = {
|
|
331
|
-
status: result.status,
|
|
332
|
-
nodes: nodeStatuses(result),
|
|
333
|
-
attempts: (prevEntry?.attempts ?? 0) + 1,
|
|
334
|
-
failStreak: result.status === 'fail' ? (prevEntry?.failStreak ?? 0) + 1 : 0,
|
|
335
|
-
updatedAt: now,
|
|
336
|
-
...(scopedRun ? { sha: getHeadSha(process.cwd()) } : {}),
|
|
337
|
-
};
|
|
338
|
-
await updateFeature(featureName, historyKey, compact);
|
|
339
|
-
|
|
340
|
-
// `sha` ties the stamp to the exact commit (null without git: fail-open). `nodes` and `e2eReason`
|
|
341
|
-
// exist because a skipped e2e does not fail the rollup; a null reason ON A SKIP reads as a
|
|
342
|
-
// waiver without motive, which risk-detector.js refuses.
|
|
343
|
-
const stamp = {
|
|
344
|
-
status: result.status,
|
|
345
|
-
nodes: nodeStatuses(result),
|
|
346
|
-
e2eReason: result.nodes.e2e.status === 'skip' ? (result.nodes.e2e.reason ?? null) : null,
|
|
347
|
-
sha: getHeadSha(process.cwd()),
|
|
348
|
-
ts: now,
|
|
349
|
-
...(result.flaky?.length ? { flaky: result.flaky } : {}),
|
|
350
|
-
...(pendingPr && result.status === 'pass' ? { pendingPr } : {}),
|
|
351
|
-
};
|
|
352
|
-
if (!scopedRun) await updateFeature(featureName, 'verification', stamp);
|
|
353
|
-
else if (result.status === 'pass') {
|
|
354
|
-
const proof = affectedProof(process.cwd(), feature.verification, stamp);
|
|
355
|
-
if (proof) {
|
|
356
|
-
await updateFeature(featureName, 'verification', proof);
|
|
357
|
-
console.error(chalk.gray(proof.renewedBy ? `↪ carimbo renovado: a rodada afetada cobre o delta desde ${feature.verification.sha.slice(0, 8)}`
|
|
358
|
-
: '↪ diff de baixo risco: a rodada afetada é a prova do gate'));
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// A run over the exact tree of the previous one proves nothing
|
|
364
|
-
// new. Advisory only: the stamp and the exit code are the same either way.
|
|
365
|
-
let repeatOf = null;
|
|
366
|
-
try {
|
|
367
|
-
const cwd = process.cwd();
|
|
368
|
-
if (persist) repeatOf = findRepeatedVerify(cwd, { feature: featureName, fingerprint });
|
|
369
|
-
const tree = resolve(cwd).replace(/\\/g, '/') === resolvePrimaryRoot(cwd) ? 'root' : 'worktree';
|
|
370
|
-
recordVerifyEvent(cwd, buildVerifyEvent(result, { sha: getHeadSha(cwd), tree, persisted: persist && !scopedRun, reason: scopedRun ? 'affected' : reason, fingerprint, source: 'local' }));
|
|
371
|
-
} catch { /* telemetry never changes the verdict */ }
|
|
372
|
-
|
|
373
|
-
// The refusal always goes to stderr, so it survives --json (whose stdout has
|
|
374
|
-
// to stay parseable) and is never something the reader has to go looking for.
|
|
375
|
-
if (result.baseline && !result.baseline.recorded) {
|
|
376
|
-
console.error(chalk.red(`
|
|
377
|
-
❌ baseline não gravada: ${result.baseline.reason}
|
|
378
|
-
`));
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
if (options.json) {
|
|
382
|
-
// Each node's tail is already in `feedback`, prefixed by node: printing it twice doubles what the session ingests.
|
|
383
|
-
const withoutOutput = ({ output: _, ...rest }) => rest;
|
|
384
|
-
const nodes = Object.fromEntries(Object.entries(result.nodes).map(([k, node]) => [k,
|
|
385
|
-
Array.isArray(node.runs) ? { ...withoutOutput(node), runs: node.runs.map(withoutOutput) } : withoutOutput(node)]));
|
|
386
|
-
const output = {
|
|
387
|
-
...result, nodes, persisted: persist, ...(persist ? {} : { reason }), repeatOf, cleanup,
|
|
388
|
-
...(pendingPr ? { pendingPr } : {}),
|
|
389
|
-
};
|
|
390
|
-
console.log(JSON.stringify(output, null, 2));
|
|
391
|
-
} else {
|
|
392
|
-
console.log(formatVerifyResult(result, ownerRef(process.cwd(), featureName, feature)));
|
|
393
|
-
if (cleanup.status !== 'skipped') {
|
|
394
|
-
const mark = cleanup.status === 'ran' ? chalk.green('✓') : chalk.yellow('⚠');
|
|
395
|
-
console.log(chalk.gray(`${mark} dotnet build-server shutdown: ${cleanup.status}${cleanup.reason ? ` (${cleanup.reason})` : ''}\n`));
|
|
396
|
-
}
|
|
397
|
-
if (repeatOf) {
|
|
398
|
-
console.log(chalk.yellow(`⚠️ O código é o mesmo da rodada de ${repeatOf.ts} (${RESULT_SAY[repeatOf.status] ?? repeatOf.status}). Esta rodada não prova nada novo.`));
|
|
399
|
-
console.log(chalk.gray(` ${SESSION_MARK} reuse o resultado anterior, a menos que o ambiente (Docker, banco, serviço externo) tenha mudado.\n`));
|
|
400
|
-
}
|
|
401
|
-
if (result.baseline?.recorded) {
|
|
402
|
-
for (const u of result.baseline.updates) {
|
|
403
|
-
console.log(chalk.green(` baseline ${u.id}: ${u.from ?? '—'} → ${u.to}`));
|
|
404
|
-
}
|
|
405
|
-
for (const id of result.baseline.removed ?? []) {
|
|
406
|
-
console.log(chalk.gray(` baseline ${id}: removida (runner sem baseline, só o piso zero)`));
|
|
407
|
-
}
|
|
408
|
-
console.log(chalk.gray(`Gravada em ${result.baseline.path}
|
|
409
|
-
`));
|
|
410
|
-
}
|
|
411
|
-
if (persist) {
|
|
412
|
-
console.log(chalk.gray(`Resultado gravado (${compact.attempts}ª rodada${scopedRun ? ', só o que a mudança alcança' : ''}).\n`));
|
|
413
|
-
} else {
|
|
414
|
-
console.log(chalk.yellow(`⚠️ Resultado não gravado (${reason}): ${notSavedSay(reason)}. A aprovação só aceita uma rodada completa e gravada.\n`));
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// A recording asked for and not made fails the invocation, even when the run was green.
|
|
419
|
-
const baselineRefused = Boolean(result.baseline && !result.baseline.recorded);
|
|
420
|
-
process.exit(result.status === 'pass' && !baselineRefused ? 0 : 1);
|
|
421
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const blank = (v) => v === undefined || v === null || String(v).trim() === '';
|
|
2
|
-
|
|
3
|
-
// `workType` is excluded on purpose: absent, it defaults to `feature`.
|
|
4
|
-
export function missingIdentity(feature) {
|
|
5
|
-
const missing = [];
|
|
6
|
-
if (blank(feature?.description)) missing.push('description');
|
|
7
|
-
if (blank(feature?.createdAt)) missing.push('createdAt');
|
|
8
|
-
if (blank(feature?.name)) missing.push('name');
|
|
9
|
-
return missing;
|
|
10
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export const GATE_PREREQ = {
|
|
2
|
-
plan: [],
|
|
3
|
-
uiux: ['plan'],
|
|
4
|
-
review: ['plan'],
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const isApproved = (gates, name) => gates?.[name]?.approved === true;
|
|
8
|
-
|
|
9
|
-
export function unmetPrereqs(gate, gates) {
|
|
10
|
-
const prereqs = GATE_PREREQ[gate] || [];
|
|
11
|
-
return prereqs.filter((p) => !isApproved(gates, p));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function gateOrderViolations(gates) {
|
|
15
|
-
if (!gates || typeof gates !== 'object') return [];
|
|
16
|
-
const out = [];
|
|
17
|
-
for (const gate of Object.keys(GATE_PREREQ)) {
|
|
18
|
-
if (!isApproved(gates, gate)) continue;
|
|
19
|
-
const missing = GATE_PREREQ[gate].filter((p) => !isApproved(gates, p));
|
|
20
|
-
if (missing.length) out.push({ gate, missing });
|
|
21
|
-
}
|
|
22
|
-
return out;
|
|
23
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'child_process';
|
|
2
|
-
import { existsSync, readdirSync, readFileSync, statSync } from 'fs';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import { gateOrderViolations } from './gate-order.js';
|
|
5
|
-
import { missingIdentity } from './feature-identity.js';
|
|
6
|
-
import { detectDefaultBranch } from '../../lib/git/default-branch.js';
|
|
7
|
-
import { commitsAhead, resolveBaseRef } from '../../lib/git/branch-classifier.js';
|
|
8
|
-
|
|
9
|
-
function operationalShape(fj) {
|
|
10
|
-
const gates = {};
|
|
11
|
-
for (const [g, v] of Object.entries(fj?.approvalGates || {})) gates[g] = v?.approved === true;
|
|
12
|
-
return JSON.stringify({ status: fj?.status ?? null, gates });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Compares only status and approved gates (bytes and timestamps are not drift).
|
|
16
|
-
// Fail-open: no repo, branch, blob or parseable JSON means no issue.
|
|
17
|
-
function branchDrift(baseDir, feature, rootFj) {
|
|
18
|
-
const branch = `morph/${feature}`;
|
|
19
|
-
try {
|
|
20
|
-
const current = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: baseDir, stdio: 'pipe' })
|
|
21
|
-
.toString().trim();
|
|
22
|
-
if (current === branch) return null;
|
|
23
|
-
|
|
24
|
-
execFileSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${branch}`], { cwd: baseDir, stdio: 'pipe' });
|
|
25
|
-
|
|
26
|
-
const raw = execFileSync('git', ['show', `${branch}:.morph/features/${feature}/feature.json`], {
|
|
27
|
-
cwd: baseDir, stdio: 'pipe',
|
|
28
|
-
}).toString();
|
|
29
|
-
const branchFj = JSON.parse(raw);
|
|
30
|
-
|
|
31
|
-
if (operationalShape(branchFj) === operationalShape(rootFj)) return null;
|
|
32
|
-
return `root copy disagrees with ${branch} (status/gates) — the branch is authoritative; `
|
|
33
|
-
+ `rode \`git show ${branch}:.morph/features/${feature}/feature.json\` para ver`;
|
|
34
|
-
} catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// A dead scaffold and a feature born minutes ago have the same shape; only age tells them apart.
|
|
40
|
-
const ABANDONED_SCAFFOLD_MIN_AGE_MS = 24 * 60 * 60 * 1000;
|
|
41
|
-
|
|
42
|
-
function lastTouched(fdir, fj) {
|
|
43
|
-
let newest = 0;
|
|
44
|
-
for (const ts of [fj?.updatedAt, fj?.createdAt]) {
|
|
45
|
-
const t = ts ? Date.parse(ts) : NaN;
|
|
46
|
-
if (!Number.isNaN(t)) newest = Math.max(newest, t);
|
|
47
|
-
}
|
|
48
|
-
if (newest) return newest;
|
|
49
|
-
try { return statSync(fdir).mtimeMs; } catch { return 0; }
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Files, not entries: `create` scaffolds the phase folders empty.
|
|
53
|
-
function hasArtifacts(fdir) {
|
|
54
|
-
let entries;
|
|
55
|
-
try { entries = readdirSync(fdir, { withFileTypes: true }); } catch { return false; }
|
|
56
|
-
for (const e of entries) {
|
|
57
|
-
if (e.isDirectory()) {
|
|
58
|
-
if (hasArtifacts(join(fdir, e.name))) return true;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (e.name === 'feature.json') continue;
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// `null` when git cannot answer: "cannot prove" must never read as "proved zero".
|
|
68
|
-
function ownCommitCount(baseDir, branch) {
|
|
69
|
-
try {
|
|
70
|
-
execFileSync('git', ['rev-parse', '--git-dir'], { cwd: baseDir, stdio: 'pipe' });
|
|
71
|
-
} catch {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
const baseRef = resolveBaseRef(detectDefaultBranch(baseDir), baseDir);
|
|
75
|
-
if (!baseRef) return null;
|
|
76
|
-
try {
|
|
77
|
-
execFileSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${branch}`], { cwd: baseDir, stdio: 'pipe' });
|
|
78
|
-
} catch {
|
|
79
|
-
return 0; // the branch never existed: nothing was committed on it
|
|
80
|
-
}
|
|
81
|
-
return commitsAhead(baseRef, branch, baseDir);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function abandonedScaffold(baseDir, feature, fdir, fj) {
|
|
85
|
-
if (fj?.status !== 'in_progress') return null;
|
|
86
|
-
|
|
87
|
-
// A gate stamped `policy:{workType}` at birth was never a decision, so it is not progress.
|
|
88
|
-
const decided = Object.values(fj.approvalGates || {}).some(
|
|
89
|
-
(g) => g?.approved === true && !String(g?.approvedBy ?? '').startsWith('policy:'),
|
|
90
|
-
);
|
|
91
|
-
if (decided) return null;
|
|
92
|
-
|
|
93
|
-
if (hasArtifacts(fdir)) return null;
|
|
94
|
-
const wtFeatureDir = fj.worktree?.path
|
|
95
|
-
? join(fj.worktree.path, '.morph', 'features', feature)
|
|
96
|
-
: null;
|
|
97
|
-
if (wtFeatureDir && existsSync(wtFeatureDir) && hasArtifacts(wtFeatureDir)) return null;
|
|
98
|
-
|
|
99
|
-
const age = Date.now() - lastTouched(fdir, fj);
|
|
100
|
-
if (age < ABANDONED_SCAFFOLD_MIN_AGE_MS) return null;
|
|
101
|
-
|
|
102
|
-
const branch = fj.worktree?.branch || `morph/${feature}`;
|
|
103
|
-
if (ownCommitCount(baseDir, branch) !== 0) return null;
|
|
104
|
-
|
|
105
|
-
const days = Math.floor(age / (24 * 60 * 60 * 1000));
|
|
106
|
-
return `in_progress há ${days}d sem nada produzido: 0 artefatos, 0 gates aprovados `
|
|
107
|
-
+ `e \`${branch}\` sem commit próprio — rode \`morph-spec delete ${feature} --archive\` `
|
|
108
|
-
+ 'ou retome a feature';
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function auditFeatureLifecycle(baseDir = process.cwd()) {
|
|
112
|
-
const issues = [];
|
|
113
|
-
const featuresDir = join(baseDir, '.morph', 'features');
|
|
114
|
-
const onDisk = new Set();
|
|
115
|
-
|
|
116
|
-
if (existsSync(featuresDir)) {
|
|
117
|
-
for (const name of readdirSync(featuresDir)) {
|
|
118
|
-
const fdir = join(featuresDir, name);
|
|
119
|
-
try {
|
|
120
|
-
if (!statSync(fdir).isDirectory()) continue;
|
|
121
|
-
} catch { continue; }
|
|
122
|
-
|
|
123
|
-
const fjPath = join(fdir, 'feature.json');
|
|
124
|
-
if (!existsSync(fjPath)) {
|
|
125
|
-
issues.push({ feature: name, type: 'orphan-folder', detail: 'folder has no feature.json' });
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
onDisk.add(name);
|
|
129
|
-
|
|
130
|
-
let fj;
|
|
131
|
-
try {
|
|
132
|
-
fj = JSON.parse(readFileSync(fjPath, 'utf8'));
|
|
133
|
-
} catch {
|
|
134
|
-
issues.push({ feature: name, type: 'corrupt', detail: 'feature.json is not valid JSON' });
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const drift = branchDrift(baseDir, name, fj);
|
|
139
|
-
if (drift) issues.push({ feature: name, type: 'branch-drift', detail: drift });
|
|
140
|
-
|
|
141
|
-
const dead = abandonedScaffold(baseDir, name, fdir, fj);
|
|
142
|
-
if (dead) issues.push({ feature: name, type: 'abandoned-scaffold', detail: dead });
|
|
143
|
-
|
|
144
|
-
const miss = missingIdentity(fj);
|
|
145
|
-
if (miss.length) {
|
|
146
|
-
issues.push({ feature: name, type: 'identity', detail: `missing ${miss.join(', ')}` });
|
|
147
|
-
}
|
|
148
|
-
for (const v of gateOrderViolations(fj.approvalGates)) {
|
|
149
|
-
issues.push({
|
|
150
|
-
feature: name,
|
|
151
|
-
type: 'gate-order',
|
|
152
|
-
detail: `${v.gate} approved but ${v.missing.join(', ')} pending`,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const rootPath = join(baseDir, '.morph', 'state.json');
|
|
159
|
-
if (existsSync(rootPath)) {
|
|
160
|
-
try {
|
|
161
|
-
const root = JSON.parse(readFileSync(rootPath, 'utf8'));
|
|
162
|
-
for (const name of Object.keys(root.features || {})) {
|
|
163
|
-
if (!onDisk.has(name)) {
|
|
164
|
-
issues.push({ feature: name, type: 'stale-index', detail: 'in state.json index but no feature folder' });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
} catch { }
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return issues;
|
|
171
|
-
}
|