@austinthesing/magic-shell 0.2.28 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tui.js CHANGED
@@ -33058,7 +33058,7 @@ var OPENROUTER_MODELS = [
33058
33058
  {
33059
33059
  id: "deepseek/deepseek-v4-flash:free",
33060
33060
  name: "DeepSeek V4 Flash (Free)",
33061
- description: "DeepSeek's fast open-source model on OpenRouter's free tier (rate-limited)",
33061
+ description: "Fast DeepSeek coding model on OpenRouter's free tier.",
33062
33062
  category: "fast",
33063
33063
  provider: "openrouter",
33064
33064
  contextLength: 1048576,
@@ -33067,7 +33067,7 @@ var OPENROUTER_MODELS = [
33067
33067
  {
33068
33068
  id: "deepseek/deepseek-v4-flash",
33069
33069
  name: "DeepSeek V4 Flash",
33070
- description: "DeepSeek's latest fast open-source model",
33070
+ description: "Fast DeepSeek coding model with a large context window.",
33071
33071
  category: "fast",
33072
33072
  provider: "openrouter",
33073
33073
  contextLength: 1048576,
@@ -33076,7 +33076,7 @@ var OPENROUTER_MODELS = [
33076
33076
  {
33077
33077
  id: "z-ai/glm-5.2",
33078
33078
  name: "GLM 5.2",
33079
- description: "Z.ai's latest fast GLM model",
33079
+ description: "Fast GLM model for low-cost command generation.",
33080
33080
  category: "fast",
33081
33081
  provider: "openrouter",
33082
33082
  contextLength: 202752,
@@ -33085,7 +33085,7 @@ var OPENROUTER_MODELS = [
33085
33085
  {
33086
33086
  id: "moonshotai/kimi-k2.7-code",
33087
33087
  name: "Kimi K2.7 Code",
33088
- description: "Moonshot's latest open-weight coding model",
33088
+ description: "Open-weight coding model for larger code tasks.",
33089
33089
  category: "smart",
33090
33090
  provider: "openrouter",
33091
33091
  contextLength: 262144,
@@ -33094,7 +33094,7 @@ var OPENROUTER_MODELS = [
33094
33094
  {
33095
33095
  id: "deepseek/deepseek-v4-pro",
33096
33096
  name: "DeepSeek V4 Pro",
33097
- description: "DeepSeek's latest high-context open-source model",
33097
+ description: "High-context DeepSeek model for larger code tasks.",
33098
33098
  category: "smart",
33099
33099
  provider: "openrouter",
33100
33100
  contextLength: 1048576,
@@ -33103,7 +33103,7 @@ var OPENROUTER_MODELS = [
33103
33103
  {
33104
33104
  id: "anthropic/claude-sonnet-4.6",
33105
33105
  name: "Claude Sonnet 4.6",
33106
- description: "Anthropic's latest Sonnet model",
33106
+ description: "Balanced Claude model for harder coding tasks.",
33107
33107
  category: "smart",
33108
33108
  provider: "openrouter",
33109
33109
  contextLength: 1e6,
@@ -33112,7 +33112,7 @@ var OPENROUTER_MODELS = [
33112
33112
  {
33113
33113
  id: "openai/gpt-5.5",
33114
33114
  name: "GPT 5.5",
33115
- description: "OpenAI's latest flagship GPT model",
33115
+ description: "Flagship GPT model for complex shell tasks.",
33116
33116
  category: "smart",
33117
33117
  provider: "openrouter",
33118
33118
  contextLength: 1050000,
@@ -33121,7 +33121,7 @@ var OPENROUTER_MODELS = [
33121
33121
  {
33122
33122
  id: "anthropic/claude-opus-4.8",
33123
33123
  name: "Claude Opus 4.8",
33124
- description: "Anthropic's latest Opus model",
33124
+ description: "Top Claude reasoning model for complex tasks.",
33125
33125
  category: "reasoning",
33126
33126
  provider: "openrouter",
33127
33127
  contextLength: 1e6,
@@ -33132,7 +33132,7 @@ var VERCEL_AI_GATEWAY_MODELS = [
33132
33132
  {
33133
33133
  id: "openai/gpt-5.5",
33134
33134
  name: "GPT 5.5",
33135
- description: "OpenAI's latest flagship GPT model",
33135
+ description: "Flagship GPT model for complex shell tasks.",
33136
33136
  category: "smart",
33137
33137
  provider: "vercel-ai-gateway",
33138
33138
  contextLength: 1050000,
@@ -33141,7 +33141,7 @@ var VERCEL_AI_GATEWAY_MODELS = [
33141
33141
  {
33142
33142
  id: "anthropic/claude-sonnet-4.6",
33143
33143
  name: "Claude Sonnet 4.6",
33144
- description: "Anthropic's latest Sonnet model",
33144
+ description: "Balanced Claude model for harder coding tasks.",
33145
33145
  category: "smart",
33146
33146
  provider: "vercel-ai-gateway",
33147
33147
  contextLength: 1e6,
@@ -33150,7 +33150,7 @@ var VERCEL_AI_GATEWAY_MODELS = [
33150
33150
  {
33151
33151
  id: "anthropic/claude-opus-4.8",
33152
33152
  name: "Claude Opus 4.8",
33153
- description: "Anthropic's latest Opus model",
33153
+ description: "Top Claude reasoning model for complex tasks.",
33154
33154
  category: "reasoning",
33155
33155
  provider: "vercel-ai-gateway",
33156
33156
  contextLength: 1e6,
@@ -33170,7 +33170,7 @@ var CLOUDFLARE_AI_GATEWAY_MODELS = [
33170
33170
  {
33171
33171
  id: "openai/gpt-5.5",
33172
33172
  name: "GPT 5.5",
33173
- description: "OpenAI's latest flagship GPT model through Cloudflare AI Gateway",
33173
+ description: "Flagship GPT model for complex shell tasks. through Cloudflare AI Gateway",
33174
33174
  category: "smart",
33175
33175
  provider: "cloudflare-ai-gateway",
33176
33176
  contextLength: 1050000,
@@ -33179,7 +33179,7 @@ var CLOUDFLARE_AI_GATEWAY_MODELS = [
33179
33179
  {
33180
33180
  id: "anthropic/claude-sonnet-4-6",
33181
33181
  name: "Claude Sonnet 4.6",
33182
- description: "Anthropic's latest Sonnet model through Cloudflare AI Gateway",
33182
+ description: "Balanced Claude model for harder coding tasks. through Cloudflare AI Gateway",
33183
33183
  category: "smart",
33184
33184
  provider: "cloudflare-ai-gateway",
33185
33185
  contextLength: 1e6,
@@ -33188,7 +33188,7 @@ var CLOUDFLARE_AI_GATEWAY_MODELS = [
33188
33188
  {
33189
33189
  id: "anthropic/claude-opus-4-8",
33190
33190
  name: "Claude Opus 4.8",
33191
- description: "Anthropic's latest Opus model through Cloudflare AI Gateway",
33191
+ description: "Top Claude reasoning model for complex tasks. through Cloudflare AI Gateway",
33192
33192
  category: "reasoning",
33193
33193
  provider: "cloudflare-ai-gateway",
33194
33194
  contextLength: 1e6,
@@ -33228,7 +33228,7 @@ var OPENCODE_ZEN_MODELS = [
33228
33228
  {
33229
33229
  id: "deepseek-v4-flash-free",
33230
33230
  name: "DeepSeek V4 Flash Free",
33231
- description: "DeepSeek's free fast open-source model (limited time)",
33231
+ description: "Free DeepSeek coding model with a large context window.",
33232
33232
  category: "fast",
33233
33233
  provider: "opencode-zen",
33234
33234
  zenApiType: "openai-compatible",
@@ -33238,7 +33238,7 @@ var OPENCODE_ZEN_MODELS = [
33238
33238
  {
33239
33239
  id: "gpt-5-nano",
33240
33240
  name: "GPT 5 Nano",
33241
- description: "OpenAI's lightweight GPT model",
33241
+ description: "Lowest-cost GPT for quick edits and simple commands.",
33242
33242
  category: "fast",
33243
33243
  provider: "opencode-zen",
33244
33244
  zenApiType: "openai-responses",
@@ -33248,7 +33248,7 @@ var OPENCODE_ZEN_MODELS = [
33248
33248
  {
33249
33249
  id: "claude-haiku-4-5",
33250
33250
  name: "Claude Haiku 4.5",
33251
- description: "Anthropic's latest fast model",
33251
+ description: "Fast Claude model for quick command generation.",
33252
33252
  category: "fast",
33253
33253
  provider: "opencode-zen",
33254
33254
  zenApiType: "anthropic",
@@ -33258,7 +33258,7 @@ var OPENCODE_ZEN_MODELS = [
33258
33258
  {
33259
33259
  id: "gemini-3.5-flash",
33260
33260
  name: "Gemini 3.5 Flash",
33261
- description: "Google's latest fast Gemini model",
33261
+ description: "Fast Gemini model with a large context window.",
33262
33262
  category: "fast",
33263
33263
  provider: "opencode-zen",
33264
33264
  zenApiType: "google",
@@ -33268,7 +33268,7 @@ var OPENCODE_ZEN_MODELS = [
33268
33268
  {
33269
33269
  id: "claude-sonnet-4-6",
33270
33270
  name: "Claude Sonnet 4.6",
33271
- description: "Anthropic's latest Sonnet model",
33271
+ description: "Balanced Claude model for harder coding tasks.",
33272
33272
  category: "smart",
33273
33273
  provider: "opencode-zen",
33274
33274
  zenApiType: "anthropic",
@@ -33278,7 +33278,7 @@ var OPENCODE_ZEN_MODELS = [
33278
33278
  {
33279
33279
  id: "gpt-5.5",
33280
33280
  name: "GPT 5.5",
33281
- description: "OpenAI's latest flagship GPT model",
33281
+ description: "Flagship GPT model for complex shell tasks.",
33282
33282
  category: "smart",
33283
33283
  provider: "opencode-zen",
33284
33284
  zenApiType: "openai-responses",
@@ -33288,7 +33288,7 @@ var OPENCODE_ZEN_MODELS = [
33288
33288
  {
33289
33289
  id: "claude-opus-4-8",
33290
33290
  name: "Claude Opus 4.8",
33291
- description: "Anthropic's latest Opus model",
33291
+ description: "Top Claude reasoning model for complex tasks.",
33292
33292
  category: "reasoning",
33293
33293
  provider: "opencode-zen",
33294
33294
  zenApiType: "anthropic",
@@ -76815,13 +76815,11 @@ function getApiKeyUrl(provider) {
76815
76815
  }
76816
76816
  var inputHintText;
76817
76817
  var helpBarText;
76818
- var modelSelector = null;
76819
- var providerSelector = null;
76820
- var slashCommandContainer = null;
76821
- var slashCommandSelector = null;
76822
76818
  var slashCommandMatches = [];
76823
76819
  var slashCommandSelectedIndex = 0;
76824
76820
  var slashCommandSyncQueued = false;
76821
+ var slashCommandExecuting = false;
76822
+ var slashCommandDismissedInput = null;
76825
76823
  var pendingMessageId = null;
76826
76824
  var awaitingConfirmation = false;
76827
76825
  function generateMessageId() {
@@ -76833,13 +76831,16 @@ function isFreeModel(model) {
76833
76831
  function costTierLabel(tier) {
76834
76832
  switch (tier) {
76835
76833
  case "free":
76836
- return "FREE";
76834
+ return "Free";
76837
76835
  case "lower-cost":
76838
- return "lower-cost";
76836
+ return "Lower Cost";
76839
76837
  case "premium":
76840
- return "premium";
76838
+ return "Premium";
76841
76839
  }
76842
76840
  }
76841
+ function getModelDisplayName(model) {
76842
+ return model.cost === "free" ? model.name.replace(/\s+Free$/i, "") : model.name;
76843
+ }
76843
76844
  async function main() {
76844
76845
  config2 = loadConfig();
76845
76846
  history = loadHistory();
@@ -76891,53 +76892,50 @@ async function showProviderSetup() {
76891
76892
  const options = [
76892
76893
  {
76893
76894
  name: "OpenCode Zen (Recommended)",
76894
- description: "Curated models optimized for coding. Has free models!",
76895
+ description: "Curated coding models with a generous free tier.",
76895
76896
  value: "opencode-zen"
76896
76897
  },
76897
76898
  {
76898
76899
  name: "OpenRouter",
76899
- description: "Access to many models from various providers",
76900
+ description: "Broad model catalog across major providers.",
76900
76901
  value: "openrouter"
76901
76902
  },
76902
76903
  {
76903
76904
  name: "Vercel AI Gateway",
76904
- description: "Unified model gateway using AI_GATEWAY_API_KEY",
76905
+ description: "Vercel-hosted gateway for managed model access.",
76905
76906
  value: "vercel-ai-gateway"
76906
76907
  },
76907
76908
  {
76908
76909
  name: "Cloudflare AI Gateway",
76909
- description: "Cloudflare gateway for provider and Workers AI models",
76910
+ description: "Cloudflare gateway for provider and Workers AI routing.",
76910
76911
  value: "cloudflare-ai-gateway"
76911
76912
  },
76912
76913
  {
76913
76914
  name: "Cloudflare Workers AI",
76914
- description: "Cloudflare-hosted models via Workers AI",
76915
+ description: "Cloudflare-hosted models with direct Workers AI access.",
76915
76916
  value: "workers-ai"
76916
76917
  }
76917
76918
  ];
76918
- providerSelector = new SelectRenderable(renderer, {
76919
- id: "provider-select",
76920
- width: 60,
76921
- height: 10,
76919
+ let providerSetupModal = null;
76920
+ providerSetupModal = openModalList({
76921
+ containerId: "provider-setup-container",
76922
+ selectorId: "provider-select",
76923
+ title: "Choose Provider",
76924
+ width: 65,
76922
76925
  options,
76923
- backgroundColor: "#1e293b",
76924
- focusedBackgroundColor: "#1e293b",
76925
- selectedBackgroundColor: "#334155",
76926
- textColor: "#e2e8f0",
76927
- selectedTextColor: "#60a5fa",
76928
- descriptionColor: "#64748b",
76929
- selectedDescriptionColor: "#94a3b8",
76930
- showDescription: true,
76931
- wrapSelection: true
76932
- });
76933
- container.add(providerSelector);
76934
- providerSelector.on(SelectRenderableEvents.ITEM_SELECTED, async (_2, option) => {
76935
- const provider = option.value;
76936
- config2.provider = provider;
76937
- saveConfig(config2);
76938
- renderer.root.remove("setup-container");
76939
- providerSelector = null;
76940
- await showApiKeyInput(provider);
76926
+ onSelect: async (_2, option) => {
76927
+ const provider = option.value;
76928
+ config2.provider = provider;
76929
+ saveConfig(config2);
76930
+ providerSetupModal?.close();
76931
+ providerSetupModal = null;
76932
+ renderer.root.remove("setup-container");
76933
+ await showApiKeyInput(provider, {
76934
+ onCancel: () => {
76935
+ showProviderSetup();
76936
+ }
76937
+ });
76938
+ }
76941
76939
  });
76942
76940
  const hint = new TextRenderable(renderer, {
76943
76941
  id: "setup-hint",
@@ -76946,76 +76944,39 @@ ${fg("#64748b")("Use arrow keys to select | Enter to confirm | Ctrl+C to exit")}
76946
76944
  marginTop: 1
76947
76945
  });
76948
76946
  container.add(hint);
76949
- renderer.keyInput.on("keypress", (key) => {
76950
- if (key.ctrl && key.name === "c") {
76951
- renderer.destroy();
76952
- process.exit(0);
76953
- }
76954
- });
76955
- providerSelector.focus();
76956
76947
  }
76957
- async function showApiKeyInput(provider) {
76958
- const container = new BoxRenderable(renderer, {
76959
- id: "apikey-container",
76960
- flexDirection: "column",
76961
- padding: 2,
76962
- width: "100%",
76963
- height: "100%"
76964
- });
76965
- renderer.root.add(container);
76966
- const title = new TextRenderable(renderer, {
76967
- id: "apikey-title",
76968
- content: t`${bold(fg("#60a5fa")(`${getProviderDisplayName(provider)} Setup`))}`,
76969
- marginBottom: 1
76970
- });
76971
- container.add(title);
76948
+ async function showApiKeyInput(provider, options) {
76949
+ if (apiKeyModal)
76950
+ return;
76951
+ apiKeyModalOnCancel = options?.onCancel ?? null;
76972
76952
  const url2 = getApiKeyUrl(provider);
76973
- const instructions = new TextRenderable(renderer, {
76974
- id: "apikey-instructions",
76975
- content: t`Get your API key from: ${fg("#22c55e")(url2)}
76976
-
76977
- Enter your API key below:`,
76978
- marginBottom: 1
76979
- });
76980
- container.add(instructions);
76981
- const input = new InputRenderable(renderer, {
76982
- id: "api-key-input",
76983
- width: 70,
76984
- placeholder: provider === "openrouter" ? "sk-or-v1-..." : "API key or token",
76985
- backgroundColor: "#1e293b",
76986
- focusedBackgroundColor: "#334155",
76987
- textColor: "#f8fafc",
76988
- cursorColor: "#60a5fa"
76989
- });
76990
- container.add(input);
76991
- if (provider === "opencode-zen") {
76992
- const freeNote = new TextRenderable(renderer, {
76993
- id: "free-note",
76994
- content: t`
76995
- ${fg("#22c55e")("Tip:")} OpenCode Zen has free models like Kimi K2.6 and DeepSeek V4 Flash!`,
76996
- marginTop: 1
76997
- });
76998
- container.add(freeNote);
76999
- }
77000
- const hint = new TextRenderable(renderer, {
77001
- id: "apikey-hint",
77002
- content: t`
77003
- ${fg("#64748b")("Press Enter to save | Ctrl+C to exit")}`,
77004
- marginTop: 1
77005
- });
77006
- container.add(hint);
77007
- input.on(InputRenderableEvents.ENTER, (value) => {
77008
- if (value.trim()) {
77009
- setApiKey(provider, value.trim());
76953
+ const extraText = provider === "opencode-zen" ? "Tip: OpenCode Zen has free models like Kimi K2.6 and DeepSeek V4 Flash!" : undefined;
76954
+ apiKeyModal = openInputModal({
76955
+ containerId: "apikey-modal",
76956
+ title: `${getProviderDisplayName(provider)} Setup`,
76957
+ width: 72,
76958
+ height: provider === "opencode-zen" ? 13 : 11,
76959
+ placeholder: provider === "openrouter" ? "API key or token" : "API token",
76960
+ description: [
76961
+ `Get your API key from: ${url2}`,
76962
+ "",
76963
+ "Enter your API key below:"
76964
+ ].join(`
76965
+ `),
76966
+ extraText,
76967
+ onSubmit: (value) => {
76968
+ const trimmed = value.trim();
76969
+ if (!trimmed)
76970
+ return;
76971
+ setApiKey(provider, trimmed);
77010
76972
  const providerModels = getProviderModels(provider);
77011
76973
  currentModel = providerModels.find((m2) => !m2.disabled) || providerModels[0] || OPENCODE_ZEN_MODELS[0];
77012
76974
  config2.defaultModel = currentModel.id;
77013
76975
  saveConfig(config2);
77014
- renderer.root.remove("apikey-container");
76976
+ closeApiKeyModal();
77015
76977
  createMainUI();
77016
76978
  }
77017
76979
  });
77018
- input.focus();
77019
76980
  }
77020
76981
  function createMainUI() {
77021
76982
  const theme = getTheme();
@@ -77106,6 +77067,10 @@ function createMainUI() {
77106
77067
  { name: "j", ctrl: true, action: "newline" }
77107
77068
  ],
77108
77069
  onSubmit: () => {
77070
+ if (slashCommandModal && slashCommandMatches.length > 0) {
77071
+ executeSelectedSlashCommand();
77072
+ return;
77073
+ }
77109
77074
  const value = inputField.editBuffer.getText();
77110
77075
  handleInput(value);
77111
77076
  }
@@ -77116,7 +77081,7 @@ function createMainUI() {
77116
77081
  content: getInputHintContent(),
77117
77082
  marginTop: 1
77118
77083
  });
77119
- inputContainer.add(inputHintText);
77084
+ mainContainer.add(inputHintText);
77120
77085
  helpBarText = new TextRenderable(renderer, {
77121
77086
  id: "help-bar-text",
77122
77087
  content: getHelpBarContent(),
@@ -77142,7 +77107,7 @@ function getHelpBarContent() {
77142
77107
  if (awaitingConfirmation) {
77143
77108
  return t`${fg(theme.colors.warning)(">>> Cmd+Enter or Enter to execute <<<")} ${fg(theme.colors.textMuted)("|")} ${fg(theme.colors.error)("Esc")}${fg(theme.colors.textMuted)(" Cancel")} ${fg(theme.colors.primary)("e")}${fg(theme.colors.textMuted)(" Edit")} ${fg(theme.colors.primary)("c")}${fg(theme.colors.textMuted)(" Copy")}`;
77144
77109
  }
77145
- return t`${fg(theme.colors.primary)("Ctrl+P")}${fg(theme.colors.textMuted)(" Commands")} ${fg(theme.colors.primary)("Ctrl+T")}${fg(theme.colors.textMuted)(" Think")} ${fg(theme.colors.primary)("Ctrl+C")}${fg(theme.colors.textMuted)(" Exit")} ${fg(theme.colors.primary)("Esc")}${fg(theme.colors.textMuted)(" Cancel")}`;
77110
+ return t`${fg(theme.colors.primary)("Ctrl+P")}${fg(theme.colors.textMuted)(" Commands")} ${fg(theme.colors.primary)("Ctrl+T")}${fg(theme.colors.textMuted)(" Think")} ${fg(theme.colors.primary)("Ctrl+Y")}${fg(theme.colors.textMuted)(" Safety")} ${fg(theme.colors.primary)("Ctrl+C")}${fg(theme.colors.textMuted)(" Exit")} ${fg(theme.colors.primary)("Esc")}${fg(theme.colors.textMuted)(" Cancel")}`;
77146
77111
  }
77147
77112
  function getInputHintContent() {
77148
77113
  const theme = getTheme();
@@ -77434,27 +77399,18 @@ function refreshThemeColors() {
77434
77399
  if (inputHintText) {
77435
77400
  inputHintText.content = getInputHintContent();
77436
77401
  }
77437
- if (slashCommandContainer) {
77438
- slashCommandContainer.borderColor = theme.colors.border;
77439
- slashCommandContainer.backgroundColor = theme.colors.backgroundPanel;
77440
- }
77441
- if (slashCommandSelector) {
77442
- slashCommandSelector.selectedBackgroundColor = theme.colors.backgroundElement;
77443
- slashCommandSelector.textColor = theme.colors.text;
77444
- slashCommandSelector.selectedTextColor = theme.colors.primary;
77445
- slashCommandSelector.descriptionColor = theme.colors.textMuted;
77446
- slashCommandSelector.selectedDescriptionColor = theme.colors.textMuted;
77447
- }
77448
77402
  }
77449
77403
  async function handleInput(value) {
77450
77404
  const input = value.trim();
77451
77405
  if (!input)
77452
77406
  return;
77453
- inputField.setText("");
77454
- closeSlashCommandMenu();
77455
77407
  if (input.startsWith("/") && await tryHandleSlashCommand(input)) {
77408
+ inputField.setText("");
77409
+ closeSlashCommandMenu();
77456
77410
  return;
77457
77411
  }
77412
+ inputField.setText("");
77413
+ closeSlashCommandMenu();
77458
77414
  if (input.startsWith("!")) {
77459
77415
  await handleSpecialCommand(input);
77460
77416
  return;
@@ -77466,13 +77422,32 @@ async function handleInput(value) {
77466
77422
  }
77467
77423
  await translateAndProcess(input);
77468
77424
  }
77425
+ async function executeSelectedSlashCommand() {
77426
+ if (slashCommandExecuting || !slashCommandModal || slashCommandMatches.length === 0)
77427
+ return;
77428
+ slashCommandExecuting = true;
77429
+ try {
77430
+ const selected = slashCommandMatches[Math.min(slashCommandSelectedIndex, slashCommandMatches.length - 1)];
77431
+ inputField.setText("");
77432
+ closeSlashCommandMenu();
77433
+ await selected.action();
77434
+ } finally {
77435
+ slashCommandExecuting = false;
77436
+ }
77437
+ }
77469
77438
  async function tryHandleSlashCommand(input) {
77470
77439
  if (!input.startsWith("/"))
77471
77440
  return false;
77472
- const slashBody = input.slice(1).trim();
77441
+ const slashBody = input.slice(1).trim().toLowerCase();
77473
77442
  if (!slashBody.includes(" ") && slashCommandMatches.length > 0) {
77474
77443
  const selected = slashCommandMatches[Math.min(slashCommandSelectedIndex, slashCommandMatches.length - 1)];
77475
- await handleSpecialCommand(`/${selected.slash}`);
77444
+ const exactMatch = slashCommandMatches.find((cmd) => cmd.slash === slashBody);
77445
+ await (exactMatch ?? selected).action();
77446
+ return true;
77447
+ }
77448
+ const exactCommand = getSlashCommands().find((cmd) => cmd.slash === slashBody);
77449
+ if (exactCommand) {
77450
+ await exactCommand.action();
77476
77451
  return true;
77477
77452
  }
77478
77453
  await handleSpecialCommand(input);
@@ -77630,7 +77605,10 @@ async function handleSpecialCommand(input) {
77630
77605
  break;
77631
77606
  case "thinking":
77632
77607
  case "think":
77633
- cycleThinkingLevel();
77608
+ showThinkingSelector();
77609
+ break;
77610
+ case "safety":
77611
+ showSafetySelector();
77634
77612
  break;
77635
77613
  case "config":
77636
77614
  await showConfig();
@@ -77663,7 +77641,8 @@ function clearChat() {
77663
77641
  function showHelp() {
77664
77642
  const helpText = `Shortcuts:
77665
77643
  Ctrl+P Commands
77666
- Ctrl+T Cycle thinking level (low/medium/high/off)
77644
+ Ctrl+T Select thinking level
77645
+ Ctrl+Y Select safety level
77667
77646
  Ctrl+C Exit magic-shell
77668
77647
  Ctrl+D Exit magic-shell
77669
77648
  Esc Cancel / Close popup
@@ -77677,7 +77656,8 @@ Q Exit
77677
77656
  Commands (type ! or / followed by):
77678
77657
  help Show this help models Change model
77679
77658
  provider Switch provider themes Change theme
77680
- dry Toggle dry-run thinking Cycle thinking
77659
+ dry Toggle dry-run safety Select safety
77660
+ thinking Select thinking
77681
77661
  config Show config history Show history
77682
77662
  clear Clear chat exit Exit
77683
77663
 
@@ -77741,29 +77721,14 @@ ${lines.join(`
77741
77721
  `)}`);
77742
77722
  }
77743
77723
  async function switchProvider() {
77744
- const container = new BoxRenderable(renderer, {
77745
- id: "provider-selector-container",
77746
- position: "absolute",
77747
- left: 2,
77748
- top: 4,
77749
- width: 65,
77750
- height: 15,
77751
- backgroundColor: "#1e293b",
77752
- border: true,
77753
- borderColor: "#60a5fa",
77754
- borderStyle: "single",
77755
- title: "Switch Provider",
77756
- titleAlignment: "center",
77757
- zIndex: 100,
77758
- padding: 1
77759
- });
77760
- renderer.root.add(container);
77724
+ if (providerModal)
77725
+ return;
77761
77726
  const providers = [
77762
- { provider: "opencode-zen", description: "Curated models optimized for coding. Has free models!" },
77763
- { provider: "openrouter", description: "Access to many models from various providers" },
77764
- { provider: "vercel-ai-gateway", description: "Unified model gateway using AI_GATEWAY_API_KEY" },
77765
- { provider: "cloudflare-ai-gateway", description: "Cloudflare gateway for provider and Workers AI models" },
77766
- { provider: "workers-ai", description: "Cloudflare-hosted models via Workers AI" }
77727
+ { provider: "opencode-zen", description: "Curated coding models with a generous free tier." },
77728
+ { provider: "openrouter", description: "Broad model catalog across major providers." },
77729
+ { provider: "vercel-ai-gateway", description: "Vercel-hosted gateway for managed model access." },
77730
+ { provider: "cloudflare-ai-gateway", description: "Cloudflare gateway for provider and Workers AI routing." },
77731
+ { provider: "workers-ai", description: "Cloudflare-hosted models with direct Workers AI access." }
77767
77732
  ];
77768
77733
  const options = await Promise.all(providers.map(async ({ provider, description }) => {
77769
77734
  const key = await getApiKey(provider);
@@ -77773,207 +77738,178 @@ async function switchProvider() {
77773
77738
  value: provider
77774
77739
  };
77775
77740
  }));
77776
- const selector = new SelectRenderable(renderer, {
77777
- id: "provider-switch-select",
77778
- width: "100%",
77779
- height: 9,
77741
+ providerModal = openModalList({
77742
+ containerId: "provider-selector-container",
77743
+ selectorId: "provider-switch-select",
77744
+ title: "Switch Provider",
77745
+ width: 65,
77780
77746
  options,
77781
- backgroundColor: "transparent",
77782
- focusedBackgroundColor: "transparent",
77783
- selectedBackgroundColor: "#334155",
77784
- textColor: "#e2e8f0",
77785
- selectedTextColor: "#60a5fa",
77786
- descriptionColor: "#64748b",
77787
- selectedDescriptionColor: "#94a3b8",
77788
- showDescription: true,
77789
- wrapSelection: true
77790
- });
77791
- container.add(selector);
77792
- const closeSelector = () => {
77793
- renderer.root.remove("provider-selector-container");
77794
- inputField.focus();
77795
- };
77796
- selector.on(SelectRenderableEvents.ITEM_SELECTED, async (_2, option) => {
77797
- const newProvider = option.value;
77798
- const existingKey = await getApiKey(newProvider);
77799
- if (existingKey) {
77800
- config2.provider = newProvider;
77801
- const models = getProviderModels(newProvider);
77802
- currentModel = models.find((m2) => m2.id === config2.defaultModel) || models[0];
77803
- config2.defaultModel = currentModel.id;
77804
- saveConfig(config2);
77805
- statusBarText.content = getStatusBarContent();
77806
- closeSelector();
77807
- const providerName = getProviderDisplayName(newProvider);
77808
- addSystemMessage(`Switched to ${providerName}. Model: ${currentModel.name}`);
77809
- } else {
77810
- closeSelector();
77811
- renderer.root.remove("main-container");
77812
- await showApiKeyInput(newProvider);
77747
+ selectedIndex: Math.max(0, providers.findIndex(({ provider }) => provider === config2.provider)),
77748
+ onSelect: async (_2, option) => {
77749
+ const newProvider = option.value;
77750
+ const existingKey = await getApiKey(newProvider);
77751
+ if (existingKey) {
77752
+ config2.provider = newProvider;
77753
+ const models = getProviderModels(newProvider);
77754
+ currentModel = models.find((m2) => m2.id === config2.defaultModel) || models[0];
77755
+ config2.defaultModel = currentModel.id;
77756
+ saveConfig(config2);
77757
+ statusBarText.content = getStatusBarContent();
77758
+ closeProviderModal();
77759
+ const providerName = getProviderDisplayName(newProvider);
77760
+ addSystemMessage(`Switched to ${providerName}. Model: ${currentModel.name}`);
77761
+ } else {
77762
+ closeProviderModal();
77763
+ await showApiKeyInput(newProvider);
77764
+ }
77813
77765
  }
77814
77766
  });
77815
- const escHandler = (key) => {
77816
- if (key.name === "escape") {
77817
- closeSelector();
77818
- renderer.keyInput.off("keypress", escHandler);
77819
- }
77820
- };
77821
- renderer.keyInput.on("keypress", escHandler);
77822
- selector.focus();
77823
77767
  }
77824
77768
  function showModelSelector() {
77825
- if (modelSelector) {
77769
+ if (modelModal)
77826
77770
  return;
77827
- }
77828
- const container = new BoxRenderable(renderer, {
77829
- id: "model-selector-container",
77830
- position: "absolute",
77831
- left: 2,
77832
- top: 4,
77833
- width: 75,
77834
- height: 22,
77835
- backgroundColor: "#1e293b",
77836
- border: true,
77837
- borderColor: "#60a5fa",
77838
- borderStyle: "single",
77839
- title: `Select Model (${getProviderDisplayName(config2.provider)})`,
77840
- titleAlignment: "center",
77841
- zIndex: 100,
77842
- padding: 1
77843
- });
77844
- renderer.root.add(container);
77845
77771
  const allModels = getProviderModels(config2.provider);
77846
77772
  const availableModels = allModels.filter((m2) => !m2.disabled);
77847
77773
  const sortedModels = sortModelsByCost(availableModels);
77848
77774
  const customModels = getCustomModels().sort((a, b2) => a.name.localeCompare(b2.name));
77849
77775
  const options = [
77850
77776
  ...sortedModels.map((model) => ({
77851
- name: `${model.name} [${costTierLabel(model.cost)}]`,
77777
+ name: `${getModelDisplayName(model)} [${costTierLabel(model.cost)}]`,
77852
77778
  description: model.description,
77853
77779
  value: model
77854
77780
  })),
77855
77781
  ...customModels.map((model) => ({
77856
- name: `${model.name} [custom]`,
77782
+ name: `${model.name} [Custom]`,
77857
77783
  description: `${model.baseUrl} - ${model.modelId}`,
77858
77784
  value: model
77859
77785
  }))
77860
77786
  ];
77861
- modelSelector = new SelectRenderable(renderer, {
77862
- id: "model-select",
77863
- width: "100%",
77864
- height: 18,
77787
+ modelModal = openModalList({
77788
+ containerId: "model-selector-container",
77789
+ selectorId: "model-select",
77790
+ title: `Select Model (${getProviderDisplayName(config2.provider)})`,
77791
+ width: 75,
77865
77792
  options,
77866
- backgroundColor: "transparent",
77867
- focusedBackgroundColor: "transparent",
77868
- selectedBackgroundColor: "#334155",
77869
- textColor: "#e2e8f0",
77870
- selectedTextColor: "#60a5fa",
77871
- descriptionColor: "#64748b",
77872
- selectedDescriptionColor: "#94a3b8",
77873
- showDescription: true,
77874
77793
  showScrollIndicator: true,
77875
- wrapSelection: true
77876
- });
77877
- container.add(modelSelector);
77878
- modelSelector.on(SelectRenderableEvents.ITEM_SELECTED, (_2, option) => {
77879
- currentModel = option.value;
77880
- config2.defaultModel = currentModel.id;
77881
- saveConfig(config2);
77882
- statusBarText.content = getStatusBarContent();
77883
- renderer.root.remove("model-selector-container");
77884
- modelSelector = null;
77885
- inputField.focus();
77886
- const isCustom = isCustomModel(currentModel);
77887
- const freeBadge = isFreeModel(currentModel) ? " (FREE)" : "";
77888
- const customBadge = isCustom ? " (custom)" : "";
77889
- addSystemMessage(`Model changed to ${currentModel.name}${freeBadge}${customBadge}`);
77794
+ selectedIndex: Math.max(0, options.findIndex((option) => option.value.id === currentModel.id)),
77795
+ onSelect: (_2, option) => {
77796
+ currentModel = option.value;
77797
+ config2.defaultModel = currentModel.id;
77798
+ saveConfig(config2);
77799
+ statusBarText.content = getStatusBarContent();
77800
+ closeModelModal();
77801
+ const isCustom = isCustomModel(currentModel);
77802
+ const freeBadge = isFreeModel(currentModel) ? " (FREE)" : "";
77803
+ const customBadge = isCustom ? " (custom)" : "";
77804
+ addSystemMessage(`Model changed to ${currentModel.name}${freeBadge}${customBadge}`);
77805
+ }
77890
77806
  });
77891
- modelSelector.focus();
77892
77807
  }
77893
- var themeSelector = null;
77894
77808
  function showThemeSelector() {
77895
- if (themeSelector) {
77809
+ if (themeModal)
77896
77810
  return;
77897
- }
77898
77811
  const currentTheme2 = getTheme();
77899
- const themeContainerWidth = 45;
77900
- const terminalWidth = process.stdout.columns || 80;
77901
- const themeContainerLeft = Math.max(2, Math.floor((terminalWidth - themeContainerWidth) / 2));
77902
- const container = new BoxRenderable(renderer, {
77903
- id: "theme-selector-container",
77904
- position: "absolute",
77905
- left: themeContainerLeft,
77906
- top: 4,
77907
- width: themeContainerWidth,
77908
- height: themeNames.length + 4,
77909
- backgroundColor: currentTheme2.colors.backgroundPanel,
77910
- border: true,
77911
- borderColor: currentTheme2.colors.primary,
77912
- borderStyle: "single",
77913
- title: "Select Theme",
77914
- titleAlignment: "center",
77915
- zIndex: 100,
77916
- padding: 1
77917
- });
77918
- renderer.root.add(container);
77919
77812
  const options = themeNames.map((name24) => ({
77920
77813
  name: name24 === currentTheme2.name ? `${name24} (current)` : name24,
77921
77814
  description: "",
77922
77815
  value: name24
77923
77816
  }));
77924
- themeSelector = new SelectRenderable(renderer, {
77925
- id: "theme-select",
77926
- width: "100%",
77927
- height: themeNames.length + 2,
77817
+ themeModal = openModalList({
77818
+ containerId: "theme-selector-container",
77819
+ selectorId: "theme-select",
77820
+ title: "Select Theme",
77821
+ width: 45,
77928
77822
  options,
77929
- backgroundColor: "transparent",
77930
- focusedBackgroundColor: "transparent",
77931
- selectedBackgroundColor: currentTheme2.colors.backgroundElement,
77932
- textColor: currentTheme2.colors.text,
77933
- selectedTextColor: currentTheme2.colors.primary,
77934
- descriptionColor: currentTheme2.colors.textMuted,
77935
- selectedDescriptionColor: currentTheme2.colors.textMuted,
77936
77823
  showDescription: false,
77937
- wrapSelection: true
77938
- });
77939
- container.add(themeSelector);
77940
- themeSelector.on(SelectRenderableEvents.ITEM_SELECTED, (_2, option) => {
77941
- const themeName = option.value;
77942
- setTheme(themeName);
77943
- renderer.root.remove("theme-selector-container");
77944
- themeSelector = null;
77945
- refreshThemeColors();
77946
- addSystemMessage(`Theme changed to ${themeName}`);
77947
- inputField.focus();
77824
+ selectedIndex: Math.max(0, themeNames.findIndex((name24) => name24 === currentTheme2.name)),
77825
+ onSelect: (_2, option) => {
77826
+ const themeName = option.value;
77827
+ setTheme(themeName);
77828
+ closeThemeModal();
77829
+ refreshThemeColors();
77830
+ addSystemMessage(`Theme changed to ${themeName}`);
77831
+ }
77948
77832
  });
77949
- const escHandler = (key) => {
77950
- if (key.name === "escape") {
77951
- renderer.root.remove("theme-selector-container");
77952
- themeSelector = null;
77953
- inputField.focus();
77954
- renderer.keyInput.off("keypress", escHandler);
77833
+ }
77834
+ function showSafetySelector() {
77835
+ if (safetyModal)
77836
+ return;
77837
+ const levels = ["strict", "moderate", "relaxed"];
77838
+ const descriptions = {
77839
+ strict: "Confirm every potentially dangerous command.",
77840
+ moderate: "Confirm high and critical risk commands.",
77841
+ relaxed: "Only confirm critical risk commands."
77842
+ };
77843
+ safetyModal = openModalList({
77844
+ containerId: "safety-selector-container",
77845
+ selectorId: "safety-select",
77846
+ title: "Safety Level",
77847
+ width: 58,
77848
+ options: levels.map((level) => ({
77849
+ name: level === config2.safetyLevel ? `${level} (current)` : level,
77850
+ description: descriptions[level],
77851
+ value: level
77852
+ })),
77853
+ selectedIndex: Math.max(0, levels.findIndex((level) => level === config2.safetyLevel)),
77854
+ onSelect: (_2, option) => {
77855
+ config2.safetyLevel = option.value;
77856
+ saveConfig(config2);
77857
+ statusBarText.content = getStatusBarContent();
77858
+ closeSafetyModal();
77859
+ addSystemMessage(`Safety level: ${config2.safetyLevel}`);
77955
77860
  }
77861
+ });
77862
+ }
77863
+ function showThinkingSelector() {
77864
+ if (thinkingModal)
77865
+ return;
77866
+ const levels = ["low", "medium", "high", "off"];
77867
+ const descriptions = {
77868
+ low: "Use light reasoning for supported models.",
77869
+ medium: "Use balanced reasoning for supported models.",
77870
+ high: "Use maximum reasoning for supported models.",
77871
+ off: "Disable extra reasoning controls."
77956
77872
  };
77957
- renderer.keyInput.on("keypress", escHandler);
77958
- themeSelector.focus();
77873
+ thinkingModal = openModalList({
77874
+ containerId: "thinking-selector-container",
77875
+ selectorId: "thinking-select",
77876
+ title: "Thinking Level",
77877
+ width: 58,
77878
+ options: levels.map((level) => ({
77879
+ name: level === config2.thinkingLevel ? `${level} (current)` : level,
77880
+ description: descriptions[level],
77881
+ value: level
77882
+ })),
77883
+ selectedIndex: Math.max(0, levels.findIndex((level) => level === config2.thinkingLevel)),
77884
+ onSelect: (_2, option) => {
77885
+ config2.thinkingLevel = option.value;
77886
+ saveConfig(config2);
77887
+ statusBarText.content = getStatusBarContent();
77888
+ closeThinkingModal();
77889
+ addSystemMessage(`Thinking level: ${config2.thinkingLevel}`);
77890
+ }
77891
+ });
77959
77892
  }
77960
- var commandPalette = null;
77893
+ var MODAL_LIST_WIDTH = 55;
77894
+ var MODAL_LIST_MAX_ITEMS = 12;
77895
+ var MODAL_LIST_FRAME_HEIGHT = 4;
77896
+ var providerModal = null;
77897
+ var modelModal = null;
77898
+ var themeModal = null;
77899
+ var safetyModal = null;
77900
+ var thinkingModal = null;
77901
+ var commandPaletteModal = null;
77902
+ var slashCommandModal = null;
77903
+ var apiKeyModal = null;
77904
+ var apiKeyModalOnCancel = null;
77961
77905
  var commandPaletteQuery = "";
77962
77906
  var chordMode = "none";
77963
- function cycleThinkingLevel() {
77964
- const levels = ["low", "medium", "high", "off"];
77965
- const currentIndex = levels.indexOf(config2.thinkingLevel);
77966
- const nextIndex = (currentIndex + 1) % levels.length;
77967
- config2.thinkingLevel = levels[nextIndex];
77968
- saveConfig(config2);
77969
- statusBarText.content = getStatusBarContent();
77970
- addSystemMessage(`Thinking level: ${config2.thinkingLevel}`);
77971
- }
77972
- function getCommandPaletteOptions() {
77907
+ function getAppCommands() {
77973
77908
  return [
77974
77909
  {
77975
77910
  name: "Change Model",
77976
77911
  description: `Current: ${currentModel.name}`,
77912
+ slash: "models",
77977
77913
  shortcut: "Ctrl+X M",
77978
77914
  chord: "m",
77979
77915
  action: () => showModelSelector()
@@ -77981,11 +77917,13 @@ function getCommandPaletteOptions() {
77981
77917
  {
77982
77918
  name: "Switch Provider",
77983
77919
  description: `Current: ${getProviderDisplayName(config2.provider)}`,
77920
+ slash: "providers",
77984
77921
  action: () => switchProvider()
77985
77922
  },
77986
77923
  {
77987
77924
  name: "Toggle Dry Run",
77988
77925
  description: dryRunMode ? "Currently ON" : "Currently OFF",
77926
+ slash: "dry",
77989
77927
  action: () => {
77990
77928
  dryRunMode = !dryRunMode;
77991
77929
  statusBarText.content = getStatusBarContent();
@@ -77993,28 +77931,18 @@ function getCommandPaletteOptions() {
77993
77931
  }
77994
77932
  },
77995
77933
  {
77996
- name: "Cycle Safety Level",
77934
+ name: "Select Safety Level",
77997
77935
  description: `Current: ${config2.safetyLevel}`,
77998
- action: () => {
77999
- const levels = ["moderate", "strict", "relaxed"];
78000
- const currentIndex = levels.indexOf(config2.safetyLevel);
78001
- const nextIndex = (currentIndex + 1) % levels.length;
78002
- config2.safetyLevel = levels[nextIndex];
78003
- saveConfig(config2);
78004
- statusBarText.content = getStatusBarContent();
78005
- const descriptions = {
78006
- strict: "confirms ALL potentially dangerous commands",
78007
- moderate: "confirms high/critical severity commands",
78008
- relaxed: "only confirms critical commands"
78009
- };
78010
- addSystemMessage(`Safety level: ${config2.safetyLevel} (${descriptions[config2.safetyLevel]})`);
78011
- }
77936
+ slash: "safety",
77937
+ shortcut: "Ctrl+Y",
77938
+ action: () => showSafetySelector()
78012
77939
  },
78013
77940
  {
78014
- name: "Cycle Thinking Level",
77941
+ name: "Select Thinking Level",
78015
77942
  description: `Current: ${config2.thinkingLevel}`,
77943
+ slash: "thinking",
78016
77944
  shortcut: "Ctrl+T",
78017
- action: () => cycleThinkingLevel()
77945
+ action: () => showThinkingSelector()
78018
77946
  },
78019
77947
  {
78020
77948
  name: "Toggle Project Context",
@@ -78029,16 +77957,19 @@ function getCommandPaletteOptions() {
78029
77957
  {
78030
77958
  name: "Show Config",
78031
77959
  description: "View current configuration",
77960
+ slash: "config",
78032
77961
  action: () => showConfig()
78033
77962
  },
78034
77963
  {
78035
77964
  name: "Show History",
78036
77965
  description: `${history.length} commands`,
77966
+ slash: "history",
78037
77967
  action: () => showHistory()
78038
77968
  },
78039
77969
  {
78040
77970
  name: "Change Theme",
78041
77971
  description: `Current: ${getTheme().name}`,
77972
+ slash: "themes",
78042
77973
  shortcut: "Ctrl+X T",
78043
77974
  chord: "t",
78044
77975
  action: () => showThemeSelector()
@@ -78046,16 +77977,19 @@ function getCommandPaletteOptions() {
78046
77977
  {
78047
77978
  name: "Clear Chat",
78048
77979
  description: "Clear the chat history",
77980
+ slash: "clear",
78049
77981
  action: () => clearChat()
78050
77982
  },
78051
77983
  {
78052
77984
  name: "Show Help",
78053
77985
  description: "View all commands and shortcuts",
77986
+ slash: "help",
78054
77987
  action: () => showHelp()
78055
77988
  },
78056
77989
  {
78057
77990
  name: "Exit",
78058
77991
  description: "Close magic-shell",
77992
+ slash: "exit",
78059
77993
  shortcut: "Ctrl+D / Ctrl+X Q",
78060
77994
  chord: "q",
78061
77995
  action: () => {
@@ -78065,76 +77999,11 @@ function getCommandPaletteOptions() {
78065
77999
  }
78066
78000
  ];
78067
78001
  }
78002
+ function getCommandPaletteOptions() {
78003
+ return getAppCommands();
78004
+ }
78068
78005
  function getSlashCommands() {
78069
- return [
78070
- {
78071
- slash: "help",
78072
- name: "Help",
78073
- description: "Show commands and shortcuts",
78074
- action: () => showHelp()
78075
- },
78076
- {
78077
- slash: "models",
78078
- name: "Models",
78079
- description: `Change model · ${currentModel.name}`,
78080
- action: () => showModelSelector()
78081
- },
78082
- {
78083
- slash: "providers",
78084
- name: "Providers",
78085
- description: `Switch provider · ${getProviderDisplayName(config2.provider)}`,
78086
- action: () => switchProvider()
78087
- },
78088
- {
78089
- slash: "themes",
78090
- name: "Themes",
78091
- description: `Change theme · ${getTheme().name}`,
78092
- action: () => showThemeSelector()
78093
- },
78094
- {
78095
- slash: "dry",
78096
- name: "Dry Run",
78097
- description: dryRunMode ? "Turn dry-run off" : "Turn dry-run on",
78098
- action: () => {
78099
- dryRunMode = !dryRunMode;
78100
- statusBarText.content = getStatusBarContent();
78101
- addSystemMessage(`Dry-run mode: ${dryRunMode ? "ON" : "OFF"}`);
78102
- }
78103
- },
78104
- {
78105
- slash: "thinking",
78106
- name: "Thinking",
78107
- description: `Cycle thinking level · ${config2.thinkingLevel}`,
78108
- action: () => cycleThinkingLevel()
78109
- },
78110
- {
78111
- slash: "config",
78112
- name: "Config",
78113
- description: "Show current configuration",
78114
- action: () => showConfig()
78115
- },
78116
- {
78117
- slash: "history",
78118
- name: "History",
78119
- description: `${history.length} commands`,
78120
- action: () => showHistory()
78121
- },
78122
- {
78123
- slash: "clear",
78124
- name: "Clear",
78125
- description: "Clear the chat history",
78126
- action: () => clearChat()
78127
- },
78128
- {
78129
- slash: "exit",
78130
- name: "Exit",
78131
- description: "Close magic-shell",
78132
- action: () => {
78133
- renderer.destroy();
78134
- process.exit(0);
78135
- }
78136
- }
78137
- ];
78006
+ return getAppCommands().filter((cmd) => Boolean(cmd.slash));
78138
78007
  }
78139
78008
  function getSlashCommandMatches(inputText) {
78140
78009
  if (!inputText.startsWith("/"))
@@ -78149,71 +78018,269 @@ function getSlashCommandMatches(inputText) {
78149
78018
  return `${cmd.slash} ${cmd.name} ${cmd.description}`.toLowerCase().includes(query);
78150
78019
  });
78151
78020
  }
78152
- function ensureSlashCommandMenu() {
78153
- if (slashCommandContainer && slashCommandSelector)
78154
- return;
78155
- slashCommandContainer = new BoxRenderable(renderer, {
78156
- id: "slash-command-container",
78157
- width: "100%",
78021
+ function openModalList(config3) {
78022
+ const theme = getTheme();
78023
+ const width = config3.width ?? MODAL_LIST_WIDTH;
78024
+ const termWidth = process.stdout.columns || 80;
78025
+ const left = Math.max(2, Math.floor((termWidth - width) / 2));
78026
+ const visibleRows = Math.max(config3.options.length, 1);
78027
+ const maxRows = Math.max(4, (process.stdout.rows || 24) - 8);
78028
+ const listHeight = Math.min(visibleRows, MODAL_LIST_MAX_ITEMS, maxRows);
78029
+ const showDetail = config3.showDescription !== false && config3.options.some((option) => option.description);
78030
+ const detailHeight = showDetail ? 2 : 0;
78031
+ const containerHeight = listHeight + MODAL_LIST_FRAME_HEIGHT + detailHeight;
78032
+ let currentOptions = config3.options;
78033
+ const formatDetail = (index) => {
78034
+ const description = currentOptions[index]?.description;
78035
+ if (!description || !showDetail)
78036
+ return t``;
78037
+ const maxLength = Math.max(20, width - 16);
78038
+ const text2 = description.length > maxLength ? `${description.slice(0, maxLength - 1)}…` : description;
78039
+ return t`${fg(theme.colors.textMuted)(` ▶ ${text2}`)}`;
78040
+ };
78041
+ const formatOptions = (options) => options.map((option) => ({
78042
+ ...option,
78043
+ description: ""
78044
+ }));
78045
+ const container = new BoxRenderable(renderer, {
78046
+ id: config3.containerId,
78047
+ position: "absolute",
78048
+ left,
78049
+ top: 3,
78050
+ width,
78051
+ height: containerHeight,
78052
+ backgroundColor: theme.colors.backgroundPanel,
78158
78053
  border: true,
78159
- borderColor: getTheme().colors.border,
78054
+ borderColor: theme.colors.primary,
78160
78055
  borderStyle: "single",
78161
- backgroundColor: getTheme().colors.backgroundPanel,
78162
- paddingLeft: 1,
78163
- paddingRight: 1,
78164
- paddingTop: 0,
78165
- paddingBottom: 0,
78166
- marginTop: 1
78056
+ title: config3.title,
78057
+ titleAlignment: "center",
78058
+ zIndex: 200,
78059
+ padding: 1
78167
78060
  });
78168
- inputContainer.add(slashCommandContainer);
78169
- slashCommandSelector = new SelectRenderable(renderer, {
78170
- id: "slash-command-select",
78061
+ renderer.root.add(container);
78062
+ const selector = new SelectRenderable(renderer, {
78063
+ id: config3.selectorId,
78171
78064
  width: "100%",
78172
- height: 6,
78173
- options: [],
78065
+ height: listHeight,
78066
+ options: formatOptions(config3.options),
78174
78067
  backgroundColor: "transparent",
78175
78068
  focusedBackgroundColor: "transparent",
78176
- selectedBackgroundColor: getTheme().colors.backgroundElement,
78177
- textColor: getTheme().colors.text,
78178
- selectedTextColor: getTheme().colors.primary,
78179
- descriptionColor: getTheme().colors.textMuted,
78180
- selectedDescriptionColor: getTheme().colors.textMuted,
78181
- showDescription: true,
78069
+ selectedBackgroundColor: theme.colors.backgroundElement,
78070
+ textColor: theme.colors.text,
78071
+ selectedTextColor: theme.colors.primary,
78072
+ descriptionColor: theme.colors.textMuted,
78073
+ selectedDescriptionColor: theme.colors.textMuted,
78074
+ showDescription: false,
78075
+ showScrollIndicator: config3.showScrollIndicator ?? false,
78182
78076
  wrapSelection: true
78183
78077
  });
78184
- slashCommandContainer.add(slashCommandSelector);
78078
+ container.add(selector);
78079
+ const detailText = showDetail ? new TextRenderable(renderer, {
78080
+ id: `${config3.containerId}-detail`,
78081
+ content: formatDetail(config3.selectedIndex ?? 0),
78082
+ marginTop: 1
78083
+ }) : null;
78084
+ if (detailText) {
78085
+ container.add(detailText);
78086
+ }
78087
+ const handle = {
78088
+ containerId: config3.containerId,
78089
+ container,
78090
+ selector,
78091
+ updateOptions(options, selectedIndex = 0) {
78092
+ currentOptions = options;
78093
+ const rows = Math.max(options.length, 1);
78094
+ const maxHeight = Math.max(4, (process.stdout.rows || 24) - 8);
78095
+ const newListHeight = Math.min(rows, MODAL_LIST_MAX_ITEMS, maxHeight);
78096
+ selector.options = formatOptions(options);
78097
+ selector.height = newListHeight;
78098
+ container.height = newListHeight + MODAL_LIST_FRAME_HEIGHT + detailHeight;
78099
+ selector.setSelectedIndex(Math.min(selectedIndex, Math.max(options.length - 1, 0)));
78100
+ if (detailText) {
78101
+ detailText.content = formatDetail(selector.getSelectedIndex());
78102
+ }
78103
+ },
78104
+ close() {
78105
+ renderer.root.remove(config3.containerId);
78106
+ inputField?.focus();
78107
+ }
78108
+ };
78109
+ if (config3.onSelect) {
78110
+ selector.on(SelectRenderableEvents.ITEM_SELECTED, async (index, option) => {
78111
+ await config3.onSelect?.(index, currentOptions[index] ?? option);
78112
+ });
78113
+ }
78114
+ selector.on(SelectRenderableEvents.SELECTION_CHANGED, (index) => {
78115
+ if (detailText) {
78116
+ detailText.content = formatDetail(index);
78117
+ }
78118
+ });
78119
+ const initialIndex = config3.selectedIndex ?? 0;
78120
+ selector.setSelectedIndex(initialIndex);
78121
+ if (config3.focusList !== false) {
78122
+ selector.focus();
78123
+ }
78124
+ return handle;
78185
78125
  }
78186
- function updateSlashCommandMenuOptions() {
78187
- if (!slashCommandSelector)
78188
- return;
78189
- slashCommandSelector.options = slashCommandMatches.map((cmd) => ({
78126
+ function openInputModal(config3) {
78127
+ const theme = getTheme();
78128
+ const width = config3.width ?? 72;
78129
+ const termWidth = process.stdout.columns || 80;
78130
+ const left = Math.max(2, Math.floor((termWidth - width) / 2));
78131
+ const container = new BoxRenderable(renderer, {
78132
+ id: config3.containerId,
78133
+ position: "absolute",
78134
+ left,
78135
+ top: 3,
78136
+ width,
78137
+ height: config3.height ?? 11,
78138
+ backgroundColor: theme.colors.backgroundPanel,
78139
+ border: true,
78140
+ borderColor: theme.colors.primary,
78141
+ borderStyle: "single",
78142
+ title: config3.title,
78143
+ titleAlignment: "center",
78144
+ zIndex: 200,
78145
+ padding: 1
78146
+ });
78147
+ renderer.root.add(container);
78148
+ const description = new TextRenderable(renderer, {
78149
+ id: `${config3.containerId}-description`,
78150
+ content: t`${fg(theme.colors.text)(config3.description)}`,
78151
+ marginBottom: 1
78152
+ });
78153
+ container.add(description);
78154
+ const input = new InputRenderable(renderer, {
78155
+ id: `${config3.containerId}-input`,
78156
+ width: "100%",
78157
+ placeholder: config3.placeholder,
78158
+ backgroundColor: theme.colors.backgroundElement,
78159
+ focusedBackgroundColor: theme.colors.backgroundElement,
78160
+ textColor: theme.colors.text,
78161
+ cursorColor: theme.colors.primary
78162
+ });
78163
+ container.add(input);
78164
+ if (config3.extraText) {
78165
+ const extra = new TextRenderable(renderer, {
78166
+ id: `${config3.containerId}-extra`,
78167
+ content: t`${fg(theme.colors.success)(config3.extraText)}`,
78168
+ marginTop: 1
78169
+ });
78170
+ container.add(extra);
78171
+ }
78172
+ const hint = new TextRenderable(renderer, {
78173
+ id: `${config3.containerId}-hint`,
78174
+ content: t`${fg(theme.colors.textMuted)(config3.hintText ?? "Press Enter to save | Esc to cancel | Ctrl+C to exit")}`,
78175
+ marginTop: 1
78176
+ });
78177
+ container.add(hint);
78178
+ input.on(InputRenderableEvents.ENTER, (value) => {
78179
+ config3.onSubmit(value);
78180
+ });
78181
+ const handle = {
78182
+ containerId: config3.containerId,
78183
+ container,
78184
+ input,
78185
+ close() {
78186
+ renderer.root.remove(config3.containerId);
78187
+ inputField?.focus();
78188
+ }
78189
+ };
78190
+ input.focus();
78191
+ return handle;
78192
+ }
78193
+ function getSlashCommandSelectOptions() {
78194
+ return slashCommandMatches.map((cmd) => ({
78190
78195
  name: `/${cmd.slash}`,
78191
78196
  description: cmd.description,
78192
78197
  value: cmd
78193
78198
  }));
78194
- slashCommandSelector.height = Math.min(Math.max(slashCommandMatches.length, 1), 6);
78195
- slashCommandSelector.setSelectedIndex(slashCommandSelectedIndex);
78196
78199
  }
78197
- function closeSlashCommandMenu() {
78198
- if (slashCommandContainer) {
78199
- inputContainer.remove("slash-command-container");
78200
- slashCommandContainer = null;
78201
- slashCommandSelector = null;
78200
+ function closeProviderModal() {
78201
+ if (!providerModal)
78202
+ return;
78203
+ providerModal.close();
78204
+ providerModal = null;
78205
+ }
78206
+ function closeModelModal() {
78207
+ if (!modelModal)
78208
+ return;
78209
+ modelModal.close();
78210
+ modelModal = null;
78211
+ }
78212
+ function closeThemeModal() {
78213
+ if (!themeModal)
78214
+ return;
78215
+ themeModal.close();
78216
+ themeModal = null;
78217
+ }
78218
+ function closeSafetyModal() {
78219
+ if (!safetyModal)
78220
+ return;
78221
+ safetyModal.close();
78222
+ safetyModal = null;
78223
+ }
78224
+ function closeThinkingModal() {
78225
+ if (!thinkingModal)
78226
+ return;
78227
+ thinkingModal.close();
78228
+ thinkingModal = null;
78229
+ }
78230
+ function closeApiKeyModal(invokeCancel = false) {
78231
+ if (!apiKeyModal)
78232
+ return;
78233
+ apiKeyModal.close();
78234
+ apiKeyModal = null;
78235
+ const onCancel = apiKeyModalOnCancel;
78236
+ apiKeyModalOnCancel = null;
78237
+ if (invokeCancel)
78238
+ onCancel?.();
78239
+ }
78240
+ function closeSlashCommandMenu(dismissCurrentInput = false) {
78241
+ if (slashCommandModal) {
78242
+ slashCommandModal.close();
78243
+ slashCommandModal = null;
78244
+ }
78245
+ if (dismissCurrentInput) {
78246
+ slashCommandDismissedInput = inputField?.editBuffer.getText() ?? null;
78202
78247
  }
78203
78248
  slashCommandMatches = [];
78204
78249
  slashCommandSelectedIndex = 0;
78205
78250
  }
78251
+ function updateSlashCommandModalOptions() {
78252
+ if (!slashCommandModal)
78253
+ return;
78254
+ slashCommandModal.updateOptions(getSlashCommandSelectOptions(), slashCommandSelectedIndex);
78255
+ }
78206
78256
  function syncSlashCommandMenu() {
78207
78257
  const inputText = inputField.editBuffer.getText();
78258
+ if (slashCommandDismissedInput !== null) {
78259
+ if (inputText === slashCommandDismissedInput) {
78260
+ return;
78261
+ }
78262
+ slashCommandDismissedInput = null;
78263
+ }
78208
78264
  const matches = getSlashCommandMatches(inputText);
78209
78265
  if (matches.length === 0) {
78210
78266
  closeSlashCommandMenu();
78211
78267
  return;
78212
78268
  }
78213
- ensureSlashCommandMenu();
78214
78269
  slashCommandMatches = matches;
78215
78270
  slashCommandSelectedIndex = Math.min(slashCommandSelectedIndex, slashCommandMatches.length - 1);
78216
- updateSlashCommandMenuOptions();
78271
+ const options = getSlashCommandSelectOptions();
78272
+ if (slashCommandModal) {
78273
+ slashCommandModal.updateOptions(options, slashCommandSelectedIndex);
78274
+ return;
78275
+ }
78276
+ slashCommandModal = openModalList({
78277
+ containerId: "slash-command-modal",
78278
+ selectorId: "slash-command-select",
78279
+ title: "Commands",
78280
+ options,
78281
+ focusList: false,
78282
+ selectedIndex: slashCommandSelectedIndex
78283
+ });
78217
78284
  }
78218
78285
  function queueSlashCommandSync() {
78219
78286
  if (slashCommandSyncQueued)
@@ -78226,55 +78293,24 @@ function queueSlashCommandSync() {
78226
78293
  }, 0);
78227
78294
  }
78228
78295
  function showCommandPalette() {
78229
- if (commandPalette) {
78296
+ if (commandPaletteModal) {
78230
78297
  return;
78231
78298
  }
78232
78299
  commandPaletteQuery = "";
78233
- const commands = getCommandPaletteOptions();
78234
- const paletteWidth = 55;
78235
- const termWidth = process.stdout.columns || 80;
78236
- const paletteLeft = Math.max(2, Math.floor((termWidth - paletteWidth) / 2));
78237
- const container = new BoxRenderable(renderer, {
78238
- id: "command-palette-container",
78239
- position: "absolute",
78240
- left: paletteLeft,
78241
- top: 3,
78242
- width: paletteWidth,
78243
- height: Math.min(commands.length + 4, 16),
78244
- backgroundColor: "#1e293b",
78245
- border: true,
78246
- borderColor: "#60a5fa",
78247
- borderStyle: "single",
78300
+ commandPaletteModal = openModalList({
78301
+ containerId: "command-palette-container",
78302
+ selectorId: "command-palette-select",
78248
78303
  title: "Commands",
78249
- titleAlignment: "center",
78250
- zIndex: 200,
78251
- padding: 1
78252
- });
78253
- renderer.root.add(container);
78254
- commandPalette = new SelectRenderable(renderer, {
78255
- id: "command-palette-select",
78256
- width: "100%",
78257
- height: Math.min(commands.length + 2, 12),
78258
78304
  options: getCommandPaletteSelectOptions(),
78259
- backgroundColor: "transparent",
78260
- focusedBackgroundColor: "transparent",
78261
- selectedBackgroundColor: "#334155",
78262
- textColor: "#e2e8f0",
78263
- selectedTextColor: "#60a5fa",
78264
- descriptionColor: "#64748b",
78265
- selectedDescriptionColor: "#94a3b8",
78266
- showDescription: true,
78267
- wrapSelection: true
78268
- });
78269
- container.add(commandPalette);
78270
- commandPalette.on(SelectRenderableEvents.ITEM_SELECTED, async (_2, option) => {
78271
- if (!option.value)
78272
- return;
78273
- const cmd = option.value;
78274
- closeCommandPalette();
78275
- await cmd.action();
78305
+ focusList: true,
78306
+ onSelect: async (_2, option) => {
78307
+ if (!option.value)
78308
+ return;
78309
+ const cmd = option.value;
78310
+ closeCommandPalette();
78311
+ await cmd.action();
78312
+ }
78276
78313
  });
78277
- commandPalette.focus();
78278
78314
  }
78279
78315
  function getCommandPaletteSelectOptions() {
78280
78316
  const query = commandPaletteQuery.toLowerCase();
@@ -78297,30 +78333,28 @@ function getCommandPaletteSelectOptions() {
78297
78333
  }));
78298
78334
  }
78299
78335
  function updateCommandPaletteOptions() {
78300
- if (!commandPalette)
78336
+ if (!commandPaletteModal)
78301
78337
  return;
78302
- commandPalette.options = getCommandPaletteSelectOptions();
78303
- commandPalette.setSelectedIndex(0);
78338
+ commandPaletteModal.updateOptions(getCommandPaletteSelectOptions(), 0);
78304
78339
  }
78305
78340
  function closeCommandPalette() {
78306
- if (commandPalette) {
78307
- renderer.root.remove("command-palette-container");
78308
- commandPalette = null;
78341
+ if (commandPaletteModal) {
78342
+ commandPaletteModal.close();
78343
+ commandPaletteModal = null;
78309
78344
  commandPaletteQuery = "";
78310
- inputField?.focus();
78311
78345
  }
78312
78346
  }
78313
78347
  function handleKeypress(key) {
78314
78348
  const commands = getCommandPaletteOptions();
78315
- if (slashCommandMatches.length > 0) {
78349
+ if (slashCommandModal && slashCommandMatches.length > 0) {
78316
78350
  if (key.name === "up") {
78317
78351
  slashCommandSelectedIndex = slashCommandSelectedIndex === 0 ? slashCommandMatches.length - 1 : slashCommandSelectedIndex - 1;
78318
- updateSlashCommandMenuOptions();
78352
+ updateSlashCommandModalOptions();
78319
78353
  return;
78320
78354
  }
78321
78355
  if (key.name === "down") {
78322
78356
  slashCommandSelectedIndex = (slashCommandSelectedIndex + 1) % slashCommandMatches.length;
78323
- updateSlashCommandMenuOptions();
78357
+ updateSlashCommandModalOptions();
78324
78358
  return;
78325
78359
  }
78326
78360
  if (key.name === "tab") {
@@ -78335,7 +78369,11 @@ function handleKeypress(key) {
78335
78369
  return;
78336
78370
  }
78337
78371
  if (key.ctrl && key.name === "t") {
78338
- cycleThinkingLevel();
78372
+ showThinkingSelector();
78373
+ return;
78374
+ }
78375
+ if (key.ctrl && key.name === "y") {
78376
+ showSafetySelector();
78339
78377
  return;
78340
78378
  }
78341
78379
  if (key.ctrl && key.name === "d") {
@@ -78356,7 +78394,7 @@ function handleKeypress(key) {
78356
78394
  }
78357
78395
  return;
78358
78396
  }
78359
- if (commandPalette) {
78397
+ if (commandPaletteModal) {
78360
78398
  if (key.name === "backspace" || key.name === "delete") {
78361
78399
  commandPaletteQuery = commandPaletteQuery.slice(0, -1);
78362
78400
  updateCommandPaletteOptions();
@@ -78370,24 +78408,36 @@ function handleKeypress(key) {
78370
78408
  }
78371
78409
  }
78372
78410
  if (key.ctrl && key.name === "c") {
78373
- if (commandPalette) {
78411
+ if (commandPaletteModal) {
78374
78412
  closeCommandPalette();
78375
78413
  return;
78376
78414
  }
78377
- if (slashCommandMatches.length > 0) {
78378
- closeSlashCommandMenu();
78415
+ if (slashCommandModal) {
78416
+ closeSlashCommandMenu(true);
78379
78417
  return;
78380
78418
  }
78381
- if (modelSelector) {
78382
- renderer.root.remove("model-selector-container");
78383
- modelSelector = null;
78384
- inputField.focus();
78419
+ if (providerModal) {
78420
+ closeProviderModal();
78385
78421
  return;
78386
78422
  }
78387
- if (themeSelector) {
78388
- renderer.root.remove("theme-selector-container");
78389
- themeSelector = null;
78390
- inputField.focus();
78423
+ if (modelModal) {
78424
+ closeModelModal();
78425
+ return;
78426
+ }
78427
+ if (themeModal) {
78428
+ closeThemeModal();
78429
+ return;
78430
+ }
78431
+ if (safetyModal) {
78432
+ closeSafetyModal();
78433
+ return;
78434
+ }
78435
+ if (thinkingModal) {
78436
+ closeThinkingModal();
78437
+ return;
78438
+ }
78439
+ if (apiKeyModal) {
78440
+ closeApiKeyModal(true);
78391
78441
  return;
78392
78442
  }
78393
78443
  if (awaitingConfirmation && pendingMessageId) {
@@ -78401,18 +78451,36 @@ function handleKeypress(key) {
78401
78451
  }
78402
78452
  if (key.name === "escape") {
78403
78453
  chordMode = "none";
78404
- if (commandPalette) {
78454
+ if (commandPaletteModal) {
78405
78455
  closeCommandPalette();
78406
78456
  return;
78407
78457
  }
78408
- if (slashCommandMatches.length > 0) {
78409
- closeSlashCommandMenu();
78458
+ if (slashCommandModal) {
78459
+ closeSlashCommandMenu(true);
78410
78460
  return;
78411
78461
  }
78412
- if (modelSelector) {
78413
- renderer.root.remove("model-selector-container");
78414
- modelSelector = null;
78415
- inputField.focus();
78462
+ if (providerModal) {
78463
+ closeProviderModal();
78464
+ return;
78465
+ }
78466
+ if (modelModal) {
78467
+ closeModelModal();
78468
+ return;
78469
+ }
78470
+ if (themeModal) {
78471
+ closeThemeModal();
78472
+ return;
78473
+ }
78474
+ if (safetyModal) {
78475
+ closeSafetyModal();
78476
+ return;
78477
+ }
78478
+ if (thinkingModal) {
78479
+ closeThinkingModal();
78480
+ return;
78481
+ }
78482
+ if (apiKeyModal) {
78483
+ closeApiKeyModal(true);
78416
78484
  return;
78417
78485
  }
78418
78486
  if (awaitingConfirmation && pendingMessageId) {
@@ -78448,7 +78516,7 @@ function handleKeypress(key) {
78448
78516
  addSystemMessage(`Copied to clipboard: ${msg.command}`);
78449
78517
  }
78450
78518
  }
78451
- if (key.name === "o" && !awaitingConfirmation && !commandPalette && !modelSelector) {
78519
+ if (key.name === "o" && !awaitingConfirmation && !commandPaletteModal && !modelModal) {
78452
78520
  toggleLastResultExpand();
78453
78521
  }
78454
78522
  }