agjan 0.0.26 → 0.0.28

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) {
@@ -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`);
@@ -13,22 +13,49 @@ import { acResults, loadResults } from '../test-results.js';
13
13
  import { testRunState } from '../test-run.js';
14
14
  import { workflowOf } from '../workflow.js';
15
15
  import { proposalProblems, proposalReview } from '../discovery.js';
16
- import { mainRole, unitTeam } from '../teams.js';
16
+ import { mainRole, personasFor, unitTeam } from '../teams.js';
17
17
  import { finalSteps, unitModel } from '../progress-view.js';
18
18
  import { splitNow } from '../story.js';
19
19
  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
- /** The unit's team and the skills of the main agent's role in it (decision 92). */
23
+ import { extraGateState, extraReviewState, extrasOf, pendingExtras, unitWorkflow } from '../customization.js';
24
+ /**
25
+ * The unit's team and what the main agent works with in it (decision 92): the skills of its
26
+ * role and the team's own roles for it, then each persona's instructions, which the workflow
27
+ * skills tell the main agent to follow (the reviewer and QA agent get theirs in their contexts).
28
+ */
24
29
  function teamRow(ctx, unit) {
25
30
  const team = unitTeam(ctx.config, unit.approvals.feature.team);
26
31
  if (!team)
27
32
  return;
28
33
  const role = mainRole(unit.kind);
29
- const skills = team.team?.personas[role]?.skills ?? [];
34
+ const skills = mainSkills(ctx, team.team, unit.kind);
30
35
  const changed = team.changed ? ctx.style.yellow(' (its definition changed since this unit started)') : '';
31
36
  row(ctx, 'team', `${team.name}${skills.length ? ctx.style.gray(` · ${role}: ${skills.join(', ')}`) : ''}${changed}`);
37
+ for (const p of mainPersonas(ctx, team.team, unit.kind)) {
38
+ if (p.instructions)
39
+ row(ctx, 'follow', `${p.role}: ${p.instructions}`);
40
+ }
41
+ }
42
+ /** The main agent's personas: role, skills and instructions (one line). */
43
+ function mainPersonas(ctx, team, kind) {
44
+ if (!team)
45
+ return [];
46
+ return personasFor(ctx.config, team, kind, 'main').map(({ role, persona }) => ({
47
+ role,
48
+ skills: persona.skills,
49
+ ...(persona.instructions?.trim() ? { instructions: persona.instructions.trim().replace(/\s+/g, ' ') } : {}),
50
+ }));
51
+ }
52
+ /** The skills the main agent works with: its role's, then those of the team's own roles for it. */
53
+ function mainSkills(ctx, team, kind) {
54
+ return team ? [...new Set(personasFor(ctx.config, team, kind, 'main').flatMap((p) => p.persona.skills))] : [];
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}` : '';
32
59
  }
33
60
  /** One indented row: a label column, then the value. `next` and `blocks` stand out. */
34
61
  function row(ctx, label, value) {
@@ -52,6 +79,33 @@ function reviewNext(ctx, feature, step) {
52
79
  return `QA (step qa) with ${reviewerFor(ctx.config, step)}${round}`;
53
80
  return `review step ${step} with ${reviewerFor(ctx.config, step)}${round}`;
54
81
  }
82
+ /**
83
+ * What a pending extra of the workflow needs (decision 95): an extra review is run like the
84
+ * stage's own, an extra gate is the person's, in a terminal.
85
+ */
86
+ function extraNext(ctx, unit, stages) {
87
+ const first = pendingExtras(ctx.root, ctx.config, unit, stages)[0];
88
+ if (!first)
89
+ return null;
90
+ if (first.kind === 'gate')
91
+ 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})`;
92
+ if (first.problem.startsWith('open blocker'))
93
+ return `${first.problem}: fix it, then ${reviewNext(ctx, unit, first.id)}`;
94
+ return `${reviewNext(ctx, unit, first.id)}: an extra review of the ${unitWorkflow(unit)} workflow (${first.description})`;
95
+ }
96
+ /** One row per extra review step and gate of the unit's workflow, with its state. */
97
+ function extraRows(ctx, unit) {
98
+ const { reviews, gates } = extrasOf(ctx.config, unitWorkflow(unit));
99
+ const tree = {};
100
+ for (const r of reviews) {
101
+ const state = extraReviewState(ctx.root, ctx.config, unit, r, tree);
102
+ 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')}`);
103
+ }
104
+ for (const g of gates) {
105
+ const state = extraGateState(ctx.root, ctx.config, unit, g, tree);
106
+ row(ctx, 'extra', `gate ${g.id} (${g.stage}): ${state === 'none' ? ctx.style.gray('not yet') : tone(ctx.style, state)}`);
107
+ }
108
+ }
55
109
  /**
56
110
  * The stage to show: the documents' stages (spec, design, build), then `verify` once the
57
111
  * verification started (its step logged since the design approval, or a verify review),
@@ -88,12 +142,19 @@ function nextInBuild(ctx, feature, progress) {
88
142
  return reviewNext(ctx, feature, progress.due[0].step);
89
143
  if (progress.next)
90
144
  return `task ${progress.next.id}: ${progress.next.title} (commit as '<KEY>-${progress.next.id}: …')`;
145
+ // The workflow's extras of Build come once every task is built and reviewed (decision 95).
146
+ const buildExtra = extraNext(ctx, feature, ['build']);
147
+ if (buildExtra)
148
+ return buildExtra;
91
149
  const { state, record } = verifyState(ctx.root, ctx.config, feature);
92
150
  if (state === 'blocked')
93
151
  return `the verify review ${record.id} is blocked: resolve its findings, then /agjan-verify again`;
94
152
  if (state === 'stale')
95
153
  return `files changed after the verify review ${record.id}: /agjan-verify again`;
96
154
  if (state === 'current') {
155
+ const verifyExtra = extraNext(ctx, feature, ['verify']);
156
+ if (verifyExtra)
157
+ return verifyExtra;
97
158
  const { problems } = verification(ctx, feature);
98
159
  if (problems.length)
99
160
  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`;
@@ -125,8 +186,9 @@ function findingCount(ctx, open) {
125
186
  }
126
187
  /** A discovery (decision 91): its proposal, its review, and the decision that is next. */
127
188
  function describeDiscovery(ctx, unit) {
128
- heading(ctx, unit, ctx.style.magenta('discovery'));
189
+ heading(ctx, unit, `${ctx.style.magenta('discovery')}${workflowNote(unit)}`);
129
190
  teamRow(ctx, unit);
191
+ extraRows(ctx, unit);
130
192
  row(ctx, 'proposal', tone(ctx.style, unit.state.proposal));
131
193
  const problems = proposalProblems(unit);
132
194
  const review = proposalReview(unit);
@@ -143,6 +205,9 @@ function describeDiscovery(ctx, unit) {
143
205
  return row(ctx, 'next', 'complete proposal.md, then review step proposal');
144
206
  if (review.problems.length)
145
207
  return row(ctx, 'next', `${review.problems[0]}: ${reviewNext(ctx, unit, 'proposal')}`);
208
+ const extra = extraNext(ctx, unit, ['proposal']);
209
+ if (extra)
210
+ return row(ctx, 'next', extra);
146
211
  row(ctx, 'next', `${ctx.style.green('ready for approval')}: a human runs '${ctx.style.bold('npx agjan approve proposal')}' in a terminal`);
147
212
  }
148
213
  /** A fix or a map run: its checks, its review, and the next step. */
@@ -151,8 +216,9 @@ function describeRecord(ctx, unit, onBase = false) {
151
216
  return describeDiscovery(ctx, unit);
152
217
  if (onBase)
153
218
  return describeRecordOnBase(ctx, unit);
154
- heading(ctx, unit, ctx.style.magenta(unit.kind));
219
+ heading(ctx, unit, `${ctx.style.magenta(unit.kind)}${workflowNote(unit)}`);
155
220
  teamRow(ctx, unit);
221
+ extraRows(ctx, unit);
156
222
  const problems = unit.kind === 'fix' ? fixRules(ctx.root, ctx.config).problems : projectProblems(ctx.root, ctx.config);
157
223
  for (const p of problems)
158
224
  row(ctx, 'blocks', p);
@@ -167,6 +233,8 @@ function describeRecord(ctx, unit, onBase = false) {
167
233
  next = unit.kind === 'fix' ? 'the change is not a fix: revert it and use /agjan-spec' : `complete agjan-docs/project.md`;
168
234
  else if (review.problem)
169
235
  next = reviewNext(ctx, unit, unit.kind);
236
+ else if (extraNext(ctx, unit, [unit.kind]))
237
+ next = extraNext(ctx, unit, [unit.kind]);
170
238
  else if (unit.kind === 'fix' && readFix(unit)?.review?.tree_hash !== record.tree_hash)
171
239
  next = 'npx agjan fix record --verify "<command and result>"';
172
240
  else
@@ -293,8 +361,9 @@ async function describe(ctx, feature, onBase = false) {
293
361
  if (onBase)
294
362
  return describeOnBase(ctx, feature);
295
363
  const stage = shownStage(ctx, feature);
296
- heading(ctx, feature, `stage: ${stage === 'done' ? ctx.style.green(stage) : ctx.style.magenta(stage)}`);
364
+ heading(ctx, feature, `stage: ${stage === 'done' ? ctx.style.green(stage) : ctx.style.magenta(stage)}${workflowNote(feature)}`);
297
365
  teamRow(ctx, feature);
366
+ extraRows(ctx, feature);
298
367
  row(ctx, 'spec', tone(ctx.style, feature.state.spec));
299
368
  const mode = feature.design?.parsed.mode ? ` (${feature.design.parsed.mode})` : '';
300
369
  row(ctx, 'design', `${tone(ctx.style, feature.state.design)}${mode}`);
@@ -348,8 +417,13 @@ async function describe(ctx, feature, onBase = false) {
348
417
  row(ctx, 'blocks', p);
349
418
  const step = gateStep(feature);
350
419
  const state = roundState(feature, ctx.config, step);
420
+ const stages = gate === 'spec' ? ['spec'] : gate === 'design' ? ['design'] : ['spec', 'design'];
421
+ const extras = pendingExtras(ctx.root, ctx.config, feature, stages).map((p) => p.problem);
422
+ const own = problems.filter((p) => !extras.includes(p));
351
423
  if (state.exhausted)
352
424
  row(ctx, 'next', ctx.style.red(reviewNext(ctx, feature, step)));
425
+ else if (!own.length && extras.length)
426
+ row(ctx, 'next', `${extraNext(ctx, feature, stages)}; then request 'approve ${gate}'`);
353
427
  else
354
428
  row(ctx, 'next', `resolve the points above, then ${reviewNext(ctx, feature, step)}; then request 'approve ${gate}'`);
355
429
  }
@@ -383,7 +457,7 @@ function json(ctx, slugs) {
383
457
  id: slug,
384
458
  key: model.key,
385
459
  kind: model.kind,
386
- workflow: workflowOf(unit.kind).name,
460
+ workflow: unit.approvals.feature.workflow ?? workflowOf(unit.kind).name,
387
461
  stages: model.stages,
388
462
  stage: model.stages[Math.min(model.at, model.stages.length - 1)],
389
463
  turn: model.turn,
@@ -392,7 +466,7 @@ function json(ctx, slugs) {
392
466
  ...((() => {
393
467
  const team = unitTeam(ctx.config, unit.approvals.feature.team);
394
468
  const role = mainRole(unit.kind);
395
- return team ? { team: { name: team.name, changed: team.changed, role, skills: team.team?.personas[role]?.skills ?? [] } } : {};
469
+ return team ? { team: { name: team.name, changed: team.changed, role, skills: mainSkills(ctx, team.team, unit.kind), personas: mainPersonas(ctx, team.team, unit.kind) } } : {};
396
470
  })()),
397
471
  ...(verified ? { verified: verified.problems.length === 0, accepted: verified.accepted, problems: verified.problems } : {}),
398
472
  };
@@ -422,7 +496,7 @@ export async function run(ctx, argv) {
422
496
  for (const line of markLine(ctx.style, ctx.kit, 'status'))
423
497
  ctx.out(line);
424
498
  const autoDefault = readAutoDefault(root) ? '; auto mode: on for new features (your default)' : '';
425
- 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}`));
499
+ ctx.out(ctx.style.gray(`settings: documents in '${c.language ?? 'en'}' (headings in English); reviews up to ${roundLimit(c)} rounds${Object.keys(c.review?.step_rounds ?? {}).length ? ` (${Object.entries(c.review.step_rounds).map(([k, n]) => `${k}: ${n}`).join(', ')})` : ''}; ${fixAttempts(c)} attempts for failing checks; ${branches}${autoDefault}`));
426
500
  if (slugs.length === 0) {
427
501
  ctx.out(values.all ? `no features in ${FEATURES_DIR}` : 'no changed feature on this branch (agjan status --all lists every feature)');
428
502
  return 0;