// @bun
import {
  getAutonomyCommandText,
  getAutonomyDeepSectionText,
  getAutonomyStatusText,
  init_autonomy
} from "./chunk-cfmkc8ha.js";
import"./chunk-67006cbc.js";
import"./chunk-6acx5heq.js";
import"./chunk-0s8fars0.js";
import"./chunk-k49xc781.js";
import {
  init_autonomyFlows,
  init_overlayContext,
  listAutonomyFlows,
  useRegisterOverlay
} from "./chunk-421yegj3.js";
import"./chunk-aaxz8a5g.js";
import"./chunk-2kcgxnvp.js";
import"./chunk-14p6wvsq.js";
import"./chunk-6s0q1s5r.js";
import"./chunk-0cpg8qh8.js";
import"./chunk-9phn5khx.js";
import"./chunk-vk9xcryd.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-ptxteaeh.js";
import"./chunk-7fcmqvbz.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-q3b4n194.js";
import"./chunk-zaqfb3tz.js";
import"./chunk-6hzx0kqr.js";
import"./chunk-71sdcaq6.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-dxa3y9vh.js";
import"./chunk-gjvhjywj.js";
import"./chunk-1w20m7gw.js";
import"./chunk-3gam18xn.js";
import"./chunk-rpmntgyh.js";
import"./chunk-24kv69g3.js";
import"./chunk-tzcrwnrf.js";
import"./chunk-k7xszak2.js";
import"./chunk-ztmb7geg.js";
import"./chunk-tbdkekz3.js";
import"./chunk-65zbgg1n.js";
import"./chunk-4spgkgr3.js";
import"./chunk-60fkafk2.js";
import"./chunk-h5zz0vxy.js";
import"./chunk-6hygvrhn.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-8gv2pjby.js";
import"./chunk-pn23dh3d.js";
import"./chunk-rpdh02rm.js";
import"./chunk-j1wktfe2.js";
import"./chunk-fjtzfz1t.js";
import"./chunk-6hr7742d.js";
import"./chunk-xyg1sk2w.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-hem4f4gz.js";
import"./chunk-hqxp6b72.js";
import"./chunk-ccw8pse0.js";
import"./chunk-wsnxtggw.js";
import"./chunk-k8nwt8yq.js";
import"./chunk-vxbjzggp.js";
import"./chunk-d6h68rz1.js";
import"./chunk-8yvsnrkr.js";
import"./chunk-5mmhfbxb.js";
import"./chunk-s2t5anwv.js";
import"./chunk-ga1jkyqy.js";
import"./chunk-9hbhydvp.js";
import"./chunk-ck9r8hpf.js";
import"./chunk-k7hexw3v.js";
import"./chunk-trqrj23e.js";
import"./chunk-za3k6h2h.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-hjxqmtg5.js";
import"./chunk-bzyzrq0k.js";
import"./chunk-vwenx8ke.js";
import"./chunk-q2h79ncs.js";
import"./chunk-v4ypszbb.js";
import"./chunk-qfsn720k.js";
import"./chunk-7qx3xhv3.js";
import"./chunk-j9475b46.js";
import"./chunk-fdwabr8p.js";
import"./chunk-e4dsy4g1.js";
import"./chunk-326zehp8.js";
import"./chunk-kc67kt75.js";
import"./chunk-40t1d75v.js";
import"./chunk-dbts5q5p.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import"./chunk-q1vrhh0q.js";
import"./chunk-hn4w9pkj.js";
import {
  Dialog,
  ThemedBox_default,
  ThemedText,
  init_src,
  use_input_default
} from "./chunk-2g0ytd9d.js";
import {
  require_jsx_dev_runtime,
  require_react
} from "./chunk-de0qnnf7.js";
import"./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-92bjkrf2.js";
import"./chunk-10k5jfc5.js";
import"./chunk-n9g24mwe.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-hzmzwte2.js";
import"./chunk-pdvg91cg.js";
import"./chunk-c696122m.js";
import"./chunk-xbj5keyy.js";
import"./chunk-c1yc761e.js";
import"./chunk-c5g9shkw.js";
import"./chunk-aeysytks.js";
import"./chunk-s3hafnk3.js";
import"./chunk-kb3758f7.js";
import"./chunk-9h9k5vz3.js";
import"./chunk-xmpgmeb8.js";
import"./chunk-2kz09j2s.js";
import"./chunk-c0k7b0jw.js";
import"./chunk-pecy49yr.js";
import"./chunk-azbab59e.js";
import"./chunk-3nk9q8dr.js";
import {
  __esm,
  __toESM
} from "./chunk-hhsxm2yr.js";

// src/commands/autonomyPanel.tsx
function getAutonomyPanelBaseActionCountForTests() {
  return BASE_AUTONOMY_PANEL_ACTION_COUNT;
}
function AutonomyPanel({ onDone }) {
  useRegisterOverlay("autonomy-panel");
  const [selectedIndex, setSelectedIndex] = import_react.useState(0);
  const [flows, setFlows] = import_react.useState([]);
  import_react.useEffect(() => {
    let cancelled = false;
    listAutonomyFlows().then((items) => {
      if (!cancelled)
        setFlows(items.slice(0, 5));
    });
    return () => {
      cancelled = true;
    };
  }, []);
  const actions = import_react.useMemo(() => {
    const base = [
      {
        label: "Overview",
        description: "Show run and flow counts plus the latest automatic activity",
        run: () => getAutonomyStatusText()
      },
      {
        label: "Full deep status",
        description: "Print every local autonomy surface in one diagnostic report",
        run: () => getAutonomyStatusText({ deep: true })
      },
      {
        label: "Auto mode",
        description: "Check whether auto permission mode is available and why",
        run: () => getAutonomyDeepSectionText("auto-mode")
      },
      {
        label: "Runs summary",
        description: "Show queued/running/completed/failed run totals and latest run",
        run: () => getAutonomyDeepSectionText("runs")
      },
      {
        label: "Recent runs",
        description: "List recent autonomy run IDs, triggers, statuses, and prompts",
        run: () => getAutonomyCommandText("runs 10")
      },
      {
        label: "Flows summary",
        description: "Show managed flow totals across queued/running/waiting states",
        run: () => getAutonomyDeepSectionText("flows")
      },
      {
        label: "Recent flows",
        description: "List recent managed flow IDs, status, current step, and goal",
        run: () => getAutonomyCommandText("flows 10")
      },
      {
        label: "Cron",
        description: "Show scheduled autonomy jobs, durability, recurrence, and next run",
        run: () => getAutonomyDeepSectionText("cron")
      },
      {
        label: "Workflow runs",
        description: "Show persisted WorkflowTool runs and their current workflow step",
        run: () => getAutonomyDeepSectionText("workflow-runs")
      },
      {
        label: "Teams",
        description: "Show Agent Teams, teammate backends, activity, and open tasks",
        run: () => getAutonomyDeepSectionText("teams")
      },
      {
        label: "Pipes",
        description: "Show UDS/named-pipe and LAN registry for terminal messaging",
        run: () => getAutonomyDeepSectionText("pipes")
      },
      {
        label: "Runtime",
        description: "Show daemon state and live background or interactive sessions",
        run: () => getAutonomyDeepSectionText("runtime")
      },
      {
        label: "Remote Control",
        description: "Show bridge mode, base URL, token presence, and entitlement note",
        run: () => getAutonomyDeepSectionText("remote-control")
      },
      {
        label: "RemoteTrigger",
        description: "Show recent remote trigger audit records, failures, and latest call",
        run: () => getAutonomyDeepSectionText("remote-trigger")
      }
    ];
    const flowActions = flows.flatMap((flow) => {
      const shortId = flow.flowId.slice(0, 8);
      const items = [
        {
          label: `Flow ${shortId}`,
          description: `${flow.status}: ${flow.goal}`,
          run: () => getAutonomyCommandText(`flow ${flow.flowId}`)
        }
      ];
      if (flow.status === "waiting") {
        items.push({
          label: `Resume ${shortId}`,
          description: flow.currentStep ? `Resume waiting step: ${flow.currentStep}` : "Resume waiting flow",
          run: () => getAutonomyCommandText(`flow resume ${flow.flowId}`, {
            enqueueInMemory: true
          })
        });
      }
      if (flow.status === "queued" || flow.status === "running" || flow.status === "waiting" || flow.status === "blocked") {
        items.push({
          label: `Cancel ${shortId}`,
          description: `Cancel ${flow.status} flow`,
          run: () => getAutonomyCommandText(`flow cancel ${flow.flowId}`, {
            removeQueuedInMemory: true
          })
        });
      }
      return items;
    });
    return [...base, ...flowActions];
  }, [flows]);
  const selectCurrent = () => {
    const action = actions[selectedIndex];
    if (!action)
      return;
    action.run().then((result) => {
      onDone(result, { display: "system" });
    });
  };
  use_input_default((_input, key) => {
    if (key.upArrow) {
      setSelectedIndex((index) => Math.max(0, index - 1));
      return;
    }
    if (key.downArrow) {
      setSelectedIndex((index) => Math.min(actions.length - 1, index + 1));
      return;
    }
    if (key.return) {
      selectCurrent();
    }
  });
  return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Dialog, {
    title: "Autonomy",
    subtitle: `${actions.length} actions`,
    onCancel: () => onDone("Autonomy panel dismissed", { display: "system" }),
    color: "background",
    hideInputGuide: true,
    children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
      flexDirection: "column",
      children: [
        actions.map((action, index) => /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
          flexDirection: "row",
          children: [
            /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
              children: `${index === selectedIndex ? "\u203A" : " "} ${action.label}`.padEnd(ACTION_LABEL_COLUMN_WIDTH)
            }, undefined, false, undefined, this),
            /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
              dimColor: true,
              children: action.description
            }, undefined, false, undefined, this)
          ]
        }, `${action.label}-${index}`, true, undefined, this)),
        /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
          marginTop: 1,
          children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
            dimColor: true,
            children: "\u2191/\u2193 select \xB7 Enter run \xB7 Esc close"
          }, undefined, false, undefined, this)
        }, undefined, false, undefined, this)
      ]
    }, undefined, true, undefined, this)
  }, undefined, false, undefined, this);
}
async function call(onDone, _context, args) {
  const trimmed = args?.trim() ?? "";
  if (trimmed) {
    const result = await getAutonomyCommandText(trimmed, {
      enqueueInMemory: true,
      removeQueuedInMemory: true
    });
    onDone(result, { display: "system" });
    return null;
  }
  return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(AutonomyPanel, {
    onDone
  }, undefined, false, undefined, this);
}
var import_react, jsx_dev_runtime, BASE_AUTONOMY_PANEL_ACTION_COUNT = 14, ACTION_LABEL_COLUMN_WIDTH = 24;
var init_autonomyPanel = __esm(() => {
  init_src();
  init_src();
  init_overlayContext();
  init_autonomy();
  init_autonomyFlows();
  import_react = __toESM(require_react(), 1);
  jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
});
init_autonomyPanel();

export {
  getAutonomyPanelBaseActionCountForTests,
  call
};
