okf 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.okf/capabilities/agent-skill.md +112 -0
  3. data/.okf/capabilities/bundles-manager.md +133 -0
  4. data/.okf/capabilities/graph-server.md +678 -0
  5. data/.okf/capabilities/index.md +26 -0
  6. data/.okf/capabilities/library-api.md +82 -0
  7. data/.okf/capabilities/linter.md +83 -0
  8. data/.okf/capabilities/read-views.md +228 -0
  9. data/.okf/capabilities/render.md +66 -0
  10. data/.okf/capabilities/search.md +295 -0
  11. data/.okf/capabilities/validator.md +60 -0
  12. data/.okf/cli.md +193 -0
  13. data/.okf/design/browser-tests.md +211 -0
  14. data/.okf/design/core-shell-split.md +73 -0
  15. data/.okf/design/index.md +17 -0
  16. data/.okf/design/integration-first.md +140 -0
  17. data/.okf/design/packaging.md +65 -0
  18. data/.okf/design/ruby-floor.md +53 -0
  19. data/.okf/design/runtime-dependencies.md +82 -0
  20. data/.okf/design/search-engines.md +154 -0
  21. data/.okf/design/server-trust-boundary.md +139 -0
  22. data/.okf/index.md +40 -0
  23. data/.okf/log.md +662 -0
  24. data/.okf/model/bundle.md +47 -0
  25. data/.okf/model/concept.md +75 -0
  26. data/.okf/model/graph.md +59 -0
  27. data/.okf/model/index.md +9 -0
  28. data/.okf/model/skeleton.md +76 -0
  29. data/.okf/overview.md +87 -0
  30. data/.okf/registry.md +265 -0
  31. data/.okf/structure/format-layer.md +59 -0
  32. data/.okf/structure/index.md +22 -0
  33. data/.okf/structure/search.md +53 -0
  34. data/.okf/structure/the-analysers.md +60 -0
  35. data/.okf/structure/the-cli.md +99 -0
  36. data/.okf/structure/the-disk-shell.md +67 -0
  37. data/.okf/structure/the-model.md +81 -0
  38. data/.okf/structure/the-server.md +74 -0
  39. data/.okf/structure/the-skill.md +52 -0
  40. data/.okf/testing/adding-a-verb.md +76 -0
  41. data/.okf/testing/index.md +12 -0
  42. data/.okf/testing/the-harness.md +45 -0
  43. data/CHANGELOG.md +83 -16
  44. data/README.md +205 -21
  45. data/lib/okf/cli.rb +20 -2
  46. data/lib/okf/skill/SKILL.md +15 -7
  47. data/lib/okf/skill/playbooks/maintain.md +3 -1
  48. data/lib/okf/skill/playbooks/produce.md +4 -2
  49. data/lib/okf/skill/reference/authoring.md +23 -26
  50. data/lib/okf/skill/reference/cli/checks.md +171 -0
  51. data/lib/okf/skill/reference/cli/graph.md +49 -0
  52. data/lib/okf/skill/reference/cli/map.md +98 -0
  53. data/lib/okf/skill/reference/cli/registry.md +70 -0
  54. data/lib/okf/skill/reference/cli/search.md +130 -0
  55. data/lib/okf/skill/reference/cli/serve.md +83 -0
  56. data/lib/okf/skill/reference/cli/views.md +59 -0
  57. data/lib/okf/skill/reference/cli.md +33 -603
  58. data/lib/okf/skill/reference/spec-map.md +32 -0
  59. data/lib/okf/version.rb +1 -1
  60. metadata +54 -5
@@ -0,0 +1,171 @@
1
+ # Checking a bundle — `validate`, `lint`, `loose`, `references`
2
+
3
+ Kind: reference. Answers: what makes a bundle non-conformant, what each lint
4
+ check means and the severity it is pinned at, which of the two clocks a flag
5
+ reads, and which dangling pointers each surface can and cannot see.
6
+
7
+ The shared contract — `@slug` refs, exit codes, `--json`, the filters — is in
8
+ [cli.md](../cli.md) and is not repeated here.
9
+
10
+ ## validate — the hard gate (§11)
11
+
12
+ Implements the spec's §11 conformance definition exactly (its words are in
13
+ [SPEC.md](../SPEC.md), routed by [spec-map.md](../spec-map.md)):
14
+
15
+ - **§11 cond. 1** every non-reserved file has a parseable YAML frontmatter block;
16
+ - **§11 cond. 2** every such block has a non-empty `type`;
17
+ - **§11 cond. 3** any `index.md`/`log.md` present follows §8/§9 (a nested
18
+ `index.md` has no frontmatter, a root `index.md` carries only `okf_version`,
19
+ `log.md` date headings are ISO `YYYY-MM-DD`).
20
+
21
+ `ERROR`s are the three conditions above; the bundle is non-conformant until every
22
+ one is fixed. `warn`s are soft — missing recommended fields, non-list tags, an
23
+ unparseable timestamp, **broken cross-links, which §6.1 explicitly tolerates**,
24
+ the shape of every §5/§10 family (`generated` not a mapping, a non-integer
25
+ `usage_count`, a `stale_after` that is not `YYYY-MM-DD`, a missing `runtime` on
26
+ an Attested Computation, …), and an `okf_version` the gem does not know (read
27
+ best-effort under §12; an absent one never warns). Absence of an optional family
28
+ is never a fault — a pure v0.1 bundle validates with zero warnings.
29
+
30
+ In `--json`, every warning carries `check` (a stable id) and `source` — `spec`
31
+ when the SPEC's own words state the rule, `convention` for a shape this gem asks
32
+ for beyond them (`verified[].by` presence, integer `usage_count`, a per-entry
33
+ `usage_window` mapping, `parameters[].name`, `executor`/`attester` `resource`).
34
+ Gate on `source` when you want only the spec-normative set; errors keep their
35
+ two-key `{ path, message }` shape. Fix warnings when cheap; never block on them.
36
+ Use `--json` in CI.
37
+
38
+ ## lint — curation quality (advisory)
39
+
40
+ Asks the complementary question to `validate`: not "is this legal OKF?" but "is
41
+ this well-curated, navigable, trustworthy?" — precisely over the things §11
42
+ forbids `validate` from rejecting. It has its own report, never emits
43
+ conformance errors, and **exits `0` even with findings** unless you pass
44
+ `--fail-on warn` (exit 1 on any `warn` finding) or `--fail-on info` (exit 1 on
45
+ any finding at all).
46
+
47
+ **Severity is API.** Every check has a pinned level — `warn` or `info` — and
48
+ machine consumers gate on it, so the levels below are stable, not advisory. A
49
+ finding you want to gate on that is `info` gets `--fail-on info` (usually with
50
+ `--only`), never a hope that its severity changes. <!-- rule:okf-severity-is-api -->
51
+
52
+ Eight categories, each backed by individual checks (severity in brackets):
53
+
54
+ - **Reachability** — `orphan` [warn], `not_in_index` [warn],
55
+ `disconnected_component` [info], `unlinked` [info]
56
+ - **Backlog** — `missing_concept` [info], `broken_index_entry` [warn]
57
+ - **Completeness** — `stub` [info], `missing_title` [info],
58
+ `missing_description` [info], `missing_generated` [info] (quiet on either
59
+ spelling — a legacy `timestamp` still counts as a recorded change)
60
+ - **Freshness** — `expired` [info] (§5.5: past the concept's own declared
61
+ `stale_after`, on the day itself), `stale` [warn] (older than the
62
+ reader-supplied `--stale-after` cutoff, keyed on `generated_at`)
63
+ - **Provenance** — `uncited_external` [info] (external body links and no
64
+ sources, in either spelling), `broken_source` [warn] (an in-bundle `.md`
65
+ source target that names no concept; URLs and scope descriptors are out of
66
+ scope, and a non-`.md` asset is out of reach — the reader models concepts,
67
+ so lint never sees the file; `okf references` is the view that checks those
68
+ pointers), `unattributed_claim` [warn] (a footnote
69
+ no `sources[].id` answers — it *misattributes* a claim, which is why it
70
+ outranks its join-twin), `unused_source` [info] (a keyed source no footnote
71
+ cites — slack, not a defect), `unprefixed_actor` [info] (a `verified[].by`
72
+ outside §7's three forms reads as machine-confirmed; a `generated.by`
73
+ outside them feeds no tier but leaves a reader unable to tell a person
74
+ from a process; info so it informs, never blocks). A missing `generated.by` is the *validator's* warning —
75
+ REQUIRED-within is shape, not curation — so lint never double-reports it
76
+ - **Attestation** — `incomplete_computation` [warn] (an Attested Computation
77
+ providing its computation neither way, or both ways — §10.3 says a
78
+ `computation:` path is used *instead of* the body fence),
79
+ `broken_attestation_ref` [warn] (on an `Attested Computation`, a
80
+ `computation`, `executor.resource` or `attester.resource` naming an
81
+ in-bundle `.md` that is not there — a contract no consumer can follow; the
82
+ keys are read only on that type, since §4.1 lets any other concept use them
83
+ for its own purpose). Its reach is exactly the `.md` files: URLs are out
84
+ of scope, and a `.sql` or `.py` target is invisible to *every* check here,
85
+ because the linter reads the concept model and the model carries only
86
+ markdown — `okf references` is the surface that sees those files and reports
87
+ a pointer that misses, whatever the extension. Remember §6.2 reads a bare
88
+ `references/…` as relative to the concept, so from a nested concept it wants
89
+ the leading `/`
90
+ - **Migration** — `legacy_timestamp` [info], `legacy_citations` [info]: one
91
+ finding per bundle naming the files still in a retired v0.1 spelling, with
92
+ the rewrite instructions in the message. Info on purpose — §13 says a v0.1
93
+ bundle is consumable forever, so `--fail-on warn` must not turn red on one.
94
+ A migration campaign gates explicitly:
95
+ `okf lint <dir> --only legacy_timestamp,legacy_citations --fail-on info`,
96
+ exit 1 until clean.
97
+ - **Hygiene** — `duplicate_title` [info], `unused_reference_def` [info],
98
+ `undefined_reference` [warn], `self_link` [info], `log_order` [info] (§9
99
+ reads a log newest-first; disorder is slack, never a §11 error)
100
+
101
+ `--only` / `--except` filter by the **individual check names above**, not the
102
+ category labels — `okf lint <dir> --only orphan,stub` works; `--only reachability`
103
+ is an error. Two knobs tune specific checks: `--min-body N` sets the `stub` body
104
+ threshold in characters (default 50), and `--stale-after DUR` sets the `stale`
105
+ cutoff — a duration like `90d` or `12w`, or an ISO date like `2026-01-01` (a bare
106
+ number is rejected).
107
+
108
+ **Two different clocks, one unlucky name.** The `--stale-after` *flag* and the
109
+ `stale_after:` *frontmatter field* are different mechanisms that happen to share
110
+ a spelling. The flag is the **reader's** age cutoff: "flag anything not touched
111
+ since DUR", keyed on `generated_at`, feeding the `stale` check. The field is the
112
+ **author's** declared expiry: "do not trust this past DATE", feeding the
113
+ `expired` check. Never read one as the other, and never show them adjacent
114
+ without the distinction. <!-- rule:okf-two-clocks -->
115
+
116
+ **The clock is explicit.** `expired` compares against a day the CLI supplies —
117
+ today by default, or `--today YYYY-MM-DD` for a reproducible report (CI wants
118
+ this). The pure library runs no clock check unless handed `today:`, and every
119
+ clock-gated check that was selected but could not run is *named* in
120
+ `stats.skipped_checks` (the human report prints one `skipped:` line) — a gate
121
+ that is sometimes absent and does not confess converts "unchecked" into
122
+ "checked and fine".
123
+
124
+ The report's stats carry the bundle's posture too: `trust` (the §5.3 tier
125
+ distribution, in the hyphenated wire spelling) and `status` (effective-status
126
+ frequency).
127
+
128
+ `lint --json` is the structured substrate you consume to reason about the two
129
+ things lint deliberately does **not** compute — contradictions and *semantic*
130
+ staleness — which need understanding of meaning.
131
+
132
+ ## loose — files with no graph connections (by folder)
133
+
134
+ Lists the **loose** files — concepts with graph **degree 0**: no cross-links in
135
+ *or* out — grouped by folder. It is a focused, folder-organized view over `lint`'s
136
+ `unlinked` check (`okf loose <dir>` ≈ `okf lint <dir> --only unlinked`, regrouped),
137
+ for the "which files float in the graph?" question. Advisory: **exits `0`**; `--json`
138
+ emits `{ bundle, count, loose: [{ id, title, dir }] }`.
139
+
140
+ **Loose ≠ orphan** — the trap. `lint`'s `orphan` is about *reachability*, and an
141
+ `index.md` listing makes a file reachable, so an indexed file is never an orphan.
142
+ But an index listing is **not a graph edge**: a file can be listed in an index yet
143
+ have no cross-links, so it floats in the graph while `lint` reports it as reachable.
144
+ `loose`/`unlinked` catch exactly that gap. A loose file is not automatically a
145
+ defect — a terminal leaf (a backlog item, a spec reference) can be loose by design;
146
+ `loose` surfaces the set so you can judge intent (see the
147
+ [maintain playbook](../../playbooks/maintain.md)).
148
+ <!-- rule:okf-loose-not-orphan -->
149
+
150
+ ## references — the `references/` inventory (§6.3)
151
+
152
+ Lists every file under `references/` — including the non-markdown ones no other
153
+ verb can see, since the concept model carries only markdown — with which
154
+ concepts cite each file through the §6.2 path-valued fields (`resource`,
155
+ `sources[].resource`, `computation`, `executor.resource`, `attester.resource`),
156
+ plus every pointer into `references/` that resolves to nothing. Advisory:
157
+ **exits `0`** even with dangling pointers — the findings are the output. JSON:
158
+ `{ bundle, dangling, count, references: [{ path, dir, kind, referenced_by }] }`,
159
+ with `--fields`/`--except` projecting the rows. A file that is itself a concept
160
+ (§6.3 allows both) is marked `kind: "concept"`; body links are the graph's
161
+ business and are not counted here.
162
+
163
+ **The dangling list is where §6.2's bare-path trap surfaces.** A bare
164
+ `references/attesters/rev.py` written from `metrics/` resolves relative to the
165
+ concept — `metrics/references/attesters/rev.py`, nothing — and when the
166
+ leading-slash spelling would have hit, the entry says so:
167
+ `/references/attesters/rev.py exists — missing leading slash?`. Reach is any
168
+ extension, which is exactly what `broken_source` and `broken_attestation_ref`
169
+ cannot offer (their exemptions above), so run it wherever a bundle carries
170
+ attester code or computation files.
171
+
@@ -0,0 +1,49 @@
1
+ # `graph` — the raw structure
2
+
3
+ Kind: reference. Answers: what a full dump costs and how to plan a traversal
4
+ without paying it, plus the two rankings that give `refine` its evidence —
5
+ `--hubs` by concept, `--traffic` by directory.
6
+
7
+ The shared contract — `@slug` refs, exit codes, `--json` — is in
8
+ [cli.md](../cli.md) and is not repeated here.
9
+
10
+ Prints the node/edge graph. `--json` emits a machine-readable dump — the
11
+ `bundle`/`slug` head every view carries, then `nodes` (with
12
+ `id`/`type`/`title`/`description`/`tags` **and, by default, every `body`** — the
13
+ part that dominates the bytes on a real bundle) plus `edges` — you can pipe into
14
+ other analysis. A concept with a missing *or blank* `type` indexes under
15
+ `Untyped`: §11 condition 2 rejects both identically, so both land in one bucket. To *plan* a traversal, structure is all you need: `--no-body`
16
+ drops each node's body, and `--minimal` ships only `id`/`title` plus the type/tag
17
+ indexes — the lean shape the `server` page boots from. Reach for the full dump
18
+ only when the task truly consumes every body; for one question, the
19
+ [search verb](search.md) is orders cheaper.
20
+
21
+ `--hubs` swaps the dump for the **inbound ranking**: every concept with at
22
+ least one inbound link, ranked by inbound degree, each with its links grouped
23
+ by *source top-level dir* (`core/status ×3 flows 2, billing 1`) — the evidence for
24
+ [refine](../../playbooks/refine.md)'s hub origin test ("is this hub well-homed?").
25
+ A source at the bundle root counts under `(root)`. JSON: `{ bundle, count,
26
+ hubs: [{ id, top_dir, inbound, by_top_dir: { <top_dir>: n } }] }`. Advisory read, exit 0;
27
+ `--minimal`/`--no-body` shape node payloads and change nothing here.
28
+
29
+ `--traffic` asks the same question one grain coarser: **directories**, not
30
+ concepts. Every concept collapses into the directory it lives in and every link
31
+ between two directories collapses into one weighted arc, so a bundle's wiring
32
+ becomes a table you can read — measured on one 47-concept bundle, 227 links
33
+ collapsed into 50 arcs, of which the fitted cut draws 22. Each row carries the
34
+ directory's traffic split three ways
35
+ (`internal` / `out` / `in`) plus **cohesion**, its internal share of the total:
36
+ the evidence for [refine](../../playbooks/refine.md)'s container test, where
37
+ `--hubs` only ever answered about concepts. Rows lead with the lowest cohesion,
38
+ so the directories with a case to answer come first, and a directory with no
39
+ traffic at all prints `—` rather than a `0%` it did not earn.
40
+
41
+ `--cut N` is the least arc weight drawn. It defaults to a value **fitted to the
42
+ bundle** — enough arcs for roughly 1.5 per directory, floored at 8 — because a
43
+ fixed weight cannot serve both ends: measured at weight 3 across ten bundles it
44
+ left 2 arcs on one and 136 on another. The JSON says which you got. Cohesion is
45
+ computed over *every* arc and never the drawn ones, so tightening the cut
46
+ changes the picture and never the evidence. JSON: `{ bundle, cut, fitted, dirs:
47
+ [{ dir, parent, count, subtree, internal, out, in, cohesion }], arcs: [{ source,
48
+ target, weight }], total_arcs }` — a fraction of the full dump (2.6 KB against
49
+ 27 KB on that bundle), and the shape rather than the contents. Advisory, exit 0.
@@ -0,0 +1,98 @@
1
+ # Orienting — `index` and `dirs`
2
+
3
+ Kind: reference. Answers: which view to run first on a bundle you do not know,
4
+ how `--dir`, `--depth` and the ancestor chain compose, what a synthesized
5
+ listing means, and how to keep the map from paging the whole bundle.
6
+
7
+ The shared contract — `@slug` refs, exit codes, `--json`, the filters — is in
8
+ [cli.md](../cli.md) and is not repeated here.
9
+
10
+ ## index — the progressive-disclosure map (§8)
11
+
12
+ The "orient before you read" view, and the read verb that sees the layer the
13
+ concept views can't: `index.md` files are reserved/structural, so
14
+ `catalog`/`files`/… never show them (in the browser, the Indexes tab and
15
+ folder clicks render this same map). `okf index <dir>` prints one entry per directory
16
+ that holds concepts or carries an `index.md`, root first — the authored index body
17
+ (frontmatter stripped), a `type`/`tag` rollup over the concepts that live directly
18
+ there, its child directories, and the concept listing. Run it first when picking up
19
+ an existing bundle: it is the cheapest high-signal orientation, and it surfaces
20
+ enumeration drift a grep can't (you can't grep for a listing entry that is *missing*).
21
+
22
+ `--dir PATH` narrows to a directory **and everything below it**, and is
23
+ **repeatable** — `--dir model --dir format` shows both; `root` (or `.`) names the
24
+ bundle root, unless the bundle really has a `root/` directory, which owns the
25
+ word. A `--dir` also brings the **chain from the root down to it**, so a branch is
26
+ never shown adrift of the authored context that says what it is — the root
27
+ `index.md`'s prose first among it. Those rows print with a leading `↑` and carry
28
+ `ancestor: true`; `--no-ancestors` drops them. Ascent and descent are separate
29
+ axes, so `--depth` never bounds the chain: `--dir X --depth 0` is X alone, plus
30
+ how you get to X. A `--dir` that names nothing gains no chain — a lone root row
31
+ would read as a partial answer to a query that matched nothing.
32
+
33
+ `--depth N` bounds how far below the starting point the map reaches
34
+ (the `--dir` when one is given, else the bundle root), counted **relatively**:
35
+ `--depth 1` is the top of the tree, `--dir X --depth 1` is one branch of it, and
36
+ the pair walks down a level at a time.
37
+
38
+ **On a bundle of any size the map is unreadable whole** — every directory is a
39
+ section, and even `--no-body` keeps one listing row per *concept* — so narrow
40
+ rather than paging it: `okf dirs` is the orientation, `--dir <branch> --depth 1`
41
+ is the step down into it,
42
+ and `--except body,listing` on top of either is the lean JSON skeleton. Full
43
+ `index` output on a few hundred concepts runs to hundreds of KB; the same map at
44
+ `--depth 1` is a couple of KB.
45
+
46
+ `--no-body` drops the prose to a
47
+ skeleton (headers, rollups, child pointers). For a directory that has concepts but
48
+ **no `index.md`**, the listing is **synthesized** from the concepts' descriptions
49
+ and tagged `(no index.md)` — §8 explicitly permits synthesizing a map on the fly.
50
+
51
+ It is a **read view**: advisory, always exit 0. A synthesized directory is a
52
+ *signal* (a map worth writing), never a defect — `index` emits no lint findings and
53
+ never fails a bundle. JSON: `{ bundle, count, directories: [{ dir, index_path,
54
+ present, synthesized, count, types, tags, subdirs, body, listing: [{ id, title,
55
+ description, type, tags }] }] }` — `ancestor` marks a row that is there to place
56
+ the branch rather than to answer about it.
57
+
58
+ ## dirs — the bundle's clusters and their sizes
59
+
60
+ `okf dirs <dir>` lists every directory the bundle has — the ones holding
61
+ concepts, the ones carrying an `index.md`, and the empty intermediates that only
62
+ exist to connect the tree — with the number of concepts living **directly** in
63
+ each and the number in its **subtree**. A cluster *is* a directory here, so this
64
+ is the view that tells you what `--dir` can be pointed at and how much sits
65
+ behind each choice.
66
+
67
+ Two numbers, because one cannot answer the question. `count` is direct, so the
68
+ column sums to the bundle's concept total and a dir holding only sub-directories
69
+ reads `0` rather than a hidden rollup. `subtree` is defined as *exactly what
70
+ `--dir <that row>` returns*, so the row and the flag can never disagree — which
71
+ is also why the root's subtree is its own direct count (`.` is a prefix of
72
+ nothing). Without it a truncated listing is all zeroes at the top of a deep tree,
73
+ which is where you most need to know where the mass is. The human table shows the
74
+ second column only where some dir actually nests.
75
+
76
+ `--dir PATH` (repeatable) narrows to a directory and its subtree, and brings the
77
+ **chain up to the root** with it so the branch is placed rather than shown
78
+ adrift — those rows are marked `↑`, carry `ancestor: true`, and stay out of
79
+ `total` (`--no-ancestors` drops them). `--depth N` keeps only N levels below the
80
+ starting point — the `--dir` when one is given,
81
+ the bundle root otherwise. Relative, not absolute, so `--dir a/b --depth 1`
82
+ reads "a/b and one level under it" without your first working out how deep `a/b`
83
+ is. `--depth 0` is the starting point alone. A `--depth` that is not a whole
84
+ number is a usage error (exit 2).
85
+
86
+ **This is the first command to run on a bundle you do not know** — the same first
87
+ move [SKILL.md](../../SKILL.md) prescribes. `okf dirs <dir>` is one row per
88
+ directory, so its size tracks the tree rather than the concept count: it tells
89
+ you the shape and where the weight sits, `--depth 1` trims it further on a deep
90
+ bundle, and you then descend with `okf index --dir`, one level at a time.
91
+
92
+ The root prints `(root)` and stores `.` — the split every grouped view keeps, so
93
+ a table and its `--json` never disagree about which spelling is the data. JSON:
94
+ `{ bundle, total, count, dirs: [{ dir, ancestor, count, subtree, subdirs }] }`,
95
+ root first. `count` is rows printed, chain included; `total` sums the direct
96
+ counts of the rows you actually asked for, which is what keeps a row's `subtree`
97
+ equal to the `total` that `--dir` on that row returns.
98
+
@@ -0,0 +1,70 @@
1
+ # `registry` — naming bundles once
2
+
3
+ Kind: reference. Answers: which file a registry op writes and how okf finds it,
4
+ which verbs key on a path and which on a slug, what a group is and which two
5
+ verbs consume one, and why the default is a position rather than a stored slug.
6
+
7
+ The *persistent registry* is a plain JSON file under `$OKF_HOME` (default
8
+ `~/.okf`), managed by the `okf registry` umbrella — like git's `remote` family,
9
+ and split by what each verb keys on. It is what every `@slug` resolves through
10
+ ([cli.md](../cli.md)) and what a bundle-less `okf server` hosts
11
+ ([serve.md](serve.md)).
12
+
13
+ **`okf registry init`** creates a *project-local* registry instead: a
14
+ `.okf-registry.json` in the current directory, which okf discovers by walking up
15
+ from the working directory and uses in place of the global one while you are
16
+ inside its tree (the nearest wins, so nested registries resolve nearest-first).
17
+ Every registry op — and every `@slug` — then resolves through it, so a bare
18
+ `okf server` inside a repo serves that repo's bundles with no `$OKF_HOME` setup;
19
+ `okf registry list` names the local file it found. `OKF_NO_DISCOVERY=1` forces
20
+ the global registry — the escape hatch for a fixed-cwd caller (CI, a tool). A
21
+ local registry stores **portable** paths: a bundle inside its tree is written
22
+ relative to the `.okf-registry.json`, so committing the file lets it travel with
23
+ the repo (a checkout elsewhere, a container mounting it) and resolve unchanged;
24
+ a bundle outside the tree stays absolute, since it cannot travel. Paths still read
25
+ back absolute wherever the CLI reports them.
26
+ **Entry verbs** take a path: `okf registry set <dir>` adds it
27
+ (slug from the basename, or `--as`, which errors on a collision; `--default`
28
+ puts it first), and because the entry is keyed by path, `set` on an
29
+ already-registered dir updates it in place — refreshing its title, and renaming
30
+ it when `--as` is given. `okf registry del <dir|@slug>` removes a bundle *or* a group — by name, so an
31
+ entry whose directory is already gone still deletes, and removing a bundle
32
+ **cascade-drops** it from every group that named it (a group emptied that way is
33
+ deleted). Slug *or* dir, never both readings at
34
+ once: an argument with a `/` in it names a location and only a location, so
35
+ `del ./notes` refuses when no entry points there rather than stripping to the
36
+ slug `notes` and deleting a bundle somewhere else entirely.
37
+ <!-- rule:okf-registry-del-path-or-slug -->
38
+ **Slug verbs** take the name — bare, or as an `@slug`: `okf registry default <@slug>`
39
+ chooses which bundle `/` opens **by moving that entry to the front** (a group is
40
+ refused — the default is one bundle), and
41
+ `okf registry rename <@slug> <new>` renames a bundle *or* group slug (mount path
42
+ and switcher name), **cascading** the new name into every group's member list —
43
+ `<new>` is a name being minted, so it is never a ref. The registry is ordered and **the first entry still on disk is the
44
+ default** — that is the whole rule, so the first bundle you register is the
45
+ default until you move another one, a rename keeps its position, and a `del`
46
+ promotes whatever is next. A vanished directory is stepped over (the server
47
+ cannot open one, so starring it would name a bundle `/` never serves), and
48
+ `registry default @slug` refuses one outright — the same refusal `registry set`
49
+ gives a directory that is not there. The file is hand-editable and reorders
50
+ visibly, which is the point: there is no stored slug that can dangle.
51
+ <!-- rule:okf-registry-default-position -->
52
+ **Group verbs** name a *set* of bundles under one slug — a durable subset for the
53
+ two verbs that take several bundles. `okf registry group <slug> <@member…>`
54
+ creates a group, or adds members to one (a union); members are bundle *or* group
55
+ slugs, so groups nest. A group shares the slug namespace with bundles (a slug
56
+ names one *or* the other, never both), `all` stays reserved, and a member set that
57
+ would make the group reach itself is refused. `okf registry ungroup <slug>
58
+ <@member…>` removes members; emptying a group deletes it. A group resolves,
59
+ recursively and path-deduped, to its bundle leaves — which **only `okf search`
60
+ and `okf server` consume**: every single-bundle verb (`lint`, `index`, …) refuses
61
+ a `@group` with exit 2, the same rule that refuses a second bundle. `@all` is
62
+ unchanged — it still names every registered *bundle*, groups being named subsets
63
+ of that.
64
+ `okf registry list` (or a bare
65
+ `okf registry`) stars the default and flags vanished dirs `(missing)` — the
66
+ server skips those with a note — and lists any groups with their members and
67
+ resolved leaf count; `--json` answers
68
+ `{ registry: <file>, count, bundles: [{ slug, title, dir, mount, default,
69
+ missing }], groups: [{ slug, members, resolved }] }`, naming the file it read so a
70
+ `$OKF_HOME` mismatch is visible.
@@ -0,0 +1,130 @@
1
+ # `search` — ranked text retrieval (metadata + body)
2
+
3
+ Kind: reference. Answers: how terms are matched and by which engine, what the
4
+ index buys and what it silently loses, how one query spans several bundles, and
5
+ which of the two JSON envelopes comes back.
6
+
7
+ The shared contract — `@slug` refs, exit codes, `--json`, the filters this verb
8
+ also takes — is in [cli.md](../cli.md) and is not repeated here.
9
+
10
+ The browser page's search brought to the CLI and extended to bodies, so "which
11
+ concept covers X?" costs rows, not body reads. `okf search <dir> <term…>`:
12
+ terms AND together — every term must hit at least one searched field, not
13
+ necessarily the same one — matched **literally against raw text** by default, or
14
+ as Ruby regular expressions with `--regexp`/`-e` (an invalid pattern is a usage
15
+ error, exit 2). `--fuzzy` forgives typos; pairing it with `-e` is a usage error,
16
+ since a pattern is matched literally rather than by edit distance.
17
+ `--in a,b` restricts the searched fields (title, id, tags, type, description,
18
+ sources, body — `sources` is each entry's title and resource joined, so a
19
+ migrated bundle keeps the recall its `# Citations` body text used to give it);
20
+ the shared `--type/--dir/--tag/--status/--trust` filters narrow the candidates
21
+ *first*, so a search scoped by what `index` taught you stays surgical.
22
+
23
+ **The default is exact, so an exact query means what it looks like.** A phrase in
24
+ one argument (`"dedup key"`), a dotted version (`7.2.0`), an underscored
25
+ identifier (`customer_id`), a mid-word fragment (`ustomer`) and a word written in
26
+ `backticks` all match literally. This is what the scan engine buys, and it is the
27
+ default precisely because those queries are the common ones and the alternative
28
+ loses them silently. <!-- rule:okf-search-exact-identifiers -->
29
+
30
+ **`--engine index` is the other engine, and the one to reach for when ranking
31
+ matters more than exactness.** The engine is normally chosen by what the query
32
+ needs — `--fuzzy` routes to the index, anything else stays on the default scan —
33
+ and nothing is printed about the choice. `--engine NAME` overrides that for the
34
+ case the flags cannot express: a matching *model* requires no capability, so no
35
+ flag selects one. Under the index, terms match whole tokens and their prefixes
36
+ (`dedup` finds `deduplication`), rows rank by BM25+, and it is the engine the
37
+ browser page runs — so name it when reconciling a CLI answer with the page. The
38
+ cost is real: its tokenizer splits on punctuation, so identifiers shatter
39
+ (`customer_id` → `customer` + `id`), an infix finds nothing, and a backtick is
40
+ never split off at all, so a word inside a code span is unfindable — a large
41
+ silent loss, since technical prose is full of them. **Do not count on ranking to
42
+ rescue it** — BM25 normalizes by field length, so a short concept dense in `7`,
43
+ `2` and `0` can outrank the one that actually says `7.2.0`. Naming an engine that
44
+ cannot do what you also asked (`--engine index -e`) is a usage error naming one
45
+ that can. <!-- rule:okf-search-engine-choice -->
46
+
47
+ **The capabilities, and which engine has them.** An engine is selected by what
48
+ the query *requires*; only a matching model has to be named, because requiring
49
+ nothing is not something a flag can express:
50
+
51
+ | Flag | Capability | Engine | What it does |
52
+ |---|---|---|---|
53
+ | *(none)* | — | scan | literal substring over raw text; scores by summed field weight |
54
+ | `-e` / `--regexp` | `regexp` | scan | each term is a Ruby regexp, case-insensitive; invalid → exit 2 |
55
+ | `--fuzzy` | `fuzzy` | **index** | edit distance 0.2 × term length — and switches engine |
56
+ | `--engine index` | — | index | whole-token + prefix matching, BM25+ ranking, browser parity |
57
+ | `--engine scan` | — | scan | the default, spelled out |
58
+
59
+ Two consequences worth holding. **`--fuzzy` is an engine switch, not a mode**: it
60
+ carries the whole index with it, so a run that wanted one typo forgiven also gets
61
+ shattered identifiers and unfindable code spans — fix the spelling and stay on
62
+ the default when you can. And **`-e` moves nothing** now, because the default
63
+ engine already offers `regexp`; it changes how a term is *read* (pattern rather
64
+ than literal), not where it is matched. <!-- rule:okf-search-fuzzy-is-a-switch -->
65
+
66
+ `prefix` is a capability the index declares but no flag selects — it is always on
67
+ there. **It is not a reason to reach for the index**: a substring match already
68
+ covers every prefix and then some, so `dedup` finds `deduplication` under both
69
+ engines, while `duplication` and `uplicat` find it under the default only. Prefix
70
+ is what the index needs to catch up to raw text, not a capability it adds on top.
71
+ The index's real advantages over the default are exactly three — relevance
72
+ ranking, typo tolerance, and page parity.
73
+
74
+ **Search spans bundles.** Leading @refs pick several registered bundles
75
+ (`okf search @handbook @notes auth`); **`@all`** is the ref that means every one.
76
+ Rows from different bundles are ranked together and comparable, and each row
77
+ carries its bundle's slug. Under `--engine index` the bundles go into **one
78
+ corpus** — BM25 prices a term by how rare it is, so separately-ranked lists would
79
+ not compare — which makes a score relative to the whole answer: the same concept
80
+ scores lower searched beside others than searched alone. The default scan needs
81
+ no such trick — its score is absolute, so a row is worth the same either way.
82
+ This is the
83
+ cross-bundle retrieval the in-page search does not have: one question, every
84
+ bundle you keep. <!-- rule:okf-search-all -->
85
+
86
+ `@all` is a ref, not a flag, which is what keeps the grammar single: slot 1 is
87
+ always a bundle identity, so a directory there is a directory and nothing can
88
+ flip it into a term. Being a ref, it is normalized like one — `@ALL` and `@All`
89
+ name every bundle just as `@One` names the bundle registered from dir `One`. It composes accordingly — `@all @docs` expands and dedupes
90
+ (all ⊇ docs), needing no diagnostic. **Asking for everything tolerates gaps;
91
+ naming one bundle demands it**: `@all` skips a bundle whose directory has
92
+ vanished with a note on stderr, while `@docs` fails hard. `@all` is only
93
+ `search`'s: every other verb answers about one bundle, so it refuses `@all` by
94
+ name rather than letting the answer depend on how many bundles you happen to
95
+ have registered. `all` is reserved as a slug — a directory named `all/` registers
96
+ as `all-2`, `--as all` is refused, and an `all` row already in the registry file
97
+ (hand-typed, or written before the name was reserved) is read as `all-2` rather
98
+ than taken as grounds to reject the file — so `@all` is never ambiguous, and the
99
+ reservation never strands a registry it inherited. **The read normalizes every
100
+ slug** the same way registration would, so a hand-typed `"slug": "My Docs"` lists
101
+ and resolves as `my-docs`; an entry the listing shows is always an entry `@slug`,
102
+ `rename`, and `default` can name.
103
+
104
+ `--fields` projects the shape the mode actually emits: `slug` is available in
105
+ registry mode, and a usage error naming the real fields on a path-named search,
106
+ which has no slug to give. Two sharp edges: every *leading* @-arg is taken as a ref, so a literal @-term
107
+ (`@babel/core`, a Ruby `@ivar`) needs a non-@ term before it or `-e '\@term'` —
108
+ the CLI notes both traps on stderr — and any ref, even one, switches the JSON
109
+ envelope (next paragraph).
110
+
111
+ Rows rank by where they hit — title 5, id 4, tags 3, type/description 2, body 1 —
112
+ summed as an absolute score by the default scan, and carried as per-field boost
113
+ into **BM25+** under `--engine index`. Each row carries one bounded context
114
+ snippet from the strongest match that needs context (description or body). Every row still names the fields that hit (`matched`), so a result stays
115
+ citable rather than being a bare relevance number. Exact by default: the
116
+ consuming agent is the fuzzy layer — when terms miss, learn the bundle's
117
+ vocabulary from `tags`/`types` and re-ask in its own words, rather than
118
+ hammering synonyms or reaching for `--fuzzy` before you have looked. Advisory read: **exit 0 even with zero matches**.
119
+ JSON, plain-dir mode: `{ bundle, query, count, matches: [{ id, title, type,
120
+ dir, top_dir, tags, matched, score, snippet }] }`. Registry mode — any leading @ref,
121
+ `@all` or a `@group` among them (a group fans out to its member bundles) — swaps the envelope: `{ bundles: [{ slug, dir }, …],
122
+ query, count, matches: [{ slug, id, … }] }`; a parser must branch on which form
123
+ it called. The head maps each slug to its dir once, so a row resolves to
124
+ `<dir>/<id>.md` without a second lookup and without repeating a path per row.
125
+ Both are projectable with `--fields/--except`, and projection is literal — when
126
+ merging bundles, put `slug` in your `--fields` list or the row label drops and
127
+ same-id concepts from different bundles become indistinguishable. The retrieval procedure that puts this verb in sequence —
128
+ map first, finder second, bodies last — is the
129
+ [search playbook](../../playbooks/search.md).
130
+
@@ -0,0 +1,83 @@
1
+ # Serving the graph — `server` and `render`
2
+
3
+ Kind: reference. Answers: what the interactive page shows and what it fetches
4
+ live, how several bundles mount behind one hub, what the static export trades
5
+ away, and the trust boundary both modes share.
6
+
7
+ The shared contract — `@slug` refs, exit codes, `--json` — is in
8
+ [cli.md](../cli.md) and is not repeated here.
9
+
10
+ ## server — interactive graph server
11
+
12
+ Starts a local HTTP server (`okf server <dir>`; `-p`/`--port`, default 8808, and
13
+ `--bind`) and prints its URL — stop it with Ctrl-C. The page boots from a lean
14
+ payload (nodes carry only `id` and `title`, plus compact type/tag indexes) and
15
+ fetches each concept's markdown body **live from disk** as you click it, so the
16
+ initial load stays small and edits show without a restart. Mermaid code blocks
17
+ in a body render as diagrams, and a click (or tap) opens the diagram full
18
+ screen with drag-to-pan and wheel/pinch zoom. Concepts render as nodes
19
+ coloured by `type` and sized by degree, links as edges, with a detail panel
20
+ (rendered markdown, "Links to" / "Linked from" backlinks), layout switching,
21
+ type/dir/tag filters on every view (the dir chips take a directory *and* its
22
+ subtree, the same rule `--dir` uses), and search. Cluster mode groups the
23
+ concepts into one box per directory, nested to a depth picked beside the layout
24
+ select — depth 1 is the flat view, and a flat bundle is offered no control. The authored layer is in the
25
+ UI too: the Files view carries **Files | Indexes** tabs — the Indexes tab
26
+ lists the log first (the chronological index), then every `index.md` — and
27
+ folder nodes in file-tree mode and directory boxes in cluster mode open a
28
+ directory's §8 map in the inspector (authored, or synthesized when none
29
+ exists). Links to an `index.md`, `log.md`, or bare directory navigate instead
30
+ of dead-ending, and the log is fetched fresh on every read, so a
31
+ just-appended entry shows without a restart. `?view=index` jumps straight to
32
+ the Indexes tab. It is a Rack app, so the same server can be mounted in a
33
+ host app (e.g. Rails).
34
+
35
+ **Hosting many bundles (the hub).** `okf server` takes zero or more dirs.
36
+ One dir is the classic single bundle at `/`. Two or more mounts each under
37
+ `/b/<slug>/` behind a hub, `/` redirects to the default, and `/b/` is a
38
+ self-contained **bundle index** (every hosted bundle, concept counts, default
39
+ marked — the browser counterpart of `okf registry`). An unknown slug 404s as a
40
+ page listing the hosted bundles, so a stale bookmark after a rename gets a way
41
+ home. With **no** dir it serves the *persistent registry*. The hub roster is a
42
+ **boot-time snapshot**: restart `okf server` after registry changes. Behind a
43
+ hub the page gains a **bundle switcher** (⌘/Ctrl-K, or the rail button with its
44
+ bundle-count badge): the current bundle is pinned, the default chipped; ⏎
45
+ opens, ⌘/Ctrl-⏎ opens a new tab, and the current view carries over. Switching
46
+ is a server-only affordance — a static `render` file has no siblings and shows
47
+ none.
48
+
49
+ **Bundle-less run.** Register bundles once, then `okf server` (no dir) hosts
50
+ them all with the registry's first entry still on disk at `/` — the way to keep
51
+ several bundles a keystroke apart without re-passing paths.
52
+ `okf server @a @b` serves a registry subset, each mounted under its registered
53
+ slug — but as with any dirs-given run, the *first argument* lands at `/`; the
54
+ registry's own order applies only to the bundle-less run. A `@group` argument
55
+ fans out to its member bundles in the same way (`okf server @backend`), its first
56
+ member landing at `/`; `okf search @group <term…>` merges the group's members
57
+ into one ranking, exactly as naming them individually would.
58
+ The registry itself — the file it reads, how okf finds it, and the verbs that
59
+ write it — is in [registry.md](registry.md).
60
+
61
+ **Trust boundary:** the page renders each fetched markdown body through
62
+ DOMPurify and escapes everything it inlines (every `<` in the graph data is
63
+ escaped, so it cannot break out of its `<script>`), but it still loads its
64
+ viewer libraries (Cytoscape, marked, DOMPurify — plus Mermaid and Panzoom,
65
+ lazy-loaded on first use) from a CDN and renders whatever
66
+ links the bundle carries — so only serve bundles you trust.
67
+ ## render — static graph export
68
+
69
+ Writes the same interactive page as one static, self-contained HTML file
70
+ (`okf render <dir>`), so the graph hosts where there is no server — GitHub Pages,
71
+ an object store, an attachment. Prints to stdout (`okf render <dir> > graph.html`)
72
+ or writes `-o FILE`; `--title`/`--link`/`--layout` mirror `server`. It is the same
73
+ template `server` renders, one switch apart: rather than fetching each body,
74
+ description, catalog, index, and log live, `render` bakes the whole bundle into
75
+ the page and the browser reads from that embedded payload — no server, no build
76
+ step. The trade-off is weight (every body is inlined), so `server` stays the
77
+ choice for a bundle too large to ship whole.
78
+
79
+ **Trust boundary:** the same two guards as `server` — every inlined body is
80
+ `</script>`-escaped like the graph data and still sanitized by DOMPurify when
81
+ rendered — so a static file is no laxer than the live server. Only render bundles
82
+ you trust.
83
+