@coda-console/plugin-check 0.5.14 → 0.5.15

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
@@ -4,14 +4,15 @@ Coda 的公开插件仓库,和给插件作者用的契约检查。Coda 自带
4
4
 
5
5
  Coda 是一个多 Agent 客户端(Mac、iPhone 与运行在你机器上的后端)。Agent 与资源页的面板都以插件接入:
6
6
  插件是一个目录,清单就是它的 `package.json`(`contributes.agents`、`contributes.panels` 等,照 VS Code 扩展的写法);
7
- Agent 讲 [ACP](https://agentclientprotocol.com),外加 Coda 的 Agent 活动报告 `_coda/wait`,见 [接入协议](docs/agent-protocol.md)。
7
+ Agent 讲 [ACP](https://agentclientprotocol.com),外加 Coda 的 Agent 活动报告 `_coda/wait`,见 [接入协议](https://github.com/coda-console/coda-protocol/blob/main/docs/agent-protocol.md)。
8
+ 插件清单的类型、它们的 schema 与接入协议都在协议包 `@coda-console/protocol`([coda-console/coda-protocol](https://github.com/coda-console/coda-protocol))里;本仓库文中与代码注释说的 `docs/agent-protocol.md` 指那里的那份。
8
9
 
9
10
  ```
10
11
  plugins/codex/ Codex:入口在同一进程里运行锁定版本的 codex-acp(npm 依赖),面板「Codex」
11
12
  plugins/claude/ Claude SDK:基于 Claude Agent SDK 的 ACP 入口(npm 依赖),面板「Claude」
12
13
  plugins/kimi/ Kimi Code:在运行机的 kimi acp 与 Coda 之间转发,面板「Kimi」
13
14
  plugins/grok/ Grok:转发运行机上 Grok CLI 的 ACP,并适配审批模式,面板「Grok」
14
- plugins/grok-bot/ Grok Bot:把 xAI 云端 Bot 接成长期会话,Webhook 消息、定时巡检与用户审批;依赖 Coda 远端 Agent 入口
15
+ plugins/grok-bot/ Grok Bot:把 xAI 云端 Bot 接成长期会话,原生主会话、Grok Routine 运行记录与用户审批;数据工具依赖 Coda 远端 Agent 入口
15
16
  plugins/opencode/ OpenCode:在运行机的 opencode acp 与 Coda 之间转发,送入会话指令与所选模型服务,模型按来源分组
16
17
  plugins/codex-accounts/ Codex 多账号:管理登录、自动续期与账号选择,接管 Codex 额度面板
17
18
  plugins/cursor/ Cursor:在运行机的 cursor-agent acp 与 Coda 之间转发,送入会话指令
@@ -25,7 +26,6 @@ templates/agent/ 最小的 Agent 插件:手写 ACP 的回声 Agent,
25
26
  templates/panel/ 最小的面板插件:一张卡片、一条进度条、一个按钮
26
27
  bin/、check/ 契约检查(仓库根的 package.json 就是它,@coda-console/plugin-check);check/coda/ 是 Coda 同步来的规则副本,不要手改
27
28
  test/ 检查包的测试;test/plugins/ 是各插件的测试(插件目录里只放运行要用的文件)
28
- docs/agent-protocol.md Coda 接入协议正文的公开副本
29
29
  .coda/workflows/ 本仓库自己的流程:sync-coda 等新版本发到 npm,再给 Coda 开升级依赖的 PR
30
30
  ```
31
31
 
@@ -82,7 +82,7 @@ Claude 把一轮进行中的插话标上 `priority: 'next'` 交给 Claude Code
82
82
  这一轮被停止或失败时,还没并进去的插话随之撤掉(`interrupt` 带 `cancelQueued`),不会在之后再跑,原来的 `session/prompt` 等撤掉了才答复。
83
83
  结果最多列出 64 条它接收的消息,所以同时在途的插话最多 32 条,再多的回 `promptRequired`,由 Coda 在这一轮结束后作为下一轮发出。
84
84
 
85
- Claude 的额度耗尽按[执行失败](docs/agent-protocol.md#额度不足)报 `quota_exhausted`,保留上游给出的重置时间;
85
+ Claude 的额度耗尽按[执行失败](https://github.com/coda-console/coda-protocol/blob/main/docs/agent-protocol.md#额度不足)报 `quota_exhausted`,保留上游给出的重置时间;
86
86
  只认明确的额度原因,或本轮 `rate_limit` 错误配合订阅窗口的 `rejected`,不把普通 429、登录失败或额度预警算进去。
87
87
  SDK 作为 `assistant` 消息发来的 API 错误不当成回复正文;由本轮 `result` 报告失败。
88
88
  后台结果或定时唤醒后的自主轮次没有 `session/prompt` 可回复,失败时以自己的活动卡片报 `failed` 和原因,额度耗尽的卡片标题为「额度不足」;
@@ -282,7 +282,7 @@ Codex 的原生失败统一以 ACP 错误结束,包括只有 `turn/completed.f
282
282
 
283
283
  Kimi 2.1.1 会把五小时额度耗尽(`403 You've reached your 5-hour usage limit.`)误报为 ACP `auth_required`。
284
284
  Kimi 插件在 `session/prompt` 的回执中将这条已知错误改为普通执行错误(-32603),在标准 `error.message` 中保留服务端完整原因,
285
- 同时按[执行失败协议](docs/agent-protocol.md#执行失败)报告 `error.data._meta.coda.failure: {kind: "quota_exhausted"}`。
285
+ 同时按[执行失败协议](https://github.com/coda-console/coda-protocol/blob/main/docs/agent-protocol.md#执行失败)报告 `error.data._meta.coda.failure: {kind: "quota_exhausted"}`。
286
286
  Coda 按这个通用类别显示「额度不足」,不触发服务故障重试;其他 ACP 客户端仍能读取完整原因。
287
287
  插件不推算额度重置时间;其他认证失败、403、短时限流与普通错误原样保留。
288
288
  `CODA_DISABLE_RUNTIME_PATCHES=kimi` 关闭这层适配。
@@ -342,7 +342,7 @@ Agent 进程的环境是会话的环境再加插件进程的那组变量(面
342
342
  `CODA_ARBITER`(`1`:这是它所在实例自己的正式后端;动本机共享的东西前看它)。
343
343
  插件自带的入口只能用插件目录里的代码、Node 自带的模块与清单里声明的 npm 依赖。
344
344
 
345
- 照 [接入协议](docs/agent-protocol.md) 实现,另外几条容易漏的:
345
+ 照 [接入协议](https://github.com/coda-console/coda-protocol/blob/main/docs/agent-protocol.md) 实现,另外几条容易漏的:
346
346
 
347
347
  - 标准输出只写 JSON-RPC,一行一条;日志写标准错误(Coda 不读它)。请求 ID 是字符串。
348
348
  - 必须接受会话指令:`initialize` 结果声明 `agentCapabilities.sessionCapabilities.systemPrompt: {}`,`session/new`、`session/load` 收到的
@@ -438,7 +438,7 @@ npx github:coda-console/coda-plugins#<提交> <插件目录>
438
438
  ## 契约副本
439
439
 
440
440
  Coda 主仓库不公开。它的插件规则(读清单、读面板、插件进程的环境、ACP 与 `_coda/wait` 的约定等,按 Coda `backend/src/` 下的路径放在 `check/coda/`)、
441
- 它自带的插件(`check/coda/builtin.json`)与协议正文 `docs/agent-protocol.md` 都是 Coda 的原样副本,由 Coda 的部署流程 `sync-plugin-check`
441
+ 它自带的插件(`check/coda/builtin.json`)都是 Coda 的原样副本,由 Coda 的部署流程 `sync-plugin-check`
442
442
  (脚本 `scripts/plugin-contract.mjs`)同步:它在分支 `sync/coda` 上给这里开 PR。**不要手改**;规则要改先改 Coda。
443
443
  `check/coda/contract.json` 记着同步自哪个提交、每个文件的 sha256 和副本用到的包的版本,CI 用它核对:
444
444
 
@@ -513,7 +513,7 @@
513
513
  "id": "resources",
514
514
  "displayName": "资源",
515
515
  "description": "资源页:这台电脑(看一组电脑时是每一台)上已安装插件的面板,如账号与额度,按插件排列;可以隐藏、从 Coda 登录、选择显示的指标。",
516
- "version": "1.1.0",
516
+ "version": "1.2.0",
517
517
  "category": "机器与资源",
518
518
  "source": {
519
519
  "kind": "builtin"
@@ -554,6 +554,114 @@
554
554
  "signIn.command": "登录",
555
555
  "signIn.installed": "安装检查",
556
556
  "signIn.install": "安装"
557
+ },
558
+ "schema": {
559
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
560
+ "title": "contributes.panels:资源页上的面板",
561
+ "description": "面板的数组:每个面板一条读取命令,它打印的 { items } 由资源页画出来(docs/plugins.md「面板」)",
562
+ "type": "array",
563
+ "x-unique-by": [
564
+ "id"
565
+ ],
566
+ "items": {
567
+ "type": "object",
568
+ "properties": {
569
+ "id": {
570
+ "$ref": "common.json#/$defs/name"
571
+ },
572
+ "title": {
573
+ "$ref": "common.json#/$defs/line40"
574
+ },
575
+ "command": {
576
+ "$ref": "common.json#/$defs/command"
577
+ },
578
+ "maxAge": {
579
+ "description": "读数不重读还能再显示多久:ISO 8601 时长,如 PT5M(周、天与时分秒,不用年和月)",
580
+ "type": "string",
581
+ "maxLength": 200,
582
+ "pattern": "^P(?!$)(?:\\d+W)?(?:\\d+D)?(?:T(?=\\d)(?:\\d+H)?(?:\\d+M)?(?:\\d+(?:\\.\\d+)?S)?)?$"
583
+ },
584
+ "actions": {
585
+ "description": "动作名 → { command, confirm }:面板上的按钮执行的命令,和执行前问的话",
586
+ "type": "object",
587
+ "propertyNames": {
588
+ "$ref": "common.json#/$defs/name"
589
+ },
590
+ "additionalProperties": {
591
+ "type": "object",
592
+ "properties": {
593
+ "command": {
594
+ "$ref": "common.json#/$defs/command"
595
+ },
596
+ "confirm": {
597
+ "$ref": "#/$defs/question"
598
+ }
599
+ },
600
+ "required": [
601
+ "command"
602
+ ],
603
+ "additionalProperties": false
604
+ }
605
+ },
606
+ "signIn": {
607
+ "description": "从 Coda 登录:command 打印一个链接,在任一设备上确认;installed 查装没装好,install 装上它",
608
+ "type": "object",
609
+ "properties": {
610
+ "command": {
611
+ "$ref": "common.json#/$defs/command"
612
+ },
613
+ "installed": {
614
+ "$ref": "common.json#/$defs/command"
615
+ },
616
+ "install": {
617
+ "$ref": "common.json#/$defs/command"
618
+ },
619
+ "input": {
620
+ "description": "登录页给出授权码要贴回来时写 authorizationCode:贴的交给 command 的标准输入",
621
+ "const": "authorizationCode"
622
+ },
623
+ "note": {
624
+ "$ref": "#/$defs/question"
625
+ }
626
+ },
627
+ "required": [
628
+ "command"
629
+ ],
630
+ "additionalProperties": false,
631
+ "if": {
632
+ "required": [
633
+ "install"
634
+ ]
635
+ },
636
+ "then": {
637
+ "description": "写了 install 就要写 installed:Coda 才知道装没装好",
638
+ "required": [
639
+ "installed"
640
+ ]
641
+ }
642
+ },
643
+ "displaySetting": {
644
+ "description": "本插件声明的布尔值表格设置的键,用来逐项选择面板显示哪些数值",
645
+ "type": "string",
646
+ "maxLength": 80,
647
+ "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"
648
+ }
649
+ },
650
+ "required": [
651
+ "id",
652
+ "title",
653
+ "command"
654
+ ],
655
+ "additionalProperties": false
656
+ },
657
+ "$defs": {
658
+ "question": {
659
+ "description": "不超过 200 字,可以分行",
660
+ "type": "string",
661
+ "maxLength": 200,
662
+ "pattern": "^(?=[\\s\\S]*\\S)[^\\u0000]*$"
663
+ }
664
+ }
557
665
  }
558
666
  }
559
667
  },
@@ -2,8 +2,9 @@
2
2
  // may plug into a point one of them declares for it (`contributes.extensionPoints` there, `contributes.extensions` here).
3
3
  // Coda checks the names and hands each plugin what is plugged into its points, as declared: what passes between the two
4
4
  // is the extended plugin's own contract, which Coda neither reads nor shapes. A point may instead take what any plugin
5
- // writes under a key of its `contributes` (`contributes` there, as the resources plugin's `panels`): kept as written, for
6
- // the declaring plugin to read, only the commands in it listed where installing confirms them.
5
+ // writes under a key of its `contributes` (`contributes` there, as the resources plugin's `panels`): of the schema the point
6
+ // declares, kept as written, for the declaring plugin to read, only the commands in it listed where installing confirms them.
7
+ import { pointProblem } from '@coda-console/protocol/validate';
7
8
  import { requireCondition as check } from '../../domain/errors.mjs';
8
9
 
9
10
  const code = 'invalid_plugin';
@@ -55,11 +56,17 @@ export function checkCatalog(plugins) {
55
56
  return plugins;
56
57
  }
57
58
  // Why what a plugin writes under the keys of `contributes` not Coda's own cannot be taken here (`plugins`: the catalog
58
- // beside it), or null: no point takes one of them.
59
+ // beside it), or null: no point takes one of them, or what it writes is not of the schema the point declares.
59
60
  export function offerProblem(plugin, plugins) {
60
- const others = new Map([...plugins, [plugin.id, plugin]]);
61
- const unknown = Object.keys(plugin.offers ?? {}).filter(key => !offerPoint(others, key));
62
- return unknown.length ? `contributes 里的 ${unknown.join('、')} 不是 Coda 的类型,也没有插件的扩展点声明它` : null;
61
+ const others = new Map([...plugins, [plugin.id, plugin]]), offers = Object.entries(plugin.offers ?? {});
62
+ const unknown = offers.map(([key]) => key).filter(key => !offerPoint(others, key));
63
+ if (unknown.length) return `contributes 里的 ${unknown.join('、')} 不是 Coda 的类型,也没有插件的扩展点声明它`;
64
+ for (const [key, value] of offers) {
65
+ const { schema } = offerPoint(others, key).declared;
66
+ const problem = schema !== undefined ? pointProblem(schema, value, `contributes.${key}`, plugin.dir) : null;
67
+ if (problem) return problem;
68
+ }
69
+ return null;
63
70
  }
64
71
  // What installing a plugin installs: what it needs, before it, then it.
65
72
  export function withDependencies(catalog, id) {
@@ -146,7 +146,7 @@ export function readPlugin(dir, source) {
146
146
  ...(contributes.composerModes?.length ? { composerModes: composerModes(contributes.composerModes) } : {}),
147
147
  ...(Object.keys(offers).length ? { offers } : {}),
148
148
  agents: agentDeclarations(contributes.agents, dir),
149
- dependencies: [...dependencies], extensionPoints: extensionPoints(contributes.extensionPoints),
149
+ dependencies: [...dependencies], extensionPoints: extensionPoints(contributes.extensionPoints, dir),
150
150
  extensions: Object.entries(contributes.extensions ?? {}).map(([key, value]) => { const [plugin, point] = key.split('/'); return { plugin, point, command: value.command }; }),
151
151
  ...(contributes.instructions ? { instructions: contributes.instructions.trim() } : {}), ...(contributes.setup ? { setup: { command: contributes.setup.command } } : {}),
152
152
  ...(contributes.skills?.length ? { skills: skills(contributes.skills, dir) } : {}),
@@ -160,9 +160,11 @@ export function readPlugin(dir, source) {
160
160
  labels: executorLabels(e.labels, `执行环境 ${e.id} 的 labels`, 'invalid_plugin'), command: e.command })) } : {}),
161
161
  ...(contributes.repositories ? { repositories: { command: contributes.repositories.command } } : {}) };
162
162
  }
163
- // Its extension points (schemas/extension-points.json), each with what it says of itself.
164
- const extensionPoints = (raw = {}) => Object.fromEntries(Object.entries(raw).map(([name, value]) => [name, value.contributes === undefined
165
- ? { description: value.description } : { description: value.description, contributes: value.contributes, title: value.title, commands: { ...(value.commands ?? {}) } }]));
163
+ // Its extension points (schemas/extension-points.json), each with what it says of itself: the schema of what others write for
164
+ // one, read from its file.
165
+ const extensionPoints = (raw = {}, dir) => Object.fromEntries(Object.entries(raw).map(([name, value]) => [name, value.contributes === undefined
166
+ ? { description: value.description } : { description: value.description, contributes: value.contributes, title: value.title, commands: { ...(value.commands ?? {}) },
167
+ ...(value.schema ? { schema: JSON.parse(readFileSync(join(dir, value.schema), 'utf8')) } : {}) }]));
166
168
  // The directories it puts on the PATH of what starts in a project it applies to: one of its own (relative, as a Skill's),
167
169
  // or one in its state on the backend (`${CODA_PLUGIN_STATE}/…`), which its setup may make.
168
170
  function pathEntry(entry) {
@@ -1,15 +1,15 @@
1
1
  {
2
- "commit": "93a0168dc6cb61a169b271da34db1e57d6b5549f",
2
+ "commit": "576291d3c0d5400f7e89db50711aa98f5c4f6447",
3
3
  "packages": {
4
4
  "@0dep/piso": "5.2.0",
5
5
  "@agentclientprotocol/sdk": "1.4.0",
6
- "@coda-console/protocol": "1.0.0",
6
+ "@coda-console/protocol": "1.1.0",
7
7
  "yaml": "2.9.1"
8
8
  },
9
9
  "files": {
10
10
  "check/coda/components/plugins/agent-plugins.mjs": "e4b05f8c5601d812eba278bed21e0fee13ce6760c812162c76f1ab253cdd4e4f",
11
- "check/coda/components/plugins/plugin-extensions.mjs": "a1e8810296fd64d0e7792f1d987bd6ea6f71d1aa5d52a225f4a14eb6681f2758",
12
- "check/coda/components/plugins/plugin-rules.mjs": "3cf99e6aaf688ad496dae00a47768fe118d204cf17f2fed490344bfababc27c9",
11
+ "check/coda/components/plugins/plugin-extensions.mjs": "91badae3de3c5a015d83d425def2593ffcd451576fb5f07309888f09d3157b52",
12
+ "check/coda/components/plugins/plugin-rules.mjs": "f91c2426eb655091c3ac2df5d99efe726de66ec318186f40f657c6edf683ddbe",
13
13
  "check/coda/components/plugins/plugin-source-rules.mjs": "4eedfd024c0824b1fed78be106f1a2827ffc3dd35ac0c69b8b0c61a59af42efd",
14
14
  "check/coda/components/plugins/skill-document.mjs": "c5b5e815c42cd836572f7b60e22a46af6ac607fd9df0170fa36f955825636ce6",
15
15
  "check/coda/components/prompt-recovery/prompt-recovery.mjs": "f43f21d24c19a58113d3304f9248225b12080ab00ed15eab74bf7b94642732de",
@@ -21,9 +21,9 @@
21
21
  "check/coda/domain/values.mjs": "01cc72b8d9c09e3fe16c93ec332ca01148bba859b1c672586d9d07444d7816c4",
22
22
  "check/coda/kernel/agent-failures.mjs": "e435b9a1710b8a7c0ee243f04a556464f50b1a5605fb7bb59af21b78fca1b637",
23
23
  "check/coda/resources/plugins/resources/panels/command.mjs": "606f28bf87f87dded9df2db892bc7624c770d795ffab88f2409998346920ae42",
24
- "check/coda/resources/plugins/resources/panels/panels.mjs": "aee040febb37fd6eebaf1a1da5b3299d2b6a9dfc982e649d9a628291af298179",
25
- "check/coda/resources/plugins/resources/panels/rules.mjs": "c024c5ede7c1516877128aa6d6796fbe5fd0e14642741b0745481bb1c5ca41d3",
24
+ "check/coda/resources/plugins/resources/panels/panels.mjs": "9e25cfbc16ed9f68101fc7bfc34b8056c13a29d2368c5561e65e333233eb921e",
25
+ "check/coda/resources/plugins/resources/panels/rules.mjs": "8418ed83b796f18047c154d8dea8dca7d98244af8ddfe3ddf188520c59324ee8",
26
26
  "check/coda/resources/plugins/resources/panels/sign-in.mjs": "1271a24e33b1b882a1fb9bee03b8e240db8b9bee1b5208f0e1c84499cfb1be7e",
27
- "check/coda/builtin.json": "d1865fad1440a62341188458578cf95e1afc5528229ff8a97c2a727ce7985b67"
27
+ "check/coda/builtin.json": "de593e6240f9c5e4881a7142facc4ed13abdc6921ad3cdba0c4e962a15e277e0"
28
28
  }
29
29
  }
@@ -11,7 +11,7 @@ import { readFileSync, writeFileSync, renameSync } from 'node:fs';
11
11
  import { tmpdir } from 'node:os';
12
12
  import { join } from 'node:path';
13
13
  import { runCommand, ended, outcome } from './command.mjs';
14
- import { PanelError, panelEntries, panelItems, actionArgs, shownItems, displayOptions, keepMissingMetrics } from './rules.mjs';
14
+ import { PanelError, panelDeclarations, panelItems, actionArgs, shownItems, displayOptions, keepMissingMetrics } from './rules.mjs';
15
15
  import { SignIn, authorizationLink, deviceCode } from './sign-in.mjs';
16
16
 
17
17
  const fail = (code, message) => { throw new PanelError(code, message); };
@@ -61,13 +61,10 @@ export class Panels {
61
61
  renameSync(next, this.file);
62
62
  }
63
63
  // The installed plugins' panels, by plugin id, each plugin's in the order it declares them. A project disabling a plugin
64
- // does not take its panels away: the page is the machine's, not a project's. One Coda cannot read is kept with why.
64
+ // does not take its panels away: the page is the machine's, not a project's.
65
65
  installed() {
66
66
  return [...this.plugins.values()].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0).flatMap(plugin =>
67
- panelEntries(plugin.contributes?.panels, plugin.name).map(entry => {
68
- const panel = entry.panel ?? { id: entry.invalid.id, title: entry.invalid.title, actions: {} };
69
- return { plugin, panel, key: `${plugin.id}/${panel.id}`, ...(entry.invalid ? { invalid: entry.invalid.error } : {}) };
70
- }));
67
+ panelDeclarations(plugin.contributes?.panels).map(panel => ({ plugin, panel, key: `${plugin.id}/${panel.id}` })));
71
68
  }
72
69
  find(key) {
73
70
  return this.installed().find(e => e.key === key) ?? fail('not_found', `没有面板 ${key}`);
@@ -85,7 +82,7 @@ export class Panels {
85
82
  configurable: !!panel.displaySetting, signsIn: !!panel.signIn, hidden: this.hidden.has(key), index,
86
83
  signIn: panel.signIn ? this.login(entry).view() : null,
87
84
  reading: shown ? this.present(entry, shown) : null,
88
- busy: this.reading.has(key), failure: entry.invalid ? `声明无效:${entry.invalid}` : this.failures.get(key) ?? null,
85
+ busy: this.reading.has(key), failure: this.failures.get(key) ?? null,
89
86
  acting: this.acting.get(key)?.button ?? null, actionError: this.acting.get(key)?.error ?? null };
90
87
  }
91
88
  list() { return this.installed().map((entry, index) => [entry.key, this.view(entry, index)]); }
@@ -112,7 +109,6 @@ export class Panels {
112
109
  // `{ items, readAt }`, or with `error` when this reading failed: then the last good items with `stale`, or none.
113
110
  read(key, { force = false } = {}) {
114
111
  const entry = this.find(key);
115
- if (entry.invalid) return Promise.resolve({ items: [], error: `声明无效:${entry.invalid}` });
116
112
  const pending = this.reading.get(key);
117
113
  if (pending) return pending;
118
114
  const last = this.last.get(key);
@@ -1,6 +1,7 @@
1
- // What a panel is (docs/plugins.md「面板」): how a plugin declares one (`contributes.panels`) and what its command may
2
- // print, checked here, where the panels are read, the way a task's card is drawn from its fields. Nothing here knows what
3
- // a panel is about: CPU, an account's quota and a disk are all meters and figures.
1
+ // What a panel is (docs/plugins.md「面板」): how a plugin declares one (`contributes.panels`, of the schema the resources
2
+ // plugin declares for its point, schema.json, checked where the plugin is installed) and what its command may print,
3
+ // checked here, where the panels are read, the way a task's card is drawn from its fields. Nothing here knows what a panel
4
+ // is about: CPU, an account's quota and a disk are all meters and figures.
4
5
 
5
6
  // What is not as it must be: the panel says so where it would show.
6
7
  export class PanelError extends Error {
@@ -10,23 +11,18 @@ function check(condition, code, message) {
10
11
  if (!condition) throw new PanelError(code, message);
11
12
  return condition;
12
13
  }
13
- // An ISO 8601 duration as panels write their `maxAge` (`PT5M`, `P1D`): weeks, days and time, not years or months.
14
+ // An ISO 8601 duration as panels write their `maxAge` (`PT5M`, `P1D`), in milliseconds: weeks, days and time.
14
15
  const DURATION = /^P(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
15
- export function isDuration(text) {
16
- const m = typeof text === 'string' && text.length <= 200 && DURATION.exec(text);
17
- return !!m && text !== 'P' && !text.endsWith('T');
18
- }
19
- export function durationMs(text) {
16
+ function durationMs(text) {
20
17
  const [, w = 0, d = 0, h = 0, min = 0, s = 0] = DURATION.exec(text);
21
18
  return ((((+w * 7 + +d) * 24 + +h) * 60 + +min) * 60 + +s) * 1000;
22
19
  }
23
20
 
24
- const NAME = /^[a-z][a-z0-9-]{0,63}$/;
25
21
  export const ITEM_TYPES = ['card', 'meter', 'stat', 'markdown', 'button', 'error'];
26
22
  // What a panel's command may print: past these, the reading fails rather than being cut short.
27
23
  export const OUTPUT_LIMIT = 64 * 1024;
28
24
  export const ARGS_LIMIT = 4 * 1024;
29
- const ITEMS = 50, CARD_ITEMS = 20, TITLE = 40, LABEL = 80, IDENTITY = 200, MARKDOWN = 4000, ERROR = 500, CONFIRM = 200;
25
+ const ITEMS = 50, CARD_ITEMS = 20, LABEL = 80, IDENTITY = 200, MARKDOWN = 4000, ERROR = 500, CONFIRM = 200;
30
26
  const fail = (code, message) => check(false, code, message);
31
27
  const keys = (value, allowed, where, code) => {
32
28
  const extra = Object.keys(value).filter(k => !allowed.includes(k));
@@ -41,73 +37,10 @@ const text = (value, max, where, code, { need = true, line = true } = {}) => {
41
37
  const object = (value, where, code) => check(value && typeof value === 'object' && !Array.isArray(value), code, `${where} 须为对象`);
42
38
 
43
39
  // ---- Declarations (`contributes.panels`) ----
44
- // One panel as the plugin declares it: what it is called, the command that reads it, how long a reading may be shown
45
- // again without asking, the actions its buttons may take, each a command of its own with what to ask first, and how to
46
- // sign in to what it shows from Coda.
47
- function declaration(raw, where) {
48
- const code = 'invalid_plugin';
49
- object(raw, where, code);
50
- keys(raw, ['id', 'title', 'command', 'maxAge', 'actions', 'signIn', 'displaySetting'], where, code);
51
- check(typeof raw.id === 'string' && NAME.test(raw.id), code, `${where} 的 id 只能用小写字母、数字和「-」,以字母开头`);
52
- const at = `面板 ${raw.id}`;
53
- check(raw.maxAge === undefined || (typeof raw.maxAge === 'string' && isDuration(raw.maxAge)), code, `${at} 的 maxAge 须为 ISO 8601 时长,如 PT5M`);
54
- const actions = {};
55
- if (raw.actions !== undefined) {
56
- object(raw.actions, `${at} 的 actions`, code);
57
- for (const [name, action] of Object.entries(raw.actions)) {
58
- check(NAME.test(name), code, `${at} 的动作名只能用小写字母、数字和「-」,以字母开头:${name}`);
59
- object(action, `${at} 的动作 ${name}`, code);
60
- keys(action, ['command', 'confirm'], `${at} 的动作 ${name}`, code);
61
- actions[name] = { command: text(action.command, 4000, `${at} 的动作 ${name} 的 command`, code),
62
- ...(action.confirm !== undefined ? { confirm: text(action.confirm, CONFIRM, `${at} 的动作 ${name} 的 confirm`, code, { line: false }) } : {}) };
63
- }
64
- }
65
- return { id: raw.id, title: text(raw.title, TITLE, `${at} 的 title`, code), command: text(raw.command, 4000, `${at} 的 command`, code),
66
- ...(raw.maxAge !== undefined ? { maxAge: raw.maxAge, maxAgeMs: durationMs(raw.maxAge) } : {}), actions,
67
- ...(raw.displaySetting !== undefined ? { displaySetting: text(raw.displaySetting, LABEL, `${at} 的 displaySetting`, code) } : {}),
68
- ...(raw.signIn !== undefined ? { signIn: signIn(raw.signIn, `${at} 的 signIn`) } : {}) };
69
- }
70
- // Signing in from Coda (adapters/sign-in.mjs): a login command that prints a link to
71
- // confirm on any device (with a code, or asking for the authorization code the page shows, which goes to its standard
72
- // input), and where Coda may install what it needs, a quick check that it is there and the command that installs it.
73
- function signIn(raw, where) {
74
- const code = 'invalid_plugin';
75
- object(raw, where, code);
76
- keys(raw, ['command', 'installed', 'install', 'input', 'note'], where, code);
77
- check(raw.input === undefined || raw.input === 'authorizationCode', code, `${where} 的 input 只能是 authorizationCode`);
78
- check(raw.install === undefined || raw.installed !== undefined, code, `${where}:写了 install 就要写 installed,Coda 才知道装没装好`);
79
- return { command: text(raw.command, 4000, `${where} 的 command`, code),
80
- ...(raw.installed !== undefined ? { installed: text(raw.installed, 4000, `${where} 的 installed`, code) } : {}),
81
- ...(raw.install !== undefined ? { install: text(raw.install, 4000, `${where} 的 install`, code) } : {}),
82
- ...(raw.input ? { input: raw.input } : {}),
83
- ...(raw.note !== undefined ? { note: text(raw.note, CONFIRM, `${where} 的 note`, code, { line: false }) } : {}) };
84
- }
85
- // A plugin's panels as it declares them, each on its own: one Coda cannot read is kept with why, under the id and title it
86
- // wrote (or its place and the plugin's name), for the page to say so where it would show.
87
- export function panelEntries(raw, pluginName) {
88
- if (raw === undefined) return [];
89
- if (!Array.isArray(raw)) return [{ invalid: { id: 'panels', title: pluginName, error: 'contributes.panels 须为数组' } }];
90
- const seen = new Set();
91
- return raw.map((item, i) => {
92
- // An ID is the first one's that writes it, read or not; one whose ID is not one, or another's, goes by its place.
93
- const named = typeof item?.id === 'string' && NAME.test(item.id), again = named && seen.has(item.id);
94
- const id = named && !again ? item.id : `#${i + 1}`;
95
- if (named) seen.add(item.id);
96
- try {
97
- check(!again, 'invalid_plugin', `contributes.panels 里有重复的 id:${item.id}`);
98
- return { panel: declaration(item, `contributes.panels[${i}]`) };
99
- } catch (e) {
100
- if (!(e instanceof PanelError)) throw e;
101
- return { invalid: { id, title: typeof item?.title === 'string' && item.title.trim() ? item.title.slice(0, 40) : pluginName, error: e.message } };
102
- }
103
- });
104
- }
105
- export function panelDeclarations(raw) {
106
- if (raw === undefined) return [];
107
- check(Array.isArray(raw), 'invalid_plugin', 'contributes.panels 须为数组');
108
- const panels = raw.map((p, i) => declaration(p, `contributes.panels[${i}]`));
109
- check(new Set(panels.map(p => p.id)).size === panels.length, 'invalid_plugin', 'contributes.panels 里有重复的 id');
110
- return panels;
40
+ // A plugin's panels as it declares them, in its order, each with the actions its buttons may take (none when it declares
41
+ // none) and, with a `maxAge`, how long a reading may be shown again without asking.
42
+ export function panelDeclarations(raw = []) {
43
+ return raw.map(panel => ({ ...panel, actions: panel.actions ?? {}, ...(panel.maxAge ? { maxAgeMs: durationMs(panel.maxAge) } : {}) }));
111
44
  }
112
45
 
113
46
  // ---- What a panel's command prints ----
@@ -11,7 +11,7 @@ import shipped from './coda/builtin.json' with { type: 'json' };
11
11
  import { manifestProblem } from '@coda-console/protocol/validate';
12
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 { panelEntries } from './coda/resources/plugins/resources/panels/rules.mjs';
14
+ import { panelDeclarations } from './coda/resources/plugins/resources/panels/rules.mjs';
15
15
 
16
16
  // The plugins Coda ships, by ID. Their files are Coda's, not here: none has a directory on this machine.
17
17
  const builtin = new Map(shipped.map(plugin => [plugin.id, { ...plugin, dir: undefined }]));
@@ -107,14 +107,9 @@ export function checkManifest(dir, say) {
107
107
  const found = besideAll(dir, plugin.dependencies);
108
108
  const offered = offerProblem(plugin, new Map([...builtin, ...found]));
109
109
  if (offered) say.fail('manifest.offers', offered);
110
- // Its panels, as the resources plugin reads what is written for its point: one it cannot read shows there as such.
111
- const panels = [];
112
- for (const entry of panelEntries(plugin.offers?.panels, plugin.displayName)) {
113
- if (entry.invalid) { say.fail('manifest.panels', `面板 ${entry.invalid.id}:${entry.invalid.error}(资源页上它只显示「声明无效」)`); continue; }
114
- const { panel } = entry;
115
- panels.push(panel);
116
- say.pass('manifest.panels', `面板 ${panel.id}「${panel.title}」:动作 ${Object.keys(panel.actions).join('、') || '无'}${panel.signIn ? ',可从 Coda 登录' : ''}`);
117
- }
110
+ // Its panels, as the resources plugin reads what is written for its point once that is of the point's schema.
111
+ const panels = offered ? [] : panelDeclarations(plugin.offers?.panels);
112
+ for (const panel of panels) say.pass('manifest.panels', `面板 ${panel.id}「${panel.title}」:动作 ${Object.keys(panel.actions).join('、') || '无'}${panel.signIn ? ',可从 Coda 登录' : ''}`);
118
113
 
119
114
  // What its processes are given (pluginEnv): the plugins it depends on, those beside it here; one Coda ships has its
120
115
  // directory in Coda, not here, even with one of its ID beside it (Coda picks its own), and one found nowhere is not named.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/plugin-check",
3
- "version": "0.5.14",
3
+ "version": "0.5.15",
4
4
  "description": "Coda 插件的契约检查:扮演 Coda 读清单、启动 Agent 讲 ACP 与 _coda/wait、读面板。",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -24,7 +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
+ "@coda-console/protocol": "1.1.0",
28
28
  "ajv": "8.20.0",
29
29
  "yaml": "2.9.1"
30
30
  },