usegrunt 0.6.2 → 0.6.3

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.
@@ -15,6 +15,7 @@ import { BrowserSquire, PROVIDERS, setup, squireEnvironment } from './setup.js';
15
15
  import { RegistrySync } from './registry.js';
16
16
  import { bundledRegistry, knownAdapters } from '../registry.js';
17
17
  import { banner } from './banner.js';
18
+ import { approveDataSharing, requiresDataSharing } from './data-sharing.js';
18
19
  import { HARNESSES, configurePi, connectHarness, detectHarnesses } from './harnesses.js';
19
20
  export const configDir = (env = process.env) => env.MILO_CONFIG_DIR || join(env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'milo');
20
21
  export async function command(binary, args, interactive = false, signal) {
@@ -101,7 +102,6 @@ export async function preflight(run = command) {
101
102
  throw new Error('Run setup on Linux with systemd or macOS with launchd.');
102
103
  for (const [binary, args, fix] of [
103
104
  ['npm', ['--version'], 'Install Node.js 22 or 24 LTS including npm.'],
104
- ['pi', ['--version'], 'Run npm install --global @mariozechner/pi-coding-agent.'],
105
105
  ['tar', ['--version'], 'Install tar using your system package manager.']
106
106
  ]) {
107
107
  try {
@@ -148,9 +148,9 @@ export async function installedSources(directory = configDir()) {
148
148
  catch (error) {
149
149
  if (error.code !== 'ENOENT')
150
150
  throw error;
151
- return 'freebuff,opencode,kilo';
151
+ return 'freebuff,opencode,kilo,zro';
152
152
  }
153
- return 'freellmapi,kilo,freebuff,opencode';
153
+ return 'freellmapi,kilo,freebuff,opencode,zro';
154
154
  }
155
155
  export async function installService(adapters) {
156
156
  if (!['linux', 'darwin'].includes(process.platform))
@@ -395,7 +395,7 @@ export async function connectHarnesses(port, options = {}) {
395
395
  note(connected.map(h => `${chalk.bold(h.name)}\n ${h.launch(port)}`).join('\n'), 'Start coding with grunt');
396
396
  return connected;
397
397
  }
398
- const wizardActions = { installedSources, createSquire: () => new BrowserSquire(), 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, approveDataSharing };
399
399
  export async function wizard(add, actions = wizardActions) {
400
400
  if (add && !Object.hasOwn(PROVIDERS, add))
401
401
  throw new Error(`Choose a supported provider: ${Object.keys(PROVIDERS).join(', ')}`);
@@ -410,8 +410,29 @@ export async function wizard(add, actions = wizardActions) {
410
410
  // Capture legacy API routing before default Kilo setup creates its admin file.
411
411
  const previous = (await actions.installedSources?.())?.split(',') ?? [];
412
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));
413
+ const defaults = bundledRegistry.adapters.filter(adapter => knownAdapters.has(adapter.id)).map(adapter => adapter.id);
414
+ const sources = ['kilo', 'nvidia', 'zro', 'tokenharbor'].includes(add)
415
+ ? [...new Set([...(previous.length ? previous : defaults), add])]
416
+ : [...new Set(['freellmapi', ...previous, ...defaults])];
417
+ const consent = await (actions.approveDataSharing ?? approveDataSharing)({ directory: configDir(), providers: sources });
418
+ if (consent.skipped.includes(add)) {
419
+ // A declined addition still needs to replace a previously installed
420
+ // runtime that predates consent enforcement. Keep only prior choices.
421
+ if (previous.length) {
422
+ await step('Updating the grunt background service', () => actions.installService(previous));
423
+ await step('Waiting for grunt to answer', () => actions.checkService(Number(process.env.MILO_PORT || '8788')));
424
+ }
425
+ outro(`${add} skipped; data sharing was not approved`);
426
+ return;
427
+ }
428
+ squire?.approveDataSharing?.(consent.approved);
429
+ const consentOptions = consent.approved.length ? { dataSharingApproved: consent.approved } : {};
430
+ await step('Connecting free provider access', () => actions.setup(line => log.info(line), [add], { ...(squire ? { squire } : {}), ...consentOptions }));
431
+ // Explicit additions must survive the saved source list from an older
432
+ // install. Keep its routing choices rather than enabling every adapter.
433
+ const approved = new Set(consent.approved);
434
+ const enabled = sources.filter(id => !requiresDataSharing(id) || approved.has(id));
435
+ await step('Starting the grunt background service', () => actions.installService(enabled));
415
436
  await step('Waiting for grunt to answer', () => actions.checkService(Number(process.env.MILO_PORT || '8788')));
416
437
  outro(`${add} connected`);
417
438
  return;
@@ -427,13 +448,29 @@ export async function wizard(add, actions = wizardActions) {
427
448
  log.message(registry.adapters.map(adapter => knownAdapters.has(adapter.id)
428
449
  ? `${chalk.bold(adapter.id.padEnd(10))} ${chalk.dim(describe(adapter))}`
429
450
  : `${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, {}]));
451
+ const requested = adapters.map(adapter => adapter.id);
452
+ const consent = await (actions.approveDataSharing ?? approveDataSharing)({ directory: configDir(), providers: requested });
453
+ squire?.approveDataSharing?.(consent.approved);
454
+ const ids = requested.filter(id => !consent.skipped.includes(id));
455
+ const results = new Map(requested.map(id => [id, consent.skipped.includes(id) ? { signup: 'skip', daemon: 'skip', check: 'skip' } : {}]));
432
456
  const unavailable = [];
433
457
  const notify = report();
458
+ if (consent.skipped.length)
459
+ log.info(`Skipped data-sharing services: ${consent.skipped.join(', ')}. Other free services continue.`);
460
+ if (!ids.length) {
461
+ // Upgrade older runtimes even after a declined batch: otherwise their
462
+ // existing provider sessions could keep routing without consent guards.
463
+ // Honor registry removals, while retaining a user's custom API routing.
464
+ const retained = previous.filter(id => id === 'freellmapi' || requested.includes(id));
465
+ await step('Updating the grunt background service', () => actions.installService(retained.length ? retained : requested));
466
+ await step('Waiting for grunt to answer', () => actions.checkService(Number(process.env.MILO_PORT || '8788')));
467
+ outro('No approved free services are available; the background service now enforces your data-sharing choices');
468
+ return;
469
+ }
434
470
  log.step(`Installing and connecting ${ids.length} vetted free services (up to 3 at once)`);
435
471
  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
472
  const outcome = await actions.setupFallbacks({ directory: configDir(), run: command, adapters: ids, notify,
473
+ ...(consent.approved.length ? { dataSharingApproved: consent.approved } : {}),
437
474
  ...(squire ? { squire, connect: () => squire.connect() } : {}) });
438
475
  unavailable.push(...outcome.unavailable);
439
476
  for (const id of ids)
@@ -453,7 +490,7 @@ export async function wizard(add, actions = wizardActions) {
453
490
  await actions.checkFallbackServices(unavailable, port, notify, [id]);
454
491
  results.get(id).check = before ? 'skip' : unavailable.includes(id) ? 'fail' : 'pass';
455
492
  });
456
- note([`${'service'.padEnd(10)} sign-in daemon test`, ...ids.map(id => {
493
+ note([`${'service'.padEnd(10)} sign-in daemon test`, ...requested.map(id => {
457
494
  const r = results.get(id);
458
495
  return `${id.padEnd(10)} ${mark(r.signup)} ${mark(r.daemon)} ${mark(r.check)}`;
459
496
  })].join('\n'), 'Free services');
@@ -0,0 +1,79 @@
1
+ import { constants } from 'node:fs';
2
+ import { mkdir, open, rename, rm, writeFile } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { randomUUID } from 'node:crypto';
6
+ import { FreeApi, isDeepSeekV41Model } from './free-api.js';
7
+ import { verifiedDeepSeekFetch } from './deepseek-response.js';
8
+ export const ZRO_DEEPSEEK = 'deepseek-v4.1-flash';
9
+ const directory = () => process.env.MILO_CONFIG_DIR || join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'milo');
10
+ function validate(value) {
11
+ const grant = value;
12
+ if (!grant || typeof grant.base_url !== 'string' || typeof grant.token !== 'string' || !grant.token.trim()
13
+ || grant.free_account_verified !== true || typeof grant.verified_at !== 'string' || !Number.isFinite(Date.parse(grant.verified_at)))
14
+ throw new Error('Zro free account verification is missing');
15
+ const url = new URL(grant.base_url);
16
+ if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash)
17
+ throw new Error('Invalid Zro grant endpoint');
18
+ return { base_url: grant.base_url.replace(/\/$/, ''), token: grant.token, free_account_verified: true, verified_at: grant.verified_at };
19
+ }
20
+ export async function readZroGrant(location = directory()) {
21
+ const file = await open(join(location, 'zro.json'), constants.O_RDONLY | constants.O_NOFOLLOW);
22
+ try {
23
+ const stat = await file.stat();
24
+ if (!stat.isFile() || (stat.mode & 0o777) !== 0o600 || stat.uid !== process.getuid?.())
25
+ throw new Error('Unsafe Zro grant file');
26
+ return validate(JSON.parse(await file.readFile('utf8')));
27
+ }
28
+ finally {
29
+ await file.close();
30
+ }
31
+ }
32
+ // Called after Squire has confirmed Free plan, no purchased balance and no payment method.
33
+ // This is a setup receipt, not a guarantee that an externally upgraded account stays free.
34
+ export async function writeZroGrant(grant, location = directory()) {
35
+ const value = validate({ ...grant, free_account_verified: true, verified_at: new Date().toISOString() });
36
+ const temporary = join(location, `zro.${randomUUID()}.tmp`);
37
+ await mkdir(location, { recursive: true, mode: 0o700 });
38
+ try {
39
+ await writeFile(temporary, JSON.stringify(value), { mode: 0o600, flag: 'wx' });
40
+ await rename(temporary, join(location, 'zro.json'));
41
+ }
42
+ finally {
43
+ await rm(temporary, { force: true });
44
+ }
45
+ }
46
+ export class Zro {
47
+ options;
48
+ id = 'zro';
49
+ supportsFunctionTools = true;
50
+ source;
51
+ constructor(options = {}) {
52
+ this.options = options;
53
+ this.source = new FreeApi('zro', { ...options, fetcher: verifiedDeepSeekFetch(options.fetcher), loadGrant: () => this.grant() });
54
+ }
55
+ grant() { return (this.options.loadGrant?.() ?? readZroGrant(this.options.directory)).then(validate); }
56
+ async available() {
57
+ try {
58
+ const grant = await this.grant();
59
+ const response = await (this.options.fetcher ?? fetch)(`${grant.base_url}/v1/models`, {
60
+ headers: { Authorization: `Bearer ${grant.token}` }, redirect: 'error', signal: AbortSignal.timeout(5000)
61
+ });
62
+ if (!response.ok) {
63
+ await response.body?.cancel();
64
+ return false;
65
+ }
66
+ const result = await response.json();
67
+ return result.data?.some(model => isDeepSeekV41Model(model.id)) ?? false;
68
+ }
69
+ catch {
70
+ return false;
71
+ }
72
+ }
73
+ async healthCheck() { return this.available(); }
74
+ complete(request, signal) {
75
+ // Router aliases select this source; they never select another upstream model.
76
+ return this.source.complete({ ...request, model: this.id }, signal);
77
+ }
78
+ async close() { await this.source.close(); }
79
+ }
@@ -6,7 +6,7 @@
6
6
  "id": "freebuff",
7
7
  "kind": "agent",
8
8
  "tier": "stable",
9
- "weight": 0.3,
9
+ "weight": 0.192,
10
10
  "modalities": [
11
11
  "text"
12
12
  ],
@@ -17,24 +17,52 @@
17
17
  "id": "opencode",
18
18
  "kind": "agent",
19
19
  "tier": "stable",
20
- "weight": 0.3,
20
+ "weight": 0.192,
21
21
  "modalities": [
22
22
  "text"
23
23
  ],
24
24
  "install": "npm:opencode-ai",
25
- "model": "big-pickle"
25
+ "models": [
26
+ "deepseek-v4.1-flash-free",
27
+ "glm-5.3-flash-free",
28
+ "big-pickle"
29
+ ]
26
30
  },
27
31
  {
28
32
  "id": "kilo",
29
33
  "kind": "model",
30
34
  "tier": "stable",
31
- "weight": 0.4,
35
+ "weight": 0.256,
32
36
  "modalities": [
33
37
  "text"
34
38
  ],
35
39
  "install": "builtin:kilo",
36
40
  "signup": "https://app.kilo.ai/profile",
37
41
  "model": "kilo-auto/free"
42
+ },
43
+ {
44
+ "id": "zro",
45
+ "kind": "model",
46
+ "tier": "stable",
47
+ "weight": 0.16,
48
+ "modalities": [
49
+ "text"
50
+ ],
51
+ "install": "builtin:zro",
52
+ "signup": "https://zro.moonmath.ai/overview",
53
+ "model": "deepseek-v4.1-flash"
54
+ },
55
+ {
56
+ "id": "tokenharbor",
57
+ "kind": "model",
58
+ "tier": "experimental",
59
+ "weight": 0.2,
60
+ "modalities": [
61
+ "text"
62
+ ],
63
+ "install": "builtin:tokenharbor",
64
+ "signup": "https://tokenharbor.ai/dashboard",
65
+ "model": "deepseek-v4.1-flash:free"
38
66
  }
39
67
  ]
40
68
  }
package/dist/registry.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { pathToFileURL } from 'node:url';
3
- const installers = { freebuff: 'npm:freebuff', opencode: 'npm:opencode-ai', kilo: 'builtin:kilo' };
3
+ const installers = { freebuff: 'npm:freebuff', opencode: 'npm:opencode-ai', kilo: 'builtin:kilo', nvidia: 'builtin:nvidia', zro: 'builtin:zro', tokenharbor: 'builtin:tokenharbor' };
4
4
  export const knownAdapters = new Set(Object.keys(installers));
5
5
  export function validateRegistry(value) {
6
6
  const fail = () => { throw new Error('Invalid adapter registry'); };
@@ -20,8 +20,10 @@ export function validateRegistry(value) {
20
20
  || !['agent', 'model'].includes(String(a.kind)) || !['stable', 'experimental'].includes(String(a.tier))
21
21
  || typeof a.weight !== 'number' || !Number.isFinite(a.weight) || a.weight <= 0 || a.weight > 1
22
22
  || !Array.isArray(a.modalities) || !a.modalities.length || a.modalities.some(m => !['text', 'image'].includes(m))
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'))
24
- || (a.model !== undefined && (typeof a.model !== 'string' || !a.model.trim())))
23
+ || new Set(a.modalities).size !== a.modalities.length || typeof a.install !== 'string' || !(/^npm:[a-z0-9@/._-]+$/.test(a.install) || (['kilo', 'nvidia', 'zro', 'tokenharbor'].includes(String(a.id)) && a.install === `builtin:${a.id}`))
24
+ || (a.model !== undefined && (typeof a.model !== 'string' || !a.model.trim()))
25
+ || (a.models !== undefined && (a.id !== 'opencode' || a.model !== undefined || !Array.isArray(a.models) || !a.models.length || a.models.length > 20
26
+ || a.models.some(model => typeof model !== 'string' || !model.trim()) || new Set(a.models).size !== a.models.length)))
25
27
  return fail();
26
28
  if (a.signup !== undefined) {
27
29
  if (typeof a.signup !== 'string')
@@ -37,7 +39,7 @@ export function validateRegistry(value) {
37
39
  return fail();
38
40
  }
39
41
  // Known adapters have fixed installers and capabilities; registry data never supplies code.
40
- if (knownAdapters.has(a.id) && (a.kind !== (a.id === 'kilo' ? 'model' : 'agent') || a.install !== installers[a.id]
42
+ if (knownAdapters.has(a.id) && (a.kind !== (['kilo', 'nvidia', 'zro', 'tokenharbor'].includes(a.id) ? 'model' : 'agent') || a.install !== installers[a.id]
41
43
  || a.modalities.some(m => m !== 'text')))
42
44
  return fail();
43
45
  ids.add(a.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usegrunt",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22"