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.
@@ -1,7 +1,7 @@
1
1
  import { parseArgs } from 'node:util';
2
2
  import { UsageError } from '../errors.js';
3
- import { BUILT_IN_TEAMS, ROLES, allTeams, defaultTeam, teamProblems } from '../teams.js';
4
- import { WORKFLOWS } from '../workflow.js';
3
+ import { workflowNames } from '../customization.js';
4
+ import { BUILT_IN_TEAMS, ROLES, allTeams, defaultTeam, roleAgent, teamProblems } from '../teams.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)}`);
@@ -27,14 +27,19 @@ export function run(ctx, argv) {
27
27
  const problems = teamProblems(ctx.root, ctx.config, name);
28
28
  if (!team)
29
29
  throw new UsageError(problems[0]);
30
- ctx.out(`${s.bold(name)}: ${team.description}`, ` workflows ${team.workflows.join(', ')}`);
31
- for (const role of ROLES) {
30
+ ctx.out(`${s.bold(name)}: ${team.description}`);
31
+ // The built-in roles first, then the team's own; a named persona says so.
32
+ const definition = ctx.config.teams?.[name] ?? BUILT_IN_TEAMS[name];
33
+ const roles = [...ROLES.filter((r) => team.personas[r]), ...Object.keys(team.personas).filter((r) => !ROLES.includes(r))];
34
+ const width = Math.max(12, ...roles.filter((r) => !ROLES.includes(r)).map((r) => r.length + 2));
35
+ ctx.out(` ${'workflows'.padEnd(width)}${team.workflows.join(', ')}`);
36
+ for (const role of roles) {
32
37
  const persona = team.personas[role];
33
- if (!persona)
34
- continue;
35
- ctx.out(` ${role.padEnd(12)}${persona.skills.join(', ')}`);
38
+ const ref = definition?.personas[role];
39
+ const notes = [typeof ref === 'string' ? `persona ${ref}` : '', ROLES.includes(role) ? '' : `reaches the ${roleAgent(ctx.config, role) ?? 'unknown'} agent`].filter(Boolean);
40
+ ctx.out(` ${role.padEnd(width)}${persona.skills.join(', ')}${notes.length ? s.gray(` (${notes.join('; ')})`) : ''}`);
36
41
  if (persona.instructions?.trim())
37
- ctx.out(` ${''.padEnd(12)}${s.gray(persona.instructions.trim().replace(/\s+/g, ' '))}`);
42
+ ctx.out(` ${''.padEnd(width)}${s.gray(persona.instructions.trim().replace(/\s+/g, ' '))}`);
38
43
  }
39
44
  ctx.out(s.gray(' The workflow decides the steps, reviews and gates; a team adds what its agents work with.'));
40
45
  for (const p of problems)
@@ -3,7 +3,27 @@ import { UsageError } from '../errors.js';
3
3
  import { allTeams, defaultTeam } from '../teams.js';
4
4
  import { WORKFLOWS } from '../workflow.js';
5
5
  import { resolveWorkflow, teamSource } from '../workflow-view.js';
6
- const USAGE = 'usage: agjan workflow list [--json] | agjan workflow show <feature|fix|map|discovery> [--team <name>] [--light] [--json]';
6
+ import { STAGES, baseOf, extrasOf, workflowNames } from '../customization.js';
7
+ const USAGE = 'usage: agjan workflow list [--json] | agjan workflow show <workflow> [--team <name>] [--light] [--json]';
8
+ /** A workflow of the list: built-in, or the project's own on its base (decision 95). */
9
+ function listed(ctx, name) {
10
+ const base = baseOf(ctx.config, name);
11
+ const w = WORKFLOWS[base];
12
+ const own = name !== base;
13
+ const extras = extrasOf(ctx.config, name);
14
+ return {
15
+ kind: name,
16
+ base,
17
+ name: own ? name : w.name,
18
+ ...(own && ctx.config.workflows?.[name]?.description ? { description: ctx.config.workflows[name].description } : {}),
19
+ skill: own ? `/agjan-${name}` : `/${w.skill}`,
20
+ stages: w.stages,
21
+ /** The stages extras attach to (decision 95). */
22
+ extraStages: STAGES[base],
23
+ team: defaultTeam(ctx.config, name),
24
+ extras: { reviews: extras.reviews.map((r) => r.id), gates: extras.gates.map((g) => g.id) },
25
+ };
26
+ }
7
27
  const SOURCE = { 'built-in': 'built in', imported: 'imported', project: 'agjan.config.json' };
8
28
  /**
9
29
  * agjan workflow list | show <kind> (decision 90): the workflows with their default teams, and
@@ -15,30 +35,34 @@ export function run(ctx, argv) {
15
35
  const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { team: { type: 'string' }, light: { type: 'boolean' }, json: { type: 'boolean' } } });
16
36
  const s = ctx.style;
17
37
  if (positionals[0] === 'list' && positionals.length === 1 && values.json) {
18
- const workflows = Object.values(WORKFLOWS).map((w) => ({ kind: w.kind, name: w.name, skill: `/${w.skill}`, stages: w.stages, team: defaultTeam(ctx.config, w.kind) }));
19
- const teams = Object.entries(allTeams(ctx.config)).map(([name, t]) => ({ name, description: t.description, workflows: t.workflows, source: teamSource(ctx.config, name) }));
38
+ const workflows = workflowNames(ctx.config).map((name) => listed(ctx, name));
39
+ const teams = Object.entries(allTeams(ctx.config)).map(([name, t]) => ({ name, description: t.description, workflows: t.workflows, source: teamSource(ctx.config, name), personas: t.personas }));
20
40
  ctx.out(JSON.stringify({ schema: 1, workflows, teams }, null, 2));
21
41
  return 0;
22
42
  }
23
43
  if (positionals[0] === 'list' && positionals.length === 1) {
24
- for (const w of Object.values(WORKFLOWS)) {
25
- ctx.out(`${s.bold(w.kind.padEnd(11))} /${w.skill.padEnd(16)} ${w.stages.join(' → ').padEnd(30)} ${s.gray(`team ${defaultTeam(ctx.config, w.kind) ?? '-'}`)}`);
44
+ for (const name of workflowNames(ctx.config)) {
45
+ const w = listed(ctx, name);
46
+ const extras = [...w.extras.reviews.map((r) => `review ${r}`), ...w.extras.gates.map((g) => `gate ${g}`)];
47
+ ctx.out(`${s.bold(name.padEnd(11))} ${w.skill.padEnd(17)} ${w.stages.join(' → ').padEnd(30)} ${s.gray(`team ${w.team ?? '-'}${w.base !== name ? `; on ${w.base}` : ''}${extras.length ? `; + ${extras.join(', ')}` : ''}`)}`);
26
48
  }
27
49
  return 0;
28
50
  }
29
51
  if (positionals[0] !== 'show' || positionals.length !== 2)
30
52
  throw new UsageError(USAGE);
31
- const kind = positionals[1];
32
- if (!WORKFLOWS[kind])
33
- throw new UsageError(`no workflow '${positionals[1]}' (workflows: ${Object.keys(WORKFLOWS).join(', ')})`);
34
- const view = resolveWorkflow(ctx.root, ctx.config, kind, { team: values.team, light: values.light });
53
+ const name = positionals[1];
54
+ if (!baseOf(ctx.config, name))
55
+ throw new UsageError(`no workflow '${name}' (workflows: ${workflowNames(ctx.config).join(', ')})`);
56
+ const view = resolveWorkflow(ctx.root, ctx.config, name, { team: values.team, light: values.light });
35
57
  if (values.json) {
36
58
  // The team's problems are in the data; tools read them there.
37
59
  ctx.out(JSON.stringify(view, null, 2));
38
60
  return 0;
39
61
  }
40
62
  const mode = view.workflow.mode ? ` (${view.workflow.mode})` : '';
41
- ctx.out(`${s.bold(`${view.workflow.name} workflow`)}${mode}, started with ${view.workflow.skill}`);
63
+ ctx.out(`${s.bold(`${view.workflow.name} workflow`)}${mode}, started with ${view.workflow.skill}${view.workflow.base !== view.workflow.kind ? s.gray(` (the ${view.workflow.base} workflow with its own additions)`) : ''}`);
64
+ if (view.workflow.description)
65
+ ctx.out(` ${s.gray(view.workflow.description)}`);
42
66
  if (view.team) {
43
67
  ctx.out(`team ${s.bold(view.team.name)} ${s.gray(`(${SOURCE[view.team.source]}${view.team.default ? ', the default' : ''})`)}`);
44
68
  if (view.team.description)
@@ -48,6 +72,7 @@ export function run(ctx, argv) {
48
72
  ctx.out('', s.bold(stage.name));
49
73
  for (const step of stage.steps) {
50
74
  const details = [
75
+ step.extra ? `extra ${step.review ? 'review' : 'gate'} ${step.review?.step ?? step.gate?.name}` : '',
51
76
  step.review ? `${step.review.tier}${step.review.per ? `, per ${step.review.per}` : ''}, up to ${step.review.rounds} rounds` : '',
52
77
  step.gate ? step.gate.command : '',
53
78
  step.off ? `skipped: ${step.off}` : '',
@@ -56,13 +81,17 @@ export function run(ctx, argv) {
56
81
  ctx.out(` ${step.agent.padEnd(21)} ${does}${details.length ? s.gray(` (${details.join('; ')})`) : ''}`);
57
82
  }
58
83
  }
59
- const roles = [...new Set(view.stages.flatMap((st) => st.steps).filter((st) => st.role).map((st) => st.role))];
60
- if (view.team && roles.length) {
84
+ // Each role once, with the agent it reaches: the built-in roles first, then the team's own.
85
+ const seen = new Map();
86
+ for (const step of view.stages.flatMap((st) => st.steps))
87
+ for (const p of step.personas)
88
+ if (!seen.has(p.role))
89
+ seen.set(p.role, { agent: step.actor === 'main' ? 'main agent' : step.actor === 'qa' ? 'QA agent' : 'reviewer', persona: p });
90
+ if (view.team && seen.size) {
61
91
  ctx.out('', s.bold(`What the agents work with (team ${view.team.name})`));
62
- for (const role of roles) {
63
- const persona = view.stages.flatMap((st) => st.steps).find((st) => st.role === role)?.persona;
64
- ctx.out(` ${role.padEnd(21)} ${persona?.skills.length ? persona.skills.join(', ') : s.gray('no persona')}`);
65
- if (persona?.instructions?.trim())
92
+ for (const [role, { agent, persona }] of seen) {
93
+ ctx.out(` ${role.padEnd(21)} ${persona.skills.length ? persona.skills.join(', ') : s.gray('no skills')}${s.gray(` (${agent}${persona.description ? `: ${persona.description}` : ''})`)}`);
94
+ if (persona.instructions?.trim())
66
95
  ctx.out(` ${''.padEnd(21)} ${s.gray(persona.instructions.trim().replace(/\s+/g, ' '))}`);
67
96
  }
68
97
  }
@@ -0,0 +1,172 @@
1
+ import { AgjanError } from './errors.js';
2
+ import { latestReview, stillBlocked } from './feature.js';
3
+ import { treeHash } from './review.js';
4
+ import { WORKFLOWS } from './workflow.js';
5
+ /** The stages extras attach to, per built-in workflow, and the built-in review step whose material each reviews. */
6
+ export const STAGES = {
7
+ feature: ['spec', 'design', 'build', 'verify'],
8
+ fix: ['fix'],
9
+ map: ['map'],
10
+ discovery: ['proposal'],
11
+ };
12
+ const DOCUMENT_STAGES = ['spec', 'design', 'proposal'];
13
+ /** Step names an extra review or gate cannot take: agjan's own steps, gates and commands. */
14
+ export const RESERVED = ['spec', 'design', 'verify', 'qa', 'fix', 'map', 'proposal', 'build', 'amendment', 'discovery', 'discover', 'feature', 'ask'];
15
+ export const EXTRA_ID = /^[a-z][a-z0-9-]{1,31}$/;
16
+ export const WORKFLOW_NAME = /^[a-z][a-z0-9-]{1,31}$/;
17
+ /** The built-in workflow a workflow name runs on: itself, or a derived workflow's base. */
18
+ export function baseOf(config, name) {
19
+ if (WORKFLOWS[name])
20
+ return name;
21
+ const base = config.workflows?.[name]?.base;
22
+ return base && WORKFLOWS[base] ? base : null;
23
+ }
24
+ /** The built-in workflows, then the project's own. */
25
+ export function workflowNames(config) {
26
+ const own = Object.entries(config.workflows ?? {}).filter(([name, w]) => !WORKFLOWS[name] && w.base).map(([name]) => name);
27
+ return [...Object.keys(WORKFLOWS), ...own];
28
+ }
29
+ /** The workflow a unit runs: the one it recorded at its start, else its kind's. */
30
+ export function unitWorkflow(unit) {
31
+ return unit.approvals.feature.workflow ?? unit.kind;
32
+ }
33
+ /** A workflow's extras. */
34
+ export function extrasOf(config, name) {
35
+ const w = config.workflows?.[name];
36
+ return { reviews: w?.reviews ?? [], gates: w?.gates ?? [] };
37
+ }
38
+ /** An extra review step by its id, in any workflow (ids are unique across them). */
39
+ export function findExtraReview(config, id) {
40
+ for (const w of Object.values(config.workflows ?? {})) {
41
+ const found = w.reviews?.find((r) => r.id === id);
42
+ if (found)
43
+ return found;
44
+ }
45
+ return null;
46
+ }
47
+ /** What is wrong with the `workflows` configuration; `check` reports it. */
48
+ export function workflowConfigProblems(config) {
49
+ const problems = [];
50
+ const ids = new Map();
51
+ const roles = (role) => role === 'reviewer' || config.roles?.[role]?.agent === 'reviewer';
52
+ for (const [name, w] of Object.entries(config.workflows ?? {})) {
53
+ const builtIn = Boolean(WORKFLOWS[name]);
54
+ const where = `workflows.${name}`;
55
+ if (builtIn && w.base)
56
+ problems.push(`${where}: a built-in workflow has no base`);
57
+ if (!builtIn) {
58
+ if (!WORKFLOW_NAME.test(name) || RESERVED.includes(name))
59
+ problems.push(`${where}: '${name}' is not a workflow name (lowercase letters, digits and -; not one of agjan's names)`);
60
+ if (!w.base || !WORKFLOWS[w.base])
61
+ problems.push(`${where}: base must be one of ${Object.keys(WORKFLOWS).join(', ')}`);
62
+ }
63
+ const base = baseOf(config, name);
64
+ const stages = base ? STAGES[base] : [];
65
+ for (const [list, items] of [['reviews', w.reviews ?? []], ['gates', w.gates ?? []]]) {
66
+ for (const item of items) {
67
+ const at = `${where}.${list}.${item.id}`;
68
+ if (!EXTRA_ID.test(item.id) || RESERVED.includes(item.id))
69
+ problems.push(`${at}: '${item.id}' is not a step name (lowercase letters, digits and -; not one of agjan's steps)`);
70
+ if (ids.has(item.id))
71
+ problems.push(`${at}: the name '${item.id}' is already used in ${ids.get(item.id)}`);
72
+ ids.set(item.id, where);
73
+ if (base && !stages.includes(item.stage))
74
+ problems.push(`${at}: stage '${item.stage}' is not a stage of ${base} (${stages.join(', ')})`);
75
+ }
76
+ }
77
+ for (const r of w.reviews ?? []) {
78
+ if (r.role && !roles(r.role))
79
+ problems.push(`${where}.reviews.${r.id}: role '${r.role}' does not reach the reviewer (the reviewer, or a role under "roles" with agent "reviewer")`);
80
+ }
81
+ }
82
+ return problems;
83
+ }
84
+ /** The hash an extra at a document stage compares: the documents the stage approves. */
85
+ function documentHash(unit, stage) {
86
+ if (stage === 'spec')
87
+ return unit.spec?.hash ?? null;
88
+ if (stage === 'design')
89
+ return unit.designHash ?? null;
90
+ if (stage === 'proposal')
91
+ return unit.proposal?.hash ?? null;
92
+ return null;
93
+ }
94
+ /** An extra review's state: none, blocked, stale (its stage's documents or the files changed after it), current. */
95
+ export function extraReviewState(root, config, unit, review, tree) {
96
+ const record = latestReview(unit.reviews, [review.id]);
97
+ if (!record)
98
+ return { state: 'none', record: null };
99
+ if (stillBlocked(unit, record))
100
+ return { state: 'blocked', record };
101
+ if (DOCUMENT_STAGES.includes(review.stage)) {
102
+ const docs = record.documents ?? {};
103
+ const seen = review.stage === 'spec' ? docs.spec : review.stage === 'design' ? docs.design : docs.proposal;
104
+ const fresh = seen === documentHash(unit, review.stage) && (review.stage !== 'design' || docs.spec === unit.spec?.hash);
105
+ return { state: fresh ? 'current' : 'stale', record };
106
+ }
107
+ const current = tree ? (tree.value ??= treeHash(root, config)) : treeHash(root, config);
108
+ return { state: record.tree_hash === current ? 'current' : 'stale', record };
109
+ }
110
+ /** The hash an extra gate's approval names: the stage's documents, or the files (tree hash). */
111
+ export function gateHash(root, config, unit, gate, tree) {
112
+ if (DOCUMENT_STAGES.includes(gate.stage))
113
+ return documentHash(unit, gate.stage);
114
+ return tree ? (tree.value ??= treeHash(root, config)) : treeHash(root, config);
115
+ }
116
+ /** An extra gate's state: none, stale (approved for other documents or files), approved. */
117
+ export function extraGateState(root, config, unit, gate, tree) {
118
+ const stamp = unit.approvals.approvals[gate.id];
119
+ if (!stamp)
120
+ return 'none';
121
+ return stamp.hash === gateHash(root, config, unit, gate, tree) ? 'approved' : 'stale';
122
+ }
123
+ /** What the unit's extras at `stages` still need: reviews not current, gates not approved, open blockers of extra steps. */
124
+ export function pendingExtras(root, config, unit, stages) {
125
+ const { reviews, gates } = extrasOf(config, unitWorkflow(unit));
126
+ const tree = {};
127
+ const out = [];
128
+ for (const r of reviews.filter((x) => stages.includes(x.stage))) {
129
+ const s = extraReviewState(root, config, unit, r, tree);
130
+ const what = DOCUMENT_STAGES.includes(r.stage) ? 'the documents' : 'files';
131
+ const problem = s.state === 'none' ? `review step ${r.id} is due (${r.description})`
132
+ : s.state === 'blocked' ? `the latest ${r.id} review ${s.record.id} is blocked`
133
+ : s.state === 'stale' ? `the ${r.id} review ${s.record.id} is stale: ${what} changed after it; review step ${r.id} again`
134
+ : null;
135
+ if (problem)
136
+ out.push({ kind: 'review', id: r.id, stage: r.stage, description: r.description, problem });
137
+ for (const f of unit.findings.filter((x) => x.step === r.id && x.status === 'open' && x.severity === 'blocker')) {
138
+ out.push({ kind: 'review', id: r.id, stage: r.stage, description: r.description, problem: `open blocker ${f.id}: ${f.issue}` });
139
+ }
140
+ }
141
+ for (const g of gates.filter((x) => stages.includes(x.stage))) {
142
+ const state = extraGateState(root, config, unit, g, tree);
143
+ if (state === 'approved')
144
+ continue;
145
+ const problem = `gate ${g.id} (${g.description}) is ${state === 'stale' ? 'stale: approved for an earlier state' : 'not approved'}: a human runs 'npx agjan approve ${g.id}' in a terminal`;
146
+ out.push({ kind: 'gate', id: g.id, stage: g.stage, description: g.description, problem });
147
+ }
148
+ return out;
149
+ }
150
+ /**
151
+ * The workflow a new unit of `kind` runs: `kind`'s own, or one of the project's own based on
152
+ * it (`--workflow`). Refused when the name is unknown or based on another kind.
153
+ */
154
+ export function startWorkflow(config, kind, requested) {
155
+ if (!requested || requested === kind)
156
+ return kind;
157
+ const base = baseOf(config, requested);
158
+ if (!base || WORKFLOWS[requested]) {
159
+ const own = workflowNames(config).filter((n) => baseOf(config, n) === kind && n !== kind);
160
+ throw new AgjanError(`no workflow '${requested}' based on ${kind}${own.length ? ` (yours: ${own.join(', ')})` : ' (define one under "workflows" in agjan.config.json)'}`);
161
+ }
162
+ if (base !== kind)
163
+ throw new AgjanError(`workflow '${requested}' is based on ${base}, not ${kind}: start it with ${START[base]}`);
164
+ return requested;
165
+ }
166
+ /** How a unit of each built-in workflow starts. */
167
+ export const START = {
168
+ feature: 'npx agjan new <slug> --key <KEY>',
169
+ fix: 'npx agjan fix start <slug> --key <KEY> --what "…"',
170
+ map: 'npx agjan map start',
171
+ discovery: 'npx agjan discover start <slug> --key <KEY> --question "…"',
172
+ };
package/dist/imports.js CHANGED
@@ -6,6 +6,7 @@ import { dirname, join, relative } from 'node:path';
6
6
  import { readJson, writeJson } from './json-file.js';
7
7
  import { AgjanError } from './errors.js';
8
8
  import { loadSchema, validate } from './schema.js';
9
+ import { ROLES } from './teams.js';
9
10
  /**
10
11
  * Imports (decision 93): skills and teams from another repository, at an exact commit.
11
12
  *
@@ -50,6 +51,15 @@ function manifestProblems(data) {
50
51
  if (data.teams !== undefined) {
51
52
  for (const p of validate(loadSchema('config'), { teams: data.teams }))
52
53
  problems.push(`${MANIFEST}: ${p}`);
54
+ // A package brings no roles or named personas: its teams use the built-in roles, with their personas inline.
55
+ for (const [name, team] of Object.entries(data.teams ?? {})) {
56
+ for (const [role, persona] of Object.entries(team?.personas ?? {})) {
57
+ if (!ROLES.includes(role))
58
+ problems.push(`${MANIFEST}: teams.${name}: role '${role}' is not a built-in role (${ROLES.join(', ')})`);
59
+ if (typeof persona === 'string')
60
+ problems.push(`${MANIFEST}: teams.${name}.personas.${role}: a package's personas are written out, not named`);
61
+ }
62
+ }
53
63
  }
54
64
  return problems;
55
65
  }
package/dist/plan.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { kitSkillFiles } from './managed.js';
3
+ import { workflowSkillFiles } from './workflow-skill.js';
3
4
  import * as claudeCode from './adapters/claude-code.js';
4
5
  import * as copilot from './adapters/copilot.js';
5
6
  import * as mcpConfig from './mcp-config.js';
@@ -15,7 +16,8 @@ function importsAgents(text) {
15
16
  * and the files of each enabled host adapter (design 4.4).
16
17
  */
17
18
  export function buildPlan(config) {
18
- const skills = kitSkillFiles();
19
+ // The kit's skills, and the generated skills of the project's own workflows (decision 95).
20
+ const skills = { ...kitSkillFiles(), ...workflowSkillFiles(config) };
19
21
  const items = Object.entries(skills).map(([path, content]) => ({ kind: 'file', path: `${SKILLS_DIR}/${path}`, content }));
20
22
  const hosts = config.hosts ?? [claudeCode.HOST];
21
23
  items.push({ kind: 'block', path: 'AGENTS.md', style: 'md', content: AGENTS_BLOCK });
@@ -252,6 +252,8 @@ export function unitModel(ctx, slug, { onBase = false, now = Date.now(), memo =
252
252
  }
253
253
  const decisions = [];
254
254
  for (const [gate, a] of Object.entries(unit.approvals.approvals)) {
255
+ if (!a)
256
+ continue;
255
257
  const by = 'enabled_by' in a && a.by === 'auto' ? `auto mode (switched on by ${a.enabled_by})` : a.by;
256
258
  decisions.push({ at: a.at_utc, by, what: gate === 'verify' ? 'accepted the feature' : `approved ${gate}` });
257
259
  }
@@ -320,7 +322,7 @@ export function unitModel(ctx, slug, { onBase = false, now = Date.now(), memo =
320
322
  decisions: shown,
321
323
  reviewers,
322
324
  humans,
323
- roundLimit: roundLimit(config),
325
+ roundLimits: Object.fromEntries([...new Set(reviews.map((r) => r.step))].map((step) => [step, roundLimit(config, step)])),
324
326
  stats: {
325
327
  activeMs: steps.reduce((t, s) => t + (s.to - s.from), 0),
326
328
  waitingMs: gates.reduce((t, s) => t + (s.to - s.from), 0),
@@ -441,7 +443,7 @@ export function unitMarkdown(model, { generatedAt }) {
441
443
  const course = rs
442
444
  .map((r, i) => `${i && r.round === 1 ? '↺ ' : i ? '→ ' : ''}${r.id} ${VERDICT_MD[r.verdict]}${r.findings.length ? ` (${severities(r.findings, model.findings)})` : ''}`)
443
445
  .join(' ');
444
- out.push(`| ${step} | ${rs.length} (limit ${model.roundLimit} per loop) | ${course} |`);
446
+ out.push(`| ${step} | ${rs.length} (limit ${model.roundLimits[step]} per loop) | ${course} |`);
445
447
  }
446
448
  out.push('');
447
449
  }
@@ -1,11 +1,13 @@
1
1
  /**
2
2
  * Review settings from agjan.config.json (design 7.3, 7.4): which reviewer agent runs a
3
- * step (`review.tiers`), how many correction rounds a step gets (`review.rounds`), and
3
+ * step (`review.tiers`), how many correction rounds a step gets (`review.rounds`, or its
4
+ * kind's own under `review.step_rounds`), and
4
5
  * how many attempts the main agent has for failing deterministic checks
5
6
  * (`build.fix_attempts`). `agjan status` shows them; the skills follow `status`.
6
7
  */
7
8
  import { stillBlocked } from './feature.js';
8
9
  import { readLog } from './log.js';
10
+ import { findExtraReview } from './customization.js';
9
11
  /** Default tier per kind of review step. */
10
12
  export const DEFAULT_TIERS = {
11
13
  spec: 'balanced',
@@ -22,14 +24,20 @@ export const DEFAULT_TIERS = {
22
24
  export function stepKind(step) {
23
25
  return step.startsWith('build:') ? 'build' : step;
24
26
  }
27
+ /** The tier of a step: `review.tiers`, else an extra review step's own (decision 95), else agjan's default. */
28
+ export function tierOf(config, step) {
29
+ const kind = stepKind(step);
30
+ return config.review?.tiers?.[kind] ?? findExtraReview(config, kind)?.tier ?? DEFAULT_TIERS[kind] ?? 'balanced';
31
+ }
25
32
  /** The generated reviewer agent for a step. There is no fast agent; `fast` uses the balanced one. */
26
33
  export function reviewerFor(config, step) {
27
- const kind = stepKind(step);
28
- const tier = config.review?.tiers?.[kind] ?? DEFAULT_TIERS[kind] ?? 'balanced';
34
+ const tier = tierOf(config, step);
29
35
  return tier === 'qa' ? 'agjan-qa' : tier === 'deep' ? 'agjan-reviewer-deep' : 'agjan-reviewer';
30
36
  }
31
- export function roundLimit(config) {
32
- return config.review?.rounds ?? 3;
37
+ /** The round limit of a review step: its kind's under `review.step_rounds` (or an extra step's own), else `review.rounds` (default 3). */
38
+ export function roundLimit(config, step) {
39
+ const own = step ? (config.review?.step_rounds?.[stepKind(step)] ?? findExtraReview(config, stepKind(step))?.rounds) : undefined;
40
+ return own ?? config.review?.rounds ?? 3;
33
41
  }
34
42
  export function fixAttempts(config) {
35
43
  return config.build?.fix_attempts ?? 3;
@@ -73,7 +81,7 @@ export function roundState(feature, config, step) {
73
81
  const records = feature.reviews.records.filter((r) => r.step === step);
74
82
  const last = records.at(-1) ?? null;
75
83
  const extra = extraRounds(feature, step);
76
- const limit = roundLimit(config) + extra;
84
+ const limit = roundLimit(config, step) + extra;
77
85
  const round = last?.round ?? 0;
78
86
  // Exhausted: still blocked, and the next round would pass the limit; a loop that an approval
79
87
  // or a passing verify review closed starts again at round 1 (nextRound).
package/dist/review.js CHANGED
@@ -15,13 +15,14 @@ import { acResults, loadResults, resultLabel } from './test-results.js';
15
15
  import { readTestRun, testRunProblem } from './test-run.js';
16
16
  import { WORKFLOWS, hasReviewStep, workflowOf } from './workflow.js';
17
17
  import { proposalProblems } from './discovery.js';
18
- import { personaText, unitTeam } from './teams.js';
18
+ import { personaText, personasFor, unitTeam } from './teams.js';
19
19
  import { LOG_FILE, appendLog } from './log.js';
20
20
  import { AgjanError } from './errors.js';
21
21
  import { nextRound, roundState } from './review-policy.js';
22
22
  import { designProblems, documentProblems } from './validate.js';
23
23
  import { QA_STEP, qaApplies, qaDirs, writeQaGuard, qaProblem, qaState, qaTestFiles, qaTestsHash } from './qa.js';
24
24
  import { buildProgress } from './progress.js';
25
+ import { extrasOf, unitWorkflow } from './customization.js';
25
26
  export const REVIEW_MD = 'review.md';
26
27
  const CONTEXT_DIR = '.agjan/review-contexts';
27
28
  /** Limit for diffs inside a review context, so a huge change cannot flood the reviewer. */
@@ -81,10 +82,15 @@ export function treeHash(root, config, except = []) {
81
82
  * only map.
82
83
  */
83
84
  export function parseStep(step, feature, config) {
85
+ const extra = extrasOf(config, unitWorkflow(feature)).reviews.find((r) => r.id === step);
86
+ if (extra) {
87
+ const tasks = extra.stage === 'build' || extra.stage === 'verify' ? (feature.tasks?.parsed.tasks ?? []) : undefined;
88
+ return { step, kind: extra.stage, ...(extra.stage === 'build' ? { tasks } : {}), extra };
89
+ }
84
90
  const workflow = workflowOf(feature.kind);
85
91
  if (feature.kind !== 'feature') {
86
92
  if (!hasReviewStep(workflow, step))
87
- throw new AgjanError(`a ${workflow.name} record has only the review step${workflow.reviewSteps.length > 1 ? 's' : ''} ${workflow.reviewSteps.map((s) => `'${s}'`).join(', ')}`);
93
+ throw new AgjanError(`a ${workflow.name} record has only the review step${workflow.reviewSteps.length > 1 ? 's' : ''} ${workflow.reviewSteps.map((s) => `'${s}'`).join(', ')} and its workflow's extra review steps`);
88
94
  return { step, kind: step };
89
95
  }
90
96
  const owner = Object.values(WORKFLOWS).find((w) => w.kind !== 'feature' && hasReviewStep(w, step));
@@ -94,7 +100,7 @@ export function parseStep(step, feature, config) {
94
100
  return { step, kind: step };
95
101
  const match = /^build:(.+)$/.exec(step ?? '');
96
102
  if (!match)
97
- throw new AgjanError(`unknown review step '${step}'; use spec, design, design:light, build:<area>, build:<task> or verify`);
103
+ throw new AgjanError(`unknown review step '${step}'; use spec, design, design:light, build:<area>, build:<task>, verify, or an extra review step of the feature's workflow`);
98
104
  const tasks = feature.tasks?.parsed.tasks ?? [];
99
105
  const byTask = tasks.filter((t) => t.id === match[1]);
100
106
  if (byTask.length)
@@ -227,10 +233,16 @@ export function buildContextText(root, config, feature, parsed) {
227
233
  `The unit's folder is \`${FEATURES_DIR}/${feature.slug}/\`. Cite files with the repository paths used below.`,
228
234
  '',
229
235
  ];
236
+ // An extra review step of the workflow (decision 95): its own focus on its stage's material.
237
+ if (parsed.extra)
238
+ parts.push(section(`This review: ${parsed.extra.id}`, `An extra review step of this project's ${unitWorkflow(feature)} workflow, on what its ${parsed.extra.stage} stage produced. Focus: ${parsed.extra.description}\n\nThe checklist of the stage's own review below still applies where it bears on this focus.`));
230
239
  parts.push(section('Checklist', CHECKLISTS[parsed.kind]));
231
240
  // The unit's team adds what the reviewer works with; it never removes a check (decision 92).
241
+ // An extra review names its role: the reviewer then works with that role's persona.
232
242
  const team = unitTeam(config, feature.approvals.feature.team);
233
- const reviewer = team?.team ? personaText(team.name, 'reviewer', team.team.personas.reviewer) : null;
243
+ const role = parsed.extra?.role;
244
+ const personas = !team?.team ? [] : role && role !== 'reviewer' ? (team.team.personas[role] ? [{ role, persona: team.team.personas[role] }] : []) : personasFor(config, team.team, feature.kind, 'reviewer');
245
+ const reviewer = team?.team ? personaText(config, team.name, personas) : null;
234
246
  if (reviewer)
235
247
  parts.push(section('Your team', reviewer));
236
248
  const baseline = join(root, FEATURES_DIR, 'project.md');
@@ -386,7 +398,8 @@ function withinRoundLimit(feature, config, step) {
386
398
  export function createReviewContext(root, config, { feature: slug, step }) {
387
399
  const feature = loadFeature(root, slug);
388
400
  const parsed = parseStep(step, feature, config);
389
- unfinishedDocuments(feature, config, parsed.step);
401
+ // An extra review needs what its stage's own review needs: complete documents.
402
+ unfinishedDocuments(feature, config, parsed.extra ? (parsed.kind === 'design' && feature.design?.parsed.mode === 'light' ? 'design:light' : parsed.kind) : parsed.step);
390
403
  if (parsed.step === QA_STEP)
391
404
  throw new AgjanError('step qa is done by the QA agent (agjan-qa, qa_context), not by a reviewer');
392
405
  withinRoundLimit(feature, config, parsed.step);
@@ -554,7 +567,7 @@ export function createQaContext(root, config, { feature: slug }) {
554
567
  section('Run locally (from agjan-docs/project.md)', runLocally || '(not described: start the application as the project README or package.json says)'),
555
568
  ...((() => {
556
569
  const team = unitTeam(config, feature.approvals.feature.team);
557
- const tester = team?.team ? personaText(team.name, 'tester', team.team.personas.tester) : null;
570
+ const tester = team?.team ? personaText(config, team.name, personasFor(config, team.team, feature.kind, 'qa')) : null;
558
571
  return tester ? [section('Your team', tester)] : [];
559
572
  })()),
560
573
  section('Test conventions', `${commands}\n- UI tests: ${ui ? '`npx agjan ui-test` runs the Playwright tests (it skips them, with the reason, where no browser can start)' : 'the project has no Playwright setup (no `test:ui` script): write service tests only'}\n- How tests are written in this stack: \`.claude/skills/cap-developer/references/testing.md\` (cds.test) and \`.claude/skills/fiori-developer/references/testing.md\` (Playwright). Read those for the test mechanics only.`),