astragate 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1238,7 +1238,7 @@ import { fileURLToPath } from "url";
1238
1238
  // package.json
1239
1239
  var package_default = {
1240
1240
  name: "astragate",
1241
- version: "0.9.2",
1241
+ version: "0.9.4",
1242
1242
  description: "Astra \u2014 a local AI gateway. Install, start, stop and manage the astra-server from the terminal.",
1243
1243
  license: "MIT",
1244
1244
  type: "module",
@@ -1269,12 +1269,12 @@ var package_default = {
1269
1269
  commander: "^12.1.0"
1270
1270
  },
1271
1271
  optionalDependencies: {
1272
- "@aidotnet/server-darwin-arm64": "0.9.2",
1273
- "@aidotnet/server-darwin-x64": "0.9.2",
1274
- "@aidotnet/server-linux-arm64": "0.9.2",
1275
- "@aidotnet/server-linux-x64": "0.9.2",
1276
- "@aidotnet/server-win32-arm64": "0.9.2",
1277
- "@aidotnet/server-win32-x64": "0.9.2"
1272
+ "@aidotnet/server-darwin-arm64": "0.9.4",
1273
+ "@aidotnet/server-darwin-x64": "0.9.4",
1274
+ "@aidotnet/server-linux-arm64": "0.9.4",
1275
+ "@aidotnet/server-linux-x64": "0.9.4",
1276
+ "@aidotnet/server-win32-arm64": "0.9.4",
1277
+ "@aidotnet/server-win32-x64": "0.9.4"
1278
1278
  },
1279
1279
  devDependencies: {
1280
1280
  "@aidotnet/update-core": "workspace:*",
@@ -1786,6 +1786,8 @@ import os3 from "os";
1786
1786
  import path12 from "path";
1787
1787
  var LAUNCHD_LABEL = "io.astra.server";
1788
1788
  var SYSTEMD_UNIT_NAME = "astra.service";
1789
+ var RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
1790
+ var RUN_VALUE_NAME = "Astra Server";
1789
1791
  var SCHTASKS_TASK_NAME = "Astra Server";
1790
1792
  function xmlEscape(s) {
1791
1793
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
@@ -1840,12 +1842,17 @@ RestartSec=3
1840
1842
  WantedBy=default.target
1841
1843
  `;
1842
1844
  }
1843
- function quoteForTr(argv) {
1844
- const inner = argv.map((a) => /[\s"]/.test(a) ? `"${a}"` : a).join(" ").replace(/"/g, '\\"');
1845
- return `"${inner}"`;
1845
+ function windowsCommandLine(argv) {
1846
+ return argv.map((a, i) => i === 0 || a === "" || /[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a).join(" ");
1846
1847
  }
1847
- function schtasksCreateArgs(argv) {
1848
- return ["/Create", "/F", "/SC", "ONLOGON", "/TN", SCHTASKS_TASK_NAME, "/TR", quoteForTr(argv)];
1848
+ function regAddArgs(argv) {
1849
+ return ["add", RUN_KEY, "/v", RUN_VALUE_NAME, "/t", "REG_SZ", "/d", windowsCommandLine(argv), "/f"];
1850
+ }
1851
+ function regDeleteArgs() {
1852
+ return ["delete", RUN_KEY, "/v", RUN_VALUE_NAME, "/f"];
1853
+ }
1854
+ function regQueryArgs() {
1855
+ return ["query", RUN_KEY, "/v", RUN_VALUE_NAME];
1849
1856
  }
1850
1857
  function schtasksDeleteArgs() {
1851
1858
  return ["/Delete", "/F", "/TN", SCHTASKS_TASK_NAME];
@@ -1911,21 +1918,39 @@ async function autostartStatusLinux(home = os3.homedir()) {
1911
1918
  const r = await exec(["systemctl", "--user", "is-enabled", SYSTEMD_UNIT_NAME]).catch(() => null);
1912
1919
  return r !== null && r.code === 0 && r.stdout.trim() === "enabled" ? "enabled" : "disabled";
1913
1920
  }
1921
+ async function legacyTaskExists() {
1922
+ const r = await exec(["schtasks", ...schtasksQueryArgs()]).catch(() => null);
1923
+ return r !== null && r.code === 0;
1924
+ }
1925
+ async function removeLegacyTask() {
1926
+ if (!await legacyTaskExists()) return true;
1927
+ await exec(["schtasks", ...schtasksDeleteArgs()]).catch(() => void 0);
1928
+ return !await legacyTaskExists();
1929
+ }
1914
1930
  async function enableAutostartWindows(argv) {
1915
- const r = await exec(["schtasks", ...schtasksCreateArgs(argv)]);
1931
+ const r = await exec(["reg", ...regAddArgs(argv)]);
1916
1932
  if (r.code !== 0) {
1917
- throw new AstraError("schtasks /Create failed.", r.stderr.trim() || void 0);
1933
+ throw new AstraError("reg add failed.", r.stderr.trim() || void 0);
1918
1934
  }
1935
+ await removeLegacyTask();
1919
1936
  }
1920
1937
  async function disableAutostartWindows() {
1921
- const r = await exec(["schtasks", ...schtasksDeleteArgs()]);
1922
- if (r.code !== 0 && !/does not exist|no existe/i.test(r.stderr + r.stdout)) {
1923
- throw new AstraError("schtasks /Delete failed.", r.stderr.trim() || void 0);
1938
+ await exec(["reg", ...regDeleteArgs()]).catch(() => void 0);
1939
+ const still = await exec(["reg", ...regQueryArgs()]);
1940
+ if (still.code === 0) {
1941
+ throw new AstraError("reg delete failed.", `Remove the "${RUN_VALUE_NAME}" value under ${RUN_KEY}.`);
1942
+ }
1943
+ if (!await removeLegacyTask()) {
1944
+ throw new AstraError(
1945
+ `The scheduled task "${SCHTASKS_TASK_NAME}" could not be removed.`,
1946
+ `Run from an administrator prompt: schtasks /Delete /F /TN "${SCHTASKS_TASK_NAME}"`
1947
+ );
1924
1948
  }
1925
1949
  }
1926
1950
  async function autostartStatusWindows() {
1927
- const r = await exec(["schtasks", ...schtasksQueryArgs()]);
1928
- return r.code === 0 ? "enabled" : "disabled";
1951
+ const r = await exec(["reg", ...regQueryArgs()]);
1952
+ if (r.code === 0) return "enabled";
1953
+ return await legacyTaskExists() ? "enabled" : "disabled";
1929
1954
  }
1930
1955
 
1931
1956
  // src/commands/autostart.ts
@@ -3070,7 +3095,7 @@ program.command("status").description("Show whether the server is running and it
3070
3095
  program.command("logs").description("Show recent server logs").option("-f, --follow", "Keep printing new log output").action((opts) => runLogs(opts));
3071
3096
  program.command("open").description("Open the Astra web UI in the default browser").action(() => runOpen());
3072
3097
  var autostart = program.command("autostart").description("Manage starting Astra at login");
3073
- autostart.command("enable").description("Enable autostart (LaunchAgent / systemd --user / schtasks)").action(() => runAutostart("enable"));
3098
+ autostart.command("enable").description("Enable autostart (LaunchAgent / systemd --user / Run registry key)").action(() => runAutostart("enable"));
3074
3099
  autostart.command("disable").description("Disable autostart").action(() => runAutostart("disable"));
3075
3100
  autostart.command("status").description("Show whether autostart is enabled").action(() => runAutostart("status"));
3076
3101
  program.command("install").description("Install optional Astra components").option("--desktop", "Install the Astra desktop app for this platform").option("--client", "Alias of --desktop").action(