@polymorphism-tech/morph-spec 10.11.1 → 10.12.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/README.md +2 -2
- package/bin/morph-spec.js +2 -0
- package/claude-plugin.json +1 -1
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +4 -3
- package/framework/MORPH.md +14 -12
- package/framework/commands/morph-review.md +1 -1
- package/framework/commands/morph-status.md +2 -6
- package/framework/docs/CLI.md +21 -6
- package/framework/hooks/claude-code/core/enforce-phase-writes.js +12 -11
- package/framework/hooks/claude-code/core/gate-guard.js +19 -14
- package/framework/hooks/claude-code/core/heavy-gate.js +4 -1
- package/framework/hooks/claude-code/core/loop-detect.js +8 -7
- package/framework/hooks/claude-code/core/masked-exit.js +5 -2
- package/framework/hooks/claude-code/core/protect-spec-files.js +13 -11
- package/framework/hooks/claude-code/core/state-sync.js +20 -12
- package/framework/hooks/claude-code/core/validate-completion.js +6 -5
- package/framework/hooks/claude-code/core/worktree-context.js +47 -43
- package/framework/hooks/shared/gate-question.js +8 -0
- package/framework/hooks/shared/next-step.js +54 -23
- package/framework/hooks/shared/owner-words.js +146 -0
- package/framework/hooks/shared/report-progress.js +84 -10
- package/framework/phases.json +7 -7
- package/framework/rules/implement-report.md +8 -7
- package/framework/rules/plan-grammar.md +4 -1
- package/framework/schemas/feature.schema.json +3 -2
- 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 +6 -5
- package/framework/skills/core/morph-apply/references/hotfix.md +6 -2
- package/framework/skills/core/morph-apply/references/review.md +9 -5
- package/framework/skills/core/morph-plan/SKILL.md +5 -5
- package/framework/skills/core/morph-plan/references/interview.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +10 -6
- package/framework/templates/docs/plan.md +1 -1
- package/package.json +1 -1
- package/src/commands/e2e/e2e.js +31 -29
- package/src/commands/project/status.js +28 -184
- package/src/commands/state/advance.js +44 -20
- package/src/commands/state/approve.js +70 -59
- package/src/commands/state/archive.js +20 -15
- package/src/commands/state/auto-approval.js +25 -23
- package/src/commands/state/create.js +35 -32
- package/src/commands/state/finish.js +179 -58
- package/src/commands/state/gate-check.js +43 -31
- package/src/commands/state/gate-decision.js +18 -14
- package/src/commands/state/list.js +23 -14
- package/src/commands/state/next.js +4 -5
- package/src/commands/state/report-check.js +47 -23
- package/src/commands/validation/plan-check.js +30 -14
- package/src/commands/validation/verify.js +39 -18
- package/src/dashboard/app/components/ActivityFeed.jsx +8 -8
- package/src/dashboard/app/components/CommandPalette.jsx +1 -1
- package/src/dashboard/app/components/GatePauses.jsx +8 -8
- package/src/dashboard/app/components/PhaseRail.jsx +6 -6
- package/src/dashboard/app/components/SessionMap.jsx +7 -7
- package/src/dashboard/app/lib/format.js +6 -2
- package/src/dashboard/app/lib/phases.js +48 -16
- package/src/dashboard/app/pages/FeatureDetail.jsx +87 -59
- package/src/dashboard/app/pages/Features.jsx +18 -18
- package/src/dashboard/app/pages/Guide.jsx +4 -4
- package/src/dashboard/app/pages/PhasePipeline.jsx +7 -7
- package/src/dashboard/app/pages/Portfolio.jsx +3 -3
- package/src/dashboard/scanner/activity-scanner.js +20 -6
- package/src/dashboard/scanner/features-scanner.js +43 -8
- package/src/dashboard/scanner/project-api.js +2 -0
- package/src/dashboard/vite.config.js +2 -0
- package/src/lib/next-step.js +3 -2
- package/src/lib/plan/checks.js +30 -15
- package/src/lib/plan/critique.js +6 -4
- package/src/lib/recap/recap.js +46 -20
- package/src/lib/risk-detector.js +260 -98
- package/src/lib/view/feature-html.js +19 -25
- package/src/lib/view/feature-view.js +6 -6
- package/src/utils/audience.js +27 -0
- package/src/utils/refusal-line.js +2 -2
|
@@ -7,12 +7,20 @@ import { statSync, openSync, readSync, closeSync } from 'fs';
|
|
|
7
7
|
import { join, resolve } from 'path';
|
|
8
8
|
import { loadTelemetryAllTrees, aggregateCost, dedupeEvents } from '../../lib/telemetry/telemetry-reader.js';
|
|
9
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';
|
|
10
11
|
|
|
11
12
|
export const DEFAULT_KINDS = ['prompt', 'question', 'skill', 'dispatch', 'handback', 'verify', 'gate', 'failure'];
|
|
12
13
|
export const ALL_KINDS = [...DEFAULT_KINDS, 'write', 'read', 'command', 'tool'];
|
|
13
14
|
|
|
14
15
|
const GATE_COMMAND = /\bmorph-spec\s+(approve|gate-check|gate-decision|advance|finish)\b/;
|
|
15
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
|
+
};
|
|
16
24
|
const SHELL_TOOLS = new Set(['Bash', 'PowerShell']);
|
|
17
25
|
const SILENT_EVENTS = new Set(['ToolBatch', 'SessionUsage', 'AgentUsage']);
|
|
18
26
|
|
|
@@ -34,7 +42,10 @@ function clip(text, max = 280) {
|
|
|
34
42
|
|
|
35
43
|
function nodesSummary(nodes) {
|
|
36
44
|
if (!nodes || typeof nodes !== 'object') return [];
|
|
37
|
-
return Object.entries(nodes).map(([name, n]) =>
|
|
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
|
+
});
|
|
38
49
|
}
|
|
39
50
|
|
|
40
51
|
export function describeEvent(e) {
|
|
@@ -62,9 +73,9 @@ export function describeEvent(e) {
|
|
|
62
73
|
}
|
|
63
74
|
if (e.event === 'Verify') {
|
|
64
75
|
const ok = e.status === 'pass';
|
|
65
|
-
return line('verify', `
|
|
76
|
+
return line('verify', `Testes automáticos ${ok ? 'passaram' : 'falharam'}`, {
|
|
66
77
|
status: ok ? 'ok' : 'fail', nodes: nodesSummary(e.nodes),
|
|
67
|
-
detail: e.persisted === false && e.reason ? `não
|
|
78
|
+
detail: e.persisted === false && e.reason ? `o resultado não foi gravado: ${e.reason}` : null,
|
|
68
79
|
});
|
|
69
80
|
}
|
|
70
81
|
if (e.event !== 'PostToolUse' && e.event !== 'PostToolUseFailure') return null;
|
|
@@ -73,17 +84,20 @@ export function describeEvent(e) {
|
|
|
73
84
|
const tool = e.tool;
|
|
74
85
|
if (tool === 'Agent' || tool === 'Task') {
|
|
75
86
|
const m = MORPH_PERSONA.exec(e.persona || '');
|
|
76
|
-
return line('dispatch', `
|
|
87
|
+
return line('dispatch', `Chamou ${(m && ROLE_NAME[m[1]]) || e.persona || 'um ajudante'}`, {
|
|
77
88
|
detail: e.desc || clip(e.prompt, 160), refs: m ? { persona: m[1] } : {},
|
|
78
89
|
});
|
|
79
90
|
}
|
|
80
|
-
if (tool === 'SubagentHandback')
|
|
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
|
+
}
|
|
81
95
|
if (tool === 'Skill') return line('skill', `Carregou a skill ${e.skill}`, { refs: { skill: e.skill } });
|
|
82
96
|
if (tool === 'AskUserQuestion') return line('question', 'Perguntou a você');
|
|
83
97
|
if (SHELL_TOOLS.has(tool)) {
|
|
84
98
|
const gate = GATE_COMMAND.exec(e.command || '');
|
|
85
99
|
if (gate) {
|
|
86
|
-
return line('gate',
|
|
100
|
+
return line('gate', GATE_SAY[gate[1]], { detail: clip(e.command, 200), status: failed ? 'fail' : 'ok' });
|
|
87
101
|
}
|
|
88
102
|
if (failed) {
|
|
89
103
|
return line('failure', `Comando falhou (exit ${e.exitCode ?? '?'})`, { detail: clip(e.command, 200), status: 'fail' });
|
|
@@ -15,6 +15,10 @@ import { resolveFeatureTree } from '../../lib/worktree/feature-truth.js';
|
|
|
15
15
|
import { containerDirs } from '../../../framework/hooks/shared/worktree-root.js';
|
|
16
16
|
import { canonicalPath, isInside, readMorphConfig } from '../../lib/tasks/test-runner.js';
|
|
17
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';
|
|
18
22
|
|
|
19
23
|
export const GATES = Object.keys(GATE_PREREQ);
|
|
20
24
|
const FINISHED = new Set(['completed', 'abandoned']);
|
|
@@ -110,15 +114,30 @@ function resolveLocation(projectDir, name, loc, resolveTree) {
|
|
|
110
114
|
};
|
|
111
115
|
}
|
|
112
116
|
|
|
113
|
-
export function readProgress(dir) {
|
|
114
|
-
const progress = implementProgress(dir);
|
|
117
|
+
export function readProgress(dir, progress = implementProgress(dir)) {
|
|
115
118
|
if (!progress) return null;
|
|
116
119
|
return {
|
|
117
120
|
counts: { total: progress.total, done: progress.done, blocked: progress.blocked, pending: progress.pending },
|
|
118
121
|
byId: new Map(progress.checks.map((c) => [c.id, c])),
|
|
122
|
+
full: progress,
|
|
119
123
|
};
|
|
120
124
|
}
|
|
121
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
|
+
|
|
122
141
|
const NO_SCENARIOS = { total: 0, done: 0, blocked: 0, pending: 0 };
|
|
123
142
|
|
|
124
143
|
function gatesOf(feature) {
|
|
@@ -211,7 +230,10 @@ export function readChecks(dir, verifier, progress = readProgress(dir)) {
|
|
|
211
230
|
coverage,
|
|
212
231
|
list: list.map((c) => ({
|
|
213
232
|
id: c.id,
|
|
233
|
+
title: scenarioTitle(c),
|
|
234
|
+
label: scenarioLabel(c),
|
|
214
235
|
text: c.text ?? '',
|
|
236
|
+
question: progress?.byId.get(c.id)?.question ?? null,
|
|
215
237
|
proof: c.proof ?? null,
|
|
216
238
|
status: byId.get(c.id)?.status ?? null,
|
|
217
239
|
evidence: byId.get(c.id)?.evidence ?? null,
|
|
@@ -220,17 +242,23 @@ export function readChecks(dir, verifier, progress = readProgress(dir)) {
|
|
|
220
242
|
};
|
|
221
243
|
}
|
|
222
244
|
|
|
223
|
-
function summarize(name, resolved) {
|
|
245
|
+
function summarize(name, resolved, progress = readProgress(resolved.dir), next = null) {
|
|
224
246
|
const { location, dir, ownerTree, rootStale } = resolved;
|
|
225
247
|
const feature = normalizeFeature(resolved.feature);
|
|
226
248
|
const gates = gatesOf(feature);
|
|
227
249
|
const reviewApproved = gates.find((g) => g.gate === 'review')?.approved === true;
|
|
228
|
-
const progress = readProgress(dir);
|
|
229
250
|
const verdict = reviewVerdict(dir, feature.workType);
|
|
230
251
|
const status = feature.status || (location === 'archive' ? 'completed' : 'draft');
|
|
231
252
|
const finished = isFinished({ status, location });
|
|
253
|
+
const phase = derivePhaseFrom(feature, diskArtifactProbe(dir));
|
|
254
|
+
const full = progress?.full ?? null;
|
|
232
255
|
return {
|
|
233
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,
|
|
234
262
|
description: feature.description || null,
|
|
235
263
|
status,
|
|
236
264
|
workType: feature.workType || null,
|
|
@@ -238,7 +266,7 @@ function summarize(name, resolved) {
|
|
|
238
266
|
dir,
|
|
239
267
|
ownerTree,
|
|
240
268
|
rootStale,
|
|
241
|
-
phase
|
|
269
|
+
phase,
|
|
242
270
|
inEvaluation: verdict !== null && !reviewApproved,
|
|
243
271
|
gates,
|
|
244
272
|
awaiting: !finished && gates.some((g) => g.paused),
|
|
@@ -321,14 +349,21 @@ export function scanFeatures(projectDir, { resolveTree = resolveFeatureTree } =
|
|
|
321
349
|
};
|
|
322
350
|
}
|
|
323
351
|
|
|
324
|
-
|
|
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 } = {}) {
|
|
325
359
|
const resolved = resolveOne(projectDir, name, resolveTree, known);
|
|
326
360
|
if (!resolved) return null;
|
|
327
|
-
const
|
|
361
|
+
const progress = readProgress(resolved.dir);
|
|
362
|
+
const summary = summarize(name, resolved, progress, nextFor(name, resolved, next));
|
|
328
363
|
const feature = normalizeFeature(resolved.feature);
|
|
329
364
|
const reports = reviewReportsFromDir(resolved.dir);
|
|
330
365
|
const verdict = reviewVerdict(resolved.dir, feature.workType, reports);
|
|
331
|
-
const checks = readChecks(resolved.dir, reports.verifier);
|
|
366
|
+
const checks = readChecks(resolved.dir, reports.verifier, progress);
|
|
332
367
|
return {
|
|
333
368
|
...summary,
|
|
334
369
|
checksList: checks?.list ?? [],
|
|
@@ -113,6 +113,8 @@ export function createProjectApi(projectDir, deps = {}) {
|
|
|
113
113
|
const limit = Math.min(Number(u.searchParams.get('limit')) || 100, 500);
|
|
114
114
|
const all = events();
|
|
115
115
|
const feed = buildFeed(all, { feature, kinds, before: u.searchParams.get('before') || undefined, limit });
|
|
116
|
+
const titles = new Map(features().features.map((f) => [f.name, f.title]));
|
|
117
|
+
feed.items = (feed.items ?? []).map((i) => (i.feature ? { ...i, featureTitle: titles.get(i.feature) ?? i.feature } : i));
|
|
116
118
|
return json(200, { ...feed, kinds, cost: feature ? store.cost(feature) : null, session: feature ? sessionMap(all, feature) : null });
|
|
117
119
|
}
|
|
118
120
|
if (parts[0] === 'gates' && parts.length === 1) {
|
package/src/lib/next-step.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { collectNextSignals, decideNext } from '../../framework/hooks/shared/next-step.js';
|
|
1
|
+
import { collectNextSignals, decideNext, retratoOf } from '../../framework/hooks/shared/next-step.js';
|
|
2
2
|
import { treeMovedSince } from './git/evidence-staleness.js';
|
|
3
3
|
|
|
4
4
|
/** The CLI collector: the hook-readable facts plus verify staleness (git). Null without feature.json. */
|
|
@@ -7,5 +7,6 @@ export function nextStepFor(featureName, tree) {
|
|
|
7
7
|
if (!signals) return null;
|
|
8
8
|
signals.verificationStale = treeMovedSince(tree, signals.verification?.sha);
|
|
9
9
|
signals.affectedStale = treeMovedSince(tree, signals.affected?.sha);
|
|
10
|
-
|
|
10
|
+
const next = decideNext(signals);
|
|
11
|
+
return { ...next, phase: signals.phase, failStreak: signals.failStreak, retrato: retratoOf(signals, next) };
|
|
11
12
|
}
|
package/src/lib/plan/checks.js
CHANGED
|
@@ -3,8 +3,10 @@ import { existsSync, readFileSync } from 'fs';
|
|
|
3
3
|
import { getAbsoluteOutputPath } from '../../core/paths/output-schema.js';
|
|
4
4
|
import { frozenBody } from '../../../framework/hooks/shared/errata.js';
|
|
5
5
|
import { getFeature } from '../../../framework/hooks/shared/state-reader.js';
|
|
6
|
+
import { planNames } from '../../../framework/hooks/shared/report-progress.js';
|
|
6
7
|
import { findArtifactTerms } from './artifact-vocabulary.js';
|
|
7
8
|
import { mediaCitationError } from './media.js';
|
|
9
|
+
import { scenarioLabel, WORK_NAME } from '../../../framework/hooks/shared/owner-words.js';
|
|
8
10
|
import { PROOF_KINDS, RISK_KINDS, REWORK_RUNGS, REUSE_VERDICTS, ADR_SCOPES, SECTIONS, CONFLICTS_HEADING } from './plan-parser.js';
|
|
9
11
|
|
|
10
12
|
export const CHECKS_VERSION = 1;
|
|
@@ -83,40 +85,40 @@ export function validatePlan(plan, { workType = null, riskRules = true, text = n
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
const duplicated = (items) => items.map((i) => i.id).filter((id, i, all) => all.indexOf(id) !== i);
|
|
86
|
-
for (const
|
|
87
|
-
|
|
88
|
-
}
|
|
88
|
+
for (const id of new Set(duplicated(plan.scenarios))) errors.push(`Cenário ${id.replace(/^C/i, '')} aparece mais de uma vez no plano (${id}): cada cenário precisa de um número só dele`);
|
|
89
|
+
for (const id of new Set(duplicated(plan.adrs))) errors.push(`A decisão ${id} aparece mais de uma vez no plano: cada decisão precisa de um número só dela`);
|
|
89
90
|
|
|
90
91
|
if (plan.present.scenarios && plan.scenarios.length === 0) {
|
|
91
92
|
errors.push(`## ${SECTIONS.scenarios} sem nenhum cenário no formato "- **C1** — Dado …, quando …, então …"`);
|
|
92
93
|
}
|
|
93
94
|
for (const c of plan.scenarios) {
|
|
95
|
+
const name = scenarioLabel(c);
|
|
94
96
|
if (c.proof === null) {
|
|
95
|
-
errors.push(`${
|
|
97
|
+
errors.push(`${name} sem "prova:" (como provar: ${PROOF_KINDS.join(' | ')})${at(c.line)}`);
|
|
96
98
|
} else if (!PROOF_KINDS.includes(c.proof.toLowerCase())) {
|
|
97
|
-
errors.push(`${
|
|
99
|
+
errors.push(`${name}: "prova: ${c.proof}" não é uma das opções (${PROOF_KINDS.join(' | ')})${at(c.line)}`);
|
|
98
100
|
}
|
|
99
101
|
const proof = c.proof?.toLowerCase();
|
|
100
102
|
const risk = c.risk === null ? null : RISK_BY_FOLD.get(foldRisk(c.risk)) ?? false;
|
|
101
103
|
if (risk === false) {
|
|
102
|
-
errors.push(`${
|
|
104
|
+
errors.push(`${name}: "risco: ${c.risk}" não é uma das opções (${RISK_KINDS.join(' | ')})${at(c.line)}`);
|
|
103
105
|
} else if (riskRules && proof === 'teste' && risk === null) {
|
|
104
|
-
errors.push(`${
|
|
106
|
+
errors.push(`${name}: tem "prova: teste" mas não diz o "risco:" (${RISK_KINDS.join(' | ')}). Sem risco, a prova é "leitura" ou "e2e"${at(c.line)}`);
|
|
105
107
|
} else if (risk && proof === 'leitura') {
|
|
106
|
-
(riskRules ? errors : warnings).push(`${
|
|
108
|
+
(riskRules ? errors : warnings).push(`${name}: tem "risco: ${risk}" e é provado só lendo o código. Cenário com risco se prova rodando ("teste" ou "e2e")${at(c.line)}`);
|
|
107
109
|
}
|
|
108
110
|
if (canonicalRung(c.rung) === false) {
|
|
109
|
-
errors.push(`${
|
|
111
|
+
errors.push(`${name}: "degrau: ${c.rung}" não é uma das opções (${REWORK_RUNGS.join(' | ')})${at(c.line)}`);
|
|
110
112
|
}
|
|
111
113
|
const terms = findArtifactTerms(c.text);
|
|
112
114
|
if (terms.length > 0 && !c.artifactWhy) {
|
|
113
|
-
errors.push(`${
|
|
115
|
+
errors.push(`${name}: descreve um arquivo ou peça interna ("${terms.join(', ')}") em vez do que a pessoa vê. Reescreva como efeito observável ou justifique com "> Por que artefato:"${at(c.line)}`);
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
const isRegression = (c) => ['teste', 'e2e'].includes(c.proof?.toLowerCase()) && c.risk !== null && RISK_BY_FOLD.get(foldRisk(c.risk)) === 'regressão';
|
|
118
120
|
if (riskRules && REGRESSION_WORK_TYPES.includes(workType) && plan.scenarios.length > 0 && !plan.scenarios.some(isRegression)) {
|
|
119
|
-
errors.push(`${workType} sem cenário
|
|
121
|
+
errors.push(`${WORK_NAME[workType]} sem cenário que prove que o bug não volta (${workType}): escreva um cenário com o sintoma real, "prova: teste" e "risco: regressão"`);
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
errors.push(...defaultsErrors(plan, { workType, riskRules }, at));
|
|
@@ -138,14 +140,14 @@ export function validatePlan(plan, { workType = null, riskRules = true, text = n
|
|
|
138
140
|
for (const s of plan.sections.filter((section) => !section.key && !isSlices(section))) {
|
|
139
141
|
warnings.push(known.has(foldRisk(s.name))
|
|
140
142
|
? `## ${s.name} repetida${at(s.line)} — só a primeira é lida, o conteúdo desta se perde`
|
|
141
|
-
: `## ${s.name} não é seção do plano${at(s.line)}
|
|
143
|
+
: `## ${s.name} não é seção do plano${at(s.line)}: a conferência do plano não a lê`);
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
for (const r of plan.reuse) {
|
|
145
147
|
if (!REUSE_VERDICTS.includes(r.verdict)) {
|
|
146
148
|
errors.push(`## ${SECTIONS.reuse}: veredito "${r.verdict}" de "${r.concept}" fora de ${REUSE_VERDICTS.join(' | ')}${at(r.line)}`);
|
|
147
149
|
} else if (r.verdict === 'CRIAR' && !r.why) {
|
|
148
|
-
warnings.push(`## ${SECTIONS.reuse}: CRIAR "${r.concept}" sem why${at(r.line)}`);
|
|
150
|
+
warnings.push(`## ${SECTIONS.reuse}: CRIAR "${r.concept}" sem dizer por que não dá para reusar (why)${at(r.line)}`);
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
for (const a of plan.adrs) {
|
|
@@ -160,8 +162,9 @@ export function buildChecks(feature, text, plan) {
|
|
|
160
162
|
version: CHECKS_VERSION,
|
|
161
163
|
feature,
|
|
162
164
|
planHash: planHash(text),
|
|
165
|
+
summary: summaryOf(plan),
|
|
163
166
|
checks: plan.scenarios.map((c) => ({
|
|
164
|
-
id: c.id, text: c.text, proof: c.proof ? c.proof.toLowerCase() : null, artifactWhy: c.artifactWhy || null,
|
|
167
|
+
id: c.id, title: c.title || null, text: c.text, proof: c.proof ? c.proof.toLowerCase() : null, artifactWhy: c.artifactWhy || null,
|
|
165
168
|
rung: canonicalRung(c.rung) || null,
|
|
166
169
|
})),
|
|
167
170
|
reuse: plan.reuse.map(({ concept, verdict, target, why }) => ({ concept, verdict, target, why })),
|
|
@@ -169,6 +172,8 @@ export function buildChecks(feature, text, plan) {
|
|
|
169
172
|
};
|
|
170
173
|
}
|
|
171
174
|
|
|
175
|
+
const summaryOf = (plan) => ({ name: plan.summary?.name ?? null, after: plan.summary?.after ?? null });
|
|
176
|
+
|
|
172
177
|
/** plan-check writes the checks only with zero errors, so `fresh` also means the plan passed every rule. */
|
|
173
178
|
export function readPlanChecks(cwd, featureName) {
|
|
174
179
|
const planPath = getAbsoluteOutputPath(cwd, featureName, 'plan');
|
|
@@ -190,5 +195,15 @@ export function readPlanChecks(cwd, featureName) {
|
|
|
190
195
|
} catch {
|
|
191
196
|
return { status: 'no-plan', checks };
|
|
192
197
|
}
|
|
193
|
-
return { status: checks.planHash === planHash(plan) ? 'fresh' : 'stale', checks };
|
|
198
|
+
return { status: checks.planHash === planHash(plan) ? 'fresh' : 'stale', checks: withPlanNames(checks, plan) };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function withPlanNames(checks, planText) {
|
|
202
|
+
if (checks.summary && checks.checks.every((c) => c?.title)) return checks;
|
|
203
|
+
const { titles, summary } = planNames(planText);
|
|
204
|
+
return {
|
|
205
|
+
...checks,
|
|
206
|
+
summary: checks.summary ?? summary,
|
|
207
|
+
checks: checks.checks.map((c) => (c?.title || !titles.has(c?.id) ? c : { ...c, title: titles.get(c.id) })),
|
|
208
|
+
};
|
|
194
209
|
}
|
package/src/lib/plan/critique.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'fs';
|
|
|
2
2
|
import { getAbsoluteOutputPath } from '../../core/paths/output-schema.js';
|
|
3
3
|
import { featureGeneratesMedia } from './media.js';
|
|
4
4
|
import { SENSITIVE_LINE } from '../risk/diff-risk.js';
|
|
5
|
+
import { RUNG_SAY, scenarioLabel } from '../../../framework/hooks/shared/owner-words.js';
|
|
5
6
|
|
|
6
7
|
export const CRITIQUE_EXEMPT_WORK_TYPES = ['chore', 'hotfix'];
|
|
7
8
|
|
|
@@ -25,11 +26,12 @@ export function isSmallPlan(checks, planText = '') {
|
|
|
25
26
|
*/
|
|
26
27
|
export function critiqueByAgent(checks, planText = '') {
|
|
27
28
|
const reasons = [];
|
|
28
|
-
const rungs = (checks?.checks ?? []).filter((c) => c.rung)
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const rungs = (checks?.checks ?? []).filter((c) => c.rung)
|
|
30
|
+
.map((c) => `${scenarioLabel(c)} ${RUNG_SAY[c.rung] ?? c.rung}`);
|
|
31
|
+
reasons.push(...rungs);
|
|
32
|
+
if (featureGeneratesMedia(planText)) reasons.push('a feature gera imagem, áudio ou vídeo');
|
|
31
33
|
const sensitive = String(planText).split(/\r?\n/).find((line) => SENSITIVE_LINE.test(line));
|
|
32
|
-
if (sensitive) reasons.push(`
|
|
34
|
+
if (sensitive) reasons.push(`assunto sensível: ${sensitive.trim().replace(/^[-*\d.\s]+/, '').slice(0, 80)}`);
|
|
33
35
|
return { agent: reasons.length > 0, reasons };
|
|
34
36
|
}
|
|
35
37
|
|
package/src/lib/recap/recap.js
CHANGED
|
@@ -7,9 +7,9 @@ import { reviewReportsFromDir } from '../review-reports.js';
|
|
|
7
7
|
import { loadGraph, getFreshness } from '../graph/graph-loader.js';
|
|
8
8
|
import { parseDiff, buildDiffTree, declarationDrift } from '../graph/diff-tree.js';
|
|
9
9
|
import { detectDefaultBranch } from '../git/default-branch.js';
|
|
10
|
+
import { CHECK_RESULT_SAY, GATE_NAME, featureName, scenarioLabel, scenarioTitle } from '../../../framework/hooks/shared/owner-words.js';
|
|
10
11
|
|
|
11
12
|
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
12
|
-
const GATE_LABEL = { plan: 'Plano', uiux: 'Design', review: 'Gate 3' };
|
|
13
13
|
|
|
14
14
|
const readJson = (path) => { try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return null; } };
|
|
15
15
|
const readText = (path) => { try { return readFileSync(path, 'utf8'); } catch { return null; } };
|
|
@@ -51,16 +51,20 @@ export function buildRecap(featureDir, feature, { changes = null, now = new Date
|
|
|
51
51
|
const plan = planText ? parsePlan(planText) : null;
|
|
52
52
|
const verifier = reviewReportsFromDir(featureDir).verifier;
|
|
53
53
|
const proved = new Map((verifier?.checks ?? []).map((c) => [c.id, c]));
|
|
54
|
-
const scenarios = (plan?.scenarios ?? []).map((c) => ({ id: c.id, text: c.text, status: proved.get(c.id)?.status ?? null, evidence: proved.get(c.id)?.evidence ?? '' }));
|
|
54
|
+
const scenarios = (plan?.scenarios ?? []).map((c) => ({ id: c.id, title: scenarioTitle(c) || null, text: c.text, status: proved.get(c.id)?.status ?? null, evidence: proved.get(c.id)?.evidence ?? '' }));
|
|
55
55
|
const gates = Object.entries(fj.approvalGates ?? {})
|
|
56
|
-
.filter(([gate]) =>
|
|
56
|
+
.filter(([gate]) => GATE_NAME[gate])
|
|
57
57
|
.map(([gate, g]) => ({
|
|
58
58
|
gate, approved: g === true || g?.approved === true, approvedBy: g?.approvedBy ?? null,
|
|
59
59
|
paused: fj.gateDecisions?.[gate]?.pause === true, reason: fj.gateDecisions?.[gate]?.reason ?? null,
|
|
60
60
|
}));
|
|
61
61
|
const started = Date.parse(fj.createdAt ?? '');
|
|
62
|
+
const s = plan?.summary ?? {};
|
|
63
|
+
const summary = { name: s.name ?? null, today: s.today ?? null, after: s.after ?? null, watch: s.watch ?? [] };
|
|
62
64
|
return {
|
|
63
65
|
feature,
|
|
66
|
+
name: featureName(feature, fj, summary),
|
|
67
|
+
summary,
|
|
64
68
|
description: fj.description ?? null,
|
|
65
69
|
workType: fj.workType ?? null,
|
|
66
70
|
days: Number.isNaN(started) ? null : Math.max(0, Math.round((now - started) / 86400000)),
|
|
@@ -82,22 +86,53 @@ function flatten(tree, limit) {
|
|
|
82
86
|
return out;
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
const sentence = (t) => { const s = String(t ?? '').trim(); return s && !/[.!?…]$/.test(s) ? `${s}.` : s; };
|
|
90
|
+
const PROOF_MARK = { PROVADO: ['ok', '✓'], FALHA: ['bad', '✕'], 'NÃO PROVADO': ['warn', '!'] };
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* One scene per part of the story, in the owner's order: what changed for whoever uses it, the
|
|
94
|
+
* proof, where it paused, then the technical part. `narration` is spoken and shown as the caption.
|
|
95
|
+
*/
|
|
86
96
|
export function recapScenes(r) {
|
|
87
97
|
const scenes = [];
|
|
98
|
+
const name = r.name ?? r.feature;
|
|
99
|
+
const after = r.summary?.after ?? null;
|
|
100
|
+
const today = r.summary?.today ?? null;
|
|
101
|
+
const took = r.days !== null ? `Do início ao fim, ${r.days === 0 ? 'menos de um dia' : `${r.days} dia${r.days > 1 ? 's' : ''}`}.` : '';
|
|
88
102
|
scenes.push({
|
|
89
103
|
id: 'abertura',
|
|
90
|
-
title:
|
|
91
|
-
narration:
|
|
92
|
-
body:
|
|
104
|
+
title: name,
|
|
105
|
+
narration: [sentence(name), after ? `O que muda para quem usa: ${sentence(after)}` : sentence(r.description), took].filter(Boolean).join(' ').replace(/\s+/g, ' ').trim(),
|
|
106
|
+
body: `${today || after
|
|
107
|
+
? `<p class="lead">${today ? `<b>Hoje:</b> ${esc(today)}<br>` : ''}${after ? `<b>Depois:</b> ${esc(after)}` : ''}</p>`
|
|
108
|
+
: `<p class="lead">${esc(r.description ?? '')}</p>`}${r.days !== null ? `<p class="big">${r.days === 0 ? '< 1' : r.days} <span>dia${r.days <= 1 ? '' : 's'}</span></p>` : ''}`,
|
|
93
109
|
});
|
|
94
110
|
if (r.scenarios.length) {
|
|
95
111
|
const ok = r.scenarios.filter((c) => c.status === 'PROVADO').length;
|
|
112
|
+
const total = r.scenarios.length;
|
|
113
|
+
const judged = r.scenarios.some((c) => c.status);
|
|
114
|
+
const proof = judged
|
|
115
|
+
? `${ok} de ${total} ${total === 1 ? 'cenário conferido' : 'cenários conferidos'} pela revisão independente.`
|
|
116
|
+
: `${total} ${total === 1 ? 'cenário' : 'cenários'}, sem conferência cenário a cenário da revisão independente.`;
|
|
96
117
|
scenes.push({
|
|
97
118
|
id: 'cenarios',
|
|
98
|
-
title: '
|
|
99
|
-
narration: `${
|
|
100
|
-
body: `<ul class="checks">${r.scenarios.map((c, i) =>
|
|
119
|
+
title: 'A prova',
|
|
120
|
+
narration: `${proof} ${r.scenarios.slice(0, 4).map((c) => `${sentence(scenarioLabel(c))}`).join(' ')}`.trim(),
|
|
121
|
+
body: `<ul class="checks">${r.scenarios.map((c, i) => {
|
|
122
|
+
const [tone, glyph] = PROOF_MARK[c.status] ?? ['warn', '·'];
|
|
123
|
+
const said = CHECK_RESULT_SAY[c.status] ?? 'sem conferência';
|
|
124
|
+
return `<li style="--i:${i}"><b class="${tone}">${glyph}</b><span>${esc(scenarioLabel(c))} <small>${esc(said)}${c.evidence ? `: ${esc(c.evidence)}` : ''}</small></span></li>`;
|
|
125
|
+
}).join('')}</ul>`,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (r.gates.length) {
|
|
129
|
+
const human = r.gates.filter((g) => g.paused);
|
|
130
|
+
const approved = r.gates.filter((g) => g.approved).length;
|
|
131
|
+
scenes.push({
|
|
132
|
+
id: 'gates',
|
|
133
|
+
title: 'Por onde passou',
|
|
134
|
+
narration: `${approved} ${approved === 1 ? 'aprovação' : 'aprovações'} no caminho. ${human.length ? `Parou para você em ${human.map((g) => GATE_NAME[g.gate]).join(' e ')}.` : 'Nenhuma parada para você.'}`,
|
|
135
|
+
body: `<ol class="gates">${r.gates.map((g, i) => `<li style="--i:${i}"><b class="${g.approved ? 'ok' : 'warn'}">${g.approved ? '✓' : '·'}</b> ${esc(GATE_NAME[g.gate])}${g.approvedBy ? ` <small>por ${esc(g.approvedBy)}</small>` : ''}${g.paused && g.reason ? `<small class="why">parou porque: ${esc(g.reason)}</small>` : ''}</li>`).join('')}</ol>`,
|
|
101
136
|
});
|
|
102
137
|
}
|
|
103
138
|
if (r.transitions.length) {
|
|
@@ -123,15 +158,6 @@ export function recapScenes(r) {
|
|
|
123
158
|
: ''}`,
|
|
124
159
|
});
|
|
125
160
|
}
|
|
126
|
-
if (r.gates.length) {
|
|
127
|
-
const human = r.gates.filter((g) => g.paused);
|
|
128
|
-
scenes.push({
|
|
129
|
-
id: 'gates',
|
|
130
|
-
title: 'Por onde passou',
|
|
131
|
-
narration: `${r.gates.filter((g) => g.approved).length} gates aprovados. ${human.length ? `Pausou para você em ${human.map((g) => GATE_LABEL[g.gate]).join(' e ')}.` : 'Nenhuma pausa para você.'}`,
|
|
132
|
-
body: `<ol class="gates">${r.gates.map((g, i) => `<li style="--i:${i}"><b class="${g.approved ? 'ok' : 'warn'}">${g.approved ? '✓' : '·'}</b> ${GATE_LABEL[g.gate]}${g.approvedBy ? ` <small>por ${esc(g.approvedBy)}</small>` : ''}${g.paused && g.reason ? `<small class="why">pausou: ${esc(g.reason)}</small>` : ''}</li>`).join('')}</ol>`,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
161
|
return scenes;
|
|
136
162
|
}
|
|
137
163
|
|
|
@@ -147,7 +173,7 @@ export function renderRecapHtml(r, { audio = null } = {}) {
|
|
|
147
173
|
<head>
|
|
148
174
|
<meta charset="utf-8">
|
|
149
175
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
150
|
-
<title>Recap — ${esc(r.feature)}</title>
|
|
176
|
+
<title>Recap — ${esc(r.name ?? r.feature)}</title>
|
|
151
177
|
<style>
|
|
152
178
|
${TOKENS}:root { --bg:var(--paper); --card:var(--panel); --fg:var(--ink); --hair:var(--rule); --accent:var(--route); }
|
|
153
179
|
* { box-sizing:border-box; }
|