mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 14:25:51 +00:00
fix(workflow): agent dead 带 reason/detail + prompt 加压 StructuredOutput
12 agent audit workflow 8 个 dead,journal 只记 {kind:"dead"} 无信息,
事后无法区分 "agent 没产 StructuredOutput" vs "runAgent 抛错"。
证据指向主因:sonnet 长 tool chain 后忘记调 StructuredOutput,
extractStructuredOutput 返回 null 即降级 dead。
- types.ts: AgentRunResult.dead 加可选 reason/detail 字段
(no-structured-output / runagent-threw / worktree-failed / unknown)
兼容旧 journal(均 optional)。
- claudeCodeBackend.ts: 三处 dead 填 reason + detail;
no-structured-output 把 finalized 文本前 200 字符做 detail,
让日志/面板能立刻看到 agent 最后说了什么。
- claudeCodeBackend.ts: schema 模式 prompt 首尾各放一次
StructuredOutput 强制要求,针对 sonnet 长 tool chain 后忘记收尾。
- hooks.ts: retry 日志带 reason;retry 仍 throw 时降级 dead 也填
reason=runagent-threw + detail。
- types.test.ts: 加 reason JSON 往返 + 旧 journal 兼容测试。
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
This commit is contained in:
@@ -19,6 +19,28 @@ test('AgentRunResult skipped/dead 分支可 JSON 往返', () => {
|
||||
}
|
||||
})
|
||||
|
||||
// dead 携带可选 reason/detail:journal 持久化后能保留死因,事后审计/面板展示用。
|
||||
test('AgentRunResult dead 带 reason/detail 可 JSON 往返', () => {
|
||||
const dead = {
|
||||
kind: 'dead' as const,
|
||||
reason: 'no-structured-output' as const,
|
||||
detail: 'finalize content has no StructuredOutput tool_use or JSON text',
|
||||
}
|
||||
const round = JSON.parse(JSON.stringify(dead))
|
||||
expect(round).toEqual(dead)
|
||||
expect(round.kind).toBe('dead')
|
||||
expect(round.reason).toBe('no-structured-output')
|
||||
})
|
||||
|
||||
// 兼容旧 journal:reason/detail 都可选,缺失时仍是合法 dead。
|
||||
test('AgentRunResult dead 无 reason 仍合法(兼容旧 journal)', () => {
|
||||
const legacy = { kind: 'dead' as const }
|
||||
const round = JSON.parse(JSON.stringify(legacy))
|
||||
expect(round.kind).toBe('dead')
|
||||
expect(round.reason).toBeUndefined()
|
||||
expect(round.detail).toBeUndefined()
|
||||
})
|
||||
|
||||
test('JournalEntry 形状稳定', () => {
|
||||
const entry = {
|
||||
key: 'abc123',
|
||||
|
||||
Reference in New Issue
Block a user