@spader/dotllm 1.3.2 → 1.3.4

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.
@@ -1,125 +1,21 @@
1
1
  // @bun
2
- var __require = import.meta.require;
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
+ };
3
13
 
4
14
  // src/core/config.ts
5
15
  import fs from "fs";
6
16
  import os from "os";
7
17
  import path from "path";
8
18
  import { z } from "zod";
9
- var LOCAL_DIR = ".llm";
10
- var LOCAL_FILE = path.join(LOCAL_DIR, "dotllm.json");
11
- var REF_DIR = path.join(LOCAL_DIR, "reference");
12
- function home() {
13
- if (process.platform === "win32") {
14
- const appData = process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
15
- return path.join(appData, "dotllm");
16
- }
17
- return path.join(process.env.HOME ?? os.homedir(), ".local", "share", "dotllm");
18
- }
19
- var RepoEntry = z.object({
20
- kind: z.enum(["url", "file"]),
21
- name: z.string(),
22
- uri: z.string(),
23
- description: z.string()
24
- });
25
- var GlobalShape = z.object({
26
- repos: z.array(RepoEntry)
27
- });
28
- var LocalShape = z.object({
29
- refs: z.record(z.string(), RepoEntry)
30
- });
31
- var Config;
32
- ((Config) => {
33
- function storeDir() {
34
- return path.join(home(), "store");
35
- }
36
- Config.storeDir = storeDir;
37
- function refDir() {
38
- return REF_DIR;
39
- }
40
- Config.refDir = refDir;
41
- let Global;
42
- ((Global) => {
43
- function read() {
44
- const raw = readJson(path.join(home(), "dotllm.json"));
45
- if (!raw)
46
- return { repos: [] };
47
- const result = GlobalShape.safeParse(raw);
48
- if (!result.success)
49
- return { repos: [] };
50
- return result.data;
51
- }
52
- Global.read = read;
53
- function write(config) {
54
- const dir = home();
55
- fs.mkdirSync(dir, { recursive: true });
56
- fs.writeFileSync(path.join(dir, "dotllm.json"), JSON.stringify(config, null, 2) + `
57
- `);
58
- }
59
- Global.write = write;
60
- function find(config, name) {
61
- const lower = name.toLowerCase();
62
- return config.repos.find((r) => r.name.toLowerCase() === lower);
63
- }
64
- Global.find = find;
65
- function add(config, entry) {
66
- const lower = entry.name.toLowerCase();
67
- const filtered = config.repos.filter((r) => r.name.toLowerCase() !== lower);
68
- return { repos: [...filtered, entry] };
69
- }
70
- Global.add = add;
71
- function remove(config, name) {
72
- const lower = name.toLowerCase();
73
- return { repos: config.repos.filter((r) => r.name.toLowerCase() !== lower) };
74
- }
75
- Global.remove = remove;
76
- })(Global = Config.Global ||= {});
77
- let Local;
78
- ((Local) => {
79
- function read() {
80
- const raw = readJson(LOCAL_FILE);
81
- if (!raw)
82
- return { refs: {} };
83
- const result = LocalShape.safeParse(raw);
84
- if (!result.success)
85
- return { refs: {} };
86
- return result.data;
87
- }
88
- Local.read = read;
89
- function write(config) {
90
- fs.mkdirSync(LOCAL_DIR, { recursive: true });
91
- fs.writeFileSync(LOCAL_FILE, JSON.stringify(config, null, 2) + `
92
- `);
93
- }
94
- Local.write = write;
95
- function find(config, name) {
96
- const lower = name.toLowerCase();
97
- for (const [key, value] of Object.entries(config.refs)) {
98
- if (key.toLowerCase() === lower)
99
- return value;
100
- }
101
- return;
102
- }
103
- Local.find = find;
104
- function has(config, name) {
105
- return find(config, name) !== undefined;
106
- }
107
- Local.has = has;
108
- function add(config, repo) {
109
- const lower = repo.name.toLowerCase();
110
- const refs = Object.fromEntries(Object.entries(config.refs).filter(([key]) => key.toLowerCase() !== lower));
111
- refs[repo.name] = repo;
112
- return { refs };
113
- }
114
- Local.add = add;
115
- function remove(config, name) {
116
- const lower = name.toLowerCase();
117
- const refs = Object.fromEntries(Object.entries(config.refs).filter(([key]) => key.toLowerCase() !== lower));
118
- return { refs };
119
- }
120
- Local.remove = remove;
121
- })(Local = Config.Local ||= {});
122
- })(Config ||= {});
123
19
  function readJson(filepath) {
124
20
  if (!fs.existsSync(filepath))
125
21
  return null;
@@ -130,6 +26,134 @@ function readJson(filepath) {
130
26
  return null;
131
27
  }
132
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
+ init_config();
156
+
133
157
  export {
134
158
  Config
135
159
  };