/* RFC-0750: appendAndCommitBordbuch and appendBatchAndCommitBordbuch helpers that combine appendBordbuchEntry + commitAndPushBordbuch into one atomic operation. Does not define bordbuch event schema — that lives in @warpgogol/werkstatt-shared/ontology/operations. Does not implement git operations — those live in bordbuch-io.ts commitAndPushBordbuch. Does not throw on commit/push failure — returns commitResult for caller to decide. RFC-0750: initial appendAndCommitBordbuch and appendBatchAndCommitBordbuch helpers. */ import type { BordbuchEntry, BordbuchEntryKind } from "@warpgogol/werkstatt-engine/schemas"; import { appendBordbuchEntry, commitAndPushBordbuch, type CommitAndPushResult, } from "./bordbuch-io.ts"; import { resolveCacheClonePath } from "../sternsystem/registry-io.ts"; export interface AppendAndCommitResult { entry: BordbuchEntry; commitResult: CommitAndPushResult; } export interface AppendBatchAndCommitResult { entries: BordbuchEntry[]; commitResult: CommitAndPushResult; } export interface AppendBordbuchOptions { missionId?: string | null; releaseId?: string | null; writerRole?: string; metadata?: Record; status?: BordbuchEntry["status"]; erratumOf?: string; } export interface BatchBordbuchEntrySpec { kind: BordbuchEntryKind; summary: string; actor: string; options?: AppendBordbuchOptions; } export async function appendAndCommitBordbuch( workspaceRoot: string, systemId: string, kind: BordbuchEntryKind, summary: string, actor: string, options?: AppendBordbuchOptions, commitMessage?: string, ): Promise { const entry = await appendBordbuchEntry(workspaceRoot, systemId, kind, summary, actor, options); const systemDir = await resolveCacheClonePath(workspaceRoot, systemId); const message = commitMessage ?? `Bordbuch: ${kind} ${systemId}`; const commitResult = await commitAndPushBordbuch(systemDir, message); return { entry, commitResult }; } export async function appendBatchAndCommitBordbuch( workspaceRoot: string, systemId: string, entries: BatchBordbuchEntrySpec[], commitMessage: string, ): Promise { const appended: BordbuchEntry[] = []; for (const spec of entries) { const entry = await appendBordbuchEntry( workspaceRoot, systemId, spec.kind, spec.summary, spec.actor, spec.options, ); appended.push(entry); } const systemDir = await resolveCacheClonePath(workspaceRoot, systemId); const commitResult = await commitAndPushBordbuch(systemDir, commitMessage); return { entries: appended, commitResult }; }