@coda-console/protocol 5.16.0 → 5.17.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,10 @@
2
2
 
3
3
  版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 5.17.0 — 2026-11-13
6
+
7
+ - 勾选项可带输入:`coda:join` 加 `inputs`(加入者要从卡片拿的自己的文字参数,逗号或空格分隔,最多 4 个;读流程时检查每个都是本流程 type 为 string 的 `coda:input`、不重复,且上卡片时的 id 与 label(没写 label 用参数名)合乎勾选项输入的限制),`joinInputNames(join)` 读出这些名字。`workflow/options.json` 的勾选项加可选的 `inputs: [{ id, label }]`(一项最多 4 个、id 不重复),勾上这一项时卡片上出现这些文字输入,几项带同一个 id 时只出一个;`hook-joiners` 的列表项带上它们。只加写法,已有流程不变(Coda #2521 第 4 步)。
8
+
5
9
  ## 5.16.0 — 2026-11-13
6
10
 
7
11
  - 不兼容:删去三个没人用的清单键。`contributes.executors`(连同 `schemas/plugin/executors.json`,`SCHEMAS` 里不再有它;扩展点仍不能取名 `executors`)、`contributes.agents[].lifecycle`、`contributes.endpoints[].checks`(`x-unique-by` 只剩 `id`)。写了 `lifecycle` 或 `checks` 的清单校验不过。这三个键没有第三方在用,不在稳定面里,属于内部面,按 coda#2463 内部面不为它升大版本,只升次版本;`$id` 不变。
package/README.md CHANGED
@@ -14,9 +14,9 @@ Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
14
14
 
15
15
  读取定义时原有的 Coda 结构规则已全部纳入协议。Coda 接入 1.8.0 后,`parseBpmn` 只需调用 `readWorkflow`,再把 `root` 编译成引擎、任务、调度和图所需的结构;运行时才能知道的表达式结果、动态字段引用、调度设置实际值及能力是否存在,仍由宿主在运行时检查。
16
16
 
17
- 流程方言的 **挂点**是流程之间互相找到的方式:被调用的流程在自己的 extensionElements 里写 `<coda:join hook name? detail? default? order?/>` 加入一个挂点(`hook` 是小写字母开头的名字,一个流程每个挂点只加入一次),`name`、`detail` 是它作为勾选项时的名字与说明,`default` 是否默认勾上(只写 true 或 false:挂点的列表在任何运行之外读出),`order` 是整数,小的在前。宿主用动作 `hook-joiners` 列出一个挂点的加入者(勾选项形状,可直接给 `coda:optionList`),用 `run-workflows` 的 `hook` 调用它们,`only` 只调用勾中的几个。挂点名是普通字符串,传哪些参数、怎么选由声明它的宿主写在自己的说明里。流程属性 `coda:mergedOnly` 说它是否只运行已合并进默认分支的提交。
17
+ 流程方言的 **挂点**是流程之间互相找到的方式:被调用的流程在自己的 extensionElements 里写 `<coda:join hook name? detail? default? order?/>` 加入一个挂点(`hook` 是小写字母开头的名字,一个流程每个挂点只加入一次),`name`、`detail` 是它作为勾选项时的名字与说明,`default` 是否默认勾上(只写 true 或 false:挂点的列表在任何运行之外读出),`order` 是整数,小的在前;`inputs` 是它要从卡片拿的自己的文字参数(`coda:input`,type 为 string,逗号或空格分隔,最多 4 个,读流程时检查),`joinInputNames(join)` 读出这些名字。宿主用动作 `hook-joiners` 列出一个挂点的加入者(勾选项形状,带上各自的 `inputs`,可直接给 `coda:optionList`),用 `run-workflows` 的 `hook` 调用它们,`only` 只调用勾中的几个。挂点名是普通字符串,传哪些参数、怎么选由声明它的宿主写在自己的说明里。流程属性 `coda:mergedOnly` 说它是否只运行已合并进默认分支的提交。
18
18
 
19
- 流程方言的 **勾选项**写在答复(外层的 `coda:choice`)里:`coda:option` 是一项,`coda:optionList` 的 `value` 是一个表达式,任务打开时读出一组勾选项(列表或它的 JSON),在它写的位置展开,两者按写的顺序排。`<coda:options>` 不是它的写法(那个名字是答复自己的勾选项集合)。定义里每个 `coda:optionList` 算一项;打开后的整组由 `workflow/options.json` 定义:每项是 `{ id, name, detail?, default? }`(`default` 为布尔值,没有 `shown`),最多 12 项,id 不重复。`optionsProblem(options, where)` 检查一个答复打开后的整组(静态项已求值、各组已展开),合法时返回 `null`,否则返回「位置:说明」;表达式求值与展开仍由 Coda 完成。
19
+ 流程方言的 **勾选项**写在答复(外层的 `coda:choice`)里:`coda:option` 是一项,`coda:optionList` 的 `value` 是一个表达式,任务打开时读出一组勾选项(列表或它的 JSON),在它写的位置展开,两者按写的顺序排。`<coda:options>` 不是它的写法(那个名字是答复自己的勾选项集合)。定义里每个 `coda:optionList` 算一项;打开后的整组由 `workflow/options.json` 定义:每项是 `{ id, name, detail?, default?, inputs? }`(`default` 为布尔值,没有 `shown`),最多 12 项,id 不重复;`inputs` 是勾上这一项时卡片上出现的文字输入,每个 `{ id, label }`,一项最多 4 个、id 不重复,几项带同一个 id 时卡上只出一个。`optionsProblem(options, where)` 检查一个答复打开后的整组(静态项已求值、各组已展开),合法时返回 `null`,否则返回「位置:说明」;表达式求值与展开仍由 Coda 完成。
20
20
 
21
21
  流程方言的 **卡片字段**由 `workflow/fields.json` 定义:七种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
22
22
 
@@ -65,7 +65,7 @@ invocationResponseProblem({ run: { kind: 'coda/run@1', id: 'run-1' } });
65
65
  ```
66
66
 
67
67
  ```js
68
- import { workflowProblem, readWorkflow, fieldProblem, fieldsProblem, optionsProblem, CODA_FIELDS, CODA_OPTIONS } from '@coda-console/protocol/workflow';
68
+ import { workflowProblem, readWorkflow, fieldProblem, fieldsProblem, optionsProblem, joinInputNames, CODA_FIELDS, CODA_OPTIONS } from '@coda-console/protocol/workflow';
69
69
 
70
70
  // 一份流程(名字不带 .bpmn,用在说明里):方言里都有就返回 null,否则是一句说明。
71
71
  const problem = await workflowProblem(readFileSync('.coda/workflows/deploy.bpmn', 'utf8'), 'deploy');
@@ -75,7 +75,7 @@ const { root } = await readWorkflow(source, 'deploy');
75
75
  fieldProblem({ type: 'text', id: 'name', label: '名称' }, 'ask 的字段 name');
76
76
  fieldsProblem(JSON.parse(fieldsJSON), 'ask');
77
77
  // 一个答复打开后的整组勾选项(静态项已求值、coda:optionList 已展开)。
78
- optionsProblem([{ id: 'deploy', name: '部署', default: false }], 'approve 的答复 merge');
78
+ optionsProblem([{ id: 'release', name: '发布正式版', default: false, inputs: [{ id: 'notes', label: '发布说明' }] }], 'approve 的答复 merge');
79
79
  // CODA_FIELDS 是同一份 fields.json,也可从 @coda-console/protocol/workflow/fields.json 导入。
80
80
  ```
81
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "5.16.0",
3
+ "version": "5.17.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "workflow-kinds": {"params": ["commit"],
17
17
  "description": "项目在这个提交上有没有各种类可调用的流程(项目自己的和启用插件的),各是布尔值"},
18
18
  "hook-joiners": {"params": ["hook", "commit"],
19
- "description": "项目在这个提交上加入挂点 hook 的流程(项目自己的和启用插件的):list 是勾选项形状的数组(id 为流程名、name、detail、default),按 order 排好,可直接给 coda:optionList;count 是个数"},
19
+ "description": "项目在这个提交上加入挂点 hook 的流程(项目自己的和启用插件的):list 是勾选项形状的数组(id 为流程名、name、detail、default,以及 join 声明了 inputs 时的 inputs:各为 id 与这个参数的 label,没写 label 时为参数名),按 order 排好,可直接给 coda:optionList;count 是个数"},
20
20
  "expire-tool-details": {"params": ["olderThan"],
21
21
  "description": "运行所属项目的会话里,已结束、最后活动距今超过 olderThan(ISO 8601 时长,如 P7D)的工具调用(含后台任务、用户自己的命令,不含原生子 Agent 卡片),删除完整输入输出,只留卡片摘要;删除不可恢复"},
22
22
  "cold-store": {"params": ["anyAfter", "archivedAfter"],
@@ -122,13 +122,14 @@
122
122
  {
123
123
  "name": "Join",
124
124
  "superClass": ["Element"],
125
- "description": "流程加入一个挂点:hook 是挂点名,宿主按它找到这个流程;name、detail 是它作为勾选项时的名字与说明,default 是否默认勾上,order 排序(小的在前,不写排最后,同序按流程名)",
125
+ "description": "流程加入一个挂点:hook 是挂点名,宿主按它找到这个流程;name、detail 是它作为勾选项时的名字与说明,default 是否默认勾上,order 排序(小的在前,不写排最后,同序按流程名),inputs 是它要从卡片拿的自己的文字参数(勾上它时卡上出现这些输入)",
126
126
  "properties": [
127
127
  {"name": "hook", "isAttr": true, "type": "String"},
128
128
  {"name": "name", "isAttr": true, "type": "String"},
129
129
  {"name": "detail", "isAttr": true, "type": "String"},
130
130
  {"name": "default", "isAttr": true, "type": "String"},
131
- {"name": "order", "isAttr": true, "type": "String"}
131
+ {"name": "order", "isAttr": true, "type": "String"},
132
+ {"name": "inputs", "isAttr": true, "type": "String"}
132
133
  ]
133
134
  },
134
135
  {
@@ -14,11 +14,23 @@
14
14
  "id": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_-]{0,63}$", "description": "id 须为字母开头的字母、数字、「_」「-」"},
15
15
  "name": {"type": "string", "pattern": "\\S", "maxLength": 40, "description": "name 须为 1–40 个字"},
16
16
  "detail": {"type": "string", "maxLength": 200, "description": "detail 不超过 200 字"},
17
- "default": {"type": "boolean", "description": "default 须为 true 或 false"}
17
+ "default": {"type": "boolean", "description": "default 须为 true 或 false"},
18
+ "inputs": {"type": "array", "items": {"$ref": "#/$defs/input"}, "x-unique-by": ["id"], "allOf": [{"maxItems": 4, "description": "一个勾选项最多带 4 个输入"}],
19
+ "description": "inputs 须为输入的数组"}
18
20
  },
19
21
  "required": ["id", "name"],
20
22
  "additionalProperties": false,
21
- "description": "勾选项须为对象,有 id 与 name,可有 detail 与 default"
23
+ "description": "勾选项须为对象,有 id 与 name,可有 detail、default 与 inputs"
24
+ },
25
+ "input": {
26
+ "type": "object",
27
+ "properties": {
28
+ "id": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$", "description": "输入的 id 须为字母开头的字母、数字、「_」"},
29
+ "label": {"type": "string", "pattern": "\\S", "maxLength": 40, "description": "输入的 label 须为 1–40 个字"}
30
+ },
31
+ "required": ["id", "label"],
32
+ "additionalProperties": false,
33
+ "description": "勾选项的输入须为对象,有 id 与 label:勾上这一项时卡片上出现的一个文字输入,几项带同一个 id 时只出一个"
22
34
  }
23
35
  }
24
36
  }
@@ -203,7 +203,8 @@
203
203
  "name": {"type": "string", "pattern": "\\S", "maxLength": 40, "description": "name 须为 1–40 个字"},
204
204
  "detail": {"type": "string", "maxLength": 200, "description": "detail 不超过 200 字"},
205
205
  "default": {"enum": ["true", "false"], "description": "default 只能是 true 或 false:挂点的列表在任何运行之外读出,不写表达式"},
206
- "order": {"type": "string", "pattern": "^-?[0-9]{1,6}$", "description": "order 须为整数(至多 6 位)"}
206
+ "order": {"type": "string", "pattern": "^-?[0-9]{1,6}$", "description": "order 须为整数(至多 6 位)"},
207
+ "inputs": {"type": "string", "pattern": "^\\s*[A-Za-z_][A-Za-z0-9_]*(?:\\s*[,\\s]\\s*[A-Za-z_][A-Za-z0-9_]*){0,3}\\s*$", "description": "inputs 须为这个流程的参数名,逗号或空格分隔,最多 4 个"}
207
208
  },
208
209
  "required": ["hook"],
209
210
  "description": "coda:join 需要 hook"
package/workflow.mjs CHANGED
@@ -198,7 +198,10 @@ export function optionsProblem(list, where = '答复') {
198
198
  const validate = ajv.getSchema(`${options.$id}#/$defs/option`);
199
199
  for (const [index, option] of list.entries()) {
200
200
  const at = `${where} 的勾选项 ${typeof option?.id === 'string' && option.id ? option.id : index + 1}`;
201
- if (!validate(option)) return `${at}:${description(validate.errors[0], option)}`;
201
+ if (!validate(option)) {
202
+ const error = validate.errors[0];
203
+ return `${at}:${error.keyword === 'x-unique-by' ? `输入的 ${error.message}` : description(error, option)}`;
204
+ }
202
205
  }
203
206
  const all = ajv.getSchema(options.$id);
204
207
  return all(list) ? null : `${where}:勾选项的 ${all.errors[0].message}`;
@@ -248,6 +251,31 @@ function valuesProblem(root) {
248
251
  return null;
249
252
  }
250
253
 
254
+ // The names of its own inputs a coda:join asks of the card (`inputs`, comma or space separated), in order.
255
+ export function joinInputNames(join) {
256
+ return (join.inputs ?? '').split(/[\s,]+/).filter(Boolean);
257
+ }
258
+ // What a coda:join asks of the card that its process does not take as text, or null: each name is once, and one of the
259
+ // process's own coda:input of type string (the default), since what the card gives is what was written.
260
+ function joinInputsProblem(root) {
261
+ for (const process of (root.rootElements ?? []).filter(e => e.$type === 'bpmn:Process')) {
262
+ const held = process.extensionElements?.values ?? [];
263
+ const text = new Map(held.filter(e => e.$type === 'coda:Input' && (e.type ?? 'string') === 'string').map(e => [e.name, e]));
264
+ const input = ajv.getSchema(`${options.$id}#/$defs/input`);
265
+ for (const join of held.filter(e => e.$type === 'coda:Join')) {
266
+ const at = `${process.id} 的 coda:join ${join.hook}`, names = joinInputNames(join);
267
+ const repeated = names.find((name, i) => names.indexOf(name) !== i);
268
+ if (repeated) return `${at}:inputs 里 ${repeated} 重复`;
269
+ const stranger = names.find(name => !text.has(name));
270
+ if (stranger) return `${at}:inputs 里的 ${stranger} 不是这个流程的文字参数(type 为 string 的 coda:input)`;
271
+ // As hook-joiners gives it on the card (the label, or the name when none is written): what the list must take.
272
+ for (const name of names) if (!input({ id: name, label: text.get(name).label ?? name }))
273
+ return `${at}:inputs 里的 ${name} 上卡片时${description(input.errors[0])}${text.get(name).label === undefined ? '(没写 label 时用参数名)' : ''}`;
274
+ }
275
+ }
276
+ return null;
277
+ }
278
+
251
279
  // A workflow's definition (`file`, its name without `.bpmn`, for what is said) read with Coda's dialect: `{ root }`, the
252
280
  // parsed definitions, or `{ problem }`, what of it the dialect does not have — not BPMN, a coda: attribute or element it
253
281
  // does not know, an action it does not have or a parameter that action does not take — or a value of it its schema does
@@ -272,7 +300,7 @@ export async function readWorkflow(source, file = 'workflow') {
272
300
  const given = (task.extensionElements?.values ?? []).filter(v => v.$type === 'coda:Param');
273
301
  if (given.some(p => !params.includes(p.name))) return { problem: `${task.id}:coda:action ${task.action} 只接受参数 ${params.join('、')}` };
274
302
  }
275
- const problem = valuesProblem(root) ?? structureProblem(root, file);
303
+ const problem = valuesProblem(root) ?? joinInputsProblem(root) ?? structureProblem(root, file);
276
304
  return problem ? { problem } : { root };
277
305
  }
278
306
  // What of a workflow's definition the dialect does not have, or null.