dev.klok.framework.common.knowledge.KlokKnowledge gives a Java service the shared Klok knowledge blocks: the glossary,
the platform rules, Kloker's identity and the role handbooks, so that a service composes system prompts without
restating the rules by hand. The Kloker gateway in klok-api-ai (KlokerSystemPrompts), klok-egress-ai and
klok-api-proxies (kloker-identity, for what they send to the model servers directly) and the documentation egress
(KlokGlossary) use it, and knowledge/consumers.json in klok-integration-agent lists who loads which block.
Where the blocks come from
The blocks are written once, in klok-integration-agent packages/cli/assets/agents/knowledge/. Edit them only there;
every other copy is generated.
-
The klok-integration-agent main pipeline copies assets/agents/ into the dependency catalog, as agents/ and
klok-agents.zip.
-
The Klok Gradle plugin task extractKlokKnowledge unpacks agents/knowledge/** from that zip into
build/generated/klok-knowledge/klok-knowledge/, a main resource directory, before processResources. A project asks
for it with the Gradle property klokKnowledge=true (or KLOK_KNOWLEDGE), and is listed in knowledge/consumers.json;
nothing else turns it on.
-
It also writes klok-knowledge/klok-knowledge.properties:
| Key | Meaning |
| --- | --- |
| commit | The dependency catalog commit that last changed the zip, as GitLab names it when the plugin fetches it (local for a local assets directory, unknown when the server names none). |
| fetchedAt | When the build fetched that zip, as an ISO-8601 instant. |
| blocks | The index: every .md block except README.md, comma separated, without .md. |
-
At run time KlokKnowledge reads the index and every listed block once, on first use, into an immutable map. After
that no call does any I/O, so a service may call it on every AI request.
API
| Method |
Returns |
get(name) |
The block's Markdown. Throws IllegalStateException naming the missing block and the fix (./gradlew extractKlokKnowledge). |
find(name) |
Optional of the block, for optional additions. |
names() |
Every bundled block name, in index order. |
commit() |
The catalog commit, local, or unknown when nothing was bundled. |
fetchedAt() |
When the zip was fetched, or unknown. |
logOnce() |
Logs Klok knowledge <commit> once per JVM (a warning when nothing was bundled) and returns the commit. |
A block is named by its path under knowledge/ without .md: glossary, platform-rules, kloker-identity,
roles/integration-architect. A trailing .md is accepted.
import dev.klok.framework.common.knowledge.KlokKnowledge;
String system = KlokKnowledge.get("kloker-identity") + "\n\n" + KlokKnowledge.get("platform-rules");
Call KlokKnowledge.logOnce() at start (the Quarkus extension or the service does it; this library has no Quarkus
dependency). It logs through System.Logger, which Quarkus routes to its log.
A build without knowledge
In CI the plugin's task fails the build of a project that asks for the knowledge and would run without it: no zip, a zip
without knowledge/, a project that consumers.json does not list, or a block listed for it that the zip does not
have. On a laptop the same findings are warnings and the build goes on with an empty directory. A service that only uses
find keeps working then; get fails with a message that says which block is missing and how to bundle it. A service
that cannot run without a block calls get at start, so that a jar built some other way does not start.
Tests
A service's own tests see the generated blocks, because they are main resources. A library test that needs its own
blocks puts klok-knowledge/klok-knowledge.properties (with blocks=) and the .md files under src/test/resources,
as this library's KlokKnowledgeTest does.