@spader/dotllm 1.3.1 → 1.3.3
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/README.md +12 -0
- package/package.json +1 -1
- package/src/cli/commands/add.js +529 -30
- package/src/cli/commands/completions.js +506 -26
- package/src/cli/commands/index.js +1268 -16
- package/src/cli/commands/link.js +516 -17
- package/src/cli/commands/list.js +628 -9
- package/src/cli/commands/remove.js +485 -5
- package/src/cli/commands/sync.js +525 -13
- package/src/cli/commands/which.js +488 -8
- package/src/cli/index.js +1438 -10
- package/src/cli/layout.js +22 -6
- package/src/cli/prompt.js +0 -2
- package/src/cli/theme.js +0 -2
- package/src/cli/yargs.js +163 -6
- package/src/core/add.js +171 -15
- package/src/core/config.js +139 -115
- package/src/core/index.js +467 -13
- package/src/core/link.js +321 -3
- package/src/core/remove.js +164 -8
- package/src/core/sync.js +260 -40
- package/src/core/unlink.js +162 -6
package/src/cli/commands/list.js
CHANGED
|
@@ -1,11 +1,630 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
2
|
+
var __esm = (fn, res, err) => () => {
|
|
3
|
+
if (fn)
|
|
4
|
+
try {
|
|
5
|
+
res = fn(fn = 0);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
err = [e];
|
|
8
|
+
}
|
|
9
|
+
if (err)
|
|
10
|
+
throw err[0];
|
|
11
|
+
return res;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/core/config.ts
|
|
15
|
+
import fs from "fs";
|
|
16
|
+
import os from "os";
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
function readJson(filepath) {
|
|
20
|
+
if (!fs.existsSync(filepath))
|
|
21
|
+
return null;
|
|
22
|
+
const raw = fs.readFileSync(filepath, "utf-8");
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(raw);
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var LOCAL_DIR = ".llm", LOCAL_FILE, REF_DIR, RepoEntry, GlobalShape, LocalShape, Config;
|
|
30
|
+
var init_config = __esm(() => {
|
|
31
|
+
LOCAL_FILE = path.join(LOCAL_DIR, "dotllm.json");
|
|
32
|
+
REF_DIR = path.join(LOCAL_DIR, "reference");
|
|
33
|
+
RepoEntry = z.object({
|
|
34
|
+
kind: z.enum(["url", "file"]),
|
|
35
|
+
name: z.string(),
|
|
36
|
+
uri: z.string(),
|
|
37
|
+
description: z.string()
|
|
38
|
+
});
|
|
39
|
+
GlobalShape = z.object({
|
|
40
|
+
store: z.string().optional(),
|
|
41
|
+
repos: z.array(RepoEntry)
|
|
42
|
+
});
|
|
43
|
+
LocalShape = z.object({
|
|
44
|
+
refs: z.record(z.string(), RepoEntry)
|
|
45
|
+
});
|
|
46
|
+
((Config) => {
|
|
47
|
+
function home() {
|
|
48
|
+
if (process.platform === "win32") {
|
|
49
|
+
const appData = process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
|
|
50
|
+
return path.join(appData, "dotllm");
|
|
51
|
+
}
|
|
52
|
+
return path.join(process.env.HOME ?? os.homedir(), ".local", "share", "dotllm");
|
|
53
|
+
}
|
|
54
|
+
Config.home = home;
|
|
55
|
+
function storeDir() {
|
|
56
|
+
const store = Global.read().store;
|
|
57
|
+
if (!store)
|
|
58
|
+
return path.join(home(), "store");
|
|
59
|
+
return expand(store);
|
|
60
|
+
}
|
|
61
|
+
Config.storeDir = storeDir;
|
|
62
|
+
function refDir() {
|
|
63
|
+
return REF_DIR;
|
|
64
|
+
}
|
|
65
|
+
Config.refDir = refDir;
|
|
66
|
+
let Global;
|
|
67
|
+
((Global) => {
|
|
68
|
+
function read() {
|
|
69
|
+
const raw = readJson(path.join(home(), "dotllm.json"));
|
|
70
|
+
if (!raw)
|
|
71
|
+
return { repos: [] };
|
|
72
|
+
const result = GlobalShape.safeParse(raw);
|
|
73
|
+
if (!result.success)
|
|
74
|
+
return { repos: [] };
|
|
75
|
+
return result.data;
|
|
76
|
+
}
|
|
77
|
+
Global.read = read;
|
|
78
|
+
function write(config) {
|
|
79
|
+
const dir = home();
|
|
80
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
81
|
+
fs.writeFileSync(path.join(dir, "dotllm.json"), JSON.stringify(config, null, 2) + `
|
|
82
|
+
`);
|
|
83
|
+
}
|
|
84
|
+
Global.write = write;
|
|
85
|
+
function find(config, name) {
|
|
86
|
+
const lower = name.toLowerCase();
|
|
87
|
+
return config.repos.find((r) => r.name.toLowerCase() === lower);
|
|
88
|
+
}
|
|
89
|
+
Global.find = find;
|
|
90
|
+
function add(config, entry) {
|
|
91
|
+
const lower = entry.name.toLowerCase();
|
|
92
|
+
const filtered = config.repos.filter((r) => r.name.toLowerCase() !== lower);
|
|
93
|
+
return { ...config, repos: [...filtered, entry] };
|
|
94
|
+
}
|
|
95
|
+
Global.add = add;
|
|
96
|
+
function remove(config, name) {
|
|
97
|
+
const lower = name.toLowerCase();
|
|
98
|
+
return { ...config, repos: config.repos.filter((r) => r.name.toLowerCase() !== lower) };
|
|
99
|
+
}
|
|
100
|
+
Global.remove = remove;
|
|
101
|
+
})(Global = Config.Global ||= {});
|
|
102
|
+
let Local;
|
|
103
|
+
((Local) => {
|
|
104
|
+
function read() {
|
|
105
|
+
const raw = readJson(LOCAL_FILE);
|
|
106
|
+
if (!raw)
|
|
107
|
+
return { refs: {} };
|
|
108
|
+
const result = LocalShape.safeParse(raw);
|
|
109
|
+
if (!result.success)
|
|
110
|
+
return { refs: {} };
|
|
111
|
+
return result.data;
|
|
112
|
+
}
|
|
113
|
+
Local.read = read;
|
|
114
|
+
function write(config) {
|
|
115
|
+
fs.mkdirSync(LOCAL_DIR, { recursive: true });
|
|
116
|
+
fs.writeFileSync(LOCAL_FILE, JSON.stringify(config, null, 2) + `
|
|
117
|
+
`);
|
|
118
|
+
}
|
|
119
|
+
Local.write = write;
|
|
120
|
+
function find(config, name) {
|
|
121
|
+
const lower = name.toLowerCase();
|
|
122
|
+
for (const [key, value] of Object.entries(config.refs)) {
|
|
123
|
+
if (key.toLowerCase() === lower)
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
Local.find = find;
|
|
129
|
+
function has(config, name) {
|
|
130
|
+
return find(config, name) !== undefined;
|
|
131
|
+
}
|
|
132
|
+
Local.has = has;
|
|
133
|
+
function add(config, repo) {
|
|
134
|
+
const lower = repo.name.toLowerCase();
|
|
135
|
+
const refs = Object.fromEntries(Object.entries(config.refs).filter(([key]) => key.toLowerCase() !== lower));
|
|
136
|
+
refs[repo.name] = repo;
|
|
137
|
+
return { refs };
|
|
138
|
+
}
|
|
139
|
+
Local.add = add;
|
|
140
|
+
function remove(config, name) {
|
|
141
|
+
const lower = name.toLowerCase();
|
|
142
|
+
const refs = Object.fromEntries(Object.entries(config.refs).filter(([key]) => key.toLowerCase() !== lower));
|
|
143
|
+
return { refs };
|
|
144
|
+
}
|
|
145
|
+
Local.remove = remove;
|
|
146
|
+
})(Local = Config.Local ||= {});
|
|
147
|
+
function expand(dir) {
|
|
148
|
+
const tilde = dir === "~" || dir.startsWith("~/") || dir.startsWith("~\\");
|
|
149
|
+
if (!tilde)
|
|
150
|
+
return path.resolve(home(), dir);
|
|
151
|
+
return path.join(os.homedir(), dir.slice(1));
|
|
152
|
+
}
|
|
153
|
+
})(Config ||= {});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// src/core/add.ts
|
|
157
|
+
import fs2 from "fs";
|
|
158
|
+
import path2 from "path";
|
|
159
|
+
function isUrl(value) {
|
|
160
|
+
return value.startsWith("http://") || value.startsWith("https://") || value.startsWith("git@") || value.startsWith("ssh://");
|
|
161
|
+
}
|
|
162
|
+
function nameFromGitRemote(dir) {
|
|
163
|
+
const result = Bun.spawnSync(["git", "remote", "get-url", "origin"], {
|
|
164
|
+
cwd: dir,
|
|
165
|
+
stdout: "pipe",
|
|
166
|
+
stderr: "pipe"
|
|
167
|
+
});
|
|
168
|
+
if (result.exitCode !== 0)
|
|
169
|
+
return null;
|
|
170
|
+
const url = result.stdout.toString().trim();
|
|
171
|
+
return nameFromUrl(url);
|
|
172
|
+
}
|
|
173
|
+
function nameFromUrl(url) {
|
|
174
|
+
const base = url.split("/").pop() ?? url;
|
|
175
|
+
return base.replace(/\.git$/, "");
|
|
176
|
+
}
|
|
177
|
+
async function add(uri, name, description) {
|
|
178
|
+
const desc = description ?? "";
|
|
179
|
+
if (isUrl(uri)) {
|
|
180
|
+
return cloneUrl(uri, name, desc);
|
|
181
|
+
}
|
|
182
|
+
return linkLocal(uri, name, desc);
|
|
183
|
+
}
|
|
184
|
+
async function cloneUrl(url, name, description) {
|
|
185
|
+
const resolved = name ?? nameFromUrl(url);
|
|
186
|
+
const store = Config.storeDir();
|
|
187
|
+
fs2.mkdirSync(store, { recursive: true });
|
|
188
|
+
const target = path2.join(store, resolved);
|
|
189
|
+
if (!fs2.existsSync(target)) {
|
|
190
|
+
const proc = Bun.spawn(["git", "clone", "--depth=1", url, target], {
|
|
191
|
+
stdout: "pipe",
|
|
192
|
+
stderr: "pipe"
|
|
193
|
+
});
|
|
194
|
+
const code = await proc.exited;
|
|
195
|
+
if (code !== 0) {
|
|
196
|
+
const msg = await new Response(proc.stderr).text();
|
|
197
|
+
return { ok: false, error: `git clone failed: ${msg.trim()}` };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const entry = { kind: "url", name: resolved, uri: url, description };
|
|
201
|
+
const global = Config.Global.read();
|
|
202
|
+
Config.Global.write(Config.Global.add(global, entry));
|
|
203
|
+
return { ok: true, entry, storePath: target };
|
|
204
|
+
}
|
|
205
|
+
function linkLocal(raw, name, description) {
|
|
206
|
+
const resolved = path2.resolve(raw);
|
|
207
|
+
if (!fs2.existsSync(resolved)) {
|
|
208
|
+
return { ok: false, error: `Path does not exist: ${resolved}` };
|
|
209
|
+
}
|
|
210
|
+
if (!fs2.statSync(resolved).isDirectory()) {
|
|
211
|
+
return { ok: false, error: `Not a directory: ${resolved}` };
|
|
212
|
+
}
|
|
213
|
+
const store = Config.storeDir();
|
|
214
|
+
fs2.mkdirSync(store, { recursive: true });
|
|
215
|
+
const finalName = name ?? nameFromGitRemote(resolved) ?? path2.basename(resolved);
|
|
216
|
+
const target = path2.join(store, finalName);
|
|
217
|
+
if (!fs2.existsSync(target)) {
|
|
218
|
+
fs2.symlinkSync(resolved, target, "dir");
|
|
219
|
+
}
|
|
220
|
+
const entry = { kind: "file", name: finalName, uri: resolved, description };
|
|
221
|
+
const global = Config.Global.read();
|
|
222
|
+
Config.Global.write(Config.Global.add(global, entry));
|
|
223
|
+
return { ok: true, entry, storePath: target };
|
|
224
|
+
}
|
|
225
|
+
var init_add = __esm(() => {
|
|
226
|
+
init_config();
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// src/core/remove.ts
|
|
230
|
+
import fs3 from "fs";
|
|
231
|
+
import path3 from "path";
|
|
232
|
+
function remove(name) {
|
|
233
|
+
const global = Config.Global.read();
|
|
234
|
+
const found = Config.Global.find(global, name);
|
|
235
|
+
if (!found) {
|
|
236
|
+
return { ok: false, error: `No repo named "${name}" in registry` };
|
|
237
|
+
}
|
|
238
|
+
const target = path3.join(Config.storeDir(), found.name);
|
|
239
|
+
if (fs3.existsSync(target)) {
|
|
240
|
+
const stat = fs3.lstatSync(target);
|
|
241
|
+
if (stat.isSymbolicLink()) {
|
|
242
|
+
fs3.unlinkSync(target);
|
|
243
|
+
}
|
|
244
|
+
if (stat.isDirectory()) {
|
|
245
|
+
fs3.rmSync(target, { recursive: true, force: true });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
Config.Global.write(Config.Global.remove(global, found.name));
|
|
249
|
+
return { ok: true };
|
|
250
|
+
}
|
|
251
|
+
var init_remove = __esm(() => {
|
|
252
|
+
init_config();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// src/core/sync.ts
|
|
256
|
+
import fs4 from "fs";
|
|
257
|
+
import path4 from "path";
|
|
258
|
+
function shouldPull(storeDir, force) {
|
|
259
|
+
if (force)
|
|
260
|
+
return true;
|
|
261
|
+
const head = path4.join(storeDir, ".git", "HEAD");
|
|
262
|
+
const headStat = fs4.statSync(head, { throwIfNoEntry: false });
|
|
263
|
+
if (!headStat)
|
|
264
|
+
return true;
|
|
265
|
+
const age = Date.now() - headStat.mtimeMs;
|
|
266
|
+
if (age < FRESH_MS)
|
|
267
|
+
return false;
|
|
268
|
+
if (age > STALE_MS)
|
|
269
|
+
return true;
|
|
270
|
+
const dirStat = fs4.statSync(storeDir, { throwIfNoEntry: false });
|
|
271
|
+
if (!dirStat)
|
|
272
|
+
return true;
|
|
273
|
+
return dirStat.atimeMs > headStat.mtimeMs;
|
|
274
|
+
}
|
|
275
|
+
async function pull(names, options = {}) {
|
|
276
|
+
const force = options.force === true;
|
|
277
|
+
const global = Config.Global.read();
|
|
278
|
+
const states = await Promise.all(names.map(async (name) => {
|
|
279
|
+
const cwd = path4.join(Config.refDir(), name);
|
|
280
|
+
if (!fs4.existsSync(cwd)) {
|
|
281
|
+
return { kind: "failed", name, error: "reference directory missing" };
|
|
282
|
+
}
|
|
283
|
+
const repo = Config.Global.find(global, name);
|
|
284
|
+
if (repo && repo.kind === "file") {
|
|
285
|
+
return { kind: "skipped", name };
|
|
286
|
+
}
|
|
287
|
+
const storeDir = path4.join(Config.storeDir(), name);
|
|
288
|
+
const storeStat = fs4.lstatSync(storeDir, { throwIfNoEntry: false });
|
|
289
|
+
if (!storeStat || storeStat.isSymbolicLink()) {
|
|
290
|
+
return { kind: "skipped", name };
|
|
291
|
+
}
|
|
292
|
+
if (!fs4.existsSync(path4.join(storeDir, ".git"))) {
|
|
293
|
+
return { kind: "failed", name, error: "store directory is not a git repo" };
|
|
294
|
+
}
|
|
295
|
+
if (!shouldPull(storeDir, force)) {
|
|
296
|
+
return { kind: "skipped", name };
|
|
297
|
+
}
|
|
298
|
+
const fetch = Bun.spawn(["git", "fetch", "--depth=1", "origin", "HEAD"], {
|
|
299
|
+
cwd,
|
|
300
|
+
stdout: "pipe",
|
|
301
|
+
stderr: "pipe"
|
|
302
|
+
});
|
|
303
|
+
const [fetchCode, fetchOut, fetchErr] = await Promise.all([
|
|
304
|
+
fetch.exited,
|
|
305
|
+
new Response(fetch.stdout).text(),
|
|
306
|
+
new Response(fetch.stderr).text()
|
|
307
|
+
]);
|
|
308
|
+
if (fetchCode !== 0) {
|
|
309
|
+
const msg = `${fetchOut}
|
|
310
|
+
${fetchErr}`.trim();
|
|
311
|
+
return { kind: "failed", name, error: msg || "git fetch failed" };
|
|
312
|
+
}
|
|
313
|
+
const reset = Bun.spawn(["git", "reset", "--hard", "FETCH_HEAD"], {
|
|
314
|
+
cwd,
|
|
315
|
+
stdout: "pipe",
|
|
316
|
+
stderr: "pipe"
|
|
317
|
+
});
|
|
318
|
+
const [resetCode, resetOut, resetErr] = await Promise.all([
|
|
319
|
+
reset.exited,
|
|
320
|
+
new Response(reset.stdout).text(),
|
|
321
|
+
new Response(reset.stderr).text()
|
|
322
|
+
]);
|
|
323
|
+
if (resetCode !== 0) {
|
|
324
|
+
const msg = `${resetOut}
|
|
325
|
+
${resetErr}`.trim();
|
|
326
|
+
return { kind: "failed", name, error: msg || "git reset failed" };
|
|
327
|
+
}
|
|
328
|
+
return { kind: "ok" };
|
|
329
|
+
}));
|
|
330
|
+
const pulled = [];
|
|
331
|
+
const skipped = [];
|
|
332
|
+
const failed = [];
|
|
333
|
+
for (let i = 0;i < states.length; i++) {
|
|
334
|
+
const state = states[i];
|
|
335
|
+
if (state.kind === "ok")
|
|
336
|
+
pulled.push(names[i]);
|
|
337
|
+
if (state.kind === "skipped")
|
|
338
|
+
skipped.push(state.name);
|
|
339
|
+
if (state.kind === "failed")
|
|
340
|
+
failed.push({ name: state.name, error: state.error });
|
|
341
|
+
}
|
|
342
|
+
return { count: names.length, pulled, skipped, failed };
|
|
343
|
+
}
|
|
344
|
+
function sync() {
|
|
345
|
+
const local = Config.Local.read();
|
|
346
|
+
const global = Config.Global.read();
|
|
347
|
+
const merged = Object.values(local.refs).reduce((config, repo) => Config.Global.add(config, repo), global);
|
|
348
|
+
if (Object.keys(local.refs).length > 0) {
|
|
349
|
+
Config.Global.write(merged);
|
|
350
|
+
}
|
|
351
|
+
const refDir = Config.refDir();
|
|
352
|
+
fs4.mkdirSync(refDir, { recursive: true });
|
|
353
|
+
fs4.mkdirSync(Config.storeDir(), { recursive: true });
|
|
354
|
+
const linked = [];
|
|
355
|
+
const removed = [];
|
|
356
|
+
const missing = [];
|
|
357
|
+
const unchanged = [];
|
|
358
|
+
const wanted = new Set(Object.keys(local.refs));
|
|
359
|
+
for (const entry of fs4.readdirSync(refDir)) {
|
|
360
|
+
if (wanted.has(entry))
|
|
361
|
+
continue;
|
|
362
|
+
const target = path4.join(refDir, entry);
|
|
363
|
+
const stat = fs4.lstatSync(target);
|
|
364
|
+
if (stat.isSymbolicLink()) {
|
|
365
|
+
fs4.unlinkSync(target);
|
|
366
|
+
removed.push(entry);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
for (const [name, repo] of Object.entries(local.refs)) {
|
|
370
|
+
const store = path4.join(Config.storeDir(), name);
|
|
371
|
+
const storeBroken = repo.kind === "url" && fs4.existsSync(store) && !fs4.existsSync(path4.join(store, ".git"));
|
|
372
|
+
if (storeBroken) {
|
|
373
|
+
fs4.rmSync(store, { recursive: true, force: true });
|
|
374
|
+
}
|
|
375
|
+
if (!fs4.existsSync(store) && repo.kind === "url") {
|
|
376
|
+
const clone = Bun.spawnSync(["git", "clone", "--depth=1", repo.uri, store], {
|
|
377
|
+
stdout: "pipe",
|
|
378
|
+
stderr: "pipe"
|
|
379
|
+
});
|
|
380
|
+
if (clone.exitCode !== 0) {
|
|
381
|
+
missing.push(name);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (!fs4.existsSync(store) && repo.kind === "file") {
|
|
386
|
+
if (!fs4.existsSync(repo.uri)) {
|
|
387
|
+
missing.push(name);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (!fs4.statSync(repo.uri).isDirectory()) {
|
|
391
|
+
missing.push(name);
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
fs4.symlinkSync(repo.uri, store, "dir");
|
|
395
|
+
}
|
|
396
|
+
if (!fs4.existsSync(store)) {
|
|
397
|
+
missing.push(name);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
const target = path4.join(refDir, name);
|
|
401
|
+
if (fs4.existsSync(target)) {
|
|
402
|
+
unchanged.push(name);
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
fs4.symlinkSync(store, target, "dir");
|
|
406
|
+
linked.push(name);
|
|
407
|
+
}
|
|
408
|
+
return { linked, removed, missing, unchanged };
|
|
409
|
+
}
|
|
410
|
+
var FRESH_MS, STALE_MS;
|
|
411
|
+
var init_sync = __esm(() => {
|
|
412
|
+
init_config();
|
|
413
|
+
FRESH_MS = 24 * 60 * 60 * 1000;
|
|
414
|
+
STALE_MS = 7 * FRESH_MS;
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// src/core/link.ts
|
|
418
|
+
function link(names) {
|
|
419
|
+
const global = Config.Global.read();
|
|
420
|
+
const rows = names.map((name) => {
|
|
421
|
+
const repo = Config.Global.find(global, name);
|
|
422
|
+
if (!repo)
|
|
423
|
+
return null;
|
|
424
|
+
return [repo.name, repo];
|
|
425
|
+
}).filter((row) => row !== null);
|
|
426
|
+
Config.Local.write({ refs: Object.fromEntries(rows) });
|
|
427
|
+
return sync();
|
|
428
|
+
}
|
|
429
|
+
var init_link = __esm(() => {
|
|
430
|
+
init_config();
|
|
431
|
+
init_sync();
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// src/core/unlink.ts
|
|
435
|
+
import fs5 from "fs";
|
|
436
|
+
import path5 from "path";
|
|
437
|
+
function unlink(name) {
|
|
438
|
+
const local = Config.Local.read();
|
|
439
|
+
const found = Config.Local.find(local, name);
|
|
440
|
+
if (!found) {
|
|
441
|
+
return { ok: false, error: `"${name}" is not linked in local config` };
|
|
442
|
+
}
|
|
443
|
+
const target = path5.join(Config.refDir(), found.name);
|
|
444
|
+
if (fs5.existsSync(target)) {
|
|
445
|
+
fs5.unlinkSync(target);
|
|
446
|
+
}
|
|
447
|
+
Config.Local.write(Config.Local.remove(local, found.name));
|
|
448
|
+
return { ok: true };
|
|
449
|
+
}
|
|
450
|
+
var init_unlink = __esm(() => {
|
|
451
|
+
init_config();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// src/core/index.ts
|
|
455
|
+
var init_core = __esm(() => {
|
|
456
|
+
init_config();
|
|
457
|
+
init_add();
|
|
458
|
+
init_remove();
|
|
459
|
+
init_link();
|
|
460
|
+
init_unlink();
|
|
461
|
+
init_sync();
|
|
462
|
+
});
|
|
3
463
|
|
|
4
464
|
// src/cli/commands/list.ts
|
|
465
|
+
init_core();
|
|
5
466
|
import * as prompts from "@clack/prompts";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
467
|
+
|
|
468
|
+
// src/cli/theme.ts
|
|
469
|
+
function rgb(r, g, b) {
|
|
470
|
+
return (value) => `\x1B[38;2;${r};${g};${b}m${value}\x1B[39m`;
|
|
471
|
+
}
|
|
472
|
+
var gray = (value) => rgb(value, value, value);
|
|
473
|
+
var defaultTheme = {
|
|
474
|
+
primary: rgb(114, 161, 136),
|
|
475
|
+
link: rgb(114, 140, 212),
|
|
476
|
+
header: gray(128),
|
|
477
|
+
command: rgb(114, 161, 136),
|
|
478
|
+
arg: rgb(161, 212, 212),
|
|
479
|
+
option: rgb(212, 212, 161),
|
|
480
|
+
type: gray(128),
|
|
481
|
+
description: (value) => value,
|
|
482
|
+
dim: gray(128),
|
|
483
|
+
error: rgb(212, 114, 114),
|
|
484
|
+
success: rgb(114, 212, 136)
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// src/cli/layout.ts
|
|
488
|
+
var ANSI_RE = /\x1b\[[0-9;]*m/g;
|
|
489
|
+
function clean(value) {
|
|
490
|
+
return value.replace(/[\t\n]/g, " ").replace(ANSI_RE, "");
|
|
491
|
+
}
|
|
492
|
+
function truncateMiddle(value, width) {
|
|
493
|
+
if (width <= 0)
|
|
494
|
+
return "";
|
|
495
|
+
if (value.length <= width)
|
|
496
|
+
return value;
|
|
497
|
+
if (width <= 3)
|
|
498
|
+
return value.slice(0, width);
|
|
499
|
+
const tail = Math.floor((width - 3) / 2);
|
|
500
|
+
const head = width - 3 - tail;
|
|
501
|
+
return `${value.slice(0, head)}...${value.slice(value.length - tail)}`;
|
|
502
|
+
}
|
|
503
|
+
function truncateStart(value, width) {
|
|
504
|
+
if (width <= 0)
|
|
505
|
+
return "";
|
|
506
|
+
if (value.length <= width)
|
|
507
|
+
return value;
|
|
508
|
+
if (width <= 3)
|
|
509
|
+
return "...".slice(0, width);
|
|
510
|
+
return `...${value.slice(value.length - (width - 3))}`;
|
|
511
|
+
}
|
|
512
|
+
function truncateEnd(value, width) {
|
|
513
|
+
if (width <= 0)
|
|
514
|
+
return "";
|
|
515
|
+
if (value.length <= width)
|
|
516
|
+
return value;
|
|
517
|
+
if (width <= 3)
|
|
518
|
+
return "...".slice(0, width);
|
|
519
|
+
return `${value.slice(0, width - 3)}...`;
|
|
520
|
+
}
|
|
521
|
+
function truncate(value, width, mode) {
|
|
522
|
+
if (mode === "start")
|
|
523
|
+
return truncateStart(value, width);
|
|
524
|
+
if (mode === "end")
|
|
525
|
+
return truncateEnd(value, width);
|
|
526
|
+
return truncateMiddle(value, width);
|
|
527
|
+
}
|
|
528
|
+
function fitWidths(natural, available, flex, noTruncate) {
|
|
529
|
+
const widths = [...natural];
|
|
530
|
+
const totalNatural = natural.reduce((sum, width) => sum + width, 0);
|
|
531
|
+
if (totalNatural <= available) {
|
|
532
|
+
return widths;
|
|
533
|
+
}
|
|
534
|
+
let fixedWidth = 0;
|
|
535
|
+
const dynamic = [];
|
|
536
|
+
for (let index = 0;index < widths.length; index++) {
|
|
537
|
+
if (noTruncate[index] || flex[index] === 0) {
|
|
538
|
+
fixedWidth += widths[index] ?? 0;
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
dynamic.push({ index, weight: flex[index] ?? 1 });
|
|
542
|
+
}
|
|
543
|
+
const remaining = Math.max(0, available - fixedWidth);
|
|
544
|
+
if (dynamic.length === 0) {
|
|
545
|
+
return widths;
|
|
546
|
+
}
|
|
547
|
+
const totalWeight = dynamic.reduce((sum, item) => sum + item.weight, 0);
|
|
548
|
+
let used = 0;
|
|
549
|
+
for (const item of dynamic) {
|
|
550
|
+
const share = Math.floor(remaining * item.weight / totalWeight);
|
|
551
|
+
const width = Math.max(1, share);
|
|
552
|
+
widths[item.index] = width;
|
|
553
|
+
used += width;
|
|
554
|
+
}
|
|
555
|
+
let extra = remaining - used;
|
|
556
|
+
let cursor = 0;
|
|
557
|
+
while (extra > 0) {
|
|
558
|
+
const item = dynamic[cursor % dynamic.length];
|
|
559
|
+
widths[item.index] = (widths[item.index] ?? 0) + 1;
|
|
560
|
+
extra--;
|
|
561
|
+
cursor++;
|
|
562
|
+
}
|
|
563
|
+
return widths;
|
|
564
|
+
}
|
|
565
|
+
function table(headers, columns, options = {}) {
|
|
566
|
+
if (headers.length === 0)
|
|
567
|
+
return;
|
|
568
|
+
const count = headers.length;
|
|
569
|
+
const gap = 2;
|
|
570
|
+
const rows = columns.reduce((max, column) => Math.max(max, column.length), 0);
|
|
571
|
+
const visibleRows = Math.min(rows, options.maxRows ?? rows);
|
|
572
|
+
const natural = [];
|
|
573
|
+
for (let col = 0;col < count; col++) {
|
|
574
|
+
const headerWidth = clean(headers[col] ?? "").length;
|
|
575
|
+
let width = headerWidth;
|
|
576
|
+
for (let row = 0;row < visibleRows; row++) {
|
|
577
|
+
const value = clean(columns[col]?.[row] ?? "");
|
|
578
|
+
width = Math.max(width, value.length);
|
|
579
|
+
}
|
|
580
|
+
natural[col] = width;
|
|
581
|
+
}
|
|
582
|
+
const maxWidth = options.maxWidth ?? (process.stdout.columns == null ? 120 : process.stdout.columns);
|
|
583
|
+
const available = Math.max(0, maxWidth - gap * (count - 1) - 1);
|
|
584
|
+
const widths = fitWidths(natural, available, options.flex ?? [], options.noTruncate ?? []);
|
|
585
|
+
const header = headers.map((title, col) => truncateMiddle(clean(title), widths[col] ?? 0).padEnd(widths[col] ?? 0)).join(" ");
|
|
586
|
+
process.stdout.write(`${defaultTheme.dim(header)}
|
|
587
|
+
`);
|
|
588
|
+
for (let row = 0;row < visibleRows; row++) {
|
|
589
|
+
const cells = [];
|
|
590
|
+
for (let col = 0;col < count; col++) {
|
|
591
|
+
const width = widths[col] ?? 0;
|
|
592
|
+
const source = clean(columns[col]?.[row] ?? "");
|
|
593
|
+
const mode = options.truncate?.[col] ?? "middle";
|
|
594
|
+
const value = options.noTruncate?.[col] ? source : truncate(source, width, mode);
|
|
595
|
+
const padded = width > 0 ? value.padEnd(width) : value;
|
|
596
|
+
const formatted = options.format?.[col]?.(padded, row, col) ?? padded;
|
|
597
|
+
cells.push(formatted);
|
|
598
|
+
}
|
|
599
|
+
process.stdout.write(`${cells.join(" ")}
|
|
600
|
+
`);
|
|
601
|
+
}
|
|
602
|
+
if (rows > visibleRows) {
|
|
603
|
+
process.stdout.write(`${defaultTheme.dim("(...truncated)")}
|
|
604
|
+
`);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function cols(rows, colorFns) {
|
|
608
|
+
if (rows.length === 0)
|
|
609
|
+
return;
|
|
610
|
+
const widths = rows[0].map((_, col) => {
|
|
611
|
+
let width = 0;
|
|
612
|
+
for (const row of rows) {
|
|
613
|
+
width = Math.max(width, clean(row[col] ?? "").length);
|
|
614
|
+
}
|
|
615
|
+
return width;
|
|
616
|
+
});
|
|
617
|
+
for (const row of rows) {
|
|
618
|
+
const line = row.map((value, col) => {
|
|
619
|
+
const padded = clean(value).padEnd(widths[col] ?? 0);
|
|
620
|
+
return colorFns?.[col]?.(padded) ?? padded;
|
|
621
|
+
}).join(" ");
|
|
622
|
+
process.stdout.write(`${line}
|
|
623
|
+
`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// src/cli/commands/list.ts
|
|
9
628
|
var command = {
|
|
10
629
|
description: "List all registered repos",
|
|
11
630
|
summary: "Show the registry",
|
|
@@ -13,8 +632,8 @@ var command = {
|
|
|
13
632
|
prompts.intro("dotllm list");
|
|
14
633
|
const global = Config.Global.read();
|
|
15
634
|
if (global.repos.length === 0) {
|
|
16
|
-
console.log(
|
|
17
|
-
console.log(
|
|
635
|
+
console.log(defaultTheme.dim("(no repos registered)"));
|
|
636
|
+
console.log(defaultTheme.dim("use `dotllm add <path>` to register one"));
|
|
18
637
|
return;
|
|
19
638
|
}
|
|
20
639
|
const local = Config.Local.read();
|
|
@@ -30,11 +649,11 @@ var command = {
|
|
|
30
649
|
noTruncate: [true, true, false, false, true],
|
|
31
650
|
truncate: ["end", "end", "start", "end", "end"],
|
|
32
651
|
format: [
|
|
33
|
-
(s) =>
|
|
652
|
+
(s) => defaultTheme.primary(s),
|
|
34
653
|
(s) => s,
|
|
35
|
-
(s) =>
|
|
654
|
+
(s) => defaultTheme.link(s),
|
|
36
655
|
(s) => s,
|
|
37
|
-
(s) => s.trim() === "yes" ?
|
|
656
|
+
(s) => s.trim() === "yes" ? defaultTheme.success(s) : s
|
|
38
657
|
]
|
|
39
658
|
});
|
|
40
659
|
}
|