Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

1.2 KB
Raw Blame
import { config } from "./config.mjs";
import * as linear from "./linear.mjs";
import { note, save, transition } from "./state.mjs";

export const FOOTER = `_Generated by linear-autofix. Add the \`${config.labels.optOut}\` label to stop the bot on this ticket._`;

export async function escalate(record, reason) {
  record.escalation = { reason, at: new Date().toISOString() };
  await linear.comment(
    record,
    `**自动处理已停止,需要人工介入**\n\n${reason}\n\n${record.pr?.url ? `PR: ${record.pr.url}\n\n` : ""}${FOOTER}`,
  );
  await linear.addLabel(record, config.labels.escalated);
  transition(record, "escalated", reason);
}

export async function recordError(record, err) {
  record.consecutiveErrors = (record.consecutiveErrors ?? 0) + 1;
  note(record, "error", err?.message ?? String(err));
  if (record.consecutiveErrors >= 3) {
    await escalate(
      record,
      `连续 ${record.consecutiveErrors} 次运行出错,最后一次:\n\n\`\`\`\n${String(err?.message ?? err).slice(0, 1500)}\n\`\`\``,
    );
  }
}

export function clearErrors(record) {
  if (record.consecutiveErrors) {
    record.consecutiveErrors = 0;
    save(record);
  }
}