omp-config-crypt 0.9.5 → 0.9.6
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 +6 -3
- package/bin/omp-sync.js +9 -2
- package/index.js +15 -10
- package/package.json +1 -1
- package/src/sync-plan.js +17 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# omp-config-crypt (v0.
|
|
1
|
+
# omp-config-crypt (v0.9.6)
|
|
2
2
|
|
|
3
3
|
Universal, zero-repair cross-platform configuration encryption and synchronization engine for `omp` (Oh My Pi).
|
|
4
4
|
|
|
@@ -62,6 +62,9 @@ npx omp-config-crypt pull gist:<id> --pass "mysecret" --token "$GITHUB_TOKEN"
|
|
|
62
62
|
# --strategy prefer-local keep local files and adopt them as the new baseline
|
|
63
63
|
npx omp-config-crypt pull gist:<id> --pass "mysecret" --token "$GITHUB_TOKEN" --strategy prefer-remote
|
|
64
64
|
|
|
65
|
+
# Keep every modelRoles leaf local (preset and top-level). Other conflicts still abort.
|
|
66
|
+
npx omp-config-crypt pull gist:<id> --pass "mysecret" --token "$GITHUB_TOKEN" --local
|
|
67
|
+
|
|
65
68
|
# Rollback to previous configuration snapshot
|
|
66
69
|
npx omp-config-crypt rollback
|
|
67
70
|
|
|
@@ -95,8 +98,8 @@ Configuration exports include the installed `omp-config-crypt` source (excluding
|
|
|
95
98
|
/config-push gist:new
|
|
96
99
|
/config-push gist:<id>
|
|
97
100
|
/config-push https://…
|
|
98
|
-
/config-pull gist:<id> [--dry-run] [--force]
|
|
99
|
-
/config-pull https://… [--dry-run] [--force]
|
|
101
|
+
/config-pull gist:<id> [--dry-run] [--force] [--local]
|
|
102
|
+
/config-pull https://… [--dry-run] [--force] [--local]
|
|
100
103
|
/config-rollback
|
|
101
104
|
/config-upgrade [--check]
|
|
102
105
|
/config-doctor [gist:<id> | https://…]
|
package/bin/omp-sync.js
CHANGED
|
@@ -62,6 +62,8 @@ Commands:
|
|
|
62
62
|
(--strategy prefer-remote|prefer-local auto-resolves
|
|
63
63
|
conflicts by taking remote or local side; default:
|
|
64
64
|
report conflicts and abort)
|
|
65
|
+
(--local keeps modelRoles leaves local and still
|
|
66
|
+
aborts on every other conflict)
|
|
65
67
|
rollback Revert the most recent config restore from its backup
|
|
66
68
|
doctor [target] Preflight env/config checks with self-healing
|
|
67
69
|
(optional gist:<id> or https://url target)
|
|
@@ -91,6 +93,7 @@ Options:
|
|
|
91
93
|
-y, --yes Non-interactive mode (use defaults without prompting)
|
|
92
94
|
-f, --force Force operations (pull: adopt differing remote namespace)
|
|
93
95
|
--strategy <mode> Conflict resolution for pull: prefer-remote | prefer-local
|
|
96
|
+
--local Keep modelRoles leaves local; other conflicts still abort
|
|
94
97
|
--profile <name> Target specific profile scene (e.g. dev, ops)
|
|
95
98
|
|
|
96
99
|
Environment Variables:
|
|
@@ -122,6 +125,7 @@ function parseCliArgs(argv) {
|
|
|
122
125
|
nonInteractive: false,
|
|
123
126
|
force: false,
|
|
124
127
|
strategy: null,
|
|
128
|
+
keepLocal: false,
|
|
125
129
|
checkOnly: false,
|
|
126
130
|
positional: [],
|
|
127
131
|
profile: null,
|
|
@@ -164,6 +168,8 @@ function parseCliArgs(argv) {
|
|
|
164
168
|
options.strategy = args[++i];
|
|
165
169
|
} else if (a.startsWith("--strategy=")) {
|
|
166
170
|
options.strategy = a.slice(11);
|
|
171
|
+
} else if (a === "--local") {
|
|
172
|
+
options.keepLocal = true;
|
|
167
173
|
} else if (a === "--check") {
|
|
168
174
|
options.checkOnly = true;
|
|
169
175
|
} else if (a === "--profile") {
|
|
@@ -323,6 +329,7 @@ async function main() {
|
|
|
323
329
|
const res = importEncrypted(options.target, pass, root, {
|
|
324
330
|
dryRun: options.dryRun,
|
|
325
331
|
strategy: options.strategy,
|
|
332
|
+
keepLocalRoles: options.keepLocal,
|
|
326
333
|
});
|
|
327
334
|
if (res.adaptedFile) {
|
|
328
335
|
console.log(`[import] incompatible v${res.legacy?.from}; adapted -> ${res.adaptedFile}`);
|
|
@@ -374,8 +381,8 @@ async function main() {
|
|
|
374
381
|
const token = await resolveToken(options.token, target.kind === "gist");
|
|
375
382
|
const res =
|
|
376
383
|
target.kind === "gist"
|
|
377
|
-
? await pullGist(target.id, pass, root, token, { dryRun: options.dryRun, force: options.force, strategy: options.strategy })
|
|
378
|
-
: await pullHttp(target.url, pass, root, token, { dryRun: options.dryRun, force: options.force, strategy: options.strategy });
|
|
384
|
+
? await pullGist(target.id, pass, root, token, { dryRun: options.dryRun, force: options.force, strategy: options.strategy, keepLocalRoles: options.keepLocal })
|
|
385
|
+
: await pullHttp(target.url, pass, root, token, { dryRun: options.dryRun, force: options.force, strategy: options.strategy, keepLocalRoles: options.keepLocal });
|
|
379
386
|
if (res.adoptedNamespace) {
|
|
380
387
|
console.log(`[pull] Adopted remote namespace ${res.adoptedNamespace} (--force); prior policy/state saved as .bak`);
|
|
381
388
|
}
|
package/index.js
CHANGED
|
@@ -462,14 +462,14 @@ export function restoreArchive(blob, pass, root = configRoot(), options = {}) {
|
|
|
462
462
|
repairUnreadablePlugins(effectivePayload, root, { install: options.installFn });
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
-
let plan = planSync(effectivePayload, root, { strategy: options.strategy });
|
|
465
|
+
let plan = planSync(effectivePayload, root, { strategy: options.strategy, keepLocalRoles: options.keepLocalRoles === true });
|
|
466
466
|
|
|
467
467
|
// Self-healing stage 2: install plugin dependencies the plan blocked on, then replan
|
|
468
468
|
// once (the install mutates the plugins tree, so the original plan is stale). Remaining
|
|
469
469
|
// blocked actions still fail the apply.
|
|
470
470
|
if (!dryRun && plan.prerequisites.length > 0 && options.autoFixPlugins !== false) {
|
|
471
471
|
const fx = fixPluginPrerequisites(plan, root, { install: options.installFn, payload: effectivePayload });
|
|
472
|
-
if (fx.fixed.length > 0) plan = planSync(effectivePayload, root, { strategy: options.strategy });
|
|
472
|
+
if (fx.fixed.length > 0) plan = planSync(effectivePayload, root, { strategy: options.strategy, keepLocalRoles: options.keepLocalRoles === true });
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
if (dryRun) {
|
|
@@ -890,12 +890,13 @@ export function parseSpec(spec) {
|
|
|
890
890
|
|
|
891
891
|
export function extractDryRun(str) {
|
|
892
892
|
const raw = String(str || "").trim();
|
|
893
|
-
if (!raw) return { dryRun: false, force: false, strategy: null, clean: "" };
|
|
893
|
+
if (!raw) return { dryRun: false, force: false, strategy: null, keepLocal: false, clean: "" };
|
|
894
894
|
const re = /"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^"\\]*)*)'|(\S+)/g;
|
|
895
895
|
let match;
|
|
896
896
|
let dryRun = false;
|
|
897
897
|
let force = false;
|
|
898
898
|
let strategy = null;
|
|
899
|
+
let keepLocal = false;
|
|
899
900
|
const kept = [];
|
|
900
901
|
const tokens = [];
|
|
901
902
|
while ((match = re.exec(raw))) {
|
|
@@ -912,6 +913,10 @@ export function extractDryRun(str) {
|
|
|
912
913
|
force = true;
|
|
913
914
|
continue;
|
|
914
915
|
}
|
|
916
|
+
if (token === "--local") {
|
|
917
|
+
keepLocal = true;
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
915
920
|
if (token === "--strategy") {
|
|
916
921
|
const value = tokens[++i];
|
|
917
922
|
if (value === undefined || value.startsWith("-")) {
|
|
@@ -929,7 +934,7 @@ export function extractDryRun(str) {
|
|
|
929
934
|
}
|
|
930
935
|
kept.push(token);
|
|
931
936
|
}
|
|
932
|
-
return { dryRun, force, strategy, clean: kept.join(" ") };
|
|
937
|
+
return { dryRun, force, strategy, keepLocal, clean: kept.join(" ") };
|
|
933
938
|
}
|
|
934
939
|
|
|
935
940
|
export function formatSyncReport(result = {}) {
|
|
@@ -1167,14 +1172,14 @@ export default function (pi) {
|
|
|
1167
1172
|
pi.registerCommand("config-import", {
|
|
1168
1173
|
description: "Decrypt and restore an omp config archive (--dry-run to preview)",
|
|
1169
1174
|
handler: async (args, ctx) => {
|
|
1170
|
-
const { dryRun, strategy, clean: src } = extractDryRun(args || "");
|
|
1175
|
+
const { dryRun, strategy, keepLocal, clean: src } = extractDryRun(args || "");
|
|
1171
1176
|
if (!src) {
|
|
1172
1177
|
ctx.ui.notify("usage: /config-import <file.enc> [--dry-run] [--strategy prefer-remote|prefer-local]", "error");
|
|
1173
1178
|
return;
|
|
1174
1179
|
}
|
|
1175
1180
|
try {
|
|
1176
1181
|
const pass = await askPass(ctx, "Import passphrase");
|
|
1177
|
-
const r = importEncrypted(src, pass, configRoot(), { dryRun, strategy });
|
|
1182
|
+
const r = importEncrypted(src, pass, configRoot(), { dryRun, strategy, keepLocalRoles: keepLocal });
|
|
1178
1183
|
if (r.adaptedFile) {
|
|
1179
1184
|
ctx.ui.notify(`[import] incompatible v${r.legacy?.from}; adapted -> ${r.adaptedFile}`, "info");
|
|
1180
1185
|
}
|
|
@@ -1226,9 +1231,9 @@ export default function (pi) {
|
|
|
1226
1231
|
const sel = await selectPublicResources(ctx, root);
|
|
1227
1232
|
if (sel === null) return;
|
|
1228
1233
|
}
|
|
1229
|
-
const { dryRun, force, strategy, clean: spec } = extractDryRun(args || "");
|
|
1234
|
+
const { dryRun, force, strategy, keepLocal, clean: spec } = extractDryRun(args || "");
|
|
1230
1235
|
if (!spec) {
|
|
1231
|
-
ctx.ui.notify("usage: /config-pull gist:<id> | https://… [--dry-run] [--force] [--strategy prefer-remote|prefer-local]", "error");
|
|
1236
|
+
ctx.ui.notify("usage: /config-pull gist:<id> | https://… [--dry-run] [--force] [--strategy prefer-remote|prefer-local] [--local]", "error");
|
|
1232
1237
|
return;
|
|
1233
1238
|
}
|
|
1234
1239
|
try {
|
|
@@ -1236,8 +1241,8 @@ export default function (pi) {
|
|
|
1236
1241
|
const pass = await askPass(ctx, "Pull passphrase");
|
|
1237
1242
|
const token = await askToken(ctx, "Cloud token", target.kind === "gist");
|
|
1238
1243
|
const r = target.kind === "gist"
|
|
1239
|
-
? await pullGist(target.id, pass, configRoot(), token, { dryRun, force, strategy })
|
|
1240
|
-
: await pullHttp(target.url, pass, configRoot(), token, { dryRun, force, strategy });
|
|
1244
|
+
? await pullGist(target.id, pass, configRoot(), token, { dryRun, force, strategy, keepLocalRoles: keepLocal })
|
|
1245
|
+
: await pullHttp(target.url, pass, configRoot(), token, { dryRun, force, strategy, keepLocalRoles: keepLocal });
|
|
1241
1246
|
if (Array.isArray(r.preflight) && r.preflight.length > 0) {
|
|
1242
1247
|
ctx.ui.notify(
|
|
1243
1248
|
"[pull] preflight:\n" + r.preflight.map((c) => ` [${c.status.toUpperCase()}] ${c.id}: ${c.detail}`).join("\n"),
|
package/package.json
CHANGED
package/src/sync-plan.js
CHANGED
|
@@ -764,11 +764,19 @@ export function adaptLegacySnapshot(snapshot) {
|
|
|
764
764
|
*/
|
|
765
765
|
export const SYNC_STRATEGIES = new Set(["manual", "prefer-remote", "prefer-local"]);
|
|
766
766
|
|
|
767
|
+
function isModelRoleSetting(id) {
|
|
768
|
+
if (!id.startsWith("setting:")) return false;
|
|
769
|
+
const tokens = id.slice("setting:".length).split("/").filter(Boolean);
|
|
770
|
+
const at = tokens.lastIndexOf("modelRoles");
|
|
771
|
+
return at >= 0 && at === tokens.length - 2;
|
|
772
|
+
}
|
|
773
|
+
|
|
767
774
|
export function planSync(snapshot, root = configRoot(), options = {}) {
|
|
768
775
|
const strategy = options.strategy == null || options.strategy === undefined ? "manual" : options.strategy;
|
|
769
776
|
if (!SYNC_STRATEGIES.has(strategy)) {
|
|
770
777
|
throw new Error(`Invalid sync strategy '${strategy}'; expected one of: ${Array.from(SYNC_STRATEGIES).join(", ")}`);
|
|
771
778
|
}
|
|
779
|
+
const keepLocalRoles = options.keepLocalRoles === true;
|
|
772
780
|
const validSnapshot = validateSnapshot(snapshot);
|
|
773
781
|
const policy = readSyncPolicy(root);
|
|
774
782
|
const state = readSyncState(root);
|
|
@@ -1013,6 +1021,15 @@ export function planSync(snapshot, root = configRoot(), options = {}) {
|
|
|
1013
1021
|
}
|
|
1014
1022
|
}
|
|
1015
1023
|
|
|
1024
|
+
// --local: modelRoles leaves stay local. Other conflicts still abort the plan.
|
|
1025
|
+
if (plannedAction === "conflict" && keepLocalRoles && isModelRoleSetting(id)) {
|
|
1026
|
+
plannedAction = localPresent ? "keep" : "delete";
|
|
1027
|
+
reason = "conflict-resolved-local-role";
|
|
1028
|
+
acceptedTransitions.set(id, localPresent
|
|
1029
|
+
? { hash: localHash, tombstone: false }
|
|
1030
|
+
: { hash: SENTINEL_DELETED, tombstone: true });
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1016
1033
|
// Check for plugin prerequisite if plannedAction is add or update
|
|
1017
1034
|
if ((plannedAction === "add" || plannedAction === "update") && id.startsWith("plugin:")) {
|
|
1018
1035
|
const pluginName = id.slice("plugin:".length);
|