@coda-console/kimi 1.5.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@ Kimi Code Agent:Coda 的入口在运行机的 kimi acp 与 Coda 之间转发
10
10
 
11
11
  资源页的「Kimi」显示这台机器上 Kimi CLI 的登录与额度,可从 Coda 安装和登录。
12
12
 
13
- - **CLI**:先找安装器放的 `~/.kimi-code/bin/kimi`,再找 `PATH` 上的 `kimi`(入口跑会话用的是同一个)。
13
+ - **CLI**:先找安装器放的 `~/.kimi-code/bin/kimi`,再找 `PATH` 上的 `kimi`(入口跑会话、记录、登录、安装用的是同一个查找);不能执行的文件(残留的、权限不对的)不算,不会挡住 `PATH` 上能用的。
14
14
  - **来源**:有 `$KIMI_CODE_HOME/credentials/kimi-code.json`(默认 `~/.kimi-code`)才算登录了;没有就输出为空,「Kimi」出现在「添加资源」里。
15
15
  账号与额度都问 CLI 自己的本地服务:临时启动 `kimi web --no-open --host 127.0.0.1 --port 0`(临时工作目录,只听回环地址,不开浏览器),
16
16
  从启动输出取本次的地址和令牌,账号问 `GET /api/v1/oauth/userinfo`(只取昵称 `nickname` 与会员等级 `userLevelName`,不取手机号、邮箱),
@@ -18,10 +18,10 @@ Kimi Code Agent:Coda 的入口在运行机的 kimi acp 与 Coda 之间转发
18
18
  令牌续期是 CLI 自己的事,Coda 不读 OAuth 令牌,也不发起模型对话。依赖 Kimi Code CLI 2.1.1 的本地接口(实验接口),升级时复核。
19
19
  - **账号**:按登录文件的修改时间问一次(CLI 登录、续期都会重写它),记在插件状态目录的 `account.json`。问不到时(CLI 向上游取资料 8 秒超时)
20
20
  沿用上次看到的,从没看到过就叫「Kimi」,下次再问;Kimi 拒绝这个登录(401)时输出为空。
21
- - **显示**:一个资源,名字是昵称(会员等级不显示);5 小时、7 天、月度窗口按套餐有的各一个读数,再加「Extra Usage 余额」。读不到额度时那一行写原因。
22
- CLI 起不来或不答复时整个类型读取失败,保留上次结果。找不到 CLI 时那一行写明,用「重新登录」安装。`maxAge` 5 分钟。
21
+ - **显示**:一个资源,名字是昵称(会员等级不显示);5 小时、7 天、月度窗口按套餐有的各一个读数,再加「Extra Usage 余额」。
22
+ 登录文件读不了、Kimi 拒绝这个登录、或有登录却找不到 CLI 时,记录照写:一行「Kimi」写原因,登录与安装入口照常在(找不到 CLI 时用「重新登录」安装);CLI 起不来、不答复、本地服务出错或没有额度时,命令以非零退出,原因写在标准错误的最后一行,Coda 保留上一份记录,资源页显示「更新失败:原因」。记录命令是 `scripts/resource.mjs`,不定时(没有 `every`),资源页打开、点「刷新」和每个操作之后运行。
23
23
  - **身份**:`kimi:<用户 ID>`。登录文件变了而这次没问到是谁时,沿用上次的昵称与等级,但不带身份。
24
- - **登录**:`scripts/login.sh` 运行 `kimi login`(设备码)。它不看 `BROWSER`,在 macOS 上直接调 `open`、Linux 上调 `xdg-open`:
25
- 脚本把只含空操作 `open`、`xdg-open` 的目录(插件状态目录里的 `no-browser/`)放在 `PATH` 最前,运行机上不弹出没人看的浏览器页面。
26
- - **安装**:`scripts/install.sh` 运行官方安装脚本 `curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash`,装进 `~/.kimi-code/bin`(CLI 约 180 MB)。
24
+ - **登录**:操作 `sign-in`(`scripts/sign-in.mjs`)运行 `kimi login`(设备码),把它打印的链接与设备码用 `coda progress` 报给 Coda(只认完整的行,两路输出各自成行;报完才算登录结束,报失败登录就失败),20 秒内没有链接就失败,原因是那时 CLI 说的最后一行;这套流程在 `scripts/device-login.mjs`。它不看 `BROWSER`,在 macOS 上直接调 `open`、Linux 上调 `xdg-open`:
25
+ 命令把只含空操作 `open`、`xdg-open` 的目录(插件状态目录里的 `no-browser/`)放在 `PATH` 最前,运行机上不弹出没人看的浏览器页面。
26
+ - **安装**:操作 `install` 就是 `scripts/setup.mjs`(结果 `{}`,说明写在标准错误):`scripts/install.sh` 运行官方安装脚本 `curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash`,装进 `~/.kimi-code/bin`(CLI 约 180 MB)。
27
27
  运行时设 `KIMI_NO_MODIFY_PATH=1`、`PATH` 里去掉 `~/.kimi-code/bin`,脚本因此不改 shell 配置,也不改名 `PATH` 上旧版 Python 的 `kimi`。
package/agent/binary.mjs CHANGED
@@ -1,11 +1,13 @@
1
1
  // Which Kimi CLI runs: the one its installer puts in ~/.kimi-code/bin, else the first `kimi` on the PATH; the same the
2
2
  // 「Kimi」resource type signs in and reads the quota with (scripts/).
3
- import { existsSync } from 'node:fs';
3
+ import { accessSync, constants, statSync } from 'node:fs';
4
4
  import { homedir } from 'node:os';
5
5
  import { join } from 'node:path';
6
6
 
7
+ // A file that can be run: a leftover that cannot is not the CLI, and does not hide the one further on the PATH.
8
+ const runnable = path => { try { accessSync(path, constants.X_OK); return statSync(path).isFile(); } catch { return false; } };
7
9
  export function kimiBinary(env = process.env) {
8
10
  const installed = join(homedir(), '.kimi-code/bin/kimi');
9
- if (existsSync(installed)) return installed;
10
- return (env.PATH ?? '').split(':').filter(Boolean).map(dir => join(dir, 'kimi')).find(path => existsSync(path)) ?? null;
11
+ if (runnable(installed)) return installed;
12
+ return (env.PATH ?? '').split(':').filter(Boolean).map(dir => join(dir, 'kimi')).find(runnable) ?? null;
11
13
  }
package/package.json CHANGED
@@ -3,7 +3,10 @@
3
3
  "id": "kimi",
4
4
  "displayName": "Kimi Code",
5
5
  "description": "用 Kimi Code 跑会话",
6
- "version": "1.5.2",
6
+ "version": "1.6.0",
7
+ "engines": {
8
+ "coda": 6
9
+ },
7
10
  "categories": [
8
11
  "Agent"
9
12
  ],
@@ -30,20 +33,21 @@
30
33
  "setupHint": "请在「资源」里为运行机添加 Kimi。"
31
34
  }
32
35
  ],
33
- "resources": [
36
+ "protocolImplementations": [
34
37
  {
35
- "id": "account",
36
- "title": "Kimi",
37
- "command": "node \"$CODA_PLUGIN_PATH/scripts/resources.mjs\"",
38
- "maxAge": "PT5M",
39
- "signIn": {
40
- "command": "exec sh \"$CODA_PLUGIN_PATH/scripts/login.sh\"",
41
- "installed": "test -x \"$HOME/.kimi-code/bin/kimi\" || command -v kimi >/dev/null",
42
- "install": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/scripts/setup.mjs\"",
43
- "note": "登录保存在这台机器的 Kimi CLI 里,由它自己续期。"
38
+ "kind": "coda/resource@1",
39
+ "commands": {
40
+ "sign-in": "scripts/sign-in.mjs",
41
+ "install": "scripts/setup.mjs"
44
42
  }
45
43
  }
46
44
  ],
45
+ "records": [
46
+ {
47
+ "kind": "coda/resource@1",
48
+ "command": "scripts/resource.mjs"
49
+ }
50
+ ],
47
51
  "setup": {
48
52
  "command": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/scripts/setup.mjs\""
49
53
  }
@@ -0,0 +1,48 @@
1
+ // A device-code login as the `sign-in` operation of `coda/resource@1` runs it: the entry says how to start the CLI that prints the
2
+ // device link and code (`start()`, a child process with its output piped), and this reports them (`coda progress`, awaited
3
+ // before the login is settled), gives the login 20 seconds to print them, ends it with its CLI, and settles it: `{}` when the
4
+ // CLI ended well and nothing failed, else one line, the first reason noted, else the last line the CLI said.
5
+ import { execFile } from 'node:child_process';
6
+ import { stripVTControlCharacters } from 'node:util';
7
+
8
+ // The device code a login prints: a verification URL that carries the code, or the code alone on a line after it. Only whole
9
+ // lines are read: output arrives in pieces, and a URL cut short would carry a code cut short.
10
+ export function deviceCode(text) {
11
+ const plain = stripVTControlCharacters(text.slice(0, text.lastIndexOf('\n') + 1));
12
+ const url = plain.match(/https:\/\/\S+/)?.[0] ?? null;
13
+ let code = null;
14
+ try { code = url && new URL(url).searchParams.get('user_code'); } catch { return null; }
15
+ code ||= plain.match(/^\s*([A-Z0-9]{4}-[A-Z0-9]{4,5})\s*$/m)?.[1] ?? null;
16
+ return url && code && /^[A-Z0-9]{4}-[A-Z0-9]{4,5}$/.test(code) ? { url, code } : null;
17
+ }
18
+ const lastLine = text => stripVTControlCharacters(text).split('\n').map(line => line.trim()).filter(Boolean).at(-1);
19
+ // Coda's own command: what it prints, or why it failed (its last line).
20
+ const coda = (...args) => new Promise((done, fail) => execFile('coda', args, (error, stdout, stderr) =>
21
+ error ? fail(new Error(stderr.trim().split('\n').at(-1) || error.message)) : done(stdout)));
22
+
23
+ export async function deviceLogin(start, name) {
24
+ const child = start();
25
+ // What each stream said, kept apart (a line is read from one stream only), and which spoke last.
26
+ const said = { stdout: '', stderr: '' };
27
+ let latest = 'stdout', reported = false, reporting = Promise.resolve(), failed = null;
28
+ // The first reason stays: what the CLI says when it is ended for it (cancelled, say) is not the reason.
29
+ const fail = reason => { failed ??= reason; child.kill(); };
30
+ const silent = setTimeout(() => fail(lastLine(said[latest]) || '登录没有完成,请重新登录。'), 20_000);
31
+ const heard = stream => chunk => {
32
+ said[stream] = (said[stream] + chunk).slice(-8000); latest = stream;
33
+ const found = !reported && deviceCode(said[stream]);
34
+ if (!found) return;
35
+ reported = true; clearTimeout(silent);
36
+ reporting = coda('progress', JSON.stringify(found)).catch(error => fail(error.message));
37
+ };
38
+ for (const stream of ['stdout', 'stderr']) child[stream].setEncoding('utf8').on('data', heard(stream));
39
+ child.on('error', () => { failed ??= `无法启动 ${name} 登录`; });
40
+ // Coda ends the whole group: the CLI is ended with it, and waited for.
41
+ for (const signal of ['SIGTERM', 'SIGINT']) process.on(signal, () => child.kill(signal));
42
+ const code = await new Promise(resolve => child.on('close', resolve));
43
+ clearTimeout(silent);
44
+ await reporting;
45
+ if (code === 0 && !failed) { console.log('{}'); return; }
46
+ console.error(failed ?? lastLine(said[latest]) ?? '登录没有完成,请重新登录。');
47
+ process.exitCode = 1;
48
+ }
package/scripts/quota.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  // What the「Kimi」resource type shows (docs/plugins.md「内置插件:Kimi Code」): the signed-in account and its quota, from what the
2
2
  // Kimi CLI's local server says (`/oauth/userinfo`, `/oauth/usage`, the same getManagedUsage its /status uses).
3
- const line = (value, max = 80) => typeof value === 'string' ? [...value.replace(/\s+/g, ' ').trim()].slice(0, max).join('') : '';
3
+ export const line = (value, max = 80) => typeof value === 'string' ? [...value.replace(/\s+/g, ' ').trim()].slice(0, max).join('') : '';
4
4
  const instant = value => typeof value === 'string' && Number.isFinite(Date.parse(value)) ? new Date(value).toISOString() : null;
5
5
 
6
6
  // Who is signed in, as the CLI's own page shows it: the nickname and membership level, never the phone number or email
7
- // that come with them. Null when Kimi refuses the login (revoked though the file is still there).
7
+ // that come with them. Null when Kimi refuses the login.
8
8
  export function account(data) {
9
- if (data?.kind === 'error' && data.status === 401) return null;
9
+ if (refused(data)) return null;
10
10
  if (data?.kind !== 'ok' || !data.userInfo) throw new Error('Kimi 没有说明是谁登录的');
11
11
  const id = typeof data.userInfo.userId === 'string' || typeof data.userInfo.userId === 'number' ? line(String(data.userInfo.userId), 120) : '';
12
12
  return { name: line(data.userInfo.nickname), plan: line(data.userInfo.userLevelName), ...(id ? { id } : {}) };
@@ -31,10 +31,13 @@ export function windows(data) {
31
31
  }
32
32
  return meters;
33
33
  }
34
- // The login as a resource: its nickname, its quota, or why it has none.
34
+ // The login as a resource: its nickname and its quota. Throws, saying why, for a quota that was not had or is not there.
35
35
  export function resource(who, usage) {
36
- const values = usage.error ? [] : windows(usage.data) ?? [];
37
- const error = usage.error ? `暂时无法获取额度:${usage.error}` : values.length ? null : '暂时无法获取额度:Kimi 没有给出额度';
36
+ if (usage.error) throw new Error(`暂时无法获取额度:${usage.error}`);
37
+ const values = windows(usage.data) ?? [];
38
+ if (!values.length) throw new Error('暂时无法获取额度:Kimi 没有给出额度');
38
39
  // The account, compared across machines by Coda's group view: its user ID, which the row does not show.
39
- return { name: who.name || 'Kimi', ...(who.id ? { identity: `kimi:${who.id}` } : {}), values, ...(error ? { error: line(error) } : {}) };
40
+ return { name: who.name || 'Kimi', ...(who.id ? { identity: `kimi:${who.id}` } : {}), values, buttons: [] };
40
41
  }
42
+ // Whether Kimi refuses the login (revoked though the file is still there).
43
+ export const refused = data => data?.kind === 'error' && data.status === 401;
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+ // The `coda/resource@1` record of the「Kimi」type, printed once. No login file here shows no resource (the type is then offered under
3
+ // 「添加资源」); a login file that cannot be read, one Kimi refuses, or a login without its CLI is one row saying so. The record always
4
+ // carries the sign-in, which the page offers with an install first when the CLI is not there. A CLI that cannot be asked, or whose
5
+ // answer cannot be understood or has no quota, fails the command (exit 1, the reason on the last line of its standard error), which
6
+ // keeps the record Coda has. Who is signed in is asked once for each
7
+ // state of the login file, which the CLI rewrites as it signs in and renews, and kept in this plugin's state: Kimi's own upstream
8
+ // lookup takes seconds and gives up after 8. The quota is asked each reading, of the same `kimi web`.
9
+ import { readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
10
+ import { homedir } from 'node:os';
11
+ import { join } from 'node:path';
12
+ import { kimiBinary } from '../agent/binary.mjs';
13
+ import { account, line, refused, resource } from './quota.mjs';
14
+ import { kimiWeb } from './web.mjs';
15
+
16
+ const home = process.env.KIMI_CODE_HOME || join(homedir(), '.kimi-code');
17
+ const binary = kimiBinary();
18
+ const signedOut = '登录已失效,请重新登录';
19
+ const problem = reason => ({ resources: [{ name: 'Kimi', values: [], buttons: [], error: line(reason) }] });
20
+
21
+ async function read() {
22
+ let changed;
23
+ try { changed = statSync(join(home, 'credentials/kimi-code.json')).mtimeMs; }
24
+ catch (error) { return error.code === 'ENOENT' ? { resources: [] } : problem(`读不了 Kimi 的登录:${error.code}`); }
25
+ if (!binary) return problem('这台机器上找不到 Kimi CLI,用「···」里的「重新登录」安装');
26
+
27
+ const seenFile = process.env.CODA_PLUGIN_STATE && join(process.env.CODA_PLUGIN_STATE, 'account.json');
28
+ let seen = null;
29
+ try { seen = JSON.parse(readFileSync(seenFile, 'utf8')); } catch {}
30
+ const known = seen?.changed === changed;
31
+ const [usage, info] = await kimiWeb(['/api/v1/oauth/usage', ...(known ? [] : ['/api/v1/oauth/userinfo'])], { binary, home });
32
+ if (refused(usage.data)) return problem(signedOut);
33
+ // The login changed and who it is could not be asked: the last name and plan stand in, but not the last ID, which is
34
+ // the other login's and would name this one's quota as that account's.
35
+ let who = known ? seen.account : { name: seen?.account?.name ?? '', plan: seen?.account?.plan ?? '' };
36
+ if (!known) {
37
+ try {
38
+ if (info.error) throw new Error(info.error);
39
+ who = account(info.data);
40
+ if (seenFile) { writeFileSync(`${seenFile}.tmp`, JSON.stringify({ changed, account: who })); renameSync(`${seenFile}.tmp`, seenFile); }
41
+ } catch { /* Not told now: the account seen last, or the kind's own name, and asked again next time. */ }
42
+ }
43
+ return who ? { resources: [resource(who, usage)] } : problem(signedOut);
44
+ }
45
+ try {
46
+ console.log(JSON.stringify([{ key: 'account', spec: { type: 'account', title: 'Kimi', ...await read(),
47
+ signIn: { installed: binary !== null, installable: true, note: '登录保存在这台机器的 Kimi CLI 里,由它自己续期。' } } }]));
48
+ } catch (error) { console.error(String(error.message).replace(/\s+/g, ' ').trim()); process.exit(1); }
package/scripts/setup.mjs CHANGED
@@ -1,8 +1,9 @@
1
+ #!/usr/bin/env node
1
2
  // 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; the「Kimi」resource type's install runs it too. Without a Kimi CLI that runs, or
3
+ // ends well once the machine can run the agent; the `install` operation of `coda/resource@1` (the「Kimi」type's) runs it too. Without a Kimi CLI that runs, or
3
4
  // with one older than MINIMUM (the file layout the relay reads, agent/observe.mjs), Kimi's own installer (install.sh) puts that
4
5
  // version (KIMI_VERSION) in ~/.kimi-code/bin, where the agent looks first; a newer one is kept. Why the machine is not ready
5
- // is said in one line on standard error.
6
+ // is said in one line on standard error; the result, when it is, is `{}`.
6
7
  import { spawnSync } from 'node:child_process';
7
8
  import { realpathSync } from 'node:fs';
8
9
  import { fileURLToPath } from 'node:url';
@@ -40,5 +41,6 @@ if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToP
40
41
  }
41
42
  const after = needed(kimiBinary());
42
43
  if (after.action !== 'none') { console.error(after.reason); process.exit(1); }
43
- console.log(`Kimi CLI ${after.version}`);
44
+ console.error(`Kimi CLI ${after.version}`);
45
+ console.log('{}');
44
46
  }
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ // The「Kimi」resource type's sign-in (the `sign-in` operation of `coda/resource@1`): `kimi login`, the device-code login of the CLI
3
+ // the agent runs. `kimi login` opens the link with `open` (`xdg-open` on Linux) whatever BROWSER says: on a machine the user is not
4
+ // at, that would be a page left open for no one, so it finds do-nothing ones first on its PATH, in this plugin's own state.
5
+ import { spawn } from 'node:child_process';
6
+ import { chmodSync, mkdirSync, writeFileSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { kimiBinary } from '../agent/binary.mjs';
9
+ import { deviceLogin } from './device-login.mjs';
10
+
11
+ const binary = kimiBinary();
12
+ if (!binary) { console.error('这台机器上找不到 Kimi CLI'); process.exit(1); }
13
+ const stubs = join(process.env.CODA_PLUGIN_STATE, 'no-browser');
14
+ mkdirSync(stubs, { recursive: true });
15
+ for (const name of ['open', 'xdg-open']) { writeFileSync(join(stubs, name), '#!/bin/sh\nexit 0\n'); chmodSync(join(stubs, name), 0o755); }
16
+ await deviceLogin(() => spawn(binary, ['login'], { env: { ...process.env, PATH: `${stubs}:${process.env.PATH}`, NO_COLOR: '1' }, stdio: ['ignore', 'pipe', 'pipe'] }), 'Kimi');
package/scripts/login.sh DELETED
@@ -1,8 +0,0 @@
1
- #!/bin/sh
2
- # The「Kimi」resource type's login (`signIn`): `kimi login`, the device-code login of the CLI the agent runs. `kimi login` opens the
3
- # link with `open` (`xdg-open` on Linux) whatever BROWSER says: on a machine the user is not at, that would be a page left
4
- # open for no one, so it finds do-nothing ones first on its PATH, in this plugin's own state.
5
- stubs="$CODA_PLUGIN_STATE/no-browser"
6
- mkdir -p "$stubs" && for name in open xdg-open; do printf '#!/bin/sh\nexit 0\n' > "$stubs/$name" && chmod 755 "$stubs/$name"; done || exit 1
7
- k="$HOME/.kimi-code/bin/kimi"; [ -x "$k" ] || k=kimi
8
- PATH="$stubs:$PATH" NO_COLOR=1 exec "$k" login
@@ -1,37 +0,0 @@
1
- // The「Kimi」resources, printed once as `{ resources }`. No login file here shows nothing (the type is then offered under
2
- // 「添加资源」). Who is signed in is asked once for each state of the login file, which the CLI rewrites as it signs in and
3
- // renews, and kept in this plugin's state: Kimi's own upstream lookup takes seconds and gives up after 8. The quota is
4
- // asked each reading, of the same `kimi web`.
5
- import { readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
6
- import { homedir } from 'node:os';
7
- import { join } from 'node:path';
8
- import { kimiBinary } from '../agent/binary.mjs';
9
- import { account, resource } from './quota.mjs';
10
- import { kimiWeb } from './web.mjs';
11
-
12
- const home = process.env.KIMI_CODE_HOME || join(homedir(), '.kimi-code');
13
- const print = value => console.log(JSON.stringify(value));
14
- let changed;
15
- try { changed = statSync(join(home, 'credentials/kimi-code.json')).mtimeMs; }
16
- catch (error) { if (error.code === 'ENOENT') { print({ resources: [] }); process.exit(0); } console.error(`读不了 Kimi 的登录:${error.code}`); process.exit(1); }
17
- const binary = kimiBinary();
18
- if (!binary) { print({ resources: [{ name: 'Kimi', error: '这台机器上找不到 Kimi CLI,用「···」里的「重新登录」安装' }] }); process.exit(0); }
19
-
20
- const seenFile = process.env.CODA_PLUGIN_STATE && join(process.env.CODA_PLUGIN_STATE, 'account.json');
21
- let seen = null;
22
- try { seen = JSON.parse(readFileSync(seenFile, 'utf8')); } catch {}
23
- const known = seen?.changed === changed;
24
- try {
25
- const [usage, info] = await kimiWeb(['/api/v1/oauth/usage', ...(known ? [] : ['/api/v1/oauth/userinfo'])], { binary, home });
26
- // The login changed and who it is could not be asked: the last name and plan stand in, but not the last ID, which is
27
- // the other login's and would name this one's quota as that account's.
28
- let who = known ? seen.account : { name: seen?.account?.name ?? '', plan: seen?.account?.plan ?? '' };
29
- if (!known) {
30
- try {
31
- if (info.error) throw new Error(info.error);
32
- who = account(info.data);
33
- if (seenFile) { writeFileSync(`${seenFile}.tmp`, JSON.stringify({ changed, account: who })); renameSync(`${seenFile}.tmp`, seenFile); }
34
- } catch { /* Not told now: the account seen last, or the kind's own name, and asked again next time. */ }
35
- }
36
- print({ resources: who ? [resource(who, usage)] : [] });
37
- } catch (error) { console.error(error.message); process.exit(1); }