@drakonkat/ai-helper 1.2.15 → 1.2.17

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 CHANGED
@@ -4,6 +4,20 @@ All notable changes to **`ai-helper` (`aih`)** are documented in this file.
4
4
 
5
5
  ---
6
6
 
7
+ ## [1.2.17] - 2026-11-06
8
+
9
+ ### Fixed
10
+ - Windows: updating Headroom from the TUI or `aih update headroom` no longer fails with "`uv` was not found on PATH". aih now also looks for tools installed with `pip install --user` (`%APPDATA%\Python\Python3XX\Scripts`, and `~/Library/Python/3.X/bin` on macOS), where it bootstraps uv.
11
+
12
+ ---
13
+
14
+ ## [1.2.16] - 2026-10-28
15
+
16
+ ### Changed
17
+ - `aih update headroom` (and `aih headroom update`) now installs Headroom when it is missing, bootstrapping uv/Python via winget, Homebrew, apt-get or dnf as needed, instead of failing.
18
+
19
+ ---
20
+
7
21
  ## [1.2.15] - 2026-10-26
8
22
 
9
23
  ### Added
@@ -85,7 +99,7 @@ All notable changes to **`ai-helper` (`aih`)** are documented in this file.
85
99
 
86
100
  ---
87
101
 
88
- ## [Unreleased]
102
+ ## [1.2.16] - 2026-10-28
89
103
 
90
104
  ### Added
91
105
  - Explicit managed-service updates with `aih <service> update`, `aih update [services...]`, and the live dashboard's `u` shortcut. Includes clean JSON results, target validation, running-service restart/recovery, and version-cache invalidation; automatic checks remain read-only.
package/README.md CHANGED
@@ -321,8 +321,14 @@ not by updating the separate `pxpipe` service.
321
321
 
322
322
  The Node services use `npm install --global <package>@latest` (`pxpipe-proxy`,
323
323
  `@bitkyc08/opencodex`, `@agentmemory/agentmemory`), so npm must be available and
324
- its global installation directory writable and on PATH. Headroom uses its own
324
+ its global installation directory writable and on PATH. Headroom is updated with its own
325
325
  `headroom update --yes` command to respect the existing Python installation.
326
+ **If Headroom is not installed, the same command installs it** on the machine running aih:
327
+ with `uv tool install --python 3.12 "headroom-ai[proxy]"` when uv exists; otherwise uv is
328
+ bootstrapped through Python 3.10+ (`python -m pip install --user uv`), and Python itself is
329
+ installed first with winget (Windows), Homebrew (macOS) or apt-get/dnf (Linux, needs root or
330
+ passwordless sudo). Tool directories are added to aih's PATH for the run and the first launch
331
+ is warmed up before the version check; open a new terminal to get `headroom` on your shell PATH.
326
332
  Installer output is captured in `aih logs <service>` rather than mixed into
327
333
  JSON or the live dashboard. An explicitly updated npx service is launched with
328
334
  the verified package version so an older project dependency/cache cannot win.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drakonkat/ai-helper",
3
- "version": "1.2.15",
3
+ "version": "1.2.17",
4
4
  "description": "Zero-config background service manager, auto-discovery daemon & dashboard launcher for AI agent ecosystems (pxpipe, ocx, agentmemory, headroom)",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -40,7 +40,7 @@
40
40
  "postinstall": "node scripts/patch-pxpipe.js",
41
41
  "start": "node ./bin/cli.js",
42
42
  "dev": "node ./bin/cli.js",
43
- "test": "bun test test/aih.test.js test/metrics.test.js test/discovery.test.js test/tui-pipeline.test.js test/tui-versions.test.js test/versions.test.js test/repositories.test.js test/service-updates.test.js && node --test test/proxy-setup.test.js test/proxy.test.js test/pxpipe-performance.test.js test/codex-config.test.js test/codex-routing.test.js test/codex-manager.test.js test/benchmark-live.test.js test/benchmark-measurement.test.js test/benchmark-quality.test.js test/benchmark-report.test.js test/benchmark-runner.test.js test/benchmark-multimodal.test.js",
43
+ "test": "bun test test/aih.test.js test/metrics.test.js test/discovery.test.js test/tui-pipeline.test.js test/tui-versions.test.js test/versions.test.js test/repositories.test.js test/service-updates.test.js test/headroom-install.test.js && node --test test/proxy-setup.test.js test/proxy.test.js test/pxpipe-performance.test.js test/codex-config.test.js test/codex-routing.test.js test/codex-manager.test.js test/benchmark-live.test.js test/benchmark-measurement.test.js test/benchmark-quality.test.js test/benchmark-report.test.js test/benchmark-runner.test.js test/benchmark-multimodal.test.js",
44
44
  "bench:proxy": "node scripts/bench-proxy.js",
45
45
  "bench:models": "node scripts/bench-proxy.js --compare-models gpt-6-astra,anthropic/claude-fable-5-1 --formats responses",
46
46
  "test:benchmark": "node --test test/benchmark-live.test.js test/benchmark-measurement.test.js test/benchmark-quality.test.js test/benchmark-report.test.js test/benchmark-runner.test.js test/benchmark-multimodal.test.js",
package/src/manager.js CHANGED
@@ -112,7 +112,7 @@ export class ServiceManager {
112
112
  details.version = live.version;
113
113
  }
114
114
  return { ...details, success: true, updated, restarted: Boolean(started), codexConfig: started?.codexConfig,
115
- message: `'${serviceId}' updated to ${details.version}${started ? " and restarted" : " (left stopped)"}` };
115
+ message: `'${serviceId}' ${details.previousVersion == null ? "installed" : "updated"} to ${details.version}${started ? " and restarted" : " (left stopped)"}` };
116
116
  } catch (error) {
117
117
  const recovery = stopped ? await restart() : null;
118
118
  return { ...details, success: false, updated, restarted: Boolean(recovery?.success && !recovery.alreadyRunning), codexConfig: recovery?.codexConfig,
@@ -1,7 +1,21 @@
1
+
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
1
4
  import { SERVICE_PACKAGES, SERVICES } from "./config.js";
2
- import { compareVersions } from "./utils/versions.js";
5
+ import { compareVersions, runVersionCommand } from "./utils/versions.js";
6
+ import { refreshToolPath } from "./utils/tool-path.js";
7
+ export { refreshToolPath, toolSearchDirectories } from "./utils/tool-path.js";
3
8
  import { npmUpdateInvocation, runUpdateInstaller } from "./utils/update-installer.js";
4
9
 
10
+ /** pip requirement for a runnable Headroom proxy (the proxy dependencies are an extra). */
11
+ export const HEADROOM_REQUIREMENT = "headroom-ai[proxy]";
12
+ /**
13
+ * Headroom pulls native dependencies (e.g. zstandard) that lack wheels for very
14
+ * new Python releases, so it gets its own interpreter instead of the system one.
15
+ */
16
+ export const HEADROOM_PYTHON = "3.12";
17
+ const MIN_PYTHON_MINOR = 10;
18
+
5
19
  /** Only allowlisted services/arguments reach an installer; never execute user input. */
6
20
  export function serviceUpdateInvocation(id, platform = process.platform) {
7
21
  if (!Object.hasOwn(SERVICE_PACKAGES, id)) throw new Error(`Service '${id}' cannot be updated separately`);
@@ -23,6 +37,88 @@ export function serviceStartCommand(id, state) {
23
37
  }
24
38
 
25
39
  /** Capture installer output, keeping --json/TUI clean and full diagnostics in the service log. */
26
- export function installServiceUpdate(id, { spawnImpl, platform = process.platform } = {}) {
27
- return runUpdateInstaller(id, serviceUpdateInvocation(id, platform), { spawnImpl });
40
+ export function installServiceUpdate(id, options = {}) {
41
+ const { spawnImpl, platform = process.platform } = options;
42
+ // Validates the id synchronously, before anything can be spawned.
43
+ const invocation = serviceUpdateInvocation(id, platform);
44
+ if (!SERVICE_PACKAGES[id].pypi) return runUpdateInstaller(id, invocation, { spawnImpl });
45
+ return installHeadroom(id, invocation, options);
46
+ }
47
+
48
+ async function findPython(probe, platform) {
49
+ const candidates = platform === "win32" ? [["python"], ["py", "-3"]] : [["python3"], ["python"]];
50
+ for (const [command, ...prefix] of candidates) {
51
+ const match = (await probe(command, [...prefix, "--version"]))?.match(/^Python (\d+)\.(\d+)/);
52
+ // On Windows the Store "python" alias fails this check instead of opening the Store.
53
+ if (match && Number(match[1]) === 3 && Number(match[2]) >= MIN_PYTHON_MINOR) return { command, prefix };
54
+ }
55
+ return null;
56
+ }
57
+
58
+ /** Fixed package-manager invocation that installs Python, or null when none is usable. */
59
+ async function pythonInstallInvocation(platform, available) {
60
+ if (platform === "win32") {
61
+ return await available("winget") ? { command: "winget", args: ["install", "-e", "--id", "Python.Python.3.12",
62
+ "--scope", "user", "--silent", "--accept-package-agreements", "--accept-source-agreements"] } : null;
63
+ }
64
+ if (platform === "darwin") return await available("brew") ? { command: "brew", args: ["install", "python"] } : null;
65
+ const sudo = process.getuid?.() === 0 ? [] : ["sudo", "-n"];
66
+ const elevated = args => ({ command: [...sudo, ...args][0], args: [...sudo, ...args].slice(1) });
67
+ if (await available("apt-get")) return elevated(["apt-get", "install", "-y", "python3", "python3-pip", "python3-venv"]);
68
+ if (await available("dnf")) return elevated(["dnf", "install", "-y", "python3", "python3-pip"]);
69
+ return null;
70
+ }
71
+
72
+ /**
73
+ * Install or update Headroom on this machine. An existing installation is
74
+ * updated by Headroom itself; otherwise the missing prerequisites (Python,
75
+ * pipx/uv) are installed first. Never shells out with user-provided text.
76
+ */
77
+ async function installHeadroom(id, updateInvocation, { spawnImpl, platform = process.platform, probe = runVersionCommand, refreshPath = refreshToolPath } = {}) {
78
+ const run = (invocation, env) => runUpdateInstaller(id, invocation, { spawnImpl, env });
79
+ const available = async (command, args = ["--version"]) => (await probe(command, args, 5000)) !== null;
80
+ refreshPath();
81
+ // The first launch of a fresh Python install compiles bytecode and can take
82
+ // tens of seconds; warm it up so aih's short version probe does not time out.
83
+ const warmUp = async result => {
84
+ if (result.success) await probe("headroom", ["--version"], 180000);
85
+ return result;
86
+ };
87
+ if (await available("headroom")) return warmUp(await run(updateInvocation));
88
+
89
+ const failed = (message, last) => ({ success: false, exitCode: last?.exitCode ?? 1, logPath: last?.logPath, message });
90
+ const install = ["tool", "install", "--force", "--python", HEADROOM_PYTHON, HEADROOM_REQUIREMENT];
91
+ // uv links its managed Python with a junction. Under MSIX-packaged hosts (e.g. the Codex
92
+ // desktop app) %APPDATA% is virtualized and that junction dangles, so keep it in the real home.
93
+ const uvEnv = platform === "win32" && !process.env.UV_PYTHON_INSTALL_DIR
94
+ ? { UV_PYTHON_INSTALL_DIR: join(homedir(), ".local", "share", "uv", "python") } : undefined;
95
+ let steps;
96
+ if (await available("uv")) {
97
+ steps = [{ command: "uv", args: install, env: uvEnv }];
98
+ } else {
99
+ // uv installs and manages the right Python itself; the system Python is only used to bootstrap uv.
100
+ let python = await findPython(probe, platform);
101
+ if (!python) {
102
+ const pythonInstall = await pythonInstallInvocation(platform, available);
103
+ if (!pythonInstall) return failed("Python 3." + MIN_PYTHON_MINOR + "+ is required to install Headroom and no supported package manager was found (winget, brew, apt-get, dnf). Install Python or uv manually and retry.");
104
+ const installed = await run(pythonInstall);
105
+ if (!installed.success) return { ...installed, message: "Cannot install Python for 'headroom': " + installed.message };
106
+ refreshPath();
107
+ python = await findPython(probe, platform);
108
+ if (!python) return failed("Python was installed but is not visible to this process yet; open a new terminal and run the update again.", installed);
109
+ }
110
+ const py = [...python.prefix, "-m"];
111
+ steps = [
112
+ { command: python.command, args: [...py, "pip", "install", "--user", "--upgrade", "uv"], env: { PIP_BREAK_SYSTEM_PACKAGES: "1" } },
113
+ { command: python.command, args: [...py, "uv", ...install], env: uvEnv },
114
+ { command: python.command, args: [...py, "uv", "tool", "update-shell"] },
115
+ ];
116
+ }
117
+ let result = { success: true, exitCode: 0 };
118
+ for (const { env, ...invocation } of steps) {
119
+ result = await run(invocation, env);
120
+ if (!result.success) return { ...result, message: "Cannot install 'headroom': " + result.message };
121
+ }
122
+ refreshPath();
123
+ return warmUp(result);
28
124
  }
@@ -0,0 +1,41 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { delimiter, join } from "node:path";
4
+
5
+ /**
6
+ * Directories where user-level installers put executables. A freshly installed
7
+ * tool is not on this process's PATH yet, so verification and startup would miss it.
8
+ */
9
+ export function toolSearchDirectories({ platform = process.platform, env = process.env, home = homedir(), exists = existsSync, list = readdirSync } = {}) {
10
+ const dirs = [join(home, ".local", "bin")];
11
+ const versions = (root, pattern) => {
12
+ try {
13
+ return list(root).filter(name => pattern.test(name)).sort().reverse();
14
+ } catch { return []; }
15
+ };
16
+ const pythons = root => versions(root, /^Python3\d+$/i).flatMap(name => [join(root, name), join(root, name, "Scripts")]);
17
+ if (platform === "win32") {
18
+ if (env.LOCALAPPDATA) dirs.push(...pythons(join(env.LOCALAPPDATA, "Programs", "Python")));
19
+ if (env.ProgramFiles) dirs.push(...pythons(env.ProgramFiles));
20
+ // `pip install --user` (how aih bootstraps uv) puts scripts in %APPDATA%\Python\Python3XX\Scripts.
21
+ // Headroom's own updater runs `uv tool upgrade` and fails when uv is not found there.
22
+ if (env.APPDATA) dirs.push(...versions(join(env.APPDATA, "Python"), /^Python3\d+$/i).map(name => join(env.APPDATA, "Python", name, "Scripts")));
23
+ } else {
24
+ dirs.push("/opt/homebrew/bin", "/usr/local/bin");
25
+ // macOS framework builds put `pip install --user` scripts in ~/Library/Python/3.X/bin.
26
+ if (platform === "darwin") dirs.push(...versions(join(home, "Library", "Python"), /^3\.\d+$/).map(name => join(home, "Library", "Python", name, "bin")));
27
+ }
28
+ return dirs.filter(dir => exists(dir));
29
+ }
30
+
31
+ /** Append (never prepend) missing tool directories to this process's PATH. */
32
+ export function refreshToolPath(options = {}) {
33
+ const env = options.env || process.env;
34
+ const current = (env.PATH || env.Path || "").split(delimiter).filter(Boolean);
35
+ const same = (a, b) => (options.platform || process.platform) === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
36
+ const added = toolSearchDirectories({ ...options, env }).filter(dir => !current.some(entry => same(entry, dir)));
37
+ if (added.length) env.PATH = [...current, ...added].join(delimiter);
38
+ return added;
39
+ }
40
+
41
+
@@ -13,7 +13,7 @@ export function npmUpdateInvocation(packageName, platform = process.platform) {
13
13
  }
14
14
 
15
15
  /** Capture installer output, keeping --json/TUI clean and full diagnostics in the log. */
16
- export function runUpdateInstaller(id, { command, args }, { spawnImpl = spawn } = {}) {
16
+ export function runUpdateInstaller(id, { command, args }, { spawnImpl = spawn, env } = {}) {
17
17
  ensureDir(getLogsDir());
18
18
  const logPath = getServiceLogPath(id);
19
19
  const fd = openSync(logPath, "a");
@@ -37,7 +37,7 @@ export function runUpdateInstaller(id, { command, args }, { spawnImpl = spawn }
37
37
  try {
38
38
  const child = spawnImpl(command, args, {
39
39
  windowsHide: true, stdio: ["ignore", "pipe", "pipe"],
40
- env: { ...process.env, CI: "1", npm_config_yes: "true", PIP_NO_INPUT: "1", NO_COLOR: "1" },
40
+ env: { ...process.env, CI: "1", npm_config_yes: "true", PIP_NO_INPUT: "1", NO_COLOR: "1", ...env },
41
41
  });
42
42
  child.stdout?.on("data", collect);
43
43
  child.stderr?.on("data", collect);
@@ -3,6 +3,7 @@ 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
5
  import { SERVICE_PACKAGES as PACKAGES } from "../config.js";
6
+ import { refreshToolPath } from "./tool-path.js";
6
7
 
7
8
  function parseVersion(value) {
8
9
  if (typeof value !== "string") return null;
@@ -94,6 +95,8 @@ export async function readNpmVersionFromCommand(command, name) {
94
95
  async function getInstalledVersion(status, command) {
95
96
  const pkg = PACKAGES[status.id];
96
97
  if (pkg.pypi) {
98
+ // User-level installers (uv/pipx) put the binary where this process may not look yet.
99
+ refreshToolPath();
97
100
  // Headroom's Click CLI explicitly implements --version without starting a proxy.
98
101
  const output = await runVersionCommand("headroom", ["--version"]);
99
102
  return cleanVersion(output?.match(/^headroom, version\s+(\S+)$/im)?.[1]);