@coda-console/protocol 6.10.0 → 6.12.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 +13 -0
- package/README.md +2 -2
- package/docs/protocol.md +30 -3
- package/package.json +1 -1
- package/protocol.mjs +15 -10
- package/schemas/protocol/v1/definition.json +22 -4
- package/workflow/actions.json +5 -3
- package/workflow.mjs +12 -3
- package/schemas/plugin/groups.json +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 6.12.0 — 2026-11-18
|
|
6
|
+
|
|
7
|
+
- 这是在 6.11.0 之上的次版本。依据 README「版本」一节:`contributes.groups` 与流程方言都是内部面,删改、新增可选参数升次版本。`stable/manifest.json` 里没有 `groups`,删它不动稳定面,`stable-grows` 与 `test/stable.test.mjs` 不受影响。
|
|
8
|
+
- 流程方言:`hold-group` 加参数 `select`,按池子借:逗号分隔的 `键=值`,全部与组记录的 `attributes` 相等才算匹配,只匹配 `attributes`,如 `platform=android`、`platform=ios,model=duo`;`group`、`select` 恰写一个,两个都写或都不写,读流程就拒(`group、select 须恰写一个`)。`select` 写成纯文本时读流程就按 `键=值(,键=值)*` 查(键是 1–100 个不含空白、「=」「,」的字符;值是 1–100 个不含「=」「,」的字符,中间可有空格如 `model=Mi 10 Pro`,首尾不能是空白;长度按字符计,补充平面字符算一个),写成表达式或含 `{{ … }}` 时留到运行时。输出 `group` 是实际排到的那个组的名字。脚本步骤上的 `coda:group` 不加选择器。`workflow/actions.json` 的动作定义因此多了 `oneOf`(列出的参数恰写一个)与 `pattern`(参数写成文字时的写法)。
|
|
9
|
+
- 不兼容:删掉 `contributes.groups`:删去 `schemas/plugin/groups.json`。名额不再由插件在清单里声明,改由插件写 `coda/group@1` 记录,容量取记录的 `capacity`(不写为 1)。`extension-points.json` 里保留键名单的 `groups` 留着,第三方仍不能把它当扩展点的键。清单里再写 `contributes.groups` 的结果与别的不认识的键一样:不查形状,`manifestProblem` 通过。README 里 `contributionProblem` 的示例改用 `modelProviders`。
|
|
10
|
+
|
|
11
|
+
## 6.11.0 — 2026-11-18
|
|
12
|
+
|
|
13
|
+
- 这是在 6.10.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,新增可选字段升次版本;`stable/` 不动,`stable/manifest.json` 与 `stable/view.json` 没有任何协议定义的字段,清单与页面接口都没变,旧清单、旧定义照旧通过(Coda 宿主设计 coda#2749 第 12 节,只读记录流)。
|
|
14
|
+
- 协议定义加可选的顶层 `streams`:流名(写法同操作名,复用 `operationName`)→ `{ description?, input }`,不许别的键,至多 50 条。流是挂在记录 `{ kind, id }` 上的只读字节流入口,和查询、操作并列;`input` 是参数的 JSON Schema(与操作的 `input` 同一写法),参数都来自查询串,是字符串。`definitionProblem` 还查每条流的 `input` 能编译。
|
|
15
|
+
- 权限组加可选的 `streams: [流名…]`(不重复)。`definitionProblem` 的规则与操作同构:每条流最多属于一组;组里列的流必须在 `streams` 里;「每组至少管一样东西」把 `streams` 算进去(有操作、有流,或 `read` 为 true),所以只管流的组合法。不在任何组里的流不对插件开放,只有 Coda 自己和它的客户端读;不写 `streams` 的定义照旧合法。
|
|
16
|
+
- 本包只管声明的形状;路由、放行与出流由 Coda 实现。核心协议的定义本版不声明流,由 Coda 后续随实现一起加。
|
|
17
|
+
|
|
5
18
|
## 6.10.0 — 2026-11-18
|
|
6
19
|
|
|
7
20
|
- 这是在 6.9.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,新增可选字段升次版本;清单新增可选根键 `uses`,旧清单照旧通过(Coda 宿主设计 coda#2749 H3)。
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
|
|
|
4
4
|
|
|
5
5
|
- **插件清单的类型**(`schemas/plugin/`):插件目录 `package.json` 里 `contributes` 的每个键是一种类型,各有一份 JSON Schema(draft 2020-12,`$id` 为 `https://coda.pub/schemas/plugin/v2/<文件>`)。`plugin.json` 是整份清单,只列通用键(`configuration`、`extensionPoints`、`extensions`、`services`、`setup`、`environment`、`path`、`endpoints`、`views`、`protocols`、`protocolImplementations`);`setting.json` 是一项设置的声明。其余键由 Coda 的贡献点登记表或某个插件的扩展点声明:Coda 自己的(`agents`、`composerModes`、`modelProviders` 等)的 schema 仍放在这里作公开数据(如 `agents.json`、`composer-modes.json`),由登记它的 provider 引用;扩展点可以带自己的 schema(`extensionPoints.<名>.schema`,声明它的插件目录里的一个文件),写给它的东西合乎那份 schema 才对。
|
|
6
6
|
- **通用校验器**(`validate.mjs`):用 Ajv 对清单做 schema 校验。JSON Schema 说不了的只用五个通用关键字(`x-unique-by`、`x-max-contains`、`x-ref`、`x-placeholders`、`x-file`,照 Kubernetes 的 `x-kubernetes-*`),每个在哪里写都是同一个意思,写法见文件开头。校验器不随功能变长:类型加字段就是改 schema。
|
|
7
|
-
- **协议定义与调用**(`schemas/protocol/`、`protocol.mjs`、`docs/protocol.md`):协议是 `命名空间/名字@大版本` + spec/status 的 JSON Schema + 操作;插件在 `contributes.protocols` 里定义自己命名空间下的协议,在 `contributes.protocolImplementations` 里声明实现哪些协议;定义可写 `permissions`
|
|
7
|
+
- **协议定义与调用**(`schemas/protocol/`、`protocol.mjs`、`docs/protocol.md`):协议是 `命名空间/名字@大版本` + spec/status 的 JSON Schema + 操作;插件在 `contributes.protocols` 里定义自己命名空间下的协议,在 `contributes.protocolImplementations` 里声明实现哪些协议;定义可写 `streams` 声明只读记录流,可写 `permissions` 把操作、流与记录的读取分成权限组,插件在清单根的 `uses` 里按组申请。调用是 `{ 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`、执行失败、工具调用的审核、配置探测)。
|
|
10
10
|
|
|
@@ -40,7 +40,7 @@ import { contributionProblem, manifestProblem, pointProblem, valueProblem, TYPES
|
|
|
40
40
|
// 整份清单的外壳与通用键;给出插件目录时,连同它点名的文件一起查(x-file)。合乎类型返回 null,否则是一句说明:哪里、schema 怎么说。
|
|
41
41
|
const manifest = JSON.parse(readFileSync('plugin/package.json', 'utf8'));
|
|
42
42
|
const problem = manifestProblem(manifest, 'plugin');
|
|
43
|
-
// 不是通用键的一个键,按声明它的一方给的 schema,放在整份清单里查:指针从清单的根算(
|
|
43
|
+
// 不是通用键的一个键,按声明它的一方给的 schema,放在整份清单里查:指针从清单的根算(modelProviders 的 ${config:…} 指向本插件的设置)。
|
|
44
44
|
contributionProblem(SCHEMAS['agents.json'], manifest, 'agents', 'plugin');
|
|
45
45
|
// 某个类型里的一部分,如输入框模式声明的参数。
|
|
46
46
|
valueProblem('composer-modes.json#/$defs/parameters', parameters, '插件给出的参数');
|
package/docs/protocol.md
CHANGED
|
@@ -74,7 +74,8 @@ protocolShortName('coda/run@1'); // 'coda-1run-21'
|
|
|
74
74
|
| `spec` | 记录的 spec 的 JSON Schema,必填 |
|
|
75
75
|
| `status` | 记录的 status 的 JSON Schema,必填 |
|
|
76
76
|
| `operations` | 操作名 → `{ description?, input, result, safe?, idempotent?, timeout? }` 或 `{ description?, input, run: true, timeout? }`,必填;不定义操作写 `{}` |
|
|
77
|
-
| `
|
|
77
|
+
| `streams` | 流名 → `{ description?, input }`,可选(见「只读记录流」) |
|
|
78
|
+
| `permissions` | 权限组名 → `{ title, trial?, operations?, streams?, read? }`,可选(见「权限组」) |
|
|
78
79
|
|
|
79
80
|
`spec`、`status`、`input`、`result` 都是 JSON Schema draft 2020-12,只引用自己文档里的 `#/$defs/...`,不引用别的文件。`input` 必有。操作的输出二选一:
|
|
80
81
|
|
|
@@ -174,18 +175,44 @@ invocationRequestProblem(request); // null 或说明
|
|
|
174
175
|
invocationResponseProblem(response); // 恰好有 result 或 run 之一
|
|
175
176
|
```
|
|
176
177
|
|
|
178
|
+
### 只读记录流
|
|
179
|
+
|
|
180
|
+
流是协议记录上的第三种入口,和查询、操作并列:按记录 `{ kind, id }` 寻址、只读、返回字节流(而不是一个 JSON 结果)。定义用顶层 `streams` 声明,键是流名(写法同操作名:小写字母开头,只用小写字母、数字和「-」,至多 64 个字符,至多 50 条),值是:
|
|
181
|
+
|
|
182
|
+
| 字段 | 含义 |
|
|
183
|
+
| --- | --- |
|
|
184
|
+
| `description` | 可选,一句话说明 |
|
|
185
|
+
| `input` | 必填,参数的 JSON Schema(draft 2020-12,和操作的 `input` 同一写法,`definitionProblem` 查它能编译) |
|
|
186
|
+
|
|
187
|
+
参数都来自查询串,取值都是字符串,所以 `input` 里的属性按字符串写约束。流名可以和操作名相同,两者各管各的。定义里不写 `streams` 就是没有流。本包只管声明的形状;怎样寻址、怎样出字节是宿主的事。
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
"streams": {
|
|
191
|
+
"log": {
|
|
192
|
+
"description": "一个步骤的日志,可从字节偏移取起",
|
|
193
|
+
"input": {
|
|
194
|
+
"type": "object",
|
|
195
|
+
"properties": {"job": {"type": "string"}, "after": {"type": "string", "pattern": "^[0-9]+$"}},
|
|
196
|
+
"required": ["job"],
|
|
197
|
+
"additionalProperties": false
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
177
203
|
### 权限组
|
|
178
204
|
|
|
179
|
-
一切对插件开放的能力都以协议提供,权限挂在协议上:定义用 `permissions`
|
|
205
|
+
一切对插件开放的能力都以协议提供,权限挂在协议上:定义用 `permissions` 把自己的操作、流与记录的读取分成组,插件在清单的 `uses` 里声明用到哪些组,没声明的调用被宿主拒绝。组名的写法同操作名(小写字母开头,只用小写字母、数字和「-」,至多 64 个字符)。每组:
|
|
180
206
|
|
|
181
207
|
| 字段 | 含义 |
|
|
182
208
|
| --- | --- |
|
|
183
209
|
| `title` | 必填,给用户看的一句话,说这组让插件能做什么,如「读取会话的标题与状态」 |
|
|
184
210
|
| `trial` | 可选,布尔,这组是否试行;只影响展示,不影响能否调用 |
|
|
185
211
|
| `operations` | 可选,不重复的操作名数组,归这组管的操作 |
|
|
212
|
+
| `streams` | 可选,不重复的流名数组,归这组管的流 |
|
|
186
213
|
| `read` | 可选,布尔,管不管读这个协议的记录(get、list、watch)。写记录只许实现方,不分给插件 |
|
|
187
214
|
|
|
188
|
-
不许有别的键。写了 `permissions` 的定义还要满足(`definitionProblem`
|
|
215
|
+
不许有别的键。写了 `permissions` 的定义还要满足(`definitionProblem` 查):每个操作、每条流最多属于一组;组里列的操作都在 `operations` 里,列的流都在 `streams` 里;每组至少管一样东西(有操作、有流,或 `read` 为 true)。**不在任何组里的操作和流不对插件开放**,只有 Coda 自己和它的客户端调;不写 `permissions` 的定义照旧合法,那时整个协议都不对插件开放。
|
|
189
216
|
|
|
190
217
|
```json
|
|
191
218
|
"permissions": {
|
package/package.json
CHANGED
package/protocol.mjs
CHANGED
|
@@ -74,18 +74,22 @@ function schemaProblem(schema, where) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
// Permission groups, when written: every group names real operations and covers something, every operation
|
|
78
|
-
// one group. An operation in no group is not open to plugins.
|
|
79
|
-
function permissionsProblem({ operations, permissions }, where) {
|
|
77
|
+
// Permission groups, when written: every group names real operations and streams and covers something, every operation and
|
|
78
|
+
// stream sits in at most one group. An operation or stream in no group is not open to plugins.
|
|
79
|
+
function permissionsProblem({ operations, streams = {}, permissions }, where) {
|
|
80
80
|
if (permissions === undefined) return null;
|
|
81
|
-
const owner = new Map();
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const owner = { operations: new Map(), streams: new Map() };
|
|
82
|
+
const things = { operations: ['操作', operations], streams: ['流', streams] };
|
|
83
|
+
for (const [group, entry] of Object.entries(permissions)) {
|
|
84
|
+
for (const key of ['operations', 'streams']) {
|
|
85
|
+
const [label, defined] = things[key];
|
|
86
|
+
for (const name of entry[key] ?? []) {
|
|
87
|
+
if (!Object.hasOwn(defined, name)) return `${where}.permissions.${group}.${key}:没有${label}「${name}」`;
|
|
88
|
+
if (owner[key].has(name)) return `${where}.permissions.${group}.${key}:${label}「${name}」已经属于权限组「${owner[key].get(name)}」,一个${label}只能属于一组`;
|
|
89
|
+
owner[key].set(name, group);
|
|
90
|
+
}
|
|
87
91
|
}
|
|
88
|
-
if (!
|
|
92
|
+
if (!entry.operations?.length && !entry.streams?.length && entry.read !== true) return `${where}.permissions.${group}:至少管一样东西:写 operations 或 streams,或 read 为 true`;
|
|
89
93
|
}
|
|
90
94
|
return null;
|
|
91
95
|
}
|
|
@@ -106,6 +110,7 @@ export function definitionProblem(definition, { namespace = null, where = '协
|
|
|
106
110
|
parts.push([`operations.${operation}.input`, value.input]);
|
|
107
111
|
if (value.result !== undefined) parts.push([`operations.${operation}.result`, value.result]);
|
|
108
112
|
}
|
|
113
|
+
for (const [stream, value] of Object.entries(definition.streams ?? {})) parts.push([`streams.${stream}.input`, value.input]);
|
|
109
114
|
for (const [key, schema] of parts) {
|
|
110
115
|
const problem = schemaProblem(schema, `${where}.${key}`);
|
|
111
116
|
if (problem) return problem;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://coda.pub/schemas/protocol/v1/definition.json",
|
|
4
4
|
"title": "协议定义",
|
|
5
|
-
"description": "一个协议的名字、记录格式与操作。名字是「命名空间/名字@大版本」;spec、status 与每个操作的输入、结果都是 JSON Schema(draft 2020-12),只引用定义自身的 $defs。操作要么立刻返回结果(result),要么返回运行引用(run: true);只读的立即结果可标 safe: true,可改状态但重发做同一件事的立即结果可标 idempotent: true。操作可写 timeout 给出默认期限。可写 permissions
|
|
5
|
+
"description": "一个协议的名字、记录格式与操作。名字是「命名空间/名字@大版本」;spec、status 与每个操作的输入、结果都是 JSON Schema(draft 2020-12),只引用定义自身的 $defs。操作要么立刻返回结果(result),要么返回运行引用(run: true);只读的立即结果可标 safe: true,可改状态但重发做同一件事的立即结果可标 idempotent: true。操作可写 timeout 给出默认期限。可写 streams 声明只读的记录流;可写 permissions 把操作、流与记录的读取分成权限组,供插件在清单里按组申请。",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"name": {"$ref": "#/$defs/name"},
|
|
@@ -18,8 +18,15 @@
|
|
|
18
18
|
"propertyNames": {"$ref": "#/$defs/operationName"},
|
|
19
19
|
"additionalProperties": {"$ref": "#/$defs/operation"}
|
|
20
20
|
},
|
|
21
|
+
"streams": {
|
|
22
|
+
"description": "只读记录流:流名 → 说明与参数。流和操作并列:按记录寻址、只读,返回字节流;参数来自查询串",
|
|
23
|
+
"type": "object",
|
|
24
|
+
"maxProperties": 50,
|
|
25
|
+
"propertyNames": {"$ref": "#/$defs/operationName"},
|
|
26
|
+
"additionalProperties": {"$ref": "#/$defs/stream"}
|
|
27
|
+
},
|
|
21
28
|
"permissions": {
|
|
22
|
-
"description": "权限组:组名 → 一组对插件开放的能力。插件在清单的 uses
|
|
29
|
+
"description": "权限组:组名 → 一组对插件开放的能力。插件在清单的 uses 里按组申请,没申请的调用被宿主拒绝。每个操作、每条流最多属于一组,组里列的操作与流都存在,每组至少管一样东西(有操作、有流,或 read 为真);这些由 definitionProblem 查。不在任何组里的操作和流不对插件开放,只有 Coda 自己和它的客户端调;不写 permissions 就是整个协议都不分组",
|
|
23
30
|
"type": "object",
|
|
24
31
|
"maxProperties": 50,
|
|
25
32
|
"propertyNames": {"$ref": "#/$defs/operationName"},
|
|
@@ -41,7 +48,7 @@
|
|
|
41
48
|
"pattern": "^[a-z][a-z0-9-]{0,62}$"
|
|
42
49
|
},
|
|
43
50
|
"operationName": {
|
|
44
|
-
"description": "
|
|
51
|
+
"description": "操作名,也是流名与权限组名(协议定义的 streams、permissions 的键、清单 uses 里的组名):小写字母开头,只用小写字母、数字和「-」,不超过 64 个字符",
|
|
45
52
|
"type": "string",
|
|
46
53
|
"pattern": "^[a-z][a-z0-9-]{0,63}$"
|
|
47
54
|
},
|
|
@@ -52,17 +59,28 @@
|
|
|
52
59
|
"title": {"description": "给人看的名字", "type": "string", "maxLength": 100, "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"},
|
|
53
60
|
"description": {"description": "一句话说明", "type": "string", "maxLength": 1000, "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"},
|
|
54
61
|
"permissionGroup": {
|
|
55
|
-
"description": "一个权限组:title 是给用户看的一句话,说这组让插件能做什么;trial 标这组是试行的;operations 是归这组管的操作;read 管不管读这个协议的记录(get、list、watch);写记录只许实现方,不分给插件",
|
|
62
|
+
"description": "一个权限组:title 是给用户看的一句话,说这组让插件能做什么;trial 标这组是试行的;operations 是归这组管的操作;streams 是归这组管的流;read 管不管读这个协议的记录(get、list、watch);写记录只许实现方,不分给插件",
|
|
56
63
|
"type": "object",
|
|
57
64
|
"properties": {
|
|
58
65
|
"title": {"$ref": "#/$defs/title"},
|
|
59
66
|
"trial": {"type": "boolean", "description": "是否试行:只影响展示,不影响能否调用"},
|
|
60
67
|
"operations": {"type": "array", "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/$defs/operationName"}, "description": "归这组管的操作名,不重复"},
|
|
68
|
+
"streams": {"type": "array", "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/$defs/operationName"}, "description": "归这组管的流名,不重复"},
|
|
61
69
|
"read": {"type": "boolean", "description": "管不管读这个协议的记录(get、list、watch)"}
|
|
62
70
|
},
|
|
63
71
|
"required": ["title"],
|
|
64
72
|
"additionalProperties": false
|
|
65
73
|
},
|
|
74
|
+
"stream": {
|
|
75
|
+
"description": "只读记录流:input 是参数的 JSON Schema,参数都来自查询串,取值都是字符串;description 是一句话说明",
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {
|
|
78
|
+
"description": {"$ref": "#/$defs/description"},
|
|
79
|
+
"input": {"$ref": "#/$defs/schema"}
|
|
80
|
+
},
|
|
81
|
+
"required": ["input"],
|
|
82
|
+
"additionalProperties": false
|
|
83
|
+
},
|
|
66
84
|
"operation": {
|
|
67
85
|
"description": "操作:input 必有;result 是立即结果的 schema,或写 run: true 表示返回运行引用。两者恰写一个。safe: true、idempotent: true 只能与 result 一起写,两者不同时写(safe 已含 idempotent)。",
|
|
68
86
|
"type": "object",
|
package/workflow/actions.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "coda:action:serviceTask 上写它,就是 Coda 在后端里做的一步,不写脚本。参数写成 <coda:param name value>,只认 params 列出的,required 列出的必须写;requires 写了某参数就必须同时写它列出的参数;enum 限定某参数写成文字(不是表达式、不含 {{ … }}
|
|
2
|
+
"description": "coda:action:serviceTask 上写它,就是 Coda 在后端里做的一步,不写脚本。参数写成 <coda:param name value>,只认 params 列出的,required 列出的必须写;requires 写了某参数就必须同时写它列出的参数;oneOf 列出的参数恰写一个;enum 限定某参数写成文字(不是表达式、不含 {{ … }})时的取值;pattern 限定某参数写成文字时的写法",
|
|
3
3
|
"actions": {
|
|
4
4
|
"publish-stage": {"params": ["stage", "detail"],
|
|
5
5
|
"description": "发布运行主体的会话此刻在流程里的阶段(stage)和放在状态旁的说明(detail),两者都空就是清掉;只用于由会话事件启动的运行"},
|
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
"description": "停掉运行主体的会话托管的 Agent 进程,下次发消息时透明恢复;result 是 stopped、absent 或 busy"},
|
|
10
10
|
"compact-session": {"params": [],
|
|
11
11
|
"description": "请运行主体的会话的 Agent 压缩上下文(_coda/session/compact,见 docs/agent-protocol.md),从不失败:没压缩就写明原因"},
|
|
12
|
-
"hold-group": {"params": ["group", "capacity", "borrow", "exclusive"],
|
|
13
|
-
"
|
|
12
|
+
"hold-group": {"params": ["group", "select", "capacity", "borrow", "exclusive"],
|
|
13
|
+
"oneOf": ["group", "select"],
|
|
14
|
+
"pattern": {"select": {"regex": "^[^\\s=,]{1,100}=[^\\s=,](?:[^=,]{0,98}[^\\s=,])?(,[^\\s=,]{1,100}=[^\\s=,](?:[^=,]{0,98}[^\\s=,])?)*$", "hint": "键=值,多个用逗号隔开,值的首尾不能是空白,如 platform=android,model=Mi 10 Pro"}},
|
|
15
|
+
"description": "为这一步所在的那一段排进并发组,离开这一段或运行结束才放开:group 点名一个组;select 按池子借,是逗号分隔的 键=值,全部与组记录的 attributes 相等才算匹配(如 platform=android),从匹配的组里挑一个排;group、select 恰写一个,输出 group 是实际排到的那个组的名字;borrow 为 only 只借不排、no 从不借,exclusive 为 true 占满整组"},
|
|
14
16
|
"run-workflows": {"params": ["hook", "only", "commit", "inputs"], "required": ["hook"],
|
|
15
17
|
"description": "在 commit(默认本次运行的)上启动项目里加入挂点 hook 的全部流程(项目自己的和启用插件的),only(流程名的 JSON 数组或逗号分隔)只启动其中这几个;各给它声明了的 inputs(JSON 对象),等它们都结束;有一个失败就失败"},
|
|
16
18
|
"hook-joiners": {"params": ["hook", "commit"],
|
package/workflow.mjs
CHANGED
|
@@ -37,9 +37,10 @@ export const CODA_OPTIONS = options;
|
|
|
37
37
|
export const CODA_ACTIONS = Object.fromEntries(Object.entries(actions.actions).map(([name, action]) => [name, action.params]));
|
|
38
38
|
// The parameters an action must be given, by its name; an action with none is not listed.
|
|
39
39
|
const REQUIRED_PARAMS = Object.fromEntries(Object.entries(actions.actions).filter(([, action]) => action.required).map(([name, action]) => [name, action.required]));
|
|
40
|
-
// What an action's parameters must keep to besides being named: the others one needs (`requires`, by parameter),
|
|
41
|
-
//
|
|
42
|
-
|
|
40
|
+
// What an action's parameters must keep to besides being named: the others one needs (`requires`, by parameter), exactly
|
|
41
|
+
// one of which to write (`oneOf`), and the values (`enum`) or the form (`pattern`) a parameter written as plain text may
|
|
42
|
+
// take; an action with none of them is not listed.
|
|
43
|
+
const PARAM_RULES = Object.fromEntries(Object.entries(actions.actions).filter(([, action]) => action.requires || action.oneOf || action.enum || action.pattern).map(([name, action]) => [name, action]));
|
|
43
44
|
// The events Coda sends (dialect.json says what each is).
|
|
44
45
|
export const CODA_EVENTS = Object.keys(dialect.events);
|
|
45
46
|
export const { lifecycleStart: SESSION_OPENED, lifecycleFacts: SESSION_FACTS, dispatch: DISPATCH_EVENT, cancel: CANCEL_EVENT } = dialect.eventRoles;
|
|
@@ -310,6 +311,14 @@ export async function readWorkflow(source, file = 'workflow') {
|
|
|
310
311
|
for (const [name, needs] of Object.entries(PARAM_RULES[task.action]?.requires ?? {}))
|
|
311
312
|
if (given.some(p => p.name === name) && needs.some(need => !given.some(p => p.name === need)))
|
|
312
313
|
return { problem: `${task.id}:coda:action ${task.action} 写了参数 ${name} 就须写参数 ${needs.join('、')}` };
|
|
314
|
+
const oneOf = PARAM_RULES[task.action]?.oneOf;
|
|
315
|
+
if (oneOf && given.filter(p => oneOf.includes(p.name)).length !== 1)
|
|
316
|
+
return { problem: `${task.id}:coda:action ${task.action} 的参数 ${oneOf.join('、')} 须恰写一个` };
|
|
317
|
+
for (const [name, { regex, hint }] of Object.entries(PARAM_RULES[task.action]?.pattern ?? {})) {
|
|
318
|
+
const value = given.find(p => p.name === name)?.value;
|
|
319
|
+
if (value !== undefined && !isExpression(value) && !value.includes('{{') && !new RegExp(regex, 'u').test(value))
|
|
320
|
+
return { problem: `${task.id}:coda:action ${task.action} 的参数 ${name} 须为 ${hint}` };
|
|
321
|
+
}
|
|
313
322
|
for (const [name, values] of Object.entries(PARAM_RULES[task.action]?.enum ?? {})) {
|
|
314
323
|
const value = given.find(p => p.name === name)?.value;
|
|
315
324
|
if (value !== undefined && !isExpression(value) && !value.includes('{{') && !values.includes(value))
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://coda.pub/schemas/plugin/v2/groups.json",
|
|
4
|
-
"title": "contributes.groups:并发组",
|
|
5
|
-
"description": "有名字、有容量的锁:name 是任何进程都能拿的组名,capacity 是本插件的一项整数设置,说同时放进几个。",
|
|
6
|
-
"type": "array",
|
|
7
|
-
"items": {
|
|
8
|
-
"type": "object",
|
|
9
|
-
"properties": {
|
|
10
|
-
"name": {"description": "组名:1–100 个非空白字符", "type": "string", "pattern": "^\\S{1,100}$"},
|
|
11
|
-
"capacity": {
|
|
12
|
-
"description": "capacity 是本插件声明的一项整数设置",
|
|
13
|
-
"type": "string",
|
|
14
|
-
"x-ref": {"pointer": "/contributes/configuration/properties", "match": {"properties": {"type": {"const": "integer"}}, "required": ["type"]}}
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"required": ["name", "capacity"],
|
|
18
|
-
"additionalProperties": false
|
|
19
|
-
},
|
|
20
|
-
"x-unique-by": ["name"]
|
|
21
|
-
}
|