@coda-console/protocol 5.13.0 → 5.15.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,16 @@
2
2
 
3
3
  版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 5.15.0 — 2026-11-13
6
+
7
+ - 流程动作加 `check-setting`(参数 `plugin`、`setting`、`value`、`project`)与 `apply-setting`(另加 `approval`):Agent 提议改一项插件设置,`check-setting` 按设置接口写入的同一套规则检查并给出卡片显示的改前改后(不给 `value` 时读出当前值),`apply-setting` 在用户于 `approval` 任务的卡片上按了主按钮、卡片最后一个 `code` 字段与改后的值逐字相同后写入,流程须来自已装的插件或默认分支。只加动作,已有流程不变(Coda 内置能力 change-setting)。
8
+
9
+ ## 5.14.0 — 2026-11-13
10
+
11
+ - 流程方言加挂点:流程可写多个 `coda:join`(`hook` 必填,`name`、`detail`、`default` 为 true/false、`order` 为整数,同一流程 hook 不重复),流程属性加 `coda:mergedOnly`(只运行已合并进默认分支的提交,由流程自己声明)。动作加 `hook-joiners`(参数 `hook`、`commit`),`run-workflows` 加参数 `hook`、`only`。只加写法,`coda:kind` 与 `coda:deploy` 不变(Coda #2521 第 2 步)。
12
+ - 报错位置里 `coda:join` 以 hook 称呼。
13
+ - `coda:mergedOnly` 只认 true、false:与字段的布尔、整数属性一样先按文字读、核对拼写后才换成布尔值,写错的读流程时拒绝,不会被当成 false 放开只跑已合并提交的限制。
14
+
5
15
  ## 5.13.0 — 2026-11-13
6
16
 
7
17
  - 流程方言的答复加 `coda:optionList`:`value` 是表达式,任务打开时读出一组勾选项,在它写的位置展开,与 `coda:option` 按写的顺序排(moddle 里两者同属答复的 `options`,类型 `ChoiceOption`)。打开后的整组由新的 `workflow/options.json` 定义(`{ id, name, detail?, default? }`,最多 12 项,id 不重复),`optionsProblem` 检查它,`CODA_OPTIONS` 导出同一份 schema。只加写法,已有流程不变(Coda #2521 第 1 步)。
package/README.md CHANGED
@@ -14,6 +14,8 @@ 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` 说它是否只运行已合并进默认分支的提交。
18
+
17
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 完成。
18
20
 
19
21
  流程方言的 **卡片字段**由 `workflow/fields.json` 定义:七种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "5.13.0",
3
+ "version": "5.15.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -11,10 +11,12 @@
11
11
  "description": "请运行主体的会话的 Agent 压缩上下文(_coda/session/compact,见 docs/agent-protocol.md),从不失败:没压缩就写明原因"},
12
12
  "hold-group": {"params": ["group", "capacity", "borrow", "exclusive"],
13
13
  "description": "为这一步所在的那一段排进并发组 group,离开这一段或运行结束才放开;borrow 为 only 只借不排、no 从不借,exclusive 为 true 占满整组"},
14
- "run-workflows": {"params": ["kind", "commit", "inputs"],
15
- "description": "在 commit(默认本次运行的)上启动项目里所选种类(kind,逗号分隔)的全部流程,各给它声明了的 inputs(JSON 对象),等它们都结束;有一个失败就失败"},
14
+ "run-workflows": {"params": ["kind", "hook", "only", "commit", "inputs"],
15
+ "description": "在 commit(默认本次运行的)上启动项目里所选种类(kind,逗号分隔)或加入挂点 hook 的全部流程(两者写一个),only(流程名的 JSON 数组或逗号分隔)只启动其中这几个;各给它声明了的 inputs(JSON 对象),等它们都结束;有一个失败就失败"},
16
16
  "workflow-kinds": {"params": ["commit"],
17
17
  "description": "项目在这个提交上有没有各种类可调用的流程(项目自己的和启用插件的),各是布尔值"},
18
+ "hook-joiners": {"params": ["hook", "commit"],
19
+ "description": "项目在这个提交上加入挂点 hook 的流程(项目自己的和启用插件的):list 是勾选项形状的数组(id 为流程名、name、detail、default),按 order 排好,可直接给 coda:optionList;count 是个数"},
18
20
  "expire-tool-details": {"params": ["olderThan"],
19
21
  "description": "运行所属项目的会话里,已结束、最后活动距今超过 olderThan(ISO 8601 时长,如 P7D)的工具调用(含后台任务、用户自己的命令,不含原生子 Agent 卡片),删除完整输入输出,只留卡片摘要;删除不可恢复"},
20
22
  "cold-store": {"params": ["anyAfter", "archivedAfter"],
@@ -33,6 +35,10 @@
33
35
  "description": "把会话在内存里保管的密码(value:句柄)键入系统的身份验证并提交"},
34
36
  "run-command": {"params": ["command", "cwd", "approval"],
35
37
  "description": "用户在本运行人工任务 approval 的卡片上批准过这条命令后,以用户的身份在会话的工作副本(或 cwd)里执行它;result 是 exited、stopped 或 unknown"},
38
+ "check-setting": {"params": ["plugin", "setting", "value", "project"],
39
+ "description": "检查对一项插件设置的修改,规则同设置接口的写入,不写入:value 是新值的 JSON 文本(null 清除这一层),project 是目录 ID 或根路径(不写就是本机插件设置);result 是 valid(带卡片显示用的 plugin、setting、layer、before、after)、invalid(reason);不给 value 时是 current(当前值,密文只说设在哪层)"},
40
+ "apply-setting": {"params": ["plugin", "setting", "value", "project", "approval"],
41
+ "description": "同 check-setting 的修改,在用户于本运行人工任务 approval 的卡片上按了主按钮、卡片最后一个 code 字段与改后的值逐字相同之后写入;流程须来自已装的插件或默认分支;输出 layer(这一层写后的值)与 value(解析后的值)"},
36
42
  "tell-overdue": {"params": [],
37
43
  "description": "告知运行主体的会话里过了期限的等待项,像结果一样叫醒 Agent;根会话的同时告诉用户;同一项的同一个期限只说一次"},
38
44
  "publish-event": {"params": ["name", "subject", "payload", "commit", "project", "session"],
@@ -10,7 +10,7 @@
10
10
  "name": "ProcessProperties",
11
11
  "isAbstract": true,
12
12
  "extends": ["bpmn:Process"],
13
- "description": "流程本身:concurrency 并发、key 未结束运行的业务键、deploy 只跑默认分支的提交、title 运行在卡片上的名字(同 GitHub 的 run-name)、kind 种类(见 dialect.json 的 kinds)、dispatch 能否手动发起、inline Agent 用 workflow_run 发起时等它结束再回答、subagents 为 false 时会话 Agent 的原生子 Agent 不能发起、agents 生命周期流程跟随哪些 Agent 的会话(ID,逗号或空格分隔,不写是全部)、autoRun 事件(如 PR)来时会话与目录都没设「自动运行」的,按它决定起不起运行:true、false 或 =vars.<插件>.<设置>(不写为起)",
13
+ "description": "流程本身:concurrency 并发、key 未结束运行的业务键、deploy 只跑默认分支的提交、title 运行在卡片上的名字(同 GitHub 的 run-name)、kind 种类(见 dialect.json 的 kinds)、dispatch 能否手动发起、inline Agent 用 workflow_run 发起时等它结束再回答、subagents 为 false 时会话 Agent 的原生子 Agent 不能发起、agents 生命周期流程跟随哪些 Agent 的会话(ID,逗号或空格分隔,不写是全部)、autoRun 事件(如 PR)来时会话与目录都没设「自动运行」的,按它决定起不起运行:true、false 或 =vars.<插件>.<设置>(不写为起)、mergedOnly 只运行已合并进默认分支的提交(写了就按它,不写由 kind 推出)",
14
14
  "properties": [
15
15
  {"name": "concurrency", "isAttr": true, "type": "String"},
16
16
  {"name": "key", "isAttr": true, "type": "String"},
@@ -21,7 +21,7 @@
21
21
  {"name": "inline", "isAttr": true, "type": "Boolean"},
22
22
  {"name": "subagents", "isAttr": true, "type": "Boolean"},
23
23
  {"name": "agents", "isAttr": true, "type": "String"},
24
- {"name": "autoRun", "isAttr": true, "type": "String"}
24
+ {"name": "autoRun", "isAttr": true, "type": "String"}, {"name": "mergedOnly", "isAttr": true, "type": "Boolean"}
25
25
  ]
26
26
  },
27
27
  {
@@ -119,6 +119,18 @@
119
119
  {"name": "noteLabel", "isAttr": true, "type": "String"}
120
120
  ]
121
121
  },
122
+ {
123
+ "name": "Join",
124
+ "superClass": ["Element"],
125
+ "description": "流程加入一个挂点:hook 是挂点名,宿主按它找到这个流程;name、detail 是它作为勾选项时的名字与说明,default 是否默认勾上,order 排序(小的在前,不写排最后,同序按流程名)",
126
+ "properties": [
127
+ {"name": "hook", "isAttr": true, "type": "String"},
128
+ {"name": "name", "isAttr": true, "type": "String"},
129
+ {"name": "detail", "isAttr": true, "type": "String"},
130
+ {"name": "default", "isAttr": true, "type": "String"},
131
+ {"name": "order", "isAttr": true, "type": "String"}
132
+ ]
133
+ },
122
134
  {
123
135
  "name": "Input",
124
136
  "superClass": ["Element"],
@@ -11,6 +11,7 @@
11
11
  "key": {"type": "string", "pattern": "\\S", "maxLength": 4000, "x-feel": {"names": ["inputs", "github", "vars"]}, "description": "coda:key 须为 1–4000 个字符"},
12
12
  "title": {"type": "string", "pattern": "\\S", "maxLength": 200, "x-feel": true, "description": "coda:title 须为 1–200 个字符"},
13
13
  "kind": {"enum": ["deploy", "preview", "release", "check", "premerge", "prebuild", "develop"], "description": "coda:kind 只能是 deploy、preview、release、check、premerge、prebuild、develop"},
14
+ "mergedOnly": {"type": "boolean", "description": "coda:mergedOnly 只能是 true 或 false"},
14
15
  "agents": {"type": "string", "pattern": "^[\\s,]*[a-z][a-z0-9-]{0,39}(?:[\\s,]+[a-z][a-z0-9-]{0,39})*[\\s,]*$",
15
16
  "description": "coda:agents 写 Agent 的 ID,用逗号或空格分隔(小写字母、数字和「-」,以字母开头,至多 40 个字符),不能为空"},
16
17
  "autoRun": {"type": "string", "anyOf": [{"enum": ["true", "false"]}, {"pattern": "^\\s*=\\s*vars(\\.[A-Za-z_][A-Za-z0-9_-]*)+\\s*$"}], "x-feel": {"names": ["vars"]},
@@ -191,9 +192,22 @@
191
192
  "Process.children": {
192
193
  "type": "object",
193
194
  "properties": {
194
- "input": {"type": "array", "x-unique-by": ["name"], "description": "coda:input 的 name 不能重复"}
195
+ "input": {"type": "array", "x-unique-by": ["name"], "description": "coda:input 的 name 不能重复"},
196
+ "join": {"type": "array", "x-unique-by": ["hook"], "description": "coda:join 的 hook 不能重复:一个流程在一个挂点只加入一次"}
195
197
  }
196
198
  },
199
+ "Join": {
200
+ "type": "object",
201
+ "properties": {
202
+ "hook": {"type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$", "description": "hook 须为小写字母开头的小写字母、数字、「-」(至多 64 个字符)"},
203
+ "name": {"type": "string", "pattern": "\\S", "maxLength": 40, "description": "name 须为 1–40 个字"},
204
+ "detail": {"type": "string", "maxLength": 200, "description": "detail 不超过 200 字"},
205
+ "default": {"enum": ["true", "false"], "description": "default 只能是 true 或 false:挂点的列表在任何运行之外读出,不写表达式"},
206
+ "order": {"type": "string", "pattern": "^-?[0-9]{1,6}$", "description": "order 须为整数(至多 6 位)"}
207
+ },
208
+ "required": ["hook"],
209
+ "description": "coda:join 需要 hook"
210
+ },
197
211
  "UserTask.children": {
198
212
  "type": "object",
199
213
  "properties": {
package/workflow.mjs CHANGED
@@ -111,12 +111,15 @@ const SIZE_LIMIT = 1_000_000;
111
111
  // bpmn-moddle rewrites a descriptor as it takes it in (its names get their prefix), and whoever imports CODA_MODDLE may hand
112
112
  // it to one: what is read here is a copy taken as this loads, and each parse is given a copy of its own.
113
113
  const DESCRIPTOR = structuredClone(moddle);
114
- // moddle's Boolean/Integer coercion accepts `no` as false and `1.5` as 1. Keep field attributes as text until their
115
- // complete spelling is known; valid ones are restored to the descriptor's types before returning the parsed workflow.
116
- const FIELD_SCALARS = DESCRIPTOR.types.find(type => type.name === 'Field').properties.filter(p => ['Boolean', 'Integer'].includes(p.type));
114
+ // moddle's Boolean/Integer coercion accepts `no` as false and `1.5` as 1. Keep these attributes as text until their
115
+ // complete spelling is known; valid ones are restored to the descriptor's types before returning the parsed workflow,
116
+ // and the schemas say no to the rest. A field's, and coda:mergedOnly: a misspelling there would quietly run unmerged
117
+ // commits.
118
+ const SCALARS = [['Field', 'coda:Field'], ['ProcessProperties', 'bpmn:Process', ['mergedOnly']]].map(([name, on, only]) => ({ name, on,
119
+ properties: DESCRIPTOR.types.find(type => type.name === name).properties.filter(p => ['Boolean', 'Integer'].includes(p.type) && (!only || only.includes(p.name))) }));
117
120
  const PARSER_DESCRIPTOR = structuredClone(DESCRIPTOR);
118
- for (const property of PARSER_DESCRIPTOR.types.find(type => type.name === 'Field').properties)
119
- if (FIELD_SCALARS.some(p => p.name === property.name)) property.type = 'String';
121
+ for (const { name, properties } of SCALARS) for (const property of PARSER_DESCRIPTOR.types.find(type => type.name === name).properties)
122
+ if (properties.some(p => p.name === property.name)) property.type = 'String';
120
123
  const children = element => Object.values(element).flatMap(v => (Array.isArray(v) ? v : [v])).filter(v => v?.$type && v.$parent === element);
121
124
  // Everything in the definition under `element`, depth first, by a stack of its own, pushed one at a time: a definition may
122
125
  // nest deeper than the call stack goes, and hold more in one place than a call takes arguments.
@@ -214,7 +217,8 @@ function valuesProblem(root) {
214
217
  for (const element of elements) {
215
218
  const type = codaType(element);
216
219
  if (type) {
217
- const name = element.id ?? element.name, kind = type.name === 'Choice' && element.$parent?.$type === 'coda:Choice' ? 'NestedChoice' : type.name;
220
+ // What names the element where it is said: its id, a join's hook, or its own name.
221
+ const name = element.id ?? element.hook ?? element.name, kind = type.name === 'Choice' && element.$parent?.$type === 'coda:Choice' ? 'NestedChoice' : type.name;
218
222
  const problem = failed(check(kind), codaObject(element), `${owner(element)?.id} 的 coda:${lower(type.name)}${name ? ` ${name}` : ''}`, false, ['Field', 'Fields'].includes(kind));
219
223
  if (problem) return problem;
220
224
  continue;
@@ -257,10 +261,10 @@ export async function readWorkflow(source, file = 'workflow') {
257
261
  catch (e) { return { problem: `${file}.bpmn 不是有效的 BPMN 2.0:${e.message}` }; }
258
262
  const { rootElement: root, warnings } = parsed;
259
263
  if (warnings.length) return { problem: `${file}.bpmn 有无法识别的内容:${warnings.slice(0, 3).map(w => w.message).join(';')}` };
260
- for (const field of all(root).filter(e => e.$type === 'coda:Field')) for (const { name, type } of FIELD_SCALARS) {
261
- const value = field[name];
262
- if (type === 'Boolean' && ['true', 'false'].includes(value)) field[name] = value === 'true';
263
- if (type === 'Integer' && typeof value === 'string' && /^[+-]?\d+$/.test(value)) field[name] = Number(value);
264
+ for (const { on, properties } of SCALARS) for (const element of all(root).filter(e => e.$type === on)) for (const { name, type } of properties) {
265
+ const value = element[name];
266
+ if (type === 'Boolean' && ['true', 'false'].includes(value)) element[name] = value === 'true';
267
+ if (type === 'Integer' && typeof value === 'string' && /^[+-]?\d+$/.test(value)) element[name] = Number(value);
264
268
  }
265
269
  for (const task of all(root).filter(e => e.$type === 'bpmn:ServiceTask' && e.action !== undefined)) {
266
270
  if (!Object.hasOwn(CODA_ACTIONS, task.action)) return { problem: `${task.id}:coda:action 只能是 ${Object.keys(CODA_ACTIONS).join('、')}` };