agentflow-core 0.5.2 → 0.6.1
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/{chunk-YTMQBL3T.js → chunk-BOSYI5YM.js} +374 -48
- package/dist/cli.cjs +480 -58
- package/dist/cli.js +103 -3
- package/dist/index.cjs +382 -53
- package/dist/index.d.cts +109 -1
- package/dist/index.d.ts +109 -1
- package/dist/index.js +7 -1
- package/package.json +7 -3
package/dist/cli.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
auditProcesses,
|
|
3
4
|
createTraceStore,
|
|
5
|
+
discoverProcessConfig,
|
|
6
|
+
formatAuditReport,
|
|
4
7
|
runTraced,
|
|
5
8
|
startLive,
|
|
6
9
|
startWatch,
|
|
7
10
|
toAsciiTree,
|
|
8
11
|
toTimeline
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-BOSYI5YM.js";
|
|
10
13
|
import "./chunk-DY7YHFIB.js";
|
|
11
14
|
|
|
12
15
|
// src/cli.ts
|
|
13
|
-
import { basename } from "path";
|
|
16
|
+
import { basename, resolve as resolve2 } from "path";
|
|
14
17
|
|
|
15
18
|
// src/trace-cli.ts
|
|
16
19
|
import { resolve } from "path";
|
|
@@ -216,6 +219,7 @@ Commands:
|
|
|
216
219
|
live [dir...] [options] Real-time terminal monitor (auto-detects any JSON/JSONL)
|
|
217
220
|
watch [dir...] [options] Headless alert system \u2014 detects failures, sends notifications
|
|
218
221
|
trace <command> [options] Inspect saved execution traces (list, show, timeline, stuck, loops)
|
|
222
|
+
audit [options] Audit OS processes \u2014 detect stale PIDs, orphans, systemd issues
|
|
219
223
|
|
|
220
224
|
Run \`agentflow <command> --help\` for command-specific options.
|
|
221
225
|
|
|
@@ -367,9 +371,102 @@ async function runCommand(argv) {
|
|
|
367
371
|
process.exit(1);
|
|
368
372
|
}
|
|
369
373
|
}
|
|
374
|
+
function parseAuditArgs(argv) {
|
|
375
|
+
let processName = "";
|
|
376
|
+
let pidFile;
|
|
377
|
+
let workersFile;
|
|
378
|
+
let systemdUnit;
|
|
379
|
+
const discoverDirs = [];
|
|
380
|
+
const args = argv.slice(0);
|
|
381
|
+
if (args[0] === "audit") args.shift();
|
|
382
|
+
let i = 0;
|
|
383
|
+
while (i < args.length) {
|
|
384
|
+
const arg = args[i];
|
|
385
|
+
if (arg === "--help" || arg === "-h") {
|
|
386
|
+
printAuditUsage();
|
|
387
|
+
process.exit(0);
|
|
388
|
+
} else if (arg === "--process" || arg === "-p") {
|
|
389
|
+
i++;
|
|
390
|
+
processName = args[i] ?? "";
|
|
391
|
+
i++;
|
|
392
|
+
} else if (arg === "--pid-file") {
|
|
393
|
+
i++;
|
|
394
|
+
pidFile = args[i];
|
|
395
|
+
i++;
|
|
396
|
+
} else if (arg === "--workers-file") {
|
|
397
|
+
i++;
|
|
398
|
+
workersFile = args[i];
|
|
399
|
+
i++;
|
|
400
|
+
} else if (arg === "--systemd") {
|
|
401
|
+
i++;
|
|
402
|
+
systemdUnit = args[i];
|
|
403
|
+
i++;
|
|
404
|
+
} else if (arg === "--no-systemd") {
|
|
405
|
+
systemdUnit = null;
|
|
406
|
+
i++;
|
|
407
|
+
} else if (!arg.startsWith("-")) {
|
|
408
|
+
discoverDirs.push(resolve2(arg));
|
|
409
|
+
i++;
|
|
410
|
+
} else {
|
|
411
|
+
i++;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (!processName && !pidFile && !workersFile && discoverDirs.length > 0) {
|
|
415
|
+
const discovered = discoverProcessConfig(discoverDirs);
|
|
416
|
+
if (discovered) {
|
|
417
|
+
console.log(`Auto-discovered: process="${discovered.processName}"${discovered.pidFile ? ` pid-file=${discovered.pidFile}` : ""}${discovered.workersFile ? ` workers=${discovered.workersFile}` : ""}`);
|
|
418
|
+
return { ...discovered, systemdUnit };
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (!processName) {
|
|
422
|
+
console.error("Error: --process <name> is required, or provide directories for auto-discovery.");
|
|
423
|
+
console.error("Examples:");
|
|
424
|
+
console.error(" agentflow audit --process alfred --pid-file ./data/alfred.pid");
|
|
425
|
+
console.error(" agentflow audit ./data # auto-discovers *.pid and workers.json");
|
|
426
|
+
process.exit(1);
|
|
427
|
+
}
|
|
428
|
+
return { processName, pidFile, workersFile, systemdUnit };
|
|
429
|
+
}
|
|
430
|
+
function printAuditUsage() {
|
|
431
|
+
console.log(
|
|
432
|
+
`
|
|
433
|
+
AgentFlow Audit \u2014 OS-level process health check for agent systems.
|
|
434
|
+
|
|
435
|
+
Detects stale PID files, orphan processes, systemd crash loops, and
|
|
436
|
+
mismatches between declared state and actual OS process state.
|
|
437
|
+
|
|
438
|
+
Usage:
|
|
439
|
+
agentflow audit [dir...] [options]
|
|
440
|
+
agentflow audit --process <name> [options]
|
|
441
|
+
|
|
442
|
+
Arguments:
|
|
443
|
+
dir Directories to scan for auto-discovery of *.pid and workers.json
|
|
444
|
+
|
|
445
|
+
Options:
|
|
446
|
+
-p, --process <name> Process name to search for (e.g. "alfred", "myagent")
|
|
447
|
+
--pid-file <path> Path to PID file
|
|
448
|
+
--workers-file <path> Path to workers.json or process registry
|
|
449
|
+
--systemd <unit> Systemd user unit name (e.g. "alfred.service")
|
|
450
|
+
--no-systemd Skip systemd checks
|
|
451
|
+
-h, --help Show this help message
|
|
452
|
+
|
|
453
|
+
Examples:
|
|
454
|
+
agentflow audit ./data # auto-discover from data directory
|
|
455
|
+
agentflow audit --process alfred --systemd alfred.service
|
|
456
|
+
agentflow audit --process myagent --pid-file /var/run/myagent.pid --workers-file ./workers.json
|
|
457
|
+
agentflow audit --process crewai --no-systemd
|
|
458
|
+
`.trim()
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
function runAudit(argv) {
|
|
462
|
+
const config = parseAuditArgs(argv);
|
|
463
|
+
const result = auditProcesses(config);
|
|
464
|
+
console.log(formatAuditReport(result));
|
|
465
|
+
process.exit(result.problems.length > 0 ? 1 : 0);
|
|
466
|
+
}
|
|
370
467
|
async function main() {
|
|
371
468
|
const argv = process.argv.slice(2);
|
|
372
|
-
const knownCommands = ["run", "live", "watch", "trace"];
|
|
469
|
+
const knownCommands = ["run", "live", "watch", "trace", "audit"];
|
|
373
470
|
if (argv.length === 0 || !knownCommands.includes(argv[0]) && (argv.includes("--help") || argv.includes("-h"))) {
|
|
374
471
|
printHelp();
|
|
375
472
|
process.exit(0);
|
|
@@ -388,6 +485,9 @@ async function main() {
|
|
|
388
485
|
case "trace":
|
|
389
486
|
await handleTrace(argv);
|
|
390
487
|
break;
|
|
488
|
+
case "audit":
|
|
489
|
+
runAudit(argv);
|
|
490
|
+
break;
|
|
391
491
|
default:
|
|
392
492
|
if (!subcommand?.startsWith("-")) {
|
|
393
493
|
startLive(["live", ...argv]);
|