omp-config-crypt 0.7.0 → 0.8.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/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 {
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.0",
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);