usegrunt 0.5.0 → 0.6.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/README.md +67 -9
- package/dist/local/api.js +24 -10
- package/dist/local/banner.js +136 -0
- package/dist/local/fallback-setup.js +2 -1
- package/dist/local/freebuff-tools.js +112 -0
- package/dist/local/freebuff.js +41 -9
- package/dist/local/freellmapi.js +2 -1
- package/dist/local/harnesses.js +164 -0
- package/dist/local/main.js +9 -4
- package/dist/local/routing.js +2 -1
- package/dist/local/source.js +6 -0
- package/dist/local/wizard.js +273 -88
- package/package.json +2 -1
package/dist/local/wizard.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { promisify } from 'node:util';
|
|
2
2
|
import { spawn, execFile } from 'node:child_process';
|
|
3
|
-
import { mkdir, readFile, writeFile,
|
|
3
|
+
import { mkdir, readFile, writeFile, cp, mkdtemp, rm, access } from 'node:fs/promises';
|
|
4
4
|
import { homedir, tmpdir } from 'node:os';
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
7
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
|
-
import { intro, outro, spinner, log } from '@clack/prompts';
|
|
8
|
+
import { intro, outro, spinner, log, note, multiselect, isCancel } from '@clack/prompts';
|
|
9
9
|
import chalk from 'chalk';
|
|
10
10
|
import { setupFallbacks } from './fallback-setup.js';
|
|
11
|
+
import { DOCTOR_TIMEOUT_MS } from './freebuff.js';
|
|
11
12
|
import { BrowserSquire, PROVIDERS, setup, squireEnvironment } from './setup.js';
|
|
12
13
|
import { RegistrySync } from './registry.js';
|
|
13
14
|
import { bundledRegistry, knownAdapters } from '../registry.js';
|
|
15
|
+
import { banner } from './banner.js';
|
|
16
|
+
import { HARNESSES, configurePi, connectHarness, detectHarnesses } from './harnesses.js';
|
|
14
17
|
export const configDir = (env = process.env) => env.MILO_CONFIG_DIR || join(env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'milo');
|
|
15
18
|
export async function command(binary, args, interactive = false, signal) {
|
|
16
19
|
await new Promise((resolve, reject) => {
|
|
@@ -19,37 +22,51 @@ export async function command(binary, args, interactive = false, signal) {
|
|
|
19
22
|
child.once('exit', code => code === 0 ? resolve() : reject(new Error(`${binary} failed; inspect its service status before retrying`)));
|
|
20
23
|
});
|
|
21
24
|
}
|
|
22
|
-
async function step(label, task) {
|
|
25
|
+
async function step(label, task, done = () => label) {
|
|
23
26
|
const progress = spinner();
|
|
24
27
|
progress.start(label);
|
|
25
28
|
try {
|
|
26
29
|
const result = await task();
|
|
27
|
-
progress.stop(
|
|
30
|
+
progress.stop(done(result));
|
|
28
31
|
return result;
|
|
29
32
|
}
|
|
30
33
|
catch (error) {
|
|
31
|
-
progress.
|
|
34
|
+
progress.error(`${label} failed`);
|
|
32
35
|
throw error;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
|
-
export async function
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
+
export async function squireBrokerExists() {
|
|
39
|
+
const service = process.platform === 'darwin'
|
|
40
|
+
? ['launchctl', ['print', `gui/${process.getuid()}/ai.trustysquire.trusty-squire-broker`]]
|
|
41
|
+
: ['systemctl', ['--user', 'is-active', 'trusty-squire-broker']];
|
|
42
|
+
try {
|
|
43
|
+
await promisify(execFile)(service[0], [...service[1]], { timeout: 10000 });
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch { /* An inactive service can still own the broker installation. */ }
|
|
47
|
+
if (process.platform === 'linux') {
|
|
48
|
+
try {
|
|
49
|
+
const { stdout } = await promisify(execFile)('systemctl', ['--user', 'list-unit-files', 'trusty-squire-broker*.service', '--no-legend', '--no-pager'], { timeout: 10000 });
|
|
50
|
+
if (/^trusty-squire-broker\S*\.service\s/m.test(stdout))
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch { /* Socket discovery remains available without a service manager. */ }
|
|
54
|
+
}
|
|
55
|
+
const home = homedir();
|
|
56
|
+
const serviceFile = process.platform === 'darwin'
|
|
57
|
+
? join(home, 'Library', 'LaunchAgents', 'ai.trustysquire.trusty-squire-broker.plist')
|
|
58
|
+
: join(process.env.XDG_CONFIG_HOME || join(home, '.config'), 'systemd', 'user', 'trusty-squire-broker.service');
|
|
59
|
+
try {
|
|
60
|
+
await access(serviceFile);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch { /* Check socket discovery too. */ }
|
|
64
|
+
const discovery = join(dirname(fileURLToPath(import.meta.resolve('@trusty-squire/mcp'))), 'bot/broker/discovery.js');
|
|
65
|
+
const program = `const {brokerSocketPath} = await import(${JSON.stringify(pathToFileURL(discovery).href)}); const {existsSync} = await import('node:fs'); process.stdout.write(existsSync(brokerSocketPath()) ? 'present' : 'missing');`;
|
|
38
66
|
const result = await promisify(execFile)(process.execPath, ['--input-type=module', '-e', program], { env: squireEnvironment(), timeout: 10000 });
|
|
39
67
|
return result.stdout === 'present';
|
|
40
68
|
}
|
|
41
69
|
export async function connectSquire(options = {}) {
|
|
42
|
-
const run = options.run || command;
|
|
43
|
-
const install = async () => {
|
|
44
|
-
if (process.env.MILO_SETUP_NO_HUMAN === '1')
|
|
45
|
-
throw new Error('Squire login needs human verification; stopped before onboarding');
|
|
46
|
-
// The bundled installer owns account creation and broker service installation.
|
|
47
|
-
const bin = options.installer || join(dirname(fileURLToPath(import.meta.resolve('@trusty-squire/mcp'))), 'bin.js');
|
|
48
|
-
await run(process.execPath, [bin, 'connect', '--target=opencode', '--json'], true);
|
|
49
|
-
};
|
|
50
|
-
const existing = await (options.hasSession || squireSessionExists)();
|
|
51
|
-
if (!existing)
|
|
52
|
-
await install();
|
|
53
70
|
const probe = async () => { const squire = new BrowserSquire(); try {
|
|
54
71
|
await squire.connect();
|
|
55
72
|
}
|
|
@@ -58,13 +75,19 @@ export async function connectSquire(options = {}) {
|
|
|
58
75
|
} };
|
|
59
76
|
try {
|
|
60
77
|
await probe();
|
|
78
|
+
return;
|
|
61
79
|
}
|
|
62
80
|
catch (error) {
|
|
63
|
-
if (
|
|
64
|
-
throw error;
|
|
65
|
-
|
|
66
|
-
await probe();
|
|
81
|
+
if (await (options.hasBroker || squireBrokerExists)()) {
|
|
82
|
+
throw new Error(`Existing trusty-squire-broker failed its connection probe: ${error instanceof Error ? error.message : String(error)}. Repair the broker, then rerun usegrunt setup.`, { cause: error });
|
|
83
|
+
}
|
|
67
84
|
}
|
|
85
|
+
if (process.env.MILO_SETUP_NO_HUMAN === '1')
|
|
86
|
+
throw new Error('Squire login needs human verification; stopped before onboarding');
|
|
87
|
+
// Only a machine without a broker may enter the installer.
|
|
88
|
+
const bin = options.installer || join(dirname(fileURLToPath(import.meta.resolve('@trusty-squire/mcp'))), 'bin.js');
|
|
89
|
+
await (options.run || command)(process.execPath, [bin, 'connect', '--target=opencode', '--json'], true);
|
|
90
|
+
await probe();
|
|
68
91
|
}
|
|
69
92
|
export async function preflight(run = command) {
|
|
70
93
|
const major = Number(process.versions.node.split('.')[0]);
|
|
@@ -102,27 +125,6 @@ export async function preflight(run = command) {
|
|
|
102
125
|
throw new Error('Start a normal user login with its systemd/launchd service manager, then run npx usegrunt setup.');
|
|
103
126
|
}
|
|
104
127
|
}
|
|
105
|
-
export async function configurePi(port = 8788) {
|
|
106
|
-
const directory = process.env.PI_CODING_AGENT_DIR || join(homedir(), '.pi', 'agent');
|
|
107
|
-
const path = join(directory, 'models.json');
|
|
108
|
-
let saved = {};
|
|
109
|
-
try {
|
|
110
|
-
saved = JSON.parse(await readFile(path, 'utf8'));
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
if (error.code !== 'ENOENT')
|
|
114
|
-
throw new Error('Cannot read Pi models config; repair it before retrying setup');
|
|
115
|
-
}
|
|
116
|
-
if (!saved || typeof saved !== 'object' || Array.isArray(saved) || (saved.providers !== undefined && (!saved.providers || typeof saved.providers !== 'object' || Array.isArray(saved.providers))))
|
|
117
|
-
throw new Error('Invalid Pi models config');
|
|
118
|
-
const providers = (saved.providers ?? {});
|
|
119
|
-
providers.grunt = { baseUrl: `http://127.0.0.1:${port}/v1`, api: 'openai-completions', apiKey: 'local',
|
|
120
|
-
models: [{ id: 'grunt', name: 'grunt', reasoning: false, input: ['text'], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 128000, maxTokens: 4096 }] };
|
|
121
|
-
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
122
|
-
const temporary = `${path}.${process.pid}.tmp`;
|
|
123
|
-
await writeFile(temporary, JSON.stringify({ ...saved, providers }, null, 2) + '\n', { mode: 0o600, flag: 'wx' });
|
|
124
|
-
await rename(temporary, path);
|
|
125
|
-
}
|
|
126
128
|
const systemdQuote = (value) => '"' + value.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('%', '%%').replaceAll('$', '$$').replaceAll('\n', '\\n') + '"';
|
|
127
129
|
const xml = (value) => value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
128
130
|
export async function installService() {
|
|
@@ -172,23 +174,60 @@ export async function installBackgroundService(name, entry, env) {
|
|
|
172
174
|
await command('launchctl', ['bootstrap', domain, plist]);
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
// /v1/models asks every source whether it is available, and Freebuff runs `freebuff doctor` to answer.
|
|
178
|
+
// Give each probe longer than that check, and stop after totalMs so a hung service still fails.
|
|
179
|
+
export async function checkService(port = 8788, totalMs = 90000) {
|
|
180
|
+
const deadline = Date.now() + totalMs;
|
|
181
|
+
while (Date.now() < deadline) {
|
|
182
|
+
const timeout = Math.max(1, Math.min(DOCTOR_TIMEOUT_MS + 5000, deadline - Date.now()));
|
|
178
183
|
try {
|
|
179
|
-
const response = await fetch(`http://127.0.0.1:${port}/v1/models`, { signal: AbortSignal.timeout(
|
|
180
|
-
if (response.ok)
|
|
181
|
-
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
+
const response = await fetch(`http://127.0.0.1:${port}/v1/models`, { signal: AbortSignal.timeout(timeout) });
|
|
185
|
+
if (response.ok)
|
|
186
|
+
return;
|
|
184
187
|
}
|
|
185
188
|
catch { /* Wait for the service manager. */ }
|
|
186
|
-
await delay(1000);
|
|
189
|
+
await delay(Math.max(0, Math.min(1000, deadline - Date.now())));
|
|
190
|
+
}
|
|
191
|
+
throw new Error('grunt service did not start; inspect its service status');
|
|
192
|
+
}
|
|
193
|
+
const systemctl = async (args) => (await promisify(execFile)('systemctl', ['--user', ...args], { timeout: 10000 })).stdout;
|
|
194
|
+
// Read MILO_SOURCES as systemd applies it, including drop-ins, and name the file that set it.
|
|
195
|
+
export async function serviceSources(run = systemctl, name = 'milo') {
|
|
196
|
+
if (run === systemctl && process.platform !== 'linux')
|
|
197
|
+
return;
|
|
198
|
+
let environment, dropIns;
|
|
199
|
+
try {
|
|
200
|
+
[environment, dropIns] = await Promise.all(['Environment', 'DropInPaths'].map(property => run(['show', `${name}.service`, '-p', property, '--value'])));
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const value = environment.match(/(?:^|\s)"?MILO_SOURCES=([^\s"]*)/)?.[1];
|
|
206
|
+
if (value === undefined)
|
|
207
|
+
return;
|
|
208
|
+
let origin = `${name}.service`;
|
|
209
|
+
for (const path of dropIns.trim().split(/\s+/).filter(Boolean)) {
|
|
210
|
+
try {
|
|
211
|
+
if (/^\s*Environment=.*MILO_SOURCES=/m.test(await readFile(path, 'utf8')))
|
|
212
|
+
origin = path;
|
|
213
|
+
}
|
|
214
|
+
catch { /* An unreadable drop-in cannot be named. */ }
|
|
215
|
+
}
|
|
216
|
+
return { sources: value.split(',').map(id => id.trim()), origin };
|
|
217
|
+
}
|
|
218
|
+
export async function checkServiceSources(unavailable, notify = console.log, adapters = ['freebuff', 'opencode'], read = serviceSources) {
|
|
219
|
+
const unit = await read();
|
|
220
|
+
if (!unit)
|
|
221
|
+
return;
|
|
222
|
+
for (const id of adapters) {
|
|
223
|
+
if (unit.sources.includes(id))
|
|
224
|
+
continue;
|
|
225
|
+
if (!unavailable.includes(id))
|
|
226
|
+
unavailable.push(id);
|
|
227
|
+
notify(`${id}: FAIL — ${unit.origin} sets MILO_SOURCES=${unit.sources.join(',')}, which lacks ${id}. Setup does not edit it; add ${id} there or remove that setting.`);
|
|
187
228
|
}
|
|
188
|
-
if (!ready)
|
|
189
|
-
throw new Error('grunt service did not start; inspect its service status');
|
|
190
229
|
}
|
|
191
|
-
export async function checkFallbackServices(unavailable, port = 8788, notify = console.log, adapters = ['freebuff', 'opencode']) {
|
|
230
|
+
export async function checkFallbackServices(unavailable, port = 8788, notify = console.log, adapters = ['freebuff', 'opencode'], wait = { limit: 180000, interval: 2000 }) {
|
|
192
231
|
const directory = await mkdtemp(join(tmpdir(), 'milo-free-check-'));
|
|
193
232
|
try {
|
|
194
233
|
for (const source of adapters) {
|
|
@@ -196,63 +235,209 @@ export async function checkFallbackServices(unavailable, port = 8788, notify = c
|
|
|
196
235
|
notify(`${source}: FAIL — setup incomplete`);
|
|
197
236
|
continue;
|
|
198
237
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
238
|
+
const deadline = Date.now() + wait.limit;
|
|
239
|
+
let failure, waiting = false;
|
|
240
|
+
for (let attempt = 1;; attempt++) {
|
|
241
|
+
let preparing = false;
|
|
242
|
+
try {
|
|
243
|
+
const response = await fetch(`http://127.0.0.1:${port}/v1/chat/completions`, {
|
|
244
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
245
|
+
body: JSON.stringify({ model: source, cwd: directory, messages: [{ role: 'user', content: `Reply only: grunt is ready (${source}). Do not use tools or change files. Check ${attempt}.` }], stream: false, max_tokens: 256 }),
|
|
246
|
+
signal: AbortSignal.timeout(120000)
|
|
247
|
+
});
|
|
248
|
+
preparing = response.headers.get('x-grunt-preparing')?.split(',').includes(source) ?? false;
|
|
249
|
+
const answered = response.headers.get('x-grunt-source');
|
|
250
|
+
const result = await response.json().catch(() => ({}));
|
|
251
|
+
if (!response.ok)
|
|
252
|
+
failure = `grunt returned HTTP ${response.status}`;
|
|
253
|
+
else if (answered !== source)
|
|
254
|
+
failure = `${answered ?? 'an unnamed source'} answered instead of ${source}`;
|
|
255
|
+
else if (!result.choices?.[0]?.message?.content?.trim())
|
|
256
|
+
failure = 'no text returned';
|
|
257
|
+
else
|
|
258
|
+
failure = undefined;
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
failure = 'grunt did not answer';
|
|
262
|
+
}
|
|
263
|
+
// Retry only while grunt still runs this adapter's background setup. Each attempt
|
|
264
|
+
// is a new prompt, so the router does not keep a fallback source from an earlier try.
|
|
265
|
+
if (!failure || !preparing || Date.now() + wait.interval > deadline)
|
|
266
|
+
break;
|
|
267
|
+
if (!waiting) {
|
|
268
|
+
waiting = true;
|
|
269
|
+
notify(`${source}: grunt is still preparing this adapter; waiting`);
|
|
270
|
+
}
|
|
271
|
+
await delay(wait.interval);
|
|
211
272
|
}
|
|
212
|
-
|
|
273
|
+
if (failure) {
|
|
213
274
|
unavailable.push(source);
|
|
214
|
-
notify(`${source}:
|
|
275
|
+
notify(`${source}: FAIL — ${failure}`);
|
|
215
276
|
}
|
|
277
|
+
else
|
|
278
|
+
notify(`${source}: PASS — ${source} answered through the grunt service`);
|
|
216
279
|
}
|
|
217
280
|
}
|
|
218
281
|
finally {
|
|
219
282
|
await rm(directory, { recursive: true, force: true });
|
|
220
283
|
}
|
|
221
284
|
}
|
|
222
|
-
export
|
|
223
|
-
|
|
285
|
+
export { configurePi };
|
|
286
|
+
// Same URL and validation as the daemon's RegistrySync; says where the list came from.
|
|
287
|
+
export async function loadRegistry(options = {}) {
|
|
288
|
+
let offline = false, cached = false;
|
|
289
|
+
const registry = new RegistrySync({ directory: configDir(), ...options, notify: () => { offline = true; } });
|
|
224
290
|
try {
|
|
225
291
|
await registry.load();
|
|
292
|
+
cached = registry.current.published !== bundledRegistry.published || JSON.stringify(registry.current) !== JSON.stringify(bundledRegistry);
|
|
226
293
|
await registry.sync();
|
|
227
|
-
return registry.current;
|
|
294
|
+
return { registry: registry.current, origin: (offline ? cached ? 'cache' : 'bundled' : 'remote') };
|
|
228
295
|
}
|
|
229
296
|
finally {
|
|
230
297
|
await registry.close();
|
|
231
298
|
}
|
|
232
299
|
}
|
|
233
|
-
const
|
|
300
|
+
const PREAMBLE = [
|
|
301
|
+
'usegrunt installs grunt, a small daemon that runs on this machine.',
|
|
302
|
+
'It pools the free AI inference quota offered by many services and serves',
|
|
303
|
+
'it as one agent at a local address. Your coding tools talk to grunt; grunt',
|
|
304
|
+
'sends each request to a free service that can answer it.',
|
|
305
|
+
'',
|
|
306
|
+
'Setup will:',
|
|
307
|
+
' 1. Connect Trusty Squire (one Google sign-in)',
|
|
308
|
+
' 2. Pull the current list of free services from the grunt registry',
|
|
309
|
+
' 3. Sign up for each service, connect it to grunt and test it',
|
|
310
|
+
' 4. Connect grunt to the coding tools installed here'
|
|
311
|
+
].join('\n');
|
|
312
|
+
const SQUIRE_NOTICE = [
|
|
313
|
+
'Some free services only work with an account. Trusty Squire is a local',
|
|
314
|
+
'browser helper that signs up for them for you using Google sign-in (OAuth).',
|
|
315
|
+
'',
|
|
316
|
+
'Next, a browser may open and ask you to sign in to Google once. If Trusty',
|
|
317
|
+
'Squire is already connected on this machine, setup reuses it. A captcha or',
|
|
318
|
+
'email check pauses setup until you finish it in the browser.'
|
|
319
|
+
].join('\n');
|
|
320
|
+
const mark = (status) => status === 'pass' ? chalk.green('✔') : status === 'fail' ? chalk.red('✘') : chalk.dim('–');
|
|
321
|
+
const describe = (adapter) => [adapter.kind === 'agent' ? 'coding agent' : 'model API', adapter.model ? `free model ${adapter.model}` : undefined,
|
|
322
|
+
adapter.signup ? `account at ${new URL(adapter.signup).host}` : 'no account needed until it asks'].filter(Boolean).join(' · ');
|
|
323
|
+
// Service lines name their result, so show PASS and FAIL as success and error.
|
|
324
|
+
const report = (shown = new Set()) => (line) => {
|
|
325
|
+
if (shown.has(line))
|
|
326
|
+
return;
|
|
327
|
+
shown.add(line);
|
|
328
|
+
if (/: PASS\b/.test(line))
|
|
329
|
+
log.success(line);
|
|
330
|
+
else if (/: FAIL\b/.test(line))
|
|
331
|
+
log.error(line);
|
|
332
|
+
else
|
|
333
|
+
log.info(line);
|
|
334
|
+
};
|
|
335
|
+
export async function connectHarnesses(port, options = {}) {
|
|
336
|
+
log.step('Connect grunt to your coding tools');
|
|
337
|
+
const found = await detectHarnesses(options.harnesses);
|
|
338
|
+
if (!found.length) {
|
|
339
|
+
log.warn(`No supported coding tool found on PATH (${HARNESSES.map(h => h.binary).join(', ')}). Install one, then rerun usegrunt setup.`);
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
log.info(`Found: ${found.map(h => h.name).join(', ')}. grunt is added as an extra, named option; your default model and provider stay as they are.`);
|
|
343
|
+
const interactive = process.stdin.isTTY && process.stdout.isTTY && process.env.MILO_SETUP_NO_HUMAN !== '1';
|
|
344
|
+
const choose = options.choose ?? (async (list) => {
|
|
345
|
+
if (!interactive)
|
|
346
|
+
return list.filter(h => h.id === 'pi');
|
|
347
|
+
const picked = await multiselect({ message: 'Connect grunt to which tools? (space toggles, enter confirms)', required: false,
|
|
348
|
+
options: list.map(h => ({ value: h.id, label: h.name, hint: h.launch(port) })), initialValues: list.filter(h => h.id === 'pi').map(h => h.id) });
|
|
349
|
+
return isCancel(picked) ? [] : list.filter(h => picked.includes(h.id));
|
|
350
|
+
});
|
|
351
|
+
const connected = [];
|
|
352
|
+
for (const harness of await choose(found)) {
|
|
353
|
+
const progress = spinner();
|
|
354
|
+
progress.start(`${harness.name}: adding grunt and sending a test request through it`);
|
|
355
|
+
try {
|
|
356
|
+
const { change } = await connectHarness(harness, port, options.run);
|
|
357
|
+
progress.stop(`${harness.name}: PASS — answered through grunt`);
|
|
358
|
+
if (change?.backup)
|
|
359
|
+
log.info(`${harness.name}: previous config saved as ${change.backup}`);
|
|
360
|
+
connected.push(harness);
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
progress.error(`${harness.name}: FAIL — ${error instanceof Error ? error.message : String(error)}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (connected.length)
|
|
367
|
+
note(connected.map(h => `${chalk.bold(h.name)}\n ${h.launch(port)}`).join('\n'), 'Start coding with grunt');
|
|
368
|
+
return connected;
|
|
369
|
+
}
|
|
370
|
+
const wizardActions = { banner, preflight, connectSquire, setup, setupFallbacks, installService, configurePi, checkService, checkFallbackServices, loadRegistry, checkServiceSources, connectHarnesses };
|
|
234
371
|
export async function wizard(add, actions = wizardActions) {
|
|
235
372
|
if (add && !Object.hasOwn(PROVIDERS, add))
|
|
236
373
|
throw new Error(`Choose a supported provider: ${Object.keys(PROVIDERS).join(', ')}`);
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
await step('
|
|
374
|
+
await actions.banner?.();
|
|
375
|
+
intro(chalk.hex('#f4b41a').bold('grunt') + chalk.dim(' — npx usegrunt setup'));
|
|
376
|
+
note(PREAMBLE, 'What grunt does');
|
|
377
|
+
await step('Checking prerequisites', () => actions.preflight());
|
|
378
|
+
note(SQUIRE_NOTICE, 'Google sign-in for Trusty Squire');
|
|
379
|
+
await step('Connecting Trusty Squire', () => actions.connectSquire());
|
|
241
380
|
if (add) {
|
|
242
381
|
await step('FreeLLMAPI and provider grants', () => actions.setup(line => log.info(line), [add]));
|
|
243
382
|
outro(`${add} connected`);
|
|
244
383
|
return;
|
|
245
384
|
}
|
|
246
|
-
const
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
|
|
385
|
+
const pulled = actions.loadRegistry ? await step('Pulling the free service list from the registry', () => actions.loadRegistry()) : { registry: bundledRegistry, origin: 'bundled' };
|
|
386
|
+
const { registry } = pulled;
|
|
387
|
+
const published = registry.published.slice(0, 10);
|
|
388
|
+
if (pulled.origin === 'remote')
|
|
389
|
+
log.info(`Registry: ${registry.adapters.length} free services, published ${published}`);
|
|
390
|
+
else
|
|
391
|
+
log.warn(`Registry unreachable; using the ${pulled.origin === 'cache' ? 'list saved by an earlier setup' : 'list bundled with this version'} (published ${published})`);
|
|
392
|
+
const adapters = registry.adapters.filter(adapter => knownAdapters.has(adapter.id));
|
|
393
|
+
log.message(registry.adapters.map(adapter => knownAdapters.has(adapter.id)
|
|
394
|
+
? `${chalk.bold(adapter.id.padEnd(10))} ${chalk.dim(describe(adapter))}`
|
|
395
|
+
: `${chalk.dim(adapter.id.padEnd(10))} ${chalk.dim('skipped: needs a newer usegrunt')}`).join('\n'));
|
|
396
|
+
const ids = adapters.map(adapter => adapter.id);
|
|
397
|
+
const results = new Map(ids.map(id => [id, {}]));
|
|
398
|
+
const unavailable = [];
|
|
399
|
+
const notify = report();
|
|
400
|
+
log.step(`Signing up for ${ids.length} free services`);
|
|
401
|
+
for (const id of ids) {
|
|
402
|
+
const outcome = await step(`${id}: installing and signing in`, () => actions.setupFallbacks({ directory: configDir(), run: command, adapters: [id], notify }), result => result.unavailable.includes(id) ? `${id}: sign-in incomplete` : `${id}: signed in`);
|
|
403
|
+
const failed = outcome.unavailable.includes(id);
|
|
404
|
+
if (failed)
|
|
405
|
+
unavailable.push(id);
|
|
406
|
+
results.get(id).signup = failed ? 'fail' : 'pass';
|
|
407
|
+
}
|
|
408
|
+
log.step('Connecting the services to the grunt daemon');
|
|
409
|
+
await step('Starting the grunt background service', actions.installService);
|
|
250
410
|
const port = Number(process.env.MILO_PORT || '8788');
|
|
251
|
-
await step(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
411
|
+
await step(`Waiting for grunt to answer at http://127.0.0.1:${port}`, () => actions.checkService(port));
|
|
412
|
+
const beforeSources = new Set(unavailable);
|
|
413
|
+
if (actions.checkServiceSources)
|
|
414
|
+
await step('Checking which services the daemon runs', () => actions.checkServiceSources(unavailable, notify, ids));
|
|
415
|
+
for (const id of ids)
|
|
416
|
+
results.get(id).daemon = beforeSources.has(id) ? 'skip' : unavailable.includes(id) ? 'fail' : 'pass';
|
|
417
|
+
log.step('Testing each service with a real request through grunt');
|
|
418
|
+
for (const id of ids) {
|
|
419
|
+
const before = unavailable.includes(id);
|
|
420
|
+
// Hold the result line until the spinner is gone so the two do not share a row.
|
|
421
|
+
const lines = [], progress = spinner();
|
|
422
|
+
progress.start(`${id}: sending a test request through grunt`);
|
|
423
|
+
try {
|
|
424
|
+
await actions.checkFallbackServices(unavailable, port, line => lines.push(line), [id]);
|
|
425
|
+
}
|
|
426
|
+
finally {
|
|
427
|
+
progress.clear();
|
|
428
|
+
lines.forEach(notify);
|
|
429
|
+
}
|
|
430
|
+
results.get(id).check = before ? 'skip' : unavailable.includes(id) ? 'fail' : 'pass';
|
|
431
|
+
}
|
|
432
|
+
note([`${'service'.padEnd(10)} sign-in daemon test`, ...ids.map(id => {
|
|
433
|
+
const r = results.get(id);
|
|
434
|
+
return `${id.padEnd(10)} ${mark(r.signup)} ${mark(r.daemon)} ${mark(r.check)}`;
|
|
435
|
+
})].join('\n'), 'Free services');
|
|
436
|
+
if (actions.connectHarnesses)
|
|
437
|
+
await actions.connectHarnesses(port);
|
|
438
|
+
else if (actions.configurePi)
|
|
439
|
+
await step('Pi provider', () => actions.configurePi(port));
|
|
440
|
+
outro(unavailable.length ? `grunt is ready; incomplete fallbacks: ${unavailable.join(', ')}. Rerun setup to finish them.` : 'grunt is ready');
|
|
441
|
+
if (unavailable.length)
|
|
257
442
|
throw new Error('Some adapters failed verification. Run usegrunt setup to resume.');
|
|
258
443
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "usegrunt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
27
27
|
"@trusty-squire/mcp": "1.1.39",
|
|
28
28
|
"@trusty-squire/sdk": "0.1.0",
|
|
29
|
+
"ajv": "^8.20.0",
|
|
29
30
|
"chalk": "^6.0.1",
|
|
30
31
|
"hono": "^4.13.8",
|
|
31
32
|
"ipaddr.js": "^2.5.0",
|