( gitInstance: Git, defaultToken?: string )
| 83 | const AUTH_COMMANDS = new Set(["clone", "fetch", "pull", "push"]); |
| 84 | |
| 85 | function createGitToolProvider( |
| 86 | gitInstance: Git, |
| 87 | defaultToken?: string |
| 88 | ): ToolProvider { |
| 89 | const tools: Record< |
| 90 | string, |
| 91 | { description: string; execute: (...args: unknown[]) => Promise<unknown> } |
| 92 | > = {}; |
| 93 | |
| 94 | for (const cmd of GIT_COMMAND_NAMES) { |
| 95 | const fn = gitInstance[cmd] as ( |
| 96 | opts?: Record<string, unknown> |
| 97 | ) => Promise<unknown>; |
| 98 | tools[cmd] = { |
| 99 | description: `git.${cmd}`, |
| 100 | execute: (...args: unknown[]) => { |
| 101 | // positionalArgs mode: args may be [] (no args), [{}], or [{ url: ... }] |
| 102 | let opts = (args[0] ?? {}) as Record<string, unknown>; |
| 103 | // Auto-inject token for auth commands if not explicitly set |
| 104 | if ( |
| 105 | defaultToken && |
| 106 | AUTH_COMMANDS.has(cmd) && |
| 107 | !opts.token && |
| 108 | !opts.username |
| 109 | ) { |
| 110 | opts = { ...opts, token: defaultToken }; |
| 111 | } |
| 112 | return fn.call(gitInstance, opts); |
| 113 | } |
| 114 | }; |
| 115 | } |
| 116 | |
| 117 | return { |
| 118 | name: "git", |
| 119 | tools, |
| 120 | types: GIT_TYPES, |
| 121 | positionalArgs: true |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | export interface GitToolsOptions { |
| 126 | /** Default directory for git operations. */ |
no test coverage detected