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.
@@ -3,7 +3,29 @@ 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
+ /** The workflow's own review settings (`workflows.<name>.review`), as written; `workflow show` resolves them. */
26
+ review: { ...(ctx.config.workflows?.[name]?.review ?? {}) },
27
+ };
28
+ }
7
29
  const SOURCE = { 'built-in': 'built in', imported: 'imported', project: 'agjan.config.json' };
8
30
  /**
9
31
  * agjan workflow list | show <kind> (decision 90): the workflows with their default teams, and
@@ -15,30 +37,34 @@ export function run(ctx, argv) {
15
37
  const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { team: { type: 'string' }, light: { type: 'boolean' }, json: { type: 'boolean' } } });
16
38
  const s = ctx.style;
17
39
  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) }));
40
+ const workflows = workflowNames(ctx.config).map((name) => listed(ctx, name));
41
+ 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
42
  ctx.out(JSON.stringify({ schema: 1, workflows, teams }, null, 2));
21
43
  return 0;
22
44
  }
23
45
  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) ?? '-'}`)}`);
46
+ for (const name of workflowNames(ctx.config)) {
47
+ const w = listed(ctx, name);
48
+ const extras = [...w.extras.reviews.map((r) => `review ${r}`), ...w.extras.gates.map((g) => `gate ${g}`)];
49
+ 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
50
  }
27
51
  return 0;
28
52
  }
29
53
  if (positionals[0] !== 'show' || positionals.length !== 2)
30
54
  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 });
55
+ const name = positionals[1];
56
+ if (!baseOf(ctx.config, name))
57
+ throw new UsageError(`no workflow '${name}' (workflows: ${workflowNames(ctx.config).join(', ')})`);
58
+ const view = resolveWorkflow(ctx.root, ctx.config, name, { team: values.team, light: values.light });
35
59
  if (values.json) {
36
60
  // The team's problems are in the data; tools read them there.
37
61
  ctx.out(JSON.stringify(view, null, 2));
38
62
  return 0;
39
63
  }
40
64
  const mode = view.workflow.mode ? ` (${view.workflow.mode})` : '';
41
- ctx.out(`${s.bold(`${view.workflow.name} workflow`)}${mode}, started with ${view.workflow.skill}`);
65
+ 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)`) : ''}`);
66
+ if (view.workflow.description)
67
+ ctx.out(` ${s.gray(view.workflow.description)}`);
42
68
  if (view.team) {
43
69
  ctx.out(`team ${s.bold(view.team.name)} ${s.gray(`(${SOURCE[view.team.source]}${view.team.default ? ', the default' : ''})`)}`);
44
70
  if (view.team.description)
@@ -48,6 +74,7 @@ export function run(ctx, argv) {
48
74
  ctx.out('', s.bold(stage.name));
49
75
  for (const step of stage.steps) {
50
76
  const details = [
77
+ step.extra ? `extra ${step.review ? 'review' : 'gate'} ${step.review?.step ?? step.gate?.name}` : '',
51
78
  step.review ? `${step.review.tier}${step.review.per ? `, per ${step.review.per}` : ''}, up to ${step.review.rounds} rounds` : '',
52
79
  step.gate ? step.gate.command : '',
53
80
  step.off ? `skipped: ${step.off}` : '',
@@ -70,7 +97,9 @@ export function run(ctx, argv) {
70
97
  ctx.out(` ${''.padEnd(21)} ${s.gray(persona.instructions.trim().replace(/\s+/g, ' '))}`);
71
98
  }
72
99
  }
73
- ctx.out('', s.gray(`Every workflow keeps: ${view.controls.join(', ')}. A team adds knowledge; it cannot remove a step.`));
100
+ const own = Object.entries(view.review.override).map(([key, value]) => (typeof value === 'object' && value ? Object.entries(value).map(([k, v]) => `${key}.${k} ${v}`).join(', ') : `${key} ${value}`));
101
+ ctx.out('', s.gray(own.length ? `Review settings of this workflow (workflows.${name}.review): ${own.join(', ')}; the others are the project's (review) or agjan's defaults.` : `Review settings: the project's (review) or agjan's defaults; workflows.${name}.review overrides them for this workflow.`));
102
+ ctx.out(s.gray(`Every workflow keeps: ${view.controls.join(', ')}. A team adds knowledge; it cannot remove a step.`));
74
103
  for (const p of view.team?.problems ?? [])
75
104
  ctx.out(`${s.red('problem')} ${p}`);
76
105
  return view.team?.problems.length ? 1 : 0;
package/dist/config.js CHANGED
@@ -64,6 +64,16 @@ export function loadDomain(id) {
64
64
  throw new AgjanError(`unknown domain '${id}'`);
65
65
  return domain;
66
66
  }
67
+ /** The project's own `review` settings (agjan.config.json as written), by the configuration loadConfig made of it. */
68
+ const writtenReview = new WeakMap();
69
+ /**
70
+ * Whether agjan.config.json itself sets `review.<key>` (so a resolved value is the project's,
71
+ * not agjan's default); undefined for a configuration loadConfig did not make.
72
+ */
73
+ export function projectSetsReview(config, key) {
74
+ const written = writtenReview.get(config);
75
+ return written ? written[key] !== undefined : undefined;
76
+ }
67
77
  /**
68
78
  * Loads the effective configuration of the project at `root`: package defaults, then
69
79
  * the enabled domains' defaults, then agjan.config.json. Also resolves the areas of all
@@ -121,6 +131,7 @@ export function loadConfig(root) {
121
131
  config.teams = { ...imported, ...(config.teams ?? {}) };
122
132
  config.domains = domainIds;
123
133
  config.areas = areas;
134
+ writtenReview.set(config, isObject(project.review) ? project.review : {});
124
135
  return config;
125
136
  }
126
137
  /**
@@ -0,0 +1,198 @@
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
+ if (base && w.review)
82
+ problems.push(...workflowReviewProblems(where, base, w.review));
83
+ }
84
+ return problems;
85
+ }
86
+ /** The review steps of a built-in workflow by kind: `build:` is `build`. */
87
+ export function reviewKinds(base) {
88
+ return WORKFLOWS[base].reviewSteps.map((s) => (s === 'build:' ? 'build' : s));
89
+ }
90
+ /** Keys of `workflows.<name>.review` that its base does not have: a step it has no review of, QA or build reviews outside a feature. */
91
+ function workflowReviewProblems(where, base, review) {
92
+ const problems = [];
93
+ const kinds = reviewKinds(base);
94
+ for (const key of Object.keys(review.step_rounds ?? {})) {
95
+ if (!kinds.includes(key))
96
+ problems.push(`${where}.review.step_rounds: '${key}' is not a review step of ${base} (${kinds.join(', ')})`);
97
+ }
98
+ const tiered = kinds.filter((k) => k !== 'qa');
99
+ for (const key of Object.keys(review.tiers ?? {})) {
100
+ if (!tiered.includes(key))
101
+ problems.push(`${where}.review.tiers: '${key}' is not a review step of ${base} with a tier (${tiered.join(', ')})`);
102
+ }
103
+ if (base !== 'feature') {
104
+ for (const key of ['qa', 'build'])
105
+ if (review[key] !== undefined)
106
+ problems.push(`${where}.review.${key}: only a feature-based workflow has ${key === 'qa' ? 'a QA step' : 'build reviews'}`);
107
+ }
108
+ return problems;
109
+ }
110
+ /** The hash an extra at a document stage compares: the documents the stage approves. */
111
+ function documentHash(unit, stage) {
112
+ if (stage === 'spec')
113
+ return unit.spec?.hash ?? null;
114
+ if (stage === 'design')
115
+ return unit.designHash ?? null;
116
+ if (stage === 'proposal')
117
+ return unit.proposal?.hash ?? null;
118
+ return null;
119
+ }
120
+ /** An extra review's state: none, blocked, stale (its stage's documents or the files changed after it), current. */
121
+ export function extraReviewState(root, config, unit, review, tree) {
122
+ const record = latestReview(unit.reviews, [review.id]);
123
+ if (!record)
124
+ return { state: 'none', record: null };
125
+ if (stillBlocked(unit, record))
126
+ return { state: 'blocked', record };
127
+ if (DOCUMENT_STAGES.includes(review.stage)) {
128
+ const docs = record.documents ?? {};
129
+ const seen = review.stage === 'spec' ? docs.spec : review.stage === 'design' ? docs.design : docs.proposal;
130
+ const fresh = seen === documentHash(unit, review.stage) && (review.stage !== 'design' || docs.spec === unit.spec?.hash);
131
+ return { state: fresh ? 'current' : 'stale', record };
132
+ }
133
+ const current = tree ? (tree.value ??= treeHash(root, config)) : treeHash(root, config);
134
+ return { state: record.tree_hash === current ? 'current' : 'stale', record };
135
+ }
136
+ /** The hash an extra gate's approval names: the stage's documents, or the files (tree hash). */
137
+ export function gateHash(root, config, unit, gate, tree) {
138
+ if (DOCUMENT_STAGES.includes(gate.stage))
139
+ return documentHash(unit, gate.stage);
140
+ return tree ? (tree.value ??= treeHash(root, config)) : treeHash(root, config);
141
+ }
142
+ /** An extra gate's state: none, stale (approved for other documents or files), approved. */
143
+ export function extraGateState(root, config, unit, gate, tree) {
144
+ const stamp = unit.approvals.approvals[gate.id];
145
+ if (!stamp)
146
+ return 'none';
147
+ return stamp.hash === gateHash(root, config, unit, gate, tree) ? 'approved' : 'stale';
148
+ }
149
+ /** What the unit's extras at `stages` still need: reviews not current, gates not approved, open blockers of extra steps. */
150
+ export function pendingExtras(root, config, unit, stages) {
151
+ const { reviews, gates } = extrasOf(config, unitWorkflow(unit));
152
+ const tree = {};
153
+ const out = [];
154
+ for (const r of reviews.filter((x) => stages.includes(x.stage))) {
155
+ const s = extraReviewState(root, config, unit, r, tree);
156
+ const what = DOCUMENT_STAGES.includes(r.stage) ? 'the documents' : 'files';
157
+ const problem = s.state === 'none' ? `review step ${r.id} is due (${r.description})`
158
+ : s.state === 'blocked' ? `the latest ${r.id} review ${s.record.id} is blocked`
159
+ : s.state === 'stale' ? `the ${r.id} review ${s.record.id} is stale: ${what} changed after it; review step ${r.id} again`
160
+ : null;
161
+ if (problem)
162
+ out.push({ kind: 'review', id: r.id, stage: r.stage, description: r.description, problem });
163
+ for (const f of unit.findings.filter((x) => x.step === r.id && x.status === 'open' && x.severity === 'blocker')) {
164
+ out.push({ kind: 'review', id: r.id, stage: r.stage, description: r.description, problem: `open blocker ${f.id}: ${f.issue}` });
165
+ }
166
+ }
167
+ for (const g of gates.filter((x) => stages.includes(x.stage))) {
168
+ const state = extraGateState(root, config, unit, g, tree);
169
+ if (state === 'approved')
170
+ continue;
171
+ 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`;
172
+ out.push({ kind: 'gate', id: g.id, stage: g.stage, description: g.description, problem });
173
+ }
174
+ return out;
175
+ }
176
+ /**
177
+ * The workflow a new unit of `kind` runs: `kind`'s own, or one of the project's own based on
178
+ * it (`--workflow`). Refused when the name is unknown or based on another kind.
179
+ */
180
+ export function startWorkflow(config, kind, requested) {
181
+ if (!requested || requested === kind)
182
+ return kind;
183
+ const base = baseOf(config, requested);
184
+ if (!base || WORKFLOWS[requested]) {
185
+ const own = workflowNames(config).filter((n) => baseOf(config, n) === kind && n !== kind);
186
+ throw new AgjanError(`no workflow '${requested}' based on ${kind}${own.length ? ` (yours: ${own.join(', ')})` : ' (define one under "workflows" in agjan.config.json)'}`);
187
+ }
188
+ if (base !== kind)
189
+ throw new AgjanError(`workflow '${requested}' is based on ${base}, not ${kind}: start it with ${START[base]}`);
190
+ return requested;
191
+ }
192
+ /** How a unit of each built-in workflow starts. */
193
+ export const START = {
194
+ feature: 'npx agjan new <slug> --key <KEY>',
195
+ fix: 'npx agjan fix start <slug> --key <KEY> --what "…"',
196
+ map: 'npx agjan map start',
197
+ discovery: 'npx agjan discover start <slug> --key <KEY> --question "…"',
198
+ };
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 });
@@ -7,6 +7,7 @@ import { readLog } from './log.js';
7
7
  import { buildProgress, headHistory, prefetchFiles, repoMemo, verifyState } from './progress.js';
8
8
  import { verification } from './readiness.js';
9
9
  import { reviewerFor, roundLimit } from './review-policy.js';
10
+ import { unitWorkflow } from './customization.js';
10
11
  import { acTestFiles } from './tests-map.js';
11
12
  import { acResults, loadResults } from './test-results.js';
12
13
  import { freshReview } from './fix.js';
@@ -198,7 +199,7 @@ export function unitModel(ctx, slug, { onBase = false, now = Date.now(), memo =
198
199
  round: r.round,
199
200
  verdict: r.verdict,
200
201
  at: r.at_utc,
201
- tier: { 'agjan-reviewer-deep': 'deep', 'agjan-qa': 'qa' }[reviewerFor(config, r.step)] ?? 'balanced',
202
+ tier: { 'agjan-reviewer-deep': 'deep', 'agjan-qa': 'qa' }[reviewerFor(config, r.step, unitWorkflow(unit))] ?? 'balanced',
202
203
  host: r.reviewer?.host ?? null,
203
204
  isolation: r.reviewer?.isolation ?? null,
204
205
  findings: (r.findings ?? []).map((f) => f.id),
@@ -252,6 +253,8 @@ export function unitModel(ctx, slug, { onBase = false, now = Date.now(), memo =
252
253
  }
253
254
  const decisions = [];
254
255
  for (const [gate, a] of Object.entries(unit.approvals.approvals)) {
256
+ if (!a)
257
+ continue;
255
258
  const by = 'enabled_by' in a && a.by === 'auto' ? `auto mode (switched on by ${a.enabled_by})` : a.by;
256
259
  decisions.push({ at: a.at_utc, by, what: gate === 'verify' ? 'accepted the feature' : `approved ${gate}` });
257
260
  }
@@ -320,7 +323,7 @@ export function unitModel(ctx, slug, { onBase = false, now = Date.now(), memo =
320
323
  decisions: shown,
321
324
  reviewers,
322
325
  humans,
323
- roundLimits: Object.fromEntries([...new Set(reviews.map((r) => r.step))].map((step) => [step, roundLimit(config, step)])),
326
+ roundLimits: Object.fromEntries([...new Set(reviews.map((r) => r.step))].map((step) => [step, roundLimit(config, step, unitWorkflow(unit))])),
324
327
  stats: {
325
328
  activeMs: steps.reduce((t, s) => t + (s.to - s.from), 0),
326
329
  waitingMs: gates.reduce((t, s) => t + (s.to - s.from), 0),
package/dist/progress.js CHANGED
@@ -3,6 +3,8 @@ import { resolveArea } from './config.js';
3
3
  import { matcher } from './scope.js';
4
4
  import { latestReview, stillBlocked } from './feature.js';
5
5
  import { isRecord, treeHash } from './review.js';
6
+ import { resolveBuild } from './review-policy.js';
7
+ import { unitWorkflow } from './customization.js';
6
8
  export function repoMemo() {
7
9
  return { files: new Map(), ancestry: new Map(), texts: new Map() };
8
10
  }
@@ -94,7 +96,7 @@ function reviewedSince(root, feature, step, sha, memo) {
94
96
  }
95
97
  /**
96
98
  * Tasks with their state, the next task, and the build reviews that are due
97
- * (design 7.3): per completed area by default, per task with `review.build: task`, and
99
+ * (design 7.3): per completed area by default, per task with `review.build: task` (the unit's workflow's, else the project's), and
98
100
  * always per task for tasks whose commit touched a risk path.
99
101
  */
100
102
  export function buildProgress(root, config, feature, options = {}) {
@@ -109,7 +111,7 @@ export function buildProgress(root, config, feature, options = {}) {
109
111
  const dueReviews = () => {
110
112
  const isRisk = matcher(config.risk_paths ?? []);
111
113
  const due = [];
112
- const perTask = config.review?.build === 'task';
114
+ const perTask = resolveBuild(config, unitWorkflow(feature)).value === 'task';
113
115
  for (const task of list.filter((t) => t.commit)) {
114
116
  const risky = filesOf(root, task.commit, memo).some(isRisk);
115
117
  if ((perTask || risky) && !reviewedSince(root, feature, `build:${task.id}`, task.commit, memo)) {
package/dist/qa.js CHANGED
@@ -4,6 +4,8 @@ import { dirname, join } from 'node:path';
4
4
  import { contentIds } from './git.js';
5
5
  import { writeJson } from './json-file.js';
6
6
  import { FEATURES_DIR, latestReview, stillBlocked } from './feature.js';
7
+ import { resolveQa } from './review-policy.js';
8
+ import { unitWorkflow } from './customization.js';
7
9
  /**
8
10
  * The QA step (design decision 81): in Verify, the QA agent (`agjan-qa`, the qa-tester
9
11
  * skill) writes and runs tests from the spec alone, without the design, the diff or the
@@ -38,9 +40,9 @@ export function writeQaGuard(root, config, slug) {
38
40
  mkdirSync(dirname(file), { recursive: true });
39
41
  writeJson(file, qaGuard(config, slug));
40
42
  }
41
- /** QA runs for full-mode features unless the project turns it off (`review.qa: "off"`). */
43
+ /** QA runs for full-mode features unless the unit's workflow or the project turns it off (`review.qa: "off"`). */
42
44
  export function qaApplies(config, feature) {
43
- return feature.kind === 'feature' && feature.design?.parsed.mode === 'full' && config.review?.qa !== 'off';
45
+ return feature.kind === 'feature' && feature.design?.parsed.mode === 'full' && resolveQa(config, unitWorkflow(feature)).value !== 'off';
44
46
  }
45
47
  function filesUnder(root, dir) {
46
48
  const abs = join(root, dir);
@@ -1,12 +1,15 @@
1
1
  /**
2
2
  * Review settings from agjan.config.json (design 7.3, 7.4): which reviewer agent runs a
3
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
+ * kind's own under `review.step_rounds`), whether QA runs (`review.qa`), each also per
5
+ * workflow under `workflows.<name>.review` over the project's, and
5
6
  * how many attempts the main agent has for failing deterministic checks
6
7
  * (`build.fix_attempts`). `agjan status` shows them; the skills follow `status`.
7
8
  */
8
9
  import { stillBlocked } from './feature.js';
9
10
  import { readLog } from './log.js';
11
+ import { projectSetsReview } from './config.js';
12
+ import { findExtraReview, unitWorkflow } from './customization.js';
10
13
  /** Default tier per kind of review step. */
11
14
  export const DEFAULT_TIERS = {
12
15
  spec: 'balanced',
@@ -23,16 +26,84 @@ export const DEFAULT_TIERS = {
23
26
  export function stepKind(step) {
24
27
  return step.startsWith('build:') ? 'build' : step;
25
28
  }
26
- /** The generated reviewer agent for a step. There is no fast agent; `fast` uses the balanced one. */
27
- export function reviewerFor(config, step) {
29
+ /** A value of the project's `review`: agjan's default when agjan.config.json does not set it (loadConfig merged it in). */
30
+ function projectValue(config, key, value) {
31
+ return { value, source: projectSetsReview(config, key) === false ? 'default' : 'project' };
32
+ }
33
+ function workflowReview(config, workflow) {
34
+ return workflow ? config.workflows?.[workflow]?.review : undefined;
35
+ }
36
+ /**
37
+ * The tier of a step in `workflow`: the workflow's `review.tiers`, else the project's
38
+ * `review.tiers`, else an extra review step's own (decision 95), else agjan's default.
39
+ */
40
+ export function resolveTier(config, step, workflow) {
28
41
  const kind = stepKind(step);
29
- const tier = config.review?.tiers?.[kind] ?? DEFAULT_TIERS[kind] ?? 'balanced';
42
+ const own = workflowReview(config, workflow)?.tiers?.[kind];
43
+ if (own)
44
+ return { value: own, source: 'workflow' };
45
+ const project = config.review?.tiers?.[kind];
46
+ if (project)
47
+ return { value: project, source: 'project' };
48
+ const extra = findExtraReview(config, kind)?.tier;
49
+ if (extra)
50
+ return { value: extra, source: 'workflow' };
51
+ return { value: DEFAULT_TIERS[kind] ?? 'balanced', source: 'default' };
52
+ }
53
+ /**
54
+ * The round limit of a review step in `workflow`. The workflow's settings come first: its
55
+ * `review.step_rounds` for the step's kind, then (when it sets `review.rounds`) an extra
56
+ * step's own `rounds` and the workflow's `review.rounds`. Then the project's: its
57
+ * `review.step_rounds`, an extra step's own `rounds`, its `review.rounds`; else 3.
58
+ */
59
+ export function resolveRounds(config, step, workflow) {
60
+ const kind = step ? stepKind(step) : undefined;
61
+ const wf = workflowReview(config, workflow);
62
+ const extra = kind ? findExtraReview(config, kind)?.rounds : undefined;
63
+ const own = kind ? wf?.step_rounds?.[kind] : undefined;
64
+ if (own !== undefined)
65
+ return { value: own, source: 'workflow' };
66
+ if (wf?.rounds !== undefined)
67
+ return { value: extra ?? wf.rounds, source: 'workflow' };
68
+ const project = kind ? config.review?.step_rounds?.[kind] : undefined;
69
+ if (project !== undefined)
70
+ return { value: project, source: 'project' };
71
+ if (extra !== undefined)
72
+ return { value: extra, source: 'workflow' };
73
+ if (config.review?.rounds !== undefined)
74
+ return projectValue(config, 'rounds', config.review.rounds);
75
+ return { value: 3, source: 'default' };
76
+ }
77
+ /** Whether the QA step runs in `workflow` (feature-based): the workflow's `review.qa`, else the project's, else on. */
78
+ export function resolveQa(config, workflow) {
79
+ const own = workflowReview(config, workflow)?.qa;
80
+ if (own)
81
+ return { value: own, source: 'workflow' };
82
+ if (config.review?.qa)
83
+ return projectValue(config, 'qa', config.review.qa);
84
+ return { value: 'on', source: 'default' };
85
+ }
86
+ /** How builds are reviewed in `workflow` (feature-based): per area or per task. */
87
+ export function resolveBuild(config, workflow) {
88
+ const own = workflowReview(config, workflow)?.build;
89
+ if (own)
90
+ return { value: own, source: 'workflow' };
91
+ if (config.review?.build)
92
+ return projectValue(config, 'build', config.review.build);
93
+ return { value: 'area', source: 'default' };
94
+ }
95
+ /** The tier of a step (in `workflow`, the unit's; see resolveTier). */
96
+ export function tierOf(config, step, workflow) {
97
+ return resolveTier(config, step, workflow).value;
98
+ }
99
+ /** The generated reviewer agent for a step. There is no fast agent; `fast` uses the balanced one. */
100
+ export function reviewerFor(config, step, workflow) {
101
+ const tier = tierOf(config, step, workflow);
30
102
  return tier === 'qa' ? 'agjan-qa' : tier === 'deep' ? 'agjan-reviewer-deep' : 'agjan-reviewer';
31
103
  }
32
- /** The round limit of a review step: its kind's under `review.step_rounds`, else `review.rounds` (default 3). */
33
- export function roundLimit(config, step) {
34
- const own = step ? config.review?.step_rounds?.[stepKind(step)] : undefined;
35
- return own ?? config.review?.rounds ?? 3;
104
+ /** The round limit of a review step (in `workflow`, the unit's; see resolveRounds). */
105
+ export function roundLimit(config, step, workflow) {
106
+ return resolveRounds(config, step, workflow).value;
36
107
  }
37
108
  export function fixAttempts(config) {
38
109
  return config.build?.fix_attempts ?? 3;
@@ -76,7 +147,7 @@ export function roundState(feature, config, step) {
76
147
  const records = feature.reviews.records.filter((r) => r.step === step);
77
148
  const last = records.at(-1) ?? null;
78
149
  const extra = extraRounds(feature, step);
79
- const limit = roundLimit(config, step) + extra;
150
+ const limit = roundLimit(config, step, unitWorkflow(feature)) + extra;
80
151
  const round = last?.round ?? 0;
81
152
  // Exhausted: still blocked, and the next round would pass the limit; a loop that an approval
82
153
  // or a passing verify review closed starts again at round 1 (nextRound).
package/dist/review.js CHANGED
@@ -18,10 +18,11 @@ import { proposalProblems } from './discovery.js';
18
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
- import { nextRound, roundState } from './review-policy.js';
21
+ import { nextRound, resolveQa, 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(config, team.name, personasFor(config, team.team, feature.kind, '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);
@@ -529,7 +542,7 @@ export function recordReview(root, config, input, recorder) {
529
542
  export function createQaContext(root, config, { feature: slug }) {
530
543
  const feature = loadFeature(root, slug);
531
544
  if (!qaApplies(config, feature))
532
- throw new AgjanError(`QA does not apply to ${slug}: it runs for full-mode features (review.qa is ${config.review?.qa ?? 'on'})`);
545
+ throw new AgjanError(`QA does not apply to ${slug}: it runs for full-mode features (review.qa is ${resolveQa(config, unitWorkflow(feature)).value})`);
533
546
  if (feature.stage !== 'build' || !feature.spec)
534
547
  throw new AgjanError(`${slug} is not in Build yet; QA runs in Verify`);
535
548
  const progress = buildProgress(root, config, feature);