@catheadowl/ukp 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.
- package/LICENSE +21 -0
- package/README.md +208 -0
- package/bun.lock +35 -0
- package/package.json +51 -0
- package/src/artifacts.ts +75 -0
- package/src/capabilities/nav.ts +734 -0
- package/src/capabilities/propose.ts +456 -0
- package/src/capabilities/qmd.ts +174 -0
- package/src/capabilities/read.ts +1040 -0
- package/src/capabilities/remote-client.ts +856 -0
- package/src/capabilities/rename-recovery.ts +294 -0
- package/src/capabilities/rg.ts +505 -0
- package/src/capabilities/search.ts +1105 -0
- package/src/capabilities/tls-identity.ts +87 -0
- package/src/capabilities/update.ts +385 -0
- package/src/cli.ts +425 -0
- package/src/commands/diagnose.ts +383 -0
- package/src/commands/flags.ts +49 -0
- package/src/commands/guide-content/client.txt +36 -0
- package/src/commands/guide-content/propose.txt +38 -0
- package/src/commands/guide-content/service-qmd.txt +44 -0
- package/src/commands/guide-content/service.txt +114 -0
- package/src/commands/guide.ts +121 -0
- package/src/commands/init.ts +245 -0
- package/src/commands/inspect.ts +182 -0
- package/src/commands/inventory.ts +570 -0
- package/src/commands/kit.ts +269 -0
- package/src/commands/nav.ts +280 -0
- package/src/commands/propose.ts +257 -0
- package/src/commands/read.ts +558 -0
- package/src/commands/rg.ts +355 -0
- package/src/commands/search.ts +325 -0
- package/src/commands/serve.ts +221 -0
- package/src/commands/update.ts +99 -0
- package/src/config/client.ts +55 -0
- package/src/config/external-tool.ts +58 -0
- package/src/config/file-native.ts +111 -0
- package/src/config/manifest.ts +188 -0
- package/src/fslock.ts +95 -0
- package/src/path-safety.ts +65 -0
- package/src/registry.ts +436 -0
- package/src/scope.ts +78 -0
- package/src/server.ts +1011 -0
- package/tsconfig.json +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CatheadOwl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# UKP
|
|
2
|
+
|
|
3
|
+
Folder as a Service: turn folders into named knowledge endpoints — one
|
|
4
|
+
stable command surface, on this machine or your own server.
|
|
5
|
+
|
|
6
|
+
Register a folder and it becomes an endpoint for humans and agents alike —
|
|
7
|
+
nothing is started, the folder stays a folder. Navigate, read, and search
|
|
8
|
+
it; propose changes back to the owner as reviewable suggestions; update
|
|
9
|
+
provider-owned indexes (local today). No physical paths to memorize, no
|
|
10
|
+
provider-specific commands to relearn.
|
|
11
|
+
|
|
12
|
+
> [!NOTE]
|
|
13
|
+
> Early-stage CLI (MVP) — commands and behavior may still change.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ ukp init service --name notes && ukp register
|
|
17
|
+
initialized Service: notes
|
|
18
|
+
registered: notes
|
|
19
|
+
|
|
20
|
+
$ ukp rg "Goals" --endpoint notes # no search provider needed
|
|
21
|
+
== notes ==
|
|
22
|
+
1. 2026/q3-plan.md:3
|
|
23
|
+
Goals for Q3: ship the knowledge plane.
|
|
24
|
+
uri: ukp://notes/2026/q3-plan.md#L3
|
|
25
|
+
|
|
26
|
+
$ ukp read ukp://notes/2026/q3-plan.md # read straight from the reference
|
|
27
|
+
# Q3 Plan
|
|
28
|
+
Goals for Q3: ship the knowledge plane.
|
|
29
|
+
|
|
30
|
+
$ ukp propose --endpoint notes --id typo-fix --file typo-fix.md # the write face: declare propose first
|
|
31
|
+
proposal typo-fix created (revision 1)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Why UKP
|
|
35
|
+
|
|
36
|
+
Knowledge work starts in folders, but repeated use needs stable names,
|
|
37
|
+
predictable scope, and a single command surface. Use UKP when:
|
|
38
|
+
|
|
39
|
+
- the right knowledge already lives in folders, and callers should address
|
|
40
|
+
it by name instead of path;
|
|
41
|
+
- you keep re-explaining to people and agents where things live and how
|
|
42
|
+
they are indexed;
|
|
43
|
+
- changes should come back as reviewable proposals for the owner to decide,
|
|
44
|
+
not as unreviewed edits;
|
|
45
|
+
- provider setup should stay with the provider instead of leaking into
|
|
46
|
+
every caller.
|
|
47
|
+
|
|
48
|
+
## What It Does
|
|
49
|
+
|
|
50
|
+
- Register local folders as named knowledge endpoints — a registered folder
|
|
51
|
+
is a *Service*, addressed by its endpoint name.
|
|
52
|
+
- `ukp inspect` shows which endpoints the current scope selects — see what a
|
|
53
|
+
command will touch before running it.
|
|
54
|
+
- Navigate the Markdown structure of an endpoint — folders, descriptions,
|
|
55
|
+
depth — with zero provider dependency.
|
|
56
|
+
- Read endpoint-scoped references through `read/file` — if a file moves,
|
|
57
|
+
reference recovery re-finds it (git history first, then search). The
|
|
58
|
+
optional `read/qmd` goes through QMD (an external tool — see
|
|
59
|
+
Requirements). `read` and `nav` are derived defaults of every local
|
|
60
|
+
Service.
|
|
61
|
+
- Run base lexical search with `rg` across endpoint files — provider-free
|
|
62
|
+
and on by default, shaped into `read`-ready references.
|
|
63
|
+
- Search one endpoint, a workspace default scope, the whole local Registry,
|
|
64
|
+
or endpoints you have explicitly declared as its dependencies
|
|
65
|
+
(authority/context links), with explicit recursion (QMD-backed).
|
|
66
|
+
- Propose changes as an idempotent, reviewable suggestion — the proposal
|
|
67
|
+
lands in the endpoint's inbox and the verdict stays with its owner.
|
|
68
|
+
- Update provider-owned indexes through a stable UKP command (QMD-backed).
|
|
69
|
+
- Serve an endpoint over HTTP — a single endpoint, or the whole registry as
|
|
70
|
+
a host door — when you want it reachable from other machines.
|
|
71
|
+
- Want a read-only endpoint? Declare zero capabilities — an empty
|
|
72
|
+
`[capabilities]` table still registers one (derived `read`/`nav` only).
|
|
73
|
+
- Give agents JSON output (`--format json`), reference sidecars, and
|
|
74
|
+
`ukp://` handoff keys when they need machine-readable results.
|
|
75
|
+
|
|
76
|
+
UKP owns endpoint names, Registry bindings, Client scope, capability
|
|
77
|
+
selection, routing, and output shape; the provider owns collection setup,
|
|
78
|
+
indexes, ranking, and maintenance. UKP points to the delegated setup path —
|
|
79
|
+
it does not rewrite provider config for you.
|
|
80
|
+
|
|
81
|
+
## Install
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npm install -g @catheadowl/ukp
|
|
85
|
+
ukp --version
|
|
86
|
+
ukp guide service
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
One-off execution: `npx @catheadowl/ukp --version` (or `pnpm dlx` / `bunx`).
|
|
90
|
+
|
|
91
|
+
Requirements:
|
|
92
|
+
|
|
93
|
+
- Bun `1.3.14` or newer — the CLI runs on Bun.
|
|
94
|
+
- QMD on `PATH` only for the QMD-backed capabilities (`search/qmd`,
|
|
95
|
+
`read/qmd`, `update/qmd`). QMD is an external tool maintained as a
|
|
96
|
+
separate project; see its own release channel for installation. UKP
|
|
97
|
+
installs and runs without it — those capabilities report as unavailable
|
|
98
|
+
until `qmd` is available.
|
|
99
|
+
|
|
100
|
+
## First Run
|
|
101
|
+
|
|
102
|
+
For a human or agent starting from a folder:
|
|
103
|
+
|
|
104
|
+
1. `ukp init service` creates the minimum Service Manifest (`.ukp/service.toml`).
|
|
105
|
+
2. `ukp guide service` shows the provider-agnostic path. For the current QMD
|
|
106
|
+
provider, `ukp guide service qmd` hands off the provider-owned setup.
|
|
107
|
+
3. `ukp diagnose` checks that the folder is wired correctly.
|
|
108
|
+
4. `ukp register` adds the folder to the Host Registry (`~/.ukp/registry.toml`).
|
|
109
|
+
5. `ukp inspect --endpoint <name>` shows the current binding, manifest, and
|
|
110
|
+
provider availability.
|
|
111
|
+
6. `ukp search "<query>" --endpoint <name>` finds matches.
|
|
112
|
+
7. `ukp read --endpoint <name> <reference>` reads a result.
|
|
113
|
+
|
|
114
|
+
No QMD installed? Skip step 6 — `nav`, `read`, `rg`, and `propose` work on any
|
|
115
|
+
endpoint without it.
|
|
116
|
+
|
|
117
|
+
An agent can carry out the same flow on your behalf.
|
|
118
|
+
|
|
119
|
+
For workspace defaults, use `ukp guide client` and `.ukp/client.toml`.
|
|
120
|
+
|
|
121
|
+
## Commands
|
|
122
|
+
|
|
123
|
+
Grouping below follows `ukp --help`; every command stays a flat
|
|
124
|
+
`ukp <verb>`. `--endpoint <name>` is the canonical endpoint selector
|
|
125
|
+
(`-c` is a compatibility alias); `-g` selects the full local Host Registry
|
|
126
|
+
where supported.
|
|
127
|
+
|
|
128
|
+
The same five commands work on local and remote endpoints — consuming a
|
|
129
|
+
remote endpoint is a one-command gesture (see below).
|
|
130
|
+
|
|
131
|
+
Endpoint commands:
|
|
132
|
+
|
|
133
|
+
| Command | What it does |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `ukp search` | Indexed search through the endpoint's provider (QMD today); `--recursive` expands endpoints explicitly declared as dependencies (authority/context). Results hand off via `ukp://` references. |
|
|
136
|
+
| `ukp read` | Reads an endpoint-scoped resource — exact path, `ukp://` URI, or `docid` handoff key. |
|
|
137
|
+
| `ukp nav` | Markdown outline of an endpoint (`--depth`, respects `.gitignore`); on by default, configurable via `[capabilities.nav]`. |
|
|
138
|
+
| `ukp rg` | Lexical grep (ripgrep) across endpoint files — provider-free, on by default; results become `read`-ready `ukp://` references. A missing rg binary degrades to a skip, never a fault. |
|
|
139
|
+
| `ukp propose` | Submits an idempotent change proposal (suggestion box — the owner decides what happens next). Created/unchanged/updated; the revision bumps only on `updated`. |
|
|
140
|
+
|
|
141
|
+
Registry commands:
|
|
142
|
+
|
|
143
|
+
| Command | What it does |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `ukp init service` | Creates a minimal `.ukp/service.toml`. |
|
|
146
|
+
| `ukp register` / `ukp unregister --endpoint <name>` | Manages Host Registry bindings. `ukp register --url <url>` registers a remote endpoint — the name comes from its discovery document (asserted, not chosen), the identity is pinned TOFU-style (trust on first use), and self-signed certificates are pinned automatically. A **host door** url imports every endpoint behind it (`--select` narrows; re-running refreshes idempotently). |
|
|
147
|
+
| `ukp list` | Lists registered endpoints with their declared capabilities. Door drift shows as a stderr note (`door <origin>: N unimported endpoint(s) …`) — importing stays an explicit gesture. |
|
|
148
|
+
|
|
149
|
+
Operations commands:
|
|
150
|
+
|
|
151
|
+
| Command | What it does |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `ukp diagnose` | Checks a Service folder or endpoint scope for wiring problems. |
|
|
154
|
+
| `ukp inspect` | Explains current scope, bindings, manifest capabilities, and provider availability. |
|
|
155
|
+
| `ukp update` | Runs provider-owned maintenance when `update/qmd` is declared (local endpoints today). |
|
|
156
|
+
| `ukp serve` | Serves one endpoint — or, without `--endpoint`, the whole registry as a **host door** — over HTTP: a discovery document plus the five command routes (the write face requires the endpoint to declare propose). Loopback by default; `UKP_SERVE_TOKEN` enables bearer auth; `--tls` for HTTPS. |
|
|
157
|
+
|
|
158
|
+
Help commands:
|
|
159
|
+
|
|
160
|
+
| Command | What it does |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `ukp version` / `ukp --version` / `ukp -V` | Shows the package version. |
|
|
163
|
+
| `ukp guide service` | Provider-agnostic Service setup path. |
|
|
164
|
+
| `ukp guide service qmd` | Provider-owned setup for the QMD provider. |
|
|
165
|
+
| `ukp guide client` | How a workspace uses registered Services by default. |
|
|
166
|
+
| `ukp guide propose` | The propose quickstart. |
|
|
167
|
+
|
|
168
|
+
## Remote in 60 seconds
|
|
169
|
+
|
|
170
|
+
`ukp serve` exposes an endpoint over HTTP. Authentication is deny-by-default:
|
|
171
|
+
serving with a `--host` beyond loopback requires `UKP_SERVE_TOKEN` (tokenless
|
|
172
|
+
serving needs an explicit `--allow-anonymous` and is refused off loopback).
|
|
173
|
+
The two fastest paths, from the consumer machine:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# SSH between two personal machines — an ephemeral tunnel per invocation:
|
|
177
|
+
ukp register --url ssh://<host>:8570 --token <token> # once; TOFU + token stored
|
|
178
|
+
ukp read --endpoint <name> notes/x.md # just works, like local
|
|
179
|
+
|
|
180
|
+
# Native TLS on a bare IP — self-signed, pinned automatically at registration:
|
|
181
|
+
UKP_SERVE_TOKEN=<token> ukp serve --endpoint <name> --host 0.0.0.0 --port 8570 --tls
|
|
182
|
+
ukp register --url https://<ip>:8570 --token <token>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Remote endpoints take the same commands as local ones — search, read, nav,
|
|
186
|
+
rg, propose. The full guide — the host door (one port for the whole
|
|
187
|
+
registry), Caddy and Tailscale fronting, the certificate pinning lifecycle,
|
|
188
|
+
and the hardening posture — lives in the
|
|
189
|
+
[deployment guide](https://github.com/CatheadOwl/ukp/blob/main/docs/remote-deployment.md).
|
|
190
|
+
|
|
191
|
+
## Not Yet
|
|
192
|
+
|
|
193
|
+
- remote operation of `update`, and a formally specified network protocol
|
|
194
|
+
beyond the current ukp-remote wire v1;
|
|
195
|
+
- semantic search tier, an HTTP search API, query rewrite, reranking, or
|
|
196
|
+
deduplication;
|
|
197
|
+
- full Client Scope with aliases, visibility, inheritance, or profiles;
|
|
198
|
+
- automatic artifact browsing, cleanup, or "select result N" references;
|
|
199
|
+
- standalone binary distribution.
|
|
200
|
+
|
|
201
|
+
## Documentation
|
|
202
|
+
|
|
203
|
+
- [Remote deployment](https://github.com/CatheadOwl/ukp/blob/main/docs/remote-deployment.md) — serving endpoints over
|
|
204
|
+
SSH/HTTPS, the host door, Caddy and Tailscale fronting, the certificate
|
|
205
|
+
pinning lifecycle, and the hardening posture.
|
|
206
|
+
- [Contributing](https://github.com/CatheadOwl/ukp/blob/main/CONTRIBUTING.md) — development setup and release packaging.
|
|
207
|
+
- Repository: https://github.com/CatheadOwl/ukp ·
|
|
208
|
+
Issues: https://github.com/CatheadOwl/ukp/issues
|
package/bun.lock
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"configVersion": 1,
|
|
4
|
+
"workspaces": {
|
|
5
|
+
"": {
|
|
6
|
+
"name": "@catheadowl/ukp",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"commander": "15.0.0",
|
|
9
|
+
"smol-toml": "1.7.1",
|
|
10
|
+
"zod": "4.4.3",
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/bun": "1.3.5",
|
|
14
|
+
"typescript": "5.9.3",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
"packages": {
|
|
19
|
+
"@types/bun": ["@types/bun@1.3.5", "https://registry.npmmirror.com/@types/bun/-/bun-1.3.5.tgz", { "dependencies": { "bun-types": "1.3.5" } }, "sha512-RnygCqNrd3srIPEWBd5LFeUYG7plCoH2Yw9WaZGyNmdTEei+gWaHqydbaIRkIkcbXwhBT94q78QljxN0Sk838w=="],
|
|
20
|
+
|
|
21
|
+
"@types/node": ["@types/node@26.1.1", "https://registry.npmmirror.com/@types/node/-/node-26.1.1.tgz", { "dependencies": { "undici-types": "~8.3.0" } }, "sha512-nxAkRSVkN1Y0JC1W8ky/fTfkGsMmcrRsbx+3XoZE+rMOX71kLYTV7fLXpqud1GpbpP5TuffXFqfX7fH2GgZREw=="],
|
|
22
|
+
|
|
23
|
+
"bun-types": ["bun-types@1.3.5", "https://registry.npmmirror.com/bun-types/-/bun-types-1.3.5.tgz", { "dependencies": { "@types/node": "*" } }, "sha512-inmAYe2PFLs0SUbFOWSVD24sg1jFlMPxOjOSSCYqUgn4Hsc3rDc7dFvfVYjFPNHtov6kgUeulV4SxbuIV/stPw=="],
|
|
24
|
+
|
|
25
|
+
"commander": ["commander@15.0.0", "https://registry.npmmirror.com/commander/-/commander-15.0.0.tgz", {}, "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg=="],
|
|
26
|
+
|
|
27
|
+
"smol-toml": ["smol-toml@1.7.1", "https://registry.npmmirror.com/smol-toml/-/smol-toml-1.7.1.tgz", {}, "sha512-PPlsspAZ4jbMBu5DMFhfUGDQLu/vrL4SyBROVS37x8ynnVmFIs1VPBz1Co8Xks3TvpIaZXmU85y4DrQ+UyVFoQ=="],
|
|
28
|
+
|
|
29
|
+
"typescript": ["typescript@5.9.3", "https://registry.npmmirror.com/typescript/-/typescript-5.9.3.tgz", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
|
30
|
+
|
|
31
|
+
"undici-types": ["undici-types@8.3.0", "https://registry.npmmirror.com/undici-types/-/undici-types-8.3.0.tgz", {}, "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ=="],
|
|
32
|
+
|
|
33
|
+
"zod": ["zod@4.4.3", "https://registry.npmmirror.com/zod/-/zod-4.4.3.tgz", {}, "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ=="],
|
|
34
|
+
}
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@catheadowl/ukp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"bun": ">=1.3.14"
|
|
7
|
+
},
|
|
8
|
+
"description": "Folder as a Service CLI: turn folders into named knowledge endpoints — one stable command surface, on this machine or your own server",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/CatheadOwl/ukp.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/CatheadOwl/ukp#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/CatheadOwl/ukp/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"knowledge",
|
|
20
|
+
"cli",
|
|
21
|
+
"bun",
|
|
22
|
+
"qmd",
|
|
23
|
+
"search",
|
|
24
|
+
"agent"
|
|
25
|
+
],
|
|
26
|
+
"bin": {
|
|
27
|
+
"ukp": "src/cli.ts"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"src",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"package.json",
|
|
34
|
+
"bun.lock",
|
|
35
|
+
"tsconfig.json"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "bun run src/cli.ts",
|
|
39
|
+
"test": "bun test",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"commander": "15.0.0",
|
|
44
|
+
"smol-toml": "1.7.1",
|
|
45
|
+
"zod": "4.4.3"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/bun": "1.3.5",
|
|
49
|
+
"typescript": "5.9.3"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/artifacts.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readdirSync,
|
|
5
|
+
rmSync,
|
|
6
|
+
statSync,
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
10
|
+
|
|
11
|
+
const RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
12
|
+
|
|
13
|
+
export interface ArtifactRunOptions {
|
|
14
|
+
root?: string;
|
|
15
|
+
runId?: string;
|
|
16
|
+
now?: Date;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ArtifactRun {
|
|
20
|
+
root: string;
|
|
21
|
+
runId: string;
|
|
22
|
+
directory: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function defaultArtifactRoot(): string {
|
|
26
|
+
if (process.platform === "win32") {
|
|
27
|
+
const localAppData = process.env.LOCALAPPDATA;
|
|
28
|
+
return resolve(localAppData ?? join(homedir(), "AppData", "Local"), "ukp", "artifacts");
|
|
29
|
+
}
|
|
30
|
+
const cacheRoot = process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache");
|
|
31
|
+
return resolve(cacheRoot, "ukp", "artifacts");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function makeRunId(now: Date): string {
|
|
35
|
+
const timestamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}Z$/, "Z");
|
|
36
|
+
return `${timestamp}-${randomBytes(3).toString("hex")}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function cleanupExpiredRuns(root: string, now: Date): void {
|
|
40
|
+
let names: string[];
|
|
41
|
+
try {
|
|
42
|
+
names = readdirSync(root);
|
|
43
|
+
} catch {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (const name of names) {
|
|
48
|
+
const candidate = join(root, name);
|
|
49
|
+
try {
|
|
50
|
+
const stat = statSync(candidate);
|
|
51
|
+
if (stat.isDirectory() && now.getTime() - stat.mtimeMs > RETENTION_MS) {
|
|
52
|
+
rmSync(candidate, { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
// Cleanup is best-effort and must not block the current search.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function createArtifactRun(options: ArtifactRunOptions = {}): ArtifactRun {
|
|
61
|
+
const now = options.now ?? new Date();
|
|
62
|
+
const root = resolve(options.root ?? defaultArtifactRoot());
|
|
63
|
+
const runId = options.runId ?? makeRunId(now);
|
|
64
|
+
if (!/^[A-Za-z0-9._-]+$/.test(runId)) {
|
|
65
|
+
throw new Error(`invalid artifact run id '${runId}'`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
69
|
+
cleanupExpiredRuns(root, now);
|
|
70
|
+
const directory = join(root, runId);
|
|
71
|
+
mkdirSync(directory, { recursive: false, mode: 0o700 });
|
|
72
|
+
|
|
73
|
+
if (!isAbsolute(directory)) throw new Error("artifact directory must be absolute");
|
|
74
|
+
return { root, runId, directory };
|
|
75
|
+
}
|