@polymorphism-tech/morph-spec 10.12.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +27 -57
- package/README.md +51 -340
- package/bin/morph-spec.js +22 -373
- package/docs/CHEATSHEET.md +37 -166
- package/docs/QUICKSTART.md +14 -74
- package/framework/CLAUDE.md +15 -26
- package/framework/MORPH.md +34 -101
- package/framework/agents.json +8 -8
- package/framework/commands/morph-apply.md +5 -5
- package/framework/commands/morph-infra.md +1 -1
- package/framework/docs/CLI.md +74 -886
- package/framework/evals/review-checklist.md +14 -14
- package/framework/hooks/README.md +21 -189
- package/framework/hooks/claude-code/core/README.md +2 -5
- package/framework/hooks/claude-code/core/conventional-commit.js +2 -2
- package/framework/hooks/claude-code/core/denylist.json +3 -3
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +2 -2
- package/framework/hooks/claude-code/core/masked-exit.js +6 -6
- package/framework/hooks/claude-code/core/pre-bash-denylist.js +2 -2
- package/framework/hooks/claude-code/core/protect-spec-files.js +17 -61
- package/framework/hooks/claude-code/core/stack-changed.js +35 -0
- package/framework/hooks/claude-code/core/validate-completion.js +31 -86
- package/framework/hooks/shared/{heavy-command.js → command-kind.js} +6 -79
- package/framework/hooks/shared/command-tokens.js +0 -139
- package/framework/hooks/shared/contract.js +14 -0
- package/framework/hooks/shared/feature-slug.js +21 -0
- package/framework/hooks/shared/frontend-locations.js +0 -1
- package/framework/hooks/shared/git-paths.js +0 -15
- package/framework/hooks/shared/graph-freshness.js +0 -19
- package/framework/hooks/shared/hook-response.js +0 -7
- package/framework/hooks/shared/morph-cli.js +2 -81
- package/framework/hooks/shared/owner-words.js +2 -120
- package/framework/hooks/shared/payload-utils.js +0 -39
- package/framework/hooks/shared/report-progress.js +7 -101
- package/framework/hooks/statusline.js +16 -60
- package/framework/mcp/registry.json +2 -2
- package/framework/rules/ai-agents-standards.md +1 -1
- package/framework/rules/asaas-standards.md +1 -1
- package/framework/rules/ef-standards.md +1 -1
- package/framework/rules/gsap-standards.md +1 -1
- package/framework/rules/hangfire-standards.md +1 -1
- package/framework/rules/implement-report.md +3 -3
- package/framework/rules/neon-auth-standards.md +1 -1
- package/framework/rules/nextjs-standards.md +1 -1
- package/framework/rules/plan-grammar.md +13 -11
- package/framework/rules/resend-standards.md +1 -1
- package/framework/rules/ui-design.md +4 -0
- package/framework/schemas/config.schema.json +95 -310
- package/framework/skills/README.md +12 -32
- package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
- package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
- package/framework/skills/core/morph-apply/SKILL.md +21 -46
- package/framework/skills/core/morph-plan/SKILL.md +28 -63
- package/framework/skills/core/morph-uiux/SKILL.md +23 -25
- package/framework/{templates/docs/ui-mockups.md → skills/core/morph-uiux/references/mockups.md} +4 -4
- package/framework/standards/STANDARDS.json +10 -11
- package/framework/standards/STANDARDS.meta.json +1 -1
- package/framework/standards/ai-agents/evals-with-cache.md +18 -32
- package/framework/standards/ai-agents/observability-patterns.md +2 -2
- package/framework/standards/architecture/code-comments.md +2 -5
- package/framework/standards/architecture/engineering-lens.md +1 -1
- package/framework/standards/backend/dotnet/testing.md +4 -4
- package/framework/standards/frontend/nextjs/lint.md +24 -10
- package/framework/standards/frontend/nextjs/testing.md +2 -2
- package/framework/standards/infrastructure/docker/local-compose-isolation.md +14 -30
- package/framework/templates/CLAUDE.md.core.guide.md +2 -2
- package/framework/templates/README.md +1 -1
- package/framework/templates/REGISTRY.json +3 -33
- package/framework/templates/docs/plan.md +3 -2
- package/framework/templates/dotnet/ai-kit/README.md +2 -4
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheMissException.cs +1 -1
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalFixture.cs +1 -1
- package/package.json +1 -2
- package/src/commands/graph/explain.js +2 -1
- package/src/commands/graph/status.js +2 -1
- package/src/commands/mcp/mcp-setup.js +1 -2
- package/src/commands/project/doctor.js +5 -341
- package/src/commands/project/env.js +21 -52
- package/src/commands/project/init-contract.js +47 -0
- package/src/commands/project/init.js +36 -66
- package/src/commands/project/stack-scan.js +1 -1
- package/src/commands/project/update.js +15 -50
- package/src/commands/validation/check.js +128 -0
- package/src/commands/validation/plan-check.js +41 -64
- package/src/commands/validation/prove-red.js +1 -1
- package/src/core/paths/output-schema.js +0 -22
- package/src/core/templates/template-renderer.js +0 -14
- package/src/lib/ai/ai-project-scan.js +1 -6
- package/src/lib/check/attempts.js +38 -0
- package/src/lib/check/signals.js +145 -0
- package/src/lib/config/project-config.js +13 -0
- package/src/lib/contract/apply.js +62 -0
- package/src/lib/contract/defaults.js +96 -0
- package/src/lib/contract/merge.js +79 -0
- package/src/lib/contract/ports.js +43 -0
- package/src/lib/contract/scan.js +102 -0
- package/src/lib/detectors/claude-config-detector.js +7 -0
- package/src/lib/{procs → detectors}/mcp-config.js +1 -37
- package/src/lib/diff/diff-lines.js +64 -0
- package/src/lib/generators/architecture-scanner.js +1 -1
- package/src/lib/generators/scaffold-generator.js +0 -7
- package/src/lib/git/default-branch.js +0 -122
- package/src/lib/graph/diff-tree.js +2 -1
- package/src/lib/graph/god-nodes.js +2 -1
- package/src/lib/graph/graphify-runtime.js +0 -1
- package/src/lib/graph/graphifyignore.js +1 -1
- package/src/lib/graph/sanitize.js +2 -8
- package/src/lib/installers/memory-installer.js +15 -30
- package/src/lib/installers/stack-sync.js +16 -9
- package/src/lib/plan/checks.js +20 -64
- package/src/lib/plan/media.js +1 -1
- package/src/lib/plan/plan-parser.js +5 -5
- package/src/lib/review-reports.js +3 -77
- package/src/lib/scan/worktree-dirs.js +3 -0
- package/src/lib/specs/adr-index.js +2 -2
- package/src/lib/stack/dotnet-build-ignores.js +10 -2
- package/src/lib/stack/stack-scan.js +2 -2
- package/src/lib/stack-filter.js +3 -2
- package/src/lib/tests-audit/audit.js +1 -1
- package/src/scripts/setup-infra.js +6 -59
- package/src/utils/agents-installer.js +1 -34
- package/src/utils/atomic-json.js +27 -0
- package/src/utils/file-copier.js +4 -12
- package/src/utils/hooks-installer.js +9 -107
- package/claude-plugin.json +0 -14
- package/framework/commands/morph-archive.md +0 -46
- package/framework/commands/morph-hotfix.md +0 -17
- package/framework/commands/morph-preflight.md +0 -180
- package/framework/commands/morph-review.md +0 -15
- package/framework/commands/morph-status.md +0 -37
- package/framework/hooks/claude-code/core/block-destructive-worktree-removal.js +0 -80
- package/framework/hooks/claude-code/core/block-raw-worktree-add.js +0 -72
- package/framework/hooks/claude-code/core/enforce-phase-writes.js +0 -100
- package/framework/hooks/claude-code/core/gate-guard.js +0 -148
- package/framework/hooks/claude-code/core/heavy-gate.js +0 -78
- package/framework/hooks/claude-code/core/heavy-release.js +0 -23
- package/framework/hooks/claude-code/core/loop-detect.js +0 -79
- package/framework/hooks/claude-code/core/state-sync.js +0 -214
- package/framework/hooks/claude-code/core/telemetry-log.js +0 -259
- package/framework/hooks/claude-code/core/test-budget.js +0 -29
- package/framework/hooks/claude-code/core/worktree-context.js +0 -249
- package/framework/hooks/claude-code/core/worktree-create.js +0 -119
- package/framework/hooks/claude-code/core/worktree-env-inject.js +0 -68
- package/framework/hooks/claude-code/core/worktree-remove.js +0 -55
- package/framework/hooks/shared/build-check.js +0 -120
- package/framework/hooks/shared/claim-registry.js +0 -125
- package/framework/hooks/shared/e2e-check.js +0 -1022
- package/framework/hooks/shared/feature-locator.js +0 -82
- package/framework/hooks/shared/gate-event.js +0 -18
- package/framework/hooks/shared/gate-question.js +0 -20
- package/framework/hooks/shared/heavy-config.js +0 -113
- package/framework/hooks/shared/heavy-holders.js +0 -85
- package/framework/hooks/shared/heavy-slots.js +0 -280
- package/framework/hooks/shared/host-services.js +0 -440
- package/framework/hooks/shared/next-step.js +0 -181
- package/framework/hooks/shared/redact-secrets.js +0 -44
- package/framework/hooks/shared/reparse-scan.js +0 -40
- package/framework/hooks/shared/state-reader.js +0 -220
- package/framework/hooks/shared/state-writer.js +0 -112
- package/framework/hooks/shared/telemetry-logger.js +0 -101
- package/framework/hooks/shared/transcript-usage.js +0 -58
- package/framework/hooks/shared/worktree-root.js +0 -71
- package/framework/phases.json +0 -92
- package/framework/schemas/feature.schema.json +0 -242
- package/framework/skills/core/morph-apply/references/hotfix.md +0 -46
- package/framework/skills/core/morph-apply/references/machine.md +0 -30
- package/framework/skills/core/morph-apply/references/review.md +0 -77
- package/framework/skills/core/morph-plan/references/critique.md +0 -51
- package/framework/skills/core/morph-plan/references/interview.md +0 -37
- package/framework/templates/state.template.json +0 -17
- package/src/commands/dashboard/dashboard.js +0 -74
- package/src/commands/e2e/e2e.js +0 -400
- package/src/commands/observability/cost.js +0 -283
- package/src/commands/project/branch.js +0 -129
- package/src/commands/project/claim.js +0 -132
- package/src/commands/project/doctor-procs.js +0 -162
- package/src/commands/project/fleet.js +0 -66
- package/src/commands/project/heavy.js +0 -81
- package/src/commands/project/install-plugin-cmd.js +0 -27
- package/src/commands/project/status.js +0 -61
- package/src/commands/project/worktree.js +0 -1234
- package/src/commands/state/advance.js +0 -248
- package/src/commands/state/approve.js +0 -303
- package/src/commands/state/archive.js +0 -231
- package/src/commands/state/auto-approval.js +0 -67
- package/src/commands/state/create.js +0 -274
- package/src/commands/state/delete.js +0 -192
- package/src/commands/state/finish.js +0 -1247
- package/src/commands/state/gate-check.js +0 -244
- package/src/commands/state/gate-decision.js +0 -122
- package/src/commands/state/list.js +0 -244
- package/src/commands/state/next.js +0 -24
- package/src/commands/state/recap.js +0 -80
- package/src/commands/state/report-check.js +0 -244
- package/src/commands/state/retype.js +0 -110
- package/src/commands/validation/verify.js +0 -421
- package/src/core/state/feature-identity.js +0 -10
- package/src/core/state/gate-order.js +0 -23
- package/src/core/state/lifecycle-audit.js +0 -171
- package/src/core/state/state-manager.js +0 -523
- package/src/core/templates/template-seed.js +0 -21
- package/src/core/work-types.js +0 -44
- package/src/dashboard/app/App.jsx +0 -84
- package/src/dashboard/app/components/ActivityFeed.jsx +0 -166
- package/src/dashboard/app/components/CommandPalette.jsx +0 -144
- package/src/dashboard/app/components/DetailPanel.jsx +0 -43
- package/src/dashboard/app/components/EntityLink.jsx +0 -42
- package/src/dashboard/app/components/ErrorBoundary.jsx +0 -47
- package/src/dashboard/app/components/FlowGraph.jsx +0 -19
- package/src/dashboard/app/components/GatePauses.jsx +0 -116
- package/src/dashboard/app/components/KnowledgeMarkdown.jsx +0 -42
- package/src/dashboard/app/components/Markdown.jsx +0 -38
- package/src/dashboard/app/components/PhaseRail.jsx +0 -100
- package/src/dashboard/app/components/SearchFilter.jsx +0 -36
- package/src/dashboard/app/components/SessionMap.jsx +0 -77
- package/src/dashboard/app/components/Sidebar.jsx +0 -147
- package/src/dashboard/app/hooks/useMorphQuery.js +0 -44
- package/src/dashboard/app/hooks/usePref.js +0 -34
- package/src/dashboard/app/lib/format.js +0 -69
- package/src/dashboard/app/lib/phases.js +0 -75
- package/src/dashboard/app/lib/project.js +0 -38
- package/src/dashboard/app/main.jsx +0 -13
- package/src/dashboard/app/pages/Activity.jsx +0 -28
- package/src/dashboard/app/pages/AgentMap.jsx +0 -363
- package/src/dashboard/app/pages/FeatureDetail.jsx +0 -579
- package/src/dashboard/app/pages/Features.jsx +0 -393
- package/src/dashboard/app/pages/Guide.jsx +0 -145
- package/src/dashboard/app/pages/HookInspector.jsx +0 -444
- package/src/dashboard/app/pages/PhasePipeline.jsx +0 -273
- package/src/dashboard/app/pages/Portfolio.jsx +0 -190
- package/src/dashboard/app/pages/RulesMap.jsx +0 -285
- package/src/dashboard/app/pages/SkillsLibrary.jsx +0 -468
- package/src/dashboard/app/pages/Standards.jsx +0 -392
- package/src/dashboard/app/styles/index.css +0 -187
- package/src/dashboard/index.html +0 -14
- package/src/dashboard/package.json +0 -32
- package/src/dashboard/scanner/activity-scanner.js +0 -321
- package/src/dashboard/scanner/agents-scanner.js +0 -67
- package/src/dashboard/scanner/docs-scanner.js +0 -34
- package/src/dashboard/scanner/feature-status.js +0 -7
- package/src/dashboard/scanner/features-scanner.js +0 -397
- package/src/dashboard/scanner/hooks-scanner.js +0 -96
- package/src/dashboard/scanner/index.js +0 -21
- package/src/dashboard/scanner/phases-scanner.js +0 -14
- package/src/dashboard/scanner/portfolio.js +0 -129
- package/src/dashboard/scanner/project-api.js +0 -160
- package/src/dashboard/scanner/rules-scanner.js +0 -46
- package/src/dashboard/scanner/skills-scanner.js +0 -104
- package/src/dashboard/scanner/standards-scanner.js +0 -38
- package/src/dashboard/vite-plugin-morph-data.js +0 -120
- package/src/dashboard/vite.config.js +0 -26
- package/src/lib/ci/ci-verify.js +0 -30
- package/src/lib/ci/github-ci.js +0 -52
- package/src/lib/ci/pr-checks.js +0 -76
- package/src/lib/e2e/applicability.js +0 -39
- package/src/lib/e2e/compose-env.js +0 -80
- package/src/lib/e2e/stack-teardown.js +0 -96
- package/src/lib/git/branch-classifier.js +0 -104
- package/src/lib/git/evidence-staleness.js +0 -40
- package/src/lib/git/gh.js +0 -15
- package/src/lib/git/pending-prs.js +0 -58
- package/src/lib/git/pr-files.js +0 -31
- package/src/lib/git/pr-index.js +0 -39
- package/src/lib/git/tree-fingerprint.js +0 -58
- package/src/lib/git/tree-state.js +0 -125
- package/src/lib/heavy/cleanup.js +0 -72
- package/src/lib/heavy/gate.js +0 -168
- package/src/lib/heavy/live-stacks.js +0 -64
- package/src/lib/heavy/reclaim.js +0 -107
- package/src/lib/heavy/watchdog.js +0 -46
- package/src/lib/next-step.js +0 -12
- package/src/lib/plan/critique.js +0 -67
- package/src/lib/plan/plan-template.js +0 -18
- package/src/lib/procs/classify.js +0 -91
- package/src/lib/procs/list.js +0 -124
- package/src/lib/procs/prune.js +0 -47
- package/src/lib/procs/wslconfig.js +0 -70
- package/src/lib/projects/registry.js +0 -121
- package/src/lib/recap/piper.js +0 -36
- package/src/lib/recap/recap.js +0 -259
- package/src/lib/review-confirmation.js +0 -66
- package/src/lib/risk/diff-risk.js +0 -137
- package/src/lib/risk-detector.js +0 -638
- package/src/lib/specs/design-seed.js +0 -18
- package/src/lib/specs/screen-checklist.js +0 -315
- package/src/lib/stack/stack-profile.js +0 -69
- package/src/lib/tasks/eval-node.js +0 -293
- package/src/lib/tasks/linux-runner.js +0 -200
- package/src/lib/tasks/test-nodes.js +0 -414
- package/src/lib/tasks/test-runner.js +0 -569
- package/src/lib/telemetry/metrics.js +0 -384
- package/src/lib/telemetry/telemetry-reader.js +0 -276
- package/src/lib/telemetry/verify-event.js +0 -57
- package/src/lib/validators/code-budget/code-budget-validator.js +0 -170
- package/src/lib/validators/contracts/contract-compliance-validator.js +0 -219
- package/src/lib/validators/nextjs/next-component-validator.js +0 -142
- package/src/lib/validators/packages/package-validator.js +0 -310
- package/src/lib/validators/reuse/reuse-validator.js +0 -202
- package/src/lib/validators/reuse/symbol-scanner.js +0 -64
- package/src/lib/validators/validation-runner.js +0 -188
- package/src/lib/validators/verify-cache.js +0 -63
- package/src/lib/validators/verify-runner.js +0 -971
- package/src/lib/verify/affected.js +0 -143
- package/src/lib/verify/detached.js +0 -159
- package/src/lib/view/feature-html.js +0 -480
- package/src/lib/view/feature-page.client.js +0 -109
- package/src/lib/view/feature-page.css +0 -278
- package/src/lib/view/feature-view.js +0 -113
- package/src/lib/view/flow-layers.js +0 -79
- package/src/lib/view/flow-svg.js +0 -63
- package/src/lib/view/tokens.css +0 -18
- package/src/lib/work-type-detector.js +0 -81
- package/src/lib/worktree/dirs.js +0 -3
- package/src/lib/worktree/docker-audit.js +0 -175
- package/src/lib/worktree/env-allocator.js +0 -177
- package/src/lib/worktree/feature-truth.js +0 -145
- package/src/lib/worktree/finish-backup.js +0 -529
- package/src/lib/worktree/fleet-scanner.js +0 -223
- package/src/lib/worktree/ignored-triage.js +0 -136
- package/src/lib/worktree/vscode-settings.js +0 -112
- package/src/lib/worktree/worktree-audit.js +0 -323
- package/src/lib/worktree/worktree-include.js +0 -44
- package/src/scripts/install-plugin.js +0 -114
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// `git worktree remove` (plain or --force) follows reparse points and deletes the
|
|
2
|
-
// primary root's files, nested links included. FAIL-CLOSED: an entry that cannot
|
|
3
|
-
// be read is `unprovable` and blocks exactly like a found link.
|
|
4
|
-
|
|
5
|
-
import { readdirSync, lstatSync } from 'fs';
|
|
6
|
-
import { join, relative } from 'path';
|
|
7
|
-
|
|
8
|
-
/** @returns {{points: string[], unprovable: string[]}} both empty = provably clean */
|
|
9
|
-
export function findReparsePoints(dir, base = dir, acc = { points: [], unprovable: [] }) {
|
|
10
|
-
let entries;
|
|
11
|
-
try {
|
|
12
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
13
|
-
} catch {
|
|
14
|
-
acc.unprovable.push((relative(base, dir) || '.').replace(/\\/g, '/'));
|
|
15
|
-
return acc;
|
|
16
|
-
}
|
|
17
|
-
for (const entry of entries) {
|
|
18
|
-
const p = join(dir, entry.name);
|
|
19
|
-
let st;
|
|
20
|
-
try {
|
|
21
|
-
st = lstatSync(p);
|
|
22
|
-
} catch {
|
|
23
|
-
acc.unprovable.push(relative(base, p).replace(/\\/g, '/'));
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (st.isSymbolicLink()) {
|
|
27
|
-
acc.points.push(relative(base, p).replace(/\\/g, '/'));
|
|
28
|
-
continue; // descending would walk the target, not the worktree
|
|
29
|
-
}
|
|
30
|
-
if (st.isDirectory() && entry.name !== '.git') findReparsePoints(p, base, acc);
|
|
31
|
-
}
|
|
32
|
-
return acc;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// One list on purpose: callers must not weigh `unprovable` lighter than a link.
|
|
36
|
-
export function scanForBlockers(dir) {
|
|
37
|
-
const { points, unprovable } = findReparsePoints(dir);
|
|
38
|
-
const blockers = [...points, ...unprovable];
|
|
39
|
-
return { safe: blockers.length === 0, blockers };
|
|
40
|
-
}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
// Fail-open: missing or corrupt state reads as null, never throws.
|
|
2
|
-
|
|
3
|
-
import { readFileSync, existsSync, readdirSync } from 'fs';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
|
|
6
|
-
const STATE_FILE = '.morph/state.json';
|
|
7
|
-
const FEATURES_DIR = '.morph/features';
|
|
8
|
-
|
|
9
|
-
// Memoized per process: each hook/CLI process handles one call. The returned
|
|
10
|
-
// object is shared, so treat it as read-only; writers call `clearStateCache()`.
|
|
11
|
-
const stateCache = new Map();
|
|
12
|
-
|
|
13
|
-
export function clearStateCache() {
|
|
14
|
-
stateCache.clear();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** The thin `state.json` index overlaid with each authoritative `feature.json`; null when neither exists. */
|
|
18
|
-
export function loadState(projectPath) {
|
|
19
|
-
const base = projectPath || process.cwd();
|
|
20
|
-
if (stateCache.has(base)) return stateCache.get(base);
|
|
21
|
-
|
|
22
|
-
const state = (() => {
|
|
23
|
-
try {
|
|
24
|
-
const statePath = join(base, STATE_FILE);
|
|
25
|
-
|
|
26
|
-
let state = null;
|
|
27
|
-
if (existsSync(statePath)) {
|
|
28
|
-
state = JSON.parse(readFileSync(statePath, 'utf-8'));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const featuresDir = join(base, FEATURES_DIR);
|
|
32
|
-
if (existsSync(featuresDir)) {
|
|
33
|
-
let names = [];
|
|
34
|
-
try {
|
|
35
|
-
names = readdirSync(featuresDir, { withFileTypes: true })
|
|
36
|
-
.filter((e) => e.isDirectory())
|
|
37
|
-
.map((e) => e.name);
|
|
38
|
-
} catch {
|
|
39
|
-
names = [];
|
|
40
|
-
}
|
|
41
|
-
for (const name of names) {
|
|
42
|
-
const fjPath = join(featuresDir, name, 'feature.json');
|
|
43
|
-
if (!existsSync(fjPath)) continue;
|
|
44
|
-
try {
|
|
45
|
-
const fj = JSON.parse(readFileSync(fjPath, 'utf-8'));
|
|
46
|
-
state = state || { features: {} };
|
|
47
|
-
state.features = state.features || {};
|
|
48
|
-
state.features[name] = fj; // feature.json is authoritative
|
|
49
|
-
} catch {
|
|
50
|
-
// one corrupt feature.json must not blind every hook
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return state;
|
|
56
|
-
} catch {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
})();
|
|
60
|
-
|
|
61
|
-
stateCache.set(base, state);
|
|
62
|
-
return state;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// A fresh worktree has `feature.json` but no gitignored `state.json` yet; hooks
|
|
66
|
-
// must stay on there.
|
|
67
|
-
export function stateExists(projectPath) {
|
|
68
|
-
try {
|
|
69
|
-
const base = projectPath || process.cwd();
|
|
70
|
-
if (existsSync(join(base, STATE_FILE))) return true;
|
|
71
|
-
|
|
72
|
-
const featuresDir = join(base, FEATURES_DIR);
|
|
73
|
-
if (!existsSync(featuresDir)) return false;
|
|
74
|
-
|
|
75
|
-
const names = readdirSync(featuresDir, { withFileTypes: true })
|
|
76
|
-
.filter((e) => e.isDirectory())
|
|
77
|
-
.map((e) => e.name);
|
|
78
|
-
|
|
79
|
-
return names.some((name) => existsSync(join(featuresDir, name, 'feature.json')));
|
|
80
|
-
} catch {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function getActiveFeature(projectPath) {
|
|
86
|
-
const state = loadState(projectPath);
|
|
87
|
-
if (!state?.features) return null;
|
|
88
|
-
|
|
89
|
-
let active = null;
|
|
90
|
-
let latestUpdate = '';
|
|
91
|
-
|
|
92
|
-
for (const [name, feature] of Object.entries(state.features)) {
|
|
93
|
-
if (feature.status === 'in_progress' || feature.status === 'draft') {
|
|
94
|
-
const updated = feature.updatedAt || feature.createdAt || '';
|
|
95
|
-
if (updated >= latestUpdate) {
|
|
96
|
-
latestUpdate = updated;
|
|
97
|
-
active = { name, feature };
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return active;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function getMostRecentFeature(projectPath) {
|
|
106
|
-
const state = loadState(projectPath);
|
|
107
|
-
if (!state?.features) return null;
|
|
108
|
-
|
|
109
|
-
let result = null;
|
|
110
|
-
let latestUpdate = '';
|
|
111
|
-
|
|
112
|
-
for (const [name, feature] of Object.entries(state.features)) {
|
|
113
|
-
const updated = feature.updatedAt || feature.createdAt || '';
|
|
114
|
-
if (updated >= latestUpdate) {
|
|
115
|
-
latestUpdate = updated;
|
|
116
|
-
result = { name, feature };
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function getFeature(featureName, projectPath) {
|
|
124
|
-
const state = loadState(projectPath);
|
|
125
|
-
return state?.features?.[featureName] || null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export const PHASE_INDEX = { plan: 0, uiux: 1, implement: 2, review: 3 };
|
|
129
|
-
|
|
130
|
-
// Descending. An empty folder is not an artifact: a pre-created folder must
|
|
131
|
-
// not advance the phase.
|
|
132
|
-
export const PHASE_ARTIFACTS = [
|
|
133
|
-
['4-review', 'review', 'verifier.md'],
|
|
134
|
-
['3-implement', 'implement', 'report.md'],
|
|
135
|
-
['3-implement', 'implement', 'reports/'],
|
|
136
|
-
['1-design', 'uiux', 'mockups.md'],
|
|
137
|
-
['2-plan', 'plan', 'plan.md'],
|
|
138
|
-
];
|
|
139
|
-
|
|
140
|
-
const DESIGN_DIR = '1-design';
|
|
141
|
-
|
|
142
|
-
const gatesOf = (feature) => feature?.approvals || feature?.approvalGates;
|
|
143
|
-
|
|
144
|
-
export function gateImpliedPhaseFrom(feature, designStarted = false) {
|
|
145
|
-
const gates = gatesOf(feature);
|
|
146
|
-
const ok = (g) => gates?.[g]?.approved === true;
|
|
147
|
-
if (ok('review')) return 'review';
|
|
148
|
-
if (ok('plan')) return designStarted && !ok('uiux') ? 'uiux' : 'implement';
|
|
149
|
-
return 'plan';
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** A path ending in `/` asks for any `.md` file directly under it. */
|
|
153
|
-
export function diskArtifactProbe(featureDir) {
|
|
154
|
-
return (rel) => {
|
|
155
|
-
const abs = join(featureDir, ...rel.split('/').filter(Boolean));
|
|
156
|
-
if (!rel.endsWith('/')) return existsSync(abs);
|
|
157
|
-
try {
|
|
158
|
-
return readdirSync(abs, { withFileTypes: true }).some((e) => e.isFile() && e.name.endsWith('.md'));
|
|
159
|
-
} catch {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function fileSetArtifactProbe(files) {
|
|
166
|
-
return (rel) => {
|
|
167
|
-
if (!rel.endsWith('/')) return files.has(rel);
|
|
168
|
-
for (const f of files) {
|
|
169
|
-
if (f.startsWith(rel) && f.endsWith('.md') && !f.slice(rel.length).includes('/')) return true;
|
|
170
|
-
}
|
|
171
|
-
return false;
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** @param {(relPath: string) => boolean} hasArtifact - {@link diskArtifactProbe} or {@link fileSetArtifactProbe} */
|
|
176
|
-
export function derivePhaseFrom(feature, hasArtifact) {
|
|
177
|
-
let artifactPhase = 'plan';
|
|
178
|
-
for (const [folder, phase, canonical] of PHASE_ARTIFACTS) {
|
|
179
|
-
if (hasArtifact(`${folder}/${canonical}`)) { artifactPhase = phase; break; }
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// An approved gate advances the phase before the next artifact exists, or
|
|
183
|
-
// that artifact could never be written.
|
|
184
|
-
const designStarted = hasArtifact(DESIGN_DIR) || hasArtifact(`${DESIGN_DIR}/mockups.md`);
|
|
185
|
-
// `unapprove` goes back through the normal flow: the revoked gate's phase holds until it is approved again.
|
|
186
|
-
const revoked = ['plan', 'uiux'].find((g) => gatesOf(feature)?.[g]?.revokedAt && gatesOf(feature)[g].approved !== true);
|
|
187
|
-
if (revoked && PHASE_INDEX[artifactPhase] > PHASE_INDEX[revoked]) return revoked;
|
|
188
|
-
const implied = gateImpliedPhaseFrom(feature, designStarted);
|
|
189
|
-
return PHASE_INDEX[implied] > PHASE_INDEX[artifactPhase] ? implied : artifactPhase;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function derivePhaseForFeature(featureName, projectPath) {
|
|
193
|
-
const basePath = join(projectPath || process.cwd(), '.morph/features', featureName);
|
|
194
|
-
return derivePhaseFrom(getFeature(featureName, projectPath), diskArtifactProbe(basePath));
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function getFeaturePhase(featureName, projectPath) {
|
|
198
|
-
const feature = getFeature(featureName, projectPath);
|
|
199
|
-
if (!feature) return null;
|
|
200
|
-
return feature.phase || derivePhaseForFeature(featureName, projectPath);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function isGateApproved(featureName, gate, projectPath) {
|
|
204
|
-
const feature = getFeature(featureName, projectPath);
|
|
205
|
-
const gates = feature?.approvals || feature?.approvalGates;
|
|
206
|
-
return gates?.[gate]?.approved === true;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export function pendingGatesFrom(feature) {
|
|
210
|
-
const gates = gatesOf(feature);
|
|
211
|
-
if (!gates) return [];
|
|
212
|
-
|
|
213
|
-
return Object.entries(gates)
|
|
214
|
-
.filter(([, gate]) => !gate.approved)
|
|
215
|
-
.map(([name]) => name);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export function getPendingGates(featureName, projectPath) {
|
|
219
|
-
return pendingGatesFrom(getFeature(featureName, projectPath));
|
|
220
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// Hook-side mirror of the CLI state writers (hooks cannot import `src/`).
|
|
2
|
-
// Fail-open: every function returns a boolean, never throws.
|
|
3
|
-
|
|
4
|
-
import { readFileSync, writeFileSync, renameSync, unlinkSync, existsSync, mkdirSync } from 'fs';
|
|
5
|
-
import { join, dirname } from 'path';
|
|
6
|
-
import { clearStateCache } from './state-reader.js';
|
|
7
|
-
import { recordGateEvent } from './gate-event.js';
|
|
8
|
-
|
|
9
|
-
const STATE_FILE = '.morph/state.json';
|
|
10
|
-
const STATE_VERSION = '5.0.0';
|
|
11
|
-
|
|
12
|
-
export function featureJsonPath(featureName, projectPath) {
|
|
13
|
-
return join(projectPath || process.cwd(), '.morph', 'features', featureName, 'feature.json');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function readFeatureFile(featureName, projectPath) {
|
|
17
|
-
const p = featureJsonPath(featureName, projectPath);
|
|
18
|
-
if (!existsSync(p)) return null;
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(readFileSync(p, 'utf-8'));
|
|
21
|
-
} catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// EPERM retry: Windows rename fails while another process holds the target.
|
|
27
|
-
function atomicWriteJson(targetPath, data) {
|
|
28
|
-
const dir = dirname(targetPath);
|
|
29
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
30
|
-
const tmp = `${targetPath}.tmp.${process.pid}`;
|
|
31
|
-
writeFileSync(tmp, JSON.stringify(data, null, 2), 'utf-8');
|
|
32
|
-
for (let attempt = 0; attempt <= 5; attempt++) {
|
|
33
|
-
try {
|
|
34
|
-
renameSync(tmp, targetPath);
|
|
35
|
-
return;
|
|
36
|
-
} catch (err) {
|
|
37
|
-
if (err.code === 'EPERM' && attempt < 5) {
|
|
38
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50 * (attempt + 1));
|
|
39
|
-
} else {
|
|
40
|
-
try { unlinkSync(tmp); } catch { /* ignore */ }
|
|
41
|
-
throw err;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function persistFeature(featureName, feature, projectPath) {
|
|
48
|
-
try {
|
|
49
|
-
atomicWriteJson(featureJsonPath(featureName, projectPath), feature);
|
|
50
|
-
|
|
51
|
-
const statePath = join(projectPath || process.cwd(), STATE_FILE);
|
|
52
|
-
let root = {};
|
|
53
|
-
if (existsSync(statePath)) {
|
|
54
|
-
try { root = JSON.parse(readFileSync(statePath, 'utf-8')); } catch { root = {}; }
|
|
55
|
-
}
|
|
56
|
-
root.version = root.version || STATE_VERSION;
|
|
57
|
-
root.features = root.features || {};
|
|
58
|
-
root.features[featureName] = { status: feature.status, updatedAt: feature.updatedAt };
|
|
59
|
-
root.metadata = root.metadata || {};
|
|
60
|
-
root.metadata.totalFeatures = Object.keys(root.features).length;
|
|
61
|
-
atomicWriteJson(statePath, root);
|
|
62
|
-
|
|
63
|
-
// chain.js runs several hooks in one process: the next link must not read
|
|
64
|
-
// the memoized pre-write snapshot.
|
|
65
|
-
clearStateCache();
|
|
66
|
-
return true;
|
|
67
|
-
} catch {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** @param {{ approvedBy?: string, timestamp?: string, selfAssessed?: boolean }} [meta] */
|
|
73
|
-
export function setGateApproved(featureName, gate, meta = {}, projectPath) {
|
|
74
|
-
try {
|
|
75
|
-
const feature = readFeatureFile(featureName, projectPath) || createDefaultFeature(featureName);
|
|
76
|
-
const now = new Date().toISOString();
|
|
77
|
-
feature.approvalGates = feature.approvalGates || {};
|
|
78
|
-
feature.approvalGates[gate] = {
|
|
79
|
-
approved: true,
|
|
80
|
-
timestamp: meta.timestamp || now,
|
|
81
|
-
approvedBy: meta.approvedBy || 'manual',
|
|
82
|
-
...(meta.selfAssessed ? { selfAssessed: true } : {}),
|
|
83
|
-
};
|
|
84
|
-
feature.updatedAt = now;
|
|
85
|
-
if (!persistFeature(featureName, feature, projectPath)) return false;
|
|
86
|
-
} catch {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
recordGateEvent(projectPath, { feature: featureName, gate, step: 'approve', approvedBy: meta.approvedBy || 'manual' });
|
|
91
|
-
} catch {}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Stamps identity so a feature born implicitly by a hook is never an anonymous
|
|
96
|
-
// shell; `description` stays absent because a hook cannot invent it.
|
|
97
|
-
export function createDefaultFeature(featureName) {
|
|
98
|
-
const now = new Date().toISOString();
|
|
99
|
-
return {
|
|
100
|
-
...(featureName ? { name: featureName } : {}),
|
|
101
|
-
status: 'in_progress',
|
|
102
|
-
workType: 'feature',
|
|
103
|
-
createdAt: now,
|
|
104
|
-
updatedAt: now,
|
|
105
|
-
approvalGates: {
|
|
106
|
-
plan: { approved: false, timestamp: null, approvedBy: null },
|
|
107
|
-
uiux: { approved: false, timestamp: null, approvedBy: null },
|
|
108
|
-
review: { approved: false, timestamp: null, approvedBy: null },
|
|
109
|
-
},
|
|
110
|
-
outputs: {},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// Append-only on purpose: rewriting a whole JSON doc per event is O(n²) across
|
|
2
|
-
// a session, and this runs on every tool call. Fail-silent: never blocks a hook.
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
appendFileSync, readFileSync, mkdirSync, existsSync, statSync, renameSync,
|
|
6
|
-
} from 'fs';
|
|
7
|
-
import { join, dirname } from 'path';
|
|
8
|
-
import { randomUUID } from 'crypto';
|
|
9
|
-
import { redactSecrets } from './redact-secrets.js';
|
|
10
|
-
|
|
11
|
-
const LOGS_DIR = '.morph/logs';
|
|
12
|
-
export const EVENTS_FILE = join(LOGS_DIR, 'events.jsonl');
|
|
13
|
-
|
|
14
|
-
export const ROTATE_THRESHOLD_BYTES = 5 * 1024 * 1024;
|
|
15
|
-
|
|
16
|
-
// Bumped when a field changes meaning. Readers key legacy handling off its
|
|
17
|
-
// absence (v1 events carry no schemaVersion and no eventId).
|
|
18
|
-
export const TELEMETRY_SCHEMA_VERSION = 2;
|
|
19
|
-
|
|
20
|
-
const FREE_TEXT_FIELDS = ['command', 'prompt', 'desc', 'target'];
|
|
21
|
-
|
|
22
|
-
/** A tool call that failed read nothing and changed nothing. */
|
|
23
|
-
export function isFailedToolCall(event) {
|
|
24
|
-
return event?.event === 'PostToolUseFailure';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getEventsPath(projectPath) {
|
|
28
|
-
return join(projectPath || process.cwd(), EVENTS_FILE);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// `eventId` dedupes the same line read back from a rotated archive or a finish backup.
|
|
32
|
-
export function appendTelemetryEvent(event, projectPath) {
|
|
33
|
-
try {
|
|
34
|
-
const eventsPath = getEventsPath(projectPath);
|
|
35
|
-
const dir = dirname(eventsPath);
|
|
36
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
37
|
-
|
|
38
|
-
const stamped = {
|
|
39
|
-
ts: event?.ts || new Date().toISOString(),
|
|
40
|
-
schemaVersion: TELEMETRY_SCHEMA_VERSION,
|
|
41
|
-
eventId: randomUUID(),
|
|
42
|
-
...event,
|
|
43
|
-
};
|
|
44
|
-
for (const field of FREE_TEXT_FIELDS) {
|
|
45
|
-
if (typeof stamped[field] === 'string') stamped[field] = redactSecrets(stamped[field]);
|
|
46
|
-
}
|
|
47
|
-
appendFileSync(eventsPath, JSON.stringify(stamped) + '\n', 'utf-8');
|
|
48
|
-
} catch {
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function readTelemetryEvents(projectPath) {
|
|
53
|
-
try {
|
|
54
|
-
const eventsPath = getEventsPath(projectPath);
|
|
55
|
-
if (!existsSync(eventsPath)) return [];
|
|
56
|
-
const raw = readFileSync(eventsPath, 'utf-8');
|
|
57
|
-
const events = [];
|
|
58
|
-
for (const line of raw.split('\n')) {
|
|
59
|
-
const trimmed = line.trim();
|
|
60
|
-
if (!trimmed) continue;
|
|
61
|
-
try {
|
|
62
|
-
events.push(JSON.parse(trimmed));
|
|
63
|
-
} catch {
|
|
64
|
-
// a process killed mid-write leaves a truncated line
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return events;
|
|
68
|
-
} catch {
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// `events-` prefix: older activity-log archives in `sessions/` carry none.
|
|
74
|
-
function archiveEvents(projectPath) {
|
|
75
|
-
try {
|
|
76
|
-
const eventsPath = getEventsPath(projectPath);
|
|
77
|
-
if (!existsSync(eventsPath)) return;
|
|
78
|
-
|
|
79
|
-
const sessionsDir = join(projectPath || process.cwd(), LOGS_DIR, 'sessions');
|
|
80
|
-
mkdirSync(sessionsDir, { recursive: true });
|
|
81
|
-
|
|
82
|
-
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
83
|
-
const archivePath = join(sessionsDir, `events-${stamp}.jsonl`);
|
|
84
|
-
renameSync(eventsPath, archivePath);
|
|
85
|
-
} catch {
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** @returns {boolean} true if a rotation was performed */
|
|
90
|
-
export function rotateEventsLogIfLarge(projectPath, thresholdBytes = ROTATE_THRESHOLD_BYTES) {
|
|
91
|
-
try {
|
|
92
|
-
const eventsPath = getEventsPath(projectPath);
|
|
93
|
-
if (!existsSync(eventsPath)) return false;
|
|
94
|
-
const { size } = statSync(eventsPath);
|
|
95
|
-
if (size < thresholdBytes) return false;
|
|
96
|
-
archiveEvents(projectPath);
|
|
97
|
-
return true;
|
|
98
|
-
} catch {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// Shared by Stop and SubagentStop: the main transcript does not include the
|
|
2
|
-
// sub-agents' usage.
|
|
3
|
-
|
|
4
|
-
import { readFileSync, existsSync, statSync } from 'fs';
|
|
5
|
-
|
|
6
|
-
// Skip rather than risk an unbounded read inside a hook.
|
|
7
|
-
const MAX_TRANSCRIPT_BYTES = 50 * 1024 * 1024;
|
|
8
|
-
|
|
9
|
-
export const USAGE_KEYS = ['inputTokens', 'outputTokens', 'cacheReadTokens', 'cacheCreationTokens'];
|
|
10
|
-
|
|
11
|
-
// One turn spans several lines repeating the same usage under the same
|
|
12
|
-
// `message.id`: summing lines double-counts, so the sum dedups by id.
|
|
13
|
-
export function readTranscriptUsage(transcriptPath) {
|
|
14
|
-
if (!transcriptPath || typeof transcriptPath !== 'string') return null;
|
|
15
|
-
try {
|
|
16
|
-
if (!existsSync(transcriptPath)) return null;
|
|
17
|
-
if (statSync(transcriptPath).size > MAX_TRANSCRIPT_BYTES) return null;
|
|
18
|
-
|
|
19
|
-
const totals = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0 };
|
|
20
|
-
const seen = new Set();
|
|
21
|
-
let sawAny = false;
|
|
22
|
-
|
|
23
|
-
for (const line of readFileSync(transcriptPath, 'utf-8').split('\n')) {
|
|
24
|
-
const trimmed = line.trim();
|
|
25
|
-
if (!trimmed) continue;
|
|
26
|
-
let entry;
|
|
27
|
-
try { entry = JSON.parse(trimmed); } catch { continue; }
|
|
28
|
-
if (entry?.type !== 'assistant') continue;
|
|
29
|
-
const usage = entry?.message?.usage;
|
|
30
|
-
if (!usage || typeof usage !== 'object') continue;
|
|
31
|
-
|
|
32
|
-
const key = entry?.message?.id || entry?.uuid;
|
|
33
|
-
if (key) {
|
|
34
|
-
if (seen.has(key)) continue;
|
|
35
|
-
seen.add(key);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
sawAny = true;
|
|
39
|
-
totals.inputTokens += Number(usage.input_tokens) || 0;
|
|
40
|
-
totals.outputTokens += Number(usage.output_tokens) || 0;
|
|
41
|
-
totals.cacheReadTokens += Number(usage.cache_read_input_tokens) || 0;
|
|
42
|
-
totals.cacheCreationTokens += Number(usage.cache_creation_input_tokens) || 0;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return sawAny ? totals : null;
|
|
46
|
-
} catch {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// A counter going DOWN means the transcript restarted: the whole current
|
|
52
|
-
// total is new usage, and subtracting would produce negative spend.
|
|
53
|
-
export function usageDelta(previous, current) {
|
|
54
|
-
const reset = !previous || USAGE_KEYS.some((k) => (current[k] ?? 0) < (previous[k] ?? 0));
|
|
55
|
-
const delta = {};
|
|
56
|
-
for (const k of USAGE_KEYS) delta[k] = reset ? (current[k] ?? 0) : (current[k] ?? 0) - (previous[k] ?? 0);
|
|
57
|
-
return { delta, changed: USAGE_KEYS.some((k) => delta[k] !== 0) };
|
|
58
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// "Está no container" é a UNIÃO do layout configurado com o padrão e o legado:
|
|
2
|
-
// uma worktree antiga segue reconhecida. Root dentro da raiz é recusado, porque as
|
|
3
|
-
// listas orientadas pelo nome `worktrees/` deixariam de enxergá-lo.
|
|
4
|
-
|
|
5
|
-
import { createHash } from 'crypto';
|
|
6
|
-
import { readFileSync } from 'fs';
|
|
7
|
-
import { homedir } from 'os';
|
|
8
|
-
import { basename, isAbsolute, join, relative, resolve } from 'path';
|
|
9
|
-
|
|
10
|
-
// No leading dot: Jest escapes it inside an absolute `rootDir` glob and reports 0 tests.
|
|
11
|
-
export const WORKTREES_DIR = 'worktrees';
|
|
12
|
-
export const LEGACY_WORKTREES_DIR = '.worktrees';
|
|
13
|
-
export const WORKTREE_DIR_NAMES = [WORKTREES_DIR, LEGACY_WORKTREES_DIR];
|
|
14
|
-
|
|
15
|
-
const fwd = (p) => String(p).replace(/\\/g, '/');
|
|
16
|
-
const foldCase = (p) => (process.platform === 'win32' ? p.toLowerCase() : p);
|
|
17
|
-
|
|
18
|
-
// Só o basename colidiria entre repositórios; o hash é estável entre `R:` e `r:`.
|
|
19
|
-
export function repoKey(primaryRoot) {
|
|
20
|
-
const root = fwd(resolve(primaryRoot));
|
|
21
|
-
const hash = createHash('sha1').update(foldCase(root)).digest('hex').slice(0, 8);
|
|
22
|
-
return `${basename(root)}-${hash}`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function configuredRoot(primaryRoot, env) {
|
|
26
|
-
if (typeof env.MORPH_WORKTREE_ROOT === 'string' && env.MORPH_WORKTREE_ROOT.trim()) return env.MORPH_WORKTREE_ROOT.trim();
|
|
27
|
-
try {
|
|
28
|
-
const raw = readFileSync(join(primaryRoot, '.morph', 'config', 'config.json'), 'utf8').replace(/^/, '');
|
|
29
|
-
const value = JSON.parse(raw)?.worktree?.root;
|
|
30
|
-
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
31
|
-
} catch {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function isInside(root, path) {
|
|
37
|
-
const rel = relative(root, path);
|
|
38
|
-
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** @returns {{ dir: string|null, base?: string, warning?: string }} `dir` = `<root>/<repoKey>` */
|
|
42
|
-
export function externalContainer(primaryRoot, { env = process.env } = {}) {
|
|
43
|
-
const configured = configuredRoot(primaryRoot, env);
|
|
44
|
-
if (!configured) return { dir: null };
|
|
45
|
-
const expanded = configured === '~' || /^~[\\/]/.test(configured) ? join(homedir(), configured.slice(1)) : configured;
|
|
46
|
-
const base = resolve(primaryRoot, expanded);
|
|
47
|
-
if (isInside(resolve(primaryRoot), base)) {
|
|
48
|
-
return { dir: null, warning: `worktree.root (${configured}) fica dentro da raiz do projeto; ignorado, valem worktrees/ — as listas de exclusão se orientam por esse nome` };
|
|
49
|
-
}
|
|
50
|
-
return { dir: fwd(join(base, repoKey(primaryRoot))), base: fwd(base) };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function newWorktreesDir(primaryRoot, opts) {
|
|
54
|
-
return externalContainer(primaryRoot, opts).dir ?? `${fwd(resolve(primaryRoot))}/${WORKTREES_DIR}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function containerDirs(primaryRoot, opts) {
|
|
58
|
-
const root = fwd(resolve(primaryRoot));
|
|
59
|
-
const external = externalContainer(primaryRoot, opts).dir;
|
|
60
|
-
return [...(external ? [external] : []), ...WORKTREE_DIR_NAMES.map((name) => `${root}/${name}`)];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Ask `containerDirs` once per audit, not once per path.
|
|
64
|
-
export function isUnder(dirs, path) {
|
|
65
|
-
const target = foldCase(fwd(resolve(path)));
|
|
66
|
-
return dirs.some((dir) => target.startsWith(`${foldCase(dir)}/`));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function isInContainer(primaryRoot, path, opts) {
|
|
70
|
-
return isUnder(containerDirs(primaryRoot, opts), path);
|
|
71
|
-
}
|
package/framework/phases.json
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "5.0.0",
|
|
3
|
-
"phases": {
|
|
4
|
-
"plan": {
|
|
5
|
-
"id": "plan",
|
|
6
|
-
"index": 0,
|
|
7
|
-
"folder": "2-plan",
|
|
8
|
-
"displayName": "Plano",
|
|
9
|
-
"goals": [
|
|
10
|
-
"Understand the business problem and scan the stack (brownfield) or assume the default (greenfield)",
|
|
11
|
-
"Write plan.md — scenarios with proof, decisions and reuse",
|
|
12
|
-
"Run plan-check to produce checks.json and reach the plan gate"
|
|
13
|
-
],
|
|
14
|
-
"requiredOutputs": [
|
|
15
|
-
"plan",
|
|
16
|
-
"checks"
|
|
17
|
-
],
|
|
18
|
-
"optionalOutputs": [],
|
|
19
|
-
"pausePoints": [
|
|
20
|
-
{
|
|
21
|
-
"id": "plan",
|
|
22
|
-
"label": "Aprovação do plano"
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"skill": "morph-plan"
|
|
26
|
-
},
|
|
27
|
-
"uiux": {
|
|
28
|
-
"id": "uiux",
|
|
29
|
-
"index": 1,
|
|
30
|
-
"folder": "1-design",
|
|
31
|
-
"displayName": "Telas",
|
|
32
|
-
"optional": true,
|
|
33
|
-
"goals": [
|
|
34
|
-
"Define design system tokens and components",
|
|
35
|
-
"Produce mockups and user flows"
|
|
36
|
-
],
|
|
37
|
-
"requiredOutputs": [],
|
|
38
|
-
"optionalOutputs": [
|
|
39
|
-
"uiMockups"
|
|
40
|
-
],
|
|
41
|
-
"pausePoints": [
|
|
42
|
-
{
|
|
43
|
-
"id": "uiux",
|
|
44
|
-
"label": "Aprovação das telas"
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
"skill": "morph-uiux"
|
|
48
|
-
},
|
|
49
|
-
"implement": {
|
|
50
|
-
"id": "implement",
|
|
51
|
-
"index": 2,
|
|
52
|
-
"folder": "3-implement",
|
|
53
|
-
"displayName": "Construção",
|
|
54
|
-
"goals": [
|
|
55
|
-
"Implement the whole plan in this session, in sequence",
|
|
56
|
-
"Mark a scenario `feito` only with its evidence; close the phase on a green, unfiltered verify",
|
|
57
|
-
"One row per scenario in 3-implement/report.md — the implementation record"
|
|
58
|
-
],
|
|
59
|
-
"requiredOutputs": [],
|
|
60
|
-
"optionalOutputs": [
|
|
61
|
-
"implementReport",
|
|
62
|
-
"evidencias"
|
|
63
|
-
],
|
|
64
|
-
"pausePoints": [],
|
|
65
|
-
"skill": "morph-apply"
|
|
66
|
-
},
|
|
67
|
-
"review": {
|
|
68
|
-
"id": "review",
|
|
69
|
-
"index": 3,
|
|
70
|
-
"folder": "4-review",
|
|
71
|
-
"displayName": "Revisão",
|
|
72
|
-
"goals": [
|
|
73
|
-
"Verifier proves every scenario; reviewer (and security, when required) judge the diff at a fixed SHA",
|
|
74
|
-
"verifier.md + reviewer.md (+ security.md) with SHIP/FIX and evidence-typed blockers, then Gate 3"
|
|
75
|
-
],
|
|
76
|
-
"requiredOutputs": [
|
|
77
|
-
"verifierReport",
|
|
78
|
-
"reviewerReport"
|
|
79
|
-
],
|
|
80
|
-
"optionalOutputs": [
|
|
81
|
-
"securityReport"
|
|
82
|
-
],
|
|
83
|
-
"pausePoints": [
|
|
84
|
-
{
|
|
85
|
-
"id": "review",
|
|
86
|
-
"label": "Revisão independente"
|
|
87
|
-
}
|
|
88
|
-
],
|
|
89
|
-
"skill": "morph-apply"
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|