@coda-console/grok 0.0.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ // Grok 1.0.52 reports no ACP modes. Translate set_mode to the notification its own UI sends; everything else passes
2
+ // through. No selected mode (the empty currentModeId) leaves the machine's configuration in charge, as before. Coda's session
3
+ // instructions go in front of a new session's first prompt (instructions.mjs).
4
+ import { spawn } from 'node:child_process';
5
+ import { grokBinary } from '../scripts/ask.mjs';
6
+ import { SessionInstructions } from './instructions.mjs';
7
+
8
+ const modes = [{ id: 'auto', name: '自动审批' }, { id: 'always-approve', name: '全部放行' }];
9
+ const grok = spawn(grokBinary() ?? 'grok', ['agent', '--no-leader', 'stdio'], { stdio: ['pipe', 'pipe', 'inherit'] });
10
+ const send = (stream, message) => stream.write(`${JSON.stringify(message)}\n`);
11
+ const say = message => send(process.stdout, { jsonrpc: '2.0', ...message });
12
+ const pending = new Map();
13
+ const instructions = new SessionInstructions();
14
+ let sessionId, mode = '', stopping = false;
15
+
16
+ // Only LF separates JSON messages; readline would also split literal Unicode line separators inside JSON strings.
17
+ function read(stream, receive) {
18
+ let rest = '';
19
+ const take = text => {
20
+ const lines = (rest + text).split('\n'); rest = lines.pop();
21
+ for (const line of lines) {
22
+ let message; try { message = JSON.parse(line); } catch { continue; }
23
+ if (message && typeof message === 'object' && !Array.isArray(message)) receive(message);
24
+ }
25
+ };
26
+ stream.setEncoding('utf8').on('data', take).on('end', () => take('\n'));
27
+ }
28
+ read(process.stdin, said => {
29
+ const { agent: message, coda } = instructions.fromCoda(said);
30
+ if (coda) { say(coda); return; }
31
+ if (message.method === 'session/set_mode' && 'id' in message) {
32
+ const chosen = message.params?.modeId;
33
+ const error = !sessionId || message.params?.sessionId !== sessionId ? 'Grok 会话不存在'
34
+ : !modes.some(m => m.id === chosen) ? '审批模式不可用'
35
+ : [...pending.values()].some(m => m.method === 'session/prompt') ? '请在当前轮次结束后切换审批模式' : null;
36
+ if (error) { say({ id: message.id, error: { code: -32602, message: error } }); return; }
37
+ send(grok.stdin, { jsonrpc: '2.0', method: '_x.ai/yolo_mode_changed', params: {
38
+ sessionId, yolo_mode: chosen === 'always-approve', auto_mode: chosen === 'auto', permission_mode: chosen,
39
+ } });
40
+ mode = chosen;
41
+ say({ method: 'session/update', params: { sessionId, update: { sessionUpdate: 'current_mode_update', currentModeId: mode } } });
42
+ say({ id: message.id, result: {} }); return;
43
+ }
44
+ if ('id' in message && ['session/new', 'session/load', 'session/prompt'].includes(message.method)) pending.set(message.id, message);
45
+ send(grok.stdin, message);
46
+ });
47
+ read(grok.stdout, said => {
48
+ const message = instructions.fromAgent(said), request = !message.method && pending.get(message.id);
49
+ if (request) {
50
+ pending.delete(message.id);
51
+ if (message.result && request.method !== 'session/prompt') {
52
+ sessionId = message.result.sessionId ?? request.params.sessionId;
53
+ mode = request.params?._meta?.yoloMode ? 'always-approve' : request.params?._meta?.autoMode ? 'auto' : '';
54
+ message.result.modes = { currentModeId: mode, availableModes: modes };
55
+ }
56
+ }
57
+ say(message);
58
+ });
59
+ const stop = () => {
60
+ if (stopping) return;
61
+ stopping = true; grok.stdin.end(); grok.kill();
62
+ setTimeout(() => grok.kill('SIGKILL'), 800).unref();
63
+ };
64
+ grok.stdin.on('error', () => {});
65
+ grok.on('error', () => process.exit(1));
66
+ grok.on('close', code => process.exit(stopping ? 0 : code ?? 1));
67
+ process.stdin.on('end', stop);
68
+ for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) process.once(signal, stop);
@@ -0,0 +1,68 @@
1
+ // Coda's session instructions (docs/agent-protocol.md「会话指令」) for an agent whose own ACP does not take `systemPrompt`: the
2
+ // entry declares that it does, keeps the parameter from the agent, and puts the text in front of the first prompt of a
3
+ // session the agent opened new, as a part of its own; a session it loaded has had them. A slash command is the agent's to
4
+ // read as one: the instructions wait for the next prompt. Kept the same in every plugin that relays a CLI's ACP.
5
+ const record = value => value && typeof value === 'object' && !Array.isArray(value);
6
+
7
+ // ACP's `systemPrompt`: its text, '' when there is none; throws on anything but text appended to the agent's own.
8
+ export function sessionInstructions(systemPrompt) {
9
+ if (systemPrompt === undefined || systemPrompt === null) return '';
10
+ if (systemPrompt.mode !== 'append') throw new Error('会话指令只支持 append 模式');
11
+ const { content } = systemPrompt;
12
+ if (!Array.isArray(content) || content.some(block => block?.type !== 'text' || typeof block.text !== 'string')) throw new Error('会话指令只接受文本块');
13
+ return content.map(block => block.text).join('\n\n');
14
+ }
15
+
16
+ // The part in front of the user's input: delimited, and said to be the client's, not the user's.
17
+ const OPENING = '<coda-session-instructions>';
18
+ export const instructionsBlock = text => ({ type: 'text', text: `${OPENING}\n`
19
+ + 'Instructions from Coda, the client this session runs in, for the whole session. They are not part of the user\'s message.\n\n'
20
+ + `${text}\n</coda-session-instructions>\n` });
21
+
22
+ export class SessionInstructions {
23
+ // Coda's requests whose answers are read here, by id; the instructions of a session yet to have its first prompt.
24
+ constructor() { this.asked = new Map(); this.waiting = new Map(); }
25
+ // What Coda says: `agent`, what the agent is told, or `coda`, Coda's answer given here instead.
26
+ fromCoda(message) {
27
+ const { id, method, params } = message;
28
+ if (!record(params)) return { agent: message };
29
+ if (method === 'initialize' && id !== undefined) this.asked.set(id, { initialize: true });
30
+ if (method === 'session/new' || method === 'session/load') {
31
+ let text;
32
+ try { text = sessionInstructions(params.systemPrompt); }
33
+ catch (error) { return { coda: { jsonrpc: '2.0', id, error: { code: -32602, message: error.message } } }; }
34
+ const { systemPrompt, ...rest } = params;
35
+ if (method === 'session/new' && text && id !== undefined) this.asked.set(id, { text });
36
+ return { agent: { ...message, params: rest } };
37
+ }
38
+ if (method === 'session/prompt' && Array.isArray(params.prompt) && this.waiting.has(params.sessionId)) {
39
+ const first = params.prompt.find(block => block?.type === 'text');
40
+ if (typeof first?.text === 'string' && first.text.trimStart().startsWith('/')) return { agent: message };
41
+ const text = this.waiting.get(params.sessionId);
42
+ this.waiting.delete(params.sessionId);
43
+ return { agent: { ...message, params: { ...params, prompt: [instructionsBlock(text), ...params.prompt] } } };
44
+ }
45
+ return { agent: message };
46
+ }
47
+ // What the agent says, as said to Coda. A title the agent took from the first prompt's text begins with the instructions,
48
+ // not with what the user asked: it is left out, and the session keeps the title Coda gives it.
49
+ fromAgent(message) {
50
+ const update = message?.method === 'session/update' && record(message.params) ? message.params.update : null;
51
+ if (record(update) && update.sessionUpdate === 'session_info_update' && typeof update.title === 'string' && update.title.trimStart().startsWith(OPENING)) {
52
+ const { title, ...rest } = update;
53
+ return { ...message, params: { ...message.params, update: rest } };
54
+ }
55
+ if (!record(message) || !('id' in message) || 'method' in message) return message;
56
+ const asked = this.asked.get(message.id);
57
+ if (!asked) return message;
58
+ this.asked.delete(message.id);
59
+ if (!record(message.result)) return message;
60
+ if (asked.text) {
61
+ if (typeof message.result.sessionId === 'string') this.waiting.set(message.result.sessionId, asked.text);
62
+ return message;
63
+ }
64
+ const capabilities = record(message.result.agentCapabilities) ? message.result.agentCapabilities : {};
65
+ const sessions = record(capabilities.sessionCapabilities) ? capabilities.sessionCapabilities : {};
66
+ return { ...message, result: { ...message.result, agentCapabilities: { ...capabilities, sessionCapabilities: { ...sessions, systemPrompt: {} } } } };
67
+ }
68
+ }
@@ -0,0 +1,16 @@
1
+ # Grok 品牌图形
2
+
3
+ 仅用于标识会话所用的服务,不作为 Coda 自身标志。商标归各自权利人所有。
4
+
5
+ - `grok.svg`:xAI 的公开站点拦截自动下载,取自 [LobeHub Icons](https://github.com/lobehub/lobe-icons)(MIT)
6
+ `@lobehub/icons-static-svg` 1.95.1 的 `icons/grok.svg`,即 Grok 的单色标志;只把 `currentColor` 换成黑色、去掉标题,并把画布从 24 放大到 256(iOS 按 96pt 光栅化 PDF 时只缩不放,页面太小会画成一个点),保留路径几何。用于 Grok。
7
+
8
+ 提取日期:2026-09-19。SVG 是可审阅的源文件,PDF 是由 CairoSVG 转换的等比矢量资源,清单的 `icon` 指向 PDF。重新生成 PDF(开发工具,不是构建或运行依赖):
9
+
10
+ ```sh
11
+ uv run --with cairosvg python - <<'PY'
12
+ import cairosvg
13
+ for name in ['grok']:
14
+ cairosvg.svg2pdf(url=f'{name}.svg', write_to=f'{name}.pdf')
15
+ PY
16
+ ```
package/icons/grok.pdf ADDED
Binary file
package/icons/grok.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 24 24" fill-rule="evenodd"><path fill="black" d="M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"></path></svg>
package/package.json CHANGED
@@ -1,7 +1,51 @@
1
1
  {
2
2
  "name": "@coda-console/grok",
3
- "version": "0.0.0",
4
- "description": "Reserved for the first Coda plugin release.",
3
+ "id": "grok",
4
+ "displayName": "Grok",
5
+ "description": "Grok Agent:适配运行机上 Grok CLI 的 ACP 与审批模式;资源页的「Grok」面板显示账号与额度,可从 Coda 安装和登录。",
6
+ "version": "1.3.1",
7
+ "contributes": {
8
+ "agents": [
9
+ {
10
+ "id": "grok",
11
+ "displayName": "Grok",
12
+ "icon": {
13
+ "light": "icons/grok.pdf",
14
+ "template": true
15
+ },
16
+ "command": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/agent/entry.mjs\"",
17
+ "modes": {
18
+ "title": "审批模式",
19
+ "unset": "按运行机配置",
20
+ "auto": "auto",
21
+ "full": "always-approve",
22
+ "note": "切换对后续消息生效;新会话未选择时沿用运行机的 Grok 配置。"
23
+ },
24
+ "skillsDir": ".agents/skills",
25
+ "configFiles": [
26
+ "${GROK_HOME:-~/.grok}/config.toml"
27
+ ],
28
+ "setupHint": "请在「资源」里为运行机添加 Grok。"
29
+ }
30
+ ],
31
+ "panels": [
32
+ {
33
+ "id": "account",
34
+ "title": "Grok",
35
+ "command": "node \"$CODA_PLUGIN_PATH/scripts/panel.mjs\"",
36
+ "maxAge": "PT5M",
37
+ "signIn": {
38
+ "command": "g=\"$HOME/.grok/bin/grok\"; [ -x \"$g\" ] || g=grok; BROWSER=/usr/bin/true NO_COLOR=1 exec \"$g\" login --device-auth",
39
+ "installed": "test -x \"$HOME/.grok/bin/grok\" || command -v grok >/dev/null",
40
+ "install": "SHELL= PATH=\"$HOME/.grok/bin:$PATH\" exec bash -c 'set -o pipefail; curl -fsSL https://x.ai/cli/install.sh | bash'",
41
+ "note": "登录保存在这台机器的 Grok CLI 里,由它自己续期;可以用 X 账号确认。"
42
+ }
43
+ }
44
+ ],
45
+ "setup": {
46
+ "command": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/scripts/setup.mjs\""
47
+ }
48
+ },
5
49
  "license": "MIT",
6
50
  "repository": {
7
51
  "type": "git",
@@ -10,5 +54,10 @@
10
54
  },
11
55
  "publishConfig": {
12
56
  "access": "public"
13
- }
57
+ },
58
+ "files": [
59
+ "agent",
60
+ "scripts",
61
+ "icons"
62
+ ]
14
63
  }
@@ -0,0 +1,48 @@
1
+ // Questions to a Grok of its own over ACP, as its own clients ask them: the results of `_x.ai/...` extension methods, in
2
+ // order. One process answers them all, as starting it takes seconds; each is asked once the one before is answered, as an
3
+ // answer may change what the next one reads (a subscription check renews the login and fills in its name).
4
+ import { spawn } from 'node:child_process';
5
+ import { existsSync } from 'node:fs';
6
+ import { homedir, tmpdir } from 'node:os';
7
+ import { join } from 'node:path';
8
+
9
+ // The installer puts the binary here whatever GROK_HOME says; the login lives in GROK_HOME. The same the agent runs.
10
+ export const grokHome = (env = process.env) => env.GROK_HOME || join(homedir(), '.grok');
11
+ export function grokBinary(env = process.env) {
12
+ const installed = join(homedir(), '.grok/bin/grok');
13
+ if (existsSync(installed)) return installed;
14
+ return (env.PATH ?? '').split(':').filter(Boolean).map(dir => join(dir, 'grok')).find(path => existsSync(path)) ?? null;
15
+ }
16
+
17
+ export function grokAsk(methods, { binary = grokBinary(), env = process.env, timeoutMs = 20000 } = {}) {
18
+ if (!binary) return Promise.reject(new Error('这台机器上找不到 Grok CLI'));
19
+ return new Promise((resolve, reject) => {
20
+ const child = spawn(binary, ['agent', '--no-leader', 'stdio'], { cwd: tmpdir(), env, stdio: ['pipe', 'pipe', 'ignore'] });
21
+ const results = new Map();
22
+ let buffer = '', settled = false;
23
+ const finish = (error, value) => {
24
+ if (settled) return; settled = true; clearTimeout(timer); child.kill();
25
+ error ? reject(error) : resolve(value);
26
+ };
27
+ const timer = setTimeout(() => finish(new Error('Grok 没有回答')), timeoutMs);
28
+ const send = (id, method, params = {}) => child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
29
+ child.on('error', error => finish(error));
30
+ child.on('close', () => finish(new Error('Grok 已退出')));
31
+ child.stdout.on('data', chunk => {
32
+ buffer += chunk;
33
+ for (let i; (i = buffer.indexOf('\n')) >= 0;) {
34
+ const line = buffer.slice(0, i); buffer = buffer.slice(i + 1);
35
+ let message; try { message = JSON.parse(line); } catch { continue; }
36
+ if (message.id === 1) send(2, methods[0]);
37
+ else if (message.id === results.size + 2 && message.id < methods.length + 2) {
38
+ if (message.error) return finish(new Error(String(message.error.message ?? 'Grok 返回错误')));
39
+ results.set(message.id, message.result);
40
+ if (results.size === methods.length) finish(null, methods.map((_, index) => results.get(index + 2)));
41
+ else send(results.size + 2, methods[results.size]);
42
+ }
43
+ }
44
+ });
45
+ child.stdin.on('error', () => {});
46
+ send(1, 'initialize', { protocolVersion: 1, clientCapabilities: {} });
47
+ });
48
+ }
@@ -0,0 +1,11 @@
1
+ // The「Grok」panel's reading, printed once as `{ items }`. No login file here shows nothing (the panel is then offered under
2
+ // 「添加资源」); a CLI that cannot be asked fails the reading, which keeps the last one shown.
3
+ import { statSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { grokAsk, grokHome } from './ask.mjs';
6
+ import { panel } from './quota.mjs';
7
+
8
+ try { statSync(join(grokHome(), 'auth.json')); }
9
+ catch (error) { if (error.code === 'ENOENT') { console.log('{"items":[]}'); process.exit(0); } console.error(`读不了 Grok 的登录:${error.code}`); process.exit(1); }
10
+ try { console.log(JSON.stringify(panel(await grokAsk(['_x.ai/auth/check_subscription', '_x.ai/auth/info', '_x.ai/billing'])))); }
11
+ catch (error) { console.error(error.message); process.exit(1); }
@@ -0,0 +1,46 @@
1
+ import { createHash } from 'node:crypto';
2
+
3
+ // What the「Grok」panel shows (docs/plugins.md「内置插件:Grok」): who is signed in and the plan's coding credits, as the
4
+ // CLI itself answers them (`_x.ai/auth/check_subscription`, `_x.ai/auth/info`, `_x.ai/billing`: what its `/usage` reads).
5
+ const line = (value, max = 80) => typeof value === 'string' ? [...value.replace(/\s+/g, ' ').trim()].slice(0, max).join('') : '';
6
+ const instant = value => typeof value === 'string' && Number.isFinite(Date.parse(value)) ? new Date(value).toISOString() : null;
7
+
8
+ // The name they gave xAI and their plan, never their email or tokens. Null when the CLI says no one is signed in: the
9
+ // login lapsed or was revoked though the file is still there.
10
+ export function account(subscription, info) {
11
+ if (subscription?.authenticated === false) return null;
12
+ if (subscription?.authenticated !== true || !subscription.meta) throw new Error('Grok 没有说明登录状态');
13
+ const email = typeof info?.email === 'string' ? info.email.trim().toLowerCase() : '';
14
+ // The account compared across machines by Coda's group view, as a hash of the email: the email itself stays here.
15
+ return { name: [line(info?.firstName), line(info?.lastName)].filter(Boolean).join(' '), plan: line(subscription.meta.subscription_tier),
16
+ ...(email ? { id: createHash('sha256').update(email).digest('hex').slice(0, 32) } : {}) };
17
+ }
18
+ // The share of the plan's allowance left this period (an absent share is zero used, as protobuf JSON leaves zeros out),
19
+ // and pay-as-you-go spending once a cap is set. A prepaid balance is money, not a share, and is not shown.
20
+ export function windows(document) {
21
+ const config = document && typeof document === 'object' ? document.config : null;
22
+ if (!config || typeof config !== 'object') return [];
23
+ const cents = value => typeof value?.val === 'number' && Number.isFinite(value.val) ? Math.abs(value.val) : 0;
24
+ const limit = cents(config.monthlyLimit);
25
+ const used = typeof config.creditUsagePercent === 'number' && Number.isFinite(config.creditUsagePercent) ? Math.min(100, Math.max(0, config.creditUsagePercent))
26
+ : limit > 0 ? Math.min(100, cents(config.used) / limit * 100) : 0;
27
+ const type = config.currentPeriod?.type, left = Math.round(100 - used), resets = instant(config.currentPeriod?.end ?? config.billingPeriodEnd);
28
+ const meters = [{ type: 'meter', label: type === 'USAGE_PERIOD_TYPE_WEEKLY' ? '7 天' : type === 'USAGE_PERIOD_TYPE_MONTHLY' ? '月度' : '额度',
29
+ value: `剩余 ${left}%`, fraction: left / 100, ...(resets ? { time: resets, timeLabel: '重置' } : {}) }];
30
+ // A zero amount still arrives as `{}`; the older shape leaves on-demand spending out, and it is what went past the allowance.
31
+ const cap = cents(config.onDemandCap);
32
+ const onDemand = config.onDemandUsed != null ? cents(config.onDemandUsed) : Math.max(0, cents(config.used) - limit);
33
+ if (cap > 0) {
34
+ const share = Math.round(Math.max(0, cap - onDemand) / cap * 100);
35
+ meters.push({ type: 'meter', label: '按需用量', value: `剩余 ${share}%`, fraction: share / 100 });
36
+ }
37
+ return meters;
38
+ }
39
+ // The panel from what the CLI answered; nothing when no one is signed in.
40
+ export function panel([subscription, info, billing]) {
41
+ const who = account(subscription, info);
42
+ if (!who) return { items: [] };
43
+ const meters = windows(billing);
44
+ return { items: [{ type: 'card', title: who.name || 'Grok', ...(who.plan ? { subtitle: who.plan } : {}), ...(who.id ? { identity: `grok:${who.id}` } : {}),
45
+ items: meters.length ? meters : [{ type: 'error', text: '暂时无法获取额度:Grok 没有给出额度' }] }] };
46
+ }
@@ -0,0 +1,46 @@
1
+ // The plugin's setup (`contributes.setup`), which Coda runs on each machine when the user installs or updates the plugin: it
2
+ // ends well once the machine can run the agent. Without a Grok CLI that runs, or with one older than MINIMUM (the CLI whose
3
+ // `agent --no-leader stdio` and `_x.ai/yolo_mode_changed` the agent entry was checked against), Grok's own installer puts
4
+ // the latest in ~/.grok/bin, where the agent looks first, as the「Grok」panel's install does; a newer one is kept. Why the
5
+ // machine is not ready is said in one line on standard error.
6
+ import { spawnSync } from 'node:child_process';
7
+ import { realpathSync } from 'node:fs';
8
+ import { homedir } from 'node:os';
9
+ import { join } from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { grokBinary } from './ask.mjs';
12
+
13
+ export const MINIMUM = '1.0.52';
14
+ // The first x.y.z a version command prints; whether one is older than another.
15
+ export const versionIn = text => /(\d+)\.(\d+)\.(\d+)/.exec(text ?? '')?.slice(1).join('.') ?? null;
16
+ export function older(version, than) {
17
+ const a = version.split('.').map(Number), b = than.split('.').map(Number), i = a.findIndex((n, k) => n !== b[k]);
18
+ return i >= 0 && a[i] < b[i];
19
+ }
20
+ const asked = binary => spawnSync(binary, ['--version'], { encoding: 'utf8', timeout: 30_000, stdio: ['ignore', 'pipe', 'pipe'] });
21
+
22
+ // What the machine needs, given the CLI found (`binary`, null for none) and how its `--version` runs (`run`):
23
+ // `install`, `upgrade` or `none`, and why.
24
+ export function needed(binary, run = asked) {
25
+ if (!binary) return { action: 'install', reason: '这台机器上没有 Grok CLI' };
26
+ const ran = run(binary);
27
+ if (ran.status !== 0) return { action: 'install', reason: `Grok CLI 无法运行(${binary})` };
28
+ const version = versionIn(`${ran.stdout ?? ''}\n${ran.stderr ?? ''}`);
29
+ if (!version) return { action: 'upgrade', reason: `读不出 Grok CLI 的版本(${binary})` };
30
+ if (older(version, MINIMUM)) return { action: 'upgrade', reason: `Grok CLI ${version} 低于所需的 ${MINIMUM}` };
31
+ return { action: 'none', version };
32
+ }
33
+
34
+ if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {
35
+ const before = needed(grokBinary());
36
+ if (before.action !== 'none') {
37
+ // What the installer prints goes to standard error with the rest of its story.
38
+ // As the panel's `install`: without SHELL it leaves the shell's configuration alone.
39
+ const installed = spawnSync('bash', ['-c', 'set -o pipefail; curl -fsSL https://x.ai/cli/install.sh | bash'], { stdio: ['ignore', 2, 2],
40
+ env: { ...process.env, SHELL: '', PATH: `${join(homedir(), '.grok/bin')}:${process.env.PATH ?? ''}` } });
41
+ if (installed.status !== 0) { console.error(`${before.reason},安装失败(退出码 ${installed.status ?? installed.signal})`); process.exit(1); }
42
+ }
43
+ const after = needed(grokBinary());
44
+ if (after.action !== 'none') { console.error(after.reason); process.exit(1); }
45
+ console.log(`Grok CLI ${after.version}`);
46
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # @coda-console/grok
2
-
3
- Bootstrap placeholder. The usable release will be published by coda-console/coda-plugins.