🐛 fix(vscode): 代码阅读问 AI 不再按总时长停,连续 5 分钟(重写注释 10 分钟)没有任何输出才停;新会话的 id 由扩展定好(--session-id)、起进程前就记在这一处,没答完就超时、出错、被叫停的那一轮说「继续」也 --resume 同一个会话接着做,会话找不到才按完整问题重开

This commit is contained in:
cruldra committed 2026-10-14 20:46:36 +11:00
1 parent a0c3df3bca
commit 20da8da4c9
17 files changed
+803 -277

No files matched your search

+3 -9
View File
@@ -245,12 +245,12 @@ export function commentFollowUp(path: string, startLine: number, endLine: number
/**
* 从 claude 的 stream-json 输出里读出来的:text 是注释正文到现在为止写出来的(结构化结果逐字长出来),activity 是正在做的事(「读取 routes.py」),
* result 是答完了(body 是结构化结果里的正文,没按 COMMENT_SCHEMA 交回、正文是空的时没有;sessionId 是这次的会话),error 是 Claude Code 自己报的失败。
* result 是答完了(body 是结构化结果里的正文,没按 COMMENT_SCHEMA 交回、正文是空的时没有),error 是 Claude Code 自己报的失败。
*/
export type CommentEvent
= | { kind: 'text', text: string }
| { kind: 'activity', label: string }
| { kind: 'result', body?: string, sessionId: string }
| { kind: 'result', body?: string }
| { kind: 'error', message: string }
function isRecord(value: unknown): value is Record<string, unknown> {
@@ -290,8 +290,6 @@ export function createCommentParser(): (line: string) => CommentEvent[] {
/** 正在写的结构化结果(工具输入的 JSON 原文);不在写时没有 */
let json: string | undefined
let text = ''
/** 开头 init 行报的会话 id;result 行没带时用它 */
let sessionId = ''
const grow = (body: string | undefined): CommentEvent[] => {
if (body === undefined || body === text)
return []
@@ -328,10 +326,6 @@ export function createCommentParser(): (line: string) => CommentEvent[] {
// 子代理的消息(parent_tool_use_id 不空)不是这次的结果
if (!isRecord(line) || (line.parent_tool_use_id !== undefined && line.parent_tool_use_id !== null))
return []
if (line.type === 'system' && line.subtype === 'init') {
sessionId = str(line.session_id)
return []
}
if (line.type === 'stream_event')
return isRecord(line.event) ? streamEvent(line.event) : []
if (line.type === 'assistant')
@@ -343,7 +337,7 @@ export function createCommentParser(): (line: string) => CommentEvent[] {
return [{ kind: 'error', message: str(line.result).trim() || errors || str(line.subtype) || '没说原因' }]
}
const body = bodyOf(line.structured_output)
return [{ kind: 'result', ...(body !== undefined && { body }), sessionId: str(line.session_id) || sessionId }]
return [{ kind: 'result', ...(body !== undefined && { body }) }]
}
}