omp-config-crypt 0.7.0 → 0.8.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/README.md CHANGED
@@ -56,6 +56,12 @@ npx omp-config-crypt pull gist:<id> --pass "mysecret" --token "$GITHUB_TOKEN" --
56
56
  # automatically (no --force needed); corrupt policy/state JSON is backed up and rebuilt
57
57
  npx omp-config-crypt pull gist:<id> --pass "mysecret" --token "$GITHUB_TOKEN"
58
58
 
59
+ # Conflict resolution: when local files differ from remote with no baseline
60
+ # (initial-conflict-both-exist-different), default behavior aborts. Auto-resolve:
61
+ # --strategy prefer-remote overwrite local with remote (typical fresh-machine pull)
62
+ # --strategy prefer-local keep local files and adopt them as the new baseline
63
+ npx omp-config-crypt pull gist:<id> --pass "mysecret" --token "$GITHUB_TOKEN" --strategy prefer-remote
64
+
59
65
  # Rollback to previous configuration snapshot
60
66
  npx omp-config-crypt rollback
61
67
 
package/bin/omp-sync.js CHANGED
@@ -58,6 +58,9 @@ Commands:
58
58
  pull <gist:id|url> Download and restore configs from Gist or HTTP URL
59
59
  (-f/--force adopts a differing remote namespace; local
60
60
  policy/state are backed up to .bak first)
61
+ (--strategy prefer-remote|prefer-local auto-resolves
62
+ conflicts by taking remote or local side; default:
63
+ report conflicts and abort)
61
64
  rollback Revert the most recent config restore from its backup
62
65
  rehydrate Rehydrate and repair locked/linked plugins in ~/.omp/plugins
63
66
  maint / gc [--force] Run automatic storage maintenance, WAL checkpoint & GC
@@ -84,6 +87,7 @@ Options:
84
87
  --public Save as public (synced across machines via models.yml)
85
88
  -y, --yes Non-interactive mode (use defaults without prompting)
86
89
  -f, --force Force operations (pull: adopt differing remote namespace)
90
+ --strategy <mode> Conflict resolution for pull: prefer-remote | prefer-local
87
91
  --profile <name> Target specific profile scene (e.g. dev, ops)
88
92
 
89
93
  Environment Variables:
@@ -114,6 +118,7 @@ function parseCliArgs(argv) {
114
118
  isPrivate: null,
115
119
  nonInteractive: false,
116
120
  force: false,
121
+ strategy: null,
117
122
  checkOnly: false,
118
123
  positional: [],
119
124
  profile: null,
@@ -152,6 +157,10 @@ function parseCliArgs(argv) {
152
157
  options.nonInteractive = true;
153
158
  } else if (a === "-f" || a === "--force") {
154
159
  options.force = true;
160
+ } else if (a === "--strategy") {
161
+ options.strategy = args[++i];
162
+ } else if (a.startsWith("--strategy=")) {
163
+ options.strategy = a.slice(11);
155
164
  } else if (a === "--check") {
156
165
  options.checkOnly = true;
157
166
  } else if (a === "--profile") {
@@ -310,6 +319,7 @@ async function main() {
310
319
  const pass = await resolvePass(options.pass);
311
320
  const res = importEncrypted(options.target, pass, root, {
312
321
  dryRun: options.dryRun,
322
+ strategy: options.strategy,
313
323
  });
314
324
  if (res.adaptedFile) {
315
325
  console.log(`[import] incompatible v${res.legacy?.from}; adapted -> ${res.adaptedFile}`);
@@ -361,8 +371,8 @@ async function main() {
361
371
  const token = await resolveToken(options.token, target.kind === "gist");
362
372
  const res =
363
373
  target.kind === "gist"
364
- ? await pullGist(target.id, pass, root, token, { dryRun: options.dryRun, force: options.force })
365
- : await pullHttp(target.url, pass, root, token, { dryRun: options.dryRun, force: options.force });
374
+ ? await pullGist(target.id, pass, root, token, { dryRun: options.dryRun, force: options.force, strategy: options.strategy })
375
+ : await pullHttp(target.url, pass, root, token, { dryRun: options.dryRun, force: options.force, strategy: options.strategy });
366
376
  if (res.adoptedNamespace) {
367
377
  console.log(`[pull] Adopted remote namespace ${res.adoptedNamespace} (--force); prior policy/state saved as .bak`);
368
378
  }
package/index.js CHANGED
@@ -364,7 +364,7 @@ export function restoreArchive(blob, pass, root = configRoot(), options = {}) {
364
364
  }
365
365
 
366
366
  const dryRun = Boolean(options.dryRun);
367
- const plan = planSync(effectivePayload, root);
367
+ const plan = planSync(effectivePayload, root, { strategy: options.strategy });
368
368
 
369
369
  if (dryRun) {
370
370
  return {
@@ -750,23 +750,28 @@ export async function pullHttp(url, pass, root = configRoot(), token = envToken(
750
750
  }
751
751
 
752
752
  export function parseSpec(spec) {
753
- const s = spec.trim();
754
- if (s.startsWith("gist:")) return { kind: "gist", id: s.slice(5) || "new" };
755
- if (/^https?:\/\//.test(s)) return { kind: "http", url: s };
753
+ const s = String(spec || "").trim();
754
+ if (s.startsWith("gist:")) return { kind: "gist", id: s.slice(5).split(/\s+/)[0] || "new" };
755
+ if (/^https?:\/\/\S+$/.test(s)) return { kind: "http", url: s };
756
756
  throw new Error("expected gist:<id|new> or an https URL");
757
757
  }
758
758
 
759
759
  export function extractDryRun(str) {
760
760
  const raw = String(str || "").trim();
761
- if (!raw) return { dryRun: false, clean: "" };
762
- const tokens = [];
763
- const re = /"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|(\S+)/g;
761
+ if (!raw) return { dryRun: false, force: false, strategy: null, clean: "" };
762
+ const re = /"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^"\\]*)*)'|(\S+)/g;
764
763
  let match;
765
764
  let dryRun = false;
766
765
  let force = false;
766
+ let strategy = null;
767
767
  const kept = [];
768
+ const tokens = [];
768
769
  while ((match = re.exec(raw))) {
769
770
  const token = match[1] !== undefined ? match[1] : match[2] !== undefined ? match[2] : match[3];
771
+ tokens.push(token);
772
+ }
773
+ for (let i = 0; i < tokens.length; i++) {
774
+ const token = tokens[i];
770
775
  if (token === "--dry-run" || token === "-d") {
771
776
  dryRun = true;
772
777
  continue;
@@ -775,11 +780,24 @@ export function extractDryRun(str) {
775
780
  force = true;
776
781
  continue;
777
782
  }
783
+ if (token === "--strategy") {
784
+ const value = tokens[++i];
785
+ if (value === undefined || value.startsWith("-")) {
786
+ throw new Error("--strategy requires a value: prefer-remote | prefer-local");
787
+ }
788
+ strategy = value;
789
+ continue;
790
+ }
791
+ if (token.startsWith("--strategy=")) {
792
+ strategy = token.slice(11);
793
+ continue;
794
+ }
795
+ if (token.startsWith("-") && token !== "-") {
796
+ throw new Error(`unknown flag: ${token}`);
797
+ }
778
798
  kept.push(token);
779
799
  }
780
- const result = { dryRun, clean: kept.join(" ") };
781
- if (force) result.force = true;
782
- return result;
800
+ return { dryRun, force, strategy, clean: kept.join(" ") };
783
801
  }
784
802
 
785
803
  export function formatSyncReport(result = {}) {
@@ -1017,14 +1035,14 @@ export default function (pi) {
1017
1035
  pi.registerCommand("config-import", {
1018
1036
  description: "Decrypt and restore an omp config archive (--dry-run to preview)",
1019
1037
  handler: async (args, ctx) => {
1020
- const { dryRun, clean: src } = extractDryRun(args || "");
1038
+ const { dryRun, strategy, clean: src } = extractDryRun(args || "");
1021
1039
  if (!src) {
1022
- ctx.ui.notify("usage: /config-import <file.enc> [--dry-run]", "error");
1040
+ ctx.ui.notify("usage: /config-import <file.enc> [--dry-run] [--strategy prefer-remote|prefer-local]", "error");
1023
1041
  return;
1024
1042
  }
1025
1043
  try {
1026
1044
  const pass = await askPass(ctx, "Import passphrase");
1027
- const r = importEncrypted(src, pass, configRoot(), { dryRun });
1045
+ const r = importEncrypted(src, pass, configRoot(), { dryRun, strategy });
1028
1046
  if (r.adaptedFile) {
1029
1047
  ctx.ui.notify(`[import] incompatible v${r.legacy?.from}; adapted -> ${r.adaptedFile}`, "info");
1030
1048
  }
@@ -1076,9 +1094,9 @@ export default function (pi) {
1076
1094
  const sel = await selectPublicResources(ctx, root);
1077
1095
  if (sel === null) return;
1078
1096
  }
1079
- const { dryRun, force, clean: spec } = extractDryRun(args || "");
1097
+ const { dryRun, force, strategy, clean: spec } = extractDryRun(args || "");
1080
1098
  if (!spec) {
1081
- ctx.ui.notify("usage: /config-pull gist:<id> | https://… [--dry-run] [--force]", "error");
1099
+ ctx.ui.notify("usage: /config-pull gist:<id> | https://… [--dry-run] [--force] [--strategy prefer-remote|prefer-local]", "error");
1082
1100
  return;
1083
1101
  }
1084
1102
  try {
@@ -1086,8 +1104,8 @@ export default function (pi) {
1086
1104
  const pass = await askPass(ctx, "Pull passphrase");
1087
1105
  const token = await askToken(ctx, "Cloud token", target.kind === "gist");
1088
1106
  const r = target.kind === "gist"
1089
- ? await pullGist(target.id, pass, configRoot(), token, { dryRun, force })
1090
- : await pullHttp(target.url, pass, configRoot(), token, { dryRun, force });
1107
+ ? await pullGist(target.id, pass, configRoot(), token, { dryRun, force, strategy })
1108
+ : await pullHttp(target.url, pass, configRoot(), token, { dryRun, force, strategy });
1091
1109
  if (r.adoptedNamespace) {
1092
1110
  ctx.ui.notify(`[pull] adopted remote namespace ${r.adoptedNamespace}; prior policy/state saved as .bak`, "info");
1093
1111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-config-crypt",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "Universal cross-platform encrypted portability for omp config, extensions, and instructions",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/sync-plan.js CHANGED
@@ -762,7 +762,13 @@ export function adaptLegacySnapshot(snapshot) {
762
762
  * Plans the 3-way synchronization between local environment, local baseline, and remote snapshot.
763
763
  * Returns { namespace, actions, conflicts, blocked, prerequisites, writes }
764
764
  */
765
- export function planSync(snapshot, root = configRoot()) {
765
+ export const SYNC_STRATEGIES = new Set(["manual", "prefer-remote", "prefer-local"]);
766
+
767
+ export function planSync(snapshot, root = configRoot(), options = {}) {
768
+ const strategy = options.strategy == null || options.strategy === undefined ? "manual" : options.strategy;
769
+ if (!SYNC_STRATEGIES.has(strategy)) {
770
+ throw new Error(`Invalid sync strategy '${strategy}'; expected one of: ${Array.from(SYNC_STRATEGIES).join(", ")}`);
771
+ }
766
772
  const validSnapshot = validateSnapshot(snapshot);
767
773
  const policy = readSyncPolicy(root);
768
774
  const state = readSyncState(root);
@@ -985,6 +991,28 @@ export function planSync(snapshot, root = configRoot()) {
985
991
  acceptedTransitions.set(id, { hash: SENTINEL_DELETED, tombstone: true });
986
992
  }
987
993
 
994
+ // Strategy-based resolution of otherwise-unresolvable conflicts.
995
+ if (plannedAction === "conflict" && strategy !== "manual") {
996
+ if (strategy === "prefer-remote") {
997
+ if (isRemoteResource) {
998
+ plannedAction = "update";
999
+ reason = "conflict-resolved-remote-preferred";
1000
+ effectiveValue = remoteVal;
1001
+ acceptedTransitions.set(id, { hash: remoteHash, tombstone: false });
1002
+ } else {
1003
+ plannedAction = "delete";
1004
+ reason = "conflict-resolved-remote-preferred";
1005
+ acceptedTransitions.set(id, { hash: SENTINEL_DELETED, tombstone: true });
1006
+ }
1007
+ } else {
1008
+ plannedAction = localPresent ? "keep" : "delete";
1009
+ reason = "conflict-resolved-local-preferred";
1010
+ acceptedTransitions.set(id, localPresent
1011
+ ? { hash: localHash, tombstone: false }
1012
+ : { hash: SENTINEL_DELETED, tombstone: true });
1013
+ }
1014
+ }
1015
+
988
1016
  // Check for plugin prerequisite if plannedAction is add or update
989
1017
  if ((plannedAction === "add" || plannedAction === "update") && id.startsWith("plugin:")) {
990
1018
  const pluginName = id.slice("plugin:".length);