🐛 fix(vscode): 导入/恢复会话时从 transcript 推断 profilePath
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user