Files
deepseek-harness/packages/experimental/tool-worktree/src/index.ts
T
Yichen Jiang accd5b77c4 feat(worktree): name generated worktrees after their Session
Generated worktree names now join the dsh- prefix, the first eight
hexadecimal digits of the UUID in the Session id, and four random
hexadecimal digits, such as dsh-6b1f02c4-9a3e. A Session id without a
UUID gets eight random hexadecimal digits after the prefix. The worktree
runtime exports generatedWorktreeName, uses it for omitted
create_worktree names, and defaults namePrefix to dsh-. The forge panel
names its Session worktrees with the same function and defaults
worktreePrefix to dsh-, so checkouts no longer nest under a dsh/
directory.

The create_worktree name parameter asks for a few lowercase words joined
by hyphens that describe the task, and the tool description drops the
defaults that its parameters already state.
2026-10-20 11:49:51 +08:00

44 lines
2.0 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 } 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 Error('create_worktree requires a calling agent')
return ctx.worktrees.create(exec.agent, args, exec.signal)
},
presentCall: args => ({ card: 'generic', title: 'create_worktree', rawInput: args }),
}))
}