Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(worktree): remove desktop agent tools conflicting with core (#995)

Mao Mrecd8c71566ee
diff --git a/packages/dsh-tauri-worktree/src/host/apply.test.ts b/packages/dsh-tauri-worktree/src/host/apply.test.ts
new file mode 100644
index 00000000..245eb83b
--- /dev/null
+++ b/packages/dsh-tauri-worktree/src/host/apply.test.ts
@@ -0,0 +1,33 @@
+import { describe, expect, it, vi } from 'vitest'
+import { inject } from '../index'
+import { apply } from './apply'
+import { handleSessionEvent } from './events/session-event'
+import { handleToolsExecute } from './events/tools-execute'
+import { checkoutContextProvider } from './prompts/checkout-context'
+import { worktreeContextProvider } from './prompts/worktree-context'
+import { worktreeSectionProvider } from './prompts/worktree-section'
+
+describe('worktree plugin registration', () => {
+ it('activates without a tools service while retaining events, prompts and lifecycle effects', () => {
+ const on = vi.fn()
+ const effect = vi.fn()
+ const section = vi.fn()
+ const context = vi.fn()
+
+ apply({ on, effect, systemPrompt: { section, context } })
+
+ expect(inject).not.toContain('tools')
+ expect(on.mock.calls).toEqual([
+ ['session/event', handleSessionEvent],
+ ['tools/execute', handleToolsExecute],
+ ])
+ expect(section).toHaveBeenCalledExactlyOnceWith(worktreeSectionProvider)
+ expect(context.mock.calls).toEqual([[worktreeContextProvider], [checkoutContextProvider]])
+ expect(effect.mock.calls.map(([, label]) => label)).toEqual([
+ 'plugin: routes',
+ 'plugin: unregister legacy worktree workspaces',
+ 'plugin: worktree discard recovery',
+ 'plugin: host runtime',
+ ])
+ })
+})
diff --git a/packages/dsh-tauri-worktree/src/host/apply.ts b/packages/dsh-tauri-worktree/src/host/apply.ts
index 29fda8d0..6987ef41 100644
--- a/packages/dsh-tauri-worktree/src/host/apply.ts
+++ b/packages/dsh-tauri-worktree/src/host/apply.ts
@@ -9,17 +9,12 @@ import { worktreeSectionProvider } from './prompts/worktree-section'
import { server } from './server'
import { workspace } from './service/workspace'
import { worktree } from './service/worktree'
-import { checkoutWorktreeTool } from './tools/checkout-worktree'
-import { createWorktreeTool } from './tools/create-worktree'
const RECOVER_INTERVAL_MS = 5 * 60_000
export function apply(ctx: HostContext): void {
ctx.effect(() => server(ctx), 'plugin: routes')
- ctx.tools.register(createWorktreeTool())
- ctx.tools.register(checkoutWorktreeTool())
-
ctx.on('session/event', handleSessionEvent)
ctx.on('tools/execute', handleToolsExecute)
diff --git a/packages/dsh-tauri-worktree/src/host/config/runtime.ts b/packages/dsh-tauri-worktree/src/host/config/runtime.ts
index a29f4075..ac74fd33 100644
--- a/packages/dsh-tauri-worktree/src/host/config/runtime.ts
+++ b/packages/dsh-tauri-worktree/src/host/config/runtime.ts
@@ -1,14 +1,9 @@
-import type { PendingHandoff } from '../types'
-
-export const pendingHandoffs = new Map<string, PendingHandoff>()
-
/** 继承前缀里没有人类消息的工作树会话:首个请求头落盘时显式补一次模型标题(内核不会为 fork 子会话自动生成)。 */
export const pendingWorktreeTitles = new Set<string>()
export const injectedCheckoutContexts = new Set<string>()
export function resetRuntime(): void {
- pendingHandoffs.clear()
pendingWorktreeTitles.clear()
injectedCheckoutContexts.clear()
}
diff --git a/packages/dsh-tauri-worktree/src/host/events/session-event.ts b/packages/dsh-tauri-worktree/src/host/events/session-event.ts
index e832c3bb..6c57c9e5 100644
--- a/packages/dsh-tauri-worktree/src/host/events/session-event.ts
+++ b/packages/dsh-tauri-worktree/src/host/events/session-event.ts
@@ -1,7 +1,6 @@
import { get, isString } from 'lodash-es'
-import { injectedCheckoutContexts, pendingHandoffs } from '../config/runtime'
+import { injectedCheckoutContexts } from '../config/runtime'
import { checkoutContext } from '../service/checkout-context'
-import { handoff } from '../service/handoff'
import { worktreeTitle } from '../service/title'
import { worktree } from '../service/worktree'
@@ -19,12 +18,6 @@ export function handleSessionEvent(session: any, event: any): void {
void worktree.recover()
- const handoffPending = pendingHandoffs.get(sessionId)
- if (handoffPending) {
- pendingHandoffs.delete(sessionId)
- void handoff.complete(handoffPending)
- }
-
if (injectedCheckoutContexts.delete(sessionId))
void checkoutContext.remove(sessionId)
}
diff --git a/packages/dsh-tauri-worktree/src/host/service/handoff.test.ts b/packages/dsh-tauri-worktree/src/host/service/handoff.test.ts
index 59d39abe..e1bff27a 100644
--- a/packages/dsh-tauri-worktree/src/host/service/handoff.test.ts
+++ b/packages/dsh-tauri-worktree/src/host/service/handoff.test.ts
@@ -1,4 +1,3 @@
-import type { Binding, PendingHandoff } from '../types'
import { resolve } from 'node:path'
import { Context } from '@deepseek-ai/cordis'
import { MessageId } from '@deepseek-ai/dsh-llm'
@@ -289,83 +288,3 @@ describe('handoff.inherit', () => {
expect(warn).toHaveBeenCalledWith(expect.stringContaining('session-target'))
})
})
-
-describe('handoff.complete', () => {
- it('uses the pending source agent even when it is no longer registered', async () => {
- const followup = vi.fn()
- const create = vi.fn(async (_options: any) => ({ agent: { followup } }))
- const sourceContext = { preset: 'source' }
- const composeFrom = vi.fn(() => 'composed')
- const composedPreset = vi.fn(() => 'composed')
- const attachSession = vi.fn(async () => {})
- disposers.push(server({
- agents: { get: () => undefined, create },
- get: () => ({ composedPreset, composeFrom }),
- workspaceRegistry: { resolveByPath: async () => ({ attachSession }) },
- webServer: { register: () => () => {} },
- } as never))
- await handoff.complete({
- sourceAgent: { ...(sourceAgent() as object), ctx: sourceContext, options: { model: 'inherited' } },
- targetSessionId: 'session-target',
- binding: { worktreePath: 'C:/worktrees/w1', projectPath: 'C:/project' } as Binding,
- })
- expect(create).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({
- sessionId: 'session-target',
- seed: conversationEvents,
- meta: expect.objectContaining({ cwd: 'C:/worktrees/w1', agentPreset: 'composed' }),
- agentOptions: { model: 'inherited' },
- }))
- expect(composedPreset).toHaveBeenCalledWith(sourceContext)
- const targetContext = { preset: 'target' }
- expect(create.mock.calls[0]![0].setup(targetContext)).toBeUndefined()
- expect(composeFrom).toHaveBeenCalledExactlyOnceWith(targetContext, sourceContext)
- expect(attachSession).toHaveBeenCalledWith('session-target')
- expect(followup).toHaveBeenCalledTimes(1)
- })
-
- it('hands the inherited log to the worktree agent', async () => {
- const followup = vi.fn()
- const { created } = setup({ create: async () => ({ agent: { followup } }) })
- const pending: PendingHandoff = {
- sourceAgent: sourceAgent(),
- targetSessionId: 'session-target',
- binding: { worktreePath: 'C:/worktrees/w1', projectPath: 'C:/project' } as Binding,
- }
-
- await handoff.complete(pending)
-
- expect(created[0]).toMatchObject({
- sessionId: 'session-target',
- seed: conversationEvents,
- inheritedEventCount: conversationEvents.length,
- meta: {
- cwd: 'C:/worktrees/w1',
- parentSession: 'session-source',
- isSeeded: true,
- agentPreset: 'default',
- },
- })
- expect(pendingWorktreeTitles.size).toBe(0)
- expect(followup).toHaveBeenCalledTimes(1)
- const followupMessage = followup.mock.calls[0][0]
- const text = followupMessage.content.map((block: any) => block.text).join('')
- expect(text).toContain('is_worktree: true')
- expect(text).toContain('Worktree path: C:/worktrees/w1')
- expect(text).toContain('Project path: C:/project')
- expect(text).toContain('The task has moved to this isolated worktree session.')
- })
-
- it('空会话直接调用工具时同样登记显式标题', async () => {
- const followup = vi.fn()
- setup({ create: async () => ({ agent: { followup } }) })
- const pending: PendingHandoff = {
- sourceAgent: sourceAgent(emptyEvents),
- targetSessionId: 'session-target',
- binding: { worktreePath: 'C:/worktrees/w1', projectPath: 'C:/project' } as Binding,
- }
-
- await handoff.complete(pending)
-
- expect([...pendingWorktreeTitles]).toEqual(['session-target'])
- })
-})
diff --git a/packages/dsh-tauri-worktree/src/host/service/handoff.ts b/packages/dsh-tauri-worktree/src/host/service/handoff.ts
index a6381121..a60eeccb 100644
--- a/packages/dsh-tauri-worktree/src/host/service/handoff.ts
+++ b/packages/dsh-tauri-worktree/src/host/service/handoff.ts
@@ -1,11 +1,10 @@
-import type { CheckoutInfo, HostContext, OperationResult, PendingHandoff } from '../types'
+import type { CheckoutInfo, HostContext, OperationResult } from '../types'
import { randomUUID } from 'node:crypto'
import { getServerContext } from 'dsh-h3/utils'
import { defineService } from 'dsh-tauri'
import { get } from 'lodash-es'
import { pendingWorktreeTitles } from '../config/runtime'
import { server } from '../server'
-import { worktreeHandoffText } from '../utils/worktree-facts'
import { checkoutContext } from './checkout-context'
import { sessionContext } from './session-context'
import { worktree } from './worktree'
@@ -71,36 +70,6 @@ export const handoff = defineService({
return checkout
return { ok: true, branch: checkout.branch, projectPath: checkout.projectPath, targetSessionId }
},
-
- async complete(pending: PendingHandoff): Promise<void> {
- const ctx = getServerContext<HostContext>(server)
- const { sourceAgent, targetSessionId, binding } = pending
- const sourceSession = sourceAgent.session
- try {
- const seed = sessionEvents(sourceSession)
- const handle = await createAgent(sourceSession, sourceAgent, targetSessionId, binding.worktreePath, seed)
- const workspace = await ctx.workspaceRegistry.resolveByPath(binding.projectPath)
- if (workspace)
- await workspace.attachSession(targetSessionId)
- if (!hasInheritedConversation(seed))
- pendingWorktreeTitles.add(targetSessionId)
- handle.agent.followup({
- id: `message-${randomUUID()}`,
- role: 'user',
- content: [{
- type: 'text',
- text: worktreeHandoffText(binding),
- }],
- source: { kind: 'user' },
- })
- }
- catch (error) {
- if (!ctx.agents.get(targetSessionId))
- await worktree.remove(targetSessionId)
- const message = get(error, 'message', String(error))
- ctx.logger?.error?.(`create_worktree handoff failed for ${targetSessionId}: ${message}`)
- }
- },
})
// --- internal ---
diff --git a/packages/dsh-tauri-worktree/src/host/tools/checkout-worktree.ts b/packages/dsh-tauri-worktree/src/host/tools/checkout-worktree.ts
deleted file mode 100644
index 581a6ab4..00000000
--- a/packages/dsh-tauri-worktree/src/host/tools/checkout-worktree.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-import { get } from 'lodash-es'
-import { worktree } from '../service/worktree'
-import { textBlock } from './create-worktree'
-
-export function checkoutWorktreeTool(): any {
- return {
- name: 'checkout_worktree',
- description:
- 'User-authorized operation only. Call this tool only after a direct human user explicitly requests or approves checkout. '
- + 'Task completion, a merged PR, or inferred convenience is not permission to call it. When checkout would be a natural next step, '
- + 'such as after a PR is merged, you may ask the user whether they want to check out the worktree; wait for their approval before calling. '
- + 'Bring the current isolated worktree back to the local repository, preserve its changes on the worktree branch, '
- + 'create or switch to the requested local branch, and remove the isolated worktree. The main branch is unchanged.',
- parameters: {
- type: 'object',
- properties: {
- worktree_hash_dirname: {
- type: 'string',
- description: 'Worktree key in `[hash]/[dirname]` form, as shown in the session context.',
- },
- branch_name: {
- type: 'string',
- description: 'Local branch name, such as `dsh/feature-xyz` or `feature-xyz`; used exactly as provided.',
- },
- carry_staged: {
- type: 'boolean',
- description: 'Whether to carry the worktree\'s staged (index) changes into the checked-out local branch '
- + 'before the worktree is removed. Committed work is always carried; staged-only work would otherwise '
- + 'be lost with the removed worktree. Default false.',
- default: false,
- },
- },
- required: ['worktree_hash_dirname', 'branch_name'],
- },
- output: {
- schema: {
- type: 'object',
- additionalProperties: true,
- properties: {
- ok: { type: 'boolean' },
- branch: { type: 'string' },
- error: { type: 'string' },
- },
- required: ['ok'],
- },
- render: (_args: unknown, value: any) => value.ok
- ? textBlock(`✅ Checked out local branch ${value.branch}; the worktree was removed.`)
- : textBlock(`❌ Checkout failed: ${value.error}`),
- },
- async execute(args: any, exec: any) {
- const result = await worktree.checkout(
- {
- worktree_hash_dirname: String(args.worktree_hash_dirname ?? ''),
- sessionId: get(exec, 'agent.session.id'),
- branch_name: String(args.branch_name ?? ''),
- },
- {
- signal: exec?.signal,
- carryStaged: args.carry_staged === true,
- },
- )
- if (!result.ok)
- return { ok: false, error: result.error }
- return { ok: true, branch: result.branch, projectPath: result.projectPath }
- },
- }
-}
diff --git a/packages/dsh-tauri-worktree/src/host/tools/create-worktree.ts b/packages/dsh-tauri-worktree/src/host/tools/create-worktree.ts
deleted file mode 100644
index 950bf41e..00000000
--- a/packages/dsh-tauri-worktree/src/host/tools/create-worktree.ts
+++ /dev/null
@@ -1,91 +0,0 @@
-import { randomUUID } from 'node:crypto'
-import { get, isString } from 'lodash-es'
-import { pendingHandoffs } from '../config/runtime'
-import { ledger } from '../service/ledger'
-import { sessionContext } from '../service/session-context'
-import { worktree } from '../service/worktree'
-
-const outputSchema = {
- type: 'object',
- additionalProperties: true,
- properties: {
- ok: { type: 'boolean' },
- targetSessionId: { type: 'string' },
- worktreePath: { type: 'string' },
- branch: { type: 'string' },
- warning: { type: 'string' },
- error: { type: 'string' },
- },
- required: ['ok'],
-}
-
-export function createWorktreeTool(): any {
- return {
- name: 'create_worktree',
- description:
- 'Use only when the user explicitly asks to work in a worktree and the current session is local. '
- + 'It creates an isolated worktree and hands the full context to a new session after the current turn. '
- + 'Do not call it from an existing worktree session.',
- parameters: {
- type: 'object',
- properties: {
- branch_name: {
- type: 'string',
- description: 'New worktree branch, for example `dsh/feature-xyz`; the `dsh/` prefix is added when omitted.',
- },
- carry_staged: {
- type: 'boolean',
- description: 'Whether to carry the source repository\'s staged (index) changes into the new worktree, '
- + 'so the isolated session starts from the same staged state. Only staged changes are carried; '
- + 'unstaged and untracked changes stay in the source repository. Default false.',
- default: false,
- },
- },
- required: ['branch_name'],
- },
- output: {
- schema: outputSchema,
- render: (_args: unknown, value: any) => value.ok
- ? textBlock(`✅ Created worktree ${value.branch}; the UI will switch to the inherited worktree session after this turn.`)
- : textBlock(`❌ Failed to create worktree: ${value.error}`),
- },
- async execute(args: any, exec: any) {
- const sourceSessionId = get(exec, 'agent.session.id')
- if (!isString(sourceSessionId))
- return { ok: false, error: 'create_worktree requires a current agent session' }
- if (ledger.load(sourceSessionId))
- return { ok: false, error: 'The current session is already in a worktree' }
-
- const projectPath = await sessionContext.resolve(sourceSessionId)
- if (!projectPath)
- return { ok: false, error: '无法解析当前会话的工作目录:会话尚未就绪,请稍后重试' }
-
- const targetSessionId = `session-${randomUUID()}`
- const created = await worktree.create(projectPath, targetSessionId, {
- sourceSessionId,
- branchName: String(args.branch_name ?? ''),
- carryStaged: args.carry_staged === true,
- signal: exec?.signal,
- })
- if (!created.ok)
- return { ok: false, error: created.error }
-
- pendingHandoffs.set(sourceSessionId, {
- sourceAgent: get(exec, 'agent'),
- targetSessionId,
- binding: created.binding,
- })
-
- return {
- ok: true,
- targetSessionId,
- worktreePath: created.binding.worktreePath,
- branch: created.binding.branchName,
- }
- },
- }
-}
-
-export function textBlock(text: string): Array<{ type: 'text', text: string }> {
- return [{ type: 'text', text }]
-}
diff --git a/packages/dsh-tauri-worktree/src/host/types/index.ts b/packages/dsh-tauri-worktree/src/host/types/index.ts
index d71e57be..c3f39653 100644
--- a/packages/dsh-tauri-worktree/src/host/types/index.ts
+++ b/packages/dsh-tauri-worktree/src/host/types/index.ts
@@ -49,12 +49,6 @@ export interface CheckoutInfo {
worktreePath?: string
}
-export interface PendingHandoff {
- sourceAgent: any
- targetSessionId: string
- binding: Binding
-}
-
export type OperationResult<T extends object = object>
= | ({ ok: true } & T)
| { ok: false, error: string }
diff --git a/packages/dsh-tauri-worktree/src/host/utils/worktree-facts.test.ts b/packages/dsh-tauri-worktree/src/host/utils/worktree-facts.test.ts
new file mode 100644
index 00000000..ea80bafb
--- /dev/null
+++ b/packages/dsh-tauri-worktree/src/host/utils/worktree-facts.test.ts
@@ -0,0 +1,22 @@
+import type { Binding } from '../types'
+import { describe, expect, it } from 'vitest'
+import { worktreeSectionText } from './worktree-facts'
+
+describe('worktreeSectionText', () => {
+ it('preserves isolated worktree facts without referring to removed model tools', () => {
+ const text = worktreeSectionText({
+ hash: 'abc123',
+ dirname: 'feature',
+ worktreePath: 'C:/worktrees/abc123/feature',
+ projectPath: 'C:/project',
+ } as Binding)
+
+ expect(text).toContain('is_worktree: true')
+ expect(text).toContain('Worktree key: abc123/feature')
+ expect(text).toContain('Worktree path: C:/worktrees/abc123/feature')
+ expect(text).toContain('Project path: C:/project')
+ expect(text).toContain('do not read from or modify it in this session')
+ expect(text).not.toContain('create_worktree')
+ expect(text).not.toContain('checkout_worktree')
+ })
+})
diff --git a/packages/dsh-tauri-worktree/src/host/utils/worktree-facts.ts b/packages/dsh-tauri-worktree/src/host/utils/worktree-facts.ts
index ec198c38..64141209 100644
--- a/packages/dsh-tauri-worktree/src/host/utils/worktree-facts.ts
+++ b/packages/dsh-tauri-worktree/src/host/utils/worktree-facts.ts
@@ -19,10 +19,7 @@ export function worktreeSectionText(binding: Binding): string {
+ `do not read from or modify it in this session, even when the inherited history refers to it. `
+ `Dependency directories (e.g. node_modules) are linked from the source repository and the agent skills directory (.agents) is copied into the worktree, so it works out of the box. The Rust build cache (src-tauri/target) is NOT carried over: the backend recompiles from scratch in this worktree. `
+ `Running a package manager install (e.g. \`pnpm install\`) inside the worktree first detaches that link and materializes an independent copy, `
- + `leaving the source repository untouched. `
- + `checkout_worktree is user-authorized only: call it only after a direct human user explicitly requests or approves checkout. `
- + `Task completion, a merged PR, or inferred convenience is not permission to call it. When checkout would be a natural next step, `
- + `such as after a PR is merged, you may ask the user whether they want to check out the worktree; wait for their approval before calling.`
+ + `leaving the source repository untouched.`
)
}
@@ -38,11 +35,3 @@ export function worktreeContextText(binding: Binding): string {
+ `do not read from or modify it here, even when the inherited history refers to it.`
)
}
-
-export function worktreeHandoffText(binding: Binding): string {
- return (
- `${worktreeFactsText(binding)}\n\n`
- + `The task has moved to this isolated worktree session. `
- + `Continue the user request from the inherited context without explaining the handoff again.`
- )
-}
diff --git a/packages/dsh-tauri-worktree/src/index.ts b/packages/dsh-tauri-worktree/src/index.ts
index 5b115392..b23851f4 100644
--- a/packages/dsh-tauri-worktree/src/index.ts
+++ b/packages/dsh-tauri-worktree/src/index.ts
@@ -2,6 +2,6 @@ import { PLUGIN_ID } from './shared/constants'
export const name = PLUGIN_ID
-export const inject = ['tools', 'systemPrompt', 'webServer', 'sessions', 'workspaceRegistry', 'agents', 'connection']
+export const inject = ['systemPrompt', 'webServer', 'sessions', 'workspaceRegistry', 'agents', 'connection']
export { apply } from './host/apply'