/* Shared helpers for sternsystem pin generation: highestRfcId extraction and snapshotCapabilities projection from the workspace. Do not include pin writing or registry update logic — those belong to the command handlers. RFC-0381: extracted highestRfcId and snapshotCapabilities from sternsystem-extract.ts and sternsystem-pin.ts to eliminate duplication. */ import path from "node:path"; import { parse as parseYaml } from "yaml"; import type { SystemPin } from "@warpgogol/werkstatt-engine/schemas"; import { createDefaultIO, type WorkspaceIO } from "@warpgogol/werkstatt-shared/kernel/workspace-io"; export async function highestRfcId( workspaceRoot: string, io: WorkspaceIO = createDefaultIO().io, ): Promise { try { const files = await io.readdir(path.join(workspaceRoot, "docs", "rfcs")); let max = 0; for (const f of files) { const m = /^[Rr][Ff][Cc]-(\d{4})/.exec(f.name); if (m) max = Math.max(max, Number(m[1])); } return `RFC-${String(max).padStart(4, "0")}`; } catch { return "RFC-0000"; } } export async function snapshotCapabilities( workspaceRoot: string, io: WorkspaceIO = createDefaultIO().io, ): Promise { try { const raw = await io.readFile(path.join(workspaceRoot, "uni.registry.yaml")); const parsed = parseYaml(raw) as { entries?: Array<{ id: string; semanticId?: string; version?: string; intent?: string[] }>; }; return (parsed.entries ?? []) .filter((e) => e.id) .map((e) => ({ semanticId: e.semanticId ?? e.id, version: e.version ?? "0.0.0", intent: e.intent ?? [], })); } catch { return []; } }