Skip to content

Commit 089fd83

Browse files
authored
Merge pull request #12 from ccchow/fix/global-install-deps
fix: add runtime deps to root for global install
2 parents 5bed9b7 + 30c0521 commit 089fd83

File tree

8 files changed

+32
-17
lines changed

8 files changed

+32
-17
lines changed

backend/src/app-state.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
22
import { join } from "node:path";
33
import { CLAWUI_DB_DIR } from "./config.js";
44

5-
const PROJECT_ROOT = join(import.meta.dirname, "..", "..");
6-
const CLAWUI_DIR = join(PROJECT_ROOT, CLAWUI_DB_DIR);
5+
const CLAWUI_DIR = CLAWUI_DB_DIR;
76
const STATE_PATH = join(CLAWUI_DIR, "app-state.json");
87

98
export interface RecentSession {

backend/src/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createLogger } from "./logger.js";
88
const log = createLogger("auth");
99

1010
const DEV_MODE = CLAWUI_DEV;
11-
const tokenDir = join(process.cwd(), CLAWUI_DB_DIR);
11+
const tokenDir = CLAWUI_DB_DIR;
1212
const tokenPath = join(tokenDir, "auth-token");
1313

1414
function resolveToken(): string {

backend/src/config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { execFileSync } from "node:child_process";
22
import { existsSync } from "node:fs";
3-
import { join } from "node:path";
3+
import { join, isAbsolute } from "node:path";
44
import { homedir } from "node:os";
55

66
/**
@@ -73,7 +73,13 @@ export const EXPECT_PATH = resolveExpectPath();
7373

7474
export const PORT = parseInt(process.env.PORT || "3001", 10);
7575

76-
export const CLAWUI_DB_DIR = process.env.CLAWUI_DB_DIR || ".clawui";
76+
/** Raw value — may be relative (e.g. ".clawui") or absolute (e.g. "/Users/x/.clawui"). */
77+
const CLAWUI_DB_DIR_RAW = process.env.CLAWUI_DB_DIR || ".clawui";
78+
79+
/** Resolved absolute path to the data directory. */
80+
export const CLAWUI_DB_DIR = isAbsolute(CLAWUI_DB_DIR_RAW)
81+
? CLAWUI_DB_DIR_RAW
82+
: join(import.meta.dirname, "..", "..", CLAWUI_DB_DIR_RAW);
7783

7884
export const NEXT_PUBLIC_API_PORT = process.env.NEXT_PUBLIC_API_PORT || "3001";
7985

backend/src/db.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { createLogger } from "./logger.js";
1010
const log = createLogger("db");
1111

1212
const CLAUDE_PROJECTS_DIR = join(homedir(), ".claude", "projects");
13-
// Resolve project root (one level up from backend/)
14-
const PROJECT_ROOT = join(import.meta.dirname, "..", "..");
15-
const DB_DIR = join(PROJECT_ROOT, CLAWUI_DB_DIR);
13+
const DB_DIR = CLAWUI_DB_DIR;
1614
const DB_PATH = join(DB_DIR, "index.db");
1715

1816
let db: Database.Database;

backend/src/enrichment.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { CLAWUI_DB_DIR } from "./config.js";
55

66
const log = createLogger("enrichment");
77

8-
const PROJECT_ROOT = join(import.meta.dirname, "..", "..");
9-
const CLAWUI_DIR = join(PROJECT_ROOT, CLAWUI_DB_DIR);
8+
const CLAWUI_DIR = CLAWUI_DB_DIR;
109
const ENRICHMENTS_PATH = join(CLAWUI_DIR, "enrichments.json");
1110

1211
export interface SessionEnrichment {

backend/src/plan-routes.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,8 +1657,7 @@ planRouter.post("/api/blueprints/:id/generate", (req, res) => {
16571657

16581658
// ─── Image upload for node descriptions ──────────────────────
16591659

1660-
const PROJECT_ROOT = join(import.meta.dirname, "..", "..");
1661-
const UPLOADS_DIR = join(PROJECT_ROOT, CLAWUI_DB_DIR, "uploads");
1660+
const UPLOADS_DIR = join(CLAWUI_DB_DIR, "uploads");
16621661

16631662
// Serve uploaded images statically
16641663
planRouter.use("/api/uploads", express.static(UPLOADS_DIR));

bin/claw-ui.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { existsSync, readFileSync } from "node:fs";
55
import { join, dirname } from "node:path";
66
import { fileURLToPath } from "node:url";
77
import { createServer } from "node:net";
8+
import { homedir } from "node:os";
89

910
// ── Resolve package root ──
1011
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -15,6 +16,11 @@ const FRONTEND_DIR = join(ROOT, "frontend");
1516
const BACKEND_PORT = parseInt(process.env.PORT || "3001", 10);
1617
const 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 ──
1925
function 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)
5661
function 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

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.2.2",
6+
"version": "0.2.3",
77
"license": "MIT",
88
"bin": {
99
"claw-ui": "./bin/claw-ui.mjs"
@@ -43,6 +43,15 @@
4343
"start:backend": "npm run start --workspace=backend",
4444
"lint": "npm run lint --workspace=backend"
4545
},
46+
"dependencies": {
47+
"better-sqlite3": "^12.6.2",
48+
"cors": "^2.8.5",
49+
"express": "^4.21.0",
50+
"glob": "^11.0.0",
51+
"next": "^14.2.0",
52+
"react": "^18.3.0",
53+
"react-dom": "^18.3.0"
54+
},
4655
"devDependencies": {
4756
"concurrently": "^9.1.0",
4857
"eslint": "^10.0.1",

0 commit comments

Comments
 (0)