diff --git a/vscode/src/panel/handlers/managedSessions.ts b/vscode/src/panel/handlers/managedSessions.ts index db5ca68..74bfa75 100644 --- a/vscode/src/panel/handlers/managedSessions.ts +++ b/vscode/src/panel/handlers/managedSessions.ts @@ -6,6 +6,7 @@ import { pollForNewSession, projectsDirFor } from '../../cc/sessionWatcher' import { logger } from '../../logging/logger' import { listImportableNamedSessions } from '../../sessions/importableNamedSessions' import { readManagedSessions, writeManagedSessions } from '../../sessions/managedStore' +import { inferProfilePathForSession } from '../../sessions/sessionProfileInference' import { resolveProfilePath } from '../../cc/profiles' /** 默认会话名:有 prompt 取前 20 字符,否则用短 id(前 8 位)。 */ @@ -221,8 +222,18 @@ export async function handleManagedSessionsResume(panel: KanbanWebviewPanel, ses const data = await readManagedSessions(workspaceRoot) 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( - target?.profilePath && target.profilePath.trim() !== '' ? target.profilePath : undefined, + storedProfile && storedProfile.trim() !== '' ? storedProfile : undefined, ) if (effectiveProfilePath.includes('\'')) { void window.showErrorMessage( @@ -286,7 +297,7 @@ export async function handleManagedSessionsListImportable(panel: KanbanWebviewPa } /** - * 把已 /rename 的会话登记进 managed store(不写 profilePath、不 resume)。 + * 把已 /rename 的会话登记进 managed store(推断成功时写 profilePath,不 resume)。 * id 已存在时幂等,仍推送全量列表。 */ export async function handleManagedSessionsImport( @@ -307,10 +318,12 @@ export async function handleManagedSessionsImport( const data = await readManagedSessions(workspaceRoot) const existing = data.sessions.find(s => s.id === trimmedId) if (!existing) { + const inferred = await inferProfilePathForSession(trimmedId, projectsDirFor(workspaceRoot)) data.sessions.push({ id: trimmedId, name: trimmedName, createdAt: Date.now(), + ...(inferred ? { profilePath: inferred } : {}), }) await writeManagedSessions(workspaceRoot, data) }