agjan 0.0.6 → 0.0.8
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.
- package/README.md +3 -2
- package/docs/guide.md +81 -29
- package/kit/hooks/guard.mjs +129 -19
- package/kit/skills/agjan-fix/SKILL.md +11 -3
- package/kit/skills/agjan-map/SKILL.md +12 -3
- package/kit/skills/agjan-spec/SKILL.md +12 -5
- package/kit/skills/agjan-verify/SKILL.md +9 -6
- package/kit/skills/cap-developer/SKILL.md +4 -0
- package/kit/skills/cap-developer/references/handlers.md +61 -4
- package/kit/skills/cap-developer/references/modeling.md +33 -1
- package/kit/skills/cap-developer/references/project-setup.md +87 -0
- package/kit/skills/cap-developer/references/services.md +32 -1
- package/kit/skills/cap-developer/references/testing.md +46 -14
- package/kit/skills/cap-developer/references/validation-security.md +66 -2
- package/kit/skills/fiori-developer/SKILL.md +1 -0
- package/kit/skills/fiori-developer/references/app-setup.md +127 -0
- package/kit/skills/fiori-developer/references/elements.md +109 -11
- package/kit/skills/fiori-developer/references/ui5-basics.md +3 -2
- package/kit/templates/agents-block.md +3 -2
- package/kit/templates/progress.html +14 -9
- package/kit/templates/project.md +5 -0
- package/package.json +1 -1
- package/schemas/config.schema.json +1 -15
- package/src/adapters/claude-code.mjs +16 -12
- package/src/cli.mjs +3 -2
- package/src/commands/branch.mjs +34 -24
- package/src/commands/check.mjs +1 -17
- package/src/commands/setup.mjs +73 -35
- package/src/commands/status.mjs +38 -13
- package/src/context.mjs +6 -0
- package/src/plan.mjs +8 -4
- package/src/progress-view.mjs +32 -11
- package/src/review.mjs +1 -1
- package/src/terminal.mjs +7 -3
- package/src/ui.mjs +22 -0
package/README.md
CHANGED
|
@@ -86,8 +86,9 @@ Approval commands are meant for humans in a terminal. agjan makes it hard for an
|
|
|
86
86
|
to run them (instructions, deny rules and hooks, and a confirmation read from the
|
|
87
87
|
terminal), but a model with unrestricted shell access could in principle get around
|
|
88
88
|
that. The trust boundary is the reviewed merge of the pull request; branch protection
|
|
89
|
-
with the required `agjan-check` status and CODEOWNERS are the recommended hardening
|
|
90
|
-
See section 9.4
|
|
89
|
+
with the required `agjan-check` status and CODEOWNERS are the recommended hardening
|
|
90
|
+
([guide](docs/guide.md#protecting-the-main-branch-on-github-optional)). See section 9.4
|
|
91
|
+
of the design.
|
|
91
92
|
|
|
92
93
|
## Contributing
|
|
93
94
|
|
package/docs/guide.md
CHANGED
|
@@ -10,7 +10,7 @@ in the [design](design.md); this guide is about using it.
|
|
|
10
10
|
- [Commands](#commands)
|
|
11
11
|
- [Configuration](#configuration)
|
|
12
12
|
- [Hosts](#hosts)
|
|
13
|
-
- [
|
|
13
|
+
- [Protecting the main branch on GitHub](#protecting-the-main-branch-on-github-optional)
|
|
14
14
|
- [Upgrading](#upgrading)
|
|
15
15
|
- [Troubleshooting](#troubleshooting)
|
|
16
16
|
|
|
@@ -49,13 +49,15 @@ Then:
|
|
|
49
49
|
1. Open the project in Claude Code once and **trust the folder**: the reviewer's tools
|
|
50
50
|
load only in a trusted folder. Allow the project MCP servers when asked (`cap`, `ui5`,
|
|
51
51
|
`fiori`: documentation tools for the role skills).
|
|
52
|
-
2.
|
|
53
|
-
[
|
|
52
|
+
2. Later, when a team shares the repository on GitHub, consider
|
|
53
|
+
[protecting the main branch](#protecting-the-main-branch-on-github-optional)
|
|
54
|
+
(optional).
|
|
54
55
|
3. For an existing application, run `/agjan-map` once (see below).
|
|
55
56
|
|
|
56
57
|
## The workflow
|
|
57
58
|
|
|
58
|
-
Each feature on a branch of its own.
|
|
59
|
+
Each feature on a branch of its own. When one is needed, the agent asks you: create the
|
|
60
|
+
name it proposes, use a branch that already exists (it lists them), or give another name.
|
|
59
61
|
|
|
60
62
|
**Spec**: in Claude Code or Copilot:
|
|
61
63
|
|
|
@@ -114,7 +116,11 @@ records (step, review, approval, amendment, fix record):
|
|
|
114
116
|
Both are local (`.agjan/` is not committed).
|
|
115
117
|
|
|
116
118
|
`npx agjan progress` regenerates the pages and prints the overview; `--open` opens the
|
|
117
|
-
HTML page in your browser.
|
|
119
|
+
HTML page in your browser. A unit shows **your turn** when it waits for you: a gate to
|
|
120
|
+
approve, an amendment, or the next skill to start (`/agjan-design`, `/agjan-build`,
|
|
121
|
+
`/agjan-verify`; a skill counts as running once it logged its start). A verified feature
|
|
122
|
+
is **done**: trying it locally, manual checks and the pull request are optional next
|
|
123
|
+
steps. `npx agjan status --done` prints just that block. Units already on the base branch appear in the overview but
|
|
118
124
|
get no new page on another branch.
|
|
119
125
|
|
|
120
126
|
## Small changes and existing applications
|
|
@@ -142,7 +148,7 @@ Run `npx agjan --help` for the full list.
|
|
|
142
148
|
| `doctor` | anyone | check Node, git, versions, managed files, hook, CI, the MCP server, guards, trust |
|
|
143
149
|
| `status [--feature <id> \| --all]` | anyone | state, blockers, tasks, due reviews, next step |
|
|
144
150
|
| `progress [--open]` | anyone | regenerate the progress pages, print the overview, open the HTML page |
|
|
145
|
-
| `branch <name>` | agent,
|
|
151
|
+
| `branch <name>` · `--list` · `--use <name>` | agent, after asking you | create the branch of a unit, list the existing branches, or switch to one |
|
|
146
152
|
| `check [--staged \| --ci] [--base <ref>]` | anyone, hook, CI | enforce the rules |
|
|
147
153
|
| `review show [--step <step>]` | anyone | review records, or the material a reviewer gets |
|
|
148
154
|
| `pr-summary`, `report` | anyone | PR description; `report.md` with time and tokens |
|
|
@@ -183,8 +189,6 @@ lists replace. The schema is `node_modules/agjan/schemas/config.schema.json`.
|
|
|
183
189
|
| `domains` | enabled domains; phase 1 has `btp` (areas `cap`, `fiori`, `btp`) |
|
|
184
190
|
| `hosts` | `claude-code`, `copilot`; decides which files `sync` generates |
|
|
185
191
|
| `git.base` | the branch features merge into; default: the remote's default branch |
|
|
186
|
-
| `git.branch.create` | who creates the branch of a feature, fix or map run: `agent` (default; the agent runs `npx agjan branch <name>`) or `confirm` (the agent proposes a name; a human runs `npx agjan branch <name>` in a terminal, may edit the name, and the guard hook blocks `git switch -c` and similar for agents) |
|
|
187
|
-
| `git.branch.pattern` | a regular expression for branch names, for teams with naming rules: `agjan branch` refuses other names, `check` warns about them (an error with `--ci`) |
|
|
188
192
|
| `verify.<area>` | `build`, `test`, `lint` commands for the skills; `results`: a JUnit XML, Jest or Mocha JSON file that `check` reads to require a passing test per AC |
|
|
189
193
|
| `tests.<area>`, `scope.implicit.<area>` | test file globs; files every task of the area may change (i18n, lockfiles, fixtures) |
|
|
190
194
|
| `risk_paths` | paths whose change needs a review per task and are never a fix |
|
|
@@ -226,15 +230,24 @@ settings remove the routine prompts without giving up control:
|
|
|
226
230
|
"agent": { "allow": ["npx agjan", "npm test", "git status", "git diff", "git log", "git add", "git commit"] }
|
|
227
231
|
```
|
|
228
232
|
|
|
229
|
-
agjan's guard hook approves a command
|
|
230
|
-
|
|
231
|
-
`
|
|
233
|
+
agjan's guard hook approves a command, or a chain (`&&`, `||`, `;`, `|`), without a
|
|
234
|
+
prompt when **every part** starts with a listed entry, is a read-only command (`ls`,
|
|
235
|
+
`cat`, `head`, `tail`, `grep`, `wc`, `sort`, `uniq`, `pwd`, `echo`, `sed -n`) or a `cd`
|
|
236
|
+
inside the project, and at least one part is listed. So
|
|
237
|
+
`git add … && git commit -m "…" && npx agjan log … 2>&1 | tail -5` runs, but
|
|
238
|
+
`npm test && git push`, `$(…)`, backticks, background jobs and redirects into files still
|
|
239
|
+
ask (only `2>&1`, `2>/dev/null` and `>/dev/null` are accepted). `agjan approve`,
|
|
232
240
|
`accept` and `reject` are always denied, listed or not. Works in Claude Code and the
|
|
233
241
|
Copilot CLI (both run the hook). Edit the list like any configuration: a change is a
|
|
234
242
|
policy change that `check` reports and the PR shows.
|
|
235
|
-
- **File changes (
|
|
236
|
-
|
|
237
|
-
|
|
243
|
+
- **File changes: `agent.allow_edits`** (`init` asks; `--agent-allow-edits`). With `true`,
|
|
244
|
+
the guard approves the hosts' file edit tools for files inside the project without a
|
|
245
|
+
prompt. Policy files (`agjan.config.json`, `.github/hooks/`, `.github/agents/`,
|
|
246
|
+
`.github/workflows/`, `.claude/settings.json`, the MCP configuration) still ask. agjan's
|
|
247
|
+
scope check, the pre-commit hook and the reviewer cover what the agent changes.
|
|
248
|
+
- **agjan's records are never edited by hand:** the guard always denies the edit tools on
|
|
249
|
+
`approvals.json`, `reviews.json`, `review.md`, `log.jsonl`, `progress.md`, the fix
|
|
250
|
+
records and `baseline.json`; agjan writes them.
|
|
238
251
|
|
|
239
252
|
**Script edits are denied.** Agents sometimes edit files with small scripts
|
|
240
253
|
(`python3 - <<EOF … open(p, 'w')`, `sed -i`, `cat > file <<EOF`) instead of their edit
|
|
@@ -246,24 +259,63 @@ Set `agent.script_edits` to `"allow"` in `agjan.config.json` to turn this off.
|
|
|
246
259
|
Copilot keeps your own "don't ask again" answers per folder in
|
|
247
260
|
`~/.copilot/permissions-config.json`; that file is personal and not part of the project.
|
|
248
261
|
|
|
249
|
-
##
|
|
262
|
+
## Protecting the main branch on GitHub (optional)
|
|
263
|
+
|
|
264
|
+
Not needed to work with agjan; recommended once a team shares the repository on GitHub.
|
|
265
|
+
|
|
266
|
+
**Why.** On your machine, agjan's checks (the pre-commit hook, the guard, `agjan check`)
|
|
267
|
+
make it hard for an agent to skip a step, but a model with full shell access could get
|
|
268
|
+
around them in principle. What reaches `main` is decided when a pull request is merged,
|
|
269
|
+
so that is where the last check belongs.
|
|
270
|
+
|
|
271
|
+
**What agjan already adds.** `init` creates `.github/workflows/agjan.yml`, a GitHub
|
|
272
|
+
Actions workflow. On every pull request, GitHub runs `agjan check --ci` and shows the
|
|
273
|
+
result as a check named **agjan-check** on the pull request: green, or red with the
|
|
274
|
+
reason (a document changed after its approval, code outside the approved paths, a stale
|
|
275
|
+
final review). It uses the agjan version pinned on `main`, so a pull request cannot
|
|
276
|
+
bring its own, weaker checker.
|
|
277
|
+
|
|
278
|
+
**What you turn on.** By default, GitHub lets you merge even when a check is red. A
|
|
279
|
+
*branch rule* makes the check, and a review, required:
|
|
280
|
+
|
|
281
|
+
1. Push the repository to GitHub and open one pull request, so that the check has run
|
|
282
|
+
once and GitHub knows its name.
|
|
283
|
+
2. In the repository: **Settings → Rules → Rulesets → New ruleset → New branch ruleset**.
|
|
284
|
+
Name it, set **Enforcement status** to *Active*, and under **Target branches** add the
|
|
285
|
+
default branch.
|
|
286
|
+
3. Turn on **Require a pull request before merging**, with 1 required approval.
|
|
287
|
+
4. Turn on **Require status checks to pass**, choose **Add checks** and select
|
|
288
|
+
`agjan-check`.
|
|
289
|
+
5. Save. A pull request with a red `agjan-check`, or one that removes the workflow (the
|
|
290
|
+
check then never reports), can no longer be merged.
|
|
291
|
+
|
|
292
|
+
**Optionally, owners for the rules.** A `CODEOWNERS` file names who must review changes
|
|
293
|
+
to certain files. With **Require review from Code Owners** turned on in the same rule,
|
|
294
|
+
changes to agjan's configuration, approvals, hooks and workflows need your review.
|
|
295
|
+
Create `.github/CODEOWNERS` (replace `@<owner>` with your GitHub user or team):
|
|
250
296
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
297
|
+
```text
|
|
298
|
+
# agjan: changes to the rules need an owner's review
|
|
299
|
+
/agjan.config.json @<owner>
|
|
300
|
+
/agjan.lock.json @<owner>
|
|
301
|
+
/docs/agjan/**/approvals.json @<owner>
|
|
302
|
+
/.claude/ @<owner>
|
|
303
|
+
/.github/agents/ @<owner>
|
|
304
|
+
/.github/hooks/ @<owner>
|
|
305
|
+
/.github/workflows/ @<owner>
|
|
306
|
+
/package.json @<owner>
|
|
307
|
+
/package-lock.json @<owner>
|
|
308
|
+
```
|
|
256
309
|
|
|
257
|
-
|
|
258
|
-
review;
|
|
259
|
-
- CODEOWNERS for the files that change the rules (`init` prints a block):
|
|
260
|
-
`agjan.config.json`, `agjan.lock.json`, `docs/agjan/**/approvals.json`, `.claude/`,
|
|
261
|
-
`.github/agents/`, `.github/hooks/`, `.github/workflows/`, `package.json`,
|
|
262
|
-
`package-lock.json`.
|
|
310
|
+
Good to know:
|
|
263
311
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
312
|
+
- GitHub Actions minutes: private repositories have a monthly quota. When it is used up,
|
|
313
|
+
the check cannot run, and a required check blocks every merge until the quota resets
|
|
314
|
+
(or an admin bypasses the rule). Public repositories are not affected.
|
|
315
|
+
- Working alone: GitHub does not let you approve your own pull request. Leave the
|
|
316
|
+
required review off, or add yourself to the rule's **Bypass list**.
|
|
317
|
+
- The approval commands are guardrails, not proof that a human approved; the reviewed
|
|
318
|
+
merge is the trust boundary.
|
|
267
319
|
|
|
268
320
|
## Upgrading
|
|
269
321
|
|
package/kit/hooks/guard.mjs
CHANGED
|
@@ -10,20 +10,28 @@
|
|
|
10
10
|
* `agent.script_edits` to "allow" (design decision 63).
|
|
11
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
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
+
* File edit tools (Copilot `edit`/`create`, Claude Code `Edit`/`Write`/`MultiEdit`): hand
|
|
20
|
+
* 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.
|
|
16
24
|
*
|
|
17
25
|
* Reads the host's payload on stdin and answers in the host's format:
|
|
18
|
-
* - GitHub Copilot: { toolName, toolArgs: { command } } -> { permissionDecision, permissionDecisionReason }
|
|
19
|
-
* - Claude Code: { tool_name, tool_input: { command } } -> { hookSpecificOutput: { … } }
|
|
26
|
+
* - GitHub Copilot: { toolName, toolArgs: { command | path } } -> { permissionDecision, permissionDecisionReason }
|
|
27
|
+
* - Claude Code: { tool_name, tool_input: { command | file_path } } -> { hookSpecificOutput: { … } }
|
|
20
28
|
* Prints nothing (default behavior) for any other command or unreadable input.
|
|
21
29
|
*
|
|
22
30
|
* Deliberately self-contained and dependency-free: it runs before every tool call.
|
|
23
31
|
*/
|
|
24
32
|
|
|
25
33
|
import { readFileSync, realpathSync } from 'node:fs';
|
|
26
|
-
import { join } from 'node:path';
|
|
34
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
27
35
|
import { fileURLToPath } from 'node:url';
|
|
28
36
|
|
|
29
37
|
const REASON =
|
|
@@ -33,12 +41,13 @@ const REASON =
|
|
|
33
41
|
const HUMAN_ONLY = /\bagjan(?:\.mjs)?["']?\s+(?:--\s+)?["']?(approve|accept|reject)\b/;
|
|
34
42
|
|
|
35
43
|
const BRANCH_REASON =
|
|
36
|
-
'
|
|
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.';
|
|
37
45
|
|
|
38
46
|
/**
|
|
39
47
|
* Commands that create or rename a branch: git switch -c/-C, git checkout -b/-B/--orphan,
|
|
40
|
-
* git branch <name> (also -m/-c), git worktree add -b.
|
|
41
|
-
*
|
|
48
|
+
* git branch <name> (also -m/-c), git worktree add -b. Always denied: agents create branches
|
|
49
|
+
* with npx agjan branch after asking the user (design decision 62); git options such as
|
|
50
|
+
* `-C <dir>` may come before.
|
|
42
51
|
*/
|
|
43
52
|
const BRANCH_CREATE = new RegExp(
|
|
44
53
|
String.raw`\bgit(?:\s+-[cC]\s+\S+|\s+--[\w-]+(?:=\S+)?)*\s+` +
|
|
@@ -75,20 +84,120 @@ function unquoted(command) {
|
|
|
75
84
|
return command.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, 'Q');
|
|
76
85
|
}
|
|
77
86
|
|
|
78
|
-
/**
|
|
79
|
-
const
|
|
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
|
+
/**
|
|
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.
|
|
95
|
+
*/
|
|
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
|
+
}
|
|
80
146
|
|
|
81
|
-
|
|
82
|
-
export function allowed(command, allow) {
|
|
83
|
-
if (!Array.isArray(allow) || COMPOUND.test(command)) return false;
|
|
84
|
-
const normalized = command.trim().replace(/\s+/g, ' ');
|
|
147
|
+
function listed(part, allow) {
|
|
85
148
|
return allow.some((entry) => {
|
|
86
149
|
if (typeof entry !== 'string' || entry.trim() === '') return false;
|
|
87
150
|
const prefix = entry.trim().replace(/\s+/g, ' ');
|
|
88
|
-
return
|
|
151
|
+
return part === prefix || part.startsWith(`${prefix} `);
|
|
89
152
|
});
|
|
90
153
|
}
|
|
91
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));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const RECORD_REASON =
|
|
177
|
+
'agjan writes this file itself (approvals, reviews, logs, progress, fix records, baseline). Never edit it by hand; use the agjan commands.';
|
|
178
|
+
|
|
179
|
+
/** 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$/;
|
|
181
|
+
|
|
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)$/;
|
|
184
|
+
|
|
185
|
+
const EDIT_TOOLS = new Set(['edit', 'create', 'Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
|
|
186
|
+
|
|
187
|
+
/** The guard's answer for a file edit tool call, or null. */
|
|
188
|
+
function decideEdit(payload, config, root) {
|
|
189
|
+
const args = payload.toolArgs ?? payload.tool_input ?? {};
|
|
190
|
+
const target = args.path ?? args.file_path ?? args.notebook_path;
|
|
191
|
+
if (typeof target !== 'string' || target === '') return null;
|
|
192
|
+
const rel = relative(root, resolve(root, target)).split('\\').join('/');
|
|
193
|
+
const inside = rel !== '' && !rel.startsWith('../') && rel !== '..' && !isAbsolute(rel);
|
|
194
|
+
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
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
|
|
92
201
|
function answer(payload, decision, reason) {
|
|
93
202
|
if (payload.tool_input !== undefined) {
|
|
94
203
|
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: decision, permissionDecisionReason: reason } };
|
|
@@ -100,15 +209,16 @@ function answer(payload, decision, reason) {
|
|
|
100
209
|
* The guard's answer for a payload: deny, allow (listed in `config.agent.allow`), or null
|
|
101
210
|
* (the host decides). `config` is the project's agjan.config.json.
|
|
102
211
|
*/
|
|
103
|
-
export function decide(payload, config = {}) {
|
|
212
|
+
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);
|
|
104
214
|
const command = payload?.toolArgs?.command ?? payload?.tool_input?.command;
|
|
105
215
|
if (typeof command !== 'string') return null;
|
|
106
216
|
if (HUMAN_ONLY.test(command)) return answer(payload, 'deny', REASON);
|
|
107
|
-
if (
|
|
217
|
+
if (BRANCH_CREATE.test(command)) return answer(payload, 'deny', BRANCH_REASON);
|
|
108
218
|
if (config?.agent?.script_edits !== 'allow' && SCRIPT_EDITS.some((matches) => matches(command))) return answer(payload, 'deny', EDIT_REASON);
|
|
109
219
|
const allow = config?.agent?.allow ?? [];
|
|
110
220
|
const shell = /^(bash|powershell|shell)$/i.test(payload.toolName ?? payload.tool_name ?? '');
|
|
111
|
-
if (shell && allowed(command, allow)) return answer(payload, 'allow', 'listed in agent.allow of agjan.config.json');
|
|
221
|
+
if (shell && allowed(command, allow, root)) return answer(payload, 'allow', 'listed in agent.allow of agjan.config.json');
|
|
112
222
|
return null;
|
|
113
223
|
}
|
|
114
224
|
|
|
@@ -20,9 +20,17 @@ change, or a business decision: stop and recommend `/agjan-spec`.
|
|
|
20
20
|
|
|
21
21
|
## 2. Start
|
|
22
22
|
|
|
23
|
-
Work on a branch of its own, without features. If you are on the base branch,
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
Work on a branch of its own, without features. If you are on the base branch,
|
|
24
|
+
ask the user one question with these choices (your host's question tool):
|
|
25
|
+
"Work needs its own branch. Create one, or use an existing branch?"
|
|
26
|
+
1. Create branch "<name>" (your proposal, following the team's naming rule if
|
|
27
|
+
AGENTS.md names one): run `npx agjan branch <name>`.
|
|
28
|
+
2. Use an existing branch: run `npx agjan branch --list`, let the user pick one
|
|
29
|
+
(offer the names as choices), then run `npx agjan branch --use <picked>`.
|
|
30
|
+
3. Another name: ask for it, then run `npx agjan branch <their name>`.
|
|
31
|
+
If `agjan branch` refuses a name (invalid, already exists), say why and ask again.
|
|
32
|
+
Never create or switch branches with git directly.
|
|
33
|
+
|
|
26
34
|
Pick a slug and a key of 2 to 6 capitals:
|
|
27
35
|
|
|
28
36
|
`npx agjan fix start <slug> --key <KEY> --what "<one sentence: what the fix changes>"`
|
|
@@ -10,9 +10,18 @@ The merge of this branch is its approval.
|
|
|
10
10
|
|
|
11
11
|
## 1. Start
|
|
12
12
|
|
|
13
|
-
On a branch of its own, without features or fixes
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
On a branch of its own, without features or fixes. If you are on the base branch,
|
|
14
|
+
ask the user one question with these choices (your host's question tool):
|
|
15
|
+
"Work needs its own branch. Create one, or use an existing branch?"
|
|
16
|
+
1. Create branch "<name>" (your proposal, following the team's naming rule if
|
|
17
|
+
AGENTS.md names one): run `npx agjan branch <name>`.
|
|
18
|
+
2. Use an existing branch: run `npx agjan branch --list`, let the user pick one
|
|
19
|
+
(offer the names as choices), then run `npx agjan branch --use <picked>`.
|
|
20
|
+
3. Another name: ask for it, then run `npx agjan branch <their name>`.
|
|
21
|
+
If `agjan branch` refuses a name (invalid, already exists), say why and ask again.
|
|
22
|
+
Never create or switch branches with git directly.
|
|
23
|
+
|
|
24
|
+
Then:
|
|
16
25
|
|
|
17
26
|
`npx agjan map start`
|
|
18
27
|
|
|
@@ -14,11 +14,18 @@ design. You write; the agjan reviewer checks; the human approves.
|
|
|
14
14
|
Run `npx agjan status`. If a feature is already in progress on this branch, continue
|
|
15
15
|
it instead of starting a new one. Otherwise:
|
|
16
16
|
|
|
17
|
-
- If you are on the base branch, the work needs a branch of its own.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
- If you are on the base branch, the work needs a branch of its own. Ask the user one
|
|
18
|
+
question with these choices (your host's question tool):
|
|
19
|
+
"Work needs its own branch. Create one, or use an existing branch?"
|
|
20
|
+
1. Create branch "<name>" (your proposal, following the team's naming rule if
|
|
21
|
+
AGENTS.md names one): run `npx agjan branch <name>`.
|
|
22
|
+
2. Use an existing branch: run `npx agjan branch --list`, let the user pick one
|
|
23
|
+
(offer the names as choices), then run `npx agjan branch --use <picked>`.
|
|
24
|
+
3. Another name: ask for it, then run `npx agjan branch <their name>`.
|
|
25
|
+
If `agjan branch` refuses a name (invalid, already exists), say why and ask again.
|
|
26
|
+
Never create or switch branches with git directly.
|
|
27
|
+
After switching, run `npx agjan status` again: an existing branch may already carry a
|
|
28
|
+
feature to continue.
|
|
22
29
|
- Pick a slug (lowercase, `-`, short: `order-status-filter`) and a key of 2 to 6
|
|
23
30
|
capitals (`OSF`).
|
|
24
31
|
- `npx agjan new <slug> --key <KEY>`
|
|
@@ -25,7 +25,9 @@ review due again: `npx agjan status` lists it; do it before the final review.
|
|
|
25
25
|
## 3. Baseline
|
|
26
26
|
|
|
27
27
|
If the feature added a CDS service, a Fiori application or a BTP service, update
|
|
28
|
-
`docs/agjan/project.md` (short, with pointers to the real files).
|
|
28
|
+
`docs/agjan/project.md` (short, with pointers to the real files). Keep its section
|
|
29
|
+
"Run locally" current: the start command, the URLs of the apps and the test users with
|
|
30
|
+
their roles, so the user can try the result. Then run
|
|
29
31
|
`npx agjan baseline refresh` whenever `npx agjan check` warns that watched files changed
|
|
30
32
|
since the baseline, and commit both.
|
|
31
33
|
|
|
@@ -44,11 +46,12 @@ Any change after the final review makes it stale; review again after the last ch
|
|
|
44
46
|
changed.
|
|
45
47
|
- `npx agjan report` writes `report.md` (durations, gate waits, models, tokens); commit
|
|
46
48
|
it.
|
|
47
|
-
- Finish with `npx agjan status`.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
- Finish with `npx agjan status --done`. Your final message starts with its output,
|
|
50
|
+
**verbatim, in a code block**: it says that development is done, what was met, and the
|
|
51
|
+
optional next steps. After it, add only what the user must know that it does not say
|
|
52
|
+
(for example what you could not check yourself). Do not end with a question: opening a
|
|
53
|
+
pull request is one of the optional next steps, done only when the user asks (its
|
|
54
|
+
description is the output of `npx agjan pr-summary`).
|
|
52
55
|
|
|
53
56
|
## 6. Pull request, only when the user asks
|
|
54
57
|
|
|
@@ -23,6 +23,7 @@ Rules for designing and building CAP Node.js backends in agjan. Project conventi
|
|
|
23
23
|
|
|
24
24
|
| The task touches | Read |
|
|
25
25
|
|---|---|
|
|
26
|
+
| a new project, the layout, configuration, development users, sample data, running it | `references/project-setup.md` |
|
|
26
27
|
| entities, types, associations, compositions, localized texts | `references/modeling.md` |
|
|
27
28
|
| services, projections, actions, functions, drafts, remote services | `references/services.md` |
|
|
28
29
|
| input validation, `@mandatory`, `@assert…`, authorization, error messages | `references/validation-security.md` |
|
|
@@ -31,6 +32,9 @@ Rules for designing and building CAP Node.js backends in agjan. Project conventi
|
|
|
31
32
|
|
|
32
33
|
## Decide in this order
|
|
33
34
|
|
|
35
|
+
0. **A new project** starts as `references/project-setup.md` says (`cds init <name>
|
|
36
|
+
--nodejs`, never `cds add sample`).
|
|
37
|
+
|
|
34
38
|
1. **Declarative before code.** What an annotation can express (validation, read-only,
|
|
35
39
|
authorization, defaults) is never written as handler code.
|
|
36
40
|
2. **Extend before adding.** A new service, entity or BTP-relevant dependency is a
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# Handlers, queries, errors, transactions (Node.js)
|
|
2
2
|
|
|
3
3
|
Distilled from the CAP documentation (capire, Apache-2.0), retrieved through the CAP
|
|
4
|
-
MCP server on 2026-10-17
|
|
4
|
+
MCP server on 2026-10-17, with patterns from the CAP team's agent skills (`capire/skills`)
|
|
5
|
+
and the reference apps `capire/bookshop` and `capire/incidents-app` (Apache-2.0); the
|
|
6
|
+
examples were checked with `@sap/cds` 10.1 on 2026-10-18. Rules restated; check details
|
|
7
|
+
with `search_docs`.
|
|
5
8
|
|
|
6
9
|
## Where handlers go
|
|
7
10
|
|
|
@@ -45,6 +48,60 @@ MCP server on 2026-10-17. Rules restated; check details with `search_docs`.
|
|
|
45
48
|
you, and nested calls to other services do not join it.
|
|
46
49
|
- Lock what you read before changing it in the same transaction:
|
|
47
50
|
`SELECT(1).from(Orders, id).forUpdate()`.
|
|
48
|
-
- For a status transition, make the update itself conditional on the expected state
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
- For a status transition, make the update itself conditional on the expected state, in
|
|
52
|
+
one round trip. It returns the number of changed rows (`@sap/cds` 10.1; projects that set
|
|
53
|
+
`cds.features.legacy_db_results: false` get `{ affected }` instead); 0 means the state
|
|
54
|
+
had changed. `.where()` and `.with()` may come in either order.
|
|
55
|
+
|
|
56
|
+
## A handler file (ESM, checked with @sap/cds 10.1)
|
|
57
|
+
|
|
58
|
+
<!-- checked: srv/leave-service.js -->
|
|
59
|
+
```js
|
|
60
|
+
import cds from '@sap/cds'
|
|
61
|
+
|
|
62
|
+
export class LeaveService extends cds.ApplicationService { init() {
|
|
63
|
+
const { LeaveRequests } = this.entities
|
|
64
|
+
|
|
65
|
+
// Fill what the client must not set; check a rule across rows.
|
|
66
|
+
this.before('CREATE', LeaveRequests, async req => {
|
|
67
|
+
const { startDate, endDate } = req.data
|
|
68
|
+
req.data.employee_userId = req.user.id
|
|
69
|
+
const overlap = await SELECT.one.from(LeaveRequests).columns('ID').where({
|
|
70
|
+
employee_userId: req.user.id, status_code: { '!=': 'R' },
|
|
71
|
+
startDate: { '<=': endDate }, endDate: { '>=': startDate }
|
|
72
|
+
})
|
|
73
|
+
if (overlap) return req.reject(400, 'ASSERT_OVERLAP', 'startDate') // target: the field
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// A status transition: one conditional UPDATE, no SELECT before it.
|
|
77
|
+
this.on('approve', LeaveRequests, async req => {
|
|
78
|
+
const [{ ID }] = req.params
|
|
79
|
+
const n = await UPDATE(LeaveRequests, ID).where({ status_code: 'N' }).with({ status_code: 'A' })
|
|
80
|
+
if (!n) return req.reject(409, 'ONLY_NEW_REQUESTS') // key in _i18n/messages.properties
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// A virtual field per row and user (for example to enable a Fiori button).
|
|
84
|
+
this.after('READ', LeaveRequests, (rows, req) => {
|
|
85
|
+
for (const r of Array.isArray(rows) ? rows : [rows]) {
|
|
86
|
+
if (r) r.canDecide = req.user.is('manager') && r.status_code === 'N'
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
return super.init() // required: the generic handlers, auth, drafts
|
|
91
|
+
}}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- An after-`READ` handler sees only the columns the client selected (Fiori selects what
|
|
95
|
+
the page shows). Compute from columns that are on the page, or read the missing ones.
|
|
96
|
+
- `req.reject(status, code)` ends the request; `req.error(…)` collects several errors.
|
|
97
|
+
Never `throw new Error(…)`: it becomes a 500.
|
|
98
|
+
- A rule across rows (no overlaps, a limit per user) belongs in a `before` handler, as
|
|
99
|
+
above; rules within one row are `@assert` annotations (validation-security.md). A query
|
|
100
|
+
awaited in a handler goes to the database without the service's `@restrict`: filter by
|
|
101
|
+
the user yourself.
|
|
102
|
+
- Never add a helper association (for example `on 1 = 1`, to reach other rows) to an
|
|
103
|
+
entity a service exposes: clients can follow it with `$expand` and read rows the
|
|
104
|
+
`where` of `@restrict` hides (checked with `@sap/cds` 10.1).
|
|
105
|
+
- Select explicit columns (`SELECT.one.from(E, id).columns('status_code')`), never `*`.
|
|
106
|
+
- Events to other parts of the application: `await this.emit('Approved', { ID })` in an
|
|
107
|
+
`after` handler.
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# Domain modeling (CDS)
|
|
2
2
|
|
|
3
3
|
Distilled from the CAP documentation (capire, Apache-2.0), retrieved through the CAP
|
|
4
|
-
MCP server on 2026-10-17
|
|
4
|
+
MCP server on 2026-10-17, with patterns from the CAP team's agent skills (`capire/skills`)
|
|
5
|
+
and the reference apps `capire/bookshop` and `capire/incidents-app` (Apache-2.0); the
|
|
6
|
+
examples were checked with `@sap/cds` 10.1 on 2026-10-18. Rules restated; check details
|
|
7
|
+
with `search_docs`.
|
|
5
8
|
|
|
6
9
|
## Keep it simple
|
|
7
10
|
|
|
@@ -44,6 +47,35 @@ composed to your body; your phone is associated with you.")
|
|
|
44
47
|
- A child of a composition has a back association to its parent
|
|
45
48
|
(`Items : Composition of many OrderItems on Items.parent = $self`).
|
|
46
49
|
|
|
50
|
+
## Code lists, enums and calculated elements (checked with @sap/cds 10.1)
|
|
51
|
+
|
|
52
|
+
<!-- checked: db/schema.cds -->
|
|
53
|
+
```cds
|
|
54
|
+
using { cuid, managed, sap.common.CodeList } from '@sap/cds/common';
|
|
55
|
+
namespace sap.capire.leaves;
|
|
56
|
+
|
|
57
|
+
entity LeaveRequests : cuid, managed {
|
|
58
|
+
employee : Association to Employees;
|
|
59
|
+
startDate : Date @mandatory;
|
|
60
|
+
endDate : Date @mandatory;
|
|
61
|
+
type : Association to LeaveTypes @mandatory;
|
|
62
|
+
status : Association to Status default 'N';
|
|
63
|
+
days : Integer = days_between(startDate, endDate) + 1; // calculated, not stored
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
entity Status : CodeList { // name, descr (localized) from CodeList
|
|
67
|
+
key code : String(1) enum { new = 'N'; approved = 'A'; rejected = 'R'; };
|
|
68
|
+
criticality : Integer; // 1 red, 2 yellow, 3 green: Fiori colors the status
|
|
69
|
+
}
|
|
70
|
+
entity LeaveTypes : CodeList { key code : String(10); }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- A status or a type with a fixed set of values is a **code list** entity (`CodeList`)
|
|
74
|
+
with an association to it, not a plain string: Fiori shows its name, offers it as a
|
|
75
|
+
value help, and colors it by `criticality`.
|
|
76
|
+
- `managed` only on the root of a composition tree; the children are covered by it.
|
|
77
|
+
- Calculated elements (`= <expression>`) are computed on read and need no handler.
|
|
78
|
+
|
|
47
79
|
## Localized data
|
|
48
80
|
|
|
49
81
|
- Mark translatable texts with `localized` (`title : localized String`); CAP generates
|