@coda-console/plugin-check 0.8.16 → 0.8.19

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 CHANGED
@@ -24,7 +24,7 @@ plugins/network-log/ 网络记录:默认关闭,按需开启建连等待
24
24
  plugins/review/ PR 生命流程:会话开的 PR 先跑项目的检查、再交叉评审,你批准后合并、部署与发布,别人的 PR 只评审;也是写 PR 流程的样例
25
25
  plugins/desktop-pet/ 桌面宠物:Coda 娘待在 Mac 桌面上,Agent 在跑时打字,有事等你时举卡片叫你(Coda 的浮窗)
26
26
  plugins/testbed/ 测试机:长插在 Mac 上的 iPhone、iPad 只经 use-testbed 使用,排到后装 App、交给会话操作、用完切黑屏;依赖宿主资源
27
- plugins/composer/ 输入框模式与开发流程:监督开发(一个需求一条泳道,主 Agent 用泳道 PR 合进泳道,用户批准一次)与需求交付;Ultra 名单引用 composer.templates
27
+ plugins/composer/ 输入框模式与开发流程:监督开发(一个需求一条需求分支,主 Agent 把一块块改动合进需求分支,用户批准一次)与需求交付;Ultra 名单引用 composer.templates
28
28
  templates/agent/ 最小的 Agent 插件:手写 ACP 的回声 Agent,演示会话指令、插话、Agent 活动与自主轮次
29
29
  templates/resource/ 最小的资源插件:一个资源、两个读数、一个按钮
30
30
  bin/、check/ 契约检查(仓库根的 package.json 就是它,@coda-console/plugin-check);check/coda/ 是 Coda 同步来的规则副本,不要手改
@@ -538,7 +538,7 @@ npx github:coda-console/coda-plugins#<提交> <插件目录>
538
538
  | 级 | 要不要登录 | 查什么 |
539
539
  | --- | --- | --- |
540
540
  | 清单(总是) | 不要 | `package.json` 的通用键对协议 schema 校验(`manifestProblem`),再照 Coda 读成插件(`readPlugin`:登记的贡献点各按自己的 schema 查、读,ID、设置名在 ID 之下);其余写给别的插件扩展点的键,要有 Coda 自带的或旁边依赖的插件声明这个类型。资源类型与旧的面板按资源插件给扩展点 `resources`、`panels` 带的 schema 查。`.coda/workflows/` 里的每个流程(含能力)按协议的流程方言读(`workflowProblem`):不是 BPMN、认不出的 `coda:` 属性或元素、没有的动作或动作不接受的参数都算失败。另有只提醒的:分类、版本、图标页面太小、旧的 Agent ID `claude` |
541
- | 握手(默认) | 不要 | `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`,没声明也通过,由 Coda 在第一轮送入);声明了的 `session/new` 带会话指令,给出会话与当前模型,配置选项的 `_meta.coda.default` 交协议校验;错误里声明的执行失败也查协议 schema,回 -32000 记为未登录、跳过后面的检查(不算失败);像 Coda 一样对进程组发 SIGTERM,5 秒内要退出(超过 0.8 秒提醒);另起一个进程,关掉标准输入后 5 秒内不退出只提醒。资源类型(或旧的面板)由 Coda 资源插件的 `Panels` 读一次(30 秒),输出合格式 |
541
+ | 握手(默认) | 不要 | `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`,没声明也通过,由 Coda 在第一轮送入);声明了的 `session/new` 带会话指令,给出会话与当前模型,配置选项的 `_meta.coda.default` 交协议校验;错误里声明的执行失败也查协议 schema,回 -32000 记为未登录、跳过后面的检查(不算失败);像 Coda 一样对进程组发 SIGTERM,5 秒内要退出(超过 0.8 秒提醒);另起一个进程,关掉标准输入后 5 秒内不退出只提醒;声明了配置探测(`_meta.coda.probe`)的,再另起进程发带探测标记的 `session/new`(要给非空的 `sessionId`;标记不是 `true` 的要回 -32602):逐个模型用 `category: model` 的配置项切换(只有 `models` 的用 `session/set_model`),每次要返回该模型完整的配置、思考档位在它自己的选项里并能设回(标了 `_meta.coda.default` 的设回那一项),不存在的模型与配置项要报错,`session/prompt` 要回 -32602,声明了 `session/close` 的另开一个虚拟会话关掉,要回 `{}`、之后它的请求回 -32002,探测期间不干活;断线后新进程的 `session/load`、`session/resume` 要回 -32002,`session/list`(带探测的 `cwd`,沿 `nextCursor` 翻完;每页、每个会话条目合 ACP schema,`sessionId` 非空,`nextCursor` 只能是字符串或 null;重复的游标或超过 100 页算失败)不列出这个虚拟会话,没声明的跳过。资源类型(或旧的面板)由 Coda 资源插件的 `Panels` 读一次(30 秒),输出合格式 |
542
542
  | 一轮(`--live`) | 要 | 声明了会话指令的经 `systemPrompt` 送入,没声明的在第一轮前加契约的 `instructionsBlock`;第一轮问会话指令里的检查词(一个随机词),回复里要有它;再发一轮提示词(默认「只回复 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` |
543
543
 
544
544
  **取消后的 `stopReason` 怎么判**:检查发 `session/cancel` 时紧跟一个只会得到 -32601 的探测请求(`_codaCheck/barrier`)。Agent 按顺序读,
package/check/agent.mjs CHANGED
@@ -84,7 +84,7 @@ class Session {
84
84
  this.say = say; this.limits = limits; this.instructions = instructions;
85
85
  this.waits = new Waits({ fail: (rule, message) => this.at.fail(rule, message), warn: (rule, message) => this.at.warn(rule, message) });
86
86
  this.turn = null; this.autonomous = null; this.autonomousTurns = 0; this.loading = true; this.pendingWaits = [];
87
- this.kinds = new Map(); this.malformed = 0; this.said = new Set(); this.listeners = new Set(); this.idleWork = [];
87
+ this.kinds = new Map(); this.malformed = 0; this.said = new Set(); this.listeners = new Set(); this.idleWork = []; this.probeWork = [];
88
88
  // The session's working copy, and the plugin's state directory, which Coda makes for it.
89
89
  this.cwd = join(base, 'work');
90
90
  for (const dir of [this.cwd, join(base, 'state')]) mkdirSync(dir, { recursive: true });
@@ -113,6 +113,7 @@ class Session {
113
113
  }
114
114
 
115
115
  receive(m) {
116
+ if (this.probing) this.probeRecord(m);
116
117
  if ('id' in m) return this.request(m);
117
118
  if (m.method === 'session/update') return this.update(m.params);
118
119
  if (m.method === '_coda/wait') {
@@ -123,6 +124,17 @@ class Session {
123
124
  if (m.method === '$/cancel_request') return;
124
125
  this.once(`notify:${m.method}`, () => this.at.info('notify.unknown', `Agent 发了 Coda 不认识的通知 ${m.method}:Coda 忽略`));
125
126
  }
127
+ // A probe does nothing (docs/agent-protocol.md「配置探测 · 通知」): whatever else it says, whichever way the rest of the
128
+ // session takes it (opening, a turn, autonomous work, another session), is work.
129
+ probeRecord(m) {
130
+ const permission = m.method === 'session/request_permission';
131
+ if ('id' in m) this.probeWork.push(permission ? '审批' : m.method === 'elicitation/create' ? '提问' : m.method);
132
+ else if (m.method === '_coda/wait') this.probeWork.push(m.method);
133
+ else if (m.method === 'session/update') {
134
+ const kind = m.params?.update?.sessionUpdate;
135
+ if (!BOOKKEEPING.has(kind)) this.probeWork.push(kind ?? m.method);
136
+ }
137
+ }
126
138
  update(params) {
127
139
  const parsed = schemas.zSessionNotification.safeParse(params);
128
140
  if (!parsed.success) {
@@ -390,6 +402,178 @@ async function inputEnd({ agent, checked, base, limits, say }) {
390
402
  } finally { proc.kill(); }
391
403
  }
392
404
 
405
+ // docs/agent-protocol.md「配置探测」: an agent that declares `_meta.coda.probe` is asked, as Coda's catalog probe asks, for
406
+ // `session/new` marked `_meta.coda.probe: true`, and opens a session of that connection alone: each model through the
407
+ // `category: model` option (`session/set_model` for an agent with `models` alone), every answer that model's whole options,
408
+ // its thinking level set back as Coda sets the default; a bad model refused; no prompt; nothing done or asked of the user;
409
+ // and, the connection gone, nothing to load, resume or list. Its own process, apart from the handshake's real session.
410
+ // Coda's own `supportsProbe` is not in the copy of its contract yet: the declaration is read here as the protocol says.
411
+ const supportsProbe = init => { const probe = init?.agentCapabilities?._meta?.coda?.probe; return !!probe && typeof probe === 'object' && !Array.isArray(probe); };
412
+ // An `initialize` answer the probe goes on from, read as the handshake reads one: no error, a result ACP's schema takes.
413
+ function initializeProblem({ error, result }) {
414
+ if (error) return `initialize 回了错误 ${error.code}:${error.message}`;
415
+ const parsed = schemas.zInitializeResponse.safeParse(result);
416
+ return parsed.success ? null : `initialize 的结果不合 ACP schema:${explain(parsed.error)}`;
417
+ }
418
+ const leaves = option => (Array.isArray(option?.options) ? option.options : []).flatMap(o => Array.isArray(o?.options) ? o.options : [o]);
419
+ const choices = option => leaves(option).map(o => o?.value);
420
+ // What the protocol answers in a probe: a malformed mark, or a prompt to a probe session (-32602); a session ID it does not
421
+ // know, or no longer (-32002).
422
+ const INVALID_PARAMS = -32602, NOT_FOUND = -32002;
423
+ // How many pages of `session/list` the session is looked for in after the probe: past that the list is taken to go on forever.
424
+ const LIST_PAGES = 100;
425
+
426
+ async function probeModels(ask, sessionId, opened, say) {
427
+ // An option it does not have is not taken (「配置」: what it does not support is an error, not sent on to a real session).
428
+ const unknown = await ask('session/set_config_option', { sessionId, configId: 'coda-check-no-such-option', value: 'coda-check' });
429
+ if (!unknown.error) return say.fail('probe.config', '设不存在的配置项也成功了:不支持的请求必须报错,不能转给真实会话');
430
+ const model = opened.configOptions?.find?.(o => o?.category === 'model' && o.type === 'select');
431
+ if (!model) {
432
+ const models = opened.models?.availableModels;
433
+ if (!Array.isArray(models) || !models.length) return say.fail('probe.config', '探测会话既没有 category 为 model 的配置项,也没有 models:Coda 读不到模型目录');
434
+ for (const { modelId } of models) {
435
+ const m = await ask('session/set_model', { sessionId, modelId });
436
+ if (m.error) return say.fail('probe.config', `session/set_model ${modelId} 回了错误 ${m.error.code}:${m.error.message}:只报 models 却不能切换,不满足配置探测`);
437
+ if (!m.result || typeof m.result !== 'object' || Array.isArray(m.result)) return say.fail('probe.config', `session/set_model ${modelId} 的答复没有 result 对象(${JSON.stringify(m.result)}):不知道切换成没成`);
438
+ }
439
+ return say.pass('probe.config', `逐个模型 session/set_model ${models.length} 个`);
440
+ }
441
+ const seen = [];
442
+ for (const value of choices(model)) {
443
+ const m = await ask('session/set_config_option', { sessionId, configId: model.id, value });
444
+ if (m.error) return say.fail('probe.config', `切到模型 ${value}(session/set_config_option ${model.id})回了错误 ${m.error.code}:${m.error.message}`);
445
+ const parsed = schemas.zSetSessionConfigOptionResponse.safeParse(m.result);
446
+ if (!parsed.success) return say.fail('probe.config', `切到模型 ${value} 的结果不合 ACP schema:${explain(parsed.error)}`);
447
+ const problems = configProblems(m.result.configOptions, 'session/set_config_option result.configOptions');
448
+ if (problems.length) return say.fail('probe.config', problems[0]);
449
+ const options = m.result.configOptions, now = options.find(o => o?.id === model.id), level = options.find(o => o?.category === 'thought_level' && o.type === 'select');
450
+ if (now?.currentValue !== value) return say.fail('probe.config', `切到模型 ${value} 后返回的配置里当前模型是 ${now?.currentValue}:要返回这个模型完整的配置`);
451
+ if (level && !choices(level).includes(level.currentValue)) return say.fail('probe.config', `模型 ${value} 的思考档位 ${level.currentValue} 不在它自己的选项里:不能留着上一个模型的档位`);
452
+ if (level) {
453
+ // Back to the level the agent marks its default, as Coda sets it; with none marked, the one it has.
454
+ const fallback = leaves(level).find(o => o?._meta?.coda?.default === true)?.value ?? level.currentValue;
455
+ const back = await ask('session/set_config_option', { sessionId, configId: level.id, value: fallback });
456
+ if (back.error) return say.fail('probe.config', `模型 ${value} 设思考档位 ${fallback} 回了错误 ${back.error.code}:${back.error.message}:Coda 读完一个模型会把档位设回默认`);
457
+ const set = schemas.zSetSessionConfigOptionResponse.safeParse(back.result);
458
+ if (!set.success) return say.fail('probe.config', `模型 ${value} 设思考档位 ${fallback} 的结果不合 ACP schema:${explain(set.error)}`);
459
+ const now = back.result.configOptions.find(o => o?.id === level.id)?.currentValue;
460
+ if (now !== fallback) return say.fail('probe.config', `模型 ${value} 设思考档位 ${fallback} 后返回的档位是 ${now}:设回默认没有生效`);
461
+ }
462
+ seen.push(`${value}(${level ? choices(level).join('/') : '无档位'})`);
463
+ }
464
+ const bad = await ask('session/set_config_option', { sessionId, configId: model.id, value: 'coda-check-no-such-model' });
465
+ if (!bad.error) return say.fail('probe.config', '切到不存在的模型也成功了:不合法的值要回错误');
466
+ say.pass('probe.config', `逐个模型切换 ${seen.length} 个,每次返回该模型完整的配置:${seen.join(',')}`);
467
+ }
468
+
469
+ async function probe({ agent, checked, base, limits, say, instructions }) {
470
+ const scopes = { handshake: say, live: say }, init = { protocolVersion: ACP_PROTOCOL_VERSION, clientCapabilities: clientCapabilities() };
471
+ const session = new Session({ agent, checked, base, say: scopes, limits, instructions });
472
+ const ask = (method, params, proc = session.proc) => proc.request(method, params, { timeout: limits.open });
473
+ session.probing = true;
474
+ let sessionId, rule = 'probe.new';
475
+ try {
476
+ let reply = await ask('initialize', init);
477
+ const initFailure = initializeProblem(reply);
478
+ if (initFailure) return say.fail(rule, initFailure);
479
+ const closes = reply.result.agentCapabilities?.sessionCapabilities?.close != null;
480
+ reply = await ask('session/new', { cwd: session.cwd, mcpServers: [], _meta: { coda: { probe: true } } });
481
+ if (reply.error?.code === SIGNED_OUT) return say.skip('probe.signed-out', '带探测标记的 session/new 回了 -32000(未登录):配置探测跳过');
482
+ if (reply.error) return say.fail(rule, `带探测标记的 session/new 回了错误 ${reply.error.code}:${reply.error.message}(Coda 不改发普通 session/new,这次读不到目录)`);
483
+ const parsed = schemas.zNewSessionResponse.safeParse(reply.result);
484
+ if (!parsed.success) return say.fail(rule, `带探测标记的 session/new 的结果不合 ACP schema:${explain(parsed.error)}`);
485
+ const problems = configProblems(reply.result.configOptions, 'session/new result.configOptions'), model = currentModel(reply.result);
486
+ if (problems.length) return say.fail(rule, problems[0]);
487
+ if (typeof model !== 'string') return say.fail(rule, '带探测标记的 session/new 没报当前模型:Coda 读不到目录');
488
+ if (!reply.result.sessionId) return say.fail(rule, '带探测标记的 session/new 给了空的 sessionId:虚拟会话要有非空的 ID');
489
+ sessionId = reply.result.sessionId;
490
+ session.sessionId = session.waits.sessionId = sessionId; session.loading = false;
491
+ say.pass(rule, `带探测标记的 session/new:虚拟会话 ${sessionId},当前模型 ${model}`);
492
+ // A mark that is not `true` is refused, not dropped for an ordinary session (「请求」).
493
+ rule = 'probe.mark';
494
+ const marked = await ask('session/new', { cwd: session.cwd, mcpServers: [], _meta: { coda: { probe: 'true' } } });
495
+ if (marked.error?.code === INVALID_PARAMS) say.pass(rule, `探测标记写成字符串 "true" 的 session/new 回 -32602:${marked.error.message}`);
496
+ else say.fail(rule, `探测标记写成字符串 "true" 的 session/new ${marked.error ? `回了 ${marked.error.code}(${marked.error.message})`
497
+ : `开了会话 ${marked.result?.sessionId}`}:标记格式不对要回 -32602,不能去掉标记当普通会话`);
498
+ rule = 'probe.config';
499
+ await probeModels(ask, sessionId, reply.result, say);
500
+ rule = 'probe.prompt';
501
+ const turn = await ask('session/prompt', { sessionId, prompt: [{ type: 'text', text: CHECK_QUESTION }] });
502
+ if (turn.error?.code === INVALID_PARAMS) say.pass(rule, `虚拟会话的 session/prompt 回 -32602:${turn.error.message}`);
503
+ else say.fail(rule, `虚拟会话的 session/prompt ${turn.error ? `回了 ${turn.error.code}(${turn.error.message})` : `被接受了(stopReason ${turn.result?.stopReason})`}:配置探测会话不执行 prompt,要回 -32602`);
504
+ // Closed, it is gone: what is asked of it then is of a session it no longer knows (「错误与收尾」). Another probe session is
505
+ // closed, so that the first goes only with the connection, as it must without a close.
506
+ if (closes) {
507
+ rule = 'probe.close';
508
+ session.loading = true;
509
+ const other = await ask('session/new', { cwd: session.cwd, mcpServers: [], _meta: { coda: { probe: true } } }), closing = other.result?.sessionId;
510
+ session.loading = false;
511
+ if (other.error || !closing) say.fail(rule, `为查 session/close 另开的虚拟会话没开成(${other.error ? `${other.error.code}:${other.error.message}` : '没有 sessionId'})`);
512
+ else {
513
+ session.waits.children.add(closing);
514
+ const closed = await ask('session/close', { sessionId: closing }), parsed = closed.error ? null : schemas.zCloseSessionResponse.safeParse(closed.result);
515
+ if (closed.error) say.fail(rule, `虚拟会话的 session/close 回了错误 ${closed.error.code}:${closed.error.message}:声明了 close 就要释放虚拟会话并回 {}`);
516
+ else if (!parsed.success) say.fail(rule, `虚拟会话的 session/close 的结果不合 ACP schema:${explain(parsed.error)}`);
517
+ else {
518
+ const after = await ask('session/prompt', { sessionId: closing, prompt: [{ type: 'text', text: CHECK_QUESTION }] });
519
+ if (after.error?.code === NOT_FOUND) say.pass(rule, `另开的虚拟会话 ${closing} session/close 回 {},之后它的请求回 -32002`);
520
+ else say.fail(rule, `session/close 之后对虚拟会话 ${closing} 发 session/prompt ${after.error ? `回了 ${after.error.code}(${after.error.message})` : '被接受了'}:已失效的 sessionId 要回 -32002`);
521
+ }
522
+ }
523
+ }
524
+ } catch (e) { return say.fail(rule, `${rule === 'probe.new' ? '带探测标记的 session/new' : '探测'}失败:${e.message}`); }
525
+ finally {
526
+ await session.proc.terminate(limits.exit); session.proc.kill();
527
+ // Whichever way the probe ended (a signed-out answer too), what was done while it ran counts.
528
+ if (session.probeWork.length) say.fail('probe.quiet', `探测期间 Agent 发了执行类的 session/update、请求或 _coda/wait(${[...new Set(session.probeWork)].join('、')}):探测不执行任何东西,不登记活动`);
529
+ }
530
+ // The connection is gone: another one has nothing of the session.
531
+ const again = new Session({ agent, checked, base, say: scopes, limits, instructions }), asked = [];
532
+ try {
533
+ const reply = await ask('initialize', init, again.proc), initFailure = initializeProblem(reply);
534
+ // An initialize that did not come back says nothing of what the new connection would resume.
535
+ if (initFailure) return say.fail('probe.resume', `断线后新进程的 ${initFailure}:查不了虚拟会话能不能恢复`);
536
+ const caps = reply.result.agentCapabilities ?? {};
537
+ const tries = [caps.loadSession === true && 'session/load', caps.sessionCapabilities?.resume != null && 'session/resume'].filter(Boolean);
538
+ for (const method of tries) {
539
+ asked.push(method);
540
+ const { error } = await ask(method, { sessionId, cwd: again.cwd, mcpServers: [] }, again.proc);
541
+ if (!error) return say.fail('probe.resume', `断线后新进程 ${method} 接上了虚拟会话 ${sessionId}:虚拟会话不能恢复`);
542
+ if (error.code !== NOT_FOUND) return say.fail('probe.resume', `断线后新进程 ${method} 虚拟会话 ${sessionId} 回了 ${error.code}(${error.message}):已失效的 sessionId 要回 -32002`);
543
+ }
544
+ if (caps.sessionCapabilities?.list != null) {
545
+ // Every page of the probe's cwd, as ACP pages it (`cursor`, `nextCursor`): the session may be on any of them.
546
+ const cursors = new Set();
547
+ for (let page = 1, cursor; ; page++) {
548
+ const { result, error } = await ask('session/list', { cwd: session.cwd, ...(cursor !== undefined && { cursor }) }, again.proc);
549
+ const at = page > 1 ? `第 ${page} 页` : '';
550
+ // A list that did not come back says nothing of whether the session was kept.
551
+ if (error) return say.fail('probe.resume', `断线后 session/list ${at}回了错误 ${error.code}:${error.message}:查不了虚拟会话是否留在历史里`);
552
+ // ACP's parser takes a `sessions` that is not a list, or has an entry it cannot read, for none, and drops a `nextCursor`
553
+ // that is not a string: the page is read as it came.
554
+ const parsed = schemas.zListSessionsResponse.safeParse(result);
555
+ if (!parsed.success) return say.fail('probe.resume', `断线后 session/list ${at}的答复不合 ACP schema:${explain(parsed.error)}:查不了虚拟会话是否留在历史里`);
556
+ if (!Array.isArray(result.sessions)) return say.fail('probe.resume', `断线后 session/list ${at}的答复没有 sessions 数组(${JSON.stringify(result.sessions)}):查不了虚拟会话是否留在历史里`);
557
+ for (const [i, entry] of result.sessions.entries()) {
558
+ const info = schemas.zSessionInfo.safeParse(entry);
559
+ if (!info.success || !entry.sessionId) return say.fail('probe.resume', `断线后 session/list ${at}的 sessions[${i}] ${info.success ? 'sessionId 是空的' : `不合 ACP schema:${explain(info.error)}`}:查不了虚拟会话是否留在历史里`);
560
+ }
561
+ if (result.sessions.some(s => s.sessionId === sessionId)) return say.fail('probe.resume', `断线后 session/list ${at}列出了虚拟会话 ${sessionId}`);
562
+ if (result.nextCursor != null && typeof result.nextCursor !== 'string') return say.fail('probe.resume', `断线后 session/list ${at}的 nextCursor 不是字符串(${JSON.stringify(result.nextCursor)}):查不了后面的页`);
563
+ cursor = result.nextCursor ?? undefined;
564
+ if (cursor === undefined) break;
565
+ if (cursors.has(cursor)) return say.fail('probe.resume', `断线后 session/list 第 ${page} 页又给了用过的 nextCursor ${cursor}:翻页不会结束,查不完虚拟会话是否留在历史里`);
566
+ if (page === LIST_PAGES) return say.fail('probe.resume', `断线后 session/list 翻了 ${LIST_PAGES} 页还有 nextCursor:查不完虚拟会话是否留在历史里`);
567
+ cursors.add(cursor);
568
+ }
569
+ asked.push(`session/list(${cursors.size + 1} 页)`);
570
+ }
571
+ if (asked.length) say.pass('probe.resume', `断线后 ${asked.join('、')} 都不接受、不列出虚拟会话`);
572
+ else say.skip('probe.resume', '没声明 loadSession、resume、list:没有恢复的路');
573
+ } catch (e) { say.fail('probe.resume', `断线后再连失败:${e.message}`); }
574
+ finally { again.proc.kill(); }
575
+ }
576
+
393
577
  // The first turn asks for the word in the session instructions (docs/agent-protocol.md「会话指令」): they are to be in the
394
578
  // agent's context before it, whether its own system prompt took them or they went in front of the user's input.
395
579
  async function instructions(session, word, limits, say) {
@@ -465,6 +649,8 @@ export async function checkAgent({ agent, checked, live: running = false, prompt
465
649
  else scopes.live.skip('live.skipped', '一轮要 --live(会真的发一条提示词,可能要登录、花额度)');
466
650
  await session.finish(scopes.handshake);
467
651
  if (opened !== 'failed') await inputEnd({ agent, checked, base, limits, say: scopes.handshake });
652
+ if (opened === 'ok' && supportsProbe(session.init)) await probe({ agent, checked, base, limits, say: scopes.handshake, instructions });
653
+ else if (opened === 'ok') scopes.handshake.skip('probe.skipped', '没声明配置探测(_meta.coda.probe):Coda 读模型目录时开普通会话');
468
654
  if (opened !== 'ok' || !running) return;
469
655
  if (!session.canLoad) { scopes.live.skip('live.load', '没声明 loadSession:Coda 不会要求恢复,session/load 不查'); return; }
470
656
  const again = new Session({ agent, checked, base, say: scopes, limits, instructions });
@@ -3,7 +3,7 @@
3
3
  "packages": {
4
4
  "@0dep/piso": "5.2.0",
5
5
  "@agentclientprotocol/sdk": "2.6.0",
6
- "@coda-console/protocol": "6.5.0",
6
+ "@coda-console/protocol": "6.6.0",
7
7
  "ajv": "8.20.0",
8
8
  "yaml": "2.9.1"
9
9
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/plugin-check",
3
- "version": "0.8.16",
3
+ "version": "0.8.19",
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": "2.6.0",
27
- "@coda-console/protocol": "6.5.0",
27
+ "@coda-console/protocol": "6.6.0",
28
28
  "ajv": "8.20.0",
29
29
  "yaml": "2.9.1"
30
30
  },