Git 工作树

session 的 git 工具以宿主侧特权操作的方式运行 git。它接收一个结构化的命令对象 (command,worktree 操作还可带 subcommand/name/path),并返回包含 output 与退出码的工具结果。worktree 配合 subcommand: 'create' 会在 path 处 新建一个 worktree,并创建名为 name 的新分支。本示例先检查仓库,然后直接通过工具表面创建、 列出并移除一个 worktree。

Rust
Node.js
Python
Go

请传入命令对象,而不是位置参数:{ command: 'status' }、{ command: 'diff' } 或 { command: 'worktree', subcommand: 'list' }。command 的取值为 status、log、 branch、checkout、diff、stash、remote 和 worktree;该工具没有 commit 或 push 命令。每次调用都会返回一个工具结果, 因此在使用 output 之前,应先检查 exit_code(Rust/Python)、exitCode (Node.js)或 ExitCode(Go)。

直接 git 调用是宿主侧特权操作:它们会跳过会话的权限策略和确认提示。请在你的应用中为分支 切换和 worktree 移除设置关卡,或使用 governedTool('git', ...) / governed_tool / GovernedTool 保留会话的关卡。

可运行版本位于 sdk/node/examples/git/test_worktree_git.ts。