agjan 0.0.11 → 0.0.13
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/agjan.mjs +9 -2
- package/dist/adapters/claude-code.js +136 -0
- package/dist/adapters/copilot.js +110 -0
- package/dist/auto.js +24 -0
- package/dist/baseline.js +66 -0
- package/dist/browser.js +46 -0
- package/dist/cli.js +170 -0
- package/dist/commands/branch.js +71 -0
- package/dist/commands/check.js +424 -0
- package/dist/commands/fix.js +122 -0
- package/dist/commands/gates.js +475 -0
- package/dist/commands/lint.js +76 -0
- package/dist/commands/log.js +74 -0
- package/dist/commands/map.js +47 -0
- package/dist/commands/models.js +90 -0
- package/dist/commands/new.js +65 -0
- package/dist/commands/pr-summary.js +176 -0
- package/dist/commands/progress.js +42 -0
- package/dist/commands/report.js +105 -0
- package/dist/commands/review.js +149 -0
- package/dist/commands/setup.js +393 -0
- package/dist/commands/status.js +323 -0
- package/dist/commands/ui-test.js +39 -0
- package/dist/config.js +114 -0
- package/dist/context.js +56 -0
- package/dist/copilot-mcp.js +56 -0
- package/dist/documents.js +207 -0
- package/dist/errors.js +15 -0
- package/dist/feature.js +221 -0
- package/dist/fix.js +117 -0
- package/dist/git.js +88 -0
- package/{src/hash.mjs → dist/hash.js} +11 -14
- package/dist/hook.js +47 -0
- package/dist/json-file.js +26 -0
- package/dist/log.js +50 -0
- package/dist/managed.js +182 -0
- package/dist/mcp-config.js +76 -0
- package/dist/mcp.js +187 -0
- package/dist/plan.js +40 -0
- package/dist/progress-view.js +494 -0
- package/dist/progress.js +106 -0
- package/dist/qa.js +77 -0
- package/dist/review-policy.js +84 -0
- package/dist/review.js +534 -0
- package/dist/scope.js +34 -0
- package/dist/terminal.js +127 -0
- package/dist/test-results.js +101 -0
- package/dist/tests-map.js +29 -0
- package/dist/types.js +5 -0
- package/dist/ui.js +136 -0
- package/dist/usage.js +116 -0
- package/dist/validate.js +46 -0
- package/docs/guide.md +80 -40
- package/kit/hooks/guard.mjs +48 -119
- package/kit/skills/agjan-build/SKILL.md +6 -2
- package/kit/skills/agjan-design/SKILL.md +9 -2
- package/kit/skills/agjan-fix/SKILL.md +8 -16
- package/kit/skills/agjan-map/SKILL.md +8 -16
- package/kit/skills/agjan-spec/SKILL.md +24 -17
- package/kit/skills/agjan-verify/SKILL.md +50 -16
- package/kit/skills/qa-tester/SKILL.md +74 -0
- package/kit/templates/agents-block.md +3 -3
- package/package.json +11 -3
- package/schemas/approvals.schema.json +23 -2
- package/schemas/config.schema.json +3 -7
- package/schemas/log.schema.json +1 -1
- package/schemas/reviews.schema.json +3 -1
- package/src/adapters/claude-code.mjs +0 -121
- package/src/adapters/copilot.mjs +0 -89
- package/src/baseline.mjs +0 -66
- package/src/browser.mjs +0 -49
- package/src/cli.mjs +0 -165
- package/src/commands/branch.mjs +0 -95
- package/src/commands/check.mjs +0 -376
- package/src/commands/fix.mjs +0 -116
- package/src/commands/gates.mjs +0 -267
- package/src/commands/lint.mjs +0 -74
- package/src/commands/log.mjs +0 -60
- package/src/commands/map.mjs +0 -47
- package/src/commands/new.mjs +0 -53
- package/src/commands/pr-summary.mjs +0 -137
- package/src/commands/progress.mjs +0 -40
- package/src/commands/report.mjs +0 -115
- package/src/commands/review.mjs +0 -141
- package/src/commands/setup.mjs +0 -393
- package/src/commands/status.mjs +0 -250
- package/src/commands/ui-test.mjs +0 -38
- package/src/config.mjs +0 -122
- package/src/context.mjs +0 -67
- package/src/copilot-mcp.mjs +0 -56
- package/src/documents.mjs +0 -188
- package/src/errors.mjs +0 -16
- package/src/feature.mjs +0 -225
- package/src/fix.mjs +0 -108
- package/src/git.mjs +0 -83
- package/src/hook.mjs +0 -48
- package/src/json-file.mjs +0 -24
- package/src/log.mjs +0 -51
- package/src/managed.mjs +0 -178
- package/src/mcp-config.mjs +0 -83
- package/src/mcp.mjs +0 -147
- package/src/plan.mjs +0 -45
- package/src/progress-view.mjs +0 -466
- package/src/progress.mjs +0 -85
- package/src/review-policy.mjs +0 -91
- package/src/review.mjs +0 -416
- package/src/scope.mjs +0 -30
- package/src/terminal.mjs +0 -118
- package/src/test-results.mjs +0 -111
- package/src/tests-map.mjs +0 -29
- package/src/ui.mjs +0 -136
- package/src/usage.mjs +0 -118
- package/src/validate.mjs +0 -41
package/dist/review.js
ADDED
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { stringify as toYaml } from 'yaml';
|
|
5
|
+
import { git, changedFiles, mergeBase, resolveBase } from './git.js';
|
|
6
|
+
import { resolveArea } from './config.js';
|
|
7
|
+
import { sha256 } from './hash.js';
|
|
8
|
+
import { readJson, writeJson } from './json-file.js';
|
|
9
|
+
import { APPROVALS_FILE, FEATURES_DIR, REVIEWS_FILE, loadFeature } from './feature.js';
|
|
10
|
+
import { acTestFiles, repoFiles } from './tests-map.js';
|
|
11
|
+
import { fixRules } from './fix.js';
|
|
12
|
+
import { watchedHashes } from './baseline.js';
|
|
13
|
+
import { acResults, loadResults, resultLabel } from './test-results.js';
|
|
14
|
+
import { LOG_FILE, appendLog } from './log.js';
|
|
15
|
+
import { AgjanError } from './errors.js';
|
|
16
|
+
import { nextRound } from './review-policy.js';
|
|
17
|
+
import { designProblems, documentProblems } from './validate.js';
|
|
18
|
+
import { QA_STEP, qaApplies, qaDirs, qaProblem, qaState, qaTestFiles, qaTestsHash } from './qa.js';
|
|
19
|
+
import { buildProgress } from './progress.js';
|
|
20
|
+
export const REVIEW_MD = 'review.md';
|
|
21
|
+
const CONTEXT_DIR = '.agjan/review-contexts';
|
|
22
|
+
/** Limit for diffs inside a review context, so a huge change cannot flood the reviewer. */
|
|
23
|
+
const MAX_DIFF_BYTES = 200_000;
|
|
24
|
+
const SEVERITIES = ['blocker', 'major', 'minor'];
|
|
25
|
+
const VERDICTS = ['pass', 'pass-with-notes', 'blocked'];
|
|
26
|
+
/** The files of a unit that agjan writes itself (records): outside every review's tree hash. */
|
|
27
|
+
export function scriptOwned(slug) {
|
|
28
|
+
return new Set([APPROVALS_FILE, REVIEWS_FILE, REVIEW_MD, LOG_FILE, 'report.md', 'progress.md', 'fix.json', 'fix.md'].map((f) => `${FEATURES_DIR}/${slug}/${f}`));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* What a changed path holds now: the file's bytes, a symbolic link's target, or null when
|
|
32
|
+
* it is deleted. A folder (an untracked link to one, a nested repository) is never read.
|
|
33
|
+
*/
|
|
34
|
+
function currentContent(path) {
|
|
35
|
+
let stat;
|
|
36
|
+
try {
|
|
37
|
+
stat = lstatSync(path);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (stat.isSymbolicLink())
|
|
43
|
+
return Buffer.from(`symbolic link to ${readlinkSync(path)}`);
|
|
44
|
+
if (!stat.isFile())
|
|
45
|
+
return Buffer.from(stat.isDirectory() ? '(folder)' : '(not a regular file)');
|
|
46
|
+
return readFileSync(path);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Hash of the change as it stands: every file changed relative to the merge-base
|
|
50
|
+
* (committed, staged, unstaged, untracked) with its current content, except the
|
|
51
|
+
* feature's script-owned files. Any write to the working tree changes it.
|
|
52
|
+
*/
|
|
53
|
+
export function treeHash(root, config, slug, except = []) {
|
|
54
|
+
const skip = scriptOwned(slug);
|
|
55
|
+
const hash = createHash('sha256');
|
|
56
|
+
for (const file of changedFiles(root, resolveBase(root, config.git?.base))) {
|
|
57
|
+
if (skip.has(file) || file.startsWith('.agjan/') || except.some((dir) => file.startsWith(dir)))
|
|
58
|
+
continue;
|
|
59
|
+
const content = currentContent(join(root, file));
|
|
60
|
+
hash.update(file).update('\0');
|
|
61
|
+
hash.update(content ? createHash('sha256').update(content).digest('hex') : 'deleted').update('\0');
|
|
62
|
+
}
|
|
63
|
+
return `sha256:${hash.digest('hex')}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parses a review step. Features: spec, design, design:light, verify, build:<area>,
|
|
67
|
+
* build:<task>. A fix has only the step fix, a map run only map.
|
|
68
|
+
*/
|
|
69
|
+
export function parseStep(step, feature, config) {
|
|
70
|
+
if (feature.kind === 'fix' || feature.kind === 'map') {
|
|
71
|
+
if (step !== feature.kind)
|
|
72
|
+
throw new AgjanError(`a ${feature.kind} record has only the review step '${feature.kind}'`);
|
|
73
|
+
return { step, kind: step };
|
|
74
|
+
}
|
|
75
|
+
if (step === 'fix' || step === 'map')
|
|
76
|
+
throw new AgjanError(`'${step}' reviews belong to a ${step} record, not to a feature`);
|
|
77
|
+
if (['spec', 'design', 'design:light', 'verify', QA_STEP].includes(step))
|
|
78
|
+
return { step, kind: step };
|
|
79
|
+
const match = /^build:(.+)$/.exec(step ?? '');
|
|
80
|
+
if (!match)
|
|
81
|
+
throw new AgjanError(`unknown review step '${step}'; use spec, design, design:light, build:<area>, build:<task> or verify`);
|
|
82
|
+
const tasks = feature.tasks?.parsed.tasks ?? [];
|
|
83
|
+
const byTask = tasks.filter((t) => t.id === match[1]);
|
|
84
|
+
if (byTask.length)
|
|
85
|
+
return { step, kind: 'build', tasks: byTask };
|
|
86
|
+
const area = resolveArea(config, match[1]);
|
|
87
|
+
const byArea = area ? tasks.filter((t) => resolveArea(config, t.area)?.id === area.id) : [];
|
|
88
|
+
if (byArea.length === 0)
|
|
89
|
+
throw new AgjanError(`'${match[1]}' is neither a task id nor an area with tasks in tasks.md`);
|
|
90
|
+
return { step: `build:${area.name}`, kind: 'build', tasks: byArea };
|
|
91
|
+
}
|
|
92
|
+
function capped(text) {
|
|
93
|
+
if (Buffer.byteLength(text) <= MAX_DIFF_BYTES)
|
|
94
|
+
return text;
|
|
95
|
+
return `${text.slice(0, MAX_DIFF_BYTES)}\n\n[diff truncated at ${MAX_DIFF_BYTES} bytes; read the files directly]\n`;
|
|
96
|
+
}
|
|
97
|
+
/** Diff of the given path patterns against the merge-base, untracked files included. */
|
|
98
|
+
function diffOf(root, base, patterns) {
|
|
99
|
+
if (patterns.length === 0)
|
|
100
|
+
return '(no changes)\n';
|
|
101
|
+
const from = mergeBase(root, base) ?? 'HEAD';
|
|
102
|
+
const specs = patterns.map((p) => `:(glob)${p.endsWith('/') ? `${p}**` : p}`);
|
|
103
|
+
let out = git(root, ['diff', '--no-color', '--no-ext-diff', from, '--', ...specs], { allowFail: true }) ?? '';
|
|
104
|
+
const untracked = git(root, ['ls-files', '--others', '--exclude-standard', '--', ...specs]).split('\n').filter(Boolean);
|
|
105
|
+
for (const file of untracked) {
|
|
106
|
+
out += `\n--- new file: ${file}\n${currentContent(join(root, file))?.toString('utf8') ?? '(deleted)'}`;
|
|
107
|
+
}
|
|
108
|
+
return capped(out || '(no changes)\n');
|
|
109
|
+
}
|
|
110
|
+
function section(title, body) {
|
|
111
|
+
return `## ${title}\n\n${body.trimEnd()}\n`;
|
|
112
|
+
}
|
|
113
|
+
function fence(text, lang = '') {
|
|
114
|
+
const ticks = text.includes('```') ? '````' : '```';
|
|
115
|
+
return `${ticks}${lang}\n${text.trimEnd()}\n${ticks}`;
|
|
116
|
+
}
|
|
117
|
+
function acsText(feature, ids) {
|
|
118
|
+
const spec = feature.spec;
|
|
119
|
+
return spec.parsed.acs
|
|
120
|
+
.filter((ac) => !ids || ids.has(ac.id))
|
|
121
|
+
.map((ac) => {
|
|
122
|
+
const lines = spec.text.split(/\r?\n/);
|
|
123
|
+
const start = ac.line - 1;
|
|
124
|
+
let end = lines.findIndex((l, i) => i > start && /^#{2,3} /.test(l));
|
|
125
|
+
if (end === -1)
|
|
126
|
+
end = lines.length;
|
|
127
|
+
return lines.slice(start, end).join('\n').trim();
|
|
128
|
+
})
|
|
129
|
+
.join('\n\n');
|
|
130
|
+
}
|
|
131
|
+
function reviewHistory(feature) {
|
|
132
|
+
if (feature.reviews.records.length === 0)
|
|
133
|
+
return '(none)';
|
|
134
|
+
return feature.reviews.records
|
|
135
|
+
.map((r) => `- ${r.id} ${r.step} round ${r.round}: ${r.verdict}, ${r.findings?.length ?? 0} finding(s)`)
|
|
136
|
+
.join('\n');
|
|
137
|
+
}
|
|
138
|
+
function openFindings(feature, steps) {
|
|
139
|
+
const open = feature.findings.filter((f) => f.status === 'open' && (!steps || steps.includes(f.step)));
|
|
140
|
+
if (open.length === 0)
|
|
141
|
+
return '(none)';
|
|
142
|
+
return open.map((f) => `- ${f.id} [${f.severity}] ${f.file ? `${f.file}${f.line ? `:${f.line}` : ''} ` : ''}${f.issue}`).join('\n');
|
|
143
|
+
}
|
|
144
|
+
const CHECKLISTS = {
|
|
145
|
+
spec: 'No unrequested technical decisions. Technical questions listed under Open technical questions are expected and are not decisions: never ask to remove that section; Design answers them. Every AC testable and complete; an AC without a Verification line is automated, which is the default and not a finding; flag only ACs that cannot be tested automatically but are not marked manual. Non-functional and authorization requirements considered. Scope consistent.',
|
|
146
|
+
'design:light': 'The spec checks, plus: light mode is justified (nothing new: no new service, application, BTP service, authorization or deployment change). Tasks: paths plausible and including where the tests of their ACs go, every AC covered. In a Fiori elements app, creating or editing records needs a draft-enabled entity.',
|
|
147
|
+
design: 'Every AC covered by tasks. Areas and app types justified with alternatives. Open technical questions answered. Every rule of the spec\'s Authorization section has a decision on how it is enforced. Every task\'s paths include where the tests of its ACs go (tests of Fiori annotations usually live in the CAP tests); a task covers an AC only if its paths include every file needed to implement and test it. The chosen service shape supports every interaction the ACs describe in the UI: in a Fiori elements app, creating or editing records needs a draft-enabled entity (@odata.draft.enabled), so "no draft" for such an app is a blocker. Nothing beyond the spec.',
|
|
148
|
+
build: 'Each covered AC is met by the diff. Tests exist and carry the AC id in their names. An AC that a user does on a page of a Fiori app (create a record, choose an action) has a UI test (Playwright, test/ui) besides the service tests; UI tests that agjan ui-test skipped because no browser can start here are not a finding. Project conventions. The spec\'s Authorization section, rule by rule: each role and permission is enforced in the code (for example @requires or @restrict on every entity and operation it covers; anything without them is open to every user, anonymous requests included) and covered by tests, including a negative test for a user without the role and for an anonymous request, and for every where condition a test with a user who has the role but whom the condition excludes. The service has a service-level @requires, so nothing it exposes (code lists, auto-exposed entities) is open. Security basics (authorization, input validation, no secrets; test or mocked users and other development settings only in a development profile, never active in production). Scope is checked by agjan: a file under the allowed paths (task, implicit or amended) is in scope; do not report it as out of scope.',
|
|
149
|
+
fix: 'The change does exactly what the fix description says and nothing else. It is correct and complete. A test covers it where practical. No hidden scope: anything that changes behaviour beyond the description, or needs a business decision, is a blocker (it belongs in /agjan-spec).',
|
|
150
|
+
map: 'Every claim in project.md is traceable to the files it points to. Services, applications and BTP services are complete. The do-not-touch list is plausible and uses real paths. Short: one to two pages, pointers instead of copies.',
|
|
151
|
+
verify: 'Cross-task consistency. Every AC covered by a passing test or marked manual. When the context has a QA section: the QA round passed and its tests (test/qa, test/ui/qa) are part of the change; the writer fixed the code for QA blockers, never the QA tests. UI tests that agjan ui-test skipped because no browser can start here are not a finding: the final message names those ACs for the human. When the project records no test results (no results file in the context), judge coverage by the tests that carry the AC ids: missing recorded results is a project setting for the human, not a finding. The spec\'s Authorization section, rule by rule: each role and permission is enforced in the code (for example @requires or @restrict on every entity and operation it covers; anything without them is open to every user, anonymous requests included) and covered by tests, including a negative test for a user without the role and for an anonymous request. Scope is checked by agjan: a file under the allowed paths (task, implicit or amended) is in scope; do not report it as out of scope. The baseline (project.md) updated if a service, application or BTP service was added, and its section "Run locally" (start command, app URLs, test users and roles) matches the change. Do not re-review each task.',
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* What the given tasks may change (design 6.5), as `agjan check` judges it: the task paths,
|
|
155
|
+
* the implicit paths of their areas (lockfiles, i18n, fixtures, package.json), and approved
|
|
156
|
+
* amendments. The reviewer sees the same scope as the script.
|
|
157
|
+
*/
|
|
158
|
+
function scopeOf(config, feature, tasks) {
|
|
159
|
+
const taskIds = new Set(tasks.map((t) => t.id));
|
|
160
|
+
const own = tasks.flatMap((t) => t.paths);
|
|
161
|
+
const areas = [...new Set(tasks.map((t) => resolveArea(config, t.area ?? '')?.name).filter((a) => Boolean(a)))];
|
|
162
|
+
const implicit = [...new Set(areas.flatMap((a) => config.scope.implicit[a] ?? []))];
|
|
163
|
+
const amended = feature.amendments.filter((a) => a.status === 'approved' && taskIds.has(a.task)).flatMap((a) => a.paths);
|
|
164
|
+
return { own, implicit, amended, all: [...new Set([...own, ...implicit, ...amended])] };
|
|
165
|
+
}
|
|
166
|
+
function scopeText(scope) {
|
|
167
|
+
const list = (items) => (items.length ? items.map((p) => `\`${p}\``).join(', ') : '(none)');
|
|
168
|
+
return [
|
|
169
|
+
`- Task paths: ${list(scope.own)}`,
|
|
170
|
+
`- Implicit for the tasks' areas: ${list(scope.implicit)}`,
|
|
171
|
+
`- Approved amendments: ${list(scope.amended)}`,
|
|
172
|
+
].join('\n');
|
|
173
|
+
}
|
|
174
|
+
/** A document's repository path, as findings should cite it. */
|
|
175
|
+
function docPath(feature, name) {
|
|
176
|
+
return `${FEATURES_DIR}/${feature.slug}/${name}`;
|
|
177
|
+
}
|
|
178
|
+
/** Builds the reviewer's input for a step: the only material the reviewer should read. */
|
|
179
|
+
export function buildContextText(root, config, feature, parsed) {
|
|
180
|
+
const base = resolveBase(root, config.git?.base);
|
|
181
|
+
const parts = [
|
|
182
|
+
`# Review context: ${feature.slug} (${feature.key}), step ${parsed.step}`,
|
|
183
|
+
'',
|
|
184
|
+
`The unit's folder is \`${FEATURES_DIR}/${feature.slug}/\`. Cite files with the repository paths used below.`,
|
|
185
|
+
'',
|
|
186
|
+
];
|
|
187
|
+
parts.push(section('Checklist', CHECKLISTS[parsed.kind]));
|
|
188
|
+
const baseline = join(root, FEATURES_DIR, 'project.md');
|
|
189
|
+
const baselineText = existsSync(baseline) ? readFileSync(baseline, 'utf8') : null;
|
|
190
|
+
if (parsed.kind === 'fix') {
|
|
191
|
+
const description = readJson(join(feature.dir, 'fix.json'))?.what ?? '(no description)';
|
|
192
|
+
const rules = fixRules(root, config);
|
|
193
|
+
const files = rules.files.map((f) => `- ${f.path} +${f.added}/-${f.deleted}${f.isNew ? ' (new)' : ''}`).join('\n') || '(none)';
|
|
194
|
+
const verdict = rules.problems.length ? rules.problems.map((p) => `- ${p}`).join('\n') : 'within the limits';
|
|
195
|
+
parts.push(section('Fix description', description));
|
|
196
|
+
parts.push(section('Fast-path rules', `${rules.total} changed lines (limit ${rules.limits.max_total}). ${verdict}\n\n${files}`));
|
|
197
|
+
parts.push(section('Diff', fence(diffOf(root, base, rules.files.map((f) => f.path)), 'diff')));
|
|
198
|
+
}
|
|
199
|
+
else if (parsed.kind === 'map') {
|
|
200
|
+
if (!baselineText)
|
|
201
|
+
throw new AgjanError(`${FEATURES_DIR}/project.md does not exist; write it first`);
|
|
202
|
+
const watched = Object.keys(watchedHashes(root, config));
|
|
203
|
+
parts.push(section('Watched files (models, services, apps, deployment)', watched.map((f) => `- ${f}`).join('\n') || '(none)'));
|
|
204
|
+
const files = repoFiles(root).filter((f) => !f.startsWith(`${FEATURES_DIR}/`));
|
|
205
|
+
parts.push(section('Repository files', `${files.slice(0, 300).map((f) => `- ${f}`).join('\n')}${files.length > 300 ? `\n- … ${files.length - 300} more` : ''}`));
|
|
206
|
+
}
|
|
207
|
+
else if (!feature.spec) {
|
|
208
|
+
throw new AgjanError('spec.md does not exist');
|
|
209
|
+
}
|
|
210
|
+
else if (parsed.kind === 'spec') {
|
|
211
|
+
parts.push(section(docPath(feature, 'spec.md'), fence(feature.spec.text, 'md')));
|
|
212
|
+
}
|
|
213
|
+
else if (parsed.kind === 'design' || parsed.kind === 'design:light') {
|
|
214
|
+
if (!feature.design || !feature.tasks)
|
|
215
|
+
throw new AgjanError('design.md and tasks.md must exist for a design review');
|
|
216
|
+
parts.push(section(docPath(feature, 'spec.md'), fence(feature.spec.text, 'md')));
|
|
217
|
+
parts.push(section(docPath(feature, 'design.md'), fence(feature.design.text, 'md')));
|
|
218
|
+
parts.push(section(docPath(feature, 'tasks.md'), fence(feature.tasks.text, 'md')));
|
|
219
|
+
}
|
|
220
|
+
else if (parsed.kind === 'build') {
|
|
221
|
+
const tasks = parsed.tasks ?? [];
|
|
222
|
+
const ids = new Set(tasks.flatMap((t) => t.covers));
|
|
223
|
+
const scope = scopeOf(config, feature, tasks);
|
|
224
|
+
parts.push(section('Tasks', fence(toYaml(tasks.map(({ verify, ...t }) => (verify ? { ...t, verify } : t))), 'yaml')));
|
|
225
|
+
parts.push(section('Allowed paths (scope, enforced by agjan check)', scopeText(scope)));
|
|
226
|
+
parts.push(section('Acceptance criteria covered', acsText(feature, ids)));
|
|
227
|
+
parts.push(section('Diff of the allowed paths', fence(diffOf(root, base, scope.all), 'diff')));
|
|
228
|
+
}
|
|
229
|
+
else if (parsed.kind === 'verify') {
|
|
230
|
+
if (!feature.design || !feature.tasks)
|
|
231
|
+
throw new AgjanError('design.md and tasks.md must exist for the verify review');
|
|
232
|
+
const areaNames = [...new Set(feature.tasks.parsed.tasks.map((t) => resolveArea(config, t.area)?.name).filter((a) => Boolean(a)))];
|
|
233
|
+
const tests = acTestFiles(root, config, areaNames, feature.key);
|
|
234
|
+
const loaded = loadResults(root, config, areaNames);
|
|
235
|
+
const results = loaded.files.length ? acResults(loaded, feature.key) : null;
|
|
236
|
+
const coverage = feature.spec.parsed.acs
|
|
237
|
+
.map((ac) => `| ${ac.id} | ${ac.verification} | ${[...(tests.get(ac.id) ?? [])].join(', ') || '-'} | ${results ? resultLabel(results.get(ac.id)) : 'not recorded'} |`)
|
|
238
|
+
.join('\n');
|
|
239
|
+
const unrecorded = results
|
|
240
|
+
? ''
|
|
241
|
+
: '\n\nThis project records no test results (no `verify.<area>.results` in agjan.config.json, a setting for the human). Coverage here means a test names the AC; missing results are not a finding.';
|
|
242
|
+
const changed = changedFiles(root, base).filter((f) => !scriptOwned(feature.slug).has(f) && !f.startsWith('.agjan/'));
|
|
243
|
+
parts.push(section('Acceptance criteria', acsText(feature)));
|
|
244
|
+
parts.push(section('AC coverage (test files mentioning the AC id, and test results)', `| AC | verification | test files | result |\n|---|---|---|---|\n${coverage}${unrecorded}`));
|
|
245
|
+
parts.push(section(docPath(feature, 'design.md'), fence(feature.design.text, 'md')));
|
|
246
|
+
parts.push(section(docPath(feature, 'tasks.md'), fence(feature.tasks.text, 'md')));
|
|
247
|
+
parts.push(section('Allowed paths (scope, enforced by agjan check)', scopeText(scopeOf(config, feature, feature.tasks.parsed.tasks))));
|
|
248
|
+
parts.push(section('Changed files', changed.map((f) => `- ${f}`).join('\n') || '(none)'));
|
|
249
|
+
const qa = qaState(root, config, feature);
|
|
250
|
+
if (qa.state !== 'off') {
|
|
251
|
+
const tests = qaTestFiles(root, feature.slug);
|
|
252
|
+
parts.push(section('QA (tests written from the spec by the QA agent)', qa.record
|
|
253
|
+
? `${qa.record.id} round ${qa.record.round}: ${qa.record.verdict} (${qa.state}); ${tests.length} QA test file(s):\n${tests.map((f) => `- ${f}`).join('\n')}`
|
|
254
|
+
: 'not run'));
|
|
255
|
+
}
|
|
256
|
+
parts.push(section('Full diff', fence(diffOf(root, base, changed), 'diff')));
|
|
257
|
+
}
|
|
258
|
+
if (baselineText && parsed.kind !== 'build' && parsed.kind !== 'fix')
|
|
259
|
+
parts.push(section('Baseline (docs/agjan/project.md)', fence(baselineText, 'md')));
|
|
260
|
+
parts.push(section('Earlier reviews', reviewHistory(feature)));
|
|
261
|
+
parts.push(section('Open findings', openFindings(feature)));
|
|
262
|
+
parts.push(section('How to record your result', 'Call review_record with this context_id, a verdict (pass, pass-with-notes, blocked), your findings ' +
|
|
263
|
+
'(severity blocker, major or minor; file and line where possible, with the repository paths used in this context; ' +
|
|
264
|
+
'issue; suggestion; evidence for a claim that an API, annotation or syntax is wrong), and in `resolves` the ids ' +
|
|
265
|
+
'of open findings that this change has fixed. A blocker finding requires the verdict blocked.'));
|
|
266
|
+
return parts.join('\n');
|
|
267
|
+
}
|
|
268
|
+
/** review_context: builds the context, stores its metadata, returns id and text. */
|
|
269
|
+
/**
|
|
270
|
+
* A new round of a step is pointless when nothing changed since its last round raised
|
|
271
|
+
* findings: the reviewer would see the same files. It happens when a writer starts the
|
|
272
|
+
* review before (or in parallel with) its edits, and it costs one of the step's rounds.
|
|
273
|
+
*/
|
|
274
|
+
function unchangedSinceFindings(feature, step, tree) {
|
|
275
|
+
const last = feature.reviews.records.filter((r) => r.step === step).at(-1);
|
|
276
|
+
if (!last || last.verdict === 'pass' || last.tree_hash !== tree)
|
|
277
|
+
return;
|
|
278
|
+
throw new AgjanError(`nothing changed since ${last.id} (${last.verdict}); address its findings and save the changes before the next round. ` +
|
|
279
|
+
'A finding that needs no change is accepted by the human (agjan accept), not reviewed again.');
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Spec and design reviews need complete documents: the same structural checks the gate
|
|
283
|
+
* runs (sections, areas, every AC covered by a task with a title and paths). A review of
|
|
284
|
+
* an unfinished template only reports that and costs one of the step's rounds.
|
|
285
|
+
*/
|
|
286
|
+
function unfinishedDocuments(feature, config, step) {
|
|
287
|
+
if (!['spec', 'design', 'design:light'].includes(step))
|
|
288
|
+
return;
|
|
289
|
+
const problems = [];
|
|
290
|
+
if (!feature.spec)
|
|
291
|
+
problems.push('spec.md does not exist');
|
|
292
|
+
if (step !== 'spec') {
|
|
293
|
+
if (!feature.design)
|
|
294
|
+
problems.push('design.md does not exist');
|
|
295
|
+
if (!feature.tasks)
|
|
296
|
+
problems.push('tasks.md does not exist');
|
|
297
|
+
}
|
|
298
|
+
const names = step === 'spec' ? ['spec.md'] : ['spec.md', 'design.md', 'tasks.md'];
|
|
299
|
+
problems.push(...documentProblems(feature).filter((p) => names.some((n) => p.startsWith(n))));
|
|
300
|
+
if (step !== 'spec')
|
|
301
|
+
problems.push(...designProblems(feature, config));
|
|
302
|
+
if (problems.length === 0)
|
|
303
|
+
return;
|
|
304
|
+
throw new AgjanError(`the documents are not ready for the ${step} review; complete them first:\n${problems.map((p) => ` - ${p}`).join('\n')}`);
|
|
305
|
+
}
|
|
306
|
+
export function createReviewContext(root, config, { feature: slug, step }) {
|
|
307
|
+
const feature = loadFeature(root, slug);
|
|
308
|
+
const parsed = parseStep(step, feature, config);
|
|
309
|
+
unfinishedDocuments(feature, config, parsed.step);
|
|
310
|
+
if (parsed.step === QA_STEP)
|
|
311
|
+
throw new AgjanError('step qa is done by the QA agent (agjan-qa, qa_context), not by a reviewer');
|
|
312
|
+
// The final review comes after QA (decision 81).
|
|
313
|
+
const qa = parsed.step === 'verify' ? qaProblem(root, config, feature) : null;
|
|
314
|
+
if (qa)
|
|
315
|
+
throw new AgjanError(`the final review waits for QA: ${qa}`);
|
|
316
|
+
const tree = treeHash(root, config, feature.slug);
|
|
317
|
+
unchangedSinceFindings(feature, parsed.step, tree);
|
|
318
|
+
const text = buildContextText(root, config, feature, parsed);
|
|
319
|
+
const id = `${feature.key}-C${randomBytes(4).toString('hex')}`;
|
|
320
|
+
const base = resolveBase(root, config.git?.base);
|
|
321
|
+
const meta = {
|
|
322
|
+
id,
|
|
323
|
+
feature: feature.slug,
|
|
324
|
+
step: parsed.step,
|
|
325
|
+
documents: { spec: feature.spec?.hash, design: feature.designHash ?? undefined },
|
|
326
|
+
inputs_hash: sha256(text),
|
|
327
|
+
tree_hash: tree,
|
|
328
|
+
base_commit: mergeBase(root, base),
|
|
329
|
+
head_commit: git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true })?.trim() ?? null,
|
|
330
|
+
};
|
|
331
|
+
const dir = join(root, CONTEXT_DIR);
|
|
332
|
+
mkdirSync(dir, { recursive: true });
|
|
333
|
+
writeJson(join(dir, `${id}.json`), meta);
|
|
334
|
+
return { id, text };
|
|
335
|
+
}
|
|
336
|
+
function validFinding(f, i) {
|
|
337
|
+
const where = `findings[${i}]`;
|
|
338
|
+
if (typeof f !== 'object' || f === null)
|
|
339
|
+
return `${where} must be an object`;
|
|
340
|
+
if (!SEVERITIES.includes(f.severity))
|
|
341
|
+
return `${where}.severity must be one of ${SEVERITIES.join(', ')}`;
|
|
342
|
+
if (typeof f.issue !== 'string' || f.issue.trim() === '')
|
|
343
|
+
return `${where}.issue is required`;
|
|
344
|
+
if (f.file !== undefined && (typeof f.file !== 'string' || f.file.includes('\\')))
|
|
345
|
+
return `${where}.file must be a POSIX path`;
|
|
346
|
+
if (f.line !== undefined && !(Number.isInteger(f.line) && f.line > 0))
|
|
347
|
+
return `${where}.line must be a positive integer`;
|
|
348
|
+
if (f.suggestion !== undefined && typeof f.suggestion !== 'string')
|
|
349
|
+
return `${where}.suggestion must be a string`;
|
|
350
|
+
if (f.evidence !== undefined && typeof f.evidence !== 'string')
|
|
351
|
+
return `${where}.evidence must be a string`;
|
|
352
|
+
const extra = Object.keys(f).filter((k) => !['severity', 'file', 'line', 'issue', 'suggestion', 'evidence'].includes(k));
|
|
353
|
+
if (extra.length)
|
|
354
|
+
return `${where} has unknown field(s): ${extra.join(', ')}`;
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
/** Checks a result against its context; shared by review_record and qa_record. */
|
|
358
|
+
function validResult(root, { context_id: contextId, verdict, findings = [], resolves = [] }, kind) {
|
|
359
|
+
if (typeof contextId !== 'string' || !/^[A-Z][A-Z0-9]{1,5}-C[0-9a-f]{8}$/.test(contextId))
|
|
360
|
+
throw new AgjanError('context_id is missing or malformed');
|
|
361
|
+
const metaFile = join(root, CONTEXT_DIR, `${contextId}.json`);
|
|
362
|
+
const meta = readJson(metaFile);
|
|
363
|
+
const call = kind === 'qa' ? 'qa_context' : 'review_context';
|
|
364
|
+
if (!meta || (meta.kind ?? 'review') !== kind)
|
|
365
|
+
throw new AgjanError(`unknown context ${contextId}; call ${call} first`);
|
|
366
|
+
if (meta.recorded)
|
|
367
|
+
throw new AgjanError(`context ${contextId} was already used for ${meta.recorded}; call ${call} again`);
|
|
368
|
+
if (typeof verdict !== 'string' || !VERDICTS.includes(verdict))
|
|
369
|
+
throw new AgjanError(`verdict must be one of ${VERDICTS.join(', ')}`);
|
|
370
|
+
if (!Array.isArray(findings) || findings.length > 50)
|
|
371
|
+
throw new AgjanError('findings must be a list of at most 50 items');
|
|
372
|
+
const problems = findings.map(validFinding).filter(Boolean);
|
|
373
|
+
if (problems.length)
|
|
374
|
+
throw new AgjanError(problems.join('; '));
|
|
375
|
+
const hasBlocker = findings.some((f) => f.severity === 'blocker');
|
|
376
|
+
if (hasBlocker && verdict !== 'blocked')
|
|
377
|
+
throw new AgjanError('a blocker finding requires the verdict blocked');
|
|
378
|
+
if (verdict === 'blocked' && !hasBlocker)
|
|
379
|
+
throw new AgjanError('the verdict blocked requires at least one blocker finding');
|
|
380
|
+
if (verdict === 'pass' && findings.length)
|
|
381
|
+
throw new AgjanError('the verdict pass allows no findings; use pass-with-notes');
|
|
382
|
+
const feature = loadFeature(root, meta.feature);
|
|
383
|
+
if (!Array.isArray(resolves) || resolves.some((id) => typeof id !== 'string'))
|
|
384
|
+
throw new AgjanError('resolves must be a list of finding ids');
|
|
385
|
+
const open = new Set(feature.findings.filter((f) => f.status === 'open').map((f) => f.id));
|
|
386
|
+
const unknown = resolves.filter((id) => !open.has(id));
|
|
387
|
+
if (unknown.length)
|
|
388
|
+
throw new AgjanError(`resolves lists findings that are not open: ${unknown.join(', ')}`);
|
|
389
|
+
return { contextId, metaFile, meta, feature, verdict: verdict, findings: findings, resolves: resolves };
|
|
390
|
+
}
|
|
391
|
+
/** Appends a record to reviews.json, regenerates review.md and logs it. */
|
|
392
|
+
function storeRecord(root, result, { host = 'unknown', isolation = 'unknown', now }, extra) {
|
|
393
|
+
const { contextId, metaFile, meta, feature } = result;
|
|
394
|
+
const records = feature.reviews.records;
|
|
395
|
+
let next = feature.findings.length;
|
|
396
|
+
const record = {
|
|
397
|
+
id: `${feature.key}-R${records.length + 1}`,
|
|
398
|
+
step: meta.step,
|
|
399
|
+
round: nextRound(feature, meta.step),
|
|
400
|
+
at_utc: now(),
|
|
401
|
+
reviewer: { host, model: null, isolation },
|
|
402
|
+
context: contextId,
|
|
403
|
+
documents: meta.documents,
|
|
404
|
+
inputs_hash: meta.inputs_hash,
|
|
405
|
+
base_commit: meta.base_commit,
|
|
406
|
+
head_commit: meta.head_commit,
|
|
407
|
+
verdict: result.verdict,
|
|
408
|
+
resolves: result.resolves,
|
|
409
|
+
findings: result.findings.map((f) => ({ id: `${feature.key}-F${++next}`, ...f })),
|
|
410
|
+
...extra,
|
|
411
|
+
};
|
|
412
|
+
records.push(record);
|
|
413
|
+
writeJson(join(feature.dir, REVIEWS_FILE), { schema: 1, records });
|
|
414
|
+
writeFileSync(join(feature.dir, REVIEW_MD), renderReviewMd(loadFeature(root, feature.slug)));
|
|
415
|
+
writeJson(metaFile, { ...meta, recorded: record.id });
|
|
416
|
+
appendLog(feature.dir, record.at_utc, 'review-recorded', {
|
|
417
|
+
review: record.id,
|
|
418
|
+
step: record.step,
|
|
419
|
+
round: record.round,
|
|
420
|
+
verdict: record.verdict,
|
|
421
|
+
findings: record.findings.length,
|
|
422
|
+
blockers: record.findings.filter((f) => f.severity === 'blocker').length,
|
|
423
|
+
isolation,
|
|
424
|
+
});
|
|
425
|
+
return record;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* review_record: validates the reviewer's result against its context and appends it.
|
|
429
|
+
* Refuses when anything in the working tree changed since the context was produced.
|
|
430
|
+
*/
|
|
431
|
+
export function recordReview(root, config, input, recorder) {
|
|
432
|
+
const result = validResult(root, input, 'review');
|
|
433
|
+
if (treeHash(root, config, result.feature.slug) !== result.meta.tree_hash) {
|
|
434
|
+
throw new AgjanError('the working tree changed since review_context was called; nothing was recorded. ' +
|
|
435
|
+
'A reviewer must not change files. Call review_context again and review the current state.');
|
|
436
|
+
}
|
|
437
|
+
return storeRecord(root, result, recorder, { tree_hash: result.meta.tree_hash });
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* qa_context (decision 81): the QA agent's input. Only what a tester gets: the spec, how
|
|
441
|
+
* to run the application and who its users are, and the test conventions; never the
|
|
442
|
+
* design, the diff or the writer's tests. Ready once the build is complete and reviewed.
|
|
443
|
+
*/
|
|
444
|
+
export function createQaContext(root, config, { feature: slug }) {
|
|
445
|
+
const feature = loadFeature(root, slug);
|
|
446
|
+
if (!qaApplies(config, feature))
|
|
447
|
+
throw new AgjanError(`QA does not apply to ${slug}: it runs for full-mode features (review.qa is ${config.review?.qa ?? 'on'})`);
|
|
448
|
+
if (feature.stage !== 'build' || !feature.spec)
|
|
449
|
+
throw new AgjanError(`${slug} is not in Build yet; QA runs in Verify`);
|
|
450
|
+
const progress = buildProgress(root, config, feature);
|
|
451
|
+
if (!progress.complete || progress.due.length)
|
|
452
|
+
throw new AgjanError('QA runs after the build: every task committed and its reviews done (npx agjan status)');
|
|
453
|
+
const dirs = qaDirs(feature.slug);
|
|
454
|
+
const baseline = join(root, FEATURES_DIR, 'project.md');
|
|
455
|
+
const runLocally = existsSync(baseline) ? (/^## Run locally\s*$([\s\S]*?)(?=^## |\s*$(?![\s\S]))/m.exec(readFileSync(baseline, 'utf8'))?.[1] ?? '').trim() : '';
|
|
456
|
+
const areaNames = [...new Set(feature.tasks.parsed.tasks.map((t) => resolveArea(config, t.area)?.name).filter((name) => Boolean(name)))];
|
|
457
|
+
const commands = areaNames.map((a) => `- ${a}: ${config.verify?.[a]?.test ?? 'npm test'} (tests: ${(config.tests[a] ?? []).join(', ') || '-'})`).join('\n');
|
|
458
|
+
const ui = Boolean(readJson(join(root, 'package.json'))?.scripts?.['test:ui']);
|
|
459
|
+
const existing = qaTestFiles(root, feature.slug);
|
|
460
|
+
const parts = [
|
|
461
|
+
`# QA context: ${feature.slug} (${feature.key}), step qa`,
|
|
462
|
+
'',
|
|
463
|
+
'You are the tester. You know the requirements, not the code: do not read the design, the application code or the existing tests, and do not change anything outside your QA folders.',
|
|
464
|
+
'',
|
|
465
|
+
section('Your QA folders (the only paths you write)', `${dirs.map((d) => `- \`${d}\``).join('\n')}\n\nService tests go into \`${dirs[0]}\`, UI tests (Playwright) into \`${dirs[1]}\`. Name each test \`${feature.key}-AC<n> QA: <what it checks>\`. They stay in the project as regression tests.`),
|
|
466
|
+
section(docPath(feature, 'spec.md'), fence(feature.spec.text, 'md')),
|
|
467
|
+
section('Run locally (from docs/agjan/project.md)', runLocally || '(not described: start the application as the project README or package.json says)'),
|
|
468
|
+
section('Test conventions', `${commands}\n- UI tests: ${ui ? '`npx agjan ui-test` runs the Playwright tests (it skips them, with the reason, where no browser can start)' : 'the project has no Playwright setup (no `test:ui` script): write service tests only'}\n- How tests are written in this stack: \`.claude/skills/cap-developer/references/testing.md\` (cds.test) and \`.claude/skills/fiori-developer/references/testing.md\` (Playwright). Read those for the test mechanics only.`),
|
|
469
|
+
section('Your tests from earlier QA rounds', existing.length ? existing.map((f) => `- ${f}`).join('\n') : '(none: this is the first QA round)'),
|
|
470
|
+
section('Earlier rounds', reviewHistory(feature)),
|
|
471
|
+
section('Open findings', openFindings(feature, [QA_STEP])),
|
|
472
|
+
section('How to record your result', 'Run your tests. Then call qa_record with this context_id, a verdict (pass, pass-with-notes, blocked), your findings and in `resolves` the ids of earlier QA findings that pass now. ' +
|
|
473
|
+
'A test that fails against an acceptance criterion or an authorization rule is a blocker (file: the test file; evidence: the test name and the failure output). ' +
|
|
474
|
+
'Something the spec does not decide is a minor finding starting with "Spec question:". A blocker requires the verdict blocked.'),
|
|
475
|
+
];
|
|
476
|
+
const text = parts.join('\n');
|
|
477
|
+
const id = `${feature.key}-C${randomBytes(4).toString('hex')}`;
|
|
478
|
+
const base = resolveBase(root, config.git?.base);
|
|
479
|
+
const meta = {
|
|
480
|
+
id,
|
|
481
|
+
kind: 'qa',
|
|
482
|
+
feature: feature.slug,
|
|
483
|
+
step: QA_STEP,
|
|
484
|
+
documents: { spec: feature.spec.hash, design: feature.designHash ?? undefined },
|
|
485
|
+
inputs_hash: sha256(text),
|
|
486
|
+
tree_hash: treeHash(root, config, feature.slug, dirs),
|
|
487
|
+
base_commit: mergeBase(root, base),
|
|
488
|
+
head_commit: git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true })?.trim() ?? null,
|
|
489
|
+
};
|
|
490
|
+
const dir = join(root, CONTEXT_DIR);
|
|
491
|
+
mkdirSync(dir, { recursive: true });
|
|
492
|
+
writeJson(join(dir, `${id}.json`), meta);
|
|
493
|
+
return { id, text };
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* qa_record: the QA agent's result. Refused when it changed anything outside its QA
|
|
497
|
+
* folders; records the hash of its tests, so a later change to them makes QA stale.
|
|
498
|
+
*/
|
|
499
|
+
export function recordQa(root, config, input, recorder) {
|
|
500
|
+
const result = validResult(root, input, 'qa');
|
|
501
|
+
const slug = result.feature.slug;
|
|
502
|
+
if (treeHash(root, config, slug, qaDirs(slug)) !== result.meta.tree_hash) {
|
|
503
|
+
throw new AgjanError(`files outside the QA folders (${qaDirs(slug).join(', ')}) changed since qa_context was called; nothing was recorded. ` +
|
|
504
|
+
'QA writes only its own tests. Undo the other changes, then call qa_context again.');
|
|
505
|
+
}
|
|
506
|
+
return storeRecord(root, result, recorder, {
|
|
507
|
+
tree_hash: treeHash(root, config, slug),
|
|
508
|
+
qa_tests_hash: qaTestsHash(root, slug),
|
|
509
|
+
qa_tests: qaTestFiles(root, slug),
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
/** Renders review.md from reviews.json (design 8.5). Generated; never edited by hand. */
|
|
513
|
+
export function renderReviewMd(feature) {
|
|
514
|
+
const out = [`# Reviews: ${feature.slug} (${feature.key})`, '', '<!-- Generated by agjan from reviews.json. Do not edit. -->', ''];
|
|
515
|
+
const status = new Map(feature.findings.map((f) => [f.id, f.status]));
|
|
516
|
+
for (const r of feature.reviews.records) {
|
|
517
|
+
out.push(`## ${r.id} ${r.step}, round ${r.round}: ${r.verdict}`, '');
|
|
518
|
+
out.push(`${r.at_utc} · reviewer: ${r.reviewer?.host ?? 'unknown'}, isolation ${r.reviewer?.isolation ?? 'unknown'}`, '');
|
|
519
|
+
if (r.resolves?.length)
|
|
520
|
+
out.push(`Resolves: ${r.resolves.join(', ')}`, '');
|
|
521
|
+
for (const f of r.findings ?? []) {
|
|
522
|
+
const where = f.file ? ` ${f.file}${f.line ? `:${f.line}` : ''}` : '';
|
|
523
|
+
out.push(`- **${f.id}** [${f.severity}]${where} (${status.get(f.id)})`);
|
|
524
|
+
out.push(` - Issue: ${f.issue}`);
|
|
525
|
+
if (f.suggestion)
|
|
526
|
+
out.push(` - Suggestion: ${f.suggestion}`);
|
|
527
|
+
if (f.evidence)
|
|
528
|
+
out.push(` - Evidence: ${f.evidence}`);
|
|
529
|
+
}
|
|
530
|
+
if (r.findings?.length)
|
|
531
|
+
out.push('');
|
|
532
|
+
}
|
|
533
|
+
return `${out.join('\n').trimEnd()}\n`;
|
|
534
|
+
}
|
package/dist/scope.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import picomatch from 'picomatch';
|
|
2
|
+
import { resolveArea } from './config.js';
|
|
3
|
+
import { qaDirs } from './qa.js';
|
|
4
|
+
/** A path ending in '/' means the whole folder. */
|
|
5
|
+
function toGlob(pattern) {
|
|
6
|
+
return pattern.endsWith('/') ? `${pattern}**` : pattern;
|
|
7
|
+
}
|
|
8
|
+
/** Case-sensitive matcher for POSIX repository paths, the same on every OS (design 4.5). */
|
|
9
|
+
export function matcher(patterns) {
|
|
10
|
+
if (patterns.length === 0)
|
|
11
|
+
return () => false;
|
|
12
|
+
return picomatch(patterns.map(toGlob), { dot: true, nocase: false, windows: false });
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The patterns a feature in Build may change: its task paths, the implicit allowlist of
|
|
16
|
+
* the task areas, and approved amendments (design 6.5).
|
|
17
|
+
*/
|
|
18
|
+
export function allowedPatterns(feature, config) {
|
|
19
|
+
const patterns = [];
|
|
20
|
+
for (const task of feature.tasks?.parsed.tasks ?? []) {
|
|
21
|
+
patterns.push(...task.paths);
|
|
22
|
+
const area = resolveArea(config, task.area ?? '');
|
|
23
|
+
if (area)
|
|
24
|
+
patterns.push(...(config.scope.implicit[area.name] ?? []));
|
|
25
|
+
}
|
|
26
|
+
for (const amendment of feature.amendments) {
|
|
27
|
+
if (amendment.status === 'approved')
|
|
28
|
+
patterns.push(...amendment.paths);
|
|
29
|
+
}
|
|
30
|
+
// The QA agent's tests (decision 81).
|
|
31
|
+
if (feature.kind === 'feature')
|
|
32
|
+
patterns.push(...qaDirs(feature.slug));
|
|
33
|
+
return patterns;
|
|
34
|
+
}
|