@leavewhite9088/harness-bus 0.2.0 → 0.2.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/ARCHITECTURE.md +81 -81
- package/LICENSE +21 -21
- package/README.md +86 -86
- package/SETUP_FOR_AI.md +79 -79
- package/package.json +4 -2
- package/packages/agentd/agentd.config.json +3 -1
- package/packages/agentd/cli/commands.mjs +854 -810
- package/packages/agentd/cli/format.mjs +294 -238
- package/packages/agentd/cli/hbus.mjs +14 -14
- package/packages/agentd/cli/index.mjs +4 -4
- package/packages/agentd/cli/skill/SKILL.md +66 -61
- package/packages/agentd/cli/skill/references/custom.md +12 -0
- package/packages/agentd/cli/skill/references/playbooks.md +89 -86
- package/packages/agentd/cli/skill/references/routing.md +43 -35
- package/packages/agentd/cli/skill-install.mjs +157 -140
- package/packages/agentd/cli/update.mjs +221 -221
- package/packages/agentd/client/index.mjs +3 -3
- package/packages/agentd/contexts/executor.md +13 -12
- package/packages/agentd/contexts/templates/architect.md +12 -12
- package/packages/agentd/contexts/templates/coder.md +12 -12
- package/packages/agentd/contexts/templates/debugger.md +12 -12
- package/packages/agentd/contexts/templates/researcher.md +12 -12
- package/packages/agentd/contexts/templates/reviewer.md +12 -12
- package/packages/agentd/contexts/templates/tester.md +12 -12
- package/packages/agentd/core/base/data-dir.mjs +39 -39
- package/packages/agentd/core/base/index.mjs +5 -5
- package/packages/agentd/core/base/protocol.mjs +13 -13
- package/packages/agentd/core/env/config.mjs +52 -1
- package/packages/agentd/core/env/index.mjs +6 -1
- package/packages/agentd/core/env/install.mjs +82 -4
- package/packages/agentd/core/pi/index.mjs +1 -1
- package/packages/agentd/core/pi/rpc.mjs +206 -206
- package/packages/agentd/core/pool/acp/client.mjs +7 -9
- package/packages/agentd/core/pool/acp/process.mjs +27 -18
- package/packages/agentd/core/pool/acp/run-tracker.mjs +293 -293
- package/packages/agentd/core/pool/acp/sessions.mjs +465 -465
- package/packages/agentd/core/pool/acp/turn-runner.mjs +5 -3
- package/packages/agentd/core/pool/index.mjs +2 -2
- package/packages/agentd/core/pool/instances.mjs +3 -5
- package/packages/agentd/core/pool/probe.mjs +91 -85
- package/packages/agentd/core/pool/registry.mjs +45 -1
- package/packages/agentd/core/pool/support/compaction.mjs +2 -43
- package/packages/agentd/core/pool/support/index.mjs +1 -1
- package/packages/agentd/core/prompts/index.mjs +12 -12
- package/packages/agentd/core/prompts/rules.mjs +22 -22
- package/packages/agentd/core/prompts/templates.mjs +172 -172
- package/packages/agentd/core/providers/index.mjs +14 -14
- package/packages/agentd/core/providers/store.mjs +206 -206
- package/packages/agentd/core/records/cleanup.mjs +51 -51
- package/packages/agentd/core/records/index.mjs +8 -8
- package/packages/agentd/core/records/metrics.mjs +73 -73
- package/packages/agentd/core/records/recovery.mjs +39 -39
- package/packages/agentd/core/records/transcripts.mjs +122 -122
- package/packages/agentd/core/threads/index.mjs +18 -17
- package/packages/agentd/core/threads/manager.mjs +498 -476
- package/packages/agentd/core/threads/paths.mjs +78 -78
- package/packages/agentd/core/threads/store.mjs +146 -125
- package/packages/agentd/daemon/agentd.mjs +58 -58
- package/packages/agentd/daemon/events.mjs +126 -126
- package/packages/agentd/daemon/guard.mjs +127 -127
- package/packages/agentd/daemon/lifecycle.mjs +61 -61
- package/packages/agentd/daemon/ops/index.mjs +15 -15
- package/packages/agentd/daemon/ops/providers.mjs +46 -46
- package/packages/agentd/daemon/ops/run.mjs +413 -400
- package/packages/agentd/daemon/ops/system.mjs +76 -69
- package/packages/agentd/daemon/ops/threads.mjs +156 -153
- package/packages/agentd/daemon/server.mjs +130 -130
- package/packages/agentd/package.json +1 -1
- package/packages/agentd/pi-adapter/acp-adapter.mjs +501 -501
- package/packages/agentd/scripts/restart-daemon.mjs +74 -74
- package/packages/agentd/scripts/run-isolated.mjs +42 -42
- package/packages/agentd/scripts/run-unit.mjs +28 -28
- package/packages/backend/src/daemon.mjs +69 -69
- package/packages/backend/src/server.mjs +270 -270
- package/packages/drivers/{agy.mjs → agy/index.mjs} +2 -1
- package/packages/drivers/{claude.mjs → claude/index.mjs} +23 -1
- package/packages/drivers/{codex.mjs → codex/index.mjs} +2 -1
- package/packages/drivers/{dsh.mjs → dsh/index.mjs} +3 -2
- package/packages/drivers/grok/index.mjs +96 -0
- package/packages/drivers/index.mjs +25 -12
- package/packages/drivers/{kimi.mjs → kimi/index.mjs} +2 -1
- package/packages/drivers/{mcode.mjs → mcode/index.mjs} +2 -1
- package/packages/drivers/{opencode.mjs → opencode/index.mjs} +2 -1
- package/packages/drivers/{pi.mjs → pi/index.mjs} +3 -2
- package/packages/drivers/probes/acp.mjs +109 -109
- package/packages/drivers/probes/index.mjs +131 -129
- package/packages/drivers/probes/provider.mjs +222 -222
- package/packages/drivers/qoder/index.mjs +32 -0
- package/packages/drivers/{bin.mjs → shared/bin.mjs} +2 -0
- package/packages/drivers/shared/index.mjs +2 -0
- package/packages/preflight/bin/preflight.mjs +116 -116
- package/packages/preflight/src/index.mjs +5 -5
- package/packages/preflight/src/report.mjs +18 -1
- package/packages/web/dist/apple-touch-icon.png +0 -0
- package/packages/web/dist/assets/index-CT8dIwav.css +2 -0
- package/packages/web/dist/assets/index-CypTUMFB.js +79 -0
- package/packages/web/dist/favicon-32.png +0 -0
- package/packages/web/dist/favicon.svg +19 -15
- package/packages/web/dist/index.html +5 -5
- package/packages/web/dist/assets/index-B2kdkHNw.js +0 -79
- package/packages/web/dist/assets/index-DQTyjC4x.css +0 -2
- /package/packages/drivers/{dsh-sessions.mjs → dsh/sessions.mjs} +0 -0
- /package/packages/drivers/{pi-catalog.mjs → pi/catalog.mjs} +0 -0
- /package/packages/drivers/{lib.mjs → shared/lib.mjs} +0 -0
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { mkdirSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { join, resolve } from 'node:path';
|
|
4
|
-
|
|
5
|
-
export const DATA_DIR = process.env.AGENTD_DATA_DIR ? resolve(process.env.AGENTD_DATA_DIR) : join(homedir(), '.harness-bus');
|
|
6
|
-
export const GLOBAL_DIR = join(DATA_DIR, 'global');
|
|
7
|
-
export const PROJECTS_DIR = join(DATA_DIR, 'projects');
|
|
8
|
-
export const WORKSPACES_DIR = join(DATA_DIR, 'workspaces');
|
|
9
|
-
|
|
10
|
-
export const PROJECT_SEP = '~';
|
|
11
|
-
|
|
12
|
-
const safe = (s) => {
|
|
13
|
-
const t = String(s).replace(/[^\w.@-]/g, '_');
|
|
14
|
-
return t === '.' || t === '..' || t === '' ? '_' : t;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const projectIdOf = (name) => String(name).split(PROJECT_SEP)[0];
|
|
18
|
-
|
|
19
|
-
export const instanceIdOf = (name) => {
|
|
20
|
-
const s = String(name);
|
|
21
|
-
const i = s.indexOf(PROJECT_SEP);
|
|
22
|
-
return i < 0 ? s : s.slice(i + PROJECT_SEP.length);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const projectDir = (project) => join(PROJECTS_DIR, safe(project));
|
|
26
|
-
|
|
27
|
-
export function projectPath(name, ...parts) {
|
|
28
|
-
return join(projectDir(projectIdOf(name)), ...parts);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function projectIdsOnDisk() {
|
|
32
|
-
try {
|
|
33
|
-
return readdirSync(PROJECTS_DIR).filter((n) => statSync(join(PROJECTS_DIR, n)).isDirectory());
|
|
34
|
-
} catch {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const ensureDir = (dir) => mkdirSync(dir, { recursive: true });
|
|
1
|
+
import { mkdirSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
export const DATA_DIR = process.env.AGENTD_DATA_DIR ? resolve(process.env.AGENTD_DATA_DIR) : join(homedir(), '.harness-bus');
|
|
6
|
+
export const GLOBAL_DIR = join(DATA_DIR, 'global');
|
|
7
|
+
export const PROJECTS_DIR = join(DATA_DIR, 'projects');
|
|
8
|
+
export const WORKSPACES_DIR = join(DATA_DIR, 'workspaces');
|
|
9
|
+
|
|
10
|
+
export const PROJECT_SEP = '~';
|
|
11
|
+
|
|
12
|
+
const safe = (s) => {
|
|
13
|
+
const t = String(s).replace(/[^\w.@-]/g, '_');
|
|
14
|
+
return t === '.' || t === '..' || t === '' ? '_' : t;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const projectIdOf = (name) => String(name).split(PROJECT_SEP)[0];
|
|
18
|
+
|
|
19
|
+
export const instanceIdOf = (name) => {
|
|
20
|
+
const s = String(name);
|
|
21
|
+
const i = s.indexOf(PROJECT_SEP);
|
|
22
|
+
return i < 0 ? s : s.slice(i + PROJECT_SEP.length);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const projectDir = (project) => join(PROJECTS_DIR, safe(project));
|
|
26
|
+
|
|
27
|
+
export function projectPath(name, ...parts) {
|
|
28
|
+
return join(projectDir(projectIdOf(name)), ...parts);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function projectIdsOnDisk() {
|
|
32
|
+
try {
|
|
33
|
+
return readdirSync(PROJECTS_DIR).filter((n) => statSync(join(PROJECTS_DIR, n)).isDirectory());
|
|
34
|
+
} catch {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const ensureDir = (dir) => mkdirSync(dir, { recursive: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CONFIG, TOOL_CALL_AS_TEXT, isConfigLoaded, loadConfig } from './app-config.mjs';
|
|
2
|
-
export { DATA_DIR, GLOBAL_DIR, PROJECTS_DIR, PROJECT_SEP, WORKSPACES_DIR, ensureDir, instanceIdOf, projectDir, projectIdOf, projectIdsOnDisk, projectPath } from './data-dir.mjs';
|
|
3
|
-
export { atomicWriteFile, atomicWriteJson } from './fs.mjs';
|
|
4
|
-
export { isMainModule, killTree } from './process.mjs';
|
|
5
|
-
export { ENDPOINT_FILE, PIPE_NAME, PORT, PROTOCOL } from './protocol.mjs';
|
|
1
|
+
export { CONFIG, TOOL_CALL_AS_TEXT, isConfigLoaded, loadConfig } from './app-config.mjs';
|
|
2
|
+
export { DATA_DIR, GLOBAL_DIR, PROJECTS_DIR, PROJECT_SEP, WORKSPACES_DIR, ensureDir, instanceIdOf, projectDir, projectIdOf, projectIdsOnDisk, projectPath } from './data-dir.mjs';
|
|
3
|
+
export { atomicWriteFile, atomicWriteJson } from './fs.mjs';
|
|
4
|
+
export { isMainModule, killTree } from './process.mjs';
|
|
5
|
+
export { ENDPOINT_FILE, PIPE_NAME, PORT, PROTOCOL } from './protocol.mjs';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { DATA_DIR } from './data-dir.mjs';
|
|
4
|
-
|
|
5
|
-
export const PROTOCOL = 3;
|
|
6
|
-
function defaultWinPipe() {
|
|
7
|
-
if (!process.env.AGENTD_DATA_DIR) return '\\\\.\\pipe\\pi-agentd';
|
|
8
|
-
const hash = createHash('sha1').update(DATA_DIR.toLowerCase()).digest('hex').slice(0, 12);
|
|
9
|
-
return `\\\\.\\pipe\\harness-bus-${hash}`;
|
|
10
|
-
}
|
|
11
|
-
export const PIPE_NAME = process.env.AGENTD_PIPE || (process.platform === 'win32' ? defaultWinPipe() : join(DATA_DIR, 'agentd.sock'));
|
|
12
|
-
export const PORT = process.env.AGENTD_PORT ? Number(process.env.AGENTD_PORT) : null;
|
|
13
|
-
export const ENDPOINT_FILE = join(DATA_DIR, 'agentd.endpoint.json');
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { DATA_DIR } from './data-dir.mjs';
|
|
4
|
+
|
|
5
|
+
export const PROTOCOL = 3;
|
|
6
|
+
function defaultWinPipe() {
|
|
7
|
+
if (!process.env.AGENTD_DATA_DIR) return '\\\\.\\pipe\\pi-agentd';
|
|
8
|
+
const hash = createHash('sha1').update(DATA_DIR.toLowerCase()).digest('hex').slice(0, 12);
|
|
9
|
+
return `\\\\.\\pipe\\harness-bus-${hash}`;
|
|
10
|
+
}
|
|
11
|
+
export const PIPE_NAME = process.env.AGENTD_PIPE || (process.platform === 'win32' ? defaultWinPipe() : join(DATA_DIR, 'agentd.sock'));
|
|
12
|
+
export const PORT = process.env.AGENTD_PORT ? Number(process.env.AGENTD_PORT) : null;
|
|
13
|
+
export const ENDPOINT_FILE = join(DATA_DIR, 'agentd.endpoint.json');
|
|
@@ -33,7 +33,58 @@ export const AGENTS = Object.fromEntries(driverTypes.map((t) => [t, specFor(getD
|
|
|
33
33
|
|
|
34
34
|
export const driverOf = getDriver;
|
|
35
35
|
|
|
36
|
-
export const
|
|
36
|
+
export const AUTH_ERROR_RE =
|
|
37
|
+
/\b(401|403|unauthorized|unauthenticated|not logged in|login required|auth(?:entication)? (?:failed|required)|invalid api key|missing api key|credential|token expired)\b|未登录|认证失败|登录失效|请先登录/i;
|
|
38
|
+
|
|
39
|
+
export function authHintFor(type) {
|
|
40
|
+
return AGENTS[type]?.driver?.authHint ?? null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function formatAuthHint(type, errMessage) {
|
|
44
|
+
if (!AUTH_ERROR_RE.test(String(errMessage ?? ''))) return null;
|
|
45
|
+
const hint = authHintFor(type);
|
|
46
|
+
if (hint) return `登录提示(${type}):${hint}`;
|
|
47
|
+
const target = type || '该工具';
|
|
48
|
+
return `登录提示(${target}):可能尚未登录或凭证已失效,请在终端完成登录授权或运行 "hbus ui" 配置第三方兼容渠道`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function enrichAuthError(type, err) {
|
|
52
|
+
if (!err) return err;
|
|
53
|
+
const msg = String(err.message ?? err);
|
|
54
|
+
if (msg.includes('登录提示(')) return err;
|
|
55
|
+
const hint = formatAuthHint(type, msg);
|
|
56
|
+
if (!hint) return err;
|
|
57
|
+
if (err instanceof Error) {
|
|
58
|
+
err.message = `${msg}\n${hint}`;
|
|
59
|
+
return err;
|
|
60
|
+
}
|
|
61
|
+
return new Error(`${msg}\n${hint}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function cliAvailability(install = currentInstall()) {
|
|
65
|
+
return driverTypes.map((t) => {
|
|
66
|
+
const driver = getDriver(t);
|
|
67
|
+
const l = driver.launch(install, { piAdapterPath: PI_ADAPTER_PATH });
|
|
68
|
+
const missing = Array.isArray(l?.missing) ? l.missing : [];
|
|
69
|
+
return {
|
|
70
|
+
type: t,
|
|
71
|
+
label: driver.label,
|
|
72
|
+
installed: missing.length === 0,
|
|
73
|
+
missing,
|
|
74
|
+
authHint: driver.authHint ?? null,
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const HIGH_EFFORT_RE = /^(high|xhigh|max)$/i;
|
|
80
|
+
|
|
81
|
+
export const idleRunMs = (effort = null) => {
|
|
82
|
+
const envMs = Number(process.env.AGENTD_IDLE_RUN_MS);
|
|
83
|
+
if (envMs > 0) return envMs;
|
|
84
|
+
const cfgMin = Number(CONFIG?.limits?.idleRunMin);
|
|
85
|
+
if (cfgMin > 0) return cfgMin * 60_000;
|
|
86
|
+
return HIGH_EFFORT_RE.test(String(effort ?? '').trim()) ? 600_000 : 480_000;
|
|
87
|
+
};
|
|
37
88
|
export const stuckToolMs = () => Number(process.env.AGENTD_STUCK_TOOL_MS) || (Number(CONFIG?.limits?.stuckToolMin) > 0 ? Number(CONFIG.limits.stuckToolMin) * 60_000 : 300_000);
|
|
38
89
|
export const MAX_RUN_MS = Number(process.env.AGENTD_MAX_RUN_MS) || 2 * 60 * 60_000;
|
|
39
90
|
export const CANCEL_GRACE_MS = Number(process.env.AGENTD_CANCEL_GRACE_MS) || 15_000;
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
export {
|
|
2
2
|
AGENTS,
|
|
3
|
+
AUTH_ERROR_RE,
|
|
3
4
|
CANCEL_GRACE_MS,
|
|
4
5
|
CONFIG,
|
|
5
6
|
MAX_RUN_MS,
|
|
6
7
|
PI_ADAPTER_PATH,
|
|
7
8
|
START_ATTEMPTS,
|
|
9
|
+
authHintFor,
|
|
10
|
+
cliAvailability,
|
|
8
11
|
defaultModelFor,
|
|
9
12
|
driverOf,
|
|
10
13
|
effortOf,
|
|
14
|
+
enrichAuthError,
|
|
11
15
|
flattenOptions,
|
|
12
16
|
forcedStopLimit,
|
|
13
17
|
forcedStopWindowMs,
|
|
18
|
+
formatAuthHint,
|
|
14
19
|
idleRunMs,
|
|
15
20
|
isEffortOption,
|
|
16
21
|
log,
|
|
17
22
|
normPath,
|
|
18
23
|
stuckToolMs,
|
|
19
24
|
} from './config.mjs';
|
|
20
|
-
export { CLIS_FILE, currentInstall, nodeBin, piPaths, readManifest } from './install.mjs';
|
|
25
|
+
export { CLIS_FILE, candidateNodeModuleRoots, currentInstall, nodeBin, piPaths, readManifest } from './install.mjs';
|
|
21
26
|
export { acpMcpServers, cleanMcpServers, describeMcpServers, mcpServersOf, piMcpServers } from './mcp.mjs';
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
1
2
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { delimiter, dirname, join, resolve } from 'node:path';
|
|
3
5
|
import { binaryEnvKey, defaultBinDirs, findBinaryInDirs, getDriver } from '../../../drivers/index.mjs';
|
|
4
6
|
import { GLOBAL_DIR } from '../base/index.mjs';
|
|
5
7
|
|
|
6
8
|
export const CLIS_FILE = process.env.AGENTD_CLIS_FILE || join(GLOBAL_DIR, 'clis.json');
|
|
7
9
|
|
|
8
10
|
let cached = { mtime: -1, data: null };
|
|
11
|
+
let npmRootCache = { at: 0, path: null };
|
|
12
|
+
const NPM_ROOT_TTL_MS = 60_000;
|
|
9
13
|
|
|
10
14
|
export function readManifest() {
|
|
11
15
|
try {
|
|
@@ -32,15 +36,89 @@ const readVersion = (dir) => {
|
|
|
32
36
|
}
|
|
33
37
|
};
|
|
34
38
|
|
|
39
|
+
export function candidateNodeModuleRoots({
|
|
40
|
+
node = nodeBin(),
|
|
41
|
+
env = process.env,
|
|
42
|
+
platform = process.platform,
|
|
43
|
+
ownToolsDir = join(GLOBAL_DIR, 'tools'),
|
|
44
|
+
} = {}) {
|
|
45
|
+
const seen = new Set();
|
|
46
|
+
const roots = [];
|
|
47
|
+
const normKey = (p) => (platform === 'win32' ? resolve(p).toLowerCase() : resolve(p));
|
|
48
|
+
const add = (p) => {
|
|
49
|
+
const raw = String(p ?? '').trim();
|
|
50
|
+
if (!raw) return;
|
|
51
|
+
const k = normKey(raw);
|
|
52
|
+
if (seen.has(k)) return;
|
|
53
|
+
seen.add(k);
|
|
54
|
+
roots.push(raw);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (ownToolsDir) add(join(ownToolsDir, 'node_modules'));
|
|
58
|
+
|
|
59
|
+
if (env.AGENTD_NODE_MODULES !== undefined) {
|
|
60
|
+
for (const part of String(env.AGENTD_NODE_MODULES).split(delimiter)) add(part);
|
|
61
|
+
return roots;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const npmPrefix = env.NPM_CONFIG_PREFIX || env.npm_config_prefix;
|
|
65
|
+
if (npmPrefix) {
|
|
66
|
+
add(platform === 'win32' ? join(npmPrefix, 'node_modules') : join(npmPrefix, 'lib', 'node_modules'));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const home = homedir();
|
|
70
|
+
if (platform === 'win32') {
|
|
71
|
+
const profile = env.USERPROFILE || home;
|
|
72
|
+
add(env.APPDATA ? join(env.APPDATA, 'npm', 'node_modules') : join(profile, 'AppData', 'Roaming', 'npm', 'node_modules'));
|
|
73
|
+
if (node) add(join(dirname(node), 'node_modules'));
|
|
74
|
+
} else {
|
|
75
|
+
const unixHome = env.HOME || home;
|
|
76
|
+
if (node) {
|
|
77
|
+
add(join(dirname(dirname(node)), 'lib', 'node_modules'));
|
|
78
|
+
add(join(dirname(node), 'node_modules'));
|
|
79
|
+
}
|
|
80
|
+
add('/opt/homebrew/lib/node_modules');
|
|
81
|
+
add('/usr/local/lib/node_modules');
|
|
82
|
+
add(join(unixHome, '.npm-global', 'lib', 'node_modules'));
|
|
83
|
+
}
|
|
84
|
+
return roots;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function cachedNpmGlobalRoot(env = process.env, platform = process.platform) {
|
|
88
|
+
if (env.AGENTD_NODE_MODULES !== undefined) return null;
|
|
89
|
+
const now = Date.now();
|
|
90
|
+
if (npmRootCache.at && now - npmRootCache.at < NPM_ROOT_TTL_MS) return npmRootCache.path;
|
|
91
|
+
let found = null;
|
|
92
|
+
try {
|
|
93
|
+
const r =
|
|
94
|
+
platform === 'win32'
|
|
95
|
+
? spawnSync('npm.cmd root -g', [], { encoding: 'utf8', timeout: 5_000, shell: true, windowsHide: true })
|
|
96
|
+
: spawnSync('npm', ['root', '-g'], { encoding: 'utf8', timeout: 5_000, windowsHide: true });
|
|
97
|
+
const out = String(r.stdout ?? '').trim().split(/\r?\n/).pop();
|
|
98
|
+
if (r.status === 0 && out && existsSync(out)) found = out;
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
npmRootCache = { at: now, path: found };
|
|
102
|
+
return found;
|
|
103
|
+
}
|
|
104
|
+
|
|
35
105
|
export function currentInstall() {
|
|
36
106
|
const node = nodeBin();
|
|
37
107
|
const manifest = readManifest();
|
|
38
|
-
const
|
|
108
|
+
const fastRoots = candidateNodeModuleRoots({ node });
|
|
39
109
|
const find = (name) => {
|
|
40
110
|
const m = manifest?.packages?.[name];
|
|
41
111
|
if (m?.dir && existsSync(join(m.dir, 'package.json'))) return m.dir;
|
|
42
|
-
const
|
|
43
|
-
|
|
112
|
+
for (const root of fastRoots) {
|
|
113
|
+
const dir = join(root, name);
|
|
114
|
+
if (existsSync(join(dir, 'package.json'))) return dir;
|
|
115
|
+
}
|
|
116
|
+
const npmRoot = cachedNpmGlobalRoot();
|
|
117
|
+
if (npmRoot && !fastRoots.includes(npmRoot)) {
|
|
118
|
+
const dir = join(npmRoot, name);
|
|
119
|
+
if (existsSync(join(dir, 'package.json'))) return dir;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
44
122
|
};
|
|
45
123
|
const findBin = (name) => {
|
|
46
124
|
const override = process.env[binaryEnvKey(name)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { PiRpc } from './rpc.mjs';
|
|
1
|
+
export { PiRpc } from './rpc.mjs';
|