@coda-console/protocol 6.1.0 → 6.3.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,21 @@
2
2
 
3
3
  版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 6.3.0 — 2026-11-15
6
+
7
+ - 这是在 6.2.0 之上的次版本(6.2.0 见下)。
8
+ - 不兼容:删去 Coda A3-3-0(coda#2641)已经删掉的能力的声明。依据 README「版本」一节:协议定义与流程方言是内部面,删改升次版本(6.2.0 是 failure.json 加 `auth_required`,见 #58)。
9
+ - 流程方言删去 `coda:reportTo`、`coda:reportOn`(moddle、取值校验与「reportOn 必须配 reportTo」、结构校验里的分支)和 `coda:placement`(`PlacementProperties`);写了它们的流程读时按认不出的属性拒绝。定时开始事件的 `coda:scope` 及其只写在定时开始事件上的约束不变。
10
+ - `coda/executor@1` 删去操作 `execute`(连同它的 `$defs`:源码快照 `git/snapshot@1`、`source` 输入等),现在没有操作;spec、status、`EXECUTOR_PROTOCOL` 与 `CORE_PROTOCOLS` 里的登记不变。
11
+ - 删去 `schemas/protocol/v1/remote-caller.json`(记录的远端入口,含 `file_ticket`)与 `docs/protocol.md` 里的对应正文。
12
+ - `coda/session@1` 的 `post`、`draft`,以及 `coda:runsOn`、`coda:source`、`group`、`hold-group`、`coda/run@1` 都保留;`coda:runsOn` 的说明改成:对本机执行环境的要求,不符合就一开始失败,不会把步骤交给别台。
13
+
14
+ ## 6.2.0 — 2026-11-14
15
+
16
+ - Agent 的执行失败类别(`schemas/agent/failure.json`)加 `kind: auth_required`:Agent 的登录凭据失效(OAuth 令牌过期或被撤销),须用户重新登录才能继续;可带可选的 `login`(1 到 200 字,指出要重新登录的账号或登录方式),不带 `input`、`retryAfterMs`、`resetAt`,带了也不检查。`docs/agent-protocol.md` 的「执行失败」写清三类的用途:`service_unavailable` 会自己好,Coda 退避后在同一会话续;`quota_exhausted` 到恢复时间再续;`auth_required` 提醒用户重新登录,登录后续;额度不足与要重新登录两类本轮内不即时重试、也不进入服务故障重试,之后的续跑由 Coda 在同一会话里决定;并写明什么时候该报它、什么时候不该报(API key 配错、权限不足仍是普通错误)。握手阶段回 -32000 的「未登录」不变。新增类别与可选字段,旧插件不受影响(Coda #2642)。
17
+ - 额度不足(`kind: quota_exhausted`)可带可选的 `input`(`accepted` 或 `not_accepted`),含义与何时报同 `service_unavailable`(`accepted` 是输入已经进入原生会话,`not_accepted` 是明确拒绝、输入尚未进入原生会话,无法确定就省略);写了就校验取值,写别的值校验不过。Coda 只用它决定续跑时发什么(`not_accepted` 重发原输入,`accepted` 接着做,没报按不确定处理:带上原输入、先核对再接着做),不会因它进入服务故障重试;`retryAfterMs` 仍不采用。可选字段,旧发送端可不写、旧接收端可忽略。
18
+ - 动作 `send-session` 加可选参数 `resumes`(要续跑的那条输入的 ID,须是 `session` 指定的会话、不写就是运行所属的会话里的输入)与 `how`(`original` 原样重发那条输入的完整内容,`verify` 先核对已经做了什么、再接着做,同样带上完整内容;只写 `resumes` 时按 `original`):写了 `resumes` 时 `text` 只是存在会话里给人看的一句短说明,发给 Agent 的是那条输入的完整内容(附件、引用都在),不再抄成一条新消息的文字(Coda quota-resume 流程)。`actions.json` 的动作加两种约束:`requires`(写了某参数就须写它列出的参数)与 `enum`(某参数写成文字时的取值,表达式与 `{{ … }}` 不查),读流程时检查:`how` 须与 `resumes` 一起写,且只能是 `original` 或 `verify`;`resumes` 是否这个会话里的输入由实现方在运行时检查。只加参数与约束,已有流程不变。
19
+
5
20
  ## 6.1.0 — 2026-11-14
6
21
 
7
22
  - 卡片字段加多选 `choices`(输入字段,须有 `id`、`label`,`required` 默认 true,表示至少勾一项):`options` 是选项表,`default` 是初始勾上的选项 id,两者都是内容属性,可写表达式在任务打开时读,读出(或写下)的是 JSON 数组或它的文字。选项 `{ id, label, detail?, disabled? }`:`id` 一行、1–64 个字、前后不带空白、表中不重复,`label` 一行、1–80 个字、前后不带空白,`detail` 一行不超过 200 字,`disabled` 为 true 的列出但不能勾;1–32 项,至少一项能勾。`default` 的 id 不重复,每个须是 options 里能勾的一项(两者都已知时读流程就查)。答复是勾中项的 id 组成的数组,按 options 的顺序,在 `answer.values.<id>` 里交来,流程读 `=<任务>.values.<id>`(FEEL 列表),`filled.<id>` 为勾了至少一项。choices 是输入字段:答复的 `fields` 可以引用它,带它的任务只交给用户(`structure.json` 的 `inputFields` 加上它)。moddle 的 `coda:field` 加属性 `options`。
package/README.md CHANGED
@@ -22,7 +22,7 @@ Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
22
22
 
23
23
  输入字段有 `text`、`secret` 与多选 `choices`。`choices` 的 `options` 是选项表,每项 `{ id, label, detail?, disabled? }`(`id` 一行、1–64 个字、前后不带空白、表中不重复,`label` 一行、1–80 个字、前后不带空白,`detail` 一行不超过 200 字,`disabled` 为 true 的列出但不能勾),1–32 项,至少一项能勾;`default` 是初始勾上的选项 id,每个须是 options 里能勾的一项,不写就是都不勾;两者都可写表达式在任务打开时读,读出(或直接写下)的是 JSON 数组或它的文字。`required`(默认 true)要求至少勾一项。答复是勾中项的 id 组成的数组,按 options 的顺序,在答复的 `values.<id>` 里(其余输入是文字,它是数组),流程读 `=<任务>.values.<id>`,是 FEEL 列表;它不认识机器或别的什么,选项的意思由给出它的步骤定(如 `check-setting` 的 `machines`)。
24
24
 
25
- 脚本步骤的 **工作副本** 由 `coda:source` 声明:这一步在哪个工作副本目录里跑,写本机上的绝对路径,可以写 FEEL 表达式。它只用于 `coda:checkout="false"` 的步骤:在本机跑就在那个目录里就地跑,不检出提交;交给别的执行环境时,由调用方给这个目录所在的工作副本拍快照(含未提交、未跟踪的改动,不含忽略的文件),对方检出快照、在对应的子目录里跑。协议里 `coda/executor@1` 的 `execute` 输入已有 `source.snapshot` 与 `workingDirectory`,交给别台时就用这两项,执行器协议本身不改。
25
+ 脚本步骤的 **工作副本** 由 `coda:source` 声明:这一步在哪个工作副本目录里跑,写本机上的绝对路径,可以写 FEEL 表达式。它只用于 `coda:checkout="false"` 的步骤:在那个目录里就地跑,不检出提交。
26
26
 
27
27
  定义和运行时共用这一份 schema。`x-deferred` 包住一个 schema:读定义时,文字先检查 FEEL,表达式或含 `{{ … }}` 的模板留到打开任务后查;运行时只按包住的 schema 严格检查,不再把结果当表达式。只有内容属性使用它,`type`、`id`、布尔值、枚举和 `maxLength` 不放宽。另有 `x-length`(沿用 Coda 的 UTF-16 长度,可用 `{ "property": "maxLength" }` 读取同一对象的上限)、`x-json`(解析 JSON 文字或检查 JSON 值,按序列化后的 UTF-8 字节数限制大小)、`x-among`(`{ property, key, match? }`:数组的每一项是同一对象里 `property`(数组或它的 JSON 文字)某一项的 `key`,且那一项合乎 `match`;`property` 还是定义里的表达式时不查);`absolute-path`、`https-url`、`link-url` 三个 format 按本机路径与 URL 解析器检查;`link-url` 接受 https 网址或 `action=download-manifest` 且 `url` 解码后为 https 网址的 `itms-services:` 安装链接。已有的 `x-ref` 增加 `key`(按数组元素的属性引用)和 `split`(逐个检查分隔后的名字)。这些操作都不改写输入。
28
28
 
@@ -61,7 +61,7 @@ protocolShortName('coda/run@1'); // 'coda-1run-21'
61
61
  definitionProblem(RUN_PROTOCOL); // null,或说明
62
62
  ownedProtocolsProblem(manifest); // contributes.protocols 只能在自己的命名空间下
63
63
  runStatusProblem({ state: 'completed', result: null }, { state: 'working' }); // 终态不能再变
64
- invocationRequestProblem({ record: { kind: 'coda/executor@1', id: 'host' }, operation: 'execute', input: {},
64
+ invocationRequestProblem({ record: { kind: 'coda/session@1', id: 'chat-1' }, operation: 'post', input: { text: 'hi' },
65
65
  requestId: 'r1', parent: { kind: 'coda/run@1', id: 'caller-run' }, awaited: true });
66
66
  invocationResponseProblem({ run: { kind: 'coda/run@1', id: 'run-1' } });
67
67
  ```
@@ -131,7 +131,7 @@ agentValueProblem('review.json', review, '工具的审核');
131
131
  命名空间 `coda` 保留给核心协议。
132
132
 
133
133
  - **`coda/run@1`**:被调用方自己的运行记录。spec 记录调用的记录、操作、输入、请求 ID、父引用和是否被等待;status 是 `working`、`input-required`、`completed`、`failed`、`canceled`,后三个是终态。`completed`/`failed` 必带 `result`,`failed` 的 `result` 约定为 `{ code, message }`(`code: "unknown"` 表示结局不明),`canceled` 可带取消前的话和留下的东西;另有可选的 `progress` 和等输入时的 `awaiting`。操作是 `cancel`。
134
- - **`coda/executor@1`**:执行器。操作 `execute` 接一份执行工作并返回运行引用,运行记录在执行器那边;没有 `target`、`executor` 或 `assignmentId` 绑定,也不回写调用方的记录。
134
+ - **`coda/executor@1`**:执行器,一台机器上的执行环境。spec 是配置意图,status 是持有端观察到的事实;没有操作。
135
135
  - **`coda/agent@1`**:Agent 资源,复数名 `agents`;spec 照 Coda 的 Agent 资源(`agent`、`title`、`plugin?`、`defaultModel`、`models`、`modes` 等),`plugin` 是提供 Agent 程序的插件、不是记录的 provider;status 为空对象;操作 `spawn`(`run: true`)开一个子会话。
136
136
  - **`coda/session@1`**:插件提供的外部会话。spec 是标题、容器和可选的环境引用;status 是 `head` 游标、参与者(可带头像 `avatar`)与 `post` 收不收语音(`accepts`);操作 `read`(`safe`)与 `draft`(`idempotent`)是立即结果,`post` 开运行;撤回、编辑、表情是用 `about` 指向旧消息的新消息。
137
137
  - **`coda/environment@1`**:插件提供的只读外部环境。spec 带 `actions`;操作 `list` 列目录、`read` 读文件(一次至多 1 MiB)。
@@ -164,7 +164,7 @@ Coda 与检查包都钉一个确切版本。对第三方的兼容承诺只覆盖
164
164
 
165
165
  协议自己的大版本写在协议名里(`coda/run@1`);同一大版本只加可选字段和新操作,改含义或删东西升大版本,新旧可并存。
166
166
 
167
- 3.0.0 删除了 `executor` 与 `execution`,并把执行请求并入 `coda/executor@1` 的 `execute`;这是不兼容变更,旧代码须改用 `@coda-console/protocol/protocol` 与 `coda/run@1`。
167
+ 3.0.0 删除了 `executor` 与 `execution`;这是不兼容变更,旧代码须改用 `@coda-console/protocol/protocol` 与 `coda/run@1`。
168
168
 
169
169
  改协议就在这里开 PR,说明写清动了哪个类型、旧插件受不受影响;发布后 Coda 与检查包各自升依赖。
170
170
 
@@ -44,7 +44,7 @@ Coda 过去静默丢弃的值,契约检查现在可得到具体位置;过去
44
44
  不把原始输入拼入错误(避免巨大值或深层对象导致报错本身失败)。
45
45
 
46
46
  **校验不是整理或运行状态判断**:审核未知 `risk` 不影响整条审核有效,宿主仍只保存 `$defs/risk` 接受的值;
47
- 额度不足按 `kind` 判断,可选的 `resetAt` 须符合下文的 UTC 时间格式,不校验也不采用它附带的 `input`/`retryAfterMs`;压缩答复的未知字段照样允许,
47
+ 额度不足按 `kind` 判断,可选的 `resetAt` 须符合下文的 UTC 时间格式,可选的 `input` 须是 `accepted` 或 `not_accepted`,不校验也不采用它附带的 `retryAfterMs`;压缩答复的未知字段照样允许,
48
48
  宿主仍只保存已知字段、裁剪原因,畸形答复仍按原有兜底处理,不应把整个答复的校验失败改成执行失败。
49
49
  压缩的 `before`/`after` 沿用有限数要求,不新增整数或非负限制。能力声明 schema 描述对象声明,
50
50
  不代替能力探测:未声明、不合法的声明仍按宿主原有方式处理(旧 `supportsRemote` 还把数组视为声明,不能直接用 schema 替换该谓词)。
@@ -155,16 +155,30 @@ Coda 使用的形状见 [steering.json](../schemas/agent/steering.json);`promp
155
155
  `session/prompt` 的 JSON-RPC 错误通过 `error.data._meta.coda.failure` 报告类别。标准 `error.message` 保留可读的失败原因;
156
156
  其他 ACP 客户端可以忽略扩展。未标记、未知或不合格式的类别按普通错误处理,不自动重试。
157
157
 
158
+ 三个类别说的是故障的性质,Coda 据此决定怎么恢复:
159
+
160
+ | 类别 | 性质 | Coda 的恢复 |
161
+ | --- | --- | --- |
162
+ | `service_unavailable` | 服务端暂时故障,会自己好 | 退避后在同一会话续 |
163
+ | `quota_exhausted` | 额度用尽,要等重置或补额度 | 到恢复时间再续 |
164
+ | `auth_required` | 登录凭据失效,要用户重新登录 | 提醒用户重新登录,登录后续 |
165
+
166
+ 责任分两段。本轮内:插件报类别并结束本轮;额度不足、要重新登录两类不即时重试,也不进入服务故障重试,服务暂不可用才按下文在本轮内即时重试。
167
+ 之后:由 Coda(发起这次工作的一方)决定什么时候续、怎么续,在同一会话里续;服务暂不可用重试用尽后同样如此。协议只约定插件报什么、本轮怎么结束。
168
+
158
169
  ### 额度不足
159
170
 
160
171
  `kind: quota_exhausted` 表示可用额度已耗尽,例如订阅用量窗口已满或余额不足。插件须有明确的上游原因,不能仅凭 HTTP 403、
161
- HTTP 429 或上游的认证错误分类判断。真正的认证失败仍沿用 ACP `auth_required`,不得报为额度不足。
172
+ HTTP 429 或上游的认证错误分类判断。认证失败按[需要重新登录](#需要重新登录)或握手阶段的 ACP `auth_required` 报告,不得报为额度不足。
162
173
 
163
174
  ```json
164
175
  {"jsonrpc":"2.0","id":"prompt-1","error":{"code":-32603,"message":"当前用量窗口的额度已耗尽,<t:2026-10-24T18:10:00.000Z> 重置","data":{"_meta":{"coda":{"failure":{"kind":"quota_exhausted","resetAt":"2026-10-24T18:10:00.000Z"}}}}}}
165
176
  ```
166
177
 
167
- Coda 按该类别显示「额度不足」,保留完整原因,不安排自动重试;这个类别不要求 `input`,即使带了也不进入服务故障重试。
178
+ Coda 按该类别显示「额度不足」,保留完整原因;本轮内不即时重试,也不进入服务故障重试,之后由 Coda 到 `resetAt` 在同一会话续(没有 `resetAt` 时按 Coda 自己的间隔再试)。
179
+ 可选 `input`(`accepted` 或 `not_accepted`)含义与何时报沿用[服务暂不可用](#服务暂不可用)里 `input: accepted`、`input: not_accepted` 的定义:`accepted` 是输入已经进入原生会话;`not_accepted` 是明确拒绝,输入尚未进入原生会话;无法确定就省略。
180
+ Coda 只用它决定续跑时发什么——`not_accepted` 重发原输入,`accepted` 从已有进度接着做,没报则按「不确定」处理,带上原输入、先核对已经做了什么再接着做;
181
+ 它不会让额度不足进入服务故障重试。`retryAfterMs` 不采用。
168
182
  该回执确认本轮因额度不足而结束,轮次记为 `ended`、`stopReason: quota_exhausted` 并保留 `error`,操作记为 `completed`;
169
183
  操作已结算不代表任务成功,子会话向调用方交回 `failed`。两端同一原因只显示一次,不再标作「执行结果未知」。
170
184
  交回 `failed` 的状态文案为「失败」,涵盖准备与执行阶段。调用结清前,后续轮次的额度错误仍连同原因算进这次调用的结果,即使没有正文或还有其他活动在等;结清后不再另交。
@@ -174,6 +188,24 @@ Coda 按该类别显示「额度不足」,保留完整原因,不安排自动
174
188
  上游没有给出确切时间时省略,不推算时间。该字段是兼容扩展:旧发送端可不写,旧接收端可忽略;不改变失败类别或服务故障重试语义。
175
189
  恢复条件(等待窗口重置、补充额度等)仍由插件放在原因中,重置时刻按[文字里的时刻](#文字里的时刻)写。
176
190
 
191
+ ### 需要重新登录
192
+
193
+ `kind: auth_required` 表示 Agent 的登录凭据已失效,须用户重新登录才能继续,例如 OAuth 令牌过期或被撤销、会话被上游登出。
194
+ 这是 `session/prompt` 执行中的失败,与握手阶段的「未登录」(`initialize`、`session/new`、`session/load` 回 -32000)不同:
195
+ 后者是还没登录,这里是执行中途登录失效。插件以普通执行错误返回(例如 -32603),不要回 -32000。
196
+
197
+ ```json
198
+ {"jsonrpc":"2.0","id":"prompt-1","error":{"code":-32603,"message":"登录已过期,请重新登录","data":{"_meta":{"coda":{"failure":{"kind":"auth_required","login":"ChatGPT 账号"}}}}}}
199
+ ```
200
+
201
+ - 插件**该**报它:上游明确表明登录凭据过期或被撤销,重新登录能解决(如刷新令牌失效、令牌被撤销)。
202
+ - 插件**不该**报它:API key 配错或缺失、权限不足、套餐或模型无权使用这类配置错误,重新登录解决不了,仍按未标记的普通错误报告;
203
+ 额度耗尽按[额度不足](#额度不足)、服务故障按[服务暂不可用](#服务暂不可用)报告。不能仅凭 HTTP 401 或 403 判断,须有上游明确的凭据失效原因。
204
+ - 可选 `login`:1 到 200 字的文本,指出要重新登录的账号或登录方式,例如 `ChatGPT 账号`、`Anthropic OAuth`;不知道时省略。
205
+ 只作显示,Coda 不据此选择登录方式。
206
+ - 不带 `input`、`retryAfterMs`、`resetAt`:带了也不检查,不影响处理。本轮内不即时重试,也不进入服务故障重试;之后由 Coda 提醒用户重新登录,登录后在同一会话续。
207
+ - 错误文字始终放在标准 `error.message`,写明失效的原因;其他 ACP 客户端可以忽略扩展。
208
+
177
209
  ### 服务暂不可用
178
210
 
179
211
  插件负责识别服务端临时故障;**重试策略归 Coda**,不依赖 Agent 名字、错误文字或私有上游错误码。
@@ -183,7 +215,7 @@ Coda 按该类别显示「额度不足」,保留完整原因,不安排自动
183
215
  {"jsonrpc":"2.0","id":"prompt-1","error":{"code":-32603,"message":"服务暂不可用","data":{"_meta":{"coda":{"failure":{"kind":"service_unavailable","input":"accepted"}}}}}}
184
216
  ```
185
217
 
186
- - `kind: service_unavailable`:服务端暂时无法处理;额度耗尽、未登录、配置或参数错误不得这样报告。
218
+ - `kind: service_unavailable`:服务端暂时无法处理;额度耗尽、需要重新登录、配置或参数错误不得这样报告。
187
219
  - `input: accepted`:输入已经进入原生会话;故障回执确认本次原生执行已结束。Coda 在同一会话发送从已有进度继续的指令。
188
220
  - `input: not_accepted`:明确拒绝,输入尚未进入原生会话,也没有执行它的操作。仅当原输入从未被接收时重投相同内容与附件;已有接收证据(包括已保存的 `delivered`)时只续跑。
189
221
  - 可选 `retryAfterMs`:上游要求或原生 Agent 实际安排的剩余等待,单位毫秒,须为非负有限数;不是预计恢复时间。
@@ -412,7 +444,7 @@ Coda 封装的 Agent 会自己长出新能力:上游 Agent 升级、服务端
412
444
 
413
445
  ## 远端入口
414
446
 
415
- 本节是 Agent 会话的旧入口,随所有机器上的 grok-bot 0.4.0 卸载一起退役;新的外部会话用[记录的远端入口](protocol.md#记录的远端入口)。
447
+ 本节是 Agent 会话的旧入口,随所有机器上的 grok-bot 0.4.0 卸载一起退役。
416
448
 
417
449
  绑定码与转交请求的形状分别见 [remote-code.json](../schemas/agent/remote-code.json)、[remote.json](../schemas/agent/remote.json)。
418
450
 
package/docs/protocol.md CHANGED
@@ -9,7 +9,7 @@
9
9
  - 六个核心协议:`coda/run@1`、`coda/executor@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1`、`coda/card@1`;
10
10
  - 插件清单里的 `contributes.protocols` 与 `contributes.protocolImplementations`。
11
11
 
12
- `executor` 与 `execution` 两个旧对象协议和 `@coda-console/protocol/executor` 在 3.0.0 删除;`execution` 的输入并入 `coda/executor@1` 的 `execute` 操作,运行由 `coda/run@1` 表达。
12
+ `executor` 与 `execution` 两个旧对象协议和 `@coda-console/protocol/executor` 在 3.0.0 删除。
13
13
 
14
14
  ## 名字
15
15
 
@@ -133,15 +133,15 @@ definitionProblem(definition, { namespace: 'my-plugin' }); // 同时核对命名
133
133
 
134
134
  ## 调用信封
135
135
 
136
- 记录引用 `{ kind, id }` 的 `kind` 是协议名,如 `coda/run@1`、`coda/executor@1`、`git/snapshot@1`、`git/source@1`;`id` 是记录的不透明 ID。Coda 自己还没定义成协议的东西(会话、流程运行等)暂用它现有的资源种类名,如 `threads`、`workflow-runs`,等后续定义成协议再改用协议名。
136
+ 记录引用 `{ kind, id }` 的 `kind` 是协议名,如 `coda/run@1`、`coda/session@1`、`git/source@1`;`id` 是记录的不透明 ID。Coda 自己还没定义成协议的东西(会话、流程运行等)暂用它现有的资源种类名,如 `threads`、`workflow-runs`,等后续定义成协议再改用协议名。
137
137
 
138
138
  一次调用是:
139
139
 
140
140
  ```json
141
141
  {
142
- "record": {"kind": "coda/executor@1", "id": "host"},
143
- "operation": "execute",
144
- "input": {"task": {"command": "npm", "args": ["test"]}},
142
+ "record": {"kind": "coda/session@1", "id": "chat-1"},
143
+ "operation": "post",
144
+ "input": {"text": "构建通过了"},
145
145
  "requestId": "request-1",
146
146
  "parent": {"kind": "coda/run@1", "id": "caller-run"},
147
147
  "awaited": true
@@ -232,9 +232,9 @@ status:
232
232
  ```json
233
233
  {
234
234
  "spec": {
235
- "record": {"kind": "coda/executor@1", "id": "host"},
236
- "operation": "execute",
237
- "input": {"task": {"command": "npm", "args": ["test"]}},
235
+ "record": {"kind": "coda/session@1", "id": "chat-1"},
236
+ "operation": "post",
237
+ "input": {"text": "构建通过了"},
238
238
  "requestId": "request-1",
239
239
  "parent": {"kind": "coda/run@1", "id": "parent-run"},
240
240
  "awaited": true
@@ -247,7 +247,7 @@ status:
247
247
 
248
248
  一台机器上的执行环境。记录格式取自 3.0.0 之前的 `executor`,版本改由协议名表达,spec 不再写 `protocolVersion`:spec 是 `enabled`、`capacity`、`labels` 和可选的 `title`;status 是探测到的标签、能力、容量与占用、`accepting`、观察时间和 `executionFeatures`。空 status `{}` 表示尚未观察到。
249
249
 
250
- 操作 `execute` 的输入是一份执行工作:`source`、`requirements`、`resources`、`exclusiveResources`、`context`、`task`、`workingDirectory`、`env`、`timeoutMs`、`cancelGraceMs`。它返回 `{ run: { kind, id } }`,运行记录由执行器持有。不再有 `target`、`executor` 或 `assignmentId` 绑定,也不回写调用方的记录;取消走运行记录的 `cancel` 操作。
250
+ 本协议没有操作:执行环境由持有它的机器自己维护,调用方不能经协议把一份工作交给它。脚本步骤的 `coda:runsOn` 只是对本机执行环境的要求,不符合就一开始失败,不会把步骤交给别台。
251
251
 
252
252
  ```json
253
253
  {
@@ -451,68 +451,6 @@ status:
451
451
  }
452
452
  ```
453
453
 
454
- ### 记录的远端入口
455
-
456
- 外部会话里的一位参与者(如跑在别处的 Grok Bot)以这条 `coda/session@1` 记录的身份调 Coda。令牌只通往这条记录,不是设备凭据,不能进入其他接口。
457
- Coda 直接处理请求,不经 Agent 进程;调用信封的 `parent` 是 `{ kind: "coda/session@1", id: <记录 ID> }`,见[调用信封](#调用信封)。请求不能另指定调用方。
458
- 形状见 [remote-caller.json](../schemas/protocol/v1/remote-caller.json):顶层校验调用正文,`$defs` 给出绑定、各方法结果及错误;`date-parse` 格式同旧入口,按 `Date.parse` 能否读出时间校验。
459
-
460
- #### 绑定
461
-
462
- Provider 为自己 provide 的记录向 Coda 申请一次性绑定码,只能为自己的记录申请,且须实现 `coda/session@1`。插件侧的 API 由 Coda 定义。
463
- 回 `{ code, expiresAt, addresses }`:码 10 分钟有效,`expiresAt` 是到期时间;`addresses` 同旧入口,是这台后端在 tailnet 里的入口(`http://<节点地址>:8080`),不在 tailnet 时为空。
464
- 远端以 `POST /v1/remote-caller/bind`、正文 `{ code }` 换得 `{ token, record }`,`record` 是记录 ID。无需凭据,每分钟最多 30 次,码成功兑换后失效。
465
- 同一条记录再绑定,新令牌取代旧的;幂等请求归记录,不随令牌更换重置。
466
-
467
- #### 调用
468
-
469
- `POST /v1/remote-caller`,头 `Authorization: Bearer <token>`,正文 `{ method, params }`,成功回 `{ result }`。调用正文至多 256 KiB;绑定正文同旧入口至多 4 KiB,`code` 为 1 到 128 个字符。
470
- `params` 是对象;只有 `hello` 可省略,等同 `{}`。
471
-
472
- | method | params | result |
473
- | --- | --- | --- |
474
- | `hello` | `{}` | `{ record, machine, tools, workflows }`:记录 ID、所在机器 ID、可用的只读工具名数组、工单白名单 |
475
- | `tool` | `{ name, arguments }` | 同名 MCP 工具的回答,原样放进 `result` |
476
- | `file_ticket` | `{ workflow, project?, inputs, requestId }` | `{ run, reused? }`;`run` 为 `{ kind: "workflow-runs", id }`,按运行主键复用时带 `reused: true` |
477
-
478
- `tool.name` 只收 `machines`、`machine_diagnostics`、`read_thread`、`read_tool_call`、`workflow_list`、`workflow_status`;`arguments` 是参数对象。
479
- 参数与回答照 Coda 的同名 MCP 工具,见[搜索与 Agent 工具](https://github.com/coda-console/coda/blob/main/docs/peers.md#搜索与-agent-工具)和[流程文档](https://github.com/coda-console/coda/blob/main/docs/workflows.md),这里不复制它们的 schema。
480
- `hello.tools` 只列本机可用的上述工具。查工单用 `workflow_status`,不另设方法。
481
-
482
- 工单白名单是 `{ project, workflow }` 的列表,存在 Coda 侧、由用户给定;怎么配置由 Coda 定义,`hello.workflows` 返回这份列表,没有就返回 `[]`。
483
- `project` 是这台机器上登记的目录 ID,`workflow` 是流程名。`file_ticket` 省略 `project` 时,按 `workflow` 在白名单里找唯一一项;没有匹配就拒绝,多项匹配就要求填写 `project`。
484
- 写了 `project` 时须与白名单的目录 ID 精确匹配。`inputs` 是流程输入对象,按流程自己的输入契约校验。
485
- Coda 以记录为 `parent`、`awaited: true` 发起流程;入口不额外出批准卡片,需要批准由流程决定。
486
-
487
- `requestId` 是 1 到 200 个字符的不透明字符串,按调用方记录区分。同一记录、同一 `requestId`、同一内容重发,返回首次受理的同一结果,不重复开运行;换内容则报冲突。
488
- 内容按受理时确定的 `project`、`workflow` 和 `inputs` 比较;省略项目的重试沿用首次受理的项目。重试仍须通过记录有效性和当前白名单检查。
489
- 不同 `requestId` 报同一问题,由流程的[运行主键](https://github.com/coda-console/coda/blob/main/docs/workflows.md#运行主键)复用未结束的运行,回原运行和 `reused: true`;不改原运行的调用方,不接管它的结果通知。
490
-
491
- #### 结果交付
492
-
493
- 运行结束(成功或失败)时,照流程的[通知规则](https://github.com/coda-console/coda/blob/main/docs/workflows.md#通知)把结论交给调用方;取消不通知,第一版不推中途状态。
494
- 调用方是 Coda 会话时,给它追加一条叫醒的消息;调用方是 `coda/session@1` 记录时,对这条记录调一次 `post`。这是同一条规则在两种会话上的交付。
495
- 发送者照 `post` 的规定是 `self`,不冒充 Bot;输入的 `text` 是运行的结论:成功用结束事件的输出,没有声明输出时沿用流程通知的步骤输出;失败写失败的步骤和原因。
496
- `post` 信封的 `requestId` 由运行 ID 与轮次派生,同一运行每轮只发一次,交付重试使用同一个值;不按每次提工单的 `requestId` 各发一条。
497
-
498
- #### 拒绝
499
-
500
- HTTP 错误正文是 `{ error: { code, message } }`,`message` 是给人看的原因,`code` 用下划线命名:
501
-
502
- | HTTP | code | 原因 |
503
- | --- | --- | --- |
504
- | 400 | `invalid_input` | JSON、方法或参数不合契约;项目有歧义;流程输入不合法 |
505
- | 401 | `unauthorized` | 调用令牌缺失、无效或已被新令牌取代 |
506
- | 401 | `unauthorized` | 绑定码不存在、过期或已用过 |
507
- | 403 | `forbidden` | 工具不在六个允许的名字中,或流程不在记录的白名单中 |
508
- | 409 | `invalid_state` | 记录不存在、已删除,或它的 Provider 已不实现 `coda/session@1`;兑换绑定码时也检查 |
509
- | 409 | `request_conflict` | 同一记录的 `requestId` 用了不同内容 |
510
- | 413 | `invalid_input` | 正文超过对应入口的上限 |
511
- | 429 | `rate_limited` | 绑定超过每分钟 30 次 |
512
- | 503 | `unavailable` | 允许的工具暂不可用,或流程尚未受理就暂时无法发起 |
513
-
514
- 不在允许列表的工具名回 403,其他正文校验错误回 400。工具自身的业务错误仍按 MCP 工具回答放在 `result` 里;已受理运行的失败经运行状态和结果交付报告,不改成 HTTP 错误。
515
-
516
454
  ## coda/environment@1
517
455
 
518
456
  插件提供的外部环境,比如别家 Agent 自带的云主机。本版本只读。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "6.1.0",
3
+ "version": "6.3.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -7,9 +7,10 @@
7
7
  "kind": {
8
8
  "enum": [
9
9
  "quota_exhausted",
10
- "service_unavailable"
10
+ "service_unavailable",
11
+ "auth_required"
11
12
  ],
12
- "description": "kind 只能是 quota_exhausted 或 service_unavailable"
13
+ "description": "kind 只能是 quota_exhausted、service_unavailable 或 auth_required"
13
14
  }
14
15
  },
15
16
  "required": [
@@ -49,14 +50,46 @@
49
50
  },
50
51
  "else": {
51
52
  "type": "object",
52
- "properties": {
53
- "resetAt": {
54
- "type": "string",
55
- "format": "date-parse",
56
- "pattern": "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d{1,9})?Z$(?![\\s\\S])",
57
- "description": "resetAt 须为 UTC ISO 8601 时间字符串(以 Z 结尾),表示上游给出的额度预计重置时间;没有确切时间时不写"
53
+ "if": {
54
+ "properties": {
55
+ "kind": {
56
+ "const": "auth_required"
57
+ }
58
+ },
59
+ "required": [
60
+ "kind"
61
+ ],
62
+ "type": "object"
63
+ },
64
+ "then": {
65
+ "type": "object",
66
+ "properties": {
67
+ "login": {
68
+ "type": "string",
69
+ "minLength": 1,
70
+ "x-length": 200,
71
+ "description": "login 须为 1 到 200 字的文本,说明要重新登录的账号或登录方式"
72
+ }
73
+ }
74
+ },
75
+ "else": {
76
+ "type": "object",
77
+ "properties": {
78
+ "input": {
79
+ "enum": [
80
+ "accepted",
81
+ "not_accepted"
82
+ ],
83
+ "description": "input 只能是 accepted 或 not_accepted"
84
+ },
85
+ "resetAt": {
86
+ "type": "string",
87
+ "format": "date-parse",
88
+ "pattern": "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d{1,9})?Z$(?![\\s\\S])",
89
+ "description": "resetAt 须为 UTC ISO 8601 时间字符串(以 Z 结尾),表示上游给出的额度预计重置时间;没有确切时间时不写"
90
+ }
58
91
  }
59
92
  }
60
93
  },
61
- "$comment": "quota_exhausted 不检查 input 或 retryAfterMs;service_unavailable 不检查 resetAt。"
94
+ "$comment": "quota_exhausted 的 input 可选,写了就须是 accepted 或 not_accepted,不检查 retryAfterMs 或 login;service_unavailable 不检查 resetAt 或 login;auth_required 只检查可选的 login,不检查 input、retryAfterMs 或 resetAt。"
62
95
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "coda/executor@1",
3
3
  "title": "执行器",
4
- "description": "一台机器上执行脚本步骤的环境。execute 接下一份工作,返回执行器自己开出的 coda/run@1 运行引用;执行器不写调用方的记录,也没有 target 绑定。",
4
+ "description": "一台机器上执行脚本步骤的环境:记录它的配置意图(spec)与持有端观察到的事实(status);没有操作。",
5
5
  "spec": {
6
6
  "$schema": "https://json-schema.org/draft/2020-12/schema",
7
7
  "type": "object",
@@ -140,140 +140,5 @@
140
140
  ],
141
141
  "description": "空对象表示未知;非空为持有端最近观察到的事实,不是在线或预留保证"
142
142
  },
143
- "operations": {
144
- "execute": {
145
- "description": "接下一份执行工作,返回执行器自己开出的运行引用。",
146
- "input": {
147
- "$schema": "https://json-schema.org/draft/2020-12/schema",
148
- "type": "object",
149
- "$defs": {
150
- "opaqueId": {"type": "string", "minLength": 1, "maxLength": 2048},
151
- "resourceRef": {
152
- "type": "object",
153
- "properties": {"kind": {"type": "string", "minLength": 1, "maxLength": 128}, "id": {"$ref": "#/$defs/opaqueId"}},
154
- "required": ["kind", "id"],
155
- "additionalProperties": false
156
- },
157
- "snapshotRef": {
158
- "type": "object",
159
- "properties": {"kind": {"const": "git/snapshot@1"}, "id": {"$ref": "#/$defs/opaqueId"}},
160
- "required": ["kind", "id"],
161
- "additionalProperties": false
162
- },
163
- "repositoryRef": {
164
- "type": "object",
165
- "properties": {"kind": {"const": "git/source@1"}, "id": {"$ref": "#/$defs/opaqueId"}},
166
- "required": ["kind", "id"],
167
- "additionalProperties": false
168
- },
169
- "labels": {
170
- "type": "array",
171
- "items": {"type": "string", "minLength": 1, "maxLength": 40, "pattern": "^[a-z0-9][a-z0-9._-]*$(?![\\s\\S])"},
172
- "maxItems": 64,
173
- "uniqueItems": true
174
- },
175
- "resourceName": {
176
- "type": "string",
177
- "pattern": "^(?:slots|group:(?!host$(?![\\s\\S]))[^\\s\\u0000-\\u001f\\u007f]{1,100})$(?![\\s\\S])"
178
- },
179
- "workingDirectory": {
180
- "type": "string",
181
- "minLength": 1,
182
- "maxLength": 4096,
183
- "pattern": "^(?!/)(?![A-Za-z]:)(?!.*\\\\)(?!.*[\\u0000-\\u001f\\u007f])(?!.*(?:^|/)\\.\\.(?:/|$)).+$",
184
- "description": "工作根下的相对路径;拒绝绝对路径、反斜线和 .. 段,真实落点与符号链接仍须执行方检查"
185
- }
186
- },
187
- "properties": {
188
- "source": {
189
- "oneOf": [
190
- {"type": "null"},
191
- {"type": "object", "properties": {"snapshot": {"$ref": "#/$defs/snapshotRef"}}, "required": ["snapshot"], "additionalProperties": false},
192
- {
193
- "type": "object",
194
- "properties": {
195
- "repository": {"$ref": "#/$defs/repositoryRef"},
196
- "commit": {"type": "string", "minLength": 1, "maxLength": 64, "pattern": "^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{64})$(?![\\s\\S])"}
197
- },
198
- "required": ["repository", "commit"],
199
- "additionalProperties": false
200
- }
201
- ]
202
- },
203
- "requirements": {
204
- "type": "object",
205
- "properties": {"labels": {"$ref": "#/$defs/labels"}},
206
- "required": ["labels"],
207
- "additionalProperties": false
208
- },
209
- "resources": {
210
- "type": "object",
211
- "propertyNames": {"$ref": "#/$defs/resourceName"},
212
- "maxProperties": 1,
213
- "additionalProperties": {"const": 1},
214
- "description": "空对象表示不占资源;否则只申请一个资源的一单位"
215
- },
216
- "exclusiveResources": {
217
- "type": "array",
218
- "items": {"$ref": "#/$defs/resourceName"},
219
- "maxItems": 1,
220
- "uniqueItems": true,
221
- "default": [],
222
- "description": "空数组或独占申请的那一个资源,须与 resources 的键一致"
223
- },
224
- "context": {
225
- "type": "object",
226
- "properties": {
227
- "workflow": {
228
- "type": "object",
229
- "properties": {
230
- "name": {"type": "string", "minLength": 1, "maxLength": 256},
231
- "job": {"type": "string", "minLength": 1, "maxLength": 256},
232
- "runId": {"$ref": "#/$defs/opaqueId"},
233
- "runAttempt": {"type": "integer", "minimum": 1, "maximum": 9007199254740991},
234
- "sha": {"type": "string", "pattern": "^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{64})?$(?![\\s\\S])"},
235
- "ref": {"type": "string", "maxLength": 1024},
236
- "repository": {"type": "string", "maxLength": 2048}
237
- },
238
- "required": ["name", "job", "runId", "runAttempt", "sha", "ref", "repository"],
239
- "additionalProperties": false
240
- },
241
- "plugin": {
242
- "type": "object",
243
- "properties": {"id": {"type": "string", "pattern": "^[a-z][a-z0-9-]{0,39}$(?![\\s\\S])"}, "version": {"type": "string", "minLength": 1, "maxLength": 128}},
244
- "required": ["id", "version"],
245
- "additionalProperties": false
246
- },
247
- "audience": {"const": "user"},
248
- "outputNames": {"type": "array", "maxItems": 64, "uniqueItems": true, "items": {"type": "string", "minLength": 1, "maxLength": 128}}
249
- },
250
- "additionalProperties": false,
251
- "description": "可信生产者给出的运行上下文与输出声明;不是环境快照或授权凭证"
252
- },
253
- "task": {
254
- "oneOf": [
255
- {"type": "object", "properties": {"script": {"type": "string", "minLength": 1, "maxLength": 65536}, "shell": {"type": "string", "minLength": 1, "maxLength": 4096}}, "required": ["script", "shell"], "additionalProperties": false},
256
- {"type": "object", "properties": {"command": {"type": "string", "minLength": 1, "maxLength": 4096}, "args": {"type": "array", "items": {"type": "string", "minLength": 0, "maxLength": 16384}, "maxItems": 256}}, "required": ["command", "args"], "additionalProperties": false}
257
- ]
258
- },
259
- "workingDirectory": {"$ref": "#/$defs/workingDirectory", "default": "."},
260
- "env": {
261
- "type": "object",
262
- "propertyNames": {"pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$(?![\\s\\S])"},
263
- "maxProperties": 128,
264
- "additionalProperties": {"type": "string", "minLength": 0, "maxLength": 16384}
265
- },
266
- "timeoutMs": {"type": "integer", "minimum": 1, "maximum": 9007199254740991},
267
- "cancelGraceMs": {"type": "integer", "minimum": 0, "maximum": 9007199254740991}
268
- },
269
- "required": ["source", "requirements", "resources", "task", "env"],
270
- "additionalProperties": false,
271
- "allOf": [
272
- {"if": {"properties": {"resources": {"maxProperties": 0}}}, "then": {"properties": {"exclusiveResources": {"maxItems": 0}}}}
273
- ],
274
- "description": "一次执行工作的输入;取消走 coda/run@1 的 cancel 操作,不写在输入里"
275
- },
276
- "run": true
277
- }
278
- }
143
+ "operations": {}
279
144
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "description": "coda:action:serviceTask 上写它,就是 Coda 在后端里做的一步,不写脚本。参数写成 <coda:param name value>,只认 params 列出的,required 列出的必须写",
2
+ "description": "coda:action:serviceTask 上写它,就是 Coda 在后端里做的一步,不写脚本。参数写成 <coda:param name value>,只认 params 列出的,required 列出的必须写;requires 写了某参数就必须同时写它列出的参数;enum 限定某参数写成文字(不是表达式、不含 {{ … }})时的取值",
3
3
  "actions": {
4
4
  "publish-stage": {"params": ["stage", "detail"],
5
5
  "description": "发布运行主体的会话此刻在流程里的阶段(stage)和放在状态旁的说明(detail),两者都空就是清掉;只用于由会话事件启动的运行"},
@@ -47,8 +47,9 @@
47
47
  "description": "从仓库地址添加项目:本机已有就是它,没有就克隆;新项目没有 Tag 时带上运行所属项目的 Tag"},
48
48
  "tell-session": {"params": ["text", "key", "session"],
49
49
  "description": "告诉一个会话(不写就是运行所属的)一句话,像结果一样叫醒它的 Agent;同一个 key(或同样的话)只说一次,已归档就不说"},
50
- "send-session": {"params": ["text", "key", "session"],
51
- "description": "在一个会话(不写就是运行所属的)里提交一条普通消息,和用户发的一样开始一轮;同一个 key 只发一次;已归档就不发"},
50
+ "send-session": {"params": ["text", "key", "session", "resumes", "how"],
51
+ "requires": {"how": ["resumes"]}, "enum": {"how": ["original", "verify"]},
52
+ "description": "在一个会话(不写就是运行所属的)里提交一条普通消息,和用户发的一样开始一轮;同一个 key 只发一次;已归档就不发。resumes 是要续跑的那条输入的 ID,须是 session 指定的会话(不写是运行所属的)里的输入;写了 resumes 时,text 只是存在会话里给人看的一句短说明,发给 Agent 的是那条输入的完整内容(附件、引用都在),how 为 original(默认)是原样重发,为 verify 是先核对已经做了什么、再接着做,加上核对说明。how 须与 resumes 一起写,只能是 original 或 verify(写成文字时读流程就查);resumes 不是这个会话里的输入由实现方在运行时检查"},
52
53
  "session-state": {"params": ["session"],
53
54
  "description": "一个会话(不写就是运行所属的)现在的样子:它或它的根会话是否已归档"}
54
55
  }
@@ -47,18 +47,11 @@
47
47
  {"name": "action", "isAttr": true, "type": "String"}
48
48
  ]
49
49
  },
50
- {
51
- "name": "PlacementProperties",
52
- "isAbstract": true,
53
- "extends": ["bpmn:Process", "bpmn:ScriptTask", "bpmn:SubProcess"],
54
- "description": "local 将脚本限制在发起端;any 允许符合要求的执行器。上层 local 不可被子节点放宽;显式执行器绑定仍须满足此约束",
55
- "properties": [{"name": "placement", "isAttr": true, "type": "String"}]
56
- },
57
50
  {
58
51
  "name": "RunsOnProperties",
59
52
  "isAbstract": true,
60
53
  "extends": ["bpmn:ScriptTask", "bpmn:SubProcess"],
61
- "description": "脚本步骤要在哪里跑(同 GitHub 的 runs-on):标签如 linux,x64,由这台机器上的项目绑到执行环境;写在子流程上对其中每个脚本步骤生效",
54
+ "description": "脚本步骤要在哪里跑(同 GitHub 的 runs-on):标签如 linux,x64,是对本机执行环境的要求,不符合就一开始失败,不会把步骤交给别台;写在子流程上对其中每个脚本步骤生效",
62
55
  "properties": [
63
56
  {"name": "runsOn", "isAttr": true, "type": "String"}
64
57
  ]
@@ -88,10 +81,8 @@
88
81
  "name": "StartEventProperties",
89
82
  "isAbstract": true,
90
83
  "extends": ["bpmn:StartEvent"],
91
- "description": "计时器开始事件的:reportTo 运行向哪个会话汇报(会话引用,或读本插件设置的 =vars.…),reportOn 是 failure(默认)或 always,scope 是 project(默认,每个有它的项目各跑)或 machine(整台机器一次)",
84
+ "description": "计时器开始事件的:scope 是 project(默认,每个有它的项目各跑)或 machine(整台机器一次)",
92
85
  "properties": [
93
- {"name": "reportTo", "isAttr": true, "type": "String"},
94
- {"name": "reportOn", "isAttr": true, "type": "String"},
95
86
  {"name": "scope", "isAttr": true, "type": "String"}
96
87
  ]
97
88
  },
@@ -203,7 +203,7 @@
203
203
  }
204
204
  },
205
205
  {
206
- "description": "coda:reportTo、coda:reportOn、coda:scope 只写在定时开始事件上(由会话发起的运行交给发起它的会话)",
206
+ "description": "coda:scope 只写在定时开始事件上",
207
207
  "schema": {
208
208
  "properties": {
209
209
  "position": {
@@ -215,22 +215,8 @@
215
215
  }
216
216
  },
217
217
  "when": {
218
- "anyOf": [
219
- {
220
- "required": [
221
- "reportTo"
222
- ]
223
- },
224
- {
225
- "required": [
226
- "reportOn"
227
- ]
228
- },
229
- {
230
- "required": [
231
- "scope"
232
- ]
233
- }
218
+ "required": [
219
+ "scope"
234
220
  ]
235
221
  }
236
222
  },
@@ -30,12 +30,6 @@
30
30
  "retry": {"type": "string", "pattern": "^[1-5]$", "description": "coda:retry 是失败后最多再试几次,须为 1 到 5 的整数"}
31
31
  }
32
32
  },
33
- "PlacementProperties": {
34
- "type": "object",
35
- "properties": {
36
- "placement": {"enum": ["local", "any"], "description": "coda:placement 只能是 local 或 any;local 限制为发起端,不能隐式回退或被子节点放宽"}
37
- }
38
- },
39
33
  "RunsOnProperties": {
40
34
  "type": "object",
41
35
  "properties": {
@@ -66,15 +60,8 @@
66
60
  "StartEventProperties": {
67
61
  "type": "object",
68
62
  "properties": {
69
- "reportTo": {"type": "string",
70
- "anyOf": [{"pattern": "^\\s*=\\s*vars(?:\\.[A-Za-z0-9_-]+)+\\s*$"},
71
- {"pattern": "^\\s*(?:coda://threads/|coda\\+space://[^/#]+/threads/)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(?:#(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}|command:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))?\\s*$"}],
72
- "description": "coda:reportTo 写会话引用(coda://threads/<会话 UUID>),或只读插件设置的表达式,如 =vars.maintenance.reportTo"},
73
- "reportOn": {"enum": ["failure", "always"], "description": "coda:reportOn 只能是 failure、always"},
74
63
  "scope": {"enum": ["project", "machine"], "description": "coda:scope 只能是 project、machine"}
75
- },
76
- "if": {"required": ["reportOn"]},
77
- "then": {"required": ["reportTo"], "description": "写了 coda:reportOn 就要写 coda:reportTo(结果交给谁)"}
64
+ }
78
65
  },
79
66
  "EndEventProperties": {
80
67
  "type": "object",
package/workflow.mjs CHANGED
@@ -37,6 +37,9 @@ 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), and the
41
+ // values a parameter written as plain text may take (`enum`); an action with neither is not listed.
42
+ const PARAM_RULES = Object.fromEntries(Object.entries(actions.actions).filter(([, action]) => action.requires || action.enum).map(([name, action]) => [name, action]));
40
43
  // The events Coda sends (dialect.json says what each is).
41
44
  export const CODA_EVENTS = Object.keys(dialect.events);
42
45
  export const { lifecycleStart: SESSION_OPENED, lifecycleFacts: SESSION_FACTS, dispatch: DISPATCH_EVENT, cancel: CANCEL_EVENT } = dialect.eventRoles;
@@ -304,6 +307,14 @@ export async function readWorkflow(source, file = 'workflow') {
304
307
  if (given.some(p => !params.includes(p.name))) return { problem: `${task.id}:coda:action ${task.action} 只接受参数 ${params.join('、')}` };
305
308
  const missing = (REQUIRED_PARAMS[task.action] ?? []).filter(name => !given.some(p => p.name === name));
306
309
  if (missing.length) return { problem: `${task.id}:coda:action ${task.action} 须写参数 ${missing.join('、')}` };
310
+ for (const [name, needs] of Object.entries(PARAM_RULES[task.action]?.requires ?? {}))
311
+ if (given.some(p => p.name === name) && needs.some(need => !given.some(p => p.name === need)))
312
+ return { problem: `${task.id}:coda:action ${task.action} 写了参数 ${name} 就须写参数 ${needs.join('、')}` };
313
+ for (const [name, values] of Object.entries(PARAM_RULES[task.action]?.enum ?? {})) {
314
+ const value = given.find(p => p.name === name)?.value;
315
+ if (value !== undefined && !isExpression(value) && !value.includes('{{') && !values.includes(value))
316
+ return { problem: `${task.id}:coda:action ${task.action} 的参数 ${name} 只能是 ${values.join('、')}` };
317
+ }
307
318
  }
308
319
  const problem = valuesProblem(root) ?? joinInputsProblem(root) ?? structureProblem(root, file);
309
320
  return problem ? { problem } : { root };
@@ -1,336 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://coda.pub/schemas/protocol/v1/remote-caller.json",
4
- "title": "记录的远端入口",
5
- "description": "POST /v1/remote-caller 的正文;绑定、回答与错误见 $defs。记录归属、参与者、白名单、幂等与 HTTP 状态由 Coda 检查,见 docs/protocol.md「记录的远端入口」。",
6
- "$defs": {
7
- "id": {
8
- "type": "string",
9
- "minLength": 1,
10
- "maxLength": 2048
11
- },
12
- "codeResult": {
13
- "type": "object",
14
- "properties": {
15
- "code": {
16
- "type": "string",
17
- "minLength": 1,
18
- "maxLength": 128
19
- },
20
- "expiresAt": {
21
- "type": "string",
22
- "format": "date-parse",
23
- "description": "绑定码到期时间,申请后 10 分钟"
24
- },
25
- "addresses": {
26
- "type": "array",
27
- "items": {
28
- "type": "string"
29
- },
30
- "description": "后端的 tailnet 入口;不在 tailnet 时为空"
31
- }
32
- },
33
- "required": [
34
- "code",
35
- "expiresAt",
36
- "addresses"
37
- ],
38
- "additionalProperties": false
39
- },
40
- "bindRequest": {
41
- "type": "object",
42
- "properties": {
43
- "code": {
44
- "type": "string",
45
- "minLength": 1,
46
- "maxLength": 128
47
- }
48
- },
49
- "required": [
50
- "code"
51
- ],
52
- "additionalProperties": false
53
- },
54
- "bindResult": {
55
- "type": "object",
56
- "properties": {
57
- "token": {
58
- "type": "string",
59
- "minLength": 1
60
- },
61
- "record": {
62
- "$ref": "#/$defs/id"
63
- }
64
- },
65
- "required": [
66
- "token",
67
- "record"
68
- ],
69
- "additionalProperties": false
70
- },
71
- "workflow": {
72
- "type": "object",
73
- "properties": {
74
- "project": {
75
- "$ref": "#/$defs/id"
76
- },
77
- "workflow": {
78
- "type": "string",
79
- "minLength": 1,
80
- "maxLength": 200
81
- }
82
- },
83
- "required": [
84
- "project",
85
- "workflow"
86
- ],
87
- "additionalProperties": false
88
- },
89
- "helloResult": {
90
- "type": "object",
91
- "properties": {
92
- "record": {
93
- "$ref": "#/$defs/id"
94
- },
95
- "machine": {
96
- "$ref": "#/$defs/id"
97
- },
98
- "tools": {
99
- "type": "array",
100
- "items": {
101
- "enum": [
102
- "machines",
103
- "machine_diagnostics",
104
- "read_thread",
105
- "read_tool_call",
106
- "workflow_list",
107
- "workflow_status"
108
- ]
109
- },
110
- "uniqueItems": true
111
- },
112
- "workflows": {
113
- "type": "array",
114
- "items": {
115
- "$ref": "#/$defs/workflow"
116
- },
117
- "uniqueItems": true
118
- }
119
- },
120
- "required": [
121
- "record",
122
- "machine",
123
- "tools",
124
- "workflows"
125
- ],
126
- "additionalProperties": false
127
- },
128
- "helloRequest": {
129
- "type": "object",
130
- "properties": {
131
- "method": {
132
- "const": "hello"
133
- },
134
- "params": {
135
- "type": "object",
136
- "properties": {},
137
- "required": [],
138
- "additionalProperties": false
139
- }
140
- },
141
- "required": [
142
- "method"
143
- ],
144
- "additionalProperties": false
145
- },
146
- "toolRequest": {
147
- "type": "object",
148
- "properties": {
149
- "method": {
150
- "const": "tool"
151
- },
152
- "params": {
153
- "type": "object",
154
- "properties": {
155
- "name": {
156
- "enum": [
157
- "machines",
158
- "machine_diagnostics",
159
- "read_thread",
160
- "read_tool_call",
161
- "workflow_list",
162
- "workflow_status"
163
- ]
164
- },
165
- "arguments": {
166
- "type": "object",
167
- "description": "参数同 Coda 的同名 MCP 工具"
168
- }
169
- },
170
- "required": [
171
- "name",
172
- "arguments"
173
- ],
174
- "additionalProperties": false
175
- }
176
- },
177
- "required": [
178
- "method",
179
- "params"
180
- ],
181
- "additionalProperties": false
182
- },
183
- "ticketRequest": {
184
- "type": "object",
185
- "properties": {
186
- "method": {
187
- "const": "file_ticket"
188
- },
189
- "params": {
190
- "type": "object",
191
- "properties": {
192
- "workflow": {
193
- "type": "string",
194
- "minLength": 1,
195
- "maxLength": 200
196
- },
197
- "project": {
198
- "$ref": "#/$defs/id"
199
- },
200
- "inputs": {
201
- "type": "object"
202
- },
203
- "requestId": {
204
- "type": "string",
205
- "minLength": 1,
206
- "maxLength": 200
207
- }
208
- },
209
- "required": [
210
- "workflow",
211
- "inputs",
212
- "requestId"
213
- ],
214
- "additionalProperties": false
215
- }
216
- },
217
- "required": [
218
- "method",
219
- "params"
220
- ],
221
- "additionalProperties": false
222
- },
223
- "ticketResult": {
224
- "type": "object",
225
- "properties": {
226
- "run": {
227
- "type": "object",
228
- "properties": {
229
- "kind": {
230
- "const": "workflow-runs"
231
- },
232
- "id": {
233
- "$ref": "#/$defs/id"
234
- }
235
- },
236
- "required": [
237
- "kind",
238
- "id"
239
- ],
240
- "additionalProperties": false
241
- },
242
- "reused": {
243
- "const": true
244
- }
245
- },
246
- "required": [
247
- "run"
248
- ],
249
- "additionalProperties": false
250
- },
251
- "toolResult": {
252
- "description": "Coda 同名 MCP 工具的回答,不在本协议复制 schema"
253
- },
254
- "helloResponse": {
255
- "type": "object",
256
- "properties": {
257
- "result": {
258
- "$ref": "#/$defs/helloResult"
259
- }
260
- },
261
- "required": [
262
- "result"
263
- ],
264
- "additionalProperties": false
265
- },
266
- "toolResponse": {
267
- "type": "object",
268
- "properties": {
269
- "result": {
270
- "$ref": "#/$defs/toolResult"
271
- }
272
- },
273
- "required": [
274
- "result"
275
- ],
276
- "additionalProperties": false
277
- },
278
- "ticketResponse": {
279
- "type": "object",
280
- "properties": {
281
- "result": {
282
- "$ref": "#/$defs/ticketResult"
283
- }
284
- },
285
- "required": [
286
- "result"
287
- ],
288
- "additionalProperties": false
289
- },
290
- "error": {
291
- "type": "object",
292
- "properties": {
293
- "error": {
294
- "type": "object",
295
- "properties": {
296
- "code": {
297
- "enum": [
298
- "invalid_input",
299
- "unauthorized",
300
- "forbidden",
301
- "invalid_state",
302
- "request_conflict",
303
- "rate_limited",
304
- "unavailable"
305
- ]
306
- },
307
- "message": {
308
- "type": "string",
309
- "minLength": 1
310
- }
311
- },
312
- "required": [
313
- "code",
314
- "message"
315
- ],
316
- "additionalProperties": false
317
- }
318
- },
319
- "required": [
320
- "error"
321
- ],
322
- "additionalProperties": false
323
- }
324
- },
325
- "oneOf": [
326
- {
327
- "$ref": "#/$defs/helloRequest"
328
- },
329
- {
330
- "$ref": "#/$defs/toolRequest"
331
- },
332
- {
333
- "$ref": "#/$defs/ticketRequest"
334
- }
335
- ]
336
- }