@coda-console/protocol 6.27.0 → 6.28.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,14 @@
2
2
 
3
3
  版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 6.28.0 — 2026-11-27
6
+
7
+ - 这是在 6.27.0 之上的次版本。依据 README「版本」一节:Agent 清单的 `modes` 只加可选键并放宽 `auto`、`full`,升次版本;旧清单一律照旧合法(`test/fixtures/stable/` 的 Pi 样本与不写 `modes` 的清单都不变)。`stable/manifest.json` 的 revision 从 3 升到 6(每登记一条加一),新登记 `modes.manual`、`modes.safe[]`、`modes.default` 三条路径。
8
+ - `schemas/plugin/agents.json`:`contributes.agents[].modes` 新增 `manual`(人工审批档的 ACP 模式 ID)、`safe`(只读、规划等安全模式的 ID 数组,不重复,不写同空数组)、`default`(ACP 没报当前模式、`currentModeId` 为空串时,这个 Agent 默认相当于哪一档:`safe`、`manual`、`auto`、`full` 或 `null`);`auto`、`full` 放宽为模式 ID 或 `null`(新增 `$defs/modeIdOrNull`),`null` 表示没有这一档、不可选。
9
+ - `validate.mjs` 的 `contributionProblem` 校验 `agents` 时多查两条:一,同一个模式 ID 不能放进多个档位(`manual`、`auto`、`full` 与 `safe` 之间);二,`engines.coda` ≥ 21 的清单里每个 Agent 须写 `modes`,并显式写齐 `manual`、`auto`、`full`(值可为 `null`),没写 `engines.coda` 或小于 21 的清单不受此限。导出不变。同一模式 ID 不跨档的检查只对 `engines.coda` ≥ 21 或写了新键(`manual`、`safe`、`default`,或 `auto`、`full` 为 `null`)的清单生效;更早且没用新键的清单仍可让 `auto` 与 `full` 用同一个 ID。`contributionProblem` 只对内置的 `agents.json` 加这两条,传别的 schema 照旧只按它校验。
10
+ - `schemas/protocol/v1/agent.json`:`coda/agent@1` 的 `spawn` 输入新增可选 `parentApproval`(`safe`、`manual`、`auto`、`full`);`parentUnattended` 不再必填,改为与 `parentApproval` 至少写一个;两个都传以 `parentApproval` 为准,只传 `parentUnattended`(旧字段,已废弃)时 `true` 当作 `auto`、`false` 当作 `manual`。只传 `parentUnattended` 的旧调用方照旧合法。
11
+ - 文档:`docs/agent-protocol.md` 新增「权限档位」一节,写明四档偏序 `safe < manual < auto < full`、没登记的模式按 `auto` 算、`null` 与 API Level 21 的写齐要求、父会话的定级顺序(当前模式、`modes.default`、保守按 `manual`)和委派省略 `mode` 时的选档规则;`docs/protocol.md` 同步 `spawn` 的 `parentApproval`。
12
+
5
13
  ## 6.27.0 — 2026-11-24
6
14
 
7
15
  - 这是在 6.26.0 之上的次版本。依据 README「版本」一节:新增可选的清单键升次版本;这两个键暂不进稳定面,`stable/` 不动,旧清单不受影响(没写这两个键的清单照旧合法)。
@@ -106,6 +106,24 @@ ACP 只允许在一轮(`session/prompt`)进行时交互。Agent 在两轮之
106
106
  Coda 记下每个 Agent 最近一次握手报的值,随后端遥测上报(Coda 遥测服务(Coda 的 docs/../telemetry/README.md「后端上报」)),用于复盘 Agent 版本带来的兼容问题;
107
107
  只取版本号式的字符(字母、数字与 `.+()-_` 空格,至多 64 个),其他写法不记。不报不影响会话。
108
108
 
109
+ ## 权限档位
110
+
111
+ Agent 的审批模式(ACP 的 mode)按权限高低归到四档,偏序是 `safe < manual < auto < full`。Agent 插件在清单 `contributes.agents[].modes`([agents.json](../schemas/plugin/agents.json))里登记:
112
+
113
+ | 键 | 含义 |
114
+ | --- | --- |
115
+ | `manual` | 人工审批档的 ACP 模式 ID |
116
+ | `auto` | 自动审批档的 ACP 模式 ID |
117
+ | `full` | 完全放行档的 ACP 模式 ID |
118
+ | `safe` | 只读、规划等安全模式的 ACP 模式 ID 列表(如 `plan`、`ask`、`dontAsk`),不写同空列表,不重复 |
119
+ | `default` | ACP 没报当前模式(`currentModeId` 为空串)时,这个 Agent 默认相当于哪一档:`safe`、`manual`、`auto`、`full` 或 `null` |
120
+
121
+ - `manual`、`auto`、`full` 都可以写 `null`(或不写),表示 Agent 没有这一档、不可选。API Level 21 起(`engines.coda` ≥ 21)Agent 插件须写 `modes` 并显式写齐这三个键,没有的一档写 `null`;更早的清单不受此限。
122
+ - 同一个模式 ID 只能属于一档:`manual`、`auto`、`full` 与 `safe` 里的 ID 两两不能相同。这条对 API Level ≥ 21 的清单,或写了新版档位特性(`manual`、`safe`、`default`,或 `auto`/`full` 为 `null`)的清单检查;只用旧版 `auto`/`full` 字符串的旧清单按稳定面保持兼容,不查。没登记在这四处的其余模式 ID 按 `auto` 算。
123
+ - **父会话的档位**:委派时先定父会话的档位。优先取运行中 ACP 实际报告的当前模式;它为空就读 `modes.default`;仍为空则保守按 `manual`。
124
+ - **委派选档**:委派(`spawn`、`new_session` 等)省略 `mode` 时,向下取不高于父会话档位的最高已登记档位:`full` 父依次试 `full`、`auto`、`manual`;`auto` 父试 `auto`、`manual`;`manual` 父只试 `manual`;`safe` 父取 `safe` 列表的第一个,不会自动落到 `safe`(从更高档往下止步于 `manual`)。没有可用档位时拒绝派出。
125
+ - 首轮 `session/prompt` 之前设档(`session/set_mode`)失败,拒绝启动这个会话,不带着未知档位开跑。
126
+
109
127
  ## 配置探测
110
128
 
111
129
  Coda 读 Agent 的模型与模式目录时,不必建一个真实的原生会话:对声明了该能力的 Agent,改请它开一个只在当前连接里有效的虚拟会话。
package/docs/protocol.md CHANGED
@@ -469,7 +469,7 @@ status:
469
469
 
470
470
  `models[].efforts` 是 `[{ id, name?, shortName? }]`;`models[].options` 是 `{ id, name?, shortName?, type: "boolean"|"select", choices? }`,`select` 带 `choices`,`boolean` 不带。status 是空对象。
471
471
 
472
- 操作 `spawn`(`run: true`):在这台机器上用这个 Agent 开一个子会话,返回运行引用。输入是 `{ projectId, threadId, title, text, settings?, checkout?, parentTitle, parentUnattended }`:子会话所在的项目与工作树(`checkout`)、Agent 的设置(`settings`,如模型与推理强度)、标题与第一条任务(`text`);`threadId` 是调用方给的子会话 ID,重试找到的是同一个;`parentTitle` 是发起方在这里显示的名字,`parentUnattended` 说发起方是否无人值守。子会话为谁工作由调用信封的 `parent` 说,不写在输入里;`parent` 不是会话、是登记过的调用方记录时,开的是顶层会话,不是子会话。
472
+ 操作 `spawn`(`run: true`):在这台机器上用这个 Agent 开一个子会话,返回运行引用。输入是 `{ projectId, threadId, title, text, settings?, checkout?, parentTitle, parentUnattended?, parentApproval? }`:子会话所在的项目与工作树(`checkout`)、Agent 的设置(`settings`,如模型与推理强度)、标题与第一条任务(`text`);`threadId` 是调用方给的子会话 ID,重试找到的是同一个;`parentTitle` 是发起方在这里显示的名字,`parentUnattended`(旧字段,已废弃)说发起方是否无人值守;`parentApproval`(`safe`、`manual`、`auto`、`full`)说发起方的权限档位,省略 `settings` 里的模式时,子会话据此选不高于它的最高档(规则见 [Agent 接入协议](agent-protocol.md#权限档位))。两个至少写一个。同时传 `parentApproval` 与 `parentUnattended` 时以 `parentApproval` 为准;只传 `parentUnattended` 时,`true` 当作 `auto`,`false` 当作 `manual`,旧调用方照旧可用。子会话为谁工作由调用信封的 `parent` 说,不写在输入里;`parent` 不是会话、是登记过的调用方记录时,开的是顶层会话,不是子会话。
473
473
 
474
474
  ```json
475
475
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "6.27.0",
3
+ "version": "6.28.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -18,14 +18,17 @@
18
18
  },
19
19
  "command": {"$ref": "common.json#/$defs/command"},
20
20
  "modes": {
21
- "description": "审批档位的说法:title 不超过 10 字,unset 不超过 20 字,note 不超过 100 字,auto、full 各不超过 200 字",
21
+ "description": "审批档位的说法:title 不超过 10 字,unset 不超过 20 字,note 不超过 100 字。manual、auto、full 各是该档对应的 ACP 模式 ID(不超过 200 字),写 null 表示 Agent 没有这一档、不可选;API Level 21 起(engines.coda ≥ 21)三个键须写齐,更早的清单可以不写。safe 是只读、规划等安全模式的 ACP 模式 ID 列表,不写同空列表。档位从低到高是 safe < manual < auto < full,同一个模式 ID 只能放在一档里(API Level ≥ 21,或写了 manual、safe、default、null 的 auto/full 等新版特性的清单才检查;只用旧版 auto、full 字符串的旧清单保持兼容);没登记在这四处的其余模式按 auto 算。default 是 ACP 没报当前模式(currentModeId 为空串)时这个 Agent 默认相当于哪一档,null 或不写表示不知道",
22
22
  "type": "object",
23
23
  "properties": {
24
24
  "title": {"$ref": "common.json#/$defs/line10"},
25
25
  "unset": {"$ref": "common.json#/$defs/line20"},
26
26
  "note": {"$ref": "common.json#/$defs/line100"},
27
- "auto": {"$ref": "common.json#/$defs/line200"},
28
- "full": {"$ref": "common.json#/$defs/line200"}
27
+ "manual": {"$ref": "#/$defs/modeIdOrNull"},
28
+ "auto": {"$ref": "#/$defs/modeIdOrNull"},
29
+ "full": {"$ref": "#/$defs/modeIdOrNull"},
30
+ "safe": {"type": "array", "items": {"$ref": "common.json#/$defs/line200"}, "uniqueItems": true},
31
+ "default": {"enum": ["safe", "manual", "auto", "full", null]}
29
32
  },
30
33
  "additionalProperties": false
31
34
  },
@@ -41,6 +44,10 @@
41
44
  },
42
45
  "x-unique-by": ["id"],
43
46
  "$defs": {
47
+ "modeIdOrNull": {
48
+ "description": "一档对应的 ACP 模式 ID,null 表示没有这一档",
49
+ "anyOf": [{"$ref": "common.json#/$defs/line200"}, {"type": "null"}]
50
+ },
44
51
  "icon": {
45
52
  "description": "插件目录里的 PDF,不超过 32 KiB",
46
53
  "allOf": [{"$ref": "common.json#/$defs/line1000"}],
@@ -81,9 +81,11 @@
81
81
  "settings": {"type": "object", "additionalProperties": true},
82
82
  "checkout": {"type": "object", "additionalProperties": true},
83
83
  "parentTitle": {"type": "string"},
84
- "parentUnattended": {"type": "boolean"}
84
+ "parentUnattended": {"type": "boolean"},
85
+ "parentApproval": {"enum": ["safe", "manual", "auto", "full"]}
85
86
  },
86
- "required": ["projectId", "threadId", "title", "text", "parentTitle", "parentUnattended"],
87
+ "required": ["projectId", "threadId", "title", "text", "parentTitle"],
88
+ "anyOf": [{"required": ["parentUnattended"]}, {"required": ["parentApproval"]}],
87
89
  "additionalProperties": false
88
90
  }
89
91
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "revision": 3,
2
+ "revision": 6,
3
3
  "entries": [
4
4
  {
5
5
  "path": "name"
@@ -70,6 +70,15 @@
70
70
  {
71
71
  "path": "contributes.agents[].modes.full"
72
72
  },
73
+ {
74
+ "path": "contributes.agents[].modes.manual"
75
+ },
76
+ {
77
+ "path": "contributes.agents[].modes.safe[]"
78
+ },
79
+ {
80
+ "path": "contributes.agents[].modes.default"
81
+ },
73
82
  {
74
83
  "path": "contributes.agents[].icon.dark"
75
84
  },
package/validate.mjs CHANGED
@@ -349,7 +349,29 @@ export function pointProblem(schema, value, where, dir = null) {
349
349
  export function contributionProblem(schema, manifest, key, dir = null) {
350
350
  const point = declared(schema);
351
351
  return point.validate.call({ dir }, manifest.contributes[key], { instancePath: `/contributes/${escape(key)}`, parentData: manifest.contributes,
352
- parentDataProperty: key, rootData: manifest, dynamicAnchors: {} }) ? null : explain(point.validate.errors, '', [point.schema]);
352
+ parentDataProperty: key, rootData: manifest, dynamicAnchors: {} }) ? (key === 'agents' && (schema === SCHEMAS['agents.json'] || schema?.$id === SCHEMAS['agents.json'].$id) && Array.isArray(manifest.contributes?.agents) ? agentsProblem(manifest) : null) : explain(point.validate.errors, '', [point.schema]);
353
+ }
354
+ // What the agents schema cannot say of its values as they stand to each other, the shapes being right by now: from API Level 21
355
+ // (`engines.coda`) an agent writes `modes` with `manual`, `auto` and `full` all there, each an ID or null; and a mode ID sits in
356
+ // one tier only (`manual`, `auto`, `full`, or the list `safe`) — for a manifest of API Level 21 or one that writes a newer
357
+ // `modes` key (`manual`, `safe`, `default`, or a null `auto` or `full`); an older one may still give `auto` and `full` one ID.
358
+ function agentsProblem({ engines, contributes }) {
359
+ const strict = engines?.coda >= 21;
360
+ for (const [i, { modes }] of contributes.agents.entries()) {
361
+ const at = `contributes.agents[${i}]`;
362
+ if (modes === undefined) { if (strict) return `${at} 缺 modes:engines.coda 为 21 起,Agent 须写 modes,并写齐 manual、auto、full`; continue; }
363
+ const missing = ['manual', 'auto', 'full'].find(tier => !Object.hasOwn(modes, tier));
364
+ if (strict && missing) return `${at}.modes 缺 ${missing}:engines.coda 为 21 起须写齐 manual、auto、full,没有这一档就写 null`;
365
+ const newer = ['manual', 'safe', 'default'].some(key => Object.hasOwn(modes, key)) || modes.auto === null || modes.full === null;
366
+ if (!strict && !newer) continue;
367
+ const tiers = new Map();
368
+ for (const [tier, id] of [['manual', modes.manual], ['auto', modes.auto], ['full', modes.full], ...(modes.safe ?? []).map(id => ['safe', id])]) {
369
+ if (id === null || id === undefined) continue;
370
+ if (tiers.has(id)) return `${at}.modes:模式 ID「${id}」不能同时放在 ${tiers.get(id)} 和 ${tier},一个模式只属于一档`;
371
+ tiers.set(id, tier);
372
+ }
373
+ }
374
+ return null;
353
375
  }
354
376
 
355
377
  // The serialized size of a value in UTF-8 bytes, `{ ok: true, bytes }`, or why it has none, `{ ok: false, error }`: what