usegrunt 0.6.4 → 0.6.6
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 +15 -6
- package/dist/local/beatapi-setup.js +83 -0
- package/dist/local/beatapi.js +298 -0
- package/dist/local/clixad-preload.js +177 -0
- package/dist/local/clixad-setup.js +345 -0
- package/dist/local/clixad.js +398 -0
- package/dist/local/data-sharing.js +18 -2
- package/dist/local/fallback-setup.js +74 -22
- package/dist/local/free-api.js +2 -1
- package/dist/local/freebuff.js +5 -1
- package/dist/local/freellmapi.js +3 -5
- package/dist/local/kilo.js +209 -0
- package/dist/local/livekit-setup.js +269 -0
- package/dist/local/livekit.js +219 -0
- package/dist/local/main.js +13 -11
- package/dist/local/parallel.js +2 -0
- package/dist/local/perch-process.js +377 -0
- package/dist/local/perch-setup.js +297 -0
- package/dist/local/perch.js +480 -0
- package/dist/local/pollinations-setup.js +109 -0
- package/dist/local/pollinations.js +324 -0
- package/dist/local/registry.js +4 -4
- package/dist/local/setup.js +340 -62
- package/dist/local/source.js +7 -2
- package/dist/local/wizard.js +24 -21
- package/dist/registry/adapters.json +65 -29
- package/dist/registry.js +4 -2
- package/package.json +1 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { lstat, mkdtemp, open, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { executable } from './multiplexer.js';
|
|
8
|
+
import { DATA_SHARING_POLICIES, readDataSharingConsent } from './data-sharing.js';
|
|
9
|
+
import { Clixad, CLIXAD_CORE_SHA256, CLIXAD_DASHBOARD, CLIXAD_INTEGRITY, CLIXAD_MODEL, CLIXAD_TARBALL, clixadEnvironment, clixadPaths, prepareClixadDirectories, readClixadInstallReceipt, verifyClixadAccess, verifyClixadPublicModel, writeClixadInstallReceipt } from './clixad.js';
|
|
10
|
+
const failure = () => new Error('Clixad free native setup did not complete; rerun usegrunt setup');
|
|
11
|
+
const modelFailure = () => new Error('Clixad already uses another model. Select GLM 5.3 Flash explicitly in the native CLI before rerunning setup; Grunt preserved the existing preference.');
|
|
12
|
+
export class ClixadNativeLoginRequired extends Error {
|
|
13
|
+
code = 'logged_out';
|
|
14
|
+
constructor() {
|
|
15
|
+
super('Sign in to the same Clixad account with the official CLI, then rerun usegrunt setup. The existing native profile was preserved.');
|
|
16
|
+
this.name = 'ClixadNativeLoginRequired';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function stop(child, force = false) {
|
|
20
|
+
try {
|
|
21
|
+
if (child.pid) {
|
|
22
|
+
if (process.platform === 'win32')
|
|
23
|
+
child.kill(force ? 'SIGKILL' : 'SIGTERM');
|
|
24
|
+
else
|
|
25
|
+
process.kill(-child.pid, force ? 'SIGKILL' : 'SIGTERM');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch { /* Only our owned process group is signalled. */ }
|
|
29
|
+
}
|
|
30
|
+
export const runClixadSetupCommand = async (binary, args, options) => {
|
|
31
|
+
options.signal.throwIfAborted();
|
|
32
|
+
return new Promise((resolveResult, reject) => {
|
|
33
|
+
const child = spawn(binary, args, { cwd: options.cwd, env: options.env, stdio: ['ignore', 'pipe', 'pipe'], detached: process.platform !== 'win32' });
|
|
34
|
+
let stdout = '', bytes = 0, failed = false, oversized = false;
|
|
35
|
+
let force;
|
|
36
|
+
const abort = () => { stop(child); force ??= setTimeout(() => stop(child, true), 1000); force.unref(); };
|
|
37
|
+
options.signal.addEventListener('abort', abort, { once: true });
|
|
38
|
+
if (options.signal.aborted)
|
|
39
|
+
abort();
|
|
40
|
+
const consume = (chunk, capture) => {
|
|
41
|
+
bytes += chunk.length;
|
|
42
|
+
if (bytes > 262144) {
|
|
43
|
+
oversized = true;
|
|
44
|
+
stop(child, true);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (capture)
|
|
48
|
+
stdout += chunk.toString('utf8');
|
|
49
|
+
try {
|
|
50
|
+
options.onOutput?.(chunk.toString('utf8'));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
failed = true;
|
|
54
|
+
stop(child, true);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
child.stdout.on('data', (chunk) => consume(chunk, true));
|
|
58
|
+
child.stderr.on('data', (chunk) => consume(chunk, false));
|
|
59
|
+
child.once('error', () => { failed = true; });
|
|
60
|
+
child.once('close', code => {
|
|
61
|
+
options.signal.removeEventListener('abort', abort);
|
|
62
|
+
if (force)
|
|
63
|
+
clearTimeout(force);
|
|
64
|
+
stop(child, true);
|
|
65
|
+
if (options.signal.aborted || failed || oversized)
|
|
66
|
+
reject(failure());
|
|
67
|
+
else
|
|
68
|
+
resolveResult({ code, stdout });
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
async function bounded(operation, signal) {
|
|
73
|
+
let abort;
|
|
74
|
+
try {
|
|
75
|
+
return await Promise.race([Promise.resolve().then(() => { if (signal.aborted)
|
|
76
|
+
throw failure(); return operation(); }), new Promise((_resolve, reject) => {
|
|
77
|
+
abort = () => reject(failure());
|
|
78
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
79
|
+
if (signal.aborted)
|
|
80
|
+
abort();
|
|
81
|
+
})]);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
if (abort)
|
|
85
|
+
signal.removeEventListener('abort', abort);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function coreFiles(directory) {
|
|
89
|
+
const paths = clixadPaths(directory);
|
|
90
|
+
for (const path of [paths.package, dirname(paths.entry)]) {
|
|
91
|
+
const stat = await lstat(path);
|
|
92
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || (stat.mode & 0o022))
|
|
93
|
+
throw failure();
|
|
94
|
+
}
|
|
95
|
+
for (const [name, expected] of Object.entries(CLIXAD_CORE_SHA256)) {
|
|
96
|
+
const file = await open(join(dirname(paths.entry), name), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
97
|
+
try {
|
|
98
|
+
const stat = await file.stat();
|
|
99
|
+
if (!stat.isFile() || stat.uid !== process.getuid?.() || (stat.mode & 0o022) || stat.size > 1048576)
|
|
100
|
+
throw failure();
|
|
101
|
+
if (createHash('sha256').update(await file.readFile()).digest('hex') !== expected)
|
|
102
|
+
throw failure();
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
await file.close();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export async function installClixad(directory, options = {}) {
|
|
110
|
+
const signal = AbortSignal.any([...(options.signal ? [options.signal] : []), AbortSignal.timeout(600000)]);
|
|
111
|
+
if (!['linux', 'darwin'].includes(process.platform))
|
|
112
|
+
throw failure();
|
|
113
|
+
signal.throwIfAborted();
|
|
114
|
+
const paths = await prepareClixadDirectories(directory);
|
|
115
|
+
try {
|
|
116
|
+
await readClixadInstallReceipt(directory);
|
|
117
|
+
await coreFiles(directory);
|
|
118
|
+
return paths;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
if (signal.aborted)
|
|
122
|
+
throw failure();
|
|
123
|
+
}
|
|
124
|
+
await rm(paths.installation, { force: true });
|
|
125
|
+
const temporary = await mkdtemp(join(paths.home, '.install-'));
|
|
126
|
+
try {
|
|
127
|
+
const response = await bounded(() => (options.fetcher ?? fetch)(CLIXAD_TARBALL, { redirect: 'error', signal }), signal);
|
|
128
|
+
if (!response.ok || !response.body || Number(response.headers.get('content-length')) > 100 * 1024 * 1024) {
|
|
129
|
+
void response.body?.cancel().catch(() => { });
|
|
130
|
+
throw failure();
|
|
131
|
+
}
|
|
132
|
+
const reader = response.body.getReader(), chunks = [];
|
|
133
|
+
let size = 0;
|
|
134
|
+
try {
|
|
135
|
+
for (;;) {
|
|
136
|
+
const part = await bounded(() => reader.read(), signal);
|
|
137
|
+
if (part.done)
|
|
138
|
+
break;
|
|
139
|
+
size += part.value.byteLength;
|
|
140
|
+
if (size > 100 * 1024 * 1024)
|
|
141
|
+
throw failure();
|
|
142
|
+
chunks.push(part.value);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
void reader.cancel().catch(() => { });
|
|
147
|
+
}
|
|
148
|
+
const archive = Buffer.concat(chunks);
|
|
149
|
+
if (`sha512-${createHash('sha512').update(archive).digest('base64')}` !== CLIXAD_INTEGRITY)
|
|
150
|
+
throw failure();
|
|
151
|
+
const tarball = join(temporary, 'clixad.tgz'), userconfig = join(temporary, 'user.npmrc'), globalconfig = join(temporary, 'global.npmrc');
|
|
152
|
+
await writeFile(tarball, archive, { mode: 0o600, flag: 'wx' });
|
|
153
|
+
await writeFile(userconfig, '', { mode: 0o600, flag: 'wx' });
|
|
154
|
+
await writeFile(globalconfig, '', { mode: 0o600, flag: 'wx' });
|
|
155
|
+
signal.throwIfAborted();
|
|
156
|
+
const env = Object.fromEntries(Object.entries(clixadEnvironment()).filter(([key]) => !/^npm_config_/i.test(key)));
|
|
157
|
+
const result = await (options.command ?? runClixadSetupCommand)(await executable('npm'), ['install', '--prefix', paths.runtime, '--ignore-scripts', '--no-audit', '--no-fund', '--no-save', '--package-lock=false',
|
|
158
|
+
'--registry=https://registry.npmjs.org', '--userconfig', userconfig, '--globalconfig', globalconfig, '--cache', join(paths.home, 'cache'), tarball], { cwd: paths.work, env, signal });
|
|
159
|
+
signal.throwIfAborted();
|
|
160
|
+
if (result.code !== 0)
|
|
161
|
+
throw failure();
|
|
162
|
+
await coreFiles(directory);
|
|
163
|
+
signal.throwIfAborted();
|
|
164
|
+
await writeClixadInstallReceipt(directory);
|
|
165
|
+
if (signal.aborted) {
|
|
166
|
+
await rm(paths.installation, { force: true });
|
|
167
|
+
throw failure();
|
|
168
|
+
}
|
|
169
|
+
return paths;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
throw failure();
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
await rm(temporary, { recursive: true, force: true });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async function nativeConfig(directory) {
|
|
179
|
+
try {
|
|
180
|
+
const home = await lstat(directory);
|
|
181
|
+
if (!home.isDirectory() || home.isSymbolicLink() || home.uid !== process.getuid?.() || (home.mode & 0o077))
|
|
182
|
+
throw failure();
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error.code === 'ENOENT')
|
|
186
|
+
return false;
|
|
187
|
+
throw failure();
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
const config = await lstat(join(directory, 'config.json'));
|
|
191
|
+
if (!config.isFile() || config.isSymbolicLink() || config.uid !== process.getuid?.() || (config.mode & 0o777) !== 0o600 || config.size < 1 || config.size > 65536)
|
|
192
|
+
throw failure();
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (error.code === 'ENOENT')
|
|
197
|
+
return false;
|
|
198
|
+
throw failure();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const clean = (value) => value.replace(/\x1b\][^\x07]*(?:\x07|\x1b\\)/g, '').replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, '').replaceAll('\r', '');
|
|
202
|
+
async function login(options, paths, signal) {
|
|
203
|
+
const lifetime = new AbortController(), combined = AbortSignal.any([signal, lifetime.signal]);
|
|
204
|
+
// The official login launches platform openers and has no no-open flag.
|
|
205
|
+
// Suppress only this unmanaged child launch; Squire opens the real device URL.
|
|
206
|
+
const openers = await mkdtemp(join(paths.home, '.login-openers-'));
|
|
207
|
+
for (const name of ['open', 'xdg-open'])
|
|
208
|
+
await writeFile(join(openers, name), '#!/bin/sh\nexit 0\n', { mode: 0o700, flag: 'wx' });
|
|
209
|
+
let output = '', pairing, failed = false;
|
|
210
|
+
const run = (options.command ?? runClixadSetupCommand)(process.execPath, ['--input-type=module', '-e', 'process.umask(0o077); await import(process.argv[1]);', paths.entry, 'login'], {
|
|
211
|
+
cwd: paths.work, env: { ...clixadEnvironment(), PATH: `${openers}:${process.env.PATH ?? '/usr/bin:/bin'}` }, signal: combined, onOutput(chunk) {
|
|
212
|
+
output += chunk;
|
|
213
|
+
if (output.length > 65536) {
|
|
214
|
+
failed = true;
|
|
215
|
+
lifetime.abort();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (pairing)
|
|
219
|
+
return;
|
|
220
|
+
const text = clean(output), url = text.match(/https:\/\/github\.com\/login\/device(?:\?[^\s]+)?(?=\s|$)/)?.[0];
|
|
221
|
+
const code = text.match(/\b(?:[Ee]nter\s+)?[Cc]ode:\s*([A-Z0-9]{4}-[A-Z0-9]{4})\b/)?.[1];
|
|
222
|
+
if (!url || !code)
|
|
223
|
+
return;
|
|
224
|
+
let address;
|
|
225
|
+
try {
|
|
226
|
+
address = new URL(url);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
failed = true;
|
|
230
|
+
lifetime.abort();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (address.origin !== 'https://github.com' || address.pathname !== '/login/device' || address.username || address.password || address.hash
|
|
234
|
+
|| [...address.searchParams.keys()].some(key => key !== 'user_code') || (address.searchParams.has('user_code') && address.searchParams.get('user_code') !== code)) {
|
|
235
|
+
failed = true;
|
|
236
|
+
lifetime.abort();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
address.searchParams.set('user_code', code);
|
|
240
|
+
pairing = bounded(() => options.squire.signup('clixad', address.href, 'Approve only the official Clixad native CLI GitHub device pairing started by Grunt, using the same personal GitHub identity just checked. Confirm the displayed device code matches this URL. Permit only read-only identity/profile and email scopes; stop on extra repository, organization, write or billing permissions. Never switch accounts, create another account, reveal tokens, add a payment method, fund a wallet, buy credits, subscribe, run offers, automate feedback or earn rewards. Required human verification needs normal browser handoff; stop on refusal. The CLI owns the token exchange and its fixed native config.'), combined);
|
|
241
|
+
void pairing.catch(() => { failed = true; lifetime.abort(); });
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
try {
|
|
245
|
+
const result = await run;
|
|
246
|
+
if (combined.aborted || failed || result.code !== 0 || !pairing)
|
|
247
|
+
throw failure();
|
|
248
|
+
await pairing;
|
|
249
|
+
if (combined.aborted)
|
|
250
|
+
throw failure();
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
lifetime.abort();
|
|
254
|
+
await rm(openers, { recursive: true, force: true });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/** Explicit user setup only; the native wallet can claim its ordinary daily streak bonus. */
|
|
258
|
+
export async function setupClixad(options) {
|
|
259
|
+
if (!DATA_SHARING_POLICIES.some(policy => policy.provider === 'clixad'))
|
|
260
|
+
throw new Error('Clixad data-sharing policy is unavailable');
|
|
261
|
+
const approved = await readDataSharingConsent(options.directory, DATA_SHARING_POLICIES.map(policy => policy.provider));
|
|
262
|
+
if (!approved.includes('clixad') || (options.dataSharingApproved && !options.dataSharingApproved.includes('clixad')))
|
|
263
|
+
throw new Error('Clixad requires the current grouped data-sharing approval');
|
|
264
|
+
const deadline = new AbortController(), timeout = setTimeout(() => deadline.abort(), 600000);
|
|
265
|
+
const signal = options.signal ? AbortSignal.any([options.signal, deadline.signal]) : deadline.signal;
|
|
266
|
+
let browserStarted = false, cancellation;
|
|
267
|
+
const cancel = () => { if (browserStarted)
|
|
268
|
+
cancellation ??= Promise.resolve().then(() => options.squire.cancelSignup('clixad')).catch(() => { }); };
|
|
269
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
270
|
+
const native = options.nativeDirectory ?? join(homedir(), '.clixad');
|
|
271
|
+
try {
|
|
272
|
+
if (signal.aborted)
|
|
273
|
+
throw failure();
|
|
274
|
+
options.squire.approveDataSharing?.(approved);
|
|
275
|
+
if (options.background) {
|
|
276
|
+
const source = new Clixad({ directory: options.directory, ...(options.fetcher ? { fetcher: options.fetcher } : {}) });
|
|
277
|
+
try {
|
|
278
|
+
if (!await bounded(() => source.available(), signal))
|
|
279
|
+
throw failure();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
await source.close();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const paths = await (options.install ?? installClixad)(options.directory, { signal, ...(options.fetcher ? { fetcher: options.fetcher } : {}) });
|
|
287
|
+
await verifyClixadPublicModel({ signal, ...(options.fetcher ? { fetcher: options.fetcher } : {}) });
|
|
288
|
+
const existed = await nativeConfig(native);
|
|
289
|
+
if (existed) {
|
|
290
|
+
const current = await (options.command ?? runClixadSetupCommand)(process.execPath, [paths.entry, 'model'], { cwd: paths.work, env: clixadEnvironment(), signal });
|
|
291
|
+
if (current.code !== 0)
|
|
292
|
+
throw failure();
|
|
293
|
+
if (clean(current.stdout).trim() !== `current model: ${CLIXAD_MODEL}`)
|
|
294
|
+
throw modelFailure();
|
|
295
|
+
}
|
|
296
|
+
const verify = () => (options.verify ?? verifyClixadAccess)({ directory: options.directory, signal, ...(options.fetcher ? { fetcher: options.fetcher } : {}) });
|
|
297
|
+
try {
|
|
298
|
+
await bounded(verify, signal);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
if (signal.aborted || error.code !== 'logged_out')
|
|
303
|
+
throw error;
|
|
304
|
+
// An expired native token cannot reveal its original public identity.
|
|
305
|
+
// Preserve that profile rather than pairing Squire's current account over it.
|
|
306
|
+
if (existed)
|
|
307
|
+
throw new ClixadNativeLoginRequired();
|
|
308
|
+
}
|
|
309
|
+
browserStarted = true;
|
|
310
|
+
await bounded(() => options.squire.signup('clixad', CLIXAD_DASHBOARD, 'Use this user\'s existing personal GitHub identity to check the ordinary Clixad account, or create its one normal free account if absent. Verify wallet balance exactly zero, GLM 5.3 Flash appears in the free catalog, and positive ordinary daily free allowance is available. Clixad uses optional prepaid credit packs: do not add a card, payment method, subscription, auto-charge, deposit or paid credits, and stop if any existing paid balance or billing condition is present. Do not change existing billing, switch identities, reset or rotate existing native authentication, create a public API key, run offers, earn credits, automate feedback, or claim rewards. The native CLI may perform its ordinary daily streak claim during this explicit setup only. Accept only required terms under the current grouped data-sharing approval; leave optional marketing off. The official CLI GitHub device pairing follows separately with read-only profile/email scopes. Stop on refusal and report required human verification for browser handoff.'), signal);
|
|
311
|
+
if (signal.aborted)
|
|
312
|
+
throw failure();
|
|
313
|
+
if (!existed && await nativeConfig(native))
|
|
314
|
+
throw failure();
|
|
315
|
+
await login(options, paths, signal);
|
|
316
|
+
if (signal.aborted || !await nativeConfig(native))
|
|
317
|
+
throw failure();
|
|
318
|
+
if (!existed) {
|
|
319
|
+
const pin = await (options.command ?? runClixadSetupCommand)(process.execPath, [paths.entry, 'model', CLIXAD_MODEL], { cwd: paths.work, env: clixadEnvironment(), signal });
|
|
320
|
+
if (pin.code !== 0)
|
|
321
|
+
throw failure();
|
|
322
|
+
}
|
|
323
|
+
await bounded(verify, signal);
|
|
324
|
+
if (signal.aborted)
|
|
325
|
+
throw failure();
|
|
326
|
+
options.notify?.('Clixad: native free GLM 5.3 Flash access verified');
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
if (browserStarted)
|
|
330
|
+
cancel();
|
|
331
|
+
if (error instanceof ClixadNativeLoginRequired)
|
|
332
|
+
throw error;
|
|
333
|
+
if (error instanceof Error && error.message === modelFailure().message)
|
|
334
|
+
throw modelFailure();
|
|
335
|
+
throw failure();
|
|
336
|
+
}
|
|
337
|
+
finally {
|
|
338
|
+
clearTimeout(timeout);
|
|
339
|
+
signal.removeEventListener('abort', cancel);
|
|
340
|
+
if (cancellation) {
|
|
341
|
+
const timer = AbortSignal.timeout(5000);
|
|
342
|
+
await bounded(() => cancellation, timer).catch(() => { });
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|