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:
1 parent
625ba79dbb
commit
ec601bef93
6 files changed
+199
-6
No files matched your search
@@ -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)";
|
||||
}
|
||||
Reference in new issue
Block a user