feat(vscode): 会话管理支持导入已 /rename 的命名会话

This commit is contained in:
2026-07-24 00:12:28 +08:00
parent 7c67d220db
commit dc522064ce
10 changed files with 438 additions and 9 deletions
+8
View File
@@ -556,6 +556,14 @@ export class KanbanWebviewPanel {
managedSessions.handleManagedSessionsCloseTab(this, msg.sessionId)
return
}
if (msg.type === 'managed-sessions/list-importable') {
void managedSessions.handleManagedSessionsListImportable(this)
return
}
if (msg.type === 'managed-sessions/import') {
void managedSessions.handleManagedSessionsImport(this, msg.sessionId, msg.name)
return
}
if (msg.type === 'pr-files/get') {
void prFiles.handleGetPrFiles(this, msg.issueNumber)
return
@@ -4,6 +4,7 @@ import { window, workspace } from 'vscode'
import { buildCcCommand } from '../../cc/ccCommand'
import { pollForNewSession, projectsDirFor } from '../../cc/sessionWatcher'
import { logger } from '../../logging/logger'
import { listImportableNamedSessions } from '../../sessions/importableNamedSessions'
import { readManagedSessions, writeManagedSessions } from '../../sessions/managedStore'
import { resolveProfilePath } from '../../cc/profiles'
@@ -270,3 +271,48 @@ export async function handleManagedSessionsDelete(panel: KanbanWebviewPanel, ses
panel.managedTerminals.delete(sessionId)
await pushManagedSessions(panel)
}
/**
* 列出当前工作区可导入的命名会话(jsonl 有 custom-title 且尚未在 managed store)。
*/
export async function handleManagedSessionsListImportable(panel: KanbanWebviewPanel): Promise<void> {
const workspaceRoot = workspace.workspaceFolders?.[0]?.uri.fsPath
if (!workspaceRoot) {
panel.postMessage({ type: 'managed-sessions/importable', sessions: [] })
return
}
const sessions = await listImportableNamedSessions(workspaceRoot)
panel.postMessage({ type: 'managed-sessions/importable', sessions })
}
/**
* 把已 /rename 的会话登记进 managed store(不写 profilePath、不 resume)。
* id 已存在时幂等,仍推送全量列表。
*/
export async function handleManagedSessionsImport(
panel: KanbanWebviewPanel,
sessionId: string,
name: string,
): Promise<void> {
const workspaceRoot = workspace.workspaceFolders?.[0]?.uri.fsPath
if (!workspaceRoot) {
void window.showErrorMessage('请先打开一个工作区文件夹')
return
}
const trimmedId = sessionId.trim()
const trimmedName = name.trim()
if (!trimmedId || !trimmedName)
return
const data = await readManagedSessions(workspaceRoot)
const existing = data.sessions.find(s => s.id === trimmedId)
if (!existing) {
data.sessions.push({
id: trimmedId,
name: trimmedName,
createdAt: Date.now(),
})
await writeManagedSessions(workspaceRoot, data)
}
await pushManagedSessions(panel)
}
+3
View File
@@ -104,6 +104,7 @@ export type ExtensionToWebview
| { type: 'issue/remove', issueNumber: number }
| { type: 'profiles/show', data: ProfilesData }
| { type: 'managed-sessions/show', data: ManagedSessionsShowData }
| { type: 'managed-sessions/importable', sessions: Array<{ id: string, name: string, mtimeMs: number }> }
| { type: 'pr-files/show', issueNumber: number, files: PrFile[], confirmed: string[], summaries: Record<string, string>, error?: string }
| { type: 'pr-file-diff/show', issueNumber: number, path: string, oldContent: string, newContent: string, oldLang?: string, newLang?: string, error?: string }
| { type: 'pr-file-summary/show', issueNumber: number, path: string, summary?: string, error?: string }
@@ -185,6 +186,8 @@ export type WebviewToExtension
| { type: 'managed-sessions/resume', sessionId: string }
| { type: 'managed-sessions/delete', sessionId: string }
| { type: 'managed-sessions/close-tab', sessionId: string }
| { type: 'managed-sessions/list-importable' }
| { type: 'managed-sessions/import', sessionId: string, name: string }
| { type: 'pr-files/get', issueNumber: number }
| { type: 'pr-file-diff/get', issueNumber: number, path: string, previousPath?: string }
| { type: 'pr-file-summary/generate', issueNumber: number, path: string, previousPath?: string }