@austinthesing/magic-shell 0.2.29 → 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,12 +76815,11 @@ function getApiKeyUrl(provider) {
76815
76815
  }
76816
76816
  var inputHintText;
76817
76817
  var helpBarText;
76818
- var modelSelector = null;
76819
- var providerSelector = null;
76820
76818
  var slashCommandMatches = [];
76821
76819
  var slashCommandSelectedIndex = 0;
76822
76820
  var slashCommandSyncQueued = false;
76823
76821
  var slashCommandExecuting = false;
76822
+ var slashCommandDismissedInput = null;
76824
76823
  var pendingMessageId = null;
76825
76824
  var awaitingConfirmation = false;
76826
76825
  function generateMessageId() {
@@ -76832,13 +76831,16 @@ function isFreeModel(model) {
76832
76831
  function costTierLabel(tier) {
76833
76832
  switch (tier) {
76834
76833
  case "free":
76835
- return "FREE";
76834
+ return "Free";
76836
76835
  case "lower-cost":
76837
- return "lower-cost";
76836
+ return "Lower Cost";
76838
76837
  case "premium":
76839
- return "premium";
76838
+ return "Premium";
76840
76839
  }
76841
76840
  }
76841
+ function getModelDisplayName(model) {
76842
+ return model.cost === "free" ? model.name.replace(/\s+Free$/i, "") : model.name;
76843
+ }
76842
76844
  async function main() {
76843
76845
  config2 = loadConfig();
76844
76846
  history = loadHistory();
@@ -76890,53 +76892,50 @@ async function showProviderSetup() {
76890
76892
  const options = [
76891
76893
  {
76892
76894
  name: "OpenCode Zen (Recommended)",
76893
- description: "Curated models optimized for coding. Has free models!",
76895
+ description: "Curated coding models with a generous free tier.",
76894
76896
  value: "opencode-zen"
76895
76897
  },
76896
76898
  {
76897
76899
  name: "OpenRouter",
76898
- description: "Access to many models from various providers",
76900
+ description: "Broad model catalog across major providers.",
76899
76901
  value: "openrouter"
76900
76902
  },
76901
76903
  {
76902
76904
  name: "Vercel AI Gateway",
76903
- description: "Unified model gateway using AI_GATEWAY_API_KEY",
76905
+ description: "Vercel-hosted gateway for managed model access.",
76904
76906
  value: "vercel-ai-gateway"
76905
76907
  },
76906
76908
  {
76907
76909
  name: "Cloudflare AI Gateway",
76908
- description: "Cloudflare gateway for provider and Workers AI models",
76910
+ description: "Cloudflare gateway for provider and Workers AI routing.",
76909
76911
  value: "cloudflare-ai-gateway"
76910
76912
  },
76911
76913
  {
76912
76914
  name: "Cloudflare Workers AI",
76913
- description: "Cloudflare-hosted models via Workers AI",
76915
+ description: "Cloudflare-hosted models with direct Workers AI access.",
76914
76916
  value: "workers-ai"
76915
76917
  }
76916
76918
  ];
76917
- providerSelector = new SelectRenderable(renderer, {
76918
- id: "provider-select",
76919
- width: 60,
76920
- 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,
76921
76925
  options,
76922
- backgroundColor: "#1e293b",
76923
- focusedBackgroundColor: "#1e293b",
76924
- selectedBackgroundColor: "#334155",
76925
- textColor: "#e2e8f0",
76926
- selectedTextColor: "#60a5fa",
76927
- descriptionColor: "#64748b",
76928
- selectedDescriptionColor: "#94a3b8",
76929
- showDescription: true,
76930
- wrapSelection: true
76931
- });
76932
- container.add(providerSelector);
76933
- providerSelector.on(SelectRenderableEvents.ITEM_SELECTED, async (_2, option) => {
76934
- const provider = option.value;
76935
- config2.provider = provider;
76936
- saveConfig(config2);
76937
- renderer.root.remove("setup-container");
76938
- providerSelector = null;
76939
- 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
+ }
76940
76939
  });
76941
76940
  const hint = new TextRenderable(renderer, {
76942
76941
  id: "setup-hint",
@@ -76945,76 +76944,39 @@ ${fg("#64748b")("Use arrow keys to select | Enter to confirm | Ctrl+C to exit")}
76945
76944
  marginTop: 1
76946
76945
  });
76947
76946
  container.add(hint);
76948
- renderer.keyInput.on("keypress", (key) => {
76949
- if (key.ctrl && key.name === "c") {
76950
- renderer.destroy();
76951
- process.exit(0);
76952
- }
76953
- });
76954
- providerSelector.focus();
76955
76947
  }
76956
- async function showApiKeyInput(provider) {
76957
- const container = new BoxRenderable(renderer, {
76958
- id: "apikey-container",
76959
- flexDirection: "column",
76960
- padding: 2,
76961
- width: "100%",
76962
- height: "100%"
76963
- });
76964
- renderer.root.add(container);
76965
- const title = new TextRenderable(renderer, {
76966
- id: "apikey-title",
76967
- content: t`${bold(fg("#60a5fa")(`${getProviderDisplayName(provider)} Setup`))}`,
76968
- marginBottom: 1
76969
- });
76970
- container.add(title);
76948
+ async function showApiKeyInput(provider, options) {
76949
+ if (apiKeyModal)
76950
+ return;
76951
+ apiKeyModalOnCancel = options?.onCancel ?? null;
76971
76952
  const url2 = getApiKeyUrl(provider);
76972
- const instructions = new TextRenderable(renderer, {
76973
- id: "apikey-instructions",
76974
- content: t`Get your API key from: ${fg("#22c55e")(url2)}
76975
-
76976
- Enter your API key below:`,
76977
- marginBottom: 1
76978
- });
76979
- container.add(instructions);
76980
- const input = new InputRenderable(renderer, {
76981
- id: "api-key-input",
76982
- width: 70,
76983
- placeholder: provider === "openrouter" ? "sk-or-v1-..." : "API key or token",
76984
- backgroundColor: "#1e293b",
76985
- focusedBackgroundColor: "#334155",
76986
- textColor: "#f8fafc",
76987
- cursorColor: "#60a5fa"
76988
- });
76989
- container.add(input);
76990
- if (provider === "opencode-zen") {
76991
- const freeNote = new TextRenderable(renderer, {
76992
- id: "free-note",
76993
- content: t`
76994
- ${fg("#22c55e")("Tip:")} OpenCode Zen has free models like Kimi K2.6 and DeepSeek V4 Flash!`,
76995
- marginTop: 1
76996
- });
76997
- container.add(freeNote);
76998
- }
76999
- const hint = new TextRenderable(renderer, {
77000
- id: "apikey-hint",
77001
- content: t`
77002
- ${fg("#64748b")("Press Enter to save | Ctrl+C to exit")}`,
77003
- marginTop: 1
77004
- });
77005
- container.add(hint);
77006
- input.on(InputRenderableEvents.ENTER, (value) => {
77007
- if (value.trim()) {
77008
- 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);
77009
76972
  const providerModels = getProviderModels(provider);
77010
76973
  currentModel = providerModels.find((m2) => !m2.disabled) || providerModels[0] || OPENCODE_ZEN_MODELS[0];
77011
76974
  config2.defaultModel = currentModel.id;
77012
76975
  saveConfig(config2);
77013
- renderer.root.remove("apikey-container");
76976
+ closeApiKeyModal();
77014
76977
  createMainUI();
77015
76978
  }
77016
76979
  });
77017
- input.focus();
77018
76980
  }
77019
76981
  function createMainUI() {
77020
76982
  const theme = getTheme();
@@ -77119,7 +77081,7 @@ function createMainUI() {
77119
77081
  content: getInputHintContent(),
77120
77082
  marginTop: 1
77121
77083
  });
77122
- inputContainer.add(inputHintText);
77084
+ mainContainer.add(inputHintText);
77123
77085
  helpBarText = new TextRenderable(renderer, {
77124
77086
  id: "help-bar-text",
77125
77087
  content: getHelpBarContent(),
@@ -77145,7 +77107,7 @@ function getHelpBarContent() {
77145
77107
  if (awaitingConfirmation) {
77146
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")}`;
77147
77109
  }
77148
- 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")}`;
77149
77111
  }
77150
77112
  function getInputHintContent() {
77151
77113
  const theme = getTheme();
@@ -77476,6 +77438,18 @@ async function executeSelectedSlashCommand() {
77476
77438
  async function tryHandleSlashCommand(input) {
77477
77439
  if (!input.startsWith("/"))
77478
77440
  return false;
77441
+ const slashBody = input.slice(1).trim().toLowerCase();
77442
+ if (!slashBody.includes(" ") && slashCommandMatches.length > 0) {
77443
+ const selected = slashCommandMatches[Math.min(slashCommandSelectedIndex, slashCommandMatches.length - 1)];
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();
77451
+ return true;
77452
+ }
77479
77453
  await handleSpecialCommand(input);
77480
77454
  return true;
77481
77455
  }
@@ -77631,7 +77605,10 @@ async function handleSpecialCommand(input) {
77631
77605
  break;
77632
77606
  case "thinking":
77633
77607
  case "think":
77634
- cycleThinkingLevel();
77608
+ showThinkingSelector();
77609
+ break;
77610
+ case "safety":
77611
+ showSafetySelector();
77635
77612
  break;
77636
77613
  case "config":
77637
77614
  await showConfig();
@@ -77664,7 +77641,8 @@ function clearChat() {
77664
77641
  function showHelp() {
77665
77642
  const helpText = `Shortcuts:
77666
77643
  Ctrl+P Commands
77667
- Ctrl+T Cycle thinking level (low/medium/high/off)
77644
+ Ctrl+T Select thinking level
77645
+ Ctrl+Y Select safety level
77668
77646
  Ctrl+C Exit magic-shell
77669
77647
  Ctrl+D Exit magic-shell
77670
77648
  Esc Cancel / Close popup
@@ -77678,7 +77656,8 @@ Q Exit
77678
77656
  Commands (type ! or / followed by):
77679
77657
  help Show this help models Change model
77680
77658
  provider Switch provider themes Change theme
77681
- dry Toggle dry-run thinking Cycle thinking
77659
+ dry Toggle dry-run safety Select safety
77660
+ thinking Select thinking
77682
77661
  config Show config history Show history
77683
77662
  clear Clear chat exit Exit
77684
77663
 
@@ -77742,29 +77721,14 @@ ${lines.join(`
77742
77721
  `)}`);
77743
77722
  }
77744
77723
  async function switchProvider() {
77745
- const container = new BoxRenderable(renderer, {
77746
- id: "provider-selector-container",
77747
- position: "absolute",
77748
- left: 2,
77749
- top: 4,
77750
- width: 65,
77751
- height: 15,
77752
- backgroundColor: "#1e293b",
77753
- border: true,
77754
- borderColor: "#60a5fa",
77755
- borderStyle: "single",
77756
- title: "Switch Provider",
77757
- titleAlignment: "center",
77758
- zIndex: 100,
77759
- padding: 1
77760
- });
77761
- renderer.root.add(container);
77724
+ if (providerModal)
77725
+ return;
77762
77726
  const providers = [
77763
- { provider: "opencode-zen", description: "Curated models optimized for coding. Has free models!" },
77764
- { provider: "openrouter", description: "Access to many models from various providers" },
77765
- { provider: "vercel-ai-gateway", description: "Unified model gateway using AI_GATEWAY_API_KEY" },
77766
- { provider: "cloudflare-ai-gateway", description: "Cloudflare gateway for provider and Workers AI models" },
77767
- { 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." }
77768
77732
  ];
77769
77733
  const options = await Promise.all(providers.map(async ({ provider, description }) => {
77770
77734
  const key = await getApiKey(provider);
@@ -77774,210 +77738,178 @@ async function switchProvider() {
77774
77738
  value: provider
77775
77739
  };
77776
77740
  }));
77777
- const selector = new SelectRenderable(renderer, {
77778
- id: "provider-switch-select",
77779
- width: "100%",
77780
- height: 9,
77741
+ providerModal = openModalList({
77742
+ containerId: "provider-selector-container",
77743
+ selectorId: "provider-switch-select",
77744
+ title: "Switch Provider",
77745
+ width: 65,
77781
77746
  options,
77782
- backgroundColor: "transparent",
77783
- focusedBackgroundColor: "transparent",
77784
- selectedBackgroundColor: "#334155",
77785
- textColor: "#e2e8f0",
77786
- selectedTextColor: "#60a5fa",
77787
- descriptionColor: "#64748b",
77788
- selectedDescriptionColor: "#94a3b8",
77789
- showDescription: true,
77790
- wrapSelection: true
77791
- });
77792
- container.add(selector);
77793
- const closeSelector = () => {
77794
- renderer.root.remove("provider-selector-container");
77795
- inputField.focus();
77796
- };
77797
- selector.on(SelectRenderableEvents.ITEM_SELECTED, async (_2, option) => {
77798
- const newProvider = option.value;
77799
- const existingKey = await getApiKey(newProvider);
77800
- if (existingKey) {
77801
- config2.provider = newProvider;
77802
- const models = getProviderModels(newProvider);
77803
- currentModel = models.find((m2) => m2.id === config2.defaultModel) || models[0];
77804
- config2.defaultModel = currentModel.id;
77805
- saveConfig(config2);
77806
- statusBarText.content = getStatusBarContent();
77807
- closeSelector();
77808
- const providerName = getProviderDisplayName(newProvider);
77809
- addSystemMessage(`Switched to ${providerName}. Model: ${currentModel.name}`);
77810
- } else {
77811
- closeSelector();
77812
- renderer.root.remove("main-container");
77813
- 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
+ }
77814
77765
  }
77815
77766
  });
77816
- const escHandler = (key) => {
77817
- if (key.name === "escape") {
77818
- closeSelector();
77819
- renderer.keyInput.off("keypress", escHandler);
77820
- }
77821
- };
77822
- renderer.keyInput.on("keypress", escHandler);
77823
- selector.focus();
77824
77767
  }
77825
77768
  function showModelSelector() {
77826
- if (modelSelector) {
77769
+ if (modelModal)
77827
77770
  return;
77828
- }
77829
- const container = new BoxRenderable(renderer, {
77830
- id: "model-selector-container",
77831
- position: "absolute",
77832
- left: 2,
77833
- top: 4,
77834
- width: 75,
77835
- height: 22,
77836
- backgroundColor: "#1e293b",
77837
- border: true,
77838
- borderColor: "#60a5fa",
77839
- borderStyle: "single",
77840
- title: `Select Model (${getProviderDisplayName(config2.provider)})`,
77841
- titleAlignment: "center",
77842
- zIndex: 100,
77843
- padding: 1
77844
- });
77845
- renderer.root.add(container);
77846
77771
  const allModels = getProviderModels(config2.provider);
77847
77772
  const availableModels = allModels.filter((m2) => !m2.disabled);
77848
77773
  const sortedModels = sortModelsByCost(availableModels);
77849
77774
  const customModels = getCustomModels().sort((a, b2) => a.name.localeCompare(b2.name));
77850
77775
  const options = [
77851
77776
  ...sortedModels.map((model) => ({
77852
- name: `${model.name} [${costTierLabel(model.cost)}]`,
77777
+ name: `${getModelDisplayName(model)} [${costTierLabel(model.cost)}]`,
77853
77778
  description: model.description,
77854
77779
  value: model
77855
77780
  })),
77856
77781
  ...customModels.map((model) => ({
77857
- name: `${model.name} [custom]`,
77782
+ name: `${model.name} [Custom]`,
77858
77783
  description: `${model.baseUrl} - ${model.modelId}`,
77859
77784
  value: model
77860
77785
  }))
77861
77786
  ];
77862
- modelSelector = new SelectRenderable(renderer, {
77863
- id: "model-select",
77864
- width: "100%",
77865
- height: 18,
77787
+ modelModal = openModalList({
77788
+ containerId: "model-selector-container",
77789
+ selectorId: "model-select",
77790
+ title: `Select Model (${getProviderDisplayName(config2.provider)})`,
77791
+ width: 75,
77866
77792
  options,
77867
- backgroundColor: "transparent",
77868
- focusedBackgroundColor: "transparent",
77869
- selectedBackgroundColor: "#334155",
77870
- textColor: "#e2e8f0",
77871
- selectedTextColor: "#60a5fa",
77872
- descriptionColor: "#64748b",
77873
- selectedDescriptionColor: "#94a3b8",
77874
- showDescription: true,
77875
77793
  showScrollIndicator: true,
77876
- wrapSelection: true
77877
- });
77878
- container.add(modelSelector);
77879
- modelSelector.on(SelectRenderableEvents.ITEM_SELECTED, (_2, option) => {
77880
- currentModel = option.value;
77881
- config2.defaultModel = currentModel.id;
77882
- saveConfig(config2);
77883
- statusBarText.content = getStatusBarContent();
77884
- renderer.root.remove("model-selector-container");
77885
- modelSelector = null;
77886
- inputField.focus();
77887
- const isCustom = isCustomModel(currentModel);
77888
- const freeBadge = isFreeModel(currentModel) ? " (FREE)" : "";
77889
- const customBadge = isCustom ? " (custom)" : "";
77890
- 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
+ }
77891
77806
  });
77892
- modelSelector.focus();
77893
77807
  }
77894
- var themeSelector = null;
77895
77808
  function showThemeSelector() {
77896
- if (themeSelector) {
77809
+ if (themeModal)
77897
77810
  return;
77898
- }
77899
77811
  const currentTheme2 = getTheme();
77900
- const themeContainerWidth = 45;
77901
- const terminalWidth = process.stdout.columns || 80;
77902
- const themeContainerLeft = Math.max(2, Math.floor((terminalWidth - themeContainerWidth) / 2));
77903
- const container = new BoxRenderable(renderer, {
77904
- id: "theme-selector-container",
77905
- position: "absolute",
77906
- left: themeContainerLeft,
77907
- top: 4,
77908
- width: themeContainerWidth,
77909
- height: themeNames.length + 4,
77910
- backgroundColor: currentTheme2.colors.backgroundPanel,
77911
- border: true,
77912
- borderColor: currentTheme2.colors.primary,
77913
- borderStyle: "single",
77914
- title: "Select Theme",
77915
- titleAlignment: "center",
77916
- zIndex: 100,
77917
- padding: 1
77918
- });
77919
- renderer.root.add(container);
77920
77812
  const options = themeNames.map((name24) => ({
77921
77813
  name: name24 === currentTheme2.name ? `${name24} (current)` : name24,
77922
77814
  description: "",
77923
77815
  value: name24
77924
77816
  }));
77925
- themeSelector = new SelectRenderable(renderer, {
77926
- id: "theme-select",
77927
- width: "100%",
77928
- height: themeNames.length + 2,
77817
+ themeModal = openModalList({
77818
+ containerId: "theme-selector-container",
77819
+ selectorId: "theme-select",
77820
+ title: "Select Theme",
77821
+ width: 45,
77929
77822
  options,
77930
- backgroundColor: "transparent",
77931
- focusedBackgroundColor: "transparent",
77932
- selectedBackgroundColor: currentTheme2.colors.backgroundElement,
77933
- textColor: currentTheme2.colors.text,
77934
- selectedTextColor: currentTheme2.colors.primary,
77935
- descriptionColor: currentTheme2.colors.textMuted,
77936
- selectedDescriptionColor: currentTheme2.colors.textMuted,
77937
77823
  showDescription: false,
77938
- wrapSelection: true
77939
- });
77940
- container.add(themeSelector);
77941
- themeSelector.on(SelectRenderableEvents.ITEM_SELECTED, (_2, option) => {
77942
- const themeName = option.value;
77943
- setTheme(themeName);
77944
- renderer.root.remove("theme-selector-container");
77945
- themeSelector = null;
77946
- refreshThemeColors();
77947
- addSystemMessage(`Theme changed to ${themeName}`);
77948
- 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
+ }
77949
77832
  });
77950
- const escHandler = (key) => {
77951
- if (key.name === "escape") {
77952
- renderer.root.remove("theme-selector-container");
77953
- themeSelector = null;
77954
- inputField.focus();
77955
- 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}`);
77956
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."
77957
77872
  };
77958
- renderer.keyInput.on("keypress", escHandler);
77959
- 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
+ });
77960
77892
  }
77961
77893
  var MODAL_LIST_WIDTH = 55;
77962
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;
77963
77901
  var commandPaletteModal = null;
77964
77902
  var slashCommandModal = null;
77903
+ var apiKeyModal = null;
77904
+ var apiKeyModalOnCancel = null;
77965
77905
  var commandPaletteQuery = "";
77966
77906
  var chordMode = "none";
77967
- function cycleThinkingLevel() {
77968
- const levels = ["low", "medium", "high", "off"];
77969
- const currentIndex = levels.indexOf(config2.thinkingLevel);
77970
- const nextIndex = (currentIndex + 1) % levels.length;
77971
- config2.thinkingLevel = levels[nextIndex];
77972
- saveConfig(config2);
77973
- statusBarText.content = getStatusBarContent();
77974
- addSystemMessage(`Thinking level: ${config2.thinkingLevel}`);
77975
- }
77976
- function getCommandPaletteOptions() {
77907
+ function getAppCommands() {
77977
77908
  return [
77978
77909
  {
77979
77910
  name: "Change Model",
77980
77911
  description: `Current: ${currentModel.name}`,
77912
+ slash: "models",
77981
77913
  shortcut: "Ctrl+X M",
77982
77914
  chord: "m",
77983
77915
  action: () => showModelSelector()
@@ -77985,11 +77917,13 @@ function getCommandPaletteOptions() {
77985
77917
  {
77986
77918
  name: "Switch Provider",
77987
77919
  description: `Current: ${getProviderDisplayName(config2.provider)}`,
77920
+ slash: "providers",
77988
77921
  action: () => switchProvider()
77989
77922
  },
77990
77923
  {
77991
77924
  name: "Toggle Dry Run",
77992
77925
  description: dryRunMode ? "Currently ON" : "Currently OFF",
77926
+ slash: "dry",
77993
77927
  action: () => {
77994
77928
  dryRunMode = !dryRunMode;
77995
77929
  statusBarText.content = getStatusBarContent();
@@ -77997,28 +77931,18 @@ function getCommandPaletteOptions() {
77997
77931
  }
77998
77932
  },
77999
77933
  {
78000
- name: "Cycle Safety Level",
77934
+ name: "Select Safety Level",
78001
77935
  description: `Current: ${config2.safetyLevel}`,
78002
- action: () => {
78003
- const levels = ["moderate", "strict", "relaxed"];
78004
- const currentIndex = levels.indexOf(config2.safetyLevel);
78005
- const nextIndex = (currentIndex + 1) % levels.length;
78006
- config2.safetyLevel = levels[nextIndex];
78007
- saveConfig(config2);
78008
- statusBarText.content = getStatusBarContent();
78009
- const descriptions = {
78010
- strict: "confirms ALL potentially dangerous commands",
78011
- moderate: "confirms high/critical severity commands",
78012
- relaxed: "only confirms critical commands"
78013
- };
78014
- addSystemMessage(`Safety level: ${config2.safetyLevel} (${descriptions[config2.safetyLevel]})`);
78015
- }
77936
+ slash: "safety",
77937
+ shortcut: "Ctrl+Y",
77938
+ action: () => showSafetySelector()
78016
77939
  },
78017
77940
  {
78018
- name: "Cycle Thinking Level",
77941
+ name: "Select Thinking Level",
78019
77942
  description: `Current: ${config2.thinkingLevel}`,
77943
+ slash: "thinking",
78020
77944
  shortcut: "Ctrl+T",
78021
- action: () => cycleThinkingLevel()
77945
+ action: () => showThinkingSelector()
78022
77946
  },
78023
77947
  {
78024
77948
  name: "Toggle Project Context",
@@ -78033,16 +77957,19 @@ function getCommandPaletteOptions() {
78033
77957
  {
78034
77958
  name: "Show Config",
78035
77959
  description: "View current configuration",
77960
+ slash: "config",
78036
77961
  action: () => showConfig()
78037
77962
  },
78038
77963
  {
78039
77964
  name: "Show History",
78040
77965
  description: `${history.length} commands`,
77966
+ slash: "history",
78041
77967
  action: () => showHistory()
78042
77968
  },
78043
77969
  {
78044
77970
  name: "Change Theme",
78045
77971
  description: `Current: ${getTheme().name}`,
77972
+ slash: "themes",
78046
77973
  shortcut: "Ctrl+X T",
78047
77974
  chord: "t",
78048
77975
  action: () => showThemeSelector()
@@ -78050,16 +77977,19 @@ function getCommandPaletteOptions() {
78050
77977
  {
78051
77978
  name: "Clear Chat",
78052
77979
  description: "Clear the chat history",
77980
+ slash: "clear",
78053
77981
  action: () => clearChat()
78054
77982
  },
78055
77983
  {
78056
77984
  name: "Show Help",
78057
77985
  description: "View all commands and shortcuts",
77986
+ slash: "help",
78058
77987
  action: () => showHelp()
78059
77988
  },
78060
77989
  {
78061
77990
  name: "Exit",
78062
77991
  description: "Close magic-shell",
77992
+ slash: "exit",
78063
77993
  shortcut: "Ctrl+D / Ctrl+X Q",
78064
77994
  chord: "q",
78065
77995
  action: () => {
@@ -78069,76 +77999,11 @@ function getCommandPaletteOptions() {
78069
77999
  }
78070
78000
  ];
78071
78001
  }
78002
+ function getCommandPaletteOptions() {
78003
+ return getAppCommands();
78004
+ }
78072
78005
  function getSlashCommands() {
78073
- return [
78074
- {
78075
- slash: "help",
78076
- name: "Help",
78077
- description: "Show commands and shortcuts",
78078
- action: () => showHelp()
78079
- },
78080
- {
78081
- slash: "models",
78082
- name: "Models",
78083
- description: `Change model · ${currentModel.name}`,
78084
- action: () => showModelSelector()
78085
- },
78086
- {
78087
- slash: "providers",
78088
- name: "Providers",
78089
- description: `Switch provider · ${getProviderDisplayName(config2.provider)}`,
78090
- action: () => switchProvider()
78091
- },
78092
- {
78093
- slash: "themes",
78094
- name: "Themes",
78095
- description: `Change theme · ${getTheme().name}`,
78096
- action: () => showThemeSelector()
78097
- },
78098
- {
78099
- slash: "dry",
78100
- name: "Dry Run",
78101
- description: dryRunMode ? "Turn dry-run off" : "Turn dry-run on",
78102
- action: () => {
78103
- dryRunMode = !dryRunMode;
78104
- statusBarText.content = getStatusBarContent();
78105
- addSystemMessage(`Dry-run mode: ${dryRunMode ? "ON" : "OFF"}`);
78106
- }
78107
- },
78108
- {
78109
- slash: "thinking",
78110
- name: "Thinking",
78111
- description: `Cycle thinking level · ${config2.thinkingLevel}`,
78112
- action: () => cycleThinkingLevel()
78113
- },
78114
- {
78115
- slash: "config",
78116
- name: "Config",
78117
- description: "Show current configuration",
78118
- action: () => showConfig()
78119
- },
78120
- {
78121
- slash: "history",
78122
- name: "History",
78123
- description: `${history.length} commands`,
78124
- action: () => showHistory()
78125
- },
78126
- {
78127
- slash: "clear",
78128
- name: "Clear",
78129
- description: "Clear the chat history",
78130
- action: () => clearChat()
78131
- },
78132
- {
78133
- slash: "exit",
78134
- name: "Exit",
78135
- description: "Close magic-shell",
78136
- action: () => {
78137
- renderer.destroy();
78138
- process.exit(0);
78139
- }
78140
- }
78141
- ];
78006
+ return getAppCommands().filter((cmd) => Boolean(cmd.slash));
78142
78007
  }
78143
78008
  function getSlashCommandMatches(inputText) {
78144
78009
  if (!inputText.startsWith("/"))
@@ -78155,12 +78020,28 @@ function getSlashCommandMatches(inputText) {
78155
78020
  }
78156
78021
  function openModalList(config3) {
78157
78022
  const theme = getTheme();
78158
- const width = MODAL_LIST_WIDTH;
78023
+ const width = config3.width ?? MODAL_LIST_WIDTH;
78159
78024
  const termWidth = process.stdout.columns || 80;
78160
78025
  const left = Math.max(2, Math.floor((termWidth - width) / 2));
78161
- const itemCount = Math.max(config3.options.length, 1);
78162
- const listHeight = Math.min(itemCount + 2, MODAL_LIST_MAX_ITEMS);
78163
- const containerHeight = listHeight + 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
+ }));
78164
78045
  const container = new BoxRenderable(renderer, {
78165
78046
  id: config3.containerId,
78166
78047
  position: "absolute",
@@ -78182,7 +78063,7 @@ function openModalList(config3) {
78182
78063
  id: config3.selectorId,
78183
78064
  width: "100%",
78184
78065
  height: listHeight,
78185
- options: config3.options,
78066
+ options: formatOptions(config3.options),
78186
78067
  backgroundColor: "transparent",
78187
78068
  focusedBackgroundColor: "transparent",
78188
78069
  selectedBackgroundColor: theme.colors.backgroundElement,
@@ -78190,24 +78071,35 @@ function openModalList(config3) {
78190
78071
  selectedTextColor: theme.colors.primary,
78191
78072
  descriptionColor: theme.colors.textMuted,
78192
78073
  selectedDescriptionColor: theme.colors.textMuted,
78193
- showDescription: true,
78074
+ showDescription: false,
78075
+ showScrollIndicator: config3.showScrollIndicator ?? false,
78194
78076
  wrapSelection: true
78195
78077
  });
78196
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
+ }
78197
78087
  const handle = {
78198
78088
  containerId: config3.containerId,
78199
78089
  container,
78200
78090
  selector,
78201
78091
  updateOptions(options, selectedIndex = 0) {
78202
- const count = Math.max(options.length, 1);
78203
- const newListHeight = Math.min(count + 2, MODAL_LIST_MAX_ITEMS);
78204
- selector.options = options;
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);
78205
78097
  selector.height = newListHeight;
78206
- container.height = newListHeight + 2;
78098
+ container.height = newListHeight + MODAL_LIST_FRAME_HEIGHT + detailHeight;
78207
78099
  selector.setSelectedIndex(Math.min(selectedIndex, Math.max(options.length - 1, 0)));
78208
- },
78209
- setSelectedIndex(index) {
78210
- selector.setSelectedIndex(index);
78100
+ if (detailText) {
78101
+ detailText.content = formatDetail(selector.getSelectedIndex());
78102
+ }
78211
78103
  },
78212
78104
  close() {
78213
78105
  renderer.root.remove(config3.containerId);
@@ -78216,17 +78108,88 @@ function openModalList(config3) {
78216
78108
  };
78217
78109
  if (config3.onSelect) {
78218
78110
  selector.on(SelectRenderableEvents.ITEM_SELECTED, async (index, option) => {
78219
- await config3.onSelect?.(index, option);
78111
+ await config3.onSelect?.(index, currentOptions[index] ?? option);
78220
78112
  });
78221
78113
  }
78114
+ selector.on(SelectRenderableEvents.SELECTION_CHANGED, (index) => {
78115
+ if (detailText) {
78116
+ detailText.content = formatDetail(index);
78117
+ }
78118
+ });
78222
78119
  const initialIndex = config3.selectedIndex ?? 0;
78120
+ selector.setSelectedIndex(initialIndex);
78223
78121
  if (config3.focusList !== false) {
78224
78122
  selector.focus();
78225
- } else {
78226
- selector.setSelectedIndex(initialIndex);
78227
78123
  }
78228
78124
  return handle;
78229
78125
  }
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
+ }
78230
78193
  function getSlashCommandSelectOptions() {
78231
78194
  return slashCommandMatches.map((cmd) => ({
78232
78195
  name: `/${cmd.slash}`,
@@ -78234,11 +78197,54 @@ function getSlashCommandSelectOptions() {
78234
78197
  value: cmd
78235
78198
  }));
78236
78199
  }
78237
- function closeSlashCommandMenu() {
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) {
78238
78241
  if (slashCommandModal) {
78239
78242
  slashCommandModal.close();
78240
78243
  slashCommandModal = null;
78241
78244
  }
78245
+ if (dismissCurrentInput) {
78246
+ slashCommandDismissedInput = inputField?.editBuffer.getText() ?? null;
78247
+ }
78242
78248
  slashCommandMatches = [];
78243
78249
  slashCommandSelectedIndex = 0;
78244
78250
  }
@@ -78249,6 +78255,12 @@ function updateSlashCommandModalOptions() {
78249
78255
  }
78250
78256
  function syncSlashCommandMenu() {
78251
78257
  const inputText = inputField.editBuffer.getText();
78258
+ if (slashCommandDismissedInput !== null) {
78259
+ if (inputText === slashCommandDismissedInput) {
78260
+ return;
78261
+ }
78262
+ slashCommandDismissedInput = null;
78263
+ }
78252
78264
  const matches = getSlashCommandMatches(inputText);
78253
78265
  if (matches.length === 0) {
78254
78266
  closeSlashCommandMenu();
@@ -78351,17 +78363,17 @@ function handleKeypress(key) {
78351
78363
  inputField.focus();
78352
78364
  return;
78353
78365
  }
78354
- if (key.name === "return" && !key.shift && !key.ctrl && !key.meta) {
78355
- executeSelectedSlashCommand();
78356
- return;
78357
- }
78358
78366
  }
78359
78367
  if (key.ctrl && key.name === "p") {
78360
78368
  showCommandPalette();
78361
78369
  return;
78362
78370
  }
78363
78371
  if (key.ctrl && key.name === "t") {
78364
- cycleThinkingLevel();
78372
+ showThinkingSelector();
78373
+ return;
78374
+ }
78375
+ if (key.ctrl && key.name === "y") {
78376
+ showSafetySelector();
78365
78377
  return;
78366
78378
  }
78367
78379
  if (key.ctrl && key.name === "d") {
@@ -78400,20 +78412,32 @@ function handleKeypress(key) {
78400
78412
  closeCommandPalette();
78401
78413
  return;
78402
78414
  }
78403
- if (slashCommandMatches.length > 0) {
78404
- closeSlashCommandMenu();
78415
+ if (slashCommandModal) {
78416
+ closeSlashCommandMenu(true);
78405
78417
  return;
78406
78418
  }
78407
- if (modelSelector) {
78408
- renderer.root.remove("model-selector-container");
78409
- modelSelector = null;
78410
- inputField.focus();
78419
+ if (providerModal) {
78420
+ closeProviderModal();
78411
78421
  return;
78412
78422
  }
78413
- if (themeSelector) {
78414
- renderer.root.remove("theme-selector-container");
78415
- themeSelector = null;
78416
- 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);
78417
78441
  return;
78418
78442
  }
78419
78443
  if (awaitingConfirmation && pendingMessageId) {
@@ -78431,14 +78455,32 @@ function handleKeypress(key) {
78431
78455
  closeCommandPalette();
78432
78456
  return;
78433
78457
  }
78434
- if (slashCommandMatches.length > 0) {
78435
- closeSlashCommandMenu();
78458
+ if (slashCommandModal) {
78459
+ closeSlashCommandMenu(true);
78436
78460
  return;
78437
78461
  }
78438
- if (modelSelector) {
78439
- renderer.root.remove("model-selector-container");
78440
- modelSelector = null;
78441
- 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);
78442
78484
  return;
78443
78485
  }
78444
78486
  if (awaitingConfirmation && pendingMessageId) {
@@ -78474,7 +78516,7 @@ function handleKeypress(key) {
78474
78516
  addSystemMessage(`Copied to clipboard: ${msg.command}`);
78475
78517
  }
78476
78518
  }
78477
- if (key.name === "o" && !awaitingConfirmation && !commandPaletteModal && !modelSelector) {
78519
+ if (key.name === "o" && !awaitingConfirmation && !commandPaletteModal && !modelModal) {
78478
78520
  toggleLastResultExpand();
78479
78521
  }
78480
78522
  }