@saadnvd1/agent-os 0.3.658 → 0.3.659
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/lib/agents/launch.ts +2 -1
- package/lib/agents/tool-path.ts +61 -0
- package/package.json +1 -1
package/lib/agents/launch.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { runInBackground } from "../async-operations";
|
|
|
10
10
|
import { trustPromptKeys } from "../tasks/state";
|
|
11
11
|
import { BUS_BRIEF } from "./brief";
|
|
12
12
|
import { selfUrl } from "./self-env";
|
|
13
|
+
import { sessionPath } from "./tool-path";
|
|
13
14
|
import { autoCompactEnv } from "../chat/refresh";
|
|
14
15
|
import { subagentEnv } from "../models/subagents";
|
|
15
16
|
import { COMPACT_BRIEF } from "../chat/working-state";
|
|
@@ -43,7 +44,7 @@ export function agentEnv(sessionId: string): Record<string, string> {
|
|
|
43
44
|
...subagentEnv(),
|
|
44
45
|
AGENTOS_SESSION_ID: sessionId,
|
|
45
46
|
AGENTOS_URL: selfUrl(),
|
|
46
|
-
PATH: `${AOS_BIN_DIR}:${
|
|
47
|
+
PATH: `${AOS_BIN_DIR}:${sessionPath()}`,
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
// Where Saad's language version managers and user-level tools put their
|
|
6
|
+
// binaries, in the order they should win. A shell's rc files normally add
|
|
7
|
+
// these; a session AgentOS starts doesn't read them, so `bin/rails` would
|
|
8
|
+
// find the system Ruby. Built in code so it is fast and the same on the Mac
|
|
9
|
+
// and the Linux box (missing dirs are skipped).
|
|
10
|
+
const USER_TOOL_DIRS = [
|
|
11
|
+
".rbenv/shims",
|
|
12
|
+
".local/share/mise/shims",
|
|
13
|
+
".asdf/shims",
|
|
14
|
+
".pyenv/shims",
|
|
15
|
+
".local/bin",
|
|
16
|
+
".bun/bin",
|
|
17
|
+
".cargo/bin",
|
|
18
|
+
];
|
|
19
|
+
const SYSTEM_TOOL_DIRS = ["/opt/homebrew/bin", "/opt/homebrew/sbin"];
|
|
20
|
+
|
|
21
|
+
function isDir(p: string): boolean {
|
|
22
|
+
try {
|
|
23
|
+
return fs.statSync(p).isDirectory();
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// `npm run` puts every node_modules/.bin from the server's directory upward on
|
|
30
|
+
// PATH; for a session in another repo those would shadow the project's tools.
|
|
31
|
+
function serverBinDirs(cwd: string): Set<string> {
|
|
32
|
+
const dirs = new Set<string>();
|
|
33
|
+
for (let d = path.resolve(cwd); ; d = path.dirname(d)) {
|
|
34
|
+
dirs.add(path.join(d, "node_modules", ".bin"));
|
|
35
|
+
if (path.dirname(d) === d) break;
|
|
36
|
+
}
|
|
37
|
+
return dirs;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function sessionPath(
|
|
41
|
+
inherited: string | undefined = process.env.PATH,
|
|
42
|
+
home: string = os.homedir(),
|
|
43
|
+
cwd: string = process.cwd()
|
|
44
|
+
): string {
|
|
45
|
+
const drop = serverBinDirs(cwd);
|
|
46
|
+
const out: string[] = [];
|
|
47
|
+
const seen = new Set<string>();
|
|
48
|
+
const add = (dir: string) => {
|
|
49
|
+
if (!dir || seen.has(dir)) return;
|
|
50
|
+
seen.add(dir);
|
|
51
|
+
out.push(dir);
|
|
52
|
+
};
|
|
53
|
+
for (const d of [
|
|
54
|
+
...USER_TOOL_DIRS.map((d) => path.join(home, d)),
|
|
55
|
+
...SYSTEM_TOOL_DIRS,
|
|
56
|
+
])
|
|
57
|
+
if (isDir(d)) add(d);
|
|
58
|
+
for (const d of (inherited ?? "").split(path.delimiter))
|
|
59
|
+
if (!drop.has(d)) add(d);
|
|
60
|
+
return out.join(path.delimiter);
|
|
61
|
+
}
|