agjan 0.0.27 → 0.0.29

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/dist/cli.js CHANGED
@@ -94,7 +94,8 @@ Agent and human:
94
94
  branch <name> | --list | --use <name>
95
95
  create the branch for a feature, fix or map run, list
96
96
  the existing ones, or switch to one (after asking the user)
97
- new <slug> --key <KEY> create a feature folder with approvals.json and spec.md
97
+ new <slug> --key <KEY> [--team <name>] [--workflow <name>]
98
+ create a feature folder with approvals.json and spec.md
98
99
  scaffold design create design.md and tasks.md from the templates
99
100
  progress [--open] regenerate the progress pages and show the overview
100
101
  (.agjan/progress.html, agjan-docs/<unit>/progress.md)
@@ -111,17 +112,18 @@ Agent and human:
111
112
  with the change it ran on (tests.json); check --ci needs it
112
113
  amend --task <id> --paths <p,...> --reason "<why>"
113
114
  propose a scope amendment during Build
114
- fix start <slug> --key <KEY> --what "<text>" | fix check | fix record [--verify "…"]
115
+ fix start <slug> --key <KEY> --what "<text>" [--team <name>] [--workflow <name>]
116
+ | fix check | fix record [--verify "…"]
115
117
  fast path for small changes (record folder under fixes/)
116
- map start start mapping an existing application (project.md)
117
- discover start <slug> --key <KEY> --question "<text>"
118
+ map start [--workflow <name>] start mapping an existing application (project.md)
119
+ discover start <slug> --key <KEY> --question "<text>" [--team <name>] [--workflow <name>]
118
120
  a question that ends in a recommendation you approve, no code
119
121
  import <git url> --commit <id> [--dry-run] | import list | import remove <name>
120
122
  (human) skills and teams from another repository, at an
121
123
  exact commit; shown first, confirmed in a terminal
122
124
  team list | team show <name> the teams a unit can start with (new, fix start, discover
123
125
  start take --team) and what their personas work with
124
- workflow list [--json] | workflow show <feature|fix|map|discovery> [--team <name>] [--light] [--json]
126
+ workflow list [--json] | workflow show <workflow> [--team <name>] [--light] [--json]
125
127
  the workflows, and one as this project runs it: each step,
126
128
  the agent that does it, its persona's skills, the review
127
129
  tiers and rounds, your gates
@@ -16,6 +16,7 @@ import { proposalProblems, proposalReview } from '../discovery.js';
16
16
  import { teamProblems, unitTeam } from '../teams.js';
17
17
  import { importDrift } from '../imports.js';
18
18
  import { acceptanceState, buildProgress, verifyState } from '../progress.js';
19
+ import { pendingExtras, workflowConfigProblems } from '../customization.js';
19
20
  import { qaProblem } from '../qa.js';
20
21
  import { FIX_FILE, fixRules, freshReview } from '../fix.js';
21
22
  import { BASELINE_FILE, baselineDrift, projectProblems } from '../baseline.js';
@@ -93,6 +94,8 @@ function checkFix(report, root, config, fix, level) {
93
94
  const review = freshReview(root, config, fix, 'fix');
94
95
  if (review.problem)
95
96
  report.error(scope, review.problem);
97
+ for (const p of pendingExtras(root, config, fix, ['fix']))
98
+ report.error(scope, p.problem);
96
99
  const record = readJson(join(fix.dir, FIX_FILE));
97
100
  if (!record?.recorded_at_utc || record.review?.tree_hash !== review.record?.tree_hash) {
98
101
  report.error(scope, 'the fix is not recorded for its latest review; run: npx agjan fix record');
@@ -111,6 +114,8 @@ function checkMap(report, root, config, run, level) {
111
114
  const review = freshReview(root, config, run, 'map');
112
115
  if (review.problem)
113
116
  report.error(scope, review.problem);
117
+ for (const p of pendingExtras(root, config, run, ['map']))
118
+ report.error(scope, p.problem);
114
119
  const drift = baselineDrift(root, config);
115
120
  if (drift === null)
116
121
  report.error(scope, `${BASELINE_FILE} is missing; run: npx agjan baseline refresh`);
@@ -120,7 +125,7 @@ function checkMap(report, root, config, run, level) {
120
125
  return run;
121
126
  }
122
127
  /** A discovery (decision 91): a complete proposal; in CI also its passing review and a person's approval of it. */
123
- function checkDiscovery(report, unit, level) {
128
+ function checkDiscovery(report, root, config, unit, level) {
124
129
  const scope = unit.slug;
125
130
  if (level === 'staged')
126
131
  return unit;
@@ -132,6 +137,8 @@ function checkDiscovery(report, unit, level) {
132
137
  report.error(scope, p);
133
138
  for (const p of proposalReview(unit).problems)
134
139
  report.error(scope, p);
140
+ for (const p of pendingExtras(root, config, unit, ['proposal']))
141
+ report.error(scope, p.problem);
135
142
  if (unit.state.proposal !== 'approved' && unit.state.proposal !== 'stale')
136
143
  report.error(scope, `${NOT_ACCEPTED}: a human runs 'npx agjan approve proposal' in a terminal`);
137
144
  return unit;
@@ -180,7 +187,7 @@ function checkFeature(report, root, config, slug, level) {
180
187
  if (feature.kind === 'map')
181
188
  return checkMap(report, root, config, feature, level);
182
189
  if (feature.kind === 'discovery')
183
- return checkDiscovery(report, feature, level);
190
+ return checkDiscovery(report, root, config, feature, level);
184
191
  const scope = slug;
185
192
  const ci = level === 'ci';
186
193
  // Approved documents must not change silently (design 9.5). The pre-commit hook only
@@ -240,6 +247,9 @@ function checkFeature(report, root, config, slug, level) {
240
247
  }
241
248
  for (const d of progress.due)
242
249
  report.error(scope, `review ${d.step} is due (${d.reason})`);
250
+ // The workflow's extra reviews and gates of Build and Verify (decision 95).
251
+ for (const p of pendingExtras(root, config, feature, ['build', 'verify']))
252
+ report.error(scope, p.problem);
243
253
  const qa = qaProblem(root, config, feature);
244
254
  if (qa)
245
255
  report.error(scope, qa);
@@ -528,6 +538,8 @@ export function runChecks(ctx, level, explicitFeature) {
528
538
  // Imported skills are what was imported, or a person re-imports them (decision 93).
529
539
  for (const drift of importDrift(root))
530
540
  report.error('imports', `${drift}; import it again or remove the package (npx agjan import)`);
541
+ for (const p of workflowConfigProblems(config))
542
+ report.error('workflows', p);
531
543
  const policy = level === 'ci' ? checkPolicy(report, root, ci, files, base) : [];
532
544
  if (level !== 'staged') {
533
545
  checkManaged(report, ctx);
@@ -4,10 +4,11 @@ import { parseArgs } from 'node:util';
4
4
  import { writeJson } from '../json-file.js';
5
5
  import { APPROVALS_FILE, FEATURES_DIR, KEY, PROPOSAL_FILE, SLUG, changedFeatures, emptyApprovals, featureDir, listFeatures, loadFeature } from '../feature.js';
6
6
  import { chooseTeam } from '../teams.js';
7
+ import { startWorkflow } from '../customization.js';
7
8
  import { appendLog } from '../log.js';
8
9
  import { AgjanError, UsageError } from '../errors.js';
9
10
  const TEMPLATE = new URL('../../kit/templates/proposal.md', import.meta.url);
10
- const USAGE = 'usage: agjan discover start <slug> --key <KEY> --question "<the question>" [--team <name>]';
11
+ const USAGE = 'usage: agjan discover start <slug> --key <KEY> --question "<the question>" [--team <name>] [--workflow <name>]';
11
12
  /**
12
13
  * agjan discover start <slug> --key <KEY> --question "<text>": a discovery (decision 91), a
13
14
  * question that ends in a recommendation a person approves, and no code. Creates
@@ -15,7 +16,7 @@ const USAGE = 'usage: agjan discover start <slug> --key <KEY> --question "<the q
15
16
  * branch that carries nothing else.
16
17
  */
17
18
  function start(ctx, argv) {
18
- const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { key: { type: 'string' }, question: { type: 'string' }, team: { type: 'string' } } });
19
+ const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { key: { type: 'string' }, question: { type: 'string' }, team: { type: 'string' }, workflow: { type: 'string' } } });
19
20
  const slug = positionals[0];
20
21
  if (positionals.length !== 1 || !values.key || !values.question?.trim())
21
22
  throw new UsageError(USAGE);
@@ -35,9 +36,12 @@ function start(ctx, argv) {
35
36
  if (loadFeature(root, other).key === values.key)
36
37
  throw new AgjanError(`key ${values.key} is already used by '${other}'`);
37
38
  }
38
- const team = chooseTeam(root, ctx.config, 'discovery', values.team);
39
+ const workflow = startWorkflow(ctx.config, 'discovery', values.workflow);
40
+ const team = chooseTeam(root, ctx.config, workflow, values.team);
39
41
  mkdirSync(dir, { recursive: true });
40
42
  const approvals = emptyApprovals(slug, values.key, ctx.kit, ctx.now(), 'discovery');
43
+ if (workflow !== 'discovery')
44
+ approvals.feature.workflow = workflow;
41
45
  if (team)
42
46
  approvals.feature.team = team;
43
47
  writeJson(join(dir, APPROVALS_FILE), approvals);
@@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parseArgs } from 'node:util';
4
4
  import { chooseTeam } from '../teams.js';
5
+ import { startWorkflow } from '../customization.js';
5
6
  import { writeJson, readJson } from '../json-file.js';
6
7
  import { APPROVALS_FILE, FEATURES_DIR, KEY, SLUG, changedFeatures, emptyApprovals, featureDir, listFeatures, loadFeature, selectFeature } from '../feature.js';
7
8
  import { FIX_FILE, FIX_MD, fixRules, freshReview } from '../fix.js';
@@ -32,10 +33,10 @@ function renderFixMd(fix, data) {
32
33
  }
33
34
  /** agjan fix start <slug> --key <KEY> --what "<text>" */
34
35
  function start(ctx, argv) {
35
- const { values, positionals } = parseArgs({ args: argv, options: { key: { type: 'string' }, what: { type: 'string' }, team: { type: 'string' } }, allowPositionals: true });
36
+ const { values, positionals } = parseArgs({ args: argv, options: { key: { type: 'string' }, what: { type: 'string' }, team: { type: 'string' }, workflow: { type: 'string' } }, allowPositionals: true });
36
37
  const [slug] = positionals;
37
38
  if (!slug || positionals.length !== 1 || !values.key || !values.what?.trim()) {
38
- throw new UsageError('usage: agjan fix start <slug> --key <KEY> --what "<what the fix changes>" [--team <name>]');
39
+ throw new UsageError('usage: agjan fix start <slug> --key <KEY> --what "<what the fix changes>" [--team <name>] [--workflow <name>]');
39
40
  }
40
41
  if (!SLUG.test(slug))
41
42
  throw new UsageError(`slug '${slug}' must be lowercase letters, digits and '-'`);
@@ -57,15 +58,18 @@ function start(ctx, argv) {
57
58
  const dir = featureDir(root, `fixes/${id}`);
58
59
  if (existsSync(dir))
59
60
  throw new AgjanError(`${FEATURES_DIR}/fixes/${id} already exists`);
60
- const team = chooseTeam(root, ctx.config, 'fix', values.team);
61
+ const workflow = startWorkflow(ctx.config, 'fix', values.workflow);
62
+ const team = chooseTeam(root, ctx.config, workflow, values.team);
61
63
  mkdirSync(dir, { recursive: true });
62
64
  const approvals = emptyApprovals(id, values.key, ctx.kit, ctx.now(), 'fix');
65
+ if (workflow !== 'fix')
66
+ approvals.feature.workflow = workflow;
63
67
  if (team)
64
68
  approvals.feature.team = team;
65
69
  writeJson(join(dir, APPROVALS_FILE), approvals);
66
70
  writeJson(join(dir, FIX_FILE), { schema: 1, what: values.what.trim(), started_at_utc: ctx.now() });
67
71
  appendLog(dir, ctx.now(), 'step', { stage: 'fix', skill: 'agjan-fix' });
68
- ctx.out(`created ${FEATURES_DIR}/fixes/${id}/ (key ${values.key})`);
72
+ ctx.out(`created ${FEATURES_DIR}/fixes/${id}/ (key ${values.key}${workflow !== 'fix' ? `, workflow ${workflow}` : ''})`);
69
73
  return 0;
70
74
  }
71
75
  /** agjan fix check [--fix <id>]: the fast-path rules on the current change. */
@@ -8,7 +8,9 @@ import { documentProblems, designProblems } from '../validate.js';
8
8
  import { AgjanError, UsageError } from '../errors.js';
9
9
  import { blink, mark, markLine, pad, tone } from '../ui.js';
10
10
  import { git } from '../git.js';
11
- import { acceptanceState } from '../progress.js';
11
+ import { acceptanceState, buildProgress, verifyState } from '../progress.js';
12
+ import { freshReview } from '../fix.js';
13
+ import { extraGateState, extrasOf, gateHash, pendingExtras, unitWorkflow } from '../customization.js';
12
14
  import { verification } from '../readiness.js';
13
15
  import { runChecks } from './check.js';
14
16
  import { proposalProblems, proposalReview } from '../discovery.js';
@@ -146,6 +148,7 @@ function proposalReadiness(ctx, feature) {
146
148
  problems.push(...proposalProblems(feature));
147
149
  const review = proposalReview(feature);
148
150
  problems.push(...review.problems);
151
+ problems.push(...pendingExtras(ctx.root, ctx.config, feature, ['proposal']).map((p) => p.problem));
149
152
  const { report } = runChecks(ctx, 'default', feature.slug);
150
153
  for (const item of report.items)
151
154
  if (item.level === 'error' && item.scope === 'scope')
@@ -170,8 +173,12 @@ async function approveProposal(ctx, feature, values) {
170
173
  * `approve`, `status` and `log --gate-requested`. No problems means the gate is ready.
171
174
  */
172
175
  export function gateReadiness(ctx, feature, gate) {
176
+ const extra = extrasOf(ctx.config, unitWorkflow(feature)).gates.find((g) => g.id === gate);
177
+ if (extra)
178
+ return { problems: extraGateReadiness(ctx, feature, extra), record: null };
173
179
  if (!workflowOf(feature.kind).gates.includes(gate)) {
174
- return { problems: [`a ${workflowOf(feature.kind).name} has no '${gate}' gate (its gates: ${workflowOf(feature.kind).gates.join(', ') || 'none'})`], record: null };
180
+ const own = extrasOf(ctx.config, unitWorkflow(feature)).gates.map((g) => g.id);
181
+ return { problems: [`a ${workflowOf(feature.kind).name} has no '${gate}' gate (its gates: ${[...workflowOf(feature.kind).gates, ...own].join(', ') || 'none'})`], record: null };
175
182
  }
176
183
  if (gate === 'verify')
177
184
  return verifyReadiness(ctx, feature);
@@ -208,8 +215,71 @@ export function gateReadiness(ctx, feature, gate) {
208
215
  problems.push(`the latest review is ${review.record.step}; a combined approval needs a design:light review`);
209
216
  }
210
217
  problems.push(...review.problems);
218
+ // The workflow's extra reviews and gates of these stages come first (decision 95).
219
+ const stages = gate === 'spec' ? ['spec'] : gate === 'design' ? ['design'] : ['spec', 'design'];
220
+ problems.push(...pendingExtras(ctx.root, ctx.config, feature, stages).map((p) => p.problem));
211
221
  return { problems, record: review.record };
212
222
  }
223
+ /**
224
+ * An extra gate of the unit's workflow (decision 95): ready when its stage's own work and
225
+ * reviews are done and current, and the stage's extra reviews pass. Not yet approved for the
226
+ * current documents or files.
227
+ */
228
+ function extraGateReadiness(ctx, feature, gate) {
229
+ const problems = [];
230
+ if (extraGateState(ctx.root, ctx.config, feature, gate) === 'approved')
231
+ problems.push(`${gate.id} is already approved and nothing changed since`);
232
+ const stage = gate.stage;
233
+ if (stage === 'spec') {
234
+ problems.push(...specGateProblems(feature), ...gateReview(feature, 'spec').problems);
235
+ }
236
+ else if (stage === 'design') {
237
+ if (feature.state.spec !== 'approved' && feature.design?.parsed.mode !== 'light')
238
+ problems.push(`the spec must be approved first (it is ${feature.state.spec})`);
239
+ problems.push(...designGateProblems(ctx, feature), ...gateReview(feature, 'design').problems);
240
+ }
241
+ else if (stage === 'build' || stage === 'verify') {
242
+ if (feature.stage !== 'build')
243
+ problems.push(`the feature is in ${feature.stage}; the ${stage} stage comes after the design is approved`);
244
+ else {
245
+ const progress = buildProgress(ctx.root, ctx.config, feature);
246
+ for (const t of progress.tasks.filter((x) => !x.commit))
247
+ problems.push(`task ${t.id} is not built yet`);
248
+ for (const d of progress.due)
249
+ problems.push(`review ${d.step} is due (${d.reason})`);
250
+ if (stage === 'verify') {
251
+ const verify = verifyState(ctx.root, ctx.config, feature);
252
+ if (verify.state !== 'current')
253
+ problems.push(verify.state === 'none' ? 'no final verify review recorded' : `the final verify review ${verify.record.id} is ${verify.state}`);
254
+ }
255
+ }
256
+ }
257
+ else if (stage === 'fix' || stage === 'map') {
258
+ const review = freshReview(ctx.root, ctx.config, feature, stage);
259
+ if (review.problem)
260
+ problems.push(review.problem);
261
+ }
262
+ else if (stage === 'proposal') {
263
+ problems.push(...proposalProblems(feature), ...proposalReview(feature).problems);
264
+ }
265
+ problems.push(...pendingExtras(ctx.root, ctx.config, feature, [stage]).filter((p) => p.kind === 'review').map((p) => p.problem));
266
+ return problems;
267
+ }
268
+ /** agjan approve <extra gate>: a person approves an extra gate of the unit's workflow (decision 95). */
269
+ async function approveExtra(ctx, feature, gate, values) {
270
+ const problems = extraGateReadiness(ctx, feature, gate);
271
+ if (problems.length)
272
+ refuse(`approve ${gate.id}`, problems);
273
+ const hash = gateHash(ctx.root, ctx.config, feature, gate);
274
+ const what = ['spec', 'design', 'proposal'].includes(gate.stage) ? `the ${gate.stage} documents` : 'the current files';
275
+ if (!(await confirmGate(ctx, feature, `approve ${gate.id}: ${gate.description}`, [`workflow ${unitWorkflow(feature)}, ${gate.stage} stage`, `approves ${what} (${short(hash)})`, openFindingsLine(feature)])))
276
+ return 1;
277
+ feature.approvals.approvals[gate.id] = { hash, at_utc: ctx.now(), by: ctx.email() };
278
+ save(ctx, feature, 'approved', { gate: gate.id });
279
+ ctx.out(ctx.style.green(`approved ${gate.id} of ${feature.slug}`));
280
+ await commitRecord(ctx, feature, values, proposedMessage(feature, gate.id) || `${feature.key}: approve ${gate.id}`);
281
+ return 0;
282
+ }
213
283
  /**
214
284
  * Stamps the documents of a spec or design gate as approved by `by` (a person's email, or
215
285
  * 'auto' with `enabledBy` in auto mode). A new spec stamp invalidates the design: its
@@ -349,7 +419,10 @@ export function approve(ctx, argv) {
349
419
  return approveProposal(ctx, feature, values);
350
420
  if (positionals[0] === 'amendment' && positionals.length === 2)
351
421
  return approveAmendment(ctx, feature, positionals[1], values);
352
- throw new UsageError('usage: agjan approve spec | design | spec design | verify | proposal | amendment <id> [--feature <slug>] [--no-commit]');
422
+ const extra = extrasOf(ctx.config, unitWorkflow(feature)).gates.find((g) => g.id === what);
423
+ if (extra)
424
+ return approveExtra(ctx, feature, extra, values);
425
+ throw new UsageError('usage: agjan approve spec | design | spec design | verify | proposal | amendment <id> | <a gate of the workflow> [--feature <slug>] [--no-commit]');
353
426
  }
354
427
  /**
355
428
  * agjan auto status [--feature <slug>]: the real settings, read-only: your default for new
@@ -37,8 +37,9 @@ export function run(ctx, argv) {
37
37
  throw new UsageError(usage);
38
38
  if (values.waiting !== undefined && !values.waiting.trim())
39
39
  throw new UsageError('--waiting needs a reason: what the user has to do or decide');
40
- if (gate && !GATES.includes(gate))
41
- throw new UsageError(`--gate-requested must be one of: ${GATES.join(', ')}`);
40
+ const ownGates = Object.values(ctx.config.workflows ?? {}).flatMap((w) => (w.gates ?? []).map((g) => g.id));
41
+ if (gate && !GATES.includes(gate) && !ownGates.includes(gate))
42
+ throw new UsageError(`--gate-requested must be one of: ${[...GATES, ...ownGates].join(', ')}`);
42
43
  if (values.stage && !STAGES.includes(values.stage))
43
44
  throw new UsageError(`--stage must be one of: ${STAGES.join(', ')}`);
44
45
  const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
@@ -7,12 +7,13 @@ import { PROJECT_MD } from '../fix.js';
7
7
  import { BASELINE_FILE, refreshBaseline } from '../baseline.js';
8
8
  import { appendLog } from '../log.js';
9
9
  import { chooseTeam } from '../teams.js';
10
+ import { startWorkflow } from '../customization.js';
10
11
  import { AgjanError, UsageError } from '../errors.js';
11
12
  const TEMPLATE = new URL('../../kit/templates/project.md', import.meta.url);
12
13
  /** Map runs need finding ids but no unique key: their findings stay in their own folder. */
13
14
  const MAP_KEY = 'MAP';
14
15
  /** agjan map start: a record folder for this map run, and project.md from the template if absent. */
15
- function start(ctx) {
16
+ function start(ctx, requested) {
16
17
  const root = ctx.root;
17
18
  const changed = changedFeatures(root, ctx.config);
18
19
  if (changed.length)
@@ -22,9 +23,12 @@ function start(ctx) {
22
23
  for (let n = 2; existsSync(featureDir(root, `maps/${id}`)); n += 1)
23
24
  id = `${date}-${n}`;
24
25
  const dir = featureDir(root, `maps/${id}`);
25
- const team = chooseTeam(root, ctx.config, 'map');
26
+ const workflow = startWorkflow(ctx.config, 'map', requested);
27
+ const team = chooseTeam(root, ctx.config, workflow);
26
28
  mkdirSync(dir, { recursive: true });
27
29
  const approvals = emptyApprovals(id, MAP_KEY, ctx.kit, ctx.now(), 'map');
30
+ if (workflow !== 'map')
31
+ approvals.feature.workflow = workflow;
28
32
  if (team)
29
33
  approvals.feature.team = team;
30
34
  writeJson(join(dir, APPROVALS_FILE), approvals);
@@ -37,9 +41,10 @@ function start(ctx) {
37
41
  return 0;
38
42
  }
39
43
  export function map(ctx, argv) {
40
- if (argv[0] === 'start' && argv.length === 1)
41
- return start(ctx);
42
- throw new UsageError('usage: agjan map start');
44
+ const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { workflow: { type: 'string' } } });
45
+ if (positionals[0] === 'start' && positionals.length === 1)
46
+ return start(ctx, values.workflow);
47
+ throw new UsageError('usage: agjan map start [--workflow <name>]');
43
48
  }
44
49
  /** agjan baseline refresh: records the hashes of the watched files in baseline.json. */
45
50
  export function baseline(ctx, argv) {
@@ -18,7 +18,10 @@ function stepsOf(config, tier) {
18
18
  if (tier === 'qa')
19
19
  return 'tests from the spec in Verify';
20
20
  const kinds = Object.keys(DEFAULT_TIERS).filter((kind) => kind !== 'qa' && reviewerFor(config, kind) === AGENTS[tier].agent);
21
- return kinds.length ? `reviews ${kinds.join(', ')}` : 'no steps (review.tiers)';
21
+ // Workflows whose own review.tiers send a step to another agent than the project's.
22
+ const own = Object.keys(config.workflows ?? {}).flatMap((name) => Object.keys(config.workflows[name].review?.tiers ?? {}).filter((kind) => reviewerFor(config, kind, name) === AGENTS[tier].agent && reviewerFor(config, kind) !== AGENTS[tier].agent).map((kind) => `${kind} (${name})`));
23
+ const all = [...kinds, ...own];
24
+ return all.length ? `reviews ${all.join(', ')}` : 'no steps (review.tiers)';
22
25
  }
23
26
  /** Model names grouped by family, for reading: Claude, GPT, Gemini, the others. */
24
27
  function families(models) {
@@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parseArgs } from 'node:util';
4
4
  import { chooseTeam } from '../teams.js';
5
+ import { startWorkflow } from '../customization.js';
5
6
  import { writeJson } from '../json-file.js';
6
7
  import { APPROVALS_FILE, CONTAINERS, FEATURES_DIR, KEY, SLUG, emptyApprovals, featureDir, listFeatures, loadFeature, selectFeature } from '../feature.js';
7
8
  import { AgjanError, UsageError } from '../errors.js';
@@ -30,10 +31,10 @@ export function scaffold(ctx, argv) {
30
31
  }
31
32
  /** agjan new <slug> --key <KEY>: creates the feature folder, approvals.json and spec.md. */
32
33
  export function run(ctx, argv) {
33
- const { values, positionals } = parseArgs({ args: argv, options: { key: { type: 'string' }, team: { type: 'string' } }, allowPositionals: true });
34
+ const { values, positionals } = parseArgs({ args: argv, options: { key: { type: 'string' }, team: { type: 'string' }, workflow: { type: 'string' } }, allowPositionals: true });
34
35
  const [slug] = positionals;
35
36
  if (!slug || positionals.length > 1 || !values.key)
36
- throw new UsageError('usage: agjan new <slug> --key <KEY> [--team <name>]');
37
+ throw new UsageError('usage: agjan new <slug> --key <KEY> [--team <name>] [--workflow <name>]');
37
38
  if (!SLUG.test(slug))
38
39
  throw new UsageError(`slug '${slug}' must be lowercase letters, digits and '-', at most 48 characters`);
39
40
  // The record folders of fixes and map runs (decision 57): a feature there would be invisible.
@@ -50,9 +51,12 @@ export function run(ctx, argv) {
50
51
  if (loadFeature(root, other).key === key)
51
52
  throw new AgjanError(`key ${key} is already used by feature '${other}'`);
52
53
  }
53
- const team = chooseTeam(root, ctx.config, 'feature', values.team);
54
+ const workflow = startWorkflow(ctx.config, 'feature', values.workflow);
55
+ const team = chooseTeam(root, ctx.config, workflow, values.team);
54
56
  mkdirSync(dir, { recursive: true });
55
57
  const approvals = emptyApprovals(slug, key, ctx.kit, ctx.now());
58
+ if (workflow !== 'feature')
59
+ approvals.feature.workflow = workflow;
56
60
  if (team)
57
61
  approvals.feature.team = team;
58
62
  // The person's auto mode default for this checkout (decision 79).
@@ -61,7 +65,7 @@ export function run(ctx, argv) {
61
65
  approvals.auto = { by: auto.by, at_utc: ctx.now(), from: 'default' };
62
66
  writeJson(join(dir, APPROVALS_FILE), approvals);
63
67
  writeFileSync(join(dir, 'spec.md'), renderTemplate('spec.md', { slug, key }));
64
- ctx.out(`created ${FEATURES_DIR}/${slug}/ (key ${key}${team ? `, team ${team.name}` : ''}): ${APPROVALS_FILE}, spec.md`);
68
+ ctx.out(`created ${FEATURES_DIR}/${slug}/ (key ${key}${workflow !== 'feature' ? `, workflow ${workflow}` : ''}${team ? `, team ${team.name}` : ''}): ${APPROVALS_FILE}, spec.md`);
65
69
  if (auto) {
66
70
  appendLog(dir, ctx.now(), 'auto-on', { from: 'default' });
67
71
  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`);
@@ -5,6 +5,7 @@ import { buildContextText, parseStep } from '../review.js';
5
5
  import { loadFeature, selectFeature } from '../feature.js';
6
6
  import { appendLog } from '../log.js';
7
7
  import { reviewerFor, roundState } from '../review-policy.js';
8
+ import { unitWorkflow } from '../customization.js';
8
9
  import { highlightMarkdown, tone } from '../ui.js';
9
10
  import { AgjanError, UsageError } from '../errors.js';
10
11
  /** agjan mcp [--host <name>] [--isolation agent|fork|none] [--role review|qa]: the agjan MCP server on stdio. */
@@ -75,7 +76,7 @@ export function report(ctx, argv) {
75
76
  // The reviewer's isolation matters to the user only when it is missing.
76
77
  const isolated = record.reviewer?.isolation === 'agent';
77
78
  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
+ out.push(`- reviewer: ${reviewerFor(ctx.config, record.step, unitWorkflow(feature))} on ${record.reviewer?.host ?? 'unknown host'}, ${isolated ? 'isolated' : `⚠️ isolation ${record.reviewer?.isolation ?? 'unknown'}`}`);
79
80
  }
80
81
  const order = { blocker: 0, major: 1, minor: 2 };
81
82
  const sorted = [...record.findings].sort((a, b) => order[a.severity] - order[b.severity]);
@@ -20,6 +20,7 @@ import { verification } from '../readiness.js';
20
20
  import { readLog } from '../log.js';
21
21
  import { readAutoDefault } from '../auto.js';
22
22
  import { QA_STEP, qaState, qaTestFiles } from '../qa.js';
23
+ import { extraGateState, extraReviewState, extrasOf, pendingExtras, unitWorkflow } from '../customization.js';
23
24
  /**
24
25
  * The unit's team and what the main agent works with in it (decision 92): the skills of its
25
26
  * role and the team's own roles for it, then each persona's instructions, which the workflow
@@ -52,6 +53,10 @@ function mainPersonas(ctx, team, kind) {
52
53
  function mainSkills(ctx, team, kind) {
53
54
  return team ? [...new Set(personasFor(ctx.config, team, kind, 'main').flatMap((p) => p.persona.skills))] : [];
54
55
  }
56
+ /** `, workflow hotfix` for a unit of a workflow of the project's own (decision 95). */
57
+ function workflowNote(unit) {
58
+ return unit.approvals.feature.workflow ? `, workflow ${unit.approvals.feature.workflow}` : '';
59
+ }
55
60
  /** One indented row: a label column, then the value. `next` and `blocks` stand out. */
56
61
  function row(ctx, label, value) {
57
62
  const s = ctx.style;
@@ -70,9 +75,37 @@ function reviewNext(ctx, feature, step) {
70
75
  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)`;
71
76
  }
72
77
  const round = state.round ? `, round ${state.next} of ${state.limit}` : '';
78
+ const reviewer = reviewerFor(ctx.config, step, unitWorkflow(feature));
73
79
  if (step === QA_STEP)
74
- return `QA (step qa) with ${reviewerFor(ctx.config, step)}${round}`;
75
- return `review step ${step} with ${reviewerFor(ctx.config, step)}${round}`;
80
+ return `QA (step qa) with ${reviewer}${round}`;
81
+ return `review step ${step} with ${reviewer}${round}`;
82
+ }
83
+ /**
84
+ * What a pending extra of the workflow needs (decision 95): an extra review is run like the
85
+ * stage's own, an extra gate is the person's, in a terminal.
86
+ */
87
+ function extraNext(ctx, unit, stages) {
88
+ const first = pendingExtras(ctx.root, ctx.config, unit, stages)[0];
89
+ if (!first)
90
+ return null;
91
+ if (first.kind === 'gate')
92
+ return `${first.problem.replace(/: a human runs .*$/, '')}: a human runs '${ctx.style.bold(`npx agjan approve ${first.id}`)}' in a terminal (request it: npx agjan log --gate-requested ${first.id})`;
93
+ if (first.problem.startsWith('open blocker'))
94
+ return `${first.problem}: fix it, then ${reviewNext(ctx, unit, first.id)}`;
95
+ return `${reviewNext(ctx, unit, first.id)}: an extra review of the ${unitWorkflow(unit)} workflow (${first.description})`;
96
+ }
97
+ /** One row per extra review step and gate of the unit's workflow, with its state. */
98
+ function extraRows(ctx, unit) {
99
+ const { reviews, gates } = extrasOf(ctx.config, unitWorkflow(unit));
100
+ const tree = {};
101
+ for (const r of reviews) {
102
+ const state = extraReviewState(ctx.root, ctx.config, unit, r, tree);
103
+ row(ctx, 'extra', `review ${r.id} (${r.stage}): ${state.record ? `${tone(ctx.style, state.state === 'current' ? 'pass' : state.state)} ${state.record.id}` : ctx.style.gray('not yet')}`);
104
+ }
105
+ for (const g of gates) {
106
+ const state = extraGateState(ctx.root, ctx.config, unit, g, tree);
107
+ row(ctx, 'extra', `gate ${g.id} (${g.stage}): ${state === 'none' ? ctx.style.gray('not yet') : tone(ctx.style, state)}`);
108
+ }
76
109
  }
77
110
  /**
78
111
  * The stage to show: the documents' stages (spec, design, build), then `verify` once the
@@ -110,12 +143,19 @@ function nextInBuild(ctx, feature, progress) {
110
143
  return reviewNext(ctx, feature, progress.due[0].step);
111
144
  if (progress.next)
112
145
  return `task ${progress.next.id}: ${progress.next.title} (commit as '<KEY>-${progress.next.id}: …')`;
146
+ // The workflow's extras of Build come once every task is built and reviewed (decision 95).
147
+ const buildExtra = extraNext(ctx, feature, ['build']);
148
+ if (buildExtra)
149
+ return buildExtra;
113
150
  const { state, record } = verifyState(ctx.root, ctx.config, feature);
114
151
  if (state === 'blocked')
115
152
  return `the verify review ${record.id} is blocked: resolve its findings, then /agjan-verify again`;
116
153
  if (state === 'stale')
117
154
  return `files changed after the verify review ${record.id}: /agjan-verify again`;
118
155
  if (state === 'current') {
156
+ const verifyExtra = extraNext(ctx, feature, ['verify']);
157
+ if (verifyExtra)
158
+ return verifyExtra;
119
159
  const { problems } = verification(ctx, feature);
120
160
  if (problems.length)
121
161
  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`;
@@ -147,8 +187,9 @@ function findingCount(ctx, open) {
147
187
  }
148
188
  /** A discovery (decision 91): its proposal, its review, and the decision that is next. */
149
189
  function describeDiscovery(ctx, unit) {
150
- heading(ctx, unit, ctx.style.magenta('discovery'));
190
+ heading(ctx, unit, `${ctx.style.magenta('discovery')}${workflowNote(unit)}`);
151
191
  teamRow(ctx, unit);
192
+ extraRows(ctx, unit);
152
193
  row(ctx, 'proposal', tone(ctx.style, unit.state.proposal));
153
194
  const problems = proposalProblems(unit);
154
195
  const review = proposalReview(unit);
@@ -165,6 +206,9 @@ function describeDiscovery(ctx, unit) {
165
206
  return row(ctx, 'next', 'complete proposal.md, then review step proposal');
166
207
  if (review.problems.length)
167
208
  return row(ctx, 'next', `${review.problems[0]}: ${reviewNext(ctx, unit, 'proposal')}`);
209
+ const extra = extraNext(ctx, unit, ['proposal']);
210
+ if (extra)
211
+ return row(ctx, 'next', extra);
168
212
  row(ctx, 'next', `${ctx.style.green('ready for approval')}: a human runs '${ctx.style.bold('npx agjan approve proposal')}' in a terminal`);
169
213
  }
170
214
  /** A fix or a map run: its checks, its review, and the next step. */
@@ -173,8 +217,9 @@ function describeRecord(ctx, unit, onBase = false) {
173
217
  return describeDiscovery(ctx, unit);
174
218
  if (onBase)
175
219
  return describeRecordOnBase(ctx, unit);
176
- heading(ctx, unit, ctx.style.magenta(unit.kind));
220
+ heading(ctx, unit, `${ctx.style.magenta(unit.kind)}${workflowNote(unit)}`);
177
221
  teamRow(ctx, unit);
222
+ extraRows(ctx, unit);
178
223
  const problems = unit.kind === 'fix' ? fixRules(ctx.root, ctx.config).problems : projectProblems(ctx.root, ctx.config);
179
224
  for (const p of problems)
180
225
  row(ctx, 'blocks', p);
@@ -189,6 +234,8 @@ function describeRecord(ctx, unit, onBase = false) {
189
234
  next = unit.kind === 'fix' ? 'the change is not a fix: revert it and use /agjan-spec' : `complete agjan-docs/project.md`;
190
235
  else if (review.problem)
191
236
  next = reviewNext(ctx, unit, unit.kind);
237
+ else if (extraNext(ctx, unit, [unit.kind]))
238
+ next = extraNext(ctx, unit, [unit.kind]);
192
239
  else if (unit.kind === 'fix' && readFix(unit)?.review?.tree_hash !== record.tree_hash)
193
240
  next = 'npx agjan fix record --verify "<command and result>"';
194
241
  else
@@ -315,8 +362,9 @@ async function describe(ctx, feature, onBase = false) {
315
362
  if (onBase)
316
363
  return describeOnBase(ctx, feature);
317
364
  const stage = shownStage(ctx, feature);
318
- heading(ctx, feature, `stage: ${stage === 'done' ? ctx.style.green(stage) : ctx.style.magenta(stage)}`);
365
+ heading(ctx, feature, `stage: ${stage === 'done' ? ctx.style.green(stage) : ctx.style.magenta(stage)}${workflowNote(feature)}`);
319
366
  teamRow(ctx, feature);
367
+ extraRows(ctx, feature);
320
368
  row(ctx, 'spec', tone(ctx.style, feature.state.spec));
321
369
  const mode = feature.design?.parsed.mode ? ` (${feature.design.parsed.mode})` : '';
322
370
  row(ctx, 'design', `${tone(ctx.style, feature.state.design)}${mode}`);
@@ -370,8 +418,13 @@ async function describe(ctx, feature, onBase = false) {
370
418
  row(ctx, 'blocks', p);
371
419
  const step = gateStep(feature);
372
420
  const state = roundState(feature, ctx.config, step);
421
+ const stages = gate === 'spec' ? ['spec'] : gate === 'design' ? ['design'] : ['spec', 'design'];
422
+ const extras = pendingExtras(ctx.root, ctx.config, feature, stages).map((p) => p.problem);
423
+ const own = problems.filter((p) => !extras.includes(p));
373
424
  if (state.exhausted)
374
425
  row(ctx, 'next', ctx.style.red(reviewNext(ctx, feature, step)));
426
+ else if (!own.length && extras.length)
427
+ row(ctx, 'next', `${extraNext(ctx, feature, stages)}; then request 'approve ${gate}'`);
375
428
  else
376
429
  row(ctx, 'next', `resolve the points above, then ${reviewNext(ctx, feature, step)}; then request 'approve ${gate}'`);
377
430
  }
@@ -405,7 +458,7 @@ function json(ctx, slugs) {
405
458
  id: slug,
406
459
  key: model.key,
407
460
  kind: model.kind,
408
- workflow: workflowOf(unit.kind).name,
461
+ workflow: unit.approvals.feature.workflow ?? workflowOf(unit.kind).name,
409
462
  stages: model.stages,
410
463
  stage: model.stages[Math.min(model.at, model.stages.length - 1)],
411
464
  turn: model.turn,
@@ -1,7 +1,7 @@
1
1
  import { parseArgs } from 'node:util';
2
2
  import { UsageError } from '../errors.js';
3
+ import { workflowNames } from '../customization.js';
3
4
  import { BUILT_IN_TEAMS, ROLES, allTeams, defaultTeam, roleAgent, teamProblems } from '../teams.js';
4
- import { WORKFLOWS } from '../workflow.js';
5
5
  const USAGE = 'usage: agjan team list | agjan team show <name>';
6
6
  /**
7
7
  * agjan team list | show <name> (decision 92): the teams a unit can start with, the default
@@ -14,7 +14,7 @@ export function run(ctx, argv) {
14
14
  const teams = allTeams(ctx.config);
15
15
  if (positionals[0] === 'list' && positionals.length === 1) {
16
16
  for (const [name, team] of Object.entries(teams)) {
17
- const defaults = Object.keys(WORKFLOWS).filter((k) => defaultTeam(ctx.config, k) === name);
17
+ const defaults = workflowNames(ctx.config).filter((k) => defaultTeam(ctx.config, k) === name);
18
18
  const origin = BUILT_IN_TEAMS[name] && !ctx.config.teams?.[name] ? 'built in' : 'agjan.config.json';
19
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
20
  ctx.out(`${''.padEnd(19)}${s.gray(team.description)}`);