agjan 0.0.10 → 0.0.12

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 (119) hide show
  1. package/README.md +2 -2
  2. package/bin/agjan.mjs +9 -2
  3. package/dist/adapters/claude-code.js +105 -0
  4. package/dist/adapters/copilot.js +80 -0
  5. package/dist/auto.js +24 -0
  6. package/dist/baseline.js +66 -0
  7. package/dist/browser.js +46 -0
  8. package/dist/cli.js +164 -0
  9. package/dist/commands/branch.js +71 -0
  10. package/dist/commands/check.js +420 -0
  11. package/dist/commands/fix.js +122 -0
  12. package/dist/commands/gates.js +462 -0
  13. package/dist/commands/lint.js +76 -0
  14. package/dist/commands/log.js +72 -0
  15. package/dist/commands/map.js +47 -0
  16. package/dist/commands/new.js +65 -0
  17. package/dist/commands/pr-summary.js +168 -0
  18. package/dist/commands/progress.js +42 -0
  19. package/dist/commands/report.js +105 -0
  20. package/dist/commands/review.js +146 -0
  21. package/dist/commands/setup.js +393 -0
  22. package/dist/commands/status.js +303 -0
  23. package/dist/commands/ui-test.js +39 -0
  24. package/dist/config.js +110 -0
  25. package/dist/context.js +56 -0
  26. package/dist/copilot-mcp.js +56 -0
  27. package/dist/documents.js +207 -0
  28. package/dist/errors.js +15 -0
  29. package/dist/feature.js +221 -0
  30. package/dist/fix.js +117 -0
  31. package/dist/git.js +88 -0
  32. package/{src/hash.mjs → dist/hash.js} +11 -14
  33. package/dist/hook.js +47 -0
  34. package/dist/json-file.js +26 -0
  35. package/dist/log.js +50 -0
  36. package/dist/managed.js +182 -0
  37. package/dist/mcp-config.js +76 -0
  38. package/dist/mcp.js +142 -0
  39. package/dist/plan.js +40 -0
  40. package/dist/progress-view.js +494 -0
  41. package/dist/progress.js +106 -0
  42. package/{src/review-policy.mjs → dist/review-policy.js} +39 -47
  43. package/dist/review.js +435 -0
  44. package/dist/scope.js +30 -0
  45. package/dist/terminal.js +127 -0
  46. package/dist/test-results.js +101 -0
  47. package/dist/tests-map.js +29 -0
  48. package/dist/types.js +5 -0
  49. package/dist/ui.js +136 -0
  50. package/dist/usage.js +116 -0
  51. package/dist/validate.js +46 -0
  52. package/docs/guide.md +98 -37
  53. package/kit/domains/btp/domain.json +4 -4
  54. package/kit/hooks/guard.mjs +48 -119
  55. package/kit/skills/agjan-build/SKILL.md +14 -8
  56. package/kit/skills/agjan-design/SKILL.md +42 -6
  57. package/kit/skills/agjan-fix/SKILL.md +9 -10
  58. package/kit/skills/agjan-map/SKILL.md +9 -10
  59. package/kit/skills/agjan-spec/SKILL.md +22 -11
  60. package/kit/skills/agjan-verify/SKILL.md +46 -19
  61. package/kit/skills/cap-developer/SKILL.md +10 -2
  62. package/kit/skills/cap-developer/references/handlers.md +11 -9
  63. package/kit/skills/cap-developer/references/project-setup.md +21 -8
  64. package/kit/skills/cap-developer/references/testing.md +38 -14
  65. package/kit/skills/cap-developer/references/typescript.md +143 -0
  66. package/kit/skills/cap-developer/references/validation-security.md +26 -8
  67. package/kit/skills/fiori-developer/SKILL.md +20 -5
  68. package/kit/skills/fiori-developer/references/app-setup.md +91 -16
  69. package/kit/skills/fiori-developer/references/elements.md +19 -5
  70. package/kit/skills/fiori-developer/references/freestyle-ts.md +5 -1
  71. package/kit/skills/fiori-developer/references/testing.md +109 -15
  72. package/kit/templates/agents-block.md +7 -3
  73. package/package.json +11 -3
  74. package/schemas/approvals.schema.json +23 -2
  75. package/schemas/config.schema.json +0 -5
  76. package/schemas/log.schema.json +1 -1
  77. package/src/adapters/claude-code.mjs +0 -121
  78. package/src/adapters/copilot.mjs +0 -89
  79. package/src/baseline.mjs +0 -66
  80. package/src/cli.mjs +0 -155
  81. package/src/commands/branch.mjs +0 -60
  82. package/src/commands/check.mjs +0 -365
  83. package/src/commands/fix.mjs +0 -116
  84. package/src/commands/gates.mjs +0 -264
  85. package/src/commands/lint.mjs +0 -74
  86. package/src/commands/log.mjs +0 -60
  87. package/src/commands/map.mjs +0 -47
  88. package/src/commands/new.mjs +0 -53
  89. package/src/commands/pr-summary.mjs +0 -137
  90. package/src/commands/progress.mjs +0 -40
  91. package/src/commands/report.mjs +0 -115
  92. package/src/commands/review.mjs +0 -76
  93. package/src/commands/setup.mjs +0 -383
  94. package/src/commands/status.mjs +0 -248
  95. package/src/config.mjs +0 -122
  96. package/src/context.mjs +0 -67
  97. package/src/copilot-mcp.mjs +0 -56
  98. package/src/documents.mjs +0 -188
  99. package/src/errors.mjs +0 -16
  100. package/src/feature.mjs +0 -225
  101. package/src/fix.mjs +0 -108
  102. package/src/git.mjs +0 -83
  103. package/src/hook.mjs +0 -48
  104. package/src/json-file.mjs +0 -24
  105. package/src/log.mjs +0 -51
  106. package/src/managed.mjs +0 -178
  107. package/src/mcp-config.mjs +0 -83
  108. package/src/mcp.mjs +0 -147
  109. package/src/plan.mjs +0 -45
  110. package/src/progress-view.mjs +0 -466
  111. package/src/progress.mjs +0 -85
  112. package/src/review.mjs +0 -413
  113. package/src/scope.mjs +0 -30
  114. package/src/terminal.mjs +0 -118
  115. package/src/test-results.mjs +0 -111
  116. package/src/tests-map.mjs +0 -29
  117. package/src/ui.mjs +0 -136
  118. package/src/usage.mjs +0 -118
  119. package/src/validate.mjs +0 -41
package/docs/guide.md CHANGED
@@ -62,9 +62,9 @@ Then:
62
62
 
63
63
  ## The workflow
64
64
 
65
- Each feature on a branch of its own. When one is needed, the agent asks you: create the
66
- name it proposes, use a branch that already exists (it lists them), or provide a new
67
- name (it confirms the name before creating the branch).
65
+ Each feature on a branch of its own. When one is needed, the agent asks you in the chat:
66
+ create a new branch or use one that already exists (it lists them). For a new branch it
67
+ proposes a name; choose it, or type another one, and the agent creates the branch.
68
68
 
69
69
  **Spec**: in Claude Code or Copilot:
70
70
 
@@ -79,9 +79,14 @@ your terminal:
79
79
  ```sh
80
80
  npx agjan status # what is ready and what blocks it
81
81
  npx agjan review show # the reviews and findings
82
+ npx agjan review report # the latest round, short: verdict, findings, what happens next
82
83
  npx agjan approve spec design # light mode; full mode: approve spec, later approve design
83
84
  ```
84
85
 
86
+ After every review the agent shows you that short report in its message: the verdict, the
87
+ findings by severity (🔴 blocker, 🟠 major, 🟡 minor), what the round resolved, the rounds
88
+ of the loop so far (`LVR-R1 ⛔ → LVR-R2 ✅`) and what the agent does next.
89
+
85
90
  `approve` shows a summary and asks you to type the feature key. It refuses when the
86
91
  latest review did not see the current files or has open blockers. After recording the
87
92
  approval it offers to commit the feature folder, with the message the agent proposed
@@ -95,19 +100,91 @@ pre-commit hook still runs. `accept` and `reject` do the same. To send a gate ba
95
100
  `design.md` and `tasks.md`; the deep reviewer checks them; you approve with
96
101
  `npx agjan approve design`.
97
102
 
103
+ New CAP services, tests and Fiori apps are written in **TypeScript** unless you or the
104
+ spec ask for JavaScript, or the application being changed is already JavaScript (then it
105
+ stays JavaScript; converting it is a design decision you make, not the agent).
106
+
98
107
  **Build**: `/agjan-build`. One commit per task, subject `ORDF-T1: …`; tests named with
99
108
  the AC ids; reviews when `agjan status` lists them as due. A file outside the approved
100
109
  task paths fails `agjan check`; the agent then proposes an amendment, which you approve
101
110
  with `npx agjan approve amendment ORDF-A1`.
102
111
 
112
+ If the approved design turns out wrong (an AC cannot be met as designed), the agent stops
113
+ and asks you. With your yes it revises `design.md` and `tasks.md` (done tasks stay done,
114
+ new tasks are added), the deep reviewer checks the revision, and you approve the design
115
+ again; then Build continues. Until then `agjan check` reports one error, that the changed
116
+ files wait for the revised design, and the pre-commit hook lets only the documents be
117
+ committed.
118
+
103
119
  **Verify**: `/agjan-verify`. Full build, tests and lint, the baseline update, the final
104
- deep review, `agjan check --ci`, `report.md`, and the PR description
105
- (`npx agjan pr-summary`). The agent opens a PR only when you ask; you review and merge.
120
+ deep review, `agjan check --ci` and `report.md`. It ends with a completion block that
121
+ gives you the last gate:
122
+
123
+ **Accept (Gate 3)**: try the result, check the manual ACs by hand, then accept it in your
124
+ terminal:
125
+
126
+ ```sh
127
+ npx agjan approve verify
128
+ ```
129
+
130
+ It lists the manual ACs for you to confirm and records your acceptance (with your name,
131
+ the time and the verified state of the change) in `approvals.json`, then commits it. Now
132
+ agjan knows the feature is done, even if the pull request is created somewhere else; CI
133
+ (`check --ci`) passes only after it. A change after the acceptance needs a new verify
134
+ review and a new acceptance. The pull request is optional: the agent opens it when you
135
+ ask (its description is `npx agjan pr-summary`); you review and merge.
136
+
137
+ **UI tests (optional)**: for what a user does on a page of a Fiori app (create a record,
138
+ choose an action), the agents also write Playwright tests (`test/ui/`, the script
139
+ `test:ui`), and `npx agjan ui-test` runs them in Chromium as each test user. Where Chromium
140
+ cannot start, it says why and skips them, and the agent tells you which ACs to try by
141
+ hand. agjan never installs anything with admin rights:
142
+
143
+ - macOS and Windows: `npx playwright install chromium` is all it needs.
144
+ - Linux, dev containers: Chromium also needs system libraries. Whoever maintains the
145
+ machine or the container image adds them once, for example
146
+ `RUN npx playwright install-deps chromium` in the Dockerfile (as root), or uses
147
+ Playwright's image `mcr.microsoft.com/playwright`. `npx agjan doctor` (row `ui tests`)
148
+ says what is missing.
149
+ - CI: on GitHub-hosted runners, add a job with `npx playwright install --with-deps
150
+ chromium` and `npx agjan ui-test --require`.
106
151
 
107
152
  At any time, `npx agjan status` says where a feature stands and what comes next. When a
108
153
  feature is verified, it ends with a completion block ("✔ ORDF is verified …") that lists
109
154
  what was met, what is open, and what you do next.
110
155
 
156
+ ### Auto mode
157
+
158
+ To let the agent go through a feature without stopping at every gate, switch auto mode
159
+ on in your terminal: for one feature, any time after `/agjan-spec` has created it, or as
160
+ your default for every new feature:
161
+
162
+ ```sh
163
+ npx agjan auto on # this feature; asks you to type its key
164
+ npx agjan auto off # this feature's gates wait for you again
165
+ npx agjan auto on --default # every feature you create in this checkout from now on
166
+ npx agjan auto off --default # new features wait at their gates again
167
+ ```
168
+
169
+ The default is yours only: it lives in `.agjan/auto.json`, which is git-ignored, so
170
+ teammates' checkouts keep their gates. A feature takes it when it is created (its
171
+ `approvals.json` records `from: default`); existing features keep their mode, and
172
+ `auto off` still switches one feature off. `npx agjan doctor` and `status` show it.
173
+
174
+ While it is on, the spec and design gates (and the combined gate of a light change) are
175
+ approved automatically once their reviews pass, and the agent goes on to the next step
176
+ in the same turn: design, build, verify. The reviewer still checks every step; a blocked
177
+ review still stops the gate. You stay in charge of:
178
+
179
+ - the final acceptance, `npx agjan approve verify`: the agent stops there in every mode;
180
+ - blockers at the round limit, scope amendments, accepting findings, business questions;
181
+ - the pull request and its merge.
182
+
183
+ Every automatic approval is recorded as `by: auto` with your name as the one who switched
184
+ auto mode on, never as your approval; `status`, the progress pages and the PR summary
185
+ show it. Auto mode belongs to one feature: the next one starts with the gates on. Agents
186
+ cannot switch it on: like `approve`, it needs your terminal, and the guard denies it.
187
+
111
188
  ### Following the progress
112
189
 
113
190
  agjan keeps a progress page for every unit and regenerates it after every event it
@@ -153,16 +230,19 @@ Run `npx agjan --help` for the full list.
153
230
  | Command | Who | Purpose |
154
231
  |---|---|---|
155
232
  | `init`, `sync [--force]` | you | set up; regenerate managed files after an upgrade |
156
- | `doctor` | anyone | check Node, git, versions, managed files, hook, CI, the MCP server, guards, folder trust (Claude Code, Copilot CLI) |
233
+ | `doctor` | anyone | check Node, git, versions, managed files, hook, CI, the MCP server, guards, folder trust (Claude Code, Copilot CLI), whether the UI tests can run |
157
234
  | `status [--feature <id> \| --all]` | anyone | state, blockers, tasks, due reviews, next step |
158
235
  | `progress [--open]` | anyone | regenerate the progress pages, print the overview, open the HTML page |
159
236
  | `branch <name>` · `--list` · `--use <name>` | agent, after asking you | create the branch of a unit, list the existing branches, or switch to one |
160
237
  | `check [--staged \| --ci] [--base <ref>]` | anyone, hook, CI | enforce the rules |
238
+ | `lint [--all]` | anyone | the area linters (UI5 linter for Fiori apps) on the changed files |
239
+ | `ui-test [--require]` | anyone | the Playwright UI tests where Chromium can start; otherwise the reason, and a skip |
161
240
  | `review show [--step <step>]` | anyone | review records, or the material a reviewer gets |
241
+ | `review report [--step <step>]` | anyone | the latest review round as a short report (agents show it after each review) |
162
242
  | `pr-summary`, `report` | anyone | PR description; `report.md` with time and tokens |
163
243
  | `new`, `scaffold design`, `amend`, `log` | agent | used by the workflow skills |
164
244
  | `fix start \| check \| record`, `map start`, `baseline refresh` | agent | fast path and baseline |
165
- | `approve`, `accept`, `reject` | **you, in a terminal** | gates; never run by an agent |
245
+ | `approve spec \| design \| spec design \| verify \| amendment <id>`, `accept`, `reject`, `auto on \| off` | **you, in a terminal** | gates (`approve verify`: the final acceptance; `auto`: auto mode for one feature); never run by an agent |
166
246
  | `mcp` | the host | the reviewer's tools; started from the agent configuration |
167
247
 
168
248
  `--feature` takes a feature slug, `fixes/<id>` or `maps/<id>`; it is needed only when
@@ -227,36 +307,16 @@ line; the skills take these values, and the reviewer agent per step, from `statu
227
307
  On every host, `approve` needs a human at a real terminal: the confirmation is read
228
308
  from the terminal, not from input an agent can pipe in.
229
309
 
230
- ### Fewer permission prompts
231
-
232
- The hosts ask before every shell command and, in Copilot, before every file change. Two
233
- settings remove the routine prompts without giving up control:
234
-
235
- - **Commands: `agent.allow`** in `agjan.config.json`. `init` asks once whether to add the
236
- recommended list (`--agent-allow` / `--no-agent-allow` decide without asking):
237
-
238
- ```json
239
- "agent": { "allow": ["npx agjan", "npm test", "git status", "git diff", "git log", "git add", "git commit"] }
240
- ```
241
-
242
- agjan's guard hook approves a command, or a chain (`&&`, `||`, `;`, `|`), without a
243
- prompt when **every part** starts with a listed entry, is a read-only command (`ls`,
244
- `cat`, `head`, `tail`, `grep`, `wc`, `sort`, `uniq`, `pwd`, `echo`, `sed -n`) or a `cd`
245
- inside the project, and at least one part is listed. So
246
- `git add … && git commit -m "…" && npx agjan log … 2>&1 | tail -5` runs, but
247
- `npm test && git push`, `$(…)`, backticks, background jobs and redirects into files still
248
- ask (only `2>&1`, `2>/dev/null` and `>/dev/null` are accepted). `agjan approve`,
249
- `accept` and `reject` are always denied, listed or not. Works in Claude Code and the
250
- Copilot CLI (both run the hook). Edit the list like any configuration: a change is a
251
- policy change that `check` reports and the PR shows.
252
- - **File changes: `agent.allow_edits`** (`init` asks; `--agent-allow-edits`). With `true`,
253
- the guard approves the hosts' file edit tools for files inside the project without a
254
- prompt. Policy files (`agjan.config.json`, `.github/hooks/`, `.github/agents/`,
255
- `.github/workflows/`, `.claude/settings.json`, the MCP configuration) still ask. agjan's
256
- scope check, the pre-commit hook and the reviewer cover what the agent changes.
257
- - **agjan's records are never edited by hand:** the guard always denies the edit tools on
258
- `approvals.json`, `reviews.json`, `review.md`, `log.jsonl`, `progress.md`, the fix
259
- records and `baseline.json`; agjan writes them.
310
+ ### Permission prompts
311
+
312
+ The hosts ask before shell commands and, in Copilot, before file changes, as you have
313
+ configured them; agjan does not change that. Its guard hook only denies:
314
+
315
+ - `agjan approve`, `accept`, `reject` and `auto`, in any form;
316
+ - branch creation with git (agents use `npx agjan branch` after asking you);
317
+ - **edits of agjan's records:** the edit tools on `approvals.json`, `reviews.json`,
318
+ `review.md`, `log.jsonl`, `progress.md`, the fix records and `baseline.json`; agjan
319
+ writes them.
260
320
 
261
321
  **Script edits are denied.** Agents sometimes edit files with small scripts
262
322
  (`python3 - <<EOF … open(p, 'w')`, `sed -i`, `cat > file <<EOF`) instead of their edit
@@ -346,5 +406,6 @@ Commit the result in a pull request of its own: CI reports it as a policy change
346
406
  | `approve` refuses: the review did not see the current files | Something changed after the last review; let the agent ask for the review again. |
347
407
  | `check` says a file is outside the approved task paths | Revert it, or let the agent propose `agjan amend` and approve the amendment. |
348
408
  | `check --ci` says the final verify review is stale | Files changed after it; run `/agjan-verify` again. |
409
+ | `ui-test` skips: Chromium cannot start, the system lacks its libraries | Linux only. The UI tests stay optional; to run them, add the libraries once to the machine or image (see "UI tests" above). Do not let an agent install them. |
349
410
  | Warnings about managed files | `npx agjan sync`; `--force` replaces files you edited. |
350
411
  | `agjan check --staged` blocks a commit | The pre-commit hook found a rule violation in the staged change; read its message. |
@@ -5,15 +5,15 @@
5
5
  "cap": {
6
6
  "role": "cap-developer",
7
7
  "tests": ["test/**"],
8
- "implicit": ["package.json", "package-lock.json", "test/fixtures/**", "_i18n/**"],
8
+ "implicit": ["package.json", "package-lock.json", "tsconfig.json", "tsconfig.cdsbuild.json", "test/fixtures/**", "_i18n/**"],
9
9
  "verify": { "test": "npm test" }
10
10
  },
11
11
  "fiori": {
12
12
  "role": "fiori-developer",
13
- "tests": ["app/*/webapp/test/**", "app/*/test/**"],
14
- "implicit": ["app/*/package.json", "app/*/package-lock.json", "app/*/webapp/i18n/**"],
13
+ "tests": ["app/*/webapp/test/**", "app/*/test/**", "test/ui/**"],
14
+ "implicit": ["app/*/package.json", "app/*/package-lock.json", "app/*/tsconfig.json", "app/*/webapp/i18n/**", "playwright.config.ts"],
15
15
  "verify": {},
16
- "lint": { "command": "npx --yes @ui5/linter", "in": "app/*", "files": "webapp/**" }
16
+ "lint": { "command": "npx --yes @ui5/linter", "in": "app/*", "files": "webapp/**/*.{js,ts,xml,json,html}" }
17
17
  },
18
18
  "btp": {
19
19
  "role": "btp-architect",
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ // @ts-check
2
3
  /**
3
4
  * agjan guard: a pre-tool-use hook that denies shell commands running the human-only
4
- * agjan commands (approve, accept, reject), however they are wrapped (`npx`, `sh -c`,
5
+ * agjan commands (approve, accept, reject, auto), however they are wrapped (`npx`, `sh -c`,
5
6
  * `cd … &&`, `node …/agjan.mjs`). It is a guardrail in front of the terminal
6
7
  * confirmation, not a proof (design 9.4).
7
8
  *
@@ -9,18 +10,12 @@
9
10
  * sed -i, cat > file, …) so that agents use their file edit tool, unless the project sets
10
11
  * `agent.script_edits` to "allow" (design decision 63).
11
12
  *
12
- * It also approves, without a prompt, shell commands the project lists in `agent.allow`
13
- * of agjan.config.json (opt-in, design decisions 61 and 68): a command, or a chain of
14
- * commands (`&&`, `||`, `;`, `|`), in which every part starts with a listed command or is a
15
- * built-in read-only command (ls, cat, head, …) or a `cd` inside the project. Only the
16
- * redirects 2>&1, 2>/dev/null and >/dev/null are accepted; `$(…)`, backticks, other
17
- * redirects and unknown commands are left to the host's own prompt.
18
- *
19
13
  * File edit tools (Copilot `edit`/`create`, Claude Code `Edit`/`Write`/`MultiEdit`): hand
20
14
  * edits of agjan's records (approvals.json, reviews.json, review.md, log.jsonl, …) are always
21
- * denied. With `agent.allow_edits: true` other files inside the project are approved,
22
- * except the policy files (configuration, hooks, agents, workflows), which stay with the
23
- * host's prompt. Denying always comes first.
15
+ * denied.
16
+ *
17
+ * The guard only denies. Everything else is left to the host, which asks the user as it
18
+ * is configured to (design decision 76).
24
19
  *
25
20
  * Reads the host's payload on stdin and answers in the host's format:
26
21
  * - GitHub Copilot: { toolName, toolArgs: { command | path } } -> { permissionDecision, permissionDecisionReason }
@@ -34,14 +29,20 @@ import { readFileSync, realpathSync } from 'node:fs';
34
29
  import { isAbsolute, join, relative, resolve } from 'node:path';
35
30
  import { fileURLToPath } from 'node:url';
36
31
 
32
+ /**
33
+ * A host's tool call as the hook receives it: Copilot's or Claude Code's form.
34
+ * @typedef {{ toolName?: string, toolArgs?: Record<string, any>, tool_name?: string, tool_input?: Record<string, any> }} Payload
35
+ * @typedef {{ agent?: { script_edits?: string } }} GuardConfig
36
+ */
37
+
37
38
  const REASON =
38
- 'agjan approve, accept and reject are for the human, in a terminal. Do not run them in any form; ask the user to run the command.';
39
+ 'agjan approve, accept, reject and auto are for the human, in a terminal. Do not run them in any form; ask the user to run the command.';
39
40
 
40
41
  /** `agjan` (or `agjan.mjs`) followed directly by a human-only command; an optional `--` (npm exec) between. */
41
- const HUMAN_ONLY = /\bagjan(?:\.mjs)?["']?\s+(?:--\s+)?["']?(approve|accept|reject)\b/;
42
+ const HUMAN_ONLY = /\bagjan(?:\.mjs)?["']?\s+(?:--\s+)?["']?(approve|accept|reject|auto)\b/;
42
43
 
43
44
  const BRANCH_REASON =
44
- 'Create branches with npx agjan branch, not with git. Ask the user first: create the proposed name, use an existing branch (npx agjan branch --list, then npx agjan branch --use <name>), or another name.';
45
+ 'Create branches with npx agjan branch, not with git. Ask the user first: create a new branch (your proposed name or one they type) or use an existing branch (npx agjan branch --list, then npx agjan branch --use <name>).';
45
46
 
46
47
  /**
47
48
  * Commands that create or rename a branch: git switch -c/-C, git checkout -b/-B/--orphan,
@@ -65,6 +66,7 @@ const EDIT_REASON =
65
66
  * that open files for writing, in-place stream edits, and cat/echo/printf/tee into a file.
66
67
  * Reading (cat file, sed -n, grep, running a project script) is not matched.
67
68
  */
69
+ /** @type {((command: string) => boolean)[]} */
68
70
  const SCRIPT_EDITS = [
69
71
  // python3 - <<EOF … / python -c "…" that writes a file (the script is inside quotes or a heredoc)
70
72
  (c) => /\bpython[0-9.]*\b/.test(c) && /(<<|\s-c\s)/.test(c) && /open\([^,)]*,\s*(?:mode\s*=\s*)?['"][wax]b?\+?['"]|\.write_(text|bytes)\(/.test(c),
@@ -79,125 +81,48 @@ const SCRIPT_EDITS = [
79
81
  (c) => /\btee\s+(?:-a\s+)?(?!\/dev\/)[\w./~]/.test(unquoted(c)),
80
82
  ];
81
83
 
82
- /** The command with every quoted string replaced by Q, so quoted text is not read as syntax. */
83
- function unquoted(command) {
84
- return command.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, 'Q');
85
- }
86
-
87
- /** Read-only commands a chain may contain besides the allow list (design decision 68). */
88
- const READ_ONLY = new Set(['ls', 'cat', 'head', 'tail', 'grep', 'wc', 'sort', 'uniq', 'pwd', 'echo', 'true', 'date']);
89
- const SAFE_REDIRECT = /(?:^|\s)(?:2>&1|[12&]?>\s*\/dev\/null)(?=\s|$)/g;
90
-
91
84
  /**
92
- * Splits a command line into its simple commands at &&, ||, ; and | outside quotes.
93
- * Null when it contains what the guard never approves: $(…), backticks, parentheses,
94
- * braces, input redirects or heredocs, background jobs, or a redirect into a file.
85
+ * The command with every quoted string replaced by Q, so quoted text is not read as syntax.
86
+ * @param {string} command
95
87
  */
96
- export function splitChain(command) {
97
- const parts = [];
98
- let current = '';
99
- let quote = null;
100
- for (let i = 0; i < command.length; i++) {
101
- const c = command[i];
102
- if (quote) {
103
- // Inside double quotes the shell still runs $(…) and backticks.
104
- if (quote === '"' && (c === '`' || (c === '$' && command[i + 1] === '('))) return null;
105
- if (c === '\\' && quote === '"') {
106
- current += c + (command[i + 1] ?? '');
107
- i++;
108
- continue;
109
- }
110
- if (c === quote) quote = null;
111
- current += c;
112
- continue;
113
- }
114
- if (c === "'" || c === '"') {
115
- quote = c;
116
- current += c;
117
- continue;
118
- }
119
- if ('`(){}<'.includes(c) || (c === '$' && command[i + 1] === '(')) return null;
120
- const two = command.slice(i, i + 2);
121
- if (two === '&&' || two === '||') {
122
- parts.push(current);
123
- current = '';
124
- i++;
125
- continue;
126
- }
127
- if (c === ';' || c === '|' || c === '\n') {
128
- parts.push(current);
129
- current = '';
130
- continue;
131
- }
132
- if (c === '&' && command[i - 1] !== '>' && command[i + 1] !== '>') return null; // background job
133
- current += c;
134
- }
135
- if (quote) return null;
136
- parts.push(current);
137
- const cleaned = [];
138
- for (const part of parts) {
139
- const text = part.replace(SAFE_REDIRECT, ' ').trim();
140
- if (!text) continue;
141
- if (/>/.test(unquoted(text))) return null; // a redirect into a file
142
- cleaned.push(text.replace(/\s+/g, ' '));
143
- }
144
- return cleaned.length ? cleaned : null;
145
- }
146
-
147
- function listed(part, allow) {
148
- return allow.some((entry) => {
149
- if (typeof entry !== 'string' || entry.trim() === '') return false;
150
- const prefix = entry.trim().replace(/\s+/g, ' ');
151
- return part === prefix || part.startsWith(`${prefix} `);
152
- });
153
- }
154
-
155
- function readOnly(part, root) {
156
- const [word, ...rest] = part.split(' ');
157
- if (word === 'cd') {
158
- const target = rest.join(' ').replace(/^["']|["']$/g, '');
159
- if (!target || rest.length > 1) return false;
160
- const where = isAbsolute(target) ? relative(root, target) : target;
161
- return !where.split(/[\\/]/).includes('..') && !isAbsolute(where);
162
- }
163
- if (word === 'sed') return /(?:^|\s)-n\b/.test(part) && !/(?:^|\s)-[a-zA-Z]*i\b|--in-place/.test(part);
164
- return READ_ONLY.has(word);
165
- }
166
-
167
- /** Whether `command` (one command or a chain) is approved by the allow list (decision 68). */
168
- export function allowed(command, allow, root = process.cwd()) {
169
- if (!Array.isArray(allow) || allow.length === 0) return false;
170
- const parts = splitChain(command);
171
- if (!parts) return false;
172
- // At least one part must be on the list: a chain of read-only commands alone is left to the host.
173
- return parts.every((part) => listed(part, allow) || readOnly(part, root)) && parts.some((part) => listed(part, allow));
88
+ function unquoted(command) {
89
+ return command.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, 'Q');
174
90
  }
175
91
 
176
92
  const RECORD_REASON =
177
93
  'agjan writes this file itself (approvals, reviews, logs, progress, fix records, baseline). Never edit it by hand; use the agjan commands.';
178
94
 
179
95
  /** agjan's records inside docs/agjan/: never edited by an agent's edit tool. */
180
- const RECORD = /^docs\/agjan\/(?:.+\/)?(?:approvals\.json|reviews\.json|review\.md|log\.jsonl|progress\.md|report\.md|fix\.json|fix\.md)$|^docs\/agjan\/baseline\.json$/;
96
+ const RECORD = /^docs\/agjan\/(?:.+\/)?(?:approvals\.json|reviews\.json|review\.md|log\.jsonl|progress\.md|report\.md|fix\.json|fix\.md)$|^docs\/agjan\/baseline\.json$|^\.agjan\/auto\.json$/;
181
97
 
182
- /** Files that define the rules: edits stay with the host's own prompt even with allow_edits. */
183
- const POLICY = /^(?:agjan\.config\.json|agjan\.lock\.json|\.mcp\.json|\.vscode\/mcp\.json|\.claude\/settings(?:\.local)?\.json|\.claude\/agents\/.*|\.github\/(?:hooks|agents|workflows)\/.*|\.github\/CODEOWNERS)$/;
98
+ const AUTO_REASON =
99
+ 'The auto mode default (.agjan/auto.json) is the user\'s, set with npx agjan auto on --default in their terminal. Do not read, write, copy or remove it.';
100
+
101
+ /** Any shell command that names the auto mode default: agents have no business with it. */
102
+ const AUTO_FILE = /\.agjan[\\/]+auto\.json/;
184
103
 
185
104
  const EDIT_TOOLS = new Set(['edit', 'create', 'Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
186
105
 
187
- /** The guard's answer for a file edit tool call, or null. */
188
- function decideEdit(payload, config, root) {
106
+ /**
107
+ * The guard's answer for a file edit tool call, or null.
108
+ * @param {Payload} payload
109
+ * @param {string} root
110
+ */
111
+ function decideEdit(payload, root) {
189
112
  const args = payload.toolArgs ?? payload.tool_input ?? {};
190
113
  const target = args.path ?? args.file_path ?? args.notebook_path;
191
114
  if (typeof target !== 'string' || target === '') return null;
192
115
  const rel = relative(root, resolve(root, target)).split('\\').join('/');
193
116
  const inside = rel !== '' && !rel.startsWith('../') && rel !== '..' && !isAbsolute(rel);
194
117
  if (inside && RECORD.test(rel)) return answer(payload, 'deny', RECORD_REASON);
195
- if (config?.agent?.allow_edits === true && inside && !POLICY.test(rel)) {
196
- return answer(payload, 'allow', 'agent.allow_edits in agjan.config.json');
197
- }
198
118
  return null;
199
119
  }
200
120
 
121
+ /**
122
+ * @param {Payload} payload
123
+ * @param {'deny'} decision
124
+ * @param {string} reason
125
+ */
201
126
  function answer(payload, decision, reason) {
202
127
  if (payload.tool_input !== undefined) {
203
128
  return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: decision, permissionDecisionReason: reason } };
@@ -206,23 +131,27 @@ function answer(payload, decision, reason) {
206
131
  }
207
132
 
208
133
  /**
209
- * The guard's answer for a payload: deny, allow (listed in `config.agent.allow`), or null
210
- * (the host decides). `config` is the project's agjan.config.json.
134
+ * The guard's answer for a payload: deny, or null (the host decides). `config` is the
135
+ * project's agjan.config.json.
136
+ * @param {Payload} payload
137
+ * @param {GuardConfig} [config]
138
+ * @param {string} [root]
211
139
  */
212
140
  export function decide(payload, config = {}, root = process.env.CLAUDE_PROJECT_DIR || process.cwd()) {
213
- if (EDIT_TOOLS.has(payload?.toolName ?? payload?.tool_name)) return decideEdit(payload, config, root);
141
+ if (EDIT_TOOLS.has(payload?.toolName ?? payload?.tool_name ?? '')) return decideEdit(payload, root);
214
142
  const command = payload?.toolArgs?.command ?? payload?.tool_input?.command;
215
143
  if (typeof command !== 'string') return null;
216
144
  if (HUMAN_ONLY.test(command)) return answer(payload, 'deny', REASON);
217
145
  if (BRANCH_CREATE.test(command)) return answer(payload, 'deny', BRANCH_REASON);
146
+ if (AUTO_FILE.test(command)) return answer(payload, 'deny', AUTO_REASON);
218
147
  if (config?.agent?.script_edits !== 'allow' && SCRIPT_EDITS.some((matches) => matches(command))) return answer(payload, 'deny', EDIT_REASON);
219
- const allow = config?.agent?.allow ?? [];
220
- const shell = /^(bash|powershell|shell)$/i.test(payload.toolName ?? payload.tool_name ?? '');
221
- if (shell && allowed(command, allow, root)) return answer(payload, 'allow', 'listed in agent.allow of agjan.config.json');
222
148
  return null;
223
149
  }
224
150
 
225
- /** The project's agjan.config.json; empty when it cannot be read. */
151
+ /**
152
+ * The project's agjan.config.json; empty when it cannot be read.
153
+ * @returns {GuardConfig}
154
+ */
226
155
  function projectConfig() {
227
156
  try {
228
157
  const root = process.env.CLAUDE_PROJECT_DIR || process.cwd();
@@ -28,13 +28,15 @@ Repeat until `npx agjan status` says `next: all tasks done and reviewed`:
28
28
  - Write tests for the task's ACs. Each test name contains the AC id, for example
29
29
  `it('ORDF-AC2: an approved order cannot be edited', ...)`. Manual ACs need no test.
30
30
  - Run the task's `verify` command (default: the area's commands in
31
- `agjan.config.json`, else `npm test`) and `npx agjan check`. Fix failures, up to the number of attempts that `npx agjan status` shows (`build.fix_attempts`, default 3); then stop and report to the user.
31
+ `agjan.config.json`, else `npm test`), for a `fiori` task also `npx agjan ui-test`
32
+ (the Playwright UI tests; it skips them where no browser can start: say so, never
33
+ install system libraries), and `npx agjan check`. Fix failures, up to the number of attempts that `npx agjan status` shows (`build.fix_attempts`, default 3); then stop and report to the user.
32
34
  - Commit the task with the subject `<KEY>-<id>: <title>`, for example
33
35
  `ORDF-T1: Add the status filter`. Include the feature's `docs/agjan/` files if they
34
36
  changed.
35
37
  3. **A due review** (`due review build:<area>` or `build:<task>`): when all your edits are saved, delegate, on its own (not in parallel with other tool calls), to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent and a short `name`, for example `spec review`):
36
38
  `Review step build:<area or task> of feature <slug>.` The work must be committed
37
- first. Read the result with `npx agjan review show`; fix
39
+ first. Read the result with `npx agjan review show` (and show the user the round: put the output of `npx agjan review report` into your message unchanged); fix
38
40
  blockers in a new commit with the same task subject prefix, then ask for the review
39
41
  again, up to the round limit that `npx agjan status` shows (default 3).
40
42
  If blockers remain at the limit, ask the user with your host's question tool, naming the open blockers, with the choices `Run another round` and `Stop here`. On `Run another round`, run `npx agjan review extend <step>` and continue; on `Stop here`, stop and tell the user. (`<step>` is the step under review, for example `build:fiori`.)
@@ -46,17 +48,21 @@ Do not change it silently; `agjan check` fails on it.
46
48
  - If the change is small and necessary: revert it, then propose an amendment:
47
49
  `npx agjan amend --task <id> --paths <path,...> --reason "<why>"`, and ask the user
48
50
  to approve it in a terminal: `npx agjan approve amendment <KEY>-A<n>`. Wait.
49
- - If the design itself is wrong (a new task, a different decision): stop and tell the
50
- user; the design must be changed and approved again.
51
+ - If the design itself is wrong (an AC cannot be met as designed, a new task, a
52
+ different decision): stop and tell the user what is wrong. With their yes, revise it
53
+ as `/agjan-design` describes ("Revising an approved design"): the design is reviewed
54
+ and approved again, then you continue with the open tasks. Done tasks stay done.
51
55
 
52
56
  ## 4. Done
53
57
 
54
58
  When `npx agjan status` says all tasks are done and reviewed, tell the user to run
55
- `/agjan-verify`.
59
+ `/agjan-verify`. In auto mode (`npx agjan status` shows `auto on`), continue in the same
60
+ turn with the `agjan-verify` skill (`.claude/skills/agjan-verify/SKILL.md`) instead. Its
61
+ final acceptance, `npx agjan approve verify`, stays with the user in every mode.
56
62
 
57
63
  ## Never
58
64
 
59
- - Run `agjan approve`, `agjan accept` or `agjan reject` yourself, in any form.
60
- - Edit `spec.md`, `design.md` or `tasks.md` to make the build fit; that is a design
61
- change for the human.
65
+ - Run `agjan approve`, `agjan accept`, `agjan reject` or `agjan auto` yourself, in any form.
66
+ - Edit `spec.md`, `design.md` or `tasks.md` to make the build fit; a design change goes
67
+ through the revision in `/agjan-design`, with the user's yes and a new approval.
62
68
  - Skip or weaken a test to make a check pass.
@@ -35,6 +35,13 @@ Every decision states what, why, and the alternative considered. For every new F
35
35
  application, record `app_type: elements` or `app_type: freestyle` with reason and
36
36
  alternative. Existing applications keep their type (read it from `manifest.json`).
37
37
 
38
+ Before you go on, check the decisions against the ACs, one by one: can the chosen UI do
39
+ what each AC describes with this service shape (create, edit, delete, each action and
40
+ its input)? In a Fiori elements app, creating or editing records needs a draft-enabled
41
+ entity; "no draft" is only for read-only apps or apps that change data through actions
42
+ (fiori-developer). An AC the design cannot meet in the UI is a design error, not a
43
+ build problem.
44
+
38
45
  Then fill `## Answers to open technical questions` (one answer per question in the
39
46
  spec) and `## Risks and trade-offs`.
40
47
 
@@ -51,16 +58,22 @@ tasks:
51
58
  area: cap
52
59
  covers: [<KEY>-AC1, <KEY>-AC2]
53
60
  title: Add the status filter to the orders service
54
- paths: [srv/orders-service.cds, srv/orders-service.js, test/orders.test.js]
61
+ paths: [srv/orders-service.cds, srv/orders-service.ts, test/orders.test.ts]
55
62
  verify: npm test
56
63
  ```
57
64
 
58
65
  - Order: backend (`cap`) first, then UI (`fiori`) against the finished service, then
59
66
  deployment (`btp`).
60
- - Every AC is covered by at least one task.
67
+ - Every AC is covered by at least one task. A task covers an AC only if its `paths`
68
+ include every file needed to implement and test it (for a handler rule: the service
69
+ `.cds`, the handler file and the test file).
61
70
  - `paths` are the exact files, or a folder ending in `/`, that the task changes,
62
71
  including **the tests of the ACs it covers**. Tests of UI annotations usually live in
63
- the CAP tests (`test/`): a `fiori` task that adds annotations lists that test file too. Keep them tight; broad globs like `srv/**` defeat the scope
72
+ the CAP tests (`test/`): a `fiori` task that adds annotations lists that test file too.
73
+ An AC that a user does on a page (create a record, choose an action) also gets a UI
74
+ test, `test/ui/<app>.spec.ts` (Playwright, fiori-developer `references/testing.md`);
75
+ the first such task also lists `.gitignore` (`playwright.config.ts` is allowed
76
+ implicitly). Keep them tight; broad globs like `srv/**` defeat the scope
64
77
  check. Do not list `package.json`, lockfiles, i18n files or test fixtures: they are
65
78
  allowed implicitly.
66
79
  - `verify` is optional; it defaults to the area's commands in `agjan.config.json`.
@@ -72,7 +85,7 @@ Run `npx agjan check` and fix every error.
72
85
  When all your edits are saved, delegate, on its own (not in parallel with other tool calls), to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer-deep`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent and a short `name`, for example `spec review`):
73
86
  `Review step design of feature <slug>.`
74
87
 
75
- Read the result with `npx agjan review show`. With minor notes only, leave them open and go on to the gate (a change would need another round). Fix blockers (and majors where you agree) and re-review, up to the round limit that `npx agjan status` shows (default 3). If blockers remain at the limit, ask the user with your host's question tool, naming the open blockers, with the choices `Run another round` and `Stop here`. On `Run another round`, run `npx agjan review extend design` and continue; on `Stop here`, stop and tell the user. Never edit review files or review
88
+ Read the result with `npx agjan review show` (and show the user the round: put the output of `npx agjan review report` into your message unchanged). With minor notes only, leave them open and go on to the gate (a change would need another round). Fix blockers (and majors where you agree) and re-review, up to the round limit that `npx agjan status` shows (default 3). If blockers remain at the limit, ask the user with your host's question tool, naming the open blockers, with the choices `Run another round` and `Stop here`. On `Run another round`, run `npx agjan review extend design` and continue; on `Stop here`, stop and tell the user. Never edit review files or review
76
89
  yourself. Any change after a review needs a new review; make no edits after the last
77
90
  passing one.
78
91
 
@@ -82,15 +95,38 @@ passing one.
82
95
  2. `npx agjan log --gate-requested design --message "<KEY>: approve design – <one line on
83
96
  the design>"` (the commit message `approve` offers the human). If it refuses, fix
84
97
  what it lists, review again, and retry.
85
- 3. Tell the user what to review, the open findings, and the command for their
98
+ 3. **Auto mode** (`npx agjan status` shows `auto on`): step 2 has approved the design
99
+ automatically. Commit the feature folder with the message it gives, show the user the
100
+ last review report and one line that the gate passed in auto mode, and continue in the
101
+ same turn with the `agjan-build` skill (`.claude/skills/agjan-build/SKILL.md`).
102
+ 4. Otherwise tell the user what to review, the open findings, and the command for their
86
103
  terminal: `npx agjan approve design` (it also commits the approval); then
87
104
  `/agjan-build`. Stop.
88
105
 
89
106
  If the spec must change, say so: changing it needs a new spec approval, and the design
90
107
  is approved again after that.
91
108
 
109
+ ## Revising an approved design
110
+
111
+ When the approved design turns out wrong during Build or Verify (an AC cannot be met as
112
+ designed), the design is revised here, never quietly in Build:
113
+
114
+ 1. Stop building and tell the user what is wrong and what you would change. Revise only
115
+ after their yes.
116
+ 2. `npx agjan log --stage design --skill agjan-design`. Edit `design.md` (the decision,
117
+ its reason, the alternative, and why the first decision failed) and `tasks.md`. Tasks
118
+ that are done (committed) keep their id, title and paths; add new tasks (`T<n+1>`)
119
+ for the change, or extend the paths of an open task. Approved amendments lapse with
120
+ the new design: put their paths into the tasks.
121
+ 3. From the first edit on, the design is stale. `npx agjan check` then reports that the
122
+ design waits for its gate, and the pre-commit hook lets you commit the revised
123
+ documents (it warns, CI does not pass) but not code. Do not touch code until the
124
+ design is approved again.
125
+ 4. Review (step `design`, section 5) and Gate 2 (section 6) as before. After
126
+ `npx agjan approve design`, continue with `/agjan-build`: it picks up the open tasks.
127
+
92
128
  ## Never
93
129
 
94
- - Run `agjan approve`, `agjan accept` or `agjan reject` yourself, in any form.
130
+ - Run `agjan approve`, `agjan accept`, `agjan reject` or `agjan auto` yourself, in any form.
95
131
  - Write code in this stage.
96
132
  - Decide beyond the spec. Anything the spec does not ask for is out of scope.