@austinthesing/magic-shell 1.1.8 → 1.2.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.
Files changed (4) hide show
  1. package/dist/cli.js +120 -41
  2. package/dist/index.js +120 -41
  3. package/dist/tui.js +120 -41
  4. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -74945,9 +74945,9 @@ function buildAiSdkProviderOptions(modelId, thinkingLevel, providerOptionsName)
74945
74945
  function shouldOmitTemperature(modelId, thinkingLevel) {
74946
74946
  if (/claude-opus-5[.-]5/.test(modelId))
74947
74947
  return true;
74948
- if (modelId.includes("gpt-6"))
74948
+ if (modelId.includes("gpt-5") || modelId.includes("gpt-6"))
74949
74949
  return true;
74950
- return thinkingLevel !== "off" && (modelId.startsWith("claude-") || modelId.includes("gpt-5"));
74950
+ return thinkingLevel !== "off" && modelId.startsWith("claude-");
74951
74951
  }
74952
74952
  async function callOpenRouter(apiKey, modelId, systemPrompt, userInput, thinkingLevel) {
74953
74953
  const thinkingOptions = buildOpenRouterThinkingOptions(modelId, thinkingLevel);
@@ -75418,9 +75418,75 @@ loadTheme();
75418
75418
  // src/lib/update-checker.ts
75419
75419
  import { spawn } from "child_process";
75420
75420
  import { homedir as homedir3 } from "os";
75421
- import { join as join6 } from "path";
75422
- import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync4, mkdirSync as mkdirSync2 } from "fs";
75423
- var __dirname = "/home/runner/work/magic-shell/magic-shell/src/lib";
75421
+ import { join as join6, dirname as dirname3, posix } from "path";
75422
+ import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync4, mkdirSync as mkdirSync2, realpathSync } from "fs";
75423
+ // package.json
75424
+ var package_default = {
75425
+ name: "@austinthesing/magic-shell",
75426
+ version: "1.2.0",
75427
+ description: "Natural language to terminal commands with safety features. Supports OpenCode Zen, OpenRouter, AI gateways, Workers AI, and custom models.",
75428
+ type: "module",
75429
+ main: "dist/index.js",
75430
+ bin: {
75431
+ msh: "dist/index.js",
75432
+ mshell: "dist/tui.js"
75433
+ },
75434
+ files: [
75435
+ "dist",
75436
+ "README.md",
75437
+ "LICENSE"
75438
+ ],
75439
+ scripts: {
75440
+ dev: "bun run src/index.ts",
75441
+ "dev:tui": "bun run src/cli.ts",
75442
+ build: "bun build src/index.ts src/cli.ts src/tui.ts --outdir dist --target node --external '@opentui/core-*'",
75443
+ typecheck: "tsc --noEmit",
75444
+ prepublishOnly: "bun run build"
75445
+ },
75446
+ keywords: [
75447
+ "cli",
75448
+ "terminal",
75449
+ "natural-language",
75450
+ "shell",
75451
+ "ai",
75452
+ "openrouter",
75453
+ "opencode",
75454
+ "zen",
75455
+ "command-line",
75456
+ "nlp",
75457
+ "gpt",
75458
+ "claude",
75459
+ "llm"
75460
+ ],
75461
+ author: "Austin Thesing (https://github.com/austin-thesing)",
75462
+ license: "MIT",
75463
+ repository: {
75464
+ type: "git",
75465
+ url: "git+https://github.com/designxdevelop/magic-shell.git"
75466
+ },
75467
+ homepage: "https://github.com/austin-thesing/magic-shell#readme",
75468
+ bugs: {
75469
+ url: "https://github.com/austin-thesing/magic-shell/issues"
75470
+ },
75471
+ packageManager: "bun@1.3.14",
75472
+ engines: {
75473
+ bun: ">=1.3.14"
75474
+ },
75475
+ dependencies: {
75476
+ "@ai-sdk/anthropic": "^4.0.36",
75477
+ "@ai-sdk/google": "^4.0.39",
75478
+ "@ai-sdk/openai": "^4.0.36",
75479
+ "@ai-sdk/openai-compatible": "^3.0.27",
75480
+ "@opentui/core": "^0.5.1",
75481
+ ai: "^7.0.58"
75482
+ },
75483
+ devDependencies: {
75484
+ "@types/bun": "^1.4.2",
75485
+ typescript: "^7.0.2"
75486
+ }
75487
+ };
75488
+
75489
+ // src/lib/update-checker.ts
75424
75490
  var PACKAGE_NAME = "@austinthesing/magic-shell";
75425
75491
  var NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
75426
75492
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
@@ -75447,22 +75513,7 @@ function saveUpdateState(state) {
75447
75513
  } catch {}
75448
75514
  }
75449
75515
  function getCurrentVersion() {
75450
- try {
75451
- const packagePaths = [
75452
- join6(__dirname, "../../package.json"),
75453
- join6(__dirname, "../../../package.json"),
75454
- join6(process.cwd(), "package.json")
75455
- ];
75456
- for (const path of packagePaths) {
75457
- if (existsSync6(path)) {
75458
- const pkg = JSON.parse(readFileSync3(path, "utf-8"));
75459
- if (pkg.name === PACKAGE_NAME || pkg.name === "magic-shell") {
75460
- return pkg.version;
75461
- }
75462
- }
75463
- }
75464
- } catch {}
75465
- return "0.0.0";
75516
+ return package_default.version;
75466
75517
  }
75467
75518
  function compareVersions(a, b) {
75468
75519
  const partsA = a.split(".").map(Number);
@@ -75494,35 +75545,56 @@ async function fetchLatestVersion() {
75494
75545
  return null;
75495
75546
  }
75496
75547
  }
75497
- function commandExists(command) {
75498
- return new Promise((resolve) => {
75499
- const checker = process.platform === "win32" ? spawn("where", [command], { stdio: "ignore" }) : spawn("command", ["-v", command], { stdio: "ignore", shell: true });
75500
- checker.on("close", (code) => resolve(code === 0));
75501
- checker.on("error", () => resolve(false));
75502
- });
75503
- }
75504
- async function resolveUpdateCommand() {
75505
- if (await commandExists("bun")) {
75506
- return `bun update -g ${PACKAGE_NAME}`;
75548
+ function getUpdateTarget(packageRoot, version = "latest") {
75549
+ const normalized = packageRoot.replaceAll("\\", "/");
75550
+ const packageSpec = `${PACKAGE_NAME}@${version}`;
75551
+ if (/\/pnpm\/global\//.test(normalized)) {
75552
+ return null;
75553
+ }
75554
+ if (/\/install\/global\/node_modules\//.test(normalized)) {
75555
+ const globalRoot = posix.dirname(posix.dirname(posix.dirname(normalized)));
75556
+ return { command: "bun", args: ["add", "-g", packageSpec], env: { BUN_INSTALL: posix.dirname(posix.dirname(globalRoot)) } };
75507
75557
  }
75508
- if (await commandExists("npm")) {
75509
- return `npm install -g ${PACKAGE_NAME}@latest`;
75558
+ if (normalized.endsWith(`/node_modules/${PACKAGE_NAME}`)) {
75559
+ const parent = posix.dirname(posix.dirname(posix.dirname(normalized)));
75560
+ const prefix = posix.basename(parent) === "lib" ? posix.dirname(parent) : parent;
75561
+ return { command: "npm", args: ["install", "-g", "--prefix", prefix, packageSpec] };
75510
75562
  }
75511
- return `bun update -g ${PACKAGE_NAME}`;
75563
+ return null;
75564
+ }
75565
+ function resolveUpdateTarget(version = "latest") {
75566
+ try {
75567
+ let directory = dirname3(realpathSync(process.argv[1]));
75568
+ while (dirname3(directory) !== directory) {
75569
+ const metadata = join6(directory, "package.json");
75570
+ if (existsSync6(metadata)) {
75571
+ const pkg = JSON.parse(readFileSync3(metadata, "utf8"));
75572
+ if (pkg.name === PACKAGE_NAME)
75573
+ return getUpdateTarget(directory, version);
75574
+ }
75575
+ directory = dirname3(directory);
75576
+ }
75577
+ } catch {}
75578
+ return null;
75579
+ }
75580
+ function formatUpdateCommand(target) {
75581
+ if (!target)
75582
+ return "Update this installation manually with its package manager.";
75583
+ return [target.command, ...target.args].map((arg) => /^[\w@./:=+-]+$/.test(arg) ? arg : JSON.stringify(arg)).join(" ");
75512
75584
  }
75513
75585
  async function buildUpdateInfo(latestVersion) {
75514
75586
  return {
75515
75587
  hasUpdate: true,
75516
75588
  currentVersion: getCurrentVersion(),
75517
75589
  latestVersion,
75518
- updateCommand: await resolveUpdateCommand()
75590
+ updateCommand: formatUpdateCommand(resolveUpdateTarget(latestVersion))
75519
75591
  };
75520
75592
  }
75521
75593
  async function checkForUpdates() {
75522
75594
  const state = loadUpdateState();
75523
75595
  const currentVersion = getCurrentVersion();
75524
75596
  const now = Date.now();
75525
- if (now - state.lastCheck < CHECK_INTERVAL_MS) {
75597
+ if (now - state.lastCheck < CHECK_INTERVAL_MS && (!state.latestVersion || compareVersions(state.latestVersion, currentVersion) >= 0)) {
75526
75598
  if (state.latestVersion && compareVersions(state.latestVersion, currentVersion) > 0) {
75527
75599
  if (state.dismissed === state.latestVersion) {
75528
75600
  return null;
@@ -75556,13 +75628,20 @@ async function forceCheckForUpdates() {
75556
75628
  saveUpdateState(state);
75557
75629
  return checkForUpdates();
75558
75630
  }
75559
- async function performUpdate() {
75560
- const updateCommand = await resolveUpdateCommand();
75631
+ async function performUpdate(version = "latest") {
75632
+ const target = resolveUpdateTarget(version);
75633
+ if (!target)
75634
+ return { success: false, output: "Cannot identify this installation's package manager; update it manually." };
75635
+ const updateCommand = formatUpdateCommand(target);
75561
75636
  return new Promise((resolve) => {
75562
- const child = spawn(updateCommand, {
75637
+ const child = process.platform === "win32" ? spawn(updateCommand, {
75563
75638
  shell: true,
75564
75639
  stdio: ["ignore", "pipe", "pipe"],
75565
- env: process.env
75640
+ env: { ...process.env, ...target.env }
75641
+ }) : spawn(target.command, target.args, {
75642
+ shell: false,
75643
+ stdio: ["ignore", "pipe", "pipe"],
75644
+ env: { ...process.env, ...target.env }
75566
75645
  });
75567
75646
  let stdout = "";
75568
75647
  let stderr = "";
@@ -75610,7 +75689,7 @@ async function processUpdateCheck(options) {
75610
75689
  return { action: "none" };
75611
75690
  }
75612
75691
  if (install || autoUpdate) {
75613
- const result = await performUpdate();
75692
+ const result = await performUpdate(update.latestVersion);
75614
75693
  if (result.success) {
75615
75694
  dismissUpdate(update.latestVersion);
75616
75695
  }
package/dist/index.js CHANGED
@@ -42874,9 +42874,9 @@ function buildAiSdkProviderOptions(modelId, thinkingLevel, providerOptionsName)
42874
42874
  function shouldOmitTemperature(modelId, thinkingLevel) {
42875
42875
  if (/claude-opus-5[.-]5/.test(modelId))
42876
42876
  return true;
42877
- if (modelId.includes("gpt-6"))
42877
+ if (modelId.includes("gpt-5") || modelId.includes("gpt-6"))
42878
42878
  return true;
42879
- return thinkingLevel !== "off" && (modelId.startsWith("claude-") || modelId.includes("gpt-5"));
42879
+ return thinkingLevel !== "off" && modelId.startsWith("claude-");
42880
42880
  }
42881
42881
  async function callOpenRouter(apiKey, modelId, systemPrompt, userInput, thinkingLevel) {
42882
42882
  const thinkingOptions = buildOpenRouterThinkingOptions(modelId, thinkingLevel);
@@ -43370,9 +43370,75 @@ loadTheme();
43370
43370
  // src/lib/update-checker.ts
43371
43371
  import { spawn } from "child_process";
43372
43372
  import { homedir as homedir4 } from "os";
43373
- import { join as join4 } from "path";
43374
- import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3 } from "fs";
43375
- var __dirname = "/home/runner/work/magic-shell/magic-shell/src/lib";
43373
+ import { join as join4, dirname, posix } from "path";
43374
+ import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3, realpathSync } from "fs";
43375
+ // package.json
43376
+ var package_default = {
43377
+ name: "@austinthesing/magic-shell",
43378
+ version: "1.2.0",
43379
+ description: "Natural language to terminal commands with safety features. Supports OpenCode Zen, OpenRouter, AI gateways, Workers AI, and custom models.",
43380
+ type: "module",
43381
+ main: "dist/index.js",
43382
+ bin: {
43383
+ msh: "dist/index.js",
43384
+ mshell: "dist/tui.js"
43385
+ },
43386
+ files: [
43387
+ "dist",
43388
+ "README.md",
43389
+ "LICENSE"
43390
+ ],
43391
+ scripts: {
43392
+ dev: "bun run src/index.ts",
43393
+ "dev:tui": "bun run src/cli.ts",
43394
+ build: "bun build src/index.ts src/cli.ts src/tui.ts --outdir dist --target node --external '@opentui/core-*'",
43395
+ typecheck: "tsc --noEmit",
43396
+ prepublishOnly: "bun run build"
43397
+ },
43398
+ keywords: [
43399
+ "cli",
43400
+ "terminal",
43401
+ "natural-language",
43402
+ "shell",
43403
+ "ai",
43404
+ "openrouter",
43405
+ "opencode",
43406
+ "zen",
43407
+ "command-line",
43408
+ "nlp",
43409
+ "gpt",
43410
+ "claude",
43411
+ "llm"
43412
+ ],
43413
+ author: "Austin Thesing (https://github.com/austin-thesing)",
43414
+ license: "MIT",
43415
+ repository: {
43416
+ type: "git",
43417
+ url: "git+https://github.com/designxdevelop/magic-shell.git"
43418
+ },
43419
+ homepage: "https://github.com/austin-thesing/magic-shell#readme",
43420
+ bugs: {
43421
+ url: "https://github.com/austin-thesing/magic-shell/issues"
43422
+ },
43423
+ packageManager: "bun@1.3.14",
43424
+ engines: {
43425
+ bun: ">=1.3.14"
43426
+ },
43427
+ dependencies: {
43428
+ "@ai-sdk/anthropic": "^4.0.36",
43429
+ "@ai-sdk/google": "^4.0.39",
43430
+ "@ai-sdk/openai": "^4.0.36",
43431
+ "@ai-sdk/openai-compatible": "^3.0.27",
43432
+ "@opentui/core": "^0.5.1",
43433
+ ai: "^7.0.58"
43434
+ },
43435
+ devDependencies: {
43436
+ "@types/bun": "^1.4.2",
43437
+ typescript: "^7.0.2"
43438
+ }
43439
+ };
43440
+
43441
+ // src/lib/update-checker.ts
43376
43442
  var PACKAGE_NAME = "@austinthesing/magic-shell";
43377
43443
  var NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
43378
43444
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
@@ -43399,22 +43465,7 @@ function saveUpdateState(state) {
43399
43465
  } catch {}
43400
43466
  }
43401
43467
  function getCurrentVersion() {
43402
- try {
43403
- const packagePaths = [
43404
- join4(__dirname, "../../package.json"),
43405
- join4(__dirname, "../../../package.json"),
43406
- join4(process.cwd(), "package.json")
43407
- ];
43408
- for (const path of packagePaths) {
43409
- if (existsSync5(path)) {
43410
- const pkg = JSON.parse(readFileSync4(path, "utf-8"));
43411
- if (pkg.name === PACKAGE_NAME || pkg.name === "magic-shell") {
43412
- return pkg.version;
43413
- }
43414
- }
43415
- }
43416
- } catch {}
43417
- return "0.0.0";
43468
+ return package_default.version;
43418
43469
  }
43419
43470
  function compareVersions(a, b) {
43420
43471
  const partsA = a.split(".").map(Number);
@@ -43446,35 +43497,56 @@ async function fetchLatestVersion() {
43446
43497
  return null;
43447
43498
  }
43448
43499
  }
43449
- function commandExists(command) {
43450
- return new Promise((resolve) => {
43451
- const checker = process.platform === "win32" ? spawn("where", [command], { stdio: "ignore" }) : spawn("command", ["-v", command], { stdio: "ignore", shell: true });
43452
- checker.on("close", (code) => resolve(code === 0));
43453
- checker.on("error", () => resolve(false));
43454
- });
43455
- }
43456
- async function resolveUpdateCommand() {
43457
- if (await commandExists("bun")) {
43458
- return `bun update -g ${PACKAGE_NAME}`;
43500
+ function getUpdateTarget(packageRoot, version = "latest") {
43501
+ const normalized = packageRoot.replaceAll("\\", "/");
43502
+ const packageSpec = `${PACKAGE_NAME}@${version}`;
43503
+ if (/\/pnpm\/global\//.test(normalized)) {
43504
+ return null;
43459
43505
  }
43460
- if (await commandExists("npm")) {
43461
- return `npm install -g ${PACKAGE_NAME}@latest`;
43506
+ if (/\/install\/global\/node_modules\//.test(normalized)) {
43507
+ const globalRoot = posix.dirname(posix.dirname(posix.dirname(normalized)));
43508
+ return { command: "bun", args: ["add", "-g", packageSpec], env: { BUN_INSTALL: posix.dirname(posix.dirname(globalRoot)) } };
43462
43509
  }
43463
- return `bun update -g ${PACKAGE_NAME}`;
43510
+ if (normalized.endsWith(`/node_modules/${PACKAGE_NAME}`)) {
43511
+ const parent = posix.dirname(posix.dirname(posix.dirname(normalized)));
43512
+ const prefix = posix.basename(parent) === "lib" ? posix.dirname(parent) : parent;
43513
+ return { command: "npm", args: ["install", "-g", "--prefix", prefix, packageSpec] };
43514
+ }
43515
+ return null;
43516
+ }
43517
+ function resolveUpdateTarget(version = "latest") {
43518
+ try {
43519
+ let directory = dirname(realpathSync(process.argv[1]));
43520
+ while (dirname(directory) !== directory) {
43521
+ const metadata = join4(directory, "package.json");
43522
+ if (existsSync5(metadata)) {
43523
+ const pkg = JSON.parse(readFileSync4(metadata, "utf8"));
43524
+ if (pkg.name === PACKAGE_NAME)
43525
+ return getUpdateTarget(directory, version);
43526
+ }
43527
+ directory = dirname(directory);
43528
+ }
43529
+ } catch {}
43530
+ return null;
43531
+ }
43532
+ function formatUpdateCommand(target) {
43533
+ if (!target)
43534
+ return "Update this installation manually with its package manager.";
43535
+ return [target.command, ...target.args].map((arg) => /^[\w@./:=+-]+$/.test(arg) ? arg : JSON.stringify(arg)).join(" ");
43464
43536
  }
43465
43537
  async function buildUpdateInfo(latestVersion) {
43466
43538
  return {
43467
43539
  hasUpdate: true,
43468
43540
  currentVersion: getCurrentVersion(),
43469
43541
  latestVersion,
43470
- updateCommand: await resolveUpdateCommand()
43542
+ updateCommand: formatUpdateCommand(resolveUpdateTarget(latestVersion))
43471
43543
  };
43472
43544
  }
43473
43545
  async function checkForUpdates() {
43474
43546
  const state = loadUpdateState();
43475
43547
  const currentVersion = getCurrentVersion();
43476
43548
  const now = Date.now();
43477
- if (now - state.lastCheck < CHECK_INTERVAL_MS) {
43549
+ if (now - state.lastCheck < CHECK_INTERVAL_MS && (!state.latestVersion || compareVersions(state.latestVersion, currentVersion) >= 0)) {
43478
43550
  if (state.latestVersion && compareVersions(state.latestVersion, currentVersion) > 0) {
43479
43551
  if (state.dismissed === state.latestVersion) {
43480
43552
  return null;
@@ -43508,13 +43580,20 @@ async function forceCheckForUpdates() {
43508
43580
  saveUpdateState(state);
43509
43581
  return checkForUpdates();
43510
43582
  }
43511
- async function performUpdate() {
43512
- const updateCommand = await resolveUpdateCommand();
43583
+ async function performUpdate(version = "latest") {
43584
+ const target = resolveUpdateTarget(version);
43585
+ if (!target)
43586
+ return { success: false, output: "Cannot identify this installation's package manager; update it manually." };
43587
+ const updateCommand = formatUpdateCommand(target);
43513
43588
  return new Promise((resolve) => {
43514
- const child = spawn(updateCommand, {
43589
+ const child = process.platform === "win32" ? spawn(updateCommand, {
43515
43590
  shell: true,
43516
43591
  stdio: ["ignore", "pipe", "pipe"],
43517
- env: process.env
43592
+ env: { ...process.env, ...target.env }
43593
+ }) : spawn(target.command, target.args, {
43594
+ shell: false,
43595
+ stdio: ["ignore", "pipe", "pipe"],
43596
+ env: { ...process.env, ...target.env }
43518
43597
  });
43519
43598
  let stdout = "";
43520
43599
  let stderr = "";
@@ -43558,7 +43637,7 @@ async function processUpdateCheck(options) {
43558
43637
  return { action: "none" };
43559
43638
  }
43560
43639
  if (install || autoUpdate) {
43561
- const result = await performUpdate();
43640
+ const result = await performUpdate(update.latestVersion);
43562
43641
  if (result.success) {
43563
43642
  dismissUpdate(update.latestVersion);
43564
43643
  }
package/dist/tui.js CHANGED
@@ -74945,9 +74945,9 @@ function buildAiSdkProviderOptions(modelId, thinkingLevel, providerOptionsName)
74945
74945
  function shouldOmitTemperature(modelId, thinkingLevel) {
74946
74946
  if (/claude-opus-5[.-]5/.test(modelId))
74947
74947
  return true;
74948
- if (modelId.includes("gpt-6"))
74948
+ if (modelId.includes("gpt-5") || modelId.includes("gpt-6"))
74949
74949
  return true;
74950
- return thinkingLevel !== "off" && (modelId.startsWith("claude-") || modelId.includes("gpt-5"));
74950
+ return thinkingLevel !== "off" && modelId.startsWith("claude-");
74951
74951
  }
74952
74952
  async function callOpenRouter(apiKey, modelId, systemPrompt, userInput, thinkingLevel) {
74953
74953
  const thinkingOptions = buildOpenRouterThinkingOptions(modelId, thinkingLevel);
@@ -75418,9 +75418,75 @@ loadTheme();
75418
75418
  // src/lib/update-checker.ts
75419
75419
  import { spawn } from "child_process";
75420
75420
  import { homedir as homedir3 } from "os";
75421
- import { join as join6 } from "path";
75422
- import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync4, mkdirSync as mkdirSync2 } from "fs";
75423
- var __dirname = "/home/runner/work/magic-shell/magic-shell/src/lib";
75421
+ import { join as join6, dirname as dirname3, posix } from "path";
75422
+ import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync4, mkdirSync as mkdirSync2, realpathSync } from "fs";
75423
+ // package.json
75424
+ var package_default = {
75425
+ name: "@austinthesing/magic-shell",
75426
+ version: "1.2.0",
75427
+ description: "Natural language to terminal commands with safety features. Supports OpenCode Zen, OpenRouter, AI gateways, Workers AI, and custom models.",
75428
+ type: "module",
75429
+ main: "dist/index.js",
75430
+ bin: {
75431
+ msh: "dist/index.js",
75432
+ mshell: "dist/tui.js"
75433
+ },
75434
+ files: [
75435
+ "dist",
75436
+ "README.md",
75437
+ "LICENSE"
75438
+ ],
75439
+ scripts: {
75440
+ dev: "bun run src/index.ts",
75441
+ "dev:tui": "bun run src/cli.ts",
75442
+ build: "bun build src/index.ts src/cli.ts src/tui.ts --outdir dist --target node --external '@opentui/core-*'",
75443
+ typecheck: "tsc --noEmit",
75444
+ prepublishOnly: "bun run build"
75445
+ },
75446
+ keywords: [
75447
+ "cli",
75448
+ "terminal",
75449
+ "natural-language",
75450
+ "shell",
75451
+ "ai",
75452
+ "openrouter",
75453
+ "opencode",
75454
+ "zen",
75455
+ "command-line",
75456
+ "nlp",
75457
+ "gpt",
75458
+ "claude",
75459
+ "llm"
75460
+ ],
75461
+ author: "Austin Thesing (https://github.com/austin-thesing)",
75462
+ license: "MIT",
75463
+ repository: {
75464
+ type: "git",
75465
+ url: "git+https://github.com/designxdevelop/magic-shell.git"
75466
+ },
75467
+ homepage: "https://github.com/austin-thesing/magic-shell#readme",
75468
+ bugs: {
75469
+ url: "https://github.com/austin-thesing/magic-shell/issues"
75470
+ },
75471
+ packageManager: "bun@1.3.14",
75472
+ engines: {
75473
+ bun: ">=1.3.14"
75474
+ },
75475
+ dependencies: {
75476
+ "@ai-sdk/anthropic": "^4.0.36",
75477
+ "@ai-sdk/google": "^4.0.39",
75478
+ "@ai-sdk/openai": "^4.0.36",
75479
+ "@ai-sdk/openai-compatible": "^3.0.27",
75480
+ "@opentui/core": "^0.5.1",
75481
+ ai: "^7.0.58"
75482
+ },
75483
+ devDependencies: {
75484
+ "@types/bun": "^1.4.2",
75485
+ typescript: "^7.0.2"
75486
+ }
75487
+ };
75488
+
75489
+ // src/lib/update-checker.ts
75424
75490
  var PACKAGE_NAME = "@austinthesing/magic-shell";
75425
75491
  var NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
75426
75492
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
@@ -75447,22 +75513,7 @@ function saveUpdateState(state) {
75447
75513
  } catch {}
75448
75514
  }
75449
75515
  function getCurrentVersion() {
75450
- try {
75451
- const packagePaths = [
75452
- join6(__dirname, "../../package.json"),
75453
- join6(__dirname, "../../../package.json"),
75454
- join6(process.cwd(), "package.json")
75455
- ];
75456
- for (const path of packagePaths) {
75457
- if (existsSync6(path)) {
75458
- const pkg = JSON.parse(readFileSync3(path, "utf-8"));
75459
- if (pkg.name === PACKAGE_NAME || pkg.name === "magic-shell") {
75460
- return pkg.version;
75461
- }
75462
- }
75463
- }
75464
- } catch {}
75465
- return "0.0.0";
75516
+ return package_default.version;
75466
75517
  }
75467
75518
  function compareVersions(a, b) {
75468
75519
  const partsA = a.split(".").map(Number);
@@ -75494,35 +75545,56 @@ async function fetchLatestVersion() {
75494
75545
  return null;
75495
75546
  }
75496
75547
  }
75497
- function commandExists(command) {
75498
- return new Promise((resolve) => {
75499
- const checker = process.platform === "win32" ? spawn("where", [command], { stdio: "ignore" }) : spawn("command", ["-v", command], { stdio: "ignore", shell: true });
75500
- checker.on("close", (code) => resolve(code === 0));
75501
- checker.on("error", () => resolve(false));
75502
- });
75503
- }
75504
- async function resolveUpdateCommand() {
75505
- if (await commandExists("bun")) {
75506
- return `bun update -g ${PACKAGE_NAME}`;
75548
+ function getUpdateTarget(packageRoot, version = "latest") {
75549
+ const normalized = packageRoot.replaceAll("\\", "/");
75550
+ const packageSpec = `${PACKAGE_NAME}@${version}`;
75551
+ if (/\/pnpm\/global\//.test(normalized)) {
75552
+ return null;
75553
+ }
75554
+ if (/\/install\/global\/node_modules\//.test(normalized)) {
75555
+ const globalRoot = posix.dirname(posix.dirname(posix.dirname(normalized)));
75556
+ return { command: "bun", args: ["add", "-g", packageSpec], env: { BUN_INSTALL: posix.dirname(posix.dirname(globalRoot)) } };
75507
75557
  }
75508
- if (await commandExists("npm")) {
75509
- return `npm install -g ${PACKAGE_NAME}@latest`;
75558
+ if (normalized.endsWith(`/node_modules/${PACKAGE_NAME}`)) {
75559
+ const parent = posix.dirname(posix.dirname(posix.dirname(normalized)));
75560
+ const prefix = posix.basename(parent) === "lib" ? posix.dirname(parent) : parent;
75561
+ return { command: "npm", args: ["install", "-g", "--prefix", prefix, packageSpec] };
75510
75562
  }
75511
- return `bun update -g ${PACKAGE_NAME}`;
75563
+ return null;
75564
+ }
75565
+ function resolveUpdateTarget(version = "latest") {
75566
+ try {
75567
+ let directory = dirname3(realpathSync(process.argv[1]));
75568
+ while (dirname3(directory) !== directory) {
75569
+ const metadata = join6(directory, "package.json");
75570
+ if (existsSync6(metadata)) {
75571
+ const pkg = JSON.parse(readFileSync3(metadata, "utf8"));
75572
+ if (pkg.name === PACKAGE_NAME)
75573
+ return getUpdateTarget(directory, version);
75574
+ }
75575
+ directory = dirname3(directory);
75576
+ }
75577
+ } catch {}
75578
+ return null;
75579
+ }
75580
+ function formatUpdateCommand(target) {
75581
+ if (!target)
75582
+ return "Update this installation manually with its package manager.";
75583
+ return [target.command, ...target.args].map((arg) => /^[\w@./:=+-]+$/.test(arg) ? arg : JSON.stringify(arg)).join(" ");
75512
75584
  }
75513
75585
  async function buildUpdateInfo(latestVersion) {
75514
75586
  return {
75515
75587
  hasUpdate: true,
75516
75588
  currentVersion: getCurrentVersion(),
75517
75589
  latestVersion,
75518
- updateCommand: await resolveUpdateCommand()
75590
+ updateCommand: formatUpdateCommand(resolveUpdateTarget(latestVersion))
75519
75591
  };
75520
75592
  }
75521
75593
  async function checkForUpdates() {
75522
75594
  const state = loadUpdateState();
75523
75595
  const currentVersion = getCurrentVersion();
75524
75596
  const now = Date.now();
75525
- if (now - state.lastCheck < CHECK_INTERVAL_MS) {
75597
+ if (now - state.lastCheck < CHECK_INTERVAL_MS && (!state.latestVersion || compareVersions(state.latestVersion, currentVersion) >= 0)) {
75526
75598
  if (state.latestVersion && compareVersions(state.latestVersion, currentVersion) > 0) {
75527
75599
  if (state.dismissed === state.latestVersion) {
75528
75600
  return null;
@@ -75556,13 +75628,20 @@ async function forceCheckForUpdates() {
75556
75628
  saveUpdateState(state);
75557
75629
  return checkForUpdates();
75558
75630
  }
75559
- async function performUpdate() {
75560
- const updateCommand = await resolveUpdateCommand();
75631
+ async function performUpdate(version = "latest") {
75632
+ const target = resolveUpdateTarget(version);
75633
+ if (!target)
75634
+ return { success: false, output: "Cannot identify this installation's package manager; update it manually." };
75635
+ const updateCommand = formatUpdateCommand(target);
75561
75636
  return new Promise((resolve) => {
75562
- const child = spawn(updateCommand, {
75637
+ const child = process.platform === "win32" ? spawn(updateCommand, {
75563
75638
  shell: true,
75564
75639
  stdio: ["ignore", "pipe", "pipe"],
75565
- env: process.env
75640
+ env: { ...process.env, ...target.env }
75641
+ }) : spawn(target.command, target.args, {
75642
+ shell: false,
75643
+ stdio: ["ignore", "pipe", "pipe"],
75644
+ env: { ...process.env, ...target.env }
75566
75645
  });
75567
75646
  let stdout = "";
75568
75647
  let stderr = "";
@@ -75610,7 +75689,7 @@ async function processUpdateCheck(options) {
75610
75689
  return { action: "none" };
75611
75690
  }
75612
75691
  if (install || autoUpdate) {
75613
- const result = await performUpdate();
75692
+ const result = await performUpdate(update.latestVersion);
75614
75693
  if (result.success) {
75615
75694
  dismissUpdate(update.latestVersion);
75616
75695
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@austinthesing/magic-shell",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "Natural language to terminal commands with safety features. Supports OpenCode Zen, OpenRouter, AI gateways, Workers AI, and custom models.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",