/**
 * commands/template.mjs — template dump command (C29).
 *
 * Layer 1 (post-CLI-layering refactor). Special-case: this cmd writes RAW
 * template text to stdout (not JSON) — the consumer pipes it directly into
 * a file or another tool. After subtask 20, returns the {rawText, exitCode}
 * tuple so wrap() routes it through process.stdout.write without wrapping
 * a JSON envelope on top.
 *
 * Errors throw a plain Error which wrap() catches and converts to fail().
 */
import { existsSync, readFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { rawText } from '../util/result.mjs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export function cmdTemplate(name) {
    if (!name)
        throw new Error('Usage: apt-tools template <name>\nAvailable: agents-greenfield, agents-brownfield, config, state, gitignore');
    const templateDir = resolve(__dirname, '..', '..', '..', 'templates');
    const nameMap = {
        'agents-greenfield': 'agents-greenfield.md',
        'agents-brownfield': 'agents-brownfield.md',
        config: 'config.json',
        state: 'state.json',
        gitignore: 'gitignore-aperant',
    };
    const filename = nameMap[name];
    if (!filename)
        throw new Error(`Unknown template: ${name}. Available: ${Object.keys(nameMap).join(', ')}`);
    const templatePath = join(templateDir, filename);
    if (!existsSync(templatePath))
        throw new Error(`Template file not found: ${templatePath}`);
    // Output raw content (not JSON) so it can be used directly. The rawText
    // shape (subtask 15) routes through wrap()'s process.stdout.write path
    // without a JSON envelope wrapper. (subtask 20: replaces the legacy
    // `return undefined + side-effect-write` pattern.)
    return rawText(readFileSync(templatePath, 'utf-8'), 0);
}
//# sourceMappingURL=template.mjs.map