okf-catalog 0.1.0

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 (107) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +10 -0
  4. package/README.md +87 -0
  5. package/dist/bundle/cat-file.js +94 -0
  6. package/dist/bundle/cat-file.js.map +1 -0
  7. package/dist/bundle/contract.js +60 -0
  8. package/dist/bundle/contract.js.map +1 -0
  9. package/dist/bundle/frontmatter.js +106 -0
  10. package/dist/bundle/frontmatter.js.map +1 -0
  11. package/dist/bundle/git-tree.js +109 -0
  12. package/dist/bundle/git-tree.js.map +1 -0
  13. package/dist/bundle/index-file.js +90 -0
  14. package/dist/bundle/index-file.js.map +1 -0
  15. package/dist/bundle/links.js +57 -0
  16. package/dist/bundle/links.js.map +1 -0
  17. package/dist/bundle/load.js +363 -0
  18. package/dist/bundle/load.js.map +1 -0
  19. package/dist/bundle/manifest.js +95 -0
  20. package/dist/bundle/manifest.js.map +1 -0
  21. package/dist/bundle/markdown.js +210 -0
  22. package/dist/bundle/markdown.js.map +1 -0
  23. package/dist/bundle/model.js +7 -0
  24. package/dist/bundle/model.js.map +1 -0
  25. package/dist/bundle/page.js +374 -0
  26. package/dist/bundle/page.js.map +1 -0
  27. package/dist/bundle/paths.js +36 -0
  28. package/dist/bundle/paths.js.map +1 -0
  29. package/dist/bundle/reserved.js +56 -0
  30. package/dist/bundle/reserved.js.map +1 -0
  31. package/dist/bundle/timestamp.js +49 -0
  32. package/dist/bundle/timestamp.js.map +1 -0
  33. package/dist/catalog/model.js +32 -0
  34. package/dist/catalog/model.js.map +1 -0
  35. package/dist/catalog/nearest.js +56 -0
  36. package/dist/catalog/nearest.js.map +1 -0
  37. package/dist/catalog/outputs.js +438 -0
  38. package/dist/catalog/outputs.js.map +1 -0
  39. package/dist/catalog/provenance.js +37 -0
  40. package/dist/catalog/provenance.js.map +1 -0
  41. package/dist/catalog/runtime.js +2 -0
  42. package/dist/catalog/runtime.js.map +1 -0
  43. package/dist/catalog/text.js +140 -0
  44. package/dist/catalog/text.js.map +1 -0
  45. package/dist/cli.js +81 -0
  46. package/dist/cli.js.map +1 -0
  47. package/dist/commands/check.js +155 -0
  48. package/dist/commands/check.js.map +1 -0
  49. package/dist/commands/pack.js +182 -0
  50. package/dist/commands/pack.js.map +1 -0
  51. package/dist/commands/serve.js +452 -0
  52. package/dist/commands/serve.js.map +1 -0
  53. package/dist/config/company-config.js +272 -0
  54. package/dist/config/company-config.js.map +1 -0
  55. package/dist/derive/derived-document.js +42 -0
  56. package/dist/derive/derived-document.js.map +1 -0
  57. package/dist/engine/qmd-render.js +54 -0
  58. package/dist/engine/qmd-render.js.map +1 -0
  59. package/dist/engine/qmd.js +241 -0
  60. package/dist/engine/qmd.js.map +1 -0
  61. package/dist/fs/cache-dir.js +140 -0
  62. package/dist/fs/cache-dir.js.map +1 -0
  63. package/dist/fs/company-lock.js +162 -0
  64. package/dist/fs/company-lock.js.map +1 -0
  65. package/dist/fs/walk.js +168 -0
  66. package/dist/fs/walk.js.map +1 -0
  67. package/dist/log.js +65 -0
  68. package/dist/log.js.map +1 -0
  69. package/dist/mcp/server.js +30 -0
  70. package/dist/mcp/server.js.map +1 -0
  71. package/dist/mcp/stdio.js +45 -0
  72. package/dist/mcp/stdio.js.map +1 -0
  73. package/dist/mcp/tools.js +249 -0
  74. package/dist/mcp/tools.js.map +1 -0
  75. package/dist/report/report.js +43 -0
  76. package/dist/report/report.js.map +1 -0
  77. package/dist/search/engine.js +2 -0
  78. package/dist/search/engine.js.map +1 -0
  79. package/dist/search/query.js +91 -0
  80. package/dist/search/query.js.map +1 -0
  81. package/dist/search/search.js +224 -0
  82. package/dist/search/search.js.map +1 -0
  83. package/dist/search/snippet.js +95 -0
  84. package/dist/search/snippet.js.map +1 -0
  85. package/dist/serve/poller.js +119 -0
  86. package/dist/serve/poller.js.map +1 -0
  87. package/dist/serve/runtime.js +390 -0
  88. package/dist/serve/runtime.js.map +1 -0
  89. package/dist/source/git-runner.js +232 -0
  90. package/dist/source/git-runner.js.map +1 -0
  91. package/dist/source/git.js +457 -0
  92. package/dist/source/git.js.map +1 -0
  93. package/dist/source/local.js +20 -0
  94. package/dist/source/local.js.map +1 -0
  95. package/dist/source/source.js +2 -0
  96. package/dist/source/source.js.map +1 -0
  97. package/npm-shrinkwrap.json +5482 -0
  98. package/package.json +80 -0
  99. package/plugin/claude-code/.claude-plugin/plugin.json +15 -0
  100. package/plugin/claude-code/.mcp.json +10 -0
  101. package/plugin/claude-code/skills/okf-catalog/SKILL.md +15 -0
  102. package/recipes/publish/README.md +32 -0
  103. package/recipes/publish/checkers.lock +435 -0
  104. package/recipes/publish/checkers.txt +5 -0
  105. package/recipes/publish/pack.sh +60 -0
  106. package/recipes/publish/publish.yml +88 -0
  107. package/recipes/publish/push.sh +63 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). The version in `package.json` names the release. 0.1.0 is published before the clean-account run of the acceptance list in `docs/acceptance/version-0.md`, by the maintainer's choice; what that run finds goes into 0.1.1.
4
+
5
+ ## [0.1.0] - 2026-10-07
6
+
7
+ Version 0: serve a company's Open Knowledge Format 0.2 bundle to Claude Code, locally. Needs Node 24 or later (the Active LTS line) on macOS or Linux.
8
+
9
+ ### Added
10
+
11
+ - `okf-catalog serve`: a stdio MCP server over one company's bundle, lexical mode, with four read-only tools. `search` takes keywords and the type, topic, overdue and limit filters, and returns every hit with its path, trust tier, verifier, recheck date, source count and resource, in the text and in the structured output; `get_page` returns a page's header, a marker line and the body as data, with its provenance; `catalog` lists a folder from its index file or generates the listing; `status` reports the load, the lock, the poller, the fetched commit and every degradation and refusal.
12
+ - The intake contract: pages are read by the specification's field table (`type`, `title`, `description`, `tags`, `status`, `stale_after` in both 0.2 texts, `generated`, `verified`, `sources`, `resource`, links, reserved files), degrade and are reported rather than refused (specification §11), and only a page without frontmatter or a type, an unsafe or oversize file, a hash mismatch or a missing manifest is refused.
13
+ - `okf-catalog check`: the contract applied to a folder, with the report as text or JSON and an exit code.
14
+ - `okf-catalog pack`: the published bundle written from a checkout, with generated index files and a manifest.
15
+ - A company configuration file (`okf-catalog.yaml`): the company name, a local folder or a git repository with its branch and bundle path, the admission rule, the development flag, the pull interval, the caps, the declared types and the specification text.
16
+ - The cache folder per company with its ownership and mode checks, and one process per company through a lock, with a private fallback for a second process.
17
+ - The git source: a bare shallow clone used as transport only, every fetched tree listed and validated before anything is written, raw blobs extracted into the server's own folder, a hardened runner, and a poller that refreshes when the branch moves.
18
+ - The publish recipe: a GitHub Actions workflow and two shell scripts that run the OKF checkers, pack, run them again, and push parent-linked commits to the published branch.
19
+ - The Claude Code plugin folder with the skill, shipped inside the package; the plugin asks for no settings and runs the `okf-catalog` command from PATH in the project folder, where the server finds `okf-catalog.yaml`.
20
+ - The benchmark harness over four public OKF bundles, with the lexical-versus-full measurement behind the maintainer's model approval.
21
+
22
+ ### Not in this version
23
+
24
+ HTTP transport and authorization, full mode as a product option, Codex and Grok Build plugins, Windows, npm publication.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ okf-catalog
2
+ Copyright 2026 Bitfusion PR LLC (bitfusion.tech) and the okf-catalog contributors
3
+
4
+ Licensed under the Apache License, Version 2.0; see LICENSE.
5
+
6
+ The fixture bundle under test/fixtures/bundles/spec-example is a verbatim
7
+ copy of the example bundle bundles/acme_retail from the Open Knowledge Format
8
+ repository, https://github.com/GoogleCloudPlatform/open-knowledge-format, at
9
+ commit 25461dbcdd5b2f3fc9aef99c19fb7d8a94ef6149, which is licensed under the
10
+ Apache License, Version 2.0. test/fixtures/README.md records what was copied.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # okf-catalog
2
+
3
+ A small-company hosted knowledge catalog for AI agents.
4
+
5
+ okf-catalog is an MCP server that serves a company's [Open Knowledge Format](https://github.com/GoogleCloudPlatform/open-knowledge-format) bundle to agents. It runs on a developer's machine today and from a cheap cloud recipe later, so that local coding agents (Claude Code, Codex, Grok Build) and the web versions of Claude and ChatGPT answer from the same cited knowledge.
6
+
7
+ What it adds: **qmd done right for OKF.** [qmd](https://github.com/tobi/qmd) is the best Markdown search engine there is. okf-catalog makes it understand OKF's fields: titles, descriptions and tags ranked as they should be, status and recheck dates respected, trust and provenance returned with every answer, deprecated pages pointing to their replacements.
8
+
9
+ **Status: version 0 release candidate (0.1.0), not yet accepted, not published.** Every item of the version 0 acceptance list that a test can prove is proven on every run; the items that need a person on a clean account (a signed-in Claude Code answering from a bundle, a real publish, the network off) are pending, with their runbook in [docs/acceptance/version-0.md](docs/acceptance/version-0.md). The package is marked private and nothing is on npm; the licence is Apache-2.0 (decision D1). Start with [docs/intent.md](docs/intent.md); the implementation plan and its execution record are under [docs/plans/](docs/plans/).
10
+
11
+ ## Quickstart
12
+
13
+ Once the package is on npm, the install is one command, and the `okf-catalog` command lands on your PATH:
14
+
15
+ ```bash
16
+ NODE_LLAMA_CPP_SKIP_DOWNLOAD=1 npm install -g okf-catalog
17
+ ```
18
+
19
+ Until then, or to work on the code, use a checkout:
20
+
21
+ ```bash
22
+ git clone https://github.com/drathm/okf-catalog.git && cd okf-catalog
23
+ NODE_LLAMA_CPP_SKIP_DOWNLOAD=1 npm ci
24
+ ```
25
+
26
+ `npm ci` builds `dist/` on its way out (the `prepare` script), and the flag keeps qmd's native dependency from downloading or compiling anything: lexical mode needs no model. Check the install and a bundle (`node dist/cli.js` in a checkout stands in for `okf-catalog`, or `npm install -g .` puts the command on PATH):
27
+
28
+ ```bash
29
+ okf-catalog --version
30
+ okf-catalog check path/to/bundle --integrity none --types Term,Guide
31
+ ```
32
+
33
+ Write the company's configuration, `okf-catalog.yaml`. A folder on this machine, served as it is, drafts admitted and labelled:
34
+
35
+ ```yaml
36
+ company: acme
37
+ source:
38
+ local: ./knowledge
39
+ serve:
40
+ dev: true
41
+ types: [Term, Guide, Policy]
42
+ ```
43
+
44
+ Or a published branch, fetched into the server's own cache and polled:
45
+
46
+ ```yaml
47
+ company: acme
48
+ source:
49
+ repository: git@github.com:acme/knowledge.git
50
+ branch: published
51
+ bundle_path: kb
52
+ serve:
53
+ pull_interval: 10m
54
+ types: [Term, Guide, Policy]
55
+ ```
56
+
57
+ Give it to Claude Code through the plugin, which asks for no settings: it runs the `okf-catalog` command from PATH in the project folder, where the server finds `okf-catalog.yaml` (or the file named by `OKF_CATALOG_CONFIG`). The plugin folder ships inside the package:
58
+
59
+ ```bash
60
+ claude --plugin-dir "$(npm root -g)/okf-catalog/plugin/claude-code"
61
+ ```
62
+
63
+ From a checkout, `npm install -g .` puts the command on PATH and `claude --plugin-dir ./plugin/claude-code` loads the same plugin. In the session, `/mcp` shows the `okf-catalog` server connected, and the skill tells Claude to search with keywords, read pages whole and cite the path, the trust tier, the verifier and the recheck date. The server can also be started from a shell with `okf-catalog serve --config okf-catalog.yaml`; it speaks MCP over stdio.
64
+
65
+ To publish, `node dist/cli.js pack --config okf-catalog.yaml --from ./knowledge --out ./published` writes what a server serves; `recipes/publish/` has the workflow and scripts that run the OKF checkers around it and push the branch. Not in this version: full mode, a hosted server, Windows, a registry install.
66
+
67
+ ## Requirements
68
+
69
+ - Node 24 or later (the Active LTS line when version 0 was built), on macOS or Linux (Windows is not a version 0 host: the cache folder's ownership and mode checks assume POSIX).
70
+ - The cache folder (`$XDG_CACHE_HOME/okf-catalog/<company>`, or the platform's user cache folder) must be on a local filesystem: the one-process-per-company lock is an operating-system lock on a SQLite file, which network filesystems do not honour reliably, and it must not lie inside the bundle folder.
71
+
72
+ ## Publishing
73
+
74
+ A server reads a `published` branch, which `okf-catalog pack` writes from a bundle folder: the admitted pages, their index files, the attachments and a manifest. `recipes/publish/` holds the GitHub Actions workflow and the two shell scripts that produce that branch on every push to the source branch, with the OKF checkers run before and after `pack`. A configuration with `source.repository`, `branch` and `bundle_path` serves that branch and polls it at `serve.pull_interval`; one with `source.local` serves a folder as it is.
75
+
76
+ ## Documents
77
+
78
+ | Document | Holds |
79
+ |---|---|
80
+ | [docs/intent.md](docs/intent.md) | What this is, for whom, what it must do, and how done is judged |
81
+ | [docs/architecture.md](docs/architecture.md) | The layers, the data flow at serve time, the publish loop, and what lives where |
82
+ | [docs/decisions/0001-founding-decisions.md](docs/decisions/0001-founding-decisions.md) | Every decision behind the design, what was rejected and why, and whether it is settled |
83
+ | [docs/research/](docs/research/) | The verified facts the design rests on, with sources and dates |
84
+
85
+ ## Licence
86
+
87
+ Apache-2.0 (see `LICENSE` and `NOTICE`); okf-catalog is a product of Bitfusion PR LLC (bitfusion.tech), settled in decision D1 on 2026-10-07. Contributions need the one-time signature of [CLA.md](CLA.md), which keeps a later change of licence possible; see [CONTRIBUTING.md](CONTRIBUTING.md).
@@ -0,0 +1,94 @@
1
+ const HEADER = /^([0-9a-f]{40,64}) (\S+)(?: (\d+))?$/;
2
+ const utf8 = new TextDecoder("utf-8");
3
+ const concat = (parts) => {
4
+ let length = 0;
5
+ for (const part of parts)
6
+ length += part.length;
7
+ const out = new Uint8Array(length);
8
+ let at = 0;
9
+ for (const part of parts) {
10
+ out.set(part, at);
11
+ at += part.length;
12
+ }
13
+ return out;
14
+ };
15
+ const indexOfNewline = (bytes) => {
16
+ for (let i = 0; i < bytes.length; i++)
17
+ if (bytes[i] === 0x0a)
18
+ return i;
19
+ return -1;
20
+ };
21
+ /**
22
+ * Reads `cat-file --batch` output for a known list of blobs, in order: `<sha> blob <size>\n`, the raw bytes, a
23
+ * newline. Each header is checked against the listing (the object, its type and its size) before a byte of
24
+ * content is kept, so a header that lies is never buffered (bite 5 review m1). Blob bytes reach `onBlob` whole.
25
+ */
26
+ export function createBatchReader(expected, onBlob) {
27
+ const queue = [...expected];
28
+ let pending = new Uint8Array(0);
29
+ let current;
30
+ let awaitingNewline = false;
31
+ let done = false;
32
+ function feed(chunk) {
33
+ if (done) {
34
+ if (chunk.length > 0)
35
+ throw new Error("cat-file printed more after the last blob");
36
+ return;
37
+ }
38
+ pending = pending.length === 0 ? chunk : concat([pending, chunk]);
39
+ for (;;) {
40
+ if (awaitingNewline) {
41
+ if (pending.length === 0)
42
+ return;
43
+ if (pending[0] !== 0x0a)
44
+ throw new Error("cat-file printed an unexpected byte after a blob");
45
+ pending = pending.subarray(1);
46
+ awaitingNewline = false;
47
+ if (queue.length === 0) {
48
+ done = true;
49
+ if (pending.length > 0)
50
+ throw new Error("cat-file printed more after the last blob");
51
+ return;
52
+ }
53
+ }
54
+ if (current === undefined) {
55
+ const newline = indexOfNewline(pending);
56
+ if (newline === -1)
57
+ return;
58
+ const header = utf8.decode(pending.subarray(0, newline));
59
+ pending = pending.subarray(newline + 1);
60
+ const match = HEADER.exec(header);
61
+ const next = queue[0];
62
+ if (match === null || next === undefined)
63
+ throw new Error("cat-file printed a header this reader cannot parse");
64
+ if (match[2] === "missing")
65
+ throw new Error(`the object for ${next.path} is missing`);
66
+ if (match[1] !== next.sha)
67
+ throw new Error(`cat-file answered ${match[1]} where ${next.sha} was expected`);
68
+ if (match[2] !== "blob")
69
+ throw new Error(`the object for ${next.path} is a ${match[2]}, not a blob`);
70
+ if (Number(match[3] ?? -1) !== next.size)
71
+ throw new Error(`cat-file reports size ${match[3] ?? "?"} for ${next.path}, the listing said ${next.size}`);
72
+ queue.shift();
73
+ current = { entry: next, got: [], gotLength: 0 };
74
+ }
75
+ const take = Math.min(current.entry.size - current.gotLength, pending.length);
76
+ if (take > 0) {
77
+ current.got.push(pending.subarray(0, take));
78
+ current.gotLength += take;
79
+ pending = pending.subarray(take);
80
+ }
81
+ if (current.gotLength < current.entry.size)
82
+ return;
83
+ onBlob(current.entry, concat(current.got));
84
+ current = undefined;
85
+ awaitingNewline = true;
86
+ }
87
+ }
88
+ function finish() {
89
+ if (queue.length > 0 || current !== undefined || awaitingNewline)
90
+ throw new Error("cat-file ended before every blob arrived");
91
+ }
92
+ return { feed, finish };
93
+ }
94
+ //# sourceMappingURL=cat-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cat-file.js","sourceRoot":"","sources":["../../src/bundle/cat-file.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,GAAG,sCAAsC,CAAC;AACtD,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;AAEtC,MAAM,MAAM,GAAG,CAAC,KAA4B,EAAc,EAAE;IAC1D,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;IAChD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAClB,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AACF,MAAM,cAAc,GAAG,CAAC,KAAiB,EAAU,EAAE;IACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI;YAAE,OAAO,CAAC,CAAC;IACvE,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAAiC,EACjC,MAAwD;IAExD,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAC5B,IAAI,OAAO,GAAe,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5C,IAAI,OAAkF,CAAC;IACvF,IAAI,eAAe,GAAG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C,EAAE,CAAC;gBACb,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;gBAC5C,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;gBAC1B,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC;YACD,IAAI,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI;gBAAE,OAAO;YACnD,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3C,OAAO,GAAG,SAAS,CAAC;YACpB,eAAe,GAAG,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;IAED,SAAS,MAAM;QACb,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,KAAK,SAAS,IAAI,eAAe;YAC9D,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["/** What one `cat-file --batch` answer must be: the blob asked for, at the size the listing gave. */\nexport interface ExpectedBlob {\n sha: string;\n size: number;\n path: string;\n}\n\nexport interface BatchReader {\n /** Feeds the next chunk of stdout; throws on the first byte that is not what the listing promised. */\n feed(chunk: Uint8Array): void;\n /** Called at the end of stdout; throws when a blob is still owed. */\n finish(): void;\n}\n\nconst HEADER = /^([0-9a-f]{40,64}) (\\S+)(?: (\\d+))?$/;\nconst utf8 = new TextDecoder(\"utf-8\");\n\nconst concat = (parts: readonly Uint8Array[]): Uint8Array => {\n let length = 0;\n for (const part of parts) length += part.length;\n const out = new Uint8Array(length);\n let at = 0;\n for (const part of parts) {\n out.set(part, at);\n at += part.length;\n }\n return out;\n};\nconst indexOfNewline = (bytes: Uint8Array): number => {\n for (let i = 0; i < bytes.length; i++) if (bytes[i] === 0x0a) return i;\n return -1;\n};\n\n/**\n * Reads `cat-file --batch` output for a known list of blobs, in order: `<sha> blob <size>\\n`, the raw bytes, a\n * newline. Each header is checked against the listing (the object, its type and its size) before a byte of\n * content is kept, so a header that lies is never buffered (bite 5 review m1). Blob bytes reach `onBlob` whole.\n */\nexport function createBatchReader(\n expected: readonly ExpectedBlob[],\n onBlob: (entry: ExpectedBlob, bytes: Uint8Array) => void,\n): BatchReader {\n const queue = [...expected];\n let pending: Uint8Array = new Uint8Array(0);\n let current: { entry: ExpectedBlob; got: Uint8Array[]; gotLength: number } | undefined;\n let awaitingNewline = false;\n let done = false;\n\n function feed(chunk: Uint8Array): void {\n if (done) {\n if (chunk.length > 0) throw new Error(\"cat-file printed more after the last blob\");\n return;\n }\n pending = pending.length === 0 ? chunk : concat([pending, chunk]);\n for (;;) {\n if (awaitingNewline) {\n if (pending.length === 0) return;\n if (pending[0] !== 0x0a)\n throw new Error(\"cat-file printed an unexpected byte after a blob\");\n pending = pending.subarray(1);\n awaitingNewline = false;\n if (queue.length === 0) {\n done = true;\n if (pending.length > 0) throw new Error(\"cat-file printed more after the last blob\");\n return;\n }\n }\n if (current === undefined) {\n const newline = indexOfNewline(pending);\n if (newline === -1) return;\n const header = utf8.decode(pending.subarray(0, newline));\n pending = pending.subarray(newline + 1);\n const match = HEADER.exec(header);\n const next = queue[0];\n if (match === null || next === undefined)\n throw new Error(\"cat-file printed a header this reader cannot parse\");\n if (match[2] === \"missing\") throw new Error(`the object for ${next.path} is missing`);\n if (match[1] !== next.sha)\n throw new Error(`cat-file answered ${match[1]} where ${next.sha} was expected`);\n if (match[2] !== \"blob\")\n throw new Error(`the object for ${next.path} is a ${match[2]}, not a blob`);\n if (Number(match[3] ?? -1) !== next.size)\n throw new Error(\n `cat-file reports size ${match[3] ?? \"?\"} for ${next.path}, the listing said ${next.size}`,\n );\n queue.shift();\n current = { entry: next, got: [], gotLength: 0 };\n }\n const take = Math.min(current.entry.size - current.gotLength, pending.length);\n if (take > 0) {\n current.got.push(pending.subarray(0, take));\n current.gotLength += take;\n pending = pending.subarray(take);\n }\n if (current.gotLength < current.entry.size) return;\n onBlob(current.entry, concat(current.got));\n current = undefined;\n awaitingNewline = true;\n }\n }\n\n function finish(): void {\n if (queue.length > 0 || current !== undefined || awaitingNewline)\n throw new Error(\"cat-file ended before every blob arrived\");\n }\n\n return { feed, finish };\n}\n"]}
@@ -0,0 +1,60 @@
1
+ /** The company's admission rule. The development flag admits drafts, and so the unknown statuses read as draft. */
2
+ export function admit(page, admitStatuses, dev) {
3
+ return admitStatuses.includes(page.status) || (dev && page.status === "draft");
4
+ }
5
+ /** Type values the company did not declare. Nothing is unknown when nothing is declared. */
6
+ export function unknownTypes(pages, declared) {
7
+ if (declared === undefined || declared.length === 0)
8
+ return [];
9
+ const known = new Set(declared);
10
+ const unknown = new Set();
11
+ for (const page of pages)
12
+ if (!known.has(page.type))
13
+ unknown.add(page.type);
14
+ return [...unknown].sort();
15
+ }
16
+ /** A path with a dot-leading segment is hidden: skipped and counted, never a page or an attachment. */
17
+ export function isHidden(path) {
18
+ return path.split("/").some((segment) => segment.startsWith("."));
19
+ }
20
+ /** The search engine's own configuration has no business inside a bundle; such a path is refused. */
21
+ export function isEngineConfig(path) {
22
+ return path.split("/").some((segment) => segment === ".qmd");
23
+ }
24
+ /** Caps: one oversize file is refused on its own; too many files or too large a tree refuses the bundle. */
25
+ export function capRefusals(files, caps) {
26
+ const perFile = [];
27
+ let total = 0;
28
+ for (const file of files) {
29
+ total += file.bytes.length;
30
+ if (file.bytes.length > caps.fileBytes) {
31
+ perFile.push({
32
+ path: file.path,
33
+ rule: "oversize",
34
+ detail: `${file.bytes.length} bytes exceeds the cap of ${caps.fileBytes}`,
35
+ });
36
+ }
37
+ }
38
+ if (files.length > caps.files) {
39
+ return {
40
+ fatal: {
41
+ path: "",
42
+ rule: "too-many-files",
43
+ detail: `${files.length} files exceeds the cap of ${caps.files}`,
44
+ },
45
+ perFile,
46
+ };
47
+ }
48
+ if (total > caps.treeBytes) {
49
+ return {
50
+ fatal: {
51
+ path: "",
52
+ rule: "tree-too-large",
53
+ detail: `${total} bytes exceeds the cap of ${caps.treeBytes}`,
54
+ },
55
+ perFile,
56
+ };
57
+ }
58
+ return { perFile };
59
+ }
60
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/bundle/contract.ts"],"names":[],"mappings":"AAEA,mHAAmH;AACnH,MAAM,UAAU,KAAK,CAAC,IAAU,EAAE,aAAuB,EAAE,GAAY;IACrE,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC;AACjF,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,QAA8B;IACxE,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,qGAAqG;AACrG,MAAM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AC;AACrB,CAAC","sourcesContent":["import type { BundleFile, Caps, Page, Refusal, Status } from \"./model.js\";\n\n/** The company's admission rule. The development flag admits drafts, and so the unknown statuses read as draft. */\nexport function admit(page: Page, admitStatuses: Status[], dev: boolean): boolean {\n return admitStatuses.includes(page.status) || (dev && page.status === \"draft\");\n}\n\n/** Type values the company did not declare. Nothing is unknown when nothing is declared. */\nexport function unknownTypes(pages: Page[], declared: string[] | undefined): string[] {\n if (declared === undefined || declared.length === 0) return [];\n const known = new Set(declared);\n const unknown = new Set<string>();\n for (const page of pages) if (!known.has(page.type)) unknown.add(page.type);\n return [...unknown].sort();\n}\n\n/** A path with a dot-leading segment is hidden: skipped and counted, never a page or an attachment. */\nexport function isHidden(path: string): boolean {\n return path.split(\"/\").some((segment) => segment.startsWith(\".\"));\n}\n\n/** The search engine's own configuration has no business inside a bundle; such a path is refused. */\nexport function isEngineConfig(path: string): boolean {\n return path.split(\"/\").some((segment) => segment === \".qmd\");\n}\n\n/** Caps: one oversize file is refused on its own; too many files or too large a tree refuses the bundle. */\nexport function capRefusals(\n files: BundleFile[],\n caps: Caps,\n): { fatal?: Refusal; perFile: Refusal[] } {\n const perFile: Refusal[] = [];\n let total = 0;\n for (const file of files) {\n total += file.bytes.length;\n if (file.bytes.length > caps.fileBytes) {\n perFile.push({\n path: file.path,\n rule: \"oversize\",\n detail: `${file.bytes.length} bytes exceeds the cap of ${caps.fileBytes}`,\n });\n }\n }\n if (files.length > caps.files) {\n return {\n fatal: {\n path: \"\",\n rule: \"too-many-files\",\n detail: `${files.length} files exceeds the cap of ${caps.files}`,\n },\n perFile,\n };\n }\n if (total > caps.treeBytes) {\n return {\n fatal: {\n path: \"\",\n rule: \"tree-too-large\",\n detail: `${total} bytes exceeds the cap of ${caps.treeBytes}`,\n },\n perFile,\n };\n }\n return { perFile };\n}\n"]}
@@ -0,0 +1,106 @@
1
+ import { isMap, isScalar, parseDocument } from "yaml";
2
+ import { BOM } from "./paths.js";
3
+ export function decodeUtf8(bytes) {
4
+ try {
5
+ return { ok: true, text: new TextDecoder("utf-8", { fatal: true }).decode(bytes) };
6
+ }
7
+ catch {
8
+ return { ok: false };
9
+ }
10
+ }
11
+ /**
12
+ * Splits a page into its frontmatter block and body. The block is present only when the text opens with
13
+ * a `---` line and a later line is exactly `---` or `...`; both fences may carry trailing spaces or tabs, as
14
+ * the OKF checkers accept. Fence lines and a trailing newline are dropped from the block; the body is
15
+ * everything after the closing fence as written.
16
+ */
17
+ export function splitFrontmatter(text) {
18
+ const t = text.startsWith(BOM) ? text.slice(1) : text;
19
+ const opening = /^---[ \t]*\r?\n/.exec(t);
20
+ if (!opening)
21
+ return { body: t };
22
+ const start = opening[0].length;
23
+ let i = start;
24
+ for (;;) {
25
+ const nl = t.indexOf("\n", i);
26
+ const line = nl === -1 ? t.slice(i) : t.slice(i, nl);
27
+ const bare = line.replace(/[ \t\r]+$/, "");
28
+ if (bare === "---" || bare === "...") {
29
+ return {
30
+ block: t.slice(start, i).replace(/\r?\n$/, ""),
31
+ body: nl === -1 ? "" : t.slice(nl + 1),
32
+ };
33
+ }
34
+ if (nl === -1)
35
+ return { body: t, unclosed: true };
36
+ i = nl + 1;
37
+ }
38
+ }
39
+ /** A YAML diagnostic as a file position: the block starts on the line after the opening fence. */
40
+ function describe(e, fenceLine, block) {
41
+ const pos = e.linePos?.[0];
42
+ const where = pos === undefined ? "" : ` at line ${pos.line + fenceLine}, column ${pos.col}`;
43
+ if (e.code === "DUPLICATE_KEY") {
44
+ // The parser's position covers one character of the repeated key; the key is the text before the colon on that line.
45
+ const line = pos === undefined ? undefined : block.split("\n")[pos.line - 1];
46
+ const key = line === undefined
47
+ ? ""
48
+ : (/^\s*(?:-\s*)?["']?([^"':]+?)["']?\s*:/.exec(line)?.[1] ?? "").trim();
49
+ return key.length === 0 ? `duplicate key${where}` : `duplicate key "${key}"${where}`;
50
+ }
51
+ const first = e.message
52
+ .split("\n")[0]
53
+ ?.replace(/\s+at line \d+, column \d+:?\s*$/, "")
54
+ .replace(/:\s*$/, "") ?? e.code;
55
+ return `${first}${where}`;
56
+ }
57
+ /**
58
+ * Parses a frontmatter block as YAML 1.2 with the core schema: dates stay strings, explicit tags are not
59
+ * resolved, duplicate keys are errors, and a cycle or a non-mapping is an error. `sources` keeps the text
60
+ * of each top-level scalar as written, so `type: 123` can still be read as "123". `fenceLine` is the file
61
+ * line of the opening fence, so diagnostics point at file lines.
62
+ */
63
+ export function parseFrontmatter(block, fenceLine = 1) {
64
+ const doc = parseDocument(block, {
65
+ version: "1.2",
66
+ schema: "core",
67
+ uniqueKeys: true,
68
+ resolveKnownTags: false,
69
+ logLevel: "silent",
70
+ });
71
+ if (doc.errors.length > 0) {
72
+ return { ok: false, error: doc.errors.map((e) => describe(e, fenceLine, block)).join("; ") };
73
+ }
74
+ let data;
75
+ try {
76
+ data = doc.toJS({ maxAliasCount: 100 });
77
+ }
78
+ catch (error) {
79
+ return { ok: false, error: `frontmatter could not be read: ${error.message}` };
80
+ }
81
+ if (data === null || data === undefined)
82
+ data = {};
83
+ if (typeof data !== "object" || Array.isArray(data))
84
+ return { ok: false, error: "frontmatter is not a mapping" };
85
+ try {
86
+ JSON.stringify(data);
87
+ }
88
+ catch {
89
+ return { ok: false, error: "frontmatter contains a cycle" };
90
+ }
91
+ const sources = Object.create(null);
92
+ if (isMap(doc.contents)) {
93
+ for (const pair of doc.contents.items) {
94
+ if (isScalar(pair.key) && isScalar(pair.value) && typeof pair.value.source === "string") {
95
+ sources[String(pair.key.value)] = pair.value.source;
96
+ }
97
+ }
98
+ }
99
+ return {
100
+ ok: true,
101
+ data: data,
102
+ warnings: doc.warnings.map((w) => describe(w, fenceLine, block)),
103
+ sources,
104
+ };
105
+ }
106
+ //# sourceMappingURL=frontmatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/bundle/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa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\";\n\nexport function decodeUtf8(bytes: Uint8Array): { ok: true; text: string } | { ok: false } {\n try {\n return { ok: true, text: new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes) };\n } catch {\n return { ok: false };\n }\n}\n\nexport interface Split {\n block?: string;\n body: string;\n /** True when a fence opened the file and no line closed it. */\n unclosed?: boolean;\n}\n\n/**\n * Splits a page into its frontmatter block and body. The block is present only when the text opens with\n * a `---` line and a later line is exactly `---` or `...`; both fences may carry trailing spaces or tabs, as\n * the OKF checkers accept. Fence lines and a trailing newline are dropped from the block; the body is\n * everything after the closing fence as written.\n */\nexport function splitFrontmatter(text: string): Split {\n const t = text.startsWith(BOM) ? text.slice(1) : text;\n const opening = /^---[ \\t]*\\r?\\n/.exec(t);\n if (!opening) return { body: t };\n const start = opening[0].length;\n let i = start;\n for (;;) {\n const nl = t.indexOf(\"\\n\", i);\n const line = nl === -1 ? t.slice(i) : t.slice(i, nl);\n const bare = line.replace(/[ \\t\\r]+$/, \"\");\n if (bare === \"---\" || bare === \"...\") {\n return {\n block: t.slice(start, i).replace(/\\r?\\n$/, \"\"),\n body: nl === -1 ? \"\" : t.slice(nl + 1),\n };\n }\n if (nl === -1) return { body: t, unclosed: true };\n i = nl + 1;\n }\n}\n\nexport type FrontmatterResult =\n | { ok: true; data: Record<string, unknown>; warnings: string[]; sources: Record<string, string> }\n | { ok: false; error: string };\n\ninterface Diagnostic {\n code: string;\n message: string;\n linePos?: Array<{ line: number; col: number }>;\n pos?: [number, number];\n}\n\n/** A YAML diagnostic as a file position: the block starts on the line after the opening fence. */\nfunction describe(e: Diagnostic, fenceLine: number, block: string): string {\n const pos = e.linePos?.[0];\n const where = pos === undefined ? \"\" : ` at line ${pos.line + fenceLine}, column ${pos.col}`;\n if (e.code === \"DUPLICATE_KEY\") {\n // The parser's position covers one character of the repeated key; the key is the text before the colon on that line.\n const line = pos === undefined ? undefined : block.split(\"\\n\")[pos.line - 1];\n const key =\n line === undefined\n ? \"\"\n : (/^\\s*(?:-\\s*)?[\"']?([^\"':]+?)[\"']?\\s*:/.exec(line)?.[1] ?? \"\").trim();\n return key.length === 0 ? `duplicate key${where}` : `duplicate key \"${key}\"${where}`;\n }\n const first =\n e.message\n .split(\"\\n\")[0]\n ?.replace(/\\s+at line \\d+, column \\d+:?\\s*$/, \"\")\n .replace(/:\\s*$/, \"\") ?? e.code;\n return `${first}${where}`;\n}\n\n/**\n * Parses a frontmatter block as YAML 1.2 with the core schema: dates stay strings, explicit tags are not\n * resolved, duplicate keys are errors, and a cycle or a non-mapping is an error. `sources` keeps the text\n * of each top-level scalar as written, so `type: 123` can still be read as \"123\". `fenceLine` is the file\n * line of the opening fence, so diagnostics point at file lines.\n */\nexport function parseFrontmatter(block: string, fenceLine = 1): FrontmatterResult {\n const doc = parseDocument(block, {\n version: \"1.2\",\n schema: \"core\",\n uniqueKeys: true,\n resolveKnownTags: false,\n logLevel: \"silent\",\n });\n if (doc.errors.length > 0) {\n return { ok: false, error: doc.errors.map((e) => describe(e, fenceLine, block)).join(\"; \") };\n }\n let data: unknown;\n try {\n data = doc.toJS({ maxAliasCount: 100 });\n } catch (error) {\n return { ok: false, error: `frontmatter could not be read: ${(error as Error).message}` };\n }\n if (data === null || data === undefined) data = {};\n if (typeof data !== \"object\" || Array.isArray(data))\n return { ok: false, error: \"frontmatter is not a mapping\" };\n try {\n JSON.stringify(data);\n } catch {\n return { ok: false, error: \"frontmatter contains a cycle\" };\n }\n const sources: Record<string, string> = Object.create(null) as Record<string, string>;\n if (isMap(doc.contents)) {\n for (const pair of doc.contents.items) {\n if (isScalar(pair.key) && isScalar(pair.value) && typeof pair.value.source === \"string\") {\n sources[String(pair.key.value)] = pair.value.source;\n }\n }\n }\n return {\n ok: true,\n data: data as Record<string, unknown>,\n warnings: doc.warnings.map((w) => describe(w, fenceLine, block)),\n sources,\n };\n}\n"]}