DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
refactor(dsh-tauri-worktree): reshape the routes into REST resources
hairyff9437d4699e9
diff --git a/packages/dsh-tauri-worktree/src/client/components/mode-select.tsx b/packages/dsh-tauri-worktree/src/client/components/mode-select.tsxindex 30c0ac1e..47aa5fa0 100644--- a/packages/dsh-tauri-worktree/src/client/components/mode-select.tsx+++ b/packages/dsh-tauri-worktree/src/client/components/mode-select.tsx@@ -104,11 +104,14 @@ function WorktreeModeControl({ sessionId, useInput, inputActions, sessionsRuntimif (!created.ok || !created.result)throw new Error(created.error ?? 'Failed to create worktree.')const result = created.result+ const worktreePath = result.worktreePath+ if (!worktreePath)+ throw new Error('Failed to create worktree.')if (result.inherited) {await waitForSessionListed({ sessions: sessionsRuntime, sessionId: targetSessionId, wait })}else {- await sessionsRuntime.create({ cwd: result.worktreePath, sessionId: targetSessionId })+ await sessionsRuntime.create({ cwd: worktreePath, sessionId: targetSessionId })}await attach({ sessionId: targetSessionId })const nextActions = await waitForInputActions({ sessions: sessionsRuntime, sessionId: targetSessionId, wait })diff --git a/packages/dsh-tauri-worktree/src/client/constants/index.ts b/packages/dsh-tauri-worktree/src/client/constants/index.tsindex fb1ecd9e..3f14ac78 100644--- a/packages/dsh-tauri-worktree/src/client/constants/index.ts+++ b/packages/dsh-tauri-worktree/src/client/constants/index.ts@@ -1,6 +1,6 @@import { PLUGIN_ID } from '../../shared/constants'-export { WORKTREE_API_PREFIX, PLUGIN_ID } from '../../shared/constants'+export { PLUGIN_ID } from '../../shared/constants'export const INPUT_DOCK_SLOT = 'conversation.input.dock'export const SHELL_OVERLAY_SLOT = 'shell.overlay'diff --git a/packages/dsh-tauri-worktree/src/client/index.ts b/packages/dsh-tauri-worktree/src/client/index.tsindex a2597c6e..857c79db 100644--- a/packages/dsh-tauri-worktree/src/client/index.ts+++ b/packages/dsh-tauri-worktree/src/client/index.ts@@ -4,11 +4,11 @@ import {HYDRATION_EFFECT,LOCALE_EFFECT,MODE_SELECT_EFFECT,+ PLUGIN_ID,PREFERENCES_EFFECT,SESSION_ICONS_EFFECT,STYLES_EFFECT,SURFACE_EFFECT,- PLUGIN_ID,} from './constants'import { locale } from './locales'import { dialogFeature } from './register/dialog'@@ -19,7 +19,6 @@ import { sessionIconsFeature } from './register/session-icons'import { stylesFeature } from './register/styles'import { surfaceFeature } from './register/surface'-export { WORKTREE_API_PREFIX } from '../shared/constants'export type * from './apis/index.type'export type * from './store/modules/worktree.types'diff --git a/packages/dsh-tauri-worktree/src/client/register/dialog.ts b/packages/dsh-tauri-worktree/src/client/register/dialog.tsindex f4f96b21..734a0e59 100644--- a/packages/dsh-tauri-worktree/src/client/register/dialog.ts+++ b/packages/dsh-tauri-worktree/src/client/register/dialog.ts@@ -2,7 +2,7 @@ import type { ClientContext } from 'dsh-tauri/client'import type { WorktreeDialogProps } from '../components/dialog.types'import { defineRegister } from 'dsh-tauri/client'import { WorktreeDialog } from '../components/dialog'-import { DIALOG_ID, SHELL_OVERLAY_SLOT, PLUGIN_ID } from '../constants'+import { DIALOG_ID, PLUGIN_ID, SHELL_OVERLAY_SLOT } from '../constants'export const dialogFeature = defineRegister<ClientContext>((controller, ctx, adapter) => {controller.add(ctx.slots.inject(SHELL_OVERLAY_SLOT, () =>diff --git a/packages/dsh-tauri-worktree/src/client/register/hydration.test.ts b/packages/dsh-tauri-worktree/src/client/register/hydration.test.tsindex 18dc1303..bc5b283a 100644--- a/packages/dsh-tauri-worktree/src/client/register/hydration.test.ts+++ b/packages/dsh-tauri-worktree/src/client/register/hydration.test.ts@@ -1,11 +1,13 @@import type { WorktreeBindings } from '../apis/index.type'import { createLifecycleController } from 'dsh-tauri/client'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'-import { DISCARD_POLL_DELAY_MS, HYDRATION_RETRY_BUDGET_PER_SECOND, HYDRATION_RETRY_WINDOW_MS, SESSION_RECONCILE_MIN_INTERVAL_MS, WORKTREE_API_PREFIX } from '../constants'+import { DISCARD_POLL_DELAY_MS, HYDRATION_RETRY_BUDGET_PER_SECOND, HYDRATION_RETRY_WINDOW_MS, SESSION_RECONCILE_MIN_INTERVAL_MS } from '../constants'import { registerWorktreeHydration } from './hydration'+const BASE_URL = '/api/desktop/dsh-tauri-worktree'+const mocks = vi.hoisted(() => ({- fetch: vi.fn<(url: string, options?: { method?: string, body?: unknown }) => Promise<unknown>>(),+ fetch: vi.fn<(url: string, options?: { method?: string, body?: unknown, baseURL?: string, params?: Record<string, string> }) => Promise<unknown>>(),}))vi.mock('dsh-tauri/client', async () => {@@ -84,6 +86,7 @@ vi.mock('dsh-tauri/client', async () => {return {fetch: mocks.fetch,+ ofetch: mocks.fetch,createStorage: () => ({ getItem: async () => null, setItem: async () => {} }),localStorageDriver: () => ({}),defineLocale: (namespace: string) => ({@@ -190,14 +193,14 @@ function harness(const list = snapshotSource<{ ids: string[], current?: string }>({ ids, current })const workspaces = snapshotSource({ archivedSessionIds: [...(options.archived ?? [])] as string[] })- mocks.fetch.mockImplementation(async (url: string) => {+ mocks.fetch.mockImplementation(async (url: string, request?: { params?: Record<string, string> }) => {const target = String(url)if (target.includes('/bindings'))return options.bindings ?? EMPTY_BINDINGS- const matched = /sessionId=([^&]+)/.exec(target)- if (!target.includes('/status') || !matched)+ const sessionId = request?.params?.sessionId+ if (!target.includes('/status') || typeof sessionId !== 'string')return { ok: true }- const payload = statusFor(decodeURIComponent(matched[1]))+ const payload = statusFor(sessionId)if (options.holdStatus)await new Promise<void>((resolve) => { releaseHeld = resolve })return payload@@ -241,7 +244,7 @@ function harness(const urls = (): string[] => mocks.fetch.mock.calls.map(call => String(call[0]))const deleteCalls = (): number => mocks.fetch.mock.calls- .filter(call => String(call[0]) === WORKTREE_API_PREFIX && call[1]?.method === 'DELETE')+ .filter(call => call[1]?.baseURL === BASE_URL && call[1]?.method?.toUpperCase() === 'DELETE').lengthconst controller = createLifecycleController()registerWorktreeHydration(controller as never, ctx.sessions as never, ctx.workspaces as never)@@ -266,10 +269,9 @@ function harness(discardCalls: deleteCalls,publishWorkspaces: () => workspaces.publish({ archivedSessionIds: [...(workspaces.getSnapshot().archivedSessionIds)] }),setArchived: (next: string[]) => workspaces.publish({ archivedSessionIds: [...next] }),- callsFor: (sessionId: string) => {- const pattern = new RegExp(`sessionId=${sessionId}(?:&|$)`)- return urls().filter(url => url.includes('/status') && pattern.test(url)).length- },+ callsFor: (sessionId: string) => mocks.fetch.mock.calls+ .filter(call => String(call[0]).includes('/status') && call[1]?.params?.sessionId === sessionId)+ .length,subscribeCount: (sessionId: string) => subscribeCalls.get(sessionId) ?? 0,releaseStatus: () => {const release = releaseHelddiff --git a/packages/dsh-tauri-worktree/src/client/service/preferences.ts b/packages/dsh-tauri-worktree/src/client/service/preferences.tsindex c876a55b..2d58dcb5 100644--- a/packages/dsh-tauri-worktree/src/client/service/preferences.ts+++ b/packages/dsh-tauri-worktree/src/client/service/preferences.ts@@ -1,6 +1,6 @@import type { WorktreeNewSessionMode } from '../store/modules/worktree.types'import { createStorage, get, localStorageDriver } from 'dsh-tauri/client'-import { PREFERRED_MODE_STORAGE_KEY, PLUGIN_ID } from '../constants'+import { PLUGIN_ID, PREFERRED_MODE_STORAGE_KEY } from '../constants'import { store } from '../store'const storage = createStorage({ driver: localStorageDriver({ base: PLUGIN_ID }) })diff --git a/packages/dsh-tauri-worktree/src/client/service/worktree.ts b/packages/dsh-tauri-worktree/src/client/service/worktree.tsindex d680a1f5..d7fc5f2b 100644--- a/packages/dsh-tauri-worktree/src/client/service/worktree.ts+++ b/packages/dsh-tauri-worktree/src/client/service/worktree.ts@@ -1,7 +1,7 @@import type { WorktreeStatus } from '../apis/index.type'import type { ActionResult, CheckoutOutcome, CreateOutcome, DiscardOutcome, DiscardProgress } from './worktree.types'import { get } from 'dsh-tauri/client'-import { deleteDiscard, getStatus, postAttach, postCheckout, postCreate } from '../apis'+import { deleteWorktree, getStatus, postBindings, postCheckouts, postWorktree } from '../apis'import { locale } from '../locales'import { store } from '../store'@@ -24,7 +24,7 @@ export async function create(input: {inherit: boolean}): Promise<CreateOutcome> {try {- const created = await postCreate(input)+ const created = await postWorktree(input)store.worktree.patch(input.sessionId, {mode: 'worktree',phase: 'created',@@ -45,7 +45,7 @@ export async function create(input: {export async function attach(input: { sessionId: string }): Promise<ActionResult> {try {- await postAttach(input)+ await postBindings(input)return { ok: true }}catch (error) {@@ -59,7 +59,7 @@ export async function checkout(input: {branchName: string}): Promise<CheckoutOutcome> {try {- const result = await postCheckout({+ const result = await postCheckouts({sessionId: input.sessionId,worktreeHashDirname: input.worktreeKey,branchName: input.branchName,@@ -87,7 +87,7 @@ export async function discard(input: {}): Promise<DiscardOutcome> {store.worktree.patch(input.sessionId, { phase: 'deleting', abandonOpen: false, error: '' })try {- const result = await deleteDiscard({+ const result = await deleteWorktree({sessionId: input.sessionId,worktreeHashDirname: input.worktreeKey,})diff --git a/packages/dsh-tauri-worktree/src/host/config/constants.ts b/packages/dsh-tauri-worktree/src/host/config/constants.tsindex 9698d115..9957eb04 100644--- a/packages/dsh-tauri-worktree/src/host/config/constants.ts+++ b/packages/dsh-tauri-worktree/src/host/config/constants.ts@@ -1,37 +1,2 @@-export const WORKTREE_BRANCH_NAME_PATTERN = /^[\w./-]+$/-export const WORKTREES_DIR = 'worktrees'export const TRASH_DIR = '.trash'-export const LEDGER_DIR = 'ledger'-export const CHECKOUT_CONTEXT_DIR = 'checkout-context'--export const DISCARD_JOB_RETENTION = 64-export const DISCARD_RETRY_ATTEMPTS = 3-export const DISCARD_RETRY_DELAY_MS = 2_000--export const DEFAULT_LINK_DIRECTORIES: readonly string[] = ['node_modules']--export const LINK_DEPENDENCIES = true--export const SHELL_TOOL_NAMES: ReadonlySet<string> = new Set([- 'bash',- 'pwsh',- 'shell',- 'sh',- 'zsh',- 'terminal',- 'run_command',- 'exec',-])--export const INSTALL_PATTERNS: readonly RegExp[] = [- /\b(?:npm|pnpm|yarn|yarnpkg|bun|corepack|pnpx|npx)\s+(?:install|i|ci|add|update|upgrade|up|remove|rm|uninstall|unlink|link|dedupe|prune|rebuild|install-test|it)\b/i,- /(?:^|[\s;&|()])yarn\s*(?:$|[\s;&|()])/i,- /\b(?:pip|pip3|pipenv|poetry|uv|conda|mamba)\s+(?:install|sync|add|update|upgrade|lock|remove|uninstall)\b/i,- /\bcargo\s+(?:fetch|build|install|update)\b/i,- /\bgo\s+(?:mod\s+(?:download|tidy|vendor)|get)\b/i,- /\b(?:bundle|bundler)\s+install\b/i,- /\bcomposer\s+(?:install|update|require|remove)\b/i,- /\bdotnet\s+(?:restore|add\s+package)\b/i,- /\b(?:mvn|maven|gradle|gradlew)\b[^\n;&|]+\bdependenc(?:y|ies)\b/i,-]diff --git a/packages/dsh-tauri-worktree/src/host/routes/bindings/get.ts b/packages/dsh-tauri-worktree/src/host/routes/bindings/get.tsindex b76d3a69..55988931 100644--- a/packages/dsh-tauri-worktree/src/host/routes/bindings/get.ts+++ b/packages/dsh-tauri-worktree/src/host/routes/bindings/get.ts@@ -1,9 +1,11 @@+import type { EventHandlerRequest } from 'dsh-tauri'+import type { WorktreeBindings } from '../index.types'import { existsSync } from 'node:fs'import { defineEventHandler } from 'dsh-tauri'import { cleaner } from '../../service/cleaner'import { ledger } from '../../service/ledger'-export default defineEventHandler(async () => ({+export default defineEventHandler<EventHandlerRequest, Promise<WorktreeBindings>>(async () => ({bindings: ledger.list().filter(binding => binding.worktreePath && existsSync(binding.worktreePath)).map(binding => ({diff --git a/packages/dsh-tauri-worktree/src/host/routes/attach/post.ts b/packages/dsh-tauri-worktree/src/host/routes/bindings/post.tssimilarity index 70%rename from packages/dsh-tauri-worktree/src/host/routes/attach/post.tsrename to packages/dsh-tauri-worktree/src/host/routes/bindings/post.tsindex 80b6461f..8c63839f 100644--- a/packages/dsh-tauri-worktree/src/host/routes/attach/post.ts+++ b/packages/dsh-tauri-worktree/src/host/routes/bindings/post.ts@@ -1,11 +1,9 @@+import type { EventHandlerRequest } from 'dsh-tauri'+import type { AttachBody, WorktreeAttach } from '../index.types'import { defineEventHandler, readBody } from 'dsh-tauri'import { workspace } from '../../service/workspace'-interface AttachBody {- sessionId?: unknown-}--export default defineEventHandler(async (event) => {+export default defineEventHandler<EventHandlerRequest, Promise<WorktreeAttach>>(async (event) => {const body = (await readBody<AttachBody>(event)) ?? {}const sessionId = String(body.sessionId ?? '')if (!sessionId) {diff --git a/packages/dsh-tauri-worktree/src/host/routes/checkout/post.ts b/packages/dsh-tauri-worktree/src/host/routes/checkouts/post.tssimilarity index 72%rename from packages/dsh-tauri-worktree/src/host/routes/checkout/post.tsrename to packages/dsh-tauri-worktree/src/host/routes/checkouts/post.tsindex 2fe5feb1..bb283d70 100644--- a/packages/dsh-tauri-worktree/src/host/routes/checkout/post.ts+++ b/packages/dsh-tauri-worktree/src/host/routes/checkouts/post.ts@@ -1,14 +1,9 @@+import type { EventHandlerRequest } from 'dsh-tauri'+import type { CheckoutBody, WorktreeCheckout } from '../index.types'import { defineEventHandler, readBody } from 'dsh-tauri'import { handoff } from '../../service/handoff'-interface CheckoutBody {- sessionId?: unknown- worktreeHashDirname?: unknown- branchName?: unknown- carryStaged?: unknown-}--export default defineEventHandler(async (event) => {+export default defineEventHandler<EventHandlerRequest, Promise<WorktreeCheckout>>(async (event) => {const body = (await readBody<CheckoutBody>(event)) ?? {}const result = await handoff.checkout(String(body.sessionId ?? ''),diff --git a/packages/dsh-tauri-worktree/src/host/routes/delete.ts b/packages/dsh-tauri-worktree/src/host/routes/delete.tsindex 662ed0d8..f21268e5 100644--- a/packages/dsh-tauri-worktree/src/host/routes/delete.ts+++ b/packages/dsh-tauri-worktree/src/host/routes/delete.ts@@ -1,12 +1,9 @@+import type { EventHandlerRequest } from 'dsh-tauri'+import type { DiscardBody, WorktreeDiscard } from './index.types'import { defineEventHandler, readBody } from 'dsh-tauri'import { worktree } from '../service/worktree'-interface DiscardBody {- sessionId?: unknown- worktreeHashDirname?: unknown-}--export default defineEventHandler(async (event) => {+export default defineEventHandler<EventHandlerRequest, Promise<WorktreeDiscard>>(async (event) => {const body = (await readBody<DiscardBody>(event, { type: 'json' })) ?? {}const result = await worktree.discard(String(body.sessionId ?? ''),diff --git a/packages/dsh-tauri-worktree/src/host/routes/index.test.ts b/packages/dsh-tauri-worktree/src/host/routes/index.test.tsindex 6f73cbcb..f3dfbdc7 100644--- a/packages/dsh-tauri-worktree/src/host/routes/index.test.ts+++ b/packages/dsh-tauri-worktree/src/host/routes/index.test.ts@@ -9,10 +9,11 @@ import { join } from 'pathe'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { routes } from '.'import { resetTestDshHome } from '../../../../.test/test-utils'-import { WORKTREE_API_PREFIX as P } from '../../shared/constants'import { clearHostRuntime } from '../config/runtime'import { ledger } from '../service/ledger'+const P = '/api/desktop/dsh-tauri-worktree'+vi.mock('dsh-tauri', async (importOriginal) => {const actual = await importOriginal<typeof import('dsh-tauri')>()const { testDshHome: home } = await import('../../../../.test/test-utils')@@ -25,16 +26,14 @@ const EXPECTED_PATHS: readonly string[] = [P,`${P}/bindings`,`${P}/status`,- `${P}/attach`,- `${P}/checkout`,+ `${P}/checkouts`,]const ALLOW_BY_PATH: Readonly<Record<string, string>> = {[P]: 'POST, DELETE, OPTIONS',- [`${P}/bindings`]: 'GET, HEAD, OPTIONS',+ [`${P}/bindings`]: 'GET, HEAD, POST, OPTIONS',[`${P}/status`]: 'GET, HEAD, OPTIONS',- [`${P}/attach`]: 'POST, OPTIONS',- [`${P}/checkout`]: 'POST, OPTIONS',+ [`${P}/checkouts`]: 'POST, OPTIONS',}const UNDECLARED_METHOD = 'PUT'@@ -172,7 +171,7 @@ describe('工作树路由声明', () => {const dispose = routes(harness.ctx)const base = await listen(harness.registered)- for (const path of [P, `${P}/attach`]) {+ for (const path of [P, `${P}/bindings`]) {const response = await sendJson(base, path, 'POST', '{}')expect(response.status, path).toBe(400)expect(await response.json(), path).toEqual({ error: '缺少 sessionId' })diff --git a/packages/dsh-tauri-worktree/src/host/routes/index.ts b/packages/dsh-tauri-worktree/src/host/routes/index.tsindex cae5ede3..9a733fb3 100644--- a/packages/dsh-tauri-worktree/src/host/routes/index.ts+++ b/packages/dsh-tauri-worktree/src/host/routes/index.ts@@ -1,17 +1,16 @@import { defineRoutes } from 'dsh-tauri'-import { WORKTREE_API_PREFIX } from '../../shared/constants'-import attach from './attach/post'import bindings from './bindings/get'-import checkout from './checkout/post'+import attach from './bindings/post'+import checkout from './checkouts/post'import deleteWorktree from './delete'import postWorktree from './post'import status from './status/get'export const routes = defineRoutes((disposer) => {- disposer.post({ kind: 'exact', path: WORKTREE_API_PREFIX }, postWorktree)- disposer.delete({ kind: 'exact', path: WORKTREE_API_PREFIX }, deleteWorktree)- disposer.get({ kind: 'exact', path: `${WORKTREE_API_PREFIX}/bindings` }, bindings)- disposer.get({ kind: 'exact', path: `${WORKTREE_API_PREFIX}/status` }, status)- disposer.post({ kind: 'exact', path: `${WORKTREE_API_PREFIX}/attach` }, attach)- disposer.post({ kind: 'exact', path: `${WORKTREE_API_PREFIX}/checkout` }, checkout)+ disposer.post({ kind: 'exact', path: '/api/desktop/dsh-tauri-worktree' }, postWorktree)+ disposer.delete({ kind: 'exact', path: '/api/desktop/dsh-tauri-worktree' }, deleteWorktree)+ disposer.get({ kind: 'exact', path: '/api/desktop/dsh-tauri-worktree/bindings' }, bindings)+ disposer.get({ kind: 'exact', path: '/api/desktop/dsh-tauri-worktree/status' }, status)+ disposer.post({ kind: 'exact', path: '/api/desktop/dsh-tauri-worktree/bindings' }, attach)+ disposer.post({ kind: 'exact', path: '/api/desktop/dsh-tauri-worktree/checkouts' }, checkout)})diff --git a/packages/dsh-tauri-worktree/src/host/routes/index.types.ts b/packages/dsh-tauri-worktree/src/host/routes/index.types.tsnew file mode 100644index 00000000..33c53aa0--- /dev/null+++ b/packages/dsh-tauri-worktree/src/host/routes/index.types.ts@@ -0,0 +1,100 @@+export interface CreateBody {+ sessionId?: string+ sourceSessionId?: string+ carryStaged?: boolean+ inherit?: boolean+}++export interface DiscardBody {+ sessionId?: string+ worktreeHashDirname?: string+}++export interface AttachBody {+ sessionId?: string+}++export interface CheckoutBody {+ sessionId?: string+ worktreeHashDirname?: string+ branchName?: string+ carryStaged?: boolean+}++export interface GetStatusQuery {+ sessionId?: string+ jobId?: string+}++export interface WorktreeCreate {+ ok?: boolean+ error?: string+ hash?: string+ dirname?: string+ worktreeKey?: string+ worktreePath?: string+ projectPath?: string+ sourceSessionId?: string+ log?: string[]+ existed?: boolean+ inherited?: boolean+}++export interface WorktreeDiscard {+ ok?: boolean+ jobId?: string+ error?: string+}++export interface WorktreeAttach {+ ok?: boolean+ workspaceId?: string+ error?: string+}++export interface WorktreeCheckout {+ ok?: boolean+ branch?: string+ projectPath?: string+ targetSessionId?: string+ error?: string+}++export interface WorktreeBindingSummary {+ sessionId: string+ sourceSessionId: string+ hash: string+ dirname: string+ worktreeKey: string+ worktreePath: string+ projectPath: string+ log: string[]+}++export interface WorktreeDiscardJobSummary {+ sessionId: string+ jobId: string+ state: string+ error?: string+ worktreeKey: string+ worktreePath?: string+}++export interface WorktreeBindings {+ bindings: WorktreeBindingSummary[]+ jobs: WorktreeDiscardJobSummary[]+}++export interface WorktreeStatus {+ mode?: string+ jobId?: string+ error?: string+ hash?: string+ dirname?: string+ worktreeKey?: string+ worktreePath?: string+ projectPath?: string+ sourceSessionId?: string+ log?: string[]+ isGit?: boolean | null+}diff --git a/packages/dsh-tauri-worktree/src/host/routes/post.ts b/packages/dsh-tauri-worktree/src/host/routes/post.tsindex ab2c6d67..04212fcb 100644--- a/packages/dsh-tauri-worktree/src/host/routes/post.ts+++ b/packages/dsh-tauri-worktree/src/host/routes/post.ts@@ -1,16 +1,11 @@+import type { EventHandlerRequest } from 'dsh-tauri'+import type { CreateBody, WorktreeCreate } from './index.types'import { defineEventHandler, readBody } from 'dsh-tauri'import { handoff } from '../service/handoff'import { sessionContext } from '../service/session-context'import { worktree } from '../service/worktree'-interface CreateBody {- sessionId?: unknown- sourceSessionId?: unknown- carryStaged?: unknown- inherit?: unknown-}--export default defineEventHandler(async (event) => {+export default defineEventHandler<EventHandlerRequest, Promise<WorktreeCreate>>(async (event) => {const body = (await readBody<CreateBody>(event)) ?? {}const sessionId = String(body.sessionId ?? '')const sourceSessionId = String(body.sourceSessionId ?? sessionId)diff --git a/packages/dsh-tauri-worktree/src/host/routes/status/get.ts b/packages/dsh-tauri-worktree/src/host/routes/status/get.tsindex ad43d4ab..f42751a5 100644--- a/packages/dsh-tauri-worktree/src/host/routes/status/get.ts+++ b/packages/dsh-tauri-worktree/src/host/routes/status/get.ts@@ -1,8 +1,10 @@+import type { EventHandlerRequest } from 'dsh-tauri'+import type { GetStatusQuery, WorktreeStatus } from '../index.types'import { defineEventHandler, getQuery } from 'dsh-tauri'import { status } from '../../service/status'-export default defineEventHandler(async (event) => {- const query = getQuery(event)+export default defineEventHandler<EventHandlerRequest, Promise<WorktreeStatus>>(async (event) => {+ const query = getQuery<GetStatusQuery>(event)const sessionId = typeof query.sessionId === 'string' ? query.sessionId : ''const jobId = typeof query.jobId === 'string' ? query.jobId : ''const facts = await status.resolve(sessionId, jobId)diff --git a/packages/dsh-tauri-worktree/src/host/service/checkout-context.ts b/packages/dsh-tauri-worktree/src/host/service/checkout-context.tsindex aa154436..5633ade0 100644--- a/packages/dsh-tauri-worktree/src/host/service/checkout-context.ts+++ b/packages/dsh-tauri-worktree/src/host/service/checkout-context.ts@@ -2,9 +2,10 @@ import type { CheckoutContext } from '../types'import { readFileSync } from 'node:fs'import { defineService, DSH_HOME } from 'dsh-tauri'import { join } from 'pathe'-import { CHECKOUT_CONTEXT_DIR } from '../config/constants'import { storage } from '../storage'+const CHECKOUT_CONTEXT_DIR = 'checkout-context'+export const checkoutContext = defineService({load(sessionId: string): CheckoutContext | null {try {diff --git a/packages/dsh-tauri-worktree/src/host/service/cleaner.ts b/packages/dsh-tauri-worktree/src/host/service/cleaner.tsindex e826e280..23f30f68 100644--- a/packages/dsh-tauri-worktree/src/host/service/cleaner.ts+++ b/packages/dsh-tauri-worktree/src/host/service/cleaner.ts@@ -2,7 +2,12 @@ import type { DiscardJob, OperationResult } from '../types'import { randomUUID } from 'node:crypto'import { defineService } from 'dsh-tauri'import { filter, find, findLast, get, take } from 'lodash-es'-import { DISCARD_JOB_RETENTION, DISCARD_RETRY_ATTEMPTS, DISCARD_RETRY_DELAY_MS } from '../config/constants'++const DISCARD_JOB_RETENTION = 64++const DISCARD_RETRY_ATTEMPTS = 3++const DISCARD_RETRY_DELAY_MS = 2_000const jobs = new Map<string, DiscardJob>()const inFlight = new Map<string, Promise<DiscardJob>>()diff --git a/packages/dsh-tauri-worktree/src/host/service/ledger.ts b/packages/dsh-tauri-worktree/src/host/service/ledger.tsindex 2277e741..50e6a746 100644--- a/packages/dsh-tauri-worktree/src/host/service/ledger.ts+++ b/packages/dsh-tauri-worktree/src/host/service/ledger.ts@@ -3,9 +3,10 @@ import { readdirSync, readFileSync } from 'node:fs'import { defineService, DSH_HOME } from 'dsh-tauri'import { compact, filter, isPlainObject } from 'lodash-es'import { join } from 'pathe'-import { LEDGER_DIR } from '../config/constants'import { storage } from '../storage'+const LEDGER_DIR = 'ledger'+export const ledger = defineService({load(sessionId: string): Binding | null {return readBinding(join(DSH_HOME, keyOf(sessionId)))diff --git a/packages/dsh-tauri-worktree/src/host/service/worktree.ts b/packages/dsh-tauri-worktree/src/host/service/worktree.tsindex 7b063b41..d0810dd1 100644--- a/packages/dsh-tauri-worktree/src/host/service/worktree.ts+++ b/packages/dsh-tauri-worktree/src/host/service/worktree.ts@@ -12,7 +12,7 @@ import process from 'node:process'import { defineService, DSH_HOME } from 'dsh-tauri'import { compact, filter, find, get, isEmpty, map, reject, some } from 'lodash-es'import { join, resolve } from 'pathe'-import { LINK_DEPENDENCIES, TRASH_DIR, WORKTREE_BRANCH_NAME_PATTERN, WORKTREES_DIR } from '../config/constants'+import { TRASH_DIR, WORKTREES_DIR } from '../config/constants'import { getCurrentHostInstance } from '../config/runtime'import {isDependencyInstallCommand,@@ -38,6 +38,10 @@ import { cleaner } from './cleaner'import { ledger } from './ledger'import { workspace } from './workspace'+const WORKTREE_BRANCH_NAME_PATTERN = /^[\w./-]+$/++const LINK_DEPENDENCIES = true+export const worktree = defineService({async create(projectPath: string,diff --git a/packages/dsh-tauri-worktree/src/host/utils/dependencies.ts b/packages/dsh-tauri-worktree/src/host/utils/dependencies.tsindex 2c7529af..d402c0c6 100644--- a/packages/dsh-tauri-worktree/src/host/utils/dependencies.ts+++ b/packages/dsh-tauri-worktree/src/host/utils/dependencies.ts@@ -3,7 +3,31 @@ import { lstat, rm, symlink } from 'node:fs/promises'import process from 'node:process'import { filter, find, get, isEmpty, isString, map, trimEnd, uniqBy } from 'lodash-es'import { resolve } from 'pathe'-import { DEFAULT_LINK_DIRECTORIES, INSTALL_PATTERNS, SHELL_TOOL_NAMES } from '../config/constants'++const DEFAULT_LINK_DIRECTORIES: readonly string[] = ['node_modules']++const SHELL_TOOL_NAMES: ReadonlySet<string> = new Set([+ 'bash',+ 'pwsh',+ 'shell',+ 'sh',+ 'zsh',+ 'terminal',+ 'run_command',+ 'exec',+])++const INSTALL_PATTERNS: readonly RegExp[] = [+ /\b(?:npm|pnpm|yarn|yarnpkg|bun|corepack|pnpx|npx)\s+(?:install|i|ci|add|update|upgrade|up|remove|rm|uninstall|unlink|link|dedupe|prune|rebuild|install-test|it)\b/i,+ /(?:^|[\s;&|()])yarn\s*(?:$|[\s;&|()])/i,+ /\b(?:pip|pip3|pipenv|poetry|uv|conda|mamba)\s+(?:install|sync|add|update|upgrade|lock|remove|uninstall)\b/i,+ /\bcargo\s+(?:fetch|build|install|update)\b/i,+ /\bgo\s+(?:mod\s+(?:download|tidy|vendor)|get)\b/i,+ /\b(?:bundle|bundler)\s+install\b/i,+ /\bcomposer\s+(?:install|update|require|remove)\b/i,+ /\bdotnet\s+(?:restore|add\s+package)\b/i,+ /\b(?:mvn|maven|gradle|gradlew)\b[^\n;&|]+\bdependenc(?:y|ies)\b/i,+]export function normalizeLinkDirectories(directories?: readonly string[]): string[] {const source = isEmpty(directories) ? DEFAULT_LINK_DIRECTORIES : directories ?? []diff --git a/packages/dsh-tauri-worktree/src/index.ts b/packages/dsh-tauri-worktree/src/index.tsindex 59a7044e..5b115392 100644--- a/packages/dsh-tauri-worktree/src/index.ts+++ b/packages/dsh-tauri-worktree/src/index.ts@@ -1,9 +1,7 @@-import { WORKTREE_API_PREFIX, PLUGIN_ID } from './shared/constants'+import { PLUGIN_ID } from './shared/constants'export const name = PLUGIN_IDexport const inject = ['tools', 'systemPrompt', 'webServer', 'sessions', 'workspaceRegistry', 'agents', 'connection']-export const API_PREFIX = WORKTREE_API_PREFIX-export { apply } from './host/apply'diff --git a/packages/dsh-tauri-worktree/src/shared/constants.ts b/packages/dsh-tauri-worktree/src/shared/constants.tsindex 2d121264..c1a405f4 100644--- a/packages/dsh-tauri-worktree/src/shared/constants.ts+++ b/packages/dsh-tauri-worktree/src/shared/constants.ts@@ -1,5 +1,3 @@export const PLUGIN_ID = 'dsh-tauri-worktree'-export const WORKTREE_API_PREFIX = '/api/dsh-worktree'-export const WORKTREE_SECTION_ORDER = 210