offgrid-ai 0.14.3 → 0.15.1

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.3",
3
+ "version": "0.15.1",
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": [
@@ -4,9 +4,9 @@ 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
- import { modelSelectOption, modelNameWidth, printGgufModelDetails, printMlxModelDetails, printManagedModelDetails, printWorkspaceHeader, printBenchmarkLine, printProfileDetails } from "../model-presenters.mjs";
9
+ import { modelSelectOption, modelNameWidth, inferBackendId, formatSourceLabel, discoverySourceForItem, printGgufModelDetails, printMlxModelDetails, printManagedModelDetails, printWorkspaceHeader, printBenchmarkLine, printProfileDetails } from "../model-presenters.mjs";
10
10
  import { runProfile } from "./run.mjs";
11
11
 
12
12
  const { stripVTControlCharacters } = await import("node:util");
@@ -65,23 +65,47 @@ export async function modelCommandCenter(initialCatalog) {
65
65
  return "setup";
66
66
  };
67
67
 
68
- const groupOrder = ["running", "ready", "setup", "missing"];
69
- const grouped = new Map(groupOrder.map((key) => [key, []]));
70
- for (const item of allItems) grouped.get(statusFor(item)).push(item);
71
-
72
- const choices = [];
73
- for (const group of groupOrder) {
74
- const bucket = grouped.get(group);
75
- if (!bucket || bucket.length === 0) continue;
76
- for (const item of bucket) {
77
- const opt = modelSelectOption(item, { runningProfilesNow, modelMissingIds, nameWidth });
78
- choices.push({ value: opt.value, label: opt.label, hint: opt.hint });
68
+ // Group ready/running/missing profiles by backend, setup items separate
69
+ const byBackend = new Map();
70
+ const setupItems = [];
71
+ for (const item of allItems) {
72
+ const s = statusFor(item);
73
+ if (s === "setup") {
74
+ setupItems.push(item);
75
+ } else {
76
+ const backendId = inferBackendId(item);
77
+ const sourceId = discoverySourceForItem(item) ?? "unknown";
78
+ const key = `${backendId}:${sourceId}`;
79
+ if (!byBackend.has(key)) byBackend.set(key, { backendId, sourceId, items: [] });
80
+ byBackend.get(key).items.push(item);
79
81
  }
80
82
  }
81
83
 
84
+ const groups = [];
85
+ for (const { backendId, sourceId, items } of byBackend.values()) {
86
+ const backendLabel = backendFor(backendId)?.label ?? backendId;
87
+ const sourceLabel = formatSourceLabel(sourceId);
88
+ const sep = sourceLabel && sourceLabel !== backendLabel
89
+ ? `${backendLabel} · ${sourceLabel} (${items.length})`
90
+ : `${backendLabel} (${items.length})`;
91
+ const groupItems = items.map((item) => {
92
+ const opt = modelSelectOption(item, { runningProfilesNow, modelMissingIds, nameWidth, compact: true });
93
+ return { value: opt.value, label: opt.label, description: opt.description };
94
+ });
95
+ groups.push({ separator: ` ${sep}`, items: groupItems });
96
+ }
97
+
98
+ if (setupItems.length > 0) {
99
+ const groupItems = setupItems.map((item) => {
100
+ const opt = modelSelectOption(item, { runningProfilesNow, modelMissingIds, nameWidth, compact: true });
101
+ return { value: opt.value, label: opt.label, description: opt.description };
102
+ });
103
+ groups.push({ separator: ` Needs setup (${setupItems.length})`, items: groupItems });
104
+ }
105
+
82
106
  const prompt = createPrompt();
83
107
  try {
84
- const selected = await prompt.choice("Select a model", choices);
108
+ const selected = await modelSelect("Select a model", groups, { pageSize: 20 });
85
109
  if (!selected) return;
86
110
  const item = allItems.find((candidate) => itemKey(candidate) === selected);
87
111
  if (!item) return;
@@ -62,7 +62,7 @@ function optionBackendTag(backendId) {
62
62
  return optionPad(label, colors[backendId] ?? pc.dim, OPTION_BACKEND_WIDTH);
63
63
  }
64
64
 
65
- function formatSourceLabel(sourceId) {
65
+ export function formatSourceLabel(sourceId) {
66
66
  if (!sourceId) return "unknown";
67
67
  const map = {
68
68
  huggingface: "HuggingFace",
@@ -95,7 +95,7 @@ function discoverySourceForProfile(profile) {
95
95
  return inferSourceFromPath(profile.modelPath);
96
96
  }
97
97
 
98
- function discoverySourceForItem(item) {
98
+ export function discoverySourceForItem(item) {
99
99
  if (item.type === "profile") return discoverySourceForProfile(item.profile);
100
100
  return item.model?.source ?? null;
101
101
  }
@@ -132,9 +132,10 @@ function optionLabel({ status, backend, source, name, quant, ctx, size, nameWidt
132
132
  return [status, backend, source, pc.bold(optionPad(name, null, nameWidth)), quant, ctx, pc.dim(size)].join(OPTION_SEPARATOR);
133
133
  }
134
134
 
135
- export function modelSelectOption(item, { runningProfilesNow, modelMissingIds, nameWidth }) {
135
+ export function modelSelectOption(item, { runningProfilesNow, modelMissingIds, nameWidth, compact = false }) {
136
136
  const sourceId = discoverySourceForItem(item) ?? "unknown";
137
137
  const backendId = inferBackendId(item);
138
+
138
139
  if (item.type === "profile") {
139
140
  const backend = backendFor(item.profile.backend);
140
141
  const running = runningProfilesNow.some((profile) => profile.id === item.profile.id);
@@ -144,6 +145,16 @@ export function modelSelectOption(item, { runningProfilesNow, modelMissingIds, n
144
145
  const hint = drafterMissing ? "MTP drafter missing — reconfigure"
145
146
  : modelMissing ? `${backend.label} model no longer available`
146
147
  : undefined;
148
+
149
+ if (compact) {
150
+ const indicator = status === "running" ? pc.green("●") : status === "missing" ? pc.red("✗") : pc.dim("○");
151
+ return {
152
+ value: itemKey(item),
153
+ label: [indicator, pc.bold(optionPad(item.label, null, nameWidth)), optionQuantLabel(item), optionCtxLabel(item), pc.dim(optionSizeLabel(item))].join(OPTION_SEPARATOR),
154
+ ...(hint ? { description: pc.red(hint) } : {}),
155
+ };
156
+ }
157
+
147
158
  return {
148
159
  value: itemKey(item),
149
160
  label: optionLabel({
@@ -159,6 +170,17 @@ export function modelSelectOption(item, { runningProfilesNow, modelMissingIds, n
159
170
  ...(hint ? { hint: pc.red(hint) } : {}),
160
171
  };
161
172
  }
173
+
174
+ // Setup item (new model or managed without profile)
175
+ if (compact) {
176
+ const backendLabel = backendFor(backendId)?.label ?? backendId;
177
+ const full = `${item.label} · ${backendLabel}`;
178
+ return {
179
+ value: itemKey(item),
180
+ label: [pc.yellow(pc.bold(optionPad(full, null, nameWidth))), optionQuantLabel(item), optionCtxLabel(item), pc.dim(optionSizeLabel(item))].join(OPTION_SEPARATOR),
181
+ };
182
+ }
183
+
162
184
  return {
163
185
  value: itemKey(item),
164
186
  label: optionLabel({
@@ -174,7 +196,7 @@ export function modelSelectOption(item, { runningProfilesNow, modelMissingIds, n
174
196
  };
175
197
  }
176
198
 
177
- function inferBackendId(item) {
199
+ export function inferBackendId(item) {
178
200
  if (item.type === "profile") return item.profile.backend;
179
201
  if (item.type === "managed") return item.backendId;
180
202
  // new model: derive from format
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
+ }