🐛 fix(vscode): 导入/恢复会话时从 transcript 推断 profilePath

This commit is contained in:
2026-07-25 01:59:22 +08:00
parent 45b2a7797d
commit e9543d37ce
+15 -2
View File
@@ -6,6 +6,7 @@ import { pollForNewSession, projectsDirFor } from '../../cc/sessionWatcher'
import { logger } from '../../logging/logger' import { logger } from '../../logging/logger'
import { listImportableNamedSessions } from '../../sessions/importableNamedSessions' import { listImportableNamedSessions } from '../../sessions/importableNamedSessions'
import { readManagedSessions, writeManagedSessions } from '../../sessions/managedStore' import { readManagedSessions, writeManagedSessions } from '../../sessions/managedStore'
import { inferProfilePathForSession } from '../../sessions/sessionProfileInference'
import { resolveProfilePath } from '../../cc/profiles' import { resolveProfilePath } from '../../cc/profiles'
/** 默认会话名:有 prompt 取前 20 字符,否则用短 id(前 8 位)。 */ /** 默认会话名:有 prompt 取前 20 字符,否则用短 id(前 8 位)。 */
@@ -221,8 +222,18 @@ export async function handleManagedSessionsResume(panel: KanbanWebviewPanel, ses
const data = await readManagedSessions(workspaceRoot) const data = await readManagedSessions(workspaceRoot)
const target = data.sessions.find(s => s.id === sessionId) const target = data.sessions.find(s => s.id === sessionId)
// store 缺 profilePath 时从 transcript 推断并回写,避免 resume 落到 default profile。
let storedProfile = target?.profilePath
if ((!storedProfile || storedProfile.trim() === '') && target) {
const inferred = await inferProfilePathForSession(sessionId, projectsDirFor(workspaceRoot))
if (inferred) {
storedProfile = inferred
target.profilePath = inferred
await writeManagedSessions(workspaceRoot, data)
}
}
const effectiveProfilePath = resolveProfilePath( const effectiveProfilePath = resolveProfilePath(
target?.profilePath && target.profilePath.trim() !== '' ? target.profilePath : undefined, storedProfile && storedProfile.trim() !== '' ? storedProfile : undefined,
) )
if (effectiveProfilePath.includes('\'')) { if (effectiveProfilePath.includes('\'')) {
void window.showErrorMessage( void window.showErrorMessage(
@@ -286,7 +297,7 @@ export async function handleManagedSessionsListImportable(panel: KanbanWebviewPa
} }
/** /**
* 把已 /rename 的会话登记进 managed store写 profilePath不 resume)。 * 把已 /rename 的会话登记进 managed store推断成功时写 profilePath不 resume)。
* id 已存在时幂等,仍推送全量列表。 * id 已存在时幂等,仍推送全量列表。
*/ */
export async function handleManagedSessionsImport( export async function handleManagedSessionsImport(
@@ -307,10 +318,12 @@ export async function handleManagedSessionsImport(
const data = await readManagedSessions(workspaceRoot) const data = await readManagedSessions(workspaceRoot)
const existing = data.sessions.find(s => s.id === trimmedId) const existing = data.sessions.find(s => s.id === trimmedId)
if (!existing) { if (!existing) {
const inferred = await inferProfilePathForSession(trimmedId, projectsDirFor(workspaceRoot))
data.sessions.push({ data.sessions.push({
id: trimmedId, id: trimmedId,
name: trimmedName, name: trimmedName,
createdAt: Date.now(), createdAt: Date.now(),
...(inferred ? { profilePath: inferred } : {}),
}) })
await writeManagedSessions(workspaceRoot, data) await writeManagedSessions(workspaceRoot, data)
} }