@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,248 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
3
|
-
import { join, relative } from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import { getFeature, setApprovalGate, derivePhase } from '../../core/state/state-manager.js';
|
|
6
|
-
import { unmetPrereqs } from '../../core/state/gate-order.js';
|
|
7
|
-
import { OUTPUT_SCHEMA } from '../../core/paths/output-schema.js';
|
|
8
|
-
import { assertOwnerTree, ownerTreeRefusalLines } from '../../lib/worktree/feature-truth.js';
|
|
9
|
-
import { uiuxAutoApprovalBlock } from '../../lib/specs/screen-checklist.js';
|
|
10
|
-
import { seedDesignArtifacts } from '../../lib/specs/design-seed.js';
|
|
11
|
-
import { implementProgress, ownerRef, reportPath, reportSkeleton } from '../../../framework/hooks/shared/report-progress.js';
|
|
12
|
-
import { autoApprovalRefusal, printRefusal } from './auto-approval.js';
|
|
13
|
-
import { seedDotnetBuildIgnores } from '../../lib/stack/dotnet-build-ignores.js';
|
|
14
|
-
import { GATE_NAME, PHASE_NAME, approvedBySay, STATUS_SAY, scenarioLabel } from '../../../framework/hooks/shared/owner-words.js';
|
|
15
|
-
import { SESSION_MARK } from '../../../framework/hooks/shared/next-step.js';
|
|
16
|
-
|
|
17
|
-
const ARTIFACT_SAY = {
|
|
18
|
-
'plan.md': 'o plano',
|
|
19
|
-
'checks.json': 'a lista de cenários do plano (gerada pela validação do plano)',
|
|
20
|
-
'report.md': 'o progresso da construção',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function missingLines(missing, featurePath) {
|
|
24
|
-
const lines = missing.filter((rel) => !rel.startsWith('3-implement/report.md ('))
|
|
25
|
-
.map((rel) => `Falta ${ARTIFACT_SAY[rel.split('/').pop()] ?? rel}.`);
|
|
26
|
-
const progress = missing.some((rel) => rel.startsWith('3-implement/report.md (')) ? implementProgress(featurePath) : null;
|
|
27
|
-
for (const c of progress?.checks ?? []) {
|
|
28
|
-
if (c.status !== 'feito') lines.push(`${scenarioLabel(c)}: ${STATUS_SAY[c.status] ?? c.status}.`);
|
|
29
|
-
}
|
|
30
|
-
return lines;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const FRAMEWORK_DIR = fileURLToPath(new URL('../../../framework/', import.meta.url));
|
|
34
|
-
|
|
35
|
-
// `implement` has no gate: advancing from it only scaffolds the review folder.
|
|
36
|
-
const PHASE_GATE = { plan: 'plan', uiux: 'uiux', review: 'review' };
|
|
37
|
-
|
|
38
|
-
const NEXT_PHASE_DIR = {
|
|
39
|
-
plan: '3-implement',
|
|
40
|
-
uiux: '3-implement',
|
|
41
|
-
implement: '4-review',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// Data-driven from phases.json so the list never drifts from the phase definition. Fail-open:
|
|
45
|
-
// an unreadable phases.json yields an empty list instead of blocking every advance.
|
|
46
|
-
function missingPhaseArtifacts(phase, featurePath) {
|
|
47
|
-
try {
|
|
48
|
-
const phasesPath = join(FRAMEWORK_DIR, 'phases.json');
|
|
49
|
-
const phases = JSON.parse(readFileSync(phasesPath, 'utf8')).phases || {};
|
|
50
|
-
const required = phases[phase]?.requiredOutputs || [];
|
|
51
|
-
const missing = [];
|
|
52
|
-
for (const outputType of required) {
|
|
53
|
-
// An unknown key is skipped rather than guessed at.
|
|
54
|
-
const entry = OUTPUT_SCHEMA[outputType];
|
|
55
|
-
if (!entry?.filename || !entry?.phaseDir) continue;
|
|
56
|
-
const rel = `${entry.phaseDir}/${entry.filename}`;
|
|
57
|
-
if (!existsSync(join(featurePath, entry.phaseDir, entry.filename))) missing.push(rel);
|
|
58
|
-
}
|
|
59
|
-
if (phase === 'implement') missing.push(...unfinishedScenarios(featurePath));
|
|
60
|
-
return missing;
|
|
61
|
-
} catch {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function unfinishedScenarios(featurePath) {
|
|
67
|
-
const progress = implementProgress(featurePath);
|
|
68
|
-
if (!progress) return ['2-plan/checks.json'];
|
|
69
|
-
const open = progress.checks.filter((c) => c.status !== 'feito').map((c) => c.id);
|
|
70
|
-
return open.length ? [`3-implement/report.md (${open.join(', ')} não feito)`] : [];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function seedReport(featurePath, featureName) {
|
|
74
|
-
const path = reportPath(featurePath);
|
|
75
|
-
if (existsSync(path)) return;
|
|
76
|
-
const progress = implementProgress(featurePath);
|
|
77
|
-
if (progress) writeFileSync(path, reportSkeleton(featureName, progress.checks.map((c) => c.id)));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Message-only and fail-open: names the worktree that holds the artifacts instead of demanding
|
|
81
|
-
// a file that exists one directory over. Never writes across trees.
|
|
82
|
-
async function artifactsLiveInWorktree(featureName, missing) {
|
|
83
|
-
try {
|
|
84
|
-
const { findWorktreeForFeature } = await import('../project/worktree.js');
|
|
85
|
-
const wt = findWorktreeForFeature(featureName, process.cwd());
|
|
86
|
-
if (!wt?.path) return null;
|
|
87
|
-
|
|
88
|
-
const base = join(wt.path, '.morph', 'features', featureName);
|
|
89
|
-
const present = missing.filter((rel) => existsSync(join(base, rel)));
|
|
90
|
-
return present.length ? { path: wt.path, branch: wt.branch, present } : null;
|
|
91
|
-
} catch {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function resolveApprovedBy(options) {
|
|
97
|
-
if (options.approver) return options.approver;
|
|
98
|
-
if (options.mode === 'auto') return 'auto';
|
|
99
|
-
if (process.stdin.isTTY) return process.env.USER || process.env.USERNAME || 'user';
|
|
100
|
-
return 'auto';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function reportDotnetIgnores(added) {
|
|
104
|
-
if (added.length) console.log(chalk.gray(` .gitignore: ${added.join(' ')} adicionados (projeto .NET) — commite antes do primeiro build.`));
|
|
105
|
-
for (const { entry, file } of added.skipped || []) {
|
|
106
|
-
console.log(chalk.yellow(` .gitignore: ${entry} não adicionado — esconderia fonte versionada (${file}); ignore a saída de build pelo caminho do projeto.`));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function reportDesignSeed({ mockups, designSystem }) {
|
|
111
|
-
const rel = (p) => relative(process.cwd(), p).replace(/\\/g, '/');
|
|
112
|
-
if (mockups.written) console.log(chalk.gray(` Escrito ${rel(mockups.path)} a partir do template (checklist de tela por \`## Tela:\`).`));
|
|
113
|
-
if (designSystem.written) console.log(chalk.gray(` Escrito ${rel(designSystem.path)} a partir do template (o projeto não tinha design system).`));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export async function advanceCommand(featureName, options = {}) {
|
|
117
|
-
try {
|
|
118
|
-
const feature = getFeature(featureName);
|
|
119
|
-
if (!feature) {
|
|
120
|
-
console.error(chalk.red(`\n✗ Funcionalidade não encontrada: ${featureName}.\n`));
|
|
121
|
-
process.exit(1);
|
|
122
|
-
}
|
|
123
|
-
const ref = ownerRef(process.cwd(), featureName, feature);
|
|
124
|
-
|
|
125
|
-
// A live worktree elsewhere owns the state: never stamp a gate onto the root skeleton.
|
|
126
|
-
const owner = assertOwnerTree(featureName, process.cwd());
|
|
127
|
-
if (owner.blocked) {
|
|
128
|
-
for (const { tone, text } of ownerTreeRefusalLines(featureName, owner.tree, owner.branch, `morph-spec advance ${featureName}`)) {
|
|
129
|
-
console.error(chalk[tone](text));
|
|
130
|
-
}
|
|
131
|
-
process.exit(1);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const featurePath = join(process.cwd(), '.morph', 'features', featureName);
|
|
135
|
-
const phase = derivePhase(featurePath);
|
|
136
|
-
|
|
137
|
-
// The plan gate is often closed by the human's answer to the gate question
|
|
138
|
-
// (state-sync), which already moves the derived phase to implement: taking
|
|
139
|
-
// the design branch then is opening 1-design/, not closing a phase.
|
|
140
|
-
if (options.design && phase === 'implement' && feature.approvalGates?.plan?.approved === true) {
|
|
141
|
-
mkdirSync(join(featurePath, '1-design'), { recursive: true });
|
|
142
|
-
reportDesignSeed(seedDesignArtifacts(featureName, process.cwd()));
|
|
143
|
-
reportDotnetIgnores(seedDotnetBuildIgnores(process.cwd(), { featureName }));
|
|
144
|
-
console.log(chalk.green(`\n✓ ${ref}: o plano já estava aprovado. O desenho das telas começa agora.`));
|
|
145
|
-
console.log(chalk.gray(` ${SESSION_MARK} ramo de design aberto em 1-design/\n`));
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (phase === 'review') {
|
|
150
|
-
console.log(chalk.yellow(`\n⚠ ${ref} já está na última etapa (${PHASE_NAME.review}).`));
|
|
151
|
-
console.log(chalk.gray(` ${SESSION_MARK} aprove a entrega com \`morph-spec approve ${featureName} review\` e arquive com \`morph-spec archive ${featureName}\`\n`));
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const stage = PHASE_NAME[phase] ?? phase;
|
|
155
|
-
|
|
156
|
-
// `implement` has no gate, so this is what keeps unfinished scenarios out of review.
|
|
157
|
-
// `--force` bypasses it but still names what was skipped.
|
|
158
|
-
const missingArtifacts = missingPhaseArtifacts(phase, featurePath);
|
|
159
|
-
if (missingArtifacts.length && !options.force) {
|
|
160
|
-
const elsewhere = await artifactsLiveInWorktree(featureName, missingArtifacts);
|
|
161
|
-
if (elsewhere) {
|
|
162
|
-
console.error(chalk.red(`\n✗ A etapa ${stage} de ${ref} não pode ser encerrada a partir desta pasta.`));
|
|
163
|
-
console.error(chalk.gray(' Nada está faltando: os arquivos vivem no worktree dono desta funcionalidade:'));
|
|
164
|
-
for (const rel of elsewhere.present) console.error(chalk.gray(` • ${rel}`));
|
|
165
|
-
console.error(chalk.gray(`\n Worktree: ${elsewhere.path}${elsewhere.branch ? ` (branch ${elsewhere.branch})` : ''}`));
|
|
166
|
-
console.error(chalk.gray(' Rode o comando LÁ — o gate é gravado no feature.json daquela árvore:'));
|
|
167
|
-
console.error(chalk.cyan(` cd "${elsewhere.path}" && morph-spec advance ${featureName}`));
|
|
168
|
-
console.error(chalk.yellow('\n NÃO use --force aqui: ele carimbaria o gate na cópia da raiz, duplicando'));
|
|
169
|
-
console.error(chalk.yellow(' uma aprovação que a outra árvore já tem e invertendo a ordem dos gates.\n'));
|
|
170
|
-
process.exit(1);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
console.error(chalk.red(`\n✗ A etapa ${stage} de ${ref} ainda não pode ser encerrada:`));
|
|
174
|
-
for (const line of missingLines(missingArtifacts, featurePath)) console.error(` ${line}`);
|
|
175
|
-
console.error(chalk.gray(` ${SESSION_MARK} ausente(s), PARCIAL ou BLOQUEADO: ${missingArtifacts.join('; ')}.`
|
|
176
|
-
+ ' Produza o artefato e rode de novo, ou passe --force para avançar assim mesmo.\n'));
|
|
177
|
-
process.exit(1);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const gate = PHASE_GATE[phase];
|
|
181
|
-
const approvedBy = resolveApprovedBy(options);
|
|
182
|
-
|
|
183
|
-
// Gate monotonicity: never stamp gate N while a predecessor is pending (`--force` to recover).
|
|
184
|
-
if (gate) {
|
|
185
|
-
const unmet = unmetPrereqs(gate, feature.approvalGates);
|
|
186
|
-
if (unmet.length && !options.force) {
|
|
187
|
-
console.error(chalk.red(`\n✗ A etapa ${stage} de ${ref} ainda não pode ser encerrada: antes vem ${unmet.map((u) => GATE_NAME[u] ?? u).join(', ')}.`));
|
|
188
|
-
console.error(chalk.gray(` ${SESSION_MARK} prerequisite gate(s) não aprovado(s): aprove na ordem (${unmet.join(' → ')} → ${gate}), ou passe --force\n`));
|
|
189
|
-
process.exit(1);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// `setApprovalGate` replaces the gate whole: rewriting an approved gate would turn a human
|
|
194
|
-
// signature into "auto". Skips ONLY the write, so the scaffold below still runs.
|
|
195
|
-
const priorGate = gate ? feature.approvalGates?.[gate] : null;
|
|
196
|
-
const alreadyApproved = priorGate?.approved === true;
|
|
197
|
-
|
|
198
|
-
const refusal = alreadyApproved ? null
|
|
199
|
-
: autoApprovalRefusal({ cwd: process.cwd(), featureName, feature, gate, approvedBy });
|
|
200
|
-
if (refusal) {
|
|
201
|
-
printRefusal(chalk, refusal);
|
|
202
|
-
process.exit(1);
|
|
203
|
-
}
|
|
204
|
-
const checklistBlock = phase === 'uiux' && !alreadyApproved ? uiuxAutoApprovalBlock(process.cwd(), featureName, feature) : null;
|
|
205
|
-
|
|
206
|
-
if (gate && !alreadyApproved) {
|
|
207
|
-
await setApprovalGate(featureName, gate, true, {
|
|
208
|
-
approvedBy,
|
|
209
|
-
approvedAt: new Date().toISOString(),
|
|
210
|
-
notes: options.notes,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
let nextDir = NEXT_PHASE_DIR[phase];
|
|
215
|
-
if (phase === 'plan' && options.design) nextDir = '1-design';
|
|
216
|
-
if (nextDir) {
|
|
217
|
-
const nextPath = join(featurePath, nextDir);
|
|
218
|
-
if (!existsSync(nextPath)) mkdirSync(nextPath, { recursive: true });
|
|
219
|
-
}
|
|
220
|
-
if (nextDir === '1-design') reportDesignSeed(seedDesignArtifacts(featureName, process.cwd()));
|
|
221
|
-
if (nextDir === '3-implement') seedReport(featurePath, featureName);
|
|
222
|
-
if (phase === 'plan') reportDotnetIgnores(seedDotnetBuildIgnores(process.cwd(), { featureName }));
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
console.log(chalk.green(`\n✓ ${ref}: etapa ${stage} encerrada.`));
|
|
226
|
-
if (missingArtifacts.length) {
|
|
227
|
-
console.log(chalk.yellow(' ⚠ Avançou sem terminar tudo:'));
|
|
228
|
-
for (const line of missingLines(missingArtifacts, featurePath)) console.log(chalk.yellow(` ${line}`));
|
|
229
|
-
console.log(chalk.gray(` ${SESSION_MARK} --force: avançou SEM ${missingArtifacts.join(', ')}`));
|
|
230
|
-
}
|
|
231
|
-
if (checklistBlock) {
|
|
232
|
-
const by = options.force ? '--force' : `aprovado por ${approvedBy}`;
|
|
233
|
-
console.log(chalk.yellow(` ⚠ ${by}: avançou com o desenho das telas incompleto.`));
|
|
234
|
-
console.log(chalk.yellow(` ${checklistBlock}`));
|
|
235
|
-
}
|
|
236
|
-
// Never claim "approved (auto)" when nothing was written.
|
|
237
|
-
if (gate && alreadyApproved) {
|
|
238
|
-
console.log(` ${GATE_NAME[gate]} já estava aprovada (por ${priorGate.approvedBy || 'alguém sem nome'}): nada foi regravado.`);
|
|
239
|
-
} else if (gate) {
|
|
240
|
-
console.log(` ${GATE_NAME[gate]}: ${approvedBySay(approvedBy)}.`);
|
|
241
|
-
}
|
|
242
|
-
if (nextDir) console.log(chalk.gray(` ${SESSION_MARK} pasta ${nextDir}/ criada para a próxima etapa\n`));
|
|
243
|
-
else console.log('');
|
|
244
|
-
} catch (error) {
|
|
245
|
-
console.error(chalk.red(`\n✗ Não deu para avançar: ${error.message}\n`));
|
|
246
|
-
process.exit(1);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { execFileSync } from 'child_process';
|
|
4
|
-
import { getFeature, setApprovalGate, getApprovalGate } from '../../core/state/state-manager.js';
|
|
5
|
-
import { unmetPrereqs } from '../../core/state/gate-order.js';
|
|
6
|
-
import { reviewReports, reviewFileName, REVIEW_ROLES, VERDICT_TOKEN, REVIEWED_SHA_TOKEN } from '../../lib/review-reports.js';
|
|
7
|
-
import { shouldPauseGate, fillTodo } from '../../lib/risk-detector.js';
|
|
8
|
-
import { GATE_NAME, PHASE_NAME, approvedBySay, ROLE_NAME, VERDICT_SAY } from '../../../framework/hooks/shared/owner-words.js';
|
|
9
|
-
import { SESSION_MARK } from '../../../framework/hooks/shared/next-step.js';
|
|
10
|
-
import { collectSignals, collectReviewRequirement } from './gate-check.js';
|
|
11
|
-
import { autoApprovalRefusal, printRefusal } from './auto-approval.js';
|
|
12
|
-
import { readTrustFromConfig } from './gate-decision.js';
|
|
13
|
-
import { assertOwnerTree, ownerTreeRefusalLines } from '../../lib/worktree/feature-truth.js';
|
|
14
|
-
import { reviewConfirmation } from '../../lib/review-confirmation.js';
|
|
15
|
-
import { seedDotnetBuildIgnores } from '../../lib/stack/dotnet-build-ignores.js';
|
|
16
|
-
import { reportDotnetIgnores } from './advance.js';
|
|
17
|
-
import { ownerRef } from '../../../framework/hooks/shared/report-progress.js';
|
|
18
|
-
|
|
19
|
-
export { REVIEWED_SHA_TOKEN };
|
|
20
|
-
|
|
21
|
-
const SIGNED_OFF = { required: [], reports: {}, checks: { status: 'ok', total: 0, missing: [], notProven: [] } };
|
|
22
|
-
|
|
23
|
-
// The worst answer across every report present wins. `skip` (no report at all, no git) never
|
|
24
|
-
// refuses falsely.
|
|
25
|
-
function reviewStaleness(reports) {
|
|
26
|
-
if (Object.values(reports).every((r) => r.status === 'missing')) return { status: 'skip' };
|
|
27
|
-
const cwd = process.cwd();
|
|
28
|
-
let head;
|
|
29
|
-
try {
|
|
30
|
-
head = execFileSync('git', ['rev-parse', 'HEAD'], { cwd, stdio: 'pipe' }).toString().trim();
|
|
31
|
-
} catch {
|
|
32
|
-
return { status: 'skip' };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// The same oracle report-check reads for `redispatch`: what it lets stay, approve accepts.
|
|
36
|
-
const staleRoles = new Set(reviewConfirmation(cwd, reports, head).moved.filter((m) => !m.skippable).map((m) => m.role));
|
|
37
|
-
|
|
38
|
-
let unstamped = null;
|
|
39
|
-
for (const [role, report] of Object.entries(reports)) {
|
|
40
|
-
if (report.status === 'missing') continue;
|
|
41
|
-
const file = reviewFileName(role);
|
|
42
|
-
let reviewed = null;
|
|
43
|
-
try {
|
|
44
|
-
if (report.reviewedSha) {
|
|
45
|
-
reviewed = execFileSync('git', ['rev-parse', '--verify', `${report.reviewedSha}^{commit}`], { cwd, stdio: 'pipe' })
|
|
46
|
-
.toString().trim();
|
|
47
|
-
}
|
|
48
|
-
} catch {
|
|
49
|
-
reviewed = null;
|
|
50
|
-
}
|
|
51
|
-
if (!reviewed) {
|
|
52
|
-
unstamped ??= { status: 'unstamped', file, role, head };
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (!staleRoles.has(role)) continue;
|
|
56
|
-
let ahead = 0;
|
|
57
|
-
try {
|
|
58
|
-
ahead = Number(execFileSync('git', ['rev-list', '--count', `${reviewed}..${head}`], { cwd, stdio: 'pipe' }).toString().trim()) || 0;
|
|
59
|
-
} catch { ahead = 0; }
|
|
60
|
-
return { status: 'stale', file, role, reviewed, head, ahead };
|
|
61
|
-
}
|
|
62
|
-
return unstamped ?? { status: 'ok', head };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function unapproveCommand(featureName, gateName, options = {}) {
|
|
66
|
-
try {
|
|
67
|
-
if (!VALID_GATES.includes(gateName)) refuseGate(gateName);
|
|
68
|
-
|
|
69
|
-
const feature = getFeature(featureName);
|
|
70
|
-
if (!feature) refuseFeature(featureName);
|
|
71
|
-
|
|
72
|
-
const owner = assertOwnerTree(featureName, process.cwd());
|
|
73
|
-
if (owner.blocked) {
|
|
74
|
-
for (const { tone, text } of ownerTreeRefusalLines(featureName, owner.tree, owner.branch, `morph-spec unapprove ${featureName} ${gateName}`)) {
|
|
75
|
-
console.error(chalk[tone](text));
|
|
76
|
-
}
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const who = gateOf(gateName, featureName, feature);
|
|
81
|
-
const currentStatus = getApprovalGate(featureName, gateName);
|
|
82
|
-
if (!currentStatus?.approved) {
|
|
83
|
-
console.log(chalk.yellow(`\n⚠ ${who} não está aprovada: nada a revogar.\n`));
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Don't pretend a human revoked the gate without an interactive shell behind the call.
|
|
88
|
-
let revokedBy;
|
|
89
|
-
if (options.revoker) {
|
|
90
|
-
revokedBy = options.revoker;
|
|
91
|
-
} else if (options.mode === 'auto') {
|
|
92
|
-
revokedBy = 'auto';
|
|
93
|
-
} else if (process.stdin.isTTY) {
|
|
94
|
-
revokedBy = process.env.USER || process.env.USERNAME || 'user';
|
|
95
|
-
} else {
|
|
96
|
-
revokedBy = 'auto';
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
await setApprovalGate(featureName, gateName, false, {
|
|
100
|
-
revokedBy,
|
|
101
|
-
revokedAt: new Date().toISOString(),
|
|
102
|
-
reason: options.reason
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
console.log(chalk.yellow(`\n↩ Aprovação revogada: ${who}. O trabalho volta para a etapa ${PHASE_NAME[gateName] ?? gateName}.`));
|
|
106
|
-
console.log(chalk.gray(` ${SESSION_MARK} emende, \`plan-check ${featureName}\`, \`gate-check ${featureName} ${gateName}\` e \`advance ${featureName}\` reaprovam pelo fluxo normal\n`));
|
|
107
|
-
|
|
108
|
-
} catch (error) {
|
|
109
|
-
console.error(chalk.red(`\n✗ Não deu para revogar a aprovação: ${error.message}\n`));
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const program = new Command();
|
|
115
|
-
|
|
116
|
-
const VALID_GATES = ['plan', 'uiux', 'review'];
|
|
117
|
-
|
|
118
|
-
const gateOf = (gate, featureName, feature) => `${GATE_NAME[gate] ?? gate} de ${ownerRef(process.cwd(), featureName, feature)}`;
|
|
119
|
-
|
|
120
|
-
function refuseGate(gateName) {
|
|
121
|
-
console.error(chalk.red(`\n✗ Etapa de aprovação desconhecida: ${gateName}.`));
|
|
122
|
-
console.error(chalk.gray(` ${SESSION_MARK} use uma destas: ${VALID_GATES.join(', ')}\n`));
|
|
123
|
-
process.exit(1);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function refuseFeature(featureName) {
|
|
127
|
-
console.error(chalk.red(`\n✗ Funcionalidade não encontrada: ${featureName}.\n`));
|
|
128
|
-
process.exit(1);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const REPORT_STATUS_SAY = {
|
|
132
|
-
missing: 'o relatório não existe',
|
|
133
|
-
partial: 'o relatório ficou pela metade',
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export async function approveCommand(featureName, gateName, options = {}) {
|
|
137
|
-
try {
|
|
138
|
-
if (!VALID_GATES.includes(gateName)) refuseGate(gateName);
|
|
139
|
-
|
|
140
|
-
const feature = getFeature(featureName);
|
|
141
|
-
if (!feature) refuseFeature(featureName);
|
|
142
|
-
|
|
143
|
-
// A live worktree elsewhere owns the state: never stamp a gate onto the root skeleton.
|
|
144
|
-
const owner = assertOwnerTree(featureName, process.cwd());
|
|
145
|
-
if (owner.blocked) {
|
|
146
|
-
for (const { tone, text } of ownerTreeRefusalLines(featureName, owner.tree, owner.branch, `morph-spec approve ${featureName} ${gateName}`)) {
|
|
147
|
-
console.error(chalk[tone](text));
|
|
148
|
-
}
|
|
149
|
-
process.exit(1);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const who = gateOf(gateName, featureName, feature);
|
|
153
|
-
const currentStatus = getApprovalGate(featureName, gateName);
|
|
154
|
-
if (currentStatus?.approved) {
|
|
155
|
-
console.log(chalk.yellow(`\n⚠ ${who} já está aprovada (por ${currentStatus.approvedBy || 'alguém sem nome'}, em ${currentStatus.timestamp}).`));
|
|
156
|
-
// `--force` does not cover this no-op (it only covers gate ORDER), so name the way out.
|
|
157
|
-
console.log(chalk.gray(` ${SESSION_MARK} para aprovar de novo, revogue antes: morph-spec unapprove ${featureName} ${gateName}\n`));
|
|
158
|
-
if (gateName === 'plan') reportDotnetIgnores(seedDotnetBuildIgnores(process.cwd(), { featureName }));
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Gate monotonicity: predecessors first; policy stamps count (`--force` to recover).
|
|
163
|
-
const unmet = unmetPrereqs(gateName, feature.approvalGates);
|
|
164
|
-
if (unmet.length && !options.force) {
|
|
165
|
-
console.error(chalk.red(`\n✗ ${who} ainda não pode ser aprovada: antes vem ${unmet.map((u) => GATE_NAME[u] ?? u).join(', ')}.`));
|
|
166
|
-
console.error(chalk.gray(` ${SESSION_MARK} aprove na ordem (${unmet.join(' → ')} → ${gateName}), ou passe --force\n`));
|
|
167
|
-
process.exit(1);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Resolved BEFORE the hotfix backstop, which gates on the signature. Without a TTY the answer
|
|
171
|
-
// is "auto": stamping $USERNAME on a gate no human approved lies to the audit trail.
|
|
172
|
-
let approvedBy;
|
|
173
|
-
if (options.approver) {
|
|
174
|
-
approvedBy = options.approver;
|
|
175
|
-
} else if (options.mode === 'auto') {
|
|
176
|
-
approvedBy = 'auto';
|
|
177
|
-
} else if (process.stdin.isTTY) {
|
|
178
|
-
approvedBy = process.env.USER || process.env.USERNAME || 'user';
|
|
179
|
-
} else {
|
|
180
|
-
approvedBy = 'auto';
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const refusal = autoApprovalRefusal({ cwd: process.cwd(), featureName, feature, gate: gateName, approvedBy });
|
|
184
|
-
if (refusal) {
|
|
185
|
-
printRefusal(chalk, refusal);
|
|
186
|
-
process.exit(1);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// A review reviews a TREE: a `Reviewed-SHA` behind HEAD refuses. A missing stamp only warns,
|
|
190
|
-
// naming the token to add, so a legacy report does not brick the feature.
|
|
191
|
-
const reports = gateName === 'review' ? reviewReports(process.cwd(), featureName) : null;
|
|
192
|
-
if (gateName === 'review') {
|
|
193
|
-
const stale = reviewStaleness(reports);
|
|
194
|
-
if (stale.status === 'stale') {
|
|
195
|
-
console.error(chalk.red(`\n✗ O código mudou depois da ${ROLE_NAME[stale.role] ?? stale.role}: ela olhou uma versão anterior.`));
|
|
196
|
-
if (stale.ahead) console.error(` ${stale.ahead} mudança(s) gravada(s) depois da revisão.`);
|
|
197
|
-
console.error(chalk.gray(` ${SESSION_MARK} \`4-review/${stale.file}\` revisado em ${stale.reviewed.slice(0, 8)}, HEAD atual ${stale.head.slice(0, 8)}:`
|
|
198
|
-
+ ` re-rode a \`morph-review\` e atualize o \`${REVIEWED_SHA_TOKEN}\` de cada relatório\n`));
|
|
199
|
-
process.exit(1);
|
|
200
|
-
}
|
|
201
|
-
if (stale.status === 'unstamped') {
|
|
202
|
-
console.log(chalk.yellow(`\n⚠ Não dá para saber se a ${ROLE_NAME[stale.role] ?? stale.role} olhou o código atual.`));
|
|
203
|
-
console.log(chalk.gray(` ${SESSION_MARK} \`${stale.file}\` sem \`${REVIEWED_SHA_TOKEN}\`: adicione a linha \`${REVIEWED_SHA_TOKEN} ${stale.head}\``));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
let selfAssessed = false;
|
|
208
|
-
if (gateName === 'review') {
|
|
209
|
-
if (feature.workType === 'hotfix') {
|
|
210
|
-
// Hotfix never dispatches: the orchestrator writes `verifier.md` itself
|
|
211
|
-
// (diff + real verify evidence); the human signature above decides.
|
|
212
|
-
if (reports.verifier.status === 'missing') {
|
|
213
|
-
console.error(chalk.red('\n✗ A correção urgente precisa do relatório da Conferência das entregas antes da aprovação.'));
|
|
214
|
-
console.error(chalk.gray(` ${SESSION_MARK} no hotfix a sessão escreve \`4-review/verifier.md\` (diff do fix + evidência real do`
|
|
215
|
-
+ ' `morph-spec verify`) sem despachar ninguém; a assinatura humana já é exigida\n'));
|
|
216
|
-
process.exit(1);
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
const { required } = collectReviewRequirement(process.cwd(), feature);
|
|
220
|
-
const unusable = required.filter((role) => reports[role].status !== 'ok');
|
|
221
|
-
if (unusable.length) {
|
|
222
|
-
if (!options.selfAssessed) {
|
|
223
|
-
console.error(chalk.red('\n✗ A entrega não pode ser aprovada: falta a Revisão independente.'));
|
|
224
|
-
for (const role of unusable) {
|
|
225
|
-
const { status } = reports[role];
|
|
226
|
-
console.error(` ${ROLE_NAME[role]}: ${REPORT_STATUS_SAY[status] ?? 'o relatório não diz se aprovou ou pediu correção'}.`);
|
|
227
|
-
}
|
|
228
|
-
const tokens = unusable.map((role) => {
|
|
229
|
-
const { status } = reports[role];
|
|
230
|
-
const what = status === 'missing' ? 'não existe'
|
|
231
|
-
: status === 'partial' ? 'está PARCIAL (despache o mesmo papel de novo dizendo o que já está no relatório)'
|
|
232
|
-
: `não tem \`${VERDICT_TOKEN} SHIP|FIX\``;
|
|
233
|
-
return `${reviewFileName(role)} ${what}`;
|
|
234
|
-
});
|
|
235
|
-
console.error(chalk.gray(` ${SESSION_MARK} exige ${required.map((r) => `\`4-review/${reviewFileName(r)}\``).join(', ')}. ${tokens.join('; ')}.`
|
|
236
|
-
+ ` Despache ${unusable.map((r) => `\`${REVIEW_ROLES[r].persona}\``).join(', ')} em contexto fresco, nunca quem implementou.`
|
|
237
|
-
+ ' Se o dispatch for impossível nesta sessão, aprove com --self-assessed (a degradação fica registrada no feature.json e aparece no `list`/`fleet`)\n'));
|
|
238
|
-
process.exit(1);
|
|
239
|
-
}
|
|
240
|
-
selfAssessed = true;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Sem gate-check prévio não há `gateDecisions.review` para o backstop morder: a auto-aprovação
|
|
244
|
-
// recalcula a decisão pela MESMA régua do gate-check. --self-assessed já dispensou os relatórios.
|
|
245
|
-
if (approvedBy === 'auto') {
|
|
246
|
-
const signals = collectSignals(featureName, feature, process.cwd(), 'review');
|
|
247
|
-
if (selfAssessed) signals.reviewReports = SIGNED_OFF;
|
|
248
|
-
const { pause, reason, todo } = shouldPauseGate({ trust: readTrustFromConfig() }, signals);
|
|
249
|
-
if (pause) {
|
|
250
|
-
console.error(chalk.red('\n✗ A entrega não pode ser aprovada sozinha.'));
|
|
251
|
-
console.error(` Motivo: ${reason}`);
|
|
252
|
-
const action = fillTodo(todo, featureName, 'review');
|
|
253
|
-
console.error(chalk.gray(` ${SESSION_MARK} ${action ? `${action}; ou ` : ''}leve a decisão ao humano (--approver <nome>)\n`));
|
|
254
|
-
process.exit(1);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
for (const role of required) {
|
|
259
|
-
const r = reports[role];
|
|
260
|
-
if (r.status === 'ok' && r.superseded.length > 0) {
|
|
261
|
-
console.log(chalk.yellow(`\n⚠ O relatório da ${ROLE_NAME[role]} tem ${r.superseded.length + 1} vereditos; vale o último: ${VERDICT_SAY[r.verdict] ?? r.verdict}, ${r.blockers.length} problema(s).`));
|
|
262
|
-
console.log(chalk.gray(` ${SESSION_MARK} ${reviewFileName(role)} tem ${r.superseded.length + 1} vereditos (append-only). Vigente: ${r.verdict}. Superados: ${r.superseded.join(', ')}\n`));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
await setApprovalGate(featureName, gateName, true, {
|
|
269
|
-
approvedBy,
|
|
270
|
-
approvedAt: new Date().toISOString(),
|
|
271
|
-
notes: options.notes,
|
|
272
|
-
...(selfAssessed ? { selfAssessed: true } : {}),
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
if (selfAssessed) {
|
|
276
|
-
console.log(chalk.yellow('\n⚠ Entrega aprovada SEM a Revisão independente.'));
|
|
277
|
-
console.log(chalk.gray(` ${SESSION_MARK} --self-assessed registrado em feature.json → approvalGates.review.selfAssessed`));
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
console.log(chalk.green(`\n✓ ${who}: ${approvedBySay(approvedBy)}. O trabalho pode seguir.`));
|
|
281
|
-
if (gateName === 'plan') reportDotnetIgnores(seedDotnetBuildIgnores(process.cwd(), { featureName }));
|
|
282
|
-
console.log('');
|
|
283
|
-
|
|
284
|
-
} catch (error) {
|
|
285
|
-
console.error(chalk.red(`\n✗ Não deu para aprovar: ${error.message}\n`));
|
|
286
|
-
process.exit(1);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
program
|
|
291
|
-
.command('approve <feature> <gate>')
|
|
292
|
-
.description('Approve a phase gate to allow workflow progression')
|
|
293
|
-
.action(approveCommand);
|
|
294
|
-
|
|
295
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
296
|
-
if (process.argv.length > 2) {
|
|
297
|
-
program.parse(process.argv);
|
|
298
|
-
} else {
|
|
299
|
-
program.help();
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export default program;
|