Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(pet): goal 自动续跑轮的中间轮不再判成功

hairyf677f66e80439
diff --git a/packages/dsh-tauri-pet/src/host/service/session-stream.types.ts b/packages/dsh-tauri-pet/src/host/service/session-stream.types.ts
index 282de57e..f9d8042a 100644
--- a/packages/dsh-tauri-pet/src/host/service/session-stream.types.ts
+++ b/packages/dsh-tauri-pet/src/host/service/session-stream.types.ts
@@ -14,6 +14,9 @@ export interface PetSessionEvent {
data?: Record<string, unknown>
}
+/** goal 自动续跑轮的收尾动作(`update_goal` 的 action)。 */
+export type PetGoalClosing = 'complete' | 'blocked'
+
/** 从真实 session 对象上读取的最小输入(与运行时形状解耦)。 */
export interface PetSessionPeer {
id: string
@@ -46,6 +49,10 @@ export interface PetSessionState {
/** 当前「等用户回答」的问句工具调用 id。 */
waitingCallId?: string
workStatus?: PetWorkStatus
+ /** 本回合是否为 goal 自动续跑轮(`user/message` 的 `source.kind==='goal'` 且 `round>0`)。 */
+ goalRound?: boolean
+ /** 本回合内 `update_goal` 声明的收尾动作;未声明 = 目标仍在推进。 */
+ goalClosing?: PetGoalClosing
/** 当前任务文本(todo/write 的 in_progress/pending 项 content)。 */
task?: string
/** 当前工具活动分类(最近一次 working 工具名分类)。 */
diff --git a/packages/dsh-tauri-pet/src/host/service/session-stream.utils.test.ts b/packages/dsh-tauri-pet/src/host/service/session-stream.utils.test.ts
index 93504b55..a81ab0a7 100644
--- a/packages/dsh-tauri-pet/src/host/service/session-stream.utils.test.ts
+++ b/packages/dsh-tauri-pet/src/host/service/session-stream.utils.test.ts
@@ -168,6 +168,78 @@ describe('petSessionReducer (host)', () => {
expect(last.payload.status).toBeUndefined()
})
+ it('goal 续跑轮(source.round>0)未声明收尾时 turn/end(completed) 只到 result,不播雀跃庆祝', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 2 }, 1))
+ reducer.apply(peer(), ev('user/message', { source: { kind: 'goal', goalId: 'g1', revision: 1, round: 1 } }, 2))
+ reducer.apply(peer(), ev('turn/end', { turn: 2, reason: { kind: 'completed' } }, 3))
+ expect(pushes.at(-1)!.payload).toMatchObject({ running: false, workStatus: 'result' })
+ })
+
+ it('goal 续跑轮以 update_goal complete 收尾 → workStatus=success', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 2 }, 1))
+ reducer.apply(peer(), ev('user/message', { source: { kind: 'goal', goalId: 'g1', revision: 1, round: 1 } }, 2))
+ reducer.apply(peer(), ev('tool/call', { turn: 2, step: 1, callId: 'c1', name: 'update_goal', arguments: '{"action":"complete"}' }, 3))
+ reducer.apply(peer(), ev('turn/end', { turn: 2, reason: { kind: 'completed' } }, 4))
+ expect(pushes.at(-1)!.payload).toMatchObject({ workStatus: 'success' })
+ })
+
+ it('goal 续跑轮以 update_goal blocked 收尾 → workStatus=error,但不写 lastAgentError(阻塞非崩溃)', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 2 }, 1))
+ reducer.apply(peer(), ev('user/message', { source: { kind: 'goal', goalId: 'g1', revision: 1, round: 1 } }, 2))
+ reducer.apply(peer(), ev('tool/call', { turn: 2, step: 1, callId: 'c1', name: 'update_goal', arguments: '{"action":"blocked","blocked_reason":"x"}' }, 3))
+ reducer.apply(peer(), ev('turn/end', { turn: 2, reason: { kind: 'completed' } }, 4))
+ const last = pushes.at(-1)!
+ expect(last.payload).toMatchObject({ workStatus: 'error' })
+ expect(last.payload.lastAgentError).toBeUndefined()
+ expect(last.payload.status).toBeUndefined()
+ })
+
+ it('goal 激活轮(round=0)不是续跑轮 → turn/end(completed) 仍为 success', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
+ reducer.apply(peer(), ev('user/message', { source: { kind: 'goal', goalId: 'g1', revision: 1, round: 0 } }, 2))
+ reducer.apply(peer(), ev('turn/end', { turn: 1, reason: { kind: 'completed' } }, 3))
+ expect(pushes.at(-1)!.payload).toMatchObject({ workStatus: 'success' })
+ })
+
+ it('非 goal 轮的 update_goal 不影响终局档位(普通回合仍 success)', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
+ reducer.apply(peer(), ev('tool/call', { turn: 1, step: 1, callId: 'c1', name: 'update_goal', arguments: '{"action":"blocked"}' }, 2))
+ reducer.apply(peer(), ev('turn/end', { turn: 1, reason: { kind: 'completed' } }, 3))
+ expect(pushes.at(-1)!.payload).toMatchObject({ workStatus: 'success' })
+ })
+
+ it('goal 标志随回合失效:续跑轮 result 后,下一普通轮 completed 回到 success', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 2 }, 1))
+ reducer.apply(peer(), ev('user/message', { source: { kind: 'goal', goalId: 'g1', revision: 1, round: 1 } }, 2))
+ reducer.apply(peer(), ev('turn/end', { turn: 2, reason: { kind: 'completed' } }, 3))
+ expect(pushes.at(-1)!.payload).toMatchObject({ workStatus: 'result' })
+ reducer.apply(peer(), ev('turn/start', { turn: 3 }, 4))
+ reducer.apply(peer(), ev('turn/end', { turn: 3, reason: { kind: 'completed' } }, 5))
+ expect(pushes.at(-1)!.payload).toMatchObject({ workStatus: 'success' })
+ })
+
+ it('update_goal 参数不可解析时不当作收尾(续跑轮仍只到 result)', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 2 }, 1))
+ reducer.apply(peer(), ev('user/message', { source: { kind: 'goal', goalId: 'g1', revision: 1, round: 2 } }, 2))
+ reducer.apply(peer(), ev('tool/call', { turn: 2, step: 1, callId: 'c1', name: 'update_goal', arguments: '{oops' }, 3))
+ reducer.apply(peer(), ev('turn/end', { turn: 2, reason: { kind: 'completed' } }, 4))
+ expect(pushes.at(-1)!.payload).toMatchObject({ workStatus: 'result' })
+ })
+
it('tool/result 的工具级错误不写入 lastAgentError(回合仍在跑时不得判 failed 收起气泡)', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
diff --git a/packages/dsh-tauri-pet/src/host/service/session-stream.utils.ts b/packages/dsh-tauri-pet/src/host/service/session-stream.utils.ts
index 14a4c1e8..fee5fa5b 100644
--- a/packages/dsh-tauri-pet/src/host/service/session-stream.utils.ts
+++ b/packages/dsh-tauri-pet/src/host/service/session-stream.utils.ts
@@ -1,5 +1,10 @@
-import type { PetSessionPayload, PetToolActivity } from '../types'
-import type { PetSessionEvent, PetSessionPeer, PetSessionState } from './session-stream.types'
+import type { PetSessionPayload, PetToolActivity, PetWorkStatus } from '../types'
+import type {
+ PetGoalClosing,
+ PetSessionEvent,
+ PetSessionPeer,
+ PetSessionState,
+} from './session-stream.types'
/** 推理文本滚动尾部窗口字符数:超出后丢弃最早内容,供气泡「思考 · text」实时滚动展示。 */
export const PET_REASONING_TAIL_WINDOW = 120
@@ -210,6 +215,42 @@ function toolActivityOf(name?: string): PetToolActivity {
return 'using-tool'
}
+/**
+ * 本回合是否为 goal **自动续跑轮**:`user/message` 的 source 标记 `kind === 'goal'` 且 `round > 0`。
+ *
+ * `round === 0` 是用户 `/goal` 触发的激活轮(内核 `isGoalRound` 同样只把 `round > 0` 计入续跑轮),
+ * 其终局语义按普通回合处理。
+ */
+function isGoalRoundEvent(data: Record<string, unknown>): boolean {
+ const source = data.source as { kind?: string, round?: number } | undefined
+ return source?.kind === 'goal' && typeof source.round === 'number' && source.round > 0
+}
+
+/** `update_goal` 调用声明的收尾动作;`edit`/`pause`/`resume` 不算收尾,参数不可解析时忽略。 */
+function goalClosingOf(name: string | undefined, args: string | undefined): PetGoalClosing | undefined {
+ if (name !== 'update_goal')
+ return undefined
+ try {
+ const action = (JSON.parse(args ?? '') as { action?: string }).action
+ return action === 'complete' || action === 'blocked' ? action : undefined
+ }
+ catch {
+ return undefined
+ }
+}
+
+/**
+ * 回合终局档位:goal 续跑轮的**中间轮**只到 `result`(目标仍在推进,不得播雀跃庆祝)。
+ * 非 goal 轮维持 `success`;续跑轮以 `update_goal` 收尾时按收尾动作定档。
+ */
+function completedStatus(state: PetSessionState): PetWorkStatus {
+ if (!state.goalRound)
+ return 'success'
+ if (state.goalClosing === 'blocked')
+ return 'error'
+ return state.goalClosing === 'complete' ? 'success' : 'result'
+}
+
/** 从 todo/write 提取当前任务文本(in_progress 优先、其次 pending)。 */
function currentTaskFromTodo(data: Record<string, unknown>): string | undefined {
const todos = Array.isArray(data.todos) ? (data.todos as Array<{ status?: string, content?: string }>) : []
@@ -294,6 +335,9 @@ function reduceSessionEvent(
case 'tool/call': {
const call = data as { callId?: string, name?: string, arguments?: string }
const name = call.name
+ const closing = goalClosingOf(name, call.arguments)
+ if (closing)
+ state.goalClosing = closing
// 携带原始 arguments JSON 字符串,供气泡解析 command/path。
if (name)
state.openTools.set(call.callId ?? name, { name, args: call.arguments })
@@ -355,6 +399,8 @@ function reduceSessionEvent(
}
case 'user/message': {
// 用户消息只标记会话活跃,不写入展示 message(避免把用户提示当成助手描述)。
+ if (isGoalRoundEvent(data))
+ state.goalRound = true
state.running = true
state.turnActive = true
if (state.waitingCallId !== undefined) {
@@ -397,7 +443,7 @@ function reduceSessionEvent(
else {
state.waitingKind = undefined
if (reason?.kind === 'completed') {
- state.workStatus = 'success'
+ state.workStatus = completedStatus(state)
state.lastAgentError = undefined
}
else if (reason?.kind === 'error' || reason?.kind === 'max-tokens' || reason?.kind === 'timeout') {
@@ -410,6 +456,9 @@ function reduceSessionEvent(
settleIdle(state)
}
}
+ // 回合级 goal 标志随回合结束失效:新一轮的 source/update_goal 各自重新声明。
+ state.goalRound = false
+ state.goalClosing = undefined
break
}
default:
@@ -442,6 +491,8 @@ function settleIdle(state: PetSessionState): void {
state.waitingCallId = undefined
state.workStatus = undefined
state.lastAgentError = undefined
+ state.goalRound = false
+ state.goalClosing = undefined
}
/** 会话是否仍处于「回合内」(只有这种状态才允许被 idle 兜底改写)。 */