@klok-integration/cli 0.3.4 → 0.5.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
@@ -22,8 +22,12 @@ klok # opens the terminal UI
22
22
 
23
23
  Configuration lives in `~/.config/klok/config.json`. Every value can be overridden by an environment
24
24
  variable: `KLOK_AGENT_URL`, `KLOK_TENANT`, `KLOK_DOMAIN`, `KLOK_DEV_URL`, `KLOK_KEYCLOAK_ISSUER`,
25
- `KLOK_KEYCLOAK_CLIENT_ID`, `KLOK_GIT_URL`, `KLOK_GIT_LOCAL_WORKSPACE`. Run `klok config list` to see
26
- what is set and where it comes from.
25
+ `KLOK_KEYCLOAK_CLIENT_ID`, `KLOK_GIT_URL`, `KLOK_GIT_LOCAL_WORKSPACE`, `KLOK_GIT_APIKEY`. Run
26
+ `klok config list` to see what is set and where it comes from.
27
+
28
+ The GitLab token can be stored with `klok config set klokApiKey` (a hidden prompt, so it stays out of the shell
29
+ history). It is shown as `****` everywhere unless you run `klok config get klokApiKey --reveal`, and the file
30
+ is kept at mode 0600.
27
31
 
28
32
  Credentials are written to `~/.config/klok/credentials.json` with mode 0600.
29
33
 
@@ -40,9 +44,14 @@ Credentials are written to `~/.config/klok/credentials.json` with mode 0600.
40
44
  | `klok agent tasks`, `klok agent open <taskId>`, `klok agent cancel <taskId>` | Work with tasks. |
41
45
  | `klok agent answer <taskId> --question <qid> --text "..."` | Answer a clarification and continue. |
42
46
  | `klok agent serve [--port 3091]` | Loopback MCP and A2A proxy for IDEs and other agents. |
43
- | `klok agents init` | Write the Klok agent instructions and skills into a repository. |
47
+ | `klok agents init` | Write the Klok agent instructions, the platform skills and your tenant's skills into a repository, with a Claude Code hook that keeps them fresh. |
48
+ | `klok agents update [--check] [--global]` | Fetch what moved in the platform and tenant catalogs; `--check` exits 5 when something is outdated. |
49
+ | `klok agents status` | Per file and per catalog: current, outdated, missing or unreachable. |
44
50
  | `klok bead list\|show\|report` | Progress beads in the current repository. |
51
+ | `klok docs read <doc-id>` | Print a documentation project's `llm.txt` from docs.klok.dev, read with your GitLab token and cached. |
52
+ | `klok docs id [path]` | The doc id of a repository path. |
45
53
  | `klok docs publish` | Build this repository's znai documentation and upload it to the docs portal. |
54
+ | `klok docs build` | Build this repository's `klok-docs/` with znai the way its documentation project will, uploading nothing. |
46
55
  | `klok solutions validate` | Check the descriptors of an integration solution registry against the descriptor contract. |
47
56
  | `klok ci env` | Show what klok-cli detected about the CI job it runs in. |
48
57
  | `klok manifest update` | Set a container's image in a deploy manifest of your GitOps repository, then commit and push. |
@@ -100,7 +109,12 @@ Cursor (`.cursor/mcp.json`):
100
109
  Klok skills. `KLOK-AGENTS.md`, the klok rule files and the `klok-*` skills belong to Klok and are
101
110
  replaced wholesale; every other file keeps its content and only has its single row created or replaced,
102
111
  so an update can never duplicate text. Klok skills the CLI no longer ships are removed.
103
- `klok agents status` shows whether a repository is up to date with the CLI version you have installed.
112
+ Your tenant's skills (`<tenant>-context` and one skill per documented repository) come from the tenant's private
113
+ catalog with your GitLab token (`KLOK_GIT_APIKEY`); they are installed, kept out of git, and refreshed by
114
+ `klok agents update`. `klok agents status` shows whether a repository is up to date with the catalogs.
115
+ After you install or update the CLI, the first interactive run tells you when the instructions you installed
116
+ with `klok agents init --global` or `--workspace` are older than the CLI, and prints the commands that update
117
+ them.
104
118
 
105
119
  ## Licence and support
106
120
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Klok application (portal, docs portal, agent service or another container) that is built and deployed with the
4
4
  platform pipelines: image to `repo.klok.dev`, deployment manifest in the manifests repository, secrets through
5
- Vault. Read https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt for the release process and the
5
+ Vault. Read `klok docs read klok-environment-build-ci-templates` for the release process and the
6
6
  repository's own `README.md` and `docs/` for its architecture.
7
7
 
8
8
  ### Rules
@@ -2,8 +2,8 @@
2
2
 
3
3
  A Klok datamodel: an XSD (or JSON schema) under `schema-definition-xsd/`, converted by the pipeline to Avro and to
4
4
  a generated Java project that is published as `dev.klok.<tenant>.datamodel:<name>-v<n>` and written into the
5
- dependency catalog. Read https://docs.klok.dev/klok-framework-klok-common/llm.txt for naming and
6
- https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt for the pipeline.
5
+ dependency catalog. Read `klok docs read klok-framework-klok-common` for naming and
6
+ `klok docs read klok-environment-build-ci-templates` for the pipeline.
7
7
 
8
8
  ### Rules
9
9
 
@@ -19,7 +19,11 @@ https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt for the pipeli
19
19
  documentation.
20
20
  * Consumers reference the artifact only through the catalog alias (`klokLibs.<key>`), never by literal version.
21
21
  * Datamodel documentation lives in `klok-docs/` (purpose, fields that need explanation, producers and consumers,
22
- design decisions). Datamodel projects publish no documentation payload yet, because the datamodel template runs
23
- no Klok Gradle task, so these pages do not reach docs.klok.dev until it does; write them anyway.
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.
24
28
  * On `main` the pipeline publishes and updates the catalog; check it, then refresh consumers with
25
29
  `./gradlew updateKlokLibsToml`.
@@ -1,7 +1,7 @@
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 (documentation from a source repository) for how
4
+ `klok docs read klok-environment-build-ci-templates` (documentation from a source repository) for how
5
5
  content arrives here. There are two kinds, and they are edited differently:
6
6
 
7
7
  * **The documentation project of a source repository** (`<tenant>/documentation/<group>/.../<repo>`, mirroring the
@@ -2,7 +2,7 @@
2
2
 
3
3
  Part of the Klok framework (klok-common, the broker client, the Quarkus extension, the gradle plugin or the CI
4
4
  templates). Changes here reach every tenant, so read the library's `klok-docs/` and its published documentation
5
- (`https://docs.klok.dev/klok-framework-<repo>/llm.txt`) before changing behaviour.
5
+ (`klok docs read klok-framework-<repo>`) before changing behaviour.
6
6
 
7
7
  ### Rules
8
8
 
@@ -3,7 +3,7 @@
3
3
  A Klok integration on the Quarkus extension 2.0: one Camel route per class, each extending a framework pattern
4
4
  (`KlokOnrampRoute`, `KlokProcessingRoute`, `KlokOfframpRoute`, their `Sync` variants, `KlokRestApi` and
5
5
  `KlokRestApiHandlerRoute`, `KlokAsyncTaskWorkerRoute`, `KlokCustomRoute`) and implementing the capabilities it
6
- needs. Read https://docs.klok.dev/klok-framework-klok-quarkus-extension/llm.txt before writing a route.
6
+ needs. Read `klok docs read klok-framework-klok-quarkus-extension` before writing a route.
7
7
 
8
8
  ### Commands
9
9
 
@@ -20,6 +20,10 @@ needs. Read https://docs.klok.dev/klok-framework-klok-quarkus-extension/llm.txt
20
20
  Configuration keys are `<RouteId>.<key>` with fallback to `<SolutionId>.<key>` and `klok.route-defaults.<key>`.
21
21
  * Datamodels are the type parameters of the pattern class and come from the catalog bundles; never hand write DTOs
22
22
  for something a datamodel project should own.
23
+ * A datamodel used in more than one flow gets a **topic purpose** per flow (`<Model>_<purpose>`, set with
24
+ `topicPurpose()` or `<RouteId>.topic.purpose`), agreed with the project on the other end and written in both
25
+ projects' `klok-docs/`. Never consume a shared topic and discard the other flows' messages. The `klok-route` skill
26
+ has the details.
23
27
  * Errors: throw `Klok4XXException` for caller errors (no retry) and `Klok5XXException` or plain exceptions for
24
28
  retryable failures; the framework retries, republishes to `_DLQ` and emits the failure event. Do not add
25
29
  `onException` blocks unless the route owns the failure (`failureHandled()`).
@@ -27,6 +31,14 @@ needs. Read https://docs.klok.dev/klok-framework-klok-quarkus-extension/llm.txt
27
31
  (`KlokTaskInitiation`, `KlokAsyncTaskWorkerRoute`).
28
32
  * Tests: `@QuarkusTest` with the recording broker client factory; assert routes started and published messages,
29
33
  never talk to a real broker or OpenSearch in unit tests.
34
+ * A route that serves several tenants (a shared platform service) consumes each tenant's own request topic,
35
+ `<tenant>[_<env>]/common/<Model>`, from the subscription list klok.dev keeps in the klok ODL; it takes the tenant
36
+ from the namespace it received on and rejects a message whose payload or properties name another tenant. It never
37
+ picks an index, repository or account from a field in the message, and what it writes back for a tenant goes to
38
+ klok's namespace, one topic per tenant.
39
+ * The service connects to the broker with a client of its own (`KLOK_BROKER_AUTH_CLIENT_ID`), granted `publish` and
40
+ `consume` on its own tenant's namespaces only; a topic of another tenant is a `consume` grant on that one topic,
41
+ reached with `<RouteId>.topic.tenant-override`. Never reuse another service's credentials.
30
42
  * `application.properties` keeps every `klok.*` key explicit; secrets come from environment variables that the
31
43
  Vault env secret provides in Kubernetes (`KLOK_BROKER_AUTH_CLIENT_ID`, ...).
32
44
  * Update `klok-docs/` (overview, design decisions, routes, operations) in the same merge request as the change.
@@ -8,23 +8,81 @@ otherwise yours. Do not copy rules into them.
8
8
 
9
9
  ## Read the documentation before guessing
10
10
 
11
- The platform documentation is published at https://docs.klok.dev. Every documentation project exposes its full
12
- content as one markdown file at `https://docs.klok.dev/<doc-id>/llm.txt`; fetch it instead of relying on memory.
11
+ Before anything else, run `klok agents update --check`. Exit 5 means the installed skills are behind a catalog:
12
+ run `klok agents update` and read the refreshed files. Exit 0 means they are current, and any other code names
13
+ what went wrong (no token, no network); say so instead of guessing.
14
+
15
+ The platform documentation is published at https://docs.klok.dev, one documentation project per repository, each
16
+ exposing its whole content as one markdown file. Read it with klok-cli, which sends your GitLab token and caches
17
+ the answer:
18
+
19
+ ```
20
+ klok docs read <doc-id> # the markdown on stdout, one status line on stderr; --json adds fetchedAt
21
+ klok docs id [tenant/group/.../repo] # the doc id of a repository, this one by default
22
+ ```
13
23
 
14
24
  | Topic | Read |
15
25
  |---|---|
16
- | Platform principles, event driven design, naming, onboarding | https://docs.klok.dev/klok-integration-strategy-and-tactics/llm.txt |
17
- | Route framework (patterns, config, logging, errors, topics, tasks) | https://docs.klok.dev/klok-framework-klok-quarkus-extension/llm.txt |
18
- | Naming conventions, message properties, CloudEvents | https://docs.klok.dev/klok-framework-klok-common/llm.txt |
19
- | Broker client | https://docs.klok.dev/klok-framework-klok-brokerclient-java/llm.txt |
20
- | Gradle plugin, versions, catalog | https://docs.klok.dev/klok-framework-klok-gradle-plugin/llm.txt |
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 |
25
-
26
- A 404 means the documentation project is not published yet; read the repository's `klok-docs/` folder instead.
27
- The `klok-docs` skill describes the lookup in detail.
26
+ | Platform principles, event driven design, naming, onboarding | `klok docs read klok-integration-strategy-and-tactics` |
27
+ | Route framework (patterns, config, logging, errors, topics, tasks) | `klok docs read klok-framework-klok-quarkus-extension` |
28
+ | Naming conventions, message properties, CloudEvents | `klok docs read klok-framework-klok-common` |
29
+ | Broker client | `klok docs read klok-framework-klok-brokerclient-java` |
30
+ | Gradle plugin, versions, catalog | `klok docs read klok-framework-klok-gradle-plugin` |
31
+ | CI templates, release process, Vault roles | `klok docs read klok-environment-build-ci-templates` |
32
+ | Developer rules: identity and access, Keycloak, Vault paths, certificates, infrastructure as code | `klok docs read klok-framework-development-guide` |
33
+ | How people use the platform: concepts, roles and access, workflow, operations | `klok docs read klok-user-guide` |
34
+ | Infrastructure: stateful services, certificates, Ansible, Keycloak clients | `klok docs read klok-environment-klok-environment-setup` |
35
+
36
+ What the answers mean:
37
+
38
+ * **404**: the project is not published yet. Its hand written pages are in the repository's `klok-docs/` on
39
+ `main`, the source of the same site: `git -C <repo> fetch origin && git show origin/main:klok-docs/<page>.md`
40
+ (`toc-manifest.json` lists the pages). Read them there; nothing else is a substitute.
41
+ * **401 or 403** (no token, or your GitLab account is not a member of the tenant or domain): say so and ask for a
42
+ token or for access. Never guess what the page says, and never try another way in.
43
+
44
+ The `klok-docs` skill describes the lookup in detail. Cite the doc id you relied on, and the `fetchedAt` from
45
+ `klok docs read --json`, in your answer or merge request description.
46
+
47
+ ## Tenant skills
48
+
49
+ Next to the platform skills (`klok-docs`, `klok-route`, `klok-datamodel`, `klok-release`, `klok-worktree`) the
50
+ skill directories hold your tenant's own skills, generated by KlokDocumentationEgress from every documentation
51
+ publish in the tenant and served from the tenant's private catalog:
52
+
53
+ * `<tenant>-context` is the router: what exists in the tenant (repositories, systems, datamodels, topics,
54
+ solutions), where it lives, and which skill to open for it. Start there. Its `data/` holds `projects.jsonl`,
55
+ `routes.jsonl`, `datamodels.jsonl`, `topics.jsonl` and `solutions.jsonl`.
56
+ * `<tenant>-<group>-…-<repo>` is one skill per documented repository (the name is its doc id): what the project
57
+ does, its routes, datamodels, topics, solution and configuration keys, with every fact as one JSON row in
58
+ `data/facts.jsonl` (`kind` first: `project`, `route`, `topic`, `datamodel`, `solution`, `config-key`, `doc-page`,
59
+ `component`).
60
+ * Search the facts instead of reading everything: `grep -i <term> .claude/skills/<skill>/data/facts.jsonl`, or
61
+ `jq -c 'select(.kind=="route")' .claude/skills/<skill>/data/facts.jsonl` (`.agents/skills/` for Codex, OpenCode
62
+ and Antigravity).
63
+ * They are installed, never committed: `klok agents update` refreshes them from the catalog and keeps them out of
64
+ git through `info/exclude`. Never edit them; a wrong fact is fixed in the repository's `klok-docs/` or code, and
65
+ the next documentation publish regenerates the skill.
66
+
67
+ ## Klok knowledge
68
+
69
+ The folder `knowledge/` next to this file holds the platform knowledge that Klok's models and agents share. Read
70
+ it when a task touches the platform:
71
+
72
+ | File | Holds |
73
+ |---|---|
74
+ | `knowledge/platform-rules.md` | the current platform rules: principles, naming, route ids and legs, topics, datamodel classes, write narrow and consume wide, claim check, tasks, the ODL |
75
+ | `knowledge/glossary.md` | the Klok terms and what they mean |
76
+ | `knowledge/kloker-identity.md` | Kloker's identity and writing style |
77
+ | `knowledge/roles/` | the role handbooks of the Kloker role models |
78
+ | `knowledge/retired-patterns.txt` | conventions the platform no longer has, one pattern per line with the reason |
79
+
80
+ * Klok knowledge is edited **only** in klok-integration-agent, `packages/cli/assets/agents/knowledge/`. Every other
81
+ copy is generated and never edited: `knowledge/` next to an installed `KLOK-AGENTS.md`, the catalog's
82
+ `agents/knowledge/`, `build/generated/klok-knowledge/`, `generated/klok-knowledge/` and the copies in images.
83
+ * A prompt, persona or agent instruction that needs the glossary or the platform rules loads the knowledge block.
84
+ It never restates it.
85
+ * Text that matches a line of `retired-patterns.txt` teaches a rule the platform no longer has; fix it at its source.
28
86
 
29
87
  ## Git is the truth, everything must work by hand
30
88
 
@@ -106,7 +164,7 @@ step by step procedure; the contract every agent follows is:
106
164
  layers, no layer cache, push from `main` only. Never use or propose a privileged runner, `docker:dind`, or a
107
165
  relaxed seccomp or AppArmor profile. A Dockerfile copies dependencies, assets and application code as separate
108
166
  `COPY` layers and sets owners with `COPY --chown`, never `RUN chown -R`, so that a build stores only what
109
- changed. Read the *Container images* page of https://docs.klok.dev/klok-environment-build-ci-templates/llm.txt
167
+ changed. Read the *Container images* page of `klok docs read klok-environment-build-ci-templates`
110
168
  before changing a Dockerfile or an image job.
111
169
  * Vault (`vault.ipaas.se`) is changed by a human only. Agents may read to diagnose and must then propose the exact
112
170
  command, including every existing field of the object.
@@ -121,6 +179,14 @@ step by step procedure; the contract every agent follows is:
121
179
  * Never push to `main` of an existing repository, never force push, never merge. Work on a branch and open a
122
180
  merge request that is ready for review; only a brand new repository gets its first commit on `main`. A draft
123
181
  merge request is not the default, it is what you open when the work is knowingly unfinished, and you say why.
182
+ * **Never cancel a running job without a human's yes.** Cancelling, stopping, killing, deleting or force-restarting
183
+ anything that runs is never done on an agent's own judgement: a CI job or pipeline, a release, a deployment
184
+ rollout, a pod, a container, a broker consumer, a scheduled task. Describe what you see (job id, how long it has
185
+ run by the current time from `date -u`, never an assumed time, the last log lines with their timestamps, what
186
+ waits behind it), say what you propose and what it would break, and wait for an explicit yes. "It looks hung",
187
+ "it blocks the `main` lane" and "it can be retried" are reasons to ask at once, not to act: a release that waits
188
+ for Maven Central or npm can legitimately take half an hour. On 2026-09-29 an agent cancelled the Gradle
189
+ plugin's release while it correctly waited for Maven Central, because it misread the time.
124
190
 
125
191
  ## Logic lives in the Klok tools, not in the pipelines
126
192
 
@@ -146,12 +212,44 @@ step by step procedure; the contract every agent follows is:
146
212
  and the solution key.
147
213
  * Topics: `persistent://<tenant>[_<env>]/<domain>/<Model>[_<purpose>]`, request/reply
148
214
  `ReqRes_<Req>_<Res>_Request|_Response`, dead letters `<topic>_DLQ`. The datamodel major version is in the class
149
- name (`CustomerV1`).
215
+ name (`CustomerV1`). The purpose is a flow that producer and consumer agree on, so one datamodel serves several
216
+ flows and each consumer reads only its own; it never contains `_`.
150
217
  * Context properties: `klok-correlation-id`, `klok-invocation-id`, `klok-parent-invocation-id`, `klok-task-id`,
151
218
  `klok-solution-id`, `klok-route-id`, `klok-tenant`, `klok-domain`, `klok-environment`; same spelling as HTTP
152
219
  header, Pulsar property and CloudEvents extension, `klok.`-prefixed as MDC key.
153
220
  * Repositories: `<tenant>/integration/domain/<d>/<repo>`, `<tenant>/datamodel/...`, mirrored documentation under
154
221
  `<tenant>/documentation/...`; documentation ids are `slug(<tenant>-<group>-...-<repo>)`.
222
+ * Permission words, one meaning each: *ingress/egress* says what a service is and is never a permission; broker
223
+ rights are `publish` and `consume` (Pulsar's own `produce`/`consume` only inside a grant command); `read` and
224
+ `ingest` belong to klok.dev's integration context graph and never to the broker.
225
+
226
+ ## Broker access and tenant isolation
227
+
228
+ Read the *Broker Access And Tenant Isolation* page of
229
+ `klok docs read klok-framework-development-guide` before designing anything that touches broker
230
+ access, Keycloak broker clients or a service that serves several tenants.
231
+
232
+ * **The topic decides the tenant, never the message.** Pulsar does not tell a consumer who published; a `tenant`
233
+ field or property can be forged by any client allowed on the topic. A service takes the tenant from the topic
234
+ name and rejects a payload that claims another one.
235
+ * **Write narrow, consume wide.** A tenant publishes only in its own namespace, `<tenant>[_<env>]/<domain>`; nobody
236
+ holds `publish` in another tenant's namespace, not even on one topic. Reading elsewhere is a `consume` grant on a
237
+ named topic, approved by the owner and recorded in Git in the owning tenant. A topic read across tenants carries
238
+ its reader as the last purpose segment (`persistent://konvoj/hr/PersonnelScheduleExportV1_degerfors`).
239
+ * **Platform services** (logs, the ODL, AI, mail, SMS, documentation) are shared klok workers that follow the same
240
+ rule: a tenant's requests live in the tenant's namespace (`persistent://<tenant>[_<env>]/common/KlokLogEventV5`)
241
+ and the worker is granted `consume` on exactly those topics, taking the tenant from the namespace; what the
242
+ platform writes back lives in klok's namespace, one topic per tenant (`klok[_<env>]/<domain>/<Model>_<tenant>`).
243
+ The worker subscribes to a list of topics kept in the klok ODL, never to a pattern. The ODL runs as one instance
244
+ per tenant.
245
+ * **Identities:** one Keycloak client per running deployment, never shared, never used by a person; its Pulsar role
246
+ is `service-account-<client id>`; one CI broker client per tenant; every broker client attaches the client scope
247
+ `pulsar` (audience and the `nbf` claim Pulsar requires) instead of copying mappers.
248
+ * **Grants:** `publish` and `consume` on the service's own domain and its tenant's `common`, as namespace grants;
249
+ anything in another domain or tenant is `consume` on one topic, never `publish`, approved by its owner and
250
+ recorded in Git in the owning tenant. Pulsar's `produce`/`consume` appear only inside a grant command.
251
+ * **Who applies it:** Ansible (`klok/environment/klok-environment-setup`) for the platform and tenant klok's
252
+ services, klok.dev for tenant projects. A grant made only in the broker's admin API is drift.
155
253
 
156
254
  ## Documentation is part of every change
157
255
 
@@ -159,7 +257,7 @@ Klok documentation has three levels, and a change is finished only when all thre
159
257
 
160
258
  * **The repository's own `klok-docs/`** (znai markdown, `toc-manifest.json`). On every `main` pipeline
161
259
  `./gradlew publishKlokDocs` publishes it, together with the scan of the code, as `KlokProjectDocumentationV1` on
162
- `persistent://klok[_<env>]/common/KlokProjectDocumentationV1_prepared`. KlokDocumentationEgress
260
+ `persistent://<tenant>[_<env>]/common/KlokProjectDocumentationV1_prepared`. KlokDocumentationEgress
163
261
  (`klok/integration/klok-documentation-egress`, KLK007) builds the repository's documentation project from it. That
164
262
  documentation project is output, and nobody edits it. There are two places to change a project's documentation:
165
263
  `klok-docs/` in the source repository (including the `KLOK:GENERATED` markers that place AI sections in a page),
@@ -192,18 +290,31 @@ Klok documentation has three levels, and a change is finished only when all thre
192
290
  sections that fill `KLOK:GENERATED` regions. They are never edited by hand. A wrong generated page is fixed in
193
291
  the egress or in the documentation generation settings in klok.dev.
194
292
 
293
+ **Prompts and agent instructions carry the same knowledge.** System prompts, section prompts, personas, tool
294
+ descriptions, these agent instructions and the skills teach platform rules to a model, and they load the shared
295
+ blocks from *Klok knowledge* above instead of restating them. The *Prompt Catalogue* in
296
+ the framework development guide (`klok docs read klok-framework-development-guide`) lists every place.
297
+ A change to a platform rule, the strategy, naming, the datamodel classes or the glossary checks the catalogue. It
298
+ updates every prompt that restates the change, or files an issue in the owning repository for each one it leaves. A
299
+ new prompt, persona, tool description or agent instruction is added to the catalogue in the same merge request.
300
+ Prompts never carry `/think` or `/no_think` tokens; the model name (`Kloker-nothink`, `Kloker`) is the only switch.
301
+
195
302
  ### Before the merge request
196
303
 
197
304
  1. Update the repository's `klok-docs/` in the same merge request as the change — ideally in the same commit as
198
305
  the code it describes. Documentation that is promised for a later merge request is documentation that never
199
306
  arrives, and a final "docs" commit at the end of a branch is the same promise wearing a hat.
200
- 2. Ask what a reader of the platform documentation would now find wrong: a renamed command, a new rule, a changed
201
- default, a workflow with one more step. Read the affected pages (`https://docs.klok.dev/<doc-id>/llm.txt`)
307
+ 2. Run `klok docs build` where a znai CLI is at hand (the Klok build image has one; `--znai <path>` points at
308
+ another). It builds `klok-docs/` with znai the way the repository's documentation project will, so a page znai
309
+ cannot parse fails now instead of stopping the documentation project from publishing after the merge, where
310
+ nobody in this repository sees it.
311
+ 3. Ask what a reader of the platform documentation would now find wrong: a renamed command, a new rule, a changed
312
+ default, a workflow with one more step. Read the affected pages (`klok docs read <doc-id>`)
202
313
  instead of guessing what they say.
203
- 3. Correct what you can judge yourself. A central page that is now plainly wrong is fixed in its own small merge
314
+ 4. Correct what you can judge yourself. A central page that is now plainly wrong is fixed in its own small merge
204
315
  request against that documentation project, linked from the change. What you cannot judge is written down
205
316
  rather than dropped.
206
- 4. Write the merge request description for the reviewer: state what changed, why, and which documentation it
317
+ 5. Write the merge request description for the reviewer: state what changed, why, and which documentation it
207
318
  affects or might affect. A description that
208
319
  says only "fixes the build" produces no documentation update.
209
320
 
@@ -0,0 +1,77 @@
1
+ # Klok knowledge
2
+
3
+ This folder is the single source of the platform knowledge that Klok teaches its models and agents: the glossary,
4
+ the platform rules, Kloker's identity and writing style, the role handbooks, and the list of retired conventions.
5
+ Every system prompt, agent instruction and tool that needs this knowledge loads these files. None of them keeps a
6
+ text of its own.
7
+
8
+ ## Edit only here
9
+
10
+ * Klok knowledge is edited **only** in klok-integration-agent, `packages/cli/assets/agents/knowledge/`, through a
11
+ merge request like any other change.
12
+ * Everything else is a generated copy and is never edited: `knowledge/` next to an installed `KLOK-AGENTS.md`, the
13
+ catalog's `agents/knowledge/` and `klok-agents.zip`, `build/generated/klok-knowledge/` in a Java build,
14
+ `generated/klok-knowledge/` in klok.dev, and the copies inside images. A wrong copy is fixed here and refreshed.
15
+ * A prompt that needs the glossary or the platform rules loads the block. It never restates it, and it never
16
+ paraphrases a rule "to keep the prompt short".
17
+ * A change here is also a prompt change: check the *Prompt Catalogue* in the framework development guide
18
+ (`klok docs read klok-framework-development-guide`) and update it in the same piece of work.
19
+
20
+ ## The files
21
+
22
+ | File | What it is | Composed into |
23
+ |---|---|---|
24
+ | `glossary.md` | the Klok terms and their meanings, with the rule never to guess a term | every Kloker prompt that explains or documents Klok, the documentation egress's sections |
25
+ | `platform-rules.md` | the current platform rules: principles, naming, route ids and legs, topics, datamodel classes, write narrow and consume wide, claim check, tasks, the ODL | the agent runner's doctrine, the role models, klok.dev's datamodel and planning helpers |
26
+ | `kloker-identity.md` | who Kloker is, and the Unslop writing style | every request to the models `Kloker` and `Kloker-nothink` |
27
+ | `roles/integration-architect.md`, `roles/integration-developer.md` | only what is specific to the role; the rules come from `platform-rules.md` | the role models `Kloker-Integration-Architect` and `Kloker-Integration-Developer` |
28
+ | `retired-patterns.txt` | conventions the platform no longer has, one pattern per line with the reason | tests that fail when a prompt teaches a retired rule |
29
+
30
+ **Blocks.** A block is a Markdown file in this folder other than `README.md`. Its name is its path under
31
+ `knowledge/` without `.md`: `glossary`, `platform-rules`, `kloker-identity`, `roles/integration-architect`,
32
+ `roles/integration-developer`. The Gradle plugin lists the block names in the `blocks=` line of
33
+ `klok-knowledge.properties`, which the build-time loader reads. So keep file names lowercase with hyphens, end a
34
+ block in `.md`, put role handbooks in `roles/`, and do not rename a block without updating every consumer that loads
35
+ it by name. `README.md` and `retired-patterns.txt` are not blocks.
36
+
37
+ A role model's system prompt is composed in this order: `kloker-identity.md`, `platform-rules.md`, `glossary.md`,
38
+ the role file. Plain `Kloker` gets `kloker-identity.md` only; framework knowledge is opt-in through the role models.
39
+ A shared block is always appended by the service, never part of a text a tenant can override, so a tenant override
40
+ can add to the knowledge but not drop it.
41
+
42
+ ## Who loads it, and how
43
+
44
+ | Consumer | How it gets the files | When it reads them |
45
+ |---|---|---|
46
+ | Coding agents in a repository | `klok agents init` (the CLI's bundled copy) and `./gradlew updateKlokAgents` (catalog `main`) write `knowledge/` next to `KLOK-AGENTS.md`: byte for byte copies of every file here, without a marker, so both installers give identical results | the agent reads the files `KLOK-AGENTS.md` points to |
47
+ | Coding agents in a home folder | `klok agents init --global` writes `~/.klok/agents/knowledge/` | same |
48
+ | The agent runner (agent.klok.dev) | the image copies `packages/cli/assets/agents` to `/app/assets/agents` (`KLOK_RUNNER_AGENT_ASSETS_DIR`) | `platform-rules.md` once, on first use, as the doctrine of every task; bead-implementation also seeds `knowledge/` into the sandbox |
49
+ | The dependency catalog | the `update_klok_agents_catalog` job on `main` copies the whole asset tree to `agents/knowledge/` and into `klok-agents.zip` | — |
50
+ | Java services: the Kloker gateway (klok-api-ai), klok-egress-ai, the documentation egress | planned: the Gradle plugin extracts `agents/knowledge/**` from the catalog into `build/generated/klok-knowledge/` on the classpath with a `klok-knowledge.properties` (catalog commit, `blocks=`), and `KlokKnowledge` in klok-common reads the blocks once at start | once, at start; never per request |
51
+ | klok.dev | planned: a prebuild step extracts the catalog's `agents/knowledge/**` into `generated/klok-knowledge/`, read once at module load | once, at start |
52
+
53
+ An installer replaces the files it ships wholesale and leaves any other file in the installed `knowledge/` alone. It
54
+ does not remove a file this folder no longer ships, so a renamed or retired block is deleted from an installed copy
55
+ by hand (or by the merge request that refreshes it).
56
+
57
+ No consumer fetches the knowledge at run time, and none reads a database for it, so an AI request costs no extra I/O.
58
+ Each build records the catalog commit it bundled.
59
+
60
+ ## How an update spreads
61
+
62
+ 1. A merge request changes a file here. Its pipeline runs the tests, including the check against
63
+ `retired-patterns.txt`.
64
+ 2. After the merge, the `main` pipeline copies the assets into the dependency catalog (`agents/knowledge/`,
65
+ `klok-agents.zip`).
66
+ 3. Consumers that build from the catalog pick up the new text on their next build. Starting those builds
67
+ automatically when this folder changes is planned (`klok knowledge propagate`).
68
+ 4. The agent runner gets it with its next image, which is built from the same commit.
69
+ 5. Developers get it with the next klok-cli release (`klok agents init`), or right away from the catalog with
70
+ `./gradlew updateKlokAgents`.
71
+
72
+ ## retired-patterns.txt
73
+
74
+ One pattern per line: a regular expression in the syntax JavaScript and Java share, then ` # ` and the reason. A
75
+ leading `(?i)` makes the pattern case-insensitive; blank lines and lines starting with `#` are comments. When a rule
76
+ is retired, add its old form here in the same merge request that changes `platform-rules.md`, so every consumer's
77
+ test catches a copy that still teaches it.
@@ -0,0 +1,26 @@
1
+ # Klok glossary
2
+
3
+ The sources you are given use Klok platform terms. Use these meanings, spell out an abbreviation only as written
4
+ here, and never guess the meaning of a Klok term that is neither in this list nor explained in the sources: write
5
+ it as the source does.
6
+
7
+ | Term | Meaning |
8
+ |---|---|
9
+ | Klok | The integration platform the documented project runs on (iPaaS): Camel routes on Quarkus, an Apache Pulsar broker, datamodels, and the portal klok.dev |
10
+ | ODL | Operative Data Layer: the platform's store for datamodel objects, keyed by the object's datamodel type and an id, per tenant; routes write, read and search it (backed by OpenSearch) |
11
+ | Claim check | A large payload stored in the platform's object storage; the message carries only a reference to it (a `klokcc://` URI) instead of the bytes |
12
+ | Broker, topic | Apache Pulsar. A topic is named `persistent://<tenant>[_<env>]/<domain>/<Model>[_<purpose>]` and carries CloudEvents whose data is a datamodel |
13
+ | CloudEvent | The standard envelope of every broker message: id, type, source, time, and the datamodel as data |
14
+ | DLQ | Dead letter queue: `<topic>_DLQ`, where a message goes after its retries are exhausted |
15
+ | Tenant | An organisation on the platform, and its security boundary; every topic, ODL object and GitLab group belongs to one tenant |
16
+ | Domain | A business area inside a tenant. `common` is shared by the tenant's domains, `public` is open to anyone |
17
+ | Route, route id | One Camel route per Java class. Its id is `<TENANTSHORT><NNN><LEG><seq>_<Description>`, for example `KLK007T1_PublishKlokStandard`; the class name is the id |
18
+ | Leg | The letter in a route id: I ingress (onramp, brings data in), P processing, E egress (offramp, delivers data out), A API, S sub route, T timer |
19
+ | Solution | The business flow a set of routes implements; its id is the route id's prefix, for example `KLK007` |
20
+ | Correlation id | `klok-correlation-id`: follows one business flow across routes and messages |
21
+ | Task | Long-running work tracked by the platform (`KlokTaskV1` events, visible in klok.dev and the task API), for example an `ai.chat` task that asks Kloker for text |
22
+ | Datamodel | A versioned data contract; the major version is in the name (`CustomerV1`). Classes: public (A), common (B) and domain (C) are XSD in a Git project of their own with generated Java, Python and TypeScript; system (X) models one external system and may be plain Java classes. All four classes may travel on the broker |
23
+ | Dependency catalog | The file that pins every Klok library and datamodel version (`klok-libs.versions.toml`) |
24
+ | Kloker | Klok's own AI model, reached through the platform's AI gateway |
25
+ | klok.dev | The platform's web portal: projects, tenants, settings, the ODL and tasks |
26
+ | klok-docs | The folder in every repository with its hand-written documentation, published to docs.klok.dev |