Require receipts for non-github bridge activity

This commit is contained in:
Meta Vens 2026-06-17 12:06:20 +01:00
commit a22092feff
8 changed files with 131 additions and 0 deletions

View file

@ -248,6 +248,7 @@ async function mirrorEnqueuedRequestOrThrow(request, options) {
...optionalArg("--target-repository-full-name", request.targetRepositoryFullName ?? request.targetRepoName),
...optionalArg("--persona-avatar-url", personaAvatarUrl),
...optionalArg("--reply-to-message-id", options["mirror-reply-to-message-id"]),
...bridgeRecoveryArgs(options),
...(options["mirror-dry-run"] === "true" ? ["--dry-run", "true"] : []),
], repoRoot);
}
@ -264,6 +265,10 @@ function allowsUnmirrored(options) {
return options["allow-unmirrored"] === "true" || process.env.BIFROST_ALLOW_UNMIRRORED_GOVERNANCE === "true";
}
function bridgeRecoveryArgs(options) {
return allowsUnreceiptedActivity(options) ? ["--allow-unreceipted-activity", "true"] : [];
}
function renderRequestMirrorFallback(request) {
const actor = request.createdByAgent ? `${request.createdByAgent} queued` : "Queued";
return [

View file

@ -267,6 +267,7 @@ async function commentGitHubPr(options) {
}
async function postDiscordMessage(options) {
ensureBridgeReceiptGate(options);
const token = process.env.BIFROST_DISCORD_BOT_TOKEN ?? process.env.DISCORD_BOT_TOKEN;
const channelId = requireOption(options, "channel-id");
const content = await readOptionText(options, "content", "content-file");
@ -339,6 +340,7 @@ async function postDiscordMessage(options) {
}
async function sendDiscordDm(options) {
ensureBridgeReceiptGate(options);
const token = process.env.BIFROST_DISCORD_BOT_TOKEN ?? process.env.DISCORD_BOT_TOKEN;
const recipientId = requireOption(options, "recipient-id");
const content = await readOptionText(options, "content", "content-file");
@ -401,6 +403,7 @@ async function sendDiscordDm(options) {
}
async function postRedditThread(options) {
ensureBridgeReceiptGate(options);
const subreddit = normalizeSubreddit(options.subreddit ?? process.env.BIFROST_REDDIT_SUBREDDIT ?? "GameCultOrg");
const title = requireOption(options, "title");
const content = await readOptionText(options, "content", "content-file");
@ -1057,6 +1060,34 @@ function ensureGitHubBridgeGate(options) {
);
}
function ensureBridgeReceiptGate(options) {
const baseUrl = optionalString(options["bifrost-base-url"]) ?? optionalString(process.env.BIFROST_BRIDGE_BASE_URL);
const token = optionalString(options["bifrost-token"]) ?? optionalString(process.env.BIFROST_BRIDGE_TOKEN);
const allowUnreceipted =
options["allow-unreceipted-activity"] === "true" ||
process.env.BIFROST_ALLOW_UNRECEIPTED_ACTIVITY === "true";
if (allowUnreceipted && process.env.BIFROST_LOCK_RECOVERY_HATCHES === "true") {
throw new Error(
"Dispatched Bifrost work cannot use --allow-unreceipted-activity or BIFROST_ALLOW_UNRECEIPTED_ACTIVITY. " +
"External bridge activity from a dispatched turn must go through the normal Bifrost receipt path.",
);
}
if (baseUrl && token) {
return;
}
if (allowUnreceipted) {
return;
}
throw new Error(
"Bridge activity requires BIFROST_BRIDGE_BASE_URL and BIFROST_BRIDGE_TOKEN so Bifrost can receipt the external crossing. " +
"Set BIFROST_BRIDGE_BASE_URL and BIFROST_BRIDGE_TOKEN, or use --allow-unreceipted-activity true only for explicit operator recovery.",
);
}
async function postBridgeJson(baseUrl, token, path, payload, allowedStatuses) {
const url = new URL(path, ensureTrailingSlash(baseUrl));
const response = await fetch(url, {

View file

@ -528,6 +528,7 @@ function postDispatchReceipt(request, dispatchRecord, options) {
"--authority-ref", "bifrost_dispatch_started_receipt",
...optionalArg("--target-repository-full-name", request.targetRepositoryFullName),
...optionalArg("--persona-avatar-url", personaAvatarUrl),
...bridgeRecoveryArgs(options),
], bifrostRoot);
}
@ -540,6 +541,10 @@ function resolveDispatchReceiptChannelId(options) {
);
}
function bridgeRecoveryArgs(options) {
return allowsUnreceiptedActivity(options) ? ["--allow-unreceipted-activity", "true"] : [];
}
function renderDispatchReceiptContent(request) {
const topic = summarizeRequestTopic(request);
const actor = request.targetAgentIdentity

View file

@ -414,6 +414,7 @@ async function mirrorTopicActivityOrThrow(cache, topic, input) {
"--target-repository-full-name", topic.jurisdictionRepoName,
...optionalArg("--persona-avatar-url", personaAvatarUrl),
...optionalArg("--reply-to-message-id", input.options["mirror-reply-to-message-id"]),
...bridgeRecoveryArgs(input.options),
...(input.options["mirror-dry-run"] === "true" ? ["--dry-run", "true"] : []),
], repoRoot);
const bodyMarkdown = receipt.dryRun
@ -445,6 +446,10 @@ function allowsUnmirrored(options) {
return options["allow-unmirrored"] === "true" || process.env.BIFROST_ALLOW_UNMIRRORED_GOVERNANCE === "true";
}
function bridgeRecoveryArgs(options) {
return allowsUnreceiptedActivity(options) ? ["--allow-unreceipted-activity", "true"] : [];
}
function renderGovernanceMirrorContent(topic, eventLabel, content) {
const event = governanceMirrorEvent(eventLabel);
return [