amai 0.0.5 → 0.0.6
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 +274 -80
- package/dist/cli.js +272 -78
- package/dist/lib/daemon-entry.cjs +213 -19
- package/dist/lib/daemon-entry.js +212 -18
- package/dist/server.cjs +213 -20
- package/dist/server.d.cts +1 -3
- package/dist/server.d.ts +1 -3
- package/dist/server.js +213 -19
- package/package.json +2 -2
package/dist/cli.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var events = require('events');
|
|
4
|
+
var pc5 = require('picocolors');
|
|
5
|
+
var WebSocket2 = require('ws');
|
|
7
6
|
var zod = require('zod');
|
|
8
7
|
var promises = require('fs/promises');
|
|
9
8
|
var path9 = require('path');
|
|
@@ -21,8 +20,8 @@ var readline = require('readline');
|
|
|
21
20
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
22
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
22
|
|
|
24
|
-
var
|
|
25
|
-
var
|
|
23
|
+
var pc5__default = /*#__PURE__*/_interopDefault(pc5);
|
|
24
|
+
var WebSocket2__default = /*#__PURE__*/_interopDefault(WebSocket2);
|
|
26
25
|
var path9__default = /*#__PURE__*/_interopDefault(path9);
|
|
27
26
|
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
28
27
|
var os2__default = /*#__PURE__*/_interopDefault(os2);
|
|
@@ -1426,15 +1425,6 @@ var startHttpServer = (connection) => {
|
|
|
1426
1425
|
controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: initialStatus === "open" })}
|
|
1427
1426
|
|
|
1428
1427
|
`));
|
|
1429
|
-
const statusHandler = (data) => {
|
|
1430
|
-
try {
|
|
1431
|
-
controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
|
|
1432
|
-
|
|
1433
|
-
`));
|
|
1434
|
-
} catch {
|
|
1435
|
-
}
|
|
1436
|
-
};
|
|
1437
|
-
statusEmitter.on("status", statusHandler);
|
|
1438
1428
|
const heartbeatInterval = setInterval(() => {
|
|
1439
1429
|
try {
|
|
1440
1430
|
const currentStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
|
|
@@ -1445,7 +1435,6 @@ var startHttpServer = (connection) => {
|
|
|
1445
1435
|
}
|
|
1446
1436
|
}, 15e3);
|
|
1447
1437
|
c.req.raw.signal.addEventListener("abort", () => {
|
|
1448
|
-
statusEmitter.off("status", statusHandler);
|
|
1449
1438
|
clearInterval(heartbeatInterval);
|
|
1450
1439
|
});
|
|
1451
1440
|
}
|
|
@@ -1685,7 +1674,7 @@ function saveTokens(tokens) {
|
|
|
1685
1674
|
"utf8"
|
|
1686
1675
|
);
|
|
1687
1676
|
} catch (error) {
|
|
1688
|
-
console.error(
|
|
1677
|
+
console.error(pc5__default.default.red("Failed to save credentials"), error);
|
|
1689
1678
|
}
|
|
1690
1679
|
}
|
|
1691
1680
|
function logout() {
|
|
@@ -1694,7 +1683,7 @@ function logout() {
|
|
|
1694
1683
|
fs3__default.default.unlinkSync(CREDENTIALS_PATH);
|
|
1695
1684
|
}
|
|
1696
1685
|
} catch (error) {
|
|
1697
|
-
console.error(
|
|
1686
|
+
console.error(pc5__default.default.red("Failed to logout"), error);
|
|
1698
1687
|
}
|
|
1699
1688
|
}
|
|
1700
1689
|
function getTokens() {
|
|
@@ -1769,27 +1758,27 @@ async function pollForTokens({
|
|
|
1769
1758
|
async function login() {
|
|
1770
1759
|
try {
|
|
1771
1760
|
const device = await authorizeDevice();
|
|
1772
|
-
console.log(
|
|
1761
|
+
console.log(pc5__default.default.bold("To sign in, follow these steps:"));
|
|
1773
1762
|
if (device.verification_uri_complete) {
|
|
1774
1763
|
console.log(
|
|
1775
|
-
` 1. Open this URL in your browser: ${
|
|
1764
|
+
` 1. Open this URL in your browser: ${pc5__default.default.cyan(
|
|
1776
1765
|
device.verification_uri_complete
|
|
1777
1766
|
)}`
|
|
1778
1767
|
);
|
|
1779
1768
|
} else {
|
|
1780
1769
|
console.log(
|
|
1781
|
-
` 1. Open this URL in your browser: ${
|
|
1770
|
+
` 1. Open this URL in your browser: ${pc5__default.default.cyan(
|
|
1782
1771
|
device.verification_uri
|
|
1783
1772
|
)}`
|
|
1784
1773
|
);
|
|
1785
1774
|
console.log(
|
|
1786
|
-
` 2. Enter this code when prompted: ${
|
|
1775
|
+
` 2. Enter this code when prompted: ${pc5__default.default.bold(device.user_code)}`
|
|
1787
1776
|
);
|
|
1788
1777
|
}
|
|
1789
1778
|
console.log(" 3. Come back here; we will detect when you finish logging in.");
|
|
1790
1779
|
console.log();
|
|
1791
1780
|
console.log(
|
|
1792
|
-
|
|
1781
|
+
pc5__default.default.gray(
|
|
1793
1782
|
`Waiting for authorization (expires in ~${Math.round(
|
|
1794
1783
|
device.expires_in / 60
|
|
1795
1784
|
)} minutes)...`
|
|
@@ -1801,14 +1790,28 @@ async function login() {
|
|
|
1801
1790
|
expiresIn: device.expires_in,
|
|
1802
1791
|
interval: device.interval
|
|
1803
1792
|
});
|
|
1804
|
-
console.log(
|
|
1793
|
+
console.log(pc5__default.default.green("Successfully authenticated!"));
|
|
1805
1794
|
saveTokens(tokens);
|
|
1806
1795
|
return tokens;
|
|
1807
1796
|
} catch (error) {
|
|
1808
|
-
console.error(
|
|
1797
|
+
console.error(pc5__default.default.red(error.message || "Login failed"));
|
|
1809
1798
|
throw error;
|
|
1810
1799
|
}
|
|
1811
1800
|
}
|
|
1801
|
+
var getUserId = () => {
|
|
1802
|
+
try {
|
|
1803
|
+
if (!fs3__default.default.existsSync(CREDENTIALS_PATH)) {
|
|
1804
|
+
return;
|
|
1805
|
+
}
|
|
1806
|
+
const raw = fs3__default.default.readFileSync(CREDENTIALS_PATH, "utf8");
|
|
1807
|
+
const data = JSON.parse(raw);
|
|
1808
|
+
return {
|
|
1809
|
+
userId: data.user.id
|
|
1810
|
+
};
|
|
1811
|
+
} catch {
|
|
1812
|
+
throw new Error("Error while getting userId");
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1812
1815
|
var ExplanationSchema = zod.z.object({
|
|
1813
1816
|
explanation: zod.z.string().describe("One sentence explanation as to why this tool is being used")
|
|
1814
1817
|
});
|
|
@@ -1897,8 +1900,201 @@ var runTerminalCommand = async (input, projectCwd) => {
|
|
|
1897
1900
|
}
|
|
1898
1901
|
};
|
|
1899
1902
|
|
|
1903
|
+
// src/lib/rpc-handlers.ts
|
|
1904
|
+
var rpcHandlers = {
|
|
1905
|
+
"daemon:get_workspace_folders": async () => {
|
|
1906
|
+
const projects = projectRegistry.list();
|
|
1907
|
+
return {
|
|
1908
|
+
folders: projects.map((p) => ({
|
|
1909
|
+
id: p.id,
|
|
1910
|
+
cwd: p.cwd,
|
|
1911
|
+
name: p.name,
|
|
1912
|
+
active: p.active
|
|
1913
|
+
}))
|
|
1914
|
+
};
|
|
1915
|
+
},
|
|
1916
|
+
"daemon:get_environment": async ({ gitRepositoryUrl }) => {
|
|
1917
|
+
const projects = projectRegistry.list();
|
|
1918
|
+
if (projects.length === 0) {
|
|
1919
|
+
const error = {
|
|
1920
|
+
_tag: "ProjectUnlinkedError",
|
|
1921
|
+
message: `Getting a local project by git repository URL "${gitRepositoryUrl}" returned an unlinked project. Please link it by running \`amai link <project name> <path to project directory>\``
|
|
1922
|
+
};
|
|
1923
|
+
throw error;
|
|
1924
|
+
}
|
|
1925
|
+
return {
|
|
1926
|
+
project: projects[0],
|
|
1927
|
+
env: {
|
|
1928
|
+
platform: process.platform,
|
|
1929
|
+
arch: process.arch,
|
|
1930
|
+
nodeVersion: process.version
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
},
|
|
1934
|
+
"daemon:get_context": async ({ cwd }) => {
|
|
1935
|
+
try {
|
|
1936
|
+
const files = getContext(cwd);
|
|
1937
|
+
return { files, cwd };
|
|
1938
|
+
} catch (error) {
|
|
1939
|
+
const rpcError = {
|
|
1940
|
+
_tag: "ContextError",
|
|
1941
|
+
message: error.message || "Failed to get context"
|
|
1942
|
+
};
|
|
1943
|
+
throw rpcError;
|
|
1944
|
+
}
|
|
1945
|
+
},
|
|
1946
|
+
"daemon:get_ide_projects": async () => {
|
|
1947
|
+
const projects = await scanIdeProjects();
|
|
1948
|
+
return { projects };
|
|
1949
|
+
},
|
|
1950
|
+
"daemon:register_project": async ({ projectId, cwd, name }) => {
|
|
1951
|
+
if (!projectId || !cwd) {
|
|
1952
|
+
const error = {
|
|
1953
|
+
_tag: "ValidationError",
|
|
1954
|
+
message: "projectId and cwd are required"
|
|
1955
|
+
};
|
|
1956
|
+
throw error;
|
|
1957
|
+
}
|
|
1958
|
+
projectRegistry.register(projectId, cwd, name);
|
|
1959
|
+
return { success: true, projectId, cwd };
|
|
1960
|
+
},
|
|
1961
|
+
"daemon:unregister_project": async ({ projectId }) => {
|
|
1962
|
+
if (!projectId) {
|
|
1963
|
+
const error = {
|
|
1964
|
+
_tag: "ValidationError",
|
|
1965
|
+
message: "projectId is required"
|
|
1966
|
+
};
|
|
1967
|
+
throw error;
|
|
1968
|
+
}
|
|
1969
|
+
projectRegistry.unregister(projectId);
|
|
1970
|
+
return { success: true, projectId };
|
|
1971
|
+
},
|
|
1972
|
+
"daemon:get_project": async ({ projectId }) => {
|
|
1973
|
+
const project = projectRegistry.getProject(projectId);
|
|
1974
|
+
if (!project) {
|
|
1975
|
+
const error = {
|
|
1976
|
+
_tag: "ProjectNotFoundError",
|
|
1977
|
+
message: `Project not found: ${projectId}`
|
|
1978
|
+
};
|
|
1979
|
+
throw error;
|
|
1980
|
+
}
|
|
1981
|
+
return { project };
|
|
1982
|
+
},
|
|
1983
|
+
"daemon:list_projects": async () => {
|
|
1984
|
+
const projects = projectRegistry.list();
|
|
1985
|
+
return { projects };
|
|
1986
|
+
},
|
|
1987
|
+
"daemon:status": async () => {
|
|
1988
|
+
return {
|
|
1989
|
+
connected: true,
|
|
1990
|
+
timestamp: Date.now(),
|
|
1991
|
+
platform: process.platform,
|
|
1992
|
+
arch: process.arch
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
var reconnectTimeout = null;
|
|
1997
|
+
var connectToUserStreams = async (serverUrl) => {
|
|
1998
|
+
const userId = getUserId();
|
|
1999
|
+
if (!userId?.userId) {
|
|
2000
|
+
throw new Error("User ID not found");
|
|
2001
|
+
}
|
|
2002
|
+
const params = new URLSearchParams({
|
|
2003
|
+
userId: userId.userId,
|
|
2004
|
+
type: "cli"
|
|
2005
|
+
});
|
|
2006
|
+
const tokens = getTokens();
|
|
2007
|
+
if (!tokens) {
|
|
2008
|
+
throw new Error("No tokens found");
|
|
2009
|
+
}
|
|
2010
|
+
const wsUrl = `${serverUrl}/api/v1/user-streams?${params.toString()}`;
|
|
2011
|
+
const ws = new WebSocket2__default.default(wsUrl, {
|
|
2012
|
+
headers: {
|
|
2013
|
+
Authorization: `Bearer ${tokens.access_token}`
|
|
2014
|
+
}
|
|
2015
|
+
});
|
|
2016
|
+
ws.on("open", () => {
|
|
2017
|
+
console.log(pc5__default.default.green("CLI connected to user-streams"));
|
|
2018
|
+
if (reconnectTimeout) {
|
|
2019
|
+
clearTimeout(reconnectTimeout);
|
|
2020
|
+
reconnectTimeout = null;
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
2023
|
+
ws.on("message", async (event) => {
|
|
2024
|
+
try {
|
|
2025
|
+
const message = JSON.parse(event.toString());
|
|
2026
|
+
if (message._tag === "rpc_call") {
|
|
2027
|
+
const { requestId, method, input } = message;
|
|
2028
|
+
console.log(pc5__default.default.gray(`RPC call: ${method}`));
|
|
2029
|
+
const handler = rpcHandlers[method];
|
|
2030
|
+
if (!handler) {
|
|
2031
|
+
ws.send(JSON.stringify({
|
|
2032
|
+
_tag: "rpc_result",
|
|
2033
|
+
requestId,
|
|
2034
|
+
data: {
|
|
2035
|
+
_tag: "UnknownMethodError",
|
|
2036
|
+
message: `Unknown RPC method: ${method}`
|
|
2037
|
+
}
|
|
2038
|
+
}));
|
|
2039
|
+
console.log(pc5__default.default.yellow(`Unknown RPC method: ${method}`));
|
|
2040
|
+
return;
|
|
2041
|
+
}
|
|
2042
|
+
try {
|
|
2043
|
+
const result = await handler(input || {});
|
|
2044
|
+
ws.send(JSON.stringify({
|
|
2045
|
+
_tag: "rpc_result",
|
|
2046
|
+
requestId,
|
|
2047
|
+
data: result
|
|
2048
|
+
}));
|
|
2049
|
+
console.log(pc5__default.default.green(`RPC completed: ${method}`));
|
|
2050
|
+
} catch (error) {
|
|
2051
|
+
const rpcError = error._tag ? error : {
|
|
2052
|
+
_tag: "RpcError",
|
|
2053
|
+
message: error.message || String(error)
|
|
2054
|
+
};
|
|
2055
|
+
ws.send(JSON.stringify({
|
|
2056
|
+
_tag: "rpc_result",
|
|
2057
|
+
requestId,
|
|
2058
|
+
data: rpcError
|
|
2059
|
+
}));
|
|
2060
|
+
console.log(pc5__default.default.red(`RPC failed: ${method} - ${rpcError.message}`));
|
|
2061
|
+
}
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
if (message.type === "presence_request") {
|
|
2065
|
+
if (message.status === "connected") {
|
|
2066
|
+
ws.send(JSON.stringify({
|
|
2067
|
+
type: "presence_request",
|
|
2068
|
+
status: "connected"
|
|
2069
|
+
}));
|
|
2070
|
+
}
|
|
2071
|
+
if (message.status === "disconnected") {
|
|
2072
|
+
ws.send(JSON.stringify({
|
|
2073
|
+
type: "presence_request",
|
|
2074
|
+
status: "disconnected"
|
|
2075
|
+
}));
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
} catch (parseError) {
|
|
2079
|
+
console.error(pc5__default.default.red(`Failed to parse message: ${parseError}`));
|
|
2080
|
+
}
|
|
2081
|
+
});
|
|
2082
|
+
ws.on("close", (code, reason) => {
|
|
2083
|
+
console.log(pc5__default.default.yellow(`CLI disconnected from user-streams (code: ${code})`));
|
|
2084
|
+
console.log(pc5__default.default.gray("Reconnecting in 5 seconds..."));
|
|
2085
|
+
reconnectTimeout = setTimeout(() => {
|
|
2086
|
+
connectToUserStreams(serverUrl).catch((err) => {
|
|
2087
|
+
console.error(pc5__default.default.red(`Reconnection failed: ${err.message}`));
|
|
2088
|
+
});
|
|
2089
|
+
}, 5e3);
|
|
2090
|
+
});
|
|
2091
|
+
ws.on("error", (error) => {
|
|
2092
|
+
console.error(pc5__default.default.red(`User streams WebSocket error: ${error.message}`));
|
|
2093
|
+
});
|
|
2094
|
+
return ws;
|
|
2095
|
+
};
|
|
2096
|
+
|
|
1900
2097
|
// src/server.ts
|
|
1901
|
-
var statusEmitter = new events.EventEmitter();
|
|
1902
2098
|
var toolExecutors = {
|
|
1903
2099
|
editFile: editFiles,
|
|
1904
2100
|
deleteFile,
|
|
@@ -1910,7 +2106,7 @@ var toolExecutors = {
|
|
|
1910
2106
|
runTerminalCommand
|
|
1911
2107
|
};
|
|
1912
2108
|
function getConnectionStatus(ws) {
|
|
1913
|
-
return ws.readyState ===
|
|
2109
|
+
return ws.readyState === WebSocket2__default.default.CONNECTING ? "connecting" : ws.readyState === WebSocket2__default.default.OPEN ? "open" : ws.readyState === WebSocket2__default.default.CLOSING ? "closing" : "closed";
|
|
1914
2110
|
}
|
|
1915
2111
|
function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
|
|
1916
2112
|
const tokens = getTokens();
|
|
@@ -1918,14 +2114,13 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
|
|
|
1918
2114
|
throw new Error("No tokens found");
|
|
1919
2115
|
}
|
|
1920
2116
|
const wsUrl = `${serverUrl}/agent-streams`;
|
|
1921
|
-
const ws = new
|
|
2117
|
+
const ws = new WebSocket2__default.default(wsUrl, {
|
|
1922
2118
|
headers: {
|
|
1923
2119
|
"Authorization": `Bearer ${tokens.access_token}`
|
|
1924
2120
|
}
|
|
1925
2121
|
});
|
|
1926
2122
|
ws.on("open", () => {
|
|
1927
|
-
console.log(
|
|
1928
|
-
statusEmitter.emit("status", { connected: true });
|
|
2123
|
+
console.log(pc5__default.default.green("Connected to server agent streams"));
|
|
1929
2124
|
});
|
|
1930
2125
|
ws.on("message", async (data) => {
|
|
1931
2126
|
const message = JSON.parse(data.toString());
|
|
@@ -1942,33 +2137,32 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
|
|
|
1942
2137
|
id: message.id,
|
|
1943
2138
|
result
|
|
1944
2139
|
}));
|
|
1945
|
-
console.log(
|
|
2140
|
+
console.log(pc5__default.default.green(`Tool completed: ${message.tool}`));
|
|
1946
2141
|
} catch (error) {
|
|
1947
2142
|
ws.send(JSON.stringify({
|
|
1948
2143
|
type: "tool_result",
|
|
1949
2144
|
id: message.id,
|
|
1950
2145
|
error: error.message
|
|
1951
2146
|
}));
|
|
1952
|
-
console.error(
|
|
2147
|
+
console.error(pc5__default.default.red(`Tool failed: ${message.tool} ${error.message}`));
|
|
1953
2148
|
}
|
|
1954
2149
|
}
|
|
1955
2150
|
});
|
|
1956
2151
|
ws.on("close", () => {
|
|
1957
|
-
console.log(
|
|
1958
|
-
statusEmitter.emit("status", { connected: false });
|
|
2152
|
+
console.log(pc5__default.default.red("Disconnected from server. Reconnecting in 5s..."));
|
|
1959
2153
|
setTimeout(() => connectToServer2(serverUrl), 5e3);
|
|
1960
2154
|
});
|
|
1961
2155
|
ws.on("error", (error) => {
|
|
1962
|
-
console.error(
|
|
1963
|
-
statusEmitter.emit("status", { connected: false });
|
|
2156
|
+
console.error(pc5__default.default.red(`WebSocket error: ${error.message}`));
|
|
1964
2157
|
});
|
|
1965
2158
|
return ws;
|
|
1966
2159
|
}
|
|
1967
2160
|
async function main() {
|
|
1968
2161
|
const serverUrl = DEFAULT_SERVER_URL;
|
|
1969
|
-
console.log(
|
|
1970
|
-
console.log(
|
|
2162
|
+
console.log(pc5__default.default.green("Starting local amai..."));
|
|
2163
|
+
console.log(pc5__default.default.gray(`Connecting to server at ${serverUrl}`));
|
|
1971
2164
|
const connection = connectToServer2(serverUrl);
|
|
2165
|
+
await connectToUserStreams(serverUrl);
|
|
1972
2166
|
startHttpServer(connection);
|
|
1973
2167
|
}
|
|
1974
2168
|
var execAsync2 = util.promisify(child_process.exec);
|
|
@@ -2020,22 +2214,22 @@ async function installCodeServer() {
|
|
|
2020
2214
|
if (!fs3__default.default.existsSync(STORAGE_DIR)) {
|
|
2021
2215
|
fs3__default.default.mkdirSync(STORAGE_DIR, { recursive: true });
|
|
2022
2216
|
}
|
|
2023
|
-
console.log(
|
|
2024
|
-
console.log(
|
|
2217
|
+
console.log(pc5__default.default.cyan(`Downloading code-server v${CODE_SERVER_VERSION}...`));
|
|
2218
|
+
console.log(pc5__default.default.gray(downloadUrl));
|
|
2025
2219
|
const response = await fetch(downloadUrl);
|
|
2026
2220
|
if (!response.ok) {
|
|
2027
2221
|
throw new Error(`Failed to download code-server: ${response.statusText}`);
|
|
2028
2222
|
}
|
|
2029
2223
|
const buffer = await response.arrayBuffer();
|
|
2030
2224
|
await fs3__default.default.promises.writeFile(tarballPath, Buffer.from(buffer));
|
|
2031
|
-
console.log(
|
|
2225
|
+
console.log(pc5__default.default.cyan("Extracting code-server..."));
|
|
2032
2226
|
await execAsync2(`tar -xzf ${tarballPath} -C ${CODE_DIR}`);
|
|
2033
2227
|
await fs3__default.default.promises.unlink(tarballPath);
|
|
2034
2228
|
const binPath = getCodeServerBin();
|
|
2035
2229
|
if (fs3__default.default.existsSync(binPath)) {
|
|
2036
2230
|
await fs3__default.default.promises.chmod(binPath, 493);
|
|
2037
2231
|
}
|
|
2038
|
-
console.log(
|
|
2232
|
+
console.log(pc5__default.default.green("\u2713 code-server installed successfully"));
|
|
2039
2233
|
}
|
|
2040
2234
|
async function killExistingCodeServer() {
|
|
2041
2235
|
try {
|
|
@@ -2074,7 +2268,7 @@ async function startCodeServer(cwd) {
|
|
|
2074
2268
|
}
|
|
2075
2269
|
} catch {
|
|
2076
2270
|
}
|
|
2077
|
-
console.log(
|
|
2271
|
+
console.log(pc5__default.default.cyan(`Starting code-server in ${workDir}...`));
|
|
2078
2272
|
const codeServer = child_process.spawn(
|
|
2079
2273
|
binPath,
|
|
2080
2274
|
[
|
|
@@ -2093,7 +2287,7 @@ async function startCodeServer(cwd) {
|
|
|
2093
2287
|
stdio: ["ignore", "pipe", "pipe"]
|
|
2094
2288
|
}
|
|
2095
2289
|
);
|
|
2096
|
-
console.log(
|
|
2290
|
+
console.log(pc5__default.default.green(`\u2713 code-server running at http://localhost:8081/?folder=${encodeURIComponent(workDir)}`));
|
|
2097
2291
|
return codeServer;
|
|
2098
2292
|
}
|
|
2099
2293
|
var __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
|
|
@@ -2157,7 +2351,7 @@ function getDaemonPid() {
|
|
|
2157
2351
|
return null;
|
|
2158
2352
|
}
|
|
2159
2353
|
}
|
|
2160
|
-
var VERSION = "0.0.
|
|
2354
|
+
var VERSION = "0.0.6";
|
|
2161
2355
|
var PROJECT_DIR = process.cwd();
|
|
2162
2356
|
function promptUser(question) {
|
|
2163
2357
|
const rl = readline__default.default.createInterface({
|
|
@@ -2173,19 +2367,19 @@ function promptUser(question) {
|
|
|
2173
2367
|
}
|
|
2174
2368
|
async function startWithCodeServer() {
|
|
2175
2369
|
if (!isCodeServerInstalled()) {
|
|
2176
|
-
console.log(
|
|
2370
|
+
console.log(pc5__default.default.cyan("First run detected. Setting up code-server..."));
|
|
2177
2371
|
try {
|
|
2178
2372
|
await installCodeServer();
|
|
2179
2373
|
} catch (error) {
|
|
2180
|
-
console.error(
|
|
2181
|
-
console.log(
|
|
2374
|
+
console.error(pc5__default.default.red(`Failed to install code-server: ${error.message}`));
|
|
2375
|
+
console.log(pc5__default.default.yellow("Continuing without code-server..."));
|
|
2182
2376
|
}
|
|
2183
2377
|
}
|
|
2184
2378
|
if (isCodeServerInstalled()) {
|
|
2185
2379
|
try {
|
|
2186
2380
|
await startCodeServer(PROJECT_DIR);
|
|
2187
2381
|
} catch (error) {
|
|
2188
|
-
console.error(
|
|
2382
|
+
console.error(pc5__default.default.red(`Failed to start code-server: ${error.message}`));
|
|
2189
2383
|
}
|
|
2190
2384
|
}
|
|
2191
2385
|
main();
|
|
@@ -2193,7 +2387,7 @@ async function startWithCodeServer() {
|
|
|
2193
2387
|
var args = process.argv.slice(2);
|
|
2194
2388
|
if (args[0] === "--help" || args[0] === "-h") {
|
|
2195
2389
|
console.log(`
|
|
2196
|
-
${
|
|
2390
|
+
${pc5__default.default.bold("amai cli")} ${pc5__default.default.gray(VERSION)}
|
|
2197
2391
|
|
|
2198
2392
|
Usage: amai [command] [options]
|
|
2199
2393
|
|
|
@@ -2221,32 +2415,32 @@ Example:
|
|
|
2221
2415
|
}
|
|
2222
2416
|
if (args[0] === "start") {
|
|
2223
2417
|
if (isDaemonRunning()) {
|
|
2224
|
-
console.log(
|
|
2418
|
+
console.log(pc5__default.default.yellow("Daemon is already running"));
|
|
2225
2419
|
process.exit(0);
|
|
2226
2420
|
}
|
|
2227
2421
|
if (!isAuthenticated()) {
|
|
2228
|
-
console.log(
|
|
2422
|
+
console.log(pc5__default.default.yellow("Not authenticated. Please log in first."));
|
|
2229
2423
|
login().then(() => {
|
|
2230
|
-
console.log(
|
|
2424
|
+
console.log(pc5__default.default.green("Starting daemon..."));
|
|
2231
2425
|
startDaemon();
|
|
2232
|
-
console.log(
|
|
2426
|
+
console.log(pc5__default.default.green("Daemon started successfully"));
|
|
2233
2427
|
process.exit(0);
|
|
2234
2428
|
}).catch(() => {
|
|
2235
|
-
console.error(
|
|
2429
|
+
console.error(pc5__default.default.red("Login failed. Cannot start daemon."));
|
|
2236
2430
|
process.exit(1);
|
|
2237
2431
|
});
|
|
2238
2432
|
} else {
|
|
2239
2433
|
startDaemon();
|
|
2240
|
-
console.log(
|
|
2241
|
-
console.log(
|
|
2434
|
+
console.log(pc5__default.default.green(pc5__default.default.bold("amai started in background mode")));
|
|
2435
|
+
console.log(pc5__default.default.gray(`Tip: You can check status any time with ${pc5__default.default.bold("amai status")}`));
|
|
2242
2436
|
process.exit(0);
|
|
2243
2437
|
}
|
|
2244
2438
|
}
|
|
2245
2439
|
if (args[0] === "stop") {
|
|
2246
2440
|
if (stopDaemon()) {
|
|
2247
|
-
console.log(
|
|
2441
|
+
console.log(pc5__default.default.green("Daemon stopped successfully"));
|
|
2248
2442
|
} else {
|
|
2249
|
-
console.log(
|
|
2443
|
+
console.log(pc5__default.default.yellow("Daemon was not running"));
|
|
2250
2444
|
}
|
|
2251
2445
|
process.exit(0);
|
|
2252
2446
|
}
|
|
@@ -2254,9 +2448,9 @@ if (args[0] === "status") {
|
|
|
2254
2448
|
const running = isDaemonRunning();
|
|
2255
2449
|
const pid = getDaemonPid();
|
|
2256
2450
|
if (running && pid) {
|
|
2257
|
-
console.log(
|
|
2451
|
+
console.log(pc5__default.default.green(`Daemon is running (PID: ${pid})`));
|
|
2258
2452
|
} else {
|
|
2259
|
-
console.log(
|
|
2453
|
+
console.log(pc5__default.default.yellow("Daemon is not running"));
|
|
2260
2454
|
}
|
|
2261
2455
|
process.exit(0);
|
|
2262
2456
|
}
|
|
@@ -2264,36 +2458,36 @@ if (args[0] === "project") {
|
|
|
2264
2458
|
if (args[1] === "add") {
|
|
2265
2459
|
const projectPath = args[2];
|
|
2266
2460
|
if (!projectPath) {
|
|
2267
|
-
console.error(
|
|
2461
|
+
console.error(pc5__default.default.red("Please provide a project path"));
|
|
2268
2462
|
console.log("Usage: amai project add <path>");
|
|
2269
2463
|
process.exit(1);
|
|
2270
2464
|
}
|
|
2271
2465
|
const resolvedPath = path9__default.default.resolve(projectPath);
|
|
2272
2466
|
if (!fs3__default.default.existsSync(resolvedPath)) {
|
|
2273
|
-
console.error(
|
|
2467
|
+
console.error(pc5__default.default.red(`Path does not exist: ${resolvedPath}`));
|
|
2274
2468
|
process.exit(1);
|
|
2275
2469
|
}
|
|
2276
2470
|
if (!fs3__default.default.statSync(resolvedPath).isDirectory()) {
|
|
2277
|
-
console.error(
|
|
2471
|
+
console.error(pc5__default.default.red(`Path is not a directory: ${resolvedPath}`));
|
|
2278
2472
|
process.exit(1);
|
|
2279
2473
|
}
|
|
2280
2474
|
const projectId = path9__default.default.basename(resolvedPath);
|
|
2281
2475
|
projectRegistry.register(projectId, resolvedPath);
|
|
2282
|
-
console.log(
|
|
2476
|
+
console.log(pc5__default.default.green(`Project registered: ${projectId} -> ${resolvedPath}`));
|
|
2283
2477
|
process.exit(0);
|
|
2284
2478
|
} else if (args[1] === "list") {
|
|
2285
2479
|
const projects = projectRegistry.list();
|
|
2286
2480
|
if (projects.length === 0) {
|
|
2287
|
-
console.log(
|
|
2481
|
+
console.log(pc5__default.default.yellow("No projects registered"));
|
|
2288
2482
|
} else {
|
|
2289
|
-
console.log(
|
|
2483
|
+
console.log(pc5__default.default.bold("Registered projects:"));
|
|
2290
2484
|
projects.forEach((project) => {
|
|
2291
|
-
console.log(` ${
|
|
2485
|
+
console.log(` ${pc5__default.default.cyan(project.id)}: ${project.cwd} ${project.active ? pc5__default.default.green("(active)") : ""}`);
|
|
2292
2486
|
});
|
|
2293
2487
|
}
|
|
2294
2488
|
process.exit(0);
|
|
2295
2489
|
} else {
|
|
2296
|
-
console.error(
|
|
2490
|
+
console.error(pc5__default.default.red(`Unknown project command: ${args[1]}`));
|
|
2297
2491
|
console.log('Use "amai project add <path>" or "amai project list"');
|
|
2298
2492
|
process.exit(1);
|
|
2299
2493
|
}
|
|
@@ -2302,39 +2496,39 @@ if (args[0] === "login" || args[0] === "--login") {
|
|
|
2302
2496
|
login().then(() => process.exit(0)).catch(() => process.exit(1));
|
|
2303
2497
|
} else if (args[0] === "logout" || args[0] === "--logout") {
|
|
2304
2498
|
logout();
|
|
2305
|
-
console.log(
|
|
2499
|
+
console.log(pc5__default.default.green("Logged out successfully"));
|
|
2306
2500
|
process.exit(0);
|
|
2307
2501
|
} else {
|
|
2308
2502
|
(async () => {
|
|
2309
2503
|
if (!isAuthenticated()) {
|
|
2310
|
-
console.log(
|
|
2504
|
+
console.log(pc5__default.default.yellow("Not authenticated. Please log in first."));
|
|
2311
2505
|
try {
|
|
2312
2506
|
await login();
|
|
2313
2507
|
} catch {
|
|
2314
|
-
console.error(
|
|
2508
|
+
console.error(pc5__default.default.red("Login failed. Cannot start server."));
|
|
2315
2509
|
process.exit(1);
|
|
2316
2510
|
}
|
|
2317
2511
|
}
|
|
2318
2512
|
if (isDaemonRunning()) {
|
|
2319
|
-
console.log(
|
|
2513
|
+
console.log(pc5__default.default.yellow('Daemon is already running. Use "amai status" to check its status.'));
|
|
2320
2514
|
process.exit(0);
|
|
2321
2515
|
}
|
|
2322
2516
|
console.log("");
|
|
2323
|
-
console.log(
|
|
2324
|
-
console.log(
|
|
2517
|
+
console.log(pc5__default.default.bold("How would you like to run amai?"));
|
|
2518
|
+
console.log(pc5__default.default.gray("Background mode is highly recommended for better performance and stability."));
|
|
2325
2519
|
const answer = await promptUser(
|
|
2326
|
-
|
|
2520
|
+
pc5__default.default.cyan("Run in background? (Y/n): ")
|
|
2327
2521
|
);
|
|
2328
2522
|
const runInBackground = answer === "" || answer.toLowerCase() === "y" || answer.toLowerCase() === "yes";
|
|
2329
2523
|
if (runInBackground) {
|
|
2330
|
-
console.log(
|
|
2524
|
+
console.log(pc5__default.default.green("Starting daemon in background..."));
|
|
2331
2525
|
startDaemon();
|
|
2332
|
-
console.log(
|
|
2333
|
-
console.log(
|
|
2334
|
-
console.log(
|
|
2526
|
+
console.log(pc5__default.default.green("Daemon started successfully!"));
|
|
2527
|
+
console.log(pc5__default.default.gray('Use "amai status" to check daemon status.'));
|
|
2528
|
+
console.log(pc5__default.default.gray('Use "amai stop" to stop the daemon.'));
|
|
2335
2529
|
process.exit(0);
|
|
2336
2530
|
} else {
|
|
2337
|
-
console.log(
|
|
2531
|
+
console.log(pc5__default.default.yellow("Starting in foreground mode..."));
|
|
2338
2532
|
startWithCodeServer();
|
|
2339
2533
|
}
|
|
2340
2534
|
})();
|