Define canon knowledge once and reuse it across projects
Define canon knowledge: reusable rules across projects with okf sync
Define a rule once and every project concept that carries it holds the same text. The output below comes from okf 0.2.5 on a throwaway copy of the test catalogue.
flowchart LR O["kc-gov/ownership.md<br/>okf:canon naming-rule"] -->|sync-insert / sync-update| A["kc-gov/naming.md<br/>okf:sync"] O -->|sync-insert / sync-update| B["recipes/soup.md<br/>okf:sync"] O -.->|sync-status: drift report| A O -.->|sync-status: drift report| B
Set it up
Mark the rule in its owner concept. The owner holds the text; consumers get copies.
<!-- okf:canon id=naming-rule -->Names are lowercase, hyphenated, stable and unique.<!-- /okf:canon -->Put the catalogue under git so each change is one diff. Details of the markers: Canon blocks.
Work through it
-
Print the payload without its markers:
okf sync-export $ okf sync-export kc-gov/ownership naming-ruleNames are lowercase, hyphenated, stable and unique.[exit 0] -
Materialise it in a consumer concept. Without
--applyit only previews:okf sync-insert (dry run) $ okf sync-insert recipes/soup kc-gov/ownership naming-rule--- a/recipes/soup.md+++ b/recipes/soup.md@@ -15,3 +15,9 @@## HinweisUse a pot <size>. Compare with [bread](/recipes/bread.md).++<!-- okf:sync id=naming-rule source=/kc-gov/ownership.md hash=5f1068e89974 -->+> [!quote] Synchronisiert aus `/kc-gov/ownership.md` — Canon-Owner, hier nicht bearbeiten.+<!-- okf:sync-body -->+Names are lowercase, hyphenated, stable and unique.+<!-- /okf:sync -->would insert recipes/soup.md /kc-gov/ownership.md#naming-rulesync-insert (dry-run): re-run with --apply.[exit 0]With
--applythe same block is written and the last line readsinserted recipes/soup.md /kc-gov/ownership.md#naming-rule. -
Change the owner text later, then see which copies lag.
sync-statusreads only and exits 5 on drift:okf sync-status $ okf sync-statussynced handbook/ops/setup.md /kc-gov/ownership.md#ownership-rulesource-changed kc-gov/naming.md /kc-gov/ownership.md#naming-rulesynced recipes/soup.md /kc-gov/ownership.md#naming-rulesync-status: 2 synced, 1 source-changed, 0 consumer-modified, 0 both-changed, 0 source-missing, 0 malformed[exit 5] -
Refresh outdated copies. Dry run first, then
--apply:okf sync-update --apply $ okf sync-update --apply--- a/kc-gov/naming.md+++ b/kc-gov/naming.md@@ -9,8 +9,8 @@Refer to [ownership](/kc-gov/ownership.md).-<!-- okf:sync id=naming-rule source=/kc-gov/ownership.md hash=68dca574d22c -->+<!-- okf:sync id=naming-rule source=/kc-gov/ownership.md hash=5f1068e89974 -->> [!quote] Synchronisiert aus `/kc-gov/ownership.md` — Canon-Owner, hier nicht bearbeiten.<!-- okf:sync-body -->-Names are lowercase, hyphenated and stable.+Names are lowercase, hyphenated, stable and unique.<!-- /okf:sync -->updated kc-gov/naming.md /kc-gov/ownership.md#naming-rulesync-update: 1 updated, 0 refused, 0 unresolvable.[exit 0]
A copy edited by hand
sync-update refuses to overwrite a consumer copy that was edited. --force discards the local edit.
$ okf sync-status --source /kc-gov/ownership.mdsynced handbook/ops/setup.md /kc-gov/ownership.md#ownership-rulesynced kc-gov/naming.md /kc-gov/ownership.md#naming-ruleconsumer-modified recipes/soup.md /kc-gov/ownership.md#naming-rulesync-status: 2 synced, 0 source-changed, 1 consumer-modified, 0 both-changed, 0 source-missing, 0 malformed[exit 5]$ okf sync-update --applyrefused recipes/soup.md /kc-gov/ownership.md#naming-rule (consumer copy modified — reconcile into the canon owner first, or --force to discard)sync-update: 0 updated, 1 refused, 0 unresolvable.[exit 5]An unknown block id stops sync-insert with exit 3:
$ okf sync-insert --apply recipes/stew kc-gov/ownership nopeno canon block `nope` in kc-gov/ownership.md[exit 3]What you get
Project concepts that carry the same canon text, and a drift report (source-changed, consumer-modified, …) whenever the owner or a copy changes. okf check also warns about an outdated copy (kc/sync/stale). Background and design: the blog post Canon in the catalogue.
Limits
- After
rename --applyof a canon owner, the> [!quote]line in consumers keeps the old path andsync-statuscan still saysynced[6peo]. Runokf sync-update --apply. sync-updateexits 5 when it refuses a block or cannot resolve one.sync-insertexits 3 when the concept or the block does not exist.