agjan 0.0.27 → 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.
@@ -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}` : '',
@@ -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/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
  }
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { stillBlocked } from './feature.js';
9
9
  import { readLog } from './log.js';
10
+ import { findExtraReview } from './customization.js';
10
11
  /** Default tier per kind of review step. */
11
12
  export const DEFAULT_TIERS = {
12
13
  spec: 'balanced',
@@ -23,15 +24,19 @@ export const DEFAULT_TIERS = {
23
24
  export function stepKind(step) {
24
25
  return step.startsWith('build:') ? 'build' : step;
25
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
+ }
26
32
  /** The generated reviewer agent for a step. There is no fast agent; `fast` uses the balanced one. */
27
33
  export function reviewerFor(config, step) {
28
- const kind = stepKind(step);
29
- const tier = config.review?.tiers?.[kind] ?? DEFAULT_TIERS[kind] ?? 'balanced';
34
+ const tier = tierOf(config, step);
30
35
  return tier === 'qa' ? 'agjan-qa' : tier === 'deep' ? 'agjan-reviewer-deep' : 'agjan-reviewer';
31
36
  }
32
- /** The round limit of a review step: its kind's under `review.step_rounds`, else `review.rounds` (default 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). */
33
38
  export function roundLimit(config, step) {
34
- const own = step ? config.review?.step_rounds?.[stepKind(step)] : undefined;
39
+ const own = step ? (config.review?.step_rounds?.[stepKind(step)] ?? findExtraReview(config, stepKind(step))?.rounds) : undefined;
35
40
  return own ?? config.review?.rounds ?? 3;
36
41
  }
37
42
  export function fixAttempts(config) {
package/dist/review.js CHANGED
@@ -22,6 +22,7 @@ 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(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);
package/dist/teams.js CHANGED
@@ -3,6 +3,7 @@ import { join } from 'node:path';
3
3
  import { hashText } from './hash.js';
4
4
  import { AgjanError } from './errors.js';
5
5
  import { WORKFLOWS } from './workflow.js';
6
+ import { baseOf } from './customization.js';
6
7
  export const ROLES = ['implementer', 'reviewer', 'tester', 'analyst'];
7
8
  export const ROLE_AGENTS = ['main', 'reviewer', 'qa'];
8
9
  /** The agent each built-in role reaches; implementer and analyst are the main agent in different workflows. */
@@ -72,12 +73,26 @@ export function personasFor(config, team, kind, agent) {
72
73
  }
73
74
  return out;
74
75
  }
75
- /** The default team of a workflow: the project's choice (`team.<kind>`), else the first that serves it. */
76
- export function defaultTeam(config, kind) {
77
- const chosen = config.team?.[kind];
76
+ /**
77
+ * The default team of a workflow: the project's choice (`team.<workflow>`), else the first
78
+ * that serves it; a workflow of the project's own falls back to its base's default.
79
+ */
80
+ export function defaultTeam(config, workflow) {
81
+ const chosen = config.team?.[workflow];
78
82
  if (chosen)
79
83
  return chosen;
80
- return Object.entries(allTeams(config)).find(([, t]) => t.workflows.includes(kind))?.[0] ?? null;
84
+ const serving = Object.entries(allTeams(config)).find(([, t]) => t.workflows.includes(workflow))?.[0];
85
+ if (serving)
86
+ return serving;
87
+ const base = baseOf(config, workflow);
88
+ return base && base !== workflow ? defaultTeam(config, base) : null;
89
+ }
90
+ /** Whether a team serves a workflow: by name, or, for a workflow of the project's own, its base. */
91
+ export function serves(config, team, workflow) {
92
+ if (team.workflows.includes(workflow))
93
+ return true;
94
+ const base = baseOf(config, workflow);
95
+ return Boolean(base && base !== workflow && team.workflows.includes(base));
81
96
  }
82
97
  /** JSON with the keys of every object sorted: the same definition always gives the same text. */
83
98
  function canonical(value) {
@@ -102,10 +117,10 @@ export function teamProblems(root, config, name, kind) {
102
117
  if (!team.workflows?.length)
103
118
  problems.push(`team '${name}' serves no workflow`);
104
119
  for (const w of team.workflows ?? [])
105
- if (!WORKFLOWS[w])
120
+ if (!baseOf(config, w))
106
121
  problems.push(`team '${name}': unknown workflow '${w}'`);
107
- if (kind && !team.workflows?.includes(kind))
108
- problems.push(`team '${name}' does not serve the ${WORKFLOWS[kind].name} workflow (it serves: ${team.workflows.join(', ')})`);
122
+ if (kind && !serves(config, team, kind))
123
+ problems.push(`team '${name}' does not serve the ${WORKFLOWS[kind]?.name ?? kind} workflow (it serves: ${team.workflows.join(', ')})`);
109
124
  const custom = Object.keys(config.roles ?? {});
110
125
  for (const [role, ref] of Object.entries(definition.personas ?? {})) {
111
126
  const agent = roleAgent(config, role);
@@ -118,7 +133,7 @@ export function teamProblems(root, config, name, kind) {
118
133
  problems.push(`team '${name}', ${role}: no skill '${skill}' in .claude/skills/`);
119
134
  }
120
135
  // A role whose agent has no step in any of the team's workflows would never be used.
121
- if (agent && !ROLES.includes(role) && !(team.workflows ?? []).some((w) => WORKFLOWS[w]?.track.some((t) => t.steps.some((s) => s.actor === agent)))) {
136
+ if (agent && !ROLES.includes(role) && !(team.workflows ?? []).some((w) => WORKFLOWS[baseOf(config, w) ?? '']?.track.some((t) => t.steps.some((s) => s.actor === agent)))) {
122
137
  problems.push(`team '${name}', ${role}: its agent (${agent}) has no step in ${team.workflows.join(', ')}`);
123
138
  }
124
139
  }
@@ -126,7 +141,7 @@ export function teamProblems(root, config, name, kind) {
126
141
  if (ROLES.includes(role))
127
142
  problems.push(`roles: '${role}' is a built-in role`);
128
143
  for (const w of team.workflows ?? []) {
129
- for (const role of ROLES_OF[w] ?? []) {
144
+ for (const role of ROLES_OF[baseOf(config, w) ?? ''] ?? []) {
130
145
  if (!team.personas?.[role]?.skills?.length)
131
146
  problems.push(`team '${name}' serves ${w} but has no ${role} with skills`);
132
147
  }
@@ -161,11 +176,11 @@ export function unitTeam(config, recorded) {
161
176
  * it does not exist or does not serve the workflow; missing skills are `check`'s to report
162
177
  * (`agjan sync` installs the built-in ones).
163
178
  */
164
- export function chooseTeam(root, config, kind, explicit) {
165
- const name = explicit ?? defaultTeam(config, kind);
179
+ export function chooseTeam(root, config, workflow, explicit) {
180
+ const name = explicit ?? defaultTeam(config, workflow);
166
181
  if (!name)
167
182
  return null;
168
- const problems = teamProblems(root, config, name, kind).filter((p) => !p.includes('in .claude/skills/'));
183
+ const problems = teamProblems(root, config, name, workflow).filter((p) => !p.includes('in .claude/skills/'));
169
184
  if (problems.length)
170
185
  throw new AgjanError(problems.join('; '));
171
186
  return { name, hash: teamHash(allTeams(config)[name]) };
@@ -0,0 +1,61 @@
1
+ import { START, extrasOf, workflowNames, baseOf } from './customization.js';
2
+ import { WORKFLOWS } from './workflow.js';
3
+ /**
4
+ * The skill of a workflow of the project's own (decision 95): `agjan sync` writes it to
5
+ * `.claude/skills/agjan-<name>/SKILL.md`, generated from the configuration, so nobody writes
6
+ * agent instructions for it by hand. It follows the base workflow's skill, starts the unit
7
+ * with `--workflow`, and names the workflow's extra review steps and gates.
8
+ */
9
+ export function workflowSkill(config, name) {
10
+ const base = baseOf(config, name);
11
+ if (!base || base === name)
12
+ return null;
13
+ const definition = config.workflows?.[name] ?? {};
14
+ const workflow = WORKFLOWS[base];
15
+ const { reviews, gates } = extrasOf(config, name);
16
+ const what = (definition.description ?? `The ${name} workflow`).replace(/\s+/g, ' ').trim();
17
+ const start = `${START[base]} --workflow ${name}`;
18
+ const lines = [
19
+ '---',
20
+ `name: agjan-${name}`,
21
+ `description: ${what.replace(/[\r\n]/g, ' ')} (the project's own agjan workflow, based on ${workflow.name}).`,
22
+ '---',
23
+ '',
24
+ `# /agjan-${name}`,
25
+ '',
26
+ what,
27
+ '',
28
+ `This is the project's own workflow \`${name}\`, based on agjan's ${workflow.name} workflow. It is generated from \`workflows.${name}\` in \`agjan.config.json\` by \`agjan sync\`; change it there, not here.`,
29
+ '',
30
+ '## How to run it',
31
+ '',
32
+ `Follow the skill of the ${workflow.name} workflow, \`.claude/skills/${workflow.skill}/SKILL.md\` (read it now), step by step, with these changes:`,
33
+ '',
34
+ `1. Start the unit with \`--workflow ${name}\`: \`${start}\`. Everything else it says about starting (the branch, the key, asking the user) stays.`,
35
+ `2. The extra review steps and gates below belong to this workflow. \`npx agjan status\` names each when it is due (\`next\`), and the stage's gate or the acceptance waits for them. \`npx agjan workflow show ${name}\` shows the whole workflow.`,
36
+ '',
37
+ ];
38
+ if (reviews.length) {
39
+ lines.push('## Extra review steps', '');
40
+ for (const r of reviews)
41
+ lines.push(`- \`${r.id}\`, in the ${r.stage} stage: ${r.description.replace(/\s+/g, ' ')}`);
42
+ lines.push('', `Run an extra review step like the stage's own review: when all your edits are saved (and, after Build, committed), delegate, on its own, to the reviewer agent that \`npx agjan status\` names for it, with the prompt \`Review step <step> of <the unit's kind> <slug>.\`; read the result with \`npx agjan review show\`, show the user \`npx agjan review report\`, and fix its blockers within the round limit, as for the stage's own review.`, '');
43
+ }
44
+ if (gates.length) {
45
+ lines.push('## Extra gates', '');
46
+ for (const g of gates)
47
+ lines.push(`- \`${g.id}\`, in the ${g.stage} stage: ${g.description.replace(/\s+/g, ' ')}`);
48
+ lines.push('', 'An extra gate is the user\'s decision. When `npx agjan status` names it, request it (`npx agjan log --gate-requested <gate> --message "<commit message>"`) and ask the user to run `npx agjan approve <gate>` in a terminal; never run it yourself. Continue after the approval.', '');
49
+ }
50
+ return `${lines.join('\n').trimEnd()}\n`;
51
+ }
52
+ /** The generated skills of the project's own workflows, as { 'agjan-<name>/SKILL.md': content }. */
53
+ export function workflowSkillFiles(config) {
54
+ const out = {};
55
+ for (const name of workflowNames(config)) {
56
+ const text = workflowSkill(config, name);
57
+ if (text)
58
+ out[`agjan-${name}/SKILL.md`] = text;
59
+ }
60
+ return out;
61
+ }