okf 2.1.1 → 2.2.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.
data/CHANGELOG.md CHANGED
@@ -5,6 +5,148 @@ All notable changes to this project are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.2.1] - 2026-12-02
9
+
10
+ ### Fixed
11
+
12
+ - **`okf references` sees a `references/` directory at any depth, not only at
13
+ the bundle root.** §6.3 names the subdirectory without placing it, but the
14
+ inventory globbed only `<root>/references/`. A bundle keeping
15
+ `computations/references/` got those files left out, and worse, a bare
16
+ `references/attesters/rev.py` from `computations/revenue.md` — which §6.2
17
+ resolves into that directory, where the file sat — was reported as dangling
18
+ with "which does not exist". The same fix reaches the MCP `references` tool,
19
+ which reads the same inventory.
20
+ - **`okf references` no longer lists a file whose symlink target is outside the
21
+ bundle, and does not walk a directory symlink.** The inventory now asks
22
+ `SafeRead` before listing, the containment check the reader already applies,
23
+ and like the reader it walks real directories only. A `references` directory
24
+ that was a link out of the root put outside names on the page as the
25
+ bundle's own — at the root in 2.2.0, and at any depth once the inventory
26
+ reached every level; a directory link within the root listed its files
27
+ twice. A root
28
+ `references` that is itself a link to another directory in the bundle now
29
+ lists nothing, though pointers through it still resolve.
30
+ - **`okf references` calls a pointer dangling only when nothing in the bundle
31
+ exists at its path.** The inventory leaves out paths that still open — hidden
32
+ ones, files behind a directory link, directories — and missing used to mean
33
+ "not in the inventory", so a pointer to any of those read "which does not
34
+ exist". The disk is now asked instead, through the same containment check:
35
+ a pointer to a file whose link leads out of the root dangles, as the reader
36
+ treats that file. The leading-slash hint still names only a file the
37
+ inventory lists.
38
+ - **`okf references` reads a pointer the way it reads the disk.** A pointer is
39
+ cleaned of `.` and `..` before it is looked up, so `/references/./x.py` cites
40
+ the file instead of dangling, and `./references/x.py` from a subdirectory
41
+ gets the leading-slash hint. Only a directory named exactly `references`
42
+ counts, so macOS no longer lists a `References/` that Linux does not. The
43
+ text hint no longer prints the pointer's `#fragment` as part of a file name.
44
+
45
+ ## [2.2.0] - 2026-08-22
46
+
47
+ ### Added
48
+
49
+ - **`okf registry import <@slug…> [--from FILE]` — copy chosen bundles out of
50
+ another registry file into the one in force, where they become yours.** It is
51
+ the opposite trade from `link` and the pair is the point: a link holds a live
52
+ pointer to a whole file and the other side keeps owning what it lends, while an
53
+ import copies chosen references and hands over ownership, so what lands renames,
54
+ defaults and groups like anything you registered by hand. The case it exists for
55
+ is standing in a repo, running `okf registry list -g`, and wanting one of the
56
+ bundles it shows — before this the only way to move it was to read the path off
57
+ the screen and retype it into `registry set`.
58
+
59
+ The source is `--from`, defaulting to the global registry, because `-g` goes on
60
+ meaning the registry acted *on*, as it does on every sibling subcommand. A group
61
+ ask brings its members and any group nested inside it, recreated under the same
62
+ names. Slugs are preserved, so a collision **refuses** (`--as` renames a single
63
+ ask) rather than being minted around the way a linked name is — a linked name was
64
+ never chosen here, an imported one was typed. A bundle already registered here
65
+ under another name refuses first, naming that name. Every ask is validated before
66
+ anything is written, so an import lands whole or leaves the file byte-for-byte
67
+ alone.
68
+
69
+ - **`.okf.json` is the project-local registry's filename.** `okf registry init`
70
+ writes it, and it is what the docs now name. The older `.okf-registry.json` is
71
+ **still discovered**, so no committed registry breaks: both names are checked in
72
+ each directory on the way up — per directory, not one name swept to the root and
73
+ then the other, or a legacy file at a repo's root would beat a `.okf.json` two
74
+ levels down and "the nearest one wins" would mean something else. Within one
75
+ directory the short name wins, and a legacy file left beside it is named on
76
+ stderr rather than silently ignored.
77
+
78
+ The deprecation note is the `registry` umbrella's alone, and it is one stderr
79
+ line: that verb's subject *is* a registry file, and it is not the one people run
80
+ in loops or pipe into something else, which is exactly what `lint` and `search`
81
+ are. Renaming is `git mv .okf-registry.json .okf.json`, and the note says so. One
82
+ transitional cost worth naming: a checkout renamed to `.okf.json` is invisible to
83
+ an installed okf older than 2.2.0, which will fall back to the global registry
84
+ until that install is upgraded.
85
+
86
+ - **`okf registry link <name> <file>` — the global registry points at another
87
+ registry file, and that file's bundles resolve here.** Nothing is copied: the
88
+ target keeps owning its rows, so an edit there shows on the next read. The case
89
+ it exists for is a repository that already curates its own bundles in a
90
+ committed `.okf-registry.json` — a link composes that curation instead of
91
+ duplicating it, and the target resolves its own relative paths exactly as it
92
+ would from inside that checkout. A linked bundle answers to its own slug, or to
93
+ `<name>-<slug>` when the name is already taken here; `@<name>` resolves as a
94
+ group over the set; `okf registry unlink <name>` drops it.
95
+
96
+ Links are the **global** registry's alone. A project-local one parses them and
97
+ never resolves them, which is what makes depth one structural — a linked file's
98
+ own links are never followed, so no chain forms and there is no cycle to guard.
99
+ A link is read-only: `rename`, `del`, `default`, `set --as` and `group` refuse a
100
+ slug it owns, naming the file that does, from the browser's ⚙ Bundles panel as
101
+ from the terminal. A target that has gone or cannot be parsed is listed
102
+ `(missing)`/`(unreadable)` and resolves to nothing, rather than taking down the
103
+ registry holding it.
104
+
105
+ - `registry group` and `registry ungroup` refuse a group a link brought in —
106
+ the link's own set, or one the linked file curates. Naming one took the
107
+ update path, reported `grouped …`, and discarded the change on the next read,
108
+ because only the groups this registry owns are written. A write that reports
109
+ success and does not happen is worse than one that raises.
110
+
111
+ - **`-g`/`--global` on every `registry` subcommand but `init`.** It forces the
112
+ `$OKF_HOME` registry for one command, so `okf registry list -g` reads the global
113
+ one from inside a repo carrying its own, and `okf registry set <dir> -g`
114
+ registers there without leaving. `OKF_NO_DISCOVERY=1` already did this for a
115
+ whole session and still does; the flag exists because a lever reachable only
116
+ through an env var is one most people never find. It stays on the `registry`
117
+ umbrella — the one verb whose subject *is* a registry file — and nowhere else.
118
+
119
+ - The graph page's ⚙ Bundles panel marks a linked row `via @onm` and **offers no
120
+ actions menu** on it. Rename, Remove and Default are all refused for a linked
121
+ bundle, so the menu could only have produced three errors. The request is
122
+ refused whether or not the button exists — the guard is in `Registry`, not in
123
+ the page — which is the same split the read-only server already keeps: hiding
124
+ a control is a UI, refusing the request is the boundary.
125
+
126
+ - **`okf help` shows one `registry` row instead of ten, and `okf registry --help`
127
+ prints the subcommands.** Ten rows for one verb made a third of the map about
128
+ registry management, and the map is there to name the verbs rather than to be
129
+ every verb's manual. The row names the help that replaces it, since nothing
130
+ else tells a reader an umbrella has subcommands. A bare `okf registry` still
131
+ lists the registry, and `okf registry <command> --help` still answers for that
132
+ command.
133
+
134
+ ### Changed
135
+
136
+ - `okf registry list --json` groups now carry a `link` key — `null` for a group
137
+ this registry owns, the link's name for one that arrived through a link.
138
+ `Registry#groups_listing` returns both kinds in one list, own groups first,
139
+ because `#group?` resolves a linked group and a listing that named only the
140
+ local half would answer about a smaller set than the same object can resolve —
141
+ the drift every library consumer would inherit silently. A caller that wants
142
+ only the editable groups filters on `link`.
143
+
144
+ - `okf registry list --json` gains a `links` array, and each bundle row gains
145
+ `link` (the link it arrived through, `null` when the registry owns it) and
146
+ `origin` (its slug in that file, differing only where a collision moved the
147
+ name). The on-disk registry gains a `"links"` key, written empty when there are
148
+ none; an older file with no such key reads unchanged.
149
+
8
150
  ## [2.1.1] - 2026-08-20
9
151
 
10
152
  ### Fixed
data/README.md CHANGED
@@ -131,6 +131,8 @@ okf graph <dir|@slug> [--hubs] [--traffic] # the raw graph; --hubs ranks c
131
131
  okf server [DIR|@slug…] [-p PORT] [--bind ADDR] # the live graph: one bundle, or all of them
132
132
  okf render <dir|@slug> [-o FILE] # the same page as one static, self-contained file
133
133
  okf registry init | list | set | del | default | rename | group | ungroup # name & group your bundles
134
+ okf registry link | unlink <name> <file> # fold another registry file's bundles in
135
+ okf registry import <@slug…> [--from FILE] # copy bundles out of another registry into this one
134
136
  okf skill <dest> # install the companion agent skill
135
137
  okf --version
136
138
  ```
@@ -173,17 +175,44 @@ at once — a durable subset for the two verbs that take several bundles.
173
175
 
174
176
  The registry lives under `$OKF_HOME` (default `~/.okf`) — one per user. For one
175
177
  scoped to a single project instead, `okf registry init` drops a
176
- `.okf-registry.json` in the current directory; okf then discovers it by walking up
177
- from wherever you run, and every registry op — and every `@slug` — resolves through
178
+ `.okf.json` in the current directory (the older `.okf-registry.json` is still
179
+ discovered, and `okf registry` says so once so you can `git mv` it); okf then
180
+ discovers it by walking up from wherever you run, and every registry op — and every `@slug` — resolves through
178
181
  it in place of the global one. So a bare `okf server` inside that repo serves *its*
179
- bundles with no `$OKF_HOME` setup. The nearest registry wins, and
180
- `OKF_NO_DISCOVERY=1` forces the global one.
182
+ bundles with no `$OKF_HOME` setup. The nearest registry wins; `-g` on any
183
+ `registry` subcommand reaches the global one for a single command (`okf registry
184
+ list -g`, `okf registry set ./docs -g`), and `OKF_NO_DISCOVERY=1` does it for a
185
+ whole shell.
181
186
 
182
187
  Commit that file and it travels with the repo: a bundle under the project root is
183
188
  stored relative to the registry, so a checkout on another machine — or a container
184
189
  that mounts the repo — resolves the same bundles unchanged. (Bundles outside the
185
190
  tree keep absolute paths, which do not travel.)
186
191
 
192
+ A repository that already curates its own bundles can lend that list rather than
193
+ have it copied. `okf registry link onm ~/ONM/.okf.json` points the global
194
+ registry at another registry file: its bundles resolve under their own slugs,
195
+ `@onm` names the set, and nothing is duplicated — edit the other file and the
196
+ change shows on the next read. They are read-only from here, since the file that
197
+ owns them is elsewhere.
198
+
199
+ ```bash
200
+ okf registry link okf ~/code/okf/.okf.json # that repo's own curation, composed
201
+ okf search @all rate limit # now spans both files
202
+ ```
203
+
204
+ When you want one bundle rather than a whole file, `import` is the opposite
205
+ trade — it copies the reference, and what lands is yours to rename, default and
206
+ group. The source is `--from`, defaulting to the global registry, which inside a
207
+ repo is the only other one you have. A group ask brings its members with it,
208
+ slugs are preserved (a collision refuses rather than being renamed behind your
209
+ back), and nothing is written unless every ask checks out.
210
+
211
+ ```bash
212
+ okf registry list -g # what does the global registry hold?
213
+ okf registry import handbook specs # take those two, here, as mine
214
+ ```
215
+
187
216
  Behind the hub each bundle mounts at `/b/<slug>/`, `/b/` lists them all, and the
188
217
  `⌘/Ctrl-K` palette both switches bundles and **searches every one at once** — type
189
218
  a few words and the matching concepts appear with their bundle and a snippet, from
@@ -71,11 +71,12 @@ module OKF
71
71
  end
72
72
 
73
73
  # The §6.3 inventory — this handle's half is the disk: the reader models
74
- # only markdown, so listing `references/` here is how a .py attester or a
75
- # .sql computation becomes visible at all. The pure model gets the
76
- # manifest and answers the rest (citers, dangling pointers).
74
+ # only markdown, so listing `references/` files here is how a .py
75
+ # attester or a .sql computation becomes visible at all.
77
76
  def references
78
- Bundle::References.build(@bundle, files: reference_files)
77
+ real_root = File.realpath(@root) if Dir.exist?(@root)
78
+ Bundle::References.build(@bundle, files: reference_files(real_root),
79
+ present: ->(relative) { contained?(relative, real_root) })
79
80
  end
80
81
 
81
82
  # Every log.md with its content, root scope first — read live from disk so a
@@ -155,16 +156,33 @@ module OKF
155
156
 
156
157
  private
157
158
 
158
- # Bundle-relative paths of every file under references/, sorted. A glob
159
- # on a directory that does not exist is simply empty — no references/ and
160
- # an empty references/ are the same inventory.
161
- def reference_files
162
- Dir.glob(File.join(@root, "references", "**", "*"))
163
- .select { |path| File.file?(path) }
164
- .map { |path| Pathname.new(path).relative_path_from(Pathname.new(@root)).to_s }
159
+ # Bundle-relative paths of every file under a references/ directory at
160
+ # any depth, sorted — §6.3 names the subdirectory, not where it sits;
161
+ # membership is References.inside?'s call. The glob is the reader's own
162
+ # `**`, which walks no hidden directory and no directory link, so a link
163
+ # can neither list names from outside the root nor list a file twice.
164
+ def reference_files(real_root)
165
+ return [] unless real_root
166
+
167
+ root = Pathname.new(@root)
168
+ Dir.glob(File.join(@root, "**", "*"))
169
+ .select { |path| path.include?("/references/") } # cheap cut before the Pathname work
170
+ .map { |path| Pathname.new(path).relative_path_from(root).to_s }
171
+ .select { |relative| Bundle::References.inside?(relative) }
172
+ .select { |relative| File.file?(File.join(@root, relative)) && contained?(relative, real_root) }
165
173
  .sort
166
174
  end
167
175
 
176
+ # Whether +relative+ exists and its resolved location stays inside the
177
+ # root — the inventory's one meaning of "in the bundle", for what it lists
178
+ # and for what it calls missing, since the reader keeps a link only then.
179
+ def contained?(relative, real_root)
180
+ SafeRead.contained_path!(@root, File.join(@root, relative), real_root: real_root)
181
+ true
182
+ rescue Path::Error, SystemCallError
183
+ false
184
+ end
185
+
168
186
  def reserved_hash(basename)
169
187
  @bundle.reserved
170
188
  .select { |entry| File.basename(entry.path) == basename }
@@ -4,42 +4,64 @@ require "set"
4
4
 
5
5
  module OKF
6
6
  class Bundle
7
- # The §6.3 inventory, pure: every file under `references/` — handed in by
8
- # the shell as +files+, because the reader models concepts and this model
9
- # performs no disk access — with which concepts cite each one through the
10
- # §6.2 path-valued fields (resource, sources[].resource, computation,
11
- # executor.resource, attester.resource), plus the pointers into
12
- # `references/` that resolve to nothing.
7
+ # The §6.3 inventory, pure: every file under a `references/` directory at
8
+ # any depth — handed in by the shell as +files+, because the reader models
9
+ # concepts and this model performs no disk access — with which concepts
10
+ # cite each one through the §6.2 path-valued fields (resource,
11
+ # sources[].resource, computation, executor.resource, attester.resource),
12
+ # plus the pointers into a `references/` that resolve to nothing.
13
13
  #
14
14
  # The bare-path trap is what the dangling list exists to surface: §6.2
15
- # resolves a bare path relative to the concept, so `references/x` works
16
- # from the bundle root and silently misses one directory down. When the
17
- # missed spelling would have hit with a leading slash, the entry says so.
15
+ # resolves a bare path relative to the concept, so `references/x` from
16
+ # `metrics/` means `metrics/references/x` — right when that directory
17
+ # exists, a silent miss when the author meant the root's. When the missed
18
+ # spelling would have hit with a leading slash, the entry says so.
18
19
  #
19
- # Scope is the folder, by design. §6.3 is "a naming convention, not a
20
- # requirement", and a computation stored beside its concept is legal —
21
- # and deliberately not this inventory's to list.
20
+ # Scope is the folders, by design. §6.3 is "a naming convention, not a
21
+ # requirement", and a computation stored beside its concept outside any
22
+ # `references/` is legal — and deliberately not this inventory's to list.
22
23
  class References
23
- def self.build(bundle, files:)
24
- new(bundle, files: files)
24
+ # +present+ is the shell's disk check, handed in so this model stays pure:
25
+ # the manifest holds only what the inventory chose to list, so a pointer
26
+ # is dangling only when the disk also says nothing is there.
27
+ def self.build(bundle, files:, present:)
28
+ new(bundle, files: files, present: present)
25
29
  end
26
30
 
27
- # Files under references/, sorted by path, each
31
+ # Whether the clean relative +path+ lies inside a directory named exactly
32
+ # `references`, at whatever depth — the one predicate the shell's listing
33
+ # and the dangling check share, so every filesystem lists the same. A path
34
+ # still starting with `..` has left the root (the resolver returns an
35
+ # escape as written).
36
+ def self.inside?(path)
37
+ segments = path.split("/")
38
+ segments.first != ".." && segments[0...-1].include?("references")
39
+ end
40
+
41
+ # A pointer's path as written, fragment dropped and `.`/`..` cleaned —
42
+ # the spelling the leading-slash hint tests at the root.
43
+ def self.bare(raw)
44
+ Pathname.new(raw.to_s.split("#", 2).first.to_s).cleanpath.to_s
45
+ end
46
+
47
+ # Every inventoried file, sorted by path, each
28
48
  # { path:, dir:, kind:, referenced_by: [ { id:, field: } ] } — kind is
29
49
  # "concept" when the file is a parsed concept (§6.3 allows both), "file"
30
50
  # otherwise. referenced_by is ordered by citing concept id.
31
51
  attr_reader :entries
32
52
 
33
- # Pointers into references/ that resolve to no file, ordered by concept
34
- # id then field position, each { id:, field:, raw:, resolved:, hint: } —
35
- # hint names the leading-slash fix when the bare spelling exists at the
36
- # root, nil otherwise.
53
+ # Pointers into a references/ that resolve to nothing, ordered by
54
+ # concept id then field position, each { id:, field:, raw:, resolved:,
55
+ # hint: } — hint names the leading-slash fix when the bare spelling, read
56
+ # from the bundle root, names a listed file; nil otherwise. Only the
57
+ # root spelling is tried, not an ancestor directory's references/.
37
58
  attr_reader :dangling
38
59
 
39
- def initialize(bundle, files:)
60
+ def initialize(bundle, files:, present:)
40
61
  @bundle = bundle
41
62
  @files = files.sort
42
63
  @existing = @files.to_set
64
+ @present = present
43
65
  build!
44
66
  end
45
67
 
@@ -55,9 +77,12 @@ module OKF
55
77
  target = Markdown::Links.resolve_path(raw, from: concept.path, bundle: @bundle.root)
56
78
  next if target.nil? # external, empty, or a directory — not a file pointer
57
79
 
80
+ # The resolver leaves a leading-slash path as given, so `.` and `..`
81
+ # are cleaned here, once, for the lookup, the citation and the row.
82
+ target = Pathname.new(target).cleanpath.to_s
58
83
  if @existing.include?(target)
59
84
  (cited[target] ||= []) << { id: concept.id, field: field }
60
- elsif under_references?(target) || bare_references?(raw)
85
+ elsif self.class.inside?(target) && !@present.call(target)
61
86
  @dangling << dangling_row(concept, field, raw, target)
62
87
  end
63
88
  end
@@ -86,20 +111,8 @@ module OKF
86
111
  fields.reject { |_field, raw| OKF.blank?(raw) }
87
112
  end
88
113
 
89
- def under_references?(path)
90
- path.to_s.start_with?("references/")
91
- end
92
-
93
- # The bare spelling of the trap: a raw that *names* references/ without
94
- # the leading slash, which §6.2 resolves relative to the concept. From a
95
- # subdirectory the resolved path leaves references/, so the target check
96
- # above no longer sees it — the raw is what still does.
97
- def bare_references?(raw)
98
- raw.to_s.split("#", 2).first.to_s.start_with?("references/")
99
- end
100
-
101
114
  def dangling_row(concept, field, raw, target)
102
- bare = raw.to_s.split("#", 2).first.to_s
115
+ bare = self.class.bare(raw)
103
116
  hint = nil
104
117
  if !bare.start_with?("/") && bare != target && @existing.include?(bare)
105
118
  hint = "/#{bare} exists — missing leading slash?"
@@ -577,12 +577,17 @@ module OKF
577
577
 
578
578
  # The registry a verb resolves against — the single seam that opts the CLI
579
579
  # into discovery. `cwd: Dir.pwd` is what makes OKF::Registry.load walk up for
580
- # a project-local .okf-registry.json; a library caller passing no cwd stays
580
+ # a project-local .okf.json; a library caller passing no cwd stays
581
581
  # global-only. The registry subcommands and `server` open through here too,
582
582
  # so a bare `okf server` inside a repo serves that repo's bundles.
583
- def open_registry
583
+ # +global+ forces the $OKF_HOME registry by withholding the cwd discovery
584
+ # needs — the per-command form of OKF_NO_DISCOVERY, and the only thing
585
+ # `okf registry -g` does. It is an argument to the `registry` verb rather
586
+ # than a flag on all fourteen, because that verb's *subject* is a registry
587
+ # file; every other verb keeps inheriting the env var's one signal.
588
+ def open_registry(global: false)
584
589
  require "okf/registry"
585
- OKF::Registry.load(cwd: Dir.pwd)
590
+ OKF::Registry.load(cwd: global ? nil : Dir.pwd)
586
591
  end
587
592
 
588
593
  # Resolve one @ref through the active registry — a discovered project-local
@@ -2,12 +2,12 @@
2
2
 
3
3
  module OKF
4
4
  class CLI
5
- # The §6.3 inventory: every file under `references/`, which concepts cite
6
- # it through the §6.2 path-valued fields, and the pointers into
7
- # `references/` that resolve to nothing — with the leading-slash fix named
8
- # when a bare path written from a subdirectory is what missed. An advisory
9
- # read (exit 0): what a curator acts on lives in the output, never the
10
- # status.
5
+ # The §6.3 inventory: every file under a `references/` directory, which
6
+ # concepts cite it through the §6.2 path-valued fields, and the pointers
7
+ # into a `references/` that resolve to nothing — with the leading-slash fix
8
+ # named when a bare path written from a subdirectory is what missed. An
9
+ # advisory read (exit 0): what a curator acts on lives in the output, never
10
+ # the status.
11
11
  class References < Command
12
12
  def self.id
13
13
  :references
@@ -19,7 +19,7 @@ module OKF
19
19
 
20
20
  def self.help_rows
21
21
  [
22
- [ "references <dir|@slug> [--json]", "inventory references/ files and the concepts citing them" ]
22
+ [ "references <dir|@slug> [--json]", "inventory references/ files, at any depth, and the concepts citing them" ]
23
23
  ]
24
24
  end
25
25
 
@@ -77,7 +77,7 @@ module OKF
77
77
  line = " resolves to #{row[:resolved]}, which does not exist"
78
78
  # hint is only ever the leading-slash fix, so the human line can name
79
79
  # the spelling that would have hit without restating the sentence.
80
- line += " — /#{row[:raw]} does (missing leading slash?)" if row[:hint]
80
+ line += " — /#{Bundle::References.bare(row[:raw])} does (missing leading slash?)" if row[:hint]
81
81
  @out.puts line
82
82
  end
83
83
  end