@austinthesing/magic-shell 0.2.29 → 1.0.1
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/README.md +95 -590
- package/dist/cli.js +762 -425
- package/dist/index.js +229 -50
- package/dist/tui.js +762 -425
- package/package.json +1 -1
package/dist/tui.js
CHANGED
|
@@ -33050,7 +33050,7 @@ var TabSelectRenderableEvents;
|
|
|
33050
33050
|
})(TabSelectRenderableEvents ||= {});
|
|
33051
33051
|
|
|
33052
33052
|
// src/cli.ts
|
|
33053
|
-
import { spawn } from "child_process";
|
|
33053
|
+
import { spawn as spawn2 } from "child_process";
|
|
33054
33054
|
import { cwd as getCwd } from "process";
|
|
33055
33055
|
|
|
33056
33056
|
// src/lib/models.ts
|
|
@@ -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
|
|
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
|
|
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: "
|
|
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: "
|
|
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
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
33291
|
+
description: "Top Claude reasoning model for complex tasks.",
|
|
33292
33292
|
category: "reasoning",
|
|
33293
33293
|
provider: "opencode-zen",
|
|
33294
33294
|
zenApiType: "anthropic",
|
|
@@ -33762,6 +33762,8 @@ var DEFAULT_CONFIG = {
|
|
|
33762
33762
|
],
|
|
33763
33763
|
confirmedDangerousPatterns: [],
|
|
33764
33764
|
repoContext: false,
|
|
33765
|
+
checkForUpdates: true,
|
|
33766
|
+
autoUpdate: false,
|
|
33765
33767
|
customModels: []
|
|
33766
33768
|
};
|
|
33767
33769
|
function ensureConfigDir() {
|
|
@@ -76782,6 +76784,215 @@ function loadTheme() {
|
|
|
76782
76784
|
}
|
|
76783
76785
|
loadTheme();
|
|
76784
76786
|
|
|
76787
|
+
// src/lib/update-checker.ts
|
|
76788
|
+
import { spawn } from "child_process";
|
|
76789
|
+
import { homedir as homedir3 } from "os";
|
|
76790
|
+
import { join as join4 } from "path";
|
|
76791
|
+
import { existsSync as existsSync8, readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2 } from "fs";
|
|
76792
|
+
var __dirname = "/Users/austin/code/dxd/magic-shell/src/lib";
|
|
76793
|
+
var PACKAGE_NAME = "@austinthesing/magic-shell";
|
|
76794
|
+
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
|
|
76795
|
+
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
76796
|
+
var CONFIG_DIR2 = join4(homedir3(), ".magic-shell");
|
|
76797
|
+
var UPDATE_CHECK_FILE = join4(CONFIG_DIR2, ".update-check");
|
|
76798
|
+
function ensureConfigDir2() {
|
|
76799
|
+
if (!existsSync8(CONFIG_DIR2)) {
|
|
76800
|
+
mkdirSync2(CONFIG_DIR2, { recursive: true });
|
|
76801
|
+
}
|
|
76802
|
+
}
|
|
76803
|
+
function loadUpdateState() {
|
|
76804
|
+
ensureConfigDir2();
|
|
76805
|
+
try {
|
|
76806
|
+
if (existsSync8(UPDATE_CHECK_FILE)) {
|
|
76807
|
+
return JSON.parse(readFileSync3(UPDATE_CHECK_FILE, "utf-8"));
|
|
76808
|
+
}
|
|
76809
|
+
} catch {}
|
|
76810
|
+
return { lastCheck: 0, latestVersion: null, dismissed: null };
|
|
76811
|
+
}
|
|
76812
|
+
function saveUpdateState(state) {
|
|
76813
|
+
ensureConfigDir2();
|
|
76814
|
+
try {
|
|
76815
|
+
writeFileSync3(UPDATE_CHECK_FILE, JSON.stringify(state));
|
|
76816
|
+
} catch {}
|
|
76817
|
+
}
|
|
76818
|
+
function getCurrentVersion() {
|
|
76819
|
+
try {
|
|
76820
|
+
const packagePaths = [
|
|
76821
|
+
join4(__dirname, "../../package.json"),
|
|
76822
|
+
join4(__dirname, "../../../package.json"),
|
|
76823
|
+
join4(process.cwd(), "package.json")
|
|
76824
|
+
];
|
|
76825
|
+
for (const path3 of packagePaths) {
|
|
76826
|
+
if (existsSync8(path3)) {
|
|
76827
|
+
const pkg = JSON.parse(readFileSync3(path3, "utf-8"));
|
|
76828
|
+
if (pkg.name === PACKAGE_NAME || pkg.name === "magic-shell") {
|
|
76829
|
+
return pkg.version;
|
|
76830
|
+
}
|
|
76831
|
+
}
|
|
76832
|
+
}
|
|
76833
|
+
} catch {}
|
|
76834
|
+
return "0.0.0";
|
|
76835
|
+
}
|
|
76836
|
+
function compareVersions(a, b2) {
|
|
76837
|
+
const partsA = a.split(".").map(Number);
|
|
76838
|
+
const partsB = b2.split(".").map(Number);
|
|
76839
|
+
for (let i = 0;i < Math.max(partsA.length, partsB.length); i++) {
|
|
76840
|
+
const numA = partsA[i] || 0;
|
|
76841
|
+
const numB = partsB[i] || 0;
|
|
76842
|
+
if (numA > numB)
|
|
76843
|
+
return 1;
|
|
76844
|
+
if (numA < numB)
|
|
76845
|
+
return -1;
|
|
76846
|
+
}
|
|
76847
|
+
return 0;
|
|
76848
|
+
}
|
|
76849
|
+
async function fetchLatestVersion() {
|
|
76850
|
+
try {
|
|
76851
|
+
const controller = new AbortController;
|
|
76852
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
76853
|
+
const response = await fetch(NPM_REGISTRY_URL, {
|
|
76854
|
+
signal: controller.signal,
|
|
76855
|
+
headers: { Accept: "application/json" }
|
|
76856
|
+
});
|
|
76857
|
+
clearTimeout(timeout);
|
|
76858
|
+
if (!response.ok)
|
|
76859
|
+
return null;
|
|
76860
|
+
const data = await response.json();
|
|
76861
|
+
return data.version || null;
|
|
76862
|
+
} catch {
|
|
76863
|
+
return null;
|
|
76864
|
+
}
|
|
76865
|
+
}
|
|
76866
|
+
function commandExists(command) {
|
|
76867
|
+
return new Promise((resolve4) => {
|
|
76868
|
+
const checker = process.platform === "win32" ? spawn("where", [command], { stdio: "ignore" }) : spawn("command", ["-v", command], { stdio: "ignore", shell: true });
|
|
76869
|
+
checker.on("close", (code) => resolve4(code === 0));
|
|
76870
|
+
checker.on("error", () => resolve4(false));
|
|
76871
|
+
});
|
|
76872
|
+
}
|
|
76873
|
+
async function resolveUpdateCommand() {
|
|
76874
|
+
if (await commandExists("bun")) {
|
|
76875
|
+
return `bun update -g ${PACKAGE_NAME}`;
|
|
76876
|
+
}
|
|
76877
|
+
if (await commandExists("npm")) {
|
|
76878
|
+
return `npm install -g ${PACKAGE_NAME}@latest`;
|
|
76879
|
+
}
|
|
76880
|
+
return `bun update -g ${PACKAGE_NAME}`;
|
|
76881
|
+
}
|
|
76882
|
+
async function buildUpdateInfo(latestVersion) {
|
|
76883
|
+
return {
|
|
76884
|
+
hasUpdate: true,
|
|
76885
|
+
currentVersion: getCurrentVersion(),
|
|
76886
|
+
latestVersion,
|
|
76887
|
+
updateCommand: await resolveUpdateCommand()
|
|
76888
|
+
};
|
|
76889
|
+
}
|
|
76890
|
+
async function checkForUpdates() {
|
|
76891
|
+
const state = loadUpdateState();
|
|
76892
|
+
const currentVersion = getCurrentVersion();
|
|
76893
|
+
const now2 = Date.now();
|
|
76894
|
+
if (now2 - state.lastCheck < CHECK_INTERVAL_MS) {
|
|
76895
|
+
if (state.latestVersion && compareVersions(state.latestVersion, currentVersion) > 0) {
|
|
76896
|
+
if (state.dismissed === state.latestVersion) {
|
|
76897
|
+
return null;
|
|
76898
|
+
}
|
|
76899
|
+
return await buildUpdateInfo(state.latestVersion);
|
|
76900
|
+
}
|
|
76901
|
+
return null;
|
|
76902
|
+
}
|
|
76903
|
+
const latestVersion = await fetchLatestVersion();
|
|
76904
|
+
state.lastCheck = now2;
|
|
76905
|
+
if (latestVersion) {
|
|
76906
|
+
state.latestVersion = latestVersion;
|
|
76907
|
+
}
|
|
76908
|
+
saveUpdateState(state);
|
|
76909
|
+
if (latestVersion && compareVersions(latestVersion, currentVersion) > 0) {
|
|
76910
|
+
if (state.dismissed === latestVersion) {
|
|
76911
|
+
return null;
|
|
76912
|
+
}
|
|
76913
|
+
return await buildUpdateInfo(latestVersion);
|
|
76914
|
+
}
|
|
76915
|
+
return null;
|
|
76916
|
+
}
|
|
76917
|
+
function dismissUpdate(version2) {
|
|
76918
|
+
const state = loadUpdateState();
|
|
76919
|
+
state.dismissed = version2;
|
|
76920
|
+
saveUpdateState(state);
|
|
76921
|
+
}
|
|
76922
|
+
async function forceCheckForUpdates() {
|
|
76923
|
+
const state = loadUpdateState();
|
|
76924
|
+
state.lastCheck = 0;
|
|
76925
|
+
saveUpdateState(state);
|
|
76926
|
+
return checkForUpdates();
|
|
76927
|
+
}
|
|
76928
|
+
async function performUpdate() {
|
|
76929
|
+
const updateCommand = await resolveUpdateCommand();
|
|
76930
|
+
return new Promise((resolve4) => {
|
|
76931
|
+
const child = spawn(updateCommand, {
|
|
76932
|
+
shell: true,
|
|
76933
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
76934
|
+
env: process.env
|
|
76935
|
+
});
|
|
76936
|
+
let stdout = "";
|
|
76937
|
+
let stderr = "";
|
|
76938
|
+
child.stdout?.on("data", (data) => {
|
|
76939
|
+
stdout += data.toString();
|
|
76940
|
+
});
|
|
76941
|
+
child.stderr?.on("data", (data) => {
|
|
76942
|
+
stderr += data.toString();
|
|
76943
|
+
});
|
|
76944
|
+
child.on("error", (error40) => {
|
|
76945
|
+
resolve4({
|
|
76946
|
+
success: false,
|
|
76947
|
+
output: error40 instanceof Error ? error40.message : String(error40)
|
|
76948
|
+
});
|
|
76949
|
+
});
|
|
76950
|
+
child.on("close", (code) => {
|
|
76951
|
+
const output = (stdout + stderr).trim() || updateCommand;
|
|
76952
|
+
resolve4({
|
|
76953
|
+
success: code === 0,
|
|
76954
|
+
output
|
|
76955
|
+
});
|
|
76956
|
+
});
|
|
76957
|
+
});
|
|
76958
|
+
}
|
|
76959
|
+
function formatUpdateMessageForTui(update, autoUpdate) {
|
|
76960
|
+
if (autoUpdate) {
|
|
76961
|
+
return `Update available (${update.currentVersion} → ${update.latestVersion}). Installing...`;
|
|
76962
|
+
}
|
|
76963
|
+
return [
|
|
76964
|
+
`Update available: ${update.currentVersion} → ${update.latestVersion}`,
|
|
76965
|
+
`Run /update to install, or /auto-update to enable automatic updates.`
|
|
76966
|
+
].join(`
|
|
76967
|
+
`);
|
|
76968
|
+
}
|
|
76969
|
+
async function processUpdateCheck(options) {
|
|
76970
|
+
const { checkForUpdates: updatesEnabled, autoUpdate, force = false, install = false } = options;
|
|
76971
|
+
if (!updatesEnabled && !force && !install) {
|
|
76972
|
+
return { action: "none" };
|
|
76973
|
+
}
|
|
76974
|
+
const update = force || install ? await forceCheckForUpdates() : await checkForUpdates();
|
|
76975
|
+
if (!update?.hasUpdate || !update.latestVersion) {
|
|
76976
|
+
if (force || install) {
|
|
76977
|
+
return { action: "up-to-date", currentVersion: getCurrentVersion() };
|
|
76978
|
+
}
|
|
76979
|
+
return { action: "none" };
|
|
76980
|
+
}
|
|
76981
|
+
if (install || autoUpdate) {
|
|
76982
|
+
const result = await performUpdate();
|
|
76983
|
+
if (result.success) {
|
|
76984
|
+
dismissUpdate(update.latestVersion);
|
|
76985
|
+
}
|
|
76986
|
+
return {
|
|
76987
|
+
action: "updated",
|
|
76988
|
+
update,
|
|
76989
|
+
success: result.success,
|
|
76990
|
+
output: result.output
|
|
76991
|
+
};
|
|
76992
|
+
}
|
|
76993
|
+
return { action: "notified", update };
|
|
76994
|
+
}
|
|
76995
|
+
|
|
76785
76996
|
// src/cli.ts
|
|
76786
76997
|
var renderer;
|
|
76787
76998
|
var currentModel = OPENCODE_ZEN_MODELS[0];
|
|
@@ -76815,12 +77026,11 @@ function getApiKeyUrl(provider) {
|
|
|
76815
77026
|
}
|
|
76816
77027
|
var inputHintText;
|
|
76817
77028
|
var helpBarText;
|
|
76818
|
-
var modelSelector = null;
|
|
76819
|
-
var providerSelector = null;
|
|
76820
77029
|
var slashCommandMatches = [];
|
|
76821
77030
|
var slashCommandSelectedIndex = 0;
|
|
76822
77031
|
var slashCommandSyncQueued = false;
|
|
76823
77032
|
var slashCommandExecuting = false;
|
|
77033
|
+
var slashCommandDismissedInput = null;
|
|
76824
77034
|
var pendingMessageId = null;
|
|
76825
77035
|
var awaitingConfirmation = false;
|
|
76826
77036
|
function generateMessageId() {
|
|
@@ -76832,13 +77042,16 @@ function isFreeModel(model) {
|
|
|
76832
77042
|
function costTierLabel(tier) {
|
|
76833
77043
|
switch (tier) {
|
|
76834
77044
|
case "free":
|
|
76835
|
-
return "
|
|
77045
|
+
return "Free";
|
|
76836
77046
|
case "lower-cost":
|
|
76837
|
-
return "
|
|
77047
|
+
return "Lower Cost";
|
|
76838
77048
|
case "premium":
|
|
76839
|
-
return "
|
|
77049
|
+
return "Premium";
|
|
76840
77050
|
}
|
|
76841
77051
|
}
|
|
77052
|
+
function getModelDisplayName(model) {
|
|
77053
|
+
return model.cost === "free" ? model.name.replace(/\s+Free$/i, "") : model.name;
|
|
77054
|
+
}
|
|
76842
77055
|
async function main() {
|
|
76843
77056
|
config2 = loadConfig();
|
|
76844
77057
|
history = loadHistory();
|
|
@@ -76890,53 +77103,50 @@ async function showProviderSetup() {
|
|
|
76890
77103
|
const options = [
|
|
76891
77104
|
{
|
|
76892
77105
|
name: "OpenCode Zen (Recommended)",
|
|
76893
|
-
description: "Curated models
|
|
77106
|
+
description: "Curated coding models with a generous free tier.",
|
|
76894
77107
|
value: "opencode-zen"
|
|
76895
77108
|
},
|
|
76896
77109
|
{
|
|
76897
77110
|
name: "OpenRouter",
|
|
76898
|
-
description: "
|
|
77111
|
+
description: "Broad model catalog across major providers.",
|
|
76899
77112
|
value: "openrouter"
|
|
76900
77113
|
},
|
|
76901
77114
|
{
|
|
76902
77115
|
name: "Vercel AI Gateway",
|
|
76903
|
-
description: "
|
|
77116
|
+
description: "Vercel-hosted gateway for managed model access.",
|
|
76904
77117
|
value: "vercel-ai-gateway"
|
|
76905
77118
|
},
|
|
76906
77119
|
{
|
|
76907
77120
|
name: "Cloudflare AI Gateway",
|
|
76908
|
-
description: "Cloudflare gateway for provider and Workers AI
|
|
77121
|
+
description: "Cloudflare gateway for provider and Workers AI routing.",
|
|
76909
77122
|
value: "cloudflare-ai-gateway"
|
|
76910
77123
|
},
|
|
76911
77124
|
{
|
|
76912
77125
|
name: "Cloudflare Workers AI",
|
|
76913
|
-
description: "Cloudflare-hosted models
|
|
77126
|
+
description: "Cloudflare-hosted models with direct Workers AI access.",
|
|
76914
77127
|
value: "workers-ai"
|
|
76915
77128
|
}
|
|
76916
77129
|
];
|
|
76917
|
-
|
|
76918
|
-
|
|
76919
|
-
|
|
76920
|
-
|
|
77130
|
+
let providerSetupModal = null;
|
|
77131
|
+
providerSetupModal = openModalList({
|
|
77132
|
+
containerId: "provider-setup-container",
|
|
77133
|
+
selectorId: "provider-select",
|
|
77134
|
+
title: "Choose Provider",
|
|
77135
|
+
width: 65,
|
|
76921
77136
|
options,
|
|
76922
|
-
|
|
76923
|
-
|
|
76924
|
-
|
|
76925
|
-
|
|
76926
|
-
|
|
76927
|
-
|
|
76928
|
-
|
|
76929
|
-
|
|
76930
|
-
|
|
76931
|
-
|
|
76932
|
-
|
|
76933
|
-
|
|
76934
|
-
|
|
76935
|
-
config2.provider = provider;
|
|
76936
|
-
saveConfig(config2);
|
|
76937
|
-
renderer.root.remove("setup-container");
|
|
76938
|
-
providerSelector = null;
|
|
76939
|
-
await showApiKeyInput(provider);
|
|
77137
|
+
onSelect: async (_2, option) => {
|
|
77138
|
+
const provider = option.value;
|
|
77139
|
+
config2.provider = provider;
|
|
77140
|
+
saveConfig(config2);
|
|
77141
|
+
providerSetupModal?.close();
|
|
77142
|
+
providerSetupModal = null;
|
|
77143
|
+
renderer.root.remove("setup-container");
|
|
77144
|
+
await showApiKeyInput(provider, {
|
|
77145
|
+
onCancel: () => {
|
|
77146
|
+
showProviderSetup();
|
|
77147
|
+
}
|
|
77148
|
+
});
|
|
77149
|
+
}
|
|
76940
77150
|
});
|
|
76941
77151
|
const hint = new TextRenderable(renderer, {
|
|
76942
77152
|
id: "setup-hint",
|
|
@@ -76945,76 +77155,39 @@ ${fg("#64748b")("Use arrow keys to select | Enter to confirm | Ctrl+C to exit")}
|
|
|
76945
77155
|
marginTop: 1
|
|
76946
77156
|
});
|
|
76947
77157
|
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
77158
|
}
|
|
76956
|
-
async function showApiKeyInput(provider) {
|
|
76957
|
-
|
|
76958
|
-
|
|
76959
|
-
|
|
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);
|
|
77159
|
+
async function showApiKeyInput(provider, options) {
|
|
77160
|
+
if (apiKeyModal)
|
|
77161
|
+
return;
|
|
77162
|
+
apiKeyModalOnCancel = options?.onCancel ?? null;
|
|
76971
77163
|
const url2 = getApiKeyUrl(provider);
|
|
76972
|
-
const
|
|
76973
|
-
|
|
76974
|
-
|
|
76975
|
-
|
|
76976
|
-
|
|
76977
|
-
|
|
76978
|
-
|
|
76979
|
-
|
|
76980
|
-
|
|
76981
|
-
|
|
76982
|
-
|
|
76983
|
-
|
|
76984
|
-
|
|
76985
|
-
|
|
76986
|
-
|
|
76987
|
-
|
|
76988
|
-
|
|
76989
|
-
|
|
76990
|
-
|
|
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());
|
|
77164
|
+
const extraText = provider === "opencode-zen" ? "Tip: OpenCode Zen has free models like Kimi K2.6 and DeepSeek V4 Flash!" : undefined;
|
|
77165
|
+
apiKeyModal = openInputModal({
|
|
77166
|
+
containerId: "apikey-modal",
|
|
77167
|
+
title: `${getProviderDisplayName(provider)} Setup`,
|
|
77168
|
+
width: 72,
|
|
77169
|
+
height: provider === "opencode-zen" ? 13 : 11,
|
|
77170
|
+
placeholder: provider === "openrouter" ? "API key or token" : "API token",
|
|
77171
|
+
description: [
|
|
77172
|
+
`Get your API key from: ${url2}`,
|
|
77173
|
+
"",
|
|
77174
|
+
"Enter your API key below:"
|
|
77175
|
+
].join(`
|
|
77176
|
+
`),
|
|
77177
|
+
extraText,
|
|
77178
|
+
onSubmit: (value) => {
|
|
77179
|
+
const trimmed = value.trim();
|
|
77180
|
+
if (!trimmed)
|
|
77181
|
+
return;
|
|
77182
|
+
setApiKey(provider, trimmed);
|
|
77009
77183
|
const providerModels = getProviderModels(provider);
|
|
77010
77184
|
currentModel = providerModels.find((m2) => !m2.disabled) || providerModels[0] || OPENCODE_ZEN_MODELS[0];
|
|
77011
77185
|
config2.defaultModel = currentModel.id;
|
|
77012
77186
|
saveConfig(config2);
|
|
77013
|
-
|
|
77187
|
+
closeApiKeyModal();
|
|
77014
77188
|
createMainUI();
|
|
77015
77189
|
}
|
|
77016
77190
|
});
|
|
77017
|
-
input.focus();
|
|
77018
77191
|
}
|
|
77019
77192
|
function createMainUI() {
|
|
77020
77193
|
const theme = getTheme();
|
|
@@ -77072,6 +77245,7 @@ function createMainUI() {
|
|
|
77072
77245
|
});
|
|
77073
77246
|
mainContainer.add(chatScrollBox);
|
|
77074
77247
|
addSystemMessage(getWelcomeMessage());
|
|
77248
|
+
handleStartupUpdateCheck();
|
|
77075
77249
|
inputContainer = new BoxRenderable(renderer, {
|
|
77076
77250
|
id: "input-container",
|
|
77077
77251
|
flexDirection: "column",
|
|
@@ -77119,7 +77293,7 @@ function createMainUI() {
|
|
|
77119
77293
|
content: getInputHintContent(),
|
|
77120
77294
|
marginTop: 1
|
|
77121
77295
|
});
|
|
77122
|
-
|
|
77296
|
+
mainContainer.add(inputHintText);
|
|
77123
77297
|
helpBarText = new TextRenderable(renderer, {
|
|
77124
77298
|
id: "help-bar-text",
|
|
77125
77299
|
content: getHelpBarContent(),
|
|
@@ -77145,7 +77319,7 @@ function getHelpBarContent() {
|
|
|
77145
77319
|
if (awaitingConfirmation) {
|
|
77146
77320
|
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
77321
|
}
|
|
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")}`;
|
|
77322
|
+
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
77323
|
}
|
|
77150
77324
|
function getInputHintContent() {
|
|
77151
77325
|
const theme = getTheme();
|
|
@@ -77156,6 +77330,67 @@ function getWelcomeMessage() {
|
|
|
77156
77330
|
return `Ready. Using ${providerName}.
|
|
77157
77331
|
Type what you want to do, or press Ctrl+P for Commands.`;
|
|
77158
77332
|
}
|
|
77333
|
+
async function handleStartupUpdateCheck() {
|
|
77334
|
+
try {
|
|
77335
|
+
const result = await processUpdateCheck({
|
|
77336
|
+
checkForUpdates: config2.checkForUpdates !== false,
|
|
77337
|
+
autoUpdate: config2.autoUpdate === true
|
|
77338
|
+
});
|
|
77339
|
+
switch (result.action) {
|
|
77340
|
+
case "notified":
|
|
77341
|
+
addSystemMessage(formatUpdateMessageForTui(result.update, false));
|
|
77342
|
+
break;
|
|
77343
|
+
case "updated":
|
|
77344
|
+
if (result.success) {
|
|
77345
|
+
addSystemMessage(`Updated to v${result.update.latestVersion}. Restart mshell to use the new version.`);
|
|
77346
|
+
} else {
|
|
77347
|
+
addSystemMessage(`Auto-update failed:
|
|
77348
|
+
${result.output}
|
|
77349
|
+
Try manually: ${result.update.updateCommand}`);
|
|
77350
|
+
}
|
|
77351
|
+
break;
|
|
77352
|
+
}
|
|
77353
|
+
} catch {}
|
|
77354
|
+
}
|
|
77355
|
+
async function runManualUpdate() {
|
|
77356
|
+
addSystemMessage("Checking for updates...");
|
|
77357
|
+
try {
|
|
77358
|
+
const result = await processUpdateCheck({
|
|
77359
|
+
checkForUpdates: true,
|
|
77360
|
+
autoUpdate: false,
|
|
77361
|
+
force: true,
|
|
77362
|
+
install: true
|
|
77363
|
+
});
|
|
77364
|
+
switch (result.action) {
|
|
77365
|
+
case "up-to-date":
|
|
77366
|
+
addSystemMessage(`Already on the latest version (${result.currentVersion}).`);
|
|
77367
|
+
break;
|
|
77368
|
+
case "updated":
|
|
77369
|
+
if (result.success) {
|
|
77370
|
+
addSystemMessage(`Updated to v${result.update.latestVersion}. Restart mshell to use the new version.`);
|
|
77371
|
+
} else {
|
|
77372
|
+
addSystemMessage(`Update failed:
|
|
77373
|
+
${result.output}
|
|
77374
|
+
Try manually: ${result.update.updateCommand}`);
|
|
77375
|
+
}
|
|
77376
|
+
break;
|
|
77377
|
+
case "none":
|
|
77378
|
+
addSystemMessage("Could not check for updates.");
|
|
77379
|
+
break;
|
|
77380
|
+
}
|
|
77381
|
+
} catch (error40) {
|
|
77382
|
+
const message = error40 instanceof Error ? error40.message : String(error40);
|
|
77383
|
+
addSystemMessage(`Update check failed: ${message}`);
|
|
77384
|
+
}
|
|
77385
|
+
}
|
|
77386
|
+
function toggleAutoUpdate() {
|
|
77387
|
+
config2.autoUpdate = !config2.autoUpdate;
|
|
77388
|
+
if (config2.autoUpdate) {
|
|
77389
|
+
config2.checkForUpdates = true;
|
|
77390
|
+
}
|
|
77391
|
+
saveConfig(config2);
|
|
77392
|
+
addSystemMessage(`Auto-update: ${config2.autoUpdate ? "ON" : "OFF"}`);
|
|
77393
|
+
}
|
|
77159
77394
|
function addSystemMessage(content) {
|
|
77160
77395
|
const msg = {
|
|
77161
77396
|
id: generateMessageId(),
|
|
@@ -77476,6 +77711,18 @@ async function executeSelectedSlashCommand() {
|
|
|
77476
77711
|
async function tryHandleSlashCommand(input) {
|
|
77477
77712
|
if (!input.startsWith("/"))
|
|
77478
77713
|
return false;
|
|
77714
|
+
const slashBody = input.slice(1).trim().toLowerCase();
|
|
77715
|
+
if (!slashBody.includes(" ") && slashCommandMatches.length > 0) {
|
|
77716
|
+
const selected = slashCommandMatches[Math.min(slashCommandSelectedIndex, slashCommandMatches.length - 1)];
|
|
77717
|
+
const exactMatch = slashCommandMatches.find((cmd) => cmd.slash === slashBody);
|
|
77718
|
+
await (exactMatch ?? selected).action();
|
|
77719
|
+
return true;
|
|
77720
|
+
}
|
|
77721
|
+
const exactCommand = getSlashCommands().find((cmd) => cmd.slash === slashBody);
|
|
77722
|
+
if (exactCommand) {
|
|
77723
|
+
await exactCommand.action();
|
|
77724
|
+
return true;
|
|
77725
|
+
}
|
|
77479
77726
|
await handleSpecialCommand(input);
|
|
77480
77727
|
return true;
|
|
77481
77728
|
}
|
|
@@ -77578,7 +77825,7 @@ function getExecutionKind(assistantMsgId, isDryRun) {
|
|
|
77578
77825
|
}
|
|
77579
77826
|
function executeCommandWithCode(command) {
|
|
77580
77827
|
return new Promise((resolve4, reject) => {
|
|
77581
|
-
const child =
|
|
77828
|
+
const child = spawn2(command, {
|
|
77582
77829
|
shell: true,
|
|
77583
77830
|
cwd: currentCwd,
|
|
77584
77831
|
env: process.env
|
|
@@ -77631,7 +77878,10 @@ async function handleSpecialCommand(input) {
|
|
|
77631
77878
|
break;
|
|
77632
77879
|
case "thinking":
|
|
77633
77880
|
case "think":
|
|
77634
|
-
|
|
77881
|
+
showThinkingSelector();
|
|
77882
|
+
break;
|
|
77883
|
+
case "safety":
|
|
77884
|
+
showSafetySelector();
|
|
77635
77885
|
break;
|
|
77636
77886
|
case "config":
|
|
77637
77887
|
await showConfig();
|
|
@@ -77639,6 +77889,12 @@ async function handleSpecialCommand(input) {
|
|
|
77639
77889
|
case "history":
|
|
77640
77890
|
showHistory();
|
|
77641
77891
|
break;
|
|
77892
|
+
case "update":
|
|
77893
|
+
await runManualUpdate();
|
|
77894
|
+
break;
|
|
77895
|
+
case "auto-update":
|
|
77896
|
+
toggleAutoUpdate();
|
|
77897
|
+
break;
|
|
77642
77898
|
case "clear":
|
|
77643
77899
|
clearChat();
|
|
77644
77900
|
break;
|
|
@@ -77664,7 +77920,8 @@ function clearChat() {
|
|
|
77664
77920
|
function showHelp() {
|
|
77665
77921
|
const helpText = `Shortcuts:
|
|
77666
77922
|
Ctrl+P Commands
|
|
77667
|
-
Ctrl+T
|
|
77923
|
+
Ctrl+T Select thinking level
|
|
77924
|
+
Ctrl+Y Select safety level
|
|
77668
77925
|
Ctrl+C Exit magic-shell
|
|
77669
77926
|
Ctrl+D Exit magic-shell
|
|
77670
77927
|
Esc Cancel / Close popup
|
|
@@ -77678,8 +77935,10 @@ Q Exit
|
|
|
77678
77935
|
Commands (type ! or / followed by):
|
|
77679
77936
|
help Show this help models Change model
|
|
77680
77937
|
provider Switch provider themes Change theme
|
|
77681
|
-
dry Toggle dry-run
|
|
77938
|
+
dry Toggle dry-run safety Select safety
|
|
77939
|
+
thinking Select thinking
|
|
77682
77940
|
config Show config history Show history
|
|
77941
|
+
update Check for updates auto-update Toggle auto-update
|
|
77683
77942
|
clear Clear chat exit Exit
|
|
77684
77943
|
|
|
77685
77944
|
Safety Levels:
|
|
@@ -77722,6 +77981,9 @@ Safety: ${config2.safetyLevel}
|
|
|
77722
77981
|
Thinking: ${config2.thinkingLevel}
|
|
77723
77982
|
Dry-run: ${dryRunMode ? "ON" : "OFF"}
|
|
77724
77983
|
Repo context: ${config2.repoContext ? "ON" : "OFF"}
|
|
77984
|
+
Version: ${getCurrentVersion()}
|
|
77985
|
+
Updates: ${config2.checkForUpdates !== false ? "checking enabled" : "checking disabled"}
|
|
77986
|
+
Auto-update: ${config2.autoUpdate ? "ON" : "OFF"}
|
|
77725
77987
|
API Key: ${apiKeyStatus}
|
|
77726
77988
|
History: ${history.length} commands`;
|
|
77727
77989
|
addSystemMessage(configText);
|
|
@@ -77742,29 +78004,14 @@ ${lines.join(`
|
|
|
77742
78004
|
`)}`);
|
|
77743
78005
|
}
|
|
77744
78006
|
async function switchProvider() {
|
|
77745
|
-
|
|
77746
|
-
|
|
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);
|
|
78007
|
+
if (providerModal)
|
|
78008
|
+
return;
|
|
77762
78009
|
const providers = [
|
|
77763
|
-
{ provider: "opencode-zen", description: "Curated models
|
|
77764
|
-
{ provider: "openrouter", description: "
|
|
77765
|
-
{ provider: "vercel-ai-gateway", description: "
|
|
77766
|
-
{ provider: "cloudflare-ai-gateway", description: "Cloudflare gateway for provider and Workers AI
|
|
77767
|
-
{ provider: "workers-ai", description: "Cloudflare-hosted models
|
|
78010
|
+
{ provider: "opencode-zen", description: "Curated coding models with a generous free tier." },
|
|
78011
|
+
{ provider: "openrouter", description: "Broad model catalog across major providers." },
|
|
78012
|
+
{ provider: "vercel-ai-gateway", description: "Vercel-hosted gateway for managed model access." },
|
|
78013
|
+
{ provider: "cloudflare-ai-gateway", description: "Cloudflare gateway for provider and Workers AI routing." },
|
|
78014
|
+
{ provider: "workers-ai", description: "Cloudflare-hosted models with direct Workers AI access." }
|
|
77768
78015
|
];
|
|
77769
78016
|
const options = await Promise.all(providers.map(async ({ provider, description }) => {
|
|
77770
78017
|
const key = await getApiKey(provider);
|
|
@@ -77774,210 +78021,178 @@ async function switchProvider() {
|
|
|
77774
78021
|
value: provider
|
|
77775
78022
|
};
|
|
77776
78023
|
}));
|
|
77777
|
-
|
|
77778
|
-
|
|
77779
|
-
|
|
77780
|
-
|
|
78024
|
+
providerModal = openModalList({
|
|
78025
|
+
containerId: "provider-selector-container",
|
|
78026
|
+
selectorId: "provider-switch-select",
|
|
78027
|
+
title: "Switch Provider",
|
|
78028
|
+
width: 65,
|
|
77781
78029
|
options,
|
|
77782
|
-
|
|
77783
|
-
|
|
77784
|
-
|
|
77785
|
-
|
|
77786
|
-
|
|
77787
|
-
|
|
77788
|
-
|
|
77789
|
-
|
|
77790
|
-
|
|
77791
|
-
|
|
77792
|
-
|
|
77793
|
-
|
|
77794
|
-
|
|
77795
|
-
|
|
77796
|
-
|
|
77797
|
-
|
|
77798
|
-
|
|
77799
|
-
|
|
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);
|
|
78030
|
+
selectedIndex: Math.max(0, providers.findIndex(({ provider }) => provider === config2.provider)),
|
|
78031
|
+
onSelect: async (_2, option) => {
|
|
78032
|
+
const newProvider = option.value;
|
|
78033
|
+
const existingKey = await getApiKey(newProvider);
|
|
78034
|
+
if (existingKey) {
|
|
78035
|
+
config2.provider = newProvider;
|
|
78036
|
+
const models = getProviderModels(newProvider);
|
|
78037
|
+
currentModel = models.find((m2) => m2.id === config2.defaultModel) || models[0];
|
|
78038
|
+
config2.defaultModel = currentModel.id;
|
|
78039
|
+
saveConfig(config2);
|
|
78040
|
+
statusBarText.content = getStatusBarContent();
|
|
78041
|
+
closeProviderModal();
|
|
78042
|
+
const providerName = getProviderDisplayName(newProvider);
|
|
78043
|
+
addSystemMessage(`Switched to ${providerName}. Model: ${currentModel.name}`);
|
|
78044
|
+
} else {
|
|
78045
|
+
closeProviderModal();
|
|
78046
|
+
await showApiKeyInput(newProvider);
|
|
78047
|
+
}
|
|
77814
78048
|
}
|
|
77815
78049
|
});
|
|
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
78050
|
}
|
|
77825
78051
|
function showModelSelector() {
|
|
77826
|
-
if (
|
|
78052
|
+
if (modelModal)
|
|
77827
78053
|
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
78054
|
const allModels = getProviderModels(config2.provider);
|
|
77847
78055
|
const availableModels = allModels.filter((m2) => !m2.disabled);
|
|
77848
78056
|
const sortedModels = sortModelsByCost(availableModels);
|
|
77849
78057
|
const customModels = getCustomModels().sort((a, b2) => a.name.localeCompare(b2.name));
|
|
77850
78058
|
const options = [
|
|
77851
78059
|
...sortedModels.map((model) => ({
|
|
77852
|
-
name: `${model
|
|
78060
|
+
name: `${getModelDisplayName(model)} [${costTierLabel(model.cost)}]`,
|
|
77853
78061
|
description: model.description,
|
|
77854
78062
|
value: model
|
|
77855
78063
|
})),
|
|
77856
78064
|
...customModels.map((model) => ({
|
|
77857
|
-
name: `${model.name} [
|
|
78065
|
+
name: `${model.name} [Custom]`,
|
|
77858
78066
|
description: `${model.baseUrl} - ${model.modelId}`,
|
|
77859
78067
|
value: model
|
|
77860
78068
|
}))
|
|
77861
78069
|
];
|
|
77862
|
-
|
|
77863
|
-
|
|
77864
|
-
|
|
77865
|
-
|
|
78070
|
+
modelModal = openModalList({
|
|
78071
|
+
containerId: "model-selector-container",
|
|
78072
|
+
selectorId: "model-select",
|
|
78073
|
+
title: `Select Model (${getProviderDisplayName(config2.provider)})`,
|
|
78074
|
+
width: 75,
|
|
77866
78075
|
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
78076
|
showScrollIndicator: true,
|
|
77876
|
-
|
|
77877
|
-
|
|
77878
|
-
|
|
77879
|
-
|
|
77880
|
-
|
|
77881
|
-
|
|
77882
|
-
|
|
77883
|
-
|
|
77884
|
-
|
|
77885
|
-
|
|
77886
|
-
|
|
77887
|
-
|
|
77888
|
-
const freeBadge = isFreeModel(currentModel) ? " (FREE)" : "";
|
|
77889
|
-
const customBadge = isCustom ? " (custom)" : "";
|
|
77890
|
-
addSystemMessage(`Model changed to ${currentModel.name}${freeBadge}${customBadge}`);
|
|
78077
|
+
selectedIndex: Math.max(0, options.findIndex((option) => option.value.id === currentModel.id)),
|
|
78078
|
+
onSelect: (_2, option) => {
|
|
78079
|
+
currentModel = option.value;
|
|
78080
|
+
config2.defaultModel = currentModel.id;
|
|
78081
|
+
saveConfig(config2);
|
|
78082
|
+
statusBarText.content = getStatusBarContent();
|
|
78083
|
+
closeModelModal();
|
|
78084
|
+
const isCustom = isCustomModel(currentModel);
|
|
78085
|
+
const freeBadge = isFreeModel(currentModel) ? " (FREE)" : "";
|
|
78086
|
+
const customBadge = isCustom ? " (custom)" : "";
|
|
78087
|
+
addSystemMessage(`Model changed to ${currentModel.name}${freeBadge}${customBadge}`);
|
|
78088
|
+
}
|
|
77891
78089
|
});
|
|
77892
|
-
modelSelector.focus();
|
|
77893
78090
|
}
|
|
77894
|
-
var themeSelector = null;
|
|
77895
78091
|
function showThemeSelector() {
|
|
77896
|
-
if (
|
|
78092
|
+
if (themeModal)
|
|
77897
78093
|
return;
|
|
77898
|
-
}
|
|
77899
78094
|
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
78095
|
const options = themeNames.map((name24) => ({
|
|
77921
78096
|
name: name24 === currentTheme2.name ? `${name24} (current)` : name24,
|
|
77922
78097
|
description: "",
|
|
77923
78098
|
value: name24
|
|
77924
78099
|
}));
|
|
77925
|
-
|
|
77926
|
-
|
|
77927
|
-
|
|
77928
|
-
|
|
78100
|
+
themeModal = openModalList({
|
|
78101
|
+
containerId: "theme-selector-container",
|
|
78102
|
+
selectorId: "theme-select",
|
|
78103
|
+
title: "Select Theme",
|
|
78104
|
+
width: 45,
|
|
77929
78105
|
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
78106
|
showDescription: false,
|
|
77938
|
-
|
|
77939
|
-
|
|
77940
|
-
|
|
77941
|
-
|
|
77942
|
-
|
|
77943
|
-
|
|
77944
|
-
|
|
77945
|
-
|
|
77946
|
-
refreshThemeColors();
|
|
77947
|
-
addSystemMessage(`Theme changed to ${themeName}`);
|
|
77948
|
-
inputField.focus();
|
|
78107
|
+
selectedIndex: Math.max(0, themeNames.findIndex((name24) => name24 === currentTheme2.name)),
|
|
78108
|
+
onSelect: (_2, option) => {
|
|
78109
|
+
const themeName = option.value;
|
|
78110
|
+
setTheme(themeName);
|
|
78111
|
+
closeThemeModal();
|
|
78112
|
+
refreshThemeColors();
|
|
78113
|
+
addSystemMessage(`Theme changed to ${themeName}`);
|
|
78114
|
+
}
|
|
77949
78115
|
});
|
|
77950
|
-
|
|
77951
|
-
|
|
77952
|
-
|
|
77953
|
-
|
|
77954
|
-
|
|
77955
|
-
|
|
78116
|
+
}
|
|
78117
|
+
function showSafetySelector() {
|
|
78118
|
+
if (safetyModal)
|
|
78119
|
+
return;
|
|
78120
|
+
const levels = ["strict", "moderate", "relaxed"];
|
|
78121
|
+
const descriptions = {
|
|
78122
|
+
strict: "Confirm every potentially dangerous command.",
|
|
78123
|
+
moderate: "Confirm high and critical risk commands.",
|
|
78124
|
+
relaxed: "Only confirm critical risk commands."
|
|
78125
|
+
};
|
|
78126
|
+
safetyModal = openModalList({
|
|
78127
|
+
containerId: "safety-selector-container",
|
|
78128
|
+
selectorId: "safety-select",
|
|
78129
|
+
title: "Safety Level",
|
|
78130
|
+
width: 58,
|
|
78131
|
+
options: levels.map((level) => ({
|
|
78132
|
+
name: level === config2.safetyLevel ? `${level} (current)` : level,
|
|
78133
|
+
description: descriptions[level],
|
|
78134
|
+
value: level
|
|
78135
|
+
})),
|
|
78136
|
+
selectedIndex: Math.max(0, levels.findIndex((level) => level === config2.safetyLevel)),
|
|
78137
|
+
onSelect: (_2, option) => {
|
|
78138
|
+
config2.safetyLevel = option.value;
|
|
78139
|
+
saveConfig(config2);
|
|
78140
|
+
statusBarText.content = getStatusBarContent();
|
|
78141
|
+
closeSafetyModal();
|
|
78142
|
+
addSystemMessage(`Safety level: ${config2.safetyLevel}`);
|
|
77956
78143
|
}
|
|
78144
|
+
});
|
|
78145
|
+
}
|
|
78146
|
+
function showThinkingSelector() {
|
|
78147
|
+
if (thinkingModal)
|
|
78148
|
+
return;
|
|
78149
|
+
const levels = ["low", "medium", "high", "off"];
|
|
78150
|
+
const descriptions = {
|
|
78151
|
+
low: "Use light reasoning for supported models.",
|
|
78152
|
+
medium: "Use balanced reasoning for supported models.",
|
|
78153
|
+
high: "Use maximum reasoning for supported models.",
|
|
78154
|
+
off: "Disable extra reasoning controls."
|
|
77957
78155
|
};
|
|
77958
|
-
|
|
77959
|
-
|
|
78156
|
+
thinkingModal = openModalList({
|
|
78157
|
+
containerId: "thinking-selector-container",
|
|
78158
|
+
selectorId: "thinking-select",
|
|
78159
|
+
title: "Thinking Level",
|
|
78160
|
+
width: 58,
|
|
78161
|
+
options: levels.map((level) => ({
|
|
78162
|
+
name: level === config2.thinkingLevel ? `${level} (current)` : level,
|
|
78163
|
+
description: descriptions[level],
|
|
78164
|
+
value: level
|
|
78165
|
+
})),
|
|
78166
|
+
selectedIndex: Math.max(0, levels.findIndex((level) => level === config2.thinkingLevel)),
|
|
78167
|
+
onSelect: (_2, option) => {
|
|
78168
|
+
config2.thinkingLevel = option.value;
|
|
78169
|
+
saveConfig(config2);
|
|
78170
|
+
statusBarText.content = getStatusBarContent();
|
|
78171
|
+
closeThinkingModal();
|
|
78172
|
+
addSystemMessage(`Thinking level: ${config2.thinkingLevel}`);
|
|
78173
|
+
}
|
|
78174
|
+
});
|
|
77960
78175
|
}
|
|
77961
78176
|
var MODAL_LIST_WIDTH = 55;
|
|
77962
78177
|
var MODAL_LIST_MAX_ITEMS = 12;
|
|
78178
|
+
var MODAL_LIST_FRAME_HEIGHT = 4;
|
|
78179
|
+
var providerModal = null;
|
|
78180
|
+
var modelModal = null;
|
|
78181
|
+
var themeModal = null;
|
|
78182
|
+
var safetyModal = null;
|
|
78183
|
+
var thinkingModal = null;
|
|
77963
78184
|
var commandPaletteModal = null;
|
|
77964
78185
|
var slashCommandModal = null;
|
|
78186
|
+
var apiKeyModal = null;
|
|
78187
|
+
var apiKeyModalOnCancel = null;
|
|
77965
78188
|
var commandPaletteQuery = "";
|
|
77966
78189
|
var chordMode = "none";
|
|
77967
|
-
function
|
|
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() {
|
|
78190
|
+
function getAppCommands() {
|
|
77977
78191
|
return [
|
|
77978
78192
|
{
|
|
77979
78193
|
name: "Change Model",
|
|
77980
78194
|
description: `Current: ${currentModel.name}`,
|
|
78195
|
+
slash: "models",
|
|
77981
78196
|
shortcut: "Ctrl+X M",
|
|
77982
78197
|
chord: "m",
|
|
77983
78198
|
action: () => showModelSelector()
|
|
@@ -77985,11 +78200,13 @@ function getCommandPaletteOptions() {
|
|
|
77985
78200
|
{
|
|
77986
78201
|
name: "Switch Provider",
|
|
77987
78202
|
description: `Current: ${getProviderDisplayName(config2.provider)}`,
|
|
78203
|
+
slash: "providers",
|
|
77988
78204
|
action: () => switchProvider()
|
|
77989
78205
|
},
|
|
77990
78206
|
{
|
|
77991
78207
|
name: "Toggle Dry Run",
|
|
77992
78208
|
description: dryRunMode ? "Currently ON" : "Currently OFF",
|
|
78209
|
+
slash: "dry",
|
|
77993
78210
|
action: () => {
|
|
77994
78211
|
dryRunMode = !dryRunMode;
|
|
77995
78212
|
statusBarText.content = getStatusBarContent();
|
|
@@ -77997,28 +78214,18 @@ function getCommandPaletteOptions() {
|
|
|
77997
78214
|
}
|
|
77998
78215
|
},
|
|
77999
78216
|
{
|
|
78000
|
-
name: "
|
|
78217
|
+
name: "Select Safety Level",
|
|
78001
78218
|
description: `Current: ${config2.safetyLevel}`,
|
|
78002
|
-
|
|
78003
|
-
|
|
78004
|
-
|
|
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
|
-
}
|
|
78219
|
+
slash: "safety",
|
|
78220
|
+
shortcut: "Ctrl+Y",
|
|
78221
|
+
action: () => showSafetySelector()
|
|
78016
78222
|
},
|
|
78017
78223
|
{
|
|
78018
|
-
name: "
|
|
78224
|
+
name: "Select Thinking Level",
|
|
78019
78225
|
description: `Current: ${config2.thinkingLevel}`,
|
|
78226
|
+
slash: "thinking",
|
|
78020
78227
|
shortcut: "Ctrl+T",
|
|
78021
|
-
action: () =>
|
|
78228
|
+
action: () => showThinkingSelector()
|
|
78022
78229
|
},
|
|
78023
78230
|
{
|
|
78024
78231
|
name: "Toggle Project Context",
|
|
@@ -78030,19 +78237,34 @@ function getCommandPaletteOptions() {
|
|
|
78030
78237
|
addSystemMessage(`Project context: ${config2.repoContext ? "ON - AI can see your package.json scripts, Makefile targets, etc." : "OFF"}`);
|
|
78031
78238
|
}
|
|
78032
78239
|
},
|
|
78240
|
+
{
|
|
78241
|
+
name: "Check for Updates",
|
|
78242
|
+
description: `Current: v${getCurrentVersion()}`,
|
|
78243
|
+
slash: "update",
|
|
78244
|
+
action: () => runManualUpdate()
|
|
78245
|
+
},
|
|
78246
|
+
{
|
|
78247
|
+
name: "Toggle Auto-Update",
|
|
78248
|
+
description: config2.autoUpdate ? "Currently ON" : "Currently OFF",
|
|
78249
|
+
slash: "auto-update",
|
|
78250
|
+
action: () => toggleAutoUpdate()
|
|
78251
|
+
},
|
|
78033
78252
|
{
|
|
78034
78253
|
name: "Show Config",
|
|
78035
78254
|
description: "View current configuration",
|
|
78255
|
+
slash: "config",
|
|
78036
78256
|
action: () => showConfig()
|
|
78037
78257
|
},
|
|
78038
78258
|
{
|
|
78039
78259
|
name: "Show History",
|
|
78040
78260
|
description: `${history.length} commands`,
|
|
78261
|
+
slash: "history",
|
|
78041
78262
|
action: () => showHistory()
|
|
78042
78263
|
},
|
|
78043
78264
|
{
|
|
78044
78265
|
name: "Change Theme",
|
|
78045
78266
|
description: `Current: ${getTheme().name}`,
|
|
78267
|
+
slash: "themes",
|
|
78046
78268
|
shortcut: "Ctrl+X T",
|
|
78047
78269
|
chord: "t",
|
|
78048
78270
|
action: () => showThemeSelector()
|
|
@@ -78050,16 +78272,19 @@ function getCommandPaletteOptions() {
|
|
|
78050
78272
|
{
|
|
78051
78273
|
name: "Clear Chat",
|
|
78052
78274
|
description: "Clear the chat history",
|
|
78275
|
+
slash: "clear",
|
|
78053
78276
|
action: () => clearChat()
|
|
78054
78277
|
},
|
|
78055
78278
|
{
|
|
78056
78279
|
name: "Show Help",
|
|
78057
78280
|
description: "View all commands and shortcuts",
|
|
78281
|
+
slash: "help",
|
|
78058
78282
|
action: () => showHelp()
|
|
78059
78283
|
},
|
|
78060
78284
|
{
|
|
78061
78285
|
name: "Exit",
|
|
78062
78286
|
description: "Close magic-shell",
|
|
78287
|
+
slash: "exit",
|
|
78063
78288
|
shortcut: "Ctrl+D / Ctrl+X Q",
|
|
78064
78289
|
chord: "q",
|
|
78065
78290
|
action: () => {
|
|
@@ -78069,76 +78294,11 @@ function getCommandPaletteOptions() {
|
|
|
78069
78294
|
}
|
|
78070
78295
|
];
|
|
78071
78296
|
}
|
|
78297
|
+
function getCommandPaletteOptions() {
|
|
78298
|
+
return getAppCommands();
|
|
78299
|
+
}
|
|
78072
78300
|
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
|
-
];
|
|
78301
|
+
return getAppCommands().filter((cmd) => Boolean(cmd.slash));
|
|
78142
78302
|
}
|
|
78143
78303
|
function getSlashCommandMatches(inputText) {
|
|
78144
78304
|
if (!inputText.startsWith("/"))
|
|
@@ -78155,12 +78315,28 @@ function getSlashCommandMatches(inputText) {
|
|
|
78155
78315
|
}
|
|
78156
78316
|
function openModalList(config3) {
|
|
78157
78317
|
const theme = getTheme();
|
|
78158
|
-
const width = MODAL_LIST_WIDTH;
|
|
78318
|
+
const width = config3.width ?? MODAL_LIST_WIDTH;
|
|
78159
78319
|
const termWidth = process.stdout.columns || 80;
|
|
78160
78320
|
const left = Math.max(2, Math.floor((termWidth - width) / 2));
|
|
78161
|
-
const
|
|
78162
|
-
const
|
|
78163
|
-
const
|
|
78321
|
+
const visibleRows = Math.max(config3.options.length, 1);
|
|
78322
|
+
const maxRows = Math.max(4, (process.stdout.rows || 24) - 8);
|
|
78323
|
+
const listHeight = Math.min(visibleRows, MODAL_LIST_MAX_ITEMS, maxRows);
|
|
78324
|
+
const showDetail = config3.showDescription !== false && config3.options.some((option) => option.description);
|
|
78325
|
+
const detailHeight = showDetail ? 2 : 0;
|
|
78326
|
+
const containerHeight = listHeight + MODAL_LIST_FRAME_HEIGHT + detailHeight;
|
|
78327
|
+
let currentOptions = config3.options;
|
|
78328
|
+
const formatDetail = (index) => {
|
|
78329
|
+
const description = currentOptions[index]?.description;
|
|
78330
|
+
if (!description || !showDetail)
|
|
78331
|
+
return t``;
|
|
78332
|
+
const maxLength = Math.max(20, width - 16);
|
|
78333
|
+
const text2 = description.length > maxLength ? `${description.slice(0, maxLength - 1)}…` : description;
|
|
78334
|
+
return t`${fg(theme.colors.textMuted)(` ▶ ${text2}`)}`;
|
|
78335
|
+
};
|
|
78336
|
+
const formatOptions = (options) => options.map((option) => ({
|
|
78337
|
+
...option,
|
|
78338
|
+
description: ""
|
|
78339
|
+
}));
|
|
78164
78340
|
const container = new BoxRenderable(renderer, {
|
|
78165
78341
|
id: config3.containerId,
|
|
78166
78342
|
position: "absolute",
|
|
@@ -78182,7 +78358,7 @@ function openModalList(config3) {
|
|
|
78182
78358
|
id: config3.selectorId,
|
|
78183
78359
|
width: "100%",
|
|
78184
78360
|
height: listHeight,
|
|
78185
|
-
options: config3.options,
|
|
78361
|
+
options: formatOptions(config3.options),
|
|
78186
78362
|
backgroundColor: "transparent",
|
|
78187
78363
|
focusedBackgroundColor: "transparent",
|
|
78188
78364
|
selectedBackgroundColor: theme.colors.backgroundElement,
|
|
@@ -78190,24 +78366,35 @@ function openModalList(config3) {
|
|
|
78190
78366
|
selectedTextColor: theme.colors.primary,
|
|
78191
78367
|
descriptionColor: theme.colors.textMuted,
|
|
78192
78368
|
selectedDescriptionColor: theme.colors.textMuted,
|
|
78193
|
-
showDescription:
|
|
78369
|
+
showDescription: false,
|
|
78370
|
+
showScrollIndicator: config3.showScrollIndicator ?? false,
|
|
78194
78371
|
wrapSelection: true
|
|
78195
78372
|
});
|
|
78196
78373
|
container.add(selector);
|
|
78374
|
+
const detailText = showDetail ? new TextRenderable(renderer, {
|
|
78375
|
+
id: `${config3.containerId}-detail`,
|
|
78376
|
+
content: formatDetail(config3.selectedIndex ?? 0),
|
|
78377
|
+
marginTop: 1
|
|
78378
|
+
}) : null;
|
|
78379
|
+
if (detailText) {
|
|
78380
|
+
container.add(detailText);
|
|
78381
|
+
}
|
|
78197
78382
|
const handle = {
|
|
78198
78383
|
containerId: config3.containerId,
|
|
78199
78384
|
container,
|
|
78200
78385
|
selector,
|
|
78201
78386
|
updateOptions(options, selectedIndex = 0) {
|
|
78202
|
-
|
|
78203
|
-
const
|
|
78204
|
-
|
|
78387
|
+
currentOptions = options;
|
|
78388
|
+
const rows = Math.max(options.length, 1);
|
|
78389
|
+
const maxHeight = Math.max(4, (process.stdout.rows || 24) - 8);
|
|
78390
|
+
const newListHeight = Math.min(rows, MODAL_LIST_MAX_ITEMS, maxHeight);
|
|
78391
|
+
selector.options = formatOptions(options);
|
|
78205
78392
|
selector.height = newListHeight;
|
|
78206
|
-
container.height = newListHeight +
|
|
78393
|
+
container.height = newListHeight + MODAL_LIST_FRAME_HEIGHT + detailHeight;
|
|
78207
78394
|
selector.setSelectedIndex(Math.min(selectedIndex, Math.max(options.length - 1, 0)));
|
|
78208
|
-
|
|
78209
|
-
|
|
78210
|
-
|
|
78395
|
+
if (detailText) {
|
|
78396
|
+
detailText.content = formatDetail(selector.getSelectedIndex());
|
|
78397
|
+
}
|
|
78211
78398
|
},
|
|
78212
78399
|
close() {
|
|
78213
78400
|
renderer.root.remove(config3.containerId);
|
|
@@ -78216,17 +78403,88 @@ function openModalList(config3) {
|
|
|
78216
78403
|
};
|
|
78217
78404
|
if (config3.onSelect) {
|
|
78218
78405
|
selector.on(SelectRenderableEvents.ITEM_SELECTED, async (index, option) => {
|
|
78219
|
-
await config3.onSelect?.(index, option);
|
|
78406
|
+
await config3.onSelect?.(index, currentOptions[index] ?? option);
|
|
78220
78407
|
});
|
|
78221
78408
|
}
|
|
78409
|
+
selector.on(SelectRenderableEvents.SELECTION_CHANGED, (index) => {
|
|
78410
|
+
if (detailText) {
|
|
78411
|
+
detailText.content = formatDetail(index);
|
|
78412
|
+
}
|
|
78413
|
+
});
|
|
78222
78414
|
const initialIndex = config3.selectedIndex ?? 0;
|
|
78415
|
+
selector.setSelectedIndex(initialIndex);
|
|
78223
78416
|
if (config3.focusList !== false) {
|
|
78224
78417
|
selector.focus();
|
|
78225
|
-
} else {
|
|
78226
|
-
selector.setSelectedIndex(initialIndex);
|
|
78227
78418
|
}
|
|
78228
78419
|
return handle;
|
|
78229
78420
|
}
|
|
78421
|
+
function openInputModal(config3) {
|
|
78422
|
+
const theme = getTheme();
|
|
78423
|
+
const width = config3.width ?? 72;
|
|
78424
|
+
const termWidth = process.stdout.columns || 80;
|
|
78425
|
+
const left = Math.max(2, Math.floor((termWidth - width) / 2));
|
|
78426
|
+
const container = new BoxRenderable(renderer, {
|
|
78427
|
+
id: config3.containerId,
|
|
78428
|
+
position: "absolute",
|
|
78429
|
+
left,
|
|
78430
|
+
top: 3,
|
|
78431
|
+
width,
|
|
78432
|
+
height: config3.height ?? 11,
|
|
78433
|
+
backgroundColor: theme.colors.backgroundPanel,
|
|
78434
|
+
border: true,
|
|
78435
|
+
borderColor: theme.colors.primary,
|
|
78436
|
+
borderStyle: "single",
|
|
78437
|
+
title: config3.title,
|
|
78438
|
+
titleAlignment: "center",
|
|
78439
|
+
zIndex: 200,
|
|
78440
|
+
padding: 1
|
|
78441
|
+
});
|
|
78442
|
+
renderer.root.add(container);
|
|
78443
|
+
const description = new TextRenderable(renderer, {
|
|
78444
|
+
id: `${config3.containerId}-description`,
|
|
78445
|
+
content: t`${fg(theme.colors.text)(config3.description)}`,
|
|
78446
|
+
marginBottom: 1
|
|
78447
|
+
});
|
|
78448
|
+
container.add(description);
|
|
78449
|
+
const input = new InputRenderable(renderer, {
|
|
78450
|
+
id: `${config3.containerId}-input`,
|
|
78451
|
+
width: "100%",
|
|
78452
|
+
placeholder: config3.placeholder,
|
|
78453
|
+
backgroundColor: theme.colors.backgroundElement,
|
|
78454
|
+
focusedBackgroundColor: theme.colors.backgroundElement,
|
|
78455
|
+
textColor: theme.colors.text,
|
|
78456
|
+
cursorColor: theme.colors.primary
|
|
78457
|
+
});
|
|
78458
|
+
container.add(input);
|
|
78459
|
+
if (config3.extraText) {
|
|
78460
|
+
const extra = new TextRenderable(renderer, {
|
|
78461
|
+
id: `${config3.containerId}-extra`,
|
|
78462
|
+
content: t`${fg(theme.colors.success)(config3.extraText)}`,
|
|
78463
|
+
marginTop: 1
|
|
78464
|
+
});
|
|
78465
|
+
container.add(extra);
|
|
78466
|
+
}
|
|
78467
|
+
const hint = new TextRenderable(renderer, {
|
|
78468
|
+
id: `${config3.containerId}-hint`,
|
|
78469
|
+
content: t`${fg(theme.colors.textMuted)(config3.hintText ?? "Press Enter to save | Esc to cancel | Ctrl+C to exit")}`,
|
|
78470
|
+
marginTop: 1
|
|
78471
|
+
});
|
|
78472
|
+
container.add(hint);
|
|
78473
|
+
input.on(InputRenderableEvents.ENTER, (value) => {
|
|
78474
|
+
config3.onSubmit(value);
|
|
78475
|
+
});
|
|
78476
|
+
const handle = {
|
|
78477
|
+
containerId: config3.containerId,
|
|
78478
|
+
container,
|
|
78479
|
+
input,
|
|
78480
|
+
close() {
|
|
78481
|
+
renderer.root.remove(config3.containerId);
|
|
78482
|
+
inputField?.focus();
|
|
78483
|
+
}
|
|
78484
|
+
};
|
|
78485
|
+
input.focus();
|
|
78486
|
+
return handle;
|
|
78487
|
+
}
|
|
78230
78488
|
function getSlashCommandSelectOptions() {
|
|
78231
78489
|
return slashCommandMatches.map((cmd) => ({
|
|
78232
78490
|
name: `/${cmd.slash}`,
|
|
@@ -78234,11 +78492,54 @@ function getSlashCommandSelectOptions() {
|
|
|
78234
78492
|
value: cmd
|
|
78235
78493
|
}));
|
|
78236
78494
|
}
|
|
78237
|
-
function
|
|
78495
|
+
function closeProviderModal() {
|
|
78496
|
+
if (!providerModal)
|
|
78497
|
+
return;
|
|
78498
|
+
providerModal.close();
|
|
78499
|
+
providerModal = null;
|
|
78500
|
+
}
|
|
78501
|
+
function closeModelModal() {
|
|
78502
|
+
if (!modelModal)
|
|
78503
|
+
return;
|
|
78504
|
+
modelModal.close();
|
|
78505
|
+
modelModal = null;
|
|
78506
|
+
}
|
|
78507
|
+
function closeThemeModal() {
|
|
78508
|
+
if (!themeModal)
|
|
78509
|
+
return;
|
|
78510
|
+
themeModal.close();
|
|
78511
|
+
themeModal = null;
|
|
78512
|
+
}
|
|
78513
|
+
function closeSafetyModal() {
|
|
78514
|
+
if (!safetyModal)
|
|
78515
|
+
return;
|
|
78516
|
+
safetyModal.close();
|
|
78517
|
+
safetyModal = null;
|
|
78518
|
+
}
|
|
78519
|
+
function closeThinkingModal() {
|
|
78520
|
+
if (!thinkingModal)
|
|
78521
|
+
return;
|
|
78522
|
+
thinkingModal.close();
|
|
78523
|
+
thinkingModal = null;
|
|
78524
|
+
}
|
|
78525
|
+
function closeApiKeyModal(invokeCancel = false) {
|
|
78526
|
+
if (!apiKeyModal)
|
|
78527
|
+
return;
|
|
78528
|
+
apiKeyModal.close();
|
|
78529
|
+
apiKeyModal = null;
|
|
78530
|
+
const onCancel = apiKeyModalOnCancel;
|
|
78531
|
+
apiKeyModalOnCancel = null;
|
|
78532
|
+
if (invokeCancel)
|
|
78533
|
+
onCancel?.();
|
|
78534
|
+
}
|
|
78535
|
+
function closeSlashCommandMenu(dismissCurrentInput = false) {
|
|
78238
78536
|
if (slashCommandModal) {
|
|
78239
78537
|
slashCommandModal.close();
|
|
78240
78538
|
slashCommandModal = null;
|
|
78241
78539
|
}
|
|
78540
|
+
if (dismissCurrentInput) {
|
|
78541
|
+
slashCommandDismissedInput = inputField?.editBuffer.getText() ?? null;
|
|
78542
|
+
}
|
|
78242
78543
|
slashCommandMatches = [];
|
|
78243
78544
|
slashCommandSelectedIndex = 0;
|
|
78244
78545
|
}
|
|
@@ -78249,6 +78550,12 @@ function updateSlashCommandModalOptions() {
|
|
|
78249
78550
|
}
|
|
78250
78551
|
function syncSlashCommandMenu() {
|
|
78251
78552
|
const inputText = inputField.editBuffer.getText();
|
|
78553
|
+
if (slashCommandDismissedInput !== null) {
|
|
78554
|
+
if (inputText === slashCommandDismissedInput) {
|
|
78555
|
+
return;
|
|
78556
|
+
}
|
|
78557
|
+
slashCommandDismissedInput = null;
|
|
78558
|
+
}
|
|
78252
78559
|
const matches = getSlashCommandMatches(inputText);
|
|
78253
78560
|
if (matches.length === 0) {
|
|
78254
78561
|
closeSlashCommandMenu();
|
|
@@ -78351,17 +78658,17 @@ function handleKeypress(key) {
|
|
|
78351
78658
|
inputField.focus();
|
|
78352
78659
|
return;
|
|
78353
78660
|
}
|
|
78354
|
-
if (key.name === "return" && !key.shift && !key.ctrl && !key.meta) {
|
|
78355
|
-
executeSelectedSlashCommand();
|
|
78356
|
-
return;
|
|
78357
|
-
}
|
|
78358
78661
|
}
|
|
78359
78662
|
if (key.ctrl && key.name === "p") {
|
|
78360
78663
|
showCommandPalette();
|
|
78361
78664
|
return;
|
|
78362
78665
|
}
|
|
78363
78666
|
if (key.ctrl && key.name === "t") {
|
|
78364
|
-
|
|
78667
|
+
showThinkingSelector();
|
|
78668
|
+
return;
|
|
78669
|
+
}
|
|
78670
|
+
if (key.ctrl && key.name === "y") {
|
|
78671
|
+
showSafetySelector();
|
|
78365
78672
|
return;
|
|
78366
78673
|
}
|
|
78367
78674
|
if (key.ctrl && key.name === "d") {
|
|
@@ -78400,20 +78707,32 @@ function handleKeypress(key) {
|
|
|
78400
78707
|
closeCommandPalette();
|
|
78401
78708
|
return;
|
|
78402
78709
|
}
|
|
78403
|
-
if (
|
|
78404
|
-
closeSlashCommandMenu();
|
|
78710
|
+
if (slashCommandModal) {
|
|
78711
|
+
closeSlashCommandMenu(true);
|
|
78405
78712
|
return;
|
|
78406
78713
|
}
|
|
78407
|
-
if (
|
|
78408
|
-
|
|
78409
|
-
modelSelector = null;
|
|
78410
|
-
inputField.focus();
|
|
78714
|
+
if (providerModal) {
|
|
78715
|
+
closeProviderModal();
|
|
78411
78716
|
return;
|
|
78412
78717
|
}
|
|
78413
|
-
if (
|
|
78414
|
-
|
|
78415
|
-
|
|
78416
|
-
|
|
78718
|
+
if (modelModal) {
|
|
78719
|
+
closeModelModal();
|
|
78720
|
+
return;
|
|
78721
|
+
}
|
|
78722
|
+
if (themeModal) {
|
|
78723
|
+
closeThemeModal();
|
|
78724
|
+
return;
|
|
78725
|
+
}
|
|
78726
|
+
if (safetyModal) {
|
|
78727
|
+
closeSafetyModal();
|
|
78728
|
+
return;
|
|
78729
|
+
}
|
|
78730
|
+
if (thinkingModal) {
|
|
78731
|
+
closeThinkingModal();
|
|
78732
|
+
return;
|
|
78733
|
+
}
|
|
78734
|
+
if (apiKeyModal) {
|
|
78735
|
+
closeApiKeyModal(true);
|
|
78417
78736
|
return;
|
|
78418
78737
|
}
|
|
78419
78738
|
if (awaitingConfirmation && pendingMessageId) {
|
|
@@ -78431,14 +78750,32 @@ function handleKeypress(key) {
|
|
|
78431
78750
|
closeCommandPalette();
|
|
78432
78751
|
return;
|
|
78433
78752
|
}
|
|
78434
|
-
if (
|
|
78435
|
-
closeSlashCommandMenu();
|
|
78753
|
+
if (slashCommandModal) {
|
|
78754
|
+
closeSlashCommandMenu(true);
|
|
78436
78755
|
return;
|
|
78437
78756
|
}
|
|
78438
|
-
if (
|
|
78439
|
-
|
|
78440
|
-
|
|
78441
|
-
|
|
78757
|
+
if (providerModal) {
|
|
78758
|
+
closeProviderModal();
|
|
78759
|
+
return;
|
|
78760
|
+
}
|
|
78761
|
+
if (modelModal) {
|
|
78762
|
+
closeModelModal();
|
|
78763
|
+
return;
|
|
78764
|
+
}
|
|
78765
|
+
if (themeModal) {
|
|
78766
|
+
closeThemeModal();
|
|
78767
|
+
return;
|
|
78768
|
+
}
|
|
78769
|
+
if (safetyModal) {
|
|
78770
|
+
closeSafetyModal();
|
|
78771
|
+
return;
|
|
78772
|
+
}
|
|
78773
|
+
if (thinkingModal) {
|
|
78774
|
+
closeThinkingModal();
|
|
78775
|
+
return;
|
|
78776
|
+
}
|
|
78777
|
+
if (apiKeyModal) {
|
|
78778
|
+
closeApiKeyModal(true);
|
|
78442
78779
|
return;
|
|
78443
78780
|
}
|
|
78444
78781
|
if (awaitingConfirmation && pendingMessageId) {
|
|
@@ -78468,13 +78805,13 @@ function handleKeypress(key) {
|
|
|
78468
78805
|
const msg = chatMessages.find((m2) => m2.id === pendingMessageId);
|
|
78469
78806
|
if (msg && msg.command) {
|
|
78470
78807
|
const copyCmd = process.platform === "darwin" ? "pbcopy" : "xclip -selection clipboard";
|
|
78471
|
-
const child =
|
|
78808
|
+
const child = spawn2(copyCmd, { shell: true });
|
|
78472
78809
|
child.stdin?.write(msg.command);
|
|
78473
78810
|
child.stdin?.end();
|
|
78474
78811
|
addSystemMessage(`Copied to clipboard: ${msg.command}`);
|
|
78475
78812
|
}
|
|
78476
78813
|
}
|
|
78477
|
-
if (key.name === "o" && !awaitingConfirmation && !commandPaletteModal && !
|
|
78814
|
+
if (key.name === "o" && !awaitingConfirmation && !commandPaletteModal && !modelModal) {
|
|
78478
78815
|
toggleLastResultExpand();
|
|
78479
78816
|
}
|
|
78480
78817
|
}
|