amai 0.0.9 → 0.0.10

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.
package/dist/cli.cjs CHANGED
@@ -1254,30 +1254,19 @@ async function pollForTokens({
1254
1254
  async function login() {
1255
1255
  try {
1256
1256
  const device = await authorizeDevice();
1257
- console.log(pc5__default.default.bold("To sign in, follow these steps:"));
1257
+ console.log("");
1258
1258
  if (device.verification_uri_complete) {
1259
- console.log(
1260
- ` 1. Open this URL in your browser: ${pc5__default.default.cyan(
1261
- device.verification_uri_complete
1262
- )}`
1263
- );
1259
+ console.log(pc5__default.default.cyan(`open: ${device.verification_uri_complete}`));
1264
1260
  } else {
1265
- console.log(
1266
- ` 1. Open this URL in your browser: ${pc5__default.default.cyan(
1267
- device.verification_uri
1268
- )}`
1269
- );
1270
- console.log(
1271
- ` 2. Enter this code when prompted: ${pc5__default.default.bold(device.user_code)}`
1272
- );
1261
+ console.log(pc5__default.default.cyan(`open: ${device.verification_uri}`));
1262
+ console.log(pc5__default.default.gray(`code: ${device.user_code}`));
1273
1263
  }
1274
- console.log(" 3. Come back here; we will detect when you finish logging in.");
1275
- console.log();
1264
+ console.log("");
1276
1265
  console.log(
1277
1266
  pc5__default.default.gray(
1278
- `Waiting for authorization (expires in ~${Math.round(
1267
+ `waiting for authorization (~${Math.round(
1279
1268
  device.expires_in / 60
1280
- )} minutes)...`
1269
+ )} min)...`
1281
1270
  )
1282
1271
  );
1283
1272
  const tokens = await pollForTokens({
@@ -1286,11 +1275,11 @@ async function login() {
1286
1275
  expiresIn: device.expires_in,
1287
1276
  interval: device.interval
1288
1277
  });
1289
- console.log(pc5__default.default.green("Successfully authenticated!"));
1278
+ console.log(pc5__default.default.cyan("authenticated"));
1290
1279
  saveTokens(tokens);
1291
1280
  return tokens;
1292
1281
  } catch (error) {
1293
- console.error(pc5__default.default.red(error.message || "Login failed"));
1282
+ console.error(pc5__default.default.red(error.message || "login failed"));
1294
1283
  throw error;
1295
1284
  }
1296
1285
  }
@@ -1984,7 +1973,19 @@ var rpcHandlers = {
1984
1973
  return { success: true, diff };
1985
1974
  }
1986
1975
  };
1976
+ var INITIAL_RECONNECT_DELAY = 1e3;
1977
+ var MAX_RECONNECT_DELAY = 6e4;
1978
+ var BACKOFF_MULTIPLIER = 2;
1987
1979
  var reconnectTimeout = null;
1980
+ var reconnectAttempts = 0;
1981
+ function getReconnectDelay() {
1982
+ const delay = Math.min(
1983
+ INITIAL_RECONNECT_DELAY * Math.pow(BACKOFF_MULTIPLIER, reconnectAttempts),
1984
+ MAX_RECONNECT_DELAY
1985
+ );
1986
+ const jitter = delay * 0.25 * (Math.random() * 2 - 1);
1987
+ return Math.floor(delay + jitter);
1988
+ }
1988
1989
  var connectToUserStreams = async (serverUrl) => {
1989
1990
  const userId = getUserId();
1990
1991
  if (!userId?.userId) {
@@ -2005,7 +2006,8 @@ var connectToUserStreams = async (serverUrl) => {
2005
2006
  }
2006
2007
  });
2007
2008
  ws.on("open", () => {
2008
- console.log(pc5__default.default.green("CLI connected to user-streams"));
2009
+ reconnectAttempts = 0;
2010
+ console.log(pc5__default.default.cyan("connected to user streams"));
2009
2011
  if (reconnectTimeout) {
2010
2012
  clearTimeout(reconnectTimeout);
2011
2013
  reconnectTimeout = null;
@@ -2016,7 +2018,7 @@ var connectToUserStreams = async (serverUrl) => {
2016
2018
  const message = JSON.parse(event.toString());
2017
2019
  if (message._tag === "rpc_call") {
2018
2020
  const { requestId, method, input } = message;
2019
- console.log(pc5__default.default.gray(`RPC call: ${method}`));
2021
+ console.log(pc5__default.default.gray(`> ${method}`));
2020
2022
  const handler = rpcHandlers[method];
2021
2023
  if (!handler) {
2022
2024
  ws.send(JSON.stringify({
@@ -2027,7 +2029,6 @@ var connectToUserStreams = async (serverUrl) => {
2027
2029
  message: `Unknown RPC method: ${method}`
2028
2030
  }
2029
2031
  }));
2030
- console.log(pc5__default.default.yellow(`Unknown RPC method: ${method}`));
2031
2032
  return;
2032
2033
  }
2033
2034
  try {
@@ -2037,7 +2038,6 @@ var connectToUserStreams = async (serverUrl) => {
2037
2038
  requestId,
2038
2039
  data: result
2039
2040
  }));
2040
- console.log(pc5__default.default.green(`RPC completed: ${method}`));
2041
2041
  } catch (error) {
2042
2042
  const rpcError = error._tag ? error : {
2043
2043
  _tag: "RpcError",
@@ -2048,7 +2048,7 @@ var connectToUserStreams = async (serverUrl) => {
2048
2048
  requestId,
2049
2049
  data: rpcError
2050
2050
  }));
2051
- console.log(pc5__default.default.red(`RPC failed: ${method} - ${rpcError.message}`));
2051
+ console.log(pc5__default.default.red(` ${method} failed`));
2052
2052
  }
2053
2053
  return;
2054
2054
  }
@@ -2067,25 +2067,38 @@ var connectToUserStreams = async (serverUrl) => {
2067
2067
  }
2068
2068
  }
2069
2069
  } catch (parseError) {
2070
- console.error(pc5__default.default.red(`Failed to parse message: ${parseError}`));
2070
+ console.error(pc5__default.default.red(`parse error`));
2071
2071
  }
2072
2072
  });
2073
2073
  ws.on("close", (code, reason) => {
2074
- console.log(pc5__default.default.yellow(`CLI disconnected from user-streams (code: ${code})`));
2075
- console.log(pc5__default.default.gray("Reconnecting in 5 seconds..."));
2074
+ const delay = getReconnectDelay();
2075
+ reconnectAttempts++;
2076
+ console.log(pc5__default.default.gray(`user streams disconnected, reconnecting in ${Math.round(delay / 1e3)}s...`));
2076
2077
  reconnectTimeout = setTimeout(() => {
2077
2078
  connectToUserStreams(serverUrl).catch((err) => {
2078
- console.error(pc5__default.default.red(`Reconnection failed: ${err.message}`));
2079
+ console.error(pc5__default.default.red(`reconnection failed`));
2079
2080
  });
2080
- }, 5e3);
2081
+ }, delay);
2081
2082
  });
2082
2083
  ws.on("error", (error) => {
2083
- console.error(pc5__default.default.red(`User streams WebSocket error: ${error.message}`));
2084
+ console.error(pc5__default.default.red(`stream error: ${error.message}`));
2084
2085
  });
2085
2086
  return ws;
2086
2087
  };
2087
2088
 
2088
2089
  // src/server.ts
2090
+ var INITIAL_RECONNECT_DELAY2 = 1e3;
2091
+ var MAX_RECONNECT_DELAY2 = 6e4;
2092
+ var BACKOFF_MULTIPLIER2 = 2;
2093
+ var reconnectAttempts2 = 0;
2094
+ function getReconnectDelay2() {
2095
+ const delay = Math.min(
2096
+ INITIAL_RECONNECT_DELAY2 * Math.pow(BACKOFF_MULTIPLIER2, reconnectAttempts2),
2097
+ MAX_RECONNECT_DELAY2
2098
+ );
2099
+ const jitter = delay * 0.25 * (Math.random() * 2 - 1);
2100
+ return Math.floor(delay + jitter);
2101
+ }
2089
2102
  var toolExecutors = {
2090
2103
  editFile: editFiles,
2091
2104
  deleteFile,
@@ -2108,12 +2121,13 @@ function connectToServer(serverUrl = DEFAULT_SERVER_URL) {
2108
2121
  }
2109
2122
  });
2110
2123
  ws.on("open", () => {
2111
- console.log(pc5__default.default.green("Connected to server agent streams"));
2124
+ reconnectAttempts2 = 0;
2125
+ console.log(pc5__default.default.cyan("connected to server"));
2112
2126
  });
2113
2127
  ws.on("message", async (data) => {
2114
2128
  const message = JSON.parse(data.toString());
2115
2129
  if (message.type === "tool_call") {
2116
- console.log(`tool call: ${message.tool}${message.projectCwd ? ` (project: ${message.projectCwd})` : ""}`);
2130
+ console.log(pc5__default.default.gray(`> ${message.tool}`));
2117
2131
  try {
2118
2132
  const executor = toolExecutors[message.tool];
2119
2133
  if (!executor) {
@@ -2125,17 +2139,16 @@ function connectToServer(serverUrl = DEFAULT_SERVER_URL) {
2125
2139
  id: message.id,
2126
2140
  result
2127
2141
  }));
2128
- console.log(pc5__default.default.green(`tool call completed: ${message.tool}`));
2129
2142
  } catch (error) {
2130
2143
  ws.send(JSON.stringify({
2131
2144
  type: "tool_result",
2132
2145
  id: message.id,
2133
2146
  error: error.message
2134
2147
  }));
2135
- console.error(pc5__default.default.red(`tool call failed: ${message.tool} ${error.message}`));
2148
+ console.error(pc5__default.default.red(` ${message.tool} failed: ${error.message}`));
2136
2149
  }
2137
2150
  } else if (message.type === "rpc_call") {
2138
- console.log(`rpc call: ${message.method}`);
2151
+ console.log(pc5__default.default.gray(`> rpc: ${message.method}`));
2139
2152
  try {
2140
2153
  const handler = rpcHandlers[message.method];
2141
2154
  if (!handler) {
@@ -2147,29 +2160,30 @@ function connectToServer(serverUrl = DEFAULT_SERVER_URL) {
2147
2160
  id: message.id,
2148
2161
  result
2149
2162
  }));
2150
- console.log(pc5__default.default.green(`rpc call completed: ${message.method}`));
2151
2163
  } catch (error) {
2152
2164
  ws.send(JSON.stringify({
2153
2165
  type: "tool_result",
2154
2166
  id: message.id,
2155
2167
  error: error.message
2156
2168
  }));
2157
- console.error(pc5__default.default.red(`rpc call failed: ${message.method} ${error.message}`));
2169
+ console.error(pc5__default.default.red(` rpc failed: ${message.method}`));
2158
2170
  }
2159
2171
  }
2160
2172
  });
2161
2173
  ws.on("close", () => {
2162
- console.log(pc5__default.default.red("disconnected from server. reconnecting in 5s..."));
2163
- setTimeout(() => connectToServer(serverUrl), 5e3);
2174
+ const delay = getReconnectDelay2();
2175
+ reconnectAttempts2++;
2176
+ console.log(pc5__default.default.gray(`disconnected, reconnecting in ${Math.round(delay / 1e3)}s...`));
2177
+ setTimeout(() => connectToServer(serverUrl), delay);
2164
2178
  });
2165
2179
  ws.on("error", (error) => {
2166
- console.error(pc5__default.default.red(`web socket error: ${error.message}`));
2180
+ console.error(pc5__default.default.red(`connection error: ${error.message}`));
2167
2181
  });
2168
2182
  return ws;
2169
2183
  }
2170
2184
  async function main() {
2171
2185
  const serverUrl = DEFAULT_SERVER_URL;
2172
- console.log(pc5__default.default.green("starting local amai..."));
2186
+ console.log(pc5__default.default.gray("starting ama..."));
2173
2187
  connectToServer(serverUrl);
2174
2188
  await connectToUserStreams(serverUrl);
2175
2189
  startHttpServer();
@@ -2411,8 +2425,14 @@ function getDaemonPid() {
2411
2425
  return null;
2412
2426
  }
2413
2427
  }
2414
- var VERSION = "0.0.9";
2428
+ var VERSION = "0.0.10";
2415
2429
  var PROJECT_DIR = process.cwd();
2430
+ var LOGO = `
2431
+ __ _ _ __ ___ __ _
2432
+ / _\` | '_ \` _ \\ / _\` |
2433
+ | (_| | | | | | | (_| |
2434
+ \\__,_|_| |_| |_|\\__,_|
2435
+ `;
2416
2436
  function promptUser(question) {
2417
2437
  const rl = readline__default.default.createInterface({
2418
2438
  input: process.stdin,
@@ -2427,168 +2447,249 @@ function promptUser(question) {
2427
2447
  }
2428
2448
  async function startWithCodeServer() {
2429
2449
  if (!isCodeServerInstalled()) {
2430
- console.log(pc5__default.default.cyan("First run detected. Setting up code-server..."));
2450
+ console.log(pc5__default.default.gray("setting up code-server..."));
2431
2451
  try {
2432
2452
  await installCodeServer();
2433
2453
  } catch (error) {
2434
- console.error(pc5__default.default.red(`Failed to install code-server: ${error.message}`));
2435
- console.log(pc5__default.default.yellow("Continuing without code-server..."));
2454
+ console.error(pc5__default.default.red(`failed to install code-server: ${error.message}`));
2455
+ console.log(pc5__default.default.gray("continuing without code-server..."));
2436
2456
  }
2437
2457
  }
2438
2458
  if (isCodeServerInstalled()) {
2439
2459
  try {
2440
2460
  await startCodeServer(PROJECT_DIR);
2441
2461
  } catch (error) {
2442
- console.error(pc5__default.default.red(`Failed to start code-server: ${error.message}`));
2462
+ console.error(pc5__default.default.red(`failed to start code-server: ${error.message}`));
2443
2463
  }
2444
2464
  }
2445
2465
  main();
2446
2466
  }
2467
+ async function checkForUpdates() {
2468
+ try {
2469
+ const response = await fetch("https://registry.npmjs.org/amai/latest");
2470
+ const data = await response.json();
2471
+ const latestVersion = data.version;
2472
+ return {
2473
+ current: VERSION,
2474
+ latest: latestVersion,
2475
+ hasUpdate: latestVersion !== VERSION
2476
+ };
2477
+ } catch {
2478
+ return { current: VERSION, latest: VERSION, hasUpdate: false };
2479
+ }
2480
+ }
2481
+ function runNpmInstall() {
2482
+ return new Promise((resolve, reject) => {
2483
+ const child = child_process.spawn("npm", ["install", "-g", "amai@latest"], {
2484
+ stdio: "inherit",
2485
+ shell: true
2486
+ });
2487
+ child.on("close", (code) => {
2488
+ if (code === 0) resolve();
2489
+ else reject(new Error(`npm install exited with code ${code}`));
2490
+ });
2491
+ child.on("error", reject);
2492
+ });
2493
+ }
2447
2494
  var args = process.argv.slice(2);
2495
+ if (args[0] === "--version" || args[0] === "-v") {
2496
+ console.log(pc5__default.default.gray(`amai ${VERSION}`));
2497
+ process.exit(0);
2498
+ }
2448
2499
  if (args[0] === "--help" || args[0] === "-h") {
2449
- console.log(`
2450
- ${pc5__default.default.bold("amai cli")} ${pc5__default.default.gray(VERSION)}
2451
-
2452
- Usage: amai [command] [options]
2453
-
2454
- Commands:
2455
- login Authorize device
2456
- logout Log out and remove credentials
2457
- start Start background daemon (background mode is highly recommended for better performance and stability)
2458
- stop Stop background daemon
2459
- status Check daemon status
2460
- project add <path> Register a project directory
2461
- project list List registered projects
2462
- Options:
2463
- --help, -h Show this help message
2464
- --logout, -l Log out and remove credentials
2465
- Environment Variables:
2466
- SERVER_URL Server URL to connect to
2467
-
2468
- Example:
2469
- amai login
2470
- amai start
2471
- amai project add /path/to/project
2472
- amai Start the agent (will prompt for background mode)
2473
- `);
2500
+ console.log(pc5__default.default.cyan(LOGO));
2501
+ console.log(pc5__default.default.gray(` v${VERSION}`));
2502
+ console.log("");
2503
+ console.log(pc5__default.default.cyan(" usage"));
2504
+ console.log(pc5__default.default.gray(" amai [command]"));
2505
+ console.log("");
2506
+ console.log(pc5__default.default.cyan(" commands"));
2507
+ console.log(pc5__default.default.gray(" login authenticate with amai"));
2508
+ console.log(pc5__default.default.gray(" logout remove credentials"));
2509
+ console.log(pc5__default.default.gray(" start start background daemon"));
2510
+ console.log(pc5__default.default.gray(" stop stop background daemon"));
2511
+ console.log(pc5__default.default.gray(" status check daemon status"));
2512
+ console.log(pc5__default.default.gray(" update update to latest version"));
2513
+ console.log(pc5__default.default.gray(" project add register a project"));
2514
+ console.log(pc5__default.default.gray(" project list list projects"));
2515
+ console.log("");
2516
+ console.log(pc5__default.default.cyan(" options"));
2517
+ console.log(pc5__default.default.gray(" -h, --help show help"));
2518
+ console.log(pc5__default.default.gray(" -v, --version show version"));
2519
+ console.log("");
2474
2520
  process.exit(0);
2475
2521
  }
2476
- if (args[0] === "start") {
2477
- if (isDaemonRunning()) {
2478
- console.log(pc5__default.default.yellow("ama is already running"));
2522
+ if (args[0] === "update") {
2523
+ (async () => {
2524
+ console.log(pc5__default.default.gray("checking for updates..."));
2525
+ const { current, latest, hasUpdate } = await checkForUpdates();
2526
+ if (!hasUpdate) {
2527
+ console.log(pc5__default.default.cyan(`already on latest version (${current})`));
2528
+ process.exit(0);
2529
+ }
2530
+ console.log(pc5__default.default.cyan(`update available: ${current} -> ${latest}`));
2531
+ const answer = await promptUser(pc5__default.default.gray("install update? (Y/n): "));
2532
+ if (answer === "" || answer.toLowerCase() === "y" || answer.toLowerCase() === "yes") {
2533
+ console.log(pc5__default.default.gray("updating..."));
2534
+ try {
2535
+ await runNpmInstall();
2536
+ console.log(pc5__default.default.cyan(`updated to ${latest}`));
2537
+ } catch (error) {
2538
+ console.error(pc5__default.default.red(`update failed: ${error.message}`));
2539
+ process.exit(1);
2540
+ }
2541
+ }
2479
2542
  process.exit(0);
2480
- }
2481
- if (!isAuthenticated()) {
2482
- console.log(pc5__default.default.yellow("Not authenticated. Please log in first."));
2483
- login().then(() => {
2484
- console.log(pc5__default.default.green("starting ama in background mode..."));
2485
- startDaemon();
2486
- console.log(pc5__default.default.green("ama started in background mode successfully"));
2543
+ })();
2544
+ } else if (args[0] === "start") {
2545
+ (async () => {
2546
+ if (isDaemonRunning()) {
2547
+ console.log(pc5__default.default.gray("amai is already running"));
2487
2548
  process.exit(0);
2488
- }).catch(() => {
2489
- console.error(pc5__default.default.red("Login failed. Cannot start ama in background mode."));
2490
- process.exit(1);
2491
- });
2492
- } else {
2549
+ }
2550
+ if (!isAuthenticated()) {
2551
+ console.log(pc5__default.default.gray("not authenticated"));
2552
+ try {
2553
+ await login();
2554
+ } catch {
2555
+ console.error(pc5__default.default.red("login failed"));
2556
+ process.exit(1);
2557
+ }
2558
+ }
2493
2559
  startDaemon();
2494
- console.log(pc5__default.default.green(pc5__default.default.bold("amai started in background mode")));
2495
- console.log(pc5__default.default.gray(`Tip: You can check status any time with ${pc5__default.default.bold("amai status")}`));
2560
+ console.log(pc5__default.default.cyan("amai started"));
2561
+ console.log(pc5__default.default.gray(`check status: amai status`));
2496
2562
  process.exit(0);
2497
- }
2498
- }
2499
- if (args[0] === "stop") {
2563
+ })();
2564
+ } else if (args[0] === "stop") {
2500
2565
  if (stopDaemon()) {
2501
- console.log(pc5__default.default.green("Daemon stopped successfully"));
2566
+ console.log(pc5__default.default.cyan("daemon stopped"));
2502
2567
  } else {
2503
- console.log(pc5__default.default.yellow("Daemon was not running"));
2568
+ console.log(pc5__default.default.gray("daemon was not running"));
2504
2569
  }
2505
2570
  process.exit(0);
2506
- }
2507
- if (args[0] === "status") {
2571
+ } else if (args[0] === "status") {
2508
2572
  const running = isDaemonRunning();
2509
2573
  const pid = getDaemonPid();
2574
+ console.log("");
2575
+ console.log(pc5__default.default.cyan(" amai status"));
2576
+ console.log("");
2510
2577
  if (running && pid) {
2511
- console.log(pc5__default.default.green(`Daemon is running (PID: ${pid})`));
2578
+ console.log(pc5__default.default.gray(` status running`));
2579
+ console.log(pc5__default.default.gray(` pid ${pid}`));
2512
2580
  } else {
2513
- console.log(pc5__default.default.yellow("Daemon is not running"));
2581
+ console.log(pc5__default.default.gray(` status stopped`));
2514
2582
  }
2583
+ console.log(pc5__default.default.gray(` version ${VERSION}`));
2584
+ console.log("");
2515
2585
  process.exit(0);
2516
- }
2517
- if (args[0] === "project") {
2586
+ } else if (args[0] === "project") {
2518
2587
  if (args[1] === "add") {
2519
2588
  const projectPath = args[2];
2520
2589
  if (!projectPath) {
2521
- console.error(pc5__default.default.red("Please provide a project path"));
2522
- console.log("Usage: amai project add <path>");
2590
+ console.error(pc5__default.default.red("please provide a project path"));
2591
+ console.log(pc5__default.default.gray("usage: amai project add <path>"));
2523
2592
  process.exit(1);
2524
2593
  }
2525
2594
  const resolvedPath = path10__default.default.resolve(projectPath);
2526
2595
  if (!fs6__default.default.existsSync(resolvedPath)) {
2527
- console.error(pc5__default.default.red(`Path does not exist: ${resolvedPath}`));
2596
+ console.error(pc5__default.default.red(`path does not exist: ${resolvedPath}`));
2528
2597
  process.exit(1);
2529
2598
  }
2530
2599
  if (!fs6__default.default.statSync(resolvedPath).isDirectory()) {
2531
- console.error(pc5__default.default.red(`Path is not a directory: ${resolvedPath}`));
2600
+ console.error(pc5__default.default.red(`path is not a directory: ${resolvedPath}`));
2532
2601
  process.exit(1);
2533
2602
  }
2534
2603
  const projectId = path10__default.default.basename(resolvedPath);
2535
2604
  projectRegistry.register(projectId, resolvedPath);
2536
- console.log(pc5__default.default.green(`Project registered: ${projectId} -> ${resolvedPath}`));
2605
+ console.log(pc5__default.default.cyan(`project registered: ${projectId}`));
2606
+ console.log(pc5__default.default.gray(` ${resolvedPath}`));
2537
2607
  process.exit(0);
2538
2608
  } else if (args[1] === "list") {
2539
2609
  const projects = projectRegistry.list();
2610
+ console.log("");
2611
+ console.log(pc5__default.default.cyan(" projects"));
2612
+ console.log("");
2540
2613
  if (projects.length === 0) {
2541
- console.log(pc5__default.default.yellow("No projects registered"));
2614
+ console.log(pc5__default.default.gray(" no projects registered"));
2542
2615
  } else {
2543
- console.log(pc5__default.default.bold("Registered projects:"));
2544
2616
  projects.forEach((project) => {
2545
- console.log(` ${pc5__default.default.cyan(project.id)}: ${project.cwd} ${project.active ? pc5__default.default.green("(active)") : ""}`);
2617
+ const status = project.active ? pc5__default.default.cyan("active") : pc5__default.default.gray("inactive");
2618
+ console.log(pc5__default.default.gray(` ${project.id} [${status}]`));
2619
+ console.log(pc5__default.default.gray(` ${project.cwd}`));
2546
2620
  });
2547
2621
  }
2622
+ console.log("");
2548
2623
  process.exit(0);
2549
2624
  } else {
2550
- console.error(pc5__default.default.red(`Unknown project command: ${args[1]}`));
2551
- console.log('Use "amai project add <path>" or "amai project list"');
2625
+ console.error(pc5__default.default.red(`unknown project command: ${args[1]}`));
2626
+ console.log(pc5__default.default.gray("usage: amai project add <path> | amai project list"));
2552
2627
  process.exit(1);
2553
2628
  }
2554
- }
2555
- if (args[0] === "login" || args[0] === "--login") {
2556
- login().then(() => process.exit(0)).catch(() => process.exit(1));
2629
+ } else if (args[0] === "login" || args[0] === "--login") {
2630
+ (async () => {
2631
+ try {
2632
+ await login();
2633
+ console.log("");
2634
+ if (isDaemonRunning()) {
2635
+ console.log(pc5__default.default.gray("amai is already running"));
2636
+ process.exit(0);
2637
+ }
2638
+ const answer = await promptUser(pc5__default.default.gray("start amai now? (Y/n): "));
2639
+ const shouldStart = answer === "" || answer.toLowerCase() === "y" || answer.toLowerCase() === "yes";
2640
+ if (shouldStart) {
2641
+ const bgAnswer = await promptUser(pc5__default.default.gray("run in background? (Y/n): "));
2642
+ const runInBackground = bgAnswer === "" || bgAnswer.toLowerCase() === "y" || bgAnswer.toLowerCase() === "yes";
2643
+ if (runInBackground) {
2644
+ console.log(pc5__default.default.gray("starting..."));
2645
+ startDaemon();
2646
+ console.log(pc5__default.default.cyan("amai started"));
2647
+ console.log(pc5__default.default.gray('use "amai status" to check status'));
2648
+ } else {
2649
+ console.log(pc5__default.default.gray("starting in foreground..."));
2650
+ startWithCodeServer();
2651
+ return;
2652
+ }
2653
+ }
2654
+ process.exit(0);
2655
+ } catch {
2656
+ console.error(pc5__default.default.red("login failed"));
2657
+ process.exit(1);
2658
+ }
2659
+ })();
2557
2660
  } else if (args[0] === "logout" || args[0] === "--logout") {
2558
2661
  logout();
2559
- console.log(pc5__default.default.green("Logged out successfully"));
2662
+ console.log(pc5__default.default.cyan("logged out"));
2560
2663
  process.exit(0);
2561
2664
  } else {
2562
2665
  (async () => {
2666
+ console.log(pc5__default.default.cyan(LOGO));
2563
2667
  if (!isAuthenticated()) {
2564
- console.log(pc5__default.default.yellow("Not authenticated. Please log in first."));
2668
+ console.log(pc5__default.default.gray("not authenticated"));
2565
2669
  try {
2566
2670
  await login();
2671
+ console.log("");
2567
2672
  } catch {
2568
- console.error(pc5__default.default.red("Login failed. Cannot start server."));
2673
+ console.error(pc5__default.default.red("login failed"));
2569
2674
  process.exit(1);
2570
2675
  }
2571
2676
  }
2572
2677
  if (isDaemonRunning()) {
2573
- console.log(pc5__default.default.yellow('Daemon is already running. Use "amai status" to check its status.'));
2678
+ console.log(pc5__default.default.gray("amai is already running"));
2679
+ console.log(pc5__default.default.gray('use "amai status" to check status'));
2574
2680
  process.exit(0);
2575
2681
  }
2576
- console.log("");
2577
- console.log(pc5__default.default.bold("How would you like to run amai?"));
2578
- console.log(pc5__default.default.gray("Background mode is highly recommended for better performance and stability."));
2579
- const answer = await promptUser(
2580
- pc5__default.default.cyan("Run in background? (Y/n): ")
2581
- );
2682
+ const answer = await promptUser(pc5__default.default.gray("run in background? (Y/n): "));
2582
2683
  const runInBackground = answer === "" || answer.toLowerCase() === "y" || answer.toLowerCase() === "yes";
2583
2684
  if (runInBackground) {
2584
- console.log(pc5__default.default.green("Starting daemon in background..."));
2685
+ console.log(pc5__default.default.gray("starting..."));
2585
2686
  startDaemon();
2586
- console.log(pc5__default.default.green("Daemon started successfully!"));
2587
- console.log(pc5__default.default.gray('Use "amai status" to check daemon status.'));
2588
- console.log(pc5__default.default.gray('Use "amai stop" to stop the daemon.'));
2687
+ console.log(pc5__default.default.cyan("amai started"));
2688
+ console.log(pc5__default.default.gray('use "amai status" to check status'));
2689
+ console.log(pc5__default.default.gray('use "amai stop" to stop'));
2589
2690
  process.exit(0);
2590
2691
  } else {
2591
- console.log(pc5__default.default.yellow("Starting in foreground mode..."));
2692
+ console.log(pc5__default.default.gray("starting in foreground..."));
2592
2693
  startWithCodeServer();
2593
2694
  }
2594
2695
  })();