1 RFC 001 okf content
Carlos Pinos edited this page 2026-12-05 19:16:52 +01:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

RFC-001: @quatrain/okf-content, versioned OKF content formatting and validation

Status: Draft (proposal only, nothing is implemented until accepted) Authors: Carlos Pinos (lead: architecture, API, version management, Core conventions) · Ganesha Rag (co-author: consumer needs, upstream reuse, migration, adoption) Reviewer: Yoda Tao · Decision and merge: project owner Date: 2026-12-05 Tracking: once accepted, each task in §10 becomes an issue on quatrain/core that links back to this page.


1. Summary

The Open Knowledge Format (OKF) specification is pre-1.0 and changes quickly: v0.2 → v0.3 brought two breaking changes. This RFC proposes:

  • keeping @quatrain/okf as the foundation package (in the Core sense: a base class holding the adapter registry, the logger and shared static methods), and
  • adding @quatrain/okf-content, which formats and validates OKF documents for several specification versions side by side, and converts a document from an earlier version on demand.

Command-line usage comes first. Web and desktop surfaces come later and use the same packages.

2. Motivation

  • One implementation per version. Every OKF producer currently writes frontmatter and indexes on its own, so the specification is reimplemented, and drifts, in each one. Core already contains two OKF writers (@quatrain/okf document/* and the okf-ingest serializer).
  • The specification changes fast. Hard-coding one version (today OKF_VERSION = '0.2' in @quatrain/okf) means rewriting the model at each release. We need a structure where adding v0.4 is a bounded, repeatable task.
  • Readers must stay tolerant. A consumer has to read v0.2 and v0.3 bundles side by side during migrations. Producers write only the latest version.

2.1 What v0.3 changes (from §13 of the upstream specification)

  • Breaking, paths. A path field without a leading / now resolves from the directory of its file, no longer from the bundle root (§6.2).
  • Breaking, trust. Only current verifications (verified[].at >= generated.at) count toward the trust tier (§5.3).
  • Additive. New superseded_by field (§5.4). The root index.md gains title, description and license (§8.1). Extension keys are allowed, using x-<producer>-<name> (§4.1).
  • Clarifications.
    • Parsing: YAML 1.2, no duplicate keys, no re-serialization of unchanged values.
    • Files: sub-directory index.md files and log.md carry no frontmatter.
    • Fields: team: actors are allowed, and date-only timestamps have a defined meaning.

3. System map (generic provider)

@quatrain/okf and @quatrain/okf-content are generic providers. Test: any data catalogue, wiki or agent memory needs to create, validate and migrate OKF documents, under these names.

Generic provider (@quatrain/okf, @quatrain/okf-content) Consumers
Owned vocabulary OKF terms only: bundle, concept, index, log, source, actor, verification, trust tier, profile, finding, extension key, manifest, composition, version, conversion their own house and business terms
Forbidden vocabulary any consumer name, house key or dataset, in code, types, tests, fixtures, README, issues and commits none
Contract OKF versions + profiles + stable API + CLI exit codes and JSON findings each consumer ships its own profile and calls the API or CLI
Where house rules live never here in the consumer, as a .okf/profile.yaml file at the bundle root or a code profile
  • Fixtures use a neutral domain (acme, example.org) and the upstream example bundles.
  • Plans specific to a consumer (its measured state, its migration, its CI) stay in that consumer's repository and issues. They link to this page, never the other way around.

4. Package split

Package Role Runtime deps
@quatrain/okf (existing, foundation) Okf extends Core. It holds the adapter registry (addAdapter/getAdapter, like Storage), the Okf.logger scope, the version registry (Okf.versions) and shared static helpers: actor parsing, datetimes, path utilities. It also keeps OKFBackendAdapter, the Quatrain backend over flat OKF files. @quatrain/core, log, backend, storage, types, yaml
@quatrain/okf-content (new) Version-aware model, lossless parse and serialize, per-version validation, profiles, conversions, plus the content operations (create, touch, verify, deprecate, move, index, scan, compose). It does no I/O and works through a BundleFileSystemInterface port. @quatrain/okf (foundation), yaml
@quatrain/okf-content-testing (dev only) Neutral fixtures, golden files, and the oracle runner for each version (§6.3) dev
@quatrain/cli (existing) core okf … command group, §7 adds @quatrain/okf-content

Dependency direction: consumers → okf-content → okf, and never the reverse. okf-content must also run in a browser (with an in-memory or HTTP port) and in a desktop shell, so it must never import Node built-ins. Node's fs implementation of the port lives in @quatrain/okf, as NodeBundleFileSystem, jailed to the bundle root.

4.1 What moves from today's @quatrain/okf

Today (@quatrain/okf/src/document) Becomes
types.ts (OKF_VERSION = '0.2'), OkfDocument, validate, OkfIndex the v0_2 version module in okf-content, then copied as the base of v0_3
provenance.ts (actors, datetimes, trust) generic parts go to static helpers on Okf; version-specific trust rules go to each version module
upgrade.ts (v0.1 → v0.2) the first link of the conversion chain (0.1→0.2)
OKFBackendAdapter stays in @quatrain/okf. It reads and writes through okf-content, so it is no longer limited to v0.2

Compatibility contract. These are the symbols imported from @quatrain/okf by its current consumers (counted import sites). They must keep working:

Symbol Sites Constraint
parseOkfDocument 4 same signature; becomes a version-detecting entry point
OkfFormatError, OkfDocumentInterface 3 + 3 same names (type re-export allowed)
renderOkfIndex 2 kept; must preserve root frontmatter (v0.3 §8.1 MUST)
okfDatetime 2 kept (moves to an Okf static, re-exported as a function)
OKFBackendAdapter 2 stays in @quatrain/okf
withOkfVerification 1 kept
also used: serializeOkfDocument, upgradeOkfDocument, validateOkfDocument, OKF_VERSION, profile and issue types — OKF_VERSION becomes "latest supported"; upgradeOkfDocument delegates to the conversion chain

For at least one Core minor cycle, @quatrain/okf keeps these symbols as re-exports. They are tagged @deprecated in their JSDoc and delegate to okf-content, so consumers compile unchanged. Each consumer's test suite runs against the release candidate before publication. The re-exports are removed only at the next Core major.

4.2 Overlap with @quatrain/okf-ingest and @quatrain/okf-ingest-catalog

Concern Decision
AI extraction, transcription, cost tracking, catalogue decomposition stays in okf-ingest*. It is not format work, and its AI dependencies must not leak into okf-content.
Serializing the output to OKF (serializer.ts, writer.ts, packaging as v0.2) replaced by okf-content. okf-ingest builds concept inputs and calls createConcept and regenerateIndexes, targeting the latest version by default (targetVersion option).
Its existing v0.2 packaging tests become conversion fixtures (0.2→0.3) in okf-content-testing

After this change, Core has one OKF writer.

5. Version management (the core requirement)

5.1 One module per version

packages/okf-content/src/
  versions/
    v0_2/  index.ts  model.ts  validate.ts  paths.ts  trust.ts  index-render.ts  codes.ts  SPEC.lock
    v0_3/  …same files…
  conversions/
    0_1-to-0_2.ts   0_2-to-0_3.ts
  operations/      create, touch, verify, deprecate, move, index, scan, compose (version-agnostic, delegate to the module)
  OkfContent.ts    facade

Each version module implements one contract:

interface OkfVersionModuleInterface {
  readonly version: string                        // '0.3'
  readonly specRef: { commit: string; url: string } // pinned upstream SPEC.md
  parse(text: string, file: string): OkfParsedDocument          // lossless (yaml Document AST)
  serialize(doc: OkfParsedDocument): string                     // untouched bytes preserved
  validate(bundle: OkfBundleView, profile?: OkfProfileInterface): OkfFinding[]  // upstream codes for this version
  resolvePath(fromFile: string, value: string): OkfResolvedPath
  trustTier(fm: OkfFrontmatter, now: Date): OkfTrustTier
  renderIndexEntries(entries: OkfIndexEntry[]): string
  newConceptFrontmatter(input: OkfNewConceptInput, ctx: OkfActionContext): OkfFrontmatter
}
  • Modules are registered in Okf.versions (foundation), keyed by version string. Okf.latestVersion is the default for writing.
  • Modules are frozen once released. A fix to a released version touches only that module, and its oracle must stay green. Modules never import each other. Shared logic goes into small internal helpers or into Okf statics.

5.2 Detection

  1. Read the okf_version of the bundle's root index.md.
  2. If it is missing, the bundle is treated as v0.2 with the finding W125. This matches the upstream tolerance rule (§12.1).
  3. A concept does not carry a version. It always uses its bundle's version.
  4. An unknown or newer version is a contract error (OkfUnsupportedVersionError) that suggests upgrading the package. We never guess.

5.3 Conversion chain

interface OkfConversionInterface {
  from: string; to: string                        // adjacent versions only
  convert(bundle: OkfBundleView, ctx: OkfActionContext): OkfPlan  // returns changes + findings; never writes
}
OkfContent.convert(bundle, { to = Okf.latestVersion }): OkfPlan   // composes 0.2→0.3→… in order
  • Only adjacent steps exist. Converting 0.2 to 0.4 composes 0.2→0.3 with 0.3→0.4.
  • Conversions are idempotent, and the dry-run is free because everything returns a plan (§6.1).
  • Data is never altered silently. Here is what the 0.2→0.3 step does:
    • Bare path values: a value that resolves from the file's directory is kept. A value that only resolves from the root is rewritten as /value. Anything else is reported as broken and never auto-fixed.
    • Verifications: those that are no longer current (I204) are listed in the findings, so that a human can re-verify.
    • Index and log files: frontmatter is removed from sub-directory index.md files, and its title and description move to the parent index entry. The root index.md gains title, description and license, but only from values provided by the caller or the profile. They are never invented.
    • Date-only timestamps: they are kept, because they remain valid in v0.3.

5.4 Conformance tests per version

The upstream repository has no releases and no tags: a version is identified only by a commit. Each module therefore has a SPEC.lock that pins the upstream commit of its specification, its example bundles and, where it exists, its reference validator.

Version SPEC.lock commit Conformance oracle Fixtures
0.2 56e30af (last v0.2 state, parent of the switch) no upstream validator exists for v0.2 (validate.py and scan.py were added later, in c4df7ba, for v0.3 only): the oracle is the current v0.2 test suites of @quatrain/okf, frozen as golden tests upstream bundles/* @ 56e30af
0.3 527e81a (switch to v0.3 at 9506f31) skills/okf-generate/scripts/validate.py + skills/okf-consume/scripts/scan.py @ 527e81a, run as a differential oracle upstream bundles/* @ 527e81a
next its commit its upstream validator if any, pinned upstream bundles @ that commit
  • Oracle job in CI (Forgejo, ci-base:1 image): for each version that has an upstream validator, that validator and our TypeScript module run on the same fixtures: the upstream example bundles at the pinned commit, the neutral acme bundles and the conversion fixtures. Any difference in finding codes fails the build.
  • Finding codes: v0.3 reuses the upstream codes and messages (E0xx, W1xx, I2xx). v0.2 reuses the same code where the rule is identical, and uses a reserved range for v0.2-only rules.
  • Conversion fixtures come free from upstream. Upstream rewrote its own example bundles when it moved to v0.3, so the same bundle exists in v0.2 form (56e30af) and in v0.3 form (9506f31 / 527e81a). acme_retail is the richest pair: it has path fields, log frontmatter and an extension-key rename. The 0.2→0.3 golden test is: convert(v0.2 fixture) must equal the upstream v0.3 fixture, apart from the documented non-mechanical edits. Fixtures are fetched at the pinned commit at test time, not vendored.
  • Golden-file tests: parse → serialize with no edit must be byte-identical. An edit must change only the edited keys.
  • Each conversion step is tested both ways. The converted bundle must validate with 0 errors under the target module, and the oracle for the target version must agree.

5.5 Procedure: adding a new version (target: ≤ 2 agent-days for a clarification-only version, 3–5 days for a version with breaking changes)

  1. Copy versions/v0_N to versions/v0_N+1, update version and SPEC.lock (upstream commit of the spec, bundles and validator if any).
  2. Apply the changes listed in the upstream changelog (§13 of the specification), each change with its test. Cite the § of the specification in JSDoc.
  3. Write the 0_N-to-0_N+1 conversion from the spec's breaking-change table, using the upstream migration.md as the checklist.
  4. Fetch the upstream bundles at the new commit as fixtures, add the conversion golden pairs and the oracle entry. CI must be green for all versions.
  5. Register the module and move Okf.latestVersion in a minor release of okf-content. Writers switch only when they choose to (targetVersion). Dropping a version requires a major release.
  6. Publish a version page on this wiki (okf-content-v0_N+1) with the changes and the conversion notes.

This procedure becomes a checklist issue template on quatrain/core.

6. Public API of @quatrain/okf-content

6.1 Principles

  • Plan / apply. Every mutation returns an OkfPlan (changes: OkfFileChange[], findings: OkfFinding[]), and nothing is written until applyPlan. A single code path then covers dry-runs, diffs, CI --check, and the review step of future web and desktop surfaces.
  • Findings, not exceptions, for content problems: { code, level, file, line?, message }, using the upstream codes of the bundle's version. Exceptions are reserved for broken contracts (invalid arguments, unreadable port, unsupported version), following the fail-fast rule.
  • Clock and actor are injected. ctx = { by: OkfActor, now: Date }. The package never reads them from the environment or from git config.
  • Profiles are data first. A .okf/profile.yaml file declares required, forbidEmpty, vocabularies, extensions and severity overrides. Code profiles implement the same OkfProfileInterface. No house rule ships in Core.
  • Core style applies: *Interface and *Type suffixes, JSDoc on every export, a single root export.

6.2 Surface

class OkfContent extends Okf {
  // reading
  static openBundle(fs: BundleFileSystemInterface, opts?: { profile?: OkfProfileInterface }): Promise<OkfBundle>
  // checking
  static validate(bundle: OkfBundle, opts?: { strict?: boolean }): Promise<OkfFinding[]>
  static loadProfile(fs: BundleFileSystemInterface, path?: string): Promise<OkfProfileInterface>
  // writing (all return OkfPlan)
  static createConcept(bundle, input: OkfNewConceptInput, ctx): Promise<OkfPlan>
  static touchConcept(bundle, id, ctx): Promise<OkfPlan>
  static verifyConcept(bundle, id, ctx): Promise<OkfPlan>
  static deprecateConcept(bundle, id, opts: { supersededBy?: string }, ctx): Promise<OkfPlan>
  static moveConcept(bundle, from, to, ctx): Promise<OkfPlan>
  static regenerateIndexes(bundle, opts?: { log?: boolean }): Promise<OkfPlan>   // owns bullet lines only, keeps prose
  static compose(bundle, manifest: OkfComposeManifest): Promise<OkfPlan>         // closure over links and path fields
  static convert(bundle, opts?: { to?: string }): Promise<OkfPlan>
  static applyPlan(fs: BundleFileSystemInterface, plan: OkfPlan): Promise<void>
}

class OkfBundle {
  readonly version: string; readonly meta: OkfRootMeta
  concepts(filter?: { current?: boolean; stale?: boolean; deprecated?: boolean; unverified?: boolean }): AsyncIterable<OkfConcept>
  get(id: string): Promise<OkfConcept | undefined>
  resolve(fromFile: string, value: string): OkfResolvedPath
}

The API follows SemVer. Finding codes are part of the contract: changing a code is a major change.

7. Where the CLI lives

Proposal: both, with a clear split.

core okf … (@quatrain/cli) an external integration tool (workstation and forge), outside Core
OKF semantics owner: thin commands over OkfContent none, delegates
Workstation and forge integration (single agent entry point, CI action template, bundle install and sync) none owner
How imports @quatrain/okf-content spawns core okf … --json at a pinned CLI version
  • Commands: core okf new|touch|verify|deprecate|move|index|validate|scan|compose|convert. They take the common options --bundle, --profile, --json, --dry-run and --check.
  • No prompt in okf commands. Missing input is a usage error, so the commands are safe for agents and CI with stdin closed.
  • Exit codes: 0 OK, 1 error-level findings (or warnings with --strict), 2 usage error, 3 contract or I/O error.
  • Actor: taken from --by or OKF_ACTOR. A command that writes generated or verified refuses to run without one.
  • Core never imports or names the wrapper. The wrapper's work is tracked on the wrapper's side.

Web and desktop later. No UI work is planned in this RFC, but nothing in the design blocks it:

  • the I/O port lets the browser use an in-memory or HTTP storage, and the desktop app use NodeBundleFileSystem;
  • a plan can be shown as a diff before it is applied;
  • findings carry a file and line, so they map directly to editor diagnostics.

A future okf HTTP adapter (REST endpoints for validate, scan and plan/apply) and the UIs (CoreUX) will get their own RFC.

8. Migration of existing producers and readers (generic rules)

The order is: package first, readers tolerant before writers switch, smallest bundle first.

  1. Release okf-content with modules v0.2 and v0.3 and the 0.1→0.2→0.3 chain, then core okf.
  2. Readers move to openBundle, which reads both versions, excludes deprecated, follows superseded_by and counts only current verifications. Readers must move before any writer switches to v0.3.
  3. Writers move to the OkfContent operations with targetVersion: '0.3'.
  4. Bundles are converted with core okf convert --dry-run, then one reviewed change per bundle. Any loss of trust tier (I204) is listed in the change description for human re-verification.

Each consumer tracks its own steps in its own repository, linking to this page (§3).

9. Adoption

  • Rule for producers: create and change OKF documents only through core okf or the API. Never hand-write generated, verified or index lines. Validate before committing.
  • Backstop in each bundle repository's CI: core okf validate --strict and core okf index --check.
  • Provenance warning when the body changes but generated.at does not. It is a warning, not an error, since a "meaningful change" is a judgement (§5.2).
  • Agent skills: the upstream okf-generate and okf-consume skills, installed unmodified and pinned by commit, plus a thin overlay that lives in the consumers' agent-instruction repository, not in Core. The overlay only redirects to core okf (same finding codes as the upstream validator) and adds no OKF rule of its own, so a new specification version moves only okf-content and the skill pin.
  • Upstream reuse (Apache-2.0 → AGPL-3.0-only, which is compatible in this direction):
    • the reference validator (validate.py) and reader (scan.py) are ported per version, keeping finding codes and messages;
    • the upstream example bundles are fetched at the pinned commit at test time, not vendored;
    • ported files keep their upstream headers, and okf-content ships a NOTICE.

10. Tasks (issues on quatrain/core once accepted)

# Task Estimate (agent-days)
T1 @quatrain/okf foundation: Okf extends Core, version and adapter registries, logger, statics, NodeBundleFileSystem 1
T2 okf-content skeleton, version module contract, v0_2 module extracted from document/*, deprecated re-exports 1.5–2
T3 v0_3 module (paths, trust, superseded_by, root metadata, extensions, lossless editing) 2–3
T4 Conversion chain 0.1→0.2→0.3 1.5
T5 Operations: create, touch, verify, deprecate, move, index, scan, compose 3–4
T6 Oracle CI per version, upstream fixture fetching, conversion golden pairs, frozen v0.2 golden suites, neutral fixtures (okf-content-testing) 2–3
T7 core okf command group in @quatrain/cli 1.5
T8 okf-ingest and okf-ingest-catalog switched to okf-content 1
T9 Wiki: okf-content-Overview, okf-content-HowTo, add-a-version checklist and issue template 0.5
Total for Core ≈ 14–18 agent-days, plus human review per PR. Consumer migrations are not included and are estimated on the consumer side.

11. Risks

# Risk Likelihood Impact Mitigation
R1 The specification changes again (pre-1.0) high medium one module per version, adjacent conversions, the §5.5 procedure
R2 The TypeScript port drifts from the upstream validator medium medium oracle per version, same codes, deliberate pin upgrades
R3 index regeneration overwrites hand-written prose high medium it owns only its bullet lines; --check; the first run is reviewed as a diff
R4 Existing consumers of @quatrain/okf break low high deprecated re-exports for one minor cycle; consumer suites run against the pre-release
R5 A writer switches to v0.3 before its readers medium high §8 order is a hard dependency
R6 Lossless YAML editing is harder than re-serializing medium medium yaml Document API; byte-identical golden tests
R7 Consumer vocabulary leaks into Core medium high profiles only, neutral fixtures, hashed forbidden-terms guard (check_forbidden_terms.js)
R8 Too many old versions to maintain low medium released modules are frozen; dropping one requires a major release with notice
R9 No upstream oracle for v0.2 certain medium current v0.2 suites frozen as golden tests; upstream v0.2/v0.3 bundle pairs as conversion fixtures
R10 Upstream has no tags: "a version" means "a commit" certain low pin by commit in SPEC.lock; pin upgrades are deliberate, reviewed changes

12. Open questions

  1. Should NodeBundleFileSystem live in @quatrain/okf (proposed) or in a separate @quatrain/okf-fs?
  2. CLI: is core okf … (proposed) the right place, or should there be a dedicated okf bin shipped by okf-content?
  3. How many minor cycles should the deprecated re-exports in @quatrain/okf be kept (proposed: one)?
  4. Which oldest version should be supported for reading (proposed: 0.1 via conversion only, 0.2 and 0.3 natively)?

13. Decision requested

Accept:

  • the foundation and content split (§4) and the okf-ingest decision (§4.2);
  • the version management design (§5);
  • the API (§6) and the CLI placement (§7).

Answer §12. On acceptance, T1–T9 become issues on quatrain/core linking to this page.