9router-proxy 0.5.83 → 0.5.84

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 (213) hide show
  1. package/app/.next-cli-build/BUILD_ID +1 -1
  2. package/app/.next-cli-build/app-path-routes-manifest.json +4 -4
  3. package/app/.next-cli-build/build-manifest.json +2 -2
  4. package/app/.next-cli-build/prerender-manifest.json +3 -3
  5. package/app/.next-cli-build/server/app/(dashboard)/dashboard/basic-chat/page_client-reference-manifest.js +1 -1
  6. package/app/.next-cli-build/server/app/(dashboard)/dashboard/cli-tools/[toolId]/page_client-reference-manifest.js +1 -1
  7. package/app/.next-cli-build/server/app/(dashboard)/dashboard/cli-tools/page_client-reference-manifest.js +1 -1
  8. package/app/.next-cli-build/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
  9. package/app/.next-cli-build/server/app/(dashboard)/dashboard/console-log/page_client-reference-manifest.js +1 -1
  10. package/app/.next-cli-build/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
  11. package/app/.next-cli-build/server/app/(dashboard)/dashboard/media-providers/[kind]/[id]/page_client-reference-manifest.js +1 -1
  12. package/app/.next-cli-build/server/app/(dashboard)/dashboard/media-providers/[kind]/page_client-reference-manifest.js +1 -1
  13. package/app/.next-cli-build/server/app/(dashboard)/dashboard/media-providers/combo/[id]/page_client-reference-manifest.js +1 -1
  14. package/app/.next-cli-build/server/app/(dashboard)/dashboard/media-providers/web/page_client-reference-manifest.js +1 -1
  15. package/app/.next-cli-build/server/app/(dashboard)/dashboard/mitm/page_client-reference-manifest.js +1 -1
  16. package/app/.next-cli-build/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
  17. package/app/.next-cli-build/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
  18. package/app/.next-cli-build/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
  19. package/app/.next-cli-build/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
  20. package/app/.next-cli-build/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
  21. package/app/.next-cli-build/server/app/(dashboard)/dashboard/proxy-pools/page_client-reference-manifest.js +1 -1
  22. package/app/.next-cli-build/server/app/(dashboard)/dashboard/pxpipe/page_client-reference-manifest.js +1 -1
  23. package/app/.next-cli-build/server/app/(dashboard)/dashboard/quota/page_client-reference-manifest.js +1 -1
  24. package/app/.next-cli-build/server/app/(dashboard)/dashboard/skills/page_client-reference-manifest.js +1 -1
  25. package/app/.next-cli-build/server/app/(dashboard)/dashboard/token-saver/page_client-reference-manifest.js +1 -1
  26. package/app/.next-cli-build/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
  27. package/app/.next-cli-build/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
  28. package/app/.next-cli-build/server/app/_global-error/page_client-reference-manifest.js +1 -1
  29. package/app/.next-cli-build/server/app/_global-error.html +1 -1
  30. package/app/.next-cli-build/server/app/_global-error.rsc +1 -1
  31. package/app/.next-cli-build/server/app/_global-error.segments/_full.segment.rsc +1 -1
  32. package/app/.next-cli-build/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  33. package/app/.next-cli-build/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  34. package/app/.next-cli-build/server/app/_not-found/page_client-reference-manifest.js +1 -1
  35. package/app/.next-cli-build/server/app/_not-found.html +1 -1
  36. package/app/.next-cli-build/server/app/_not-found.rsc +4 -4
  37. package/app/.next-cli-build/server/app/_not-found.segments/_full.segment.rsc +4 -4
  38. package/app/.next-cli-build/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +4 -4
  39. package/app/.next-cli-build/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  40. package/app/.next-cli-build/server/app/api/cli-tools/all-statuses/route.js +5 -5
  41. package/app/.next-cli-build/server/app/api/cli-tools/antigravity-mitm/alias/route.js +2 -2
  42. package/app/.next-cli-build/server/app/api/cli-tools/claude-settings/route.js +2 -2
  43. package/app/.next-cli-build/server/app/api/cli-tools/cline-settings/route.js +2 -2
  44. package/app/.next-cli-build/server/app/api/cli-tools/codex-settings/route.js +1 -1
  45. package/app/.next-cli-build/server/app/api/cli-tools/copilot-settings/route.js +2 -2
  46. package/app/.next-cli-build/server/app/api/cli-tools/cowork-mcp-registry/route.js +1 -1
  47. package/app/.next-cli-build/server/app/api/cli-tools/cowork-mcp-tools/route.js +1 -1
  48. package/app/.next-cli-build/server/app/api/cli-tools/cowork-settings/route.js +2 -2
  49. package/app/.next-cli-build/server/app/api/cli-tools/deepseek-tui-settings/route.js +3 -3
  50. package/app/.next-cli-build/server/app/api/cli-tools/devin-settings/route.js +1 -1
  51. package/app/.next-cli-build/server/app/api/cli-tools/droid-settings/route.js +2 -2
  52. package/app/.next-cli-build/server/app/api/cli-tools/grok-build-settings/route.js +2 -2
  53. package/app/.next-cli-build/server/app/api/cli-tools/hermes-settings/route.js +3 -3
  54. package/app/.next-cli-build/server/app/api/cli-tools/jcode-settings/route.js +2 -2
  55. package/app/.next-cli-build/server/app/api/cli-tools/kilo-settings/route.js +2 -2
  56. package/app/.next-cli-build/server/app/api/cli-tools/openclaw-settings/route.js +2 -2
  57. package/app/.next-cli-build/server/app/api/cli-tools/opencode-settings/route.js +1 -1
  58. package/app/.next-cli-build/server/app/api/oauth/[provider]/[action]/route.js +1 -1
  59. package/app/.next-cli-build/server/app/api/oauth/codex/bulk-import/route.js +1 -1
  60. package/app/.next-cli-build/server/app/api/oauth/codex/import-token/route.js +1 -1
  61. package/app/.next-cli-build/server/app/api/providers/client/route.js +1 -1
  62. package/app/.next-cli-build/server/app/api/providers/validate/route.js +1 -1
  63. package/app/.next-cli-build/server/app/api/translator/send/route.js +1 -1
  64. package/app/.next-cli-build/server/app/api/translator/translate/route.js +1 -1
  65. package/app/.next-cli-build/server/app/api/tunnel/tailscale-install/route.js +2 -2
  66. package/app/.next-cli-build/server/app/api/usage/[connectionId]/codex-reset-credits/route.js +1 -1
  67. package/app/.next-cli-build/server/app/api/usage/[connectionId]/route.js +1 -1
  68. package/app/.next-cli-build/server/app/api/version/route.js +1 -1
  69. package/app/.next-cli-build/server/app/api/version/shutdown/route.js +1 -1
  70. package/app/.next-cli-build/server/app/api/version/update/route.js +1 -1
  71. package/app/.next-cli-build/server/app/callback/page_client-reference-manifest.js +1 -1
  72. package/app/.next-cli-build/server/app/callback.html +1 -1
  73. package/app/.next-cli-build/server/app/callback.rsc +4 -4
  74. package/app/.next-cli-build/server/app/callback.segments/_full.segment.rsc +4 -4
  75. package/app/.next-cli-build/server/app/callback.segments/_tree.segment.rsc +1 -1
  76. package/app/.next-cli-build/server/app/callback.segments/callback/__PAGE__.segment.rsc +4 -4
  77. package/app/.next-cli-build/server/app/dashboard/basic-chat.html +1 -1
  78. package/app/.next-cli-build/server/app/dashboard/basic-chat.rsc +6 -6
  79. package/app/.next-cli-build/server/app/dashboard/basic-chat.segments/!KGRhc2hib2FyZCk/dashboard/basic-chat/__PAGE__.segment.rsc +6 -6
  80. package/app/.next-cli-build/server/app/dashboard/basic-chat.segments/_full.segment.rsc +6 -6
  81. package/app/.next-cli-build/server/app/dashboard/basic-chat.segments/_tree.segment.rsc +1 -1
  82. package/app/.next-cli-build/server/app/dashboard/cli-tools.html +1 -1
  83. package/app/.next-cli-build/server/app/dashboard/cli-tools.rsc +6 -6
  84. package/app/.next-cli-build/server/app/dashboard/cli-tools.segments/!KGRhc2hib2FyZCk/dashboard/cli-tools/__PAGE__.segment.rsc +6 -6
  85. package/app/.next-cli-build/server/app/dashboard/cli-tools.segments/_full.segment.rsc +6 -6
  86. package/app/.next-cli-build/server/app/dashboard/cli-tools.segments/_tree.segment.rsc +1 -1
  87. package/app/.next-cli-build/server/app/dashboard/combos.html +1 -1
  88. package/app/.next-cli-build/server/app/dashboard/combos.rsc +6 -6
  89. package/app/.next-cli-build/server/app/dashboard/combos.segments/!KGRhc2hib2FyZCk/dashboard/combos/__PAGE__.segment.rsc +6 -6
  90. package/app/.next-cli-build/server/app/dashboard/combos.segments/_full.segment.rsc +6 -6
  91. package/app/.next-cli-build/server/app/dashboard/combos.segments/_tree.segment.rsc +1 -1
  92. package/app/.next-cli-build/server/app/dashboard/endpoint.html +1 -1
  93. package/app/.next-cli-build/server/app/dashboard/endpoint.rsc +6 -6
  94. package/app/.next-cli-build/server/app/dashboard/endpoint.segments/!KGRhc2hib2FyZCk/dashboard/endpoint/__PAGE__.segment.rsc +6 -6
  95. package/app/.next-cli-build/server/app/dashboard/endpoint.segments/_full.segment.rsc +6 -6
  96. package/app/.next-cli-build/server/app/dashboard/endpoint.segments/_tree.segment.rsc +1 -1
  97. package/app/.next-cli-build/server/app/dashboard/media-providers/web.html +1 -1
  98. package/app/.next-cli-build/server/app/dashboard/media-providers/web.rsc +6 -6
  99. package/app/.next-cli-build/server/app/dashboard/media-providers/web.segments/!KGRhc2hib2FyZCk/dashboard/media-providers/web/__PAGE__.segment.rsc +6 -6
  100. package/app/.next-cli-build/server/app/dashboard/media-providers/web.segments/_full.segment.rsc +6 -6
  101. package/app/.next-cli-build/server/app/dashboard/media-providers/web.segments/_tree.segment.rsc +1 -1
  102. package/app/.next-cli-build/server/app/dashboard/mitm.html +1 -1
  103. package/app/.next-cli-build/server/app/dashboard/mitm.rsc +6 -6
  104. package/app/.next-cli-build/server/app/dashboard/mitm.segments/!KGRhc2hib2FyZCk/dashboard/mitm/__PAGE__.segment.rsc +6 -6
  105. package/app/.next-cli-build/server/app/dashboard/mitm.segments/_full.segment.rsc +6 -6
  106. package/app/.next-cli-build/server/app/dashboard/mitm.segments/_tree.segment.rsc +1 -1
  107. package/app/.next-cli-build/server/app/dashboard/profile.html +1 -1
  108. package/app/.next-cli-build/server/app/dashboard/profile.rsc +6 -6
  109. package/app/.next-cli-build/server/app/dashboard/profile.segments/!KGRhc2hib2FyZCk/dashboard/profile/__PAGE__.segment.rsc +6 -6
  110. package/app/.next-cli-build/server/app/dashboard/profile.segments/_full.segment.rsc +6 -6
  111. package/app/.next-cli-build/server/app/dashboard/profile.segments/_tree.segment.rsc +1 -1
  112. package/app/.next-cli-build/server/app/dashboard/providers/new.html +1 -1
  113. package/app/.next-cli-build/server/app/dashboard/providers/new.rsc +6 -6
  114. package/app/.next-cli-build/server/app/dashboard/providers/new.segments/!KGRhc2hib2FyZCk/dashboard/providers/new/__PAGE__.segment.rsc +6 -6
  115. package/app/.next-cli-build/server/app/dashboard/providers/new.segments/_full.segment.rsc +6 -6
  116. package/app/.next-cli-build/server/app/dashboard/providers/new.segments/_tree.segment.rsc +1 -1
  117. package/app/.next-cli-build/server/app/dashboard/providers.html +1 -1
  118. package/app/.next-cli-build/server/app/dashboard/providers.rsc +6 -6
  119. package/app/.next-cli-build/server/app/dashboard/providers.segments/!KGRhc2hib2FyZCk/dashboard/providers/__PAGE__.segment.rsc +6 -6
  120. package/app/.next-cli-build/server/app/dashboard/providers.segments/_full.segment.rsc +6 -6
  121. package/app/.next-cli-build/server/app/dashboard/providers.segments/_tree.segment.rsc +1 -1
  122. package/app/.next-cli-build/server/app/dashboard/proxy-pools.html +1 -1
  123. package/app/.next-cli-build/server/app/dashboard/proxy-pools.rsc +6 -6
  124. package/app/.next-cli-build/server/app/dashboard/proxy-pools.segments/!KGRhc2hib2FyZCk/dashboard/proxy-pools/__PAGE__.segment.rsc +6 -6
  125. package/app/.next-cli-build/server/app/dashboard/proxy-pools.segments/_full.segment.rsc +6 -6
  126. package/app/.next-cli-build/server/app/dashboard/proxy-pools.segments/_tree.segment.rsc +1 -1
  127. package/app/.next-cli-build/server/app/dashboard/pxpipe.html +1 -1
  128. package/app/.next-cli-build/server/app/dashboard/pxpipe.rsc +6 -6
  129. package/app/.next-cli-build/server/app/dashboard/pxpipe.segments/!KGRhc2hib2FyZCk/dashboard/pxpipe/__PAGE__.segment.rsc +6 -6
  130. package/app/.next-cli-build/server/app/dashboard/pxpipe.segments/_full.segment.rsc +6 -6
  131. package/app/.next-cli-build/server/app/dashboard/pxpipe.segments/_tree.segment.rsc +1 -1
  132. package/app/.next-cli-build/server/app/dashboard/quota.html +2 -2
  133. package/app/.next-cli-build/server/app/dashboard/quota.rsc +7 -7
  134. package/app/.next-cli-build/server/app/dashboard/quota.segments/!KGRhc2hib2FyZCk/dashboard/quota/__PAGE__.segment.rsc +7 -7
  135. package/app/.next-cli-build/server/app/dashboard/quota.segments/_full.segment.rsc +7 -7
  136. package/app/.next-cli-build/server/app/dashboard/quota.segments/_tree.segment.rsc +1 -1
  137. package/app/.next-cli-build/server/app/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
  138. package/app/.next-cli-build/server/app/dashboard/settings/pricing.html +1 -1
  139. package/app/.next-cli-build/server/app/dashboard/settings/pricing.rsc +4 -4
  140. package/app/.next-cli-build/server/app/dashboard/settings/pricing.segments/_full.segment.rsc +4 -4
  141. package/app/.next-cli-build/server/app/dashboard/settings/pricing.segments/_tree.segment.rsc +1 -1
  142. package/app/.next-cli-build/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing/__PAGE__.segment.rsc +4 -4
  143. package/app/.next-cli-build/server/app/dashboard/skills.html +1 -1
  144. package/app/.next-cli-build/server/app/dashboard/skills.rsc +6 -6
  145. package/app/.next-cli-build/server/app/dashboard/skills.segments/!KGRhc2hib2FyZCk/dashboard/skills/__PAGE__.segment.rsc +6 -6
  146. package/app/.next-cli-build/server/app/dashboard/skills.segments/_full.segment.rsc +6 -6
  147. package/app/.next-cli-build/server/app/dashboard/skills.segments/_tree.segment.rsc +1 -1
  148. package/app/.next-cli-build/server/app/dashboard/token-saver.html +1 -1
  149. package/app/.next-cli-build/server/app/dashboard/token-saver.rsc +6 -6
  150. package/app/.next-cli-build/server/app/dashboard/token-saver.segments/!KGRhc2hib2FyZCk/dashboard/token-saver/__PAGE__.segment.rsc +6 -6
  151. package/app/.next-cli-build/server/app/dashboard/token-saver.segments/_full.segment.rsc +6 -6
  152. package/app/.next-cli-build/server/app/dashboard/token-saver.segments/_tree.segment.rsc +1 -1
  153. package/app/.next-cli-build/server/app/dashboard/translator.html +1 -1
  154. package/app/.next-cli-build/server/app/dashboard/translator.rsc +6 -6
  155. package/app/.next-cli-build/server/app/dashboard/translator.segments/!KGRhc2hib2FyZCk/dashboard/translator/__PAGE__.segment.rsc +6 -6
  156. package/app/.next-cli-build/server/app/dashboard/translator.segments/_full.segment.rsc +6 -6
  157. package/app/.next-cli-build/server/app/dashboard/translator.segments/_tree.segment.rsc +1 -1
  158. package/app/.next-cli-build/server/app/dashboard/usage.html +1 -1
  159. package/app/.next-cli-build/server/app/dashboard/usage.rsc +6 -6
  160. package/app/.next-cli-build/server/app/dashboard/usage.segments/!KGRhc2hib2FyZCk/dashboard/usage/__PAGE__.segment.rsc +6 -6
  161. package/app/.next-cli-build/server/app/dashboard/usage.segments/_full.segment.rsc +6 -6
  162. package/app/.next-cli-build/server/app/dashboard/usage.segments/_tree.segment.rsc +1 -1
  163. package/app/.next-cli-build/server/app/dashboard.html +1 -1
  164. package/app/.next-cli-build/server/app/dashboard.rsc +6 -6
  165. package/app/.next-cli-build/server/app/dashboard.segments/!KGRhc2hib2FyZCk/dashboard/__PAGE__.segment.rsc +6 -6
  166. package/app/.next-cli-build/server/app/dashboard.segments/_full.segment.rsc +6 -6
  167. package/app/.next-cli-build/server/app/dashboard.segments/_tree.segment.rsc +1 -1
  168. package/app/.next-cli-build/server/app/index.html +1 -1
  169. package/app/.next-cli-build/server/app/index.rsc +4 -4
  170. package/app/.next-cli-build/server/app/index.segments/__PAGE__.segment.rsc +4 -4
  171. package/app/.next-cli-build/server/app/index.segments/_full.segment.rsc +4 -4
  172. package/app/.next-cli-build/server/app/index.segments/_tree.segment.rsc +1 -1
  173. package/app/.next-cli-build/server/app/landing/page_client-reference-manifest.js +1 -1
  174. package/app/.next-cli-build/server/app/landing.html +1 -1
  175. package/app/.next-cli-build/server/app/landing.rsc +4 -4
  176. package/app/.next-cli-build/server/app/landing.segments/_full.segment.rsc +4 -4
  177. package/app/.next-cli-build/server/app/landing.segments/_tree.segment.rsc +1 -1
  178. package/app/.next-cli-build/server/app/landing.segments/landing/__PAGE__.segment.rsc +4 -4
  179. package/app/.next-cli-build/server/app/login/page_client-reference-manifest.js +1 -1
  180. package/app/.next-cli-build/server/app/login.html +1 -1
  181. package/app/.next-cli-build/server/app/login.rsc +5 -5
  182. package/app/.next-cli-build/server/app/login.segments/_full.segment.rsc +5 -5
  183. package/app/.next-cli-build/server/app/login.segments/_tree.segment.rsc +1 -1
  184. package/app/.next-cli-build/server/app/login.segments/login/__PAGE__.segment.rsc +5 -5
  185. package/app/.next-cli-build/server/app/page_client-reference-manifest.js +1 -1
  186. package/app/.next-cli-build/server/app-paths-manifest.json +4 -4
  187. package/app/.next-cli-build/server/chunks/1478.js +1 -1
  188. package/app/.next-cli-build/server/chunks/2751.js +1 -1
  189. package/app/.next-cli-build/server/chunks/4037.js +1 -1
  190. package/app/.next-cli-build/server/chunks/4123.js +1 -1
  191. package/app/.next-cli-build/server/chunks/4125.js +1 -1
  192. package/app/.next-cli-build/server/chunks/4572.js +1 -1
  193. package/app/.next-cli-build/server/chunks/8145.js +1 -1
  194. package/app/.next-cli-build/server/chunks/869.js +1 -1
  195. package/app/.next-cli-build/server/chunks/915.js +1 -1
  196. package/app/.next-cli-build/server/middleware-build-manifest.js +1 -1
  197. package/app/.next-cli-build/server/pages/404.html +1 -1
  198. package/app/.next-cli-build/server/pages/500.html +1 -1
  199. package/app/.next-cli-build/server/server-reference-manifest.js +1 -1
  200. package/app/.next-cli-build/server/server-reference-manifest.json +1 -1
  201. package/app/.next-cli-build/static/chunks/{1321-338ffabac587d51a.js → 1321-a5d8e3855a06191d.js} +1 -1
  202. package/app/package.json +1 -1
  203. package/app/src/lib/updater/updater.js +8 -5
  204. package/app/src/mitm/server.js +19 -19
  205. package/cli.js +35 -21
  206. package/hooks/sqliteRuntime.js +1 -8
  207. package/package.json +1 -1
  208. package/src/cli/api/client.js +1 -10
  209. package/src/cli/commands/daemon.js +46 -23
  210. package/src/cli/tray/tray.js +1 -0
  211. package/src/cli/utils/dataDir.js +42 -0
  212. /package/app/.next-cli-build/static/{3C7TjBE-6n_cSjwJbMKkM → 8voY36sc1ZdqaQh3B48Q2}/_buildManifest.js +0 -0
  213. /package/app/.next-cli-build/static/{3C7TjBE-6n_cSjwJbMKkM → 8voY36sc1ZdqaQh3B48Q2}/_ssgManifest.js +0 -0
package/cli.js CHANGED
@@ -65,6 +65,7 @@ function createSpinner(text) {
65
65
  const pkg = require("./package.json");
66
66
  const { ensureSqliteRuntime, buildEnvWithRuntime } = require("./hooks/sqliteRuntime");
67
67
  const { ensureTrayRuntime } = require("./hooks/trayRuntime");
68
+ const { getDataDir } = require("./src/cli/utils/dataDir");
68
69
  const args = process.argv.slice(2);
69
70
 
70
71
  // Subcommands (`9router xai video …`) run against an already-running gateway
@@ -201,13 +202,6 @@ function compareVersions(a, b) {
201
202
  return 0;
202
203
  }
203
204
 
204
- // Get app data dir (matches app/src/lib/dataDir.js convention)
205
- function getAppDataDir() {
206
- return process.platform === "win32"
207
- ? path.join(process.env.APPDATA || "", "9router")
208
- : path.join(os.homedir(), ".9router");
209
- }
210
-
211
205
  // Kill PID from file (best-effort, removes file after)
212
206
  function killByPidFile(pidFile) {
213
207
  try {
@@ -227,7 +221,7 @@ function killByPidFile(pidFile) {
227
221
 
228
222
  // Kill tunnel processes (cloudflared/tailscale) by their PID files
229
223
  function killTunnelByPidFile() {
230
- const tunnelDir = path.join(getAppDataDir(), "tunnel");
224
+ const tunnelDir = path.join(getDataDir(), "tunnel");
231
225
  killByPidFile(path.join(tunnelDir, "cloudflared.pid"));
232
226
  killByPidFile(path.join(tunnelDir, "tailscale.pid"));
233
227
  }
@@ -379,7 +373,7 @@ function waitForExit(pid, timeoutMs) {
379
373
  // Sends SIGTERM first so MIT can clean up host entries before dying.
380
374
  function killProxyByPidFile() {
381
375
  try {
382
- const pidFile = path.join(getAppDataDir(), "mitm", ".mitm.pid");
376
+ const pidFile = path.join(getDataDir(), "mitm", ".mitm.pid");
383
377
  if (!fs.existsSync(pidFile)) return;
384
378
  const pid = parseInt(fs.readFileSync(pidFile, "utf8").trim(), 10);
385
379
  if (!pid) return;
@@ -703,11 +697,12 @@ function startServer(updatePromise) {
703
697
  setTimeout(() => process.exit(0), 100);
704
698
  });
705
699
 
706
- // Initialize tray icon (runs alongside TUI)
700
+ // Initialize tray icon (runs alongside TUI). Returns false on headless sessions
701
+ // (e.g. Linux without a display server) so callers can explain the real state.
707
702
  const initTrayIcon = () => {
708
703
  try {
709
704
  const { initTray } = require("./src/cli/tray/tray");
710
- initTray({
705
+ return initTray({
711
706
  port,
712
707
  onQuit: () => {
713
708
  isShuttingDown = true;
@@ -718,7 +713,7 @@ function startServer(updatePromise) {
718
713
  onOpenDashboard: () => openBrowser(url)
719
714
  });
720
715
  } catch (err) {
721
- // Tray not available - continue without it
716
+ return false;
722
717
  }
723
718
  };
724
719
 
@@ -732,9 +727,13 @@ function startServer(updatePromise) {
732
727
  console.log(`Server: http://${displayHost}:${port}`);
733
728
 
734
729
  waitServerReady(port).then(() => {
735
- initTrayIcon();
736
- console.log("\n💡 Router is now running in system tray. Close this terminal if you want.");
737
- console.log(" Right-click tray icon to open dashboard or quit.\n");
730
+ const tray = initTrayIcon();
731
+ console.log(tray
732
+ ? "\n💡 Router is now running in system tray. Close this terminal if you want."
733
+ : "\n💡 Router is running headless (no system tray on this session).");
734
+ console.log(tray
735
+ ? " Right-click tray icon to open dashboard or quit.\n"
736
+ : ` Open the dashboard in a browser, or stop it with: 9router-proxy stop\n`);
738
737
  });
739
738
 
740
739
  return;
@@ -745,7 +744,7 @@ function startServer(updatePromise) {
745
744
  // Resolve parallel update check (already running); don't block server start on it.
746
745
  const latestVersion = await latestVersionPromise;
747
746
  // Start tray icon alongside TUI
748
- initTrayIcon();
747
+ const trayActive = !!initTrayIcon();
749
748
 
750
749
  try {
751
750
  while (true) {
@@ -778,9 +777,10 @@ function startServer(updatePromise) {
778
777
  clearScreen();
779
778
 
780
779
  // Enable auto startup on OS boot
780
+ let autostartOk = false;
781
781
  try {
782
782
  const { enableAutoStart } = require("./src/cli/tray/autostart");
783
- enableAutoStart(__filename);
783
+ autostartOk = enableAutoStart(__filename) !== false;
784
784
  } catch (e) { }
785
785
 
786
786
  if (process.platform === "darwin") {
@@ -798,8 +798,15 @@ function startServer(updatePromise) {
798
798
  return;
799
799
  }
800
800
 
801
- // Windows/Linux: spawn detached bgProcess (systray works fine in child)
802
- console.log(`\n⏳ Starting background process... (tray icon will appear in ~3s)`);
801
+ if (!trayActive) {
802
+ // No tray session available (e.g. headless Linux): still keep the
803
+ // server alive in the background, but say so instead of pointing
804
+ // at an icon that will never appear.
805
+ console.log(`\n⏳ Starting background process... (no system tray in this session)`);
806
+ } else {
807
+ // Windows/Linux: spawn detached bgProcess (systray works fine in child)
808
+ console.log(`\n⏳ Starting background process... (tray icon will appear in ~3s)`);
809
+ }
803
810
 
804
811
  const bgProcess = spawn(process.execPath, ["--dns-result-order=ipv4first", __filename, "--tray", "--skip-update", "-p", port.toString()], {
805
812
  detached: true,
@@ -811,7 +818,14 @@ function startServer(updatePromise) {
811
818
 
812
819
  console.log(`🔔 9Router is now running in background (PID: ${bgProcess.pid})`);
813
820
  console.log(` Server: http://${displayHost}:${port}`);
814
- console.log(`\n💡 You can close this terminal. Right-click tray icon to quit.\n`);
821
+ if (trayActive) {
822
+ console.log(`\n💡 You can close this terminal. Right-click tray icon to quit.\n`);
823
+ } else {
824
+ console.log(`\n💡 You can close this terminal. Stop the server with: 9router-proxy stop\n`);
825
+ }
826
+ if (!autostartOk) {
827
+ console.log(`⚠️ Could not enable auto-start — it needs a desktop login session.\n`);
828
+ }
815
829
 
816
830
  // cleanup() kills server so bgProcess can claim the port fresh
817
831
  cleanup();
@@ -854,7 +868,7 @@ function startServer(updatePromise) {
854
868
  if (restartCount >= MAX_RESTARTS) {
855
869
  console.error(`\n⚠️ Server crashed ${MAX_RESTARTS} times. Disabling MIT and restarting...`);
856
870
  try {
857
- const dbPath = path.join(os.homedir(), process.platform === "win32" ? path.join("AppData", "Roaming", "9router", "db.json") : path.join(".9router", "db.json"));
871
+ const dbPath = path.join(getDataDir(), "db.json");
858
872
  if (fs.existsSync(dbPath)) {
859
873
  const db = JSON.parse(fs.readFileSync(dbPath, "utf-8"));
860
874
  if (db.settings) db.settings.mitmEnabled = false;
@@ -3,8 +3,8 @@
3
3
  // sql.js is bundled in bin/app already; node:sqlite / bun:sqlite are built-in.
4
4
  const { execSync, spawnSync } = require("child_process");
5
5
  const fs = require("fs");
6
- const os = require("os");
7
6
  const path = require("path");
7
+ const { getDataDir } = require("../src/cli/utils/dataDir");
8
8
 
9
9
  // Gate the pinned version by Node major, mirroring src/lib/db/driver.js gating
10
10
  // style: 13.x is N-API and ships per-platform prebuilds inside the package, so
@@ -15,13 +15,6 @@ const USE_NAPI_BUILD = NODE_MAJOR >= 22;
15
15
  const BETTER_SQLITE3_VERSION = USE_NAPI_BUILD ? "13.0.3" : "12.6.2";
16
16
  const SQL_JS_VERSION = "1.14.1";
17
17
 
18
- function getDataDir() {
19
- if (process.env.DATA_DIR) return process.env.DATA_DIR;
20
- return process.platform === "win32"
21
- ? path.join(process.env.APPDATA || os.homedir(), "9router")
22
- : path.join(os.homedir(), ".9router");
23
- }
24
-
25
18
  function getRuntimeDir() {
26
19
  return path.join(getDataDir(), "runtime");
27
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "9router-proxy",
3
- "version": "0.5.83",
3
+ "version": "0.5.84",
4
4
  "description": "9Router CLI - Start and manage 9Router server",
5
5
  "bin": {
6
6
  "9router-proxy": "./cli.js"
@@ -3,7 +3,6 @@ const https = require("https");
3
3
  const crypto = require("crypto");
4
4
  const fs = require("node:fs");
5
5
  const path = require("node:path");
6
- const os = require("node:os");
7
6
  const { machineIdSync } = require("node-machine-id");
8
7
 
9
8
  // Default configuration
@@ -15,15 +14,7 @@ const DEFAULT_CONFIG = {
15
14
 
16
15
  const CLI_TOKEN_HEADER = "x-9r-cli-token";
17
16
  const CLI_TOKEN_SALT = "9r-cli-auth";
18
- const APP_NAME = "9router";
19
-
20
- function getDataDir() {
21
- if (process.env.DATA_DIR) return process.env.DATA_DIR;
22
- if (process.platform === "win32") {
23
- return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), APP_NAME);
24
- }
25
- return path.join(os.homedir(), `.${APP_NAME}`);
26
- }
17
+ const { getDataDir } = require("../utils/dataDir");
27
18
 
28
19
  const MACHINE_ID_FILE = path.join(getDataDir(), "machine-id");
29
20
  const AUTH_DIR = path.join(getDataDir(), "auth");
@@ -4,8 +4,8 @@
4
4
  const path = require("path");
5
5
  const fs = require("fs");
6
6
  const net = require("net");
7
- const os = require("os");
8
7
  const { spawn, execSync } = require("child_process");
8
+ const { getDataDir } = require("../utils/dataDir");
9
9
  const pkg = require("../../../package.json");
10
10
 
11
11
  const DEFAULT_PORT = 20128;
@@ -15,14 +15,9 @@ const standaloneDir = path.join(cliRoot, "app");
15
15
  const customServerPath = path.join(standaloneDir, "custom-server.js");
16
16
  const serverPath = fs.existsSync(customServerPath) ? customServerPath : path.join(standaloneDir, "server.js");
17
17
 
18
- function getAppDataDir() {
19
- return process.platform === "win32"
20
- ? path.join(process.env.APPDATA || "", "9router")
21
- : path.join(os.homedir(), ".9router");
22
- }
23
-
24
- const pidFile = path.join(getAppDataDir(), "server.pid");
25
- const logFile = path.join(getAppDataDir(), "server.log");
18
+ const APP_DATA_DIR = getDataDir();
19
+ const pidFile = path.join(APP_DATA_DIR, "server.pid");
20
+ const logFile = path.join(APP_DATA_DIR, "server.log");
26
21
 
27
22
  function parseOpts(argv) {
28
23
  const opts = { port: DEFAULT_PORT, host: DEFAULT_HOST, help: false };
@@ -53,17 +48,31 @@ function isAlive(pid) {
53
48
  }
54
49
 
55
50
  // Guard against PID reuse: the recorded PID must look like our server process.
56
- function isOurServer(pid) {
57
- if (!isAlive(pid)) return false;
58
- if (process.platform === "win32") return true;
51
+ // Windows has no `ps`; CIM is the only way to read another process' command line,
52
+ // and without it a recycled PID would be reported as "running".
53
+ function processCommandLine(pid) {
59
54
  try {
60
- const cmd = execSync(`ps -p ${pid} -o command=`, { encoding: "utf8", timeout: 3000 }).toLowerCase();
61
- return cmd.includes("server.js") || cmd.includes("next-server") || cmd.includes("9router");
55
+ if (process.platform === "win32") {
56
+ return execSync(
57
+ `powershell -NoProfile -NonInteractive -WindowStyle Hidden -Command "(Get-CimInstance Win32_Process -Filter 'ProcessId=${pid}').CommandLine"`,
58
+ { encoding: "utf8", timeout: 8000, windowsHide: true }
59
+ );
60
+ }
61
+ return execSync(`ps -p ${pid} -o command=`, { encoding: "utf8", timeout: 3000 });
62
62
  } catch {
63
- return false;
63
+ return "";
64
64
  }
65
65
  }
66
66
 
67
+ function isOurServer(pid) {
68
+ if (!isAlive(pid)) return false;
69
+ const cmd = processCommandLine(pid).toLowerCase();
70
+ // If CIM/powershell is unavailable, fall back to the old Windows behaviour: refusing to
71
+ // stop a live server would orphan it, which is worse than a stale-PID false positive.
72
+ if (!cmd) return process.platform === "win32";
73
+ return cmd.includes("server.js") || cmd.includes("next-server") || cmd.includes("9router");
74
+ }
75
+
67
76
  function tcpProbe(port, timeoutMs = 1000) {
68
77
  return new Promise((resolve) => {
69
78
  const socket = net.connect({ host: "127.0.0.1", port }, () => {
@@ -118,7 +127,7 @@ async function cmdStart(opts) {
118
127
 
119
128
  const { ensureSqliteRuntime, buildEnvWithRuntime } = require("../../../hooks/sqliteRuntime");
120
129
  try { ensureSqliteRuntime({ silent: true }); } catch { /* best-effort; server falls back to sql.js */ }
121
- fs.mkdirSync(getAppDataDir(), { recursive: true });
130
+ fs.mkdirSync(APP_DATA_DIR, { recursive: true });
122
131
  const fd = fs.openSync(logFile, "a");
123
132
  const child = spawn(process.execPath,
124
133
  ["--dns-result-order=ipv4first", "--max-old-space-size=6144", serverPath], {
@@ -136,7 +145,7 @@ async function cmdStart(opts) {
136
145
  if (!ready) {
137
146
  console.error(`❌ Server did not come up on port ${opts.port} within 20s. Last log lines:`);
138
147
  console.error(tailLog());
139
- try { process.kill(child.pid, "SIGKILL"); } catch { /* already dead */ }
148
+ terminateTree(child.pid, "SIGKILL");
140
149
  try { fs.unlinkSync(pidFile); } catch { /* ignore */ }
141
150
  return 1;
142
151
  }
@@ -147,6 +156,23 @@ async function cmdStart(opts) {
147
156
  return 0;
148
157
  }
149
158
 
159
+ function terminateTree(pid, signal) {
160
+ if (process.platform === "win32") {
161
+ // A detached Windows console process can't be sent SIGTERM, so taskkill is the only
162
+ // lever. /T walks the process tree — otherwise the MITM/tunnel children survive us.
163
+ const flags = signal === "SIGKILL" ? "/T /F" : "/T";
164
+ try {
165
+ execSync(`taskkill ${flags} /PID ${pid}`, { stdio: "ignore", windowsHide: true, timeout: 8000 });
166
+ } catch { /* already gone / needs /F */ }
167
+ return;
168
+ }
169
+ // start() spawns detached, so the server is its own process-group leader: signalling
170
+ // -pid tears down its children in one go. Plain pid covers the non-leader case.
171
+ for (const target of [-pid, pid]) {
172
+ try { process.kill(target, signal); } catch { /* not a group leader / already dead */ }
173
+ }
174
+ }
175
+
150
176
  function cmdStop() {
151
177
  const pid = readPid();
152
178
  if (!pid || !isOurServer(pid)) {
@@ -154,14 +180,11 @@ function cmdStop() {
154
180
  console.log("Not running.");
155
181
  return 0;
156
182
  }
157
- // SIGTERM first so the server can tear down its MITM/tunnel children.
158
- try { process.kill(pid, "SIGTERM"); } catch { /* ignore */ }
159
- try { process.kill(-pid, "SIGTERM"); } catch { /* not a group leader (win/exec) */ }
183
+ terminateTree(pid, "SIGTERM");
160
184
  let deadline = Date.now() + 5000;
161
185
  while (Date.now() < deadline && isAlive(pid)) sleepSync(100);
162
186
  if (isAlive(pid)) {
163
- try { process.kill(pid, "SIGKILL"); } catch { /* ignore */ }
164
- try { process.kill(-pid, "SIGKILL"); } catch { /* ignore */ }
187
+ terminateTree(pid, "SIGKILL");
165
188
  deadline = Date.now() + 2000;
166
189
  while (Date.now() < deadline && isAlive(pid)) sleepSync(100);
167
190
  }
@@ -216,4 +239,4 @@ async function runDaemon(verb, argv) {
216
239
  return cmdStatus(opts);
217
240
  }
218
241
 
219
- module.exports = { runDaemon, __test__: { parseOpts, pidFile, logFile, getAppDataDir } };
242
+ module.exports = { runDaemon, __test__: { parseOpts, pidFile, logFile, isOurServer, terminateTree, processCommandLine } };
@@ -318,5 +318,6 @@ function openBrowser(url) {
318
318
 
319
319
  module.exports = {
320
320
  initTray,
321
+ isTraySupported,
321
322
  killTray
322
323
  };
@@ -0,0 +1,42 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const os = require("os");
4
+
5
+ const APP_NAME = "9router";
6
+
7
+ function defaultDir() {
8
+ if (process.platform === "win32") {
9
+ return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), APP_NAME);
10
+ }
11
+ return path.join(os.homedir(), `.${APP_NAME}`);
12
+ }
13
+
14
+ /**
15
+ * Resolve the writable data directory. Mirrors src/lib/dataDir.js (app side) —
16
+ * keep both in sync; the CLI cannot import ESM from the Next app bundle.
17
+ */
18
+ function getDataDir() {
19
+ const configured = process.env.DATA_DIR;
20
+ if (!configured) return defaultDir();
21
+
22
+ // A Unix-style DATA_DIR from a Linux/Docker .env is meaningless on Windows.
23
+ if (process.platform === "win32" && /^\//.test(configured)) {
24
+ console.warn(`[DATA_DIR] '${configured}' is a Unix path on Windows → fallback to default`);
25
+ return defaultDir();
26
+ }
27
+
28
+ try {
29
+ fs.mkdirSync(configured, { recursive: true });
30
+ return configured;
31
+ } catch (e) {
32
+ // Unlike the app-side copy this never throws: the CLI also runs from
33
+ // postinstall, where failing the whole npm install over a bad DATA_DIR
34
+ // would be far worse than falling back.
35
+ console.warn(`[DATA_DIR] '${configured}' unusable (${e?.code || e}) → fallback ~/${APP_NAME}`);
36
+ return defaultDir();
37
+ }
38
+ }
39
+
40
+ const DATA_DIR = getDataDir();
41
+
42
+ module.exports = { APP_NAME, DATA_DIR, getDataDir };