bgrun 3.3.3 → 3.4.0

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.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * GET /api/debug — Debug info about BGR internals
3
+ *
4
+ * Returns DB path, BGR home dir, platform info for diagnostics.
5
+ */
6
+ import { getDbInfo } from 'bgrun';
7
+
8
+ export async function GET() {
9
+ const info = getDbInfo();
10
+ return Response.json({
11
+ ...info,
12
+ platform: process.platform,
13
+ bun: Bun.version,
14
+ pid: process.pid,
15
+ cwd: process.cwd(),
16
+ });
17
+ }
@@ -5,7 +5,7 @@
5
5
  * instead of per-process calls to avoid subprocess pile-up on Windows.
6
6
  * Results are cached for 5 seconds via globalThis.
7
7
  */
8
- import { getAllProcesses, calculateRuntime } from 'bgrun';
8
+ import { getAllProcesses, calculateRuntime, getProcessBatchMemory, getDbInfo } from 'bgrun';
9
9
  import { $ } from 'bun';
10
10
 
11
11
  const CACHE_TTL_MS = 5_000;
@@ -97,19 +97,33 @@ async function getPortsByPid(pids: number[]): Promise<Map<number, number[]>> {
97
97
  return portMap;
98
98
  }
99
99
 
100
+ // Parse environment string to find BGR_GROUP
101
+ function getProcessGroup(envStr: string): string | null {
102
+ if (!envStr) return null;
103
+ // Env is usually "KEY=VAL,KEY2=VAL2"
104
+ const match = envStr.match(/(?:^|,)BGR_GROUP=([^,]+)/);
105
+ return match ? match[1] : null;
106
+ }
107
+
108
+ // ... existing code ...
109
+
100
110
  async function fetchProcesses(): Promise<any[]> {
101
111
  const procs = getAllProcesses();
102
112
  const pids = procs.map((p: any) => p.pid);
103
113
 
104
- // Two subprocess calls total (not 2×N)
105
- const [runningPids, portMap] = await Promise.all([
114
+ // Three subprocess calls total (not 3×N)
115
+ const [runningPids, portMap, memoryMap] = await Promise.all([
106
116
  withTimeout(getRunningPids(pids), new Set<number>()),
107
117
  withTimeout(getPortsByPid(pids), new Map<number, number[]>()),
118
+ // Use the new batch memory fetcher
119
+ withTimeout(getProcessBatchMemory(pids), new Map<number, number>()),
108
120
  ]);
109
121
 
110
122
  return procs.map((p: any) => {
111
123
  const running = runningPids.has(p.pid);
112
124
  const ports = running ? (portMap.get(p.pid) || []) : [];
125
+ const memory = running ? (memoryMap.get(p.pid) || 0) : 0;
126
+
113
127
  return {
114
128
  name: p.name,
115
129
  command: p.command,
@@ -118,6 +132,8 @@ async function fetchProcesses(): Promise<any[]> {
118
132
  running,
119
133
  port: ports.length > 0 ? ports[0] : null,
120
134
  ports,
135
+ memory, // Bytes
136
+ group: getProcessGroup(p.env),
121
137
  runtime: calculateRuntime(p.timestamp),
122
138
  timestamp: p.timestamp,
123
139
  };