@coda-console/protocol 6.26.0 → 6.28.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/CHANGELOG.md +16 -0
- package/README.md +3 -3
- package/docs/agent-protocol.md +18 -0
- package/docs/protocol.md +7 -1
- package/package.json +1 -1
- package/plugin.d.mts +11 -0
- package/schemas/plugin/agents.json +10 -3
- package/schemas/plugin/optional-protocol-implementations.json +10 -0
- package/schemas/plugin/plugin.json +2 -0
- package/schemas/plugin/reserved-accord-kinds.json +13 -0
- package/schemas/protocol/v1/agent.json +4 -2
- package/stable/manifest.json +10 -1
- package/validate.mjs +41 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 6.28.0 — 2026-11-27
|
|
6
|
+
|
|
7
|
+
- 这是在 6.27.0 之上的次版本。依据 README「版本」一节:Agent 清单的 `modes` 只加可选键并放宽 `auto`、`full`,升次版本;旧清单一律照旧合法(`test/fixtures/stable/` 的 Pi 样本与不写 `modes` 的清单都不变)。`stable/manifest.json` 的 revision 从 3 升到 6(每登记一条加一),新登记 `modes.manual`、`modes.safe[]`、`modes.default` 三条路径。
|
|
8
|
+
- `schemas/plugin/agents.json`:`contributes.agents[].modes` 新增 `manual`(人工审批档的 ACP 模式 ID)、`safe`(只读、规划等安全模式的 ID 数组,不重复,不写同空数组)、`default`(ACP 没报当前模式、`currentModeId` 为空串时,这个 Agent 默认相当于哪一档:`safe`、`manual`、`auto`、`full` 或 `null`);`auto`、`full` 放宽为模式 ID 或 `null`(新增 `$defs/modeIdOrNull`),`null` 表示没有这一档、不可选。
|
|
9
|
+
- `validate.mjs` 的 `contributionProblem` 校验 `agents` 时多查两条:一,同一个模式 ID 不能放进多个档位(`manual`、`auto`、`full` 与 `safe` 之间);二,`engines.coda` ≥ 21 的清单里每个 Agent 须写 `modes`,并显式写齐 `manual`、`auto`、`full`(值可为 `null`),没写 `engines.coda` 或小于 21 的清单不受此限。导出不变。同一模式 ID 不跨档的检查只对 `engines.coda` ≥ 21 或写了新键(`manual`、`safe`、`default`,或 `auto`、`full` 为 `null`)的清单生效;更早且没用新键的清单仍可让 `auto` 与 `full` 用同一个 ID。`contributionProblem` 只对内置的 `agents.json` 加这两条,传别的 schema 照旧只按它校验。
|
|
10
|
+
- `schemas/protocol/v1/agent.json`:`coda/agent@1` 的 `spawn` 输入新增可选 `parentApproval`(`safe`、`manual`、`auto`、`full`);`parentUnattended` 不再必填,改为与 `parentApproval` 至少写一个;两个都传以 `parentApproval` 为准,只传 `parentUnattended`(旧字段,已废弃)时 `true` 当作 `auto`、`false` 当作 `manual`。只传 `parentUnattended` 的旧调用方照旧合法。
|
|
11
|
+
- 文档:`docs/agent-protocol.md` 新增「权限档位」一节,写明四档偏序 `safe < manual < auto < full`、没登记的模式按 `auto` 算、`null` 与 API Level 21 的写齐要求、父会话的定级顺序(当前模式、`modes.default`、保守按 `manual`)和委派省略 `mode` 时的选档规则;`docs/protocol.md` 同步 `spawn` 的 `parentApproval`。
|
|
12
|
+
|
|
13
|
+
## 6.27.0 — 2026-11-24
|
|
14
|
+
|
|
15
|
+
- 这是在 6.26.0 之上的次版本。依据 README「版本」一节:新增可选的清单键升次版本;这两个键暂不进稳定面,`stable/` 不动,旧清单不受影响(没写这两个键的清单照旧合法)。
|
|
16
|
+
- `contributes` 加两个可选键,各有一份 schema:`optionalProtocolImplementations`(`schemas/plugin/optional-protocol-implementations.json`)是可选实现的协议名数组,每项同 `protocolImplementations` 的文本项,不收 `{ kind, commands }`,至多 100 项、不重复;协议本机没有时插件照常运行、这一项不生效。`reservedAccordKinds`(`schemas/plugin/reserved-accord-kinds.json`)是只归本插件的 Accord 签名记录种类数组,每项匹配 `^[a-z0-9-]{1,64}/[a-z0-9-]{1,64}$`(命名空间必带),至多 32 项、不重复;只有本插件能直接发布、撤回、读这些种类。
|
|
17
|
+
- 两条跨键规则,由 `validate.mjs` 的 `manifestProblem` 在整份清单的 schema 通过后用代码查(没有新增 schema 关键字,两个键的 schema 文件单独用时只校验形状):`optionalProtocolImplementations` 的每项不能已在 `protocolImplementations` 里(文本项或对象项的 `kind` 都算);`reservedAccordKinds` 每项的命名空间须等于清单的 `id`(没写 `id` 用 `name`)。报错说明是哪个键、哪一项。`TYPES` 随之多这两个键。
|
|
18
|
+
- `./types`(`plugin.d.mts`)新增导出 `ManifestContributions`,只含这两个可选键;清单的其余键还没有类型。
|
|
19
|
+
- 协议包只校验形状;协议在不在、这一项生不生效、谁被拒绝由 Coda 宿主判定。
|
|
20
|
+
|
|
5
21
|
## 6.26.0 — 2026-11-24
|
|
6
22
|
|
|
7
23
|
- 这是在 6.25.0 之上的次版本。依据 README「版本」一节:流程方言与 Agent 接入协议是内部面,只加可选属性与约定,升次版本;`stable/` 不动,清单 schema 没改。6.25.0 下合法的流程仍合法。
|
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
|
|
4
4
|
|
|
5
|
-
- **插件清单的类型**(`schemas/plugin/`):插件目录 `package.json` 里 `contributes` 的每个键是一种类型,各有一份 JSON Schema(draft 2020-12,`$id` 为 `https://coda.pub/schemas/plugin/v2/<文件>`)。`plugin.json` 是整份清单,只列通用键(`configuration`、`services`、`setup`、`environment`、`path`、`views`、`protocols`、`protocolImplementations`、`records`);`setting.json` 是一项设置的声明。其余键由 Coda 的贡献点登记表声明:Coda 自己的(`agents`、`composerModes`、`modelProviders` 等)的 schema 仍放在这里作公开数据(如 `agents.json`、`composer-modes.json`),由登记它的 provider 引用;`contributes` 里只有 Coda 认得的键。
|
|
6
|
-
- **通用校验器**(`validate.mjs`):用 Ajv 对清单做 schema 校验。JSON Schema 说不了的只用五个通用关键字(`x-unique-by`、`x-max-contains`、`x-ref`、`x-placeholders`、`x-file`,照 Kubernetes 的 `x-kubernetes-*`),每个在哪里写都是同一个意思,写法见文件开头。校验器不随功能变长:类型加字段就是改 schema
|
|
5
|
+
- **插件清单的类型**(`schemas/plugin/`):插件目录 `package.json` 里 `contributes` 的每个键是一种类型,各有一份 JSON Schema(draft 2020-12,`$id` 为 `https://coda.pub/schemas/plugin/v2/<文件>`)。`plugin.json` 是整份清单,只列通用键(`configuration`、`services`、`setup`、`environment`、`path`、`views`、`protocols`、`protocolImplementations`、`optionalProtocolImplementations`、`reservedAccordKinds`、`records`);`setting.json` 是一项设置的声明。其余键由 Coda 的贡献点登记表声明:Coda 自己的(`agents`、`composerModes`、`modelProviders` 等)的 schema 仍放在这里作公开数据(如 `agents.json`、`composer-modes.json`),由登记它的 provider 引用;`contributes` 里只有 Coda 认得的键。
|
|
6
|
+
- **通用校验器**(`validate.mjs`):用 Ajv 对清单做 schema 校验。JSON Schema 说不了的只用五个通用关键字(`x-unique-by`、`x-max-contains`、`x-ref`、`x-placeholders`、`x-file`,照 Kubernetes 的 `x-kubernetes-*`),每个在哪里写都是同一个意思,写法见文件开头。校验器不随功能变长:类型加字段就是改 schema。例外是清单级的两条跨字段约束:`manifestProblem` 在 schema 通过后还会检查,同一协议不能既是必需实现(`protocolImplementations`)又是可选实现(`optionalProtocolImplementations`),保留种类(`reservedAccordKinds`)的命名空间须等于插件 ID;只拿 `plugin.json` 校验,只查形状,这两条不在内。
|
|
7
7
|
- **协议定义与调用**(`schemas/protocol/`、`protocol.mjs`、`docs/protocol.md`):协议是 `命名空间/名字@大版本` + spec/status 的 JSON Schema + 操作;插件在 `contributes.protocols` 里定义自己命名空间下的协议,在 `contributes.protocolImplementations` 里声明实现哪些协议;定义可写 `streams` 声明记录流(读、写、原样 HTTP 三种形状,字节或帧),可写 `events` 声明事件(载荷格式与 `starts`、`ends`;只有事件的协议可以不写 `spec`、`status`、`operations`,`protocolHasRecords` 判断一份定义有没有记录),可写 `permissions` 把操作、流、事件与记录的读取分成权限组,插件在清单根的 `uses`(必需)或 `optionalUses`(可选)里按组申请。调用是 `{ record, operation, input, requestId, parent, awaited }`,回答是 `{ result }` 或 `{ run }`;`coda/run@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1`、`coda/card@1` 是五个核心协议。
|
|
8
8
|
- **流程方言**(`workflow/`):项目和插件的流程(`.coda/workflows/*.bpmn`,BPMN 2.0)在 Coda 的命名空间 `https://coda.pub/schema/bpmn/1.0` 里能写什么。`moddle.json` 是 `coda:` 属性与元素(bpmn-moddle 的描述格式),`values.json` 是每个值能写什么(每个 `coda:` 类型的属性组成的对象的 JSON Schema,一个元素里同种 `coda:` 元素成组的 schema),`actions.json` 是 `coda:action` 的各个动作和它们接受的参数,`dialect.json` 是 Coda 自己发的事件、步骤失败的错误码、表达式能读的运行变量和运行的输入能是哪些类型。`workflow.mjs` 用它们读一份流程:方言里没有的、值不合 schema 的都拒绝,说法是「位置:schema 对那里的说明」。值的 schema 用清单的那几个关键字,另加三个:`x-feel`(是 FEEL:「=」开头是表达式,否则文字里的 `{{ … }}` 是,按这份流程里的名字读得通)、`x-duration`(ISO 8601 时长,不为负)、`x-number`(文字换算成数字是个有限的数)。`structure.json` 声明流程结构规则,`structure.mjs` 负责跨节点检查。
|
|
9
9
|
- **Agent 接入扩展**(`schemas/agent/`、`agent.mjs`、`docs/agent-protocol.md`):Coda 怎样用 ACP 接 Agent,以及 Coda 加的扩展(会话指令、插话、`_coda/wait`、执行失败、工具调用的审核、配置探测)。
|
|
@@ -170,7 +170,7 @@ agentValueProblem('review.json', review, '工具的审核');
|
|
|
170
170
|
## 协议定义与核心协议
|
|
171
171
|
|
|
172
172
|
从 3.0.0 起,协议是 `命名空间/名字@大版本` + 记录格式(spec、status 的 JSON Schema)+ 操作,见[协议正文](docs/protocol.md)。
|
|
173
|
-
插件用 `contributes.protocols` 定义自己命名空间下的协议,用 `contributes.protocolImplementations` 声明实现哪些协议,用根上的 `uses` 申请别的协议的权限组(必需),用 `optionalUses` 声明可选用到的权限组(对应协议或提供方缺席时不阻止插件运行,可用性判定与鉴权由 Coda
|
|
173
|
+
插件用 `contributes.protocols` 定义自己命名空间下的协议,用 `contributes.protocolImplementations` 声明实现哪些协议,用根上的 `uses` 申请别的协议的权限组(必需),用 `optionalUses` 声明可选用到的权限组(对应协议或提供方缺席时不阻止插件运行,可用性判定与鉴权由 Coda 宿主负责);`contributes.optionalProtocolImplementations` 列可选实现的协议(本机没有这个协议时插件照常运行、这一项不生效),`contributes.reservedAccordKinds` 声明只归本插件的 Accord 签名记录种类(命名空间须是插件 ID);这两个键协议包只校验形状与两条跨键规则(可选实现不与 `protocolImplementations` 重复、保留种类的命名空间等于插件 ID),协议在不在、谁被拒绝由 Coda 宿主判定;
|
|
174
174
|
命名空间 `coda` 保留给核心协议。
|
|
175
175
|
|
|
176
176
|
- **`coda/run@1`**:被调用方自己的运行记录。spec 记录调用的记录、操作、输入、请求 ID、父引用和是否被等待;status 是 `working`、`input-required`、`completed`、`failed`、`canceled`,后三个是终态。`completed`/`failed` 必带 `result`,`failed` 的 `result` 约定为 `{ code, message }`(`code: "unknown"` 表示结局不明),`canceled` 可带取消前的话和留下的东西;另有可选的 `progress` 和等输入时的 `awaiting`。操作是 `cancel`。
|
package/docs/agent-protocol.md
CHANGED
|
@@ -106,6 +106,24 @@ ACP 只允许在一轮(`session/prompt`)进行时交互。Agent 在两轮之
|
|
|
106
106
|
Coda 记下每个 Agent 最近一次握手报的值,随后端遥测上报(Coda 遥测服务(Coda 的 docs/../telemetry/README.md「后端上报」)),用于复盘 Agent 版本带来的兼容问题;
|
|
107
107
|
只取版本号式的字符(字母、数字与 `.+()-_` 空格,至多 64 个),其他写法不记。不报不影响会话。
|
|
108
108
|
|
|
109
|
+
## 权限档位
|
|
110
|
+
|
|
111
|
+
Agent 的审批模式(ACP 的 mode)按权限高低归到四档,偏序是 `safe < manual < auto < full`。Agent 插件在清单 `contributes.agents[].modes`([agents.json](../schemas/plugin/agents.json))里登记:
|
|
112
|
+
|
|
113
|
+
| 键 | 含义 |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| `manual` | 人工审批档的 ACP 模式 ID |
|
|
116
|
+
| `auto` | 自动审批档的 ACP 模式 ID |
|
|
117
|
+
| `full` | 完全放行档的 ACP 模式 ID |
|
|
118
|
+
| `safe` | 只读、规划等安全模式的 ACP 模式 ID 列表(如 `plan`、`ask`、`dontAsk`),不写同空列表,不重复 |
|
|
119
|
+
| `default` | ACP 没报当前模式(`currentModeId` 为空串)时,这个 Agent 默认相当于哪一档:`safe`、`manual`、`auto`、`full` 或 `null` |
|
|
120
|
+
|
|
121
|
+
- `manual`、`auto`、`full` 都可以写 `null`(或不写),表示 Agent 没有这一档、不可选。API Level 21 起(`engines.coda` ≥ 21)Agent 插件须写 `modes` 并显式写齐这三个键,没有的一档写 `null`;更早的清单不受此限。
|
|
122
|
+
- 同一个模式 ID 只能属于一档:`manual`、`auto`、`full` 与 `safe` 里的 ID 两两不能相同。这条对 API Level ≥ 21 的清单,或写了新版档位特性(`manual`、`safe`、`default`,或 `auto`/`full` 为 `null`)的清单检查;只用旧版 `auto`/`full` 字符串的旧清单按稳定面保持兼容,不查。没登记在这四处的其余模式 ID 按 `auto` 算。
|
|
123
|
+
- **父会话的档位**:委派时先定父会话的档位。优先取运行中 ACP 实际报告的当前模式;它为空就读 `modes.default`;仍为空则保守按 `manual`。
|
|
124
|
+
- **委派选档**:委派(`spawn`、`new_session` 等)省略 `mode` 时,向下取不高于父会话档位的最高已登记档位:`full` 父依次试 `full`、`auto`、`manual`;`auto` 父试 `auto`、`manual`;`manual` 父只试 `manual`;`safe` 父取 `safe` 列表的第一个,不会自动落到 `safe`(从更高档往下止步于 `manual`)。没有可用档位时拒绝派出。
|
|
125
|
+
- 首轮 `session/prompt` 之前设档(`session/set_mode`)失败,拒绝启动这个会话,不带着未知档位开跑。
|
|
126
|
+
|
|
109
127
|
## 配置探测
|
|
110
128
|
|
|
111
129
|
Coda 读 Agent 的模型与模式目录时,不必建一个真实的原生会话:对声明了该能力的 Agent,改请它开一个只在当前连接里有效的虚拟会话。
|
package/docs/protocol.md
CHANGED
|
@@ -358,6 +358,12 @@ const body = writeFrames(frames, { heartbeatMs: 15000 });
|
|
|
358
358
|
|
|
359
359
|
同一个协议在数组里只能出现一次,写成文本还是对象都算。
|
|
360
360
|
|
|
361
|
+
`contributes.optionalProtocolImplementations` 是插件可选实现的协议列表:协议名的数组,至多 100 项、不重复,只收文本,不收 `{ kind, commands }`。这些协议本机没有时,插件照常运行,只是这一项不生效;同一个协议不能既写在这里又写在 `protocolImplementations` 里(文本项、对象项的 `kind` 都算)。
|
|
362
|
+
|
|
363
|
+
`contributes.reservedAccordKinds` 声明哪几种 Accord 签名记录(AIP-01)的种类只归本插件:「命名空间/名字」的数组,至多 32 项、不重复,每项须匹配 `^[a-z0-9-]{1,64}/[a-z0-9-]{1,64}$`(比 Accord 的种类规则少了可选的命名空间:必须带),命名空间须等于插件 ID(没写 `id` 时用 `name`)。只有本插件能直接发布、撤回、读这些种类。
|
|
364
|
+
|
|
365
|
+
这两个键协议包只校验形状与上面两条跨键规则;协议在不在、这一项生不生效、谁被拒绝由 Coda 宿主判定。
|
|
366
|
+
|
|
361
367
|
`contributes.records` 声明哪些种类的记录由命令给出,每种一项,至多 20 项:
|
|
362
368
|
|
|
363
369
|
```json
|
|
@@ -463,7 +469,7 @@ status:
|
|
|
463
469
|
|
|
464
470
|
`models[].efforts` 是 `[{ id, name?, shortName? }]`;`models[].options` 是 `{ id, name?, shortName?, type: "boolean"|"select", choices? }`,`select` 带 `choices`,`boolean` 不带。status 是空对象。
|
|
465
471
|
|
|
466
|
-
操作 `spawn`(`run: true`):在这台机器上用这个 Agent 开一个子会话,返回运行引用。输入是 `{ projectId, threadId, title, text, settings?, checkout?, parentTitle, parentUnattended }`:子会话所在的项目与工作树(`checkout`)、Agent 的设置(`settings`,如模型与推理强度)、标题与第一条任务(`text`);`threadId` 是调用方给的子会话 ID,重试找到的是同一个;`parentTitle` 是发起方在这里显示的名字,`parentUnattended`
|
|
472
|
+
操作 `spawn`(`run: true`):在这台机器上用这个 Agent 开一个子会话,返回运行引用。输入是 `{ projectId, threadId, title, text, settings?, checkout?, parentTitle, parentUnattended?, parentApproval? }`:子会话所在的项目与工作树(`checkout`)、Agent 的设置(`settings`,如模型与推理强度)、标题与第一条任务(`text`);`threadId` 是调用方给的子会话 ID,重试找到的是同一个;`parentTitle` 是发起方在这里显示的名字,`parentUnattended`(旧字段,已废弃)说发起方是否无人值守;`parentApproval`(`safe`、`manual`、`auto`、`full`)说发起方的权限档位,省略 `settings` 里的模式时,子会话据此选不高于它的最高档(规则见 [Agent 接入协议](agent-protocol.md#权限档位))。两个至少写一个。同时传 `parentApproval` 与 `parentUnattended` 时以 `parentApproval` 为准;只传 `parentUnattended` 时,`true` 当作 `auto`,`false` 当作 `manual`,旧调用方照旧可用。子会话为谁工作由调用信封的 `parent` 说,不写在输入里;`parent` 不是会话、是登记过的调用方记录时,开的是顶层会话,不是子会话。
|
|
467
473
|
|
|
468
474
|
```json
|
|
469
475
|
{
|
package/package.json
CHANGED
package/plugin.d.mts
CHANGED
|
@@ -423,3 +423,14 @@ export interface ViewInstance {
|
|
|
423
423
|
onContext(fn: (context: ViewInstance['context']) => void): Disposable;
|
|
424
424
|
onClose(fn: () => void): Disposable;
|
|
425
425
|
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The keys of the manifest's `contributes` that are typed here: only these two so far, the rest of the manifest has no type
|
|
429
|
+
* here yet. Their shape is checked by `schemas/plugin/`; whether a protocol is on this machine and who is refused is the host's.
|
|
430
|
+
*/
|
|
431
|
+
export interface ManifestContributions {
|
|
432
|
+
/** Protocols the plugin implements if they are on this machine (`namespace/name@major`); with one absent the plugin still runs, only that implementation does not take effect. */
|
|
433
|
+
optionalProtocolImplementations?: string[];
|
|
434
|
+
/** Accord signature record kinds (`namespace/name`, the namespace the plugin's own ID) that only this plugin may publish, revoke or read. */
|
|
435
|
+
reservedAccordKinds?: string[];
|
|
436
|
+
}
|
|
@@ -18,14 +18,17 @@
|
|
|
18
18
|
},
|
|
19
19
|
"command": {"$ref": "common.json#/$defs/command"},
|
|
20
20
|
"modes": {
|
|
21
|
-
"description": "审批档位的说法:title 不超过 10 字,unset 不超过 20 字,note 不超过 100
|
|
21
|
+
"description": "审批档位的说法:title 不超过 10 字,unset 不超过 20 字,note 不超过 100 字。manual、auto、full 各是该档对应的 ACP 模式 ID(不超过 200 字),写 null 表示 Agent 没有这一档、不可选;API Level 21 起(engines.coda ≥ 21)三个键须写齐,更早的清单可以不写。safe 是只读、规划等安全模式的 ACP 模式 ID 列表,不写同空列表。档位从低到高是 safe < manual < auto < full,同一个模式 ID 只能放在一档里(API Level ≥ 21,或写了 manual、safe、default、null 的 auto/full 等新版特性的清单才检查;只用旧版 auto、full 字符串的旧清单保持兼容);没登记在这四处的其余模式按 auto 算。default 是 ACP 没报当前模式(currentModeId 为空串)时这个 Agent 默认相当于哪一档,null 或不写表示不知道",
|
|
22
22
|
"type": "object",
|
|
23
23
|
"properties": {
|
|
24
24
|
"title": {"$ref": "common.json#/$defs/line10"},
|
|
25
25
|
"unset": {"$ref": "common.json#/$defs/line20"},
|
|
26
26
|
"note": {"$ref": "common.json#/$defs/line100"},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"manual": {"$ref": "#/$defs/modeIdOrNull"},
|
|
28
|
+
"auto": {"$ref": "#/$defs/modeIdOrNull"},
|
|
29
|
+
"full": {"$ref": "#/$defs/modeIdOrNull"},
|
|
30
|
+
"safe": {"type": "array", "items": {"$ref": "common.json#/$defs/line200"}, "uniqueItems": true},
|
|
31
|
+
"default": {"enum": ["safe", "manual", "auto", "full", null]}
|
|
29
32
|
},
|
|
30
33
|
"additionalProperties": false
|
|
31
34
|
},
|
|
@@ -41,6 +44,10 @@
|
|
|
41
44
|
},
|
|
42
45
|
"x-unique-by": ["id"],
|
|
43
46
|
"$defs": {
|
|
47
|
+
"modeIdOrNull": {
|
|
48
|
+
"description": "一档对应的 ACP 模式 ID,null 表示没有这一档",
|
|
49
|
+
"anyOf": [{"$ref": "common.json#/$defs/line200"}, {"type": "null"}]
|
|
50
|
+
},
|
|
44
51
|
"icon": {
|
|
45
52
|
"description": "插件目录里的 PDF,不超过 32 KiB",
|
|
46
53
|
"allOf": [{"$ref": "common.json#/$defs/line1000"}],
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://coda.pub/schemas/plugin/v2/optional-protocol-implementations.json",
|
|
4
|
+
"title": "contributes.optionalProtocolImplementations:插件可选实现的协议",
|
|
5
|
+
"description": "插件可选实现哪些协议,写协议名「命名空间/名字@大版本」的数组,至多 100 项,不重复,只收文本、不收 { kind, commands }。这些协议本机没有时,插件照常运行,只是这一项不生效;协议在不在、这一项生不生效由 Coda 宿主判定,这里只管清单形状。同一个协议不能同时写在 protocolImplementations 里,这条跨键规则由整份清单的校验(manifestProblem)查。",
|
|
6
|
+
"type": "array",
|
|
7
|
+
"maxItems": 100,
|
|
8
|
+
"uniqueItems": true,
|
|
9
|
+
"items": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/name"}
|
|
10
|
+
}
|
|
@@ -73,6 +73,8 @@
|
|
|
73
73
|
"views": {"$ref": "views.json"},
|
|
74
74
|
"protocols": {"$ref": "protocols.json"},
|
|
75
75
|
"protocolImplementations": {"$ref": "protocol-implementations.json"},
|
|
76
|
+
"optionalProtocolImplementations": {"$ref": "optional-protocol-implementations.json"},
|
|
77
|
+
"reservedAccordKinds": {"$ref": "reserved-accord-kinds.json"},
|
|
76
78
|
"records": {"$ref": "records.json"}
|
|
77
79
|
},
|
|
78
80
|
"propertyNames": {"description": "contributes 的键:字母和数字,以小写字母开头", "pattern": "^[a-z][A-Za-z0-9]{0,39}$"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://coda.pub/schemas/plugin/v2/reserved-accord-kinds.json",
|
|
4
|
+
"title": "contributes.reservedAccordKinds:只归本插件的 Accord 签名记录种类",
|
|
5
|
+
"description": "插件声明哪几种 Accord 签名记录(AIP-01)的种类只归自己,写「命名空间/名字」的数组,至多 32 项,不重复;命名空间必须带,名字与命名空间都是小写字母、数字和「-」,各至多 64 个字符。只有本插件能直接发布、撤回、读这些种类;谁被拒绝由 Coda 宿主判定,这里只管清单形状。命名空间须是本插件的 ID,这条跨键规则由整份清单的校验(manifestProblem)查。",
|
|
6
|
+
"type": "array",
|
|
7
|
+
"maxItems": 32,
|
|
8
|
+
"uniqueItems": true,
|
|
9
|
+
"items": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"pattern": "^[a-z0-9-]{1,64}/[a-z0-9-]{1,64}$"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -81,9 +81,11 @@
|
|
|
81
81
|
"settings": {"type": "object", "additionalProperties": true},
|
|
82
82
|
"checkout": {"type": "object", "additionalProperties": true},
|
|
83
83
|
"parentTitle": {"type": "string"},
|
|
84
|
-
"parentUnattended": {"type": "boolean"}
|
|
84
|
+
"parentUnattended": {"type": "boolean"},
|
|
85
|
+
"parentApproval": {"enum": ["safe", "manual", "auto", "full"]}
|
|
85
86
|
},
|
|
86
|
-
"required": ["projectId", "threadId", "title", "text", "parentTitle"
|
|
87
|
+
"required": ["projectId", "threadId", "title", "text", "parentTitle"],
|
|
88
|
+
"anyOf": [{"required": ["parentUnattended"]}, {"required": ["parentApproval"]}],
|
|
87
89
|
"additionalProperties": false
|
|
88
90
|
}
|
|
89
91
|
}
|
package/stable/manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"revision":
|
|
2
|
+
"revision": 6,
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
5
|
"path": "name"
|
|
@@ -70,6 +70,15 @@
|
|
|
70
70
|
{
|
|
71
71
|
"path": "contributes.agents[].modes.full"
|
|
72
72
|
},
|
|
73
|
+
{
|
|
74
|
+
"path": "contributes.agents[].modes.manual"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"path": "contributes.agents[].modes.safe[]"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"path": "contributes.agents[].modes.default"
|
|
81
|
+
},
|
|
73
82
|
{
|
|
74
83
|
"path": "contributes.agents[].icon.dark"
|
|
75
84
|
},
|
package/validate.mjs
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
// JSON Schema of its own. The manifest's schema names only the general ones (schemas/plugin/,
|
|
3
3
|
// `https://coda.pub/schemas/plugin/v2/…`); every other key is one Coda's registry of contribution points declares, with a
|
|
4
4
|
// schema of its provider's (those of Coda's own still kept here, by file). Checking one is checking it against those
|
|
5
|
-
// schemas, nothing else: a field joins a type by joining its schema, never by a rule here
|
|
5
|
+
// schemas, nothing else: a field joins a type by joining its schema, never by a rule here, but for two
|
|
6
|
+
// rules across a manifest's keys: after the schema, `manifestProblem` checks that a protocol is not both implemented and optionally
|
|
7
|
+
// implemented, and that a reserved Accord kind is in the plugin's own namespace, its ID; checked against plugin.json alone, a
|
|
8
|
+
// manifest is checked for its shape only. Coda checks a plugin with this
|
|
6
9
|
// module when it reads one, and coda-plugins' contract check does where a plugin is written.
|
|
7
10
|
// What JSON Schema cannot say of one value alone it says with five keywords, each meaning one thing wherever it is written,
|
|
8
11
|
// as Kubernetes extends its OpenAPI with `x-kubernetes-*`:
|
|
@@ -311,7 +314,20 @@ export function explain(errors, base = '', schemas = [], { style = 'keyword', re
|
|
|
311
314
|
// A manifest checked against its schema, the files it names in `dir` when given. Returns null, or what is wrong.
|
|
312
315
|
export function manifestProblem(manifest, dir = null) {
|
|
313
316
|
const validate = validator('plugin.json');
|
|
314
|
-
return validate.call({ dir }, manifest) ?
|
|
317
|
+
return validate.call({ dir }, manifest) ? crossKeyProblem(manifest) : explain(validate.errors, '', [PROTOCOL_DEFINITION]);
|
|
318
|
+
}
|
|
319
|
+
// What the manifest's schema cannot say of one key alone, as its keys stand to each other; the shapes are right by now.
|
|
320
|
+
// An optional implementation is none that is implemented already (a text, or the `kind` of an object); a reserved Accord kind
|
|
321
|
+
// is in the plugin's own namespace, the plugin's `id` (its `name` when it has none).
|
|
322
|
+
function crossKeyProblem({ id, name, contributes }) {
|
|
323
|
+
const { protocolImplementations = [], optionalProtocolImplementations = [], reservedAccordKinds = [] } = contributes ?? {};
|
|
324
|
+
const implemented = new Set(protocolImplementations.map(item => typeof item === 'string' ? item : item.kind));
|
|
325
|
+
const twice = optionalProtocolImplementations.findIndex(kind => implemented.has(kind));
|
|
326
|
+
if (twice !== -1) return `contributes.optionalProtocolImplementations[${twice}]:已写在 protocolImplementations 里,不能再写:${optionalProtocolImplementations[twice]}`;
|
|
327
|
+
const owner = id ?? name;
|
|
328
|
+
const other = reservedAccordKinds.findIndex(kind => kind.split('/')[0] !== owner);
|
|
329
|
+
if (other === -1) return null;
|
|
330
|
+
return `contributes.reservedAccordKinds[${other}]:${owner === undefined ? '须先写插件的 id 或 name' : `命名空间须是本插件的 ID「${owner}」`}:${reservedAccordKinds[other]}`;
|
|
315
331
|
}
|
|
316
332
|
// A value checked against one of the schemas (`ref`: a file, with a fragment, as `composer-modes.json#/$defs/parameters`),
|
|
317
333
|
// as a plugin gives it while it runs: null, or what is wrong, at `where`.
|
|
@@ -333,7 +349,29 @@ export function pointProblem(schema, value, where, dir = null) {
|
|
|
333
349
|
export function contributionProblem(schema, manifest, key, dir = null) {
|
|
334
350
|
const point = declared(schema);
|
|
335
351
|
return point.validate.call({ dir }, manifest.contributes[key], { instancePath: `/contributes/${escape(key)}`, parentData: manifest.contributes,
|
|
336
|
-
parentDataProperty: key, rootData: manifest, dynamicAnchors: {} }) ? null : explain(point.validate.errors, '', [point.schema]);
|
|
352
|
+
parentDataProperty: key, rootData: manifest, dynamicAnchors: {} }) ? (key === 'agents' && (schema === SCHEMAS['agents.json'] || schema?.$id === SCHEMAS['agents.json'].$id) && Array.isArray(manifest.contributes?.agents) ? agentsProblem(manifest) : null) : explain(point.validate.errors, '', [point.schema]);
|
|
353
|
+
}
|
|
354
|
+
// What the agents schema cannot say of its values as they stand to each other, the shapes being right by now: from API Level 21
|
|
355
|
+
// (`engines.coda`) an agent writes `modes` with `manual`, `auto` and `full` all there, each an ID or null; and a mode ID sits in
|
|
356
|
+
// one tier only (`manual`, `auto`, `full`, or the list `safe`) — for a manifest of API Level 21 or one that writes a newer
|
|
357
|
+
// `modes` key (`manual`, `safe`, `default`, or a null `auto` or `full`); an older one may still give `auto` and `full` one ID.
|
|
358
|
+
function agentsProblem({ engines, contributes }) {
|
|
359
|
+
const strict = engines?.coda >= 21;
|
|
360
|
+
for (const [i, { modes }] of contributes.agents.entries()) {
|
|
361
|
+
const at = `contributes.agents[${i}]`;
|
|
362
|
+
if (modes === undefined) { if (strict) return `${at} 缺 modes:engines.coda 为 21 起,Agent 须写 modes,并写齐 manual、auto、full`; continue; }
|
|
363
|
+
const missing = ['manual', 'auto', 'full'].find(tier => !Object.hasOwn(modes, tier));
|
|
364
|
+
if (strict && missing) return `${at}.modes 缺 ${missing}:engines.coda 为 21 起须写齐 manual、auto、full,没有这一档就写 null`;
|
|
365
|
+
const newer = ['manual', 'safe', 'default'].some(key => Object.hasOwn(modes, key)) || modes.auto === null || modes.full === null;
|
|
366
|
+
if (!strict && !newer) continue;
|
|
367
|
+
const tiers = new Map();
|
|
368
|
+
for (const [tier, id] of [['manual', modes.manual], ['auto', modes.auto], ['full', modes.full], ...(modes.safe ?? []).map(id => ['safe', id])]) {
|
|
369
|
+
if (id === null || id === undefined) continue;
|
|
370
|
+
if (tiers.has(id)) return `${at}.modes:模式 ID「${id}」不能同时放在 ${tiers.get(id)} 和 ${tier},一个模式只属于一档`;
|
|
371
|
+
tiers.set(id, tier);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
337
375
|
}
|
|
338
376
|
|
|
339
377
|
// The serialized size of a value in UTF-8 bytes, `{ ok: true, bytes }`, or why it has none, `{ ok: false, error }`: what
|