@coda-console/protocol 6.7.0 → 6.8.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 CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 6.8.0 — 2026-11-17
6
+
7
+ - 这是在 6.7.0 之上的次版本。依据 README「版本」一节:清单的通用键放宽写法、旧写法照旧通过,升次版本(Coda 宿主设计 coda#2749 第 4、5 节与 6.7 节)。
8
+ - `contributes.protocolImplementations` 的每一项除了协议名(文本,这个协议的全部操作由模块实现),也可以是对象 `{ kind, commands }`:`kind` 是协议名;`commands` 至少一项,键是操作名(只按定义里 `operations` 键名的格式校验,在不在定义里由 Coda 装载时查),值是插件目录里的文件(`x-file`);没列在 `commands` 里的操作由模块实现;不允许别的键。上限仍是 100 项。
9
+ - 同一个协议在数组里只能出现一次,文本加对象、两个对象也算重复(原来的 `uniqueItems` 管不到混写)。为此 `x-unique-by` 加写法 `{ key, text: true }`:文本项按它自己的值、对象项按 `key` 属性的值一并查重;`docs/protocol.md` 同步写清两种写法。已有的纯文本写法不受影响。
10
+ - `contributes.commands` 的保留名单改了:宿主 H5 在同一次交付里把 `coda-run`、`coda-event`、`coda-resources` 并成一个 `coda`、删掉旧名(coda#2749 6.7 节第 3 条)。现在插件的命令不能叫 `coda`;`coda-run`、`coda-event`、`coda-resources` 不再保留,可以用。`schemas/plugin/commands.json` 的 `name` 描述同步。
11
+ - 版本判断:不升主版本,升到 6.8.0。`contributes.commands[].name` 虽在稳定面,但稳定面条目没有登记取值(`values`),承诺的只是「这个键存在、可写命令名」;保留名是 Coda 自己占用的命令名,插件写 `coda` 会盖掉宿主工具,本就不是被承诺的用法。三个旧名放开是放宽,只多接受;新增的 `coda` 只会拒掉一个从未被承诺、也没有已知插件在用的名字(样本里没有),三道检查都不受影响。
12
+
5
13
  ## 6.7.0 — 2026-11-17
6
14
 
7
15
  - 这是在 6.6.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,新增可选字段升次版本,先例见 6.4.0(`deadline`)。
package/docs/protocol.md CHANGED
@@ -187,7 +187,19 @@ invocationResponseProblem(response); // 恰好有 result 或 run 之一
187
187
  }
188
188
  ```
189
189
 
190
- `contributes.protocols` 是插件拥有的定义,每份都按定义文档 schema 校验;定义里的命名空间必须等于插件 ID。`contributes.protocolImplementations` 是插件实现的协议名列表,可以包含别的命名空间下的协议(包括 `coda/...`),不重复。
190
+ `contributes.protocols` 是插件拥有的定义,每份都按定义文档 schema 校验;定义里的命名空间必须等于插件 ID。`contributes.protocolImplementations` 是插件实现的协议列表,可以包含别的命名空间下的协议(包括 `coda/...`),最多 100 项。每项有两种写法:
191
+
192
+ ```json
193
+ "protocolImplementations": [
194
+ "my-plugin/task@1",
195
+ {"kind": "coda/run@1", "commands": {"cancel": "bin/cancel.sh"}}
196
+ ]
197
+ ```
198
+
199
+ - 协议名(文本):这个协议的全部操作都由模块实现。
200
+ - `{ "kind": "<协议名>", "commands": { "<操作名>": "<文件>" } }`:`commands` 至少一项,键是操作名(格式同定义里 `operations` 的键,这个操作在不在协议定义里由 Coda 装载时查),值是插件目录里的文件(相对路径,不离开插件目录)。`commands` 里列出的操作由这个文件实现,**没列在 `commands` 里的操作由模块实现**。对象里不能有 `kind`、`commands` 之外的键。命令怎么写、怎么跑由 Coda 的文档讲,这里不重述。
201
+
202
+ 同一个协议在数组里只能出现一次,写成文本还是对象都算。
191
203
 
192
204
  `manifestProblem` 校验清单的外壳与通用键(这两个键在其中);别的键由 Coda 的贡献点登记表或某个插件的扩展点声明,按声明方的 schema 校验,本包不管它们的形状。命名空间约束需要插件 ID,单独用:
193
205
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "6.7.0",
3
+ "version": "6.8.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,9 +8,9 @@
8
8
  "type": "object",
9
9
  "properties": {
10
10
  "name": {
11
- "description": "命令名:小写字母、数字和「-」,以字母开头,不能是 Coda 自己的 coda-run、coda-event、coda-resources",
11
+ "description": "命令名:小写字母、数字和「-」,以字母开头,不能是 Coda 自己的 coda",
12
12
  "$ref": "common.json#/$defs/id",
13
- "not": {"enum": ["coda-run", "coda-event", "coda-resources"]}
13
+ "not": {"const": "coda"}
14
14
  },
15
15
  "command": {"$ref": "common.json#/$defs/command"}
16
16
  },
@@ -2,9 +2,28 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://coda.pub/schemas/plugin/v2/protocol-implementations.json",
4
4
  "title": "contributes.protocolImplementations:插件实现的协议",
5
- "description": "插件实现哪些协议,写协议名「命名空间/名字@大版本」,不重复。可以实现在别的命名空间下定义的协议。",
5
+ "description": "插件实现哪些协议,写协议名「命名空间/名字@大版本」。可以实现在别的命名空间下定义的协议。每项是文本(这个协议的全部操作由模块实现),或 { kind, commands }(commands 里列出的操作由插件目录里的命令实现,没列的由模块实现)。同一个协议只能出现一次,不论写成文本还是对象。",
6
6
  "type": "array",
7
7
  "maxItems": 100,
8
- "uniqueItems": true,
9
- "items": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/name"}
8
+ "x-unique-by": [{"key": "kind", "text": true}],
9
+ "items": {
10
+ "if": {"type": "string"},
11
+ "then": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/name"},
12
+ "else": {
13
+ "description": "不是协议名时须为 { kind, commands },按命令实现这个协议的部分操作:kind 是协议名,commands 的键是操作名,值是插件目录里的文件",
14
+ "type": "object",
15
+ "properties": {
16
+ "kind": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/name"},
17
+ "commands": {
18
+ "description": "操作名 → 插件目录里的文件(相对路径,不离开插件目录),至少一项;操作是否在协议定义里由 Coda 装载时查",
19
+ "type": "object",
20
+ "minProperties": 1,
21
+ "propertyNames": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/operationName"},
22
+ "additionalProperties": {"type": "string", "x-file": {"type": "file"}}
23
+ }
24
+ },
25
+ "required": ["kind", "commands"],
26
+ "additionalProperties": false
27
+ }
28
+ }
10
29
  }
package/validate.mjs CHANGED
@@ -10,7 +10,8 @@
10
10
  // as Kubernetes extends its OpenAPI with `x-kubernetes-*`:
11
11
  // - `x-unique-by`: [name, { part } or { key, nested }] — in an array, each named property of its objects is unique among the
12
12
  // items having it, and so is `part`'s first group of each of its texts (a directory's last name), and `key` among the
13
- // items and those in their `nested` arrays, at every depth (a task's answers and those offered on holding one);
13
+ // items and those in their `nested` arrays, at every depth (a task's answers and those offered on holding one), and with
14
+ // `text: true` a text item counts as the value of `key` itself (an item written as a name or as an object with it);
14
15
  // - `x-max-contains`: { match, max } — of an object's values, at most `max` satisfy `match` (`maxContains` of an object);
15
16
  // - `x-ref`: { pointer, part?, key?, split?, match? } — the value (or `part`'s first group of it), or each nonempty token
16
17
  // separated by `split`, names a key of the object, or an element (with `key`, that property of an element)
@@ -60,7 +61,8 @@ const META = {
60
61
  'x-max-contains': { type: 'object', properties: { match: SCHEMA_VALUE, max: { type: 'integer', minimum: 0 } }, required: ['match', 'max'], additionalProperties: false },
61
62
  'x-unique-by': { type: 'array', minItems: 1, items: { anyOf: [{ type: 'string' },
62
63
  { type: 'object', properties: { part: { type: 'string' } }, required: ['part'], additionalProperties: false },
63
- { type: 'object', properties: { key: { type: 'string' }, nested: { type: 'string' } }, required: ['key', 'nested'], additionalProperties: false }] } },
64
+ { type: 'object', properties: { key: { type: 'string' }, nested: { type: 'string' } }, required: ['key', 'nested'], additionalProperties: false },
65
+ { type: 'object', properties: { key: { type: 'string' }, text: { const: true } }, required: ['key', 'text'], additionalProperties: false }] } },
64
66
  'x-ref': { type: 'object', properties: { pointer: { type: 'string', pattern: '^(?:\\d+(?:/.*)?|/.*)$' }, part: { type: 'string' }, key: { type: 'string' }, split: { type: 'string' }, match: SCHEMA_VALUE },
65
67
  required: ['pointer'], additionalProperties: false },
66
68
  'x-placeholders': { type: 'object', properties: { names: { type: 'array', items: { type: 'string' } }, config: SCHEMA_VALUE }, additionalProperties: false },
@@ -111,14 +113,15 @@ function keywords(ajv) {
111
113
  return found;
112
114
  };
113
115
  return function unique(items) {
114
- for (const { key, part, nested } of by) {
116
+ for (const { key, part, nested, text } of by) {
115
117
  const seen = new Set();
116
118
  for (const item of every(items, nested)) {
117
119
  const value = part ? (typeof item === 'string' ? part.exec(item)?.[1] : undefined)
120
+ : text && typeof item === 'string' ? item
118
121
  : item && typeof item === 'object' && Object.hasOwn(item, key) ? item[key] : undefined;
119
122
  if (value === undefined) continue;
120
123
  const said = JSON.stringify(value);
121
- if (seen.has(said)) return fail(unique, 'x-unique-by', part ? `不能重复:${value}` : `${key} 不能重复:${value}`, parentSchema);
124
+ if (seen.has(said)) return fail(unique, 'x-unique-by', part || text ? `不能重复:${value}` : `${key} 不能重复:${value}`, parentSchema);
122
125
  seen.add(said);
123
126
  }
124
127
  }