agjan 0.0.11 → 0.0.12
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 +105 -0
- package/dist/adapters/copilot.js +80 -0
- package/dist/auto.js +24 -0
- package/dist/baseline.js +66 -0
- package/dist/browser.js +46 -0
- package/dist/cli.js +164 -0
- package/dist/commands/branch.js +71 -0
- package/dist/commands/check.js +420 -0
- package/dist/commands/fix.js +122 -0
- package/dist/commands/gates.js +462 -0
- package/dist/commands/lint.js +76 -0
- package/dist/commands/log.js +72 -0
- package/dist/commands/map.js +47 -0
- package/dist/commands/new.js +65 -0
- package/dist/commands/pr-summary.js +168 -0
- package/dist/commands/progress.js +42 -0
- package/dist/commands/report.js +105 -0
- package/dist/commands/review.js +146 -0
- package/dist/commands/setup.js +393 -0
- package/dist/commands/status.js +303 -0
- package/dist/commands/ui-test.js +39 -0
- package/dist/config.js +110 -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 +142 -0
- package/dist/plan.js +40 -0
- package/dist/progress-view.js +494 -0
- package/dist/progress.js +106 -0
- package/{src/review-policy.mjs → dist/review-policy.js} +39 -47
- package/dist/review.js +435 -0
- package/dist/scope.js +30 -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 +62 -38
- package/kit/hooks/guard.mjs +48 -119
- package/kit/skills/agjan-build/SKILL.md +4 -2
- package/kit/skills/agjan-design/SKILL.md +6 -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 +21 -17
- package/kit/skills/agjan-verify/SKILL.md +20 -13
- 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 +0 -5
- package/schemas/log.schema.json +1 -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.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/src/commands/gates.mjs
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { join, relative } from 'node:path';
|
|
3
|
-
import { parseArgs } from 'node:util';
|
|
4
|
-
import { writeJson } from '../json-file.mjs';
|
|
5
|
-
import { appendLog, readLog } from '../log.mjs';
|
|
6
|
-
import { APPROVALS_FILE, FEATURES_DIR, gateReview, loadFeature, selectFeature } from '../feature.mjs';
|
|
7
|
-
import { documentProblems, designProblems } from '../validate.mjs';
|
|
8
|
-
import { AgjanError, UsageError } from '../errors.mjs';
|
|
9
|
-
import { blink, mark, tone } from '../ui.mjs';
|
|
10
|
-
import { git } from '../git.mjs';
|
|
11
|
-
|
|
12
|
-
function short(hash) {
|
|
13
|
-
return hash ? hash.slice('sha256:'.length, 'sha256:'.length + 12) : '-';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function refuse(what, problems) {
|
|
17
|
-
throw new AgjanError(`cannot ${what}:\n${problems.map((p) => ` - ${p}`).join('\n')}`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function save(ctx, feature, event, fields) {
|
|
21
|
-
writeJson(join(feature.dir, APPROVALS_FILE), feature.approvals);
|
|
22
|
-
appendLog(feature.dir, ctx.now(), event, fields);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Shows what is being approved and asks the human to type the feature key (design 9.4). */
|
|
26
|
-
async function confirmGate(ctx, feature, title, lines) {
|
|
27
|
-
const logo = mark(ctx.style, ctx.kit, 'a human decision, recorded with your name');
|
|
28
|
-
for (const line of logo) ctx.out(line);
|
|
29
|
-
await blink(ctx, logo);
|
|
30
|
-
const summary = [
|
|
31
|
-
...(logo.length ? [] : ['']),
|
|
32
|
-
ctx.style.bold(`agjan: ${title}`),
|
|
33
|
-
` feature ${ctx.style.bold(feature.slug)} (${ctx.style.cyan(feature.key)})`,
|
|
34
|
-
...lines.map((l) => ` ${l}`),
|
|
35
|
-
` approver ${ctx.email()}`,
|
|
36
|
-
'',
|
|
37
|
-
].join('\n');
|
|
38
|
-
if (!ctx.confirm(summary, feature.key)) {
|
|
39
|
-
ctx.out(ctx.style.yellow('cancelled, nothing recorded'));
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** One line, no control characters, at most 200 characters. */
|
|
46
|
-
export function cleanMessage(text) {
|
|
47
|
-
return String(text ?? '').replace(/[\x00-\x1f\x7f]+/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 200);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** The commit message the agent proposed when it handed `gate` over (`log --gate-requested --message`). */
|
|
51
|
-
function proposedMessage(feature, gate) {
|
|
52
|
-
const request = readLog(feature.dir).findLast((e) => e.event === 'gate-requested' && e.gate === gate);
|
|
53
|
-
return cleanMessage(request?.message);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* After a recorded decision: commits the feature folder (the approved documents and the
|
|
58
|
-
* record) with a message the human confirms or edits. Only that folder goes into the
|
|
59
|
-
* commit, whatever else is staged; the pre-commit hook still runs. A failed or skipped
|
|
60
|
-
* commit leaves the decision recorded and says how to commit it.
|
|
61
|
-
*/
|
|
62
|
-
async function commitRecord(ctx, feature, values, proposal) {
|
|
63
|
-
const s = ctx.style;
|
|
64
|
-
const folder = relative(ctx.root, feature.dir).split('\\').join('/');
|
|
65
|
-
const manual = s.yellow(`not committed; commit ${folder}/ yourself`);
|
|
66
|
-
if (values['no-commit']) return ctx.out(manual);
|
|
67
|
-
if (!git(ctx.root, ['status', '--porcelain', '--', folder]).trim()) return undefined;
|
|
68
|
-
const message = cleanMessage(await ctx.edit(`${s.bold('Commit message')} (Enter to commit, empty to skip): `, proposal));
|
|
69
|
-
if (!message) return ctx.out(manual);
|
|
70
|
-
git(ctx.root, ['add', '-A', '--', folder]);
|
|
71
|
-
const result = spawnSync('git', ['commit', '-q', '-m', message, '--', folder], { cwd: ctx.root, encoding: 'utf8' });
|
|
72
|
-
if (result.status !== 0) {
|
|
73
|
-
ctx.out(`${result.stdout ?? ''}${result.stderr ?? ''}`.trimEnd(), s.red(`the commit failed; the decision is recorded but ${folder}/ is not committed`));
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
const sha = git(ctx.root, ['rev-parse', '--short', 'HEAD']).trim();
|
|
77
|
-
return ctx.out(`${s.green('committed')} ${s.gray(sha)} ${message}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function reviewLine(ctx, review) {
|
|
81
|
-
const notes = review.findings?.length ? `, ${review.findings.length} finding(s)` : '';
|
|
82
|
-
return `review ${review.id} ${review.step} round ${review.round}: ${tone(ctx.style, review.verdict)}${notes}`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function specGateProblems(feature) {
|
|
86
|
-
const problems = [];
|
|
87
|
-
if (!feature.spec) problems.push('spec.md does not exist');
|
|
88
|
-
else problems.push(...feature.spec.parsed.problems.map((p) => `spec.md: ${p}`));
|
|
89
|
-
return problems;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function designGateProblems(ctx, feature) {
|
|
93
|
-
const problems = [];
|
|
94
|
-
if (!feature.design) problems.push('design.md does not exist');
|
|
95
|
-
if (!feature.tasks) problems.push('tasks.md does not exist');
|
|
96
|
-
problems.push(...documentProblems(feature).filter((p) => !p.startsWith('spec.md')));
|
|
97
|
-
problems.push(...designProblems(feature, ctx.config));
|
|
98
|
-
return problems;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** The gate a feature waits for: 'spec', 'spec design' (light mode) or 'design'; null in Build. */
|
|
102
|
-
export function pendingGate(feature) {
|
|
103
|
-
if (feature.stage === 'spec') return feature.design?.parsed.mode === 'light' ? 'spec design' : 'spec';
|
|
104
|
-
if (feature.stage === 'design') return 'design';
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Everything that stands between a feature and the approval of `gate`, shared by
|
|
110
|
-
* `approve`, `status` and `log --gate-requested`. No problems means the gate is ready.
|
|
111
|
-
*/
|
|
112
|
-
export function gateReadiness(ctx, feature, gate) {
|
|
113
|
-
const problems = [];
|
|
114
|
-
let review;
|
|
115
|
-
if (gate === 'spec') {
|
|
116
|
-
if (feature.state.spec === 'approved') problems.push('spec.md is already approved and unchanged');
|
|
117
|
-
problems.push(...specGateProblems(feature));
|
|
118
|
-
review = gateReview(feature, 'spec');
|
|
119
|
-
if (feature.design?.parsed.mode === 'light') problems.push("design.md is in light mode: approve both together with 'agjan approve spec design'");
|
|
120
|
-
} else if (gate === 'design') {
|
|
121
|
-
if (feature.state.spec !== 'approved') problems.push(`the spec must be approved first (it is ${feature.state.spec})`);
|
|
122
|
-
if (feature.state.design === 'approved') problems.push('design.md and tasks.md are already approved and unchanged');
|
|
123
|
-
problems.push(...designGateProblems(ctx, feature));
|
|
124
|
-
if (feature.design?.parsed.mode === 'light') problems.push("light-mode designs are approved together with the spec ('agjan approve spec design')");
|
|
125
|
-
review = gateReview(feature, 'design');
|
|
126
|
-
} else {
|
|
127
|
-
if (feature.state.spec === 'approved' && feature.state.design === 'approved') problems.push('spec and design are already approved and unchanged');
|
|
128
|
-
problems.push(...specGateProblems(feature), ...designGateProblems(ctx, feature));
|
|
129
|
-
if (feature.design && feature.design.parsed.mode !== 'light') problems.push("design.md is in full mode: approve the spec first, then 'agjan approve design'");
|
|
130
|
-
review = gateReview(feature, 'design');
|
|
131
|
-
if (review.record && review.record.step !== 'design:light') problems.push(`the latest review is ${review.record.step}; a combined approval needs a design:light review`);
|
|
132
|
-
}
|
|
133
|
-
problems.push(...review.problems);
|
|
134
|
-
return { problems, record: review.record };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function approveSpec(ctx, feature, values) {
|
|
138
|
-
const { problems, record } = gateReadiness(ctx, feature, 'spec');
|
|
139
|
-
if (problems.length) refuse('approve the spec', problems);
|
|
140
|
-
const previous = feature.state.spec === 'stale' ? ' (re-approval: changed since the last approval)' : '';
|
|
141
|
-
if (!(await confirmGate(ctx, feature, `approve spec${previous}`, [`spec.md ${short(feature.spec.hash)}`, reviewLine(ctx, record)]))) return 1;
|
|
142
|
-
feature.approvals.approvals.spec = { hash: feature.spec.hash, at_utc: ctx.now(), by: ctx.email() };
|
|
143
|
-
// A new spec approval invalidates the design: its spec_hash no longer matches.
|
|
144
|
-
save(ctx, feature, 'approved', { gate: 'spec' });
|
|
145
|
-
ctx.out(ctx.style.green(`approved spec of ${feature.slug}`));
|
|
146
|
-
await commitRecord(ctx, feature, values, proposedMessage(feature, 'spec') || `${feature.key}: approve spec`);
|
|
147
|
-
return 0;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async function approveDesign(ctx, feature, values) {
|
|
151
|
-
const { problems, record } = gateReadiness(ctx, feature, 'design');
|
|
152
|
-
if (problems.length) refuse('approve the design', problems);
|
|
153
|
-
const lines = [`design ${short(feature.designHash)} (design.md + tasks.md, mode ${feature.design.parsed.mode})`, reviewLine(ctx, record)];
|
|
154
|
-
if (!(await confirmGate(ctx, feature, 'approve design', lines))) return 1;
|
|
155
|
-
feature.approvals.approvals.design = { hash: feature.designHash, spec_hash: feature.spec.hash, at_utc: ctx.now(), by: ctx.email() };
|
|
156
|
-
save(ctx, feature, 'approved', { gate: 'design' });
|
|
157
|
-
ctx.out(ctx.style.green(`approved design of ${feature.slug}`));
|
|
158
|
-
await commitRecord(ctx, feature, values, proposedMessage(feature, 'design') || `${feature.key}: approve design`);
|
|
159
|
-
return 0;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async function approveCombined(ctx, feature, values) {
|
|
163
|
-
const { problems, record } = gateReadiness(ctx, feature, 'spec design');
|
|
164
|
-
if (problems.length) refuse('approve spec and design', problems);
|
|
165
|
-
const lines = [
|
|
166
|
-
`spec.md ${short(feature.spec.hash)}`,
|
|
167
|
-
`design ${short(feature.designHash)} (design.md + tasks.md, mode light)`,
|
|
168
|
-
reviewLine(ctx, record),
|
|
169
|
-
];
|
|
170
|
-
if (!(await confirmGate(ctx, feature, 'approve spec and design (light mode)', lines))) return 1;
|
|
171
|
-
const at = ctx.now();
|
|
172
|
-
const by = ctx.email();
|
|
173
|
-
feature.approvals.approvals.spec = { hash: feature.spec.hash, at_utc: at, by };
|
|
174
|
-
feature.approvals.approvals.design = { hash: feature.designHash, spec_hash: feature.spec.hash, at_utc: at, by };
|
|
175
|
-
save(ctx, feature, 'approved', { gate: 'spec design' });
|
|
176
|
-
ctx.out(ctx.style.green(`approved spec and design of ${feature.slug}`));
|
|
177
|
-
await commitRecord(ctx, feature, values, proposedMessage(feature, 'spec design') || `${feature.key}: approve spec and design`);
|
|
178
|
-
return 0;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async function approveAmendment(ctx, feature, id, values) {
|
|
182
|
-
if (feature.state.design !== 'approved') throw new AgjanError(`amendments need an approved design (it is ${feature.state.design})`);
|
|
183
|
-
const amendment = feature.approvals.amendments.find((a) => a.id === id);
|
|
184
|
-
if (!amendment) throw new AgjanError(`no amendment ${id} in ${feature.slug}`);
|
|
185
|
-
if (amendment.approved_at_utc && amendment.design_hash === feature.approvals.approvals.design.hash) {
|
|
186
|
-
throw new AgjanError(`${id} is already approved`);
|
|
187
|
-
}
|
|
188
|
-
const lines = [`amendment ${id} for ${amendment.task}`, `paths ${amendment.paths.join(', ')}`, `reason ${amendment.reason}`];
|
|
189
|
-
if (!(await confirmGate(ctx, feature, 'approve scope amendment', lines))) return 1;
|
|
190
|
-
Object.assign(amendment, { approved_at_utc: ctx.now(), by: ctx.email(), design_hash: feature.approvals.approvals.design.hash });
|
|
191
|
-
save(ctx, feature, 'approved', { gate: 'amendment', amendment: id });
|
|
192
|
-
ctx.out(ctx.style.green(`approved ${id}`));
|
|
193
|
-
await commitRecord(ctx, feature, values, `${feature.key}: approve amendment ${id}`);
|
|
194
|
-
return 0;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const FEATURE_OPTION = { feature: { type: 'string' }, 'no-commit': { type: 'boolean' } };
|
|
198
|
-
|
|
199
|
-
/** agjan approve spec | design | spec design | amendment <id> [--feature <slug>] [--no-commit] */
|
|
200
|
-
export function approve(ctx, argv) {
|
|
201
|
-
const { values, positionals } = parseArgs({ args: argv, options: FEATURE_OPTION, allowPositionals: true });
|
|
202
|
-
const what = positionals.join(' ');
|
|
203
|
-
const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
|
|
204
|
-
if (what === 'spec') return approveSpec(ctx, feature, values);
|
|
205
|
-
if (what === 'design') return approveDesign(ctx, feature, values);
|
|
206
|
-
if (what === 'spec design' || what === 'design spec') return approveCombined(ctx, feature, values);
|
|
207
|
-
if (positionals[0] === 'amendment' && positionals.length === 2) return approveAmendment(ctx, feature, positionals[1], values);
|
|
208
|
-
throw new UsageError('usage: agjan approve spec | design | spec design | amendment <id> [--feature <slug>] [--no-commit]');
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/** agjan accept <finding-id> --reason "…" [--feature <slug>] [--no-commit] */
|
|
212
|
-
export async function accept(ctx, argv) {
|
|
213
|
-
const { values, positionals } = parseArgs({ args: argv, options: { ...FEATURE_OPTION, reason: { type: 'string' } }, allowPositionals: true });
|
|
214
|
-
const [id] = positionals;
|
|
215
|
-
if (!id || positionals.length !== 1 || !values.reason?.trim()) throw new UsageError('usage: agjan accept <finding-id> --reason "<why>" [--feature <slug>] [--no-commit]');
|
|
216
|
-
const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
|
|
217
|
-
const finding = feature.findings.find((f) => f.id === id);
|
|
218
|
-
if (!finding) throw new AgjanError(`no finding ${id} in ${feature.slug}`);
|
|
219
|
-
if (finding.status !== 'open') throw new AgjanError(`${id} is already ${finding.status}`);
|
|
220
|
-
const lines = [`finding ${id} [${finding.severity}] ${finding.file ?? ''}`.trimEnd(), `issue ${finding.issue}`, `reason ${values.reason}`];
|
|
221
|
-
if (!(await confirmGate(ctx, feature, 'accept finding', lines))) return 1;
|
|
222
|
-
feature.approvals.accepted.push({ finding: id, reason: values.reason, at_utc: ctx.now(), by: ctx.email() });
|
|
223
|
-
save(ctx, feature, 'accepted', { finding: id, severity: finding.severity });
|
|
224
|
-
ctx.out(ctx.style.green(`accepted ${id}`));
|
|
225
|
-
await commitRecord(ctx, feature, values, `${feature.key}: accept ${id}`);
|
|
226
|
-
return 0;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** agjan reject spec|design --reason "…" [--feature <slug>] [--no-commit]: sends a gate back (for quality signals). */
|
|
230
|
-
export async function reject(ctx, argv) {
|
|
231
|
-
const { values, positionals } = parseArgs({ args: argv, options: { ...FEATURE_OPTION, reason: { type: 'string' } }, allowPositionals: true });
|
|
232
|
-
const [gate] = positionals;
|
|
233
|
-
if (!['spec', 'design'].includes(gate) || positionals.length !== 1 || !values.reason?.trim()) {
|
|
234
|
-
throw new UsageError('usage: agjan reject spec|design --reason "<why>" [--feature <slug>] [--no-commit]');
|
|
235
|
-
}
|
|
236
|
-
const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
|
|
237
|
-
if (!(await confirmGate(ctx, feature, `reject ${gate}`, [`reason ${values.reason}`]))) return 1;
|
|
238
|
-
feature.approvals.rejections.push({ gate, reason: values.reason, at_utc: ctx.now(), by: ctx.email() });
|
|
239
|
-
save(ctx, feature, 'rejected', { gate });
|
|
240
|
-
ctx.out(`recorded rejection of ${gate} for ${feature.slug}; the document stays draft`);
|
|
241
|
-
await commitRecord(ctx, feature, values, `${feature.key}: reject ${gate}`);
|
|
242
|
-
return 0;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/** agjan amend --task <id> --paths <p1,p2> --reason "…": proposes a scope amendment (agent-run). */
|
|
246
|
-
export function amend(ctx, argv) {
|
|
247
|
-
const { values } = parseArgs({
|
|
248
|
-
args: argv,
|
|
249
|
-
options: { ...FEATURE_OPTION, task: { type: 'string' }, paths: { type: 'string' }, reason: { type: 'string' } },
|
|
250
|
-
});
|
|
251
|
-
const paths = (values.paths ?? '').split(',').map((p) => p.trim()).filter(Boolean);
|
|
252
|
-
if (!values.task || paths.length === 0 || !values.reason?.trim()) {
|
|
253
|
-
throw new UsageError('usage: agjan amend --task <id> --paths <path,...> --reason "<why>" [--feature <slug>]');
|
|
254
|
-
}
|
|
255
|
-
const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
|
|
256
|
-
if (feature.state.design !== 'approved') throw new AgjanError(`amendments need an approved design (it is ${feature.state.design})`);
|
|
257
|
-
if (!feature.tasks.parsed.tasks.some((t) => t.id === values.task)) throw new AgjanError(`no task ${values.task} in tasks.md`);
|
|
258
|
-
for (const p of paths) {
|
|
259
|
-
if (p.includes('\\') || p.startsWith('/') || p.split('/').includes('..')) throw new UsageError(`path '${p}' must be relative, POSIX, without '..'`);
|
|
260
|
-
}
|
|
261
|
-
const id = `${feature.key}-A${feature.approvals.amendments.length + 1}`;
|
|
262
|
-
feature.approvals.amendments.push({ id, task: values.task, paths, reason: values.reason, proposed_at_utc: ctx.now() });
|
|
263
|
-
save(ctx, feature, 'amendment-proposed', { amendment: id, task: values.task });
|
|
264
|
-
ctx.out(`proposed ${id} in ${FEATURES_DIR}/${feature.slug}/${APPROVALS_FILE}`);
|
|
265
|
-
ctx.out(`a human must approve it in a terminal: agjan approve amendment ${id}`);
|
|
266
|
-
return 0;
|
|
267
|
-
}
|
package/src/commands/lint.mjs
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { parseArgs } from 'node:util';
|
|
5
|
-
import { changedFiles, git, resolveBase } from '../git.mjs';
|
|
6
|
-
import { matcher } from '../scope.mjs';
|
|
7
|
-
import { UsageError } from '../errors.mjs';
|
|
8
|
-
import { overrideBase } from './check.mjs';
|
|
9
|
-
|
|
10
|
-
/** Quotes a path for the shell (sh and cmd both accept double quotes). */
|
|
11
|
-
const quote = (path) => (/^[\w./@-]+$/.test(path) ? path : `"${path.replace(/"/g, '\\"')}"`);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The folders an area's linter runs in, with the files to lint in each (paths relative to
|
|
15
|
-
* the folder). `lint.in` names the folders (for example `app/*`), `lint.files` the files
|
|
16
|
-
* inside them (for example `webapp/**`).
|
|
17
|
-
*/
|
|
18
|
-
export function lintTargets(files, lint) {
|
|
19
|
-
const depth = lint.in.split('/').length;
|
|
20
|
-
const isTarget = matcher([`${lint.in}/${lint.files}`]);
|
|
21
|
-
const folders = new Map();
|
|
22
|
-
for (const file of files.filter((f) => isTarget(f))) {
|
|
23
|
-
const parts = file.split('/');
|
|
24
|
-
const folder = parts.slice(0, depth).join('/');
|
|
25
|
-
if (!folders.has(folder)) folders.set(folder, []);
|
|
26
|
-
folders.get(folder).push(parts.slice(depth).join('/'));
|
|
27
|
-
}
|
|
28
|
-
return folders;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* agjan lint [--all] [--base <ref>]: runs each area's linter from the command line
|
|
33
|
-
* (`lint` in the domain or agjan.config.json; the fiori area runs the UI5 linter, which
|
|
34
|
-
* also checks manifest.json), in every folder with changed files and on those files.
|
|
35
|
-
* --all lints the whole folders. It needs no MCP server, so it runs on every host.
|
|
36
|
-
* Exit code 1 when a linter reports problems or cannot run.
|
|
37
|
-
*/
|
|
38
|
-
export function run(ctx, argv) {
|
|
39
|
-
const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { all: { type: 'boolean' }, base: { type: 'string' } } });
|
|
40
|
-
if (positionals.length) throw new UsageError('usage: agjan lint [--all] [--base <ref>]');
|
|
41
|
-
overrideBase(ctx, values.base);
|
|
42
|
-
const s = ctx.style;
|
|
43
|
-
const linters = Object.entries(ctx.config.lint ?? {}).filter(([, l]) => l?.command && l.in && l.files);
|
|
44
|
-
if (!linters.length) {
|
|
45
|
-
ctx.out(s.gray('no linter configured (lint in agjan.config.json)'));
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
const root = ctx.root;
|
|
49
|
-
const files = values.all
|
|
50
|
-
? (git(root, ['ls-files', '--cached', '--others', '--exclude-standard']) ?? '').split('\n').filter(Boolean)
|
|
51
|
-
: changedFiles(root, resolveBase(root, ctx.config.git?.base));
|
|
52
|
-
const present = files.filter((f) => existsSync(join(root, f)));
|
|
53
|
-
let failed = 0;
|
|
54
|
-
let ran = 0;
|
|
55
|
-
for (const [area, lint] of linters) {
|
|
56
|
-
for (const [folder, inside] of lintTargets(present, lint)) {
|
|
57
|
-
ran += 1;
|
|
58
|
-
const command = values.all ? lint.command : `${lint.command} ${inside.map(quote).join(' ')}`;
|
|
59
|
-
ctx.out(`${s.bold(`lint ${area}`)} ${folder}: ${s.gray(values.all ? lint.command : `${lint.command} (${inside.length} file(s))`)}`);
|
|
60
|
-
const result = spawnSync(command, { cwd: join(root, folder), shell: true, encoding: 'utf8', timeout: 600_000, maxBuffer: 64 * 1024 * 1024 });
|
|
61
|
-
const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim();
|
|
62
|
-
if (output) ctx.out(output);
|
|
63
|
-
if (result.status === 0) {
|
|
64
|
-
ctx.out(` ${s.green('ok')}`);
|
|
65
|
-
} else {
|
|
66
|
-
failed += 1;
|
|
67
|
-
const why = result.error ? `could not run: ${result.error.message}` : result.status === null ? 'could not run (stopped)' : `problems found (exit code ${result.status})`;
|
|
68
|
-
ctx.out(` ${s.red(why)}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (!ran) ctx.out(s.gray(values.all ? 'no files to lint' : 'no changed files to lint (--all lints everything)'));
|
|
73
|
-
return failed ? 1 : 0;
|
|
74
|
-
}
|
package/src/commands/log.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from 'node:util';
|
|
2
|
-
import { appendLog } from '../log.mjs';
|
|
3
|
-
import { loadFeature, selectFeature } from '../feature.mjs';
|
|
4
|
-
import { AgjanError, UsageError } from '../errors.mjs';
|
|
5
|
-
import { cleanMessage, gateReadiness } from './gates.mjs';
|
|
6
|
-
|
|
7
|
-
const STAGES = ['map', 'spec', 'design', 'build', 'verify', 'fix'];
|
|
8
|
-
const GATES = ['spec', 'design', 'spec design'];
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* agjan log --stage <stage> [--role r] [--task T1] [--skill s] [--host h] [--model m]
|
|
12
|
-
* agjan log --gate-requested <gate> [--message "<commit message>"]
|
|
13
|
-
* agjan log --waiting "<what the agent needs from the user>"
|
|
14
|
-
* Called once at the start of each step (design 12.1); the end of a step is inferred
|
|
15
|
-
* from the next event. `--message` proposes the commit message `approve` offers the human.
|
|
16
|
-
* `--waiting`: the agent stopped and waits for the user; its next step event ends the wait.
|
|
17
|
-
*/
|
|
18
|
-
export function run(ctx, argv) {
|
|
19
|
-
const { values } = parseArgs({
|
|
20
|
-
args: argv,
|
|
21
|
-
options: {
|
|
22
|
-
feature: { type: 'string' },
|
|
23
|
-
stage: { type: 'string' },
|
|
24
|
-
role: { type: 'string' },
|
|
25
|
-
task: { type: 'string' },
|
|
26
|
-
skill: { type: 'string' },
|
|
27
|
-
host: { type: 'string' },
|
|
28
|
-
model: { type: 'string' },
|
|
29
|
-
'gate-requested': { type: 'string' },
|
|
30
|
-
message: { type: 'string' },
|
|
31
|
-
waiting: { type: 'string' },
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
const gate = values['gate-requested'];
|
|
35
|
-
const usage = 'usage: agjan log --stage <stage> [--role r] [--task T1] [--skill s] | --gate-requested <gate> [--message "<text>"] | --waiting "<reason>"';
|
|
36
|
-
if ([gate, values.stage, values.waiting].filter((v) => v !== undefined).length !== 1) throw new UsageError(usage);
|
|
37
|
-
if (values.waiting !== undefined && !values.waiting.trim()) throw new UsageError('--waiting needs a reason: what the user has to do or decide');
|
|
38
|
-
if (gate && !GATES.includes(gate)) throw new UsageError(`--gate-requested must be one of: ${GATES.join(', ')}`);
|
|
39
|
-
if (values.stage && !STAGES.includes(values.stage)) throw new UsageError(`--stage must be one of: ${STAGES.join(', ')}`);
|
|
40
|
-
const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
|
|
41
|
-
|
|
42
|
-
if (values.waiting !== undefined) {
|
|
43
|
-
appendLog(feature.dir, ctx.now(), 'waiting', { reason: values.waiting.trim().replace(/\s+/g, ' ') });
|
|
44
|
-
} else if (gate) {
|
|
45
|
-
// A gate is handed to the human only when approving it can succeed.
|
|
46
|
-
const { problems } = gateReadiness(ctx, feature, gate);
|
|
47
|
-
if (problems.length) {
|
|
48
|
-
throw new AgjanError(`the ${gate} gate is not ready; nothing logged:\n${problems.map((p) => ` - ${p}`).join('\n')}`);
|
|
49
|
-
}
|
|
50
|
-
const message = cleanMessage(values.message);
|
|
51
|
-
appendLog(feature.dir, ctx.now(), 'gate-requested', message ? { gate, message } : { gate });
|
|
52
|
-
} else {
|
|
53
|
-
const fields = { stage: values.stage };
|
|
54
|
-
for (const key of ['role', 'task', 'skill', 'host']) if (values[key]) fields[key] = values[key];
|
|
55
|
-
// The configured model only; the actual model comes from host transcripts (design 12.2).
|
|
56
|
-
if (values.model) fields.configured_model = values.model;
|
|
57
|
-
appendLog(feature.dir, ctx.now(), 'step', fields);
|
|
58
|
-
}
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
package/src/commands/map.mjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { parseArgs } from 'node:util';
|
|
4
|
-
import { writeJson } from '../json-file.mjs';
|
|
5
|
-
import { APPROVALS_FILE, FEATURES_DIR, changedFeatures, emptyApprovals, featureDir } from '../feature.mjs';
|
|
6
|
-
import { PROJECT_MD } from '../fix.mjs';
|
|
7
|
-
import { BASELINE_FILE, refreshBaseline } from '../baseline.mjs';
|
|
8
|
-
import { appendLog } from '../log.mjs';
|
|
9
|
-
import { AgjanError, UsageError } from '../errors.mjs';
|
|
10
|
-
|
|
11
|
-
const TEMPLATE = new URL('../../kit/templates/project.md', import.meta.url);
|
|
12
|
-
/** Map runs need finding ids but no unique key: their findings stay in their own folder. */
|
|
13
|
-
const MAP_KEY = 'MAP';
|
|
14
|
-
|
|
15
|
-
/** agjan map start: a record folder for this map run, and project.md from the template if absent. */
|
|
16
|
-
function start(ctx) {
|
|
17
|
-
const root = ctx.root;
|
|
18
|
-
const changed = changedFeatures(root, ctx.config);
|
|
19
|
-
if (changed.length) throw new AgjanError(`this branch already carries ${changed.join(', ')}; map the project on its own branch`);
|
|
20
|
-
const date = ctx.now().slice(0, 10);
|
|
21
|
-
let id = date;
|
|
22
|
-
for (let n = 2; existsSync(featureDir(root, `maps/${id}`)); n += 1) id = `${date}-${n}`;
|
|
23
|
-
const dir = featureDir(root, `maps/${id}`);
|
|
24
|
-
mkdirSync(dir, { recursive: true });
|
|
25
|
-
writeJson(join(dir, APPROVALS_FILE), emptyApprovals(id, MAP_KEY, ctx.kit, ctx.now(), 'map'));
|
|
26
|
-
appendLog(dir, ctx.now(), 'step', { stage: 'map', skill: 'agjan-map' });
|
|
27
|
-
ctx.out(`created ${FEATURES_DIR}/maps/${id}/`);
|
|
28
|
-
if (!existsSync(join(root, PROJECT_MD))) {
|
|
29
|
-
writeFileSync(join(root, PROJECT_MD), readFileSync(TEMPLATE, 'utf8'));
|
|
30
|
-
ctx.out(`created ${PROJECT_MD} from the template`);
|
|
31
|
-
}
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function map(ctx, argv) {
|
|
36
|
-
if (argv[0] === 'start' && argv.length === 1) return start(ctx);
|
|
37
|
-
throw new UsageError('usage: agjan map start');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** agjan baseline refresh: records the hashes of the watched files in baseline.json. */
|
|
41
|
-
export function baseline(ctx, argv) {
|
|
42
|
-
const { positionals } = parseArgs({ args: argv, allowPositionals: true });
|
|
43
|
-
if (positionals.join(' ') !== 'refresh') throw new UsageError('usage: agjan baseline refresh');
|
|
44
|
-
const data = refreshBaseline(ctx.root, ctx.config, ctx.now());
|
|
45
|
-
ctx.out(`wrote ${BASELINE_FILE}: ${Object.keys(data.watched).length} watched file(s)`);
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
package/src/commands/new.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { parseArgs } from 'node:util';
|
|
4
|
-
import { writeJson } from '../json-file.mjs';
|
|
5
|
-
import { APPROVALS_FILE, FEATURES_DIR, KEY, SLUG, emptyApprovals, featureDir, listFeatures, loadFeature, selectFeature } from '../feature.mjs';
|
|
6
|
-
import { AgjanError, UsageError } from '../errors.mjs';
|
|
7
|
-
|
|
8
|
-
const TEMPLATES = new URL('../../kit/templates/', import.meta.url);
|
|
9
|
-
|
|
10
|
-
export function renderTemplate(name, { slug, key }) {
|
|
11
|
-
return readFileSync(new URL(name, TEMPLATES), 'utf8').replaceAll('{{SLUG}}', slug).replaceAll('{{KEY}}', key);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** agjan scaffold design [--feature <slug>]: creates design.md and tasks.md from the templates. */
|
|
15
|
-
export function scaffold(ctx, argv) {
|
|
16
|
-
const { values, positionals } = parseArgs({ args: argv, options: { feature: { type: 'string' } }, allowPositionals: true });
|
|
17
|
-
if (positionals.join(' ') !== 'design') throw new UsageError('usage: agjan scaffold design [--feature <slug>]');
|
|
18
|
-
const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
|
|
19
|
-
for (const name of ['design.md', 'tasks.md']) {
|
|
20
|
-
const file = join(feature.dir, name);
|
|
21
|
-
if (existsSync(file)) {
|
|
22
|
-
ctx.out(`${FEATURES_DIR}/${feature.slug}/${name} exists; not changed`);
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
writeFileSync(file, renderTemplate(name, { slug: feature.slug, key: feature.key }));
|
|
26
|
-
ctx.out(`created ${FEATURES_DIR}/${feature.slug}/${name}`);
|
|
27
|
-
}
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** agjan new <slug> --key <KEY>: creates the feature folder, approvals.json and spec.md. */
|
|
32
|
-
export function run(ctx, argv) {
|
|
33
|
-
const { values, positionals } = parseArgs({ args: argv, options: { key: { type: 'string' } }, allowPositionals: true });
|
|
34
|
-
const [slug] = positionals;
|
|
35
|
-
if (!slug || positionals.length > 1 || !values.key) throw new UsageError('usage: agjan new <slug> --key <KEY>');
|
|
36
|
-
if (!SLUG.test(slug)) throw new UsageError(`slug '${slug}' must be lowercase letters, digits and '-', at most 48 characters`);
|
|
37
|
-
if (slug === 'fixes') throw new UsageError("'fixes' is reserved");
|
|
38
|
-
const key = values.key;
|
|
39
|
-
if (!KEY.test(key)) throw new UsageError(`key '${key}' must be 2 to 6 uppercase letters or digits, starting with a letter`);
|
|
40
|
-
|
|
41
|
-
const root = ctx.root;
|
|
42
|
-
const dir = featureDir(root, slug);
|
|
43
|
-
if (existsSync(dir)) throw new AgjanError(`${FEATURES_DIR}/${slug} already exists`);
|
|
44
|
-
for (const other of listFeatures(root)) {
|
|
45
|
-
if (loadFeature(root, other).key === key) throw new AgjanError(`key ${key} is already used by feature '${other}'`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
mkdirSync(dir, { recursive: true });
|
|
49
|
-
writeJson(join(dir, APPROVALS_FILE), emptyApprovals(slug, key, ctx.kit, ctx.now()));
|
|
50
|
-
writeFileSync(join(dir, 'spec.md'), renderTemplate('spec.md', { slug, key }));
|
|
51
|
-
ctx.out(`created ${FEATURES_DIR}/${slug}/ (key ${key}): ${APPROVALS_FILE}, spec.md`);
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from 'node:util';
|
|
2
|
-
import { resolveArea } from '../config.mjs';
|
|
3
|
-
import { FEATURES_DIR } from '../feature.mjs';
|
|
4
|
-
import { acTestFiles } from '../tests-map.mjs';
|
|
5
|
-
import { acResults, loadResults, resultLabel } from '../test-results.mjs';
|
|
6
|
-
import { overrideBase, runChecks } from './check.mjs';
|
|
7
|
-
import { readFix } from './fix.mjs';
|
|
8
|
-
import { highlightMarkdown } from '../ui.mjs';
|
|
9
|
-
import { readLog } from '../log.mjs';
|
|
10
|
-
|
|
11
|
-
function short(hash) {
|
|
12
|
-
return hash ? hash.slice('sha256:'.length, 'sha256:'.length + 12) : '-';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** A fix or a map run in the PR summary. */
|
|
16
|
-
function recordSection(feature) {
|
|
17
|
-
const out = [`### ${feature.kind === 'fix' ? 'Fix' : 'Map run'} ${feature.slug} (${feature.key})`, ''];
|
|
18
|
-
if (feature.kind === 'fix') {
|
|
19
|
-
const fix = readFix(feature);
|
|
20
|
-
out.push(`**What:** ${fix?.what ?? '(not stated)'}`, '');
|
|
21
|
-
if (fix?.files) {
|
|
22
|
-
out.push(`**Size:** ${fix.total} changed lines (limit ${fix.limits.max_total}, per file ${fix.limits.max_per_file})`, '');
|
|
23
|
-
out.push(`**Verified with:** ${fix.verify ?? 'not stated'}`, '');
|
|
24
|
-
} else {
|
|
25
|
-
out.push('**Not recorded yet** (`npx agjan fix record`).', '');
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
out.push('Writes the baseline `docs/agjan/project.md` and `docs/agjan/baseline.json`.', '');
|
|
29
|
-
}
|
|
30
|
-
for (const r of feature.reviews.records) out.push(`- ${r.id} ${r.step} round ${r.round}: ${r.verdict} (${r.findings?.length ?? 0} findings, isolation ${r.reviewer?.isolation ?? 'unknown'})`);
|
|
31
|
-
if (feature.reviews.records.length) out.push('');
|
|
32
|
-
return out;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function featureSection(ctx, feature) {
|
|
36
|
-
if (feature.kind !== 'feature') return recordSection(feature);
|
|
37
|
-
const out = [];
|
|
38
|
-
const mode = feature.design?.parsed.mode ?? '-';
|
|
39
|
-
out.push(`### ${feature.slug} (${feature.key})`, '');
|
|
40
|
-
out.push('| Document | State | Hash | Approved |', '|---|---|---|---|');
|
|
41
|
-
const spec = feature.approvals.approvals.spec;
|
|
42
|
-
const design = feature.approvals.approvals.design;
|
|
43
|
-
out.push(`| spec.md | ${feature.state.spec} | ${short(feature.spec?.hash)} | ${spec ? `${spec.at_utc} by ${spec.by}` : '-'} |`);
|
|
44
|
-
out.push(`| design (${mode}) | ${feature.state.design} | ${short(feature.designHash)} | ${design ? `${design.at_utc} by ${design.by}` : '-'} |`, '');
|
|
45
|
-
|
|
46
|
-
if (feature.spec && feature.tasks) {
|
|
47
|
-
const areaNames = [...new Set(feature.tasks.parsed.tasks.map((t) => resolveArea(ctx.config, t.area)?.name).filter(Boolean))];
|
|
48
|
-
const tests = acTestFiles(ctx.root, ctx.config, areaNames, feature.key);
|
|
49
|
-
const tasksFor = (id) => feature.tasks.parsed.tasks.filter((t) => t.covers.includes(id)).map((t) => t.id).join(', ') || '-';
|
|
50
|
-
const loaded = loadResults(ctx.root, ctx.config, areaNames);
|
|
51
|
-
const results = loaded.files.length ? acResults(loaded, feature.key) : null;
|
|
52
|
-
out.push('**Acceptance criteria**', '');
|
|
53
|
-
out.push(results ? '| AC | Verification | Tasks | Tests | Result |' : '| AC | Verification | Tasks | Tests |');
|
|
54
|
-
out.push(results ? '|---|---|---|---|---|' : '|---|---|---|---|');
|
|
55
|
-
for (const ac of feature.spec.parsed.acs) {
|
|
56
|
-
const files = [...(tests.get(ac.id) ?? [])].join(', ');
|
|
57
|
-
const manual = ac.verification === 'manual';
|
|
58
|
-
const row = `| ${ac.id} | ${ac.verification} | ${tasksFor(ac.id)} | ${manual ? 'manual' : files || '**missing**'} |`;
|
|
59
|
-
if (!results) out.push(row);
|
|
60
|
-
else out.push(`${row} ${manual ? '-' : resultLabel(results.get(ac.id)).replace(/^(failed|not run|skipped)$/, '**$1**')} |`);
|
|
61
|
-
}
|
|
62
|
-
out.push('');
|
|
63
|
-
if (results) out.push(`Results from ${loaded.files.map((f) => `\`${f.file}\``).join(', ')}.`, '');
|
|
64
|
-
else out.push('Test coverage is by AC id in test files (existence only).', '');
|
|
65
|
-
const manual = feature.spec.parsed.acs.filter((ac) => ac.verification === 'manual');
|
|
66
|
-
if (manual.length) {
|
|
67
|
-
out.push('**Verify before merge (manual ACs):**', '');
|
|
68
|
-
for (const ac of manual) out.push(`- [ ] ${ac.id}`);
|
|
69
|
-
out.push('');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (feature.reviews.records.length) {
|
|
74
|
-
out.push('**Reviews**', '', '| Review | Step | Round | Verdict | Findings | Isolation |', '|---|---|---|---|---|---|');
|
|
75
|
-
for (const r of feature.reviews.records) {
|
|
76
|
-
out.push(`| ${r.id} | ${r.step} | ${r.round} | ${r.verdict} | ${r.findings?.length ?? 0} | ${r.reviewer?.isolation ?? 'unknown'} |`);
|
|
77
|
-
}
|
|
78
|
-
out.push('');
|
|
79
|
-
const weak = feature.reviews.records.filter((r) => r.reviewer?.isolation !== 'agent');
|
|
80
|
-
if (weak.length) out.push(`Reviews without an isolated reviewer agent: ${weak.map((r) => r.id).join(', ')}.`, '');
|
|
81
|
-
const granted = readLog(feature.dir).filter((e) => e.event === 'round-granted');
|
|
82
|
-
if (granted.length) out.push(`Rounds beyond the limit, allowed by the user: ${granted.map((e) => `${e.step} round ${e.round}`).join(', ')}.`, '');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const open = feature.findings.filter((f) => f.status === 'open');
|
|
86
|
-
const accepted = feature.findings.filter((f) => f.status === 'accepted');
|
|
87
|
-
if (open.length) {
|
|
88
|
-
out.push('**Open findings**', '');
|
|
89
|
-
for (const f of open) out.push(`- ${f.id} [${f.severity}] ${f.issue}`);
|
|
90
|
-
out.push('');
|
|
91
|
-
}
|
|
92
|
-
if (accepted.length) {
|
|
93
|
-
out.push('**Accepted findings**', '');
|
|
94
|
-
for (const f of accepted) {
|
|
95
|
-
const a = feature.approvals.accepted.find((x) => x.finding === f.id);
|
|
96
|
-
out.push(`- ${f.id} [${f.severity}] ${f.issue} (accepted by ${a.by}: ${a.reason})`);
|
|
97
|
-
}
|
|
98
|
-
out.push('');
|
|
99
|
-
}
|
|
100
|
-
const amendments = feature.amendments.filter((a) => a.status !== 'lapsed');
|
|
101
|
-
if (amendments.length) {
|
|
102
|
-
out.push('**Scope amendments**', '');
|
|
103
|
-
for (const a of amendments) out.push(`- ${a.id} (${a.task}, ${a.status}): ${a.paths.join(', ')}: ${a.reason}`);
|
|
104
|
-
out.push('');
|
|
105
|
-
}
|
|
106
|
-
return out;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** agjan pr-summary [--feature <slug>]: prints the PR description in Markdown (design 6.6). */
|
|
110
|
-
export function run(ctx, argv) {
|
|
111
|
-
const { values } = parseArgs({ args: argv, options: { feature: { type: 'string' }, base: { type: 'string' } } });
|
|
112
|
-
overrideBase(ctx, values.base);
|
|
113
|
-
const { report, features, files, policy } = runChecks(ctx, 'ci', values.feature);
|
|
114
|
-
const out = ['## agjan summary', ''];
|
|
115
|
-
|
|
116
|
-
if (features.length === 0) out.push('No agjan feature in this change.', '');
|
|
117
|
-
for (const feature of features) out.push(...featureSection(ctx, feature));
|
|
118
|
-
|
|
119
|
-
const code = files.filter((f) => !f.startsWith(`${FEATURES_DIR}/`) && !f.startsWith('.agjan/'));
|
|
120
|
-
out.push(`**Changed files** (${code.length} outside ${FEATURES_DIR}/)`, '');
|
|
121
|
-
for (const f of code) out.push(`- ${f}`);
|
|
122
|
-
if (code.length) out.push('');
|
|
123
|
-
if (files.includes(`${FEATURES_DIR}/project.md`)) out.push('The baseline `docs/agjan/project.md` is updated in this change.', '');
|
|
124
|
-
|
|
125
|
-
if (policy.length) {
|
|
126
|
-
out.push('**Policy changes** (these change the rules that check this PR)', '');
|
|
127
|
-
for (const p of policy) out.push(`- ${p}`);
|
|
128
|
-
out.push('');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const state = report.errors > 0 ? `**failing**: ${report.errors} error(s)` : 'passing';
|
|
132
|
-
out.push(`**agjan check --ci**: ${state}, ${report.warnings} warning(s)`, '');
|
|
133
|
-
for (const item of report.items.filter((i) => i.level === 'error')) out.push(`- ${item.scope}: ${item.message}`);
|
|
134
|
-
if (report.errors) out.push('');
|
|
135
|
-
ctx.out(highlightMarkdown(ctx.style, out.join('\n').trimEnd()));
|
|
136
|
-
return 0;
|
|
137
|
-
}
|