@polymorphism-tech/morph-spec 10.12.1 → 11.1.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 +53 -338
- 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 +12 -9
- 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 +15 -13
- package/framework/rules/resend-standards.md +1 -1
- package/framework/rules/ui-design.md +5 -1
- 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 +13 -342
- 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 +16 -53
- 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 +13 -37
- package/src/utils/atomic-json.js +27 -0
- package/src/utils/file-copier.js +24 -24
- 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,214 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { existsSync } from 'fs';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
import { loadState, stateExists } from '../../shared/state-reader.js';
|
|
6
|
-
import { persistFeature, setGateApproved, createDefaultFeature, readFeatureFile } from '../../shared/state-writer.js';
|
|
7
|
-
import { resolveMorphRoot } from '../../shared/payload-utils.js';
|
|
8
|
-
import { contextResult, runStandalone } from '../../shared/hook-response.js';
|
|
9
|
-
import { gateFromQuestion } from '../../shared/gate-question.js';
|
|
10
|
-
import { GATE_NAME } from '../../shared/owner-words.js';
|
|
11
|
-
import { SESSION_MARK } from '../../shared/next-step.js';
|
|
12
|
-
import { ownerRef } from '../../shared/report-progress.js';
|
|
13
|
-
import {
|
|
14
|
-
locateFeatureForQuestion,
|
|
15
|
-
allWorkTrees,
|
|
16
|
-
featureNamesIn,
|
|
17
|
-
unrecognizedSlugLike,
|
|
18
|
-
} from '../../shared/feature-locator.js';
|
|
19
|
-
|
|
20
|
-
const PHASE_FOLDERS = {
|
|
21
|
-
'1-design': 'design',
|
|
22
|
-
'1-ui': 'uiux', // legacy alias
|
|
23
|
-
'2-plan': 'plan',
|
|
24
|
-
'3-implement': 'implement',
|
|
25
|
-
'4-review': 'review',
|
|
26
|
-
'5-implement': 'implement', // legacy alias
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function projectDir() {
|
|
30
|
-
return process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function extractFeatureName(filePath) {
|
|
34
|
-
if (!filePath) return null;
|
|
35
|
-
const normalized = String(filePath).replace(/\\/g, '/');
|
|
36
|
-
const match = normalized.match(/\.morph\/features\/([^/]+)\//);
|
|
37
|
-
return match ? match[1] : null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function extractPhaseFolder(filePath) {
|
|
41
|
-
if (!filePath) return null;
|
|
42
|
-
const normalized = String(filePath).replace(/\\/g, '/');
|
|
43
|
-
const match = normalized.match(/\.morph\/features\/[^/]+\/([^/]+)\//);
|
|
44
|
-
if (!match) return null;
|
|
45
|
-
return PHASE_FOLDERS[match[1]] ?? null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function extractFilename(filePath) {
|
|
49
|
-
const normalized = String(filePath).replace(/\\/g, '/');
|
|
50
|
-
return normalized.split('/').pop();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function registerFeatureIfMissing(state, featureName) {
|
|
54
|
-
if (!state.features) state.features = {};
|
|
55
|
-
if (state.features[featureName]) return false;
|
|
56
|
-
|
|
57
|
-
state.features[featureName] = createDefaultFeature(featureName);
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function trackOutput(state, featureName, filePath) {
|
|
62
|
-
const filename = extractFilename(filePath);
|
|
63
|
-
const feature = state.features[featureName];
|
|
64
|
-
if (!feature) return false;
|
|
65
|
-
feature.outputs ??= {};
|
|
66
|
-
const normalizedPath = String(filePath).replace(/\\/g, '/');
|
|
67
|
-
const wasMissing = !feature.outputs[filename]?.created;
|
|
68
|
-
feature.outputs[filename] = {
|
|
69
|
-
created: true,
|
|
70
|
-
path: normalizedPath,
|
|
71
|
-
};
|
|
72
|
-
feature.updatedAt = new Date().toISOString();
|
|
73
|
-
return wasMissing;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const gateName = (g) => GATE_NAME[g] ?? g;
|
|
77
|
-
|
|
78
|
-
function isApprovalAnswer(answer) {
|
|
79
|
-
if (typeof answer !== 'string') return false;
|
|
80
|
-
const lower = answer.toLowerCase();
|
|
81
|
-
return (
|
|
82
|
-
lower.startsWith('aprovado') ||
|
|
83
|
-
lower.includes('pode avan') ||
|
|
84
|
-
lower.includes('pode implementar') ||
|
|
85
|
-
lower.includes('pode prosseguir')
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Mirror of src/core/state/gate-order.js: hooks are installed standalone and cannot import src/.
|
|
90
|
-
const GATE_PREREQ = { plan: [], uiux: ['plan'], review: ['plan'] };
|
|
91
|
-
function unmetGatePrereqs(gate, gates) {
|
|
92
|
-
const isApproved = (g) => gates?.[g]?.approved === true || gates?.[g] === true;
|
|
93
|
-
return (GATE_PREREQ[gate] || []).filter((p) => !isApproved(p));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function handleWriteEdit(input, sessionRoot) {
|
|
97
|
-
const filePath = input.tool_input?.file_path;
|
|
98
|
-
const featureName = extractFeatureName(filePath);
|
|
99
|
-
if (!featureName) return false;
|
|
100
|
-
|
|
101
|
-
// Sync the tree that OWNS the written file: a root session also writes into worktrees.
|
|
102
|
-
const cwd = resolveMorphRoot(filePath, sessionRoot);
|
|
103
|
-
if (!stateExists(cwd)) return false;
|
|
104
|
-
|
|
105
|
-
const state = loadState(cwd);
|
|
106
|
-
if (!state) return false;
|
|
107
|
-
|
|
108
|
-
let changed = registerFeatureIfMissing(state, featureName);
|
|
109
|
-
const phase = extractPhaseFolder(filePath);
|
|
110
|
-
if (phase) {
|
|
111
|
-
const outputChanged = trackOutput(state, featureName, filePath);
|
|
112
|
-
changed = changed || outputChanged;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (changed) {
|
|
116
|
-
persistFeature(featureName, state.features[featureName], cwd);
|
|
117
|
-
}
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function handleAskUserQuestion(input, sessionRoot) {
|
|
122
|
-
const answers = input.tool_response?.answers ?? input.tool_response?.responses ?? {};
|
|
123
|
-
if (typeof answers !== 'object' || answers === null) return null;
|
|
124
|
-
|
|
125
|
-
const warnings = [];
|
|
126
|
-
for (const [question, answer] of Object.entries(answers)) {
|
|
127
|
-
if (!isApprovalAnswer(answer)) continue;
|
|
128
|
-
const gate = gateFromQuestion(question);
|
|
129
|
-
if (!gate) continue;
|
|
130
|
-
|
|
131
|
-
// The feature the QUESTION names, in the tree that owns it — never the session tree's first in-progress feature.
|
|
132
|
-
const located = locateFeatureForQuestion(question, sessionRoot);
|
|
133
|
-
if (!located) {
|
|
134
|
-
// Refuse to guess: a gate on the wrong feature inverts gate order. For an unregistered slug
|
|
135
|
-
// `approve` is a dead end ("Feature not found"), so the remediation names `create`.
|
|
136
|
-
const allNames = allWorkTrees(sessionRoot).flatMap((r) => featureNamesIn(r));
|
|
137
|
-
const candidate = unrecognizedSlugLike(question, allNames);
|
|
138
|
-
const remediation = candidate
|
|
139
|
-
? `"${candidate}" não está registrada em nenhuma árvore conhecida; se é nova, ` +
|
|
140
|
-
`morph-spec create ${candidate} --description "<o quê/porquê>" --type <feature|bug|chore|hotfix>, ` +
|
|
141
|
-
`depois morph-spec approve ${candidate} ${gate}`
|
|
142
|
-
: `morph-spec approve <feature> ${gate}`;
|
|
143
|
-
warnings.push(
|
|
144
|
-
`⚠️ A sua aprovação (${gateName(gate)}) não foi gravada: a pergunta não diz de qual funcionalidade é ` +
|
|
145
|
-
`("${question}"), e gravar no palpite poderia aprovar a funcionalidade errada.\n` +
|
|
146
|
-
`${SESSION_MARK} ${remediation}`
|
|
147
|
-
);
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const { name: featureName, root } = located;
|
|
152
|
-
if (!stateExists(root)) continue;
|
|
153
|
-
|
|
154
|
-
// Fallback to the merged view: a feature only in the thin index would read every predecessor as unapproved.
|
|
155
|
-
const feature = readFeatureFile(featureName, root) || loadState(root)?.features?.[featureName];
|
|
156
|
-
const gates = feature?.approvalGates;
|
|
157
|
-
const existing = gates?.[gate];
|
|
158
|
-
const alreadyApproved = existing === true || existing?.approved === true;
|
|
159
|
-
if (alreadyApproved) continue;
|
|
160
|
-
const ref = ownerRef(root, featureName, feature);
|
|
161
|
-
|
|
162
|
-
// Out of order still approves (never block a human in the loop); `morph-spec approve` refuses the same shape.
|
|
163
|
-
const unmet = unmetGatePrereqs(gate, gates);
|
|
164
|
-
if (unmet.length) {
|
|
165
|
-
warnings.push(
|
|
166
|
-
`⚠️ Aprovação fora de ordem: ${gateName(gate)} de ${ref} foi gravada, ` +
|
|
167
|
-
`mas antes dela falta ${unmet.map(gateName).join(' e ')}.\n` +
|
|
168
|
-
`${SESSION_MARK} ordem ${[...unmet, gate].join(' → ')}; aprove os anteriores ` +
|
|
169
|
-
`(${unmet.map((g) => `morph-spec approve ${featureName} ${g}`).join(', ')}) ou confira com morph-spec doctor`
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Same contract as `approve --self-assessed`: approving review without its reports is stamped, never silent.
|
|
174
|
-
// The reports live in the tree that ran the review, which may not be the one the feature was found in.
|
|
175
|
-
const trees = allWorkTrees(sessionRoot);
|
|
176
|
-
const reportIn = (f) => trees.some((t) => existsSync(join(t, '.morph', 'features', featureName, '4-review', f)));
|
|
177
|
-
const selfAssessed = gate === 'review' && feature?.workType !== 'hotfix'
|
|
178
|
-
&& (feature?.workType === 'chore' ? ['reviewer.md'] : ['verifier.md', 'reviewer.md']).some((f) => !reportIn(f));
|
|
179
|
-
if (selfAssessed) {
|
|
180
|
-
warnings.push(
|
|
181
|
-
`⚠️ A entrega de ${ref} foi aprovada sem os relatórios da revisão independente: ` +
|
|
182
|
-
`fica registrada como aprovada sem essa revisão.\n` +
|
|
183
|
-
`${SESSION_MARK} faltam 4-review/verifier.md e/ou reviewer.md; gravado selfAssessed (aparece no list/fleet)`
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
setGateApproved(featureName, gate, { approvedBy: 'manual', ...(selfAssessed ? { selfAssessed: true } : {}) }, root);
|
|
187
|
-
}
|
|
188
|
-
return warnings.length ? warnings.join('\n') : null;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export async function run(payload) {
|
|
192
|
-
try {
|
|
193
|
-
// Only a starting point: each handler resolves the tree it reads and writes, so the stateExists gate lives there.
|
|
194
|
-
const sessionRoot = projectDir();
|
|
195
|
-
|
|
196
|
-
const input = payload || {};
|
|
197
|
-
const toolName = input.tool_name;
|
|
198
|
-
|
|
199
|
-
let warning = null;
|
|
200
|
-
try {
|
|
201
|
-
if (toolName === 'Write' || toolName === 'Edit') {
|
|
202
|
-
handleWriteEdit(input, sessionRoot);
|
|
203
|
-
} else if (toolName === 'AskUserQuestion') {
|
|
204
|
-
warning = handleAskUserQuestion(input, sessionRoot);
|
|
205
|
-
}
|
|
206
|
-
} catch {}
|
|
207
|
-
|
|
208
|
-
return warning ? contextResult(warning, 'PostToolUse') : null;
|
|
209
|
-
} catch {
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
await runStandalone(run);
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { statSync, readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
4
|
-
import { dirname, join } from 'path';
|
|
5
|
-
import { stateExists, getActiveFeature, derivePhaseForFeature } from '../../shared/state-reader.js';
|
|
6
|
-
import { appendTelemetryEvent } from '../../shared/telemetry-logger.js';
|
|
7
|
-
import { runStandalone } from '../../shared/hook-response.js';
|
|
8
|
-
import { getFilePath, resolveMorphRoot, resolveTargetPath } from '../../shared/payload-utils.js';
|
|
9
|
-
import { redactSecrets } from '../../shared/redact-secrets.js';
|
|
10
|
-
import { exitCodeMasked } from '../../shared/command-tokens.js';
|
|
11
|
-
import { morphBranchFeature } from '../../shared/git-paths.js';
|
|
12
|
-
import { readTranscriptUsage, usageDelta } from '../../shared/transcript-usage.js';
|
|
13
|
-
|
|
14
|
-
function normalize(p) {
|
|
15
|
-
return (p || '').replace(/\\/g, '/');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// The original length travels in a sibling `<field>Chars` key that `morph-spec cost` prefers: do not rename either half.
|
|
19
|
-
const MAX_FIELD_CHARS = 2000;
|
|
20
|
-
const TRUNCATE_SUFFIX = '…[truncado]';
|
|
21
|
-
|
|
22
|
-
// Read returns this many lines when the call passes no `limit`.
|
|
23
|
-
const DEFAULT_READ_LINES = 2000;
|
|
24
|
-
// Above this, measuring the slice would cost more than the hook budget allows.
|
|
25
|
-
const MAX_SLICE_BYTES = 10 * 1024 * 1024;
|
|
26
|
-
const BINARY_READ = /\.(png|jpe?g|gif|webp|bmp|ico|pdf)$/i;
|
|
27
|
-
|
|
28
|
-
// Redact before capping: a token cut at the cap would survive as a recognizable prefix.
|
|
29
|
-
function capField(value) {
|
|
30
|
-
const str = typeof value === 'string' ? value : '';
|
|
31
|
-
const clean = redactSecrets(str);
|
|
32
|
-
if (clean.length <= MAX_FIELD_CHARS) return { value: clean, chars: str.length };
|
|
33
|
-
return { value: clean.slice(0, MAX_FIELD_CHARS) + TRUNCATE_SUFFIX, chars: str.length };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// The `kind` values are a contract with src/lib/telemetry/telemetry-reader.js.
|
|
37
|
-
function classifyReadKind(target) {
|
|
38
|
-
const t = (target || '').toLowerCase();
|
|
39
|
-
|
|
40
|
-
if (t.includes('evals/review-checklist')) return 'checklist';
|
|
41
|
-
if (t.includes('standards/')) return 'standard';
|
|
42
|
-
if (t.endsWith('skill.md') || t.includes('/skills/')) return 'skill';
|
|
43
|
-
if (t.split('/').pop() === 'agents.json') return 'agents';
|
|
44
|
-
|
|
45
|
-
const inFeature = t.match(/\.morph\/features\/[^/]+\/(.+)$/);
|
|
46
|
-
if (inFeature) {
|
|
47
|
-
const rel = inFeature[1];
|
|
48
|
-
const PLAN_ARTIFACT_BASENAMES = new Set([
|
|
49
|
-
'plan.md', 'checks.json', 'report.md',
|
|
50
|
-
]);
|
|
51
|
-
const base = rel.split('/').pop();
|
|
52
|
-
if (PLAN_ARTIFACT_BASENAMES.has(base) || rel.includes('reports/')) {
|
|
53
|
-
return 'plan-artifact';
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return 'code';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function morphRootAbove(dir, fallback) {
|
|
61
|
-
if (!dir) return fallback;
|
|
62
|
-
let current = normalize(dir);
|
|
63
|
-
for (let i = 0; i < 32; i++) {
|
|
64
|
-
if (stateExists(current)) return current;
|
|
65
|
-
const parent = normalize(dirname(current));
|
|
66
|
-
if (parent === current) break;
|
|
67
|
-
current = parent;
|
|
68
|
-
}
|
|
69
|
-
return fallback;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const FEATURE_NAME = /^[A-Za-z0-9._-]+$/;
|
|
73
|
-
|
|
74
|
-
// Branch binding before state: otherwise a sub-agent's worktree reports the root's most recent active feature.
|
|
75
|
-
async function boundFeature(root) {
|
|
76
|
-
const fromBranch = morphBranchFeature(root);
|
|
77
|
-
if (fromBranch) return fromBranch;
|
|
78
|
-
const manifest = join(root, '.morph', 'worktree.env');
|
|
79
|
-
if (!existsSync(manifest)) return null;
|
|
80
|
-
const { loadEnvFile } = await import('../../shared/e2e-check.js');
|
|
81
|
-
const name = loadEnvFile(manifest)?.MORPH_FEATURE;
|
|
82
|
-
return name && FEATURE_NAME.test(name) && name !== '.' && name !== '..' ? name : null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function featureFromPath(target) {
|
|
86
|
-
const m = /\/\.morph\/features\/([^/]+)\//.exec(`/${normalize(target)}`);
|
|
87
|
-
return m ? m[1] : null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function readSliceBytes(absPath, input, size) {
|
|
91
|
-
if (BINARY_READ.test(absPath)) return size;
|
|
92
|
-
if (size > MAX_SLICE_BYTES) return undefined;
|
|
93
|
-
const offset = Number.isInteger(input.offset) && input.offset > 1 ? input.offset : 1;
|
|
94
|
-
const limit = Number.isInteger(input.limit) && input.limit > 0 ? input.limit : DEFAULT_READ_LINES;
|
|
95
|
-
const lines = readFileSync(absPath, 'utf-8').split('\n');
|
|
96
|
-
if (offset === 1 && limit >= lines.length) return size;
|
|
97
|
-
return Buffer.byteLength(lines.slice(offset - 1, offset - 1 + limit).join('\n'), 'utf-8');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Only the exit code is kept: the rest of `error` is command output, where a secret can appear with no name beside it.
|
|
101
|
-
function outcomeOf(payload, input) {
|
|
102
|
-
if (payload.hook_event_name === 'PostToolUseFailure') {
|
|
103
|
-
const firstLine = String(payload.error ?? '').split('\n', 1)[0];
|
|
104
|
-
const code = /^exit code (\d+)/i.exec(firstLine);
|
|
105
|
-
const outcome = payload.is_interrupt === true ? 'interrupted'
|
|
106
|
-
: /timed? ?out/i.test(firstLine) ? 'timeout'
|
|
107
|
-
: 'error';
|
|
108
|
-
return { outcome, exitCode: code ? Number(code[1]) : null };
|
|
109
|
-
}
|
|
110
|
-
if (input.run_in_background === true) return { outcome: 'background', exitCode: null };
|
|
111
|
-
if (payload.tool_response?.interrupted === true) return { outcome: 'interrupted', exitCode: null };
|
|
112
|
-
return { outcome: 'ok', exitCode: 0 };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function countByName(calls) {
|
|
116
|
-
const out = {};
|
|
117
|
-
for (const call of calls) {
|
|
118
|
-
const name = call?.tool_name || 'unknown';
|
|
119
|
-
out[name] = (out[name] || 0) + 1;
|
|
120
|
-
}
|
|
121
|
-
return out;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// One store file per agent, so two sub-agents stopping together never share a read-modify-write.
|
|
125
|
-
function agentUsageEvent(payload, cwd) {
|
|
126
|
-
const usage = readTranscriptUsage(payload.agent_transcript_path);
|
|
127
|
-
if (!usage || !payload.agent_id) return null;
|
|
128
|
-
const dir = join(cwd, '.morph', 'memory', 'agent-usage');
|
|
129
|
-
const storePath = join(dir, `${String(payload.agent_id).replace(/[^A-Za-z0-9_-]/g, '_')}.json`);
|
|
130
|
-
let previous = null;
|
|
131
|
-
try {
|
|
132
|
-
if (existsSync(storePath)) previous = JSON.parse(readFileSync(storePath, 'utf-8'));
|
|
133
|
-
} catch { previous = null; }
|
|
134
|
-
const { delta, changed } = usageDelta(previous, usage);
|
|
135
|
-
if (!changed) return null;
|
|
136
|
-
try {
|
|
137
|
-
mkdirSync(dir, { recursive: true });
|
|
138
|
-
writeFileSync(storePath, JSON.stringify(usage), 'utf-8');
|
|
139
|
-
} catch { /* the event still carries the delta */ }
|
|
140
|
-
return { event: 'AgentUsage', ...usage, delta };
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export async function run(payload) {
|
|
144
|
-
try {
|
|
145
|
-
if (!payload) return null;
|
|
146
|
-
|
|
147
|
-
const projectDir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
148
|
-
const targetFilePath = getFilePath(payload);
|
|
149
|
-
const targetAbs = targetFilePath ? resolveTargetPath(targetFilePath, projectDir) : '';
|
|
150
|
-
const cwd = targetAbs
|
|
151
|
-
? resolveMorphRoot(targetAbs, null) ?? morphRootAbove(dirname(targetAbs), projectDir)
|
|
152
|
-
: morphRootAbove(payload.cwd, projectDir);
|
|
153
|
-
|
|
154
|
-
if (!stateExists(cwd)) return null;
|
|
155
|
-
|
|
156
|
-
let feature = null;
|
|
157
|
-
let phase = null;
|
|
158
|
-
try {
|
|
159
|
-
const active = getActiveFeature(cwd);
|
|
160
|
-
const bound = await boundFeature(cwd);
|
|
161
|
-
if (bound) {
|
|
162
|
-
feature = bound;
|
|
163
|
-
if (bound === active?.name && active.feature?.phase) phase = active.feature.phase;
|
|
164
|
-
else if (existsSync(join(cwd, '.morph', 'features', bound, 'feature.json'))) phase = derivePhaseForFeature(bound, cwd);
|
|
165
|
-
} else {
|
|
166
|
-
feature = active?.name ?? featureFromPath(targetFilePath);
|
|
167
|
-
if (feature) phase = active?.feature?.phase || derivePhaseForFeature(feature, cwd);
|
|
168
|
-
}
|
|
169
|
-
} catch {}
|
|
170
|
-
|
|
171
|
-
// Claim heartbeat: shouldHeartbeat is a git-free pre-check that says no on ~99% of calls.
|
|
172
|
-
if (feature && payload.session_id) {
|
|
173
|
-
try {
|
|
174
|
-
const { shouldHeartbeat, heartbeatClaim } = await import('../../shared/claim-registry.js');
|
|
175
|
-
if (shouldHeartbeat(feature, { cwd, sessionId: payload.session_id })) {
|
|
176
|
-
const { resolveGitCommonDir } = await import('../../shared/git-paths.js');
|
|
177
|
-
const common = resolveGitCommonDir(cwd);
|
|
178
|
-
if (common) heartbeatClaim(feature, { gitCommonDir: common, sessionId: payload.session_id });
|
|
179
|
-
}
|
|
180
|
-
} catch {}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const hookEvent = payload.hook_event_name;
|
|
184
|
-
let event;
|
|
185
|
-
|
|
186
|
-
if (hookEvent === 'UserPromptSubmit' || (!payload.tool_name && typeof payload.prompt === 'string' && !hookEvent)) {
|
|
187
|
-
const userPrompt = capField(payload.prompt || '');
|
|
188
|
-
event = { event: 'UserPromptSubmit', tool: 'UserPrompt', prompt: userPrompt.value, promptChars: userPrompt.chars };
|
|
189
|
-
} else if (hookEvent === 'PostToolBatch') {
|
|
190
|
-
const calls = Array.isArray(payload.tool_calls) ? payload.tool_calls : [];
|
|
191
|
-
event = { event: 'ToolBatch', size: calls.length, tools: countByName(calls) };
|
|
192
|
-
} else if (hookEvent === 'SubagentStop') {
|
|
193
|
-
event = agentUsageEvent(payload, cwd);
|
|
194
|
-
if (!event) return null;
|
|
195
|
-
} else {
|
|
196
|
-
const tool = payload.tool_name;
|
|
197
|
-
if (!tool) return null;
|
|
198
|
-
const input = payload.tool_input || {};
|
|
199
|
-
event = { event: hookEvent === 'PostToolUseFailure' ? 'PostToolUseFailure' : 'PostToolUse', tool };
|
|
200
|
-
|
|
201
|
-
if (tool === 'Skill') {
|
|
202
|
-
event.skill = input.skill || '';
|
|
203
|
-
} else if (tool === 'Agent' || tool === 'Task') {
|
|
204
|
-
event.persona = input.subagent_type || '';
|
|
205
|
-
if (input.description) event.desc = redactSecrets(input.description);
|
|
206
|
-
const dispatchPrompt = capField(input.prompt || '');
|
|
207
|
-
event.prompt = dispatchPrompt.value;
|
|
208
|
-
event.promptChars = dispatchPrompt.chars;
|
|
209
|
-
} else if (tool === 'SendMessage') {
|
|
210
|
-
if (input.to) event.target = String(input.to);
|
|
211
|
-
event.messageChars = typeof input.message === 'string' ? input.message.length : 0;
|
|
212
|
-
} else if (tool === 'Read') {
|
|
213
|
-
event.target = targetFilePath || normalize(input.file_path || input.path);
|
|
214
|
-
event.kind = classifyReadKind(event.target);
|
|
215
|
-
if (Number.isInteger(input.offset)) event.offset = input.offset;
|
|
216
|
-
if (Number.isInteger(input.limit)) event.limit = input.limit;
|
|
217
|
-
// A failed Read ingested nothing; a file deleted before this hook just omits the numbers.
|
|
218
|
-
if (hookEvent !== 'PostToolUseFailure') {
|
|
219
|
-
try {
|
|
220
|
-
const abs = targetAbs || resolveTargetPath(event.target, projectDir);
|
|
221
|
-
event.bytes = statSync(abs).size;
|
|
222
|
-
const read = readSliceBytes(abs, input, event.bytes);
|
|
223
|
-
if (read !== undefined) event.bytesRead = read;
|
|
224
|
-
} catch {}
|
|
225
|
-
}
|
|
226
|
-
} else if (tool === 'Bash' || tool === 'PowerShell') {
|
|
227
|
-
const command = capField(input.command || '');
|
|
228
|
-
event.command = command.value;
|
|
229
|
-
event.commandChars = command.chars;
|
|
230
|
-
Object.assign(event, outcomeOf(payload, input));
|
|
231
|
-
if (exitCodeMasked(input.command)) event.exitMasked = true;
|
|
232
|
-
} else if (tool === 'Write' || tool === 'Edit') {
|
|
233
|
-
event.target = normalize(input.file_path || input.path);
|
|
234
|
-
} else {
|
|
235
|
-
const target = input.file_path || input.path || input.pattern || input.query || input.url || '';
|
|
236
|
-
if (target) event.target = normalize(String(target));
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (hookEvent === 'PostToolUseFailure' && event.outcome === undefined) event.outcome = 'error';
|
|
240
|
-
if (payload.tool_use_id) event.toolUseId = payload.tool_use_id;
|
|
241
|
-
if (Number.isFinite(payload.duration_ms)) event.durationMs = payload.duration_ms;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (payload.session_id) event.sessionId = payload.session_id;
|
|
245
|
-
if (payload.prompt_id) event.promptId = payload.prompt_id;
|
|
246
|
-
if (payload.agent_id) event.agentId = payload.agent_id;
|
|
247
|
-
if (payload.agent_type) event.agentType = payload.agent_type;
|
|
248
|
-
if (payload.cwd) event.cwd = normalize(payload.cwd);
|
|
249
|
-
event.feature = feature;
|
|
250
|
-
event.phase = phase;
|
|
251
|
-
|
|
252
|
-
appendTelemetryEvent(event, cwd);
|
|
253
|
-
return null;
|
|
254
|
-
} catch {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
await runStandalone(run);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { blockResult, runStandalone } from '../../shared/hook-response.js';
|
|
3
|
-
import { stateExists } from '../../shared/state-reader.js';
|
|
4
|
-
import { REVIEW_AGENT_TYPES, morphVerifyCall, testRunCall } from '../../shared/heavy-command.js';
|
|
5
|
-
|
|
6
|
-
export const REASONS = {
|
|
7
|
-
verify: '`morph-spec verify` sem `--filter` é a prova do gate, rodada pela sessão. Rode só o nó do cenário: `morph-spec verify <f> --filter <nó> --no-persist`.',
|
|
8
|
-
suite: 'Suíte inteira não: rode só o teste do cenário que você está provando (o arquivo, `-t <nome>` ou `--filter <expr>`).',
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const projectRoot = (payload, env) => env.CLAUDE_PROJECT_DIR || payload?.cwd || process.cwd();
|
|
12
|
-
|
|
13
|
-
export async function run(payload, deps = {}) {
|
|
14
|
-
try {
|
|
15
|
-
if (payload?.hook_event_name !== 'PreToolUse' || payload.tool_name !== 'Bash') return null;
|
|
16
|
-
if (!payload.agent_id || !REVIEW_AGENT_TYPES.has(payload.agent_type)) return null;
|
|
17
|
-
const command = payload.tool_input?.command || '';
|
|
18
|
-
const verify = morphVerifyCall(command);
|
|
19
|
-
const tests = testRunCall(command);
|
|
20
|
-
if (!verify && !tests) return null;
|
|
21
|
-
if (!stateExists(projectRoot(payload, deps.env ?? process.env))) return null;
|
|
22
|
-
|
|
23
|
-
if (verify && !verify.filtered) return blockResult(REASONS.verify);
|
|
24
|
-
if (tests && !tests.filtered) return blockResult(REASONS.suite);
|
|
25
|
-
} catch {}
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
await runStandalone(run);
|