// @bun
import {
  getAutonomyCommandText,
  getAutonomyDeepSectionText,
  getAutonomyStatusText,
  init_autonomy
} from "./chunk-eqzp2kq5.js";
import"./chunk-q65hv45k.js";
import"./chunk-g2cvzj5j.js";
import"./chunk-s502dnzf.js";
import"./chunk-k49xc781.js";
import {
  init_autonomyFlows,
  init_overlayContext,
  listAutonomyFlows,
  useRegisterOverlay
} from "./chunk-4vz571bb.js";
import"./chunk-14p6wvsq.js";
import"./chunk-8hseq8b1.js";
import"./chunk-ddtxq6k5.js";
import"./chunk-28jd8qjx.js";
import"./chunk-djt39ze3.js";
import"./chunk-ptxteaeh.js";
import"./chunk-wd53a7m4.js";
import"./chunk-hms8ge0k.js";
import"./chunk-whpphypt.js";
import"./chunk-pht800m5.js";
import"./chunk-pjkqh1kq.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-qn6me9n1.js";
import"./chunk-qd3r2s2n.js";
import"./chunk-djzd7tef.js";
import"./chunk-gyhnpbkx.js";
import"./chunk-71sdcaq6.js";
import"./chunk-60gf7p5s.js";
import"./chunk-sj3d0nqx.js";
import"./chunk-9pk9rk2w.js";
import"./chunk-javpza6a.js";
import"./chunk-6v7bre98.js";
import"./chunk-24kv69g3.js";
import"./chunk-fcqebw9m.js";
import"./chunk-dnfd3c9s.js";
import"./chunk-15ezj4ww.js";
import"./chunk-1h284c6e.js";
import"./chunk-582g9yce.js";
import"./chunk-y3ztgztb.js";
import"./chunk-4spgkgr3.js";
import"./chunk-n8kbhswc.js";
import"./chunk-60fkafk2.js";
import"./chunk-fgbkrbk3.js";
import"./chunk-ssw61jfd.js";
import"./chunk-093ej2sf.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-nde5ym6a.js";
import"./chunk-k8wq4qsj.js";
import"./chunk-g7d3xx1p.js";
import"./chunk-3wrx2943.js";
import"./chunk-7p9kkh0f.js";
import"./chunk-qp8cgz66.js";
import"./chunk-1mg610h2.js";
import"./chunk-93hc149s.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-nnat9jw5.js";
import"./chunk-hqxp6b72.js";
import"./chunk-4jzkqgf1.js";
import"./chunk-33rd41ng.js";
import"./chunk-f257kqw9.js";
import"./chunk-w5hnghah.js";
import"./chunk-36twraxy.js";
import"./chunk-1bkvnj0y.js";
import"./chunk-akdpcc5p.js";
import"./chunk-7rrkrej7.js";
import"./chunk-6r0bxrh6.js";
import"./chunk-d6500tvx.js";
import"./chunk-jg4bw4hp.js";
import"./chunk-epvbnq43.js";
import"./chunk-tn2sx7j6.js";
import"./chunk-6tzyv21c.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-ch4pgvwq.js";
import"./chunk-99jc4tcw.js";
import"./chunk-fghczfqt.js";
import"./chunk-vwenx8ke.js";
import"./chunk-f86mwfyd.js";
import"./chunk-v4ypszbb.js";
import"./chunk-bk6ck5c2.js";
import"./chunk-ym6j0wv1.js";
import"./chunk-hjmatcgt.js";
import"./chunk-6mdh70q0.js";
import"./chunk-ch92ycde.js";
import"./chunk-e4dsy4g1.js";
import"./chunk-326zehp8.js";
import"./chunk-kc67kt75.js";
import"./chunk-40t1d75v.js";
import"./chunk-nt5dmk8q.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import"./chunk-0gp4q8aq.js";
import"./chunk-hn4w9pkj.js";
import {
  Dialog,
  ThemedBox_default,
  ThemedText,
  init_src,
  require_react,
  use_input_default
} from "./chunk-0r6npc3t.js";
import {
  require_jsx_runtime
} from "./chunk-gxyx8b8w.js";
import"./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-t0450ma3.js";
import"./chunk-0cqw3y8h.js";
import"./chunk-k1sw7km0.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-sc9ycxra.js";
import"./chunk-hhta0nge.js";
import"./chunk-8wsj9fff.js";
import"./chunk-m28vg9w4.js";
import"./chunk-f8prtxs3.js";
import"./chunk-41a6f2kv.js";
import"./chunk-c1yc761e.js";
import"./chunk-c5g9shkw.js";
import"./chunk-byd20vdq.js";
import"./chunk-kb3758f7.js";
import"./chunk-3j8w0rq8.js";
import"./chunk-tj0dzck2.js";
import"./chunk-aeysytks.js";
import"./chunk-ns1htxgd.js";
import"./chunk-ztqzmfx1.js";
import"./chunk-6k1rsk85.js";
import"./chunk-nxzx0ey9.js";
import"./chunk-yes1my80.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_runtime.jsx(Dialog, {
    title: "Autonomy",
    subtitle: `${actions.length} actions`,
    onCancel: () => onDone("Autonomy panel dismissed", { display: "system" }),
    color: "background",
    hideInputGuide: true,
    children: /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      flexDirection: "column",
      children: [
        actions.map((action, index) => /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
          flexDirection: "row",
          children: [
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              children: `${index === selectedIndex ? "\u203A" : " "} ${action.label}`.padEnd(ACTION_LABEL_COLUMN_WIDTH)
            }),
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              dimColor: true,
              children: action.description
            })
          ]
        }, `${action.label}-${index}`)),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedBox_default, {
          marginTop: 1,
          children: /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
            dimColor: true,
            children: "\u2191/\u2193 select \xB7 Enter run \xB7 Esc close"
          })
        })
      ]
    })
  });
}
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_runtime.jsx(AutonomyPanel, {
    onDone
  });
}
var import_react, jsx_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_runtime = __toESM(require_jsx_runtime(), 1);
});
init_autonomyPanel();

export {
  getAutonomyPanelBaseActionCountForTests,
  call
};

//# debugId=81A1E0B18A6D6E0964756E2164756E21
//# sourceMappingURL=chunk-tszt36gj.js.map
