kentutai-app 1.1.0 → 1.1.2

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/cli/cli.js +34 -60
  2. package/package.json +1 -1
package/cli/cli.js CHANGED
@@ -7,7 +7,6 @@ const os = require("os");
7
7
 
8
8
  const pkg = require("./package.json");
9
9
 
10
- // ─── Configuration ────────────────────────────────────────────────────
11
10
  const DEFAULT_PORT = 20123;
12
11
  const DEFAULT_HOST = "0.0.0.0";
13
12
 
@@ -17,7 +16,6 @@ let noBrowser = false;
17
16
  let showLog = false;
18
17
  let trayMode = false;
19
18
 
20
- // Parse arguments
21
19
  const args = process.argv.slice(2);
22
20
  for (let i = 0; i < args.length; i++) {
23
21
  if (args[i] === "--port" || args[i] === "-p") {
@@ -52,17 +50,18 @@ Options:
52
50
  }
53
51
  }
54
52
 
55
- // ─── Standalone server path ───────────────────────────────────────────
56
- const standaloneDir = path.join(__dirname, "app");
57
- const serverPath = path.join(standaloneDir, "server.js");
53
+ const appDir = path.join(__dirname, "app");
54
+ const standaloneServer = path.join(appDir, "server.js");
55
+ const mainAppDir = path.resolve(__dirname, "..");
56
+ const mainServerPath = path.join(mainAppDir, ".next", "standalone", "server.js");
58
57
 
59
- if (!fs.existsSync(serverPath)) {
60
- console.error("Error: Standalone build not found at cli/app/server.js");
61
- console.error("Run 'npm run build:cli' first.");
62
- process.exit(1);
63
- }
58
+ const useStandalone = fs.existsSync(standaloneServer);
59
+ const useMainApp = !useStandalone && fs.existsSync(mainServerPath);
64
60
 
65
- // ─── Helpers ──────────────────────────────────────────────────────────
61
+ if (!useStandalone && !useMainApp) {
62
+ console.log("\n First run detected. Starting development server...\n");
63
+ console.log(" For production, run: npm run build\n");
64
+ }
66
65
 
67
66
  function openBrowser(url) {
68
67
  const cmd = process.platform === "darwin" ? "open"
@@ -94,17 +93,34 @@ function killProcessOnPort(port) {
94
93
  });
95
94
  }
96
95
 
97
- // ─── Start Server ─────────────────────────────────────────────────────
98
-
99
96
  function startServer() {
100
97
  const displayHost = host === DEFAULT_HOST ? "localhost" : host;
101
98
  const url = `http://${displayHost}:${port}/dashboard`;
102
99
 
103
- const server = spawn(process.execPath, ["--max-old-space-size=4096", serverPath], {
104
- cwd: standaloneDir,
105
- stdio: showLog ? "inherit" : "ignore",
106
- env: { ...process.env, PORT: String(port), HOSTNAME: host }
107
- });
100
+ let server;
101
+
102
+ if (useStandalone) {
103
+ server = spawn(process.execPath, ["--max-old-space-size=4096", standaloneServer], {
104
+ cwd: appDir,
105
+ stdio: showLog ? "inherit" : "ignore",
106
+ env: { ...process.env, PORT: String(port), HOSTNAME: host }
107
+ });
108
+ } else if (useMainApp) {
109
+ server = spawn(process.execPath, ["--max-old-space-size=4096", mainServerPath], {
110
+ cwd: path.join(mainAppDir, ".next", "standalone"),
111
+ stdio: showLog ? "inherit" : "ignore",
112
+ env: { ...process.env, PORT: String(port), HOSTNAME: host }
113
+ });
114
+ } else {
115
+ const isWin = process.platform === "win32";
116
+ const npmCmd = isWin ? "npm.cmd" : "npm";
117
+ server = spawn(npmCmd, ["run", "dev", "--", "--port", String(port)], {
118
+ cwd: mainAppDir,
119
+ stdio: showLog ? "inherit" : "ignore",
120
+ shell: isWin,
121
+ env: { ...process.env, PORT: String(port) }
122
+ });
123
+ }
108
124
 
109
125
  server.on("error", (err) => {
110
126
  console.error("Failed to start server:", err.message);
@@ -118,7 +134,6 @@ function startServer() {
118
134
  process.exit(code || 0);
119
135
  });
120
136
 
121
- // Cleanup on exit
122
137
  const cleanup = () => {
123
138
  try { server.kill(); } catch {}
124
139
  };
@@ -149,14 +164,11 @@ async function checkForUpdate() {
149
164
  } catch { return null; }
150
165
  }
151
166
 
152
- // ─── Main ─────────────────────────────────────────────────────────────
153
-
154
167
  async function main() {
155
168
  await killProcessOnPort(port);
156
169
 
157
170
  const { server, url } = startServer();
158
171
 
159
- // Tray mode: no interactive menu
160
172
  if (trayMode) {
161
173
  console.log(`\n ${pkg.name} v${pkg.version}`);
162
174
  console.log(` Server: ${url}`);
@@ -164,14 +176,11 @@ async function main() {
164
176
  return;
165
177
  }
166
178
 
167
- // Wait for server to be ready
168
179
  const { selectMenu, pause } = require("./src/cli/utils/input");
169
180
  const { clearScreen } = require("./src/cli/utils/display");
170
181
 
171
- // Wait a bit for server startup
172
182
  await new Promise(r => setTimeout(r, 3000));
173
183
 
174
- // If --no-browser, just show info and wait
175
184
  if (noBrowser) {
176
185
  console.log(`\n ${pkg.name} v${pkg.version}`);
177
186
  console.log(` Server: ${url}`);
@@ -208,12 +217,10 @@ async function main() {
208
217
  `\ud83d\ude80 Server: ${serverUrl}`
209
218
  );
210
219
 
211
- // Handle choice
212
220
  const adjustedChoice = latestVersion ? choice : choice + 1;
213
221
 
214
222
  if (adjustedChoice === 0 && latestVersion) {
215
223
  console.log("\n Updating...");
216
- const { execSync } = require("child_process");
217
224
  try {
218
225
  execSync(`npm install -g ${pkg.name}`, { stdio: "inherit" });
219
226
  console.log("\n Update complete! Please restart the application.");
@@ -251,39 +258,6 @@ async function main() {
251
258
  }
252
259
  }
253
260
  }
254
- } else if (adjustedChoice === 1 || (adjustedChoice === 0 && !latestVersion)) {
255
- // Web UI
256
- openBrowser(url);
257
- await pause("\nPress Enter to go back to menu...");
258
- } else if (adjustedChoice === 2) {
259
- // Terminal UI
260
- try {
261
- const { startTerminalUI } = require("./src/cli/terminalUI");
262
- await startTerminalUI(port);
263
- } catch (err) {
264
- console.error("\n Terminal UI error:", err.message);
265
- await pause("\nPress Enter to continue...");
266
- }
267
- } else if (adjustedChoice === 3) {
268
- // Hide to Tray
269
- clearScreen();
270
- console.log(`\n \ud83d\udd14 ${pkg.name} is running in background`);
271
- console.log(` Server: ${serverUrl}`);
272
- console.log(` PID: ${server.pid}`);
273
- console.log(`\n Press Ctrl+C to stop.\n`);
274
- // Keep process alive, remove stdin listeners
275
- process.stdin.removeAllListeners("keypress");
276
- if (process.stdin.isTTY) try { process.stdin.setRawMode(false); } catch {}
277
- return;
278
- } else {
279
- // Exit
280
- console.log("\nExiting...");
281
- server.kill();
282
- setTimeout(() => process.exit(0), 100);
283
- return;
284
- }
285
- }
286
- }
287
261
 
288
262
  main().catch((err) => {
289
263
  console.error("Fatal:", err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kentutai-app",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "KentutAI web dashboard",
5
5
  "private": false,
6
6
  "bin": {