🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(chat-input): worktree branch removal + skill drag preview icon (#16704)
Arvin Xua90c41ec13de
diff --git a/apps/server/src/routers/lambda/device.ts b/apps/server/src/routers/lambda/device.tsindex a1526b7816d..195e100cdce 100644--- a/apps/server/src/routers/lambda/device.ts+++ b/apps/server/src/routers/lambda/device.ts@@ -292,7 +292,7 @@ export const deviceRouter = router({),/**- * Remove a detached worktree in a directory's repository on a remote device,+ * Remove a worktree in a directory's repository on a remote device,* via the device's `removeGitWorktree` RPC.*/removeGitWorktree: deviceProcedurediff --git a/apps/server/src/services/deviceGateway/index.ts b/apps/server/src/services/deviceGateway/index.tsindex 50da90aa9c0..eee5fe9ccc8 100644--- a/apps/server/src/services/deviceGateway/index.ts+++ b/apps/server/src/services/deviceGateway/index.ts@@ -421,7 +421,7 @@ export class DeviceGateway {}/**- * Remove a detached worktree in a directory's repository on a remote device via+ * Remove a worktree in a directory's repository on a remote device via* the `removeGitWorktree` device RPC.*/async removeGitWorktree(params: {diff --git a/locales/en-US/device.json b/locales/en-US/device.jsonindex 928576dcf7a..b8640c2f87c 100644--- a/locales/en-US/device.json+++ b/locales/en-US/device.json@@ -58,11 +58,11 @@"workingDirectory.recent": "Recent","workingDirectory.refreshGitStatus": "Refresh branch & PR status","workingDirectory.removeRecent": "Remove from recent",- "workingDirectory.removeWorktreeAction": "Delete detached worktree",- "workingDirectory.removeWorktreeConfirm": "Delete detached worktree “{{name}}”? This removes the worktree directory. Git will refuse if it has uncommitted changes.",+ "workingDirectory.removeWorktreeAction": "Delete worktree",+ "workingDirectory.removeWorktreeConfirm": "Delete worktree “{{name}}”? This removes the worktree directory but keeps its branch. Git will refuse if it has uncommitted changes.","workingDirectory.removeWorktreeFailed": "Delete worktree failed","workingDirectory.removeWorktreeSuccess": "Worktree deleted",- "workingDirectory.removeWorktreeTitle": "Delete detached worktree",+ "workingDirectory.removeWorktreeTitle": "Delete worktree","workingDirectory.renameBranchAction": "Rename branch","workingDirectory.renameBranchTitle": "Rename branch","workingDirectory.renameFailed": "Rename failed",diff --git a/locales/zh-CN/device.json b/locales/zh-CN/device.jsonindex 4ed6b2d2766..507a959f27a 100644--- a/locales/zh-CN/device.json+++ b/locales/zh-CN/device.json@@ -58,11 +58,11 @@"workingDirectory.recent": "最近使用","workingDirectory.refreshGitStatus": "刷新分支与 PR 状态","workingDirectory.removeRecent": "从最近目录中移除",- "workingDirectory.removeWorktreeAction": "删除游离 Worktree",- "workingDirectory.removeWorktreeConfirm": "删除游离 Worktree“{{name}}”?这会移除该 worktree 目录;如果仍有未提交更改,Git 会拒绝删除。",+ "workingDirectory.removeWorktreeAction": "删除 Worktree",+ "workingDirectory.removeWorktreeConfirm": "删除 Worktree“{{name}}”?这会移除该 worktree 目录,但保留其分支;如果仍有未提交更改,Git 会拒绝删除。","workingDirectory.removeWorktreeFailed": "删除 Worktree 失败","workingDirectory.removeWorktreeSuccess": "Worktree 已删除",- "workingDirectory.removeWorktreeTitle": "删除游离 Worktree",+ "workingDirectory.removeWorktreeTitle": "删除 Worktree","workingDirectory.renameBranchAction": "重命名分支","workingDirectory.renameBranchTitle": "重命名分支","workingDirectory.renameFailed": "重命名失败",diff --git a/packages/local-file-shell/src/git/__tests__/branches.test.ts b/packages/local-file-shell/src/git/__tests__/branches.test.tsindex 2c0f0881cef..202fc4c9d69 100644--- a/packages/local-file-shell/src/git/__tests__/branches.test.ts+++ b/packages/local-file-shell/src/git/__tests__/branches.test.ts@@ -144,17 +144,22 @@ describe('removeGitWorktree', () => {);});- it('refuses to remove a branch worktree', async () => {+ it('removes a branch worktree', async () => {git(repo, 'branch', 'feature');const worktreeParent = await mkdtemp(path.join(tmpdir(), 'lfs-worktree-branch-'));cleanup.push(worktreeParent);const linked = path.join(worktreeParent, 'linked');git(repo, 'worktree', 'add', linked, 'feature');+ const linkedRealPath = await realpath(linked);expect(await removeGitWorktree({ path: repo, worktreePath: linked })).toEqual({- error: 'Only detached worktrees can be removed',- success: false,+ success: true,});++ expect(existsSync(linkedRealPath)).toBe(false);+ expect((await listGitWorktrees(repo)).map((worktree) => worktree.path)).not.toContain(+ linkedRealPath,+ );});it('refuses to remove the current worktree', async () => {diff --git a/packages/local-file-shell/src/git/worktrees.ts b/packages/local-file-shell/src/git/worktrees.tsindex 0f5837b8574..3886739d9b2 100644--- a/packages/local-file-shell/src/git/worktrees.ts+++ b/packages/local-file-shell/src/git/worktrees.ts@@ -147,8 +147,7 @@ export const removeGitWorktree = async (payload: {const worktree = await findListedWorktree(dirPath, worktreePath);if (!worktree) return { error: 'Worktree not found', success: false };if (worktree.current) return { error: 'Cannot remove the current worktree', success: false };- if (!worktree.detached)- return { error: 'Only detached worktrees can be removed', success: false };+ if (worktree.bare) return { error: 'Cannot remove the bare worktree', success: false };try {await execFileAsync('git', ['worktree', 'remove', worktree.path], {diff --git a/packages/locales/src/default/device.ts b/packages/locales/src/default/device.tsindex 50ab2b74650..ac107aa88e4 100644--- a/packages/locales/src/default/device.ts+++ b/packages/locales/src/default/device.ts@@ -74,12 +74,12 @@ export default {'workingDirectory.detachedWorktree': 'detached','workingDirectory.lockedWorktree': 'locked','workingDirectory.prunableWorktree': 'prunable',- 'workingDirectory.removeWorktreeAction': 'Delete detached worktree',+ 'workingDirectory.removeWorktreeAction': 'Delete worktree','workingDirectory.removeWorktreeConfirm':- 'Delete detached worktree “{{name}}”? This removes the worktree directory. Git will refuse if it has uncommitted changes.',+ 'Delete worktree “{{name}}”? This removes the worktree directory but keeps its branch. Git will refuse if it has uncommitted changes.','workingDirectory.removeWorktreeFailed': 'Delete worktree failed','workingDirectory.removeWorktreeSuccess': 'Worktree deleted',- 'workingDirectory.removeWorktreeTitle': 'Delete detached worktree',+ 'workingDirectory.removeWorktreeTitle': 'Delete worktree','workingDirectory.worktreeCount': '{{count}} worktrees','workingDirectory.worktreeSwitchDescription': 'Switch the current conversation working directory','workingDirectory.worktreeUnavailable': 'unavailable',diff --git a/src/features/ChatInput/ControlBar/WorktreeSwitcher.tsx b/src/features/ChatInput/ControlBar/WorktreeSwitcher.tsxindex 74338eb9596..c71923bbea6 100644--- a/src/features/ChatInput/ControlBar/WorktreeSwitcher.tsx+++ b/src/features/ChatInput/ControlBar/WorktreeSwitcher.tsx@@ -337,7 +337,7 @@ const isDisabled = (worktree: DeviceGitWorktreeListItem): boolean =>!!worktree.bare || !!worktree.prunable;const canRemoveWorktree = (worktree: DeviceGitWorktreeListItem): boolean =>- !!worktree.detached && !worktree.current && !worktree.locked && !isDisabled(worktree);+ !worktree.current && !worktree.locked && !isDisabled(worktree);interface DirtyStatProps {status?: DeviceGitWorktreeListItem['status'];diff --git a/src/features/ChatInput/ControlBar/__tests__/WorktreeSwitcher.test.tsx b/src/features/ChatInput/ControlBar/__tests__/WorktreeSwitcher.test.tsxindex 3f03e7724e1..4ecc80d8d0b 100644--- a/src/features/ChatInput/ControlBar/__tests__/WorktreeSwitcher.test.tsx+++ b/src/features/ChatInput/ControlBar/__tests__/WorktreeSwitcher.test.tsx@@ -1,4 +1,4 @@-import { fireEvent, render, screen } from '@testing-library/react';+import { fireEvent, render, screen, within } from '@testing-library/react';import type { ReactNode } from 'react';import { beforeEach, describe, expect, it, vi } from 'vitest';@@ -98,8 +98,9 @@ describe('WorktreeSwitcher', () => {/>,);- expect(screen.getByTestId('worktree-dropdown-trigger').firstElementChild?.tagName).toBe('DIV');- expect(screen.getByTestId('worktree-tooltip')).toBeTruthy();+ const trigger = screen.getByTestId('worktree-dropdown-trigger');+ expect(trigger.firstElementChild?.tagName).toBe('DIV');+ expect(within(trigger).getByTestId('worktree-tooltip')).toBeTruthy();});it('renders dirty stats and omits clean labels in the worktree list', () => {@@ -173,7 +174,7 @@ describe('WorktreeSwitcher', () => {expect(screen.getByText('/tmp/project-scratch')).toBeTruthy();});- it('confirms and removes a detached non-current worktree', async () => {+ it('confirms and removes a non-current worktree', async () => {const onWorktreesChange = vi.fn();render(<WorktreeSwitcher@@ -208,9 +209,11 @@ describe('WorktreeSwitcher', () => {/>,);- expect(screen.getAllByLabelText('workingDirectory.removeWorktreeAction')).toHaveLength(1);+ // both the detached and the branch worktree are removable; only the current one is not+ const removeButtons = screen.getAllByLabelText('workingDirectory.removeWorktreeAction');+ expect(removeButtons).toHaveLength(2);- fireEvent.click(screen.getByLabelText('workingDirectory.removeWorktreeAction'));+ fireEvent.click(removeButtons[0]);expect(commitMock).not.toHaveBeenCalled();expect(confirmModalMock).toHaveBeenCalledTimes(1);diff --git a/src/features/ChatInput/InputEditor/ActionTag/skillDragData.ts b/src/features/ChatInput/InputEditor/ActionTag/skillDragData.tsindex 3e4b4f03815..e054d090585 100644--- a/src/features/ChatInput/InputEditor/ActionTag/skillDragData.ts+++ b/src/features/ChatInput/InputEditor/ActionTag/skillDragData.ts@@ -99,9 +99,13 @@ const setSkillDragImage = (event: React.DragEvent, label: string): void => {zIndex: '9999',});- // Row layout is: [chevron svg] [skill icon svg] [name] [count]. Take the last- // svg so we always grab the skill icon, never the chevron.- const svgs = Array.from(host.querySelectorAll('svg'));+ // Row layout is: [chevron svg] [skill icon svg] [name] [count] [row actions].+ // The hover action buttons (view / rename / delete) stay in the DOM even when+ // hidden, so exclude them before taking the last svg — otherwise we'd grab the+ // trailing Trash2 action icon instead of the skill icon.+ const svgs = Array.from(host.querySelectorAll('svg')).filter(+ (svg) => !svg.closest('.skill-row-actions'),+ );const iconSvg = svgs.at(-1);if (iconSvg) {const iconClone = iconSvg.cloneNode(true) as SVGElement;diff --git a/src/features/ChatInput/store/action.test.ts b/src/features/ChatInput/store/action.test.tsindex 02a42c1ddb2..416c91aa4d9 100644--- a/src/features/ChatInput/store/action.test.ts+++ b/src/features/ChatInput/store/action.test.ts@@ -1,7 +1,9 @@import type { IEditor } from '@lobehub/editor';+import { KEY_ESCAPE_COMMAND } from 'lexical';import { beforeEach, describe, expect, it, vi } from 'vitest';import { useAgentStore } from '@/store/agent';+import { systemAgentSelectors } from '@/store/user/selectors';import { getInputHistory } from '../inputHistoryStorage';import { createStore, selectors } from '.';@@ -91,6 +93,44 @@ describe('ChatInput store actions', () => {expect(editor.getDocument).not.toHaveBeenCalled();});+ it('clears the input-completion ghost before sending when autocomplete is enabled', () => {+ vi.spyOn(systemAgentSelectors, 'inputCompletion').mockReturnValue({ enabled: true } as any);++ const dispatchCommand = vi.fn();+ const editor = {+ cleanDocument: vi.fn(),+ dispatchCommand,+ focus: vi.fn(),+ getDocument: vi.fn((type: string) => (type === 'markdown' ? 'Hello' : { root: {} })),+ };+ const store = createStore({+ editor: editor as unknown as IEditor,+ onSend: vi.fn(),+ });++ store.getState().handleSendButton();++ expect(dispatchCommand).toHaveBeenCalledWith(KEY_ESCAPE_COMMAND, expect.any(Object));+ });++ it('does not dispatch escape on send when autocomplete is disabled', () => {+ const dispatchCommand = vi.fn();+ const editor = {+ cleanDocument: vi.fn(),+ dispatchCommand,+ focus: vi.fn(),+ getDocument: vi.fn((type: string) => (type === 'markdown' ? 'Hello' : { root: {} })),+ };+ const store = createStore({+ editor: editor as unknown as IEditor,+ onSend: vi.fn(),+ });++ store.getState().handleSendButton();++ expect(dispatchCommand).not.toHaveBeenCalled();+ });+it('does not record history when no send handler is configured', () => {const editor = {cleanDocument: vi.fn(),diff --git a/src/features/ChatInput/store/action.ts b/src/features/ChatInput/store/action.tsindex a8d51c82e75..8927738cde0 100644--- a/src/features/ChatInput/store/action.ts+++ b/src/features/ChatInput/store/action.ts@@ -1,8 +1,9 @@+import { KEY_ESCAPE_COMMAND } from 'lexical';import { type StateCreator } from 'zustand/vanilla';import { useAgentStore } from '@/store/agent';import { useUserStore } from '@/store/user';-import { userProfileSelectors } from '@/store/user/selectors';+import { systemAgentSelectors, userProfileSelectors } from '@/store/user/selectors';import { removeDraft } from '../draftStorage';import { addInputHistory } from '../inputHistoryStorage';@@ -59,6 +60,18 @@ export const store: CreateStore = (publicState) => (set, get) => ({if (!editor) return;if (get().sendButtonProps?.disabled) return;+ // Drop any pending AI input-completion ghost before serializing the message.+ // The suggestion is materialized as real placeholder nodes inside the+ // document, so sending without clearing would emit the ghost text too —+ // Enter and the send button must submit only what the user actually typed.+ // Escape is the plugin's reject path and clears those nodes synchronously.+ const autoCompleteEnabled =+ (get().feature?.inputCompletion ?? true) &&+ systemAgentSelectors.inputCompletion(useUserStore.getState()).enabled;+ if (autoCompleteEnabled) {+ editor.dispatchCommand(KEY_ESCAPE_COMMAND, new KeyboardEvent('keydown', { key: 'Escape' }));+ }+const onSend = get().onSend;const historyEnabled = !!onSend && (get().feature?.inputHistory ?? true);const historySnapshot = historyEnableddiff --git a/src/services/git.ts b/src/services/git.tsindex d36021951d1..87d6b7fec89 100644--- a/src/services/git.ts+++ b/src/services/git.ts@@ -104,7 +104,7 @@ class GitService {: electronGitService.deleteGitBranch({ branch, path });}- /** Remove a detached worktree from a working directory's repository. */+ /** Remove a worktree from a working directory's repository. */removeGitWorktree({deviceId,path,