diff --git a/.playwright/scripts/__tests__/mobile-branches.e2e.mjs b/.playwright/scripts/__tests__/mobile-branches.e2e.mjs index b4c7d0010..f40c88611 100644 --- a/.playwright/scripts/__tests__/mobile-branches.e2e.mjs +++ b/.playwright/scripts/__tests__/mobile-branches.e2e.mjs @@ -202,10 +202,24 @@ test('Android and Desktop browse and run separate branches concurrently without const branchB = fork.branchId await expect.poll(() => read(db => db.prepare('SELECT status FROM runs WHERE id = ?').get(fork.runId).status)).toBe('completed') expect(branchB).not.toBe(branchA) - await page.locator('[data-testid="conversation-branches"]:visible').click() - await page.getByTestId(`conversation-branch-${branchB}`).click() - const branchView = page.locator('[data-testid="conversation-branches"]:visible') - await expect(branchView).toHaveAttribute('data-branch-id', branchB) + await page.reload() + const branchView = page.locator(`.workbench__view[data-resource-id="${conversationId}"]:visible`) + const expectBranch = async (branchId) => { + await expect(branchView).toBeVisible() + const viewId = await branchView.getAttribute('data-view-id') + await expect.poll(() => page.evaluate(async id => (await window.lexoraDesktop.workbench.read())?.layout.views[id]?.resource, viewId)).toMatchObject({ + scheme: 'task', + id: conversationId, + data: { branchId }, + }) + } + await expectBranch(branchA) + const originalMessage = branchView.locator('[data-message-id]').filter({ hasText: `Parallel baseline A ${token}` }) + await originalMessage.hover() + await expect(originalMessage.getByRole('group')).toHaveText('1 / 2') + await originalMessage.getByRole('button', { name: '下一条分支', exact: true }).click() + await expectBranch(branchB) + await expect(branchView.getByText(`历史 B 原文 ${token}`, { exact: false })).toBeVisible() const listener = createServer() await new Promise(resolve => listener.listen(0, bindAddress, resolve)) port = listener.address().port @@ -225,7 +239,7 @@ test('Android and Desktop browse and run separate branches concurrently without return value }) const phone = await checkpoint('phone-started') - await expect(branchView).toHaveAttribute('data-branch-id', branchB) + await expectBranch(branchB) await composer.fill(`Parallel branch B main ${token}`) await page.getByRole('button', { name: '发送消息', exact: true }).click() await expect.poll(() => requests.filter(value => value.phase === 'initial').map(value => value.branch).sort(), { timeout: 45000 }).toEqual(['A', 'B']) @@ -258,10 +272,10 @@ test('Android and Desktop browse and run separate branches concurrently without await expect.poll(() => questions(branchB), { timeout: 45000 }).toMatchObject([{ status: 'pending', branchId: branchB }]) await signal('questions-ready') expect(await checkpoint('views-isolated')).toMatchObject({ recreated: true }) - await expect(branchView).toHaveAttribute('data-branch-id', branchB) + await expectBranch(branchB) await expect(composer).toHaveText(desktopDraft) await page.reload() - await expect(branchView).toHaveAttribute('data-branch-id', branchB) + await expectBranch(branchB) await expect(composer).toHaveText(desktopDraft) await signal('answer-a') await checkpoint('answered-a') @@ -283,12 +297,12 @@ test('Android and Desktop browse and run separate branches concurrently without expect(edited.branchId).not.toBe(branchB) expect(read(db => db.prepare('SELECT status FROM runs WHERE id = ?').get(runB).status)).toBe('running') expect(read(db => db.prepare(`SELECT id, content_json FROM messages WHERE id IN (${originalRecords.map(() => '?').join(',')}) ORDER BY rowid`).all(...originalRecords.map(value => value.id)))).toEqual(originalRecords) - await expect(branchView).toHaveAttribute('data-branch-id', branchB) + await expectBranch(branchB) await expect(composer).toHaveText(desktopDraft) await signal('restore-a') expect(await checkpoint('reconnected-a')).toMatchObject({ draft: `手机 A 独立草稿😀 ${token}` }) await page.reload() - await expect(branchView).toHaveAttribute('data-branch-id', branchB) + await expectBranch(branchB) await expect(composer).toHaveText(desktopDraft) gates['B-result'].resolve() await expect.poll(() => read(db => db.prepare('SELECT status FROM runs WHERE id = ?').get(runB).status)).toBe('completed') diff --git a/.playwright/scripts/__tests__/workbench.e2e.mjs b/.playwright/scripts/__tests__/workbench.e2e.mjs index 093cdd0bd..b48cf5c5b 100644 --- a/.playwright/scripts/__tests__/workbench.e2e.mjs +++ b/.playwright/scripts/__tests__/workbench.e2e.mjs @@ -1,6 +1,7 @@ import fs from 'node:fs/promises' import path from 'node:path' import { expect, test } from '../fixtures/electron.mjs' +import { prepareMobileDesktopProfile } from '../fixtures/mobile-desktop.mjs' test('working copies preserve drafts, veto unsaved closure and recover across restart', async ({ buddy }) => { const instance = await buddy.createInstance('working-copy') @@ -157,9 +158,11 @@ test('task switching preserves drafts and ignores late loading results while fai expect(diagnostics.console.filter(item => item.type === 'pageerror')).toEqual([]) }) -async function prepareNotificationNavigation(buddy, label) { +async function prepareNotificationNavigation(buddy, label, profileOutput) { const instance = await buddy.createInstance(label) - const desktop = await instance.launch() + if (profileOutput) + await prepareMobileDesktopProfile(instance.home, profileOutput) + const desktop = await instance.launch({ storageAuthority: profileOutput ? 'sqlite' : 'legacy_jsonl' }) const window = await desktop.app.browserWindow(desktop.page) await expect.poll(() => desktop.page.evaluate(async () => (await window.lexoraDesktop.localChat.runtime.getStatus()).status), { timeout: 45000 }).toBe('ready') await window.evaluate(window => window.setSize(1600, 1000)) @@ -222,6 +225,74 @@ async function expectNotificationMessage(page, pane) { await expect(pane.locator('[data-message-id="message-b"]')).toHaveCount(0) } +test('history dragging moves the existing branch view and preserves both inputs across restart', async ({ buddy }, testInfo) => { + const desktop = await prepareNotificationNavigation(buddy, 'history-branch-drag', testInfo.outputPath('profile-preparation')) + let { page } = desktop + await notificationTask(page, 'a').click() + let first = notificationPane(page, 'a') + await first.locator('.desktop-chat-composer__prosemirror').fill('Draft A stays with its branch.') + await first.getByTestId('pane-layout-menu').click() + await page.locator('.n-dropdown-menu:visible').getByText('分屏', { exact: true }).hover() + await page.locator('.n-dropdown-menu:visible').getByText('向右分屏', { exact: true }).click() + const newPane = page.locator('.workbench-pane').filter({ has: page.getByRole('button', { name: '新任务', exact: true }) }) + await expect(newPane.locator('.desktop-chat-composer__prosemirror')).toBeVisible() + await notificationTask(page, 'b').click() + let second = notificationPane(page, 'b') + await second.locator('.desktop-chat-composer__prosemirror').fill('Draft B stays independent.') + const firstViewId = await first.locator('.workbench__view[data-resource-id="a"]').getAttribute('data-view-id') + const secondViewId = await second.locator('.workbench__view[data-resource-id="b"]').getAttribute('data-view-id') + await expect.poll(() => page.evaluate(async () => { + const saved = await window.lexoraDesktop.localChat.draftRecovery.load() + return saved.records.filter(record => ['conversation:a:branch-a', 'conversation:b:branch-b'].includes(record.snapshot.targetKey) + && record.snapshot.content.body.some(paragraph => paragraph.content.some(node => node.type === 'text' && node.text.startsWith('Draft ')))).length + })).toBe(2) + + const source = await notificationTask(page, 'a').boundingBox() + const target = await second.boundingBox() + expect(source).not.toBeNull() + expect(target).not.toBeNull() + await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2) + await page.mouse.down() + await page.mouse.move(target.x + target.width - 12, target.y + target.height / 2, { steps: 20 }) + await expect(second.locator('[data-drop-position="right"]')).toBeVisible() + await page.mouse.up() + await expect(page.locator('.workbench-pane')).toHaveCount(2) + await expect(first.locator('.workbench__view')).toHaveAttribute('data-view-id', firstViewId) + await expect(second.locator('.workbench__view')).toHaveAttribute('data-view-id', secondViewId) + await expect(first.locator('.desktop-chat-composer__prosemirror')).toHaveText('Draft A stays with its branch.') + await expect(second.locator('.desktop-chat-composer__prosemirror')).toHaveText('Draft B stays independent.') + expect((await first.boundingBox()).x).toBeGreaterThan((await second.boundingBox()).x) + await expect.poll(() => page.evaluate(async () => { + const layout = (await window.lexoraDesktop.workbench.read())?.layout + const ordered = node => node.kind === 'pane' ? [layout.views[node.view]?.resource.id] : [...ordered(node.first), ...ordered(node.second)] + return layout ? ordered(layout.root) : [] + })).toEqual(['b', 'a']) + + await desktop.instance.stop() + const restarted = await desktop.instance.launch({ storageAuthority: 'sqlite' }) + page = restarted.page + first = notificationPane(page, 'a') + second = notificationPane(page, 'b') + await expect(page.locator('.workbench-pane')).toHaveCount(2) + await notificationTask(page, 'b').click() + await expect(second.locator('.desktop-chat-composer__prosemirror')).toHaveText('Draft B stays independent.') + await notificationTask(page, 'a').click() + await expect(first.locator('.desktop-chat-composer__prosemirror')).toHaveText('Draft A stays with its branch.') + await expect(page.locator('.desktop-draft-restoration:visible')).toHaveCount(0) + await expect(page.getByRole('button', { name: '对话分支', exact: true })).toHaveCount(0) + expect((await first.boundingBox()).x).toBeGreaterThan((await second.boundingBox()).x) + await page.screenshot({ path: testInfo.outputPath('history-branch-drag.png') }) + await page.evaluate(() => window.lexoraDesktop.themes.request({ action: 'preference', preference: { id: 'lexora.themes.classic-dark' } })) + await expect(page.locator('html')).toHaveAttribute('data-buddy-theme', 'dark') + await page.screenshot({ path: testInfo.outputPath('history-branch-drag-dark.png') }) + const browserWindow = await restarted.app.browserWindow(page) + await browserWindow.evaluate(window => window.setSize(...window.getMinimumSize())) + await expect(first.locator('.desktop-chat-composer__prosemirror')).toBeVisible() + await expect(second.locator('.desktop-chat-composer__prosemirror')).toBeVisible() + await page.screenshot({ path: testInfo.outputPath('history-branch-drag-narrow.png') }) + expect([...desktop.diagnostics.console, ...restarted.diagnostics.console].filter(item => item.type === 'pageerror')).toEqual([]) +}) + test('notification targets reuse split panes and restore the task from settings without losing the other draft', async ({ buddy }) => { const { page, window, diagnostics } = await prepareNotificationNavigation(buddy, 'notification-split') await notificationTask(page, 'a').click() diff --git a/apps/buddy/src/app/workbench/__tests__/useTaskNavigation.spec.ts b/apps/buddy/src/app/workbench/__tests__/useTaskNavigation.spec.ts new file mode 100644 index 000000000..96f23fe07 --- /dev/null +++ b/apps/buddy/src/app/workbench/__tests__/useTaskNavigation.spec.ts @@ -0,0 +1,219 @@ +import type { LexoraDesktopApi } from '@buddy-electron/shared/desktopApi' +import type { TaskWorkspaceResource } from '../taskResource' +import type { TaskCapability } from '@/modules/tasks' +import type { SplitDirection } from '@/workbench/common/workbench' +import { afterEach, describe, expect, it } from 'vitest' +import { computed, effectScope, shallowRef } from 'vue' +import { createMemoryHistory, createRouter } from 'vue-router' +import { panes, resourceKey } from '@/workbench/common/workbench' +import { ContributionRegistry } from '@/workbench/services/ContributionRegistry' +import { WorkbenchController } from '@/workbench/services/WorkbenchController' +import { draftResource, taskResource } from '../taskResource' +import { TaskWorkspacePool } from '../TaskWorkspacePool' +import { useTaskNavigation } from '../useTaskNavigation' + +const cleanups: Array<() => Promise> = [] +afterEach(async () => { + for (const cleanup of cleanups.splice(0).reverse()) await cleanup() +}) + +async function fixture() { + const registry = new ContributionRegistry() + registry.register('tasks', scope => scope.view({ id: 'task', renderer: 'task', label: 'Task', locations: ['main'], supports: resource => ['task', 'draft'].includes(resource.scheme), multiple: false })) + let navigation: ReturnType + const controller = new WorkbenchController(registry, view => navigation.prepareClose(view)) + const api = { localChat: { + conversations: { + get: async (id: string) => ({ id, activeBranchId: `${id}-main`, spaceId: null, deletedAt: null }), + listBranches: async (id: string) => [`${id}-main`, `${id}-fork`].map(branchId => ({ id: branchId, conversationId: id })), + }, + } } as unknown as LexoraDesktopApi + const created: TaskCapability[] = [] + const disposed = new Set() + const draftText = shallowRef('unsent input') + const pool = new TaskWorkspacePool({ + conversations: api.localChat.conversations, + index: { ensureConversation: async () => {}, applyConversation: () => {} }, + createTask: ({ initialTarget }) => { + const task = { + initialize: async () => {}, + dispose: () => disposed.add(task), + workspace: { + restoration: { state: shallowRef('ready') }, + session: { activeConversationId: shallowRef(initialTarget.conversationId), activeBranchId: shallowRef(initialTarget.branchId) }, + composer: { hasUnsentContent: computed(() => !!draftText.value) }, + }, + } as unknown as TaskCapability + created.push(task) + return task + }, + }, (previous, _task, resource) => { + for (const view of Object.values(controller.layout.views)) { + if (resourceKey(view.resource) === resourceKey(previous)) + controller.updateView(view.id, { resource }) + } + }, async () => {}) + const subscription = controller.onDidChangeLayout(() => pool.retain(controller.renderedViews.map(view => view.resource))) + const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/tasks', component: {} }] }) + await router.push('/tasks') + const errors: unknown[] = [] + const decisions = { replacement: 'cancel' as 'cancel' | 'discard' | 'split', discard: false } + const scope = effectScope() + navigation = scope.run(() => useTaskNavigation({ + api, + controller, + pool, + router, + center: () => controller.layout.activePane, + chooseReplacement: async () => decisions.replacement, + confirmDiscard: async () => decisions.discard, + onError: error => errors.push(error), + }))! + cleanups.push(async () => { + scope.stop() + subscription.dispose() + await controller.dispose() + registry.dispose() + pool.dispose() + expect(errors).toEqual([]) + }) + async function open(resource: TaskWorkspaceResource, direction?: SplitDirection) { + await navigation.activateTask(resource, resource.id, { direction }) + return controller.context.view!.id + } + return { controller, pool, navigation, open, created, disposed, decisions, draftText } +} + +describe('task navigation resource identity', () => { + it.each(['left', 'right', 'up', 'down'] as const)('moves an opened history task to the %s edge without replacing its view or workspace', async (direction) => { + const f = await fixture() + const resource = taskResource('a', 'a-fork') + const source = await f.open(resource) + const original = f.pool.peek(resource) + f.controller.updateView(source, { state: { readingAnchor: 'message-1' } }) + const oldPane = f.controller.owner(source)!.id + const other = await f.open(taskResource('b'), 'right') + const targetPane = f.controller.owner(other)!.id + f.controller.setAuxiliary('taskBranches', { a: 'a-main' }) + + await f.navigation.activateTask(taskResource('a'), 'a', { paneId: targetPane, direction, move: true }) + + expect(Object.keys(f.controller.layout.views).sort()).toEqual([source, other].sort()) + expect(f.controller.context.view?.id).toBe(source) + expect(f.controller.layout.views[source]?.resource).toEqual(resource) + expect(f.controller.layout.views[source]?.state).toEqual({ readingAnchor: 'message-1' }) + expect(f.controller.pane(oldPane)).toBeNull() + expect(panes(f.controller.layout.root)).toHaveLength(2) + expect(f.pool.peek(resource)).toBe(original) + expect(f.created).toHaveLength(2) + expect(f.disposed.has(original!)).toBe(false) + }) + + it('moves the original view into the center and closes only the replaced task', async () => { + const f = await fixture() + const resource = taskResource('a', 'a-fork') + const source = await f.open(resource) + const original = f.pool.peek(resource) + const replaced = await f.open(taskResource('b'), 'right') + const replacedTask = f.pool.peek(f.controller.layout.views[replaced]!.resource)! + const targetPane = f.controller.owner(replaced)!.id + + await f.navigation.activateTask(taskResource('a'), 'a', { paneId: targetPane, move: true }) + + expect(Object.keys(f.controller.layout.views)).toEqual([source]) + expect(f.controller.pane(targetPane)?.view).toBe(source) + expect(panes(f.controller.layout.root)).toHaveLength(1) + expect(f.pool.peek(resource)).toBe(original) + expect(f.disposed).toEqual(new Set([replacedTask])) + expect(f.created).toHaveLength(2) + }) + + it('preserves both panes and the unsent draft when discarding the replacement is cancelled', async () => { + const f = await fixture() + const resource = taskResource('a', 'a-fork') + const source = await f.open(resource) + const draft = await f.open(draftResource('draft'), 'right') + const before = structuredClone(f.controller.layout) + + await f.navigation.activateTask(taskResource('a'), 'a', { paneId: f.controller.owner(draft)!.id, move: true }) + + expect(f.controller.layout).toEqual(before) + expect(f.draftText.value).toBe('unsent input') + expect(f.disposed.size).toBe(0) + expect(f.created).toHaveLength(2) + expect(f.controller.layout.views[source]?.resource).toEqual(resource) + + f.decisions.discard = true + await f.navigation.activateTask(taskResource('a'), 'a', { paneId: f.controller.owner(draft)!.id, move: true }) + expect(Object.keys(f.controller.layout.views)).toEqual([source]) + expect(f.controller.context.view?.id).toBe(source) + expect(f.pool.peek(resource)).toBe(f.created[0]) + }) + + it('uses the active branch for history opening and dragging when several branches are visible', async () => { + const f = await fixture() + const main = await f.open(taskResource('a', 'a-main')) + const fork = await f.open(taskResource('a', 'a-fork'), 'right') + const other = await f.open(taskResource('b'), 'right') + const targetPane = f.controller.owner(other)!.id + f.controller.focus(fork) + f.controller.setAuxiliary('taskBranches', { a: 'a-main' }) + + await f.navigation.activateTask(taskResource('a'), 'a') + expect(f.controller.context.view?.id).toBe(fork) + await f.navigation.activateTask(taskResource('a'), 'a', { paneId: targetPane, direction: 'down', move: true }) + + expect(f.controller.context.view?.id).toBe(fork) + expect(f.controller.layout.views[main]?.resource).toEqual(taskResource('a', 'a-main')) + expect(f.controller.layout.views[fork]?.resource).toEqual(taskResource('a', 'a-fork')) + expect(Object.keys(f.controller.layout.views)).toHaveLength(3) + expect(f.created).toHaveLength(3) + }) + + it('keeps explicit branch dragging independent of the active branch and local memory', async () => { + const f = await fixture() + const main = await f.open(taskResource('a', 'a-main')) + const other = await f.open(taskResource('b'), 'right') + const targetPane = f.controller.owner(other)!.id + f.controller.setAuxiliary('taskBranches', { a: 'a-main' }) + f.controller.focus(main) + + await f.navigation.activateTask(taskResource('a', 'a-fork'), 'a fork', { paneId: targetPane, direction: 'right', move: true }) + const fork = f.controller.context.view!.id + expect(fork).not.toBe(main) + expect(f.controller.layout.views[fork]?.resource).toEqual(taskResource('a', 'a-fork')) + f.controller.focus(main) + await f.navigation.activateTask(taskResource('a', 'a-fork'), 'a fork', { paneId: targetPane, direction: 'down', move: true }) + + expect(f.controller.context.view?.id).toBe(fork) + expect(f.controller.layout.views[main]?.resource).toEqual(taskResource('a', 'a-main')) + expect(f.pool.peek(taskResource('a', 'a-fork'))).not.toBe(f.pool.peek(taskResource('a', 'a-main'))) + expect(Object.keys(f.controller.layout.views)).toHaveLength(3) + expect(f.created).toHaveLength(3) + }) + + it.each([false, true])('opens a closed task on the locally remembered branch (move: %s)', async (move) => { + const f = await fixture() + f.controller.setAuxiliary('taskBranches', { a: 'a-fork' }) + + await f.navigation.activateTask(taskResource('a'), 'a', { move }) + + expect(f.controller.context.view?.resource).toEqual(taskResource('a', 'a-fork')) + expect(f.pool.peek(taskResource('a', 'a-fork'))?.workspace.session.activeBranchId.value).toBe('a-fork') + expect(f.created).toHaveLength(1) + }) + + it.each(['cancel', 'split', 'discard'] as const)('honors the %s decision when a history task would replace an unsent draft', async (replacement) => { + const f = await fixture() + const draft = await f.open(draftResource('draft')) + f.controller.setAuxiliary('taskBranches', { a: 'a-fork' }) + f.decisions.replacement = replacement + + await f.navigation.activateTask(taskResource('a'), 'a', { move: true }) + + expect(!!f.controller.layout.views[draft]).toBe(replacement !== 'discard') + expect(Object.keys(f.controller.layout.views)).toHaveLength(replacement === 'split' ? 2 : 1) + expect(f.controller.context.view?.resource).toEqual(replacement === 'cancel' ? draftResource('draft') : taskResource('a', 'a-fork')) + expect(f.created).toHaveLength(replacement === 'cancel' ? 1 : 2) + }) +}) diff --git a/apps/buddy/src/app/workbench/useDesktopWorkbench.ts b/apps/buddy/src/app/workbench/useDesktopWorkbench.ts index f6520b42a..74e08be67 100644 --- a/apps/buddy/src/app/workbench/useDesktopWorkbench.ts +++ b/apps/buddy/src/app/workbench/useDesktopWorkbench.ts @@ -173,16 +173,7 @@ export function useDesktopWorkbench(options: { beforeExtensionClose?: (viewId: s } function openTask(id: string, destination: { signal?: AbortSignal, direction?: SplitDirection, branchId?: string } = {}): Promise { const { branchId, ...placement } = destination - const selectedViewId = controller.pane(controller.layout.activePane)?.view - const selected = selectedViewId ? controller.layout.views[selectedViewId]?.resource : undefined - const selectedResource = selected ? parseTaskResource(selected) : null - const previous = selectedResource?.scheme === 'task' && selectedResource.id === id - ? selectedResource - : Object.values(controller.layout.views).map(view => parseTaskResource(view.resource)).find(resource => resource?.scheme === 'task' && resource.id === id) - const rememberedBranch = localBranches()[id] - const localResource = taskResource(id, typeof rememberedBranch === 'string' ? rememberedBranch : undefined) - const resource = branchId ? taskResource(id, branchId) : previous ?? localResource - return activateTask(resource, options.taskIndex.index.tasks.value.find(task => task.id === id)?.title ?? labels().tasks, placement) + return activateTask(taskResource(id, branchId), options.taskIndex.index.tasks.value.find(task => task.id === id)?.title ?? labels().tasks, placement) } function openDraft(id: string): Promise { return activateTask(draftResource(id), labels().newTask, { direction: 'right' }) diff --git a/apps/buddy/src/app/workbench/useTaskNavigation.ts b/apps/buddy/src/app/workbench/useTaskNavigation.ts index 803f8c770..a221aea37 100644 --- a/apps/buddy/src/app/workbench/useTaskNavigation.ts +++ b/apps/buddy/src/app/workbench/useTaskNavigation.ts @@ -1,5 +1,6 @@ import type { LexoraDesktopApi } from '@buddy-electron/shared/desktopApi' import type { BuddyUserContentV1 } from '@buddy-shared/conversation/buddyUserContent' +import type { ReadonlyJsonObject } from '@buddy-shared/workbench/workbenchState' import type { Router } from 'vue-router' import type { TaskWorkspaceResource } from './taskResource' import type { TaskWorkspacePool } from './TaskWorkspacePool' @@ -47,9 +48,26 @@ export function useTaskNavigation(options: { } } + function resolveResource(resource: TaskWorkspaceResource): TaskWorkspaceResource { + if (resource.scheme !== 'task' || resource.data.branchId !== undefined) + return resource + const selectedViewId = controller.pane(controller.layout.activePane)?.view + const selected = selectedViewId ? controller.layout.views[selectedViewId]?.resource : undefined + const selectedResource = selected ? parseTaskResource(selected) : null + const previous = selectedResource?.scheme === 'task' && selectedResource.id === resource.id + ? selectedResource + : Object.values(controller.layout.views).map(view => parseTaskResource(view.resource)).find(target => target?.scheme === 'task' && target.id === resource.id) + if (previous) + return previous + const branches = controller.layout.auxiliary.taskBranches + const rememberedBranch = branches && typeof branches === 'object' && !Array.isArray(branches) ? (branches as ReadonlyJsonObject)[resource.id] : undefined + return typeof rememberedBranch === 'string' ? { ...resource, data: { ...resource.data, branchId: rememberedBranch } } : resource + } + async function activateTask(resource: TaskWorkspaceResource, title: string, destination: { paneId?: string, direction?: SplitDirection, move?: boolean, signal?: AbortSignal, initialContent?: BuddyUserContentV1, prepareInput?: (viewId: string) => Promise } = {}) { if (destination.signal?.aborted) return + resource = resolveResource(resource) const targetPaneId = destination.paneId ?? options.center() const targetPane = controller.pane(targetPaneId) const currentViewId = targetPane?.view diff --git a/apps/buddy/src/i18n/locales/en-US/chat.ts b/apps/buddy/src/i18n/locales/en-US/chat.ts index dbb56a973..421f419e1 100644 --- a/apps/buddy/src/i18n/locales/en-US/chat.ts +++ b/apps/buddy/src/i18n/locales/en-US/chat.ts @@ -623,11 +623,6 @@ export default { 'desktop.chat.draftRestoration.resolveFailed': 'Restoration is incomplete, or the input changed while waiting. Your input is still available. Review it and retry.', 'desktop.chat.draftRestoration.keepLocal': 'Keep input for now', 'desktop.chat.draftRestoration.useSaved': 'Discard input and restore saved content', - 'desktop.chat.openBranchBeside': 'Open to the side', - 'desktop.chat.conversationBranches': 'Conversation branches', - 'desktop.chat.branchesLoading': 'Loading…', - 'desktop.chat.branchesUnavailable': 'Branches could not be loaded. Please try again.', 'desktop.chat.originalBranch': 'Original branch', 'desktop.chat.numberedBranch': 'Branch {index}', - 'desktop.chat.viewedBranch': 'Viewing', } satisfies Record diff --git a/apps/buddy/src/i18n/locales/zh-CN/chat.ts b/apps/buddy/src/i18n/locales/zh-CN/chat.ts index 82c22b035..d79ab059a 100644 --- a/apps/buddy/src/i18n/locales/zh-CN/chat.ts +++ b/apps/buddy/src/i18n/locales/zh-CN/chat.ts @@ -621,11 +621,6 @@ export default { 'desktop.chat.draftRestoration.resolveFailed': '恢复尚未完成,或等待期间输入又发生变化。当前输入仍保留,请检查后重试。', 'desktop.chat.draftRestoration.keepLocal': '保留输入,稍后处理', 'desktop.chat.draftRestoration.useSaved': '放弃此输入并恢复已保存内容', - 'desktop.chat.openBranchBeside': '在旁边打开', - 'desktop.chat.conversationBranches': '对话分支', - 'desktop.chat.branchesLoading': '正在载入…', - 'desktop.chat.branchesUnavailable': '分支暂时无法载入,请稍后重试', 'desktop.chat.originalBranch': '原始分支', 'desktop.chat.numberedBranch': '分支 {index}', - 'desktop.chat.viewedBranch': '当前浏览', } as const diff --git a/apps/buddy/src/modules/tasks/contracts.ts b/apps/buddy/src/modules/tasks/contracts.ts index f4b6bd61f..4adec520e 100644 --- a/apps/buddy/src/modules/tasks/contracts.ts +++ b/apps/buddy/src/modules/tasks/contracts.ts @@ -10,7 +10,6 @@ import type { LocalContextUsageSnapshotRequest } from '@buddy-shared/conversatio import type { LocalConversation, LocalConversationBranch, LocalConversationSummary, LocalConversationTimelineItem, LocalMessage } from '@buddy-shared/conversation/conversationApi' import type { LocalConversationHistoryPage } from '@buddy-shared/conversation/conversationHistoryApi' import type { LocalConversationTree } from '@buddy-shared/conversation/conversationTree' -import type { DraftRecoveryRecord } from '@buddy-shared/conversation/draftRecovery' import type { BuddyServiceTier, BuddyThinkingLevel } from '@buddy-shared/conversation/modelSelection' import type { LocalTaskMark, LocalTaskMarkState, TaskMarkInput } from '@buddy-shared/conversation/taskMarkApi' import type { LocalExecutionInputReceipt } from '@buddy-shared/executions/executionInputReceipt' @@ -251,7 +250,6 @@ export interface TaskStatus { } export interface TaskDraftRestoration { - localCopies?: State state: State conflict: State restore: () => Promise diff --git a/apps/buddy/src/modules/tasks/state/drafts/useTaskWorkspacePersistence.ts b/apps/buddy/src/modules/tasks/state/drafts/useTaskWorkspacePersistence.ts index 0afff28ad..0a56acb36 100644 --- a/apps/buddy/src/modules/tasks/state/drafts/useTaskWorkspacePersistence.ts +++ b/apps/buddy/src/modules/tasks/state/drafts/useTaskWorkspacePersistence.ts @@ -328,7 +328,6 @@ export function useTaskWorkspacePersistence(options: UseTaskWorkspacePersistence }, restore, resolveRemote, - localCopies: recovery.copies, persistLocalChanges: recovery.schedule, restorationConflict: readonly(restorationConflict), restorationState: readonly(restorationState), diff --git a/apps/buddy/src/modules/tasks/state/useTaskCapability.ts b/apps/buddy/src/modules/tasks/state/useTaskCapability.ts index e1ced009a..04f2fbaae 100644 --- a/apps/buddy/src/modules/tasks/state/useTaskCapability.ts +++ b/apps/buddy/src/modules/tasks/state/useTaskCapability.ts @@ -745,7 +745,6 @@ export function useTaskCapability(options: UseTaskCapabilityOptions): TaskCapabi welcomeCompanionImage: readonly(welcomeCompanionImage), restoration: { state: workspacePersistence.restorationState, - localCopies: workspacePersistence.localCopies, conflict: workspacePersistence.restorationConflict, restore: lifecycle.refreshRuntimeDependentState, resolveRemote: workspacePersistence.resolveRemote, diff --git a/apps/buddy/src/modules/tasks/widgets/transcript/BuddyChatActionToolbar.vue b/apps/buddy/src/modules/tasks/widgets/transcript/BuddyChatActionToolbar.vue index 60a5b49ef..7226eb648 100644 --- a/apps/buddy/src/modules/tasks/widgets/transcript/BuddyChatActionToolbar.vue +++ b/apps/buddy/src/modules/tasks/widgets/transcript/BuddyChatActionToolbar.vue @@ -18,6 +18,7 @@ import { useChatContent } from './chatContentContext' const props = defineProps<{ actions: ChatMessageActions + branchNavigationDisabled?: boolean branchNavigator: ChatMessageBranchNavigator | null copyText: string createdAt: string @@ -146,7 +147,7 @@ async function copyContent() {