@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,244 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { getFeature } from '../../core/state/state-manager.js';
|
|
3
|
-
import { shouldPauseGate, getRiskSignals, classifyE2eSkip, planChecksPause, securityReviewFor, pausingRungs, migrationsTouched, contractsTouched, humanApprover, rungPause, planCritiquePause, planAutoApprovalTodo, scenarioTitles, fillTodo, ASK_OWNER } from '../../lib/risk-detector.js';
|
|
4
|
-
import { GATE_NAME, featureRef } from '../../../framework/hooks/shared/owner-words.js';
|
|
5
|
-
import { SESSION_MARK } from '../../../framework/hooks/shared/next-step.js';
|
|
6
|
-
import { readPlanCritique } from '../../lib/plan/critique.js';
|
|
7
|
-
import { reviewReports, reviewSignal, requiredReviewRoles, verifierMediaSection } from '../../lib/review-reports.js';
|
|
8
|
-
import { featureDiffRisk } from '../../lib/risk/diff-risk.js';
|
|
9
|
-
import { collectScreenChecklist } from '../../lib/specs/screen-checklist.js';
|
|
10
|
-
import { persistGateDecision, VALID_GATES, readTrustFromConfig } from './gate-decision.js';
|
|
11
|
-
import { minimatch } from 'minimatch';
|
|
12
|
-
import { detectDefaultBranch, getHeadSha, getDiffStat, changedPathsAgainst } from '../../lib/git/default-branch.js';
|
|
13
|
-
import { treeMovedSince } from '../../lib/git/evidence-staleness.js';
|
|
14
|
-
import { readMorphConfig } from '../../lib/tasks/test-runner.js';
|
|
15
|
-
import { readPlanChecks } from '../../lib/plan/checks.js';
|
|
16
|
-
import { featureGeneratesMedia } from '../../lib/plan/media.js';
|
|
17
|
-
import { readFileSync, existsSync } from 'fs';
|
|
18
|
-
import { getAbsoluteOutputPath } from '../../core/paths/output-schema.js';
|
|
19
|
-
import { assertOwnerTree, ownerTreeRefusalLines } from '../../lib/worktree/feature-truth.js';
|
|
20
|
-
|
|
21
|
-
export { featureGeneratesMedia, MEDIA_STANDARD_IDS, standardIdOf } from '../../lib/plan/media.js';
|
|
22
|
-
|
|
23
|
-
// Only signals NOT derivable from disk may be overridden: overriding a disk fact (e.g. `workType`
|
|
24
|
-
// away from hotfix) would silently defeat the policy this command makes deterministic.
|
|
25
|
-
const OVERRIDABLE_SIGNAL_KEYS = ['standardsViolations', 'designSystemDivergence'];
|
|
26
|
-
|
|
27
|
-
function readPlanText(cwd, featureName) {
|
|
28
|
-
const path = getAbsoluteOutputPath(cwd, featureName, 'plan');
|
|
29
|
-
try { return existsSync(path) ? readFileSync(path, 'utf8') : ''; } catch { return ''; }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// `declared: false` (nenhum caminho declarado: regra inerte) e `touched: []` (declarou, nada
|
|
34
|
-
// tocado) não podem colapsar num array vazio. COLETA, NUNCA DECIDE: política no coletor cria
|
|
35
|
-
// duas fontes para o mesmo fato.
|
|
36
|
-
function collectPromptModel(cwd, defaultBranch) {
|
|
37
|
-
const watch = readMorphConfig(cwd)?.project?.evals?.watch;
|
|
38
|
-
const globs = Array.isArray(watch) ? watch.filter((g) => typeof g === 'string' && g.trim()) : [];
|
|
39
|
-
|
|
40
|
-
if (globs.length === 0) return { declared: false, watch: [], touched: [] };
|
|
41
|
-
|
|
42
|
-
const changed = changedPathsAgainst(defaultBranch, cwd);
|
|
43
|
-
return {
|
|
44
|
-
declared: true,
|
|
45
|
-
watch: globs,
|
|
46
|
-
touched: changed.filter((path) => globs.some((glob) => minimatch(path, glob))),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** A regra única de quais relatórios o ship exige, lida por gate-check, approve e report-check. */
|
|
51
|
-
export function collectReviewRequirement(cwd, feature) {
|
|
52
|
-
let changed = [];
|
|
53
|
-
try { changed = changedPathsAgainst(detectDefaultBranch(cwd), cwd); } catch { changed = []; }
|
|
54
|
-
const byPath = securityReviewFor(changed);
|
|
55
|
-
const risk = featureDiffRisk(cwd, detectDefaultBranch(cwd));
|
|
56
|
-
const reasons = [...new Set([...byPath.reasons, ...(risk?.security.reasons ?? [])])];
|
|
57
|
-
const security = { required: reasons.length > 0, reasons };
|
|
58
|
-
const required = requiredReviewRoles({ workType: feature?.workType, securityRequired: security.required, risk: risk?.level ?? null });
|
|
59
|
-
return { required, security, risk: risk ? { level: risk.level, reasons: risk.reasons } : null };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function collectReviewSignal(cwd, featureName, feature, planChecks = readPlanChecks(cwd, featureName)) {
|
|
63
|
-
const { required } = collectReviewRequirement(cwd, feature);
|
|
64
|
-
const checkIds = Array.isArray(planChecks.checks?.checks) ? planChecks.checks.checks.map((c) => c.id) : null;
|
|
65
|
-
return reviewSignal(reviewReports(cwd, featureName), { required, checkIds });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Why an automatic signature may not close the plan gate: the rule that makes gate-check pause it.
|
|
70
|
-
* @returns {{ reason: string, todo: string|null }|null}
|
|
71
|
-
*/
|
|
72
|
-
export function planAutoApprovalBlock(cwd, featureName, feature) {
|
|
73
|
-
const planChecks = readPlanChecks(cwd, featureName);
|
|
74
|
-
const workType = feature?.workType || 'feature';
|
|
75
|
-
const planCritique = readPlanCritique(cwd, featureName, { workType, planChecks });
|
|
76
|
-
const reason = planChecksPause(planChecks.status)
|
|
77
|
-
?? planCritiquePause(planCritique)
|
|
78
|
-
?? rungPause({ gate: 'plan', rungs: pausingRungs(planChecks.checks) })?.reason;
|
|
79
|
-
if (!reason) return null;
|
|
80
|
-
return { reason, todo: fillTodo(planAutoApprovalTodo({ planChecks: planChecks.status, planCritique }), featureName, 'plan') ?? null };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Collects only; risk-detector.js decides. `e2eStatus`/`e2eReason` exist because a skipped e2e
|
|
84
|
-
// node does not fail the rollup: the literal reason is the only fact separating a legitimate
|
|
85
|
-
// waiver from missing proof.
|
|
86
|
-
export function collectSignals(featureName, feature, cwd, gateName) {
|
|
87
|
-
const planChecks = readPlanChecks(cwd, featureName);
|
|
88
|
-
const defaultBranch = detectDefaultBranch(cwd);
|
|
89
|
-
const sha = getHeadSha(cwd);
|
|
90
|
-
const verification = feature.verification || null;
|
|
91
|
-
|
|
92
|
-
const signals = {
|
|
93
|
-
// Disk-derived, never overridable: a caller cannot spoof which gate is being decided.
|
|
94
|
-
gate: gateName,
|
|
95
|
-
workType: feature.workType || 'feature',
|
|
96
|
-
standardsViolations: [],
|
|
97
|
-
designSystemDivergence: false,
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
if (gateName === 'plan') {
|
|
101
|
-
signals.planChecks = planChecks.status;
|
|
102
|
-
signals.planCritique = readPlanCritique(cwd, featureName, { workType: signals.workType, planChecks });
|
|
103
|
-
}
|
|
104
|
-
if (gateName === 'plan' || gateName === 'review') {
|
|
105
|
-
signals.rungs = pausingRungs(planChecks.checks);
|
|
106
|
-
signals.scenarios = scenarioTitles(planChecks.checks);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Só onde o checklist decide algo: no fecho do design e no ship.
|
|
110
|
-
if (gateName === 'uiux' || gateName === 'review') {
|
|
111
|
-
signals.screenChecklist = collectScreenChecklist(cwd, featureName, gateName);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (gateName === 'review') {
|
|
115
|
-
signals.reviewReports = collectReviewSignal(cwd, featureName, feature, planChecks);
|
|
116
|
-
signals.mediaClaims = {
|
|
117
|
-
section: verifierMediaSection(cwd, featureName),
|
|
118
|
-
featureGeneratesMedia: featureGeneratesMedia(readPlanText(cwd, featureName)),
|
|
119
|
-
};
|
|
120
|
-
let changed = [];
|
|
121
|
-
try { changed = changedPathsAgainst(defaultBranch, cwd); } catch { changed = []; }
|
|
122
|
-
signals.migrationsTouched = migrationsTouched(changed);
|
|
123
|
-
signals.contractsTouched = contractsTouched(changed);
|
|
124
|
-
signals.planApprovedByHuman = feature.approvalGates?.plan?.approved === true
|
|
125
|
-
&& humanApprover(feature.approvalGates.plan.approvedBy);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// verificationStale é fail-open: stamp sem sha (checkout sem git) ou ausente lê como NOT stale.
|
|
129
|
-
signals.verification = verification;
|
|
130
|
-
if (verification?.status) signals.verificationStatus = verification.status;
|
|
131
|
-
signals.failStreak = feature.verifications?.feature?.failStreak ?? 0;
|
|
132
|
-
signals.verificationStale = treeMovedSince(cwd, verification?.sha, sha);
|
|
133
|
-
|
|
134
|
-
// Separado do rollup: um `skip` NÃO reprova `verification.status`. `null` é DESCONHECIDO, nunca
|
|
135
|
-
// 'skip'. Fora de OVERRIDABLE_SIGNAL_KEYS: um `--signals '{"e2eStatus":"pass"}'` compraria o ship.
|
|
136
|
-
signals.e2eStatus = verification?.nodes?.e2e ?? null;
|
|
137
|
-
signals.e2eReason = verification?.e2eReason ?? null;
|
|
138
|
-
signals.e2eSkipClass = signals.e2eStatus === 'skip' ? classifyE2eSkip(signals.e2eReason) : null;
|
|
139
|
-
|
|
140
|
-
// Mesma razão do e2e. `null` = o projeto não declara nó de eval, DISTINTO de 'skip'.
|
|
141
|
-
signals.evalsStatus = verification?.nodes?.evals ?? null;
|
|
142
|
-
signals.promptModel = collectPromptModel(cwd, defaultBranch);
|
|
143
|
-
|
|
144
|
-
signals.diffstat = getDiffStat(defaultBranch, cwd);
|
|
145
|
-
signals.sha = sha;
|
|
146
|
-
|
|
147
|
-
return signals;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Never changes gate policy: a faithful caller of risk-detector.js, which wins wherever the
|
|
151
|
-
// skills' risk tables diverge. Persists through the same path as `gate-decision`.
|
|
152
|
-
export async function gateCheckCommand(featureName, gateName, options = {}) {
|
|
153
|
-
try {
|
|
154
|
-
if (!VALID_GATES.includes(gateName)) {
|
|
155
|
-
console.error(chalk.red(`\n✗ Etapa de aprovação desconhecida: ${gateName}.`));
|
|
156
|
-
console.error(chalk.gray(` ${SESSION_MARK} use uma destas: ${VALID_GATES.join(', ')}\n`));
|
|
157
|
-
process.exit(1);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const feature = getFeature(featureName);
|
|
161
|
-
if (!feature) {
|
|
162
|
-
console.error(chalk.red(`\n✗ Funcionalidade não encontrada: ${featureName}.\n`));
|
|
163
|
-
process.exit(1);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Both the reads and the persisted decision are wrong from a tree that doesn't own the feature.
|
|
167
|
-
const owner = assertOwnerTree(featureName, process.cwd());
|
|
168
|
-
if (owner.blocked) {
|
|
169
|
-
for (const { tone, text } of ownerTreeRefusalLines(featureName, owner.tree, owner.branch, `morph-spec gate-check ${featureName} ${gateName}`)) {
|
|
170
|
-
console.error(chalk[tone](text));
|
|
171
|
-
}
|
|
172
|
-
process.exit(1);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
let overrides = {};
|
|
176
|
-
if (options.signals !== undefined) {
|
|
177
|
-
let parsed;
|
|
178
|
-
try {
|
|
179
|
-
parsed = JSON.parse(options.signals);
|
|
180
|
-
} catch (err) {
|
|
181
|
-
console.error(chalk.red(`\n✗ --signals inválido: não é JSON (${err.message})\n`));
|
|
182
|
-
process.exit(1);
|
|
183
|
-
}
|
|
184
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
185
|
-
console.error(chalk.red('\n✗ --signals inválido: precisa ser um objeto JSON, por exemplo \'{"standardsViolations":[]}\'\n'));
|
|
186
|
-
process.exit(1);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const rejected = Object.keys(parsed).filter((k) => !OVERRIDABLE_SIGNAL_KEYS.includes(k));
|
|
190
|
-
if (rejected.length > 0) {
|
|
191
|
-
console.error(chalk.yellow(
|
|
192
|
-
`\n⚠ --signals ignorado para: ${rejected.join(', ')}\n` +
|
|
193
|
-
` ${SESSION_MARK} só ${OVERRIDABLE_SIGNAL_KEYS.join(', ')} entram por aqui; o resto é lido de feature.json/checks.json/git.` +
|
|
194
|
-
' Para uma decisão toda manual, use `morph-spec gate-decision`.\n'
|
|
195
|
-
));
|
|
196
|
-
}
|
|
197
|
-
for (const key of OVERRIDABLE_SIGNAL_KEYS) {
|
|
198
|
-
if (key in parsed) overrides[key] = parsed[key];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const cwd = process.cwd();
|
|
204
|
-
const signals = { ...collectSignals(featureName, feature, cwd, gateName), ...overrides };
|
|
205
|
-
|
|
206
|
-
const trust = options.trust || readTrustFromConfig();
|
|
207
|
-
const computed = shouldPauseGate({ trust }, signals);
|
|
208
|
-
const manual = feature.gateDecisions?.[gateName];
|
|
209
|
-
const manualPause = manual?.source === 'manual' && manual.pause === true;
|
|
210
|
-
const { pause, reason, signal, resolver, todo } = manualPause
|
|
211
|
-
? { pause: true, reason: manual.reason, signal: 'manual', resolver: 'human',
|
|
212
|
-
todo: `${ASK_OWNER}; pausa manual: só depois que o dono liberar, grave \`morph-spec gate-decision ${featureName} ${gateName} --pause false\`` }
|
|
213
|
-
: { ...computed, todo: fillTodo(computed.todo, featureName, gateName) };
|
|
214
|
-
|
|
215
|
-
const entry = await persistGateDecision(featureName, gateName, {
|
|
216
|
-
pause, reason, signal, resolver, todo, signals, trust, cwd, source: manualPause ? 'manual' : 'gate-check',
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
const riskSignals = getRiskSignals(signals);
|
|
220
|
-
if (options.json) {
|
|
221
|
-
console.log(JSON.stringify({ feature: featureName, gate: gateName, ...entry, riskSignals }, null, 2));
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const who = `${GATE_NAME[gateName]} de ${featureRef(featureName, feature, readPlanChecks(cwd, featureName).checks?.summary)}`;
|
|
226
|
-
if (!entry.pause) {
|
|
227
|
-
console.log(chalk.green(`\n✓ ${who}: segue sem parar.\n`));
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
console.log(entry.resolver === 'session'
|
|
231
|
-
? chalk.yellow(`\n↻ ${who} parou: a sessão resolve e segue.`)
|
|
232
|
-
: chalk.yellow(`\n⏸ ${who} parou: espera você.`));
|
|
233
|
-
console.log(` Motivo: ${entry.reason}`);
|
|
234
|
-
if (manualPause) {
|
|
235
|
-
console.log(' A pausa foi registrada à mão e continua até alguém liberar.');
|
|
236
|
-
if (computed.pause) console.log(` Além disso: ${computed.reason}`);
|
|
237
|
-
}
|
|
238
|
-
if (entry.todo) console.log(chalk.gray(` ${SESSION_MARK} ${entry.todo}`));
|
|
239
|
-
console.log('');
|
|
240
|
-
} catch (error) {
|
|
241
|
-
console.error(chalk.red(`\n✗ Não deu para decidir a etapa: ${error.message}\n`));
|
|
242
|
-
process.exit(1);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import { getFeature, updateFeature } from '../../core/state/state-manager.js';
|
|
5
|
-
import { assertOwnerTree, ownerTreeRefusalLines } from '../../lib/worktree/feature-truth.js';
|
|
6
|
-
import { mockupsHash } from '../../lib/specs/screen-checklist.js';
|
|
7
|
-
import { recordGateEvent } from '../../../framework/hooks/shared/gate-event.js';
|
|
8
|
-
import { GATE_NAME } from '../../../framework/hooks/shared/owner-words.js';
|
|
9
|
-
import { SESSION_MARK } from '../../../framework/hooks/shared/next-step.js';
|
|
10
|
-
import { ownerRef } from '../../../framework/hooks/shared/report-progress.js';
|
|
11
|
-
|
|
12
|
-
export const VALID_GATES = ['plan', 'uiux', 'review'];
|
|
13
|
-
|
|
14
|
-
function parsePauseValue(raw) {
|
|
15
|
-
const v = String(raw).toLowerCase();
|
|
16
|
-
if (v === 'true') return true;
|
|
17
|
-
if (v === 'false') return false;
|
|
18
|
-
console.error(chalk.red(`\n✗ --pause inválido: "${raw}" (use true ou false)\n`));
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** `trust` from the committed config (BOM-tolerant), defaulting to "auto". */
|
|
23
|
-
export function readTrustFromConfig() {
|
|
24
|
-
try {
|
|
25
|
-
const path = join(process.cwd(), '.morph', 'config', 'config.json');
|
|
26
|
-
if (!existsSync(path)) return 'auto';
|
|
27
|
-
const raw = readFileSync(path, 'utf8').replace(/^/, '');
|
|
28
|
-
return JSON.parse(raw).trust || 'auto';
|
|
29
|
-
} catch {
|
|
30
|
-
return 'auto';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The ONE write path of `gateDecisions.{gate}`, shared by `gate-decision` and `gate-check`.
|
|
36
|
-
* Does not validate `gateName`. A uiux decision records the `mockupsHash` it saw.
|
|
37
|
-
*/
|
|
38
|
-
export async function persistGateDecision(featureName, gateName, { pause, reason, signal, resolver, todo, signals = {}, trust, cwd = process.cwd(), source } = {}) {
|
|
39
|
-
const entry = {
|
|
40
|
-
pause,
|
|
41
|
-
resolver: pause ? resolver ?? 'human' : null,
|
|
42
|
-
reason: reason || (pause ? 'risco detectado' : 'nenhum sinal de risco'),
|
|
43
|
-
todo: pause && todo ? todo : null,
|
|
44
|
-
signals,
|
|
45
|
-
trust: trust || readTrustFromConfig(),
|
|
46
|
-
decidedAt: new Date().toISOString(),
|
|
47
|
-
...(gateName === 'uiux' ? { mockupsHash: mockupsHash(cwd, featureName) } : {}),
|
|
48
|
-
source,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
await updateFeature(featureName, `gateDecisions.${gateName}`, entry);
|
|
52
|
-
recordGateEvent(cwd, { feature: featureName, gate: gateName, step: 'decision', pause, signal, source, resolver: entry.resolver });
|
|
53
|
-
return entry;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function gateDecisionCommand(featureName, gateName, options = {}) {
|
|
57
|
-
try {
|
|
58
|
-
if (!VALID_GATES.includes(gateName)) {
|
|
59
|
-
console.error(chalk.red(`\n✗ Etapa de aprovação desconhecida: ${gateName}.`));
|
|
60
|
-
console.error(chalk.gray(` ${SESSION_MARK} use uma destas: ${VALID_GATES.join(', ')}\n`));
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (options.pause === undefined) {
|
|
65
|
-
console.error(chalk.red('\n✗ Falta o --pause (true ou false)\n'));
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
const pause = parsePauseValue(options.pause);
|
|
69
|
-
|
|
70
|
-
const feature = getFeature(featureName);
|
|
71
|
-
if (!feature) {
|
|
72
|
-
console.error(chalk.red(`\n✗ Funcionalidade não encontrada: ${featureName}.\n`));
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const owner = assertOwnerTree(featureName, process.cwd());
|
|
77
|
-
if (owner.blocked) {
|
|
78
|
-
for (const { tone, text } of ownerTreeRefusalLines(featureName, owner.tree, owner.branch, `morph-spec gate-decision ${featureName} ${gateName} --pause ${pause}`)) {
|
|
79
|
-
console.error(chalk[tone](text));
|
|
80
|
-
}
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let signals = {};
|
|
85
|
-
if (options.signals !== undefined) {
|
|
86
|
-
try {
|
|
87
|
-
signals = JSON.parse(options.signals);
|
|
88
|
-
} catch (err) {
|
|
89
|
-
console.error(chalk.red(`\n✗ --signals inválido: não é JSON (${err.message})\n`));
|
|
90
|
-
process.exit(1);
|
|
91
|
-
}
|
|
92
|
-
if (!signals || typeof signals !== 'object' || Array.isArray(signals)) {
|
|
93
|
-
console.error(chalk.red('\n✗ --signals inválido: precisa ser um objeto JSON, por exemplo \'{"standardsViolations":[]}\'\n'));
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const entry = await persistGateDecision(featureName, gateName, {
|
|
99
|
-
pause,
|
|
100
|
-
reason: options.reason,
|
|
101
|
-
signal: 'manual',
|
|
102
|
-
signals,
|
|
103
|
-
trust: options.trust,
|
|
104
|
-
source: 'manual',
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
if (options.json) {
|
|
108
|
-
console.log(JSON.stringify({ feature: featureName, gate: gateName, ...entry }, null, 2));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const who = `${GATE_NAME[gateName]} de ${ownerRef(process.cwd(), featureName, feature)}`;
|
|
113
|
-
console.log(chalk.green(entry.pause
|
|
114
|
-
? `\n⏸ Decisão registrada: ${who} para e espera você.`
|
|
115
|
-
: `\n✓ Decisão registrada: ${who} segue sem parar.`));
|
|
116
|
-
console.log(` Motivo: ${entry.reason}`);
|
|
117
|
-
console.log('');
|
|
118
|
-
} catch (error) {
|
|
119
|
-
console.error(chalk.red(`\n✗ Não deu para registrar a decisão: ${error.message}\n`));
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { existsSync, readdirSync, readFileSync, statSync } from 'fs';
|
|
3
|
-
import { basename, join } from 'path';
|
|
4
|
-
import { derivePhase } from '../../core/state/state-manager.js';
|
|
5
|
-
import { gateOrderViolations } from '../../core/state/gate-order.js';
|
|
6
|
-
import { missingIdentity } from '../../core/state/feature-identity.js';
|
|
7
|
-
import { derivePhaseFrom, fileSetArtifactProbe } from '../../../framework/hooks/shared/state-reader.js';
|
|
8
|
-
import { isGitRepo } from '../project/worktree.js';
|
|
9
|
-
import { morphBranches, currentBranch, branchView } from '../../lib/worktree/feature-truth.js';
|
|
10
|
-
import { buildPrIndex } from '../../lib/git/pr-index.js';
|
|
11
|
-
import { pendingPrFeatures, prForFeature } from '../../lib/git/pending-prs.js';
|
|
12
|
-
import { PHASE_NAME, WORK_NAME, featureName } from '../../../framework/hooks/shared/owner-words.js';
|
|
13
|
-
import { featureSummary } from '../../../framework/hooks/shared/report-progress.js';
|
|
14
|
-
|
|
15
|
-
// Read-only: feature.json straight off disk, never `loadState` (which mutates). By default the
|
|
16
|
-
// branch `morph/{f}` wins over a stale root copy; `--no-branch` reads only the disk.
|
|
17
|
-
|
|
18
|
-
const G = ['plan', 'uiux', 'review'];
|
|
19
|
-
|
|
20
|
-
function readFeaturesIn(baseDir, subdir, location) {
|
|
21
|
-
const root = join(baseDir, '.morph', subdir);
|
|
22
|
-
if (!existsSync(root)) return [];
|
|
23
|
-
const rows = [];
|
|
24
|
-
for (const name of readdirSync(root)) {
|
|
25
|
-
const fdir = join(root, name);
|
|
26
|
-
try {
|
|
27
|
-
if (!statSync(fdir).isDirectory()) continue;
|
|
28
|
-
} catch { continue; }
|
|
29
|
-
const fjPath = join(fdir, 'feature.json');
|
|
30
|
-
if (!existsSync(fjPath)) continue;
|
|
31
|
-
let fj;
|
|
32
|
-
try {
|
|
33
|
-
fj = JSON.parse(readFileSync(fjPath, 'utf8'));
|
|
34
|
-
} catch { fj = { status: 'unknown', __corrupt: true }; }
|
|
35
|
-
rows.push(buildRow(name, fj, fdir, location));
|
|
36
|
-
}
|
|
37
|
-
return rows;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function readWorktreePointer(fj) {
|
|
41
|
-
const w = fj?.worktree;
|
|
42
|
-
if (!w?.path) return null;
|
|
43
|
-
return { path: w.path, branch: w.branch || null, exists: existsSync(w.path) };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Shared by the disk and branch reads so the two never drift on what counts as an anomaly.
|
|
47
|
-
function shapeRow(name, fj, location, phase, { corruptDisk = false, worktree = null, source = 'disk', branch = null, planName = null } = {}) {
|
|
48
|
-
const gates = {};
|
|
49
|
-
for (const g of G) gates[g] = fj.approvalGates?.[g]?.approved === true;
|
|
50
|
-
|
|
51
|
-
// Review approved via `--self-assessed`: a recorded degradation is only worth it if visible.
|
|
52
|
-
const selfAssessed = fj.approvalGates?.review?.selfAssessed === true;
|
|
53
|
-
|
|
54
|
-
const flags = [];
|
|
55
|
-
if (corruptDisk) flags.push('corrupt');
|
|
56
|
-
if (selfAssessed) flags.push('self-assessed-g3');
|
|
57
|
-
for (const field of missingIdentity(fj)) flags.push(`missing-${field}`);
|
|
58
|
-
for (const v of gateOrderViolations(fj.approvalGates)) flags.push(`gate-order:${v.gate}`);
|
|
59
|
-
if (worktree && !worktree.exists) flags.push('worktree-missing');
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
feature: name,
|
|
63
|
-
name: fj.name || null,
|
|
64
|
-
planName,
|
|
65
|
-
description: fj.description || null,
|
|
66
|
-
workType: fj.workType || 'feature',
|
|
67
|
-
status: fj.status || 'unknown',
|
|
68
|
-
phase: location === 'archived' ? 'archived' : phase,
|
|
69
|
-
gates,
|
|
70
|
-
selfAssessed,
|
|
71
|
-
flags,
|
|
72
|
-
location,
|
|
73
|
-
createdAt: fj.createdAt || null,
|
|
74
|
-
updatedAt: fj.updatedAt || null,
|
|
75
|
-
// `worktree` always comes from the local disk copy, whatever `source` reads the rest from.
|
|
76
|
-
source,
|
|
77
|
-
branch,
|
|
78
|
-
worktree,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function buildRow(name, fj, fdir, location) {
|
|
83
|
-
const phase = location === 'archived' ? 'archived' : derivePhase(fdir);
|
|
84
|
-
return shapeRow(name, fj, location, phase, {
|
|
85
|
-
corruptDisk: Boolean(fj.__corrupt),
|
|
86
|
-
worktree: readWorktreePointer(fj),
|
|
87
|
-
source: 'disk',
|
|
88
|
-
branch: null,
|
|
89
|
-
planName: featureSummary(fdir)?.name ?? null,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Never throws: a git hiccup or a corrupt blob leaves the disk-read row in place.
|
|
94
|
-
function resolveBranchTruth(cwd, rows) {
|
|
95
|
-
if (!isGitRepo(cwd)) return;
|
|
96
|
-
let head;
|
|
97
|
-
let branches;
|
|
98
|
-
try {
|
|
99
|
-
head = currentBranch(cwd);
|
|
100
|
-
branches = morphBranches(cwd);
|
|
101
|
-
} catch { return; }
|
|
102
|
-
if (!branches || branches.size === 0) return;
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < rows.length; i++) {
|
|
105
|
-
const row = rows[i];
|
|
106
|
-
if (row.location === 'archived') continue;
|
|
107
|
-
if (!branches.has(row.feature)) continue;
|
|
108
|
-
const featureBranch = `morph/${row.feature}`;
|
|
109
|
-
if (head === featureBranch) continue; // cwd IS the checkout — disk is freshest, never go backwards
|
|
110
|
-
const view = branchView(cwd, row.feature, featureBranch);
|
|
111
|
-
if (!view?.fj) continue;
|
|
112
|
-
const phase = derivePhaseFrom(view.fj, fileSetArtifactProbe(view.files));
|
|
113
|
-
rows[i] = shapeRow(row.feature, view.fj, row.location, phase, {
|
|
114
|
-
corruptDisk: row.flags.includes('corrupt'),
|
|
115
|
-
worktree: row.worktree, // root-owned — never trust the branch copy for this
|
|
116
|
-
planName: row.planName,
|
|
117
|
-
source: 'branch',
|
|
118
|
-
branch: featureBranch,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// The untracked root skeleton survives a `git pull` that brings `.morph/archive/{f}`. Flagged,
|
|
124
|
-
// never hidden: a read-only board must not silently suppress the anomaly.
|
|
125
|
-
function flagArchivedElsewhere(cwd, rows) {
|
|
126
|
-
for (const row of rows) {
|
|
127
|
-
if (row.location !== 'active') continue;
|
|
128
|
-
if (existsSync(join(cwd, '.morph', 'archive', row.feature, 'feature.json'))) {
|
|
129
|
-
row.flags.push('archived-elsewhere');
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// O estado que o `finish --pr` deixa: sem esta linha o trabalho fica sem dono no quadro, e
|
|
135
|
-
// uma branch sem dono é candidata a poda.
|
|
136
|
-
function pendingRow(p) {
|
|
137
|
-
return {
|
|
138
|
-
feature: p.feature,
|
|
139
|
-
name: null,
|
|
140
|
-
description: null,
|
|
141
|
-
workType: null,
|
|
142
|
-
status: 'in_progress',
|
|
143
|
-
phase: 'aguardando-merge',
|
|
144
|
-
gates: { plan: false, uiux: false, review: false },
|
|
145
|
-
selfAssessed: false,
|
|
146
|
-
flags: ['pr-pending'],
|
|
147
|
-
location: 'pr-pending',
|
|
148
|
-
createdAt: p.createdAt,
|
|
149
|
-
updatedAt: null,
|
|
150
|
-
source: 'pr',
|
|
151
|
-
branch: p.branch,
|
|
152
|
-
worktree: null,
|
|
153
|
-
pr: { number: p.number, state: p.state, url: p.url, ageDays: p.ageDays },
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const mark = (on) => (on ? chalk.green('✓') : chalk.gray('·'));
|
|
158
|
-
const truncate = (s, n) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
|
|
159
|
-
|
|
160
|
-
function whereLabel(row) {
|
|
161
|
-
if (row.location === 'pr-pending') return `branch ${row.branch}`;
|
|
162
|
-
if (row.location === 'archived') return '-';
|
|
163
|
-
if (row.worktree) return row.worktree.exists ? `worktree ${basename(row.worktree.path)}` : '⚠ worktree ausente';
|
|
164
|
-
if (row.source === 'branch') return `branch ${row.branch}`;
|
|
165
|
-
return 'raiz';
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const PR_STATE = { open: 'aberto', merged: 'mergeado', closed: 'fechado' };
|
|
169
|
-
const STATUS_NAME = { draft: 'rascunho', in_progress: 'em andamento', completed: 'concluída', unknown: 'ilegível' };
|
|
170
|
-
|
|
171
|
-
const prCell = (pr) => {
|
|
172
|
-
if (!pr) return '-';
|
|
173
|
-
const state = String(pr.state || '').toLowerCase();
|
|
174
|
-
return `#${pr.number} ${PR_STATE[state] ?? state}`;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export function listCommand(options = {}) {
|
|
178
|
-
const cwd = options.cwd || process.cwd();
|
|
179
|
-
const rows = readFeaturesIn(cwd, 'features', 'active');
|
|
180
|
-
if (options.all || options.archived) rows.push(...readFeaturesIn(cwd, 'archive', 'archived'));
|
|
181
|
-
|
|
182
|
-
flagArchivedElsewhere(cwd, rows);
|
|
183
|
-
// Commander's `--no-branch` sets options.branch = false; anything else (undefined/true) reads the branch.
|
|
184
|
-
if (options.branch !== false) resolveBranchTruth(cwd, rows);
|
|
185
|
-
|
|
186
|
-
// Uma consulta ao `gh` por invocação. `prIndex` `null` = a pergunta não pôde ser feita: sem
|
|
187
|
-
// coluna PR, e sem `-` que afirme "sem PR" para o que é "não sabemos".
|
|
188
|
-
let prIndex = null;
|
|
189
|
-
if (options.branch !== false) {
|
|
190
|
-
prIndex = buildPrIndex(cwd);
|
|
191
|
-
for (const row of rows) {
|
|
192
|
-
const pr = prForFeature(prIndex, row.feature);
|
|
193
|
-
row.pr = pr ? { number: pr.number, state: pr.state, url: pr.url, ageDays: null } : null;
|
|
194
|
-
}
|
|
195
|
-
const known = new Set(rows.map((r) => r.feature));
|
|
196
|
-
// `null` propaga desconhecido: nenhuma linha sintetizada.
|
|
197
|
-
for (const p of pendingPrFeatures(cwd, { index: prIndex }) || []) {
|
|
198
|
-
if (!known.has(p.feature)) rows.push(pendingRow(p));
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
for (const row of rows) row.pr = null;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
rows.sort((a, b) => a.feature.localeCompare(b.feature));
|
|
205
|
-
|
|
206
|
-
if (options.json) {
|
|
207
|
-
console.log(JSON.stringify(rows));
|
|
208
|
-
process.exit(0);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (!rows.length) {
|
|
212
|
-
console.log(chalk.gray('Nenhuma funcionalidade neste projeto ainda.'));
|
|
213
|
-
process.exit(0);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const col = (s, w) => String(s ?? '-').padEnd(w);
|
|
217
|
-
const showPr = Boolean(prIndex);
|
|
218
|
-
// `pr-pending` é trabalho em voo, não anomalia: segue em `flags` no `--json`, sem `⚠`.
|
|
219
|
-
const warnFlags = (r) => r.flags.filter((f) => f !== 'pr-pending');
|
|
220
|
-
console.log(chalk.white.bold(
|
|
221
|
-
col('FUNCIONALIDADE', 34) + col('TIPO', 20) + col('SITUAÇÃO', 14) + col('PASSO', 24) + col('ONDE', 22) + (showPr ? col('PR', 12) : '')
|
|
222
|
-
+ col('Plano', 7) + col('Telas', 7) + col('Revisão', 9) + col('', 2) + 'ID',
|
|
223
|
-
));
|
|
224
|
-
for (const r of rows) {
|
|
225
|
-
const flag = warnFlags(r).length ? chalk.yellow('⚠') : ' ';
|
|
226
|
-
const name = r.location === 'pr-pending'
|
|
227
|
-
? `esperando o merge${r.pr?.ageDays != null ? ` há ${r.pr.ageDays}d` : ''}, sem cópia local`
|
|
228
|
-
: featureName(r.feature, { description: r.description }, r.planName ? { name: r.planName } : r.name && r.name !== r.feature ? { name: r.name } : null);
|
|
229
|
-
const note = r.selfAssessed ? chalk.yellow(' (revisão feita pela própria sessão)') : '';
|
|
230
|
-
// padEnd counts the invisible color codes; pad the plain marks manually.
|
|
231
|
-
console.log(
|
|
232
|
-
col(truncate(name, 33), 34) + col(WORK_NAME[r.workType] ?? r.workType, 20) + col(STATUS_NAME[r.status] ?? r.status, 14)
|
|
233
|
-
+ col(r.phase === 'archived' ? 'Arquivada' : PHASE_NAME[r.phase] ?? r.phase, 24) + col(whereLabel(r), 22) + (showPr ? col(prCell(r.pr), 12) : '')
|
|
234
|
-
+ mark(r.gates.plan) + ' ' + mark(r.gates.uiux) + ' ' + mark(r.gates.review) + ' '
|
|
235
|
-
+ flag + ' ' + r.feature + note,
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
const flagged = rows.filter((r) => warnFlags(r).length);
|
|
239
|
-
if (flagged.length) {
|
|
240
|
-
console.log(chalk.gray(`\n⚠ ${flagged.length} com inconsistência. Para ver o que é: morph-spec doctor`));
|
|
241
|
-
}
|
|
242
|
-
console.log(chalk.gray(`\nPlano, Telas e Revisão: ✓ aprovado · ainda não${options.all || options.archived ? '. Inclui as arquivadas.' : ''}`));
|
|
243
|
-
process.exit(0);
|
|
244
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { nextStepFor } from '../../lib/next-step.js';
|
|
3
|
-
import { resolveFeatureTree } from '../../lib/worktree/feature-truth.js';
|
|
4
|
-
|
|
5
|
-
// Read-only: decides in the tree that owns the feature, since the root copy of a worktree feature is a birth skeleton.
|
|
6
|
-
export function nextCommand(featureName, options = {}) {
|
|
7
|
-
const owner = resolveFeatureTree(featureName, process.cwd());
|
|
8
|
-
const next = owner.source === 'none' || owner.source === 'branch-only' ? null : nextStepFor(featureName, owner.tree);
|
|
9
|
-
|
|
10
|
-
if (!next) {
|
|
11
|
-
const error = owner.source === 'branch-only' ? 'feature-not-in-tree' : 'feature-not-found';
|
|
12
|
-
if (options.json) console.log(JSON.stringify({ error, feature: featureName, branch: owner.branch ?? null }));
|
|
13
|
-
else if (owner.branch) console.error(chalk.red(`\n❌ A feature ${featureName} existe só na branch ${owner.branch}. Para trazê-la: morph-spec worktree setup ${featureName}\n`));
|
|
14
|
-
else console.error(chalk.red(`\n❌ Não achei a feature ${featureName} neste projeto.\n`));
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (options.json) {
|
|
19
|
-
console.log(JSON.stringify({ ...next, feature: featureName, tree: owner.tree }));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
for (const line of next.retrato) console.log(line);
|
|
23
|
-
if (owner.tree !== process.cwd()) console.log(chalk.gray(`Pasta da feature: ${owner.tree}`));
|
|
24
|
-
}
|