feat: append a collapsible runtime environment to bot comments

Comments in which ghbot starts or completes an operation now end with a collapsed Runtime environment block (trigger, runner, goose model and version, review policy, automation flags, cache state) followed by a Created By GHBot signature linking to this repository. The template is shared by action-mode progress, recheck, completion, and PR chat comments; the workflow exports the pinned GOOSE_VERSION so the displayed version is truthful.
This commit is contained in:
lezi-fun committed 2026-08-22 11:36:39 +08:00
1 parent 625ba79dbb
commit ec601bef93
6 files changed
+199 -6

No files matched your search

+6 -1
View File
@@ -1,6 +1,7 @@
import fs from "node:fs";
import { config } from "../config.js";
import { createGitHubCredentials } from "../github/client.js";
import { formatBotSignature, formatRuntimeEnvironmentDetails } from "../github/runtimeInfo.js";
import { logger } from "../logger.js";
import { withRetry } from "../retry.js";
import { processPullRequestChat } from "../chat/processor.js";
@@ -161,7 +162,11 @@ async function main(): Promise<void> {
owner: prPayload.repository.owner.login,
repo: prPayload.repository.name,
issue_number: prPayload.pull_request.number,
body: "Automated review has started. I am checking this pull request now."
body: [
"Automated review has started. I am checking this pull request now.",
formatRuntimeEnvironmentDetails(),
formatBotSignature()
].join("\n\n")
});
});
}
+2 -1
View File
@@ -4,6 +4,7 @@ import type { Octokit } from "@octokit/rest";
import { runGooseAgent } from "../ai/gooseCli.js";
import { config } from "../config.js";
import { postPermissionDeniedComment } from "../github/commandFeedback.js";
import { formatBotSignature, formatRuntimeEnvironmentDetails } from "../github/runtimeInfo.js";
import { logger } from "../logger.js";
import { withRetry } from "../retry.js";
import { compactFilesForReview } from "../review/prompt.js";
@@ -145,7 +146,7 @@ export async function processPullRequestChat(
owner: params.owner,
repo: params.repo,
issue_number: params.pullNumber,
body: `${marker}\n${reply}`
body: `${marker}\n${reply}\n\n${formatRuntimeEnvironmentDetails()}\n\n${formatBotSignature()}`
});
});
}
+106
View File
@@ -0,0 +1,106 @@
import { config } from "../config.js";
export type RuntimeMode = "actions" | "webhook" | "local";
/**
* Where is this ghbot process running? Action-mode workflow runs set
* GITHUB_ACTIONS; the optional webhook service opts in via WEBHOOK_ENABLED.
* Anything else is a local simulation.
*/
export function detectRuntimeMode(): RuntimeMode {
if (process.env.GITHUB_ACTIONS === "true") {
return "actions";
}
return config.webhookEnabled ? "webhook" : "local";
}
function gooseVersion(): string | undefined {
const version = process.env.GOOSE_VERSION?.trim();
return version ? version : undefined;
}
function hostLine(): string {
const os = process.env.RUNNER_OS ?? process.platform;
return `${os} / ${process.arch} · Node.js ${process.version}`;
}
function eventLine(): string | undefined {
const eventName = process.env.GHBOT_EVENT_NAME ?? process.env.GITHUB_EVENT_NAME;
const eventAction = process.env.GHBOT_EVENT_ACTION;
if (!eventName) {
return undefined;
}
return eventAction ? `\`${eventName}\` / ${eventAction}` : `\`${eventName}\``;
}
function r2CacheEnabled(): boolean {
return Boolean(
config.r2Endpoint &&
config.r2BucketName &&
config.r2AccessKeyId &&
config.r2SecretAccessKey
);
}
/**
* Collapsed <details> block appended to comments in which the bot announces or
* performs an operation. The visual template is identical for every runtime
* mode (Actions, webhook service, local); only the fact lines differ. It must
* never contain credentials: only non-secret configuration and host facts.
*/
export function formatRuntimeEnvironmentDetails(mode: RuntimeMode = detectRuntimeMode()): string {
const lines: string[] = [];
if (mode === "webhook") {
lines.push(
"- **Mode:** GitHub App webhook service (read-only chat)",
`- **Host:** ${hostLine()}`
);
} else {
const event = eventLine();
const modeLabel = mode === "actions"
? event ? `GitHub Actions (${event})` : "GitHub Actions"
: event ? `local run (${event})` : "local run";
lines.push(
`- **Mode:** ${modeLabel}`,
`- **Runner:** ${hostLine()}`
);
}
const gooseParts = [
gooseVersion(),
`model \`${config.gooseModel ?? "unknown"}\``,
`thinking effort \`${config.gooseThinkingEffort ?? "high"}\``
].filter(Boolean);
lines.push(`- **goose:** ${gooseParts.join(" · ")}`);
if (mode === "webhook") {
lines.push(
`- **Chat permission policy:** \`${config.webhookChatPermission}\``,
"- **Tools:** none · cannot edit files, run commands, or push commits"
);
} else {
lines.push(
`- **Review policy:** \`${config.reviewPolicy}\` · strictness \`${config.reviewStrictness}\` · max patch ${config.maxPatchChars} chars`,
`- **Automation:** auto-merge ${config.autoMerge ? "on" : "off"} · conflict repair ${config.autoResolveConflicts ? "on" : "off"}`,
`- **Cache:** R2 ${r2CacheEnabled() ? "enabled" : "disabled"} · repository knowledge ${config.repositoryKnowledgeEnabled ? "enabled" : "disabled"}`
);
}
return [
"<details>",
"<summary>⚙️ Runtime environment</summary>",
"",
...lines,
"",
"</details>"
].join("\n");
}
/**
* Attribution footer appended after the environment block on the comments in
* which the bot announces or performs an operation.
*/
export function formatBotSignature(): string {
return "🤖 Created By [**GHBot**](https://github.com/lezi-fun/ghbot)";
}
+7 -4
View File
@@ -2,6 +2,7 @@ import type { Octokit } from "@octokit/rest";
import { config } from "../config.js";
import { requiredChecksAreGreen } from "../github/checks.js";
import { postPermissionDeniedComment } from "../github/commandFeedback.js";
import { formatBotSignature, formatRuntimeEnvironmentDetails } from "../github/runtimeInfo.js";
import { formatBotDisplayName } from "../github/botIdentity.js";
import { collectValidNewLines, toDiffPosition } from "../github/diff.js";
import { logger } from "../logger.js";
@@ -351,8 +352,10 @@ export async function beginCommitReviewProgress(
const marker = reviewProgressMarker(pullRequest.head.sha);
const body = [
marker,
`New commit \`${shortSha(pullRequest.head.sha)}\` detected. Automated review has started for this commit.`
].join("\n");
`New commit \`${shortSha(pullRequest.head.sha)}\` detected. Automated review has started for this commit.`,
formatRuntimeEnvironmentDetails(),
formatBotSignature()
].join("\n\n");
const existing = await findIssueCommentByMarker(octokit, params, marker);
const response = existing
? await withRetry("github.issues.updateComment.reviewProgressStarted", async () => {
@@ -410,7 +413,7 @@ export async function finishCommitReviewProgress(
owner: params.owner,
repo: params.repo,
comment_id: params.commentId,
body: [marker, message].join("\n")
body: [marker, message, formatRuntimeEnvironmentDetails(), formatBotSignature()].join("\n\n")
});
});
}
@@ -608,7 +611,7 @@ export async function processRecheckComment(
owner: params.owner,
repo: params.repo,
issue_number: params.pullNumber,
body: `Recheck requested by @${params.commenterLogin}. Re-running the review with the repository's current strictness settings.`
body: `Recheck requested by @${params.commenterLogin}. Re-running the review with the repository's current strictness settings.\n\n${formatRuntimeEnvironmentDetails()}\n\n${formatBotSignature()}`
});
});