"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TmuxPlugin = void 0;
const PluginBase_1 = require("./PluginBase");
const utils_1 = require("../utils");
class TmuxPlugin extends PluginBase_1.PluginBase {
    static meta = {
        key: "tmux",
        name: "Tmux Plugin",
        requires: [],
    };
    meta = TmuxPlugin.meta;
    constructor(context) {
        super(context);
    }
    async embed(userPrompt) {
        return [];
    }
    async isInTmux() {
        try {
            const { stdout } = await (0, utils_1.execAsync)("echo $TMUX");
            return stdout.trim().length > 0;
        }
        catch {
            return false;
        }
    }
    async getCurrentSession() {
        try {
            const { stdout } = await (0, utils_1.execAsync)("tmux display-message -p '#{session_name}:#{window_index}:#{window_name}'");
            return stdout.trim();
        }
        catch (error) {
            return "";
        }
    }
    async getSessions() {
        try {
            const { stdout } = await (0, utils_1.execAsync)("tmux list-sessions");
            return stdout
                .trim()
                .split("\n")
                .filter((line) => line.length > 0);
        }
        catch {
            return [];
        }
    }
    async getWindows() {
        try {
            const { stdout } = await (0, utils_1.execAsync)("tmux list-windows");
            return stdout
                .trim()
                .split("\n")
                .filter((line) => line.length > 0);
        }
        catch {
            return [];
        }
    }
    async getPanes() {
        try {
            const { stdout } = await (0, utils_1.execAsync)("tmux list-panes -a -F '#{session_name}:#{window_index}.#{pane_index} #{pane_title} #{pane_current_command} #{pane_current_path}'");
            return stdout
                .trim()
                .split("\n")
                .filter((line) => line.length > 0);
        }
        catch {
            return [];
        }
    }
    async call() {
        const inTmux = await this.isInTmux();
        if (!inTmux) {
            return "TMUX PLUGIN: Not currently in a tmux session";
        }
        const currentSession = await this.getCurrentSession();
        const sessions = await this.getSessions();
        const windows = await this.getWindows();
        const panes = await this.getPanes();
        const output = `TMUX PLUGIN: You are currently in a tmux session. This means you can use tmux commands to help debug and navigate.

**Current Session/Window**: ${currentSession}

**Available Sessions**:
${sessions.map((s) => `  - ${s}`).join("\n")}

**Windows in Current Session**:
${windows.map((w) => `  - ${w}`).join("\n")}

**All Panes** (showing running commands and paths):
${panes.map((p) => `  - ${p}`).join("\n")}

**Useful tmux commands for debugging**:
- \`tmux send-keys -t <session>:<window>.<pane> "command" Enter\` - Send a command to a specific pane
- \`tmux capture-pane -t <session>:<window>.<pane> -p\` - Capture output from a pane
- \`tmux list-panes -a\` - List all panes
- \`tmux switch-client -t <session>\` - Switch to another session
- \`tmux select-window -t <window>\` - Switch to another window
- \`tmux select-pane -t <pane>\` - Switch to another pane

You can use execCommand to run these tmux commands to inspect running processes, send commands to other panes, or capture output for debugging.`;
        return output;
    }
}
exports.TmuxPlugin = TmuxPlugin;
//# sourceMappingURL=tmux.js.map