Repository navigation
Description
Part of #1057. This is the design-risk task in the epic; #1058 is the mechanical one.
The gap
chant infers structure. Types, props, dependency edges, ownership, which rules apply. It cannot infer intent: why a suppression exists, why two networks are peered, what to do when a component fails.
Intent has no home in a chant project today. It lives in code comments, in CLAUDE.md, or nowhere. That is awkward given chant's pitch is types plus semantic lint, because intent sits outside both.
The proposal is to let a project carry an OKF bundle that chant reads, making the format internals rather than an export target.
What reading a bundle would enable
- A lint suppression cites a concept, and
chant lintprints the authored reason alongside the rule id rather than the id alone. explainanddescribemerge inferred structure with authored intent in a single answer.graphrenders nodes carrying their concept links.- The MCP
contextresource (cli/mcp/resources/context.ts) serves both from one place.
The actual design question
How does a concept document bind to an entity? Candidates, none obviously right:
- Frontmatter key on the concept naming the logical name or resource type. Simple, but a bare logical name is ambiguous across multi-stack projects.
- Path convention, mirroring the source tree. Zero config, brittle under refactor.
- Explicit reference from source, some declaration in the resource pointing at a concept path. Precise, and it puts a docs concern into the typed surface.
- Link-based, using the spec's own cross-linking with an agreed link target shape. Most idiomatic to OKF, least precise.
Secondary questions that follow from the choice:
- Does an unbound concept warn, or is orphaned knowledge legitimate?
- Does a broken binding fail a build? The spec permits broken links, which argues for warn.
- Is the bundle discovered by convention (a well-known directory) or configured in
chant.config.ts? - Does this interact with child projects, where two stacks could both claim a logical name?
Acceptance criteria
- A written decision on the binding mechanism, with the rejected options and why.
- A decision on discovery: convention, config, or both.
- A stated failure posture for unbound concepts and broken bindings, consistent with the spec permitting broken links.
- A worked example showing a lint suppression citing a concept and the resulting
chant lintoutput. - A note on multi-stack and child-project ambiguity.
- Scope boundary: which consumers read bundles in the first implementation, and which are deferred.
Constraint
Whatever binding is chosen has to survive chant emitting bundles too (#1058). A round trip where chant writes a bundle and later reads it back should not produce duplicate or conflicting concepts for the same entity.
Activity
lex00 commentedon Aug 7, 2026
Design proposal:
Binding: a frontmatter key on the concept
A concept binds to an entity through a
bindsfrontmatter key naming the entity's logical name, the same string that keysDiscoveryResult.entities(packages/core/src/discovery/index.ts). The key takes one name or a list, since a decision frequently spans entities. A concept withoutbindsbinds nothing and is legitimate.The direction of reference is the point. Knowledge points at code. Code never points at knowledge, except the suppression citation below, which is a comment and not part of the typed surface. That keeps the epic's non-goal intact: emit and consume, never declare.
Rejected options.
Path convention mirroring the source tree is zero-config but breaks on every refactor, and it forces one concept per source file when intent often belongs to several entities at once. A concept explaining why two networks are peered belongs to both networks.
Explicit reference from source, a field on the declarable pointing at a concept path, is the most precise and the worst fit. It puts a docs concern into the typed surface, couples source to bundle layout, and makes renaming a markdown file dirty TypeScript.
Link-based binding via the spec's cross-links requires inventing a link target shape for things that are not bundle files. Entities live outside the bundle, so the target would be a made-up URI. That is a frontmatter key wearing link syntax, harder to parse and no more precise. Bundle-relative links stay what the spec says they are: links between knowledge files.
The stated objection to a bare logical name, ambiguity across multi-stack projects, dissolves at the right scope. Within one discovery pass entity names are unique map keys. A bundle binds only within its own project. A multi-stack repo is several projects, each with its own bundle.
Discovery: convention, with a config override
knowledge/besidechant.config.tsby convention.ChantConfigSchema(packages/core/src/config.ts) gainsknowledge?: { dir?: string }for projects that want another location. Config-only was rejected because a bundle that requires configuration to be found defeats the epic's argument, consumable without an integration. Convention-only was rejected because some projects already have aknowledge/meaning something else.Reader
New
packages/core/src/okf-read.ts.loadOkfBundle(dir)parses every non-reserved.mdusing the existingsplitFrontmatterfromokf.tsplusparseYAML. Tolerant to the letter of the spec: unknowntypevalues pass through, extra keys pass through, a file with unparseable frontmatter is skipped with a warning, and nothing rejects the bundle.bindConcepts(bundle, entities)returns aMap<entityName, OkfConcept[]>plus the list of unresolved bindings.Precedence: resolved by construction
Structural facts come only from discovery: type, lexicon, kind, edges, source file. Authored concepts contribute only category, title, and prose. The reader interprets exactly one key,
binds, and ignores structural-looking keys likenameandlexiconon authored concepts. Authored and inferred knowledge therefore cannot conflict at the fact level, and there is no merge policy to get wrong. Where both appear in output, sections are labeled by origin. chant never parses authored prose for facts.The rejected alternative was letting authored frontmatter override inferred fields, for instance a hand-written description shadowing the generated one. Cheap to build, expensive to trust. Once authored data can shadow the graph, a stale concept silently lies about structure, which is the failure the typed graph exists to prevent.
Lifecycle and failure posture
A
bindsthat resolves is a bound concept. Abindsthat resolves nothing is a stale binding and surfaces as a lint warning under a new core rule (next free COR id, COR019 at time of writing), never a build failure. The spec permits broken links between knowledge files; a binding is chant's own link into the graph and gets the same posture. A renamed entity looks identical to a deleted one and the fix is identical, one frontmatter line. No fuzzy matching and no rename tracking; a wrong guess would be worse than a plain warning. A concept with nobindswarns nothing. Orphaned knowledge is legitimate: runbooks, decisions about the project as a whole.Consumers in the first implementation
Three surfaces read the bundle first.
chant lint(packages/core/src/cli/commands/lint.ts). A suppression reason may cite a concept with anokf:token.parseDisableCommentsinlint/engine.tsalready captures reason text after--unchanged, so the directive syntax does not move. Today the stylish reporter prints only active diagnostics and the reason reaches SARIF alone (justificationincli/reporters/stylish.ts); the first implementation adds a suppressed section toformatStylishthat resolves the citation against the loaded bundle and prints the concept's title beside the rule id. An unresolvable citation prints as-is with a warning.chant explain(cli/handlers/explain.ts,cli/mcp/tools/explain.ts). The markdown and json formats gain a per-entity knowledge section carrying each bound concept's type, title, and path.MCP. A new
chant://knowledgeresource besidecli/mcp/resources/context.ts, serving the bundle index and concepts so the MCP path sees what the file path sees.Deferred:
graphrendering concept links on nodes,describe, and docs-site integration. Each is additive once the reader exists.Round trip with #1058
The emitter never writes
binds. The reader binds only onbinds. Reading back an emitted bundle therefore yields zero bindings and zero conflicts by construction, and no dedupe logic is needed. Emitted bundles are generated artifacts and should not live inknowledge/; one that ends up there anyway is inert and redundant, not wrong. One open point:explain --format okfcould link each emitted entity concept to its bound authored concepts, but that is a cross-bundle link the spec has no shape for, so it stays out until the spec grows one or the bundles merge.Multi-stack and child projects
A bundle binds only names visible to its own project's discovery. A child project (
nestedStack(),packages/core/src/child-project.ts) appears in the parent as a single entity, and a parent concept may bind that entity. Names inside the child belong to the child's own bundle. A qualifiedchild/nameform is reserved but rejected for now, no driving case, and adding it later is additive.Worked example
knowledge/decisions/public-assets.md:src/storage.ts:chant lintoutput, suppressed section:Delete
assetsBucketand the next lint run prints one COR019 warning naming the concept file and the unresolved name. The build is unaffected.Out of scope
Reading lexicon
dist/okf/bundles; agents consume those directly and no binding applies. chant writing or updating authored concepts. Knowledge affecting build output or lint behavior in any way; a cited suppression suppresses exactly as an uncited one does. Cross-bundle links from emitted bundles intoknowledge/. Qualified child-project bindings.Awaits review before implementation.
lex00 commentedon Aug 24, 2026
Design pass complete. The proposal above was re-verified against current code before decomposition, since two weeks of work landed after it was written. It holds.
Verification against current code
Every load-bearing claim checks out.
packages/core/src/okf.tsstill exportssplitFrontmatter,buildOkfBundle, andokfConformanceProblems; the reader can reuse them as proposed. No reader exists yet, andChantConfigSchema(packages/core/src/config.ts) has noknowledgekey.DiscoveryResult.entities(packages/core/src/discovery/index.ts) is still aMap<string, Declarable>keyed by logical name, unique within one discovery pass, so a bare name inbindsremains unambiguous at bundle scope.parseDisableComments(packages/core/src/lint/engine.ts) still captures reason text after--unchanged, and suppressed diagnostics with reasons flow throughpackages/core/src/cli/commands/lint.ts. Today the reason reaches only SARIF asjustification(formatSarifincli/reporters/stylish.ts);formatStylishtakes active diagnostics only. The proposed suppressed section is additive, exactly as described.explain --format okf) #1058, PR feat(core): explain --format okf emits an OKF v0.2 knowledge bundle #1576) never writesbinds, so the round-trip guarantee holds by construction. Lexicon bundles (feat(lexicons): generate an OKF knowledge bundle per lexicon at build time #1060, PR feat(lexicons): every lexicon build emits an OKF knowledge bundle beside meta.json #1585) ship indist/okf/via each lexicon's prepack and stay out of scope for the reader.Decisions, as recorded above
bindsfrontmatter key on the concept, one logical name or a list. Knowledge points at code, never the reverse.knowledge/besidechant.config.tsby convention, with aknowledge.dirconfig override.binds; structural facts come only from the graph. No merge policy exists to get wrong.graph,describe, docs site, qualified child-project bindings, cross-bundle links from emitted bundles.Implementation
okf-read.ts,bindsresolution, config key)okf:citationschant://knowledgeMCP resource#1864 is the prerequisite; the other three are independent once it lands.
lex00 commentedon Aug 24, 2026
Design recorded above; implementation tracked in #1864, #1865, #1866, #1867.
feat(core): OKF knowledge bundle reader — load and bind authored conc…
feat(core): COR026 stale knowledge binding warning
feat(core): COR026 stale knowledge binding warning (#1914)