@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,397 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The root copy of a feature built in a worktree is its birth skeleton, so for an
|
|
3
|
-
* active feature the owner tree wins. Only active features ask: it spawns git.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { readFileSync, existsSync, readdirSync, statSync } from 'fs';
|
|
7
|
-
import { join, basename, isAbsolute } from 'path';
|
|
8
|
-
import { derivePhaseFrom, diskArtifactProbe, PHASE_ARTIFACTS } from '../../../framework/hooks/shared/state-reader.js';
|
|
9
|
-
import { GATE_PREREQ } from '../../core/state/gate-order.js';
|
|
10
|
-
import { implementProgress, checksPath } from '../../../framework/hooks/shared/report-progress.js';
|
|
11
|
-
import {
|
|
12
|
-
reviewReportsFromDir, requiredReviewRoles, combinedVerdict, allBlockers, checksCoverage, reviewFileName, REVIEW_ROLES,
|
|
13
|
-
} from '../../lib/review-reports.js';
|
|
14
|
-
import { resolveFeatureTree } from '../../lib/worktree/feature-truth.js';
|
|
15
|
-
import { containerDirs } from '../../../framework/hooks/shared/worktree-root.js';
|
|
16
|
-
import { canonicalPath, isInside, readMorphConfig } from '../../lib/tasks/test-runner.js';
|
|
17
|
-
import { isFinished } from './feature-status.js';
|
|
18
|
-
import {
|
|
19
|
-
featureName, scenarioLabel, scenarioTitle, retrato, GATE_ASK,
|
|
20
|
-
} from '../../../framework/hooks/shared/owner-words.js';
|
|
21
|
-
import { nextStepFor } from '../../lib/next-step.js';
|
|
22
|
-
|
|
23
|
-
export const GATES = Object.keys(GATE_PREREQ);
|
|
24
|
-
const FINISHED = new Set(['completed', 'abandoned']);
|
|
25
|
-
const FOLDER_PHASE = Object.fromEntries(PHASE_ARTIFACTS.map(([folder, phase]) => [folder, phase]));
|
|
26
|
-
const MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
27
|
-
const MAX_DEPTH = 4;
|
|
28
|
-
|
|
29
|
-
function readJson(path) {
|
|
30
|
-
try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return null; }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function subdirs(dir) {
|
|
34
|
-
try {
|
|
35
|
-
return readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
36
|
-
} catch { return []; }
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Old feature.json files stamped a gate as a bare `true`. */
|
|
40
|
-
export function normalizeGates(gates) {
|
|
41
|
-
const out = {};
|
|
42
|
-
for (const [name, value] of Object.entries(gates || {})) {
|
|
43
|
-
out[name] = value === true ? { approved: true } : (value && typeof value === 'object' ? value : { approved: false });
|
|
44
|
-
}
|
|
45
|
-
return out;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function normalizeFeature(fj) {
|
|
49
|
-
const f = fj && typeof fj === 'object' ? fj : {};
|
|
50
|
-
return { ...f, approvalGates: normalizeGates(f.approvalGates || f.approvals) };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function collectLocations(projectDir) {
|
|
54
|
-
const found = new Map();
|
|
55
|
-
const slot = (name) => {
|
|
56
|
-
if (!found.has(name)) found.set(name, { worktrees: [] });
|
|
57
|
-
return found.get(name);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const rootFeatures = join(projectDir, '.morph', 'features');
|
|
61
|
-
for (const name of subdirs(rootFeatures)) {
|
|
62
|
-
if (existsSync(join(rootFeatures, name, 'feature.json'))) slot(name).root = join(rootFeatures, name);
|
|
63
|
-
}
|
|
64
|
-
for (const container of containerDirs(projectDir)) {
|
|
65
|
-
for (const wt of subdirs(container)) {
|
|
66
|
-
const wtFeatures = join(container, wt, '.morph', 'features');
|
|
67
|
-
for (const name of subdirs(wtFeatures)) {
|
|
68
|
-
if (existsSync(join(wtFeatures, name, 'feature.json'))) slot(name).worktrees.push(join(wtFeatures, name));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const archive = join(projectDir, '.morph', 'archive');
|
|
73
|
-
for (const name of subdirs(archive)) slot(name).archive = join(archive, name);
|
|
74
|
-
return found;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function resolveLocation(projectDir, name, loc, resolveTree) {
|
|
78
|
-
const rootFj = loc.root ? readJson(join(loc.root, 'feature.json')) : null;
|
|
79
|
-
|
|
80
|
-
// An old root copy may linger; the archive holds the files.
|
|
81
|
-
const rootFinished = rootFj && (FINISHED.has(rootFj.status) || rootFj.archivedAt);
|
|
82
|
-
if (loc.archive && (!rootFj || rootFinished)) {
|
|
83
|
-
const archFj = readJson(join(loc.archive, 'feature.json'));
|
|
84
|
-
return {
|
|
85
|
-
location: 'archive',
|
|
86
|
-
dir: loc.archive,
|
|
87
|
-
feature: archFj || rootFj || { status: 'completed' },
|
|
88
|
-
ownerTree: null,
|
|
89
|
-
rootStale: false,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (rootFj && !FINISHED.has(rootFj.status)) {
|
|
94
|
-
const truth = resolveTree(name, projectDir);
|
|
95
|
-
const tree = truth?.tree;
|
|
96
|
-
if (tree && canonicalPath(tree) !== canonicalPath(projectDir)) {
|
|
97
|
-
const wtDir = join(tree, '.morph', 'features', name);
|
|
98
|
-
const wtFj = readJson(join(wtDir, 'feature.json'));
|
|
99
|
-
if (wtFj) return { location: 'worktree', dir: wtDir, feature: wtFj, ownerTree: tree, rootStale: false };
|
|
100
|
-
// The owner tree has no copy of the feature: only the root skeleton is left.
|
|
101
|
-
return { location: 'root', dir: loc.root, feature: rootFj, ownerTree: tree, rootStale: true };
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (rootFj) return { location: 'root', dir: loc.root, feature: rootFj, ownerTree: null, rootStale: false };
|
|
106
|
-
|
|
107
|
-
const wtDir = loc.worktrees[0];
|
|
108
|
-
return {
|
|
109
|
-
location: 'worktree',
|
|
110
|
-
dir: wtDir,
|
|
111
|
-
feature: readJson(join(wtDir, 'feature.json')) || {},
|
|
112
|
-
ownerTree: join(wtDir, '..', '..', '..'),
|
|
113
|
-
rootStale: false,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function readProgress(dir, progress = implementProgress(dir)) {
|
|
118
|
-
if (!progress) return null;
|
|
119
|
-
return {
|
|
120
|
-
counts: { total: progress.total, done: progress.done, blocked: progress.blocked, pending: progress.pending },
|
|
121
|
-
byId: new Map(progress.checks.map((c) => [c.id, c])),
|
|
122
|
-
full: progress,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const capitalize = (s) => (s ? s[0].toUpperCase() + s.slice(1) : s);
|
|
127
|
-
|
|
128
|
-
export function waitingOnOwner(gates, checks = []) {
|
|
129
|
-
const out = [];
|
|
130
|
-
for (const g of gates) {
|
|
131
|
-
if (!g.paused) continue;
|
|
132
|
-
out.push({ kind: 'gate', gate: g.gate, text: `${capitalize(GATE_ASK[g.gate] ?? g.gate)}${g.reason ? `: ${g.reason}` : '.'}` });
|
|
133
|
-
}
|
|
134
|
-
for (const c of checks) {
|
|
135
|
-
if (c.status !== 'bloqueado') continue;
|
|
136
|
-
out.push({ kind: 'check', id: c.id, text: c.question ? `Responder o ${scenarioLabel(c)}. ${c.question}` : `Decidir o ${scenarioLabel(c)}.` });
|
|
137
|
-
}
|
|
138
|
-
return out;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const NO_SCENARIOS = { total: 0, done: 0, blocked: 0, pending: 0 };
|
|
142
|
-
|
|
143
|
-
function gatesOf(feature) {
|
|
144
|
-
const skipped = new Set(feature.skippedPhases || []);
|
|
145
|
-
return GATES.map((gate) => {
|
|
146
|
-
const g = feature.approvalGates[gate] || { approved: false };
|
|
147
|
-
const decision = feature.gateDecisions?.[gate] || null;
|
|
148
|
-
const approved = g.approved === true;
|
|
149
|
-
return {
|
|
150
|
-
gate,
|
|
151
|
-
approved,
|
|
152
|
-
approvedBy: g.approvedBy ?? (g.auto ? 'auto' : null),
|
|
153
|
-
at: g.approvedAt || g.timestamp || null,
|
|
154
|
-
// `paused` is "waiting for the human"; a session-owned pause is work in progress.
|
|
155
|
-
paused: !approved && decision?.pause === true && decision.resolver !== 'session',
|
|
156
|
-
skipped: skipped.has(gate),
|
|
157
|
-
reason: decision?.reason ?? null,
|
|
158
|
-
since: decision?.decidedAt ?? null,
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Security counts only when its report exists: deciding it is required takes git.
|
|
164
|
-
function reviewVerdict(dir, workType, reports = reviewReportsFromDir(dir)) {
|
|
165
|
-
const present = Object.values(reports).some((r) => r.status !== 'missing');
|
|
166
|
-
if (!present) return null;
|
|
167
|
-
const required = requiredReviewRoles({ workType, securityRequired: reports.security.status !== 'missing' });
|
|
168
|
-
return { verdict: combinedVerdict(reports, required), blockers: allBlockers(reports) };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function reviewRows(reports, workType) {
|
|
172
|
-
const required = requiredReviewRoles({ workType, securityRequired: reports.security.status !== 'missing' });
|
|
173
|
-
return Object.keys(REVIEW_ROLES)
|
|
174
|
-
.filter((role) => required.includes(role) || reports[role].status !== 'missing')
|
|
175
|
-
.map((role) => {
|
|
176
|
-
const r = reports[role];
|
|
177
|
-
return {
|
|
178
|
-
role,
|
|
179
|
-
path: `4-review/${reviewFileName(role)}`,
|
|
180
|
-
status: r.status,
|
|
181
|
-
verdict: r.verdict ?? null,
|
|
182
|
-
blockers: r.blockers?.length ?? 0,
|
|
183
|
-
reviewedSha: r.reviewedSha ?? null,
|
|
184
|
-
};
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// The contract opens the evidence with "Cn:"; a later mention is context, not the target.
|
|
189
|
-
const LEADING_CHECKS_RE = /^\s*(C\d+(?:\s*(?:,|e|\/)\s*C\d+)*)\s*:/;
|
|
190
|
-
function citedChecks(b) {
|
|
191
|
-
const lead = String(b.evidence).match(LEADING_CHECKS_RE)?.[1];
|
|
192
|
-
return [...new Set((lead ?? `${b.where} ${b.evidence}`).match(/\bC\d+\b/g) ?? [])];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// A role re-run fewer times keeps its last round; verifier rows accumulate across rounds.
|
|
196
|
-
export function scoreboard(reports) {
|
|
197
|
-
const roles = Object.keys(REVIEW_ROLES).filter((role) => reports[role].status !== 'missing' && reports[role].rounds?.length);
|
|
198
|
-
const total = Math.max(0, ...roles.map((role) => reports[role].rounds.length));
|
|
199
|
-
const rows = new Map();
|
|
200
|
-
return Array.from({ length: total }, (_, i) => {
|
|
201
|
-
const byRole = {};
|
|
202
|
-
for (const role of roles) {
|
|
203
|
-
const all = reports[role].rounds;
|
|
204
|
-
const r = all[Math.min(i, all.length - 1)];
|
|
205
|
-
byRole[role] = {
|
|
206
|
-
verdict: r.verdict,
|
|
207
|
-
reviewedSha: r.reviewedSha,
|
|
208
|
-
carried: i >= all.length,
|
|
209
|
-
blockers: r.blockers.map((b) => ({ ...b, checks: citedChecks(b) })),
|
|
210
|
-
};
|
|
211
|
-
if (role === 'verifier' && i < all.length) {
|
|
212
|
-
for (const c of r.checks ?? []) rows.set(c.id, { ...c, round: i });
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return { roles: byRole, checks: [...rows.values()] };
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/** `coverage` is `null` until a verifier report exists; only PROVADO covers. */
|
|
220
|
-
export function readChecks(dir, verifier, progress = readProgress(dir)) {
|
|
221
|
-
const checks = readJson(checksPath(dir))?.checks;
|
|
222
|
-
if (!Array.isArray(checks)) return null;
|
|
223
|
-
const list = checks.filter((c) => c && c.id);
|
|
224
|
-
const rows = verifier?.checks ?? null;
|
|
225
|
-
const byId = new Map((rows ?? []).map((r) => [r.id, r]));
|
|
226
|
-
const coverage = verifier && verifier.status !== 'missing'
|
|
227
|
-
? { total: list.length, ...checksCoverage(list.map((c) => c.id), rows) }
|
|
228
|
-
: null;
|
|
229
|
-
return {
|
|
230
|
-
coverage,
|
|
231
|
-
list: list.map((c) => ({
|
|
232
|
-
id: c.id,
|
|
233
|
-
title: scenarioTitle(c),
|
|
234
|
-
label: scenarioLabel(c),
|
|
235
|
-
text: c.text ?? '',
|
|
236
|
-
question: progress?.byId.get(c.id)?.question ?? null,
|
|
237
|
-
proof: c.proof ?? null,
|
|
238
|
-
status: byId.get(c.id)?.status ?? null,
|
|
239
|
-
evidence: byId.get(c.id)?.evidence ?? null,
|
|
240
|
-
implement: progress?.byId.get(c.id)?.status ?? 'pendente',
|
|
241
|
-
})),
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function summarize(name, resolved, progress = readProgress(resolved.dir), next = null) {
|
|
246
|
-
const { location, dir, ownerTree, rootStale } = resolved;
|
|
247
|
-
const feature = normalizeFeature(resolved.feature);
|
|
248
|
-
const gates = gatesOf(feature);
|
|
249
|
-
const reviewApproved = gates.find((g) => g.gate === 'review')?.approved === true;
|
|
250
|
-
const verdict = reviewVerdict(dir, feature.workType);
|
|
251
|
-
const status = feature.status || (location === 'archive' ? 'completed' : 'draft');
|
|
252
|
-
const finished = isFinished({ status, location });
|
|
253
|
-
const phase = derivePhaseFrom(feature, diskArtifactProbe(dir));
|
|
254
|
-
const full = progress?.full ?? null;
|
|
255
|
-
return {
|
|
256
|
-
name,
|
|
257
|
-
title: featureName(name, feature, full?.summary),
|
|
258
|
-
summary: full?.summary ?? null,
|
|
259
|
-
retrato: retrato({ slug: name, feature, progress: full, phase, next, hasDesign: existsSync(join(dir, '1-design')) }),
|
|
260
|
-
waitingOnOwner: finished ? [] : waitingOnOwner(gates, full?.checks),
|
|
261
|
-
next: next ? { action: next.action, say: next.say ?? null } : null,
|
|
262
|
-
description: feature.description || null,
|
|
263
|
-
status,
|
|
264
|
-
workType: feature.workType || null,
|
|
265
|
-
location,
|
|
266
|
-
dir,
|
|
267
|
-
ownerTree,
|
|
268
|
-
rootStale,
|
|
269
|
-
phase,
|
|
270
|
-
inEvaluation: verdict !== null && !reviewApproved,
|
|
271
|
-
gates,
|
|
272
|
-
awaiting: !finished && gates.some((g) => g.paused),
|
|
273
|
-
scenarios: progress?.counts ?? NO_SCENARIOS,
|
|
274
|
-
verification: feature.verification
|
|
275
|
-
? { status: feature.verification.status ?? null, ts: feature.verification.ts ?? null }
|
|
276
|
-
: null,
|
|
277
|
-
verdict: verdict?.verdict ?? null,
|
|
278
|
-
blockers: verdict ? verdict.blockers.length : null,
|
|
279
|
-
createdAt: feature.createdAt || null,
|
|
280
|
-
updatedAt: feature.updatedAt || feature.archivedAt || feature.createdAt || null,
|
|
281
|
-
archivedAt: feature.archivedAt || null,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export function listDocuments(dir) {
|
|
286
|
-
const out = [];
|
|
287
|
-
const walk = (abs, rel, depth) => {
|
|
288
|
-
let entries;
|
|
289
|
-
try { entries = readdirSync(abs, { withFileTypes: true }); } catch { return; }
|
|
290
|
-
for (const e of entries) {
|
|
291
|
-
// A stray `.morph/` under a phase folder is a hook's misplaced log, not a document.
|
|
292
|
-
if (e.name.startsWith('.')) continue;
|
|
293
|
-
const childRel = rel ? `${rel}/${e.name}` : e.name;
|
|
294
|
-
const childAbs = join(abs, e.name);
|
|
295
|
-
if (e.isDirectory()) {
|
|
296
|
-
if (depth < MAX_DEPTH) walk(childAbs, childRel, depth + 1);
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
let st;
|
|
300
|
-
try { st = statSync(childAbs); } catch { continue; }
|
|
301
|
-
out.push({
|
|
302
|
-
path: childRel,
|
|
303
|
-
phase: FOLDER_PHASE[childRel.split('/')[0]] || null,
|
|
304
|
-
size: st.size,
|
|
305
|
-
mtime: st.mtime.toISOString(),
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
walk(dir, '', 0);
|
|
310
|
-
return out.sort((a, b) => a.path.localeCompare(b.path));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* `known` is where a previous scan found the feature, so opening it does not pay
|
|
315
|
-
* for git again. It is only trusted while its feature.json still reads.
|
|
316
|
-
*/
|
|
317
|
-
function resolveOne(projectDir, name, resolveTree, known) {
|
|
318
|
-
if (known?.dir) {
|
|
319
|
-
const fj = readJson(join(known.dir, 'feature.json'));
|
|
320
|
-
if (fj) return { location: known.location, dir: known.dir, feature: fj, ownerTree: known.ownerTree ?? null, rootStale: Boolean(known.rootStale) };
|
|
321
|
-
}
|
|
322
|
-
const loc = collectLocations(projectDir).get(name);
|
|
323
|
-
if (!loc) return null;
|
|
324
|
-
return resolveLocation(projectDir, name, loc, resolveTree);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
export function scanFeatures(projectDir, { resolveTree = resolveFeatureTree } = {}) {
|
|
328
|
-
const config = readMorphConfig(projectDir);
|
|
329
|
-
const features = [];
|
|
330
|
-
for (const [name, loc] of collectLocations(projectDir)) {
|
|
331
|
-
try {
|
|
332
|
-
features.push(summarize(name, resolveLocation(projectDir, name, loc, resolveTree)));
|
|
333
|
-
} catch { /* one unreadable feature never hides the rest */ }
|
|
334
|
-
}
|
|
335
|
-
features.sort((a, b) => (b.updatedAt || '').localeCompare(a.updatedAt || ''));
|
|
336
|
-
|
|
337
|
-
const hasState = existsSync(join(projectDir, '.morph', 'state.json'));
|
|
338
|
-
return {
|
|
339
|
-
project: {
|
|
340
|
-
name: config?.project?.name || basename(projectDir),
|
|
341
|
-
stack: config?.project?.stack || null,
|
|
342
|
-
trust: config?.trust || null,
|
|
343
|
-
dir: projectDir,
|
|
344
|
-
initialized: existsSync(join(projectDir, '.morph')),
|
|
345
|
-
// state.json with no feature.json anywhere predates the per-feature state model.
|
|
346
|
-
legacyStateOnly: hasState && features.length === 0,
|
|
347
|
-
},
|
|
348
|
-
features,
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// The next step reads the tree that holds the feature folder: <tree>/.morph/features/<name>.
|
|
353
|
-
function nextFor(name, resolved, next) {
|
|
354
|
-
if (resolved.location === 'archive' || isFinished({ status: resolved.feature?.status })) return null;
|
|
355
|
-
try { return next(name, join(resolved.dir, '..', '..', '..')); } catch { return null; }
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export function readFeatureDetail(projectDir, name, { resolveTree = resolveFeatureTree, known, next = nextStepFor } = {}) {
|
|
359
|
-
const resolved = resolveOne(projectDir, name, resolveTree, known);
|
|
360
|
-
if (!resolved) return null;
|
|
361
|
-
const progress = readProgress(resolved.dir);
|
|
362
|
-
const summary = summarize(name, resolved, progress, nextFor(name, resolved, next));
|
|
363
|
-
const feature = normalizeFeature(resolved.feature);
|
|
364
|
-
const reports = reviewReportsFromDir(resolved.dir);
|
|
365
|
-
const verdict = reviewVerdict(resolved.dir, feature.workType, reports);
|
|
366
|
-
const checks = readChecks(resolved.dir, reports.verifier, progress);
|
|
367
|
-
return {
|
|
368
|
-
...summary,
|
|
369
|
-
checksList: checks?.list ?? [],
|
|
370
|
-
checksCoverage: checks?.coverage ?? null,
|
|
371
|
-
reviews: reviewRows(reports, feature.workType),
|
|
372
|
-
rounds: scoreboard(reports),
|
|
373
|
-
gateDecisions: feature.gateDecisions || {},
|
|
374
|
-
verificationNodes: feature.verification?.nodes || null,
|
|
375
|
-
featureVerification: feature.verifications?.feature || null,
|
|
376
|
-
blockerList: verdict?.blockers ?? [],
|
|
377
|
-
documents: listDocuments(resolved.dir),
|
|
378
|
-
raw: resolved.feature,
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// Junctions and win32 case are resolved by `canonicalPath` before the check,
|
|
383
|
-
// so `..`, an absolute path or a link that leaves the feature folder are refused.
|
|
384
|
-
export function readFeatureFile(projectDir, name, relPath, { resolveTree = resolveFeatureTree, known } = {}) {
|
|
385
|
-
if (typeof relPath !== 'string' || relPath === '') return { error: 'path ausente', status: 400 };
|
|
386
|
-
if (isAbsolute(relPath) || /^[a-zA-Z]:/.test(relPath)) return { error: 'path fora da feature', status: 403 };
|
|
387
|
-
const resolved = resolveOne(projectDir, name, resolveTree, known);
|
|
388
|
-
if (!resolved) return { error: `feature "${name}" não encontrada`, status: 404 };
|
|
389
|
-
const base = canonicalPath(resolved.dir);
|
|
390
|
-
const target = canonicalPath(join(resolved.dir, ...relPath.split(/[\\/]/)));
|
|
391
|
-
if (!isInside(target, base) || target === base) return { error: 'path fora da feature', status: 403 };
|
|
392
|
-
let st;
|
|
393
|
-
try { st = statSync(target); } catch { return { error: 'arquivo não encontrado', status: 404 }; }
|
|
394
|
-
if (!st.isFile()) return { error: 'não é um arquivo', status: 400 };
|
|
395
|
-
if (st.size > MAX_FILE_BYTES) return { error: 'arquivo grande demais para exibir', status: 413 };
|
|
396
|
-
return { path: relPath, content: readFileSync(target, 'utf8'), mtime: st.mtime.toISOString() };
|
|
397
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { readFileSync, readdirSync, existsSync } from 'fs';
|
|
2
|
-
import { join, basename } from 'path';
|
|
3
|
-
import { getHookDefinitions } from '../../utils/hooks-installer.js';
|
|
4
|
-
|
|
5
|
-
function findJsFiles(dir) {
|
|
6
|
-
const results = [];
|
|
7
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
8
|
-
const fullPath = join(dir, entry.name);
|
|
9
|
-
if (entry.isDirectory()) results.push(...findJsFiles(fullPath));
|
|
10
|
-
else if (entry.name.endsWith('.js')) results.push(fullPath);
|
|
11
|
-
}
|
|
12
|
-
return results;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function extractJsDocDescription(source) {
|
|
16
|
-
const match = source.match(/\/\*\*\s*\n([\s\S]*?)\*\//);
|
|
17
|
-
if (!match) return '';
|
|
18
|
-
return match[1].split('\n').map(l => l.replace(/^\s*\*\s?/, '').trim()).filter(Boolean).join(' ');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function extractImports(source) {
|
|
22
|
-
const imports = [];
|
|
23
|
-
const regex = /import\s+.*?from\s+['"](.+?)['"]/g;
|
|
24
|
-
let m;
|
|
25
|
-
while ((m = regex.exec(source)) !== null) imports.push(m[1]);
|
|
26
|
-
return imports;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** `pre-compact` and `teammate-idle` have no MORPH hooks: those nodes render empty on purpose. */
|
|
30
|
-
const EVENT_KEYS = {
|
|
31
|
-
SessionStart: 'session-start',
|
|
32
|
-
UserPromptSubmit: 'user-prompt',
|
|
33
|
-
PreToolUse: 'pre-tool-use',
|
|
34
|
-
PostToolUse: 'post-tool-use',
|
|
35
|
-
PostToolUseFailure: 'post-tool-use',
|
|
36
|
-
PostToolBatch: 'post-tool-use',
|
|
37
|
-
Stop: 'stop',
|
|
38
|
-
SubagentStop: 'stop',
|
|
39
|
-
PreCompact: 'pre-compact',
|
|
40
|
-
WorktreeCreate: 'worktree-create',
|
|
41
|
-
WorktreeRemove: 'worktree-remove',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/** The event is not derivable from the path: every hook sits in `core/`. */
|
|
45
|
-
export function hookRegistrations(definitions = getHookDefinitions()) {
|
|
46
|
-
const byFile = new Map();
|
|
47
|
-
for (const def of definitions) {
|
|
48
|
-
const key = EVENT_KEYS[def.event];
|
|
49
|
-
if (!key) continue;
|
|
50
|
-
for (const h of def.hooks || []) {
|
|
51
|
-
const file = basename(String(h.command || '').trim());
|
|
52
|
-
if (!file.endsWith('.js')) continue;
|
|
53
|
-
// Grupos consolidados apontam para chain.js com os elos em `args`: registre
|
|
54
|
-
// cada elo, senão chain.js vira nó fantasma em todo evento.
|
|
55
|
-
const files = file === 'chain.js' && Array.isArray(h.args) && h.args.length
|
|
56
|
-
? h.args.map(a => `${a}.js`)
|
|
57
|
-
: [file];
|
|
58
|
-
for (const f of files) {
|
|
59
|
-
if (!byFile.has(f)) byFile.set(f, []);
|
|
60
|
-
const entries = byFile.get(f);
|
|
61
|
-
const matcher = def.matcher || null;
|
|
62
|
-
// PostToolUse and its Failure/Batch siblings share one Inspector column.
|
|
63
|
-
if (entries.some((e) => e.event === key && e.matcher === matcher)) continue;
|
|
64
|
-
entries.push({ event: key, rawEvent: def.event, matcher });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return byFile;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function scanHooks(frameworkDir) {
|
|
72
|
-
const hooksDir = join(frameworkDir, 'hooks', 'claude-code');
|
|
73
|
-
if (!existsSync(hooksDir)) return [];
|
|
74
|
-
|
|
75
|
-
const registrations = hookRegistrations();
|
|
76
|
-
|
|
77
|
-
return findJsFiles(hooksDir).flatMap(filePath => {
|
|
78
|
-
const source = readFileSync(filePath, 'utf8');
|
|
79
|
-
const filename = basename(filePath);
|
|
80
|
-
const base = {
|
|
81
|
-
name: basename(filePath, '.js'),
|
|
82
|
-
filename,
|
|
83
|
-
source,
|
|
84
|
-
imports: extractImports(source),
|
|
85
|
-
description: extractJsDocDescription(source),
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// One entry per (file × event): telemetry-log is registered on both
|
|
89
|
-
// PostToolUse and UserPromptSubmit, and must show under both.
|
|
90
|
-
const regs = registrations.get(filename);
|
|
91
|
-
if (!regs || regs.length === 0) {
|
|
92
|
-
return [{ ...base, event: 'unregistered', matcher: null }];
|
|
93
|
-
}
|
|
94
|
-
return regs.map(r => ({ ...base, event: r.event, rawEvent: r.rawEvent, matcher: r.matcher }));
|
|
95
|
-
});
|
|
96
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { scanAgents } from './agents-scanner.js';
|
|
2
|
-
import { scanPhases } from './phases-scanner.js';
|
|
3
|
-
import { scanHooks } from './hooks-scanner.js';
|
|
4
|
-
import { scanSkills } from './skills-scanner.js';
|
|
5
|
-
import { scanStandards } from './standards-scanner.js';
|
|
6
|
-
import { scanRules } from './rules-scanner.js';
|
|
7
|
-
import { scanDocs } from './docs-scanner.js';
|
|
8
|
-
|
|
9
|
-
export function scanAll(frameworkDir) {
|
|
10
|
-
const agents = scanAgents(frameworkDir);
|
|
11
|
-
const phases = scanPhases(frameworkDir);
|
|
12
|
-
return {
|
|
13
|
-
agents,
|
|
14
|
-
phases,
|
|
15
|
-
hooks: scanHooks(frameworkDir),
|
|
16
|
-
skills: scanSkills(frameworkDir, phases.list),
|
|
17
|
-
standards: scanStandards(frameworkDir, agents.list),
|
|
18
|
-
rules: scanRules(frameworkDir),
|
|
19
|
-
docs: scanDocs(frameworkDir),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
|
|
4
|
-
export function scanPhases(frameworkDir) {
|
|
5
|
-
const phasesJson = JSON.parse(readFileSync(join(frameworkDir, 'phases.json'), 'utf8'));
|
|
6
|
-
const list = Object.values(phasesJson.phases).map((p) => ({
|
|
7
|
-
id: p.id, index: p.index, folder: p.folder || null, displayName: p.displayName,
|
|
8
|
-
optional: p.optional || false, goals: p.goals || [], requiredOutputs: p.requiredOutputs || [],
|
|
9
|
-
optionalOutputs: p.optionalOutputs || [], recommendedMCPs: p.recommendedMCPs || [],
|
|
10
|
-
pausePoints: p.pausePoints || [], skill: p.skill || null,
|
|
11
|
-
}));
|
|
12
|
-
list.sort((a, b) => a.index - b.index);
|
|
13
|
-
return { version: phasesJson.version, list };
|
|
14
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The portfolio never waits for a cold project (a 100k-event log takes seconds):
|
|
3
|
-
* `summary` is served only from memory, the rest is read by `warmNext`.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { dirname, basename } from 'path';
|
|
7
|
-
import { createProjectApi } from './project-api.js';
|
|
8
|
-
import * as registryModule from '../../lib/projects/registry.js';
|
|
9
|
-
|
|
10
|
-
function slug(text) {
|
|
11
|
-
return String(text).toLowerCase().normalize('NFD').replace(/[̀-ͯ]/g, '')
|
|
12
|
-
.replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'projeto';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const lower = (p) => (process.platform === 'win32' ? p.toLowerCase() : p);
|
|
16
|
-
|
|
17
|
-
export function createPortfolio({ launchDir, registry = registryModule, createApi = createProjectApi }) {
|
|
18
|
-
const launchKey = registry.projectKey(launchDir);
|
|
19
|
-
const apis = new Map();
|
|
20
|
-
// While a changed project is read again, its last summary keeps showing.
|
|
21
|
-
const lastSummary = new Map();
|
|
22
|
-
|
|
23
|
-
function list() {
|
|
24
|
-
const dirs = registry.readRegistry().projects.map((p) => ({ dir: p.dir, name: p.name, source: p.source }));
|
|
25
|
-
if (!dirs.some((p) => lower(p.dir) === lower(launchKey))) {
|
|
26
|
-
dirs.unshift({ dir: launchKey, name: basename(launchKey), source: 'launch' });
|
|
27
|
-
}
|
|
28
|
-
const used = new Map();
|
|
29
|
-
return dirs.map((p) => {
|
|
30
|
-
const base = slug(basename(p.dir));
|
|
31
|
-
const n = (used.get(base) || 0) + 1;
|
|
32
|
-
used.set(base, n);
|
|
33
|
-
return { ...p, id: n === 1 ? base : `${base}-${n}`, launch: lower(p.dir) === lower(launchKey) };
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function apiFor(dir) {
|
|
38
|
-
const key = lower(dir);
|
|
39
|
-
if (!apis.has(key)) apis.set(key, createApi(dir));
|
|
40
|
-
return apis.get(key);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function byId(id) {
|
|
44
|
-
return list().find((p) => p.id === id) || null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function ownerOf(path) {
|
|
48
|
-
const p = lower(String(path).replace(/\\/g, '/'));
|
|
49
|
-
let best = null;
|
|
50
|
-
for (const proj of list()) {
|
|
51
|
-
const d = lower(proj.dir);
|
|
52
|
-
if ((p === d || p.startsWith(`${d}/`)) && (!best || d.length > best.dir.length)) best = { ...proj, dir: d };
|
|
53
|
-
}
|
|
54
|
-
return best ? list().find((x) => x.id === best.id) : null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function suggestions() {
|
|
58
|
-
const projects = list();
|
|
59
|
-
const roots = [...new Set(projects.map((p) => dirname(p.dir)))];
|
|
60
|
-
return registry.discoverProjects(roots).filter((s) => !projects.some((p) => lower(p.dir) === lower(s.dir)));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function warmNext() {
|
|
64
|
-
const next = list().find((p) => !apiFor(p.dir).ready());
|
|
65
|
-
if (!next) return null;
|
|
66
|
-
apiFor(next.dir).warm();
|
|
67
|
-
return next;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function projectsBody() {
|
|
71
|
-
return {
|
|
72
|
-
launch: list().find((p) => p.launch)?.id || null,
|
|
73
|
-
projects: list().map((p) => {
|
|
74
|
-
const api = apiFor(p.dir);
|
|
75
|
-
let summary = lastSummary.get(lower(p.dir)) || null;
|
|
76
|
-
if (api.ready()) {
|
|
77
|
-
try {
|
|
78
|
-
summary = api.summary();
|
|
79
|
-
lastSummary.set(lower(p.dir), summary);
|
|
80
|
-
} catch { /* keep the last one */ }
|
|
81
|
-
}
|
|
82
|
-
return { id: p.id, dir: p.dir, name: summary?.name || p.name, launch: p.launch, source: p.source, summary };
|
|
83
|
-
}),
|
|
84
|
-
suggestions: suggestions(),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const json = (status, body) => ({ status, body });
|
|
89
|
-
|
|
90
|
-
function handle(method, url, body = null) {
|
|
91
|
-
const u = new URL(url, 'http://local');
|
|
92
|
-
const parts = u.pathname.split('/').filter(Boolean);
|
|
93
|
-
try {
|
|
94
|
-
if (parts[0] === 'projects' && parts.length === 1) {
|
|
95
|
-
if (method === 'GET') return json(200, projectsBody());
|
|
96
|
-
if (method === 'POST') {
|
|
97
|
-
const dir = body?.dir;
|
|
98
|
-
if (typeof dir !== 'string' || !dir) return json(400, { error: 'informe o caminho do projeto' });
|
|
99
|
-
if (!registry.isMorphProject(dir)) return json(400, { error: 'esta pasta não tem .morph/config/config.json: rode morph-spec init nela primeiro' });
|
|
100
|
-
return registry.registerProject(dir, 'manual')
|
|
101
|
-
? json(200, projectsBody())
|
|
102
|
-
: json(400, { error: 'não foi possível registrar esta pasta' });
|
|
103
|
-
}
|
|
104
|
-
if (method === 'DELETE') {
|
|
105
|
-
const dir = u.searchParams.get('dir') || '';
|
|
106
|
-
registry.unregisterProject(dir);
|
|
107
|
-
lastSummary.delete(lower(registry.projectKey(dir)));
|
|
108
|
-
return json(200, projectsBody());
|
|
109
|
-
}
|
|
110
|
-
return json(405, { error: 'método não suportado' });
|
|
111
|
-
}
|
|
112
|
-
if (parts[0] === 'p' && parts.length >= 2) {
|
|
113
|
-
const project = byId(decodeURIComponent(parts[1]));
|
|
114
|
-
if (!project) return json(404, { error: `projeto "${parts[1]}" não está no portfólio` });
|
|
115
|
-
const rest = `/${parts.slice(2).join('/')}${u.search}`;
|
|
116
|
-
return apiFor(project.dir).handle(rest);
|
|
117
|
-
}
|
|
118
|
-
return json(404, { error: 'rota desconhecida' });
|
|
119
|
-
} catch (err) {
|
|
120
|
-
return json(500, { error: err?.message || String(err) });
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function invalidate(project, scope, path, event) {
|
|
125
|
-
apiFor(project.dir).invalidate(scope, path, event);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return { list, byId, ownerOf, handle, invalidate, warmNext, suggestions };
|
|
129
|
-
}
|