@drakonkat/ai-helper 1.0.0 → 1.0.4
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/CHANGELOG.md +28 -8
- package/package.json +11 -4
- package/src/config.js +6 -2
- package/src/manager.js +73 -42
- package/src/utils/process.js +84 -40
package/CHANGELOG.md
CHANGED
|
@@ -4,19 +4,39 @@ All notable changes to **`ai-helper` (`aih`)** are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
## [1.0.4] - 2026-08-27
|
|
8
|
+
|
|
9
|
+
### 🐛 Bug Fixes
|
|
10
|
+
- **Self Process CLI Exclusion**: Exclude current CLI process (`process.pid`) and `aih` CLI command patterns from OS process auto-discovery, preventing false-positive "already running" statuses during `aih start <service>`.
|
|
11
|
+
- **Precise Process Matching**: Refine `pxpipe-proxy` matching patterns so general CLI arguments are not mistaken for the active service daemon.
|
|
12
|
+
- **Post-Start Verification**: Verify actual service liveness after the startup grace period in `startService`, reporting startup failures accurately instead of declaring dead processes as running.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## [1.0.2] - 2026-08-19
|
|
17
|
+
|
|
18
|
+
### 🐛 Bug Fixes
|
|
19
|
+
- **Auto-Discovery Fix**: Strictly exclude `agentmemory-mcp` / `@agentmemory/mcp` client shims from matching the `agentmemory` daemon server, ensuring the background web server (`http://localhost:3113`) is launched properly on `aih start`.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## [1.0.1] - 2026-08-19
|
|
24
|
+
|
|
25
|
+
### 🔧 Improvements & Fixes
|
|
26
|
+
- **Scoped Package Deployment**: Published under the `@drakonkat/ai-helper` npm scope for instant `npx` execution.
|
|
27
|
+
- **Enhanced Process Auto-Discovery**: Optimized WMI/CIM process query performance on Windows.
|
|
28
|
+
- **Documentation & CI**: Added complete GitHub community templates, architecture guides, and CI workflows.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
7
32
|
## [1.0.0] - 2026-08-19
|
|
8
33
|
|
|
9
34
|
### 🚀 Initial Release
|
|
10
|
-
- **Managed Services**: Support for background lifecycle management of
|
|
11
|
-
|
|
12
|
-
- `ocx` (`ocx start`)
|
|
13
|
-
- `agentmemory` (`npx @agentmemory/agentmemory`)
|
|
14
|
-
- **Auto-Discovery Engine**: Detects running service instances started from external terminal windows via OS process table queries (`Win32_Process` and `ps`).
|
|
35
|
+
- **Managed Services**: Support for background lifecycle management of `pxpipe`, `ocx`, and `agentmemory`.
|
|
36
|
+
- **Auto-Discovery Engine**: Detects running service instances started from external terminal windows via OS process table queries.
|
|
15
37
|
- **TCP Port & Dashboard Mapping**: Dynamically detects listening web ports and exposes clickable dashboard URLs.
|
|
16
38
|
- **One-Click Browser Dashboard Launcher**: Added `aih open [service]` to launch active dashboards directly in the user's default browser.
|
|
17
39
|
- **Safe Process Tree Termination**: Tree-killing on Windows via `taskkill /pid <PID> /T /F` and process group termination on Unix.
|
|
18
40
|
- **Unified Live Log Streaming**: Real-time log capture and streaming with `aih logs <service> -f`.
|
|
19
41
|
- **Programmatic JSON API**: Added `--json` flag for IDE, agent, and pipeline integration.
|
|
20
|
-
- **Cross-Runtime & NPX Ready**: Universal Node.js (>=18) and Bun support
|
|
21
|
-
- **Standalone Binary Compilation**: Optional compilation to standalone `aih.exe` via `bun run install-bin`.
|
|
22
|
-
|
|
42
|
+
- **Cross-Runtime & NPX Ready**: Universal Node.js (>=18) and Bun support.
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drakonkat/ai-helper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Zero-config background service manager, auto-discovery daemon & dashboard launcher for AI agent ecosystems (pxpipe, ocx, agentmemory)",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|
|
9
|
-
"aih": "
|
|
10
|
-
"ai-helper": "
|
|
9
|
+
"aih": "bin/cli.js",
|
|
10
|
+
"ai-helper": "bin/cli.js"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"bin",
|
|
@@ -23,6 +23,14 @@
|
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/drakonkat/ai-helper.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/drakonkat/ai-helper/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/drakonkat/ai-helper#readme",
|
|
26
34
|
"scripts": {
|
|
27
35
|
"start": "node ./bin/cli.js",
|
|
28
36
|
"dev": "node ./bin/cli.js",
|
|
@@ -46,4 +54,3 @@
|
|
|
46
54
|
"author": "Mauro",
|
|
47
55
|
"license": "MIT"
|
|
48
56
|
}
|
|
49
|
-
|
package/src/config.js
CHANGED
|
@@ -12,22 +12,27 @@ export const SERVICES = {
|
|
|
12
12
|
description: "AI LLM / MCP reverse proxy bridge (pxpipe-proxy)",
|
|
13
13
|
defaultPort: 47821,
|
|
14
14
|
defaultUrl: "http://localhost:47821",
|
|
15
|
+
ports: [47821],
|
|
15
16
|
},
|
|
16
17
|
ocx: {
|
|
17
18
|
id: "ocx",
|
|
18
19
|
name: "ocx",
|
|
19
20
|
command: "ocx start",
|
|
21
|
+
stopCommand: "ocx stop",
|
|
20
22
|
description: "OpenCode Interpreter daemon service (ocx start)",
|
|
21
23
|
defaultPort: 10100,
|
|
22
24
|
defaultUrl: "http://localhost:10100",
|
|
25
|
+
ports: [10100],
|
|
23
26
|
},
|
|
24
27
|
agentmemory: {
|
|
25
28
|
id: "agentmemory",
|
|
26
29
|
name: "agentmemory",
|
|
27
30
|
command: "npx @agentmemory/agentmemory",
|
|
31
|
+
stopCommand: "npx @agentmemory/agentmemory stop --force",
|
|
28
32
|
description: "Long-term persistent agent memory service (@agentmemory/agentmemory)",
|
|
29
33
|
defaultPort: 3113,
|
|
30
34
|
defaultUrl: "http://localhost:3113",
|
|
35
|
+
ports: [3111, 3112, 3113, 49134],
|
|
31
36
|
},
|
|
32
37
|
};
|
|
33
38
|
|
|
@@ -35,5 +40,4 @@ export const SERVICE_IDS = Object.keys(SERVICES);
|
|
|
35
40
|
|
|
36
41
|
export const APP_NAME = "ai-helper";
|
|
37
42
|
export const CLI_NAME = "aih";
|
|
38
|
-
export const VERSION = "1.0.
|
|
39
|
-
|
|
43
|
+
export const VERSION = "1.0.4";
|
package/src/manager.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync, statSync, openSync, readSync, closeSync } from "node:fs";
|
|
2
2
|
import { SERVICES, SERVICE_IDS } from "./config.js";
|
|
3
3
|
import { ensureDir, getAihDir, getLogsDir, getServiceLogPath, getStateFilePath } from "./utils/path.js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isPidRunning,
|
|
6
|
+
killProcessTree,
|
|
7
|
+
spawnDetachedProcess,
|
|
8
|
+
discoverRunningProcesses,
|
|
9
|
+
openBrowser,
|
|
10
|
+
sleep,
|
|
11
|
+
execCommand,
|
|
12
|
+
findPidsListeningOnPorts,
|
|
13
|
+
} from "./utils/process.js";
|
|
5
14
|
import { formatBytes, formatUptime, gray, red, yellow, green, cyan } from "./utils/format.js";
|
|
6
15
|
|
|
7
16
|
export class ServiceManager {
|
|
@@ -48,35 +57,39 @@ export class ServiceManager {
|
|
|
48
57
|
const state = this.readState();
|
|
49
58
|
let needsSave = false;
|
|
50
59
|
|
|
51
|
-
//
|
|
52
|
-
for (const id of Object.keys(state.services)) {
|
|
53
|
-
const svc = state.services[id];
|
|
54
|
-
if (svc.status === "running") {
|
|
55
|
-
if (!svc.pid || !isPidRunning(svc.pid)) {
|
|
56
|
-
svc.status = "stopped";
|
|
57
|
-
svc.pid = undefined;
|
|
58
|
-
svc.startedAt = undefined;
|
|
59
|
-
needsSave = true;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 2. Discover externally started processes
|
|
60
|
+
// Discover active verified daemon processes from OS
|
|
65
61
|
const discovered = await discoverRunningProcesses();
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
|
|
63
|
+
for (const id of SERVICE_IDS) {
|
|
68
64
|
const svc = state.services[id];
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const info = discovered[id];
|
|
66
|
+
|
|
67
|
+
if (info && info.pid && isPidRunning(info.pid)) {
|
|
68
|
+
// Confirmed active service daemon discovered in OS
|
|
69
|
+
if (svc.status !== "running" || svc.pid !== info.pid) {
|
|
71
70
|
svc.status = "running";
|
|
72
71
|
svc.pid = info.pid;
|
|
73
|
-
svc.startedAt = info.startedAt || new Date().toISOString();
|
|
72
|
+
svc.startedAt = info.startedAt || svc.startedAt || new Date().toISOString();
|
|
74
73
|
svc.url = info.url || SERVICES[id]?.defaultUrl;
|
|
75
74
|
needsSave = true;
|
|
76
75
|
} else if (info.url && svc.url !== info.url) {
|
|
77
76
|
svc.url = info.url;
|
|
78
77
|
needsSave = true;
|
|
79
78
|
}
|
|
79
|
+
} else if (svc.status === "running" && svc.pid && isPidRunning(svc.pid)) {
|
|
80
|
+
// Process spawned by aih is still actively running in background
|
|
81
|
+
if (!svc.url) {
|
|
82
|
+
svc.url = SERVICES[id]?.defaultUrl;
|
|
83
|
+
needsSave = true;
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
// Not running and not discovered
|
|
87
|
+
if (svc.status === "running" || svc.pid !== undefined) {
|
|
88
|
+
svc.status = "stopped";
|
|
89
|
+
svc.pid = undefined;
|
|
90
|
+
svc.startedAt = undefined;
|
|
91
|
+
needsSave = true;
|
|
92
|
+
}
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
|
|
@@ -221,28 +234,28 @@ export class ServiceManager {
|
|
|
221
234
|
startedAt: new Date().toISOString(),
|
|
222
235
|
url: def.defaultUrl,
|
|
223
236
|
};
|
|
224
|
-
|
|
237
|
+
this.saveState(state);
|
|
225
238
|
|
|
226
|
-
|
|
239
|
+
// Wait a moment for background boot
|
|
240
|
+
await sleep(2000);
|
|
227
241
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
state.services[serviceId].lastError = "Process exited immediately after spawn";
|
|
232
|
-
this.saveState(state);
|
|
242
|
+
// Re-sync with OS
|
|
243
|
+
const updatedState = await this.syncState();
|
|
244
|
+
const updatedSvc = updatedState.services[serviceId];
|
|
233
245
|
|
|
246
|
+
if (!updatedSvc || updatedSvc.status !== "running" || !updatedSvc.pid || !isPidRunning(updatedSvc.pid)) {
|
|
234
247
|
return {
|
|
235
248
|
success: false,
|
|
236
|
-
message: `Service '${serviceId}' exited immediately. Check logs with 'aih logs ${serviceId}'`,
|
|
249
|
+
message: `Service '${serviceId}' failed to start or exited immediately. Check logs with 'aih logs ${serviceId}'`,
|
|
237
250
|
pid,
|
|
238
251
|
};
|
|
239
252
|
}
|
|
240
253
|
|
|
241
254
|
return {
|
|
242
255
|
success: true,
|
|
243
|
-
message: `Service '${serviceId}' started successfully (PID: ${pid})`,
|
|
244
|
-
pid,
|
|
245
|
-
url: def.defaultUrl,
|
|
256
|
+
message: `Service '${serviceId}' started successfully (PID: ${updatedSvc.pid})`,
|
|
257
|
+
pid: updatedSvc.pid,
|
|
258
|
+
url: updatedSvc.url || def.defaultUrl,
|
|
246
259
|
};
|
|
247
260
|
}
|
|
248
261
|
|
|
@@ -261,29 +274,48 @@ export class ServiceManager {
|
|
|
261
274
|
}
|
|
262
275
|
|
|
263
276
|
/**
|
|
264
|
-
* Stops a single service
|
|
277
|
+
* Stops a single service cleanly, executing stop commands and clearing ports/workers.
|
|
265
278
|
*/
|
|
266
279
|
async stopService(serviceId) {
|
|
280
|
+
const def = SERVICES[serviceId];
|
|
267
281
|
const state = await this.syncState();
|
|
268
282
|
const current = state.services[serviceId];
|
|
269
283
|
|
|
270
|
-
|
|
271
|
-
|
|
284
|
+
// 1. If service has a dedicated graceful stopCommand, run it
|
|
285
|
+
if (def?.stopCommand) {
|
|
286
|
+
const isWin = process.platform === "win32";
|
|
287
|
+
if (isWin) {
|
|
288
|
+
await execCommand("cmd.exe", ["/c", def.stopCommand]);
|
|
289
|
+
} else {
|
|
290
|
+
await execCommand("sh", ["-c", def.stopCommand]);
|
|
291
|
+
}
|
|
292
|
+
await sleep(400);
|
|
272
293
|
}
|
|
273
294
|
|
|
274
|
-
|
|
275
|
-
|
|
295
|
+
// 2. Kill recorded process tree if still active
|
|
296
|
+
if (current && current.pid && isPidRunning(current.pid)) {
|
|
297
|
+
await killProcessTree(current.pid);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 3. Clean up any remaining processes holding the service's ports
|
|
301
|
+
if (def?.ports && def.ports.length > 0) {
|
|
302
|
+
const portPids = await findPidsListeningOnPorts(def.ports);
|
|
303
|
+
for (const p of portPids) {
|
|
304
|
+
if (isPidRunning(p)) {
|
|
305
|
+
await killProcessTree(p);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
276
309
|
|
|
310
|
+
// 4. Update state to stopped
|
|
277
311
|
state.services[serviceId].status = "stopped";
|
|
278
312
|
state.services[serviceId].pid = undefined;
|
|
279
313
|
state.services[serviceId].startedAt = undefined;
|
|
280
314
|
this.saveState(state);
|
|
281
315
|
|
|
282
316
|
return {
|
|
283
|
-
success:
|
|
284
|
-
message:
|
|
285
|
-
? `Service '${serviceId}' stopped (PID: ${pidToKill})`
|
|
286
|
-
: `Failed to stop service '${serviceId}': ${killResult.message}`,
|
|
317
|
+
success: true,
|
|
318
|
+
message: `Service '${serviceId}' stopped cleanly`,
|
|
287
319
|
};
|
|
288
320
|
}
|
|
289
321
|
|
|
@@ -306,7 +338,7 @@ export class ServiceManager {
|
|
|
306
338
|
*/
|
|
307
339
|
async restartService(serviceId) {
|
|
308
340
|
await this.stopService(serviceId);
|
|
309
|
-
await sleep(
|
|
341
|
+
await sleep(600);
|
|
310
342
|
return await this.startService(serviceId);
|
|
311
343
|
}
|
|
312
344
|
|
|
@@ -377,4 +409,3 @@ export class ServiceManager {
|
|
|
377
409
|
}
|
|
378
410
|
|
|
379
411
|
export const manager = new ServiceManager();
|
|
380
|
-
|
package/src/utils/process.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { openSync,
|
|
2
|
+
import { openSync, appendFileSync } from "node:fs";
|
|
3
3
|
import { ensureDir, getLogsDir } from "./path.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -94,6 +94,46 @@ export function openBrowser(url) {
|
|
|
94
94
|
} catch {}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Finds PIDs of processes currently listening on the specified TCP ports.
|
|
99
|
+
* @param {number[]} ports
|
|
100
|
+
* @returns {Promise<number[]>}
|
|
101
|
+
*/
|
|
102
|
+
export async function findPidsListeningOnPorts(ports) {
|
|
103
|
+
if (!ports || ports.length === 0) return [];
|
|
104
|
+
const matchedPids = new Set();
|
|
105
|
+
|
|
106
|
+
if (process.platform === "win32") {
|
|
107
|
+
try {
|
|
108
|
+
const portList = ports.join(", ");
|
|
109
|
+
const script = `Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue | Where-Object { $_.LocalPort -in ${portList} } | Select-Object -ExpandProperty OwningProcess`;
|
|
110
|
+
const res = await execCommand("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script]);
|
|
111
|
+
const lines = res.stdout.trim().split(/\r?\n/);
|
|
112
|
+
for (const line of lines) {
|
|
113
|
+
const pid = parseInt(line.trim(), 10);
|
|
114
|
+
if (pid && !isNaN(pid) && pid > 0) {
|
|
115
|
+
matchedPids.add(pid);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} catch {}
|
|
119
|
+
} else {
|
|
120
|
+
try {
|
|
121
|
+
for (const port of ports) {
|
|
122
|
+
const res = await execCommand("lsof", ["-t", `-i:${port}`, "-sTCP:LISTEN"]);
|
|
123
|
+
const lines = res.stdout.trim().split(/\r?\n/);
|
|
124
|
+
for (const line of lines) {
|
|
125
|
+
const pid = parseInt(line.trim(), 10);
|
|
126
|
+
if (pid && !isNaN(pid) && pid > 0) {
|
|
127
|
+
matchedPids.add(pid);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch {}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return Array.from(matchedPids);
|
|
135
|
+
}
|
|
136
|
+
|
|
97
137
|
/**
|
|
98
138
|
* Kills a process and its entire child process tree.
|
|
99
139
|
* @param {number} pid
|
|
@@ -181,28 +221,16 @@ export function spawnDetachedProcess(command, logFilePath, options) {
|
|
|
181
221
|
|
|
182
222
|
const fd = openSync(logFilePath, "a");
|
|
183
223
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
193
|
-
} else {
|
|
194
|
-
proc = spawn("sh", ["-c", command], {
|
|
195
|
-
detached: true,
|
|
196
|
-
stdio: ["ignore", fd, fd],
|
|
197
|
-
env: { ...process.env, ...options?.env },
|
|
198
|
-
cwd: options?.cwd,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
224
|
+
const proc = spawn(command, [], {
|
|
225
|
+
shell: true,
|
|
226
|
+
detached: true,
|
|
227
|
+
stdio: ["ignore", fd, fd],
|
|
228
|
+
env: { ...process.env, ...options?.env },
|
|
229
|
+
cwd: options?.cwd,
|
|
230
|
+
windowsHide: true,
|
|
231
|
+
});
|
|
201
232
|
|
|
202
233
|
proc.unref();
|
|
203
|
-
try {
|
|
204
|
-
closeSync(fd);
|
|
205
|
-
} catch {}
|
|
206
234
|
|
|
207
235
|
return { pid: proc.pid };
|
|
208
236
|
}
|
|
@@ -213,14 +241,16 @@ export function spawnDetachedProcess(command, logFilePath, options) {
|
|
|
213
241
|
*/
|
|
214
242
|
export async function discoverRunningProcesses() {
|
|
215
243
|
const discovered = {};
|
|
244
|
+
const currentPid = process.pid;
|
|
216
245
|
|
|
217
246
|
if (process.platform === "win32") {
|
|
218
247
|
try {
|
|
219
248
|
const script = `
|
|
220
249
|
$procs = Get-CimInstance Win32_Process | Where-Object {
|
|
250
|
+
$_.ProcessId -ne ${currentPid} -and
|
|
221
251
|
$_.CommandLine -and
|
|
222
|
-
($_.CommandLine -match 'pxpipe|ocx|agentmemory|iii') -and
|
|
223
|
-
($_.CommandLine -notmatch 'ai-helper|Get-CimInstance|Where-Object|Select-Object')
|
|
252
|
+
($_.CommandLine -match 'pxpipe-proxy|ocx|agentmemory|iii') -and
|
|
253
|
+
($_.CommandLine -notmatch 'ai-helper|\\baih(\\.exe)?\\b|bin\\\\cli\\.js|Get-CimInstance|Where-Object|Select-Object')
|
|
224
254
|
} | Select-Object ProcessId, ParentProcessId, Name, CommandLine, CreationDate
|
|
225
255
|
|
|
226
256
|
$ports = Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue | Select-Object LocalPort, OwningProcess
|
|
@@ -252,7 +282,12 @@ export async function discoverRunningProcesses() {
|
|
|
252
282
|
for (const item of procList) {
|
|
253
283
|
const cmd = item.CommandLine || "";
|
|
254
284
|
const pid = item.ProcessId;
|
|
255
|
-
if (!pid || !isPidRunning(pid)) continue;
|
|
285
|
+
if (!pid || pid === currentPid || !isPidRunning(pid)) continue;
|
|
286
|
+
|
|
287
|
+
// Skip any ai-helper / aih CLI executions
|
|
288
|
+
if (cmd.includes("bin/cli.js") || cmd.includes("bin\\cli.js") || /\baih(\.exe)?\b/i.test(cmd)) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
256
291
|
|
|
257
292
|
let startedAt;
|
|
258
293
|
if (item.CreationDate) {
|
|
@@ -270,7 +305,7 @@ export async function discoverRunningProcesses() {
|
|
|
270
305
|
const ports = pidToPorts[pid] || [];
|
|
271
306
|
|
|
272
307
|
// 1. pxpipe
|
|
273
|
-
if (cmd.includes("pxpipe-proxy")
|
|
308
|
+
if (cmd.includes("pxpipe-proxy")) {
|
|
274
309
|
if (!discovered.pxpipe || (item.Name && item.Name.toLowerCase() === "node.exe" && cmd.includes("cli.js"))) {
|
|
275
310
|
const webPort = ports.find(p => p > 1000 && p < 65000) || (discovered.pxpipe?.port);
|
|
276
311
|
discovered.pxpipe = {
|
|
@@ -284,7 +319,7 @@ export async function discoverRunningProcesses() {
|
|
|
284
319
|
}
|
|
285
320
|
|
|
286
321
|
// 2. ocx
|
|
287
|
-
if (cmd.includes("ocx.mjs") || cmd.includes("opencodex") || cmd.includes("ocx start")) {
|
|
322
|
+
if (cmd.includes("ocx.mjs") || cmd.includes("opencodex") || (cmd.includes("ocx start") && !cmd.includes("aih "))) {
|
|
288
323
|
const webPort = ports.find(p => p === 10100 || (p > 1000 && p < 65000));
|
|
289
324
|
if (!discovered.ocx || cmd.includes("ocx.mjs start")) {
|
|
290
325
|
discovered.ocx = {
|
|
@@ -297,16 +332,20 @@ export async function discoverRunningProcesses() {
|
|
|
297
332
|
}
|
|
298
333
|
}
|
|
299
334
|
|
|
300
|
-
// 3. agentmemory
|
|
335
|
+
// 3. agentmemory (daemon / iii-engine only, strictly exclude MCP stdio shims)
|
|
336
|
+
const isMcpShim = cmd.includes("agentmemory-mcp") || cmd.includes("@agentmemory/mcp") || cmd.includes("agentmemory mcp");
|
|
337
|
+
|
|
301
338
|
if (
|
|
302
|
-
|
|
303
|
-
cmd.includes("agentmemory
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
339
|
+
!isMcpShim &&
|
|
340
|
+
(cmd.includes("@agentmemory/agentmemory") ||
|
|
341
|
+
cmd.includes("agentmemory\\dist\\cli.mjs") ||
|
|
342
|
+
cmd.includes("agentmemory/dist/cli.mjs") ||
|
|
343
|
+
cmd.includes("iii-config.yaml") ||
|
|
344
|
+
cmd.includes("iii.exe") ||
|
|
345
|
+
(cmd.includes("agentmemory") && !cmd.includes("mcp") && !cmd.includes("aih ")))
|
|
307
346
|
) {
|
|
308
347
|
const webPort = ports.find(p => p === 3113 || p === 43210 || (p > 1000 && p < 65000));
|
|
309
|
-
if (!discovered.agentmemory || cmd.includes("agentmemory/agentmemory")) {
|
|
348
|
+
if (!discovered.agentmemory || cmd.includes("agentmemory/agentmemory") || cmd.includes("dist\\cli.mjs")) {
|
|
310
349
|
discovered.agentmemory = {
|
|
311
350
|
pid,
|
|
312
351
|
command: cmd,
|
|
@@ -340,23 +379,29 @@ export async function discoverRunningProcesses() {
|
|
|
340
379
|
|
|
341
380
|
for (const line of lines) {
|
|
342
381
|
const trimmed = line.trim();
|
|
343
|
-
if (!trimmed || trimmed.includes("ps -eo") || trimmed.includes("ai-helper")) continue;
|
|
382
|
+
if (!trimmed || trimmed.includes("ps -eo") || trimmed.includes("ai-helper") || /\baih\b/.test(trimmed)) continue;
|
|
344
383
|
|
|
345
384
|
const parts = trimmed.split(/\s+/);
|
|
346
385
|
const pid = parseInt(parts[0], 10);
|
|
347
386
|
const cmd = parts.slice(1).join(" ");
|
|
348
|
-
if (!pid || !isPidRunning(pid)) continue;
|
|
387
|
+
if (!pid || pid === currentPid || !isPidRunning(pid)) continue;
|
|
388
|
+
|
|
389
|
+
if (cmd.includes("bin/cli.js") || cmd.includes("bin/aih")) continue;
|
|
349
390
|
|
|
350
|
-
if (cmd.includes("pxpipe-proxy")
|
|
391
|
+
if (cmd.includes("pxpipe-proxy")) {
|
|
351
392
|
if (!discovered.pxpipe) discovered.pxpipe = { pid, command: cmd, url: "http://localhost:47821" };
|
|
352
393
|
}
|
|
353
394
|
if (cmd.includes("ocx start") || cmd.includes("ocx.mjs") || cmd.includes("opencodex")) {
|
|
354
395
|
if (!discovered.ocx) discovered.ocx = { pid, command: cmd, url: "http://localhost:10100" };
|
|
355
396
|
}
|
|
397
|
+
|
|
398
|
+
const isMcpShim = cmd.includes("agentmemory-mcp") || cmd.includes("@agentmemory/mcp") || cmd.includes("agentmemory mcp");
|
|
356
399
|
if (
|
|
357
|
-
|
|
358
|
-
cmd.includes("
|
|
359
|
-
|
|
400
|
+
!isMcpShim &&
|
|
401
|
+
(cmd.includes("@agentmemory/agentmemory") ||
|
|
402
|
+
cmd.includes("iii-config.yaml") ||
|
|
403
|
+
cmd.includes("iii") ||
|
|
404
|
+
(cmd.includes("agentmemory") && !cmd.includes("mcp")))
|
|
360
405
|
) {
|
|
361
406
|
if (!discovered.agentmemory) discovered.agentmemory = { pid, command: cmd, url: "http://localhost:3113" };
|
|
362
407
|
}
|
|
@@ -366,4 +411,3 @@ export async function discoverRunningProcesses() {
|
|
|
366
411
|
|
|
367
412
|
return discovered;
|
|
368
413
|
}
|
|
369
|
-
|