Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/coding-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- Added system prompt note listing pre-installed Python packages (requests, httpx, pyyaml, tomli, python-dotenv, pandas, numpy, scipy, beautifulsoup4, lxml, pydantic).
- Added `DEFAULT_RLM_EXTRA_UV_ARGS` constant and kernel bootstrap installation of those packages; updated prompt to reference the constant instead of a hardcoded list.


## [0.0.2] - 2026-05-20
Expand Down
43 changes: 40 additions & 3 deletions packages/coding-agent/src/core/kernel/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@ import { createInterface } from "node:readline/promises";
import { setTimeout as sleep } from "node:timers/promises";
import { fileURLToPath } from "node:url";

const BOOTSTRAP_SCHEMA = 2;
const BOOTSTRAP_SCHEMA = 3;
const PYTHON_VERSION = "3.11";
const IPYKERNEL_REQUIREMENT = "ipykernel";
const RUNTIME_REQUIREMENT = "prime-agent-runtime";
export const DEFAULT_RLM_EXTRA_UV_ARGS = [
"requests",
"httpx",
"pyyaml",
"tomli",
"python-dotenv",
"pandas",
"numpy",
"scipy",
"beautifulsoup4",
"lxml",
"pydantic",
];
const UV_INSTALL_COMMAND = "curl -LsSf https://astral.sh/uv/install.sh | sh";
const RUNTIME_READY_CHECK =
"import rlm; assert hasattr(rlm, 'run'); assert callable(rlm); assert hasattr(rlm, 'rlm'); assert callable(rlm.rlm); assert not hasattr(rlm, 'background'); assert not hasattr(rlm.rlm, 'background')";
Expand All @@ -26,6 +39,7 @@ interface BootstrapVersion {
schema: number;
ipykernel?: string;
runtime?: string;
extraUvArgs?: string[];
}

function errorMessage(error: unknown): string {
Expand Down Expand Up @@ -266,21 +280,35 @@ async function readBootstrapVersion(venv: string): Promise<BootstrapVersion | nu
const raw = await readFile(path.join(venv, BOOTSTRAP_VERSION_FILE), "utf8");
const parsed: unknown = JSON.parse(raw);
if (!isRecord(parsed) || typeof parsed.schema !== "number") return null;
const extraUvArgs =
Array.isArray(parsed.extraUvArgs) &&
parsed.extraUvArgs.every((v: unknown): v is string => typeof v === "string")
? (parsed.extraUvArgs as string[])
: undefined;
return {
schema: parsed.schema,
ipykernel: typeof parsed.ipykernel === "string" ? parsed.ipykernel : undefined,
runtime: typeof parsed.runtime === "string" ? parsed.runtime : undefined,
extraUvArgs,
};
} catch {
return null;
}
}

function extraUvArgsMatch(a: string[] | undefined, b: string[] | undefined): boolean {
if (a === b) return true;
if (!a || !b) return false;
if (a.length !== b.length) return false;
return a.every((v, i) => v === b[i]);
}

function bootstrapVersionCurrent(version: BootstrapVersion | null): boolean {
return (
version?.schema === BOOTSTRAP_SCHEMA &&
version.ipykernel === IPYKERNEL_REQUIREMENT &&
version.runtime === RUNTIME_REQUIREMENT
version.runtime === RUNTIME_REQUIREMENT &&
extraUvArgsMatch(version.extraUvArgs, DEFAULT_RLM_EXTRA_UV_ARGS)
);
}

Expand All @@ -289,6 +317,7 @@ async function writeBootstrapVersion(venv: string): Promise<void> {
schema: BOOTSTRAP_SCHEMA,
ipykernel: IPYKERNEL_REQUIREMENT,
runtime: RUNTIME_REQUIREMENT,
extraUvArgs: DEFAULT_RLM_EXTRA_UV_ARGS,
};
await writeFile(path.join(venv, BOOTSTRAP_VERSION_FILE), `${JSON.stringify(version)}\n`, "utf8");
}
Expand Down Expand Up @@ -318,7 +347,15 @@ async function bootstrapVenv(venv: string): Promise<void> {

await run(uv, ["python", "install", PYTHON_VERSION]);
await run(uv, ["venv", venv, "--python", PYTHON_VERSION, "--seed"]);
await run(uv, ["pip", "install", "--python", python, IPYKERNEL_REQUIREMENT, runtimeRequirement]);
await run(uv, [
"pip",
"install",
"--python",
python,
IPYKERNEL_REQUIREMENT,
runtimeRequirement,
...DEFAULT_RLM_EXTRA_UV_ARGS,
]);
await writeBootstrapVersion(venv);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/coding-agent/src/core/prompts/rlm.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DEFAULT_RLM_EXTRA_UV_ARGS } from "../kernel/bootstrap.js";

export interface RlmPromptOptions {
cwd: string;
skillsDir?: string;
Expand Down Expand Up @@ -53,7 +55,7 @@ export function buildRlmPrompt(options: RlmPromptOptions): string {
"",
"Use `ipython` for both Python and shell work. For repository shell commands, prefer IPython shell syntax: `!rg ...`, `!npm run check`, or `%%bash` for multi-line scripts. Do not wrap ordinary shell commands in Python subprocesses unless you need Python-level processing.",
"",
"The kernel has requests, httpx, pyyaml, tomli, python-dotenv, pandas, numpy, scipy, beautifulsoup4, lxml, and pydantic pre-installed. Import them directly; no pip install needed.",
`The kernel has these packages pre-installed: ${DEFAULT_RLM_EXTRA_UV_ARGS.join(", ")}. Import them directly; no pip install needed.`,
);
}

Expand Down
Loading