@isarai/maestro 0.1.1 → 0.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.
- package/dist/index.js +15 -4
- package/dist/index.js.map +2 -2
- package/dist/server.js +21 -7
- package/dist/server.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ var MAESTRO_DIR = path.join(os.homedir(), ".maestro");
|
|
|
9
9
|
var PID_PATH = path.join(MAESTRO_DIR, "server.pid");
|
|
10
10
|
var META_PATH = path.join(MAESTRO_DIR, "server-meta.json");
|
|
11
11
|
var LOG_PATH = path.join(MAESTRO_DIR, "server.log");
|
|
12
|
-
var TOKEN_PATH = path.join(MAESTRO_DIR, "
|
|
12
|
+
var TOKEN_PATH = path.join(MAESTRO_DIR, "token");
|
|
13
|
+
var LEGACY_TOKEN_PATH = path.join(MAESTRO_DIR, "api-token");
|
|
13
14
|
var SERVER_PATH = path.join(PACKAGE_ROOT, "dist", "server.js");
|
|
14
15
|
var DEFAULT_HOST = process.env.HOST || "0.0.0.0";
|
|
15
16
|
var DEFAULT_PORT = process.env.PORT || "4800";
|
|
@@ -76,6 +77,15 @@ function cleanupState() {
|
|
|
76
77
|
} catch {
|
|
77
78
|
}
|
|
78
79
|
}
|
|
80
|
+
function resolveTokenPath() {
|
|
81
|
+
if (fs.existsSync(TOKEN_PATH)) {
|
|
82
|
+
return TOKEN_PATH;
|
|
83
|
+
}
|
|
84
|
+
if (fs.existsSync(LEGACY_TOKEN_PATH)) {
|
|
85
|
+
return LEGACY_TOKEN_PATH;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
79
89
|
function displayHost(host) {
|
|
80
90
|
if (!host || host === "0.0.0.0" || host === "::") {
|
|
81
91
|
return "127.0.0.1";
|
|
@@ -170,16 +180,17 @@ function status() {
|
|
|
170
180
|
console.log(`Log: ${LOG_PATH}`);
|
|
171
181
|
}
|
|
172
182
|
function auth() {
|
|
173
|
-
|
|
183
|
+
const tokenPath = resolveTokenPath();
|
|
184
|
+
if (!tokenPath) {
|
|
174
185
|
fail(`Maestro API token not found at ${TOKEN_PATH}. Start Maestro first.`);
|
|
175
186
|
}
|
|
176
|
-
const token = fs.readFileSync(
|
|
187
|
+
const token = fs.readFileSync(tokenPath, "utf8").trim();
|
|
177
188
|
const current = getStatus();
|
|
178
189
|
const host = displayHost(current.meta?.host || DEFAULT_HOST);
|
|
179
190
|
const port = current.meta?.port || DEFAULT_PORT;
|
|
180
191
|
console.log(`Server URL: http://${host}:${port}`);
|
|
181
192
|
console.log(`API token: ${token}`);
|
|
182
|
-
console.log(`Token path: ${
|
|
193
|
+
console.log(`Token path: ${tokenPath}`);
|
|
183
194
|
}
|
|
184
195
|
function help() {
|
|
185
196
|
console.log("Usage: maestro <command>");
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { spawn } from \"node:child_process\";\nimport { fileURLToPath } from \"node:url\";\n\nconst PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), \"..\");\nconst MAESTRO_DIR = path.join(os.homedir(), \".maestro\");\nconst PID_PATH = path.join(MAESTRO_DIR, \"server.pid\");\nconst META_PATH = path.join(MAESTRO_DIR, \"server-meta.json\");\nconst LOG_PATH = path.join(MAESTRO_DIR, \"server.log\");\nconst TOKEN_PATH = path.join(MAESTRO_DIR, \"api-token\");\nconst SERVER_PATH = path.join(PACKAGE_ROOT, \"dist\", \"server.js\");\nconst DEFAULT_HOST = process.env.HOST || \"0.0.0.0\";\nconst DEFAULT_PORT = process.env.PORT || \"4800\";\n\ninterface ServerMeta {\n pid: number;\n host: string;\n port: string;\n logPath: string;\n startedAt: string;\n cwd: string;\n}\n\nfunction ensureMaestroDir(): void {\n fs.mkdirSync(MAESTRO_DIR, { recursive: true });\n}\n\nfunction fail(message: string): never {\n console.error(message);\n process.exit(1);\n}\n\nfunction preflight(): void {\n if (!fs.existsSync(SERVER_PATH)) {\n fail(`Maestro server bundle not found at ${SERVER_PATH}`);\n }\n}\n\nfunction readPid(): number | null {\n try {\n const raw = fs.readFileSync(PID_PATH, \"utf8\").trim();\n if (!raw) return null;\n const pid = Number(raw);\n return Number.isInteger(pid) && pid > 0 ? pid : null;\n } catch {\n return null;\n }\n}\n\nfunction isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n if (process.platform === \"linux\") {\n try {\n const stat = fs.readFileSync(`/proc/${pid}/stat`, \"utf8\");\n const fields = stat.trim().split(\" \");\n if (fields[2] === \"Z\") {\n return false;\n }\n } catch {\n // Ignore /proc read failures and fall back to kill(0).\n }\n }\n return true;\n } catch (error) {\n return Boolean(\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n (error as NodeJS.ErrnoException).code === \"EPERM\"\n );\n }\n}\n\nfunction readMeta(): ServerMeta | null {\n try {\n return JSON.parse(fs.readFileSync(META_PATH, \"utf8\")) as ServerMeta;\n } catch {\n return null;\n }\n}\n\nfunction writeMeta(meta: ServerMeta): void {\n ensureMaestroDir();\n fs.writeFileSync(META_PATH, JSON.stringify(meta, null, 2) + \"\\n\", \"utf8\");\n}\n\nfunction cleanupState(): void {\n try {\n fs.unlinkSync(PID_PATH);\n } catch {}\n try {\n fs.unlinkSync(META_PATH);\n } catch {}\n}\n\nfunction displayHost(host: string | undefined): string {\n if (!host || host === \"0.0.0.0\" || host === \"::\") {\n return \"127.0.0.1\";\n }\n return host;\n}\n\nfunction getStatus(): { running: boolean; pid: number | null; meta: ServerMeta | null } {\n const pid = readPid();\n const meta = readMeta();\n\n if (!pid) {\n return { running: false, pid: null, meta };\n }\n\n if (!isProcessAlive(pid)) {\n cleanupState();\n return { running: false, pid: null, meta };\n }\n\n return { running: true, pid, meta };\n}\n\nfunction start(): void {\n preflight();\n ensureMaestroDir();\n\n const current = getStatus();\n if (current.running) {\n const host = displayHost(current.meta?.host || DEFAULT_HOST);\n const port = current.meta?.port || DEFAULT_PORT;\n console.log(`Maestro is already running (pid ${current.pid})`);\n console.log(`URL: http://${host}:${port}`);\n console.log(`Log: ${LOG_PATH}`);\n return;\n }\n\n const out = fs.openSync(LOG_PATH, \"a\");\n const env = {\n ...process.env,\n NODE_ENV: process.env.NODE_ENV || \"production\",\n HOST: DEFAULT_HOST,\n PORT: DEFAULT_PORT,\n MAESTRO_INSTALL_ROOT: PACKAGE_ROOT,\n };\n\n const child = spawn(process.execPath, [SERVER_PATH], {\n cwd: process.cwd(),\n detached: true,\n stdio: [\"ignore\", out, out],\n env,\n });\n\n child.unref();\n\n fs.writeFileSync(PID_PATH, `${child.pid}\\n`, \"utf8\");\n writeMeta({\n pid: child.pid ?? 0,\n host: env.HOST,\n port: env.PORT,\n logPath: LOG_PATH,\n startedAt: new Date().toISOString(),\n cwd: process.cwd(),\n });\n\n console.log(`Started Maestro (pid ${child.pid})`);\n console.log(`URL: http://${displayHost(env.HOST)}:${env.PORT}`);\n console.log(`Log: ${LOG_PATH}`);\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nasync function stop(): Promise<void> {\n const status = getStatus();\n if (!status.running || !status.pid) {\n console.log(\"Maestro is not running\");\n cleanupState();\n return;\n }\n\n process.kill(status.pid, \"SIGTERM\");\n\n const deadline = Date.now() + 10_000;\n while (Date.now() < deadline) {\n if (!isProcessAlive(status.pid)) {\n cleanupState();\n console.log(`Stopped Maestro (pid ${status.pid})`);\n return;\n }\n await sleep(200);\n }\n\n fail(`Timed out waiting for Maestro (pid ${status.pid}) to stop`);\n}\n\nfunction status(): void {\n const current = getStatus();\n if (!current.running) {\n console.log(\"Maestro is not running\");\n return;\n }\n\n const host = displayHost(current.meta?.host || DEFAULT_HOST);\n const port = current.meta?.port || DEFAULT_PORT;\n console.log(`Maestro is running (pid ${current.pid})`);\n console.log(`URL: http://${host}:${port}`);\n console.log(`Log: ${LOG_PATH}`);\n}\n\nfunction auth(): void {\n if (!
|
|
5
|
-
"mappings": ";AAAA,YAAY,QAAQ;AACpB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAE9B,IAAM,eAAoB,aAAa,aAAQ,cAAc,YAAY,GAAG,CAAC,GAAG,IAAI;AACpF,IAAM,cAAmB,UAAQ,WAAQ,GAAG,UAAU;AACtD,IAAM,WAAgB,UAAK,aAAa,YAAY;AACpD,IAAM,YAAiB,UAAK,aAAa,kBAAkB;AAC3D,IAAM,WAAgB,UAAK,aAAa,YAAY;AACpD,IAAM,aAAkB,UAAK,aAAa,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { spawn } from \"node:child_process\";\nimport { fileURLToPath } from \"node:url\";\n\nconst PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), \"..\");\nconst MAESTRO_DIR = path.join(os.homedir(), \".maestro\");\nconst PID_PATH = path.join(MAESTRO_DIR, \"server.pid\");\nconst META_PATH = path.join(MAESTRO_DIR, \"server-meta.json\");\nconst LOG_PATH = path.join(MAESTRO_DIR, \"server.log\");\nconst TOKEN_PATH = path.join(MAESTRO_DIR, \"token\");\nconst LEGACY_TOKEN_PATH = path.join(MAESTRO_DIR, \"api-token\");\nconst SERVER_PATH = path.join(PACKAGE_ROOT, \"dist\", \"server.js\");\nconst DEFAULT_HOST = process.env.HOST || \"0.0.0.0\";\nconst DEFAULT_PORT = process.env.PORT || \"4800\";\n\ninterface ServerMeta {\n pid: number;\n host: string;\n port: string;\n logPath: string;\n startedAt: string;\n cwd: string;\n}\n\nfunction ensureMaestroDir(): void {\n fs.mkdirSync(MAESTRO_DIR, { recursive: true });\n}\n\nfunction fail(message: string): never {\n console.error(message);\n process.exit(1);\n}\n\nfunction preflight(): void {\n if (!fs.existsSync(SERVER_PATH)) {\n fail(`Maestro server bundle not found at ${SERVER_PATH}`);\n }\n}\n\nfunction readPid(): number | null {\n try {\n const raw = fs.readFileSync(PID_PATH, \"utf8\").trim();\n if (!raw) return null;\n const pid = Number(raw);\n return Number.isInteger(pid) && pid > 0 ? pid : null;\n } catch {\n return null;\n }\n}\n\nfunction isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n if (process.platform === \"linux\") {\n try {\n const stat = fs.readFileSync(`/proc/${pid}/stat`, \"utf8\");\n const fields = stat.trim().split(\" \");\n if (fields[2] === \"Z\") {\n return false;\n }\n } catch {\n // Ignore /proc read failures and fall back to kill(0).\n }\n }\n return true;\n } catch (error) {\n return Boolean(\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n (error as NodeJS.ErrnoException).code === \"EPERM\"\n );\n }\n}\n\nfunction readMeta(): ServerMeta | null {\n try {\n return JSON.parse(fs.readFileSync(META_PATH, \"utf8\")) as ServerMeta;\n } catch {\n return null;\n }\n}\n\nfunction writeMeta(meta: ServerMeta): void {\n ensureMaestroDir();\n fs.writeFileSync(META_PATH, JSON.stringify(meta, null, 2) + \"\\n\", \"utf8\");\n}\n\nfunction cleanupState(): void {\n try {\n fs.unlinkSync(PID_PATH);\n } catch {}\n try {\n fs.unlinkSync(META_PATH);\n } catch {}\n}\n\nfunction resolveTokenPath(): string | null {\n if (fs.existsSync(TOKEN_PATH)) {\n return TOKEN_PATH;\n }\n if (fs.existsSync(LEGACY_TOKEN_PATH)) {\n return LEGACY_TOKEN_PATH;\n }\n return null;\n}\n\nfunction displayHost(host: string | undefined): string {\n if (!host || host === \"0.0.0.0\" || host === \"::\") {\n return \"127.0.0.1\";\n }\n return host;\n}\n\nfunction getStatus(): { running: boolean; pid: number | null; meta: ServerMeta | null } {\n const pid = readPid();\n const meta = readMeta();\n\n if (!pid) {\n return { running: false, pid: null, meta };\n }\n\n if (!isProcessAlive(pid)) {\n cleanupState();\n return { running: false, pid: null, meta };\n }\n\n return { running: true, pid, meta };\n}\n\nfunction start(): void {\n preflight();\n ensureMaestroDir();\n\n const current = getStatus();\n if (current.running) {\n const host = displayHost(current.meta?.host || DEFAULT_HOST);\n const port = current.meta?.port || DEFAULT_PORT;\n console.log(`Maestro is already running (pid ${current.pid})`);\n console.log(`URL: http://${host}:${port}`);\n console.log(`Log: ${LOG_PATH}`);\n return;\n }\n\n const out = fs.openSync(LOG_PATH, \"a\");\n const env = {\n ...process.env,\n NODE_ENV: process.env.NODE_ENV || \"production\",\n HOST: DEFAULT_HOST,\n PORT: DEFAULT_PORT,\n MAESTRO_INSTALL_ROOT: PACKAGE_ROOT,\n };\n\n const child = spawn(process.execPath, [SERVER_PATH], {\n cwd: process.cwd(),\n detached: true,\n stdio: [\"ignore\", out, out],\n env,\n });\n\n child.unref();\n\n fs.writeFileSync(PID_PATH, `${child.pid}\\n`, \"utf8\");\n writeMeta({\n pid: child.pid ?? 0,\n host: env.HOST,\n port: env.PORT,\n logPath: LOG_PATH,\n startedAt: new Date().toISOString(),\n cwd: process.cwd(),\n });\n\n console.log(`Started Maestro (pid ${child.pid})`);\n console.log(`URL: http://${displayHost(env.HOST)}:${env.PORT}`);\n console.log(`Log: ${LOG_PATH}`);\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nasync function stop(): Promise<void> {\n const status = getStatus();\n if (!status.running || !status.pid) {\n console.log(\"Maestro is not running\");\n cleanupState();\n return;\n }\n\n process.kill(status.pid, \"SIGTERM\");\n\n const deadline = Date.now() + 10_000;\n while (Date.now() < deadline) {\n if (!isProcessAlive(status.pid)) {\n cleanupState();\n console.log(`Stopped Maestro (pid ${status.pid})`);\n return;\n }\n await sleep(200);\n }\n\n fail(`Timed out waiting for Maestro (pid ${status.pid}) to stop`);\n}\n\nfunction status(): void {\n const current = getStatus();\n if (!current.running) {\n console.log(\"Maestro is not running\");\n return;\n }\n\n const host = displayHost(current.meta?.host || DEFAULT_HOST);\n const port = current.meta?.port || DEFAULT_PORT;\n console.log(`Maestro is running (pid ${current.pid})`);\n console.log(`URL: http://${host}:${port}`);\n console.log(`Log: ${LOG_PATH}`);\n}\n\nfunction auth(): void {\n const tokenPath = resolveTokenPath();\n if (!tokenPath) {\n fail(`Maestro API token not found at ${TOKEN_PATH}. Start Maestro first.`);\n }\n\n const token = fs.readFileSync(tokenPath, \"utf8\").trim();\n const current = getStatus();\n const host = displayHost(current.meta?.host || DEFAULT_HOST);\n const port = current.meta?.port || DEFAULT_PORT;\n\n console.log(`Server URL: http://${host}:${port}`);\n console.log(`API token: ${token}`);\n console.log(`Token path: ${tokenPath}`);\n}\n\nfunction help(): void {\n console.log(\"Usage: maestro <command>\");\n console.log(\"\");\n console.log(\"Commands:\");\n console.log(\" start Start the Maestro server in the background\");\n console.log(\" stop Stop the background Maestro server\");\n console.log(\" status Show whether the Maestro server is running\");\n console.log(\" auth Print the local Maestro API token\");\n}\n\nasync function main(): Promise<void> {\n const cmd = process.argv[2];\n\n switch (cmd) {\n case \"start\":\n start();\n break;\n case \"stop\":\n await stop();\n break;\n case \"status\":\n status();\n break;\n case \"auth\":\n auth();\n break;\n case \"help\":\n case \"--help\":\n case \"-h\":\n case undefined:\n help();\n break;\n default:\n fail(`Unknown command: ${cmd}`);\n }\n}\n\nvoid main();\n"],
|
|
5
|
+
"mappings": ";AAAA,YAAY,QAAQ;AACpB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAE9B,IAAM,eAAoB,aAAa,aAAQ,cAAc,YAAY,GAAG,CAAC,GAAG,IAAI;AACpF,IAAM,cAAmB,UAAQ,WAAQ,GAAG,UAAU;AACtD,IAAM,WAAgB,UAAK,aAAa,YAAY;AACpD,IAAM,YAAiB,UAAK,aAAa,kBAAkB;AAC3D,IAAM,WAAgB,UAAK,aAAa,YAAY;AACpD,IAAM,aAAkB,UAAK,a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;AACH,aAAO;AACP;AAAA,IACF,KAAK;AACH,WAAK;AACL;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,WAAK;AACL;AAAA,IACF;AACE,WAAK,oBAAoB,GAAG,EAAE;AAAA,EAClC;AACF;AAEA,KAAK,KAAK;",
|
|
6
6
|
"names": ["resolve", "status"]
|
|
7
7
|
}
|
package/dist/server.js
CHANGED
|
@@ -6450,8 +6450,20 @@ import * as path15 from "path";
|
|
|
6450
6450
|
import jwt from "jsonwebtoken";
|
|
6451
6451
|
var MAESTRO_DIR = MAESTRO_DATA_DIR;
|
|
6452
6452
|
var SECRET_PATH = path15.join(MAESTRO_DIR, "jwt-secret");
|
|
6453
|
-
var TOKEN_PATH = path15.join(MAESTRO_DIR, "
|
|
6453
|
+
var TOKEN_PATH = path15.join(MAESTRO_DIR, "token");
|
|
6454
|
+
var LEGACY_TOKEN_PATH = path15.join(MAESTRO_DIR, "api-token");
|
|
6454
6455
|
var jwtSecret;
|
|
6456
|
+
function resolveTokenPath() {
|
|
6457
|
+
if (fs14.existsSync(TOKEN_PATH)) {
|
|
6458
|
+
return TOKEN_PATH;
|
|
6459
|
+
}
|
|
6460
|
+
if (fs14.existsSync(LEGACY_TOKEN_PATH)) {
|
|
6461
|
+
fs14.renameSync(LEGACY_TOKEN_PATH, TOKEN_PATH);
|
|
6462
|
+
console.log(`Migrated API token path from ${LEGACY_TOKEN_PATH} to ${TOKEN_PATH}`);
|
|
6463
|
+
return TOKEN_PATH;
|
|
6464
|
+
}
|
|
6465
|
+
return TOKEN_PATH;
|
|
6466
|
+
}
|
|
6455
6467
|
function initAuth() {
|
|
6456
6468
|
ensureDataDir();
|
|
6457
6469
|
if (fs14.existsSync(SECRET_PATH)) {
|
|
@@ -6461,14 +6473,15 @@ function initAuth() {
|
|
|
6461
6473
|
fs14.writeFileSync(SECRET_PATH, jwtSecret, { mode: 384 });
|
|
6462
6474
|
}
|
|
6463
6475
|
let apiToken;
|
|
6464
|
-
|
|
6465
|
-
|
|
6476
|
+
const tokenPath = resolveTokenPath();
|
|
6477
|
+
if (fs14.existsSync(tokenPath)) {
|
|
6478
|
+
apiToken = fs14.readFileSync(tokenPath, "utf-8").trim();
|
|
6466
6479
|
} else {
|
|
6467
6480
|
apiToken = `sym_${crypto2.randomBytes(32).toString("hex")}`;
|
|
6468
|
-
fs14.writeFileSync(
|
|
6481
|
+
fs14.writeFileSync(tokenPath, apiToken, { mode: 384 });
|
|
6469
6482
|
console.log(`
|
|
6470
6483
|
API token generated: ${apiToken}`);
|
|
6471
|
-
console.log(`Stored at: ${
|
|
6484
|
+
console.log(`Stored at: ${tokenPath}
|
|
6472
6485
|
`);
|
|
6473
6486
|
}
|
|
6474
6487
|
return { apiToken };
|
|
@@ -6484,8 +6497,9 @@ function verifySessionToken(token) {
|
|
|
6484
6497
|
}
|
|
6485
6498
|
}
|
|
6486
6499
|
function getApiToken() {
|
|
6487
|
-
|
|
6488
|
-
|
|
6500
|
+
const tokenPath = resolveTokenPath();
|
|
6501
|
+
if (fs14.existsSync(tokenPath)) {
|
|
6502
|
+
return fs14.readFileSync(tokenPath, "utf-8").trim();
|
|
6489
6503
|
}
|
|
6490
6504
|
return "";
|
|
6491
6505
|
}
|