Files
superwork/vscode/src/panel/autoReviewDecision.ts
T
2026-07-31 08:20:42 +08:00

28 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 自动审查启动路径决策(纯逻辑,不碰 VS Code API)。
*
* 与 TUI 对齐:只有已持久化 `reviewSessionId` 才走「再审」;
* 仅 tab 活着但还没有 session id,说明首次审查刚开、session 尚未落盘,
* 再注入 "PR 更新了,再审一下" 会污染首轮 prompt(opened 后紧跟 synchronize 的常见竞态)。
*/
export type AutoReviewPath = 'reuse' | 'resume' | 'new' | 'noop'
export function decideAutoReviewPath(opts: {
tabAlive: boolean
reviewSessionId: string | undefined
}): AutoReviewPath {
const hasSid = typeof opts.reviewSessionId === 'string' && opts.reviewSessionId.length > 0
// ① 有 session + tab 活着 → 往现有 TUI 注入再审
if (opts.tabAlive && hasSid)
return 'reuse'
// ② 有 session + tab 已关 → codex resume 后再注入
if (!opts.tabAlive && hasSid)
return 'resume'
// ③ tab 活着但无 session → 首次审查进行中,跳过
if (opts.tabAlive)
return 'noop'
// ④ 无 session、无 tab → 新建完整审查会话
return 'new'
}