@coda-console/plugin-check 0.5.21 → 0.5.23
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/README.md +2 -2
- package/check/agent.mjs +57 -11
- package/check/coda/components/session-config/commands.mjs +5 -5
- package/check/coda/contract.json +5 -5
- package/check/coda/domain/agent-protocol.mjs +7 -13
- package/check/coda/kernel/agent-failures.mjs +2 -5
- package/check/waits.mjs +4 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -421,8 +421,8 @@ npx github:coda-console/coda-plugins#<提交> <插件目录>
|
|
|
421
421
|
| 级 | 要不要登录 | 查什么 |
|
|
422
422
|
| --- | --- | --- |
|
|
423
423
|
| 清单(总是) | 不要 | `package.json` 对 Coda 的类型 schema 校验(`manifestProblem`),再照 Coda 读成插件(`readPlugin`:ID、设置名在 ID 之下);写给别的插件扩展点的键,要有 Coda 自带的或旁边依赖的插件声明这个类型。面板写法按资源插件给扩展点 `panels` 带的 schema 查。`.coda/workflows/` 里的每个流程(含能力)按协议的流程方言读(`workflowProblem`):不是 BPMN、认不出的 `coda:` 属性或元素、没有的动作或动作不接受的参数都算失败。另有只提醒的:分类、版本、图标页面太小、旧的 Agent ID `claude` |
|
|
424
|
-
| 握手(默认) | 不要 | `sh -c` 启动 `command`(环境是 Coda 的 `pluginEnv` 给的:`CODA_NODE`、`CODA_PLUGIN_PATH`、临时的 `CODA_PLUGIN_STATE`、设置默认值的 `CODA_PLUGIN_SETTINGS`;依赖的插件在旁边(同一个父目录里同名的目录)时 `CODA_PLUGIN_DEPENDENCIES` 给它的目录,Coda 自带的不在这里、不给),发与 Coda 相同的 `initialize`,要求 `protocolVersion` 为 1
|
|
425
|
-
| 一轮(`--live`) | 要 | 第一轮问会话指令里的检查词(一个随机词),回复里要有它;再发一轮提示词(默认「只回复 ok」)收到 `stopReason`;每条 `session/update`
|
|
424
|
+
| 握手(默认) | 不要 | `sh -c` 启动 `command`(环境是 Coda 的 `pluginEnv` 给的:`CODA_NODE`、`CODA_PLUGIN_PATH`、临时的 `CODA_PLUGIN_STATE`、设置默认值的 `CODA_PLUGIN_SETTINGS`;依赖的插件在旁边(同一个父目录里同名的目录)时 `CODA_PLUGIN_DEPENDENCIES` 给它的目录,Coda 自带的不在这里、不给),发与 Coda 相同的 `initialize`,要求 `protocolVersion` 为 1;能力声明的 `_meta.coda` 与顶层插话声明交协议 schema 校验;声明会话指令(`sessionCapabilities.systemPrompt`,没声明算失败);`session/new` 带会话指令,给出会话与当前模型,配置选项的 `_meta.coda.default` 交协议校验;错误里声明的执行失败也查协议 schema,回 -32000 记为未登录、跳过后面的检查(不算失败);像 Coda 一样对进程组发 SIGTERM,5 秒内要退出(超过 0.8 秒提醒);另起一个进程,关掉标准输入后 5 秒内不退出只提醒。面板由 Coda 资源插件的 `Panels` 读一次(30 秒),输出合格式 |
|
|
425
|
+
| 一轮(`--live`) | 要 | 第一轮问会话指令里的检查词(一个随机词),回复里要有它;再发一轮提示词(默认「只回复 ok」)收到 `stopReason`;每条 `session/update` 先过 ACP SDK 的 schema,工具审核、用量与默认选项标记再过协议 schema;`_coda/wait` 用协议的 `agentMessageProblem` 校验形状,另查会话归属、登记与终态(子 Agent 不带 `childSessionId`、定时不带 `at` 只提醒);扩展形状问题按现有规则报告协议返回的「位置:说明」;远端绑定码请求先查协议参数再查本会话归属;执行失败的形状交协议校验,重试预算照 Coda 策略;审批与提问一律回拒绝,在一轮之外发来的算失败;再发一轮并 `session/cancel`,30 秒内要结束,读到取消后还在做事或拖过 5 秒才答复却不回 `cancelled` 算失败(见下);有自主轮次的也取消一次;声明插话的,答复用协议的 `agentResultProblem` 校验,一轮结束后插话要回 `promptRequired` 且不自己另开一轮,一轮进行中插话要回 `injected` 或 `promptRequired`(`injected` 的那一轮照常回 `stopReason`);声明 `loadSession` 的,新开进程 `session/load`(同样带会话指令)要成功,随后在新进程里再跑一轮也要收到 `stopReason` |
|
|
426
426
|
|
|
427
427
|
**取消后的 `stopReason` 怎么判**:检查发 `session/cancel` 时紧跟一个只会得到 -32601 的探测请求(`_codaCheck/barrier`)。Agent 按顺序读,
|
|
428
428
|
探测的答复一定写在它读到取消之后,所以本轮的答复与 `session/update` 落在探测答复的前后,就说明它们写出时读没读到取消。
|
package/check/agent.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// agent's command the way Coda does, says what Coda says, and holds what the agent says to ACP's schema and to
|
|
3
3
|
// docs/agent-protocol.md. Where Coda would quietly drop or refuse something, the check fails and says what Coda does.
|
|
4
4
|
import { PROTOCOL_VERSION } from '@agentclientprotocol/sdk';
|
|
5
|
+
import { agentCapabilitiesProblem, agentMessageProblem, agentResultProblem, agentValueProblem } from '@coda-console/protocol/agent';
|
|
5
6
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
6
7
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
8
|
import { mkdirSync } from 'node:fs';
|
|
@@ -20,8 +21,6 @@ import { Waits } from './waits.mjs';
|
|
|
20
21
|
export const ACP_PROTOCOL_VERSION = PROTOCOL_VERSION;
|
|
21
22
|
// What Coda answers an agent request it has no handler for (JSON-RPC's, as the SDK sends it): it handles only approvals and forms.
|
|
22
23
|
const METHOD_NOT_FOUND = -32601;
|
|
23
|
-
// What an agent answers a message sent into a turn: it joined the turn, or the turn had ended.
|
|
24
|
-
const STEERING_OUTCOMES = [STEERED, NOT_STEERED];
|
|
25
24
|
// `exit`: how long an agent may take to go after SIGTERM, or after its input ends. `cancelReply`: how soon a turn whose work
|
|
26
25
|
// was done answers once it has read the cancel. `pause`: a quiet moment between two turns, as between two messages of a
|
|
27
26
|
// person, for what an agent says after a turn to be heard outside it. `term`: how long Coda's session host waits after
|
|
@@ -48,6 +47,33 @@ const STEER_TURN = '从 1 数到 20,每个数字单独一行。', STEER_TEXT =
|
|
|
48
47
|
const secs = ms => (ms / 1000).toFixed(1);
|
|
49
48
|
const short = (text, max = 80) => (text.length > max ? `${text.slice(0, max)}…` : text).replace(/\s+/g, ' ');
|
|
50
49
|
|
|
50
|
+
// Optional extensions are checked only when present; null is a value, not an absent declaration. Read the wire values:
|
|
51
|
+
// ACP parsers may drop optional fields they cannot read. Only the protocol decides an extension's shape.
|
|
52
|
+
const optionalValueProblem = (ref, value, where) => value === undefined ? null : agentValueProblem(ref, value, where);
|
|
53
|
+
const failureProblem = error => optionalValueProblem('failure.json', error?.data?._meta?.coda?.failure, 'error.data._meta.coda.failure');
|
|
54
|
+
function configProblems(configOptions, where) {
|
|
55
|
+
const problems = [];
|
|
56
|
+
const check = (option, path) => {
|
|
57
|
+
const problem = optionalValueProblem('default.json', option?._meta?.coda, `${path}._meta.coda`);
|
|
58
|
+
if (problem) problems.push(problem);
|
|
59
|
+
};
|
|
60
|
+
if (!Array.isArray(configOptions)) return problems;
|
|
61
|
+
for (const [i, config] of configOptions.entries()) {
|
|
62
|
+
if (config?.type !== 'select' || !Array.isArray(config.options)) continue;
|
|
63
|
+
const parsed = schemas.zSessionConfigSelectOptions.safeParse(config.options);
|
|
64
|
+
if (!parsed.success) continue; // ACP drops a config whose options it cannot read.
|
|
65
|
+
for (const [j, option] of config.options.entries()) {
|
|
66
|
+
const at = `${where}[${i}].options[${j}]`;
|
|
67
|
+
// ACP selects a branch for the whole list; extra wire fields do not determine its shape.
|
|
68
|
+
// Keep the original values and indices, including metadata ACP may drop while parsing.
|
|
69
|
+
if ('group' in parsed.data[j]) {
|
|
70
|
+
if (Array.isArray(option.options)) for (const [k, child] of option.options.entries()) check(child, `${at}.options[${k}]`);
|
|
71
|
+
} else check(option, at);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return problems;
|
|
75
|
+
}
|
|
76
|
+
|
|
51
77
|
// The environment Coda starts the agent with: the session's (here the checker's), and what Coda gives its plugin's processes
|
|
52
78
|
// (`checked.env`, components/plugins/plugin-rules.mjs pluginEnv) with the state directory made for it.
|
|
53
79
|
const agentEnv = (checked, base) => ({ ...cleared(process.env), ...checked.env(join(base, 'state')) });
|
|
@@ -104,13 +130,18 @@ class Session {
|
|
|
104
130
|
this.at.fail('update.schema', `session/update 不合 ACP schema(SDK 1.4.0):${explain(parsed.error, params)}`);
|
|
105
131
|
return;
|
|
106
132
|
}
|
|
133
|
+
const update = params.update, kind = update.sessionUpdate;
|
|
134
|
+
const problems = kind === 'config_option_update' ? configProblems(update.configOptions, 'session/update params.update.configOptions') : [];
|
|
135
|
+
if (kind === 'tool_call' || kind === 'tool_call_update')
|
|
136
|
+
problems.push(optionalValueProblem('review.json', update._meta?.coda?.review, 'session/update params.update._meta.coda.review'));
|
|
137
|
+
if (kind === 'usage_update') problems.push(optionalValueProblem('usage.json', update._meta?.coda, 'session/update params.update._meta.coda'));
|
|
138
|
+
for (const problem of problems.filter(Boolean)) { this.malformed++; this.at.fail('update.schema', problem); }
|
|
107
139
|
// Of a session being opened Coda keeps only its commands and title; a replayed history it does not want.
|
|
108
140
|
if (this.loading) return;
|
|
109
141
|
if (!this.waits.owns(params.sessionId)) {
|
|
110
142
|
this.at.fail('update.session', `session/update 说的会话 ${params.sessionId} 不是本会话,也不是 _coda/wait 登记过的子会话:Coda 丢弃`);
|
|
111
143
|
return;
|
|
112
144
|
}
|
|
113
|
-
const kind = params.update.sessionUpdate;
|
|
114
145
|
this.kinds.set(kind, (this.kinds.get(kind) ?? 0) + 1);
|
|
115
146
|
const turn = this.turn ?? this.autonomous;
|
|
116
147
|
if (turn) {
|
|
@@ -156,6 +187,8 @@ class Session {
|
|
|
156
187
|
// A code binding the place a remote agent works (docs/agent-protocol.md「远端入口」): Coda answers it for the agent's own
|
|
157
188
|
// session only, here with a code that binds nothing and no address, as on a machine in no tailnet.
|
|
158
189
|
if (m.method === REMOTE_CODE) {
|
|
190
|
+
const problem = agentMessageProblem(m.method, m.params);
|
|
191
|
+
if (problem) { this.at.fail('request.schema', problem); this.proc.respondError(m.id, -32602, problem); return; }
|
|
159
192
|
if (m.params?.sessionId !== this.sessionId) {
|
|
160
193
|
this.at.fail('request.session', `绑定码请求说的会话 ${m.params?.sessionId} 不是本会话:Coda 只为本会话发绑定码`);
|
|
161
194
|
this.proc.respondError(m.id, -32603, '只能为本会话请求');
|
|
@@ -176,10 +209,15 @@ class Session {
|
|
|
176
209
|
let reply;
|
|
177
210
|
try { reply = await this.proc.request('initialize', { protocolVersion: ACP_PROTOCOL_VERSION, clientCapabilities: clientCapabilities() }, { timeout: this.limits.open }); }
|
|
178
211
|
catch (e) { this.reportedExit = e instanceof Exited; say.fail('handshake.initialize', `initialize 失败:${e.message}`); return 'failed'; }
|
|
212
|
+
const initFailure = failureProblem(reply.error);
|
|
213
|
+
if (initFailure) { say.fail('handshake.initialize', initFailure); return 'failed'; }
|
|
179
214
|
if (reply.error?.code === SIGNED_OUT) { say.skip('handshake.signed-out', `initialize 回了 -32000(未登录):Coda 提示用户去「资源」登录;后面的检查跳过`); return 'signed-out'; }
|
|
180
215
|
if (reply.error) { say.fail('handshake.initialize', `initialize 回了错误 ${reply.error.code}:${reply.error.message}`); return 'failed'; }
|
|
181
216
|
const init = schemas.zInitializeResponse.safeParse(reply.result);
|
|
182
217
|
if (!init.success) { say.fail('handshake.initialize', `initialize 的结果不合 ACP schema:${explain(init.error)}`); return 'failed'; }
|
|
218
|
+
for (const problem of [agentCapabilitiesProblem(reply.result.agentCapabilities?._meta),
|
|
219
|
+
optionalValueProblem('steering.json#/$defs/capabilities', reply.result._meta, 'initialize result._meta')])
|
|
220
|
+
if (problem) say.fail('handshake.initialize', problem);
|
|
183
221
|
this.init = reply.result;
|
|
184
222
|
if (reply.result.protocolVersion !== ACP_PROTOCOL_VERSION) {
|
|
185
223
|
say.fail('handshake.protocol', `protocolVersion 是 ${reply.result.protocolVersion}:Coda 用的 ACP(SDK 1.4.0)是版本 ${ACP_PROTOCOL_VERSION}(Coda 自己不核对这一项,按它说的协议说话)`);
|
|
@@ -201,10 +239,14 @@ class Session {
|
|
|
201
239
|
const instructions = this.instructed ? { systemPrompt: systemPrompt(this.instructions) } : {};
|
|
202
240
|
try { reply = await this.proc.request(method, { cwd: this.cwd, mcpServers: [], ...instructions, ...(sessionId ? { sessionId } : {}) }, { timeout: this.limits.open }); }
|
|
203
241
|
catch (e) { this.reportedExit = e instanceof Exited; say.fail(sessionId ? 'handshake.load' : 'handshake.new', `${method} 失败:${e.message}`); return 'failed'; }
|
|
242
|
+
const openFailure = failureProblem(reply.error);
|
|
243
|
+
if (openFailure) { say.fail(sessionId ? 'handshake.load' : 'handshake.new', openFailure); return 'failed'; }
|
|
204
244
|
if (reply.error?.code === SIGNED_OUT) { say.skip('handshake.signed-out', `${method} 回了 -32000(未登录):Coda 提示用户去「资源」登录;后面的检查跳过`); return 'signed-out'; }
|
|
205
245
|
if (reply.error) { say.fail(sessionId ? 'handshake.load' : 'handshake.new', `${method} 回了错误 ${reply.error.code}:${reply.error.message}`); return 'failed'; }
|
|
206
246
|
const parsed = (sessionId ? schemas.zLoadSessionResponse : schemas.zNewSessionResponse).safeParse(reply.result);
|
|
207
247
|
if (!parsed.success) { say.fail(sessionId ? 'handshake.load' : 'handshake.new', `${method} 的结果不合 ACP schema:${explain(parsed.error)}`); return 'failed'; }
|
|
248
|
+
for (const problem of configProblems(reply.result.configOptions, `${method} result.configOptions`))
|
|
249
|
+
say.fail(sessionId ? 'handshake.load' : 'handshake.new', problem);
|
|
208
250
|
this.sessionId = sessionId ?? reply.result.sessionId; this.waits.sessionId = this.sessionId; this.info = reply.result;
|
|
209
251
|
this.loading = false;
|
|
210
252
|
for (const params of this.pendingWaits.splice(0)) this.wait(params);
|
|
@@ -255,6 +297,8 @@ class Session {
|
|
|
255
297
|
return null;
|
|
256
298
|
} finally { clearTimeout(timer); }
|
|
257
299
|
if (m.error) {
|
|
300
|
+
const problem = failureProblem(m.error);
|
|
301
|
+
if (problem) { say.fail(rule, problem); return null; }
|
|
258
302
|
// As Coda retries (PromptRecovery): an upstream wait past its one-minute budget is not waited for, and a shorter one is
|
|
259
303
|
// waited at least as long as it asks.
|
|
260
304
|
const failure = serviceFailure(m.error), upstream = failure?.retryAfterMs ?? 0, base = this.limits.retryDelays[attempt];
|
|
@@ -289,11 +333,13 @@ class Session {
|
|
|
289
333
|
}
|
|
290
334
|
return stop;
|
|
291
335
|
}
|
|
292
|
-
// `_session/steering` as Coda sends it: the agent's answer
|
|
336
|
+
// `_session/steering` as Coda sends it: `{ result }` holds the agent's answer, `{ error }` a diagnostic.
|
|
293
337
|
async steer(text) {
|
|
294
338
|
try {
|
|
295
339
|
const m = await this.proc.request(STEERING, steeringParams(this.sessionId, text), { timeout: this.limits.steer });
|
|
296
|
-
|
|
340
|
+
if (m.error) return { error: failureProblem(m.error) ?? `回了错误 ${m.error.code}:${m.error.message}` };
|
|
341
|
+
const problem = agentResultProblem(STEERING, m.result);
|
|
342
|
+
return problem ? { error: problem } : { result: m.result };
|
|
297
343
|
} catch (e) { this.reportedExit = e instanceof Exited; return { error: e.message }; }
|
|
298
344
|
}
|
|
299
345
|
// Waits for every open wait to end, `limit` at most; with `cancel`, stops the first turn of its own the agent takes.
|
|
@@ -363,22 +409,22 @@ async function instructions(session, word, limits, say) {
|
|
|
363
409
|
// takes it in (injected) and still ends with the original `session/prompt`. Anything else Coda records as unknown.
|
|
364
410
|
async function steering(session, limits, say) {
|
|
365
411
|
if (!session.steering) { say.skip('live.steering', '没声明插话(_meta.steering.supported):用户「立即插话」时 Coda 停止这一轮,结束后再把消息作为下一轮发出'); return; }
|
|
366
|
-
const answer = result => result.error ?? (result.outcome ? `outcome ${result.outcome}` : `结果 ${short(JSON.stringify(result))}`);
|
|
367
412
|
if (!await session.until(() => !session.autonomous, limits.settle)) { say.warn('live.steering', `自主轮次 ${secs(limits.settle)} 秒还没结束,插话没查`); return; }
|
|
368
413
|
const before = session.idleWork.length, late = await session.steer(STEER_LATE);
|
|
369
414
|
if (session.proc.exit) return;
|
|
370
415
|
await delay(limits.steerQuiet);
|
|
371
416
|
const work = session.idleWork.slice(before);
|
|
372
|
-
if (late.
|
|
417
|
+
if (late.error) say.fail('live.steering', late.error);
|
|
418
|
+
else if (late.result.outcome !== NOT_STEERED) say.fail('live.steering', `一轮已经结束时发 ${STEERING},回了 outcome ${late.result.outcome}:要回 promptRequired(reason noRunningTurn),消息不收、也不自己另开一轮;Coda 把其他答复记为结果未知,不再把消息作为下一轮发出`);
|
|
373
419
|
else if (work.length) say.fail('live.steering', `一轮已经结束时发 ${STEERING},回了 promptRequired,随后却自己说起话来(${work.length} 条 session/update:${[...new Set(work)].join('、')}):promptRequired 的消息没被接收,Agent 不得自己另开一轮,Coda 会把它作为下一轮发出`);
|
|
374
|
-
else say.pass('live.steering', `一轮已经结束时插话:回 promptRequired${late.reason ? `(${late.reason})` : ''},${secs(limits.steerQuiet)} 秒里没有自己另开一轮`);
|
|
420
|
+
else say.pass('live.steering', `一轮已经结束时插话:回 promptRequired${late.result.reason ? `(${late.result.reason})` : ''},${secs(limits.steerQuiet)} 秒里没有自己另开一轮`);
|
|
375
421
|
await delay(limits.pause);
|
|
376
422
|
const stop = await session.prompt(STEER_TURN, { steer: STEER_TEXT, as: 'live.steering' }), turn = session.last;
|
|
377
423
|
if (!turn.steered) { if (stop) say.info('live.steering', `这一轮在说出第一句之前就结束了(stopReason ${stop}),一轮进行中的插话没机会发`); return; }
|
|
378
424
|
const steered = await turn.steered;
|
|
379
|
-
if (
|
|
425
|
+
if (steered.error) say.fail('live.steering', steered.error);
|
|
380
426
|
else if (!stop) return;
|
|
381
|
-
else if (steered.outcome === STEERED) say.pass('live.steering', `一轮进行中插话:injected,原来的 session/prompt 照常结束(stopReason ${stop},${turn.updates} 条 session/update${turn.text ? `,回复「${short(turn.text)}」` : ''})`);
|
|
427
|
+
else if (steered.result.outcome === STEERED) say.pass('live.steering', `一轮进行中插话:injected,原来的 session/prompt 照常结束(stopReason ${stop},${turn.updates} 条 session/update${turn.text ? `,回复「${short(turn.text)}」` : ''})`);
|
|
382
428
|
else say.info('live.steering', `一轮进行中插话:回 promptRequired,插话到时这一轮已经结束(stopReason ${stop})`);
|
|
383
429
|
}
|
|
384
430
|
|
|
@@ -403,7 +449,7 @@ async function live(session, { prompt, word }, limits, say) {
|
|
|
403
449
|
await session.settle(limits.settle, { cancel: true });
|
|
404
450
|
}
|
|
405
451
|
const kinds = [...session.kinds].map(([kind, n]) => `${kind} ×${n}`).join(',');
|
|
406
|
-
if (!session.malformed) say.pass('live.updates', `session/update 都合 ACP schema(SDK 1.4.0
|
|
452
|
+
if (!session.malformed) say.pass('live.updates', `session/update 都合 ACP schema(SDK 1.4.0)与 Coda 扩展 schema:${kinds || '无'}`);
|
|
407
453
|
}
|
|
408
454
|
|
|
409
455
|
// Checks one declared agent of the plugin as the manifest level read it (`checked`, manifest.mjs checkManifest), started as
|
|
@@ -125,7 +125,7 @@ export function childSpawn(value) {
|
|
|
125
125
|
object(value, 'spawn');
|
|
126
126
|
keys(value, ['turn', 'requestId', 'agent', 'prompt', 'title', 'model', 'effort', 'mode', 'options', 'checkout', 'project']);
|
|
127
127
|
check([undefined, 'shared', 'worktree'].includes(value.checkout), 'invalid_input', 'checkout 必须是 shared 或 worktree');
|
|
128
|
-
check(typeof value.agent === 'string' && AGENT_ID.test(value.agent), 'invalid_input', 'agent 须为 Agent 的 ID(agents
|
|
128
|
+
check(typeof value.agent === 'string' && AGENT_ID.test(value.agent), 'invalid_input', 'agent 须为 Agent 的 ID(agents 工具列出的),或用户给的 Agent 引用 coda://agents/…');
|
|
129
129
|
const prompt = text(value.prompt, 'prompt', 100_000);
|
|
130
130
|
return { turn: text(value.turn, 'turn', 100), requestId: text(value.requestId, 'requestId', 100), agent: value.agent, prompt,
|
|
131
131
|
title: text(value.title ?? prompt.trim().slice(0, 80), 'title'), checkout: value.checkout ?? 'shared',
|
|
@@ -133,11 +133,11 @@ export function childSpawn(value) {
|
|
|
133
133
|
settings: settings(Object.fromEntries(['model', 'effort', 'mode', 'options'].filter(k => value[k] !== undefined).map(k => [k, value[k]]))) };
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
// A remote client asks the user to open a root session
|
|
136
|
+
// A remote client asks the user to open a root session: in the project's own directory (`checkout` shared, the default) or
|
|
137
|
+
// in a new worktree of its default branch (`worktree`). No parent is supplied by the agent.
|
|
137
138
|
export function newSession(value) {
|
|
138
139
|
object(value, 'new_session');
|
|
139
|
-
keys(value, ['turn', 'requestId', 'project', 'agent', 'prompt', 'title', 'model', 'effort', 'mode', 'options']);
|
|
140
|
+
keys(value, ['turn', 'requestId', 'project', 'agent', 'prompt', 'title', 'model', 'effort', 'mode', 'options', 'checkout']);
|
|
140
141
|
text(value.project, 'project', 200);
|
|
141
|
-
|
|
142
|
-
return spec;
|
|
142
|
+
return childSpawn(value);
|
|
143
143
|
}
|
package/check/coda/contract.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"commit": "
|
|
2
|
+
"commit": "b4280e88dedb17190fd84e3d0678bd5b838214c2",
|
|
3
3
|
"packages": {
|
|
4
4
|
"@0dep/piso": "5.2.0",
|
|
5
5
|
"@agentclientprotocol/sdk": "1.4.0",
|
|
6
|
-
"@coda-console/protocol": "1.
|
|
6
|
+
"@coda-console/protocol": "1.9.0",
|
|
7
7
|
"yaml": "2.9.1"
|
|
8
8
|
},
|
|
9
9
|
"files": {
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"check/coda/components/plugins/plugin-source-rules.mjs": "d894d55a3272df5ef3b108b68820c64aefdf6b69346404b58954f2a3503cb4a5",
|
|
14
14
|
"check/coda/components/plugins/skill-document.mjs": "c5b5e815c42cd836572f7b60e22a46af6ac607fd9df0170fa36f955825636ce6",
|
|
15
15
|
"check/coda/components/prompt-recovery/prompt-recovery.mjs": "f43f21d24c19a58113d3304f9248225b12080ab00ed15eab74bf7b94642732de",
|
|
16
|
-
"check/coda/components/session-config/commands.mjs": "
|
|
16
|
+
"check/coda/components/session-config/commands.mjs": "5d6139f1e5814422dab5f9d69f0b31967bf08f49c51c40ff91d9282dfc642dd9",
|
|
17
17
|
"check/coda/components/workflows/executor-labels.mjs": "dceca6ae60c0a4f3c3cc72a6c84f1489831790774c93caab96e4ddb493bc89e1",
|
|
18
|
-
"check/coda/domain/agent-protocol.mjs": "
|
|
18
|
+
"check/coda/domain/agent-protocol.mjs": "769cc10dc21b3cef7718f94272aaef2d17d4882d42617b408cb47357abfc3bcb",
|
|
19
19
|
"check/coda/domain/duration.mjs": "15dd64ef9b02342ad521c66e5968a569432a89dc7568d11afd3e6f3fe37e104b",
|
|
20
20
|
"check/coda/domain/errors.mjs": "ddc00aef9bb6f9a56845a9926c82200628a906230d31212d88fcde48e36dfd36",
|
|
21
21
|
"check/coda/domain/values.mjs": "01cc72b8d9c09e3fe16c93ec332ca01148bba859b1c672586d9d07444d7816c4",
|
|
22
|
-
"check/coda/kernel/agent-failures.mjs": "
|
|
22
|
+
"check/coda/kernel/agent-failures.mjs": "cbc215e2403d86f0acc765c2077197e0b529fc01e213db465c388361238ea8ce",
|
|
23
23
|
"check/coda/resources/plugins/resources/panels/command.mjs": "606f28bf87f87dded9df2db892bc7624c770d795ffab88f2409998346920ae42",
|
|
24
24
|
"check/coda/resources/plugins/resources/panels/panels.mjs": "9e25cfbc16ed9f68101fc7bfc34b8056c13a29d2368c5561e65e333233eb921e",
|
|
25
25
|
"check/coda/resources/plugins/resources/panels/rules.mjs": "8418ed83b796f18047c154d8dea8dca7d98244af8ddfe3ddf188520c59324ee8",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AGENT_SCHEMAS, agentMessageProblem, agentValueProblem } from '@coda-console/protocol/agent';
|
|
2
|
+
|
|
1
3
|
// What Coda says to an agent and takes from it beside the connection itself (coda-protocol docs/agent-protocol.md): the capabilities it
|
|
2
4
|
// sends, session instructions, steering, the agent's own waits, and how long Coda waits on it. Part of the plugin contract
|
|
3
5
|
// coda-plugins' check is given as written (scripts/plugin-contract.mjs).
|
|
@@ -33,21 +35,13 @@ export const steeringParams = (sessionId, text) => ({ sessionId, prompt: [{ type
|
|
|
33
35
|
export const currentModel = session => session?.configOptions?.find?.(x => x?.category === 'model')?.currentValue ?? session?.models?.currentModelId;
|
|
34
36
|
|
|
35
37
|
// What an agent may say of a wait of its own (「_coda/wait」); anything else is dropped unread.
|
|
36
|
-
const
|
|
37
|
-
export const
|
|
38
|
-
const fits = (value, limit) => value === undefined || (typeof value === 'string' && value.length <= limit);
|
|
39
|
-
export const validWait = p => record(p) && typeof p.sessionId === 'string' && p.sessionId.length > 0 && p.sessionId.length <= 200
|
|
40
|
-
&& typeof p.waitId === 'string' && p.waitId.length > 0 && p.waitId.length <= 200 && WAIT_STATES.has(p.state)
|
|
41
|
-
&& fits(p.kind, 50) && fits(p.title, 500) && fits(p.detail, 4000) && fits(p.childSessionId, 200) && fits(p.model, 200) && fits(p.outputFile, 4096)
|
|
42
|
-
&& fits(p.toolCallId, 200)
|
|
43
|
-
&& [p.stoppable, p.recurring].every(flag => flag === undefined || typeof flag === 'boolean')
|
|
44
|
-
&& (p.at === undefined || (typeof p.at === 'string' && Number.isFinite(Date.parse(p.at))));
|
|
38
|
+
export const WAIT_STATES = new Set(AGENT_SCHEMAS['wait.json'].properties.state.enum);
|
|
39
|
+
export const validWait = p => agentMessageProblem('_coda/wait', p) === null;
|
|
45
40
|
// What the agent's own check of a tool call said before running it (「工具调用的审核」): `_meta.coda.review` of the call's
|
|
46
41
|
// `tool_call` or `tool_call_update`, as Coda keeps it; null for anything else. A risk it does not know is left out.
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
? { state: r.state, ...(r.reason ? { reason: r.reason } : {}), ...(RISKS.has(r.risk) ? { risk: r.risk } : {}) } : null;
|
|
42
|
+
export const toolReview = r => agentValueProblem('review.json', r) === null
|
|
43
|
+
? { state: r.state, ...(r.reason ? { reason: r.reason } : {}),
|
|
44
|
+
...(agentValueProblem('review.json#/$defs/risk', r.risk) === null ? { risk: r.risk } : {}) } : null;
|
|
51
45
|
|
|
52
46
|
// Opening a session (initialize, then session/new or session/load) may take this long.
|
|
53
47
|
export const OPEN_LIMIT = 60_000;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { agentValueProblem } from '@coda-console/protocol/agent';
|
|
2
2
|
|
|
3
3
|
// Only the shared protocol establishes a category; provider codes and error text stay with the plugin.
|
|
4
4
|
export function agentFailure(error) {
|
|
5
5
|
const failure = error?.data?._meta?.coda?.failure;
|
|
6
|
-
|
|
7
|
-
return failure.kind === 'quota_exhausted' ||
|
|
8
|
-
(failure.kind === 'service_unavailable' && ['accepted', 'not_accepted'].includes(failure.input) &&
|
|
9
|
-
(failure.retryAfterMs === undefined || (Number.isFinite(failure.retryAfterMs) && failure.retryAfterMs >= 0))) ? failure : null;
|
|
6
|
+
return agentValueProblem('failure.json', failure) === null ? failure : null;
|
|
10
7
|
}
|
|
11
8
|
|
|
12
9
|
export function agentErrorMessage(error) {
|
package/check/waits.mjs
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
// `_coda/wait` as Coda takes it:
|
|
1
|
+
// `_coda/wait` as Coda takes it: the shared protocol's shape check first, then the stateful rules of
|
|
2
2
|
// docs/agent-protocol.md「Agent 活动」. Where Coda drops a report without a word, the checker fails it: an agent that relies
|
|
3
3
|
// on it is not heard.
|
|
4
|
-
import {
|
|
4
|
+
import { agentMessageProblem } from '@coda-console/protocol/agent';
|
|
5
5
|
|
|
6
6
|
export const TERMINAL = new Set(['done', 'failed', 'cancelled']);
|
|
7
|
-
const LIMITS = { sessionId: 200, waitId: 200, kind: 50, title: 500, detail: 4000, childSessionId: 200, model: 200, outputFile: 4096, toolCallId: 200 };
|
|
8
|
-
|
|
9
|
-
// The first part of validWait a report fails, in words (validWait decides; this only says why).
|
|
10
|
-
export function whyInvalid(p) {
|
|
11
|
-
if (!p || typeof p !== 'object' || Array.isArray(p)) return 'params 须为对象';
|
|
12
|
-
for (const key of ['sessionId', 'waitId']) if (typeof p[key] !== 'string' || !p[key]) return `缺 ${key}`;
|
|
13
|
-
if (!WAIT_STATES.has(p.state)) return `state 只能是 ${[...WAIT_STATES].join('、')},现为 ${JSON.stringify(p.state)}`;
|
|
14
|
-
for (const [key, max] of Object.entries(LIMITS)) if (p[key] !== undefined && (typeof p[key] !== 'string' || p[key].length > max)) return `${key} 须为不超过 ${max} 字的文本`;
|
|
15
|
-
for (const key of ['stoppable', 'recurring']) if (p[key] !== undefined && typeof p[key] !== 'boolean') return `${key} 须为 true 或 false`;
|
|
16
|
-
if (p.at !== undefined && !(typeof p.at === 'string' && Number.isFinite(Date.parse(p.at)))) return `at 读不出时间:${JSON.stringify(p.at)}`;
|
|
17
|
-
return '不合 validWait';
|
|
18
|
-
}
|
|
19
7
|
|
|
20
8
|
export class Waits {
|
|
21
9
|
constructor(say) {
|
|
@@ -27,7 +15,8 @@ export class Waits {
|
|
|
27
15
|
get handling() { return this.open.filter(w => w.state === 'handling'); }
|
|
28
16
|
// One report, in order with the session's updates; `turn`: whether a turn of Coda's was under way as it came.
|
|
29
17
|
take(p, { turn }) {
|
|
30
|
-
|
|
18
|
+
const problem = agentMessageProblem('_coda/wait', p);
|
|
19
|
+
if (problem) { this.say.fail('wait.invalid', problem); return; }
|
|
31
20
|
if (!this.owns(p.sessionId)) { this.say.fail('wait.session', `_coda/wait 说的会话 ${p.sessionId} 不是本会话,也不是登记过的子会话:Coda 丢弃`); return; }
|
|
32
21
|
const key = `${p.sessionId}\0${p.waitId}`, known = this.waits.get(key);
|
|
33
22
|
if (known && TERMINAL.has(known.state)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coda-console/plugin-check",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.23",
|
|
4
4
|
"description": "Coda 插件的契约检查:扮演 Coda 读清单、启动 Agent 讲 ACP 与 _coda/wait、读面板。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@0dep/piso": "5.2.0",
|
|
26
26
|
"@agentclientprotocol/sdk": "1.4.0",
|
|
27
|
-
"@coda-console/protocol": "1.
|
|
27
|
+
"@coda-console/protocol": "1.9.0",
|
|
28
28
|
"ajv": "8.20.0",
|
|
29
29
|
"yaml": "2.9.1"
|
|
30
30
|
},
|