agjan 0.0.21 → 0.0.23

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.
Files changed (63) hide show
  1. package/README.md +6 -3
  2. package/dist/adapters/claude-code.js +3 -3
  3. package/dist/baseline.js +2 -2
  4. package/dist/cli.js +22 -4
  5. package/dist/commands/check.js +91 -7
  6. package/dist/commands/discover.js +54 -0
  7. package/dist/commands/fix.js +8 -3
  8. package/dist/commands/gates.js +48 -28
  9. package/dist/commands/import.js +73 -0
  10. package/dist/commands/log.js +3 -2
  11. package/dist/commands/map.js +6 -1
  12. package/dist/commands/new.js +7 -3
  13. package/dist/commands/pr-summary.js +20 -5
  14. package/dist/commands/progress.js +1 -1
  15. package/dist/commands/report.js +1 -1
  16. package/dist/commands/review.js +21 -9
  17. package/dist/commands/status.js +118 -20
  18. package/dist/commands/summary.js +2 -1
  19. package/dist/commands/team.js +45 -0
  20. package/dist/commands/test.js +37 -0
  21. package/dist/config.js +8 -0
  22. package/dist/discovery.js +42 -0
  23. package/dist/feature.js +14 -7
  24. package/dist/imports.js +197 -0
  25. package/dist/plan.js +1 -1
  26. package/dist/progress-view.js +46 -11
  27. package/dist/qa.js +35 -7
  28. package/dist/readiness.js +33 -0
  29. package/dist/review-policy.js +10 -4
  30. package/dist/review.js +68 -17
  31. package/dist/schema.js +4 -0
  32. package/dist/story.js +15 -8
  33. package/dist/teams.js +127 -0
  34. package/dist/test-run.js +101 -0
  35. package/dist/types.js +0 -4
  36. package/dist/workflow.js +83 -0
  37. package/docs/guide.md +179 -20
  38. package/kit/domains/btp/domain.json +1 -0
  39. package/kit/hooks/guard.mjs +134 -6
  40. package/kit/skills/agjan-ask/SKILL.md +80 -0
  41. package/kit/skills/agjan-ask/references/sources.md +45 -0
  42. package/kit/skills/agjan-build/SKILL.md +6 -5
  43. package/kit/skills/agjan-design/SKILL.md +2 -2
  44. package/kit/skills/agjan-discover/SKILL.md +87 -0
  45. package/kit/skills/agjan-fix/SKILL.md +10 -6
  46. package/kit/skills/agjan-map/SKILL.md +12 -8
  47. package/kit/skills/agjan-spec/SKILL.md +14 -7
  48. package/kit/skills/agjan-verify/SKILL.md +27 -17
  49. package/kit/skills/btp-architect/SKILL.md +2 -2
  50. package/kit/skills/btp-architect/references/security.md +1 -1
  51. package/kit/skills/cap-developer/SKILL.md +2 -2
  52. package/kit/skills/cap-developer/references/project-setup.md +1 -1
  53. package/kit/skills/cap-developer/references/validation-security.md +1 -1
  54. package/kit/skills/fiori-developer/SKILL.md +2 -2
  55. package/kit/skills/qa-tester/SKILL.md +4 -2
  56. package/kit/templates/agents-block.md +13 -5
  57. package/kit/templates/progress.html +2 -2
  58. package/kit/templates/proposal.md +22 -0
  59. package/package.json +1 -1
  60. package/schemas/approvals.schema.json +9 -1
  61. package/schemas/config.schema.json +33 -1
  62. package/schemas/log.schema.json +1 -1
  63. package/schemas/reviews.schema.json +2 -2
@@ -1,6 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parseArgs } from 'node:util';
4
+ import { chooseTeam } from '../teams.js';
4
5
  import { writeJson } from '../json-file.js';
5
6
  import { APPROVALS_FILE, CONTAINERS, FEATURES_DIR, KEY, SLUG, emptyApprovals, featureDir, listFeatures, loadFeature, selectFeature } from '../feature.js';
6
7
  import { AgjanError, UsageError } from '../errors.js';
@@ -29,10 +30,10 @@ export function scaffold(ctx, argv) {
29
30
  }
30
31
  /** agjan new <slug> --key <KEY>: creates the feature folder, approvals.json and spec.md. */
31
32
  export function run(ctx, argv) {
32
- const { values, positionals } = parseArgs({ args: argv, options: { key: { type: 'string' } }, allowPositionals: true });
33
+ const { values, positionals } = parseArgs({ args: argv, options: { key: { type: 'string' }, team: { type: 'string' } }, allowPositionals: true });
33
34
  const [slug] = positionals;
34
35
  if (!slug || positionals.length > 1 || !values.key)
35
- throw new UsageError('usage: agjan new <slug> --key <KEY>');
36
+ throw new UsageError('usage: agjan new <slug> --key <KEY> [--team <name>]');
36
37
  if (!SLUG.test(slug))
37
38
  throw new UsageError(`slug '${slug}' must be lowercase letters, digits and '-', at most 48 characters`);
38
39
  // The record folders of fixes and map runs (decision 57): a feature there would be invisible.
@@ -49,15 +50,18 @@ export function run(ctx, argv) {
49
50
  if (loadFeature(root, other).key === key)
50
51
  throw new AgjanError(`key ${key} is already used by feature '${other}'`);
51
52
  }
53
+ const team = chooseTeam(root, ctx.config, 'feature', values.team);
52
54
  mkdirSync(dir, { recursive: true });
53
55
  const approvals = emptyApprovals(slug, key, ctx.kit, ctx.now());
56
+ if (team)
57
+ approvals.feature.team = team;
54
58
  // The person's auto mode default for this checkout (decision 79).
55
59
  const auto = readAutoDefault(root);
56
60
  if (auto)
57
61
  approvals.auto = { by: auto.by, at_utc: ctx.now(), from: 'default' };
58
62
  writeJson(join(dir, APPROVALS_FILE), approvals);
59
63
  writeFileSync(join(dir, 'spec.md'), renderTemplate('spec.md', { slug, key }));
60
- ctx.out(`created ${FEATURES_DIR}/${slug}/ (key ${key}): ${APPROVALS_FILE}, spec.md`);
64
+ ctx.out(`created ${FEATURES_DIR}/${slug}/ (key ${key}${team ? `, team ${team.name}` : ''}): ${APPROVALS_FILE}, spec.md`);
61
65
  if (auto) {
62
66
  appendLog(dir, ctx.now(), 'auto-on', { from: 'default' });
63
67
  ctx.out(`auto mode on (the default of ${auto.by} in this checkout): spec and design pass automatically after their reviews; approve verify stays with the user`);
@@ -3,6 +3,8 @@ import { resolveArea } from '../config.js';
3
3
  import { FEATURES_DIR } from '../feature.js';
4
4
  import { acTestFiles } from '../tests-map.js';
5
5
  import { acResults, loadResults, resultLabel } from '../test-results.js';
6
+ import { testRunState } from '../test-run.js';
7
+ import { workflowOf } from '../workflow.js';
6
8
  import { overrideBase, runChecks } from './check.js';
7
9
  import { readFix } from './fix.js';
8
10
  import { highlightMarkdown } from '../ui.js';
@@ -14,7 +16,8 @@ function short(hash) {
14
16
  }
15
17
  /** A fix or a map run in the PR summary. */
16
18
  function recordSection(feature) {
17
- const out = [`### ${feature.kind === 'fix' ? 'Fix' : 'Map run'} ${feature.slug} (${feature.key})`, ''];
19
+ const name = workflowOf(feature.kind).name;
20
+ const out = [`### ${name[0].toUpperCase()}${name.slice(1)} ${feature.slug} (${feature.key})`, ''];
18
21
  if (feature.kind === 'fix') {
19
22
  const fix = readFix(feature);
20
23
  out.push(`**What:** ${fix?.what ?? '(not stated)'}`, '');
@@ -26,8 +29,13 @@ function recordSection(feature) {
26
29
  out.push('**Not recorded yet** (`npx agjan fix record`).', '');
27
30
  }
28
31
  }
32
+ else if (feature.kind === 'discovery') {
33
+ const stamp = feature.approvals.approvals.proposal;
34
+ out.push(`**Proposal:** \`${FEATURES_DIR}/${feature.slug}/proposal.md\` (a recommendation; no code changes).`, '');
35
+ out.push(`**Decision:** ${feature.state.proposal === 'approved' && stamp ? `approved by ${stamp.by} at ${stamp.at_utc}` : feature.state.proposal === 'stale' ? '**changed after its approval**' : '**not approved yet**'}`, '');
36
+ }
29
37
  else {
30
- out.push('Writes the baseline `docs/agjan/project.md` and `docs/agjan/baseline.json`.', '');
38
+ out.push('Writes the baseline `agjan-docs/project.md` and `agjan-docs/baseline.json`.', '');
31
39
  }
32
40
  for (const r of feature.reviews.records)
33
41
  out.push(`- ${r.id} ${r.step} round ${r.round}: ${r.verdict} (${r.findings?.length ?? 0} findings, isolation ${r.reviewer?.isolation ?? 'unknown'})`);
@@ -64,7 +72,8 @@ function featureSection(ctx, feature) {
64
72
  const tests = acTestFiles(ctx.root, ctx.config, areaNames, feature.key);
65
73
  const tasksFor = (id) => tasks.parsed.tasks.filter((t) => t.covers.includes(id)).map((t) => t.id).join(', ') || '-';
66
74
  const loaded = loadResults(ctx.root, ctx.config, areaNames);
67
- const results = loaded.files.length ? acResults(loaded, feature.key) : null;
75
+ const testRun = ctx.config.test_evidence === 'names' ? null : testRunState(ctx.root, ctx.config, feature);
76
+ const results = testRun?.run?.results ? new Map(Object.entries(testRun.run.results)) : loaded.files.length ? acResults(loaded, feature.key) : null;
68
77
  out.push('**Acceptance criteria**', '');
69
78
  out.push(results ? '| AC | Verification | Tasks | Tests | Result |' : '| AC | Verification | Tasks | Tests |');
70
79
  out.push(results ? '|---|---|---|---|---|' : '|---|---|---|---|');
@@ -78,7 +87,13 @@ function featureSection(ctx, feature) {
78
87
  out.push(`${row} ${manual ? '-' : resultLabel(results.get(ac.id)).replace(/^(failed|not run|skipped)$/, '**$1**')} |`);
79
88
  }
80
89
  out.push('');
81
- if (results)
90
+ if (testRun) {
91
+ const run = testRun.run;
92
+ const ui = run?.ui.state === 'skipped' ? ` UI tests skipped: ${run.ui.reason}.` : run?.ui.state === 'passed' ? ' UI tests passed.' : '';
93
+ const state = { none: '**not run** on this change', stale: `**outdated**: files changed after the run (${run?.at_utc})`, failed: `**failed** (${run?.at_utc})`, passed: `passed on this change (${run?.at_utc})` }[testRun.state];
94
+ out.push(`Test run (\`agjan test\`): ${state}.${ui}${results ? '' : ' Coverage per AC is by AC id in test files.'}`, '');
95
+ }
96
+ else if (results)
82
97
  out.push(`Results from ${loaded.files.map((f) => `\`${f.file}\``).join(', ')}.`, '');
83
98
  else
84
99
  out.push('Test coverage is by AC id in test files (existence only).', '');
@@ -158,7 +173,7 @@ export function run(ctx, argv) {
158
173
  if (code.length)
159
174
  out.push('');
160
175
  if (files.includes(`${FEATURES_DIR}/project.md`))
161
- out.push('The baseline `docs/agjan/project.md` is updated in this change.', '');
176
+ out.push('The baseline `agjan-docs/project.md` is updated in this change.', '');
162
177
  if (policy.length) {
163
178
  out.push('**Policy changes** (these change the rules that check this PR)', '');
164
179
  for (const p of policy)
@@ -35,7 +35,7 @@ export function run(ctx, argv) {
35
35
  ctx.out(`${s.bold(m.key.padEnd(6))} ${m.slug.padEnd(34)} ${stage.padEnd(15)} ${turn}${m.turn === 'merged' ? '' : s.gray(` · ${m.now}`)}`);
36
36
  }
37
37
  const html = relative(ctx.root, result.html).split('\\').join('/');
38
- ctx.out('', `${s.gray('overview')} ${html} ${s.gray('· per unit: docs/agjan/<unit>/progress.md')}`);
38
+ ctx.out('', `${s.gray('overview')} ${html} ${s.gray('· per unit: agjan-docs/<unit>/progress.md')}`);
39
39
  if (values.open && !openFile(result.html))
40
40
  ctx.out(`open ${html} in a browser`);
41
41
  return 0;
@@ -94,7 +94,7 @@ export function buildReport(root, feature, { now = Date.now(), homes = {} } = {}
94
94
  'folder within each time span; other work in the same folder at the same time is included.', '');
95
95
  return lines.join('\n');
96
96
  }
97
- /** agjan report [--feature <slug>]: writes docs/agjan/<slug>/report.md. */
97
+ /** agjan report [--feature <slug>]: writes agjan-docs/<slug>/report.md. */
98
98
  export function run(ctx, argv) {
99
99
  const { values } = parseArgs({ args: argv, options: { feature: { type: 'string' } } });
100
100
  const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
@@ -1,4 +1,5 @@
1
1
  import { parseArgs } from 'node:util';
2
+ import { join, relative } from 'node:path';
2
3
  import { serve } from '../mcp.js';
3
4
  import { buildContextText, parseStep } from '../review.js';
4
5
  import { loadFeature, selectFeature } from '../feature.js';
@@ -52,15 +53,17 @@ function nextAfter(feature, config, record) {
52
53
  return record.verdict === 'pass' ? 'the agent goes on with the next step' : 'minor notes stay open (the PR summary lists them); the agent goes on';
53
54
  }
54
55
  /**
55
- * agjan review report [--step <step>] [--feature <slug>]: the latest review round as a
56
- * short Markdown report for the user (verdict, findings by severity, the rounds of this
57
- * loop, what happens next). Agents put it into their message after every review, so the
58
- * user sees what the reviewer found; the markers are emoji, which every host shows.
56
+ * agjan review report [--step <step>] [--feature <slug>] [--full]: the latest review round
57
+ * as a short Markdown report for the user (verdict, blockers and majors, the minors in one
58
+ * line, the rounds of this loop, what happens next). Agents put it into their message after
59
+ * every review, so the user sees what the reviewer found without the detail they did not
60
+ * ask for: `review.md` has every finding, `--full` lists them all here, with the reviewer.
61
+ * The markers are emoji, which every host shows.
59
62
  */
60
63
  export function report(ctx, argv) {
61
- const { values, positionals } = parseArgs({ args: argv, options: { step: { type: 'string' }, feature: { type: 'string' } }, allowPositionals: true });
64
+ const { values, positionals } = parseArgs({ args: argv, options: { step: { type: 'string' }, feature: { type: 'string' }, full: { type: 'boolean' } }, allowPositionals: true });
62
65
  if (positionals.length)
63
- throw new UsageError('usage: agjan review report [--step <step>] [--feature <slug>]');
66
+ throw new UsageError('usage: agjan review report [--step <step>] [--feature <slug>] [--full]');
64
67
  const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
65
68
  const records = feature.reviews.records.filter((r) => !values.step || r.step === values.step);
66
69
  const record = records.at(-1);
@@ -69,14 +72,23 @@ export function report(ctx, argv) {
69
72
  const { limit } = roundState(feature, ctx.config, record.step);
70
73
  const status = new Map(feature.findings.map((f) => [f.id, f.status]));
71
74
  const out = [`**🔍 Review ${record.id} · ${record.step} · round ${record.round} of ${limit} · ${VERDICT[record.verdict]}**`];
72
- const isolation = record.reviewer?.isolation === 'agent' ? 'isolated' : `isolation ${record.reviewer?.isolation ?? 'unknown'}`;
73
- out.push(`- reviewer: ${reviewerFor(ctx.config, record.step)} on ${record.reviewer?.host ?? 'unknown host'}, ${isolation}`);
75
+ // The reviewer's isolation matters to the user only when it is missing.
76
+ const isolated = record.reviewer?.isolation === 'agent';
77
+ if (values.full || !isolated) {
78
+ out.push(`- reviewer: ${reviewerFor(ctx.config, record.step)} on ${record.reviewer?.host ?? 'unknown host'}, ${isolated ? 'isolated' : `⚠️ isolation ${record.reviewer?.isolation ?? 'unknown'}`}`);
79
+ }
74
80
  const order = { blocker: 0, major: 1, minor: 2 };
75
- for (const f of [...record.findings].sort((a, b) => order[a.severity] - order[b.severity])) {
81
+ const sorted = [...record.findings].sort((a, b) => order[a.severity] - order[b.severity]);
82
+ const listed = values.full ? sorted : sorted.filter((f) => f.severity !== 'minor');
83
+ for (const f of listed) {
76
84
  const where = f.file ? ` · \`${f.file}${f.line ? `:${f.line}` : ''}\`` : '';
77
85
  const state = status.get(f.id) === 'open' ? '' : ` (${status.get(f.id)})`;
78
86
  out.push(`- ${SEVERITY[f.severity]} **${f.id}** ${f.severity}${state}${where} · ${oneLine(f.issue)}`);
79
87
  }
88
+ const minors = sorted.filter((f) => f.severity === 'minor');
89
+ if (!values.full && minors.length) {
90
+ out.push(`- ${SEVERITY.minor} ${minors.length} minor note${minors.length === 1 ? '' : 's'}: ${minors.map((f) => f.id).join(', ')} (\`${relative(ctx.root, join(feature.dir, 'review.md')).split('\\').join('/')}\`)`);
91
+ }
80
92
  if (!record.findings.length)
81
93
  out.push('- no findings');
82
94
  if (record.resolves?.length)
@@ -10,11 +10,26 @@ import { fixAttempts, reviewerFor, roundLimit, roundState } from '../review-poli
10
10
  import { blink, mark, markLine, pad, tone } from '../ui.js';
11
11
  import { acTestFiles } from '../tests-map.js';
12
12
  import { acResults, loadResults } from '../test-results.js';
13
- import { NOT_ACCEPTED, runChecks } from './check.js';
13
+ import { testRunState } from '../test-run.js';
14
+ import { workflowOf } from '../workflow.js';
15
+ import { proposalProblems, proposalReview } from '../discovery.js';
16
+ import { mainRole, unitTeam } from '../teams.js';
17
+ import { finalSteps, unitModel } from '../progress-view.js';
18
+ import { splitNow } from '../story.js';
19
+ import { verification } from '../readiness.js';
14
20
  import { readLog } from '../log.js';
15
- import { finalSteps } from '../progress-view.js';
16
21
  import { readAutoDefault } from '../auto.js';
17
22
  import { QA_STEP, qaState, qaTestFiles } from '../qa.js';
23
+ /** The unit's team and the skills of the main agent's role in it (decision 92). */
24
+ function teamRow(ctx, unit) {
25
+ const team = unitTeam(ctx.config, unit.approvals.feature.team);
26
+ if (!team)
27
+ return;
28
+ const role = mainRole(unit.kind);
29
+ const skills = team.team?.personas[role]?.skills ?? [];
30
+ const changed = team.changed ? ctx.style.yellow(' (its definition changed since this unit started)') : '';
31
+ row(ctx, 'team', `${team.name}${skills.length ? ctx.style.gray(` · ${role}: ${skills.join(', ')}`) : ''}${changed}`);
32
+ }
18
33
  /** One indented row: a label column, then the value. `next` and `blocks` stand out. */
19
34
  function row(ctx, label, value) {
20
35
  const s = ctx.style;
@@ -79,6 +94,9 @@ function nextInBuild(ctx, feature, progress) {
79
94
  if (state === 'stale')
80
95
  return `files changed after the verify review ${record.id}: /agjan-verify again`;
81
96
  if (state === 'current') {
97
+ const { problems } = verification(ctx, feature);
98
+ if (problems.length)
99
+ return `the final review ${record.id} passed, but the feature is not verified yet: ${problems[0]}${problems.length > 1 ? ` (and ${problems.length - 1} more)` : ''}; fix it, then /agjan-verify again`;
82
100
  const acceptance = acceptanceState(ctx.root, ctx.config, feature, { state, record });
83
101
  if (acceptance.state === 'accepted')
84
102
  return `${ctx.style.green('done')}: verified (${record.id}) and accepted by ${acceptance.approval.by}; the next steps below are optional`;
@@ -105,11 +123,36 @@ function findingCount(ctx, open) {
105
123
  const text = `${open.length} open, ${blockers} blocker(s)`;
106
124
  return `${blockers ? ctx.style.red(text) : ctx.style.yellow(text)} ${ctx.style.gray('(npx agjan findings lists them)')}`;
107
125
  }
126
+ /** A discovery (decision 91): its proposal, its review, and the decision that is next. */
127
+ function describeDiscovery(ctx, unit) {
128
+ heading(ctx, unit, ctx.style.magenta('discovery'));
129
+ teamRow(ctx, unit);
130
+ row(ctx, 'proposal', tone(ctx.style, unit.state.proposal));
131
+ const problems = proposalProblems(unit);
132
+ const review = proposalReview(unit);
133
+ if (review.record)
134
+ row(ctx, 'review', `${review.record.id} ${tone(ctx.style, review.record.verdict)} (round ${review.record.round} of ${roundState(unit, ctx.config, 'proposal').limit})`);
135
+ const open = unit.findings.filter((f) => f.status === 'open');
136
+ if (open.length)
137
+ row(ctx, 'findings', findingCount(ctx, open));
138
+ if (unit.state.proposal === 'approved')
139
+ return row(ctx, 'next', `${ctx.style.green('approved')}: to build the recommendation, start a feature with /agjan-spec`);
140
+ for (const p of problems)
141
+ row(ctx, 'blocks', p);
142
+ if (problems.length)
143
+ return row(ctx, 'next', 'complete proposal.md, then review step proposal');
144
+ if (review.problems.length)
145
+ return row(ctx, 'next', `${review.problems[0]}: ${reviewNext(ctx, unit, 'proposal')}`);
146
+ row(ctx, 'next', `${ctx.style.green('ready for approval')}: a human runs '${ctx.style.bold('npx agjan approve proposal')}' in a terminal`);
147
+ }
108
148
  /** A fix or a map run: its checks, its review, and the next step. */
109
149
  function describeRecord(ctx, unit, onBase = false) {
150
+ if (unit.kind === 'discovery')
151
+ return describeDiscovery(ctx, unit);
110
152
  if (onBase)
111
153
  return describeRecordOnBase(ctx, unit);
112
154
  heading(ctx, unit, ctx.style.magenta(unit.kind));
155
+ teamRow(ctx, unit);
113
156
  const problems = unit.kind === 'fix' ? fixRules(ctx.root, ctx.config).problems : projectProblems(ctx.root, ctx.config);
114
157
  for (const p of problems)
115
158
  row(ctx, 'blocks', p);
@@ -121,7 +164,7 @@ function describeRecord(ctx, unit, onBase = false) {
121
164
  row(ctx, 'findings', findingCount(ctx, open));
122
165
  let next;
123
166
  if (problems.length)
124
- next = unit.kind === 'fix' ? 'the change is not a fix: revert it and use /agjan-spec' : `complete docs/agjan/project.md`;
167
+ next = unit.kind === 'fix' ? 'the change is not a fix: revert it and use /agjan-spec' : `complete agjan-docs/project.md`;
125
168
  else if (review.problem)
126
169
  next = reviewNext(ctx, unit, unit.kind);
127
170
  else if (unit.kind === 'fix' && readFix(unit)?.review?.tree_hash !== record.tree_hash)
@@ -164,14 +207,16 @@ function describeRecordOnBase(ctx, unit) {
164
207
  if (open.length)
165
208
  row(ctx, 'findings', findingCount(ctx, open));
166
209
  if (!merged)
167
- row(ctx, 'next', `start follow-up work on a branch (/agjan-${unit.kind === 'fix' ? 'fix' : 'map'})`);
210
+ row(ctx, 'next', `start follow-up work on a branch (/${workflowOf(unit.kind).skill})`);
168
211
  }
169
212
  /**
170
- * The end of a feature's agent work (verified, CI check clean or not): a screen that says
171
- * so unmistakably, what was met, and what the human does next: try it, check the manual
172
- * ACs and accept it with `approve verify` (Gate 3, decision 77); once accepted, the
173
- * optional pull request. Colored with the agjan mark on a terminal; the same content as
174
- * plain text for agents, who end /agjan-verify with it.
213
+ * The end of a feature's agent work: a screen that says unmistakably whether it is verified
214
+ * (`verification`: the same answer as the acceptance gate), what was met, and what the
215
+ * human does next: try it, check the manual ACs and accept it with `approve verify` (Gate 3,
216
+ * decision 77); once accepted, the optional pull request. While checks still fail it says
217
+ * "not verified yet" and lists them. Colored with the agjan mark on a terminal; the same
218
+ * content as plain text for agents, who end /agjan-verify with it. Returns whether the
219
+ * feature is verified.
175
220
  */
176
221
  async function completion(ctx, feature, progress) {
177
222
  const s = ctx.style;
@@ -179,14 +224,14 @@ async function completion(ctx, feature, progress) {
179
224
  const acs = feature.spec.parsed.acs;
180
225
  const automated = acs.filter((ac) => ac.verification !== 'manual');
181
226
  const manual = acs.filter((ac) => ac.verification === 'manual');
227
+ const testRun = ctx.config.test_evidence === 'names' ? null : testRunState(ctx.root, ctx.config, feature);
182
228
  const loaded = loadResults(ctx.root, ctx.config, areaNames);
183
- const results = loaded.files.length ? acResults(loaded, feature.key) : null;
229
+ const results = testRun?.run?.results ? new Map(Object.entries(testRun.run.results)) : loaded.files.length ? acResults(loaded, feature.key) : null;
184
230
  const tests = acTestFiles(ctx.root, ctx.config, areaNames, feature.key);
185
231
  const covered = automated.filter((ac) => (results ? results.get(ac.id)?.passed && !results.get(ac.id)?.failed : tests.has(ac.id))).length;
186
- const { report } = runChecks(ctx, 'ci', feature.slug);
187
- const errors = report.items.filter((i) => i.level === 'error' && !i.message.startsWith(NOT_ACCEPTED)).length;
232
+ const { problems, accepted } = verification(ctx, feature);
233
+ const errors = problems.filter((p) => p.startsWith('check --ci: ')).length;
188
234
  const acceptance = acceptanceState(ctx.root, ctx.config, feature);
189
- const accepted = acceptance.state === 'accepted';
190
235
  const open = feature.findings.filter((f) => f.status === 'open');
191
236
  const blockers = open.filter((f) => f.severity === 'blocker').length;
192
237
  const ok = (text) => `${s.teal('✔')} ${text}`;
@@ -196,11 +241,27 @@ async function completion(ctx, feature, progress) {
196
241
  errors ? bad(`check --ci: ${errors} error(s)`) : ok('check --ci clean')].join(' '),
197
242
  [(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(' '),
198
243
  ];
199
- if (accepted)
244
+ if (testRun) {
245
+ const ui = testRun.run?.ui;
246
+ lines.push([
247
+ (testRun.state === 'passed' ? ok : bad)(testRun.state === 'passed' ? 'tests passed on this change (agjan test)' : testRun.state === 'none' ? 'tests not run on this change' : `test run ${testRun.state}`),
248
+ ui?.state === 'skipped' ? `${s.yellow('●')} UI tests skipped: ${ui.reason}` : ui?.state === 'passed' ? ok('UI tests passed') : '',
249
+ ].filter(Boolean).join(' '));
250
+ }
251
+ ctx.out();
252
+ if (problems.length) {
253
+ ctx.out(`${s.red('✖')} ${s.bold(`${feature.key} is not verified yet`)}: the final review passed, but ${problems.length === 1 ? 'one point blocks' : `${problems.length} points block`} it (${feature.slug})`);
254
+ for (const line of lines)
255
+ ctx.out(` ${line}`);
256
+ ctx.out(` ${s.bold('Fix these, then run /agjan-verify again:')}`);
257
+ for (const p of problems)
258
+ ctx.out(` ${s.red('▸')} ${p}`);
259
+ return false;
260
+ }
261
+ if (accepted && acceptance.state === 'accepted')
200
262
  lines.push(ok(`accepted by ${acceptance.approval.by} (${acceptance.approval.at_utc})`));
201
263
  const title = accepted ? `${feature.key} is done` : `${feature.key} is verified`;
202
264
  const detail = accepted ? 'implemented, verified and accepted' : 'development finished and verified; your acceptance is next';
203
- ctx.out();
204
265
  if (s.brand) {
205
266
  const stars = `${s.teal('✦')} ${s.violet('✦')} ${s.teal('✦')}`;
206
267
  const logo = mark(s, ctx.kit, `${stars} ${s.bold(title)} ${stars}`, `${feature.slug} · ${detail}`);
@@ -222,6 +283,9 @@ async function completion(ctx, feature, progress) {
222
283
  ctx.out(` ${s.bold(accepted ? 'Optional next steps:' : 'Then, optional:')}`);
223
284
  for (const step of optional)
224
285
  ctx.out(` ${s.violet('▸')} ${step}`);
286
+ // The details stay one step away: the records, and the story for whoever wants it.
287
+ ctx.out(` ${s.gray(`Details: ${FEATURES_DIR}/${feature.slug}/ (spec, design, reviews, test run, progress.md) · the whole story: npx agjan summary`)}`);
288
+ return true;
225
289
  }
226
290
  async function describe(ctx, feature, onBase = false) {
227
291
  if (feature.kind !== 'feature')
@@ -230,6 +294,7 @@ async function describe(ctx, feature, onBase = false) {
230
294
  return describeOnBase(ctx, feature);
231
295
  const stage = shownStage(ctx, feature);
232
296
  heading(ctx, feature, `stage: ${stage === 'done' ? ctx.style.green(stage) : ctx.style.magenta(stage)}`);
297
+ teamRow(ctx, feature);
233
298
  row(ctx, 'spec', tone(ctx.style, feature.state.spec));
234
299
  const mode = feature.design?.parsed.mode ? ` (${feature.design.parsed.mode})` : '';
235
300
  row(ctx, 'design', `${tone(ctx.style, feature.state.design)}${mode}`);
@@ -298,15 +363,46 @@ async function done(ctx, slug) {
298
363
  const feature = loadFeature(ctx.root, slug);
299
364
  const progress = feature.kind === 'feature' && feature.stage === 'build' ? buildProgress(ctx.root, ctx.config, feature) : null;
300
365
  if (progress?.complete && progress.due.length === 0 && verifyState(ctx.root, ctx.config, feature).state === 'current') {
301
- await completion(ctx, feature, progress);
302
- return 0;
366
+ return (await completion(ctx, feature, progress)) ? 0 : 1;
303
367
  }
304
368
  ctx.out(`${feature.key} is not done yet: ${progress ? nextInBuild(ctx, feature, progress).replace('<KEY>', feature.key) : `stage ${feature.stage}`}`);
305
369
  return 1;
306
370
  }
307
- /** agjan status [--feature <slug> | --all | --done] */
371
+ /**
372
+ * agjan status --json: the state of each unit for tools (the evaluation runner, CI, an
373
+ * IDE), so none of them parses the text: its workflow and stage, whose turn it is, what is
374
+ * next and the command or skill that does it, and for a feature in Build whether it is
375
+ * verified and what blocks it (decision 90).
376
+ */
377
+ function json(ctx, slugs) {
378
+ const units = slugs.map((slug) => {
379
+ const model = unitModel(ctx, slug, { now: Date.parse(ctx.now()) });
380
+ const unit = loadFeature(ctx.root, slug);
381
+ const verified = unit.kind === 'feature' && unit.stage === 'build' ? verification(ctx, unit) : null;
382
+ return {
383
+ id: slug,
384
+ key: model.key,
385
+ kind: model.kind,
386
+ workflow: workflowOf(unit.kind).name,
387
+ stages: model.stages,
388
+ stage: model.stages[Math.min(model.at, model.stages.length - 1)],
389
+ turn: model.turn,
390
+ now: model.now,
391
+ next: splitNow(model.now).command,
392
+ ...((() => {
393
+ const team = unitTeam(ctx.config, unit.approvals.feature.team);
394
+ const role = mainRole(unit.kind);
395
+ return team ? { team: { name: team.name, changed: team.changed, role, skills: team.team?.personas[role]?.skills ?? [] } } : {};
396
+ })()),
397
+ ...(verified ? { verified: verified.problems.length === 0, accepted: verified.accepted, problems: verified.problems } : {}),
398
+ };
399
+ });
400
+ ctx.out(JSON.stringify({ schema: 1, units }, null, 2));
401
+ return 0;
402
+ }
403
+ /** agjan status [--feature <slug> | --all | --done | --json] */
308
404
  export async function run(ctx, argv) {
309
- const { values } = parseArgs({ args: argv, options: { feature: { type: 'string' }, all: { type: 'boolean' }, done: { type: 'boolean' } } });
405
+ const { values } = parseArgs({ args: argv, options: { feature: { type: 'string' }, all: { type: 'boolean' }, done: { type: 'boolean' }, json: { type: 'boolean' } } });
310
406
  const root = ctx.root;
311
407
  if (values.done)
312
408
  return done(ctx, selectFeature(root, ctx.config, values.feature));
@@ -319,8 +415,10 @@ export async function run(ctx, argv) {
319
415
  else {
320
416
  slugs = values.all ? listFeatures(root) : changedFeatures(root, ctx.config);
321
417
  }
418
+ if (values.json)
419
+ return json(ctx, slugs);
322
420
  const c = ctx.config;
323
- const branches = 'branches: ask the user, then npx agjan branch';
421
+ const branches = c.git?.branches === 'ask' ? 'branches: ask the user, then npx agjan branch' : 'branches: the agent creates one (npx agjan branch <name>)';
324
422
  for (const line of markLine(ctx.style, ctx.kit, 'status'))
325
423
  ctx.out(line);
326
424
  const autoDefault = readAutoDefault(root) ? '; auto mode: on for new features (your default)' : '';
@@ -25,8 +25,9 @@ export function run(ctx, argv) {
25
25
  for (const slug of slugs) {
26
26
  const model = unitModel(ctx, slug, { now: Date.parse(ctx.now()) });
27
27
  ctx.out('', `${s.bold(model.slug)} ${s.gray(`(${model.key})`)}`, '');
28
+ // Past blockers stay visible as such; what holds now is the last line.
28
29
  for (const item of storyItems(model))
29
- ctx.out(` ${s.green('✔')} ${item.text}`);
30
+ ctx.out(` ${item.mark === 'issue' ? s.red('✖') : item.mark === 'note' ? s.yellow('●') : s.green('✔')} ${item.text}`);
30
31
  const end = storyEnd(model);
31
32
  const mark = end.turn === 'you' ? s.violet('⏳') : end.turn === 'agent' ? s.cyan('▶') : s.green('✔');
32
33
  ctx.out(` ${mark} ${s.bold(end.text)}`);
@@ -0,0 +1,45 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { UsageError } from '../errors.js';
3
+ import { BUILT_IN_TEAMS, ROLES, allTeams, defaultTeam, teamProblems } from '../teams.js';
4
+ import { WORKFLOWS } from '../workflow.js';
5
+ const USAGE = 'usage: agjan team list | agjan team show <name>';
6
+ /**
7
+ * agjan team list | show <name> (decision 92): the teams a unit can start with, the default
8
+ * per workflow, and what a team's personas work with. A team is chosen when a unit starts
9
+ * (`--team` on new, fix start, discover start), else the workflow's default.
10
+ */
11
+ export function run(ctx, argv) {
12
+ const { positionals } = parseArgs({ args: argv, allowPositionals: true });
13
+ const s = ctx.style;
14
+ const teams = allTeams(ctx.config);
15
+ if (positionals[0] === 'list' && positionals.length === 1) {
16
+ for (const [name, team] of Object.entries(teams)) {
17
+ const defaults = Object.keys(WORKFLOWS).filter((k) => defaultTeam(ctx.config, k) === name);
18
+ const origin = BUILT_IN_TEAMS[name] && !ctx.config.teams?.[name] ? 'built in' : 'agjan.config.json';
19
+ ctx.out(`${s.bold(name.padEnd(18))} ${team.workflows.join(', ').padEnd(16)} ${s.gray(origin)}${defaults.length ? s.green(` default for ${defaults.join(', ')}`) : ''}`);
20
+ ctx.out(`${''.padEnd(19)}${s.gray(team.description)}`);
21
+ }
22
+ return 0;
23
+ }
24
+ if (positionals[0] === 'show' && positionals.length === 2) {
25
+ const name = positionals[1];
26
+ const team = teams[name];
27
+ const problems = teamProblems(ctx.root, ctx.config, name);
28
+ if (!team)
29
+ throw new UsageError(problems[0]);
30
+ ctx.out(`${s.bold(name)}: ${team.description}`, ` workflows ${team.workflows.join(', ')}`);
31
+ for (const role of ROLES) {
32
+ const persona = team.personas[role];
33
+ if (!persona)
34
+ continue;
35
+ ctx.out(` ${role.padEnd(12)}${persona.skills.join(', ')}`);
36
+ if (persona.instructions?.trim())
37
+ ctx.out(` ${''.padEnd(12)}${s.gray(persona.instructions.trim().replace(/\s+/g, ' '))}`);
38
+ }
39
+ ctx.out(s.gray(' The workflow decides the steps, reviews and gates; a team adds what its agents work with.'));
40
+ for (const p of problems)
41
+ ctx.out(` ${s.red('problem')} ${p}`);
42
+ return problems.length ? 1 : 0;
43
+ }
44
+ throw new UsageError(USAGE);
45
+ }
@@ -0,0 +1,37 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { loadFeature, selectFeature } from '../feature.js';
3
+ import { AgjanError, UsageError } from '../errors.js';
4
+ import { UI_SCRIPT } from '../browser.js';
5
+ import { TEST_RUN_FILE, runTests } from '../test-run.js';
6
+ /**
7
+ * agjan test [--feature <slug>]: runs the feature's test commands (`verify.<area>.test`,
8
+ * else `npm test`) and its UI tests where a browser can start, and records the run with
9
+ * the change it ran on in the feature's tests.json (decision 88). Exit code 1 when a test
10
+ * command or the UI tests fail. Output stays short: a line per command, the end of the
11
+ * output of what failed.
12
+ */
13
+ export function run(ctx, argv) {
14
+ const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { feature: { type: 'string' } } });
15
+ if (positionals.length)
16
+ throw new UsageError('usage: agjan test [--feature <slug>]');
17
+ const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
18
+ if (feature.kind !== 'feature' || feature.stage !== 'build')
19
+ throw new AgjanError(`${feature.slug} is not in Build: agjan test records the tests of a built feature`);
20
+ const s = ctx.style;
21
+ const result = runTests(ctx.root, ctx.config, feature, ctx.now, (line) => ctx.out(s.gray(line)));
22
+ for (const r of result.runs) {
23
+ const verdict = r.exit === 0 ? s.green('passed') : s.red(r.exit === null ? 'stopped' : `failed (exit code ${r.exit})`);
24
+ ctx.out(`${s.bold(r.command)}: ${verdict} ${s.gray(`(${(r.ms / 1000).toFixed(1)} s)`)}`);
25
+ }
26
+ const ui = result.ui;
27
+ if (ui.state === 'skipped')
28
+ ctx.out(`${s.bold(`npm run ${UI_SCRIPT}`)}: ${s.yellow('skipped')}: ${ui.reason} (npx agjan ui-test says how to enable it; name the UI ACs to the user)`);
29
+ else if (ui.state !== 'none')
30
+ ctx.out(`${s.bold(`npm run ${UI_SCRIPT}`)}: ${ui.state === 'passed' ? s.green('passed') : s.red('failed')}`);
31
+ const failedAcs = Object.entries(result.results ?? {}).filter(([, c]) => c.failed).map(([id]) => id);
32
+ if (result.results)
33
+ ctx.out(`ACs in the results: ${Object.keys(result.results).length}${failedAcs.length ? `, failing: ${s.red(failedAcs.join(', '))}` : ''}`);
34
+ const passed = result.runs.every((r) => r.exit === 0) && ui.state !== 'failed';
35
+ ctx.out(`${passed ? s.green('recorded') : s.red('recorded, failed')}: ${feature.slug}/${TEST_RUN_FILE} for this change${passed ? '' : '; fix the code, then run npx agjan test again'}`);
36
+ return passed ? 0 : 1;
37
+ }
package/dist/config.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { join } from 'node:path';
2
2
  import { readJson } from './json-file.js';
3
+ import { importedTeams } from './imports.js';
3
4
  import { AgjanError } from './errors.js';
4
5
  import { git } from './git.js';
5
6
  import { loadSchema, validate } from './schema.js';
@@ -29,6 +30,7 @@ const DEFAULTS = {
29
30
  git: { base: null },
30
31
  scope: { implicit: {} },
31
32
  risk_paths: [],
33
+ application: [],
32
34
  tests: {},
33
35
  fix: {
34
36
  max_total: 80,
@@ -40,6 +42,7 @@ const DEFAULTS = {
40
42
  lint: {},
41
43
  build: { fix_attempts: 3 },
42
44
  review: { build: 'area', rounds: 3 },
45
+ test_evidence: 'run',
43
46
  ci: { policy_changes: 'warn', untracked_changes: 'fail' },
44
47
  limits: { spec_kb: 12, design_kb: 20 },
45
48
  };
@@ -101,6 +104,7 @@ export function loadConfig(root) {
101
104
  verify,
102
105
  lint,
103
106
  risk_paths: [...config.risk_paths, ...(domain.risk_paths ?? [])],
107
+ application: [...config.application, ...(domain.application ?? [])],
104
108
  fix: { protected: [...config.fix.protected, ...(domain.protected ?? [])] },
105
109
  watched: [...(config.watched ?? []), ...(domain.watched ?? [])],
106
110
  });
@@ -111,6 +115,10 @@ export function loadConfig(root) {
111
115
  areas[area.name] = area;
112
116
  }
113
117
  config = merge(config, project);
118
+ // Imported teams (decision 93) sit under the project's own: a project team of the same name wins.
119
+ const imported = importedTeams(root);
120
+ if (Object.keys(imported).length)
121
+ config.teams = { ...imported, ...(config.teams ?? {}) };
114
122
  config.domains = domainIds;
115
123
  config.areas = areas;
116
124
  return config;
@@ -0,0 +1,42 @@
1
+ import { latestReview, stillBlocked } from './feature.js';
2
+ /**
3
+ * Discoveries (decision 91): a question that ends in a recommendation a person approves,
4
+ * and no code. The proposal (proposal.md) is reviewed (step `proposal`) and approved
5
+ * (`agjan approve proposal`); the branch changes nothing outside the discovery's folder.
6
+ */
7
+ /** A section's text: the lines under `## name` up to the next `## `. */
8
+ function section(text, name) {
9
+ const match = new RegExp(`^## ${name}\\s*$([\\s\\S]*?)(?=^## |(?![\\s\\S]))`, 'm').exec(text);
10
+ return match ? match[1].trim() : '';
11
+ }
12
+ /** What the proposal lacks before its review and its approval. */
13
+ export function proposalProblems(feature) {
14
+ const text = feature.proposal?.text;
15
+ if (!text)
16
+ return ['proposal.md does not exist'];
17
+ const problems = [];
18
+ for (const name of ['Question', 'Context', 'Options', 'Recommendation', 'Sources']) {
19
+ if (!section(text, name))
20
+ problems.push(`proposal.md: the section "${name}" is empty`);
21
+ }
22
+ const options = [...section(text, 'Options').matchAll(/^### (.*)$/gm)].map((m) => m[1].replace(/^Option \d+:?\s*/, '').trim());
23
+ if (!options.length || options.some((o) => !o))
24
+ problems.push('proposal.md: name each option in its heading ("### Option 1: <name>")');
25
+ return problems;
26
+ }
27
+ /** The proposal's review: the latest `proposal` record, and why it does not allow the gate. */
28
+ export function proposalReview(feature) {
29
+ const record = latestReview(feature.reviews, ['proposal']);
30
+ const problems = [];
31
+ if (!record)
32
+ problems.push('no proposal review recorded');
33
+ else {
34
+ if (record.documents?.proposal !== feature.proposal?.hash)
35
+ problems.push(`the latest proposal review (${record.id}) did not review the current proposal.md`);
36
+ if (stillBlocked(feature, record))
37
+ problems.push(`the latest proposal review (${record.id}) is blocked`);
38
+ }
39
+ for (const f of feature.findings.filter((x) => x.status === 'open' && x.severity === 'blocker' && x.step === 'proposal'))
40
+ problems.push(`open blocker ${f.id}: ${f.issue}`);
41
+ return { record, problems };
42
+ }