agjan 0.0.20 → 0.0.21

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 (56) hide show
  1. package/dist/adapters/claude-code.js +9 -3
  2. package/dist/auto.js +4 -0
  3. package/dist/baseline.js +11 -8
  4. package/dist/commands/check.js +65 -13
  5. package/dist/commands/gates.js +9 -1
  6. package/dist/commands/lint.js +16 -5
  7. package/dist/commands/new.js +4 -3
  8. package/dist/commands/setup.js +91 -81
  9. package/dist/config.js +24 -0
  10. package/dist/fix.js +13 -10
  11. package/dist/git.js +57 -9
  12. package/dist/launcher.js +9 -3
  13. package/dist/progress-view.js +35 -23
  14. package/dist/progress.js +103 -38
  15. package/dist/qa.js +10 -5
  16. package/dist/review-policy.js +4 -1
  17. package/dist/review.js +82 -35
  18. package/dist/schema.js +85 -0
  19. package/dist/scope.js +12 -4
  20. package/dist/tests-map.js +17 -11
  21. package/docs/guide.md +25 -7
  22. package/kit/domains/btp/domain.json +2 -2
  23. package/kit/hooks/guard.mjs +53 -9
  24. package/kit/skills/agjan-design/SKILL.md +13 -0
  25. package/kit/skills/agjan-fix/SKILL.md +1 -1
  26. package/kit/skills/agjan-spec/SKILL.md +7 -1
  27. package/kit/skills/agjan-spec/references/elicitation.md +135 -0
  28. package/kit/skills/btp-architect/SKILL.md +7 -2
  29. package/kit/skills/btp-architect/references/deployment.md +43 -0
  30. package/kit/skills/btp-architect/references/security.md +59 -4
  31. package/kit/skills/cap-developer/SKILL.md +19 -7
  32. package/kit/skills/cap-developer/references/agents.md +90 -0
  33. package/kit/skills/cap-developer/references/handlers.md +88 -9
  34. package/kit/skills/cap-developer/references/modeling.md +41 -0
  35. package/kit/skills/cap-developer/references/project-setup.md +57 -7
  36. package/kit/skills/cap-developer/references/services.md +172 -7
  37. package/kit/skills/cap-developer/references/testing.md +79 -6
  38. package/kit/skills/cap-developer/references/typescript.md +8 -7
  39. package/kit/skills/cap-developer/references/validation-security.md +74 -2
  40. package/kit/skills/fiori-developer/SKILL.md +21 -1
  41. package/kit/skills/fiori-developer/references/accessibility.md +65 -0
  42. package/kit/skills/fiori-developer/references/app-setup.md +10 -3
  43. package/kit/skills/fiori-developer/references/elements-cookbook.md +71 -0
  44. package/kit/skills/fiori-developer/references/elements.md +82 -9
  45. package/kit/skills/fiori-developer/references/freestyle-ts.md +27 -0
  46. package/kit/skills/fiori-developer/references/testing.md +5 -0
  47. package/kit/skills/fiori-developer/references/ui5-basics.md +34 -1
  48. package/kit/skills/qa-tester/SKILL.md +11 -4
  49. package/kit/skills/qa-tester/references/techniques.md +123 -0
  50. package/kit/skills/solution-reviewer/SKILL.md +10 -0
  51. package/kit/skills/solution-reviewer/references/defects.md +154 -0
  52. package/kit/templates/agents-block.md +1 -1
  53. package/kit/templates/agjan-ci.yml +3 -0
  54. package/package.json +1 -1
  55. package/schemas/config.schema.json +1 -1
  56. package/schemas/reviews.schema.json +1 -1
@@ -53,6 +53,10 @@ To start a feature:
53
53
  - Ask the user only what the business needs: who, what, why, what is out of scope.
54
54
  One round of questions at most; put remaining uncertainty into the spec as open
55
55
  questions.
56
+ - Before you ask, go through `.claude/skills/agjan-spec/references/elicitation.md`: the
57
+ gaps a senior business analyst closes (who may do what, the life of a record, limits,
58
+ personal data, two people at once, volumes, what the user is told, other systems). Ask
59
+ the ones the request leaves open and whose answer changes the result.
56
60
 
57
61
  ## 3. Write `docs/agjan/<slug>/spec.md`
58
62
 
@@ -66,7 +70,9 @@ Keep the template's headings exactly (they are checked). Write the text in the l
66
70
  - Never make technical decisions the requester did not ask for. Write technical
67
71
  questions under `## Open technical questions`; Design answers them.
68
72
  - Acceptance criteria: `### <KEY>-AC1`, `### <KEY>-AC2`, ... each with `Given`,
69
- `When`, `Then` lines. Each must be testable by someone who did not write it. Add
73
+ `When`, `Then` lines (`And` adds one). Each must be testable by someone who did not
74
+ write it: concrete data, an observable outcome, an AC for the user who may not, and one
75
+ at the edge of every limit (elicitation.md, "Writing the acceptance criteria"). Add
70
76
  `Verification: manual` only when an automated test is not practical (for example
71
77
  visual layout); the default is automated.
72
78
  - `## Authorization` says who may do what, in business roles.
@@ -0,0 +1,135 @@
1
+ # What a senior business analyst asks
2
+
3
+ The questions that decide whether a feature works for its users, and that a spec most
4
+ often leaves open. All of them are business questions: ask them in the user's words,
5
+ and never answer one with a technology (that is Design's work).
6
+
7
+ Ask only what the request leaves open and the answer changes the result. One round of
8
+ questions at most (`SKILL.md`, section 2); what stays open goes into the spec as an open
9
+ question, a technical one under `## Open technical questions`.
10
+
11
+ ## Who may do what
12
+
13
+ The gaps that turn into security defects. Fill `## Authorization` as a matrix in prose:
14
+
15
+ - Who **creates**, who **sees**, who **changes**, who **deletes**, who **decides** (an
16
+ action), for each kind of record.
17
+ - **Own, team or all**: does a manager see the requests of their team only, or of everyone
18
+ below them? Who is "the team" when someone changes teams?
19
+ - **Stand-ins**: who acts when the manager is away? Is a stand-in allowed at all?
20
+ - **Separation of duties**: may someone approve their own request (a manager who is also
21
+ an employee)?
22
+ - **Read-only roles**: does anyone only look (an auditor, HR, a reporting team)?
23
+ - What a user **without** the role sees: nothing, or a message?
24
+
25
+ ## The life of a record
26
+
27
+ - The **states** a record goes through, and who or what moves it to the next one.
28
+ - Which steps can be **undone** (withdraw, reopen, cancel), and by whom, until when.
29
+ - What may still **change** in each state (nothing after approval? only the comment?).
30
+ - **Deadlines**: does anything happen when nobody acts (a reminder, an escalation, an
31
+ automatic decision)?
32
+ - **Deletion**: may records be deleted, or only cancelled? How long are they kept?
33
+
34
+ ## The data
35
+
36
+ - Which fields are **required**, and their **limits** in business terms: "a comment of at
37
+ most 500 characters", "an amount with two decimals", "at most 30 days per request".
38
+ - **Numbers and identifiers** the users see (a request number), and whether they must be
39
+ without gaps.
40
+ - **Duplicates and overlaps**: two requests for the same days? the same customer twice?
41
+ - **Dates**: time zones of the users, working days or calendar days, public holidays,
42
+ across a year end, half days.
43
+ - **Money and quantities**: currency, rounding, units.
44
+ - **Languages**: which languages the texts and the data are in.
45
+
46
+ ## Personal data
47
+
48
+ Ask whenever the feature stores data about people (employees, customers, contacts):
49
+
50
+ - Whose data is it, and who may see it (sickness as a leave type is sensitive)?
51
+ - How long must it be kept, and when must it be deleted or anonymized?
52
+ - Must changes or reads of it be traceable (who looked at what)?
53
+
54
+ Write the answers into `## Business constraints` and `## Authorization`; they become
55
+ data-protection decisions in Design.
56
+
57
+ ## Two people at once
58
+
59
+ - Two managers decide the same request at the same moment: the first wins, and the second
60
+ is told?
61
+ - Two people edit the same record: may the second overwrite the first?
62
+
63
+ ## How much, how fast
64
+
65
+ Make `## Non-functional requirements` measurable, or "none":
66
+
67
+ - How many records (now, in a year), how many users at the same time?
68
+ - How fast must a list or an action answer for them ("the list shows within 2 seconds
69
+ with 10,000 requests")?
70
+ - Does the list show everything, or do users always filter first (by year, by team)?
71
+ - Availability or working hours that matter (end of month, payroll runs)?
72
+ - Accessibility: must the app meet a standard (for example WCAG 2.2 level AA), and do
73
+ users work with a screen reader or only the keyboard? The answer is a non-functional
74
+ requirement with a measurable target.
75
+
76
+ ## What the user is told
77
+
78
+ - After an action: a short confirmation, or a message they must read?
79
+ - Before an action that cannot be undone: is the user asked to confirm?
80
+ - When something is not allowed: which reason do they see?
81
+ - Who else is **informed** (the employee after a decision, by mail, in the inbox, not at
82
+ all)? That is a business requirement; how it is sent is Design's.
83
+
84
+ ## Other systems
85
+
86
+ - Does data come from somewhere else (employees from HR, customers from the ERP), and who
87
+ owns it?
88
+ - Must something go to another system (a payroll export, an update in the ERP), and what
89
+ happens when that system is down?
90
+
91
+ ## An AI agent in the app
92
+
93
+ Ask when the request mentions an assistant, a chat, or "the system should decide":
94
+
95
+ - What may the agent only read, and what may it do (create, approve, send)?
96
+ - Which actions need a person's yes before the agent runs them?
97
+ - Which data may it see, and may personal data be sent to an AI model at all?
98
+ - Who may use it, and how much (requests per user per hour)?
99
+ - How do we judge its answers (examples of good and bad answers become the acceptance
100
+ criteria; the automated tests check what it may do, not every wording)?
101
+
102
+ ## Writing the acceptance criteria
103
+
104
+ - One behaviour per AC, with **concrete data**: "Given a new request of Erika for 2 to 6
105
+ November", not "Given a request".
106
+ - The **outcome is observable**: what the user sees or what is stored, not "it works".
107
+ - Every rule of `## Authorization` has an AC for the user who **may not** (a manager of
108
+ another team cannot approve), not only for the one who may.
109
+ - Every limit has an AC at its **edge** ("a request of 30 days is accepted; 31 days are
110
+ refused with the message …").
111
+ - Every state with a restriction has an AC for the forbidden step ("an approved request
112
+ cannot be approved again").
113
+ - Business words, not screens: "the manager approves", not "clicks the button in the
114
+ third column". Name what the user sees only where it matters (a message, a confirmation).
115
+ - `Verification: manual` only where an automated test cannot judge it (a layout, a
116
+ printed document).
117
+
118
+ A weak and a strong AC for the same rule:
119
+
120
+ ```text
121
+ ### LR-AC4
122
+ Given a request
123
+ When the manager approves it
124
+ Then it is approved
125
+ ```
126
+
127
+ ```text
128
+ ### LR-AC4
129
+ Given a new leave request of Erika (team Sales) for 2 to 6 November
130
+ When Mia, the manager of Sales, approves it
131
+ Then the request has the status Approved
132
+ And Mia is told that it is approved
133
+ And the request can no longer be approved or rejected
134
+ Verification: automated
135
+ ```
@@ -24,8 +24,8 @@ existing `mta.yaml` or Helm chart) win over these defaults.
24
24
 
25
25
  | The task touches | Read |
26
26
  |---|---|
27
- | runtime, `mta.yaml`, Helm, database, `cds add`, profiles, health, logging | `references/deployment.md` |
28
- | `xs-security.json`, roles, authentication, app router, destinations, secrets | `references/security.md` |
27
+ | runtime, `mta.yaml`, Helm, database, what the production build contains, serving the UIs, which `cds add` facet, updates without downtime, health, logging | `references/deployment.md` |
28
+ | IAS or XSUAA, `xs-security.json`, roles, redirect URIs, app router, destinations, secrets | `references/security.md` |
29
29
 
30
30
  ## Decide in this order
31
31
 
@@ -40,6 +40,11 @@ existing `mta.yaml` or Helm chart) win over these defaults.
40
40
  4. **Security follows the model.** Roles come from the service's `@requires` and
41
41
  `@restrict`; `xs-security.json` is derived from them, never the other way round.
42
42
  5. **Secrets never go into files** in the repository; they come from service bindings.
43
+ 6. **Every app and every data change has a way to production.** A design with a Fiori
44
+ app says how it is served (it is not in `cds build`); a model change that renames or
45
+ deletes persisted data says how the data moves; demo rows never reach `db/data`.
46
+ 7. **Identity:** IAS with AMS for new projects (CAP's recommendation), XSUAA where the
47
+ project already uses it; switching is a decision of its own.
43
48
 
44
49
  ## Building
45
50
 
@@ -35,6 +35,31 @@ CC-BY-4.0), on 2026-10-17. Rules restated; check details with `search_docs`.
35
35
  change before committing.
36
36
  - Keep `package-lock.json` current (`npm install --package-lock-only`) so the build
37
37
  installs what was tested.
38
+ - Updates without downtime: `cf deploy <mtar> --strategy blue-green` (the MultiApps CLI
39
+ plugin) runs the new version next to the old and switches routes after checks; confirm
40
+ the options for the landscape. Database changes deploy first and must work with both
41
+ versions while they run side by side (cap-developer `modeling.md`, changing a deployed
42
+ model).
43
+
44
+ ## What a production build contains (checked with cds-dk 10.1)
45
+
46
+ - `cds build --production` writes `gen/srv` (the compiled service, its `package.json`) and
47
+ `gen/db` (the HDI artifacts). Check it before committing a deployment change.
48
+ - **The Fiori apps are not in it.** `cds watch` serves them through `cds-plugin-ui5`, a
49
+ development dependency; in production nothing serves `app/` unless the design decides how:
50
+ the HTML5 Application Repository (`cds add html5-repo`) with SAP Build Work Zone
51
+ (`cds add workzone-standard`) for a launchpad, or the Application Frontend service
52
+ (`cds add app-frontend`). A design with a Fiori app and a btp area names one.
53
+ - `gen/db` contains `.hdbtabledata` only for `db/data` (test rows in `test/data` stay out),
54
+ the `cds.outbox.Messages` table of the persistent queue, and an `undeploy.json` that lets
55
+ HDI remove views and draft tables. Never add tables to `undeploy.json` (their data is
56
+ dropped).
57
+ - Every TypeScript file that `tsconfig.cdsbuild.json` does not exclude is compiled into
58
+ `gen/srv` and deployed (tests, a `playwright.config.ts`): exclude them (cap-developer
59
+ `typescript.md`).
60
+ - `cds add mta` builds with `npm ci` and `cds build --production`, deploys modules in
61
+ parallel, and gives the service 1 instance; memory, instances and per-landscape values
62
+ belong in an `.mtaext` per landscape, not in the base `mta.yaml`.
38
63
 
39
64
  ## Kyma
40
65
 
@@ -61,6 +86,24 @@ CC-BY-4.0), on 2026-10-17. Rules restated; check details with `search_docs`.
61
86
  and extensibility fundamentally: decide it at the start of a project, never as a side
62
87
  effect of a feature.
63
88
 
89
+ ## Choosing what to add
90
+
91
+ `cds add` (cds-dk 10.1) has a facet for each BTP service a CAP app commonly needs; each is a
92
+ decision with its plan and cost, never a side effect:
93
+
94
+ | Need | Facet |
95
+ |---|---|
96
+ | login and roles | `ias` with `ams` (new projects), `xsuaa` (existing) |
97
+ | database | `hana`, `hana-serverless`, `postgres` |
98
+ | UI hosting and launchpad | `html5-repo`, `workzone-standard`, `app-frontend`, `approuter` |
99
+ | remote systems | `destination`, `connectivity` (on-premise through the Cloud Connector) |
100
+ | events between apps | `event-mesh`, `enterprise-messaging`, `kafka`, `redis-messaging` |
101
+ | personal data, logs, telemetry | `audit-logging`, `application-logging`, `cloud-logging` |
102
+ | files | `attachments` (Object Store), `malware-scanner` |
103
+ | an AI agent or other LLM use | `ai` (SAP AI Core, adds `@cap-js/ai`); the agent itself is `@cap-js/agents` (cap-developer `agents.md`) |
104
+ | notifications to users | `notifications` |
105
+ | CI/CD | `github-actions`, `pipeline` |
106
+
64
107
  ## Operations
65
108
 
66
109
  - The Node.js runtime answers `/health` with `{ status: 'UP' }` for liveness and readiness
@@ -4,7 +4,50 @@ Distilled from the CAP documentation (capire, Apache-2.0), retrieved through the
4
4
  server, and from the SAP BTP documentation (`SAP-docs/btp-cloud-platform`, CC-BY-4.0),
5
5
  on 2026-10-17. Rules restated; check details with `search_docs`.
6
6
 
7
- ## Authentication and the security descriptor
7
+ ## Choosing the identity service
8
+
9
+ Authentication is a design decision, and for a project already on XSUAA it stays XSUAA:
10
+
11
+ - **New projects: SAP Cloud Identity Services (IAS)**, as CAP's documentation now
12
+ recommends ("Start new projects with IAS"): `cds add ias` for authentication, and
13
+ `cds add ams` for roles through the Authorization Management Service (below). IAS also propagates users across landscapes, which XSUAA does
14
+ not do out of the box. Production uses `"auth": { "kind": "ias" }`.
15
+ - **XSUAA** (`cds add xsuaa`, below) where the project, the subaccount's role collections
16
+ or the customer's landscape already use it. IAS can consume XSUAA-protected services.
17
+ - Either way the model's roles are the source; the descriptor or the policies are derived.
18
+ - Confirm the current setup steps with `search_docs` ("Adding IAS", "Adding AMS Support");
19
+ they changed in recent CAP releases.
20
+
21
+ ## Authorization with AMS (checked with @sap/ams 3.10 and @sap/cds 10.1)
22
+
23
+ Tried on a copy of the example with the setup of SAP's `ams-samples-node` (Apache-2.0):
24
+
25
+ - `cds add ams` (it adds `ias` too) adds `@sap/ams`, `@sap/xssec` and the dev plugin
26
+ `@sap/ams-dev`, and sets `"[production]": { "auth": "ias" }`. It rewrites the whole
27
+ `package.json`; review the diff.
28
+ - **The roles stay in the model** (`@requires`, `@restrict`). `cds build --for ams` writes
29
+ `ams/dcl/cap/basePolicies.dcl`, one policy per role (`POLICY "manager" { ASSIGN ROLE
30
+ "manager"; }`), and `ams/dcl/schema.dcl`. Commit the `ams/` folder; administrators
31
+ assign the policies to users in the Identity Service, at runtime and without a
32
+ deployment (role changes are cached for 15 seconds in the sample).
33
+ - **Attributes** let administrators narrow a role per user without code:
34
+ `annotate LeaveService.LeaveRequests with @ams.attributes: { Team: (employee.team.name) };`
35
+ puts `Team: String` into the schema. Write the base policy so it can be restricted,
36
+ `ASSIGN ROLE "manager" WHERE Team IS NOT RESTRICTED;`, and a restricting policy uses it:
37
+ `POLICY SalesManager { USE cap.manager RESTRICT Team IN ('Sales'); }`. Once you edit a
38
+ generated file and remove its generated header, the build keeps it.
39
+ - The attribute filter **adds to** the model's `where`: the team's manager saw 2 requests
40
+ with `cap.manager` and with Sales only, and 0 with Support only. AMS narrows, it never
41
+ opens what `@restrict` closes.
42
+ - **Local and test users** get policies instead of roles,
43
+ `"manager": { "password": "manager", "policies": ["cap.manager"] }`; policies for tests
44
+ only go to `ams/dcl/local/` (the sample's convention). Users with `roles` keep working.
45
+ Technical users and calls from other apps use `ias_apis` with API policies, which
46
+ narrow the user's policies further (principal propagation in the sample).
47
+ - Each policy, attribute and assignment rule is an authorization decision of the design;
48
+ `ams/**` is a risk path in agjan, like `xs-security.json`.
49
+
50
+ ## Authentication and the security descriptor (XSUAA)
8
51
 
9
52
  - `cds add xsuaa` configures XSUAA authentication (`"auth": "xsuaa"`, with `@sap/xssec`)
10
53
  and generates `xs-security.json` from the model:
@@ -22,12 +65,24 @@ on 2026-10-17. Rules restated; check details with `search_docs`.
22
65
  common subset works for both.) Attributes used as `$user.<attribute>`: letters, digits
23
66
  and `_`, at most 64 characters. Role collection names: at most 64 characters.
24
67
  - Role collections, which group role templates and are assigned to users, are normally
25
- created by administrators in the BTP cockpit. Predefine them in `xs-security.json`
26
- (`role-collections`) only for templates without attributes. The design names who
27
- assigns which collection.
68
+ created by administrators in the BTP cockpit. Predefine them only for templates without
69
+ attributes. The design names who assigns which collection.
70
+ - What `cds add xsuaa,mta` writes (cds-dk 10.1, checked 2026-10-21) and why it matters:
71
+ - `xs-security.json` holds the scopes and role templates; `mta.yaml` adds the instance
72
+ `config`: `xsappname: <app>-${org}-${space}` (one per space, so dev and prod do not
73
+ collide), `tenant-mode: dedicated`, `credential-types: [binding-secret, x509]`, and the
74
+ role collections named `<role> (<app> ${org}-${space})`.
75
+ - `oauth2-configuration.redirect-uris: [https://*~{app-api/app-uri}/**]`: XSUAA redirects
76
+ a login only to listed URLs. Keep the entry when editing, and add every other host the
77
+ app is reached by (a custom domain), or the login fails with a redirect error.
78
+ - `[production]: { auth: 'xsuaa' }` in `package.json`, `@sap/xssec` as a dependency.
28
79
 
29
80
  ## App router
30
81
 
82
+ - `cds add approuter` (cds-dk 10.1) writes `.deploy/app-router/` with an `xs-app.json`
83
+ that forwards everything to the service destination `srv-api` with
84
+ `"csrfProtection": true` and the user's token (`forwardAuthToken: true` in `mta.yaml`).
85
+ Keep CSRF protection on for every route that changes data.
31
86
  - `cds add approuter` adds the SAP application router, which serves the UIs, runs the
32
87
  interactive login against XSUAA and forwards requests with the user's token. Routes
33
88
  live in `xs-app.json`. It is only needed for deployment; keep it out of the app folders
@@ -23,12 +23,13 @@ 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
+ | a new project, the layout, configuration, development users, sample and test data, running it | `references/project-setup.md` |
27
27
  | TypeScript: setup, generated types, typed handlers, tests, build (the default language) | `references/typescript.md` |
28
- | entities, types, associations, compositions, localized texts | `references/modeling.md` |
29
- | services, projections, actions, functions, drafts, remote services | `references/services.md` |
30
- | input validation, `@mandatory`, `@assert…`, authorization, error messages | `references/validation-security.md` |
31
- | handler code, queries, errors, transactions | `references/handlers.md` |
28
+ | entities, types (money, dates, lengths), associations, compositions, localized texts, changing a deployed model | `references/modeling.md` |
29
+ | an AI agent in the app (`@cap-js/agents`: `@agent`, the LLM per profile, `AGENTS.md` next to a service, human approval, masking) | `references/agents.md` |
30
+ | services, projections, actions, functions, status-transition flows, drafts, read-only input, concurrent changes, value help, remote services and their local mocks, other protocols (`@rest`, `@mcp`) | `references/services.md` |
31
+ | input validation, `@mandatory`, `@assert…`, authorization, error messages, personal data | `references/validation-security.md` |
32
+ | handler code, queries, errors, messages to the user, performance, queued calls, transactions | `references/handlers.md` |
32
33
  | tests | `references/testing.md` |
33
34
 
34
35
  ## Decide in this order
@@ -41,7 +42,8 @@ Rules for designing and building CAP Node.js backends in agjan. Project conventi
41
42
  convert it on your own (`references/typescript.md`).
42
43
 
43
44
  1. **Declarative before code.** What an annotation can express (validation, read-only,
44
- authorization, defaults) is never written as handler code.
45
+ authorization, defaults, status transitions with `@flow.status`) is never written as
46
+ handler code.
45
47
  2. **Extend before adding.** A new service, entity or BTP-relevant dependency is a
46
48
  design decision with reason and alternative; prefer extending what exists.
47
49
  3. **The domain model stays clean; services are facades.** Persistence in `db/`;
@@ -49,7 +51,13 @@ Rules for designing and building CAP Node.js backends in agjan. Project conventi
49
51
  4. **Authorization is part of the design**, named after the spec's business roles, and a
50
52
  risk whenever it changes.
51
53
  5. **Compatibility.** Removing or renaming an element of an exposed entity breaks
52
- clients (UIs, other services); call it out under Risks.
54
+ clients (UIs, other services), and on a deployed SAP HANA database a rename drops the
55
+ column's data (`references/modeling.md`); call it out under Risks.
56
+ 6. **Design for production, not for the demo.** For every entity the feature touches,
57
+ decide and write down: how many rows (paging, no queries in loops), who changes it at
58
+ the same time (draft lock or `@odata.etag`), which fields only the server sets
59
+ (`@readonly`, `@Core.Immutable`), and whether it holds personal data (`@PersonalData`,
60
+ audit logging). Demo rows go to `test/data`, never `db/data`.
53
61
 
54
62
  ## Building
55
63
 
@@ -57,5 +65,9 @@ Rules for designing and building CAP Node.js backends in agjan. Project conventi
57
65
  `.js` in a JavaScript project).
58
66
  - In TypeScript, `npm run typecheck` (cds-typer, then `tsc --noEmit`) must pass with the
59
67
  tests.
68
+ - Where the project has `eslint.config.mjs`, `npx cds lint` must pass after a model change
69
+ (CAP's model and authorization rules, `references/project-setup.md`).
70
+ - One concern per file, as the layout says (`references/project-setup.md`): constraints,
71
+ flows and each app's annotations next to the service, not inside it.
60
72
  - Write a test for each AC of the task, named with the AC id, through the service API.
61
73
  - Run the area's test command, then `npx agjan check`, before you commit the task.
@@ -0,0 +1,90 @@
1
+ # CAP-level agents (`@cap-js/agents`)
2
+
3
+ Distilled from the plugin `cap-js/agents` (Apache-2.0, `@cap-js/agents` 0.9.8, repository at
4
+ `95bce97`) and CAP's guide "CAP-level Agents"; tried on a copy of the example with
5
+ `@sap/cds` 10.1 on 2026-10-21. The plugin is alpha in CAP's June 2026 release: an agent is
6
+ a design decision (btp: SAP AI Core), never added unasked. It must not be used to give
7
+ agents access to SAP application APIs (CAP's guide, "SAP API Policy").
8
+
9
+ ## What it does
10
+
11
+ `npm add @cap-js/agents`, then `annotate LeaveService with @agent;` serves the service as
12
+ an agent over the A2A protocol (`/a2a/<service>`, an agent card at
13
+ `/a2a/<service>/.well-known/agent-card.json`, a chat preview at `…/preview/` in
14
+ development). The agent's tools are the MCP tools of the service (`@cap-js/mcp`,
15
+ services.md, Other protocols): `describe`, `query` and, for unbound actions, `call`.
16
+
17
+ Checked on the example:
18
+
19
+ - **`@agent` alone replaces OData**, like `@mcp`: the service was served at `/a2a/leave`
20
+ only and `/odata/v4/leave` answered 404. Name every protocol: `@odata @agent`.
21
+ - **Authorization holds:** the agent card answered 401 (anonymous) and 403 (no role); the
22
+ agent's `query` ran as the calling user, so `@restrict` filtered it (the employee's agent
23
+ saw one request, the team's manager's two, another manager's none). Tasks (the stored
24
+ conversations) are per user: another user's `tasks/get` answered "Task not found".
25
+ - **Bound actions are not tools** (`approve`, `decline` were not offered; the agent had 2
26
+ tools). An agent that must act needs unbound actions, each with its own authorization
27
+ and checks, and `@agent.hitl` (or `@Common.IsActionCritical`, which the plugin honors)
28
+ so that a human approves before it runs: the task waits in A2A state `input-required`.
29
+ - Paths in `query` reach what associations reach (validation-security.md, "What paths can
30
+ reach"): give agents a service of their own with small projections.
31
+
32
+ ## The LLM, and whose credentials
33
+
34
+ `cds.requires.llm` decides which model answers; the plugin's defaults per profile:
35
+
36
+ | Profile | `llm` |
37
+ |---|---|
38
+ | development (also `cds.test`) | `auto`: credentials from the environment (`ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_BASE_URL`), then `~/.claude/settings.json`, Codex's and OpenCode's configuration, else a mock |
39
+ | hybrid, production | `aicore` (SAP AI Core; `cds add ai` adds `@cap-js/ai` for it) |
40
+
41
+ - **Tests and local runs can spend a developer's LLM credits and send the dev data to the
42
+ model:** with a key in the environment, `cds.test` resolved `llm` to `anthropic` with that
43
+ key (checked with a fake key, no request sent). Pin the mock for development and tests:
44
+
45
+ ```json
46
+ "cds": { "requires": { "[development]": { "llm": { "kind": "llm-mock" } } } }
47
+ ```
48
+
49
+ The mock answers with a fixed text after one `query` on the service's first entity:
50
+ enough to test the wiring and the authorization, not the agent's judgment. In 0.9.8 the
51
+ automatic fallback named the kind `mock`, which has no implementation ("No service
52
+ implementation found for llm"); `llm-mock` works.
53
+ - Real model runs (evals) are tests of their own, run on purpose with a binding to SAP AI
54
+ Core (`cds bind --exec -- npx vitest run test/eval/…`), never in the normal test command;
55
+ the plugin's `@cap-js/agents/eval` offers `Judge` (LLM as judge) and `matchToolCall`
56
+ (experimental).
57
+
58
+ ## `AGENTS.md` next to a service is the agent's prompt
59
+
60
+ The plugin looks for an agent directory per service: `@agent.directory`, else the folder of
61
+ the service's `.cds` file **if it has an `AGENTS.md`**, else `<folder>/<service>-agent/`, else
62
+ `<folder>/agents/<service>/`. With an `AGENTS.md` there it builds a "deep agent" that reads
63
+ that file as its memory (instructions) and `skills/*/SKILL.md` as its skills. Checked: an
64
+ `srv/AGENTS.md` written as notes for coding agents made `LeaveService` a deep agent with
65
+ `agentDir: …/srv`.
66
+
67
+ - Put each agent in a folder of its own (`srv/leave-agent/`, with its `service.cds`,
68
+ `AGENTS.md`, `skills/`), and never put notes for coding agents into an `AGENTS.md` in a
69
+ service folder: the app's agent would follow them. agjan's own `AGENTS.md` is at the
70
+ project root, where no service lives.
71
+ - Coding agents that read nested `AGENTS.md` files (GitHub Copilot does) take an agent's
72
+ prompt as instructions for that folder; say in the root `AGENTS.md` (outside agjan's
73
+ block) that `srv/*-agent/AGENTS.md` files are prompts of the app's agents.
74
+ - The plugin sets `cds.folders.srvs` to `srv/*`, so services in subfolders of `srv/` are
75
+ loaded.
76
+
77
+ ## Data, limits, operations
78
+
79
+ - **Personal data reaches the model unless masking is on:** `cds.agents.masking` is
80
+ `false` by default; with `true`, fields annotated `@PersonalData.IsPotentiallyPersonal`,
81
+ `IsPotentiallySensitive` or `FieldSemantics: 'UserID'`/`'DataSubjectID'` are
82
+ pseudonymized before the model and the traces see them (plugin documentation). The
83
+ annotations come from the model (validation-security.md, Personal data).
84
+ - Conversations, checkpoints and tasks are stored in the app's database (the plugin's
85
+ `cap.agent.*` entities, deployed with the app) and kept 30 days (`cds.agents.retention`).
86
+ - Quotas limit tasks, tool calls, tokens and time per user and tenant
87
+ (`cds.agents.quotas`; defaults such as 20 tasks per hour per user, 50 tool calls per task,
88
+ 5 minutes per task); a breach answers 429 or ends the task.
89
+ - With `@cap-js/audit-logging` it writes audit events for decisions, tool calls and human
90
+ approvals; with `@cap-js/telemetry` it emits traces and metrics (tokens, tool calls).
@@ -28,6 +28,29 @@ with `search_docs`.
28
28
  - 5xx errors reach the client as generic messages in production; never put internal
29
29
  details into them, and do not turn sanitizing off.
30
30
  - If an annotation can do the check, do not write it (see validation-security.md).
31
+ - CAP's own messages (`INVALID_FLOW_TRANSITION_SINGLE`, `ASSERT_*`) get the project's
32
+ texts in `_i18n/messages_en.properties` (and the other languages' files): the
33
+ framework's English file takes precedence over a project's `messages.properties`
34
+ (checked with `@sap/cds` 10.1).
35
+ - Messages take arguments: `req.reject(400, 'LIMIT_EXCEEDED', [max])` fills `{0}` of
36
+ `LIMIT_EXCEEDED=At most {0} days.` in `_i18n/messages.properties` (checked with `@sap/cds`
37
+ 10.1). Annotation messages (`@assert`) take none.
38
+
39
+ ## Messages that do not fail the request
40
+
41
+ A handler can tell the user something and still succeed; the messages travel in the
42
+ `sap-messages` response header. How Fiori elements shows them after an action (checked in
43
+ a browser with SAPUI5 1.145 on 2026-10-21):
44
+
45
+ | Call | Severity | Fiori elements shows |
46
+ |---|---|---|
47
+ | `req.notify('KEY')` | success | a toast that disappears by itself |
48
+ | `req.info('KEY')` | information | a dialog the user has to close |
49
+ | `req.warn('KEY')` | warning | a warning dialog the user has to close |
50
+
51
+ - A confirmation that something worked is `req.notify`; `info` and `warn` interrupt the
52
+ user and are for what they must read.
53
+ - Keys resolve like error codes, from `_i18n/messages.properties`, with arguments.
31
54
 
32
55
  ## Queries
33
56
 
@@ -38,6 +61,52 @@ with `search_docs`.
38
61
  - `INSERT.into`, `UPDATE(Entity, key).with(…)`, `DELETE.from` work the same way; on a
39
62
  service, `srv.run(query)` or the CRUD helpers `srv.read/create/update`.
40
63
 
64
+ ## Performance
65
+
66
+ - **No queries in a loop.** Read what the rows need in one query: `SELECT.from(Employees)
67
+ .where({ userId: { in: ids } })`, or with the parent in one go through a nested
68
+ projection: `SELECT.from(Employees, e => { e.name, e.team(t => { t.name }) })`
69
+ (checked with `@sap/cds` 10.1). Ten rows on a page must not mean ten round trips.
70
+ - **Read only the columns you use**, never `*` on wide entities.
71
+ - **OData reads are paged:** `cds.query.limit.max` (default 1000) caps every collection
72
+ read; the response then carries `@odata.nextLink`, and a larger `$top` is cut to the
73
+ maximum without an error (checked with `@sap/cds` 10.1). Code that reads a collection
74
+ over OData follows the next link; a page size per entity is `@cds.query.limit`.
75
+ - Database work in handlers is pushed down where it can be (`UPDATE … with` an expression,
76
+ a calculated element), not done row by row in JavaScript.
77
+
78
+ ## Work that runs later or elsewhere
79
+
80
+ - Calls to other systems that must happen when (and only when) the transaction commits,
81
+ and survive a crash (mails, events, a remote update), go through a queued service:
82
+ `const mail = cds.queued(await cds.connect.to('Mail')); await mail.send('send', data)`.
83
+ The message is stored in the same transaction (`cds.outbox.Messages`) and dispatched
84
+ after the commit, with retries (the persistent queue is the default; `cds.outboxed` is
85
+ the older name). Events to a message broker (`messaging.emit`) are queued that way too.
86
+ - **Events between apps:** declare the event in the service (`event Request.Decided { ID :
87
+ UUID; status : String; }`) and send it from a handler with `await this.emit(…)`; another
88
+ app connects to that service (`cds.requires` with its model) and subscribes,
89
+ `(await cds.connect.to('LeaveService')).on('Request.Decided', msg => …)`. With
90
+ `"messaging": true` in `cds.requires`, CAP uses file-based messaging in development
91
+ (`~/.cds-msg-box`, so two apps on one machine exchange events with no broker) and SAP
92
+ Event Mesh in production, queued in both (checked with cds-dk 10.2,
93
+ `cds env get requires.messaging`; the event declared, emitted and received in-process
94
+ with `@sap/cds` 10.1). The production broker is a btp decision.
95
+ - **Delayed or recurring work** (a nightly cleanup, a replication every 10 minutes):
96
+ `await srv.schedule('cleanup', { olderThan: '30d' }).every('1h')`, or `.after('10m')`, or
97
+ a cron string (`.every('0 2 * * *')`). It is queued like `cds.queued(srv).send()`, but as
98
+ **one** task per event name, stored and run once across all instances, so registering it
99
+ at every start is safe (in `server.js` at the project root,
100
+ `cds.on('served', async () => { … })`: CAP runs these listeners one after the other and
101
+ starts serving requests only after them; checked with `@sap/cds` 10.1); `.as('<name>')`
102
+ makes several tasks of one event,
103
+ `srv.unschedule('<name>')` removes one (CAP 10; a delayed task checked with `@sap/cds`
104
+ 10.1).
105
+ - `cds.spawn` runs a detached in-memory job: lost on a crash and run by every instance.
106
+ Only for work that is idempotent and may be dropped (a cache refresh).
107
+ - Choosing a broker (SAP Event Mesh, Kafka, Redis) or SAP's Job Scheduling service (jobs
108
+ managed outside the app) is a btp decision.
109
+
41
110
  ## Transactions
42
111
 
43
112
  - A request handler already runs in a transaction; do not wrap it in `cds.tx(req)`
@@ -48,10 +117,18 @@ with `search_docs`.
48
117
  you, and nested calls to other services do not join it.
49
118
  - Lock what you read before changing it in the same transaction:
50
119
  `SELECT(1).from(Orders, id).forUpdate()`.
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.
120
+ - Status transitions are a flow (services.md, Status-transition flows). Where two people
121
+ may decide the same record at the same moment, also make the update conditional on the
122
+ expected state, in one round trip, in the action's `on` handler:
123
+ `const n = await UPDATE(req.subject).where({ status_code: 'N' }).with({ status_code: 'A' })`,
124
+ then `if (!n) return req.reject(409, …)`. Awaited in a handler, it runs on the database
125
+ and returns the number of changed rows (`@sap/cds` 10.1; `cds.features.legacy_db_results:
126
+ false` gives `{ affected }` instead); 0 means the state had changed. `.where()` and
127
+ `.with()` may come in either order.
128
+ - Through a service (`srv.run`, `srv.update`), a write returns an array with `.affected`
129
+ (CAP 10): an array is always truthy, so test `.affected`, never the result itself. For a
130
+ draft-enabled entity, `.affected` was 1 whatever matched (`@sap/cds` 10.1.1, checked with
131
+ 0 and 2 rows): conditional updates go to the database as above.
55
132
 
56
133
  ## A handler file (TypeScript, checked with @sap/cds 10.1)
57
134
 
@@ -73,11 +150,9 @@ export class LeaveService extends cds.ApplicationService { override init() {
73
150
  if (overlap) return req.reject(400, 'ASSERT_OVERLAP', 'startDate') // target: the field
74
151
  })
75
152
 
76
- // A status transition: one conditional UPDATE, no SELECT before it.
77
- this.on(LeaveRequest.actions.approve, async req => {
78
- const [{ ID }] = req.params as { ID: string }[]
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
153
+ // The flow (leave-flows.cds) checks and sets the status; handlers add what it does not.
154
+ this.after(LeaveRequest.actions.approve, (_, req) => {
155
+ req.notify('REQUEST_APPROVED') // a success message: Fiori shows it as a toast
81
156
  })
82
157
 
83
158
  // A virtual field per row and user (for example to enable a Fiori button).
@@ -87,6 +162,10 @@ export class LeaveService extends cds.ApplicationService { override init() {
87
162
  }
88
163
  })
89
164
 
165
+ this.on(LeaveRequest.actions.decline, async req => {
166
+ await UPDATE(req.subject).with({ reason: req.data.reason }) // the action's parameter
167
+ })
168
+
90
169
  return super.init() // required: the generic handlers, auth, drafts
91
170
  }}
92
171
  ```