fix: Fix TypeScript error in agent mode git config

- Remove dependency on configureGitAuth which expects ParsedGitHubContext
- Implement git configuration directly for automation contexts
- Properly handle git authentication for agent mode
This commit is contained in:
km-anthropic
2025-08-21 11:26:11 -07:00
parent 7929f4a47f
commit ca512bcbe0

View File

@@ -4,7 +4,6 @@ import type { Mode, ModeOptions, ModeResult } from "../types";
import type { PreparedContext } from "../../create-prompt/types"; import type { PreparedContext } from "../../create-prompt/types";
import { prepareMcpConfig } from "../../mcp/install-mcp-server"; import { prepareMcpConfig } from "../../mcp/install-mcp-server";
import { parseAllowedTools } from "./parse-tools"; import { parseAllowedTools } from "./parse-tools";
import { configureGitAuth } from "../../github/operations/git-config";
/** /**
* Agent mode implementation. * Agent mode implementation.
@@ -42,20 +41,37 @@ export const agentMode: Mode = {
return false; return false;
}, },
async prepare({ context, githubToken, octokit }: ModeOptions): Promise<ModeResult> { async prepare({
// Configure git authentication for agent mode (same as tag mode) context,
// Fetch the authenticated user to set proper git identity githubToken,
octokit,
}: ModeOptions): Promise<ModeResult> {
// Configure git authentication for agent mode
// Since agent mode is for automation contexts, we need to set up git differently
if (!context.inputs.useCommitSigning) { if (!context.inputs.useCommitSigning) {
try { try {
// Get the authenticated user (will be claude[bot] when using Claude App token) // Get the authenticated user (will be claude[bot] when using Claude App token)
const { data: authenticatedUser } = await octokit.rest.users.getAuthenticated(); const { data: authenticatedUser } =
const user = { await octokit.rest.users.getAuthenticated();
login: authenticatedUser.login,
id: authenticatedUser.id,
};
// Configure git with the authenticated user's identity // Set up git config directly for automation contexts
await configureGitAuth(githubToken, context, user); const { $ } = await import("bun");
const serverUrl = new URL(
process.env.GITHUB_SERVER_URL || "https://github.com",
);
const noreplyDomain =
serverUrl.hostname === "github.com"
? "users.noreply.github.com"
: `users.noreply.${serverUrl.hostname}`;
await $`git config user.name "${authenticatedUser.login}"`;
await $`git config user.email "${authenticatedUser.id}+${authenticatedUser.login}@${noreplyDomain}"`;
// Set up token authentication
const authHeader = `Authorization: token ${githubToken}`;
await $`git config http.${serverUrl.origin}/.extraheader "${authHeader}"`;
console.log(`✓ Configured git as ${authenticatedUser.login}`);
} catch (error) { } catch (error) {
console.error("Failed to configure git authentication:", error); console.error("Failed to configure git authentication:", error);
// Continue anyway - git operations may still work with default config // Continue anyway - git operations may still work with default config
@@ -83,11 +99,15 @@ export const agentMode: Mode = {
// Check for branch info from environment variables (useful for auto-fix workflows) // Check for branch info from environment variables (useful for auto-fix workflows)
const claudeBranch = process.env.CLAUDE_BRANCH || undefined; const claudeBranch = process.env.CLAUDE_BRANCH || undefined;
const baseBranch = process.env.BASE_BRANCH || context.inputs.baseBranch || "main"; const baseBranch =
process.env.BASE_BRANCH || context.inputs.baseBranch || "main";
// Detect current branch from GitHub environment // Detect current branch from GitHub environment
const currentBranch = claudeBranch || const currentBranch =
process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || "main"; claudeBranch ||
process.env.GITHUB_HEAD_REF ||
process.env.GITHUB_REF_NAME ||
"main";
// Get our GitHub MCP servers config // Get our GitHub MCP servers config
const ourMcpConfig = await prepareMcpConfig({ const ourMcpConfig = await prepareMcpConfig({