@@ -5,6 +5,7 @@ import { existsSync, readFileSync } from "node:fs";
55import { join , dirname } from "node:path" ;
66import { fileURLToPath } from "node:url" ;
77import { createServer } from "node:net" ;
8+ import { homedir } from "node:os" ;
89
910// ── Resolve package root ──
1011const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
@@ -15,6 +16,11 @@ const FRONTEND_DIR = join(ROOT, "frontend");
1516const BACKEND_PORT = parseInt ( process . env . PORT || "3001" , 10 ) ;
1617const FRONTEND_PORT = parseInt ( process . env . FRONTEND_PORT || "3000" , 10 ) ;
1718
19+ // ── Data directory ──
20+ // Default to ~/.clawui for global installs (the launcher is only used for
21+ // `claw-ui` CLI invocations, not `npm run dev`).
22+ const CLAWUI_DB_DIR = process . env . CLAWUI_DB_DIR || join ( homedir ( ) , ".clawui" ) ;
23+
1824// ── Pre-flight checks ──
1925function checkBuilds ( ) {
2026 if ( ! existsSync ( join ( BACKEND_DIR , "dist" , "index.js" ) ) ) {
@@ -52,9 +58,8 @@ async function checkPorts() {
5258}
5359
5460// ── Wait for auth token file ──
55- // Backend writes token relative to its own cwd (BACKEND_DIR)
5661function waitForAuthToken ( timeout = 30000 ) {
57- const tokenPath = join ( BACKEND_DIR , ".clawui" , "auth-token" ) ;
62+ const tokenPath = join ( CLAWUI_DB_DIR , "auth-token" ) ;
5863 return new Promise ( ( resolve ) => {
5964 const start = Date . now ( ) ;
6065 const check = ( ) => {
@@ -81,7 +86,7 @@ async function main() {
8186 const backend = spawn ( "node" , [ "dist/index.js" ] , {
8287 cwd : BACKEND_DIR ,
8388 stdio : "inherit" ,
84- env : { ...process . env , PORT : String ( BACKEND_PORT ) } ,
89+ env : { ...process . env , PORT : String ( BACKEND_PORT ) , CLAWUI_DB_DIR } ,
8590 } ) ;
8691
8792 // Start frontend
@@ -102,7 +107,7 @@ async function main() {
102107 console . log ( "" ) ;
103108 } else {
104109 console . error ( "⚠️ Auth token not found after 30s. Check backend logs." ) ;
105- console . error ( ` Expected token at: ${ join ( BACKEND_DIR , ".clawui" , "auth-token" ) } ` ) ;
110+ console . error ( ` Expected token at: ${ join ( CLAWUI_DB_DIR , "auth-token" ) } ` ) ;
106111 }
107112
108113 // Clean shutdown
0 commit comments