Skip to content

design(core): OKF bundles as project input — binding authored concepts to inferred entities #1059

Closed

Description

@lex00

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 lint prints the authored reason alongside the rule id rather than the id alone.
  • explain and describe merge inferred structure with authored intent in a single answer.
  • graph renders nodes carrying their concept links.
  • The MCP context resource (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:

  1. Frontmatter key on the concept naming the logical name or resource type. Simple, but a bare logical name is ambiguous across multi-stack projects.
  2. Path convention, mirroring the source tree. Zero config, brittle under refactor.
  3. 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.
  4. 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 lint output.
  • 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

  1. added
    enhancement
    on Jul 26, 2026
  2. lex00 commented on Aug 7, 2026

    @lex00
    ContributorAuthor

    Design proposal:

    Binding: a frontmatter key on the concept

    A concept binds to an entity through a binds frontmatter key naming the entity's logical name, the same string that keys DiscoveryResult.entities (packages/core/src/discovery/index.ts). The key takes one name or a list, since a decision frequently spans entities. A concept without binds binds nothing and is legitimate.

    ---
    type: decision
    title: Public asset bucket stays world-readable
    binds: assetsBucket
    ---

    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/ beside chant.config.ts by convention. ChantConfigSchema (packages/core/src/config.ts) gains knowledge?: { 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 a knowledge/ meaning something else.

    Reader

    New packages/core/src/okf-read.ts. loadOkfBundle(dir) parses every non-reserved .md using the existing splitFrontmatter from okf.ts plus parseYAML. Tolerant to the letter of the spec: unknown type values 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 a Map<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 like name and lexicon on 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 binds that resolves is a bound concept. A binds that 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 no binds warns 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 an okf: token. parseDisableComments in lint/engine.ts already 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 (justification in cli/reporters/stylish.ts); the first implementation adds a suppressed section to formatStylish that 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://knowledge resource beside cli/mcp/resources/context.ts, serving the bundle index and concepts so the MCP path sees what the file path sees.

    Deferred: graph rendering 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 on binds. 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 in knowledge/; one that ends up there anyway is inert and redundant, not wrong. One open point: explain --format okf could 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 qualified child/name form is reserved but rejected for now, no driving case, and adding it later is additive.

    Worked example

    knowledge/
      index.md
      decisions/
        public-assets.md
    

    knowledge/decisions/public-assets.md:

    ---
    type: decision
    title: Public asset bucket stays world-readable
    binds: assetsBucket
    ---
    The assets bucket serves the marketing site directly. AWS021 flags the
    public ACL. It is intentional. Revisit when the site moves behind
    CloudFront, tracked in #412.

    src/storage.ts:

    // chant-disable-next-line AWS021 -- okf:/decisions/public-assets.md
    export const assetsBucket = new Bucket({ name: "marketing-assets", acl: "public-read" });

    chant lint output, suppressed section:

    src/storage.ts
      12:1  suppressed  AWS021  Public asset bucket stays world-readable
                                knowledge/decisions/public-assets.md
    

    Delete assetsBucket and 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 into knowledge/. Qualified child-project bindings.

    Awaits review before implementation.

  3. added
    area:core
    design
    on Aug 23, 2026
  4. lex00 commented on Aug 24, 2026

    @lex00
    ContributorAuthor

    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.

    Decisions, as recorded above

    • Binding is a binds frontmatter key on the concept, one logical name or a list. Knowledge points at code, never the reverse.
    • Discovery is knowledge/ beside chant.config.ts by convention, with a knowledge.dir config override.
    • Precedence is resolved by construction. The reader interprets only binds; structural facts come only from the graph. No merge policy exists to get wrong.
    • An unresolved binding is a lint warning (COR022), never a build failure. Unbound concepts warn nothing.
    • First consumers are lint, explain, and MCP. Deferred: graph, describe, docs site, qualified child-project bindings, cross-bundle links from emitted bundles.

    Implementation

    #1864 is the prerequisite; the other three are independent once it lands.

  5. lex00 commented on Aug 24, 2026

    @lex00
    ContributorAuthor

    Design recorded above; implementation tracked in #1864, #1865, #1866, #1867.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coredesignenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions