omp-config-crypt 0.6.0 → 0.6.2
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 +46 -2
- package/index.js +6 -0
- package/package.json +1 -1
- package/src/maintenance.js +59 -1
package/bin/omp-sync.js
CHANGED
|
@@ -26,6 +26,9 @@ import {
|
|
|
26
26
|
setRole,
|
|
27
27
|
VALID_ROLES,
|
|
28
28
|
runMaintenance,
|
|
29
|
+
getCronStatus,
|
|
30
|
+
installCron,
|
|
31
|
+
removeCron,
|
|
29
32
|
} from "../index.js";
|
|
30
33
|
|
|
31
34
|
function printHelp() {
|
|
@@ -43,6 +46,7 @@ Commands:
|
|
|
43
46
|
rollback Revert the most recent config restore from its backup
|
|
44
47
|
rehydrate Rehydrate and repair locked/linked plugins in ~/.omp/plugins
|
|
45
48
|
maint / gc [--force] Run automatic storage maintenance, WAL checkpoint & GC
|
|
49
|
+
cron [install|status|rm] Manage OS-level scheduled crontab maintenance job
|
|
46
50
|
provider add <name> Auto-probe and add an LLM provider (public or private)
|
|
47
51
|
provider ls / list List configured providers, models and active role bindings
|
|
48
52
|
provider rm <name> Remove a provider from public or private store
|
|
@@ -66,6 +70,7 @@ Options:
|
|
|
66
70
|
--public Save as public (synced across machines via models.yml)
|
|
67
71
|
-y, --yes Non-interactive mode (use defaults without prompting)
|
|
68
72
|
-f, --force Force operations (e.g. bypass maintenance debounce)
|
|
73
|
+
--profile <name> Target specific profile scene (e.g. dev, ops)
|
|
69
74
|
|
|
70
75
|
Environment Variables:
|
|
71
76
|
OMP_CONFIG_PASS Passphrase for non-interactive automation
|
|
@@ -96,6 +101,7 @@ function parseCliArgs(argv) {
|
|
|
96
101
|
nonInteractive: false,
|
|
97
102
|
force: false,
|
|
98
103
|
positional: [],
|
|
104
|
+
profile: null,
|
|
99
105
|
};
|
|
100
106
|
|
|
101
107
|
const positional = [];
|
|
@@ -133,6 +139,10 @@ function parseCliArgs(argv) {
|
|
|
133
139
|
options.nonInteractive = true;
|
|
134
140
|
} else if (a === "-f" || a === "--force") {
|
|
135
141
|
options.force = true;
|
|
142
|
+
} else if (a === "--profile") {
|
|
143
|
+
options.profile = args[++i];
|
|
144
|
+
} else if (a.startsWith("--profile=")) {
|
|
145
|
+
options.profile = a.slice(10);
|
|
136
146
|
} else if (a.startsWith("--pass=")) {
|
|
137
147
|
options.pass = a.slice(7);
|
|
138
148
|
} else if (a.startsWith("--token=")) {
|
|
@@ -194,8 +204,11 @@ async function main() {
|
|
|
194
204
|
process.exit(options.help ? 0 : 1);
|
|
195
205
|
}
|
|
196
206
|
|
|
197
|
-
const root =
|
|
198
|
-
|
|
207
|
+
const root =
|
|
208
|
+
options.root ||
|
|
209
|
+
(options.profile
|
|
210
|
+
? path.join(os.homedir(), ".omp", "profiles", options.profile, "agent")
|
|
211
|
+
: configRoot());
|
|
199
212
|
try {
|
|
200
213
|
switch (options.command) {
|
|
201
214
|
case "export": {
|
|
@@ -342,6 +355,37 @@ async function main() {
|
|
|
342
355
|
}
|
|
343
356
|
break;
|
|
344
357
|
}
|
|
358
|
+
case "cron": {
|
|
359
|
+
const sub = (options.target || "status").toLowerCase();
|
|
360
|
+
if (sub === "status") {
|
|
361
|
+
const st = getCronStatus();
|
|
362
|
+
if (!st.supported) {
|
|
363
|
+
console.log("[cron] System crontab is not supported or not available in this environment.");
|
|
364
|
+
} else if (st.installed) {
|
|
365
|
+
console.log(`[cron] ✓ Active scheduled maintenance job:\n ${st.line}`);
|
|
366
|
+
} else {
|
|
367
|
+
console.log("[cron] No automated maintenance job installed in crontab. Run 'omp-sync cron install' to enable.");
|
|
368
|
+
}
|
|
369
|
+
} else if (sub === "install" || sub === "enable") {
|
|
370
|
+
const schedule = options.positional[2] || "0 3 * * *";
|
|
371
|
+
const res = installCron(schedule);
|
|
372
|
+
if (res.success) {
|
|
373
|
+
console.log(`[cron] ✓ Successfully installed maintenance job (${res.schedule}) in system crontab.`);
|
|
374
|
+
} else {
|
|
375
|
+
console.error(`[cron] ✗ Failed to install crontab job: ${res.error}`);
|
|
376
|
+
}
|
|
377
|
+
} else if (sub === "remove" || sub === "rm" || sub === "uninstall" || sub === "disable") {
|
|
378
|
+
const res = removeCron();
|
|
379
|
+
if (res.success) {
|
|
380
|
+
console.log("[cron] ✓ Successfully removed maintenance job from system crontab.");
|
|
381
|
+
} else {
|
|
382
|
+
console.error(`[cron] ✗ Failed to remove crontab job: ${res.error}`);
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
throw new Error(`Unknown cron subcommand: ${sub}. Allowed: status, install [schedule], remove.`);
|
|
386
|
+
}
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
345
389
|
|
|
346
390
|
case "provider": {
|
|
347
391
|
const sub = (options.target || "list").toLowerCase();
|
package/index.js
CHANGED
|
@@ -47,6 +47,9 @@ import {
|
|
|
47
47
|
cleanObsoleteFiles,
|
|
48
48
|
runOmpGc,
|
|
49
49
|
scheduleAutoMaintenance,
|
|
50
|
+
getCronStatus,
|
|
51
|
+
installCron,
|
|
52
|
+
removeCron,
|
|
50
53
|
} from "./src/maintenance.js";
|
|
51
54
|
|
|
52
55
|
export {
|
|
@@ -71,6 +74,9 @@ export {
|
|
|
71
74
|
cleanObsoleteFiles,
|
|
72
75
|
runOmpGc,
|
|
73
76
|
scheduleAutoMaintenance,
|
|
77
|
+
getCronStatus,
|
|
78
|
+
installCron,
|
|
79
|
+
removeCron,
|
|
74
80
|
};
|
|
75
81
|
|
|
76
82
|
const MAGIC = Buffer.from("OMPCFG1\0", "latin1");
|
package/package.json
CHANGED
package/src/maintenance.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
|
-
import { exec } from "node:child_process";
|
|
4
|
+
import { exec, execSync } from "node:child_process";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
|
|
7
7
|
const execAsync = promisify(exec);
|
|
@@ -181,3 +181,61 @@ export function scheduleAutoMaintenance(agentDir = getAgentDir(), delayMs = 4000
|
|
|
181
181
|
runMaintenance({ agentDir }).catch(() => {});
|
|
182
182
|
}, delayMs).unref?.();
|
|
183
183
|
}
|
|
184
|
+
|
|
185
|
+
const CRON_TAG = "# omp-auto-maint";
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Check if automated maintenance is scheduled in system crontab.
|
|
189
|
+
*/
|
|
190
|
+
export function getCronStatus() {
|
|
191
|
+
try {
|
|
192
|
+
const out = execSync("crontab -l 2>/dev/null", { encoding: "utf8" });
|
|
193
|
+
const line = out.split("\n").find((l) => l.includes(CRON_TAG));
|
|
194
|
+
return { installed: Boolean(line), line: line || null, supported: true };
|
|
195
|
+
} catch {
|
|
196
|
+
return { installed: false, line: null, supported: false };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Install scheduled maintenance into system crontab.
|
|
202
|
+
*/
|
|
203
|
+
export function installCron(schedule = "0 3 * * *", command = null) {
|
|
204
|
+
try {
|
|
205
|
+
let current = "";
|
|
206
|
+
try {
|
|
207
|
+
current = execSync("crontab -l 2>/dev/null", { encoding: "utf8" });
|
|
208
|
+
} catch {}
|
|
209
|
+
|
|
210
|
+
const lines = current.split("\n").filter((l) => !l.includes(CRON_TAG) && l.trim().length > 0);
|
|
211
|
+
const cmd = command || "npx -y omp-config-crypt maint --force > /dev/null 2>&1";
|
|
212
|
+
lines.push(`${schedule} ${cmd} ${CRON_TAG}`);
|
|
213
|
+
|
|
214
|
+
execSync(`(echo "${lines.join("\n")}") | crontab -`);
|
|
215
|
+
return { success: true, schedule, command: cmd };
|
|
216
|
+
} catch (err) {
|
|
217
|
+
return { success: false, error: err.message };
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Remove scheduled maintenance from system crontab.
|
|
223
|
+
*/
|
|
224
|
+
export function removeCron() {
|
|
225
|
+
try {
|
|
226
|
+
let current = "";
|
|
227
|
+
try {
|
|
228
|
+
current = execSync("crontab -l 2>/dev/null", { encoding: "utf8" });
|
|
229
|
+
} catch {}
|
|
230
|
+
|
|
231
|
+
const lines = current.split("\n").filter((l) => !l.includes(CRON_TAG) && l.trim().length > 0);
|
|
232
|
+
if (lines.length > 0) {
|
|
233
|
+
execSync(`(echo "${lines.join("\n")}") | crontab -`);
|
|
234
|
+
} else {
|
|
235
|
+
execSync("crontab -r 2>/dev/null || true");
|
|
236
|
+
}
|
|
237
|
+
return { success: true };
|
|
238
|
+
} catch (err) {
|
|
239
|
+
return { success: false, error: err.message };
|
|
240
|
+
}
|
|
241
|
+
}
|