/**
 * Names of Claude Code tools that indicate entering Plan Mode.
 * The main "Task" tool is how Claude enters plan mode; "plan" is an alias.
 */
const ENTER_PLAN_MODE_TOOLS = ['Task'];
/**
 * Names of Claude Code tools that indicate exiting Plan Mode.
 */
const EXIT_PLAN_MODE_TOOLS = ['exit_plan_mode'];
/**
 * Reads CLAUDE_TOOL_NAME and CLAUDE_TOOL_INPUT from the environment
 * and returns a PlanModeEvent describing the current tool invocation.
 *
 * This is designed to be called from Claude Code hook scripts that set
 * these env vars before invoking the hook handler.
 */
export function detectPlanModeEvent() {
    const toolName = process.env.CLAUDE_TOOL_NAME ?? '';
    const toolInputRaw = process.env.CLAUDE_TOOL_INPUT ?? '';
    const taskDescription = extractTaskDescription(toolInputRaw);
    return { toolName, taskDescription };
}
/**
 * Returns true when the given tool name corresponds to entering Plan Mode.
 */
export function isEnterPlanMode(toolName) {
    return ENTER_PLAN_MODE_TOOLS.includes(toolName);
}
/**
 * Returns true when the given tool name corresponds to exiting Plan Mode.
 */
export function isExitPlanMode(toolName) {
    return EXIT_PLAN_MODE_TOOLS.includes(toolName);
}
/**
 * Attempts to extract a human-readable task description from the JSON-encoded
 * CLAUDE_TOOL_INPUT string.  Returns null when the input is empty or cannot
 * be parsed, or when no recognisable description field is present.
 *
 * Claude Code's Task tool input has the shape: { description: string, ... }
 * We also fall back to a `prompt`, `task`, or `content` field.
 */
export function extractTaskDescription(toolInput) {
    if (!toolInput.trim()) {
        return null;
    }
    let parsed;
    try {
        parsed = JSON.parse(toolInput);
    }
    catch {
        // Not JSON — treat the raw string as the description if it is short enough
        const trimmed = toolInput.trim();
        return trimmed.length > 0 && trimmed.length <= 2000 ? trimmed : null;
    }
    if (typeof parsed !== 'object' || parsed === null) {
        return null;
    }
    const obj = parsed;
    for (const key of ['description', 'prompt', 'task', 'content']) {
        const val = obj[key];
        if (typeof val === 'string' && val.trim().length > 0) {
            return val.trim();
        }
    }
    return null;
}
//# sourceMappingURL=plan-mode-detector.js.map