/** * Instruction File Merger (2.0) - CLAUDE.md / AGENTS.md * * parse → classify → render. * * File layout produced: * [user content that was above the META line] * * … (template order) * [user-owned tail: ## Commands / ## Project notes] (added once) * [all other user content, in original order] * * Guarantees: * - user content (anything outside SW markers) is never dropped * - sections removed from the template are deleted, ids reported * - a section's version attr changes only when its body changed * - idempotent: a second run over the output is byte-identical * - broken markers are repaired (body kept as user content), never abort * - legacy 1.x files (no markers, or "↓ ORIGINAL ↓" stacks) are stripped of * known 1.x template blocks by heading and de-duplicated */ import type { StackCommands } from './stack-detector.js'; export type TemplateType = 'claude' | 'agents'; /** Major version of the managed-block schema. Files below it are migrated. */ export declare const TEMPLATE_SCHEMA_MAJOR = 2; export interface TemplateSection { id: string; order: number; required: boolean; /** * Name of the condition flag (``). * The section is rendered only when `MergeOptions.flags[when]` is true, and is * removed from an existing file when the flag turns false. */ when?: string; content: string; } export interface ParsedTemplate { sections: TemplateSection[]; /** Content after the last ``: user-owned, emitted once. */ tail: string; } export interface MergeOptions { /** Template tail (user-owned). Ignored when a ParsedTemplate is passed. */ tail?: string; /** Detected project commands for the {{BUILD_CMD}} family of placeholders. */ commands?: StackCommands; /** Condition flags for `when="…"` sections (e.g. `{ umbrella: true }`). */ flags?: Record; } export interface MigrationInfo { fromVersion: string; removed: string[]; } export interface MergeResult { content: string; action: 'created' | 'merged' | 'unchanged'; updated: string[]; added: string[]; removed: string[]; preserved: number; warnings: string[]; migration: MigrationInfo | null; } export declare function parseTemplate(content: string): ParsedTemplate; export declare function parseTemplateSections(content: string): TemplateSection[]; /** A file split into the region SpecWeave manages and the region the user owns. */ export interface ManagedRegions { /** False when the file carries no SW:META / SW:SECTION markers at all. */ hasMarkers: boolean; /** Concatenated bodies of the SW:SECTION regions SpecWeave generates. */ managed: string; /** Everything else — the user's own writing, preserved verbatim by the merger. */ user: string; } /** * Split an instruction file into managed vs user-owned content, using the very * same marker parser the merger uses to preserve user content (`parseFile`), so * there is exactly one implementation of the SW marker grammar. * * A file with no markers (a legacy 1.x file `update` has not touched yet) is * entirely user-owned. */ export declare function splitManagedRegions(raw: string): ManagedRegions; /** * Fill `{{BUILD_CMD}}` / `{{TEST_CMD}}` / `{{LINT_CMD}}` (and the TODO marker a * previous run may have left) only where they are still present. Guarantees no * `{{…}}` placeholder survives into a written instruction file. */ export declare function fillCommandPlaceholders(text: string, commands?: StackCommands): string; export declare function mergeInstructionFile(existing: string | null, secs: TemplateSection[] | ParsedTemplate, type: TemplateType, ver: string, name: string, opts?: MergeOptions): MergeResult; /** * Strip all SW-managed content from an instruction file, returning only user * content (null when nothing is left). Used by `specweave uninstall`. */ export declare function stripSwSections(content: string): string | null; /** * Read specweave's own package.json (not the user's project). * Resolves reliably with symlinked installs (nvm, pnpm, npm link); falls back to a directory walk. */ export declare function readSpecweavePackageJson(): Record; export declare function getPackageVersion(): string; /** * Minimum Node.js version from specweave's package.json `engines.node` (e.g. ">=20.12.0" → "20.12.0"). */ export declare function getMinNodeVersion(): string; //# sourceMappingURL=instruction-file-merger.d.ts.map