@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,321 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `loadTelemetryAllTrees` reads and `aggregateCost` is the one place tokens are
|
|
3
|
-
* summed: a v1 stream yields `null`, shown as unknown, never 0.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { statSync, openSync, readSync, closeSync } from 'fs';
|
|
7
|
-
import { join, resolve } from 'path';
|
|
8
|
-
import { loadTelemetryAllTrees, aggregateCost, dedupeEvents } from '../../lib/telemetry/telemetry-reader.js';
|
|
9
|
-
import { isFailedToolCall } from '../../../framework/hooks/shared/telemetry-logger.js';
|
|
10
|
-
import { VERIFY_STEP_SAY, RESULT_SAY, ROLE_NAME } from '../../../framework/hooks/shared/owner-words.js';
|
|
11
|
-
|
|
12
|
-
export const DEFAULT_KINDS = ['prompt', 'question', 'skill', 'dispatch', 'handback', 'verify', 'gate', 'failure'];
|
|
13
|
-
export const ALL_KINDS = [...DEFAULT_KINDS, 'write', 'read', 'command', 'tool'];
|
|
14
|
-
|
|
15
|
-
const GATE_COMMAND = /\bmorph-spec\s+(approve|gate-check|gate-decision|advance|finish)\b/;
|
|
16
|
-
const MORPH_PERSONA = /^morph-(.+)$/;
|
|
17
|
-
const GATE_SAY = {
|
|
18
|
-
approve: 'Registrou uma aprovação',
|
|
19
|
-
'gate-check': 'Conferiu se a aprovação pode passar',
|
|
20
|
-
'gate-decision': 'Registrou a decisão de uma aprovação',
|
|
21
|
-
advance: 'Avançou de etapa',
|
|
22
|
-
finish: 'Encerrou a feature',
|
|
23
|
-
};
|
|
24
|
-
const SHELL_TOOLS = new Set(['Bash', 'PowerShell']);
|
|
25
|
-
const SILENT_EVENTS = new Set(['ToolBatch', 'SessionUsage', 'AgentUsage']);
|
|
26
|
-
|
|
27
|
-
function shortPath(p) {
|
|
28
|
-
if (typeof p !== 'string') return null;
|
|
29
|
-
const norm = p.replace(/\\/g, '/');
|
|
30
|
-
const feat = norm.indexOf('/.morph/features/');
|
|
31
|
-
if (feat !== -1) return norm.slice(feat + '/.morph/features/'.length).split('/').slice(1).join('/');
|
|
32
|
-
const morph = norm.indexOf('/.morph/');
|
|
33
|
-
if (morph !== -1) return norm.slice(morph + 1);
|
|
34
|
-
return norm.split('/').slice(-3).join('/');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function clip(text, max = 280) {
|
|
38
|
-
if (typeof text !== 'string') return null;
|
|
39
|
-
const flat = text.trim();
|
|
40
|
-
return flat.length > max ? `${flat.slice(0, max)}…` : flat;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function nodesSummary(nodes) {
|
|
44
|
-
if (!nodes || typeof nodes !== 'object') return [];
|
|
45
|
-
return Object.entries(nodes).map(([name, n]) => {
|
|
46
|
-
const status = typeof n === 'string' ? n : n?.status ?? null;
|
|
47
|
-
return { name, status, label: `${VERIFY_STEP_SAY[name] ?? name}: ${RESULT_SAY[status] ?? status ?? '?'}` };
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function describeEvent(e) {
|
|
52
|
-
if (!e || typeof e !== 'object' || SILENT_EVENTS.has(e.event)) return null;
|
|
53
|
-
const base = {
|
|
54
|
-
id: e.eventId || `${e.ts}:${e.event}:${e.tool || ''}`,
|
|
55
|
-
ts: e.ts || null,
|
|
56
|
-
feature: e.feature || null,
|
|
57
|
-
phase: e.phase || null,
|
|
58
|
-
agent: e.agentType || null,
|
|
59
|
-
status: null,
|
|
60
|
-
detail: null,
|
|
61
|
-
refs: {},
|
|
62
|
-
};
|
|
63
|
-
const line = (kind, title, extra = {}) => ({ ...base, kind, title, ...extra, refs: { ...base.refs, ...(extra.refs || {}) } });
|
|
64
|
-
|
|
65
|
-
if (e.event === 'UserPromptSubmit') {
|
|
66
|
-
// Hand-backs, notifications and reminders arrive as a prompt wrapped in a tag;
|
|
67
|
-
// a slash command is the one tagged prompt a person typed.
|
|
68
|
-
const text = typeof e.prompt === 'string' ? e.prompt.trim() : '';
|
|
69
|
-
const command = /^<command-name>\/?([^<]+)<\/command-name>/.exec(text);
|
|
70
|
-
if (command) return line('prompt', `Você rodou /${command[1].trim()}`);
|
|
71
|
-
if (text.startsWith('<')) return null;
|
|
72
|
-
return line('prompt', 'Você escreveu', { detail: clip(text) });
|
|
73
|
-
}
|
|
74
|
-
if (e.event === 'Verify') {
|
|
75
|
-
const ok = e.status === 'pass';
|
|
76
|
-
return line('verify', `Testes automáticos ${ok ? 'passaram' : 'falharam'}`, {
|
|
77
|
-
status: ok ? 'ok' : 'fail', nodes: nodesSummary(e.nodes),
|
|
78
|
-
detail: e.persisted === false && e.reason ? `o resultado não foi gravado: ${e.reason}` : null,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (e.event !== 'PostToolUse' && e.event !== 'PostToolUseFailure') return null;
|
|
82
|
-
|
|
83
|
-
const failed = isFailedToolCall(e);
|
|
84
|
-
const tool = e.tool;
|
|
85
|
-
if (tool === 'Agent' || tool === 'Task') {
|
|
86
|
-
const m = MORPH_PERSONA.exec(e.persona || '');
|
|
87
|
-
return line('dispatch', `Chamou ${(m && ROLE_NAME[m[1]]) || e.persona || 'um ajudante'}`, {
|
|
88
|
-
detail: e.desc || clip(e.prompt, 160), refs: m ? { persona: m[1] } : {},
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (tool === 'SubagentHandback') {
|
|
92
|
-
const who = ROLE_NAME[MORPH_PERSONA.exec(e.agentType || '')?.[1]] ?? e.agentType ?? 'O ajudante';
|
|
93
|
-
return line('handback', `${who} entregou o relatório`);
|
|
94
|
-
}
|
|
95
|
-
if (tool === 'Skill') return line('skill', `Carregou a skill ${e.skill}`, { refs: { skill: e.skill } });
|
|
96
|
-
if (tool === 'AskUserQuestion') return line('question', 'Perguntou a você');
|
|
97
|
-
if (SHELL_TOOLS.has(tool)) {
|
|
98
|
-
const gate = GATE_COMMAND.exec(e.command || '');
|
|
99
|
-
if (gate) {
|
|
100
|
-
return line('gate', GATE_SAY[gate[1]], { detail: clip(e.command, 200), status: failed ? 'fail' : 'ok' });
|
|
101
|
-
}
|
|
102
|
-
if (failed) {
|
|
103
|
-
return line('failure', `Comando falhou (exit ${e.exitCode ?? '?'})`, { detail: clip(e.command, 200), status: 'fail' });
|
|
104
|
-
}
|
|
105
|
-
return line('command', tool, { detail: clip(e.command, 200) });
|
|
106
|
-
}
|
|
107
|
-
if (tool === 'Write' || tool === 'Edit') {
|
|
108
|
-
return line('write', `${tool === 'Write' ? 'Escreveu' : 'Editou'} ${shortPath(e.target)}`, { refs: { path: shortPath(e.target) } });
|
|
109
|
-
}
|
|
110
|
-
if (tool === 'Read') {
|
|
111
|
-
const what = e.kind && e.kind !== 'code' ? ` (${e.kind})` : '';
|
|
112
|
-
return line('read', `Leu ${shortPath(e.target)}${what}`, { refs: { path: shortPath(e.target) } });
|
|
113
|
-
}
|
|
114
|
-
if (failed) return line('failure', `${tool} falhou`, { status: 'fail' });
|
|
115
|
-
return line('tool', tool || e.event);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Memoized per events array: describing ~100k events once, not per page.
|
|
119
|
-
const described = new WeakMap();
|
|
120
|
-
|
|
121
|
-
function describeAll(events) {
|
|
122
|
-
if (!Array.isArray(events)) return [];
|
|
123
|
-
if (!described.has(events)) {
|
|
124
|
-
const lines = [];
|
|
125
|
-
for (const e of events) {
|
|
126
|
-
const d = describeEvent(e);
|
|
127
|
-
if (d) lines.push(d);
|
|
128
|
-
}
|
|
129
|
-
lines.sort((a, b) => (b.ts || '').localeCompare(a.ts || ''));
|
|
130
|
-
described.set(events, lines);
|
|
131
|
-
}
|
|
132
|
-
return described.get(events);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function buildFeed(events, { feature, kinds = DEFAULT_KINDS, before, limit = 100 } = {}) {
|
|
136
|
-
const wanted = new Set(kinds);
|
|
137
|
-
const lines = describeAll(events).filter((l) => wanted.has(l.kind) && (!feature || l.feature === feature));
|
|
138
|
-
const start = before ? lines.findIndex((l) => (l.ts || '') < before) : 0;
|
|
139
|
-
const page = start === -1 ? [] : lines.slice(start, start + limit);
|
|
140
|
-
const last = page[page.length - 1];
|
|
141
|
-
return { items: page, next: page.length === limit && last ? last.ts : null, total: lines.length };
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const lastByLines = new WeakMap();
|
|
145
|
-
|
|
146
|
-
export function lastActivityByFeature(events) {
|
|
147
|
-
const lines = describeAll(events);
|
|
148
|
-
if (lastByLines.has(lines)) return lastByLines.get(lines);
|
|
149
|
-
const wanted = new Set(DEFAULT_KINDS);
|
|
150
|
-
const out = {};
|
|
151
|
-
for (const line of lines) {
|
|
152
|
-
if (!line.feature) continue;
|
|
153
|
-
const entry = (out[line.feature] ||= { ts: line.ts, title: null, kind: null, status: null, titleTs: null });
|
|
154
|
-
if (entry.title === null && wanted.has(line.kind)) {
|
|
155
|
-
Object.assign(entry, { title: line.title, kind: line.kind, status: line.status, titleTs: line.ts });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
lastByLines.set(lines, out);
|
|
159
|
-
return out;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const LIVE_LOG = join('.morph', 'logs', 'events.jsonl');
|
|
163
|
-
|
|
164
|
-
function eventKey(e) {
|
|
165
|
-
return e.eventId ? `id:${e.eventId}` : `raw:${JSON.stringify(e)}`;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function fileSize(path) {
|
|
169
|
-
try { return statSync(path).size; } catch { return -1; }
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Tails each live log from the last byte read; a shrunk (rotated) or unseen log,
|
|
174
|
-
* an archive or a backup falls back to a full reload. Every update yields a NEW
|
|
175
|
-
* events array, so everything memoized per array follows the change.
|
|
176
|
-
*/
|
|
177
|
-
export function createEventStore(projectDir, { loadTrees = loadTelemetryAllTrees } = {}) {
|
|
178
|
-
let events = null;
|
|
179
|
-
let seen = new Set();
|
|
180
|
-
let offsets = new Map();
|
|
181
|
-
let pending = new Set();
|
|
182
|
-
let fullReload = true;
|
|
183
|
-
const costs = new Map();
|
|
184
|
-
|
|
185
|
-
function reload() {
|
|
186
|
-
const trees = loadTrees(projectDir);
|
|
187
|
-
const next = new Map();
|
|
188
|
-
// Sizes before the read: a line appended in between is read twice and
|
|
189
|
-
// deduplicated, never skipped.
|
|
190
|
-
for (const t of trees) {
|
|
191
|
-
if (t.tree === 'finish-backup') continue;
|
|
192
|
-
const path = join(t.path, LIVE_LOG);
|
|
193
|
-
next.set(path, Math.max(0, fileSize(path)));
|
|
194
|
-
}
|
|
195
|
-
events = dedupeEvents(trees.flatMap((t) => t.events));
|
|
196
|
-
seen = new Set(events.map(eventKey));
|
|
197
|
-
offsets = next;
|
|
198
|
-
fullReload = false;
|
|
199
|
-
pending.clear();
|
|
200
|
-
costs.clear();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function tail(path) {
|
|
204
|
-
const from = offsets.get(path);
|
|
205
|
-
const size = fileSize(path);
|
|
206
|
-
if (from === undefined || size < from) return false;
|
|
207
|
-
if (size === from) return true;
|
|
208
|
-
const fd = openSync(path, 'r');
|
|
209
|
-
let text;
|
|
210
|
-
try {
|
|
211
|
-
const buf = Buffer.alloc(size - from);
|
|
212
|
-
readSync(fd, buf, 0, buf.length, from);
|
|
213
|
-
text = buf.toString('utf8');
|
|
214
|
-
} finally {
|
|
215
|
-
closeSync(fd);
|
|
216
|
-
}
|
|
217
|
-
const end = text.lastIndexOf('\n');
|
|
218
|
-
if (end === -1) return true; // a line still being written
|
|
219
|
-
offsets.set(path, from + Buffer.byteLength(text.slice(0, end + 1), 'utf8'));
|
|
220
|
-
const fresh = [];
|
|
221
|
-
for (const raw of text.slice(0, end).split('\n')) {
|
|
222
|
-
const trimmed = raw.trim();
|
|
223
|
-
if (!trimmed) continue;
|
|
224
|
-
let e;
|
|
225
|
-
try { e = JSON.parse(trimmed); } catch { continue; }
|
|
226
|
-
if (!e || typeof e !== 'object') continue;
|
|
227
|
-
const key = eventKey(e);
|
|
228
|
-
if (seen.has(key)) continue;
|
|
229
|
-
seen.add(key);
|
|
230
|
-
fresh.push(e);
|
|
231
|
-
}
|
|
232
|
-
if (fresh.length) {
|
|
233
|
-
const last = events[events.length - 1]?.ts || '';
|
|
234
|
-
const prevLines = described.get(events);
|
|
235
|
-
const merged = events.concat(fresh);
|
|
236
|
-
events = fresh.every((e) => (e.ts || '') >= last) ? merged : dedupeEvents(merged);
|
|
237
|
-
if (prevLines) {
|
|
238
|
-
const byTsDesc = (a, b) => (b.ts || '').localeCompare(a.ts || '');
|
|
239
|
-
const added = fresh.map(describeEvent).filter(Boolean).sort(byTsDesc);
|
|
240
|
-
const top = prevLines[0]?.ts || '';
|
|
241
|
-
described.set(events, added.every((l) => (l.ts || '') >= top)
|
|
242
|
-
? [...added, ...prevLines]
|
|
243
|
-
: [...added, ...prevLines].sort(byTsDesc));
|
|
244
|
-
}
|
|
245
|
-
costs.clear();
|
|
246
|
-
}
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function current() {
|
|
251
|
-
if (fullReload || events === null) {
|
|
252
|
-
reload();
|
|
253
|
-
} else if (pending.size) {
|
|
254
|
-
const paths = [...pending];
|
|
255
|
-
pending.clear();
|
|
256
|
-
for (const p of paths) {
|
|
257
|
-
if (!tail(p)) { reload(); break; }
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return events;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return {
|
|
264
|
-
events: current,
|
|
265
|
-
changed(path) {
|
|
266
|
-
const known = path && [...offsets.keys()].find((p) => resolve(p) === resolve(path));
|
|
267
|
-
if (known) pending.add(known);
|
|
268
|
-
else fullReload = true;
|
|
269
|
-
},
|
|
270
|
-
reset() { fullReload = true; },
|
|
271
|
-
ready() { return events !== null && !fullReload; },
|
|
272
|
-
cost(feature) {
|
|
273
|
-
const all = current();
|
|
274
|
-
if (!costs.has(feature)) costs.set(feature, featureCost(all, feature));
|
|
275
|
-
return costs.get(feature);
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const SESSION_GAP_MS = 30 * 60 * 1000;
|
|
281
|
-
const SESSION_MARK_KINDS = new Set(['prompt', 'question', 'dispatch', 'handback', 'verify', 'gate', 'failure']);
|
|
282
|
-
|
|
283
|
-
// "Where was I": the feature's most recent stretch of work, split from the previous one by a 30-minute silence.
|
|
284
|
-
export function sessionMap(events, feature, { gapMs = SESSION_GAP_MS } = {}) {
|
|
285
|
-
const lines = describeAll(events).filter((l) => l.feature === feature && l.ts);
|
|
286
|
-
if (lines.length === 0) return null;
|
|
287
|
-
const session = [lines[0]];
|
|
288
|
-
for (let i = 1; i < lines.length; i++) {
|
|
289
|
-
if (Date.parse(session[session.length - 1].ts) - Date.parse(lines[i].ts) > gapMs) break;
|
|
290
|
-
session.push(lines[i]);
|
|
291
|
-
}
|
|
292
|
-
const files = new Map();
|
|
293
|
-
for (const l of session) {
|
|
294
|
-
if (l.kind === 'write' && l.refs.path) files.set(l.refs.path, (files.get(l.refs.path) || 0) + 1);
|
|
295
|
-
}
|
|
296
|
-
const lastGreen = session.find((l) => l.kind === 'verify' && l.status === 'ok');
|
|
297
|
-
const lastFailure = session.find((l) => l.status === 'fail' && (!lastGreen || l.ts > lastGreen.ts)) || null;
|
|
298
|
-
return {
|
|
299
|
-
start: session[session.length - 1].ts,
|
|
300
|
-
end: session[0].ts,
|
|
301
|
-
actions: session.length,
|
|
302
|
-
marks: session.filter((l) => SESSION_MARK_KINDS.has(l.kind)).reverse()
|
|
303
|
-
.map(({ ts, kind, status, title }) => ({ ts, kind, status, title })),
|
|
304
|
-
files: [...files].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, 5).map(([path, edits]) => ({ path, edits })),
|
|
305
|
-
lastFailure: lastFailure && { ts: lastFailure.ts, title: lastFailure.title, detail: lastFailure.detail },
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** `sessionUsage` and `agentUsage` stay `null` when the stream has no summable sample. */
|
|
310
|
-
export function featureCost(events, feature) {
|
|
311
|
-
const c = aggregateCost(events, { feature });
|
|
312
|
-
return {
|
|
313
|
-
sessionUsage: c.sessionUsage,
|
|
314
|
-
agentUsage: c.agentUsage,
|
|
315
|
-
legacyUsageSamples: c.sessionUsageLegacySamples,
|
|
316
|
-
dispatches: c.dispatches,
|
|
317
|
-
bytesTotal: c.bytesTotal,
|
|
318
|
-
bytesByKind: c.bytesByKind,
|
|
319
|
-
events: c.total,
|
|
320
|
-
};
|
|
321
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { readFileSync, existsSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { personaStandardIds, renderAgentMd, loadKnownMcpIds } from '../../utils/agents-installer.js';
|
|
4
|
-
|
|
5
|
-
const DISPATCH_LINE = /despach|dispatch|subagent_type/i;
|
|
6
|
-
|
|
7
|
-
// Only dispatch lines count: a skill that merely names a persona dispatches nobody. Two phases can
|
|
8
|
-
// share a skill, so beyond SKILL.md only the phase's own `references/{phase}.md` is read.
|
|
9
|
-
export function personaPhases(frameworkDir, agents) {
|
|
10
|
-
const result = new Map(Object.keys(agents).map((id) => [id, []]));
|
|
11
|
-
const phasesJsonPath = join(frameworkDir, 'phases.json');
|
|
12
|
-
if (!existsSync(phasesJsonPath)) return result;
|
|
13
|
-
|
|
14
|
-
const phases = Object.values(JSON.parse(readFileSync(phasesJsonPath, 'utf8')).phases || {})
|
|
15
|
-
.sort((a, b) => a.index - b.index);
|
|
16
|
-
for (const phase of phases) {
|
|
17
|
-
if (!phase.skill) continue;
|
|
18
|
-
const skillDir = join(frameworkDir, 'skills', 'core', phase.skill);
|
|
19
|
-
const sources = [join(skillDir, 'SKILL.md'), join(skillDir, 'references', `${phase.id}.md`)].filter(existsSync);
|
|
20
|
-
const dispatchLines = sources
|
|
21
|
-
.flatMap((f) => readFileSync(f, 'utf8').split(/\r?\n/))
|
|
22
|
-
.filter((l) => DISPATCH_LINE.test(l));
|
|
23
|
-
for (const id of Object.keys(agents)) {
|
|
24
|
-
const named = new RegExp(`morph-${id}(?![\\w-])`);
|
|
25
|
-
if (dispatchLines.some((l) => named.test(l))) {
|
|
26
|
-
result.get(id).push(phase.id);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function scanAgents(frameworkDir) {
|
|
34
|
-
const agentsJsonPath = join(frameworkDir, 'agents.json');
|
|
35
|
-
if (!existsSync(agentsJsonPath)) {
|
|
36
|
-
return { version: 'unknown', total: 0, list: [] };
|
|
37
|
-
}
|
|
38
|
-
const agentsJson = JSON.parse(readFileSync(agentsJsonPath, 'utf8'));
|
|
39
|
-
const phasesOf = personaPhases(frameworkDir, agentsJson.agents);
|
|
40
|
-
const knownMcpIds = loadKnownMcpIds(frameworkDir);
|
|
41
|
-
// A persona whose data the renderer refuses shows the refusal instead of hiding the persona.
|
|
42
|
-
const promptOf = (id, agent) => {
|
|
43
|
-
try { return renderAgentMd({ id, ...agent }, knownMcpIds); } catch (err) { return `<!-- não renderizou: ${err.message} -->`; }
|
|
44
|
-
};
|
|
45
|
-
const list = Object.entries(agentsJson.agents).map(([id, agent]) => ({
|
|
46
|
-
id,
|
|
47
|
-
title: agent.title,
|
|
48
|
-
icon: agent.icon || null,
|
|
49
|
-
color: agent.color || null,
|
|
50
|
-
domains: agent.domains || [],
|
|
51
|
-
keywords: agent.keywords || [],
|
|
52
|
-
standards: personaStandardIds(agent),
|
|
53
|
-
stack: agent.stack || ['*'],
|
|
54
|
-
activePhases: phasesOf.get(id),
|
|
55
|
-
persona: agent.persona || '',
|
|
56
|
-
model: agent.model || null,
|
|
57
|
-
maxTurns: agent.maxTurns ?? null,
|
|
58
|
-
tools: agent.tools || null,
|
|
59
|
-
mcp: agent.mcp || [],
|
|
60
|
-
prompt: promptOf(id, agent),
|
|
61
|
-
}));
|
|
62
|
-
return {
|
|
63
|
-
version: agentsJson.version,
|
|
64
|
-
total: agentsJson.total_agents || list.length,
|
|
65
|
-
list,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
|
|
4
|
-
function read(path) {
|
|
5
|
-
try { return readFileSync(path, 'utf8'); } catch { return null; }
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function headingsOf(content) {
|
|
9
|
-
const out = [];
|
|
10
|
-
let inFence = false;
|
|
11
|
-
for (const line of String(content).split(/\r?\n/)) {
|
|
12
|
-
if (/^\s*```/.test(line)) { inFence = !inFence; continue; }
|
|
13
|
-
if (inFence) continue;
|
|
14
|
-
const m = /^(#{1,3})\s+(.+?)\s*#*\s*$/.exec(line);
|
|
15
|
-
if (m) out.push({ depth: m[1].length, text: m[2].replace(/[`*_]/g, '') });
|
|
16
|
-
}
|
|
17
|
-
return out;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const GUIDE = [
|
|
21
|
-
{ id: 'morph', path: 'MORPH.md', title: 'Carta do harness (MORPH.md)', summary: 'Como o Claude trabalha: papéis, fases, gates, sub-agents. É a fonte única do comportamento.' },
|
|
22
|
-
{ id: 'runtime', path: 'CLAUDE.md', title: 'Instruções de runtime (CLAUDE.md)', summary: 'O que é injetado no CLAUDE.md do projeto: como começar cada sessão, regras críticas, comandos.' },
|
|
23
|
-
{ id: 'cli', path: 'docs/CLI.md', title: 'Referência do CLI', summary: 'Todos os comandos morph-spec: gates, verify, worktrees, grafo, telemetria.' },
|
|
24
|
-
{ id: 'review-checklist', path: 'evals/review-checklist.md', title: 'Checklist do Gate 3', summary: 'O que verificador, revisor e segurança procuram antes do ship: veredito SHIP/FIX e bloqueador com evidência.' },
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
export function scanDocs(frameworkDir) {
|
|
28
|
-
const guide = GUIDE.map((g) => {
|
|
29
|
-
const content = read(join(frameworkDir, ...g.path.split('/'))) || '';
|
|
30
|
-
return { ...g, content, headings: headingsOf(content).filter((h) => h.depth <= 3) };
|
|
31
|
-
}).filter((g) => g.content);
|
|
32
|
-
|
|
33
|
-
return { guide };
|
|
34
|
-
}
|