agjan 0.0.10 → 0.0.11

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.
Files changed (31) hide show
  1. package/docs/guide.md +39 -2
  2. package/kit/domains/btp/domain.json +4 -4
  3. package/kit/skills/agjan-build/SKILL.md +10 -6
  4. package/kit/skills/agjan-design/SKILL.md +36 -4
  5. package/kit/skills/agjan-fix/SKILL.md +11 -4
  6. package/kit/skills/agjan-map/SKILL.md +11 -4
  7. package/kit/skills/agjan-spec/SKILL.md +11 -4
  8. package/kit/skills/agjan-verify/SKILL.md +26 -6
  9. package/kit/skills/cap-developer/SKILL.md +10 -2
  10. package/kit/skills/cap-developer/references/handlers.md +11 -9
  11. package/kit/skills/cap-developer/references/project-setup.md +21 -8
  12. package/kit/skills/cap-developer/references/testing.md +38 -14
  13. package/kit/skills/cap-developer/references/typescript.md +143 -0
  14. package/kit/skills/cap-developer/references/validation-security.md +26 -8
  15. package/kit/skills/fiori-developer/SKILL.md +20 -5
  16. package/kit/skills/fiori-developer/references/app-setup.md +91 -16
  17. package/kit/skills/fiori-developer/references/elements.md +19 -5
  18. package/kit/skills/fiori-developer/references/freestyle-ts.md +5 -1
  19. package/kit/skills/fiori-developer/references/testing.md +109 -15
  20. package/kit/templates/agents-block.md +4 -0
  21. package/package.json +1 -1
  22. package/src/browser.mjs +49 -0
  23. package/src/cli.mjs +14 -4
  24. package/src/commands/branch.mjs +50 -15
  25. package/src/commands/check.mjs +17 -6
  26. package/src/commands/gates.mjs +12 -9
  27. package/src/commands/review.mjs +69 -4
  28. package/src/commands/setup.mjs +12 -2
  29. package/src/commands/status.mjs +13 -11
  30. package/src/commands/ui-test.mjs +38 -0
  31. package/src/review.mjs +9 -6
@@ -2,32 +2,126 @@
2
2
 
3
3
  Distilled from the SAPUI5 documentation (`SAP-docs/sapui5`, CC-BY-4.0) through the Fiori
4
4
  MCP server and from the UI5 MCP server's guidelines (Apache-2.0), retrieved on
5
- 2026-10-17. Rules restated.
5
+ 2026-10-17, and from the Playwright documentation (Apache-2.0); the UI tests were run
6
+ against `examples/skill-patterns` in Chromium on 2026-10-19. Rules restated.
6
7
 
7
8
  ## What to test where
8
9
 
9
10
  - Most ACs of a Fiori feature are about data and rules: test them in the **service**
10
11
  (`cap-developer`, `cds.test`), which is faster and stable. That includes annotations whose
11
12
  effect shows in `$metadata` or in the data (a filter, a value list, a computed field).
12
- - Use a UI test only for behavior that exists only in the UI (navigation, a button that
13
- appears in a state, a dialog). Name it with the AC id like any test.
14
- - An AC that cannot be tested automatically in a reasonable way is `Verification: manual`
15
- in the spec, decided at Spec time, not skipped in Build.
13
+ - Test in the **browser** (Playwright, below) what only the UI shows: that a user can do
14
+ what an AC describes on the page (create a record, choose an action, see a button in a
15
+ state). One UI test per such AC, named with the AC id, next to the service tests of
16
+ the same AC.
17
+ - An AC that cannot be tested automatically in a reasonable way (visual layout) is
18
+ `Verification: manual` in the spec, decided at Spec time, not skipped in Build.
16
19
 
17
- ## Fiori elements (OData V4)
20
+ ## UI tests: optional, with Playwright
18
21
 
19
- - OPA5 journeys with the `sap.fe.test` library: its page objects for list report and
20
- object page (`JourneyRunner`, `onTheMainPage`, ...). The OData V2 library
21
- (`sap/suite/ui/generic/template/integration/testLibrary`) is a different one; never mix
22
- them.
23
- - The Fiori MCP server's `search_docs` has a detailed guide for these journeys (query
24
- "OPA5 integration tests for SAP Fiori elements"): read it before writing one.
22
+ UI tests run the app in Playwright's Chromium against the CAP server with the mocked
23
+ users. They are **optional**: `npx agjan ui-test` runs them where Chromium can start and
24
+ otherwise says why and skips them (exit code 0). Never install system libraries or use
25
+ `sudo` to make them run; on Linux that is a decision for whoever maintains the machine or
26
+ container image (`npx agjan doctor` names it). When they are skipped, say so and name the
27
+ ACs that were not tried in a browser.
25
28
 
26
- ## Freestyle (TypeScript)
29
+ Setup, once per project (the task's paths list the test file and `.gitignore`;
30
+ `playwright.config.ts` and `package.json` are allowed implicitly):
27
31
 
28
- - QUnit and OPA5 as in `freestyle-ts.md`: page objects as classes extending `Opa5`.
32
+ 1. `npm install --save-dev @playwright/test`, then `npx playwright install chromium` (no
33
+ admin rights).
34
+ 2. The script `"test:ui": "playwright test"` in the root `package.json` (`agjan ui-test`
35
+ runs it), and `test-results/` and `playwright-report/` in `.gitignore`.
36
+ 3. `playwright.config.ts` in the project root:
37
+
38
+ <!-- checked: playwright.config.ts -->
39
+ ```ts
40
+ import { defineConfig } from '@playwright/test'
41
+
42
+ export default defineConfig({
43
+ testDir: 'test/ui',
44
+ timeout: 60_000,
45
+ expect: { timeout: 15_000 }, // UI5 loads its libraries on first use
46
+ workers: 1, // one server, shared data
47
+ reporter: [['list'], ['junit', { outputFile: 'test-results/ui.xml' }]],
48
+ use: { baseURL: 'http://localhost:4005', locale: 'en-US', trace: 'retain-on-failure' }, // dates as 'Dec 1, 2026'
49
+ webServer: {
50
+ command: 'npx cds-tsx serve --port 4005', // no file watching; fresh in-memory data
51
+ url: 'http://localhost:4005',
52
+ reuseExistingServer: false,
53
+ timeout: 120_000,
54
+ },
55
+ })
56
+ ```
57
+
58
+ - `cds serve`, not `cds watch`: the watcher restarts the server when Playwright writes
59
+ `test-results/`. `cds-tsx serve` in a TypeScript project, `cds serve` in JavaScript.
60
+ - Its own port, so a `cds watch` you have open on 4004 keeps running and the tests start
61
+ from the initial data.
62
+ - The JUnit file counts for `agjan check` only if the user adds it to
63
+ `verify.fiori.results`; then CI needs a browser too.
64
+
65
+ A test, `test/ui/<app>.spec.ts`:
66
+
67
+ <!-- checked: test/ui/requests.spec.ts -->
68
+ ```ts
69
+ const as = (user: string) => ({ httpCredentials: { username: user, password: user } })
70
+
71
+ async function openList(page: Page) {
72
+ await page.goto(app)
73
+ await page.getByRole('button', { name: 'Go' }).click()
74
+ return page.getByRole('grid', { name: 'Leave requests' })
75
+ }
76
+
77
+ test.describe('as employee', () => {
78
+ test.use(as('employee'))
79
+
80
+ test('TLR-AC2: an employee creates a request in the app', async ({ page }) => {
81
+ await openList(page)
82
+ await page.getByRole('button', { name: 'Create' }).click() // a draft
83
+ const request = page.getByRole('region', { name: 'Request' }) // the list page stays in the DOM
84
+ await request.getByRole('button', { name: 'Show Value Help' }).click() // pick, do not type
85
+ await page.getByRole('dialog', { name: 'Available Values' }).getByRole('row', { name: /Vacation/ }).click()
86
+ await request.getByRole('textbox', { name: 'Start date' }).fill('Dec 1, 2026')
87
+ await request.getByRole('textbox', { name: 'End date' }).fill('Dec 2, 2026')
88
+ await page.getByRole('button', { name: 'Create' }).click() // activates it
89
+ await expect(page.getByRole('heading', { name: 'Erika Employee' })).toBeVisible() // saved, no longer "New Object"
90
+ await expect(page.getByRole('region', { name: 'Decision' })).toContainText('New')
91
+ })
92
+ })
93
+ ```
94
+
95
+ Rules, each learned on a Fiori elements app:
96
+
97
+ - **Locate as a user sees the page**: by role and label (`getByRole('button', { name:
98
+ 'Create' })`), never by the generated UI5 ids or CSS classes; they change with UI5
99
+ versions.
100
+ - **Scope to the section**: Fiori elements keeps the list page in the DOM after
101
+ navigating, so `Type` matches the list's filter field too. Scope to the object page
102
+ section (`getByRole('region', { name: 'Request' })`) or a dialog.
103
+ - **Pick values from the value help**; text typed into a value-list field is not
104
+ selected and the draft fails with "Provide the missing value".
105
+ - **One user per `test.describe`** with `httpCredentials` (the mocked users' basic
106
+ authentication); never put a password in a URL.
107
+ - **Click Go** on a list report before reading rows; wait with `expect(...)`, never with
108
+ fixed timeouts.
109
+ - **Assert what the user sees** after the action: the saved title, the new status, a
110
+ disabled button. Each AC's test also fails without the change (a test of a create AC
111
+ fails without the draft).
112
+ - To find the names on a page, print `await page.locator('body').ariaSnapshot()` once
113
+ while writing the test, then remove it.
114
+
115
+ ## OPA5 (existing apps)
116
+
117
+ Apps that already have OPA5 journeys keep them: Fiori elements (OData V4) with the
118
+ `sap.fe.test` library (`JourneyRunner`, `onTheMainPage`), never mixed with the OData V2
119
+ library `sap/suite/ui/generic/template/integration/testLibrary`; freestyle with page
120
+ objects as classes extending `Opa5` (`freestyle-ts.md`). The Fiori MCP server's
121
+ `search_docs` has a guide ("OPA5 integration tests for SAP Fiori elements"). New UI tests
122
+ are Playwright tests.
29
123
 
30
124
  ## After every UI change
31
125
 
32
126
  - `npx agjan lint` (the UI5 linter), `run_manifest_validation` if the Fiori MCP server is
33
- available, then the tests.
127
+ available, the service tests, then `npx agjan ui-test`.
@@ -24,6 +24,8 @@ Rules for agents:
24
24
  - Run commands from the project root; do not `cd` into folders. Edit files with your
25
25
  editor tool, not with scripts. Check behavior with the project's tests (add one if
26
26
  needed), not with throwaway scripts.
27
+ - In a folder that does not exist yet, create its first file on its own before the
28
+ others: a batch of parallel creates fails when the folder is missing.
27
29
  - After a review, fix blockers, and majors where you agree. Minor findings may stay open
28
30
  (the PR summary lists them): do not spend a review round on minor findings alone. Any
29
31
  change after a review needs another round before the gate.
@@ -32,6 +34,8 @@ Rules for agents:
32
34
  user whether to run another round (`npx agjan review extend <step>` after a yes).
33
35
  - Start a review only when all your edits are saved, and on its own: never in parallel
34
36
  with other tool calls. The reviewer must see the finished change.
37
+ - After every review, show the user what the reviewer found: the output of
38
+ `npx agjan review report` (the latest round), unchanged in your message.
35
39
  - Run `npx agjan check` before you report a step as done.
36
40
  - When you stop in the middle of a skill to wait for the user (an error you cannot
37
41
  resolve, a decision, an action only they can take, a limit reached), first run
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agjan",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Spec-driven workflow kit for AI coding agents, with human approval gates and a read-only reviewer at every step.",
5
5
  "keywords": [
6
6
  "ai",
@@ -0,0 +1,49 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { join } from 'node:path';
3
+ import { readJson } from './json-file.mjs';
4
+
5
+ /**
6
+ * UI tests are optional (design decision 75): they run in Playwright's Chromium where it
7
+ * can start, and are skipped with the reason where it cannot. On macOS and Windows,
8
+ * `npx playwright install chromium` is all it needs; on Linux, Chromium also needs system
9
+ * libraries, which only an administrator adds. agjan never installs them.
10
+ */
11
+
12
+ /** The npm script that runs a project's UI tests. */
13
+ export const UI_SCRIPT = 'test:ui';
14
+
15
+ // Exit code 3: the project has no Playwright.
16
+ const PROBE = `let pw;
17
+ try { pw = await import('@playwright/test'); } catch { process.exit(3); }
18
+ const browser = await pw.chromium.launch();
19
+ await browser.close();`;
20
+
21
+ /** Whether the project defines the UI test script. */
22
+ export function hasUiTests(root) {
23
+ return Boolean(readJson(join(root, 'package.json'))?.scripts?.[UI_SCRIPT]);
24
+ }
25
+
26
+ /**
27
+ * Starts and closes Chromium from the project. Returns { ready: true } or { ready: false,
28
+ * reason, enable }. AGJAN_BROWSER_PROBE names a Node script that replaces the probe (tests).
29
+ */
30
+ export function probeBrowser(root) {
31
+ const fake = process.env.AGJAN_BROWSER_PROBE;
32
+ const run = spawnSync(process.execPath, fake ? [fake] : ['--input-type=module', '-e', PROBE], { cwd: root, encoding: 'utf8', timeout: 120_000 });
33
+ if (run.status === 0) return { ready: true };
34
+ if (run.status === 3) return { ready: false, reason: '@playwright/test is not installed', enable: 'npm install' };
35
+ const output = `${run.stderr ?? ''}${run.stdout ?? ''}`;
36
+ if (/Executable doesn't exist|playwright install/i.test(output) && !/install-deps|missing dependencies/i.test(output)) {
37
+ return { ready: false, reason: 'Chromium is not downloaded', enable: 'npx playwright install chromium (no admin rights needed)' };
38
+ }
39
+ const library = /error while loading shared libraries: (\S+?):/.exec(output)?.[1];
40
+ if (library || /missing dependencies|install-deps/i.test(output)) {
41
+ return {
42
+ ready: false,
43
+ reason: `Chromium cannot start: this Linux system lacks its libraries${library ? ` (${library})` : ''}`,
44
+ enable: 'whoever maintains the machine or container image adds them once, for example with `npx playwright install-deps chromium` run as root in its Dockerfile',
45
+ };
46
+ }
47
+ const first = output.split('\n').map((l) => l.trim()).find((l) => l && !l.startsWith('at ')) ?? (run.error ? run.error.message : `exit code ${run.status}`);
48
+ return { ready: false, reason: `Chromium cannot start: ${first.replace(/^\w*Error: /, '')}`, enable: 'npx playwright install chromium, then npx agjan doctor' };
49
+ }
package/src/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createContext, pkg } from './context.mjs';
2
2
  import { AgjanError } from './errors.mjs';
3
- import { createStyle, mark } from './ui.mjs';
3
+ import { blink, createStyle, mark } from './ui.mjs';
4
4
  import * as newCommand from './commands/new.mjs';
5
5
  import * as gates from './commands/gates.mjs';
6
6
  import * as check from './commands/check.mjs';
@@ -15,6 +15,7 @@ import * as mapCommand from './commands/map.mjs';
15
15
  import * as branch from './commands/branch.mjs';
16
16
  import * as progress from './commands/progress.mjs';
17
17
  import * as lint from './commands/lint.mjs';
18
+ import * as uiTest from './commands/ui-test.mjs';
18
19
  import { onEvent } from './log.mjs';
19
20
  import { refreshAfterEvent } from './progress-view.mjs';
20
21
 
@@ -30,6 +31,7 @@ const COMMANDS = {
30
31
  status: status.run,
31
32
  check: check.run,
32
33
  lint: lint.run,
34
+ 'ui-test': uiTest.run,
33
35
  amend: gates.amend,
34
36
  approve: gates.approve,
35
37
  accept: gates.accept,
@@ -63,9 +65,10 @@ Setup (human):
63
65
  doctor check the environment and the project setup
64
66
 
65
67
  Agent and human:
66
- branch <name> | --list | --use <name>
68
+ branch <name> | --list | --use <name> | --edit <proposal>
67
69
  create the branch for a feature, fix or map run, list
68
- the existing ones, or switch to one (after asking the user)
70
+ the existing ones, or switch to one (after asking the user);
71
+ --edit: the human edits the proposed name in a terminal
69
72
  new <slug> --key <KEY> create a feature folder with approvals.json and spec.md
70
73
  scaffold design create design.md and tasks.md from the templates
71
74
  progress [--open] regenerate the progress pages and show the overview
@@ -76,6 +79,8 @@ Agent and human:
76
79
  enforce the workflow rules
77
80
  lint [--all] [--base <ref>] run the area linters (UI5 linter for fiori) on the changed
78
81
  files of each app, without MCP
82
+ ui-test [--require] run the UI tests (npm run test:ui, Playwright) where
83
+ Chromium can start; else say why and skip (--require: exit 1)
79
84
  amend --task <id> --paths <p,...> --reason "<why>"
80
85
  propose a scope amendment during Build
81
86
  fix start <slug> --key <KEY> --what "<text>" | fix check | fix record [--verify "…"]
@@ -83,6 +88,8 @@ Agent and human:
83
88
  map start start mapping an existing application (project.md)
84
89
  baseline refresh record the watched files in baseline.json
85
90
  review show [--step <step>] list review records, or print a step's review context
91
+ review report [--step <step>] the latest review round for the user: verdict, findings,
92
+ rounds, what happens next (agents show it after each review)
86
93
  review extend <step> one more round for a step still blocked at its round
87
94
  limit (after the user said yes)
88
95
  log --stage <stage> [--role r] [--task T1] [--skill s]
@@ -123,7 +130,10 @@ export async function main(args, options = {}) {
123
130
  }
124
131
  // On a terminal: the agjan mark instead of the first line, and bold section headings.
125
132
  const body = HELP.split('\n').slice(1).map((l) => (/^\S.*:$/.test(l) ? s.bold(l) : l));
126
- stdout.write(`${[...mark(s, pkg.version), ...body.slice(1)].join('\n')}`);
133
+ const logo = mark(s, pkg.version);
134
+ stdout.write(`${logo.join('\n')}\n`);
135
+ await blink({ isTTY: Boolean(stdout.isTTY), write: (text) => stdout.write(text) }, logo);
136
+ stdout.write(body.slice(1).join('\n'));
127
137
  return 0;
128
138
  }
129
139
  if (command === '--version' || command === '-v' || command === 'version') {
@@ -20,15 +20,58 @@ export function existingBranches(root, config) {
20
20
  }).filter((b) => b.name !== base);
21
21
  }
22
22
 
23
+ /** Creates the branch `name` from the current one and switches to it. */
24
+ function create(ctx, name) {
25
+ const s = ctx.style;
26
+ const problems = branchProblems(ctx.root, ctx.config, name);
27
+ if (problems.length) throw new AgjanError(`cannot create the branch:\n${problems.map((p) => ` - ${p}`).join('\n')}`);
28
+ const from = currentBranch(ctx.root);
29
+ git(ctx.root, ['switch', '-q', '-c', name]);
30
+ ctx.out(`${s.green('created branch')} ${s.bold(name)}${from ? s.gray(` (from ${from})`) : ''}`);
31
+ const base = resolveBase(ctx.root, ctx.config.git?.base);
32
+ if (from && base && from !== base.replace(/^origin\//, '')) ctx.out(s.yellow(`note: created from ${from}, not from the base branch ${base}`));
33
+ return 0;
34
+ }
35
+
36
+ /**
37
+ * --edit <proposal>: the human edits the proposed name in a terminal (it is typed in
38
+ * already), then the branch is created. A name git refuses is shown again for editing;
39
+ * an empty name cancels. Agents have no terminal: they ask the user to run it.
40
+ */
41
+ async function edit(ctx, proposal) {
42
+ const s = ctx.style;
43
+ let name = proposal;
44
+ for (;;) {
45
+ try {
46
+ name = String(await ctx.edit(`${s.bold('Branch name')} (Enter to create, empty to cancel): `, name)).trim();
47
+ } catch (error) {
48
+ if (error instanceof AgjanError) throw new AgjanError(`npx agjan branch --edit needs a human at a terminal; agents ask the user to run it (${error.message})`);
49
+ throw error;
50
+ }
51
+ if (!name) {
52
+ ctx.out(s.yellow('cancelled, no branch created'));
53
+ return 1;
54
+ }
55
+ const problems = branchProblems(ctx.root, ctx.config, name);
56
+ if (!problems.length) return create(ctx, name);
57
+ ctx.out(s.red(`${problems.join('; ')}; change the name`));
58
+ }
59
+ }
60
+
23
61
  /**
24
- * agjan branch <name> | --list | --use <name>: the branch for a feature, fix or map run.
25
- * The agent asks the user first (create the proposed name, use an existing branch, or
26
- * another name; design decision 62), then runs this: <name> creates the branch and
27
- * switches to it, --list shows the existing ones, --use switches to one of them.
62
+ * agjan branch <name> | --list | --use <name> | --edit <proposal>: the branch for a
63
+ * feature, fix or map run. The agent asks the user first (create the proposed name, use
64
+ * an existing branch, or another name; design decision 62), then runs this: <name>
65
+ * creates the branch and switches to it, --list shows the existing ones, --use switches
66
+ * to one of them. --edit is for the human in a terminal: the proposal, ready to edit.
28
67
  */
29
68
  export async function run(ctx, argv) {
30
- const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { list: { type: 'boolean' }, use: { type: 'string' } } });
69
+ const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { list: { type: 'boolean' }, use: { type: 'string' }, edit: { type: 'string' } } });
31
70
  const s = ctx.style;
71
+ if (values.edit !== undefined) {
72
+ if (positionals.length || values.use !== undefined || values.list) throw new UsageError('usage: agjan branch --edit <proposal>');
73
+ return edit(ctx, values.edit);
74
+ }
32
75
  if (values.list) {
33
76
  if (positionals.length || values.use) throw new UsageError('usage: agjan branch --list');
34
77
  const current = currentBranch(ctx.root);
@@ -47,14 +90,6 @@ export async function run(ctx, argv) {
47
90
  ctx.out(`${s.green('on branch')} ${s.bold(name)}`);
48
91
  return 0;
49
92
  }
50
- if (positionals.length !== 1) throw new UsageError('usage: agjan branch <name> | --list | --use <name>');
51
- const name = positionals[0];
52
- const problems = branchProblems(ctx.root, ctx.config, name);
53
- if (problems.length) throw new AgjanError(`cannot create the branch:\n${problems.map((p) => ` - ${p}`).join('\n')}`);
54
- const from = currentBranch(ctx.root);
55
- git(ctx.root, ['switch', '-q', '-c', name]);
56
- ctx.out(`${s.green('created branch')} ${s.bold(name)}${from ? s.gray(` (from ${from})`) : ''}`);
57
- const base = resolveBase(ctx.root, ctx.config.git?.base);
58
- if (from && base && from !== base.replace(/^origin\//, '')) ctx.out(s.yellow(`note: created from ${from}, not from the base branch ${base}`));
59
- return 0;
93
+ if (positionals.length !== 1) throw new UsageError('usage: agjan branch <name> | --list | --use <name> | --edit <proposal>');
94
+ return create(ctx, positionals[0]);
60
95
  }
@@ -109,10 +109,13 @@ function checkFeature(report, root, config, slug, level) {
109
109
  const scope = slug;
110
110
  const ci = level === 'ci';
111
111
 
112
- // Approved documents must not change silently (design 9.5), at every level.
113
- if (feature.state.spec === 'stale') report.error(scope, 'spec.md changed after its approval; re-approve it or revert the change');
112
+ // Approved documents must not change silently (design 9.5). The pre-commit hook only
113
+ // warns, so a revision can be committed before its new approval (decision 74); every
114
+ // other level, CI included, fails until the document is approved again.
115
+ const stale = (message) => (level === 'staged' ? report.warn(scope, `${message} (commit allowed; CI fails until it is approved again)`) : report.error(scope, message));
116
+ if (feature.state.spec === 'stale') stale('spec.md changed after its approval; re-approve it or revert the change');
114
117
  if (feature.state.design === 'stale') {
115
- report.error(scope, 'the design is stale (design.md, tasks.md or the spec changed after approval); re-approve it or revert');
118
+ stale('the design is stale (design.md, tasks.md or the spec changed after approval): review it and request approve design again (/agjan-design, revising an approved design), or revert');
116
119
  }
117
120
  if (level === 'staged') return feature;
118
121
 
@@ -225,11 +228,19 @@ function checkScope(report, features, config, files, level) {
225
228
  return;
226
229
  }
227
230
  const building = features.filter((f) => f.stage === 'build');
231
+ if (building.length === 0) {
232
+ // One error with its cause, not one per file: the files wait for a design approval.
233
+ if (!outside.length) return;
234
+ const shown = outside.slice(0, 5).join(', ') + (outside.length > 5 ? `, … (${outside.length - 5} more)` : '');
235
+ const revised = features.filter((f) => f.state.design === 'stale' || f.state.spec === 'stale').map((f) => f.slug);
236
+ report.error('scope', revised.length
237
+ ? `${outside.length} changed file(s) wait for the approval of the revised design of ${revised.join(', ')} (${shown}); once it is approved, they are checked against its tasks`
238
+ : `${outside.length} changed file(s), but no feature on this branch has an approved design (${shown})`);
239
+ return;
240
+ }
228
241
  const allowed = matcher(building.flatMap((f) => allowedPatterns(f, config)));
229
242
  for (const file of outside) {
230
- if (allowed(file)) continue;
231
- if (building.length === 0) report.error('scope', `${file} changed, but no feature on this branch has an approved design`);
232
- else report.error('scope', `${file} is outside the approved task paths; revert it or propose an amendment (agjan amend)`);
243
+ if (!allowed(file)) report.error('scope', `${file} is outside the approved task paths; revert it or propose an amendment (agjan amend)`);
233
244
  }
234
245
  }
235
246
 
@@ -6,7 +6,7 @@ import { appendLog, readLog } from '../log.mjs';
6
6
  import { APPROVALS_FILE, FEATURES_DIR, gateReview, loadFeature, selectFeature } from '../feature.mjs';
7
7
  import { documentProblems, designProblems } from '../validate.mjs';
8
8
  import { AgjanError, UsageError } from '../errors.mjs';
9
- import { mark, tone } from '../ui.mjs';
9
+ import { blink, mark, tone } from '../ui.mjs';
10
10
  import { git } from '../git.mjs';
11
11
 
12
12
  function short(hash) {
@@ -23,9 +23,12 @@ function save(ctx, feature, event, fields) {
23
23
  }
24
24
 
25
25
  /** Shows what is being approved and asks the human to type the feature key (design 9.4). */
26
- function confirmGate(ctx, feature, title, lines) {
26
+ async function confirmGate(ctx, feature, title, lines) {
27
+ const logo = mark(ctx.style, ctx.kit, 'a human decision, recorded with your name');
28
+ for (const line of logo) ctx.out(line);
29
+ await blink(ctx, logo);
27
30
  const summary = [
28
- ...(ctx.style.brand ? mark(ctx.style, ctx.kit, 'a human decision, recorded with your name') : ['']),
31
+ ...(logo.length ? [] : ['']),
29
32
  ctx.style.bold(`agjan: ${title}`),
30
33
  ` feature ${ctx.style.bold(feature.slug)} (${ctx.style.cyan(feature.key)})`,
31
34
  ...lines.map((l) => ` ${l}`),
@@ -135,7 +138,7 @@ async function approveSpec(ctx, feature, values) {
135
138
  const { problems, record } = gateReadiness(ctx, feature, 'spec');
136
139
  if (problems.length) refuse('approve the spec', problems);
137
140
  const previous = feature.state.spec === 'stale' ? ' (re-approval: changed since the last approval)' : '';
138
- if (!confirmGate(ctx, feature, `approve spec${previous}`, [`spec.md ${short(feature.spec.hash)}`, reviewLine(ctx, record)])) return 1;
141
+ if (!(await confirmGate(ctx, feature, `approve spec${previous}`, [`spec.md ${short(feature.spec.hash)}`, reviewLine(ctx, record)]))) return 1;
139
142
  feature.approvals.approvals.spec = { hash: feature.spec.hash, at_utc: ctx.now(), by: ctx.email() };
140
143
  // A new spec approval invalidates the design: its spec_hash no longer matches.
141
144
  save(ctx, feature, 'approved', { gate: 'spec' });
@@ -148,7 +151,7 @@ async function approveDesign(ctx, feature, values) {
148
151
  const { problems, record } = gateReadiness(ctx, feature, 'design');
149
152
  if (problems.length) refuse('approve the design', problems);
150
153
  const lines = [`design ${short(feature.designHash)} (design.md + tasks.md, mode ${feature.design.parsed.mode})`, reviewLine(ctx, record)];
151
- if (!confirmGate(ctx, feature, 'approve design', lines)) return 1;
154
+ if (!(await confirmGate(ctx, feature, 'approve design', lines))) return 1;
152
155
  feature.approvals.approvals.design = { hash: feature.designHash, spec_hash: feature.spec.hash, at_utc: ctx.now(), by: ctx.email() };
153
156
  save(ctx, feature, 'approved', { gate: 'design' });
154
157
  ctx.out(ctx.style.green(`approved design of ${feature.slug}`));
@@ -164,7 +167,7 @@ async function approveCombined(ctx, feature, values) {
164
167
  `design ${short(feature.designHash)} (design.md + tasks.md, mode light)`,
165
168
  reviewLine(ctx, record),
166
169
  ];
167
- if (!confirmGate(ctx, feature, 'approve spec and design (light mode)', lines)) return 1;
170
+ if (!(await confirmGate(ctx, feature, 'approve spec and design (light mode)', lines))) return 1;
168
171
  const at = ctx.now();
169
172
  const by = ctx.email();
170
173
  feature.approvals.approvals.spec = { hash: feature.spec.hash, at_utc: at, by };
@@ -183,7 +186,7 @@ async function approveAmendment(ctx, feature, id, values) {
183
186
  throw new AgjanError(`${id} is already approved`);
184
187
  }
185
188
  const lines = [`amendment ${id} for ${amendment.task}`, `paths ${amendment.paths.join(', ')}`, `reason ${amendment.reason}`];
186
- if (!confirmGate(ctx, feature, 'approve scope amendment', lines)) return 1;
189
+ if (!(await confirmGate(ctx, feature, 'approve scope amendment', lines))) return 1;
187
190
  Object.assign(amendment, { approved_at_utc: ctx.now(), by: ctx.email(), design_hash: feature.approvals.approvals.design.hash });
188
191
  save(ctx, feature, 'approved', { gate: 'amendment', amendment: id });
189
192
  ctx.out(ctx.style.green(`approved ${id}`));
@@ -215,7 +218,7 @@ export async function accept(ctx, argv) {
215
218
  if (!finding) throw new AgjanError(`no finding ${id} in ${feature.slug}`);
216
219
  if (finding.status !== 'open') throw new AgjanError(`${id} is already ${finding.status}`);
217
220
  const lines = [`finding ${id} [${finding.severity}] ${finding.file ?? ''}`.trimEnd(), `issue ${finding.issue}`, `reason ${values.reason}`];
218
- if (!confirmGate(ctx, feature, 'accept finding', lines)) return 1;
221
+ if (!(await confirmGate(ctx, feature, 'accept finding', lines))) return 1;
219
222
  feature.approvals.accepted.push({ finding: id, reason: values.reason, at_utc: ctx.now(), by: ctx.email() });
220
223
  save(ctx, feature, 'accepted', { finding: id, severity: finding.severity });
221
224
  ctx.out(ctx.style.green(`accepted ${id}`));
@@ -231,7 +234,7 @@ export async function reject(ctx, argv) {
231
234
  throw new UsageError('usage: agjan reject spec|design --reason "<why>" [--feature <slug>] [--no-commit]');
232
235
  }
233
236
  const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
234
- if (!confirmGate(ctx, feature, `reject ${gate}`, [`reason ${values.reason}`])) return 1;
237
+ if (!(await confirmGate(ctx, feature, `reject ${gate}`, [`reason ${values.reason}`]))) return 1;
235
238
  feature.approvals.rejections.push({ gate, reason: values.reason, at_utc: ctx.now(), by: ctx.email() });
236
239
  save(ctx, feature, 'rejected', { gate });
237
240
  ctx.out(`recorded rejection of ${gate} for ${feature.slug}; the document stays draft`);
@@ -3,8 +3,8 @@ import { serve } from '../mcp.mjs';
3
3
  import { buildContextText, parseStep } from '../review.mjs';
4
4
  import { loadFeature, selectFeature } from '../feature.mjs';
5
5
  import { appendLog } from '../log.mjs';
6
- import { roundState } from '../review-policy.mjs';
7
- import { tone } from '../ui.mjs';
6
+ import { reviewerFor, roundState } from '../review-policy.mjs';
7
+ import { highlightMarkdown, tone } from '../ui.mjs';
8
8
  import { AgjanError, UsageError } from '../errors.mjs';
9
9
 
10
10
  /** agjan mcp [--host <name>] [--isolation agent|fork|none]: the agjan MCP server on stdio. */
@@ -19,9 +19,74 @@ export function mcp(ctx, argv) {
19
19
  return serve(ctx, { host: values.host ?? 'unknown', isolation });
20
20
  }
21
21
 
22
- /** agjan review show | extend: dispatches to the subcommand. */
22
+ /** agjan review show | report | extend: dispatches to the subcommand. */
23
23
  export function run(ctx, argv) {
24
- return argv[0] === 'extend' ? extend(ctx, argv.slice(1)) : show(ctx, argv);
24
+ if (argv[0] === 'extend') return extend(ctx, argv.slice(1));
25
+ if (argv[0] === 'report') return report(ctx, argv.slice(1));
26
+ return show(ctx, argv);
27
+ }
28
+
29
+ const VERDICT = { pass: '✅ pass', 'pass-with-notes': '✅ pass with notes', blocked: '⛔ blocked' };
30
+ const MARK = { pass: '✅', 'pass-with-notes': '✅', blocked: '⛔' };
31
+ const SEVERITY = { blocker: '🔴', major: '🟠', minor: '🟡' };
32
+
33
+ /** One line of an issue, at most `max` characters. */
34
+ function oneLine(text, max = 140) {
35
+ const line = String(text ?? '').replace(/\s+/g, ' ').trim();
36
+ return line.length > max ? `${line.slice(0, max - 1)}…` : line;
37
+ }
38
+
39
+ /** What the writer does after this review (design 7.4), in the user's words. */
40
+ function nextAfter(feature, config, record) {
41
+ const state = roundState(feature, config, record.step);
42
+ const status = new Map(feature.findings.map((f) => [f.id, f.status]));
43
+ const open = (severity) => record.findings.filter((f) => f.severity === severity && status.get(f.id) === 'open').length;
44
+ if (record.verdict === 'blocked') {
45
+ if (state.exhausted) return `round limit reached (${state.round} of ${state.limit}): the agent asks you whether to run another round`;
46
+ return `the agent fixes ${open('blocker')} blocker(s), then review round ${state.next} of ${state.limit}`;
47
+ }
48
+ const majors = open('major');
49
+ if (majors) return `the agent fixes the ${majors} major finding(s) it agrees with (another round), or goes on; minor notes stay open for the PR`;
50
+ return record.verdict === 'pass' ? 'the agent goes on with the next step' : 'minor notes stay open (the PR summary lists them); the agent goes on';
51
+ }
52
+
53
+ /**
54
+ * agjan review report [--step <step>] [--feature <slug>]: the latest review round as a
55
+ * short Markdown report for the user (verdict, findings by severity, the rounds of this
56
+ * loop, what happens next). Agents put it into their message after every review, so the
57
+ * user sees what the reviewer found; the markers are emoji, which every host shows.
58
+ */
59
+ export function report(ctx, argv) {
60
+ const { values, positionals } = parseArgs({ args: argv, options: { step: { type: 'string' }, feature: { type: 'string' } }, allowPositionals: true });
61
+ if (positionals.length) throw new UsageError('usage: agjan review report [--step <step>] [--feature <slug>]');
62
+ const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
63
+ const records = feature.reviews.records.filter((r) => !values.step || r.step === values.step);
64
+ const record = records.at(-1);
65
+ if (!record) throw new AgjanError(`no review recorded for ${feature.slug}${values.step ? ` (step ${values.step})` : ''}`);
66
+ const { limit } = roundState(feature, ctx.config, record.step);
67
+ const status = new Map(feature.findings.map((f) => [f.id, f.status]));
68
+ const out = [`**🔍 Review ${record.id} · ${record.step} · round ${record.round} of ${limit} · ${VERDICT[record.verdict]}**`];
69
+ const isolation = record.reviewer?.isolation === 'agent' ? 'isolated' : `isolation ${record.reviewer?.isolation ?? 'unknown'}`;
70
+ out.push(`- reviewer: ${reviewerFor(ctx.config, record.step)} on ${record.reviewer?.host ?? 'unknown host'}, ${isolation}`);
71
+ const order = { blocker: 0, major: 1, minor: 2 };
72
+ for (const f of [...record.findings].sort((a, b) => order[a.severity] - order[b.severity])) {
73
+ const where = f.file ? ` · \`${f.file}${f.line ? `:${f.line}` : ''}\`` : '';
74
+ const state = status.get(f.id) === 'open' ? '' : ` (${status.get(f.id)})`;
75
+ out.push(`- ${SEVERITY[f.severity]} **${f.id}** ${f.severity}${state}${where} · ${oneLine(f.issue)}`);
76
+ }
77
+ if (!record.findings.length) out.push('- no findings');
78
+ if (record.resolves?.length) out.push(`- ✅ resolved: ${record.resolves.join(', ')}`);
79
+ const mine = new Set(record.findings.map((f) => f.id));
80
+ const earlier = feature.findings.filter((f) => f.step === record.step && f.status === 'open' && !mine.has(f.id));
81
+ if (earlier.length) out.push(`- still open from earlier rounds: ${earlier.map((f) => `${SEVERITY[f.severity]} ${f.id}`).join(', ')}`);
82
+ // The rounds of this correction loop, oldest first: shows the cycles between the agents.
83
+ const step = feature.reviews.records.filter((r) => r.step === record.step && r.at_utc <= record.at_utc);
84
+ const start = step.findLastIndex((r) => r.round === 1);
85
+ const loop = step.slice(Math.max(start, 0));
86
+ if (loop.length > 1) out.push(`- rounds: ${loop.map((r) => `${r.id} ${MARK[r.verdict]}`).join(' → ')}`);
87
+ out.push(`- ➜ next: ${nextAfter(feature, ctx.config, record)}`);
88
+ ctx.out(highlightMarkdown(ctx.style, out.join('\n')));
89
+ return 0;
25
90
  }
26
91
 
27
92
  /**
@@ -17,6 +17,7 @@ import { AgjanError, UsageError } from '../errors.mjs';
17
17
  import { blink, mark, pad, tone, verdictColor } from '../ui.mjs';
18
18
  import { mcpServers } from '../mcp-config.mjs';
19
19
  import { addCommand, addCopilotServers, copilotServers } from '../copilot-mcp.mjs';
20
+ import { UI_SCRIPT, hasUiTests, probeBrowser } from '../browser.mjs';
20
21
 
21
22
  const CI_FILE = '.github/workflows/agjan.yml';
22
23
  const CI_TEMPLATE = new URL('../../kit/templates/agjan-ci.yml', import.meta.url);
@@ -286,8 +287,10 @@ function claudeTrust(root) {
286
287
  }
287
288
 
288
289
  /** agjan doctor: checks the environment and the project setup; exit 1 on any failure. */
289
- export function doctor(ctx) {
290
- for (const line of mark(ctx.style, ctx.kit, 'doctor: environment and project setup')) ctx.out(line);
290
+ export async function doctor(ctx) {
291
+ const lines = mark(ctx.style, ctx.kit, 'doctor: environment and project setup');
292
+ for (const line of lines) ctx.out(line);
293
+ await blink(ctx, lines);
291
294
  const rows = [];
292
295
  const ok = (what, detail = '') => rows.push(['ok', what, detail]);
293
296
  const warn = (what, detail) => rows.push(['warn', what, detail]);
@@ -361,6 +364,13 @@ export function doctor(ctx) {
361
364
  if (trust === 'trusted') ok('claude code trust', 'project folder trusted');
362
365
  else warn('claude code trust', `${trust}; open the folder in Claude Code once and trust it, or the reviewer has no agjan tools`);
363
366
  }
367
+ if (hasUiTests(root)) {
368
+ const browser = probeBrowser(root);
369
+ if (browser.ready) ok('ui tests', `Chromium starts; npx agjan ui-test runs npm run ${UI_SCRIPT}`);
370
+ else warn('ui tests', `skipped (optional): ${browser.reason}; enable: ${browser.enable}`);
371
+ } else if (config.areas.fiori) {
372
+ ok('ui tests', `none (optional: Playwright, a ${UI_SCRIPT} script; see the fiori-developer skill)`);
373
+ }
364
374
  const allow = config.agent?.allow ?? [];
365
375
  ok('agent allow list', allow.length ? `${allow.length} command(s) without a prompt: ${allow.join(', ')}` : 'none (the hosts ask for every command)');
366
376
  ok('reviewer models', config.hosts.map((h) => `${h}: ${MODEL_TIERS.map((t) => `${t} ${agentModel(config, h, t) ?? 'session model'}`).join(', ')}`).join('; '));