@devness/useai-cli 0.5.17 → 0.5.18

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 (2) hide show
  1. package/dist/index.js +91 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ var SYSTEMD_SERVICE_PATH = join(homedir(), ".config", "systemd", "user", "useai-
30
30
  var WINDOWS_STARTUP_SCRIPT_PATH = join(process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "useai-daemon.vbs");
31
31
 
32
32
  // ../shared/dist/constants/version.js
33
- var VERSION = "0.5.17";
33
+ var VERSION = "0.5.18";
34
34
 
35
35
  // ../shared/dist/constants/defaults.js
36
36
  var DEFAULT_CONFIG = {
@@ -4736,13 +4736,25 @@ function detectPlatform() {
4736
4736
  return "unsupported";
4737
4737
  }
4738
4738
  }
4739
+ var LAUNCHD_LABEL = "dev.useai.daemon";
4740
+ function getLaunchdDomain() {
4741
+ try {
4742
+ const uid = execSync3("id -u", { encoding: "utf-8" }).trim();
4743
+ return `gui/${uid}`;
4744
+ } catch {
4745
+ return `gui/${process.getuid?.() ?? 501}`;
4746
+ }
4747
+ }
4748
+ function getLaunchdServiceTarget() {
4749
+ return `${getLaunchdDomain()}/${LAUNCHD_LABEL}`;
4750
+ }
4739
4751
  function buildPlist(npxPath, nodePath) {
4740
4752
  return `<?xml version="1.0" encoding="UTF-8"?>
4741
4753
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4742
4754
  <plist version="1.0">
4743
4755
  <dict>
4744
4756
  <key>Label</key>
4745
- <string>dev.useai.daemon</string>
4757
+ <string>${LAUNCHD_LABEL}</string>
4746
4758
  <key>ProgramArguments</key>
4747
4759
  <array>
4748
4760
  <string>${npxPath}</string>
@@ -4761,6 +4773,10 @@ function buildPlist(npxPath, nodePath) {
4761
4773
  </dict>
4762
4774
  <key>ThrottleInterval</key>
4763
4775
  <integer>10</integer>
4776
+ <key>ExitTimeOut</key>
4777
+ <integer>10</integer>
4778
+ <key>ProcessType</key>
4779
+ <string>Background</string>
4764
4780
  <key>StandardOutPath</key>
4765
4781
  <string>${DAEMON_LOG_FILE}</string>
4766
4782
  <key>StandardErrorPath</key>
@@ -4777,17 +4793,24 @@ function buildPlist(npxPath, nodePath) {
4777
4793
  function installMacos() {
4778
4794
  const npxPath = resolveNpxPath();
4779
4795
  const nodePath = buildNodePath();
4796
+ const target = getLaunchdServiceTarget();
4797
+ const domain = getLaunchdDomain();
4780
4798
  mkdirSync2(dirname(LAUNCHD_PLIST_PATH), { recursive: true });
4781
4799
  writeFileSync2(LAUNCHD_PLIST_PATH, buildPlist(npxPath, nodePath));
4782
4800
  try {
4783
- execSync3(`launchctl unload "${LAUNCHD_PLIST_PATH}" 2>/dev/null`, { stdio: "ignore" });
4801
+ execSync3(`launchctl bootout ${target} 2>/dev/null`, { stdio: "ignore" });
4784
4802
  } catch {
4785
4803
  }
4786
- execSync3(`launchctl load "${LAUNCHD_PLIST_PATH}"`, { stdio: "ignore" });
4804
+ try {
4805
+ execSync3(`launchctl enable ${target}`, { stdio: "ignore" });
4806
+ } catch {
4807
+ }
4808
+ execSync3(`launchctl bootstrap ${domain} "${LAUNCHD_PLIST_PATH}"`, { stdio: "ignore" });
4787
4809
  }
4788
4810
  function removeMacos() {
4811
+ const target = getLaunchdServiceTarget();
4789
4812
  try {
4790
- execSync3(`launchctl unload "${LAUNCHD_PLIST_PATH}" 2>/dev/null`, { stdio: "ignore" });
4813
+ execSync3(`launchctl bootout ${target} 2>/dev/null`, { stdio: "ignore" });
4791
4814
  } catch {
4792
4815
  }
4793
4816
  try {
@@ -4803,6 +4826,8 @@ function buildSystemdUnit(npxPath, nodePath) {
4803
4826
  return `[Unit]
4804
4827
  Description=UseAI Daemon
4805
4828
  After=network.target
4829
+ StartLimitBurst=5
4830
+ StartLimitIntervalSec=60
4806
4831
 
4807
4832
  [Service]
4808
4833
  Type=simple
@@ -4820,6 +4845,10 @@ function installLinux() {
4820
4845
  const nodePath = buildNodePath();
4821
4846
  mkdirSync2(dirname(SYSTEMD_SERVICE_PATH), { recursive: true });
4822
4847
  writeFileSync2(SYSTEMD_SERVICE_PATH, buildSystemdUnit(npxPath, nodePath));
4848
+ try {
4849
+ execSync3("systemctl --user reset-failed useai-daemon.service", { stdio: "ignore" });
4850
+ } catch {
4851
+ }
4823
4852
  execSync3("systemctl --user daemon-reload", { stdio: "ignore" });
4824
4853
  execSync3("systemctl --user enable --now useai-daemon.service", { stdio: "ignore" });
4825
4854
  }
@@ -4906,6 +4935,45 @@ function isAutostartInstalled() {
4906
4935
  return false;
4907
4936
  }
4908
4937
  }
4938
+ function recoverAutostart() {
4939
+ const platform = detectPlatform();
4940
+ switch (platform) {
4941
+ case "macos": {
4942
+ if (!existsSync6(LAUNCHD_PLIST_PATH)) {
4943
+ return { recovered: false, message: "Auto-start is not installed (plist missing)" };
4944
+ }
4945
+ const target = getLaunchdServiceTarget();
4946
+ const domain = getLaunchdDomain();
4947
+ try {
4948
+ execSync3(`launchctl enable ${target}`, { stdio: "ignore" });
4949
+ try {
4950
+ execSync3(`launchctl bootout ${target} 2>/dev/null`, { stdio: "ignore" });
4951
+ } catch {
4952
+ }
4953
+ execSync3(`launchctl bootstrap ${domain} "${LAUNCHD_PLIST_PATH}"`, { stdio: "ignore" });
4954
+ return { recovered: true, message: "Re-enabled and bootstrapped launchd service" };
4955
+ } catch (e) {
4956
+ return { recovered: false, message: `Failed to recover: ${e.message}` };
4957
+ }
4958
+ }
4959
+ case "linux": {
4960
+ if (!existsSync6(SYSTEMD_SERVICE_PATH)) {
4961
+ return { recovered: false, message: "Auto-start is not installed (unit file missing)" };
4962
+ }
4963
+ try {
4964
+ execSync3("systemctl --user reset-failed useai-daemon.service", { stdio: "ignore" });
4965
+ execSync3("systemctl --user start useai-daemon.service", { stdio: "ignore" });
4966
+ return { recovered: true, message: "Reset systemd failed state and started service" };
4967
+ } catch (e) {
4968
+ return { recovered: false, message: `Failed to recover: ${e.message}` };
4969
+ }
4970
+ }
4971
+ case "windows":
4972
+ return { recovered: false, message: "Recovery is not needed on Windows (no crash loop protection)" };
4973
+ default:
4974
+ return { recovered: false, message: `Unsupported platform: ${process.platform}` };
4975
+ }
4976
+ }
4909
4977
 
4910
4978
  // ../shared/dist/hooks/claude-code.js
4911
4979
  import { existsSync as existsSync7, readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3, unlinkSync as unlinkSync3, chmodSync } from "fs";
@@ -6003,7 +6071,24 @@ var autostartStatusCommand = new Command8("status").description("Check auto-star
6003
6071
  console.log(chalk7.dim(` Auto-start is not installed`));
6004
6072
  }
6005
6073
  });
6006
- var autostartCommand = new Command8("autostart").description("Manage auto-start service").addCommand(autostartInstallCommand).addCommand(autostartRemoveCommand).addCommand(autostartStatusCommand);
6074
+ var autostartRecoverCommand = new Command8("recover").description("Recover auto-start from disabled/failed state (after crash loops)").action(() => {
6075
+ const platform = detectPlatform();
6076
+ if (platform === "unsupported") {
6077
+ console.log(chalk7.red(` \u2717 Auto-start is not supported on ${process.platform}`));
6078
+ return;
6079
+ }
6080
+ if (!isAutostartInstalled()) {
6081
+ console.log(chalk7.yellow(" Auto-start is not installed. Run: useai daemon autostart install"));
6082
+ return;
6083
+ }
6084
+ const result = recoverAutostart();
6085
+ if (result.recovered) {
6086
+ console.log(chalk7.green(` \u2713 ${result.message}`));
6087
+ } else {
6088
+ console.log(chalk7.yellow(` ${result.message}`));
6089
+ }
6090
+ });
6091
+ var autostartCommand = new Command8("autostart").description("Manage auto-start service").addCommand(autostartInstallCommand).addCommand(autostartRemoveCommand).addCommand(autostartStatusCommand).addCommand(autostartRecoverCommand);
6007
6092
  var daemonCommand = new Command8("daemon").description("Manage the UseAI HTTP daemon").addCommand(startCommand).addCommand(stopCommand).addCommand(statusCommand2).addCommand(autostartCommand);
6008
6093
 
6009
6094
  // src/commands/serve.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devness/useai-cli",
3
- "version": "0.5.17",
3
+ "version": "0.5.18",
4
4
  "description": "CLI tool for useai.dev — stats, sync, publish your AI development workflow",
5
5
  "author": "nabeelkausari",
6
6
  "license": "MIT",