offgrid-ai 0.14.2 → 0.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "offgrid-ai",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
4
4
  "description": "Privacy-first CLI for running local LLMs — discover, configure, run, benchmark",
5
5
  "author": "Eeshan Srivastava (https://eeshans.com)",
6
6
  "type": "module",
@@ -42,10 +42,10 @@
42
42
  "pretest": "npm run lint"
43
43
  },
44
44
  "dependencies": {
45
- "@clack/prompts": "^1.4.0",
46
45
  "@earendil-works/pi-agent-core": "^0.80.3",
47
46
  "@earendil-works/pi-ai": "^0.80.3",
48
47
  "@earendil-works/pi-coding-agent": "^0.80.3",
48
+ "@inquirer/prompts": "^8.5.2",
49
49
  "picocolors": "^1.1.0"
50
50
  },
51
51
  "keywords": [
package/src/backends.mjs CHANGED
@@ -99,21 +99,25 @@ async function scanOmlxModels() {
99
99
  // The oMLX API doesn't return model sizes or publishers — look them up from disk.
100
100
  const infoMap = await scanOmlxModelSizes();
101
101
 
102
- // The oMLX API can return the same model twice once loaded (with
103
- // max_model_len) and once available (without). Deduplicate by ID,
104
- // keeping the entry with context window info.
105
- const byId = new Map();
102
+ // The oMLX API can return the same model multiple times with different
103
+ // ID formats (e.g. "Qwen3.6-35B-A3B-OptiQ-4bit" and
104
+ // "mlx-community--Qwen3.6-35B-A3B-OptiQ-4bit"). Deduplicate by the
105
+ // normalized full name (publisher/model), keeping the first entry
106
+ // (which has the most complete metadata from the loaded model).
107
+ const seen = new Set();
108
+ const deduped = [];
106
109
  for (const model of body.data.filter(isChatOmlxModel)) {
107
- const existing = byId.get(model.id);
108
- if (existing && existing.max_model_len) continue; // keep loaded entry
109
- byId.set(model.id, model);
110
+ const info = lookupOmlxModelInfo(model.id, infoMap);
111
+ const hasPublisher = model.id.includes("/") || model.id.includes("--");
112
+ const fullName = (!hasPublisher && info?.publisher) ? `${info.publisher}/${model.id}` : model.id;
113
+ if (seen.has(fullName)) continue;
114
+ seen.add(fullName);
115
+ deduped.push(model);
110
116
  }
111
117
 
112
- return Array.from(byId.values())
118
+ return deduped
113
119
  .map((model) => {
114
120
  const info = lookupOmlxModelInfo(model.id, infoMap);
115
- // If the API ID doesn't already include a publisher (no / or --),
116
- // prepend the publisher found on disk.
117
121
  const hasPublisher = model.id.includes("/") || model.id.includes("--");
118
122
  const fullName = (!hasPublisher && info?.publisher) ? `${info.publisher}/${model.id}` : model.id;
119
123
  const parsed = parseModelName(fullName, "omlx");
@@ -4,7 +4,7 @@ import { createProfileFromModel, readProfile, saveProfile, deleteProfile, profil
4
4
  import { isProfileRunning, isProfileServerUp, modelAvailableOnServer, stopProfile } from "../process.mjs";
5
5
  import { syncPiConfig, removeFromPiConfig } from "../harness-pi.mjs";
6
6
  import { configureLocalProfile } from "../profile-setup.mjs";
7
- import { pc, startInteractive, createPrompt } from "../ui.mjs";
7
+ import { pc, startInteractive, createPrompt, modelSelect } from "../ui.mjs";
8
8
  import { buildCatalogItems, createManagedProfile, itemKey, loadModelCatalog, normalizeCatalog } from "../model-catalog.mjs";
9
9
  import { modelSelectOption, modelNameWidth, printGgufModelDetails, printMlxModelDetails, printManagedModelDetails, printWorkspaceHeader, printBenchmarkLine, printProfileDetails } from "../model-presenters.mjs";
10
10
  import { runProfile } from "./run.mjs";
@@ -66,22 +66,29 @@ export async function modelCommandCenter(initialCatalog) {
66
66
  };
67
67
 
68
68
  const groupOrder = ["running", "ready", "setup", "missing"];
69
+ const groupLabels = {
70
+ running: "Running now",
71
+ ready: "Ready",
72
+ setup: "Needs setup",
73
+ missing: "Missing files",
74
+ };
69
75
  const grouped = new Map(groupOrder.map((key) => [key, []]));
70
76
  for (const item of allItems) grouped.get(statusFor(item)).push(item);
71
77
 
72
- const choices = [];
78
+ const groups = [];
73
79
  for (const group of groupOrder) {
74
80
  const bucket = grouped.get(group);
75
81
  if (!bucket || bucket.length === 0) continue;
76
- for (const item of bucket) {
82
+ const items = bucket.map((item) => {
77
83
  const opt = modelSelectOption(item, { runningProfilesNow, modelMissingIds, nameWidth });
78
- choices.push({ value: opt.value, label: opt.label, hint: opt.hint });
79
- }
84
+ return { value: opt.value, label: opt.label, description: opt.hint };
85
+ });
86
+ groups.push({ separator: ` ${groupLabels[group]} (${bucket.length})`, items });
80
87
  }
81
88
 
82
89
  const prompt = createPrompt();
83
90
  try {
84
- const selected = await prompt.choice("Select a model", choices);
91
+ const selected = await modelSelect("Select a model", groups, { pageSize: 20 });
85
92
  if (!selected) return;
86
93
  const item = allItems.find((candidate) => itemKey(candidate) === selected);
87
94
  if (!item) return;
package/src/ui.mjs CHANGED
@@ -1,8 +1,12 @@
1
- import { box, cancel, confirm, intro, isCancel, select, text } from "@clack/prompts";
1
+ import { select as inquirerSelect, input, confirm, number, Separator } from "@inquirer/prompts";
2
2
  import pc from "picocolors";
3
3
  import { stripVTControlCharacters } from "node:util";
4
4
 
5
5
  export { pc };
6
+ export { Separator };
7
+
8
+ // ── Formatting helpers (no prompt dependency) ───────────────────────────────
9
+
6
10
  export function formatBytes(bytes) {
7
11
  if (!Number.isFinite(bytes)) return "unknown";
8
12
  const units = ["B", "KB", "MB", "GB", "TB"];
@@ -12,42 +16,6 @@ export function formatBytes(bytes) {
12
16
  return `${size.toFixed(unit === 0 ? 0 : 2)} ${units[unit]}`;
13
17
  }
14
18
 
15
- export function startInteractive(title = "offgrid-ai") {
16
- if (process.stdin.isTTY) console.clear();
17
- intro(title);
18
- }
19
-
20
- export function createPrompt() {
21
- return {
22
- async text(label, defaultValue) {
23
- const value = await text({ message: label, initialValue: defaultValue === undefined ? undefined : String(defaultValue) });
24
- return handleCancel(value)?.trim() || String(defaultValue ?? "");
25
- },
26
- async number(label, defaultValue, min, max) {
27
- const value = await text({
28
- message: label, initialValue: String(defaultValue),
29
- validate(input) { const n = Number(input); if (!Number.isFinite(n) || n < min || n > max) return `Enter a number from ${min} to ${max}.`; },
30
- });
31
- return Number(handleCancel(value));
32
- },
33
- async yesNo(label, defaultValue) {
34
- return handleCancel(await confirm({ message: label, initialValue: defaultValue }));
35
- },
36
- async choice(label, choices, defaultValue) {
37
- return handleCancel(await select({
38
- message: label, initialValue: defaultValue,
39
- options: choices.map((c) => ({ value: c.value, label: c.label ?? c.value, hint: c.hint, disabled: c.disabled })),
40
- }));
41
- },
42
- close() {},
43
- };
44
- }
45
-
46
- function handleCancel(value) {
47
- if (isCancel(value)) { cancel("Cancelled."); process.exit(0); }
48
- return value;
49
- }
50
-
51
19
  export function renderRows(rows) {
52
20
  if (rows.length === 0) return "";
53
21
  const width = Math.max(...rows.map(([key]) => stripVTControlCharacters(String(key)).length));
@@ -57,26 +25,45 @@ export function renderRows(rows) {
57
25
  }).join("\n");
58
26
  }
59
27
 
28
+ // ── Box renderer ────────────────────────────────────────────────────────────
29
+
30
+ function visibleLen(text) {
31
+ return stripVTControlCharacters(String(text)).length;
32
+ }
33
+
34
+ function padVisible(text, width) {
35
+ const pad = Math.max(0, width - visibleLen(text));
36
+ return text + " ".repeat(pad);
37
+ }
38
+
60
39
  export function renderCard(title, body, options = {}) {
61
- let output = "";
62
- box(String(body ?? ""), title, {
63
- output: captureOutput((chunk) => { output += chunk; }, options.columns),
64
- withGuide: false,
65
- width: "auto",
66
- contentPadding: options.contentPadding ?? 1,
67
- titlePadding: options.titlePadding ?? 1,
68
- rounded: options.rounded ?? true,
69
- titleAlign: options.titleAlign ?? "left",
70
- contentAlign: options.contentAlign ?? "left",
71
- formatBorder: options.formatBorder ?? pc.magenta,
72
- });
73
- return output.trimEnd();
40
+ const borderColor = options.formatBorder ?? pc.magenta;
41
+ const maxCols = options.columns ?? process.stdout.columns ?? 88;
42
+ const lines = String(body ?? "").split("\n");
43
+ const titleStr = title ? ` ${title} ` : "";
44
+ const innerWidth = Math.max(
45
+ visibleLen(titleStr),
46
+ ...lines.map(visibleLen),
47
+ );
48
+ const width = Math.min(innerWidth + 2, maxCols - 2);
49
+
50
+ const topTitle = title ? `╭${pc.reset(titleStr)}` : "╭";
51
+ const topFill = "─".repeat(Math.max(0, width + 2 - visibleLen(titleStr)));
52
+ const top = `${topTitle}${topFill}╮`;
53
+
54
+ const middle = lines.map((line) => `│ ${padVisible(line, width)} │`);
55
+
56
+ const bottom = `╰${"─".repeat(width + 2)}╯`;
57
+
58
+ return [top, ...middle, bottom].map((l) => borderColor(l)).join("\n");
74
59
  }
75
60
 
76
61
  export function renderSection(title, body, options = {}) {
77
62
  return renderCard(title, body, { formatBorder: pc.magenta, ...options });
78
63
  }
79
64
 
65
+ // ── Status / capability helpers ─────────────────────────────────────────────
66
+
80
67
  export function humanCapabilitySummary(caps = {}) {
81
68
  const parts = [];
82
69
  if (caps.thinking) parts.push(pc.magenta("Reasoning"));
@@ -97,13 +84,93 @@ export function statusText(kind, text) {
97
84
  return color(text);
98
85
  }
99
86
 
100
- function captureOutput(write, columns) {
87
+ // ── Interactive prompt factory ──────────────────────────────────────────────
88
+
89
+ export function startInteractive(title = "offgrid-ai") {
90
+ if (process.stdin.isTTY) console.clear();
91
+ console.log(pc.magenta(`◆ ${title}`));
92
+ }
93
+
94
+ export function createPrompt() {
101
95
  return {
102
- columns: Math.min(columns ?? process.stdout.columns ?? 88, 120),
103
- write,
96
+ async text(label, defaultValue) {
97
+ const value = await input({
98
+ message: label,
99
+ default: defaultValue === undefined ? undefined : String(defaultValue),
100
+ });
101
+ return value?.trim() || String(defaultValue ?? "");
102
+ },
103
+
104
+ async number(label, defaultValue, min, max) {
105
+ const value = await number({
106
+ message: label,
107
+ default: defaultValue,
108
+ validate(input) {
109
+ if (!Number.isFinite(input) || input < min || input > max) {
110
+ return `Enter a number from ${min} to ${max}.`;
111
+ }
112
+ },
113
+ });
114
+ return Number(value);
115
+ },
116
+
117
+ async yesNo(label, defaultValue) {
118
+ return await confirm({ message: label, default: defaultValue });
119
+ },
120
+
121
+ async choice(label, choices, defaultValue) {
122
+ const mapped = choices.map((c) => {
123
+ if (c instanceof Separator) return c;
124
+ return {
125
+ value: c.value,
126
+ name: c.label ?? c.value,
127
+ description: c.hint,
128
+ disabled: c.disabled || undefined,
129
+ };
130
+ });
131
+ return await inquirerSelect({
132
+ message: label,
133
+ default: defaultValue,
134
+ choices: mapped,
135
+ pageSize: 20,
136
+ });
137
+ },
138
+
139
+ close() {},
104
140
  };
105
141
  }
106
142
 
143
+ // ── Model picker with grouped select ────────────────────────────────────────
144
+
145
+ export async function modelSelect(label, groups, { defaultKey, pageSize = 20 } = {}) {
146
+ const choices = [];
147
+ for (const group of groups) {
148
+ if (group.separator) {
149
+ choices.push(new Separator(group.separator));
150
+ }
151
+ for (const item of group.items) {
152
+ if (item.separator) {
153
+ choices.push(new Separator(item.separator));
154
+ continue;
155
+ }
156
+ choices.push({
157
+ value: item.value,
158
+ name: item.label ?? item.value,
159
+ description: item.description,
160
+ disabled: item.disabled || undefined,
161
+ });
162
+ }
163
+ }
164
+ return await inquirerSelect({
165
+ message: label,
166
+ default: defaultKey,
167
+ choices,
168
+ pageSize,
169
+ });
170
+ }
171
+
172
+ // ── Option parsing (no prompt dependency) ────────────────────────────────────
173
+
107
174
  export function parseOptions(argv) {
108
175
  const positional = [];
109
176
  const options = {};
@@ -126,4 +193,4 @@ export function parseOptions(argv) {
126
193
  }
127
194
  }
128
195
  return { positional, options };
129
- }
196
+ }