@quillmark/quiver 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 (4) hide show
  1. package/LICENSE +201 -0
  2. package/PROGRAM.md +420 -0
  3. package/README.md +96 -0
  4. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/PROGRAM.md ADDED
@@ -0,0 +1,420 @@
1
+ # Program: Quivers Rewrite (`@quillmark/quiver`)
2
+
3
+ **Status:** Updated for upstream Quillmark Render API overhaul
4
+ **Audience:** Senior engineer planning and executing V1
5
+ **Scope:** This document applies only to the **Node/npm** package **`@quillmark/quiver`**: a smaller surface than `@quillmark/registry`, aligned with the **JavaScript/WASM** Quillmark bindings (not Python or other language bindings).
6
+
7
+ ## Summary
8
+
9
+ V1 still introduces Quivers as the primary runtime abstraction, but one boundary changed materially upstream:
10
+
11
+ - Quillmark no longer owns a quill registry
12
+ - Rendering lives on `Quill` (`quill.render(...)`), not the engine
13
+ - Engine is now a backend registry + quill factory (`engine.quill(tree)` on the Quillmark WASM binding, typically `@quillmark/wasm`)
14
+
15
+ This means Quiver must own quill selection and lifecycle entirely. There is no engine `registerQuill`, `hasQuill`, or engine-level render hot path to optimize around.
16
+
17
+ ---
18
+
19
+ ## Core Decisions
20
+
21
+ ### 1) Quiver Shapes and Transports Are Orthogonal
22
+
23
+ Two on-disk/data shapes:
24
+
25
+ - **Source Quiver** (authoring shape)
26
+ - Human-authored, git-friendly
27
+ - Root `Quiver.yaml`
28
+ - Quills under `quills/<name>/<version>/Quill.yaml`
29
+ - Assets in normal source layout
30
+ - **Packed Quiver** (distribution/runtime artifact)
31
+ - Hashed manifest
32
+ - Bundle zips
33
+ - Dehydrated shared font store (`store/<md5>`)
34
+ - Stable pointer file to current hashed manifest
35
+
36
+ Transport is a separate axis for **Packed Quiver** loading:
37
+
38
+ - `http` (browser/runtime delivery)
39
+ - `fs` (packed artifact loaded from local disk)
40
+ - future transports can be added without changing packed format
41
+
42
+ **Naming decision:** use `pack()` (format operation), not transport-specific names.
43
+
44
+ ### 2) `Quiver.yaml` Is Required in Source Quivers
45
+
46
+ Source Quivers require root `Quiver.yaml` metadata.
47
+
48
+ Fields for V1:
49
+
50
+ - `name` (required) — runtime namespace identity; may differ from npm package name. Charset: alphanumeric only (`[A-Za-z0-9_-]+`).
51
+ - `description` (optional) — tooling-only metadata in V1; not consumed by runtime paths.
52
+
53
+ Unknown fields in `Quiver.yaml` are a **validation error** (`quiver_invalid`). Strict-by-default keeps forward compatibility explicit: any future field is additive and requires a schema bump.
54
+
55
+ `package.json.version` remains npm-channel identity; packed artifact identity remains hashed-manifest based.
56
+
57
+ ### 3) `QuillSource` Becomes Quiver-Centric
58
+
59
+ - Re-express `QuillSource` concepts around Quivers
60
+ - Split old filesystem concept into:
61
+ - **Source filesystem loader** (reads Source Quiver directly)
62
+ - **Packed filesystem transport** (loads Packed Quiver artifact from disk)
63
+ - Treat HTTP as a Packed transport, not a separate format concept
64
+
65
+ ### 4) Multi-Quiver Composition with Deterministic Precedence
66
+
67
+ `QuiverRegistry` accepts multiple quivers with explicit order.
68
+
69
+ This registry/composition layer lives entirely in `@quillmark/quiver`; it is not a Quillmark engine feature.
70
+
71
+ Precedence rule:
72
+
73
+ - **Precedence is a hard filter**
74
+ - Scan quivers in order
75
+ - First quiver with any matching candidate wins
76
+ - Choose highest matching version **within that quiver**
77
+
78
+ Applies to:
79
+
80
+ - unqualified refs (e.g. `usaf_memo`)
81
+ - selector refs (e.g. `usaf_memo@1.2`)
82
+
83
+ No global highest-across-all-quivers behavior.
84
+
85
+ **Identity collision:** duplicate `Quiver.yaml.name` across composed quivers is an error in V1.
86
+
87
+ ### 5) Semver Selector Rules Are Strict and Small
88
+
89
+ Supported forms:
90
+
91
+ - `name` (highest version in first-winning quiver)
92
+ - `name@x.y.z` exact
93
+ - `name@x.y` highest `x.y.*`
94
+ - `name@x` highest `x.*.*`
95
+
96
+ Not supported in V1:
97
+
98
+ - ranges (`>=`, `<`, etc.)
99
+ - npm operators (`^`, `~`)
100
+ - wildcards (`*`)
101
+ - prerelease/build metadata
102
+
103
+ Canonical version format:
104
+
105
+ - `x.y.z` only
106
+ - applies to quill version directories (`quills/<name>/<version>/`)
107
+ - non-canonical versions on disk are validation errors
108
+
109
+ Canonicalization:
110
+
111
+ - resolve selector to canonical ref once per manifest snapshot
112
+ - key internal caches by canonical ref
113
+
114
+ ### 6) Warm/Prefetch Is Purely a Quiver Concern
115
+
116
+ `warm()` remains a quiver-layer optimization:
117
+
118
+ - `warm()` warms all by default in V1
119
+ - `resolve()` must work even if nothing is warmed
120
+
121
+ Warm now means "load/prepare quills and artifacts", not "register in engine". There is no engine registration step anymore.
122
+
123
+ ### 7) Engine Boundary: New Canonical Contract (Node / JS–WASM only)
124
+
125
+ Quillmark integration for `@quillmark/quiver` is:
126
+
127
+ 1. Initialize engine once (`new Quillmark()` from `@quillmark/wasm`)
128
+ 2. When quill bytes are ready, build a render-ready quill with `engine.quill(tree)` (`Map<string, Uint8Array>`)
129
+ 3. Render through the returned quill: `quill.render(doc, opts?)` (`Document` — built via `Document.fromMarkdown(...)`)
130
+
131
+ Important implications:
132
+
133
+ - No engine quill registry in the JS binding; no `registerQuill`, `hasQuill`, or engine-level `render(doc)` in Quiver’s flow
134
+ - Quiver owns mapping from canonical ref → in-memory tree → `Quill` instance
135
+ - Cache optimization is in-process reuse of `Quill` instances, not registration checks
136
+ - Path-based loading (`quill_from_path`) exists in **other** bindings only; in Node, Quiver reads files and assembles `tree` for `engine.quill(tree)` (see upstream `references/quillmark/docs/integration/javascript/api.md`)
137
+
138
+ For advanced dynamic-asset behavior, defer to Quillmark’s JS/WASM docs; the default integration path here is `engine.quill` + `quill.render`.
139
+
140
+ ### 8) Markdown and Ref Parsing Boundary
141
+
142
+ - Markdown parsing does not require a quill registry: `Document.fromMarkdown(markdown)`
143
+ - Quiver owns ref parsing and selector resolution for its own API (`resolve`, `warm`, validation)
144
+ - QUILL field is informational at render time; Quiver routes to the intended quill explicitly without mutating the parsed document in V1
145
+
146
+ Upstream behavior note:
147
+
148
+ - If rendering a parsed document whose `quill_ref` differs from selected quill name, render proceeds with warning `quill::ref_mismatch`
149
+ - Quiver should surface that warning, not suppress it. In V1, this is an intentional loud footgun detector for ref/selection drift.
150
+
151
+ ### 9) Distribution Strategy
152
+
153
+ V1 supports:
154
+
155
+ - npm distribution for Source Quiver projects
156
+ - git/folder-copy consumption of Source Quivers
157
+ - `pack()` output for Packed runtime distribution
158
+
159
+ Clarification:
160
+
161
+ - npm/git are developer distribution channels
162
+ - packed artifacts are runtime delivery artifacts
163
+
164
+ ---
165
+
166
+ ## Carryover Matrix (What We Keep)
167
+
168
+ V1 intentionally retains:
169
+
170
+ 1. Font dehydration as a Packed Quiver property
171
+ 2. Consumer validation tooling for Source Quivers (+ optional Packed parity checks)
172
+ 3. Manifest pointer resolution for Packed format
173
+ 4. HTTP loading as a Packed transport
174
+ 5. Source filesystem loading as first-class dev loop
175
+ 6. Packed filesystem loading as first-class runtime option
176
+ 7. Typed errors (`QuiverError`) with quiver/transport context
177
+ 8. Concurrency coalescing for in-flight loads
178
+ 9. Preload/fail-fast helpers where they still add value
179
+
180
+ Removed from carryover assumptions:
181
+
182
+ - Any engine-registration cache fast path (`register`/`has`) because upstream removed the capability
183
+
184
+ ---
185
+
186
+ ## Explicit Trims (Surface Reduction)
187
+
188
+ V1 should trim public API where behavior can stay internal:
189
+
190
+ - Drop internal-only utility exports
191
+ - Keep engine payload and transport internals opaque
192
+ - Consolidate validation exports
193
+ - Avoid duplicate entry points for equivalent validation workflows
194
+ - Do not expose internal quill-object cache mechanisms as public contract
195
+
196
+ ---
197
+
198
+ ## Error Model
199
+
200
+ Single `QuiverError` class with `code: string` + contextual payload (ref, version, quiver name, underlying cause where applicable). No subclasses. Fail-fast: operations throw on first failure; no aggregate/partial-success results in V1.
201
+
202
+ V1 code catalog (closed set):
203
+
204
+ | Code | Fires when |
205
+ |---|---|
206
+ | `invalid_ref` | Malformed ref string at `resolve()`/`warm()` boundary (fails `parseQuillRef`) |
207
+ | `quill_not_found` | Selector did not match any quill in any composed quiver |
208
+ | `quiver_invalid` | `Quiver.yaml` or hashed manifest malformed, unknown field, non-canonical version on disk, or font/bundle hash mismatch |
209
+ | `transport_error` | I/O failure: missing path, HTTP non-2xx, network error, permission error. Wraps underlying cause. |
210
+ | `quiver_collision` | Two composed quivers share `Quiver.yaml.name` at registry construction |
211
+
212
+ Notes:
213
+ - `quill_not_found` is selector-resolution failure after quiver composition and precedence.
214
+ - `transport_error` is artifact access failure (filesystem/HTTP/network/permissions), including missing packed files and HTTP 404.
215
+ - Legacy categories such as `manifest_invalid`, `quill_load_failed`, and `backend_not_found` are folded into `quiver_invalid` or `transport_error` in V1.
216
+
217
+ Errors must include offending ref/version/quiver identifiers when available.
218
+
219
+ ---
220
+
221
+ ## Runtime + Packaging Model
222
+
223
+ V1 runtime loading paths:
224
+
225
+ 1. Source Quiver from filesystem (authoring/dev)
226
+ 2. Packed Quiver over HTTP (browser/runtime)
227
+ 3. Packed Quiver from filesystem (air-gapped/container/runtime)
228
+
229
+ V1 packaging behavior:
230
+
231
+ - `Quiver.pack()` produces Packed Quiver artifact independent of transport
232
+ - packed output includes pointer + hashed manifest + bundles + dehydrated font store
233
+
234
+ Execution behavior:
235
+
236
+ - Quiver resolves selector -> canonical ref
237
+ - Quiver loads/creates a render-ready `Quill` via engine factory
238
+ - Quiver reuses loaded quill objects by canonical ref
239
+ - Quiver renders through `quill.render(...)`
240
+
241
+ Caching scope:
242
+
243
+ - In V1, loaded-quill object reuse is in scope
244
+ - Cache eviction policy is out of scope for V1 (can be added as an additive lifecycle control later)
245
+
246
+ ---
247
+
248
+ ## Source Quiver Layout (normative)
249
+
250
+ ```
251
+ <root>/
252
+ Quiver.yaml
253
+ quills/
254
+ <name>/
255
+ <version>/ # canonical x.y.z
256
+ Quill.yaml
257
+ ... # quill-local templates, partials, assets, fonts
258
+ ```
259
+
260
+ - All assets (including fonts) are **quill-local**. No quiver-level shared asset directory in V1.
261
+ - Non-canonical version directories are a validation error (`quiver_invalid`).
262
+ - Dedup of identical fonts across quills happens at pack time (into `store/<md5>`), not at the source layer.
263
+
264
+ ## Packed Quiver Format (normative)
265
+
266
+ ```
267
+ <root>/
268
+ Quiver.json # stable pointer, always this filename
269
+ manifest.<md5>.json # hashed manifest, content-addressed
270
+ <name>@<version>.<md5>.zip # one bundle per quill, content-addressed
271
+ store/
272
+ <md5> # raw font bytes, no extension
273
+ ```
274
+
275
+ **Hash:** MD5 prefix-6, computed with `node:crypto` at `pack()` time only (dev/tooling; not browser runtime).
276
+
277
+ **Pointer** `Quiver.json`:
278
+ ```json
279
+ { "manifest": "manifest.abc123.json" }
280
+ ```
281
+
282
+ **Hashed manifest** `manifest.<md5>.json`:
283
+ ```json
284
+ {
285
+ "version": 1,
286
+ "name": "<quiver-name>",
287
+ "quills": [
288
+ {
289
+ "name": "usaf_memo",
290
+ "version": "1.2.3",
291
+ "bundle": "usaf_memo@1.2.3.def456.zip",
292
+ "fonts": { "fonts/roboto.ttf": "md5abc", "fonts/arial.ttf": "md5def" }
293
+ }
294
+ ]
295
+ }
296
+ ```
297
+
298
+ **Bundle zips** contain pure quill content (`Quill.yaml` + templates + partials + non-font assets). Fonts are dehydrated at pack time: their bytes live only in `store/<md5>`; their path→hash mapping lives only in the hashed manifest. Bundles do **not** embed a `fonts.json`.
299
+
300
+ Rehydration on load: transport fetches the pointer → hashed manifest → required bundle(s) → required `store/<md5>` blobs; library reconstructs the full in-memory tree and builds a render-ready quill via `engine.quill(tree)`.
301
+
302
+ ## API Surface (V1)
303
+
304
+ Single class, three factories:
305
+
306
+ ```ts
307
+ class Quiver {
308
+ // Node-only factories (from `@quillmark/quiver/node`). Fail fast in browser.
309
+ static fromSourceDir(path: string): Promise<Quiver>;
310
+ static fromPackedDir(path: string): Promise<Quiver>;
311
+ // Browser-safe factory (from `@quillmark/quiver` main).
312
+ static fromHttp(url: string): Promise<Quiver>;
313
+ // Node-only tooling. Writes a Packed Quiver to outDir.
314
+ static pack(sourceDir: string, outDir: string, opts?: PackOptions): Promise<void>;
315
+
316
+ readonly name: string; // from Quiver.yaml
317
+
318
+ // Read-only introspection and lazy tree access used by QuiverRegistry
319
+ // internally; also available for external debugging and tooling.
320
+ quillNames(): string[]; // sorted lex
321
+ versionsOf(name: string): string[]; // sorted desc
322
+ loadTree(name: string, version: string): Promise<Map<string, Uint8Array>>;
323
+ }
324
+ ```
325
+
326
+ ```ts
327
+ class QuiverRegistry {
328
+ constructor(args: { engine: Quillmark; quivers: Quiver[] });
329
+
330
+ // Selector ref -> canonical ref. Throws invalid_ref / quill_not_found.
331
+ resolve(ref: string): Promise<string>;
332
+
333
+ // Canonical ref -> render-ready quill handle (materialized via engine.quill(tree), cached in-process).
334
+ getQuill(canonicalRef: string): Promise<Quill>;
335
+
336
+ // Warms every ref in every composed quiver. Fail-fast. Zero params in V1.
337
+ warm(): Promise<void>;
338
+ }
339
+
340
+ class QuiverError extends Error {
341
+ code: "invalid_ref" | "quill_not_found" | "quiver_invalid" | "transport_error" | "quiver_collision";
342
+ // plus contextual payload fields
343
+ }
344
+ ```
345
+
346
+ **No render wrapper.** Callers invoke `quill.render(doc, opts?)` (and `quill.open(doc)` when needed) after `resolve()` + `getQuill()`. Quiver never mirrors Quillmark render APIs.
347
+
348
+ **Internal (not exported):** `QuiverTransport`, `QuiverManifest` (runtime shape), `parseQuillRef`, in-flight coalescing state.
349
+
350
+ Hot-path flow:
351
+ ```ts
352
+ const doc = Document.fromMarkdown(md);
353
+ const canonicalRef = await registry.resolve(doc.quillRef);
354
+ const quill = await registry.getQuill(canonicalRef);
355
+ const result = quill.render(doc, { format: "pdf" });
356
+ ```
357
+
358
+ ## Package Structure
359
+
360
+ **Name:** `@quillmark/quiver`
361
+
362
+ **Entrypoints:**
363
+ - `@quillmark/quiver` (main, browser-safe): `Quiver` class with only `fromHttp` functional (Node-only factories/pack throw `transport_error` if reached in browser), `QuiverRegistry`, `QuiverError`, shared types.
364
+ - `@quillmark/quiver/node`: adds `Quiver.fromSourceDir`, `Quiver.fromPackedDir`, `Quiver.pack` behaviors. Single `Quiver` class — Node-only factories fail fast outside Node.
365
+
366
+ **Dependencies:**
367
+ - Peer: `@quillmark/wasm@>=0.59.0-rc.2` with `Quillmark`, `Document.fromMarkdown`, `engine.quill(tree)`, and `quill.render(doc, opts?)` APIs.
368
+ - Runtime: `fflate ^0.8.2` for zip read/write (Node + browser)
369
+ - Dev-only: `node:crypto` (MD5 hashing in `pack()` — never reached at runtime)
370
+
371
+ ---
372
+
373
+ ## Out of Scope for V1
374
+
375
+ - Non-Node consumers of Quillmark (e.g. Python bindings, Rust CLI) as deliverables of this program — `@quillmark/quiver` is the Node/npm package only
376
+ - Quiver CLI (`quiver init`, etc.)
377
+ - prerelease semver support
378
+ - semver range expression support
379
+ - quiver-declared precedence/priority
380
+ - inter-quiver dependency graph in `Quiver.yaml`
381
+ - marketplace/discovery service
382
+ - advanced warm strategies beyond API-compatible hooks
383
+ - multi-quiver name-collision soft handling (V1 errors on duplicate `Quiver.yaml.name`)
384
+
385
+ ---
386
+
387
+ ## Planner Questions — Resolved
388
+
389
+ All V1 planner questions resolved; implementation plan can proceed against the spec above.
390
+
391
+ 1. ~~Final `Quiver` interface shape and transport factoring style~~ → Single `Quiver` class, three static factories (`fromHttp`, `fromSourceDir`, `fromPackedDir`). Transport kept internal (no `fromTransport` in V1; YAGNI).
392
+ 2. ~~Final `Quiver.yaml` schema and unknown-field policy~~ → See §2: alphanumeric `name` and optional tooling-only `description`. Unknown fields are `quiver_invalid`.
393
+ 3. ~~Canonical ref grammar and parser API contract~~ → Internal `parseQuillRef`, not exported. Selector syntax per §5. Throws `invalid_ref`.
394
+ 4. ~~Exact warning policy for shadowed refs across quivers~~ → No warnings in V1. Precedence is a hard filter (§4); duplicate quiver names error as `quiver_collision`.
395
+ 5. ~~Validation API shape consolidation~~ → No separate validation API. Validation errors surface as `QuiverError('quiver_invalid')` during load or `pack()`.
396
+ 6. ~~Pack artifact directory structure~~ → See "Packed Quiver Format (normative)".
397
+ 7. ~~Node/browser entrypoint split~~ → See "Package Structure": main + `/node` subpath, single `Quiver` class.
398
+ 8. ~~Final exported type names~~ → `Quiver`, `QuiverRegistry`, `QuiverError`. Hot-path entry is `QuiverRegistry.resolve(ref)` + `QuiverRegistry.getQuill(canonicalRef)`.
399
+
400
+ ---
401
+
402
+ ## References
403
+
404
+ Local copies in this repo for `@quillmark/quiver` implementation:
405
+
406
+ - `references/quillmark-registry/` — prior `@quillmark/registry` source and patterns to mine or replace
407
+ - `references/quillmark/docs/integration/javascript/api.md` — JS/WASM API this package integrates with
408
+ - `references/quillmark/prose/designs/WASM.md` — WASM binding shape
409
+ - `references/quillmark/prose/taskings/quill_render_api.md` — upstream render API overhaul (cross-binding; use the JS/WASM sections for Node)
410
+
411
+ ---
412
+
413
+ ## Success Criteria
414
+
415
+ - A team can author and validate a Source Quiver locally with fast filesystem loops
416
+ - A packed artifact can be loaded via HTTP or local filesystem with equivalent semantics
417
+ - Multi-quiver resolution is deterministic and matches precedence hard-filter rules
418
+ - Selector behavior is predictable and explicitly documented
419
+ - Quiver (Node) integrates via `engine.quill(tree)` + `quill.render(...)` only (no engine quill registration path)
420
+ - Public API surface is smaller and clearer than `@quillmark/registry`
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @quillmark/quiver
2
+
3
+ Quiver registry and packaging for Quillmark — load, compose, and pack collections of quills for rendering with `@quillmark/wasm`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @quillmark/quiver @quillmark/wasm
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { Quillmark, Document } from "@quillmark/wasm";
15
+ import { Quiver, QuiverRegistry } from "@quillmark/quiver/node";
16
+
17
+ // 1. Load a source quiver from disk (Node.js only)
18
+ const quiver = await Quiver.fromSourceDir("./my-quiver");
19
+
20
+ // 2. Build a registry with one or more quivers
21
+ const engine = new Quillmark();
22
+ const registry = new QuiverRegistry({ engine, quivers: [quiver] });
23
+
24
+ // 3. Resolve a ref, obtain a render-ready quill, and render
25
+ const doc = Document.fromMarkdown(markdownString);
26
+ const canonicalRef = await registry.resolve(doc.quillRef);
27
+ const quill = await registry.getQuill(canonicalRef);
28
+ const result = quill.render(doc, { format: "pdf" });
29
+ ```
30
+
31
+ ## HTTP (browser / CDN)
32
+
33
+ ```ts
34
+ import { Quiver, QuiverRegistry } from "@quillmark/quiver";
35
+
36
+ const quiver = await Quiver.fromHttp("https://cdn.example.com/my-quiver");
37
+ const registry = new QuiverRegistry({ engine, quivers: [quiver] });
38
+ ```
39
+
40
+ ## Packed directory (Node.js)
41
+
42
+ ```ts
43
+ import { Quiver } from "@quillmark/quiver/node";
44
+
45
+ const quiver = await Quiver.fromPackedDir("./dist/my-quiver");
46
+ ```
47
+
48
+ ## Pack a source quiver
49
+
50
+ ```ts
51
+ import { Quiver } from "@quillmark/quiver/node";
52
+
53
+ await Quiver.pack("./my-quiver", "./dist/my-quiver");
54
+ ```
55
+
56
+ ## Warm (prefetch all quills)
57
+
58
+ ```ts
59
+ await registry.warm();
60
+ ```
61
+
62
+ ## Multi-quiver composition
63
+
64
+ Quivers are scanned in order. The first quiver with any matching candidate wins;
65
+ the highest matching version within that quiver is returned.
66
+
67
+ ```ts
68
+ const registry = new QuiverRegistry({
69
+ engine,
70
+ quivers: [primaryQuiver, fallbackQuiver],
71
+ });
72
+ ```
73
+
74
+ ## Error handling
75
+
76
+ All errors are instances of `QuiverError` with a `code` field.
77
+
78
+ ```ts
79
+ import { QuiverError } from "@quillmark/quiver";
80
+
81
+ try {
82
+ const canonicalRef = await registry.resolve("unknown_quill");
83
+ } catch (err) {
84
+ if (err instanceof QuiverError) {
85
+ console.error(err.code); // e.g. "quill_not_found"
86
+ console.error(err.message); // human-readable description
87
+ console.error(err.ref); // offending ref, when available
88
+ }
89
+ }
90
+ ```
91
+
92
+ Error codes: `invalid_ref`, `quill_not_found`, `quiver_invalid`, `transport_error`, `quiver_collision`.
93
+
94
+ ## Full specification
95
+
96
+ See [PROGRAM.md](./PROGRAM.md) for the complete API surface, packed format specification, and design decisions.
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@quillmark/quiver",
3
+ "version": "0.1.0",
4
+ "description": "Quiver registry and packaging for Quillmark",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/quillmark/quiver"
10
+ },
11
+ "keywords": [
12
+ "quillmark",
13
+ "quiver",
14
+ "typst",
15
+ "markdown"
16
+ ],
17
+ "author": "Quillmark Contributors",
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ },
26
+ "./node": {
27
+ "types": "./dist/node.d.ts",
28
+ "import": "./dist/node.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "PROGRAM.md",
34
+ "README.md"
35
+ ],
36
+ "peerDependencies": {
37
+ "@quillmark/wasm": ">=0.59.0-rc.2"
38
+ },
39
+ "dependencies": {
40
+ "fflate": "^0.8.2",
41
+ "yaml": "^2.8.3"
42
+ },
43
+ "devDependencies": {
44
+ "@quillmark/wasm": "0.59.0-rc.2",
45
+ "@types/node": "^25.3.3",
46
+ "typescript": "^5.9.3",
47
+ "vitest": "^4.0.18"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc",
51
+ "test": "vitest run",
52
+ "lint": "tsc --noEmit"
53
+ }
54
+ }