lorefile 0.0.0-stage → 0.2.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.
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,7 @@
1
+ Lorefile
2
+
3
+ Built by the team at Stella, https://stellaheystella.com
4
+
5
+ Licensed under the Apache License, Version 2.0; see the LICENSE file.
6
+ Anyone who redistributes Lorefile, changed or not, keeps this NOTICE
7
+ file with it (Apache License 2.0, section 4(d)).
package/README.md CHANGED
@@ -1,3 +1,123 @@
1
- # Temporary Holding Version
1
+ # Lorefile
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A team's business knowledge, written down in plain YAML files that AI agents read: what counts as a sale, where the orders live, which number the business runs on, what an agent may never do. One `lorefile` binary serves it three ways: an MCP server for agents, a CLI, and a web page for the people who review it.
4
+
5
+ This page is about installing it. The guide to using it is the project README on GitHub: <https://github.com/lorefile/lorefile#readme>.
6
+
7
+ ## Install
8
+
9
+ Pick one. Each gives you the same `lorefile` command.
10
+
11
+ | Way | Command | Needs |
12
+ |---|---|---|
13
+ | npx | `npx lorefile serve` | Node.js 18 or newer |
14
+ | Docker | `docker run -p 7070:7070 -v lorefile-spaces:/spaces ghcr.io/lorefile/lorefile` | Docker |
15
+ | cargo | `cargo install lorefile --locked` | Rust 1.87 or newer |
16
+ | Install script | `curl -fsSL https://raw.githubusercontent.com/lorefile/lorefile/main/scripts/install.sh \| sh` | macOS or Linux |
17
+
18
+ ### npx
19
+
20
+ ```bash
21
+ npx lorefile serve --dir spaces
22
+ ```
23
+
24
+ The first run downloads the Lorefile binary built for your computer from the project's GitHub Releases (the release with the same version as this package), checks its SHA-256 checksum against the one published with the package, and keeps it in `~/.cache/lorefile/<version>/` (under `$XDG_CACHE_HOME` if you set it; `%LOCALAPPDATA%\lorefile\` on Windows). Later runs start straight away. Nothing runs when the package is installed; the download happens on first use.
25
+
26
+ `npm install --global lorefile` gives you a plain `lorefile` command instead.
27
+
28
+ To run the MCP server for Claude Code over stdio:
29
+
30
+ ```bash
31
+ claude mcp add lorefile -- npx -y lorefile mcp --dir /path/to/spaces
32
+ ```
33
+
34
+ Other MCP clients (Claude Desktop, Cursor) take the same command in their config:
35
+
36
+ ```json
37
+ { "mcpServers": { "lorefile": { "command": "npx", "args": ["-y", "lorefile", "mcp", "--dir", "/path/to/spaces"] } } }
38
+ ```
39
+
40
+ The launcher prints only to stderr, so stdout stays clean for the MCP messages.
41
+
42
+ ### Docker
43
+
44
+ ```bash
45
+ docker run -d -p 7070:7070 -v lorefile-spaces:/spaces -e LOREFILE_TOKEN=choose-a-long-secret ghcr.io/lorefile/lorefile
46
+ ```
47
+
48
+ Then open <http://127.0.0.1:7070>. Images are published for `linux/amd64` and `linux/arm64`, tagged with each version and `latest` (and `edge` for test builds). The container runs as a non-root user (uid 10001) and keeps your spaces on the `/spaces` volume. It starts read-only; to let the page and agents write, pass the command yourself:
49
+
50
+ ```bash
51
+ docker run -d -p 7070:7070 -v lorefile-spaces:/spaces -e LOREFILE_TOKEN=choose-a-long-secret \
52
+ ghcr.io/lorefile/lorefile serve --dir /spaces --host 0.0.0.0 --allow-edit
53
+ ```
54
+
55
+ ### cargo install
56
+
57
+ ```bash
58
+ cargo install lorefile --locked
59
+ ```
60
+
61
+ This compiles DuckDB from source, which takes 5 to 10 minutes. `cargo install lorefile --locked --no-default-features --features rdf` builds the slim version in a minute or two (see below).
62
+
63
+ ### Install script (macOS and Linux, no Node needed)
64
+
65
+ ```bash
66
+ curl -fsSL https://raw.githubusercontent.com/lorefile/lorefile/main/scripts/install.sh | sh
67
+ ```
68
+
69
+ It downloads the latest release for your computer, checks the checksum, puts `lorefile` in `~/.local/bin` (or `/usr/local/bin` when run as root, e.g. with `sudo sh`), and prints what it did. Optional settings go before `sh`:
70
+
71
+ | Setting | What it does |
72
+ |---|---|
73
+ | `LOREFILE_VERSION=0.2.0` | that version instead of the latest |
74
+ | `LOREFILE_INSTALL_DIR=/opt/bin` | install there (asks `sudo` if the folder needs it) |
75
+ | `LOREFILE_SLIM=1` | the slim build |
76
+
77
+ For example: `curl -fsSL …/install.sh | LOREFILE_SLIM=1 sh`.
78
+
79
+ ### Binaries
80
+
81
+ Every release on <https://github.com/lorefile/lorefile/releases> has an archive per platform, each with a `.sha256` file next to it, and one `checksums.txt`:
82
+
83
+ | Platform | Archive |
84
+ |---|---|
85
+ | macOS, Apple silicon | `lorefile-<version>-aarch64-apple-darwin.tar.gz` |
86
+ | macOS, Intel | `lorefile-<version>-x86_64-apple-darwin.tar.gz` |
87
+ | Linux x86_64 (glibc 2.35 or newer) | `lorefile-<version>-x86_64-unknown-linux-gnu.tar.gz` |
88
+ | Linux arm64 (glibc 2.35 or newer) | `lorefile-<version>-aarch64-unknown-linux-gnu.tar.gz` |
89
+ | Windows x86_64 | `lorefile-<version>-x86_64-pc-windows-msvc.zip` |
90
+
91
+ macOS builds need macOS 11 or newer. On Alpine and other musl Linux, use Docker or `cargo install`.
92
+
93
+ **Full or slim.** Each platform comes in two builds. The full one (about 70 MB) includes DuckDB, so the `query` tool and the Data & SQL page can run SQL over local CSV, Parquet and DuckDB files. The slim one (`-slim` in the name, about 10 MB) leaves DuckDB out; everything else works the same, the Apache Ossie and OWL / SKOS / SHACL import and export included. `npx` uses the full build; if a release has no full build for your platform, it uses the slim one and says so.
94
+
95
+ ## First run: the login token
96
+
97
+ `lorefile serve` asks for a token before it shows the page or answers the API, the way Jupyter does. On the first run it makes one, saves it in `<dir>/.lorefile/auth.toml`, and prints a login URL with the token in it:
98
+
99
+ ```
100
+ Open http://127.0.0.1:7070/?token=k3f9…
101
+ MCP http://127.0.0.1:7070/mcp Authorization: Bearer k3f9…
102
+ ```
103
+
104
+ Open that URL once and the browser remembers you. To choose the token yourself, set `LOREFILE_TOKEN` (or pass `--token`); that is how Docker and servers get theirs. The same token lets agents use MCP over HTTP, which is what you need when Lorefile runs in a container:
105
+
106
+ ```bash
107
+ claude mcp add --transport http lorefile http://127.0.0.1:7070/mcp --header "Authorization: Bearer <token>"
108
+ ```
109
+
110
+ ## Launcher settings
111
+
112
+ | Variable | What it does |
113
+ |---|---|
114
+ | `LOREFILE_BINARY` | run this binary (say, your own build) instead of downloading one |
115
+ | `XDG_CACHE_HOME` | where the downloaded binary is kept: `<it>/lorefile/<version>/` |
116
+ | `LOREFILE_DOWNLOAD_URL` | a folder URL holding the release archives, for a mirror |
117
+ | `LOREFILE_REPO` | download from another GitHub repository (a fork) |
118
+
119
+ Behind a proxy that Node cannot get through, download the archive for your computer from the releases page and set `LOREFILE_BINARY` to the `lorefile` binary inside it.
120
+
121
+ ## Licence
122
+
123
+ Apache-2.0. Each release archive carries the licences of the software compiled into it, DuckDB's included. Built by the team at [Stella](https://stellaheystella.com).
@@ -0,0 +1,304 @@
1
+ #!/usr/bin/env node
2
+ // The `lorefile` command for npm and npx.
3
+ //
4
+ // This package holds no binary. The first time it runs, this script downloads
5
+ // the Lorefile binary built for this computer from the project's GitHub
6
+ // Releases (the release whose version matches this package), checks its SHA-256
7
+ // checksum, and keeps it in a cache folder. From then on it just starts that
8
+ // binary with your arguments and exits with its exit code. Nothing runs at
9
+ // install time.
10
+ //
11
+ // Environment, all optional:
12
+ // LOREFILE_BINARY run this binary instead (say, a local build); nothing is downloaded
13
+ // LOREFILE_REPO the GitHub org/repo to download from (DEFAULT_REPO below)
14
+ // LOREFILE_DOWNLOAD_URL a folder URL holding the release assets: a mirror, or a test server
15
+ // XDG_CACHE_HOME where the cache lives: <it>/lorefile/<version>/ (default ~/.cache)
16
+ //
17
+ // Everything this script prints goes to stderr, so `npx lorefile mcp` keeps
18
+ // stdout for the MCP messages.
19
+ 'use strict';
20
+
21
+ // The GitHub org/repo that publishes the binaries. Change it here, in
22
+ // npm/package.json, in scripts/install.sh and in .github/workflows/release.yml
23
+ // (LOREFILE_REPO) together; the release workflow checks they agree.
24
+ const DEFAULT_REPO = 'lorefile/lorefile';
25
+
26
+ const childProcess = require('child_process');
27
+ const crypto = require('crypto');
28
+ const fs = require('fs');
29
+ const os = require('os');
30
+ const path = require('path');
31
+
32
+ const VERSION = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')).version;
33
+
34
+ // Node's platform and CPU names, mapped to the Rust targets the release workflow
35
+ // builds (keep in step with its build matrix).
36
+ const TARGETS = {
37
+ 'darwin arm64': 'aarch64-apple-darwin',
38
+ 'darwin x64': 'x86_64-apple-darwin',
39
+ 'linux arm64': 'aarch64-unknown-linux-gnu',
40
+ 'linux x64': 'x86_64-unknown-linux-gnu',
41
+ 'win32 x64': 'x86_64-pc-windows-msvc',
42
+ };
43
+ const PLATFORM_NAMES = { darwin: 'macOS', linux: 'Linux', win32: 'Windows' };
44
+
45
+ const REPO = process.env.LOREFILE_REPO || DEFAULT_REPO;
46
+ const OTHER_WAYS =
47
+ `Other ways to run Lorefile: Docker (ghcr.io/${REPO.split('/')[0].toLowerCase()}/lorefile), ` +
48
+ '`cargo install lorefile --locked`, or build it yourself and set LOREFILE_BINARY to the binary.';
49
+
50
+ let progressLineOpen = false; // a progress line without its newline yet
51
+
52
+ function say(line) {
53
+ if (progressLineOpen) process.stderr.write('\n');
54
+ progressLineOpen = false;
55
+ process.stderr.write(`lorefile: ${line}\n`);
56
+ }
57
+
58
+ function fail(message) {
59
+ say(message);
60
+ process.exit(1);
61
+ }
62
+
63
+ // glibc builds do not run on musl Linux (Alpine). Node's report says which libc it runs on.
64
+ function isMusl() {
65
+ if (process.platform !== 'linux') return false;
66
+ try {
67
+ const header = process.report.getReport().header;
68
+ return !header.glibcVersionRuntime;
69
+ } catch (_) {
70
+ return false;
71
+ }
72
+ }
73
+
74
+ function cacheDir() {
75
+ let root = process.env.XDG_CACHE_HOME;
76
+ if (!root && process.platform === 'win32' && process.env.LOCALAPPDATA) root = process.env.LOCALAPPDATA;
77
+ if (!root) root = path.join(os.homedir(), '.cache');
78
+ return path.join(root, 'lorefile', VERSION);
79
+ }
80
+
81
+ // GET a URL, following redirects (GitHub sends release downloads to a CDN).
82
+ // Resolves with the response stream; rejects with err.status set on HTTP errors.
83
+ function get(url, redirects = 0) {
84
+ return new Promise((resolve, reject) => {
85
+ const client = url.startsWith('http://') ? require('http') : require('https');
86
+ const req = client.get(url, { headers: { 'User-Agent': `lorefile-npm/${VERSION}` } }, (res) => {
87
+ const { statusCode, headers } = res;
88
+ if ([301, 302, 303, 307, 308].includes(statusCode) && headers.location) {
89
+ res.resume();
90
+ const next = new URL(headers.location, url).toString();
91
+ if (redirects >= 10) return reject(new Error(`too many redirects fetching ${url}`));
92
+ if (url.startsWith('https:') && !next.startsWith('https:')) {
93
+ return reject(new Error(`refusing a redirect from https to ${next}`));
94
+ }
95
+ return resolve(get(next, redirects + 1));
96
+ }
97
+ if (statusCode !== 200) {
98
+ res.resume();
99
+ const err = new Error(`HTTP ${statusCode} fetching ${url}`);
100
+ err.status = statusCode;
101
+ err.network = true;
102
+ return reject(err);
103
+ }
104
+ resolve(res);
105
+ });
106
+ req.on('error', (err) => {
107
+ err.network = true; // no connection, DNS, TLS, a proxy in the way, or the timeout below
108
+ reject(err);
109
+ });
110
+ req.setTimeout(60000, () => req.destroy(new Error(`no answer for 60 seconds fetching ${url}`)));
111
+ });
112
+ }
113
+
114
+ async function getText(url) {
115
+ const res = await get(url);
116
+ const chunks = [];
117
+ for await (const chunk of res) chunks.push(chunk);
118
+ return Buffer.concat(chunks).toString('utf8');
119
+ }
120
+
121
+ // `checksums.txt` lines look like "<64 hex digits> <file name>".
122
+ function findChecksum(text, fileName) {
123
+ for (const line of text.split(/\r?\n/)) {
124
+ const m = line.trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
125
+ if (m && m[2] === fileName) return m[1].toLowerCase();
126
+ }
127
+ return null;
128
+ }
129
+
130
+ // The published checksum for one asset. A package published by the release
131
+ // workflow carries the release's checksums.txt, so the download is checked
132
+ // against what npm holds (a mirror included); otherwise use the .sha256 file
133
+ // next to the asset. Resolves null when the asset is not published.
134
+ async function publishedChecksum(base, fileName) {
135
+ const baked = path.join(__dirname, '..', 'checksums.txt');
136
+ if (fs.existsSync(baked)) {
137
+ return findChecksum(fs.readFileSync(baked, 'utf8'), fileName);
138
+ }
139
+ try {
140
+ const text = await getText(`${base}/${fileName}.sha256`);
141
+ const hex = text.trim().split(/\s+/)[0].toLowerCase();
142
+ if (!/^[0-9a-f]{64}$/.test(hex)) throw new Error(`${fileName}.sha256 does not hold a SHA-256 checksum`);
143
+ return hex;
144
+ } catch (err) {
145
+ if (err.status === 404) return null;
146
+ throw err;
147
+ }
148
+ }
149
+
150
+ // Stream a URL into a file, showing one progress line, and return the file's SHA-256.
151
+ async function download(url, file, label) {
152
+ const res = await get(url);
153
+ const total = Number(res.headers['content-length']) || 0;
154
+ const mb = (n) => (n / 1048576).toFixed(1);
155
+ const tty = process.stderr.isTTY;
156
+ let received = 0;
157
+ let shown = -1;
158
+ const show = () => {
159
+ const pct = total ? Math.floor((received / total) * 100) : 0;
160
+ if (pct === shown) return;
161
+ shown = pct;
162
+ const amount = total ? `${pct}% of ${mb(total)} MB` : `${mb(received)} MB`;
163
+ process.stderr.write(`\rlorefile: downloading ${label}… ${amount}`);
164
+ progressLineOpen = true;
165
+ };
166
+ if (tty) show();
167
+ else say(`downloading ${label}${total ? ` (${mb(total)} MB)` : ''}…`);
168
+
169
+ const hash = crypto.createHash('sha256');
170
+ const out = fs.createWriteStream(file, { mode: 0o600 });
171
+ try {
172
+ await new Promise((resolve, reject) => {
173
+ res.on('data', (chunk) => {
174
+ hash.update(chunk);
175
+ received += chunk.length;
176
+ if (tty) show();
177
+ });
178
+ res.on('aborted', () => reject(new Error(`the download of ${url} was cut off`)));
179
+ res.on('error', reject);
180
+ out.on('error', reject);
181
+ out.on('finish', resolve);
182
+ res.pipe(out);
183
+ });
184
+ } finally {
185
+ out.destroy(); // let go of the file even when the download failed (Windows cannot delete open files)
186
+ }
187
+ if (progressLineOpen) process.stderr.write('\n');
188
+ progressLineOpen = false;
189
+ if (total && received !== total) throw new Error(`got ${received} of ${total} bytes from ${url}`);
190
+ return hash.digest('hex');
191
+ }
192
+
193
+ // Unpack with the system's tar: on macOS and Linux it reads .tar.gz, and the
194
+ // bsdtar that ships with Windows 10 and later reads .zip.
195
+ function unpack(archive, into) {
196
+ const win = process.platform === 'win32';
197
+ const tar = win ? path.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'tar.exe') : 'tar';
198
+ const args = win ? ['-xf', archive, '-C', into] : ['-xzf', archive, '-C', into];
199
+ const r = childProcess.spawnSync(tar, args, { stdio: ['ignore', 'ignore', 'inherit'] });
200
+ if (r.error || r.status !== 0) {
201
+ throw new Error(`could not unpack ${path.basename(archive)} with ${tar}${r.error ? `: ${r.error.message}` : ''}`);
202
+ }
203
+ }
204
+
205
+ // The cached binary for this version, downloading it first if needed.
206
+ async function cachedBinary() {
207
+ const exe = process.platform === 'win32' ? 'lorefile.exe' : 'lorefile';
208
+ const dir = cacheDir();
209
+ const binary = path.join(dir, exe);
210
+ if (fs.existsSync(binary)) return binary;
211
+
212
+ const target = TARGETS[`${process.platform} ${process.arch}`];
213
+ if (!target || isMusl()) {
214
+ const what = isMusl() ? 'musl Linux (Alpine)' : `${process.platform} on ${process.arch}`;
215
+ fail(`there is no prebuilt Lorefile binary for ${what}. ${OTHER_WAYS}`);
216
+ }
217
+
218
+ const base = (process.env.LOREFILE_DOWNLOAD_URL || `https://github.com/${REPO}/releases/download/v${VERSION}`).replace(/\/+$/, '');
219
+ const ext = process.platform === 'win32' ? 'zip' : 'tar.gz';
220
+
221
+ // The full build (with DuckDB) first. If a release has no full build for this
222
+ // platform (Windows may ship slim only), use the slim one and say so.
223
+ let name = null;
224
+ let expected = null;
225
+ for (const suffix of ['', '-slim']) {
226
+ const candidate = `lorefile-${VERSION}-${target}${suffix}`;
227
+ expected = await publishedChecksum(base, `${candidate}.${ext}`);
228
+ if (expected) {
229
+ name = candidate;
230
+ break;
231
+ }
232
+ }
233
+ if (!name) {
234
+ fail(`Lorefile ${VERSION} has no build for ${target} at ${base}. Is ${VERSION} a published release? ${OTHER_WAYS}`);
235
+ }
236
+ if (name.endsWith('-slim')) {
237
+ say(`this release has no full build for ${PLATFORM_NAMES[process.platform]}; using lorefile-slim (everything but SQL over local files).`);
238
+ }
239
+
240
+ fs.mkdirSync(dir, { recursive: true });
241
+ const scratch = fs.mkdtempSync(path.join(dir, '.download-'));
242
+ try {
243
+ const archive = path.join(scratch, `${name}.${ext}`);
244
+ const label = `Lorefile ${VERSION} for ${PLATFORM_NAMES[process.platform]} ${process.arch === 'x64' ? 'x86_64' : process.arch}`;
245
+ const actual = await download(`${base}/${name}.${ext}`, archive, label);
246
+ if (actual !== expected) {
247
+ throw new Error(`checksum mismatch for ${name}.${ext}: expected ${expected}, got ${actual}. Nothing was installed.`);
248
+ }
249
+ unpack(archive, scratch);
250
+ const unpacked = path.join(scratch, name, exe);
251
+ if (!fs.existsSync(unpacked)) throw new Error(`${name}.${ext} does not contain ${name}/${exe}`);
252
+ fs.chmodSync(unpacked, 0o755);
253
+ // Rename is atomic, so a second `npx lorefile` started at the same moment
254
+ // either finds the finished binary or does its own download.
255
+ try {
256
+ fs.renameSync(unpacked, binary);
257
+ } catch (err) {
258
+ if (!fs.existsSync(binary)) throw err;
259
+ }
260
+ } finally {
261
+ fs.rmSync(scratch, { recursive: true, force: true });
262
+ }
263
+ return binary;
264
+ }
265
+
266
+ // Start the binary with our arguments and our stdin, stdout and stderr; pass
267
+ // on signals; leave with its exit code (or its signal).
268
+ function run(binary, args) {
269
+ const child = childProcess.spawn(binary, args, { stdio: 'inherit' });
270
+ const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'];
271
+ for (const signal of signals) {
272
+ process.on(signal, () => child.kill(signal));
273
+ }
274
+ child.on('error', (err) => fail(`could not start ${binary}: ${err.message}`));
275
+ child.on('exit', (code, signal) => {
276
+ if (signal) {
277
+ for (const s of signals) process.removeAllListeners(s);
278
+ process.kill(process.pid, signal);
279
+ return;
280
+ }
281
+ process.exit(code === null ? 1 : code);
282
+ });
283
+ }
284
+
285
+ async function main() {
286
+ let binary;
287
+ if (process.env.LOREFILE_BINARY) {
288
+ binary = path.resolve(process.env.LOREFILE_BINARY);
289
+ if (!fs.existsSync(binary)) fail(`LOREFILE_BINARY points at ${binary}, which does not exist.`);
290
+ } else {
291
+ binary = await cachedBinary();
292
+ }
293
+ run(binary, process.argv.slice(2));
294
+ }
295
+
296
+ main().catch((err) => {
297
+ // A network failure (no connection, a proxy, an HTTP error) gets the manual route as a hint.
298
+ fail(
299
+ err.network
300
+ ? `${err.message}\nBehind a proxy or offline? Download the archive for this computer from ` +
301
+ `https://github.com/${REPO}/releases/tag/v${VERSION} and set LOREFILE_BINARY to the binary inside. ${OTHER_WAYS}`
302
+ : err.message
303
+ );
304
+ });
package/checksums.txt ADDED
@@ -0,0 +1,10 @@
1
+ 3bc12b88bd5fde9ae18a224d234de006eff3e2000d726c130faf757d39fdf840 lorefile-0.2.0-aarch64-apple-darwin-slim.tar.gz
2
+ e49a65e6284d1f2dbff17398472951e999692298b579011aa769d23cadb55127 lorefile-0.2.0-aarch64-apple-darwin.tar.gz
3
+ b14da955d193bc0718e9d68dfbbf9167bb29fda2bdabad9b0b8209c7759116ad lorefile-0.2.0-aarch64-unknown-linux-gnu-slim.tar.gz
4
+ 9a26e067ac5893da9987007bf0f99fc437c202d2fc559e7640c9a7afffaa6e5d lorefile-0.2.0-aarch64-unknown-linux-gnu.tar.gz
5
+ e1cca91188a396b4311f0c82f2b9723d1c0e88c2e4b94dfabbe3818988fc86a8 lorefile-0.2.0-x86_64-apple-darwin-slim.tar.gz
6
+ ccbf74b86ee77b512346850d57a0bf1738b9434b986cb689ebc7a6cf0f5c22f5 lorefile-0.2.0-x86_64-apple-darwin.tar.gz
7
+ 6574203b0550e39bef83dafddd70233216263534fc0a66fd56da335ea15a4103 lorefile-0.2.0-x86_64-pc-windows-msvc-slim.zip
8
+ 8ffabe24eb18c0d8f6bdbae30b4309cd2f8079ab2b9b9f1964fe88a0bf402de0 lorefile-0.2.0-x86_64-pc-windows-msvc.zip
9
+ 67913eb2cac3209af5f349d683e2b384b197b777ba314532fee103f8177173be lorefile-0.2.0-x86_64-unknown-linux-gnu-slim.tar.gz
10
+ 8276945eb59153a45e09c2dbfffda6a2c8c15fc2347c7a023dac3df237972ea1 lorefile-0.2.0-x86_64-unknown-linux-gnu.tar.gz
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "lorefile",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "A team's business knowledge in plain YAML files, for AI agents: an MCP server, a CLI and a web page in one binary. This package downloads and runs it.",
5
+ "keywords": [
6
+ "ontology",
7
+ "mcp",
8
+ "ai-agents",
9
+ "semantic-layer",
10
+ "yaml",
11
+ "cli"
12
+ ],
13
+ "homepage": "https://github.com/lorefile/lorefile#readme",
14
+ "bugs": "https://github.com/lorefile/lorefile/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/lorefile/lorefile.git",
18
+ "directory": "npm"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "bin": {
22
+ "lorefile": "bin/lorefile.js"
23
+ },
24
+ "files": [
25
+ "bin/lorefile.js",
26
+ "checksums.txt",
27
+ "LICENSE",
28
+ "NOTICE"
29
+ ],
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "os": [
34
+ "darwin",
35
+ "linux",
36
+ "win32"
37
+ ],
38
+ "cpu": [
39
+ "x64",
40
+ "arm64"
41
+ ]
42
+ }