// engine/hooks/full-spectrum-generator.ts — Full-spectrum Claude Code hook generator (SPEC-265)
// ---------------------------------------------------------------------------
// Individual script builders
// ---------------------------------------------------------------------------
/**
 * Generates the Stop hook script. Planu housekeeping is opt-in so generated
 * hooks cannot silently stage or commit user branches.
 */
export function generateStopHookScript(projectPath) {
    return `#!/bin/bash
# Optionally auto-commit planu/ if explicitly enabled (Planu Stop hook)
cd "${projectPath}"
if [ "$PLANU_ENABLE_AUTOCOMMIT" != "true" ]; then exit 0; fi
if git diff --quiet planu/ 2>/dev/null; then exit 0; fi
git add planu/specs/ planu/conventions.json && git commit -m "chore(planu): auto-commit session state [skip ci]" --no-verify
`;
}
/**
 * Generates the PreCompact hook script — queues a session_checkpoint action.
 */
export function generatePreCompactHookScript() {
    return `#!/bin/bash
# Queue session_checkpoint before context compression (Planu PreCompact hook)
echo '{"tool":"session_checkpoint","note":"auto-checkpoint before context compression"}' >> /tmp/planu-pending-actions.json
`;
}
/**
 * Generates the UserPromptSubmit hook script — injects active spec context.
 */
export function generateUserPromptSubmitHookScript() {
    return `#!/bin/bash
# Inject active spec context on each prompt (Planu UserPromptSubmit hook)
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
SPEC_ID=$(echo "$BRANCH" | grep -oE 'SPEC-[0-9]+' | head -1)
if [ -n "$SPEC_ID" ]; then
  echo "## Active spec: $SPEC_ID | Branch: $BRANCH"
fi
`;
}
/**
 * Generates the Notification hook script — shown when Claude is idle.
 */
export function generateNotificationHookScript() {
    return `#!/bin/bash
# Show pending approved specs when Claude is idle (Planu Notification hook)
# Non-blocking: only outputs if there are pending specs
true
`;
}
/**
 * Generates WorktreeCreate and WorktreeRemove hook scripts.
 */
export function generateWorktreeHookScripts() {
    const create = `#!/bin/bash
# Log worktree creation in shared-context (Planu WorktreeCreate hook)
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] Worktree created: $CLAUDE_WORKTREE_PATH" >> .claude/shared-context.md 2>/dev/null || true
`;
    const remove = `#!/bin/bash
# Log worktree removal in shared-context (Planu WorktreeRemove hook)
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] Worktree removed: $CLAUDE_WORKTREE_PATH" >> .claude/shared-context.md 2>/dev/null || true
`;
    return { create, remove };
}
// ---------------------------------------------------------------------------
// Public aggregator
// ---------------------------------------------------------------------------
/**
 * Generates all requested hook scripts based on the supplied config.
 * Returns an array of HookScript objects, one per enabled hook type.
 * The projectPath is used only for the Stop hook script.
 */
export function generateFullSpectrumHooks(config, projectPath = '$CLAUDE_PROJECT_PATH') {
    const scripts = [];
    if (config.stopHook) {
        scripts.push({
            eventType: 'Stop',
            scriptContent: generateStopHookScript(projectPath),
            description: 'Optionally auto-commits planu/ changes at session end when enabled.',
        });
    }
    if (config.preCompactHook) {
        scripts.push({
            eventType: 'PreCompact',
            scriptContent: generatePreCompactHookScript(),
            description: 'Queues a session_checkpoint before context compression.',
        });
    }
    if (config.userPromptSubmitHook) {
        scripts.push({
            eventType: 'UserPromptSubmit',
            scriptContent: generateUserPromptSubmitHookScript(),
            description: 'Injects active spec/branch context into each prompt.',
        });
    }
    if (config.notificationHook) {
        scripts.push({
            eventType: 'Notification',
            scriptContent: generateNotificationHookScript(),
            description: 'Shows pending approved specs when Claude is idle.',
        });
    }
    if (config.worktreeHooks) {
        const { create, remove } = generateWorktreeHookScripts();
        scripts.push({
            eventType: 'WorktreeCreate',
            scriptContent: create,
            description: 'Logs worktree creation in .claude/shared-context.md.',
        });
        scripts.push({
            eventType: 'WorktreeRemove',
            scriptContent: remove,
            description: 'Logs worktree removal in .claude/shared-context.md.',
        });
    }
    return scripts;
}
//# sourceMappingURL=full-spectrum-generator.js.map