Files
deepseek-harness/packages/experimental/tool-worktree/src/index.ts
T
sjw1231 2c45f0d705 feat(worktree): add WorktreeError for create_worktree failures
Invalid names and requests, existing branches or paths, locked
registrations, failed, oversized, or timed-out commands, and a disposed
service now throw WorktreeError with a closed WORKTREE_* code. The
retained-artifact wrapper keeps the name and code of a HarnessError it
wraps and keeps caller cancellation an AbortError. create_worktree
throws ToolContextUnavailableError without a calling agent.

Refs #7869
2026-11-09 14:51:45 +08:00

44 lines
2.1 KiB
TypeScript

/** Model tool for creating and entering a new Git worktree through the shared runtime. */
import type { Context } from '@deepseek-ai/cordis'
import type {} from '@deepseek-ai/dsh-experimental-worktree'
import { defineTool, ToolContextUnavailableError } from '@deepseek-ai/dsh-tools'
/** Cordis plugin name. */
export const name = 'tool-worktree'
/** Services required to register and execute the worktree tool. */
export const inject = ['tools', 'worktrees']
/**
* Register create_worktree for model and PTC callers.
* @param ctx - tool registry and worktree runtime.
*/
export function apply(ctx: Context): void {
ctx.tools.register(defineTool({
name: 'create_worktree',
description: 'Create a new Git branch and worktree from a local commit, branch, or tag, then change this session\'s working directory to it. Uncommitted files stay in the source checkout. Existing names fail. Use working_directory with cd to leave; the checkout and branch remain.',
parameters: {
name: { type: 'string', description: 'New branch name, also used as the checkout directory: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to generate a unique name.' },
from: { type: 'string', description: 'Local commit, branch, or tag to start from. Defaults to HEAD; no fetch is performed.' },
},
output: {
schema: {
type: 'object',
additionalProperties: false,
properties: {
path: { type: 'string', required: true },
branch: { type: 'string', required: true },
baseCommit: { type: 'string', required: true },
repositoryRoot: { type: 'string', required: true },
},
},
render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }],
},
async execute(args, exec) {
if (exec.agent === undefined) throw new ToolContextUnavailableError('create_worktree requires a calling agent')
return ctx.worktrees.create(exec.agent, args, exec.signal)
},
presentCall: args => ({ card: 'generic', title: 'create_worktree', rawInput: args }),
}))
}