agjan 0.0.10 → 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 +98 -37
- package/kit/domains/btp/domain.json +4 -4
- package/kit/hooks/guard.mjs +48 -119
- package/kit/skills/agjan-build/SKILL.md +14 -8
- package/kit/skills/agjan-design/SKILL.md +42 -6
- package/kit/skills/agjan-fix/SKILL.md +9 -10
- package/kit/skills/agjan-map/SKILL.md +9 -10
- package/kit/skills/agjan-spec/SKILL.md +22 -11
- package/kit/skills/agjan-verify/SKILL.md +46 -19
- package/kit/skills/cap-developer/SKILL.md +10 -2
- package/kit/skills/cap-developer/references/handlers.md +11 -9
- package/kit/skills/cap-developer/references/project-setup.md +21 -8
- package/kit/skills/cap-developer/references/testing.md +38 -14
- package/kit/skills/cap-developer/references/typescript.md +143 -0
- package/kit/skills/cap-developer/references/validation-security.md +26 -8
- package/kit/skills/fiori-developer/SKILL.md +20 -5
- package/kit/skills/fiori-developer/references/app-setup.md +91 -16
- package/kit/skills/fiori-developer/references/elements.md +19 -5
- package/kit/skills/fiori-developer/references/freestyle-ts.md +5 -1
- package/kit/skills/fiori-developer/references/testing.md +109 -15
- package/kit/templates/agents-block.md +7 -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/cli.mjs +0 -155
- package/src/commands/branch.mjs +0 -60
- package/src/commands/check.mjs +0 -365
- package/src/commands/fix.mjs +0 -116
- package/src/commands/gates.mjs +0 -264
- 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 -76
- package/src/commands/setup.mjs +0 -383
- package/src/commands/status.mjs +0 -248
- 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 -413
- 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
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { FEATURES_DIR, changedFeatures, listFeatures, loadFeature, selectFeature, stillBlocked } from '../feature.js';
|
|
3
|
+
import { UsageError } from '../errors.js';
|
|
4
|
+
import { acceptanceState, buildProgress, verifyState } from '../progress.js';
|
|
5
|
+
import { gateReadiness, pendingGate } from './gates.js';
|
|
6
|
+
import { fixRules, freshReview } from '../fix.js';
|
|
7
|
+
import { projectProblems } from '../baseline.js';
|
|
8
|
+
import { readFix } from './fix.js';
|
|
9
|
+
import { fixAttempts, reviewerFor, roundLimit, roundState } from '../review-policy.js';
|
|
10
|
+
import { blink, mark, markLine, pad, tone } from '../ui.js';
|
|
11
|
+
import { acTestFiles } from '../tests-map.js';
|
|
12
|
+
import { acResults, loadResults } from '../test-results.js';
|
|
13
|
+
import { NOT_ACCEPTED, runChecks } from './check.js';
|
|
14
|
+
import { readLog } from '../log.js';
|
|
15
|
+
import { finalSteps } from '../progress-view.js';
|
|
16
|
+
import { readAutoDefault } from '../auto.js';
|
|
17
|
+
/** One indented row: a label column, then the value. `next` and `blocks` stand out. */
|
|
18
|
+
function row(ctx, label, value) {
|
|
19
|
+
const s = ctx.style;
|
|
20
|
+
const styled = { next: s.bold(s.cyan(label)), blocks: s.red(label) }[label] ?? s.gray(label);
|
|
21
|
+
ctx.out(` ${pad(styled, label, 8)} ${value}`);
|
|
22
|
+
}
|
|
23
|
+
/** The unit's heading: slug, key and stage (or kind). */
|
|
24
|
+
function heading(ctx, unit, detail) {
|
|
25
|
+
const s = ctx.style;
|
|
26
|
+
ctx.out(`${s.bold(unit.slug)} (${s.cyan(unit.key)}) ${detail}`);
|
|
27
|
+
}
|
|
28
|
+
/** "review step X with agent Y", or the hand-over when the step used up its rounds. */
|
|
29
|
+
function reviewNext(ctx, feature, step) {
|
|
30
|
+
const state = roundState(feature, ctx.config, step);
|
|
31
|
+
if (state.exhausted) {
|
|
32
|
+
return `the ${step} review is still blocked after ${state.round} of ${state.limit} rounds: ask the user whether to run another round (yes: npx agjan review extend ${step}) or to stop and take over (fix with them, accept findings, or change the documents)`;
|
|
33
|
+
}
|
|
34
|
+
const round = state.round ? `, round ${state.next} of ${state.limit}` : '';
|
|
35
|
+
return `review step ${step} with ${reviewerFor(ctx.config, step)}${round}`;
|
|
36
|
+
}
|
|
37
|
+
/** The review step a feature in Spec or Design needs next. */
|
|
38
|
+
function gateStep(feature) {
|
|
39
|
+
if (feature.stage === 'design')
|
|
40
|
+
return 'design';
|
|
41
|
+
return feature.design?.parsed.mode === 'light' ? 'design:light' : 'spec';
|
|
42
|
+
}
|
|
43
|
+
/** The next action in Build: a due review first, then the next task, then Verify, then the PR. */
|
|
44
|
+
function nextInBuild(ctx, feature, progress) {
|
|
45
|
+
// The same rule as the progress pages: a skill runs once it logged its start (decision 70).
|
|
46
|
+
const events = readLog(feature.dir);
|
|
47
|
+
const since = feature.approvals.approvals.design?.at_utc;
|
|
48
|
+
const building = events.some((e) => e.event === 'step' && e.stage === 'build' && (!since || e.at_utc >= since));
|
|
49
|
+
const lastStage = events.filter((e) => e.event === 'step').at(-1)?.stage;
|
|
50
|
+
if (!building && (progress.next || progress.due.length)) {
|
|
51
|
+
const first = progress.next ? ` (first task ${progress.next.id}: ${progress.next.title})` : '';
|
|
52
|
+
return feature.approvals.auto ? `auto mode: the agent goes on with the build: /agjan-build${first}` : `a human starts the build: /agjan-build${first}`;
|
|
53
|
+
}
|
|
54
|
+
if (progress.due.length)
|
|
55
|
+
return reviewNext(ctx, feature, progress.due[0].step);
|
|
56
|
+
if (progress.next)
|
|
57
|
+
return `task ${progress.next.id}: ${progress.next.title} (commit as '<KEY>-${progress.next.id}: …')`;
|
|
58
|
+
const { state, record } = verifyState(ctx.root, ctx.config, feature);
|
|
59
|
+
if (state === 'blocked')
|
|
60
|
+
return `the verify review ${record.id} is blocked: resolve its findings, then /agjan-verify again`;
|
|
61
|
+
if (state === 'stale')
|
|
62
|
+
return `files changed after the verify review ${record.id}: /agjan-verify again`;
|
|
63
|
+
if (state === 'current') {
|
|
64
|
+
const acceptance = acceptanceState(ctx.root, ctx.config, feature, { state, record });
|
|
65
|
+
if (acceptance.state === 'accepted')
|
|
66
|
+
return `${ctx.style.green('done')}: verified (${record.id}) and accepted by ${acceptance.approval.by}; the next steps below are optional`;
|
|
67
|
+
return `${ctx.style.green('verified')} (${record.id}): a human accepts it in a terminal: '${ctx.style.bold('npx agjan approve verify')}'`;
|
|
68
|
+
}
|
|
69
|
+
if (lastStage === 'verify')
|
|
70
|
+
return 'verify is running: /agjan-verify';
|
|
71
|
+
return feature.approvals.auto ? 'all tasks done and reviewed: auto mode: the agent goes on with /agjan-verify' : 'all tasks done and reviewed: a human starts the verification: /agjan-verify';
|
|
72
|
+
}
|
|
73
|
+
/** "2 open, 1 blocker(s)", red when a blocker is open. */
|
|
74
|
+
function findingCount(ctx, open) {
|
|
75
|
+
const blockers = open.filter((f) => f.severity === 'blocker').length;
|
|
76
|
+
const text = `${open.length} open, ${blockers} blocker(s)`;
|
|
77
|
+
return blockers ? ctx.style.red(text) : ctx.style.yellow(text);
|
|
78
|
+
}
|
|
79
|
+
/** A fix or a map run: its checks, its review, and the next step. */
|
|
80
|
+
function describeRecord(ctx, unit, onBase = false) {
|
|
81
|
+
if (onBase)
|
|
82
|
+
return describeRecordOnBase(ctx, unit);
|
|
83
|
+
heading(ctx, unit, ctx.style.magenta(unit.kind));
|
|
84
|
+
const problems = unit.kind === 'fix' ? fixRules(ctx.root, ctx.config).problems : projectProblems(ctx.root, ctx.config);
|
|
85
|
+
for (const p of problems)
|
|
86
|
+
row(ctx, 'blocks', p);
|
|
87
|
+
const review = freshReview(ctx.root, ctx.config, unit, unit.kind);
|
|
88
|
+
const record = review.record;
|
|
89
|
+
row(ctx, 'review', review.problem ?? `${record.id} ${tone(ctx.style, record.verdict)}, ${tone(ctx.style, 'current')}`);
|
|
90
|
+
const open = unit.findings.filter((f) => f.status === 'open');
|
|
91
|
+
if (open.length)
|
|
92
|
+
row(ctx, 'findings', findingCount(ctx, open));
|
|
93
|
+
let next;
|
|
94
|
+
if (problems.length)
|
|
95
|
+
next = unit.kind === 'fix' ? 'the change is not a fix: revert it and use /agjan-spec' : `complete docs/agjan/project.md`;
|
|
96
|
+
else if (review.problem)
|
|
97
|
+
next = reviewNext(ctx, unit, unit.kind);
|
|
98
|
+
else if (unit.kind === 'fix' && readFix(unit)?.review?.tree_hash !== record.tree_hash)
|
|
99
|
+
next = 'npx agjan fix record --verify "<command and result>"';
|
|
100
|
+
else
|
|
101
|
+
next = unit.kind === 'map' ? 'npx agjan baseline refresh, commit, open a PR' : 'commit and open a PR';
|
|
102
|
+
row(ctx, 'next', next);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A feature that did not change on this branch is already on the base branch (merged, or
|
|
106
|
+
* committed there directly): its tasks come from the whole history, and work on it
|
|
107
|
+
* continues as a new feature on a branch.
|
|
108
|
+
*/
|
|
109
|
+
function describeOnBase(ctx, feature) {
|
|
110
|
+
const s = ctx.style;
|
|
111
|
+
const progress = buildProgress(ctx.root, ctx.config, feature, { history: true });
|
|
112
|
+
const verify = feature.reviews.records.filter((r) => r.step === 'verify').at(-1);
|
|
113
|
+
const merged = progress.complete && verify && !stillBlocked(feature, verify);
|
|
114
|
+
heading(ctx, feature, merged ? `stage: ${s.green('merged')}` : `stage: ${s.magenta(feature.stage)} (on the base branch)`);
|
|
115
|
+
row(ctx, 'spec', tone(s, feature.state.spec));
|
|
116
|
+
row(ctx, 'design', `${tone(s, feature.state.design)}${feature.design?.parsed.mode ? ` (${feature.design.parsed.mode})` : ''}`);
|
|
117
|
+
const reviews = feature.reviews.records;
|
|
118
|
+
const latest = reviews.at(-1);
|
|
119
|
+
if (latest)
|
|
120
|
+
row(ctx, 'reviews', `${reviews.length}, last ${latest.id} ${latest.step}: ${tone(s, latest.verdict)}`);
|
|
121
|
+
for (const t of progress.tasks) {
|
|
122
|
+
row(ctx, 'task', `${tone(s, t.commit ? 'done' : 'open')} ${t.id} [${t.areaName}] ${t.title}${t.commit ? s.gray(` (${t.commit.slice(0, 7)})`) : ''}`);
|
|
123
|
+
}
|
|
124
|
+
if (!merged)
|
|
125
|
+
row(ctx, 'next', 'continue on a feature branch, or start follow-up work as a new feature');
|
|
126
|
+
}
|
|
127
|
+
/** A fix or a map run already on the base branch: merged once its last review passed. */
|
|
128
|
+
function describeRecordOnBase(ctx, unit) {
|
|
129
|
+
const s = ctx.style;
|
|
130
|
+
const last = unit.reviews.records.at(-1);
|
|
131
|
+
const merged = last && !stillBlocked(unit, last);
|
|
132
|
+
heading(ctx, unit, `${s.magenta(unit.kind)} ${merged ? `stage: ${s.green('merged')}` : '(on the base branch)'}`);
|
|
133
|
+
row(ctx, 'review', last ? `${last.id} ${tone(s, last.verdict)}` : 'none');
|
|
134
|
+
const open = unit.findings.filter((f) => f.status === 'open');
|
|
135
|
+
if (open.length)
|
|
136
|
+
row(ctx, 'findings', findingCount(ctx, open));
|
|
137
|
+
if (!merged)
|
|
138
|
+
row(ctx, 'next', `start follow-up work on a branch (/agjan-${unit.kind === 'fix' ? 'fix' : 'map'})`);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The end of a feature's agent work (verified, CI check clean or not): a screen that says
|
|
142
|
+
* so unmistakably, what was met, and what the human does next: try it, check the manual
|
|
143
|
+
* ACs and accept it with `approve verify` (Gate 3, decision 77); once accepted, the
|
|
144
|
+
* optional pull request. Colored with the agjan mark on a terminal; the same content as
|
|
145
|
+
* plain text for agents, who end /agjan-verify with it.
|
|
146
|
+
*/
|
|
147
|
+
async function completion(ctx, feature, progress) {
|
|
148
|
+
const s = ctx.style;
|
|
149
|
+
const areaNames = [...new Set(progress.tasks.map((t) => t.areaName))];
|
|
150
|
+
const acs = feature.spec.parsed.acs;
|
|
151
|
+
const automated = acs.filter((ac) => ac.verification !== 'manual');
|
|
152
|
+
const manual = acs.filter((ac) => ac.verification === 'manual');
|
|
153
|
+
const loaded = loadResults(ctx.root, ctx.config, areaNames);
|
|
154
|
+
const results = loaded.files.length ? acResults(loaded, feature.key) : null;
|
|
155
|
+
const tests = acTestFiles(ctx.root, ctx.config, areaNames, feature.key);
|
|
156
|
+
const covered = automated.filter((ac) => (results ? results.get(ac.id)?.passed && !results.get(ac.id)?.failed : tests.has(ac.id))).length;
|
|
157
|
+
const { report } = runChecks(ctx, 'ci', feature.slug);
|
|
158
|
+
const errors = report.items.filter((i) => i.level === 'error' && !i.message.startsWith(NOT_ACCEPTED)).length;
|
|
159
|
+
const acceptance = acceptanceState(ctx.root, ctx.config, feature);
|
|
160
|
+
const accepted = acceptance.state === 'accepted';
|
|
161
|
+
const open = feature.findings.filter((f) => f.status === 'open');
|
|
162
|
+
const blockers = open.filter((f) => f.severity === 'blocker').length;
|
|
163
|
+
const ok = (text) => `${s.teal('✔')} ${text}`;
|
|
164
|
+
const bad = (text) => `${s.red('✖')} ${text}`;
|
|
165
|
+
const lines = [
|
|
166
|
+
[ok(`tasks ${progress.tasks.length}/${progress.tasks.length}`), (covered === automated.length ? ok : bad)(`ACs ${covered}/${automated.length} ${results ? 'with passing tests' : 'with tests'}`),
|
|
167
|
+
errors ? bad(`check --ci: ${errors} error(s)`) : ok('check --ci clean')].join(' '),
|
|
168
|
+
[(blockers ? bad : ok)(`reviews ${feature.reviews.records.length}, ${blockers} blocker(s) open`), open.length - blockers ? `${s.gray('●')} ${open.length - blockers} note(s) open` : ok('no open notes')].join(' '),
|
|
169
|
+
];
|
|
170
|
+
if (accepted)
|
|
171
|
+
lines.push(ok(`accepted by ${acceptance.approval.by} (${acceptance.approval.at_utc})`));
|
|
172
|
+
const title = accepted ? `${feature.key} is done` : `${feature.key} is verified`;
|
|
173
|
+
const detail = accepted ? 'implemented, verified and accepted' : 'development finished and verified; your acceptance is next';
|
|
174
|
+
ctx.out();
|
|
175
|
+
if (s.brand) {
|
|
176
|
+
const stars = `${s.teal('✦')} ${s.violet('✦')} ${s.teal('✦')}`;
|
|
177
|
+
const logo = mark(s, ctx.kit, `${stars} ${s.bold(title)} ${stars}`, `${feature.slug} · ${detail}`);
|
|
178
|
+
for (const line of logo)
|
|
179
|
+
ctx.out(line);
|
|
180
|
+
await blink(ctx, logo);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
ctx.out(`✔ ${title}: ${detail} (${feature.slug})`);
|
|
184
|
+
}
|
|
185
|
+
for (const line of lines)
|
|
186
|
+
ctx.out(` ${line}`);
|
|
187
|
+
const { yours, optional } = finalSteps(ctx.root, feature, { manual: manual.map((ac) => ac.id), accepted });
|
|
188
|
+
if (yours.length) {
|
|
189
|
+
ctx.out(` ${s.bold('Your turn, in a terminal:')}`);
|
|
190
|
+
for (const step of yours)
|
|
191
|
+
ctx.out(` ${s.violet('▸')} ${step}`);
|
|
192
|
+
}
|
|
193
|
+
ctx.out(` ${s.bold(accepted ? 'Optional next steps:' : 'Then, optional:')}`);
|
|
194
|
+
for (const step of optional)
|
|
195
|
+
ctx.out(` ${s.violet('▸')} ${step}`);
|
|
196
|
+
}
|
|
197
|
+
async function describe(ctx, feature, onBase = false) {
|
|
198
|
+
if (feature.kind !== 'feature')
|
|
199
|
+
return describeRecord(ctx, feature, onBase);
|
|
200
|
+
if (onBase)
|
|
201
|
+
return describeOnBase(ctx, feature);
|
|
202
|
+
heading(ctx, feature, `stage: ${ctx.style.magenta(feature.stage)}`);
|
|
203
|
+
row(ctx, 'spec', tone(ctx.style, feature.state.spec));
|
|
204
|
+
const mode = feature.design?.parsed.mode ? ` (${feature.design.parsed.mode})` : '';
|
|
205
|
+
row(ctx, 'design', `${tone(ctx.style, feature.state.design)}${mode}`);
|
|
206
|
+
const auto = feature.approvals.auto;
|
|
207
|
+
if (auto)
|
|
208
|
+
row(ctx, 'auto', `${ctx.style.yellow('on')} (switched on by ${auto.by}, ${auto.at_utc}): spec and design pass automatically after their reviews; approve verify stays yours`);
|
|
209
|
+
const steps = [...new Set(feature.reviews.records.map((r) => r.step))];
|
|
210
|
+
for (const step of steps) {
|
|
211
|
+
const records = feature.reviews.records.filter((r) => r.step === step);
|
|
212
|
+
const last = records[records.length - 1];
|
|
213
|
+
const { limit, extra } = roundState(feature, ctx.config, step);
|
|
214
|
+
row(ctx, 'review', `${step}: ${tone(ctx.style, last.verdict)} (round ${last.round} of ${limit}${extra ? `, ${extra} granted by the user` : ''}, ${last.id})`);
|
|
215
|
+
}
|
|
216
|
+
const open = feature.findings.filter((f) => f.status === 'open');
|
|
217
|
+
if (open.length) {
|
|
218
|
+
row(ctx, 'findings', findingCount(ctx, open));
|
|
219
|
+
}
|
|
220
|
+
for (const a of feature.amendments.filter((x) => x.status !== 'approved')) {
|
|
221
|
+
row(ctx, 'amend', `${a.id} ${tone(ctx.style, a.status)}: ${a.paths.join(', ')}`);
|
|
222
|
+
}
|
|
223
|
+
if (feature.stage === 'build') {
|
|
224
|
+
const progress = buildProgress(ctx.root, ctx.config, feature);
|
|
225
|
+
for (const t of progress.tasks) {
|
|
226
|
+
row(ctx, 'task', `${tone(ctx.style, t.commit ? 'done' : 'open')} ${t.id} [${t.areaName}] ${t.title}${t.commit ? ctx.style.gray(` (${t.commit.slice(0, 7)})`) : ''}`);
|
|
227
|
+
}
|
|
228
|
+
for (const d of progress.due)
|
|
229
|
+
row(ctx, 'due', ctx.style.yellow(`review ${d.step} (${d.reason})`));
|
|
230
|
+
row(ctx, 'next', nextInBuild(ctx, feature, progress).replace('<KEY>', feature.key));
|
|
231
|
+
const verify = verifyState(ctx.root, ctx.config, feature);
|
|
232
|
+
if (progress.complete && progress.due.length === 0 && verify.state === 'current')
|
|
233
|
+
await completion(ctx, feature, progress);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Spec and Design: either the gate is ready for the human, or what blocks it.
|
|
237
|
+
const gate = pendingGate(feature) ?? 'spec';
|
|
238
|
+
const { problems } = gateReadiness(ctx, feature, gate);
|
|
239
|
+
if (problems.length === 0) {
|
|
240
|
+
if (feature.approvals.auto)
|
|
241
|
+
row(ctx, 'next', `${ctx.style.green('ready')}: auto mode approves it when the agent requests the gate: npx agjan log --gate-requested ${gate}`);
|
|
242
|
+
else
|
|
243
|
+
row(ctx, 'next', `${ctx.style.green('ready for approval')}: a human runs '${ctx.style.bold(`npx agjan approve ${gate}`)}' in a terminal`);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
for (const p of problems)
|
|
247
|
+
row(ctx, 'blocks', p);
|
|
248
|
+
const step = gateStep(feature);
|
|
249
|
+
const state = roundState(feature, ctx.config, step);
|
|
250
|
+
if (state.exhausted)
|
|
251
|
+
row(ctx, 'next', ctx.style.red(reviewNext(ctx, feature, step)));
|
|
252
|
+
else
|
|
253
|
+
row(ctx, 'next', `resolve the points above, then ${reviewNext(ctx, feature, step)}; then request 'approve ${gate}'`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* agjan status --done [--feature <slug>]: only the completion block of a verified feature,
|
|
259
|
+
* for the agent's final message (exit 1 with the next step while it is not done).
|
|
260
|
+
*/
|
|
261
|
+
async function done(ctx, slug) {
|
|
262
|
+
const feature = loadFeature(ctx.root, slug);
|
|
263
|
+
const progress = feature.kind === 'feature' && feature.stage === 'build' ? buildProgress(ctx.root, ctx.config, feature) : null;
|
|
264
|
+
if (progress?.complete && progress.due.length === 0 && verifyState(ctx.root, ctx.config, feature).state === 'current') {
|
|
265
|
+
await completion(ctx, feature, progress);
|
|
266
|
+
return 0;
|
|
267
|
+
}
|
|
268
|
+
ctx.out(`${feature.key} is not done yet: ${progress ? nextInBuild(ctx, feature, progress).replace('<KEY>', feature.key) : `stage ${feature.stage}`}`);
|
|
269
|
+
return 1;
|
|
270
|
+
}
|
|
271
|
+
/** agjan status [--feature <slug> | --all | --done] */
|
|
272
|
+
export async function run(ctx, argv) {
|
|
273
|
+
const { values } = parseArgs({ args: argv, options: { feature: { type: 'string' }, all: { type: 'boolean' }, done: { type: 'boolean' } } });
|
|
274
|
+
const root = ctx.root;
|
|
275
|
+
if (values.done)
|
|
276
|
+
return done(ctx, selectFeature(root, ctx.config, values.feature));
|
|
277
|
+
let slugs;
|
|
278
|
+
if (values.feature) {
|
|
279
|
+
if (!listFeatures(root).includes(values.feature))
|
|
280
|
+
throw new UsageError(`no feature '${values.feature}'`);
|
|
281
|
+
slugs = [values.feature];
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
slugs = values.all ? listFeatures(root) : changedFeatures(root, ctx.config);
|
|
285
|
+
}
|
|
286
|
+
const c = ctx.config;
|
|
287
|
+
const branches = 'branches: ask the user, then npx agjan branch';
|
|
288
|
+
for (const line of markLine(ctx.style, ctx.kit, 'status'))
|
|
289
|
+
ctx.out(line);
|
|
290
|
+
const autoDefault = readAutoDefault(root) ? '; auto mode: on for new features (your default)' : '';
|
|
291
|
+
ctx.out(ctx.style.gray(`settings: documents in '${c.language ?? 'en'}' (headings in English); reviews up to ${roundLimit(c)} rounds; ${fixAttempts(c)} attempts for failing checks; ${branches}${autoDefault}`));
|
|
292
|
+
if (slugs.length === 0) {
|
|
293
|
+
ctx.out(values.all ? `no features in ${FEATURES_DIR}` : 'no changed feature on this branch (agjan status --all lists every feature)');
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
const changed = new Set(changedFeatures(root, ctx.config));
|
|
297
|
+
for (const [i, slug] of slugs.entries()) {
|
|
298
|
+
if (i > 0)
|
|
299
|
+
ctx.out();
|
|
300
|
+
await describe(ctx, loadFeature(root, slug), !changed.has(slug));
|
|
301
|
+
}
|
|
302
|
+
return 0;
|
|
303
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { UsageError } from '../errors.js';
|
|
4
|
+
import { UI_SCRIPT, hasUiTests, probeBrowser } from '../browser.js';
|
|
5
|
+
/**
|
|
6
|
+
* agjan ui-test [--require]: runs the project's UI tests (`npm run test:ui`, Playwright)
|
|
7
|
+
* when Chromium can start here. Where it cannot, it says why and how to enable them, and
|
|
8
|
+
* exits 0: UI tests are optional (design decision 75). --require makes a skip exit 1
|
|
9
|
+
* (for a CI job that installs the browser). Exit code 1 when the tests fail.
|
|
10
|
+
*/
|
|
11
|
+
export function run(ctx, argv) {
|
|
12
|
+
const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { require: { type: 'boolean' } } });
|
|
13
|
+
if (positionals.length)
|
|
14
|
+
throw new UsageError('usage: agjan ui-test [--require]');
|
|
15
|
+
const s = ctx.style;
|
|
16
|
+
const root = ctx.root;
|
|
17
|
+
if (!hasUiTests(root)) {
|
|
18
|
+
ctx.out(s.gray(`no UI tests: package.json has no ${UI_SCRIPT} script (the fiori-developer skill sets them up)`));
|
|
19
|
+
return values.require ? 1 : 0;
|
|
20
|
+
}
|
|
21
|
+
const browser = probeBrowser(root);
|
|
22
|
+
if (!browser.ready) {
|
|
23
|
+
ctx.out(`${s.bold('ui tests')} ${s.yellow('skipped')}: ${browser.reason}`);
|
|
24
|
+
ctx.out(` enable: ${browser.enable}`);
|
|
25
|
+
ctx.out(' The UI ACs were not tested in a browser: name them to the user, who tries them by hand.');
|
|
26
|
+
return values.require ? 1 : 0;
|
|
27
|
+
}
|
|
28
|
+
ctx.out(`${s.bold('ui tests')}: ${s.gray(`npm run ${UI_SCRIPT}`)}`);
|
|
29
|
+
const result = spawnSync(`npm run ${UI_SCRIPT}`, { cwd: root, shell: true, encoding: 'utf8', timeout: 1_800_000, maxBuffer: 64 * 1024 * 1024 });
|
|
30
|
+
const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim();
|
|
31
|
+
if (output)
|
|
32
|
+
ctx.out(output);
|
|
33
|
+
if (result.status === 0) {
|
|
34
|
+
ctx.out(` ${s.green('ok')}`);
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
ctx.out(` ${s.red(result.status === null ? 'could not run (stopped)' : `failed (exit code ${result.status})`)}`);
|
|
38
|
+
return 1;
|
|
39
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { readJson } from './json-file.js';
|
|
3
|
+
import { AgjanError } from './errors.js';
|
|
4
|
+
export const CONFIG_FILE = 'agjan.config.json';
|
|
5
|
+
const KIT_DIR = new URL('../kit/', import.meta.url);
|
|
6
|
+
/**
|
|
7
|
+
* Reviewer models (`models.<host>.<tier>`). "session" means the reviewer agent runs on the
|
|
8
|
+
* model of the session that starts it: no model is written into the agent file. `init`
|
|
9
|
+
* writes this default visibly for every host, so users notice it and can change it.
|
|
10
|
+
*/
|
|
11
|
+
export const SESSION_MODEL = 'session';
|
|
12
|
+
export const MODEL_TIERS = ['balanced', 'deep'];
|
|
13
|
+
/** The model to write into an agent file, or undefined for the session's model. */
|
|
14
|
+
export function agentModel(config, host, tier) {
|
|
15
|
+
const value = config.models?.[host]?.[tier] ?? config.models?.[host]?.balanced;
|
|
16
|
+
return value && value !== SESSION_MODEL ? value : undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Package defaults. Domain defaults and project overrides are layered on top. */
|
|
19
|
+
const DEFAULTS = {
|
|
20
|
+
domains: ['btp'],
|
|
21
|
+
hosts: ['claude-code'],
|
|
22
|
+
language: 'en',
|
|
23
|
+
git: { base: null },
|
|
24
|
+
scope: { implicit: {} },
|
|
25
|
+
risk_paths: [],
|
|
26
|
+
tests: {},
|
|
27
|
+
fix: {
|
|
28
|
+
max_total: 80,
|
|
29
|
+
max_per_file: 50,
|
|
30
|
+
protected: [],
|
|
31
|
+
ignored: ['package-lock.json', '**/package-lock.json', 'gen/**', 'dist/**'],
|
|
32
|
+
},
|
|
33
|
+
verify: {},
|
|
34
|
+
lint: {},
|
|
35
|
+
build: { fix_attempts: 3 },
|
|
36
|
+
review: { build: 'area', rounds: 3 },
|
|
37
|
+
ci: { policy_changes: 'warn', untracked_changes: 'fail' },
|
|
38
|
+
limits: { spec_kb: 12, design_kb: 20 },
|
|
39
|
+
};
|
|
40
|
+
function isObject(value) {
|
|
41
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
/** Deep merge: objects merge key by key, everything else (arrays included) replaces. */
|
|
44
|
+
export function merge(base, override) {
|
|
45
|
+
if (!isObject(base) || !isObject(override))
|
|
46
|
+
return override === undefined ? base : override;
|
|
47
|
+
const out = { ...base };
|
|
48
|
+
for (const [key, value] of Object.entries(override))
|
|
49
|
+
out[key] = merge(base[key], value);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
export function loadDomain(id) {
|
|
53
|
+
const domain = readJson(new URL(`domains/${id}/domain.json`, KIT_DIR));
|
|
54
|
+
if (!domain)
|
|
55
|
+
throw new AgjanError(`unknown domain '${id}'`);
|
|
56
|
+
return domain;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Loads the effective configuration of the project at `root`: package defaults, then
|
|
60
|
+
* the enabled domains' defaults, then agjan.config.json. Also resolves the areas of all
|
|
61
|
+
* enabled domains, keyed by both the short id and the canonical `domain:area` id.
|
|
62
|
+
*/
|
|
63
|
+
export function loadConfig(root) {
|
|
64
|
+
const project = readJson(join(root, CONFIG_FILE)) ?? {};
|
|
65
|
+
if (!isObject(project))
|
|
66
|
+
throw new AgjanError(`${CONFIG_FILE} must contain a JSON object`);
|
|
67
|
+
const domainIds = project.domains ?? DEFAULTS.domains;
|
|
68
|
+
let config = merge(DEFAULTS, {});
|
|
69
|
+
const areas = {};
|
|
70
|
+
const shortCount = {};
|
|
71
|
+
for (const id of domainIds) {
|
|
72
|
+
const domain = loadDomain(id);
|
|
73
|
+
const implicit = {};
|
|
74
|
+
const tests = {};
|
|
75
|
+
const verify = {};
|
|
76
|
+
const lint = {};
|
|
77
|
+
for (const [name, area] of Object.entries(domain.areas)) {
|
|
78
|
+
const canonical = `${id}:${name}`;
|
|
79
|
+
areas[canonical] = { id: canonical, domain: id, name, role: area.role };
|
|
80
|
+
shortCount[name] = (shortCount[name] ?? 0) + 1;
|
|
81
|
+
implicit[name] = area.implicit ?? [];
|
|
82
|
+
tests[name] = area.tests ?? [];
|
|
83
|
+
verify[name] = area.verify ?? {};
|
|
84
|
+
if (area.lint)
|
|
85
|
+
lint[name] = area.lint;
|
|
86
|
+
}
|
|
87
|
+
config = merge(config, {
|
|
88
|
+
scope: { implicit },
|
|
89
|
+
tests,
|
|
90
|
+
verify,
|
|
91
|
+
lint,
|
|
92
|
+
risk_paths: [...config.risk_paths, ...(domain.risk_paths ?? [])],
|
|
93
|
+
fix: { protected: [...config.fix.protected, ...(domain.protected ?? [])] },
|
|
94
|
+
watched: [...(config.watched ?? []), ...(domain.watched ?? [])],
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// Short ids resolve only when they are unique among the enabled domains (design 3).
|
|
98
|
+
for (const area of Object.values(areas)) {
|
|
99
|
+
if (shortCount[area.name] === 1)
|
|
100
|
+
areas[area.name] = area;
|
|
101
|
+
}
|
|
102
|
+
config = merge(config, project);
|
|
103
|
+
config.domains = domainIds;
|
|
104
|
+
config.areas = areas;
|
|
105
|
+
return config;
|
|
106
|
+
}
|
|
107
|
+
/** Resolves a short or canonical area id; returns null when unknown or ambiguous. */
|
|
108
|
+
export function resolveArea(config, id) {
|
|
109
|
+
return config.areas[id] ?? null;
|
|
110
|
+
}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { repoRoot, userEmail } from './git.js';
|
|
3
|
+
import { loadConfig } from './config.js';
|
|
4
|
+
import { askOnTerminal, confirmOnTerminal, editOnTerminal } from './terminal.js';
|
|
5
|
+
import { createStyle } from './ui.js';
|
|
6
|
+
export const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
7
|
+
/** UTC timestamp without milliseconds, for example 2026-10-17T09:12:03Z. */
|
|
8
|
+
export function utcNow() {
|
|
9
|
+
return new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Everything a command needs from the outside world. Tests pass their own streams,
|
|
13
|
+
* clock, confirmation and line editor; the CLI uses the real ones. There is deliberately
|
|
14
|
+
* no option
|
|
15
|
+
* to skip the confirmation from the command line or the environment.
|
|
16
|
+
*/
|
|
17
|
+
export function createContext({ cwd = process.cwd(), stdout = process.stdout, stderr = process.stderr, now = utcNow, confirm = confirmOnTerminal, edit = editOnTerminal, ask = askOnTerminal, } = {}) {
|
|
18
|
+
let root;
|
|
19
|
+
let config;
|
|
20
|
+
return {
|
|
21
|
+
cwd,
|
|
22
|
+
/** Colors for stdout; plain text unless stdout is a terminal (see ui.ts). */
|
|
23
|
+
style: createStyle(stdout),
|
|
24
|
+
now,
|
|
25
|
+
confirm,
|
|
26
|
+
/** Asks the human for one line, prefilled with `initial` (async). */
|
|
27
|
+
edit,
|
|
28
|
+
/** Asks the human a yes/no question; null without a terminal. */
|
|
29
|
+
ask,
|
|
30
|
+
kit: pkg.version,
|
|
31
|
+
get root() {
|
|
32
|
+
root ??= repoRoot(cwd);
|
|
33
|
+
return root;
|
|
34
|
+
},
|
|
35
|
+
get config() {
|
|
36
|
+
config ??= loadConfig(this.root);
|
|
37
|
+
return config;
|
|
38
|
+
},
|
|
39
|
+
email() {
|
|
40
|
+
return userEmail(this.root);
|
|
41
|
+
},
|
|
42
|
+
/** Whether stdout is a terminal (for the mark's blink). */
|
|
43
|
+
isTTY: Boolean(stdout?.isTTY),
|
|
44
|
+
/** Writes raw text to stdout, for terminal control sequences. */
|
|
45
|
+
write(text) {
|
|
46
|
+
stdout.write(text);
|
|
47
|
+
},
|
|
48
|
+
/** Writes each argument as one line; no argument writes an empty line. */
|
|
49
|
+
out(...lines) {
|
|
50
|
+
stdout.write(`${(lines.length ? lines : ['']).join('\n')}\n`);
|
|
51
|
+
},
|
|
52
|
+
err(...lines) {
|
|
53
|
+
stderr.write(`${(lines.length ? lines : ['']).join('\n')}\n`);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* Copilot CLI loads a project's .mcp.json only in folders it remembers as trusted, so
|
|
4
|
+
* `init` also adds the documentation servers to Copilot's user configuration with
|
|
5
|
+
* `copilot mcp add` (design decision 72). Servers there load in every folder. agjan
|
|
6
|
+
* never removes or changes a server in that configuration: one that exists is reported
|
|
7
|
+
* and left as it is.
|
|
8
|
+
*/
|
|
9
|
+
/** Runs the copilot command; AGJAN_COPILOT names a Node script that replaces it (tests). */
|
|
10
|
+
function copilot(args) {
|
|
11
|
+
const options = { encoding: 'utf8', timeout: 60_000 };
|
|
12
|
+
const fake = process.env.AGJAN_COPILOT;
|
|
13
|
+
if (fake)
|
|
14
|
+
return spawnSync(process.execPath, [fake, ...args], options);
|
|
15
|
+
return spawnSync('copilot', args, { ...options, shell: process.platform === 'win32' });
|
|
16
|
+
}
|
|
17
|
+
/** The command line that adds one server, for messages and for doing it by hand. */
|
|
18
|
+
export function addCommand(name, server) {
|
|
19
|
+
const env = Object.entries(server.env ?? {}).flatMap(([k, v]) => ['--env', `${k}=${v}`]);
|
|
20
|
+
return ['copilot', 'mcp', 'add', ...env, name, '--', server.command, ...(server.args ?? [])];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The servers Copilot knows (user, workspace, plugin; not its built-in ones), as
|
|
24
|
+
* { name: { source, command, args } }, or null when copilot cannot be run.
|
|
25
|
+
*/
|
|
26
|
+
export function copilotServers() {
|
|
27
|
+
const run = copilot(['mcp', 'list', '--json']);
|
|
28
|
+
if (run.error || run.status !== 0)
|
|
29
|
+
return null;
|
|
30
|
+
try {
|
|
31
|
+
const list = JSON.parse(run.stdout).mcpServers ?? {};
|
|
32
|
+
return Object.fromEntries(Object.entries(list).filter(([, s]) => s.source !== 'builtin'));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Adds each server that Copilot does not know yet. Returns one result per server:
|
|
40
|
+
* `added`, `exists` (left as it is), or `failed` with the reason.
|
|
41
|
+
*/
|
|
42
|
+
export function addCopilotServers(servers) {
|
|
43
|
+
const known = copilotServers();
|
|
44
|
+
if (!known)
|
|
45
|
+
return Object.keys(servers).map((name) => ({ name, state: 'failed', detail: 'copilot is not on PATH' }));
|
|
46
|
+
return Object.entries(servers).map(([name, server]) => {
|
|
47
|
+
if (known[name])
|
|
48
|
+
return { name, state: 'exists', detail: `already in Copilot's ${known[name].source} configuration; left as it is` };
|
|
49
|
+
const run = copilot(addCommand(name, server).slice(1));
|
|
50
|
+
const output = `${run.stdout ?? ''}${run.stderr ?? ''}`.trim();
|
|
51
|
+
if (run.error || run.status !== 0 || /^Error:/m.test(output)) {
|
|
52
|
+
return { name, state: 'failed', detail: (output.split('\n').find((l) => l.startsWith('Error:')) ?? output.split('\n')[0] ?? `exit code ${run.status}`).trim() };
|
|
53
|
+
}
|
|
54
|
+
return { name, state: 'added', detail: "Copilot's user configuration" };
|
|
55
|
+
});
|
|
56
|
+
}
|