@darkrymit/crunes-cli 0.5.10 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +5 -5
  2. package/dist/chunks/add-OWYVF3IE.js +22 -0
  3. package/dist/chunks/apply-OMEVXCHC.js +183 -0
  4. package/dist/chunks/args-32BVYW77.js +42 -0
  5. package/dist/chunks/benchmark-CLUBISCR.js +164 -0
  6. package/dist/chunks/browse-COH6IJEX.js +34 -0
  7. package/dist/chunks/check-BS6TZGRR.js +144 -0
  8. package/dist/chunks/chunk-2Q24YPGL.js +369 -0
  9. package/dist/chunks/chunk-3TM6B4E5.js +70 -0
  10. package/dist/chunks/chunk-67I2J474.js +153 -0
  11. package/dist/chunks/chunk-6XLT25GS.js +50 -0
  12. package/dist/chunks/chunk-BVY5LN7X.js +25091 -0
  13. package/dist/chunks/chunk-CGZL5SSH.js +926 -0
  14. package/dist/chunks/chunk-DMMC4X27.js +1836 -0
  15. package/dist/chunks/chunk-G3U4V32O.js +46 -0
  16. package/dist/chunks/chunk-GHQOK4L7.js +59 -0
  17. package/dist/chunks/chunk-H3BVJCIL.js +105 -0
  18. package/dist/chunks/chunk-HMU2J25D.js +63 -0
  19. package/dist/chunks/chunk-HOH7WZX4.js +95 -0
  20. package/dist/chunks/chunk-L72BG6DS.js +225 -0
  21. package/dist/chunks/chunk-NXSDVVTW.js +181 -0
  22. package/dist/chunks/chunk-QLDB3FO2.js +73059 -0
  23. package/dist/chunks/chunk-QMWGQXEZ.js +26 -0
  24. package/dist/chunks/chunk-TPK5AGRA.js +54 -0
  25. package/dist/chunks/chunk-UGN3FFEF.js +8379 -0
  26. package/dist/chunks/chunk-WCODTMDN.js +508 -0
  27. package/dist/chunks/chunk-XIXND2M4.js +296 -0
  28. package/dist/chunks/chunk-XXUNHQIB.js +129 -0
  29. package/dist/chunks/chunk-ZXIP4Z5V.js +281 -0
  30. package/dist/chunks/clear-Y5POLIMF.js +32 -0
  31. package/dist/chunks/completions-2MSEWWTG.js +232 -0
  32. package/dist/chunks/create-5FXQYCGM.js +165 -0
  33. package/dist/chunks/create-I6BNYZ5Q.js +247 -0
  34. package/dist/chunks/create-O3HMODSL.js +130 -0
  35. package/dist/chunks/delete-7CQFYIXS.js +40 -0
  36. package/dist/chunks/delete-UB5SXO5I.js +40 -0
  37. package/dist/chunks/disable-FCBW7WVG.js +47 -0
  38. package/dist/chunks/doctor-DS57HDLJ.js +53 -0
  39. package/dist/chunks/enable-IXRVUXJM.js +47 -0
  40. package/dist/chunks/esm-7MEWZCHY.js +5162 -0
  41. package/dist/chunks/globals-YCJ2DGWC.js +60 -0
  42. package/dist/chunks/init-WGKQVAZE.js +59 -0
  43. package/dist/chunks/install-BCTBOPBS.js +57 -0
  44. package/dist/chunks/intro-2UDWF6D4.js +1482 -0
  45. package/dist/chunks/kill-LWRXZVM5.js +37 -0
  46. package/dist/chunks/list-5DVVP7HX.js +50 -0
  47. package/dist/chunks/list-6WL5LGIZ.js +80 -0
  48. package/dist/chunks/list-NGOCMJXE.js +104 -0
  49. package/dist/chunks/list-TTKLNJKI.js +28 -0
  50. package/dist/chunks/list-WUAOSO3M.js +110 -0
  51. package/dist/chunks/list-YPI7YDKK.js +80 -0
  52. package/dist/chunks/list-ZBYPMUID.js +23 -0
  53. package/dist/chunks/manifest-7RVNKBOH.js +9 -0
  54. package/dist/chunks/output-RJ6JSNY7.js +12 -0
  55. package/dist/chunks/promise-DUSIQMA2.js +19400 -0
  56. package/dist/chunks/query-NY4SCO77.js +41 -0
  57. package/dist/chunks/registry-W5XFI5T6.js +16 -0
  58. package/dist/chunks/remove-WEAZFZCO.js +22 -0
  59. package/dist/chunks/run-I6TZX347.js +23 -0
  60. package/dist/chunks/run-MVIZQVJ6.js +36 -0
  61. package/dist/chunks/rune-TAX26NH2.js +76 -0
  62. package/dist/chunks/search-XENXL3GC.js +25 -0
  63. package/dist/chunks/uninstall-MX5PLGDI.js +49 -0
  64. package/dist/chunks/unset-KQOZYVTE.js +28 -0
  65. package/dist/chunks/update-7XDTVFZ3.js +39 -0
  66. package/dist/chunks/update-IEE54GPY.js +79 -0
  67. package/dist/chunks/utils-PO3ZK53L.js +50 -0
  68. package/dist/chunks/version-DIEA5FVV.js +145 -0
  69. package/dist/cli.js +3360 -125840
  70. package/package.json +23 -15
@@ -0,0 +1,181 @@
1
+ import {
2
+ storageKey
3
+ } from "./chunk-QMWGQXEZ.js";
4
+ import {
5
+ getCacheJsonPath,
6
+ getCachesBasePath
7
+ } from "./chunk-HMU2J25D.js";
8
+ import {
9
+ init_require_shim
10
+ } from "./chunk-TPK5AGRA.js";
11
+
12
+ // src/cache/index.js
13
+ init_require_shim();
14
+ import { readFile, readdir, writeFile, mkdir, rm } from "node:fs/promises";
15
+ import { dirname } from "node:path";
16
+ import path from "node:path";
17
+ function getCachePluginDir(pluginId) {
18
+ return path.join(getCachesBasePath(), "plugins", pluginId);
19
+ }
20
+ function getCacheProjectDir(key) {
21
+ return path.join(getCachesBasePath(), "projects", key);
22
+ }
23
+ function getCacheProjectPluginDir(key, pluginId) {
24
+ return path.join(getCachesBasePath(), "project-plugins", key, pluginId);
25
+ }
26
+ async function loadCacheBuckets() {
27
+ try {
28
+ return JSON.parse(await readFile(getCacheJsonPath(), "utf8"));
29
+ } catch {
30
+ return { format: "1", buckets: {} };
31
+ }
32
+ }
33
+ async function upsertCacheBucket(resolvedPath, { scope, projectId, pluginId, location, name }) {
34
+ const data = await loadCacheBuckets();
35
+ const key = storageKey(scope, { projectId, pluginId, name });
36
+ const effectiveProjectId = projectId ?? null;
37
+ data.buckets[key] = {
38
+ path: resolvedPath,
39
+ scope,
40
+ projectKey: effectiveProjectId,
41
+ pluginId: pluginId ?? null,
42
+ location,
43
+ name,
44
+ firstSeenAt: data.buckets[key]?.firstSeenAt ?? (/* @__PURE__ */ new Date()).toISOString()
45
+ };
46
+ const p = getCacheJsonPath();
47
+ await mkdir(dirname(p), { recursive: true });
48
+ await writeFile(p, JSON.stringify(data, null, 2), "utf8");
49
+ }
50
+ function scopedBuckets(data, projectKey) {
51
+ if (projectKey === void 0) return data.buckets;
52
+ return Object.fromEntries(
53
+ Object.entries(data.buckets).filter(
54
+ ([, e]) => (e.scope === "global-project" || e.scope === "global-project-plugin") && e.projectKey === projectKey
55
+ )
56
+ );
57
+ }
58
+ async function listCacheBuckets(projectKey = void 0) {
59
+ const data = await loadCacheBuckets();
60
+ const entries = Object.entries(data.buckets).map(([key, entry]) => ({ key, ...entry }));
61
+ if (projectKey === void 0) return entries;
62
+ return entries.filter(
63
+ (e) => (e.scope === "global-project" || e.scope === "global-project-plugin") && e.projectKey === projectKey
64
+ );
65
+ }
66
+ async function listLocalCacheBuckets(projectDir) {
67
+ let projectId;
68
+ try {
69
+ const raw = await readFile(path.join(projectDir, ".crunes", "project.local.json"), "utf8");
70
+ projectId = JSON.parse(raw).id;
71
+ } catch {
72
+ return [];
73
+ }
74
+ const results = [];
75
+ const localCachesDir = path.join(projectDir, ".crunes", "caches");
76
+ async function scanScope(scopeDir, scope, pluginId = null) {
77
+ let entries;
78
+ try {
79
+ entries = await readdir(scopeDir, { withFileTypes: true });
80
+ } catch {
81
+ return;
82
+ }
83
+ for (const entry of entries) {
84
+ if (!entry.isDirectory()) continue;
85
+ const name = entry.name;
86
+ const key = storageKey(scope, { projectId, pluginId, name });
87
+ const location = pluginId ? `@local-project-plugin-cache/${pluginId}/${name}` : `@local-project-cache/${name}`;
88
+ let firstSeenAt;
89
+ try {
90
+ const stat = await readFile(path.join(scopeDir, name, ".firstSeen"), "utf8");
91
+ firstSeenAt = stat.trim();
92
+ } catch {
93
+ firstSeenAt = null;
94
+ }
95
+ results.push({ key, scope, projectKey: projectId, pluginId, location, name, firstSeenAt, path: path.join(scopeDir, name) });
96
+ }
97
+ }
98
+ await scanScope(path.join(localCachesDir, "project"), "local-project");
99
+ const pluginsDir = path.join(localCachesDir, "project-plugins");
100
+ let pluginEntries;
101
+ try {
102
+ pluginEntries = await readdir(pluginsDir, { withFileTypes: true });
103
+ } catch {
104
+ pluginEntries = [];
105
+ }
106
+ for (const pluginEntry of pluginEntries) {
107
+ if (!pluginEntry.isDirectory()) continue;
108
+ await scanScope(path.join(pluginsDir, pluginEntry.name), "local-project-plugin", pluginEntry.name);
109
+ }
110
+ return results;
111
+ }
112
+ function resolveKey(id, buckets) {
113
+ if (id in buckets) return id;
114
+ const matches = Object.keys(buckets).filter((k) => k.startsWith(id));
115
+ if (matches.length === 1) return matches[0];
116
+ if (matches.length === 0) throw new Error(`No cache bucket matching "${id}".`);
117
+ throw new Error(`Ambiguous id "${id}" \u2014 matches: ${matches.join(", ")}.`);
118
+ }
119
+ async function clearCacheBucket(id, projectKey = void 0) {
120
+ const data = await loadCacheBuckets();
121
+ const key = resolveKey(id, scopedBuckets(data, projectKey));
122
+ const { path: bucketPath, name } = data.buckets[key];
123
+ let removed = 0;
124
+ try {
125
+ const files = await readdir(bucketPath);
126
+ const now = Date.now();
127
+ const results = await Promise.all(
128
+ files.filter((f) => f.endsWith(".json")).map(async (f) => {
129
+ const fp = path.join(bucketPath, f);
130
+ try {
131
+ const entry = JSON.parse(await readFile(fp, "utf8"));
132
+ if (entry.expiresAt !== null && now > entry.expiresAt) {
133
+ await rm(fp);
134
+ return true;
135
+ }
136
+ } catch {
137
+ }
138
+ return false;
139
+ })
140
+ );
141
+ removed = results.filter(Boolean).length;
142
+ } catch (e) {
143
+ if (e.code !== "ENOENT") throw e;
144
+ }
145
+ return { removed, name };
146
+ }
147
+ async function deleteCacheKey(id, keyName, projectKey = void 0) {
148
+ const data = await loadCacheBuckets();
149
+ const key = resolveKey(id, scopedBuckets(data, projectKey));
150
+ const { path: bucketPath, name } = data.buckets[key];
151
+ try {
152
+ await rm(path.join(bucketPath, `${keyName}.json`));
153
+ } catch (e) {
154
+ if (e.code === "ENOENT") throw new Error(`Key "${keyName}" not found in cache bucket "${name}".`);
155
+ throw e;
156
+ }
157
+ return { name };
158
+ }
159
+ async function deleteCacheBucket(id, projectKey = void 0) {
160
+ const data = await loadCacheBuckets();
161
+ const key = resolveKey(id, scopedBuckets(data, projectKey));
162
+ const { path: bucketPath, name } = data.buckets[key];
163
+ await rm(bucketPath, { recursive: true, force: true });
164
+ delete data.buckets[key];
165
+ const p = getCacheJsonPath();
166
+ await mkdir(dirname(p), { recursive: true });
167
+ await writeFile(p, JSON.stringify(data, null, 2), "utf8");
168
+ return { name };
169
+ }
170
+
171
+ export {
172
+ getCachePluginDir,
173
+ getCacheProjectDir,
174
+ getCacheProjectPluginDir,
175
+ upsertCacheBucket,
176
+ listCacheBuckets,
177
+ listLocalCacheBuckets,
178
+ clearCacheBucket,
179
+ deleteCacheKey,
180
+ deleteCacheBucket
181
+ };