@sifxprime/krouter 0.5.157 → 0.5.159

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 (190) hide show
  1. package/app/.next-cli-build/BUILD_ID +1 -1
  2. package/app/.next-cli-build/app-path-routes-manifest.json +11 -11
  3. package/app/.next-cli-build/build-manifest.json +2 -2
  4. package/app/.next-cli-build/server/app/(dashboard)/dashboard/basic-chat/page_client-reference-manifest.js +1 -1
  5. package/app/.next-cli-build/server/app/(dashboard)/dashboard/cli-tools/[toolId]/page_client-reference-manifest.js +1 -1
  6. package/app/.next-cli-build/server/app/(dashboard)/dashboard/cli-tools/page_client-reference-manifest.js +1 -1
  7. package/app/.next-cli-build/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
  8. package/app/.next-cli-build/server/app/(dashboard)/dashboard/console-log/page_client-reference-manifest.js +1 -1
  9. package/app/.next-cli-build/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
  10. package/app/.next-cli-build/server/app/(dashboard)/dashboard/environment/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/presidio/page_client-reference-manifest.js +1 -1
  18. package/app/.next-cli-build/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
  19. package/app/.next-cli-build/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
  20. package/app/.next-cli-build/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
  21. package/app/.next-cli-build/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
  22. package/app/.next-cli-build/server/app/(dashboard)/dashboard/proxy-pools/page_client-reference-manifest.js +1 -1
  23. package/app/.next-cli-build/server/app/(dashboard)/dashboard/pxpipe/page_client-reference-manifest.js +1 -1
  24. package/app/.next-cli-build/server/app/(dashboard)/dashboard/quota/page_client-reference-manifest.js +1 -1
  25. package/app/.next-cli-build/server/app/(dashboard)/dashboard/skills/page_client-reference-manifest.js +1 -1
  26. package/app/.next-cli-build/server/app/(dashboard)/dashboard/token-saver/page_client-reference-manifest.js +1 -1
  27. package/app/.next-cli-build/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
  28. package/app/.next-cli-build/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
  29. package/app/.next-cli-build/server/app/_global-error/page_client-reference-manifest.js +1 -1
  30. package/app/.next-cli-build/server/app/_global-error.html +1 -1
  31. package/app/.next-cli-build/server/app/_global-error.rsc +1 -1
  32. package/app/.next-cli-build/server/app/_global-error.segments/_full.segment.rsc +1 -1
  33. package/app/.next-cli-build/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  34. package/app/.next-cli-build/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  35. package/app/.next-cli-build/server/app/_not-found/page_client-reference-manifest.js +1 -1
  36. package/app/.next-cli-build/server/app/_not-found.html +1 -1
  37. package/app/.next-cli-build/server/app/_not-found.rsc +3 -3
  38. package/app/.next-cli-build/server/app/_not-found.segments/_full.segment.rsc +3 -3
  39. package/app/.next-cli-build/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +3 -3
  40. package/app/.next-cli-build/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  41. package/app/.next-cli-build/server/app/api/models/route.js +1 -1
  42. package/app/.next-cli-build/server/app/api/providers/route.js +1 -1
  43. package/app/.next-cli-build/server/app/api/translator/console-logs/route.js +1 -1
  44. package/app/.next-cli-build/server/app/api/translator/console-logs/stream/route.js +1 -1
  45. package/app/.next-cli-build/server/app/api/version/route.js +1 -1
  46. package/app/.next-cli-build/server/app/api/version/shutdown/route.js +1 -1
  47. package/app/.next-cli-build/server/app/api/version/update/route.js +1 -1
  48. package/app/.next-cli-build/server/app/callback/page_client-reference-manifest.js +1 -1
  49. package/app/.next-cli-build/server/app/callback.html +1 -1
  50. package/app/.next-cli-build/server/app/callback.rsc +3 -3
  51. package/app/.next-cli-build/server/app/callback.segments/_full.segment.rsc +3 -3
  52. package/app/.next-cli-build/server/app/callback.segments/_tree.segment.rsc +1 -1
  53. package/app/.next-cli-build/server/app/callback.segments/callback/__PAGE__.segment.rsc +3 -3
  54. package/app/.next-cli-build/server/app/dashboard/basic-chat.html +1 -1
  55. package/app/.next-cli-build/server/app/dashboard/basic-chat.rsc +5 -5
  56. package/app/.next-cli-build/server/app/dashboard/basic-chat.segments/!KGRhc2hib2FyZCk/dashboard/basic-chat/__PAGE__.segment.rsc +5 -5
  57. package/app/.next-cli-build/server/app/dashboard/basic-chat.segments/_full.segment.rsc +5 -5
  58. package/app/.next-cli-build/server/app/dashboard/basic-chat.segments/_tree.segment.rsc +1 -1
  59. package/app/.next-cli-build/server/app/dashboard/cli-tools.html +1 -1
  60. package/app/.next-cli-build/server/app/dashboard/cli-tools.rsc +5 -5
  61. package/app/.next-cli-build/server/app/dashboard/cli-tools.segments/!KGRhc2hib2FyZCk/dashboard/cli-tools/__PAGE__.segment.rsc +5 -5
  62. package/app/.next-cli-build/server/app/dashboard/cli-tools.segments/_full.segment.rsc +5 -5
  63. package/app/.next-cli-build/server/app/dashboard/cli-tools.segments/_tree.segment.rsc +1 -1
  64. package/app/.next-cli-build/server/app/dashboard/combos.html +1 -1
  65. package/app/.next-cli-build/server/app/dashboard/combos.rsc +5 -5
  66. package/app/.next-cli-build/server/app/dashboard/combos.segments/!KGRhc2hib2FyZCk/dashboard/combos/__PAGE__.segment.rsc +5 -5
  67. package/app/.next-cli-build/server/app/dashboard/combos.segments/_full.segment.rsc +5 -5
  68. package/app/.next-cli-build/server/app/dashboard/combos.segments/_tree.segment.rsc +1 -1
  69. package/app/.next-cli-build/server/app/dashboard/endpoint.html +1 -1
  70. package/app/.next-cli-build/server/app/dashboard/endpoint.rsc +5 -5
  71. package/app/.next-cli-build/server/app/dashboard/endpoint.segments/!KGRhc2hib2FyZCk/dashboard/endpoint/__PAGE__.segment.rsc +5 -5
  72. package/app/.next-cli-build/server/app/dashboard/endpoint.segments/_full.segment.rsc +5 -5
  73. package/app/.next-cli-build/server/app/dashboard/endpoint.segments/_tree.segment.rsc +1 -1
  74. package/app/.next-cli-build/server/app/dashboard/environment.html +1 -1
  75. package/app/.next-cli-build/server/app/dashboard/environment.rsc +5 -5
  76. package/app/.next-cli-build/server/app/dashboard/environment.segments/!KGRhc2hib2FyZCk/dashboard/environment/__PAGE__.segment.rsc +5 -5
  77. package/app/.next-cli-build/server/app/dashboard/environment.segments/_full.segment.rsc +5 -5
  78. package/app/.next-cli-build/server/app/dashboard/environment.segments/_tree.segment.rsc +1 -1
  79. package/app/.next-cli-build/server/app/dashboard/media-providers/web.html +1 -1
  80. package/app/.next-cli-build/server/app/dashboard/media-providers/web.rsc +5 -5
  81. package/app/.next-cli-build/server/app/dashboard/media-providers/web.segments/!KGRhc2hib2FyZCk/dashboard/media-providers/web/__PAGE__.segment.rsc +5 -5
  82. package/app/.next-cli-build/server/app/dashboard/media-providers/web.segments/_full.segment.rsc +5 -5
  83. package/app/.next-cli-build/server/app/dashboard/media-providers/web.segments/_tree.segment.rsc +1 -1
  84. package/app/.next-cli-build/server/app/dashboard/mitm.html +1 -1
  85. package/app/.next-cli-build/server/app/dashboard/mitm.rsc +5 -5
  86. package/app/.next-cli-build/server/app/dashboard/mitm.segments/!KGRhc2hib2FyZCk/dashboard/mitm/__PAGE__.segment.rsc +5 -5
  87. package/app/.next-cli-build/server/app/dashboard/mitm.segments/_full.segment.rsc +5 -5
  88. package/app/.next-cli-build/server/app/dashboard/mitm.segments/_tree.segment.rsc +1 -1
  89. package/app/.next-cli-build/server/app/dashboard/presidio.html +1 -1
  90. package/app/.next-cli-build/server/app/dashboard/presidio.rsc +4 -4
  91. package/app/.next-cli-build/server/app/dashboard/presidio.segments/!KGRhc2hib2FyZCk/dashboard/presidio/__PAGE__.segment.rsc +4 -4
  92. package/app/.next-cli-build/server/app/dashboard/presidio.segments/_full.segment.rsc +4 -4
  93. package/app/.next-cli-build/server/app/dashboard/presidio.segments/_tree.segment.rsc +1 -1
  94. package/app/.next-cli-build/server/app/dashboard/profile.html +1 -1
  95. package/app/.next-cli-build/server/app/dashboard/profile.rsc +5 -5
  96. package/app/.next-cli-build/server/app/dashboard/profile.segments/!KGRhc2hib2FyZCk/dashboard/profile/__PAGE__.segment.rsc +5 -5
  97. package/app/.next-cli-build/server/app/dashboard/profile.segments/_full.segment.rsc +5 -5
  98. package/app/.next-cli-build/server/app/dashboard/profile.segments/_tree.segment.rsc +1 -1
  99. package/app/.next-cli-build/server/app/dashboard/providers/new.html +1 -1
  100. package/app/.next-cli-build/server/app/dashboard/providers/new.rsc +5 -5
  101. package/app/.next-cli-build/server/app/dashboard/providers/new.segments/!KGRhc2hib2FyZCk/dashboard/providers/new/__PAGE__.segment.rsc +5 -5
  102. package/app/.next-cli-build/server/app/dashboard/providers/new.segments/_full.segment.rsc +5 -5
  103. package/app/.next-cli-build/server/app/dashboard/providers/new.segments/_tree.segment.rsc +1 -1
  104. package/app/.next-cli-build/server/app/dashboard/providers.html +1 -1
  105. package/app/.next-cli-build/server/app/dashboard/providers.rsc +5 -5
  106. package/app/.next-cli-build/server/app/dashboard/providers.segments/!KGRhc2hib2FyZCk/dashboard/providers/__PAGE__.segment.rsc +5 -5
  107. package/app/.next-cli-build/server/app/dashboard/providers.segments/_full.segment.rsc +5 -5
  108. package/app/.next-cli-build/server/app/dashboard/providers.segments/_tree.segment.rsc +1 -1
  109. package/app/.next-cli-build/server/app/dashboard/proxy-pools.html +1 -1
  110. package/app/.next-cli-build/server/app/dashboard/proxy-pools.rsc +5 -5
  111. package/app/.next-cli-build/server/app/dashboard/proxy-pools.segments/!KGRhc2hib2FyZCk/dashboard/proxy-pools/__PAGE__.segment.rsc +5 -5
  112. package/app/.next-cli-build/server/app/dashboard/proxy-pools.segments/_full.segment.rsc +5 -5
  113. package/app/.next-cli-build/server/app/dashboard/proxy-pools.segments/_tree.segment.rsc +1 -1
  114. package/app/.next-cli-build/server/app/dashboard/pxpipe.html +1 -1
  115. package/app/.next-cli-build/server/app/dashboard/pxpipe.rsc +5 -5
  116. package/app/.next-cli-build/server/app/dashboard/pxpipe.segments/!KGRhc2hib2FyZCk/dashboard/pxpipe/__PAGE__.segment.rsc +5 -5
  117. package/app/.next-cli-build/server/app/dashboard/pxpipe.segments/_full.segment.rsc +5 -5
  118. package/app/.next-cli-build/server/app/dashboard/pxpipe.segments/_tree.segment.rsc +1 -1
  119. package/app/.next-cli-build/server/app/dashboard/quota.html +2 -2
  120. package/app/.next-cli-build/server/app/dashboard/quota.rsc +6 -6
  121. package/app/.next-cli-build/server/app/dashboard/quota.segments/!KGRhc2hib2FyZCk/dashboard/quota/__PAGE__.segment.rsc +6 -6
  122. package/app/.next-cli-build/server/app/dashboard/quota.segments/_full.segment.rsc +6 -6
  123. package/app/.next-cli-build/server/app/dashboard/quota.segments/_tree.segment.rsc +1 -1
  124. package/app/.next-cli-build/server/app/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
  125. package/app/.next-cli-build/server/app/dashboard/settings/pricing.html +1 -1
  126. package/app/.next-cli-build/server/app/dashboard/settings/pricing.rsc +3 -3
  127. package/app/.next-cli-build/server/app/dashboard/settings/pricing.segments/_full.segment.rsc +3 -3
  128. package/app/.next-cli-build/server/app/dashboard/settings/pricing.segments/_tree.segment.rsc +1 -1
  129. package/app/.next-cli-build/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing/__PAGE__.segment.rsc +3 -3
  130. package/app/.next-cli-build/server/app/dashboard/skills.html +1 -1
  131. package/app/.next-cli-build/server/app/dashboard/skills.rsc +5 -5
  132. package/app/.next-cli-build/server/app/dashboard/skills.segments/!KGRhc2hib2FyZCk/dashboard/skills/__PAGE__.segment.rsc +5 -5
  133. package/app/.next-cli-build/server/app/dashboard/skills.segments/_full.segment.rsc +5 -5
  134. package/app/.next-cli-build/server/app/dashboard/skills.segments/_tree.segment.rsc +1 -1
  135. package/app/.next-cli-build/server/app/dashboard/token-saver.html +1 -1
  136. package/app/.next-cli-build/server/app/dashboard/token-saver.rsc +5 -5
  137. package/app/.next-cli-build/server/app/dashboard/token-saver.segments/!KGRhc2hib2FyZCk/dashboard/token-saver/__PAGE__.segment.rsc +5 -5
  138. package/app/.next-cli-build/server/app/dashboard/token-saver.segments/_full.segment.rsc +5 -5
  139. package/app/.next-cli-build/server/app/dashboard/token-saver.segments/_tree.segment.rsc +1 -1
  140. package/app/.next-cli-build/server/app/dashboard/translator.html +1 -1
  141. package/app/.next-cli-build/server/app/dashboard/translator.rsc +5 -5
  142. package/app/.next-cli-build/server/app/dashboard/translator.segments/!KGRhc2hib2FyZCk/dashboard/translator/__PAGE__.segment.rsc +5 -5
  143. package/app/.next-cli-build/server/app/dashboard/translator.segments/_full.segment.rsc +5 -5
  144. package/app/.next-cli-build/server/app/dashboard/translator.segments/_tree.segment.rsc +1 -1
  145. package/app/.next-cli-build/server/app/dashboard/usage.html +1 -1
  146. package/app/.next-cli-build/server/app/dashboard/usage.rsc +5 -5
  147. package/app/.next-cli-build/server/app/dashboard/usage.segments/!KGRhc2hib2FyZCk/dashboard/usage/__PAGE__.segment.rsc +5 -5
  148. package/app/.next-cli-build/server/app/dashboard/usage.segments/_full.segment.rsc +5 -5
  149. package/app/.next-cli-build/server/app/dashboard/usage.segments/_tree.segment.rsc +1 -1
  150. package/app/.next-cli-build/server/app/dashboard.html +1 -1
  151. package/app/.next-cli-build/server/app/dashboard.rsc +5 -5
  152. package/app/.next-cli-build/server/app/dashboard.segments/!KGRhc2hib2FyZCk/dashboard/__PAGE__.segment.rsc +5 -5
  153. package/app/.next-cli-build/server/app/dashboard.segments/_full.segment.rsc +5 -5
  154. package/app/.next-cli-build/server/app/dashboard.segments/_tree.segment.rsc +1 -1
  155. package/app/.next-cli-build/server/app/index.html +1 -1
  156. package/app/.next-cli-build/server/app/index.rsc +3 -3
  157. package/app/.next-cli-build/server/app/index.segments/__PAGE__.segment.rsc +3 -3
  158. package/app/.next-cli-build/server/app/index.segments/_full.segment.rsc +3 -3
  159. package/app/.next-cli-build/server/app/index.segments/_tree.segment.rsc +1 -1
  160. package/app/.next-cli-build/server/app/landing/page_client-reference-manifest.js +1 -1
  161. package/app/.next-cli-build/server/app/landing.html +1 -1
  162. package/app/.next-cli-build/server/app/landing.rsc +3 -3
  163. package/app/.next-cli-build/server/app/landing.segments/_full.segment.rsc +3 -3
  164. package/app/.next-cli-build/server/app/landing.segments/_tree.segment.rsc +1 -1
  165. package/app/.next-cli-build/server/app/landing.segments/landing/__PAGE__.segment.rsc +3 -3
  166. package/app/.next-cli-build/server/app/login/page_client-reference-manifest.js +1 -1
  167. package/app/.next-cli-build/server/app/login.html +1 -1
  168. package/app/.next-cli-build/server/app/login.rsc +4 -4
  169. package/app/.next-cli-build/server/app/login.segments/_full.segment.rsc +4 -4
  170. package/app/.next-cli-build/server/app/login.segments/_tree.segment.rsc +1 -1
  171. package/app/.next-cli-build/server/app/login.segments/login/__PAGE__.segment.rsc +4 -4
  172. package/app/.next-cli-build/server/app/page_client-reference-manifest.js +1 -1
  173. package/app/.next-cli-build/server/app-paths-manifest.json +11 -11
  174. package/app/.next-cli-build/server/chunks/2365.js +1 -1
  175. package/app/.next-cli-build/server/chunks/4921.js +1 -1
  176. package/app/.next-cli-build/server/chunks/5718.js +1 -1
  177. package/app/.next-cli-build/server/chunks/706.js +3 -3
  178. package/app/.next-cli-build/server/chunks/8238.js +1 -1
  179. package/app/.next-cli-build/server/middleware-build-manifest.js +1 -1
  180. package/app/.next-cli-build/server/pages/404.html +1 -1
  181. package/app/.next-cli-build/server/pages/500.html +1 -1
  182. package/app/.next-cli-build/static/chunks/{1321-081b63f7d78bf41f.js → 1321-1c2a824823ca3ce1.js} +1 -1
  183. package/app/cli/package.json +1 -1
  184. package/app/package.json +1 -1
  185. package/cli.js +29 -14
  186. package/package.json +1 -1
  187. package/src/cli/api/client.js +4 -9
  188. package/src/lib/dataDir.js +75 -0
  189. /package/app/.next-cli-build/static/{LZeC-BuWxbn-5kt1kNc58 → 5yjzy8V3yYGJ5_YtOmrKY}/_buildManifest.js +0 -0
  190. /package/app/.next-cli-build/static/{LZeC-BuWxbn-5kt1kNc58 → 5yjzy8V3yYGJ5_YtOmrKY}/_ssgManifest.js +0 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sifxprime/krouter",
3
- "version": "0.5.157",
3
+ "version": "0.5.159",
4
4
  "description": "kRouter (Kodelyth Router) CLI — Kodelyth AI Infrastructure",
5
5
  "homepage": "https://github.com/sifxprime/krouter",
6
6
  "repository": {
package/app/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "krouter-app",
3
- "version": "0.5.157",
3
+ "version": "0.5.159",
4
4
  "description": "kRouter (Kodelyth Router) web dashboard — Kodelyth AI Infrastructure",
5
5
  "private": true,
6
6
  "scripts": {
package/cli.js CHANGED
@@ -45,6 +45,7 @@ function createSpinner(text) {
45
45
  const pkg = require("./package.json");
46
46
  const { ensureSqliteRuntime, buildEnvWithRuntime } = require("./hooks/sqliteRuntime");
47
47
  const { ensureTrayRuntime } = require("./hooks/trayRuntime");
48
+ const { getDataDir: getAppDataDir } = require("./src/lib/dataDir");
48
49
  const args = process.argv.slice(2);
49
50
 
50
51
  // Self-heal SQLite runtime deps (sql.js + better-sqlite3) into ~/.krouter/runtime
@@ -202,13 +203,11 @@ function compareVersions(a, b) {
202
203
  return 0;
203
204
  }
204
205
 
205
- // Get app data dir — kept in sync with src/mitm/paths.js
206
- const DATA_DIR_NAME = "krouter";
207
- function getAppDataDir() {
208
- return process.platform === "win32"
209
- ? path.join(process.env.APPDATA || "", DATA_DIR_NAME)
210
- : path.join(os.homedir(), `.${DATA_DIR_NAME}`);
211
- }
206
+ // getAppDataDir comes from ./src/lib/dataDir (required at the top). It used to be
207
+ // a local copy that resolved ~/.krouter unconditionally and ignored DATA_DIR, so
208
+ // the three call sites below -- the tunnel directory, the mitm pidfile, and the
209
+ // db.json write in the crash-loop handler -- all looked in the wrong place
210
+ // whenever DATA_DIR was set. The db.json one failed silently.
212
211
 
213
212
  // Kill PID from file (best-effort, removes file after)
214
213
  function killByPidFile(pidFile) {
@@ -726,6 +725,9 @@ async function showInterfaceMenu(latestVersion) {
726
725
  }
727
726
 
728
727
  const MAX_RESTARTS = 2;
728
+ // Must match MITM_RECOVERY_MARKER in src/shared/services/initializeApp.js.
729
+ // tests/unit/mitm-recovery-marker.test.js pins the two together.
730
+ const MITM_RECOVERY_MARKER = ".mitm-recovery";
729
731
  const RESTART_RESET_MS = 30000; // Reset counter if alive > 30s
730
732
 
731
733
  // First non-internal IPv4 — the address remote peers actually reach when bound to 0.0.0.0.
@@ -1033,14 +1035,27 @@ function startServer(latestVersion) {
1033
1035
 
1034
1036
  if (restartCount >= MAX_RESTARTS) {
1035
1037
  console.error(`\n⚠️ Server crashed ${MAX_RESTARTS} times. Disabling MIT and restarting...`);
1038
+ // Ask the app to disable MITM; do not write the setting here. This used to
1039
+ // patch mitmEnabled in DATA_DIR/db.json, which the app migrated into SQLite
1040
+ // and now keeps only as a rollback artifact -- so the write landed in a file
1041
+ // nothing reads, and this recovery path had quietly done nothing for a long
1042
+ // time. A supervisor has no business knowing how the app stores settings.
1043
+ // MITM_RECOVERY_MARKER must match the constant of the same name in
1044
+ // src/shared/services/initializeApp.js.
1036
1045
  try {
1037
- const dbPath = path.join(getAppDataDir(), "db.json");
1038
- if (fs.existsSync(dbPath)) {
1039
- const db = JSON.parse(fs.readFileSync(dbPath, "utf-8"));
1040
- if (db.settings) db.settings.mitmEnabled = false;
1041
- fs.writeFileSync(dbPath, JSON.stringify(db, null, 2));
1042
- }
1043
- } catch { /* best effort */ }
1046
+ const marker = path.join(getAppDataDir(), MITM_RECOVERY_MARKER);
1047
+ fs.mkdirSync(path.dirname(marker), { recursive: true });
1048
+ fs.writeFileSync(
1049
+ marker,
1050
+ JSON.stringify({ reason: "crash-loop", restarts: MAX_RESTARTS, at: new Date().toISOString() }, null, 2)
1051
+ );
1052
+ } catch (e) {
1053
+ // Not swallowed: if the request cannot be recorded, the restart below is
1054
+ // very likely to crash again for the same reason, and the user should be
1055
+ // told why rather than watching it loop.
1056
+ console.error(` Could not record the MITM recovery request: ${e.message}`);
1057
+ console.error(" If this keeps crashing, disable MITM from the dashboard.");
1058
+ }
1044
1059
  restartCount = 0;
1045
1060
  server = spawnServer();
1046
1061
  attachServerEvents();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sifxprime/krouter",
3
- "version": "0.5.157",
3
+ "version": "0.5.159",
4
4
  "description": "kRouter (Kodelyth Router) CLI — Kodelyth AI Infrastructure",
5
5
  "homepage": "https://github.com/sifxprime/krouter",
6
6
  "repository": {
@@ -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,14 +14,10 @@ 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
- // Kept in sync with src/mitm/paths.js / src/lib/dataDir.js
19
- function getDataDir() {
20
- if (process.env.DATA_DIR) return process.env.DATA_DIR;
21
- if (process.platform === "win32") {
22
- return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "krouter");
23
- }
24
- return path.join(os.homedir(), ".krouter");
25
- }
17
+ // Was a third hand-synced copy of this resolver. It honoured DATA_DIR but
18
+ // without the Windows-path and writability guards the others have, so the same
19
+ // setting could resolve three different ways in one process.
20
+ const { getDataDir } = require("../../lib/dataDir");
26
21
 
27
22
  const MACHINE_ID_FILE = path.join(getDataDir(), "machine-id");
28
23
  const AUTH_DIR = path.join(getDataDir(), "auth");
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Where the CLI keeps its data. One definition for the whole published package.
5
+ *
6
+ * This exists because there were three hand-synced copies of this logic, each
7
+ * carrying a "kept in sync with..." comment, and one of them had drifted:
8
+ * cli.js resolved `~/.krouter` unconditionally and ignored DATA_DIR entirely.
9
+ * That is a documented setting (README: "DATA_DIR | ~/.krouter | Data directory
10
+ * (SQLite, certs, cache)") and ARCHITECTURE.md promises db.json lives at
11
+ * `${DATA_DIR}/db.json`, so anyone who set it -- Docker users, mainly -- got a
12
+ * split brain: auth and machine-id read from DATA_DIR, while db.json, the
13
+ * tunnel directory and the mitm pidfile read from the home directory.
14
+ *
15
+ * The worst of it was silent. cli.js disables MITM in DATA_DIR/db.json to break
16
+ * a crash loop; looking in the wrong place made existsSync false, the
17
+ * best-effort catch swallowed it, and the server kept crash-looping with the
18
+ * safety valve doing nothing.
19
+ *
20
+ * Mirrors the app's own src/lib/dataDir.js. It cannot import it: that module is
21
+ * ESM and lives outside this package's `files`, so the published CLI has no
22
+ * access to it. Keep the two in step.
23
+ */
24
+
25
+ const fs = require("node:fs");
26
+ const path = require("node:path");
27
+ const os = require("node:os");
28
+
29
+ const APP_NAME = "krouter";
30
+
31
+ /** The platform default, used when DATA_DIR is unset or unusable. */
32
+ function appDir() {
33
+ if (process.platform === "win32") {
34
+ // Falling back to "" here would yield a *relative* path, which is how the
35
+ // previous cli.js copy could end up writing into the current directory.
36
+ return path.join(
37
+ process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"),
38
+ APP_NAME
39
+ );
40
+ }
41
+ return path.join(os.homedir(), `.${APP_NAME}`);
42
+ }
43
+
44
+ /**
45
+ * Resolve the data directory, honouring DATA_DIR.
46
+ *
47
+ * Creating the directory is deliberate and matches the app: callers immediately
48
+ * join subpaths onto the result, so a configured-but-absent directory would
49
+ * otherwise fail at the first write rather than here.
50
+ */
51
+ function getDataDir() {
52
+ const configured = process.env.DATA_DIR;
53
+ if (!configured) return appDir();
54
+
55
+ // A Unix path on Windows almost always means a Linux-targeted .env or Docker
56
+ // config leaked into a Windows run. Honouring it would write somewhere the
57
+ // user never intended.
58
+ if (process.platform === "win32" && /^\//.test(configured)) {
59
+ console.warn(`[DATA_DIR] '${configured}' is a Unix path on Windows - falling back to the default`);
60
+ return appDir();
61
+ }
62
+
63
+ try {
64
+ fs.mkdirSync(configured, { recursive: true });
65
+ return configured;
66
+ } catch (e) {
67
+ if (e && (e.code === "EACCES" || e.code === "EPERM")) {
68
+ console.warn(`[DATA_DIR] '${configured}' is not writable - falling back to ~/.${APP_NAME}`);
69
+ return appDir();
70
+ }
71
+ throw e;
72
+ }
73
+ }
74
+
75
+ module.exports = { getDataDir, appDir, APP_NAME };