Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(helper): send_to_session 漏传目标时不再让 created 被误读为已投递(#4884)
ficowang318edc7d5dfa
diff --git a/packages/lizi-mcps/src/__tests__/getCapabilitiesTool.test.ts b/packages/lizi-mcps/src/__tests__/getCapabilitiesTool.test.tsindex d344a17b9e..ad0695a38c 100644--- a/packages/lizi-mcps/src/__tests__/getCapabilitiesTool.test.ts+++ b/packages/lizi-mcps/src/__tests__/getCapabilitiesTool.test.ts@@ -93,6 +93,17 @@ describe('capabilities data source', () => {expect(entry!.detail).toContain('实际故障环境按需写进正文');});+ it('session-handoff 写明 send_to_session 发给已有任务时 target_session_id 必传, 省略即静默新建 (#4884)', () => {+ const entry = findCapability('session-handoff');+ expect(entry).toBeDefined();+ expect(entry!.detail).toContain('target_session_id 必传');+ expect(entry!.detail).toContain('list_sessions');+ expect(entry!.detail).toContain('wake_kind=created');+ // jump 撞忙已改为入队,旧的「本工具不排队」说法会误导 skill 自己 retry/backoff。+ expect(entry!.detail).not.toContain('本工具不排队');+ expect(entry!.detail).toContain('wake_kind=queued');+ });+it('collab-mode 明确 Pi 可作本地 Lead 和 Worker,且不扩大到 SSH 远程 Pi', () => {const entry = findCapability('collab-mode');diff --git a/packages/lizi-mcps/src/__tests__/sendToSessionTool.test.ts b/packages/lizi-mcps/src/__tests__/sendToSessionTool.test.tsindex 29d98a2c6d..a3ca1b2693 100644--- a/packages/lizi-mcps/src/__tests__/sendToSessionTool.test.ts+++ b/packages/lizi-mcps/src/__tests__/sendToSessionTool.test.ts@@ -10,6 +10,7 @@ import { describe, expect, it, vi } from 'vitest';import { XdtHelperToolRegistry } from '../lizi_xdtHelperToolRegistry.js';import type { XdtHelperToolResult } from '../lizi_xdtHelperToolRegistry.js';import {+ createdNote,registerSendToSessionTool,type SendToSessionCallback,} from '../xdt-helper/send_to_session.js';@@ -104,12 +105,54 @@ describe('send_to_session tool', () => {target_session_id: 'tgt-1',agent_kind: 'claude-code',wake_kind: 'created',+ note: createdNote('tgt-1'),target_title: 'issue #1',target_last_user_send_at: null,worktree_path: null,});});+ it('create 返回的 note 明确写出「已新建任务 <id>」与「本轮已触发」, 不能被误读为已投给既有任务 (#4884)', async () => {+ const { registry } = setup();+ const res = await registry.call('send_to_session', { message: '漏传了收件任务' });+ const payload = parse(res) as { wake_kind: string; note: string };+ expect(payload.wake_kind).toBe('created');+ expect(payload.note).toContain('已新建任务 tgt-1');+ expect(payload.note).toContain('本轮已触发');+ expect(payload.note).toContain('不是投递到既有任务');+ expect(payload.note).toContain('list_sessions');+ });++ it('jump 成功返回不带 note(resumed / already-active / queued 都是投给既有任务)', async () => {+ for (const wakeKind of ['resumed', 'already-active', 'queued'] as const) {+ const { registry } = setup({+ result: {+ ok: true,+ targetSessionId: UUID,+ agentKind: 'codex',+ wakeKind,+ targetTitle: 'Existing',+ targetLastUserSendAt: null,+ },+ });+ const res = await registry.call('send_to_session', {+ target_session_id: UUID,+ message: '增量',+ });+ expect(parse(res)).not.toHaveProperty('note');+ }+ });++ it('工具描述开头就是硬规则: 发给已有任务时 target_session_id 必传, 不知道 id 先 list_sessions (#4884)', () => {+ const { registry } = setup();+ const tool = registry.list('handoff').find((t) => t.name === 'send_to_session');+ expect(tool).toBeDefined();+ const firstParagraph = tool!.description.split('\n')[0] ?? '';+ expect(firstParagraph).toContain('target_session_id 必传');+ expect(firstParagraph).toContain('list_sessions');+ expect(firstParagraph).toContain('wake_kind=created');+ });+it('create + use_worktree=true → host 收到 useWorktree=true, worktree_path 回显', async () => {const { registry, sendToSession } = setup({result: {diff --git a/packages/lizi-mcps/src/xdt-helper/capabilities.ts b/packages/lizi-mcps/src/xdt-helper/capabilities.tsindex 84425086d4..c1ea3b8d30 100644--- a/packages/lizi-mcps/src/xdt-helper/capabilities.ts+++ b/packages/lizi-mcps/src/xdt-helper/capabilities.ts@@ -81,7 +81,8 @@ export const CAPABILITIES: readonly CapabilityEntry[] = [`【是什么】get_current_session_id(cindy_helper 自省类)+ send_to_worker(cindy_orca team 工具)/ send_to_session(cindy_helper handoff 类, 走 call_tool)配合使用。前者返回当前 ${BRAND_NAME} session 的 business id / agent_kind / working_dir, 后两者把一条控制层消息投递到指定 session;目标不在内存时会自动 resume, 投递成功即返回。`,'【典型场景】自动化 skill 首次处理某个外部业务对象(issue / jira / pr / 任意自定义 key)时, 先调 get_current_session_id 拿 session_id 并把它和外部 key 做持久化绑定;后续二次处理同一对象时, 调 send_to_worker(team 内 worker)或 send_to_session(任意已知 session)把增量信息 handoff 回那个 session, 保留原始上下文、决策链和历史工具调用。','【skill 端伪代码】first_seen -> sid = get_current_session_id(); store(key, sid.session_id); later -> sid = load(key); if sid then send_to_worker / send_to_session({ target_session_id: sid, message: "...增量..." }) else fallback normal flow。',- '【失败码】NOT_FOUND / DELETED 通常表示绑定失效,skill 应清掉绑定并回退; ARCHIVED 表示 session 已归档,skill 自己决定是否回退或等待未来的 unarchive 能力; BUSY 表示目标 turn 正在跑,本工具不排队,skill 自己决定 retry/backoff。',+ '【硬规则】send_to_session 要发给已有任务时 target_session_id 必传;不知道 id 先用 history 类目的 list_sessions 查。完全省略该参数不会报错,而是 create:静默新建一个专属任务、把消息当首条输入并立刻跑一轮,返回 wake_kind=created 和 note。只有明确要为业务对象新建专属任务时才省略;拿到 created 不等于已投给既有任务。',+ '【失败码】NOT_FOUND / DELETED 通常表示绑定失效,skill 应清掉绑定并回退; ARCHIVED 表示 session 已归档,skill 自己决定是否回退或等待未来的 unarchive 能力; 传了 id 但目标不存在只会返 NOT_FOUND,绝不自动新建。jump 撞上目标正在跑 turn 时不再返 BUSY,而是入队并成功返回 wake_kind=queued(可用 update/cancel_session_queued_message 管理);BUSY 仅是 create 模式的罕见兜底。','【边界】它不是普通聊天入口,而是 session 间 handoff 的控制层能力;不会自动关闭当前 dispatcher session,也不会替 skill 管理绑定键的存储语义。',].join(' '),},diff --git a/packages/lizi-mcps/src/xdt-helper/send_to_session.ts b/packages/lizi-mcps/src/xdt-helper/send_to_session.tsindex a9e3e514f0..3af4fb0b46 100644--- a/packages/lizi-mcps/src/xdt-helper/send_to_session.ts+++ b/packages/lizi-mcps/src/xdt-helper/send_to_session.ts@@ -77,6 +77,8 @@ export interface SendToSessionDeps {// 这是 LLM 点进 handoff 类目、看到本工具后的行为说明;选类目阶段的协同规避另见// lizi_xdtHelperMcpServer.ts 的 D_LIST_TOOLS(handoff 类目介绍)。const DESCRIPTION = [+ "⚠️【硬规则:发给已有任务时 target_session_id 必传】上层要求把消息发给某个已存在的任务(session / thread)时,必须传 target_session_id;不知道目标 id 就先用 history 类目的 list_sessions 查到再调用,不要省略。只有明确要为某个业务对象新建一个专属任务时才省略该参数——省略不会报错,而是静默新建一个任务、把消息当作首条输入并立刻跑一轮(返回 wake_kind=created + note)。把 created 误当成「已投给既有任务」会凭空多出一个任务并消耗 token。",+ "",'⚠️【不要用于"开协同 / 多 worker"】本工具 create 模式产出的是普通独立 session,不进入 Orca 协同分组或 Lead 右侧 worker 栏。用户明确要协同 team/worker 时才使用 cindy_orca;外部业务对象(issue / jira / pr)需要独立项目 session 时使用本工具。',"","把一条控制层 handoff 消息投递到一个 session。两种模式:",@@ -107,6 +109,17 @@ const DESCRIPTION = ["【重要】这不是 chat 对话工具,而是 session 间 handoff 的控制层入口。不要拿它替代普通的 user→agent 对话。",].join("\n");+/**+ * create 模式成功返回附带的说明:明确告诉调用方「这是新建、不是投给既有任务」以及+ * 后果(本轮已触发),避免调用方漏传 target_session_id 时把 created 误读为投递成功(#4884)。+ */+export function createdNote(targetSessionId: string): string {+ return (+ `已新建任务 ${targetSessionId}(wake_kind=created),本条消息作为其首条输入,本轮已触发。` ++ "这不是投递到既有任务;若原意是发给某个已存在的任务,请用 list_sessions 找到目标 id 后带 target_session_id 重发,并停止或归档这个多出来的任务。"+ );+}+/*** 注册 send_to_session 到 XdtHelperToolRegistry(handoff 类目),经 call_tool 调用。* 范式对齐 set_current_session_title.ts:host 通过 deps 注入 getSessionContext +@@ -127,7 +140,8 @@ export function registerSendToSessionTool(.optional().describe(`目标 ${BRAND_NAME} session 的 business id(UUID)。` +- "省略 → create:新建一个专属 session 并在返回里回传新建 id;提供 → jump 到该既有 session。",+ "要发给已有任务时必传(不知道 id 先用 list_sessions 查);提供 → jump 到该既有 session。" ++ "省略 → create:静默新建一个专属 session 并立刻跑一轮,返回里回传新建 id——仅在明确要新建专属任务时省略。",),message: z.string()@@ -218,6 +232,9 @@ export function registerSendToSessionTool(target_session_id: result.targetSessionId,agent_kind: result.agentKind,wake_kind: result.wakeKind,+ ...(result.wakeKind === "created"+ ? { note: createdNote(result.targetSessionId) }+ : {}),target_title: result.targetTitle,target_last_user_send_at: result.targetLastUserSendAt,...(result.queuedMessageId ? { queued_message_id: result.queuedMessageId } : {}),