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 +229 -128
- package/dist/cli.js +229 -128
- package/dist/lib/daemon-entry.cjs +65 -40
- package/dist/lib/daemon-entry.js +64 -39
- package/dist/server.cjs +49 -24
- package/dist/server.js +48 -23
- package/package.json +2 -2
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(
|
|
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
|
-
|
|
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("
|
|
1275
|
-
console.log();
|
|
1264
|
+
console.log("");
|
|
1276
1265
|
console.log(
|
|
1277
1266
|
pc5__default.default.gray(
|
|
1278
|
-
`
|
|
1267
|
+
`waiting for authorization (~${Math.round(
|
|
1279
1268
|
device.expires_in / 60
|
|
1280
|
-
)}
|
|
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.
|
|
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 || "
|
|
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
|
-
|
|
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(
|
|
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(`
|
|
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(`
|
|
2070
|
+
console.error(pc5__default.default.red(`parse error`));
|
|
2071
2071
|
}
|
|
2072
2072
|
});
|
|
2073
2073
|
ws.on("close", (code, reason) => {
|
|
2074
|
-
|
|
2075
|
-
|
|
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(`
|
|
2079
|
+
console.error(pc5__default.default.red(`reconnection failed`));
|
|
2079
2080
|
});
|
|
2080
|
-
},
|
|
2081
|
+
}, delay);
|
|
2081
2082
|
});
|
|
2082
2083
|
ws.on("error", (error) => {
|
|
2083
|
-
console.error(pc5__default.default.red(`
|
|
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
|
-
|
|
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(
|
|
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(`
|
|
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(
|
|
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
|
|
2169
|
+
console.error(pc5__default.default.red(` rpc failed: ${message.method}`));
|
|
2158
2170
|
}
|
|
2159
2171
|
}
|
|
2160
2172
|
});
|
|
2161
2173
|
ws.on("close", () => {
|
|
2162
|
-
|
|
2163
|
-
|
|
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(`
|
|
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.
|
|
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.
|
|
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.
|
|
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(`
|
|
2435
|
-
console.log(pc5__default.default.
|
|
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(`
|
|
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
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
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] === "
|
|
2477
|
-
|
|
2478
|
-
console.log(pc5__default.default.
|
|
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
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
console.log(pc5__default.default.
|
|
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
|
-
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
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.
|
|
2495
|
-
console.log(pc5__default.default.gray(`
|
|
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.
|
|
2566
|
+
console.log(pc5__default.default.cyan("daemon stopped"));
|
|
2502
2567
|
} else {
|
|
2503
|
-
console.log(pc5__default.default.
|
|
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.
|
|
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.
|
|
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("
|
|
2522
|
-
console.log("
|
|
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(`
|
|
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(`
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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(`
|
|
2551
|
-
console.log(
|
|
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
|
-
|
|
2556
|
-
|
|
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.
|
|
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.
|
|
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("
|
|
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.
|
|
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
|
-
|
|
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.
|
|
2685
|
+
console.log(pc5__default.default.gray("starting..."));
|
|
2585
2686
|
startDaemon();
|
|
2586
|
-
console.log(pc5__default.default.
|
|
2587
|
-
console.log(pc5__default.default.gray('
|
|
2588
|
-
console.log(pc5__default.default.gray('
|
|
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.
|
|
2692
|
+
console.log(pc5__default.default.gray("starting in foreground..."));
|
|
2592
2693
|
startWithCodeServer();
|
|
2593
2694
|
}
|
|
2594
2695
|
})();
|