const SESSION_START_COMMAND = [
    'echo "=== Planu Active Specs ===";',
    'if command -v planu >/dev/null 2>&1; then',
    '  planu list --status=approved --compact 2>/dev/null || echo "No approved specs";',
    'fi;',
    'echo "=== Git Branch ===";',
    'git branch --show-current 2>/dev/null || echo "Not a git repo"',
].join(' ');
const STOP_COMMAND = [
    'if [ -d "planu/" ]; then',
    '  if [ "$PLANU_ENABLE_AUTOCOMMIT" != "true" ]; then exit 0; fi;',
    '  git add planu/specs/ planu/conventions.json 2>/dev/null;',
    '  git diff --staged --quiet || git commit -m "chore: auto-save planu state" 2>/dev/null;',
    'fi',
].join(' ');
const AFTER_TOOL_USE_COMMAND = [
    'if echo "$CODEX_TOOL_NAME" | grep -qE "write|edit|create"; then',
    '  if echo "$CODEX_TOOL_PATH" | grep -qE "^src/"; then',
    '    echo "Reminder: ensure an approved Planu spec exists before writing to src/";',
    '  fi;',
    'fi',
].join(' ');
/** Returns the standard set of Codex hooks for Planu SDD workflow. */
export function generateCodexHooks() {
    return [
        {
            event: 'SessionStart',
            command: SESSION_START_COMMAND,
        },
        {
            event: 'Stop',
            command: STOP_COMMAND,
        },
        {
            event: 'AfterToolUse',
            command: AFTER_TOOL_USE_COMMAND,
        },
    ];
}
function escapeTomlString(value) {
    // Use triple-quoted TOML string for multi-line commands
    if (value.includes('\n') || value.includes('"')) {
        return `'''\n${value}\n'''`;
    }
    return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
}
/** Converts a CodexHook array to TOML [[hooks]] sections. */
export function generateCodexHooksToml(hooks) {
    return hooks
        .map((hook) => {
        const command = escapeTomlString(hook.command);
        return [`[[hooks]]`, `event = "${hook.event}"`, `command = ${command}`].join('\n');
    })
        .join('\n\n');
}
//# sourceMappingURL=hooks-generator.js.map