usegrunt 0.6.1 → 0.6.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/README.md +2 -2
- package/dist/local/fallback-setup.js +109 -86
- package/dist/local/freellmapi.js +6 -0
- package/dist/local/main.js +8 -6
- package/dist/local/native-router.js +8 -6
- package/dist/local/parallel.js +20 -0
- package/dist/local/registry.js +35 -13
- package/dist/local/setup.js +61 -23
- package/dist/local/terminal.js +8 -0
- package/dist/local/verification-queue.js +31 -0
- package/dist/local/wizard.js +90 -77
- package/dist/registry/adapters.json +35 -5
- package/dist/registry.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,11 +16,11 @@ usegrunt installs grunt on this machine. It pools free AI quota and serves one l
|
|
|
16
16
|
|
|
17
17
|
https://grunt.run. `milo` and `milo-local` remain aliases.
|
|
18
18
|
|
|
19
|
-
Setup
|
|
19
|
+
Setup connects Trusty Squire, installs and connects the vetted Freebuff, OpenCode and Kilo pool (up to three services at once), tests each service, then connects your coding tools. Browser verification is queued when a provider needs you.
|
|
20
20
|
|
|
21
21
|
[Reference](https://github.com/bananaman614305/milo/blob/main/docs/reference.md).
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
New installs route tasks across Freebuff, OpenCode and Kilo Auto. `usegrunt add groq`, `usegrunt add cerebras` and `usegrunt add kilo` remain available. Existing `freellmapi` routes keep their Nemotron-first Kilo chain; the default `kilo` source selects `kilo-auto/free`. Repeat setup preserves previously connected API sources.
|
|
24
24
|
|
|
25
25
|
Kilo free models may log prompts or use them for training; avoid sensitive prompts. Their free limits are unknown. Kilo quota errors fall through FreeLLMAPI's fallback chain. Requests allow a long timeout for Nemotron reasoning.
|
|
26
26
|
|
|
@@ -2,7 +2,8 @@ import { spawn, execFile } from 'node:child_process';
|
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
import { mkdir, writeFile, access } from 'node:fs/promises';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { BrowserSquire } from './setup.js';
|
|
5
|
+
import { BrowserSquire, setup } from './setup.js';
|
|
6
|
+
import { parallelMap } from './parallel.js';
|
|
6
7
|
import { OpenCode } from './opencode.js';
|
|
7
8
|
import { DOCTOR_TIMEOUT_MS } from './freebuff.js';
|
|
8
9
|
import { SourceError, Sources } from './source.js';
|
|
@@ -74,119 +75,141 @@ export async function setupFallbacks(options) {
|
|
|
74
75
|
if (error.code !== 'ENOENT')
|
|
75
76
|
throw error;
|
|
76
77
|
}
|
|
77
|
-
let
|
|
78
|
-
const connect = async () => { if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
await squire.connect();
|
|
83
|
-
connected = true;
|
|
84
|
-
} };
|
|
78
|
+
let connection;
|
|
79
|
+
const connect = () => connection ??= (async () => { if (options.connect)
|
|
80
|
+
await options.connect();
|
|
81
|
+
else if (owned)
|
|
82
|
+
await squire.connect(); })();
|
|
85
83
|
const install = async (binary, pkg) => {
|
|
86
84
|
try {
|
|
87
85
|
await options.run(binary, ['--version']);
|
|
88
86
|
}
|
|
89
87
|
catch {
|
|
90
|
-
await options.run('npm', ['install', '--global', pkg]
|
|
88
|
+
await options.run('npm', ['install', '--global', pkg]);
|
|
91
89
|
}
|
|
92
90
|
};
|
|
93
91
|
options.notify('Free routes run their own tools with your filesystem permissions in the working directory. Free model providers may retain prompts.');
|
|
94
92
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await install('freebuff', 'freebuff');
|
|
98
|
-
// Older CLIs accept --version but cannot run the login diagnostic.
|
|
93
|
+
const tasks = {
|
|
94
|
+
freebuff: async () => {
|
|
99
95
|
try {
|
|
100
|
-
await
|
|
101
|
-
|
|
102
|
-
catch {
|
|
103
|
-
options.notify('Freebuff: repairing the installed CLI before checking sign-in');
|
|
96
|
+
await install('freebuff', 'freebuff');
|
|
97
|
+
// Older CLIs accept --version but cannot run the login diagnostic.
|
|
104
98
|
try {
|
|
105
|
-
await options.run('npm', ['install', '--global', 'freebuff@latest'], true);
|
|
106
99
|
await options.run('freebuff', ['doctor']);
|
|
107
100
|
}
|
|
108
101
|
catch {
|
|
109
|
-
|
|
102
|
+
options.notify('Freebuff: repairing the installed CLI before checking sign-in');
|
|
103
|
+
try {
|
|
104
|
+
await options.run('npm', ['install', '--global', 'freebuff@latest']);
|
|
105
|
+
await options.run('freebuff', ['doctor']);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw new FreebuffCompatibilityError('Freebuff CLI repair incomplete. The active freebuff on PATH must support doctor. Run npm install --global freebuff@latest, remove older Freebuff binaries earlier on PATH, then rerun usegrunt setup. Continuing with OpenCode.');
|
|
109
|
+
}
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
111
|
+
try {
|
|
112
|
+
await options.run('tmux', ['-V']);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
if (process.platform === 'darwin')
|
|
116
|
+
await options.run('brew', ['install', 'tmux'], true);
|
|
117
|
+
else {
|
|
118
|
+
let manager;
|
|
119
|
+
for (const candidate of ['apt-get', 'dnf']) {
|
|
120
|
+
try {
|
|
121
|
+
await options.run(candidate, ['--version']);
|
|
122
|
+
manager = candidate;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
catch { /* Try the next supported OS package manager. */ }
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
+
if (!manager)
|
|
128
|
+
throw new Error('Install tmux with your OS package manager');
|
|
129
|
+
const args = ['install', '-y', 'tmux'];
|
|
130
|
+
await options.run(process.getuid?.() === 0 ? manager : 'sudo', process.getuid?.() === 0 ? args : [manager, ...args], true);
|
|
127
131
|
}
|
|
128
|
-
if (!manager)
|
|
129
|
-
throw new Error('Install tmux with your OS package manager');
|
|
130
|
-
const args = ['install', '-y', 'tmux'];
|
|
131
|
-
await options.run(process.getuid?.() === 0 ? manager : 'sudo', process.getuid?.() === 0 ? args : [manager, ...args], true);
|
|
132
132
|
}
|
|
133
|
+
const signedIn = options.signedIn ?? freebuffSignedIn;
|
|
134
|
+
if (!await signedIn()) {
|
|
135
|
+
await connect();
|
|
136
|
+
if (options.login)
|
|
137
|
+
await options.login(squire);
|
|
138
|
+
else
|
|
139
|
+
await loginFreebuff(squire, options.signal);
|
|
140
|
+
}
|
|
141
|
+
if (!await signedIn())
|
|
142
|
+
throw new Error('Freebuff is still signed out; rerun setup to resume');
|
|
143
|
+
options.notify('Freebuff: signed in; grunt will start its loopback bridge with the background service');
|
|
133
144
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
await options.login(squire);
|
|
145
|
+
catch (error) {
|
|
146
|
+
unavailable.push('freebuff');
|
|
147
|
+
if (error instanceof FreebuffCompatibilityError)
|
|
148
|
+
options.notify(error.message);
|
|
139
149
|
else
|
|
140
|
-
|
|
150
|
+
options.notify('Freebuff setup incomplete. Run freebuff doctor, install tmux if missing, then rerun usegrunt setup. Continuing with OpenCode.');
|
|
141
151
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
options.notify('Freebuff: signed in; grunt will start its loopback bridge with the background service');
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
unavailable.push('freebuff');
|
|
148
|
-
if (error instanceof FreebuffCompatibilityError)
|
|
149
|
-
options.notify(error.message);
|
|
150
|
-
else
|
|
151
|
-
options.notify('Freebuff setup incomplete. Run freebuff doctor, install tmux if missing, then rerun usegrunt setup. Continuing with OpenCode.');
|
|
152
|
-
}
|
|
153
|
-
if (!options.adapters || options.adapters.includes('opencode'))
|
|
154
|
-
try {
|
|
155
|
-
await install('opencode', 'opencode-ai');
|
|
156
|
-
const verify = options.verify ?? (() => verifyOpenCode(new OpenCode(), options.signal ? AbortSignal.any([options.signal, AbortSignal.timeout(120000)]) : AbortSignal.timeout(120000)));
|
|
152
|
+
},
|
|
153
|
+
opencode: async () => {
|
|
157
154
|
try {
|
|
158
|
-
await
|
|
155
|
+
await install('opencode', 'opencode-ai');
|
|
156
|
+
const verify = options.verify ?? (() => verifyOpenCode(new OpenCode(), options.signal ? AbortSignal.any([options.signal, AbortSignal.timeout(120000)]) : AbortSignal.timeout(120000)));
|
|
157
|
+
try {
|
|
158
|
+
await verify();
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (!(error instanceof SourceError) || error.code !== 'logged_out')
|
|
162
|
+
throw error;
|
|
163
|
+
await connect();
|
|
164
|
+
const findCredential = async () => (await squire.credentials.list()).find(c => c.service?.trim().toLowerCase() === 'opencode'
|
|
165
|
+
&& c.auth_strategy !== 'username_password' && c.field_names.some(field => /^(?:api_?key|token|key)$/i.test(field)));
|
|
166
|
+
let credential = await findCredential();
|
|
167
|
+
if (!credential) {
|
|
168
|
+
await squire.signup('opencode', 'https://opencode.ai/auth', "Use the user's existing OpenCode account or sign up for free access. Use operate_extract to store an OpenCode Zen API key directly in this user's Squire vault under service opencode. Never include its value in your answer. No payment, paid plans, extra accounts or account switching. Stop if free access requires payment. Report human verification for browser handoff; do not bypass it.");
|
|
169
|
+
credential = await findCredential();
|
|
170
|
+
}
|
|
171
|
+
if (!credential)
|
|
172
|
+
throw new Error('No OpenCode access was created');
|
|
173
|
+
const grant = await squire.credentials.grant(credential.reference);
|
|
174
|
+
const path = join(options.directory, 'opencode-free.json');
|
|
175
|
+
await mkdir(options.directory, { recursive: true, mode: 0o700 });
|
|
176
|
+
await writeFile(path, JSON.stringify({ provider: { opencode: { options: { baseURL: grant.base_url.replace(/\/$/, '') + '/zen/v1', apiKey: grant.token } } } }), { mode: 0o600 });
|
|
177
|
+
process.env.OPENCODE_CONFIG = path;
|
|
178
|
+
await verify();
|
|
179
|
+
}
|
|
180
|
+
options.notify('OpenCode: free model answered');
|
|
159
181
|
}
|
|
160
|
-
catch
|
|
161
|
-
|
|
162
|
-
|
|
182
|
+
catch {
|
|
183
|
+
unavailable.push('opencode');
|
|
184
|
+
options.notify('OpenCode free model check failed or signup was refused. Rerun usegrunt setup after repairing OpenCode; other routes remain available.');
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
kilo: async () => {
|
|
188
|
+
try {
|
|
163
189
|
await connect();
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
throw new Error('No OpenCode access was created');
|
|
173
|
-
const grant = await squire.credentials.grant(credential.reference);
|
|
174
|
-
const path = join(options.directory, 'opencode-free.json');
|
|
175
|
-
await mkdir(options.directory, { recursive: true, mode: 0o700 });
|
|
176
|
-
await writeFile(path, JSON.stringify({ provider: { opencode: { options: { baseURL: grant.base_url.replace(/\/$/, '') + '/zen/v1', apiKey: grant.token } } } }), { mode: 0o600 });
|
|
177
|
-
process.env.OPENCODE_CONFIG = path;
|
|
178
|
-
await verify();
|
|
190
|
+
if (!squire.runs)
|
|
191
|
+
throw new Error('Provider signup requires Squire');
|
|
192
|
+
await (options.setupProvider ?? setup)(options.notify, ['kilo'], { squire: squire, ...(options.signal ? { signal: options.signal } : {}) });
|
|
193
|
+
options.notify('Kilo: free API access connected through Squire');
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
unavailable.push('kilo');
|
|
197
|
+
options.notify('Kilo setup incomplete. Rerun usegrunt setup to resume; other routes remain available.');
|
|
179
198
|
}
|
|
180
|
-
options.notify('OpenCode: free model answered');
|
|
181
|
-
}
|
|
182
|
-
catch {
|
|
183
|
-
unavailable.push('opencode');
|
|
184
|
-
options.notify('OpenCode free model check failed or signup was refused. Rerun usegrunt setup after repairing OpenCode; other routes remain available.');
|
|
185
199
|
}
|
|
186
|
-
|
|
200
|
+
};
|
|
201
|
+
const adapters = options.adapters ?? ['freebuff', 'opencode'];
|
|
202
|
+
await parallelMap(adapters, async (id) => {
|
|
203
|
+
const task = tasks[id];
|
|
204
|
+
if (!task)
|
|
205
|
+
throw new Error('Unsupported vetted adapter');
|
|
206
|
+
await task();
|
|
207
|
+
}, 3, options.signal);
|
|
208
|
+
options.signal?.throwIfAborted();
|
|
209
|
+
return { unavailable: adapters.filter(id => unavailable.includes(id)) };
|
|
187
210
|
}
|
|
188
211
|
finally {
|
|
189
|
-
if (owned &&
|
|
212
|
+
if (owned && connection)
|
|
190
213
|
await squire.close();
|
|
191
214
|
}
|
|
192
215
|
}
|
package/dist/local/freellmapi.js
CHANGED
|
@@ -67,6 +67,12 @@ export class FreeLLMAPI {
|
|
|
67
67
|
}
|
|
68
68
|
if (!response.ok)
|
|
69
69
|
throw new SourceError(response.status === 403 ? 'refused' : response.status === 401 ? 'logged_out' : response.status === 429 ? 'quota' : 'upstream', `FreeLLMAPI returned HTTP ${response.status}`);
|
|
70
|
+
// FreeLLMAPI treats a pinned model as a preference and can fall back to
|
|
71
|
+
// another provider. Never attribute that provider's answer to Kilo.
|
|
72
|
+
if (this.id === 'kilo' && response.headers.get('x-routed-via') !== `custom/${this.options.model}`) {
|
|
73
|
+
await response.body?.cancel();
|
|
74
|
+
throw new SourceError('upstream', 'Kilo did not answer; the local backend selected another route');
|
|
75
|
+
}
|
|
70
76
|
const result = await response.json();
|
|
71
77
|
const message = result.choices?.[0]?.message;
|
|
72
78
|
if (message?.refusal)
|
package/dist/local/main.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { knownAdapters } from '../registry.js';
|
|
2
3
|
import { realpathSync } from 'node:fs';
|
|
3
4
|
import { pathToFileURL } from 'node:url';
|
|
4
5
|
import { basename } from 'node:path';
|
|
@@ -32,8 +33,8 @@ export function configure(env = process.env, registry = () => bundledRegistry) {
|
|
|
32
33
|
const connection = { url, loadKey };
|
|
33
34
|
const dots = new Dots({ env, timeout: positive(env.MILO_DOTS_TIMEOUT_MS, 300000) });
|
|
34
35
|
const registered = [dots, new Codex(env.MILO_CODEX_MODEL ? { model: env.MILO_CODEX_MODEL } : {}), new FreeLLMAPI(connection), new FreeLLMAPI({ ...connection, id: 'kilo', model: 'kilo-auto/free' }), new OpenCode({ model: () => env.MILO_OPENCODE_MODEL ?? registry().adapters.find(a => a.id === 'opencode')?.model ?? 'big-pickle', ...(env.MILO_OPENCODE_URL ? { url: env.MILO_OPENCODE_URL } : {}) }), new Freebuff({ toolBridge: env.MILO_FREEBUFF_JSON_BRIDGE === '1' })];
|
|
35
|
-
const ids = env.MILO_SOURCES?.split(',').map(id => id.trim()) ?? [
|
|
36
|
-
const routing = ids.every(id =>
|
|
36
|
+
const ids = env.MILO_SOURCES?.split(',').map(id => id.trim()) ?? [...knownAdapters];
|
|
37
|
+
const routing = ids.every(id => knownAdapters.has(id)) ? { registry } : undefined;
|
|
37
38
|
return new Sources(ids.map(id => { const source = registered.find(s => s.id === id); if (!source)
|
|
38
39
|
throw new Error(`Unknown grunt source: ${id}`); return source; }), routing);
|
|
39
40
|
}
|
|
@@ -41,23 +42,24 @@ export function start(env = process.env) {
|
|
|
41
42
|
let registry = structuredClone(bundledRegistry);
|
|
42
43
|
const sources = configure(env, () => registry);
|
|
43
44
|
const directory = configDir(env);
|
|
45
|
+
let squire;
|
|
44
46
|
const sync = new RegistrySync({ directory, ...(env.GRUNT_REGISTRY_URL ? { url: env.GRUNT_REGISTRY_URL } : {}),
|
|
47
|
+
afterEnsure: async () => { await squire?.close(); squire = undefined; },
|
|
45
48
|
changed: current => { registry = current; }, notify: console.error,
|
|
46
49
|
ensure: async (adapter, signal) => {
|
|
47
50
|
if (!sources.sources.some(source => source.id === adapter.id))
|
|
48
51
|
return;
|
|
49
52
|
sources.preparing.add(adapter.id);
|
|
50
|
-
const
|
|
53
|
+
const client = squire ??= new BrowserSquire({ background: true, signal });
|
|
51
54
|
try {
|
|
52
|
-
const result = await setupFallbacks({ directory, run: (binary, args) => command(binary, args, false, signal), notify: console.error, adapters: [adapter.id], squire, signal,
|
|
53
|
-
connect: () =>
|
|
55
|
+
const result = await setupFallbacks({ directory, run: (binary, args) => command(binary, args, false, signal), notify: console.error, adapters: [adapter.id], squire: client, signal,
|
|
56
|
+
connect: () => client.connect() });
|
|
54
57
|
if (result.unavailable.length)
|
|
55
58
|
throw new Error('Adapter setup incomplete');
|
|
56
59
|
sources.healthy(adapter.id);
|
|
57
60
|
}
|
|
58
61
|
finally {
|
|
59
62
|
sources.preparing.delete(adapter.id);
|
|
60
|
-
await squire.close();
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
});
|
|
@@ -4,7 +4,9 @@ import { command, configDir, installBackgroundService } from './wizard.js';
|
|
|
4
4
|
import { loopback } from './freellmapi.js';
|
|
5
5
|
// Published FreeLLMAPI v0.16.24 source, pinned independently of grunt releases.
|
|
6
6
|
export const FREELLMAPI_REVISION = '4c8c2f834b587b6acc3f00698ad8f6468bea1aa2';
|
|
7
|
-
export async function ensureNativeRouter() {
|
|
7
|
+
export async function ensureNativeRouter(signal) {
|
|
8
|
+
signal?.throwIfAborted();
|
|
9
|
+
const run = (binary, args) => command(binary, args, false, signal);
|
|
8
10
|
if (!['linux', 'darwin'].includes(process.platform))
|
|
9
11
|
throw new Error('grunt setup requires Linux or macOS');
|
|
10
12
|
const directory = join(configDir(), 'freellmapi'), source = join(directory, 'source');
|
|
@@ -19,16 +21,16 @@ export async function ensureNativeRouter() {
|
|
|
19
21
|
catch { /* First install or interrupted build. */ }
|
|
20
22
|
if (!installed) {
|
|
21
23
|
const archive = join(directory, 'source.tar.gz');
|
|
22
|
-
const response = await fetch(`https://codeload.github.com/tashfeenahmed/freellmapi/tar.gz/${FREELLMAPI_REVISION}`, { signal: AbortSignal.timeout(120000) });
|
|
24
|
+
const response = await fetch(`https://codeload.github.com/tashfeenahmed/freellmapi/tar.gz/${FREELLMAPI_REVISION}`, { signal: AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(120000)]) });
|
|
23
25
|
if (!response.ok)
|
|
24
26
|
throw new Error('Cannot download the pinned FreeLLMAPI Node server');
|
|
25
27
|
await writeFile(archive, Buffer.from(await response.arrayBuffer()), { mode: 0o600 });
|
|
26
28
|
await mkdir(source, { recursive: true, mode: 0o700 });
|
|
27
|
-
await
|
|
29
|
+
await run('tar', ['-xzf', archive, '--strip-components=1', '-C', source]);
|
|
28
30
|
await rm(archive);
|
|
29
|
-
await
|
|
30
|
-
await
|
|
31
|
-
await
|
|
31
|
+
await run('npm', ['install', '--prefix', source, '--ignore-scripts', '--no-audit', '--no-fund']);
|
|
32
|
+
await run('npm', ['rebuild', '--prefix', source, 'better-sqlite3', 'sharp']);
|
|
33
|
+
await run(process.execPath, [join(source, 'node_modules', 'typescript', 'bin', 'tsc'), '--project', join(source, 'server', 'tsconfig.json')]);
|
|
32
34
|
await writeFile(join(directory, FREELLMAPI_REVISION), '', { mode: 0o600 });
|
|
33
35
|
}
|
|
34
36
|
const runner = join(directory, 'runner.mjs');
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Limit browser/build pressure as the vetted catalog grows. Wait for started
|
|
2
|
+
// jobs before rejecting so callers can safely close shared resources.
|
|
3
|
+
export async function parallelMap(items, task, limit = 3, signal) {
|
|
4
|
+
if (!Number.isInteger(limit) || limit < 1)
|
|
5
|
+
throw new Error('Invalid concurrency limit');
|
|
6
|
+
const results = new Array(items.length);
|
|
7
|
+
let next = 0;
|
|
8
|
+
const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
9
|
+
while (next < items.length) {
|
|
10
|
+
signal?.throwIfAborted();
|
|
11
|
+
const index = next++;
|
|
12
|
+
results[index] = await task(items[index]);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const settled = await Promise.allSettled(workers);
|
|
16
|
+
const failed = settled.find(result => result.status === 'rejected');
|
|
17
|
+
if (failed?.status === 'rejected')
|
|
18
|
+
throw failed.reason;
|
|
19
|
+
return results;
|
|
20
|
+
}
|
package/dist/local/registry.js
CHANGED
|
@@ -2,7 +2,9 @@ import { mkdir, readFile, writeFile, rename, rm } from 'node:fs/promises';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { bundledRegistry, knownAdapters, validateRegistry } from '../registry.js';
|
|
5
|
+
import { parallelMap } from './parallel.js';
|
|
5
6
|
export const REGISTRY_INTERVAL = 24 * 60 * 60 * 1000;
|
|
7
|
+
const REGISTRY_URLS = ['https://api.grunt.run/v1/registry', 'https://milo-gateway.fly.dev/v1/registry'];
|
|
6
8
|
export class RegistrySync {
|
|
7
9
|
options;
|
|
8
10
|
current = structuredClone(bundledRegistry);
|
|
@@ -29,10 +31,25 @@ export class RegistrySync {
|
|
|
29
31
|
}
|
|
30
32
|
async refresh() {
|
|
31
33
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
let response;
|
|
35
|
+
for (const url of this.options.url ? [this.options.url] : REGISTRY_URLS) {
|
|
36
|
+
try {
|
|
37
|
+
response = await (this.options.fetcher ?? fetch)(url, {
|
|
38
|
+
headers: this.etag ? { 'If-None-Match': this.etag } : {}, redirect: 'error',
|
|
39
|
+
signal: AbortSignal.any([this.controller.signal, AbortSignal.timeout(10000)])
|
|
40
|
+
});
|
|
41
|
+
if (response.status === 200 || response.status === 304)
|
|
42
|
+
break;
|
|
43
|
+
await response.body?.cancel();
|
|
44
|
+
response = undefined;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
if (this.controller.signal.aborted)
|
|
48
|
+
throw new Error('Registry sync cancelled');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!response)
|
|
52
|
+
throw new Error('Registry unavailable');
|
|
36
53
|
if (response.status === 200) {
|
|
37
54
|
const registry = validateRegistry(await response.json());
|
|
38
55
|
const etag = response.headers.get('ETag') ?? undefined;
|
|
@@ -57,15 +74,20 @@ export class RegistrySync {
|
|
|
57
74
|
}
|
|
58
75
|
if (this.controller.signal.aborted)
|
|
59
76
|
return;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
try {
|
|
78
|
+
await parallelMap(this.enabled, async (adapter) => {
|
|
79
|
+
if (!this.options.ensure || this.controller.signal.aborted)
|
|
80
|
+
return;
|
|
81
|
+
try {
|
|
82
|
+
await this.options.ensure(adapter, this.controller.signal);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
this.options.notify?.(`${adapter.id}: setup needs attention; run usegrunt setup to finish sign-in`);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await this.options.afterEnsure?.();
|
|
69
91
|
}
|
|
70
92
|
}
|
|
71
93
|
async start() {
|
package/dist/local/setup.js
CHANGED
|
@@ -13,6 +13,8 @@ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
|
13
13
|
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
14
14
|
import { freeConfig, loopback } from './freellmapi.js';
|
|
15
15
|
import { proxyApproval } from './approval-proxy.js';
|
|
16
|
+
import { VerificationQueue } from './verification-queue.js';
|
|
17
|
+
import { withTerminal } from './terminal.js';
|
|
16
18
|
const exec = promisify(execFile);
|
|
17
19
|
export const FREELLMAPI_IMAGE = 'ghcr.io/tashfeenahmed/freellmapi@sha256:845a4b568a20fffd5112e1b9c0258e7782d9eabbba2430612d2f7c811eee267e';
|
|
18
20
|
export const PROVIDERS = { groq: 'https://console.groq.com/keys', cerebras: 'https://cloud.cerebras.ai/platform/api-keys', kilo: 'https://app.kilo.ai/profile' };
|
|
@@ -142,7 +144,23 @@ export class BrowserSquire {
|
|
|
142
144
|
client = new Client({ name: 'grunt setup', version: '0.1.0' });
|
|
143
145
|
sessions = new Map();
|
|
144
146
|
handoffs = [];
|
|
145
|
-
|
|
147
|
+
connection;
|
|
148
|
+
metadata;
|
|
149
|
+
grants = new Map();
|
|
150
|
+
verification = new VerificationQueue(items => withTerminal(async () => {
|
|
151
|
+
this.options.signal?.throwIfAborted();
|
|
152
|
+
for (const item of items)
|
|
153
|
+
console.log(`Complete ${item.service} verification in this browser: ${item.url}`);
|
|
154
|
+
const { confirm, isCancel } = await import('@clack/prompts');
|
|
155
|
+
const done = await confirm({ message: `Finished verification for ${items.map(item => item.service).join(', ')}? Resume setup.`, initialValue: true });
|
|
156
|
+
if (isCancel(done) || !done)
|
|
157
|
+
throw new Error('Provider verification cancelled');
|
|
158
|
+
this.options.signal?.throwIfAborted();
|
|
159
|
+
}));
|
|
160
|
+
connect() {
|
|
161
|
+
return this.connection ??= this.connectOnce().catch(error => { this.connection = undefined; throw error; });
|
|
162
|
+
}
|
|
163
|
+
async connectOnce() {
|
|
146
164
|
const bin = join(dirname(fileURLToPath(import.meta.resolve('@trusty-squire/mcp'))), 'bin.js');
|
|
147
165
|
const env = squireEnvironment();
|
|
148
166
|
// Squire owns its account binding and vault. grunt never reads its files.
|
|
@@ -163,6 +181,7 @@ export class BrowserSquire {
|
|
|
163
181
|
const result = await this.call('list_credentials', { fields: 'summary' }, true);
|
|
164
182
|
if (!Array.isArray(result.credentials))
|
|
165
183
|
throw new Error('Squire did not return vault metadata');
|
|
184
|
+
this.metadata = Promise.resolve(result.credentials);
|
|
166
185
|
}
|
|
167
186
|
catch (error) {
|
|
168
187
|
await this.client.close().catch(() => { });
|
|
@@ -206,21 +225,30 @@ export class BrowserSquire {
|
|
|
206
225
|
}
|
|
207
226
|
credentials = {
|
|
208
227
|
list: async () => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
228
|
+
return structuredClone(await (this.metadata ??= this.call('list_credentials', { fields: 'summary' }).then(result => {
|
|
229
|
+
if (!Array.isArray(result.credentials))
|
|
230
|
+
throw new Error('Squire did not return vault metadata');
|
|
231
|
+
return result.credentials;
|
|
232
|
+
}).catch(error => { this.metadata = undefined; throw error; })));
|
|
213
233
|
},
|
|
214
234
|
grant: async (reference) => {
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return { base_url: result.base_url, token: result.token };
|
|
235
|
+
let grant = this.grants.get(reference);
|
|
236
|
+
if (!grant) {
|
|
237
|
+
grant = this.grant(reference).catch(error => { this.grants.delete(reference); throw error; });
|
|
238
|
+
this.grants.set(reference, grant);
|
|
239
|
+
}
|
|
240
|
+
return grant;
|
|
222
241
|
}
|
|
223
242
|
};
|
|
243
|
+
async grant(reference) {
|
|
244
|
+
const result = await this.call('grant_app_access', { reference });
|
|
245
|
+
if (typeof result.base_url !== 'string' || typeof result.token !== 'string' || !result.token)
|
|
246
|
+
throw new Error('Squire returned no app grant');
|
|
247
|
+
const url = new URL(result.base_url);
|
|
248
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash)
|
|
249
|
+
throw new Error('Squire returned an invalid grant endpoint');
|
|
250
|
+
return { base_url: result.base_url, token: result.token };
|
|
251
|
+
}
|
|
224
252
|
async signup(service, url, goal) {
|
|
225
253
|
const deadline = Date.now() + 600000;
|
|
226
254
|
while (Date.now() < deadline) {
|
|
@@ -248,6 +276,7 @@ export class BrowserSquire {
|
|
|
248
276
|
if (refusal)
|
|
249
277
|
throw setupStopped(`Provider refused ${provider} signup; setup stopped`, reason);
|
|
250
278
|
if (result.status === 'complete') {
|
|
279
|
+
this.metadata = undefined; // A browser capture may have added a credential.
|
|
251
280
|
const id = this.sessions.get(provider);
|
|
252
281
|
if (id) {
|
|
253
282
|
await this.call('operate_finish', { session_id: id, outcome: 'result', summary: 'grunt provider key stored in user vault' });
|
|
@@ -262,15 +291,12 @@ export class BrowserSquire {
|
|
|
262
291
|
throw new Error('Provider signup needs human verification; stopped before handoff');
|
|
263
292
|
if (humanStep && this.sessions.has(provider)) {
|
|
264
293
|
const url = await this.humanHandoff(this.sessions.get(provider));
|
|
265
|
-
console.log(`Complete ${provider} verification in this browser: ${url}`);
|
|
266
294
|
if (this.options.background) {
|
|
295
|
+
console.log(`Complete ${provider} verification in this browser: ${url}`);
|
|
267
296
|
await delay(5000, undefined, this.options.signal ? { signal: this.options.signal } : {});
|
|
268
297
|
return { run: { id: provider, state: 'running' }, decision: 'silent' };
|
|
269
298
|
}
|
|
270
|
-
|
|
271
|
-
const done = await confirm({ message: 'Verification complete? Resume signup.', initialValue: true });
|
|
272
|
-
if (isCancel(done) || !done)
|
|
273
|
-
throw new Error('Provider verification cancelled');
|
|
299
|
+
await this.verification.wait({ service: provider, url });
|
|
274
300
|
return { run: { id: provider, state: 'running' }, decision: 'silent' };
|
|
275
301
|
}
|
|
276
302
|
this.sessions.delete(provider);
|
|
@@ -482,11 +508,13 @@ export async function loadRouterKey(url) {
|
|
|
482
508
|
throw new Error('Local router returned an invalid API key');
|
|
483
509
|
return key;
|
|
484
510
|
}
|
|
485
|
-
export async function setup(notify = console.log, providers = ['groq']) {
|
|
486
|
-
const
|
|
511
|
+
export async function setup(notify = console.log, providers = ['groq'], options = {}) {
|
|
512
|
+
const owned = options.squire ? undefined : new BrowserSquire(options.signal ? { signal: options.signal } : {});
|
|
513
|
+
const squire = options.squire ?? owned;
|
|
487
514
|
const router = new FreeLLMAdmin();
|
|
488
515
|
try {
|
|
489
|
-
await
|
|
516
|
+
await owned?.connect();
|
|
517
|
+
options.signal?.throwIfAborted();
|
|
490
518
|
const saved = await readLocalAdmin();
|
|
491
519
|
if (!saved && process.env.MILO_ROUTER_RUNTIME !== 'docker') {
|
|
492
520
|
const database = join(dirname(localAdminPath()), 'freellmapi', 'router.db');
|
|
@@ -512,17 +540,27 @@ export async function setup(notify = console.log, providers = ['groq']) {
|
|
|
512
540
|
if (!saved)
|
|
513
541
|
await saveLocalAdmin(admin);
|
|
514
542
|
const { ensureNativeRouter } = await import('./native-router.js');
|
|
515
|
-
|
|
543
|
+
let running = false;
|
|
544
|
+
if (saved) {
|
|
545
|
+
try {
|
|
546
|
+
await router.login(admin.password);
|
|
547
|
+
running = true;
|
|
548
|
+
}
|
|
549
|
+
catch { /* Repair an unavailable backend. */ }
|
|
550
|
+
}
|
|
551
|
+
if (!running)
|
|
552
|
+
await ensureNativeRouter(options.signal);
|
|
516
553
|
}
|
|
517
554
|
let ready = false;
|
|
518
555
|
for (let attempt = 0; attempt < 60; attempt++) {
|
|
556
|
+
options.signal?.throwIfAborted();
|
|
519
557
|
try {
|
|
520
558
|
await router.login(admin.password);
|
|
521
559
|
ready = true;
|
|
522
560
|
break;
|
|
523
561
|
}
|
|
524
562
|
catch {
|
|
525
|
-
await delay(1000);
|
|
563
|
+
await delay(1000, undefined, options.signal ? { signal: options.signal } : {});
|
|
526
564
|
}
|
|
527
565
|
}
|
|
528
566
|
if (!ready)
|
|
@@ -545,6 +583,6 @@ export async function setup(notify = console.log, providers = ['groq']) {
|
|
|
545
583
|
throw new Error('FreeLLMAPI installation failed; check Node and npm availability and run npx usegrunt setup again');
|
|
546
584
|
}
|
|
547
585
|
finally {
|
|
548
|
-
await
|
|
586
|
+
await owned?.close();
|
|
549
587
|
}
|
|
550
588
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Interactive child processes (for example sudo) and browser confirmations
|
|
2
|
+
// must never read stdin at the same time. Noninteractive jobs stay concurrent.
|
|
3
|
+
let tail = Promise.resolve();
|
|
4
|
+
export function withTerminal(task) {
|
|
5
|
+
const result = tail.then(task);
|
|
6
|
+
tail = result.catch(() => { });
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Group handoffs arriving together; only one terminal prompt may own stdin.
|
|
2
|
+
// Other installation/browser jobs keep running while the user verifies.
|
|
3
|
+
export class VerificationQueue {
|
|
4
|
+
confirm;
|
|
5
|
+
pending = [];
|
|
6
|
+
running = false;
|
|
7
|
+
constructor(confirm) {
|
|
8
|
+
this.confirm = confirm;
|
|
9
|
+
}
|
|
10
|
+
wait(item) {
|
|
11
|
+
const result = new Promise((resolve, reject) => this.pending.push({ item, resolve, reject }));
|
|
12
|
+
if (!this.running) {
|
|
13
|
+
this.running = true;
|
|
14
|
+
setImmediate(() => { void this.drain(); });
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
async drain() {
|
|
19
|
+
while (this.pending.length) {
|
|
20
|
+
const batch = this.pending.splice(0);
|
|
21
|
+
try {
|
|
22
|
+
await this.confirm(batch.map(entry => entry.item));
|
|
23
|
+
batch.forEach(entry => entry.resolve());
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
[...batch, ...this.pending.splice(0)].forEach(entry => entry.reject(error));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
this.running = false;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/local/wizard.js
CHANGED
|
@@ -8,6 +8,8 @@ import { setTimeout as delay } from 'node:timers/promises';
|
|
|
8
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 { parallelMap } from './parallel.js';
|
|
12
|
+
import { withTerminal } from './terminal.js';
|
|
11
13
|
import { DOCTOR_TIMEOUT_MS } from './freebuff.js';
|
|
12
14
|
import { BrowserSquire, PROVIDERS, setup, squireEnvironment } from './setup.js';
|
|
13
15
|
import { RegistrySync } from './registry.js';
|
|
@@ -16,11 +18,12 @@ import { banner } from './banner.js';
|
|
|
16
18
|
import { HARNESSES, configurePi, connectHarness, detectHarnesses } from './harnesses.js';
|
|
17
19
|
export const configDir = (env = process.env) => env.MILO_CONFIG_DIR || join(env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'milo');
|
|
18
20
|
export async function command(binary, args, interactive = false, signal) {
|
|
19
|
-
|
|
21
|
+
const run = () => new Promise((resolve, reject) => {
|
|
20
22
|
const child = spawn(binary, args, { stdio: interactive ? 'inherit' : 'ignore', ...(signal ? { signal } : {}) });
|
|
21
23
|
child.once('error', () => reject(new Error(`Could not run ${binary}`)));
|
|
22
24
|
child.once('exit', code => code === 0 ? resolve() : reject(new Error(`${binary} failed; inspect its service status before retrying`)));
|
|
23
25
|
});
|
|
26
|
+
await (interactive ? withTerminal(run) : run());
|
|
24
27
|
}
|
|
25
28
|
async function step(label, task, done = () => label) {
|
|
26
29
|
const progress = spinner();
|
|
@@ -67,11 +70,12 @@ export async function squireBrokerExists() {
|
|
|
67
70
|
return result.stdout === 'present';
|
|
68
71
|
}
|
|
69
72
|
export async function connectSquire(options = {}) {
|
|
70
|
-
const probe = async () => { const squire = new BrowserSquire(); try {
|
|
73
|
+
const probe = async () => { const squire = options.squire ?? new BrowserSquire(); try {
|
|
71
74
|
await squire.connect();
|
|
72
75
|
}
|
|
73
76
|
finally {
|
|
74
|
-
|
|
77
|
+
if (!options.squire)
|
|
78
|
+
await squire.close();
|
|
75
79
|
} };
|
|
76
80
|
try {
|
|
77
81
|
await probe();
|
|
@@ -128,17 +132,27 @@ export async function preflight(run = command) {
|
|
|
128
132
|
const systemdQuote = (value) => '"' + value.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('%', '%%').replaceAll('$', '$$').replaceAll('\n', '\\n') + '"';
|
|
129
133
|
const xml = (value) => value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
130
134
|
export async function installedSources(directory = configDir()) {
|
|
135
|
+
try {
|
|
136
|
+
const sources = JSON.parse(await readFile(join(directory, 'installed-sources.json'), 'utf8'));
|
|
137
|
+
if (!Array.isArray(sources) || !sources.length || sources.some(id => typeof id !== 'string' || ![...knownAdapters, 'freellmapi'].includes(id)))
|
|
138
|
+
throw new Error('Invalid saved grunt sources');
|
|
139
|
+
return [...new Set(sources)].join(',');
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (error.code !== 'ENOENT')
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
131
145
|
try {
|
|
132
146
|
await access(join(directory, 'router-admin.json'));
|
|
133
147
|
}
|
|
134
148
|
catch (error) {
|
|
135
149
|
if (error.code !== 'ENOENT')
|
|
136
150
|
throw error;
|
|
137
|
-
return 'freebuff,opencode';
|
|
151
|
+
return 'freebuff,opencode,kilo';
|
|
138
152
|
}
|
|
139
153
|
return 'freellmapi,kilo,freebuff,opencode';
|
|
140
154
|
}
|
|
141
|
-
export async function installService() {
|
|
155
|
+
export async function installService(adapters) {
|
|
142
156
|
if (!['linux', 'darwin'].includes(process.platform))
|
|
143
157
|
throw new Error('grunt background service requires systemd or launchd');
|
|
144
158
|
const directory = configDir(), runtime = join(directory, 'runtime');
|
|
@@ -153,7 +167,7 @@ export async function installService() {
|
|
|
153
167
|
const port = process.env.MILO_PORT || '8788';
|
|
154
168
|
if (!/^\d+$/.test(port) || Number(port) < 1 || Number(port) > 65535)
|
|
155
169
|
throw new Error('Invalid grunt service port');
|
|
156
|
-
const env = { GRUNT_DAEMON: '1', MILO_CONFIG_DIR: directory, MILO_PORT: port, MILO_SOURCES: await installedSources(directory), PATH: process.env.PATH || '/usr/local/bin:/usr/bin:/bin' };
|
|
170
|
+
const env = { GRUNT_DAEMON: '1', MILO_CONFIG_DIR: directory, MILO_PORT: port, MILO_SOURCES: adapters?.join(',') ?? await installedSources(directory), PATH: process.env.PATH || '/usr/local/bin:/usr/bin:/bin' };
|
|
157
171
|
if (process.env.MILO_FREELLMAPI_URL)
|
|
158
172
|
env.MILO_FREELLMAPI_URL = process.env.MILO_FREELLMAPI_URL;
|
|
159
173
|
const opencodeConfig = join(directory, 'opencode-free.json');
|
|
@@ -166,6 +180,7 @@ export async function installService() {
|
|
|
166
180
|
throw error;
|
|
167
181
|
}
|
|
168
182
|
await installBackgroundService('milo', entry, env);
|
|
183
|
+
await writeFile(join(directory, 'installed-sources.json'), JSON.stringify(env.MILO_SOURCES.split(',')), { mode: 0o600 });
|
|
169
184
|
}
|
|
170
185
|
export async function installBackgroundService(name, entry, env) {
|
|
171
186
|
if (!/^[a-z][a-z0-9-]*$/.test(name))
|
|
@@ -380,79 +395,77 @@ export async function connectHarnesses(port, options = {}) {
|
|
|
380
395
|
note(connected.map(h => `${chalk.bold(h.name)}\n ${h.launch(port)}`).join('\n'), 'Start coding with grunt');
|
|
381
396
|
return connected;
|
|
382
397
|
}
|
|
383
|
-
const wizardActions = { banner, preflight, connectSquire, setup, setupFallbacks, installService, configurePi, checkService, checkFallbackServices, loadRegistry, checkServiceSources, connectHarnesses };
|
|
398
|
+
const wizardActions = { installedSources, createSquire: () => new BrowserSquire(), banner, preflight, connectSquire, setup, setupFallbacks, installService, configurePi, checkService, checkFallbackServices, loadRegistry, checkServiceSources, connectHarnesses };
|
|
384
399
|
export async function wizard(add, actions = wizardActions) {
|
|
385
400
|
if (add && !Object.hasOwn(PROVIDERS, add))
|
|
386
401
|
throw new Error(`Choose a supported provider: ${Object.keys(PROVIDERS).join(', ')}`);
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
await step('
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (pulled.origin === 'remote')
|
|
404
|
-
log.info(`Registry: ${registry.adapters.length} free services, published ${published}`);
|
|
405
|
-
else
|
|
406
|
-
log.warn(`Registry unreachable; using the ${pulled.origin === 'cache' ? 'list saved by an earlier setup' : 'list bundled with this version'} (published ${published})`);
|
|
407
|
-
const adapters = registry.adapters.filter(adapter => knownAdapters.has(adapter.id));
|
|
408
|
-
log.message(registry.adapters.map(adapter => knownAdapters.has(adapter.id)
|
|
409
|
-
? `${chalk.bold(adapter.id.padEnd(10))} ${chalk.dim(describe(adapter))}`
|
|
410
|
-
: `${chalk.dim(adapter.id.padEnd(10))} ${chalk.dim('skipped: needs a newer usegrunt')}`).join('\n'));
|
|
411
|
-
const ids = adapters.map(adapter => adapter.id);
|
|
412
|
-
const results = new Map(ids.map(id => [id, {}]));
|
|
413
|
-
const unavailable = [];
|
|
414
|
-
const notify = report();
|
|
415
|
-
log.step(`Signing up for ${ids.length} free services`);
|
|
416
|
-
for (const id of ids) {
|
|
417
|
-
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`);
|
|
418
|
-
const failed = outcome.unavailable.includes(id);
|
|
419
|
-
if (failed)
|
|
420
|
-
unavailable.push(id);
|
|
421
|
-
results.get(id).signup = failed ? 'fail' : 'pass';
|
|
422
|
-
}
|
|
423
|
-
log.step('Connecting the services to the grunt daemon');
|
|
424
|
-
await step('Starting the grunt background service', actions.installService);
|
|
425
|
-
const port = Number(process.env.MILO_PORT || '8788');
|
|
426
|
-
await step(`Waiting for grunt to answer at http://127.0.0.1:${port}`, () => actions.checkService(port));
|
|
427
|
-
const beforeSources = new Set(unavailable);
|
|
428
|
-
if (actions.checkServiceSources)
|
|
429
|
-
await step('Checking which services the daemon runs', () => actions.checkServiceSources(unavailable, notify, ids));
|
|
430
|
-
for (const id of ids)
|
|
431
|
-
results.get(id).daemon = beforeSources.has(id) ? 'skip' : unavailable.includes(id) ? 'fail' : 'pass';
|
|
432
|
-
log.step('Testing each service with a real request through grunt');
|
|
433
|
-
for (const id of ids) {
|
|
434
|
-
const before = unavailable.includes(id);
|
|
435
|
-
// Hold the result line until the spinner is gone so the two do not share a row.
|
|
436
|
-
const lines = [], progress = spinner();
|
|
437
|
-
progress.start(`${id}: sending a test request through grunt`);
|
|
438
|
-
try {
|
|
439
|
-
await actions.checkFallbackServices(unavailable, port, line => lines.push(line), [id]);
|
|
440
|
-
}
|
|
441
|
-
finally {
|
|
442
|
-
progress.clear();
|
|
443
|
-
lines.forEach(notify);
|
|
402
|
+
const squire = actions.createSquire?.();
|
|
403
|
+
try {
|
|
404
|
+
await actions.banner?.();
|
|
405
|
+
intro(chalk.hex('#f4b41a').bold('grunt') + chalk.dim(' — npx usegrunt setup'));
|
|
406
|
+
note(PREAMBLE, 'What grunt does');
|
|
407
|
+
await step('Checking prerequisites', () => actions.preflight());
|
|
408
|
+
note(SQUIRE_NOTICE, 'Google sign-in for Trusty Squire');
|
|
409
|
+
await step('Connecting Trusty Squire', () => actions.connectSquire(squire ? { squire } : {}));
|
|
410
|
+
// Capture legacy API routing before default Kilo setup creates its admin file.
|
|
411
|
+
const previous = (await actions.installedSources?.())?.split(',') ?? [];
|
|
412
|
+
if (add) {
|
|
413
|
+
await step('FreeLLMAPI and provider grants', () => actions.setup(line => log.info(line), [add], squire ? { squire } : {}));
|
|
414
|
+
await step('Starting the grunt background service', () => actions.installService(add !== 'kilo' ? [...new Set(['freellmapi', ...previous, ...knownAdapters])] : undefined));
|
|
415
|
+
await step('Waiting for grunt to answer', () => actions.checkService(Number(process.env.MILO_PORT || '8788')));
|
|
416
|
+
outro(`${add} connected`);
|
|
417
|
+
return;
|
|
444
418
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
419
|
+
const pulled = actions.loadRegistry ? await step('Pulling the free service list from the registry', () => actions.loadRegistry()) : { registry: bundledRegistry, origin: 'bundled' };
|
|
420
|
+
const { registry } = pulled;
|
|
421
|
+
const published = registry.published.slice(0, 10);
|
|
422
|
+
if (pulled.origin === 'remote')
|
|
423
|
+
log.info(`Registry: ${registry.adapters.length} free services, published ${published}`);
|
|
424
|
+
else
|
|
425
|
+
log.warn(`Registry unreachable; using the ${pulled.origin === 'cache' ? 'list saved by an earlier setup' : 'list bundled with this version'} (published ${published})`);
|
|
426
|
+
const adapters = registry.adapters.filter(adapter => knownAdapters.has(adapter.id));
|
|
427
|
+
log.message(registry.adapters.map(adapter => knownAdapters.has(adapter.id)
|
|
428
|
+
? `${chalk.bold(adapter.id.padEnd(10))} ${chalk.dim(describe(adapter))}`
|
|
429
|
+
: `${chalk.dim(adapter.id.padEnd(10))} ${chalk.dim('skipped: needs a newer usegrunt')}`).join('\n'));
|
|
430
|
+
const ids = adapters.map(adapter => adapter.id);
|
|
431
|
+
const results = new Map(ids.map(id => [id, {}]));
|
|
432
|
+
const unavailable = [];
|
|
433
|
+
const notify = report();
|
|
434
|
+
log.step(`Installing and connecting ${ids.length} vetted free services (up to 3 at once)`);
|
|
435
|
+
log.info('Trusty Squire reuses existing accounts and grants. Only free access is requested. Provider verification may still need your browser; verification prompts are queued.');
|
|
436
|
+
const outcome = await actions.setupFallbacks({ directory: configDir(), run: command, adapters: ids, notify,
|
|
437
|
+
...(squire ? { squire, connect: () => squire.connect() } : {}) });
|
|
438
|
+
unavailable.push(...outcome.unavailable);
|
|
439
|
+
for (const id of ids)
|
|
440
|
+
results.get(id).signup = unavailable.includes(id) ? 'fail' : 'pass';
|
|
441
|
+
log.step('Connecting the services to the grunt daemon');
|
|
442
|
+
await step('Starting the grunt background service', () => actions.installService([...new Set([...previous.filter(id => id === 'freellmapi'), ...ids])]));
|
|
443
|
+
const port = Number(process.env.MILO_PORT || '8788');
|
|
444
|
+
await step(`Waiting for grunt to answer at http://127.0.0.1:${port}`, () => actions.checkService(port));
|
|
445
|
+
const beforeSources = new Set(unavailable);
|
|
446
|
+
if (actions.checkServiceSources)
|
|
447
|
+
await step('Checking which services the daemon runs', () => actions.checkServiceSources(unavailable, notify, ids));
|
|
448
|
+
for (const id of ids)
|
|
449
|
+
results.get(id).daemon = beforeSources.has(id) ? 'skip' : unavailable.includes(id) ? 'fail' : 'pass';
|
|
450
|
+
log.step('Testing each service with a real request through grunt');
|
|
451
|
+
await parallelMap(ids, async (id) => {
|
|
452
|
+
const before = unavailable.includes(id);
|
|
453
|
+
await actions.checkFallbackServices(unavailable, port, notify, [id]);
|
|
454
|
+
results.get(id).check = before ? 'skip' : unavailable.includes(id) ? 'fail' : 'pass';
|
|
455
|
+
});
|
|
456
|
+
note([`${'service'.padEnd(10)} sign-in daemon test`, ...ids.map(id => {
|
|
457
|
+
const r = results.get(id);
|
|
458
|
+
return `${id.padEnd(10)} ${mark(r.signup)} ${mark(r.daemon)} ${mark(r.check)}`;
|
|
459
|
+
})].join('\n'), 'Free services');
|
|
460
|
+
if (actions.connectHarnesses)
|
|
461
|
+
await actions.connectHarnesses(port);
|
|
462
|
+
else if (actions.configurePi)
|
|
463
|
+
await step('Pi provider', () => actions.configurePi(port));
|
|
464
|
+
outro(unavailable.length ? `grunt is ready; incomplete fallbacks: ${unavailable.join(', ')}. Rerun setup to finish them.` : 'grunt is ready');
|
|
465
|
+
if (unavailable.length)
|
|
466
|
+
throw new Error('Some adapters failed verification. Run usegrunt setup to resume.');
|
|
467
|
+
}
|
|
468
|
+
finally {
|
|
469
|
+
await squire?.close();
|
|
470
|
+
}
|
|
458
471
|
}
|
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 1,
|
|
3
|
-
"published": "2026-11-
|
|
3
|
+
"published": "2026-11-14T22:10:00Z",
|
|
4
4
|
"adapters": [
|
|
5
|
-
{
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
5
|
+
{
|
|
6
|
+
"id": "freebuff",
|
|
7
|
+
"kind": "agent",
|
|
8
|
+
"tier": "stable",
|
|
9
|
+
"weight": 0.3,
|
|
10
|
+
"modalities": [
|
|
11
|
+
"text"
|
|
12
|
+
],
|
|
13
|
+
"install": "npm:freebuff",
|
|
14
|
+
"signup": "https://freebuff.com/login"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "opencode",
|
|
18
|
+
"kind": "agent",
|
|
19
|
+
"tier": "stable",
|
|
20
|
+
"weight": 0.3,
|
|
21
|
+
"modalities": [
|
|
22
|
+
"text"
|
|
23
|
+
],
|
|
24
|
+
"install": "npm:opencode-ai",
|
|
25
|
+
"model": "big-pickle"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "kilo",
|
|
29
|
+
"kind": "model",
|
|
30
|
+
"tier": "stable",
|
|
31
|
+
"weight": 0.4,
|
|
32
|
+
"modalities": [
|
|
33
|
+
"text"
|
|
34
|
+
],
|
|
35
|
+
"install": "builtin:kilo",
|
|
36
|
+
"signup": "https://app.kilo.ai/profile",
|
|
37
|
+
"model": "kilo-auto/free"
|
|
38
|
+
}
|
|
9
39
|
]
|
|
10
40
|
}
|
package/dist/registry.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
|
-
|
|
3
|
+
const installers = { freebuff: 'npm:freebuff', opencode: 'npm:opencode-ai', kilo: 'builtin:kilo' };
|
|
4
|
+
export const knownAdapters = new Set(Object.keys(installers));
|
|
4
5
|
export function validateRegistry(value) {
|
|
5
6
|
const fail = () => { throw new Error('Invalid adapter registry'); };
|
|
6
7
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
@@ -19,7 +20,7 @@ export function validateRegistry(value) {
|
|
|
19
20
|
|| !['agent', 'model'].includes(String(a.kind)) || !['stable', 'experimental'].includes(String(a.tier))
|
|
20
21
|
|| typeof a.weight !== 'number' || !Number.isFinite(a.weight) || a.weight <= 0 || a.weight > 1
|
|
21
22
|
|| !Array.isArray(a.modalities) || !a.modalities.length || a.modalities.some(m => !['text', 'image'].includes(m))
|
|
22
|
-
|| new Set(a.modalities).size !== a.modalities.length || typeof a.install !== 'string' ||
|
|
23
|
+
|| new Set(a.modalities).size !== a.modalities.length || typeof a.install !== 'string' || !(/^npm:[a-z0-9@/._-]+$/.test(a.install) || (a.id === 'kilo' && a.install === 'builtin:kilo'))
|
|
23
24
|
|| (a.model !== undefined && (typeof a.model !== 'string' || !a.model.trim())))
|
|
24
25
|
return fail();
|
|
25
26
|
if (a.signup !== undefined) {
|
|
@@ -36,7 +37,7 @@ export function validateRegistry(value) {
|
|
|
36
37
|
return fail();
|
|
37
38
|
}
|
|
38
39
|
// Known adapters have fixed installers and capabilities; registry data never supplies code.
|
|
39
|
-
if (knownAdapters.has(a.id) && (a.kind !==
|
|
40
|
+
if (knownAdapters.has(a.id) && (a.kind !== (a.id === 'kilo' ? 'model' : 'agent') || a.install !== installers[a.id]
|
|
40
41
|
|| a.modalities.some(m => m !== 'text')))
|
|
41
42
|
return fail();
|
|
42
43
|
ids.add(a.id);
|