@coda-console/protocol 5.11.0 → 5.13.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
@@ -1,6 +1,14 @@
1
1
  # 变更记录
2
2
 
3
- 按 semver。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
3
+ 版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
+
5
+ ## 5.13.0 — 2026-11-13
6
+
7
+ - 流程方言的答复加 `coda:optionList`:`value` 是表达式,任务打开时读出一组勾选项,在它写的位置展开,与 `coda:option` 按写的顺序排(moddle 里两者同属答复的 `options`,类型 `ChoiceOption`)。打开后的整组由新的 `workflow/options.json` 定义(`{ id, name, detail?, default? }`,最多 12 项,id 不重复),`optionsProblem` 检查它,`CODA_OPTIONS` 导出同一份 schema。只加写法,已有流程不变(Coda #2521 第 1 步)。
8
+
9
+ ## 5.12.0 — 2026-11-13
10
+
11
+ - 圈定第三方稳定面:随包发布 53 条清单路径及页面接口、外观清单,各从 revision 1 起;增加只增不减、schema 路径可达与第三方清单样本校验,PR 对目标分支、发布前对 npm latest 检查。补充清单的 displayName、version;稳定面只增不减,内部面删改不升主版本(coda#2463)。
4
12
 
5
13
  ## 5.11.0 — 2026-11-11
6
14
 
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
+ 流程方言的 **勾选项**写在答复(外层的 `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
+
17
19
  流程方言的 **卡片字段**由 `workflow/fields.json` 定义:七种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
18
20
 
19
21
  脚本步骤的 **工作副本** 由 `coda:source` 声明:这一步在哪个工作副本目录里跑,写本机上的绝对路径,可以写 FEEL 表达式。它只用于 `coda:checkout="false"` 的步骤:在本机跑就在那个目录里就地跑,不检出提交;交给别的执行环境时,由调用方给这个目录所在的工作副本拍快照(含未提交、未跟踪的改动,不含忽略的文件),对方检出快照、在对应的子目录里跑。协议里 `coda/executor@1` 的 `execute` 输入已有 `source.snapshot` 与 `workingDirectory`,交给别台时就用这两项,执行器协议本身不改。
@@ -61,7 +63,7 @@ invocationResponseProblem({ run: { kind: 'coda/run@1', id: 'run-1' } });
61
63
  ```
62
64
 
63
65
  ```js
64
- import { workflowProblem, readWorkflow, fieldProblem, fieldsProblem, CODA_FIELDS } from '@coda-console/protocol/workflow';
66
+ import { workflowProblem, readWorkflow, fieldProblem, fieldsProblem, optionsProblem, CODA_FIELDS, CODA_OPTIONS } from '@coda-console/protocol/workflow';
65
67
 
66
68
  // 一份流程(名字不带 .bpmn,用在说明里):方言里都有就返回 null,否则是一句说明。
67
69
  const problem = await workflowProblem(readFileSync('.coda/workflows/deploy.bpmn', 'utf8'), 'deploy');
@@ -70,6 +72,8 @@ const { root } = await readWorkflow(source, 'deploy');
70
72
  // 任务打开、接受答复时检查已求值的字段,不填默认值,不执行表达式。
71
73
  fieldProblem({ type: 'text', id: 'name', label: '名称' }, 'ask 的字段 name');
72
74
  fieldsProblem(JSON.parse(fieldsJSON), 'ask');
75
+ // 一个答复打开后的整组勾选项(静态项已求值、coda:optionList 已展开)。
76
+ optionsProblem([{ id: 'deploy', name: '部署', default: false }], 'approve 的答复 merge');
73
77
  // CODA_FIELDS 是同一份 fields.json,也可从 @coda-console/protocol/workflow/fields.json 导入。
74
78
  ```
75
79
 
@@ -144,11 +148,21 @@ agentValueProblem('review.json', review, '工具的审核');
144
148
 
145
149
  ## 版本
146
150
 
147
- 按 semver,Coda 与检查包都钉一个确切版本:
151
+ Coda 与检查包都钉一个确切版本。对第三方的兼容承诺只覆盖**稳定面**:第三方实际在用的清单键和页面接口,定义在随 npm 包发布的 [`stable/manifest.json`](stable/manifest.json) 与 [`stable/view.json`](stable/view.json)。稳定面只增不减;要改变或删除承诺,先标弃用,保留过渡时间,不能直接移除定义或破坏现有用法。
152
+
153
+ 其余都是**内部面**,不承诺兼容,删改升次版本。包括未列入稳定面的清单键、扩展点、模块的 `coda` 对象、`CODA_*` 环境变量、Agent 接入协议、协议定义与流程方言,以及 `coda-view://service/…`。新增可选字段、新类型、放宽限制升次版本。主版本只留给稳定面的不兼容改动;按稳定面只增不减的规矩,这不该发生,真要发生须先标弃用、留过渡时间。协议名里的版本(如 `coda/run@1`)与 npm 包版本、schema 的 `$id` 独立。
154
+
155
+ 两份数据各有从 1 起的整数 `revision`。每项清单以 `path` 标识;`.` 分隔固定键,`[]` 表示数组项,`*` 表示插件自行命名的键。例如 `contributes.configuration.properties.*.additionalProperties.properties.*.format`。`values` 是承诺接受的取值,而非完整枚举。页面文件的成员、事件、根类名、CSS 变量分别列出;`open.targets` 只承诺 `{ view, args }`,`toolbar.fields/kinds` 只承诺列出的字段和种类。
156
+
157
+ 三道检查分别守住:
158
+
159
+ - `scripts/stable-grows.mjs <基线>`:两份数据的旧条目及其取值必须全部保留,有新增时对应文件的 revision 必须增大,不能倒退。基线可为 git 提交、解包目录或 `npm:latest`。PR 和目标分支比较,发布前下载并解包 npm latest 比较;基线还没有 stable 文件时通过。
160
+ - `test/stable.test.mjs`:53 条路径仍在 schema 中可达,承诺的取值仍被接受。使用固定样本选择条件分支,支持 `$ref`、`allOf`、`anyOf`、`if/then/else`、`not`、`properties`、`items`、`additionalProperties` 及布尔 schema;未知写法失败,不推测其含义。`agents`、`commands`、`skills` 从各自的业务 schema 起步。
161
+ - `test/third-party.test.mjs`:两版 pi、一版 resource-manager 原文与 company 合成样本,分别跑整份清单和每个贡献键的校验,防止样本用到的约束被收紧。不检查磁盘文件与页面桥行为。这个仓库只守页面接口清单只增不减;页面接口的实现在 Coda 的客户端里,这里不核对。
162
+
163
+ 增加稳定面一项时,先补 schema 或页面实现,再把路径、取值或页面条目加进对应 JSON;每加一项,该文件 revision 加一。补充能覆盖新路径和条件分支的测试样本,运行三道检查,并更新次版本与 CHANGELOG。
148
164
 
149
- - 只加东西(新的可选字段、新的类型、放宽限制)升次版本;
150
- - 改名、删除、收紧(旧的清单会变得不合)升主版本,`$id` 里的 `v1` 随之变成 `v2`。
151
- - 协议自己的大版本写在协议名里(`coda/run@1`);同一大版本只加可选字段和新操作,改含义或删东西升大版本,新旧可并存。
165
+ 协议自己的大版本写在协议名里(`coda/run@1`);同一大版本只加可选字段和新操作,改含义或删东西升大版本,新旧可并存。
152
166
 
153
167
  3.0.0 删除了 `executor` 与 `execution`,并把执行请求并入 `coda/executor@1` 的 `execute`;这是不兼容变更,旧代码须改用 `@coda-console/protocol/protocol` 与 `coda/run@1`。
154
168
 
@@ -1,6 +1,6 @@
1
1
  # Agent 接入协议
2
2
 
3
- Coda 用 [ACP](https://agentclientprotocol.com)(Agent Client Protocol)接 Agent,要求 Agent 接受[会话指令](#会话指令)(ACP 的 `systemPrompt`),
3
+ Coda 用 [ACP](https://agentclientprotocol.com)(Agent Client Protocol)接 Agent,把[会话指令](#会话指令)交给 Agent(ACP 的 `systemPrompt`;不收它的由 Coda 在第一轮送入),
4
4
  可选支持[插话](#插话)(`_session/steering`),另收 Agent 活动报告(`_coda/wait`)、入口[没适配的东西](#没适配的东西)(`_coda/unrecognized`)、[执行失败事实](#执行失败)(ACP 错误数据里的 `_meta.coda.failure`)和[工具调用的审核](#工具调用的审核)(`_meta.coda.review`)。本文是这份协议的唯一正文,写给要让一个 Agent(比如 Cursor 的)接入 Coda 的人:照它实现,
5
5
  Coda 就知道这个 Agent 在一轮之外还在做什么,如实显示、不回收它的进程,把它处理这些东西时的输出、审批和提问放进正确的一轮,
6
6
  并在这次调用结清时把结果只交回一次。产品上这些规则的来由见会话行为契约(Coda 的 docs/session-contracts.md)与完成唤醒契约(Coda 的 docs/subagent-design.md「完成唤醒契约」)。
@@ -76,7 +76,7 @@ Coda 是 ACP 的客户端。每个会话的 Agent 进程由一个会话托管进
76
76
  | 方法 | 方向 | Coda 怎么用 |
77
77
  | --- | --- | --- |
78
78
  | `initialize` | Coda → Agent | 握手。`clientCapabilities` 带 `elicitation.form`、`elicitation.url`、`session.compaction`、`session.configOptions.boolean`、`_meta.coda.waits`(见[能力协商](#能力协商))、`_meta.coda.unrecognized`(见[没适配的东西](#没适配的东西))与 `_meta.coda.remote`(见[远端入口](#远端入口)) |
79
- | `session/new`、`session/load` | Coda → Agent | 新建或恢复原生会话,会话 ID 由 Agent 给;Agent 声明 `loadSession` 才会被要求恢复。带 `systemPrompt`([会话指令](#会话指令))。结果里要报出当前模型(见下)。恢复期间重放的历史 Coda 不收(它有自己的),只收命令与标题 |
79
+ | `session/new`、`session/load` | Coda → Agent | 新建或恢复原生会话,会话 ID 由 Agent 给;Agent 声明 `loadSession` 才会被要求恢复。Agent 声明了才带 `systemPrompt`([会话指令](#会话指令))。结果里要报出当前模型(见下)。恢复期间重放的历史 Coda 不收(它有自己的),只收命令与标题 |
80
80
  | `session/prompt` | Coda → Agent | 一轮:Coda 送出用户的消息或它自己合成的输入(子会话结果等),Agent 回复 `stopReason` 即本轮结束 |
81
81
  | `_session/steering` | Coda → Agent | [插话](#插话):把用户的消息加进正在进行的一轮;只对声明支持的 Agent 发 |
82
82
  | `session/cancel` | Coda → Agent | 停止:本轮在进行时取消本轮;Agent 在一轮之外处理活动(`handling`)时,停止处理 |
@@ -126,7 +126,7 @@ ACP 只允许在一轮(`session/prompt`)进行时交互。Agent 在两轮之
126
126
 
127
127
  Coda 给每个会话一份指令:回复怎样在 Mac 与 iPhone 上显示、默认回复语言,再接目录启用的插件说明(插件(Coda 的 docs/plugins.md)的 `contributes.instructions`),
128
128
  正文在 `backend/src/components/session-config/client-instructions.mjs`。它走 ACP 的 [`systemPrompt`](https://agentclientprotocol.com/protocol/draft/session-setup#system-prompt-unstable)(unstable),
129
- **接入 Coda 的 Agent 必须支持**:
129
+ 有原生入口的 Agent 声明并接收它;没有的不必声明,由 Coda 自己送入(见本节最后一条):
130
130
 
131
131
  - **声明**:`initialize` 结果的 `agentCapabilities.sessionCapabilities.systemPrompt: {}`。Coda 只用 `append` 模式,不需要声明 `mode.override`。
132
132
  - **传入**:`session/new` 与 `session/load` 都带同一份 `{"mode": "append", "content": [{"type": "text", "text": …}]}`,只有一个文本块。
@@ -135,7 +135,7 @@ Coda 给每个会话一份指令:回复怎样在 Mac 与 iPhone 上显示、
135
135
  没有原生入口的,由插件在这个原生会话**第一次** `session/prompt` 时把指令作为单独、明确分隔的一段放在用户输入前面一起送入,之后不再送(第一轮是斜杠命令时顺延到下一轮,免得命令不再被认出);
136
136
  `session/load` 恢复的会话已经送过,不再送。Coda 显示与保存的用户原文不变。首条消息里的指令分量不如系统提示词,这是没有原生入口时的近似。
137
137
  - **失败**:应用不了(不认识的模式、内容超出上限)时 `session/new`、`session/load` 回错误,不建立会话(ACP 建议 -32602)。
138
- - 没声明的 Agent,Coda 照 ACP 的规矩不发 `systemPrompt`,会话照常打开,只是没有 Coda 的指令;契约检查判它不合格。
138
+ - **没声明的 Agent**:Coda 照 ACP 的规矩不发 `systemPrompt`,由 Coda 自己在这个原生会话**第一次** `session/prompt` 时把指令作为单独的一个文本块放在用户输入前面一起送入,之后不再送。这一块以 `<coda-session-instructions>` 起、`</coda-session-instructions>` 止,开头写明它来自 Coda、不是用户消息的一部分。第一轮是斜杠命令时顺延到下一轮,免得命令不再被认出;`session/load` 恢复的会话已经送过,不再送。Coda 显示与保存的用户原文不变;Agent 拿这一轮的开头起的标题,Coda 不采用。首条消息里的指令分量不如系统提示词,这是没有原生入口时的近似。插件不用为此写代码。
139
139
 
140
140
  Coda 的 MCP 服务器只提供工具,不带 `instructions`。
141
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "5.11.0",
3
+ "version": "5.13.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -19,7 +19,8 @@
19
19
  "workflow.mjs",
20
20
  "docs",
21
21
  "protocol.mjs",
22
- "CHANGELOG.md"
22
+ "CHANGELOG.md",
23
+ "stable"
23
24
  ],
24
25
  "exports": {
25
26
  "./validate": "./validate.mjs",
@@ -29,7 +30,8 @@
29
30
  "./docs/*": "./docs/*",
30
31
  "./package.json": "./package.json",
31
32
  "./agent": "./agent.mjs",
32
- "./protocol": "./protocol.mjs"
33
+ "./protocol": "./protocol.mjs",
34
+ "./stable/*": "./stable/*"
33
35
  },
34
36
  "engines": {
35
37
  "node": ">=24"
@@ -7,6 +7,8 @@
7
7
  "properties": {
8
8
  "id": {"$ref": "common.json#/$defs/id", "description": "插件 ID:小写字母、数字和「-」,以字母开头,至多 40 个字符;不写就用 name"},
9
9
  "name": {"type": "string"},
10
+ "displayName": {"type": "string"},
11
+ "version": {"type": "string"},
10
12
  "description": {"description": "一句话简介:插件列表里只显示一行,20 字以内为宜;更多的说明写在插件目录的 README.md,插件页里显示", "type": "string"},
11
13
  "icon": {
12
14
  "description": "插件的图标:插件目录里的 PDF(light 必填,dark 与 template 可选,同 Agent 的图标),或 SF Symbols 的符号画在系统色的底上(symbol 与 color);客户端裁成圆角方块。不写时,只带一个 Agent 的插件用那个 Agent 的图标,其余用分类的默认图标",
@@ -0,0 +1,171 @@
1
+ {
2
+ "revision": 1,
3
+ "entries": [
4
+ {
5
+ "path": "name"
6
+ },
7
+ {
8
+ "path": "id"
9
+ },
10
+ {
11
+ "path": "displayName"
12
+ },
13
+ {
14
+ "path": "description"
15
+ },
16
+ {
17
+ "path": "version"
18
+ },
19
+ {
20
+ "path": "categories"
21
+ },
22
+ {
23
+ "path": "icon.symbol"
24
+ },
25
+ {
26
+ "path": "icon.color"
27
+ },
28
+ {
29
+ "path": "main"
30
+ },
31
+ {
32
+ "path": "contributes.agents[].id"
33
+ },
34
+ {
35
+ "path": "contributes.agents[].displayName"
36
+ },
37
+ {
38
+ "path": "contributes.agents[].command"
39
+ },
40
+ {
41
+ "path": "contributes.agents[].icon.light"
42
+ },
43
+ {
44
+ "path": "contributes.agents[].modes.title"
45
+ },
46
+ {
47
+ "path": "contributes.agents[].modes.note"
48
+ },
49
+ {
50
+ "path": "contributes.agents[].skillsDir"
51
+ },
52
+ {
53
+ "path": "contributes.agents[].configFiles[]"
54
+ },
55
+ {
56
+ "path": "contributes.agents[].setupHint"
57
+ },
58
+ {
59
+ "path": "contributes.agents[].modes.unset"
60
+ },
61
+ {
62
+ "path": "contributes.agents[].modes.auto"
63
+ },
64
+ {
65
+ "path": "contributes.agents[].modes.full"
66
+ },
67
+ {
68
+ "path": "contributes.agents[].icon.dark"
69
+ },
70
+ {
71
+ "path": "contributes.agents[].icon.template"
72
+ },
73
+ {
74
+ "path": "contributes.configuration.title"
75
+ },
76
+ {
77
+ "path": "contributes.configuration.properties.*"
78
+ },
79
+ {
80
+ "path": "contributes.configuration.properties.*.type"
81
+ },
82
+ {
83
+ "path": "contributes.configuration.properties.*.title"
84
+ },
85
+ {
86
+ "path": "contributes.configuration.properties.*.description"
87
+ },
88
+ {
89
+ "path": "contributes.configuration.properties.*.order"
90
+ },
91
+ {
92
+ "path": "contributes.configuration.properties.*.default"
93
+ },
94
+ {
95
+ "path": "contributes.configuration.properties.*.additionalProperties.type"
96
+ },
97
+ {
98
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*"
99
+ },
100
+ {
101
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.type"
102
+ },
103
+ {
104
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.title"
105
+ },
106
+ {
107
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.description"
108
+ },
109
+ {
110
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.order"
111
+ },
112
+ {
113
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.default"
114
+ },
115
+ {
116
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.enum"
117
+ },
118
+ {
119
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.minimum"
120
+ },
121
+ {
122
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.format",
123
+ "values": [
124
+ "coda-model-provider",
125
+ "coda-model-url"
126
+ ]
127
+ },
128
+ {
129
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.writeOnly"
130
+ },
131
+ {
132
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.modelKey"
133
+ },
134
+ {
135
+ "path": "contributes.configuration.properties.*.additionalProperties.properties.*.modelApi"
136
+ },
137
+ {
138
+ "path": "contributes.setup.command"
139
+ },
140
+ {
141
+ "path": "contributes.skills[]"
142
+ },
143
+ {
144
+ "path": "contributes.commands[].name"
145
+ },
146
+ {
147
+ "path": "contributes.commands[].command"
148
+ },
149
+ {
150
+ "path": "contributes.environment.*"
151
+ },
152
+ {
153
+ "path": "contributes.views[].id"
154
+ },
155
+ {
156
+ "path": "contributes.views[].title"
157
+ },
158
+ {
159
+ "path": "contributes.views[].entry"
160
+ },
161
+ {
162
+ "path": "contributes.views[].in[]",
163
+ "values": [
164
+ "side"
165
+ ]
166
+ },
167
+ {
168
+ "path": "contributes.views[].icon"
169
+ }
170
+ ]
171
+ }
@@ -0,0 +1,100 @@
1
+ {
2
+ "revision": 1,
3
+ "entries": [
4
+ {
5
+ "path": "window.coda.platform"
6
+ },
7
+ {
8
+ "path": "window.coda.args"
9
+ },
10
+ {
11
+ "path": "window.coda.getState"
12
+ },
13
+ {
14
+ "path": "window.coda.setState"
15
+ },
16
+ {
17
+ "path": "window.coda.copy"
18
+ },
19
+ {
20
+ "path": "window.coda.open",
21
+ "targets": [
22
+ {
23
+ "view": true,
24
+ "args": true
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ "path": "window.coda.close"
30
+ },
31
+ {
32
+ "path": "window.coda.back"
33
+ },
34
+ {
35
+ "path": "window.coda.toolbar",
36
+ "fields": [
37
+ "id",
38
+ "label",
39
+ "icon",
40
+ "kind",
41
+ "on"
42
+ ],
43
+ "kinds": [
44
+ "button",
45
+ "toggle"
46
+ ]
47
+ },
48
+ {
49
+ "path": "window.coda.postMessage"
50
+ },
51
+ {
52
+ "path": "window.coda.on",
53
+ "events": [
54
+ "toolbar",
55
+ "visibility",
56
+ "back",
57
+ "theme",
58
+ "context"
59
+ ]
60
+ },
61
+ {
62
+ "path": "window",
63
+ "events": [
64
+ "message"
65
+ ]
66
+ },
67
+ {
68
+ "path": "root.classes",
69
+ "values": [
70
+ "coda-ios",
71
+ "coda-mac",
72
+ "coda-dark",
73
+ "coda-light"
74
+ ]
75
+ },
76
+ {
77
+ "path": "root.cssVariables",
78
+ "values": [
79
+ "--coda-accent",
80
+ "--coda-secondary",
81
+ "--coda-radius",
82
+ "--coda-selection",
83
+ "--coda-tertiary",
84
+ "--coda-background",
85
+ "--coda-font-size",
86
+ "--coda-card",
87
+ "--coda-orange",
88
+ "--coda-foreground",
89
+ "--coda-fill",
90
+ "--coda-separator",
91
+ "--coda-secondary-background",
92
+ "--coda-radius-card",
93
+ "--coda-outline",
94
+ "--coda-mono",
95
+ "--coda-hover",
96
+ "--coda-font"
97
+ ]
98
+ }
99
+ ]
100
+ }
@@ -182,12 +182,19 @@
182
182
  {"name": "note", "isAttr": true, "type": "String"},
183
183
  {"name": "fields", "isAttr": true, "type": "String"},
184
184
  {"name": "choices", "type": "Choice", "isMany": true},
185
- {"name": "options", "type": "Option", "isMany": true}
185
+ {"name": "options", "type": "ChoiceOption", "isMany": true}
186
186
  ]
187
187
  },
188
188
  {
189
- "name": "Option",
189
+ "name": "ChoiceOption",
190
+ "isAbstract": true,
190
191
  "superClass": ["Element"],
192
+ "description": "答复里的勾选项:一个 coda:option,或一组由 coda:optionList 在任务打开时读出的勾选项,按写的顺序排",
193
+ "properties": []
194
+ },
195
+ {
196
+ "name": "Option",
197
+ "superClass": ["ChoiceOption"],
191
198
  "description": "一个答复上可以独立勾选的附加项:default(是否默认勾上)与 shown(是否给出)都在任务打开时读;没给出的总是 false",
192
199
  "properties": [
193
200
  {"name": "id", "isAttr": true, "type": "String"},
@@ -197,6 +204,14 @@
197
204
  {"name": "default", "isAttr": true, "type": "String"}
198
205
  ]
199
206
  },
207
+ {
208
+ "name": "OptionList",
209
+ "superClass": ["ChoiceOption"],
210
+ "description": "一组勾选项:value 是表达式,任务打开时读出勾选项的列表(或它的 JSON),在它所在的位置展开",
211
+ "properties": [
212
+ {"name": "value", "isAttr": true, "type": "String"}
213
+ ]
214
+ },
200
215
  {
201
216
  "name": "Field",
202
217
  "superClass": ["Element"],
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://coda.pub/schema/bpmn/1.0/options.json",
4
+ "title": "一个答复在任务打开时的勾选项",
5
+ "description": "勾选项须为数组",
6
+ "type": "array",
7
+ "items": {"$ref": "#/$defs/option"},
8
+ "x-unique-by": ["id"],
9
+ "allOf": [{"maxItems": 12, "description": "最多 12 个勾选项"}],
10
+ "$defs": {
11
+ "option": {
12
+ "type": "object",
13
+ "properties": {
14
+ "id": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_-]{0,63}$", "description": "id 须为字母开头的字母、数字、「_」「-」"},
15
+ "name": {"type": "string", "pattern": "\\S", "maxLength": 40, "description": "name 须为 1–40 个字"},
16
+ "detail": {"type": "string", "maxLength": 200, "description": "detail 不超过 200 字"},
17
+ "default": {"type": "boolean", "description": "default 须为 true 或 false"}
18
+ },
19
+ "required": ["id", "name"],
20
+ "additionalProperties": false,
21
+ "description": "勾选项须为对象,有 id 与 name,可有 detail 与 default"
22
+ }
23
+ }
24
+ }
@@ -155,14 +155,14 @@
155
155
  "options": {"type": "array", "maxItems": 12, "x-unique-by": ["id"], "description": "最多 12 个勾选项"}
156
156
  },
157
157
  "required": ["id", "name"],
158
- "allOf": [{"description": "勾选项(coda:option)只能属于没有嵌套 choice 的外层 choice", "not": {"required": ["choices", "options"]}}]
158
+ "allOf": [{"description": "勾选项(coda:option、coda:optionList)只能属于没有嵌套 choice 的外层 choice", "not": {"required": ["choices", "options"]}}]
159
159
  },
160
160
  "NestedChoice": {
161
161
  "allOf": [{"$ref": "#/$defs/Choice"}],
162
162
  "properties": {
163
163
  "primary": {"const": false, "description": "只有最外层的选项能是主按钮"},
164
164
  "choices": {"maxItems": 0, "description": "按住出现的选项里不能再嵌套"},
165
- "options": {"maxItems": 0, "description": "勾选项(coda:option)只能属于没有嵌套 choice 的外层 choice"}
165
+ "options": {"maxItems": 0, "description": "勾选项(coda:option、coda:optionList)只能属于没有嵌套 choice 的外层 choice"}
166
166
  }
167
167
  },
168
168
  "Option": {
@@ -176,6 +176,18 @@
176
176
  },
177
177
  "required": ["id", "name"]
178
178
  },
179
+ "OptionList": {
180
+ "type": "object",
181
+ "properties": {
182
+ "value": {"type": "string", "pattern": "^\\s*=", "x-feel": true, "description": "coda:optionList 须用 value 写一个「=」开头的表达式(勾选项的列表)"}
183
+ },
184
+ "required": ["value"],
185
+ "description": "coda:optionList 须用 value 写一个「=」开头的表达式(勾选项的列表)"
186
+ },
187
+ "ChoiceOption": {
188
+ "not": {},
189
+ "description": "勾选项写 coda:option,一组读出来的勾选项写 coda:optionList"
190
+ },
179
191
  "Process.children": {
180
192
  "type": "object",
181
193
  "properties": {
package/workflow.mjs CHANGED
@@ -22,6 +22,7 @@ import values from './workflow/values.json' with { type: 'json' };
22
22
  import actions from './workflow/actions.json' with { type: 'json' };
23
23
  import dialect from './workflow/dialect.json' with { type: 'json' };
24
24
  import fields from './workflow/fields.json' with { type: 'json' };
25
+ import options from './workflow/options.json' with { type: 'json' };
25
26
  import { valueKeywords } from './workflow/keywords.mjs';
26
27
  import { structureChecker } from './workflow/structure.mjs';
27
28
  export { CODA_STRUCTURE } from './workflow/structure.mjs';
@@ -30,6 +31,7 @@ export const CODA_MODDLE = moddle;
30
31
  export const CODA_NAMESPACE = moddle.uri;
31
32
  export const CODA_VALUES = values;
32
33
  export const CODA_FIELDS = fields;
34
+ export const CODA_OPTIONS = options;
33
35
  // Each action by name, with the parameters it takes (`coda:param`).
34
36
  export const CODA_ACTIONS = Object.fromEntries(Object.entries(actions.actions).map(([name, action]) => [name, action.params]));
35
37
  export const WORKFLOW_KINDS = Object.keys(dialect.kinds);
@@ -95,6 +97,7 @@ ajv.addKeyword({
95
97
  ajv.addKeyword({ keyword: 'x-duration', type: 'string', schemaType: 'boolean', compile: spec => value => !spec || isDuration(value) });
96
98
  ajv.addKeyword({ keyword: 'x-number', type: 'string', schemaType: 'boolean', compile: spec => value => !spec || Number.isFinite(Number(value)) });
97
99
  ajv.addSchema(fields);
100
+ ajv.addSchema(options);
98
101
  ajv.addSchema(values);
99
102
  const structureProblem = structureChecker(ajv, { feelProblem, isExpression });
100
103
  const checks = new Map();
@@ -148,7 +151,7 @@ function said(error, at, attribute) {
148
151
  if (error.keyword === 'x-unique-by') return `${at}:${error.message}`;
149
152
  return `${at}:${description(error)}`;
150
153
  }
151
- const description = (error, object = {}) => (described(error, { schemas: [values, fields] }) ?? error.message)
154
+ const description = (error, object = {}) => (described(error, { schemas: [values, fields, options] }) ?? error.message)
152
155
  .replace(/\{(\w+)\}/g, (whole, key) => Object.hasOwn(error.params, key) ? String(error.params[key])
153
156
  : object && Object.hasOwn(object, key) ? String(object[key]) : whole);
154
157
  // Required values and allowed attributes come from the same schema as validation; none of the field types is named here.
@@ -181,6 +184,22 @@ export function fieldsProblem(list, where = '任务') {
181
184
  const validate = ajv.getSchema(`${values.$id}#/$defs/UserTask.children/properties/field`);
182
185
  return validate(list) ? null : `${where}:字段 id 重复:${validate.errors[0].message.slice('id 不能重复:'.length)}`;
183
186
  }
187
+ // One answer's options as the task opens: the static ones resolved and each coda:optionList read and put where it is
188
+ // written, in order. Each is an object of id, name and optionally detail and a boolean default; at most 12, ids unique.
189
+ let optionsBound;
190
+ export function optionsProblem(list, where = '答复') {
191
+ const { $id, $schema, $defs, items, 'x-unique-by': unique, ...shape } = options;
192
+ // The bound first, then each option, then uniqueness, so that what is said is about the first thing wrong.
193
+ const bound = optionsBound ??= ajv.compile(shape);
194
+ if (!bound(list)) return `${where}:${description(bound.errors[0])}`;
195
+ const validate = ajv.getSchema(`${options.$id}#/$defs/option`);
196
+ for (const [index, option] of list.entries()) {
197
+ const at = `${where} 的勾选项 ${typeof option?.id === 'string' && option.id ? option.id : index + 1}`;
198
+ if (!validate(option)) return `${at}:${description(validate.errors[0], option)}`;
199
+ }
200
+ const all = ajv.getSchema(options.$id);
201
+ return all(list) ? null : `${where}:勾选项的 ${all.errors[0].message}`;
202
+ }
184
203
  // What of the coda: values in the definition its schemas do not take, or null: each element in order, its coda:
185
204
  // attributes by each type of Coda's extending what it is, the coda: elements it holds by kind, and each coda: element.
186
205
  function valuesProblem(root) {