// @bun
import {
  init_launchCommand,
  launchCommand
} from "./chunk-n2nc3x52.js";
import {
  TextInput,
  archiveStore,
  createStore1 as createStore,
  getEntry,
  init_TextInput,
  init_localValidate,
  init_multiStore,
  isValidKey,
  isValidStoreName,
  listEntries,
  listStores,
  setEntry
} 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/local-memory/LocalMemoryView.tsx
function LocalMemoryView(props) {
  if (props.mode === "list") {
    if (props.stores.length === 0) {
      return /* @__PURE__ */ jsx_runtime.jsx(ThemedBox_default, {
        children: /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          dimColor: true,
          children: "No memory stores found. Use /local-memory create <store> to create one."
        })
      });
    }
    return /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      flexDirection: "column",
      children: [
        /* @__PURE__ */ jsx_runtime.jsx(ThemedBox_default, {
          marginBottom: 1,
          children: /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
            bold: true,
            children: [
              "Local Memory Stores (",
              props.stores.length,
              ")"
            ]
          })
        }),
        props.stores.map((s) => /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
          children: [
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              children: " "
            }),
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              color: "success",
              children: "\u25C6"
            }),
            /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
              children: [
                " ",
                s
              ]
            })
          ]
        }, s))
      ]
    });
  }
  if (props.mode === "created") {
    return /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      children: [
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          color: "success",
          children: "\u2713"
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          children: " Store created: "
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          bold: true,
          children: props.store
        })
      ]
    });
  }
  if (props.mode === "stored") {
    return /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      children: [
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          color: "success",
          children: "\u2713"
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          children: " Stored entry "
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          bold: true,
          children: props.key
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          children: " in "
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          bold: true,
          children: props.store
        })
      ]
    });
  }
  if (props.mode === "fetched") {
    return /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      flexDirection: "column",
      children: [
        /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
          marginBottom: 1,
          children: [
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              bold: true,
              children: props.store
            }),
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              dimColor: true,
              children: "/"
            }),
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              bold: true,
              children: props.key
            })
          ]
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedBox_default, {
          children: /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
            children: props.value
          })
        })
      ]
    });
  }
  if (props.mode === "not-found") {
    return /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      children: [
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          color: "error",
          children: "Not found: "
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          bold: true,
          children: props.store
        }),
        props.key ? /* @__PURE__ */ jsx_runtime.jsxs(jsx_runtime.Fragment, {
          children: [
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              dimColor: true,
              children: "/"
            }),
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              bold: true,
              children: props.key
            })
          ]
        }) : null
      ]
    });
  }
  if (props.mode === "entries") {
    if (props.keys.length === 0) {
      return /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
        children: [
          /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
            dimColor: true,
            children: "No entries in "
          }),
          /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
            bold: true,
            children: props.store
          }),
          /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
            dimColor: true,
            children: [
              ". Use /local-memory store ",
              props.store,
              " <key> <value> to add one."
            ]
          })
        ]
      });
    }
    return /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      flexDirection: "column",
      children: [
        /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
          marginBottom: 1,
          children: [
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              bold: true,
              children: props.store
            }),
            /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
              dimColor: true,
              children: [
                " (",
                props.keys.length,
                " entries)"
              ]
            })
          ]
        }),
        props.keys.map((k) => /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
          children: [
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              children: " "
            }),
            /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              color: "success",
              children: "\xB7"
            }),
            /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
              children: [
                " ",
                k
              ]
            })
          ]
        }, k))
      ]
    });
  }
  if (props.mode === "archived") {
    return /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      children: [
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          color: "success",
          children: "\u2713"
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          children: " Archived store: "
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          bold: true,
          children: props.store
        }),
        /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
          dimColor: true,
          children: [
            " (renamed to ",
            props.store,
            ".archived)"
          ]
        })
      ]
    });
  }
  return /* @__PURE__ */ jsx_runtime.jsx(ThemedBox_default, {
    children: /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
      color: "error",
      children: [
        "Error: ",
        props.message
      ]
    })
  });
}
var jsx_runtime;
var init_LocalMemoryView = __esm(() => {
  init_src();
  jsx_runtime = __toESM(require_jsx_runtime(), 1);
});

// src/commands/local-memory/parseArgs.ts
function parseLocalMemoryArgs(args) {
  const trimmed = args.trim();
  if (trimmed === "" || trimmed === "list") {
    return { action: "list" };
  }
  const tokens = trimmed.split(/\s+/);
  const subCmd = tokens[0];
  if (subCmd === "list") {
    return { action: "list" };
  }
  if (subCmd === "create") {
    const store = tokens[1];
    if (!store) {
      return {
        action: "invalid",
        reason: `create requires a store name. ${USAGE}`
      };
    }
    return { action: "create", store };
  }
  if (subCmd === "store") {
    const store = tokens[1];
    const key = tokens[2];
    if (!store) {
      return {
        action: "invalid",
        reason: `store requires a store name. ${USAGE}`
      };
    }
    if (!key) {
      return { action: "invalid", reason: `store requires a key. ${USAGE}` };
    }
    const rest = tokens.slice(3).join(" ");
    if (!rest) {
      return { action: "invalid", reason: `store requires a value. ${USAGE}` };
    }
    return { action: "store", store, key, value: rest };
  }
  if (subCmd === "fetch") {
    const store = tokens[1];
    const key = tokens[2];
    if (!store) {
      return {
        action: "invalid",
        reason: `fetch requires a store name. ${USAGE}`
      };
    }
    if (!key) {
      return { action: "invalid", reason: `fetch requires a key. ${USAGE}` };
    }
    return { action: "fetch", store, key };
  }
  if (subCmd === "entries") {
    const store = tokens[1];
    if (!store) {
      return {
        action: "invalid",
        reason: `entries requires a store name. ${USAGE}`
      };
    }
    return { action: "entries", store };
  }
  if (subCmd === "archive") {
    const store = tokens[1];
    if (!store) {
      return {
        action: "invalid",
        reason: `archive requires a store name. ${USAGE}`
      };
    }
    return { action: "archive", store };
  }
  return {
    action: "invalid",
    reason: `Unknown sub-command "${subCmd}". ${USAGE}`
  };
}
var USAGE = "Usage: /local-memory list | create STORE | store STORE KEY VALUE | fetch STORE KEY | entries STORE | archive STORE";
var init_parseArgs = () => {};

// src/commands/local-memory/launchLocalMemory.tsx
function formatStoreList(stores) {
  if (stores.length === 0) {
    return "No memory stores found.";
  }
  return ["Local Memory Stores", ...stores.map((store) => `- ${store}`)].join(`
`);
}
function formatEntryList(store, keys) {
  if (keys.length === 0) {
    return `No entries in "${store}".`;
  }
  return [`Entries in "${store}"`, ...keys.map((key) => `- ${key}`)].join(`
`);
}
function LocalMemoryPanel({ onDone }) {
  const [step, setStep] = import_react.default.useState({ kind: "menu" });
  const [selectedIndex, setSelectedIndex] = import_react.default.useState(0);
  const [textValue, setTextValue] = import_react.default.useState("");
  const [cursorOffset, setCursorOffset] = import_react.default.useState(0);
  const [error, setError] = import_react.default.useState(null);
  const transition = import_react.default.useCallback((next) => {
    setStep(next);
    setTextValue("");
    setCursorOffset(0);
    setError(null);
  }, []);
  const closeWith = import_react.default.useCallback((msg) => onDone(msg, { display: "system" }), [onDone]);
  const runAction = import_react.default.useCallback((action, store, key, value, opts = {}) => {
    try {
      if (action === "list") {
        closeWith(formatStoreList(listStores()));
        return;
      }
      if (action === "about") {
        closeWith(USAGE2);
        return;
      }
      if (!store) {
        setError("Internal: missing store");
        return;
      }
      if (action === "create") {
        createStore(store);
        closeWith(`Store created: ${store}`);
        return;
      }
      if (action === "entries") {
        const keys = listEntries(store);
        closeWith(formatEntryList(store, keys));
        return;
      }
      if (action === "archive") {
        archiveStore(store);
        closeWith(`Archived store: ${store}`);
        return;
      }
      if (action === "fetch") {
        if (!key) {
          setError("Internal: missing key");
          return;
        }
        const v = getEntry(store, key);
        if (v === null) {
          closeWith(`Entry not found: ${store}/${key}`);
          return;
        }
        closeWith(`Entry fetched: ${store}/${key}

${v}`);
        return;
      }
      if (action === "store") {
        if (!key || value === undefined) {
          setError("Internal: missing key or value");
          return;
        }
        if (!opts.confirmedOverwrite && getEntry(store, key) !== null) {
          transition({
            kind: "confirm-overwrite",
            store,
            key,
            value
          });
          return;
        }
        setEntry(store, key, value);
        closeWith(`Stored ${store}/${key} (${value.length} chars)`);
        return;
      }
    } catch (e) {
      setError(e instanceof Error ? e.message : String(e));
    }
  }, [closeWith, transition]);
  use_input_default((input, key) => {
    if (step.kind !== "menu")
      return;
    if (key.upArrow) {
      setSelectedIndex((idx) => Math.max(0, idx - 1));
      return;
    }
    if (key.downArrow) {
      setSelectedIndex((idx) => Math.min(MENU.length - 1, idx + 1));
      return;
    }
    if (key.return) {
      const choice = MENU[selectedIndex];
      if (!choice)
        return;
      if (choice.kind === "list" || choice.kind === "about") {
        runAction(choice.kind, undefined, undefined, undefined);
        return;
      }
      transition({ kind: "collect-store", action: choice.kind });
      return;
    }
    const n = Number(input);
    if (Number.isInteger(n) && n >= 1 && n <= MENU.length) {
      setSelectedIndex(n - 1);
    }
  }, { isActive: step.kind === "menu" });
  use_input_default((input, key) => {
    if (step.kind !== "confirm-archive" && step.kind !== "confirm-overwrite") {
      return;
    }
    if (key.escape) {
      transition({ kind: "menu" });
      return;
    }
    const ch = input.toLowerCase();
    if (ch === "y" || key.return) {
      if (step.kind === "confirm-archive") {
        runAction("archive", step.store, undefined, undefined);
      } else {
        runAction("store", step.store, step.key, step.value, {
          confirmedOverwrite: true
        });
      }
    } else if (ch === "n") {
      transition({ kind: "menu" });
    }
  }, {
    isActive: step.kind === "confirm-archive" || step.kind === "confirm-overwrite"
  });
  use_input_default((_input, key) => {
    if (step.kind !== "collect-store" && step.kind !== "collect-key" && step.kind !== "collect-value") {
      return;
    }
    if (key.escape) {
      if (step.kind === "collect-value") {
        transition({
          kind: "collect-key",
          action: step.action,
          store: step.store
        });
        return;
      }
      if (step.kind === "collect-key") {
        transition({ kind: "collect-store", action: step.action });
        return;
      }
      transition({ kind: "menu" });
    }
  }, {
    isActive: step.kind === "collect-store" || step.kind === "collect-key" || step.kind === "collect-value"
  });
  if (step.kind === "menu") {
    return /* @__PURE__ */ jsx_runtime2.jsx(Dialog, {
      title: "Local Memory",
      subtitle: `${MENU.length} actions`,
      onCancel: () => closeWith("Local memory panel dismissed"),
      color: "background",
      hideInputGuide: true,
      children: /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
        flexDirection: "column",
        children: [
          MENU.map((m, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "row",
            children: [
              /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                children: `${i === selectedIndex ? "\u203A" : " "} ${m.label}`.padEnd(ACTION_LABEL_COLUMN_WIDTH)
              }),
              /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                dimColor: true,
                children: m.description
              })
            ]
          }, m.kind)),
          /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
            marginTop: 1,
            children: /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
              dimColor: true,
              children: "\u2191/\u2193 or 1-7 select \xB7 Enter run \xB7 Esc close"
            })
          })
        ]
      })
    });
  }
  if (step.kind === "confirm-archive") {
    return /* @__PURE__ */ jsx_runtime2.jsx(Dialog, {
      title: "Confirm Archive",
      onCancel: () => transition({ kind: "menu" }),
      color: "warning",
      hideInputGuide: true,
      children: /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
        flexDirection: "column",
        children: [
          /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
            children: [
              'Archive store "',
              step.store,
              '"? This renames it to *.archived.'
            ]
          }),
          /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
            marginTop: 1,
            children: /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
              dimColor: true,
              children: "y/Enter = archive \xB7 n/Esc = cancel"
            })
          })
        ]
      })
    });
  }
  if (step.kind === "confirm-overwrite") {
    return /* @__PURE__ */ jsx_runtime2.jsx(Dialog, {
      title: "Confirm Overwrite",
      onCancel: () => transition({ kind: "menu" }),
      color: "warning",
      hideInputGuide: true,
      children: /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
        flexDirection: "column",
        children: [
          /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
            children: [
              'Entry "',
              step.store,
              "/",
              step.key,
              '" already exists. Overwrite with new value (',
              step.value.length,
              " chars)?"
            ]
          }),
          /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
            marginTop: 1,
            children: /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
              dimColor: true,
              children: "y/Enter = overwrite \xB7 n/Esc = cancel"
            })
          })
        ]
      })
    });
  }
  const fieldLabel = step.kind === "collect-store" ? "STORE NAME" : step.kind === "collect-key" ? "KEY NAME" : "VALUE";
  const placeholder = step.kind === "collect-store" ? "e.g. my-notes" : step.kind === "collect-key" ? "e.g. todo-2026-05-08" : "free text";
  const validateAndAdvance = (raw) => {
    const trimmed = raw.trim();
    if (step.kind === "collect-store") {
      if (!trimmed) {
        setError("Store name required");
        return;
      }
      if (!isValidStoreName(trimmed)) {
        setError("Invalid store name (no /, \\, :, null byte, or leading dot; max 255 chars)");
        return;
      }
      if (step.action === "create" || step.action === "entries" || step.action === "archive") {
        if (step.action === "archive") {
          transition({ kind: "confirm-archive", store: trimmed });
        } else {
          runAction(step.action, trimmed, undefined, undefined);
        }
      } else {
        transition({
          kind: "collect-key",
          action: step.action,
          store: trimmed
        });
      }
      return;
    }
    if (step.kind === "collect-key") {
      if (!trimmed) {
        setError("Key required");
        return;
      }
      if (!isValidKey(trimmed)) {
        setError("Invalid key (allowed: letters/digits/._- only; no leading dot; not a Windows reserved name)");
        return;
      }
      if (step.action === "fetch") {
        runAction("fetch", step.store, trimmed, undefined);
      } else {
        transition({
          kind: "collect-value",
          action: "store",
          store: step.store,
          key: trimmed
        });
      }
      return;
    }
    if (step.kind === "collect-value") {
      runAction("store", step.store, step.key, raw);
    }
  };
  return /* @__PURE__ */ jsx_runtime2.jsx(Dialog, {
    title: `Local Memory \xB7 ${step.kind.replace("collect-", "").toUpperCase()}`,
    onCancel: () => transition({ kind: "menu" }),
    color: "background",
    hideInputGuide: true,
    children: /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
      flexDirection: "column",
      children: [
        /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
          children: /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
            dimColor: true,
            children: fieldLabel
          })
        }),
        /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
          children: [
            /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
              children: "> "
            }),
            /* @__PURE__ */ jsx_runtime2.jsx(TextInput, {
              value: textValue,
              onChange: (v) => {
                setTextValue(v);
                setError(null);
              },
              cursorOffset,
              onChangeCursorOffset: setCursorOffset,
              onSubmit: validateAndAdvance,
              placeholder,
              columns: 70,
              showCursor: true
            })
          ]
        }),
        error !== null && /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
          marginTop: 0,
          children: /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
            color: "warning",
            children: [
              "\u2717 ",
              error
            ]
          })
        }),
        /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
          marginTop: 1,
          children: /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
            dimColor: true,
            children: "Enter = next \xB7 Esc = back"
          })
        })
      ]
    })
  });
}
async function dispatchLocalMemory(parsed, onDone) {
  if (parsed.action === "list") {
    const stores = listStores();
    onDone(formatStoreList(stores), { display: "system" });
    return null;
  }
  if (parsed.action === "create") {
    const { store } = parsed;
    createStore(store);
    onDone(`Store created: ${store}`, { display: "system" });
    return null;
  }
  if (parsed.action === "store") {
    const { store, key, value } = parsed;
    setEntry(store, key, value);
    onDone(`Stored entry "${key}" in store "${store}".`, { display: "system" });
    return null;
  }
  if (parsed.action === "fetch") {
    const { store, key } = parsed;
    const value = getEntry(store, key);
    if (value === null) {
      onDone(`Entry not found: ${store}/${key}`, { display: "system" });
      return null;
    }
    onDone(`Entry fetched: ${store}/${key}
${value}`, { display: "system" });
    return null;
  }
  if (parsed.action === "entries") {
    const { store } = parsed;
    const keys = listEntries(store);
    onDone(formatEntryList(store, keys), { display: "system" });
    return null;
  }
  if (parsed.action === "archive") {
    const { store } = parsed;
    archiveStore(store);
    onDone(`Archived store: ${store}`, { display: "system" });
    return null;
  }
  onDone(USAGE2, { display: "system" });
  return null;
}
var import_react, jsx_runtime2, USAGE2 = "Usage: /local-memory list | create STORE | store STORE KEY VALUE | fetch STORE KEY | entries STORE | archive STORE", ACTION_LABEL_COLUMN_WIDTH = 26, MENU, callLocalMemoryDirect, callLocalMemory = async (onDone, context, args) => {
  if ((args ?? "").trim() === "") {
    return /* @__PURE__ */ jsx_runtime2.jsx(LocalMemoryPanel, {
      onDone
    });
  }
  return callLocalMemoryDirect(onDone, context, args);
};
var init_launchLocalMemory = __esm(() => {
  init_src();
  init_multiStore();
  init_localValidate();
  init_TextInput();
  init_LocalMemoryView();
  init_parseArgs();
  init_launchCommand();
  import_react = __toESM(require_react(), 1);
  jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
  MENU = [
    { kind: "list", label: "List", description: "Show all stores" },
    {
      kind: "create",
      label: "Create",
      description: "Create a new memory store"
    },
    {
      kind: "store",
      label: "Store",
      description: "Write an entry: store name + key + value"
    },
    {
      kind: "fetch",
      label: "Fetch",
      description: "Read an entry by store name + key"
    },
    {
      kind: "entries",
      label: "Entries",
      description: "List entry keys in a store"
    },
    {
      kind: "archive",
      label: "Archive",
      description: "Archive a store (rename to *.archived)"
    },
    {
      kind: "about",
      label: "About",
      description: "Show command syntax"
    }
  ];
  callLocalMemoryDirect = launchCommand({
    commandName: "local-memory",
    parseArgs: (raw) => {
      const result = parseLocalMemoryArgs(raw);
      if (result.action === "invalid") {
        return { action: "invalid", reason: `${USAGE2}
${result.reason}` };
      }
      return result;
    },
    dispatch: dispatchLocalMemory,
    View: LocalMemoryView,
    errorView: (msg) => import_react.default.createElement(LocalMemoryView, { mode: "error", message: msg })
  });
});
init_launchLocalMemory();

export {
  callLocalMemory
};

//# debugId=E9C224962698D56F64756E2164756E21
//# sourceMappingURL=chunk-5dcmpxrw.js.map
