Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop,maker-shared): 失败回扫共用真实用户边界;斜杠判据认信封里的指令范围
Kafeifeic0831bb78edc
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.tsindex 841629bde7..3a6bfe1b2b 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts@@ -1506,6 +1506,64 @@ describe('session-agent-switch handoff injection', () => {expect(peekPlanReconcileNote).not.toHaveBeenCalled();});+ it('按信封里的 slash 范围区分控制指令与绝对路径开头的真实提问', async () => {+ const peekPlanReconcileNote = vi.fn(async () => 'RECONCILE-NOTE');+ const { deps, session } = createDeps({ peekPlanReconcileNote });+ const transaction = createMakerSendTransaction(deps);++ // `/tmp/build.log 为什么失败` 是普通提问:Composer 写了空的 slashCommandRanges+ // (= 确认没有指令),不能因首字符 '/' 就绕过对账(review P2)。+ await transaction.sendToAgentAccepted(+ 'session-1',+ { type: 'user', content: '/tmp/build.log 为什么失败' },+ undefined,+ {+ persistUserMessage: {+ clientId: 'c-path',+ content: '{"text":"/tmp/build.log 为什么失败","images":[],"files":[],"slashCommandRanges":[]}',+ },+ },+ );+ expect(session.send).toHaveBeenLastCalledWith(+ { type: 'user', content: 'RECONCILE-NOTE\n\n/tmp/build.log 为什么失败' },+ expect.anything(),+ );++ // 真正的控制指令带起点为 0 的范围:照旧排除。+ await transaction.sendToAgentAccepted(+ 'session-1',+ { type: 'user', content: '/compact' },+ undefined,+ {+ persistUserMessage: {+ clientId: 'c-cmd',+ content: '{"text":"/compact","images":[],"files":[],"slashCommandRanges":[{"start":0,"end":8}]}',+ },+ },+ );+ expect(session.send).toHaveBeenLastCalledWith(+ { type: 'user', content: '/compact' },+ expect.anything(),+ );++ // 正文中段出现的指令形态(范围起点非 0)仍是真实提问。+ await transaction.sendToAgentAccepted(+ 'session-1',+ { type: 'user', content: '解释一下 /compact 做了什么' },+ undefined,+ {+ persistUserMessage: {+ clientId: 'c-mid',+ content: '{"text":"解释一下 /compact 做了什么","images":[],"files":[],"slashCommandRanges":[{"start":5,"end":13}]}',+ },+ },+ );+ expect(session.send).toHaveBeenLastCalledWith(+ { type: 'user', content: 'RECONCILE-NOTE\n\n解释一下 /compact 做了什么' },+ expect.anything(),+ );+ });+it('计划对账覆盖仅附件轮次(正文空,带图片/文件)', async () => {const peekPlanReconcileNote = vi.fn(async () => 'RECONCILE-NOTE');const { deps, session } = createDeps({ peekPlanReconcileNote });diff --git a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts b/apps/desktop/src/main/maker-ipc/makerSendTransaction.tsindex de45982914..4d69e1e5d3 100644--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts@@ -783,12 +783,34 @@ export function createMakerSendTransaction(deps: MakerSendTransactionDeps): Makereturn false;}})();+ // 斜杠开头不等于控制指令:`/tmp/build.log 为什么失败` 是普通提问,按首字符+ // 排除会让它绕过对账、遗留计划失去这一轮的收口机会(review P2)。信封里的+ // slashCommandRanges 是权威判据 —— Composer 对新消息总会写这个键(空数组+ // 表示"确认没有指令",见 stringifyUserContent 的注释),所以键在时只认+ // 起点为 0 的真实指令范围;键不在(旧数据 / 非 Composer 生产者)才退回+ // 首字符启发式。+ const reconcileSlashRanges = (() => {+ if (typeof reconcilePersistContent !== 'string') return undefined;+ if (!reconcilePersistContent.startsWith('{')) return undefined;+ try {+ const parsed = JSON.parse(reconcilePersistContent) as { slashCommandRanges?: unknown };+ return Array.isArray(parsed.slashCommandRanges) ? parsed.slashCommandRanges : undefined;+ } catch {+ return undefined;+ }+ })();+ const startsWithSlashCommand =+ reconcileSlashRanges !== undefined+ ? reconcileSlashRanges.some(+ (range) => (range as { start?: unknown } | null)?.start === 0,+ )+ : reconcilePersistText.startsWith('/');const isOrdinaryUserTurn =soForReconcile.origin === undefined &&soForReconcile.persistUserMessage?.autoResume !== true &&soForReconcile.persistUserMessage?.origin === undefined &&(reconcilePersistText.length > 0 || reconcileHasAttachments) &&- !reconcilePersistText.startsWith('/') &&+ !startsWithSlashCommand &&!reconcilePersistText.startsWith('[UI_ACTION_TRIGGER]');const planReconcileNote = isOrdinaryUserTurn? ((await deps.peekPlanReconcileNote?.(sessionId).catch(() => null)) ?? null)diff --git a/packages/maker-shared/src/__tests__/planCompletion.test.ts b/packages/maker-shared/src/__tests__/planCompletion.test.tsindex 6d864869fb..d095760d69 100644--- a/packages/maker-shared/src/__tests__/planCompletion.test.ts+++ b/packages/maker-shared/src/__tests__/planCompletion.test.ts@@ -294,6 +294,36 @@ describe('markCodexPlanTurnFailed', () => {expect(metaResult.messages[0]).toMatchObject({ turnCompleted: false });});+ it('does not stop the failure scan at a synthetic (auto-resume / scheduler / subagent) user row', () => {+ // 计划 → 自动续跑的合成 user 行 → 终态 error:合成行不是"用户开口",回扫+ // 必须穿过它命中本轮计划,否则全勾完的失败计划先按旧数据退场、等 main 的+ // 异步印记广播才复活(手机端断连要到重新加载,review P2)。判据与计划分组+ // 边界共用同一份,四类合成形态逐一覆盖。+ const syntheticRows = [+ { clientId: 'u-auto', agentMeta: { autoResume: true } },+ { clientId: 'u-sched', agentMeta: { origin: 'scheduler' } },+ { clientId: 'u-proj', isSyntheticTrigger: true },+ { clientId: 'u-auto-origin', automationOrigin: 'cron' },+ { clientId: 'u-sub', agentMeta: { parentUuid: 'toolu_01AbCdEf' } },+ ];+ for (const extra of syntheticRows) {+ const plan = planMessage(`plan:${extra.clientId}`, [{ step: 'Ship', status: 'completed' }]);+ const result = markCodexPlanTurnFailed([+ plan,+ { role: 'user' as const, content: 'continue', ...extra },+ ]);+ expect(result.changed, extra.clientId).toBe(true);+ expect(result.messages[0]).toMatchObject({ turnCompleted: false });+ }++ // 普通 user 行仍是硬边界:上一段历史里的计划不得被本轮失败顺手盖印记。+ const historic = planMessage('plan:historic', [{ step: 'Ship', status: 'completed' }]);+ expect(markCodexPlanTurnFailed([+ historic,+ { role: 'user' as const, clientId: 'u-real', content: '换个话题' },+ ]).changed).toBe(false);+ });+it('never reaches past the latest user message into an older turn plan', () => {// 所有权边界:本次失败的 turn 没发过 update_plan 时,不得把上一段历史里// 未盖章的旧计划(如升级前已全勾完退场的行)标成失败复活——main 侧对应diff --git a/packages/maker-shared/src/messageRender.ts b/packages/maker-shared/src/messageRender.tsindex c3c6702be5..23c8567955 100644--- a/packages/maker-shared/src/messageRender.ts+++ b/packages/maker-shared/src/messageRender.ts@@ -466,6 +466,36 @@ export function dedupeToolMediaByUrl<TMedia extends MessageRenderToolMediaLike>(return out;}+/**+ * 计划所有权的**唯一** user 边界判据:这个 user 行是不是"用户真的开口"的反面。+ *+ * 落在 user 行上但不构成边界的四类:+ * - 自动续跑 / scheduler 定时消息(agentMeta.autoResume / origin;desktop 渲染层+ * 投影成 isSyntheticTrigger / automationOrigin 后丢弃原 meta,两套字段都认):+ * 同一件事的延续,当边界会把进行中的计划切成新 session、历史里出现重复计划卡;+ * - 同轮 steer 插话:turn 还在跑,用户在指挥进行中的活,不是开新话题+ * (MessageStream 的 turn 分组同样把 steer 排除在新 turn 边界外);+ * - 子代理内部的 user 行(带 parentUuid / parentToolUseId):子任务的输入,当边界+ * 会顶掉主线程计划、换 key 重挂载 TodoListCard。+ *+ * **计划分组(findMessageTodoInsertions)与失败回扫(markCodexPlanTurnFailed)共用+ * 这一份判据**。两边各自推导过一次,结果是回扫只豁免了 steer:计划之后经过一次+ * 自动续跑再以 terminal error 收尾时,回扫在合成 user 行上提前 break、够不到本轮+ * 计划,全勾完的失败计划先按旧数据退场,等 main 的异步印记广播才复活(手机端断连+ * 则要到重新加载,review P2)。+ */+function isSyntheticUserRow(message: MessageRenderSourceMessageLike): boolean {+ const meta = message.agentMeta;+ return (+ message.isSyntheticTrigger === true ||+ (message.automationOrigin !== undefined && message.automationOrigin !== null) ||+ meta?.autoResume === true ||+ (meta?.origin !== undefined && meta?.origin !== null) ||+ isSteerUserRow(message) ||+ hasSubagentParent(message)+ );+}+/*** 子代理归属判定:desktop 投影出顶层 parentToolUseId;mobile / main 原始行只有* agentMeta.parentUuid。二者任一存在即视为子代理内部消息。@@ -521,26 +551,7 @@ export function findMessageTodoInsertions<TMessage extends MessageRenderSourceMefor (let index = 0; index < messages.length; index++) {const message = messages[index];if (message.role === 'user') {- // 只有"用户真的开口"才是所有权边界。自动续跑与 scheduler 定时消息落的- // 也是 user 行,但那是同一件事的延续,不能把进行中的计划切成新 session- // (否则历史里出现重复计划卡)。两套字段都认:main/mobile 路径消息带- // agentMeta(autoResume/origin);desktop 渲染层把 agentMeta 投影成- // isSyntheticTrigger / automationOrigin 后丢弃原 meta。- const meta = message.agentMeta;- const syntheticUserRow =- message.isSyntheticTrigger === true ||- (message.automationOrigin !== undefined && message.automationOrigin !== null) ||- meta?.autoResume === true ||- (meta?.origin !== undefined && meta?.origin !== null) ||- // 同轮 steer 插话:turn 还在跑,用户在指挥进行中的活,不是开新话题- // (MessageStream 的 turn 分组同样把 steer 排除在新 turn 边界外)。当- // 边界会让插话后的 TaskCreate 清掉本轮 taskState、TodoWrite 换 key。- isSteerUserRow(message) ||- // 子代理内部的 user 行(带 parentUuid/parentToolUseId)是子任务的输入,- // 不是用户开新话题——当边界会把主线程进行中的计划切成新 session、换 key- // 重挂载 TodoListCard。- hasSubagentParent(message);- if (!syntheticUserRow) lastUserIndex = index;+ if (!isSyntheticUserRow(message)) lastUserIndex = index;continue;}const source = agentPlanSource(toolNameOf(message));@@ -837,10 +848,12 @@ function isSteerUserRow(message: MessageRenderSourceMessageLike): boolean {* Ownership boundary: only rows inside the failing turn's segment — after the* latest turn-starting user message — may be stamped. Codex plan rows are* per-turn (`plan:<turnId>` is created within its own turn), so the scan stops- * cold at the first user row that started a turn. A mid-turn steer interjection- * (`delivery: 'steer'`) does NOT start a new turn — the vendor turn keeps- * running and its plan row stays owned by the same turn — so steer rows do not- * end the scan. A failed turn that never emitted `update_plan` stamps nothing;+ * cold at the first user row that started a turn. What counts as "started a+ * turn" is `isSyntheticUserRow`'s negation — the same predicate the plan+ * grouping boundary uses, so steer interjections, auto-resume / scheduler+ * dispatches, and subagent-internal user rows all keep the scan going instead of+ * each surface re-deriving its own list. A failed turn that never emitted+ * `update_plan` stamps nothing;* reaching past the boundary would resurrect an unrelated historical plan* (pre-seal-era all-done rows retire via the legacy fallback, and a stray* failure stamp would flip them back to "alive" with no durable write to@@ -851,7 +864,7 @@ export function markCodexPlanTurnFailed<TMessage extends MessageRenderSourceMess): { messages: readonly TMessage[]; changed: boolean; toolUseId: string | null } {for (let index = messages.length - 1; index >= 0; index -= 1) {const message = messages[index];- if (message.role === 'user' && !isSteerUserRow(message)) break;+ if (message.role === 'user' && !isSyntheticUserRow(message)) break;if (message.role !== 'tool_use' || toolNameOf(message) !== 'update_plan') continue;if (planRowSealOf(message).sealed || planRowTurnFailed(message)) {return { messages, changed: false, toolUseId: null };