omp-config-crypt 0.6.0 → 0.6.1

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 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
@@ -342,6 +346,37 @@ async function main() {
342
346
  }
343
347
  break;
344
348
  }
349
+ case "cron": {
350
+ const sub = (options.target || "status").toLowerCase();
351
+ if (sub === "status") {
352
+ const st = getCronStatus();
353
+ if (!st.supported) {
354
+ console.log("[cron] System crontab is not supported or not available in this environment.");
355
+ } else if (st.installed) {
356
+ console.log(`[cron] ✓ Active scheduled maintenance job:\n ${st.line}`);
357
+ } else {
358
+ console.log("[cron] No automated maintenance job installed in crontab. Run 'omp-sync cron install' to enable.");
359
+ }
360
+ } else if (sub === "install" || sub === "enable") {
361
+ const schedule = options.positional[2] || "0 3 * * *";
362
+ const res = installCron(schedule);
363
+ if (res.success) {
364
+ console.log(`[cron] ✓ Successfully installed maintenance job (${res.schedule}) in system crontab.`);
365
+ } else {
366
+ console.error(`[cron] ✗ Failed to install crontab job: ${res.error}`);
367
+ }
368
+ } else if (sub === "remove" || sub === "rm" || sub === "uninstall" || sub === "disable") {
369
+ const res = removeCron();
370
+ if (res.success) {
371
+ console.log("[cron] ✓ Successfully removed maintenance job from system crontab.");
372
+ } else {
373
+ console.error(`[cron] ✗ Failed to remove crontab job: ${res.error}`);
374
+ }
375
+ } else {
376
+ throw new Error(`Unknown cron subcommand: ${sub}. Allowed: status, install [schedule], remove.`);
377
+ }
378
+ break;
379
+ }
345
380
 
346
381
  case "provider": {
347
382
  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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-config-crypt",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Universal cross-platform encrypted portability for omp config, extensions, and instructions",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -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
+ }