@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,249 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { readFileSync, existsSync, readdirSync } from 'fs';
|
|
4
|
-
import { dirname, join, resolve } from 'path';
|
|
5
|
-
import { execSync } from 'child_process';
|
|
6
|
-
import { stateExists, getActiveFeature, getFeaturePhase } from '../../shared/state-reader.js';
|
|
7
|
-
import { implementProgress, ownerRef } from '../../shared/report-progress.js';
|
|
8
|
-
import { collectNextSignals, decideNext, retratoOf, SESSION_MARK } from '../../shared/next-step.js';
|
|
9
|
-
import { featureRef, TESTS } from '../../shared/owner-words.js';
|
|
10
|
-
import { contextResult, runStandalone } from '../../shared/hook-response.js';
|
|
11
|
-
import { acquireClaim, foreignClaim, claimAge } from '../../shared/claim-registry.js';
|
|
12
|
-
import { rotateEventsLogIfLarge } from '../../shared/telemetry-logger.js';
|
|
13
|
-
import { kickGraphRefresh, seedFromPrimary } from '../../shared/graph-refresh.js';
|
|
14
|
-
import { isInContainer } from '../../shared/worktree-root.js';
|
|
15
|
-
import { isSecondaryWorktree, resolveGitCommonDir } from '../../shared/git-paths.js';
|
|
16
|
-
|
|
17
|
-
function projectDir() {
|
|
18
|
-
return process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const samePath = (a, b) => (process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
22
|
-
|
|
23
|
-
// Inside a worktree Claude Code keeps CLAUDE_PROJECT_DIR at the project root and moves only the payload `cwd`.
|
|
24
|
-
function sessionDir(payload) {
|
|
25
|
-
const base = projectDir();
|
|
26
|
-
const cwd = typeof payload?.cwd === 'string' ? payload.cwd : '';
|
|
27
|
-
if (!cwd || samePath(resolve(cwd), resolve(base))) return base;
|
|
28
|
-
try {
|
|
29
|
-
const common = resolveGitCommonDir(cwd);
|
|
30
|
-
return common && samePath(resolve(common), resolve(resolveGitCommonDir(base) ?? '')) && isSecondaryWorktree(cwd) ? cwd : base;
|
|
31
|
-
} catch {
|
|
32
|
-
return base;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function gitRevParse(arg, dir) {
|
|
37
|
-
return execSync(`git rev-parse ${arg}`, { cwd: dir, stdio: ['pipe', 'pipe', 'pipe'] })
|
|
38
|
-
.toString()
|
|
39
|
-
.trim();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function featureFromBranch(dir) {
|
|
43
|
-
try {
|
|
44
|
-
const branch = gitRevParse('--abbrev-ref HEAD', dir);
|
|
45
|
-
const match = branch.match(/^morph\/(.+)$/);
|
|
46
|
-
return match ? match[1] : null;
|
|
47
|
-
} catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function taskFromBranch(dir) {
|
|
53
|
-
try {
|
|
54
|
-
const branch = gitRevParse('--abbrev-ref HEAD', dir);
|
|
55
|
-
const match = branch.match(/^morph-task\/(.+)$/);
|
|
56
|
-
return match ? match[1] : null;
|
|
57
|
-
} catch {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Any error reads as "in container" so a healthy tree is never nagged.
|
|
63
|
-
function isOutsideContainer(dir) {
|
|
64
|
-
try {
|
|
65
|
-
const common = resolve(dir, gitRevParse('--git-common-dir', dir)).replace(/\\/g, '/');
|
|
66
|
-
const root = common.replace(/\/\.git$/, '');
|
|
67
|
-
return !isInContainer(root, dir);
|
|
68
|
-
} catch {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function buildOutOfContainerWarning(dir) {
|
|
74
|
-
return '⚠ Este worktree está FORA do container do morph (worktrees/): foi criado sem o morph-spec — ' +
|
|
75
|
-
'sem junctions de infra, sem bloco de portas, invisível ao `fleet`. ' +
|
|
76
|
-
'Integre a branch e remova com `morph-spec worktree remove --target "<path>"`; ' +
|
|
77
|
-
'crie worktrees por `morph-spec worktree setup <f>` ou `worktree provision <n>` (o hook WorktreeCreate faz isso sozinho). ' +
|
|
78
|
-
'Diagnóstico: `morph-spec doctor --worktrees`.';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function buildTaskContext(dir, task) {
|
|
82
|
-
let text = `🧩 Worktree de isolamento de task: ${task} (branch morph-task/${task}). ` +
|
|
83
|
-
'Não é uma feature: trabalhe só na task despachada, commite na branch como último ato e NUNCA faça merge — ' +
|
|
84
|
-
'o orquestrador integra e remove este worktree.';
|
|
85
|
-
const envLine = buildEnvLine(dir);
|
|
86
|
-
if (envLine) text += `\n${envLine}`;
|
|
87
|
-
text += buildMissingInfraWarning(dir);
|
|
88
|
-
return text;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function featureFromSingleDir(dir) {
|
|
92
|
-
try {
|
|
93
|
-
const entries = readdirSync(join(dir, '.morph', 'features'), { withFileTypes: true })
|
|
94
|
-
.filter((e) => e.isDirectory());
|
|
95
|
-
return entries.length === 1 ? entries[0].name : null;
|
|
96
|
-
} catch {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function buildEnvLine(dir) {
|
|
102
|
-
try {
|
|
103
|
-
const envPath = join(dir, '.morph', 'worktree.env');
|
|
104
|
-
if (!existsSync(envPath)) return null;
|
|
105
|
-
const content = readFileSync(envPath, 'utf8');
|
|
106
|
-
const port = content.match(/^PORT=(\d+)$/m)?.[1];
|
|
107
|
-
if (!port) return null;
|
|
108
|
-
const range = content.match(/^MORPH_PORT_RANGE=([\d-]+)$/m)?.[1];
|
|
109
|
-
const pg = content.match(/^POSTGRES_PORT=(\d+)$/m)?.[1];
|
|
110
|
-
const project = content.match(/^COMPOSE_PROJECT_NAME=(\S+)$/m)?.[1];
|
|
111
|
-
const extras = [pg ? `POSTGRES_PORT=${pg}` : null, project ? `COMPOSE_PROJECT_NAME=${project}` : null].filter(Boolean);
|
|
112
|
-
return `🔌 Ambiente desta worktree: PORT=${port}${range ? ` (bloco ${range})` : ''}${extras.length ? `, ${extras.join(', ')}` : ''}. ` +
|
|
113
|
-
'Suba dev servers SEMPRE nessas portas (fonte: .morph/worktree.env; o hook PreToolUse injeta em npm run dev/dotnet run/docker compose) — as portas padrão pertencem à raiz.';
|
|
114
|
-
} catch {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function signalsFor(dir, slug, fallbackFeature) {
|
|
120
|
-
let signals = null;
|
|
121
|
-
try { signals = collectNextSignals(slug, dir); } catch {}
|
|
122
|
-
if (signals) return { signals, ownSignals: true };
|
|
123
|
-
const featureDir = join(dir, '.morph', 'features', slug);
|
|
124
|
-
return {
|
|
125
|
-
ownSignals: false,
|
|
126
|
-
signals: {
|
|
127
|
-
feature: slug, featureJson: fallbackFeature ?? null, progress: implementProgress(featureDir),
|
|
128
|
-
phase: getFeaturePhase(slug, dir), hasDesign: existsSync(join(featureDir, '1-design')),
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// No git here, so verify staleness is unknown: an escalation the tree already moved past, or the
|
|
134
|
-
// root skeleton of a feature living in a worktree, would be an order read from stale facts.
|
|
135
|
-
function featureBlock(dir, slug, fallbackFeature) {
|
|
136
|
-
const { signals, ownSignals } = signalsFor(dir, slug, fallbackFeature);
|
|
137
|
-
const ref = featureRef(slug, signals.featureJson, signals.progress?.summary);
|
|
138
|
-
if (signals.worktreePath && !samePath(resolve(signals.worktreePath), resolve(dir))) {
|
|
139
|
-
return {
|
|
140
|
-
ref,
|
|
141
|
-
lines: [
|
|
142
|
-
`Esta funcionalidade está sendo construída em outro worktree (${signals.worktreePath}): abra a sessão lá; `
|
|
143
|
-
+ 'aqui é só o esqueleto de quando ela nasceu.',
|
|
144
|
-
],
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
let next = null;
|
|
148
|
-
try { next = ownSignals ? decideNext(signals) : null; } catch {}
|
|
149
|
-
const escalate = next?.action === 'escalate';
|
|
150
|
-
const lines = retratoOf(signals, escalate ? null : next).slice(1);
|
|
151
|
-
if (escalate) lines.push(`${SESSION_MARK} ${TESTS} falharam de novo: leia \`morph-spec next ${slug} --json\` de ${ref} antes de agir.`);
|
|
152
|
-
else if (next) lines.push(`${SESSION_MARK} o passo exato (ação, comando e how) está em \`morph-spec next ${slug} --json\` de ${ref}; releia depois de mudar a árvore.`);
|
|
153
|
-
return { ref, lines };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function buildWorktreeContext(dir, feature) {
|
|
157
|
-
const { ref, lines } = featureBlock(dir, feature);
|
|
158
|
-
let text = `🌳 Worktree desta funcionalidade: ${ref} (branch morph/${feature}). ` +
|
|
159
|
-
`Trabalhe só nela nesta sessão; o estado vive no .morph/ deste worktree.`;
|
|
160
|
-
if (lines.length) text += `\n${lines.join('\n')}`;
|
|
161
|
-
|
|
162
|
-
const envLine = buildEnvLine(dir);
|
|
163
|
-
if (envLine) text += `\n${envLine}`;
|
|
164
|
-
|
|
165
|
-
text += buildMissingInfraWarning(dir);
|
|
166
|
-
return text;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// The hook commands resolve through the .morph/framework junction: without it every guardrail here is silently off.
|
|
170
|
-
function buildMissingInfraWarning(dir) {
|
|
171
|
-
// node_modules is linked only where the primary root has one (a .NET or monorepo root has none).
|
|
172
|
-
const common = resolveGitCommonDir(dir);
|
|
173
|
-
const root = common ? dirname(common) : null;
|
|
174
|
-
const missing = ['node_modules', '.claude', join('.morph', 'framework')]
|
|
175
|
-
.filter((rel) => rel !== 'node_modules' || !root || existsSync(join(root, rel)))
|
|
176
|
-
.filter((rel) => !existsSync(join(dir, rel)));
|
|
177
|
-
if (!missing.length) return '';
|
|
178
|
-
let text = `\n⚠ Infra compartilhada ausente (${missing.join(', ').replace(/\\/g, '/')}). Rode: morph-spec worktree link --all`;
|
|
179
|
-
if (missing.includes(join('.morph', 'framework'))) {
|
|
180
|
-
text += `\n Sem .morph/framework os hooks do morph-spec NÃO executam neste worktree (nenhum guardrail ativo).`;
|
|
181
|
-
}
|
|
182
|
-
return text;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function buildActiveFeatureSummary(dir) {
|
|
186
|
-
const active = getActiveFeature(dir);
|
|
187
|
-
if (!active) return null;
|
|
188
|
-
|
|
189
|
-
const { ref, lines } = featureBlock(dir, active.name, active.feature);
|
|
190
|
-
return [`MORPH-SPEC: em andamento — ${ref}`, ...lines].join('\n');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Advisory: the claim is taken even on collision; it warns, never locks.
|
|
194
|
-
function claimBlock(dir, feature, sessionId) {
|
|
195
|
-
try {
|
|
196
|
-
const gitCommonDir = resolve(dir, gitRevParse('--git-common-dir', dir));
|
|
197
|
-
const other = foreignClaim(feature, { gitCommonDir, sessionId });
|
|
198
|
-
acquireClaim(feature, { gitCommonDir, sessionId, pid: process.pid, path: dir });
|
|
199
|
-
if (!other) return '';
|
|
200
|
-
return `\n⚠️ ATENÇÃO: outra sessão está trabalhando agora nesta mesma funcionalidade: ${ownerRef(dir, feature, null)}`
|
|
201
|
-
+ `\n processo ${other.pid}${other.path ? ` · ${other.path}` : ''} · visto há ${claimAge(other)}`
|
|
202
|
-
+ '\n Duas sessões na mesma funcionalidade apagam o trabalho uma da outra.'
|
|
203
|
-
+ '\n Confirme com quem está na outra sessão antes de continuar, principalmente antes de entregar, arquivar ou apagar.'
|
|
204
|
-
+ `\n${SESSION_MARK} claim vivo de outra sessão; confirme antes de \`finish\`, \`archive\` ou \`delete\`. `
|
|
205
|
-
+ `Se aquela sessão morreu: \`morph-spec claim ${feature} --release\` de ${ownerRef(dir, feature, null)}.`;
|
|
206
|
-
} catch {
|
|
207
|
-
return '';
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export async function run(payload) {
|
|
212
|
-
try {
|
|
213
|
-
const dir = sessionDir(payload);
|
|
214
|
-
const sessionId = payload?.session_id || `pid-${process.pid}`;
|
|
215
|
-
|
|
216
|
-
if (!stateExists(dir)) {
|
|
217
|
-
return null;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
try { rotateEventsLogIfLarge(dir); } catch {}
|
|
221
|
-
// Only the ROOT's graph is refreshed in background: a detached process holding a worktree directory made `finish` fail on win32.
|
|
222
|
-
try { seedFromPrimary(dir); } catch {}
|
|
223
|
-
try { kickGraphRefresh(dir); } catch {}
|
|
224
|
-
|
|
225
|
-
if (isSecondaryWorktree(dir)) {
|
|
226
|
-
const task = taskFromBranch(dir);
|
|
227
|
-
if (task) {
|
|
228
|
-
return contextResult(buildTaskContext(dir, task), 'SessionStart');
|
|
229
|
-
}
|
|
230
|
-
const feature = featureFromBranch(dir) || featureFromSingleDir(dir);
|
|
231
|
-
if (!feature) {
|
|
232
|
-
// No identity AND outside the container is the signature of a worktree created behind morph's back.
|
|
233
|
-
return isOutsideContainer(dir) ? contextResult(buildOutOfContainerWarning(dir), 'SessionStart') : null;
|
|
234
|
-
}
|
|
235
|
-
return contextResult(buildWorktreeContext(dir, feature) + claimBlock(dir, feature, sessionId), 'SessionStart');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const summary = buildActiveFeatureSummary(dir);
|
|
239
|
-
if (!summary) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
const active = getActiveFeature(dir);
|
|
243
|
-
return contextResult(summary + (active?.name ? claimBlock(dir, active.name, sessionId) : ''), 'SessionStart');
|
|
244
|
-
} catch {
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
await runStandalone(run);
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { existsSync, mkdirSync } from 'fs';
|
|
4
|
-
import { execFileSync } from 'child_process';
|
|
5
|
-
import { dirname, join, resolve } from 'path';
|
|
6
|
-
import { stateExists } from '../../shared/state-reader.js';
|
|
7
|
-
import { resolveGitCommonDir } from '../../shared/git-paths.js';
|
|
8
|
-
import { runMorphSpec } from '../../shared/morph-cli.js';
|
|
9
|
-
import { newWorktreesDir } from '../../shared/worktree-root.js';
|
|
10
|
-
|
|
11
|
-
const fwd = (p) => String(p).replace(/\\/g, '/');
|
|
12
|
-
|
|
13
|
-
function git(args, cwd) {
|
|
14
|
-
return execFileSync('git', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] }).toString().trim();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// `git worktree list`'s first entry is the primary checkout, from any worktree.
|
|
18
|
-
export function resolvePrimaryRoot(startDir) {
|
|
19
|
-
try {
|
|
20
|
-
const first = git(['worktree', 'list', '--porcelain'], startDir).split('\n').find((l) => l.startsWith('worktree '));
|
|
21
|
-
if (first) return fwd(first.slice('worktree '.length).trim());
|
|
22
|
-
} catch {}
|
|
23
|
-
const common = resolveGitCommonDir(startDir);
|
|
24
|
-
return common ? fwd(dirname(common)) : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function slugify(name) {
|
|
28
|
-
const slug = String(name || '')
|
|
29
|
-
.toLowerCase()
|
|
30
|
-
.replace(/[^a-z0-9-]+/g, '-')
|
|
31
|
-
.replace(/-{2,}/g, '-')
|
|
32
|
-
.replace(/^-+|-+$/g, '');
|
|
33
|
-
return slug || `wt-${Date.now().toString(36)}`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function isKnownFeature(root, name) {
|
|
37
|
-
if (existsSync(join(root, '.morph', 'features', name, 'feature.json'))) return true;
|
|
38
|
-
try {
|
|
39
|
-
git(['show-ref', '--verify', '--quiet', `refs/heads/morph/${name}`], root);
|
|
40
|
-
return true;
|
|
41
|
-
} catch {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function defaultBranch(root) {
|
|
47
|
-
try {
|
|
48
|
-
const m = git(['symbolic-ref', '--quiet', 'refs/remotes/origin/HEAD'], root).match(/^refs\/remotes\/origin\/(.+)$/);
|
|
49
|
-
if (m) return m[1];
|
|
50
|
-
} catch {}
|
|
51
|
-
for (const c of ['main', 'master']) {
|
|
52
|
-
try { git(['show-ref', '--verify', '--quiet', `refs/heads/${c}`], root); return c; } catch {}
|
|
53
|
-
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function gitFallback(root, name) {
|
|
58
|
-
const branch = `morph-task/${name}`;
|
|
59
|
-
const container = newWorktreesDir(root);
|
|
60
|
-
const path = `${container}/${name}`;
|
|
61
|
-
if (existsSync(path)) return { path };
|
|
62
|
-
try { git(['show-ref', '--verify', '--quiet', `refs/heads/${branch}`], root); }
|
|
63
|
-
catch {
|
|
64
|
-
const from = defaultBranch(root);
|
|
65
|
-
git(from ? ['branch', branch, from] : ['branch', branch], root);
|
|
66
|
-
}
|
|
67
|
-
mkdirSync(container, { recursive: true });
|
|
68
|
-
git(['worktree', 'add', path, branch], root);
|
|
69
|
-
return { path };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export async function run(payload) {
|
|
73
|
-
const start = payload?.cwd || process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
74
|
-
const root = resolvePrimaryRoot(start) || (process.env.CLAUDE_PROJECT_DIR ? fwd(resolve(process.env.CLAUDE_PROJECT_DIR)) : null);
|
|
75
|
-
if (!root) return { error: `worktree-create: "${start}" is not inside a git repository` };
|
|
76
|
-
|
|
77
|
-
const name = slugify(payload?.name);
|
|
78
|
-
|
|
79
|
-
if (!stateExists(root)) {
|
|
80
|
-
try { return gitFallback(root, name); }
|
|
81
|
-
catch (err) { return { error: `worktree-create: ${err?.message || err}` }; }
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const args = isKnownFeature(root, name)
|
|
85
|
-
? ['worktree', 'setup', name, '--json']
|
|
86
|
-
: ['worktree', 'provision', name, '--json'];
|
|
87
|
-
|
|
88
|
-
const r = runMorphSpec(args, { cwd: root });
|
|
89
|
-
if (r.unavailable) {
|
|
90
|
-
process.stderr.write('worktree-create: morph-spec CLI not found — creating the tree with plain git under worktrees/ (no infra links, no port block). Run `morph-spec worktree link --all` inside it.\n');
|
|
91
|
-
try { return gitFallback(root, name); }
|
|
92
|
-
catch (err) { return { error: `worktree-create: ${err?.message || err}` }; }
|
|
93
|
-
}
|
|
94
|
-
if (r.stderr?.trim()) process.stderr.write(r.stderr);
|
|
95
|
-
|
|
96
|
-
const ok = r.code === 0 || r.code === 2;
|
|
97
|
-
const path = r.json?.path;
|
|
98
|
-
if (ok && path && !r.json?.error) return { path: fwd(path) };
|
|
99
|
-
const why = r.json?.error || r.json?.hint || r.stderr?.trim() || `exit ${r.code}`;
|
|
100
|
-
return { error: `worktree-create: morph-spec ${args.slice(0, 2).join(' ')} ${name} failed — ${why}` };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Standalone tail — NOT runStandalone(): this event's contract is "path on
|
|
104
|
-
// stdout, exit 0" / "non-zero exit", never a JSON verdict.
|
|
105
|
-
if (!process.env.MORPH_HOOK_CHAINED) {
|
|
106
|
-
const { readStdin } = await import('../../shared/stdin-reader.js');
|
|
107
|
-
let result;
|
|
108
|
-
try {
|
|
109
|
-
result = await run(await readStdin());
|
|
110
|
-
} catch (err) {
|
|
111
|
-
result = { error: `worktree-create: ${err?.message || err}` };
|
|
112
|
-
}
|
|
113
|
-
if (result?.path) {
|
|
114
|
-
process.stdout.write(`${result.path}\n`);
|
|
115
|
-
process.exit(0);
|
|
116
|
-
}
|
|
117
|
-
process.stderr.write(`${result?.error || 'worktree-create: no path produced'}\n`);
|
|
118
|
-
process.exit(1);
|
|
119
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Launchers get the worktree's port block exported; teardowns get the session anchor, because the CLI cannot see
|
|
3
|
-
// CLAUDE_PROJECT_DIR and tearing down the worktree a session is anchored in kills every later hook (MODULE_NOT_FOUND).
|
|
4
|
-
|
|
5
|
-
import { existsSync } from 'fs';
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
import { stateExists } from '../../shared/state-reader.js';
|
|
8
|
-
import { updatedInputResult, runStandalone } from '../../shared/hook-response.js';
|
|
9
|
-
import { loadEnvFile } from '../../shared/e2e-check.js';
|
|
10
|
-
|
|
11
|
-
const LAUNCHER_RE = /\b(?:(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start)\b|next\s+(?:dev|start)\b|vite\b|dotnet\s+(?:run|watch)\b|docker(?:\s+|-)compose\b|playwright\s+test\b)/;
|
|
12
|
-
|
|
13
|
-
const SELF_CONFIGURED_RE = /(?:^|[\s;&|])(?:PORT|API_PORT|POSTGRES_PORT|COMPOSE_PROJECT_NAME|ASPNETCORE_URLS)=|--port\b|(?:^|\s)-p\s+\d|compose\b[^|;&]*\s-p\s/;
|
|
14
|
-
|
|
15
|
-
// POSIX single quote, safe for Git Bash on Windows too.
|
|
16
|
-
function shq(v) {
|
|
17
|
-
return `'${String(v).replace(/'/g, "'\\''")}'`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function rewriteCommand(command, env) {
|
|
21
|
-
if (!command || !LAUNCHER_RE.test(command)) return null;
|
|
22
|
-
if (SELF_CONFIGURED_RE.test(command)) return null;
|
|
23
|
-
const pairs = Object.keys(env).filter((k) => k !== 'MORPH_FEATURE' && env[k]).map((k) => [k, env[k]]);
|
|
24
|
-
if (!pairs.some(([k]) => k === 'PORT')) return null;
|
|
25
|
-
if (!env.PLAYWRIGHT_BASE_URL) pairs.push(['PLAYWRIGHT_BASE_URL', `http://localhost:${env.PORT}`]);
|
|
26
|
-
const prefix = `export ${pairs.map(([k, v]) => `${k}=${shq(v)}`).join(' ')}; `;
|
|
27
|
-
return { command: prefix + command, injected: pairs.map(([k, v]) => `${k}=${v}`) };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Also matches `node …/morph-spec.js` and `npx morph-spec`.
|
|
31
|
-
const TEARDOWN_RE = /\bmorph-spec(?:\.js)?\b[^\n;&|]*?\s(?:finish|worktree\s+remove)\b/;
|
|
32
|
-
|
|
33
|
-
const ANCHOR_KEY = 'MORPH_SESSION_PROJECT_DIR';
|
|
34
|
-
|
|
35
|
-
export function anchorSessionCommand(command, anchorDir) {
|
|
36
|
-
if (!command || !anchorDir) return null;
|
|
37
|
-
if (!TEARDOWN_RE.test(command)) return null;
|
|
38
|
-
if (new RegExp(`(?:^|[\\s;&|])${ANCHOR_KEY}=`).test(command)) return null;
|
|
39
|
-
return { command: `export ${ANCHOR_KEY}=${shq(anchorDir)}; ${command}`, anchor: anchorDir };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function run(payload) {
|
|
43
|
-
try {
|
|
44
|
-
if (payload?.tool_name && payload.tool_name !== 'Bash') return null;
|
|
45
|
-
if (!stateExists()) return null;
|
|
46
|
-
const command = payload?.tool_input?.command || '';
|
|
47
|
-
if (!command) return null;
|
|
48
|
-
|
|
49
|
-
// CLAUDE_PROJECT_DIR first: it is what the project hooks resolve `.morph/framework` against.
|
|
50
|
-
const anchored = anchorSessionCommand(command, process.env.CLAUDE_PROJECT_DIR || payload?.cwd || '');
|
|
51
|
-
if (anchored) {
|
|
52
|
-
return updatedInputResult({ ...payload.tool_input, command: anchored.command }, 'PreToolUse');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const dir = payload?.cwd || process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
56
|
-
const manifest = join(dir, '.morph', 'worktree.env');
|
|
57
|
-
if (!existsSync(manifest)) return null;
|
|
58
|
-
|
|
59
|
-
const rewritten = rewriteCommand(command, loadEnvFile(manifest));
|
|
60
|
-
if (!rewritten) return null;
|
|
61
|
-
|
|
62
|
-
return updatedInputResult({ ...payload.tool_input, command: rewritten.command }, 'PreToolUse');
|
|
63
|
-
} catch {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
await runStandalone(run);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Routes Claude Code's native removal (a raw `git worktree remove`, which follows the infra junctions out) through
|
|
3
|
-
// `morph-spec worktree remove --if-clean`. The event ignores output, so this hook always exits 0.
|
|
4
|
-
|
|
5
|
-
import { existsSync } from 'fs';
|
|
6
|
-
import { execFileSync } from 'child_process';
|
|
7
|
-
import { dirname, resolve } from 'path';
|
|
8
|
-
import { stateExists } from '../../shared/state-reader.js';
|
|
9
|
-
import { resolveGitCommonDir } from '../../shared/git-paths.js';
|
|
10
|
-
import { runMorphSpec } from '../../shared/morph-cli.js';
|
|
11
|
-
|
|
12
|
-
const fwd = (p) => String(p).replace(/\\/g, '/');
|
|
13
|
-
|
|
14
|
-
function primaryRoot(startDir) {
|
|
15
|
-
try {
|
|
16
|
-
const out = execFileSync('git', ['worktree', 'list', '--porcelain'], { cwd: startDir, stdio: ['ignore', 'pipe', 'pipe'] }).toString();
|
|
17
|
-
const first = out.split('\n').find((l) => l.startsWith('worktree '));
|
|
18
|
-
if (first) return fwd(first.slice('worktree '.length).trim());
|
|
19
|
-
} catch {}
|
|
20
|
-
const common = resolveGitCommonDir(startDir);
|
|
21
|
-
return common ? fwd(dirname(common)) : null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function run(payload) {
|
|
25
|
-
try {
|
|
26
|
-
const target = payload?.worktree_path;
|
|
27
|
-
if (!target || !existsSync(target)) return null;
|
|
28
|
-
|
|
29
|
-
const start = payload?.cwd || process.env.CLAUDE_PROJECT_DIR || dirname(resolve(target));
|
|
30
|
-
const root = primaryRoot(start) || primaryRoot(dirname(resolve(target)));
|
|
31
|
-
if (!root) return null;
|
|
32
|
-
// Never a raw removal from here: outside a morph project the tree is left for git's own cleanup.
|
|
33
|
-
if (!stateExists(root)) return null;
|
|
34
|
-
|
|
35
|
-
const r = runMorphSpec(['worktree', 'remove', '--target', fwd(resolve(target)), '--if-clean', '--json'], { cwd: root });
|
|
36
|
-
if (r.unavailable) {
|
|
37
|
-
process.stderr.write(`worktree-remove: morph-spec CLI not found — "${target}" left in place (remove it with \`morph-spec worktree remove --target\`, never with raw git: it follows the infra junctions out).\n`);
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
if (!r.ok) {
|
|
41
|
-
const why = r.json?.error || r.json?.hint || r.stderr?.trim() || `exit ${r.code}`;
|
|
42
|
-
process.stderr.write(`worktree-remove: "${target}" NOT removed — ${why}\n`);
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
} catch (err) {
|
|
46
|
-
process.stderr.write(`worktree-remove: ${err?.message || err}\n`);
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!process.env.MORPH_HOOK_CHAINED) {
|
|
52
|
-
const { readStdin } = await import('../../shared/stdin-reader.js');
|
|
53
|
-
try { await run(await readStdin()); } catch {}
|
|
54
|
-
process.exit(0);
|
|
55
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
|
|
5
|
-
const DOTNET_BUILD_CMD = 'dotnet build --no-restore --nologo -v q';
|
|
6
|
-
const TSC_BUILD_CMD = 'npx tsc --noEmit';
|
|
7
|
-
const ESLINT_CONFIGS = ['eslint.config.mjs', 'eslint.config.js', 'eslint.config.cjs'];
|
|
8
|
-
const LINT_BATCH_CHARS = 6000;
|
|
9
|
-
|
|
10
|
-
/** HTML que o projeto tem como componente do shadcn: cru, só dentro de `components/ui/`. */
|
|
11
|
-
export const RAW_ELEMENTS = ['button', 'input', 'textarea', 'select', 'table', 'dialog'];
|
|
12
|
-
const RAW_ELEMENTS_RULE = ` --rule "react/forbid-elements: [error, {forbid: [${RAW_ELEMENTS.join(', ')}]}]"`;
|
|
13
|
-
const SHADCN_UI_DIR_RE = /(^|[\\/])components[\\/]ui[\\/]/;
|
|
14
|
-
|
|
15
|
-
// A regra entra pela linha de comando: vale no projeto cujo `eslint.config` ainda não a declara.
|
|
16
|
-
// O plugin `react` vem do eslint-config-next; sem ele o eslint recusaria a regra.
|
|
17
|
-
function cobraElementoCru(frontendDir) {
|
|
18
|
-
return existsSync(join(frontendDir, 'components.json'))
|
|
19
|
-
&& existsSync(join(frontendDir, 'node_modules', 'eslint-config-next'));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function isDotnetStack(s) {
|
|
23
|
-
return s.includes('dotnet') || s.includes('aspnet');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isFrontendStack(s) {
|
|
27
|
-
return s.includes('nextjs') || s.includes('node') || s.includes('react') || s.includes('vue');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// A compound stack checks BOTH sides, each from its own directory.
|
|
31
|
-
// `backendTarget` names the solution when the backend directory holds none.
|
|
32
|
-
export function getBuildSteps(stack, { cwd, frontendPath, backendPath, backendTarget, lintFiles = [] } = {}) {
|
|
33
|
-
if (!stack || !cwd) return [];
|
|
34
|
-
const s = stack.toLowerCase();
|
|
35
|
-
const steps = [];
|
|
36
|
-
|
|
37
|
-
if (isDotnetStack(s)) {
|
|
38
|
-
const command = backendTarget ? DOTNET_BUILD_CMD.replace(/^dotnet build/, `dotnet build "${backendTarget}"`) : DOTNET_BUILD_CMD;
|
|
39
|
-
steps.push({ command, cwd: backendPath ? join(cwd, backendPath) : cwd });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (isFrontendStack(s)) {
|
|
43
|
-
const frontendDir = frontendPath ? join(cwd, frontendPath) : cwd;
|
|
44
|
-
// Without node_modules, `npx tsc` fetches an unrelated "tsc" package.
|
|
45
|
-
if (
|
|
46
|
-
existsSync(join(frontendDir, 'tsconfig.json')) &&
|
|
47
|
-
existsSync(join(frontendDir, 'node_modules'))
|
|
48
|
-
) {
|
|
49
|
-
steps.push({ command: TSC_BUILD_CMD, cwd: frontendDir });
|
|
50
|
-
}
|
|
51
|
-
// Only the files the feature touched: legacy lint debt never turns a feature's verify red.
|
|
52
|
-
if (
|
|
53
|
-
lintFiles.length > 0 &&
|
|
54
|
-
ESLINT_CONFIGS.some((name) => existsSync(join(frontendDir, name))) &&
|
|
55
|
-
existsSync(join(frontendDir, 'node_modules', 'eslint'))
|
|
56
|
-
) {
|
|
57
|
-
// cmd.exe caps a command line at 8191 chars: a wide diff is linted in batches.
|
|
58
|
-
const lint = (files, rule) => {
|
|
59
|
-
let batch = [];
|
|
60
|
-
let size = 0;
|
|
61
|
-
const flush = () => {
|
|
62
|
-
if (batch.length > 0) steps.push({ command: `npx eslint --quiet --no-warn-ignored${rule} ${batch.join(' ')}`, cwd: frontendDir });
|
|
63
|
-
batch = [];
|
|
64
|
-
size = 0;
|
|
65
|
-
};
|
|
66
|
-
for (const file of files.map((f) => JSON.stringify(f))) {
|
|
67
|
-
if (size + file.length + 1 > LINT_BATCH_CHARS) flush();
|
|
68
|
-
batch.push(file);
|
|
69
|
-
size += file.length + 1;
|
|
70
|
-
}
|
|
71
|
-
flush();
|
|
72
|
-
};
|
|
73
|
-
if (cobraElementoCru(frontendDir)) {
|
|
74
|
-
lint(lintFiles.filter((f) => !SHADCN_UI_DIR_RE.test(f)), RAW_ELEMENTS_RULE);
|
|
75
|
-
lint(lintFiles.filter((f) => SHADCN_UI_DIR_RE.test(f)), '');
|
|
76
|
-
} else {
|
|
77
|
-
lint(lintFiles, '');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return steps;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function parseBuildResult(exitCode, output) {
|
|
86
|
-
const trimmed = (output || '').trim();
|
|
87
|
-
if (exitCode === 0) {
|
|
88
|
-
return { status: 'pass', output: '' };
|
|
89
|
-
}
|
|
90
|
-
const lines = trimmed.split('\n');
|
|
91
|
-
const truncated = lines.slice(-20).join('\n');
|
|
92
|
-
return { status: 'fail', output: truncated };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** @returns {{ status: 'pass'|'fail'|'skip', output: string }} */
|
|
96
|
-
export function runBuildCheck(cwd, stack, timeout = 30000, paths = {}) {
|
|
97
|
-
const steps = getBuildSteps(stack, { cwd, frontendPath: paths.frontendPath, backendPath: paths.backendPath, backendTarget: paths.backendTarget, lintFiles: paths.lintFiles });
|
|
98
|
-
if (steps.length === 0) return { status: 'skip', output: '' };
|
|
99
|
-
|
|
100
|
-
const failures = [];
|
|
101
|
-
for (const step of steps) {
|
|
102
|
-
try {
|
|
103
|
-
execSync(step.command, {
|
|
104
|
-
cwd: step.cwd,
|
|
105
|
-
encoding: 'utf-8',
|
|
106
|
-
timeout,
|
|
107
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
108
|
-
});
|
|
109
|
-
} catch (err) {
|
|
110
|
-
const output = (err.stdout || '') + (err.stderr || '');
|
|
111
|
-
const parsed = parseBuildResult(err.status || 1, output);
|
|
112
|
-
failures.push(`[${step.command}] ${parsed.output}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (failures.length > 0) {
|
|
117
|
-
return { status: 'fail', output: failures.join('\n\n') };
|
|
118
|
-
}
|
|
119
|
-
return { status: 'pass', output: '' };
|
|
120
|
-
}
|