// PEP-127: «Принять» pressed while the story's PR conflicts with the main branch is remembered — // the agent rebases, Peppa merges and closes the story by itself (runner/accept-pending.ts). import { settings, type Db, keyPrefix } from "@peppa/db"; import { m } from "@peppa/shared/i18n"; import { like } from "drizzle-orm"; import { deleteSetting, getSetting, setSetting } from "./settings.ts"; export interface PendingAccept { /** When the PM accepted (ms). */ at: number; /** Where «Принять» was pressed. */ via: string; /** Rebase requests sent to the agent so far. */ rebases: number; /** Head SHA for which Peppa asked Gitea to bring the base branch into the PR branch. */ updateSha?: string; } const PREFIX = "accept.pending:"; const key = (taskId: number) => `${PREFIX}${taskId}`; /** What the PM sees on the story while the accept is being carried through. */ export const PENDING_ACCEPT_LABEL = m("Принято — изменения обновляются, закроется само"); /** Answer that closes the ready-for-review message of a deferred accept. */ export const PENDING_ACCEPT_ANSWER = `✅ ${PENDING_ACCEPT_LABEL}`; export const getPendingAccept = (db: Db, taskId: number) => getSetting(db, key(taskId)); export const setPendingAccept = (db: Db, taskId: number, s: PendingAccept) => setSetting(db, key(taskId), s); export const clearPendingAccept = (db: Db, taskId: number) => deleteSetting(db, key(taskId)); /** All remembered accepts: task id → state. */ export async function listPendingAccepts(db: Db): Promise> { const rows = await db.select().from(settings).where(keyPrefix(settings.key, `${PREFIX}`)); return new Map(rows.map((r) => [Number(r.key.slice(PREFIX.length)), r.value as PendingAccept])); }