omp-config-crypt 0.5.5 → 0.6.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/bin/omp-sync.js +41 -0
- package/index.js +63 -0
- package/package.json +1 -1
- package/src/maintenance.js +183 -0
package/bin/omp-sync.js
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
getRoles,
|
|
26
26
|
setRole,
|
|
27
27
|
VALID_ROLES,
|
|
28
|
+
runMaintenance,
|
|
28
29
|
} from "../index.js";
|
|
29
30
|
|
|
30
31
|
function printHelp() {
|
|
@@ -41,6 +42,7 @@ Commands:
|
|
|
41
42
|
pull <gist:id|url> Download and restore configs from Gist or HTTP URL
|
|
42
43
|
rollback Revert the most recent config restore from its backup
|
|
43
44
|
rehydrate Rehydrate and repair locked/linked plugins in ~/.omp/plugins
|
|
45
|
+
maint / gc [--force] Run automatic storage maintenance, WAL checkpoint & GC
|
|
44
46
|
provider add <name> Auto-probe and add an LLM provider (public or private)
|
|
45
47
|
provider ls / list List configured providers, models and active role bindings
|
|
46
48
|
provider rm <name> Remove a provider from public or private store
|
|
@@ -63,6 +65,7 @@ Options:
|
|
|
63
65
|
--private Save as private (local-only, unsynced, non-overwritten) [default]
|
|
64
66
|
--public Save as public (synced across machines via models.yml)
|
|
65
67
|
-y, --yes Non-interactive mode (use defaults without prompting)
|
|
68
|
+
-f, --force Force operations (e.g. bypass maintenance debounce)
|
|
66
69
|
|
|
67
70
|
Environment Variables:
|
|
68
71
|
OMP_CONFIG_PASS Passphrase for non-interactive automation
|
|
@@ -91,6 +94,7 @@ function parseCliArgs(argv) {
|
|
|
91
94
|
role: null,
|
|
92
95
|
isPrivate: null,
|
|
93
96
|
nonInteractive: false,
|
|
97
|
+
force: false,
|
|
94
98
|
positional: [],
|
|
95
99
|
};
|
|
96
100
|
|
|
@@ -127,6 +131,8 @@ function parseCliArgs(argv) {
|
|
|
127
131
|
options.isPrivate = false;
|
|
128
132
|
} else if (a === "-y" || a === "--yes" || a === "--non-interactive") {
|
|
129
133
|
options.nonInteractive = true;
|
|
134
|
+
} else if (a === "-f" || a === "--force") {
|
|
135
|
+
options.force = true;
|
|
130
136
|
} else if (a.startsWith("--pass=")) {
|
|
131
137
|
options.pass = a.slice(7);
|
|
132
138
|
} else if (a.startsWith("--token=")) {
|
|
@@ -226,6 +232,9 @@ async function main() {
|
|
|
226
232
|
`[rehydrate] Plugins processed: ${res.rehydration.rehydrated} rehydrated (installed: ${res.rehydration.npmInstalled.length}, links: ${res.rehydration.linksRepaired.length}).`
|
|
227
233
|
);
|
|
228
234
|
}
|
|
235
|
+
if (res.purged && res.purged.length > 0) {
|
|
236
|
+
console.log(`[cleanup] Automatically purged ${res.purged.length} obsolete file(s) (e.g. legacy agy.js).`);
|
|
237
|
+
}
|
|
229
238
|
}
|
|
230
239
|
break;
|
|
231
240
|
}
|
|
@@ -279,6 +288,9 @@ async function main() {
|
|
|
279
288
|
`[rehydrate] Plugins processed: ${res.rehydration.rehydrated} rehydrated (installed: ${res.rehydration.npmInstalled.length}, links: ${res.rehydration.linksRepaired.length}).`
|
|
280
289
|
);
|
|
281
290
|
}
|
|
291
|
+
if (res.purged && res.purged.length > 0) {
|
|
292
|
+
console.log(`[cleanup] Automatically purged ${res.purged.length} obsolete file(s) (e.g. legacy agy.js).`);
|
|
293
|
+
}
|
|
282
294
|
}
|
|
283
295
|
break;
|
|
284
296
|
}
|
|
@@ -301,6 +313,35 @@ async function main() {
|
|
|
301
313
|
}
|
|
302
314
|
break;
|
|
303
315
|
}
|
|
316
|
+
case "maint":
|
|
317
|
+
case "gc": {
|
|
318
|
+
const force = Boolean(options.force || options.positional?.includes("--force"));
|
|
319
|
+
console.log(`[maint] Running storage maintenance and garbage collection on ${root}...`);
|
|
320
|
+
const res = await runMaintenance({
|
|
321
|
+
agentDir: root,
|
|
322
|
+
force,
|
|
323
|
+
dryRun: options.dryRun,
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
if (res.skipped) {
|
|
327
|
+
console.log(
|
|
328
|
+
`[maint] Storage maintenance skipped (already executed recently). Next run in ~${res.nextRunInMinutes}m. Use --force to override.`
|
|
329
|
+
);
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
console.log(`[maint] ✓ Corrupt crash files cleaned: ${res.corruptCleaned?.length || 0}`);
|
|
334
|
+
console.log(`[maint] ✓ Obsolete legacy files purged: ${res.obsoletePurged?.length || 0}`);
|
|
335
|
+
console.log(`[maint] ✓ Old backup snapshots pruned: ${res.backupsPruned?.length || 0}`);
|
|
336
|
+
if (res.gc) {
|
|
337
|
+
if (res.gc.success) {
|
|
338
|
+
console.log(`[maint] ✓ Native GC & WAL checkpoint:\n ${res.gc.output.split("\n").join("\n ")}`);
|
|
339
|
+
} else {
|
|
340
|
+
console.warn(`[maint] ⚠ Native GC warning: ${res.gc.error}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
304
345
|
|
|
305
346
|
case "provider": {
|
|
306
347
|
const sub = (options.target || "list").toLowerCase();
|
package/index.js
CHANGED
|
@@ -40,6 +40,14 @@ import {
|
|
|
40
40
|
formatYamlModels,
|
|
41
41
|
} from "./src/provider-store.js";
|
|
42
42
|
import { getRoles, setRole, VALID_ROLES } from "./src/role-manager.js";
|
|
43
|
+
import {
|
|
44
|
+
runMaintenance,
|
|
45
|
+
cleanCorruptFiles,
|
|
46
|
+
pruneOldBackups,
|
|
47
|
+
cleanObsoleteFiles,
|
|
48
|
+
runOmpGc,
|
|
49
|
+
scheduleAutoMaintenance,
|
|
50
|
+
} from "./src/maintenance.js";
|
|
43
51
|
|
|
44
52
|
export {
|
|
45
53
|
probeProvider,
|
|
@@ -57,6 +65,12 @@ export {
|
|
|
57
65
|
getRoles,
|
|
58
66
|
setRole,
|
|
59
67
|
VALID_ROLES,
|
|
68
|
+
runMaintenance,
|
|
69
|
+
cleanCorruptFiles,
|
|
70
|
+
pruneOldBackups,
|
|
71
|
+
cleanObsoleteFiles,
|
|
72
|
+
runOmpGc,
|
|
73
|
+
scheduleAutoMaintenance,
|
|
60
74
|
};
|
|
61
75
|
|
|
62
76
|
const MAGIC = Buffer.from("OMPCFG1\0", "latin1");
|
|
@@ -395,10 +409,28 @@ export function restoreArchive(blob, pass, root = configRoot(), options = {}) {
|
|
|
395
409
|
}
|
|
396
410
|
}
|
|
397
411
|
|
|
412
|
+
const purged = [];
|
|
413
|
+
if (!dryRun) {
|
|
414
|
+
const obsoleteCandidates = [
|
|
415
|
+
path.join(ompHome(root), "extensions", "agy.js"),
|
|
416
|
+
path.join(ompHome(root), "extensions", "local-models.js"),
|
|
417
|
+
path.join(root, "models.local.json"),
|
|
418
|
+
];
|
|
419
|
+
for (const p of obsoleteCandidates) {
|
|
420
|
+
if (fs.existsSync(p)) {
|
|
421
|
+
try {
|
|
422
|
+
fs.rmSync(p, { force: true });
|
|
423
|
+
purged.push(p);
|
|
424
|
+
} catch {}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
398
429
|
return {
|
|
399
430
|
files: restored,
|
|
400
431
|
dryRun,
|
|
401
432
|
actions,
|
|
433
|
+
purged,
|
|
402
434
|
backupDir: !dryRun && fs.existsSync(backupDir) ? backupDir : null,
|
|
403
435
|
rehydration,
|
|
404
436
|
};
|
|
@@ -907,4 +939,35 @@ export default function (pi) {
|
|
|
907
939
|
}
|
|
908
940
|
},
|
|
909
941
|
});
|
|
942
|
+
|
|
943
|
+
// Register maintenance command (/maint or /gc)
|
|
944
|
+
pi.registerCommand("maint", {
|
|
945
|
+
description: "Run storage maintenance, WAL checkpoint, and garbage collection (/maint [--force])",
|
|
946
|
+
handler: async (args, ctx) => {
|
|
947
|
+
const force = (args || "").includes("--force");
|
|
948
|
+
ctx.ui.notify("Running storage maintenance & garbage collection...", "info");
|
|
949
|
+
try {
|
|
950
|
+
const res = await runMaintenance({
|
|
951
|
+
agentDir: configRoot(),
|
|
952
|
+
force: true, // User manual trigger always forces execution
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
const parts = [];
|
|
956
|
+
if (res.corruptCleaned?.length > 0) parts.push(`cleaned ${res.corruptCleaned.length} corrupt file(s)`);
|
|
957
|
+
if (res.backupsPruned?.length > 0) parts.push(`pruned ${res.backupsPruned.length} backup snapshot(s)`);
|
|
958
|
+
if (res.obsoletePurged?.length > 0) parts.push(`purged ${res.obsoletePurged.length} obsolete file(s)`);
|
|
959
|
+
if (res.gc?.success) parts.push("WAL checkpointed & GC complete");
|
|
960
|
+
|
|
961
|
+
const msg = parts.length > 0 ? `Maintenance complete: ${parts.join(", ")}.` : "Storage is already optimal. No cleanup needed.";
|
|
962
|
+
ctx.ui.notify(msg, "info");
|
|
963
|
+
} catch (err) {
|
|
964
|
+
ctx.ui.notify(`Maintenance error: ${err.message || err}`, "error");
|
|
965
|
+
}
|
|
966
|
+
},
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
// Launch non-blocking background auto-maintenance (debounced every 24h)
|
|
970
|
+
try {
|
|
971
|
+
scheduleAutoMaintenance(configRoot(), 4000);
|
|
972
|
+
} catch {}
|
|
910
973
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import { exec } from "node:child_process";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
|
|
7
|
+
const execAsync = promisify(exec);
|
|
8
|
+
|
|
9
|
+
export function getAgentDir(root) {
|
|
10
|
+
return root || process.env.OMP_CFG_ROOT || path.join(os.homedir(), ".omp", "agent");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getOmpHome(agentDir) {
|
|
14
|
+
const norm = path.resolve(agentDir);
|
|
15
|
+
return path.basename(norm) === "agent" ? path.dirname(norm) : norm;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Remove corrupt database files (*.corrupt-*) left over from crashes.
|
|
20
|
+
*/
|
|
21
|
+
export function cleanCorruptFiles(agentDir) {
|
|
22
|
+
const cleaned = [];
|
|
23
|
+
if (!fs.existsSync(agentDir)) return cleaned;
|
|
24
|
+
|
|
25
|
+
const entries = fs.readdirSync(agentDir, { withFileTypes: true });
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (entry.name.includes(".corrupt-")) {
|
|
28
|
+
const fullPath = path.join(agentDir, entry.name);
|
|
29
|
+
try {
|
|
30
|
+
const stat = fs.statSync(fullPath);
|
|
31
|
+
fs.rmSync(fullPath, { recursive: true, force: true });
|
|
32
|
+
cleaned.push({ path: fullPath, bytes: stat.size });
|
|
33
|
+
} catch {}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return cleaned;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Prune historical .import-backup-* directories, keeping only the most recent N.
|
|
41
|
+
*/
|
|
42
|
+
export function pruneOldBackups(agentDir, keepCount = 3) {
|
|
43
|
+
const pruned = [];
|
|
44
|
+
if (!fs.existsSync(agentDir)) return pruned;
|
|
45
|
+
|
|
46
|
+
const entries = fs.readdirSync(agentDir, { withFileTypes: true });
|
|
47
|
+
const backups = entries
|
|
48
|
+
.filter((e) => e.isDirectory() && e.name.startsWith(".import-backup-"))
|
|
49
|
+
.map((e) => e.name)
|
|
50
|
+
.sort()
|
|
51
|
+
.reverse();
|
|
52
|
+
|
|
53
|
+
if (backups.length > keepCount) {
|
|
54
|
+
const toRemove = backups.slice(keepCount);
|
|
55
|
+
for (const name of toRemove) {
|
|
56
|
+
const fullPath = path.join(agentDir, name);
|
|
57
|
+
try {
|
|
58
|
+
fs.rmSync(fullPath, { recursive: true, force: true });
|
|
59
|
+
pruned.push(fullPath);
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return pruned;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Remove obsolete legacy transition files.
|
|
68
|
+
*/
|
|
69
|
+
export function cleanObsoleteFiles(agentDir) {
|
|
70
|
+
const ompDir = getOmpHome(agentDir);
|
|
71
|
+
const targets = [
|
|
72
|
+
path.join(agentDir, "models.local.json"),
|
|
73
|
+
path.join(ompDir, "extensions", "local-models.js"),
|
|
74
|
+
path.join(ompDir, "extensions", "agy.js"),
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const purged = [];
|
|
78
|
+
for (const p of targets) {
|
|
79
|
+
if (fs.existsSync(p)) {
|
|
80
|
+
try {
|
|
81
|
+
fs.rmSync(p, { force: true });
|
|
82
|
+
purged.push(p);
|
|
83
|
+
} catch {}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return purged;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Execute OMP native garbage collection and checkpoint WAL files.
|
|
91
|
+
*/
|
|
92
|
+
export async function runOmpGc({
|
|
93
|
+
archiveDays = 14,
|
|
94
|
+
retainNewest = 20,
|
|
95
|
+
agentDir = null,
|
|
96
|
+
} = {}) {
|
|
97
|
+
const dirFlag = agentDir ? `--agent-dir="${agentDir}"` : "";
|
|
98
|
+
const cmd = `omp gc --apply --blobs --stale --wal --archive --cold-archive-after-days=${archiveDays} --retain-newest-global=${retainNewest} ${dirFlag}`.trim();
|
|
99
|
+
try {
|
|
100
|
+
const { stdout, stderr } = await execAsync(cmd);
|
|
101
|
+
return { success: true, output: (stdout + "\n" + stderr).trim() };
|
|
102
|
+
} catch (err) {
|
|
103
|
+
return { success: false, error: err.message, output: (err.stdout || "") + (err.stderr || "") };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Full automatic maintenance cycle with debouncing.
|
|
109
|
+
*/
|
|
110
|
+
export async function runMaintenance({
|
|
111
|
+
agentDir = getAgentDir(),
|
|
112
|
+
dryRun = false,
|
|
113
|
+
force = false,
|
|
114
|
+
intervalHours = 24,
|
|
115
|
+
archiveDays = 14,
|
|
116
|
+
keepBackups = 3,
|
|
117
|
+
skipGc = false,
|
|
118
|
+
} = {}) {
|
|
119
|
+
const stampFile = path.join(agentDir, ".last-maintenance.json");
|
|
120
|
+
const now = Date.now();
|
|
121
|
+
const minIntervalMs = intervalHours * 3600 * 1000;
|
|
122
|
+
|
|
123
|
+
if (!force && fs.existsSync(stampFile)) {
|
|
124
|
+
try {
|
|
125
|
+
const stamp = JSON.parse(fs.readFileSync(stampFile, "utf8"));
|
|
126
|
+
if (stamp.timestamp && now - stamp.timestamp < minIntervalMs) {
|
|
127
|
+
return {
|
|
128
|
+
skipped: true,
|
|
129
|
+
reason: "debounced",
|
|
130
|
+
lastRun: stamp.lastRun,
|
|
131
|
+
nextRunInMinutes: Math.round((minIntervalMs - (now - stamp.timestamp)) / 60000),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
} catch {}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const result = {
|
|
138
|
+
skipped: false,
|
|
139
|
+
timestamp: now,
|
|
140
|
+
lastRun: new Date(now).toISOString(),
|
|
141
|
+
corruptCleaned: [],
|
|
142
|
+
backupsPruned: [],
|
|
143
|
+
obsoletePurged: [],
|
|
144
|
+
gc: null,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
if (dryRun) {
|
|
148
|
+
result.dryRun = true;
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 1. Clean corrupt crash dumps
|
|
153
|
+
result.corruptCleaned = cleanCorruptFiles(agentDir);
|
|
154
|
+
|
|
155
|
+
// 2. Prune old import backup snapshots
|
|
156
|
+
result.backupsPruned = pruneOldBackups(agentDir, keepBackups);
|
|
157
|
+
|
|
158
|
+
// 3. Purge obsolete files
|
|
159
|
+
result.obsoletePurged = cleanObsoleteFiles(agentDir);
|
|
160
|
+
|
|
161
|
+
// 4. Run native GC
|
|
162
|
+
if (!skipGc) {
|
|
163
|
+
result.gc = await runOmpGc({ archiveDays, agentDir });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 5. Update stamp
|
|
167
|
+
try {
|
|
168
|
+
fs.mkdirSync(agentDir, { recursive: true });
|
|
169
|
+
fs.writeFileSync(stampFile, JSON.stringify(result, null, 2), "utf8");
|
|
170
|
+
} catch {}
|
|
171
|
+
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Start non-blocking background auto-maintenance.
|
|
177
|
+
* Runs in background after delayMs without blocking startup.
|
|
178
|
+
*/
|
|
179
|
+
export function scheduleAutoMaintenance(agentDir = getAgentDir(), delayMs = 4000) {
|
|
180
|
+
setTimeout(() => {
|
|
181
|
+
runMaintenance({ agentDir }).catch(() => {});
|
|
182
|
+
}, delayMs).unref?.();
|
|
183
|
+
}
|