@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,39 +0,0 @@
|
|
|
1
|
-
import { basename } from 'path';
|
|
2
|
-
import { readPlanChecks } from '../plan/checks.js';
|
|
3
|
-
import { changedPathsAgainst, detectDefaultBranch } from '../git/default-branch.js';
|
|
4
|
-
import { resolveComposeFile } from '../../../framework/hooks/shared/e2e-check.js';
|
|
5
|
-
import { E2E_SPEC_LOCATIONS } from '../../../framework/hooks/shared/frontend-locations.js';
|
|
6
|
-
|
|
7
|
-
export const E2E_NOT_APPLICABLE = 'not applicable: no `prova: e2e` scenario and the diff touches no UI, e2e spec or container file';
|
|
8
|
-
|
|
9
|
-
const UI_FILE = /\.(tsx|jsx|vue|svelte|astro|css|scss|sass|less|html)$/i;
|
|
10
|
-
const RUNTIME_FILE = /(^|\/)(dockerfile[^/]*|\.dockerignore|(docker-)?compose[^/]*\.ya?ml|playwright\.config\.[cm]?[jt]s)$/i;
|
|
11
|
-
const E2E_DIR = /(^|\/)e2e\//i;
|
|
12
|
-
// The harness writes here itself (verify syncs .claude/rules/), so these never mean the app changed.
|
|
13
|
-
const HARNESS_DIR = /^\.(morph|claude)\//;
|
|
14
|
-
const KNOWN_PACKAGE_DIRS = E2E_SPEC_LOCATIONS.filter((dir) => dir !== '.');
|
|
15
|
-
|
|
16
|
-
function packageDirsOf(config) {
|
|
17
|
-
const declared = [config?.project?.frontendPath, ...(config?.project?.tests ?? []).filter((n) => n?.runner !== 'dotnet').map((n) => n?.cwd)];
|
|
18
|
-
const extra = declared.filter((d) => typeof d === 'string').map((d) => d.replace(/\\/g, '/').replace(/^\.\/|\/$/g, '')).filter((d) => d && d !== '.');
|
|
19
|
-
return [...KNOWN_PACKAGE_DIRS, ...extra];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const touchesRuntime = (file, composeFile, packageDirs) => UI_FILE.test(file)
|
|
23
|
-
|| RUNTIME_FILE.test(file)
|
|
24
|
-
|| E2E_DIR.test(file)
|
|
25
|
-
|| (composeFile && basename(file) === basename(composeFile))
|
|
26
|
-
|| packageDirs.some((dir) => file === dir || file.startsWith(`${dir}/`));
|
|
27
|
-
|
|
28
|
-
/** Unknown (no git, no base, empty diff) is applicable: the e2e only stands down on evidence. */
|
|
29
|
-
export function e2eApplicability(projectPath, featureName, config) {
|
|
30
|
-
const { checks } = readPlanChecks(projectPath, featureName);
|
|
31
|
-
if (checks?.checks?.some((c) => c.proof === 'e2e')) return { applicable: true, reason: 'prova: e2e' };
|
|
32
|
-
const base = detectDefaultBranch(projectPath);
|
|
33
|
-
const changed = base ? changedPathsAgainst(base, projectPath).filter((f) => !HARNESS_DIR.test(f)) : [];
|
|
34
|
-
if (changed.length === 0) return { applicable: true, reason: 'diff unknown' };
|
|
35
|
-
const composeFile = resolveComposeFile(projectPath, config);
|
|
36
|
-
const packageDirs = packageDirsOf(config);
|
|
37
|
-
const hit = changed.find((f) => touchesRuntime(f, composeFile, packageDirs));
|
|
38
|
-
return hit ? { applicable: true, reason: hit } : { applicable: false, reason: E2E_NOT_APPLICABLE };
|
|
39
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// One place for `e2e up` and the `e2e` node of `verify`, which must never disagree on ports. Lives in
|
|
2
|
-
// src/lib, not hooks/shared, because it depends on env-allocator.js and hooks run without `src/`.
|
|
3
|
-
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
|
|
8
|
-
import { loadEnvFile } from '../../../framework/hooks/shared/e2e-check.js';
|
|
9
|
-
import { allocateEnvBlock, portLayout, resolveFleetConfig, resolvePortAliases } from '../worktree/env-allocator.js';
|
|
10
|
-
|
|
11
|
-
// Ports come from `portLayout()`, the same function that renders `.morph/worktree.env`. The credentials
|
|
12
|
-
// file loads after the layout but cannot outrank it: a `.env.e2e` copied from a sibling worktree carries
|
|
13
|
-
// that worktree's block. Ignored keys are announced on stderr; stdout carries `morph-spec env` output.
|
|
14
|
-
// `withCredentials: false` keeps envFile values off stdout (`morph-spec env` lands in transcripts);
|
|
15
|
-
// the withheld names go to stderr.
|
|
16
|
-
export function buildComposeEnv({ cwd, config, featureName, gitCommonDir, withCredentials = true }) {
|
|
17
|
-
const env = {};
|
|
18
|
-
let layoutKeys = null;
|
|
19
|
-
|
|
20
|
-
if (gitCommonDir) {
|
|
21
|
-
try {
|
|
22
|
-
const { basePort, blockSize } = resolveFleetConfig(cwd);
|
|
23
|
-
const block = allocateEnvBlock(featureName, { gitCommonDir, basePort, blockSize });
|
|
24
|
-
|
|
25
|
-
const { aliases, problems } = resolvePortAliases(config);
|
|
26
|
-
for (const problem of problems) console.warn(chalk.yellow(` ⚠ ${problem} — ignorado`));
|
|
27
|
-
|
|
28
|
-
const layout = {
|
|
29
|
-
...portLayout(block, { stack: config?.project?.stack ?? '', feature: featureName, aliases }),
|
|
30
|
-
PLAYWRIGHT_BASE_URL: `http://localhost:${block.base}`,
|
|
31
|
-
};
|
|
32
|
-
Object.assign(env, layout);
|
|
33
|
-
layoutKeys = new Set(Object.keys(layout));
|
|
34
|
-
} catch {
|
|
35
|
-
// No block → default ports. Surfaces later as a port conflict, never here.
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Credentials live in a gitignored env file, never in the committed config.
|
|
40
|
-
const envFile = config?.e2e?.auth?.envFile;
|
|
41
|
-
if (envFile) {
|
|
42
|
-
const ignored = [];
|
|
43
|
-
const withheld = [];
|
|
44
|
-
const foreignPorts = [];
|
|
45
|
-
const layoutPorts = layoutKeys ? new Set([...layoutKeys].map((key) => env[key])) : null;
|
|
46
|
-
for (const [key, value] of Object.entries(loadEnvFile(join(cwd, envFile)))) {
|
|
47
|
-
if (layoutKeys?.has(key)) {
|
|
48
|
-
ignored.push(key);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (layoutPorts && /(^|_)PORT$/.test(key) && !layoutPorts.has(value)) foreignPorts.push(`${key}=${value}`);
|
|
52
|
-
if (withCredentials) env[key] = value;
|
|
53
|
-
else withheld.push(key);
|
|
54
|
-
}
|
|
55
|
-
if (ignored.length) reportIgnoredLayoutKeys(envFile, ignored, env);
|
|
56
|
-
if (foreignPorts.length) reportForeignPorts(envFile, foreignPorts);
|
|
57
|
-
if (withheld.length) {
|
|
58
|
-
console.warn(chalk.yellow(
|
|
59
|
-
` ⚠ ${envFile}: ${withheld.join(', ')} omitida(s) — credenciais não vão para o stdout; use --with-secrets dentro de eval "$(…)".`,
|
|
60
|
-
));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return env;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function reportForeignPorts(envFile, foreignPorts) {
|
|
68
|
-
console.warn(chalk.yellow(
|
|
69
|
-
` ⚠ ${envFile}: ${foreignPorts.join(', ')} não é porta do bloco desta worktree. `
|
|
70
|
-
+ 'Se nomeia uma das portas do layout, declare-a em e2e.portEnvNames (ex.: { "postgres": "PG_PORT" }) e o bloco passa a prevalecer.',
|
|
71
|
-
));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function reportIgnoredLayoutKeys(envFile, ignored, env) {
|
|
75
|
-
const shown = ignored.map((key) => `${key}=${env[key]}`).join(', ');
|
|
76
|
-
console.warn(chalk.yellow(
|
|
77
|
-
` ⚠ ${envFile}: ${ignored.join(', ')} ignorada(s) — o bloco de portas desta worktree prevalece (${shown}). `
|
|
78
|
-
+ 'O envFile carrega credenciais; portas vêm do bloco alocado.',
|
|
79
|
-
));
|
|
80
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// `verify` leaves the stack up on purpose, so this is the one place that brings it down. Runs from the
|
|
2
|
-
// owning tree with the full port block, or compose resolves a different config and `down` misses it.
|
|
3
|
-
// Fail-open: a stack that refuses to come down must never fail a finish that already merged.
|
|
4
|
-
|
|
5
|
-
import { execFileSync } from 'child_process';
|
|
6
|
-
import { existsSync, readFileSync } from 'fs';
|
|
7
|
-
import { join, resolve } from 'path';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
composeProjectName,
|
|
11
|
-
defaultExec,
|
|
12
|
-
deleteStamp,
|
|
13
|
-
resolveComposeFile,
|
|
14
|
-
tearDownStack,
|
|
15
|
-
} from '../../../framework/hooks/shared/e2e-check.js';
|
|
16
|
-
import { stopHostServices } from '../../../framework/hooks/shared/host-services.js';
|
|
17
|
-
import { buildComposeEnv } from './compose-env.js';
|
|
18
|
-
|
|
19
|
-
export function tearDownFeatureStack(feature, { root, worktreePath = null, volumes = true, images, _exec = defaultExec } = {}) {
|
|
20
|
-
const cwd = worktreePath && existsSync(worktreePath) ? worktreePath : root;
|
|
21
|
-
const projectName = composeProjectName(feature);
|
|
22
|
-
const gitCommonDir = resolveGitCommonDir(root);
|
|
23
|
-
// Before the compose lookup: a worktree already gone still leaves its host processes running.
|
|
24
|
-
const stopped = stopHostServicesSafely(gitCommonDir, projectName);
|
|
25
|
-
const hostServices = stopped.killed.length + stopped.skipped.length + stopped.warnings.length > 0
|
|
26
|
-
? { hostServices: stopped }
|
|
27
|
-
: {};
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const config = readConfig(cwd) ?? readConfig(root);
|
|
31
|
-
|
|
32
|
-
// The owning tree's compose first; the root's copy is the fallback for a worktree already half torn down.
|
|
33
|
-
let composeCwd = cwd;
|
|
34
|
-
let composeFile = resolveComposeFile(cwd, config);
|
|
35
|
-
if (!composeFile && cwd !== root) {
|
|
36
|
-
composeCwd = root;
|
|
37
|
-
composeFile = resolveComposeFile(root, config);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!composeFile) {
|
|
41
|
-
// Nothing to bring down, but a stamp left behind would tell the next `up` a stack it cannot see is fresh.
|
|
42
|
-
return { attempted: false, cwd, status: 'skip', stampDeleted: deleteStamp(gitCommonDir, projectName), ...hostServices };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const env = {
|
|
46
|
-
COMPOSE_PROJECT_NAME: projectName,
|
|
47
|
-
...buildComposeEnv({ cwd: composeCwd, config, featureName: feature, gitCommonDir }),
|
|
48
|
-
};
|
|
49
|
-
const result = tearDownStack(composeCwd, { composeFile, projectName, env, volumes, images }, _exec);
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
attempted: true,
|
|
53
|
-
cwd: composeCwd,
|
|
54
|
-
status: result.status,
|
|
55
|
-
stampDeleted: deleteStamp(gitCommonDir, projectName),
|
|
56
|
-
...hostServices,
|
|
57
|
-
...(result.status === 'fail' && result.output ? { output: result.output } : {}),
|
|
58
|
-
};
|
|
59
|
-
} catch {
|
|
60
|
-
// The stamp must not outlive the stack it described, even when the teardown itself blew up.
|
|
61
|
-
return { attempted: false, cwd, status: 'fail', stampDeleted: deleteStamp(gitCommonDir, projectName), ...hostServices };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function stopHostServicesSafely(gitCommonDir, projectName) {
|
|
66
|
-
try {
|
|
67
|
-
return stopHostServices(gitCommonDir, projectName);
|
|
68
|
-
} catch (err) {
|
|
69
|
-
return { killed: [], skipped: [], warnings: [`host services not stopped: ${err?.message ?? err}`] };
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function readConfig(dir) {
|
|
74
|
-
try {
|
|
75
|
-
const path = join(dir, '.morph', 'config', 'config.json');
|
|
76
|
-
if (!existsSync(path)) return null;
|
|
77
|
-
return JSON.parse(readFileSync(path, 'utf8').replace(/^/, ''));
|
|
78
|
-
} catch {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Same resolution (and same fail-open) as verify-runner's. */
|
|
84
|
-
function resolveGitCommonDir(cwd) {
|
|
85
|
-
try {
|
|
86
|
-
const common = execFileSync('git', ['rev-parse', '--git-common-dir'], {
|
|
87
|
-
cwd,
|
|
88
|
-
stdio: 'pipe',
|
|
89
|
-
encoding: 'utf-8',
|
|
90
|
-
windowsHide: true,
|
|
91
|
-
}).trim();
|
|
92
|
-
return common ? resolve(cwd, common) : null;
|
|
93
|
-
} catch {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// A squash-merge leaves the work in the default branch but none of the branch's commits,
|
|
2
|
-
// so `branch -d` refuses it and `-D` looks like discarding real work. Only the two
|
|
3
|
-
// `merged-*` classes are deletable; anything not PROVEN integrated is `unmerged`.
|
|
4
|
-
|
|
5
|
-
import { execFileSync } from 'child_process';
|
|
6
|
-
|
|
7
|
-
function git(args, cwd) {
|
|
8
|
-
return execFileSync('git', args, { cwd, stdio: 'pipe' }).toString();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** @returns {Array<{ name: string, sha: string, current: boolean, worktreePath: string|null }>} */
|
|
12
|
-
export function listLocalBranches(cwd) {
|
|
13
|
-
try {
|
|
14
|
-
const out = git(['for-each-ref', '--format=%(refname:short)%09%(objectname)%09%(HEAD)%09%(worktreepath)', 'refs/heads/'], cwd);
|
|
15
|
-
return out.split('\n').filter(Boolean).map((line) => {
|
|
16
|
-
const [name, sha, head, worktreePath] = line.split('\t');
|
|
17
|
-
return { name, sha, current: head === '*', worktreePath: worktreePath || null };
|
|
18
|
-
});
|
|
19
|
-
} catch {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function isAncestor(ancestor, descendant, cwd) {
|
|
25
|
-
try {
|
|
26
|
-
git(['merge-base', '--is-ancestor', ancestor, descendant], cwd);
|
|
27
|
-
return true;
|
|
28
|
-
} catch {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Two-dot tree diff, never `base...branch`: the three-dot form still shows a squash-merged
|
|
34
|
-
// branch's own changes. Fail-closed: a git error never reads as merged.
|
|
35
|
-
function treeIsIdentical(base, branch, cwd) {
|
|
36
|
-
try {
|
|
37
|
-
execFileSync('git', ['diff', '--quiet', base, branch], { cwd, stdio: 'pipe' });
|
|
38
|
-
return true;
|
|
39
|
-
} catch {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Reporting only: a squash-merged branch legitimately has commits ahead. @returns {number|null} */
|
|
45
|
-
export function commitsAhead(base, branch, cwd) {
|
|
46
|
-
try {
|
|
47
|
-
const out = git(['rev-list', '--count', `${base}..${branch}`], cwd).trim();
|
|
48
|
-
const n = Number(out);
|
|
49
|
-
return Number.isFinite(n) ? n : null;
|
|
50
|
-
} catch {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* `origin/<default>` when it exists, else the local branch.
|
|
57
|
-
* @returns {string|null} null = no baseline, so everything is `unmerged`.
|
|
58
|
-
*/
|
|
59
|
-
export function resolveBaseRef(defaultBranch, cwd) {
|
|
60
|
-
if (!defaultBranch) return null;
|
|
61
|
-
for (const ref of [`refs/remotes/origin/${defaultBranch}`, `refs/heads/${defaultBranch}`]) {
|
|
62
|
-
try {
|
|
63
|
-
git(['show-ref', '--verify', '--quiet', ref], cwd);
|
|
64
|
-
return ref.replace(/^refs\/(remotes|heads)\//, '');
|
|
65
|
-
} catch { /* try the next */ }
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Order is the policy: checked-out and open-PR branches are protected before any
|
|
71
|
-
// merged check, even when the tree matches the base.
|
|
72
|
-
export function classifyBranch(b, { baseRef, cwd, pr }) {
|
|
73
|
-
const prNum = pr?.number ?? null;
|
|
74
|
-
const mk = (kind, reason, deletable) => ({
|
|
75
|
-
name: b.name, kind, reason, pr: prNum, ahead: baseRef ? commitsAhead(baseRef, b.name, cwd) : null, deletable,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
if (b.current || b.worktreePath) {
|
|
79
|
-
return mk('in-worktree', b.current ? 'é a branch atual (HEAD)' : `está em uso pelo worktree ${b.worktreePath}`, false);
|
|
80
|
-
}
|
|
81
|
-
if (pr?.state === 'OPEN') {
|
|
82
|
-
return mk('open', `PR #${prNum} está OPEN — a branch é o que o PR aponta`, false);
|
|
83
|
-
}
|
|
84
|
-
if (!baseRef) {
|
|
85
|
-
return mk('unmerged', 'não há branch default resolvível (origin/HEAD, main ou master) para comparar', false);
|
|
86
|
-
}
|
|
87
|
-
if (isAncestor(b.name, baseRef, cwd)) {
|
|
88
|
-
return mk('merged-ancestral', `já é ancestral de ${baseRef}`, true);
|
|
89
|
-
}
|
|
90
|
-
if (pr?.state === 'MERGED') {
|
|
91
|
-
return mk('merged-squash', `PR #${prNum} está MERGED (squash-merge: os commits não entram em ${baseRef}, o trabalho sim)`, true);
|
|
92
|
-
}
|
|
93
|
-
if (treeIsIdentical(baseRef, b.name, cwd)) {
|
|
94
|
-
return mk('merged-squash', `a árvore é idêntica à de ${baseRef} — tudo que a branch muda já está lá`, true);
|
|
95
|
-
}
|
|
96
|
-
return mk('unmerged', `carrega mudanças que não estão em ${baseRef} e nenhum PR MERGED comprova o contrário`, false);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function classifyBranches({ cwd, defaultBranch, prIndex }) {
|
|
100
|
-
const baseRef = resolveBaseRef(defaultBranch, cwd);
|
|
101
|
-
return listLocalBranches(cwd)
|
|
102
|
-
.filter((b) => b.name !== defaultBranch)
|
|
103
|
-
.map((b) => classifyBranch(b, { baseRef, cwd, pr: prIndex?.get(b.name) ?? null }));
|
|
104
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'child_process';
|
|
2
|
-
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
-
import { getHeadSha } from './default-branch.js';
|
|
4
|
-
|
|
5
|
-
const MORPH_DIR = '.morph/';
|
|
6
|
-
const CONFIG_PATH = '.morph/config/config.json';
|
|
7
|
-
|
|
8
|
-
const gitOut = (cwd, args) => execFileSync('git', args, { cwd, stdio: 'pipe', maxBuffer: 64 * 1024 * 1024 }).toString();
|
|
9
|
-
|
|
10
|
-
export function withoutBaseline(text) {
|
|
11
|
-
const config = JSON.parse(text);
|
|
12
|
-
if (Array.isArray(config?.project?.tests)) {
|
|
13
|
-
for (const node of config.project.tests) delete node?.expectedCount;
|
|
14
|
-
}
|
|
15
|
-
return config;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function configMoved(cwd, sha, head) {
|
|
19
|
-
try {
|
|
20
|
-
const before = withoutBaseline(gitOut(cwd, ['show', `${sha}:${CONFIG_PATH}`]));
|
|
21
|
-
const after = withoutBaseline(gitOut(cwd, ['show', `${head}:${CONFIG_PATH}`]));
|
|
22
|
-
return !isDeepStrictEqual(before, after);
|
|
23
|
-
} catch {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// `.morph/` is bookkeeping, except the config: it names the test commands, and only its
|
|
29
|
-
// expectedCount is something a baseline run writes.
|
|
30
|
-
export function treeMovedSince(cwd, sha, head = getHeadSha(cwd)) {
|
|
31
|
-
if (!sha || !head || sha === head) return false;
|
|
32
|
-
let changed;
|
|
33
|
-
try {
|
|
34
|
-
// Without --no-renames a file moved into .morph/ shows only its new path and the deletion outside is lost.
|
|
35
|
-
changed = gitOut(cwd, ['diff', '--name-only', '--no-renames', '-z', sha, head]).split('\0').filter(Boolean);
|
|
36
|
-
} catch {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return changed.some((path) => !path.startsWith(MORPH_DIR) || (path === CONFIG_PATH && configMoved(cwd, sha, head)));
|
|
40
|
-
}
|
package/src/lib/git/gh.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MORPH_GH_BIN: string = outro binário; array JSON = prefixo de argv completo
|
|
3
|
-
* (Node ≥20 recusa shim `.cmd` sem `shell:true`, e `shell:true` reabre injeção de argumento).
|
|
4
|
-
* @returns {{ bin: string, prefix: string[] }}
|
|
5
|
-
*/
|
|
6
|
-
export function resolveGh() {
|
|
7
|
-
const raw = process.env.MORPH_GH_BIN;
|
|
8
|
-
if (raw && raw.trim().startsWith('[')) {
|
|
9
|
-
try {
|
|
10
|
-
const arr = JSON.parse(raw);
|
|
11
|
-
if (Array.isArray(arr) && arr.length) return { bin: String(arr[0]), prefix: arr.slice(1).map(String) };
|
|
12
|
-
} catch { /* não é JSON — trata como nome de binário abaixo */ }
|
|
13
|
-
}
|
|
14
|
-
return { bin: raw && raw.trim() ? raw.trim() : 'gh', prefix: [] };
|
|
15
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// Depois do `finish --pr` a raiz não guarda nada da feature até o merge: o PR aberto
|
|
2
|
-
// é o único registro de que a branch tem dono. `null` = DESCONHECIDO, nunca "sem pendência".
|
|
3
|
-
|
|
4
|
-
import { existsSync } from 'fs';
|
|
5
|
-
import { join } from 'path';
|
|
6
|
-
import { buildPrIndex } from './pr-index.js';
|
|
7
|
-
|
|
8
|
-
export const MORPH_BRANCH_RE = /^morph\/(.+)$/;
|
|
9
|
-
|
|
10
|
-
const DAY_MS = 86400000;
|
|
11
|
-
|
|
12
|
-
/** @returns {object|null} null = desconhecido OU sem PR; quem precisa distinguir olha o índice. */
|
|
13
|
-
export function prForFeature(index, feature) {
|
|
14
|
-
if (!index) return null;
|
|
15
|
-
return index.get(`morph/${feature}`) || null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function hasLocalFolder(root, feature) {
|
|
19
|
-
return existsSync(join(root, '.morph', 'features', feature))
|
|
20
|
-
|| existsSync(join(root, '.morph', 'archive', feature));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* PR OPEN numa branch `morph/*` cujo slug não tem pasta nesta árvore.
|
|
25
|
-
* @param {{ index?: Map<string,object>|null, now?: Date }} [opts] `index` ausente = constrói.
|
|
26
|
-
* @returns {Array<object>|null} null = DESCONHECIDO, nunca lista vazia por falta de informação.
|
|
27
|
-
*/
|
|
28
|
-
export function pendingPrFeatures(root, opts = {}) {
|
|
29
|
-
const index = opts.index !== undefined ? opts.index : buildPrIndex(root);
|
|
30
|
-
if (!index) return null;
|
|
31
|
-
|
|
32
|
-
const now = opts.now instanceof Date ? opts.now : new Date();
|
|
33
|
-
const out = [];
|
|
34
|
-
for (const [branch, pr] of index) {
|
|
35
|
-
const m = branch.match(MORPH_BRANCH_RE);
|
|
36
|
-
if (!m) continue;
|
|
37
|
-
if (pr.state !== 'OPEN') continue;
|
|
38
|
-
const feature = m[1];
|
|
39
|
-
if (hasLocalFolder(root, feature)) continue;
|
|
40
|
-
|
|
41
|
-
let ageDays = null;
|
|
42
|
-
if (pr.createdAt) {
|
|
43
|
-
const t = Date.parse(pr.createdAt);
|
|
44
|
-
if (!Number.isNaN(t)) ageDays = Math.floor((now.getTime() - t) / DAY_MS);
|
|
45
|
-
}
|
|
46
|
-
out.push({
|
|
47
|
-
feature,
|
|
48
|
-
branch,
|
|
49
|
-
number: pr.number,
|
|
50
|
-
state: pr.state,
|
|
51
|
-
url: pr.url ?? null,
|
|
52
|
-
createdAt: pr.createdAt ?? null,
|
|
53
|
-
ageDays,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
out.sort((a, b) => a.feature.localeCompare(b.feature));
|
|
57
|
-
return out;
|
|
58
|
-
}
|
package/src/lib/git/pr-files.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'child_process';
|
|
2
|
-
import { resolveGh } from './gh.js';
|
|
3
|
-
|
|
4
|
-
export const GH_FILES_CAP = 100;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Uma branch `morph/{f}` não prova que o PR carregou a feature: só o diff tocando
|
|
8
|
-
* `.morph/{features,archive}/{f}/` prova.
|
|
9
|
-
* @returns {boolean|null} null = DESCONHECIDO; só `false` autoriza calar um aviso.
|
|
10
|
-
*/
|
|
11
|
-
export function prCarriesFeature(root, number, feature, opts = {}) {
|
|
12
|
-
const timeout = opts.timeout ?? 8000;
|
|
13
|
-
try {
|
|
14
|
-
const { bin, prefix } = resolveGh();
|
|
15
|
-
const out = execFileSync(
|
|
16
|
-
bin,
|
|
17
|
-
[...prefix, 'pr', 'view', String(number), '--json', 'files'],
|
|
18
|
-
{ cwd: root, stdio: 'pipe', timeout },
|
|
19
|
-
).toString();
|
|
20
|
-
const files = JSON.parse(out)?.files;
|
|
21
|
-
if (!Array.isArray(files)) return null;
|
|
22
|
-
// A barra final é a fronteira do slug: `vitrine` não pode casar `vitrine-lead/`.
|
|
23
|
-
const owned = [`.morph/features/${feature}/`, `.morph/archive/${feature}/`];
|
|
24
|
-
if (files.some((f) => typeof f?.path === 'string' && owned.some((p) => f.path.startsWith(p)))) return true;
|
|
25
|
-
// Diff truncado sem o caminho não prova ausência — o archive pode estar além do teto.
|
|
26
|
-
if (files.length >= GH_FILES_CAP) return null;
|
|
27
|
-
return false;
|
|
28
|
-
} catch {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/lib/git/pr-index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'child_process';
|
|
2
|
-
import { resolveGh } from './gh.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Branch → PR. `--state all`: a MERGED PR is the evidence a squash-merge erases from git.
|
|
6
|
-
* `gh` lists newest-first, so the first entry per branch wins.
|
|
7
|
-
* @returns {Map<string,{number:number,state:string,mergedAt:string|null,url:string|null,createdAt:string|null}>|null}
|
|
8
|
-
* null = unknown, NEVER "no PR": destructive callers act only on a positive fact.
|
|
9
|
-
*/
|
|
10
|
-
export function buildPrIndex(root, opts = {}) {
|
|
11
|
-
const limit = String(opts.limit ?? 200);
|
|
12
|
-
const timeout = opts.timeout ?? 8000;
|
|
13
|
-
try {
|
|
14
|
-
const url = execFileSync('git', ['remote', 'get-url', 'origin'], { cwd: root, stdio: 'pipe' }).toString();
|
|
15
|
-
if (!/github\.com/i.test(url)) return null;
|
|
16
|
-
const { bin, prefix } = resolveGh();
|
|
17
|
-
const out = execFileSync(
|
|
18
|
-
bin,
|
|
19
|
-
[...prefix, 'pr', 'list', '--state', 'all', '--limit', limit,
|
|
20
|
-
'--json', 'number,state,headRefName,mergedAt,url,createdAt'],
|
|
21
|
-
{ cwd: root, stdio: 'pipe', timeout },
|
|
22
|
-
).toString();
|
|
23
|
-
const map = new Map();
|
|
24
|
-
for (const pr of JSON.parse(out)) {
|
|
25
|
-
if (pr?.headRefName && !map.has(pr.headRefName)) {
|
|
26
|
-
map.set(pr.headRefName, {
|
|
27
|
-
number: pr.number,
|
|
28
|
-
state: pr.state,
|
|
29
|
-
mergedAt: pr.mergedAt ?? null,
|
|
30
|
-
url: pr.url ?? null,
|
|
31
|
-
createdAt: pr.createdAt ?? null,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return map;
|
|
36
|
-
} catch {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// `.morph/` stays out except `config.json` minus `expectedCount`, as in `treeMovedSince`:
|
|
2
|
-
// committing verify's own bookkeeping must not make the same code look different.
|
|
3
|
-
|
|
4
|
-
import { execFileSync } from 'child_process';
|
|
5
|
-
import { createHash } from 'crypto';
|
|
6
|
-
import { existsSync, readFileSync, statSync } from 'fs';
|
|
7
|
-
import { join } from 'path';
|
|
8
|
-
import { withoutBaseline } from './evidence-staleness.js';
|
|
9
|
-
|
|
10
|
-
export const OUTSIDE_MORPH = ['--', '.', ':(exclude).morph'];
|
|
11
|
-
const MAX_OUTPUT = 64 * 1024 * 1024;
|
|
12
|
-
|
|
13
|
-
export function git(projectPath, args, input) {
|
|
14
|
-
return execFileSync('git', args, {
|
|
15
|
-
cwd: projectPath, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'ignore'], maxBuffer: MAX_OUTPUT, input,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** @returns {string|null} sha256 hex, or null outside a git repo / on any git error */
|
|
20
|
-
export function treeFingerprint(projectPath) {
|
|
21
|
-
try {
|
|
22
|
-
const hash = createHash('sha256');
|
|
23
|
-
let head = null;
|
|
24
|
-
try { head = git(projectPath, ['rev-parse', 'HEAD']).toString().trim(); } catch { /* no commit yet */ }
|
|
25
|
-
const tree = head
|
|
26
|
-
? git(projectPath, ['ls-tree', '-z', 'HEAD']).toString().split('\0').filter((e) => e && e.split('\t')[1] !== '.morph')
|
|
27
|
-
: ['no-commit'];
|
|
28
|
-
hash.update(`tree\0${tree.join('\0')}\0`);
|
|
29
|
-
if (head) hash.update(git(projectPath, ['diff', 'HEAD', '--binary', ...OUTSIDE_MORPH]));
|
|
30
|
-
hash.update('\0untracked\0');
|
|
31
|
-
const untracked = git(projectPath, ['ls-files', '--others', '--exclude-standard', '-z', ...OUTSIDE_MORPH])
|
|
32
|
-
.toString().split('\0').filter(Boolean).sort();
|
|
33
|
-
for (const rel of untracked) {
|
|
34
|
-
// Size and mtime stand in for content: hashing every untracked file of
|
|
35
|
-
// a large tree would cost more than the run the warning tries to save.
|
|
36
|
-
let stamp = 'gone';
|
|
37
|
-
try {
|
|
38
|
-
const st = statSync(join(projectPath, rel));
|
|
39
|
-
stamp = `${st.size}\0${st.mtimeMs}`;
|
|
40
|
-
} catch { /* deleted since the listing */ }
|
|
41
|
-
hash.update(`${rel}\0${stamp}\0`);
|
|
42
|
-
}
|
|
43
|
-
const config = join(projectPath, '.morph', 'config', 'config.json');
|
|
44
|
-
hash.update('\0config\0');
|
|
45
|
-
if (existsSync(config)) hash.update(normalizedConfig(readFileSync(config, 'utf8')));
|
|
46
|
-
return hash.digest('hex');
|
|
47
|
-
} catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function normalizedConfig(text) {
|
|
53
|
-
try {
|
|
54
|
-
return JSON.stringify(withoutBaseline(text));
|
|
55
|
-
} catch {
|
|
56
|
-
return text;
|
|
57
|
-
}
|
|
58
|
-
}
|