@vendian/cli 0.0.38 → 0.0.40
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/cli-wrapper.mjs +63 -32
- package/package.json +1 -1
package/cli-wrapper.mjs
CHANGED
|
@@ -491,6 +491,29 @@ function spawnForward(command, args, options = {}) {
|
|
|
491
491
|
});
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
|
+
function childProcessIsRunning(child) {
|
|
495
|
+
return Boolean(child) && child.exitCode == null && child.signalCode == null;
|
|
496
|
+
}
|
|
497
|
+
function killProcessTree(child, {
|
|
498
|
+
platform = process.platform,
|
|
499
|
+
signal = "SIGTERM",
|
|
500
|
+
spawnSyncFn = spawnSync
|
|
501
|
+
} = {}) {
|
|
502
|
+
if (!childProcessIsRunning(child)) return false;
|
|
503
|
+
if (platform === "win32") {
|
|
504
|
+
try {
|
|
505
|
+
spawnSyncFn("taskkill", ["/F", "/T", "/PID", String(child.pid)], { stdio: "ignore" });
|
|
506
|
+
} catch {
|
|
507
|
+
}
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
child.kill(signal);
|
|
512
|
+
return true;
|
|
513
|
+
} catch {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
494
517
|
|
|
495
518
|
// src/python.js
|
|
496
519
|
import fs2 from "node:fs";
|
|
@@ -2381,7 +2404,7 @@ function buildLocalServeEventStreamArgs({ agentsDir: agentsDir2 = "./agents", co
|
|
|
2381
2404
|
}
|
|
2382
2405
|
|
|
2383
2406
|
// src/version.js
|
|
2384
|
-
var CLI_VERSION = true ? "0.0.
|
|
2407
|
+
var CLI_VERSION = true ? "0.0.40" : process.env.npm_package_version || "0.0.0-dev";
|
|
2385
2408
|
|
|
2386
2409
|
// src/dev-server.js
|
|
2387
2410
|
var __dirname = path8.dirname(fileURLToPath(import.meta.url));
|
|
@@ -2392,6 +2415,7 @@ var serveState = initialServeState();
|
|
|
2392
2415
|
var serveLogs = [];
|
|
2393
2416
|
var logStore = null;
|
|
2394
2417
|
var agentsDir = "";
|
|
2418
|
+
var activeServeAgentsDir = "";
|
|
2395
2419
|
var collectionId = "";
|
|
2396
2420
|
async function startDevServer({
|
|
2397
2421
|
port = 3859,
|
|
@@ -2439,8 +2463,8 @@ async function startDevServer({
|
|
|
2439
2463
|
}
|
|
2440
2464
|
function shutdown(server) {
|
|
2441
2465
|
console.log("\n \x1B[90mShutting down...\x1B[0m");
|
|
2442
|
-
if (serveChild
|
|
2443
|
-
serveChild
|
|
2466
|
+
if (childProcessIsRunning(serveChild)) {
|
|
2467
|
+
killProcessTree(serveChild, { signal: "SIGTERM" });
|
|
2444
2468
|
}
|
|
2445
2469
|
server.close();
|
|
2446
2470
|
process.exit(0);
|
|
@@ -2529,10 +2553,11 @@ async function handleApi(req, res, pathname, parsed) {
|
|
|
2529
2553
|
}
|
|
2530
2554
|
}
|
|
2531
2555
|
function apiStatus(req, res) {
|
|
2532
|
-
const serving = serveChild
|
|
2556
|
+
const serving = childProcessIsRunning(serveChild);
|
|
2533
2557
|
jsonResponse(res, {
|
|
2534
2558
|
serving,
|
|
2535
2559
|
agentsDir,
|
|
2560
|
+
serveAgentsDir: serving ? activeServeAgentsDir || agentsDir : "",
|
|
2536
2561
|
collectionId,
|
|
2537
2562
|
connected: serveState.connected,
|
|
2538
2563
|
activity: serveState.activity,
|
|
@@ -2542,7 +2567,7 @@ function apiStatus(req, res) {
|
|
|
2542
2567
|
});
|
|
2543
2568
|
}
|
|
2544
2569
|
function apiServeState(req, res) {
|
|
2545
|
-
const serving = serveChild
|
|
2570
|
+
const serving = childProcessIsRunning(serveChild);
|
|
2546
2571
|
const agentStatuses = serveState.agents.map((agent) => {
|
|
2547
2572
|
const relPath = agent.relativePath || ".";
|
|
2548
2573
|
const runtime = agentRuntimeStatus(agent, serveState.agentRunState);
|
|
@@ -2593,6 +2618,8 @@ function apiServeState(req, res) {
|
|
|
2593
2618
|
activity.sort((a, b) => (a.timestamp || "").localeCompare(b.timestamp || ""));
|
|
2594
2619
|
jsonResponse(res, {
|
|
2595
2620
|
serving,
|
|
2621
|
+
agentsDir,
|
|
2622
|
+
serveAgentsDir: serving ? activeServeAgentsDir || agentsDir : "",
|
|
2596
2623
|
connected: serveState.connected,
|
|
2597
2624
|
stopped: serveState.stopped,
|
|
2598
2625
|
activity: serveState.activity,
|
|
@@ -2706,8 +2733,15 @@ function resolveServeStartTarget(body = {}, current = {}) {
|
|
|
2706
2733
|
}
|
|
2707
2734
|
return { ok: true, agentsDir: targetDir, collectionId: targetCollection };
|
|
2708
2735
|
}
|
|
2736
|
+
function devServerStateAfterServeStart(current = {}, target = {}) {
|
|
2737
|
+
return {
|
|
2738
|
+
agentsDir: current.agentsDir || "",
|
|
2739
|
+
activeServeAgentsDir: target.agentsDir || current.agentsDir || "",
|
|
2740
|
+
collectionId: target.collectionId || current.collectionId || ""
|
|
2741
|
+
};
|
|
2742
|
+
}
|
|
2709
2743
|
async function apiServeStart(req, res, body) {
|
|
2710
|
-
if (serveChild
|
|
2744
|
+
if (childProcessIsRunning(serveChild)) {
|
|
2711
2745
|
return jsonResponse(res, { ok: false, error: "Already serving" });
|
|
2712
2746
|
}
|
|
2713
2747
|
const target = resolveServeStartTarget(body, { agentsDir, collectionId });
|
|
@@ -2721,11 +2755,13 @@ async function apiServeStart(req, res, body) {
|
|
|
2721
2755
|
buildLocalServeEventStreamArgs({ agentsDir: targetDir, collectionId: targetCollection }),
|
|
2722
2756
|
{ onProgress: null }
|
|
2723
2757
|
);
|
|
2724
|
-
|
|
2725
|
-
|
|
2758
|
+
const nextState = devServerStateAfterServeStart({ agentsDir, collectionId }, target);
|
|
2759
|
+
agentsDir = nextState.agentsDir;
|
|
2760
|
+
activeServeAgentsDir = nextState.activeServeAgentsDir;
|
|
2761
|
+
collectionId = nextState.collectionId;
|
|
2726
2762
|
serveState = initialServeState();
|
|
2727
2763
|
serveLogs = [];
|
|
2728
|
-
logStore = createServeLogStore({ agentsDir:
|
|
2764
|
+
logStore = createServeLogStore({ agentsDir: activeServeAgentsDir, collectionId });
|
|
2729
2765
|
serveChild = spawn3(invocation.command, invocation.args, {
|
|
2730
2766
|
env: invocation.env,
|
|
2731
2767
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -2765,6 +2801,7 @@ async function apiServeStart(req, res, body) {
|
|
|
2765
2801
|
serveState = { ...serveState, stopped: true, connected: false };
|
|
2766
2802
|
serveLogs.push(`[process] Exited code=${code} signal=${signal || "none"}`);
|
|
2767
2803
|
serveChild = null;
|
|
2804
|
+
activeServeAgentsDir = "";
|
|
2768
2805
|
try {
|
|
2769
2806
|
logStore?.compact();
|
|
2770
2807
|
} catch {
|
|
@@ -2776,13 +2813,15 @@ async function apiServeStart(req, res, body) {
|
|
|
2776
2813
|
}
|
|
2777
2814
|
}
|
|
2778
2815
|
function apiServeStop(req, res) {
|
|
2779
|
-
if (!serveChild
|
|
2816
|
+
if (!childProcessIsRunning(serveChild)) {
|
|
2817
|
+
activeServeAgentsDir = "";
|
|
2780
2818
|
return jsonResponse(res, { ok: true, wasRunning: false });
|
|
2781
2819
|
}
|
|
2782
|
-
serveChild
|
|
2820
|
+
const stoppingChild = serveChild;
|
|
2821
|
+
killProcessTree(stoppingChild, { signal: "SIGTERM" });
|
|
2783
2822
|
setTimeout(() => {
|
|
2784
|
-
if (
|
|
2785
|
-
|
|
2823
|
+
if (childProcessIsRunning(stoppingChild)) {
|
|
2824
|
+
killProcessTree(stoppingChild, { signal: "SIGKILL" });
|
|
2786
2825
|
}
|
|
2787
2826
|
}, 3e3);
|
|
2788
2827
|
jsonResponse(res, { ok: true, wasRunning: true });
|
|
@@ -2959,7 +2998,6 @@ function openUrl(url) {
|
|
|
2959
2998
|
// src/tui.js
|
|
2960
2999
|
init_constants();
|
|
2961
3000
|
init_auth();
|
|
2962
|
-
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
2963
3001
|
import fs12 from "node:fs";
|
|
2964
3002
|
import path9 from "node:path";
|
|
2965
3003
|
import readline from "node:readline";
|
|
@@ -3670,7 +3708,7 @@ async function runServeDashboard({ env, platform, agentsDir: agentsDir2, collect
|
|
|
3670
3708
|
stopSignalAttempt += 1;
|
|
3671
3709
|
const signal = stopSignalForAttempt(stopSignalAttempt);
|
|
3672
3710
|
if (process.platform === "win32") {
|
|
3673
|
-
|
|
3711
|
+
killProcessTree2(child);
|
|
3674
3712
|
} else {
|
|
3675
3713
|
try {
|
|
3676
3714
|
child.kill(signal);
|
|
@@ -3692,7 +3730,7 @@ async function runServeDashboard({ env, platform, agentsDir: agentsDir2, collect
|
|
|
3692
3730
|
clearTimeout(ctrlCArmTimer);
|
|
3693
3731
|
ctrlCArmed = false;
|
|
3694
3732
|
if (process.platform === "win32") {
|
|
3695
|
-
|
|
3733
|
+
killProcessTree2(child);
|
|
3696
3734
|
} else {
|
|
3697
3735
|
try {
|
|
3698
3736
|
child.kill(stopSignalForAttempt(stopSignalAttempt));
|
|
@@ -3706,9 +3744,13 @@ async function runServeDashboard({ env, platform, agentsDir: agentsDir2, collect
|
|
|
3706
3744
|
if (!key) return;
|
|
3707
3745
|
if (key.ctrl && key.name === "c") {
|
|
3708
3746
|
if (ctrlCArmed) {
|
|
3709
|
-
|
|
3710
|
-
child
|
|
3711
|
-
}
|
|
3747
|
+
if (process.platform === "win32") {
|
|
3748
|
+
killProcessTree2(child);
|
|
3749
|
+
} else {
|
|
3750
|
+
try {
|
|
3751
|
+
child?.kill("SIGINT");
|
|
3752
|
+
} catch (error) {
|
|
3753
|
+
}
|
|
3712
3754
|
}
|
|
3713
3755
|
finish("exit");
|
|
3714
3756
|
return;
|
|
@@ -3947,19 +3989,8 @@ function stopSignalForAttempt(attempt = 0) {
|
|
|
3947
3989
|
if (attempt === 1) return "SIGTERM";
|
|
3948
3990
|
return "SIGKILL";
|
|
3949
3991
|
}
|
|
3950
|
-
function
|
|
3951
|
-
|
|
3952
|
-
if (process.platform === "win32") {
|
|
3953
|
-
try {
|
|
3954
|
-
spawnSync4("taskkill", ["/F", "/T", "/PID", String(child.pid)], { stdio: "ignore" });
|
|
3955
|
-
} catch {
|
|
3956
|
-
}
|
|
3957
|
-
} else {
|
|
3958
|
-
try {
|
|
3959
|
-
child.kill("SIGTERM");
|
|
3960
|
-
} catch {
|
|
3961
|
-
}
|
|
3962
|
-
}
|
|
3992
|
+
function killProcessTree2(child) {
|
|
3993
|
+
killProcessTree(child, { signal: "SIGTERM" });
|
|
3963
3994
|
}
|
|
3964
3995
|
function helpText() {
|
|
3965
3996
|
return [
|