✨ feat(vscode): 改动说明 profile 可配置

This commit is contained in:
cruldra committed 2026-08-28 06:38:02 +08:00
1 parent 77037924ef
commit 443a8e472a
14 files changed
+137 -37

No files matched your search

+29 -12
View File
@@ -8,18 +8,22 @@
* 404 兜底空串,故新增/删除/改名天然成立。
*/
import type { PrDiffMode } from '../../cc/prDiffMode'
import type { KanbanWebviewPanel } from '../KanbanPanel'
import { accessSync, constants } from 'node:fs'
import { createPatch } from 'diff'
import { workspace } from 'vscode'
import { getToken } from '../../auth/secrets'
import { listClaudeProfiles } from '../../cc/profiles'
import { resolveCommitProfileForRun } from '../../cc/commitProfile'
import { parsePrDiffMode } from '../../cc/prDiffMode'
import { resolveProfilePath } from '../../cc/profiles'
import { spawnClaude } from '../../cc/spawnClaude'
import { detectRepo } from '../../git/remote'
import { getPullRequest, getRawFile, listPullRequestFiles } from '../../gitea/api'
import { readStateJsonComment } from '../../gitea/stateJson'
import { readFileSummaries, readSummarySession, writeFileSummary, writeSummarySession } from '../../sessions/prFileSummaryStore'
import { readConfirmedSigs, writeConfirmedSigs } from '../../sessions/prReviewStore'
import { parsePrDiffMode, type PrDiffMode } from '../../cc/prDiffMode'
import { getEffectivePrDiffSummaryProfilePath } from '../../settings/store'
import { makeNonce } from '../KanbanPanel'
/**
@@ -259,7 +263,7 @@ function buildSummaryPrompt(prNumber: number, prBody: string, filePath: string,
}
/**
* 用 deepseek 给单个文件生成「一句话说明改了什么」的改动说明。增量复用同一会话:首个文件开新会话并把
* 给单个文件生成「一句话说明改了什么」的改动说明。增量复用同一会话:首个文件开新会话并把
* sessionId 记到 `.spx/pr-file-summaries.json`,后续文件 `--resume` 接上去,省去每次重新理解
* PR 的开销。说明也落盘,重载后仍显示。
*
@@ -279,18 +283,32 @@ export async function handleGeneratePrFileSummary(
return
}
// deepseek profile 与「一键提交」同一来源;缺失则提示用户创建并清掉前端 loading。
const profiles = await listClaudeProfiles()
const deepseek = profiles.find(p => p.name === 'deepseek-v4-pro')
if (!deepseek) {
const raw = await getEffectivePrDiffSummaryProfilePath(panel.context)
const resolution = resolveCommitProfileForRun(
raw,
resolveProfilePath,
(p) => {
try {
accessSync(p, constants.R_OK)
return true
}
catch {
return false
}
},
)
if (!resolution.ok) {
const message = resolution.reason === 'empty'
? '未配置改动说明 profile,请在设置中选择'
: `改动说明 profile 不可用:${resolution.profilePath}`
panel.postMessage({
type: 'toast/show',
id: makeNonce(),
level: 'error',
message: '未找到 deepseek profile(deepseek-v4-pro / deepseek),请在 Claude profiles 目录下创建对应 .json',
message,
dismissOnTimer: 8000,
})
panel.postMessage({ type: 'pr-file-summary/show', issueNumber, path: filePath, error: '未找到 deepseek profile' })
panel.postMessage({ type: 'pr-file-summary/show', issueNumber, path: filePath, error: message })
return
}
@@ -315,7 +333,7 @@ export async function handleGeneratePrFileSummary(
result = await spawnClaude({
prompt: buildSummaryPrompt(index, pr.body, filePath, patch, !prevSession),
cwd: workspaceRoot,
profilePath: deepseek.path,
profilePath: resolution.profilePath,
resumeSessionId: prevSession,
timeoutMs: 120_000,
})
@@ -328,7 +346,7 @@ export async function handleGeneratePrFileSummary(
result = await spawnClaude({
prompt: buildSummaryPrompt(index, pr.body, filePath, patch, true),
cwd: workspaceRoot,
profilePath: deepseek.path,
profilePath: resolution.profilePath,
timeoutMs: 120_000,
})
}
@@ -370,4 +388,3 @@ export async function handleSetPrDiffMode(
const next: PrDiffMode = parsePrDiffMode(mode)
await panel.context.workspaceState.update(PR_DIFF_MODE_KEY, next)
}