Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 887f37236d | |||
| 727e407ed3 | |||
| 421eecebe3 | |||
| cc46af0d47 | |||
| 53970308ee | |||
| 7c8dd7f43c | |||
| de686da001 | |||
| c456fae716 | |||
| 20b08b5321 | |||
| c0fd69560f | |||
| e0bd984975 | |||
| c4d66bf7f6 | |||
| 1d2a06998c | |||
| 6311138132 | |||
| 1ed3da8273 |
@@ -437,6 +437,15 @@ export const opencode = agent({
|
||||
};
|
||||
}
|
||||
|
||||
if (eventCount === 0 && lastProviderError) {
|
||||
return {
|
||||
success: false,
|
||||
output: finalOutput || output,
|
||||
error: `provider error: ${lastProviderError}`,
|
||||
usage,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: finalOutput || output,
|
||||
|
||||
+15
-3
@@ -229,8 +229,8 @@ interface FixReviewEvent extends BasePayloadEvent {
|
||||
issue_number: number;
|
||||
is_pr: true;
|
||||
review_id: number;
|
||||
/** username of the person who triggered this action - use with get_review_comments approved_by */
|
||||
triggerer: string;
|
||||
/** when true, only address comments the triggerer approved with 👍 (vs all comments) */
|
||||
approved_only?: boolean | undefined;
|
||||
}
|
||||
|
||||
interface ImplementPlanEvent extends BasePayloadEvent {
|
||||
@@ -241,6 +241,17 @@ interface ImplementPlanEvent extends BasePayloadEvent {
|
||||
body: string | null;
|
||||
}
|
||||
|
||||
interface PullRequestSynchronizeEvent extends BasePayloadEvent {
|
||||
trigger: "pull_request_synchronize";
|
||||
issue_number: number;
|
||||
is_pr: true;
|
||||
title: string;
|
||||
body: string | null;
|
||||
branch: string;
|
||||
/** SHA before the push -- used to compute incremental diff via `git diff before_sha...HEAD` */
|
||||
before_sha: string;
|
||||
}
|
||||
|
||||
interface UnknownEvent extends BasePayloadEvent {
|
||||
trigger: "unknown";
|
||||
}
|
||||
@@ -250,6 +261,7 @@ interface UnknownEvent extends BasePayloadEvent {
|
||||
export type PayloadEvent =
|
||||
| PullRequestOpenedEvent
|
||||
| PullRequestReadyForReviewEvent
|
||||
| PullRequestSynchronizeEvent
|
||||
| PullRequestReviewRequestedEvent
|
||||
| PullRequestReviewSubmittedEvent
|
||||
| PullRequestReviewCommentCreatedEvent
|
||||
@@ -273,7 +285,7 @@ export interface WriteablePayload {
|
||||
/** the user's actual request (body if @pullfrog tagged) */
|
||||
prompt: string;
|
||||
/** github username of the human who triggered this workflow run */
|
||||
triggeringUser?: string | undefined;
|
||||
triggerer?: string | undefined;
|
||||
/** event-level instructions for this trigger type (flag-expanded server-side) */
|
||||
eventInstructions?: string | undefined;
|
||||
/** repo-level instructions (flag-expanded server-side) */
|
||||
|
||||
@@ -25507,6 +25507,7 @@ var core3 = __toESM(require_core(), 1);
|
||||
// utils/log.ts
|
||||
var core = __toESM(require_core(), 1);
|
||||
var import_table = __toESM(require_src(), 1);
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
// utils/globals.ts
|
||||
import { existsSync } from "node:fs";
|
||||
@@ -25515,6 +25516,20 @@ var isGitHubActions = !!process.env.GITHUB_ACTIONS;
|
||||
var isInsideDocker = existsSync("/.dockerenv");
|
||||
|
||||
// utils/log.ts
|
||||
var logContext = new AsyncLocalStorage();
|
||||
var MAGENTA = "\x1B[35m";
|
||||
var RESET = "\x1B[0m";
|
||||
function prefixLines(message) {
|
||||
const ctx = logContext.getStore();
|
||||
if (!ctx) return message;
|
||||
const colored = `${MAGENTA}${ctx.prefix}${RESET} `;
|
||||
return message.split("\n").map((line) => `${colored}${line}`).join("\n");
|
||||
}
|
||||
function prefixPlain(name) {
|
||||
const ctx = logContext.getStore();
|
||||
if (!ctx) return name;
|
||||
return `${ctx.prefix} ${name}`;
|
||||
}
|
||||
var isRunnerDebugEnabled = () => core.isDebug();
|
||||
var isLocalDebugEnabled = () => process.env.LOG_LEVEL === "debug" || process.env.ACTIONS_STEP_DEBUG === "true";
|
||||
var isDebugEnabled = () => isLocalDebugEnabled() || isRunnerDebugEnabled();
|
||||
@@ -25530,10 +25545,11 @@ ${arg.stack}`;
|
||||
}).join(" ");
|
||||
}
|
||||
function startGroup2(name) {
|
||||
const prefixed = prefixPlain(name);
|
||||
if (isGitHubActions) {
|
||||
core.startGroup(name);
|
||||
core.startGroup(prefixed);
|
||||
} else {
|
||||
console.group(name);
|
||||
console.group(prefixed);
|
||||
}
|
||||
}
|
||||
function endGroup2() {
|
||||
@@ -25606,7 +25622,7 @@ function boxString(text, options) {
|
||||
}
|
||||
function box(text, options) {
|
||||
const boxContent = boxString(text, options);
|
||||
core.info(boxContent);
|
||||
core.info(prefixLines(boxContent));
|
||||
}
|
||||
function printTable(rows, options) {
|
||||
const { title } = options || {};
|
||||
@@ -25620,42 +25636,42 @@ function printTable(rows, options) {
|
||||
);
|
||||
const formatted = (0, import_table.table)(tableData);
|
||||
if (title) {
|
||||
core.info(`
|
||||
${title}`);
|
||||
core.info(prefixLines(`
|
||||
${title}`));
|
||||
}
|
||||
core.info(`
|
||||
core.info(prefixLines(`
|
||||
${formatted}
|
||||
`);
|
||||
`));
|
||||
}
|
||||
function separator(length = 50) {
|
||||
const separatorText = "\u2500".repeat(length);
|
||||
core.info(separatorText);
|
||||
core.info(prefixLines(separatorText));
|
||||
}
|
||||
var log = {
|
||||
/** Print info message */
|
||||
info: (...args) => {
|
||||
core.info(`${ts()}${formatArgs(args)}`);
|
||||
core.info(prefixLines(`${ts()}${formatArgs(args)}`));
|
||||
},
|
||||
/** Print a warning message. Use only for warnings that should be displayed in the job summary. */
|
||||
warning: (...args) => {
|
||||
core.warning(`${ts()}${formatArgs(args)}`);
|
||||
core.warning(prefixLines(`${ts()}${formatArgs(args)}`));
|
||||
},
|
||||
/** Print an error message. Use only for errors that should be displayed in the job summary. */
|
||||
error: (...args) => {
|
||||
core.error(`${ts()}${formatArgs(args)}`);
|
||||
core.error(prefixLines(`${ts()}${formatArgs(args)}`));
|
||||
},
|
||||
/** Print success message */
|
||||
success: (...args) => {
|
||||
core.info(`${ts()}\xBB ${formatArgs(args)}`);
|
||||
core.info(prefixLines(`${ts()}\xBB ${formatArgs(args)}`));
|
||||
},
|
||||
/** Print debug message (only when debug mode is enabled) */
|
||||
debug: (...args) => {
|
||||
if (isRunnerDebugEnabled()) {
|
||||
core.debug(formatArgs(args));
|
||||
core.debug(prefixLines(formatArgs(args)));
|
||||
return;
|
||||
}
|
||||
if (isLocalDebugEnabled()) {
|
||||
core.info(`${ts()}[DEBUG] ${formatArgs(args)}`);
|
||||
core.info(prefixLines(`${ts()}[DEBUG] ${formatArgs(args)}`));
|
||||
}
|
||||
},
|
||||
/** Print a formatted box with text */
|
||||
@@ -25683,8 +25699,8 @@ function formatJsonValue(value) {
|
||||
}
|
||||
|
||||
// utils/github.ts
|
||||
var core2 = __toESM(require_core(), 1);
|
||||
import { createSign } from "node:crypto";
|
||||
var core2 = __toESM(require_core(), 1);
|
||||
|
||||
// utils/apiUrl.ts
|
||||
function isLocalUrl(url) {
|
||||
@@ -25914,6 +25930,17 @@ function parseRepoContext() {
|
||||
}
|
||||
return { owner, name };
|
||||
}
|
||||
function emptyResourceUsage() {
|
||||
return {
|
||||
requestCount: 0,
|
||||
rateLimitRemaining: null,
|
||||
rateLimitResetMs: null
|
||||
};
|
||||
}
|
||||
var usageByResource = {
|
||||
core: emptyResourceUsage(),
|
||||
graphql: emptyResourceUsage()
|
||||
};
|
||||
|
||||
// utils/token.ts
|
||||
async function revokeGitHubInstallationToken(token) {
|
||||
|
||||
+3
-1
@@ -20,6 +20,8 @@ export {
|
||||
Effort,
|
||||
ghPullfrogMcpName,
|
||||
} from "../external.ts";
|
||||
export type { Mode } from "../modes.ts";
|
||||
export { modes } from "../modes.ts";
|
||||
export type {
|
||||
AgentInfo,
|
||||
BuildPullfrogFooterParams,
|
||||
@@ -30,7 +32,7 @@ export {
|
||||
PULLFROG_DIVIDER,
|
||||
stripExistingFooter,
|
||||
} from "../utils/buildPullfrogFooter.ts";
|
||||
|
||||
export type { ResourceUsage, UsageSummary } from "../utils/github.ts";
|
||||
export {
|
||||
isValidTimeString,
|
||||
parseTimeString,
|
||||
|
||||
@@ -12,8 +12,9 @@ import { validateAgentApiKey } from "./utils/apiKeys.ts";
|
||||
import { resolveBody } from "./utils/body.ts";
|
||||
import { formatUsageSummary, log, writeSummary } from "./utils/cli.ts";
|
||||
import { reportErrorToComment } from "./utils/errorReport.ts";
|
||||
import { onExitSignal } from "./utils/exitHandler.ts";
|
||||
import { resolveGit } from "./utils/gitAuth.ts";
|
||||
import { createOctokit } from "./utils/github.ts";
|
||||
import { createOctokit, writeGitHubUsageSummaryToFile } from "./utils/github.ts";
|
||||
import { resolveInstructions } from "./utils/instructions.ts";
|
||||
import { executeLifecycleHook } from "./utils/lifecycle.ts";
|
||||
import { normalizeEnv } from "./utils/normalizeEnv.ts";
|
||||
@@ -48,6 +49,12 @@ export async function main(): Promise<MainResult> {
|
||||
// normalize env var names to uppercase (handles case-insensitive workflow files)
|
||||
normalizeEnv();
|
||||
|
||||
// write usage summary on SIGINT/SIGTERM so the worker can read it after sandbox.exec
|
||||
const usageSummaryPath = process.env.PULLFROG_USAGE_SUMMARY_PATH;
|
||||
if (usageSummaryPath) {
|
||||
onExitSignal(() => writeGitHubUsageSummaryToFile(usageSummaryPath));
|
||||
}
|
||||
|
||||
const timer = new Timer();
|
||||
let activityTimeout: ActivityTimeout | null = null;
|
||||
|
||||
@@ -155,6 +162,7 @@ export async function main(): Promise<MainResult> {
|
||||
agent,
|
||||
modes,
|
||||
postCheckoutScript: runContext.repoSettings.postCheckoutScript,
|
||||
prApproveEnabled: runContext.repoSettings.prApproveEnabled,
|
||||
toolState,
|
||||
runId: runInfo.runId,
|
||||
jobId: runInfo.jobId,
|
||||
@@ -235,8 +243,14 @@ export async function main(): Promise<MainResult> {
|
||||
log.info(`::pullfrog-output::${Buffer.from(toolState.output).toString("base64")}`);
|
||||
}
|
||||
|
||||
const mainResult = await handleAgentResult({
|
||||
result,
|
||||
toolState,
|
||||
silent: payload.event.silent ?? false,
|
||||
});
|
||||
|
||||
return {
|
||||
...handleAgentResult(result),
|
||||
...mainResult,
|
||||
result: toolState.output,
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -260,5 +274,8 @@ export async function main(): Promise<MainResult> {
|
||||
};
|
||||
} finally {
|
||||
activityTimeout?.stop();
|
||||
if (usageSummaryPath) {
|
||||
await writeGitHubUsageSummaryToFile(usageSummaryPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,40 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`formatReviewThreads > formats thread blocks with TOC and correct line numbers > content 1`] = `
|
||||
"# Review Threads (1) for PR #49 - Review 3485940013 by cursor
|
||||
exports[`getFormattedReviewThreads > formats body-only review > content 1`] = `
|
||||
"# Review Threads (0) for PR #64 - Review 3531000326 by pullfrog[bot]
|
||||
|
||||
## Review Body
|
||||
|
||||
This PR looks great. The retry logic is well-implemented and the tests are comprehensive.
|
||||
|
||||
---
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`getFormattedReviewThreads > formats body-only review > toc 1`] = `""`;
|
||||
|
||||
exports[`getFormattedReviewThreads > formats thread blocks with TOC and correct line numbers > content 1`] = `
|
||||
"# Review Threads (1) for PR #49 - Review 3485940013 by cursor[bot]
|
||||
|
||||
## TOC
|
||||
|
||||
- .github/workflows/test.yml:7 → lines 9-36
|
||||
- .github/workflows/test.yml:7 → lines 25-52
|
||||
|
||||
## Review Body
|
||||
|
||||
### This is the final PR Bugbot will review for you during this billing cycle
|
||||
|
||||
Your free Bugbot reviews will reset on November 30
|
||||
|
||||
<details>
|
||||
<summary>Details</summary>
|
||||
|
||||
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
|
||||
|
||||
To receive Bugbot reviews on all of your PRs, visit the [Cursor dashboard](https://www.cursor.com/dashboard?tab=bugbot) to activate Pro and start your 14-day free trial.
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
@@ -39,4 +68,4 @@ LOCATIONS END -->
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`formatReviewThreads > formats thread blocks with TOC and correct line numbers > toc 1`] = `"- .github/workflows/test.yml:7 → lines 9-36"`;
|
||||
exports[`getFormattedReviewThreads > formats thread blocks with TOC and correct line numbers > toc 1`] = `"- .github/workflows/test.yml:7 → lines 25-52"`;
|
||||
|
||||
+4
-2
@@ -25,7 +25,9 @@ async function buildCommentFooter({
|
||||
customParts,
|
||||
}: BuildCommentFooterParams): Promise<string> {
|
||||
const repoContext = parseRepoContext();
|
||||
const runId = process.env.GITHUB_RUN_ID;
|
||||
const runId = process.env.GITHUB_RUN_ID
|
||||
? Number.parseInt(process.env.GITHUB_RUN_ID, 10)
|
||||
: undefined;
|
||||
|
||||
let jobId: string | undefined;
|
||||
if (runId && octokit) {
|
||||
@@ -34,7 +36,7 @@ async function buildCommentFooter({
|
||||
const { data: jobs } = await octokit.rest.actions.listJobsForWorkflowRun({
|
||||
owner: repoContext.owner,
|
||||
repo: repoContext.name,
|
||||
run_id: parseInt(runId, 10),
|
||||
run_id: runId,
|
||||
});
|
||||
// use the first job's ID available
|
||||
jobId = jobs.jobs[0]?.id.toString();
|
||||
|
||||
+25
-9
@@ -138,10 +138,26 @@ export function PushBranchTool(ctx: ToolContext) {
|
||||
if (force) {
|
||||
log.warning(`force pushing - this will overwrite remote history`);
|
||||
}
|
||||
$git("push", pushArgs, {
|
||||
token: ctx.gitToken,
|
||||
restricted: ctx.payload.shell !== "enabled",
|
||||
});
|
||||
|
||||
try {
|
||||
$git("push", pushArgs, {
|
||||
token: ctx.gitToken,
|
||||
restricted: ctx.payload.shell !== "enabled",
|
||||
});
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
if (msg.includes("fetch first") || msg.includes("non-fast-forward")) {
|
||||
throw new Error(
|
||||
`push rejected: the remote branch '${pushDest.remoteBranch}' has new commits you don't have locally.\n\n` +
|
||||
`to resolve this:\n` +
|
||||
`1. use git_fetch to fetch the remote branch: git_fetch({ ref: "${pushDest.remoteBranch}" })\n` +
|
||||
`2. use the git tool to rebase your changes: git({ subcommand: "rebase", args: ["origin/${pushDest.remoteBranch}"] })\n` +
|
||||
`3. resolve any merge conflicts if needed\n` +
|
||||
`4. retry push_branch`
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -157,10 +173,10 @@ export function PushBranchTool(ctx: ToolContext) {
|
||||
|
||||
// commands that require authentication - redirect to dedicated tools
|
||||
const AUTH_REQUIRED_REDIRECT: Record<string, string> = {
|
||||
push: "Use push_branch tool instead.",
|
||||
fetch: "Use git_fetch tool instead.",
|
||||
pull: "Use git_fetch + git merge instead.",
|
||||
clone: "Repository already cloned. Use checkout_pr for PR branches.",
|
||||
push: "use the push_branch tool instead — it handles authentication and permission checks.",
|
||||
fetch: "use the git_fetch tool instead — it handles authentication.",
|
||||
pull: "use git_fetch to fetch the remote ref, then use this git tool with subcommand 'merge' or 'rebase' locally.",
|
||||
clone: "the repository is already cloned. use checkout_pr for PR branches.",
|
||||
};
|
||||
|
||||
// SECURITY: subcommands blocked when shell is disabled.
|
||||
@@ -219,7 +235,7 @@ export function GitTool(ctx: ToolContext) {
|
||||
|
||||
const redirect = AUTH_REQUIRED_REDIRECT[subcommand];
|
||||
if (redirect) {
|
||||
throw new Error(`git ${subcommand} requires authentication. ${redirect}`);
|
||||
throw new Error(`git ${subcommand} is not available through this tool — ${redirect}`);
|
||||
}
|
||||
|
||||
// SECURITY: block dangerous subcommands when shell is disabled.
|
||||
|
||||
@@ -9,6 +9,9 @@ export const PullRequest = type({
|
||||
title: type.string.describe("the title of the pull request"),
|
||||
body: type.string.describe("the body content of the pull request"),
|
||||
base: type.string.describe("the base branch to merge into (e.g., 'main')"),
|
||||
"draft?": type.boolean.describe(
|
||||
"if true, create the pull request as a draft. use when the user explicitly asks for a draft PR."
|
||||
),
|
||||
});
|
||||
|
||||
function buildPrBodyWithFooter(ctx: ToolContext, body: string): string {
|
||||
@@ -71,10 +74,11 @@ export function CreatePullRequestTool(ctx: ToolContext) {
|
||||
body: bodyWithFooter,
|
||||
head: currentBranch,
|
||||
base: params.base,
|
||||
draft: params.draft ?? false,
|
||||
});
|
||||
|
||||
// best-effort: request review from the user who triggered the workflow
|
||||
const reviewer = ctx.payload.triggeringUser;
|
||||
const reviewer = ctx.payload.triggerer;
|
||||
if (reviewer) {
|
||||
try {
|
||||
log.debug(`requesting review from ${reviewer} on PR #${result.data.number}`);
|
||||
|
||||
+78
-15
@@ -1,5 +1,6 @@
|
||||
import type { RestEndpointMethodTypes } from "@octokit/rest";
|
||||
import { type } from "arktype";
|
||||
import { apiFetch } from "../utils/apiFetch.ts";
|
||||
import { getApiUrl } from "../utils/apiUrl.ts";
|
||||
import { buildPullfrogFooter } from "../utils/buildPullfrogFooter.ts";
|
||||
import { log } from "../utils/cli.ts";
|
||||
@@ -15,11 +16,18 @@ export const CreatePullRequestReview = type({
|
||||
"1-2 sentence high-level summary with urgency level, critical callouts, and feedback about code outside the diff. Specific feedback on diff lines goes in 'comments' array."
|
||||
)
|
||||
.optional(),
|
||||
approved: type.boolean
|
||||
.describe(
|
||||
"Set to true to submit as an approval. ONLY when the review contains no actionable feedback — neither inline comments nor actionable content in the body. Defaults to false (comment-only review). Rejections are not supported."
|
||||
)
|
||||
.optional(),
|
||||
commit_id: type.string
|
||||
.describe("Optional SHA of the commit being reviewed. Defaults to latest.")
|
||||
.optional(),
|
||||
comments: type({
|
||||
path: type.string.describe("The file path to comment on (relative to repo root)"),
|
||||
path: type.string.describe(
|
||||
"The file path to comment on (relative to repo root). Must be a file that appears in the PR diff."
|
||||
),
|
||||
line: type.number.describe(
|
||||
"End line of the comment range. For single-line comments, set equal to 'start_line'. Use NEW column from diff format."
|
||||
),
|
||||
@@ -57,18 +65,28 @@ export function CreatePullRequestReviewTool(ctx: ToolContext) {
|
||||
"Only use 'body' for a 1-2 sentence summary with urgency and critical callouts. " +
|
||||
"Use 'suggestion' to propose replacement code - MUST preserve exact indentation of original code. " +
|
||||
"Example replacing lines 42-44 (3 lines) with 5 lines: " +
|
||||
`{ path: 'src/api.ts', start_line: 42, line: 44, suggestion: ' const result = await fetch(url);\\n if (!result.ok) {\\n log.error(result.status);\\n throw new Error("request failed");\\n }' }`,
|
||||
`{ path: 'src/api.ts', start_line: 42, line: 44, suggestion: ' const result = await fetch(url);\\n if (!result.ok) {\\n log.error(result.status);\\n throw new Error("request failed");\\n }' }` +
|
||||
" CONSTRAINT: Inline comments can ONLY target files and lines that appear in the PR diff." +
|
||||
" Commenting on files or lines outside the diff will cause GitHub API errors." +
|
||||
" Put feedback about code outside the diff in 'body' instead.",
|
||||
parameters: CreatePullRequestReview,
|
||||
execute: execute(async ({ pull_number, body, commit_id, comments = [] }) => {
|
||||
execute: execute(async ({ pull_number, body, approved, commit_id, comments = [] }) => {
|
||||
// set issue context (PRs are issues)
|
||||
ctx.toolState.issueNumber = pull_number;
|
||||
|
||||
// enforce prApproveEnabled: downgrade APPROVE to COMMENT if disabled
|
||||
let event: "APPROVE" | "COMMENT" = approved ? "APPROVE" : "COMMENT";
|
||||
if (event === "APPROVE" && !ctx.prApproveEnabled) {
|
||||
log.info("prApproveEnabled is disabled — downgrading APPROVE to COMMENT");
|
||||
event = "COMMENT";
|
||||
}
|
||||
|
||||
// compose the request
|
||||
const params: RestEndpointMethodTypes["pulls"]["createReview"]["parameters"] = {
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.name,
|
||||
pull_number,
|
||||
event: "COMMENT",
|
||||
event,
|
||||
};
|
||||
if (body) params.body = body;
|
||||
if (commit_id) {
|
||||
@@ -105,30 +123,46 @@ export function CreatePullRequestReviewTool(ctx: ToolContext) {
|
||||
return reviewComment;
|
||||
});
|
||||
}
|
||||
|
||||
const result = await ctx.octokit.rest.pulls.createReview(params);
|
||||
log.debug(`createReview response: ${JSON.stringify(result.data)}`);
|
||||
if (!result.data.id) {
|
||||
throw new Error(`createReview returned invalid data: ${JSON.stringify(result.data)}`);
|
||||
}
|
||||
const reviewId = result.data.id;
|
||||
const reviewNodeId = result.data.node_id;
|
||||
|
||||
// report review node ID to server so the in-flight dedup check
|
||||
// in the synchronize webhook handler sees this run as "review submitted."
|
||||
// awaited (not fire-and-forget) to guarantee the signal lands before
|
||||
// any subsequent push's webhook checks for in-flight runs.
|
||||
await reportReviewNodeId(ctx, reviewNodeId);
|
||||
|
||||
// build quick links footer and update the review body
|
||||
// only include "Fix all" and "Fix 👍s" links if there are actual review comments
|
||||
const customParts: string[] = [];
|
||||
if (comments.length > 0) {
|
||||
const apiUrl = getApiUrl();
|
||||
const fixAllUrl = `${apiUrl}/trigger/${ctx.repo.owner}/${ctx.repo.name}/${pull_number}?action=fix&review_id=${reviewId}`;
|
||||
const fixApprovedUrl = `${apiUrl}/trigger/${ctx.repo.owner}/${ctx.repo.name}/${pull_number}?action=fix-approved&review_id=${reviewId}`;
|
||||
customParts.push(`[Fix all ➔](${fixAllUrl})`, `[Fix 👍s ➔](${fixApprovedUrl})`);
|
||||
if (!approved) {
|
||||
if (comments.length > 0) {
|
||||
const apiUrl = getApiUrl();
|
||||
const fixAllUrl = `${apiUrl}/trigger/${ctx.repo.owner}/${ctx.repo.name}/${pull_number}?action=fix&review_id=${reviewId}`;
|
||||
const fixApprovedUrl = `${apiUrl}/trigger/${ctx.repo.owner}/${ctx.repo.name}/${pull_number}?action=fix-approved&review_id=${reviewId}`;
|
||||
customParts.push(`[Fix all ➔](${fixAllUrl})`, `[Fix 👍s ➔](${fixApprovedUrl})`);
|
||||
} else if (body) {
|
||||
const apiUrl = getApiUrl();
|
||||
const fixUrl = `${apiUrl}/trigger/${ctx.repo.owner}/${ctx.repo.name}/${pull_number}?action=fix&review_id=${reviewId}`;
|
||||
customParts.push(`[Fix it ➔](${fixUrl})`);
|
||||
}
|
||||
}
|
||||
|
||||
const footer = buildPullfrogFooter({
|
||||
workflowRun: {
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.name,
|
||||
runId: ctx.runId,
|
||||
jobId: ctx.jobId,
|
||||
},
|
||||
workflowRun: ctx.runId
|
||||
? {
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.name,
|
||||
runId: ctx.runId,
|
||||
jobId: ctx.jobId,
|
||||
}
|
||||
: undefined,
|
||||
customParts,
|
||||
});
|
||||
|
||||
@@ -157,6 +191,35 @@ export function CreatePullRequestReviewTool(ctx: ToolContext) {
|
||||
});
|
||||
}
|
||||
|
||||
async function reportReviewNodeId(ctx: ToolContext, reviewNodeId: string): Promise<void> {
|
||||
for (let remaining = 2; remaining >= 0; remaining--) {
|
||||
try {
|
||||
const response = await apiFetch({
|
||||
path: `/api/workflow-run/${ctx.runId}`,
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
authorization: `Bearer ${ctx.apiToken}`,
|
||||
"content-type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ reviewNodeId }),
|
||||
signal: AbortSignal.timeout(10_000),
|
||||
});
|
||||
if (response.ok) return;
|
||||
if (remaining > 0) {
|
||||
log.debug(`reportReviewNodeId got ${response.status}, retrying (${remaining} left)`);
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
}
|
||||
} catch (error) {
|
||||
if (remaining > 0) {
|
||||
log.debug(`reportReviewNodeId failed, retrying (${remaining} left): ${error}`);
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
} else {
|
||||
log.debug(`reportReviewNodeId exhausted retries: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// COMMENTED OUT: Three-step review flow (start_review, add_review_comment, submit_review)
|
||||
// This approach used GraphQL to add comments to a pending review one-by-one,
|
||||
|
||||
+22
-39
@@ -1,60 +1,43 @@
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { acquireNewToken } from "../utils/github.ts";
|
||||
import {
|
||||
buildThreadBlocks,
|
||||
formatReviewThreads,
|
||||
type ParsedHunk,
|
||||
parseFilePatches,
|
||||
REVIEW_THREADS_QUERY,
|
||||
type ReviewThread,
|
||||
type ReviewThreadsQueryResponse,
|
||||
} from "./reviewComments.ts";
|
||||
import { getReviewData } from "./reviewComments.ts";
|
||||
|
||||
async function getToken(): Promise<string> {
|
||||
// prefer explicit GH_TOKEN, fall back to acquiring one via GitHub App credentials
|
||||
if (process.env.GH_TOKEN) return process.env.GH_TOKEN;
|
||||
return await acquireNewToken();
|
||||
}
|
||||
|
||||
describe("formatReviewThreads", () => {
|
||||
describe("getFormattedReviewThreads", () => {
|
||||
it("formats thread blocks with TOC and correct line numbers", { timeout: 30000 }, async () => {
|
||||
const token = await getToken();
|
||||
const octokit = new Octokit({ auth: token });
|
||||
const pullNumber = 49;
|
||||
const reviewId = 3485940013;
|
||||
|
||||
// fetch review threads via GraphQL
|
||||
const response = await octokit.graphql<ReviewThreadsQueryResponse>(REVIEW_THREADS_QUERY, {
|
||||
const { formatted } = (await getReviewData({
|
||||
octokit,
|
||||
owner: "pullfrog",
|
||||
name: "scratch",
|
||||
prNumber: pullNumber,
|
||||
});
|
||||
pullNumber: 49,
|
||||
reviewId: 3485940013,
|
||||
}))!;
|
||||
|
||||
const allThreads = response.repository?.pullRequest?.reviewThreads?.nodes ?? [];
|
||||
const threadsForReview = allThreads.filter((thread): thread is ReviewThread => {
|
||||
if (!thread?.comments?.nodes) return false;
|
||||
return thread.comments.nodes.some((c) => c?.pullRequestReview?.databaseId === reviewId);
|
||||
});
|
||||
expect(formatted.toc).toMatchSnapshot("toc");
|
||||
expect(formatted.content).toMatchSnapshot("content");
|
||||
});
|
||||
|
||||
// fetch file patches
|
||||
const prFilesResponse = await octokit.rest.pulls.listFiles({
|
||||
it("formats body-only review", { timeout: 30000 }, async () => {
|
||||
const token = await getToken();
|
||||
const octokit = new Octokit({ auth: token });
|
||||
|
||||
const { formatted } = (await getReviewData({
|
||||
octokit,
|
||||
owner: "pullfrog",
|
||||
repo: "scratch",
|
||||
pull_number: pullNumber,
|
||||
});
|
||||
const filePatchMap = new Map<string, ParsedHunk[]>();
|
||||
for (const file of prFilesResponse.data) {
|
||||
if (file.patch) {
|
||||
filePatchMap.set(file.filename, parseFilePatches(file.patch));
|
||||
}
|
||||
}
|
||||
name: "scratch",
|
||||
pullNumber: 64,
|
||||
reviewId: 3531000326,
|
||||
}))!;
|
||||
|
||||
// build and format
|
||||
const { threadBlocks, reviewer } = buildThreadBlocks(threadsForReview, filePatchMap, reviewId);
|
||||
const result = formatReviewThreads(threadBlocks, { pullNumber, reviewId, reviewer });
|
||||
|
||||
expect(result.toc).toMatchSnapshot("toc");
|
||||
expect(result.content).toMatchSnapshot("content");
|
||||
expect(formatted.toc).toMatchSnapshot("toc");
|
||||
expect(formatted.content).toMatchSnapshot("content");
|
||||
});
|
||||
});
|
||||
|
||||
+129
-71
@@ -1,6 +1,8 @@
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import type { Octokit } from "@octokit/rest";
|
||||
import { type } from "arktype";
|
||||
import { stripExistingFooter } from "../utils/buildPullfrogFooter.ts";
|
||||
import { log } from "../utils/log.ts";
|
||||
import type { ToolContext } from "./server.ts";
|
||||
import { execute, tool } from "./shared.ts";
|
||||
@@ -94,6 +96,16 @@ export type ReviewThreadsQueryResponse = {
|
||||
} | null;
|
||||
};
|
||||
|
||||
export function countLines(str: string): number {
|
||||
let count = 1;
|
||||
let index = -1;
|
||||
// biome-ignore lint/suspicious/noAssignInExpressions: assignment in while condition is intentional for indexOf loop pattern
|
||||
while ((index = str.indexOf("\n", index + 1)) !== -1) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// extract exactly the commented line range from diffHunk, plus context
|
||||
const CONTEXT_PADDING = 3;
|
||||
|
||||
@@ -279,19 +291,14 @@ function extractFromFilePatches(
|
||||
export const GetReviewComments = type({
|
||||
pull_number: type.number.describe("The pull request number"),
|
||||
review_id: type.number.describe("The review ID to get comments for"),
|
||||
approved_by: type.string
|
||||
.describe(
|
||||
"Optional GitHub username - only return threads where this user gave a 👍 to at least one comment"
|
||||
)
|
||||
.optional(),
|
||||
});
|
||||
|
||||
function hasThumbsUpFrom(comment: ReviewThreadComment, username: string): boolean {
|
||||
if (!comment.reactionGroups) return false;
|
||||
const thumbsUp = comment.reactionGroups.find((g) => g.content === "THUMBS_UP");
|
||||
if (!thumbsUp?.reactors?.nodes) return false;
|
||||
const usernameNeedle = username.toLowerCase();
|
||||
return thumbsUp.reactors.nodes.some((r) => r?.login?.toLowerCase() === usernameNeedle);
|
||||
const needle = username.toLowerCase();
|
||||
return thumbsUp.reactors.nodes.some((r) => r?.login?.toLowerCase() === needle);
|
||||
}
|
||||
|
||||
function threadHasThumbsUpFrom(thread: ReviewThread, username: string): boolean {
|
||||
@@ -305,19 +312,26 @@ function threadHasThumbsUpFrom(thread: ReviewThread, username: string): boolean
|
||||
*/
|
||||
export function formatReviewThreads(
|
||||
threadBlocks: Array<{ path: string; lineRange: string; content: string[] }>,
|
||||
header: { pullNumber: number; reviewId: number; reviewer: string }
|
||||
header: { pullNumber: number; reviewId: number; reviewer: string; reviewBody?: string }
|
||||
) {
|
||||
// header section takes: title (1) + blank (1) + "## TOC" (1) + blank (1) + N TOC entries + blank (1) + "---" (1) + blank (1)
|
||||
const tocHeaderLines = 4;
|
||||
const tocFooterLines = 3;
|
||||
let currentLine = tocHeaderLines + threadBlocks.length + tocFooterLines + 1;
|
||||
|
||||
// account for review body section if present
|
||||
const reviewBodyLines: string[] = [];
|
||||
if (header.reviewBody) {
|
||||
reviewBodyLines.push("## Review Body", "", header.reviewBody, "");
|
||||
currentLine += reviewBodyLines.reduce((sum, line) => sum + countLines(line), 0);
|
||||
}
|
||||
|
||||
const tocEntries: string[] = [];
|
||||
const threadLines: string[] = [];
|
||||
|
||||
for (const block of threadBlocks) {
|
||||
const startLine = currentLine;
|
||||
const actualLineCount = block.content.reduce((sum, line) => sum + line.split("\n").length, 0);
|
||||
const actualLineCount = block.content.reduce((sum, line) => sum + countLines(line), 0);
|
||||
const endLine = currentLine + actualLineCount - 1;
|
||||
tocEntries.push(`- ${block.path}:${block.lineRange} → lines ${startLine}-${endLine}`);
|
||||
threadLines.push(...block.content);
|
||||
@@ -329,10 +343,13 @@ export function formatReviewThreads(
|
||||
`# Review Threads (${threadBlocks.length}) for PR #${header.pullNumber} - Review ${header.reviewId} by ${header.reviewer}`
|
||||
);
|
||||
lines.push("");
|
||||
lines.push("## TOC");
|
||||
lines.push("");
|
||||
lines.push(...tocEntries);
|
||||
lines.push("");
|
||||
if (threadBlocks.length > 0) {
|
||||
lines.push("## TOC");
|
||||
lines.push("");
|
||||
lines.push(...tocEntries);
|
||||
lines.push("");
|
||||
}
|
||||
lines.push(...reviewBodyLines);
|
||||
lines.push("---");
|
||||
lines.push("");
|
||||
lines.push(...threadLines);
|
||||
@@ -352,12 +369,6 @@ export function buildThreadBlocks(
|
||||
filePatchMap: Map<string, ParsedHunk[]>,
|
||||
reviewId: number
|
||||
) {
|
||||
// get reviewer from first matching comment
|
||||
const firstMatchingComment = threads[0]?.comments?.nodes?.find(
|
||||
(c) => c?.pullRequestReview?.databaseId === reviewId
|
||||
);
|
||||
const reviewer = firstMatchingComment?.pullRequestReview?.author?.login ?? "unknown";
|
||||
|
||||
// sort threads by file path, then by line number
|
||||
threads.sort((a, b) => {
|
||||
const pathCmp = a.path.localeCompare(b.path);
|
||||
@@ -439,7 +450,89 @@ export function buildThreadBlocks(
|
||||
threadBlocks.push({ path: thread.path, lineRange, content: block });
|
||||
}
|
||||
|
||||
return { threadBlocks, reviewer };
|
||||
return threadBlocks;
|
||||
}
|
||||
|
||||
async function getReviewThreads(input: GetReviewDataInput) {
|
||||
const response = await input.octokit.graphql<ReviewThreadsQueryResponse>(REVIEW_THREADS_QUERY, {
|
||||
owner: input.owner,
|
||||
name: input.name,
|
||||
prNumber: input.pullNumber,
|
||||
});
|
||||
|
||||
const allThreads = response.repository?.pullRequest?.reviewThreads?.nodes ?? [];
|
||||
|
||||
const threadsForReview = allThreads.filter((thread): thread is ReviewThread => {
|
||||
if (!thread?.comments?.nodes) return false;
|
||||
return thread.comments.nodes.some((c) => c?.pullRequestReview?.databaseId === input.reviewId);
|
||||
});
|
||||
|
||||
if (!input.approvedBy) {
|
||||
return threadsForReview;
|
||||
}
|
||||
|
||||
const username = input.approvedBy;
|
||||
return threadsForReview.filter((thread) => threadHasThumbsUpFrom(thread, username));
|
||||
}
|
||||
|
||||
interface GetReviewDataInput {
|
||||
octokit: Octokit;
|
||||
owner: string;
|
||||
name: string;
|
||||
pullNumber: number;
|
||||
reviewId: number;
|
||||
approvedBy?: string | undefined;
|
||||
}
|
||||
|
||||
export async function getReviewData(input: GetReviewDataInput): Promise<
|
||||
| {
|
||||
threadBlocks: Array<{ path: string; lineRange: string; content: string[] }>;
|
||||
reviewer: string;
|
||||
formatted: { toc: string; content: string };
|
||||
}
|
||||
| undefined
|
||||
> {
|
||||
const [review, threads] = await Promise.all([
|
||||
input.octokit.rest.pulls.getReview({
|
||||
owner: input.owner,
|
||||
repo: input.name,
|
||||
pull_number: input.pullNumber,
|
||||
review_id: input.reviewId,
|
||||
}),
|
||||
getReviewThreads(input),
|
||||
]);
|
||||
|
||||
const rawReviewBody = review.data.body;
|
||||
const reviewBody = rawReviewBody ? stripExistingFooter(rawReviewBody) : "";
|
||||
const reviewer = review.data.user?.login ?? "unknown";
|
||||
|
||||
if (threads.length === 0 && !reviewBody) return undefined;
|
||||
|
||||
let threadBlocks: Array<{ path: string; lineRange: string; content: string[] }> = [];
|
||||
|
||||
if (threads.length > 0) {
|
||||
const prFilesResponse = await input.octokit.rest.pulls.listFiles({
|
||||
owner: input.owner,
|
||||
repo: input.name,
|
||||
pull_number: input.pullNumber,
|
||||
});
|
||||
const filePatchMap = new Map<string, ParsedHunk[]>();
|
||||
for (const file of prFilesResponse.data) {
|
||||
if (file.patch) {
|
||||
filePatchMap.set(file.filename, parseFilePatches(file.patch));
|
||||
}
|
||||
}
|
||||
threadBlocks = buildThreadBlocks(threads, filePatchMap, input.reviewId);
|
||||
}
|
||||
|
||||
const formatted = formatReviewThreads(threadBlocks, {
|
||||
pullNumber: input.pullNumber,
|
||||
reviewId: input.reviewId,
|
||||
reviewer,
|
||||
reviewBody,
|
||||
});
|
||||
|
||||
return { threadBlocks, reviewer, formatted };
|
||||
}
|
||||
|
||||
export function GetReviewCommentsTool(ctx: ToolContext) {
|
||||
@@ -447,35 +540,26 @@ export function GetReviewCommentsTool(ctx: ToolContext) {
|
||||
name: "get_review_comments",
|
||||
description:
|
||||
"Get review comments for a pull request review with full thread context. " +
|
||||
"When approved_by is provided, only returns threads where that user gave a 👍 to at least one comment. " +
|
||||
"Automatically filters to approved comments when applicable. " +
|
||||
"Returns a TOC and commentsPath pointing to a markdown file with full comment details.",
|
||||
parameters: GetReviewComments,
|
||||
execute: execute(async (params) => {
|
||||
// fetch all review threads for the PR via GraphQL
|
||||
const response = await ctx.octokit.graphql<ReviewThreadsQueryResponse>(REVIEW_THREADS_QUERY, {
|
||||
// auto-filter to approved comments when the event has approved_only set
|
||||
const approvedBy =
|
||||
ctx.payload.event.trigger === "fix_review" && ctx.payload.event.approved_only
|
||||
? ctx.payload.triggerer
|
||||
: undefined;
|
||||
|
||||
const result = await getReviewData({
|
||||
octokit: ctx.octokit,
|
||||
owner: ctx.repo.owner,
|
||||
name: ctx.repo.name,
|
||||
prNumber: params.pull_number,
|
||||
pullNumber: params.pull_number,
|
||||
reviewId: params.review_id,
|
||||
approvedBy,
|
||||
});
|
||||
|
||||
const allThreads = response.repository?.pullRequest?.reviewThreads?.nodes ?? [];
|
||||
|
||||
// filter to threads where at least one comment belongs to the target review
|
||||
let threadsForReview = allThreads.filter((thread): thread is ReviewThread => {
|
||||
if (!thread?.comments?.nodes) return false;
|
||||
return thread.comments.nodes.some(
|
||||
(c) => c?.pullRequestReview?.databaseId === params.review_id
|
||||
);
|
||||
});
|
||||
|
||||
// filter by approved_by if specified
|
||||
if (params.approved_by) {
|
||||
threadsForReview = threadsForReview.filter((thread) =>
|
||||
threadHasThumbsUpFrom(thread, params.approved_by as string)
|
||||
);
|
||||
}
|
||||
|
||||
if (threadsForReview.length === 0) {
|
||||
if (!result) {
|
||||
return {
|
||||
review_id: params.review_id,
|
||||
pull_number: params.pull_number,
|
||||
@@ -483,40 +567,14 @@ export function GetReviewCommentsTool(ctx: ToolContext) {
|
||||
threadCount: 0,
|
||||
commentsPath: null,
|
||||
toc: null,
|
||||
instructions: params.approved_by
|
||||
? `no threads with 👍 from ${params.approved_by}`
|
||||
instructions: approvedBy
|
||||
? `no threads with 👍 from ${approvedBy}`
|
||||
: "no threads found for this review",
|
||||
};
|
||||
}
|
||||
|
||||
// fetch full file patches for better multi-hunk context
|
||||
const prFilesResponse = await ctx.octokit.rest.pulls.listFiles({
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.name,
|
||||
pull_number: params.pull_number,
|
||||
});
|
||||
const filePatchMap = new Map<string, ParsedHunk[]>();
|
||||
for (const file of prFilesResponse.data) {
|
||||
if (file.patch) {
|
||||
filePatchMap.set(file.filename, parseFilePatches(file.patch));
|
||||
}
|
||||
}
|
||||
const { threadBlocks, reviewer, formatted } = result;
|
||||
|
||||
// build thread blocks
|
||||
const { threadBlocks, reviewer } = buildThreadBlocks(
|
||||
threadsForReview,
|
||||
filePatchMap,
|
||||
params.review_id
|
||||
);
|
||||
|
||||
// format thread blocks into markdown with TOC
|
||||
const formatted = formatReviewThreads(threadBlocks, {
|
||||
pullNumber: params.pull_number,
|
||||
reviewId: params.review_id,
|
||||
reviewer,
|
||||
});
|
||||
|
||||
// write to temp file
|
||||
const tempDir = process.env.PULLFROG_TEMP_DIR;
|
||||
if (!tempDir) {
|
||||
throw new Error("PULLFROG_TEMP_DIR not set");
|
||||
|
||||
+32
-3
@@ -6,7 +6,7 @@ import { execute, tool } from "./shared.ts";
|
||||
|
||||
export const SelectModeParams = type({
|
||||
mode: type.string.describe(
|
||||
"the name of the mode to select (e.g., 'Build', 'Plan', 'Review', 'Fix', 'AddressReviews', 'Task')"
|
||||
"the name of the mode to select (e.g., 'Build', 'Plan', 'Review', 'IncrementalReview', 'Fix', 'AddressReviews', 'Task')"
|
||||
),
|
||||
});
|
||||
|
||||
@@ -89,9 +89,38 @@ Each task in the \`tasks\` array should include:
|
||||
|
||||
After all tasks complete, consolidate into a **single** review:
|
||||
- merge the \`comments\` arrays from all subagent outputs
|
||||
- submit one \`${ghPullfrogMcpName}/create_pull_request_review\` with the merged comments and a unified summary body
|
||||
- if subagents found actionable issues: submit one \`${ghPullfrogMcpName}/create_pull_request_review\` with \`approved: false\`, the merged comments, and a unified summary body
|
||||
- if no subagent found actionable issues: submit with \`approved: true\` and a brief positive summary (no inline comments)
|
||||
- call \`${ghPullfrogMcpName}/report_progress\` with the summary
|
||||
|
||||
Use max effort for thorough reviews.`,
|
||||
|
||||
IncrementalReview: `### Checklist
|
||||
|
||||
1. Checkout the PR via \`${ghPullfrogMcpName}/checkout_pr\` — this returns PR metadata and a \`diffPath\`. Read the diff to identify the major areas of change.
|
||||
2. Generate the incremental diff using the \`before_sha\` from EVENT DATA: \`git diff <before_sha>...HEAD\`. This isolates only the new commits. If the command fails (e.g., force-push rewrote history), fall back to reviewing the full PR diff.
|
||||
3. Fetch previous reviews via \`${ghPullfrogMcpName}/list_pull_request_reviews\`. For the most recent Pullfrog review, call \`${ghPullfrogMcpName}/get_review_comments\` with the review ID to retrieve specific prior line-level feedback. Include the prior review summary and comment details when crafting subagent tasks.
|
||||
4. Delegate multiple subagents in a single \`${ghPullfrogMcpName}/delegate\` call, each focused on a specific area of the new changes. Provide both the full diff path and the incremental diff.
|
||||
5. After all subagents return, consolidate their findings into a single review.
|
||||
|
||||
### Crafting each task
|
||||
|
||||
Each task in the \`tasks\` array should include:
|
||||
- the full diff file path AND the incremental diff (so the subagent can see both new changes and full context)
|
||||
- what specific area/aspect to focus on
|
||||
- instruct it to prioritize reviewing code in the incremental diff while using the full diff for context and to catch any changes not covered by the incremental diff
|
||||
- include the prior review comments (from step 3) so the subagent knows what feedback was already given — instruct it to avoid repeating prior issues and to note whether prior feedback was addressed by the new commits
|
||||
- instruct it to actively hunt for problems: trace data flow, check boundaries, explore failure modes, verify assumptions, consider lifecycle, spot performance issues
|
||||
- draft inline comments with NEW line numbers from the full PR diff — every comment must be actionable (2-3 sentences max)
|
||||
- call \`${ghPullfrogMcpName}/set_output\` with a JSON object: \`{ "summary": "...", "comments": [{ "path": "file.ts", "line": 42, "body": "..." }, ...] }\`
|
||||
|
||||
### Post-delegation
|
||||
|
||||
After all tasks complete, consolidate into a **single** review:
|
||||
- merge the \`comments\` arrays from all subagent outputs
|
||||
- if subagents found actionable issues: submit one \`${ghPullfrogMcpName}/create_pull_request_review\` with \`approved: false\`, the merged comments, and a unified summary body
|
||||
- if no subagent found actionable issues: submit with \`approved: true\` and a brief positive summary (no inline comments)
|
||||
- call \`${ghPullfrogMcpName}/report_progress\` with the summary
|
||||
- if no subagent found actionable issues, skip the review — just call \`report_progress\` noting the PR was reviewed
|
||||
|
||||
Use max effort for thorough reviews.`,
|
||||
|
||||
|
||||
+2
-1
@@ -99,8 +99,9 @@ export interface ToolContext {
|
||||
agent: Agent;
|
||||
modes: Mode[];
|
||||
postCheckoutScript: string | null;
|
||||
prApproveEnabled: boolean;
|
||||
toolState: ToolState;
|
||||
runId: string;
|
||||
runId: number | undefined;
|
||||
jobId: string | undefined;
|
||||
// set after MCP server starts — used by delegate tool to pass URL to subagents
|
||||
mcpServerUrl: string;
|
||||
|
||||
+20
-1
@@ -160,6 +160,14 @@ function getTempDir(): string {
|
||||
return tempDir;
|
||||
}
|
||||
|
||||
/** detect git as a command invocation (not as part of another word like .gitignore) */
|
||||
function isGitCommand(command: string): boolean {
|
||||
const trimmed = command.trim();
|
||||
if (trimmed === "git" || trimmed.startsWith("git ")) return true;
|
||||
if (trimmed.startsWith("sudo git")) return true;
|
||||
return /[;&|]\s*(?:sudo\s+)?git(?:\s|$)/.test(trimmed);
|
||||
}
|
||||
|
||||
export function ShellTool(ctx: ToolContext) {
|
||||
return tool({
|
||||
name: "shell",
|
||||
@@ -169,9 +177,20 @@ Use this tool to:
|
||||
- Run shell commands (ls, cat, grep, find, etc.)
|
||||
- Execute build tools (npm, pnpm, cargo, make, etc.)
|
||||
- Run tests and linters
|
||||
- Perform git operations`,
|
||||
|
||||
Do NOT use this tool for git commands — use the dedicated git tools instead.`,
|
||||
parameters: ShellParams,
|
||||
execute: execute(async (params) => {
|
||||
if (isGitCommand(params.command)) {
|
||||
throw new Error(
|
||||
"git commands are not allowed in the shell tool. use the dedicated git tools instead:\n" +
|
||||
"- git: local operations (status, log, diff, add, commit, checkout, merge, rebase, etc.)\n" +
|
||||
"- push_branch: push to remote (handles authentication)\n" +
|
||||
"- git_fetch: fetch from remote (handles authentication)\n" +
|
||||
"- checkout_pr: check out PR branches"
|
||||
);
|
||||
}
|
||||
|
||||
const timeout = Math.min(params.timeout ?? 30000, 120000);
|
||||
const cwd = params.working_directory ?? process.cwd();
|
||||
const env = resolveEnv(ctx.payload.shell === "enabled" ? "inherit" : "restricted");
|
||||
|
||||
+36
-33
@@ -6,6 +6,7 @@ import type { Effort } from "../external.ts";
|
||||
import { ghPullfrogMcpName } from "../external.ts";
|
||||
import { markActivity } from "../utils/activity.ts";
|
||||
import type { ResolvedInstructions } from "../utils/instructions.ts";
|
||||
import { withLogPrefix } from "../utils/log.ts";
|
||||
import { type SubagentState, startSubagentMcpServer, type ToolContext } from "./server.ts";
|
||||
|
||||
type CreateSubagentParams = {
|
||||
@@ -132,41 +133,43 @@ type RunSubagentResult = {
|
||||
};
|
||||
|
||||
export async function runSubagent(params: RunSubagentParams): Promise<RunSubagentResult> {
|
||||
params.subagent.keepAliveInterval = setInterval(markActivity, 30_000);
|
||||
const mcpServer = await startSubagentMcpServer({
|
||||
ctx: params.ctx,
|
||||
subagentId: params.subagent.id,
|
||||
});
|
||||
// each subagent gets its own tmpdir so parallel agents don't clobber config files
|
||||
const subagentTmpdir = join(params.ctx.tmpdir, params.subagent.id);
|
||||
mkdirSync(subagentTmpdir, { recursive: true });
|
||||
try {
|
||||
const subagentPayload = { ...params.ctx.payload, effort: params.effort };
|
||||
const subagentInstructions = buildSubagentInstructions({
|
||||
return withLogPrefix(`[${params.subagent.label}]`, async () => {
|
||||
params.subagent.keepAliveInterval = setInterval(markActivity, 30_000);
|
||||
const mcpServer = await startSubagentMcpServer({
|
||||
ctx: params.ctx,
|
||||
label: params.subagent.label,
|
||||
instructions: params.instructions,
|
||||
subagentId: params.subagent.id,
|
||||
});
|
||||
const result = await params.ctx.agent.run({
|
||||
payload: subagentPayload,
|
||||
mcpServerUrl: mcpServer.url,
|
||||
tmpdir: subagentTmpdir,
|
||||
instructions: subagentInstructions,
|
||||
});
|
||||
params.subagent.usage = result.usage;
|
||||
writeFileSync(params.subagent.stdoutFilePath, result.output ?? "", "utf-8");
|
||||
completeSubagent({ ctx: params.ctx, subagent: params.subagent, success: result.success });
|
||||
return { success: result.success, error: result.error };
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : String(err);
|
||||
// each subagent gets its own tmpdir so parallel agents don't clobber config files
|
||||
const subagentTmpdir = join(params.ctx.tmpdir, params.subagent.id);
|
||||
mkdirSync(subagentTmpdir, { recursive: true });
|
||||
try {
|
||||
writeFileSync(params.subagent.stdoutFilePath, "", "utf-8");
|
||||
} catch {
|
||||
// best-effort
|
||||
const subagentPayload = { ...params.ctx.payload, effort: params.effort };
|
||||
const subagentInstructions = buildSubagentInstructions({
|
||||
ctx: params.ctx,
|
||||
label: params.subagent.label,
|
||||
instructions: params.instructions,
|
||||
});
|
||||
const result = await params.ctx.agent.run({
|
||||
payload: subagentPayload,
|
||||
mcpServerUrl: mcpServer.url,
|
||||
tmpdir: subagentTmpdir,
|
||||
instructions: subagentInstructions,
|
||||
});
|
||||
params.subagent.usage = result.usage;
|
||||
writeFileSync(params.subagent.stdoutFilePath, result.output ?? "", "utf-8");
|
||||
completeSubagent({ ctx: params.ctx, subagent: params.subagent, success: result.success });
|
||||
return { success: result.success, error: result.error };
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : String(err);
|
||||
try {
|
||||
writeFileSync(params.subagent.stdoutFilePath, "", "utf-8");
|
||||
} catch {
|
||||
// best-effort
|
||||
}
|
||||
completeSubagent({ ctx: params.ctx, subagent: params.subagent, success: false });
|
||||
return { success: false, error: errorMessage };
|
||||
} finally {
|
||||
await mcpServer.stop();
|
||||
}
|
||||
completeSubagent({ ctx: params.ctx, subagent: params.subagent, success: false });
|
||||
return { success: false, error: errorMessage };
|
||||
} finally {
|
||||
await mcpServer.stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export function computeModes(): Mode[] {
|
||||
1. **CHECKOUT** - Determine whether to checkout the existing PR branch or create a new one:
|
||||
- **PR event, modifying the existing PR**: Call \`${ghPullfrogMcpName}/checkout_pr\` with the PR number to checkout the PR branch.
|
||||
- **PR event, but user wants a NEW branch/PR**: Create a new branch with \`git checkout -b pullfrog/branch-name\` via the \`${ghPullfrogMcpName}/git\` tool.
|
||||
|
||||
|
||||
Branch names must be prefixed with "pullfrog/" and be specific enough to avoid collisions. Never commit directly to main/master/production.
|
||||
|
||||
2. **DEPENDENCIES** - ${dependencyInstallationStep}
|
||||
@@ -51,12 +51,13 @@ export function computeModes(): Mode[] {
|
||||
|
||||
9. **PR** - Determine whether to create a PR (if not already on a PR branch):
|
||||
- **Default behavior**: Create a PR using ${ghPullfrogMcpName}/create_pull_request with an informative title and body. If you are working in the context of an issue (check EVENT DATA for \`issue_number\` where \`is_pr\` is not true), include "Closes #<issue_number>" in the PR body to auto-close the issue when merged.
|
||||
- **Draft PR request**: If the user explicitly asks for a draft PR (e.g. "draft PR", "create as draft", "WIP"), create a PR with \`draft: true\`.
|
||||
- **Branch-only request**: If the user explicitly asks for a branch without a PR (e.g. "don't create a PR", "branch only", "just create a branch"), do NOT create a PR. Simply push the branch and report the branch link.
|
||||
|
||||
10. **FINAL REPORT** - Call report_progress one final time ONLY if you haven't already included all the important information (PR links, branch links, summary) in a previous report_progress call. If you already called report_progress with complete information including PR links after creating the PR, you do NOT need to call it again. Only make a final call if you need to add missing information. When making the final call, ensure it includes:
|
||||
- A summary of what was accomplished
|
||||
- Links to any artifacts created (PRs, branches, issues)
|
||||
- If you created a PR, ALWAYS include the PR link. e.g.:
|
||||
- If you created a PR, ALWAYS include the PR link. e.g.:
|
||||
\`\`\`md
|
||||
[View PR ➔](https://github.com/org/repo/pull/123)
|
||||
\`\`\`
|
||||
@@ -78,7 +79,7 @@ export function computeModes(): Mode[] {
|
||||
|
||||
2. **DEPENDENCIES** - ${dependencyInstallationStep}
|
||||
|
||||
3. **FETCH COMMENTS** - Fetch review comments using ${ghPullfrogMcpName}/get_review_comments with \`pull_number\` and \`review_id\` from EVENT DATA. This returns \`commentsPath\` - read that file for full comment details with diff context. If EVENT DATA contains a \`triggerer\` field (indicating who requested fixes), you can pass \`approved_by\` to filter to only comments they approved with 👍.
|
||||
3. **FETCH COMMENTS** - Fetch review comments using ${ghPullfrogMcpName}/get_review_comments with \`pull_number\` and \`review_id\` from EVENT DATA. This returns \`commentsPath\` - read that file for full comment details with diff context. When \`approved_only\` is set in EVENT DATA, only approved comments are returned automatically.
|
||||
|
||||
4. **UNDERSTAND** - Review the feedback provided. Understand each review comment and what changes are being requested.
|
||||
|
||||
@@ -100,7 +101,7 @@ Keep the progress comment extremely brief. The summary should be 1-2 sentences m
|
||||
name: "Review",
|
||||
description:
|
||||
"Review code, PRs, or implementations; provide feedback or suggestions; identify issues; or check code quality, style, and correctness",
|
||||
prompt: `Follow these steps to review the PR. Your job is to find problems—assume they exist until you've proven otherwise. Do not submit a clean review without thorough investigation. **If you have nothing interesting to say, do NOT submit a review at all—use \`report_progress\` instead.**
|
||||
prompt: `Follow these steps to review the PR. Your job is to find problems—assume they exist until you've proven otherwise. Do not submit a clean review without thorough investigation.
|
||||
|
||||
1. **CHECKOUT** - Call ${ghPullfrogMcpName}/checkout_pr with the PR number. This should give you all PR metadata you need, including a \`diffPath\`: a path to a temp file containing the PR diff.
|
||||
|
||||
@@ -118,13 +119,50 @@ Keep the progress comment extremely brief. The summary should be 1-2 sentences m
|
||||
- **Check PR consistency**: Does the PR title/description match the actual code changes? Flag significant discrepancies.
|
||||
- Do NOT stop at "this looks reasonable." Dig until you either find a problem or have concrete evidence there isn't one.
|
||||
|
||||
4. **DRAFT LINE-BY-LINE COMMENTS** - Every comment must be actionable: the author should need to change something in response. 2-3 sentences max. Use the NEW line number from the diff (second column: \`| OLD | NEW | TYPE | CODE\`). If no issues found, skip to step 5. NO COMPLIMENTS. NO NITPICKING ABOUT CHANGES UNRELATED TO THE MAIN CHANGE. Non-actionable comments (praise, style preferences, minor optimizatfixons, documentation nits) must not be drafted. If no comments survive and you have no significant concerns, **do not submit a review**. Use \`${ghPullfrogMcpName}/report_progress\` to note the PR was reviewed and no issues were found.
|
||||
4. **DRAFT LINE-BY-LINE COMMENTS** - Every comment must be actionable: the author should need to change something in response. 2-3 sentences max. Use the NEW line number from the diff (second column: \`| OLD | NEW | TYPE | CODE\`). If no issues found, skip to step 5. NO COMPLIMENTS. NO NITPICKING ABOUT CHANGES UNRELATED TO THE MAIN CHANGE. Non-actionable comments (praise, style preferences, minor optimizatfixons, documentation nits) must not be drafted.
|
||||
|
||||
5. **WRITE SUMMARY** - Draft a 1-3 sentence summary for the review body. Include urgency level and any concerns about code outside the diff.
|
||||
5. **WRITE SUMMARY** - Draft a 1-3 sentence summary for the review body. If issues were found, include urgency level and any concerns about code outside the diff. If no issues were found, write a brief approval summary (e.g., "Changes look good. No issues found.").
|
||||
|
||||
6. **SUBMIT** — Use ${ghPullfrogMcpName}/create_pull_request_review:
|
||||
6. **SUBMIT** — Always submit a review via ${ghPullfrogMcpName}/create_pull_request_review:
|
||||
- \`body\`: The summary from step 5
|
||||
- \`comments\`: The inline comments from step 4
|
||||
- \`approved\`: Set to \`true\` ONLY if the review contains no actionable feedback — neither inline comments nor actionable content in the body. An approval signals "no changes needed."
|
||||
|
||||
${permalinkTip}
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "IncrementalReview",
|
||||
description:
|
||||
"Re-review a PR after new commits are pushed; focus on new changes since the last review",
|
||||
prompt: `Follow these steps to incrementally re-review the PR after new commits were pushed. Focus on what changed since the last review.
|
||||
|
||||
1. **CHECKOUT** - Call ${ghPullfrogMcpName}/checkout_pr with the PR number. This gives you the full PR diff via \`diffPath\`.
|
||||
|
||||
2. **INCREMENTAL DIFF** - EVENT DATA contains \`before_sha\` (the HEAD before this push). Generate the incremental diff:
|
||||
\`git diff <before_sha>...HEAD\`
|
||||
This shows the changes introduced by this push. Cross-reference with previous reviews (step 3) to confirm coverage of all unreviewed changes — the full PR diff fills any gaps.
|
||||
**If the diff command fails** (e.g., force-push rewrote history), fall back to reviewing the full PR diff from step 1.
|
||||
|
||||
3. **FETCH PREVIOUS REVIEWS** - Use ${ghPullfrogMcpName}/list_pull_request_reviews to find previous Pullfrog reviews. For the most recent one, call ${ghPullfrogMcpName}/get_review_comments with the review ID to see specific line-level feedback. This lets you avoid repeating issues and assess whether prior feedback was addressed by the new commits.
|
||||
|
||||
4. **ANALYZE** - Read the incremental diff to understand the new changes. Use the full PR diff for surrounding context and to catch any changes not covered by the incremental diff.
|
||||
- **Understand the change**: What is new or modified since the last review?
|
||||
- **Evaluate the approach**: Are the new changes sound? Do they address prior feedback?
|
||||
|
||||
5. **INVESTIGATE** - Hunt for problems in the new code using the same techniques as a full review:
|
||||
- Trace data flow, check boundaries, explore failure modes, verify assumptions, consider lifecycle, spot performance issues.
|
||||
- Focus investigation on code that changed in the incremental diff, but trace its effects through the broader codebase.
|
||||
- Do NOT repeat feedback already given in previous reviews unless it was not addressed.
|
||||
|
||||
6. **DRAFT LINE-BY-LINE COMMENTS** - Every comment must be actionable. 2-3 sentences max. Use the NEW line number from the full PR diff. NO COMPLIMENTS. NO NITPICKING.
|
||||
|
||||
7. **WRITE SUMMARY** - Draft a 1-3 sentence summary for the review body. Focus on what changed since the last review and whether the new changes are sound. If issues were found, include urgency level. If no issues were found, write a brief approval summary.
|
||||
|
||||
8. **SUBMIT** — Use ${ghPullfrogMcpName}/create_pull_request_review:
|
||||
- \`body\`: The summary from step 7
|
||||
- \`comments\`: The inline comments from step 6
|
||||
- \`approved\`: Set to \`true\` ONLY if the review contains no actionable feedback — neither inline comments nor actionable content in the body. An approval signals "no changes needed."
|
||||
|
||||
${permalinkTip}
|
||||
`,
|
||||
@@ -162,23 +200,23 @@ ${permalinkTip}`,
|
||||
- \`failed_steps\`: which CI steps failed (e.g., "Step 6: Run tests")
|
||||
|
||||
2. **CHECKOUT AND ASSESS CAUSATION** - Use ${ghPullfrogMcpName}/checkout_pr to get the PR diff. BEFORE attempting any fix, you MUST determine if this PR caused the failure:
|
||||
|
||||
|
||||
**Ask yourself**: "Could the changes in this PR have caused this failure?"
|
||||
|
||||
|
||||
- Read the PR diff carefully - what files were modified?
|
||||
- What is failing? (test file, module, assertion)
|
||||
- Is there a PLAUSIBLE CONNECTION between the PR changes and the failure?
|
||||
|
||||
|
||||
**ABORT immediately if any of these are true:**
|
||||
- The failing test/file was NOT touched by this PR AND doesn't depend on changed code
|
||||
- The error is infrastructure-related (network timeout, runner OOM, service unavailable)
|
||||
- The error is a flaky test that passes/fails randomly
|
||||
- The error existed before this PR (pre-existing bug in main branch)
|
||||
- The error is in a dependency update not introduced by this PR
|
||||
|
||||
|
||||
**When aborting**, use ${ghPullfrogMcpName}/report_progress to explain:
|
||||
"This CI failure appears unrelated to the PR's changes. [Describe the failure]. [Explain why it's not caused by the PR]. No changes made."
|
||||
|
||||
|
||||
**Only proceed** if there's a clear, logical connection between the PR changes and the failure.
|
||||
|
||||
3. **UNDERSTAND HOW CI RUNS** - Read the workflow file to understand exactly what commands CI runs:
|
||||
@@ -233,6 +271,7 @@ Your job is to fix issues THIS PR introduced, not to fix all CI failures. If in
|
||||
- Commit your changes with \`${ghPullfrogMcpName}/git\` (\`git add .\` then \`git commit -m "message"\`), then push with \`${ghPullfrogMcpName}/push_branch\`. Do NOT use \`git push\` directly - it requires credentials that only the MCP tool provides.
|
||||
- Determine whether to create a PR:
|
||||
- **Default behavior**: Create a PR using ${ghPullfrogMcpName}/create_pull_request with an informative title and body. If you are working in the context of an issue (check EVENT DATA for \`issue_number\` where \`is_pr\` is not true), include "Closes #<issue_number>" in the PR body to auto-close the issue when merged.
|
||||
- **Draft PR request**: If the user explicitly asks for a draft PR (e.g. "draft PR", "create as draft", "WIP"), create a PR with \`draft: true\`.
|
||||
- **Branch-only request**: If the user explicitly asks for a branch without a PR (e.g. "don't create a PR", "branch only", "just create a branch"), do NOT create a PR. Simply push the branch and report the branch link.
|
||||
|
||||
5. **PROGRESS** - ${reportProgressInstruction}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pullfrog/pullfrog",
|
||||
"version": "0.0.173",
|
||||
"version": "0.0.177",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"index.js",
|
||||
|
||||
@@ -24695,7 +24695,7 @@ var require_lodash = __commonJS({
|
||||
var symbolProto = Symbol2 ? Symbol2.prototype : void 0;
|
||||
var symbolToString = symbolProto ? symbolProto.toString : void 0;
|
||||
function baseIsRegExp(value2) {
|
||||
return isObject(value2) && objectToString.call(value2) == regexpTag;
|
||||
return isObject2(value2) && objectToString.call(value2) == regexpTag;
|
||||
}
|
||||
function baseSlice(array, start, end) {
|
||||
var index = -1, length = array.length;
|
||||
@@ -24729,7 +24729,7 @@ var require_lodash = __commonJS({
|
||||
end = end === void 0 ? length : end;
|
||||
return !start && end >= length ? array : baseSlice(array, start, end);
|
||||
}
|
||||
function isObject(value2) {
|
||||
function isObject2(value2) {
|
||||
var type2 = typeof value2;
|
||||
return !!value2 && (type2 == "object" || type2 == "function");
|
||||
}
|
||||
@@ -24762,9 +24762,9 @@ var require_lodash = __commonJS({
|
||||
if (isSymbol(value2)) {
|
||||
return NAN;
|
||||
}
|
||||
if (isObject(value2)) {
|
||||
if (isObject2(value2)) {
|
||||
var other = typeof value2.valueOf == "function" ? value2.valueOf() : value2;
|
||||
value2 = isObject(other) ? other + "" : other;
|
||||
value2 = isObject2(other) ? other + "" : other;
|
||||
}
|
||||
if (typeof value2 != "string") {
|
||||
return value2 === 0 ? value2 : +value2;
|
||||
@@ -24778,7 +24778,7 @@ var require_lodash = __commonJS({
|
||||
}
|
||||
function truncate(string2, options) {
|
||||
var length = DEFAULT_TRUNC_LENGTH, omission = DEFAULT_TRUNC_OMISSION;
|
||||
if (isObject(options)) {
|
||||
if (isObject2(options)) {
|
||||
var separator2 = "separator" in options ? options.separator : separator2;
|
||||
length = "length" in options ? toInteger(options.length) : length;
|
||||
omission = "omission" in options ? baseToString(options.omission) : omission;
|
||||
@@ -28846,6 +28846,7 @@ var require_semver2 = __commonJS({
|
||||
// utils/log.ts
|
||||
var core = __toESM(require_core(), 1);
|
||||
var import_table = __toESM(require_src(), 1);
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
// utils/globals.ts
|
||||
import { existsSync } from "node:fs";
|
||||
@@ -28854,6 +28855,20 @@ var isGitHubActions = !!process.env.GITHUB_ACTIONS;
|
||||
var isInsideDocker = existsSync("/.dockerenv");
|
||||
|
||||
// utils/log.ts
|
||||
var logContext = new AsyncLocalStorage();
|
||||
var MAGENTA = "\x1B[35m";
|
||||
var RESET = "\x1B[0m";
|
||||
function prefixLines(message) {
|
||||
const ctx = logContext.getStore();
|
||||
if (!ctx) return message;
|
||||
const colored = `${MAGENTA}${ctx.prefix}${RESET} `;
|
||||
return message.split("\n").map((line) => `${colored}${line}`).join("\n");
|
||||
}
|
||||
function prefixPlain(name) {
|
||||
const ctx = logContext.getStore();
|
||||
if (!ctx) return name;
|
||||
return `${ctx.prefix} ${name}`;
|
||||
}
|
||||
var isRunnerDebugEnabled = () => core.isDebug();
|
||||
var isLocalDebugEnabled = () => process.env.LOG_LEVEL === "debug" || process.env.ACTIONS_STEP_DEBUG === "true";
|
||||
var isDebugEnabled = () => isLocalDebugEnabled() || isRunnerDebugEnabled();
|
||||
@@ -28869,10 +28884,11 @@ ${arg.stack}`;
|
||||
}).join(" ");
|
||||
}
|
||||
function startGroup2(name) {
|
||||
const prefixed = prefixPlain(name);
|
||||
if (isGitHubActions) {
|
||||
core.startGroup(name);
|
||||
core.startGroup(prefixed);
|
||||
} else {
|
||||
console.group(name);
|
||||
console.group(prefixed);
|
||||
}
|
||||
}
|
||||
function endGroup2() {
|
||||
@@ -28945,7 +28961,7 @@ function boxString(text, options) {
|
||||
}
|
||||
function box(text, options) {
|
||||
const boxContent = boxString(text, options);
|
||||
core.info(boxContent);
|
||||
core.info(prefixLines(boxContent));
|
||||
}
|
||||
function printTable(rows, options) {
|
||||
const { title } = options || {};
|
||||
@@ -28959,42 +28975,42 @@ function printTable(rows, options) {
|
||||
);
|
||||
const formatted = (0, import_table.table)(tableData);
|
||||
if (title) {
|
||||
core.info(`
|
||||
${title}`);
|
||||
core.info(prefixLines(`
|
||||
${title}`));
|
||||
}
|
||||
core.info(`
|
||||
core.info(prefixLines(`
|
||||
${formatted}
|
||||
`);
|
||||
`));
|
||||
}
|
||||
function separator(length = 50) {
|
||||
const separatorText = "\u2500".repeat(length);
|
||||
core.info(separatorText);
|
||||
core.info(prefixLines(separatorText));
|
||||
}
|
||||
var log = {
|
||||
/** Print info message */
|
||||
info: (...args2) => {
|
||||
core.info(`${ts()}${formatArgs(args2)}`);
|
||||
core.info(prefixLines(`${ts()}${formatArgs(args2)}`));
|
||||
},
|
||||
/** Print a warning message. Use only for warnings that should be displayed in the job summary. */
|
||||
warning: (...args2) => {
|
||||
core.warning(`${ts()}${formatArgs(args2)}`);
|
||||
core.warning(prefixLines(`${ts()}${formatArgs(args2)}`));
|
||||
},
|
||||
/** Print an error message. Use only for errors that should be displayed in the job summary. */
|
||||
error: (...args2) => {
|
||||
core.error(`${ts()}${formatArgs(args2)}`);
|
||||
core.error(prefixLines(`${ts()}${formatArgs(args2)}`));
|
||||
},
|
||||
/** Print success message */
|
||||
success: (...args2) => {
|
||||
core.info(`${ts()}\xBB ${formatArgs(args2)}`);
|
||||
core.info(prefixLines(`${ts()}\xBB ${formatArgs(args2)}`));
|
||||
},
|
||||
/** Print debug message (only when debug mode is enabled) */
|
||||
debug: (...args2) => {
|
||||
if (isRunnerDebugEnabled()) {
|
||||
core.debug(formatArgs(args2));
|
||||
core.debug(prefixLines(formatArgs(args2)));
|
||||
return;
|
||||
}
|
||||
if (isLocalDebugEnabled()) {
|
||||
core.info(`${ts()}[DEBUG] ${formatArgs(args2)}`);
|
||||
core.info(prefixLines(`${ts()}[DEBUG] ${formatArgs(args2)}`));
|
||||
}
|
||||
},
|
||||
/** Print a formatted box with text */
|
||||
@@ -37477,6 +37493,22 @@ var schema = ark.schema;
|
||||
var define2 = ark.define;
|
||||
var declare = ark.declare;
|
||||
|
||||
// utils/apiUrl.ts
|
||||
function isLocalUrl(url2) {
|
||||
return url2.hostname === "localhost" || url2.hostname === "127.0.0.1";
|
||||
}
|
||||
function getApiUrl() {
|
||||
const raw = process.env.API_URL || "https://pullfrog.com";
|
||||
const parsed2 = new URL(raw);
|
||||
if (parsed2.protocol !== "https:" && !isLocalUrl(parsed2)) {
|
||||
throw new Error(
|
||||
`API_URL must use https:// (got ${parsed2.protocol}). only localhost is exempt.`
|
||||
);
|
||||
}
|
||||
log.debug(`resolved API_URL: ${raw}`);
|
||||
return raw;
|
||||
}
|
||||
|
||||
// utils/buildPullfrogFooter.ts
|
||||
var PULLFROG_DIVIDER = "<!-- PULLFROG_DIVIDER_DO_NOT_REMOVE_PLZ -->";
|
||||
var FROG_LOGO = `<a href="https://pullfrog.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pullfrog.com/logos/frog-white-full-18px.png"><img src="https://pullfrog.com/logos/frog-green-full-18px.png" width="9px" height="9px" style="vertical-align: middle; " alt="Pullfrog"></picture></a>`;
|
||||
@@ -41151,6 +41183,9 @@ var Octokit2 = Octokit.plugin(requestLog, legacyRestEndpointMethods, paginateRes
|
||||
);
|
||||
|
||||
// utils/github.ts
|
||||
function isObject(value2) {
|
||||
return typeof value2 === "object" && value2 !== null;
|
||||
}
|
||||
function parseRepoContext() {
|
||||
const githubRepo = process.env.GITHUB_REPOSITORY;
|
||||
if (!githubRepo) {
|
||||
@@ -41162,9 +41197,20 @@ function parseRepoContext() {
|
||||
}
|
||||
return { owner, name };
|
||||
}
|
||||
function emptyResourceUsage() {
|
||||
return {
|
||||
requestCount: 0,
|
||||
rateLimitRemaining: null,
|
||||
rateLimitResetMs: null
|
||||
};
|
||||
}
|
||||
var usageByResource = {
|
||||
core: emptyResourceUsage(),
|
||||
graphql: emptyResourceUsage()
|
||||
};
|
||||
function createOctokit(token) {
|
||||
const OctokitWithPlugins = Octokit2.plugin(throttling);
|
||||
return new OctokitWithPlugins({
|
||||
const octokit = new OctokitWithPlugins({
|
||||
auth: token,
|
||||
throttle: {
|
||||
onRateLimit: (_retryAfter, _options, _octokit, retryCount) => {
|
||||
@@ -41175,6 +41221,37 @@ function createOctokit(token) {
|
||||
}
|
||||
}
|
||||
});
|
||||
const onResponse = (response) => {
|
||||
const resource = response.headers["x-ratelimit-resource"];
|
||||
if (!resource) {
|
||||
return response;
|
||||
}
|
||||
usageByResource[resource] ??= emptyResourceUsage();
|
||||
const usage = usageByResource[resource];
|
||||
usage.requestCount++;
|
||||
const remaining = response.headers["x-ratelimit-remaining"];
|
||||
const reset = response.headers["x-ratelimit-reset"];
|
||||
if (remaining !== void 0) {
|
||||
usage.rateLimitRemaining = Number(remaining);
|
||||
}
|
||||
if (reset !== void 0) {
|
||||
usage.rateLimitResetMs = Number(reset) * 1e3;
|
||||
}
|
||||
return response;
|
||||
};
|
||||
octokit.hook.wrap("request", async (request2, options) => {
|
||||
try {
|
||||
const response = await request2(options);
|
||||
onResponse(response);
|
||||
return response;
|
||||
} catch (error2) {
|
||||
if (isObject(error2) && "response" in error2 && isObject(error2.response) && "headers" in error2.response && isObject(error2.response.headers)) {
|
||||
onResponse(error2.response);
|
||||
}
|
||||
throw error2;
|
||||
}
|
||||
});
|
||||
return octokit;
|
||||
}
|
||||
|
||||
// mcp/comment.ts
|
||||
@@ -41235,7 +41312,7 @@ var Effort = type.enumerated("mini", "auto", "max");
|
||||
// package.json
|
||||
var package_default = {
|
||||
name: "@pullfrog/pullfrog",
|
||||
version: "0.0.173",
|
||||
version: "0.0.177",
|
||||
type: "module",
|
||||
files: [
|
||||
"index.js",
|
||||
@@ -41350,7 +41427,7 @@ var JsonPayload = type({
|
||||
version: "string",
|
||||
"agent?": AgentName.or("undefined"),
|
||||
prompt: "string",
|
||||
"triggeringUser?": "string | undefined",
|
||||
"triggerer?": "string | undefined",
|
||||
"eventInstructions?": "string",
|
||||
"repoInstructions?": "string",
|
||||
"event?": "object",
|
||||
@@ -41403,15 +41480,25 @@ function getJobToken() {
|
||||
// utils/postCleanup.ts
|
||||
var SHOULD_CHECK_REASON = true;
|
||||
function buildErrorCommentBody(params) {
|
||||
const workflowRunLink = params.runId ? `[workflow run logs](https://github.com/${params.owner}/${params.repo}/actions/runs/${params.runId})` : "workflow run logs";
|
||||
const errorMessage = params.isCancellation ? `This run was cancelled \u{1F6D1}
|
||||
let errorMessage = params.isCancellation ? `This run was cancelled \u{1F6D1}
|
||||
|
||||
The workflow was cancelled before completion. Please check the ${workflowRunLink} for details.` : `This run croaked \u{1F635}
|
||||
The workflow was cancelled before completion.` : `This run croaked \u{1F635}
|
||||
|
||||
The workflow encountered an error before any progress could be reported. Please check the ${workflowRunLink} for details.`;
|
||||
The workflow encountered an error before any progress could be reported.`;
|
||||
if (params.runId) {
|
||||
errorMessage += " Please check the link below for details.";
|
||||
}
|
||||
const customParts = [];
|
||||
if (!params.isCancellation && params.runId) {
|
||||
const apiUrl = getApiUrl();
|
||||
customParts.push(
|
||||
`[Rerun failed job \u2794](${apiUrl}/trigger/${params.owner}/${params.repo}/${params.runId}?action=rerun)`
|
||||
);
|
||||
}
|
||||
const footer = buildPullfrogFooter({
|
||||
triggeredBy: true,
|
||||
workflowRun: params.runId ? { owner: params.owner, repo: params.repo, runId: params.runId } : void 0
|
||||
workflowRun: params.runId ? { owner: params.owner, repo: params.repo, runId: params.runId } : void 0,
|
||||
customParts
|
||||
});
|
||||
return `${errorMessage}${footer}`;
|
||||
}
|
||||
@@ -41441,12 +41528,12 @@ async function validateStuckProgressComment(params) {
|
||||
}
|
||||
}
|
||||
async function getIsCancelled(params) {
|
||||
if (!params.runIdStr) return false;
|
||||
if (!params.runId) return false;
|
||||
try {
|
||||
const jobsResult = await params.octokit.rest.actions.listJobsForWorkflowRun({
|
||||
owner: params.repoContext.owner,
|
||||
repo: params.repoContext.name,
|
||||
run_id: Number.parseInt(params.runIdStr, 10)
|
||||
run_id: params.runId
|
||||
});
|
||||
const currentJobName = process.env.GITHUB_JOB;
|
||||
const currentJob = currentJobName ? jobsResult.data.jobs.find(
|
||||
@@ -41473,7 +41560,7 @@ async function getIsCancelled(params) {
|
||||
}
|
||||
async function runPostCleanup() {
|
||||
log.info("\xBB [post] starting post cleanup");
|
||||
const runIdStr = process.env.GITHUB_RUN_ID;
|
||||
const runId = process.env.GITHUB_RUN_ID ? Number.parseInt(process.env.GITHUB_RUN_ID, 10) : void 0;
|
||||
let promptInput = null;
|
||||
try {
|
||||
const resolved = resolvePromptInput();
|
||||
@@ -41498,8 +41585,8 @@ async function runPostCleanup() {
|
||||
const body = buildErrorCommentBody({
|
||||
owner: repoContext.owner,
|
||||
repo: repoContext.name,
|
||||
runId: runIdStr,
|
||||
isCancellation: SHOULD_CHECK_REASON ? await getIsCancelled({ octokit, repoContext, runIdStr }) : false
|
||||
runId,
|
||||
isCancellation: SHOULD_CHECK_REASON ? await getIsCancelled({ octokit, repoContext, runId }) : false
|
||||
});
|
||||
await octokit.rest.issues.updateComment({
|
||||
owner: repoContext.owner,
|
||||
|
||||
@@ -72,6 +72,7 @@ async function fetchBodyHtml(ctx: ResolveBodyContext): Promise<string | undefine
|
||||
|
||||
case "pull_request_opened":
|
||||
case "pull_request_ready_for_review":
|
||||
case "pull_request_synchronize":
|
||||
case "pull_request_review_requested":
|
||||
// PRs are also issues - use issues.get which returns body_html
|
||||
if (!event.issue_number) return;
|
||||
|
||||
@@ -10,7 +10,7 @@ export interface AgentInfo {
|
||||
export interface WorkflowRunFooterInfo {
|
||||
owner: string;
|
||||
repo: string;
|
||||
runId: string;
|
||||
runId: number;
|
||||
/** optional job ID - if provided, will append /job/{jobId} to the workflow run URL */
|
||||
jobId?: string | undefined;
|
||||
}
|
||||
|
||||
+13
-2
@@ -1,4 +1,5 @@
|
||||
import type { ToolState } from "../mcp/server.ts";
|
||||
import { getApiUrl } from "./apiUrl.ts";
|
||||
import { buildPullfrogFooter } from "./buildPullfrogFooter.ts";
|
||||
import { createOctokit, parseRepoContext } from "./github.ts";
|
||||
import { getGitHubInstallationToken } from "./token.ts";
|
||||
@@ -19,12 +20,22 @@ export async function reportErrorToComment(ctx: ReportErrorParams): Promise<void
|
||||
|
||||
const repoContext = parseRepoContext();
|
||||
const octokit = createOctokit(getGitHubInstallationToken());
|
||||
const runId = process.env.GITHUB_RUN_ID;
|
||||
const runId = process.env.GITHUB_RUN_ID
|
||||
? Number.parseInt(process.env.GITHUB_RUN_ID, 10)
|
||||
: undefined;
|
||||
|
||||
const customParts: string[] = [];
|
||||
if (runId) {
|
||||
const apiUrl = getApiUrl();
|
||||
customParts.push(
|
||||
`[Rerun failed job ➔](${apiUrl}/trigger/${repoContext.owner}/${repoContext.name}/${runId}?action=rerun)`
|
||||
);
|
||||
}
|
||||
|
||||
// build footer with workflow run link
|
||||
const footer = buildPullfrogFooter({
|
||||
triggeredBy: true,
|
||||
workflowRun: runId ? { owner: repoContext.owner, repo: repoContext.name, runId } : undefined,
|
||||
customParts,
|
||||
});
|
||||
|
||||
await octokit.rest.issues.updateComment({
|
||||
|
||||
+99
-1
@@ -1,10 +1,24 @@
|
||||
import { createSign } from "node:crypto";
|
||||
import { rename, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import * as core from "@actions/core";
|
||||
import { throttling } from "@octokit/plugin-throttling";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { apiFetch } from "./apiFetch.ts";
|
||||
import { retry } from "./retry.ts";
|
||||
|
||||
function isObject(value: unknown) {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
// we don't get access to the actual class from @octokit/rest
|
||||
// it's reachable from @octokit/request-error but we'd have to add a dependency on it
|
||||
// and it would pose a risk of accidentally pulling a different version of that class (node_modules dep graphs ❤️)
|
||||
// so it's safer to ducktype this
|
||||
interface OctokitResponseShim {
|
||||
headers: Record<string, string | number | undefined>;
|
||||
}
|
||||
|
||||
export interface InstallationToken {
|
||||
token: string;
|
||||
expires_at: string;
|
||||
@@ -339,11 +353,55 @@ export type OctokitWithPlugins = InstanceType<
|
||||
ReturnType<typeof Octokit.plugin<typeof Octokit, [typeof throttling]>>
|
||||
>;
|
||||
|
||||
export interface ResourceUsage {
|
||||
requestCount: number;
|
||||
rateLimitRemaining: number | null;
|
||||
rateLimitResetMs: number | null;
|
||||
}
|
||||
|
||||
function emptyResourceUsage(): ResourceUsage {
|
||||
return {
|
||||
requestCount: 0,
|
||||
rateLimitRemaining: null,
|
||||
rateLimitResetMs: null,
|
||||
};
|
||||
}
|
||||
|
||||
const usageByResource: Record<string, ResourceUsage> = {
|
||||
core: emptyResourceUsage(),
|
||||
graphql: emptyResourceUsage(),
|
||||
};
|
||||
|
||||
export interface UsageSummary {
|
||||
version: 1;
|
||||
github: {
|
||||
core: ResourceUsage;
|
||||
graphql: ResourceUsage;
|
||||
};
|
||||
}
|
||||
|
||||
function getGitHubUsageSummary(): UsageSummary {
|
||||
return {
|
||||
version: 1,
|
||||
github: {
|
||||
core: usageByResource.core,
|
||||
graphql: usageByResource.graphql,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function writeGitHubUsageSummaryToFile(path: string): Promise<void> {
|
||||
const summary = getGitHubUsageSummary();
|
||||
const tmpPath = join(dirname(path), `.usage-summary-${process.pid}.tmp`);
|
||||
await writeFile(tmpPath, JSON.stringify(summary));
|
||||
await rename(tmpPath, path);
|
||||
}
|
||||
|
||||
export function createOctokit(token: string): OctokitWithPlugins {
|
||||
// `OctokitWithPlugins` initialization based on https://github.com/actions/toolkit/blob/2506e78e82fbd2f9e94d63e75f5309118c8de1b1/packages/github/src/github.ts#L15-L22
|
||||
// we can't use it directly because it's stuck on `@octokit/core@v5` and we use the hottest `@octokit/core@v7`
|
||||
const OctokitWithPlugins = Octokit.plugin(throttling);
|
||||
return new OctokitWithPlugins({
|
||||
const octokit = new OctokitWithPlugins({
|
||||
auth: token,
|
||||
throttle: {
|
||||
onRateLimit: (_retryAfter, _options, _octokit, retryCount) => {
|
||||
@@ -354,4 +412,44 @@ export function createOctokit(token: string): OctokitWithPlugins {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const onResponse = (response: OctokitResponseShim) => {
|
||||
const resource = response.headers["x-ratelimit-resource"];
|
||||
if (!resource) {
|
||||
return response;
|
||||
}
|
||||
usageByResource[resource] ??= emptyResourceUsage();
|
||||
const usage = usageByResource[resource];
|
||||
usage.requestCount++;
|
||||
const remaining = response.headers["x-ratelimit-remaining"];
|
||||
const reset = response.headers["x-ratelimit-reset"];
|
||||
if (remaining !== undefined) {
|
||||
usage.rateLimitRemaining = Number(remaining);
|
||||
}
|
||||
if (reset !== undefined) {
|
||||
usage.rateLimitResetMs = Number(reset) * 1000;
|
||||
}
|
||||
return response;
|
||||
};
|
||||
|
||||
octokit.hook.wrap("request", async (request, options) => {
|
||||
try {
|
||||
const response = await request(options);
|
||||
onResponse(response);
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (
|
||||
isObject(error) &&
|
||||
"response" in error &&
|
||||
isObject(error.response) &&
|
||||
"headers" in error.response &&
|
||||
isObject(error.response.headers)
|
||||
) {
|
||||
onResponse(error.response as OctokitResponseShim);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
return octokit;
|
||||
}
|
||||
|
||||
+45
-12
@@ -2,11 +2,43 @@
|
||||
* Logging utilities that work well in both local and GitHub Actions environments
|
||||
*/
|
||||
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
import * as core from "@actions/core";
|
||||
import { table } from "table";
|
||||
import type { AgentUsage } from "../agents/shared.ts";
|
||||
import { isGitHubActions, isInsideDocker } from "./globals.ts";
|
||||
|
||||
// --- subagent log prefix via AsyncLocalStorage ---
|
||||
|
||||
type LogContext = { prefix: string };
|
||||
|
||||
const logContext = new AsyncLocalStorage<LogContext>();
|
||||
|
||||
const MAGENTA = "\x1b[35m";
|
||||
const RESET = "\x1b[0m";
|
||||
|
||||
/** run `fn` with every log line prefixed by `prefix` (e.g. "[task-label]") in magenta */
|
||||
export function withLogPrefix<T>(prefix: string, fn: () => Promise<T>): Promise<T> {
|
||||
return logContext.run({ prefix }, fn);
|
||||
}
|
||||
|
||||
function prefixLines(message: string): string {
|
||||
const ctx = logContext.getStore();
|
||||
if (!ctx) return message;
|
||||
const colored = `${MAGENTA}${ctx.prefix}${RESET} `;
|
||||
return message
|
||||
.split("\n")
|
||||
.map((line) => `${colored}${line}`)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
/** plain-text prefix (no ANSI) for GitHub Actions group names */
|
||||
function prefixPlain(name: string): string {
|
||||
const ctx = logContext.getStore();
|
||||
if (!ctx) return name;
|
||||
return `${ctx.prefix} ${name}`;
|
||||
}
|
||||
|
||||
const isRunnerDebugEnabled = () => core.isDebug();
|
||||
|
||||
const isLocalDebugEnabled = () =>
|
||||
@@ -36,10 +68,11 @@ function formatArgs(args: unknown[]): string {
|
||||
* Start a collapsed group (GitHub Actions) or regular group (local)
|
||||
*/
|
||||
function startGroup(name: string): void {
|
||||
const prefixed = prefixPlain(name);
|
||||
if (isGitHubActions) {
|
||||
core.startGroup(name);
|
||||
core.startGroup(prefixed);
|
||||
} else {
|
||||
console.group(name);
|
||||
console.group(prefixed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +186,7 @@ function box(
|
||||
}
|
||||
): void {
|
||||
const boxContent = boxString(text, options);
|
||||
core.info(boxContent);
|
||||
core.info(prefixLines(boxContent));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,9 +233,9 @@ function printTable(
|
||||
const formatted = table(tableData);
|
||||
|
||||
if (title) {
|
||||
core.info(`\n${title}`);
|
||||
core.info(prefixLines(`\n${title}`));
|
||||
}
|
||||
core.info(`\n${formatted}\n`);
|
||||
core.info(prefixLines(`\n${formatted}\n`));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +243,7 @@ function printTable(
|
||||
*/
|
||||
function separator(length: number = 50): void {
|
||||
const separatorText = "─".repeat(length);
|
||||
core.info(separatorText);
|
||||
core.info(prefixLines(separatorText));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,32 +252,32 @@ function separator(length: number = 50): void {
|
||||
export const log = {
|
||||
/** Print info message */
|
||||
info: (...args: unknown[]): void => {
|
||||
core.info(`${ts()}${formatArgs(args)}`);
|
||||
core.info(prefixLines(`${ts()}${formatArgs(args)}`));
|
||||
},
|
||||
|
||||
/** Print a warning message. Use only for warnings that should be displayed in the job summary. */
|
||||
warning: (...args: unknown[]): void => {
|
||||
core.warning(`${ts()}${formatArgs(args)}`);
|
||||
core.warning(prefixLines(`${ts()}${formatArgs(args)}`));
|
||||
},
|
||||
|
||||
/** Print an error message. Use only for errors that should be displayed in the job summary. */
|
||||
error: (...args: unknown[]): void => {
|
||||
core.error(`${ts()}${formatArgs(args)}`);
|
||||
core.error(prefixLines(`${ts()}${formatArgs(args)}`));
|
||||
},
|
||||
|
||||
/** Print success message */
|
||||
success: (...args: unknown[]): void => {
|
||||
core.info(`${ts()}» ${formatArgs(args)}`);
|
||||
core.info(prefixLines(`${ts()}» ${formatArgs(args)}`));
|
||||
},
|
||||
|
||||
/** Print debug message (only when debug mode is enabled) */
|
||||
debug: (...args: unknown[]): void => {
|
||||
if (isRunnerDebugEnabled()) {
|
||||
core.debug(formatArgs(args));
|
||||
core.debug(prefixLines(formatArgs(args)));
|
||||
return;
|
||||
}
|
||||
if (isLocalDebugEnabled()) {
|
||||
core.info(`${ts()}[DEBUG] ${formatArgs(args)}`);
|
||||
core.info(prefixLines(`${ts()}[DEBUG] ${formatArgs(args)}`));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
+5
-3
@@ -19,7 +19,8 @@ export const JsonPayload = type({
|
||||
version: "string",
|
||||
"agent?": AgentName.or("undefined"),
|
||||
prompt: "string",
|
||||
"triggeringUser?": "string | undefined",
|
||||
"triggerer?": "string | undefined",
|
||||
|
||||
"eventInstructions?": "string",
|
||||
"repoInstructions?": "string",
|
||||
"event?": "object",
|
||||
@@ -167,8 +168,8 @@ export function resolvePayload(
|
||||
version: jsonPayload?.version ?? packageJson.version,
|
||||
agent: resolvedAgent,
|
||||
prompt,
|
||||
triggeringUser:
|
||||
jsonPayload?.triggeringUser ??
|
||||
triggerer:
|
||||
jsonPayload?.triggerer ??
|
||||
// it's not a common use case but GITHUB_ACTOR can be a user when the workflow is manually triggered by a user through GitHub Actions UI
|
||||
(!isPullfrog(process.env.GITHUB_ACTOR) ? process.env.GITHUB_ACTOR : undefined),
|
||||
eventInstructions: jsonPayload?.eventInstructions,
|
||||
@@ -177,6 +178,7 @@ export function resolvePayload(
|
||||
effort: inputs.effort ?? jsonPayload?.effort ?? "auto",
|
||||
timeout: inputs.timeout ?? jsonPayload?.timeout,
|
||||
cwd: resolveCwd(inputs.cwd),
|
||||
progressCommentId: jsonPayload?.progressCommentId,
|
||||
debug: jsonPayload?.debug,
|
||||
|
||||
// permissions: inputs > repoSettings > fallbacks
|
||||
|
||||
+26
-13
@@ -1,4 +1,5 @@
|
||||
import { LEAPING_INTO_ACTION_PREFIX } from "../mcp/comment.ts";
|
||||
import { getApiUrl } from "./apiUrl.ts";
|
||||
import { buildPullfrogFooter } from "./buildPullfrogFooter.ts";
|
||||
import { log } from "./cli.ts";
|
||||
import { createOctokit, parseRepoContext } from "./github.ts";
|
||||
@@ -15,22 +16,32 @@ const SHOULD_CHECK_REASON = true;
|
||||
type BuildErrorCommentBodyParams = {
|
||||
owner: string;
|
||||
repo: string;
|
||||
runId: string | undefined;
|
||||
runId: number | undefined;
|
||||
isCancellation: boolean;
|
||||
};
|
||||
|
||||
function buildErrorCommentBody(params: BuildErrorCommentBodyParams): string {
|
||||
const workflowRunLink = params.runId
|
||||
? `[workflow run logs](https://github.com/${params.owner}/${params.repo}/actions/runs/${params.runId})`
|
||||
: "workflow run logs";
|
||||
const errorMessage = params.isCancellation
|
||||
? `This run was cancelled 🛑\n\nThe workflow was cancelled before completion. Please check the ${workflowRunLink} for details.`
|
||||
: `This run croaked 😵\n\nThe workflow encountered an error before any progress could be reported. Please check the ${workflowRunLink} for details.`;
|
||||
let errorMessage = params.isCancellation
|
||||
? `This run was cancelled 🛑\n\nThe workflow was cancelled before completion.`
|
||||
: `This run croaked 😵\n\nThe workflow encountered an error before any progress could be reported.`;
|
||||
|
||||
if (params.runId) {
|
||||
errorMessage += " Please check the link below for details.";
|
||||
}
|
||||
|
||||
const customParts: string[] = [];
|
||||
if (!params.isCancellation && params.runId) {
|
||||
const apiUrl = getApiUrl();
|
||||
customParts.push(
|
||||
`[Rerun failed job ➔](${apiUrl}/trigger/${params.owner}/${params.repo}/${params.runId}?action=rerun)`
|
||||
);
|
||||
}
|
||||
const footer = buildPullfrogFooter({
|
||||
triggeredBy: true,
|
||||
workflowRun: params.runId
|
||||
? { owner: params.owner, repo: params.repo, runId: params.runId }
|
||||
: undefined,
|
||||
customParts,
|
||||
});
|
||||
return `${errorMessage}${footer}`;
|
||||
}
|
||||
@@ -76,16 +87,16 @@ async function validateStuckProgressComment(
|
||||
type GetIsCancelledParams = {
|
||||
repoContext: ReturnType<typeof parseRepoContext>;
|
||||
octokit: ReturnType<typeof createOctokit>;
|
||||
runIdStr: string | undefined;
|
||||
runId: number | undefined;
|
||||
};
|
||||
|
||||
async function getIsCancelled(params: GetIsCancelledParams): Promise<boolean> {
|
||||
if (!params.runIdStr) return false; // can't check without a run ID — assume failure
|
||||
if (!params.runId) return false; // can't check without a run ID — assume failure
|
||||
try {
|
||||
const jobsResult = await params.octokit.rest.actions.listJobsForWorkflowRun({
|
||||
owner: params.repoContext.owner,
|
||||
repo: params.repoContext.name,
|
||||
run_id: Number.parseInt(params.runIdStr, 10),
|
||||
run_id: params.runId,
|
||||
});
|
||||
|
||||
// find current job by matching GITHUB_JOB env var.
|
||||
@@ -125,7 +136,9 @@ async function getIsCancelled(params: GetIsCancelledParams): Promise<boolean> {
|
||||
export async function runPostCleanup(): Promise<void> {
|
||||
log.info("» [post] starting post cleanup");
|
||||
|
||||
const runIdStr = process.env.GITHUB_RUN_ID;
|
||||
const runId = process.env.GITHUB_RUN_ID
|
||||
? Number.parseInt(process.env.GITHUB_RUN_ID, 10)
|
||||
: undefined;
|
||||
|
||||
// resolve prompt input once and use it for both issue number and comment ID extraction
|
||||
// only use the object form (JSON payload), not plain string prompts
|
||||
@@ -159,9 +172,9 @@ export async function runPostCleanup(): Promise<void> {
|
||||
const body = buildErrorCommentBody({
|
||||
owner: repoContext.owner,
|
||||
repo: repoContext.name,
|
||||
runId: runIdStr,
|
||||
runId,
|
||||
isCancellation: SHOULD_CHECK_REASON
|
||||
? await getIsCancelled({ octokit, repoContext, runIdStr })
|
||||
? await getIsCancelled({ octokit, repoContext, runId })
|
||||
: false,
|
||||
});
|
||||
|
||||
|
||||
+29
-5
@@ -1,13 +1,37 @@
|
||||
import type { AgentResult } from "../agents/shared.ts";
|
||||
import type { MainResult } from "../main.ts";
|
||||
import type { ToolState } from "../mcp/server.ts";
|
||||
import { log } from "./cli.ts";
|
||||
import { reportErrorToComment } from "./errorReport.ts";
|
||||
|
||||
export function handleAgentResult(result: AgentResult): MainResult {
|
||||
if (!result.success) {
|
||||
export interface HandleAgentResultParams {
|
||||
result: AgentResult;
|
||||
toolState: ToolState;
|
||||
silent: boolean | undefined;
|
||||
}
|
||||
|
||||
export async function handleAgentResult(ctx: HandleAgentResultParams): Promise<MainResult> {
|
||||
if (!ctx.result.success) {
|
||||
return {
|
||||
success: false,
|
||||
error: result.error || "Agent execution failed",
|
||||
output: result.output!,
|
||||
error: ctx.result.error || "Agent execution failed",
|
||||
output: ctx.result.output!,
|
||||
};
|
||||
}
|
||||
|
||||
if (!ctx.toolState.wasUpdated && ctx.toolState.progressCommentId && !ctx.silent) {
|
||||
const error = ctx.result.error || "agent completed without reporting progress";
|
||||
try {
|
||||
await reportErrorToComment({
|
||||
toolState: ctx.toolState,
|
||||
error,
|
||||
title: "Error",
|
||||
});
|
||||
} catch {}
|
||||
return {
|
||||
success: false,
|
||||
error,
|
||||
output: ctx.result.output || "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +39,6 @@ export function handleAgentResult(result: AgentResult): MainResult {
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: result.output || "",
|
||||
output: ctx.result.output || "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface RepoSettings {
|
||||
search: ToolPermission;
|
||||
push: PushPermission;
|
||||
shell: ShellPermission;
|
||||
prApproveEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface RunContext {
|
||||
@@ -36,6 +37,7 @@ const defaultSettings: RepoSettings = {
|
||||
search: "enabled",
|
||||
push: "restricted",
|
||||
shell: "restricted",
|
||||
prApproveEnabled: false,
|
||||
};
|
||||
|
||||
const defaultRunContext: RunContext = {
|
||||
|
||||
+5
-3
@@ -6,7 +6,7 @@ interface ResolveRunParams {
|
||||
}
|
||||
|
||||
export interface ResolveRunResult {
|
||||
runId: string;
|
||||
runId: number | undefined;
|
||||
jobId: string | undefined;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ export interface ResolveRunResult {
|
||||
* Uses GITHUB_REPOSITORY and GITHUB_RUN_ID env vars.
|
||||
*/
|
||||
export async function resolveRun(params: ResolveRunParams): Promise<ResolveRunResult> {
|
||||
const runId = process.env.GITHUB_RUN_ID || "";
|
||||
const runId = process.env.GITHUB_RUN_ID
|
||||
? Number.parseInt(process.env.GITHUB_RUN_ID, 10)
|
||||
: undefined;
|
||||
const githubRepo = process.env.GITHUB_REPOSITORY;
|
||||
if (!githubRepo || !githubRepo.includes("/")) {
|
||||
throw new Error(`GITHUB_REPOSITORY env var must be set to "owner/repo", got: ${githubRepo}`);
|
||||
@@ -28,7 +30,7 @@ export async function resolveRun(params: ResolveRunParams): Promise<ResolveRunRe
|
||||
const jobs = await params.octokit.rest.actions.listJobsForWorkflowRun({
|
||||
owner,
|
||||
repo,
|
||||
run_id: parseInt(runId, 10),
|
||||
run_id: runId,
|
||||
});
|
||||
const matchingJob = jobs.data.jobs.find((job) => job.name === jobName);
|
||||
if (matchingJob) {
|
||||
|
||||
Reference in New Issue
Block a user