omp-config-crypt 0.9.0 → 0.9.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/index.js +60 -13
- package/package.json +1 -1
- package/src/provider-store.js +47 -11
package/index.js
CHANGED
|
@@ -111,6 +111,7 @@ import {
|
|
|
111
111
|
import {
|
|
112
112
|
inventoryResources,
|
|
113
113
|
readResource,
|
|
114
|
+
canonicalResourceValue,
|
|
114
115
|
sanitizeResourceForExport,
|
|
115
116
|
restoreResourceForImport,
|
|
116
117
|
HOME_PLACEHOLDER,
|
|
@@ -356,12 +357,10 @@ export function adaptArchive(blob, pass) {
|
|
|
356
357
|
}
|
|
357
358
|
|
|
358
359
|
/**
|
|
359
|
-
* Installs
|
|
360
|
-
*
|
|
361
|
-
* public plans sanitize action values away, so the snapshot payload is consulted as
|
|
362
|
-
* fallback. Skipped entries keep their blocked state and surface as apply errors.
|
|
360
|
+
* Installs exact plugin package versions through npm (or an injected installer).
|
|
361
|
+
* Returns the fixed "name@version" entries plus names skipped for missing versions.
|
|
363
362
|
*/
|
|
364
|
-
|
|
363
|
+
function installPluginPackages(entries, root, install) {
|
|
365
364
|
const npmCmd = resolveNpmCommand();
|
|
366
365
|
const doInstall = install ?? ((name, version) => {
|
|
367
366
|
execFileSync(
|
|
@@ -370,14 +369,9 @@ export function fixPluginPrerequisites(plan, root, { install, payload = null } =
|
|
|
370
369
|
{ stdio: "pipe", shell: npmCmd.shell },
|
|
371
370
|
);
|
|
372
371
|
});
|
|
373
|
-
const payloadVersions = new Map((payload?.resources || []).map((resource) => [resource.id, resource.value]));
|
|
374
372
|
const fixed = [];
|
|
375
373
|
const skipped = [];
|
|
376
|
-
for (const
|
|
377
|
-
if (action.action !== "blocked" || !String(action.id || "").startsWith("plugin:")) continue;
|
|
378
|
-
if (action.reason !== "plugin-not-installed" && action.reason !== "plugin-version-mismatch") continue;
|
|
379
|
-
const name = action.id.slice("plugin:".length);
|
|
380
|
-
const version = action.value?.version ?? payloadVersions.get(action.id)?.version ?? null;
|
|
374
|
+
for (const { name, version } of entries) {
|
|
381
375
|
if (!version) {
|
|
382
376
|
skipped.push(name);
|
|
383
377
|
continue;
|
|
@@ -392,6 +386,52 @@ export function fixPluginPrerequisites(plan, root, { install, payload = null } =
|
|
|
392
386
|
return { fixed, skipped };
|
|
393
387
|
}
|
|
394
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Installs remote-declared plugins whose local declaration can no longer be
|
|
391
|
+
* canonicalized — a range dependency (e.g. "^0.1.2") whose node_modules vanished
|
|
392
|
+
* makes planSync throw before the blocked-plugin path can trigger. Restoring the
|
|
393
|
+
* exact remote version first keeps the plan buildable.
|
|
394
|
+
*/
|
|
395
|
+
export function repairUnreadablePlugins(payload, root, { install } = {}) {
|
|
396
|
+
const entries = [];
|
|
397
|
+
for (const resource of payload?.resources || []) {
|
|
398
|
+
const id = String(resource?.id || "");
|
|
399
|
+
if (!id.startsWith("plugin:")) continue;
|
|
400
|
+
const version = resource.value?.version;
|
|
401
|
+
if (!version) continue;
|
|
402
|
+
let local = null;
|
|
403
|
+
try {
|
|
404
|
+
local = readResource(root, id);
|
|
405
|
+
} catch { local = null; }
|
|
406
|
+
if (!local) continue;
|
|
407
|
+
try {
|
|
408
|
+
canonicalResourceValue(id, local.value, root);
|
|
409
|
+
} catch {
|
|
410
|
+
entries.push({ name: id.slice("plugin:".length), version });
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return installPluginPackages(entries, root, install).fixed;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Installs the missing or mismatched plugin dependencies a sync plan blocked on.
|
|
418
|
+
* Versions come from the plan action value when present (internal/hand-built plans);
|
|
419
|
+
* public plans sanitize action values away, so the snapshot payload is consulted as
|
|
420
|
+
* fallback. Skipped entries keep their blocked state and surface as apply errors.
|
|
421
|
+
*/
|
|
422
|
+
export function fixPluginPrerequisites(plan, root, { install, payload = null } = {}) {
|
|
423
|
+
const payloadVersions = new Map((payload?.resources || []).map((resource) => [resource.id, resource.value]));
|
|
424
|
+
const entries = [];
|
|
425
|
+
for (const action of plan.actions || []) {
|
|
426
|
+
if (action.action !== "blocked" || !String(action.id || "").startsWith("plugin:")) continue;
|
|
427
|
+
if (action.reason !== "plugin-not-installed" && action.reason !== "plugin-version-mismatch") continue;
|
|
428
|
+
const name = action.id.slice("plugin:".length);
|
|
429
|
+
const version = action.value?.version ?? payloadVersions.get(action.id)?.version ?? null;
|
|
430
|
+
entries.push({ name, version });
|
|
431
|
+
}
|
|
432
|
+
return installPluginPackages(entries, root, install);
|
|
433
|
+
}
|
|
434
|
+
|
|
395
435
|
/**
|
|
396
436
|
* Restores an encrypted archive buffer into the config tree with 3-way merge planning and journaled transaction.
|
|
397
437
|
*/
|
|
@@ -415,10 +455,17 @@ export function restoreArchive(blob, pass, root = configRoot(), options = {}) {
|
|
|
415
455
|
}
|
|
416
456
|
|
|
417
457
|
const dryRun = Boolean(options.dryRun);
|
|
458
|
+
|
|
459
|
+
// Self-healing stage 1: repair local plugin declarations that would break planning
|
|
460
|
+
// (range dependency with a vanished install). Must run before planSync.
|
|
461
|
+
if (!dryRun && options.autoFixPlugins !== false) {
|
|
462
|
+
repairUnreadablePlugins(effectivePayload, root, { install: options.installFn });
|
|
463
|
+
}
|
|
464
|
+
|
|
418
465
|
let plan = planSync(effectivePayload, root, { strategy: options.strategy });
|
|
419
466
|
|
|
420
|
-
// Self-healing: install plugin dependencies the plan blocked on, then replan
|
|
421
|
-
// (the install mutates the plugins tree, so the original plan is stale). Remaining
|
|
467
|
+
// Self-healing stage 2: install plugin dependencies the plan blocked on, then replan
|
|
468
|
+
// once (the install mutates the plugins tree, so the original plan is stale). Remaining
|
|
422
469
|
// blocked actions still fail the apply.
|
|
423
470
|
if (!dryRun && plan.prerequisites.length > 0 && options.autoFixPlugins !== false) {
|
|
424
471
|
const fx = fixPluginPrerequisites(plan, root, { install: options.installFn, payload: effectivePayload });
|
package/package.json
CHANGED
package/src/provider-store.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import fs from "node:fs";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import os from "node:os";
|
|
11
|
+
import { parseDocument } from "yaml";
|
|
11
12
|
|
|
12
13
|
export function getAgentDir(customRoot) {
|
|
13
14
|
return customRoot || process.env.OMP_CFG_ROOT || path.join(os.homedir(), ".omp", "agent");
|
|
@@ -230,6 +231,27 @@ export function ensureLocalExtension(ompDir) {
|
|
|
230
231
|
*/
|
|
231
232
|
export function parseYamlModels(str) {
|
|
232
233
|
if (!str || typeof str !== "string") return {};
|
|
234
|
+
const providers = parseBlockYamlModels(str);
|
|
235
|
+
if (Object.keys(providers).length) return providers;
|
|
236
|
+
// Flow-style (brace/bracket) YAML: delegate to the yaml package.
|
|
237
|
+
return parseFlowYamlModels(str);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function parseFlowYamlModels(str) {
|
|
241
|
+
let doc;
|
|
242
|
+
try {
|
|
243
|
+
doc = parseDocument(str, { indent: true });
|
|
244
|
+
if (doc.errors.length) return {};
|
|
245
|
+
} catch {
|
|
246
|
+
return {};
|
|
247
|
+
}
|
|
248
|
+
const data = doc.toJS();
|
|
249
|
+
const providers = data && typeof data === "object" && !Array.isArray(data) ? data.providers : null;
|
|
250
|
+
if (!providers || typeof providers !== "object" || Array.isArray(providers)) return {};
|
|
251
|
+
return providers;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function parseBlockYamlModels(str) {
|
|
233
255
|
const lines = str.split("\n");
|
|
234
256
|
const providers = {};
|
|
235
257
|
let curProvider = null;
|
|
@@ -555,26 +577,40 @@ function assertSupportedProviders(providers) {
|
|
|
555
577
|
function assertPublicSource(agentDir) {
|
|
556
578
|
const file = ["models.yml", "models.yaml"].map(name => path.join(agentDir, name)).find(name => fs.existsSync(name));
|
|
557
579
|
if (!file) return;
|
|
580
|
+
const text = fs.readFileSync(file, "utf8");
|
|
581
|
+
// The fixed-field formatter cannot preserve arbitrary YAML. Reject unfamiliar structure,
|
|
582
|
+
// unless the yaml package can parse it into the providers mapping (the next write
|
|
583
|
+
// re-serializes everything in canonical block style anyway).
|
|
584
|
+
try {
|
|
585
|
+
scanBlockSource(text);
|
|
586
|
+
} catch (blockError) {
|
|
587
|
+
if (!parseFlowYamlModels(text) || !Object.keys(parseFlowYamlModels(text)).length) throw blockError;
|
|
588
|
+
assertSupportedProviders(parseFlowYamlModels(text));
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
assertSupportedProviders(readPublicProviders(agentDir));
|
|
592
|
+
}
|
|
593
|
+
function scanBlockSource(text) {
|
|
558
594
|
// The fixed-field formatter cannot preserve arbitrary YAML. Reject unfamiliar structure.
|
|
559
595
|
let section = "", provider = "";
|
|
560
|
-
for (const line of
|
|
561
|
-
const
|
|
562
|
-
if (!
|
|
596
|
+
for (const line of text.split("\n")) {
|
|
597
|
+
const trimmed = line.trim();
|
|
598
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
563
599
|
const indent = line.search(/\S/);
|
|
564
|
-
const field =
|
|
565
|
-
if (indent === 0 &&
|
|
566
|
-
if (indent === 2 && /^[A-Za-z0-9][A-Za-z0-9_-]*:$/.test(
|
|
600
|
+
const field = trimmed.replace(/^-\s*/, "").split(":")[0];
|
|
601
|
+
if (indent === 0 && trimmed === "providers:") { section = "providers"; continue; }
|
|
602
|
+
if (indent === 2 && /^[A-Za-z0-9][A-Za-z0-9_-]*:$/.test(trimmed)) { provider = field; section = "provider"; continue; }
|
|
567
603
|
if (provider && indent === 4 && PROVIDER_FIELDS.has(field)) {
|
|
568
|
-
section = field === "models" &&
|
|
569
|
-
if (section === "provider" && field !== "apiKey" && !
|
|
604
|
+
section = field === "models" && trimmed === "models:" ? "models" : "provider";
|
|
605
|
+
if (section === "provider" && field !== "apiKey" && !trimmed.slice(trimmed.indexOf(":") + 1).trim()) unsupported(`${provider}.${field}`);
|
|
570
606
|
continue;
|
|
571
607
|
}
|
|
572
608
|
if (section === "models" || section === "model" || section === "compat") {
|
|
573
|
-
if (indent === 6 &&
|
|
609
|
+
if (indent === 6 && trimmed.startsWith("- ") && field === "id") { section = "model"; continue; }
|
|
574
610
|
if (indent === 8 && MODEL_FIELDS.has(field)) { section = field === "compat" ? "compat" : "model"; continue; }
|
|
575
|
-
if (indent === 10 && section === "compat" && /^[A-Za-z0-9_-]+:\s*\S/.test(
|
|
611
|
+
if (indent === 10 && section === "compat" && /^[A-Za-z0-9_-]+:\s*\S/.test(trimmed)) continue;
|
|
576
612
|
}
|
|
577
613
|
unsupported(`${provider || "root"}.${field}`);
|
|
578
614
|
}
|
|
579
|
-
assertSupportedProviders(readPublicProviders(agentDir));
|
|
580
615
|
}
|
|
616
|
+
|