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/index.d.cts CHANGED
@@ -494,6 +494,114 @@ declare function withGuards(builder: GraphBuilder, config?: GuardConfig): GraphB
494
494
 
495
495
  declare function startLive(argv: string[]): void;
496
496
 
497
+ /**
498
+ * AgentFlow Process Audit — OS-level process health checks for agent systems.
499
+ *
500
+ * Detects stale PID files, orphan processes, systemd unit issues,
501
+ * and mismatches between declared state (PID files, workers.json)
502
+ * and actual OS process state.
503
+ *
504
+ * Linux-only (reads /proc). Returns structured results for programmatic
505
+ * use or terminal display.
506
+ *
507
+ * @module
508
+ */
509
+ interface PidFileResult {
510
+ path: string;
511
+ pid: number | null;
512
+ alive: boolean;
513
+ /** Whether /proc/<pid>/cmdline contains the expected process name. */
514
+ matchesProcess: boolean;
515
+ stale: boolean;
516
+ reason: string;
517
+ }
518
+ interface SystemdUnitResult {
519
+ unit: string;
520
+ activeState: string;
521
+ subState: string;
522
+ mainPid: number;
523
+ restarts: number;
524
+ result: string;
525
+ crashLooping: boolean;
526
+ failed: boolean;
527
+ }
528
+ interface WorkerEntry {
529
+ name: string;
530
+ pid: number | null;
531
+ declaredStatus: string;
532
+ alive: boolean;
533
+ stale: boolean;
534
+ }
535
+ interface WorkersResult {
536
+ orchestratorPid: number | null;
537
+ orchestratorAlive: boolean;
538
+ startedAt: string;
539
+ workers: WorkerEntry[];
540
+ }
541
+ interface OsProcess {
542
+ pid: number;
543
+ cpu: string;
544
+ mem: string;
545
+ command: string;
546
+ }
547
+ interface ProcessAuditResult {
548
+ pidFile: PidFileResult | null;
549
+ systemd: SystemdUnitResult | null;
550
+ workers: WorkersResult | null;
551
+ osProcesses: OsProcess[];
552
+ orphans: OsProcess[];
553
+ problems: string[];
554
+ }
555
+ interface ProcessAuditConfig {
556
+ /** Path to the PID file (e.g. /home/user/.myapp/data/app.pid). */
557
+ pidFile?: string;
558
+ /** Path to workers.json or equivalent process registry. */
559
+ workersFile?: string;
560
+ /** Systemd unit name (e.g. "myapp.service"). Use `null` to skip. */
561
+ systemdUnit?: string | null;
562
+ /** Process name to match in `pgrep -a` and /proc/cmdline (e.g. "alfred", "myagent"). */
563
+ processName: string;
564
+ }
565
+ /**
566
+ * Scan directories for PID files (`*.pid`), worker registries (`workers.json`,
567
+ * `*-workers.json`), and infer a process name from the PID file name.
568
+ *
569
+ * Returns a config suitable for `auditProcesses()`, or null if nothing found.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * const config = discoverProcessConfig(['./data', '/var/run/myagent']);
574
+ * if (config) console.log(formatAuditReport(auditProcesses(config)));
575
+ * ```
576
+ */
577
+ declare function discoverProcessConfig(dirs: string[]): ProcessAuditConfig | null;
578
+ /**
579
+ * Run a full process health audit.
580
+ *
581
+ * Checks PID files, systemd units, worker registries, and OS process tables
582
+ * to detect stale processes, orphans, and state mismatches.
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * import { auditProcesses, formatAuditReport } from 'agentflow-core';
587
+ *
588
+ * const result = auditProcesses({
589
+ * processName: 'alfred',
590
+ * pidFile: '/home/user/.alfred/data/alfred.pid',
591
+ * workersFile: '/home/user/.alfred/data/workers.json',
592
+ * systemdUnit: 'alfred.service',
593
+ * });
594
+ *
595
+ * console.log(formatAuditReport(result));
596
+ * ```
597
+ */
598
+ declare function auditProcesses(config: ProcessAuditConfig): ProcessAuditResult;
599
+ /**
600
+ * Format an audit result as a human-readable terminal report.
601
+ * Uses Unicode box-drawing characters and status icons.
602
+ */
603
+ declare function formatAuditReport(result: ProcessAuditResult): string;
604
+
497
605
  /**
498
606
  * Load and deserialize execution graphs from JSON.
499
607
  *
@@ -743,4 +851,4 @@ interface AlertPayload {
743
851
  readonly dirs: readonly string[];
744
852
  }
745
853
 
746
- export { type Adapter, type AgentFlowConfig, type AlertCondition, type AlertPayload, type DistributedTrace, type EdgeType, type ExecutionEdge, type ExecutionGraph, type ExecutionNode, type GraphBuilder, type GraphStats, type GraphStatus, type GuardConfig, type GuardViolation, type MutableExecutionNode, type NodeStatus, type NodeType, type NotifyChannel, type RunConfig, type RunResult, type StartNodeOptions, type TraceEvent, type TraceEventType, type TraceStore, type WatchConfig, type Writer, checkGuards, createGraphBuilder, createTraceStore, findWaitingOn, getChildren, getCriticalPath, getDepth, getDuration, getFailures, getHungNodes, getNode, getParent, getStats, getSubtree, getTraceTree, graphToJson, groupByTraceId, loadGraph, runTraced, startLive, startWatch, stitchTrace, toAsciiTree, toTimeline, withGuards };
854
+ export { type Adapter, type AgentFlowConfig, type AlertCondition, type AlertPayload, type DistributedTrace, type EdgeType, type ExecutionEdge, type ExecutionGraph, type ExecutionNode, type GraphBuilder, type GraphStats, type GraphStatus, type GuardConfig, type GuardViolation, type MutableExecutionNode, type NodeStatus, type NodeType, type NotifyChannel, type OsProcess, type PidFileResult, type ProcessAuditConfig, type ProcessAuditResult, type RunConfig, type RunResult, type StartNodeOptions, type SystemdUnitResult, type TraceEvent, type TraceEventType, type TraceStore, type WatchConfig, type WorkerEntry, type WorkersResult, type Writer, auditProcesses, checkGuards, createGraphBuilder, createTraceStore, discoverProcessConfig, findWaitingOn, formatAuditReport, getChildren, getCriticalPath, getDepth, getDuration, getFailures, getHungNodes, getNode, getParent, getStats, getSubtree, getTraceTree, graphToJson, groupByTraceId, loadGraph, runTraced, startLive, startWatch, stitchTrace, toAsciiTree, toTimeline, withGuards };
package/dist/index.d.ts CHANGED
@@ -494,6 +494,114 @@ declare function withGuards(builder: GraphBuilder, config?: GuardConfig): GraphB
494
494
 
495
495
  declare function startLive(argv: string[]): void;
496
496
 
497
+ /**
498
+ * AgentFlow Process Audit — OS-level process health checks for agent systems.
499
+ *
500
+ * Detects stale PID files, orphan processes, systemd unit issues,
501
+ * and mismatches between declared state (PID files, workers.json)
502
+ * and actual OS process state.
503
+ *
504
+ * Linux-only (reads /proc). Returns structured results for programmatic
505
+ * use or terminal display.
506
+ *
507
+ * @module
508
+ */
509
+ interface PidFileResult {
510
+ path: string;
511
+ pid: number | null;
512
+ alive: boolean;
513
+ /** Whether /proc/<pid>/cmdline contains the expected process name. */
514
+ matchesProcess: boolean;
515
+ stale: boolean;
516
+ reason: string;
517
+ }
518
+ interface SystemdUnitResult {
519
+ unit: string;
520
+ activeState: string;
521
+ subState: string;
522
+ mainPid: number;
523
+ restarts: number;
524
+ result: string;
525
+ crashLooping: boolean;
526
+ failed: boolean;
527
+ }
528
+ interface WorkerEntry {
529
+ name: string;
530
+ pid: number | null;
531
+ declaredStatus: string;
532
+ alive: boolean;
533
+ stale: boolean;
534
+ }
535
+ interface WorkersResult {
536
+ orchestratorPid: number | null;
537
+ orchestratorAlive: boolean;
538
+ startedAt: string;
539
+ workers: WorkerEntry[];
540
+ }
541
+ interface OsProcess {
542
+ pid: number;
543
+ cpu: string;
544
+ mem: string;
545
+ command: string;
546
+ }
547
+ interface ProcessAuditResult {
548
+ pidFile: PidFileResult | null;
549
+ systemd: SystemdUnitResult | null;
550
+ workers: WorkersResult | null;
551
+ osProcesses: OsProcess[];
552
+ orphans: OsProcess[];
553
+ problems: string[];
554
+ }
555
+ interface ProcessAuditConfig {
556
+ /** Path to the PID file (e.g. /home/user/.myapp/data/app.pid). */
557
+ pidFile?: string;
558
+ /** Path to workers.json or equivalent process registry. */
559
+ workersFile?: string;
560
+ /** Systemd unit name (e.g. "myapp.service"). Use `null` to skip. */
561
+ systemdUnit?: string | null;
562
+ /** Process name to match in `pgrep -a` and /proc/cmdline (e.g. "alfred", "myagent"). */
563
+ processName: string;
564
+ }
565
+ /**
566
+ * Scan directories for PID files (`*.pid`), worker registries (`workers.json`,
567
+ * `*-workers.json`), and infer a process name from the PID file name.
568
+ *
569
+ * Returns a config suitable for `auditProcesses()`, or null if nothing found.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * const config = discoverProcessConfig(['./data', '/var/run/myagent']);
574
+ * if (config) console.log(formatAuditReport(auditProcesses(config)));
575
+ * ```
576
+ */
577
+ declare function discoverProcessConfig(dirs: string[]): ProcessAuditConfig | null;
578
+ /**
579
+ * Run a full process health audit.
580
+ *
581
+ * Checks PID files, systemd units, worker registries, and OS process tables
582
+ * to detect stale processes, orphans, and state mismatches.
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * import { auditProcesses, formatAuditReport } from 'agentflow-core';
587
+ *
588
+ * const result = auditProcesses({
589
+ * processName: 'alfred',
590
+ * pidFile: '/home/user/.alfred/data/alfred.pid',
591
+ * workersFile: '/home/user/.alfred/data/workers.json',
592
+ * systemdUnit: 'alfred.service',
593
+ * });
594
+ *
595
+ * console.log(formatAuditReport(result));
596
+ * ```
597
+ */
598
+ declare function auditProcesses(config: ProcessAuditConfig): ProcessAuditResult;
599
+ /**
600
+ * Format an audit result as a human-readable terminal report.
601
+ * Uses Unicode box-drawing characters and status icons.
602
+ */
603
+ declare function formatAuditReport(result: ProcessAuditResult): string;
604
+
497
605
  /**
498
606
  * Load and deserialize execution graphs from JSON.
499
607
  *
@@ -743,4 +851,4 @@ interface AlertPayload {
743
851
  readonly dirs: readonly string[];
744
852
  }
745
853
 
746
- export { type Adapter, type AgentFlowConfig, type AlertCondition, type AlertPayload, type DistributedTrace, type EdgeType, type ExecutionEdge, type ExecutionGraph, type ExecutionNode, type GraphBuilder, type GraphStats, type GraphStatus, type GuardConfig, type GuardViolation, type MutableExecutionNode, type NodeStatus, type NodeType, type NotifyChannel, type RunConfig, type RunResult, type StartNodeOptions, type TraceEvent, type TraceEventType, type TraceStore, type WatchConfig, type Writer, checkGuards, createGraphBuilder, createTraceStore, findWaitingOn, getChildren, getCriticalPath, getDepth, getDuration, getFailures, getHungNodes, getNode, getParent, getStats, getSubtree, getTraceTree, graphToJson, groupByTraceId, loadGraph, runTraced, startLive, startWatch, stitchTrace, toAsciiTree, toTimeline, withGuards };
854
+ export { type Adapter, type AgentFlowConfig, type AlertCondition, type AlertPayload, type DistributedTrace, type EdgeType, type ExecutionEdge, type ExecutionGraph, type ExecutionNode, type GraphBuilder, type GraphStats, type GraphStatus, type GuardConfig, type GuardViolation, type MutableExecutionNode, type NodeStatus, type NodeType, type NotifyChannel, type OsProcess, type PidFileResult, type ProcessAuditConfig, type ProcessAuditResult, type RunConfig, type RunResult, type StartNodeOptions, type SystemdUnitResult, type TraceEvent, type TraceEventType, type TraceStore, type WatchConfig, type WorkerEntry, type WorkersResult, type Writer, auditProcesses, checkGuards, createGraphBuilder, createTraceStore, discoverProcessConfig, findWaitingOn, formatAuditReport, getChildren, getCriticalPath, getDepth, getDuration, getFailures, getHungNodes, getNode, getParent, getStats, getSubtree, getTraceTree, graphToJson, groupByTraceId, loadGraph, runTraced, startLive, startWatch, stitchTrace, toAsciiTree, toTimeline, withGuards };
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import {
2
+ auditProcesses,
2
3
  createGraphBuilder,
3
4
  createTraceStore,
5
+ discoverProcessConfig,
4
6
  findWaitingOn,
7
+ formatAuditReport,
5
8
  getChildren,
6
9
  getCriticalPath,
7
10
  getDepth,
@@ -20,7 +23,7 @@ import {
20
23
  stitchTrace,
21
24
  toAsciiTree,
22
25
  toTimeline
23
- } from "./chunk-YTMQBL3T.js";
26
+ } from "./chunk-BOSYI5YM.js";
24
27
  import {
25
28
  graphToJson,
26
29
  loadGraph
@@ -184,10 +187,13 @@ function withGuards(builder, config) {
184
187
  };
185
188
  }
186
189
  export {
190
+ auditProcesses,
187
191
  checkGuards,
188
192
  createGraphBuilder,
189
193
  createTraceStore,
194
+ discoverProcessConfig,
190
195
  findWaitingOn,
196
+ formatAuditReport,
191
197
  getChildren,
192
198
  getCriticalPath,
193
199
  getDepth,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agentflow-core",
3
- "version": "0.5.2",
4
- "description": "Monitor any AI agent system. Auto-detects failures, sends alerts. Zero config, zero dependencies.",
3
+ "version": "0.6.1",
4
+ "description": "Monitor any AI agent system. Auto-detects failures, sends alerts, audits OS processes. Zero config, zero dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -37,7 +37,11 @@
37
37
  "autogen",
38
38
  "cron",
39
39
  "watchdog",
40
- "health-check"
40
+ "health-check",
41
+ "process-audit",
42
+ "pid",
43
+ "orphan-detection",
44
+ "systemd"
41
45
  ],
42
46
  "license": "MIT",
43
47
  "repository": {