6d25adfd1a
* agent & model refactor with ASKPASS git auth, UI restructure, clerk v7 Made-with: Cursor * fix stale agent/effort refs, add tests for askpass + model resolution - reviewCleanup.ts: payload.agent -> payload.model, remove effort - selectMode.ts PlanEdit: remove delegation/subagent/effort references - pullfrog.yml.ts: update env vars (drop GOOGLE_API_KEY/CURSOR_API_KEY, add GOOGLE_GENERATIVE_AI_API_KEY/XAI_API_KEY/MOONSHOT_API_KEY/OPENCODE_API_KEY) - FlagsSettings/RepoInstructionsSection: remove stale effort/timeout copy - new: gitAuthServer.test.ts (10 tests — lifecycle, token delivery, tamper detection, script gen) - new: agent.test.ts (4 tests — default opentoad, AGENT_OVERRIDE, invalid override) - new: models.test.ts (19 tests — parseModel, resolution, registry invariants) - update models.dev snapshot Made-with: Cursor * fix changed-agents.sh to filter legacy agent files from CI matrix legacy agent files (claude.ts, codex.ts, etc.) are @ts-nocheck and not exported from index.ts. changed-agents.sh now reads index.ts imports to build the active agent set and treats changes to inactive files as non-agent changes (opentoad canary only). Made-with: Cursor * remove MCP file tools, old agent harnesses, and obsolete security tests ASKPASS-based git auth makes the old MCP file tool security layer unnecessary: - token never in subprocess env, so symlink/gitattributes/hook attacks can't exfiltrate it - agents now use native file tools (OpenCode builtin read/edit) deleted: - action/mcp/file.ts (file_read, file_write, file_edit, file_delete, list_directory) - action/mcp/index.ts (dead re-export) - agent harnesses: claude.ts, codex.ts, cursor.ts, gemini.ts, opencode.ts - opencode-runner.ts (inlined into opentoad.ts) - security tests that validated MCP file tool restrictions - commented-out three-step review flow (~300 lines) - sanitizeSchema/wrapSchema dead code from mcp/shared.ts - OPENCODE_MODEL_MINI/MAX env vars (effort-level model overrides removed) updated test prompts to use generic file ops instead of MCP tool names. restored pkg-json-scripts + requirements-txt-attack (test --ignore-scripts defense). Made-with: Cursor * bump actions/checkout v4 → v6 (node 24) node 20 actions deprecated june 2, 2026. Made-with: Cursor * temporarily disable fail-fast on agnostic tests to debug checkout@v6 Made-with: Cursor * re-enable fail-fast on agnostic tests Made-with: Cursor * fix test token mismatch: mint OIDC tokens scoped to target repo CI tests override GITHUB_REPOSITORY to pullfrog/test-repo but inherit the runner's GITHUB_TOKEN (scoped to pullfrog/app), causing 401s on every run-context fetch. Clear GITHUB_TOKEN in the test subprocess so ensureGitHubToken() mints a properly scoped token via OIDC. Also centralizes the default GITHUB_REPOSITORY in runAgentStreaming instead of repeating it in every test file, and fixes preview-cleanup to remove workers from all queues (not just name-matching ones). Made-with: Cursor * fix ensureGitHubToken to try OIDC when app credentials are absent ensureGitHubToken only attempted token minting when GITHUB_APP_ID and GITHUB_PRIVATE_KEY were set. In CI, OIDC is available but app creds aren't exposed — so the guard prevented minting entirely. Made-with: Cursor * dead code cleanup: remove remnants of deleted agents, file tools, effort system remove unused @anthropic-ai/claude-agent-sdk and @openai/codex-sdk deps, orphaned file-tool security tests, dead GEMINI_MODEL passthrough, stale opencode-runner wiki refs, deleted test file references, and MCP file tool docs. rename docs/effort → docs/models. fix vitest setup: move dotenv to globalSetup (runs once before forks instead of per-file, 19s → 200ms). Made-with: Cursor * address review feedback: remove dead code, update stale references - remove AGENT_OVERRIDE (only opentoad exists) - remove shellToolName plumbing (always restricted shell) - bump action version to 0.0.179 - remove CURSOR_API_KEY from all workflows/configs - remove OPENCODE_MODEL_MINI/MAX from workflows/docs - delete wiki/effort.md, rewrite docs/effort.mdx as "Models" - rewrite wiki/modes.md: orchestrator/subagent → single agent - simplify flag system: drop builtin flag extraction (debug, effort, timeout, agent), keep custom flag replacement only - reserve all legacy flag names to prevent custom flag conflicts Made-with: Cursor * regenerate lockfile after removing claude-agent-sdk and codex-sdk Made-with: Cursor * fix import ordering, add lockfile check to pre-push hook Made-with: Cursor * remove dead debug payload field, stale packageExtensions Made-with: Cursor * merge proc-sandbox and token-exfil into a single test proc-sandbox and token-exfil were duplicative — both tested that SANDBOX_TEST_TOKEN couldn't be exfiltrated. consolidated into token-exfil with shell:restricted (which actually exercises filterEnv) and the /proc attack vector hints from proc-sandbox. Made-with: Cursor * fix wiki adversarial.md to match actual tokenExfil validator Made-with: Cursor
172 lines
6.2 KiB
TypeScript
172 lines
6.2 KiB
TypeScript
import { execSync } from "node:child_process";
|
|
import { mkdtempSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import type { ShellPermission } from "../external.ts";
|
|
import type { ToolState } from "../mcp/server.ts";
|
|
import { log } from "./cli.ts";
|
|
import type { OctokitWithPlugins } from "./github.ts";
|
|
import { isInsideDocker } from "./globals.ts";
|
|
import { $ } from "./shell.ts";
|
|
|
|
export interface SetupOptions {
|
|
tempDir: string;
|
|
}
|
|
|
|
/**
|
|
* Create a shared temp directory for the action
|
|
*/
|
|
export function createTempDirectory(): string {
|
|
const sharedTempDir = mkdtempSync(join(tmpdir(), "pullfrog-"));
|
|
process.env.PULLFROG_TEMP_DIR = sharedTempDir;
|
|
log.info(`» created temp dir at ${sharedTempDir}`);
|
|
return sharedTempDir;
|
|
}
|
|
|
|
/**
|
|
* Setup the test repository for running actions
|
|
*/
|
|
export function setupTestRepo(options: SetupOptions): void {
|
|
const tempDir = options.tempDir;
|
|
const repo = process.env.GITHUB_REPOSITORY;
|
|
if (!repo) throw new Error("GITHUB_REPOSITORY is required");
|
|
log.info(`» cloning ${repo} into ${tempDir}...`);
|
|
|
|
// use https with token in ci or when running inside docker
|
|
if (process.env.CI || isInsideDocker) {
|
|
const token = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN;
|
|
if (!token) {
|
|
throw new Error("GITHUB_TOKEN or GH_TOKEN is required for https clone in ci or docker");
|
|
}
|
|
$("git", ["clone", `https://x-access-token:${token}@github.com/${repo}.git`, tempDir]);
|
|
} else {
|
|
$("git", ["clone", `git@github.com:${repo}.git`, tempDir]);
|
|
}
|
|
}
|
|
|
|
export interface GitContext {
|
|
gitToken: string;
|
|
owner: string;
|
|
name: string;
|
|
octokit: OctokitWithPlugins;
|
|
toolState: ToolState;
|
|
// shell permission level — controls hook and security behavior:
|
|
// enabled: full shell, hooks run, no restrictions
|
|
// restricted: MCP shell in stripped env, hooks run, token protection on auth ops
|
|
// disabled: no shell, hooks disabled globally, all code execution paths blocked
|
|
shell: ShellPermission;
|
|
postCheckoutScript: string | null;
|
|
}
|
|
|
|
export type SetupGitParams = GitContext;
|
|
|
|
/**
|
|
* setup git configuration and authentication for the repository.
|
|
* - configures git identity (user.email, user.name)
|
|
* - sets up authentication via gitToken (minimal contents:write)
|
|
* - for PR events, checks out the PR branch using shared helper
|
|
*
|
|
* gitToken is a minimal-permission token (contents + workflows) used for git operations.
|
|
* it is assumed to be potentially exfiltratable, so it has limited scope.
|
|
*/
|
|
export async function setupGit(params: SetupGitParams): Promise<void> {
|
|
const repoDir = process.cwd();
|
|
|
|
// 1. configure git identity
|
|
log.info("» setting up git configuration...");
|
|
try {
|
|
// check current config - only set defaults if not configured or using generic bot
|
|
let currentEmail = "";
|
|
try {
|
|
currentEmail = execSync("git config user.email", {
|
|
cwd: repoDir,
|
|
stdio: "pipe",
|
|
encoding: "utf-8",
|
|
}).trim();
|
|
} catch {
|
|
// not configured
|
|
}
|
|
|
|
const shouldSetDefaults =
|
|
!currentEmail || currentEmail === "github-actions[bot]@users.noreply.github.com";
|
|
|
|
if (shouldSetDefaults) {
|
|
execSync('git config --local user.email "226033991+pullfrog[bot]@users.noreply.github.com"', {
|
|
cwd: repoDir,
|
|
stdio: "pipe",
|
|
});
|
|
execSync('git config --local user.name "pullfrog[bot]"', {
|
|
cwd: repoDir,
|
|
stdio: "pipe",
|
|
});
|
|
log.debug("» git user configured (using defaults)");
|
|
} else {
|
|
log.debug(`» git user already configured (${currentEmail}), skipping`);
|
|
}
|
|
|
|
// SECURITY: disable git hooks when shell is disabled to prevent code execution.
|
|
// in restricted mode, hooks run in the stripped sandbox — that's fine.
|
|
// in enabled mode, the agent has full shell anyway.
|
|
// in disabled mode, hooks are the primary code-execution escape vector.
|
|
if (params.shell === "disabled") {
|
|
execSync("git config --local core.hooksPath /dev/null", {
|
|
cwd: repoDir,
|
|
stdio: "pipe",
|
|
});
|
|
log.debug("» git hooks disabled (shell=disabled)");
|
|
}
|
|
} catch (error) {
|
|
// If git config fails, log warning but don't fail the action
|
|
// This can happen if we're not in a git repo or git isn't available
|
|
log.info(`Failed to set git config: ${error instanceof Error ? error.message : String(error)}`);
|
|
}
|
|
|
|
// 2. setup authentication
|
|
// remove existing git auth headers that actions/checkout might have set
|
|
try {
|
|
execSync("git config --local --unset-all http.https://github.com/.extraheader", {
|
|
cwd: repoDir,
|
|
stdio: "pipe",
|
|
});
|
|
log.info("» removed existing authentication headers");
|
|
} catch {
|
|
log.debug("» no existing authentication headers to remove");
|
|
}
|
|
|
|
// remove includeIf entries that actions/checkout@v6 uses for credential persistence.
|
|
// v6 stores credentials in an external file loaded via includeIf.gitdir, which our
|
|
// --unset-all above doesn't catch. without this, stale credentials from actions/checkout
|
|
// would be sent alongside ASKPASS-provided credentials.
|
|
try {
|
|
const configOutput = execSync("git config --local --get-regexp ^includeif\\.", {
|
|
cwd: repoDir,
|
|
encoding: "utf-8",
|
|
stdio: "pipe",
|
|
});
|
|
for (const line of configOutput.trim().split("\n")) {
|
|
const key = line.split(" ")[0];
|
|
if (!key) continue;
|
|
execSync(`git config --local --unset "${key}"`, {
|
|
cwd: repoDir,
|
|
stdio: "pipe",
|
|
});
|
|
}
|
|
log.info("» removed includeIf credential entries");
|
|
} catch {
|
|
log.debug("» no includeIf credential entries to remove");
|
|
}
|
|
|
|
// SECURITY: set origin URL without token - auth is injected via GIT_ASKPASS
|
|
// in $git() calls. this prevents token leakage to git hooks and subprocesses.
|
|
const originUrl = `https://github.com/${params.owner}/${params.name}.git`;
|
|
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
|
|
|
// initialize pushUrl to base repo - may be updated by checkout_pr for fork PRs
|
|
params.toolState.pushUrl = originUrl;
|
|
|
|
// disable credential helpers to prevent prompts and ensure clean auth state
|
|
$("git", ["config", "--local", "credential.helper", ""], { cwd: repoDir });
|
|
|
|
log.info("» git authentication configured");
|
|
}
|