@drakonkat/ai-helper 1.2.17 → 1.2.19
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/ARCHITECTURE.md +21 -4
- package/CHANGELOG.md +28 -0
- package/README.md +131 -40
- package/package.json +5 -4
- package/src/config.js +12 -12
- package/src/health.js +81 -0
- package/src/hindsight.js +285 -0
- package/src/index.js +34 -14
- package/src/manager.js +350 -9
- package/src/proxy.js +10 -0
- package/src/startup-services.js +5 -2
- package/src/tui-proxy-setup.js +81 -9
- package/src/tui.js +155 -93
- package/src/utils/metrics.js +3 -3
- package/src/utils/process.js +7 -65
- package/src/utils/versions.js +16 -3
package/src/utils/process.js
CHANGED
|
@@ -244,61 +244,26 @@ export function spawnDetachedProcess(command, logFilePath, options) {
|
|
|
244
244
|
return { pid: proc.pid };
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
// agentmemory binds a quartet derived from one anchor port N:
|
|
248
|
-
// REST N | streams N+1 | viewer N+2 | engine N+46023
|
|
249
|
-
const AGENTMEMORY_ENGINE_OFFSET = 46023;
|
|
250
|
-
const AGENTMEMORY_VIEWER_OFFSET = 2;
|
|
251
|
-
const AGENTMEMORY_DEFAULT_VIEWER = 3113;
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Resolves the agentmemory viewer port from the ports a process is listening on.
|
|
255
|
-
* The engine port is the one that binds 0.0.0.0 and is usually discovered first,
|
|
256
|
-
* but the only browsable dashboard is the viewer, so derive it from the anchor.
|
|
257
|
-
* @param {number[]} ports
|
|
258
|
-
* @param {number[]} [viewerPorts] Ports owned by the Node viewer, not the iii engine.
|
|
259
|
-
* @returns {number}
|
|
260
|
-
*/
|
|
261
|
-
export function resolveAgentmemoryViewerPort(ports, viewerPorts = []) {
|
|
262
|
-
// The Node viewer and iii engine can own different parts of the port quartet.
|
|
263
|
-
const visibleViewerPorts = [...new Set(viewerPorts.filter(p => Number.isFinite(p) && p > 0))];
|
|
264
|
-
if (visibleViewerPorts.length === 1) return visibleViewerPorts[0];
|
|
265
|
-
const candidates = (ports || []).filter(p => Number.isFinite(p) && p > 0);
|
|
266
|
-
if (candidates.length === 0) return AGENTMEMORY_DEFAULT_VIEWER;
|
|
267
|
-
|
|
268
|
-
// The engine port is the most reliable marker: it is the only one above the
|
|
269
|
-
// offset and always anchor + 46023, so it recovers the anchor by itself. This
|
|
270
|
-
// matters because the engine binds 0.0.0.0 while the rest of the quartet is
|
|
271
|
-
// loopback-only, so the engine is sometimes the only port we get to see.
|
|
272
|
-
const engine = candidates.find(p => p > AGENTMEMORY_ENGINE_OFFSET);
|
|
273
|
-
if (engine) return engine - AGENTMEMORY_ENGINE_OFFSET + AGENTMEMORY_VIEWER_OFFSET;
|
|
274
|
-
|
|
275
|
-
// Otherwise the lowest port is the REST anchor: REST is always bound, so the
|
|
276
|
-
// smallest one we can see is the base of the quartet.
|
|
277
|
-
return Math.min(...candidates) + AGENTMEMORY_VIEWER_OFFSET;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
247
|
/** Resolve services from one Windows process/port snapshot, including child workers. */
|
|
248
|
+
// Hindsight runs in Docker and is tracked by container state, never by host processes:
|
|
249
|
+
// on Windows its published ports belong to Docker Desktop itself.
|
|
281
250
|
export function discoverWindowsProcesses(data, { knownServices = {}, currentPid = process.pid, isRunning = isPidRunning } = {}) {
|
|
282
251
|
const array = value => value ? (Array.isArray(value) ? value : [value]) : [];
|
|
283
252
|
const procs = array(data?.Procs).filter(p => p.ProcessId && p.ProcessId !== currentPid);
|
|
284
253
|
const ports = array(data?.Ports).filter(p => p.LocalPort > 0 && p.OwningProcess > 0);
|
|
285
|
-
const byPid = new Map(procs.map(p => [p.ProcessId, p]));
|
|
286
254
|
const children = new Map();
|
|
287
255
|
const ownedPorts = new Map();
|
|
288
256
|
for (const p of procs) children.set(p.ParentProcessId, [...(children.get(p.ParentProcessId) || []), p]);
|
|
289
257
|
for (const p of ports) ownedPorts.set(p.OwningProcess, [...(ownedPorts.get(p.OwningProcess) || []), p]);
|
|
290
|
-
const runtime = p => /^(node|bun|python[\d.]*|headroom|ocx|
|
|
291
|
-
const engine = p => /^iii(?:\.exe)?$/i.test(p.Name || "");
|
|
258
|
+
const runtime = p => /^(node|bun|python[\d.]*|headroom|ocx|cmd|powershell|pwsh)(\.exe)?$/i.test(p.Name || "");
|
|
292
259
|
|
|
293
260
|
function serviceOf(p) {
|
|
294
261
|
if (!runtime(p)) return;
|
|
295
262
|
const cmd = (p.CommandLine || "").replace(/\\/g, "/").toLowerCase();
|
|
296
263
|
// Do not exclude every bin/cli.js: pxpipe's real daemon uses that filename too.
|
|
297
264
|
if (/aih_gpt_launcher|get-ciminstance|where-object|(?:ai-helper|\.aih)\/(?:bin\/cli|src\/index)\.js/.test(cmd)) return;
|
|
298
|
-
if (/agentmemory-mcp|@agentmemory\/mcp|\bagentmemory\s+mcp\b|cli\.mjs["']?\s+mcp\b/.test(cmd)) return;
|
|
299
265
|
if (cmd.includes("pxpipe-proxy")) return "pxpipe";
|
|
300
266
|
if (cmd.includes("ocx.mjs") || (cmd.includes("opencodex") && !cmd.includes(".ps1")) || /\bocx(?:\.exe)?["']?\s+start\b/.test(cmd)) return "ocx";
|
|
301
|
-
if (engine(p) || /@agentmemory\/agentmemory|agentmemory\/dist\/cli\.mjs|iii-config\.yaml/.test(cmd)) return "agentmemory";
|
|
302
267
|
if (/headroom(?:\.exe)?["']?\s+proxy\b/.test(cmd)) return "headroom";
|
|
303
268
|
}
|
|
304
269
|
|
|
@@ -311,12 +276,7 @@ export function discoverWindowsProcesses(data, { knownServices = {}, currentPid
|
|
|
311
276
|
id = Object.keys(knownServices).find(id => knownServices[id]?.pid === seed.ProcessId);
|
|
312
277
|
}
|
|
313
278
|
if (!id) continue;
|
|
314
|
-
|
|
315
|
-
if (id === "agentmemory" && engine(seed)) {
|
|
316
|
-
const parent = byPid.get(seed.ParentProcessId);
|
|
317
|
-
if (parent && /^(node|bun)(\.exe)?$/i.test(parent.Name || "") &&
|
|
318
|
-
(!parent.CommandLine || serviceOf(parent) === id)) root = parent;
|
|
319
|
-
}
|
|
279
|
+
const root = seed;
|
|
320
280
|
const family = new Map();
|
|
321
281
|
const pending = [root];
|
|
322
282
|
while (pending.length) {
|
|
@@ -328,16 +288,9 @@ export function discoverWindowsProcesses(data, { knownServices = {}, currentPid
|
|
|
328
288
|
const listeners = [...family.keys()].flatMap(pid => ownedPorts.get(pid) || []);
|
|
329
289
|
if (!listeners.length) continue; // Shells, editors and hooks are not running daemons.
|
|
330
290
|
const available = listeners.map(p => p.LocalPort);
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const viewerPorts = listeners.filter(p => /^(node|bun)(\.exe)?$/i.test(family.get(p.OwningProcess)?.Name || "")).map(p => p.LocalPort);
|
|
335
|
-
port = resolveAgentmemoryViewerPort(enginePorts.length ? enginePorts : available, viewerPorts);
|
|
336
|
-
} else {
|
|
337
|
-
const explicit = Number(seed.CommandLine?.match(/\s--port(?:=|\s+)(\d+)/i)?.[1]);
|
|
338
|
-
const defaults = { pxpipe: [47822, 47821], headroom: [8788, 8787], ocx: [10100] };
|
|
339
|
-
port = [explicit, ...(defaults[id] || []), ...available].find(p => available.includes(p));
|
|
340
|
-
}
|
|
291
|
+
const explicit = Number(seed.CommandLine?.match(/\s--port(?:=|\s+)(\d+)/i)?.[1]);
|
|
292
|
+
const defaults = { pxpipe: [47822, 47821], headroom: [8788, 8787], ocx: [10100] };
|
|
293
|
+
const port = [explicit, ...(defaults[id] || []), ...available].find(p => available.includes(p));
|
|
341
294
|
const owner = family.get((listeners.find(p => p.LocalPort === port) || listeners[0]).OwningProcess);
|
|
342
295
|
if (!isRunning(owner.ProcessId)) continue;
|
|
343
296
|
const rank = family.has(knownServices[id]?.pid) ? 1 : 0;
|
|
@@ -402,17 +355,6 @@ export async function discoverRunningProcesses({ knownServices = {} } = {}) {
|
|
|
402
355
|
if (!discovered.ocx) discovered.ocx = { pid, command: cmd, url: "http://localhost:10100" };
|
|
403
356
|
}
|
|
404
357
|
|
|
405
|
-
const isMcpShim = cmd.includes("agentmemory-mcp") || cmd.includes("@agentmemory/mcp") || cmd.includes("agentmemory mcp");
|
|
406
|
-
if (
|
|
407
|
-
!isMcpShim &&
|
|
408
|
-
(cmd.includes("@agentmemory/agentmemory") ||
|
|
409
|
-
cmd.includes("iii-config.yaml") ||
|
|
410
|
-
cmd.includes("iii") ||
|
|
411
|
-
(cmd.includes("agentmemory") && !cmd.includes("mcp")))
|
|
412
|
-
) {
|
|
413
|
-
if (!discovered.agentmemory) discovered.agentmemory = { pid, command: cmd, url: "http://localhost:3113" };
|
|
414
|
-
}
|
|
415
|
-
|
|
416
358
|
if (cmd.includes("headroom proxy") || (cmd.includes("headroom") && !cmd.includes("aih "))) {
|
|
417
359
|
if (!discovered.headroom) discovered.headroom = { pid, command: cmd, url: "http://localhost:8787/dashboard" };
|
|
418
360
|
}
|
package/src/utils/versions.js
CHANGED
|
@@ -2,7 +2,8 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import { readFile, realpath } from "node:fs/promises";
|
|
3
3
|
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
4
|
import { baseUrl, fetchJson } from "./metrics.js";
|
|
5
|
-
import { SERVICE_PACKAGES as PACKAGES } from "../config.js";
|
|
5
|
+
import { SERVICE_PACKAGES as PACKAGES, SERVICES } from "../config.js";
|
|
6
|
+
import { HINDSIGHT_RELEASES_URL } from "../hindsight.js";
|
|
6
7
|
import { refreshToolPath } from "./tool-path.js";
|
|
7
8
|
|
|
8
9
|
function parseVersion(value) {
|
|
@@ -136,10 +137,22 @@ export async function getServiceVersions(statuses, {
|
|
|
136
137
|
processCommands = getProcessCommands,
|
|
137
138
|
installedVersion = getInstalledVersion,
|
|
138
139
|
} = {}) {
|
|
140
|
+
const docker = (statuses || []).filter(status => SERVICES[status.id]?.runtime === "docker");
|
|
139
141
|
const services = (statuses || []).filter(status => PACKAGES[status.id]);
|
|
140
142
|
let commands;
|
|
141
143
|
const readCommands = () => commands ||= Promise.resolve().then(() => processCommands(services)).catch(() => ({}));
|
|
142
|
-
|
|
144
|
+
// Docker images: the running API reports its version; releases come from GitHub.
|
|
145
|
+
const dockerVersions = docker.map(async status => {
|
|
146
|
+
const [version, latestVersion] = await Promise.all([
|
|
147
|
+
status.status === "running" && baseUrl(status.apiUrl)
|
|
148
|
+
? request(`${baseUrl(status.apiUrl)}/health/live`, 2000).then(data => cleanVersion(data?.version)).catch(() => null)
|
|
149
|
+
: null,
|
|
150
|
+
request(HINDSIGHT_RELEASES_URL, 3000).then(data => cleanVersion(data?.tag_name)).catch(() => null),
|
|
151
|
+
]);
|
|
152
|
+
const comparison = compareVersions(version, latestVersion);
|
|
153
|
+
return [status.id, { version, latestVersion, updateAvailable: comparison === null ? null : comparison < 0 }];
|
|
154
|
+
});
|
|
155
|
+
return Object.fromEntries(await Promise.all([...dockerVersions, ...services.map(async status => {
|
|
143
156
|
const pkg = PACKAGES[status.id];
|
|
144
157
|
const latest = (async () => {
|
|
145
158
|
try {
|
|
@@ -164,5 +177,5 @@ export async function getServiceVersions(statuses, {
|
|
|
164
177
|
const [version, latestVersion] = await Promise.all([installed, latest]);
|
|
165
178
|
const comparison = compareVersions(version, latestVersion);
|
|
166
179
|
return [status.id, { version, latestVersion, updateAvailable: comparison === null ? null : comparison < 0 }];
|
|
167
|
-
})));
|
|
180
|
+
})]));
|
|
168
181
|
}
|