Code style (#97)

* Cleanup

* fix: populate deny array before assigning to config, add CursorCliConfig type

* Fix deny array ordering and add CursorCliConfig type

Move deny array population before config declaration to avoid
relying on reference semantics. Add proper type interface for
the CLI config object.

---------

Co-authored-by: pullfrog[bot] <226033991+pullfrog[bot]@users.noreply.github.com>
This commit is contained in:
Colin McDonnell
2026-01-15 22:06:53 +00:00
committed by pullfrog[bot]
parent 0ccaa68d3a
commit 2d2d31adfa
13 changed files with 713 additions and 779 deletions
+101 -112
View File
@@ -100032,11 +100032,19 @@ var package_default = {
packageManager: "pnpm@10.27.0+sha512.72d699da16b1179c14ba9e64dc71c9a40988cbdc65c264cb0e489db7de917f20dcf4d64d8723625f2969ba52d4b7e2a1170682d9ac2a5dcaeaab732b7e16f04a"
};
// utils/cli.ts
// utils/log.ts
var core = __toESM(require_core(), 1);
var import_table = __toESM(require_src(), 1);
var isGitHubActions = !!process.env.GITHUB_ACTIONS;
var isDebugEnabled = () => process.env.LOG_LEVEL === "debug" || process.env.ACTIONS_STEP_DEBUG === "true" || process.env.RUNNER_DEBUG === "1" || core.isDebug();
function formatArgs(args3) {
return args3.map((arg) => {
if (typeof arg === "string") return arg;
if (arg instanceof Error) return `${arg.message}
${arg.stack}`;
return JSON.stringify(arg);
}).join(" ");
}
function startGroup2(name) {
if (isGitHubActions) {
core.startGroup(name);
@@ -100145,25 +100153,25 @@ function separator(length = 50) {
}
var log = {
/** Print info message */
info: (message) => {
core.info(message);
info: (...args3) => {
core.info(formatArgs(args3));
},
/** Print warning message */
warning: (message) => {
core.warning(message);
warning: (...args3) => {
core.warning(formatArgs(args3));
},
/** Print error message */
error: (message) => {
core.error(message);
error: (...args3) => {
core.error(formatArgs(args3));
},
/** Print success message */
success: (message) => {
core.info(`\u2705 ${message}`);
success: (...args3) => {
core.info(`\u2705 ${formatArgs(args3)}`);
},
/** Print debug message (only if LOG_LEVEL=debug) */
debug: (message) => {
debug: (...args3) => {
if (isDebugEnabled()) {
core.info(`[DEBUG] ${message}`);
core.info(`[DEBUG] ${formatArgs(args3)}`);
}
},
/** Print a formatted box with text */
@@ -100420,14 +100428,14 @@ function getShellInstructions(bash) {
}
}
}
var addInstructions = ({ payload, repo, tools }) => {
var addInstructions = (ctx) => {
let encodedEvent = "";
const eventKeys = Object.keys(payload.event);
const eventKeys = Object.keys(ctx.payload.event);
if (eventKeys.length === 1 && eventKeys[0] === "trigger") {
} else {
encodedEvent = encode(payload.event);
encodedEvent = encode(ctx.payload.event);
}
const runtimeContext = buildRuntimeContext(repo);
const runtimeContext = buildRuntimeContext(ctx.repo);
return `
***********************************************
************* SYSTEM INSTRUCTIONS *************
@@ -100475,7 +100483,7 @@ Tool names may be formatted as \`(server name)/(tool name)\`, for example: \`${g
**Efficiency**: Trust the tools - do not repeatedly verify file contents or git status after operations. If a tool reports success, proceed to the next step. Only verify if you encounter an actual error.
${getShellInstructions(tools.bash)}
${getShellInstructions(ctx.tools.bash)}
**Command execution**: Never use \`sleep\` to wait for commands to complete. Commands run synchronously - when the bash tool returns, the command has finished.
@@ -100496,7 +100504,7 @@ ${getShellInstructions(tools.bash)}
### Available modes
${[...getModes({ disableProgressComment: payload.disableProgressComment }), ...payload.modes].map((w) => ` - "${w.name}": ${w.description}`).join("\n")}
${[...getModes({ disableProgressComment: ctx.payload.disableProgressComment }), ...ctx.payload.modes].map((w) => ` - "${w.name}": ${w.description}`).join("\n")}
### Following the mode instructions
@@ -100506,7 +100514,7 @@ Eagerly inspect the MCP tools available to you via the \`${ghPullfrogMcpName}\`
************* USER PROMPT *************
${payload.prompt.split("\n").map((line) => `> ${line}`).join("\n")}
${ctx.payload.prompt.split("\n").map((line) => `> ${line}`).join("\n")}
${encodedEvent ? `************* EVENT DATA *************
@@ -104635,12 +104643,12 @@ var claudeEffortModels = {
auto: "opusplan",
max: "opus"
};
function buildDisallowedTools(tools) {
function buildDisallowedTools(ctx) {
const disallowed = [];
if (tools.web === "disabled") disallowed.push("WebFetch");
if (tools.search === "disabled") disallowed.push("WebSearch");
if (tools.write === "disabled") disallowed.push("Write");
if (tools.bash !== "enabled") disallowed.push("Bash");
if (ctx.tools.web === "disabled") disallowed.push("WebFetch");
if (ctx.tools.search === "disabled") disallowed.push("WebSearch");
if (ctx.tools.write === "disabled") disallowed.push("Write");
if (ctx.tools.bash !== "enabled") disallowed.push("Bash");
return disallowed;
}
var claude = agent({
@@ -104653,23 +104661,23 @@ var claude = agent({
executablePath: "cli.js"
});
},
run: async ({ payload, mcpServers, apiKey, cliPath, repo, effort, tools }) => {
run: async (ctx) => {
delete process.env.ANTHROPIC_API_KEY;
const prompt = addInstructions({ payload, repo, tools });
const prompt = addInstructions(ctx);
log.group("Full prompt", () => log.info(prompt));
const model = claudeEffortModels[effort];
log.info(`Using model: ${model} (effort: ${effort})`);
const disallowedTools = buildDisallowedTools(tools);
const model = claudeEffortModels[ctx.effort];
log.info(`Using model: ${model} (effort: ${ctx.effort})`);
const disallowedTools = buildDisallowedTools(ctx);
if (disallowedTools.length > 0) {
log.info(`\u{1F512} disallowed tools: ${disallowedTools.join(", ")}`);
}
const queryOptions = {
permissionMode: "bypassPermissions",
disallowedTools,
mcpServers,
mcpServers: ctx.mcpServers,
model,
pathToClaudeCodeExecutable: cliPath,
env: createAgentEnv({ ANTHROPIC_API_KEY: apiKey })
pathToClaudeCodeExecutable: ctx.cliPath,
env: createAgentEnv({ ANTHROPIC_API_KEY: ctx.apiKey })
};
const queryInstance = query({
prompt,
@@ -105132,19 +105140,20 @@ var codexReasoningEffort = {
// use default
max: "high"
};
function writeCodexConfig({ tempHome, mcpServers, tools }) {
function writeCodexConfig(ctx) {
const tempHome = process.env.PULLFROG_TEMP_DIR;
const codexDir = join6(tempHome, ".codex");
mkdirSync3(codexDir, { recursive: true });
const configPath = join6(codexDir, "config.toml");
const mcpServerSections = [];
for (const [name, config4] of Object.entries(mcpServers)) {
for (const [name, config4] of Object.entries(ctx.mcpServers)) {
if (config4.type !== "http") continue;
log.info(`\xBB adding MCP server '${name}' at ${config4.url}`);
mcpServerSections.push(`[mcp_servers.${name}]
url = "${config4.url}"`);
}
const features = [];
if (tools.bash !== "enabled") {
if (ctx.tools.bash !== "enabled") {
features.push("shell_command_tool = false");
features.push("unified_exec = false");
}
@@ -105159,7 +105168,7 @@ ${mcpServerSections.join("\n\n")}
`.trim() + "\n"
);
log.info(
`\xBB Codex config written to ${configPath} (shell: ${tools.bash === "enabled" ? "enabled" : "disabled"})`
`\xBB Codex config written to ${configPath} (shell: ${ctx.tools.bash === "enabled" ? "enabled" : "disabled"})`
);
return codexDir;
}
@@ -105172,41 +105181,37 @@ var codex = agent({
executablePath: "bin/codex.js"
});
},
run: async ({ payload, mcpServers, apiKey, cliPath, repo, effort, tools }) => {
run: async (ctx) => {
const tempHome = process.env.PULLFROG_TEMP_DIR;
const configDir = join6(tempHome, ".config", "codex");
mkdirSync3(configDir, { recursive: true });
const codexDir = writeCodexConfig({
tempHome,
mcpServers,
tools
});
const codexDir = writeCodexConfig(ctx);
setupProcessAgentEnv({
OPENAI_API_KEY: apiKey,
OPENAI_API_KEY: ctx.apiKey,
HOME: tempHome,
CODEX_HOME: codexDir
// point Codex to our config directory
});
const model = codexModel[effort];
const modelReasoningEffort = codexReasoningEffort[effort];
const model = codexModel[ctx.effort];
const modelReasoningEffort = codexReasoningEffort[ctx.effort];
log.info(`Using model: ${model}`);
if (modelReasoningEffort) {
log.info(`Using modelReasoningEffort: ${modelReasoningEffort}`);
}
const codexOptions = {
apiKey,
codexPathOverride: cliPath
apiKey: ctx.apiKey,
codexPathOverride: ctx.cliPath
};
const codex2 = new Codex(codexOptions);
const threadOptions = {
model,
approvalPolicy: "never",
// write: "disabled" → read-only sandbox, otherwise full access for git ops
sandboxMode: tools.write === "disabled" ? "read-only" : "danger-full-access",
sandboxMode: ctx.tools.write === "disabled" ? "read-only" : "danger-full-access",
// web: controls network access
networkAccessEnabled: tools.web !== "disabled",
networkAccessEnabled: ctx.tools.web !== "disabled",
// search: controls web search
webSearchEnabled: tools.search !== "disabled",
webSearchEnabled: ctx.tools.search !== "disabled",
...modelReasoningEffort && { modelReasoningEffort }
};
log.info(
@@ -105214,7 +105219,7 @@ var codex = agent({
);
const thread = codex2.startThread(threadOptions);
try {
const streamedTurn = await thread.runStreamed(addInstructions({ payload, repo, tools }));
const streamedTurn = await thread.runStreamed(addInstructions(ctx));
let finalOutput2 = "";
for await (const event of streamedTurn.events) {
const handler2 = messageHandlers2[event.type];
@@ -105341,9 +105346,9 @@ var cursor = agent({
executableName: "cursor-agent"
});
},
run: async ({ payload, apiKey, cliPath, mcpServers, repo, effort, tools }) => {
configureCursorMcpServers({ mcpServers, cliPath });
configureCursorTools({ tools });
run: async (ctx) => {
configureCursorMcpServers(ctx);
configureCursorTools(ctx);
const projectCliConfigPath = join7(process.cwd(), ".cursor", "cli.json");
let modelOverride = null;
if (existsSync4(projectCliConfigPath)) {
@@ -105352,18 +105357,18 @@ var cursor = agent({
if (projectConfig.model) {
log.info(`Using model from project .cursor/cli.json: ${projectConfig.model}`);
} else {
modelOverride = cursorEffortModels[effort];
modelOverride = cursorEffortModels[ctx.effort];
}
} catch {
modelOverride = cursorEffortModels[effort];
modelOverride = cursorEffortModels[ctx.effort];
}
} else {
modelOverride = cursorEffortModels[effort];
modelOverride = cursorEffortModels[ctx.effort];
}
if (modelOverride) {
log.info(`Using model: ${modelOverride} (effort: ${effort})`);
log.info(`Using model: ${modelOverride} (effort: ${ctx.effort})`);
} else if (!existsSync4(projectCliConfigPath)) {
log.info(`Using default model (effort: ${effort})`);
log.info(`Using default model (effort: ${ctx.effort})`);
}
const loggedModelCallIds = /* @__PURE__ */ new Set();
const messageHandlers5 = {
@@ -105415,7 +105420,7 @@ var cursor = agent({
}
};
try {
const fullPrompt = addInstructions({ payload, repo, tools });
const fullPrompt = addInstructions(ctx);
log.group("Full prompt", () => log.info(fullPrompt));
const baseArgs = ["--print", fullPrompt, "--output-format", "stream-json", "--approve-mcps"];
if (modelOverride) {
@@ -105425,10 +105430,10 @@ var cursor = agent({
log.info("Running Cursor CLI...");
const startTime = Date.now();
return new Promise((resolve2) => {
const child = spawn3(cliPath, cursorArgs, {
const child = spawn3(ctx.cliPath, cursorArgs, {
cwd: process.cwd(),
env: createAgentEnv({
CURSOR_API_KEY: apiKey
CURSOR_API_KEY: ctx.apiKey
}),
stdio: ["ignore", "pipe", "pipe"]
// Ignore stdin, pipe stdout/stderr
@@ -105503,13 +105508,13 @@ var cursor = agent({
}
}
});
function configureCursorMcpServers({ mcpServers }) {
function configureCursorMcpServers(ctx) {
const realHome = homedir2();
const cursorConfigDir = join7(realHome, ".cursor");
const mcpConfigPath = join7(cursorConfigDir, "mcp.json");
mkdirSync4(cursorConfigDir, { recursive: true });
const cursorMcpServers = {};
for (const [serverName, serverConfig] of Object.entries(mcpServers)) {
for (const [serverName, serverConfig] of Object.entries(ctx.mcpServers)) {
if (serverConfig.type !== "http") {
throw new Error(
`Unsupported MCP server type for Cursor: ${serverConfig.type || "unknown"}`
@@ -105523,33 +105528,29 @@ function configureCursorMcpServers({ mcpServers }) {
writeFileSync2(mcpConfigPath, JSON.stringify({ mcpServers: cursorMcpServers }, null, 2), "utf-8");
log.info(`\xBB MCP config written to ${mcpConfigPath}`);
}
function configureCursorTools({ tools }) {
function configureCursorTools(ctx) {
const realHome = homedir2();
const cursorConfigDir = join7(realHome, ".config", "cursor");
const cliConfigPath = join7(cursorConfigDir, "cli-config.json");
mkdirSync4(cursorConfigDir, { recursive: true });
const deny = [];
if (tools.search === "disabled") deny.push("WebSearch");
if (tools.write === "disabled") deny.push("Write(**)");
if (tools.bash !== "enabled") deny.push("Shell(*)");
const needsSandbox = tools.web === "disabled";
if (ctx.tools.search === "disabled") deny.push("WebSearch");
if (ctx.tools.write === "disabled") deny.push("Write(**)");
if (ctx.tools.bash !== "enabled") deny.push("Shell(*)");
const config4 = {
permissions: {
allow: tools.write === "disabled" ? ["Read(**)"] : ["Read(**)", "Write(**)"],
allow: ctx.tools.write === "disabled" ? ["Read(**)"] : ["Read(**)", "Write(**)"],
deny
}
};
if (needsSandbox) {
if (ctx.tools.web === "disabled") {
config4.sandbox = {
mode: "enabled",
networkAccess: "allowlist"
};
}
writeFileSync2(cliConfigPath, JSON.stringify(config4, null, 2), "utf-8");
log.info(`\xBB CLI config written to ${cliConfigPath}`);
log.info(
`\u{1F527} Cursor permissions: allow=${config4.permissions.allow.join(",")}, deny=${deny.join(",") || "(none)"}, sandbox=${needsSandbox ? "enabled" : "disabled"}`
);
log.info(`\xBB CLI config written to ${cliConfigPath}`, JSON.stringify(config4, null, 2));
}
// agents/gemini.ts
@@ -105725,14 +105726,12 @@ var gemini = agent({
...githubInstallationToken2 && { githubInstallationToken: githubInstallationToken2 }
});
},
run: async ({ payload, apiKey, mcpServers, cliPath, repo, effort, tools }) => {
const { model, thinkingLevel } = geminiEffortConfig[effort];
log.info(`Using model: ${model}, thinkingLevel: ${thinkingLevel}`);
configureGeminiSettings({ mcpServers, tools, thinkingLevel });
if (!apiKey) {
run: async (ctx) => {
const model = configureGeminiSettings(ctx);
if (!ctx.apiKey) {
throw new Error("google_api_key or gemini_api_key is required for gemini agent");
}
const sessionPrompt = addInstructions({ payload, repo, tools });
const sessionPrompt = addInstructions(ctx);
log.group("Full prompt", () => log.info(sessionPrompt));
const args3 = ["--model", model, "--yolo", "--output-format=stream-json", "-p", sessionPrompt];
let finalOutput2 = "";
@@ -105740,8 +105739,8 @@ var gemini = agent({
try {
const result = await spawn4({
cmd: "node",
args: [cliPath, ...args3],
env: createAgentEnv({ GEMINI_API_KEY: apiKey }),
args: [ctx.cliPath, ...args3],
env: createAgentEnv({ GEMINI_API_KEY: ctx.apiKey }),
onStdout: async (chunk) => {
const text = chunk.toString();
finalOutput2 += text;
@@ -105798,11 +105797,9 @@ var gemini = agent({
}
}
});
function configureGeminiSettings({
mcpServers,
tools,
thinkingLevel
}) {
function configureGeminiSettings(ctx) {
const { model, thinkingLevel } = geminiEffortConfig[ctx.effort];
log.info(`Using model: ${model}, thinkingLevel: ${thinkingLevel}`);
const realHome = homedir3();
const geminiConfigDir = join8(realHome, ".gemini");
const settingsPath = join8(geminiConfigDir, "settings.json");
@@ -105814,7 +105811,7 @@ function configureGeminiSettings({
} catch {
}
const geminiMcpServers = {};
for (const [serverName, serverConfig] of Object.entries(mcpServers)) {
for (const [serverName, serverConfig] of Object.entries(ctx.mcpServers)) {
if (serverConfig.type !== "http") {
throw new Error(
`Unsupported MCP server type for Gemini: ${serverConfig.type || "unknown"}`
@@ -105828,10 +105825,10 @@ function configureGeminiSettings({
log.info(`adding MCP server '${serverName}' at ${serverConfig.url}...`);
}
const exclude = [];
if (tools.bash !== "enabled") exclude.push("run_shell_command");
if (tools.write === "disabled") exclude.push("write_file");
if (tools.web === "disabled") exclude.push("web_fetch");
if (tools.search === "disabled") exclude.push("google_web_search");
if (ctx.tools.bash !== "enabled") exclude.push("run_shell_command");
if (ctx.tools.write === "disabled") exclude.push("write_file");
if (ctx.tools.web === "disabled") exclude.push("web_fetch");
if (ctx.tools.search === "disabled") exclude.push("google_web_search");
const newSettings = {
...existingSettings,
mcpServers: geminiMcpServers,
@@ -105852,6 +105849,7 @@ function configureGeminiSettings({
if (exclude.length > 0) {
log.info(`\u{1F512} excluded tools: ${exclude.join(", ")}`);
}
return model;
}
// agents/opencode.ts
@@ -105867,21 +105865,12 @@ var opencode = agent({
installDependencies: true
});
},
run: async ({
payload,
apiKey: _apiKey,
apiKeys,
mcpServers,
cliPath,
repo,
effort: _effort,
tools
}) => {
run: async (ctx) => {
const tempHome = process.env.PULLFROG_TEMP_DIR;
const configDir = join9(tempHome, ".config", "opencode");
mkdirSync6(configDir, { recursive: true });
configureOpenCode({ mcpServers, tools });
const prompt = addInstructions({ payload, repo, tools });
configureOpenCode(ctx);
const prompt = addInstructions(ctx);
log.group("Full prompt", () => log.info(prompt));
const args3 = ["run", prompt, "--format", "json"];
setupProcessAgentEnv({ HOME: tempHome });
@@ -105890,14 +105879,14 @@ var opencode = agent({
XDG_CONFIG_HOME: join9(tempHome, ".config")
};
delete env3.GITHUB_TOKEN;
for (const [key, value2] of Object.entries(apiKeys || {})) {
for (const [key, value2] of Object.entries(ctx.apiKeys || {})) {
env3[key.toUpperCase()] = value2;
if (key === "GEMINI_API_KEY") {
env3.GOOGLE_GENERATIVE_AI_API_KEY = value2;
}
}
const repoDir = process.cwd();
log.info(`\u{1F680} Starting OpenCode CLI: ${cliPath} ${args3.join(" ")}`);
log.info(`\u{1F680} Starting OpenCode CLI: ${ctx.cliPath} ${args3.join(" ")}`);
log.info(`\u{1F4C1} Working directory: ${repoDir}`);
log.debug(`\u{1F3E0} HOME: ${env3.HOME}`);
log.debug(`\u{1F4CB} XDG_CONFIG_HOME: ${env3.XDG_CONFIG_HOME}`);
@@ -105907,7 +105896,7 @@ var opencode = agent({
let output = "";
let stdoutBuffer = "";
const result = await spawn4({
cmd: cliPath,
cmd: ctx.cliPath,
args: args3,
cwd: repoDir,
env: env3,
@@ -105993,13 +105982,13 @@ var opencode = agent({
};
}
});
function configureOpenCode({ mcpServers, tools }) {
function configureOpenCode(ctx) {
const tempHome = process.env.PULLFROG_TEMP_DIR;
const configDir = join9(tempHome, ".config", "opencode");
mkdirSync6(configDir, { recursive: true });
const configPath = join9(configDir, "opencode.json");
const opencodeMcpServers = {};
for (const [serverName, serverConfig] of Object.entries(mcpServers)) {
for (const [serverName, serverConfig] of Object.entries(ctx.mcpServers)) {
if (serverConfig.type !== "http") {
log.error(
`unsupported MCP server type for OpenCode: ${serverConfig.type || "unknown"}`
@@ -106014,9 +106003,9 @@ function configureOpenCode({ mcpServers, tools }) {
};
}
const permission = {
edit: tools.write === "disabled" ? "deny" : "allow",
bash: tools.bash !== "enabled" ? "deny" : "allow",
webfetch: tools.web === "disabled" ? "deny" : "allow",
edit: ctx.tools.write === "disabled" ? "deny" : "allow",
bash: ctx.tools.bash !== "enabled" ? "deny" : "allow",
webfetch: ctx.tools.web === "disabled" ? "deny" : "allow",
doom_loop: "allow",
external_directory: "allow"
};