@drakonkat/ai-helper 1.1.1 → 1.2.3
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/ARCHITECTURE.md +14 -3
- package/CHANGELOG.md +9 -0
- package/README.md +483 -26
- package/docs/benchmark.md +373 -0
- package/package.json +17 -5
- package/scripts/bench-proxy.js +111 -0
- package/scripts/build.js +16 -0
- package/src/benchmark/fixtures.js +162 -0
- package/src/benchmark/live.js +207 -0
- package/src/benchmark/measurement.js +180 -0
- package/src/benchmark/quality-fixtures.js +95 -0
- package/src/benchmark/quality.js +206 -0
- package/src/benchmark/report.js +162 -0
- package/src/benchmark/runner.js +287 -0
- package/src/codex-config.js +247 -0
- package/src/codex-routing.js +132 -0
- package/src/config.js +19 -1
- package/src/index.js +158 -26
- package/src/manager.js +233 -15
- package/src/proxy-interceptor.example.mjs +33 -0
- package/src/proxy-presets.js +235 -0
- package/src/proxy-stats.js +64 -0
- package/src/proxy-worker.js +17 -0
- package/src/proxy.js +313 -0
- package/src/request-images.js +69 -0
- package/src/service-updates.js +68 -0
- package/src/tui.js +370 -162
- package/src/update.js +41 -0
- package/src/utils/metrics.js +39 -12
- package/src/utils/process.js +92 -146
- package/src/utils/versions.js +165 -0
package/src/config.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
// Node 18 uses assert; newer Node uses with. Bun embeds this JSON when compiling.
|
|
4
|
+
const { default: packageInfo } = await import("../package.json", {
|
|
5
|
+
with: { type: "json" }, assert: { type: "json" },
|
|
6
|
+
});
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* Pre-configured AI ecosystem services managed by aih
|
|
@@ -9,6 +13,7 @@ export const SERVICES = {
|
|
|
9
13
|
id: "pxpipe",
|
|
10
14
|
name: "pxpipe",
|
|
11
15
|
command: "npx pxpipe-proxy",
|
|
16
|
+
repositoryUrl: "https://github.com/teamchong/pxpipe",
|
|
12
17
|
description: "AI LLM / MCP reverse proxy bridge (pxpipe-proxy)",
|
|
13
18
|
defaultPort: 47821,
|
|
14
19
|
defaultUrl: "http://localhost:47821",
|
|
@@ -19,6 +24,7 @@ export const SERVICES = {
|
|
|
19
24
|
name: "ocx",
|
|
20
25
|
command: "ocx start",
|
|
21
26
|
stopCommand: "ocx stop",
|
|
27
|
+
repositoryUrl: "https://github.com/lidge-jun/opencodex",
|
|
22
28
|
description: "OpenCode Interpreter daemon service (ocx start)",
|
|
23
29
|
defaultPort: 10100,
|
|
24
30
|
defaultUrl: "http://localhost:10100",
|
|
@@ -29,6 +35,7 @@ export const SERVICES = {
|
|
|
29
35
|
name: "agentmemory",
|
|
30
36
|
command: "npx @agentmemory/agentmemory",
|
|
31
37
|
stopCommand: "npx @agentmemory/agentmemory stop --force",
|
|
38
|
+
repositoryUrl: "https://github.com/rohitg00/agentmemory",
|
|
32
39
|
description: "Long-term persistent agent memory service (@agentmemory/agentmemory)",
|
|
33
40
|
defaultPort: 3113,
|
|
34
41
|
defaultUrl: "http://localhost:3113",
|
|
@@ -38,6 +45,7 @@ export const SERVICES = {
|
|
|
38
45
|
id: "headroom",
|
|
39
46
|
name: "headroom",
|
|
40
47
|
command: "headroom proxy",
|
|
48
|
+
repositoryUrl: "https://github.com/headroomlabs-ai/headroom",
|
|
41
49
|
description: "Context optimization & LLM proxy (headroom proxy)",
|
|
42
50
|
defaultPort: 8787,
|
|
43
51
|
defaultUrl: "http://localhost:8787/dashboard",
|
|
@@ -47,6 +55,16 @@ export const SERVICES = {
|
|
|
47
55
|
|
|
48
56
|
export const SERVICE_IDS = Object.keys(SERVICES);
|
|
49
57
|
|
|
58
|
+
// Shared by read-only version probes and explicit service updates.
|
|
59
|
+
export const SERVICE_PACKAGES = {
|
|
60
|
+
pxpipe: { name: "pxpipe-proxy", bin: "pxpipe", npx: true },
|
|
61
|
+
ocx: { name: "@bitkyc08/opencodex", bin: "ocx", health: "/healthz", service: "opencodex" },
|
|
62
|
+
agentmemory: { name: "@agentmemory/agentmemory", bin: "agentmemory", npx: true, health: "/agentmemory/health", service: "agentmemory" },
|
|
63
|
+
headroom: { name: "headroom-ai", bin: "headroom", health: "/health", pypi: true },
|
|
64
|
+
};
|
|
65
|
+
|
|
50
66
|
export const APP_NAME = "ai-helper";
|
|
51
67
|
export const CLI_NAME = "aih";
|
|
52
|
-
export const VERSION =
|
|
68
|
+
export const VERSION = packageInfo.version;
|
|
69
|
+
export const PACKAGE_NAME = packageInfo.name;
|
|
70
|
+
export const APP_REPOSITORY_URL = packageInfo.repository.url.replace(/^git\+/, "").replace(/\.git$/, "");
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { APP_NAME, CLI_NAME, SERVICES, SERVICE_IDS, VERSION } from "./config.js";
|
|
2
2
|
import { manager } from "./manager.js";
|
|
3
|
+
import { checkForUpdates } from "./update.js";
|
|
4
|
+
import { readProxyStats, proxyStatsLines } from "./proxy-stats.js";
|
|
3
5
|
import {
|
|
4
6
|
badgeStatus,
|
|
5
7
|
bold,
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
import { isLocalBinInPath, getAddToPathInstructions, getLocalBinDir, ensureDir } from "./utils/path.js";
|
|
17
19
|
import { join } from "node:path";
|
|
18
20
|
import { copyFileSync } from "node:fs";
|
|
21
|
+
import { parseArgs } from "node:util";
|
|
19
22
|
|
|
20
23
|
function printHelp() {
|
|
21
24
|
printBanner();
|
|
@@ -26,10 +29,14 @@ ${bold("COMMANDS:")}
|
|
|
26
29
|
${yellow("status")}, ${yellow("ps")} Show status, PID, uptime, and web dashboard URLs
|
|
27
30
|
${yellow("status -ui")} Interactive live dashboard: manage services and watch the AI pipeline
|
|
28
31
|
${yellow("open")}, ${yellow("dash")} [services...] Open web dashboard(s) directly in your default browser
|
|
29
|
-
${yellow("start")}, ${yellow("up")} [services...] Start
|
|
32
|
+
${yellow("start")}, ${yellow("up")} [services...] Start ocx, agentmemory and the pxpipe proxy, or specified services
|
|
33
|
+
${yellow("start proxy")} <upstream> Start HTTP/SSE/WebSocket proxy (default: 127.0.0.1:10101)
|
|
30
34
|
${yellow("stop")}, ${yellow("down")} [services...] Stop all or specified services
|
|
31
35
|
${yellow("restart")} [services...] Restart all or specified services
|
|
36
|
+
${yellow("update")} [services...] Update managed services to the latest available version
|
|
37
|
+
${yellow("<service> update")} Update one service (for example: aih ocx update)
|
|
32
38
|
${yellow("logs")} <service> [-n 50] [-f] View or stream live logs for a service
|
|
39
|
+
${yellow("stats proxy")} [--json] Show proxy token savings estimates and recent requests
|
|
33
40
|
${yellow("install")} Build standalone binary to ~/.local/bin and verify PATH
|
|
34
41
|
${yellow("version")}, ${yellow("-v")} Show version information
|
|
35
42
|
${yellow("help")}, ${yellow("-h")} Show this help message
|
|
@@ -44,8 +51,25 @@ ${bold("OPTIONS:")}
|
|
|
44
51
|
${gray("-n, --lines <num>")} Number of log lines to show (default: 50)
|
|
45
52
|
${gray("-f, --follow")} Follow log output in real-time
|
|
46
53
|
${gray("--json")} Output results in JSON format
|
|
54
|
+
${gray("--repo")} Open GitHub repositories instead of dashboards (open only)
|
|
55
|
+
${gray("--listen <http://host:port>")} Proxy loopback listening address
|
|
56
|
+
${gray("--interceptor <file.mjs>")} Proxy JavaScript hooks (loaded at startup)
|
|
57
|
+
${gray("--preset <name>")} pxpipe | headroom | rtk | headroom-pxpipe | rtk-pxpipe | rtk-headroom-pxpipe | none
|
|
58
|
+
${gray("--models <list>")} pxpipe model allowlist, comma-separated (trailing * supported)
|
|
59
|
+
${gray("--headroom-url <url>")} Headroom service (default: http://127.0.0.1:8787)
|
|
60
|
+
${gray("--rtk-filter <name>")} Fixed rtk pipe filter (default: auto-detect)
|
|
61
|
+
${gray("--max-body-bytes <num>")} Proxy buffered request / WebSocket limit (default: 67108864)
|
|
47
62
|
${gray("-ui, --ui")} Open the interactive dashboard (status only, requires a TTY)
|
|
48
63
|
|
|
64
|
+
${bold("SERVICE UPDATES:")}
|
|
65
|
+
'update' without targets updates pxpipe, ocx, agentmemory and headroom, not proxy.
|
|
66
|
+
In the live dashboard, select a service with up/down and press u to update it.
|
|
67
|
+
Only running services are restarted; stopped services stay stopped.
|
|
68
|
+
|
|
69
|
+
${bold("CODEX CONFIGURATION:")}
|
|
70
|
+
Starting aih's proxy, or ocx with an active proxy, updates Codex's two base URLs.
|
|
71
|
+
Respects CODEX_HOME; set AIH_CODEX_AUTOCONFIG=0 to leave config.toml untouched.
|
|
72
|
+
|
|
49
73
|
${bold("EXAMPLES:")}
|
|
50
74
|
${dim("$")} ${cyan("npx ai-helper")} status
|
|
51
75
|
${dim("$")} ${cyan(CLI_NAME)} open ${dim("# Opens all running dashboards in browser")}
|
|
@@ -53,6 +77,8 @@ ${bold("EXAMPLES:")}
|
|
|
53
77
|
${dim("$")} ${cyan(CLI_NAME)} start
|
|
54
78
|
${dim("$")} ${cyan(CLI_NAME)} stop pxpipe
|
|
55
79
|
${dim("$")} ${cyan(CLI_NAME)} restart ocx
|
|
80
|
+
${dim("$")} ${cyan(CLI_NAME)} ocx update
|
|
81
|
+
${dim("$")} ${cyan(CLI_NAME)} update ocx agentmemory --json
|
|
56
82
|
${dim("$")} ${cyan(CLI_NAME)} logs pxpipe -f
|
|
57
83
|
`);
|
|
58
84
|
}
|
|
@@ -62,6 +88,11 @@ function printVersion() {
|
|
|
62
88
|
console.log(`${bold(cyan(CLI_NAME))} version ${bold(VERSION)} (${runtime}, ${process.platform}-${process.arch})`);
|
|
63
89
|
}
|
|
64
90
|
|
|
91
|
+
function printCodexConfig(result) {
|
|
92
|
+
const config = result.codexConfig;
|
|
93
|
+
if (config?.message) console.log((config.status === "warning" ? yellow : dim)(` ${config.message}`));
|
|
94
|
+
}
|
|
95
|
+
|
|
65
96
|
async function runInstall() {
|
|
66
97
|
printBanner();
|
|
67
98
|
console.log(cyan("⚙ Building standalone binary and installing to ~/.local/bin...\n"));
|
|
@@ -81,14 +112,7 @@ async function runInstall() {
|
|
|
81
112
|
|
|
82
113
|
try {
|
|
83
114
|
const buildProc = Bun.spawn(
|
|
84
|
-
[
|
|
85
|
-
process.execPath,
|
|
86
|
-
"build",
|
|
87
|
-
"--compile",
|
|
88
|
-
"--minify",
|
|
89
|
-
`--outfile=${tempBuildPath}`,
|
|
90
|
-
join(import.meta.dir, "index.js"),
|
|
91
|
-
],
|
|
115
|
+
[process.execPath, join(import.meta.dir, "../scripts/build.js"), tempBuildPath],
|
|
92
116
|
{ stdout: "pipe", stderr: "pipe" }
|
|
93
117
|
);
|
|
94
118
|
|
|
@@ -134,9 +158,38 @@ async function runInstall() {
|
|
|
134
158
|
export async function main() {
|
|
135
159
|
const rawArgs = process.argv.slice(2);
|
|
136
160
|
|
|
161
|
+
if (["start", "up", "restart"].includes(rawArgs[0]) && rawArgs[1] === "proxy" && !rawArgs.includes("--help") && !rawArgs.includes("-h")) {
|
|
162
|
+
const { values, positionals } = parseArgs({ args: rawArgs.slice(2), allowPositionals: true, options: {
|
|
163
|
+
listen: { type: "string" }, interceptor: { type: "string" },
|
|
164
|
+
preset: { type: "string" }, models: { type: "string" },
|
|
165
|
+
"headroom-url": { type: "string" }, "rtk-filter": { type: "string" },
|
|
166
|
+
"max-body-bytes": { type: "string" }, json: { type: "boolean" },
|
|
167
|
+
} });
|
|
168
|
+
if (positionals.length > 1) throw new Error("Expected one upstream URL");
|
|
169
|
+
const options = {};
|
|
170
|
+
if (positionals[0]) options.upstream = positionals[0];
|
|
171
|
+
if (values.listen !== undefined) options.listen = values.listen;
|
|
172
|
+
if (values.interceptor !== undefined) options.interceptor = values.interceptor;
|
|
173
|
+
for (const [flag, key] of Object.entries({ preset: "preset", models: "models", "headroom-url": "headroomUrl", "rtk-filter": "rtkFilter" })) {
|
|
174
|
+
if (values[flag] !== undefined) options[key] = values[flag];
|
|
175
|
+
}
|
|
176
|
+
if (values["max-body-bytes"] !== undefined) options.maxBodyBytes = values["max-body-bytes"];
|
|
177
|
+
if (rawArgs[0] !== "restart") await checkForUpdates();
|
|
178
|
+
const result = rawArgs[0] === "restart"
|
|
179
|
+
? await manager.restartService("proxy", options)
|
|
180
|
+
: await manager.startService("proxy", options);
|
|
181
|
+
if (values.json) console.log(JSON.stringify(result));
|
|
182
|
+
else if (result.success) console.log(green(`Proxy ${result.alreadyRunning ? "already running" : "started"} (PID: ${result.pid}) at ${result.url}`));
|
|
183
|
+
else console.error(red(result.message));
|
|
184
|
+
if (!values.json) printCodexConfig(result);
|
|
185
|
+
if (!result.success) process.exitCode = 1;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
137
189
|
let jsonOutput = false;
|
|
138
190
|
let follow = false;
|
|
139
191
|
let uiMode = false;
|
|
192
|
+
let repoMode = false;
|
|
140
193
|
let lines = 50;
|
|
141
194
|
const positionalArgs = [];
|
|
142
195
|
|
|
@@ -144,6 +197,8 @@ export async function main() {
|
|
|
144
197
|
const arg = rawArgs[i];
|
|
145
198
|
if (arg === "--json") {
|
|
146
199
|
jsonOutput = true;
|
|
200
|
+
} else if (arg === "--repo") {
|
|
201
|
+
repoMode = true;
|
|
147
202
|
} else if (arg === "-ui" || arg === "--ui") {
|
|
148
203
|
uiMode = true;
|
|
149
204
|
} else if (arg === "-f" || arg === "--follow") {
|
|
@@ -169,10 +224,65 @@ export async function main() {
|
|
|
169
224
|
}
|
|
170
225
|
}
|
|
171
226
|
|
|
172
|
-
const
|
|
173
|
-
const
|
|
227
|
+
const serviceFirstUpdate = positionalArgs[1]?.toLowerCase() === "update" && positionalArgs[0]?.toLowerCase() !== "update";
|
|
228
|
+
const command = serviceFirstUpdate ? "update" : positionalArgs[0]?.toLowerCase() || "status";
|
|
229
|
+
const targets = serviceFirstUpdate ? [positionalArgs[0].toLowerCase()] : positionalArgs.slice(1);
|
|
174
230
|
|
|
175
231
|
switch (command) {
|
|
232
|
+
case "update": {
|
|
233
|
+
const ids = [...new Set(targets.length ? targets : SERVICE_IDS)];
|
|
234
|
+
const invalid = ids.filter(id => !SERVICE_IDS.includes(id));
|
|
235
|
+
const invalidOption = rawArgs.find(arg => arg.startsWith("-") && arg !== "--json");
|
|
236
|
+
let results;
|
|
237
|
+
// Validate the entire request before updating anything, including the
|
|
238
|
+
// service-first alias (which accepts exactly one service).
|
|
239
|
+
if (invalidOption) {
|
|
240
|
+
results = [{ id: targets[0] || null, success: false, message: `Unsupported update option '${invalidOption}'. Only --json is supported.` }];
|
|
241
|
+
} else if (serviceFirstUpdate && positionalArgs.length !== 2) {
|
|
242
|
+
results = [{ id: targets[0], success: false, message: `Usage: ${CLI_NAME} <service> update [--json]; use '${CLI_NAME} update <services...>' for multiple services.` }];
|
|
243
|
+
} else if (invalid.length) {
|
|
244
|
+
results = invalid.map(id => ({ id, success: false, message: id === "proxy"
|
|
245
|
+
? "The built-in proxy is updated with ai-helper itself; update the ai-helper package or rebuild its executable."
|
|
246
|
+
: `Unsupported service '${id}'. Updatable services: ${SERVICE_IDS.join(", ")}.` }));
|
|
247
|
+
} else {
|
|
248
|
+
if (!jsonOutput) printBanner();
|
|
249
|
+
results = [];
|
|
250
|
+
for (const id of ids) {
|
|
251
|
+
if (!jsonOutput) process.stdout.write(` Updating ${bold(id)}... `);
|
|
252
|
+
let result;
|
|
253
|
+
try {
|
|
254
|
+
result = await manager.updateService(id);
|
|
255
|
+
} catch (err) {
|
|
256
|
+
result = { success: false, message: err?.message || String(err) };
|
|
257
|
+
}
|
|
258
|
+
results.push({ id, ...result });
|
|
259
|
+
if (!jsonOutput) {
|
|
260
|
+
console.log((result.success ? green : red)(result.message || `${id}: ${result.success ? "updated" : "update failed"}`));
|
|
261
|
+
printCodexConfig(result);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (jsonOutput) console.log(JSON.stringify(results, null, 2));
|
|
266
|
+
else if (invalidOption || invalid.length || (serviceFirstUpdate && positionalArgs.length !== 2)) {
|
|
267
|
+
for (const result of results) console.error(red(result.message));
|
|
268
|
+
}
|
|
269
|
+
if (results.some(result => !result.success)) process.exitCode = 1;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case "stats": {
|
|
273
|
+
if (targets.length > 1 || (targets[0] && targets[0] !== "proxy")) throw new Error("Usage: aih stats proxy [--json]");
|
|
274
|
+
const stats = readProxyStats();
|
|
275
|
+
if (jsonOutput) console.log(JSON.stringify(stats, null, 2));
|
|
276
|
+
else {
|
|
277
|
+
console.log(proxyStatsLines(stats).join("\n"));
|
|
278
|
+
if (stats) console.log(` Dal ${stats.since} | aggiornato ${stats.updatedAt}`);
|
|
279
|
+
for (const event of stats?.recent.slice(-5) || []) {
|
|
280
|
+
console.log(` ${event.at} ${event.transport} ${event.model} ${event.preset}: ${event.error ? "errore" : `${event.saved} token stimati`}`);
|
|
281
|
+
for (const stage of event.stages) console.log(` ${stage.name}: ${stage.saved ?? "?"} (${stage.reason}, ${stage.method})`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
176
286
|
case "status":
|
|
177
287
|
case "ps":
|
|
178
288
|
case "ls":
|
|
@@ -199,7 +309,8 @@ export async function main() {
|
|
|
199
309
|
"STATUS",
|
|
200
310
|
{ header: "PID", align: "right" },
|
|
201
311
|
{ header: "UPTIME", align: "right" },
|
|
202
|
-
"
|
|
312
|
+
"ADDRESS",
|
|
313
|
+
"REPO",
|
|
203
314
|
"COMMAND",
|
|
204
315
|
];
|
|
205
316
|
|
|
@@ -208,9 +319,10 @@ export async function main() {
|
|
|
208
319
|
badgeStatus(s.status),
|
|
209
320
|
s.pid ? String(s.pid) : dim("-"),
|
|
210
321
|
s.status === "running" ? s.uptime : dim("-"),
|
|
211
|
-
s.status === "running" && s.url && s.url !== "-"
|
|
322
|
+
s.id === "proxy" ? dim(`${s.url} (proxy)`) : s.status === "running" && s.url && s.url !== "-"
|
|
212
323
|
? cyan(underline(s.url))
|
|
213
324
|
: dim(s.url || "-"),
|
|
325
|
+
s.repositoryUrl ? cyan(underline(s.repositoryUrl)) : dim("-"),
|
|
214
326
|
dim(s.command),
|
|
215
327
|
]);
|
|
216
328
|
|
|
@@ -225,6 +337,12 @@ export async function main() {
|
|
|
225
337
|
case "dash": {
|
|
226
338
|
printBanner();
|
|
227
339
|
const svcsToOpen = targets.length > 0 ? targets : undefined;
|
|
340
|
+
if (repoMode) {
|
|
341
|
+
const opened = await manager.openRepository(svcsToOpen);
|
|
342
|
+
if (!opened.length) console.log(yellow("No GitHub repositories available to open."));
|
|
343
|
+
for (const item of opened) console.log(` ${bold(item.name)}: ${cyan(underline(item.url))}`);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
228
346
|
const opened = await manager.openDashboard(svcsToOpen);
|
|
229
347
|
|
|
230
348
|
if (opened.length === 0) {
|
|
@@ -243,13 +361,22 @@ export async function main() {
|
|
|
243
361
|
|
|
244
362
|
case "start":
|
|
245
363
|
case "up": {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
364
|
+
await checkForUpdates();
|
|
365
|
+
if (!jsonOutput) printBanner();
|
|
366
|
+
const svcsToStart = targets.length > 0 ? targets : ["ocx", "agentmemory", "proxy"];
|
|
367
|
+
if (!jsonOutput) console.log(cyan(`Starting service(s): ${svcsToStart.join(", ")}...\n`));
|
|
368
|
+
const results = [];
|
|
249
369
|
|
|
250
370
|
for (const id of svcsToStart) {
|
|
251
|
-
process.stdout.write(` Launching ${bold(id)}... `);
|
|
252
|
-
const res = await manager.startService(id
|
|
371
|
+
if (!jsonOutput) process.stdout.write(` Launching ${bold(id)}... `);
|
|
372
|
+
const res = await manager.startService(id, !targets.length && id === "proxy" ? {
|
|
373
|
+
upstream: "http://127.0.0.1:10100/",
|
|
374
|
+
listen: "http://127.0.0.1:10102",
|
|
375
|
+
preset: "pxpipe",
|
|
376
|
+
models: "gpt-6-astra,google-antigravity/gemini-3.8*,anthropic/claude-fable*",
|
|
377
|
+
} : undefined);
|
|
378
|
+
results.push({ id, ...res });
|
|
379
|
+
if (jsonOutput) continue;
|
|
253
380
|
if (res.success) {
|
|
254
381
|
if (res.alreadyRunning) {
|
|
255
382
|
console.log(yellow(`already running (PID: ${res.pid})`));
|
|
@@ -259,15 +386,16 @@ export async function main() {
|
|
|
259
386
|
} else {
|
|
260
387
|
console.log(red(`failed: ${res.message}`));
|
|
261
388
|
}
|
|
389
|
+
printCodexConfig(res);
|
|
262
390
|
}
|
|
263
|
-
console.log("");
|
|
391
|
+
console.log(jsonOutput ? JSON.stringify(results, null, 2) : "");
|
|
264
392
|
break;
|
|
265
393
|
}
|
|
266
394
|
|
|
267
395
|
case "stop":
|
|
268
396
|
case "down": {
|
|
269
397
|
printBanner();
|
|
270
|
-
const svcsToStop = targets.length > 0 ? targets :
|
|
398
|
+
const svcsToStop = targets.length > 0 ? targets : Object.keys(manager.readState().services);
|
|
271
399
|
console.log(cyan(`Stopping service(s): ${svcsToStop.join(", ")}...\n`));
|
|
272
400
|
|
|
273
401
|
for (const id of svcsToStop) {
|
|
@@ -284,20 +412,24 @@ export async function main() {
|
|
|
284
412
|
}
|
|
285
413
|
|
|
286
414
|
case "restart": {
|
|
287
|
-
printBanner();
|
|
288
|
-
const svcsToRestart = targets.length > 0 ? targets :
|
|
289
|
-
console.log(cyan(`Restarting service(s): ${svcsToRestart.join(", ")}...\n`));
|
|
415
|
+
if (!jsonOutput) printBanner();
|
|
416
|
+
const svcsToRestart = targets.length > 0 ? targets : Object.keys(manager.readState().services);
|
|
417
|
+
if (!jsonOutput) console.log(cyan(`Restarting service(s): ${svcsToRestart.join(", ")}...\n`));
|
|
418
|
+
const results = [];
|
|
290
419
|
|
|
291
420
|
for (const id of svcsToRestart) {
|
|
292
|
-
process.stdout.write(` Restarting ${bold(id)}... `);
|
|
421
|
+
if (!jsonOutput) process.stdout.write(` Restarting ${bold(id)}... `);
|
|
293
422
|
const res = await manager.restartService(id);
|
|
423
|
+
results.push({ id, ...res });
|
|
424
|
+
if (jsonOutput) continue;
|
|
294
425
|
if (res.success) {
|
|
295
426
|
console.log(green(`started (PID: ${res.pid})`));
|
|
296
427
|
} else {
|
|
297
428
|
console.log(red(`failed: ${res.message}`));
|
|
298
429
|
}
|
|
430
|
+
printCodexConfig(res);
|
|
299
431
|
}
|
|
300
|
-
console.log("");
|
|
432
|
+
console.log(jsonOutput ? JSON.stringify(results, null, 2) : "");
|
|
301
433
|
break;
|
|
302
434
|
}
|
|
303
435
|
|
|
@@ -311,7 +443,7 @@ export async function main() {
|
|
|
311
443
|
process.exit(1);
|
|
312
444
|
}
|
|
313
445
|
|
|
314
|
-
if (!SERVICE_IDS.includes(targetService)) {
|
|
446
|
+
if (!SERVICE_IDS.includes(targetService) && targetService !== "proxy") {
|
|
315
447
|
console.log(yellow(`⚠ Warning: '${targetService}' is not a standard service. Looking for log file anyway...`));
|
|
316
448
|
}
|
|
317
449
|
|