@coda-console/plugin-check 0.5.11 → 0.5.13

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
@@ -399,10 +399,10 @@ gh workflow run publish.yml --repo coda-console/coda-plugins --ref main
399
399
 
400
400
  ## 契约检查
401
401
 
402
- 扮演 Coda 去读一个插件目录:清单用 Coda 自己的代码读,Agent 照 Coda 的样子启动、说 Coda 说的话,面板由 Coda 的资源插件模块读一次。
403
- 规则只在 Coda 里写:`check/coda/` 是 Coda 代码的原样副本(见[契约副本](#契约副本)),检查包手写的只有怎样扮演 Coda、怎样判。
404
- 清单照「从仓库添加…」的顺序读,Coda 在第一处拒绝就停,检查也只报这一处;扮演的是一台刚装好的 Coda(只有它自带与默认装的插件),
405
- 装进别的 Coda 时版本或已装的插件不同,以那台的读取为准。
402
+ 扮演 Coda 去读一个插件目录:清单对 Coda 的类型 schema 校验,Agent 照 Coda 的样子启动、说 Coda 说的话,面板由 Coda 的资源插件模块读一次。
403
+ 插件写的合乎它用到的类型就对:清单的写法只在协议包 `@coda-console/protocol`([coda-console/coda-protocol](https://github.com/coda-console/coda-protocol))的 schema 里,由 Coda 自己用的同一个校验器判,
404
+ 检查包不另写规则,Coda 加字段只是改 schema。`check/coda/` 是 Coda 文件的原样副本(见[契约副本](#契约副本)),检查包手写的只有怎样扮演 Coda、怎样判。
405
+ 只在装到一台机器上才知道的(仓库里扫不扫得到、npm 锁文件、和那台已装插件冲突)是那台 Coda 安装时说的,不是插件类型的问题,检查不跑。
406
406
 
407
407
  ```sh
408
408
  npm ci
@@ -414,8 +414,8 @@ npx github:coda-console/coda-plugins#<提交> <插件目录>
414
414
 
415
415
  | 级 | 要不要登录 | 查什么 |
416
416
  | --- | --- | --- |
417
- | 清单(总是) | 不要 | Coda 读仓库的顺序:目录扫得到、名字合规;目录里无符号链接与子模块、不超过 10 MiB(`treeProblem`);`readPlugin` 读得成插件;带 npm 依赖要有对得上的 `package-lock.json`(`manifestProblem`);与刚装好的 Coda 的插件不冲突、要一起装的找得到(`candidate`:默认装着的内置插件的 ID、别的插件声明的 Agent、组、扩展点等)。本仓库 `plugins/<id>` 里的内置插件按内置插件的同一来源读(新版本可以盖过它)。另有只提醒的:分类、版本、图标页面太小、旧的 Agent ID `claude`、没提交的文件。面板声明由资源插件的 `panelEntries` 读 |
418
- | 握手(默认) | 不要 | `sh -c` 启动 `command`(环境是 Coda 的 `pluginEnv` 给的:`CODA_NODE`、`CODA_PLUGIN_PATH`、临时的 `CODA_PLUGIN_STATE`、设置默认值的 `CODA_PLUGIN_SETTINGS`;依赖的插件在同一仓库里时 `CODA_PLUGIN_DEPENDENCIES` 给它的目录,Coda 自带的不在这里、不给),发与 Coda 相同的 `initialize`,要求 `protocolVersion` 为 1、声明会话指令(`sessionCapabilities.systemPrompt`,没声明算失败);`session/new` 带会话指令,给出会话与当前模型,回 -32000 记为未登录、跳过后面的检查(不算失败);像 Coda 一样对进程组发 SIGTERM,5 秒内要退出(超过 0.8 秒提醒);另起一个进程,关掉标准输入后 5 秒内不退出只提醒。面板由 Coda 资源插件的 `Panels` 读一次(30 秒),输出合格式 |
417
+ | 清单(总是) | 不要 | `package.json` 对 Coda 的类型 schema 校验(`manifestProblem`),再照 Coda 读成插件(`readPlugin`:ID、设置名在 ID 之下);写给别的插件扩展点的键,要有 Coda 自带的或旁边依赖的插件声明这个类型。另有只提醒的:分类、版本、图标页面太小、旧的 Agent ID `claude`。面板声明由资源插件的 `panelEntries` 读 |
418
+ | 握手(默认) | 不要 | `sh -c` 启动 `command`(环境是 Coda 的 `pluginEnv` 给的:`CODA_NODE`、`CODA_PLUGIN_PATH`、临时的 `CODA_PLUGIN_STATE`、设置默认值的 `CODA_PLUGIN_SETTINGS`;依赖的插件在旁边(同一个父目录里同名的目录)时 `CODA_PLUGIN_DEPENDENCIES` 给它的目录,Coda 自带的不在这里、不给),发与 Coda 相同的 `initialize`,要求 `protocolVersion` 为 1、声明会话指令(`sessionCapabilities.systemPrompt`,没声明算失败);`session/new` 带会话指令,给出会话与当前模型,回 -32000 记为未登录、跳过后面的检查(不算失败);像 Coda 一样对进程组发 SIGTERM,5 秒内要退出(超过 0.8 秒提醒);另起一个进程,关掉标准输入后 5 秒内不退出只提醒。面板由 Coda 资源插件的 `Panels` 读一次(30 秒),输出合格式 |
419
419
  | 一轮(`--live`) | 要 | 第一轮问会话指令里的检查词(一个随机词),回复里要有它;再发一轮提示词(默认「只回复 ok」)收到 `stopReason`;每条 `session/update` 过 ACP SDK 的 schema;`_coda/wait` 按 Coda 的 `validWait` 与协议的规则核对(子 Agent 不带 `childSessionId`、定时不带 `at` 只提醒);审批与提问一律回拒绝,在一轮之外发来的算失败;再发一轮并 `session/cancel`,30 秒内要结束,读到取消后还在做事或拖过 5 秒才答复却不回 `cancelled` 算失败(见下);有自主轮次的也取消一次;声明插话的,一轮结束后插话要回 `promptRequired` 且不自己另开一轮,一轮进行中插话要回 `injected` 或 `promptRequired`(`injected` 的那一轮照常回 `stopReason`);声明 `loadSession` 的,新开进程 `session/load`(同样带会话指令)要成功,随后在新进程里再跑一轮也要收到 `stopReason` |
420
420
 
421
421
  **取消后的 `stopReason` 怎么判**:检查发 `session/cancel` 时紧跟一个只会得到 -32601 的探测请求(`_codaCheck/barrier`)。Agent 按顺序读,
package/bin/check.mjs CHANGED
@@ -34,6 +34,6 @@ for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => process.exi
34
34
  const dir = resolve(positionals[0]);
35
35
  const { report, plugin } = await checkPlugin(dir, { agent: values.agent ?? null, manifestOnly: !!values.manifest, live: !!values.live, prompt: values.prompt });
36
36
  const shown = positionals[0];
37
- console.log(format(report, { title: `coda-plugin-check ${pkg.version} · 插件 ${plugin?.id ?? '?'}(${shown})· 规则是 Coda ${contract.commit.slice(0, 7)} 的代码 · ACP 协议版本 ${ACP_PROTOCOL_VERSION}` }));
38
- console.log('清单照一台刚装好的 Coda 读(只有它自带与默认装的插件);装进别的 Coda 时,版本或已装的插件不同,以那台「设置 › 插件 › 从仓库添加…」的读取为准。');
37
+ console.log(format(report, { title: `coda-plugin-check ${pkg.version} · 插件 ${plugin?.id ?? '?'}(${shown})· 类型是 Coda ${contract.commit.slice(0, 7)} 的 schema · ACP 协议版本 ${ACP_PROTOCOL_VERSION}` }));
38
+ console.log('清单只查是否合乎它用到的类型;装到一台 Coda 上时,仓库、npm 锁文件与那台已装插件的冲突由那台在安装时说。');
39
39
  process.exit(report.ok ? 0 : 1);
package/check/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // The contract check of one plugin directory: the manifest, then each agent's handshake (and with `live`, a turn) and each
2
- // panel's reading. The rules are Coda's own code (check/coda/), run where a plugin is written.
2
+ // panel's reading. The manifest is checked against Coda's schemas of its types, the rest by Coda's own code (check/coda/), run where
3
+ // a plugin is written.
3
4
  import { resolve } from 'node:path';
4
5
  import { checkAgent } from './agent.mjs';
5
6
  import { checkManifest } from './manifest.mjs';
@@ -1,125 +1,46 @@
1
- // The manifest level: what Coda reads of a plugin's directory before anything of it runs, by Coda's own code (check/coda/,
2
- // copied as it is from the Coda commit check/coda/contract.json names), in the order its「从仓库添加…」reads a repository
3
- // (components/plugins/plugin-sources.mjs readSource, inspect): whether it finds the directory, what the directory holds
4
- // (treeProblem), the plugin (readPlugin), its npm packages (manifestProblem), and the plugin beside those of the machine it
5
- // goes to (candidate). Coda stops at the first thing it refuses, and the verdict here is that one failure; the rest is
6
- // advice of the checker's that Coda does not refuse a plugin for. The machine is a Coda fresh from installing it: the
7
- // plugins it ships (check/coda/builtin.json, as its builtinPlugins reads them), those it installs from the start installed.
8
- import { execFileSync } from 'node:child_process';
9
- import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync } from 'node:fs';
10
- import { basename, join, relative, sep } from 'node:path';
1
+ // The manifest level: whether the plugin is of the types it names (Coda's docs/plugins.md「插件的内容」, #1917). Its
2
+ // package.json is checked against the schemas of Coda's types (the protocol, @coda-console/protocol) by the checker Coda runs
3
+ // itself, and then read as Coda reads it: its ID, and its settings named under it. What Coda says only where it installs one — the repository it comes from, its npm
4
+ // lock, the plugins of that machine beside it — is that machine's to say, not a question of the plugin's types: the checker
5
+ // does not run it. The plugins Coda ships (check/coda/builtin.json) and those beside this one in its directory's parent
6
+ // stand in for what it depends on, for the levels after this one.
7
+ import { existsSync, readFileSync, realpathSync } from 'node:fs';
8
+ import { dirname, join } from 'node:path';
11
9
  import { inflateSync } from 'node:zlib';
12
10
  import shipped from './coda/builtin.json' with { type: 'json' };
11
+ import { manifestProblem } from '@coda-console/protocol/validate';
12
+ import { offerProblem } from './coda/components/plugins/plugin-extensions.mjs';
13
13
  import { choosesModelProviders, pluginEnv, readPlugin, resolveSettings } from './coda/components/plugins/plugin-rules.mjs';
14
- import { candidate, candidates, catalogAfter, manifestId, manifestProblem, npmPackages, repoAddress, sameSource, sourcePath, treeProblem } from './coda/components/plugins/plugin-source-rules.mjs';
15
14
  import { panelEntries } from './coda/resources/plugins/resources/panels/rules.mjs';
16
15
 
17
- // The plugins Coda ships, by ID. Their files are Coda's, not here: none has a directory on this machine, and what Coda gives
18
- // a plugin's processes of them names none.
16
+ // The plugins Coda ships, by ID. Their files are Coda's, not here: none has a directory on this machine.
19
17
  const builtin = new Map(shipped.map(plugin => [plugin.id, { ...plugin, dir: undefined }]));
20
- // Those it installs from the start, as rows without a source (components/plugins/plugins.mjs), and its catalog, which is
21
- // they and nothing installed from elsewhere yet.
18
+ // Those it installs from the start, as rows without a source (components/plugins/plugins.mjs).
22
19
  const installed = new Map(shipped.filter(plugin => plugin.defaultInstalled).map(plugin => [plugin.id, { id: plugin.id, source: null }]));
23
- const catalog = new Map(builtin);
24
20
  // The categories Coda's own plugins use, which its plugin pages list first, in this order.
25
21
  export const CATEGORIES = ['Agent', '模型与账号', '工作流程', '机器与资源', 'Skills 与工具'];
26
- // Where a refusal comes in the order Coda reads: one after the first is not reached.
27
- const ORDER = ['source.depth', 'source.segment', 'source.files', 'manifest.read', 'source.npm', 'source.catalog'];
28
-
29
- // ---- The repository, as Coda's reading of it sees it ----
30
- // The repository a directory is read from, as Coda would be given it — its Git origin, else its top directory (Coda reads a
31
- // repository of this machine by its absolute path) —, the directory in it, and the files a commit of it would hold: those
32
- // Git tracks, and those it would once they are committed (`untracked`). Outside Git, the directory is a repository of its own.
33
- function repository(dir) {
34
- const real = realpathSync(dir);
35
- const git = (at, args) => execFileSync('git', ['-C', at, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
36
- let top = null;
37
- try { top = git(real, ['rev-parse', '--show-toplevel']).trim(); } catch {}
38
- if (!top) return { top: null, at: real, repo: real, path: '', commit: null, files: walk(real) };
39
- const tracked = git(top, ['ls-files', '-s', '-z']).split('\0').filter(Boolean).map(entry => {
40
- const tab = entry.indexOf('\t'), [mode] = entry.slice(0, tab).split(' ');
41
- return { mode, name: entry.slice(tab + 1) };
42
- });
43
- const untracked = git(top, ['ls-files', '-o', '--exclude-standard', '-z']).split('\0').filter(Boolean).map(name => ({ name, untracked: true }));
44
- let repo = top, commit = null;
45
- try { repo = repoAddress(git(top, ['remote', 'get-url', 'origin']).trim()); } catch {}
46
- try { commit = git(top, ['rev-parse', 'HEAD']).trim(); } catch {}
47
- // Git names the top by its real path; so is the directory measured.
48
- return { top, at: top, repo, commit, path: relative(top, real).split(sep).filter(Boolean).join('/'), files: [...tracked, ...untracked].map(e => withStat(top, e)) };
22
+ // A plugin it depends on, beside it in its parent directory (as coda-plugins keeps them) and of the ID asked for: read as Coda
23
+ // reads one, or none.
24
+ function beside(dir, id) {
25
+ const at = join(dirname(realpathSync(dir)), id);
26
+ if (!existsSync(join(at, 'package.json'))) return null;
27
+ try { const plugin = readPlugin(at, { kind: 'git' }); return plugin.id === id ? plugin : null; } catch { return null; }
49
28
  }
50
- // Every file but `.git`, and the npm packages installed beside them, which do not count (SIZE_LIMIT); a directory with a `.git`
51
- // of its own is another repository.
52
- function walk(dir) {
53
- const entries = [];
54
- const visit = sub => {
55
- for (const name of readdirSync(join(dir, sub))) {
56
- if ((!sub && name === '.git') || name === 'node_modules') continue;
57
- const rel = sub ? `${sub}/${name}` : name, stat = lstatSync(join(dir, rel));
58
- if (stat.isDirectory()) { if (existsSync(join(dir, rel, '.git'))) entries.push({ name: rel, mode: '160000', size: 0 }); else visit(rel); }
59
- else entries.push(withStat(dir, { name: rel }));
60
- }
29
+ // The plugins it depends on, directly or through another, found beside it (`ids`: those it names), by ID; one Coda ships is
30
+ // Coda's, not looked for here.
31
+ function besideAll(dir, ids) {
32
+ const found = new Map(), seen = new Set();
33
+ const visit = id => {
34
+ if (seen.has(id) || builtin.has(id)) return;
35
+ seen.add(id);
36
+ const there = beside(dir, id);
37
+ if (!there) return;
38
+ found.set(id, there);
39
+ for (const next of there.dependencies) visit(next);
61
40
  };
62
- visit('');
63
- return entries;
64
- }
65
- function withStat(dir, entry) {
66
- let stat = null;
67
- try { stat = lstatSync(join(dir, entry.name)); } catch {}
68
- const mode = entry.mode ?? (stat?.isSymbolicLink() ? '120000' : '100644');
69
- return { ...entry, mode, size: stat && !stat.isSymbolicLink() && stat.isFile() ? stat.size : 0, missing: !stat && mode !== '160000' };
70
- }
71
- // The files of the directory at `path`, named within it, as `git ls-tree -r -l <commit>:<path>` lists them for Coda.
72
- const within = (files, path) => path ? files.filter(f => f.name.startsWith(`${path}/`)).map(f => ({ ...f, name: f.name.slice(path.length + 1) })) : files;
73
- // Coda's reading of a commit takes a directory as a plugin by its manifest saying what it contributes.
74
- const contributing = manifest => !!manifest && typeof manifest === 'object' && !Array.isArray(manifest) && 'contributes' in manifest;
75
-
76
- // What a directory is as a plugin, as Coda's inspect says it (`found`: `{ plugin }` and why it cannot be installed, or only
77
- // why), with the rule the first refusal is said under. `plugin` is read even where Coda stopped before it, for the levels
78
- // after this one; `lock` is the package-lock.json a commit would hold (null without one, undefined when it does not parse).
79
- // A file system's error reading it (a file where Coda reads a directory, say) is no problem of the directory's own to Coda:
80
- // it fails Coda's reading of the whole repository (`broken`).
81
- function inspect(dir, files, source) {
82
- let plugin = null, manifest = null, unread = null, broken = false;
83
- try { plugin = readPlugin(dir, source); manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')); }
84
- catch (e) {
85
- if (e.code !== 'invalid_plugin' && !e.syscall) throw e;
86
- unread = e.code === 'invalid_plugin' ? e.message : `读不了:${e.message}`; broken = !!e.syscall && e.code !== 'ENOENT';
87
- }
88
- let lock = null;
89
- if (files.some(f => f.name === 'package-lock.json' && !f.missing)) try { lock = JSON.parse(readFileSync(join(dir, 'package-lock.json'), 'utf8')); } catch { lock = undefined; }
90
- const tree = treeProblem(files);
91
- if (tree) return { found: { problem: tree }, rule: 'source.files', plugin, lock };
92
- if (unread) return { found: { problem: unread }, rule: 'manifest.read', plugin, lock, broken };
93
- const npm = manifestProblem(manifest, lock);
94
- plugin = { ...plugin, npm: npmPackages(manifest, lock) };
95
- return { found: { plugin, problem: npm }, rule: npm ? 'source.npm' : null, plugin, lock };
96
- }
97
- // Why Coda's reading of the repository does not get to the directory at `path`, or null: it looks for plugins only so deep
98
- // (candidates), and a source names only some directories (sourcePath; readSource says so in these words).
99
- function located(path) {
100
- if (!candidates([path ? `${path}/package.json` : 'package.json']).length)
101
- return { problem: `插件目录 ${path} 在仓库根下超过 2 层(或在 node_modules 里):Coda 读仓库时扫不到它`, rule: 'source.depth' };
102
- try { sourcePath(path); } catch { return { problem: `目录名 ${path} 只能用字母、数字和「._-」`, rule: 'source.segment' }; }
103
- return null;
41
+ for (const id of ids) visit(id);
42
+ return found;
104
43
  }
105
- // The other plugins of the same commit, by ID → `{ path, plugin }`: those that read, as Coda's readSource finds them; and
106
- // those whose reading fails Coda's reading of the whole repository (`broken`: path → why).
107
- function siblingsOf(repo, own) {
108
- const found = new Map(), broken = new Map();
109
- for (const path of candidates(repo.files.filter(f => !f.missing).map(f => f.name))) {
110
- if (path === own) continue;
111
- const dir = join(repo.at, path);
112
- let manifest = null;
113
- try { manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')); } catch {}
114
- if (!contributing(manifest)) continue;
115
- try { sourcePath(path); } catch { continue; }
116
- const read = inspect(dir, within(repo.files, path), { kind: 'git', repo: repo.repo, path, ref: '', commit: repo.commit });
117
- if (read.broken) broken.set(path, read.found.problem);
118
- else if (read.plugin && !read.found.problem) found.set(read.plugin.id, { path, plugin: read.plugin });
119
- }
120
- return { found, broken };
121
- }
122
-
123
44
  // iOS draws an icon's PDF at 96 points and only ever scales it down: a smaller page comes out as a dot (Coda's own icons are
124
45
  // 256 points). The page box may sit in a compressed object stream (PDF 1.5 and later, as CairoSVG writes them).
125
46
  function pageSize(data) {
@@ -139,43 +60,22 @@ function pageSize(data) {
139
60
 
140
61
  // Checks the manifest in `dir` and reports under `say` (report.mjs). Returns what the later levels need — the plugin as Coda
141
62
  // reads it, its agents and the panels the resources plugin can read, its settings for every project, the directories of the
142
- // plugins it depends on that are here, and `env(stateDir)`, what Coda gives each of its processes —; null when Coda reads no
143
- // plugin there.
63
+ // plugins it depends on that are here, and `env(stateDir)`, what Coda gives each of its processes —; null when it is no
64
+ // plugin, or not of the types it names.
144
65
  export function checkManifest(dir, say) {
145
66
  let manifest;
146
67
  try { manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')); }
147
68
  catch (e) { say.fail('manifest.read', `没有可读的 package.json:${e.message}`); return null; }
148
- if (!contributing(manifest)) { say.fail('manifest.contributes', 'package.json 没有 contributes:Coda 读仓库时不把这个目录当插件'); return null; }
149
- const repo = repository(dir), { path } = repo, files = within(repo.files, path);
150
- // A plugin Coda ships, checked where it is kept: a new version of it, from the same source — its directory in the repository
151
- // it comes from (as Coda's「从仓库添加…」reads it there), or the package Coda ships it as, read as from where that package is
152
- // published. Any other of the same ID is a plugin from elsewhere, refused while Coda has the built-in one installed.
153
- const own = [...builtin.values()].find(b => b.id === manifestId(manifest) && b.source?.repo
154
- && ((b.source.package && b.source.package === manifest.name) || sameSource(b.source, { repo: repo.repo, path })));
155
- const source = { kind: 'git', repo: own?.source.repo ?? repo.repo, path: own?.source.path ?? path, ref: '', commit: repo.commit };
156
-
157
- const where = located(path), read = inspect(dir, files, source), { found: siblings, broken } = siblingsOf(repo, path);
158
- for (const [at, why] of broken) say.fail('source.read', `同一仓库的 ${at} ${why}:Coda 读这个仓库时整个出错,这个插件也装不了`);
159
- const judged = candidate({ path, manifest, ...(where ? { problem: where.problem } : read.found), fallback: basename(path || repo.repo).replace(/\.git$/, '') },
160
- { catalog, installed, builtin }, siblings);
161
- const refused = judged.problem ? where?.rule ?? read.rule ?? 'source.catalog' : null;
162
- const reached = rule => !refused || ORDER.indexOf(rule) < ORDER.indexOf(refused);
163
- if (refused) say.fail(refused, refused === 'manifest.read' ? `Coda 读不成插件:${judged.problem}`
164
- : refused === 'source.npm' && read.lock === null && existsSync(join(dir, 'package-lock.json')) ? `${judged.problem}(有这个文件,但被 .gitignore 忽略了,不在提交里)` : judged.problem);
165
-
166
- // What a commit of the directory holds, said after what Coda read of it.
167
- const commit = () => {
168
- const size = files.reduce((sum, e) => sum + e.size, 0), untracked = files.filter(e => e.untracked), missing = files.filter(e => e.missing);
169
- if (reached('source.files') && refused !== 'source.files') say.pass('source.files', `从仓库安装的限制:无符号链接与子模块,整个目录 ${(size / 1024).toFixed(1)} KiB`);
170
- if (untracked.length) say.warn('source.untracked', `${untracked.length} 个文件还没提交(如 ${untracked[0].name}):Coda 只读提交里的文件`);
171
- if (missing.length) say.warn('source.missing', `${missing.length} 个已跟踪的文件在工作区里不见了(如 ${missing[0].name})`);
172
- if (!repo.top) say.info('source.git', '目录不在 Git 仓库里:按目录里的文件检查,提交后以 Coda 读到的为准');
173
- };
174
- const { plugin } = read;
175
- if (!plugin) { commit(); return null; }
69
+ if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest) || !('contributes' in manifest)) {
70
+ say.fail('manifest.contributes', 'package.json 没有 contributes:Coda 读仓库时不把这个目录当插件'); return null;
71
+ }
72
+ const problem = manifestProblem(manifest, dir);
73
+ if (problem) { say.fail('manifest.read', `不合它用到的类型:${problem}`); return null; }
74
+ let plugin;
75
+ try { plugin = readPlugin(dir, { kind: 'git' }); }
76
+ catch (e) { if (e.code !== 'invalid_plugin') throw e; say.fail('manifest.read', `Coda 读不成插件:${e.message}`); return null; }
176
77
 
177
- say.pass('manifest.name', `package.json 能读,插件 ID ${plugin.id}${own ? `(Coda 内置插件 ${own.id}:Coda 带的是${own.source.package
178
- ? ` npm 上 ${own.source.package} 的一个版本` : ` ${own.source.repo} 的一个提交`},这里是它同一来源的新版本,可以盖过它)` : ''}`);
78
+ say.pass('manifest.name', `package.json 合乎它用到的类型,插件 ID ${plugin.id}${builtin.has(plugin.id) ? `(Coda 也自带 ${plugin.id}:装同一来源的新版本才能盖过它)` : ''}`);
179
79
  if (typeof manifest.version !== 'string') say.warn('manifest.version', 'package.json 没有 version:Coda 只认提交,version 只作显示,但安装确认里会空着');
180
80
  // Coda's plugin pages group plugins by the first of their `categories` (Coda's docs/plugins.md「商店」).
181
81
  if (!plugin.category) say.warn('manifest.categories', `package.json 没有 categories:Coda 的插件页把它归「其他」;分类用 ${CATEGORIES.join('、')} 之一`);
@@ -196,12 +96,17 @@ export function checkManifest(dir, say) {
196
96
  const icons = [['light', declared.light], ...(agent.icon.dark ? [['dark', declared.dark]] : [])].map(([key, at]) => ({ at, data: Buffer.from(agent.icon[key], 'base64') }));
197
97
  say.pass('manifest.agents', `Agent ${agent.id}「${agent.displayName}」:command 一行,图标 PDF(${icons.map(i => `${i.at} ${(i.data.length / 1024).toFixed(1)} KiB`).join(',')})`);
198
98
  // Sessions from before #1069 store the agent ID `claude`: a plugin that declares it takes them over.
199
- if (agent.id === 'claude') say.warn('manifest.agent-id', 'Agent ID claude 是 Coda 早先的 Claude 会话存的 ID:Coda 的读取来源不拦它,但装上会接管那些旧会话,换一个 ID');
99
+ if (agent.id === 'claude') say.warn('manifest.agent-id', 'Agent ID claude 是 Coda 早先的 Claude 会话存的 ID:装上会接管那些旧会话,换一个 ID');
200
100
  for (const icon of icons) {
201
101
  const page = pageSize(icon.data);
202
102
  if (page && Math.min(page.width, page.height) < 64) say.warn('manifest.icon-page', `${icon.at} 的页面只有 ${page.width}×${page.height} pt:iOS 按 96 pt 光栅化图标、只缩不放,页面太小会画成一个点;照 Coda 自带图标按 256 px(192 pt)出图`);
203
103
  }
204
104
  });
105
+ // What it writes for other plugins' points (Coda's own keys aside) is of the types they declare: one no plugin Coda ships, and
106
+ // none it depends on beside it (directly or through another), declares is of no type.
107
+ const found = besideAll(dir, plugin.dependencies);
108
+ const offered = offerProblem(plugin, new Map([...builtin, ...found]));
109
+ if (offered) say.fail('manifest.offers', offered);
205
110
  // Its panels, as the resources plugin reads what is written for its point: one it cannot read shows there as such.
206
111
  const panels = [];
207
112
  for (const entry of panelEntries(plugin.offers?.panels, plugin.displayName)) {
@@ -211,33 +116,19 @@ export function checkManifest(dir, say) {
211
116
  say.pass('manifest.panels', `面板 ${panel.id}「${panel.title}」:动作 ${Object.keys(panel.actions).join('、') || '无'}${panel.signIn ? ',可从 Coda 登录' : ''}`);
212
117
  }
213
118
 
214
- // What its processes are given (pluginEnv), on this machine: the plugins it depends on as Coda picks them (catalogAfter:
215
- // the one the machine has, else the one of the same commit installed with it). One Coda ships has its directory in Coda,
216
- // not here, unless this repository keeps its source (sameSource as Coda's), which stands in for it; one Coda has nowhere
217
- // (it refuses the plugin for it) is not named.
218
- const kept = id => { const at = siblings.get(id), shipped = builtin.get(id);
219
- return at && shipped && sameSource(shipped.source, { repo: repo.repo, path: at.path }) ? at.plugin.dir : undefined; };
220
- const local = catalogAfter(plugin, { catalog, siblings });
221
- const given = new Map([...[...local].map(([id, each]) => [id, each.dir ? each : { ...each, dir: kept(id) }]),
222
- [plugin.id, { ...plugin, dependencies: plugin.dependencies.filter(d => local.has(d)) }]]);
223
- const dependencies = Object.fromEntries(plugin.dependencies.flatMap(d => given.get(d)?.dir ? [[d, given.get(d).dir]] : []));
119
+ // What its processes are given (pluginEnv): the plugins it depends on, those beside it here; one Coda ships has its
120
+ // directory in Coda, not here, even with one of its ID beside it (Coda picks its own), and one found nowhere is not named.
121
+ const given = new Map([...builtin, ...found, [plugin.id, { ...plugin, dependencies: plugin.dependencies.filter(d => found.has(d) || builtin.has(d)) }]]);
122
+ const dependencies = Object.fromEntries([...found].filter(([id]) => plugin.dependencies.includes(id)).map(([id, each]) => [id, each.dir]));
224
123
  if (plugin.dependencies.length) {
225
- const absent = plugin.dependencies.filter(d => !dependencies[d]);
226
- say.info('manifest.extensions', `依赖 ${plugin.dependencies.join('、')}:Coda 装它时先装它们(这台机器的插件,或同一提交里的兄弟目录),它的进程从 CODA_PLUGIN_DEPENDENCIES 拿到它们的目录${absent.length
124
+ const absent = plugin.dependencies.filter(d => !found.has(d));
125
+ say.info('manifest.extensions', `依赖 ${plugin.dependencies.join('、')}:Coda 装它时先装它们,它的进程从 CODA_PLUGIN_DEPENDENCIES 拿到它们的目录${absent.length
227
126
  ? `;${absent.join('、')} 不在旁边,检查时不带` : ''}`);
228
127
  }
229
- commit();
230
- if (reached('source.npm') && refused !== 'source.npm' && plugin.npm?.length)
231
- say.pass('source.npm', `npm 依赖 ${plugin.npm.length} 个,带 package-lock.json:Coda 在插件的版本目录里 npm ci 装它们`);
232
- if (!refused) {
233
- const along = judged.together.map(each => each.from === 'source' ? `${each.id}(同一提交的 ${each.path})` : `${each.id}(Coda 自带)`);
234
- say.pass('source.catalog', `与刚装好的 Coda 自带、默认装的插件不冲突${along.length ? `;一起装 ${along.join('、')}` : ''}`);
235
- }
236
-
237
128
  // Its settings for every project, as nobody has set any: the declarations' defaults.
238
129
  const settings = resolveSettings(plugin).values;
239
130
  // The model services of a machine with none, for one that chooses them; the PATH has no directories of Coda's own here.
240
131
  const env = stateDir => pluginEnv({ catalog: given, installed, id: plugin.id, stateDir: id => id === plugin.id ? stateDir : null, settings,
241
132
  providers: choosesModelProviders(plugin) ? {} : null, userPath: process.env.PATH ?? '' });
242
- return { id: plugin.id, manifest, plugin, agents: plugin.agents, panels, settings, dependencies, path: repo.top ? path : null, env };
133
+ return { id: plugin.id, manifest, plugin, agents: plugin.agents, panels, settings, dependencies, env };
243
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/plugin-check",
3
- "version": "0.5.11",
3
+ "version": "0.5.13",
4
4
  "description": "Coda 插件的契约检查:扮演 Coda 读清单、启动 Agent 讲 ACP 与 _coda/wait、读面板。",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -24,6 +24,7 @@
24
24
  "dependencies": {
25
25
  "@0dep/piso": "5.2.0",
26
26
  "@agentclientprotocol/sdk": "1.4.0",
27
+ "@coda-console/protocol": "1.0.0",
27
28
  "ajv": "8.20.0",
28
29
  "yaml": "2.9.1"
29
30
  },