@coda-console/plugin-check 0.8.19 → 0.8.20

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
@@ -61,7 +61,7 @@ Coda 插件页的「商店」列出 Coda 自带的插件,以及 npm 上 `@coda
61
61
 
62
62
  | 插件 | npm 依赖(与 Coda 后端同版本) | 运行机上另要 |
63
63
  | --- | --- | --- |
64
- | `codex` | `@agentclientprotocol/codex-acp` 1.12.0、`@openai/codex` 0.165.0;`overrides` 让 codex-acp 用同一个 `@openai/codex` | — |
64
+ | `codex` | `@agentclientprotocol/codex-acp` 1.12.0、`@openai/codex` 0.169.0;`overrides` 让 codex-acp 用同一个 `@openai/codex` | — |
65
65
  | `claude` | `@agentclientprotocol/sdk` 1.4.0、`@anthropic-ai/claude-agent-sdk` 0.3.312(平台二进制是 SDK 自己的可选依赖) | — |
66
66
  | `codex-accounts` | `proper-lockfile` 4.1.2;用依赖插件 `codex` 的 Codex CLI | 无;依赖 `codex` 插件 |
67
67
  | `kimi` | 无 | Kimi CLI 2.1.1 及以上(缺失或更旧时设置动作装入口核对过的 2.1.1,更新的不动;资源页上可从 Coda 安装、登录) |
@@ -0,0 +1,48 @@
1
+ // A panel's command run once to its end, as Coda's panels module ran it before it took `runPluginCommand`
2
+ // (check/coda/resources/plugins/resources/panels/command.mjs, which a sync drops): `sh -c` in its own process group, its
3
+ // standard output kept apart from what it says on standard error, both bounded. Kept here so the checker runs with the
4
+ // panels module of either version: `start`, `cwd` and `input`, which the newer one passes, are ignored, and the command's
5
+ // standard input stays closed.
6
+ import { spawn } from 'node:child_process';
7
+ import { tmpdir } from 'node:os';
8
+
9
+ const ansi = /\x1b\[[0-9;]*[A-Za-z]/g;
10
+ // The last thing a failed command said, for the one line the user sees.
11
+ export const lastLine = text => text.replace(ansi, '').split('\n').map(line => line.trim()).filter(Boolean).at(-1)?.slice(0, 200) ?? '';
12
+
13
+ export function runCommand(command, { env, timeoutMs, signal: aborted, maxBytes = 64 * 1024 }) {
14
+ return new Promise(resolve => {
15
+ const child = spawn('/bin/sh', ['-c', command], { cwd: tmpdir(), env, detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
16
+ const out = [], err = [];
17
+ let sizes = [0, 0], overflow = false, timedOut = false, finished = false, hard = null;
18
+ const signal = name => { try { process.kill(-child.pid, name); } catch {} };
19
+ const stop = () => { signal('SIGTERM'); hard = setTimeout(() => signal('SIGKILL'), 2000); };
20
+ const due = setTimeout(() => { timedOut = true; stop(); }, timeoutMs);
21
+ const abort = () => { if (!finished) signal('SIGKILL'); };
22
+ aborted?.addEventListener('abort', abort, { once: true });
23
+ const keep = (chunks, i) => chunk => {
24
+ if (sizes[i] + chunk.length > maxBytes) { if (i === 0 && !overflow) { overflow = true; stop(); } return; }
25
+ sizes[i] += chunk.length; chunks.push(chunk);
26
+ };
27
+ child.stdout.on('data', keep(out, 0));
28
+ child.stderr.on('data', keep(err, 1));
29
+ const finish = (code, error) => {
30
+ if (finished) return;
31
+ finished = true; clearTimeout(due); clearTimeout(hard); aborted?.removeEventListener('abort', abort);
32
+ // Whatever it left behind in its group goes with it.
33
+ if (child.pid) signal('SIGKILL');
34
+ resolve({ code, stdout: Buffer.concat(out).toString('utf8'), stderr: Buffer.concat(err).toString('utf8'), timedOut, overflow, ...(error ? { error } : {}) });
35
+ };
36
+ child.on('error', error => finish(null, error.message));
37
+ child.on('close', code => finish(code));
38
+ });
39
+ }
40
+ // A command ended well: by itself, with 0. One stopped for its deadline or its output may still say 0 on the way out.
41
+ export const ended = result => result.code === 0 && !result.timedOut && !result.overflow;
42
+ // Why a command did not end well, in one line.
43
+ export function outcome(result, what) {
44
+ if (result.timedOut) return `${what}超时`;
45
+ if (result.overflow) return '输出过长';
46
+ if (result.error) return `${what}没有开始:${result.error}`;
47
+ return lastLine(result.stderr) || lastLine(result.stdout) || `${what}没有完成(退出码 ${result.code ?? '无'})`;
48
+ }
package/check/panel.mjs CHANGED
@@ -5,7 +5,7 @@
5
5
  // Its actions are not run: a button may change things (switch an account, spend a reset), and only a person presses it.
6
6
  import { dirname } from 'node:path';
7
7
  import { cleared } from './coda/components/plugins/plugin-rules.mjs';
8
- import { ended, runCommand } from './coda/resources/plugins/resources/panels/command.mjs';
8
+ import { ended, runCommand } from './command.mjs';
9
9
  import { Panels } from './coda/resources/plugins/resources/panels/panels.mjs';
10
10
  import { OUTPUT_LIMIT, panelItems, resourceItems } from './coda/resources/plugins/resources/panels/rules.mjs';
11
11
  import { closing, temporary } from './leftovers.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/plugin-check",
3
- "version": "0.8.19",
3
+ "version": "0.8.20",
4
4
  "description": "Coda 插件的契约检查:扮演 Coda 读清单、启动 Agent 讲 ACP 与 _coda/wait、读资源类型(与旧的面板)。",
5
5
  "license": "MIT",
6
6
  "repository": {