/** * `specweave reopen`: correct a completed increment back to `planned`. * * For an increment closed too early (source shipped, release or scope still * open). It never activates: `specweave start` stays the separate step, so a * workspace at capacity can still record the correction. Every check runs * before anything is written, and a refusal changes nothing: * * 1. a reason (stored in the audit record); * 2. an explicit workspace (`--workspace` or `SPECWEAVE_WORKSPACE`); the * increment folder must really live inside it, and its metadata.json, * spec.md and ledger.jsonl must be regular files, never symlinks; * 3. status `completed`; * 4. no task claimed, stale or blocked by another agent. Ownership moves only * through `specweave task release`, never through this command. * * Nothing here goes through MetadataManager.read/write or ConfigManager: those * persist schema and config repairs, which a refusal must not do. Reopens of * one increment are serialized by an exclusive lock file. Ledger writers take * no lock, so both new files are staged and flushed first, then the ledger, * metadata and spec bytes are compared with the ones checked, and only renames * follow. Any difference aborts with nothing changed. What remains is the gap * between that compare and the renames; closing it needs every ledger writer * to take the same lock. * * The ledger, reports/ and the spec body are left byte-identical; only the * frontmatter `status:` line changes, and the closure moves into * `metadata.reopened[]`. * * @module core/increment/reopen */ import { IncrementStatus, type ReopenRecord } from '../types/increment-metadata.js'; import { type TaskLedgerStatus } from '../tasks/ledger.js'; export type ReopenRefusal = 'no-reason' | 'no-workspace' | 'not-found' | 'outside-workspace' | 'not-completed' | 'foreign-owner' | 'busy' | 'changed'; export declare class ReopenRefused extends Error { readonly code: ReopenRefusal; readonly owners: UnfinishedTask[]; constructor(code: ReopenRefusal, message: string, owners?: UnfinishedTask[]); } export interface UnfinishedTask { task: string; status: TaskLedgerStatus; by?: string; } export interface ReopenResult { id: string; root: string; from: IncrementStatus; to: IncrementStatus.PLANNED; at: string; by: string; reason: string; /** The closure this reopen moved into `metadata.reopened[]`. */ previous: Pick; unfinished: UnfinishedTask[]; /** True when the increment was already reopened and nothing was written. */ unchanged: boolean; /** Active increments in the workspace and the advisory limit (0 = off). */ active: { count: number; limit: number; }; } export interface ReopenOptions { incrementId: string; reason?: string; /** Workspace root; defaults to SPECWEAVE_WORKSPACE (bin/specweave.js sets it from --workspace). */ workspace?: string; env?: NodeJS.ProcessEnv; now?: Date; /** Tests only: fault and race injection points in the commit. */ hooks?: { /** After both temp files are staged, before the final re-check and the renames. */ beforeCommit?: () => void; /** After spec.md is renamed into place, before metadata.json is. */ afterSpecCommit?: () => void; /** During a rollback, after the restored spec.md is staged, before its compare and rename. */ beforeRestore?: () => void; }; } /** * Set the frontmatter `status:` line, leaving every other byte as it was. A spec * with no frontmatter, or no top-level status line in it, is returned unchanged: * 3.0 specs keep their status in metadata.json only. */ export declare function withFrontmatterStatus(content: string, status: string): string; export declare function reopenIncrement(opts: ReopenOptions): ReopenResult; //# sourceMappingURL=reopen.d.ts.map