omp-config-crypt 0.5.3 → 0.5.5

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 CHANGED
@@ -36,6 +36,8 @@ import {
36
36
  readPrivateProviders,
37
37
  writePrivateProviders,
38
38
  ensureLocalExtension,
39
+ parseYamlModels,
40
+ formatYamlModels,
39
41
  } from "./src/provider-store.js";
40
42
  import { getRoles, setRole, VALID_ROLES } from "./src/role-manager.js";
41
43
 
@@ -241,8 +243,22 @@ export function buildArchive(pass, root = configRoot()) {
241
243
  const homePosix = home.replace(/\\/g, "/");
242
244
 
243
245
  const files = items.map(({ rel, abs }) => {
244
- const raw = fs.readFileSync(abs);
246
+ let raw = fs.readFileSync(abs);
245
247
  const mode = fs.statSync(abs).mode & 0o777;
248
+
249
+ // Sanitize private providers from models.yml so they are never exported to cloud
250
+ if (rel === "models.yml" || rel === "models.yaml") {
251
+ try {
252
+ const providers = parseYamlModels(raw.toString("utf8"));
253
+ const publicProviders = {};
254
+ for (const [name, cfg] of Object.entries(providers)) {
255
+ if (!cfg.private) {
256
+ publicProviders[name] = cfg;
257
+ }
258
+ }
259
+ raw = Buffer.from(formatYamlModels(publicProviders), "utf8");
260
+ } catch {}
261
+ }
246
262
  let data;
247
263
  if (isText(raw)) {
248
264
  let str = raw.toString("utf8");
@@ -337,8 +353,26 @@ export function restoreArchive(blob, pass, root = configRoot(), options = {}) {
337
353
  buf = Buffer.from(str, "utf8");
338
354
  }
339
355
  }
340
-
341
356
  const exists = fs.existsSync(dst);
357
+
358
+ // Intelligently merge existing local private providers in models.yml so they are never overwritten
359
+ if ((rel === "models.yml" || rel === "models.yaml") && exists) {
360
+ try {
361
+ const existingRaw = fs.readFileSync(dst, "utf8");
362
+ const existingProviders = parseYamlModels(existingRaw);
363
+ const privateProviders = {};
364
+ for (const [name, cfg] of Object.entries(existingProviders)) {
365
+ if (cfg.private) {
366
+ privateProviders[name] = cfg;
367
+ }
368
+ }
369
+ if (Object.keys(privateProviders).length > 0) {
370
+ const incomingProviders = parseYamlModels(buf.toString("utf8"));
371
+ const merged = { ...incomingProviders, ...privateProviders };
372
+ buf = Buffer.from(formatYamlModels(merged), "utf8");
373
+ }
374
+ } catch {}
375
+ }
342
376
  actions.push({ path: rel, dest: dst, exists, remapped });
343
377
 
344
378
  if (!dryRun) {
@@ -648,6 +682,46 @@ export default function (pi) {
648
682
  });
649
683
  pi.registerCommand("provider", {
650
684
  description: "Manage LLM providers (/provider ls | add <name> <url> <key> | rm <name>)",
685
+ getArgumentCompletions: (prefix) => {
686
+ const parts = (prefix || "").split(/\s+/);
687
+ const sub = parts[0]?.toLowerCase();
688
+
689
+ if (!prefix.includes(" ") || parts.length <= 1) {
690
+ const subcommands = [
691
+ { value: "add", description: "Auto-probe and add a new provider (wizard)" },
692
+ { value: "ls", description: "List all configured providers & models" },
693
+ { value: "rm", description: "Remove a provider from configuration" },
694
+ ];
695
+ const p = parts[0]?.toLowerCase() || "";
696
+ return subcommands.filter((s) => s.value.startsWith(p));
697
+ }
698
+
699
+ if (sub === "rm" || sub === "remove") {
700
+ if (parts.length === 2) {
701
+ const providers = listProviders({ agentDir: configRoot() });
702
+ const target = parts[1].toLowerCase();
703
+ return providers
704
+ .map((p) => ({
705
+ value: p.name,
706
+ description: `${p.isPrivate ? "Private" : "Public"} (${p.models.length} models)`,
707
+ }))
708
+ .filter((i) => i.value.toLowerCase().startsWith(target));
709
+ }
710
+ }
711
+
712
+ if (sub === "add") {
713
+ const last = parts[parts.length - 1];
714
+ if (last.startsWith("-")) {
715
+ const flags = [
716
+ { value: "--private", description: "Save to local-only, unsynced store (default)" },
717
+ { value: "--public", description: "Save to synced models.yml" },
718
+ ];
719
+ return flags.filter((f) => f.value.startsWith(last));
720
+ }
721
+ }
722
+
723
+ return null;
724
+ },
651
725
  handler: async (args, ctx) => {
652
726
  const cleanArgs = (args || "").trim();
653
727
  const parts = cleanArgs.split(/\s+/).filter(Boolean);
@@ -764,6 +838,47 @@ export default function (pi) {
764
838
 
765
839
  pi.registerCommand("role", {
766
840
  description: "Manage model roles (/role ls | <role> <provider/model>)",
841
+ getArgumentCompletions: (prefix) => {
842
+ const parts = (prefix || "").split(/\s+/);
843
+ const sub = parts[0]?.toLowerCase();
844
+
845
+ if (!prefix.includes(" ") || parts.length <= 1) {
846
+ const roles = [
847
+ { value: "default", description: "Primary chat & orchestration model" },
848
+ { value: "smol", description: "Fast model for lightweight tasks & tools" },
849
+ { value: "plan", description: "High-context architectural planning model" },
850
+ { value: "slow", description: "Deep reasoning / hard debugging model" },
851
+ { value: "web", description: "Web search provider model" },
852
+ { value: "ls", description: "List current role mappings" },
853
+ ];
854
+ const p = parts[0]?.toLowerCase() || "";
855
+ return roles.filter((r) => r.value.startsWith(p));
856
+ }
857
+
858
+ if (VALID_ROLES.includes(sub)) {
859
+ if (parts.length === 2) {
860
+ const providers = listProviders({ agentDir: configRoot() });
861
+ const models = [];
862
+ for (const p of providers) {
863
+ for (const m of p.models) {
864
+ const ref = `${p.name}/${m.id}`;
865
+ const desc = [
866
+ p.isPrivate ? "private" : "public",
867
+ m.reasoning ? "reasoning" : null,
868
+ m.input?.includes("image") ? "vision" : null,
869
+ ]
870
+ .filter(Boolean)
871
+ .join(", ");
872
+ models.push({ value: ref, description: `${m.name || m.id} [${desc}]` });
873
+ }
874
+ }
875
+ const target = parts[1].toLowerCase();
876
+ return models.filter((m) => m.value.toLowerCase().startsWith(target));
877
+ }
878
+ }
879
+
880
+ return null;
881
+ },
767
882
  handler: async (args, ctx) => {
768
883
  const cleanArgs = (args || "").trim();
769
884
  const parts = cleanArgs.split(/\s+/).filter(Boolean);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-config-crypt",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Universal cross-platform encrypted portability for omp config, extensions, and instructions",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -165,6 +165,7 @@ export function formatYamlModels(providers) {
165
165
  let out = "providers:\n";
166
166
  for (const [name, cfg] of Object.entries(providers || {})) {
167
167
  out += ` ${name}:\n`;
168
+ if (cfg.private) out += ` private: true\n`;
168
169
  if (cfg.baseUrl) out += ` baseUrl: ${cfg.baseUrl}\n`;
169
170
  if (cfg.api) out += ` api: ${cfg.api}\n`;
170
171
  if (cfg.apiKey) out += ` apiKey: ${cfg.apiKey}\n`;
@@ -257,6 +258,7 @@ export function saveProvider({
257
258
  }
258
259
 
259
260
  const cleanConfig = {
261
+ private: Boolean(isPrivate),
260
262
  baseUrl: providerConfig.baseUrl,
261
263
  api: providerConfig.api || "openai-completions",
262
264
  apiKey: providerConfig.apiKey || "",
@@ -264,26 +266,18 @@ export function saveProvider({
264
266
  models: Array.isArray(providerConfig.models) ? providerConfig.models : [],
265
267
  };
266
268
 
267
- const ompDir = getOmpDir(agentDir);
269
+ // Always save to models.yml so OMP /model natively sees and uses it
270
+ const pub = readPublicProviders(agentDir);
271
+ pub[name] = cleanConfig;
272
+ writePublicProviders(agentDir, pub);
268
273
 
274
+ // Also record in models.local.json for redundancy
269
275
  if (isPrivate) {
270
276
  const priv = readPrivateProviders(agentDir);
271
277
  priv[name] = cleanConfig;
272
278
  writePrivateProviders(agentDir, priv);
273
- ensureLocalExtension(ompDir);
274
-
275
- // If it existed in public, remove from public to prevent duplicate
276
- const pub = readPublicProviders(agentDir);
277
- if (pub[name]) {
278
- delete pub[name];
279
- writePublicProviders(agentDir, pub);
280
- }
279
+ ensureLocalExtension(getOmpDir(agentDir));
281
280
  } else {
282
- const pub = readPublicProviders(agentDir);
283
- pub[name] = cleanConfig;
284
- writePublicProviders(agentDir, pub);
285
-
286
- // If it existed in private, remove from private
287
281
  const priv = readPrivateProviders(agentDir);
288
282
  if (priv[name]) {
289
283
  delete priv[name];
@@ -323,22 +317,13 @@ export function removeProvider({ name, agentDir = getAgentDir() }) {
323
317
  export function listProviders({ agentDir = getAgentDir() } = {}) {
324
318
  const pub = readPublicProviders(agentDir);
325
319
  const priv = readPrivateProviders(agentDir);
320
+ const merged = { ...priv, ...pub };
326
321
 
327
322
  const list = [];
328
- for (const [name, cfg] of Object.entries(pub)) {
329
- list.push({
330
- name,
331
- isPrivate: false,
332
- baseUrl: cfg.baseUrl,
333
- api: cfg.api,
334
- apiKey: cfg.apiKey,
335
- models: cfg.models || [],
336
- });
337
- }
338
- for (const [name, cfg] of Object.entries(priv)) {
323
+ for (const [name, cfg] of Object.entries(merged)) {
339
324
  list.push({
340
325
  name,
341
- isPrivate: true,
326
+ isPrivate: Boolean(cfg.private || priv[name]),
342
327
  baseUrl: cfg.baseUrl,
343
328
  api: cfg.api,
344
329
  apiKey: cfg.apiKey,