Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

Persist Python package deps in shared venv

wyt60fd99ef6dae
diff --git a/bin/orkas-pkg.cjs b/bin/orkas-pkg.cjs
index dac20538..838a0440 100644
--- a/bin/orkas-pkg.cjs
+++ b/bin/orkas-pkg.cjs
@@ -50,6 +50,8 @@
* Python package venv creation.
* ORKAS_UV — optional bundled uv executable used for Python
* package dependency installs.
+ * ORKAS_VENV_ROOT — optional shared machine-local venv root.
+ * Defaults to `<ORKAS_WORKSPACE_ROOT>/venv`.
*/
'use strict';
@@ -57,6 +59,7 @@
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
+const crypto = require('node:crypto');
const { spawnSync } = require('node:child_process');
const REGISTRY_VERSION = 1;
@@ -82,6 +85,16 @@ function wsRoot() {
|| path.join(os.homedir(), '.orkas', 'data');
}
+function sharedVenvRoot() { return process.env.ORKAS_VENV_ROOT || path.join(wsRoot(), 'venv'); }
+function pythonVenvRoot() { return path.join(sharedVenvRoot(), 'python'); }
+function pythonVenvCacheEnv() {
+ return {
+ ORKAS_VENV_ROOT: sharedVenvRoot(),
+ UV_CACHE_DIR: process.env.UV_CACHE_DIR || path.join(pythonVenvRoot(), 'cache', 'uv'),
+ PIP_CACHE_DIR: process.env.PIP_CACHE_DIR || path.join(pythonVenvRoot(), 'cache', 'pip'),
+ };
+}
+
function resolveUid() {
const envUid = (process.env.ORKAS_UID || '').trim();
if (envUid && !envUid.includes('/') && !envUid.includes('\\')) return envUid;
@@ -167,7 +180,7 @@ function run(cmd, args, opts) {
cwd: opts && opts.cwd,
encoding: 'utf8',
timeout: (opts && opts.timeoutMs) || 10 * 60 * 1000,
- env: process.env,
+ env: { ...process.env, ...((opts && opts.env) || {}) },
// npm/pip/git progress goes to our stderr so the bash tool surfaces it.
stdio: ['ignore', 'pipe', 'inherit'],
});
@@ -214,16 +227,37 @@ function uvCommand() {
return null;
}
-function venvPythonPath(pkgDir) {
+function venvPythonPath(venvDir) {
return process.platform === 'win32'
- ? path.join(pkgDir, '.venv', 'Scripts', 'python.exe')
- : path.join(pkgDir, '.venv', 'bin', 'python');
+ ? path.join(venvDir, 'Scripts', 'python.exe')
+ : path.join(venvDir, 'bin', 'python');
}
-function venvPipPath(pkgDir) {
+function venvPipPath(venvDir) {
return process.platform === 'win32'
- ? path.join(pkgDir, '.venv', 'Scripts', 'pip.exe')
- : path.join(pkgDir, '.venv', 'bin', 'pip');
+ ? path.join(venvDir, 'Scripts', 'pip.exe')
+ : path.join(venvDir, 'bin', 'pip');
+}
+
+function venvConsoleScriptPath(venvDir, name) {
+ return process.platform === 'win32'
+ ? path.join(venvDir, 'Scripts', `${name}.exe`)
+ : path.join(venvDir, 'bin', name);
+}
+
+function shortHash(input) {
+ return crypto.createHash('sha256').update(String(input)).digest('hex').slice(0, 12);
+}
+
+function packageVenvKey(pkg) {
+ const rawName = (pkg && pkg.name) || 'package';
+ const name = PKG_NAME_RE.test(rawName) ? rawName : 'package';
+ const basis = [name, (pkg && pkg.repo_url) || '', (pkg && pkg.commit) || ''].join('\n');
+ return `${name}-${shortHash(basis)}`;
+}
+
+function packageVenvDir(pkg) {
+ return path.join(pythonVenvRoot(), 'packages', packageVenvKey(pkg), '.venv');
}
/** Candidate rel dirs whose children (or, for '.', the dir itself) hold SKILL.md. */
@@ -266,9 +300,9 @@ function scanNodeBinEntries(pkgDir) {
/**
* `[project.scripts]` console entries from pyproject.toml. Naive
* line-oriented TOML section walk — enough for the `name = "module:func"`
- * shape; anything fancier is ignored. Targets resolve to the venv console
- * script (created by `pip install -e .`), so they only become shims once
- * deps are installed.
+ * shape; anything fancier is ignored. Targets keep the legacy package-local
+ * `.venv` shape for registry compatibility; shim generation resolves shared
+ * `data/venv` console scripts first.
*/
function scanPythonBinEntries(pkgDir) {
const entries = [];
@@ -317,46 +351,49 @@ function hasPythonProject(pkgDir) {
return isFile(path.join(pkgDir, 'pyproject.toml')) || isFile(path.join(pkgDir, 'setup.py'));
}
-function describeDepCommands(pkgDir) {
+function describeDepCommands(pkgDir, pkgMeta) {
const cmds = [];
if (hasNodeDeps(pkgDir)) cmds.push('npm install --omit=dev');
if (hasPythonProject(pkgDir)) {
+ const venv = packageVenvDir(pkgMeta);
const uv = uvCommand();
if (uv) {
const venvCmd = process.env.ORKAS_PYTHON
- ? '$ORKAS_UV venv --python $ORKAS_PYTHON .venv'
- : '$ORKAS_UV venv .venv';
- cmds.push(`${venvCmd} && $ORKAS_UV pip install --python .venv -e .`);
+ ? `$ORKAS_UV venv --python $ORKAS_PYTHON "${venv}"`
+ : `$ORKAS_UV venv "${venv}"`;
+ cmds.push(`${venvCmd} && $ORKAS_UV pip install --python "${venvPythonPath(venv)}" .`);
} else {
- cmds.push(`${pythonCommand().label} -m venv .venv && ${process.platform === 'win32' ? '.venv\\Scripts\\pip.exe' : '.venv/bin/pip'} install -e .`);
+ cmds.push(`${pythonCommand().label} -m venv "${venv}" && "${venvPipPath(venv)}" install .`);
}
}
return cmds;
}
-function installDeps(pkgDir) {
+function installDeps(pkgDir, pkgMeta) {
const performed = [];
if (hasNodeDeps(pkgDir)) {
runOrDie('npm', ['install', '--omit=dev', '--no-fund', '--no-audit'], { cwd: pkgDir }, 'npm install');
performed.push('npm install --omit=dev');
}
if (hasPythonProject(pkgDir)) {
- const venv = path.join(pkgDir, '.venv');
+ const venv = packageVenvDir(pkgMeta);
+ const cacheEnv = pythonVenvCacheEnv();
+ fs.mkdirSync(path.dirname(venv), { recursive: true });
const uv = uvCommand();
if (uv) {
if (!isDir(venv)) {
const args = ['venv'];
if (process.env.ORKAS_PYTHON) args.push('--python', process.env.ORKAS_PYTHON);
- args.push('.venv');
- runOrDie(uv, args, { cwd: pkgDir }, 'uv venv');
+ args.push(venv);
+ runOrDie(uv, args, { cwd: pkgDir, env: cacheEnv }, 'uv venv');
}
- runOrDie(uv, ['pip', 'install', '--python', venvPythonPath(pkgDir), '-e', '.'], { cwd: pkgDir }, 'uv pip install');
- performed.push('uv pip install -e .');
+ runOrDie(uv, ['pip', 'install', '--python', venvPythonPath(venv), '.'], { cwd: pkgDir, env: cacheEnv }, 'uv pip install');
+ performed.push('uv pip install .');
} else {
const py = pythonCommand();
- if (!isDir(venv)) runOrDie(py.cmd, [...py.args, '-m', 'venv', '.venv'], { cwd: pkgDir }, 'venv creation');
- runOrDie(venvPipPath(pkgDir), ['install', '-e', '.'], { cwd: pkgDir }, 'pip install');
- performed.push('pip install -e .');
+ if (!isDir(venv)) runOrDie(py.cmd, [...py.args, '-m', 'venv', venv], { cwd: pkgDir, env: cacheEnv }, 'venv creation');
+ runOrDie(venvPipPath(venv), ['install', '.'], { cwd: pkgDir, env: cacheEnv }, 'pip install');
+ performed.push('pip install .');
}
}
return performed;
@@ -372,9 +409,14 @@ function regenerateShims(uid, registry) {
for (const pkg of registry.packages) {
if (pkg.enabled === false) continue;
for (const entry of pkg.bin_entries || []) {
- const targetAbs = path.join(packagesDir(uid), pkg.name, entry.target);
- // Python console scripts only exist after pip install -e — skip until then.
- if (entry.runtime === 'python' && !isFile(targetAbs)) continue;
+ let targetAbs = path.join(packagesDir(uid), pkg.name, entry.target);
+ if (entry.runtime === 'python') {
+ const sharedTarget = venvConsoleScriptPath(packageVenvDir(pkg), entry.name);
+ targetAbs = isFile(sharedTarget) ? sharedTarget : targetAbs;
+ // Python console scripts only exist after dependency install — skip
+ // until either the shared venv or a legacy package-local venv has one.
+ if (!isFile(targetAbs)) continue;
+ }
wanted.push({ pkg: pkg.name, ...entry, targetAbs });
}
}
@@ -460,10 +502,12 @@ function cmdInstall(args) {
{ source });
}
- const depCommands = describeDepCommands(staging);
+ const commit = headCommit(staging);
+ const pkgMeta = { name, repo_url: source, commit };
+ const depCommands = describeDepCommands(staging, pkgMeta);
let depsInstalled = [];
if (depCommands.length && consentDeps) {
- depsInstalled = installDeps(staging);
+ depsInstalled = installDeps(staging, pkgMeta);
}
fs.renameSync(staging, finalDir);
@@ -474,7 +518,7 @@ function cmdInstall(args) {
registry.packages.push({
name,
repo_url: source,
- commit: headCommit(finalDir),
+ commit,
kind: scan.kind,
skill_roots: scan.skillRoots,
bin_entries: scan.binEntries,
@@ -518,9 +562,10 @@ function cmdConsentDeps(args) {
const pkgDir = path.join(packagesDir(uid), name);
if (!entry || !isDir(pkgDir)) die(66, `package "${name}" is not installed`);
- const depsInstalled = installDeps(pkgDir);
+ if (!entry.commit) entry.commit = headCommit(pkgDir);
+ const depsInstalled = installDeps(pkgDir, entry);
entry.deps_consent = true;
- // Python console-script targets only materialize after pip install -e,
+ // Python console-script targets only materialize after dependency install,
// so rescan bin entries before regenerating shims.
const scan = scanPackage(pkgDir);
if (scan.kind) {
@@ -552,13 +597,15 @@ function cmdUpdate(args) {
if (!scan.kind) {
die(65, `after update, "${name}" no longer has a supported skill/CLI shape — leaving files in place; review manually`);
}
+ const commit = headCommit(pkgDir);
let depsInstalled = [];
- const depCommands = describeDepCommands(pkgDir);
+ const pkgMeta = { ...entry, commit };
+ const depCommands = describeDepCommands(pkgDir, pkgMeta);
if (depCommands.length && entry.deps_consent === true) {
- depsInstalled = installDeps(pkgDir);
+ depsInstalled = installDeps(pkgDir, pkgMeta);
}
- entry.commit = headCommit(pkgDir);
+ entry.commit = commit;
entry.kind = scan.kind;
entry.skill_roots = scan.skillRoots;
entry.bin_entries = scan.binEntries;
diff --git a/bin/run-skill.cjs b/bin/run-skill.cjs
index 8904e31f..e913f20f 100755
--- a/bin/run-skill.cjs
+++ b/bin/run-skill.cjs
@@ -9,9 +9,10 @@
* of skill language:
* .ts / .mjs / .js — require() with tsx/cjs hook, call default export as
* `async (args) => result`, JSON.stringify result to stdout.
- * .py — spawn nearest package `.venv`, else `ORKAS_PYTHON`,
- * else system Python (`python3`; Windows: `py -3`
- * then `python`), inherit stdio, exit with child code.
+ * .py — spawn shared data/venv package Python, else nearest
+ * package `.venv`, else `ORKAS_PYTHON`, else system
+ * Python (`python3`; Windows: `py -3` then `python`),
+ * inherit stdio, exit with child code.
* .ps1 — spawn PowerShell (Windows-native script).
* .cmd / .bat — spawn `cmd.exe` (Windows-native batch script).
* .sh — spawn `bash` (Windows: Git Bash only; WSL is not
@@ -30,8 +31,9 @@
* Dependency resolution for scripts living under an external package (or any
* skill dir that vendors its own deps): the NEAREST `node_modules` walking up
* from the skill dir is prepended to NODE_PATH ahead of PC/node_modules, and
- * a `.venv` found the same way supplies the python interpreter. The package
- * tree itself is never modified.
+ * Python package deps prefer the shared machine-local data/venv interpreter
+ * keyed by package source+commit; legacy/vendored `.venv` dirs still work as
+ * fallback. The package tree itself is never modified.
*
* Env inputs:
* ORKAS_PC_DIR — points at PC root (or asar.unpacked equivalent).
@@ -47,6 +49,8 @@
* ORKAS_PYTHON — optional bundled Python executable injected by
* the main process when resources/runtime is
* available.
+ * ORKAS_VENV_ROOT — optional shared venv root. Defaults to
+ * `<ORKAS_WORKSPACE_ROOT>/venv`.
* ELECTRON_RUN_AS_NODE — set to 1 when running through Electron binary.
*
* This file is CommonJS so it can be required directly without import-hook
@@ -57,9 +61,11 @@
const fs = require('node:fs');
const path = require('node:path');
+const crypto = require('node:crypto');
const { spawn } = require('node:child_process');
const SCRIPT_EXTS = ['py', 'ts', 'mjs', 'js', 'ps1', 'cmd', 'bat', 'sh', 'rb'];
+const PKG_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
function scriptExtsForPlatform(platform = process.platform) {
if (platform === 'win32') return SCRIPT_EXTS;
@@ -98,6 +104,27 @@ function isDir(p) {
}
}
+function workspaceRoot() {
+ return process.env.ORKAS_WORKSPACE_ROOT
+ || process.env.ORKAS_WS_ROOT
+ || path.join(require('os').homedir(), '.orkas', 'data');
+}
+
+function sharedVenvRoot() {
+ return process.env.ORKAS_VENV_ROOT || path.join(workspaceRoot(), 'venv');
+}
+
+function shortHash(input) {
+ return crypto.createHash('sha256').update(String(input)).digest('hex').slice(0, 12);
+}
+
+function packageVenvKey(pkg) {
+ const rawName = (pkg && pkg.name) || 'package';
+ const name = PKG_NAME_RE.test(rawName) ? rawName : 'package';
+ const basis = [name, (pkg && pkg.repo_url) || '', (pkg && pkg.commit) || ''].join('\n');
+ return `${name}-${shortHash(basis)}`;
+}
+
function pushUnique(arr, seen, value) {
const resolved = path.resolve(value);
if (seen.has(resolved)) return;
@@ -173,9 +200,7 @@ function collectSkillDirs(skillRef) {
return [resolved];
}
- const wsRoot = process.env.ORKAS_WORKSPACE_ROOT
- || process.env.ORKAS_WS_ROOT
- || path.join(require('os').homedir(), '.orkas', 'data');
+ const wsRoot = workspaceRoot();
// Candidate skill dirs — mirror SkillRegistry's
// [<uid>/cloud/skills, <uid>/local/marketplace/skills] resolution.
//
@@ -330,6 +355,42 @@ function existingFile(p) {
}
}
+function packageEntryForScript(scriptPath) {
+ const root = path.resolve(workspaceRoot());
+ const rel = path.relative(root, path.resolve(scriptPath));
+ if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return null;
+ const parts = rel.split(path.sep);
+ if (parts.length < 5 || parts[1] !== 'local' || parts[2] !== 'packages') return null;
+ const uid = parts[0];
+ const pkgName = parts[3];
+ if (!PKG_NAME_RE.test(pkgName)) return null;
+ let registry;
+ try {
+ registry = JSON.parse(fs.readFileSync(path.join(root, uid, 'local', 'packages', '_registry.json'), 'utf8'));
+ } catch {
+ return null;
+ }
+ if (!registry || !Array.isArray(registry.packages)) return null;
+ const entry = registry.packages.find((pkg) =>
+ pkg && pkg.name === pkgName && pkg.enabled !== false);
+ if (!entry) return null;
+ return {
+ name: pkgName,
+ repo_url: typeof entry.repo_url === 'string' ? entry.repo_url : '',
+ commit: typeof entry.commit === 'string' ? entry.commit : '',
+ };
+}
+
+function sharedPackageVenvPython(scriptPath, isWin) {
+ const entry = packageEntryForScript(scriptPath);
+ if (!entry) return null;
+ const venv = path.join(sharedVenvRoot(), 'python', 'packages', packageVenvKey(entry), '.venv');
+ const python = isWin
+ ? path.join(venv, 'Scripts', 'python.exe')
+ : path.join(venv, 'bin', 'python');
+ return existingFile(python) ? python : null;
+}
+
function findOnPath(names, env = process.env) {
const pathValue = env.PATH || env.Path || env.path || '';
const dirs = pathValue.split(path.delimiter).filter(Boolean);
@@ -427,15 +488,18 @@ function runViaSubprocess(scriptPath, scriptArgs, skillId) {
// to `python` if missing — handled by trying spawn.
let cmd; let argv0Args = [];
if (ext === 'py') {
- // External packages / vendored skills: a `.venv` found walking up from
- // the skill dir supplies the interpreter, so `pip install -e .` deps
- // resolve without touching the system python.
+ // External package skills prefer the shared data/venv interpreter keyed
+ // by package source+commit. Legacy/vendored skills can still supply a
+ // nearest `.venv` walking up from the skill dir.
+ const sharedPython = sharedPackageVenvPython(scriptPath, isWin);
const venvPython = findUpwards(
skillDir,
isWin ? path.join('.venv', 'Scripts', 'python.exe') : path.join('.venv', 'bin', 'python3'),
3,
);
- if (venvPython) {
+ if (sharedPython) {
+ cmd = sharedPython;
+ } else if (venvPython) {
cmd = venvPython;
} else if (isWin) {
const py = findPython(isWin);
diff --git a/src/main/features/packages.ts b/src/main/features/packages.ts
index af0ab349..b0f85d56 100644
--- a/src/main/features/packages.ts
+++ b/src/main/features/packages.ts
@@ -1,6 +1,6 @@
/**
* External packages — read-side accessor for the `<uid>/local/packages/`
- * domain (verbatim third-party repos; see paths.ts and
+ * domain (verbatim third-party repos; Python envs live under data/venv; see paths.ts and
* docs/plans/open-ecosystem-architecture.md §A).
*
* Write-side lives in `bin/orkas-pkg.cjs` (the bash-driven installer CLI,
diff --git a/src/main/model/core-agent/client.ts b/src/main/model/core-agent/client.ts
index f2394e77..05670deb 100644
--- a/src/main/model/core-agent/client.ts
+++ b/src/main/model/core-agent/client.ts
@@ -34,6 +34,7 @@ import { buildRunner } from './runner';
import { mapCoreAgentEvents } from './event-mapper';
import { getSession as _getCachedSession } from './session-store';
import { app } from 'electron';
+import * as fs from 'node:fs';
import * as paths from '../../paths';
import { getCurrentLang } from '../../i18n';
import { bundledRuntimeEnv, bundledRuntimePathEntries } from '../../util/bundled-runtime';
@@ -98,6 +99,9 @@ export async function* stopStreamOnAbort<T>(
* find installed per-user skills under `<uid>/local/marketplace/skills`
* - `ORKAS_PYTHON` / `ORKAS_UV` = optional bundled Python runtime and uv
* binary under resources/runtime, used for `.py` skills and package deps
+ * - `ORKAS_VENV_ROOT` = shared machine-local dependency env root under
+ * data/venv, plus uv/pip cache dirs there so package installs survive app
+ * updates and are reused across Orkas accounts on this device
* - `ELECTRON_RUN_AS_NODE` = makes the Electron binary boot as Node
*
* Injected via `AgentRunParams.sandboxEnv` → `ToolContext.state.sandboxEnv`
@@ -137,7 +141,16 @@ function buildSkillSandboxEnvStatic(): Record<string, string> {
export function buildSkillSandboxEnv(userId?: string): Record<string, string> {
const env = { ...buildSkillSandboxEnvStatic(), ...bundledRuntimeEnv() };
env.ORKAS_UI_LANG = getCurrentLang();
+ env.ORKAS_VENV_ROOT = paths.VENV_ROOT;
+ env.ORKAS_PYTHON_VENV_ROOT = paths.PYTHON_VENV_ROOT;
+ env.UV_CACHE_DIR = paths.PYTHON_VENV_UV_CACHE_DIR;
+ env.PIP_CACHE_DIR = paths.PYTHON_VENV_PIP_CACHE_DIR;
const pathEntries = bundledRuntimePathEntries();
+ try {
+ if (fs.statSync(paths.PYTHON_VENV_BIN_DIR).isDirectory()) {
+ pathEntries.push(paths.PYTHON_VENV_BIN_DIR);
+ }
+ } catch { /* shared venv shims are created on demand */ }
if (userId) {
env.ORKAS_UID = userId;
try {
diff --git a/src/main/paths.ts b/src/main/paths.ts
index 5dced3cc..7762df97 100644
--- a/src/main/paths.ts
+++ b/src/main/paths.ts
@@ -17,6 +17,7 @@
* users.json ← Local uid registry + current_user_id / dev_current_user_id
* window-state.json ← Last desktop window bounds (machine-local)
* logs/ ← Local logs (rolled daily, global)
+ * venv/ ← Machine-global dependency envs/caches
* local/marketplace/ ← Per-user platform installs reconciled from cloud manifests
* agents/<agent_id>/
* skills/<skill_id>/
@@ -73,6 +74,17 @@ export const USERS_FILE = path.join(WS_ROOT, 'users.json');
export const WINDOW_STATE_FILE = path.join(WS_ROOT, 'window-state.json');
// Machine-local logs (daily rolling, single global file shared across uids).
export const LOGS_DIR = path.join(WS_ROOT, 'logs');
+// Machine-local dependency environments shared across Orkas accounts on this
+// device. Lives directly under data/ so app updates never overwrite it and
+// multiple uids do not redownload the same package wheels.
+export const VENV_ROOT = path.join(WS_ROOT, 'venv');
+export const PYTHON_VENV_ROOT = path.join(VENV_ROOT, 'python');
+export const PYTHON_VENV_BIN_DIR = path.join(PYTHON_VENV_ROOT, 'bin');
+export const PYTHON_VENV_CACHE_DIR = path.join(PYTHON_VENV_ROOT, 'cache');
+export const PYTHON_VENV_UV_CACHE_DIR = path.join(PYTHON_VENV_CACHE_DIR, 'uv');
+export const PYTHON_VENV_PIP_CACHE_DIR = path.join(PYTHON_VENV_CACHE_DIR, 'pip');
+export const pythonPackageVenvDir = (key: string) =>
+ path.join(PYTHON_VENV_ROOT, 'packages', key, '.venv');
// Marketplace installs land under `<uid>/local/marketplace/` per machine — see
// `userMarketplace*` helpers below. There is no top-level platform install tree.
@@ -399,8 +411,9 @@ export const localCliSessionsFile = (uid: string, cid: string) =>
// ── External packages (machine-private, verbatim third-party repos) ─────
// `<uid>/local/packages/<name>/` hosts a cloned open-source repo UNMODIFIED
-// (including its node_modules / .venv — which is why this is local/, never
-// cloud-synced). Package metadata lives OUTSIDE the package dirs in the
+// (including node_modules when consented — Python venvs live under top-level
+// data/venv so they can be reused across Orkas accounts on this device).
+// Package metadata lives OUTSIDE the package dirs in the
// sidecar `_registry.json` so `git pull` updates never conflict with Orkas
// bookkeeping. The registry is written only by `bin/orkas-pkg.cjs` (the
// bash-driven installer CLI); main-process code reads it via
@@ -552,7 +565,7 @@ export const DEFAULT_USER_WORKSPACE = path.join(WS_ROOT, '..', 'userWorkSpace');
// Only the top-level shared directories are created here; per-uid sub-trees
// are mkdir'd on demand by `features/users.activateUser(uid)`.
export function ensureTopLevelLayout(): void {
- for (const d of [LOGS_DIR, DEFAULT_USER_WORKSPACE]) {
+ for (const d of [LOGS_DIR, VENV_ROOT, DEFAULT_USER_WORKSPACE]) {
fs.mkdirSync(d, { recursive: true });
}
}
diff --git a/test/main/model/core-agent/client.test.ts b/test/main/model/core-agent/client.test.ts
index 12105d2e..f8fe19b3 100644
--- a/test/main/model/core-agent/client.test.ts
+++ b/test/main/model/core-agent/client.test.ts
@@ -42,6 +42,10 @@ describe('core-agent client skill sandbox env', () => {
ELECTRON_RUN_AS_NODE: '1',
ORKAS_PC_DIR: expect.stringMatching(/PC$/),
ORKAS_WORKSPACE_ROOT: path.resolve(tmpDir),
+ ORKAS_VENV_ROOT: path.join(path.resolve(tmpDir), 'venv'),
+ ORKAS_PYTHON_VENV_ROOT: path.join(path.resolve(tmpDir), 'venv', 'python'),
+ UV_CACHE_DIR: path.join(path.resolve(tmpDir), 'venv', 'python', 'cache', 'uv'),
+ PIP_CACHE_DIR: path.join(path.resolve(tmpDir), 'venv', 'python', 'cache', 'pip'),
});
});
diff --git a/test/main/paths.test.ts b/test/main/paths.test.ts
index bfbf22f1..3bdecc79 100644
--- a/test/main/paths.test.ts
+++ b/test/main/paths.test.ts
@@ -40,7 +40,7 @@ describe('paths › roots', () => {
});
});
-describe('paths › top-level (users.json / logs)', () => {
+describe('paths › top-level (users.json / logs / venv)', () => {
it('USERS_FILE sits at the data root', async () => {
const p = await import('../../src/main/paths');
expect(p.USERS_FILE).toBe(path.join(p.WS_ROOT, 'users.json'));
@@ -50,6 +50,14 @@ describe('paths › top-level (users.json / logs)', () => {
const p = await import('../../src/main/paths');
expect(p.LOGS_DIR).toBe(path.join(p.WS_ROOT, 'logs'));
});
+
+ it('VENV_ROOT is a top-level shared dependency directory', async () => {
+ const p = await import('../../src/main/paths');
+ expect(p.VENV_ROOT).toBe(path.join(p.WS_ROOT, 'venv'));
+ expect(p.PYTHON_VENV_ROOT).toBe(path.join(p.WS_ROOT, 'venv', 'python'));
+ expect(p.pythonPackageVenvDir('pkg-abc'))
+ .toBe(path.join(p.WS_ROOT, 'venv', 'python', 'packages', 'pkg-abc', '.venv'));
+ });
});
describe('paths › cloud-synced per-user', () => {
@@ -141,6 +149,7 @@ describe('paths › ensureTopLevelLayout side effect', () => {
it('mkdirs the top-level skeleton on import (no uid-specific dirs)', async () => {
await import('../../src/main/paths');
expect(fs.existsSync(path.join(tmpDir, 'logs')), 'expected logs/ to exist').toBe(true);
+ expect(fs.existsSync(path.join(tmpDir, 'venv')), 'expected venv/ to exist').toBe(true);
// Crucially: no `config/` at the top level any more — that was legacy.
expect(fs.existsSync(path.join(tmpDir, 'config'))).toBe(false);
// And no `shared/` — folded into `<uid>/cloud/`.
diff --git a/test/main/util/orkas-pkg.test.ts b/test/main/util/orkas-pkg.test.ts
index 42a2e06e..2f4a44f8 100644
--- a/test/main/util/orkas-pkg.test.ts
+++ b/test/main/util/orkas-pkg.test.ts
@@ -218,13 +218,15 @@ describe.skipIf(!gitAvailable)('orkas-pkg.cjs', () => {
'#!/bin/sh',
'set -eu',
'if [ "$1" = "venv" ]; then',
- ' mkdir -p .venv/bin',
- ' printf "#!/bin/sh\\nexit 0\\n" > .venv/bin/python',
- ' chmod +x .venv/bin/python',
+ ' if [ "$2" = "--python" ]; then venv="$4"; else venv="$2"; fi',
+ ' mkdir -p "$venv/bin"',
+ ' printf "#!/bin/sh\\nexit 0\\n" > "$venv/bin/python"',
+ ' chmod +x "$venv/bin/python"',
'elif [ "$1" = "pip" ]; then',
- ' mkdir -p .venv/bin',
- ' printf "#!/bin/sh\\necho real-entry\\n" > .venv/bin/real-entry',
- ' chmod +x .venv/bin/real-entry',
+ ' venv="$(dirname "$(dirname "$4")")"',
+ ' mkdir -p "$venv/bin"',
+ ' printf "#!/bin/sh\\necho real-entry\\n" > "$venv/bin/real-entry"',
+ ' chmod +x "$venv/bin/real-entry"',
'else',
' exit 2',
'fi',
@@ -235,16 +237,19 @@ describe.skipIf(!gitAvailable)('orkas-pkg.cjs', () => {
const install = runPkgWithEnv(env, 'install', repo);
expect(install.status).toBe(0);
- expect(install.json.deps_pending_consent).toEqual([
- '$ORKAS_UV venv --python $ORKAS_PYTHON .venv && $ORKAS_UV pip install --python .venv -e .',
- ]);
+ expect(install.json.deps_pending_consent).toHaveLength(1);
+ expect(install.json.deps_pending_consent[0]).toContain(path.join(wsRoot, 'venv', 'python', 'packages', 'pyuv-'));
+ expect(install.json.deps_pending_consent[0]).toContain('$ORKAS_UV pip install --python');
+ expect(install.json.deps_pending_consent[0]).not.toContain(' -e ');
expect(fs.existsSync(path.join(pkgsDir(), '.bin', 'real-entry'))).toBe(false);
const consent = runPkgWithEnv(env, 'consent-deps', 'pyuv');
expect(consent.status).toBe(0);
- expect(consent.json.deps_installed).toEqual(['uv pip install -e .']);
+ expect(consent.json.deps_installed).toEqual(['uv pip install .']);
expect(consent.json.shims).toEqual(['real-entry']);
- expect(fs.existsSync(path.join(pkgsDir(), 'pyuv', '.venv', 'bin', 'real-entry'))).toBe(true);
+ expect(fs.existsSync(path.join(pkgsDir(), 'pyuv', '.venv', 'bin', 'real-entry'))).toBe(false);
+ const shim = fs.readFileSync(path.join(pkgsDir(), '.bin', 'real-entry'), 'utf8');
+ expect(shim).toContain(path.join(wsRoot, 'venv', 'python', 'packages'));
expect(fs.existsSync(path.join(pkgsDir(), '.bin', 'real-entry'))).toBe(true);
});
diff --git a/test/main/util/run-skill-packages.test.ts b/test/main/util/run-skill-packages.test.ts
index a547ede1..69b04566 100644
--- a/test/main/util/run-skill-packages.test.ts
+++ b/test/main/util/run-skill-packages.test.ts
@@ -1,5 +1,6 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { spawnSync } from 'node:child_process';
+import { createHash } from 'node:crypto';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
@@ -10,11 +11,17 @@ import * as path from 'node:path';
const TEST_UID = 'u1';
let tmpDir: string;
+const itOnNonWindows = process.platform === 'win32' ? it.skip : it;
function pkgsDir(): string {
return path.join(tmpDir, TEST_UID, 'local', 'packages');
}
+function packageVenvKey(name: string, repoUrl: string, commit: string): string {
+ const hash = createHash('sha256').update([name, repoUrl, commit].join('\n')).digest('hex').slice(0, 12);
+ return `${name}-${hash}`;
+}
+
function writeRegistry(registry: unknown): void {
fs.mkdirSync(pkgsDir(), { recursive: true });
fs.writeFileSync(path.join(pkgsDir(), '_registry.json'), JSON.stringify(registry));
@@ -43,6 +50,17 @@ function writePackageSkill(pkgName: string, skillId: string, displayName: string
);
}
+function writePackagePythonSkill(pkgName: string, skillId: string): void {
+ const skillDir = path.join(pkgsDir(), pkgName, 'skills', skillId);
+ const scriptsDir = path.join(skillDir, 'scripts');
+ fs.mkdirSync(scriptsDir, { recursive: true });
+ fs.writeFileSync(
+ path.join(skillDir, 'SKILL.md'),
+ `---\nname: ${skillId}\ndescription: pkg py skill\n---\nbody\n`,
+ );
+ fs.writeFileSync(path.join(scriptsDir, 'run.py'), 'print("package-local python should not run")\n');
+}
+
function runSkill(skillRef: string, scriptBase: string, args: string[] = [], extraEnv: Record<string, string> = {}) {
const pcRoot = process.cwd();
return spawnSync(process.execPath, [
@@ -121,6 +139,50 @@ describe('run-skill.cjs › external packages root', () => {
expect(r.status).toBe(66);
});
+ itOnNonWindows('uses shared data/venv Python for package skill scripts', () => {
+ const repoUrl = 'https://example.test/mypack.git';
+ const commit = 'abc123';
+ writePackagePythonSkill('mypack', 'pkg-py');
+ writeRegistry({
+ version: 1,
+ packages: [{
+ name: 'mypack',
+ repo_url: repoUrl,
+ commit,
+ kind: 'skill',
+ skill_roots: ['skills'],
+ bin_entries: [],
+ enabled: true,
+ }],
+ });
+ const python = path.join(
+ tmpDir,
+ 'venv',
+ 'python',
+ 'packages',
+ packageVenvKey('mypack', repoUrl, commit),
+ '.venv',
+ 'bin',
+ 'python',
+ );
+ fs.mkdirSync(path.dirname(python), { recursive: true });
+ fs.writeFileSync(python, [
+ '#!/bin/sh',
+ 'printf \'{"python":"shared","script":"%s","arg":"%s"}\\n\' "$1" "$2"',
+ '',
+ ].join('\n'));
+ fs.chmodSync(python, 0o755);
+
+ const r = runSkill('pkg-py', 'run', ['x']);
+
+ expect(r.status).toBe(0);
+ expect(JSON.parse(r.stdout.trim())).toEqual({
+ python: 'shared',
+ script: path.join(pkgsDir(), 'mypack', 'skills', 'pkg-py', 'scripts', 'run.py'),
+ arg: 'x',
+ });
+ });
+
it('honors ORKAS_RUN_SKILL_DIR without falling back to other roots', () => {
const allowed = path.join(tmpDir, TEST_UID, 'cloud', 'skills', 'allowed');
const allowedScripts = path.join(allowed, 'scripts');