@klok-integration/cli 0.3.3 → 0.4.0

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 CHANGED
@@ -43,6 +43,9 @@ Credentials are written to `~/.config/klok/credentials.json` with mode 0600.
43
43
  | `klok agents init` | Write the Klok agent instructions and skills into a repository. |
44
44
  | `klok bead list\|show\|report` | Progress beads in the current repository. |
45
45
  | `klok docs publish` | Build this repository's znai documentation and upload it to the docs portal. |
46
+ | `klok docs build` | Build this repository's `klok-docs/` with znai the way its documentation project will, uploading nothing. |
47
+ | `klok solutions validate` | Check the descriptors of an integration solution registry against the descriptor contract. |
48
+ | `klok ci env` | Show what klok-cli detected about the CI job it runs in. |
46
49
  | `klok manifest update` | Set a container's image in a deploy manifest of your GitOps repository, then commit and push. |
47
50
  | `klok sync clone\|pull\|status` | Clone and refresh every repository you can see, in one workspace folder. |
48
51
 
@@ -93,8 +96,8 @@ Cursor (`.cursor/mcp.json`):
93
96
  ## Agent instructions
94
97
 
95
98
  `klok agents init` writes `KLOK-AGENTS.md` with the rules, one managed row in every harness file
96
- (`AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.cursorrules`, `.clinerules`,
97
- `.github/copilot-instructions.md`), the klok named rule files (`.cursor/rules`, `.agents/rules`) and the
99
+ (`AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.cursorrules`, `.clinerules` or a file inside a
100
+ `.clinerules/` directory, `.github/copilot-instructions.md`), the klok named rule files (`.cursor/rules`, `.agents/rules`) and the
98
101
  Klok skills. `KLOK-AGENTS.md`, the klok rule files and the `klok-*` skills belong to Klok and are
99
102
  replaced wholesale; every other file keeps its content and only has its single row created or replaced,
100
103
  so an update can never duplicate text. Klok skills the CLI no longer ships are removed.
@@ -10,12 +10,20 @@ https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt for the pipeli
10
10
  * One root element `<Name>_vN` that references every complex type; a single `xs:` prefix; `targetNamespace` and
11
11
  `xmlns:tns` set; `elementFormDefault="qualified"`. Validate with the XSD validation of the CI template before
12
12
  pushing (`python3 scripts/validate-xsd.py` from build-ci-templates, or the pipeline's `generate_avro_from_xsd`).
13
- * The major version is part of the model name (`Customer_v1`, class `CustomerV1`); a breaking change is a new
14
- major version and a new topic, never a silent change of an existing one.
13
+ * One name, in kebab case, from the repository down: `customer-v1` is the repository, the XSD file
14
+ (`customer-v1.xsd`), the Maven artifact and the npm and Python packages, and `customer_v1` ends the Java package.
15
+ Inside the XSD the model keeps its PascalCase form: root element `Customer_v1`, root type and class `CustomerV1`.
16
+ * The major version is part of the model name; a breaking change is a new major version and a new topic, never a
17
+ silent change of an existing one.
15
18
  * `meta.json` uses the flat form with `targetNamespace`; it drives the generated project's group, name and
16
19
  documentation.
17
20
  * Consumers reference the artifact only through the catalog alias (`klokLibs.<key>`), never by literal version.
18
21
  * Datamodel documentation lives in `klok-docs/` (purpose, fields that need explanation, producers and consumers,
19
- design decisions) and is mirrored to the documentation project.
22
+ design decisions). The datamodel pipeline's `klok_docs_publish` job sends it with the XSD to docs.klok.dev, where
23
+ the model is documented from the XSD (a structure page, then AI sections from the complex types up) under
24
+ `<tenant>/documentation/datamodel/<same path>`. Put `xs:documentation` on types and fields; that is what the
25
+ generated text is written from.
26
+ * The repository's path is its class: `public` (A), `common` (B), `domain/<d>` (C) or `system/<s>` (X). The wider
27
+ the scope, the stricter a breaking change; see the `klok-datamodel` skill.
20
28
  * On `main` the pipeline publishes and updates the catalog; check it, then refresh consumers with
21
29
  `./gradlew updateKlokLibsToml`.
@@ -1,15 +1,25 @@
1
1
  ## This repository: documentation project
2
2
 
3
3
  A znai documentation project published to https://docs.klok.dev under the doc id in `klok-docs-sync.json`. Read
4
- https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt (docs sync) for how content arrives here.
4
+ https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt (documentation from a source repository) for how
5
+ content arrives here. There are two kinds, and they are edited differently:
6
+
7
+ * **The documentation project of a source repository** (`<tenant>/documentation/<group>/.../<repo>`, mirroring the
8
+ source path) is output. KlokDocumentationEgress (`klok/integration/klok-documentation-egress`, KLK007) builds it
9
+ from the `KlokProjectDocumentationV1` payload the source repository's `main` pipeline publishes, replaces
10
+ everything under `docs/` on every run and commits the AI sections under `docs/_ai/`. Never edit it: a change made
11
+ here is overwritten by the next run. There are exactly two places to change it:
12
+ * `klok-docs/` in the source repository, in a merge request there: the hand written pages, their order and
13
+ chapter titles (`toc-manifest.json`), and where an AI section appears (`<!-- KLOK:GENERATED:START <id> -->` …
14
+ `<!-- KLOK:GENERATED:END <id> -->`);
15
+ * what is generated and how (chapters, sections, prompts, languages, model): klok.dev, Tenant Administration,
16
+ Documentation generation, which tenant admins change.
17
+ * **A standalone documentation project** (directly under `<tenant>/documentation/`, such as
18
+ `klok-integration-strategy-and-tactics`) is written by hand in this repository, and the egress never touches it.
19
+ Keep `docs/toc` and `docs/toc-manifest.json` in sync when adding a page.
5
20
 
6
21
  ### Rules
7
22
 
8
- * `docs/klok-docs/` and `docs/generated/` are written by the docs sync of the source repository. Never edit them
9
- here; change `klok-docs/` in the source repository, or the generator. Only `KLOK:GENERATED` regions of AI
10
- maintained pages are rewritten automatically.
11
- * Human pages live in `docs/` next to them (`overview`, `architecture`, `operations`, `changelog`); keep
12
- `docs/toc` and `docs/toc-manifest.json` in sync when adding a page.
13
23
  * The doc id must start with the tenant prefix (`<tenant>-...`); the pipeline refuses others. Do not set the
14
24
  tenant, the Vault path or upload tokens in the project CI. This project's `.gitlab-ci.yml` is the include of
15
25
  `klok/environment/build-ci-templates:/klok-docs-publish.yml` and nothing else; the job is `klok docs publish`.
@@ -27,10 +27,19 @@ needs. Read https://docs.klok.dev/klok-framework-klok-quarkus-extension/llm.txt
27
27
  (`KlokTaskInitiation`, `KlokAsyncTaskWorkerRoute`).
28
28
  * Tests: `@QuarkusTest` with the recording broker client factory; assert routes started and published messages,
29
29
  never talk to a real broker or OpenSearch in unit tests.
30
+ * A route that serves several tenants (a shared platform service) consumes each tenant's own request topic,
31
+ `<tenant>[_<env>]/common/<Model>`, from the subscription list klok.dev keeps in the klok ODL; it takes the tenant
32
+ from the namespace it received on and rejects a message whose payload or properties name another tenant. It never
33
+ picks an index, repository or account from a field in the message, and what it writes back for a tenant goes to
34
+ klok's namespace, one topic per tenant.
35
+ * The service connects to the broker with a client of its own (`KLOK_BROKER_AUTH_CLIENT_ID`), granted `publish` and
36
+ `consume` on its own tenant's namespaces only; a topic of another tenant is a `consume` grant on that one topic,
37
+ reached with `<RouteId>.topic.tenant-override`. Never reuse another service's credentials.
30
38
  * `application.properties` keeps every `klok.*` key explicit; secrets come from environment variables that the
31
39
  Vault env secret provides in Kubernetes (`KLOK_BROKER_AUTH_CLIENT_ID`, ...).
32
40
  * Update `klok-docs/` (overview, design decisions, routes, operations) in the same merge request as the change.
33
- * On `main` the pipeline builds the image, updates the deployment manifest and syncs the documentation; check it.
41
+ * On `main` the pipeline builds the image, updates the deployment manifest and publishes the documentation payload
42
+ that KlokDocumentationEgress turns into the documentation project; check it.
34
43
  * The `Dockerfile` copies `build/quarkus-app/lib/` in a `COPY` of its own before `quarkus-run.jar`, `quarkus/`
35
44
  and `app/`, all with `COPY --chown`, never `COPY build/quarkus-app/ .` followed by `RUN chown -R`, which stores
36
45
  every dependency twice in every build.
@@ -19,6 +19,9 @@ content as one markdown file at `https://docs.klok.dev/<doc-id>/llm.txt`; fetch
19
19
  | Broker client | https://docs.klok.dev/klok-framework-klok-brokerclient-java/llm.txt |
20
20
  | Gradle plugin, versions, catalog | https://docs.klok.dev/klok-framework-klok-gradle-plugin/llm.txt |
21
21
  | CI templates, release process, Vault roles | https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt |
22
+ | Developer rules: identity and access, Keycloak, Vault paths, certificates, infrastructure as code | https://docs.klok.dev/klok-framework-development-guide/llm.txt |
23
+ | How people use the platform: concepts, roles and access, workflow, operations | https://docs.klok.dev/klok-user-guide/llm.txt |
24
+ | Infrastructure: stateful services, certificates, Ansible, Keycloak clients | https://docs.klok.dev/klok-environment-klok-environment-setup/llm.txt |
22
25
 
23
26
  A 404 means the documentation project is not published yet; read the repository's `klok-docs/` folder instead.
24
27
  The `klok-docs` skill describes the lookup in detail.
@@ -149,15 +152,51 @@ step by step procedure; the contract every agent follows is:
149
152
  header, Pulsar property and CloudEvents extension, `klok.`-prefixed as MDC key.
150
153
  * Repositories: `<tenant>/integration/domain/<d>/<repo>`, `<tenant>/datamodel/...`, mirrored documentation under
151
154
  `<tenant>/documentation/...`; documentation ids are `slug(<tenant>-<group>-...-<repo>)`.
155
+ * Permission words, one meaning each: *ingress/egress* says what a service is and is never a permission; broker
156
+ rights are `publish` and `consume` (Pulsar's own `produce`/`consume` only inside a grant command); `read` and
157
+ `ingest` belong to klok.dev's integration context graph and never to the broker.
158
+
159
+ ## Broker access and tenant isolation
160
+
161
+ Read the *Broker Access And Tenant Isolation* page of
162
+ https://docs.klok.dev/klok-framework-development-guide/llm.txt before designing anything that touches broker
163
+ access, Keycloak broker clients or a service that serves several tenants.
164
+
165
+ * **The topic decides the tenant, never the message.** Pulsar does not tell a consumer who published; a `tenant`
166
+ field or property can be forged by any client allowed on the topic. A service takes the tenant from the topic
167
+ name and rejects a payload that claims another one.
168
+ * **Write narrow, consume wide.** A tenant publishes only in its own namespace, `<tenant>[_<env>]/<domain>`; nobody
169
+ holds `publish` in another tenant's namespace, not even on one topic. Reading elsewhere is a `consume` grant on a
170
+ named topic, approved by the owner and recorded in Git in the owning tenant. A topic read across tenants carries
171
+ its reader as the last purpose segment (`persistent://konvoj/hr/PersonnelScheduleExportV1_degerfors`).
172
+ * **Platform services** (logs, the ODL, AI, mail, SMS, documentation) are shared klok workers that follow the same
173
+ rule: a tenant's requests live in the tenant's namespace (`persistent://<tenant>[_<env>]/common/KlokLogEventV5`)
174
+ and the worker is granted `consume` on exactly those topics, taking the tenant from the namespace; what the
175
+ platform writes back lives in klok's namespace, one topic per tenant (`klok[_<env>]/<domain>/<Model>_<tenant>`).
176
+ The worker subscribes to a list of topics kept in the klok ODL, never to a pattern. The ODL runs as one instance
177
+ per tenant.
178
+ * **Identities:** one Keycloak client per running deployment, never shared, never used by a person; its Pulsar role
179
+ is `service-account-<client id>`; one CI broker client per tenant; every broker client attaches the client scope
180
+ `pulsar` (audience and the `nbf` claim Pulsar requires) instead of copying mappers.
181
+ * **Grants:** `publish` and `consume` on the service's own domain and its tenant's `common`, as namespace grants;
182
+ anything in another domain or tenant is `consume` on one topic, never `publish`, approved by its owner and
183
+ recorded in Git in the owning tenant. Pulsar's `produce`/`consume` appear only inside a grant command.
184
+ * **Who applies it:** Ansible (`klok/environment/klok-environment-setup`) for the platform and tenant klok's
185
+ services, klok.dev for tenant projects. A grant made only in the broker's admin API is drift.
152
186
 
153
187
  ## Documentation is part of every change
154
188
 
155
189
  Klok documentation has three levels, and a change is finished only when all three have been considered:
156
190
 
157
- * **The repository's own `klok-docs/`** (znai markdown, `toc-manifest.json`), which KlokDocumentationEgress merges
158
- with the pages it generates from the code into the repository's documentation project on every `main` pipeline.
159
- That documentation project is output: never edit it; what is generated is set by tenant admins in klok.dev. A change that adds or alters a route, a datamodel, a configuration key, a
160
- CI job, a command or a decision updates `klok-docs/` in the same merge request.
191
+ * **The repository's own `klok-docs/`** (znai markdown, `toc-manifest.json`). On every `main` pipeline
192
+ `./gradlew publishKlokDocs` publishes it, together with the scan of the code, as `KlokProjectDocumentationV1` on
193
+ `persistent://<tenant>[_<env>]/common/KlokProjectDocumentationV1_prepared`. KlokDocumentationEgress
194
+ (`klok/integration/klok-documentation-egress`, KLK007) builds the repository's documentation project from it. That
195
+ documentation project is output, and nobody edits it. There are two places to change a project's documentation:
196
+ `klok-docs/` in the source repository (including the `KLOK:GENERATED` markers that place AI sections in a page),
197
+ and the documentation generation settings in klok.dev, which tenant admins own. A change that adds or alters a
198
+ route, a datamodel, a configuration key, a CI job, a command or a decision updates `klok-docs/` in the same merge
199
+ request.
161
200
 
162
201
  `klok-docs/` has to answer **two different questions**, and a repository that answers only the first is not
163
202
  documented:
@@ -180,22 +219,27 @@ Klok documentation has three levels, and a change is finished only when all thre
180
219
  and tactics (`klok-integration-strategy-and-tactics`) and the framework, CI and tooling documentation. They
181
220
  describe how the platform is used and why. A change that alters a rule, a convention, a workflow, a command or
182
221
  a published contract belongs there too, even when the code that changed lives somewhere else entirely.
183
- * **Generated pages** (`docs/generated/`, `KLOK:GENERATED` regions), which are never edited by hand. A wrong
184
- generated page is a bug in the generator.
222
+ * **Generated pages**: everything KlokDocumentationEgress writes into a documentation project, including the AI
223
+ sections that fill `KLOK:GENERATED` regions. They are never edited by hand. A wrong generated page is fixed in
224
+ the egress or in the documentation generation settings in klok.dev.
185
225
 
186
226
  ### Before the merge request
187
227
 
188
228
  1. Update the repository's `klok-docs/` in the same merge request as the change — ideally in the same commit as
189
229
  the code it describes. Documentation that is promised for a later merge request is documentation that never
190
230
  arrives, and a final "docs" commit at the end of a branch is the same promise wearing a hat.
191
- 2. Ask what a reader of the platform documentation would now find wrong: a renamed command, a new rule, a changed
231
+ 2. Run `klok docs build` where a znai CLI is at hand (the Klok build image has one; `--znai <path>` points at
232
+ another). It builds `klok-docs/` with znai the way the repository's documentation project will, so a page znai
233
+ cannot parse fails now instead of stopping the documentation project from publishing after the merge, where
234
+ nobody in this repository sees it.
235
+ 3. Ask what a reader of the platform documentation would now find wrong: a renamed command, a new rule, a changed
192
236
  default, a workflow with one more step. Read the affected pages (`https://docs.klok.dev/<doc-id>/llm.txt`)
193
237
  instead of guessing what they say.
194
- 3. Correct what you can judge yourself. A central page that is now plainly wrong is fixed in its own small merge
238
+ 4. Correct what you can judge yourself. A central page that is now plainly wrong is fixed in its own small merge
195
239
  request against that documentation project, linked from the change. What you cannot judge is written down
196
240
  rather than dropped.
197
- 4. Write the merge request description for two readers: the reviewer, and the documentation flow that runs after
198
- the merge. State what changed, why, and which documentation it affects or might affect. A description that
241
+ 5. Write the merge request description for the reviewer: state what changed, why, and which documentation it
242
+ affects or might affect. A description that
199
243
  says only "fixes the build" produces no documentation update.
200
244
 
201
245
  ### After the merge
@@ -8,11 +8,31 @@ description: Create or change a Klok datamodel (XSD first, generated Java, publi
8
8
  Read https://docs.klok.dev/klok-framework-klok-common/llm.txt (naming) and
9
9
  https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt (datamodel pipeline).
10
10
 
11
+ ## Choosing the class
12
+
13
+ Every datamodel is one of four classes (decided 2026-09-29; the reasoning is in
14
+ https://docs.klok.dev/klok-integration-strategy-and-tactics/platform-2-0/datamodel-classes/). All four may be sent
15
+ over the broker; the class sets how widely the model is shared and how strict its stability is.
16
+
17
+ | Class | Repository | Schema | A breaking change |
18
+ |---|---|---|---|
19
+ | A, public | `<tenant>/datamodel/public/<name>-v<n>` | XSD | the strictest: every reader notified; the old version runs at least 12 months after the notice |
20
+ | B, common | `<tenant>/datamodel/common/<name>-v<n>` | XSD | coordinated across the tenant's domains; the old version runs at least 3 months |
21
+ | C, domain | `<tenant>/datamodel/domain/<d>/<name>-v<n>` | XSD | decided within the domain; no fixed minimum |
22
+ | X, system | `<tenant>/datamodel/system/<s>/<name>-v<n>`, **or** plain Java classes in the integration's own source | XSD not required | follows the external system; no fixed minimum |
23
+
24
+ A class X model mirrors one external system's format. It does not need an XSD: simple Java classes in the
25
+ integration, explained in the source, are enough, and the steps below do not apply to them. Give it a repository
26
+ with an XSD when more than one integration or a service in another language needs it. Data that other systems or
27
+ domains read should still travel as class B or C (transform at the edge).
28
+
11
29
  ## Creating or changing a model
12
30
 
13
31
  1. The model lives in its own repository `<tenant>/datamodel/<common|public|domain/<d>|system/<s>>/<name>-v<n>`,
14
- where the repository name is the model name in kebab case (`supplier-invoice-v1`); the XSD file inside keeps
15
- the PascalCase form (`SupplierInvoice_v1.xsd`).
32
+ where the repository name is the model name in kebab case (`supplier-invoice-v1`). The XSD file has the same
33
+ name (`supplier-invoice-v1.xsd`), and so do the Maven artifact and the npm and Python packages; the Java package
34
+ ends in `supplier_invoice_v1`. Inside the XSD the model keeps its PascalCase form: root element
35
+ `SupplierInvoice_v1`, root type `SupplierInvoiceV1`.
16
36
 
17
37
  **Create it through klok.dev, or through the agent at https://agent.klok.dev** authenticated as the tenant
18
38
  with the right to create projects in the domain. That is the supported path: it creates the repository from
@@ -35,17 +55,21 @@ https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt (datamodel pip
35
55
  3. `meta.json` in the flat form with `targetNamespace`, and `klok-docs/` with the purpose, the important fields and
36
56
  the producers and consumers.
37
57
  4. A breaking change is a new major version (`Customer_v2`), which is a new class, a new topic and a new catalog
38
- key; a compatible change (optional field) stays in the same version.
58
+ key; a compatible change (optional field) stays in the same version. The old and the new version run in
59
+ parallel while readers move, at least the class's minimum (table above) and until every known reader
60
+ has moved.
39
61
  5. Work in the task worktree (`klok-worktree` skill), push its `agent/<task-id>` branch, open a merge request;
40
62
  the pipeline validates the XSD and generates the Java project. On `main` it
41
- publishes `dev.klok.<tenant>.datamodel:<name>-v<n>:1.0.0-build.<ts>` and writes `<nameVn>` (for example
42
- `klokOdlV1`) into the dependency catalog.
63
+ publishes `dev.klok.<tenant>.datamodel:<name>-v<n>:1.0.0-build.<ts>` with its Python and TypeScript packages,
64
+ writes `<nameVn>` (for example `klokOdlV1`) into the dependency catalog, and publishes the documentation payload
65
+ that becomes `<tenant>/documentation/datamodel/<same path>` on docs.klok.dev.
43
66
 
44
67
  ## Using a model in a project
45
68
 
46
69
  * Run `./gradlew updateKlokLibsToml` in the consumer, commit the refreshed `gradle/klok-libs.versions.toml`, and
47
70
  reference the alias (`klokLibs.klokOdlV1` or the bundle). Never type a version.
48
- * The generated class is `dev.klok.<tenant>.datamodel.<group>.<name>_v<n>.<Name>Vn`; the ODL type of an object is
49
- the fully qualified class name.
71
+ * The generated class is `dev.klok.<tenant>.datamodel.<group>.<name_with_underscores>_v<n>.<Name>Vn` (for
72
+ `klok-task-event-v1`: `dev.klok.klok.datamodel.common.klok_task_event_v1.KlokTaskStatusEventV1`); the ODL type of an object is the
73
+ fully qualified class name, so moving a class to another package is a data migration of its ODL index.
50
74
  * The topic for the model is derived from the class (`persistent://<tenant>[_<env>]/<domain>/<Name>Vn`); do not
51
75
  invent topic strings.
@@ -30,7 +30,7 @@ drops the `klok-` prefix of the name (`klok-integration-strategy-and-tactics`).
30
30
  | Naming conventions, `klok-*` properties, CloudEvents attributes | `klok-framework-klok-common` |
31
31
  | Broker client configuration, subscriptions, request/reply | `klok-framework-klok-brokerclient-java` |
32
32
  | Gradle plugin, versions, catalog refresh | `klok-framework-klok-gradle-plugin` |
33
- | CI templates, release process, Vault roles, docs sync, catalog update | `klok-environment-build-ci-templates` |
33
+ | CI templates, release process, Vault roles, documentation chain, catalog update | `klok-environment-build-ci-templates` |
34
34
  | ODL REST and request/reply, tasks API | `klok-integration-klok-api-opensearch` |
35
35
  | ODL writers, log receivers | `klok-integration-klok-egress-opensearch` |
36
36
  | Scheduled queries, stale task detection | `klok-integration-klok-ingress-opensearch` |
@@ -35,5 +35,9 @@ Read https://docs.klok.dev/klok-framework-klok-quarkus-extension/llm.txt first (
35
35
 
36
36
  * A route id that does not start with the solution id, or two routes with the same id.
37
37
  * Publishing to a hand written topic string; use the resolver and the datamodel.
38
+ * Choosing a tenant, index, repository or account from a field in the message; the topic decides the tenant.
39
+ * Sharing broker credentials between services, or granting a whole namespace of another domain or tenant.
40
+ * Publishing into another tenant's namespace, with `<RouteId>.topic.tenant-override` or otherwise; a route consumes
41
+ another tenant's topic with the override and a `consume` grant, and publishes only in its own tenant.
38
42
  * Catching exceptions to return HTTP 200 with an error text.
39
43
  * Pinning a framework or datamodel version in `gradle/klok-libs.versions.toml` by hand.